Deleted Added
full compact
bsd_kernel.h (256281) bsd_kernel.h (269921)
1/* $FreeBSD: stable/10/sys/boot/usb/bsd_kernel.h 246363 2013-02-05 14:44:25Z hselasky $ */
1/* $FreeBSD: stable/10/sys/boot/usb/bsd_kernel.h 269921 2014-08-13 08:18:49Z hselasky $ */
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#define __FreeBSD_version 1000000
32
33#include <sys/cdefs.h>
34#include <sys/queue.h>
35#include <sys/errno.h>
36
37#define isalpha(x) (((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z'))
38#define isdigit(x) ((x) >= '0' && (x) <= '9')
39#define panic(...) do { printf("USB PANIC: " __VA_ARGS__); while (1) ; } while (0)
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#define __FreeBSD_version 1000000
32
33#include <sys/cdefs.h>
34#include <sys/queue.h>
35#include <sys/errno.h>
36
37#define isalpha(x) (((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z'))
38#define isdigit(x) ((x) >= '0' && (x) <= '9')
39#define panic(...) do { printf("USB PANIC: " __VA_ARGS__); while (1) ; } while (0)
40#define rebooting 0
40#define M_USB 0
41#define M_USBDEV 0
42#define USB_PROC_MAX 3
43#define USB_BUS_GIANT_PROC(bus) (usb_process + 2)
44#define USB_BUS_NON_GIANT_PROC(bus) (usb_process + 2)
45#define USB_BUS_EXPLORE_PROC(bus) (usb_process + 0)
46#define USB_BUS_CONTROL_XFER_PROC(bus) (usb_process + 1)
47#define SYSCTL_DECL(...)
48#define SYSCTL_NODE(name,...) struct { } name __used
49#define SYSCTL_INT(...)
50#define TUNABLE_INT(...)
51#define MALLOC_DECLARE(...)
52#define MALLOC_DEFINE(...)
53#define EVENTHANDLER_DECLARE(...)
54#define EVENTHANDLER_INVOKE(...)
55#define KASSERT(...)
56#define SCHEDULER_STOPPED(x) (0)
57#define PI_SWI(...) (0)
58#define UNIQ_NAME(x) x
59#define UNIQ_NAME_STR(x) #x
60#define DEVCLASS_MAXUNIT 32
61#define MOD_LOAD 1
62#define MOD_UNLOAD 2
63#define DEVMETHOD(what,func) { #what, (void *)&func }
64#define DEVMETHOD_END {0,0}
65#define DRIVER_MODULE(name, busname, driver, devclass, evh, arg) \
66 static struct module_data bsd_##name##_##busname##_driver_mod = { \
67 evh, arg, #busname, #name, #busname "/" #name, \
68 &driver, &devclass, { 0, 0 } }; \
69SYSINIT(bsd_##name##_##busname##_driver_mod, SI_SUB_DRIVERS, \
70 SI_ORDER_MIDDLE, module_register, \
71 &bsd_##name##_##busname##_driver_mod)
72#define SYSINIT(uniq, subs, order, _func, _data) \
73const struct sysinit UNIQ_NAME(sysinit_##uniq) = { \
74 .func = (_func), \
75 .data = __DECONST(void *, _data) \
76}; \
77SYSINIT_ENTRY(uniq##_entry, "sysinit", (subs), \
78 (order), "const struct sysinit", \
79 UNIQ_NAME_STR(sysinit_##uniq), "SYSINIT")
80
81#define SYSUNINIT(uniq, subs, order, _func, _data) \
82const struct sysinit UNIQ_NAME(sysuninit_##uniq) = { \
83 .func = (_func), \
84 .data = __DECONST(void *, _data) \
85}; \
86SYSINIT_ENTRY(uniq##_entry, "sysuninit", (subs), \
87 (order), "const struct sysuninit", \
88 UNIQ_NAME_STR(sysuninit_##uniq), "SYSUNINIT")
89#define MODULE_DEPEND(...)
90#define MODULE_VERSION(...)
91#define NULL ((void *)0)
92#define BUS_SPACE_BARRIER_READ 0x01
93#define BUS_SPACE_BARRIER_WRITE 0x02
94#define hz 1000
95#define PAGE_SIZE 4096
96#define MIN(a,b) (((a) < (b)) ? (a) : (b))
97#define MAX(a,b) (((a) > (b)) ? (a) : (b))
98#define MTX_DEF 0
41#define M_USB 0
42#define M_USBDEV 0
43#define USB_PROC_MAX 3
44#define USB_BUS_GIANT_PROC(bus) (usb_process + 2)
45#define USB_BUS_NON_GIANT_PROC(bus) (usb_process + 2)
46#define USB_BUS_EXPLORE_PROC(bus) (usb_process + 0)
47#define USB_BUS_CONTROL_XFER_PROC(bus) (usb_process + 1)
48#define SYSCTL_DECL(...)
49#define SYSCTL_NODE(name,...) struct { } name __used
50#define SYSCTL_INT(...)
51#define TUNABLE_INT(...)
52#define MALLOC_DECLARE(...)
53#define MALLOC_DEFINE(...)
54#define EVENTHANDLER_DECLARE(...)
55#define EVENTHANDLER_INVOKE(...)
56#define KASSERT(...)
57#define SCHEDULER_STOPPED(x) (0)
58#define PI_SWI(...) (0)
59#define UNIQ_NAME(x) x
60#define UNIQ_NAME_STR(x) #x
61#define DEVCLASS_MAXUNIT 32
62#define MOD_LOAD 1
63#define MOD_UNLOAD 2
64#define DEVMETHOD(what,func) { #what, (void *)&func }
65#define DEVMETHOD_END {0,0}
66#define DRIVER_MODULE(name, busname, driver, devclass, evh, arg) \
67 static struct module_data bsd_##name##_##busname##_driver_mod = { \
68 evh, arg, #busname, #name, #busname "/" #name, \
69 &driver, &devclass, { 0, 0 } }; \
70SYSINIT(bsd_##name##_##busname##_driver_mod, SI_SUB_DRIVERS, \
71 SI_ORDER_MIDDLE, module_register, \
72 &bsd_##name##_##busname##_driver_mod)
73#define SYSINIT(uniq, subs, order, _func, _data) \
74const struct sysinit UNIQ_NAME(sysinit_##uniq) = { \
75 .func = (_func), \
76 .data = __DECONST(void *, _data) \
77}; \
78SYSINIT_ENTRY(uniq##_entry, "sysinit", (subs), \
79 (order), "const struct sysinit", \
80 UNIQ_NAME_STR(sysinit_##uniq), "SYSINIT")
81
82#define SYSUNINIT(uniq, subs, order, _func, _data) \
83const struct sysinit UNIQ_NAME(sysuninit_##uniq) = { \
84 .func = (_func), \
85 .data = __DECONST(void *, _data) \
86}; \
87SYSINIT_ENTRY(uniq##_entry, "sysuninit", (subs), \
88 (order), "const struct sysuninit", \
89 UNIQ_NAME_STR(sysuninit_##uniq), "SYSUNINIT")
90#define MODULE_DEPEND(...)
91#define MODULE_VERSION(...)
92#define NULL ((void *)0)
93#define BUS_SPACE_BARRIER_READ 0x01
94#define BUS_SPACE_BARRIER_WRITE 0x02
95#define hz 1000
96#define PAGE_SIZE 4096
97#define MIN(a,b) (((a) < (b)) ? (a) : (b))
98#define MAX(a,b) (((a) > (b)) ? (a) : (b))
99#define MTX_DEF 0
100#define MTX_SPIN 0
99#define MTX_RECURSE 0
100#define SX_DUPOK 0
101#define SX_NOWITNESS 0
102#define WITNESS_WARN(...)
103#define cold 0
104#define BUS_PROBE_GENERIC 0
105#define CALLOUT_RETURNUNLOCKED 0x1
106#define va_list __builtin_va_list
107#define va_size(type) __builtin_va_size(type)
108#define va_start(ap, last) __builtin_va_start(ap, last)
109#define va_end(ap) __builtin_va_end(ap)
110#define va_arg(ap, type) __builtin_va_arg((ap), type)
111#define DEVICE_ATTACH(dev, ...) \
112 (((device_attach_t *)(device_get_method(dev, "device_attach")))(dev,## __VA_ARGS__))
113#define DEVICE_DETACH(dev, ...) \
114 (((device_detach_t *)(device_get_method(dev, "device_detach")))(dev,## __VA_ARGS__))
115#define DEVICE_PROBE(dev, ...) \
116 (((device_probe_t *)(device_get_method(dev, "device_probe")))(dev,## __VA_ARGS__))
117#define DEVICE_RESUME(dev, ...) \
118 (((device_resume_t *)(device_get_method(dev, "device_resume")))(dev,## __VA_ARGS__))
119#define DEVICE_SHUTDOWN(dev, ...) \
120 (((device_shutdown_t *)(device_get_method(dev, "device_shutdown")))(dev,## __VA_ARGS__))
121#define DEVICE_SUSPEND(dev, ...) \
122 (((device_suspend_t *)(device_get_method(dev, "device_suspend")))(dev,## __VA_ARGS__))
123#define USB_HANDLE_REQUEST(dev, ...) \
124 (((usb_handle_request_t *)(device_get_method(dev, "usb_handle_request")))(dev,## __VA_ARGS__))
125#define USB_TAKE_CONTROLLER(dev, ...) \
126 (((usb_take_controller_t *)(device_get_method(dev, "usb_take_controller")))(dev,## __VA_ARGS__))
127
128enum {
129 SI_SUB_DUMMY = 0x0000000,
130 SI_SUB_LOCK = 0x1B00000,
131 SI_SUB_KLD = 0x2000000,
132 SI_SUB_DRIVERS = 0x3100000,
133 SI_SUB_PSEUDO = 0x7000000,
134 SI_SUB_KICK_SCHEDULER = 0xa000000,
135 SI_SUB_RUN_SCHEDULER = 0xfffffff
136};
137
138enum {
139 SI_ORDER_FIRST = 0x0000000,
140 SI_ORDER_SECOND = 0x0000001,
141 SI_ORDER_THIRD = 0x0000002,
142 SI_ORDER_FOURTH = 0x0000003,
143 SI_ORDER_MIDDLE = 0x1000000,
144 SI_ORDER_ANY = 0xfffffff /* last */
145};
146
147struct uio;
148struct thread;
149struct malloc_type;
150struct usb_process;
151
152typedef unsigned char uint8_t;
153typedef signed char int8_t;
154
155typedef unsigned short uint16_t;
156typedef signed short int16_t;
157
158typedef unsigned int uint32_t;
159typedef signed int int32_t;
160
161typedef unsigned long long uint64_t;
162typedef signed long long int64_t;
163
164typedef unsigned long bus_addr_t;
165typedef unsigned long bus_size_t;
166
167typedef unsigned long size_t;
168typedef unsigned long u_long;
169
170typedef void *bus_dmamap_t;
171typedef void *bus_dma_tag_t;
172
173typedef void *bus_space_tag_t;
174typedef uint8_t *bus_space_handle_t;
175
176typedef uint16_t uid_t;
177typedef uint16_t gid_t;
178typedef uint16_t mode_t;
179
180typedef uint8_t *caddr_t;
181typedef unsigned long __uintptr_t;
182typedef unsigned long uintptr_t;
183
184/* SYSINIT API */
185
186#include <sysinit.h>
187
188struct sysinit {
189 void (*func) (void *arg);
190 void *data;
191};
192
193/* MUTEX API */
194
195struct mtx {
196 int owned;
197 struct mtx *parent;
198};
199
200#define mtx_assert(...) do { } while (0)
201void mtx_init(struct mtx *, const char *, const char *, int);
202void mtx_lock(struct mtx *);
203void mtx_unlock(struct mtx *);
101#define MTX_RECURSE 0
102#define SX_DUPOK 0
103#define SX_NOWITNESS 0
104#define WITNESS_WARN(...)
105#define cold 0
106#define BUS_PROBE_GENERIC 0
107#define CALLOUT_RETURNUNLOCKED 0x1
108#define va_list __builtin_va_list
109#define va_size(type) __builtin_va_size(type)
110#define va_start(ap, last) __builtin_va_start(ap, last)
111#define va_end(ap) __builtin_va_end(ap)
112#define va_arg(ap, type) __builtin_va_arg((ap), type)
113#define DEVICE_ATTACH(dev, ...) \
114 (((device_attach_t *)(device_get_method(dev, "device_attach")))(dev,## __VA_ARGS__))
115#define DEVICE_DETACH(dev, ...) \
116 (((device_detach_t *)(device_get_method(dev, "device_detach")))(dev,## __VA_ARGS__))
117#define DEVICE_PROBE(dev, ...) \
118 (((device_probe_t *)(device_get_method(dev, "device_probe")))(dev,## __VA_ARGS__))
119#define DEVICE_RESUME(dev, ...) \
120 (((device_resume_t *)(device_get_method(dev, "device_resume")))(dev,## __VA_ARGS__))
121#define DEVICE_SHUTDOWN(dev, ...) \
122 (((device_shutdown_t *)(device_get_method(dev, "device_shutdown")))(dev,## __VA_ARGS__))
123#define DEVICE_SUSPEND(dev, ...) \
124 (((device_suspend_t *)(device_get_method(dev, "device_suspend")))(dev,## __VA_ARGS__))
125#define USB_HANDLE_REQUEST(dev, ...) \
126 (((usb_handle_request_t *)(device_get_method(dev, "usb_handle_request")))(dev,## __VA_ARGS__))
127#define USB_TAKE_CONTROLLER(dev, ...) \
128 (((usb_take_controller_t *)(device_get_method(dev, "usb_take_controller")))(dev,## __VA_ARGS__))
129
130enum {
131 SI_SUB_DUMMY = 0x0000000,
132 SI_SUB_LOCK = 0x1B00000,
133 SI_SUB_KLD = 0x2000000,
134 SI_SUB_DRIVERS = 0x3100000,
135 SI_SUB_PSEUDO = 0x7000000,
136 SI_SUB_KICK_SCHEDULER = 0xa000000,
137 SI_SUB_RUN_SCHEDULER = 0xfffffff
138};
139
140enum {
141 SI_ORDER_FIRST = 0x0000000,
142 SI_ORDER_SECOND = 0x0000001,
143 SI_ORDER_THIRD = 0x0000002,
144 SI_ORDER_FOURTH = 0x0000003,
145 SI_ORDER_MIDDLE = 0x1000000,
146 SI_ORDER_ANY = 0xfffffff /* last */
147};
148
149struct uio;
150struct thread;
151struct malloc_type;
152struct usb_process;
153
154typedef unsigned char uint8_t;
155typedef signed char int8_t;
156
157typedef unsigned short uint16_t;
158typedef signed short int16_t;
159
160typedef unsigned int uint32_t;
161typedef signed int int32_t;
162
163typedef unsigned long long uint64_t;
164typedef signed long long int64_t;
165
166typedef unsigned long bus_addr_t;
167typedef unsigned long bus_size_t;
168
169typedef unsigned long size_t;
170typedef unsigned long u_long;
171
172typedef void *bus_dmamap_t;
173typedef void *bus_dma_tag_t;
174
175typedef void *bus_space_tag_t;
176typedef uint8_t *bus_space_handle_t;
177
178typedef uint16_t uid_t;
179typedef uint16_t gid_t;
180typedef uint16_t mode_t;
181
182typedef uint8_t *caddr_t;
183typedef unsigned long __uintptr_t;
184typedef unsigned long uintptr_t;
185
186/* SYSINIT API */
187
188#include <sysinit.h>
189
190struct sysinit {
191 void (*func) (void *arg);
192 void *data;
193};
194
195/* MUTEX API */
196
197struct mtx {
198 int owned;
199 struct mtx *parent;
200};
201
202#define mtx_assert(...) do { } while (0)
203void mtx_init(struct mtx *, const char *, const char *, int);
204void mtx_lock(struct mtx *);
205void mtx_unlock(struct mtx *);
206#define mtx_lock_spin(x) mtx_lock(x)
207#define mtx_unlock_spin(x) mtx_unlock(x)
204int mtx_owned(struct mtx *);
205void mtx_destroy(struct mtx *);
206
207extern struct mtx Giant;
208
209/* SX API */
210
211struct sx {
212 int owned;
213};
214
215#define sx_assert(...) do { } while (0)
216#define sx_init(...) sx_init_flags(__VA_ARGS__, 0)
217void sx_init_flags(struct sx *, const char *, int);
218void sx_destroy(struct sx *);
219void sx_xlock(struct sx *);
220void sx_xunlock(struct sx *);
221int sx_xlocked(struct sx *);
222
223/* CONDVAR API */
224
225struct cv {
226 int sleeping;
227};
228
229void cv_init(struct cv *, const char *desc);
230void cv_destroy(struct cv *);
231void cv_wait(struct cv *, struct mtx *);
232int cv_timedwait(struct cv *, struct mtx *, int);
233void cv_signal(struct cv *);
234void cv_broadcast(struct cv *);
235
236/* CALLOUT API */
237
238typedef void callout_fn_t (void *);
239
240extern volatile int ticks;
241
242struct callout {
243 LIST_ENTRY(callout) entry;
244 callout_fn_t *func;
245 void *arg;
246 struct mtx *mtx;
247 int flags;
248 int timeout;
249};
250
251void callout_init_mtx(struct callout *, struct mtx *, int);
252void callout_reset(struct callout *, int, callout_fn_t *, void *);
253void callout_stop(struct callout *);
254void callout_drain(struct callout *);
255int callout_pending(struct callout *);
256void callout_process(int timeout);
257
258/* DEVICE API */
259
260struct driver;
261struct devclass;
262struct device;
263struct module;
264struct module_data;
265
266typedef struct driver driver_t;
267typedef struct devclass *devclass_t;
268typedef struct device *device_t;
208int mtx_owned(struct mtx *);
209void mtx_destroy(struct mtx *);
210
211extern struct mtx Giant;
212
213/* SX API */
214
215struct sx {
216 int owned;
217};
218
219#define sx_assert(...) do { } while (0)
220#define sx_init(...) sx_init_flags(__VA_ARGS__, 0)
221void sx_init_flags(struct sx *, const char *, int);
222void sx_destroy(struct sx *);
223void sx_xlock(struct sx *);
224void sx_xunlock(struct sx *);
225int sx_xlocked(struct sx *);
226
227/* CONDVAR API */
228
229struct cv {
230 int sleeping;
231};
232
233void cv_init(struct cv *, const char *desc);
234void cv_destroy(struct cv *);
235void cv_wait(struct cv *, struct mtx *);
236int cv_timedwait(struct cv *, struct mtx *, int);
237void cv_signal(struct cv *);
238void cv_broadcast(struct cv *);
239
240/* CALLOUT API */
241
242typedef void callout_fn_t (void *);
243
244extern volatile int ticks;
245
246struct callout {
247 LIST_ENTRY(callout) entry;
248 callout_fn_t *func;
249 void *arg;
250 struct mtx *mtx;
251 int flags;
252 int timeout;
253};
254
255void callout_init_mtx(struct callout *, struct mtx *, int);
256void callout_reset(struct callout *, int, callout_fn_t *, void *);
257void callout_stop(struct callout *);
258void callout_drain(struct callout *);
259int callout_pending(struct callout *);
260void callout_process(int timeout);
261
262/* DEVICE API */
263
264struct driver;
265struct devclass;
266struct device;
267struct module;
268struct module_data;
269
270typedef struct driver driver_t;
271typedef struct devclass *devclass_t;
272typedef struct device *device_t;
269typedef void (intr_fn_t)(void *arg);
273typedef void (driver_intr_t)(void *arg);
274typedef int (driver_filter_t)(void *arg);
275#define FILTER_STRAY 0x01
276#define FILTER_HANDLED 0x02
277#define FILTER_SCHEDULE_THREAD 0x04
270
271typedef int device_attach_t (device_t dev);
272typedef int device_detach_t (device_t dev);
273typedef int device_resume_t (device_t dev);
274typedef int device_shutdown_t (device_t dev);
275typedef int device_probe_t (device_t dev);
276typedef int device_suspend_t (device_t dev);
277
278typedef int bus_child_location_str_t (device_t parent, device_t child, char *buf, size_t buflen);
279typedef int bus_child_pnpinfo_str_t (device_t parent, device_t child, char *buf, size_t buflen);
280typedef void bus_driver_added_t (device_t dev, driver_t *driver);
281
282struct device_method {
283 const char *desc;
284 void *const func;
285};
286
287typedef struct device_method device_method_t;
288
289struct device {
290 TAILQ_HEAD(device_list, device) dev_children;
291 TAILQ_ENTRY(device) dev_link;
292
293 struct device *dev_parent;
294 const struct module_data *dev_module;
295 void *dev_sc;
296 void *dev_aux;
278
279typedef int device_attach_t (device_t dev);
280typedef int device_detach_t (device_t dev);
281typedef int device_resume_t (device_t dev);
282typedef int device_shutdown_t (device_t dev);
283typedef int device_probe_t (device_t dev);
284typedef int device_suspend_t (device_t dev);
285
286typedef int bus_child_location_str_t (device_t parent, device_t child, char *buf, size_t buflen);
287typedef int bus_child_pnpinfo_str_t (device_t parent, device_t child, char *buf, size_t buflen);
288typedef void bus_driver_added_t (device_t dev, driver_t *driver);
289
290struct device_method {
291 const char *desc;
292 void *const func;
293};
294
295typedef struct device_method device_method_t;
296
297struct device {
298 TAILQ_HEAD(device_list, device) dev_children;
299 TAILQ_ENTRY(device) dev_link;
300
301 struct device *dev_parent;
302 const struct module_data *dev_module;
303 void *dev_sc;
304 void *dev_aux;
297 intr_fn_t *dev_irq_fn;
305 driver_filter_t *dev_irq_filter;
306 driver_intr_t *dev_irq_fn;
298 void *dev_irq_arg;
299
300 uint16_t dev_unit;
301
302 char dev_nameunit[64];
303 char dev_desc[64];
304
305 uint8_t dev_res_alloc:1;
306 uint8_t dev_quiet:1;
307 uint8_t dev_softc_set:1;
308 uint8_t dev_softc_alloc:1;
309 uint8_t dev_attached:1;
310 uint8_t dev_fixed_class:1;
311 uint8_t dev_unit_manual:1;
312};
313
314struct devclass {
315 device_t dev_list[DEVCLASS_MAXUNIT];
316};
317
318struct driver {
319 const char *name;
320 const struct device_method *methods;
321 uint32_t size;
322};
323
324struct module_data {
325 int (*callback) (struct module *, int, void *arg);
326 void *arg;
327 const char *bus_name;
328 const char *mod_name;
329 const char *long_name;
330 const struct driver *driver;
331 struct devclass **devclass_pp;
332 TAILQ_ENTRY(module_data) entry;
333};
334
335device_t device_get_parent(device_t dev);
336void *device_get_method(device_t dev, const char *what);
337const char *device_get_name(device_t dev);
338const char *device_get_nameunit(device_t dev);
339
340#define device_printf(dev, fmt,...) \
341 printf("%s: " fmt, device_get_nameunit(dev),## __VA_ARGS__)
342device_t device_add_child(device_t dev, const char *name, int unit);
343void device_quiet(device_t dev);
307 void *dev_irq_arg;
308
309 uint16_t dev_unit;
310
311 char dev_nameunit[64];
312 char dev_desc[64];
313
314 uint8_t dev_res_alloc:1;
315 uint8_t dev_quiet:1;
316 uint8_t dev_softc_set:1;
317 uint8_t dev_softc_alloc:1;
318 uint8_t dev_attached:1;
319 uint8_t dev_fixed_class:1;
320 uint8_t dev_unit_manual:1;
321};
322
323struct devclass {
324 device_t dev_list[DEVCLASS_MAXUNIT];
325};
326
327struct driver {
328 const char *name;
329 const struct device_method *methods;
330 uint32_t size;
331};
332
333struct module_data {
334 int (*callback) (struct module *, int, void *arg);
335 void *arg;
336 const char *bus_name;
337 const char *mod_name;
338 const char *long_name;
339 const struct driver *driver;
340 struct devclass **devclass_pp;
341 TAILQ_ENTRY(module_data) entry;
342};
343
344device_t device_get_parent(device_t dev);
345void *device_get_method(device_t dev, const char *what);
346const char *device_get_name(device_t dev);
347const char *device_get_nameunit(device_t dev);
348
349#define device_printf(dev, fmt,...) \
350 printf("%s: " fmt, device_get_nameunit(dev),## __VA_ARGS__)
351device_t device_add_child(device_t dev, const char *name, int unit);
352void device_quiet(device_t dev);
344void device_set_interrupt(device_t dev, intr_fn_t *fn, void *arg);
353void device_set_interrupt(device_t dev, driver_filter_t *, driver_intr_t *, void *);
345void device_run_interrupts(device_t parent);
346void device_set_ivars(device_t dev, void *ivars);
347void *device_get_ivars(device_t dev);
348const char *device_get_desc(device_t dev);
349int device_probe_and_attach(device_t dev);
350int device_detach(device_t dev);
351void *device_get_softc(device_t dev);
352void device_set_softc(device_t dev, void *softc);
353int device_delete_child(device_t dev, device_t child);
354int device_delete_children(device_t dev);
355int device_is_attached(device_t dev);
356void device_set_desc(device_t dev, const char *desc);
357void device_set_desc_copy(device_t dev, const char *desc);
358int device_get_unit(device_t dev);
359void *devclass_get_softc(devclass_t dc, int unit);
360int devclass_get_maxunit(devclass_t dc);
361device_t devclass_get_device(devclass_t dc, int unit);
362devclass_t devclass_find(const char *classname);
363
364#define bus_get_dma_tag(...) (NULL)
365int bus_generic_detach(device_t dev);
366int bus_generic_resume(device_t dev);
367int bus_generic_shutdown(device_t dev);
368int bus_generic_suspend(device_t dev);
369int bus_generic_print_child(device_t dev, device_t child);
370void bus_generic_driver_added(device_t dev, driver_t *driver);
371
372/* BUS SPACE API */
373
374void bus_space_write_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint8_t data);
375void bus_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint16_t data);
376void bus_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint32_t data);
377
378uint8_t bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset);
379uint16_t bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset);
380uint32_t bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset);
381
382void 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);
383void 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);
384void 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);
385
386void 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);
387void 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);
388void 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);
389
390void 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);
391void 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);
392void 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);
393void 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);
394
395void bus_space_barrier(bus_space_tag_t space, bus_space_handle_t handle, bus_size_t offset, bus_size_t length, int flags);
396
397void module_register(void *);
398
399/* LIB-C */
400
401void *memset(void *, int, size_t len);
402void *memcpy(void *, const void *, size_t len);
403int printf(const char *,...) __printflike(1, 2);
404int snprintf(char *restrict str, size_t size, const char *restrict format,...) __printflike(3, 4);
405size_t strlen(const char *s);
406
407/* MALLOC API */
408
409#define malloc(s,x,f) usb_malloc(s)
410void *usb_malloc(size_t);
411
412#define free(p,x) usb_free(p)
413void usb_free(void *);
414
415#define strdup(p,x) usb_strdup(p)
416char *usb_strdup(const char *str);
417
418/* ENDIANNESS */
419
420/* Assume little endian */
421
422#define htole64(x) ((uint64_t)(x))
423#define le64toh(x) ((uint64_t)(x))
424
425#define htole32(x) ((uint32_t)(x))
426#define le32toh(x) ((uint32_t)(x))
427
428#define htole16(x) ((uint16_t)(x))
429#define le16toh(x) ((uint16_t)(x))
430
431#define be32toh(x) ((uint32_t)(x))
432#define htobe32(x) ((uint32_t)(x))
433
434/* USB */
435
436typedef int usb_handle_request_t (device_t dev, const void *req, void **pptr, uint16_t *plen, uint16_t offset, uint8_t *pstate);
437typedef int usb_take_controller_t (device_t dev);
438
439void usb_idle(void);
440void usb_init(void);
441void usb_uninit(void);
442
443/* set some defaults */
444
445#ifndef USB_POOL_SIZE
446#define USB_POOL_SIZE (1024*1024) /* 1 MByte */
447#endif
448
449int pause(const char *, int);
450void DELAY(unsigned int);
451
452/* OTHER */
453
454struct selinfo {
455};
456
457/* SYSTEM STARTUP API */
458
459extern const void *sysinit_data[];
460extern const void *sysuninit_data[];
461
462#endif /* _BSD_KERNEL_H_ */
354void device_run_interrupts(device_t parent);
355void device_set_ivars(device_t dev, void *ivars);
356void *device_get_ivars(device_t dev);
357const char *device_get_desc(device_t dev);
358int device_probe_and_attach(device_t dev);
359int device_detach(device_t dev);
360void *device_get_softc(device_t dev);
361void device_set_softc(device_t dev, void *softc);
362int device_delete_child(device_t dev, device_t child);
363int device_delete_children(device_t dev);
364int device_is_attached(device_t dev);
365void device_set_desc(device_t dev, const char *desc);
366void device_set_desc_copy(device_t dev, const char *desc);
367int device_get_unit(device_t dev);
368void *devclass_get_softc(devclass_t dc, int unit);
369int devclass_get_maxunit(devclass_t dc);
370device_t devclass_get_device(devclass_t dc, int unit);
371devclass_t devclass_find(const char *classname);
372
373#define bus_get_dma_tag(...) (NULL)
374int bus_generic_detach(device_t dev);
375int bus_generic_resume(device_t dev);
376int bus_generic_shutdown(device_t dev);
377int bus_generic_suspend(device_t dev);
378int bus_generic_print_child(device_t dev, device_t child);
379void bus_generic_driver_added(device_t dev, driver_t *driver);
380
381/* BUS SPACE API */
382
383void bus_space_write_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint8_t data);
384void bus_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint16_t data);
385void bus_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, uint32_t data);
386
387uint8_t bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset);
388uint16_t bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset);
389uint32_t bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset);
390
391void 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);
392void 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);
393void 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);
394
395void 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);
396void 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);
397void 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);
398
399void 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);
400void 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);
401void 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);
402void 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);
403
404void bus_space_barrier(bus_space_tag_t space, bus_space_handle_t handle, bus_size_t offset, bus_size_t length, int flags);
405
406void module_register(void *);
407
408/* LIB-C */
409
410void *memset(void *, int, size_t len);
411void *memcpy(void *, const void *, size_t len);
412int printf(const char *,...) __printflike(1, 2);
413int snprintf(char *restrict str, size_t size, const char *restrict format,...) __printflike(3, 4);
414size_t strlen(const char *s);
415
416/* MALLOC API */
417
418#define malloc(s,x,f) usb_malloc(s)
419void *usb_malloc(size_t);
420
421#define free(p,x) usb_free(p)
422void usb_free(void *);
423
424#define strdup(p,x) usb_strdup(p)
425char *usb_strdup(const char *str);
426
427/* ENDIANNESS */
428
429/* Assume little endian */
430
431#define htole64(x) ((uint64_t)(x))
432#define le64toh(x) ((uint64_t)(x))
433
434#define htole32(x) ((uint32_t)(x))
435#define le32toh(x) ((uint32_t)(x))
436
437#define htole16(x) ((uint16_t)(x))
438#define le16toh(x) ((uint16_t)(x))
439
440#define be32toh(x) ((uint32_t)(x))
441#define htobe32(x) ((uint32_t)(x))
442
443/* USB */
444
445typedef int usb_handle_request_t (device_t dev, const void *req, void **pptr, uint16_t *plen, uint16_t offset, uint8_t *pstate);
446typedef int usb_take_controller_t (device_t dev);
447
448void usb_idle(void);
449void usb_init(void);
450void usb_uninit(void);
451
452/* set some defaults */
453
454#ifndef USB_POOL_SIZE
455#define USB_POOL_SIZE (1024*1024) /* 1 MByte */
456#endif
457
458int pause(const char *, int);
459void DELAY(unsigned int);
460
461/* OTHER */
462
463struct selinfo {
464};
465
466/* SYSTEM STARTUP API */
467
468extern const void *sysinit_data[];
469extern const void *sysuninit_data[];
470
471#endif /* _BSD_KERNEL_H_ */