3 #include "config/isa.h"
8 * isa.c implements a "classical" port-scanning method of ISA device
9 * detection. The driver must provide a list of probe addresses
10 * (probe_addrs), together with a function (probe_addr) that can be
11 * used to test for the physical presence of a device at any given
14 * Note that this should probably be considered the "last resort" for
15 * device probing. If the card supports ISAPnP or EISA, use that
16 * instead. Some cards (e.g. the 3c509) implement a proprietary
17 * ISAPnP-like mechanism.
19 * The ISA probe address list can be overridden by config.h; if the
20 * user specifies ISA_PROBE_ADDRS then that list will be used first.
21 * (If ISA_PROBE_ONLY is defined, the driver's own list will never be
26 * User-supplied probe address list
29 static isa_probe_addr_t isa_extra_probe_addrs[] = {
30 #ifdef ISA_PROBE_ADDRS
34 #define isa_extra_probe_addr_count \
35 ( sizeof ( isa_extra_probe_addrs ) / sizeof ( isa_extra_probe_addrs[0] ) )
38 #define ISA_PROBE_ADDR_COUNT(driver) ( isa_extra_probe_addr_count )
40 #define ISA_PROBE_ADDR_COUNT(driver) \
41 ( isa_extra_probe_addr_count + (driver)->addr_count )
45 * Symbols defined by linker
48 static struct isa_driver isa_drivers[0]
49 __table_start ( struct isa_driver, isa_driver );
50 static struct isa_driver isa_drivers_end[0]
51 __table_end ( struct isa_driver, isa_driver );
54 * Increment a bus_loc structure to the next possible ISA location.
55 * Leave the structure zeroed and return 0 if there are no more valid
58 * There is no sensible concept of a device location on an ISA bus, so
59 * we use the probe address list for each ISA driver to define the
60 * list of ISA locations.
63 static int isa_next_location ( struct bus_loc *bus_loc ) {
64 struct isa_loc *isa_loc = ( struct isa_loc * ) bus_loc;
65 struct isa_driver *driver;
68 * Ensure that there is sufficient space in the shared bus
69 * structures for a struct isa_loc and a struct
70 * isa_dev, as mandated by bus.h.
73 BUS_LOC_CHECK ( struct isa_loc );
74 BUS_DEV_CHECK ( struct isa_device );
76 /* Move to next probe address within this driver */
77 driver = &isa_drivers[isa_loc->driver];
78 if ( ++isa_loc->probe_idx < ISA_PROBE_ADDR_COUNT ( driver ) )
81 /* Move to next driver */
82 isa_loc->probe_idx = 0;
83 if ( ( ++isa_loc->driver, ++driver ) < isa_drivers_end )
91 * Fill in parameters (vendor & device ids, class, membase etc.) for
92 * an ISA device based on bus_loc.
94 * Returns 1 if a device was found, 0 for no device present.
97 static int isa_fill_device ( struct bus_dev *bus_dev,
98 struct bus_loc *bus_loc ) {
99 struct isa_loc *isa_loc = ( struct isa_loc * ) bus_loc;
100 struct isa_device *isa = ( struct isa_device * ) bus_dev;
101 signed int driver_probe_idx;
103 /* Fill in struct isa from struct isa_loc */
104 isa->driver = &isa_drivers[isa_loc->driver];
105 driver_probe_idx = isa_loc->probe_idx - isa_extra_probe_addr_count;
106 if ( driver_probe_idx < 0 ) {
107 isa->ioaddr = isa_extra_probe_addrs[isa_loc->probe_idx];
109 isa->ioaddr = isa->driver->probe_addrs[driver_probe_idx];
112 /* Call driver's probe_addr method to determine if a device is
115 if ( isa->driver->probe_addr ( isa->ioaddr ) ) {
116 isa->name = isa->driver->name;
117 isa->mfg_id = isa->driver->mfg_id;
118 isa->prod_id = isa->driver->prod_id;
119 DBG ( "ISA found %s device at address %hx\n",
120 isa->name, isa->ioaddr );
128 * Test whether or not a driver is capable of driving the specified
132 int isa_check_driver ( struct bus_dev *bus_dev,
133 struct device_driver *device_driver ) {
134 struct isa_device *isa = ( struct isa_device * ) bus_dev;
135 struct isa_driver *driver
136 = ( struct isa_driver * ) device_driver->bus_driver_info;
138 return ( driver == isa->driver );
142 * Describe a ISA device
145 static char * isa_describe_device ( struct bus_dev *bus_dev ) {
146 struct isa_device *isa = ( struct isa_device * ) bus_dev;
147 static char isa_description[] = "ISA 0000 (00)";
149 sprintf ( isa_description + 4, "%hx (%hhx)", isa->ioaddr,
150 isa->driver - isa_drivers );
151 return isa_description;
158 static const char * isa_name_device ( struct bus_dev *bus_dev ) {
159 struct isa_device *isa = ( struct isa_device * ) bus_dev;
165 * ISA bus operations table
168 struct bus_driver isa_driver __bus_driver = {
170 .next_location = isa_next_location,
171 .fill_device = isa_fill_device,
172 .check_driver = isa_check_driver,
173 .describe_device = isa_describe_device,
174 .name_device = isa_name_device,
178 * Fill in a nic structure
181 void isa_fill_nic ( struct nic *nic, struct isa_device *isa ) {
183 /* Fill in ioaddr and irqno */
184 nic->ioaddr = isa->ioaddr;
187 /* Fill in DHCP device ID structure */
188 nic->dhcp_dev_id.bus_type = ISA_BUS_TYPE;
189 nic->dhcp_dev_id.vendor_id = htons ( isa->mfg_id );
190 nic->dhcp_dev_id.device_id = htons ( isa->prod_id );