1246145Shselasky/* $FreeBSD$ */
2246145Shselasky/*-
3246145Shselasky * Copyright (c) 2011 Hans Petter Selasky. All rights reserved.
4246145Shselasky *
5246145Shselasky * Redistribution and use in source and binary forms, with or without
6246145Shselasky * modification, are permitted provided that the following conditions
7246145Shselasky * are met:
8246145Shselasky * 1. Redistributions of source code must retain the above copyright
9246145Shselasky *    notice, this list of conditions and the following disclaimer.
10246145Shselasky * 2. Redistributions in binary form must reproduce the above copyright
11246145Shselasky *    notice, this list of conditions and the following disclaimer in the
12246145Shselasky *    documentation and/or other materials provided with the distribution.
13246145Shselasky *
14246145Shselasky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15246145Shselasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16246145Shselasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17246145Shselasky * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18246145Shselasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19246145Shselasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20246145Shselasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21246145Shselasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22246145Shselasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23246145Shselasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24246145Shselasky * SUCH DAMAGE.
25246145Shselasky */
26246145Shselasky
27246145Shselasky#ifndef _BSD_KERNEL_H_
28246145Shselasky#define	_BSD_KERNEL_H_
29246145Shselasky
30246145Shselasky#define	_KERNEL
31246145Shselasky#define	__FreeBSD_version 1000000
32246145Shselasky
33246145Shselasky#include <sys/cdefs.h>
34246145Shselasky#include <sys/queue.h>
35246145Shselasky#include <sys/errno.h>
36246145Shselasky
37246145Shselasky#define	isalpha(x) (((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z'))
38246145Shselasky#define	isdigit(x) ((x) >= '0' && (x) <= '9')
39246145Shselasky#define	panic(...) do { printf("USB PANIC: " __VA_ARGS__); while (1) ; } while (0)
40269921Shselasky#define	rebooting 0
41246145Shselasky#define	M_USB 0
42246145Shselasky#define	M_USBDEV 0
43246145Shselasky#define	USB_PROC_MAX 3
44246363Shselasky#define	USB_BUS_GIANT_PROC(bus) (usb_process + 2)
45246363Shselasky#define	USB_BUS_NON_GIANT_PROC(bus) (usb_process + 2)
46246363Shselasky#define	USB_BUS_EXPLORE_PROC(bus) (usb_process + 0)
47246363Shselasky#define	USB_BUS_CONTROL_XFER_PROC(bus) (usb_process + 1)
48246145Shselasky#define	SYSCTL_DECL(...)
49246145Shselasky#define	SYSCTL_NODE(name,...) struct { } name __used
50246145Shselasky#define	SYSCTL_INT(...)
51246145Shselasky#define	TUNABLE_INT(...)
52246145Shselasky#define	MALLOC_DECLARE(...)
53246145Shselasky#define	MALLOC_DEFINE(...)
54246145Shselasky#define	EVENTHANDLER_DECLARE(...)
55246145Shselasky#define	EVENTHANDLER_INVOKE(...)
56246145Shselasky#define	KASSERT(...)
57246145Shselasky#define	SCHEDULER_STOPPED(x) (0)
58246145Shselasky#define	PI_SWI(...) (0)
59246145Shselasky#define	UNIQ_NAME(x) x
60246145Shselasky#define	UNIQ_NAME_STR(x) #x
61246145Shselasky#define	DEVCLASS_MAXUNIT 32
62246145Shselasky#define	MOD_LOAD 1
63246145Shselasky#define	MOD_UNLOAD 2
64246145Shselasky#define	DEVMETHOD(what,func) { #what, (void *)&func }
65246145Shselasky#define	DEVMETHOD_END {0,0}
66246145Shselasky#define	DRIVER_MODULE(name, busname, driver, devclass, evh, arg)	\
67246145Shselasky  static struct module_data bsd_##name##_##busname##_driver_mod = {	\
68246145Shselasky	evh, arg, #busname, #name, #busname "/" #name,			\
69246145Shselasky	&driver, &devclass, { 0, 0 } };					\
70246145ShselaskySYSINIT(bsd_##name##_##busname##_driver_mod, SI_SUB_DRIVERS,		\
71246145Shselasky  SI_ORDER_MIDDLE, module_register,					\
72246145Shselasky  &bsd_##name##_##busname##_driver_mod)
73246145Shselasky#define	SYSINIT(uniq, subs, order, _func, _data)	\
74246145Shselaskyconst struct sysinit UNIQ_NAME(sysinit_##uniq) = {	\
75246145Shselasky	.func = (_func),				\
76246145Shselasky	.data = __DECONST(void *, _data)		\
77246145Shselasky};							\
78246145ShselaskySYSINIT_ENTRY(uniq##_entry, "sysinit", (subs),		\
79246145Shselasky    (order), "const struct sysinit",			\
80246145Shselasky    UNIQ_NAME_STR(sysinit_##uniq), "SYSINIT")
81246145Shselasky
82246145Shselasky#define	SYSUNINIT(uniq, subs, order, _func, _data)	\
83246145Shselaskyconst struct sysinit UNIQ_NAME(sysuninit_##uniq) = {	\
84246145Shselasky	.func = (_func),				\
85246145Shselasky	.data = __DECONST(void *, _data)		\
86246145Shselasky};							\
87246145ShselaskySYSINIT_ENTRY(uniq##_entry, "sysuninit", (subs),	\
88246145Shselasky    (order), "const struct sysuninit",			\
89246145Shselasky    UNIQ_NAME_STR(sysuninit_##uniq), "SYSUNINIT")
90246145Shselasky#define	MODULE_DEPEND(...)
91246145Shselasky#define	MODULE_VERSION(...)
92246145Shselasky#define	NULL ((void *)0)
93246145Shselasky#define	BUS_SPACE_BARRIER_READ 0x01
94246145Shselasky#define	BUS_SPACE_BARRIER_WRITE 0x02
95246145Shselasky#define	hz 1000
96246145Shselasky#define	PAGE_SIZE 4096
97246145Shselasky#define	MIN(a,b) (((a) < (b)) ? (a) : (b))
98246145Shselasky#define	MAX(a,b) (((a) > (b)) ? (a) : (b))
99246145Shselasky#define	MTX_DEF 0
100269921Shselasky#define	MTX_SPIN 0
101246145Shselasky#define	MTX_RECURSE 0
102246145Shselasky#define	SX_DUPOK 0
103246145Shselasky#define	SX_NOWITNESS 0
104246145Shselasky#define	WITNESS_WARN(...)
105246145Shselasky#define	cold 0
106246145Shselasky#define	BUS_PROBE_GENERIC 0
107246145Shselasky#define	CALLOUT_RETURNUNLOCKED 0x1
108246145Shselasky#define	va_list __builtin_va_list
109246145Shselasky#define	va_size(type) __builtin_va_size(type)
110246145Shselasky#define	va_start(ap, last) __builtin_va_start(ap, last)
111246145Shselasky#define	va_end(ap) __builtin_va_end(ap)
112246145Shselasky#define	va_arg(ap, type) __builtin_va_arg((ap), type)
113246145Shselasky#define	DEVICE_ATTACH(dev, ...) \
114246145Shselasky  (((device_attach_t *)(device_get_method(dev, "device_attach")))(dev,## __VA_ARGS__))
115246145Shselasky#define	DEVICE_DETACH(dev, ...) \
116246145Shselasky  (((device_detach_t *)(device_get_method(dev, "device_detach")))(dev,## __VA_ARGS__))
117246145Shselasky#define	DEVICE_PROBE(dev, ...) \
118246145Shselasky  (((device_probe_t *)(device_get_method(dev, "device_probe")))(dev,## __VA_ARGS__))
119246145Shselasky#define	DEVICE_RESUME(dev, ...) \
120246145Shselasky  (((device_resume_t *)(device_get_method(dev, "device_resume")))(dev,## __VA_ARGS__))
121246145Shselasky#define	DEVICE_SHUTDOWN(dev, ...) \
122246145Shselasky  (((device_shutdown_t *)(device_get_method(dev, "device_shutdown")))(dev,## __VA_ARGS__))
123246145Shselasky#define	DEVICE_SUSPEND(dev, ...) \
124246145Shselasky  (((device_suspend_t *)(device_get_method(dev, "device_suspend")))(dev,## __VA_ARGS__))
125246145Shselasky#define	USB_HANDLE_REQUEST(dev, ...) \
126246145Shselasky  (((usb_handle_request_t *)(device_get_method(dev, "usb_handle_request")))(dev,## __VA_ARGS__))
127246145Shselasky#define	USB_TAKE_CONTROLLER(dev, ...) \
128246145Shselasky  (((usb_take_controller_t *)(device_get_method(dev, "usb_take_controller")))(dev,## __VA_ARGS__))
129246145Shselasky
130246145Shselaskyenum {
131246145Shselasky	SI_SUB_DUMMY = 0x0000000,
132246145Shselasky	SI_SUB_LOCK = 0x1B00000,
133246145Shselasky	SI_SUB_KLD = 0x2000000,
134246145Shselasky	SI_SUB_DRIVERS = 0x3100000,
135246145Shselasky	SI_SUB_PSEUDO = 0x7000000,
136246145Shselasky	SI_SUB_KICK_SCHEDULER = 0xa000000,
137246145Shselasky	SI_SUB_RUN_SCHEDULER = 0xfffffff
138246145Shselasky};
139246145Shselasky
140246145Shselaskyenum {
141246145Shselasky	SI_ORDER_FIRST = 0x0000000,
142246145Shselasky	SI_ORDER_SECOND = 0x0000001,
143246145Shselasky	SI_ORDER_THIRD = 0x0000002,
144246145Shselasky	SI_ORDER_FOURTH = 0x0000003,
145246145Shselasky	SI_ORDER_MIDDLE = 0x1000000,
146246145Shselasky	SI_ORDER_ANY = 0xfffffff	/* last */
147246145Shselasky};
148246145Shselasky
149246145Shselaskystruct uio;
150246145Shselaskystruct thread;
151246145Shselaskystruct malloc_type;
152246145Shselaskystruct usb_process;
153246145Shselasky
154246145Shselaskytypedef unsigned char uint8_t;
155246145Shselaskytypedef signed char int8_t;
156246145Shselasky
157246145Shselaskytypedef unsigned short uint16_t;
158246145Shselaskytypedef signed short int16_t;
159246145Shselasky
160246145Shselaskytypedef unsigned int uint32_t;
161246145Shselaskytypedef signed int int32_t;
162246145Shselasky
163246145Shselaskytypedef unsigned long long uint64_t;
164246145Shselaskytypedef signed long long int64_t;
165246145Shselasky
166246145Shselaskytypedef unsigned long bus_addr_t;
167246145Shselaskytypedef unsigned long bus_size_t;
168246145Shselasky
169246145Shselaskytypedef unsigned long size_t;
170246145Shselaskytypedef unsigned long u_long;
171246145Shselasky
172246145Shselaskytypedef void *bus_dmamap_t;
173246145Shselaskytypedef void *bus_dma_tag_t;
174246145Shselasky
175246145Shselaskytypedef void *bus_space_tag_t;
176246145Shselaskytypedef uint8_t *bus_space_handle_t;
177246145Shselasky
178246145Shselaskytypedef uint16_t uid_t;
179246145Shselaskytypedef uint16_t gid_t;
180246145Shselaskytypedef uint16_t mode_t;
181246145Shselasky
182246145Shselaskytypedef uint8_t *caddr_t;
183246145Shselaskytypedef unsigned long __uintptr_t;
184246145Shselaskytypedef unsigned long uintptr_t;
185246145Shselasky
186246145Shselasky/* SYSINIT API */
187246145Shselasky
188246145Shselasky#include <sysinit.h>
189246145Shselasky
190246145Shselaskystruct sysinit {
191246145Shselasky	void    (*func) (void *arg);
192246145Shselasky	void   *data;
193246145Shselasky};
194246145Shselasky
195246145Shselasky/* MUTEX API */
196246145Shselasky
197246145Shselaskystruct mtx {
198246145Shselasky	int	owned;
199246145Shselasky	struct mtx *parent;
200246145Shselasky};
201246145Shselasky
202246145Shselasky#define	mtx_assert(...) do { } while (0)
203246145Shselaskyvoid	mtx_init(struct mtx *, const char *, const char *, int);
204246145Shselaskyvoid	mtx_lock(struct mtx *);
205246145Shselaskyvoid	mtx_unlock(struct mtx *);
206269921Shselasky#define	mtx_lock_spin(x) mtx_lock(x)
207269921Shselasky#define	mtx_unlock_spin(x) mtx_unlock(x)
208246145Shselaskyint	mtx_owned(struct mtx *);
209246145Shselaskyvoid	mtx_destroy(struct mtx *);
210246145Shselasky
211246145Shselaskyextern struct mtx Giant;
212246145Shselasky
213246145Shselasky/* SX API */
214246145Shselasky
215246145Shselaskystruct sx {
216246145Shselasky	int	owned;
217246145Shselasky};
218246145Shselasky
219246145Shselasky#define	sx_assert(...) do { } while (0)
220246145Shselasky#define	sx_init(...) sx_init_flags(__VA_ARGS__, 0)
221246145Shselaskyvoid	sx_init_flags(struct sx *, const char *, int);
222246145Shselaskyvoid	sx_destroy(struct sx *);
223246145Shselaskyvoid	sx_xlock(struct sx *);
224246145Shselaskyvoid	sx_xunlock(struct sx *);
225246145Shselaskyint	sx_xlocked(struct sx *);
226246145Shselasky
227246145Shselasky/* CONDVAR API */
228246145Shselasky
229246145Shselaskystruct cv {
230246145Shselasky	int	sleeping;
231246145Shselasky};
232246145Shselasky
233246145Shselaskyvoid	cv_init(struct cv *, const char *desc);
234246145Shselaskyvoid	cv_destroy(struct cv *);
235246145Shselaskyvoid	cv_wait(struct cv *, struct mtx *);
236246145Shselaskyint	cv_timedwait(struct cv *, struct mtx *, int);
237246145Shselaskyvoid	cv_signal(struct cv *);
238246145Shselaskyvoid	cv_broadcast(struct cv *);
239246145Shselasky
240246145Shselasky/* CALLOUT API */
241246145Shselasky
242246145Shselaskytypedef void callout_fn_t (void *);
243246145Shselasky
244246145Shselaskyextern volatile int ticks;
245246145Shselasky
246246145Shselaskystruct callout {
247246145Shselasky	LIST_ENTRY(callout) entry;
248246145Shselasky	callout_fn_t *func;
249246145Shselasky	void   *arg;
250246145Shselasky	struct mtx *mtx;
251246145Shselasky	int	flags;
252246145Shselasky	int	timeout;
253246145Shselasky};
254246145Shselasky
255246145Shselaskyvoid	callout_init_mtx(struct callout *, struct mtx *, int);
256246145Shselaskyvoid	callout_reset(struct callout *, int, callout_fn_t *, void *);
257246145Shselaskyvoid	callout_stop(struct callout *);
258246145Shselaskyvoid	callout_drain(struct callout *);
259246145Shselaskyint	callout_pending(struct callout *);
260246145Shselaskyvoid	callout_process(int timeout);
261246145Shselasky
262246145Shselasky/* DEVICE API */
263246145Shselasky
264246145Shselaskystruct driver;
265246145Shselaskystruct devclass;
266246145Shselaskystruct device;
267246145Shselaskystruct module;
268246145Shselaskystruct module_data;
269246145Shselasky
270246145Shselaskytypedef struct driver driver_t;
271246145Shselaskytypedef struct devclass *devclass_t;
272246145Shselaskytypedef struct device *device_t;
273269921Shselaskytypedef void (driver_intr_t)(void *arg);
274269921Shselaskytypedef int (driver_filter_t)(void *arg);
275269921Shselasky#define	FILTER_STRAY		0x01
276269921Shselasky#define	FILTER_HANDLED		0x02
277269921Shselasky#define	FILTER_SCHEDULE_THREAD	0x04
278246145Shselasky
279246145Shselaskytypedef int device_attach_t (device_t dev);
280246145Shselaskytypedef int device_detach_t (device_t dev);
281246145Shselaskytypedef int device_resume_t (device_t dev);
282246145Shselaskytypedef int device_shutdown_t (device_t dev);
283246145Shselaskytypedef int device_probe_t (device_t dev);
284246145Shselaskytypedef int device_suspend_t (device_t dev);
285246145Shselasky
286246145Shselaskytypedef int bus_child_location_str_t (device_t parent, device_t child, char *buf, size_t buflen);
287246145Shselaskytypedef int bus_child_pnpinfo_str_t (device_t parent, device_t child, char *buf, size_t buflen);
288246145Shselaskytypedef void bus_driver_added_t (device_t dev, driver_t *driver);
289246145Shselasky
290246145Shselaskystruct device_method {
291246145Shselasky	const char *desc;
292246145Shselasky	void   *const func;
293246145Shselasky};
294246145Shselasky
295246145Shselaskytypedef struct device_method device_method_t;
296246145Shselasky
297246145Shselaskystruct device {
298246145Shselasky	TAILQ_HEAD(device_list, device) dev_children;
299246145Shselasky	TAILQ_ENTRY(device) dev_link;
300246145Shselasky
301246145Shselasky	struct device *dev_parent;
302246145Shselasky	const struct module_data *dev_module;
303246145Shselasky	void   *dev_sc;
304246145Shselasky	void   *dev_aux;
305269921Shselasky	driver_filter_t *dev_irq_filter;
306269921Shselasky	driver_intr_t *dev_irq_fn;
307246145Shselasky	void   *dev_irq_arg;
308246145Shselasky
309246145Shselasky	uint16_t dev_unit;
310246145Shselasky
311246145Shselasky	char	dev_nameunit[64];
312246145Shselasky	char	dev_desc[64];
313246145Shselasky
314246145Shselasky	uint8_t	dev_res_alloc:1;
315246145Shselasky	uint8_t	dev_quiet:1;
316246145Shselasky	uint8_t	dev_softc_set:1;
317246145Shselasky	uint8_t	dev_softc_alloc:1;
318246145Shselasky	uint8_t	dev_attached:1;
319246145Shselasky	uint8_t	dev_fixed_class:1;
320246145Shselasky	uint8_t	dev_unit_manual:1;
321246145Shselasky};
322246145Shselasky
323246145Shselaskystruct devclass {
324246145Shselasky	device_t dev_list[DEVCLASS_MAXUNIT];
325246145Shselasky};
326246145Shselasky
327246145Shselaskystruct driver {
328246145Shselasky	const char *name;
329246145Shselasky	const struct device_method *methods;
330246145Shselasky	uint32_t size;
331246145Shselasky};
332246145Shselasky
333246145Shselaskystruct module_data {
334246145Shselasky	int     (*callback) (struct module *, int, void *arg);
335246145Shselasky	void   *arg;
336246145Shselasky	const char *bus_name;
337246145Shselasky	const char *mod_name;
338246145Shselasky	const char *long_name;
339246145Shselasky	const struct driver *driver;
340246145Shselasky	struct devclass **devclass_pp;
341246145Shselasky	TAILQ_ENTRY(module_data) entry;
342246145Shselasky};
343246145Shselasky
344246145Shselaskydevice_t device_get_parent(device_t dev);
345246145Shselaskyvoid   *device_get_method(device_t dev, const char *what);
346246145Shselaskyconst char *device_get_name(device_t dev);
347246145Shselaskyconst char *device_get_nameunit(device_t dev);
348246145Shselasky
349246145Shselasky#define	device_printf(dev, fmt,...) \
350246145Shselasky	printf("%s: " fmt, device_get_nameunit(dev),## __VA_ARGS__)
351246145Shselaskydevice_t device_add_child(device_t dev, const char *name, int unit);
352246145Shselaskyvoid	device_quiet(device_t dev);
353269921Shselaskyvoid	device_set_interrupt(device_t dev, driver_filter_t *, driver_intr_t *, void *);
354246145Shselaskyvoid	device_run_interrupts(device_t parent);
355246145Shselaskyvoid	device_set_ivars(device_t dev, void *ivars);
356246145Shselaskyvoid   *device_get_ivars(device_t dev);
357246145Shselaskyconst char *device_get_desc(device_t dev);
358246145Shselaskyint	device_probe_and_attach(device_t dev);
359246145Shselaskyint	device_detach(device_t dev);
360246145Shselaskyvoid   *device_get_softc(device_t dev);
361246145Shselaskyvoid	device_set_softc(device_t dev, void *softc);
362246145Shselaskyint	device_delete_child(device_t dev, device_t child);
363246145Shselaskyint	device_delete_children(device_t dev);
364246145Shselaskyint	device_is_attached(device_t dev);
365246145Shselaskyvoid	device_set_desc(device_t dev, const char *desc);
366246145Shselaskyvoid	device_set_desc_copy(device_t dev, const char *desc);
367246145Shselaskyint	device_get_unit(device_t dev);
368246145Shselaskyvoid   *devclass_get_softc(devclass_t dc, int unit);
369246145Shselaskyint	devclass_get_maxunit(devclass_t dc);
370246145Shselaskydevice_t devclass_get_device(devclass_t dc, int unit);
371246145Shselaskydevclass_t devclass_find(const char *classname);
372246145Shselasky
373246145Shselasky#define	bus_get_dma_tag(...) (NULL)
374246145Shselaskyint	bus_generic_detach(device_t dev);
375246145Shselaskyint	bus_generic_resume(device_t dev);
376246145Shselaskyint	bus_generic_shutdown(device_t dev);
377246145Shselaskyint	bus_generic_suspend(device_t dev);
378246145Shselaskyint	bus_generic_print_child(device_t dev, device_t child);
379246145Shselaskyvoid	bus_generic_driver_added(device_t dev, driver_t *driver);
380246145Shselasky
381246145Shselasky/* BUS SPACE API */
382246145Shselasky
383246145Shselaskyvoid	bus_space_write_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint8_t data);
384246145Shselaskyvoid	bus_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint16_t data);
385246145Shselaskyvoid	bus_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint32_t data);
386246145Shselasky
387246145Shselaskyuint8_t	bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset);
388246145Shselaskyuint16_t bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset);
389246145Shselaskyuint32_t bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset);
390246145Shselasky
391246145Shselaskyvoid	bus_space_read_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint8_t *datap, bus_size_t count);
392246145Shselaskyvoid	bus_space_read_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint16_t *datap, bus_size_t count);
393246145Shselaskyvoid	bus_space_read_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint32_t *datap, bus_size_t count);
394246145Shselasky
395246145Shselaskyvoid	bus_space_write_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint8_t *datap, bus_size_t count);
396246145Shselaskyvoid	bus_space_write_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint16_t *datap, bus_size_t count);
397246145Shselaskyvoid	bus_space_write_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint32_t *datap, bus_size_t count);
398246145Shselasky
399246145Shselaskyvoid	bus_space_read_region_1(bus_space_tag_t space, bus_space_handle_t handle, bus_size_t offset, uint8_t *datap, bus_size_t count);
400246145Shselaskyvoid	bus_space_write_region_1(bus_space_tag_t space, bus_space_handle_t handle, bus_size_t offset, uint8_t *datap, bus_size_t count);
401246145Shselaskyvoid	bus_space_read_region_4(bus_space_tag_t space, bus_space_handle_t handle, bus_size_t offset, uint32_t *datap, bus_size_t count);
402246145Shselaskyvoid	bus_space_write_region_4(bus_space_tag_t space, bus_space_handle_t handle, bus_size_t offset, uint32_t *datap, bus_size_t count);
403246145Shselasky
404246145Shselaskyvoid	bus_space_barrier(bus_space_tag_t space, bus_space_handle_t handle, bus_size_t offset, bus_size_t length, int flags);
405246145Shselasky
406246145Shselaskyvoid	module_register(void *);
407246145Shselasky
408246145Shselasky/* LIB-C */
409246145Shselasky
410246145Shselaskyvoid   *memset(void *, int, size_t len);
411246145Shselaskyvoid   *memcpy(void *, const void *, size_t len);
412246145Shselaskyint	printf(const char *,...) __printflike(1, 2);
413246145Shselaskyint	snprintf(char *restrict str, size_t size, const char *restrict format,...) __printflike(3, 4);
414246145Shselaskysize_t	strlen(const char *s);
415246145Shselasky
416246145Shselasky/* MALLOC API */
417246145Shselasky
418246145Shselasky#define	malloc(s,x,f) usb_malloc(s)
419246145Shselaskyvoid   *usb_malloc(size_t);
420246145Shselasky
421246145Shselasky#define	free(p,x) usb_free(p)
422246145Shselaskyvoid	usb_free(void *);
423246145Shselasky
424246145Shselasky#define	strdup(p,x) usb_strdup(p)
425246145Shselaskychar   *usb_strdup(const char *str);
426246145Shselasky
427246145Shselasky/* ENDIANNESS */
428246145Shselasky
429246145Shselasky/* Assume little endian */
430246145Shselasky
431246145Shselasky#define	htole64(x) ((uint64_t)(x))
432246145Shselasky#define	le64toh(x) ((uint64_t)(x))
433246145Shselasky
434246145Shselasky#define	htole32(x) ((uint32_t)(x))
435246145Shselasky#define	le32toh(x) ((uint32_t)(x))
436246145Shselasky
437246145Shselasky#define	htole16(x) ((uint16_t)(x))
438246145Shselasky#define	le16toh(x) ((uint16_t)(x))
439246145Shselasky
440246145Shselasky#define	be32toh(x) ((uint32_t)(x))
441246145Shselasky#define	htobe32(x) ((uint32_t)(x))
442246145Shselasky
443246145Shselasky/* USB */
444246145Shselasky
445246145Shselaskytypedef int usb_handle_request_t (device_t dev, const void *req, void **pptr, uint16_t *plen, uint16_t offset, uint8_t *pstate);
446246145Shselaskytypedef int usb_take_controller_t (device_t dev);
447246145Shselasky
448246145Shselaskyvoid	usb_idle(void);
449246145Shselaskyvoid	usb_init(void);
450246145Shselaskyvoid	usb_uninit(void);
451246145Shselasky
452246145Shselasky/* set some defaults */
453246145Shselasky
454246145Shselasky#ifndef USB_POOL_SIZE
455246145Shselasky#define	USB_POOL_SIZE (1024*1024)	/* 1 MByte */
456246145Shselasky#endif
457246145Shselasky
458246145Shselaskyint	pause(const char *, int);
459246145Shselaskyvoid	DELAY(unsigned int);
460246145Shselasky
461246145Shselasky/* OTHER */
462246145Shselasky
463246145Shselaskystruct selinfo {
464246145Shselasky};
465246145Shselasky
466246145Shselasky/* SYSTEM STARTUP API */
467246145Shselasky
468246145Shselaskyextern const void *sysinit_data[];
469246145Shselaskyextern const void *sysuninit_data[];
470246145Shselasky
471246145Shselasky#endif					/* _BSD_KERNEL_H_ */
472