aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pnp/resource.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pnp/resource.c')
-rw-r--r--drivers/pnp/resource.c102
1 files changed, 48 insertions, 54 deletions
diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
index a685fbec4604..ea6ec14a0559 100644
--- a/drivers/pnp/resource.c
+++ b/drivers/pnp/resource.c
@@ -3,7 +3,6 @@
3 * 3 *
4 * based on isapnp.c resource management (c) Jaroslav Kysela <perex@suse.cz> 4 * based on isapnp.c resource management (c) Jaroslav Kysela <perex@suse.cz>
5 * Copyright 2003 Adam Belay <ambx1@neo.rr.com> 5 * Copyright 2003 Adam Belay <ambx1@neo.rr.com>
6 *
7 */ 6 */
8 7
9#include <linux/module.h> 8#include <linux/module.h>
@@ -20,21 +19,19 @@
20#include <linux/pnp.h> 19#include <linux/pnp.h>
21#include "base.h" 20#include "base.h"
22 21
23static int pnp_reserve_irq[16] = { [0 ... 15] = -1 }; /* reserve (don't use) some IRQ */ 22static int pnp_reserve_irq[16] = {[0 ... 15] = -1 }; /* reserve (don't use) some IRQ */
24static int pnp_reserve_dma[8] = { [0 ... 7] = -1 }; /* reserve (don't use) some DMA */ 23static int pnp_reserve_dma[8] = {[0 ... 7] = -1 }; /* reserve (don't use) some DMA */
25static int pnp_reserve_io[16] = { [0 ... 15] = -1 }; /* reserve (don't use) some I/O region */ 24static int pnp_reserve_io[16] = {[0 ... 15] = -1 }; /* reserve (don't use) some I/O region */
26static int pnp_reserve_mem[16] = { [0 ... 15] = -1 }; /* reserve (don't use) some memory region */ 25static int pnp_reserve_mem[16] = {[0 ... 15] = -1 }; /* reserve (don't use) some memory region */
27
28 26
29/* 27/*
30 * option registration 28 * option registration
31 */ 29 */
32 30
33static struct pnp_option * pnp_build_option(int priority) 31static struct pnp_option *pnp_build_option(int priority)
34{ 32{
35 struct pnp_option *option = pnp_alloc(sizeof(struct pnp_option)); 33 struct pnp_option *option = pnp_alloc(sizeof(struct pnp_option));
36 34
37 /* check if pnp_alloc ran out of memory */
38 if (!option) 35 if (!option)
39 return NULL; 36 return NULL;
40 37
@@ -46,9 +43,10 @@ static struct pnp_option * pnp_build_option(int priority)
46 return option; 43 return option;
47} 44}
48 45
49struct pnp_option * pnp_register_independent_option(struct pnp_dev *dev) 46struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev)
50{ 47{
51 struct pnp_option *option; 48 struct pnp_option *option;
49
52 if (!dev) 50 if (!dev)
53 return NULL; 51 return NULL;
54 52
@@ -61,9 +59,11 @@ struct pnp_option * pnp_register_independent_option(struct pnp_dev *dev)
61 return option; 59 return option;
62} 60}
63 61
64struct pnp_option * pnp_register_dependent_option(struct pnp_dev *dev, int priority) 62struct pnp_option *pnp_register_dependent_option(struct pnp_dev *dev,
63 int priority)
65{ 64{
66 struct pnp_option *option; 65 struct pnp_option *option;
66
67 if (!dev) 67 if (!dev)
68 return NULL; 68 return NULL;
69 69
@@ -82,6 +82,7 @@ struct pnp_option * pnp_register_dependent_option(struct pnp_dev *dev, int prior
82int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data) 82int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data)
83{ 83{
84 struct pnp_irq *ptr; 84 struct pnp_irq *ptr;
85
85 if (!option) 86 if (!option)
86 return -EINVAL; 87 return -EINVAL;
87 if (!data) 88 if (!data)
@@ -110,6 +111,7 @@ int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data)
110int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data) 111int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data)
111{ 112{
112 struct pnp_dma *ptr; 113 struct pnp_dma *ptr;
114
113 if (!option) 115 if (!option)
114 return -EINVAL; 116 return -EINVAL;
115 if (!data) 117 if (!data)
@@ -129,6 +131,7 @@ int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data)
129int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data) 131int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data)
130{ 132{
131 struct pnp_port *ptr; 133 struct pnp_port *ptr;
134
132 if (!option) 135 if (!option)
133 return -EINVAL; 136 return -EINVAL;
134 if (!data) 137 if (!data)
@@ -148,6 +151,7 @@ int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data)
148int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data) 151int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data)
149{ 152{
150 struct pnp_mem *ptr; 153 struct pnp_mem *ptr;
154
151 if (!option) 155 if (!option)
152 return -EINVAL; 156 return -EINVAL;
153 if (!data) 157 if (!data)
@@ -222,7 +226,6 @@ void pnp_free_option(struct pnp_option *option)
222 } 226 }
223} 227}
224 228
225
226/* 229/*
227 * resource validity checking 230 * resource validity checking
228 */ 231 */
@@ -236,11 +239,12 @@ void pnp_free_option(struct pnp_option *option)
236#define cannot_compare(flags) \ 239#define cannot_compare(flags) \
237((flags) & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) 240((flags) & (IORESOURCE_UNSET | IORESOURCE_DISABLED))
238 241
239int pnp_check_port(struct pnp_dev * dev, int idx) 242int pnp_check_port(struct pnp_dev *dev, int idx)
240{ 243{
241 int tmp; 244 int tmp;
242 struct pnp_dev *tdev; 245 struct pnp_dev *tdev;
243 resource_size_t *port, *end, *tport, *tend; 246 resource_size_t *port, *end, *tport, *tend;
247
244 port = &dev->res.port_resource[idx].start; 248 port = &dev->res.port_resource[idx].start;
245 end = &dev->res.port_resource[idx].end; 249 end = &dev->res.port_resource[idx].end;
246 250
@@ -250,8 +254,8 @@ int pnp_check_port(struct pnp_dev * dev, int idx)
250 254
251 /* check if the resource is already in use, skip if the 255 /* check if the resource is already in use, skip if the
252 * device is active because it itself may be in use */ 256 * device is active because it itself may be in use */
253 if(!dev->active) { 257 if (!dev->active) {
254 if (__check_region(&ioport_resource, *port, length(port,end))) 258 if (__check_region(&ioport_resource, *port, length(port, end)))
255 return 0; 259 return 0;
256 } 260 }
257 261
@@ -259,7 +263,7 @@ int pnp_check_port(struct pnp_dev * dev, int idx)
259 for (tmp = 0; tmp < 8; tmp++) { 263 for (tmp = 0; tmp < 8; tmp++) {
260 int rport = pnp_reserve_io[tmp << 1]; 264 int rport = pnp_reserve_io[tmp << 1];
261 int rend = pnp_reserve_io[(tmp << 1) + 1] + rport - 1; 265 int rend = pnp_reserve_io[(tmp << 1) + 1] + rport - 1;
262 if (ranged_conflict(port,end,&rport,&rend)) 266 if (ranged_conflict(port, end, &rport, &rend))
263 return 0; 267 return 0;
264 } 268 }
265 269
@@ -268,7 +272,7 @@ int pnp_check_port(struct pnp_dev * dev, int idx)
268 if (dev->res.port_resource[tmp].flags & IORESOURCE_IO) { 272 if (dev->res.port_resource[tmp].flags & IORESOURCE_IO) {
269 tport = &dev->res.port_resource[tmp].start; 273 tport = &dev->res.port_resource[tmp].start;
270 tend = &dev->res.port_resource[tmp].end; 274 tend = &dev->res.port_resource[tmp].end;
271 if (ranged_conflict(port,end,tport,tend)) 275 if (ranged_conflict(port, end, tport, tend))
272 return 0; 276 return 0;
273 } 277 }
274 } 278 }
@@ -279,11 +283,12 @@ int pnp_check_port(struct pnp_dev * dev, int idx)
279 continue; 283 continue;
280 for (tmp = 0; tmp < PNP_MAX_PORT; tmp++) { 284 for (tmp = 0; tmp < PNP_MAX_PORT; tmp++) {
281 if (tdev->res.port_resource[tmp].flags & IORESOURCE_IO) { 285 if (tdev->res.port_resource[tmp].flags & IORESOURCE_IO) {
282 if (cannot_compare(tdev->res.port_resource[tmp].flags)) 286 if (cannot_compare
287 (tdev->res.port_resource[tmp].flags))
283 continue; 288 continue;
284 tport = &tdev->res.port_resource[tmp].start; 289 tport = &tdev->res.port_resource[tmp].start;
285 tend = &tdev->res.port_resource[tmp].end; 290 tend = &tdev->res.port_resource[tmp].end;
286 if (ranged_conflict(port,end,tport,tend)) 291 if (ranged_conflict(port, end, tport, tend))
287 return 0; 292 return 0;
288 } 293 }
289 } 294 }
@@ -292,11 +297,12 @@ int pnp_check_port(struct pnp_dev * dev, int idx)
292 return 1; 297 return 1;
293} 298}
294 299
295int pnp_check_mem(struct pnp_dev * dev, int idx) 300int pnp_check_mem(struct pnp_dev *dev, int idx)
296{ 301{
297 int tmp; 302 int tmp;
298 struct pnp_dev *tdev; 303 struct pnp_dev *tdev;
299 resource_size_t *addr, *end, *taddr, *tend; 304 resource_size_t *addr, *end, *taddr, *tend;
305
300 addr = &dev->res.mem_resource[idx].start; 306 addr = &dev->res.mem_resource[idx].start;
301 end = &dev->res.mem_resource[idx].end; 307 end = &dev->res.mem_resource[idx].end;
302 308
@@ -306,8 +312,8 @@ int pnp_check_mem(struct pnp_dev * dev, int idx)
306 312
307 /* check if the resource is already in use, skip if the 313 /* check if the resource is already in use, skip if the
308 * device is active because it itself may be in use */ 314 * device is active because it itself may be in use */
309 if(!dev->active) { 315 if (!dev->active) {
310 if (check_mem_region(*addr, length(addr,end))) 316 if (check_mem_region(*addr, length(addr, end)))
311 return 0; 317 return 0;
312 } 318 }
313 319
@@ -315,7 +321,7 @@ int pnp_check_mem(struct pnp_dev * dev, int idx)
315 for (tmp = 0; tmp < 8; tmp++) { 321 for (tmp = 0; tmp < 8; tmp++) {
316 int raddr = pnp_reserve_mem[tmp << 1]; 322 int raddr = pnp_reserve_mem[tmp << 1];
317 int rend = pnp_reserve_mem[(tmp << 1) + 1] + raddr - 1; 323 int rend = pnp_reserve_mem[(tmp << 1) + 1] + raddr - 1;
318 if (ranged_conflict(addr,end,&raddr,&rend)) 324 if (ranged_conflict(addr, end, &raddr, &rend))
319 return 0; 325 return 0;
320 } 326 }
321 327
@@ -324,7 +330,7 @@ int pnp_check_mem(struct pnp_dev * dev, int idx)
324 if (dev->res.mem_resource[tmp].flags & IORESOURCE_MEM) { 330 if (dev->res.mem_resource[tmp].flags & IORESOURCE_MEM) {
325 taddr = &dev->res.mem_resource[tmp].start; 331 taddr = &dev->res.mem_resource[tmp].start;
326 tend = &dev->res.mem_resource[tmp].end; 332 tend = &dev->res.mem_resource[tmp].end;
327 if (ranged_conflict(addr,end,taddr,tend)) 333 if (ranged_conflict(addr, end, taddr, tend))
328 return 0; 334 return 0;
329 } 335 }
330 } 336 }
@@ -335,11 +341,12 @@ int pnp_check_mem(struct pnp_dev * dev, int idx)
335 continue; 341 continue;
336 for (tmp = 0; tmp < PNP_MAX_MEM; tmp++) { 342 for (tmp = 0; tmp < PNP_MAX_MEM; tmp++) {
337 if (tdev->res.mem_resource[tmp].flags & IORESOURCE_MEM) { 343 if (tdev->res.mem_resource[tmp].flags & IORESOURCE_MEM) {
338 if (cannot_compare(tdev->res.mem_resource[tmp].flags)) 344 if (cannot_compare
345 (tdev->res.mem_resource[tmp].flags))
339 continue; 346 continue;
340 taddr = &tdev->res.mem_resource[tmp].start; 347 taddr = &tdev->res.mem_resource[tmp].start;
341 tend = &tdev->res.mem_resource[tmp].end; 348 tend = &tdev->res.mem_resource[tmp].end;
342 if (ranged_conflict(addr,end,taddr,tend)) 349 if (ranged_conflict(addr, end, taddr, tend))
343 return 0; 350 return 0;
344 } 351 }
345 } 352 }
@@ -353,11 +360,11 @@ static irqreturn_t pnp_test_handler(int irq, void *dev_id)
353 return IRQ_HANDLED; 360 return IRQ_HANDLED;
354} 361}
355 362
356int pnp_check_irq(struct pnp_dev * dev, int idx) 363int pnp_check_irq(struct pnp_dev *dev, int idx)
357{ 364{
358 int tmp; 365 int tmp;
359 struct pnp_dev *tdev; 366 struct pnp_dev *tdev;
360 resource_size_t * irq = &dev->res.irq_resource[idx].start; 367 resource_size_t *irq = &dev->res.irq_resource[idx].start;
361 368
362 /* if the resource doesn't exist, don't complain about it */ 369 /* if the resource doesn't exist, don't complain about it */
363 if (cannot_compare(dev->res.irq_resource[idx].flags)) 370 if (cannot_compare(dev->res.irq_resource[idx].flags))
@@ -394,9 +401,9 @@ int pnp_check_irq(struct pnp_dev * dev, int idx)
394 401
395 /* check if the resource is already in use, skip if the 402 /* check if the resource is already in use, skip if the
396 * device is active because it itself may be in use */ 403 * device is active because it itself may be in use */
397 if(!dev->active) { 404 if (!dev->active) {
398 if (request_irq(*irq, pnp_test_handler, 405 if (request_irq(*irq, pnp_test_handler,
399 IRQF_DISABLED|IRQF_PROBE_SHARED, "pnp", NULL)) 406 IRQF_DISABLED | IRQF_PROBE_SHARED, "pnp", NULL))
400 return 0; 407 return 0;
401 free_irq(*irq, NULL); 408 free_irq(*irq, NULL);
402 } 409 }
@@ -407,7 +414,8 @@ int pnp_check_irq(struct pnp_dev * dev, int idx)
407 continue; 414 continue;
408 for (tmp = 0; tmp < PNP_MAX_IRQ; tmp++) { 415 for (tmp = 0; tmp < PNP_MAX_IRQ; tmp++) {
409 if (tdev->res.irq_resource[tmp].flags & IORESOURCE_IRQ) { 416 if (tdev->res.irq_resource[tmp].flags & IORESOURCE_IRQ) {
410 if (cannot_compare(tdev->res.irq_resource[tmp].flags)) 417 if (cannot_compare
418 (tdev->res.irq_resource[tmp].flags))
411 continue; 419 continue;
412 if ((tdev->res.irq_resource[tmp].start == *irq)) 420 if ((tdev->res.irq_resource[tmp].start == *irq))
413 return 0; 421 return 0;
@@ -418,12 +426,12 @@ int pnp_check_irq(struct pnp_dev * dev, int idx)
418 return 1; 426 return 1;
419} 427}
420 428
421int pnp_check_dma(struct pnp_dev * dev, int idx) 429int pnp_check_dma(struct pnp_dev *dev, int idx)
422{ 430{
423#ifndef CONFIG_IA64 431#ifndef CONFIG_IA64
424 int tmp; 432 int tmp;
425 struct pnp_dev *tdev; 433 struct pnp_dev *tdev;
426 resource_size_t * dma = &dev->res.dma_resource[idx].start; 434 resource_size_t *dma = &dev->res.dma_resource[idx].start;
427 435
428 /* if the resource doesn't exist, don't complain about it */ 436 /* if the resource doesn't exist, don't complain about it */
429 if (cannot_compare(dev->res.dma_resource[idx].flags)) 437 if (cannot_compare(dev->res.dma_resource[idx].flags))
@@ -449,7 +457,7 @@ int pnp_check_dma(struct pnp_dev * dev, int idx)
449 457
450 /* check if the resource is already in use, skip if the 458 /* check if the resource is already in use, skip if the
451 * device is active because it itself may be in use */ 459 * device is active because it itself may be in use */
452 if(!dev->active) { 460 if (!dev->active) {
453 if (request_dma(*dma, "pnp")) 461 if (request_dma(*dma, "pnp"))
454 return 0; 462 return 0;
455 free_dma(*dma); 463 free_dma(*dma);
@@ -461,7 +469,8 @@ int pnp_check_dma(struct pnp_dev * dev, int idx)
461 continue; 469 continue;
462 for (tmp = 0; tmp < PNP_MAX_DMA; tmp++) { 470 for (tmp = 0; tmp < PNP_MAX_DMA; tmp++) {
463 if (tdev->res.dma_resource[tmp].flags & IORESOURCE_DMA) { 471 if (tdev->res.dma_resource[tmp].flags & IORESOURCE_DMA) {
464 if (cannot_compare(tdev->res.dma_resource[tmp].flags)) 472 if (cannot_compare
473 (tdev->res.dma_resource[tmp].flags))
465 continue; 474 continue;
466 if ((tdev->res.dma_resource[tmp].start == *dma)) 475 if ((tdev->res.dma_resource[tmp].start == *dma))
467 return 0; 476 return 0;
@@ -471,30 +480,18 @@ int pnp_check_dma(struct pnp_dev * dev, int idx)
471 480
472 return 1; 481 return 1;
473#else 482#else
474 /* IA64 hasn't legacy DMA */ 483 /* IA64 does not have legacy DMA */
475 return 0; 484 return 0;
476#endif 485#endif
477} 486}
478 487
479
480#if 0
481EXPORT_SYMBOL(pnp_register_dependent_option);
482EXPORT_SYMBOL(pnp_register_independent_option);
483EXPORT_SYMBOL(pnp_register_irq_resource);
484EXPORT_SYMBOL(pnp_register_dma_resource);
485EXPORT_SYMBOL(pnp_register_port_resource);
486EXPORT_SYMBOL(pnp_register_mem_resource);
487#endif /* 0 */
488
489
490/* format is: pnp_reserve_irq=irq1[,irq2] .... */ 488/* format is: pnp_reserve_irq=irq1[,irq2] .... */
491
492static int __init pnp_setup_reserve_irq(char *str) 489static int __init pnp_setup_reserve_irq(char *str)
493{ 490{
494 int i; 491 int i;
495 492
496 for (i = 0; i < 16; i++) 493 for (i = 0; i < 16; i++)
497 if (get_option(&str,&pnp_reserve_irq[i]) != 2) 494 if (get_option(&str, &pnp_reserve_irq[i]) != 2)
498 break; 495 break;
499 return 1; 496 return 1;
500} 497}
@@ -502,13 +499,12 @@ static int __init pnp_setup_reserve_irq(char *str)
502__setup("pnp_reserve_irq=", pnp_setup_reserve_irq); 499__setup("pnp_reserve_irq=", pnp_setup_reserve_irq);
503 500
504/* format is: pnp_reserve_dma=dma1[,dma2] .... */ 501/* format is: pnp_reserve_dma=dma1[,dma2] .... */
505
506static int __init pnp_setup_reserve_dma(char *str) 502static int __init pnp_setup_reserve_dma(char *str)
507{ 503{
508 int i; 504 int i;
509 505
510 for (i = 0; i < 8; i++) 506 for (i = 0; i < 8; i++)
511 if (get_option(&str,&pnp_reserve_dma[i]) != 2) 507 if (get_option(&str, &pnp_reserve_dma[i]) != 2)
512 break; 508 break;
513 return 1; 509 return 1;
514} 510}
@@ -516,13 +512,12 @@ static int __init pnp_setup_reserve_dma(char *str)
516__setup("pnp_reserve_dma=", pnp_setup_reserve_dma); 512__setup("pnp_reserve_dma=", pnp_setup_reserve_dma);
517 513
518/* format is: pnp_reserve_io=io1,size1[,io2,size2] .... */ 514/* format is: pnp_reserve_io=io1,size1[,io2,size2] .... */
519
520static int __init pnp_setup_reserve_io(char *str) 515static int __init pnp_setup_reserve_io(char *str)
521{ 516{
522 int i; 517 int i;
523 518
524 for (i = 0; i < 16; i++) 519 for (i = 0; i < 16; i++)
525 if (get_option(&str,&pnp_reserve_io[i]) != 2) 520 if (get_option(&str, &pnp_reserve_io[i]) != 2)
526 break; 521 break;
527 return 1; 522 return 1;
528} 523}
@@ -530,13 +525,12 @@ static int __init pnp_setup_reserve_io(char *str)
530__setup("pnp_reserve_io=", pnp_setup_reserve_io); 525__setup("pnp_reserve_io=", pnp_setup_reserve_io);
531 526
532/* format is: pnp_reserve_mem=mem1,size1[,mem2,size2] .... */ 527/* format is: pnp_reserve_mem=mem1,size1[,mem2,size2] .... */
533
534static int __init pnp_setup_reserve_mem(char *str) 528static int __init pnp_setup_reserve_mem(char *str)
535{ 529{
536 int i; 530 int i;
537 531
538 for (i = 0; i < 16; i++) 532 for (i = 0; i < 16; i++)
539 if (get_option(&str,&pnp_reserve_mem[i]) != 2) 533 if (get_option(&str, &pnp_reserve_mem[i]) != 2)
540 break; 534 break;
541 return 1; 535 return 1;
542} 536}