Commit 8fbcf5ec authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

Merge branch 'acpi-resources'

* acpi-resources: (23 commits)
  Merge branch 'pci/host-generic' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci into acpi-resources
  x86/irq, ACPI: Implement ACPI driver to support IOAPIC hotplug
  ACPI: Add interfaces to parse IOAPIC ID for IOAPIC hotplug
  x86/PCI: Refine the way to release PCI IRQ resources
  x86/PCI/ACPI: Use common ACPI resource interfaces to simplify implementation
  x86/PCI: Fix the range check for IO resources
  PCI: Use common resource list management code instead of private implementation
  resources: Move struct resource_list_entry from ACPI into resource core
  ACPI: Introduce helper function acpi_dev_filter_resource_type()
  ACPI: Add field offset to struct resource_list_entry
  ACPI: Translate resource into master side address for bridge window resources
  ACPI: Return translation offset when parsing ACPI address space resources
  ACPI: Enforce stricter checks for address space descriptors
  ACPI: Set flag IORESOURCE_UNSET for unassigned resources
  ACPI: Normalize return value of resource parser functions
  ACPI: Fix a bug in parsing ACPI Memory24 resource
  ACPI: Add prefetch decoding to the address space parser
  ACPI: Move the window flag logic to the combined parser
  ACPI: Unify the parsing of address_space and ext_address_space
  ACPI: Let the parser return false for disabled resources
  ...
