system.c 2.8 KB

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