bsd_kernel.h revision 287274
19908Swollman/* $FreeBSD: stable/10/sys/boot/usb/bsd_kernel.h 287274 2015-08-29 06:23:40Z hselasky $ */
22742Swollman/*-
32742Swollman * Copyright (c) 2011 Hans Petter Selasky. All rights reserved.
42742Swollman *
52742Swollman * Redistribution and use in source and binary forms, with or without
62742Swollman * modification, are permitted provided that the following conditions
72742Swollman * are met:
82742Swollman * 1. Redistributions of source code must retain the above copyright
92742Swollman *    notice, this list of conditions and the following disclaimer.
102742Swollman * 2. Redistributions in binary form must reproduce the above copyright
112742Swollman *    notice, this list of conditions and the following disclaimer in the
122742Swollman *    documentation and/or other materials provided with the distribution.
132742Swollman *
142742Swollman * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
152742Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
162742Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
172742Swollman * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
182742Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
192742Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
202742Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
212742Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
222742Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
232742Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
242742Swollman * SUCH DAMAGE.
252742Swollman */
262742Swollman
272742Swollman#ifndef _BSD_KERNEL_H_
282742Swollman#define	_BSD_KERNEL_H_
292742Swollman
302742Swollman#define	_KERNEL
312742Swollman#define	__FreeBSD_version 1000000
322742Swollman
332742Swollman#include <sys/cdefs.h>
342742Swollman#include <sys/queue.h>
352742Swollman#include <sys/errno.h>
362742Swollman
372742Swollman#define	isalpha(x) (((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z'))
382742Swollman#define	isdigit(x) ((x) >= '0' && (x) <= '9')
392742Swollman#define	panic(...) do { printf("USB PANIC: " __VA_ARGS__); while (1) ; } while (0)
402742Swollman#define	rebooting 0
412742Swollman#define	M_USB 0
422742Swollman#define	M_USBDEV 0
432742Swollman#define	USB_PROC_MAX 3
442742Swollman#define	USB_BUS_GIANT_PROC(bus) (usb_process + 2)
452742Swollman#define	USB_BUS_NON_GIANT_BULK_PROC(bus) (usb_process + 2)
462742Swollman#define	USB_BUS_NON_GIANT_ISOC_PROC(bus) (usb_process + 2)
472742Swollman#define	USB_BUS_EXPLORE_PROC(bus) (usb_process + 0)
482742Swollman#define	USB_BUS_CONTROL_XFER_PROC(bus) (usb_process + 1)
492742Swollman#define	SYSCTL_DECL(...)
502742Swollman#define	SYSCTL_NODE(name,...) struct { } name __used
512742Swollman#define	SYSCTL_INT(...)
522742Swollman#define	TUNABLE_INT(...)
532742Swollman#define	MALLOC_DECLARE(...)
542742Swollman#define	MALLOC_DEFINE(...)
552742Swollman#define	EVENTHANDLER_DECLARE(...)
569908Swollman#define	EVENTHANDLER_INVOKE(...)
579908Swollman#define	KASSERT(...)
589908Swollman#define	SCHEDULER_STOPPED(x) (0)
599908Swollman#define	PI_SWI(...) (0)
609908Swollman#define	UNIQ_NAME(x) x
619908Swollman#define	UNIQ_NAME_STR(x) #x
629908Swollman#define	DEVCLASS_MAXUNIT 32
639908Swollman#define	MOD_LOAD 1
649908Swollman#define	MOD_UNLOAD 2
659908Swollman#define	DEVMETHOD(what,func) { #what, (void *)&func }
669908Swollman#define	DEVMETHOD_END {0,0}
679908Swollman#define	DRIVER_MODULE(name, busname, driver, devclass, evh, arg)	\
689908Swollman  static struct module_data bsd_##name##_##busname##_driver_mod = {	\
699908Swollman	evh, arg, #busname, #name, #busname "/" #name,			\
709908Swollman	&driver, &devclass, { 0, 0 } };					\
719908SwollmanSYSINIT(bsd_##name##_##busname##_driver_mod, SI_SUB_DRIVERS,		\
729908Swollman  SI_ORDER_MIDDLE, module_register,					\
739908Swollman  &bsd_##name##_##busname##_driver_mod)
749908Swollman#define	SYSINIT(uniq, subs, order, _func, _data)	\
759908Swollmanconst struct sysinit UNIQ_NAME(sysinit_##uniq) = {	\
769908Swollman	.func = (_func),				\
779908Swollman	.data = __DECONST(void *, _data)		\
782742Swollman};							\
792742SwollmanSYSINIT_ENTRY(uniq##_entry, "sysinit", (subs),		\
802742Swollman    (order), "const struct sysinit",			\
812742Swollman    UNIQ_NAME_STR(sysinit_##uniq), "SYSINIT")
822742Swollman
832742Swollman#define	SYSUNINIT(uniq, subs, order, _func, _data)	\
842742Swollmanconst struct sysinit UNIQ_NAME(sysuninit_##uniq) = {	\
852742Swollman	.func = (_func),				\
862742Swollman	.data = __DECONST(void *, _data)		\
872742Swollman};							\
882742SwollmanSYSINIT_ENTRY(uniq##_entry, "sysuninit", (subs),	\
892742Swollman    (order), "const struct sysuninit",			\
902742Swollman    UNIQ_NAME_STR(sysuninit_##uniq), "SYSUNINIT")
912742Swollman#define	MODULE_DEPEND(...)
922742Swollman#define	MODULE_VERSION(...)
932742Swollman#define	NULL ((void *)0)
942742Swollman#define	BUS_SPACE_BARRIER_READ 0x01
952742Swollman#define	BUS_SPACE_BARRIER_WRITE 0x02
962742Swollman#define	hz 1000
972742Swollman#define	PAGE_SIZE 4096
982742Swollman#define	MIN(a,b) (((a) < (b)) ? (a) : (b))
992742Swollman#define	MAX(a,b) (((a) > (b)) ? (a) : (b))
1002742Swollman#define	MTX_DEF 0
1012742Swollman#define	MTX_SPIN 0
1022742Swollman#define	MTX_RECURSE 0
1032742Swollman#define	SX_DUPOK 0
1042742Swollman#define	SX_NOWITNESS 0
1052742Swollman#define	WITNESS_WARN(...)
1062742Swollman#define	cold 0
1072742Swollman#define	BUS_PROBE_GENERIC 0
1082742Swollman#define	CALLOUT_RETURNUNLOCKED 0x1
1092742Swollman#define	va_list __builtin_va_list
1102742Swollman#define	va_size(type) __builtin_va_size(type)
1112742Swollman#define	va_start(ap, last) __builtin_va_start(ap, last)
1122742Swollman#define	va_end(ap) __builtin_va_end(ap)
1132742Swollman#define	va_arg(ap, type) __builtin_va_arg((ap), type)
1142742Swollman#define	DEVICE_ATTACH(dev, ...) \
1152742Swollman  (((device_attach_t *)(device_get_method(dev, "device_attach")))(dev,## __VA_ARGS__))
1162742Swollman#define	DEVICE_DETACH(dev, ...) \
1172742Swollman  (((device_detach_t *)(device_get_method(dev, "device_detach")))(dev,## __VA_ARGS__))
1182742Swollman#define	DEVICE_PROBE(dev, ...) \
1192742Swollman  (((device_probe_t *)(device_get_method(dev, "device_probe")))(dev,## __VA_ARGS__))
1202742Swollman#define	DEVICE_RESUME(dev, ...) \
1212742Swollman  (((device_resume_t *)(device_get_method(dev, "device_resume")))(dev,## __VA_ARGS__))
1222742Swollman#define	DEVICE_SHUTDOWN(dev, ...) \
1232742Swollman  (((device_shutdown_t *)(device_get_method(dev, "device_shutdown")))(dev,## __VA_ARGS__))
1242742Swollman#define	DEVICE_SUSPEND(dev, ...) \
1252742Swollman  (((device_suspend_t *)(device_get_method(dev, "device_suspend")))(dev,## __VA_ARGS__))
1262742Swollman#define	USB_HANDLE_REQUEST(dev, ...) \
1272742Swollman  (((usb_handle_request_t *)(device_get_method(dev, "usb_handle_request")))(dev,## __VA_ARGS__))
1282742Swollman#define	USB_TAKE_CONTROLLER(dev, ...) \
1292742Swollman  (((usb_take_controller_t *)(device_get_method(dev, "usb_take_controller")))(dev,## __VA_ARGS__))
1302742Swollman
1312742Swollmanenum {
1322742Swollman	SI_SUB_DUMMY = 0x0000000,
1332742Swollman	SI_SUB_LOCK = 0x1B00000,
1342742Swollman	SI_SUB_KLD = 0x2000000,
1352742Swollman	SI_SUB_DRIVERS = 0x3100000,
1362742Swollman	SI_SUB_PSEUDO = 0x7000000,
1372742Swollman	SI_SUB_KICK_SCHEDULER = 0xa000000,
1382742Swollman	SI_SUB_RUN_SCHEDULER = 0xfffffff
1392742Swollman};
1402742Swollman
1412742Swollmanenum {
1422742Swollman	SI_ORDER_FIRST = 0x0000000,
1432742Swollman	SI_ORDER_SECOND = 0x0000001,
1442742Swollman	SI_ORDER_THIRD = 0x0000002,
1452742Swollman	SI_ORDER_FOURTH = 0x0000003,
1462742Swollman	SI_ORDER_MIDDLE = 0x1000000,
1472742Swollman	SI_ORDER_ANY = 0xfffffff	/* last */
1482742Swollman};
1492742Swollman
1502742Swollmanstruct uio;
1512742Swollmanstruct thread;
1522742Swollmanstruct malloc_type;
1532742Swollmanstruct usb_process;
1542742Swollman
1552742Swollmantypedef unsigned char uint8_t;
1562742Swollmantypedef signed char int8_t;
1572742Swollman
1582742Swollmantypedef unsigned short uint16_t;
1592742Swollmantypedef signed short int16_t;
1602742Swollman
1612742Swollmantypedef unsigned int uint32_t;
1622742Swollmantypedef signed int int32_t;
1632742Swollman
1642742Swollmantypedef unsigned long long uint64_t;
1652742Swollmantypedef signed long long int64_t;
1662742Swollman
1672742Swollmantypedef unsigned long bus_addr_t;
1682742Swollmantypedef unsigned long bus_size_t;
1692742Swollman
1702742Swollmantypedef unsigned long size_t;
1712742Swollmantypedef unsigned long u_long;
1722742Swollman
1732742Swollmantypedef void *bus_dmamap_t;
1742742Swollmantypedef void *bus_dma_tag_t;
1752742Swollman
1762742Swollmantypedef void *bus_space_tag_t;
1772742Swollmantypedef uint8_t *bus_space_handle_t;
1782742Swollman
1792742Swollmantypedef uint16_t uid_t;
1802742Swollmantypedef uint16_t gid_t;
1812742Swollmantypedef uint16_t mode_t;
1822742Swollman
1832742Swollmantypedef uint8_t *caddr_t;
1842742Swollmantypedef unsigned long __uintptr_t;
1852742Swollmantypedef unsigned long uintptr_t;
1862742Swollman
1872742Swollman/* SYSINIT API */
1882742Swollman
1892742Swollman#include <sysinit.h>
1902742Swollman
1912742Swollmanstruct sysinit {
1922742Swollman	void    (*func) (void *arg);
1932742Swollman	void   *data;
1942742Swollman};
1952742Swollman
1962742Swollman/* MUTEX API */
1972742Swollman
1982742Swollmanstruct mtx {
1992742Swollman	int	owned;
2002742Swollman	struct mtx *parent;
2012742Swollman};
2022742Swollman
2032742Swollman#define	mtx_assert(...) do { } while (0)
2042742Swollmanvoid	mtx_init(struct mtx *, const char *, const char *, int);
2052742Swollmanvoid	mtx_lock(struct mtx *);
2062742Swollmanvoid	mtx_unlock(struct mtx *);
2072742Swollman#define	mtx_lock_spin(x) mtx_lock(x)
2082742Swollman#define	mtx_unlock_spin(x) mtx_unlock(x)
2092742Swollmanint	mtx_owned(struct mtx *);
2102742Swollmanvoid	mtx_destroy(struct mtx *);
2112742Swollman
2122742Swollmanextern struct mtx Giant;
2132742Swollman
2142742Swollman/* SX API */
2152742Swollman
2162742Swollmanstruct sx {
2172742Swollman	int	owned;
2182742Swollman};
2192742Swollman
2202742Swollman#define	sx_assert(...) do { } while (0)
2212742Swollman#define	sx_init(...) sx_init_flags(__VA_ARGS__, 0)
2222742Swollmanvoid	sx_init_flags(struct sx *, const char *, int);
2232742Swollmanvoid	sx_destroy(struct sx *);
2242742Swollmanvoid	sx_xlock(struct sx *);
2252742Swollmanvoid	sx_xunlock(struct sx *);
2262742Swollmanint	sx_xlocked(struct sx *);
2272742Swollman
2282742Swollman/* CONDVAR API */
2292742Swollman
2302742Swollmanstruct cv {
2312742Swollman	int	sleeping;
2322742Swollman};
2332742Swollman
2342742Swollmanvoid	cv_init(struct cv *, const char *desc);
2352742Swollmanvoid	cv_destroy(struct cv *);
2362742Swollmanvoid	cv_wait(struct cv *, struct mtx *);
2372742Swollmanint	cv_timedwait(struct cv *, struct mtx *, int);
2382742Swollmanvoid	cv_signal(struct cv *);
2392742Swollmanvoid	cv_broadcast(struct cv *);
2402742Swollman
2412742Swollman/* CALLOUT API */
2422742Swollman
2432742Swollmantypedef void callout_fn_t (void *);
2442742Swollman
2452742Swollmanextern volatile int ticks;
2462742Swollman
2472742Swollmanstruct callout {
2482742Swollman	LIST_ENTRY(callout) entry;
2492742Swollman	callout_fn_t *func;
2502742Swollman	void   *arg;
2512742Swollman	struct mtx *mtx;
2522742Swollman	int	flags;
2532742Swollman	int	timeout;
2542742Swollman};
2552742Swollman
2562742Swollmanvoid	callout_init_mtx(struct callout *, struct mtx *, int);
2572742Swollmanvoid	callout_reset(struct callout *, int, callout_fn_t *, void *);
2582742Swollmanvoid	callout_stop(struct callout *);
2592742Swollmanvoid	callout_drain(struct callout *);
2602742Swollmanint	callout_pending(struct callout *);
2612742Swollmanvoid	callout_process(int timeout);
2622742Swollman
2632742Swollman/* DEVICE API */
2642742Swollman
2652742Swollmanstruct driver;
2662742Swollmanstruct devclass;
2672742Swollmanstruct device;
2682742Swollmanstruct module;
2692742Swollmanstruct module_data;
2702742Swollman
2712742Swollmantypedef struct driver driver_t;
2722742Swollmantypedef struct devclass *devclass_t;
2732742Swollmantypedef struct device *device_t;
2742742Swollmantypedef void (driver_intr_t)(void *arg);
2752742Swollmantypedef int (driver_filter_t)(void *arg);
2762742Swollman#define	FILTER_STRAY		0x01
2772742Swollman#define	FILTER_HANDLED		0x02
2782742Swollman#define	FILTER_SCHEDULE_THREAD	0x04
2792742Swollman
2802742Swollmantypedef int device_attach_t (device_t dev);
2812742Swollmantypedef int device_detach_t (device_t dev);
2822742Swollmantypedef int device_resume_t (device_t dev);
2832742Swollmantypedef int device_shutdown_t (device_t dev);
2842742Swollmantypedef int device_probe_t (device_t dev);
2852742Swollmantypedef int device_suspend_t (device_t dev);
2862742Swollman
2872742Swollmantypedef int bus_child_location_str_t (device_t parent, device_t child, char *buf, size_t buflen);
2882742Swollmantypedef int bus_child_pnpinfo_str_t (device_t parent, device_t child, char *buf, size_t buflen);
2892742Swollmantypedef void bus_driver_added_t (device_t dev, driver_t *driver);
2902742Swollman
2912742Swollmanstruct device_method {
2922742Swollman	const char *desc;
2932742Swollman	void   *const func;
2942742Swollman};
2952742Swollman
2962742Swollmantypedef struct device_method device_method_t;
2972742Swollman
2982742Swollmanstruct device {
2992742Swollman	TAILQ_HEAD(device_list, device) dev_children;
3002742Swollman	TAILQ_ENTRY(device) dev_link;
3012742Swollman
3022742Swollman	struct device *dev_parent;
3032742Swollman	const struct module_data *dev_module;
3042742Swollman	void   *dev_sc;
3052742Swollman	void   *dev_aux;
3062742Swollman	driver_filter_t *dev_irq_filter;
3072742Swollman	driver_intr_t *dev_irq_fn;
3082742Swollman	void   *dev_irq_arg;
3092742Swollman
3102742Swollman	uint16_t dev_unit;
3112742Swollman
3122742Swollman	char	dev_nameunit[64];
3132742Swollman	char	dev_desc[64];
3142742Swollman
3152742Swollman	uint8_t	dev_res_alloc:1;
3162742Swollman	uint8_t	dev_quiet:1;
3172742Swollman	uint8_t	dev_softc_set:1;
3182742Swollman	uint8_t	dev_softc_alloc:1;
3192742Swollman	uint8_t	dev_attached:1;
3202742Swollman	uint8_t	dev_fixed_class:1;
3212742Swollman	uint8_t	dev_unit_manual:1;
3222742Swollman};
3232742Swollman
3242742Swollmanstruct devclass {
3252742Swollman	device_t dev_list[DEVCLASS_MAXUNIT];
3262742Swollman};
3272742Swollman
3282742Swollmanstruct driver {
3292742Swollman	const char *name;
3302742Swollman	const struct device_method *methods;
3312742Swollman	uint32_t size;
3322742Swollman};
3332742Swollman
3342742Swollmanstruct module_data {
3352742Swollman	int     (*callback) (struct module *, int, void *arg);
3362742Swollman	void   *arg;
3372742Swollman	const char *bus_name;
3382742Swollman	const char *mod_name;
3392742Swollman	const char *long_name;
3402742Swollman	const struct driver *driver;
3412742Swollman	struct devclass **devclass_pp;
3422742Swollman	TAILQ_ENTRY(module_data) entry;
3432742Swollman};
3442742Swollman
3452742Swollmandevice_t device_get_parent(device_t dev);
3462742Swollmanvoid   *device_get_method(device_t dev, const char *what);
3472742Swollmanconst char *device_get_name(device_t dev);
3482742Swollmanconst char *device_get_nameunit(device_t dev);
3492742Swollman
3502742Swollman#define	device_printf(dev, fmt,...) \
3512742Swollman	printf("%s: " fmt, device_get_nameunit(dev),## __VA_ARGS__)
3522742Swollmandevice_t device_add_child(device_t dev, const char *name, int unit);
3532742Swollmanvoid	device_quiet(device_t dev);
3542742Swollmanvoid	device_set_interrupt(device_t dev, driver_filter_t *, driver_intr_t *, void *);
3552742Swollmanvoid	device_run_interrupts(device_t parent);
3562742Swollmanvoid	device_set_ivars(device_t dev, void *ivars);
3572742Swollmanvoid   *device_get_ivars(device_t dev);
3582742Swollmanconst char *device_get_desc(device_t dev);
3592742Swollmanint	device_probe_and_attach(device_t dev);
3602742Swollmanint	device_detach(device_t dev);
3612742Swollmanvoid   *device_get_softc(device_t dev);
3622742Swollmanvoid	device_set_softc(device_t dev, void *softc);
3632742Swollmanint	device_delete_child(device_t dev, device_t child);
3642742Swollmanint	device_delete_children(device_t dev);
3652742Swollmanint	device_is_attached(device_t dev);
3662742Swollmanvoid	device_set_desc(device_t dev, const char *desc);
3672742Swollmanvoid	device_set_desc_copy(device_t dev, const char *desc);
3682742Swollmanint	device_get_unit(device_t dev);
3692742Swollmanvoid   *devclass_get_softc(devclass_t dc, int unit);
3702742Swollmanint	devclass_get_maxunit(devclass_t dc);
3712742Swollmandevice_t devclass_get_device(devclass_t dc, int unit);
3722742Swollmandevclass_t devclass_find(const char *classname);
3732742Swollman
3742742Swollman#define	bus_get_dma_tag(...) (NULL)
3752742Swollmanint	bus_generic_detach(device_t dev);
3762742Swollmanint	bus_generic_resume(device_t dev);
3772742Swollmanint	bus_generic_shutdown(device_t dev);
3782742Swollmanint	bus_generic_suspend(device_t dev);
3792742Swollmanint	bus_generic_print_child(device_t dev, device_t child);
3802742Swollmanvoid	bus_generic_driver_added(device_t dev, driver_t *driver);
3812742Swollman
3822742Swollman/* BUS SPACE API */
3832742Swollman
3842742Swollmanvoid	bus_space_write_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint8_t data);
3852742Swollmanvoid	bus_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint16_t data);
3862742Swollmanvoid	bus_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint32_t data);
3872742Swollman
3882742Swollmanuint8_t	bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset);
3892742Swollmanuint16_t bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset);
3902742Swollmanuint32_t bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset);
3912742Swollman
3922742Swollmanvoid	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);
3932742Swollmanvoid	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);
3942742Swollmanvoid	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);
3952742Swollman
3962742Swollmanvoid	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);
3972742Swollmanvoid	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);
3982742Swollmanvoid	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);
3992742Swollman
4009908Swollmanvoid	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);
4012742Swollmanvoid	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);
4022742Swollmanvoid	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);
4032742Swollmanvoid	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);
4042742Swollman
4052742Swollmanvoid	bus_space_barrier(bus_space_tag_t space, bus_space_handle_t handle, bus_size_t offset, bus_size_t length, int flags);
4062742Swollman
4072742Swollmanvoid	module_register(void *);
4082742Swollman
4092742Swollman/* LIB-C */
4102742Swollman
4112742Swollmanvoid   *memset(void *, int, size_t len);
4122742Swollmanvoid   *memcpy(void *, const void *, size_t len);
4132742Swollmanint	printf(const char *,...) __printflike(1, 2);
4142742Swollmanint	snprintf(char *restrict str, size_t size, const char *restrict format,...) __printflike(3, 4);
4152742Swollmansize_t	strlen(const char *s);
4162742Swollman
4172742Swollman/* MALLOC API */
4182742Swollman
4192742Swollman#define	malloc(s,x,f) usb_malloc(s)
4202742Swollmanvoid   *usb_malloc(size_t);
4212742Swollman
4222742Swollman#define	free(p,x) usb_free(p)
4232742Swollmanvoid	usb_free(void *);
4242742Swollman
4252742Swollman#define	strdup(p,x) usb_strdup(p)
4262742Swollmanchar   *usb_strdup(const char *str);
4272742Swollman
4282742Swollman/* ENDIANNESS */
4292742Swollman
4302742Swollman/* Assume little endian */
4312742Swollman
4322742Swollman#define	htole64(x) ((uint64_t)(x))
4332742Swollman#define	le64toh(x) ((uint64_t)(x))
4342742Swollman
4352742Swollman#define	htole32(x) ((uint32_t)(x))
4362742Swollman#define	le32toh(x) ((uint32_t)(x))
4372742Swollman
4382742Swollman#define	htole16(x) ((uint16_t)(x))
4392742Swollman#define	le16toh(x) ((uint16_t)(x))
4402742Swollman
4412742Swollman#define	be32toh(x) ((uint32_t)(x))
4422742Swollman#define	htobe32(x) ((uint32_t)(x))
4432742Swollman
4442742Swollman/* USB */
4452742Swollman
4462742Swollmantypedef int usb_handle_request_t (device_t dev, const void *req, void **pptr, uint16_t *plen, uint16_t offset, uint8_t *pstate);
4472742Swollmantypedef int usb_take_controller_t (device_t dev);
4482742Swollman
4499908Swollmanvoid	usb_idle(void);
4502742Swollmanvoid	usb_init(void);
4512742Swollmanvoid	usb_uninit(void);
4522742Swollman
4532742Swollman/* set some defaults */
4542742Swollman
4552742Swollman#ifndef USB_POOL_SIZE
4562742Swollman#define	USB_POOL_SIZE (1024*1024)	/* 1 MByte */
4572742Swollman#endif
4582742Swollman
4592742Swollmanint	pause(const char *, int);
4602742Swollmanvoid	DELAY(unsigned int);
4612742Swollman
4622742Swollman/* OTHER */
4632742Swollman
4642742Swollmanstruct selinfo {
4652742Swollman};
4662742Swollman
4672742Swollman/* SYSTEM STARTUP API */
4682742Swollman
4692742Swollmanextern const void *sysinit_data[];
4702742Swollmanextern const void *sysuninit_data[];
4712742Swollman
4722742Swollman#endif					/* _BSD_KERNEL_H_ */
4732742Swollman