Browse Source

ISA bus driver updated to report devices as present only if a driver

thinks they are.
Other bus drivers modified for consistency.
tags/v0.9.3
Michael Brown 19 years ago
parent
commit
3dbdeb588f

+ 1
- 2
src/arch/i386/drivers/disk/floppy.c View File

@@ -21,8 +21,7 @@ static void floppy_disable ( struct disk *disk,
21 21
 	
22 22
 }
23 23
 
24
-static struct bios_disk_driver floppy_driver =
25
-	BIOS_DISK_DRIVER ( fill_floppy_name, 0x00, 0x7f );
24
+BIOS_DISK_DRIVER ( floppy_driver, fill_floppy_name, 0x00, 0x7f );
26 25
 
27 26
 DRIVER ( "floppy", disk_driver, bios_disk_driver, floppy_driver,
28 27
 	 floppy_probe, floppy_disable );

+ 6
- 5
src/arch/i386/include/bios_disks.h View File

@@ -47,11 +47,12 @@ struct bios_disk_driver {
47 47
  * Define a BIOS disk driver
48 48
  *
49 49
  */
50
-#define BIOS_DISK_DRIVER( _fill_drive_name, _min_drive, _max_drive ) {	      \
51
-	.fill_drive_name = _fill_drive_name,				      \
52
-	.min_drive = _min_drive,					      \
53
-	.max_drive = _max_drive,					      \
54
-}
50
+#define BIOS_DISK_DRIVER( _name, _fill_drive_name, _min_drive, _max_drive )   \
51
+	static struct bios_disk_driver _name = {			      \
52
+		.fill_drive_name = _fill_drive_name,			      \
53
+		.min_drive = _min_drive,				      \
54
+		.max_drive = _max_drive,				      \
55
+	}
55 56
 
56 57
 /*
57 58
  * Functions in bios_disks.c

+ 3
- 0
src/arch/i386/scripts/i386.lds View File

@@ -145,6 +145,9 @@ SECTIONS {
145 145
 	device_drivers = .;
146 146
 	*(.drivers.device)
147 147
 	device_drivers_end = .;
148
+	isa_drivers = . ;
149
+	*(.drivers.isa)
150
+	isa_drivers_end = .;
148 151
 	bus_drivers = .;
149 152
 	*(.drivers.bus)
150 153
 	bus_drivers_end = .;

+ 52
- 38
src/drivers/bus/isa.c View File

@@ -17,8 +17,8 @@
17 17
  *
18 18
  * The ISA probe address list can be overridden by config.h; if the
19 19
  * user specifies ISA_PROBE_ADDRS then that list will be used first.
20
- * (If ISA_PROBE_ADDRS ends with a zero, the driver's own list will
21
- * never be used).
20
+ * (If ISA_PROBE_ONLY is defined, the driver's own list will never be
21
+ * used).
22 22
  */
23 23
 
24 24
 /*
@@ -34,20 +34,33 @@ static isa_probe_addr_t isa_extra_probe_addrs[] = {
34 34
      ( sizeof ( isa_extra_probe_addrs ) / sizeof ( isa_extra_probe_addrs[0] ) )
35 35
 
36 36
 #ifdef ISA_PROBE_ONLY
37
-#  define		ISA_PROBE_IDX_LIMIT	isa_extra_probe_addr_count
37
+#define ISA_PROBE_ADDR_COUNT(driver) ( isa_extra_probe_addr_count )
38 38
 #else
39
-#  define		ISA_PROBE_IDX_LIMIT	( ISA_MAX_PROBE_IDX + 1 )
39
+#define ISA_PROBE_ADDR_COUNT(driver) \
40
+	( isa_extra_probe_addr_count + (driver)->addr_count )
40 41
 #endif
41 42
 
43
+/*
44
+ * Symbols defined by linker
45
+ *
46
+ */
47
+extern struct isa_driver isa_drivers[];
48
+extern struct isa_driver isa_drivers_end[];
49
+
42 50
 /*
43 51
  * Increment a bus_loc structure to the next possible ISA location.
44 52
  * Leave the structure zeroed and return 0 if there are no more valid
45 53
  * locations.
46 54
  *
55
+ * There is no sensible concept of a device location on an ISA bus, so
56
+ * we use the probe address list for each ISA driver to define the
57
+ * list of ISA locations.
58
+ *
47 59
  */
