Annotation of prex-old/dev/core/config_search.c, Revision 1.2
1.1 nbrk 1: /*
1.2 ! nbrk 2: * $Id: config_search.c,v 1.1 2008/08/08 12:37:11 nbrk Exp $
1.1 nbrk 3: */
4: #include <driver.h>
5:
6: /* #define AUTOCONF_DEBUG */
7:
8: #ifndef AUTOCONF_DEBUG
9: #define DPRINTF(fmt...) do {} while (0)
10: #else
11: #define DPRINTF(fmt...) do { printk(fmt); } while (0)
12: #endif /* !AUTOCONF_DEBUG */
13:
14: extern struct driver *drivers[];
15: extern struct attachment config_table[];
16:
17: int
18: config_search_children(struct device *parent, void *aux)
19: {
20: struct attachment *atp;
21: struct driver *chdrvp, *hedrvp;
22: struct device *self;
23: int retval;
24: int ndevs;
25:
26: DPRINTF("config_search_children: enter, name=%s\n", parent->dv_xname);
27: atp = config_table;
28:
29: /*
30: * Look through the table.
31: */
32: while (atp->at_childname != NULL) {
33: DPRINTF("config_table: trying %s at %s%u via %s\n", atp->at_childname, atp->at_parentname,
34: atp->at_parentunit == -1 ? "*" : atp->at_parentunit,
35: atp->at_helpername != NULL ? atp->at_helpername : "(self)");
36:
37: if (atp->at_parentname == NULL)
38: panic("config: bogus config table (no parent given for %s)",
39: atp->at_childname);
40:
41: if (strncmp(atp->at_parentname, parent->dv_xname, CONFIG_XNAMELEN) == 0) {
42: /*
43: * Names are matched.
44: */
45: /* see if parent unit is specified */
46: if (atp->at_parentunit != -1 && parent->dv_unit != atp->at_parentunit)
47: /* child didn't like our unit number */
48: break;
49:
50: /*
51: * This is our child device.
52: */
53: /* locate child driver */
54: chdrvp = config_find_driver(atp->at_childname);
55:
56: /*
57: * See if helper is specified.
58: */
59: if (atp->at_helpername != NULL) {
60: /* locate helper driver */
61: hedrvp = config_find_driver(atp->at_helpername);
62:
63: /* match helper */
1.2 ! nbrk 64: if (hedrvp->dr_match != NULL && hedrvp->dr_match(parent, aux) < 1)
1.1 nbrk 65: break; /* not matched */
66: }
67:
68: /* match device */
1.2 ! nbrk 69: if (chdrvp->dr_match != NULL && chdrvp->dr_match(parent, aux) < 1)
1.1 nbrk 70: break; /* not matched */
71:
72: /* allocate device */
73: self = config_alloc_device(chdrvp);
74:
75: /* increase units number in driver */
76: chdrvp->dr_nunits++;
77:
78: /* initialize device */
79: self->dv_xname = chdrvp->dr_name;
80: self->dv_unit = chdrvp->dr_nunits;
81: self->dv_flags = atp->at_flags;
82: self->dv_parent = parent;
83:
84: printk("%s%u at %s%u via %s flags 0x%x: ", self->dv_xname, self->dv_unit,
85: parent->dv_xname, parent->dv_unit,
86: atp->at_helpername != NULL ? atp->at_helpername : "(self)", self->dv_flags);
87:
88: /*
89: * Attach device directly or via its helper.
90: * If there is helper, call its attach routine instead of child's one.
91: */
92: if (atp->at_helpername != NULL) {
93: if (hedrvp->dr_attach == NULL)
94: panic("config: no attach entry for driver '%s'", hedrvp->dr_name);
95:
96: retval = hedrvp->dr_attach(parent, self, aux);
97: } else {
98: /* no helper, direct attach */
99: if (chdrvp->dr_attach == NULL)
100: panic("config: no attach entry for driver '%s'", chdrvp->dr_name);
101:
102: retval = chdrvp->dr_attach(parent, self, aux);
103: }
104:
105: /*
106: * Attachment is done. See if it's succeeded.
107: */
108: if (retval != 0) {
109: /* attachment failed */
110: config_free_device(self);
111:
112: /* decrement nunits in driver */
113: chdrvp->dr_nunits--;
114: }
115:
116: }
117: /* okay, see next line in config_table */
118: atp++;
119: ndevs++;
120: }
121:
122: return(ndevs);
123: }
124:
125:
126: struct driver
127: *config_find_driver(const char *name)
128: {
129: /*
130: * Return pointer to driver for given 'name'.
131: */
132: struct driver *drvp;
133: int i;
134:
135: #if 0
136: drvp = drivers[0];
137:
138: while (drvp != NULL) {
139: DPRINTFg("drvp->dr_name %s\n", drvp->dr_name);
140: if (strncmp(drvp->dr_name, name, CONFIG_XNAMELEN) == 0) {
141: DPRINTF("config: found driver for %s\n", drvp->dr_name);
142: return(drvp);
143: }
144:
145: drvp += sizeof(struct driver *);
146: }
147: #endif
148: for (i = 0; i < 100; i++) {
149: drvp = drivers[i];
150: if (drvp == NULL)
151: break;
152:
153: if (strncmp(drvp->dr_name, name, CONFIG_XNAMELEN) == 0) {
154: return(drvp);
155: }
156: }
157:
158: panic("config: can't find driver for name '%s'", name);
159: }
160:
CVSweb