[BACK]Return to driver.h CVS log [TXT][DIR] Up to [local] / prex-old / dev / include

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

CVSweb