Back to home page

LXR

 
 

    


0001 EISA bus support (Marc Zyngier <maz@wild-wind.fr.eu.org>)
0002 
0003 This document groups random notes about porting EISA drivers to the
0004 new EISA/sysfs API.
0005 
0006 Starting from version 2.5.59, the EISA bus is almost given the same
0007 status as other much more mainstream busses such as PCI or USB. This
0008 has been possible through sysfs, which defines a nice enough set of
0009 abstractions to manage busses, devices and drivers.
0010 
0011 Although the new API is quite simple to use, converting existing
0012 drivers to the new infrastructure is not an easy task (mostly because
0013 detection code is generally also used to probe ISA cards). Moreover,
0014 most EISA drivers are among the oldest Linux drivers so, as you can
0015 imagine, some dust has settled here over the years.
0016 
0017 The EISA infrastructure is made up of three parts :
0018 
0019     - The bus code implements most of the generic code. It is shared
0020     among all the architectures that the EISA code runs on. It
0021     implements bus probing (detecting EISA cards available on the bus),
0022     allocates I/O resources, allows fancy naming through sysfs, and
0023     offers interfaces for driver to register.
0024 
0025     - The bus root driver implements the glue between the bus hardware
0026     and the generic bus code. It is responsible for discovering the
0027     device implementing the bus, and setting it up to be latter probed
0028     by the bus code. This can go from something as simple as reserving
0029     an I/O region on x86, to the rather more complex, like the hppa
0030     EISA code. This is the part to implement in order to have EISA
0031     running on an "new" platform.
0032 
0033     - The driver offers the bus a list of devices that it manages, and
0034     implements the necessary callbacks to probe and release devices
0035     whenever told to.
0036 
0037 Every function/structure below lives in <linux/eisa.h>, which depends
0038 heavily on <linux/device.h>.
0039 
0040 ** Bus root driver :
0041 
0042 int eisa_root_register (struct eisa_root_device *root);
0043 
0044 The eisa_root_register function is used to declare a device as the
0045 root of an EISA bus. The eisa_root_device structure holds a reference
0046 to this device, as well as some parameters for probing purposes.
0047 
0048 struct eisa_root_device {
0049         struct device   *dev;    /* Pointer to bridge device */
0050         struct resource *res;
0051         unsigned long    bus_base_addr;
0052         int              slots;  /* Max slot number */
0053         int              force_probe; /* Probe even when no slot 0 */
0054         u64              dma_mask; /* from bridge device */
0055         int              bus_nr; /* Set by eisa_root_register */
0056         struct resource  eisa_root_res; /* ditto */
0057 };
0058 
0059 node          : used for eisa_root_register internal purpose
0060 dev           : pointer to the root device
0061 res           : root device I/O resource
0062 bus_base_addr : slot 0 address on this bus
0063 slots         : max slot number to probe
0064 force_probe   : Probe even when slot 0 is empty (no EISA mainboard)
0065 dma_mask      : Default DMA mask. Usually the bridge device dma_mask.
0066 bus_nr        : unique bus id, set by eisa_root_register
0067 
0068 ** Driver :
0069 
0070 int eisa_driver_register (struct eisa_driver *edrv);
0071 void eisa_driver_unregister (struct eisa_driver *edrv);
0072 
0073 Clear enough ?
0074 
0075 struct eisa_device_id {
0076         char sig[EISA_SIG_LEN];
0077         unsigned long driver_data;
0078 };
0079 
0080 struct eisa_driver {
0081         const struct eisa_device_id *id_table;
0082         struct device_driver         driver;
0083 };
0084 
0085 id_table        : an array of NULL terminated EISA id strings,
0086                   followed by an empty string. Each string can
0087                   optionally be paired with a driver-dependent value
0088                   (driver_data).
0089 
0090 driver          : a generic driver, such as described in
0091                   Documentation/driver-model/driver.txt. Only .name,
0092                   .probe and .remove members are mandatory.
0093 
0094 An example is the 3c59x driver :
0095 
0096 static struct eisa_device_id vortex_eisa_ids[] = {
0097         { "TCM5920", EISA_3C592_OFFSET },
0098         { "TCM5970", EISA_3C597_OFFSET },
0099         { "" }
0100 };
0101 
0102 static struct eisa_driver vortex_eisa_driver = {
0103         .id_table = vortex_eisa_ids,
0104         .driver   = {
0105                 .name    = "3c59x",
0106                 .probe   = vortex_eisa_probe,
0107                 .remove  = vortex_eisa_remove
0108         }
0109 };
0110 
0111 ** Device :
0112 
0113 The sysfs framework calls .probe and .remove functions upon device
0114 discovery and removal (note that the .remove function is only called
0115 when driver is built as a module).
0116 
0117 Both functions are passed a pointer to a 'struct device', which is
0118 encapsulated in a 'struct eisa_device' described as follows :
0119 
0120 struct eisa_device {
0121         struct eisa_device_id id;
0122         int                   slot;
0123         int                   state;
0124         unsigned long         base_addr;
0125         struct resource       res[EISA_MAX_RESOURCES];
0126         u64                   dma_mask;
0127         struct device         dev; /* generic device */
0128 };
0129 
0130 id      : EISA id, as read from device. id.driver_data is set from the
0131           matching driver EISA id.
0132 slot    : slot number which the device was detected on
0133 state   : set of flags indicating the state of the device. Current
0134           flags are EISA_CONFIG_ENABLED and EISA_CONFIG_FORCED.
0135 res     : set of four 256 bytes I/O regions allocated to this device
0136 dma_mask: DMA mask set from the parent device.
0137 dev     : generic device (see Documentation/driver-model/device.txt)
0138 
0139 You can get the 'struct eisa_device' from 'struct device' using the
0140 'to_eisa_device' macro.
0141 
0142 ** Misc stuff :
0143 
0144 void eisa_set_drvdata (struct eisa_device *edev, void *data);
0145 
0146 Stores data into the device's driver_data area.
0147 
0148 void *eisa_get_drvdata (struct eisa_device *edev):
0149 
0150 Gets the pointer previously stored into the device's driver_data area.
0151 
0152 int eisa_get_region_index (void *addr);
0153 
0154 Returns the region number (0 <= x < EISA_MAX_RESOURCES) of a given
0155 address.
0156 
0157 ** Kernel parameters :
0158 
0159 eisa_bus.enable_dev :
0160 
0161 A comma-separated list of slots to be enabled, even if the firmware
0162 set the card as disabled. The driver must be able to properly
0163 initialize the device in such conditions.
0164 
0165 eisa_bus.disable_dev :
0166 
0167 A comma-separated list of slots to be enabled, even if the firmware
0168 set the card as enabled. The driver won't be called to handle this
0169 device.
0170 
0171 virtual_root.force_probe :
0172 
0173 Force the probing code to probe EISA slots even when it cannot find an
0174 EISA compliant mainboard (nothing appears on slot 0). Defaults to 0
0175 (don't force), and set to 1 (force probing) when either
0176 CONFIG_ALPHA_JENSEN or CONFIG_EISA_VLB_PRIMING are set.
0177 
0178 ** Random notes :
0179 
0180 Converting an EISA driver to the new API mostly involves *deleting*
0181 code (since probing is now in the core EISA code). Unfortunately, most
0182 drivers share their probing routine between ISA, and EISA. Special
0183 care must be taken when ripping out the EISA code, so other busses
0184 won't suffer from these surgical strikes...
0185 
0186 You *must not* expect any EISA device to be detected when returning
0187 from eisa_driver_register, since the chances are that the bus has not
0188 yet been probed. In fact, that's what happens most of the time (the
0189 bus root driver usually kicks in rather late in the boot process).
0190 Unfortunately, most drivers are doing the probing by themselves, and
0191 expect to have explored the whole machine when they exit their probe
0192 routine.
0193 
0194 For example, switching your favorite EISA SCSI card to the "hotplug"
0195 model is "the right thing"(tm).
0196 
0197 ** Thanks :
0198 
0199 I'd like to thank the following people for their help :
0200 - Xavier Benigni for lending me a wonderful Alpha Jensen,
0201 - James Bottomley, Jeff Garzik for getting this stuff into the kernel,
0202 - Andries Brouwer for contributing numerous EISA ids,
0203 - Catrin Jones for coping with far too many machines at home.