11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * pci.c - Low-Level PCI Access in IA-64 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Derived from bios32.c of i386 tree. 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * (c) Copyright 2002, 2005 Hewlett-Packard Development Company, L.P. 71da177e4SLinus Torvalds * David Mosberger-Tang <davidm@hpl.hp.com> 81da177e4SLinus Torvalds * Bjorn Helgaas <bjorn.helgaas@hp.com> 91da177e4SLinus Torvalds * Copyright (C) 2004 Silicon Graphics, Inc. 101da177e4SLinus Torvalds * 111da177e4SLinus Torvalds * Note: Above list of copyright holders is incomplete... 121da177e4SLinus Torvalds */ 131da177e4SLinus Torvalds #include <linux/config.h> 141da177e4SLinus Torvalds 151da177e4SLinus Torvalds #include <linux/acpi.h> 161da177e4SLinus Torvalds #include <linux/types.h> 171da177e4SLinus Torvalds #include <linux/kernel.h> 181da177e4SLinus Torvalds #include <linux/pci.h> 191da177e4SLinus Torvalds #include <linux/init.h> 201da177e4SLinus Torvalds #include <linux/ioport.h> 211da177e4SLinus Torvalds #include <linux/slab.h> 221da177e4SLinus Torvalds #include <linux/smp_lock.h> 231da177e4SLinus Torvalds #include <linux/spinlock.h> 241da177e4SLinus Torvalds 251da177e4SLinus Torvalds #include <asm/machvec.h> 261da177e4SLinus Torvalds #include <asm/page.h> 271da177e4SLinus Torvalds #include <asm/system.h> 281da177e4SLinus Torvalds #include <asm/io.h> 291da177e4SLinus Torvalds #include <asm/sal.h> 301da177e4SLinus Torvalds #include <asm/smp.h> 311da177e4SLinus Torvalds #include <asm/irq.h> 321da177e4SLinus Torvalds #include <asm/hw_irq.h> 331da177e4SLinus Torvalds 341da177e4SLinus Torvalds 351da177e4SLinus Torvalds /* 361da177e4SLinus Torvalds * Low-level SAL-based PCI configuration access functions. Note that SAL 371da177e4SLinus Torvalds * calls are already serialized (via sal_lock), so we don't need another 381da177e4SLinus Torvalds * synchronization mechanism here. 391da177e4SLinus Torvalds */ 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds #define PCI_SAL_ADDRESS(seg, bus, devfn, reg) \ 421da177e4SLinus Torvalds (((u64) seg << 24) | (bus << 16) | (devfn << 8) | (reg)) 431da177e4SLinus Torvalds 441da177e4SLinus Torvalds /* SAL 3.2 adds support for extended config space. */ 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds #define PCI_SAL_EXT_ADDRESS(seg, bus, devfn, reg) \ 471da177e4SLinus Torvalds (((u64) seg << 28) | (bus << 20) | (devfn << 12) | (reg)) 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds static int 501da177e4SLinus Torvalds pci_sal_read (unsigned int seg, unsigned int bus, unsigned int devfn, 511da177e4SLinus Torvalds int reg, int len, u32 *value) 521da177e4SLinus Torvalds { 531da177e4SLinus Torvalds u64 addr, data = 0; 541da177e4SLinus Torvalds int mode, result; 551da177e4SLinus Torvalds 561da177e4SLinus Torvalds if (!value || (seg > 65535) || (bus > 255) || (devfn > 255) || (reg > 4095)) 571da177e4SLinus Torvalds return -EINVAL; 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds if ((seg | reg) <= 255) { 601da177e4SLinus Torvalds addr = PCI_SAL_ADDRESS(seg, bus, devfn, reg); 611da177e4SLinus Torvalds mode = 0; 621da177e4SLinus Torvalds } else { 631da177e4SLinus Torvalds addr = PCI_SAL_EXT_ADDRESS(seg, bus, devfn, reg); 641da177e4SLinus Torvalds mode = 1; 651da177e4SLinus Torvalds } 661da177e4SLinus Torvalds result = ia64_sal_pci_config_read(addr, mode, len, &data); 671da177e4SLinus Torvalds if (result != 0) 681da177e4SLinus Torvalds return -EINVAL; 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds *value = (u32) data; 711da177e4SLinus Torvalds return 0; 721da177e4SLinus Torvalds } 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds static int 751da177e4SLinus Torvalds pci_sal_write (unsigned int seg, unsigned int bus, unsigned int devfn, 761da177e4SLinus Torvalds int reg, int len, u32 value) 771da177e4SLinus Torvalds { 781da177e4SLinus Torvalds u64 addr; 791da177e4SLinus Torvalds int mode, result; 801da177e4SLinus Torvalds 811da177e4SLinus Torvalds if ((seg > 65535) || (bus > 255) || (devfn > 255) || (reg > 4095)) 821da177e4SLinus Torvalds return -EINVAL; 831da177e4SLinus Torvalds 841da177e4SLinus Torvalds if ((seg | reg) <= 255) { 851da177e4SLinus Torvalds addr = PCI_SAL_ADDRESS(seg, bus, devfn, reg); 861da177e4SLinus Torvalds mode = 0; 871da177e4SLinus Torvalds } else { 881da177e4SLinus Torvalds addr = PCI_SAL_EXT_ADDRESS(seg, bus, devfn, reg); 891da177e4SLinus Torvalds mode = 1; 901da177e4SLinus Torvalds } 911da177e4SLinus Torvalds result = ia64_sal_pci_config_write(addr, mode, len, value); 921da177e4SLinus Torvalds if (result != 0) 931da177e4SLinus Torvalds return -EINVAL; 941da177e4SLinus Torvalds return 0; 951da177e4SLinus Torvalds } 961da177e4SLinus Torvalds 971da177e4SLinus Torvalds static struct pci_raw_ops pci_sal_ops = { 981da177e4SLinus Torvalds .read = pci_sal_read, 991da177e4SLinus Torvalds .write = pci_sal_write 1001da177e4SLinus Torvalds }; 1011da177e4SLinus Torvalds 1021da177e4SLinus Torvalds struct pci_raw_ops *raw_pci_ops = &pci_sal_ops; 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds static int 1051da177e4SLinus Torvalds pci_read (struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value) 1061da177e4SLinus Torvalds { 1071da177e4SLinus Torvalds return raw_pci_ops->read(pci_domain_nr(bus), bus->number, 1081da177e4SLinus Torvalds devfn, where, size, value); 1091da177e4SLinus Torvalds } 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds static int 1121da177e4SLinus Torvalds pci_write (struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value) 1131da177e4SLinus Torvalds { 1141da177e4SLinus Torvalds return raw_pci_ops->write(pci_domain_nr(bus), bus->number, 1151da177e4SLinus Torvalds devfn, where, size, value); 1161da177e4SLinus Torvalds } 1171da177e4SLinus Torvalds 1181da177e4SLinus Torvalds struct pci_ops pci_root_ops = { 1191da177e4SLinus Torvalds .read = pci_read, 1201da177e4SLinus Torvalds .write = pci_write, 1211da177e4SLinus Torvalds }; 1221da177e4SLinus Torvalds 1231da177e4SLinus Torvalds /* Called by ACPI when it finds a new root bus. */ 1241da177e4SLinus Torvalds 1251da177e4SLinus Torvalds static struct pci_controller * __devinit 1261da177e4SLinus Torvalds alloc_pci_controller (int seg) 1271da177e4SLinus Torvalds { 1281da177e4SLinus Torvalds struct pci_controller *controller; 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds controller = kmalloc(sizeof(*controller), GFP_KERNEL); 1311da177e4SLinus Torvalds if (!controller) 1321da177e4SLinus Torvalds return NULL; 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds memset(controller, 0, sizeof(*controller)); 1351da177e4SLinus Torvalds controller->segment = seg; 136514604c6SChristoph Lameter controller->node = -1; 1371da177e4SLinus Torvalds return controller; 1381da177e4SLinus Torvalds } 1391da177e4SLinus Torvalds 1404f41d5a4SBjorn Helgaas struct pci_root_info { 1414f41d5a4SBjorn Helgaas struct pci_controller *controller; 1424f41d5a4SBjorn Helgaas char *name; 1434f41d5a4SBjorn Helgaas }; 1444f41d5a4SBjorn Helgaas 1454f41d5a4SBjorn Helgaas static unsigned int 1464f41d5a4SBjorn Helgaas new_space (u64 phys_base, int sparse) 1471da177e4SLinus Torvalds { 1484f41d5a4SBjorn Helgaas u64 mmio_base; 1491da177e4SLinus Torvalds int i; 1501da177e4SLinus Torvalds 1514f41d5a4SBjorn Helgaas if (phys_base == 0) 1524f41d5a4SBjorn Helgaas return 0; /* legacy I/O port space */ 1531da177e4SLinus Torvalds 1544f41d5a4SBjorn Helgaas mmio_base = (u64) ioremap(phys_base, 0); 1551da177e4SLinus Torvalds for (i = 0; i < num_io_spaces; i++) 1564f41d5a4SBjorn Helgaas if (io_space[i].mmio_base == mmio_base && 1571da177e4SLinus Torvalds io_space[i].sparse == sparse) 1584f41d5a4SBjorn Helgaas return i; 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds if (num_io_spaces == MAX_IO_SPACES) { 1614f41d5a4SBjorn Helgaas printk(KERN_ERR "PCI: Too many IO port spaces " 1624f41d5a4SBjorn Helgaas "(MAX_IO_SPACES=%lu)\n", MAX_IO_SPACES); 1631da177e4SLinus Torvalds return ~0; 1641da177e4SLinus Torvalds } 1651da177e4SLinus Torvalds 1661da177e4SLinus Torvalds i = num_io_spaces++; 1674f41d5a4SBjorn Helgaas io_space[i].mmio_base = mmio_base; 1681da177e4SLinus Torvalds io_space[i].sparse = sparse; 1691da177e4SLinus Torvalds 1704f41d5a4SBjorn Helgaas return i; 1714f41d5a4SBjorn Helgaas } 1724f41d5a4SBjorn Helgaas 1734f41d5a4SBjorn Helgaas static u64 __devinit 1744f41d5a4SBjorn Helgaas add_io_space (struct pci_root_info *info, struct acpi_resource_address64 *addr) 1754f41d5a4SBjorn Helgaas { 1764f41d5a4SBjorn Helgaas struct resource *resource; 1774f41d5a4SBjorn Helgaas char *name; 1784f41d5a4SBjorn Helgaas u64 base, min, max, base_port; 1794f41d5a4SBjorn Helgaas unsigned int sparse = 0, space_nr, len; 1804f41d5a4SBjorn Helgaas 1814f41d5a4SBjorn Helgaas resource = kzalloc(sizeof(*resource), GFP_KERNEL); 1824f41d5a4SBjorn Helgaas if (!resource) { 1834f41d5a4SBjorn Helgaas printk(KERN_ERR "PCI: No memory for %s I/O port space\n", 1844f41d5a4SBjorn Helgaas info->name); 1854f41d5a4SBjorn Helgaas goto out; 1864f41d5a4SBjorn Helgaas } 1874f41d5a4SBjorn Helgaas 1884f41d5a4SBjorn Helgaas len = strlen(info->name) + 32; 1894f41d5a4SBjorn Helgaas name = kzalloc(len, GFP_KERNEL); 1904f41d5a4SBjorn Helgaas if (!name) { 1914f41d5a4SBjorn Helgaas printk(KERN_ERR "PCI: No memory for %s I/O port space name\n", 1924f41d5a4SBjorn Helgaas info->name); 1934f41d5a4SBjorn Helgaas goto free_resource; 1944f41d5a4SBjorn Helgaas } 1954f41d5a4SBjorn Helgaas 1964f41d5a4SBjorn Helgaas min = addr->min_address_range; 1974f41d5a4SBjorn Helgaas max = min + addr->address_length - 1; 1984f41d5a4SBjorn Helgaas if (addr->attribute.io.translation_attribute == ACPI_SPARSE_TRANSLATION) 1994f41d5a4SBjorn Helgaas sparse = 1; 2004f41d5a4SBjorn Helgaas 2014f41d5a4SBjorn Helgaas space_nr = new_space(addr->address_translation_offset, sparse); 2024f41d5a4SBjorn Helgaas if (space_nr == ~0) 2034f41d5a4SBjorn Helgaas goto free_name; 2044f41d5a4SBjorn Helgaas 2054f41d5a4SBjorn Helgaas base = __pa(io_space[space_nr].mmio_base); 2064f41d5a4SBjorn Helgaas base_port = IO_SPACE_BASE(space_nr); 2074f41d5a4SBjorn Helgaas snprintf(name, len, "%s I/O Ports %08lx-%08lx", info->name, 2084f41d5a4SBjorn Helgaas base_port + min, base_port + max); 2094f41d5a4SBjorn Helgaas 2104f41d5a4SBjorn Helgaas /* 2114f41d5a4SBjorn Helgaas * The SDM guarantees the legacy 0-64K space is sparse, but if the 2124f41d5a4SBjorn Helgaas * mapping is done by the processor (not the bridge), ACPI may not 2134f41d5a4SBjorn Helgaas * mark it as sparse. 2144f41d5a4SBjorn Helgaas */ 2154f41d5a4SBjorn Helgaas if (space_nr == 0) 2164f41d5a4SBjorn Helgaas sparse = 1; 2174f41d5a4SBjorn Helgaas 2184f41d5a4SBjorn Helgaas resource->name = name; 2194f41d5a4SBjorn Helgaas resource->flags = IORESOURCE_MEM; 2204f41d5a4SBjorn Helgaas resource->start = base + (sparse ? IO_SPACE_SPARSE_ENCODING(min) : min); 2214f41d5a4SBjorn Helgaas resource->end = base + (sparse ? IO_SPACE_SPARSE_ENCODING(max) : max); 2224f41d5a4SBjorn Helgaas insert_resource(&iomem_resource, resource); 2234f41d5a4SBjorn Helgaas 2244f41d5a4SBjorn Helgaas return base_port; 2254f41d5a4SBjorn Helgaas 2264f41d5a4SBjorn Helgaas free_name: 2274f41d5a4SBjorn Helgaas kfree(name); 2284f41d5a4SBjorn Helgaas free_resource: 2294f41d5a4SBjorn Helgaas kfree(resource); 2304f41d5a4SBjorn Helgaas out: 2314f41d5a4SBjorn Helgaas return ~0; 2321da177e4SLinus Torvalds } 2331da177e4SLinus Torvalds 234463eb297SBjorn Helgaas static acpi_status __devinit resource_to_window(struct acpi_resource *resource, 235463eb297SBjorn Helgaas struct acpi_resource_address64 *addr) 236463eb297SBjorn Helgaas { 237463eb297SBjorn Helgaas acpi_status status; 238463eb297SBjorn Helgaas 239463eb297SBjorn Helgaas /* 240463eb297SBjorn Helgaas * We're only interested in _CRS descriptors that are 241463eb297SBjorn Helgaas * - address space descriptors for memory or I/O space 242463eb297SBjorn Helgaas * - non-zero size 243463eb297SBjorn Helgaas * - producers, i.e., the address space is routed downstream, 244463eb297SBjorn Helgaas * not consumed by the bridge itself 245463eb297SBjorn Helgaas */ 246463eb297SBjorn Helgaas status = acpi_resource_to_address64(resource, addr); 247463eb297SBjorn Helgaas if (ACPI_SUCCESS(status) && 248463eb297SBjorn Helgaas (addr->resource_type == ACPI_MEMORY_RANGE || 249463eb297SBjorn Helgaas addr->resource_type == ACPI_IO_RANGE) && 250463eb297SBjorn Helgaas addr->address_length && 251463eb297SBjorn Helgaas addr->producer_consumer == ACPI_PRODUCER) 252463eb297SBjorn Helgaas return AE_OK; 253463eb297SBjorn Helgaas 254463eb297SBjorn Helgaas return AE_ERROR; 255463eb297SBjorn Helgaas } 256463eb297SBjorn Helgaas 2571da177e4SLinus Torvalds static acpi_status __devinit 2581da177e4SLinus Torvalds count_window (struct acpi_resource *resource, void *data) 2591da177e4SLinus Torvalds { 2601da177e4SLinus Torvalds unsigned int *windows = (unsigned int *) data; 2611da177e4SLinus Torvalds struct acpi_resource_address64 addr; 2621da177e4SLinus Torvalds acpi_status status; 2631da177e4SLinus Torvalds 264463eb297SBjorn Helgaas status = resource_to_window(resource, &addr); 2651da177e4SLinus Torvalds if (ACPI_SUCCESS(status)) 2661da177e4SLinus Torvalds (*windows)++; 2671da177e4SLinus Torvalds 2681da177e4SLinus Torvalds return AE_OK; 2691da177e4SLinus Torvalds } 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds static __devinit acpi_status add_window(struct acpi_resource *res, void *data) 2721da177e4SLinus Torvalds { 2731da177e4SLinus Torvalds struct pci_root_info *info = data; 2741da177e4SLinus Torvalds struct pci_window *window; 2751da177e4SLinus Torvalds struct acpi_resource_address64 addr; 2761da177e4SLinus Torvalds acpi_status status; 2771da177e4SLinus Torvalds unsigned long flags, offset = 0; 2781da177e4SLinus Torvalds struct resource *root; 2791da177e4SLinus Torvalds 280463eb297SBjorn Helgaas /* Return AE_OK for non-window resources to keep scanning for more */ 281463eb297SBjorn Helgaas status = resource_to_window(res, &addr); 2821da177e4SLinus Torvalds if (!ACPI_SUCCESS(status)) 2831da177e4SLinus Torvalds return AE_OK; 2841da177e4SLinus Torvalds 2851da177e4SLinus Torvalds if (addr.resource_type == ACPI_MEMORY_RANGE) { 2861da177e4SLinus Torvalds flags = IORESOURCE_MEM; 2871da177e4SLinus Torvalds root = &iomem_resource; 2881da177e4SLinus Torvalds offset = addr.address_translation_offset; 2891da177e4SLinus Torvalds } else if (addr.resource_type == ACPI_IO_RANGE) { 2901da177e4SLinus Torvalds flags = IORESOURCE_IO; 2911da177e4SLinus Torvalds root = &ioport_resource; 2924f41d5a4SBjorn Helgaas offset = add_io_space(info, &addr); 2931da177e4SLinus Torvalds if (offset == ~0) 2941da177e4SLinus Torvalds return AE_OK; 2951da177e4SLinus Torvalds } else 2961da177e4SLinus Torvalds return AE_OK; 2971da177e4SLinus Torvalds 2981da177e4SLinus Torvalds window = &info->controller->window[info->controller->windows++]; 2991da177e4SLinus Torvalds window->resource.name = info->name; 3001da177e4SLinus Torvalds window->resource.flags = flags; 3011da177e4SLinus Torvalds window->resource.start = addr.min_address_range + offset; 3024f41d5a4SBjorn Helgaas window->resource.end = window->resource.start + addr.address_length - 1; 3031da177e4SLinus Torvalds window->resource.child = NULL; 3041da177e4SLinus Torvalds window->offset = offset; 3051da177e4SLinus Torvalds 3061da177e4SLinus Torvalds if (insert_resource(root, &window->resource)) { 3071da177e4SLinus Torvalds printk(KERN_ERR "alloc 0x%lx-0x%lx from %s for %s failed\n", 3081da177e4SLinus Torvalds window->resource.start, window->resource.end, 3091da177e4SLinus Torvalds root->name, info->name); 3101da177e4SLinus Torvalds } 3111da177e4SLinus Torvalds 3121da177e4SLinus Torvalds return AE_OK; 3131da177e4SLinus Torvalds } 3141da177e4SLinus Torvalds 3151da177e4SLinus Torvalds static void __devinit 3161da177e4SLinus Torvalds pcibios_setup_root_windows(struct pci_bus *bus, struct pci_controller *ctrl) 3171da177e4SLinus Torvalds { 3181da177e4SLinus Torvalds int i, j; 3191da177e4SLinus Torvalds 3201da177e4SLinus Torvalds j = 0; 3211da177e4SLinus Torvalds for (i = 0; i < ctrl->windows; i++) { 3221da177e4SLinus Torvalds struct resource *res = &ctrl->window[i].resource; 3231da177e4SLinus Torvalds /* HP's firmware has a hack to work around a Windows bug. 3241da177e4SLinus Torvalds * Ignore these tiny memory ranges */ 3251da177e4SLinus Torvalds if ((res->flags & IORESOURCE_MEM) && 3261da177e4SLinus Torvalds (res->end - res->start < 16)) 3271da177e4SLinus Torvalds continue; 3281da177e4SLinus Torvalds if (j >= PCI_BUS_NUM_RESOURCES) { 3291da177e4SLinus Torvalds printk("Ignoring range [%lx-%lx] (%lx)\n", res->start, 3301da177e4SLinus Torvalds res->end, res->flags); 3311da177e4SLinus Torvalds continue; 3321da177e4SLinus Torvalds } 3331da177e4SLinus Torvalds bus->resource[j++] = res; 3341da177e4SLinus Torvalds } 3351da177e4SLinus Torvalds } 3361da177e4SLinus Torvalds 3371da177e4SLinus Torvalds struct pci_bus * __devinit 3381da177e4SLinus Torvalds pci_acpi_scan_root(struct acpi_device *device, int domain, int bus) 3391da177e4SLinus Torvalds { 3401da177e4SLinus Torvalds struct pci_root_info info; 3411da177e4SLinus Torvalds struct pci_controller *controller; 3421da177e4SLinus Torvalds unsigned int windows = 0; 3431da177e4SLinus Torvalds struct pci_bus *pbus; 3441da177e4SLinus Torvalds char *name; 345514604c6SChristoph Lameter int pxm; 3461da177e4SLinus Torvalds 3471da177e4SLinus Torvalds controller = alloc_pci_controller(domain); 3481da177e4SLinus Torvalds if (!controller) 3491da177e4SLinus Torvalds goto out1; 3501da177e4SLinus Torvalds 3511da177e4SLinus Torvalds controller->acpi_handle = device->handle; 3521da177e4SLinus Torvalds 353514604c6SChristoph Lameter pxm = acpi_get_pxm(controller->acpi_handle); 354514604c6SChristoph Lameter #ifdef CONFIG_NUMA 355514604c6SChristoph Lameter if (pxm >= 0) 356514604c6SChristoph Lameter controller->node = pxm_to_nid_map[pxm]; 357514604c6SChristoph Lameter #endif 358514604c6SChristoph Lameter 3591da177e4SLinus Torvalds acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_window, 3601da177e4SLinus Torvalds &windows); 361514604c6SChristoph Lameter controller->window = kmalloc_node(sizeof(*controller->window) * windows, 362514604c6SChristoph Lameter GFP_KERNEL, controller->node); 3631da177e4SLinus Torvalds if (!controller->window) 3641da177e4SLinus Torvalds goto out2; 3651da177e4SLinus Torvalds 3661da177e4SLinus Torvalds name = kmalloc(16, GFP_KERNEL); 3671da177e4SLinus Torvalds if (!name) 3681da177e4SLinus Torvalds goto out3; 3691da177e4SLinus Torvalds 3701da177e4SLinus Torvalds sprintf(name, "PCI Bus %04x:%02x", domain, bus); 3711da177e4SLinus Torvalds info.controller = controller; 3721da177e4SLinus Torvalds info.name = name; 3731da177e4SLinus Torvalds acpi_walk_resources(device->handle, METHOD_NAME__CRS, add_window, 3741da177e4SLinus Torvalds &info); 3751da177e4SLinus Torvalds 376c431ada4SRajesh Shah pbus = pci_scan_bus_parented(NULL, bus, &pci_root_ops, controller); 3771da177e4SLinus Torvalds if (pbus) 3781da177e4SLinus Torvalds pcibios_setup_root_windows(pbus, controller); 3791da177e4SLinus Torvalds 3801da177e4SLinus Torvalds return pbus; 3811da177e4SLinus Torvalds 3821da177e4SLinus Torvalds out3: 3831da177e4SLinus Torvalds kfree(controller->window); 3841da177e4SLinus Torvalds out2: 3851da177e4SLinus Torvalds kfree(controller); 3861da177e4SLinus Torvalds out1: 3871da177e4SLinus Torvalds return NULL; 3881da177e4SLinus Torvalds } 3891da177e4SLinus Torvalds 3901da177e4SLinus Torvalds void pcibios_resource_to_bus(struct pci_dev *dev, 3911da177e4SLinus Torvalds struct pci_bus_region *region, struct resource *res) 3921da177e4SLinus Torvalds { 3931da177e4SLinus Torvalds struct pci_controller *controller = PCI_CONTROLLER(dev); 3941da177e4SLinus Torvalds unsigned long offset = 0; 3951da177e4SLinus Torvalds int i; 3961da177e4SLinus Torvalds 3971da177e4SLinus Torvalds for (i = 0; i < controller->windows; i++) { 3981da177e4SLinus Torvalds struct pci_window *window = &controller->window[i]; 3991da177e4SLinus Torvalds if (!(window->resource.flags & res->flags)) 4001da177e4SLinus Torvalds continue; 4011da177e4SLinus Torvalds if (window->resource.start > res->start) 4021da177e4SLinus Torvalds continue; 4031da177e4SLinus Torvalds if (window->resource.end < res->end) 4041da177e4SLinus Torvalds continue; 4051da177e4SLinus Torvalds offset = window->offset; 4061da177e4SLinus Torvalds break; 4071da177e4SLinus Torvalds } 4081da177e4SLinus Torvalds 4091da177e4SLinus Torvalds region->start = res->start - offset; 4101da177e4SLinus Torvalds region->end = res->end - offset; 4111da177e4SLinus Torvalds } 4121da177e4SLinus Torvalds EXPORT_SYMBOL(pcibios_resource_to_bus); 4131da177e4SLinus Torvalds 4141da177e4SLinus Torvalds void pcibios_bus_to_resource(struct pci_dev *dev, 4151da177e4SLinus Torvalds struct resource *res, struct pci_bus_region *region) 4161da177e4SLinus Torvalds { 4171da177e4SLinus Torvalds struct pci_controller *controller = PCI_CONTROLLER(dev); 4181da177e4SLinus Torvalds unsigned long offset = 0; 4191da177e4SLinus Torvalds int i; 4201da177e4SLinus Torvalds 4211da177e4SLinus Torvalds for (i = 0; i < controller->windows; i++) { 4221da177e4SLinus Torvalds struct pci_window *window = &controller->window[i]; 4231da177e4SLinus Torvalds if (!(window->resource.flags & res->flags)) 4241da177e4SLinus Torvalds continue; 4251da177e4SLinus Torvalds if (window->resource.start - window->offset > region->start) 4261da177e4SLinus Torvalds continue; 4271da177e4SLinus Torvalds if (window->resource.end - window->offset < region->end) 4281da177e4SLinus Torvalds continue; 4291da177e4SLinus Torvalds offset = window->offset; 4301da177e4SLinus Torvalds break; 4311da177e4SLinus Torvalds } 4321da177e4SLinus Torvalds 4331da177e4SLinus Torvalds res->start = region->start + offset; 4341da177e4SLinus Torvalds res->end = region->end + offset; 4351da177e4SLinus Torvalds } 43641290c14SKeith Owens EXPORT_SYMBOL(pcibios_bus_to_resource); 4371da177e4SLinus Torvalds 43871c3511cSRajesh Shah static int __devinit is_valid_resource(struct pci_dev *dev, int idx) 43971c3511cSRajesh Shah { 44071c3511cSRajesh Shah unsigned int i, type_mask = IORESOURCE_IO | IORESOURCE_MEM; 44171c3511cSRajesh Shah struct resource *devr = &dev->resource[idx]; 44271c3511cSRajesh Shah 44371c3511cSRajesh Shah if (!dev->bus) 44471c3511cSRajesh Shah return 0; 44571c3511cSRajesh Shah for (i=0; i<PCI_BUS_NUM_RESOURCES; i++) { 44671c3511cSRajesh Shah struct resource *busr = dev->bus->resource[i]; 44771c3511cSRajesh Shah 44871c3511cSRajesh Shah if (!busr || ((busr->flags ^ devr->flags) & type_mask)) 44971c3511cSRajesh Shah continue; 45071c3511cSRajesh Shah if ((devr->start) && (devr->start >= busr->start) && 45171c3511cSRajesh Shah (devr->end <= busr->end)) 45271c3511cSRajesh Shah return 1; 45371c3511cSRajesh Shah } 45471c3511cSRajesh Shah return 0; 45571c3511cSRajesh Shah } 45671c3511cSRajesh Shah 4571da177e4SLinus Torvalds static void __devinit pcibios_fixup_device_resources(struct pci_dev *dev) 4581da177e4SLinus Torvalds { 4591da177e4SLinus Torvalds struct pci_bus_region region; 4601da177e4SLinus Torvalds int i; 4611da177e4SLinus Torvalds int limit = (dev->hdr_type == PCI_HEADER_TYPE_NORMAL) ? \ 4621da177e4SLinus Torvalds PCI_BRIDGE_RESOURCES : PCI_NUM_RESOURCES; 4631da177e4SLinus Torvalds 4641da177e4SLinus Torvalds for (i = 0; i < limit; i++) { 4651da177e4SLinus Torvalds if (!dev->resource[i].flags) 4661da177e4SLinus Torvalds continue; 4671da177e4SLinus Torvalds region.start = dev->resource[i].start; 4681da177e4SLinus Torvalds region.end = dev->resource[i].end; 4691da177e4SLinus Torvalds pcibios_bus_to_resource(dev, &dev->resource[i], ®ion); 47071c3511cSRajesh Shah if ((is_valid_resource(dev, i))) 4711da177e4SLinus Torvalds pci_claim_resource(dev, i); 4721da177e4SLinus Torvalds } 4731da177e4SLinus Torvalds } 4741da177e4SLinus Torvalds 4751da177e4SLinus Torvalds /* 4761da177e4SLinus Torvalds * Called after each bus is probed, but before its children are examined. 4771da177e4SLinus Torvalds */ 4781da177e4SLinus Torvalds void __devinit 4791da177e4SLinus Torvalds pcibios_fixup_bus (struct pci_bus *b) 4801da177e4SLinus Torvalds { 4811da177e4SLinus Torvalds struct pci_dev *dev; 4821da177e4SLinus Torvalds 483f7d473d9SRajesh Shah if (b->self) { 484f7d473d9SRajesh Shah pci_read_bridge_bases(b); 485f7d473d9SRajesh Shah pcibios_fixup_device_resources(b->self); 486f7d473d9SRajesh Shah } 4871da177e4SLinus Torvalds list_for_each_entry(dev, &b->devices, bus_list) 4881da177e4SLinus Torvalds pcibios_fixup_device_resources(dev); 4891da177e4SLinus Torvalds 4901da177e4SLinus Torvalds return; 4911da177e4SLinus Torvalds } 4921da177e4SLinus Torvalds 4931da177e4SLinus Torvalds void __devinit 4941da177e4SLinus Torvalds pcibios_update_irq (struct pci_dev *dev, int irq) 4951da177e4SLinus Torvalds { 4961da177e4SLinus Torvalds pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq); 4971da177e4SLinus Torvalds 4981da177e4SLinus Torvalds /* ??? FIXME -- record old value for shutdown. */ 4991da177e4SLinus Torvalds } 5001da177e4SLinus Torvalds 5011da177e4SLinus Torvalds static inline int 5021da177e4SLinus Torvalds pcibios_enable_resources (struct pci_dev *dev, int mask) 5031da177e4SLinus Torvalds { 5041da177e4SLinus Torvalds u16 cmd, old_cmd; 5051da177e4SLinus Torvalds int idx; 5061da177e4SLinus Torvalds struct resource *r; 507fab3fb0aSRajesh Shah unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM; 5081da177e4SLinus Torvalds 5091da177e4SLinus Torvalds if (!dev) 5101da177e4SLinus Torvalds return -EINVAL; 5111da177e4SLinus Torvalds 5121da177e4SLinus Torvalds pci_read_config_word(dev, PCI_COMMAND, &cmd); 5131da177e4SLinus Torvalds old_cmd = cmd; 514fab3fb0aSRajesh Shah for (idx=0; idx<PCI_NUM_RESOURCES; idx++) { 5151da177e4SLinus Torvalds /* Only set up the desired resources. */ 5161da177e4SLinus Torvalds if (!(mask & (1 << idx))) 5171da177e4SLinus Torvalds continue; 5181da177e4SLinus Torvalds 5191da177e4SLinus Torvalds r = &dev->resource[idx]; 520fab3fb0aSRajesh Shah if (!(r->flags & type_mask)) 521fab3fb0aSRajesh Shah continue; 522fab3fb0aSRajesh Shah if ((idx == PCI_ROM_RESOURCE) && 523fab3fb0aSRajesh Shah (!(r->flags & IORESOURCE_ROM_ENABLE))) 524fab3fb0aSRajesh Shah continue; 5251da177e4SLinus Torvalds if (!r->start && r->end) { 5261da177e4SLinus Torvalds printk(KERN_ERR 5271da177e4SLinus Torvalds "PCI: Device %s not available because of resource collisions\n", 5281da177e4SLinus Torvalds pci_name(dev)); 5291da177e4SLinus Torvalds return -EINVAL; 5301da177e4SLinus Torvalds } 5311da177e4SLinus Torvalds if (r->flags & IORESOURCE_IO) 5321da177e4SLinus Torvalds cmd |= PCI_COMMAND_IO; 5331da177e4SLinus Torvalds if (r->flags & IORESOURCE_MEM) 5341da177e4SLinus Torvalds cmd |= PCI_COMMAND_MEMORY; 5351da177e4SLinus Torvalds } 5361da177e4SLinus Torvalds if (cmd != old_cmd) { 5371da177e4SLinus Torvalds printk("PCI: Enabling device %s (%04x -> %04x)\n", pci_name(dev), old_cmd, cmd); 5381da177e4SLinus Torvalds pci_write_config_word(dev, PCI_COMMAND, cmd); 5391da177e4SLinus Torvalds } 5401da177e4SLinus Torvalds return 0; 5411da177e4SLinus Torvalds } 5421da177e4SLinus Torvalds 5431da177e4SLinus Torvalds int 5441da177e4SLinus Torvalds pcibios_enable_device (struct pci_dev *dev, int mask) 5451da177e4SLinus Torvalds { 5461da177e4SLinus Torvalds int ret; 5471da177e4SLinus Torvalds 5481da177e4SLinus Torvalds ret = pcibios_enable_resources(dev, mask); 5491da177e4SLinus Torvalds if (ret < 0) 5501da177e4SLinus Torvalds return ret; 5511da177e4SLinus Torvalds 5521da177e4SLinus Torvalds return acpi_pci_irq_enable(dev); 5531da177e4SLinus Torvalds } 5541da177e4SLinus Torvalds 5551da177e4SLinus Torvalds void 5561da177e4SLinus Torvalds pcibios_disable_device (struct pci_dev *dev) 5571da177e4SLinus Torvalds { 5581da177e4SLinus Torvalds acpi_pci_irq_disable(dev); 5591da177e4SLinus Torvalds } 5601da177e4SLinus Torvalds 5611da177e4SLinus Torvalds void 5621da177e4SLinus Torvalds pcibios_align_resource (void *data, struct resource *res, 5631da177e4SLinus Torvalds unsigned long size, unsigned long align) 5641da177e4SLinus Torvalds { 5651da177e4SLinus Torvalds } 5661da177e4SLinus Torvalds 5671da177e4SLinus Torvalds /* 5681da177e4SLinus Torvalds * PCI BIOS setup, always defaults to SAL interface 5691da177e4SLinus Torvalds */ 5701da177e4SLinus Torvalds char * __init 5711da177e4SLinus Torvalds pcibios_setup (char *str) 5721da177e4SLinus Torvalds { 5731da177e4SLinus Torvalds return NULL; 5741da177e4SLinus Torvalds } 5751da177e4SLinus Torvalds 5761da177e4SLinus Torvalds int 5771da177e4SLinus Torvalds pci_mmap_page_range (struct pci_dev *dev, struct vm_area_struct *vma, 5781da177e4SLinus Torvalds enum pci_mmap_state mmap_state, int write_combine) 5791da177e4SLinus Torvalds { 5801da177e4SLinus Torvalds /* 5811da177e4SLinus Torvalds * I/O space cannot be accessed via normal processor loads and 5821da177e4SLinus Torvalds * stores on this platform. 5831da177e4SLinus Torvalds */ 5841da177e4SLinus Torvalds if (mmap_state == pci_mmap_io) 5851da177e4SLinus Torvalds /* 5861da177e4SLinus Torvalds * XXX we could relax this for I/O spaces for which ACPI 5871da177e4SLinus Torvalds * indicates that the space is 1-to-1 mapped. But at the 5881da177e4SLinus Torvalds * moment, we don't support multiple PCI address spaces and 5891da177e4SLinus Torvalds * the legacy I/O space is not 1-to-1 mapped, so this is moot. 5901da177e4SLinus Torvalds */ 5911da177e4SLinus Torvalds return -EINVAL; 5921da177e4SLinus Torvalds 5931da177e4SLinus Torvalds /* 5941da177e4SLinus Torvalds * Leave vm_pgoff as-is, the PCI space address is the physical 5951da177e4SLinus Torvalds * address on this platform. 5961da177e4SLinus Torvalds */ 5971da177e4SLinus Torvalds vma->vm_flags |= (VM_SHM | VM_RESERVED | VM_IO); 5981da177e4SLinus Torvalds 5991da177e4SLinus Torvalds if (write_combine && efi_range_is_wc(vma->vm_start, 6001da177e4SLinus Torvalds vma->vm_end - vma->vm_start)) 6011da177e4SLinus Torvalds vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); 6021da177e4SLinus Torvalds else 6031da177e4SLinus Torvalds vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 6041da177e4SLinus Torvalds 6051da177e4SLinus Torvalds if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, 6061da177e4SLinus Torvalds vma->vm_end - vma->vm_start, vma->vm_page_prot)) 6071da177e4SLinus Torvalds return -EAGAIN; 6081da177e4SLinus Torvalds 6091da177e4SLinus Torvalds return 0; 6101da177e4SLinus Torvalds } 6111da177e4SLinus Torvalds 6121da177e4SLinus Torvalds /** 6131da177e4SLinus Torvalds * ia64_pci_get_legacy_mem - generic legacy mem routine 6141da177e4SLinus Torvalds * @bus: bus to get legacy memory base address for 6151da177e4SLinus Torvalds * 6161da177e4SLinus Torvalds * Find the base of legacy memory for @bus. This is typically the first 6171da177e4SLinus Torvalds * megabyte of bus address space for @bus or is simply 0 on platforms whose 6181da177e4SLinus Torvalds * chipsets support legacy I/O and memory routing. Returns the base address 6191da177e4SLinus Torvalds * or an error pointer if an error occurred. 6201da177e4SLinus Torvalds * 6211da177e4SLinus Torvalds * This is the ia64 generic version of this routine. Other platforms 6221da177e4SLinus Torvalds * are free to override it with a machine vector. 6231da177e4SLinus Torvalds */ 6241da177e4SLinus Torvalds char *ia64_pci_get_legacy_mem(struct pci_bus *bus) 6251da177e4SLinus Torvalds { 6261da177e4SLinus Torvalds return (char *)__IA64_UNCACHED_OFFSET; 6271da177e4SLinus Torvalds } 6281da177e4SLinus Torvalds 6291da177e4SLinus Torvalds /** 6301da177e4SLinus Torvalds * pci_mmap_legacy_page_range - map legacy memory space to userland 6311da177e4SLinus Torvalds * @bus: bus whose legacy space we're mapping 6321da177e4SLinus Torvalds * @vma: vma passed in by mmap 6331da177e4SLinus Torvalds * 6341da177e4SLinus Torvalds * Map legacy memory space for this device back to userspace using a machine 6351da177e4SLinus Torvalds * vector to get the base address. 6361da177e4SLinus Torvalds */ 6371da177e4SLinus Torvalds int 6381da177e4SLinus Torvalds pci_mmap_legacy_page_range(struct pci_bus *bus, struct vm_area_struct *vma) 6391da177e4SLinus Torvalds { 6401da177e4SLinus Torvalds char *addr; 6411da177e4SLinus Torvalds 6421da177e4SLinus Torvalds addr = pci_get_legacy_mem(bus); 6431da177e4SLinus Torvalds if (IS_ERR(addr)) 6441da177e4SLinus Torvalds return PTR_ERR(addr); 6451da177e4SLinus Torvalds 6461da177e4SLinus Torvalds vma->vm_pgoff += (unsigned long)addr >> PAGE_SHIFT; 6471da177e4SLinus Torvalds vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 6481da177e4SLinus Torvalds vma->vm_flags |= (VM_SHM | VM_RESERVED | VM_IO); 6491da177e4SLinus Torvalds 6501da177e4SLinus Torvalds if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, 6511da177e4SLinus Torvalds vma->vm_end - vma->vm_start, vma->vm_page_prot)) 6521da177e4SLinus Torvalds return -EAGAIN; 6531da177e4SLinus Torvalds 6541da177e4SLinus Torvalds return 0; 6551da177e4SLinus Torvalds } 6561da177e4SLinus Torvalds 6571da177e4SLinus Torvalds /** 6581da177e4SLinus Torvalds * ia64_pci_legacy_read - read from legacy I/O space 6591da177e4SLinus Torvalds * @bus: bus to read 6601da177e4SLinus Torvalds * @port: legacy port value 6611da177e4SLinus Torvalds * @val: caller allocated storage for returned value 6621da177e4SLinus Torvalds * @size: number of bytes to read 6631da177e4SLinus Torvalds * 6641da177e4SLinus Torvalds * Simply reads @size bytes from @port and puts the result in @val. 6651da177e4SLinus Torvalds * 6661da177e4SLinus Torvalds * Again, this (and the write routine) are generic versions that can be 6671da177e4SLinus Torvalds * overridden by the platform. This is necessary on platforms that don't 6681da177e4SLinus Torvalds * support legacy I/O routing or that hard fail on legacy I/O timeouts. 6691da177e4SLinus Torvalds */ 6701da177e4SLinus Torvalds int ia64_pci_legacy_read(struct pci_bus *bus, u16 port, u32 *val, u8 size) 6711da177e4SLinus Torvalds { 6721da177e4SLinus Torvalds int ret = size; 6731da177e4SLinus Torvalds 6741da177e4SLinus Torvalds switch (size) { 6751da177e4SLinus Torvalds case 1: 6761da177e4SLinus Torvalds *val = inb(port); 6771da177e4SLinus Torvalds break; 6781da177e4SLinus Torvalds case 2: 6791da177e4SLinus Torvalds *val = inw(port); 6801da177e4SLinus Torvalds break; 6811da177e4SLinus Torvalds case 4: 6821da177e4SLinus Torvalds *val = inl(port); 6831da177e4SLinus Torvalds break; 6841da177e4SLinus Torvalds default: 6851da177e4SLinus Torvalds ret = -EINVAL; 6861da177e4SLinus Torvalds break; 6871da177e4SLinus Torvalds } 6881da177e4SLinus Torvalds 6891da177e4SLinus Torvalds return ret; 6901da177e4SLinus Torvalds } 6911da177e4SLinus Torvalds 6921da177e4SLinus Torvalds /** 6931da177e4SLinus Torvalds * ia64_pci_legacy_write - perform a legacy I/O write 6941da177e4SLinus Torvalds * @bus: bus pointer 6951da177e4SLinus Torvalds * @port: port to write 6961da177e4SLinus Torvalds * @val: value to write 6971da177e4SLinus Torvalds * @size: number of bytes to write from @val 6981da177e4SLinus Torvalds * 6991da177e4SLinus Torvalds * Simply writes @size bytes of @val to @port. 7001da177e4SLinus Torvalds */ 7011da177e4SLinus Torvalds int ia64_pci_legacy_write(struct pci_dev *bus, u16 port, u32 val, u8 size) 7021da177e4SLinus Torvalds { 7031da177e4SLinus Torvalds int ret = 0; 7041da177e4SLinus Torvalds 7051da177e4SLinus Torvalds switch (size) { 7061da177e4SLinus Torvalds case 1: 7071da177e4SLinus Torvalds outb(val, port); 7081da177e4SLinus Torvalds break; 7091da177e4SLinus Torvalds case 2: 7101da177e4SLinus Torvalds outw(val, port); 7111da177e4SLinus Torvalds break; 7121da177e4SLinus Torvalds case 4: 7131da177e4SLinus Torvalds outl(val, port); 7141da177e4SLinus Torvalds break; 7151da177e4SLinus Torvalds default: 7161da177e4SLinus Torvalds ret = -EINVAL; 7171da177e4SLinus Torvalds break; 7181da177e4SLinus Torvalds } 7191da177e4SLinus Torvalds 7201da177e4SLinus Torvalds return ret; 7211da177e4SLinus Torvalds } 7221da177e4SLinus Torvalds 7231da177e4SLinus Torvalds /** 7241da177e4SLinus Torvalds * pci_cacheline_size - determine cacheline size for PCI devices 7251da177e4SLinus Torvalds * @dev: void 7261da177e4SLinus Torvalds * 7271da177e4SLinus Torvalds * We want to use the line-size of the outer-most cache. We assume 7281da177e4SLinus Torvalds * that this line-size is the same for all CPUs. 7291da177e4SLinus Torvalds * 7301da177e4SLinus Torvalds * Code mostly taken from arch/ia64/kernel/palinfo.c:cache_info(). 7311da177e4SLinus Torvalds * 7321da177e4SLinus Torvalds * RETURNS: An appropriate -ERRNO error value on eror, or zero for success. 7331da177e4SLinus Torvalds */ 7341da177e4SLinus Torvalds static unsigned long 7351da177e4SLinus Torvalds pci_cacheline_size (void) 7361da177e4SLinus Torvalds { 7371da177e4SLinus Torvalds u64 levels, unique_caches; 7381da177e4SLinus Torvalds s64 status; 7391da177e4SLinus Torvalds pal_cache_config_info_t cci; 7401da177e4SLinus Torvalds static u8 cacheline_size; 7411da177e4SLinus Torvalds 7421da177e4SLinus Torvalds if (cacheline_size) 7431da177e4SLinus Torvalds return cacheline_size; 7441da177e4SLinus Torvalds 7451da177e4SLinus Torvalds status = ia64_pal_cache_summary(&levels, &unique_caches); 7461da177e4SLinus Torvalds if (status != 0) { 7471da177e4SLinus Torvalds printk(KERN_ERR "%s: ia64_pal_cache_summary() failed (status=%ld)\n", 7481da177e4SLinus Torvalds __FUNCTION__, status); 7491da177e4SLinus Torvalds return SMP_CACHE_BYTES; 7501da177e4SLinus Torvalds } 7511da177e4SLinus Torvalds 7521da177e4SLinus Torvalds status = ia64_pal_cache_config_info(levels - 1, /* cache_type (data_or_unified)= */ 2, 7531da177e4SLinus Torvalds &cci); 7541da177e4SLinus Torvalds if (status != 0) { 7551da177e4SLinus Torvalds printk(KERN_ERR "%s: ia64_pal_cache_config_info() failed (status=%ld)\n", 7561da177e4SLinus Torvalds __FUNCTION__, status); 7571da177e4SLinus Torvalds return SMP_CACHE_BYTES; 7581da177e4SLinus Torvalds } 7591da177e4SLinus Torvalds cacheline_size = 1 << cci.pcci_line_size; 7601da177e4SLinus Torvalds return cacheline_size; 7611da177e4SLinus Torvalds } 7621da177e4SLinus Torvalds 7631da177e4SLinus Torvalds /** 7641da177e4SLinus Torvalds * pcibios_prep_mwi - helper function for drivers/pci/pci.c:pci_set_mwi() 7651da177e4SLinus Torvalds * @dev: the PCI device for which MWI is enabled 7661da177e4SLinus Torvalds * 7671da177e4SLinus Torvalds * For ia64, we can get the cacheline sizes from PAL. 7681da177e4SLinus Torvalds * 7691da177e4SLinus Torvalds * RETURNS: An appropriate -ERRNO error value on eror, or zero for success. 7701da177e4SLinus Torvalds */ 7711da177e4SLinus Torvalds int 7721da177e4SLinus Torvalds pcibios_prep_mwi (struct pci_dev *dev) 7731da177e4SLinus Torvalds { 7741da177e4SLinus Torvalds unsigned long desired_linesize, current_linesize; 7751da177e4SLinus Torvalds int rc = 0; 7761da177e4SLinus Torvalds u8 pci_linesize; 7771da177e4SLinus Torvalds 7781da177e4SLinus Torvalds desired_linesize = pci_cacheline_size(); 7791da177e4SLinus Torvalds 7801da177e4SLinus Torvalds pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &pci_linesize); 7811da177e4SLinus Torvalds current_linesize = 4 * pci_linesize; 7821da177e4SLinus Torvalds if (desired_linesize != current_linesize) { 7831da177e4SLinus Torvalds printk(KERN_WARNING "PCI: slot %s has incorrect PCI cache line size of %lu bytes,", 7841da177e4SLinus Torvalds pci_name(dev), current_linesize); 7851da177e4SLinus Torvalds if (current_linesize > desired_linesize) { 7861da177e4SLinus Torvalds printk(" expected %lu bytes instead\n", desired_linesize); 7871da177e4SLinus Torvalds rc = -EINVAL; 7881da177e4SLinus Torvalds } else { 7891da177e4SLinus Torvalds printk(" correcting to %lu\n", desired_linesize); 7901da177e4SLinus Torvalds pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, desired_linesize / 4); 7911da177e4SLinus Torvalds } 7921da177e4SLinus Torvalds } 7931da177e4SLinus Torvalds return rc; 7941da177e4SLinus Torvalds } 7951da177e4SLinus Torvalds 7961da177e4SLinus Torvalds int pci_vector_resources(int last, int nr_released) 7971da177e4SLinus Torvalds { 7981da177e4SLinus Torvalds int count = nr_released; 7991da177e4SLinus Torvalds 8001da177e4SLinus Torvalds count += (IA64_LAST_DEVICE_VECTOR - last); 8011da177e4SLinus Torvalds 8021da177e4SLinus Torvalds return count; 8031da177e4SLinus Torvalds } 804