Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * EISA bus support functions for sysfs.
  4 *
  5 * (C) 2002, 2003 Marc Zyngier <maz@wild-wind.fr.eu.org>
 
 
  6 */
  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;
 24	char name[50];
 25};
 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];
 37static unsigned int enable_dev_count;
 38static int disable_dev[EISA_MAX_FORCED_DEV];
 39static unsigned int disable_dev_count;
 40
 41static int is_forced_dev(int *forced_tab,
 42			 int forced_count,
 43			 struct eisa_root_device *root,
 44			 struct eisa_device *edev)
 45{
 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
 57static void __init eisa_name_device(struct eisa_device *edev)
 58{
 59#ifdef CONFIG_EISA_NAMES
 60	int i;
 61	for (i = 0; i < EISA_INFOS; i++) {
 62		if (!strcmp(edev->id.sig, eisa_table[i].id.sig)) {
 63			strscpy(edev->pretty_name,
 64				eisa_table[i].name,
 65				sizeof(edev->pretty_name));
 66			return;
 67		}
 68	}
 69
 70	/* No name was found */
 71	sprintf(edev->pretty_name, "EISA device %.7s", edev->id.sig);
 72#endif
 73}
 74
 75static char __init *decode_eisa_sig(unsigned long addr)
 76{
 77	static char sig_str[EISA_SIG_LEN];
 78	u8 sig[4];
 79	u16 rev;
 80	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
 93		sig[i] = inb(addr + i);
 94
 95		if (!i && (sig[0] & 0x80))
 96			return NULL;
 97	}
 
 
 
 
 
 
 98
 99	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;
106}
107
108static int eisa_bus_match(struct device *dev, const struct device_driver *drv)
109{
110	struct eisa_device *edev = to_eisa_device(dev);
111	const struct eisa_driver *edrv = to_eisa_driver(drv);
112	const struct eisa_device_id *eids = edrv->id_table;
113
114	if (!eids)
115		return 0;
116
117	while (strlen(eids->sig)) {
118		if (!strcmp(eids->sig, edev->id.sig) &&
119		    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
130static int eisa_bus_uevent(const struct device *dev, struct kobj_uevent_env *env)
131{
132	const struct eisa_device *edev = to_eisa_device(dev);
133
134	add_uevent_var(env, "MODALIAS=" EISA_DEVICE_MODALIAS_FMT, edev->id.sig);
135	return 0;
136}
137
138struct bus_type eisa_bus_type = {
139	.name  = "eisa",
140	.match = eisa_bus_match,
141	.uevent = eisa_bus_uevent,
142};
143EXPORT_SYMBOL(eisa_bus_type);
144
145int eisa_driver_register(struct eisa_driver *edrv)
146{
147	edrv->driver.bus = &eisa_bus_type;
148	return driver_register(&edrv->driver);
149}
150EXPORT_SYMBOL(eisa_driver_register);
151
152void eisa_driver_unregister(struct eisa_driver *edrv)
153{
154	driver_unregister(&edrv->driver);
155}
156EXPORT_SYMBOL(eisa_driver_unregister);
157
158static ssize_t signature_show(struct device *dev,
159			      struct device_attribute *attr, char *buf)
160{
161	struct eisa_device *edev = to_eisa_device(dev);
162	return sprintf(buf, "%s\n", edev->id.sig);
163}
164static DEVICE_ATTR_RO(signature);
165
166static ssize_t enabled_show(struct device *dev,
167			    struct device_attribute *attr, char *buf)
 
 
 
168{
169	struct eisa_device *edev = to_eisa_device(dev);
170	return sprintf(buf, "%d\n", edev->state & EISA_CONFIG_ENABLED);
171}
172static DEVICE_ATTR_RO(enabled);
173
174static ssize_t modalias_show(struct device *dev,
175			     struct device_attribute *attr, char *buf)
 
 
 
176{
177	struct eisa_device *edev = to_eisa_device(dev);
178	return sprintf(buf, EISA_DEVICE_MODALIAS_FMT "\n", edev->id.sig);
179}
180static DEVICE_ATTR_RO(modalias);
 
181
182static int __init eisa_init_device(struct eisa_root_device *root,
183				   struct eisa_device *edev,
184				   int slot)
185{
186	char *sig;
187	unsigned long sig_addr;
188	int i;
189
190	sig_addr = SLOT_ADDRESS(root, slot) + EISA_VENDOR_ID_OFFSET;
191
192	sig = decode_eisa_sig(sig_addr);
193	if (!sig)
194		return -1;	/* No EISA device here */
195
196	memcpy(edev->id.sig, sig, EISA_SIG_LEN);
197	edev->slot = slot;
198	edev->state = inb(SLOT_ADDRESS(root, slot) + EISA_CONFIG_OFFSET)
199		      & EISA_CONFIG_ENABLED;
200	edev->base_addr = SLOT_ADDRESS(root, slot);
201	edev->dma_mask = root->dma_mask; /* Default DMA mask */
202	eisa_name_device(edev);
203	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;
207	dev_set_name(&edev->dev, "%02X:%02X", root->bus_nr, slot);
208
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
217	if (is_forced_dev(enable_dev, enable_dev_count, root, edev))
218		edev->state = EISA_CONFIG_ENABLED | EISA_CONFIG_FORCED;
219
220	if (is_forced_dev(disable_dev, disable_dev_count, root, edev))
221		edev->state = EISA_CONFIG_FORCED;
222
223	return 0;
224}
225
226static int __init eisa_register_device(struct eisa_device *edev)
227{
228	int rc = device_register(&edev->dev);
229	if (rc) {
230		put_device(&edev->dev);
231		return rc;
232	}
233
234	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;
243
244	return 0;
245
246err_enab:
247	device_remove_file(&edev->dev, &dev_attr_enabled);
248err_sig:
249	device_remove_file(&edev->dev, &dev_attr_signature);
250err_devreg:
251	device_unregister(&edev->dev);
252	return rc;
253}
254
255static int __init eisa_request_resources(struct eisa_root_device *root,
256					 struct eisa_device *edev,
257					 int slot)
258{
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		}
272
273		if (slot) {
274			edev->res[i].name  = NULL;
275			edev->res[i].start = SLOT_ADDRESS(root, slot)
276					     + (i * 0x400);
277			edev->res[i].end   = edev->res[i].start + 0xff;
278			edev->res[i].flags = IORESOURCE_IO;
279		} else {
280			edev->res[i].name  = NULL;
281			edev->res[i].start = SLOT_ADDRESS(root, slot)
282					     + EISA_VENDOR_ID_OFFSET;
283			edev->res[i].end   = edev->res[i].start + 3;
284			edev->res[i].flags = IORESOURCE_IO | IORESOURCE_BUSY;
285		}
286
287		if (request_resource(root->res, &edev->res[i]))
288			goto failed;
289	}
290
291	return 0;
292
293 failed:
294	while (--i >= 0)
295		release_resource(&edev->res[i]);
296
297	return -1;
298}
299
300static void __init eisa_release_resources(struct eisa_device *edev)
301{
302	int i;
303
304	for (i = 0; i < EISA_MAX_RESOURCES; i++)
305		if (edev->res[i].start || edev->res[i].end)
306			release_resource(&edev->res[i]);
307}
308
309static int __init eisa_probe(struct eisa_root_device *root)
310{
311	int i, c;
312	struct eisa_device *edev;
313	char *enabled_str;
314
315	dev_info(root->dev, "Probing EISA bus %d\n", root->bus_nr);
316
317	/* First try to get hold of slot 0. If there is no device
318	 * here, simply fail, unless root->force_probe is set. */
319
320	edev = kzalloc(sizeof(*edev), GFP_KERNEL);
321	if (!edev)
 
322		return -ENOMEM;
323
 
324	if (eisa_request_resources(root, edev, 0)) {
325		dev_warn(root->dev,
326			 "EISA: Cannot allocate resource for mainboard\n");
327		kfree(edev);
328		if (!root->force_probe)
329			return -EBUSY;
330		goto force_probe;
331	}
332
333	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
341	dev_info(&edev->dev, "EISA: Mainboard %s detected\n", edev->id.sig);
342
343	if (eisa_register_device(edev)) {
344		dev_err(&edev->dev, "EISA: Failed to register %s\n",
345			edev->id.sig);
346		eisa_release_resources(edev);
347		kfree(edev);
348	}
349
350 force_probe:
351
352	for (c = 0, i = 1; i <= root->slots; i++) {
353		edev = kzalloc(sizeof(*edev), GFP_KERNEL);
354		if (!edev) {
355			dev_err(root->dev, "EISA: Out of memory for slot %d\n",
356				i);
357			continue;
358		}
359
360		if (eisa_request_resources(root, edev, i)) {
361			dev_warn(root->dev,
362				 "Cannot allocate resource for EISA slot %d\n",
363				 i);
364			kfree(edev);
365			continue;
366		}
367
368		if (eisa_init_device(root, edev, i)) {
369			eisa_release_resources(edev);
370			kfree(edev);
371			continue;
372		}
373
374		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 = "";
382
383		dev_info(&edev->dev, "EISA: slot %d: %s detected%s\n", i,
384			 edev->id.sig, enabled_str);
385
386		c++;
387
388		if (eisa_register_device(edev)) {
389			dev_err(&edev->dev, "EISA: Failed to register %s\n",
390				edev->id.sig);
391			eisa_release_resources(edev);
392			kfree(edev);
393		}
394	}
395
396	dev_info(root->dev, "EISA: Detected %d card%s\n", c, c == 1 ? "" : "s");
397	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
409int __init eisa_root_register(struct eisa_root_device *root)
410{
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... */
417
418	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
423	err = request_resource(&eisa_root_res, &root->eisa_root_res);
424	if (err)
425		return err;
426
427	root->bus_nr = eisa_bus_count++;
428
429	err = eisa_probe(root);
430	if (err)
431		release_resource(&root->eisa_root_res);
432
433	return err;
434}
435
436static int __init eisa_init(void)
437{
438	int r;
439
440	r = bus_register(&eisa_bus_type);
441	if (r)
442		return r;
443
444	printk(KERN_INFO "EISA bus registered\n");
445	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
451postcore_initcall(eisa_init);
452
453int EISA_bus;		/* for legacy drivers */
454EXPORT_SYMBOL(EISA_bus);
v3.15
 
  1/*
  2 * EISA bus support functions for sysfs.
  3 *
  4 * (C) 2002, 2003 Marc Zyngier <maz@wild-wind.fr.eu.org>
  5 *
  6 * This code is released under the GPL version 2.
  7 */
  8
  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>
 17#include <asm/io.h>
 18
 19#define SLOT_ADDRESS(r,n) (r->bus_base_addr + (0x1000 * n))
 20
 21#define EISA_DEVINFO(i,s) { .id = { .sig = i }, .name = s }
 22
 23struct eisa_device_info {
 24	struct eisa_device_id id;
 25	char name[50];
 26};
 27
 28#ifdef CONFIG_EISA_NAMES
 29static struct eisa_device_info __initdata eisa_table[] = {
 30#include "devlist.h"
 31};
 32#define EISA_INFOS (sizeof (eisa_table) / (sizeof (struct eisa_device_info)))
 33#endif
 34
 35#define EISA_MAX_FORCED_DEV 16
 36
 37static int enable_dev[EISA_MAX_FORCED_DEV];
 38static unsigned int enable_dev_count;
 39static int disable_dev[EISA_MAX_FORCED_DEV];
 40static unsigned int disable_dev_count;
 41
 42static int is_forced_dev(int *forced_tab,
 43			 int forced_count,
 44			 struct eisa_root_device *root,
 45			 struct eisa_device *edev)
 46{
 47	int i, x;
 48
 49	for (i = 0; i < forced_count; i++) {
 50		x = (root->bus_nr << 8) | edev->slot;
 51		if (forced_tab[i] == x)
 52			return 1;
 53	}
 54
 55	return 0;
 56}
 57
 58static void __init eisa_name_device(struct eisa_device *edev)
 59{
 60#ifdef CONFIG_EISA_NAMES
 61	int i;
 62	for (i = 0; i < EISA_INFOS; i++) {
 63		if (!strcmp(edev->id.sig, eisa_table[i].id.sig)) {
 64			strlcpy(edev->pretty_name,
 65				eisa_table[i].name,
 66				sizeof(edev->pretty_name));
 67			return;
 68		}
 69	}
 70
 71	/* No name was found */
 72	sprintf(edev->pretty_name, "EISA device %.7s", edev->id.sig);
 73#endif
 74}
 75
 76static char __init *decode_eisa_sig(unsigned long addr)
 77{
 78        static char sig_str[EISA_SIG_LEN];
 79	u8 sig[4];
 80        u16 rev;
 81	int i;
 82
 83	for (i = 0; i < 4; i++) {
 84#ifdef CONFIG_EISA_VLB_PRIMING
 85		/*
 86		 * This ugly stuff is used to wake up VL-bus cards
 87		 * (AHA-284x is the only known example), so we can
 88		 * read the EISA id.
 89		 *
 90		 * Thankfully, this only exists on x86...
 91		 */
 92		outb(0x80 + i, addr);
 93#endif
 94		sig[i] = inb(addr + i);
 95
 96		if (!i && (sig[0] & 0x80))
 97			return NULL;
 98	}
 99	
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);
105
106        return sig_str;
 
 
 
 
 
 
107}
108
109static int eisa_bus_match(struct device *dev, struct device_driver *drv)
110{
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;
114
115	if (!eids)
116		return 0;
117
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;
122			return 1;
123		}
124
125		eids++;
126	}
127
128	return 0;
129}
130
131static int eisa_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
132{
133	struct eisa_device *edev = to_eisa_device(dev);
134
135	add_uevent_var(env, "MODALIAS=" EISA_DEVICE_MODALIAS_FMT, edev->id.sig);
136	return 0;
137}
138
139struct bus_type eisa_bus_type = {
140	.name  = "eisa",
141	.match = eisa_bus_match,
142	.uevent = eisa_bus_uevent,
143};
144EXPORT_SYMBOL(eisa_bus_type);
145
146int eisa_driver_register(struct eisa_driver *edrv)
147{
148	edrv->driver.bus = &eisa_bus_type;
149	return driver_register(&edrv->driver);
150}
151EXPORT_SYMBOL(eisa_driver_register);
152
153void eisa_driver_unregister(struct eisa_driver *edrv)
154{
155	driver_unregister(&edrv->driver);
156}
157EXPORT_SYMBOL(eisa_driver_unregister);
158
159static ssize_t eisa_show_sig(struct device *dev, struct device_attribute *attr,
160			     char *buf)
161{
162	struct eisa_device *edev = to_eisa_device(dev);
163	return sprintf(buf, "%s\n", edev->id.sig);
164}
 
