blob: 65bffde137e3f7066e38cd4b2ab0203588213585 [file] [log] [blame]
Thomas Gleixnerd1d24ed2019-05-28 10:10:13 -07001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * EISA bus support functions for sysfs.
4 *
5 * (C) 2002, 2003 Marc Zyngier <maz@wild-wind.fr.eu.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7
8#include <linux/kernel.h>
9#include <linux/device.h>
10#include <linux/eisa.h>
11#include <linux/module.h>
12#include <linux/moduleparam.h>
13#include <linux/init.h>
14#include <linux/slab.h>
15#include <linux/ioport.h>
16#include <asm/io.h>
17
18#define SLOT_ADDRESS(r,n) (r->bus_base_addr + (0x1000 * n))
19
20#define EISA_DEVINFO(i,s) { .id = { .sig = i }, .name = s }
21
22struct eisa_device_info {
23 struct eisa_device_id id;
Kay Sieversca52a492008-05-02 06:02:41 +020024 char name[50];
Linus Torvalds1da177e2005-04-16 15:20:36 -070025};
26
27#ifdef CONFIG_EISA_NAMES
28static struct eisa_device_info __initdata eisa_table[] = {
29#include "devlist.h"
30};
31#define EISA_INFOS (sizeof (eisa_table) / (sizeof (struct eisa_device_info)))
32#endif
33
34#define EISA_MAX_FORCED_DEV 16
35
36static int enable_dev[EISA_MAX_FORCED_DEV];
Al Viro64a6f952007-10-14 19:35:30 +010037static unsigned int enable_dev_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038static int disable_dev[EISA_MAX_FORCED_DEV];
Al Viro64a6f952007-10-14 19:35:30 +010039static unsigned int disable_dev_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -080041static int is_forced_dev(int *forced_tab,
42 int forced_count,
43 struct eisa_root_device *root,
44 struct eisa_device *edev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
46 int i, x;
47
48 for (i = 0; i < forced_count; i++) {
49 x = (root->bus_nr << 8) | edev->slot;
50 if (forced_tab[i] == x)
51 return 1;
52 }
53
54 return 0;
55}
56
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -080057static void __init eisa_name_device(struct eisa_device *edev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
59#ifdef CONFIG_EISA_NAMES
60 int i;
61 for (i = 0; i < EISA_INFOS; i++) {
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -080062 if (!strcmp(edev->id.sig, eisa_table[i].id.sig)) {
63 strlcpy(edev->pretty_name,
64 eisa_table[i].name,
65 sizeof(edev->pretty_name));
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 return;
67 }
68 }
69
70 /* No name was found */
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -080071 sprintf(edev->pretty_name, "EISA device %.7s", edev->id.sig);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#endif
73}
74
75static char __init *decode_eisa_sig(unsigned long addr)
76{
Ladislav Michl91809d22018-01-17 10:44:06 +010077 static char sig_str[EISA_SIG_LEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 u8 sig[4];
Ladislav Michl91809d22018-01-17 10:44:06 +010079 u16 rev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 int i;
81
82 for (i = 0; i < 4; i++) {
83#ifdef CONFIG_EISA_VLB_PRIMING
84 /*
85 * This ugly stuff is used to wake up VL-bus cards
86 * (AHA-284x is the only known example), so we can
87 * read the EISA id.
88 *
89 * Thankfully, this only exists on x86...
90 */
91 outb(0x80 + i, addr);
92#endif
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -080093 sig[i] = inb(addr + i);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95 if (!i && (sig[0] & 0x80))
96 return NULL;
97 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Ladislav Michl91809d22018-01-17 10:44:06 +010099 sig_str[0] = ((sig[0] >> 2) & 0x1f) + ('A' - 1);
100 sig_str[1] = (((sig[0] & 3) << 3) | (sig[1] >> 5)) + ('A' - 1);
101 sig_str[2] = (sig[1] & 0x1f) + ('A' - 1);
102 rev = (sig[2] << 8) | sig[3];
103 sprintf(sig_str + 3, "%04X", rev);
104
105 return sig_str;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106}
107
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800108static int eisa_bus_match(struct device *dev, struct device_driver *drv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800110 struct eisa_device *edev = to_eisa_device(dev);
111 struct eisa_driver *edrv = to_eisa_driver(drv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 const struct eisa_device_id *eids = edrv->id_table;
113
114 if (!eids)
115 return 0;
116
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800117 while (strlen(eids->sig)) {
118 if (!strcmp(eids->sig, edev->id.sig) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 edev->state & EISA_CONFIG_ENABLED) {
120 edev->id.driver_data = eids->driver_data;
121 return 1;
122 }
123
124 eids++;
125 }
126
127 return 0;
128}
129
Kay Sievers7eff2e72007-08-14 15:15:12 +0200130static int eisa_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
Michael Tokarev07563c72006-09-27 01:50:56 -0700131{
132 struct eisa_device *edev = to_eisa_device(dev);
Michael Tokarev07563c72006-09-27 01:50:56 -0700133
Kay Sievers7eff2e72007-08-14 15:15:12 +0200134 add_uevent_var(env, "MODALIAS=" EISA_DEVICE_MODALIAS_FMT, edev->id.sig);
Michael Tokarev07563c72006-09-27 01:50:56 -0700135 return 0;
136}
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138struct bus_type eisa_bus_type = {
139 .name = "eisa",
140 .match = eisa_bus_match,
Michael Tokarev07563c72006-09-27 01:50:56 -0700141 .uevent = eisa_bus_uevent,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142};
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800143EXPORT_SYMBOL(eisa_bus_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800145int eisa_driver_register(struct eisa_driver *edrv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 edrv->driver.bus = &eisa_bus_type;
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800148 return driver_register(&edrv->driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149}
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800150EXPORT_SYMBOL(eisa_driver_register);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800152void eisa_driver_unregister(struct eisa_driver *edrv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153{
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800154 driver_unregister(&edrv->driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155}
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800156EXPORT_SYMBOL(eisa_driver_unregister);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Zhen Lei39ee1562021-06-03 17:05:06 +0800158static ssize_t signature_show(struct device *dev,
159 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160{
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800161 struct eisa_device *edev = to_eisa_device(dev);
162 return sprintf(buf, "%s\n", edev->id.sig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
Zhen Lei39ee1562021-06-03 17:05:06 +0800164static DEVICE_ATTR_RO(signature);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Zhen Lei39ee1562021-06-03 17:05:06 +0800166static ssize_t enabled_show(struct device *dev,
167 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168{
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800169 struct eisa_device *edev = to_eisa_device(dev);
170 return sprintf(buf, "%d\n", edev->state & EISA_CONFIG_ENABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171}
Zhen Lei39ee1562021-06-03 17:05:06 +0800172static DEVICE_ATTR_RO(enabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Zhen Lei39ee1562021-06-03 17:05:06 +0800174static ssize_t modalias_show(struct device *dev,
175 struct device_attribute *attr, char *buf)
Michael Tokarev07563c72006-09-27 01:50:56 -0700176{
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800177 struct eisa_device *edev = to_eisa_device(dev);
178 return sprintf(buf, EISA_DEVICE_MODALIAS_FMT "\n", edev->id.sig);
Michael Tokarev07563c72006-09-27 01:50:56 -0700179}
Zhen Lei39ee1562021-06-03 17:05:06 +0800180static DEVICE_ATTR_RO(modalias);
Michael Tokarev07563c72006-09-27 01:50:56 -0700181
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800182static int __init eisa_init_device(struct eisa_root_device *root,
183 struct eisa_device *edev,
184 int slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185{
186 char *sig;
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800187 unsigned long sig_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 int i;
189
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800190 sig_addr = SLOT_ADDRESS(root, slot) + EISA_VENDOR_ID_OFFSET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800192 sig = decode_eisa_sig(sig_addr);
193 if (!sig)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 return -1; /* No EISA device here */
Ladislav Michl91809d22018-01-17 10:44:06 +0100195
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800196 memcpy(edev->id.sig, sig, EISA_SIG_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 edev->slot = slot;
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800198 edev->state = inb(SLOT_ADDRESS(root, slot) + EISA_CONFIG_OFFSET)
199 & EISA_CONFIG_ENABLED;
200 edev->base_addr = SLOT_ADDRESS(root, slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 edev->dma_mask = root->dma_mask; /* Default DMA mask */
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800202 eisa_name_device(edev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 edev->dev.parent = root->dev;
204 edev->dev.bus = &eisa_bus_type;
205 edev->dev.dma_mask = &edev->dma_mask;
206 edev->dev.coherent_dma_mask = edev->dma_mask;
Kay Sieverse537b242009-03-24 16:38:22 -0700207 dev_set_name(&edev->dev, "%02X:%02X", root->bus_nr, slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209 for (i = 0; i < EISA_MAX_RESOURCES; i++) {
210#ifdef CONFIG_EISA_NAMES
211 edev->res[i].name = edev->pretty_name;
212#else
213 edev->res[i].name = edev->id.sig;
214#endif
215 }
216
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800217 if (is_forced_dev(enable_dev, enable_dev_count, root, edev))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 edev->state = EISA_CONFIG_ENABLED | EISA_CONFIG_FORCED;
Ladislav Michl91809d22018-01-17 10:44:06 +0100219
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800220 if (is_forced_dev(disable_dev, disable_dev_count, root, edev))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 edev->state = EISA_CONFIG_FORCED;
222
223 return 0;
224}
225
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800226static int __init eisa_register_device(struct eisa_device *edev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227{
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800228 int rc = device_register(&edev->dev);
Levente Kurusa04df0082013-12-13 19:39:54 +0100229 if (rc) {
230 put_device(&edev->dev);
Jeff Garzik42ddfd62006-10-11 01:22:22 -0700231 return rc;
Levente Kurusa04df0082013-12-13 19:39:54 +0100232 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800234 rc = device_create_file(&edev->dev, &dev_attr_signature);
235 if (rc)
236 goto err_devreg;
237 rc = device_create_file(&edev->dev, &dev_attr_enabled);
238 if (rc)
239 goto err_sig;
240 rc = device_create_file(&edev->dev, &dev_attr_modalias);
241 if (rc)
242 goto err_enab;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244 return 0;
Jeff Garzik42ddfd62006-10-11 01:22:22 -0700245
246err_enab:
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800247 device_remove_file(&edev->dev, &dev_attr_enabled);
Jeff Garzik42ddfd62006-10-11 01:22:22 -0700248err_sig:
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800249 device_remove_file(&edev->dev, &dev_attr_signature);
Jeff Garzik42ddfd62006-10-11 01:22:22 -0700250err_devreg:
251 device_unregister(&edev->dev);
252 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253}
254
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800255static int __init eisa_request_resources(struct eisa_root_device *root,
256 struct eisa_device *edev,
257 int slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
259 int i;
260
261 for (i = 0; i < EISA_MAX_RESOURCES; i++) {
262 /* Don't register resource for slot 0, since this is
263 * very likely to fail... :-( Instead, grab the EISA
264 * id, now we can display something in /proc/ioports.
265 */
266
267 /* Only one region for mainboard */
268 if (!slot && i > 0) {
269 edev->res[i].start = edev->res[i].end = 0;
270 continue;
271 }
Ladislav Michl91809d22018-01-17 10:44:06 +0100272
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 if (slot) {
Bjorn Helgaas765ee512014-01-17 14:57:29 -0700274 edev->res[i].name = NULL;
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800275 edev->res[i].start = SLOT_ADDRESS(root, slot)
276 + (i * 0x400);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 edev->res[i].end = edev->res[i].start + 0xff;
278 edev->res[i].flags = IORESOURCE_IO;
279 } else {
Bjorn Helgaas765ee512014-01-17 14:57:29 -0700280 edev->res[i].name = NULL;
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800281 edev->res[i].start = SLOT_ADDRESS(root, slot)
282 + EISA_VENDOR_ID_OFFSET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 edev->res[i].end = edev->res[i].start + 3;
Bjorn Helgaas76668252013-04-15 14:33:56 -0600284 edev->res[i].flags = IORESOURCE_IO | IORESOURCE_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 }
286
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800287 if (request_resource(root->res, &edev->res[i]))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 goto failed;
289 }
290
291 return 0;
Ladislav Michl91809d22018-01-17 10:44:06 +0100292
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 failed:
294 while (--i >= 0)
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800295 release_resource(&edev->res[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
297 return -1;
298}
299
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800300static void __init eisa_release_resources(struct eisa_device *edev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
302 int i;
303
304 for (i = 0; i < EISA_MAX_RESOURCES; i++)
305 if (edev->res[i].start || edev->res[i].end)
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800306 release_resource(&edev->res[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307}
308
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800309static int __init eisa_probe(struct eisa_root_device *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
Ladislav Michl91809d22018-01-17 10:44:06 +0100311 int i, c;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 struct eisa_device *edev;
Bjorn Helgaas4cf9f242013-04-15 14:33:42 -0600313 char *enabled_str;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
Bjorn Helgaas4cf9f242013-04-15 14:33:42 -0600315 dev_info(root->dev, "Probing EISA bus %d\n", root->bus_nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317 /* First try to get hold of slot 0. If there is no device
318 * here, simply fail, unless root->force_probe is set. */
Ladislav Michl91809d22018-01-17 10:44:06 +0100319
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800320 edev = kzalloc(sizeof(*edev), GFP_KERNEL);
Ladislav Michl3ea98d42018-01-17 10:45:01 +0100321 if (!edev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 return -ENOMEM;
Ladislav Michl91809d22018-01-17 10:44:06 +0100323
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800324 if (eisa_request_resources(root, edev, 0)) {
Bjorn Helgaas4cf9f242013-04-15 14:33:42 -0600325 dev_warn(root->dev,
Ladislav Michl91809d22018-01-17 10:44:06 +0100326 "EISA: Cannot allocate resource for mainboard\n");
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800327 kfree(edev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 if (!root->force_probe)
329 return -EBUSY;
330 goto force_probe;
331 }
332
Bjorn Helgaas765ee512014-01-17 14:57:29 -0700333 if (eisa_init_device(root, edev, 0)) {
334 eisa_release_resources(edev);
335 kfree(edev);
336 if (!root->force_probe)
337 return -ENODEV;
338 goto force_probe;
339 }
340
Bjorn Helgaas4cf9f242013-04-15 14:33:42 -0600341 dev_info(&edev->dev, "EISA: Mainboard %s detected\n", edev->id.sig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800343 if (eisa_register_device(edev)) {
Bjorn Helgaas4cf9f242013-04-15 14:33:42 -0600344 dev_err(&edev->dev, "EISA: Failed to register %s\n",
Ladislav Michl91809d22018-01-17 10:44:06 +0100345 edev->id.sig);
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800346 eisa_release_resources(edev);
347 kfree(edev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 }
Ladislav Michl91809d22018-01-17 10:44:06 +0100349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 force_probe:
Ladislav Michl91809d22018-01-17 10:44:06 +0100351
352 for (c = 0, i = 1; i <= root->slots; i++) {
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800353 edev = kzalloc(sizeof(*edev), GFP_KERNEL);
354 if (!edev) {
Bjorn Helgaas4cf9f242013-04-15 14:33:42 -0600355 dev_err(root->dev, "EISA: Out of memory for slot %d\n",
356 i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 continue;
358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Bjorn Helgaas26abfee2013-04-15 14:34:02 -0600360 if (eisa_request_resources(root, edev, i)) {
361 dev_warn(root->dev,
Ladislav Michl91809d22018-01-17 10:44:06 +0100362 "Cannot allocate resource for EISA slot %d\n",
363 i);
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800364 kfree(edev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 continue;
366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Bjorn Helgaas765ee512014-01-17 14:57:29 -0700368 if (eisa_init_device(root, edev, i)) {
369 eisa_release_resources(edev);
370 kfree(edev);
371 continue;
372 }
373
Bjorn Helgaas4cf9f242013-04-15 14:33:42 -0600374 if (edev->state == (EISA_CONFIG_ENABLED | EISA_CONFIG_FORCED))
375 enabled_str = " (forced enabled)";
376 else if (edev->state == EISA_CONFIG_FORCED)
377 enabled_str = " (forced disabled)";
378 else if (edev->state == 0)
379 enabled_str = " (disabled)";
380 else
381 enabled_str = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Bjorn Helgaas4cf9f242013-04-15 14:33:42 -0600383 dev_info(&edev->dev, "EISA: slot %d: %s detected%s\n", i,
384 edev->id.sig, enabled_str);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
386 c++;
387
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800388 if (eisa_register_device(edev)) {
Bjorn Helgaas4cf9f242013-04-15 14:33:42 -0600389 dev_err(&edev->dev, "EISA: Failed to register %s\n",
Ladislav Michl91809d22018-01-17 10:44:06 +0100390 edev->id.sig);
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800391 eisa_release_resources(edev);
392 kfree(edev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 }
Ladislav Michl91809d22018-01-17 10:44:06 +0100394 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Bjorn Helgaas4cf9f242013-04-15 14:33:42 -0600396 dev_info(root->dev, "EISA: Detected %d card%s\n", c, c == 1 ? "" : "s");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 return 0;
398}
399
400static struct resource eisa_root_res = {
401 .name = "EISA root resource",
402 .start = 0,
403 .end = 0xffffffff,
404 .flags = IORESOURCE_IO,
405};
406
407static int eisa_bus_count;
408
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800409int __init eisa_root_register(struct eisa_root_device *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410{
411 int err;
412
413 /* Use our own resources to check if this bus base address has
414 * been already registered. This prevents the virtual root
415 * device from registering after the real one has, for
416 * example... */
Ladislav Michl91809d22018-01-17 10:44:06 +0100417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 root->eisa_root_res.name = eisa_root_res.name;
419 root->eisa_root_res.start = root->res->start;
420 root->eisa_root_res.end = root->res->end;
421 root->eisa_root_res.flags = IORESOURCE_BUSY;
422
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800423 err = request_resource(&eisa_root_res, &root->eisa_root_res);
424 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 return err;
Ladislav Michl91809d22018-01-17 10:44:06 +0100426
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 root->bus_nr = eisa_bus_count++;
428
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800429 err = eisa_probe(root);
430 if (err)
431 release_resource(&root->eisa_root_res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433 return err;
434}
435
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800436static int __init eisa_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
438 int r;
Ladislav Michl91809d22018-01-17 10:44:06 +0100439
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800440 r = bus_register(&eisa_bus_type);
441 if (r)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 return r;
443
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800444 printk(KERN_INFO "EISA bus registered\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 return 0;
446}
447
448module_param_array(enable_dev, int, &enable_dev_count, 0444);
449module_param_array(disable_dev, int, &disable_dev_count, 0444);
450
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800451postcore_initcall(eisa_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
453int EISA_bus; /* for legacy drivers */
Thadeu Lima de Souza Cascardo33fd7972010-03-05 13:42:48 -0800454EXPORT_SYMBOL(EISA_bus);