acpi.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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[] __devinitdata = {
  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. if (info->res_num >= PCI_BUS_NUM_RESOURCES)
  74. return AE_OK;
  75. status = resource_to_addr(acpi_res, &addr);
  76. if (ACPI_SUCCESS(status))
  77. info->res_num++;
  78. return AE_OK;
  79. }
  80. static acpi_status
  81. setup_resource(struct acpi_resource *acpi_res, void *data)
  82. {
  83. struct pci_root_info *info = data;
  84. struct resource *res;
  85. struct acpi_resource_address64 addr;
  86. acpi_status status;
  87. unsigned long flags;
  88. struct resource *root;
  89. if (info->res_num >= PCI_BUS_NUM_RESOURCES)
  90. return AE_OK;
  91. status = resource_to_addr(acpi_res, &addr);
  92. if (!ACPI_SUCCESS(status))
  93. return AE_OK;
  94. if (addr.resource_type == ACPI_MEMORY_RANGE) {
  95. root = &iomem_resource;
  96. flags = IORESOURCE_MEM;
  97. if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY)
  98. flags |= IORESOURCE_PREFETCH;
  99. } else if (addr.resource_type == ACPI_IO_RANGE) {
  100. root = &ioport_resource;
  101. flags = IORESOURCE_IO;
  102. } else
  103. return AE_OK;
  104. res = &info->res[info->res_num];
  105. res->name = info->name;
  106. res->flags = flags;
  107. res->start = addr.minimum + addr.translation_offset;
  108. res->end = res->start + addr.address_length - 1;
  109. res->child = NULL;
  110. if (insert_resource(root, res)) {
  111. printk(KERN_ERR "PCI: Failed to allocate 0x%lx-0x%lx "
  112. "from %s for %s\n", (unsigned long) res->start,
  113. (unsigned long) res->end, root->name, info->name);
  114. } else {
  115. info->bus->resource[info->res_num] = res;
  116. info->res_num++;
  117. }
  118. return AE_OK;
  119. }
  120. static void
  121. adjust_transparent_bridge_resources(struct pci_bus *bus)
  122. {
  123. struct pci_dev *dev;
  124. list_for_each_entry(dev, &bus->devices, bus_list) {
  125. int i;
  126. u16 class = dev->class >> 8;
  127. if (class == PCI_CLASS_BRIDGE_PCI && dev->transparent) {
  128. for(i = 3; i < PCI_BUS_NUM_RESOURCES; i++)
  129. dev->subordinate->resource[i] =
  130. dev->bus->resource[i - 3];
  131. }
  132. }
  133. }
  134. static void
  135. get_current_resources(struct acpi_device *device, int busnum,
  136. int domain, struct pci_bus *bus)
  137. {
  138. struct pci_root_info info;
  139. size_t size;
  140. info.bus = bus;
  141. info.res_num = 0;
  142. acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource,
  143. &info);
  144. if (!info.res_num)
  145. return;
  146. size = sizeof(*info.res) * info.res_num;
  147. info.res = kmalloc(size, GFP_KERNEL);
  148. if (!info.res)
  149. goto res_alloc_fail;
  150. info.name = kmalloc(16, GFP_KERNEL);
  151. if (!info.name)
  152. goto name_alloc_fail;
  153. sprintf(info.name, "PCI Bus %04x:%02x", domain, busnum);
  154. info.res_num = 0;
  155. acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,
  156. &info);
  157. if (info.res_num)
  158. adjust_transparent_bridge_resources(bus);
  159. return;
  160. name_alloc_fail:
  161. kfree(info.res);
  162. res_alloc_fail:
  163. return;
  164. }
  165. struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int domain, int busnum)
  166. {
  167. struct pci_bus *bus;
  168. struct pci_sysdata *sd;
  169. int pxm;
  170. dmi_check_system(acpi_pciprobe_dmi_table);
  171. if (domain && !pci_domains_supported) {
  172. printk(KERN_WARNING "PCI: Multiple domains not supported "
  173. "(dom %d, bus %d)\n", domain, busnum);
  174. return NULL;
  175. }
  176. /* Allocate per-root-bus (not per bus) arch-specific data.
  177. * TODO: leak; this memory is never freed.
  178. * It's arguable whether it's worth the trouble to care.
  179. */
  180. sd = kzalloc(sizeof(*sd), GFP_KERNEL);
  181. if (!sd) {
  182. printk(KERN_ERR "PCI: OOM, not probing PCI bus %02x\n", busnum);
  183. return NULL;
  184. }
  185. sd->domain = domain;
  186. sd->node = -1;
  187. pxm = acpi_get_pxm(device->handle);
  188. #ifdef CONFIG_ACPI_NUMA
  189. if (pxm >= 0)
  190. sd->node = pxm_to_node(pxm);
  191. #endif
  192. /*
  193. * Maybe the desired pci bus has been already scanned. In such case
  194. * it is unnecessary to scan the pci bus with the given domain,busnum.
  195. */
  196. bus = pci_find_bus(domain, busnum);
  197. if (bus) {
  198. /*
  199. * If the desired bus exits, the content of bus->sysdata will
  200. * be replaced by sd.
  201. */
  202. memcpy(bus->sysdata, sd, sizeof(*sd));
  203. kfree(sd);
  204. } else
  205. bus = pci_scan_bus_parented(NULL, busnum, &pci_root_ops, sd);
  206. if (!bus)
  207. kfree(sd);
  208. #ifdef CONFIG_ACPI_NUMA
  209. if (bus != NULL) {
  210. if (pxm >= 0) {
  211. printk("bus %d -> pxm %d -> node %d\n",
  212. busnum, pxm, pxm_to_node(pxm));
  213. }
  214. }
  215. #endif
  216. if (bus && (pci_probe & PCI_USE__CRS))
  217. get_current_resources(device, busnum, domain, bus);
  218. return bus;
  219. }
  220. extern int pci_routeirq;
  221. static int __init pci_acpi_init(void)
  222. {
  223. struct pci_dev *dev = NULL;
  224. if (pcibios_scanned)
  225. return 0;
  226. if (acpi_noirq)
  227. return 0;
  228. printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
  229. acpi_irq_penalty_init();
  230. pcibios_scanned++;
  231. pcibios_enable_irq = acpi_pci_irq_enable;
  232. pcibios_disable_irq = acpi_pci_irq_disable;
  233. if (pci_routeirq) {
  234. /*
  235. * PCI IRQ routing is set up by pci_enable_device(), but we
  236. * also do it here in case there are still broken drivers that
  237. * don't use pci_enable_device().
  238. */
  239. printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
  240. for_each_pci_dev(dev)
  241. acpi_pci_irq_enable(dev);
  242. }
  243. #ifdef CONFIG_X86_IO_APIC
  244. if (acpi_ioapic)
  245. print_IO_APIC();
  246. #endif
  247. return 0;
  248. }
  249. subsys_initcall(pci_acpi_init);