[BACK]Return to kern_devconfig.c CVS log [TXT][DIR] Up to [local] / funnyos / kern

Diff for /funnyos/kern/kern_devconfig.c between version 1.2 and 1.7

version 1.2, 2007/10/16 14:29:12 version 1.7, 2007/11/01 13:22:08
Line 8 
Line 8 
 #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)
Line 16 
Line 16 
 #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;
Line 41 
Line 39 
          *  -     ...and so on.           *  -     ...and so on.
          */           */
         devconfig_attach_root();          devconfig_attach_root();
 //      devconfig_attach(&rootdev);  
 }  }
   
   
Line 89 
Line 86 
         /* 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 */
   
Line 106 
Line 103 
 {  {
         /*          /*
          * Attach device childs, if any.           * 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;          int retval;
         struct device *cdevp;          struct device *cdevp;
Line 149 
Line 146 
                         cdevp->dv_name = dip->di_dname;                          cdevp->dv_name = dip->di_dname;
                         cdevp->dv_minor = dip->di_ninstances;                          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,                          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);                                                                          pdevp->dv_name, pdevp->dv_minor, aip->ai_locator, aip->ai_flags);
   
                         /* 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.
                                  */                                   */
Line 166 
Line 161 
   
                                 /* TODO kfree devdata and device */                                  /* TODO kfree devdata and device */
   
                                 /* XXX next aip */                                  /* next aip */
                                 aip++;                                  aip++;
   
                                 continue;                                  continue;
Line 180 
Line 175 
                         /* activate device */                          /* activate device */
                         cdevp->dv_active = 1;                          cdevp->dv_active = 1;
   
                         /* XXX think about recursion */  
   
                         /* recursive attach this child's children */                          /* recursive attach this child's children */
                         devconfig_attach_childs(cdevp);                          devconfig_attach_childs(cdevp);
   
                 }                  }
                 printf("next aip\n");  
   
                 /* next attachinfo in table */                  /* next attachinfo in table */
                 aip++;                  aip++;
Line 194 
Line 186 
   
 }  }
   
 #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)

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.7

CVSweb