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