48 60
 static int isa_next_location ( struct bus_loc *bus_loc ) {
49 61
 	struct isa_loc *isa_loc = ( struct isa_loc * ) bus_loc;
50
-	
62
+	struct isa_driver *driver;
63
+
51 64
 	/*
52 65
 	 * Ensure that there is sufficient space in the shared bus
53 66
 	 * structures for a struct isa_loc and a struct
@@ -57,8 +70,18 @@ static int isa_next_location ( struct bus_loc *bus_loc ) {
57 70
 	BUS_LOC_CHECK ( struct isa_loc );
58 71
 	BUS_DEV_CHECK ( struct isa_device );
59 72
 
60
-	return ( ( ++isa_loc->probe_idx < ISA_PROBE_IDX_LIMIT ) ?
61
-		 1 : ( isa_loc->probe_idx = 0 ) );
73
+	/* Move to next probe address within this driver */
74
+	driver = &isa_drivers[isa_loc->driver];
75
+	if ( ++isa_loc->probe_idx < ISA_PROBE_ADDR_COUNT ( driver ) )
76
+		return 1;
77
+
78
+	/* Move to next driver */
79
+	isa_loc->probe_idx = 0;
80
+	if ( ( ++isa_loc->driver, ++driver ) < isa_drivers_end )
81
+		return 1;
82
+
83
+	isa_loc->driver = 0;
84
+	return 0;
62 85
 }
63 86
 
64 87
 /*
@@ -73,17 +96,29 @@ static int isa_fill_device ( struct bus_dev *bus_dev,
73 96
 	struct isa_loc *isa_loc = ( struct isa_loc * ) bus_loc;
74 97
 	struct isa_device *isa = ( struct isa_device * ) bus_dev;
75 98
 	signed int driver_probe_idx;
76
-
99
+	
100
+	/* Fill in struct isa from struct isa_loc */
101
+	isa->driver = &isa_drivers[isa_loc->driver];
77 102
 	driver_probe_idx = isa_loc->probe_idx - isa_extra_probe_addr_count;
78 103
 	if ( driver_probe_idx < 0 ) {
79 104
 		isa->ioaddr = isa_extra_probe_addrs[isa_loc->probe_idx];
80 105
 	} else {
81
-		isa->ioaddr = 0;
82
-		isa->driver_probe_idx = driver_probe_idx;
106
+		isa->ioaddr = isa->driver->probe_addrs[driver_probe_idx];
107
+	}
108
+
109
+	/* Call driver's probe_addr method to determine if a device is
110
+	 * physically present
111
+	 */
112
+	if ( isa->driver->probe_addr ( isa->ioaddr ) ) {
113
+		isa->name = isa->driver->name;
114
+		isa->mfg_id = isa->driver->mfg_id;
115
+		isa->prod_id = isa->driver->prod_id;
116
+		DBG ( "ISA found %s device at address %hx\n",
117
+		      isa->name, isa->ioaddr );
118
+		return 1;
83 119
 	}
84
-	isa->mfg_id = isa->prod_id = 0;
85
-	isa->name = "?";
86
-	return 1;
120
+
121
+	return 0;
87 122
 }
88 123
 
89 124
 /*
@@ -97,29 +132,7 @@ int isa_check_driver ( struct bus_dev *bus_dev,
97 132
 	struct isa_driver *driver
98 133
 		= ( struct isa_driver * ) device_driver->bus_driver_info;
99 134
 
100
-	/* If ioaddr is zero, it means we're using a driver-specified
101
-	 * ioaddr
102
-	 */
103
-	if ( ! isa->ioaddr ) {
104
-		if ( isa->driver_probe_idx >= driver->addr_count )
105
-			return 0;
106
-		isa->ioaddr = driver->probe_addrs[isa->driver_probe_idx];
107
-	}
108
-
109
-	/* Use probe_addr method to see if there's a device
110
-	 * present at this address.
111
-	 */
112
-	if ( driver->probe_addr ( isa->ioaddr ) ) {
113
-		DBG ( "ISA found %s device at address %hx\n",
114
-		      driver->name, isa->ioaddr );
115
-		isa->name = driver->name;
116
-		isa->mfg_id = driver->mfg_id;
117
-		isa->prod_id = driver->prod_id;
118
-		return 1;
119
-	}
120
-
121
-	/* No device found */
122
-	return 0;
135
+	return ( driver == isa->driver );
123 136
 }
124 137
 
125 138
 /*
@@ -128,9 +141,10 @@ int isa_check_driver ( struct bus_dev *bus_dev,
128 141
  */
129 142
 static char * isa_describe_device ( struct bus_dev *bus_dev ) {
130 143
 	struct isa_device *isa = ( struct isa_device * ) bus_dev;
131
-	static char isa_description[] = "ISA 0000";
144
+	static char isa_description[] = "ISA 0000 (00)";
132 145
 
133
-	sprintf ( isa_description + 4, "%hx", isa->ioaddr );
146
+	sprintf ( isa_description + 4, "%hx (%hhx)", isa->ioaddr,
147
+		  isa->driver - isa_drivers );
134 148
 	return isa_description;
135 149
 }
136 150
 

+ 1
- 1
src/include/dev.h View File

@@ -28,7 +28,7 @@ struct device_driver;
28 28
  * A physical device location on a bus.
