1*4882a593Smuzhiyun================ 2*4882a593SmuzhiyunEISA bus support 3*4882a593Smuzhiyun================ 4*4882a593Smuzhiyun 5*4882a593Smuzhiyun:Author: Marc Zyngier <maz@wild-wind.fr.eu.org> 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunThis document groups random notes about porting EISA drivers to the 8*4882a593Smuzhiyunnew EISA/sysfs API. 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunStarting from version 2.5.59, the EISA bus is almost given the same 11*4882a593Smuzhiyunstatus as other much more mainstream busses such as PCI or USB. This 12*4882a593Smuzhiyunhas been possible through sysfs, which defines a nice enough set of 13*4882a593Smuzhiyunabstractions to manage busses, devices and drivers. 14*4882a593Smuzhiyun 15*4882a593SmuzhiyunAlthough the new API is quite simple to use, converting existing 16*4882a593Smuzhiyundrivers to the new infrastructure is not an easy task (mostly because 17*4882a593Smuzhiyundetection code is generally also used to probe ISA cards). Moreover, 18*4882a593Smuzhiyunmost EISA drivers are among the oldest Linux drivers so, as you can 19*4882a593Smuzhiyunimagine, some dust has settled here over the years. 20*4882a593Smuzhiyun 21*4882a593SmuzhiyunThe EISA infrastructure is made up of three parts: 22*4882a593Smuzhiyun 23*4882a593Smuzhiyun - The bus code implements most of the generic code. It is shared 24*4882a593Smuzhiyun among all the architectures that the EISA code runs on. It 25*4882a593Smuzhiyun implements bus probing (detecting EISA cards available on the bus), 26*4882a593Smuzhiyun allocates I/O resources, allows fancy naming through sysfs, and 27*4882a593Smuzhiyun offers interfaces for driver to register. 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun - The bus root driver implements the glue between the bus hardware 30*4882a593Smuzhiyun and the generic bus code. It is responsible for discovering the 31*4882a593Smuzhiyun device implementing the bus, and setting it up to be latter probed 32*4882a593Smuzhiyun by the bus code. This can go from something as simple as reserving 33*4882a593Smuzhiyun an I/O region on x86, to the rather more complex, like the hppa 34*4882a593Smuzhiyun EISA code. This is the part to implement in order to have EISA 35*4882a593Smuzhiyun running on an "new" platform. 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun - The driver offers the bus a list of devices that it manages, and 38*4882a593Smuzhiyun implements the necessary callbacks to probe and release devices 39*4882a593Smuzhiyun whenever told to. 40*4882a593Smuzhiyun 41*4882a593SmuzhiyunEvery function/structure below lives in <linux/eisa.h>, which depends 42*4882a593Smuzhiyunheavily on <linux/device.h>. 43*4882a593Smuzhiyun 44*4882a593SmuzhiyunBus root driver 45*4882a593Smuzhiyun=============== 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun:: 48*4882a593Smuzhiyun 49*4882a593Smuzhiyun int eisa_root_register (struct eisa_root_device *root); 50*4882a593Smuzhiyun 51*4882a593SmuzhiyunThe eisa_root_register function is used to declare a device as the 52*4882a593Smuzhiyunroot of an EISA bus. The eisa_root_device structure holds a reference 53*4882a593Smuzhiyunto this device, as well as some parameters for probing purposes:: 54*4882a593Smuzhiyun 55*4882a593Smuzhiyun struct eisa_root_device { 56*4882a593Smuzhiyun struct device *dev; /* Pointer to bridge device */ 57*4882a593Smuzhiyun struct resource *res; 58*4882a593Smuzhiyun unsigned long bus_base_addr; 59*4882a593Smuzhiyun int slots; /* Max slot number */ 60*4882a593Smuzhiyun int force_probe; /* Probe even when no slot 0 */ 61*4882a593Smuzhiyun u64 dma_mask; /* from bridge device */ 62*4882a593Smuzhiyun int bus_nr; /* Set by eisa_root_register */ 63*4882a593Smuzhiyun struct resource eisa_root_res; /* ditto */ 64*4882a593Smuzhiyun }; 65*4882a593Smuzhiyun 66*4882a593Smuzhiyun============= ====================================================== 67*4882a593Smuzhiyunnode used for eisa_root_register internal purpose 68*4882a593Smuzhiyundev pointer to the root device 69*4882a593Smuzhiyunres root device I/O resource 70*4882a593Smuzhiyunbus_base_addr slot 0 address on this bus 71*4882a593Smuzhiyunslots max slot number to probe 72*4882a593Smuzhiyunforce_probe Probe even when slot 0 is empty (no EISA mainboard) 73*4882a593Smuzhiyundma_mask Default DMA mask. Usually the bridge device dma_mask. 74*4882a593Smuzhiyunbus_nr unique bus id, set by eisa_root_register 75*4882a593Smuzhiyun============= ====================================================== 76*4882a593Smuzhiyun 77*4882a593SmuzhiyunDriver 78*4882a593Smuzhiyun====== 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun:: 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun int eisa_driver_register (struct eisa_driver *edrv); 83*4882a593Smuzhiyun void eisa_driver_unregister (struct eisa_driver *edrv); 84*4882a593Smuzhiyun 85*4882a593SmuzhiyunClear enough ? 86*4882a593Smuzhiyun 87*4882a593Smuzhiyun:: 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun struct eisa_device_id { 90*4882a593Smuzhiyun char sig[EISA_SIG_LEN]; 91*4882a593Smuzhiyun unsigned long driver_data; 92*4882a593Smuzhiyun }; 93*4882a593Smuzhiyun 94*4882a593Smuzhiyun struct eisa_driver { 95*4882a593Smuzhiyun const struct eisa_device_id *id_table; 96*4882a593Smuzhiyun struct device_driver driver; 97*4882a593Smuzhiyun }; 98*4882a593Smuzhiyun 99*4882a593Smuzhiyun=============== ==================================================== 100*4882a593Smuzhiyunid_table an array of NULL terminated EISA id strings, 101*4882a593Smuzhiyun followed by an empty string. Each string can 102*4882a593Smuzhiyun optionally be paired with a driver-dependent value 103*4882a593Smuzhiyun (driver_data). 104*4882a593Smuzhiyun 105*4882a593Smuzhiyundriver a generic driver, such as described in 106*4882a593Smuzhiyun Documentation/driver-api/driver-model/driver.rst. Only .name, 107*4882a593Smuzhiyun .probe and .remove members are mandatory. 108*4882a593Smuzhiyun=============== ==================================================== 109*4882a593Smuzhiyun 110*4882a593SmuzhiyunAn example is the 3c59x driver:: 111*4882a593Smuzhiyun 112*4882a593Smuzhiyun static struct eisa_device_id vortex_eisa_ids[] = { 113*4882a593Smuzhiyun { "TCM5920", EISA_3C592_OFFSET }, 114*4882a593Smuzhiyun { "TCM5970", EISA_3C597_OFFSET }, 115*4882a593Smuzhiyun { "" } 116*4882a593Smuzhiyun }; 117*4882a593Smuzhiyun 118*4882a593Smuzhiyun static struct eisa_driver vortex_eisa_driver = { 119*4882a593Smuzhiyun .id_table = vortex_eisa_ids, 120*4882a593Smuzhiyun .driver = { 121*4882a593Smuzhiyun .name = "3c59x", 122*4882a593Smuzhiyun .probe = vortex_eisa_probe, 123*4882a593Smuzhiyun .remove = vortex_eisa_remove 124*4882a593Smuzhiyun } 125*4882a593Smuzhiyun }; 126*4882a593Smuzhiyun 127*4882a593SmuzhiyunDevice 128*4882a593Smuzhiyun====== 129*4882a593Smuzhiyun 130*4882a593SmuzhiyunThe sysfs framework calls .probe and .remove functions upon device 131*4882a593Smuzhiyundiscovery and removal (note that the .remove function is only called 132*4882a593Smuzhiyunwhen driver is built as a module). 133*4882a593Smuzhiyun 134*4882a593SmuzhiyunBoth functions are passed a pointer to a 'struct device', which is 135*4882a593Smuzhiyunencapsulated in a 'struct eisa_device' described as follows:: 136*4882a593Smuzhiyun 137*4882a593Smuzhiyun struct eisa_device { 138*4882a593Smuzhiyun struct eisa_device_id id; 139*4882a593Smuzhiyun int slot; 140*4882a593Smuzhiyun int state; 141*4882a593Smuzhiyun unsigned long base_addr; 142*4882a593Smuzhiyun struct resource res[EISA_MAX_RESOURCES]; 143*4882a593Smuzhiyun u64 dma_mask; 144*4882a593Smuzhiyun struct device dev; /* generic device */ 145*4882a593Smuzhiyun }; 146*4882a593Smuzhiyun 147*4882a593Smuzhiyun======== ============================================================ 148*4882a593Smuzhiyunid EISA id, as read from device. id.driver_data is set from the 149*4882a593Smuzhiyun matching driver EISA id. 150*4882a593Smuzhiyunslot slot number which the device was detected on 151*4882a593Smuzhiyunstate set of flags indicating the state of the device. Current 152*4882a593Smuzhiyun flags are EISA_CONFIG_ENABLED and EISA_CONFIG_FORCED. 153*4882a593Smuzhiyunres set of four 256 bytes I/O regions allocated to this device 154*4882a593Smuzhiyundma_mask DMA mask set from the parent device. 155*4882a593Smuzhiyundev generic device (see Documentation/driver-api/driver-model/device.rst) 156*4882a593Smuzhiyun======== ============================================================ 157*4882a593Smuzhiyun 158*4882a593SmuzhiyunYou can get the 'struct eisa_device' from 'struct device' using the 159*4882a593Smuzhiyun'to_eisa_device' macro. 160*4882a593Smuzhiyun 161*4882a593SmuzhiyunMisc stuff 162*4882a593Smuzhiyun========== 163*4882a593Smuzhiyun 164*4882a593Smuzhiyun:: 165*4882a593Smuzhiyun 166*4882a593Smuzhiyun void eisa_set_drvdata (struct eisa_device *edev, void *data); 167*4882a593Smuzhiyun 168*4882a593SmuzhiyunStores data into the device's driver_data area. 169*4882a593Smuzhiyun 170*4882a593Smuzhiyun:: 171*4882a593Smuzhiyun 172*4882a593Smuzhiyun void *eisa_get_drvdata (struct eisa_device *edev): 173*4882a593Smuzhiyun 174*4882a593SmuzhiyunGets the pointer previously stored into the device's driver_data area. 175*4882a593Smuzhiyun 176*4882a593Smuzhiyun:: 177*4882a593Smuzhiyun 178*4882a593Smuzhiyun int eisa_get_region_index (void *addr); 179*4882a593Smuzhiyun 180*4882a593SmuzhiyunReturns the region number (0 <= x < EISA_MAX_RESOURCES) of a given 181*4882a593Smuzhiyunaddress. 182*4882a593Smuzhiyun 183*4882a593SmuzhiyunKernel parameters 184*4882a593Smuzhiyun================= 185*4882a593Smuzhiyun 186*4882a593Smuzhiyuneisa_bus.enable_dev 187*4882a593Smuzhiyun A comma-separated list of slots to be enabled, even if the firmware 188*4882a593Smuzhiyun set the card as disabled. The driver must be able to properly 189*4882a593Smuzhiyun initialize the device in such conditions. 190*4882a593Smuzhiyun 191*4882a593Smuzhiyuneisa_bus.disable_dev 192*4882a593Smuzhiyun A comma-separated list of slots to be enabled, even if the firmware 193*4882a593Smuzhiyun set the card as enabled. The driver won't be called to handle this 194*4882a593Smuzhiyun device. 195*4882a593Smuzhiyun 196*4882a593Smuzhiyunvirtual_root.force_probe 197*4882a593Smuzhiyun Force the probing code to probe EISA slots even when it cannot find an 198*4882a593Smuzhiyun EISA compliant mainboard (nothing appears on slot 0). Defaults to 0 199*4882a593Smuzhiyun (don't force), and set to 1 (force probing) when either 200*4882a593Smuzhiyun CONFIG_ALPHA_JENSEN or CONFIG_EISA_VLB_PRIMING are set. 201*4882a593Smuzhiyun 202*4882a593SmuzhiyunRandom notes 203*4882a593Smuzhiyun============ 204*4882a593Smuzhiyun 205*4882a593SmuzhiyunConverting an EISA driver to the new API mostly involves *deleting* 206*4882a593Smuzhiyuncode (since probing is now in the core EISA code). Unfortunately, most 207*4882a593Smuzhiyundrivers share their probing routine between ISA, and EISA. Special 208*4882a593Smuzhiyuncare must be taken when ripping out the EISA code, so other busses 209*4882a593Smuzhiyunwon't suffer from these surgical strikes... 210*4882a593Smuzhiyun 211*4882a593SmuzhiyunYou *must not* expect any EISA device to be detected when returning 212*4882a593Smuzhiyunfrom eisa_driver_register, since the chances are that the bus has not 213*4882a593Smuzhiyunyet been probed. In fact, that's what happens most of the time (the 214*4882a593Smuzhiyunbus root driver usually kicks in rather late in the boot process). 215*4882a593SmuzhiyunUnfortunately, most drivers are doing the probing by themselves, and 216*4882a593Smuzhiyunexpect to have explored the whole machine when they exit their probe 217*4882a593Smuzhiyunroutine. 218*4882a593Smuzhiyun 219*4882a593SmuzhiyunFor example, switching your favorite EISA SCSI card to the "hotplug" 220*4882a593Smuzhiyunmodel is "the right thing"(tm). 221*4882a593Smuzhiyun 222*4882a593SmuzhiyunThanks 223*4882a593Smuzhiyun====== 224*4882a593Smuzhiyun 225*4882a593SmuzhiyunI'd like to thank the following people for their help: 226*4882a593Smuzhiyun 227*4882a593Smuzhiyun- Xavier Benigni for lending me a wonderful Alpha Jensen, 228*4882a593Smuzhiyun- James Bottomley, Jeff Garzik for getting this stuff into the kernel, 229*4882a593Smuzhiyun- Andries Brouwer for contributing numerous EISA ids, 230*4882a593Smuzhiyun- Catrin Jones for coping with far too many machines at home. 231