acpi.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. #include <linux/pci.h>
  2. #include <linux/acpi.h>
  3. #include <linux/init.h>
  4. #include <linux/irq.h>
  5. #include <linux/dmi.h>
  6. #include <asm/numa.h>
  7. #include "pci.h"
  8. static int __devinit can_skip_ioresource_align(const struct dmi_system_id *d)
  9. {
  10. pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
  11. printk(KERN_INFO "PCI: %s detected, can skip ISA alignment\n", d->ident);
  12. return 0;
  13. }
  14. static struct dmi_system_id acpi_pciprobe_dmi_table[] = {
  15. /*
  16. * Systems where PCI IO resource ISA alignment can be skipped
  17. * when the ISA enable bit in the bridge control is not set
  18. */
  19. {
  20. .callback = can_skip_ioresource_align,
  21. .ident = "IBM System x3800",
  22. .matches = {
  23. DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
  24. DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
  25. },
  26. },
  27. {
  28. .callback = can_skip_ioresource_align,
  29. .ident = "IBM System x3850",
  30. .matches = {
  31. DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
  32. DMI_MATCH(DMI_PRODUCT_NAME, "x3850"),
  33. },
  34. },
  35. {
  36. .callback = can_skip_ioresource_align,
  37. .ident = "IBM System x3950",
  38. .matches = {
  39. DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
  40. DMI_MATCH(DMI_PRODUCT_NAME, "x3950"),
  41. },
  42. },
  43. {}
  44. };
  45. struct pci_root_info {
  46. char *name;
  47. unsigned int res_num;
  48. struct resource *res;
  49. struct pci_bus *bus;
  50. int busnum;
  51. };
  52. static acpi_status
  53. resource_to_addr(struct acpi_resource *resource,
  54. struct acpi_resource_address64 *addr)
  55. {
  56. acpi_status status;
  57. status = acpi_resource_to_address64(resource, addr);
  58. if (ACPI_SUCCESS(status) &&
  59. (addr->resource_type == ACPI_MEMORY_RANGE ||
  60. addr->resource_type == ACPI_IO_RANGE) &&
  61. addr->address_length > 0 &&
  62. addr->producer_consumer == ACPI_PRODUCER) {
  63. return AE_OK;
  64. }
  65. return AE_ERROR;
  66. }
  67. static acpi_status
  68. count_resource(struct acpi_resource *acpi_res, void *data)
  69. {
  70. struct pci_root_info *info = data;
  71. struct acpi_resource_address64 addr;
  72. acpi_status status;
  73. status = resource_to_addr(acpi_res, &addr);
  74. if (ACPI_SUCCESS(status))
  75. info->res_num++;
  76. return AE_OK;
  77. }
  78. static acpi_status
  79. setup_resource(struct acpi_resource *acpi_res, void *data)
  80. {
  81. struct pci_root_info *info = data;
  82. struct resource *res;
  83. struct acpi_resource_address64 addr;
  84. acpi_status status;
  85. unsigned long flags;
  86. struct resource *root;
  87. status = resource_to_addr(acpi_res, &addr);
  88. if (!ACPI_SUCCESS(status))
  89. return AE_OK;
  90. if (addr.resource_type == ACPI_MEMORY_RANGE) {
  91. root = &iomem_resource;
  92. flags = IORESOURCE_MEM;
  93. if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY)
  94. flags |= IORESOURCE_PREFETCH;
  95. } else if (addr.resource_type == ACPI_IO_RANGE) {
  96. root = &ioport_resource;
  97. flags = IORESOURCE_IO;
  98. } else
  99. return AE_OK;
  100. res = &info->res[info->res_num];
  101. res->name = info->name;
  102. res->flags = flags;
  103. res->start = addr.minimum + addr.translation_offset;
  104. res->end = res->start + addr.address_length - 1;
  105. res->child = NULL;
  106. if (insert_resource(root, res)) {
  107. printk(KERN_ERR "PCI: Failed to allocate 0x%lx-0x%lx "
  108. "from %s for %s\n", (unsigned long) res->start,
  109. (unsigned long) res->end, root->name, info->name);
  110. } else {
  111. info->bus->resource[info->res_num] = res;
  112. info->res_num++;
  113. }
  114. return AE_OK;
  115. }
  116. static void
  117. adjust_transparent_bridge_resources(struct pci_bus *bus)
  118. {
  119. struct pci_dev *dev;
  120. list_for_each_entry(dev, &bus->devices, bus_list) {
  121. int i;
  122. u16 class = dev->class >> 8;
  123. if (class == PCI_CLASS_BRIDGE_PCI && dev->transparent) {
  124. for(i = 3; i < PCI_BUS_NUM_RESOURCES; i++)
  125. dev->subordinate->resource[i] =
  126. dev->bus->resource[i - 3];
  127. }
  128. }
  129. }
  130. static void
  131. get_current_resources(struct acpi_device *device, int busnum,
  132. struct pci_bus *bus)
  133. {
  134. struct pci_root_info info;
  135. size_t size;
  136. info.bus = bus;
  137. info.res_num = 0;
  138. acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource,
  139. &info);
  140. if (!info.res_num)
  141. return;
  142. size = sizeof(*info.res) * info.res_num;
  143. info.res = kmalloc(size, GFP_KERNEL);
  144. if (!info.res)
  145. goto res_alloc_fail;
  146. info.name = kmalloc(12, GFP_KERNEL);
  147. if (!info.name)
  148. goto name_alloc_fail;
  149. sprintf(info.name, "PCI Bus #%02x", busnum);
  150. info.res_num = 0;
  151. acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,
  152. &info);
  153. if (info.res_num)
  154. adjust_transparent_bridge_resources(bus);
  155. return;
  156. name_alloc_fail:
  157. kfree(info.res);
  158. res_alloc_fail:
  159. return;
  160. }
  161. struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int domain, int busnum)
  162. {
  163. struct pci_bus *bus;
  164. struct pci_sysdata *sd;
  165. int pxm;
  166. dmi_check_system(acpi_pciprobe_dmi_table);
  167. if (domain && !pci_domains_supported) {
  168. printk(KERN_WARNING "PCI: Multiple domains not supported "
  169. "(dom %d, bus %d)\n", domain, busnum);
  170. return NULL;
  171. }
  172. /* Allocate per-root-bus (not per bus) arch-specific data.
  173. * TODO: leak; this memory is never freed.
  174. * It's arguable whether it's worth the trouble to care.
  175. */
  176. sd = kzalloc(sizeof(*sd), GFP_KERNEL);
  177. if (!sd) {
  178. printk(KERN_ERR "PCI: OOM, not probing PCI bus %02x\n", busnum);
  179. return NULL;
  180. }
  181. sd->domain = domain;
  182. sd->node = -1;
  183. pxm = acpi_get_pxm(device->handle);
  184. #ifdef CONFIG_ACPI_NUMA
  185. if (pxm >= 0)
  186. sd->node = pxm_to_node(pxm);
  187. #endif
  188. bus = pci_scan_bus_parented(NULL, busnum, &pci_root_ops, sd);
  189. if (!bus)
  190. kfree(sd);
  191. #ifdef CONFIG_ACPI_NUMA
  192. if (bus != NULL) {
  193. if (pxm >= 0) {
  194. printk("bus %d -> pxm %d -> node %d\n",
  195. busnum, pxm, sd->node);
  196. }
  197. }
  198. #endif
  199. if (bus && (pci_probe & PCI_USE__CRS))
  200. get_current_resources(device, busnum, bus);
  201. return bus;
  202. }
  203. extern int pci_routeirq;
  204. static int __init pci_acpi_init(void)
  205. {
  206. struct pci_dev *dev = NULL;
  207. if (pcibios_scanned)
  208. return 0;
  209. if (acpi_noirq)
  210. return 0;
  211. printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
  212. acpi_irq_penalty_init();
  213. pcibios_scanned++;
  214. pcibios_enable_irq = acpi_pci_irq_enable;
  215. pcibios_disable_irq = acpi_pci_irq_disable;
  216. if (pci_routeirq) {
  217. /*
  218. * PCI IRQ routing is set up by pci_enable_device(), but we
  219. * also do it here in case there are still broken drivers that
  220. * don't use pci_enable_device().
  221. */
  222. printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
  223. for_each_pci_dev(dev)
  224. acpi_pci_irq_enable(dev);
  225. } else
  226. printk(KERN_INFO "PCI: If a device doesn't work, try \"pci=routeirq\". If it helps, post a report\n");
  227. #ifdef CONFIG_X86_IO_APIC
  228. if (acpi_ioapic)
  229. print_IO_APIC();
  230. #endif
  231. return 0;
  232. }
  233. subsys_initcall(pci_acpi_init);