Linux Audio

Check our new training course

Loading...
v3.1
 
  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		return rc;
 
237
238	rc = device_create_file(&edev->dev, &dev_attr_signature);
239	if (rc)
240		goto err_devreg;
241	rc = device_create_file(&edev->dev, &dev_attr_enabled);
242	if (rc)
243		goto err_sig;
244	rc = device_create_file(&edev->dev, &dev_attr_modalias);
245	if (rc)
246		goto err_enab;
247
248	return 0;
249
250err_enab:
251	device_remove_file(&edev->dev, &dev_attr_enabled);
252err_sig:
253	device_remove_file(&edev->dev, &dev_attr_signature);
254err_devreg:
255	device_unregister(&edev->dev);
256	return rc;
257}
258
259static int __init eisa_request_resources(struct eisa_root_device *root,
260					 struct eisa_device *edev,
261					 int slot)
262{
263	int i;
264
265	for (i = 0; i < EISA_MAX_RESOURCES; i++) {
266		/* Don't register resource for slot 0, since this is
267		 * very likely to fail... :-( Instead, grab the EISA
268		 * id, now we can display something in /proc/ioports.
269		 */
270
271		/* Only one region for mainboard */
272		if (!slot && i > 0) {
273			edev->res[i].start = edev->res[i].end = 0;
274			continue;
275		}
276		
277		if (slot) {
278			edev->res[i].name  = NULL;
279			edev->res[i].start = SLOT_ADDRESS(root, slot)
280					     + (i * 0x400);
281			edev->res[i].end   = edev->res[i].start + 0xff;
282			edev->res[i].flags = IORESOURCE_IO;
283		} else {
284			edev->res[i].name  = NULL;
285			edev->res[i].start = SLOT_ADDRESS(root, slot)
286					     + EISA_VENDOR_ID_OFFSET;
287			edev->res[i].end   = edev->res[i].start + 3;
288			edev->res[i].flags = IORESOURCE_BUSY;
289		}
290
291		if (request_resource(root->res, &edev->res[i]))
292			goto failed;
293	}
294
295	return 0;
296	
297 failed:
298	while (--i >= 0)
299		release_resource(&edev->res[i]);
300
301	return -1;
302}
303
304static void __init eisa_release_resources(struct eisa_device *edev)
305{
306	int i;
307
308	for (i = 0; i < EISA_MAX_RESOURCES; i++)
309		if (edev->res[i].start || edev->res[i].end)
310			release_resource(&edev->res[i]);
311}
312
313static int __init eisa_probe(struct eisa_root_device *root)
314{
315        int i, c;
316	struct eisa_device *edev;
 
317
318	printk(KERN_INFO "EISA: Probing bus %d at %s\n",
319	       root->bus_nr, dev_name(root->dev));
320
321	/* First try to get hold of slot 0. If there is no device
322	 * here, simply fail, unless root->force_probe is set. */
323	
324	edev = kzalloc(sizeof(*edev), GFP_KERNEL);
325	if (!edev) {
326		printk(KERN_ERR "EISA: Couldn't allocate mainboard slot\n");
327		return -ENOMEM;
328	}
329		
330	if (eisa_request_resources(root, edev, 0)) {
331		printk(KERN_WARNING \
332		       "EISA: Cannot allocate resource for mainboard\n");
333		kfree(edev);
334		if (!root->force_probe)
335			return -EBUSY;
336		goto force_probe;
337	}
338
339	if (eisa_init_device(root, edev, 0)) {
340		eisa_release_resources(edev);
341		kfree(edev);
342		if (!root->force_probe)
343			return -ENODEV;
344		goto force_probe;
345	}
346
347	printk(KERN_INFO "EISA: Mainboard %s detected.\n", edev->id.sig);
348
349	if (eisa_register_device(edev)) {
350		printk(KERN_ERR "EISA: Failed to register %s\n",
351		       edev->id.sig);
352		eisa_release_resources(edev);
353		kfree(edev);
354	}
355	
356 force_probe:
357	
358        for (c = 0, i = 1; i <= root->slots; i++) {
359		edev = kzalloc(sizeof(*edev), GFP_KERNEL);
360		if (!edev) {
361			printk(KERN_ERR "EISA: Out of memory for slot %d\n", i);
 
362			continue;
363		}
364
365		if (eisa_request_resources(root, edev, i)) {
366			printk(KERN_WARNING \
367			       "Cannot allocate resource for EISA slot %d\n",
368			       i);
369			kfree(edev);
370			continue;
371		}
372
373		if (eisa_init_device(root, edev, i)) {
374			eisa_release_resources(edev);
375			kfree(edev);
376			continue;
377		}
378		
379		printk(KERN_INFO "EISA: slot %d : %s detected",
380		       i, edev->id.sig);
381			
382		switch (edev->state) {
383		case EISA_CONFIG_ENABLED | EISA_CONFIG_FORCED:
384			printk(" (forced enabled)");
385			break;
386
387		case EISA_CONFIG_FORCED:
388			printk(" (forced disabled)");
389			break;
390
391		case 0:
392			printk(" (disabled)");
393			break;
394		}
395			
396		printk (".\n");
397
398		c++;
399
400		if (eisa_register_device(edev)) {
401			printk(KERN_ERR "EISA: Failed to register %s\n",
402			       edev->id.sig);
403			eisa_release_resources(edev);
404			kfree(edev);
405		}
406        }
407
408	printk(KERN_INFO "EISA: Detected %d card%s.\n", c, c == 1 ? "" : "s");
409
 
410	return 0;
411}
412
413static struct resource eisa_root_res = {
414	.name  = "EISA root resource",
415	.start = 0,
416	.end   = 0xffffffff,
417	.flags = IORESOURCE_IO,
418};
419
420static int eisa_bus_count;
421
422int __init eisa_root_register(struct eisa_root_device *root)
423{
424	int err;
425
426	/* Use our own resources to check if this bus base address has
427	 * been already registered. This prevents the virtual root
428	 * device from registering after the real one has, for
429	 * example... */
430	
431	root->eisa_root_res.name  = eisa_root_res.name;
432	root->eisa_root_res.start = root->res->start;
433	root->eisa_root_res.end   = root->res->end;
434	root->eisa_root_res.flags = IORESOURCE_BUSY;
435
436	err = request_resource(&eisa_root_res, &root->eisa_root_res);
437	if (err)
438		return err;
439	
440	root->bus_nr = eisa_bus_count++;
441
442	err = eisa_probe(root);
443	if (err)
444		release_resource(&root->eisa_root_res);
445
446	return err;
447}
448
449static int __init eisa_init(void)
450{
451	int r;
452	
453	r = bus_register(&eisa_bus_type);
454	if (r)
455		return r;
456
457	printk(KERN_INFO "EISA bus registered\n");
458	return 0;
459}
460
461module_param_array(enable_dev, int, &enable_dev_count, 0444);
462module_param_array(disable_dev, int, &disable_dev_count, 0444);
463
464postcore_initcall(eisa_init);
465
466int EISA_bus;		/* for legacy drivers */
467EXPORT_SYMBOL(EISA_bus);
v5.4
  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			strlcpy(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, struct device_driver *drv)
