瀏覽代碼

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

tags/v0.9.3
Michael Brown 19 年之前
父節點
當前提交
104880ca19
共有 6 個文件被更改,包括 85 次插入90 次删除
  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 查看文件

@@ -48,37 +48,22 @@ static int fill_eisa_device ( struct eisa_device *eisa ) {
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 58
 	if ( eisa->magic != eisa_magic ) {
60 59
 		memset ( eisa, 0, sizeof ( *eisa ) );
61 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 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 67
 	for ( ; eisa->slot <= EISA_MAX_SLOT ; eisa->slot++ ) {
83 68
 		/* If we've already used this device, skip it */
84 69
 		if ( eisa->already_tried ) {
@@ -102,15 +87,7 @@ int find_eisa_device ( struct eisa_device *eisa, struct eisa_driver *driver ) {
102 87
 				      id->name, driver->name,
103 88
 				      isa_id_string ( eisa->mfg_id,
104 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 91
 				eisa->already_tried = 1;
115 92
 				return 1;
116 93
 			}
@@ -122,6 +99,25 @@ int find_eisa_device ( struct eisa_device *eisa, struct eisa_driver *driver ) {
122 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 122
  * Reset and enable an EISA device
127 123
  *

+ 25
- 24
src/drivers/bus/mca.c 查看文件

@@ -49,31 +49,20 @@ static int fill_mca_device ( struct mca_device *mca ) {
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 59
 	if ( mca->magic != mca_magic ) {
61 60
 		memset ( mca, 0, sizeof ( *mca ) );
62 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 64
 	/* Iterate through all possible MCA slots, starting where we
76
-	 * left off/
65
+	 * left off
77 66
 	 */
78 67
 	for ( ; mca->slot < MCA_MAX_SLOT_NR ; mca->slot++ ) {
79 68
 		/* If we've already used this device, skip it */
@@ -94,14 +83,7 @@ int find_mca_device ( struct mca_device *mca, struct mca_driver *driver ) {
94 83
 			if ( MCA_ID ( mca ) == id->id ) {
95 84
 				DBG ( "Device %s (driver %s) matches ID %hx\n",
96 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 87
 				mca->already_tried = 1;
106 88
 				return 1;
107 89
 			}
@@ -112,3 +94,22 @@ int find_mca_device ( struct mca_device *mca, struct mca_driver *driver ) {
112 94
 	mca->slot = 0;
113 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 查看文件

@@ -109,23 +109,6 @@ void adjust_pci_device ( struct pci_device *pci ) {
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 113
  * Set PCI device to use.
131 114
  *
@@ -148,6 +131,12 @@ int find_pci_device ( struct pci_device *pci,
148 131
 		      struct pci_driver *driver ) {
149 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 140
 	/* Iterate through all possible PCI bus:dev.fn combinations,
152 141
 	 * starting where we left off.
153 142
 	 */
@@ -166,19 +155,12 @@ int find_pci_device ( struct pci_device *pci,
166 155
 		/* Fix up PCI device */
167 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 158
 		/* If driver has a class, and class matches, use it */
178 159
 		if ( driver->class && 
179 160
 		     ( driver->class == pci->class ) ) {
180 161
 			DBG ( "Driver %s matches class %hx\n",
181 162
 			      driver->name, driver->class );
163
+			pci->name = driver->name;
182 164
 			pci->already_tried = 1;
183 165
 			return 1;
184 166
 		}
@@ -192,8 +174,7 @@ int find_pci_device ( struct pci_device *pci,
192 174
 				DBG ( "Device %s (driver %s) matches "
193 175
 				      "ID %hx:%hx\n", id->name, driver->name,
194 176
 				      id->vendor, id->dev_id );
195
-				if ( pci->dev )
196
-					pci->dev->name = id->name;
177
+				pci->name = id->name;
197 178
 				pci->already_tried = 1;
198 179
 				return 1;
199 180
 			}
@@ -206,6 +187,25 @@ int find_pci_device ( struct pci_device *pci,
206 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 210
  * Find the start of a pci resource.
211 211
  */

+ 3
- 3
src/include/eisa.h 查看文件

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

+ 2
- 3
src/include/mca.h 查看文件

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

+ 2
- 3
src/include/pci.h 查看文件

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

Loading…
取消
儲存