1 /* $FreeBSD$ */ 2 /*- 3 * Copyright (c) 2011 Hans Petter Selasky. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27 #ifndef _BSD_KERNEL_H_ 28 #define _BSD_KERNEL_H_ 29 30 #if !defined(_STANDALONE) 31 #error "_STANDALONE is not defined!" 32 #endif 33 34 #undef __FreeBSD_version 35 #define __FreeBSD_version 1300000 36 37 #include <sys/cdefs.h> 38 #include <sys/queue.h> 39 #include <sys/errno.h> 40 41 #define offsetof(type, field) __builtin_offsetof(type, field) 42 #define howmany(x, y) (((x)+((y)-1))/(y)) 43 #define nitems(x) (sizeof((x)) / sizeof((x)[0])) 44 #define isalpha(x) (((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z')) 45 #define isdigit(x) ((x) >= '0' && (x) <= '9') 46 #define panic(...) do { printf("USB PANIC: " __VA_ARGS__); while (1) ; } while (0) 47 #define rebooting 0 48 #define M_USB 0 49 #define M_USBDEV 0 50 #define USB_PROC_MAX 3 51 #define USB_BUS_GIANT_PROC(bus) (usb_process + 2) 52 #define USB_BUS_NON_GIANT_BULK_PROC(bus) (usb_process + 2) 53 #define USB_BUS_NON_GIANT_ISOC_PROC(bus) (usb_process + 2) 54 #define USB_BUS_EXPLORE_PROC(bus) (usb_process + 0) 55 #define USB_BUS_CONTROL_XFER_PROC(bus) (usb_process + 1) 56 #define SYSCTL_DECL(...) 57 struct sysctl_ctx_list { 58 }; 59 struct sysctl_req { 60 void *newptr; 61 }; 62 #define SYSCTL_HANDLER_ARGS void *oidp, void *arg1, \ 63 uint32_t arg2, struct sysctl_req *req 64 #define SYSCTL_NODE(name,...) struct { } name __used 65 #define SYSCTL_INT(...) 66 #define SYSCTL_UINT(...) 67 #define SYSCTL_PROC(...) 68 #define SYSCTL_ADD_NODE(...) NULL 69 #define SYSCTL_ADD_U16(...) NULL 70 #define SYSCTL_ADD_PROC(...) NULL 71 #define sysctl_handle_int(...) EOPNOTSUPP 72 #define sysctl_handle_string(...) EOPNOTSUPP 73 #define sysctl_ctx_init(ctx) do { (void)(ctx); } while (0) 74 #define sysctl_ctx_free(ctx) do { (void)(ctx); } while (0) 75 #define TUNABLE_INT(...) 76 #define MALLOC_DECLARE(...) 77 #define MALLOC_DEFINE(...) 78 #define EVENTHANDLER_DECLARE(...) 79 #define EVENTHANDLER_INVOKE(...) 80 #define KASSERT(...) 81 #define CTASSERT(x) _Static_assert(x, "compile-time assertion failed") 82 #define SCHEDULER_STOPPED(x) (0) 83 #define PI_SWI(...) (0) 84 #define UNIQ_NAME(x) x 85 #define UNIQ_NAME_STR(x) #x 86 #define DEVCLASS_MAXUNIT 32 87 #define MOD_LOAD 1 88 #define MOD_UNLOAD 2 89 #define DEVMETHOD(what,func) { #what, (void *)&func } 90 #define DEVMETHOD_END {0,0} 91 #define EARLY_DRIVER_MODULE(a, b, c, d, e, f, g) DRIVER_MODULE(a, b, c, d, e, f) 92 #define DRIVER_MODULE(name, busname, driver, devclass, evh, arg) \ 93 static struct module_data bsd_##name##_##busname##_driver_mod = { \ 94 evh, arg, #busname, #name, #busname "/" #name, \ 95 &driver, &devclass, { 0, 0 } }; \ 96 SYSINIT(bsd_##name##_##busname##_driver_mod, SI_SUB_DRIVERS, \ 97 SI_ORDER_MIDDLE, module_register, \ 98 &bsd_##name##_##busname##_driver_mod) 99 #define SYSINIT(uniq, subs, order, _func, _data) \ 100 const struct sysinit UNIQ_NAME(sysinit_##uniq) = { \ 101 .func = (_func), \ 102 .data = __DECONST(void *, _data) \ 103 }; \ 104 SYSINIT_ENTRY(uniq##_entry, "sysinit", (subs), \ 105 (order), "const struct sysinit", \ 106 UNIQ_NAME_STR(sysinit_##uniq), "SYSINIT") 107 108 #define SYSUNINIT(uniq, subs, order, _func, _data) \ 109 const struct sysinit UNIQ_NAME(sysuninit_##uniq) = { \ 110 .func = (_func), \ 111 .data = __DECONST(void *, _data) \ 112 }; \ 113 SYSINIT_ENTRY(uniq##_entry, "sysuninit", (subs), \ 114 (order), "const struct sysuninit", \ 115 UNIQ_NAME_STR(sysuninit_##uniq), "SYSUNINIT") 116 #define MODULE_DEPEND(...) 117 #define MODULE_VERSION(...) 118 #define NULL ((void *)0) 119 #define BUS_SPACE_BARRIER_READ 0x01 120 #define BUS_SPACE_BARRIER_WRITE 0x02 121 #define hz 1000 122 #undef PAGE_SIZE 123 #define PAGE_SIZE 4096 124 #undef PAGE_SHIFT 125 #define PAGE_SHIFT 12 126 #undef MIN 127 #define MIN(a,b) (((a) < (b)) ? (a) : (b)) 128 #undef MAX 129 #define MAX(a,b) (((a) > (b)) ? (a) : (b)) 130 #define MTX_DEF 0 131 #define MTX_SPIN 0 132 #define MTX_RECURSE 0 133 #define SX_DUPOK 0 134 #define SX_NOWITNESS 0 135 #define WITNESS_WARN(...) 136 #define cold 0 137 #define BUS_PROBE_GENERIC 0 138 #define BUS_PROBE_DEFAULT (-20) 139 #define CALLOUT_RETURNUNLOCKED 0x1 140 #undef ffs 141 #define ffs(x) __builtin_ffs(x) 142 #undef va_list 143 #define va_list __builtin_va_list 144 #undef va_size 145 #define va_size(type) __builtin_va_size(type) 146 #undef va_start 147 #define va_start(ap, last) __builtin_va_start(ap, last) 148 #undef va_end 149 #define va_end(ap) __builtin_va_end(ap) 150 #undef va_arg 151 #define va_arg(ap, type) __builtin_va_arg((ap), type) 152 #define DEVICE_ATTACH(dev, ...) \ 153 (((device_attach_t *)(device_get_method(dev, "device_attach")))(dev,## __VA_ARGS__)) 154 #define DEVICE_DETACH(dev, ...) \ 155 (((device_detach_t *)(device_get_method(dev, "device_detach")))(dev,## __VA_ARGS__)) 156 #define DEVICE_PROBE(dev, ...) \ 157 (((device_probe_t *)(device_get_method(dev, "device_probe")))(dev,## __VA_ARGS__)) 158 #define DEVICE_RESUME(dev, ...) \ 159 (((device_resume_t *)(device_get_method(dev, "device_resume")))(dev,## __VA_ARGS__)) 160 #define DEVICE_SHUTDOWN(dev, ...) \ 161 (((device_shutdown_t *)(device_get_method(dev, "device_shutdown")))(dev,## __VA_ARGS__)) 162 #define DEVICE_SUSPEND(dev, ...) \ 163 (((device_suspend_t *)(device_get_method(dev, "device_suspend")))(dev,## __VA_ARGS__)) 164 #define USB_HANDLE_REQUEST(dev, ...) \ 165 (((usb_handle_request_t *)(device_get_method(dev, "usb_handle_request")))(dev,## __VA_ARGS__)) 166 #define USB_TAKE_CONTROLLER(dev, ...) \ 167 (((usb_take_controller_t *)(device_get_method(dev, "usb_take_controller")))(dev,## __VA_ARGS__)) 168 #define GPIO_PIN_SET(dev, ...) \ 169 (((gpio_pin_set_t *)(device_get_method(dev, "gpio_pin_set")))(dev,## __VA_ARGS__)) 170 #define GPIO_PIN_SETFLAGS(dev, ...) \ 171 (((gpio_pin_setflags_t *)(device_get_method(dev, "gpio_pin_setflags")))(dev,## __VA_ARGS__)) 172 173 enum { 174 SI_SUB_DUMMY = 0x0000000, 175 SI_SUB_LOCK = 0x1B00000, 176 SI_SUB_KLD = 0x2000000, 177 SI_SUB_DRIVERS = 0x3100000, 178 SI_SUB_PSEUDO = 0x7000000, 179 SI_SUB_KICK_SCHEDULER = 0xa000000, 180 SI_SUB_RUN_SCHEDULER = 0xfffffff 181 }; 182 183 enum { 184 SI_ORDER_FIRST = 0x0000000, 185 SI_ORDER_SECOND = 0x0000001, 186 SI_ORDER_THIRD = 0x0000002, 187 SI_ORDER_FOURTH = 0x0000003, 188 SI_ORDER_MIDDLE = 0x1000000, 189 SI_ORDER_ANY = 0xfffffff /* last */ 190 }; 191 192 struct uio; 193 struct thread; 194 struct malloc_type; 195 struct usb_process; 196 197 #ifndef INT32_MAX 198 #define INT32_MAX 0x7fffffff 199 #endif 200 201 #ifndef HAVE_STANDARD_DEFS 202 #define _UINT8_T_DECLARED 203 typedef unsigned char uint8_t; 204 #define _INT8_T_DECLARED 205 typedef signed char int8_t; 206 #define _UINT16_T_DECLARED 207 typedef unsigned short uint16_t; 208 #define _INT16_T_DECLARED 209 typedef signed short int16_t; 210 #define _UINT32_T_DECLARED 211 typedef unsigned int uint32_t; 212 #define _INT32_T_DECLARED 213 typedef signed int int32_t; 214 #define _UINT64_T_DECLARED 215 #ifndef __LP64__ 216 typedef unsigned long long uint64_t; 217 #else 218 typedef unsigned long uint64_t; 219 #endif 220 #define _INT64_T_DECLARED 221 #ifndef __LP64__ 222 typedef signed long long int64_t; 223 #else 224 typedef signed long int64_t; 225 #endif 226 227 typedef uint16_t uid_t; 228 typedef uint16_t gid_t; 229 typedef uint16_t mode_t; 230 231 typedef uint8_t *caddr_t; 232 #define _UINTPTR_T_DECLARED 233 typedef unsigned long uintptr_t; 234 #define _UINTMAX_T_DECLARED 235 typedef unsigned long uintmax_t; 236 typedef unsigned long vm_paddr_t; 237 238 #define _SIZE_T_DECLARED 239 typedef unsigned long size_t; 240 #define _SSIZE_T_DECLARED 241 typedef signed long ssize_t; 242 #define _OFF_T_DECLARED 243 typedef unsigned long off_t; 244 245 typedef unsigned char u_char; 246 typedef unsigned short u_short; 247 typedef unsigned int u_int; 248 typedef unsigned long u_long; 249 #endif 250 251 typedef unsigned long bus_addr_t; 252 typedef unsigned long bus_size_t; 253 254 typedef struct bus_dma_segment { 255 bus_addr_t ds_addr; /* DMA address */ 256 bus_size_t ds_len; /* length of transfer */ 257 } bus_dma_segment_t; 258 259 struct bus_dma_tag { 260 uint32_t alignment; 261 uint32_t maxsize; 262 }; 263 264 typedef void *bus_dmamap_t; 265 typedef struct bus_dma_tag *bus_dma_tag_t; 266 267 typedef enum { 268 BUS_DMA_LOCK = 0x01, 269 BUS_DMA_UNLOCK = 0x02, 270 } bus_dma_lock_op_t; 271 272 typedef void *bus_space_tag_t; 273 typedef uint8_t *bus_space_handle_t; 274 typedef int bus_dma_filter_t(void *, bus_addr_t); 275 typedef void bus_dma_lock_t(void *, bus_dma_lock_op_t); 276 277 #ifndef __bool_true_false_are_defined 278 #define __bool_true_false_are_defined 279 typedef _Bool bool; 280 #define true 1 281 #define false 0 282 #endif 283 284 /* SYSINIT API */ 285 286 #include <sysinit.h> 287 288 struct sysinit { 289 void (*func) (void *arg); 290 void *data; 291 }; 292 293 /* MUTEX API */ 294 295 struct mtx { 296 int owned; 297 struct mtx *parent; 298 }; 299 300 #define mtx_assert(...) do { } while (0) 301 void mtx_init(struct mtx *, const char *, const char *, int); 302 void mtx_lock(struct mtx *); 303 void mtx_unlock(struct mtx *); 304 #define mtx_lock_spin(x) mtx_lock(x) 305 #define mtx_unlock_spin(x) mtx_unlock(x) 306 int mtx_owned(struct mtx *); 307 void mtx_destroy(struct mtx *); 308 309 extern struct mtx Giant; 310 311 /* SX API */ 312 313 struct sx { 314 int owned; 315 }; 316 317 #define sx_assert(...) do { } while (0) 318 #define sx_init(...) sx_init_flags(__VA_ARGS__, 0) 319 void sx_init_flags(struct sx *, const char *, int); 320 void sx_destroy(struct sx *); 321 void sx_xlock(struct sx *); 322 void sx_xunlock(struct sx *); 323 int sx_xlocked(struct sx *); 324 325 /* CONDVAR API */ 326 327 struct cv { 328 int sleeping; 329 }; 330 331 void cv_init(struct cv *, const char *desc); 332 void cv_destroy(struct cv *); 333 void cv_wait(struct cv *, struct mtx *); 334 int cv_timedwait(struct cv *, struct mtx *, int); 335 void cv_signal(struct cv *); 336 void cv_broadcast(struct cv *); 337 338 /* CALLOUT API */ 339 340 typedef void callout_fn_t (void *); 341 342 extern volatile int ticks; 343 344 struct callout { 345 LIST_ENTRY(callout) entry; 346 callout_fn_t *c_func; 347 void *c_arg; 348 struct mtx *mtx; 349 int flags; 350 int timeout; 351 }; 352 353 void callout_init_mtx(struct callout *, struct mtx *, int); 354 void callout_reset(struct callout *, int, callout_fn_t *, void *); 355 void callout_stop(struct callout *); 356 void callout_drain(struct callout *); 357 int callout_pending(struct callout *); 358 void callout_process(int timeout); 359 360 /* DEVICE API */ 361 362 struct driver; 363 struct devclass; 364 struct device; 365 struct module; 366 struct module_data; 367 368 typedef struct driver driver_t; 369 typedef struct devclass *devclass_t; 370 typedef struct device *device_t; 371 typedef void (driver_intr_t)(void *arg); 372 typedef int (driver_filter_t)(void *arg); 373 #define FILTER_STRAY 0x01 374 #define FILTER_HANDLED 0x02 375 #define FILTER_SCHEDULE_THREAD 0x04 376 377 typedef int device_attach_t (device_t dev); 378 typedef int device_detach_t (device_t dev); 379 typedef int device_resume_t (device_t dev); 380 typedef int device_shutdown_t (device_t dev); 381 typedef int device_probe_t (device_t dev); 382 typedef int device_suspend_t (device_t dev); 383 typedef int gpio_pin_set_t (device_t dev, uint32_t, unsigned int); 384 typedef int gpio_pin_setflags_t (device_t dev, uint32_t, uint32_t); 385 386 typedef int bus_child_location_str_t (device_t parent, device_t child, char *buf, size_t buflen); 387 typedef int bus_child_pnpinfo_str_t (device_t parent, device_t child, char *buf, size_t buflen); 388 typedef void bus_driver_added_t (device_t dev, driver_t *driver); 389 390 struct device_method { 391 const char *desc; 392 void *const func; 393 }; 394 395 typedef struct device_method device_method_t; 396 397 struct device { 398 TAILQ_HEAD(device_list, device) dev_children; 399 TAILQ_ENTRY(device) dev_link; 400 401 struct device *dev_parent; 402 const struct module_data *dev_module; 403 void *dev_sc; 404 void *dev_aux; 405 driver_filter_t *dev_irq_filter; 406 driver_intr_t *dev_irq_fn; 407 void *dev_irq_arg; 408 409 uint16_t dev_unit; 410 411 char dev_nameunit[64]; 412 char dev_desc[64]; 413 414 uint8_t dev_res_alloc:1; 415 uint8_t dev_quiet:1; 416 uint8_t dev_softc_set:1; 417 uint8_t dev_softc_alloc:1; 418 uint8_t dev_attached:1; 419 uint8_t dev_fixed_class:1; 420 uint8_t dev_unit_manual:1; 421 }; 422 423 struct devclass { 424 device_t dev_list[DEVCLASS_MAXUNIT]; 425 }; 426 427 struct driver { 428 const char *name; 429 const struct device_method *methods; 430 uint32_t size; 431 }; 432 433 struct module_data { 434 int (*callback) (struct module *, int, void *arg); 435 void *arg; 436 const char *bus_name; 437 const char *mod_name; 438 const char *long_name; 439 const struct driver *driver; 440 struct devclass **devclass_pp; 441 TAILQ_ENTRY(module_data) entry; 442 }; 443 444 device_t device_get_parent(device_t dev); 445 void *device_get_method(device_t dev, const char *what); 446 const char *device_get_name(device_t dev); 447 const char *device_get_nameunit(device_t dev); 448 449 #define device_printf(dev, fmt,...) \ 450 printf("%s: " fmt, device_get_nameunit(dev),## __VA_ARGS__) 451 device_t device_add_child(device_t dev, const char *name, int unit); 452 void device_quiet(device_t dev); 453 void device_set_interrupt(device_t dev, driver_filter_t *, driver_intr_t *, void *); 454 void device_run_interrupts(device_t parent); 455 void device_set_ivars(device_t dev, void *ivars); 456 void *device_get_ivars(device_t dev); 457 const char *device_get_desc(device_t dev); 458 int device_probe_and_attach(device_t dev); 459 int device_detach(device_t dev); 460 void *device_get_softc(device_t dev); 461 void device_set_softc(device_t dev, void *softc); 462 int device_delete_child(device_t dev, device_t child); 463 int device_delete_children(device_t dev); 464 int device_is_attached(device_t dev); 465 void device_set_desc(device_t dev, const char *desc); 466 void device_set_desc_copy(device_t dev, const char *desc); 467 int device_get_unit(device_t dev); 468 void *devclass_get_softc(devclass_t dc, int unit); 469 int devclass_get_maxunit(devclass_t dc); 470 device_t devclass_get_device(devclass_t dc, int unit); 471 devclass_t devclass_find(const char *classname); 472 473 #define bus_get_dma_tag(...) (NULL) 474 int bus_generic_detach(device_t dev); 475 int bus_generic_resume(device_t dev); 476 int bus_generic_shutdown(device_t dev); 477 int bus_generic_suspend(device_t dev); 478 int bus_generic_print_child(device_t dev, device_t child); 479 void bus_generic_driver_added(device_t dev, driver_t *driver); 480 int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh, 481 bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp); 482 483 /* BUS SPACE API */ 484 485 void bus_space_write_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint8_t data); 486 void bus_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint16_t data); 487 void bus_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint32_t data); 488 489 uint8_t bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset); 490 uint16_t bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset); 491 uint32_t bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset); 492 493 void 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); 494 void 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); 495 void 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); 496 497 void 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); 498 void 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); 499 void 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); 500 501 void 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); 502 void 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); 503 void 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); 504 void 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); 505 506 void bus_space_barrier(bus_space_tag_t space, bus_space_handle_t handle, bus_size_t offset, bus_size_t length, int flags); 507 508 void module_register(void *); 509 510 /* LIB-C */ 511 512 void *memset(void *, int, size_t len); 513 void *memcpy(void *, const void *, size_t len); 514 int memcmp(const void *, const void *, size_t len); 515 int printf(const char *,...) __printflike(1, 2); 516 int snprintf(char *restrict str, size_t size, const char *restrict format,...) __printflike(3, 4); 517 size_t strlen(const char *s); 518 519 /* MALLOC API */ 520 521 #undef malloc 522 #define malloc(s,x,f) usb_malloc(s) 523 void *usb_malloc(size_t); 524 525 #undef free 526 #define free(p,x) usb_free(p) 527 void usb_free(void *); 528 529 #define strdup(p,x) usb_strdup(p) 530 char *usb_strdup(const char *str); 531 532 /* ENDIANNESS */ 533 534 #ifndef HAVE_ENDIAN_DEFS 535 536 /* Assume little endian */ 537 538 #define htole64(x) ((uint64_t)(x)) 539 #define le64toh(x) ((uint64_t)(x)) 540 541 #define htole32(x) ((uint32_t)(x)) 542 #define le32toh(x) ((uint32_t)(x)) 543 544 #define htole16(x) ((uint16_t)(x)) 545 #define le16toh(x) ((uint16_t)(x)) 546 547 #define be32toh(x) ((uint32_t)(x)) 548 #define htobe32(x) ((uint32_t)(x)) 549 550 #else 551 #include <sys/endian.h> 552 #endif 553 554 /* USB */ 555 556 typedef int usb_handle_request_t (device_t dev, const void *req, void **pptr, uint16_t *plen, uint16_t offset, uint8_t *pstate); 557 typedef int usb_take_controller_t (device_t dev); 558 559 void usb_idle(void); 560 void usb_init(void); 561 void usb_uninit(void); 562 563 /* set some defaults */ 564 565 #ifndef USB_POOL_SIZE 566 #define USB_POOL_SIZE (1024*1024) /* 1 MByte */ 567 #endif 568 569 int pause(const char *, int); 570 void DELAY(unsigned int); 571 572 /* OTHER */ 573 574 struct selinfo { 575 }; 576 577 /* SYSTEM STARTUP API */ 578 579 extern const void *sysinit_data[]; 580 extern const void *sysuninit_data[]; 581 582 /* Resources */ 583 584 enum intr_type { 585 INTR_TYPE_TTY = 1, 586 INTR_TYPE_BIO = 2, 587 INTR_TYPE_NET = 4, 588 INTR_TYPE_CAM = 8, 589 INTR_TYPE_MISC = 16, 590 INTR_TYPE_CLK = 32, 591 INTR_TYPE_AV = 64, 592 INTR_EXCL = 256, /* exclusive interrupt */ 593 INTR_MPSAFE = 512, /* this interrupt is SMP safe */ 594 INTR_ENTROPY = 1024, /* this interrupt provides entropy */ 595 INTR_MD1 = 4096, /* flag reserved for MD use */ 596 INTR_MD2 = 8192, /* flag reserved for MD use */ 597 INTR_MD3 = 16384, /* flag reserved for MD use */ 598 INTR_MD4 = 32768 /* flag reserved for MD use */ 599 }; 600 601 struct resource_i { 602 u_long r_start; /* index of the first entry in this resource */ 603 u_long r_end; /* index of the last entry (inclusive) */ 604 }; 605 606 struct resource { 607 struct resource_i *__r_i; 608 bus_space_tag_t r_bustag; /* bus_space tag */ 609 bus_space_handle_t r_bushandle; /* bus_space handle */ 610 }; 611 612 struct resource_spec { 613 int type; 614 int rid; 615 int flags; 616 }; 617 618 #define SYS_RES_IRQ 1 /* interrupt lines */ 619 #define SYS_RES_DRQ 2 /* isa dma lines */ 620 #define SYS_RES_MEMORY 3 /* i/o memory */ 621 #define SYS_RES_IOPORT 4 /* i/o ports */ 622 623 #define RF_ALLOCATED 0x0001 /* resource has been reserved */ 624 #define RF_ACTIVE 0x0002 /* resource allocation has been activated */ 625 #define RF_SHAREABLE 0x0004 /* resource permits contemporaneous sharing */ 626 #define RF_SPARE1 0x0008 627 #define RF_SPARE2 0x0010 628 #define RF_FIRSTSHARE 0x0020 /* first in sharing list */ 629 #define RF_PREFETCHABLE 0x0040 /* resource is prefetchable */ 630 #define RF_OPTIONAL 0x0080 /* for bus_alloc_resources() */ 631 632 int bus_alloc_resources(device_t, struct resource_spec *, struct resource **); 633 int bus_release_resource(device_t, int, int, struct resource *); 634 void bus_release_resources(device_t, const struct resource_spec *, 635 struct resource **); 636 struct resource *bus_alloc_resource_any(device_t, int, int *, unsigned int); 637 int bus_generic_attach(device_t); 638 bus_space_tag_t rman_get_bustag(struct resource *); 639 bus_space_handle_t rman_get_bushandle(struct resource *); 640 u_long rman_get_size(struct resource *); 641 int bus_setup_intr(device_t, struct resource *, int, driver_filter_t, 642 driver_intr_t, void *, void **); 643 int bus_teardown_intr(device_t, struct resource *, void *); 644 int ofw_bus_status_okay(device_t); 645 int ofw_bus_is_compatible(device_t, char *); 646 647 extern int (*bus_alloc_resource_any_cb)(struct resource *res, device_t dev, 648 int type, int *rid, unsigned int flags); 649 extern int (*ofw_bus_status_ok_cb)(device_t dev); 650 extern int (*ofw_bus_is_compatible_cb)(device_t dev, char *name); 651 652 #ifndef strlcpy 653 #define strlcpy(d,s,n) snprintf((d),(n),"%s",(s)) 654 #endif 655 656 /* Should be defined in user application since it is machine-dependent */ 657 extern int delay(unsigned int); 658 659 /* BUS dma */ 660 #define BUS_SPACE_MAXADDR_24BIT 0xFFFFFF 661 #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF 662 #define BUS_SPACE_MAXADDR 0xFFFFFFFF 663 #define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF 664 #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF 665 #define BUS_SPACE_MAXSIZE 0xFFFFFFFF 666 667 #define BUS_DMA_WAITOK 0x00 /* safe to sleep (pseudo-flag) */ 668 #define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */ 669 #define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */ 670 #define BUS_DMA_COHERENT 0x04 /* hint: map memory in a coherent way */ 671 #define BUS_DMA_ZERO 0x08 /* allocate zero'ed memory */ 672 #define BUS_DMA_BUS1 0x10 /* placeholders for bus functions... */ 673 #define BUS_DMA_BUS2 0x20 674 #define BUS_DMA_BUS3 0x40 675 #define BUS_DMA_BUS4 0x80 676 677 #define BUS_DMASYNC_PREREAD 0x01 678 #define BUS_DMASYNC_POSTREAD 0x02 679 #define BUS_DMASYNC_PREWRITE 0x04 680 #define BUS_DMASYNC_POSTWRITE 0x08 681 682 typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int); 683 684 int 685 bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, 686 bus_size_t boundary, bus_addr_t lowaddr, 687 bus_addr_t highaddr, bus_dma_filter_t *filter, 688 void *filterarg, bus_size_t maxsize, int nsegments, 689 bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, 690 void *lockfuncarg, bus_dma_tag_t *dmat); 691 692 int bus_dmamem_alloc(bus_dma_tag_t, void** vaddr, int flags, bus_dmamap_t *); 693 void bus_dmamem_free(bus_dma_tag_t, void *vaddr, bus_dmamap_t); 694 int bus_dma_tag_destroy(bus_dma_tag_t); 695 696 int bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *buf, 697 bus_size_t buflen, bus_dmamap_callback_t *, 698 void *callback_arg, int flags); 699 void bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t); 700 void bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, int flags); 701 702 #endif /* _BSD_KERNEL_H_ */ 703