version 1.3, 2007/10/16 14:29:59 |
version 1.6, 2007/11/01 13:19:27 |
|
|
#include <libkern/string.h> |
#include <libkern/string.h> |
#include <libkern/printf.h> |
#include <libkern/printf.h> |
|
|
#define DEVCONFIG_DEBUG |
/* #define DEVCONFIG_DEBUG */ |
|
|
#ifdef DEVCONFIG_DEBUG |
#ifdef DEVCONFIG_DEBUG |
#define DPRINTF(x...) do { printf(x); } while (0) |
#define DPRINTF(x...) do { printf(x); } while (0) |
|
|
#define DPRINTF(x...) { } |
#define DPRINTF(x...) { } |
#endif |
#endif |
|
|
//extern struct device devlist[]; |
|
//extern uint8_t ndevices; |
|
|
|
/* system root device */ |
/* system root device */ |
extern struct device *rootdev; |
extern struct device *rootdev; |
|
|
* - ...and so on. |
* - ...and so on. |
*/ |
*/ |
devconfig_attach_root(); |
devconfig_attach_root(); |
// devconfig_attach(&rootdev); |
|
} |
} |
|
|
|
|
|
|
/* attach root; should never fail */ |
/* attach root; should never fail */ |
retval = drp->dr_attach(rootdev, 0, 0); |
retval = drp->dr_attach(rootdev, 0, 0); |
|
|
if (retval == -1) |
if (retval != 0) |
panic("failed to attach rootdev\n"); |
panic("failed to attach rootdev\n"); |
/* NOTREACHED */ |
/* NOTREACHED */ |
|
|
|
|
|
|
/* try to attach this device */ |
/* try to attach this device */ |
retval = drp->dr_attach(cdevp, aip->ai_locator, aip->ai_flags); |
retval = drp->dr_attach(cdevp, aip->ai_locator, aip->ai_flags); |
if (retval == -1) { |
if (retval != 0) { |
/* |
/* |
* Attachment failed. |
* Attachment failed. |
*/ |
*/ |
|
|
|
|
} |
} |
|
|
#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 |
struct driverinfo |
*devconfig_finddriverinfo(const char *dname) |
*devconfig_finddriverinfo(const char *dname) |