system.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. static void reserve_resources_of_dev(struct pnp_dev *dev)
  49. {
  50. int i;
  51. for (i = 0; i < PNP_MAX_PORT; i++) {
  52. if (!pnp_port_valid(dev, i))
  53. continue;
  54. if (pnp_port_start(dev, i) == 0)
  55. continue; /* disabled */
  56. if (pnp_port_start(dev, i) < 0x100)
  57. /*
  58. * Below 0x100 is only standard PC hardware
  59. * (pics, kbd, timer, dma, ...)
  60. * We should not get resource conflicts there,
  61. * and the kernel reserves these anyway
  62. * (see arch/i386/kernel/setup.c).
  63. * So, do nothing
  64. */
  65. continue;
  66. if (pnp_port_end(dev, i) < pnp_port_start(dev, i))
  67. continue; /* invalid */
  68. reserve_range(dev->dev.bus_id, pnp_port_start(dev, i),
  69. pnp_port_end(dev, i), 1);
  70. }
  71. for (i = 0; i < PNP_MAX_MEM; i++) {
  72. if (!pnp_mem_valid(dev, i))
  73. continue;
  74. reserve_range(dev->dev.bus_id, pnp_mem_start(dev, i),
  75. pnp_mem_end(dev, i), 0);
  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);