Path: blob/master/arch/ia64/sn/kernel/io_acpi_init.c
10819 views
/*1* This file is subject to the terms and conditions of the GNU General Public2* License. See the file "COPYING" in the main directory of this archive3* for more details.4*5* Copyright (C) 2006 Silicon Graphics, Inc. All rights reserved.6*/78#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#include <linux/slab.h>161718/*19* The code in this file will only be executed when running with20* a PROM that has ACPI IO support. (i.e., SN_ACPI_BASE_SUPPORT() == 1)21*/222324/*25* This value must match the UUID the PROM uses26* (io/acpi/defblk.c) when building a vendor descriptor.27*/28struct acpi_vendor_uuid sn_uuid = {29.subtype = 0,30.data = { 0x2c, 0xc6, 0xa6, 0xfe, 0x9c, 0x44, 0xda, 0x11,310xa2, 0x7c, 0x08, 0x00, 0x69, 0x13, 0xea, 0x51 },32};3334struct sn_pcidev_match {35u8 bus;36unsigned int devfn;37acpi_handle handle;38};3940/*41* Perform the early IO init in PROM.42*/43static long44sal_ioif_init(u64 *result)45{46struct ia64_sal_retval isrv = {0,0,0,0};4748SAL_CALL_NOLOCK(isrv,49SN_SAL_IOIF_INIT, 0, 0, 0, 0, 0, 0, 0);50*result = isrv.v0;51return isrv.status;52}5354/*55* sn_acpi_hubdev_init() - This function is called by acpi_ns_get_device_callback()56* for all SGIHUB and SGITIO acpi devices defined in the57* DSDT. It obtains the hubdev_info pointer from the58* ACPI vendor resource, which the PROM setup, and sets up the59* hubdev_info in the pda.60*/6162static acpi_status __init63sn_acpi_hubdev_init(acpi_handle handle, u32 depth, void *context, void **ret)64{65struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };66struct acpi_buffer name_buffer = { ACPI_ALLOCATE_BUFFER, NULL };67u64 addr;68struct hubdev_info *hubdev;69struct hubdev_info *hubdev_ptr;70int i;71u64 nasid;72struct acpi_resource *resource;73acpi_status status;74struct acpi_resource_vendor_typed *vendor;75extern void sn_common_hubdev_init(struct hubdev_info *);7677status = acpi_get_vendor_resource(handle, METHOD_NAME__CRS,78&sn_uuid, &buffer);79if (ACPI_FAILURE(status)) {80acpi_get_name(handle, ACPI_FULL_PATHNAME, &name_buffer);81printk(KERN_ERR82"sn_acpi_hubdev_init: acpi_get_vendor_resource() "83"(0x%x) failed for: %s\n", status,84(char *)name_buffer.pointer);85kfree(name_buffer.pointer);86return AE_OK; /* Continue walking namespace */87}8889resource = buffer.pointer;90vendor = &resource->data.vendor_typed;91if ((vendor->byte_length - sizeof(struct acpi_vendor_uuid)) !=92sizeof(struct hubdev_info *)) {93acpi_get_name(handle, ACPI_FULL_PATHNAME, &name_buffer);94printk(KERN_ERR95"sn_acpi_hubdev_init: Invalid vendor data length: "96"%d for: %s\n",97vendor->byte_length, (char *)name_buffer.pointer);98kfree(name_buffer.pointer);99goto exit;100}101102memcpy(&addr, vendor->byte_data, sizeof(struct hubdev_info *));103hubdev_ptr = __va((struct hubdev_info *) addr);104105nasid = hubdev_ptr->hdi_nasid;106i = nasid_to_cnodeid(nasid);107hubdev = (struct hubdev_info *)(NODEPDA(i)->pdinfo);108*hubdev = *hubdev_ptr;109sn_common_hubdev_init(hubdev);110111exit:112kfree(buffer.pointer);113return AE_OK; /* Continue walking namespace */114}115116/*117* sn_get_bussoft_ptr() - The pcibus_bussoft pointer is found in118* the ACPI Vendor resource for this bus.119*/120static struct pcibus_bussoft *121sn_get_bussoft_ptr(struct pci_bus *bus)122{123u64 addr;124struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };125struct acpi_buffer name_buffer = { ACPI_ALLOCATE_BUFFER, NULL };126acpi_handle handle;127struct pcibus_bussoft *prom_bussoft_ptr;128struct acpi_resource *resource;129acpi_status status;130struct acpi_resource_vendor_typed *vendor;131132133handle = PCI_CONTROLLER(bus)->acpi_handle;134status = acpi_get_vendor_resource(handle, METHOD_NAME__CRS,135&sn_uuid, &buffer);136if (ACPI_FAILURE(status)) {137acpi_get_name(handle, ACPI_FULL_PATHNAME, &name_buffer);138printk(KERN_ERR "%s: "139"acpi_get_vendor_resource() failed (0x%x) for: %s\n",140__func__, status, (char *)name_buffer.pointer);141kfree(name_buffer.pointer);142return NULL;143}144resource = buffer.pointer;145vendor = &resource->data.vendor_typed;146147if ((vendor->byte_length - sizeof(struct acpi_vendor_uuid)) !=148sizeof(struct pcibus_bussoft *)) {149printk(KERN_ERR150"%s: Invalid vendor data length %d\n",151__func__, vendor->byte_length);152kfree(buffer.pointer);153return NULL;154}155memcpy(&addr, vendor->byte_data, sizeof(struct pcibus_bussoft *));156prom_bussoft_ptr = __va((struct pcibus_bussoft *) addr);157kfree(buffer.pointer);158159return prom_bussoft_ptr;160}161162/*163* sn_extract_device_info - Extract the pcidev_info and the sn_irq_info164* pointers from the vendor resource using the165* provided acpi handle, and copy the structures166* into the argument buffers.167*/168static int169sn_extract_device_info(acpi_handle handle, struct pcidev_info **pcidev_info,170struct sn_irq_info **sn_irq_info)171{172u64 addr;173struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };174struct acpi_buffer name_buffer = { ACPI_ALLOCATE_BUFFER, NULL };175struct sn_irq_info *irq_info, *irq_info_prom;176struct pcidev_info *pcidev_ptr, *pcidev_prom_ptr;177struct acpi_resource *resource;178int ret = 0;179acpi_status status;180struct acpi_resource_vendor_typed *vendor;181182/*183* The pointer to this device's pcidev_info structure in184* the PROM, is in the vendor resource.185*/186status = acpi_get_vendor_resource(handle, METHOD_NAME__CRS,187&sn_uuid, &buffer);188if (ACPI_FAILURE(status)) {189acpi_get_name(handle, ACPI_FULL_PATHNAME, &name_buffer);190printk(KERN_ERR191"%s: acpi_get_vendor_resource() failed (0x%x) for: %s\n",192__func__, status, (char *)name_buffer.pointer);193kfree(name_buffer.pointer);194return 1;195}196197resource = buffer.pointer;198vendor = &resource->data.vendor_typed;199if ((vendor->byte_length - sizeof(struct acpi_vendor_uuid)) !=200sizeof(struct pci_devdev_info *)) {201acpi_get_name(handle, ACPI_FULL_PATHNAME, &name_buffer);202printk(KERN_ERR203"%s: Invalid vendor data length: %d for: %s\n",204__func__, vendor->byte_length,205(char *)name_buffer.pointer);206kfree(name_buffer.pointer);207ret = 1;208goto exit;209}210211pcidev_ptr = kzalloc(sizeof(struct pcidev_info), GFP_KERNEL);212if (!pcidev_ptr)213panic("%s: Unable to alloc memory for pcidev_info", __func__);214215memcpy(&addr, vendor->byte_data, sizeof(struct pcidev_info *));216pcidev_prom_ptr = __va(addr);217memcpy(pcidev_ptr, pcidev_prom_ptr, sizeof(struct pcidev_info));218219/* Get the IRQ info */220irq_info = kzalloc(sizeof(struct sn_irq_info), GFP_KERNEL);221if (!irq_info)222panic("%s: Unable to alloc memory for sn_irq_info", __func__);223224if (pcidev_ptr->pdi_sn_irq_info) {225irq_info_prom = __va(pcidev_ptr->pdi_sn_irq_info);226memcpy(irq_info, irq_info_prom, sizeof(struct sn_irq_info));227}228229*pcidev_info = pcidev_ptr;230*sn_irq_info = irq_info;231232exit:233kfree(buffer.pointer);234return ret;235}236237static unsigned int238get_host_devfn(acpi_handle device_handle, acpi_handle rootbus_handle)239{240unsigned long long adr;241acpi_handle child;242unsigned int devfn;243int function;244acpi_handle parent;245int slot;246acpi_status status;247struct acpi_buffer name_buffer = { ACPI_ALLOCATE_BUFFER, NULL };248249acpi_get_name(device_handle, ACPI_FULL_PATHNAME, &name_buffer);250251/*252* Do an upward search to find the root bus device, and253* obtain the host devfn from the previous child device.254*/255child = device_handle;256while (child) {257status = acpi_get_parent(child, &parent);258if (ACPI_FAILURE(status)) {259printk(KERN_ERR "%s: acpi_get_parent() failed "260"(0x%x) for: %s\n", __func__, status,261(char *)name_buffer.pointer);262panic("%s: Unable to find host devfn\n", __func__);263}264if (parent == rootbus_handle)265break;266child = parent;267}268if (!child) {269printk(KERN_ERR "%s: Unable to find root bus for: %s\n",270__func__, (char *)name_buffer.pointer);271BUG();272}273274status = acpi_evaluate_integer(child, METHOD_NAME__ADR, NULL, &adr);275if (ACPI_FAILURE(status)) {276printk(KERN_ERR "%s: Unable to get _ADR (0x%x) for: %s\n",277__func__, status, (char *)name_buffer.pointer);278panic("%s: Unable to find host devfn\n", __func__);279}280281kfree(name_buffer.pointer);282283slot = (adr >> 16) & 0xffff;284function = adr & 0xffff;285devfn = PCI_DEVFN(slot, function);286return devfn;287}288289/*290* find_matching_device - Callback routine to find the ACPI device291* that matches up with our pci_dev device.292* Matching is done on bus number and devfn.293* To find the bus number for a particular294* ACPI device, we must look at the _BBN method295* of its parent.296*/297static acpi_status298find_matching_device(acpi_handle handle, u32 lvl, void *context, void **rv)299{300unsigned long long bbn = -1;301unsigned long long adr;302acpi_handle parent = NULL;303acpi_status status;304unsigned int devfn;305int function;306int slot;307struct sn_pcidev_match *info = context;308struct acpi_buffer name_buffer = { ACPI_ALLOCATE_BUFFER, NULL };309310status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,311&adr);312if (ACPI_SUCCESS(status)) {313status = acpi_get_parent(handle, &parent);314if (ACPI_FAILURE(status)) {315acpi_get_name(handle, ACPI_FULL_PATHNAME, &name_buffer);316printk(KERN_ERR317"%s: acpi_get_parent() failed (0x%x) for: %s\n",318__func__, status, (char *)name_buffer.pointer);319kfree(name_buffer.pointer);320return AE_OK;321}322status = acpi_evaluate_integer(parent, METHOD_NAME__BBN,323NULL, &bbn);324if (ACPI_FAILURE(status)) {325acpi_get_name(handle, ACPI_FULL_PATHNAME, &name_buffer);326printk(KERN_ERR327"%s: Failed to find _BBN in parent of: %s\n",328__func__, (char *)name_buffer.pointer);329kfree(name_buffer.pointer);330return AE_OK;331}332333slot = (adr >> 16) & 0xffff;334function = adr & 0xffff;335devfn = PCI_DEVFN(slot, function);336if ((info->devfn == devfn) && (info->bus == bbn)) {337/* We have a match! */338info->handle = handle;339return 1;340}341}342return AE_OK;343}344345/*346* sn_acpi_get_pcidev_info - Search ACPI namespace for the acpi347* device matching the specified pci_dev,348* and return the pcidev info and irq info.349*/350int351sn_acpi_get_pcidev_info(struct pci_dev *dev, struct pcidev_info **pcidev_info,352struct sn_irq_info **sn_irq_info)353{354unsigned int host_devfn;355struct sn_pcidev_match pcidev_match;356acpi_handle rootbus_handle;357unsigned long long segment;358acpi_status status;359struct acpi_buffer name_buffer = { ACPI_ALLOCATE_BUFFER, NULL };360361rootbus_handle = PCI_CONTROLLER(dev)->acpi_handle;362status = acpi_evaluate_integer(rootbus_handle, METHOD_NAME__SEG, NULL,363&segment);364if (ACPI_SUCCESS(status)) {365if (segment != pci_domain_nr(dev)) {366acpi_get_name(rootbus_handle, ACPI_FULL_PATHNAME,367&name_buffer);368printk(KERN_ERR369"%s: Segment number mismatch, 0x%llx vs 0x%x for: %s\n",370__func__, segment, pci_domain_nr(dev),371(char *)name_buffer.pointer);372kfree(name_buffer.pointer);373return 1;374}375} else {376acpi_get_name(rootbus_handle, ACPI_FULL_PATHNAME, &name_buffer);377printk(KERN_ERR "%s: Unable to get __SEG from: %s\n",378__func__, (char *)name_buffer.pointer);379kfree(name_buffer.pointer);380return 1;381}382383/*384* We want to search all devices in this segment/domain385* of the ACPI namespace for the matching ACPI device,386* which holds the pcidev_info pointer in its vendor resource.387*/388pcidev_match.bus = dev->bus->number;389pcidev_match.devfn = dev->devfn;390pcidev_match.handle = NULL;391392acpi_walk_namespace(ACPI_TYPE_DEVICE, rootbus_handle, ACPI_UINT32_MAX,393find_matching_device, NULL, &pcidev_match, NULL);394395if (!pcidev_match.handle) {396printk(KERN_ERR397"%s: Could not find matching ACPI device for %s.\n",398__func__, pci_name(dev));399return 1;400}401402if (sn_extract_device_info(pcidev_match.handle, pcidev_info, sn_irq_info))403return 1;404405/* Build up the pcidev_info.pdi_slot_host_handle */406host_devfn = get_host_devfn(pcidev_match.handle, rootbus_handle);407(*pcidev_info)->pdi_slot_host_handle =408((unsigned long) pci_domain_nr(dev) << 40) |409/* bus == 0 */410host_devfn;411return 0;412}413414/*415* sn_acpi_slot_fixup - Obtain the pcidev_info and sn_irq_info.416* Perform any SN specific slot fixup.417* At present there does not appear to be418* any generic way to handle a ROM image419* that has been shadowed by the PROM, so420* we pass a pointer to it within the421* pcidev_info structure.422*/423424void425sn_acpi_slot_fixup(struct pci_dev *dev)426{427void __iomem *addr;428struct pcidev_info *pcidev_info = NULL;429struct sn_irq_info *sn_irq_info = NULL;430size_t image_size, size;431432if (sn_acpi_get_pcidev_info(dev, &pcidev_info, &sn_irq_info)) {433panic("%s: Failure obtaining pcidev_info for %s\n",434__func__, pci_name(dev));435}436437if (pcidev_info->pdi_pio_mapped_addr[PCI_ROM_RESOURCE]) {438/*439* A valid ROM image exists and has been shadowed by the440* PROM. Setup the pci_dev ROM resource with the address441* of the shadowed copy, and the actual length of the ROM image.442*/443size = pci_resource_len(dev, PCI_ROM_RESOURCE);444addr = ioremap(pcidev_info->pdi_pio_mapped_addr[PCI_ROM_RESOURCE],445size);446image_size = pci_get_rom_size(dev, addr, size);447dev->resource[PCI_ROM_RESOURCE].start = (unsigned long) addr;448dev->resource[PCI_ROM_RESOURCE].end =449(unsigned long) addr + image_size - 1;450dev->resource[PCI_ROM_RESOURCE].flags |= IORESOURCE_ROM_BIOS_COPY;451}452sn_pci_fixup_slot(dev, pcidev_info, sn_irq_info);453}454455EXPORT_SYMBOL(sn_acpi_slot_fixup);456457458/*459* sn_acpi_bus_fixup - Perform SN specific setup of software structs460* (pcibus_bussoft, pcidev_info) and hardware461* registers, for the specified bus and devices under it.462*/463void464sn_acpi_bus_fixup(struct pci_bus *bus)465{466struct pci_dev *pci_dev = NULL;467struct pcibus_bussoft *prom_bussoft_ptr;468469if (!bus->parent) { /* If root bus */470prom_bussoft_ptr = sn_get_bussoft_ptr(bus);471if (prom_bussoft_ptr == NULL) {472printk(KERN_ERR473"%s: 0x%04x:0x%02x Unable to "474"obtain prom_bussoft_ptr\n",475__func__, pci_domain_nr(bus), bus->number);476return;477}478sn_common_bus_fixup(bus, prom_bussoft_ptr);479}480list_for_each_entry(pci_dev, &bus->devices, bus_list) {481sn_acpi_slot_fixup(pci_dev);482}483}484485/*486* sn_io_acpi_init - PROM has ACPI support for IO, defining at a minimum the487* nodes and root buses in the DSDT. As a result, bus scanning488* will be initiated by the Linux ACPI code.489*/490491void __init492sn_io_acpi_init(void)493{494u64 result;495long status;496497/* SN Altix does not follow the IOSAPIC IRQ routing model */498acpi_irq_model = ACPI_IRQ_MODEL_PLATFORM;499500/* Setup hubdev_info for all SGIHUB/SGITIO devices */501acpi_get_devices("SGIHUB", sn_acpi_hubdev_init, NULL, NULL);502acpi_get_devices("SGITIO", sn_acpi_hubdev_init, NULL, NULL);503504status = sal_ioif_init(&result);505if (status || result)506panic("sal_ioif_init failed: [%lx] %s\n",507status, ia64_sal_strerror(status));508}509510511