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