109{
110	struct eisa_device *edev = to_eisa_device(dev);
111	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(struct device *dev, struct kobj_uevent_env *env)
131{
132	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 eisa_show_sig(struct device *dev, struct device_attribute *attr,
159			     char *buf)
160{
161	struct eisa_device *edev = to_eisa_device(dev);
162	return sprintf(buf, "%s\n", edev->id.sig);
163}
164
165static DEVICE_ATTR(signature, S_IRUGO, eisa_show_sig, NULL);
166
167static ssize_t eisa_show_state(struct device *dev,
168			       struct device_attribute *attr,
169			       char *buf)
170{
171	struct eisa_device *edev = to_eisa_device(dev);
172	return sprintf(buf, "%d\n", edev->state & EISA_CONFIG_ENABLED);
173}
174
175static DEVICE_ATTR(enabled, S_IRUGO, eisa_show_state, NULL);
176
177static ssize_t eisa_show_modalias(struct device *dev,
178				  struct device_attribute *attr,
179				  char *buf)
180{
181	struct eisa_device *edev = to_eisa_device(dev);
182	return sprintf(buf, EISA_DEVICE_MODALIAS_FMT "\n", edev->id.sig);
183}
184
185static DEVICE_ATTR(modalias, S_IRUGO, eisa_show_modalias, NULL);
186
187static int __init eisa_init_device(struct eisa_root_device *root,
188				   struct eisa_device *edev,
189				   int slot)
190{
191	char *sig;
192	unsigned long sig_addr;
193	int i;
194
195	sig_addr = SLOT_ADDRESS(root, slot) + EISA_VENDOR_ID_OFFSET;
196
197	sig = decode_eisa_sig(sig_addr);
198	if (!sig)
199		return -1;	/* No EISA device here */
200
201	memcpy(edev->id.sig, sig, EISA_SIG_LEN);
202	edev->slot = slot;
203	edev->state = inb(SLOT_ADDRESS(root, slot) + EISA_CONFIG_OFFSET)
204		      & EISA_CONFIG_ENABLED;
205	edev->base_addr = SLOT_ADDRESS(root, slot);
206	edev->dma_mask = root->dma_mask; /* Default DMA mask */
207	eisa_name_device(edev);
208	edev->dev.parent = root->dev;
209	edev->dev.bus = &eisa_bus_type;
210	edev->dev.dma_mask = &edev->dma_mask;
211	edev->dev.coherent_dma_mask = edev->dma_mask;
212	dev_set_name(&edev->dev, "%02X:%02X", root->bus_nr, slot);
213
214	for (i = 0; i < EISA_MAX_RESOURCES; i++) {
215#ifdef CONFIG_EISA_NAMES
216		edev->res[i].name = edev->pretty_name;
217#else
218		edev->res[i].name = edev->id.sig;
219#endif
220	}
221
222	if (is_forced_dev(enable_dev, enable_dev_count, root, edev))
223		edev->state = EISA_CONFIG_ENABLED | EISA_CONFIG_FORCED;
224
225	if (is_forced_dev(disable_dev, disable_dev_count, root, edev))
226		edev->state = EISA_CONFIG_FORCED;
227
228	return 0;
229}
230
231static int __init eisa_register_device(struct eisa_device *edev)
232{
233	int rc = device_register(&edev->dev);
234	if (rc) {
235		put_device(&edev->dev);
236		return rc;
237	}
238
239	rc = device_create_file(&edev->dev, &dev_attr_signature);
240	if (rc)
241		goto err_devreg;
242	rc = device_create_file(&edev->dev, &dev_attr_enabled);
243	if (rc)
244		goto err_sig;
245	rc = device_create_file(&edev->dev, &dev_attr_modalias);
246	if (rc)
247		goto err_enab;
248
249	return 0;
250
251err_enab:
252	device_remove_file(&edev->dev, &dev_attr_enabled);
253err_sig:
254	device_remove_file(&edev->dev, &dev_attr_signature);
255err_devreg:
256	device_unregister(&edev->dev);
257	return rc;
258}
259
260static int __init eisa_request_resources(struct eisa_root_device *root,
261					 struct eisa_device *edev,
262					 int slot)
263{
264	int i;
265
266	for (i = 0; i < EISA_MAX_RESOURCES; i++) {
267		/* Don't register resource for slot 0, since this is
268		 * very likely to fail... :-( Instead, grab the EISA
269		 * id, now we can display something in /proc/ioports.
270		 */
271
272		/* Only one region for mainboard */
273		if (!slot && i > 0) {
274			edev->res[i].start = edev->res[i].end = 0;
275			continue;
276		}
277
278		if (slot) {
279			edev->res[i].name  = NULL;
280			edev->res[i].start = SLOT_ADDRESS(root, slot)
281					     + (i * 0x400);
282			edev->res[i].end   = edev->res[i].start + 0xff;
283			edev->res[i].flags = IORESOURCE_IO;
284		} else {
285			edev->res[i].name  = NULL;
286			edev->res[i].start = SLOT_ADDRESS(root, slot)
287					     + EISA_VENDOR_ID_OFFSET;
288			edev->res[i].end   = edev->res[i].start + 3;
289			edev->res[i].flags = IORESOURCE_IO | IORESOURCE_BUSY;
290		}
291
292		if (request_resource(root->res, &edev->res[i]))
293			goto failed;
294	}
295
296	return 0;
297
298 failed:
299	while (--i >= 0)
300		release_resource(&edev->res[i]);
301
302	return -1;
303}
304
305static void __init eisa_release_resources(struct eisa_device *edev)
306{
307	int i;
308
309	for (i = 0; i < EISA_MAX_RESOURCES; i++)
310		if (edev->res[i].start || edev->res[i].end)
311			release_resource(&edev->res[i]);
312}
313
314static int __init eisa_probe(struct eisa_root_device *root)
315{
316	int i, c;
317	struct eisa_device *edev;
318	char *enabled_str;
319
320	dev_info(root->dev, "Probing EISA bus %d\n", root->bus_nr);
 
321
322	/* First try to get hold of slot 0. If there is no device
323	 * here, simply fail, unless root->force_probe is set. */
324
325	edev = kzalloc(sizeof(*edev), GFP_KERNEL);
326	if (!edev)
 
327		return -ENOMEM;
328
 
329	if (eisa_request_resources(root, edev, 0)) {
330		dev_warn(root->dev,
331			 "EISA: Cannot allocate resource for mainboard\n");
332		kfree(edev);
333		if (!root->force_probe)
334			return -EBUSY;
335		goto force_probe;
336	}
337
338	if (eisa_init_device(root, edev, 0)) {
339		eisa_release_resources(edev);
340		kfree(edev);
341		if (!root->force_probe)
342			return -ENODEV;
343		goto force_probe;
344	}
345
346	dev_info(&edev->dev, "EISA: Mainboard %s detected\n", edev->id.sig);
347
348	if (eisa_register_device(edev)) {
349		dev_err(&edev->dev, "EISA: Failed to register %s\n",
350			edev->id.sig);
351		eisa_release_resources(edev);
352		kfree(edev);
353	}
354
355 force_probe:
356
357	for (c = 0, i = 1; i <= root->slots; i++) {
358		edev = kzalloc(sizeof(*edev), GFP_KERNEL);
359		if (!edev) {
360			dev_err(root->dev, "EISA: Out of memory for slot %d\n",
361				i);
362			continue;
363		}
364
365		if (eisa_request_resources(root, edev, i)) {
366			dev_warn(root->dev,
367				 "Cannot allocate resource for EISA slot %d\n",
368				 i);
369			kfree(edev);
370			continue;
371		}
372
373		if (eisa_init_device(root, edev, i)) {
374			eisa_release_resources(edev);
375			kfree(edev);
376			continue;
377		}
378
379		if (edev->state == (EISA_CONFIG_ENABLED | EISA_CONFIG_FORCED))
380			enabled_str = " (forced enabled)";
381		else if (edev->state == EISA_CONFIG_FORCED)
382			enabled_str = " (forced disabled)";
383		else if (edev->state == 0)
384			enabled_str = " (disabled)";
385		else
386			enabled_str = "";
387
388		dev_info(&edev->dev, "EISA: slot %d: %s detected%s\n", i,
389			 edev->id.sig, enabled_str);
 
 
 
 
 
 
 
390
391		c++;
392
393		if (eisa_register_device(edev)) {
394			dev_err(&edev->dev, "EISA: Failed to register %s\n",
395				edev->id.sig);
396			eisa_release_resources(edev);
397			kfree(edev);
398		}
399	}
 
 
400
401	dev_info(root->dev, "EISA: Detected %d card%s\n", c, c == 1 ? "" : "s");
402	return 0;
403}
404
405static struct resource eisa_root_res = {
406	.name  = "EISA root resource",
407	.start = 0,
408	.end   = 0xffffffff,
409	.flags = IORESOURCE_IO,
410};
411
412static int eisa_bus_count;
413
414int __init eisa_root_register(struct eisa_root_device *root)
415{
416	int err;
417
418	/* Use our own resources to check if this bus base address has
419	 * been already registered. This prevents the virtual root
420	 * device from registering after the real one has, for
421	 * example... */
422
423	root->eisa_root_res.name  = eisa_root_res.name;
424	root->eisa_root_res.start = root->res->start;
425	root->eisa_root_res.end   = root->res->end;
426	root->eisa_root_res.flags = IORESOURCE_BUSY;
427
428	err = request_resource(&eisa_root_res, &root->eisa_root_res);
429	if (err)
430		return err;
431
432	root->bus_nr = eisa_bus_count++;
433
434	err = eisa_probe(root);
435	if (err)
436		release_resource(&root->eisa_root_res);
437
438	return err;
439}
440
441static int __init eisa_init(void)
442{
443	int r;
444
445	r = bus_register(&eisa_bus_type);
446	if (r)
447		return r;
448
449	printk(KERN_INFO "EISA bus registered\n");
450	return 0;
451}
452
453module_param_array(enable_dev, int, &enable_dev_count, 0444);
454module_param_array(disable_dev, int, &disable_dev_count, 0444);
455
456postcore_initcall(eisa_init);
457
458int EISA_bus;		/* for legacy drivers */
459EXPORT_SYMBOL(EISA_bus);