parents d2320968 5c493df2
...@@ -422,17 +422,16 @@ static int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin) ...@@ -422,17 +422,16 @@ static int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
static int pcibios_init_resources(int busnr, struct pci_sys_data *sys) static int pcibios_init_resources(int busnr, struct pci_sys_data *sys)
{ {
int ret; int ret;
struct pci_host_bridge_window *window; struct resource_entry *window;
if (list_empty(&sys->resources)) { if (list_empty(&sys->resources)) {
pci_add_resource_offset(&sys->resources, pci_add_resource_offset(&sys->resources,
&iomem_resource, sys->mem_offset); &iomem_resource, sys->mem_offset);
} }
list_for_each_entry(window, &sys->resources, list) { resource_list_for_each_entry(window, &sys->resources)
if (resource_type(window->res) == IORESOURCE_IO) if (resource_type(window->res) == IORESOURCE_IO)
return 0; return 0;
}
sys->io_res.start = (busnr * SZ_64K) ? : pcibios_min_io; sys->io_res.start = (busnr * SZ_64K) ? : pcibios_min_io;
sys->io_res.end = (busnr + 1) * SZ_64K - 1; sys->io_res.end = (busnr + 1) * SZ_64K - 1;
......
...@@ -93,8 +93,6 @@ extern raw_spinlock_t pci_config_lock; ...@@ -93,8 +93,6 @@ extern raw_spinlock_t pci_config_lock;
extern int (*pcibios_enable_irq)(struct pci_dev *dev); extern int (*pcibios_enable_irq)(struct pci_dev *dev);
extern void (*pcibios_disable_irq)(struct pci_dev *dev); extern void (*pcibios_disable_irq)(struct pci_dev *dev);
extern bool mp_should_keep_irq(struct device *dev);
struct pci_raw_ops { struct pci_raw_ops {
int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn, int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn,
int reg, int len, u32 *val); int reg, int len, u32 *val);
......
This diff is collapsed.
...@@ -31,7 +31,7 @@ void x86_pci_root_bus_resources(int bus, struct list_head *resources) ...@@ -31,7 +31,7 @@ void x86_pci_root_bus_resources(int bus, struct list_head *resources)
{ {
struct pci_root_info *info = x86_find_pci_root_info(bus); struct pci_root_info *info = x86_find_pci_root_info(bus);
struct pci_root_res *root_res; struct pci_root_res *root_res;
struct pci_host_bridge_window *window; struct resource_entry *window;
bool found = false; bool found = false;
if (!info) if (!info)
...@@ -41,7 +41,7 @@ void x86_pci_root_bus_resources(int bus, struct list_head *resources) ...@@ -41,7 +41,7 @@ void x86_pci_root_bus_resources(int bus, struct list_head *resources)
bus); bus);
/* already added by acpi ? */ /* already added by acpi ? */
list_for_each_entry(window, resources, list) resource_list_for_each_entry(window, resources)
if (window->res->flags & IORESOURCE_BUS) { if (window->res->flags & IORESOURCE_BUS) {
found = true; found = true;
break; break;
......
...@@ -513,6 +513,31 @@ void __init pcibios_set_cache_line_size(void) ...@@ -513,6 +513,31 @@ void __init pcibios_set_cache_line_size(void)
} }
} }
/*
* Some device drivers assume dev->irq won't change after calling
* pci_disable_device(). So delay releasing of IRQ resource to driver
* unbinding time. Otherwise it will break PM subsystem and drivers
* like xen-pciback etc.
*/
static int pci_irq_notifier(struct notifier_block *nb, unsigned long action,
void *data)
{
struct pci_dev *dev = to_pci_dev(data);
if (action != BUS_NOTIFY_UNBOUND_DRIVER)
return NOTIFY_DONE;
if (pcibios_disable_irq)
pcibios_disable_irq(dev);
return NOTIFY_OK;
}
static struct notifier_block pci_irq_nb = {
.notifier_call = pci_irq_notifier,
.priority = INT_MIN,
};
int __init pcibios_init(void) int __init pcibios_init(void)
{ {
if (!raw_pci_ops) { if (!raw_pci_ops) {
...@@ -525,6 +550,9 @@ int __init pcibios_init(void) ...@@ -525,6 +550,9 @@ int __init pcibios_init(void)
if (pci_bf_sort >= pci_force_bf) if (pci_bf_sort >= pci_force_bf)
pci_sort_breadthfirst(); pci_sort_breadthfirst();
bus_register_notifier(&pci_bus_type, &pci_irq_nb);
return 0; return 0;
} }
...@@ -683,12 +711,6 @@ int pcibios_enable_device(struct pci_dev *dev, int mask) ...@@ -683,12 +711,6 @@ int pcibios_enable_device(struct pci_dev *dev, int mask)
return 0; return 0;
} }
void pcibios_disable_device (struct pci_dev *dev)
{
if (!pci_dev_msi_enabled(dev) && pcibios_disable_irq)
pcibios_disable_irq(dev);
}
int pci_ext_cfg_avail(void) int pci_ext_cfg_avail(void)
{ {
if (raw_pci_ext_ops) if (raw_pci_ext_ops)
......
...@@ -234,10 +234,10 @@ static int intel_mid_pci_irq_enable(struct pci_dev *dev) ...@@ -234,10 +234,10 @@ static int intel_mid_pci_irq_enable(struct pci_dev *dev)
static void intel_mid_pci_irq_disable(struct pci_dev *dev) static void intel_mid_pci_irq_disable(struct pci_dev *dev)
{ {
if (!mp_should_keep_irq(&dev->dev) && dev->irq_managed && if (dev->irq_managed && dev->irq > 0) {
dev->irq > 0) {
mp_unmap_irq(dev->irq); mp_unmap_irq(dev->irq);
dev->irq_managed = 0; dev->irq_managed = 0;
dev->irq = 0;
} }
} }
......
...@@ -1256,22 +1256,9 @@ static int pirq_enable_irq(struct pci_dev *dev) ...@@ -1256,22 +1256,9 @@ static int pirq_enable_irq(struct pci_dev *dev)
return 0; return 0;
} }
bool mp_should_keep_irq(struct device *dev)
{
if (dev->power.is_prepared)
return true;
#ifdef CONFIG_PM
if (dev->power.runtime_status == RPM_SUSPENDING)
return true;
#endif
return false;
}
static void pirq_disable_irq(struct pci_dev *dev) static void pirq_disable_irq(struct pci_dev *dev)
{ {
if (io_apic_assign_pci_irqs && !mp_should_keep_irq(&dev->dev) && if (io_apic_assign_pci_irqs && dev->irq_managed && dev->irq) {
dev->irq_managed && dev->irq) {
mp_unmap_irq(dev->irq); mp_unmap_irq(dev->irq);
dev->irq = 0; dev->irq = 0;
dev->irq_managed = 0; dev->irq_managed = 0;
......
...@@ -315,6 +315,12 @@ config ACPI_HOTPLUG_MEMORY ...@@ -315,6 +315,12 @@ config ACPI_HOTPLUG_MEMORY
To compile this driver as a module, choose M here: To compile this driver as a module, choose M here:
the module will be called acpi_memhotplug. the module will be called acpi_memhotplug.
config ACPI_HOTPLUG_IOAPIC
bool
depends on PCI
depends on X86_IO_APIC
default y
config ACPI_SBS config ACPI_SBS
tristate "Smart Battery System" tristate "Smart Battery System"
depends on X86 depends on X86
......
...@@ -70,6 +70,7 @@ obj-$(CONFIG_ACPI_PROCESSOR) += processor.o ...@@ -70,6 +70,7 @@ obj-$(CONFIG_ACPI_PROCESSOR) += processor.o
obj-y += container.o obj-y += container.o
obj-$(CONFIG_ACPI_THERMAL) += thermal.o obj-$(CONFIG_ACPI_THERMAL) += thermal.o
obj-y += acpi_memhotplug.o obj-y += acpi_memhotplug.o
obj-$(CONFIG_ACPI_HOTPLUG_IOAPIC) += ioapic.o
obj-$(CONFIG_ACPI_BATTERY) += battery.o obj-$(CONFIG_ACPI_BATTERY) += battery.o
obj-$(CONFIG_ACPI_SBS) += sbshc.o obj-$(CONFIG_ACPI_SBS) += sbshc.o
obj-$(CONFIG_ACPI_SBS) += sbs.o obj-$(CONFIG_ACPI_SBS) += sbs.o
......
...@@ -307,7 +307,7 @@ static int acpi_lpss_create_device(struct acpi_device *adev, ...@@ -307,7 +307,7 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
{ {
struct lpss_device_desc *dev_desc; struct lpss_device_desc *dev_desc;
struct lpss_private_data *pdata; struct lpss_private_data *pdata;
struct resource_list_entry *rentry; struct resource_entry *rentry;
struct list_head resource_list; struct list_head resource_list;
struct platform_device *pdev; struct platform_device *pdev;
int ret; int ret;
...@@ -327,12 +327,12 @@ static int acpi_lpss_create_device(struct acpi_device *adev, ...@@ -327,12 +327,12 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
goto err_out; goto err_out;
list_for_each_entry(rentry, &resource_list, node) list_for_each_entry(rentry, &resource_list, node)
if (resource_type(&rentry->res) == IORESOURCE_MEM) { if (resource_type(rentry->res) == IORESOURCE_MEM) {
if (dev_desc->prv_size_override) if (dev_desc->prv_size_override)
pdata->mmio_size = dev_desc->prv_size_override; pdata->mmio_size = dev_desc->prv_size_override;
else else
pdata->mmio_size = resource_size(&rentry->res); pdata->mmio_size = resource_size(rentry->res);
pdata->mmio_base = ioremap(rentry->res.start, pdata->mmio_base = ioremap(rentry->res->start,
pdata->mmio_size); pdata->mmio_size);
if (!pdata->mmio_base) if (!pdata->mmio_base)
goto err_out; goto err_out;
......
...@@ -45,7 +45,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev) ...@@ -45,7 +45,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev)
struct platform_device *pdev = NULL; struct platform_device *pdev = NULL;
struct acpi_device *acpi_parent; struct acpi_device *acpi_parent;
struct platform_device_info pdevinfo; struct platform_device_info pdevinfo;
struct resource_list_entry *rentry; struct resource_entry *rentry;
struct list_head resource_list; struct list_head resource_list;
struct resource *resources = NULL; struct resource *resources = NULL;
int count; int count;
...@@ -71,7 +71,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev) ...@@ -71,7 +71,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev)
} }
count = 0; count = 0;
list_for_each_entry(rentry, &resource_list, node) list_for_each_entry(rentry, &resource_list, node)
resources[count++] = rentry->res; resources[count++] = *rentry->res;
acpi_dev_free_resource_list(&resource_list); acpi_dev_free_resource_list(&resource_list);
} }
......
...@@ -35,6 +35,13 @@ void acpi_int340x_thermal_init(void); ...@@ -35,6 +35,13 @@ void acpi_int340x_thermal_init(void);
int acpi_sysfs_init(void); int acpi_sysfs_init(void);
void acpi_container_init(void); void acpi_container_init(void);
void acpi_memory_hotplug_init(void); void acpi_memory_hotplug_init(void);
#ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
int acpi_ioapic_add(struct acpi_pci_root *root);
int acpi_ioapic_remove(struct acpi_pci_root *root);
#else
static inline int acpi_ioapic_add(struct acpi_pci_root *root) { return 0; }
static inline int acpi_ioapic_remove(struct acpi_pci_root *root) { return 0; }
#endif
#ifdef CONFIG_ACPI_DOCK #ifdef CONFIG_ACPI_DOCK
void register_dock_dependent_device(struct acpi_device *adev, void register_dock_dependent_device(struct acpi_device *adev,
acpi_handle dshandle); acpi_handle dshandle);
......
/*
* IOAPIC/IOxAPIC/IOSAPIC driver
*
* Copyright (C) 2009 Fujitsu Limited.
* (c) Copyright 2009 Hewlett-Packard Development Company, L.P.
*
* Copyright (C) 2014 Intel Corporation
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Based on original drivers/pci/ioapic.c
* Yinghai Lu <yinghai@kernel.org>
* Jiang Liu <jiang.liu@intel.com>
*/
/*
* This driver manages I/O APICs added by hotplug after boot.
* We try to claim all I/O APIC devices, but those present at boot were
* registered when we parsed the ACPI MADT.
*/
#define pr_fmt(fmt) "ACPI : IOAPIC: " fmt
#include <linux/slab.h>
#include <linux/acpi.h>
#include <linux/pci.h>
#include <acpi/acpi.h>
struct acpi_pci_ioapic {
acpi_handle root_handle;
acpi_handle handle;
u32 gsi_base;
struct resource res;
struct pci_dev *pdev;
struct list_head list;
};
static LIST_HEAD(ioapic_list);
static DEFINE_MUTEX(ioapic_list_lock);
static acpi_status setup_res(struct acpi_resource *acpi_res, void *data)
{
struct resource *res = data;
struct resource_win win;
res->flags = 0;
if (acpi_dev_filter_resource_type(acpi_res, IORESOURCE_MEM) == 0)
return AE_OK;
if (!acpi_dev_resource_memory(acpi_res, res)) {
if (acpi_dev_resource_address_space(acpi_res, &win) ||
acpi_dev_resource_ext_address_space(acpi_res, &win))
*res = win.res;
}
if ((res->flags & IORESOURCE_PREFETCH) ||
(res->flags & IORESOURCE_DISABLED))
res->flags = 0;
return AE_CTRL_TERMINATE;
}
static bool acpi_is_ioapic(acpi_handle handle, char **type)
{
acpi_status status;
struct acpi_device_info *info;
char *hid = NULL;
bool match = false;
if (!acpi_has_method(handle, "_GSB"))
return false;
status = acpi_get_object_info(handle, &info);
if (ACPI_SUCCESS(status)) {
if (info->valid & ACPI_VALID_HID)
hid = info->hardware_id.string;
if (hid) {
if (strcmp(hid, "ACPI0009") == 0) {
*type = "IOxAPIC";
match = true;
} else if (strcmp(hid, "ACPI000A") == 0) {
*type = "IOAPIC";
match = true;
}
}
kfree(info);
}
return match;
}
static acpi_status handle_ioapic_add(acpi_handle handle, u32 lvl,
void *context, void **rv)
{
acpi_status status;
unsigned long long gsi_base;
struct acpi_pci_ioapic *ioapic;
struct pci_dev *dev = NULL;
struct resource *res = NULL;
char *type = NULL;
if (!acpi_is_ioapic(handle, &type))
return AE_OK;
mutex_lock(&ioapic_list_lock);
list_for_each_entry(ioapic, &ioapic_list, list)
if (ioapic->handle == handle) {
mutex_unlock(&ioapic_list_lock);
return AE_OK;
}
status = acpi_evaluate_integer(handle, "_GSB", NULL, &gsi_base);
if (ACPI_FAILURE(status)) {
acpi_handle_warn(handle, "failed to evaluate _GSB method\n");
goto exit;
}
ioapic = kzalloc(sizeof(*ioapic), GFP_KERNEL);
if (!ioapic) {
pr_err("cannot allocate memory for new IOAPIC\n");
goto exit;
} else {
ioapic->root_handle = (acpi_handle)context;
ioapic->handle = handle;
ioapic->gsi_base = (u32)gsi_base;
INIT_LIST_HEAD(&ioapic->list);
}
if (acpi_ioapic_registered(handle, (u32)gsi_base))
goto done;
dev = acpi_get_pci_dev(handle);
if (dev && pci_resource_len(dev, 0)) {
if (pci_enable_device(dev) < 0)
goto exit_put;
pci_set_master(dev);
if (pci_request_region(dev, 0, type))
goto exit_disable;
res = &dev->resource[0];
ioapic->pdev = dev;
} else {
pci_dev_put(dev);
dev = NULL;
res = &ioapic->res;
acpi_walk_resources(handle, METHOD_NAME__CRS, setup_res, res);
if (res->flags == 0) {
acpi_handle_warn(handle, "failed to get resource\n");
goto exit_free;
} else if (request_resource(&iomem_resource, res)) {
acpi_handle_warn(handle, "failed to insert resource\n");
goto exit_free;
}
}
if (acpi_register_ioapic(handle, res->start, (u32)gsi_base)) {
acpi_handle_warn(handle, "failed to register IOAPIC\n");
goto exit_release;
}
done:
list_add(&ioapic->list, &ioapic_list);
mutex_unlock(&ioapic_list_lock);
if (dev)
dev_info(&dev->dev, "%s at %pR, GSI %u\n",
type, res, (u32)gsi_base);
else
acpi_handle_info(handle, "%s at %pR, GSI %u\n",
type, res, (u32)gsi_base);
return AE_OK;
exit_release:
if (dev)
pci_release_region(dev, 0);
else
release_resource(res);
exit_disable:
if (dev)
pci_disable_device(dev);
exit_put:
pci_dev_put(dev);
exit_free:
kfree(ioapic);
exit:
mutex_unlock(&ioapic_list_lock);
*(acpi_status *)rv = AE_ERROR;
return AE_OK;
}
int acpi_ioapic_add(struct acpi_pci_root *root)
{
acpi_status status, retval = AE_OK;
status = acpi_walk_namespace(ACPI_TYPE_DEVICE, root->device->handle,
UINT_MAX, handle_ioapic_add, NULL,
root->device->handle, (void **)&retval);
return ACPI_SUCCESS(status) && ACPI_SUCCESS(retval) ? 0 : -ENODEV;
}
int acpi_ioapic_remove(struct acpi_pci_root *root)
{
int retval = 0;
struct acpi_pci_ioapic *ioapic, *tmp;
mutex_lock(&ioapic_list_lock);
list_for_each_entry_safe(ioapic, tmp, &ioapic_list, list) {
if (root->device->handle != ioapic->root_handle)
continue;
if (acpi_unregister_ioapic(ioapic->handle, ioapic->gsi_base))
retval = -EBUSY;
if (ioapic->pdev) {
pci_release_region(ioapic->pdev, 0);
pci_disable_device(ioapic->pdev);
pci_dev_put(ioapic->pdev);
} else if (ioapic->res.flags && ioapic->res.parent) {
release_resource(&ioapic->res);
}
list_del(&ioapic->list);
kfree(ioapic);
}
mutex_unlock(&ioapic_list_lock);
return retval;
}
...@@ -485,14 +485,6 @@ void acpi_pci_irq_disable(struct pci_dev *dev) ...@@ -485,14 +485,6 @@ void acpi_pci_irq_disable(struct pci_dev *dev)
if (!pin || !dev->irq_managed || dev->irq <= 0) if (!pin || !dev->irq_managed || dev->irq <= 0)
return; return;
/* Keep IOAPIC pin configuration when suspending */
if (dev->dev.power.is_prepared)
return;
#ifdef CONFIG_PM
if (dev->dev.power.runtime_status == RPM_SUSPENDING)
return;
#endif
entry = acpi_pci_irq_lookup(dev, pin); entry = acpi_pci_irq_lookup(dev, pin);
if (!entry) if (!entry)
return; return;
...@@ -513,5 +505,6 @@ void acpi_pci_irq_disable(struct pci_dev *dev) ...@@ -513,5 +505,6 @@ void acpi_pci_irq_disable(struct pci_dev *dev)
if (gsi >= 0) { if (gsi >= 0) {
acpi_unregister_gsi(gsi); acpi_unregister_gsi(gsi);
dev->irq_managed = 0; dev->irq_managed = 0;
dev->irq = 0;
} }
} }
...@@ -621,6 +621,7 @@ static int acpi_pci_root_add(struct acpi_device *device, ...@@ -621,6 +621,7 @@ static int acpi_pci_root_add(struct acpi_device *device,
if (hotadd) { if (hotadd) {
pcibios_resource_survey_bus(root->bus); pcibios_resource_survey_bus(root->bus);
pci_assign_unassigned_root_bus_resources(root->bus); pci_assign_unassigned_root_bus_resources(root->bus);
acpi_ioapic_add(root);
} }
pci_lock_rescan_remove(); pci_lock_rescan_remove();
...@@ -644,6 +645,8 @@ static void acpi_pci_root_remove(struct acpi_device *device) ...@@ -644,6 +645,8 @@ static void acpi_pci_root_remove(struct acpi_device *device)
pci_stop_root_bus(root->bus); pci_stop_root_bus(root->bus);
WARN_ON(acpi_ioapic_remove(root));
device_set_run_wake(root->bus->bridge, false); device_set_run_wake(root->bus->bridge, false);
pci_acpi_remove_bus_pm_notifier(device); pci_acpi_remove_bus_pm_notifier(device);
......
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
* *
* Alex Chiang <achiang@hp.com> * Alex Chiang <achiang@hp.com>
* - Unified x86/ia64 implementations * - Unified x86/ia64 implementations
*
* I/O APIC hotplug support
* Yinghai Lu <yinghai@kernel.org>
* Jiang Liu <jiang.liu@intel.com>
*/ */
#include <linux/export.h> #include <linux/export.h>
#include <linux/acpi.h> #include <linux/acpi.h>
...@@ -12,6 +16,21 @@ ...@@ -12,6 +16,21 @@
#define _COMPONENT ACPI_PROCESSOR_COMPONENT #define _COMPONENT ACPI_PROCESSOR_COMPONENT
ACPI_MODULE_NAME("processor_core"); ACPI_MODULE_NAME("processor_core");
static struct acpi_table_madt *get_madt_table(void)
{
static struct acpi_table_madt *madt;
static int read_madt;
if (!read_madt) {
if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_MADT, 0,
(struct acpi_table_header **)&madt)))
madt = NULL;
read_madt++;
}
return madt;
}
static int map_lapic_id(struct acpi_subtable_header *entry, static int map_lapic_id(struct acpi_subtable_header *entry,
u32 acpi_id, int *apic_id) u32 acpi_id, int *apic_id)
{ {
...@@ -67,17 +86,10 @@ static int map_lsapic_id(struct acpi_subtable_header *entry, ...@@ -67,17 +86,10 @@ static int map_lsapic_id(struct acpi_subtable_header *entry,
static int map_madt_entry(int type, u32 acpi_id) static int map_madt_entry(int type, u32 acpi_id)
{ {
unsigned long madt_end, entry; unsigned long madt_end, entry;
static struct acpi_table_madt *madt;
static int read_madt;
int phys_id = -1; /* CPU hardware ID */ int phys_id = -1; /* CPU hardware ID */
struct acpi_table_madt *madt;
if (!read_madt) { madt = get_madt_table();
if (ACPI_FAILURE(acpi_get_table(ACPI_SIG_MADT, 0,
(struct acpi_table_header **)&madt)))
madt = NULL;
read_madt++;
}
if (!madt) if (!madt)
return phys_id; return phys_id;
...@@ -203,3 +215,96 @@ int acpi_get_cpuid(acpi_handle handle, int type, u32 acpi_id) ...@@ -203,3 +215,96 @@ int acpi_get_cpuid(acpi_handle handle, int type, u32 acpi_id)
return acpi_map_cpuid(phys_id, acpi_id); return acpi_map_cpuid(phys_id, acpi_id);
} }
EXPORT_SYMBOL_GPL(acpi_get_cpuid); EXPORT_SYMBOL_GPL(acpi_get_cpuid);
#ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
static int get_ioapic_id(struct acpi_subtable_header *entry, u32 gsi_base,
u64 *phys_addr, int *ioapic_id)
{
struct acpi_madt_io_apic *ioapic = (struct acpi_madt_io_apic *)entry;
if (ioapic->global_irq_base != gsi_base)
return 0;
*phys_addr = ioapic->address;
*ioapic_id = ioapic->id;
return 1;
}
static int parse_madt_ioapic_entry(u32 gsi_base, u64 *phys_addr)
{
struct acpi_subtable_header *hdr;
unsigned long madt_end, entry;
struct acpi_table_madt *madt;
int apic_id = -1;
madt = get_madt_table();
if (!madt)
return apic_id;
entry = (unsigned long)madt;
madt_end = entry + madt->header.length;
/* Parse all entries looking for a match. */
entry += sizeof(struct acpi_table_madt);
while (entry + sizeof(struct acpi_subtable_header) < madt_end) {
hdr = (struct acpi_subtable_header *)entry;
if (hdr->type == ACPI_MADT_TYPE_IO_APIC &&
get_ioapic_id(hdr, gsi_base, phys_addr, &apic_id))
break;
else
entry += hdr->length;
}
return apic_id;
}
static int parse_mat_ioapic_entry(acpi_handle handle, u32 gsi_base,
u64 *phys_addr)
{
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
struct acpi_subtable_header *header;
union acpi_object *obj;
int apic_id = -1;
if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
goto exit;
if (!buffer.length || !buffer.pointer)
goto exit;
obj = buffer.pointer;
if (obj->type != ACPI_TYPE_BUFFER ||
obj->buffer.length < sizeof(struct acpi_subtable_header))
goto exit;
header = (struct acpi_subtable_header *)obj->buffer.pointer;
if (header->type == ACPI_MADT_TYPE_IO_APIC)
get_ioapic_id(header, gsi_base, phys_addr, &apic_id);
exit:
kfree(buffer.pointer);
return apic_id;
}
/**
* acpi_get_ioapic_id - Get IOAPIC ID and physical address matching @gsi_base
* @handle: ACPI object for IOAPIC device
* @gsi_base: GSI base to match with
* @phys_addr: Pointer to store physical address of matching IOAPIC record
*
* Walk resources returned by ACPI_MAT method, then ACPI MADT table, to search
* for an ACPI IOAPIC record matching @gsi_base.
* Return IOAPIC id and store physical address in @phys_addr if found a match,
* otherwise return <0.
*/
int acpi_get_ioapic_id(acpi_handle handle, u32 gsi_base, u64 *phys_addr)
{
int apic_id;
apic_id = parse_mat_ioapic_entry(handle, gsi_base, phys_addr);
if (apic_id == -1)
apic_id = parse_madt_ioapic_entry(gsi_base, phys_addr);
return apic_id;
}
#endif /* CONFIG_ACPI_HOTPLUG_IOAPIC */
This diff is collapsed.
...@@ -43,7 +43,7 @@ static int acpi_dma_parse_resource_group(const struct acpi_csrt_group *grp, ...@@ -43,7 +43,7 @@ static int acpi_dma_parse_resource_group(const struct acpi_csrt_group *grp,
{ {
const struct acpi_csrt_shared_info *si; const struct acpi_csrt_shared_info *si;
struct list_head resource_list; struct list_head resource_list;
struct resource_list_entry *rentry; struct resource_entry *rentry;
resource_size_t mem = 0, irq = 0; resource_size_t mem = 0, irq = 0;
int ret; int ret;
...@@ -56,10 +56,10 @@ static int acpi_dma_parse_resource_group(const struct acpi_csrt_group *grp, ...@@ -56,10 +56,10 @@ static int acpi_dma_parse_resource_group(const struct acpi_csrt_group *grp,
return 0; return 0;
list_for_each_entry(rentry, &resource_list, node) { list_for_each_entry(rentry, &resource_list, node) {
if (resource_type(&rentry->res) == IORESOURCE_MEM) if (resource_type(rentry->res) == IORESOURCE_MEM)
mem = rentry->res.start; mem = rentry->res->start;
else if (resource_type(&rentry->res) == IORESOURCE_IRQ) else if (resource_type(rentry->res) == IORESOURCE_IRQ)
irq = rentry->res.start; irq = rentry->res->start;
} }
acpi_dev_free_resource_list(&resource_list); acpi_dev_free_resource_list(&resource_list);
......
...@@ -140,6 +140,7 @@ int of_pci_get_host_bridge_resources(struct device_node *dev, ...@@ -140,6 +140,7 @@ int of_pci_get_host_bridge_resources(struct device_node *dev,
unsigned char busno, unsigned char bus_max, unsigned char busno, unsigned char bus_max,
struct list_head *resources, resource_size_t *io_base) struct list_head *resources, resource_size_t *io_base)
{ {
struct resource_entry *window;
struct resource *res; struct resource *res;
struct resource *bus_range; struct resource *bus_range;
struct of_pci_range range; struct of_pci_range range;
...@@ -225,6 +226,8 @@ int of_pci_get_host_bridge_resources(struct device_node *dev, ...@@ -225,6 +226,8 @@ int of_pci_get_host_bridge_resources(struct device_node *dev,
conversion_failed: conversion_failed:
kfree(res); kfree(res);
parse_failed: parse_failed:
resource_list_for_each_entry(window, resources)
kfree(window->res);
pci_free_resource_list(resources); pci_free_resource_list(resources);
return err; return err;
} }
......
...@@ -20,17 +20,16 @@ ...@@ -20,17 +20,16 @@
void pci_add_resource_offset(struct list_head *resources, struct resource *res, void pci_add_resource_offset(struct list_head *resources, struct resource *res,
resource_size_t offset) resource_size_t offset)
{ {
struct pci_host_bridge_window *window; struct resource_entry *entry;
window = kzalloc(sizeof(struct pci_host_bridge_window), GFP_KERNEL); entry = resource_list_create_entry(res, 0);
if (!window) { if (!entry) {
printk(KERN_ERR "PCI: can't add host bridge window %pR\n", res); printk(KERN_ERR "PCI: can't add host bridge window %pR\n", res);
return; return;
} }
window->res = res; entry->offset = offset;
window->offset = offset; resource_list_add_tail(entry, resources);
list_add_tail(&window->list, resources);
} }
EXPORT_SYMBOL(pci_add_resource_offset); EXPORT_SYMBOL(pci_add_resource_offset);
...@@ -42,12 +41,7 @@ EXPORT_SYMBOL(pci_add_resource); ...@@ -42,12 +41,7 @@ EXPORT_SYMBOL(pci_add_resource);
void pci_free_resource_list(struct list_head *resources) void pci_free_resource_list(struct list_head *resources)
{ {
struct pci_host_bridge_window *window, *tmp; resource_list_free(resources);
list_for_each_entry_safe(window, tmp, resources, list) {
list_del(&window->list);
kfree(window);
}
} }
EXPORT_SYMBOL(pci_free_resource_list); EXPORT_SYMBOL(pci_free_resource_list);
......
...@@ -35,10 +35,10 @@ void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region, ...@@ -35,10 +35,10 @@ void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region,
struct resource *res) struct resource *res)
{ {
struct pci_host_bridge *bridge = find_pci_host_bridge(bus); struct pci_host_bridge *bridge = find_pci_host_bridge(bus);
struct pci_host_bridge_window *window; struct resource_entry *window;
resource_size_t offset = 0; resource_size_t offset = 0;
list_for_each_entry(window, &bridge->windows, list) { resource_list_for_each_entry(window, &bridge->windows) {
if (resource_contains(window->res, res)) { if (resource_contains(window->res, res)) {
offset = window->offset; offset = window->offset;
break; break;
...@@ -60,10 +60,10 @@ void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res, ...@@ -60,10 +60,10 @@ void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res,
struct pci_bus_region *region) struct pci_bus_region *region)
{ {
struct pci_host_bridge *bridge = find_pci_host_bridge(bus); struct pci_host_bridge *bridge = find_pci_host_bridge(bus);
struct pci_host_bridge_window *window; struct resource_entry *window;
resource_size_t offset = 0; resource_size_t offset = 0;
list_for_each_entry(window, &bridge->windows, list) { resource_list_for_each_entry(window, &bridge->windows) {
struct pci_bus_region bus_region; struct pci_bus_region bus_region;
if (resource_type(res) != resource_type(window->res)) if (resource_type(res) != resource_type(window->res))
......
...@@ -149,14 +149,14 @@ static int gen_pci_parse_request_of_pci_ranges(struct gen_pci *pci) ...@@ -149,14 +149,14 @@ static int gen_pci_parse_request_of_pci_ranges(struct gen_pci *pci)
struct device *dev = pci->host.dev.parent; struct device *dev = pci->host.dev.parent;
struct device_node *np = dev->of_node; struct device_node *np = dev->of_node;
resource_size_t iobase; resource_size_t iobase;
struct pci_host_bridge_window *win; struct resource_entry *win;
err = of_pci_get_host_bridge_resources(np, 0, 0xff, &pci->resources, err = of_pci_get_host_bridge_resources(np, 0, 0xff, &pci->resources,
&iobase); &iobase);
if (err) if (err)
return err; return err;
list_for_each_entry(win, &pci->resources, list) { resource_list_for_each_entry(win, &pci->resources) {
struct resource *parent, *res = win->res; struct resource *parent, *res = win->res;
switch (resource_type(res)) { switch (resource_type(res)) {
......
...@@ -401,11 +401,11 @@ static int xgene_pcie_map_ranges(struct xgene_pcie_port *port, ...@@ -401,11 +401,11 @@ static int xgene_pcie_map_ranges(struct xgene_pcie_port *port,
struct list_head *res, struct list_head *res,
resource_size_t io_base) resource_size_t io_base)
{ {
struct pci_host_bridge_window *window; struct resource_entry *window;
struct device *dev = port->dev; struct device *dev = port->dev;
int ret; int ret;
list_for_each_entry(window, res, list) { resource_list_for_each_entry(window, res) {
struct resource *res = window->res; struct resource *res = window->res;
u64 restype = resource_type(res); u64 restype = resource_type(res);
......
...@@ -737,7 +737,7 @@ static int xilinx_pcie_parse_and_add_res(struct xilinx_pcie_port *port) ...@@ -737,7 +737,7 @@ static int xilinx_pcie_parse_and_add_res(struct xilinx_pcie_port *port)
resource_size_t offset; resource_size_t offset;
struct of_pci_range_parser parser; struct of_pci_range_parser parser;
struct of_pci_range range; struct of_pci_range range;
struct pci_host_bridge_window *win; struct resource_entry *win;
int err = 0, mem_resno = 0; int err = 0, mem_resno = 0;
/* Get the ranges */ /* Get the ranges */
...@@ -807,7 +807,7 @@ static int xilinx_pcie_parse_and_add_res(struct xilinx_pcie_port *port) ...@@ -807,7 +807,7 @@ static int xilinx_pcie_parse_and_add_res(struct xilinx_pcie_port *port)
free_resources: free_resources:
release_child_resources(&iomem_resource); release_child_resources(&iomem_resource);
list_for_each_entry(win, &port->resources, list) resource_list_for_each_entry(win, &port->resources)
devm_kfree(dev, win->res); devm_kfree(dev, win->res);
pci_free_resource_list(&port->resources); pci_free_resource_list(&port->resources);
......
...@@ -1895,7 +1895,7 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus, ...@@ -1895,7 +1895,7 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
int error; int error;
struct pci_host_bridge *bridge; struct pci_host_bridge *bridge;
struct pci_bus *b, *b2; struct pci_bus *b, *b2;
struct pci_host_bridge_window *window, *n; struct resource_entry *window, *n;
struct resource *res; struct resource *res;
resource_size_t offset; resource_size_t offset;
char bus_addr[64]; char bus_addr[64];
...@@ -1959,8 +1959,8 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus, ...@@ -1959,8 +1959,8 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
printk(KERN_INFO "PCI host bridge to bus %s\n", dev_name(&b->dev)); printk(KERN_INFO "PCI host bridge to bus %s\n", dev_name(&b->dev));
/* Add initial resources to the bus */ /* Add initial resources to the bus */
list_for_each_entry_safe(window, n, resources, list) { resource_list_for_each_entry_safe(window, n, resources) {
list_move_tail(&window->list, &bridge->windows); list_move_tail(&window->node, &bridge->windows);
res = window->res; res = window->res;
offset = window->offset; offset = window->offset;
if (res->flags & IORESOURCE_BUS) if (res->flags & IORESOURCE_BUS)
...@@ -2060,12 +2060,12 @@ void pci_bus_release_busn_res(struct pci_bus *b) ...@@ -2060,12 +2060,12 @@ void pci_bus_release_busn_res(struct pci_bus *b)
struct pci_bus *pci_scan_root_bus(struct device *parent, int bus, struct pci_bus *pci_scan_root_bus(struct device *parent, int bus,
struct pci_ops *ops, void *sysdata, struct list_head *resources) struct pci_ops *ops, void *sysdata, struct list_head *resources)
{ {
struct pci_host_bridge_window *window; struct resource_entry *window;
bool found = false; bool found = false;
struct pci_bus *b; struct pci_bus *b;
int max; int max;
list_for_each_entry(window, resources, list) resource_list_for_each_entry(window, resources)
if (window->res->flags & IORESOURCE_BUS) { if (window->res->flags & IORESOURCE_BUS) {
found = true; found = true;
break; break;
......
...@@ -180,20 +180,21 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res, ...@@ -180,20 +180,21 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
struct pnp_dev *dev = data; struct pnp_dev *dev = data;
struct acpi_resource_dma *dma; struct acpi_resource_dma *dma;
struct acpi_resource_vendor_typed *vendor_typed; struct acpi_resource_vendor_typed *vendor_typed;
struct resource r = {0}; struct resource_win win = {{0}, 0};
struct resource *r = &win.res;
int i, flags; int i, flags;
if (acpi_dev_resource_address_space(res, &r) if (acpi_dev_resource_address_space(res, &win)
|| acpi_dev_resource_ext_address_space(res, &r)) { || acpi_dev_resource_ext_address_space(res, &win)) {
pnp_add_resource(dev, &r); pnp_add_resource(dev, &win.res);
return AE_OK; return AE_OK;
} }
r.flags = 0; r->flags = 0;
if (acpi_dev_resource_interrupt(res, 0, &r)) { if (acpi_dev_resource_interrupt(res, 0, r)) {
pnpacpi_add_irqresource(dev, &r); pnpacpi_add_irqresource(dev, r);
for (i = 1; acpi_dev_resource_interrupt(res, i, &r); i++) for (i = 1; acpi_dev_resource_interrupt(res, i, r); i++)
pnpacpi_add_irqresource(dev, &r); pnpacpi_add_irqresource(dev, r);
if (i > 1) { if (i > 1) {
/* /*
...@@ -209,7 +210,7 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res, ...@@ -209,7 +210,7 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
} }
} }
return AE_OK; return AE_OK;
} else if (r.flags & IORESOURCE_DISABLED) { } else if (r->flags & IORESOURCE_DISABLED) {
pnp_add_irq_resource(dev, 0, IORESOURCE_DISABLED); pnp_add_irq_resource(dev, 0, IORESOURCE_DISABLED);
return AE_OK; return AE_OK;
} }
...@@ -218,13 +219,13 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res, ...@@ -218,13 +219,13 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
case ACPI_RESOURCE_TYPE_MEMORY24: case ACPI_RESOURCE_TYPE_MEMORY24:
case ACPI_RESOURCE_TYPE_MEMORY32: case ACPI_RESOURCE_TYPE_MEMORY32:
case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
if (acpi_dev_resource_memory(res, &r)) if (acpi_dev_resource_memory(res, r))
pnp_add_resource(dev, &r); pnp_add_resource(dev, r);
break; break;
case ACPI_RESOURCE_TYPE_IO: case ACPI_RESOURCE_TYPE_IO:
case ACPI_RESOURCE_TYPE_FIXED_IO: case ACPI_RESOURCE_TYPE_FIXED_IO:
if (acpi_dev_resource_io(res, &r)) if (acpi_dev_resource_io(res, r))
pnp_add_resource(dev, &r); pnp_add_resource(dev, r);
break; break;
case ACPI_RESOURCE_TYPE_DMA: case ACPI_RESOURCE_TYPE_DMA:
dma = &res->data.dma; dma = &res->data.dma;
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/ioport.h> /* for struct resource */ #include <linux/ioport.h> /* for struct resource */
#include <linux/resource_ext.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/property.h> #include <linux/property.h>
...@@ -151,6 +152,10 @@ int acpi_map_cpu(acpi_handle handle, int physid, int *pcpu); ...@@ -151,6 +152,10 @@ int acpi_map_cpu(acpi_handle handle, int physid, int *pcpu);
int acpi_unmap_cpu(int cpu); int acpi_unmap_cpu(int cpu);
#endif /* CONFIG_ACPI_HOTPLUG_CPU */ #endif /* CONFIG_ACPI_HOTPLUG_CPU */
#ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
int acpi_get_ioapic_id(acpi_handle handle, u32 gsi_base, u64 *phys_addr);
#endif
int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base); int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base);
int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base); int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base);
int acpi_ioapic_registered(acpi_handle handle, u32 gsi_base); int acpi_ioapic_registered(acpi_handle handle, u32 gsi_base);
...@@ -288,22 +293,25 @@ extern int pnpacpi_disabled; ...@@ -288,22 +293,25 @@ extern int pnpacpi_disabled;
bool acpi_dev_resource_memory(struct acpi_resource *ares, struct resource *res); bool acpi_dev_resource_memory(struct acpi_resource *ares, struct resource *res);
bool acpi_dev_resource_io(struct acpi_resource *ares, struct resource *res); bool acpi_dev_resource_io(struct acpi_resource *ares, struct resource *res);
bool acpi_dev_resource_address_space(struct acpi_resource *ares, bool acpi_dev_resource_address_space(struct acpi_resource *ares,
struct resource *res); struct resource_win *win);
bool acpi_dev_resource_ext_address_space(struct acpi_resource *ares, bool acpi_dev_resource_ext_address_space(struct acpi_resource *ares,
struct resource *res); struct resource_win *win);
unsigned long acpi_dev_irq_flags(u8 triggering, u8 polarity, u8 shareable); unsigned long acpi_dev_irq_flags(u8 triggering, u8 polarity, u8 shareable);
bool acpi_dev_resource_interrupt(struct acpi_resource *ares, int index, bool acpi_dev_resource_interrupt(struct acpi_resource *ares, int index,
struct resource *res); struct resource *res);
struct resource_list_entry {
struct list_head node;
struct resource res;
};
void acpi_dev_free_resource_list(struct list_head *list); void acpi_dev_free_resource_list(struct list_head *list);
int acpi_dev_get_resources(struct acpi_device *adev, struct list_head *list, int acpi_dev_get_resources(struct acpi_device *adev, struct list_head *list,
int (*preproc)(struct acpi_resource *, void *), int (*preproc)(struct acpi_resource *, void *),
void *preproc_data); void *preproc_data);
int acpi_dev_filter_resource_type(struct acpi_resource *ares,
unsigned long types);
static inline int acpi_dev_filter_resource_type_cb(struct acpi_resource *ares,
void *arg)
{
return acpi_dev_filter_resource_type(ares, (unsigned long)arg);
}
int acpi_check_resource_conflict(const struct resource *res); int acpi_check_resource_conflict(const struct resource *res);
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <linux/atomic.h> #include <linux/atomic.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/resource_ext.h>
#include <uapi/linux/pci.h> #include <uapi/linux/pci.h>
#include <linux/pci_ids.h> #include <linux/pci_ids.h>
...@@ -397,16 +398,10 @@ static inline int pci_channel_offline(struct pci_dev *pdev) ...@@ -397,16 +398,10 @@ static inline int pci_channel_offline(struct pci_dev *pdev)
return (pdev->error_state != pci_channel_io_normal); return (pdev->error_state != pci_channel_io_normal);
} }
struct pci_host_bridge_window {
struct list_head list;
struct resource *res; /* host bridge aperture (CPU address) */
resource_size_t offset; /* bus address + offset = CPU address */
};
struct pci_host_bridge { struct pci_host_bridge {
struct device dev; struct device dev;
struct pci_bus *bus; /* root bus */ struct pci_bus *bus; /* root bus */
struct list_head windows; /* pci_host_bridge_windows */ struct list_head windows; /* resource_entry */
void (*release_fn)(struct pci_host_bridge *); void (*release_fn)(struct pci_host_bridge *);
void *release_data; void *release_data;
}; };
......
/*
* Copyright (C) 2015, Intel Corporation
* Author: Jiang Liu <jiang.liu@linux.intel.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*/
#ifndef _LINUX_RESOURCE_EXT_H
#define _LINUX_RESOURCE_EXT_H
#include <linux/types.h>
#include <linux/list.h>
#include <linux/ioport.h>
#include <linux/slab.h>
/* Represent resource window for bridge devices */
struct resource_win {
struct resource res; /* In master (CPU) address space */
resource_size_t offset; /* Translation offset for bridge */
};
/*
* Common resource list management data structure and interfaces to support
* ACPI, PNP and PCI host bridge etc.
*/
struct resource_entry {
struct list_head node;
struct resource *res; /* In master (CPU) address space */
resource_size_t offset; /* Translation offset for bridge */
struct resource __res; /* Default storage for res */
};
extern struct resource_entry *
resource_list_create_entry(struct resource *res, size_t extra_size);
extern void resource_list_free(struct list_head *head);
static inline void resource_list_add(struct resource_entry *entry,
struct list_head *head)
{
list_add(&entry->node, head);
}
static inline void resource_list_add_tail(struct resource_entry *entry,
struct list_head *head)
{
list_add_tail(&entry->node, head);
}
static inline void resource_list_del(struct resource_entry *entry)
{
list_del(&entry->node);
}
static inline void resource_list_free_entry(struct resource_entry *entry)
{
kfree(entry);
}
static inline void
resource_list_destroy_entry(struct resource_entry *entry)
{
resource_list_del(entry);
resource_list_free_entry(entry);
}
#define resource_list_for_each_entry(entry, list) \
list_for_each_entry((entry), (list), node)
#define resource_list_for_each_entry_safe(entry, tmp, list) \
list_for_each_entry_safe((entry), (tmp), (list), node)
#endif /* _LINUX_RESOURCE_EXT_H */
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/pfn.h> #include <linux/pfn.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/resource_ext.h>
#include <asm/io.h> #include <asm/io.h>
...@@ -1529,6 +1530,30 @@ int iomem_is_exclusive(u64 addr) ...@@ -1529,6 +1530,30 @@ int iomem_is_exclusive(u64 addr)
return err; return err;
} }
struct resource_entry *resource_list_create_entry(struct resource *res,
size_t extra_size)
{
struct resource_entry *entry;
entry = kzalloc(sizeof(*entry) + extra_size, GFP_KERNEL);
if (entry) {
INIT_LIST_HEAD(&entry->node);
entry->res = res ? res : &entry->__res;
}
return entry;
}
EXPORT_SYMBOL(resource_list_create_entry);
void resource_list_free(struct list_head *head)
{
struct resource_entry *entry, *tmp;
list_for_each_entry_safe(entry, tmp, head, node)
resource_list_destroy_entry(entry);
}
EXPORT_SYMBOL(resource_list_free);
static int __init strict_iomem(char *str) static int __init strict_iomem(char *str)
{ {
if (strstr(str, "relaxed")) if (strstr(str, "relaxed"))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment