Browse Source

Tweak API to allow separation of bus-scanning and device-probing logic.

tags/v0.9.3
Michael Brown 20 years ago
parent
commit
104880ca19
6 changed files with 85 additions and 90 deletions
  1. 26
    30
      src/drivers/bus/eisa.c
  2. 25
    24
      src/drivers/bus/mca.c
  3. 27
    27
      src/drivers/bus/pci.c
  4. 3
    3
      src/include/eisa.h
  5. 2
    3
      src/include/mca.h
  6. 2
    3
      src/include/pci.h

+ 26
- 30
src/drivers/bus/eisa.c View File

48
 }
48
 }
49
 
49
 
50
 /*
50
 /*
51
- * Obtain a struct eisa * from a struct dev *
51
+ * Find an EISA device matching the specified driver
52
  *
52
  *
53
- * If dev has not previously been used for an EISA device scan, blank
54
- * out struct eisa
55
  */
53
  */
56
-struct eisa_device * eisa_device ( struct dev *dev ) {
57
-	struct eisa_device *eisa = dev->bus;;
54
+int find_eisa_device ( struct eisa_device *eisa, struct eisa_driver *driver ) {
55
+	unsigned int i;
58
 
56
 
57
+	/* Initialise struct eisa if it's the first time it's been used. */
59
 	if ( eisa->magic != eisa_magic ) {
58
 	if ( eisa->magic != eisa_magic ) {
60
 		memset ( eisa, 0, sizeof ( *eisa ) );
59
 		memset ( eisa, 0, sizeof ( *eisa ) );
61
 		eisa->magic = eisa_magic;
60
 		eisa->magic = eisa_magic;
61
+		eisa->slot = EISA_MIN_SLOT;
62
 	}
62
 	}
63
-	eisa->dev = dev;
64
-	return eisa;
65
-}
66
-
67
-/*
68
- * Find an EISA device matching the specified driver
69
- *
70
- */
71
-int find_eisa_device ( struct eisa_device *eisa, struct eisa_driver *driver ) {
72
-	unsigned int i;
73
 
63
 
74
 	/* Iterate through all possible EISA slots, starting where we
64
 	/* Iterate through all possible EISA slots, starting where we
75
-	 * left off.  If eisa->slot is zero (which it will be if we
76
-	 * have a zeroed structure), start from slot EISA_MIN_SLOT,
77
-	 * since slot 0 doesn't exist.
65
+	 * left off.
78
 	 */
66
 	 */
79
-	if ( ! eisa->slot ) {
80
-		eisa->slot = EISA_MIN_SLOT;
81
-	}
82
 	for ( ; eisa->slot <= EISA_MAX_SLOT ; eisa->slot++ ) {
67
 	for ( ; eisa->slot <= EISA_MAX_SLOT ; eisa->slot++ ) {
83
 		/* If we've already used this device, skip it */
68
 		/* If we've already used this device, skip it */
84
 		if ( eisa->already_tried ) {
69
 		if ( eisa->already_tried ) {
102
 				      id->name, driver->name,
87
 				      id->name, driver->name,
103
 				      isa_id_string ( eisa->mfg_id,
88
 				      isa_id_string ( eisa->mfg_id,
104
 						      eisa->prod_id ) );
89
 						      eisa->prod_id ) );
105
-				if ( eisa->dev ) {
106
-					eisa->dev->name = driver->name;
107
-					eisa->dev->devid.bus_type
108
-						= ISA_BUS_TYPE;
109
-					eisa->dev->devid.vendor_id
110
-						= eisa->mfg_id;
111
-					eisa->dev->devid.device_id
112
-						= eisa->prod_id;
113
-				}
90
+				eisa->name = id->name;
114
 				eisa->already_tried = 1;
91
 				eisa->already_tried = 1;
115
 				return 1;
92
 				return 1;
116
 			}
93
 			}
122
 	return 0;
99
 	return 0;
123
 }
100
 }
124
 
101
 
