bus_numa.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #include <linux/init.h>
  2. #include <linux/pci.h>
  3. #include <linux/range.h>
  4. #include "bus_numa.h"
  5. LIST_HEAD(pci_root_infos);
  6. static struct pci_root_info *x86_find_pci_root_info(int bus)
  7. {
  8. struct pci_root_info *info;
  9. if (list_empty(&pci_root_infos))
  10. return NULL;
  11. list_for_each_entry(info, &pci_root_infos, list)
  12. if (info->bus_min == bus)
  13. return info;
  14. return NULL;
  15. }
  16. void x86_pci_root_bus_resources(int bus, struct list_head *resources)
  17. {
  18. struct pci_root_info *info = x86_find_pci_root_info(bus);
  19. struct pci_root_res *root_res;
  20. if (!info)
  21. goto default_resources;
  22. printk(KERN_DEBUG "PCI: root bus %02x: hardware-probed resources\n",
  23. bus);
  24. list_for_each_entry(root_res, &info->resources, list) {
  25. struct resource *res;
  26. struct resource *root;
  27. res = &root_res->res;
  28. pci_add_resource(resources, res);
  29. if (res->flags & IORESOURCE_IO)
  30. root = &ioport_resource;
  31. else
  32. root = &iomem_resource;
  33. insert_resource(root, res);
  34. }
  35. return;
  36. default_resources:
  37. /*
  38. * We don't have any host bridge aperture information from the
  39. * "native host bridge drivers," e.g., amd_bus or broadcom_bus,
  40. * so fall back to the defaults historically used by pci_create_bus().
  41. */
  42. printk(KERN_DEBUG "PCI: root bus %02x: using default resources\n", bus);
  43. pci_add_resource(resources, &ioport_resource);
  44. pci_add_resource(resources, &iomem_resource);
  45. }
  46. struct pci_root_info __init *alloc_pci_root_info(int bus_min, int bus_max,
  47. int node, int link)
  48. {
  49. struct pci_root_info *info;
  50. info = kzalloc(sizeof(*info), GFP_KERNEL);
  51. if (!info)
  52. return info;
  53. INIT_LIST_HEAD(&info->resources);
  54. info->bus_min = bus_min;
  55. info->bus_max = bus_max;
  56. info->node = node;
  57. info->link = link;
  58. list_add_tail(&info->list, &pci_root_infos);
  59. return info;
  60. }
  61. void __devinit update_res(struct pci_root_info *info, resource_size_t start,
  62. resource_size_t end, unsigned long flags, int merge)
  63. {
  64. struct resource *res;
  65. struct pci_root_res *root_res;
  66. if (start > end)
  67. return;
  68. if (start == MAX_RESOURCE)
  69. return;
  70. if (!merge)
  71. goto addit;
  72. /* try to merge it with old one */
  73. list_for_each_entry(root_res, &info->resources, list) {
  74. resource_size_t final_start, final_end;
  75. resource_size_t common_start, common_end;
  76. res = &root_res->res;
  77. if (res->flags != flags)
  78. continue;
  79. common_start = max(res->start, start);
  80. common_end = min(res->end, end);
  81. if (common_start > common_end + 1)
  82. continue;
  83. final_start = min(res->start, start);
  84. final_end = max(res->end, end);
  85. res->start = final_start;
  86. res->end = final_end;
  87. return;
  88. }
  89. addit:
  90. /* need to add that */
  91. root_res = kzalloc(sizeof(*root_res), GFP_KERNEL);
  92. if (!root_res)
  93. return;
  94. res = &root_res->res;
  95. res->name = info->name;
  96. res->flags = flags;
  97. res->start = start;
  98. res->end = end;
  99. list_add_tail(&root_res->list, &info->resources);
  100. }