2 * EISA bus support functions for sysfs.
4 * (C) 2002, 2003 Marc Zyngier <maz@wild-wind.fr.eu.org>
6 * This code is released under the GPL version 2.
9 #include <linux/kernel.h>
10 #include <linux/device.h>
11 #include <linux/eisa.h>
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/init.h>
15 #include <linux/slab.h>
16 #include <linux/ioport.h>
19 #define SLOT_ADDRESS(r,n) (r->bus_base_addr + (0x1000 * n))
21 #define EISA_DEVINFO(i,s) { .id = { .sig = i }, .name = s }
23 struct eisa_device_info {
24 struct eisa_device_id id;
28 #ifdef CONFIG_EISA_NAMES
29 static struct eisa_device_info __initdata eisa_table[] = {
32 #define EISA_INFOS (sizeof (eisa_table) / (sizeof (struct eisa_device_info)))
35 #define EISA_MAX_FORCED_DEV 16
37 static int enable_dev[EISA_MAX_FORCED_DEV];
38 static unsigned int enable_dev_count;
39 static int disable_dev[EISA_MAX_FORCED_DEV];
40 static unsigned int disable_dev_count;
42 static int is_forced_dev(int *forced_tab,
44 struct eisa_root_device *root,
45 struct eisa_device *edev)
49 for (i = 0; i < forced_count; i++) {
50 x = (root->bus_nr << 8) | edev->slot;
51 if (forced_tab[i] == x)
58 static void __init eisa_name_device(struct eisa_device *edev)
60 #ifdef CONFIG_EISA_NAMES
62 for (i = 0; i < EISA_INFOS; i++) {
63 if (!strcmp(edev->id.sig, eisa_table[i].id.sig)) {
64 strlcpy(edev->pretty_name,
66 sizeof(edev->pretty_name));
71 /* No name was found */
72 sprintf(edev->pretty_name, "EISA device %.7s", edev->id.sig);
76 static char __init *decode_eisa_sig(unsigned long addr)
78 static char sig_str[EISA_SIG_LEN];
83 for (i = 0; i < 4; i++) {
84 #ifdef CONFIG_EISA_VLB_PRIMING
86 * This ugly stuff is used to wake up VL-bus cards
87 * (AHA-284x is the only known example), so we can
90 * Thankfully, this only exists on x86...
94 sig[i] = inb(addr + i);
96 if (!i && (sig[0] & 0x80))
100 sig_str[0] = ((sig[0] >> 2) & 0x1f) + ('A' - 1);
101 sig_str[1] = (((sig[0] & 3) << 3) | (sig[1] >> 5)) + ('A' - 1);
102 sig_str[2] = (sig[1] & 0x1f) + ('A' - 1);
103 rev = (sig[2] << 8) | sig[3];
104 sprintf(sig_str + 3, "%04X", rev);
109 static int eisa_bus_match(struct device *dev, struct device_driver *drv)
111 struct eisa_device *edev = to_eisa_device(dev);
112 struct eisa_driver *edrv = to_eisa_driver(drv);
113 const struct eisa_device_id *eids = edrv->id_table;
118 while (strlen(eids->sig)) {
119 if (!strcmp(eids->sig, edev->id.sig) &&
120 edev->state & EISA_CONFIG_ENABLED) {
121 edev->id.driver_data = eids->driver_data;
131 static int eisa_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
133 struct eisa_device *edev = to_eisa_device(dev);
135 add_uevent_var(env, "MODALIAS=" EISA_DEVICE_MODALIAS_FMT, edev->id.sig);
139 struct bus_type eisa_bus_type = {
141 .match = eisa_bus_match,
142 .uevent = eisa_bus_uevent,
144 EXPORT_SYMBOL(eisa_bus_type);
146 int eisa_driver_register(struct eisa_driver *edrv)
148 edrv->driver.bus = &eisa_bus_type;
149 return driver_register(&edrv->driver);
151 EXPORT_SYMBOL(eisa_driver_register);
153 void eisa_driver_unregister(struct eisa_driver *edrv)
155 driver_unregister(&edrv->driver);
157 EXPORT_SYMBOL(eisa_driver_unregister);
159 static ssize_t eisa_show_sig(struct device *dev, struct device_attribute *attr,
162 struct eisa_device *edev = to_eisa_device(dev);
163 return sprintf(buf, "%s\n", edev->id.sig);
166 static DEVICE_ATTR(signature, S_IRUGO, eisa_show_sig, NULL);
168 static ssize_t eisa_show_state(struct device *dev,
169 struct device_attribute *attr,
172 struct eisa_device *edev = to_eisa_device(dev);
173 return sprintf(buf, "%d\n", edev->state & EISA_CONFIG_ENABLED);
176 static DEVICE_ATTR(enabled, S_IRUGO, eisa_show_state, NULL);
178 static ssize_t eisa_show_modalias(struct device *dev,
179 struct device_attribute *attr,
182 struct eisa_device *edev = to_eisa_device(dev);
183 return sprintf(buf, EISA_DEVICE_MODALIAS_FMT "\n", edev->id.sig);
186 static DEVICE_ATTR(modalias, S_IRUGO, eisa_show_modalias, NULL);
188 static int __init eisa_init_device(struct eisa_root_device *root,
189 struct eisa_device *edev,
193 unsigned long sig_addr;
196 sig_addr = SLOT_ADDRESS(root, slot) + EISA_VENDOR_ID_OFFSET;
198 sig = decode_eisa_sig(sig_addr);
200 return -1; /* No EISA device here */
202 memcpy(edev->id.sig, sig, EISA_SIG_LEN);
204 edev->state = inb(SLOT_ADDRESS(root, slot) + EISA_CONFIG_OFFSET)
205 & EISA_CONFIG_ENABLED;
206 edev->base_addr = SLOT_ADDRESS(root, slot);
207 edev->dma_mask = root->dma_mask; /* Default DMA mask */
208 eisa_name_device(edev);
209 edev->dev.parent = root->dev;
210 edev->dev.bus = &eisa_bus_type;
211 edev->dev.dma_mask = &edev->dma_mask;
212 edev->dev.coherent_dma_mask = edev->dma_mask;
213 dev_set_name(&edev->dev, "%02X:%02X", root->bus_nr, slot);
215 for (i = 0; i < EISA_MAX_RESOURCES; i++) {
216 #ifdef CONFIG_EISA_NAMES
217 edev->res[i].name = edev->pretty_name;
219 edev->res[i].name = edev->id.sig;
223 if (is_forced_dev(enable_dev, enable_dev_count, root, edev))
224 edev->state = EISA_CONFIG_ENABLED | EISA_CONFIG_FORCED;
226 if (is_forced_dev(disable_dev, disable_dev_count, root, edev))
227 edev->state = EISA_CONFIG_FORCED;
232 static int __init eisa_register_device(struct eisa_device *edev)
234 int rc = device_register(&edev->dev);
236 put_device(&edev->dev);
240 rc = device_create_file(&edev->dev, &dev_attr_signature);
243 rc = device_create_file(&edev->dev, &dev_attr_enabled);
246 rc = device_create_file(&edev->dev, &dev_attr_modalias);
253 device_remove_file(&edev->dev, &dev_attr_enabled);
255 device_remove_file(&edev->dev, &dev_attr_signature);
257 device_unregister(&edev->dev);
261 static int __init eisa_request_resources(struct eisa_root_device *root,
262 struct eisa_device *edev,
267 for (i = 0; i < EISA_MAX_RESOURCES; i++) {
268 /* Don't register resource for slot 0, since this is
269 * very likely to fail... :-( Instead, grab the EISA
270 * id, now we can display something in /proc/ioports.
273 /* Only one region for mainboard */
274 if (!slot && i > 0) {
275 edev->res[i].start = edev->res[i].end = 0;
280 edev->res[i].name = NULL;
281 edev->res[i].start = SLOT_ADDRESS(root, slot)
283 edev->res[i].end = edev->res[i].start + 0xff;
284 edev->res[i].flags = IORESOURCE_IO;
286 edev->res[i].name = NULL;
287 edev->res[i].start = SLOT_ADDRESS(root, slot)
288 + EISA_VENDOR_ID_OFFSET;
289 edev->res[i].end = edev->res[i].start + 3;
290 edev->res[i].flags = IORESOURCE_IO | IORESOURCE_BUSY;
293 if (request_resource(root->res, &edev->res[i]))
301 release_resource(&edev->res[i]);
306 static void __init eisa_release_resources(struct eisa_device *edev)
310 for (i = 0; i < EISA_MAX_RESOURCES; i++)
311 if (edev->res[i].start || edev->res[i].end)
312 release_resource(&edev->res[i]);
315 static int __init eisa_probe(struct eisa_root_device *root)
318 struct eisa_device *edev;
321 dev_info(root->dev, "Probing EISA bus %d\n", root->bus_nr);
323 /* First try to get hold of slot 0. If there is no device
324 * here, simply fail, unless root->force_probe is set. */
326 edev = kzalloc(sizeof(*edev), GFP_KERNEL);
328 dev_err(root->dev, "EISA: Couldn't allocate mainboard slot\n");
332 if (eisa_request_resources(root, edev, 0)) {
334 "EISA: Cannot allocate resource for mainboard\n");
336 if (!root->force_probe)
341 if (eisa_init_device(root, edev, 0)) {
342 eisa_release_resources(edev);
344 if (!root->force_probe)
349 dev_info(&edev->dev, "EISA: Mainboard %s detected\n", edev->id.sig);
351 if (eisa_register_device(edev)) {
352 dev_err(&edev->dev, "EISA: Failed to register %s\n",
354 eisa_release_resources(edev);
360 for (c = 0, i = 1; i <= root->slots; i++) {
361 edev = kzalloc(sizeof(*edev), GFP_KERNEL);
363 dev_err(root->dev, "EISA: Out of memory for slot %d\n",
368 if (eisa_request_resources(root, edev, i)) {
370 "Cannot allocate resource for EISA slot %d\n",
376 if (eisa_init_device(root, edev, i)) {
377 eisa_release_resources(edev);
382 if (edev->state == (EISA_CONFIG_ENABLED | EISA_CONFIG_FORCED))
383 enabled_str = " (forced enabled)";
384 else if (edev->state == EISA_CONFIG_FORCED)
385 enabled_str = " (forced disabled)";
386 else if (edev->state == 0)
387 enabled_str = " (disabled)";
391 dev_info(&edev->dev, "EISA: slot %d: %s detected%s\n", i,
392 edev->id.sig, enabled_str);
396 if (eisa_register_device(edev)) {
397 dev_err(&edev->dev, "EISA: Failed to register %s\n",
399 eisa_release_resources(edev);
404 dev_info(root->dev, "EISA: Detected %d card%s\n", c, c == 1 ? "" : "s");
408 static struct resource eisa_root_res = {
409 .name = "EISA root resource",
412 .flags = IORESOURCE_IO,
415 static int eisa_bus_count;
417 int __init eisa_root_register(struct eisa_root_device *root)
421 /* Use our own resources to check if this bus base address has
422 * been already registered. This prevents the virtual root
423 * device from registering after the real one has, for
426 root->eisa_root_res.name = eisa_root_res.name;
427 root->eisa_root_res.start = root->res->start;
428 root->eisa_root_res.end = root->res->end;
429 root->eisa_root_res.flags = IORESOURCE_BUSY;
431 err = request_resource(&eisa_root_res, &root->eisa_root_res);
435 root->bus_nr = eisa_bus_count++;
437 err = eisa_probe(root);
439 release_resource(&root->eisa_root_res);
444 static int __init eisa_init(void)
448 r = bus_register(&eisa_bus_type);
452 printk(KERN_INFO "EISA bus registered\n");
456 module_param_array(enable_dev, int, &enable_dev_count, 0444);
457 module_param_array(disable_dev, int, &disable_dev_count, 0444);
459 postcore_initcall(eisa_init);
461 int EISA_bus; /* for legacy drivers */
462 EXPORT_SYMBOL(EISA_bus);