ntoskrnl_var.h revision 125551
1123474Swpaul/* 2123474Swpaul * Copyright (c) 2003 3123474Swpaul * Bill Paul <wpaul@windriver.com>. All rights reserved. 4123474Swpaul * 5123474Swpaul * Redistribution and use in source and binary forms, with or without 6123474Swpaul * modification, are permitted provided that the following conditions 7123474Swpaul * are met: 8123474Swpaul * 1. Redistributions of source code must retain the above copyright 9123474Swpaul * notice, this list of conditions and the following disclaimer. 10123474Swpaul * 2. Redistributions in binary form must reproduce the above copyright 11123474Swpaul * notice, this list of conditions and the following disclaimer in the 12123474Swpaul * documentation and/or other materials provided with the distribution. 13123474Swpaul * 3. All advertising materials mentioning features or use of this software 14123474Swpaul * must display the following acknowledgement: 15123474Swpaul * This product includes software developed by Bill Paul. 16123474Swpaul * 4. Neither the name of the author nor the names of any co-contributors 17123474Swpaul * may be used to endorse or promote products derived from this software 18123474Swpaul * without specific prior written permission. 19123474Swpaul * 20123474Swpaul * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 21123474Swpaul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22123474Swpaul * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23123474Swpaul * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 24123474Swpaul * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25123474Swpaul * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26123474Swpaul * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27123474Swpaul * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28123474Swpaul * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29123474Swpaul * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30123474Swpaul * THE POSSIBILITY OF SUCH DAMAGE. 31123474Swpaul * 32123474Swpaul * $FreeBSD: head/sys/compat/ndis/ntoskrnl_var.h 125551 2004-02-07 06:44:13Z wpaul $ 33123474Swpaul */ 34123474Swpaul 35123474Swpaul#ifndef _NTOSKRNL_VAR_H_ 36123474Swpaul#define _NTOSKRNL_VAR_H_ 37123474Swpaul 38123512Swpaul/* Note: assumes x86 page size of 4K. */ 39123512Swpaul#define PAGE_SHIFT 12 40123512Swpaul#define SPAN_PAGES(ptr, len) \ 41123512Swpaul ((uint32_t)((((uintptr_t)(ptr) & (PAGE_SIZE -1)) + \ 42123512Swpaul (len) + (PAGE_SIZE - 1)) >> PAGE_SHIFT)) 43123757Swpaul#define PAGE_ALIGN(ptr) \ 44123757Swpaul ((void *)((uintptr_t)(ptr) & ~(PAGE_SIZE - 1))) 45123757Swpaul#define BYTE_OFFSET(ptr) \ 46123757Swpaul ((uint32_t)((uintptr_t)(ptr) & (PAGE_SIZE - 1))) 47123757Swpaul#define MDL_INIT(b, baseva, len) \ 48123757Swpaul (b)->nb_next = NULL; \ 49123757Swpaul (b)->nb_size = (uint16_t)(sizeof(struct ndis_buffer) + \ 50123757Swpaul (sizeof(uint32_t) * SPAN_PAGES((baseva), (len)))); \ 51123757Swpaul (b)->nb_flags = 0; \ 52123757Swpaul (b)->nb_startva = (void *)PAGE_ALIGN((baseva)); \ 53123757Swpaul (b)->nb_byteoffset = BYTE_OFFSET((baseva)); \ 54123757Swpaul (b)->nb_bytecount = (uint32_t)(len); 55123757Swpaul#define MDL_VA(b) \ 56123757Swpaul ((void *)((char *)((b)->nb_startva) + (b)->nb_byteoffset)) 57123512Swpaul 58124729Swpaul#define WDM_MAJOR 1 59124729Swpaul#define WDM_MINOR_WIN98 0x00 60124729Swpaul#define WDM_MINOR_WINME 0x05 61124729Swpaul#define WDM_MINOR_WIN2000 0x10 62124729Swpaul#define WDM_MINOR_WINXP 0x20 63124729Swpaul#define WDM_MINOR_WIN2003 0x30 64124729Swpaul 65124582Sobrien/*- 66124582Sobrien * The ndis_kspin_lock type is called KSPIN_LOCK in MS-Windows. 67124582Sobrien * According to the Windows DDK header files, KSPIN_LOCK is defined like this: 68124582Sobrien * typedef ULONG_PTR KSPIN_LOCK; 69124582Sobrien * 70124582Sobrien * From basetsd.h (SDK, Feb. 2003): 71124582Sobrien * typedef [public] unsigned __int3264 ULONG_PTR, *PULONG_PTR; 72124582Sobrien * typedef unsigned __int64 ULONG_PTR, *PULONG_PTR; 73124582Sobrien * typedef _W64 unsigned long ULONG_PTR, *PULONG_PTR; 74124582Sobrien * 75124582Sobrien * The keyword __int3264 specifies an integral type that has the following 76124582Sobrien * properties: 77124582Sobrien * + It is 32-bit on 32-bit platforms 78124582Sobrien * + It is 64-bit on 64-bit platforms 79124582Sobrien * + It is 32-bit on the wire for backward compatibility. 80124582Sobrien * It gets truncated on the sending side and extended appropriately 81124582Sobrien * (signed or unsigned) on the receiving side. 82124582Sobrien * 83124582Sobrien * Thus register_t seems the proper mapping onto FreeBSD for spin locks. 84124582Sobrien */ 85123474Swpaul 86124582Sobrientypedef register_t kspin_lock; 87124582Sobrien 88123474Swpaulstruct slist_entry { 89123474Swpaul struct slist_entry *sl_next; 90123474Swpaul}; 91123474Swpaul 92123474Swpaultypedef struct slist_entry slist_entry; 93123474Swpaul 94123474Swpaulunion slist_header { 95123474Swpaul uint64_t slh_align; 96123474Swpaul struct { 97123474Swpaul struct slist_entry *slh_next; 98123474Swpaul uint16_t slh_depth; 99123474Swpaul uint16_t slh_seq; 100123474Swpaul } slh_list; 101123474Swpaul}; 102123474Swpaul 103123474Swpaultypedef union slist_header slist_header; 104123474Swpaul 105123507Swpaulstruct list_entry { 106123507Swpaul struct list_entry *nle_flink; 107123507Swpaul struct list_entry *nle_blink; 108123507Swpaul}; 109123507Swpaul 110123507Swpaultypedef struct list_entry list_entry; 111123507Swpaul 112125551Swpaul#define INIT_LIST_HEAD(l) \ 113125551Swpaul l->nle_flink = l->nle_blink = l 114125551Swpaul 115125551Swpaul#define REMOVE_LIST_ENTRY(e) \ 116125551Swpaul do { \ 117125551Swpaul list_entry *b; \ 118125551Swpaul list_entry *f; \ 119125551Swpaul \ 120125551Swpaul f = e->nle_flink; \ 121125551Swpaul b = e->nle_blink; \ 122125551Swpaul b->nle_flink = f; \ 123125551Swpaul f->nle_blink = b; \ 124125551Swpaul } while (0) 125125551Swpaul 126125551Swpaul#define REMOVE_LIST_HEAD(l) \ 127125551Swpaul do { \ 128125551Swpaul list_entry *f; \ 129125551Swpaul list_entry *e; \ 130125551Swpaul \ 131125551Swpaul e = l->nle_flink; \ 132125551Swpaul f = e->nle_flink; \ 133125551Swpaul l->nle_flink = f; \ 134125551Swpaul f->nle_blink = l; \ 135125551Swpaul } while (0) 136125551Swpaul 137125551Swpaul#define REMOVE_LIST_TAIL(l) \ 138125551Swpaul do { \ 139125551Swpaul list_entry *b; \ 140125551Swpaul list_entry *e; \ 141125551Swpaul \ 142125551Swpaul e = l->nle_blink; \ 143125551Swpaul b = e->nle_blink; \ 144125551Swpaul l->nle_blink = b; \ 145125551Swpaul b->nle_flink = l; \ 146125551Swpaul } while (0) 147125551Swpaul 148125551Swpaul#define INSERT_LIST_TAIL(l, e) \ 149125551Swpaul do { \ 150125551Swpaul list_entry *b; \ 151125551Swpaul \ 152125551Swpaul b = l->nle_blink; \ 153125551Swpaul e->nle_flink = l \ 154125551Swpaul e->nle_blink = b; \ 155125551Swpaul b->nle_flink = e; \ 156125551Swpaul l->nle_blink = e; \ 157125551Swpaul } while (0) 158125551Swpaul 159125551Swpaul#define INSERT_LIST_HEAD(l, e) \ 160125551Swpaul do { \ 161125551Swpaul list_entry *f; \ 162125551Swpaul \ 163125551Swpaul f = l->nle_flink; \ 164125551Swpaul e->nle_flink = f; \ 165125551Swpaul e->nle_blink = l; \ 166125551Swpaul f->nle_blink = e; \ 167125551Swpaul l->nle_flink = e; \ 168125551Swpaul } while (0) 169125551Swpaul 170125551Swpaulstruct nt_dispatch_header { 171125551Swpaul uint8_t dh_type; 172125551Swpaul uint8_t dh_abs; 173125551Swpaul uint8_t dh_size; 174125551Swpaul uint8_t dh_inserted; 175125551Swpaul uint32_t dh_sigstate; 176125551Swpaul list_entry dh_waitlisthead; 177125551Swpaul}; 178125551Swpaul 179125551Swpaultypedef struct nt_dispatch_header nt_dispatch_header; 180125551Swpaul 181125551Swpaul#define OTYPE_EVENT 0 182125551Swpaul#define OTYPE_MUTEX 1 183125551Swpaul#define OTYPE_THREAD 2 184125551Swpaul#define OTYPE_TIMER 3 185125551Swpaul 186125551Swpaul/* Windows dispatcher levels. */ 187125551Swpaul 188125551Swpaul#define PASSIVE_LEVEL 0 189125551Swpaul#define LOW_LEVEL 0 190125551Swpaul#define APC_LEVEL 1 191125551Swpaul#define DISPATCH_LEVEL 2 192125551Swpaul#define PROFILE_LEVEL 27 193125551Swpaul#define CLOCK1_LEVEL 28 194125551Swpaul#define CLOCK2_LEVEL 28 195125551Swpaul#define IPI_LEVEL 29 196125551Swpaul#define POWER_LEVEL 30 197125551Swpaul#define HIGH_LEVEL 31 198125551Swpaul 199125551Swpaul#define SYNC_LEVEL_UP DISPATCH_LEVEL 200125551Swpaul#define SYNC_LEVEL_MP (IPI_LEVEL - 1) 201125551Swpaul 202125551Swpaulstruct nt_objref { 203125551Swpaul nt_dispatch_header no_dh; 204125551Swpaul void *no_obj; 205125551Swpaul TAILQ_ENTRY(nt_objref) link; 206125551Swpaul}; 207125551Swpaul 208125551SwpaulTAILQ_HEAD(nt_objref_head, nt_objref); 209125551Swpaul 210125551Swpaultypedef struct nt_objref nt_objref; 211125551Swpaul 212125551Swpaul#define EVENT_TYPE_NOTIFY 0 213125551Swpaul#define EVENT_TYPE_SYNC 1 214125551Swpaul 215125551Swpaulstruct ktimer { 216125551Swpaul nt_dispatch_header k_header; 217125551Swpaul uint64_t k_duetime; 218125551Swpaul list_entry k_timerlistentry; 219125551Swpaul void *k_dpc; 220125551Swpaul uint32_t k_period; 221125551Swpaul}; 222125551Swpaul 223125551Swpaulstruct nt_kevent { 224125551Swpaul nt_dispatch_header k_header; 225125551Swpaul}; 226125551Swpaul 227125551Swpaultypedef struct nt_kevent nt_kevent; 228125551Swpaul 229125551Swpaul/* Kernel defered procedure call (i.e. timer callback) */ 230125551Swpaul 231125551Swpaulstruct kdpc; 232125551Swpaultypedef void (*kdpc_func)(struct kdpc *, void *, void *, void *); 233125551Swpaul 234125551Swpaulstruct kdpc { 235125551Swpaul uint16_t k_type; 236125551Swpaul uint8_t k_num; 237125551Swpaul uint8_t k_importance; 238125551Swpaul list_entry k_dpclistentry; 239125551Swpaul kdpc_func k_deferedfunc; 240125551Swpaul void *k_deferredctx; 241125551Swpaul void *k_sysarg1; 242125551Swpaul void *k_sysarg2; 243125551Swpaul uint32_t *k_lock; 244125551Swpaul}; 245125551Swpaul 246125551Swpaul/* 247125551Swpaul * Note: the acquisition count is BSD-specific. The Microsoft 248125551Swpaul * documentation says that mutexes can be acquired recursively 249125551Swpaul * by a given thread, but that you must release the mutex as 250125551Swpaul * many times as you acquired it before it will be set to the 251125551Swpaul * signalled state (i.e. before any other threads waiting on 252125551Swpaul * the object will be woken up). However the Windows KMUTANT 253125551Swpaul * structure has no field for keeping track of the number of 254125551Swpaul * acquisitions, so we need to add one ourselves. As long as 255125551Swpaul * driver code treats the mutex as opaque, we should be ok. 256125551Swpaul */ 257125551Swpaulstruct kmutant { 258125551Swpaul nt_dispatch_header km_header; 259125551Swpaul list_entry km_listentry; 260125551Swpaul void *km_ownerthread; 261125551Swpaul uint8_t km_abandoned; 262125551Swpaul uint8_t km_apcdisable; 263125551Swpaul uint32_t km_acquirecnt; 264125551Swpaul}; 265125551Swpaul 266125551Swpaultypedef struct kmutant kmutant; 267125551Swpaul 268123474Swpaulstruct general_lookaside { 269123474Swpaul slist_header gl_listhead; 270123474Swpaul uint16_t gl_depth; 271123474Swpaul uint16_t gl_maxdepth; 272123474Swpaul uint32_t gl_totallocs; 273123474Swpaul union { 274123474Swpaul uint32_t gl_allocmisses; 275123474Swpaul uint32_t gl_allochits; 276123474Swpaul } u_a; 277123474Swpaul uint32_t gl_totalfrees; 278123474Swpaul union { 279123474Swpaul uint32_t gl_freemisses; 280123474Swpaul uint32_t gl_freehits; 281123474Swpaul } u_m; 282123474Swpaul uint32_t gl_type; 283123474Swpaul uint32_t gl_tag; 284123474Swpaul uint32_t gl_size; 285123474Swpaul void *gl_allocfunc; 286123474Swpaul void *gl_freefunc; 287123507Swpaul list_entry gl_listent; 288123474Swpaul uint32_t gl_lasttotallocs; 289123474Swpaul union { 290123474Swpaul uint32_t gl_lastallocmisses; 291123474Swpaul uint32_t gl_lastallochits; 292123474Swpaul } u_l; 293123474Swpaul uint32_t gl_rsvd[2]; 294123474Swpaul}; 295123474Swpaul 296123474Swpaultypedef struct general_lookaside general_lookaside; 297123474Swpaul 298123474Swpaulstruct npaged_lookaside_list { 299123474Swpaul general_lookaside nll_l; 300123474Swpaul kspin_lock nll_obsoletelock; 301123474Swpaul}; 302123474Swpaul 303123474Swpaultypedef struct npaged_lookaside_list npaged_lookaside_list; 304123474Swpaultypedef struct npaged_lookaside_list paged_lookaside_list; 305123474Swpaul 306123474Swpaultypedef void * (*lookaside_alloc_func)(uint32_t, size_t, uint32_t); 307123474Swpaultypedef void (*lookaside_free_func)(void *); 308123474Swpaul 309125551Swpaulstruct irp; 310123474Swpaul 311125551Swpaulstruct kdevice_qentry { 312125551Swpaul list_entry kqe_devlistent; 313125551Swpaul uint32_t kqe_sortkey; 314125551Swpaul uint8_t kqe_inserted; 315125551Swpaul}; 316125551Swpaul 317125551Swpaultypedef struct kdevice_qentry kdevice_qentry; 318125551Swpaul 319125551Swpaulstruct kdevice_queue { 320125551Swpaul uint16_t kq_type; 321125551Swpaul uint16_t kq_size; 322125551Swpaul list_entry kq_devlisthead; 323125551Swpaul kspin_lock kq_lock; 324125551Swpaul uint8_t kq_busy; 325125551Swpaul}; 326125551Swpaul 327125551Swpaultypedef struct kdevice_queue kdevice_queue; 328125551Swpaul 329125551Swpaulstruct wait_ctx_block { 330125551Swpaul kdevice_qentry wcb_waitqueue; 331125551Swpaul void *wcb_devfunc; 332125551Swpaul void *wcb_devctx; 333125551Swpaul uint32_t wcb_mapregcnt; 334125551Swpaul void *wcb_devobj; 335125551Swpaul void *wcb_curirp; 336125551Swpaul void *wcb_bufchaindpc; 337125551Swpaul}; 338125551Swpaul 339125551Swpaultypedef struct wait_ctx_block wait_ctx_block; 340125551Swpaul 341125551Swpaulstruct wait_block { 342125551Swpaul list_entry wb_waitlist; 343125551Swpaul void *wb_kthread; 344125551Swpaul nt_dispatch_header *wb_object; 345125551Swpaul struct wait_block *wb_next; 346125551Swpaul uint16_t wb_waitkey; 347125551Swpaul uint16_t wb_waittype; 348125551Swpaul}; 349125551Swpaul 350125551Swpaultypedef struct wait_block wait_block; 351125551Swpaul 352125551Swpaul#define THREAD_WAIT_OBJECTS 3 353125551Swpaul#define MAX_WAIT_OBJECTS 64 354125551Swpaul 355125551Swpaul#define WAITTYPE_ALL 0 356125551Swpaul#define WAITTYPE_ANY 1 357125551Swpaul 358125551Swpaulstruct thread_context { 359125551Swpaul void *tc_thrctx; 360125551Swpaul void *tc_thrfunc; 361125551Swpaul}; 362125551Swpaul 363125551Swpaultypedef struct thread_context thread_context; 364125551Swpaul 365125551Swpaulstruct device_object { 366125551Swpaul uint16_t do_type; 367125551Swpaul uint16_t do_size; 368125551Swpaul uint32_t do_refcnt; 369125551Swpaul struct device_object *do_drvobj; 370125551Swpaul struct device_object *do_nextdev; 371125551Swpaul struct device_object *do_attacheddev; 372125551Swpaul struct irp *do_currirp; 373125551Swpaul void *do_iotimer; 374125551Swpaul uint32_t do_flags; 375125551Swpaul uint32_t do_characteristics; 376125551Swpaul void *do_vpb; 377125551Swpaul void *do_devext; 378125551Swpaul uint8_t do_stacksize; 379125551Swpaul union { 380125551Swpaul list_entry do_listent; 381125551Swpaul wait_ctx_block do_wcb; 382125551Swpaul } queue; 383125551Swpaul uint32_t do_alignreq; 384125551Swpaul kdevice_queue do_devqueue; 385125551Swpaul struct kdpc do_dpc; 386125551Swpaul uint32_t do_activethreads; 387125551Swpaul void *do_securitydesc; 388125551Swpaul struct nt_kevent do_devlock; 389125551Swpaul uint16_t do_sectorsz; 390125551Swpaul uint16_t do_spare1; 391125551Swpaul void *do_devobj_ext; 392125551Swpaul void *do_rsvd; 393125551Swpaul}; 394125551Swpaul 395125551Swpaultypedef struct device_object device_object; 396125551Swpaul 397125551Swpaulstruct irp { 398125551Swpaul uint32_t i_dummy; 399125551Swpaul}; 400125551Swpaul 401125551Swpaultypedef struct irp irp; 402125551Swpaul 403125551Swpaultypedef uint32_t (*driver_dispatch)(device_object *, irp *); 404125551Swpaul 405125551Swpaul#define DEVPROP_DEVICE_DESCRIPTION 0x00000000 406125551Swpaul#define DEVPROP_HARDWARE_ID 0x00000001 407125551Swpaul#define DEVPROP_COMPATIBLE_IDS 0x00000002 408125551Swpaul#define DEVPROP_BOOTCONF 0x00000003 409125551Swpaul#define DEVPROP_BOOTCONF_TRANSLATED 0x00000004 410125551Swpaul#define DEVPROP_CLASS_NAME 0x00000005 411125551Swpaul#define DEVPROP_CLASS_GUID 0x00000006 412125551Swpaul#define DEVPROP_DRIVER_KEYNAME 0x00000007 413125551Swpaul#define DEVPROP_MANUFACTURER 0x00000008 414125551Swpaul#define DEVPROP_FRIENDLYNAME 0x00000009 415125551Swpaul#define DEVPROP_LOCATION_INFO 0x0000000A 416125551Swpaul#define DEVPROP_PHYSDEV_NAME 0x0000000B 417125551Swpaul#define DEVPROP_BUSTYPE_GUID 0x0000000C 418125551Swpaul#define DEVPROP_LEGACY_BUSTYPE 0x0000000D 419125551Swpaul#define DEVPROP_BUS_NUMBER 0x0000000E 420125551Swpaul#define DEVPROP_ENUMERATOR_NAME 0x0000000F 421125551Swpaul#define DEVPROP_ADDRESS 0x00000010 422125551Swpaul#define DEVPROP_UINUMBER 0x00000011 423125551Swpaul#define DEVPROP_INSTALL_STATE 0x00000012 424125551Swpaul#define DEVPROP_REMOVAL_POLICY 0x00000013 425125551Swpaul 426125551Swpaul#define STATUS_SUCCESS 0x00000000 427125551Swpaul#define STATUS_USER_APC 0x000000C0 428125551Swpaul#define STATUS_KERNEL_APC 0x00000100 429125551Swpaul#define STATUS_ALERTED 0x00000101 430125551Swpaul#define STATUS_TIMEOUT 0x00000102 431125551Swpaul#define STATUS_INVALID_PARAMETER 0xC000000D 432125551Swpaul#define STATUS_INVALID_DEVICE_REQUEST 0xC0000010 433125551Swpaul#define STATUS_BUFFER_TOO_SMALL 0xC0000023 434125551Swpaul#define STATUS_MUTANT_NOT_OWNED 0xC0000046 435125551Swpaul#define STATUS_INVALID_PARAMETER_2 0xC00000F0 436125551Swpaul 437125551Swpaul#define STATUS_WAIT_0 0x00000000 438125551Swpaul 439123474Swpaulextern image_patch_table ntoskrnl_functbl[]; 440125551Swpaulextern struct mtx *ntoskrnl_dispatchlock; 441123474Swpaul 442123474Swpaul__BEGIN_DECLS 443123474Swpaulextern int ntoskrnl_libinit(void); 444123474Swpaulextern int ntoskrnl_libfini(void); 445125551Swpaulextern void ntoskrnl_wakeup(void *); 446123474Swpaul__END_DECLS 447123474Swpaul 448123474Swpaul#endif /* _NTOSKRNL_VAR_H_ */ 449