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.

458 lines
14 KiB

  1. //=================================================================
  2. //
  3. // chwres.h
  4. //
  5. // Copyright (c) 1999-2001 Microsoft Corporation, All Rights Reserved
  6. //
  7. //=================================================================
  8. #ifndef _RESOURCE_H_
  9. #define _RESOURCE_H_
  10. // Pseudo handle type definition.
  11. #define HREGKEY LPKEY
  12. // Single value description within a key.
  13. typedef struct _VALUE
  14. {
  15. LPTSTR Name;
  16. DWORD Type;
  17. } VALUE, *LPVALUE;
  18. // Macro to initialize a value description table entry.
  19. //
  20. // v - value name
  21. // t - value type
  22. #define MakeValue( v, t ) \
  23. { \
  24. #v, \
  25. REG_##t \
  26. }
  27. // Single key description. Points to a table of value descriptions.
  28. typedef struct _KEY
  29. {
  30. HKEY ParentHandle;
  31. LPTSTR Name;
  32. DWORD CountOfValues;
  33. LPVALUE Values;
  34. HKEY hKey;
  35. LPBYTE Data;
  36. DWORD Size;
  37. LPTSTR ValueName;
  38. DWORD ValueNameLength;
  39. LPTSTR Subkey;
  40. DWORD SubkeyLength;
  41. DWORD Subkeys;
  42. DWORD Type;
  43. DWORD CurrentSize;
  44. DWORD CurrentValueNameLength;
  45. DWORD CurrentValue;
  46. DWORD CurrentSubkeyLength;
  47. DWORD CurrentSubkey;
  48. } KEY, *LPKEY;
  49. // Macro to initialize a subkey description.
  50. //
  51. // k - key variable name
  52. // h - parent handle (HREGKEY)
  53. // n - key name (path)
  54. #define InitializeKey( k, h, n ) \
  55. { \
  56. ( k )->ParentHandle = h->hRegKey; \
  57. ( k )->Name = n; \
  58. ( k )->CountOfValues = 0; \
  59. ( k )->Values = NULL; \
  60. ( k )->hKey = NULL; \
  61. ( k )->Data = NULL; \
  62. ( k )->Size = 0; \
  63. ( k )->ValueName = NULL; \
  64. ( k )->ValueNameLength = 0; \
  65. ( k )->Subkey = NULL; \
  66. ( k )->SubkeyLength = 0; \
  67. ( k )->Subkeys = 0; \
  68. ( k )->Type = REG_NONE; \
  69. ( k )->CurrentSize = 0; \
  70. ( k )->CurrentValueNameLength = 0; \
  71. ( k )->CurrentValue = 0; \
  72. ( k )->CurrentSubkeyLength = 0; \
  73. ( k )->CurrentSubkey = 0; \
  74. }
  75. // Macro to statically initialize a key description.
  76. //
  77. // k - key variable name
  78. // h - parent handle
  79. // n - key name (path)
  80. // v - count of values in table
  81. // t - pointer to values table
  82. //
  83. #define MakeKey( k, h, n, v, t ) \
  84. KEY \
  85. k = { \
  86. h, \
  87. n, \
  88. v, \
  89. t, \
  90. NULL, \
  91. NULL, \
  92. 0, \
  93. NULL, \
  94. 0, \
  95. NULL, \
  96. 0, \
  97. 0, \
  98. REG_NONE, \
  99. 0, \
  100. 0, \
  101. 0, \
  102. 0, \
  103. 0 \
  104. }
  105. class ClRegistry {
  106. public:
  107. BOOL CloseRegistryKey(HREGKEY Handle);
  108. BOOL QueryNextValue(HREGKEY Handle);
  109. HREGKEY OpenRegistryKey(LPKEY Key);
  110. HREGKEY QueryNextSubkey(HREGKEY Handle);
  111. };
  112. typedef LARGE_INTEGER PHYSICAL_ADDRESS;
  113. // ntconfig.h defines this as an int
  114. #ifndef _NTCONFIG_
  115. typedef enum _CM_RESOURCE_TYPE {
  116. CmResourceTypeNull = 0, // Reserved
  117. CmResourceTypePort,
  118. CmResourceTypeInterrupt,
  119. CmResourceTypeMemory,
  120. CmResourceTypeDma,
  121. CmResourceTypeDeviceSpecific
  122. } CM_RESOURCE_TYPE;
  123. //
  124. // Defines the ShareDisposition in the RESOURCE_DESCRIPTOR
  125. //
  126. typedef enum _CM_SHARE_DISPOSITION {
  127. CmResourceShareUndetermined = 0, // Reserved
  128. CmResourceShareDeviceExclusive,
  129. CmResourceShareDriverExclusive,
  130. CmResourceShareShared
  131. } CM_SHARE_DISPOSITION;
  132. #endif
  133. //
  134. // Define the bit masks for Flags when type is CmResourceTypeInterrupt
  135. //
  136. #define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE 0
  137. #define CM_RESOURCE_INTERRUPT_LATCHED 1
  138. //
  139. // Define the bit masks for Flags when type is CmResourceTypeMemory
  140. //
  141. #define CM_RESOURCE_MEMORY_READ_WRITE 0x0000
  142. #define CM_RESOURCE_MEMORY_READ_ONLY 0x0001
  143. #define CM_RESOURCE_MEMORY_WRITE_ONLY 0x0002
  144. #define CM_RESOURCE_MEMORY_PREFETCHABLE 0x0004
  145. //
  146. // Define the bit masks for Flags when type is CmResourceTypePort
  147. //
  148. #define CM_RESOURCE_PORT_MEMORY 0x0000
  149. #define CM_RESOURCE_PORT_IO 0x0001
  150. #ifndef _NTCONFIG_
  151. typedef enum Interface_Type {
  152. InterfaceTypeUndefined = -1,
  153. Internal,
  154. Isa,
  155. Eisa,
  156. MicroChannel,
  157. TurboChannel,
  158. PCIBus,
  159. VMEBus,
  160. NuBus,
  161. PCMCIABus,
  162. CBus,
  163. MPIBus,
  164. MPSABus,
  165. ProcessorInternal,
  166. InternalPowerBus,
  167. PNPISABus,
  168. PNPBus,
  169. MaximumInterfaceType
  170. }INTERFACE_TYPE;
  171. #endif
  172. #define REG_RESOURCE_LIST ( 8 ) // Resource list in the resource map
  173. #define REG_FULL_RESOURCE_DESCRIPTOR ( 9 ) // Resource list in the hardware description
  174. // ntconfig.h defines this
  175. #ifndef _NTCONFIG_
  176. #pragma pack(4)
  177. typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
  178. UCHAR Type;
  179. UCHAR ShareDisposition;
  180. USHORT Flags;
  181. union {
  182. //
  183. // Range of resources, inclusive. These are physical, bus relative.
  184. // It is known that Port and Memory below have the exact same layout
  185. // as Generic.
  186. //
  187. struct {
  188. PHYSICAL_ADDRESS Start;
  189. ULONG Length;
  190. } Generic;
  191. //
  192. // Range of port numbers, inclusive. These are physical, bus
  193. // relative. The value should be the same as the one passed to
  194. // HalTranslateBusAddress().
  195. //
  196. struct {
  197. PHYSICAL_ADDRESS Start;
  198. ULONG Length;
  199. } Port;
  200. //
  201. // IRQL and vector. Should be same values as were passed to
  202. // HalGetInterruptVector().
  203. //
  204. struct {
  205. ULONG Level;
  206. ULONG Vector;
  207. ULONG Affinity;
  208. } Interrupt;
  209. //
  210. // Range of memory addresses, inclusive. These are physical, bus
  211. // relative. The value should be the same as the one passed to
  212. // HalTranslateBusAddress().
  213. //
  214. struct {
  215. PHYSICAL_ADDRESS Start; // 64 bit physical addresses.
  216. ULONG Length;
  217. } Memory;
  218. //
  219. // Physical DMA channel.
  220. //
  221. struct {
  222. ULONG Channel;
  223. ULONG Port;
  224. ULONG Reserved1;
  225. } Dma;
  226. //
  227. // Device driver private data, usually used to help it figure
  228. // what the resource assignments decisions that were made.
  229. //
  230. struct {
  231. ULONG Data[3];
  232. } DevicePrivate;
  233. //
  234. // Bus Number information.
  235. //
  236. struct {
  237. ULONG Start;
  238. ULONG Length;
  239. ULONG Reserved;
  240. } BusNumber;
  241. //
  242. // Device Specific information defined by the driver.
  243. // The DataSize field indicates the size of the data in bytes. The
  244. // data is located immediately after the DeviceSpecificData field in
  245. // the structure.
  246. //
  247. struct {
  248. ULONG DataSize;
  249. ULONG Reserved1;
  250. ULONG Reserved2;
  251. } DeviceSpecificData;
  252. } u;
  253. } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
  254. #pragma pack()
  255. #endif
  256. //
  257. // The device data record for the Keyboard peripheral.
  258. // The KeyboardFlags is defined (by x86 BIOS INT 16h, function 02) as:
  259. // bit 7 : Insert on
  260. // bit 6 : Caps Lock on
  261. // bit 5 : Num Lock on
  262. // bit 4 : Scroll Lock on
  263. // bit 3 : Alt Key is down
  264. // bit 2 : Ctrl Key is down
  265. // bit 1 : Left shift key is down
  266. // bit 0 : Right shift key is down
  267. //
  268. // ntconfig.h defines this
  269. #ifndef _NTCONFIG_
  270. typedef struct _CM_KEYBOARD_DEVICE_DATA {
  271. USHORT Version;
  272. USHORT Revision;
  273. UCHAR Type;
  274. UCHAR Subtype;
  275. USHORT KeyboardFlags;
  276. } CM_KEYBOARD_DEVICE_DATA, *PCM_KEYBOARD_DEVICE_DATA;
  277. #endif
  278. //
  279. // A Partial Resource List is what can be found in the ARC firmware
  280. // or will be generated by ntdetect.com.
  281. // The configuration manager will transform this structure into a Full
  282. // resource descriptor when it is about to store it in the regsitry.
  283. //
  284. // Note: There must a be a convention to the order of fields of same type,
  285. // (defined on a device by device basis) so that the fields can make sense
  286. // to a driver (i.e. when multiple memory ranges are necessary).
  287. //
  288. // ntconfig.h defines this
  289. #ifndef _NTCONFIG_
  290. typedef struct _CM_PARTIAL_RESOURCE_LIST {
  291. USHORT Version;
  292. USHORT Revision;
  293. ULONG Count;
  294. CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];
  295. } CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;
  296. #endif
  297. //
  298. // A Full Resource Descriptor is what can be found in the registry.
  299. // This is what will be returned to a driver when it queries the registry
  300. // to get device information; it will be stored under a key in the hardware
  301. // description tree.
  302. //
  303. // Note: The BusNumber and Type are redundant information, but we will keep
  304. // it since it allows the driver _not_ to append it when it is creating
  305. // a resource list which could possibly span multiple buses.
  306. //
  307. // Note2: There must a be a convention to the order of fields of same type,
  308. // (defined on a device by device basis) so that the fields can make sense
  309. // to a driver (i.e. when multiple memory ranges are necessary).
  310. //
  311. // ntconfig.h defines this
  312. #ifndef _NTCONFIG_
  313. typedef struct _CM_FULL_RESOURCE_DESCRIPTOR {
  314. INTERFACE_TYPE InterfaceType;
  315. ULONG BusNumber;
  316. CM_PARTIAL_RESOURCE_LIST PartialResourceList;
  317. } CM_FULL_RESOURCE_DESCRIPTOR, *PCM_FULL_RESOURCE_DESCRIPTOR;
  318. #endif
  319. //
  320. // The Resource list is what will be stored by the drivers into the
  321. // resource map via the IO API.
  322. //
  323. // ntconfig.h defines this as an int
  324. #ifndef _NTCONFIG_
  325. typedef struct _CM_RESOURCE_LIST {
  326. ULONG Count;
  327. CM_FULL_RESOURCE_DESCRIPTOR List[1];
  328. } CM_RESOURCE_LIST, *PCM_RESOURCE_LIST;
  329. #endif
  330. typedef struct _RESOURCE_DESCRIPTOR *LPRESOURCE_DESCRIPTOR;
  331. typedef struct _DEVICE *LPDEVICE;
  332. typedef struct _RESOURCE_DESCRIPTOR
  333. {
  334. CM_PARTIAL_RESOURCE_DESCRIPTOR CmResourceDescriptor;
  335. LPRESOURCE_DESCRIPTOR NextSame;
  336. LPRESOURCE_DESCRIPTOR NextDiff;
  337. LPDEVICE Owner;
  338. ULONG Bus;
  339. INTERFACE_TYPE InterfaceType;
  340. } RESOURCE_DESCRIPTOR;
  341. typedef struct _DEVICE
  342. {
  343. LPTSTR Name;
  344. LPRESOURCE_DESCRIPTOR ResourceDescriptorHead;
  345. LPRESOURCE_DESCRIPTOR ResourceDescriptorTail;
  346. LPDEVICE Next;
  347. LPTSTR KeyName;
  348. } DEVICE;
  349. typedef struct _SYSTEM_RESOURCES
  350. {
  351. LPDEVICE DeviceHead;
  352. LPDEVICE DeviceTail;
  353. LPRESOURCE_DESCRIPTOR DmaHead;
  354. LPRESOURCE_DESCRIPTOR DmaTail;
  355. LPRESOURCE_DESCRIPTOR InterruptHead;
  356. LPRESOURCE_DESCRIPTOR InterruptTail;
  357. LPRESOURCE_DESCRIPTOR MemoryHead;
  358. LPRESOURCE_DESCRIPTOR MemoryTail;
  359. LPRESOURCE_DESCRIPTOR PortHead;
  360. LPRESOURCE_DESCRIPTOR PortTail;
  361. } SYSTEM_RESOURCES, *LPSYSTEM_RESOURCES;
  362. // Helper function for converting interface_type values to strings
  363. BOOL WINAPI StringFromInterfaceType( INTERFACE_TYPE it, CHString& strVal );
  364. #ifdef NTONLY
  365. class CHWResource {
  366. public :
  367. CHWResource() ;
  368. ~CHWResource() ;
  369. void CreateSystemResourceLists(void);
  370. void DestroySystemResourceLists();
  371. SYSTEM_RESOURCES _SystemResourceList ;
  372. private :
  373. void EnumerateResources(CHString sKeyName);
  374. void CreateResourceList(CHString sDeviceName,
  375. DWORD dwResourceCount,
  376. PCM_FULL_RESOURCE_DESCRIPTOR pFullDescriptor, CHString sKeyName);
  377. void CreateResourceRecord(LPDEVICE pDevice, INTERFACE_TYPE Interface, ULONG Bus,
  378. PCM_PARTIAL_RESOURCE_DESCRIPTOR pResource);
  379. } ;
  380. #endif
  381. #endif // _RESOURCE_H_