102
+/*
103
+ * Find the next EISA device that can be used to boot using the
104
+ * specified driver.
105
+ *
106
+ */
107
+int find_eisa_boot_device ( struct dev *dev, struct eisa_driver *driver ) {
108
+	struct eisa_device *eisa = ( struct eisa_device * )dev->bus;
109
+
110
+	if ( ! find_eisa_device ( eisa, driver ) )
111
+		return 0;
112
+
113
+	dev->name = eisa->name;
114
+	dev->devid.bus_type = ISA_BUS_TYPE;
115
+	dev->devid.vendor_id = eisa->mfg_id;
116
+	dev->devid.device_id = eisa->prod_id;
117
+
118
+	return 1;
119
+}
120
+
125
 /*
121
 /*
126
  * Reset and enable an EISA device
122
  * Reset and enable an EISA device
127
  *
123
  *

+ 25
- 24
src/drivers/bus/mca.c View File

49
 }
49
 }
50
 
50
 
51
 /*
51
 /*
52
- * Obtain a struct mca * from a struct dev *
52
+ * Find an MCA device matching the specified driver
53
  *
53
  *
54
- * If dev has not previously been used for an MCA device scan, blank
55
- * out struct mca
56
  */
54
  */
57
-struct mca_device * mca_device ( struct dev *dev ) {
58
-	struct mca_device *mca = dev->bus;
55
+int find_mca_device ( struct mca_device *mca, struct mca_driver *driver ) {
56
+	unsigned int i;
59
 
57
 
58
+	/* Initialise struct mca if it's the first time it's been used. */
60
 	if ( mca->magic != mca_magic ) {
59
 	if ( mca->magic != mca_magic ) {
61
 		memset ( mca, 0, sizeof ( *mca ) );
60
 		memset ( mca, 0, sizeof ( *mca ) );
62
 		mca->magic = mca_magic;
61
 		mca->magic = mca_magic;
63
 	}
62
 	}
64
-	mca->dev = dev;
65
-	return mca;
66
-}
67
-
68
-/*
69
- * Find an MCA device matching the specified driver
70
- *
71
- */
72
-int find_mca_device ( struct mca_device *mca, struct mca_driver *driver ) {
73
-	unsigned int i;
74
 
63
 
75
 	/* Iterate through all possible MCA slots, starting where we
64
 	/* Iterate through all possible MCA slots, starting where we
76
-	 * left off/
65
+	 * left off
77
 	 */
66
 	 */
78
 	for ( ; mca->slot < MCA_MAX_SLOT_NR ; mca->slot++ ) {
67
 	for ( ; mca->slot < MCA_MAX_SLOT_NR ; mca->slot++ ) {
79
 		/* If we've already used this device, skip it */
68
 		/* If we've already used this device, skip it */
94
 			if ( MCA_ID ( mca ) == id->id ) {
83
 			if ( MCA_ID ( mca ) == id->id ) {
95
 				DBG ( "Device %s (driver %s) matches ID %hx\n",
84
 				DBG ( "Device %s (driver %s) matches ID %hx\n",
96
 				      id->name, driver->name, id->id );
85
 				      id->name, driver->name, id->id );
97
-				if ( mca->dev ) {
98
-					mca->dev->name = driver->name;
99
-					mca->dev->devid.bus_type
100
-						= MCA_BUS_TYPE;
101
-					mca->dev->devid.vendor_id
102
-						= GENERIC_MCA_VENDOR;
103
-					mca->dev->devid.device_id = id->id;
104
-				}
86
+				mca->name = id->name;
105
 				mca->already_tried = 1;
87
 				mca->already_tried = 1;
106
 				return 1;
88
 				return 1;
107
 			}
89
 			}
112
 	mca->slot = 0;
94
 	mca->slot = 0;
113
 	return 0;
95
 	return 0;
114
 }
96
 }
97
+
98
+/*
99
+ * Find the next MCA device that can be used to boot using the
100
+ * specified driver.
101
+ *
102
+ */
103
+int find_mca_boot_device ( struct dev *dev, struct mca_driver *driver ) {
104
+	struct mca_device *mca = ( struct mca_device * )dev->bus;
105
+
106
+	if ( ! find_mca_device ( mca, driver ) )
107
+		return 0;
108
+
109
+	dev->name = mca->name;
110
+	dev->devid.bus_type = MCA_BUS_TYPE;
111
+	dev->devid.vendor_id = GENERIC_MCA_VENDOR;
112
+	dev->devid.device_id = MCA_ID ( mca );
113
+
114
+	return 1;
115
+}

+ 27
- 27
src/drivers/bus/pci.c View File

109
 	}
109
 	}