165
166static DEVICE_ATTR(signature, S_IRUGO, eisa_show_sig, NULL);
167
168static ssize_t eisa_show_state(struct device *dev,
169			       struct device_attribute *attr,
170			       char *buf)
171{
172	struct eisa_device *edev = to_eisa_device(dev);
173	return sprintf(buf, "%d\n", edev->state & EISA_CONFIG_ENABLED);
174}
 
175
176static DEVICE_ATTR(enabled, S_IRUGO, eisa_show_state, NULL);
177
178static ssize_t eisa_show_modalias(struct device *dev,
179				  struct device_attribute *attr,
180				  char *buf)
181{
182	struct eisa_device *edev = to_eisa_device(dev);
183	return sprintf(buf, EISA_DEVICE_MODALIAS_FMT "\n", edev->id.sig);
184}
185
186static DEVICE_ATTR(modalias, S_IRUGO, eisa_show_modalias, NULL);
187
188static int __init eisa_init_device(struct eisa_root_device *root,
189				   struct eisa_device *edev,
190				   int slot)
191{
192	char *sig;
193	unsigned long sig_addr;
194	int i;
195
196	sig_addr = SLOT_ADDRESS(root, slot) + EISA_VENDOR_ID_OFFSET;
197
198	sig = decode_eisa_sig(sig_addr);
199	if (!sig)
200		return -1;	/* No EISA device here */
201	
202	memcpy(edev->id.sig, sig, EISA_SIG_LEN);
203	edev->slot = slot;
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);
214
215	for (i = 0; i < EISA_MAX_RESOURCES; i++) {
216#ifdef CONFIG_EISA_NAMES
217		edev->res[i].name = edev->pretty_name;
218#else
219		edev->res[i].name = edev->id.sig;
220#endif
221	}
222
223	if (is_forced_dev(enable_dev, enable_dev_count, root, edev))
224		edev->state = EISA_CONFIG_ENABLED | EISA_CONFIG_FORCED;
225	
226	if (is_forced_dev(disable_dev, disable_dev_count, root, edev))
227		edev->state = EISA_CONFIG_FORCED;
228
229	return 0;
230}
231
232static int __init eisa_register_device(struct eisa_device *edev)
233{
234	int rc = device_register(&edev->dev);
235	if (rc) {
236		put_device(&edev->dev);
237		return rc;
238	}
239
240	rc = device_create_file(&edev->dev, &dev_attr_signature);
241	if (rc)
242		goto err_devreg;
243	rc = device_create_file(&edev->dev, &dev_attr_enabled);
244	if (rc)
245		goto err_sig;
246	rc = device_create_file(&edev->dev, &dev_attr_modalias);
247	if (rc)
248		goto err_enab;
249
250	return 0;
251
252err_enab:
253	device_remove_file(&edev->dev, &dev_attr_enabled);
254err_sig:
255	device_remove_file(&edev->dev, &dev_attr_signature);
256err_devreg:
257	device_unregister(&edev->dev);
258	return rc;
259}
260
261static int __init eisa_request_resources(struct eisa_root_device *root,
262					 struct eisa_device *edev,
263					 int slot)
264{
265	int i;
266
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.
271		 */
272
273		/* Only one region for mainboard */
274		if (!slot && i > 0) {
275			edev->res[i].start = edev->res[i].end = 0;
276			continue;
277		}
278		
279		if (slot) {
280			edev->res[i].name  = NULL;
281			edev->res[i].start = SLOT_ADDRESS(root, slot)
282					     + (i * 0x400);
283			edev->res[i].end   = edev->res[i].start + 0xff;
284			edev->res[i].flags = IORESOURCE_IO;
285		} else {
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;
291		}
292
293		if (request_resource(root->res, &edev->res[i]))
294			goto failed;
295	}
296
297	return 0;
298	
299 failed:
300	while (--i >= 0)
301		release_resource(&edev->res[i]);
302
303	return -1;
304}
305
306static void __init eisa_release_resources(struct eisa_device *edev)
307{
308	int i;
309
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]);
313}
314
315static int __init eisa_probe(struct eisa_root_device *root)
316{
317        int i, c;
318	struct eisa_device *edev;
319	char *enabled_str;
320
321	dev_info(root->dev, "Probing EISA bus %d\n", root->bus_nr);
322
323	/* First try to get hold of slot 0. If there is no device
324	 * here, simply fail, unless root->force_probe is set. */
325	
326	edev = kzalloc(sizeof(*edev), GFP_KERNEL);
327	if (!edev) {
328		dev_err(root->dev, "EISA: Couldn't allocate mainboard slot\n");
329		return -ENOMEM;
330	}
331		
332	if (eisa_request_resources(root, edev, 0)) {
333		dev_warn(root->dev,
334		         "EISA: Cannot allocate resource for mainboard\n");
335		kfree(edev);
336		if (!root->force_probe)
337			return -EBUSY;
338		goto force_probe;
339	}
340
341	if (eisa_init_device(root, edev, 0)) {
342		eisa_release_resources(edev);
343		kfree(edev);
344		if (!root->force_probe)
345			return -ENODEV;
346		goto force_probe;
347	}
348
349	dev_info(&edev->dev, "EISA: Mainboard %s detected\n", edev->id.sig);
350
351	if (eisa_register_device(edev)) {
352		dev_err(&edev->dev, "EISA: Failed to register %s\n",
353		        edev->id.sig);
354		eisa_release_resources(edev);
355		kfree(edev);
356	}
357	
358 force_probe:
359	
360        for (c = 0, i = 1; i <= root->slots; i++) {
361		edev = kzalloc(sizeof(*edev), GFP_KERNEL);
362		if (!edev) {
363			dev_err(root->dev, "EISA: Out of memory for slot %d\n",
364				i);
365			continue;
366		}
367
368		if (eisa_request_resources(root, edev, i)) {
369			dev_warn(root->dev,
370			         "Cannot allocate resource for EISA slot %d\n",
371			         i);
372			kfree(edev);
373			continue;
374		}
375
376		if (eisa_init_device(root, edev, i)) {
377			eisa_release_resources(edev);
378			kfree(edev);
379			continue;
380		}
381
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)";
388		else
389			enabled_str = "";
390
391		dev_info(&edev->dev, "EISA: slot %d: %s detected%s\n", i,
392			 edev->id.sig, enabled_str);
393
394		c++;
395
396		if (eisa_register_device(edev)) {
397			dev_err(&edev->dev, "EISA: Failed to register %s\n",
398			        edev->id.sig);
399			eisa_release_resources(edev);
400			kfree(edev);
401		}
402        }
403
404	dev_info(root->dev, "EISA: Detected %d card%s\n", c, c == 1 ? "" : "s");
405	return 0;
406}
407
408static struct resource eisa_root_res = {
409	.name  = "EISA root resource",
410	.start = 0,
411	.end   = 0xffffffff,
412	.flags = IORESOURCE_IO,
413};
414
415static int eisa_bus_count;
416
417int __init eisa_root_register(struct eisa_root_device *root)
418{
419	int err;
420
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
424	 * example... */
425	
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;
430
431	err = request_resource(&eisa_root_res, &root->eisa_root_res);
432	if (err)
433		return err;
434	
435	root->bus_nr = eisa_bus_count++;
436
437	err = eisa_probe(root);
438	if (err)
439		release_resource(&root->eisa_root_res);
440
441	return err;
442}
443
444static int __init eisa_init(void)
445{
446	int r;
447	
448	r = bus_register(&eisa_bus_type);
449	if (r)
450		return r;
451
452	printk(KERN_INFO "EISA bus registered\n");
453	return 0;
454}
455
456module_param_array(enable_dev, int, &enable_dev_count, 0444);
457module_param_array(disable_dev, int, &disable_dev_count, 0444);
458
459postcore_initcall(eisa_init);
460
461int EISA_bus;		/* for legacy drivers */
462EXPORT_SYMBOL(EISA_bus);