Basic NDIS 3.0 support
[reactos.git] / reactos / drivers / net / ndis / include / ndissys.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS NDIS library
4 * FILE: ndissys.h
5 * PURPOSE: NDIS library definitions
6 * NOTES: Spin lock acquire order:
7 * - Miniport list lock
8 * - Adapter list lock
9 */
10 #ifndef __NDISSYS_H
11 #define __NDISSYS_H
12
13 #define NDIS50 1 /* Use NDIS 5.0 structures by default */
14
15 #ifdef _MSC_VER
16 #include <basetsd.h>
17 #include <ntddk.h>
18 #include <windef.h>
19 #include <ndis.h>
20 #else /* _MSC_VER */
21 #include <ddk/ntddk.h>
22 #include <net/ndis.h>
23 #endif /* _MSC_VER */
24
25 #include <debug.h>
26
27
28 #ifndef _MSC_VER
29 /* FIXME: The following should be moved to ntddk.h */
30
31 /* i386 specific constants */
32
33 /* Page size for the Intel 386 is 4096 */
34 #define PAGE_SIZE (ULONG)0x1000
35
36 /* 4096 is 2^12. Used to find the virtual page number from a virtual address */
37 #define PAGE_SHIFT 12L
38
39 /*
40 * ULONG ADDRESS_AND_SIZE_TO_SPAN_PAGES(
41 * IN PVOID Va,
42 * IN ULONG Size);
43 */
44 #define ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va, Size) \
45 ((((ULONG)((ULONG)(Size) - 1) >> PAGE_SHIFT) + \
46 (((((ULONG)(Size - 1) & (PAGE_SIZE - 1)) + \
47 ((ULONG)Va & (PAGE_SIZE - 1)))) >> PAGE_SHIFT)) + 1)
48
49 /*
50 * ULONG MmGetMdlByteCount(
51 * IN PMDL Mdl)
52 */
53 #define MmGetMdlByteCount(Mdl) \
54 ((Mdl)->ByteCount)
55
56 #endif
57
58
59 /* Exported functions */
60 #ifdef _MSC_VER
61 #define EXPORT __declspec(dllexport)
62 #else
63 #define EXPORT STDCALL
64 #endif
65
66
67 #ifdef DBG
68
69 #define DEBUG_REFCHECK(Object) { \
70 if ((Object)->RefCount <= 0) { \
71 NDIS_DbgPrint(MIN_TRACE, ("Object at (0x%X) has invalid reference count (%d).\n", \
72 (Object), (Object)->RefCount)); \
73 } \
74 }
75
76 #else
77
78 #define DEBUG_REFCHECK(Object)
79
80 #endif
81
82
83 /*
84 * VOID ReferenceObject(
85 * PVOID Object)
86 */
87 #define ReferenceObject(Object) \
88 { \
89 DEBUG_REFCHECK(Object); \
90 NDIS_DbgPrint(DEBUG_REFCOUNT, ("Referencing object at (0x%X). RefCount (%d).\n", \
91 (Object), (Object)->RefCount)); \
92 \
93 InterlockedIncrement(&((Object)->RefCount)); \
94 }
95
96 /*
97 * VOID DereferenceObject(
98 * PVOID Object)
99 */
100 #define DereferenceObject(Object) \
101 { \
102 DEBUG_REFCHECK(Object); \
103 NDIS_DbgPrint(DEBUG_REFCOUNT, ("Dereferencing object at (0x%X). RefCount (%d).\n", \
104 (Object), (Object)->RefCount)); \
105 \
106 if (InterlockedDecrement(&((Object)->RefCount)) == 0) \
107 PoolFreeBuffer(Object); \
108 }
109
110
111 #define MIN(value1, value2) \
112 ((value1 < value2)? value1 : value2)
113
114 #define MAX(value1, value2) \
115 ((value1 > value2)? value1 : value2)
116
117 #endif /* __NDISSYS_H */
118
119 /* EOF */