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.

344 lines
11 KiB

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