Commit ddb6ee51 authored by Marc Zyngier's avatar Marc Zyngier Committed by Linus Torvalds

[PATCH] EISA: core changes

- Now reserves I/O ranges according to EISA specs (four 256 bytes
  regions instead of a single 4KB region).

- By default, do not try to probe the bus if the mainboard does not
  seems to support EISA (allow this behaviour to be changed through a
  command-line option).

- Use parent bridge device dma_mask as default for each discovered
  device.

- Allow devices to be enabled or disabled from the kernel command line
  (useful for non-x86 platforms where the firmware simply disable
  devices it doesn't know about...).
parent ee389f0a
/* /*
* EISA bus support functions for sysfs. * EISA bus support functions for sysfs.
* *
* (C) 2002 Marc Zyngier <maz@wild-wind.fr.eu.org> * (C) 2002, 2003 Marc Zyngier <maz@wild-wind.fr.eu.org>
* *
* This code is released under the GPL version 2. * This code is released under the GPL version 2.
*/ */
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/eisa.h> #include <linux/eisa.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/ioport.h> #include <linux/ioport.h>
...@@ -24,7 +25,7 @@ struct eisa_device_info { ...@@ -24,7 +25,7 @@ struct eisa_device_info {
char name[DEVICE_NAME_SIZE]; char name[DEVICE_NAME_SIZE];
}; };
struct eisa_device_info __initdata eisa_table[] = { static struct eisa_device_info __initdata eisa_table[] = {
#ifdef CONFIG_EISA_NAMES #ifdef CONFIG_EISA_NAMES
#include "devlist.h" #include "devlist.h"
#endif #endif
...@@ -32,6 +33,30 @@ struct eisa_device_info __initdata eisa_table[] = { ...@@ -32,6 +33,30 @@ struct eisa_device_info __initdata eisa_table[] = {
#define EISA_INFOS (sizeof (eisa_table) / (sizeof (struct eisa_device_info))) #define EISA_INFOS (sizeof (eisa_table) / (sizeof (struct eisa_device_info)))
#define EISA_MAX_FORCED_DEV 16
#define EISA_FORCED_OFFSET 2
static int enable_dev[EISA_MAX_FORCED_DEV + EISA_FORCED_OFFSET] = { 1, EISA_MAX_FORCED_DEV, };
static int disable_dev[EISA_MAX_FORCED_DEV + EISA_FORCED_OFFSET] = { 1, EISA_MAX_FORCED_DEV, };
static int is_forced_dev (int *forced_tab,
struct eisa_root_device *root,
struct eisa_device *edev)
{
int i, x;
for (i = 0; i < EISA_MAX_FORCED_DEV; i++) {
if (!forced_tab[EISA_FORCED_OFFSET + i])
return 0;
x = (root->bus_nr << 8) | edev->slot;
if (forced_tab[EISA_FORCED_OFFSET + i] == x)
return 1;
}
return 0;
}
static void __init eisa_name_device (struct eisa_device *edev) static void __init eisa_name_device (struct eisa_device *edev)
{ {
int i; int i;
...@@ -92,7 +117,8 @@ static int eisa_bus_match (struct device *dev, struct device_driver *drv) ...@@ -92,7 +117,8 @@ static int eisa_bus_match (struct device *dev, struct device_driver *drv)
return 0; return 0;
while (strlen (eids->sig)) { while (strlen (eids->sig)) {
if (!strcmp (eids->sig, edev->id.sig)) { if (!strcmp (eids->sig, edev->id.sig) &&
edev->state & EISA_CONFIG_ENABLED) {
edev->id.driver_data = eids->driver_data; edev->id.driver_data = eids->driver_data;
return 1; return 1;
} }
...@@ -132,67 +158,169 @@ static ssize_t eisa_show_sig (struct device *dev, char *buf) ...@@ -132,67 +158,169 @@ static ssize_t eisa_show_sig (struct device *dev, char *buf)
static DEVICE_ATTR(signature, S_IRUGO, eisa_show_sig, NULL); static DEVICE_ATTR(signature, S_IRUGO, eisa_show_sig, NULL);
static int __init eisa_register_device (struct eisa_root_device *root, static ssize_t eisa_show_state (struct device *dev, char *buf)
{
struct eisa_device *edev = to_eisa_device (dev);
return sprintf (buf,"%d\n", edev->state & EISA_CONFIG_ENABLED);
}
static DEVICE_ATTR(enabled, S_IRUGO, eisa_show_state, NULL);
static int __init eisa_init_device (struct eisa_root_device *root,
struct eisa_device *edev, struct eisa_device *edev,
char *sig, int slot) int slot)
{ {
char *sig;
unsigned long sig_addr;
int i;
sig_addr = SLOT_ADDRESS (root, slot) + EISA_VENDOR_ID_OFFSET;
if (!(sig = decode_eisa_sig (sig_addr)))
return -1; /* No EISA device here */
memcpy (edev->id.sig, sig, EISA_SIG_LEN); memcpy (edev->id.sig, sig, EISA_SIG_LEN);
edev->slot = slot; edev->slot = slot;
edev->state = inb (SLOT_ADDRESS (root, slot) + EISA_CONFIG_OFFSET) & EISA_CONFIG_ENABLED;
edev->base_addr = SLOT_ADDRESS (root, slot); edev->base_addr = SLOT_ADDRESS (root, slot);
edev->dma_mask = 0xffffffff; /* Default DMA mask */ edev->dma_mask = root->dma_mask; /* Default DMA mask */
eisa_name_device (edev); eisa_name_device (edev);
edev->dev.parent = root->dev; edev->dev.parent = root->dev;
edev->dev.bus = &eisa_bus_type; edev->dev.bus = &eisa_bus_type;
edev->dev.dma_mask = &edev->dma_mask; edev->dev.dma_mask = &edev->dma_mask;
sprintf (edev->dev.bus_id, "%02X:%02X", root->bus_nr, slot); sprintf (edev->dev.bus_id, "%02X:%02X", root->bus_nr, slot);
edev->res.name = edev->dev.name; for (i = 0; i < EISA_MAX_RESOURCES; i++)
edev->res[i].name = edev->dev.name;
if (is_forced_dev (enable_dev, root, edev))
edev->state = EISA_CONFIG_ENABLED | EISA_CONFIG_FORCED;
if (is_forced_dev (disable_dev, root, edev))
edev->state = EISA_CONFIG_FORCED;
return 0;
}
static int __init eisa_register_device (struct eisa_device *edev)
{
if (device_register (&edev->dev)) if (device_register (&edev->dev))
return -1; return -1;
device_create_file (&edev->dev, &dev_attr_signature); device_create_file (&edev->dev, &dev_attr_signature);
device_create_file (&edev->dev, &dev_attr_enabled);
return 0; return 0;
} }
static int __init eisa_request_resources (struct eisa_root_device *root,
struct eisa_device *edev,
int slot)
{
int i;
for (i = 0; i < EISA_MAX_RESOURCES; i++) {
/* Don't register resource for slot 0, since this is
* very likely to fail... :-( Instead, grab the EISA
* id, now we can display something in /proc/ioports.
*/
/* Only one region for mainboard */
if (!slot && i > 0) {
edev->res[i].start = edev->res[i].end = 0;
continue;
}
if (slot) {
edev->res[i].name = NULL;
edev->res[i].start = SLOT_ADDRESS (root, slot) + (i * 0x400);
edev->res[i].end = edev->res[i].start + 0xff;
edev->res[i].flags = IORESOURCE_IO;
} else {
edev->res[i].name = NULL;
edev->res[i].start = SLOT_ADDRESS (root, slot) + EISA_VENDOR_ID_OFFSET;
edev->res[i].end = edev->res[i].start + 3;
edev->res[i].flags = IORESOURCE_BUSY;
}
if (request_resource (root->res, &edev->res[i]))
goto failed;
}
return 0;
failed:
while (--i >= 0)
release_resource (&edev->res[i]);
return -1;
}
static void __init eisa_release_resources (struct eisa_device *edev)
{
int i;
for (i = 0; i < EISA_MAX_RESOURCES; i++)
if (edev->res[i].start || edev->res[i].end)
release_resource (&edev->res[i]);
}
static int __init eisa_probe (struct eisa_root_device *root) static int __init eisa_probe (struct eisa_root_device *root)
{ {
int i, c; int i, c;
char *str;
unsigned long sig_addr;
struct eisa_device *edev; struct eisa_device *edev;
printk (KERN_INFO "EISA: Probing bus %d at %s\n", printk (KERN_INFO "EISA: Probing bus %d at %s\n",
root->bus_nr, root->dev->name); root->bus_nr, root->dev->name);
for (c = 0, i = 0; i <= root->slots; i++) { /* First try to get hold of slot 0. If there is no device
* here, simply fail, unless root->force_probe is set. */
if (!(edev = kmalloc (sizeof (*edev), GFP_KERNEL))) { if (!(edev = kmalloc (sizeof (*edev), GFP_KERNEL))) {
printk (KERN_ERR "EISA: Out of memory for slot %d\n", printk (KERN_ERR "EISA: Couldn't allocate mainboard slot\n");
i); return -ENOMEM;
continue;
} }
memset (edev, 0, sizeof (*edev)); memset (edev, 0, sizeof (*edev));
/* Don't register resource for slot 0, since this is if (eisa_request_resources (root, edev, 0)) {
* very likely to fail... :-( Instead, grab the EISA printk (KERN_WARNING \
* id, now we can display something in /proc/ioports. "EISA: Cannot allocate resource for mainboard\n");
*/ kfree (edev);
if (!root->force_probe)
return -EBUSY;
goto force_probe;
}
if (i) { if (eisa_init_device (root, edev, 0)) {
edev->res.name = NULL; eisa_release_resources (edev);
edev->res.start = SLOT_ADDRESS (root, i); kfree (edev);
edev->res.end = edev->res.start + 0xfff; if (!root->force_probe)
edev->res.flags = IORESOURCE_IO; return -ENODEV;
} else { goto force_probe;
edev->res.name = NULL;
edev->res.start = SLOT_ADDRESS (root, i) + EISA_VENDOR_ID_OFFSET;
edev->res.end = edev->res.start + 3;
edev->res.flags = IORESOURCE_BUSY;
} }
if (request_resource (root->res, &edev->res)) { printk (KERN_INFO "EISA: Mainboard %s detected.\n", edev->id.sig);
if (eisa_register_device (edev)) {
printk (KERN_ERR "EISA: Failed to register %s\n",
edev->id.sig);
eisa_release_resources (edev);
kfree (edev);
}
force_probe:
for (c = 0, i = 1; i <= root->slots; i++) {
if (!(edev = kmalloc (sizeof (*edev), GFP_KERNEL))) {
printk (KERN_ERR "EISA: Out of memory for slot %d\n",
i);
continue;
}
memset (edev, 0, sizeof (*edev));
if (eisa_request_resources (root, edev, i)) {
printk (KERN_WARNING \ printk (KERN_WARNING \
"Cannot allocate resource for EISA slot %d\n", "Cannot allocate resource for EISA slot %d\n",
i); i);
...@@ -200,30 +328,41 @@ static int __init eisa_probe (struct eisa_root_device *root) ...@@ -200,30 +328,41 @@ static int __init eisa_probe (struct eisa_root_device *root)
continue; continue;
} }
sig_addr = SLOT_ADDRESS (root, i) + EISA_VENDOR_ID_OFFSET; if (eisa_init_device (root, edev, i)) {
eisa_release_resources (edev);
if (!(str = decode_eisa_sig (sig_addr))) {
release_resource (&edev->res);
kfree (edev); kfree (edev);
continue; continue;
} }
if (!i) printk (KERN_INFO "EISA: slot %d : %s detected",
printk (KERN_INFO "EISA: Motherboard %s detected\n", i, edev->id.sig);
str);
else {
printk (KERN_INFO "EISA: slot %d : %s detected.\n",
i, str);
c++; switch (edev->state) {
case EISA_CONFIG_ENABLED | EISA_CONFIG_FORCED:
printk (" (forced enabled)");
break;
case EISA_CONFIG_FORCED:
printk (" (forced disabled)");
break;
case 0:
printk (" (disabled)");
break;
} }
if (eisa_register_device (root, edev, str, i)) { printk (".\n");
printk (KERN_ERR "EISA: Failed to register %s\n", str);
release_resource (&edev->res); c++;
if (eisa_register_device (edev)) {
printk (KERN_ERR "EISA: Failed to register %s\n",
edev->id.sig);
eisa_release_resources (edev);
kfree (edev); kfree (edev);
} }
} }
printk (KERN_INFO "EISA: Detected %d card%s.\n", c, c == 1 ? "" : "s"); printk (KERN_INFO "EISA: Detected %d card%s.\n", c, c == 1 ? "" : "s");
return 0; return 0;
...@@ -274,6 +413,13 @@ static int __init eisa_init (void) ...@@ -274,6 +413,13 @@ static int __init eisa_init (void)
return 0; return 0;
} }
/* Couldn't use intarray with checking on... :-( */
#undef param_check_intarray
#define param_check_intarray(name, p)
module_param(enable_dev, intarray, 0444);
module_param(disable_dev, intarray, 0444);
postcore_initcall (eisa_init); postcore_initcall (eisa_init);
EXPORT_SYMBOL (eisa_bus_type); EXPORT_SYMBOL (eisa_bus_type);
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#define EISA_SIG_LEN 8 #define EISA_SIG_LEN 8
#define EISA_MAX_SLOTS 8 #define EISA_MAX_SLOTS 8
#define EISA_MAX_RESOURCES 4
/* A few EISA constants/offsets... */ /* A few EISA constants/offsets... */
#define EISA_DMA1_STATUS 8 #define EISA_DMA1_STATUS 8
...@@ -17,6 +19,10 @@ ...@@ -17,6 +19,10 @@
#define EISA_INT1_EDGE_LEVEL 0x4D0 #define EISA_INT1_EDGE_LEVEL 0x4D0
#define EISA_INT2_EDGE_LEVEL 0x4D1 #define EISA_INT2_EDGE_LEVEL 0x4D1
#define EISA_VENDOR_ID_OFFSET 0xC80 #define EISA_VENDOR_ID_OFFSET 0xC80
#define EISA_CONFIG_OFFSET 0xC84
#define EISA_CONFIG_ENABLED 1
#define EISA_CONFIG_FORCED 2
/* The EISA signature, in ASCII form, null terminated */ /* The EISA signature, in ASCII form, null terminated */
struct eisa_device_id { struct eisa_device_id {
...@@ -26,19 +32,28 @@ struct eisa_device_id { ...@@ -26,19 +32,28 @@ struct eisa_device_id {
/* There is not much we can say about an EISA device, apart from /* There is not much we can say about an EISA device, apart from
* signature, slot number, and base address. dma_mask is set by * signature, slot number, and base address. dma_mask is set by
* default to 32 bits.*/ * default to parent device mask..*/
struct eisa_device { struct eisa_device {
struct eisa_device_id id; struct eisa_device_id id;
int slot; int slot;
int state;
unsigned long base_addr; unsigned long base_addr;
struct resource res; struct resource res[EISA_MAX_RESOURCES];
u64 dma_mask; u64 dma_mask;
struct device dev; /* generic device */ struct device dev; /* generic device */
}; };
#define to_eisa_device(n) container_of(n, struct eisa_device, dev) #define to_eisa_device(n) container_of(n, struct eisa_device, dev)
static inline int eisa_get_region_index (void *addr)
{
unsigned long x = (unsigned long) addr;
x &= 0xc00;
return (x >> 12);
}
struct eisa_driver { struct eisa_driver {
const struct eisa_device_id *id_table; const struct eisa_device_id *id_table;
struct device_driver driver; struct device_driver driver;
...@@ -69,6 +84,8 @@ struct eisa_root_device { ...@@ -69,6 +84,8 @@ struct eisa_root_device {
struct resource *res; struct resource *res;
unsigned long bus_base_addr; unsigned long bus_base_addr;
int slots; /* Max slot number */ int slots; /* Max slot number */
int force_probe; /* Probe even when no slot 0 */
u64 dma_mask; /* from bridge device */
int bus_nr; /* Set by eisa_root_register */ int bus_nr; /* Set by eisa_root_register */
struct resource eisa_root_res; /* ditto */ struct resource eisa_root_res; /* ditto */
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment