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

5784 lines
127 KiB

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