Annotation of prex/dev/include/driver.h, Revision 1.1
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/types.h>
! 41: #include <sys/errno.h>
! 42: #include <sys/list.h>
! 43: #include <prex/bootinfo.h>
! 44: #include <queue.h>
! 45: #include <drvlib.h>
! 46:
! 47: /*
! 48: * Kernel types
! 49: */
! 50: typedef unsigned long device_t;
! 51: typedef unsigned long task_t;
! 52: typedef unsigned long irq_t;
! 53:
! 54: #define DEVICE_NULL ((device_t)0)
! 55: #define TASK_NULL ((task_t)0)
! 56: #define IRQ_NULL ((irq_t)0)
! 57:
! 58: /*
! 59: * Driver structure
! 60: *
! 61: * "order" is initialize order which must be between 0 and 15.
! 62: * The driver with order 0 is called first.
! 63: */
! 64: struct driver {
! 65: const char *name; /* Name of device driver */
! 66: const int order; /* Initialize order */
! 67: int (*init)(void); /* Initialize routine */
! 68: };
! 69:
! 70: /*
! 71: * Device I/O table
! 72: */
! 73: struct devio {
! 74: int (*open) (device_t dev, int mode);
! 75: int (*close) (device_t dev);
! 76: int (*read) (device_t dev, char *buf, size_t *nbyte, int blkno);
! 77: int (*write) (device_t dev, char *buf, size_t *nbyte, int blkno);
! 78: int (*ioctl) (device_t dev, u_long arg, void *);
! 79: int (*event) (int event);
! 80: };
! 81:
! 82: /*
! 83: * Flags for device_create()
! 84: */
! 85: #define DF_CHR 0x00000001 /* Character device */
! 86: #define DF_BLK 0x00000002 /* Block device */
! 87: #define DF_RDONLY 0x00000004 /* Read only device */
! 88: #define DF_REM 0x00000008 /* Removable device */
! 89:
! 90: /*
! 91: * Device open mode
! 92: */
! 93: #define DO_RDONLY 0x0
! 94: #define DO_WRONLY 0x1
! 95: #define DO_RDWR 0x2
! 96: #define DO_RWMASK 0x3
! 97:
! 98: /*
! 99: * Return value of ISR
! 100: */
! 101: #define INT_DONE 0
! 102: #define INT_ERROR 1
! 103: #define INT_CONTINUE 2
! 104:
! 105: /*
! 106: * Interrupt priority levels
! 107: */
! 108: #define IPL_NONE 0 /* Nothing */
! 109: #define IPL_COMM 1 /* Serial, Parallel */
! 110: #define IPL_BLOCK 2 /* FDD, IDE */
! 111: #define IPL_NET 3 /* Network */
! 112: #define IPL_DISPLAY 4 /* Screen */
! 113: #define IPL_INPUT 5 /* Keyboard, Mouse */
! 114: #define IPL_AUDIO 6 /* Audio */
! 115: #define IPL_BUS 7 /* USB, PCCARD */
! 116: #define IPL_RTC 8 /* RTC Alarm */
! 117: #define IPL_PROFILE 9 /* Profiling timer */
! 118: #define IPL_CLOCK 10 /* System Clock Timer */
! 119: #define IPL_HIGH 11 /* Everything */
! 120:
! 121: #define NIPL 12
! 122:
! 123: /*
! 124: * Event for sleep/wakeup
! 125: */
! 126: struct event {
! 127: struct queue sleepq; /* queue for waiting thread */
! 128: const char *name; /* pointer to event name string */
! 129: };
! 130:
! 131: #define event_init(event, evt_name) \
! 132: do { list_init(&(event)->sleepq); (event)->name = evt_name; } while (0)
! 133:
! 134: /*
! 135: * Sleep result
! 136: */
! 137: #define SLP_SUCCESS 0
! 138: #define SLP_BREAK 1
! 139: #define SLP_TIMEOUT 2
! 140: #define SLP_INVAL 3
! 141: #define SLP_INTR 4
! 142:
! 143: /*
! 144: * DPC (Deferred Procedure Call) object
! 145: */
! 146: struct dpc {
! 147: struct queue link; /* Linkage on DPC queue */
! 148: int state;
! 149: void (*func)(void *); /* Call back routine */
! 150: void *arg; /* Argument to pass */
! 151: };
! 152:
! 153: /*
! 154: * Macro to convert milliseconds and tick.
! 155: */
! 156: #define msec_to_tick(ms) (((ms) >= 0x20000) ? \
! 157: ((ms) / 1000UL) * HZ : \
! 158: ((ms) * HZ) / 1000UL)
! 159:
! 160: #define tick_to_msec(tick) (((tick) * 1000) / HZ)
! 161:
! 162: /*
! 163: * Timer structure
! 164: */
! 165: struct timer {
! 166: struct list link; /* Linkage on timer chain */
! 167: int active; /* True if active */
! 168: u_long expire; /* Expire time (ticks) */
! 169: u_long interval; /* Time interval */
! 170: void (*func)(void *); /* Function to call */
! 171: void *arg; /* Function argument */
! 172: struct event event; /* Event for this timer */
! 173: };
! 174:
! 175: #define timer_init(tmr) (tmr)->expire = 0;
! 176:
! 177: /*
! 178: * Items for debug_dump()
! 179: */
! 180: #define DUMP_THREAD 1
! 181: #define DUMP_TASK 2
! 182: #define DUMP_VM 3
! 183:
! 184: __BEGIN_DECLS
! 185: device_t device_create(struct devio *io, const char *name, int flags);
! 186: int device_destroy(device_t dev);
! 187: int device_broadcast(int event, int force);
! 188:
! 189: int umem_copyin(const void *uaddr, void *kaddr, size_t len);
! 190: int umem_copyout(const void *kaddr, void *uaddr, size_t len);
! 191: int umem_strnlen(const char *uaddr, size_t maxlen, size_t *len);
! 192:
! 193: void *kmem_alloc(size_t size);
! 194: void kmem_free(void *ptr);
! 195: void *kmem_map(void *addr, size_t size);
! 196:
! 197: void *page_alloc(size_t size);
! 198: void page_free(void *paddr, size_t size);
! 199: int page_reserve(void *paddr, size_t size);
! 200:
! 201: irq_t irq_attach(int irqno, int level, int shared, int (*isr)(int), void (*ist)(int));
! 202: void irq_detach(irq_t irq);
! 203: void irq_lock(void);
! 204: void irq_unlock(void);
! 205:
! 206: void timer_callout(struct timer *tmr, u_long msec, void (*func)(void *), void *arg);
! 207: void timer_stop(struct timer *tmr);
! 208: u_long timer_delay(u_long msec);
! 209: u_long timer_count(void);
! 210: int timer_hook(void (*func)(int));
! 211:
! 212: void sched_lock(void);
! 213: void sched_unlock(void);
! 214: int sched_tsleep(struct event *evt, u_long timeout);
! 215: void sched_wakeup(struct event *evt);
! 216: void sched_dpc(struct dpc *dpc, void (*func)(void *), void *arg);
! 217: #define sched_sleep(event) sched_tsleep((event), 0)
! 218:
! 219: int exception_post(task_t task, int exc);
! 220: int task_capable(int cap);
! 221:
! 222: void *phys_to_virt(void *p_addr);
! 223: void *virt_to_phys(void *v_addr);
! 224:
! 225: void machine_reset(void);
! 226: void machine_idle(void);
! 227: void machine_bootinfo(struct boot_info **);
! 228:
! 229: void debug_attach(void (*func)(char *));
! 230: int debug_dump(int index);
! 231:
! 232: void printf(const char *fmt, ...);
! 233: void panic(const char *msg);
! 234: #ifdef DEBUG
! 235: void assert(const char *file, int line, const char *exp);
! 236: #define ASSERT(exp) do { if (!(exp)) \
! 237: assert(__FILE__, __LINE__, #exp); } while (0)
! 238: #else
! 239: #define ASSERT(exp) do {} while (0)
! 240: #endif
! 241:
! 242: void driver_main(void);
! 243: __END_DECLS
! 244:
! 245: #endif /* !_DRIVER_H */
CVSweb