bus_numa.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. list_for_each_entry(info, &pci_root_infos, list)
  10. if (info->busn.start == bus)
  11. return info;
  12. return NULL;
  13. }
  14. int x86_pci_root_bus_node(int bus)
  15. {
  16. struct pci_root_info *info = x86_find_pci_root_info(bus);
  17. if (!info)
  18. return NUMA_NO_NODE;
  19. return info->node;
  20. }
  21. void x86_pci_root_bus_resources(int bus, struct list_head *resources)
  22. {
  23. struct pci_root_info *info = x86_find_pci_root_info(bus);
  24. struct pci_root_res *root_res;
  25. struct resource_entry *window;
  26. bool found = false;
  27. if (!info)
  28. goto default_resources;
  29. printk(KERN_DEBUG "PCI: root bus %02x: hardware-probed resources\n",
  30. bus);
  31. /* already added by acpi ? */
  32. resource_list_for_each_entry(window, resources)
  33. if (window->res->flags & IORESOURCE_BUS) {
  34. found = true;
  35. break;
  36. }
  37. if (!found)
  38. pci_add_resource(resources, &info->busn);
  39. list_for_each_entry(root_res, &info->resources, list)
  40. pci_add_resource(resources, &root_res->res);
  41. return;
  42. default_resources:
  43. /*
  44. * We don't have any host bridge aperture information from the
  45. * "native host bridge drivers," e.g., amd_bus or broadcom_bus,
  46. * so fall back to the defaults historically used by pci_create_bus().
  47. */
  48. printk(KERN_DEBUG "PCI: root bus %02x: using default resources\n", bus);
  49. pci_add_resource(resources, &ioport_resource);
  50. pci_add_resource(resources, &iomem_resource);
  51. }
  52. struct pci_root_info __init *alloc_pci_root_info(int bus_min, int bus_max,
  53. int node, int link)
  54. {
  55. struct pci_root_info *info;
  56. info = kzalloc(sizeof(*info), GFP_KERNEL);
  57. if (!info)
  58. return info;
  59. sprintf(info->name, "PCI Bus #%02x", bus_min);
  60. INIT_LIST_HEAD(&info->resources);
  61. info->busn.name = info->name;
  62. info->busn.start = bus_min;
  63. info->busn.end = bus_max;
  64. info->busn.flags = IORESOURCE_BUS;
  65. info->node = node;
  66. info->link = link;
  67. list_add_tail(&info->list, &pci_root_infos);
  68. return info;
  69. }
  70. void update_res(struct pci_root_info *info, resource_size_t start,
  71. resource_size_t end, unsigned long flags, int merge)
  72. {
  73. struct resource *res;
  74. struct pci_root_res *root_res;
  75. if (start > end)
  76. return;
  77. if (start == MAX_RESOURCE)
  78. return;
  79. if (!merge)
  80. goto addit;
  81. /* try to merge it with old one */
  82. list_for_each_entry(root_res, &info->resources, list) {
  83. resource_size_t final_start, final_end;
  84. resource_size_t common_start, common_end;
  85. res = &root_res->res;
  86. if (res->flags != flags)
  87. continue;
  88. common_start = max(res->start, start);
  89. common_end = min(res->end, end);
  90. if (common_start > common_end + 1)
  91. continue;
  92. final_start = min(res->start, start);
  93. final_end = max(res->end, end);
  94. res->start = final_start;
  95. res->end = final_end;
  96. return;
  97. }
  98. addit:
  99. /* need to add that */
  100. root_res = kzalloc(sizeof(*root_res), GFP_KERNEL);
  101. if (!root_res)
  102. return;
  103. res = &root_res->res;
  104. res->name = info->name;
  105. res->flags = flags;
  106. res->start = start;
  107. res->end = end;
  108. list_add_tail(&root_res->list, &info->resources);
  109. }