110
 }
110
 }
111
 
111
 
112
-/*
113
- * Obtain a struct pci * from a struct dev *
114
- *
115
- * If dev has not previously been used for a PCI device scan, blank
116
- * out struct pci
117
- */
118
-struct pci_device * pci_device ( struct dev *dev ) {
119
-	struct pci_device *pci = dev->bus;
120
-
121
-	if ( pci->magic != pci_magic ) {
122
-		memset ( pci, 0, sizeof ( *pci ) );
123
-		pci->magic = pci_magic;
124
-	}
125
-	pci->dev = dev;
126
-	return pci;
127
-}
128
-
129
 /*
112
 /*
130
  * Set PCI device to use.
113
  * Set PCI device to use.
131
  *
114
  *
148
 		      struct pci_driver *driver ) {
131
 		      struct pci_driver *driver ) {
149
 	int i;
132
 	int i;
150
 
133
 
134
+	/* Initialise struct pci if it's the first time it's been used. */
135
+	if ( pci->magic != pci_magic ) {
136
+		memset ( pci, 0, sizeof ( *pci ) );
137
+		pci->magic = pci_magic;
138
+	}
139
+
151
 	/* Iterate through all possible PCI bus:dev.fn combinations,
140
 	/* Iterate through all possible PCI bus:dev.fn combinations,
152
 	 * starting where we left off.
141
 	 * starting where we left off.
153
 	 */
142
 	 */
166
 		/* Fix up PCI device */
155
 		/* Fix up PCI device */
167
 		adjust_pci_device ( pci );
156
 		adjust_pci_device ( pci );
168
 		
157
 		
169
-		/* Fill in dev structure, if present */
170
-		if ( pci->dev ) {
171
-			pci->dev->name = driver->name;
172
-			pci->dev->devid.bus_type = PCI_BUS_TYPE;
173
-			pci->dev->devid.vendor_id = pci->vendor;
174
-			pci->dev->devid.device_id = pci->dev_id;
175
-		}
176
-
177
 		/* If driver has a class, and class matches, use it */
158
 		/* If driver has a class, and class matches, use it */
178
 		if ( driver->class && 
159
 		if ( driver->class && 
179
 		     ( driver->class == pci->class ) ) {
160
 		     ( driver->class == pci->class ) ) {
180
 			DBG ( "Driver %s matches class %hx\n",
161
 			DBG ( "Driver %s matches class %hx\n",
181
 			      driver->name, driver->class );
162
 			      driver->name, driver->class );
163
+			pci->name = driver->name;
182
 			pci->already_tried = 1;
164
 			pci->already_tried = 1;
183
 			return 1;
165
 			return 1;
184
 		}
166
 		}
192
 				DBG ( "Device %s (driver %s) matches "
174
 				DBG ( "Device %s (driver %s) matches "
193
 				      "ID %hx:%hx\n", id->name, driver->name,
175
 				      "ID %hx:%hx\n", id->name, driver->name,
194
 				      id->vendor, id->dev_id );
176
 				      id->vendor, id->dev_id );
195
-				if ( pci->dev )
196
-					pci->dev->name = id->name;
177
+				pci->name = id->name;
197
 				pci->already_tried = 1;
178
 				pci->already_tried = 1;
198
 				return 1;
179
 				return 1;
199
 			}
180
 			}
206
 	return 0;
187
 	return 0;
207
 }
188
 }
208
 
189
 
190
+/*
191
+ * Find the next PCI device that can be used to boot using the
192
+ * specified driver.
193
+ *
194
+ */
195
+int find_pci_boot_device ( struct dev *dev, struct pci_driver *driver ) {
196
+	struct pci_device *pci = ( struct pci_device * )dev->bus;
197
+
198
+	if ( ! find_pci_device ( pci, driver ) )
199
+		return 0;
200
+
201
+	dev->name = pci->name;
202
+	dev->devid.bus_type = PCI_BUS_TYPE;
203
+	dev->devid.vendor_id = pci->vendor;
204
+	dev->devid.device_id = pci->dev_id;
205
+
206
+	return 1;
207
+}
208
+
209
 /*
209
 /*
210
  * Find the start of a pci resource.
210
  * Find the start of a pci resource.
211
  */
