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