1362fcfcimp/*-
29da7bddpfg * SPDX-License-Identifier: BSD-4-Clause
39da7bddpfg *
47e1ac58wpaul * Copyright (c) 2003
57e1ac58wpaul *	Bill Paul <wpaul@windriver.com>.  All rights reserved.
67e1ac58wpaul *
77e1ac58wpaul * Redistribution and use in source and binary forms, with or without
87e1ac58wpaul * modification, are permitted provided that the following conditions
97e1ac58wpaul * are met:
107e1ac58wpaul * 1. Redistributions of source code must retain the above copyright
117e1ac58wpaul *    notice, this list of conditions and the following disclaimer.
127e1ac58wpaul * 2. Redistributions in binary form must reproduce the above copyright
137e1ac58wpaul *    notice, this list of conditions and the following disclaimer in the
147e1ac58wpaul *    documentation and/or other materials provided with the distribution.
157e1ac58wpaul * 3. All advertising materials mentioning features or use of this software
167e1ac58wpaul *    must display the following acknowledgement:
177e1ac58wpaul *	This product includes software developed by Bill Paul.
187e1ac58wpaul * 4. Neither the name of the author nor the names of any co-contributors
197e1ac58wpaul *    may be used to endorse or promote products derived from this software
207e1ac58wpaul *    without specific prior written permission.
217e1ac58wpaul *
227e1ac58wpaul * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
237e1ac58wpaul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
247e1ac58wpaul * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
257e1ac58wpaul * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
267e1ac58wpaul * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
277e1ac58wpaul * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
287e1ac58wpaul * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
297e1ac58wpaul * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
307e1ac58wpaul * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
317e1ac58wpaul * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
327e1ac58wpaul * THE POSSIBILITY OF SUCH DAMAGE.
337e1ac58wpaul */
347e1ac58wpaul
357e1ac58wpaul#include <sys/cdefs.h>
367e1ac58wpaul__FBSDID("$FreeBSD$");
377e1ac58wpaul
3853e0028wpaul#include <sys/ctype.h>
39fe7c8eewpaul#include <sys/unistd.h>
407e1ac58wpaul#include <sys/param.h>
417e1ac58wpaul#include <sys/types.h>
427e1ac58wpaul#include <sys/errno.h>
437e1ac58wpaul#include <sys/systm.h>
447e1ac58wpaul#include <sys/malloc.h>
457e1ac58wpaul#include <sys/lock.h>
467e1ac58wpaul#include <sys/mutex.h>
477e1ac58wpaul
487e1ac58wpaul#include <sys/callout.h>
497fd8e71marcel#include <sys/kdb.h>
507e1ac58wpaul#include <sys/kernel.h>
51fe7c8eewpaul#include <sys/proc.h>
52ef07dbewpaul#include <sys/condvar.h>
53fe7c8eewpaul#include <sys/kthread.h>
54df89b62wpaul#include <sys/module.h>
55e9bace5wpaul#include <sys/smp.h>
56e9bace5wpaul#include <sys/sched.h>
5781737ffwpaul#include <sys/sysctl.h>
587e1ac58wpaul
5967bfe86wpaul#include <machine/atomic.h>
607e1ac58wpaul#include <machine/bus.h>
617e1ac58wpaul#include <machine/stdarg.h>
62ef07dbewpaul#include <machine/resource.h>
637e1ac58wpaul
647e1ac58wpaul#include <sys/bus.h>
657e1ac58wpaul#include <sys/rman.h>
667e1ac58wpaul
67361515awpaul#include <vm/vm.h>
68361515awpaul#include <vm/vm_param.h>
69361515awpaul#include <vm/pmap.h>
7015a925bwpaul#include <vm/uma.h>
71e9bace5wpaul#include <vm/vm_kern.h>
72e9bace5wpaul#include <vm/vm_map.h>
7387fbb48bschmidt#include <vm/vm_extern.h>
74361515awpaul
757e1ac58wpaul#include <compat/ndis/pe_var.h>
76b493dd5wpaul#include <compat/ndis/cfg_var.h>
77b493dd5wpaul#include <compat/ndis/resource_var.h>
78b9b3cafwpaul#include <compat/ndis/ntoskrnl_var.h>
79dfae368wpaul#include <compat/ndis/hal_var.h>
80fe7c8eewpaul#include <compat/ndis/ndis_var.h>
817e1ac58wpaul
8281737ffwpaul#ifdef NTOSKRNL_DEBUG_TIMERS
8381737ffwpaulstatic int sysctl_show_timers(SYSCTL_HANDLER_ARGS);
8481737ffwpaul
85ad355b0kaktusSYSCTL_PROC(_debug, OID_AUTO, ntoskrnl_timers,
86ad355b0kaktus    CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, NULL, 0,
87ad355b0kaktus    sysctl_show_timers, "I",
88caeebe8mdf    "Show ntoskrnl timer stats");
8981737ffwpaul#endif
9081737ffwpaul
91e9bace5wpaulstruct kdpc_queue {
92ef07dbewpaul	list_entry		kq_disp;
93e9bace5wpaul	struct thread		*kq_td;
94e9bace5wpaul	int			kq_cpu;
95e9bace5wpaul	int			kq_exit;
9681737ffwpaul	int			kq_running;
9781737ffwpaul	kspin_lock		kq_lock;
98e9bace5wpaul	nt_kevent		kq_proc;
99e9bace5wpaul	nt_kevent		kq_done;
100e9bace5wpaul};
101e9bace5wpaul
102e9bace5wpaultypedef struct kdpc_queue kdpc_queue;
103e9bace5wpaul
104ef07dbewpaulstruct wb_ext {
105ef07dbewpaul	struct cv		we_cv;
106ef07dbewpaul	struct thread		*we_td;
107ef07dbewpaul};
108ef07dbewpaul
109ef07dbewpaultypedef struct wb_ext wb_ext;
110ef07dbewpaul
111ef07dbewpaul#define NTOSKRNL_TIMEOUTS	256
11281737ffwpaul#ifdef NTOSKRNL_DEBUG_TIMERS
11381737ffwpaulstatic uint64_t ntoskrnl_timer_fires;
11481737ffwpaulstatic uint64_t ntoskrnl_timer_sets;
11581737ffwpaulstatic uint64_t ntoskrnl_timer_reloads;
11681737ffwpaulstatic uint64_t ntoskrnl_timer_cancels;
11781737ffwpaul#endif
11881737ffwpaul
11981737ffwpaulstruct callout_entry {
12081737ffwpaul	struct callout		ce_callout;
12181737ffwpaul	list_entry		ce_list;
12281737ffwpaul};
12381737ffwpaul
12481737ffwpaultypedef struct callout_entry callout_entry;
12581737ffwpaul
12681737ffwpaulstatic struct list_entry ntoskrnl_calllist;
12781737ffwpaulstatic struct mtx ntoskrnl_calllock;
12882896fcbschmidtstruct kuser_shared_data kuser_shared_data;
12981737ffwpaul
13081737ffwpaulstatic struct list_entry ntoskrnl_intlist;
13181737ffwpaulstatic kspin_lock ntoskrnl_intlock;
132ef07dbewpaul
133ef07dbe