=================================================================== RCS file: /cvs/prex-old/dev/include/driver.h,v retrieving revision 1.1.1.1.2.1 retrieving revision 1.2 diff -u -r1.1.1.1.2.1 -r1.2 --- prex-old/dev/include/driver.h 2008/08/13 17:12:24 1.1.1.1.2.1 +++ prex-old/dev/include/driver.h 2008/08/08 13:37:11 1.2 @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -49,12 +50,13 @@ */ typedef unsigned long device_t; typedef unsigned long task_t; -typedef unsigned long irq_t; -#define DEVICE_NULL ((device_t)0) -#define TASK_NULL ((task_t)0) -#define IRQ_NULL ((irq_t)0) +#define NULL_DEVICE ((device_t)0) +#define NULL_TASK ((task_t)0) +#ifndef CONFIG_AUTOCONF + + /* * Driver structure * @@ -66,8 +68,59 @@ const int order; /* Initialize order */ int (*init)(void); /* Initialize routine */ }; +#else /* CONFIG_AUTOCONF */ +#define CONFIG_XNAMELEN 16 /* maximum name for device (name+unit) */ + /* + * Generic information that is held for every attached device. + */ +struct device { + void *dv_data; /* private data */ + int dv_unit; /* unit number (starting from 0) */ + char *dv_xname; /* name */ + unsigned long dv_flags; + + struct device *dv_parent; /* parent device */ +}; + +/* + * Data structure that describes device driver. + */ +struct driver { + char *dr_name; /* abstract name for a device */ + int dr_datasize;/* sizeof private data structure */ + + int (*dr_match)(struct device *parent, void *aux); + int (*dr_attach)(struct device *parent, struct device *self, void *aux); + int (*dr_detach)(struct device *parent, struct device *self, void *aux); + /* XXX dr_search() ? */ + int dr_nunits; /* number of attached units */ +}; + +/* + * Autoconf prototypes. + */ +void config_attach_rootdev(void); +int config_search_children(struct device *self, void *aux); +struct driver *config_find_driver(const char *name); +struct device *config_alloc_device(struct driver *drv); +void config_free_device(struct device *dev); + +/* + * Attachment information. + */ +struct attachment { + const char *at_childname; + const char *at_parentname; + const int at_parentunit; /* -1 for ALL */ + const char *at_helpername; + const unsigned long at_flags; +}; + +#endif /* !CONFIG_AUTOCONF */ + +/* * Device I/O table */ struct devio { @@ -75,7 +128,7 @@ int (*close) (device_t dev); int (*read) (device_t dev, char *buf, size_t *nbyte, int blkno); int (*write) (device_t dev, char *buf, size_t *nbyte, int blkno); - int (*ioctl) (device_t dev, u_long arg, void *); + int (*ioctl) (device_t dev, int cmd, u_long arg); int (*event) (int event); }; @@ -128,6 +181,9 @@ const char *name; /* pointer to event name string */ }; +#define EVENT_INIT(event, evt_name) \ + { {&(event).sleepq, &(event).sleepq}, evt_name} + #define event_init(event, evt_name) \ do { list_init(&(event)->sleepq); (event)->name = evt_name; } while (0) @@ -179,15 +235,21 @@ */ #define DUMP_THREAD 1 #define DUMP_TASK 2 -#define DUMP_VM 3 +#define DUMP_OBJECT 3 +#define DUMP_TIMER 4 +#define DUMP_IRQ 5 +#define DUMP_DEVICE 6 +#define DUMP_VM 7 +#define DUMP_MSGLOG 8 +#define DUMP_TRACE 9 __BEGIN_DECLS device_t device_create(struct devio *io, const char *name, int flags); int device_destroy(device_t dev); int device_broadcast(int event, int force); -int umem_copyin(const void *uaddr, void *kaddr, size_t len); -int umem_copyout(const void *kaddr, void *uaddr, size_t len); +int umem_copyin(void *uaddr, void *kaddr, size_t len); +int umem_copyout(void *kaddr, void *uaddr, size_t len); int umem_strnlen(const char *uaddr, size_t maxlen, size_t *len); void *kmem_alloc(size_t size); @@ -195,15 +257,15 @@ void *kmem_map(void *addr, size_t size); void *page_alloc(size_t size); -void page_free(void *paddr, size_t size); -int page_reserve(void *paddr, size_t size); +void page_free(void *addr, size_t size); +int page_reserve(void *addr, size_t size); -irq_t irq_attach(int irqno, int level, int shared, int (*isr)(int), void (*ist)(int)); -void irq_detach(irq_t irq); +int irq_attach(int irqno, int level, int shared, int (*isr)(int), void (*ist)(int)); +void irq_detach(int handle); void irq_lock(void); void irq_unlock(void); -void timer_callout(struct timer *tmr, u_long msec, void (*func)(void *), void *arg); +void timer_callout(struct timer *tmr, void (*func)(u_long), u_long arg, u_long msec); void timer_stop(struct timer *tmr); u_long timer_delay(u_long msec); u_long timer_count(void); @@ -229,17 +291,17 @@ void debug_attach(void (*func)(char *)); int debug_dump(int index); -void printf(const char *fmt, ...); -void panic(const char *msg); #ifdef DEBUG +void printk(const char *fmt, ...); +void panic(const char *fmt, ...); void assert(const char *file, int line, const char *exp); #define ASSERT(exp) do { if (!(exp)) \ - assert(__FILE__, __LINE__, #exp); } while (0) + assert(__FILE__, __LINE__, #exp); } while (0) #else -#define ASSERT(exp) do {} while (0) +#define printk(fmt...) do {} while (0) +#define panic(fmt...) do { for (;;) ; } while (0) +#define ASSERT(exp) #endif - -void driver_main(void); __END_DECLS #endif /* !_DRIVER_H */