Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

358 lines
10 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. regiodls.cxx
  5. Abstract:
  6. This module contains the definitions of the member functions
  7. of IO_DESCRIPTOR_LIST class.
  8. Author:
  9. Jaime Sasson (jaimes) 02-Dec-1993
  10. Environment:
  11. ULIB, User Mode
  12. --*/
  13. #include "regiodls.hxx"
  14. #include "regiodsc.hxx"
  15. #include "iterator.hxx"
  16. DEFINE_CONSTRUCTOR ( IO_DESCRIPTOR_LIST, OBJECT );
  17. IO_DESCRIPTOR_LIST::~IO_DESCRIPTOR_LIST (
  18. )
  19. /*++
  20. Routine Description:
  21. Destroy an IO_DESCRIPTOR_LIST.
  22. Arguments:
  23. None.
  24. Return Value:
  25. None.
  26. --*/
  27. {
  28. Destroy();
  29. }
  30. VOID
  31. IO_DESCRIPTOR_LIST::Construct (
  32. )
  33. /*++
  34. Routine Description:
  35. Construct an IO_DESCRIPTOR_LIST object.
  36. Arguments:
  37. None.
  38. Return Value:
  39. None.
  40. --*/
  41. {
  42. _Version = 0;
  43. _Revision = 0;
  44. _DescriptorsList = NULL;
  45. }
  46. VOID
  47. IO_DESCRIPTOR_LIST::Destroy (
  48. )
  49. /*++
  50. Routine Description:
  51. Worker method for object destruction.
  52. Arguments:
  53. None.
  54. Return Value:
  55. None.
  56. --*/
  57. {
  58. _Version = 0;
  59. _Revision = 0;
  60. if( _DescriptorsList != NULL ) {
  61. _DescriptorsList->DeleteAllMembers();
  62. DELETE( _DescriptorsList );
  63. }
  64. _DescriptorsList = NULL;
  65. }
  66. BOOLEAN
  67. IO_DESCRIPTOR_LIST::Initialize(
  68. IN PCBYTE Data,
  69. IN ULONG Size,
  70. OUT PULONG DescriptorSize
  71. )
  72. /*++
  73. Routine Description:
  74. Initialize an object of type IO_DESCRIPTOR_LIST.
  75. Arguments:
  76. Data - Pointer to a buffer that contains an IO_RESOURCE_LIST.
  77. Size - Buffer size.
  78. Return Value:
  79. BOOLEAN - Returns TRUE if the initialization succeeds.
  80. --*/
  81. {
  82. PIO_RESOURCE_LIST IoResourceList;
  83. ULONG Count;
  84. ULONG i;
  85. ULONG j;
  86. PARRAY TmpList;
  87. PIO_PORT_DESCRIPTOR PortDescriptor;
  88. PIO_INTERRUPT_DESCRIPTOR InterruptDescriptor;
  89. PIO_MEMORY_DESCRIPTOR MemoryDescriptor;
  90. PIO_DMA_DESCRIPTOR DmaDescriptor;
  91. if( Data == NULL ) {
  92. return( FALSE );
  93. }
  94. Count = 1;
  95. IoResourceList = ( PIO_RESOURCE_LIST )Data;
  96. TmpList = ( PARRAY )NEW( ARRAY );
  97. DebugPtrAssert( TmpList );
  98. if( ( TmpList == NULL ) ||
  99. ( !TmpList->Initialize() ) ) {
  100. DebugPrintTrace(("REGEDT32: Out of memory" ));
  101. DELETE( TmpList );
  102. return( FALSE );
  103. }
  104. _Version = IoResourceList->Version;
  105. _Revision = IoResourceList->Revision;
  106. //
  107. // For each CM_FULL_RESOURCE DESCRIPTOR in the current value...
  108. //
  109. for( i = 0; i < Count; i++ ) {
  110. PIO_RESOURCE_DESCRIPTOR IoResourceDescriptor;
  111. //
  112. // For each IO_RESOURCE_DESCRIPTOR in the list...
  113. //
  114. for( j = 0; j < IoResourceList->Count; j++ ) {
  115. //
  116. // Get a pointer to the current IO_RESOURCE_DESCRIPTOR
  117. // in the current IO_RESOURCE_LIST.
  118. //
  119. IoResourceDescriptor = &( IoResourceList->Descriptors[ j ]);
  120. //
  121. // Ignore invalid data
  122. //
  123. if( ( ULONG_PTR )IoResourceDescriptor >
  124. ( ULONG_PTR )( Data + Size - sizeof( IO_RESOURCE_DESCRIPTOR ) ) ) {
  125. DebugPrintTrace(( "REGEDT32: Invalid IO_RESOURCE_DESCRIPTOR, j = %d \n", j ));
  126. if( DescriptorSize != NULL ) {
  127. *DescriptorSize = Size;
  128. }
  129. _DescriptorsList = TmpList;
  130. return( TRUE );
  131. }
  132. switch( IoResourceDescriptor->Type ) {
  133. case CmResourceTypePort:
  134. PortDescriptor = ( PIO_PORT_DESCRIPTOR )NEW( IO_PORT_DESCRIPTOR );
  135. if( ( PortDescriptor == NULL ) ||
  136. ( !PortDescriptor->Initialize( IoResourceDescriptor->u.Port.Length,
  137. IoResourceDescriptor->u.Port.Alignment,
  138. &IoResourceDescriptor->u.Port.MinimumAddress,
  139. &IoResourceDescriptor->u.Port.MaximumAddress,
  140. IoResourceDescriptor->Option,
  141. IoResourceDescriptor->ShareDisposition,
  142. IoResourceDescriptor->Flags ) )
  143. ) {
  144. DebugPrintTrace(( "REGEDT32: Unable to create IO_PORT_DESCRIPTOR" ));
  145. DELETE( PortDescriptor );
  146. TmpList->DeleteAllMembers();
  147. DELETE( TmpList );
  148. return( FALSE );
  149. }
  150. TmpList->Put( PortDescriptor );
  151. break;
  152. case CmResourceTypeInterrupt:
  153. InterruptDescriptor = ( PIO_INTERRUPT_DESCRIPTOR )NEW( IO_INTERRUPT_DESCRIPTOR );
  154. if( ( InterruptDescriptor == NULL ) ||
  155. ( !InterruptDescriptor->Initialize( IoResourceDescriptor->u.Interrupt.MinimumVector,
  156. IoResourceDescriptor->u.Interrupt.MaximumVector,
  157. IoResourceDescriptor->Option,
  158. IoResourceDescriptor->ShareDisposition,
  159. IoResourceDescriptor->Flags ) )
  160. ) {
  161. DebugPrintTrace(( "REGEDT32: Unable to create IO_INTERRUPT_DESCRIPTOR" ));
  162. DELETE( InterruptDescriptor );
  163. TmpList->DeleteAllMembers();
  164. DELETE( TmpList );
  165. return( FALSE );
  166. }
  167. TmpList->Put( InterruptDescriptor );
  168. break;
  169. case CmResourceTypeMemory:
  170. MemoryDescriptor = ( PIO_MEMORY_DESCRIPTOR )NEW( IO_MEMORY_DESCRIPTOR );
  171. if( ( MemoryDescriptor == NULL ) ||
  172. ( !MemoryDescriptor->Initialize( IoResourceDescriptor->u.Memory.Length,
  173. IoResourceDescriptor->u.Memory.Alignment,
  174. &IoResourceDescriptor->u.Memory.MinimumAddress,
  175. &IoResourceDescriptor->u.Memory.MaximumAddress,
  176. IoResourceDescriptor->Option,
  177. IoResourceDescriptor->ShareDisposition,
  178. IoResourceDescriptor->Flags ) )
  179. ) {
  180. DebugPrintTrace(( "REGEDT32: Unable to create IO_MEMORY_DESCRIPTOR" ));
  181. DELETE( MemoryDescriptor );
  182. TmpList->DeleteAllMembers();
  183. DELETE( TmpList );
  184. return( FALSE );
  185. }
  186. TmpList->Put( MemoryDescriptor );
  187. break;
  188. case CmResourceTypeDma:
  189. DmaDescriptor = ( PIO_DMA_DESCRIPTOR )NEW( IO_DMA_DESCRIPTOR );
  190. if( ( DmaDescriptor == NULL ) ||
  191. ( !DmaDescriptor->Initialize( IoResourceDescriptor->u.Dma.MinimumChannel,
  192. IoResourceDescriptor->u.Dma.MaximumChannel,
  193. IoResourceDescriptor->Option,
  194. IoResourceDescriptor->ShareDisposition,
  195. IoResourceDescriptor->Flags ) )
  196. ) {
  197. DebugPrintTrace(( "REGEDT32: Unable to create IO_DMA_DESCRIPTOR" ));
  198. DELETE( DmaDescriptor );
  199. TmpList->DeleteAllMembers();
  200. DELETE( TmpList );
  201. return( FALSE );
  202. }
  203. TmpList->Put( DmaDescriptor );
  204. break;
  205. default:
  206. DebugPrintTrace(( "REGEDT32: Unknown IoResourceDescriptor->Type == %#x \n",
  207. IoResourceDescriptor->Type ));
  208. continue;
  209. }
  210. }
  211. _DescriptorsList = TmpList;
  212. //
  213. // Get the next IO_RESOURCE_LIST from the list.
  214. //
  215. IoResourceList = ( PIO_RESOURCE_LIST )( IoResourceDescriptor + 1 );
  216. }
  217. if( DescriptorSize != NULL ) {
  218. *DescriptorSize = ( ULONG )( ( ULONG_PTR )IoResourceList - ( ULONG_PTR )Data );
  219. #if DBG
  220. if( *DescriptorSize > Size ) {
  221. DebugPrintTrace(( "REGEDT32: Invalid sizes, *DescriptorSize = %d, Size = %d \n", *DescriptorSize, Size ));
  222. }
  223. #endif
  224. }
  225. return( TRUE );
  226. }
  227. #if DBG
  228. VOID
  229. IO_DESCRIPTOR_LIST::DbgDumpObject(
  230. )
  231. /*++
  232. Routine Description:
  233. Print an IO_DESCRIPTOR_LIST object.
  234. Arguments:
  235. None.
  236. Return Value:
  237. None.
  238. --*/
  239. {
  240. PITERATOR Iterator;
  241. PIO_DESCRIPTOR Descriptor;
  242. DebugPrintTrace(( "\tVersion = %#x \n", _Version ));
  243. DebugPrintTrace(( "\tRevision = %#x \n", _Revision ));
  244. if( _DescriptorsList != NULL ) {
  245. Iterator = _DescriptorsList->QueryIterator();
  246. while( Descriptor = ( PIO_DESCRIPTOR ) Iterator->GetNext() ) {
  247. if( Descriptor->IsDescriptorTypePort() ) {
  248. ( ( PIO_PORT_DESCRIPTOR )Descriptor )->DbgDumpObject();
  249. } else if( Descriptor->IsDescriptorTypeInterrupt() ) {
  250. ( ( PIO_INTERRUPT_DESCRIPTOR )Descriptor )->DbgDumpObject();
  251. } else if( Descriptor->IsDescriptorTypeMemory() ) {
  252. ( ( PIO_MEMORY_DESCRIPTOR )Descriptor )->DbgDumpObject();
  253. } else if( Descriptor->IsDescriptorTypeDma() ) {
  254. ( ( PIO_DMA_DESCRIPTOR )Descriptor )->DbgDumpObject();
  255. } else {
  256. DebugPrintTrace(( "\tERROR: Unknown Descriptor \n\n" ));
  257. }
  258. }
  259. DELETE( Iterator );
  260. }
  261. }
  262. #endif