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