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
6 * Copyright (C) 2006 Silicon Graphics, Inc. All rights reserved.
9 #include <asm/sn/types.h>
10 #include <asm/sn/addrs.h>
11 #include <asm/sn/pcidev.h>
12 #include <asm/sn/pcibus_provider_defs.h>
13 #include <asm/sn/sn_sal.h>
14 #include "xtalk/hubdev.h"
15 #include <linux/acpi.h>
19 * The code in this file will only be executed when running with
20 * a PROM that has ACPI IO support. (i.e., SN_ACPI_BASE_SUPPORT() == 1)
25 * This value must match the UUID the PROM uses
26 * (io/acpi/defblk.c) when building a vendor descriptor.
28 struct acpi_vendor_uuid sn_uuid = {
30 .data = { 0x2c, 0xc6, 0xa6, 0xfe, 0x9c, 0x44, 0xda, 0x11,
31 0xa2, 0x7c, 0x08, 0x00, 0x69, 0x13, 0xea, 0x51 },
35 * Perform the early IO init in PROM.
38 sal_ioif_init(u64 *result)
40 struct ia64_sal_retval isrv = {0,0,0,0};
43 SN_SAL_IOIF_INIT, 0, 0, 0, 0, 0, 0, 0);
49 * sn_hubdev_add - The 'add' function of the acpi_sn_hubdev_driver.
50 * Called for every "SGIHUB" or "SGITIO" device defined
51 * in the ACPI namespace.
54 sn_hubdev_add(struct acpi_device *device)
56 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
58 struct hubdev_info *hubdev;
59 struct hubdev_info *hubdev_ptr;
62 struct acpi_resource *resource;
65 struct acpi_resource_vendor_typed *vendor;
66 extern void sn_common_hubdev_init(struct hubdev_info *);
68 status = acpi_get_vendor_resource(device->handle, METHOD_NAME__CRS,
70 if (ACPI_FAILURE(status)) {
72 "sn_hubdev_add: acpi_get_vendor_resource() failed: %d\n",
77 resource = buffer.pointer;
78 vendor = &resource->data.vendor_typed;
79 if ((vendor->byte_length - sizeof(struct acpi_vendor_uuid)) !=
80 sizeof(struct hubdev_info *)) {
82 "sn_hubdev_add: Invalid vendor data length: %d\n",
88 memcpy(&addr, vendor->byte_data, sizeof(struct hubdev_info *));
89 hubdev_ptr = __va((struct hubdev_info *) addr);
91 nasid = hubdev_ptr->hdi_nasid;
92 i = nasid_to_cnodeid(nasid);
93 hubdev = (struct hubdev_info *)(NODEPDA(i)->pdinfo);
94 *hubdev = *hubdev_ptr;
95 sn_common_hubdev_init(hubdev);
98 kfree(buffer.pointer);
103 * sn_get_bussoft_ptr() - The pcibus_bussoft pointer is found in
104 * the ACPI Vendor resource for this bus.
106 static struct pcibus_bussoft *
107 sn_get_bussoft_ptr(struct pci_bus *bus)
110 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
112 struct pcibus_bussoft *prom_bussoft_ptr;
113 struct acpi_resource *resource;
115 struct acpi_resource_vendor_typed *vendor;
118 handle = PCI_CONTROLLER(bus)->acpi_handle;
119 status = acpi_get_vendor_resource(handle, METHOD_NAME__CRS,
121 if (ACPI_FAILURE(status)) {
122 printk(KERN_ERR "get_acpi_pcibus_ptr: "
123 "get_acpi_bussoft_info() failed: %d\n",
127 resource = buffer.pointer;
128 vendor = &resource->data.vendor_typed;
130 if ((vendor->byte_length - sizeof(struct acpi_vendor_uuid)) !=
131 sizeof(struct pcibus_bussoft *)) {
133 "get_acpi_bussoft_ptr: Invalid vendor data "
134 "length %d\n", vendor->byte_length);
135 kfree(buffer.pointer);
138 memcpy(&addr, vendor->byte_data, sizeof(struct pcibus_bussoft *));
139 prom_bussoft_ptr = __va((struct pcibus_bussoft *) addr);
140 kfree(buffer.pointer);
142 return prom_bussoft_ptr;
149 sn_acpi_bus_fixup(struct pci_bus *bus)
151 struct pci_dev *pci_dev = NULL;
152 struct pcibus_bussoft *prom_bussoft_ptr;
153 extern void sn_common_bus_fixup(struct pci_bus *,
154 struct pcibus_bussoft *);
156 if (!bus->parent) { /* If root bus */
157 prom_bussoft_ptr = sn_get_bussoft_ptr(bus);
158 if (prom_bussoft_ptr == NULL) {
160 "sn_pci_fixup_bus: 0x%04x:0x%02x Unable to "
161 "obtain prom_bussoft_ptr\n",
162 pci_domain_nr(bus), bus->number);
165 sn_common_bus_fixup(bus, prom_bussoft_ptr);
167 list_for_each_entry(pci_dev, &bus->devices, bus_list) {
168 sn_pci_fixup_slot(pci_dev);
173 * sn_acpi_slot_fixup - Perform any SN specific slot fixup.
174 * At present there does not appear to be
175 * any generic way to handle a ROM image
176 * that has been shadowed by the PROM, so
177 * we pass a pointer to it within the
178 * pcidev_info structure.
182 sn_acpi_slot_fixup(struct pci_dev *dev, struct pcidev_info *pcidev_info)
187 if (pcidev_info->pdi_pio_mapped_addr[PCI_ROM_RESOURCE]) {
189 * A valid ROM image exists and has been shadowed by the
190 * PROM. Setup the pci_dev ROM resource to point to
193 size = dev->resource[PCI_ROM_RESOURCE].end -
194 dev->resource[PCI_ROM_RESOURCE].start;
196 ioremap(pcidev_info->pdi_pio_mapped_addr[PCI_ROM_RESOURCE],
198 dev->resource[PCI_ROM_RESOURCE].start = (unsigned long) addr;
199 dev->resource[PCI_ROM_RESOURCE].end =
200 (unsigned long) addr + size;
201 dev->resource[PCI_ROM_RESOURCE].flags |= IORESOURCE_ROM_BIOS_COPY;
205 static struct acpi_driver acpi_sn_hubdev_driver = {
206 .name = "SGI HUBDEV Driver",
207 .ids = "SGIHUB,SGITIO",
209 .add = sn_hubdev_add,
215 * sn_io_acpi_init - PROM has ACPI support for IO, defining at a minimum the
216 * nodes and root buses in the DSDT. As a result, bus scanning
217 * will be initiated by the Linux ACPI code.
221 sn_io_acpi_init(void)
226 /* SN Altix does not follow the IOSAPIC IRQ routing model */
227 acpi_irq_model = ACPI_IRQ_MODEL_PLATFORM;
229 acpi_bus_register_driver(&acpi_sn_hubdev_driver);
230 status = sal_ioif_init(&result);
231 if (status || result)
232 panic("sal_ioif_init failed: [%lx] %s\n",
233 status, ia64_sal_strerror(status));