system.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * system.c - a driver for reserving pnp system resources
  3. *
  4. * Some code is based on pnpbios_core.c
  5. * Copyright 2002 Adam Belay <ambx1@neo.rr.com>
  6. *
  7. */
  8. #include <linux/pnp.h>
  9. #include <linux/device.h>
  10. #include <linux/init.h>
  11. #include <linux/slab.h>
  12. #include <linux/kernel.h>
  13. #include <linux/ioport.h>
  14. static const struct pnp_device_id pnp_dev_table[] = {
  15. /* General ID for reserving resources */
  16. { "PNP0c02", 0 },
  17. /* memory controller */
  18. { "PNP0c01", 0 },
  19. { "", 0 }
  20. };
  21. static void reserve_ioport_range(char *pnpid, int start, int end)
  22. {
  23. struct resource *res;
  24. char *regionid;
  25. regionid = kmalloc(16, GFP_KERNEL);
  26. if ( regionid == NULL )
  27. return;
  28. snprintf(regionid, 16, "pnp %s", pnpid);
  29. res = request_region(start,end-start+1,regionid);
  30. if ( res == NULL )
  31. kfree( regionid );
  32. else
  33. res->flags &= ~IORESOURCE_BUSY;
  34. /*
  35. * Failures at this point are usually harmless. pci quirks for
  36. * example do reserve stuff they know about too, so we may well
  37. * have double reservations.
  38. */
  39. printk(KERN_INFO
  40. "pnp: %s: ioport range 0x%x-0x%x %s reserved\n",
  41. pnpid, start, end,
  42. NULL != res ? "has been" : "could not be"
  43. );
  44. return;
  45. }
  46. static void reserve_resources_of_dev( struct pnp_dev *dev )
  47. {
  48. int i;
  49. for (i=0;i<PNP_MAX_PORT;i++) {
  50. if (!pnp_port_valid(dev, i))
  51. /* end of resources */
  52. continue;
  53. if (pnp_port_start(dev, i) == 0)
  54. /* disabled */
  55. /* Do nothing */
  56. continue;
  57. if (pnp_port_start(dev, i) < 0x100)
  58. /*
  59. * Below 0x100 is only standard PC hardware
  60. * (pics, kbd, timer, dma, ...)
  61. * We should not get resource conflicts there,
  62. * and the kernel reserves these anyway
  63. * (see arch/i386/kernel/setup.c).
  64. * So, do nothing
  65. */
  66. continue;
  67. if (pnp_port_end(dev, i) < pnp_port_start(dev, i))
  68. /* invalid endpoint */
  69. /* Do nothing */
  70. continue;
  71. reserve_ioport_range(
  72. dev->dev.bus_id,
  73. pnp_port_start(dev, i),
  74. pnp_port_end(dev, i)
  75. );
  76. }
  77. return;
  78. }
  79. static int system_pnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id)
  80. {
  81. reserve_resources_of_dev(dev);
  82. return 0;
  83. }
  84. static struct pnp_driver system_pnp_driver = {
  85. .name = "system",
  86. .id_table = pnp_dev_table,
  87. .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
  88. .probe = system_pnp_probe,
  89. .remove = NULL,
  90. };
  91. static int __init pnp_system_init(void)
  92. {
  93. return pnp_register_driver(&system_pnp_driver);
  94. }
  95. /**
  96. * Reserve motherboard resources after PCI claim BARs,
  97. * but before PCI assign resources for uninitialized PCI devices
  98. */
  99. fs_initcall(pnp_system_init);