Thomas Gleixner | d1d24ed | 2019-05-28 10:10:13 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * EISA bus support functions for sysfs. |
| 4 | * |
| 5 | * (C) 2002, 2003 Marc Zyngier <maz@wild-wind.fr.eu.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 22 | struct eisa_device_info { |
| 23 | struct eisa_device_id id; |
Kay Sievers | ca52a49 | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 24 | char name[50]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | #ifdef CONFIG_EISA_NAMES |
| 28 | static 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 | |
| 36 | static int enable_dev[EISA_MAX_FORCED_DEV]; |
Al Viro | 64a6f95 | 2007-10-14 19:35:30 +0100 | [diff] [blame] | 37 | static unsigned int enable_dev_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | static int disable_dev[EISA_MAX_FORCED_DEV]; |
Al Viro | 64a6f95 | 2007-10-14 19:35:30 +0100 | [diff] [blame] | 39 | static unsigned int disable_dev_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 41 | static int is_forced_dev(int *forced_tab, |
| 42 | int forced_count, |
| 43 | struct eisa_root_device *root, |
| 44 | struct eisa_device *edev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 57 | static void __init eisa_name_device(struct eisa_device *edev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
| 59 | #ifdef CONFIG_EISA_NAMES |
| 60 | int i; |
| 61 | for (i = 0; i < EISA_INFOS; i++) { |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 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)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | return; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /* No name was found */ |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 71 | sprintf(edev->pretty_name, "EISA device %.7s", edev->id.sig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #endif |
| 73 | } |
| 74 | |
| 75 | static char __init *decode_eisa_sig(unsigned long addr) |
| 76 | { |
Ladislav Michl | 91809d2 | 2018-01-17 10:44:06 +0100 | [diff] [blame] | 77 | static char sig_str[EISA_SIG_LEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | u8 sig[4]; |
Ladislav Michl | 91809d2 | 2018-01-17 10:44:06 +0100 | [diff] [blame] | 79 | u16 rev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 93 | sig[i] = inb(addr + i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
| 95 | if (!i && (sig[0] & 0x80)) |
| 96 | return NULL; |
| 97 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Ladislav Michl | 91809d2 | 2018-01-17 10:44:06 +0100 | [diff] [blame] | 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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 108 | static int eisa_bus_match(struct device *dev, struct device_driver *drv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | { |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 110 | struct eisa_device *edev = to_eisa_device(dev); |
| 111 | struct eisa_driver *edrv = to_eisa_driver(drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | const struct eisa_device_id *eids = edrv->id_table; |
| 113 | |
| 114 | if (!eids) |
| 115 | return 0; |
| 116 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 117 | while (strlen(eids->sig)) { |
| 118 | if (!strcmp(eids->sig, edev->id.sig) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 130 | static int eisa_bus_uevent(struct device *dev, struct kobj_uevent_env *env) |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 131 | { |
| 132 | struct eisa_device *edev = to_eisa_device(dev); |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 133 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 134 | add_uevent_var(env, "MODALIAS=" EISA_DEVICE_MODALIAS_FMT, edev->id.sig); |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 135 | return 0; |
| 136 | } |
| 137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | struct bus_type eisa_bus_type = { |
| 139 | .name = "eisa", |
| 140 | .match = eisa_bus_match, |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 141 | .uevent = eisa_bus_uevent, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | }; |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 143 | EXPORT_SYMBOL(eisa_bus_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 145 | int eisa_driver_register(struct eisa_driver *edrv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | edrv->driver.bus = &eisa_bus_type; |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 148 | return driver_register(&edrv->driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | } |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 150 | EXPORT_SYMBOL(eisa_driver_register); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 152 | void eisa_driver_unregister(struct eisa_driver *edrv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | { |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 154 | driver_unregister(&edrv->driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | } |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 156 | EXPORT_SYMBOL(eisa_driver_unregister); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 158 | static ssize_t eisa_show_sig(struct device *dev, struct device_attribute *attr, |
| 159 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | { |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 161 | struct eisa_device *edev = to_eisa_device(dev); |
| 162 | return sprintf(buf, "%s\n", edev->id.sig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | static DEVICE_ATTR(signature, S_IRUGO, eisa_show_sig, NULL); |
| 166 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 167 | static ssize_t eisa_show_state(struct device *dev, |
| 168 | struct device_attribute *attr, |
| 169 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | { |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 171 | struct eisa_device *edev = to_eisa_device(dev); |
| 172 | return sprintf(buf, "%d\n", edev->state & EISA_CONFIG_ENABLED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | static DEVICE_ATTR(enabled, S_IRUGO, eisa_show_state, NULL); |
| 176 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 177 | static ssize_t eisa_show_modalias(struct device *dev, |
| 178 | struct device_attribute *attr, |
| 179 | char *buf) |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 180 | { |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 181 | struct eisa_device *edev = to_eisa_device(dev); |
| 182 | return sprintf(buf, EISA_DEVICE_MODALIAS_FMT "\n", edev->id.sig); |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | static DEVICE_ATTR(modalias, S_IRUGO, eisa_show_modalias, NULL); |
| 186 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 187 | static int __init eisa_init_device(struct eisa_root_device *root, |
| 188 | struct eisa_device *edev, |
| 189 | int slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | { |
| 191 | char *sig; |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 192 | unsigned long sig_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | int i; |
| 194 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 195 | sig_addr = SLOT_ADDRESS(root, slot) + EISA_VENDOR_ID_OFFSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 197 | sig = decode_eisa_sig(sig_addr); |
| 198 | if (!sig) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | return -1; /* No EISA device here */ |
Ladislav Michl | 91809d2 | 2018-01-17 10:44:06 +0100 | [diff] [blame] | 200 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 201 | memcpy(edev->id.sig, sig, EISA_SIG_LEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | edev->slot = slot; |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 203 | edev->state = inb(SLOT_ADDRESS(root, slot) + EISA_CONFIG_OFFSET) |
| 204 | & EISA_CONFIG_ENABLED; |
| 205 | edev->base_addr = SLOT_ADDRESS(root, slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | edev->dma_mask = root->dma_mask; /* Default DMA mask */ |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 207 | eisa_name_device(edev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Kay Sievers | e537b24 | 2009-03-24 16:38:22 -0700 | [diff] [blame] | 212 | dev_set_name(&edev->dev, "%02X:%02X", root->bus_nr, slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 222 | if (is_forced_dev(enable_dev, enable_dev_count, root, edev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | edev->state = EISA_CONFIG_ENABLED | EISA_CONFIG_FORCED; |
Ladislav Michl | 91809d2 | 2018-01-17 10:44:06 +0100 | [diff] [blame] | 224 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 225 | if (is_forced_dev(disable_dev, disable_dev_count, root, edev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | edev->state = EISA_CONFIG_FORCED; |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 231 | static int __init eisa_register_device(struct eisa_device *edev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | { |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 233 | int rc = device_register(&edev->dev); |
Levente Kurusa | 04df008 | 2013-12-13 19:39:54 +0100 | [diff] [blame] | 234 | if (rc) { |
| 235 | put_device(&edev->dev); |
Jeff Garzik | 42ddfd6 | 2006-10-11 01:22:22 -0700 | [diff] [blame] | 236 | return rc; |
Levente Kurusa | 04df008 | 2013-12-13 19:39:54 +0100 | [diff] [blame] | 237 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 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; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
| 249 | return 0; |
Jeff Garzik | 42ddfd6 | 2006-10-11 01:22:22 -0700 | [diff] [blame] | 250 | |
| 251 | err_enab: |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 252 | device_remove_file(&edev->dev, &dev_attr_enabled); |
Jeff Garzik | 42ddfd6 | 2006-10-11 01:22:22 -0700 | [diff] [blame] | 253 | err_sig: |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 254 | device_remove_file(&edev->dev, &dev_attr_signature); |
Jeff Garzik | 42ddfd6 | 2006-10-11 01:22:22 -0700 | [diff] [blame] | 255 | err_devreg: |
| 256 | device_unregister(&edev->dev); |
| 257 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 260 | static int __init eisa_request_resources(struct eisa_root_device *root, |
| 261 | struct eisa_device *edev, |
| 262 | int slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | } |
Ladislav Michl | 91809d2 | 2018-01-17 10:44:06 +0100 | [diff] [blame] | 277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | if (slot) { |
Bjorn Helgaas | 765ee51 | 2014-01-17 14:57:29 -0700 | [diff] [blame] | 279 | edev->res[i].name = NULL; |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 280 | edev->res[i].start = SLOT_ADDRESS(root, slot) |
| 281 | + (i * 0x400); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | edev->res[i].end = edev->res[i].start + 0xff; |
| 283 | edev->res[i].flags = IORESOURCE_IO; |
| 284 | } else { |
Bjorn Helgaas | 765ee51 | 2014-01-17 14:57:29 -0700 | [diff] [blame] | 285 | edev->res[i].name = NULL; |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 286 | edev->res[i].start = SLOT_ADDRESS(root, slot) |
| 287 | + EISA_VENDOR_ID_OFFSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | edev->res[i].end = edev->res[i].start + 3; |
Bjorn Helgaas | 7666825 | 2013-04-15 14:33:56 -0600 | [diff] [blame] | 289 | edev->res[i].flags = IORESOURCE_IO | IORESOURCE_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 292 | if (request_resource(root->res, &edev->res[i])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | goto failed; |
| 294 | } |
| 295 | |
| 296 | return 0; |
Ladislav Michl | 91809d2 | 2018-01-17 10:44:06 +0100 | [diff] [blame] | 297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | failed: |
| 299 | while (--i >= 0) |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 300 | release_resource(&edev->res[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
| 302 | return -1; |
| 303 | } |
| 304 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 305 | static void __init eisa_release_resources(struct eisa_device *edev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | { |
| 307 | int i; |
| 308 | |
| 309 | for (i = 0; i < EISA_MAX_RESOURCES; i++) |
| 310 | if (edev->res[i].start || edev->res[i].end) |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 311 | release_resource(&edev->res[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 314 | static int __init eisa_probe(struct eisa_root_device *root) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | { |
Ladislav Michl | 91809d2 | 2018-01-17 10:44:06 +0100 | [diff] [blame] | 316 | int i, c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | struct eisa_device *edev; |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 318 | char *enabled_str; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 320 | dev_info(root->dev, "Probing EISA bus %d\n", root->bus_nr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. */ |
Ladislav Michl | 91809d2 | 2018-01-17 10:44:06 +0100 | [diff] [blame] | 324 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 325 | edev = kzalloc(sizeof(*edev), GFP_KERNEL); |
Ladislav Michl | 3ea98d4 | 2018-01-17 10:45:01 +0100 | [diff] [blame] | 326 | if (!edev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | return -ENOMEM; |
Ladislav Michl | 91809d2 | 2018-01-17 10:44:06 +0100 | [diff] [blame] | 328 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 329 | if (eisa_request_resources(root, edev, 0)) { |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 330 | dev_warn(root->dev, |
Ladislav Michl | 91809d2 | 2018-01-17 10:44:06 +0100 | [diff] [blame] | 331 | "EISA: Cannot allocate resource for mainboard\n"); |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 332 | kfree(edev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | if (!root->force_probe) |
| 334 | return -EBUSY; |
| 335 | goto force_probe; |
| 336 | } |
| 337 | |
Bjorn Helgaas | 765ee51 | 2014-01-17 14:57:29 -0700 | [diff] [blame] | 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 | |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 346 | dev_info(&edev->dev, "EISA: Mainboard %s detected\n", edev->id.sig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 348 | if (eisa_register_device(edev)) { |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 349 | dev_err(&edev->dev, "EISA: Failed to register %s\n", |
Ladislav Michl | 91809d2 | 2018-01-17 10:44:06 +0100 | [diff] [blame] | 350 | edev->id.sig); |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 351 | eisa_release_resources(edev); |
| 352 | kfree(edev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | } |
Ladislav Michl | 91809d2 | 2018-01-17 10:44:06 +0100 | [diff] [blame] | 354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | force_probe: |
Ladislav Michl | 91809d2 | 2018-01-17 10:44:06 +0100 | [diff] [blame] | 356 | |
| 357 | for (c = 0, i = 1; i <= root->slots; i++) { |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 358 | edev = kzalloc(sizeof(*edev), GFP_KERNEL); |
| 359 | if (!edev) { |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 360 | dev_err(root->dev, "EISA: Out of memory for slot %d\n", |
| 361 | i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | continue; |
| 363 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
Bjorn Helgaas | 26abfee | 2013-04-15 14:34:02 -0600 | [diff] [blame] | 365 | if (eisa_request_resources(root, edev, i)) { |
| 366 | dev_warn(root->dev, |
Ladislav Michl | 91809d2 | 2018-01-17 10:44:06 +0100 | [diff] [blame] | 367 | "Cannot allocate resource for EISA slot %d\n", |
| 368 | i); |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 369 | kfree(edev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | continue; |
| 371 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
Bjorn Helgaas | 765ee51 | 2014-01-17 14:57:29 -0700 | [diff] [blame] | 373 | if (eisa_init_device(root, edev, i)) { |
| 374 | eisa_release_resources(edev); |
| 375 | kfree(edev); |
| 376 | continue; |
| 377 | } |
| 378 | |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 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 = ""; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 388 | dev_info(&edev->dev, "EISA: slot %d: %s detected%s\n", i, |
| 389 | edev->id.sig, enabled_str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
| 391 | c++; |
| 392 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 393 | if (eisa_register_device(edev)) { |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 394 | dev_err(&edev->dev, "EISA: Failed to register %s\n", |
Ladislav Michl | 91809d2 | 2018-01-17 10:44:06 +0100 | [diff] [blame] | 395 | edev->id.sig); |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 396 | eisa_release_resources(edev); |
| 397 | kfree(edev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | } |
Ladislav Michl | 91809d2 | 2018-01-17 10:44:06 +0100 | [diff] [blame] | 399 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
Bjorn Helgaas | 4cf9f24 | 2013-04-15 14:33:42 -0600 | [diff] [blame] | 401 | dev_info(root->dev, "EISA: Detected %d card%s\n", c, c == 1 ? "" : "s"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | return 0; |
| 403 | } |
| 404 | |
| 405 | static struct resource eisa_root_res = { |
| 406 | .name = "EISA root resource", |
| 407 | .start = 0, |
| 408 | .end = 0xffffffff, |
| 409 | .flags = IORESOURCE_IO, |
| 410 | }; |
| 411 | |
| 412 | static int eisa_bus_count; |
| 413 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 414 | int __init eisa_root_register(struct eisa_root_device *root) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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... */ |
Ladislav Michl | 91809d2 | 2018-01-17 10:44:06 +0100 | [diff] [blame] | 422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 428 | err = request_resource(&eisa_root_res, &root->eisa_root_res); |
| 429 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | return err; |
Ladislav Michl | 91809d2 | 2018-01-17 10:44:06 +0100 | [diff] [blame] | 431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | root->bus_nr = eisa_bus_count++; |
| 433 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 434 | err = eisa_probe(root); |
| 435 | if (err) |
| 436 | release_resource(&root->eisa_root_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
| 438 | return err; |
| 439 | } |
| 440 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 441 | static int __init eisa_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | { |
| 443 | int r; |
Ladislav Michl | 91809d2 | 2018-01-17 10:44:06 +0100 | [diff] [blame] | 444 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 445 | r = bus_register(&eisa_bus_type); |
| 446 | if (r) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | return r; |
| 448 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 449 | printk(KERN_INFO "EISA bus registered\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | return 0; |
| 451 | } |
| 452 | |
| 453 | module_param_array(enable_dev, int, &enable_dev_count, 0444); |
| 454 | module_param_array(disable_dev, int, &disable_dev_count, 0444); |
| 455 | |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 456 | postcore_initcall(eisa_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | |
| 458 | int EISA_bus; /* for legacy drivers */ |
Thadeu Lima de Souza Cascardo | 33fd797 | 2010-03-05 13:42:48 -0800 | [diff] [blame] | 459 | EXPORT_SYMBOL(EISA_bus); |