bsd_kernel.h revision 266882
1246145Shselasky/* $FreeBSD: head/sys/boot/usb/bsd_kernel.h 266882 2014-05-30 13:39:58Z hselasky $ */
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
31266882Shselasky#undef __FreeBSD_version
32266882Shselasky#define	__FreeBSD_version 1100000
33246145Shselasky
34246145Shselasky#include <sys/cdefs.h>
35246145Shselasky#include <sys/queue.h>
36246145Shselasky#include <sys/errno.h>
37246145Shselasky
38246145Shselasky#define	isalpha(x) (((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z'))
39246145Shselasky#define	isdigit(x) ((x) >= '0' && (x) <= '9')
40246145Shselasky#define	panic(...) do { printf("USB PANIC: " __VA_ARGS__); while (1) ; } while (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
96266882Shselasky#undef PAGE_SIZE
97246145Shselasky#define	PAGE_SIZE 4096
98266882Shselasky#undef MIN
99246145Shselasky#define	MIN(a,b) (((a) < (b)) ? (a) : (b))
100266882Shselasky#undef MAX
101246145Shselasky#define	MAX(a,b) (((a) > (b)) ? (a) : (b))
102246145Shselasky#define	MTX_DEF 0
103266396Shselasky#define	MTX_SPIN 0
104246145Shselasky#define	MTX_RECURSE 0
105246145Shselasky#define	SX_DUPOK 0
106246145Shselasky#define	SX_NOWITNESS 0
107246145Shselasky#define	WITNESS_WARN(...)
108246145Shselasky#define	cold 0
109246145Shselasky#define	BUS_PROBE_GENERIC 0
110246145Shselasky#define	CALLOUT_RETURNUNLOCKED 0x1
111266882Shselasky#undef va_list
112246145Shselasky#define	va_list __builtin_va_list
113266882Shselasky#undef va_size
114246145Shselasky#define	va_size(type) __builtin_va_size(type)
115266882Shselasky#undef va_start
116246145Shselasky#define	va_start(ap, last) __builtin_va_start(ap, last)
117266882Shselasky#undef va_end
118246145Shselasky#define	va_end(ap) __builtin_va_end(ap)
119266882Shselasky#undef va_arg
120246145Shselasky#define	va_arg(ap, type) __builtin_va_arg((ap), type)
121246145Shselasky#define	DEVICE_ATTACH(dev, ...) \
122246145Shselasky  (((device_attach_t *)(device_get_method(dev, "device_attach")))(dev,## __VA_ARGS__))
123246145Shselasky#define	DEVICE_DETACH(dev, ...) \
124246145Shselasky  (((device_detach_t *)(device_get_method(dev, "device_detach")))(dev,## __VA_ARGS__))
125246145Shselasky#define	DEVICE_PROBE(dev, ...) \
126246145Shselasky  (((device_probe_t *)(device_get_method(dev, "device_probe")))(dev,## __VA_ARGS__))
127246145Shselasky#define	DEVICE_RESUME(dev, ...) \
128246145Shselasky  (((device_resume_t *)(device_get_method(dev, "device_resume")))(dev,## __VA_ARGS__))
129246145Shselasky#define	DEVICE_SHUTDOWN(dev, ...) \
130246145Shselasky  (((device_shutdown_t *)(device_get_method(dev, "device_shutdown")))(dev,## __VA_ARGS__))
131246145Shselasky#define	DEVICE_SUSPEND(dev, ...) \
132246145Shselasky  (((device_suspend_t *)(device_get_method(dev, "device_suspend")))(dev,## __VA_ARGS__))
133246145Shselasky#define	USB_HANDLE_REQUEST(dev, ...) \
134246145Shselasky  (((usb_handle_request_t *)(device_get_method(dev, "usb_handle_request")))(dev,## __VA_ARGS__))
135246145Shselasky#define	USB_TAKE_CONTROLLER(dev, ...) \
136246145Shselasky  (((usb_take_controller_t *)(device_get_method(dev, "usb_take_controller")))(dev,## __VA_ARGS__))
137246145Shselasky
138246145Shselaskyenum {
139246145Shselasky	SI_SUB_DUMMY = 0x0000000,
140246145Shselasky	SI_SUB_LOCK = 0x1B00000,
141246145Shselasky	SI_SUB_KLD = 0x2000000,
142246145Shselasky	SI_SUB_DRIVERS = 0x3100000,
143246145Shselasky	SI_SUB_PSEUDO = 0x7000000,
144246145Shselasky	SI_SUB_KICK_SCHEDULER = 0xa000000,
145246145Shselasky	SI_SUB_RUN_SCHEDULER = 0xfffffff
146246145Shselasky};
147246145Shselasky
148246145Shselaskyenum {
149246145Shselasky	SI_ORDER_FIRST = 0x0000000,
150246145Shselasky	SI_ORDER_SECOND = 0x0000001,
151246145Shselasky	SI_ORDER_THIRD = 0x0000002,
152246145Shselasky	SI_ORDER_FOURTH = 0x0000003,
153246145Shselasky	SI_ORDER_MIDDLE = 0x1000000,
154246145Shselasky	SI_ORDER_ANY = 0xfffffff	/* last */
155246145Shselasky};
156246145Shselasky
157246145Shselaskystruct uio;
158246145Shselaskystruct thread;
159246145Shselaskystruct malloc_type;
160246145Shselaskystruct usb_process;
161246145Shselasky
162266882Shselasky#ifndef HAVE_STANDARD_DEFS
163266882Shselasky#define	_UINT8_T_DECLARED
164246145Shselaskytypedef unsigned char uint8_t;
165266882Shselasky#define	_INT8_T_DECLARED
166246145Shselaskytypedef signed char int8_t;
167266882Shselasky#define	_UINT16_T_DECLARED
168246145Shselaskytypedef unsigned short uint16_t;
169266882Shselasky#define	_INT16_T_DECLARED
170246145Shselaskytypedef signed short int16_t;
171266882Shselasky#define	_UINT32_T_DECLARED
172246145Shselaskytypedef unsigned int uint32_t;
173266882Shselasky#define	_INT32_T_DECLARED
174246145Shselaskytypedef signed int int32_t;
175266882Shselasky#define	_UINT64_T_DECLARED
176246145Shselaskytypedef unsigned long long uint64_t;
177266882Shselasky#define	_INT16_T_DECLARED
178246145Shselaskytypedef signed long long int64_t;
179246145Shselasky
180266882Shselaskytypedef uint16_t uid_t;
181266882Shselaskytypedef uint16_t gid_t;
182266882Shselaskytypedef uint16_t mode_t;
183246145Shselasky
184266882Shselaskytypedef uint8_t *caddr_t;
185266882Shselaskytypedef unsigned long __uintptr_t;
186266882Shselaskytypedef unsigned long uintptr_t;
187266882Shselasky
188246145Shselaskytypedef unsigned long size_t;
189246145Shselaskytypedef unsigned long u_long;
190266882Shselasky#endif
191246145Shselasky
192266882Shselaskytypedef unsigned long bus_addr_t;
193266882Shselaskytypedef unsigned long bus_size_t;
194266882Shselasky
195246145Shselaskytypedef void *bus_dmamap_t;
196246145Shselaskytypedef void *bus_dma_tag_t;
197246145Shselasky
198246145Shselaskytypedef void *bus_space_tag_t;
199246145Shselaskytypedef uint8_t *bus_space_handle_t;
200246145Shselasky
201246145Shselasky/* SYSINIT API */
202246145Shselasky
203246145Shselasky#include <sysinit.h>
204246145Shselasky
205246145Shselaskystruct sysinit {
206246145Shselasky	void    (*func) (void *arg);
207246145Shselasky	void   *data;
208246145Shselasky};
209246145Shselasky
210246145Shselasky/* MUTEX API */
211246145Shselasky
212246145Shselaskystruct mtx {
213246145Shselasky	int	owned;
214246145Shselasky	struct mtx *parent;
215246145Shselasky};
216246145Shselasky
217246145Shselasky#define	mtx_assert(...) do { } while (0)
218246145Shselaskyvoid	mtx_init(struct mtx *, const char *, const char *, int);
219246145Shselaskyvoid	mtx_lock(struct mtx *);
220246145Shselaskyvoid	mtx_unlock(struct mtx *);
221266396Shselasky#define	mtx_lock_spin(x) mtx_lock(x)
222266396Shselasky#define	mtx_unlock_spin(x) mtx_unlock(x)
223246145Shselaskyint	mtx_owned(struct mtx *);
224246145Shselaskyvoid	mtx_destroy(struct mtx *);
225246145Shselasky
226246145Shselaskyextern struct mtx Giant;
227246145Shselasky
228246145Shselasky/* SX API */
229246145Shselasky
230246145Shselaskystruct sx {
231246145Shselasky	int	owned;
232246145Shselasky};
233246145Shselasky
234246145Shselasky#define	sx_assert(...) do { } while (0)
235246145Shselasky#define	sx_init(...) sx_init_flags(__VA_ARGS__, 0)
236246145Shselaskyvoid	sx_init_flags(struct sx *, const char *, int);
237246145Shselaskyvoid	sx_destroy(struct sx *);
238246145Shselaskyvoid	sx_xlock(struct sx *);
239246145Shselaskyvoid	sx_xunlock(struct sx *);
240246145Shselaskyint	sx_xlocked(struct sx *);
241246145Shselasky
242246145Shselasky/* CONDVAR API */
243246145Shselasky
244246145Shselaskystruct cv {
245246145Shselasky	int	sleeping;
246246145Shselasky};
247246145Shselasky
248246145Shselaskyvoid	cv_init(struct cv *, const char *desc);
249246145Shselaskyvoid	cv_destroy(struct cv *);
250246145Shselaskyvoid	cv_wait(struct cv *, struct mtx *);
251246145Shselaskyint	cv_timedwait(struct cv *, struct mtx *, int);
252246145Shselaskyvoid	cv_signal(struct cv *);
253246145Shselaskyvoid	cv_broadcast(struct cv *);
254246145Shselasky
255246145Shselasky/* CALLOUT API */
256246145Shselasky
257246145Shselaskytypedef void callout_fn_t (void *);
258246145Shselasky
259246145Shselaskyextern volatile int ticks;
260246145Shselasky
261246145Shselaskystruct callout {
262246145Shselasky	LIST_ENTRY(callout) entry;
263246145Shselasky	callout_fn_t *func;
264246145Shselasky	void   *arg;
265246145Shselasky	struct mtx *mtx;
266246145Shselasky	int	flags;
267246145Shselasky	int	timeout;
268246145Shselasky};
269246145Shselasky
270246145Shselaskyvoid	callout_init_mtx(struct callout *, struct mtx *, int);
271246145Shselaskyvoid	callout_reset(struct callout *, int, callout_fn_t *, void *);
272246145Shselaskyvoid	callout_stop(struct callout *);
273246145Shselaskyvoid	callout_drain(struct callout *);
274246145Shselaskyint	callout_pending(struct callout *);
275246145Shselaskyvoid	callout_process(int timeout);
276246145Shselasky
277246145Shselasky/* DEVICE API */
278246145Shselasky
279246145Shselaskystruct driver;
280246145Shselaskystruct devclass;
281246145Shselaskystruct device;
282246145Shselaskystruct module;
283246145Shselaskystruct module_data;
284246145Shselasky
285246145Shselaskytypedef struct driver driver_t;
286246145Shselaskytypedef struct devclass *devclass_t;
287246145Shselaskytypedef struct device *device_t;
288266396Shselaskytypedef void (driver_intr_t)(void *arg);
289266396Shselaskytypedef int (driver_filter_t)(void *arg);
290266396Shselasky#define	FILTER_STRAY		0x01
291266396Shselasky#define	FILTER_HANDLED		0x02
292266396Shselasky#define	FILTER_SCHEDULE_THREAD	0x04
293246145Shselasky
294246145Shselaskytypedef int device_attach_t (device_t dev);
295246145Shselaskytypedef int device_detach_t (device_t dev);
296246145Shselaskytypedef int device_resume_t (device_t dev);
297246145Shselaskytypedef int device_shutdown_t (device_t dev);
298246145Shselaskytypedef int device_probe_t (device_t dev);
299246145Shselaskytypedef int device_suspend_t (device_t dev);
300246145Shselasky
301246145Shselaskytypedef int bus_child_location_str_t (device_t parent, device_t child, char *buf, size_t buflen);
302246145Shselaskytypedef int bus_child_pnpinfo_str_t (device_t parent, device_t child, char *buf, size_t buflen);
303246145Shselaskytypedef void bus_driver_added_t (device_t dev, driver_t *driver);
304246145Shselasky
305246145Shselaskystruct device_method {
306246145Shselasky	const char *desc;
307246145Shselasky	void   *const func;
308246145Shselasky};
309246145Shselasky
310246145Shselaskytypedef struct device_method device_method_t;
311246145Shselasky
312246145Shselaskystruct device {
313246145Shselasky	TAILQ_HEAD(device_list, device) dev_children;
314246145Shselasky	TAILQ_ENTRY(device) dev_link;
315246145Shselasky
316246145Shselasky	struct device *dev_parent;
317246145Shselasky	const struct module_data *dev_module;
318246145Shselasky	void   *dev_sc;
319246145Shselasky	void   *dev_aux;
320266396Shselasky	driver_filter_t *dev_irq_filter;
321266396Shselasky	driver_intr_t *dev_irq_fn;
322246145Shselasky	void   *dev_irq_arg;
323246145Shselasky
324246145Shselasky	uint16_t dev_unit;
325246145Shselasky
326246145Shselasky	char	dev_nameunit[64];
327246145Shselasky	char	dev_desc[64];
328246145Shselasky
329246145Shselasky	uint8_t	dev_res_alloc:1;
330246145Shselasky	uint8_t	dev_quiet:1;
331246145Shselasky	uint8_t	dev_softc_set:1;
332246145Shselasky	uint8_t	dev_softc_alloc:1;
333246145Shselasky	uint8_t	dev_attached:1;
334246145Shselasky	uint8_t	dev_fixed_class:1;
335246145Shselasky	uint8_t	dev_unit_manual:1;
336246145Shselasky};
337246145Shselasky
338246145Shselaskystruct devclass {
339246145Shselasky	device_t dev_list[DEVCLASS_MAXUNIT];
340246145Shselasky};
341246145Shselasky
342246145Shselaskystruct driver {
343246145Shselasky	const char *name;
344246145Shselasky	const struct device_method *methods;
345246145Shselasky	uint32_t size;
346246145Shselasky};
347246145Shselasky
348246145Shselaskystruct module_data {
349246145Shselasky	int     (*callback) (struct module *, int, void *arg);
350246145Shselasky	void   *arg;
351246145Shselasky	const char *bus_name;
352246145Shselasky	const char *mod_name;
353246145Shselasky	const char *long_name;
354246145Shselasky	const struct driver *driver;
355246145Shselasky	struct devclass **devclass_pp;
356246145Shselasky	TAILQ_ENTRY(module_data) entry;
357246145Shselasky};
358246145Shselasky
359246145Shselaskydevice_t device_get_parent(device_t dev);
360246145Shselaskyvoid   *device_get_method(device_t dev, const char *what);
361246145Shselaskyconst char *device_get_name(device_t dev);
362246145Shselaskyconst char *device_get_nameunit(device_t dev);
363246145Shselasky
364246145Shselasky#define	device_printf(dev, fmt,...) \
365246145Shselasky	printf("%s: " fmt, device_get_nameunit(dev),## __VA_ARGS__)
366246145Shselaskydevice_t device_add_child(device_t dev, const char *name, int unit);
367246145Shselaskyvoid	device_quiet(device_t dev);
368266396Shselaskyvoid	device_set_interrupt(device_t dev, driver_filter_t *, driver_intr_t *, void *);
369246145Shselaskyvoid	device_run_interrupts(device_t parent);
370246145Shselaskyvoid	device_set_ivars(device_t dev, void *ivars);
371246145Shselaskyvoid   *device_get_ivars(device_t dev);
372246145Shselaskyconst char *device_get_desc(device_t dev);
373246145Shselaskyint	device_probe_and_attach(device_t dev);
374246145Shselaskyint	device_detach(device_t dev);
375246145Shselaskyvoid   *device_get_softc(device_t dev);
376246145Shselaskyvoid	device_set_softc(device_t dev, void *softc);
377246145Shselaskyint	device_delete_child(device_t dev, device_t child);
378246145Shselaskyint	device_delete_children(device_t dev);
379246145Shselaskyint	device_is_attached(device_t dev);
380246145Shselaskyvoid	device_set_desc(device_t dev, const char *desc);
381246145Shselaskyvoid	device_set_desc_copy(device_t dev, const char *desc);
382246145Shselaskyint	device_get_unit(device_t dev);
383246145Shselaskyvoid   *devclass_get_softc(devclass_t dc, int unit);
384246145Shselaskyint	devclass_get_maxunit(devclass_t dc);
385246145Shselaskydevice_t devclass_get_device(devclass_t dc, int unit);
386246145Shselaskydevclass_t devclass_find(const char *classname);
387246145Shselasky
388246145Shselasky#define	bus_get_dma_tag(...) (NULL)
389246145Shselaskyint	bus_generic_detach(device_t dev);
390246145Shselaskyint	bus_generic_resume(device_t dev);
391246145Shselaskyint	bus_generic_shutdown(device_t dev);
392246145Shselaskyint	bus_generic_suspend(device_t dev);
393246145Shselaskyint	bus_generic_print_child(device_t dev, device_t child);
394246145Shselaskyvoid	bus_generic_driver_added(device_t dev, driver_t *driver);
395246145Shselasky
396246145Shselasky/* BUS SPACE API */
397246145Shselasky
398246145Shselaskyvoid	bus_space_write_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint8_t data);
399246145Shselaskyvoid	bus_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint16_t data);
400246145Shselaskyvoid	bus_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint32_t data);
401246145Shselasky
402246145Shselaskyuint8_t	bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset);
403246145Shselaskyuint16_t bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset);
404246145Shselaskyuint32_t bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset);
405246145Shselasky
406246145Shselaskyvoid	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);
407246145Shselaskyvoid	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);
408246145Shselaskyvoid	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);
409246145Shselasky
410246145Shselaskyvoid	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);
411246145Shselaskyvoid	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);
412246145Shselaskyvoid	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);
413246145Shselasky
414246145Shselaskyvoid	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);
415246145Shselaskyvoid	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);
416246145Shselaskyvoid	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);
417246145Shselaskyvoid	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);
418246145Shselasky
419246145Shselaskyvoid	bus_space_barrier(bus_space_tag_t space, bus_space_handle_t handle, bus_size_t offset, bus_size_t length, int flags);
420246145Shselasky
421246145Shselaskyvoid	module_register(void *);
422246145Shselasky
423246145Shselasky/* LIB-C */
424246145Shselasky
425246145Shselaskyvoid   *memset(void *, int, size_t len);
426246145Shselaskyvoid   *memcpy(void *, const void *, size_t len);
427246145Shselaskyint	printf(const char *,...) __printflike(1, 2);
428246145Shselaskyint	snprintf(char *restrict str, size_t size, const char *restrict format,...) __printflike(3, 4);
429246145Shselaskysize_t	strlen(const char *s);
430246145Shselasky
431246145Shselasky/* MALLOC API */
432246145Shselasky
433266882Shselasky#ifndef HAVE_MALLOC
434266882Shselasky#undef malloc
435246145Shselasky#define	malloc(s,x,f) usb_malloc(s)
436246145Shselaskyvoid   *usb_malloc(size_t);
437246145Shselasky
438266882Shselasky#undef free
439246145Shselasky#define	free(p,x) usb_free(p)
440246145Shselaskyvoid	usb_free(void *);
441266882Shselasky#else
442266882Shselasky#undef malloc
443266882Shselaskyvoid *malloc(size_t);
444266882Shselasky#define	malloc(s,x,f) malloc(s)
445246145Shselasky
446266882Shselasky#undef free
447266882Shselaskyvoid free(void *);
448266882Shselasky#define	free(p,x) free(p)
449266882Shselasky#endif
450266882Shselasky
451246145Shselasky#define	strdup(p,x) usb_strdup(p)
452246145Shselaskychar   *usb_strdup(const char *str);
453246145Shselasky
454246145Shselasky/* ENDIANNESS */
455246145Shselasky
456266882Shselasky#ifndef HAVE_ENDIAN_DEFS
457266882Shselasky
458246145Shselasky/* Assume little endian */
459246145Shselasky
460246145Shselasky#define	htole64(x) ((uint64_t)(x))
461246145Shselasky#define	le64toh(x) ((uint64_t)(x))
462246145Shselasky
463246145Shselasky#define	htole32(x) ((uint32_t)(x))
464246145Shselasky#define	le32toh(x) ((uint32_t)(x))
465246145Shselasky
466246145Shselasky#define	htole16(x) ((uint16_t)(x))
467246145Shselasky#define	le16toh(x) ((uint16_t)(x))
468246145Shselasky
469246145Shselasky#define	be32toh(x) ((uint32_t)(x))
470246145Shselasky#define	htobe32(x) ((uint32_t)(x))
471246145Shselasky
472266882Shselasky#else
473266882Shselasky#include <sys/endian.h>
474266882Shselasky#endif
475266882Shselasky
476246145Shselasky/* USB */
477246145Shselasky
478246145Shselaskytypedef int usb_handle_request_t (device_t dev, const void *req, void **pptr, uint16_t *plen, uint16_t offset, uint8_t *pstate);
479246145Shselaskytypedef int usb_take_controller_t (device_t dev);
480246145Shselasky
481246145Shselaskyvoid	usb_idle(void);
482246145Shselaskyvoid	usb_init(void);
483246145Shselaskyvoid	usb_uninit(void);
484246145Shselasky
485246145Shselasky/* set some defaults */
486246145Shselasky
487246145Shselasky#ifndef USB_POOL_SIZE
488246145Shselasky#define	USB_POOL_SIZE (1024*1024)	/* 1 MByte */
489246145Shselasky#endif
490246145Shselasky
491246145Shselaskyint	pause(const char *, int);
492246145Shselaskyvoid	DELAY(unsigned int);
493246145Shselasky
494246145Shselasky/* OTHER */
495246145Shselasky
496246145Shselaskystruct selinfo {
497246145Shselasky};
498246145Shselasky
499246145Shselasky/* SYSTEM STARTUP API */
500246145Shselasky
501246145Shselaskyextern const void *sysinit_data[];
502246145Shselaskyextern const void *sysuninit_data[];
503246145Shselasky
504246145Shselasky#endif					/* _BSD_KERNEL_H_ */
505