bus_numa.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include <linux/init.h>
  2. #include <linux/pci.h>
  3. #include "bus_numa.h"
  4. int pci_root_num;
  5. struct pci_root_info pci_root_info[PCI_ROOT_NR];
  6. int found_all_numa_early;
  7. void x86_pci_root_bus_res_quirks(struct pci_bus *b)
  8. {
  9. int i;
  10. int j;
  11. struct pci_root_info *info;
  12. /* don't go for it if _CRS is used already */
  13. if (b->resource[0] != &ioport_resource ||
  14. b->resource[1] != &iomem_resource)
  15. return;
  16. if (!pci_root_num)
  17. return;
  18. /* for amd, if only one root bus, don't need to do anything */
  19. if (pci_root_num < 2 && found_all_numa_early)
  20. return;
  21. for (i = 0; i < pci_root_num; i++) {
  22. if (pci_root_info[i].bus_min == b->number)
  23. break;
  24. }
  25. if (i == pci_root_num)
  26. return;
  27. printk(KERN_DEBUG "PCI: peer root bus %02x res updated from pci conf\n",
  28. b->number);
  29. pci_bus_remove_resources(b);
  30. info = &pci_root_info[i];
  31. for (j = 0; j < info->res_num; j++) {
  32. struct resource *res;
  33. struct resource *root;
  34. res = &info->res[j];
  35. pci_bus_add_resource(b, res, 0);
  36. if (res->flags & IORESOURCE_IO)
  37. root = &ioport_resource;
  38. else
  39. root = &iomem_resource;
  40. insert_resource(root, res);
  41. }
  42. }
  43. void __devinit update_res(struct pci_root_info *info, size_t start,
  44. size_t end, unsigned long flags, int merge)
  45. {
  46. int i;
  47. struct resource *res;
  48. if (start > end)
  49. return;
  50. if (!merge)
  51. goto addit;
  52. /* try to merge it with old one */
  53. for (i = 0; i < info->res_num; i++) {
  54. size_t final_start, final_end;
  55. size_t common_start, common_end;
  56. res = &info->res[i];
  57. if (res->flags != flags)
  58. continue;
  59. common_start = max((size_t)res->start, start);
  60. common_end = min((size_t)res->end, end);
  61. if (common_start > common_end + 1)
  62. continue;
  63. final_start = min((size_t)res->start, start);
  64. final_end = max((size_t)res->end, end);
  65. res->start = final_start;
  66. res->end = final_end;
  67. return;
  68. }
  69. addit:
  70. /* need to add that */
  71. if (info->res_num >= RES_NUM)
  72. return;
  73. res = &info->res[info->res_num];
  74. res->name = info->name;
  75. res->flags = flags;
  76. res->start = start;
  77. res->end = end;
  78. res->child = NULL;
  79. info->res_num++;
  80. }