211
  */

+ 3
- 3
src/include/eisa.h View File

25
  * A physical EISA device
25
  * A physical EISA device
26
  *
26
  *
27
  */
27
  */
28
-struct dev;
29
 struct eisa_device {
28
 struct eisa_device {
30
 	char *magic; /* must be first */
29
 	char *magic; /* must be first */
31
-	struct dev *dev;
30
+	const char *name;
32
 	unsigned int slot;
31
 	unsigned int slot;
33
 	uint16_t ioaddr;
32
 	uint16_t ioaddr;
34
 	uint16_t mfg_id;
33
 	uint16_t mfg_id;
69
  * Functions in eisa.c
68
  * Functions in eisa.c
70
  *
69
  *
71
  */
70
  */
72
-extern struct eisa_device * eisa_device ( struct dev *dev );
73
 extern int find_eisa_device ( struct eisa_device *eisa,
71
 extern int find_eisa_device ( struct eisa_device *eisa,
74
 			      struct eisa_driver *driver );
72
 			      struct eisa_driver *driver );
73
+extern int find_eisa_boot_device ( struct dev *dev,
74
+				   struct eisa_driver *driver );
75
 extern void enable_eisa_device ( struct eisa_device *eisa );
75
 extern void enable_eisa_device ( struct eisa_device *eisa );
76
 
76
 
77
 #endif /* EISA_H */
77
 #endif /* EISA_H */

+ 2
- 3
src/include/mca.h View File

26
  * A physical MCA device
26
  * A physical MCA device
27
  *
27
  *
28
  */
28
  */
29
-struct dev;
30
 struct mca_device {
29
 struct mca_device {
31
 	char *magic; /* must be first */
30
 	char *magic; /* must be first */
32
-	struct dev *dev;
31
+	const char *name;
33
 	unsigned int slot;
32
 	unsigned int slot;
34
 	unsigned char pos[8];
33
 	unsigned char pos[8];
35
 	int already_tried;
34
 	int already_tried;
69
  * Functions in mca.c
68
  * Functions in mca.c
70
  *
69
  *
71
  */
70
  */
72
-extern struct mca_device * mca_device ( struct dev *dev );
73
 extern int find_mca_device ( struct mca_device *mca,
71
 extern int find_mca_device ( struct mca_device *mca,
74
 			     struct mca_driver *driver );
72
 			     struct mca_driver *driver );
73
+extern int find_mca_boot_device ( struct dev *dev, struct mca_driver *driver );
75
 
74
 
76
 #endif
75
 #endif

+ 2
- 3
src/include/pci.h View File

236
  * A physical PCI device
236
  * A physical PCI device
237
  *
237
  *
238
  */
238
  */
239
-struct dev;
240
 struct pci_device {
239
 struct pci_device {
241
 	char *			magic; /* must be first */
240
 	char *			magic; /* must be first */
242
-	struct dev *		dev;
241
+	const char *		name;
243
 	uint32_t		membase;	/* BAR 1 */
242
 	uint32_t		membase;	/* BAR 1 */
244
 	uint32_t		ioaddr;		/* first IO BAR */
243
 	uint32_t		ioaddr;		/* first IO BAR */
245
 	uint16_t		vendor, dev_id;
244
 	uint16_t		vendor, dev_id;
322
  * Functions in pci.c
321
  * Functions in pci.c
323
  *
322
  *
324
  */
323
  */
325
-extern struct pci_device * pci_device ( struct dev *dev );
326
 extern int find_pci_device ( struct pci_device *pci,
324
 extern int find_pci_device ( struct pci_device *pci,
327
 			     struct pci_driver *driver );
325
 			     struct pci_driver *driver );
326
+extern int find_pci_boot_device ( struct dev *dev, struct pci_driver *driver );
328
 extern void adjust_pci_device ( struct pci_device *pci );
327
 extern void adjust_pci_device ( struct pci_device *pci );
329
 extern unsigned long pci_bar_start ( struct pci_device *pci,
328
 extern unsigned long pci_bar_start ( struct pci_device *pci,
330
 				     unsigned int bar );
329
 				     unsigned int bar );

Loading…
Cancel
Save