=================================================================== RCS file: /cvs/funnyos/kern/kern_devconfig.c,v retrieving revision 1.1.1.1 retrieving revision 1.11 diff -u -r1.1.1.1 -r1.11 --- funnyos/kern/kern_devconfig.c 2007/10/16 09:41:04 1.1.1.1 +++ funnyos/kern/kern_devconfig.c 2007/12/16 23:16:09 1.11 @@ -1,14 +1,15 @@ /* - * $Id: kern_devconfig.c,v 1.1.1.1 2007/10/16 08:41:04 init Exp $ + * $Id: kern_devconfig.c,v 1.11 2007/12/16 23:16:09 nbrk Exp $ */ #include #include #include #include +#include #include #include -#define DEVCONFIG_DEBUG +/* #define DEVCONFIG_DEBUG */ #ifdef DEVCONFIG_DEBUG #define DPRINTF(x...) do { printf(x); } while (0) @@ -16,8 +17,6 @@ #define DPRINTF(x...) { } #endif -//extern struct device devlist[]; -//extern uint8_t ndevices; /* system root device */ extern struct device *rootdev; @@ -41,7 +40,6 @@ * - ...and so on. */ devconfig_attach_root(); -// devconfig_attach(&rootdev); } @@ -89,7 +87,7 @@ /* attach root; should never fail */ retval = drp->dr_attach(rootdev, 0, 0); - if (retval == -1) + if (retval != 0) panic("failed to attach rootdev\n"); /* NOTREACHED */ @@ -106,7 +104,7 @@ { /* * Attach device childs, if any. - * XXX Allocate space for struct device and its xxx_dd + * Allocate space for struct device and its xxx_dd */ int retval; struct device *cdevp; @@ -140,7 +138,7 @@ /* allocate space for device's devdata */ cdevp->dv_devdata = kmalloc(drp->dr_ddsize); if (cdevp->dv_devdata == NULL) - panic("failed to allocate space for %s devdata\n"); + panic("failed to allocate space for %s devdata\n", aip->ai_cname); /* NOTREACHED */ /* increment number of driver's instances */ @@ -149,14 +147,12 @@ cdevp->dv_name = dip->di_dname; cdevp->dv_minor = dip->di_ninstances; - /* XXX what about locator (aip->ai_locator)? */ - printf("%s/%d at %s/%d loc 0x%x flags 0x%x: ", cdevp->dv_name, cdevp->dv_minor, pdevp->dv_name, pdevp->dv_minor, aip->ai_locator, aip->ai_flags); /* try to attach this device */ retval = drp->dr_attach(cdevp, aip->ai_locator, aip->ai_flags); - if (retval == -1) { + if (retval != 0) { /* * Attachment failed. */ @@ -166,6 +162,9 @@ /* TODO kfree devdata and device */ + /* next aip */ + aip++; + continue; /* NOTREACHED */ } @@ -177,10 +176,15 @@ /* activate device */ cdevp->dv_active = 1; - /* XXX think about recursion */ + /* if device has interrupt handler, establish it */ + if (drp->dr_interrupt != NULL && aip->ai_intrno != -1) { + DPRINTF("devconfig_attach_childs: establishing interrupt %d for %s/%d\n", + aip->ai_intrno, cdevp->dv_name, cdevp->dv_minor); + intr_establish(aip->ai_intrno, cdevp, drp->dr_interrupt); + } /* recursive attach this child's children */ - //devconfig_attach_childs(cdevp); + devconfig_attach_childs(cdevp); } @@ -190,95 +194,6 @@ } -#if 0 -void -devconfig_iterate(void) -{ - struct device *devp = devlist; - - printf("Entered devconfig phase\n"); - - while(devp->dv_attach != NULL) { - /* - * Iterative attach all devices in list. - */ - if (! devp->dv_active && (devp->dv_parent->dv_active || devp->dv_parent == devp)) { - - printf("%s/%d at %s/%d loc 0x%x: ", devp->dv_name, devp->dv_minor, devp->dv_parent->dv_name, - devp->dv_parent->dv_minor, devp->dv_locator); - - /* call attach_subr and activate device if it returns 0 */ - if (devp->dv_attach(devp) == 0) { - /* driver returns okay; mark device as active */ - devp->dv_active = 1; - } - else { - /* attachment failed */ - printf("disabling %s/%d\n", devp->dv_name, devp->dv_minor); - } - } - - devp++; - } - - printf("Exited devconfig phase\n"); -} - - -int -devconfig_target(struct device *devp) -{ - /* - * Recursive attach (subtree) nodes upto already active parent or (root). - */ - - if (devp == NULL) - return(-1); - - /* attach parent if it's not (root) or not activated yet */ - if (devp->dv_parent != devp && ! devp->dv_parent->dv_active) { - - if (devconfig_target(devp->dv_parent) == -1) - return(-1); - } - - printf("%s/%d at %s/%d\n", devp->dv_name, devp->dv_minor, - devp->dv_parent->dv_name, devp->dv_parent->dv_minor); - if (devp->dv_attach(devp) == 0) { - /* attached */ - devp->dv_active = 1; - - return(0); - } - else { - /* failed */ - printf("disabling %s/%d\n", devp->dv_name, devp->dv_minor); - - /* XXX maybe it is easier to panic here? */ - /* panic(XXX) */ - - return(-1); - } -} - - -struct device -*devconfig_findbyname(const char *dv_name, const uint8_t dv_minor) -{ - /* - * Return pointer to device dv_name/dv_minor. - */ - struct device *devp = devlist; - - while(devp->dv_name) { - if (strncmp(devp->dv_name, dv_name, DVNAMELEN - 1) == 0 && devp->dv_minor == dv_minor) - return (devp); - } - - /* nothing has been found */ - return(NULL); -} -#endif /* not 0 */ struct driverinfo *devconfig_finddriverinfo(const char *dname)