ntoskrnl_var.h revision 124582
1158432Scognet/*
2158432Scognet * Copyright (c) 2003
3158432Scognet *	Bill Paul <wpaul@windriver.com>.  All rights reserved.
4158432Scognet *
5158432Scognet * Redistribution and use in source and binary forms, with or without
6158432Scognet * modification, are permitted provided that the following conditions
7158432Scognet * are met:
8158432Scognet * 1. Redistributions of source code must retain the above copyright
9158432Scognet *    notice, this list of conditions and the following disclaimer.
10158432Scognet * 2. Redistributions in binary form must reproduce the above copyright
11158432Scognet *    notice, this list of conditions and the following disclaimer in the
12158432Scognet *    documentation and/or other materials provided with the distribution.
13158432Scognet * 3. All advertising materials mentioning features or use of this software
14158432Scognet *    must display the following acknowledgement:
15158432Scognet *	This product includes software developed by Bill Paul.
16158432Scognet * 4. Neither the name of the author nor the names of any co-contributors
17158432Scognet *    may be used to endorse or promote products derived from this software
18158432Scognet *    without specific prior written permission.
19158432Scognet *
20158432Scognet * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21158432Scognet * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22158432Scognet * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23158432Scognet * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24158432Scognet * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25158432Scognet * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26158432Scognet * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27158432Scognet * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28158432Scognet * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29158432Scognet * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30158432Scognet * THE POSSIBILITY OF SUCH DAMAGE.
31158432Scognet *
32158432Scognet * $FreeBSD: head/sys/compat/ndis/ntoskrnl_var.h 124582 2004-01-16 02:07:04Z obrien $
33158432Scognet */
34158432Scognet
35158432Scognet#ifndef _NTOSKRNL_VAR_H_
36158432Scognet#define _NTOSKRNL_VAR_H_
37158432Scognet
38158432Scognet/* Note: assumes x86 page size of 4K. */
39158432Scognet#define PAGE_SHIFT	12
40158432Scognet#define SPAN_PAGES(ptr, len)					\
41158432Scognet	((uint32_t)((((uintptr_t)(ptr) & (PAGE_SIZE -1)) +	\
42158432Scognet	(len) + (PAGE_SIZE - 1)) >> PAGE_SHIFT))
43158432Scognet#define PAGE_ALIGN(ptr)						\
44158432Scognet	((void *)((uintptr_t)(ptr) & ~(PAGE_SIZE - 1)))
45158432Scognet#define BYTE_OFFSET(ptr)					\
46158432Scognet	((uint32_t)((uintptr_t)(ptr) & (PAGE_SIZE - 1)))
47158432Scognet#define MDL_INIT(b, baseva, len)					\
48	(b)->nb_next = NULL;						\
49	(b)->nb_size = (uint16_t)(sizeof(struct ndis_buffer) +		\
50		(sizeof(uint32_t) * SPAN_PAGES((baseva), (len))));	\
51	(b)->nb_flags = 0;						\
52	(b)->nb_startva = (void *)PAGE_ALIGN((baseva));			\
53	(b)->nb_byteoffset = BYTE_OFFSET((baseva));			\
54	(b)->nb_bytecount = (uint32_t)(len);
55#define MDL_VA(b)						\
56	((void *)((char *)((b)->nb_startva) + (b)->nb_byteoffset))
57
58/*-
59 * The ndis_kspin_lock type is called KSPIN_LOCK in MS-Windows.
60 * According to the Windows DDK header files, KSPIN_LOCK is defined like this:
61 *	typedef ULONG_PTR KSPIN_LOCK;
62 *
63 * From basetsd.h (SDK, Feb. 2003):
64 * 	typedef [public] unsigned __int3264 ULONG_PTR, *PULONG_PTR;
65 * 	typedef unsigned __int64 ULONG_PTR, *PULONG_PTR;
66 * 	typedef _W64 unsigned long ULONG_PTR, *PULONG_PTR;
67 *
68 * The keyword __int3264 specifies an integral type that has the following
69 * properties:
70 *	+ It is 32-bit on 32-bit platforms
71 *	+ It is 64-bit on 64-bit platforms
72 *	+ It is 32-bit on the wire for backward compatibility.
73 *	  It gets truncated on the sending side and extended appropriately
74 *	  (signed or unsigned) on the receiving side.
75 *
76 * Thus register_t seems the proper mapping onto FreeBSD for spin locks.
77 */
78
79typedef register_t kspin_lock;
80
81struct slist_entry {
82	struct slist_entry	*sl_next;
83};
84
85typedef struct slist_entry slist_entry;
86
87union slist_header {
88	uint64_t		slh_align;
89	struct {
90		struct slist_entry	*slh_next;
91		uint16_t		slh_depth;
92		uint16_t		slh_seq;
93	} slh_list;
94};
95
96typedef union slist_header slist_header;
97
98struct list_entry {
99        struct list_entry *nle_flink;
100        struct list_entry *nle_blink;
101};
102
103typedef struct list_entry list_entry;
104
105struct general_lookaside {
106	slist_header		gl_listhead;
107	uint16_t		gl_depth;
108	uint16_t		gl_maxdepth;
109	uint32_t		gl_totallocs;
110	union {
111		uint32_t		gl_allocmisses;
112		uint32_t		gl_allochits;
113	} u_a;
114	uint32_t		gl_totalfrees;
115	union {
116		uint32_t		gl_freemisses;
117		uint32_t		gl_freehits;
118	} u_m;
119	uint32_t		gl_type;
120	uint32_t		gl_tag;
121	uint32_t		gl_size;
122	void			*gl_allocfunc;
123	void			*gl_freefunc;
124	list_entry		gl_listent;
125	uint32_t		gl_lasttotallocs;
126	union {
127		uint32_t		gl_lastallocmisses;
128		uint32_t		gl_lastallochits;
129	} u_l;
130	uint32_t		gl_rsvd[2];
131};
132
133typedef struct general_lookaside general_lookaside;
134
135struct npaged_lookaside_list {
136	general_lookaside	nll_l;
137	kspin_lock		nll_obsoletelock;
138};
139
140typedef struct npaged_lookaside_list npaged_lookaside_list;
141typedef struct npaged_lookaside_list paged_lookaside_list;
142
143typedef void * (*lookaside_alloc_func)(uint32_t, size_t, uint32_t);
144typedef void (*lookaside_free_func)(void *);
145
146
147extern image_patch_table ntoskrnl_functbl[];
148
149__BEGIN_DECLS
150extern int ntoskrnl_libinit(void);
151extern int ntoskrnl_libfini(void);
152__END_DECLS
153
154#endif /* _NTOSKRNL_VAR_H_ */
155