Leaked source code of windows server 2003
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.

352 lines
12 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. {
  142. case CmResourceTypePort:
  143. {
  144. PortDescriptor = ( PPORT_DESCRIPTOR )NEW( PORT_DESCRIPTOR );
  145. PHYSICAL_ADDRESS portStartAddr = (PHYSICAL_ADDRESS) PartialResourceDescriptor->u.Port.Start;
  146. if ( (PortDescriptor == NULL) ||
  147. ( !PortDescriptor->Initialize( &portStartAddr,
  148. PartialResourceDescriptor->u.Port.Length,
  149. PartialResourceDescriptor->ShareDisposition,
  150. PartialResourceDescriptor->Flags ) )
  151. )
  152. {
  153. DebugPrintTrace(( "REGEDT32: Unable to create PORT_DESCRIPTOR" ));
  154. DELETE( PortDescriptor );
  155. TmpList->DeleteAllMembers();
  156. DELETE( TmpList );
  157. return( FALSE );
  158. }
  159. TmpList->Put( PortDescriptor );
  160. }
  161. break;
  162. case CmResourceTypeInterrupt:
  163. {
  164. InterruptDescriptor = ( PINTERRUPT_DESCRIPTOR )NEW( INTERRUPT_DESCRIPTOR );
  165. if ( ( InterruptDescriptor == NULL ) ||
  166. ( !InterruptDescriptor->Initialize( PartialResourceDescriptor->u.Interrupt.Affinity,
  167. PartialResourceDescriptor->u.Interrupt.Level,
  168. PartialResourceDescriptor->u.Interrupt.Vector,
  169. PartialResourceDescriptor->ShareDisposition,
  170. PartialResourceDescriptor->Flags ) )
  171. )
  172. {
  173. DebugPrintTrace(( "REGEDT32: Unable to create INTERRUPT_DESCRIPTOR" ));
  174. DELETE( InterruptDescriptor );
  175. TmpList->DeleteAllMembers();
  176. DELETE( TmpList );
  177. return( FALSE );
  178. }
  179. TmpList->Put( InterruptDescriptor );
  180. }
  181. break;
  182. case CmResourceTypeMemory:
  183. {
  184. MemoryDescriptor = ( PMEMORY_DESCRIPTOR )NEW( MEMORY_DESCRIPTOR );
  185. PHYSICAL_ADDRESS memStartAddr = (PHYSICAL_ADDRESS) PartialResourceDescriptor->u.Memory.Start;
  186. if ( ( MemoryDescriptor == NULL ) ||
  187. ( !MemoryDescriptor->Initialize( &memStartAddr,
  188. PartialResourceDescriptor->u.Memory.Length,
  189. PartialResourceDescriptor->ShareDisposition,
  190. PartialResourceDescriptor->Flags ) )
  191. )
  192. {
  193. DebugPrintTrace(( "REGEDT32: Unable to create MEMORY_DESCRIPTOR" ));
  194. DELETE( MemoryDescriptor );
  195. TmpList->DeleteAllMembers();
  196. DELETE( TmpList );
  197. return( FALSE );
  198. }
  199. TmpList->Put( MemoryDescriptor );
  200. }
  201. break;
  202. case CmResourceTypeDma:
  203. {
  204. DmaDescriptor = ( PDMA_DESCRIPTOR )NEW( DMA_DESCRIPTOR );
  205. if ( ( DmaDescriptor == NULL ) ||
  206. ( !DmaDescriptor->Initialize( PartialResourceDescriptor->u.Dma.Channel,
  207. PartialResourceDescriptor->u.Dma.Port,
  208. PartialResourceDescriptor->u.Dma.Reserved1,
  209. PartialResourceDescriptor->ShareDisposition,
  210. PartialResourceDescriptor->Flags ) )
  211. )
  212. {
  213. DebugPrintTrace(( "REGEDT32: Unable to create DMA_DESCRIPTOR" ));
  214. DELETE( DmaDescriptor );
  215. TmpList->DeleteAllMembers();
  216. DELETE( TmpList );
  217. return( FALSE );
  218. }
  219. TmpList->Put( DmaDescriptor );
  220. }
  221. break;
  222. case CmResourceTypeDeviceSpecific:
  223. {
  224. DeviceSpecificDataSize = PartialResourceDescriptor->u.DeviceSpecificData.DataSize;
  225. DeviceSpecificDescriptor = ( PDEVICE_SPECIFIC_DESCRIPTOR )NEW( DEVICE_SPECIFIC_DESCRIPTOR );
  226. if ( ( DeviceSpecificDescriptor == NULL ) ||
  227. ( !DeviceSpecificDescriptor->Initialize(
  228. PartialResourceDescriptor->u.DeviceSpecificData.Reserved1,
  229. PartialResourceDescriptor->u.DeviceSpecificData.Reserved2,
  230. PartialResourceDescriptor->u.DeviceSpecificData.DataSize,
  231. ( PBYTE )&PartialResourceDescriptor->u.DeviceSpecificData + 3*sizeof( ULONG ),
  232. PartialResourceDescriptor->ShareDisposition,
  233. PartialResourceDescriptor->Flags ) )
  234. )
  235. {
  236. DebugPrintTrace(( "REGEDT32: Unable to create DEVICE_SPECIFIC_DESCRIPTOR" ));
  237. DELETE( DeviceSpecificDescriptor );
  238. TmpList->DeleteAllMembers();
  239. DELETE( TmpList );
  240. return( FALSE );
  241. }
  242. TmpList->Put( DeviceSpecificDescriptor );
  243. }
  244. break;
  245. default:
  246. DebugPrintTrace(( "REGEDT32: Unknown PartialResourceDescriptor->Type == %#x \n", PartialResourceDescriptor->Type ));
  247. continue;
  248. }
  249. }
  250. _ResourceDescriptors = TmpList;
  251. //
  252. // Get the next CM_FULL_RESOURCE_DESCRIPTOR from the list.
  253. //
  254. FullResource = ( PCM_FULL_RESOURCE_DESCRIPTOR ) ( ( ULONG_PTR )FullResource +
  255. sizeof( ULONG ) +
  256. sizeof( ULONG ) +
  257. sizeof( USHORT ) +
  258. sizeof( USHORT ) +
  259. sizeof( ULONG ) +
  260. j*sizeof( CM_PARTIAL_RESOURCE_DESCRIPTOR ) +
  261. DeviceSpecificDataSize );
  262. // FullResource = ( PCM_FULL_RESOURCE_DESCRIPTOR )( PartialResourceDescriptor + 1 );
  263. // FullResource = ( PCM_FULL_RESOURCE_DESCRIPTOR )( ( ULONG )FullResource +
  264. // DeviceSpecificDataSize );
  265. }
  266. if( DescriptorSize != NULL ) {
  267. *DescriptorSize = ( ULONG )( ( ULONG_PTR )FullResource - ( ULONG_PTR )Data );
  268. }
  269. return( TRUE );
  270. }