Annotation of prex-old/dev/include/driver.h, Revision 1.2
1.1 nbrk 1: /*
2: * Copyright (c) 2005-2007, Kohsuke Ohtani
3: * 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: * 3. Neither the name of the author nor the names of any co-contributors
14: * may be used to endorse or promote products derived from this software
15: * without specific prior written permission.
16: *
17: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27: * SUCH DAMAGE.
28: */
29:
30: /*
31: * driver.h - Kernel Interface for device driver
32: */
33:
34: #ifndef _DRIVER_H
35: #define _DRIVER_H
36:
37: #include <conf/config.h>
38: #include <sys/cdefs.h>
39: #include <sys/param.h>
40: #include <sys/null.h>
41: #include <sys/types.h>
42: #include <sys/errno.h>
43: #include <sys/list.h>
44: #include <prex/bootinfo.h>
45: #include <queue.h>
46: #include <drvlib.h>
47:
48: /*
49: * Kernel types
50: */
51: typedef unsigned long device_t;
52: typedef unsigned long task_t;
53:
54: #define NULL_DEVICE ((device_t)0)
55: #define NULL_TASK ((task_t)0)
56:
1.2 ! nbrk 57: #ifndef CONFIG_AUTOCONF
! 58:
! 59:
1.1 nbrk 60: /*
61: * Driver structure
62: *
63: * "order" is initialize order which must be between 0 and 15.
64: * The driver with order 0 is called first.
65: */
66: struct driver {
67: const char *name; /* Name of device driver */
68: const int order; /* Initialize order */
69: int (*init)(void); /* Initialize routine */
70: };
1.2 ! nbrk 71: #else /* CONFIG_AUTOCONF */
! 72:
! 73: #define CONFIG_XNAMELEN 16 /* maximum name for device (name+unit) */
! 74:
! 75: /*
! 76: * Generic information that is held for every attached device.
! 77: */
! 78: struct device {
! 79: void *dv_data; /* private data */
! 80: int dv_unit; /* unit number (starting from 0) */
! 81: char *dv_xname; /* name */
! 82: unsigned long dv_flags;
! 83:
! 84: struct device *dv_parent; /* parent device */
! 85: };
! 86:
! 87: /*
! 88: * Data structure that describes device driver.
! 89: */
! 90: struct driver {
! 91: char *dr_name; /* abstract name for a device */
! 92: int dr_datasize;/* sizeof private data structure */
! 93:
! 94: int (*dr_match)(struct device *parent, void *aux);
! 95: int (*dr_attach)(struct device *parent, struct device *self, void *aux);
! 96: int (*dr_detach)(struct device *parent, struct device *self, void *aux);
! 97: /* XXX dr_search() ? */
! 98: int dr_nunits; /* number of attached units */
! 99: };
! 100:
! 101: /*
! 102: * Autoconf prototypes.
! 103: */
! 104: void config_attach_rootdev(void);
! 105: int config_search_children(struct device *self, void *aux);
! 106: struct driver *config_find_driver(const char *name);
! 107: struct device *config_alloc_device(struct driver *drv);
! 108: void config_free_device(struct device *dev);
! 109:
! 110: /*
! 111: * Attachment information.
! 112: */
! 113: struct attachment {
! 114: const char *at_childname;
! 115: const char *at_parentname;
! 116: const int at_parentunit; /* -1 for ALL */
! 117: const char *at_helpername;
! 118: const unsigned long at_flags;
! 119: };
! 120:
! 121: #endif /* !CONFIG_AUTOCONF */
1.1 nbrk 122:
123: /*
124: * Device I/O table
125: */
126: struct devio {
127: int (*open) (device_t dev, int mode);
128: int (*close) (device_t dev);
129: int (*read) (device_t dev, char *buf, size_t *nbyte, int blkno);
130: int (*write) (device_t dev, char *buf, size_t *nbyte, int blkno);
131: int (*ioctl) (device_t dev, int cmd, u_long arg);
132: int (*event) (int event);
133: };
134:
135: /*
136: * Flags for device_create()
137: */
138: #define DF_CHR 0x00000001 /* Character device */
139: #define DF_BLK 0x00000002 /* Block device */
140: #define DF_RDONLY 0x00000004 /* Read only device */
141: #define DF_REM 0x00000008 /* Removable device */
142:
143: /*
144: * Device open mode
145: */
146: #define DO_RDONLY 0x0
147: #define DO_WRONLY 0x1
148: #define DO_RDWR 0x2
149: #define DO_RWMASK 0x3
150:
151: /*
152: * Return value of ISR
153: */
154: #define INT_DONE 0
155: #define INT_ERROR 1
156: #define INT_CONTINUE 2
157:
158: /*
159: * Interrupt priority levels
160: */
161: #define IPL_NONE 0 /* Nothing */
162: #define IPL_COMM 1 /* Serial, Parallel */
163: #define IPL_BLOCK 2 /* FDD, IDE */
164: #define IPL_NET 3 /* Network */
165: #define IPL_DISPLAY 4 /* Screen */
166: #define IPL_INPUT 5 /* Keyboard, Mouse */
167: #define IPL_AUDIO 6 /* Audio */
168: #define IPL_BUS 7 /* USB, PCCARD */
169: #define IPL_RTC 8 /* RTC Alarm */
170: #define IPL_PROFILE 9 /* Profiling timer */
171: #define IPL_CLOCK 10 /* System Clock Timer */
172: #define IPL_HIGH 11 /* Everything */
173:
174: #define NIPL 12
175:
176: /*
177: * Event for sleep/wakeup
178: */
179: struct event {
180: struct queue sleepq; /* queue for waiting thread */
181: const char *name; /* pointer to event name string */
182: };
183:
184: #define EVENT_INIT(event, evt_name) \
185: { {&(event).sleepq, &(event).sleepq}, evt_name}
186:
187: #define event_init(event, evt_name) \
188: do { list_init(&(event)->sleepq); (event)->name = evt_name; } while (0)
189:
190: /*
191: * Sleep result
192: */
193: #define SLP_SUCCESS 0
194: #define SLP_BREAK 1
195: #define SLP_TIMEOUT 2
196: #define SLP_INVAL 3
197: #define SLP_INTR 4
198:
199: /*
200: * DPC (Deferred Procedure Call) object
201: */
202: struct dpc {
203: struct queue link; /* Linkage on DPC queue */
204: int state;
205: void (*func)(void *); /* Call back routine */
206: void *arg; /* Argument to pass */
207: };
208:
209: /*
210: * Macro to convert milliseconds and tick.
211: */
212: #define msec_to_tick(ms) (((ms) >= 0x20000) ? \
213: ((ms) / 1000UL) * HZ : \
214: ((ms) * HZ) / 1000UL)
215:
216: #define tick_to_msec(tick) (((tick) * 1000) / HZ)
217:
218: /*
219: * Timer structure
220: */
221: struct timer {
222: struct list link; /* Linkage on timer chain */
223: int active; /* True if active */
224: u_long expire; /* Expire time (ticks) */
225: u_long interval; /* Time interval */
226: void (*func)(void *); /* Function to call */
227: void *arg; /* Function argument */
228: struct event event; /* Event for this timer */
229: };
230:
231: #define timer_init(tmr) (tmr)->expire = 0;
232:
233: /*
234: * Items for debug_dump()
235: */
236: #define DUMP_THREAD 1
237: #define DUMP_TASK 2
238: #define DUMP_OBJECT 3
239: #define DUMP_TIMER 4
240: #define DUMP_IRQ 5
241: #define DUMP_DEVICE 6
242: #define DUMP_VM 7
243: #define DUMP_MSGLOG 8
244: #define DUMP_TRACE 9
245:
246: __BEGIN_DECLS
247: device_t device_create(struct devio *io, const char *name, int flags);
248: int device_destroy(device_t dev);
249: int device_broadcast(int event, int force);
250:
251: int umem_copyin(void *uaddr, void *kaddr, size_t len);
252: int umem_copyout(void *kaddr, void *uaddr, size_t len);
253: int umem_strnlen(const char *uaddr, size_t maxlen, size_t *len);
254:
255: void *kmem_alloc(size_t size);
256: void kmem_free(void *ptr);
257: void *kmem_map(void *addr, size_t size);
258:
259: void *page_alloc(size_t size);
260: void page_free(void *addr, size_t size);
261: int page_reserve(void *addr, size_t size);
262:
263: int irq_attach(int irqno, int level, int shared, int (*isr)(int), void (*ist)(int));
264: void irq_detach(int handle);
265: void irq_lock(void);
266: void irq_unlock(void);
267:
268: void timer_callout(struct timer *tmr, void (*func)(u_long), u_long arg, u_long msec);
269: void timer_stop(struct timer *tmr);
270: u_long timer_delay(u_long msec);
271: u_long timer_count(void);
272: int timer_hook(void (*func)(int));
273:
274: void sched_lock(void);
275: void sched_unlock(void);
276: int sched_tsleep(struct event *evt, u_long timeout);
277: void sched_wakeup(struct event *evt);
278: void sched_dpc(struct dpc *dpc, void (*func)(void *), void *arg);
279: #define sched_sleep(event) sched_tsleep((event), 0)
280:
281: int exception_post(task_t task, int exc);
282: int task_capable(int cap);
283:
284: void *phys_to_virt(void *p_addr);
285: void *virt_to_phys(void *v_addr);
286:
287: void machine_reset(void);
288: void machine_idle(void);
289: void machine_bootinfo(struct boot_info **);
290:
291: void debug_attach(void (*func)(char *));
292: int debug_dump(int index);
293:
294: #ifdef DEBUG
295: void printk(const char *fmt, ...);
296: void panic(const char *fmt, ...);
297: void assert(const char *file, int line, const char *exp);
298: #define ASSERT(exp) do { if (!(exp)) \
299: assert(__FILE__, __LINE__, #exp); } while (0)
300: #else
301: #define printk(fmt...) do {} while (0)
302: #define panic(fmt...) do { for (;;) ; } while (0)
303: #define ASSERT(exp)
304: #endif
305: __END_DECLS
306:
307: #endif /* !_DRIVER_H */
CVSweb