bsd_kernel.h revision 246363
1246145Shselasky/* $FreeBSD: head/sys/boot/usb/bsd_kernel.h 246363 2013-02-05 14:44:25Z 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 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) 40246145Shselasky#define M_USB 0 41246145Shselasky#define M_USBDEV 0 42246145Shselasky#define USB_PROC_MAX 3 43246363Shselasky#define USB_BUS_GIANT_PROC(bus) (usb_process + 2) 44246363Shselasky#define USB_BUS_NON_GIANT_PROC(bus) (usb_process + 2) 45246363Shselasky#define USB_BUS_EXPLORE_PROC(bus) (usb_process + 0) 46246363Shselasky#define USB_BUS_CONTROL_XFER_PROC(bus) (usb_process + 1) 47246145Shselasky#define SYSCTL_DECL(...) 48246145Shselasky#define SYSCTL_NODE(name,...) struct { } name __used 49246145Shselasky#define SYSCTL_INT(...) 50246145Shselasky#define TUNABLE_INT(...) 51246145Shselasky#define MALLOC_DECLARE(...) 52246145Shselasky#define MALLOC_DEFINE(...) 53246145Shselasky#define EVENTHANDLER_DECLARE(...) 54246145Shselasky#define EVENTHANDLER_INVOKE(...) 55246145Shselasky#define KASSERT(...) 56246145Shselasky#define SCHEDULER_STOPPED(x) (0) 57246145Shselasky#define PI_SWI(...) (0) 58246145Shselasky#define UNIQ_NAME(x) x 59246145Shselasky#define UNIQ_NAME_STR(x) #x 60246145Shselasky#define DEVCLASS_MAXUNIT 32 61246145Shselasky#define MOD_LOAD 1 62246145Shselasky#define MOD_UNLOAD 2 63246145Shselasky#define DEVMETHOD(what,func) { #what, (void *)&func } 64246145Shselasky#define DEVMETHOD_END {0,0} 65246145Shselasky#define DRIVER_MODULE(name, busname, driver, devclass, evh, arg) \ 66246145Shselasky static struct module_data bsd_##name##_##busname##_driver_mod = { \ 67246145Shselasky evh, arg, #busname, #name, #busname "/" #name, \ 68246145Shselasky &driver, &devclass, { 0, 0 } }; \ 69246145ShselaskySYSINIT(bsd_##name##_##busname##_driver_mod, SI_SUB_DRIVERS, \ 70246145Shselasky SI_ORDER_MIDDLE, module_register, \ 71246145Shselasky &bsd_##name##_##busname##_driver_mod) 72246145Shselasky#define SYSINIT(uniq, subs, order, _func, _data) \ 73246145Shselaskyconst struct sysinit UNIQ_NAME(sysinit_##uniq) = { \ 74246145Shselasky .func = (_func), \ 75246145Shselasky .data = __DECONST(void *, _data) \ 76246145Shselasky}; \ 77246145ShselaskySYSINIT_ENTRY(uniq##_entry, "sysinit", (subs), \ 78246145Shselasky (order), "const struct sysinit", \ 79246145Shselasky UNIQ_NAME_STR(sysinit_##uniq), "SYSINIT") 80246145Shselasky 81246145Shselasky#define SYSUNINIT(uniq, subs, order, _func, _data) \ 82246145Shselaskyconst struct sysinit UNIQ_NAME(sysuninit_##uniq) = { \ 83246145Shselasky .func = (_func), \ 84246145Shselasky .data = __DECONST(void *, _data) \ 85246145Shselasky}; \ 86246145ShselaskySYSINIT_ENTRY(uniq##_entry, "sysuninit", (subs), \ 87246145Shselasky (order), "const struct sysuninit", \ 88246145Shselasky UNIQ_NAME_STR(sysuninit_##uniq), "SYSUNINIT") 89246145Shselasky#define MODULE_DEPEND(...) 90246145Shselasky#define MODULE_VERSION(...) 91246145Shselasky#define NULL ((void *)0) 92246145Shselasky#define BUS_SPACE_BARRIER_READ 0x01 93246145Shselasky#define BUS_SPACE_BARRIER_WRITE 0x02 94246145Shselasky#define hz 1000 95246145Shselasky#define PAGE_SIZE 4096 96246145Shselasky#define MIN(a,b) (((a) < (b)) ? (a) : (b)) 97246145Shselasky#define MAX(a,b) (((a) > (b)) ? (a) : (b)) 98246145Shselasky#define MTX_DEF 0 99246145Shselasky#define MTX_RECURSE 0 100246145Shselasky#define SX_DUPOK 0 101246145Shselasky#define SX_NOWITNESS 0 102246145Shselasky#define WITNESS_WARN(...) 103246145Shselasky#define cold 0 104246145Shselasky#define BUS_PROBE_GENERIC 0 105246145Shselasky#define CALLOUT_RETURNUNLOCKED 0x1 106246145Shselasky#define va_list __builtin_va_list 107246145Shselasky#define va_size(type) __builtin_va_size(type) 108246145Shselasky#define va_start(ap, last) __builtin_va_start(ap, last) 109246145Shselasky#define va_end(ap) __builtin_va_end(ap) 110246145Shselasky#define va_arg(ap, type) __builtin_va_arg((ap), type) 111246145Shselasky#define DEVICE_ATTACH(dev, ...) \ 112246145Shselasky (((device_attach_t *)(device_get_method(dev, "device_attach")))(dev,## __VA_ARGS__)) 113246145Shselasky#define DEVICE_DETACH(dev, ...) \ 114246145Shselasky (((device_detach_t *)(device_get_method(dev, "device_detach")))(dev,## __VA_ARGS__)) 115246145Shselasky#define DEVICE_PROBE(dev, ...) \ 116246145Shselasky (((device_probe_t *)(device_get_method(dev, "device_probe")))(dev,## __VA_ARGS__)) 117246145Shselasky#define DEVICE_RESUME(dev, ...) \ 118246145Shselasky (((device_resume_t *)(device_get_method(dev, "device_resume")))(dev,## __VA_ARGS__)) 119246145Shselasky#define DEVICE_SHUTDOWN(dev, ...) \ 120246145Shselasky (((device_shutdown_t *)(device_get_method(dev, "device_shutdown")))(dev,## __VA_ARGS__)) 121246145Shselasky#define DEVICE_SUSPEND(dev, ...) \ 122246145Shselasky (((device_suspend_t *)(device_get_method(dev, "device_suspend")))(dev,## __VA_ARGS__)) 123246145Shselasky#define USB_HANDLE_REQUEST(dev, ...) \ 124246145Shselasky (((usb_handle_request_t *)(device_get_method(dev, "usb_handle_request")))(dev,## __VA_ARGS__)) 125246145Shselasky#define USB_TAKE_CONTROLLER(dev, ...) \ 126246145Shselasky (((usb_take_controller_t *)(device_get_method(dev, "usb_take_controller")))(dev,## __VA_ARGS__)) 127246145Shselasky 128246145Shselaskyenum { 129246145Shselasky SI_SUB_DUMMY = 0x0000000, 130246145Shselasky SI_SUB_LOCK = 0x1B00000, 131246145Shselasky SI_SUB_KLD = 0x2000000, 132246145Shselasky SI_SUB_DRIVERS = 0x3100000, 133246145Shselasky SI_SUB_PSEUDO = 0x7000000, 134246145Shselasky SI_SUB_KICK_SCHEDULER = 0xa000000, 135246145Shselasky SI_SUB_RUN_SCHEDULER = 0xfffffff 136246145Shselasky}; 137246145Shselasky 138246145Shselaskyenum { 139246145Shselasky SI_ORDER_FIRST = 0x0000000, 140246145Shselasky SI_ORDER_SECOND = 0x0000001, 141246145Shselasky SI_ORDER_THIRD = 0x0000002, 142246145Shselasky SI_ORDER_FOURTH = 0x0000003, 143246145Shselasky SI_ORDER_MIDDLE = 0x1000000, 144246145Shselasky SI_ORDER_ANY = 0xfffffff /* last */ 145246145Shselasky}; 146246145Shselasky 147246145Shselaskystruct uio; 148246145Shselaskystruct thread; 149246145Shselaskystruct malloc_type; 150246145Shselaskystruct usb_process; 151246145Shselasky 152246145Shselaskytypedef unsigned char uint8_t; 153246145Shselaskytypedef signed char int8_t; 154246145Shselasky 155246145Shselaskytypedef unsigned short uint16_t; 156246145Shselaskytypedef signed short int16_t; 157246145Shselasky 158246145Shselaskytypedef unsigned int uint32_t; 159246145Shselaskytypedef signed int int32_t; 160246145Shselasky 161246145Shselaskytypedef unsigned long long uint64_t; 162246145Shselaskytypedef signed long long int64_t; 163246145Shselasky 164246145Shselaskytypedef unsigned long bus_addr_t; 165246145Shselaskytypedef unsigned long bus_size_t; 166246145Shselasky 167246145Shselaskytypedef unsigned long size_t; 168246145Shselaskytypedef unsigned long u_long; 169246145Shselasky 170246145Shselaskytypedef void *bus_dmamap_t; 171246145Shselaskytypedef void *bus_dma_tag_t; 172246145Shselasky 173246145Shselaskytypedef void *bus_space_tag_t; 174246145Shselaskytypedef uint8_t *bus_space_handle_t; 175246145Shselasky 176246145Shselaskytypedef uint16_t uid_t; 177246145Shselaskytypedef uint16_t gid_t; 178246145Shselaskytypedef uint16_t mode_t; 179246145Shselasky 180246145Shselaskytypedef uint8_t *caddr_t; 181246145Shselaskytypedef unsigned long __uintptr_t; 182246145Shselaskytypedef unsigned long uintptr_t; 183246145Shselasky 184246145Shselasky/* SYSINIT API */ 185246145Shselasky 186246145Shselasky#include <sysinit.h> 187246145Shselasky 188246145Shselaskystruct sysinit { 189246145Shselasky void (*func) (void *arg); 190246145Shselasky void *data; 191246145Shselasky}; 192246145Shselasky 193246145Shselasky/* MUTEX API */ 194246145Shselasky 195246145Shselaskystruct mtx { 196246145Shselasky int owned; 197246145Shselasky struct mtx *parent; 198246145Shselasky}; 199246145Shselasky 200246145Shselasky#define mtx_assert(...) do { } while (0) 201246145Shselaskyvoid mtx_init(struct mtx *, const char *, const char *, int); 202246145Shselaskyvoid mtx_lock(struct mtx *); 203246145Shselaskyvoid mtx_unlock(struct mtx *); 204246145Shselaskyint mtx_owned(struct mtx *); 205246145Shselaskyvoid mtx_destroy(struct mtx *); 206246145Shselasky 207246145Shselaskyextern struct mtx Giant; 208246145Shselasky 209246145Shselasky/* SX API */ 210246145Shselasky 211246145Shselaskystruct sx { 212246145Shselasky int owned; 213246145Shselasky}; 214246145Shselasky 215246145Shselasky#define sx_assert(...) do { } while (0) 216246145Shselasky#define sx_init(...) sx_init_flags(__VA_ARGS__, 0) 217246145Shselaskyvoid sx_init_flags(struct sx *, const char *, int); 218246145Shselaskyvoid sx_destroy(struct sx *); 219246145Shselaskyvoid sx_xlock(struct sx *); 220246145Shselaskyvoid sx_xunlock(struct sx *); 221246145Shselaskyint sx_xlocked(struct sx *); 222246145Shselasky 223246145Shselasky/* CONDVAR API */ 224246145Shselasky 225246145Shselaskystruct cv { 226246145Shselasky int sleeping; 227246145Shselasky}; 228246145Shselasky 229246145Shselaskyvoid cv_init(struct cv *, const char *desc); 230246145Shselaskyvoid cv_destroy(struct cv *); 231246145Shselaskyvoid cv_wait(struct cv *, struct mtx *); 232246145Shselaskyint cv_timedwait(struct cv *, struct mtx *, int); 233246145Shselaskyvoid cv_signal(struct cv *); 234246145Shselaskyvoid cv_broadcast(struct cv *); 235246145Shselasky 236246145Shselasky/* CALLOUT API */ 237246145Shselasky 238246145Shselaskytypedef void callout_fn_t (void *); 239246145Shselasky 240246145Shselaskyextern volatile int ticks; 241246145Shselasky 242246145Shselaskystruct callout { 243246145Shselasky LIST_ENTRY(callout) entry; 244246145Shselasky callout_fn_t *func; 245246145Shselasky void *arg; 246246145Shselasky struct mtx *mtx; 247246145Shselasky int flags; 248246145Shselasky int timeout; 249246145Shselasky}; 250246145Shselasky 251246145Shselaskyvoid callout_init_mtx(struct callout *, struct mtx *, int); 252246145Shselaskyvoid callout_reset(struct callout *, int, callout_fn_t *, void *); 253246145Shselaskyvoid callout_stop(struct callout *); 254246145Shselaskyvoid callout_drain(struct callout *); 255246145Shselaskyint callout_pending(struct callout *); 256246145Shselaskyvoid callout_process(int timeout); 257246145Shselasky 258246145Shselasky/* DEVICE API */ 259246145Shselasky 260246145Shselaskystruct driver; 261246145Shselaskystruct devclass; 262246145Shselaskystruct device; 263246145Shselaskystruct module; 264246145Shselaskystruct module_data; 265246145Shselasky 266246145Shselaskytypedef struct driver driver_t; 267246145Shselaskytypedef struct devclass *devclass_t; 268246145Shselaskytypedef struct device *device_t; 269246145Shselaskytypedef void (intr_fn_t)(void *arg); 270246145Shselasky 271246145Shselaskytypedef int device_attach_t (device_t dev); 272246145Shselaskytypedef int device_detach_t (device_t dev); 273246145Shselaskytypedef int device_resume_t (device_t dev); 274246145Shselaskytypedef int device_shutdown_t (device_t dev); 275246145Shselaskytypedef int device_probe_t (device_t dev); 276246145Shselaskytypedef int device_suspend_t (device_t dev); 277246145Shselasky 278246145Shselaskytypedef int bus_child_location_str_t (device_t parent, device_t child, char *buf, size_t buflen); 279246145Shselaskytypedef int bus_child_pnpinfo_str_t (device_t parent, device_t child, char *buf, size_t buflen); 280246145Shselaskytypedef void bus_driver_added_t (device_t dev, driver_t *driver); 281246145Shselasky 282246145Shselaskystruct device_method { 283246145Shselasky const char *desc; 284246145Shselasky void *const func; 285246145Shselasky}; 286246145Shselasky 287246145Shselaskytypedef struct device_method device_method_t; 288246145Shselasky 289246145Shselaskystruct device { 290246145Shselasky TAILQ_HEAD(device_list, device) dev_children; 291246145Shselasky TAILQ_ENTRY(device) dev_link; 292246145Shselasky 293246145Shselasky struct device *dev_parent; 294246145Shselasky const struct module_data *dev_module; 295246145Shselasky void *dev_sc; 296246145Shselasky void *dev_aux; 297246145Shselasky intr_fn_t *dev_irq_fn; 298246145Shselasky void *dev_irq_arg; 299246145Shselasky 300246145Shselasky uint16_t dev_unit; 301246145Shselasky 302246145Shselasky char dev_nameunit[64]; 303246145Shselasky char dev_desc[64]; 304246145Shselasky 305246145Shselasky uint8_t dev_res_alloc:1; 306246145Shselasky uint8_t dev_quiet:1; 307246145Shselasky uint8_t dev_softc_set:1; 308246145Shselasky uint8_t dev_softc_alloc:1; 309246145Shselasky uint8_t dev_attached:1; 310246145Shselasky uint8_t dev_fixed_class:1; 311246145Shselasky uint8_t dev_unit_manual:1; 312246145Shselasky}; 313246145Shselasky 314246145Shselaskystruct devclass { 315246145Shselasky device_t dev_list[DEVCLASS_MAXUNIT]; 316246145Shselasky}; 317246145Shselasky 318246145Shselaskystruct driver { 319246145Shselasky const char *name; 320246145Shselasky const struct device_method *methods; 321246145Shselasky uint32_t size; 322246145Shselasky}; 323246145Shselasky 324246145Shselaskystruct module_data { 325246145Shselasky int (*callback) (struct module *, int, void *arg); 326246145Shselasky void *arg; 327246145Shselasky const char *bus_name; 328246145Shselasky const char *mod_name; 329246145Shselasky const char *long_name; 330246145Shselasky const struct driver *driver; 331246145Shselasky struct devclass **devclass_pp; 332246145Shselasky TAILQ_ENTRY(module_data) entry; 333246145Shselasky}; 334246145Shselasky 335246145Shselaskydevice_t device_get_parent(device_t dev); 336246145Shselaskyvoid *device_get_method(device_t dev, const char *what); 337246145Shselaskyconst char *device_get_name(device_t dev); 338246145Shselaskyconst char *device_get_nameunit(device_t dev); 339246145Shselasky 340246145Shselasky#define device_printf(dev, fmt,...) \ 341246145Shselasky printf("%s: " fmt, device_get_nameunit(dev),## __VA_ARGS__) 342246145Shselaskydevice_t device_add_child(device_t dev, const char *name, int unit); 343246145Shselaskyvoid device_quiet(device_t dev); 344246145Shselaskyvoid device_set_interrupt(device_t dev, intr_fn_t *fn, void *arg); 345246145Shselaskyvoid device_run_interrupts(device_t parent); 346246145Shselaskyvoid device_set_ivars(device_t dev, void *ivars); 347246145Shselaskyvoid *device_get_ivars(device_t dev); 348246145Shselaskyconst char *device_get_desc(device_t dev); 349246145Shselaskyint device_probe_and_attach(device_t dev); 350246145Shselaskyint device_detach(device_t dev); 351246145Shselaskyvoid *device_get_softc(device_t dev); 352246145Shselaskyvoid device_set_softc(device_t dev, void *softc); 353246145Shselaskyint device_delete_child(device_t dev, device_t child); 354246145Shselaskyint device_delete_children(device_t dev); 355246145Shselaskyint device_is_attached(device_t dev); 356246145Shselaskyvoid device_set_desc(device_t dev, const char *desc); 357246145Shselaskyvoid device_set_desc_copy(device_t dev, const char *desc); 358246145Shselaskyint device_get_unit(device_t dev); 359246145Shselaskyvoid *devclass_get_softc(devclass_t dc, int unit); 360246145Shselaskyint devclass_get_maxunit(devclass_t dc); 361246145Shselaskydevice_t devclass_get_device(devclass_t dc, int unit); 362246145Shselaskydevclass_t devclass_find(const char *classname); 363246145Shselasky 364246145Shselasky#define bus_get_dma_tag(...) (NULL) 365246145Shselaskyint bus_generic_detach(device_t dev); 366246145Shselaskyint bus_generic_resume(device_t dev); 367246145Shselaskyint bus_generic_shutdown(device_t dev); 368246145Shselaskyint bus_generic_suspend(device_t dev); 369246145Shselaskyint bus_generic_print_child(device_t dev, device_t child); 370246145Shselaskyvoid bus_generic_driver_added(device_t dev, driver_t *driver); 371246145Shselasky 372246145Shselasky/* BUS SPACE API */ 373246145Shselasky 374246145Shselaskyvoid bus_space_write_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint8_t data); 375246145Shselaskyvoid bus_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint16_t data); 376246145Shselaskyvoid bus_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint32_t data); 377246145Shselasky 378246145Shselaskyuint8_t bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset); 379246145Shselaskyuint16_t bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset); 380246145Shselaskyuint32_t bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset); 381246145Shselasky 382246145Shselaskyvoid 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); 383246145Shselaskyvoid 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); 384246145Shselaskyvoid 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); 385246145Shselasky 386246145Shselaskyvoid 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); 387246145Shselaskyvoid 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); 388246145Shselaskyvoid 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); 389246145Shselasky 390246145Shselaskyvoid 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); 391246145Shselaskyvoid 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); 392246145Shselaskyvoid 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); 393246145Shselaskyvoid 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); 394246145Shselasky 395246145Shselaskyvoid bus_space_barrier(bus_space_tag_t space, bus_space_handle_t handle, bus_size_t offset, bus_size_t length, int flags); 396246145Shselasky 397246145Shselaskyvoid module_register(void *); 398246145Shselasky 399246145Shselasky/* LIB-C */ 400246145Shselasky 401246145Shselaskyvoid *memset(void *, int, size_t len); 402246145Shselaskyvoid *memcpy(void *, const void *, size_t len); 403246145Shselaskyint printf(const char *,...) __printflike(1, 2); 404246145Shselaskyint snprintf(char *restrict str, size_t size, const char *restrict format,...) __printflike(3, 4); 405246145Shselaskysize_t strlen(const char *s); 406246145Shselasky 407246145Shselasky/* MALLOC API */ 408246145Shselasky 409246145Shselasky#define malloc(s,x,f) usb_malloc(s) 410246145Shselaskyvoid *usb_malloc(size_t); 411246145Shselasky 412246145Shselasky#define free(p,x) usb_free(p) 413246145Shselaskyvoid usb_free(void *); 414246145Shselasky 415246145Shselasky#define strdup(p,x) usb_strdup(p) 416246145Shselaskychar *usb_strdup(const char *str); 417246145Shselasky 418246145Shselasky/* ENDIANNESS */ 419246145Shselasky 420246145Shselasky/* Assume little endian */ 421246145Shselasky 422246145Shselasky#define htole64(x) ((uint64_t)(x)) 423246145Shselasky#define le64toh(x) ((uint64_t)(x)) 424246145Shselasky 425246145Shselasky#define htole32(x) ((uint32_t)(x)) 426246145Shselasky#define le32toh(x) ((uint32_t)(x)) 427246145Shselasky 428246145Shselasky#define htole16(x) ((uint16_t)(x)) 429246145Shselasky#define le16toh(x) ((uint16_t)(x)) 430246145Shselasky 431246145Shselasky#define be32toh(x) ((uint32_t)(x)) 432246145Shselasky#define htobe32(x) ((uint32_t)(x)) 433246145Shselasky 434246145Shselasky/* USB */ 435246145Shselasky 436246145Shselaskytypedef int usb_handle_request_t (device_t dev, const void *req, void **pptr, uint16_t *plen, uint16_t offset, uint8_t *pstate); 437246145Shselaskytypedef int usb_take_controller_t (device_t dev); 438246145Shselasky 439246145Shselaskyvoid usb_idle(void); 440246145Shselaskyvoid usb_init(void); 441246145Shselaskyvoid usb_uninit(void); 442246145Shselasky 443246145Shselasky/* set some defaults */ 444246145Shselasky 445246145Shselasky#ifndef USB_POOL_SIZE 446246145Shselasky#define USB_POOL_SIZE (1024*1024) /* 1 MByte */ 447246145Shselasky#endif 448246145Shselasky 449246145Shselaskyint pause(const char *, int); 450246145Shselaskyvoid DELAY(unsigned int); 451246145Shselasky 452246145Shselasky/* OTHER */ 453246145Shselasky 454246145Shselaskystruct selinfo { 455246145Shselasky}; 456246145Shselasky 457246145Shselasky/* SYSTEM STARTUP API */ 458246145Shselasky 459246145Shselaskyextern const void *sysinit_data[]; 460246145Shselaskyextern const void *sysuninit_data[]; 461246145Shselasky 462246145Shselasky#endif /* _BSD_KERNEL_H_ */ 463