2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* pci.c - Low-Level PCI Access in IA-64
|
|
|
|
*
|
|
|
|
* Derived from bios32.c of i386 tree.
|
|
|
|
*
|
|
|
|
* (c) Copyright 2002, 2005 Hewlett-Packard Development Company, L.P.
|
|
|
|
* David Mosberger-Tang <davidm@hpl.hp.com>
|
|
|
|
* Bjorn Helgaas <bjorn.helgaas@hp.com>
|
|
|
|
* Copyright (C) 2004 Silicon Graphics, Inc.
|
|
|
|
*
|
|
|
|
* Note: Above list of copyright holders is incomplete...
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/acpi.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/pci.h>
|
2013-04-12 13:44:22 +08:00
|
|
|
#include <linux/pci-acpi.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/spinlock.h>
|
2008-11-25 06:47:17 +08:00
|
|
|
#include <linux/bootmem.h>
|
2011-08-01 06:33:21 +08:00
|
|
|
#include <linux/export.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/machvec.h>
|
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/sal.h>
|
|
|
|
#include <asm/smp.h>
|
|
|
|
#include <asm/irq.h>
|
|
|
|
#include <asm/hw_irq.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Low-level SAL-based PCI configuration access functions. Note that SAL
|
|
|
|
* calls are already serialized (via sal_lock), so we don't need another
|
|
|
|
* synchronization mechanism here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define PCI_SAL_ADDRESS(seg, bus, devfn, reg) \
|
|
|
|
(((u64) seg << 24) | (bus << 16) | (devfn << 8) | (reg))
|
|
|
|
|
|
|
|
/* SAL 3.2 adds support for extended config space. */
|
|
|
|
|
|
|
|
#define PCI_SAL_EXT_ADDRESS(seg, bus, devfn, reg) \
|
|
|
|
(((u64) seg << 28) | (bus << 20) | (devfn << 12) | (reg))
|
|
|
|
|
2008-02-10 22:45:28 +08:00
|
|
|
int raw_pci_read(unsigned int seg, unsigned int bus, unsigned int devfn,
|
2005-04-17 06:20:36 +08:00
|
|
|
int reg, int len, u32 *value)
|
|
|
|
{
|
|
|
|
u64 addr, data = 0;
|
|
|
|
int mode, result;
|
|
|
|
|
|
|
|
if (!value || (seg > 65535) || (bus > 255) || (devfn > 255) || (reg > 4095))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if ((seg | reg) <= 255) {
|
|
|
|
addr = PCI_SAL_ADDRESS(seg, bus, devfn, reg);
|
|
|
|
mode = 0;
|
2009-10-12 22:24:30 +08:00
|
|
|
} else if (sal_revision >= SAL_VERSION_CODE(3,2)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
addr = PCI_SAL_EXT_ADDRESS(seg, bus, devfn, reg);
|
|
|
|
mode = 1;
|
2009-10-12 22:24:30 +08:00
|
|
|
} else {
|
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-10-12 22:24:30 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
result = ia64_sal_pci_config_read(addr, mode, len, &data);
|
|
|
|
if (result != 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
*value = (u32) data;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-10 22:45:28 +08:00
|
|
|
int raw_pci_write(unsigned int seg, unsigned int bus, unsigned int devfn,
|
2005-04-17 06:20:36 +08:00
|
|
|
int reg, int len, u32 value)
|
|
|
|
{
|
|
|
|
u64 addr;
|
|
|
|
int mode, result;
|
|
|
|
|
|
|
|
if ((seg > 65535) || (bus > 255) || (devfn > 255) || (reg > 4095))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if ((seg | reg) <= 255) {
|
|
|
|
addr = PCI_SAL_ADDRESS(seg, bus, devfn, reg);
|
|
|
|
mode = 0;
|
2009-10-12 22:24:30 +08:00
|
|
|
} else if (sal_revision >= SAL_VERSION_CODE(3,2)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
addr = PCI_SAL_EXT_ADDRESS(seg, bus, devfn, reg);
|
|
|
|
mode = 1;
|
2009-10-12 22:24:30 +08:00
|
|
|
} else {
|
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
result = ia64_sal_pci_config_write(addr, mode, len, value);
|
|
|
|
if (result != 0)
|
|
|
|
return -EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-10 22:45:28 +08:00
|
|
|
static int pci_read(struct pci_bus *bus, unsigned int devfn, int where,
|
|
|
|
int size, u32 *value)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-02-10 22:45:28 +08:00
|
|
|
return raw_pci_read(pci_domain_nr(bus), bus->number,
|
2005-04-17 06:20:36 +08:00
|
|
|
devfn, where, size, value);
|
|
|
|
}
|
|
|
|
|
2008-02-10 22:45:28 +08:00
|
|
|
static int pci_write(struct pci_bus *bus, unsigned int devfn, int where,
|
|
|
|
int size, u32 value)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-02-10 22:45:28 +08:00
|
|
|
return raw_pci_write(pci_domain_nr(bus), bus->number,
|
2005-04-17 06:20:36 +08:00
|
|
|
devfn, where, size, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct pci_ops pci_root_ops = {
|
|
|
|
.read = pci_read,
|
|
|
|
.write = pci_write,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Called by ACPI when it finds a new root bus. */
|
|
|
|
|
2012-12-22 06:05:13 +08:00
|
|
|
static struct pci_controller *alloc_pci_controller(int seg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct pci_controller *controller;
|
|
|
|
|
2006-12-05 06:58:35 +08:00
|
|
|
controller = kzalloc(sizeof(*controller), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!controller)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
controller->segment = seg;
|
|
|
|
return controller;
|
|
|
|
}
|
|
|
|
|
2005-11-08 06:13:59 +08:00
|
|
|
struct pci_root_info {
|
2009-10-07 05:33:54 +08:00
|
|
|
struct acpi_device *bridge;
|
2005-11-08 06:13:59 +08:00
|
|
|
struct pci_controller *controller;
|
2011-10-29 06:26:31 +08:00
|
|
|
struct list_head resources;
|
2013-06-06 15:34:48 +08:00
|
|
|
struct resource *res;
|
|
|
|
resource_size_t *res_offset;
|
|
|
|
unsigned int res_num;
|
2013-06-06 15:34:50 +08:00
|
|
|
struct list_head io_resources;
|
2005-11-08 06:13:59 +08:00
|
|
|
char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
new_space (u64 phys_base, int sparse)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-08 06:13:59 +08:00
|
|
|
u64 mmio_base;
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
|
|
|
|
2005-11-08 06:13:59 +08:00
|
|
|
if (phys_base == 0)
|
|
|
|
return 0; /* legacy I/O port space */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-11-08 06:13:59 +08:00
|
|
|
mmio_base = (u64) ioremap(phys_base, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < num_io_spaces; i++)
|
2005-11-08 06:13:59 +08:00
|
|
|
if (io_space[i].mmio_base == mmio_base &&
|
2005-04-17 06:20:36 +08:00
|
|
|
io_space[i].sparse == sparse)
|
2005-11-08 06:13:59 +08:00
|
|
|
return i;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (num_io_spaces == MAX_IO_SPACES) {
|
2013-06-06 15:34:53 +08:00
|
|
|
pr_err("PCI: Too many IO port spaces "
|
2005-11-08 06:13:59 +08:00
|
|
|
"(MAX_IO_SPACES=%lu)\n", MAX_IO_SPACES);
|
2005-04-17 06:20:36 +08:00
|
|
|
return ~0;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = num_io_spaces++;
|
2005-11-08 06:13:59 +08:00
|
|
|
io_space[i].mmio_base = mmio_base;
|
2005-04-17 06:20:36 +08:00
|
|
|
io_space[i].sparse = sparse;
|
|
|
|
|
2005-11-08 06:13:59 +08:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2012-12-22 06:05:13 +08:00
|
|
|
static u64 add_io_space(struct pci_root_info *info,
|
|
|
|
struct acpi_resource_address64 *addr)
|
2005-11-08 06:13:59 +08:00
|
|
|
{
|
2013-06-06 15:34:50 +08:00
|
|
|
struct iospace_resource *iospace;
|
2005-11-08 06:13:59 +08:00
|
|
|
struct resource *resource;
|
|
|
|
char *name;
|
2009-05-23 04:49:49 +08:00
|
|
|
unsigned long base, min, max, base_port;
|
2005-11-08 06:13:59 +08:00
|
|
|
unsigned int sparse = 0, space_nr, len;
|
|
|
|
|
2013-06-06 15:34:50 +08:00
|
|
|
len = strlen(info->name) + 32;
|
|
|
|
iospace = kzalloc(sizeof(*iospace) + len, GFP_KERNEL);
|
|
|
|
if (!iospace) {
|
2013-06-06 15:34:53 +08:00
|
|
|
dev_err(&info->bridge->dev,
|
|
|
|
"PCI: No memory for %s I/O port space\n",
|
|
|
|
info->name);
|
2005-11-08 06:13:59 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2013-06-06 15:34:50 +08:00
|
|
|
name = (char *)(iospace + 1);
|
2005-11-08 06:13:59 +08:00
|
|
|
|
[ACPI] ACPICA 20050930
Completed a major overhaul of the Resource Manager code -
specifically, optimizations in the area of the AML/internal
resource conversion code. The code has been optimized to
simplify and eliminate duplicated code, CPU stack use has
been decreased by optimizing function parameters and local
variables, and naming conventions across the manager have
been standardized for clarity and ease of maintenance (this
includes function, parameter, variable, and struct/typedef
names.)
All Resource Manager dispatch and information tables have
been moved to a single location for clarity and ease of
maintenance. One new file was created, named "rsinfo.c".
The ACPI return macros (return_ACPI_STATUS, etc.) have
been modified to guarantee that the argument is
not evaluated twice, making them less prone to macro
side-effects. However, since there exists the possibility
of additional stack use if a particular compiler cannot
optimize them (such as in the debug generation case),
the original macros are optionally available. Note that
some invocations of the return_VALUE macro may now cause
size mismatch warnings; the return_UINT8 and return_UINT32
macros are provided to eliminate these. (From Randy Dunlap)
Implemented a new mechanism to enable debug tracing for
individual control methods. A new external interface,
acpi_debug_trace(), is provided to enable this mechanism. The
intent is to allow the host OS to easily enable and disable
tracing for problematic control methods. This interface
can be easily exposed to a user or debugger interface if
desired. See the file psxface.c for details.
acpi_ut_callocate() will now return a valid pointer if a
length of zero is specified - a length of one is used
and a warning is issued. This matches the behavior of
acpi_ut_allocate().
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
2005-10-01 07:03:00 +08:00
|
|
|
min = addr->minimum;
|
2005-11-08 06:13:59 +08:00
|
|
|
max = min + addr->address_length - 1;
|
2005-10-21 12:00:00 +08:00
|
|
|
if (addr->info.io.translation_type == ACPI_SPARSE_TRANSLATION)
|
2005-11-08 06:13:59 +08:00
|
|
|
sparse = 1;
|
|
|
|
|
[ACPI] ACPICA 20050930
Completed a major overhaul of the Resource Manager code -
specifically, optimizations in the area of the AML/internal
resource conversion code. The code has been optimized to
simplify and eliminate duplicated code, CPU stack use has
been decreased by optimizing function parameters and local
variables, and naming conventions across the manager have
been standardized for clarity and ease of maintenance (this
includes function, parameter, variable, and struct/typedef
names.)
All Resource Manager dispatch and information tables have
been moved to a single location for clarity and ease of
maintenance. One new file was created, named "rsinfo.c".
The ACPI return macros (return_ACPI_STATUS, etc.) have
been modified to guarantee that the argument is
not evaluated twice, making them less prone to macro
side-effects. However, since there exists the possibility
of additional stack use if a particular compiler cannot
optimize them (such as in the debug generation case),
the original macros are optionally available. Note that
some invocations of the return_VALUE macro may now cause
size mismatch warnings; the return_UINT8 and return_UINT32
macros are provided to eliminate these. (From Randy Dunlap)
Implemented a new mechanism to enable debug tracing for
individual control methods. A new external interface,
acpi_debug_trace(), is provided to enable this mechanism. The
intent is to allow the host OS to easily enable and disable
tracing for problematic control methods. This interface
can be easily exposed to a user or debugger interface if
desired. See the file psxface.c for details.
acpi_ut_callocate() will now return a valid pointer if a
length of zero is specified - a length of one is used
and a warning is issued. This matches the behavior of
acpi_ut_allocate().
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
2005-10-01 07:03:00 +08:00
|
|
|
space_nr = new_space(addr->translation_offset, sparse);
|
2005-11-08 06:13:59 +08:00
|
|
|
if (space_nr == ~0)
|
2013-06-06 15:34:50 +08:00
|
|
|
goto free_resource;
|
2005-11-08 06:13:59 +08:00
|
|
|
|
|
|
|
base = __pa(io_space[space_nr].mmio_base);
|
|
|
|
base_port = IO_SPACE_BASE(space_nr);
|
|
|
|
snprintf(name, len, "%s I/O Ports %08lx-%08lx", info->name,
|
|
|
|
base_port + min, base_port + max);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The SDM guarantees the legacy 0-64K space is sparse, but if the
|
|
|
|
* mapping is done by the processor (not the bridge), ACPI may not
|
|
|
|
* mark it as sparse.
|
|
|
|
*/
|
|
|
|
if (space_nr == 0)
|
|
|
|
sparse = 1;
|
|
|
|
|
2013-06-06 15:34:50 +08:00
|
|
|
resource = &iospace->res;
|
2005-11-08 06:13:59 +08:00
|
|
|
resource->name = name;
|
|
|
|
resource->flags = IORESOURCE_MEM;
|
|
|
|
resource->start = base + (sparse ? IO_SPACE_SPARSE_ENCODING(min) : min);
|
|
|
|
resource->end = base + (sparse ? IO_SPACE_SPARSE_ENCODING(max) : max);
|
2013-06-06 15:34:50 +08:00
|
|
|
if (insert_resource(&iomem_resource, resource)) {
|
|
|
|
dev_err(&info->bridge->dev,
|
|
|
|
"can't allocate host bridge io space resource %pR\n",
|
|
|
|
resource);
|
|
|
|
goto free_resource;
|
|
|
|
}
|
2005-11-08 06:13:59 +08:00
|
|
|
|
2013-06-06 15:34:50 +08:00
|
|
|
list_add_tail(&iospace->list, &info->io_resources);
|
2005-11-08 06:13:59 +08:00
|
|
|
return base_port;
|
|
|
|
|
|
|
|
free_resource:
|
2013-06-06 15:34:50 +08:00
|
|
|
kfree(iospace);
|
2005-11-08 06:13:59 +08:00
|
|
|
out:
|
|
|
|
return ~0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-12-22 06:05:13 +08:00
|
|
|
static acpi_status resource_to_window(struct acpi_resource *resource,
|
|
|
|
struct acpi_resource_address64 *addr)
|
2005-09-24 01:39:07 +08:00
|
|
|
{
|
|
|
|
acpi_status status;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We're only interested in _CRS descriptors that are
|
|
|
|
* - address space descriptors for memory or I/O space
|
|
|
|
* - non-zero size
|
|
|
|
* - producers, i.e., the address space is routed downstream,
|
|
|
|
* not consumed by the bridge itself
|
|
|
|
*/
|
|
|
|
status = acpi_resource_to_address64(resource, addr);
|
|
|
|
if (ACPI_SUCCESS(status) &&
|
|
|
|
(addr->resource_type == ACPI_MEMORY_RANGE ||
|
|
|
|
addr->resource_type == ACPI_IO_RANGE) &&
|
|
|
|
addr->address_length &&
|
|
|
|
addr->producer_consumer == ACPI_PRODUCER)
|
|
|
|
return AE_OK;
|
|
|
|
|
|
|
|
return AE_ERROR;
|
|
|
|
}
|
|
|
|
|
2012-12-22 06:05:13 +08:00
|
|
|
static acpi_status count_window(struct acpi_resource *resource, void *data)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned int *windows = (unsigned int *) data;
|
|
|
|
struct acpi_resource_address64 addr;
|
|
|
|
acpi_status status;
|
|
|
|
|
2005-09-24 01:39:07 +08:00
|
|
|
status = resource_to_window(resource, &addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ACPI_SUCCESS(status))
|
2005-09-24 01:39:07 +08:00
|
|
|
(*windows)++;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return AE_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-22 06:05:13 +08:00
|
|
|
static acpi_status add_window(struct acpi_resource *res, void *data)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct pci_root_info *info = data;
|
2013-06-06 15:34:48 +08:00
|
|
|
struct resource *resource;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct acpi_resource_address64 addr;
|
|
|
|
acpi_status status;
|
|
|
|
unsigned long flags, offset = 0;
|
|
|
|
struct resource *root;
|
|
|
|
|
2005-09-24 01:39:07 +08:00
|
|
|
/* Return AE_OK for non-window resources to keep scanning for more */
|
|
|
|
status = resource_to_window(res, &addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!ACPI_SUCCESS(status))
|
|
|
|
return AE_OK;
|
|
|
|
|
|
|
|
if (addr.resource_type == ACPI_MEMORY_RANGE) {
|
|
|
|
flags = IORESOURCE_MEM;
|
|
|
|
root = &iomem_resource;
|
[ACPI] ACPICA 20050930
Completed a major overhaul of the Resource Manager code -
specifically, optimizations in the area of the AML/internal
resource conversion code. The code has been optimized to
simplify and eliminate duplicated code, CPU stack use has
been decreased by optimizing function parameters and local
variables, and naming conventions across the manager have
been standardized for clarity and ease of maintenance (this
includes function, parameter, variable, and struct/typedef
names.)
All Resource Manager dispatch and information tables have
been moved to a single location for clarity and ease of
maintenance. One new file was created, named "rsinfo.c".
The ACPI return macros (return_ACPI_STATUS, etc.) have
been modified to guarantee that the argument is
not evaluated twice, making them less prone to macro
side-effects. However, since there exists the possibility
of additional stack use if a particular compiler cannot
optimize them (such as in the debug generation case),
the original macros are optionally available. Note that
some invocations of the return_VALUE macro may now cause
size mismatch warnings; the return_UINT8 and return_UINT32
macros are provided to eliminate these. (From Randy Dunlap)
Implemented a new mechanism to enable debug tracing for
individual control methods. A new external interface,
acpi_debug_trace(), is provided to enable this mechanism. The
intent is to allow the host OS to easily enable and disable
tracing for problematic control methods. This interface
can be easily exposed to a user or debugger interface if
desired. See the file psxface.c for details.
acpi_ut_callocate() will now return a valid pointer if a
length of zero is specified - a length of one is used
and a warning is issued. This matches the behavior of
acpi_ut_allocate().
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
2005-10-01 07:03:00 +08:00
|
|
|
offset = addr.translation_offset;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else if (addr.resource_type == ACPI_IO_RANGE) {
|
|
|
|
flags = IORESOURCE_IO;
|
|
|
|
root = &ioport_resource;
|
2005-11-08 06:13:59 +08:00
|
|
|
offset = add_io_space(info, &addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (offset == ~0)
|
|
|
|
return AE_OK;
|
|
|
|
} else
|
|
|
|
return AE_OK;
|
|
|
|
|
2013-06-06 15:34:48 +08:00
|
|
|
resource = &info->res[info->res_num];
|
|
|
|
resource->name = info->name;
|
|
|
|
resource->flags = flags;
|
|
|
|
resource->start = addr.minimum + offset;
|
|
|
|
resource->end = resource->start + addr.address_length - 1;
|
|
|
|
info->res_offset[info->res_num] = offset;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-06-06 15:34:48 +08:00
|
|
|
if (insert_resource(root, resource)) {
|
2009-10-28 03:26:47 +08:00
|
|
|
dev_err(&info->bridge->dev,
|
|
|
|
"can't allocate host bridge window %pR\n",
|
2013-06-06 15:34:48 +08:00
|
|
|
resource);
|
2009-10-07 05:33:54 +08:00
|
|
|
} else {
|
|
|
|
if (offset)
|
2009-10-28 03:26:47 +08:00
|
|
|
dev_info(&info->bridge->dev, "host bridge window %pR "
|
2009-10-07 05:33:54 +08:00
|
|
|
"(PCI address [%#llx-%#llx])\n",
|
2013-06-06 15:34:48 +08:00
|
|
|
resource,
|
|
|
|
resource->start - offset,
|
|
|
|
resource->end - offset);
|
2009-10-07 05:33:54 +08:00
|
|
|
else
|
|
|
|
dev_info(&info->bridge->dev,
|
2013-06-06 15:34:48 +08:00
|
|
|
"host bridge window %pR\n", resource);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2011-10-29 06:26:31 +08:00
|
|
|
/* HP's firmware has a hack to work around a Windows bug.
|
|
|
|
* Ignore these tiny memory ranges */
|
2013-06-06 15:34:48 +08:00
|
|
|
if (!((resource->flags & IORESOURCE_MEM) &&
|
|
|
|
(resource->end - resource->start < 16)))
|
|
|
|
pci_add_resource_offset(&info->resources, resource,
|
|
|
|
info->res_offset[info->res_num]);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-06-06 15:34:48 +08:00
|
|
|
info->res_num++;
|
2011-10-29 06:26:31 +08:00
|
|
|
return AE_OK;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2013-06-06 15:34:50 +08:00
|
|
|
static void free_pci_root_info_res(struct pci_root_info *info)
|
|
|
|
{
|
|
|
|
struct iospace_resource *iospace, *tmp;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(iospace, tmp, &info->io_resources, list)
|
|
|
|
kfree(iospace);
|
|
|
|
|
|
|
|
kfree(info->name);
|
|
|
|
kfree(info->res);
|
|
|
|
info->res = NULL;
|
|
|
|
kfree(info->res_offset);
|
|
|
|
info->res_offset = NULL;
|
|
|
|
info->res_num = 0;
|
|
|
|
kfree(info->controller);
|
|
|
|
info->controller = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __release_pci_root_info(struct pci_root_info *info)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct resource *res;
|
|
|
|
struct iospace_resource *iospace;
|
|
|
|
|
|
|
|
list_for_each_entry(iospace, &info->io_resources, list)
|
|
|
|
release_resource(&iospace->res);
|
|
|
|
|
|
|
|
for (i = 0; i < info->res_num; i++) {
|
|
|
|
res = &info->res[i];
|
|
|
|
|
|
|
|
if (!res->parent)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!(res->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
release_resource(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
free_pci_root_info_res(info);
|
|
|
|
kfree(info);
|
|
|
|
}
|
|
|
|
|
2013-06-06 15:34:51 +08:00
|
|
|
static void release_pci_root_info(struct pci_host_bridge *bridge)
|
|
|
|
{
|
|
|
|
struct pci_root_info *info = bridge->release_data;
|
|
|
|
|
|
|
|
__release_pci_root_info(info);
|
|
|
|
}
|
|
|
|
|
2013-06-06 15:34:52 +08:00
|
|
|
static int
|
|
|
|
probe_pci_root_info(struct pci_root_info *info, struct acpi_device *device,
|
|
|
|
int busnum, int domain)
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
name = kmalloc(16, GFP_KERNEL);
|
|
|
|
if (!name)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
sprintf(name, "PCI Bus %04x:%02x", domain, busnum);
|
|
|
|
info->bridge = device;
|
|
|
|
info->name = name;
|
|
|
|
|
|
|
|
acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_window,
|
|
|
|
&info->res_num);
|
|
|
|
if (info->res_num) {
|
|
|
|
info->res =
|
|
|
|
kzalloc_node(sizeof(*info->res) * info->res_num,
|
|
|
|
GFP_KERNEL, info->controller->node);
|
|
|
|
if (!info->res) {
|
|
|
|
kfree(name);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->res_offset =
|
|
|
|
kzalloc_node(sizeof(*info->res_offset) * info->res_num,
|
|
|
|
GFP_KERNEL, info->controller->node);
|
|
|
|
if (!info->res_offset) {
|
|
|
|
kfree(name);
|
|
|
|
kfree(info->res);
|
|
|
|
info->res = NULL;
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->res_num = 0;
|
|
|
|
acpi_walk_resources(device->handle, METHOD_NAME__CRS,
|
|
|
|
add_window, info);
|
|
|
|
} else
|
|
|
|
kfree(name);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-22 06:05:13 +08:00
|
|
|
struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-03-12 03:20:11 +08:00
|
|
|
struct acpi_device *device = root->device;
|
|
|
|
int domain = root->segment;
|
|
|
|
int bus = root->secondary.start;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct pci_controller *controller;
|
2013-06-06 15:34:49 +08:00
|
|
|
struct pci_root_info *info = NULL;
|
|
|
|
int busnum = root->secondary.start;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct pci_bus *pbus;
|
2014-01-25 06:28:42 +08:00
|
|
|
int ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
controller = alloc_pci_controller(domain);
|
|
|
|
if (!controller)
|
2013-06-06 15:34:52 +08:00
|
|
|
return NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
ACPI / driver core: Store an ACPI device pointer in struct acpi_dev_node
Modify struct acpi_dev_node to contain a pointer to struct acpi_device
associated with the given device object (that is, its ACPI companion
device) instead of an ACPI handle corresponding to it. Introduce two
new macros for manipulating that pointer in a CONFIG_ACPI-safe way,
ACPI_COMPANION() and ACPI_COMPANION_SET(), and rework the
ACPI_HANDLE() macro to take the above changes into account.
Drop the ACPI_HANDLE_SET() macro entirely and rework its users to
use ACPI_COMPANION_SET() instead. For some of them who used to
pass the result of acpi_get_child() directly to ACPI_HANDLE_SET()
introduce a helper routine acpi_preset_companion() doing an
equivalent thing.
The main motivation for doing this is that there are things
represented by struct acpi_device objects that don't have valid
ACPI handles (so called fixed ACPI hardware features, such as
power and sleep buttons) and we would like to create platform
device objects for them and "glue" them to their ACPI companions
in the usual way (which currently is impossible due to the
lack of valid ACPI handles). However, there are more reasons
why it may be useful.
First, struct acpi_device pointers allow of much better type checking
than void pointers which are ACPI handles, so it should be more
difficult to write buggy code using modified struct acpi_dev_node
and the new macros. Second, the change should help to reduce (over
time) the number of places in which the result of ACPI_HANDLE() is
passed to acpi_bus_get_device() in order to obtain a pointer to the
struct acpi_device associated with the given "physical" device,
because now that pointer is returned by ACPI_COMPANION() directly.
Finally, the change should make it easier to write generic code that
will build both for CONFIG_ACPI set and unset without adding explicit
compiler directives to it.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com> # on Haswell
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Aaron Lu <aaron.lu@intel.com> # for ATA and SDIO part
2013-11-12 05:41:56 +08:00
|
|
|
controller->companion = device;
|
2014-01-25 06:28:42 +08:00
|
|
|
controller->node = acpi_get_node(device->handle);
|
2005-07-08 07:59:00 +08:00
|
|
|
|
2013-06-06 15:34:49 +08:00
|
|
|
info = kzalloc(sizeof(*info), GFP_KERNEL);
|
|
|
|
if (!info) {
|
2013-06-06 15:34:53 +08:00
|
|
|
dev_err(&device->dev,
|
2013-06-06 15:34:49 +08:00
|
|
|
"pci_bus %04x:%02x: ignored (out of memory)\n",
|
2013-06-06 15:34:52 +08:00
|
|
|
domain, busnum);
|
|
|
|
kfree(controller);
|
|
|
|
return NULL;
|
2013-06-06 15:34:49 +08:00
|
|
|
}
|
|
|
|
|
2013-06-06 15:34:52 +08:00
|
|
|
info->controller = controller;
|
2013-06-06 15:34:50 +08:00
|
|
|
INIT_LIST_HEAD(&info->io_resources);
|
2013-06-06 15:34:49 +08:00
|
|
|
INIT_LIST_HEAD(&info->resources);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-06-06 15:34:52 +08:00
|
|
|
ret = probe_pci_root_info(info, device, busnum, domain);
|
|
|
|
if (ret) {
|
|
|
|
kfree(info->controller);
|
|
|
|
kfree(info);
|
|
|
|
return NULL;
|
2008-08-16 06:37:48 +08:00
|
|
|
}
|
2013-06-06 15:34:52 +08:00
|
|
|
/* insert busn resource at first */
|
|
|
|
pci_add_resource(&info->resources, &root->secondary);
|
2008-04-16 05:34:49 +08:00
|
|
|
/*
|
|
|
|
* See arch/x86/pci/acpi.c.
|
|
|
|
* The desired pci bus might already be scanned in a quirk. We
|
|
|
|
* should handle the case here, but it appears that IA64 hasn't
|
|
|
|
* such quirk. So we just ignore the case now.
|
|
|
|
*/
|
2011-10-29 06:26:31 +08:00
|
|
|
pbus = pci_create_root_bus(NULL, bus, &pci_root_ops, controller,
|
2013-06-06 15:34:49 +08:00
|
|
|
&info->resources);
|
2011-10-29 06:26:31 +08:00
|
|
|
if (!pbus) {
|
2013-06-06 15:34:49 +08:00
|
|
|
pci_free_resource_list(&info->resources);
|
2013-06-06 15:34:50 +08:00
|
|
|
__release_pci_root_info(info);
|
2011-10-29 06:26:26 +08:00
|
|
|
return NULL;
|
2011-10-29 06:26:31 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-06-06 15:34:51 +08:00
|
|
|
pci_set_host_bridge_release(to_pci_host_bridge(pbus->bridge),
|
|
|
|
release_pci_root_info, info);
|
2012-05-18 09:51:12 +08:00
|
|
|
pci_scan_child_bus(pbus);
|
2005-04-17 06:20:36 +08:00
|
|
|
return pbus;
|
|
|
|
}
|
|
|
|
|
ACPI / PCI: Set root bridge ACPI handle in advance
The ACPI handles of PCI root bridges need to be known to
acpi_bind_one(), so that it can create the appropriate
"firmware_node" and "physical_node" files for them, but currently
the way it gets to know those handles is not exactly straightforward
(to put it lightly).
This is how it works, roughly:
1. acpi_bus_scan() finds the handle of a PCI root bridge,
creates a struct acpi_device object for it and passes that
object to acpi_pci_root_add().
2. acpi_pci_root_add() creates a struct acpi_pci_root object,
populates its "device" field with its argument's address
(device->handle is the ACPI handle found in step 1).
3. The struct acpi_pci_root object created in step 2 is passed
to pci_acpi_scan_root() and used to get resources that are
passed to pci_create_root_bus().
4. pci_create_root_bus() creates a struct pci_host_bridge object
and passes its "dev" member to device_register().
5. platform_notify(), which for systems with ACPI is set to
acpi_platform_notify(), is called.
So far, so good. Now it starts to be "interesting".
6. acpi_find_bridge_device() is used to find the ACPI handle of
the given device (which is the PCI root bridge) and executes
acpi_pci_find_root_bridge(), among other things, for the
given device object.
7. acpi_pci_find_root_bridge() uses the name (sic!) of the given
device object to extract the segment and bus numbers of the PCI
root bridge and passes them to acpi_get_pci_rootbridge_handle().
8. acpi_get_pci_rootbridge_handle() browses the list of ACPI PCI
root bridges and finds the one that matches the given segment
and bus numbers. Its handle is then used to initialize the
ACPI handle of the PCI root bridge's device object by
acpi_bind_one(). However, this is *exactly* the ACPI handle we
started with in step 1.
Needless to say, this is quite embarassing, but it may be avoided
thanks to commit f3fd0c8 (ACPI: Allow ACPI handles of devices to be
initialized in advance), which makes it possible to initialize the
ACPI handle of a device before passing it to device_register().
Accordingly, add a new __weak routine, pcibios_root_bridge_prepare(),
defaulting to an empty implementation that can be replaced by the
interested architecutres (x86 and ia64 at the moment) with functions
that will set the root bridge's ACPI handle before its dev member is
passed to device_register(). Make both x86 and ia64 provide such
implementations of pcibios_root_bridge_prepare() and remove
acpi_pci_find_root_bridge() and acpi_get_pci_rootbridge_handle() that
aren't necessary any more.
Included is a fix for breakage on systems with non-ACPI PCI host
bridges from Bjorn Helgaas.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2013-01-10 05:33:37 +08:00
|
|
|
int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge)
|
|
|
|
{
|
|
|
|
struct pci_controller *controller = bridge->bus->sysdata;
|
|
|
|
|
ACPI / driver core: Store an ACPI device pointer in struct acpi_dev_node
Modify struct acpi_dev_node to contain a pointer to struct acpi_device
associated with the given device object (that is, its ACPI companion
device) instead of an ACPI handle corresponding to it. Introduce two
new macros for manipulating that pointer in a CONFIG_ACPI-safe way,
ACPI_COMPANION() and ACPI_COMPANION_SET(), and rework the
ACPI_HANDLE() macro to take the above changes into account.
Drop the ACPI_HANDLE_SET() macro entirely and rework its users to
use ACPI_COMPANION_SET() instead. For some of them who used to
pass the result of acpi_get_child() directly to ACPI_HANDLE_SET()
introduce a helper routine acpi_preset_companion() doing an
equivalent thing.
The main motivation for doing this is that there are things
represented by struct acpi_device objects that don't have valid
ACPI handles (so called fixed ACPI hardware features, such as
power and sleep buttons) and we would like to create platform
device objects for them and "glue" them to their ACPI companions
in the usual way (which currently is impossible due to the
lack of valid ACPI handles). However, there are more reasons
why it may be useful.
First, struct acpi_device pointers allow of much better type checking
than void pointers which are ACPI handles, so it should be more
difficult to write buggy code using modified struct acpi_dev_node
and the new macros. Second, the change should help to reduce (over
time) the number of places in which the result of ACPI_HANDLE() is
passed to acpi_bus_get_device() in order to obtain a pointer to the
struct acpi_device associated with the given "physical" device,
because now that pointer is returned by ACPI_COMPANION() directly.
Finally, the change should make it easier to write generic code that
will build both for CONFIG_ACPI set and unset without adding explicit
compiler directives to it.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com> # on Haswell
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Aaron Lu <aaron.lu@intel.com> # for ATA and SDIO part
2013-11-12 05:41:56 +08:00
|
|
|
ACPI_COMPANION_SET(&bridge->dev, controller->companion);
|
ACPI / PCI: Set root bridge ACPI handle in advance
The ACPI handles of PCI root bridges need to be known to
acpi_bind_one(), so that it can create the appropriate
"firmware_node" and "physical_node" files for them, but currently
the way it gets to know those handles is not exactly straightforward
(to put it lightly).
This is how it works, roughly:
1. acpi_bus_scan() finds the handle of a PCI root bridge,
creates a struct acpi_device object for it and passes that
object to acpi_pci_root_add().
2. acpi_pci_root_add() creates a struct acpi_pci_root object,
populates its "device" field with its argument's address
(device->handle is the ACPI handle found in step 1).
3. The struct acpi_pci_root object created in step 2 is passed
to pci_acpi_scan_root() and used to get resources that are
passed to pci_create_root_bus().
4. pci_create_root_bus() creates a struct pci_host_bridge object
and passes its "dev" member to device_register().
5. platform_notify(), which for systems with ACPI is set to
acpi_platform_notify(), is called.
So far, so good. Now it starts to be "interesting".
6. acpi_find_bridge_device() is used to find the ACPI handle of
the given device (which is the PCI root bridge) and executes
acpi_pci_find_root_bridge(), among other things, for the
given device object.
7. acpi_pci_find_root_bridge() uses the name (sic!) of the given
device object to extract the segment and bus numbers of the PCI
root bridge and passes them to acpi_get_pci_rootbridge_handle().
8. acpi_get_pci_rootbridge_handle() browses the list of ACPI PCI
root bridges and finds the one that matches the given segment
and bus numbers. Its handle is then used to initialize the
ACPI handle of the PCI root bridge's device object by
acpi_bind_one(). However, this is *exactly* the ACPI handle we
started with in step 1.
Needless to say, this is quite embarassing, but it may be avoided
thanks to commit f3fd0c8 (ACPI: Allow ACPI handles of devices to be
initialized in advance), which makes it possible to initialize the
ACPI handle of a device before passing it to device_register().
Accordingly, add a new __weak routine, pcibios_root_bridge_prepare(),
defaulting to an empty implementation that can be replaced by the
interested architecutres (x86 and ia64 at the moment) with functions
that will set the root bridge's ACPI handle before its dev member is
passed to device_register(). Make both x86 and ia64 provide such
implementations of pcibios_root_bridge_prepare() and remove
acpi_pci_find_root_bridge() and acpi_get_pci_rootbridge_handle() that
aren't necessary any more.
Included is a fix for breakage on systems with non-ACPI PCI host
bridges from Bjorn Helgaas.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2013-01-10 05:33:37 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-22 06:05:13 +08:00
|
|
|
static int is_valid_resource(struct pci_dev *dev, int idx)
|
2005-04-28 15:25:46 +08:00
|
|
|
{
|
|
|
|
unsigned int i, type_mask = IORESOURCE_IO | IORESOURCE_MEM;
|
2010-02-24 01:24:31 +08:00
|
|
|
struct resource *devr = &dev->resource[idx], *busr;
|
2005-04-28 15:25:46 +08:00
|
|
|
|
|
|
|
if (!dev->bus)
|
|
|
|
return 0;
|
|
|
|
|
2010-02-24 01:24:31 +08:00
|
|
|
pci_bus_for_each_resource(dev->bus, busr, i) {
|
2005-04-28 15:25:46 +08:00
|
|
|
if (!busr || ((busr->flags ^ devr->flags) & type_mask))
|
|
|
|
continue;
|
|
|
|
if ((devr->start) && (devr->start >= busr->start) &&
|
|
|
|
(devr->end <= busr->end))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-22 06:05:13 +08:00
|
|
|
static void pcibios_fixup_resources(struct pci_dev *dev, int start, int limit)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2006-01-16 12:45:23 +08:00
|
|
|
for (i = start; i < limit; i++) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!dev->resource[i].flags)
|
|
|
|
continue;
|
2005-04-28 15:25:46 +08:00
|
|
|
if ((is_valid_resource(dev, i)))
|
|
|
|
pci_claim_resource(dev, i);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-22 06:05:13 +08:00
|
|
|
void pcibios_fixup_device_resources(struct pci_dev *dev)
|
2006-01-16 12:45:23 +08:00
|
|
|
{
|
|
|
|
pcibios_fixup_resources(dev, 0, PCI_BRIDGE_RESOURCES);
|
|
|
|
}
|
Altix: Add initial ACPI IO support
First phase in introducing ACPI support to SN.
In this phase, when running with an ACPI capable PROM,
the DSDT will define the root busses and all SN nodes
(SGIHUB, SGITIO). An ACPI bus driver will be registered
for the node devices, with the acpi_pci_root_driver being
used for the root busses. An ACPI vendor descriptor is
now used to pass platform specific information for both
nodes and busses, eliminating the need for the current
SAL calls. Also, with ACPI support, SN fixup code is no longer
needed to initiate the PCI bus scans, as the acpi_pci_root_driver
does that.
However, to maintain backward compatibility with non-ACPI capable
PROMs, none of the current 'fixup' code can been deleted, though
much restructuring has been done. For example, the bulk of the code
in io_common.c is relocated code that is now common regardless
of what PROM is running, while io_acpi_init.c and io_init.c contain
routines specific to an ACPI or non ACPI capable PROM respectively.
A new pci bus fixup platform vector has been created to provide
a hook for invoking platform specific bus fixup from pcibios_fixup_bus().
The size of io_space[] has been increased to support systems with
large IO configurations.
Signed-off-by: John Keller <jpk@sgi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2006-10-05 05:49:25 +08:00
|
|
|
EXPORT_SYMBOL_GPL(pcibios_fixup_device_resources);
|
2006-01-16 12:45:23 +08:00
|
|
|
|
2012-12-22 06:05:13 +08:00
|
|
|
static void pcibios_fixup_bridge_resources(struct pci_dev *dev)
|
2006-01-16 12:45:23 +08:00
|
|
|
{
|
|
|
|
pcibios_fixup_resources(dev, PCI_BRIDGE_RESOURCES, PCI_NUM_RESOURCES);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Called after each bus is probed, but before its children are examined.
|
|
|
|
*/
|
2012-12-22 06:05:13 +08:00
|
|
|
void pcibios_fixup_bus(struct pci_bus *b)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct pci_dev *dev;
|
|
|
|
|
2005-04-28 15:25:51 +08:00
|
|
|
if (b->self) {
|
|
|
|
pci_read_bridge_bases(b);
|
2006-01-16 12:45:23 +08:00
|
|
|
pcibios_fixup_bridge_resources(b->self);
|
2005-04-28 15:25:51 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
list_for_each_entry(dev, &b->devices, bus_list)
|
|
|
|
pcibios_fixup_device_resources(dev);
|
Altix: Add initial ACPI IO support
First phase in introducing ACPI support to SN.
In this phase, when running with an ACPI capable PROM,
the DSDT will define the root busses and all SN nodes
(SGIHUB, SGITIO). An ACPI bus driver will be registered
for the node devices, with the acpi_pci_root_driver being
used for the root busses. An ACPI vendor descriptor is
now used to pass platform specific information for both
nodes and busses, eliminating the need for the current
SAL calls. Also, with ACPI support, SN fixup code is no longer
needed to initiate the PCI bus scans, as the acpi_pci_root_driver
does that.
However, to maintain backward compatibility with non-ACPI capable
PROMs, none of the current 'fixup' code can been deleted, though
much restructuring has been done. For example, the bulk of the code
in io_common.c is relocated code that is now common regardless
of what PROM is running, while io_acpi_init.c and io_init.c contain
routines specific to an ACPI or non ACPI capable PROM respectively.
A new pci bus fixup platform vector has been created to provide
a hook for invoking platform specific bus fixup from pcibios_fixup_bus().
The size of io_space[] has been increased to support systems with
large IO configurations.
Signed-off-by: John Keller <jpk@sgi.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2006-10-05 05:49:25 +08:00
|
|
|
platform_pci_fixup_bus(b);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2013-04-12 13:44:22 +08:00
|
|
|
void pcibios_add_bus(struct pci_bus *bus)
|
|
|
|
{
|
|
|
|
acpi_pci_add_bus(bus);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pcibios_remove_bus(struct pci_bus *bus)
|
|
|
|
{
|
|
|
|
acpi_pci_remove_bus(bus);
|
|
|
|
}
|
|
|
|
|
2011-10-29 05:47:49 +08:00
|
|
|
void pcibios_set_master (struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
/* No special bus mastering setup handling */
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
int
|
|
|
|
pcibios_enable_device (struct pci_dev *dev, int mask)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2008-03-05 02:56:52 +08:00
|
|
|
ret = pci_enable_resources(dev, mask);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2007-03-28 21:36:09 +08:00
|
|
|
if (!dev->msi_enabled)
|
|
|
|
return acpi_pci_irq_enable(dev);
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pcibios_disable_device (struct pci_dev *dev)
|
|
|
|
{
|
2006-12-05 09:25:31 +08:00
|
|
|
BUG_ON(atomic_read(&dev->enable_cnt));
|
2007-03-28 21:36:09 +08:00
|
|
|
if (!dev->msi_enabled)
|
|
|
|
acpi_pci_irq_disable(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-01-02 00:40:49 +08:00
|
|
|
resource_size_t
|
2010-01-02 00:40:50 +08:00
|
|
|
pcibios_align_resource (void *data, const struct resource *res,
|
2006-06-13 08:06:02 +08:00
|
|
|
resource_size_t size, resource_size_t align)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-01-02 00:40:49 +08:00
|
|
|
return res->start;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pci_mmap_page_range (struct pci_dev *dev, struct vm_area_struct *vma,
|
|
|
|
enum pci_mmap_state mmap_state, int write_combine)
|
|
|
|
{
|
2007-07-12 01:02:15 +08:00
|
|
|
unsigned long size = vma->vm_end - vma->vm_start;
|
|
|
|
pgprot_t prot;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* I/O space cannot be accessed via normal processor loads and
|
|
|
|
* stores on this platform.
|
|
|
|
*/
|
|
|
|
if (mmap_state == pci_mmap_io)
|
|
|
|
/*
|
|
|
|
* XXX we could relax this for I/O spaces for which ACPI
|
|
|
|
* indicates that the space is 1-to-1 mapped. But at the
|
|
|
|
* moment, we don't support multiple PCI address spaces and
|
|
|
|
* the legacy I/O space is not 1-to-1 mapped, so this is moot.
|
|
|
|
*/
|
|
|
|
return -EINVAL;
|
|
|
|
|
2007-07-12 01:02:15 +08:00
|
|
|
if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
prot = phys_mem_access_prot(NULL, vma->vm_pgoff, size,
|
|
|
|
vma->vm_page_prot);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2007-07-12 01:02:15 +08:00
|
|
|
* If the user requested WC, the kernel uses UC or WC for this region,
|
|
|
|
* and the chipset supports WC, we can use WC. Otherwise, we have to
|
|
|
|
* use the same attribute the kernel uses.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2007-07-12 01:02:15 +08:00
|
|
|
if (write_combine &&
|
|
|
|
((pgprot_val(prot) & _PAGE_MA_MASK) == _PAGE_MA_UC ||
|
|
|
|
(pgprot_val(prot) & _PAGE_MA_MASK) == _PAGE_MA_WC) &&
|
|
|
|
efi_range_is_wc(vma->vm_start, vma->vm_end - vma->vm_start))
|
2005-04-17 06:20:36 +08:00
|
|
|
vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
|
|
|
|
else
|
2007-07-12 01:02:15 +08:00
|
|
|
vma->vm_page_prot = prot;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
|
|
|
|
vma->vm_end - vma->vm_start, vma->vm_page_prot))
|
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ia64_pci_get_legacy_mem - generic legacy mem routine
|
|
|
|
* @bus: bus to get legacy memory base address for
|
|
|
|
*
|
|
|
|
* Find the base of legacy memory for @bus. This is typically the first
|
|
|
|
* megabyte of bus address space for @bus or is simply 0 on platforms whose
|
|
|
|
* chipsets support legacy I/O and memory routing. Returns the base address
|
|
|
|
* or an error pointer if an error occurred.
|
|
|
|
*
|
|
|
|
* This is the ia64 generic version of this routine. Other platforms
|
|
|
|
* are free to override it with a machine vector.
|
|
|
|
*/
|
|
|
|
char *ia64_pci_get_legacy_mem(struct pci_bus *bus)
|
|
|
|
{
|
|
|
|
return (char *)__IA64_UNCACHED_OFFSET;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pci_mmap_legacy_page_range - map legacy memory space to userland
|
|
|
|
* @bus: bus whose legacy space we're mapping
|
|
|
|
* @vma: vma passed in by mmap
|
|
|
|
*
|
|
|
|
* Map legacy memory space for this device back to userspace using a machine
|
|
|
|
* vector to get the base address.
|
|
|
|
*/
|
|
|
|
int
|
2008-10-03 17:49:32 +08:00
|
|
|
pci_mmap_legacy_page_range(struct pci_bus *bus, struct vm_area_struct *vma,
|
|
|
|
enum pci_mmap_state mmap_state)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-05-06 07:19:50 +08:00
|
|
|
unsigned long size = vma->vm_end - vma->vm_start;
|
|
|
|
pgprot_t prot;
|
2005-04-17 06:20:36 +08:00
|
|
|
char *addr;
|
|
|
|
|
2008-10-03 17:49:32 +08:00
|
|
|
/* We only support mmap'ing of legacy memory space */
|
|
|
|
if (mmap_state != pci_mmap_mem)
|
|
|
|
return -ENOSYS;
|
|
|
|
|
2006-05-06 07:19:50 +08:00
|
|
|
/*
|
|
|
|
* Avoid attribute aliasing. See Documentation/ia64/aliasing.txt
|
|
|
|
* for more details.
|
|
|
|
*/
|
2006-07-10 19:45:27 +08:00
|
|
|
if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size))
|
2006-05-06 07:19:50 +08:00
|
|
|
return -EINVAL;
|
|
|
|
prot = phys_mem_access_prot(NULL, vma->vm_pgoff, size,
|
|
|
|
vma->vm_page_prot);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
addr = pci_get_legacy_mem(bus);
|
|
|
|
if (IS_ERR(addr))
|
|
|
|
return PTR_ERR(addr);
|
|
|
|
|
|
|
|
vma->vm_pgoff += (unsigned long)addr >> PAGE_SHIFT;
|
2006-05-06 07:19:50 +08:00
|
|
|
vma->vm_page_prot = prot;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
|
2006-05-06 07:19:50 +08:00
|
|
|
size, vma->vm_page_prot))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ia64_pci_legacy_read - read from legacy I/O space
|
|
|
|
* @bus: bus to read
|
|
|
|
* @port: legacy port value
|
|
|
|
* @val: caller allocated storage for returned value
|
|
|
|
* @size: number of bytes to read
|
|
|
|
*
|
|
|
|
* Simply reads @size bytes from @port and puts the result in @val.
|
|
|
|
*
|
|
|
|
* Again, this (and the write routine) are generic versions that can be
|
|
|
|
* overridden by the platform. This is necessary on platforms that don't
|
|
|
|
* support legacy I/O routing or that hard fail on legacy I/O timeouts.
|
|
|
|
*/
|
|
|
|
int ia64_pci_legacy_read(struct pci_bus *bus, u16 port, u32 *val, u8 size)
|
|
|
|
{
|
|
|
|
int ret = size;
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
*val = inb(port);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
*val = inw(port);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
*val = inl(port);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ia64_pci_legacy_write - perform a legacy I/O write
|
|
|
|
* @bus: bus pointer
|
|
|
|
* @port: port to write
|
|
|
|
* @val: value to write
|
|
|
|
* @size: number of bytes to write from @val
|
|
|
|
*
|
|
|
|
* Simply writes @size bytes of @val to @port.
|
|
|
|
*/
|
2006-04-20 17:49:48 +08:00
|
|
|
int ia64_pci_legacy_write(struct pci_bus *bus, u16 port, u32 val, u8 size)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-12-22 06:21:36 +08:00
|
|
|
int ret = size;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
outb(val, port);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
outw(val, port);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
outl(val, port);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-10-10 22:01:19 +08:00
|
|
|
* set_pci_cacheline_size - determine cacheline size for PCI devices
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* We want to use the line-size of the outer-most cache. We assume
|
|
|
|
* that this line-size is the same for all CPUs.
|
|
|
|
*
|
|
|
|
* Code mostly taken from arch/ia64/kernel/palinfo.c:cache_info().
|
|
|
|
*/
|
2009-10-27 04:20:44 +08:00
|
|
|
static void __init set_pci_dfl_cacheline_size(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-05-23 04:49:49 +08:00
|
|
|
unsigned long levels, unique_caches;
|
|
|
|
long status;
|
2005-04-17 06:20:36 +08:00
|
|
|
pal_cache_config_info_t cci;
|
|
|
|
|
|
|
|
status = ia64_pal_cache_summary(&levels, &unique_caches);
|
|
|
|
if (status != 0) {
|
2013-06-06 15:34:53 +08:00
|
|
|
pr_err("%s: ia64_pal_cache_summary() failed "
|
2008-03-05 07:15:00 +08:00
|
|
|
"(status=%ld)\n", __func__, status);
|
2006-10-10 22:01:19 +08:00
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-10-10 22:01:19 +08:00
|
|
|
status = ia64_pal_cache_config_info(levels - 1,
|
|
|
|
/* cache_type (data_or_unified)= */ 2, &cci);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (status != 0) {
|
2013-06-06 15:34:53 +08:00
|
|
|
pr_err("%s: ia64_pal_cache_config_info() failed "
|
2008-03-05 07:15:00 +08:00
|
|
|
"(status=%ld)\n", __func__, status);
|
2006-10-10 22:01:19 +08:00
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-10-27 04:20:44 +08:00
|
|
|
pci_dfl_cache_line_size = (1 << cci.pcci_line_size) / 4;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-11-25 06:47:17 +08:00
|
|
|
u64 ia64_dma_get_required_mask(struct device *dev)
|
|
|
|
{
|
|
|
|
u32 low_totalram = ((max_pfn - 1) << PAGE_SHIFT);
|
|
|
|
u32 high_totalram = ((max_pfn - 1) >> (32 - PAGE_SHIFT));
|
|
|
|
u64 mask;
|
|
|
|
|
|
|
|
if (!high_totalram) {
|
|
|
|
/* convert to mask just covering totalram */
|
|
|
|
low_totalram = (1 << (fls(low_totalram) - 1));
|
|
|
|
low_totalram += low_totalram - 1;
|
|
|
|
mask = low_totalram;
|
|
|
|
} else {
|
|
|
|
high_totalram = (1 << (fls(high_totalram) - 1));
|
|
|
|
high_totalram += high_totalram - 1;
|
|
|
|
mask = (((u64)high_totalram) << 32) + 0xffffffff;
|
|
|
|
}
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(ia64_dma_get_required_mask);
|
|
|
|
|
|
|
|
u64 dma_get_required_mask(struct device *dev)
|
|
|
|
{
|
|
|
|
return platform_dma_get_required_mask(dev);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dma_get_required_mask);
|
|
|
|
|
2006-10-10 22:01:19 +08:00
|
|
|
static int __init pcibios_init(void)
|
|
|
|
{
|
2009-10-27 04:20:44 +08:00
|
|
|
set_pci_dfl_cacheline_size();
|
2006-10-10 22:01:19 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2006-10-10 22:01:19 +08:00
|
|
|
|
|
|
|
subsys_initcall(pcibios_init);
|