io_acpi_init.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2006 Silicon Graphics, Inc. All rights reserved.
  7. */
  8. #include <asm/sn/types.h>
  9. #include <asm/sn/addrs.h>
  10. #include <asm/sn/pcidev.h>
  11. #include <asm/sn/pcibus_provider_defs.h>
  12. #include <asm/sn/sn_sal.h>
  13. #include "xtalk/hubdev.h"
  14. #include <linux/acpi.h>
  15. /*
  16. * The code in this file will only be executed when running with
  17. * a PROM that has ACPI IO support. (i.e., SN_ACPI_BASE_SUPPORT() == 1)
  18. */
  19. /*
  20. * This value must match the UUID the PROM uses
  21. * (io/acpi/defblk.c) when building a vendor descriptor.
  22. */
  23. struct acpi_vendor_uuid sn_uuid = {
  24. .subtype = 0,
  25. .data = { 0x2c, 0xc6, 0xa6, 0xfe, 0x9c, 0x44, 0xda, 0x11,
  26. 0xa2, 0x7c, 0x08, 0x00, 0x69, 0x13, 0xea, 0x51 },
  27. };
  28. /*
  29. * Perform the early IO init in PROM.
  30. */
  31. static s64
  32. sal_ioif_init(u64 *result)
  33. {
  34. struct ia64_sal_retval isrv = {0,0,0,0};
  35. SAL_CALL_NOLOCK(isrv,
  36. SN_SAL_IOIF_INIT, 0, 0, 0, 0, 0, 0, 0);
  37. *result = isrv.v0;
  38. return isrv.status;
  39. }
  40. /*
  41. * sn_hubdev_add - The 'add' function of the acpi_sn_hubdev_driver.
  42. * Called for every "SGIHUB" or "SGITIO" device defined
  43. * in the ACPI namespace.
  44. */
  45. static int __init
  46. sn_hubdev_add(struct acpi_device *device)
  47. {
  48. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  49. u64 addr;
  50. struct hubdev_info *hubdev;
  51. struct hubdev_info *hubdev_ptr;
  52. int i;
  53. u64 nasid;
  54. struct acpi_resource *resource;
  55. int ret = 0;
  56. acpi_status status;
  57. struct acpi_resource_vendor_typed *vendor;
  58. extern void sn_common_hubdev_init(struct hubdev_info *);
  59. status = acpi_get_vendor_resource(device->handle, METHOD_NAME__CRS,
  60. &sn_uuid, &buffer);
  61. if (ACPI_FAILURE(status)) {
  62. printk(KERN_ERR
  63. "sn_hubdev_add: acpi_get_vendor_resource() failed: %d\n",
  64. status);
  65. return 1;
  66. }
  67. resource = buffer.pointer;
  68. vendor = &resource->data.vendor_typed;
  69. if ((vendor->byte_length - sizeof(struct acpi_vendor_uuid)) !=
  70. sizeof(struct hubdev_info *)) {
  71. printk(KERN_ERR
  72. "sn_hubdev_add: Invalid vendor data length: %d\n",
  73. vendor->byte_length);
  74. ret = 1;
  75. goto exit;
  76. }
  77. memcpy(&addr, vendor->byte_data, sizeof(struct hubdev_info *));
  78. hubdev_ptr = __va((struct hubdev_info *) addr);
  79. nasid = hubdev_ptr->hdi_nasid;
  80. i = nasid_to_cnodeid(nasid);
  81. hubdev = (struct hubdev_info *)(NODEPDA(i)->pdinfo);
  82. *hubdev = *hubdev_ptr;
  83. sn_common_hubdev_init(hubdev);
  84. exit:
  85. kfree(buffer.pointer);
  86. return ret;
  87. }
  88. /*
  89. * sn_get_bussoft_ptr() - The pcibus_bussoft pointer is found in
  90. * the ACPI Vendor resource for this bus.
  91. */
  92. static struct pcibus_bussoft *
  93. sn_get_bussoft_ptr(struct pci_bus *bus)
  94. {
  95. u64 addr;
  96. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  97. acpi_handle handle;
  98. struct pcibus_bussoft *prom_bussoft_ptr;
  99. struct acpi_resource *resource;
  100. acpi_status status;
  101. struct acpi_resource_vendor_typed *vendor;
  102. handle = PCI_CONTROLLER(bus)->acpi_handle;
  103. status = acpi_get_vendor_resource(handle, METHOD_NAME__CRS,
  104. &sn_uuid, &buffer);
  105. if (ACPI_FAILURE(status)) {
  106. printk(KERN_ERR "get_acpi_pcibus_ptr: "
  107. "get_acpi_bussoft_info() failed: %d\n",
  108. status);
  109. return NULL;
  110. }
  111. resource = buffer.pointer;
  112. vendor = &resource->data.vendor_typed;
  113. if ((vendor->byte_length - sizeof(struct acpi_vendor_uuid)) !=
  114. sizeof(struct pcibus_bussoft *)) {
  115. printk(KERN_ERR
  116. "get_acpi_bussoft_ptr: Invalid vendor data "
  117. "length %d\n", vendor->byte_length);
  118. kfree(buffer.pointer);
  119. return NULL;
  120. }
  121. memcpy(&addr, vendor->byte_data, sizeof(struct pcibus_bussoft *));
  122. prom_bussoft_ptr = __va((struct pcibus_bussoft *) addr);
  123. kfree(buffer.pointer);
  124. return prom_bussoft_ptr;
  125. }
  126. /*
  127. * sn_acpi_bus_fixup
  128. */
  129. void
  130. sn_acpi_bus_fixup(struct pci_bus *bus)
  131. {
  132. struct pci_dev *pci_dev = NULL;
  133. struct pcibus_bussoft *prom_bussoft_ptr;
  134. extern void sn_common_bus_fixup(struct pci_bus *,
  135. struct pcibus_bussoft *);
  136. if (!bus->parent) { /* If root bus */
  137. prom_bussoft_ptr = sn_get_bussoft_ptr(bus);
  138. if (prom_bussoft_ptr == NULL) {
  139. printk(KERN_ERR
  140. "sn_pci_fixup_bus: 0x%04x:0x%02x Unable to "
  141. "obtain prom_bussoft_ptr\n",
  142. pci_domain_nr(bus), bus->number);
  143. return;
  144. }
  145. sn_common_bus_fixup(bus, prom_bussoft_ptr);
  146. }
  147. list_for_each_entry(pci_dev, &bus->devices, bus_list) {
  148. sn_pci_fixup_slot(pci_dev);
  149. }
  150. }
  151. /*
  152. * sn_acpi_slot_fixup - Perform any SN specific slot fixup.
  153. * At present there does not appear to be
  154. * any generic way to handle a ROM image
  155. * that has been shadowed by the PROM, so
  156. * we pass a pointer to it within the
  157. * pcidev_info structure.
  158. */
  159. void
  160. sn_acpi_slot_fixup(struct pci_dev *dev, struct pcidev_info *pcidev_info)
  161. {
  162. void __iomem *addr;
  163. size_t size;
  164. if (pcidev_info->pdi_pio_mapped_addr[PCI_ROM_RESOURCE]) {
  165. /*
  166. * A valid ROM image exists and has been shadowed by the
  167. * PROM. Setup the pci_dev ROM resource to point to
  168. * the shadowed copy.
  169. */
  170. size = dev->resource[PCI_ROM_RESOURCE].end -
  171. dev->resource[PCI_ROM_RESOURCE].start;
  172. addr =
  173. ioremap(pcidev_info->pdi_pio_mapped_addr[PCI_ROM_RESOURCE],
  174. size);
  175. dev->resource[PCI_ROM_RESOURCE].start = (unsigned long) addr;
  176. dev->resource[PCI_ROM_RESOURCE].end =
  177. (unsigned long) addr + size;
  178. dev->resource[PCI_ROM_RESOURCE].flags |= IORESOURCE_ROM_BIOS_COPY;
  179. }
  180. }
  181. static struct acpi_driver acpi_sn_hubdev_driver = {
  182. .name = "SGI HUBDEV Driver",
  183. .ids = "SGIHUB,SGITIO",
  184. .ops = {
  185. .add = sn_hubdev_add,
  186. },
  187. };
  188. /*
  189. * sn_io_acpi_init - PROM has ACPI support for IO, defining at a minimum the
  190. * nodes and root buses in the DSDT. As a result, bus scanning
  191. * will be initiated by the Linux ACPI code.
  192. */
  193. void __init
  194. sn_io_acpi_init(void)
  195. {
  196. u64 result;
  197. s64 status;
  198. /* SN Altix does not follow the IOSAPIC IRQ routing model */
  199. acpi_irq_model = ACPI_IRQ_MODEL_PLATFORM;
  200. acpi_bus_register_driver(&acpi_sn_hubdev_driver);
  201. status = sal_ioif_init(&result);
  202. if (status || result)
  203. panic("sal_ioif_init failed: [%lx] %s\n",
  204. status, ia64_sal_strerror(status));
  205. }