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.

5577 lines
125 KiB

  1. /*++ BUILD Version: 0096 // Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. ndis.h
  5. Abstract:
  6. This module defines the structures, macros, and functions available
  7. to NDIS drivers.
  8. Revision History:
  9. --*/
  10. #if !defined(_NDIS_)
  11. #define _NDIS_
  12. #if !defined(NDIS_WDM)
  13. #define NDIS_WDM 0
  14. #endif
  15. //
  16. // If we're building a miniport on x86, set BINARY_COMPATIBLE so that
  17. // we don't use functions that aren't available on Windows 9x.
  18. //
  19. #if !defined(BINARY_COMPATIBLE)
  20. #if defined(NDIS_MINIPORT_DRIVER) && defined(_M_IX86)
  21. #define BINARY_COMPATIBLE 1
  22. #else
  23. #define BINARY_COMPATIBLE 0
  24. #endif
  25. #endif
  26. #if !defined(_M_IX86)
  27. #undef BINARY_COMPATIBLE
  28. #define BINARY_COMPATIBLE 0
  29. #endif
  30. //
  31. // BEGIN INTERNAL DEFINITIONS
  32. //
  33. //
  34. // BINARY_COMPATIBLE = 1 and NDIS_WDM = 1 then use wdm.h
  35. // BINARY_COMPATIBLE = 1 and NDIS_WDM = 0 then use ndis.h only
  36. // BINARY_COMPATIBLE = 0 and NDIS_WDM = 1 then use ntddk.h
  37. // BINARY_COMPATIBLE = 0 and NDIS_WDM = 0 then use ntddk.h
  38. //
  39. #if (BINARY_COMPATIBLE && !NDIS_WDM)
  40. //
  41. // BINARY_COMPATIBLE = 1 and NDIS_WDM = 0 then use ndis.h only
  42. //
  43. // The following internal definitions are included here in order to allow
  44. // the exported NDIS structures, macros, and functions to compile. They
  45. // must not be used directly by miniport drivers.
  46. //
  47. #define _NTDDK_
  48. #include <ctype.h>
  49. #ifndef IN
  50. #define IN
  51. #endif
  52. #ifndef OUT
  53. #define OUT
  54. #endif
  55. #ifndef OPTIONAL
  56. #define OPTIONAL
  57. #endif
  58. #ifndef NOTHING
  59. #define NOTHING
  60. #endif
  61. #ifndef CRITICAL
  62. #define CRITICAL
  63. #endif
  64. #ifndef ANYSIZE_ARRAY
  65. #define ANYSIZE_ARRAY 1 // winnt
  66. #endif
  67. // begin_winnt
  68. #if defined(_M_MRX000) && !(defined(MIDL_PASS) || defined(RC_INVOKED)) && defined(ENABLE_RESTRICTED)
  69. #define RESTRICTED_POINTER __restrict
  70. #else
  71. #define RESTRICTED_POINTER
  72. #endif
  73. #if defined(_M_MRX000) || defined(_M_ALPHA) || defined(_M_PPC) || defined(_M_IA64) || defined(_M_AMD64)
  74. #define UNALIGNED __unaligned
  75. #if defined(_WIN64)
  76. #define UNALIGNED64 __unaligned
  77. #else
  78. #define UNALIGNED64
  79. #endif
  80. #else
  81. #define UNALIGNED
  82. #define UNALIGNED64
  83. #endif
  84. #if defined(_WIN64) || defined(_M_ALPHA)
  85. #define MAX_NATURAL_ALIGNMENT sizeof(ULONGLONG)
  86. #define MEMORY_ALLOCATION_ALIGNMENT 16
  87. #else
  88. #define MAX_NATURAL_ALIGNMENT sizeof(ULONG)
  89. #define MEMORY_ALLOCATION_ALIGNMENT 8
  90. #endif
  91. //
  92. // TYPE_ALIGNMENT will return the alignment requirements of a given type for
  93. // the current platform.
  94. //
  95. #ifdef __cplusplus
  96. #if _MSC_VER >= 1300
  97. #define TYPE_ALIGNMENT( t ) __alignof(t)
  98. #endif
  99. #else
  100. #define TYPE_ALIGNMENT( t ) \
  101. FIELD_OFFSET( struct { char x; t test; }, test )
  102. #endif
  103. #if defined(_WIN64)
  104. #define PROBE_ALIGNMENT( _s ) (TYPE_ALIGNMENT( _s ) > TYPE_ALIGNMENT( ULONG ) ? \
  105. TYPE_ALIGNMENT( _s ) : TYPE_ALIGNMENT( ULONG ))
  106. #define PROBE_ALIGNMENT32( _s ) TYPE_ALIGNMENT( ULONG )
  107. #else
  108. #define PROBE_ALIGNMENT( _s ) TYPE_ALIGNMENT( ULONG )
  109. #endif
  110. //
  111. // C_ASSERT() can be used to perform many compile-time assertions:
  112. // type sizes, field offsets, etc.
  113. //
  114. // An assertion failure results in error C2118: negative subscript.
  115. //
  116. #define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1]
  117. #if !defined(_MAC) && (defined(_M_MRX000) || defined(_M_AMD64) || defined(_M_IA64)) && (_MSC_VER >= 1100) && !(defined(MIDL_PASS) || defined(RC_INVOKED))
  118. #define POINTER_64 __ptr64
  119. typedef unsigned __int64 POINTER_64_INT;
  120. #if defined(_WIN64)
  121. #define POINTER_32 __ptr32
  122. #else
  123. #define POINTER_32
  124. #endif
  125. #else
  126. #if defined(_MAC) && defined(_MAC_INT_64)
  127. #define POINTER_64 __ptr64
  128. typedef unsigned __int64 POINTER_64_INT;
  129. #else
  130. #define POINTER_64
  131. typedef unsigned long POINTER_64_INT;
  132. #endif
  133. #define POINTER_32
  134. #endif
  135. #if defined(_IA64_) || defined(_AMD64_)
  136. #define FIRMWARE_PTR
  137. #else
  138. #define FIRMWARE_PTR POINTER_32
  139. #endif
  140. #include <basetsd.h>
  141. // end_winnt
  142. #ifndef CONST
  143. #define CONST const
  144. #endif
  145. // begin_winnt
  146. #if (defined(_M_IX86) || defined(_M_IA64) || defined(_M_AMD64)) && !defined(MIDL_PASS)
  147. #define DECLSPEC_IMPORT __declspec(dllimport)
  148. #else
  149. #define DECLSPEC_IMPORT
  150. #endif
  151. #ifndef DECLSPEC_NORETURN
  152. #if (_MSC_VER >= 1200) && !defined(MIDL_PASS)
  153. #define DECLSPEC_NORETURN __declspec(noreturn)
  154. #else
  155. #define DECLSPEC_NORETURN
  156. #endif
  157. #endif
  158. #ifndef DECLSPEC_ALIGN
  159. #if (_MSC_VER >= 1300) && !defined(MIDL_PASS)
  160. #define DECLSPEC_ALIGN(x) __declspec(align(x))
  161. #else
  162. #define DECLSPEC_ALIGN(x)
  163. #endif
  164. #endif
  165. #ifndef DECLSPEC_CACHEALIGN
  166. #define DECLSPEC_CACHEALIGN DECLSPEC_ALIGN(128)
  167. #endif
  168. #ifndef DECLSPEC_UUID
  169. #if (_MSC_VER >= 1100) && defined (__cplusplus)
  170. #define DECLSPEC_UUID(x) __declspec(uuid(x))
  171. #else
  172. #define DECLSPEC_UUID(x)
  173. #endif
  174. #endif
  175. #ifndef DECLSPEC_NOVTABLE
  176. #if (_MSC_VER >= 1100) && defined(__cplusplus)
  177. #define DECLSPEC_NOVTABLE __declspec(novtable)
  178. #else
  179. #define DECLSPEC_NOVTABLE
  180. #endif
  181. #endif
  182. #ifndef DECLSPEC_SELECTANY
  183. #if (_MSC_VER >= 1100)
  184. #define DECLSPEC_SELECTANY __declspec(selectany)
  185. #else
  186. #define DECLSPEC_SELECTANY
  187. #endif
  188. #endif
  189. #ifndef NOP_FUNCTION
  190. #if (_MSC_VER >= 1210)
  191. #define NOP_FUNCTION __noop
  192. #else
  193. #define NOP_FUNCTION (void)0
  194. #endif
  195. #endif
  196. #ifndef DECLSPEC_ADDRSAFE
  197. #if (_MSC_VER >= 1200) && (defined(_M_ALPHA) || defined(_M_AXP64))
  198. #define DECLSPEC_ADDRSAFE __declspec(address_safe)
  199. #else
  200. #define DECLSPEC_ADDRSAFE
  201. #endif
  202. #endif
  203. #ifndef DECLSPEC_NOINLINE
  204. #if (_MSC_VER >= 1300)
  205. #define DECLSPEC_NOINLINE __declspec(noinline)
  206. #else
  207. #define DECLSPEC_NOINLINE
  208. #endif
  209. #endif
  210. #ifndef FORCEINLINE
  211. #if (_MSC_VER >= 1200)
  212. #define FORCEINLINE __forceinline
  213. #else
  214. #define FORCEINLINE __inline
  215. #endif
  216. #endif
  217. #ifndef DECLSPEC_DEPRECATED
  218. #if (_MSC_VER >= 1300) && !defined(MIDL_PASS)
  219. #define DECLSPEC_DEPRECATED __declspec(deprecated)
  220. #define DEPRECATE_SUPPORTED
  221. #else
  222. #define DECLSPEC_DEPRECATED
  223. #undef DEPRECATE_SUPPORTED
  224. #endif
  225. #endif
  226. #ifdef DEPRECATE_DDK_FUNCTIONS
  227. #ifdef _NTDDK_
  228. #define DECLSPEC_DEPRECATED_DDK DECLSPEC_DEPRECATED
  229. #ifdef DEPRECATE_SUPPORTED
  230. #define PRAGMA_DEPRECATED_DDK 1
  231. #endif
  232. #else
  233. #define DECLSPEC_DEPRECATED_DDK
  234. #define PRAGMA_DEPRECATED_DDK 1
  235. #endif
  236. #else
  237. #define DECLSPEC_DEPRECATED_DDK
  238. #define PRAGMA_DEPRECATED_DDK 0
  239. #endif
  240. //
  241. // Void
  242. //
  243. typedef void *PVOID;
  244. typedef void * POINTER_64 PVOID64;
  245. // end_winnt
  246. #if defined(_M_IX86)
  247. #define FASTCALL _fastcall
  248. #else
  249. #define FASTCALL
  250. #endif
  251. #if ((_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED)) && !defined(_M_AMD64)
  252. #define NTAPI __stdcall
  253. #else
  254. #define _cdecl
  255. #define NTAPI
  256. #endif
  257. //
  258. // Define API decoration for direct importing system DLL references.
  259. //
  260. #if !defined(_NTSYSTEM_)
  261. #define NTSYSAPI DECLSPEC_IMPORT
  262. #define NTSYSCALLAPI DECLSPEC_IMPORT
  263. #else
  264. #define NTSYSAPI
  265. #if defined(_NTDLLBUILD_)
  266. #define NTSYSCALLAPI
  267. #else
  268. #define NTSYSCALLAPI DECLSPEC_ADDRSAFE
  269. #endif
  270. #endif
  271. //
  272. // Basics
  273. //
  274. #ifndef VOID
  275. #define VOID void
  276. typedef char CHAR;
  277. typedef short SHORT;
  278. typedef long LONG;
  279. #endif
  280. //
  281. // UNICODE (Wide Character) types
  282. //
  283. #ifndef _MAC
  284. typedef wchar_t WCHAR; // wc, 16-bit UNICODE character
  285. #else
  286. // some Macintosh compilers don't define wchar_t in a convenient location, or define it as a char
  287. typedef unsigned short WCHAR; // wc, 16-bit UNICODE character
  288. #endif
  289. typedef WCHAR *PWCHAR;
  290. typedef WCHAR *LPWCH, *PWCH;
  291. typedef CONST WCHAR *LPCWCH, *PCWCH;
  292. typedef WCHAR *NWPSTR;
  293. typedef WCHAR *LPWSTR, *PWSTR;
  294. typedef WCHAR UNALIGNED *LPUWSTR, *PUWSTR;
  295. typedef CONST WCHAR *LPCWSTR, *PCWSTR;
  296. typedef CONST WCHAR UNALIGNED *LPCUWSTR, *PCUWSTR;
  297. //
  298. // ANSI (Multi-byte Character) types
  299. //
  300. typedef CHAR *PCHAR;
  301. typedef CHAR *LPCH, *PCH;
  302. typedef CONST CHAR *LPCCH, *PCCH;
  303. typedef CHAR *NPSTR;
  304. typedef CHAR *LPSTR, *PSTR;
  305. typedef CONST CHAR *LPCSTR, *PCSTR;
  306. //
  307. // Neutral ANSI/UNICODE types and macros
  308. //
  309. #ifdef UNICODE // r_winnt
  310. #ifndef _TCHAR_DEFINED
  311. typedef WCHAR TCHAR, *PTCHAR;
  312. typedef WCHAR TUCHAR, *PTUCHAR;
  313. #define _TCHAR_DEFINED
  314. #endif /* !_TCHAR_DEFINED */
  315. typedef LPWSTR LPTCH, PTCH;
  316. typedef LPWSTR PTSTR, LPTSTR;
  317. typedef LPCWSTR PCTSTR, LPCTSTR;
  318. typedef LPUWSTR PUTSTR, LPUTSTR;
  319. typedef LPCUWSTR PCUTSTR, LPCUTSTR;
  320. typedef LPWSTR LP;
  321. #define __TEXT(quote) L##quote // r_winnt
  322. #else /* UNICODE */ // r_winnt
  323. #ifndef _TCHAR_DEFINED
  324. typedef char TCHAR, *PTCHAR;
  325. typedef unsigned char TUCHAR, *PTUCHAR;
  326. #define _TCHAR_DEFINED
  327. #endif /* !_TCHAR_DEFINED */
  328. typedef LPSTR LPTCH, PTCH;
  329. typedef LPSTR PTSTR, LPTSTR, PUTSTR, LPUTSTR;
  330. typedef LPCSTR PCTSTR, LPCTSTR, PCUTSTR, LPCUTSTR;
  331. #define __TEXT(quote) quote // r_winnt
  332. #endif /* UNICODE */ // r_winnt
  333. #define TEXT(quote) __TEXT(quote) // r_winnt
  334. // end_winnt
  335. typedef double DOUBLE;
  336. typedef struct _QUAD { // QUAD is for those times we want
  337. double DoNotUseThisField; // an 8 byte aligned 8 byte long structure
  338. } QUAD; // which is NOT really a floating point
  339. // number. Use DOUBLE if you want an FP
  340. // number.
  341. //
  342. // Pointer to Basics
  343. //
  344. typedef SHORT *PSHORT; // winnt
  345. typedef LONG *PLONG; // winnt
  346. typedef QUAD *PQUAD;
  347. //
  348. // Unsigned Basics
  349. //
  350. // Tell windef.h that some types are already defined.
  351. #define BASETYPES
  352. typedef unsigned char UCHAR;
  353. typedef unsigned short USHORT;
  354. typedef unsigned long ULONG;
  355. typedef QUAD UQUAD;
  356. //
  357. // Pointer to Unsigned Basics
  358. //
  359. typedef UCHAR *PUCHAR;
  360. typedef USHORT *PUSHORT;
  361. typedef ULONG *PULONG;
  362. typedef UQUAD *PUQUAD;
  363. //
  364. // Signed characters
  365. //
  366. typedef signed char SCHAR;
  367. typedef SCHAR *PSCHAR;
  368. #ifndef NO_STRICT
  369. #ifndef STRICT
  370. #define STRICT 1
  371. #endif
  372. #endif
  373. //
  374. // Handle to an Object
  375. //
  376. // begin_winnt
  377. #ifdef STRICT
  378. typedef void *HANDLE;
  379. #define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
  380. #else
  381. typedef PVOID HANDLE;
  382. #define DECLARE_HANDLE(name) typedef HANDLE name
  383. #endif
  384. typedef HANDLE *PHANDLE;
  385. //
  386. // Flag (bit) fields
  387. //
  388. typedef UCHAR FCHAR;
  389. typedef USHORT FSHORT;
  390. typedef ULONG FLONG;
  391. // Component Object Model defines, and macros
  392. #ifndef _HRESULT_DEFINED
  393. #define _HRESULT_DEFINED
  394. typedef LONG HRESULT;
  395. #endif // !_HRESULT_DEFINED
  396. #ifdef __cplusplus
  397. #define EXTERN_C extern "C"
  398. #else
  399. #define EXTERN_C extern
  400. #endif
  401. #if defined(_WIN32) || defined(_MPPC_)
  402. // Win32 doesn't support __export
  403. #ifdef _68K_
  404. #define STDMETHODCALLTYPE __cdecl
  405. #else
  406. #define STDMETHODCALLTYPE __stdcall
  407. #endif
  408. #define STDMETHODVCALLTYPE __cdecl
  409. #define STDAPICALLTYPE __stdcall
  410. #define STDAPIVCALLTYPE __cdecl
  411. #else
  412. #define STDMETHODCALLTYPE __export __stdcall
  413. #define STDMETHODVCALLTYPE __export __cdecl
  414. #define STDAPICALLTYPE __export __stdcall
  415. #define STDAPIVCALLTYPE __export __cdecl
  416. #endif
  417. #define STDAPI EXTERN_C HRESULT STDAPICALLTYPE
  418. #define STDAPI_(type) EXTERN_C type STDAPICALLTYPE
  419. #define STDMETHODIMP HRESULT STDMETHODCALLTYPE
  420. #define STDMETHODIMP_(type) type STDMETHODCALLTYPE
  421. // The 'V' versions allow Variable Argument lists.
  422. #define STDAPIV EXTERN_C HRESULT STDAPIVCALLTYPE
  423. #define STDAPIV_(type) EXTERN_C type STDAPIVCALLTYPE
  424. #define STDMETHODIMPV HRESULT STDMETHODVCALLTYPE
  425. #define STDMETHODIMPV_(type) type STDMETHODVCALLTYPE
  426. // end_winnt
  427. //
  428. // Low order two bits of a handle are ignored by the system and available
  429. // for use by application code as tag bits. The remaining bits are opaque
  430. // and used to store a serial number and table index.
  431. //
  432. #define OBJ_HANDLE_TAGBITS 0x00000003L
  433. //
  434. // Cardinal Data Types [0 - 2**N-2)
  435. //
  436. typedef char CCHAR; // winnt
  437. typedef short CSHORT;
  438. typedef ULONG CLONG;
  439. typedef CCHAR *PCCHAR;
  440. typedef CSHORT *PCSHORT;
  441. typedef CLONG *PCLONG;
  442. //
  443. // NTSTATUS
  444. //
  445. typedef LONG NTSTATUS;
  446. /*lint -save -e624 */ // Don't complain about different typedefs.
  447. typedef NTSTATUS *PNTSTATUS;
  448. /*lint -restore */ // Resume checking for different typedefs.
  449. //
  450. // Status values are 32 bit values layed out as follows:
  451. //
  452. // 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
  453. // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  454. // +---+-+-------------------------+-------------------------------+
  455. // |Sev|C| Facility | Code |
  456. // +---+-+-------------------------+-------------------------------+
  457. //
  458. // where
  459. //
  460. // Sev - is the severity code
  461. //
  462. // 00 - Success
  463. // 01 - Informational
  464. // 10 - Warning
  465. // 11 - Error
  466. //
  467. // C - is the Customer code flag
  468. //
  469. // Facility - is the facility code
  470. //
  471. // Code - is the facility's status code
  472. //
  473. //
  474. // Generic test for success on any status value (non-negative numbers
  475. // indicate success).
  476. //
  477. #define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
  478. //
  479. // Generic test for information on any status value.
  480. //
  481. #define NT_INFORMATION(Status) ((ULONG)(Status) >> 30 == 1)
  482. //
  483. // Generic test for warning on any status value.
  484. //
  485. #define NT_WARNING(Status) ((ULONG)(Status) >> 30 == 2)
  486. //
  487. // Generic test for error on any status value.
  488. //
  489. #define NT_ERROR(Status) ((ULONG)(Status) >> 30 == 3)
  490. // end_windbgkd
  491. // begin_winnt
  492. #define APPLICATION_ERROR_MASK 0x20000000
  493. #define ERROR_SEVERITY_SUCCESS 0x00000000
  494. #define ERROR_SEVERITY_INFORMATIONAL 0x40000000
  495. #define ERROR_SEVERITY_WARNING 0x80000000
  496. #define ERROR_SEVERITY_ERROR 0xC0000000
  497. // end_winnt
  498. #ifndef __SECSTATUS_DEFINED__
  499. typedef long SECURITY_STATUS;
  500. #define __SECSTATUS_DEFINED__
  501. #endif
  502. //
  503. // __int64 is only supported by 2.0 and later midl.
  504. // __midl is set by the 2.0 midl and not by 1.0 midl.
  505. //
  506. #define _ULONGLONG_
  507. #if (!defined (_MAC) && (!defined(MIDL_PASS) || defined(__midl)) && (!defined(_M_IX86) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64)))
  508. typedef __int64 LONGLONG;
  509. typedef unsigned __int64 ULONGLONG;
  510. #define MAXLONGLONG (0x7fffffffffffffff)
  511. #else
  512. #if defined(_MAC) && defined(_MAC_INT_64)
  513. typedef __int64 LONGLONG;
  514. typedef unsigned __int64 ULONGLONG;
  515. #define MAXLONGLONG (0x7fffffffffffffff)
  516. #else
  517. typedef double LONGLONG;
  518. typedef double ULONGLONG;
  519. #endif //_MAC and int64
  520. #endif
  521. typedef LONGLONG *PLONGLONG;
  522. typedef ULONGLONG *PULONGLONG;
  523. // Update Sequence Number
  524. typedef LONGLONG USN;
  525. #if defined(MIDL_PASS)
  526. typedef struct _LARGE_INTEGER {
  527. #else // MIDL_PASS
  528. typedef union _LARGE_INTEGER {
  529. struct {
  530. ULONG LowPart;
  531. LONG HighPart;
  532. };
  533. struct {
  534. ULONG LowPart;
  535. LONG HighPart;
  536. } u;
  537. #endif //MIDL_PASS
  538. LONGLONG QuadPart;
  539. } LARGE_INTEGER;
  540. typedef LARGE_INTEGER *PLARGE_INTEGER;
  541. #if defined(MIDL_PASS)
  542. typedef struct _ULARGE_INTEGER {
  543. #else // MIDL_PASS
  544. typedef union _ULARGE_INTEGER {
  545. struct {
  546. ULONG LowPart;
  547. ULONG HighPart;
  548. };
  549. struct {
  550. ULONG LowPart;
  551. ULONG HighPart;
  552. } u;
  553. #endif //MIDL_PASS
  554. ULONGLONG QuadPart;
  555. } ULARGE_INTEGER;
  556. typedef ULARGE_INTEGER *PULARGE_INTEGER;
  557. //
  558. // Physical address.
  559. //
  560. typedef LARGE_INTEGER PHYSICAL_ADDRESS, *PPHYSICAL_ADDRESS;
  561. //
  562. // Counted String
  563. //
  564. typedef USHORT RTL_STRING_LENGTH_TYPE;
  565. typedef struct _STRING {
  566. USHORT Length;
  567. USHORT MaximumLength;
  568. #ifdef MIDL_PASS
  569. [size_is(MaximumLength), length_is(Length) ]
  570. #endif // MIDL_PASS
  571. PCHAR Buffer;
  572. } STRING;
  573. typedef STRING *PSTRING;
  574. typedef STRING ANSI_STRING;
  575. typedef PSTRING PANSI_STRING;
  576. typedef STRING OEM_STRING;
  577. typedef PSTRING POEM_STRING;
  578. typedef CONST STRING* PCOEM_STRING;
  579. //
  580. // CONSTCounted String
  581. //
  582. typedef struct _CSTRING {
  583. USHORT Length;
  584. USHORT MaximumLength;
  585. CONST char *Buffer;
  586. } CSTRING;
  587. typedef CSTRING *PCSTRING;
  588. #define ANSI_NULL ((CHAR)0) // winnt
  589. typedef STRING CANSI_STRING;
  590. typedef PSTRING PCANSI_STRING;
  591. //
  592. // Unicode strings are counted 16-bit character strings. If they are
  593. // NULL terminated, Length does not include trailing NULL.
  594. //
  595. typedef struct _UNICODE_STRING {
  596. USHORT Length;
  597. USHORT MaximumLength;
  598. #ifdef MIDL_PASS
  599. [size_is(MaximumLength / 2), length_is((Length) / 2) ] USHORT * Buffer;
  600. #else // MIDL_PASS
  601. PWSTR Buffer;
  602. #endif // MIDL_PASS
  603. } UNICODE_STRING;
  604. typedef UNICODE_STRING *PUNICODE_STRING;
  605. typedef const UNICODE_STRING *PCUNICODE_STRING;
  606. #define UNICODE_NULL ((WCHAR)0) // winnt
  607. #if _WIN32_WINNT >= 0x0501
  608. #define UNICODE_STRING_MAX_BYTES ((USHORT) 65534) // winnt
  609. #define UNICODE_STRING_MAX_CHARS (32767) // winnt
  610. #define DECLARE_CONST_UNICODE_STRING(_variablename, _string) \
  611. const WCHAR _variablename ## _buffer[] = _string; \
  612. const UNICODE_STRING _variablename = { sizeof(_string) - sizeof(WCHAR), sizeof(_string), (PWSTR) _variablename ## _buffer };
  613. #endif // _WIN32_WINNT >= 0x0501
  614. // begin_ntminiport begin_ntminitape
  615. //
  616. // Boolean
  617. //
  618. typedef UCHAR BOOLEAN; // winnt
  619. typedef BOOLEAN *PBOOLEAN; // winnt
  620. // end_ntminiport end_ntminitape
  621. // begin_winnt
  622. //
  623. // Doubly linked list structure. Can be used as either a list head, or
  624. // as link words.
  625. //
  626. typedef struct _LIST_ENTRY {
  627. struct _LIST_ENTRY *Flink;
  628. struct _LIST_ENTRY *Blink;
  629. } LIST_ENTRY, *PLIST_ENTRY, *RESTRICTED_POINTER PRLIST_ENTRY;
  630. //
  631. // Singly linked list structure. Can be used as either a list head, or
  632. // as link words.
  633. //
  634. typedef struct _SINGLE_LIST_ENTRY {
  635. struct _SINGLE_LIST_ENTRY *Next;
  636. } SINGLE_LIST_ENTRY, *PSINGLE_LIST_ENTRY;
  637. //
  638. // Constants
  639. //
  640. #define FALSE 0
  641. #define TRUE 1
  642. #ifndef NULL
  643. #ifdef __cplusplus
  644. #define NULL 0
  645. #define NULL64 0
  646. #else
  647. #define NULL ((void *)0)
  648. #define NULL64 ((void * POINTER_64)0)
  649. #endif
  650. #endif // NULL
  651. #include <guiddef.h>
  652. #ifndef __OBJECTID_DEFINED
  653. #define __OBJECTID_DEFINED
  654. typedef struct _OBJECTID { // size is 20
  655. GUID Lineage;
  656. ULONG Uniquifier;
  657. } OBJECTID;
  658. #endif // !_OBJECTID_DEFINED
  659. //
  660. // Determine if an argument is present by testing the value of the pointer
  661. // to the argument value.
  662. //
  663. #define ARGUMENT_PRESENT(ArgumentPointer) (\
  664. (CHAR *)((ULONG_PTR)(ArgumentPointer)) != (CHAR *)(NULL) )
  665. // begin_winnt begin_ntminiport
  666. //
  667. // Calculate the byte offset of a field in a structure of type type.
  668. //
  669. #define FIELD_OFFSET(type, field) ((LONG)(LONG_PTR)&(((type *)0)->field))
  670. //
  671. // Calculate the size of a field in a structure of type type, without
  672. // knowing or stating the type of the field.
  673. //
  674. #define RTL_FIELD_SIZE(type, field) (sizeof(((type *)0)->field))
  675. //
  676. // Calculate the size of a structure of type type up through and
  677. // including a field.
  678. //
  679. #define RTL_SIZEOF_THROUGH_FIELD(type, field) \
  680. (FIELD_OFFSET(type, field) + RTL_FIELD_SIZE(type, field))
  681. //
  682. // RTL_CONTAINS_FIELD usage:
  683. //
  684. // if (RTL_CONTAINS_FIELD(pBlock, pBlock->cbSize, dwMumble)) { // safe to use pBlock->dwMumble
  685. //
  686. #define RTL_CONTAINS_FIELD(Struct, Size, Field) \
  687. ( (((PCHAR)(&(Struct)->Field)) + sizeof((Struct)->Field)) <= (((PCHAR)(Struct))+(Size)) )
  688. //
  689. // Return the number of elements in a statically sized array.
  690. // ULONG Buffer[100];
  691. // RTL_NUMBER_OF(Buffer) == 100
  692. // This is also popularly known as: NUMBER_OF, ARRSIZE, _countof, NELEM, etc.
  693. //
  694. #define RTL_NUMBER_OF(A) (sizeof(A)/sizeof((A)[0]))
  695. //
  696. // An expression that yields the type of a field in a struct.
  697. //
  698. #define RTL_FIELD_TYPE(type, field) (((type*)0)->field)
  699. // RTL_ to avoid collisions in the global namespace.
  700. //
  701. // Given typedef struct _FOO { BYTE Bar[123]; } FOO;
  702. // RTL_NUMBER_OF_FIELD(FOO, Bar) == 123
  703. //
  704. #define RTL_NUMBER_OF_FIELD(type, field) (RTL_NUMBER_OF(RTL_FIELD_TYPE(type, field)))
  705. //
  706. // eg:
  707. // typedef struct FOO {
  708. // ULONG Integer;
  709. // PVOID Pointer;
  710. // } FOO;
  711. //
  712. // RTL_PADDING_BETWEEN_FIELDS(FOO, Integer, Pointer) == 0 for Win32, 4 for Win64
  713. //
  714. #define RTL_PADDING_BETWEEN_FIELDS(T, F1, F2) \
  715. ((FIELD_OFFSET(T, F2) > FIELD_OFFSET(T, F1)) \
  716. ? (FIELD_OFFSET(T, F2) - FIELD_OFFSET(T, F1) - RTL_FIELD_SIZE(T, F1)) \
  717. : (FIELD_OFFSET(T, F1) - FIELD_OFFSET(T, F2) - RTL_FIELD_SIZE(T, F2)))
  718. // RTL_ to avoid collisions in the global namespace.
  719. #if defined(__cplusplus)
  720. #define RTL_CONST_CAST(type) const_cast<type>
  721. #else
  722. #define RTL_CONST_CAST(type) (type)
  723. #endif
  724. // end_winnt
  725. //
  726. // This works "generically" for Unicode and Ansi/Oem strings.
  727. // Usage:
  728. // const static UNICODE_STRING FooU = RTL_CONSTANT_STRING(L"Foo");
  729. // const static STRING Foo = RTL_CONSTANT_STRING( "Foo");
  730. // instead of the slower:
  731. // UNICODE_STRING FooU;
  732. // STRING Foo;
  733. // RtlInitUnicodeString(&FooU, L"Foo");
  734. // RtlInitString(&Foo , "Foo");
  735. //
  736. #define RTL_CONSTANT_STRING(s) { sizeof( s ) - sizeof( (s)[0] ), sizeof( s ), s }
  737. // begin_winnt
  738. // like sizeof
  739. // usually this would be * CHAR_BIT, but we don't necessarily have #include <limits.h>
  740. #define RTL_BITS_OF(sizeOfArg) (sizeof(sizeOfArg) * 8)
  741. #define RTL_BITS_OF_FIELD(type, field) (RTL_BITS_OF(RTL_FIELD_TYPE(type, field)))
  742. //
  743. // Calculate the address of the base of the structure given its type, and an
  744. // address of a field within the structure.
  745. //
  746. #define CONTAINING_RECORD(address, type, field) ((type *)( \
  747. (PCHAR)(address) - \
  748. (ULONG_PTR)(&((type *)0)->field)))
  749. //
  750. // Interrupt Request Level (IRQL)
  751. //
  752. typedef UCHAR KIRQL;
  753. typedef KIRQL *PKIRQL;
  754. //
  755. // Macros used to eliminate compiler warning generated when formal
  756. // parameters or local variables are not declared.
  757. //
  758. // Use DBG_UNREFERENCED_PARAMETER() when a parameter is not yet
  759. // referenced but will be once the module is completely developed.
  760. //
  761. // Use DBG_UNREFERENCED_LOCAL_VARIABLE() when a local variable is not yet
  762. // referenced but will be once the module is completely developed.
  763. //
  764. // Use UNREFERENCED_PARAMETER() if a parameter will never be referenced.
  765. //
  766. // DBG_UNREFERENCED_PARAMETER and DBG_UNREFERENCED_LOCAL_VARIABLE will
  767. // eventually be made into a null macro to help determine whether there
  768. // is unfinished work.
  769. //
  770. #if ! defined(lint)
  771. #define UNREFERENCED_PARAMETER(P) (P)
  772. #define DBG_UNREFERENCED_PARAMETER(P) (P)
  773. #define DBG_UNREFERENCED_LOCAL_VARIABLE(V) (V)
  774. #else // lint
  775. // Note: lint -e530 says don't complain about uninitialized variables for
  776. // this varible. Error 527 has to do with unreachable code.
  777. // -restore restores checking to the -save state
  778. #define UNREFERENCED_PARAMETER(P) \
  779. /*lint -save -e527 -e530 */ \
  780. { \
  781. (P) = (P); \
  782. } \
  783. /*lint -restore */
  784. #define DBG_UNREFERENCED_PARAMETER(P) \
  785. /*lint -save -e527 -e530 */ \
  786. { \
  787. (P) = (P); \
  788. } \
  789. /*lint -restore */
  790. #define DBG_UNREFERENCED_LOCAL_VARIABLE(V) \
  791. /*lint -save -e527 -e530 */ \
  792. { \
  793. (V) = (V); \
  794. } \
  795. /*lint -restore */
  796. #endif // lint
  797. //
  798. // Macro used to eliminate compiler warning 4715 within a switch statement
  799. // when all possible cases have already been accounted for.
  800. //
  801. // switch (a & 3) {
  802. // case 0: return 1;
  803. // case 1: return Foo();
  804. // case 2: return Bar();
  805. // case 3: return 1;
  806. // DEFAULT_UNREACHABLE;
  807. //
  808. #if (_MSC_VER > 1200)
  809. #define DEFAULT_UNREACHABLE default: __assume(0)
  810. #else
  811. //
  812. // Older compilers do not support __assume(), and there is no other free
  813. // method of eliminating the warning.
  814. //
  815. #define DEFAULT_UNREACHABLE
  816. #endif
  817. // end_winnt
  818. //
  819. // Define standard min and max macros
  820. //
  821. #ifndef NOMINMAX
  822. #ifndef min
  823. #define min(a,b) (((a) < (b)) ? (a) : (b))
  824. #endif
  825. #ifndef max
  826. #define max(a,b) (((a) > (b)) ? (a) : (b))
  827. #endif
  828. #endif // NOMINMAX
  829. //
  830. // Processor modes.
  831. //
  832. typedef CCHAR KPROCESSOR_MODE;
  833. typedef enum _MODE {
  834. KernelMode,
  835. UserMode,
  836. MaximumMode
  837. } MODE;
  838. //
  839. // DPC routine
  840. //
  841. struct _KDPC;
  842. typedef
  843. VOID
  844. (*PKDEFERRED_ROUTINE) (
  845. IN struct _KDPC *Dpc,
  846. IN PVOID DeferredContext,
  847. IN PVOID SystemArgument1,
  848. IN PVOID SystemArgument2
  849. );
  850. //
  851. // Define DPC importance.
  852. //
  853. // LowImportance - Queue DPC at end of target DPC queue.
  854. // MediumImportance - Queue DPC at end of target DPC queue.
  855. // HighImportance - Queue DPC at front of target DPC DPC queue.
  856. //
  857. // If there is currently a DPC active on the target processor, or a DPC
  858. // interrupt has already been requested on the target processor when a
  859. // DPC is queued, then no further action is necessary. The DPC will be
  860. // executed on the target processor when its queue entry is processed.
  861. //
  862. // If there is not a DPC active on the target processor and a DPC interrupt
  863. // has not been requested on the target processor, then the exact treatment
  864. // of the DPC is dependent on whether the host system is a UP system or an
  865. // MP system.
  866. //
  867. // UP system.
  868. //
  869. // If the DPC is of medium or high importance, the current DPC queue depth
  870. // is greater than the maximum target depth, or current DPC request rate is
  871. // less the minimum target rate, then a DPC interrupt is requested on the
  872. // host processor and the DPC will be processed when the interrupt occurs.
  873. // Otherwise, no DPC interupt is requested and the DPC execution will be
  874. // delayed until the DPC queue depth is greater that the target depth or the
  875. // minimum DPC rate is less than the target rate.
  876. //
  877. // MP system.
  878. //
  879. // If the DPC is being queued to another processor and the depth of the DPC
  880. // queue on the target processor is greater than the maximum target depth or
  881. // the DPC is of high importance, then a DPC interrupt is requested on the
  882. // target processor and the DPC will be processed when the interrupt occurs.
  883. // Otherwise, the DPC execution will be delayed on the target processor until
  884. // the DPC queue depth on the target processor is greater that the maximum
  885. // target depth or the minimum DPC rate on the target processor is less than
  886. // the target mimimum rate.
  887. //
  888. // If the DPC is being queued to the current processor and the DPC is not of
  889. // low importance, the current DPC queue depth is greater than the maximum
  890. // target depth, or the minimum DPC rate is less than the minimum target rate,
  891. // then a DPC interrupt is request on the current processor and the DPV will
  892. // be processed whne the interrupt occurs. Otherwise, no DPC interupt is
  893. // requested and the DPC execution will be delayed until the DPC queue depth
  894. // is greater that the target depth or the minimum DPC rate is less than the
  895. // target rate.
  896. //
  897. typedef enum _KDPC_IMPORTANCE {
  898. LowImportance,
  899. MediumImportance,
  900. HighImportance
  901. } KDPC_IMPORTANCE;
  902. //
  903. // Define DPC type indicies.
  904. //
  905. #define DPC_NORMAL 0
  906. #define DPC_THREADED 1
  907. //
  908. // Deferred Procedure Call (DPC) object
  909. //
  910. typedef struct _KDPC {
  911. CSHORT Type;
  912. UCHAR Number;
  913. UCHAR Importance;
  914. LIST_ENTRY DpcListEntry;
  915. PKDEFERRED_ROUTINE DeferredRoutine;
  916. PVOID DeferredContext;
  917. PVOID SystemArgument1;
  918. PVOID SystemArgument2;
  919. PVOID DpcData;
  920. } KDPC, *PKDPC, *RESTRICTED_POINTER PRKDPC;
  921. //
  922. // Interprocessor interrupt worker routine function prototype.
  923. //
  924. typedef PVOID PKIPI_CONTEXT;
  925. typedef
  926. VOID
  927. (*PKIPI_WORKER)(
  928. IN PKIPI_CONTEXT PacketContext,
  929. IN PVOID Parameter1,
  930. IN PVOID Parameter2,
  931. IN PVOID Parameter3
  932. );
  933. //
  934. // Define interprocessor interrupt performance counters.
  935. //
  936. typedef struct _KIPI_COUNTS {
  937. ULONG Freeze;
  938. ULONG Packet;
  939. ULONG DPC;
  940. ULONG APC;
  941. ULONG FlushSingleTb;
  942. ULONG FlushMultipleTb;
  943. ULONG FlushEntireTb;
  944. ULONG GenericCall;
  945. ULONG ChangeColor;
  946. ULONG SweepDcache;
  947. ULONG SweepIcache;
  948. ULONG SweepIcacheRange;
  949. ULONG FlushIoBuffers;
  950. ULONG GratuitousDPC;
  951. } KIPI_COUNTS, *PKIPI_COUNTS;
  952. //
  953. // I/O system definitions.
  954. //
  955. // Define a Memory Descriptor List (MDL)
  956. //
  957. // An MDL describes pages in a virtual buffer in terms of physical pages. The
  958. // pages associated with the buffer are described in an array that is allocated
  959. // just after the MDL header structure itself.
  960. //
  961. // One simply calculates the base of the array by adding one to the base
  962. // MDL pointer:
  963. //
  964. // Pages = (PPFN_NUMBER) (Mdl + 1);
  965. //
  966. // Notice that while in the context of the subject thread, the base virtual
  967. // address of a buffer mapped by an MDL may be referenced using the following:
  968. //
  969. // Mdl->StartVa | Mdl->ByteOffset
  970. //
  971. typedef struct _MDL {
  972. struct _MDL *Next;
  973. CSHORT Size;
  974. CSHORT MdlFlags;
  975. struct _EPROCESS *Process;
  976. PVOID MappedSystemVa;
  977. PVOID StartVa;
  978. ULONG ByteCount;
  979. ULONG ByteOffset;
  980. } MDL, *PMDL;
  981. #define MDL_MAPPED_TO_SYSTEM_VA 0x0001
  982. #define MDL_PAGES_LOCKED 0x0002
  983. #define MDL_SOURCE_IS_NONPAGED_POOL 0x0004
  984. #define MDL_ALLOCATED_FIXED_SIZE 0x0008
  985. #define MDL_PARTIAL 0x0010
  986. #define MDL_PARTIAL_HAS_BEEN_MAPPED 0x0020
  987. #define MDL_IO_PAGE_READ 0x0040
  988. #define MDL_WRITE_OPERATION 0x0080
  989. #define MDL_PARENT_MAPPED_SYSTEM_VA 0x0100
  990. #define MDL_FREE_EXTRA_PTES 0x0200
  991. #define MDL_DESCRIBES_AWE 0x0400
  992. #define MDL_IO_SPACE 0x0800
  993. #define MDL_NETWORK_HEADER 0x1000
  994. #define MDL_MAPPING_CAN_FAIL 0x2000
  995. #define MDL_ALLOCATED_MUST_SUCCEED 0x4000
  996. #define MDL_MAPPING_FLAGS (MDL_MAPPED_TO_SYSTEM_VA | \
  997. MDL_PAGES_LOCKED | \
  998. MDL_SOURCE_IS_NONPAGED_POOL | \
  999. MDL_PARTIAL_HAS_BEEN_MAPPED | \
  1000. MDL_PARENT_MAPPED_SYSTEM_VA | \
  1001. MDL_SYSTEM_VA | \
  1002. MDL_IO_SPACE )
  1003. #define NTKERNELAPI DECLSPEC_IMPORT
  1004. #define NTHALAPI DECLSPEC_IMPORT
  1005. //
  1006. // Common dispatcher object header
  1007. //
  1008. // N.B. The size field contains the number of dwords in the structure.
  1009. //
  1010. typedef struct _DISPATCHER_HEADER {
  1011. union {
  1012. struct {
  1013. UCHAR Type;
  1014. UCHAR Absolute;
  1015. UCHAR Size;
  1016. union {
  1017. UCHAR Inserted;
  1018. BOOLEAN DebugActive;
  1019. };
  1020. };
  1021. volatile LONG Lock;
  1022. };
  1023. LONG SignalState;
  1024. LIST_ENTRY WaitListHead;
  1025. } DISPATCHER_HEADER;
  1026. //
  1027. // Event object
  1028. //
  1029. typedef struct _KEVENT {
  1030. DISPATCHER_HEADER Header;
  1031. } KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
  1032. //
  1033. // Timer object
  1034. //
  1035. typedef struct _KTIMER {
  1036. DISPATCHER_HEADER Header;
  1037. ULARGE_INTEGER DueTime;
  1038. LIST_ENTRY TimerListEntry;
  1039. struct _KDPC *Dpc;
  1040. LONG Period;
  1041. } KTIMER, *PKTIMER, *RESTRICTED_POINTER PRKTIMER;
  1042. typedef enum _LOCK_OPERATION {
  1043. IoReadAccess,
  1044. IoWriteAccess,
  1045. IoModifyAccess
  1046. } LOCK_OPERATION;
  1047. typedef ULONG_PTR KSPIN_LOCK;
  1048. typedef KSPIN_LOCK *PKSPIN_LOCK;
  1049. //
  1050. // Define the I/O bus interface types.
  1051. //
  1052. typedef enum _INTERFACE_TYPE {
  1053. InterfaceTypeUndefined = -1,
  1054. Internal,
  1055. Isa,
  1056. Eisa,
  1057. MicroChannel,
  1058. TurboChannel,
  1059. PCIBus,
  1060. VMEBus,
  1061. NuBus,
  1062. PCMCIABus,
  1063. CBus,
  1064. MPIBus,
  1065. MPSABus,
  1066. ProcessorInternal,
  1067. InternalPowerBus,
  1068. PNPISABus,
  1069. PNPBus,
  1070. MaximumInterfaceType
  1071. }INTERFACE_TYPE, *PINTERFACE_TYPE;
  1072. //
  1073. // Define the DMA transfer widths.
  1074. //
  1075. typedef enum _DMA_WIDTH {
  1076. Width8Bits,
  1077. Width16Bits,
  1078. Width32Bits,
  1079. MaximumDmaWidth
  1080. }DMA_WIDTH, *PDMA_WIDTH;
  1081. //
  1082. // Define DMA transfer speeds.
  1083. //
  1084. typedef enum _DMA_SPEED {
  1085. Compatible,
  1086. TypeA,
  1087. TypeB,
  1088. TypeC,
  1089. TypeF,
  1090. MaximumDmaSpeed
  1091. }DMA_SPEED, *PDMA_SPEED;
  1092. //
  1093. // Define Interface reference/dereference routines for
  1094. // Interfaces exported by IRP_MN_QUERY_INTERFACE
  1095. //
  1096. typedef VOID (*PINTERFACE_REFERENCE)(PVOID Context);
  1097. typedef VOID (*PINTERFACE_DEREFERENCE)(PVOID Context);
  1098. // end_wdm
  1099. //
  1100. // Define types of bus information.
  1101. //
  1102. typedef enum _BUS_DATA_TYPE {
  1103. ConfigurationSpaceUndefined = -1,
  1104. Cmos,
  1105. EisaConfiguration,
  1106. Pos,
  1107. CbusConfiguration,
  1108. PCIConfiguration,
  1109. VMEConfiguration,
  1110. NuBusConfiguration,
  1111. PCMCIAConfiguration,
  1112. MPIConfiguration,
  1113. MPSAConfiguration,
  1114. PNPISAConfiguration,
  1115. SgiInternalConfiguration,
  1116. MaximumBusDataType
  1117. } BUS_DATA_TYPE, *PBUS_DATA_TYPE;
  1118. #ifndef _SLIST_HEADER_
  1119. #define _SLIST_HEADER_
  1120. #if defined(_WIN64)
  1121. //
  1122. // The type SINGLE_LIST_ENTRY is not suitable for use with SLISTs. For
  1123. // WIN64, an entry on an SLIST is required to be 16-byte aligned, while a
  1124. // SINGLE_LIST_ENTRY structure has only 8 byte alignment.
  1125. //
  1126. // Therefore, all SLIST code should use the SLIST_ENTRY type instead of the
  1127. // SINGLE_LIST_ENTRY type.
  1128. //
  1129. #pragma warning(push)
  1130. #pragma warning(disable:4324) // structure padded due to align()
  1131. typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY *PSLIST_ENTRY;
  1132. typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
  1133. PSLIST_ENTRY Next;
  1134. } SLIST_ENTRY;
  1135. #pragma warning(pop)
  1136. #else
  1137. #define SLIST_ENTRY SINGLE_LIST_ENTRY
  1138. #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
  1139. #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
  1140. #endif
  1141. #if defined(_WIN64)
  1142. typedef struct DECLSPEC_ALIGN(16) _SLIST_HEADER {
  1143. ULONGLONG Alignment;
  1144. ULONGLONG Region;
  1145. } SLIST_HEADER;
  1146. typedef struct _SLIST_HEADER *PSLIST_HEADER;
  1147. #else
  1148. typedef union _SLIST_HEADER {
  1149. ULONGLONG Alignment;
  1150. struct {
  1151. SLIST_ENTRY Next;
  1152. USHORT Depth;
  1153. USHORT Sequence;
  1154. };
  1155. } SLIST_HEADER, *PSLIST_HEADER;
  1156. #endif
  1157. #endif
  1158. //
  1159. // If debugging support enabled, define an ASSERT macro that works. Otherwise
  1160. // define the ASSERT macro to expand to an empty expression.
  1161. //
  1162. // The ASSERT macro has been updated to be an expression instead of a statement.
  1163. //
  1164. NTSYSAPI
  1165. VOID
  1166. NTAPI
  1167. RtlAssert(
  1168. PVOID FailedAssertion,
  1169. PVOID FileName,
  1170. ULONG LineNumber,
  1171. PCHAR Message
  1172. );
  1173. #if DBG
  1174. #define ASSERT( exp ) \
  1175. ((!(exp)) ? \
  1176. (RtlAssert( #exp, __FILE__, __LINE__, NULL ),FALSE) : \
  1177. TRUE)
  1178. #define ASSERTMSG( msg, exp ) \
  1179. ((!(exp)) ? \
  1180. (RtlAssert( #exp, __FILE__, __LINE__, msg ),FALSE) : \
  1181. TRUE)
  1182. #define RTL_SOFT_ASSERT(_exp) \
  1183. ((!(_exp)) ? \
  1184. (DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n", __FILE__, __LINE__, #_exp),FALSE) : \
  1185. TRUE)
  1186. #define RTL_SOFT_ASSERTMSG(_msg, _exp) \
  1187. ((!(_exp)) ? \
  1188. (DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n Message: %s\n", __FILE__, __LINE__, #_exp, (_msg)),FALSE) : \
  1189. TRUE)
  1190. #define RTL_VERIFY ASSERT
  1191. #define RTL_VERIFYMSG ASSERTMSG
  1192. #define RTL_SOFT_VERIFY RTL_SOFT_ASSERT
  1193. #define RTL_SOFT_VERIFYMSG RTL_SOFT_ASSERTMSG
  1194. #else
  1195. #define ASSERT( exp ) ((void) 0)
  1196. #define ASSERTMSG( msg, exp ) ((void) 0)
  1197. #define RTL_SOFT_ASSERT(_exp) ((void) 0)
  1198. #define RTL_SOFT_ASSERTMSG(_msg, _exp) ((void) 0)
  1199. #define RTL_VERIFY( exp ) ((exp) ? TRUE : FALSE)
  1200. #define RTL_VERIFYMSG( msg, exp ) ((exp) ? TRUE : FALSE)
  1201. #define RTL_SOFT_VERIFY(_exp) ((_exp) ? TRUE : FALSE)
  1202. #define RTL_SOFT_VERIFYMSG(msg, _exp) ((_exp) ? TRUE : FALSE)
  1203. #endif // DBG
  1204. //
  1205. // Doubly-linked list manipulation routines.
  1206. //
  1207. //
  1208. // VOID
  1209. // InitializeListHead32(
  1210. // PLIST_ENTRY32 ListHead
  1211. // );
  1212. //
  1213. #define InitializeListHead32(ListHead) (\
  1214. (ListHead)->Flink = (ListHead)->Blink = PtrToUlong((ListHead)))
  1215. #if !defined(MIDL_PASS) && !defined(SORTPP_PASS)
  1216. VOID
  1217. FORCEINLINE
  1218. InitializeListHead(
  1219. IN PLIST_ENTRY ListHead
  1220. )
  1221. {
  1222. ListHead->Flink = ListHead->Blink = ListHead;
  1223. }
  1224. //
  1225. // BOOLEAN
  1226. // IsListEmpty(
  1227. // PLIST_ENTRY ListHead
  1228. // );
  1229. //
  1230. #define IsListEmpty(ListHead) \
  1231. ((ListHead)->Flink == (ListHead))
  1232. BOOLEAN
  1233. FORCEINLINE
  1234. RemoveEntryList(
  1235. IN PLIST_ENTRY Entry
  1236. )
  1237. {
  1238. PLIST_ENTRY Blink;
  1239. PLIST_ENTRY Flink;
  1240. Flink = Entry->Flink;
  1241. Blink = Entry->Blink;
  1242. Blink->Flink = Flink;
  1243. Flink->Blink = Blink;
  1244. return (BOOLEAN)(Flink == Blink);
  1245. }
  1246. PLIST_ENTRY
  1247. FORCEINLINE
  1248. RemoveHeadList(
  1249. IN PLIST_ENTRY ListHead
  1250. )
  1251. {
  1252. PLIST_ENTRY Flink;
  1253. PLIST_ENTRY Entry;
  1254. Entry = ListHead->Flink;
  1255. Flink = Entry->Flink;
  1256. ListHead->Flink = Flink;
  1257. Flink->Blink = ListHead;
  1258. return Entry;
  1259. }
  1260. PLIST_ENTRY
  1261. FORCEINLINE
  1262. RemoveTailList(
  1263. IN PLIST_ENTRY ListHead
  1264. )
  1265. {
  1266. PLIST_ENTRY Blink;
  1267. PLIST_ENTRY Entry;
  1268. Entry = ListHead->Blink;
  1269. Blink = Entry->Blink;
  1270. ListHead->Blink = Blink;
  1271. Blink->Flink = ListHead;
  1272. return Entry;
  1273. }
  1274. VOID
  1275. FORCEINLINE
  1276. InsertTailList(
  1277. IN PLIST_ENTRY ListHead,
  1278. IN PLIST_ENTRY Entry
  1279. )
  1280. {
  1281. PLIST_ENTRY Blink;
  1282. Blink = ListHead->Blink;
  1283. Entry->Flink = ListHead;
  1284. Entry->Blink = Blink;
  1285. Blink->Flink = Entry;
  1286. ListHead->Blink = Entry;
  1287. }
  1288. VOID
  1289. FORCEINLINE
  1290. InsertHeadList(
  1291. IN PLIST_ENTRY ListHead,
  1292. IN PLIST_ENTRY Entry
  1293. )
  1294. {
  1295. PLIST_ENTRY Flink;
  1296. Flink = ListHead->Flink;
  1297. Entry->Flink = Flink;
  1298. Entry->Blink = ListHead;
  1299. Flink->Blink = Entry;
  1300. ListHead->Flink = Entry;
  1301. }
  1302. //
  1303. //
  1304. // PSINGLE_LIST_ENTRY
  1305. // PopEntryList(
  1306. // PSINGLE_LIST_ENTRY ListHead
  1307. // );
  1308. //
  1309. #define PopEntryList(ListHead) \
  1310. (ListHead)->Next;\
  1311. {\
  1312. PSINGLE_LIST_ENTRY FirstEntry;\
  1313. FirstEntry = (ListHead)->Next;\
  1314. if (FirstEntry != NULL) { \
  1315. (ListHead)->Next = FirstEntry->Next;\
  1316. } \
  1317. }
  1318. //
  1319. // VOID
  1320. // PushEntryList(
  1321. // PSINGLE_LIST_ENTRY ListHead,
  1322. // PSINGLE_LIST_ENTRY Entry
  1323. // );
  1324. //
  1325. #define PushEntryList(ListHead,Entry) \
  1326. (Entry)->Next = (ListHead)->Next; \
  1327. (ListHead)->Next = (Entry)
  1328. #endif // !MIDL_PASS
  1329. #if defined (_MSC_VER) && ( _MSC_VER >= 900 )
  1330. PVOID
  1331. _ReturnAddress (
  1332. VOID
  1333. );
  1334. #pragma intrinsic(_ReturnAddress)
  1335. #endif
  1336. #if (defined(_M_AMD64) || defined(_M_IA64)) && !defined(_REALLY_GET_CALLERS_CALLER_)
  1337. #define RtlGetCallersAddress(CallersAddress, CallersCaller) \
  1338. *CallersAddress = (PVOID)_ReturnAddress(); \
  1339. *CallersCaller = NULL;
  1340. #else
  1341. NTSYSAPI
  1342. VOID
  1343. NTAPI
  1344. RtlGetCallersAddress(
  1345. OUT PVOID *CallersAddress,
  1346. OUT PVOID *CallersCaller
  1347. );
  1348. #endif
  1349. NTSYSAPI
  1350. ULONG
  1351. NTAPI
  1352. RtlWalkFrameChain (
  1353. OUT PVOID *Callers,
  1354. IN ULONG Count,
  1355. IN ULONG Flags
  1356. );
  1357. NTSYSAPI
  1358. NTSTATUS
  1359. NTAPI
  1360. RtlUnicodeStringToAnsiString(
  1361. PANSI_STRING DestinationString,
  1362. PCUNICODE_STRING SourceString,
  1363. BOOLEAN AllocateDestinationString
  1364. );
  1365. NTSYSAPI
  1366. LONG
  1367. NTAPI
  1368. RtlCompareUnicodeString(
  1369. PCUNICODE_STRING String1,
  1370. PCUNICODE_STRING String2,
  1371. BOOLEAN CaseInSensitive
  1372. );
  1373. NTSYSAPI
  1374. BOOLEAN
  1375. NTAPI
  1376. RtlEqualUnicodeString(
  1377. PCUNICODE_STRING String1,
  1378. PCUNICODE_STRING String2,
  1379. BOOLEAN CaseInSensitive
  1380. );
  1381. #define HASH_STRING_ALGORITHM_DEFAULT (0)
  1382. #define HASH_STRING_ALGORITHM_X65599 (1)
  1383. #define HASH_STRING_ALGORITHM_INVALID (0xffffffff)
  1384. NTSYSAPI
  1385. NTSTATUS
  1386. NTAPI
  1387. RtlHashUnicodeString(
  1388. IN const UNICODE_STRING *String,
  1389. IN BOOLEAN CaseInSensitive,
  1390. IN ULONG HashAlgorithm,
  1391. OUT PULONG HashValue
  1392. );
  1393. NTSYSAPI
  1394. BOOLEAN
  1395. NTAPI
  1396. RtlPrefixUnicodeString(
  1397. IN PCUNICODE_STRING String1,
  1398. IN PCUNICODE_STRING String2,
  1399. IN BOOLEAN CaseInSensitive
  1400. );
  1401. NTSYSAPI
  1402. NTSTATUS
  1403. NTAPI
  1404. RtlUpcaseUnicodeString(
  1405. PUNICODE_STRING DestinationString,
  1406. PCUNICODE_STRING SourceString,
  1407. BOOLEAN AllocateDestinationString
  1408. );
  1409. NTSYSAPI
  1410. VOID
  1411. NTAPI
  1412. RtlCopyUnicodeString(
  1413. PUNICODE_STRING DestinationString,
  1414. PCUNICODE_STRING SourceString
  1415. );
  1416. NTSYSAPI
  1417. NTSTATUS
  1418. NTAPI
  1419. RtlAppendUnicodeStringToString (
  1420. PUNICODE_STRING Destination,
  1421. PCUNICODE_STRING Source
  1422. );
  1423. NTSYSAPI
  1424. NTSTATUS
  1425. NTAPI
  1426. RtlAppendUnicodeToString (
  1427. PUNICODE_STRING Destination,
  1428. PCWSTR Source
  1429. );
  1430. NTSYSAPI
  1431. SIZE_T
  1432. NTAPI
  1433. RtlCompareMemory (
  1434. const VOID *Source1,
  1435. const VOID *Source2,
  1436. SIZE_T Length
  1437. );
  1438. #define RtlEqualMemory(Destination,Source,Length) (!memcmp((Destination),(Source),(Length)))
  1439. #if defined(_M_AMD64)
  1440. NTSYSAPI
  1441. VOID
  1442. NTAPI
  1443. RtlCopyMemory (
  1444. VOID UNALIGNED *Destination,
  1445. CONST VOID UNALIGNED *Source,
  1446. SIZE_T Length
  1447. );
  1448. NTSYSAPI
  1449. VOID
  1450. NTAPI
  1451. RtlMoveMemory (
  1452. VOID UNALIGNED *Destination,
  1453. CONST VOID UNALIGNED *Source,
  1454. SIZE_T Length
  1455. );
  1456. NTSYSAPI
  1457. VOID
  1458. NTAPI
  1459. RtlFillMemory (
  1460. VOID UNALIGNED *Destination,
  1461. SIZE_T Length,
  1462. IN UCHAR Fill
  1463. );
  1464. NTSYSAPI
  1465. VOID
  1466. NTAPI
  1467. RtlZeroMemory (
  1468. VOID UNALIGNED *Destination,
  1469. SIZE_T Length
  1470. );
  1471. #else
  1472. #define RtlMoveMemory(Destination,Source,Length) memmove((Destination),(Source),(Length))
  1473. #define RtlCopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
  1474. #define RtlFillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
  1475. #define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
  1476. #endif
  1477. #if !defined(MIDL_PASS)
  1478. FORCEINLINE
  1479. PVOID
  1480. RtlSecureZeroMemory(
  1481. IN PVOID ptr,
  1482. IN SIZE_T cnt
  1483. )
  1484. {
  1485. volatile char *vptr = (volatile char *)ptr;
  1486. while (cnt) {
  1487. *vptr = 0;
  1488. vptr++;
  1489. cnt--;
  1490. }
  1491. return ptr;
  1492. }
  1493. #endif
  1494. //
  1495. // Define kernel debugger print prototypes and macros.
  1496. //
  1497. // N.B. The following function cannot be directly imported because there are
  1498. // a few places in the source tree where this function is redefined.
  1499. //
  1500. VOID
  1501. NTAPI
  1502. DbgBreakPoint(
  1503. VOID
  1504. );
  1505. // end_wdm
  1506. NTSYSAPI
  1507. VOID
  1508. NTAPI
  1509. DbgBreakPointWithStatus(
  1510. IN ULONG Status
  1511. );
  1512. // begin_wdm
  1513. #define DBG_STATUS_CONTROL_C 1
  1514. #define DBG_STATUS_SYSRQ 2
  1515. #define DBG_STATUS_BUGCHECK_FIRST 3
  1516. #define DBG_STATUS_BUGCHECK_SECOND 4
  1517. #define DBG_STATUS_FATAL 5
  1518. #define DBG_STATUS_DEBUG_CONTROL 6
  1519. #define DBG_STATUS_WORKER 7
  1520. #if DBG
  1521. #define KdPrint(_x_) DbgPrint _x_
  1522. // end_wdm
  1523. #define KdPrintEx(_x_) DbgPrintEx _x_
  1524. #define vKdPrintEx(_x_) vDbgPrintEx _x_
  1525. #define vKdPrintExWithPrefix(_x_) vDbgPrintExWithPrefix _x_
  1526. // begin_wdm
  1527. #define KdBreakPoint() DbgBreakPoint()
  1528. // end_wdm
  1529. #define KdBreakPointWithStatus(s) DbgBreakPointWithStatus(s)
  1530. // begin_wdm
  1531. #else
  1532. #define KdPrint(_x_)
  1533. // end_wdm
  1534. #define KdPrintEx(_x_)
  1535. #define vKdPrintEx(_x_)
  1536. #define vKdPrintExWithPrefix(_x_)
  1537. // begin_wdm
  1538. #define KdBreakPoint()
  1539. // end_wdm
  1540. #define KdBreakPointWithStatus(s)
  1541. // begin_wdm
  1542. #endif
  1543. #ifndef _DBGNT_
  1544. ULONG
  1545. __cdecl
  1546. DbgPrint(
  1547. PCH Format,
  1548. ...
  1549. );
  1550. // end_wdm
  1551. ULONG
  1552. __cdecl
  1553. DbgPrintEx(
  1554. IN ULONG ComponentId,
  1555. IN ULONG Level,
  1556. IN PCH Format,
  1557. ...
  1558. );
  1559. #ifdef _VA_LIST_DEFINED
  1560. ULONG
  1561. vDbgPrintEx(
  1562. IN ULONG ComponentId,
  1563. IN ULONG Level,
  1564. IN PCH Format,
  1565. va_list arglist
  1566. );
  1567. ULONG
  1568. vDbgPrintExWithPrefix(
  1569. IN PCH Prefix,
  1570. IN ULONG ComponentId,
  1571. IN ULONG Level,
  1572. IN PCH Format,
  1573. va_list arglist
  1574. );
  1575. #endif
  1576. ULONG
  1577. __cdecl
  1578. DbgPrintReturnControlC(
  1579. PCH Format,
  1580. ...
  1581. );
  1582. NTSYSAPI
  1583. NTSTATUS
  1584. DbgQueryDebugFilterState(
  1585. IN ULONG ComponentId,
  1586. IN ULONG Level
  1587. );
  1588. NTSYSAPI
  1589. NTSTATUS
  1590. DbgSetDebugFilterState(
  1591. IN ULONG ComponentId,
  1592. IN ULONG Level,
  1593. IN BOOLEAN State
  1594. );
  1595. // begin_wdm
  1596. #endif // _DBGNT_
  1597. //
  1598. // Component name filter id enumeration and levels.
  1599. //
  1600. #define DPFLTR_ERROR_LEVEL 0
  1601. #define DPFLTR_WARNING_LEVEL 1
  1602. #define DPFLTR_TRACE_LEVEL 2
  1603. #define DPFLTR_INFO_LEVEL 3
  1604. #define DPFLTR_MASK 0x80000000
  1605. typedef enum _DPFLTR_TYPE {
  1606. DPFLTR_SYSTEM_ID = 0,
  1607. DPFLTR_SMSS_ID = 1,
  1608. DPFLTR_SETUP_ID = 2,
  1609. DPFLTR_NTFS_ID = 3,
  1610. DPFLTR_FSTUB_ID = 4,
  1611. DPFLTR_CRASHDUMP_ID = 5,
  1612. DPFLTR_CDAUDIO_ID = 6,
  1613. DPFLTR_CDROM_ID = 7,
  1614. DPFLTR_CLASSPNP_ID = 8,
  1615. DPFLTR_DISK_ID = 9,
  1616. DPFLTR_REDBOOK_ID = 10,
  1617. DPFLTR_STORPROP_ID = 11,
  1618. DPFLTR_SCSIPORT_ID = 12,
  1619. DPFLTR_SCSIMINIPORT_ID = 13,
  1620. DPFLTR_CONFIG_ID = 14,
  1621. DPFLTR_I8042PRT_ID = 15,
  1622. DPFLTR_SERMOUSE_ID = 16,
  1623. DPFLTR_LSERMOUS_ID = 17,
  1624. DPFLTR_KBDHID_ID = 18,
  1625. DPFLTR_MOUHID_ID = 19,
  1626. DPFLTR_KBDCLASS_ID = 20,
  1627. DPFLTR_MOUCLASS_ID = 21,
  1628. DPFLTR_TWOTRACK_ID = 22,
  1629. DPFLTR_WMILIB_ID = 23,
  1630. DPFLTR_ACPI_ID = 24,
  1631. DPFLTR_AMLI_ID = 25,
  1632. DPFLTR_HALIA64_ID = 26,
  1633. DPFLTR_VIDEO_ID = 27,
  1634. DPFLTR_SVCHOST_ID = 28,
  1635. DPFLTR_VIDEOPRT_ID = 29,
  1636. DPFLTR_TCPIP_ID = 30,
  1637. DPFLTR_DMSYNTH_ID = 31,
  1638. DPFLTR_NTOSPNP_ID = 32,
  1639. DPFLTR_FASTFAT_ID = 33,
  1640. DPFLTR_SAMSS_ID = 34,
  1641. DPFLTR_PNPMGR_ID = 35,
  1642. DPFLTR_NETAPI_ID = 36,
  1643. DPFLTR_SCSERVER_ID = 37,
  1644. DPFLTR_SCCLIENT_ID = 38,
  1645. DPFLTR_SERIAL_ID = 39,
  1646. DPFLTR_SERENUM_ID = 40,
  1647. DPFLTR_UHCD_ID = 41,
  1648. DPFLTR_RPCPROXY_ID = 42,
  1649. DPFLTR_AUTOCHK_ID = 43,
  1650. DPFLTR_DCOMSS_ID = 44,
  1651. DPFLTR_UNIMODEM_ID = 45,
  1652. DPFLTR_SIS_ID = 46,
  1653. DPFLTR_FLTMGR_ID = 47,
  1654. DPFLTR_WMICORE_ID = 48,
  1655. DPFLTR_BURNENG_ID = 49,
  1656. DPFLTR_IMAPI_ID = 50,
  1657. DPFLTR_SXS_ID = 51,
  1658. DPFLTR_FUSION_ID = 52,
  1659. DPFLTR_IDLETASK_ID = 53,
  1660. DPFLTR_SOFTPCI_ID = 54,
  1661. DPFLTR_TAPE_ID = 55,
  1662. DPFLTR_MCHGR_ID = 56,
  1663. DPFLTR_IDEP_ID = 57,
  1664. DPFLTR_PCIIDE_ID = 58,
  1665. DPFLTR_FLOPPY_ID = 59,
  1666. DPFLTR_FDC_ID = 60,
  1667. DPFLTR_TERMSRV_ID = 61,
  1668. DPFLTR_W32TIME_ID = 62,
  1669. DPFLTR_PREFETCHER_ID = 63,
  1670. DPFLTR_RSFILTER_ID = 64,
  1671. DPFLTR_FCPORT_ID = 65,
  1672. DPFLTR_PCI_ID = 66,
  1673. DPFLTR_DMIO_ID = 67,
  1674. DPFLTR_DMCONFIG_ID = 68,
  1675. DPFLTR_DMADMIN_ID = 69,
  1676. DPFLTR_WSOCKTRANSPORT_ID = 70,
  1677. DPFLTR_VSS_ID = 71,
  1678. DPFLTR_PNPMEM_ID = 72,
  1679. DPFLTR_PROCESSOR_ID = 73,
  1680. DPFLTR_DMSERVER_ID = 74,
  1681. DPFLTR_SR_ID = 75,
  1682. DPFLTR_INFINIBAND_ID = 76,
  1683. DPFLTR_IHVDRIVER_ID = 77,
  1684. DPFLTR_IHVVIDEO_ID = 78,
  1685. DPFLTR_IHVAUDIO_ID = 79,
  1686. DPFLTR_IHVNETWORK_ID = 80,
  1687. DPFLTR_IHVSTREAMING_ID = 81,
  1688. DPFLTR_IHVBUS_ID = 82,
  1689. DPFLTR_HPS_ID = 83,
  1690. DPFLTR_RTLTHREADPOOL_ID = 84,
  1691. DPFLTR_LDR_ID = 85,
  1692. DPFLTR_TCPIP6_ID = 86,
  1693. DPFLTR_ISAPNP_ID = 87,
  1694. DPFLTR_SHPC_ID = 88,
  1695. DPFLTR_STORPORT_ID = 89,
  1696. DPFLTR_STORMINIPORT_ID = 90,
  1697. DPFLTR_PRINTSPOOLER_ID = 91,
  1698. DPFLTR_VSSDYNDISK_ID = 92,
  1699. DPFLTR_VERIFIER_ID = 93,
  1700. DPFLTR_VDS_ID = 94,
  1701. DPFLTR_VDSBAS_ID = 95,
  1702. DPFLTR_VDSDYNDR_ID = 96,
  1703. DPFLTR_VDSUTIL_ID = 97,
  1704. DPFLTR_DFRGIFC_ID = 98,
  1705. DPFLTR_ENDOFTABLE_ID
  1706. } DPFLTR_TYPE;
  1707. //
  1708. // Define I/O Driver error log packet structure. This structure is filled in
  1709. // by the driver.
  1710. //
  1711. typedef struct _IO_ERROR_LOG_PACKET {
  1712. UCHAR MajorFunctionCode;
  1713. UCHAR RetryCount;
  1714. USHORT DumpDataSize;
  1715. USHORT NumberOfStrings;
  1716. USHORT StringOffset;
  1717. USHORT EventCategory;
  1718. NTSTATUS ErrorCode;
  1719. ULONG UniqueErrorValue;
  1720. NTSTATUS FinalStatus;
  1721. ULONG SequenceNumber;
  1722. ULONG IoControlCode;
  1723. LARGE_INTEGER DeviceOffset;
  1724. ULONG DumpData[1];
  1725. }IO_ERROR_LOG_PACKET, *PIO_ERROR_LOG_PACKET;
  1726. //
  1727. // Define the I/O error log message. This message is sent by the error log
  1728. // thread over the lpc port.
  1729. //
  1730. typedef struct _IO_ERROR_LOG_MESSAGE {
  1731. USHORT Type;
  1732. USHORT Size;
  1733. USHORT DriverNameLength;
  1734. LARGE_INTEGER TimeStamp;
  1735. ULONG DriverNameOffset;
  1736. IO_ERROR_LOG_PACKET EntryData;
  1737. }IO_ERROR_LOG_MESSAGE, *PIO_ERROR_LOG_MESSAGE;
  1738. //
  1739. // Define the maximum message size that will be sent over the LPC to the
  1740. // application reading the error log entries.
  1741. //
  1742. //
  1743. // Regardless of LPC size restrictions, ERROR_LOG_MAXIMUM_SIZE must remain
  1744. // a value that can fit in a UCHAR.
  1745. //
  1746. #define ERROR_LOG_LIMIT_SIZE (256-16)
  1747. //
  1748. // This limit, exclusive of IO_ERROR_LOG_MESSAGE_HEADER_LENGTH, also applies
  1749. // to IO_ERROR_LOG_MESSAGE_LENGTH
  1750. //
  1751. #define IO_ERROR_LOG_MESSAGE_HEADER_LENGTH (sizeof(IO_ERROR_LOG_MESSAGE) - \
  1752. sizeof(IO_ERROR_LOG_PACKET) + \
  1753. (sizeof(WCHAR) * 40))
  1754. #define ERROR_LOG_MESSAGE_LIMIT_SIZE \
  1755. (ERROR_LOG_LIMIT_SIZE + IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
  1756. //
  1757. // IO_ERROR_LOG_MESSAGE_LENGTH is
  1758. // min(PORT_MAXIMUM_MESSAGE_LENGTH, ERROR_LOG_MESSAGE_LIMIT_SIZE)
  1759. //
  1760. #define IO_ERROR_LOG_MESSAGE_LENGTH \
  1761. ((PORT_MAXIMUM_MESSAGE_LENGTH > ERROR_LOG_MESSAGE_LIMIT_SIZE) ? \
  1762. ERROR_LOG_MESSAGE_LIMIT_SIZE : \
  1763. PORT_MAXIMUM_MESSAGE_LENGTH)
  1764. //
  1765. // Define the maximum packet size a driver can allocate.
  1766. //
  1767. #define ERROR_LOG_MAXIMUM_SIZE (IO_ERROR_LOG_MESSAGE_LENGTH - \
  1768. IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
  1769. #if defined(_X86_)
  1770. //
  1771. // Types to use to contain PFNs and their counts.
  1772. //
  1773. typedef ULONG PFN_COUNT;
  1774. typedef LONG SPFN_NUMBER, *PSPFN_NUMBER;
  1775. typedef ULONG PFN_NUMBER, *PPFN_NUMBER;
  1776. //
  1777. // Define maximum size of flush multiple TB request.
  1778. //
  1779. #define FLUSH_MULTIPLE_MAXIMUM 32
  1780. //
  1781. // Indicate that the i386 compiler supports the pragma textout construct.
  1782. //
  1783. #define ALLOC_PRAGMA 1
  1784. //
  1785. // Indicate that the i386 compiler supports the DATA_SEG("INIT") and
  1786. // DATA_SEG("PAGE") pragmas
  1787. //
  1788. #define ALLOC_DATA_PRAGMA 1
  1789. //
  1790. // I/O space read and write macros.
  1791. //
  1792. // These have to be actual functions on the 386, because we need
  1793. // to use assembler, but cannot return a value if we inline it.
  1794. //
  1795. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
  1796. // (Use x86 move instructions, with LOCK prefix to force correct behavior
  1797. // w.r.t. caches and write buffers.)
  1798. //
  1799. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
  1800. // (Use x86 in/out instructions.)
  1801. //
  1802. NTKERNELAPI
  1803. UCHAR
  1804. NTAPI
  1805. READ_REGISTER_UCHAR(
  1806. PUCHAR Register
  1807. );
  1808. NTKERNELAPI
  1809. USHORT
  1810. NTAPI
  1811. READ_REGISTER_USHORT(
  1812. PUSHORT Register
  1813. );
  1814. NTKERNELAPI
  1815. ULONG
  1816. NTAPI
  1817. READ_REGISTER_ULONG(
  1818. PULONG Register
  1819. );
  1820. NTKERNELAPI
  1821. VOID
  1822. NTAPI
  1823. READ_REGISTER_BUFFER_UCHAR(
  1824. PUCHAR Register,
  1825. PUCHAR Buffer,
  1826. ULONG Count
  1827. );
  1828. NTKERNELAPI
  1829. VOID
  1830. NTAPI
  1831. READ_REGISTER_BUFFER_USHORT(
  1832. PUSHORT Register,
  1833. PUSHORT Buffer,
  1834. ULONG Count
  1835. );
  1836. NTKERNELAPI
  1837. VOID
  1838. NTAPI
  1839. READ_REGISTER_BUFFER_ULONG(
  1840. PULONG Register,
  1841. PULONG Buffer,
  1842. ULONG Count
  1843. );
  1844. NTKERNELAPI
  1845. VOID
  1846. NTAPI
  1847. WRITE_REGISTER_UCHAR(
  1848. PUCHAR Register,
  1849. UCHAR Value
  1850. );
  1851. NTKERNELAPI
  1852. VOID
  1853. NTAPI
  1854. WRITE_REGISTER_USHORT(
  1855. PUSHORT Register,
  1856. USHORT Value
  1857. );
  1858. NTKERNELAPI
  1859. VOID
  1860. NTAPI
  1861. WRITE_REGISTER_ULONG(
  1862. PULONG Register,
  1863. ULONG Value
  1864. );
  1865. NTKERNELAPI
  1866. VOID
  1867. NTAPI
  1868. WRITE_REGISTER_BUFFER_UCHAR(
  1869. PUCHAR Register,
  1870. PUCHAR Buffer,
  1871. ULONG Count
  1872. );
  1873. NTKERNELAPI
  1874. VOID
  1875. NTAPI
  1876. WRITE_REGISTER_BUFFER_USHORT(
  1877. PUSHORT Register,
  1878. PUSHORT Buffer,
  1879. ULONG Count
  1880. );
  1881. NTKERNELAPI
  1882. VOID
  1883. NTAPI
  1884. WRITE_REGISTER_BUFFER_ULONG(
  1885. PULONG Register,
  1886. PULONG Buffer,
  1887. ULONG Count
  1888. );
  1889. NTHALAPI
  1890. UCHAR
  1891. NTAPI
  1892. READ_PORT_UCHAR(
  1893. PUCHAR Port
  1894. );
  1895. NTHALAPI
  1896. USHORT
  1897. NTAPI
  1898. READ_PORT_USHORT(
  1899. PUSHORT Port
  1900. );
  1901. NTHALAPI
  1902. ULONG
  1903. NTAPI
  1904. READ_PORT_ULONG(
  1905. PULONG Port
  1906. );
  1907. NTHALAPI
  1908. VOID
  1909. NTAPI
  1910. READ_PORT_BUFFER_UCHAR(
  1911. PUCHAR Port,
  1912. PUCHAR Buffer,
  1913. ULONG Count
  1914. );
  1915. NTHALAPI
  1916. VOID
  1917. NTAPI
  1918. READ_PORT_BUFFER_USHORT(
  1919. PUSHORT Port,
  1920. PUSHORT Buffer,
  1921. ULONG Count
  1922. );
  1923. NTHALAPI
  1924. VOID
  1925. NTAPI
  1926. READ_PORT_BUFFER_ULONG(
  1927. PULONG Port,
  1928. PULONG Buffer,
  1929. ULONG Count
  1930. );
  1931. NTHALAPI
  1932. VOID
  1933. NTAPI
  1934. WRITE_PORT_UCHAR(
  1935. PUCHAR Port,
  1936. UCHAR Value
  1937. );
  1938. NTHALAPI
  1939. VOID
  1940. NTAPI
  1941. WRITE_PORT_USHORT(
  1942. PUSHORT Port,
  1943. USHORT Value
  1944. );
  1945. NTHALAPI
  1946. VOID
  1947. NTAPI
  1948. WRITE_PORT_ULONG(
  1949. PULONG Port,
  1950. ULONG Value
  1951. );
  1952. NTHALAPI
  1953. VOID
  1954. NTAPI
  1955. WRITE_PORT_BUFFER_UCHAR(
  1956. PUCHAR Port,
  1957. PUCHAR Buffer,
  1958. ULONG Count
  1959. );
  1960. NTHALAPI
  1961. VOID
  1962. NTAPI
  1963. WRITE_PORT_BUFFER_USHORT(
  1964. PUSHORT Port,
  1965. PUSHORT Buffer,
  1966. ULONG Count
  1967. );
  1968. NTHALAPI
  1969. VOID
  1970. NTAPI
  1971. WRITE_PORT_BUFFER_ULONG(
  1972. PULONG Port,
  1973. PULONG Buffer,
  1974. ULONG Count
  1975. );
  1976. #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
  1977. //
  1978. // i386 Specific portions of mm component
  1979. //
  1980. //
  1981. // Define the page size for the Intel 386 as 4096 (0x1000).
  1982. //
  1983. #define PAGE_SIZE 0x1000
  1984. //
  1985. // Define the number of trailing zeroes in a page aligned virtual address.
  1986. // This is used as the shift count when shifting virtual addresses to
  1987. // virtual page numbers.
  1988. //
  1989. #define PAGE_SHIFT 12L
  1990. //++
  1991. //
  1992. // VOID
  1993. // KeMemoryBarrier (
  1994. // VOID
  1995. // )
  1996. //
  1997. // VOID
  1998. // KeMemoryBarrierWithoutFence (
  1999. // VOID
  2000. // )
  2001. //
  2002. //
  2003. // Routine Description:
  2004. //
  2005. // These functions order memory accesses as seen by other processors.
  2006. //
  2007. // Arguments:
  2008. //
  2009. // None.
  2010. //
  2011. // Return Value:
  2012. //
  2013. // None.
  2014. //
  2015. //--
  2016. #ifdef __cplusplus
  2017. extern "C" {
  2018. #endif
  2019. VOID
  2020. _ReadWriteBarrier(
  2021. VOID
  2022. );
  2023. #ifdef __cplusplus
  2024. }
  2025. #endif
  2026. #pragma intrinsic (_ReadWriteBarrier)
  2027. FORCEINLINE
  2028. VOID
  2029. KeMemoryBarrier (
  2030. VOID
  2031. )
  2032. {
  2033. LONG Barrier;
  2034. __asm {
  2035. xchg Barrier, eax
  2036. }
  2037. }
  2038. #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
  2039. #endif // defined(_X86_)
  2040. #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  2041. //
  2042. // Define intrinsic function to do in's and out's.
  2043. //
  2044. #ifdef __cplusplus
  2045. extern "C" {
  2046. #endif
  2047. UCHAR
  2048. __inbyte (
  2049. IN USHORT Port
  2050. );
  2051. USHORT
  2052. __inword (
  2053. IN USHORT Port
  2054. );
  2055. ULONG
  2056. __indword (
  2057. IN USHORT Port
  2058. );
  2059. VOID
  2060. __outbyte (
  2061. IN USHORT Port,
  2062. IN UCHAR Data
  2063. );
  2064. VOID
  2065. __outword (
  2066. IN USHORT Port,
  2067. IN USHORT Data
  2068. );
  2069. VOID
  2070. __outdword (
  2071. IN USHORT Port,
  2072. IN ULONG Data
  2073. );
  2074. VOID
  2075. __inbytestring (
  2076. IN USHORT Port,
  2077. IN PUCHAR Buffer,
  2078. IN ULONG Count
  2079. );
  2080. VOID
  2081. __inwordstring (
  2082. IN USHORT Port,
  2083. IN PUSHORT Buffer,
  2084. IN ULONG Count
  2085. );
  2086. VOID
  2087. __indwordstring (
  2088. IN USHORT Port,
  2089. IN PULONG Buffer,
  2090. IN ULONG Count
  2091. );
  2092. VOID
  2093. __outbytestring (
  2094. IN USHORT Port,
  2095. IN PUCHAR Buffer,
  2096. IN ULONG Count
  2097. );
  2098. VOID
  2099. __outwordstring (
  2100. IN USHORT Port,
  2101. IN PUSHORT Buffer,
  2102. IN ULONG Count
  2103. );
  2104. VOID
  2105. __outdwordstring (
  2106. IN USHORT Port,
  2107. IN PULONG Buffer,
  2108. IN ULONG Count
  2109. );
  2110. #ifdef __cplusplus
  2111. }
  2112. #endif
  2113. #pragma intrinsic(__inbyte)
  2114. #pragma intrinsic(__inword)
  2115. #pragma intrinsic(__indword)
  2116. #pragma intrinsic(__outbyte)
  2117. #pragma intrinsic(__outword)
  2118. #pragma intrinsic(__outdword)
  2119. #pragma intrinsic(__inbytestring)
  2120. #pragma intrinsic(__inwordstring)
  2121. #pragma intrinsic(__indwordstring)
  2122. #pragma intrinsic(__outbytestring)
  2123. #pragma intrinsic(__outwordstring)
  2124. #pragma intrinsic(__outdwordstring)
  2125. //
  2126. // Interlocked intrinsic functions.
  2127. //
  2128. #define InterlockedAnd _InterlockedAnd
  2129. #define InterlockedOr _InterlockedOr
  2130. #define InterlockedXor _InterlockedXor
  2131. #define InterlockedIncrement _InterlockedIncrement
  2132. #define InterlockedIncrementAcquire InterlockedIncrement
  2133. #define InterlockedIncrementRelease InterlockedIncrement
  2134. #define InterlockedDecrement _InterlockedDecrement
  2135. #define InterlockedDecrementAcquire InterlockedDecrement
  2136. #define InterlockedDecrementRelease InterlockedDecrement
  2137. #define InterlockedAdd _InterlockedAdd
  2138. #define InterlockedExchange _InterlockedExchange
  2139. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  2140. #define InterlockedCompareExchange _InterlockedCompareExchange
  2141. #define InterlockedCompareExchangeAcquire InterlockedCompareExchange
  2142. #define InterlockedCompareExchangeRelease InterlockedCompareExchange
  2143. #define InterlockedAnd64 _InterlockedAnd64
  2144. #define InterlockedOr64 _InterlockedOr64
  2145. #define InterlockedXor64 _InterlockedXor64
  2146. #define InterlockedIncrement64 _InterlockedIncrement64
  2147. #define InterlockedDecrement64 _InterlockedDecrement64
  2148. #define InterlockedAdd64 _InterlockedAdd64
  2149. #define InterlockedExchange64 _InterlockedExchange64
  2150. #define InterlockedExchangeAcquire64 InterlockedExchange64
  2151. #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
  2152. #define InterlockedCompareExchange64 _InterlockedCompareExchange64
  2153. #define InterlockedCompareExchangeAcquire64 InterlockedCompareExchange64
  2154. #define InterlockedCompareExchangeRelease64 InterlockedCompareExchange64
  2155. #define InterlockedExchangePointer _InterlockedExchangePointer
  2156. #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
  2157. #ifdef __cplusplus
  2158. extern "C" {
  2159. #endif
  2160. LONG
  2161. InterlockedAnd (
  2162. IN OUT LONG volatile *Destination,
  2163. IN LONG Value
  2164. );
  2165. LONG
  2166. InterlockedOr (
  2167. IN OUT LONG volatile *Destination,
  2168. IN LONG Value
  2169. );
  2170. LONG
  2171. InterlockedXor (
  2172. IN OUT LONG volatile *Destination,
  2173. IN LONG Value
  2174. );
  2175. LONG64
  2176. InterlockedAnd64 (
  2177. IN OUT LONG64 volatile *Destination,
  2178. IN LONG64 Value
  2179. );
  2180. LONG64
  2181. InterlockedOr64 (
  2182. IN OUT LONG64 volatile *Destination,
  2183. IN LONG64 Value
  2184. );
  2185. LONG64
  2186. InterlockedXor64 (
  2187. IN OUT LONG64 volatile *Destination,
  2188. IN LONG64 Value
  2189. );
  2190. LONG
  2191. InterlockedIncrement(
  2192. IN OUT LONG volatile *Addend
  2193. );
  2194. LONG
  2195. InterlockedDecrement(
  2196. IN OUT LONG volatile *Addend
  2197. );
  2198. LONG
  2199. InterlockedExchange(
  2200. IN OUT LONG volatile *Target,
  2201. IN LONG Value
  2202. );
  2203. LONG
  2204. InterlockedExchangeAdd(
  2205. IN OUT LONG volatile *Addend,
  2206. IN LONG Value
  2207. );
  2208. #if !defined(_X86AMD64_)
  2209. __forceinline
  2210. LONG
  2211. InterlockedAdd(
  2212. IN OUT LONG volatile *Addend,
  2213. IN LONG Value
  2214. )
  2215. {
  2216. return InterlockedExchangeAdd(Addend, Value) + Value;
  2217. }
  2218. #endif
  2219. LONG
  2220. InterlockedCompareExchange (
  2221. IN OUT LONG volatile *Destination,
  2222. IN LONG ExChange,
  2223. IN LONG Comperand
  2224. );
  2225. LONG64
  2226. InterlockedIncrement64(
  2227. IN OUT LONG64 volatile *Addend
  2228. );
  2229. LONG64
  2230. InterlockedDecrement64(
  2231. IN OUT LONG64 volatile *Addend
  2232. );
  2233. LONG64
  2234. InterlockedExchange64(
  2235. IN OUT LONG64 volatile *Target,
  2236. IN LONG64 Value
  2237. );
  2238. LONG64
  2239. InterlockedExchangeAdd64(
  2240. IN OUT LONG64 volatile *Addend,
  2241. IN LONG64 Value
  2242. );
  2243. #if !defined(_X86AMD64_)
  2244. __forceinline
  2245. LONG64
  2246. InterlockedAdd64(
  2247. IN OUT LONG64 volatile *Addend,
  2248. IN LONG64 Value
  2249. )
  2250. {
  2251. return InterlockedExchangeAdd64(Addend, Value) + Value;
  2252. }
  2253. #endif
  2254. LONG64
  2255. InterlockedCompareExchange64 (
  2256. IN OUT LONG64 volatile *Destination,
  2257. IN LONG64 ExChange,
  2258. IN LONG64 Comperand
  2259. );
  2260. PVOID
  2261. InterlockedCompareExchangePointer (
  2262. IN OUT PVOID volatile *Destination,
  2263. IN PVOID Exchange,
  2264. IN PVOID Comperand
  2265. );
  2266. PVOID
  2267. InterlockedExchangePointer(
  2268. IN OUT PVOID volatile *Target,
  2269. IN PVOID Value
  2270. );
  2271. #pragma intrinsic(_InterlockedAnd)
  2272. #pragma intrinsic(_InterlockedOr)
  2273. #pragma intrinsic(_InterlockedXor)
  2274. #pragma intrinsic(_InterlockedIncrement)
  2275. #pragma intrinsic(_InterlockedDecrement)
  2276. #pragma intrinsic(_InterlockedExchange)
  2277. #pragma intrinsic(_InterlockedExchangeAdd)
  2278. #pragma intrinsic(_InterlockedCompareExchange)
  2279. #pragma intrinsic(_InterlockedAnd64)
  2280. #pragma intrinsic(_InterlockedOr64)
  2281. #pragma intrinsic(_InterlockedXor64)
  2282. #pragma intrinsic(_InterlockedIncrement64)
  2283. #pragma intrinsic(_InterlockedDecrement64)
  2284. #pragma intrinsic(_InterlockedExchange64)
  2285. #pragma intrinsic(_InterlockedExchangeAdd64)
  2286. #pragma intrinsic(_InterlockedCompareExchange64)
  2287. #pragma intrinsic(_InterlockedExchangePointer)
  2288. #pragma intrinsic(_InterlockedCompareExchangePointer)
  2289. #ifdef __cplusplus
  2290. }
  2291. #endif
  2292. #endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
  2293. #if defined(_AMD64_)
  2294. //
  2295. // Types to use to contain PFNs and their counts.
  2296. //
  2297. typedef ULONG PFN_COUNT;
  2298. typedef LONG64 SPFN_NUMBER, *PSPFN_NUMBER;
  2299. typedef ULONG64 PFN_NUMBER, *PPFN_NUMBER;
  2300. //
  2301. // Define maximum size of flush multiple TB request.
  2302. //
  2303. #define FLUSH_MULTIPLE_MAXIMUM 32
  2304. //
  2305. // Indicate that the AMD64 compiler supports the allocate pragmas.
  2306. //
  2307. #define ALLOC_PRAGMA 1
  2308. #define ALLOC_DATA_PRAGMA 1
  2309. //
  2310. // I/O space read and write macros.
  2311. //
  2312. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
  2313. //
  2314. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
  2315. //
  2316. __forceinline
  2317. UCHAR
  2318. READ_REGISTER_UCHAR (
  2319. volatile UCHAR *Register
  2320. )
  2321. {
  2322. return *Register;
  2323. }
  2324. __forceinline
  2325. USHORT
  2326. READ_REGISTER_USHORT (
  2327. volatile USHORT *Register
  2328. )
  2329. {
  2330. return *Register;
  2331. }
  2332. __forceinline
  2333. ULONG
  2334. READ_REGISTER_ULONG (
  2335. volatile ULONG *Register
  2336. )
  2337. {
  2338. return *Register;
  2339. }
  2340. __forceinline
  2341. VOID
  2342. READ_REGISTER_BUFFER_UCHAR (
  2343. PUCHAR Register,
  2344. PUCHAR Buffer,
  2345. ULONG Count
  2346. )
  2347. {
  2348. __movsb(Buffer, Register, Count);
  2349. return;
  2350. }
  2351. __forceinline
  2352. VOID
  2353. READ_REGISTER_BUFFER_USHORT (
  2354. PUSHORT Register,
  2355. PUSHORT Buffer,
  2356. ULONG Count
  2357. )
  2358. {
  2359. __movsw(Buffer, Register, Count);
  2360. return;
  2361. }
  2362. __forceinline
  2363. VOID
  2364. READ_REGISTER_BUFFER_ULONG (
  2365. PULONG Register,
  2366. PULONG Buffer,
  2367. ULONG Count
  2368. )
  2369. {
  2370. __movsd(Buffer, Register, Count);
  2371. return;
  2372. }
  2373. __forceinline
  2374. VOID
  2375. WRITE_REGISTER_UCHAR (
  2376. PUCHAR Register,
  2377. UCHAR Value
  2378. )
  2379. {
  2380. *Register = Value;
  2381. StoreFence();
  2382. return;
  2383. }
  2384. __forceinline
  2385. VOID
  2386. WRITE_REGISTER_USHORT (
  2387. PUSHORT Register,
  2388. USHORT Value
  2389. )
  2390. {
  2391. *Register = Value;
  2392. StoreFence();
  2393. return;
  2394. }
  2395. __forceinline
  2396. VOID
  2397. WRITE_REGISTER_ULONG (
  2398. PULONG Register,
  2399. ULONG Value
  2400. )
  2401. {
  2402. *Register = Value;
  2403. StoreFence();
  2404. return;
  2405. }
  2406. __forceinline
  2407. VOID
  2408. WRITE_REGISTER_BUFFER_UCHAR (
  2409. PUCHAR Register,
  2410. PUCHAR Buffer,
  2411. ULONG Count
  2412. )
  2413. {
  2414. __movsb(Register, Buffer, Count);
  2415. StoreFence();
  2416. return;
  2417. }
  2418. __forceinline
  2419. VOID
  2420. WRITE_REGISTER_BUFFER_USHORT (
  2421. PUSHORT Register,
  2422. PUSHORT Buffer,
  2423. ULONG Count
  2424. )
  2425. {
  2426. __movsw(Register, Buffer, Count);
  2427. StoreFence();
  2428. return;
  2429. }
  2430. __forceinline
  2431. VOID
  2432. WRITE_REGISTER_BUFFER_ULONG (
  2433. PULONG Register,
  2434. PULONG Buffer,
  2435. ULONG Count
  2436. )
  2437. {
  2438. __movsd(Register, Buffer, Count);
  2439. StoreFence();
  2440. return;
  2441. }
  2442. __forceinline
  2443. UCHAR
  2444. READ_PORT_UCHAR (
  2445. PUCHAR Port
  2446. )
  2447. {
  2448. return __inbyte((USHORT)((ULONG64)Port));
  2449. }
  2450. __forceinline
  2451. USHORT
  2452. READ_PORT_USHORT (
  2453. PUSHORT Port
  2454. )
  2455. {
  2456. return __inword((USHORT)((ULONG64)Port));
  2457. }
  2458. __forceinline
  2459. ULONG
  2460. READ_PORT_ULONG (
  2461. PULONG Port
  2462. )
  2463. {
  2464. return __indword((USHORT)((ULONG64)Port));
  2465. }
  2466. __forceinline
  2467. VOID
  2468. READ_PORT_BUFFER_UCHAR (
  2469. PUCHAR Port,
  2470. PUCHAR Buffer,
  2471. ULONG Count
  2472. )
  2473. {
  2474. __inbytestring((USHORT)((ULONG64)Port), Buffer, Count);
  2475. return;
  2476. }
  2477. __forceinline
  2478. VOID
  2479. READ_PORT_BUFFER_USHORT (
  2480. PUSHORT Port,
  2481. PUSHORT Buffer,
  2482. ULONG Count
  2483. )
  2484. {
  2485. __inwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  2486. return;
  2487. }
  2488. __forceinline
  2489. VOID
  2490. READ_PORT_BUFFER_ULONG (
  2491. PULONG Port,
  2492. PULONG Buffer,
  2493. ULONG Count
  2494. )
  2495. {
  2496. __indwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  2497. return;
  2498. }
  2499. __forceinline
  2500. VOID
  2501. WRITE_PORT_UCHAR (
  2502. PUCHAR Port,
  2503. UCHAR Value
  2504. )
  2505. {
  2506. __outbyte((USHORT)((ULONG64)Port), Value);
  2507. return;
  2508. }
  2509. __forceinline
  2510. VOID
  2511. WRITE_PORT_USHORT (
  2512. PUSHORT Port,
  2513. USHORT Value
  2514. )
  2515. {
  2516. __outword((USHORT)((ULONG64)Port), Value);
  2517. return;
  2518. }
  2519. __forceinline
  2520. VOID
  2521. WRITE_PORT_ULONG (
  2522. PULONG Port,
  2523. ULONG Value
  2524. )
  2525. {
  2526. __outdword((USHORT)((ULONG64)Port), Value);
  2527. return;
  2528. }
  2529. __forceinline
  2530. VOID
  2531. WRITE_PORT_BUFFER_UCHAR (
  2532. PUCHAR Port,
  2533. PUCHAR Buffer,
  2534. ULONG Count
  2535. )
  2536. {
  2537. __outbytestring((USHORT)((ULONG64)Port), Buffer, Count);
  2538. return;
  2539. }
  2540. __forceinline
  2541. VOID
  2542. WRITE_PORT_BUFFER_USHORT (
  2543. PUSHORT Port,
  2544. PUSHORT Buffer,
  2545. ULONG Count
  2546. )
  2547. {
  2548. __outwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  2549. return;
  2550. }
  2551. __forceinline
  2552. VOID
  2553. WRITE_PORT_BUFFER_ULONG (
  2554. PULONG Port,
  2555. PULONG Buffer,
  2556. ULONG Count
  2557. )
  2558. {
  2559. __outdwordstring((USHORT)((ULONG64)Port), Buffer, Count);
  2560. return;
  2561. }
  2562. #define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
  2563. //
  2564. // AMD64 Specific portions of mm component.
  2565. //
  2566. // Define the page size for the AMD64 as 4096 (0x1000).
  2567. //
  2568. #define PAGE_SIZE 0x1000
  2569. //
  2570. // Define the number of trailing zeroes in a page aligned virtual address.
  2571. // This is used as the shift count when shifting virtual addresses to
  2572. // virtual page numbers.
  2573. //
  2574. #define PAGE_SHIFT 12L
  2575. //++
  2576. //
  2577. //
  2578. // VOID
  2579. // KeMemoryBarrier (
  2580. // VOID
  2581. // )
  2582. //
  2583. // VOID
  2584. // KeMemoryBarrierWithoutFence (
  2585. // VOID
  2586. // )
  2587. //
  2588. //
  2589. // Routine Description:
  2590. //
  2591. // These functions order memory accesses as seen by other processors.
  2592. //
  2593. // Arguments:
  2594. //
  2595. // None.
  2596. //
  2597. // Return Value:
  2598. //
  2599. // None.
  2600. //
  2601. //--
  2602. #if !defined(_CROSS_PLATFORM_)
  2603. #ifdef __cplusplus
  2604. extern "C" {
  2605. #endif
  2606. VOID
  2607. _ReadWriteBarrier (
  2608. VOID
  2609. );
  2610. #pragma intrinsic(_ReadWriteBarrier)
  2611. #ifdef __cplusplus
  2612. }
  2613. #endif
  2614. #define KeMemoryBarrier() _ReadWriteBarrier()
  2615. #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
  2616. #else
  2617. #define KeMemoryBarrier()
  2618. #define KeMemoryBarrierWithoutFence()
  2619. #endif
  2620. #endif // defined(_AMD64_)
  2621. #if defined(_IA64_)
  2622. //
  2623. // Types to use to contain PFNs and their counts.
  2624. //
  2625. typedef ULONG PFN_COUNT;
  2626. typedef LONG_PTR SPFN_NUMBER, *PSPFN_NUMBER;
  2627. typedef ULONG_PTR PFN_NUMBER, *PPFN_NUMBER;
  2628. //
  2629. // Indicate that the IA64 compiler supports the pragma textout construct.
  2630. //
  2631. #define ALLOC_PRAGMA 1
  2632. //
  2633. // Define intrinsic calls and their prototypes
  2634. //
  2635. #include "ia64reg.h"
  2636. #ifdef __cplusplus
  2637. extern "C" {
  2638. #endif
  2639. unsigned __int64 __getReg (int);
  2640. void __setReg (int, unsigned __int64);
  2641. void __isrlz (void);
  2642. void __dsrlz (void);
  2643. void __fwb (void);
  2644. void __mf (void);
  2645. void __mfa (void);
  2646. void __synci (void);
  2647. __int64 __thash (__int64);
  2648. __int64 __ttag (__int64);
  2649. void __ptcl (__int64, __int64);
  2650. void __ptcg (__int64, __int64);
  2651. void __ptcga (__int64, __int64);
  2652. void __ptri (__int64, __int64);
  2653. void __ptrd (__int64, __int64);
  2654. void __invalat (void);
  2655. void __break (int);
  2656. void __fc (__int64);
  2657. void __fci (__int64);
  2658. void __sum (int);
  2659. void __rsm (int);
  2660. void _ReleaseSpinLock( unsigned __int64 *);
  2661. void __yield();
  2662. void __lfetch(int, void const *);
  2663. void __lfetchfault(int, void const *);
  2664. #ifdef _M_IA64
  2665. #pragma intrinsic (__getReg)
  2666. #pragma intrinsic (__setReg)
  2667. #pragma intrinsic (__isrlz)
  2668. #pragma intrinsic (__dsrlz)
  2669. #pragma intrinsic (__fwb)
  2670. #pragma intrinsic (__mf)
  2671. #pragma intrinsic (__mfa)
  2672. #pragma intrinsic (__synci)
  2673. #pragma intrinsic (__thash)
  2674. #pragma intrinsic (__ttag)
  2675. #pragma intrinsic (__ptcl)
  2676. #pragma intrinsic (__ptcg)
  2677. #pragma intrinsic (__ptcga)
  2678. #pragma intrinsic (__ptri)
  2679. #pragma intrinsic (__ptrd)
  2680. #pragma intrinsic (__invalat)
  2681. #pragma intrinsic (__break)
  2682. #pragma intrinsic (__fc)
  2683. #pragma intrinsic (__fci)
  2684. #pragma intrinsic (__sum)
  2685. #pragma intrinsic (__rsm)
  2686. #pragma intrinsic (_ReleaseSpinLock)
  2687. #pragma intrinsic (__yield)
  2688. #pragma intrinsic (__lfetch)
  2689. #pragma intrinsic (__lfetchfault)
  2690. #endif // _M_IA64
  2691. #ifdef __cplusplus
  2692. }
  2693. #endif
  2694. //
  2695. //
  2696. // VOID
  2697. // KeMemoryBarrierWithoutFence (
  2698. // VOID
  2699. // )
  2700. //
  2701. //
  2702. // Routine Description:
  2703. //
  2704. // This function cases ordering of memory acceses generated by the compiler.
  2705. //
  2706. //
  2707. // Arguments:
  2708. //
  2709. // None.
  2710. //
  2711. // Return Value:
  2712. //
  2713. // None.
  2714. //--
  2715. #ifdef __cplusplus
  2716. extern "C" {
  2717. #endif
  2718. VOID
  2719. _ReadWriteBarrier (
  2720. VOID
  2721. );
  2722. #ifdef __cplusplus
  2723. }
  2724. #endif
  2725. #pragma intrinsic(_ReadWriteBarrier)
  2726. #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
  2727. //++
  2728. //
  2729. //
  2730. // VOID
  2731. // KeMemoryBarrier (
  2732. // VOID
  2733. // )
  2734. //
  2735. //
  2736. // Routine Description:
  2737. //
  2738. // This function cases ordering of memory acceses as generated by the compiler and
  2739. // as seen by other processors.
  2740. //
  2741. //
  2742. // Arguments:
  2743. //
  2744. // None.
  2745. //
  2746. // Return Value:
  2747. //
  2748. // None.
  2749. //--
  2750. #define KE_MEMORY_BARRIER_REQUIRED
  2751. #define KeMemoryBarrier() {_ReadWriteBarrier();__mf ();_ReadWriteBarrier();}
  2752. //
  2753. // Define the page size
  2754. //
  2755. #define PAGE_SIZE 0x2000
  2756. //
  2757. // Define the number of trailing zeroes in a page aligned virtual address.
  2758. // This is used as the shift count when shifting virtual addresses to
  2759. // virtual page numbers.
  2760. //
  2761. #define PAGE_SHIFT 13L
  2762. //
  2763. // Cache and write buffer flush functions.
  2764. //
  2765. NTKERNELAPI
  2766. VOID
  2767. KeFlushIoBuffers (
  2768. IN PMDL Mdl,
  2769. IN BOOLEAN ReadOperation,
  2770. IN BOOLEAN DmaOperation
  2771. );
  2772. //
  2773. // I/O space read and write macros.
  2774. //
  2775. NTHALAPI
  2776. UCHAR
  2777. READ_PORT_UCHAR (
  2778. PUCHAR RegisterAddress
  2779. );
  2780. NTHALAPI
  2781. USHORT
  2782. READ_PORT_USHORT (
  2783. PUSHORT RegisterAddress
  2784. );
  2785. NTHALAPI
  2786. ULONG
  2787. READ_PORT_ULONG (
  2788. PULONG RegisterAddress
  2789. );
  2790. NTHALAPI
  2791. VOID
  2792. READ_PORT_BUFFER_UCHAR (
  2793. PUCHAR portAddress,
  2794. PUCHAR readBuffer,
  2795. ULONG readCount
  2796. );
  2797. NTHALAPI
  2798. VOID
  2799. READ_PORT_BUFFER_USHORT (
  2800. PUSHORT portAddress,
  2801. PUSHORT readBuffer,
  2802. ULONG readCount
  2803. );
  2804. NTHALAPI
  2805. VOID
  2806. READ_PORT_BUFFER_ULONG (
  2807. PULONG portAddress,
  2808. PULONG readBuffer,
  2809. ULONG readCount
  2810. );
  2811. NTHALAPI
  2812. VOID
  2813. WRITE_PORT_UCHAR (
  2814. PUCHAR portAddress,
  2815. UCHAR Data
  2816. );
  2817. NTHALAPI
  2818. VOID
  2819. WRITE_PORT_USHORT (
  2820. PUSHORT portAddress,
  2821. USHORT Data
  2822. );
  2823. NTHALAPI
  2824. VOID
  2825. WRITE_PORT_ULONG (
  2826. PULONG portAddress,
  2827. ULONG Data
  2828. );
  2829. NTHALAPI
  2830. VOID
  2831. WRITE_PORT_BUFFER_UCHAR (
  2832. PUCHAR portAddress,
  2833. PUCHAR writeBuffer,
  2834. ULONG writeCount
  2835. );
  2836. NTHALAPI
  2837. VOID
  2838. WRITE_PORT_BUFFER_USHORT (
  2839. PUSHORT portAddress,
  2840. PUSHORT writeBuffer,
  2841. ULONG writeCount
  2842. );
  2843. NTHALAPI
  2844. VOID
  2845. WRITE_PORT_BUFFER_ULONG (
  2846. PULONG portAddress,
  2847. PULONG writeBuffer,
  2848. ULONG writeCount
  2849. );
  2850. #define READ_REGISTER_UCHAR(x) \
  2851. (__mf(), *(volatile UCHAR * const)(x))
  2852. #define READ_REGISTER_USHORT(x) \
  2853. (__mf(), *(volatile USHORT * const)(x))
  2854. #define READ_REGISTER_ULONG(x) \
  2855. (__mf(), *(volatile ULONG * const)(x))
  2856. #define READ_REGISTER_BUFFER_UCHAR(x, y, z) { \
  2857. PUCHAR registerBuffer = x; \
  2858. PUCHAR readBuffer = y; \
  2859. ULONG readCount; \
  2860. __mf(); \
  2861. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  2862. *readBuffer = *(volatile UCHAR * const)(registerBuffer); \
  2863. } \
  2864. }
  2865. #define READ_REGISTER_BUFFER_USHORT(x, y, z) { \
  2866. PUSHORT registerBuffer = x; \
  2867. PUSHORT readBuffer = y; \
  2868. ULONG readCount; \
  2869. __mf(); \
  2870. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  2871. *readBuffer = *(volatile USHORT * const)(registerBuffer); \
  2872. } \
  2873. }
  2874. #define READ_REGISTER_BUFFER_ULONG(x, y, z) { \
  2875. PULONG registerBuffer = x; \
  2876. PULONG readBuffer = y; \
  2877. ULONG readCount; \
  2878. __mf(); \
  2879. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  2880. *readBuffer = *(volatile ULONG * const)(registerBuffer); \
  2881. } \
  2882. }
  2883. #define WRITE_REGISTER_UCHAR(x, y) { \
  2884. *(volatile UCHAR * const)(x) = y; \
  2885. KeFlushWriteBuffer(); \
  2886. }
  2887. #define WRITE_REGISTER_USHORT(x, y) { \
  2888. *(volatile USHORT * const)(x) = y; \
  2889. KeFlushWriteBuffer(); \
  2890. }
  2891. #define WRITE_REGISTER_ULONG(x, y) { \
  2892. *(volatile ULONG * const)(x) = y; \
  2893. KeFlushWriteBuffer(); \
  2894. }
  2895. #define WRITE_REGISTER_BUFFER_UCHAR(x, y, z) { \
  2896. PUCHAR registerBuffer = x; \
  2897. PUCHAR writeBuffer = y; \
  2898. ULONG writeCount; \
  2899. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  2900. *(volatile UCHAR * const)(registerBuffer) = *writeBuffer; \
  2901. } \
  2902. KeFlushWriteBuffer(); \
  2903. }
  2904. #define WRITE_REGISTER_BUFFER_USHORT(x, y, z) { \
  2905. PUSHORT registerBuffer = x; \
  2906. PUSHORT writeBuffer = y; \
  2907. ULONG writeCount; \
  2908. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  2909. *(volatile USHORT * const)(registerBuffer) = *writeBuffer; \
  2910. } \
  2911. KeFlushWriteBuffer(); \
  2912. }
  2913. #define WRITE_REGISTER_BUFFER_ULONG(x, y, z) { \
  2914. PULONG registerBuffer = x; \
  2915. PULONG writeBuffer = y; \
  2916. ULONG writeCount; \
  2917. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  2918. *(volatile ULONG * const)(registerBuffer) = *writeBuffer; \
  2919. } \
  2920. KeFlushWriteBuffer(); \
  2921. }
  2922. #endif // defined(_IA64_)
  2923. //
  2924. // Defines the Type in the RESOURCE_DESCRIPTOR
  2925. //
  2926. // NOTE: For all CM_RESOURCE_TYPE values, there must be a
  2927. // corresponding ResType value in the 32-bit ConfigMgr headerfile
  2928. // (cfgmgr32.h). Values in the range [0x6,0x80) use the same values
  2929. // as their ConfigMgr counterparts. CM_RESOURCE_TYPE values with
  2930. // the high bit set (i.e., in the range [0x80,0xFF]), are
  2931. // non-arbitrated resources. These correspond to the same values
  2932. // in cfgmgr32.h that have their high bit set (however, since
  2933. // cfgmgr32.h uses 16 bits for ResType values, these values are in
  2934. // the range [0x8000,0x807F). Note that ConfigMgr ResType values
  2935. // cannot be in the range [0x8080,0xFFFF), because they would not
  2936. // be able to map into CM_RESOURCE_TYPE values. (0xFFFF itself is
  2937. // a special value, because it maps to CmResourceTypeDeviceSpecific.)
  2938. //
  2939. typedef int CM_RESOURCE_TYPE;
  2940. // CmResourceTypeNull is reserved
  2941. #define CmResourceTypeNull 0 // ResType_All or ResType_None (0x0000)
  2942. #define CmResourceTypePort 1 // ResType_IO (0x0002)
  2943. #define CmResourceTypeInterrupt 2 // ResType_IRQ (0x0004)
  2944. #define CmResourceTypeMemory 3 // ResType_Mem (0x0001)
  2945. #define CmResourceTypeDma 4 // ResType_DMA (0x0003)
  2946. #define CmResourceTypeDeviceSpecific 5 // ResType_ClassSpecific (0xFFFF)
  2947. #define CmResourceTypeBusNumber 6 // ResType_BusNumber (0x0006)
  2948. // end_wdm
  2949. #define CmResourceTypeMaximum 7
  2950. // begin_wdm
  2951. #define CmResourceTypeNonArbitrated 128 // Not arbitrated if 0x80 bit set
  2952. #define CmResourceTypeConfigData 128 // ResType_Reserved (0x8000)
  2953. #define CmResourceTypeDevicePrivate 129 // ResType_DevicePrivate (0x8001)
  2954. #define CmResourceTypePcCardConfig 130 // ResType_PcCardConfig (0x8002)
  2955. #define CmResourceTypeMfCardConfig 131 // ResType_MfCardConfig (0x8003)
  2956. //
  2957. // Defines the ShareDisposition in the RESOURCE_DESCRIPTOR
  2958. //
  2959. typedef enum _CM_SHARE_DISPOSITION {
  2960. CmResourceShareUndetermined = 0, // Reserved
  2961. CmResourceShareDeviceExclusive,
  2962. CmResourceShareDriverExclusive,
  2963. CmResourceShareShared
  2964. } CM_SHARE_DISPOSITION;
  2965. //
  2966. // Define the bit masks for Flags when type is CmResourceTypeInterrupt
  2967. //
  2968. #define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE 0
  2969. #define CM_RESOURCE_INTERRUPT_LATCHED 1
  2970. //
  2971. // Define the bit masks for Flags when type is CmResourceTypeMemory
  2972. //
  2973. #define CM_RESOURCE_MEMORY_READ_WRITE 0x0000
  2974. #define CM_RESOURCE_MEMORY_READ_ONLY 0x0001
  2975. #define CM_RESOURCE_MEMORY_WRITE_ONLY 0x0002
  2976. #define CM_RESOURCE_MEMORY_PREFETCHABLE 0x0004
  2977. #define CM_RESOURCE_MEMORY_COMBINEDWRITE 0x0008
  2978. #define CM_RESOURCE_MEMORY_24 0x0010
  2979. #define CM_RESOURCE_MEMORY_CACHEABLE 0x0020
  2980. //
  2981. // Define the bit masks for Flags when type is CmResourceTypePort
  2982. //
  2983. #define CM_RESOURCE_PORT_MEMORY 0x0000
  2984. #define CM_RESOURCE_PORT_IO 0x0001
  2985. #define CM_RESOURCE_PORT_10_BIT_DECODE 0x0004
  2986. #define CM_RESOURCE_PORT_12_BIT_DECODE 0x0008
  2987. #define CM_RESOURCE_PORT_16_BIT_DECODE 0x0010
  2988. #define CM_RESOURCE_PORT_POSITIVE_DECODE 0x0020
  2989. #define CM_RESOURCE_PORT_PASSIVE_DECODE 0x0040
  2990. #define CM_RESOURCE_PORT_WINDOW_DECODE 0x0080
  2991. //
  2992. // Define the bit masks for Flags when type is CmResourceTypeDma
  2993. //
  2994. #define CM_RESOURCE_DMA_8 0x0000
  2995. #define CM_RESOURCE_DMA_16 0x0001
  2996. #define CM_RESOURCE_DMA_32 0x0002
  2997. #define CM_RESOURCE_DMA_8_AND_16 0x0004
  2998. #define CM_RESOURCE_DMA_BUS_MASTER 0x0008
  2999. #define CM_RESOURCE_DMA_TYPE_A 0x0010
  3000. #define CM_RESOURCE_DMA_TYPE_B 0x0020
  3001. #define CM_RESOURCE_DMA_TYPE_F 0x0040
  3002. #include "pshpack4.h"
  3003. typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
  3004. UCHAR Type;
  3005. UCHAR ShareDisposition;
  3006. USHORT Flags;
  3007. union {
  3008. //
  3009. // Range of resources, inclusive. These are physical, bus relative.
  3010. // It is known that Port and Memory below have the exact same layout
  3011. // as Generic.
  3012. //
  3013. struct {
  3014. PHYSICAL_ADDRESS Start;
  3015. ULONG Length;
  3016. } Generic;
  3017. //
  3018. // end_wdm
  3019. // Range of port numbers, inclusive. These are physical, bus
  3020. // relative. The value should be the same as the one passed to
  3021. // HalTranslateBusAddress().
  3022. // begin_wdm
  3023. //
  3024. struct {
  3025. PHYSICAL_ADDRESS Start;
  3026. ULONG Length;
  3027. } Port;
  3028. //
  3029. // end_wdm
  3030. // IRQL and vector. Should be same values as were passed to
  3031. // HalGetInterruptVector().
  3032. // begin_wdm
  3033. //
  3034. struct {
  3035. ULONG Level;
  3036. ULONG Vector;
  3037. KAFFINITY Affinity;
  3038. } Interrupt;
  3039. //
  3040. // Range of memory addresses, inclusive. These are physical, bus
  3041. // relative. The value should be the same as the one passed to
  3042. // HalTranslateBusAddress().
  3043. //
  3044. struct {
  3045. PHYSICAL_ADDRESS Start; // 64 bit physical addresses.
  3046. ULONG Length;
  3047. } Memory;
  3048. //
  3049. // Physical DMA channel.
  3050. //
  3051. struct {
  3052. ULONG Channel;
  3053. ULONG Port;
  3054. ULONG Reserved1;
  3055. } Dma;
  3056. //
  3057. // Device driver private data, usually used to help it figure
  3058. // what the resource assignments decisions that were made.
  3059. //
  3060. struct {
  3061. ULONG Data[3];
  3062. } DevicePrivate;
  3063. //
  3064. // Bus Number information.
  3065. //
  3066. struct {
  3067. ULONG Start;
  3068. ULONG Length;
  3069. ULONG Reserved;
  3070. } BusNumber;
  3071. //
  3072. // Device Specific information defined by the driver.
  3073. // The DataSize field indicates the size of the data in bytes. The
  3074. // data is located immediately after the DeviceSpecificData field in
  3075. // the structure.
  3076. //
  3077. struct {
  3078. ULONG DataSize;
  3079. ULONG Reserved1;
  3080. ULONG Reserved2;
  3081. } DeviceSpecificData;
  3082. } u;
  3083. } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
  3084. #include "poppack.h"
  3085. //
  3086. // A Partial Resource List is what can be found in the ARC firmware
  3087. // or will be generated by ntdetect.com.
  3088. // The configuration manager will transform this structure into a Full
  3089. // resource descriptor when it is about to store it in the regsitry.
  3090. //
  3091. // Note: There must a be a convention to the order of fields of same type,
  3092. // (defined on a device by device basis) so that the fields can make sense
  3093. // to a driver (i.e. when multiple memory ranges are necessary).
  3094. //
  3095. typedef struct _CM_PARTIAL_RESOURCE_LIST {
  3096. USHORT Version;
  3097. USHORT Revision;
  3098. ULONG Count;
  3099. CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];
  3100. } CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;
  3101. //
  3102. // A Full Resource Descriptor is what can be found in the registry.
  3103. // This is what will be returned to a driver when it queries the registry
  3104. // to get device information; it will be stored under a key in the hardware
  3105. // description tree.
  3106. //
  3107. // end_wdm
  3108. // Note: The BusNumber and Type are redundant information, but we will keep
  3109. // it since it allows the driver _not_ to append it when it is creating
  3110. // a resource list which could possibly span multiple buses.
  3111. //
  3112. // begin_wdm
  3113. // Note: There must a be a convention to the order of fields of same type,
  3114. // (defined on a device by device basis) so that the fields can make sense
  3115. // to a driver (i.e. when multiple memory ranges are necessary).
  3116. //
  3117. typedef struct _CM_FULL_RESOURCE_DESCRIPTOR {
  3118. INTERFACE_TYPE InterfaceType; // unused for WDM
  3119. ULONG BusNumber; // unused for WDM
  3120. CM_PARTIAL_RESOURCE_LIST PartialResourceList;
  3121. } CM_FULL_RESOURCE_DESCRIPTOR, *PCM_FULL_RESOURCE_DESCRIPTOR;
  3122. //
  3123. // The Resource list is what will be stored by the drivers into the
  3124. // resource map via the IO API.
  3125. //
  3126. typedef struct _CM_RESOURCE_LIST {
  3127. ULONG Count;
  3128. CM_FULL_RESOURCE_DESCRIPTOR List[1];
  3129. } CM_RESOURCE_LIST, *PCM_RESOURCE_LIST;
  3130. #include "pshpack1.h"
  3131. //
  3132. // Define Mca POS data block for slot
  3133. //
  3134. typedef struct _CM_MCA_POS_DATA {
  3135. USHORT AdapterId;
  3136. UCHAR PosData1;
  3137. UCHAR PosData2;
  3138. UCHAR PosData3;
  3139. UCHAR PosData4;
  3140. } CM_MCA_POS_DATA, *PCM_MCA_POS_DATA;
  3141. //
  3142. // Memory configuration of eisa data block structure
  3143. //
  3144. typedef struct _EISA_MEMORY_TYPE {
  3145. UCHAR ReadWrite: 1;
  3146. UCHAR Cached : 1;
  3147. UCHAR Reserved0 :1;
  3148. UCHAR Type:2;
  3149. UCHAR Shared:1;
  3150. UCHAR Reserved1 :1;
  3151. UCHAR MoreEntries : 1;
  3152. } EISA_MEMORY_TYPE, *PEISA_MEMORY_TYPE;
  3153. typedef struct _EISA_MEMORY_CONFIGURATION {
  3154. EISA_MEMORY_TYPE ConfigurationByte;
  3155. UCHAR DataSize;
  3156. USHORT AddressLowWord;
  3157. UCHAR AddressHighByte;
  3158. USHORT MemorySize;
  3159. } EISA_MEMORY_CONFIGURATION, *PEISA_MEMORY_CONFIGURATION;
  3160. //
  3161. // Interrupt configurationn of eisa data block structure
  3162. //
  3163. typedef struct _EISA_IRQ_DESCRIPTOR {
  3164. UCHAR Interrupt : 4;
  3165. UCHAR Reserved :1;
  3166. UCHAR LevelTriggered :1;
  3167. UCHAR Shared : 1;
  3168. UCHAR MoreEntries : 1;
  3169. } EISA_IRQ_DESCRIPTOR, *PEISA_IRQ_DESCRIPTOR;
  3170. typedef struct _EISA_IRQ_CONFIGURATION {
  3171. EISA_IRQ_DESCRIPTOR ConfigurationByte;
  3172. UCHAR Reserved;
  3173. } EISA_IRQ_CONFIGURATION, *PEISA_IRQ_CONFIGURATION;
  3174. //
  3175. // DMA description of eisa data block structure
  3176. //
  3177. typedef struct _DMA_CONFIGURATION_BYTE0 {
  3178. UCHAR Channel : 3;
  3179. UCHAR Reserved : 3;
  3180. UCHAR Shared :1;
  3181. UCHAR MoreEntries :1;
  3182. } DMA_CONFIGURATION_BYTE0;
  3183. typedef struct _DMA_CONFIGURATION_BYTE1 {
  3184. UCHAR Reserved0 : 2;
  3185. UCHAR TransferSize : 2;
  3186. UCHAR Timing : 2;
  3187. UCHAR Reserved1 : 2;
  3188. } DMA_CONFIGURATION_BYTE1;
  3189. typedef struct _EISA_DMA_CONFIGURATION {
  3190. DMA_CONFIGURATION_BYTE0 ConfigurationByte0;
  3191. DMA_CONFIGURATION_BYTE1 ConfigurationByte1;
  3192. } EISA_DMA_CONFIGURATION, *PEISA_DMA_CONFIGURATION;
  3193. //
  3194. // Port description of eisa data block structure
  3195. //
  3196. typedef struct _EISA_PORT_DESCRIPTOR {
  3197. UCHAR NumberPorts : 5;
  3198. UCHAR Reserved :1;
  3199. UCHAR Shared :1;
  3200. UCHAR MoreEntries : 1;
  3201. } EISA_PORT_DESCRIPTOR, *PEISA_PORT_DESCRIPTOR;
  3202. typedef struct _EISA_PORT_CONFIGURATION {
  3203. EISA_PORT_DESCRIPTOR Configuration;
  3204. USHORT PortAddress;
  3205. } EISA_PORT_CONFIGURATION, *PEISA_PORT_CONFIGURATION;
  3206. //
  3207. // Eisa slot information definition
  3208. // N.B. This structure is different from the one defined
  3209. // in ARC eisa addendum.
  3210. //
  3211. typedef struct _CM_EISA_SLOT_INFORMATION {
  3212. UCHAR ReturnCode;
  3213. UCHAR ReturnFlags;
  3214. UCHAR MajorRevision;
  3215. UCHAR MinorRevision;
  3216. USHORT Checksum;
  3217. UCHAR NumberFunctions;
  3218. UCHAR FunctionInformation;
  3219. ULONG CompressedId;
  3220. } CM_EISA_SLOT_INFORMATION, *PCM_EISA_SLOT_INFORMATION;
  3221. //
  3222. // Eisa function information definition
  3223. //
  3224. typedef struct _CM_EISA_FUNCTION_INFORMATION {
  3225. ULONG CompressedId;
  3226. UCHAR IdSlotFlags1;
  3227. UCHAR IdSlotFlags2;
  3228. UCHAR MinorRevision;
  3229. UCHAR MajorRevision;
  3230. UCHAR Selections[26];
  3231. UCHAR FunctionFlags;
  3232. UCHAR TypeString[80];
  3233. EISA_MEMORY_CONFIGURATION EisaMemory[9];
  3234. EISA_IRQ_CONFIGURATION EisaIrq[7];
  3235. EISA_DMA_CONFIGURATION EisaDma[4];
  3236. EISA_PORT_CONFIGURATION EisaPort[20];
  3237. UCHAR InitializationData[60];
  3238. } CM_EISA_FUNCTION_INFORMATION, *PCM_EISA_FUNCTION_INFORMATION;
  3239. //
  3240. // The following defines the way pnp bios information is stored in
  3241. // the registry \\HKEY_LOCAL_MACHINE\HARDWARE\Description\System\MultifunctionAdapter\x
  3242. // key, where x is an integer number indicating adapter instance. The
  3243. // "Identifier" of the key must equal to "PNP BIOS" and the
  3244. // "ConfigurationData" is organized as follow:
  3245. //
  3246. // CM_PNP_BIOS_INSTALLATION_CHECK +
  3247. // CM_PNP_BIOS_DEVICE_NODE for device 1 +
  3248. // CM_PNP_BIOS_DEVICE_NODE for device 2 +
  3249. // ...
  3250. // CM_PNP_BIOS_DEVICE_NODE for device n
  3251. //
  3252. //
  3253. // Pnp BIOS device node structure
  3254. //
  3255. typedef struct _CM_PNP_BIOS_DEVICE_NODE {
  3256. USHORT Size;
  3257. UCHAR Node;
  3258. ULONG ProductId;
  3259. UCHAR DeviceType[3];
  3260. USHORT DeviceAttributes;
  3261. // followed by AllocatedResourceBlock, PossibleResourceBlock
  3262. // and CompatibleDeviceId
  3263. } CM_PNP_BIOS_DEVICE_NODE,*PCM_PNP_BIOS_DEVICE_NODE;
  3264. //
  3265. // Pnp BIOS Installation check
  3266. //
  3267. typedef struct _CM_PNP_BIOS_INSTALLATION_CHECK {
  3268. UCHAR Signature[4]; // $PnP (ascii)
  3269. UCHAR Revision;
  3270. UCHAR Length;
  3271. USHORT ControlField;
  3272. UCHAR Checksum;
  3273. ULONG EventFlagAddress; // Physical address
  3274. USHORT RealModeEntryOffset;
  3275. USHORT RealModeEntrySegment;
  3276. USHORT ProtectedModeEntryOffset;
  3277. ULONG ProtectedModeCodeBaseAddress;
  3278. ULONG OemDeviceId;
  3279. USHORT RealModeDataBaseAddress;
  3280. ULONG ProtectedModeDataBaseAddress;
  3281. } CM_PNP_BIOS_INSTALLATION_CHECK, *PCM_PNP_BIOS_INSTALLATION_CHECK;
  3282. #include "poppack.h"
  3283. //
  3284. // Masks for EISA function information
  3285. //
  3286. #define EISA_FUNCTION_ENABLED 0x80
  3287. #define EISA_FREE_FORM_DATA 0x40
  3288. #define EISA_HAS_PORT_INIT_ENTRY 0x20
  3289. #define EISA_HAS_PORT_RANGE 0x10
  3290. #define EISA_HAS_DMA_ENTRY 0x08
  3291. #define EISA_HAS_IRQ_ENTRY 0x04
  3292. #define EISA_HAS_MEMORY_ENTRY 0x02
  3293. #define EISA_HAS_TYPE_ENTRY 0x01
  3294. #define EISA_HAS_INFORMATION EISA_HAS_PORT_RANGE + \
  3295. EISA_HAS_DMA_ENTRY + \
  3296. EISA_HAS_IRQ_ENTRY + \
  3297. EISA_HAS_MEMORY_ENTRY + \
  3298. EISA_HAS_TYPE_ENTRY
  3299. //
  3300. // Masks for EISA memory configuration
  3301. //
  3302. #define EISA_MORE_ENTRIES 0x80
  3303. #define EISA_SYSTEM_MEMORY 0x00
  3304. #define EISA_MEMORY_TYPE_RAM 0x01
  3305. //
  3306. // Returned error code for EISA bios call
  3307. //
  3308. #define EISA_INVALID_SLOT 0x80
  3309. #define EISA_INVALID_FUNCTION 0x81
  3310. #define EISA_INVALID_CONFIGURATION 0x82
  3311. #define EISA_EMPTY_SLOT 0x83
  3312. #define EISA_INVALID_BIOS_CALL 0x86
  3313. //
  3314. // Interrupt modes.
  3315. //
  3316. typedef enum _KINTERRUPT_MODE {
  3317. LevelSensitive,
  3318. Latched
  3319. } KINTERRUPT_MODE;
  3320. typedef struct _KINTERRUPT *PKINTERRUPT, *RESTRICTED_POINTER PRKINTERRUPT;
  3321. //
  3322. // On X86 the following routines are defined in the HAL and imported by
  3323. // all other modules.
  3324. //
  3325. #if defined(_X86_) && !defined(_NTHAL_)
  3326. #define _DECL_HAL_KE_IMPORT __declspec(dllimport)
  3327. #else
  3328. #define _DECL_HAL_KE_IMPORT
  3329. #endif
  3330. //
  3331. // spin lock functions
  3332. //
  3333. #if defined(_X86_) && (defined(_WDMDDK_) || defined(WIN9X_COMPAT_SPINLOCK))
  3334. NTKERNELAPI
  3335. VOID
  3336. NTAPI
  3337. KeInitializeSpinLock (
  3338. IN PKSPIN_LOCK SpinLock
  3339. );
  3340. #else
  3341. __inline
  3342. VOID
  3343. NTAPI
  3344. KeInitializeSpinLock (
  3345. IN PKSPIN_LOCK SpinLock
  3346. )
  3347. {
  3348. *SpinLock = 0;
  3349. }
  3350. #endif
  3351. #if defined(_X86_)
  3352. NTKERNELAPI
  3353. VOID
  3354. FASTCALL
  3355. KefAcquireSpinLockAtDpcLevel (
  3356. IN PKSPIN_LOCK SpinLock
  3357. );
  3358. NTKERNELAPI
  3359. VOID
  3360. FASTCALL
  3361. KefReleaseSpinLockFromDpcLevel (
  3362. IN PKSPIN_LOCK SpinLock
  3363. );
  3364. #define KeAcquireSpinLockAtDpcLevel(a) KefAcquireSpinLockAtDpcLevel(a)
  3365. #define KeReleaseSpinLockFromDpcLevel(a) KefReleaseSpinLockFromDpcLevel(a)
  3366. _DECL_HAL_KE_IMPORT
  3367. KIRQL
  3368. FASTCALL
  3369. KfAcquireSpinLock (
  3370. IN PKSPIN_LOCK SpinLock
  3371. );
  3372. _DECL_HAL_KE_IMPORT
  3373. VOID
  3374. FASTCALL
  3375. KfReleaseSpinLock (
  3376. IN PKSPIN_LOCK SpinLock,
  3377. IN KIRQL NewIrql
  3378. );
  3379. // end_wdm end_ntddk
  3380. _DECL_HAL_KE_IMPORT
  3381. KIRQL
  3382. FASTCALL
  3383. KeAcquireSpinLockRaiseToSynch (
  3384. IN PKSPIN_LOCK SpinLock
  3385. );
  3386. // begin_wdm begin_ntddk
  3387. #define KeAcquireSpinLock(a,b) *(b) = KfAcquireSpinLock(a)
  3388. #define KeReleaseSpinLock(a,b) KfReleaseSpinLock(a,b)
  3389. NTKERNELAPI
  3390. BOOLEAN
  3391. FASTCALL
  3392. KeTestSpinLock (
  3393. IN PKSPIN_LOCK SpinLock
  3394. );
  3395. NTKERNELAPI
  3396. BOOLEAN
  3397. FASTCALL
  3398. KeTryToAcquireSpinLockAtDpcLevel (
  3399. IN PKSPIN_LOCK SpinLock
  3400. );
  3401. #else
  3402. //
  3403. // These functions are imported for IA64, ntddk, ntifs, nthal, ntosp, and wdm.
  3404. // They can be inlined for the system on AMD64.
  3405. //
  3406. #define KeAcquireSpinLock(SpinLock, OldIrql) \
  3407. *(OldIrql) = KeAcquireSpinLockRaiseToDpc(SpinLock)
  3408. #if defined(_IA64_) || defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_) || defined(_WDMDDK_)
  3409. // end_wdm end_ntddk
  3410. NTKERNELAPI
  3411. KIRQL
  3412. FASTCALL
  3413. KeAcquireSpinLockRaiseToSynch (
  3414. IN PKSPIN_LOCK SpinLock
  3415. );
  3416. // begin_wdm begin_ntddk
  3417. NTKERNELAPI
  3418. VOID
  3419. KeAcquireSpinLockAtDpcLevel (
  3420. IN PKSPIN_LOCK SpinLock
  3421. );
  3422. NTKERNELAPI
  3423. KIRQL
  3424. KeAcquireSpinLockRaiseToDpc (
  3425. IN PKSPIN_LOCK SpinLock
  3426. );
  3427. NTKERNELAPI
  3428. VOID
  3429. KeReleaseSpinLock (
  3430. IN PKSPIN_LOCK SpinLock,
  3431. IN KIRQL NewIrql
  3432. );
  3433. NTKERNELAPI
  3434. VOID
  3435. KeReleaseSpinLockFromDpcLevel (
  3436. IN PKSPIN_LOCK SpinLock
  3437. );
  3438. NTKERNELAPI
  3439. BOOLEAN
  3440. FASTCALL
  3441. KeTestSpinLock (
  3442. IN PKSPIN_LOCK SpinLock
  3443. );
  3444. NTKERNELAPI
  3445. BOOLEAN
  3446. FASTCALL
  3447. KeTryToAcquireSpinLockAtDpcLevel (
  3448. IN PKSPIN_LOCK SpinLock
  3449. );
  3450. #else
  3451. #if defined(_AMD64_)
  3452. //
  3453. // The system version of these functions are defined in amd64.h for AMD64.
  3454. //
  3455. #endif
  3456. #endif
  3457. #endif
  3458. // end_wdm end_ntddk end_nthal end_ntifs
  3459. NTKERNELAPI
  3460. KIRQL
  3461. FASTCALL
  3462. KeAcquireSpinLockForDpc (
  3463. IN PKSPIN_LOCK SpinLock
  3464. );
  3465. NTKERNELAPI
  3466. VOID
  3467. FASTCALL
  3468. KeReleaseSpinLockForDpc (
  3469. IN PKSPIN_LOCK SpinLock,
  3470. IN KIRQL OldIrql
  3471. );
  3472. //
  3473. // Define I/O system data structure type codes. Each major data structure in
  3474. // the I/O system has a type code The type field in each structure is at the
  3475. // same offset. The following values can be used to determine which type of
  3476. // data structure a pointer refers to.
  3477. //
  3478. #define IO_TYPE_ADAPTER 0x00000001
  3479. #define IO_TYPE_CONTROLLER 0x00000002
  3480. #define IO_TYPE_DEVICE 0x00000003
  3481. #define IO_TYPE_DRIVER 0x00000004
  3482. #define IO_TYPE_FILE 0x00000005
  3483. #define IO_TYPE_IRP 0x00000006
  3484. #define IO_TYPE_MASTER_ADAPTER 0x00000007
  3485. #define IO_TYPE_OPEN_PACKET 0x00000008
  3486. #define IO_TYPE_TIMER 0x00000009
  3487. #define IO_TYPE_VPB 0x0000000a
  3488. #define IO_TYPE_ERROR_LOG 0x0000000b
  3489. #define IO_TYPE_ERROR_MESSAGE 0x0000000c
  3490. #define IO_TYPE_DEVICE_OBJECT_EXTENSION 0x0000000d
  3491. //
  3492. // Define the major function codes for IRPs.
  3493. //
  3494. #define IRP_MJ_CREATE 0x00
  3495. #define IRP_MJ_CREATE_NAMED_PIPE 0x01
  3496. #define IRP_MJ_CLOSE 0x02
  3497. #define IRP_MJ_READ 0x03
  3498. #define IRP_MJ_WRITE 0x04
  3499. #define IRP_MJ_QUERY_INFORMATION 0x05
  3500. #define IRP_MJ_SET_INFORMATION 0x06
  3501. #define IRP_MJ_QUERY_EA 0x07
  3502. #define IRP_MJ_SET_EA 0x08
  3503. #define IRP_MJ_FLUSH_BUFFERS 0x09
  3504. #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
  3505. #define IRP_MJ_SET_VOLUME_INFORMATION 0x0b
  3506. #define IRP_MJ_DIRECTORY_CONTROL 0x0c
  3507. #define IRP_MJ_FILE_SYSTEM_CONTROL 0x0d
  3508. #define IRP_MJ_DEVICE_CONTROL 0x0e
  3509. #define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0f
  3510. #define IRP_MJ_SHUTDOWN 0x10
  3511. #define IRP_MJ_LOCK_CONTROL 0x11
  3512. #define IRP_MJ_CLEANUP 0x12
  3513. #define IRP_MJ_CREATE_MAILSLOT 0x13
  3514. #define IRP_MJ_QUERY_SECURITY 0x14
  3515. #define IRP_MJ_SET_SECURITY 0x15
  3516. #define IRP_MJ_POWER 0x16
  3517. #define IRP_MJ_SYSTEM_CONTROL 0x17
  3518. #define IRP_MJ_DEVICE_CHANGE 0x18
  3519. #define IRP_MJ_QUERY_QUOTA 0x19
  3520. #define IRP_MJ_SET_QUOTA 0x1a
  3521. #define IRP_MJ_PNP 0x1b
  3522. #define IRP_MJ_PNP_POWER IRP_MJ_PNP // Obsolete....
  3523. #define IRP_MJ_MAXIMUM_FUNCTION 0x1b
  3524. //
  3525. // Make the Scsi major code the same as internal device control.
  3526. //
  3527. #define IRP_MJ_SCSI IRP_MJ_INTERNAL_DEVICE_CONTROL
  3528. //
  3529. // Define the minor function codes for IRPs. The lower 128 codes, from 0x00 to
  3530. // 0x7f are reserved to Microsoft. The upper 128 codes, from 0x80 to 0xff, are
  3531. // reserved to customers of Microsoft.
  3532. //
  3533. //
  3534. // Define driver cancel routine type.
  3535. //
  3536. typedef
  3537. VOID
  3538. (*PDRIVER_CANCEL) (
  3539. IN struct _DEVICE_OBJECT *DeviceObject,
  3540. IN struct _IRP *Irp
  3541. );
  3542. //
  3543. // Define driver dispatch routine type.
  3544. //
  3545. typedef
  3546. NTSTATUS
  3547. (*PDRIVER_DISPATCH) (
  3548. IN struct _DEVICE_OBJECT *DeviceObject,
  3549. IN struct _IRP *Irp
  3550. );
  3551. //
  3552. // Define driver start I/O routine type.
  3553. //
  3554. typedef
  3555. VOID
  3556. (*PDRIVER_STARTIO) (
  3557. IN struct _DEVICE_OBJECT *DeviceObject,
  3558. IN struct _IRP *Irp
  3559. );
  3560. //
  3561. // Define driver unload routine type.
  3562. //
  3563. typedef
  3564. VOID
  3565. (*PDRIVER_UNLOAD) (
  3566. IN struct _DRIVER_OBJECT *DriverObject
  3567. );
  3568. //
  3569. // Define driver AddDevice routine type.
  3570. //
  3571. typedef
  3572. NTSTATUS
  3573. (*PDRIVER_ADD_DEVICE) (
  3574. IN struct _DRIVER_OBJECT *DriverObject,
  3575. IN struct _DEVICE_OBJECT *PhysicalDeviceObject
  3576. );
  3577. typedef struct _ADAPTER_OBJECT *PADAPTER_OBJECT;
  3578. typedef struct _DEVICE_OBJECT *PDEVICE_OBJECT;
  3579. typedef struct _DRIVER_OBJECT *PDRIVER_OBJECT;
  3580. typedef struct _FILE_OBJECT *PFILE_OBJECT;
  3581. #if defined(_WIN64)
  3582. #define POINTER_ALIGNMENT DECLSPEC_ALIGN(8)
  3583. #else
  3584. #define POINTER_ALIGNMENT
  3585. #endif
  3586. #if defined(_IA64_)
  3587. DECLSPEC_DEPRECATED_DDK // Use GetDmaRequirement
  3588. NTHALAPI
  3589. ULONG
  3590. HalGetDmaAlignmentRequirement (
  3591. VOID
  3592. );
  3593. #endif
  3594. #if defined(_M_IX86) || defined(_M_AMD64)
  3595. #define HalGetDmaAlignmentRequirement() 1L
  3596. #endif
  3597. NTHALAPI
  3598. VOID
  3599. KeFlushWriteBuffer (
  3600. VOID
  3601. );
  3602. //
  3603. // Stall processor execution function.
  3604. //
  3605. NTHALAPI
  3606. VOID
  3607. KeStallExecutionProcessor (
  3608. IN ULONG MicroSeconds
  3609. );
  3610. typedef struct _MAP_REGISTER_ENTRY {
  3611. PVOID MapRegister;
  3612. BOOLEAN WriteToDevice;
  3613. } MAP_REGISTER_ENTRY, *PMAP_REGISTER_ENTRY;
  3614. typedef struct _SCATTER_GATHER_ELEMENT {
  3615. PHYSICAL_ADDRESS Address;
  3616. ULONG Length;
  3617. ULONG_PTR Reserved;
  3618. } SCATTER_GATHER_ELEMENT, *PSCATTER_GATHER_ELEMENT;
  3619. #if _MSC_VER >= 1200
  3620. #pragma warning(push)
  3621. #endif
  3622. #pragma warning(disable:4200)
  3623. typedef struct _SCATTER_GATHER_LIST {
  3624. ULONG NumberOfElements;
  3625. ULONG_PTR Reserved;
  3626. SCATTER_GATHER_ELEMENT Elements[];
  3627. } SCATTER_GATHER_LIST, *PSCATTER_GATHER_LIST;
  3628. #if _MSC_VER >= 1200
  3629. #pragma warning(pop)
  3630. #else
  3631. #pragma warning(default:4200)
  3632. #endif
  3633. //
  3634. // Pool Allocation routines (in pool.c)
  3635. //
  3636. typedef enum _POOL_TYPE {
  3637. NonPagedPool,
  3638. PagedPool,
  3639. NonPagedPoolMustSucceed,
  3640. DontUseThisType,
  3641. NonPagedPoolCacheAligned,
  3642. PagedPoolCacheAligned,
  3643. NonPagedPoolCacheAlignedMustS,
  3644. MaxPoolType
  3645. // end_wdm
  3646. ,
  3647. //
  3648. // Note these per session types are carefully chosen so that the appropriate
  3649. // masking still applies as well as MaxPoolType above.
  3650. //
  3651. NonPagedPoolSession = 32,
  3652. PagedPoolSession = NonPagedPoolSession + 1,
  3653. NonPagedPoolMustSucceedSession = PagedPoolSession + 1,
  3654. DontUseThisTypeSession = NonPagedPoolMustSucceedSession + 1,
  3655. NonPagedPoolCacheAlignedSession = DontUseThisTypeSession + 1,
  3656. PagedPoolCacheAlignedSession = NonPagedPoolCacheAlignedSession + 1,
  3657. NonPagedPoolCacheAlignedMustSSession = PagedPoolCacheAlignedSession + 1,
  3658. // begin_wdm
  3659. } POOL_TYPE;
  3660. #define POOL_COLD_ALLOCATION 256 // Note this cannot encode into the header.
  3661. //
  3662. #if defined(_WIN64)
  3663. #define ExInterlockedAddLargeStatistic(Addend, Increment) \
  3664. (VOID) InterlockedAdd64(&(Addend)->QuadPart, Increment)
  3665. #else
  3666. #ifdef __cplusplus
  3667. extern "C" {
  3668. #endif
  3669. LONG
  3670. _InterlockedAddLargeStatistic (
  3671. IN PLONGLONG Addend,
  3672. IN ULONG Increment
  3673. );
  3674. #ifdef __cplusplus
  3675. }
  3676. #endif
  3677. #pragma intrinsic (_InterlockedAddLargeStatistic)
  3678. #define ExInterlockedAddLargeStatistic(Addend,Increment) \
  3679. (VOID) _InterlockedAddLargeStatistic ((PLONGLONG)&(Addend)->QuadPart, Increment)
  3680. #endif
  3681. //
  3682. // Define interlocked sequenced listhead functions.
  3683. //
  3684. // A sequenced interlocked list is a singly linked list with a header that
  3685. // contains the current depth and a sequence number. Each time an entry is
  3686. // inserted or removed from the list the depth is updated and the sequence
  3687. // number is incremented. This enables AMD64, IA64, and Pentium and later
  3688. // machines to insert and remove from the list without the use of spinlocks.
  3689. //
  3690. #if !defined(_WINBASE_)
  3691. /*++
  3692. Routine Description:
  3693. This function initializes a sequenced singly linked listhead.
  3694. Arguments:
  3695. SListHead - Supplies a pointer to a sequenced singly linked listhead.
  3696. Return Value:
  3697. None.
  3698. --*/
  3699. #if defined(_WIN64) && (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
  3700. NTKERNELAPI
  3701. VOID
  3702. InitializeSListHead (
  3703. IN PSLIST_HEADER SListHead
  3704. );
  3705. #else
  3706. __inline
  3707. VOID
  3708. InitializeSListHead (
  3709. IN PSLIST_HEADER SListHead
  3710. )
  3711. {
  3712. #ifdef _WIN64
  3713. //
  3714. // Slist headers must be 16 byte aligned.
  3715. //
  3716. if ((ULONG_PTR) SListHead & 0x0f) {
  3717. DbgPrint( "InitializeSListHead unaligned Slist header. Address = %p, Caller = %p\n", SListHead, _ReturnAddress());
  3718. RtlRaiseStatus(STATUS_DATATYPE_MISALIGNMENT);
  3719. }
  3720. #endif
  3721. SListHead->Alignment = 0;
  3722. //
  3723. // For IA-64 we save the region number of the elements of the list in a
  3724. // separate field. This imposes the requirement that all elements stored
  3725. // in the list are from the same region.
  3726. #if defined(_IA64_)
  3727. SListHead->Region = (ULONG_PTR)SListHead & VRN_MASK;
  3728. #elif defined(_AMD64_)
  3729. SListHead->Region = 0;
  3730. #endif
  3731. return;
  3732. }
  3733. #endif
  3734. #endif // !defined(_WINBASE_)
  3735. #define ExInitializeSListHead InitializeSListHead
  3736. PSLIST_ENTRY
  3737. FirstEntrySList (
  3738. IN const SLIST_HEADER *SListHead
  3739. );
  3740. /*++
  3741. Routine Description:
  3742. This function queries the current number of entries contained in a
  3743. sequenced single linked list.
  3744. Arguments:
  3745. SListHead - Supplies a pointer to the sequenced listhead which is
  3746. be queried.
  3747. Return Value:
  3748. The current number of entries in the sequenced singly linked list is
  3749. returned as the function value.
  3750. --*/
  3751. #if defined(_WIN64)
  3752. #if (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
  3753. NTKERNELAPI
  3754. USHORT
  3755. ExQueryDepthSList (
  3756. IN PSLIST_HEADER SListHead
  3757. );
  3758. #else
  3759. __inline
  3760. USHORT
  3761. ExQueryDepthSList (
  3762. IN PSLIST_HEADER SListHead
  3763. )
  3764. {
  3765. return (USHORT)(SListHead->Alignment & 0xffff);
  3766. }
  3767. #endif
  3768. #else
  3769. #define ExQueryDepthSList(_listhead_) (_listhead_)->Depth
  3770. #endif
  3771. #if defined(_WIN64)
  3772. #define ExInterlockedPopEntrySList(Head, Lock) \
  3773. ExpInterlockedPopEntrySList(Head)
  3774. #define ExInterlockedPushEntrySList(Head, Entry, Lock) \
  3775. ExpInterlockedPushEntrySList(Head, Entry)
  3776. #define ExInterlockedFlushSList(Head) \
  3777. ExpInterlockedFlushSList(Head)
  3778. #if !defined(_WINBASE_)
  3779. #define InterlockedPopEntrySList(Head) \
  3780. ExpInterlockedPopEntrySList(Head)
  3781. #define InterlockedPushEntrySList(Head, Entry) \
  3782. ExpInterlockedPushEntrySList(Head, Entry)
  3783. #define InterlockedFlushSList(Head) \
  3784. ExpInterlockedFlushSList(Head)
  3785. #define QueryDepthSList(Head) \
  3786. ExQueryDepthSList(Head)
  3787. #endif // !defined(_WINBASE_)
  3788. NTKERNELAPI
  3789. PSLIST_ENTRY
  3790. ExpInterlockedPopEntrySList (
  3791. IN PSLIST_HEADER ListHead
  3792. );
  3793. NTKERNELAPI
  3794. PSLIST_ENTRY
  3795. ExpInterlockedPushEntrySList (
  3796. IN PSLIST_HEADER ListHead,
  3797. IN PSLIST_ENTRY ListEntry
  3798. );
  3799. NTKERNELAPI
  3800. PSLIST_ENTRY
  3801. ExpInterlockedFlushSList (
  3802. IN PSLIST_HEADER ListHead
  3803. );
  3804. #else
  3805. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  3806. NTKERNELAPI
  3807. PSLIST_ENTRY
  3808. FASTCALL
  3809. ExInterlockedPopEntrySList (
  3810. IN PSLIST_HEADER ListHead,
  3811. IN PKSPIN_LOCK Lock
  3812. );
  3813. NTKERNELAPI
  3814. PSLIST_ENTRY
  3815. FASTCALL
  3816. ExInterlockedPushEntrySList (
  3817. IN PSLIST_HEADER ListHead,
  3818. IN PSLIST_ENTRY ListEntry,
  3819. IN PKSPIN_LOCK Lock
  3820. );
  3821. #else
  3822. #define ExInterlockedPopEntrySList(ListHead, Lock) \
  3823. InterlockedPopEntrySList(ListHead)
  3824. #define ExInterlockedPushEntrySList(ListHead, ListEntry, Lock) \
  3825. InterlockedPushEntrySList(ListHead, ListEntry)
  3826. #endif
  3827. NTKERNELAPI
  3828. PSLIST_ENTRY
  3829. FASTCALL
  3830. ExInterlockedFlushSList (
  3831. IN PSLIST_HEADER ListHead
  3832. );
  3833. #if !defined(_WINBASE_)
  3834. NTKERNELAPI
  3835. PSLIST_ENTRY
  3836. FASTCALL
  3837. InterlockedPopEntrySList (
  3838. IN PSLIST_HEADER ListHead
  3839. );
  3840. NTKERNELAPI
  3841. PSLIST_ENTRY
  3842. FASTCALL
  3843. InterlockedPushEntrySList (
  3844. IN PSLIST_HEADER ListHead,
  3845. IN PSLIST_ENTRY ListEntry
  3846. );
  3847. #define InterlockedFlushSList(Head) \
  3848. ExInterlockedFlushSList(Head)
  3849. #define QueryDepthSList(Head) \
  3850. ExQueryDepthSList(Head)
  3851. #endif // !defined(_WINBASE_)
  3852. #endif // defined(_WIN64)
  3853. // end_ntddk end_wdm end_ntosp
  3854. PSLIST_ENTRY
  3855. FASTCALL
  3856. InterlockedPushListSList (
  3857. IN PSLIST_HEADER ListHead,
  3858. IN PSLIST_ENTRY List,
  3859. IN PSLIST_ENTRY ListEnd,
  3860. IN ULONG Count
  3861. );
  3862. //
  3863. // Define interlocked lookaside list structure and allocation functions.
  3864. //
  3865. VOID
  3866. ExAdjustLookasideDepth (
  3867. VOID
  3868. );
  3869. // begin_ntddk begin_wdm begin_ntosp
  3870. typedef
  3871. PVOID
  3872. (*PALLOCATE_FUNCTION) (
  3873. IN POOL_TYPE PoolType,
  3874. IN SIZE_T NumberOfBytes,
  3875. IN ULONG Tag
  3876. );
  3877. typedef
  3878. VOID
  3879. (*PFREE_FUNCTION) (
  3880. IN PVOID Buffer
  3881. );
  3882. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  3883. typedef struct _GENERAL_LOOKASIDE {
  3884. #else
  3885. typedef struct DECLSPEC_CACHEALIGN _GENERAL_LOOKASIDE {
  3886. #endif
  3887. SLIST_HEADER ListHead;
  3888. USHORT Depth;
  3889. USHORT MaximumDepth;
  3890. ULONG TotalAllocates;
  3891. union {
  3892. ULONG AllocateMisses;
  3893. ULONG AllocateHits;
  3894. };
  3895. ULONG TotalFrees;
  3896. union {
  3897. ULONG FreeMisses;
  3898. ULONG FreeHits;
  3899. };
  3900. POOL_TYPE Type;
  3901. ULONG Tag;
  3902. ULONG Size;
  3903. PALLOCATE_FUNCTION Allocate;
  3904. PFREE_FUNCTION Free;
  3905. LIST_ENTRY ListEntry;
  3906. ULONG LastTotalAllocates;
  3907. union {
  3908. ULONG LastAllocateMisses;
  3909. ULONG LastAllocateHits;
  3910. };
  3911. ULONG Future[2];
  3912. } GENERAL_LOOKASIDE, *PGENERAL_LOOKASIDE;
  3913. #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
  3914. typedef struct _NPAGED_LOOKASIDE_LIST {
  3915. #else
  3916. typedef struct DECLSPEC_CACHEALIGN _NPAGED_LOOKASIDE_LIST {
  3917. #endif
  3918. GENERAL_LOOKASIDE L;
  3919. #if !defined(_AMD64_) && !defined(_IA64_)
  3920. KSPIN_LOCK Lock__ObsoleteButDoNotDelete;
  3921. #endif
  3922. } NPAGED_LOOKASIDE_LIST, *PNPAGED_LOOKASIDE_LIST;
  3923. NTKERNELAPI
  3924. VOID
  3925. ExInitializeNPagedLookasideList (
  3926. IN PNPAGED_LOOKASIDE_LIST Lookaside,
  3927. IN PALLOCATE_FUNCTION Allocate,
  3928. IN PFREE_FUNCTION Free,
  3929. IN ULONG Flags,
  3930. IN SIZE_T Size,
  3931. IN ULONG Tag,
  3932. IN USHORT Depth
  3933. );
  3934. NTKERNELAPI
  3935. VOID
  3936. ExDeleteNPagedLookasideList (
  3937. IN PNPAGED_LOOKASIDE_LIST Lookaside
  3938. );
  3939. __inline
  3940. PVOID
  3941. ExAllocateFromNPagedLookasideList(
  3942. IN PNPAGED_LOOKASIDE_LIST Lookaside
  3943. )
  3944. /*++
  3945. Routine Description:
  3946. This function removes (pops) the first entry from the specified
  3947. nonpaged lookaside list.
  3948. Arguments:
  3949. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  3950. Return Value:
  3951. If an entry is removed from the specified lookaside list, then the
  3952. address of the entry is returned as the function value. Otherwise,
  3953. NULL is returned.
  3954. --*/
  3955. {
  3956. PVOID Entry;
  3957. Lookaside->L.TotalAllocates += 1;
  3958. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  3959. Entry = ExInterlockedPopEntrySList(&Lookaside->L.ListHead,
  3960. &Lookaside->Lock__ObsoleteButDoNotDelete);
  3961. #else
  3962. Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
  3963. #endif
  3964. if (Entry == NULL) {
  3965. Lookaside->L.AllocateMisses += 1;
  3966. Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
  3967. Lookaside->L.Size,
  3968. Lookaside->L.Tag);
  3969. }
  3970. return Entry;
  3971. }
  3972. __inline
  3973. VOID
  3974. ExFreeToNPagedLookasideList(
  3975. IN PNPAGED_LOOKASIDE_LIST Lookaside,
  3976. IN PVOID Entry
  3977. )
  3978. /*++
  3979. Routine Description:
  3980. This function inserts (pushes) the specified entry into the specified
  3981. nonpaged lookaside list.
  3982. Arguments:
  3983. Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
  3984. Entry - Supples a pointer to the entry that is inserted in the
  3985. lookaside list.
  3986. Return Value:
  3987. None.
  3988. --*/
  3989. {
  3990. Lookaside->L.TotalFrees += 1;
  3991. if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
  3992. Lookaside->L.FreeMisses += 1;
  3993. (Lookaside->L.Free)(Entry);
  3994. } else {
  3995. #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
  3996. ExInterlockedPushEntrySList(&Lookaside->L.ListHead,
  3997. (PSLIST_ENTRY)Entry,
  3998. &Lookaside->Lock__ObsoleteButDoNotDelete);
  3999. #else
  4000. InterlockedPushEntrySList(&Lookaside->L.ListHead,
  4001. (PSLIST_ENTRY)Entry);
  4002. #endif
  4003. }
  4004. return;
  4005. }
  4006. typedef struct _PCI_SLOT_NUMBER {
  4007. union {
  4008. struct {
  4009. ULONG DeviceNumber:5;
  4010. ULONG FunctionNumber:3;
  4011. ULONG Reserved:24;
  4012. } bits;
  4013. ULONG AsULONG;
  4014. } u;
  4015. } PCI_SLOT_NUMBER, *PPCI_SLOT_NUMBER;
  4016. #define PCI_TYPE0_ADDRESSES 6
  4017. #define PCI_TYPE1_ADDRESSES 2
  4018. #define PCI_TYPE2_ADDRESSES 5
  4019. typedef struct _PCI_COMMON_CONFIG {
  4020. USHORT VendorID; // (ro)
  4021. USHORT DeviceID; // (ro)
  4022. USHORT Command; // Device control
  4023. USHORT Status;
  4024. UCHAR RevisionID; // (ro)
  4025. UCHAR ProgIf; // (ro)
  4026. UCHAR SubClass; // (ro)
  4027. UCHAR BaseClass; // (ro)
  4028. UCHAR CacheLineSize; // (ro+)
  4029. UCHAR LatencyTimer; // (ro+)
  4030. UCHAR HeaderType; // (ro)
  4031. UCHAR BIST; // Built in self test
  4032. union {
  4033. struct _PCI_HEADER_TYPE_0 {
  4034. ULONG BaseAddresses[PCI_TYPE0_ADDRESSES];
  4035. ULONG CIS;
  4036. USHORT SubVendorID;
  4037. USHORT SubSystemID;
  4038. ULONG ROMBaseAddress;
  4039. UCHAR CapabilitiesPtr;
  4040. UCHAR Reserved1[3];
  4041. ULONG Reserved2;
  4042. UCHAR InterruptLine; //
  4043. UCHAR InterruptPin; // (ro)
  4044. UCHAR MinimumGrant; // (ro)
  4045. UCHAR MaximumLatency; // (ro)
  4046. } type0;
  4047. } u;
  4048. UCHAR DeviceSpecific[192];
  4049. } PCI_COMMON_CONFIG, *PPCI_COMMON_CONFIG;
  4050. #define PCI_COMMON_HDR_LENGTH (FIELD_OFFSET (PCI_COMMON_CONFIG, DeviceSpecific))
  4051. #define PCI_MAX_DEVICES 32
  4052. #define PCI_MAX_FUNCTION 8
  4053. #define PCI_MAX_BRIDGE_NUMBER 0xFF
  4054. #define PCI_INVALID_VENDORID 0xFFFF
  4055. //
  4056. // Bit encodings for PCI_COMMON_CONFIG.HeaderType
  4057. //
  4058. #define PCI_MULTIFUNCTION 0x80
  4059. #define PCI_DEVICE_TYPE 0x00
  4060. #define PCI_BRIDGE_TYPE 0x01
  4061. #define PCI_CARDBUS_BRIDGE_TYPE 0x02
  4062. #define PCI_CONFIGURATION_TYPE(PciData) \
  4063. (((PPCI_COMMON_CONFIG)(PciData))->HeaderType & ~PCI_MULTIFUNCTION)
  4064. #define PCI_MULTIFUNCTION_DEVICE(PciData) \
  4065. ((((PPCI_COMMON_CONFIG)(PciData))->HeaderType & PCI_MULTIFUNCTION) != 0)
  4066. //
  4067. // Bit encodings for PCI_COMMON_CONFIG.Command
  4068. //
  4069. #define PCI_ENABLE_IO_SPACE 0x0001
  4070. #define PCI_ENABLE_MEMORY_SPACE 0x0002
  4071. #define PCI_ENABLE_BUS_MASTER 0x0004
  4072. #define PCI_ENABLE_SPECIAL_CYCLES 0x0008
  4073. #define PCI_ENABLE_WRITE_AND_INVALIDATE 0x0010
  4074. #define PCI_ENABLE_VGA_COMPATIBLE_PALETTE 0x0020
  4075. #define PCI_ENABLE_PARITY 0x0040 // (ro+)
  4076. #define PCI_ENABLE_WAIT_CYCLE 0x0080 // (ro+)
  4077. #define PCI_ENABLE_SERR 0x0100 // (ro+)
  4078. #define PCI_ENABLE_FAST_BACK_TO_BACK 0x0200 // (ro)
  4079. //
  4080. // Bit encodings for PCI_COMMON_CONFIG.Status
  4081. //
  4082. #define PCI_STATUS_CAPABILITIES_LIST 0x0010 // (ro)
  4083. #define PCI_STATUS_66MHZ_CAPABLE 0x0020 // (ro)
  4084. #define PCI_STATUS_UDF_SUPPORTED 0x0040 // (ro)
  4085. #define PCI_STATUS_FAST_BACK_TO_BACK 0x0080 // (ro)
  4086. #define PCI_STATUS_DATA_PARITY_DETECTED 0x0100
  4087. #define PCI_STATUS_DEVSEL 0x0600 // 2 bits wide
  4088. #define PCI_STATUS_SIGNALED_TARGET_ABORT 0x0800
  4089. #define PCI_STATUS_RECEIVED_TARGET_ABORT 0x1000
  4090. #define PCI_STATUS_RECEIVED_MASTER_ABORT 0x2000
  4091. #define PCI_STATUS_SIGNALED_SYSTEM_ERROR 0x4000
  4092. #define PCI_STATUS_DETECTED_PARITY_ERROR 0x8000
  4093. //
  4094. // The NT PCI Driver uses a WhichSpace parameter on its CONFIG_READ/WRITE
  4095. // routines. The following values are defined-
  4096. //
  4097. #define PCI_WHICHSPACE_CONFIG 0x0
  4098. #define PCI_WHICHSPACE_ROM 0x52696350
  4099. // end_wdm
  4100. //
  4101. // PCI Capability IDs
  4102. //
  4103. #define PCI_CAPABILITY_ID_POWER_MANAGEMENT 0x01
  4104. #define PCI_CAPABILITY_ID_AGP 0x02
  4105. #define PCI_CAPABILITY_ID_MSI 0x05
  4106. #define PCI_CAPABILITY_ID_AGP_TARGET 0x0E
  4107. //
  4108. // All PCI Capability structures have the following header.
  4109. //
  4110. // CapabilityID is used to identify the type of the structure (is
  4111. // one of the PCI_CAPABILITY_ID values above.
  4112. //
  4113. // Next is the offset in PCI Configuration space (0x40 - 0xfc) of the
  4114. // next capability structure in the list, or 0x00 if there are no more
  4115. // entries.
  4116. //
  4117. typedef struct _PCI_CAPABILITIES_HEADER {
  4118. UCHAR CapabilityID;
  4119. UCHAR Next;
  4120. } PCI_CAPABILITIES_HEADER, *PPCI_CAPABILITIES_HEADER;
  4121. //
  4122. // Power Management Capability
  4123. //
  4124. typedef struct _PCI_PMC {
  4125. UCHAR Version:3;
  4126. UCHAR PMEClock:1;
  4127. UCHAR Rsvd1:1;
  4128. UCHAR DeviceSpecificInitialization:1;
  4129. UCHAR Rsvd2:2;
  4130. struct _PM_SUPPORT {
  4131. UCHAR Rsvd2:1;
  4132. UCHAR D1:1;
  4133. UCHAR D2:1;
  4134. UCHAR PMED0:1;
  4135. UCHAR PMED1:1;
  4136. UCHAR PMED2:1;
  4137. UCHAR PMED3Hot:1;
  4138. UCHAR PMED3Cold:1;
  4139. } Support;
  4140. } PCI_PMC, *PPCI_PMC;
  4141. typedef struct _PCI_PMCSR {
  4142. USHORT PowerState:2;
  4143. USHORT Rsvd1:6;
  4144. USHORT PMEEnable:1;
  4145. USHORT DataSelect:4;
  4146. USHORT DataScale:2;
  4147. USHORT PMEStatus:1;
  4148. } PCI_PMCSR, *PPCI_PMCSR;
  4149. typedef struct _PCI_PMCSR_BSE {
  4150. UCHAR Rsvd1:6;
  4151. UCHAR D3HotSupportsStopClock:1; // B2_B3#
  4152. UCHAR BusPowerClockControlEnabled:1; // BPCC_EN
  4153. } PCI_PMCSR_BSE, *PPCI_PMCSR_BSE;
  4154. typedef struct _PCI_PM_CAPABILITY {
  4155. PCI_CAPABILITIES_HEADER Header;
  4156. //
  4157. // Power Management Capabilities (Offset = 2)
  4158. //
  4159. union {
  4160. PCI_PMC Capabilities;
  4161. USHORT AsUSHORT;
  4162. } PMC;
  4163. //
  4164. // Power Management Control/Status (Offset = 4)
  4165. //
  4166. union {
  4167. PCI_PMCSR ControlStatus;
  4168. USHORT AsUSHORT;
  4169. } PMCSR;
  4170. //
  4171. // PMCSR PCI-PCI Bridge Support Extensions
  4172. //
  4173. union {
  4174. PCI_PMCSR_BSE BridgeSupport;
  4175. UCHAR AsUCHAR;
  4176. } PMCSR_BSE;
  4177. //
  4178. // Optional read only 8 bit Data register. Contents controlled by
  4179. // DataSelect and DataScale in ControlStatus.
  4180. //
  4181. UCHAR Data;
  4182. } PCI_PM_CAPABILITY, *PPCI_PM_CAPABILITY;
  4183. //
  4184. // AGP Capability
  4185. //
  4186. typedef struct _PCI_AGP_CAPABILITY {
  4187. PCI_CAPABILITIES_HEADER Header;
  4188. USHORT Minor:4;
  4189. USHORT Major:4;
  4190. USHORT Rsvd1:8;
  4191. struct _PCI_AGP_STATUS {
  4192. ULONG Rate:3;
  4193. ULONG Agp3Mode:1;
  4194. ULONG FastWrite:1;
  4195. ULONG FourGB:1;
  4196. ULONG HostTransDisable:1;
  4197. ULONG Gart64:1;
  4198. ULONG ITA_Coherent:1;
  4199. ULONG SideBandAddressing:1; // SBA
  4200. ULONG CalibrationCycle:3;
  4201. ULONG AsyncRequestSize:3;
  4202. ULONG Rsvd1:1;
  4203. ULONG Isoch:1;
  4204. ULONG Rsvd2:6;
  4205. ULONG RequestQueueDepthMaximum:8; // RQ
  4206. } AGPStatus;
  4207. struct _PCI_AGP_COMMAND {
  4208. ULONG Rate:3;
  4209. ULONG Rsvd1:1;
  4210. ULONG FastWriteEnable:1;
  4211. ULONG FourGBEnable:1;
  4212. ULONG Rsvd2:1;
  4213. ULONG Gart64:1;
  4214. ULONG AGPEnable:1;
  4215. ULONG SBAEnable:1;
  4216. ULONG CalibrationCycle:3;
  4217. ULONG AsyncReqSize:3;
  4218. ULONG Rsvd3:8;
  4219. ULONG RequestQueueDepth:8;
  4220. } AGPCommand;
  4221. } PCI_AGP_CAPABILITY, *PPCI_AGP_CAPABILITY;
  4222. //
  4223. // An AGPv3 Target must have an extended capability,
  4224. // but it's only present for a Master when the Isoch
  4225. // bit is set in its status register
  4226. //
  4227. typedef enum _EXTENDED_AGP_REGISTER {
  4228. IsochStatus,
  4229. AgpControl,
  4230. ApertureSize,
  4231. AperturePageSize,
  4232. GartLow,
  4233. GartHigh,
  4234. IsochCommand
  4235. } EXTENDED_AGP_REGISTER, *PEXTENDED_AGP_REGISTER;
  4236. typedef struct _PCI_AGP_ISOCH_STATUS {
  4237. ULONG ErrorCode: 2;
  4238. ULONG Rsvd1: 1;
  4239. ULONG Isoch_L: 3;
  4240. ULONG Isoch_Y: 2;
  4241. ULONG Isoch_N: 8;
  4242. ULONG Rsvd2: 16;
  4243. } PCI_AGP_ISOCH_STATUS, *PPCI_AGP_ISOCH_STATUS;
  4244. typedef struct _PCI_AGP_CONTROL {
  4245. ULONG Rsvd1: 7;
  4246. ULONG GTLB_Enable: 1;
  4247. ULONG AP_Enable: 1;
  4248. ULONG CAL_Disable: 1;
  4249. ULONG Rsvd2: 22;
  4250. } PCI_AGP_CONTROL, *PPCI_AGP_CONTROL;
  4251. typedef struct _PCI_AGP_APERTURE_PAGE_SIZE {
  4252. USHORT PageSizeMask: 11;
  4253. USHORT Rsvd1: 1;
  4254. USHORT PageSizeSelect: 4;
  4255. } PCI_AGP_APERTURE_PAGE_SIZE, *PPCI_AGP_APERTURE_PAGE_SIZE;
  4256. typedef struct _PCI_AGP_ISOCH_COMMAND {
  4257. USHORT Rsvd1: 6;
  4258. USHORT Isoch_Y: 2;
  4259. USHORT Isoch_N: 8;
  4260. } PCI_AGP_ISOCH_COMMAND, *PPCI_AGP_ISOCH_COMMAND;
  4261. typedef struct PCI_AGP_EXTENDED_CAPABILITY {
  4262. PCI_AGP_ISOCH_STATUS IsochStatus;
  4263. //
  4264. // Target only ----------------<<-begin->>
  4265. //
  4266. PCI_AGP_CONTROL AgpControl;
  4267. USHORT ApertureSize;
  4268. PCI_AGP_APERTURE_PAGE_SIZE AperturePageSize;
  4269. ULONG GartLow;
  4270. ULONG GartHigh;
  4271. //
  4272. // ------------------------------<<-end->>
  4273. //
  4274. PCI_AGP_ISOCH_COMMAND IsochCommand;
  4275. } PCI_AGP_EXTENDED_CAPABILITY, *PPCI_AGP_EXTENDED_CAPABILITY;
  4276. #define PCI_AGP_RATE_1X 0x1
  4277. #define PCI_AGP_RATE_2X 0x2
  4278. #define PCI_AGP_RATE_4X 0x4
  4279. //
  4280. // MSI (Message Signalled Interrupts) Capability
  4281. //
  4282. typedef struct _PCI_MSI_CAPABILITY {
  4283. PCI_CAPABILITIES_HEADER Header;
  4284. struct _PCI_MSI_MESSAGE_CONTROL {
  4285. USHORT MSIEnable:1;
  4286. USHORT MultipleMessageCapable:3;
  4287. USHORT MultipleMessageEnable:3;
  4288. USHORT CapableOf64Bits:1;
  4289. USHORT Reserved:8;
  4290. } MessageControl;
  4291. union {
  4292. struct _PCI_MSI_MESSAGE_ADDRESS {
  4293. ULONG_PTR Reserved:2; // always zero, DWORD aligned address
  4294. ULONG_PTR Address:30;
  4295. } Register;
  4296. ULONG_PTR Raw;
  4297. } MessageAddress;
  4298. //
  4299. // The rest of the Capability structure differs depending on whether
  4300. // 32bit or 64bit addressing is being used.
  4301. //
  4302. // (The CapableOf64Bits bit above determines this)
  4303. //
  4304. union {
  4305. // For 64 bit devices
  4306. struct _PCI_MSI_64BIT_DATA {
  4307. ULONG MessageUpperAddress;
  4308. USHORT MessageData;
  4309. } Bit64;
  4310. // For 32 bit devices
  4311. struct _PCI_MSI_32BIT_DATA {
  4312. USHORT MessageData;
  4313. ULONG Unused;
  4314. } Bit32;
  4315. } Data;
  4316. } PCI_MSI_CAPABILITY, *PPCI_PCI_CAPABILITY;
  4317. // begin_wdm
  4318. //
  4319. // Base Class Code encodings for Base Class (from PCI spec rev 2.1).
  4320. //
  4321. #define PCI_CLASS_PRE_20 0x00
  4322. #define PCI_CLASS_MASS_STORAGE_CTLR 0x01
  4323. #define PCI_CLASS_NETWORK_CTLR 0x02
  4324. #define PCI_CLASS_DISPLAY_CTLR 0x03
  4325. #define PCI_CLASS_MULTIMEDIA_DEV 0x04
  4326. #define PCI_CLASS_MEMORY_CTLR 0x05
  4327. #define PCI_CLASS_BRIDGE_DEV 0x06
  4328. #define PCI_CLASS_SIMPLE_COMMS_CTLR 0x07
  4329. #define PCI_CLASS_BASE_SYSTEM_DEV 0x08
  4330. #define PCI_CLASS_INPUT_DEV 0x09
  4331. #define PCI_CLASS_DOCKING_STATION 0x0a
  4332. #define PCI_CLASS_PROCESSOR 0x0b
  4333. #define PCI_CLASS_SERIAL_BUS_CTLR 0x0c
  4334. #define PCI_CLASS_WIRELESS_CTLR 0x0d
  4335. #define PCI_CLASS_INTELLIGENT_IO_CTLR 0x0e
  4336. #define PCI_CLASS_SATELLITE_COMMS_CTLR 0x0f
  4337. #define PCI_CLASS_ENCRYPTION_DECRYPTION 0x10
  4338. #define PCI_CLASS_DATA_ACQ_SIGNAL_PROC 0x11
  4339. // 0d thru fe reserved
  4340. #define PCI_CLASS_NOT_DEFINED 0xff
  4341. //
  4342. // Sub Class Code encodings (PCI rev 2.1).
  4343. //
  4344. // Class 00 - PCI_CLASS_PRE_20
  4345. #define PCI_SUBCLASS_PRE_20_NON_VGA 0x00
  4346. #define PCI_SUBCLASS_PRE_20_VGA 0x01
  4347. // Class 01 - PCI_CLASS_MASS_STORAGE_CTLR
  4348. #define PCI_SUBCLASS_MSC_SCSI_BUS_CTLR 0x00
  4349. #define PCI_SUBCLASS_MSC_IDE_CTLR 0x01
  4350. #define PCI_SUBCLASS_MSC_FLOPPY_CTLR 0x02
  4351. #define PCI_SUBCLASS_MSC_IPI_CTLR 0x03
  4352. #define PCI_SUBCLASS_MSC_RAID_CTLR 0x04
  4353. #define PCI_SUBCLASS_MSC_OTHER 0x80
  4354. // Class 02 - PCI_CLASS_NETWORK_CTLR
  4355. #define PCI_SUBCLASS_NET_ETHERNET_CTLR 0x00
  4356. #define PCI_SUBCLASS_NET_TOKEN_RING_CTLR 0x01
  4357. #define PCI_SUBCLASS_NET_FDDI_CTLR 0x02
  4358. #define PCI_SUBCLASS_NET_ATM_CTLR 0x03
  4359. #define PCI_SUBCLASS_NET_ISDN_CTLR 0x04
  4360. #define PCI_SUBCLASS_NET_OTHER 0x80
  4361. // Class 03 - PCI_CLASS_DISPLAY_CTLR
  4362. // N.B. Sub Class 00 could be VGA or 8514 depending on Interface byte
  4363. #define PCI_SUBCLASS_VID_VGA_CTLR 0x00
  4364. #define PCI_SUBCLASS_VID_XGA_CTLR 0x01
  4365. #define PCI_SUBLCASS_VID_3D_CTLR 0x02
  4366. #define PCI_SUBCLASS_VID_OTHER 0x80
  4367. // Class 04 - PCI_CLASS_MULTIMEDIA_DEV
  4368. #define PCI_SUBCLASS_MM_VIDEO_DEV 0x00
  4369. #define PCI_SUBCLASS_MM_AUDIO_DEV 0x01
  4370. #define PCI_SUBCLASS_MM_TELEPHONY_DEV 0x02
  4371. #define PCI_SUBCLASS_MM_OTHER 0x80
  4372. // Class 05 - PCI_CLASS_MEMORY_CTLR
  4373. #define PCI_SUBCLASS_MEM_RAM 0x00
  4374. #define PCI_SUBCLASS_MEM_FLASH 0x01
  4375. #define PCI_SUBCLASS_MEM_OTHER 0x80
  4376. // Class 06 - PCI_CLASS_BRIDGE_DEV
  4377. #define PCI_SUBCLASS_BR_HOST 0x00
  4378. #define PCI_SUBCLASS_BR_ISA 0x01
  4379. #define PCI_SUBCLASS_BR_EISA 0x02
  4380. #define PCI_SUBCLASS_BR_MCA 0x03
  4381. #define PCI_SUBCLASS_BR_PCI_TO_PCI 0x04
  4382. #define PCI_SUBCLASS_BR_PCMCIA 0x05
  4383. #define PCI_SUBCLASS_BR_NUBUS 0x06
  4384. #define PCI_SUBCLASS_BR_CARDBUS 0x07
  4385. #define PCI_SUBCLASS_BR_RACEWAY 0x08
  4386. #define PCI_SUBCLASS_BR_OTHER 0x80
  4387. // Class 07 - PCI_CLASS_SIMPLE_COMMS_CTLR
  4388. // N.B. Sub Class 00 and 01 additional info in Interface byte
  4389. #define PCI_SUBCLASS_COM_SERIAL 0x00
  4390. #define PCI_SUBCLASS_COM_PARALLEL 0x01
  4391. #define PCI_SUBCLASS_COM_MULTIPORT 0x02
  4392. #define PCI_SUBCLASS_COM_MODEM 0x03
  4393. #define PCI_SUBCLASS_COM_OTHER 0x80
  4394. // Class 08 - PCI_CLASS_BASE_SYSTEM_DEV
  4395. // N.B. See Interface byte for additional info.
  4396. #define PCI_SUBCLASS_SYS_INTERRUPT_CTLR 0x00
  4397. #define PCI_SUBCLASS_SYS_DMA_CTLR 0x01
  4398. #define PCI_SUBCLASS_SYS_SYSTEM_TIMER 0x02
  4399. #define PCI_SUBCLASS_SYS_REAL_TIME_CLOCK 0x03
  4400. #define PCI_SUBCLASS_SYS_GEN_HOTPLUG_CTLR 0x04
  4401. #define PCI_SUBCLASS_SYS_OTHER 0x80
  4402. // Class 09 - PCI_CLASS_INPUT_DEV
  4403. #define PCI_SUBCLASS_INP_KEYBOARD 0x00
  4404. #define PCI_SUBCLASS_INP_DIGITIZER 0x01
  4405. #define PCI_SUBCLASS_INP_MOUSE 0x02
  4406. #define PCI_SUBCLASS_INP_SCANNER 0x03
  4407. #define PCI_SUBCLASS_INP_GAMEPORT 0x04
  4408. #define PCI_SUBCLASS_INP_OTHER 0x80
  4409. // Class 0a - PCI_CLASS_DOCKING_STATION
  4410. #define PCI_SUBCLASS_DOC_GENERIC 0x00
  4411. #define PCI_SUBCLASS_DOC_OTHER 0x80
  4412. // Class 0b - PCI_CLASS_PROCESSOR
  4413. #define PCI_SUBCLASS_PROC_386 0x00
  4414. #define PCI_SUBCLASS_PROC_486 0x01
  4415. #define PCI_SUBCLASS_PROC_PENTIUM 0x02
  4416. #define PCI_SUBCLASS_PROC_ALPHA 0x10
  4417. #define PCI_SUBCLASS_PROC_POWERPC 0x20
  4418. #define PCI_SUBCLASS_PROC_COPROCESSOR 0x40
  4419. // Class 0c - PCI_CLASS_SERIAL_BUS_CTLR
  4420. #define PCI_SUBCLASS_SB_IEEE1394 0x00
  4421. #define PCI_SUBCLASS_SB_ACCESS 0x01
  4422. #define PCI_SUBCLASS_SB_SSA 0x02
  4423. #define PCI_SUBCLASS_SB_USB 0x03
  4424. #define PCI_SUBCLASS_SB_FIBRE_CHANNEL 0x04
  4425. #define PCI_SUBCLASS_SB_SMBUS 0x05
  4426. // Class 0d - PCI_CLASS_WIRELESS_CTLR
  4427. #define PCI_SUBCLASS_WIRELESS_IRDA 0x00
  4428. #define PCI_SUBCLASS_WIRELESS_CON_IR 0x01
  4429. #define PCI_SUBCLASS_WIRELESS_RF 0x10
  4430. #define PCI_SUBCLASS_WIRELESS_OTHER 0x80
  4431. // Class 0e - PCI_CLASS_INTELLIGENT_IO_CTLR
  4432. #define PCI_SUBCLASS_INTIO_I2O 0x00
  4433. // Class 0f - PCI_CLASS_SATELLITE_CTLR
  4434. #define PCI_SUBCLASS_SAT_TV 0x01
  4435. #define PCI_SUBCLASS_SAT_AUDIO 0x02
  4436. #define PCI_SUBCLASS_SAT_VOICE 0x03
  4437. #define PCI_SUBCLASS_SAT_DATA 0x04
  4438. // Class 10 - PCI_CLASS_ENCRYPTION_DECRYPTION
  4439. #define PCI_SUBCLASS_CRYPTO_NET_COMP 0x00
  4440. #define PCI_SUBCLASS_CRYPTO_ENTERTAINMENT 0x10
  4441. #define PCI_SUBCLASS_CRYPTO_OTHER 0x80
  4442. // Class 11 - PCI_CLASS_DATA_ACQ_SIGNAL_PROC
  4443. #define PCI_SUBCLASS_DASP_DPIO 0x00
  4444. #define PCI_SUBCLASS_DASP_OTHER 0x80
  4445. typedef enum _MM_PAGE_PRIORITY {
  4446. LowPagePriority,
  4447. NormalPagePriority = 16,
  4448. HighPagePriority = 32
  4449. } MM_PAGE_PRIORITY;
  4450. #else // BINARY_COMPATIBLE && !NDIS_WDM
  4451. #if (!BINARY_COMPATIBLE)
  4452. //
  4453. // BINARY_COMPATIBLE = 0 and NDIS_WDM = 1 then use ntddk.h
  4454. // BINARY_COMPATIBLE = 0 and NDIS_WDM = 0 then use ntddk.h
  4455. //
  4456. //
  4457. // The definitions available in ntddk.h must not be used directly by non-WDM miniport drivers.
  4458. //
  4459. #include <ntddk.h>
  4460. #else // !BINARY_COMPATIBLE
  4461. //
  4462. // BINARY_COMPATIBLE = 1 and NDIS_WDM = 1 then use wdm.h
  4463. //
  4464. #include <wdm.h>
  4465. #endif // else !BINARY_COMPATIBLE
  4466. #endif // else BINARY_COMPATIBLE && !NDIS_WDM