PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/arch/x86/pci/acpi.c

https://github.com/xdabravoteam/cm-kernel
C | 340 lines | 274 code | 42 blank | 24 comment | 45 complexity | 535eb0ccca1cbc8ce48a0e9b435060fa MD5 | raw file
  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 <linux/slab.h>
  7. #include <asm/numa.h>
  8. #include <asm/pci_x86.h>
  9. struct pci_root_info {
  10. struct acpi_device *bridge;
  11. char *name;
  12. unsigned int res_num;
  13. struct resource *res;
  14. struct pci_bus *bus;
  15. int busnum;
  16. };
  17. static bool pci_use_crs = true;
  18. static int __init set_use_crs(const struct dmi_system_id *id)
  19. {
  20. pci_use_crs = true;
  21. return 0;
  22. }
  23. static const struct dmi_system_id pci_use_crs_table[] __initconst = {
  24. /* http://bugzilla.kernel.org/show_bug.cgi?id=14183 */
  25. {
  26. .callback = set_use_crs,
  27. .ident = "IBM System x3800",
  28. .matches = {
  29. DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
  30. DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
  31. },
  32. },
  33. /* https://bugzilla.kernel.org/show_bug.cgi?id=16007 */
  34. /* 2006 AMD HT/VIA system with two host bridges */
  35. {
  36. .callback = set_use_crs,
  37. .ident = "ASRock ALiveSATA2-GLAN",
  38. .matches = {
  39. DMI_MATCH(DMI_PRODUCT_NAME, "ALiveSATA2-GLAN"),
  40. },
  41. },
  42. {}
  43. };
  44. void __init pci_acpi_crs_quirks(void)
  45. {
  46. int year;
  47. if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year < 2008)
  48. pci_use_crs = false;
  49. dmi_check_system(pci_use_crs_table);
  50. /*
  51. * If the user specifies "pci=use_crs" or "pci=nocrs" explicitly, that
  52. * takes precedence over anything we figured out above.
  53. */
  54. if (pci_probe & PCI_ROOT_NO_CRS)
  55. pci_use_crs = false;
  56. else if (pci_probe & PCI_USE__CRS)
  57. pci_use_crs = true;
  58. printk(KERN_INFO "PCI: %s host bridge windows from ACPI; "
  59. "if necessary, use \"pci=%s\" and report a bug\n",
  60. pci_use_crs ? "Using" : "Ignoring",
  61. pci_use_crs ? "nocrs" : "use_crs");
  62. }
  63. static acpi_status
  64. resource_to_addr(struct acpi_resource *resource,
  65. struct acpi_resource_address64 *addr)
  66. {
  67. acpi_status status;
  68. struct acpi_resource_memory24 *memory24;
  69. struct acpi_resource_memory32 *memory32;
  70. struct acpi_resource_fixed_memory32 *fixed_memory32;
  71. memset(addr, 0, sizeof(*addr));
  72. switch (resource->type) {
  73. case ACPI_RESOURCE_TYPE_MEMORY24:
  74. memory24 = &resource->data.memory24;
  75. addr->resource_type = ACPI_MEMORY_RANGE;
  76. addr->minimum = memory24->minimum;
  77. addr->address_length = memory24->address_length;
  78. addr->maximum = addr->minimum + addr->address_length - 1;
  79. return AE_OK;
  80. case ACPI_RESOURCE_TYPE_MEMORY32:
  81. memory32 = &resource->data.memory32;
  82. addr->resource_type = ACPI_MEMORY_RANGE;
  83. addr->minimum = memory32->minimum;
  84. addr->address_length = memory32->address_length;
  85. addr->maximum = addr->minimum + addr->address_length - 1;
  86. return AE_OK;
  87. case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
  88. fixed_memory32 = &resource->data.fixed_memory32;
  89. addr->resource_type = ACPI_MEMORY_RANGE;
  90. addr->minimum = fixed_memory32->address;
  91. addr->address_length = fixed_memory32->address_length;
  92. addr->maximum = addr->minimum + addr->address_length - 1;
  93. return AE_OK;
  94. case ACPI_RESOURCE_TYPE_ADDRESS16:
  95. case ACPI_RESOURCE_TYPE_ADDRESS32:
  96. case ACPI_RESOURCE_TYPE_ADDRESS64:
  97. status = acpi_resource_to_address64(resource, addr);
  98. if (ACPI_SUCCESS(status) &&
  99. (addr->resource_type == ACPI_MEMORY_RANGE ||
  100. addr->resource_type == ACPI_IO_RANGE) &&
  101. addr->address_length > 0) {
  102. return AE_OK;
  103. }
  104. break;
  105. }
  106. return AE_ERROR;
  107. }
  108. static acpi_status
  109. count_resource(struct acpi_resource *acpi_res, void *data)
  110. {
  111. struct pci_root_info *info = data;
  112. struct acpi_resource_address64 addr;
  113. acpi_status status;
  114. status = resource_to_addr(acpi_res, &addr);
  115. if (ACPI_SUCCESS(status))
  116. info->res_num++;
  117. return AE_OK;
  118. }
  119. static acpi_status
  120. setup_resource(struct acpi_resource *acpi_res, void *data)
  121. {
  122. struct pci_root_info *info = data;
  123. struct resource *res;
  124. struct acpi_resource_address64 addr;
  125. acpi_status status;
  126. unsigned long flags;
  127. struct resource *root, *conflict;
  128. u64 start, end;
  129. status = resource_to_addr(acpi_res, &addr);
  130. if (!ACPI_SUCCESS(status))
  131. return AE_OK;
  132. if (addr.resource_type == ACPI_MEMORY_RANGE) {
  133. root = &iomem_resource;
  134. flags = IORESOURCE_MEM;
  135. if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY)
  136. flags |= IORESOURCE_PREFETCH;
  137. } else if (addr.resource_type == ACPI_IO_RANGE) {
  138. root = &ioport_resource;
  139. flags = IORESOURCE_IO;
  140. } else
  141. return AE_OK;
  142. start = addr.minimum + addr.translation_offset;
  143. end = addr.maximum + addr.translation_offset;
  144. res = &info->res[info->res_num];
  145. res->name = info->name;
  146. res->flags = flags;
  147. res->start = start;
  148. res->end = end;
  149. res->child = NULL;
  150. if (!pci_use_crs) {
  151. dev_printk(KERN_DEBUG, &info->bridge->dev,
  152. "host bridge window %pR (ignored)\n", res);
  153. return AE_OK;
  154. }
  155. conflict = insert_resource_conflict(root, res);
  156. if (conflict) {
  157. dev_err(&info->bridge->dev,
  158. "address space collision: host bridge window %pR "
  159. "conflicts with %s %pR\n",
  160. res, conflict->name, conflict);
  161. } else {
  162. pci_bus_add_resource(info->bus, res, 0);
  163. info->res_num++;
  164. if (addr.translation_offset)
  165. dev_info(&info->bridge->dev, "host bridge window %pR "
  166. "(PCI address [%#llx-%#llx])\n",
  167. res, res->start - addr.translation_offset,
  168. res->end - addr.translation_offset);
  169. else
  170. dev_info(&info->bridge->dev,
  171. "host bridge window %pR\n", res);
  172. }
  173. return AE_OK;
  174. }
  175. static void
  176. get_current_resources(struct acpi_device *device, int busnum,
  177. int domain, struct pci_bus *bus)
  178. {
  179. struct pci_root_info info;
  180. size_t size;
  181. if (pci_use_crs)
  182. pci_bus_remove_resources(bus);
  183. info.bridge = device;
  184. info.bus = bus;
  185. info.res_num = 0;
  186. acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource,
  187. &info);
  188. if (!info.res_num)
  189. return;
  190. size = sizeof(*info.res) * info.res_num;
  191. info.res = kmalloc(size, GFP_KERNEL);
  192. if (!info.res)
  193. goto res_alloc_fail;
  194. info.name = kmalloc(16, GFP_KERNEL);
  195. if (!info.name)
  196. goto name_alloc_fail;
  197. sprintf(info.name, "PCI Bus %04x:%02x", domain, busnum);
  198. info.res_num = 0;
  199. acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,
  200. &info);
  201. return;
  202. name_alloc_fail:
  203. kfree(info.res);
  204. res_alloc_fail:
  205. return;
  206. }
  207. struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int domain, int busnum)
  208. {
  209. struct pci_bus *bus;
  210. struct pci_sysdata *sd;
  211. int node;
  212. #ifdef CONFIG_ACPI_NUMA
  213. int pxm;
  214. #endif
  215. if (domain && !pci_domains_supported) {
  216. printk(KERN_WARNING "pci_bus %04x:%02x: "
  217. "ignored (multiple domains not supported)\n",
  218. domain, busnum);
  219. return NULL;
  220. }
  221. node = -1;
  222. #ifdef CONFIG_ACPI_NUMA
  223. pxm = acpi_get_pxm(device->handle);
  224. if (pxm >= 0)
  225. node = pxm_to_node(pxm);
  226. if (node != -1)
  227. set_mp_bus_to_node(busnum, node);
  228. else
  229. #endif
  230. node = get_mp_bus_to_node(busnum);
  231. if (node != -1 && !node_online(node))
  232. node = -1;
  233. /* Allocate per-root-bus (not per bus) arch-specific data.
  234. * TODO: leak; this memory is never freed.
  235. * It's arguable whether it's worth the trouble to care.
  236. */
  237. sd = kzalloc(sizeof(*sd), GFP_KERNEL);
  238. if (!sd) {
  239. printk(KERN_WARNING "pci_bus %04x:%02x: "
  240. "ignored (out of memory)\n", domain, busnum);
  241. return NULL;
  242. }
  243. sd->domain = domain;
  244. sd->node = node;
  245. /*
  246. * Maybe the desired pci bus has been already scanned. In such case
  247. * it is unnecessary to scan the pci bus with the given domain,busnum.
  248. */
  249. bus = pci_find_bus(domain, busnum);
  250. if (bus) {
  251. /*
  252. * If the desired bus exits, the content of bus->sysdata will
  253. * be replaced by sd.
  254. */
  255. memcpy(bus->sysdata, sd, sizeof(*sd));
  256. kfree(sd);
  257. } else {
  258. bus = pci_create_bus(NULL, busnum, &pci_root_ops, sd);
  259. if (bus) {
  260. get_current_resources(device, busnum, domain, bus);
  261. bus->subordinate = pci_scan_child_bus(bus);
  262. }
  263. }
  264. if (!bus)
  265. kfree(sd);
  266. if (bus && node != -1) {
  267. #ifdef CONFIG_ACPI_NUMA
  268. if (pxm >= 0)
  269. dev_printk(KERN_DEBUG, &bus->dev,
  270. "on NUMA node %d (pxm %d)\n", node, pxm);
  271. #else
  272. dev_printk(KERN_DEBUG, &bus->dev, "on NUMA node %d\n", node);
  273. #endif
  274. }
  275. return bus;
  276. }
  277. int __init pci_acpi_init(void)
  278. {
  279. struct pci_dev *dev = NULL;
  280. if (acpi_noirq)
  281. return -ENODEV;
  282. printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
  283. acpi_irq_penalty_init();
  284. pcibios_enable_irq = acpi_pci_irq_enable;
  285. pcibios_disable_irq = acpi_pci_irq_disable;
  286. x86_init.pci.init_irq = x86_init_noop;
  287. if (pci_routeirq) {
  288. /*
  289. * PCI IRQ routing is set up by pci_enable_device(), but we
  290. * also do it here in case there are still broken drivers that
  291. * don't use pci_enable_device().
  292. */
  293. printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
  294. for_each_pci_dev(dev)
  295. acpi_pci_irq_enable(dev);
  296. }
  297. return 0;
  298. }