29 29
  *
30 30
  */
31
-#define BUS_LOC_SIZE 4
31
+#define BUS_LOC_SIZE 8
32 32
 struct bus_loc {
33 33
 	char bytes[BUS_LOC_SIZE];
34 34
 };

+ 5
- 4
src/include/eisa.h View File

@@ -66,10 +66,11 @@ struct eisa_driver {
66 66
  * Define an EISA driver
67 67
  *
68 68
  */
69
-#define EISA_DRIVER( _ids ) {					\
70
-	.ids = _ids,						\
71
-	.id_count = sizeof ( _ids ) / sizeof ( _ids[0] ),	\
72
-}
69
+#define EISA_DRIVER( _name, _ids ) 					\
70
+	static struct eisa_driver _name = {				\
71
+		.ids = _ids,						\
72
+		.id_count = sizeof ( _ids ) / sizeof ( _ids[0] ),	\
73
+	}
73 74
 
74 75
 /*
75 76
  * Functions in eisa.c

+ 6
- 3
src/include/isa.h View File

@@ -9,10 +9,11 @@
9 9
  * A location on an ISA bus
10 10
  *
11 11
  */
12
+struct isa_driver;
12 13
 struct isa_loc {
14
+	unsigned int driver;
13 15
 	unsigned int probe_idx;
14 16
 };
15
-#define ISA_MAX_PROBE_IDX	255 /* Unlikely to ever be more than ~20 */
16 17
 
17 18
 /*
18 19
  * A physical ISA device
@@ -20,7 +21,7 @@ struct isa_loc {
20 21
  */
21 22
 struct isa_device {
22 23
 	const char *name;
23
-	unsigned int driver_probe_idx;
24
+	struct isa_driver *driver;
24 25
 	uint16_t ioaddr;
25 26
 	uint16_t mfg_id;
26 27
 	uint16_t prod_id;
@@ -47,12 +48,14 @@ struct isa_driver {
47 48
 	uint16_t mfg_id;
48 49
 	uint16_t prod_id;
49 50
 };
51
+#define __isa_driver __attribute__ (( section ( ".drivers.isa" ) ))
50 52
 
51 53
 /*
52 54
  * Define an ISA driver
53 55
  *
54 56
  */
55
-#define ISA_DRIVER( _probe_addrs, _probe_addr, _mfg_id, _prod_id ) {	    \
57
+#define ISA_DRIVER( _name, _probe_addrs, _probe_addr, _mfg_id, _prod_id )   \
58
+static struct isa_driver _name __isa_driver = {				    \
56 59
 	.probe_addrs = _probe_addrs,					    \
57 60
 	.addr_count = sizeof ( _probe_addrs ) / sizeof ( _probe_addrs[0] ), \
58 61
 	.probe_addr = _probe_addr,					    \

+ 5
- 4
src/include/isapnp.h View File

@@ -200,10 +200,11 @@ struct isapnp_driver {
200 200
  * Define an ISAPnP driver
201 201
  *
202 202
  */
203
-#define ISAPNP_DRIVER( _ids ) {					\
204
-	.ids = _ids,						\
205
-	.id_count = sizeof ( _ids ) / sizeof ( _ids[0] ),	\
206
-}
203
+#define ISAPNP_DRIVER( _name, _ids ) 					\
204
+	static struct isapnp_driver _name = {				\
205
+		.ids = _ids,						\
206
+		.id_count = sizeof ( _ids ) / sizeof ( _ids[0] ),	\
207
+	}
207 208
 
208 209
 /*
209 210
  * Functions in isapnp.c

+ 5
- 4
src/include/mca.h View File

@@ -67,10 +67,11 @@ struct mca_driver {
67 67
  * Define an MCA driver
68 68
  *
69 69
  */
70
-#define MCA_DRIVER( _ids ) {					\
71
-	.ids = _ids,						\
72
-	.id_count = sizeof ( _ids ) / sizeof ( _ids[0] ),	\
73
-}
70
+#define MCA_DRIVER( _name, _ids )					\
71
+	static struct mca_driver _name = {				\
72
+		.ids = _ids,						\
73
+		.id_count = sizeof ( _ids ) / sizeof ( _ids[0] ),	\
74
+	}
74 75
 
75 76
 /*
76 77
  * Functions in mca.c

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

@@ -307,7 +307,8 @@ struct pci_driver {
307 307
  * Define a PCI driver.
308 308
  *
309 309
  */
310
-#define PCI_DRIVER( _ids, _class ) {					\
310
+#define PCI_DRIVER( _name, _ids, _class ) 				\
311
+	static struct pci_driver _name = {				\
311 312
 		.ids = _ids,						\
312 313
 		.id_count = sizeof ( _ids ) / sizeof ( _ids[0] ),	\
313 314
 		.class = _class,					\

Loading…
Cancel
Save