Re: [patch 4/4] acpi: ioapic: Respect the resource flags

From: Yinghai Lu
Date: Thu Dec 11 2014 - 21:45:07 EST


On Thu, Dec 11, 2014 at 11:48 AM, Thomas Gleixner <tglx@xxxxxxxxxxxxx> wrote:
> The acpi parser can set the DISABLED flag on a resource. In
> setup_res() we clear all flags except MEM, so we ignore the DISABLED
> flag. Add proper checks and preserve the flags.
>
> Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> ---
> drivers/acpi/ioapic.c | 38 +++++++++++++++++++++-----------------
> 1 file changed, 21 insertions(+), 17 deletions(-)
>
> Index: tip/drivers/acpi/ioapic.c
> ===================================================================
> --- tip.orig/drivers/acpi/ioapic.c
> +++ tip/drivers/acpi/ioapic.c
> @@ -40,29 +40,33 @@ struct acpi_pci_ioapic {
> static LIST_HEAD(ioapic_list);
> static DEFINE_MUTEX(ioapic_list_lock);
>
> +static inline bool is_valid_mem_resource(struct resource *res)
> +{
> + return !(res->flags & IORESOURCE_DISABLED) &&
> + (res->flags & IORESOURCE_MEM);
> +}
> +
> static acpi_status setup_res(struct acpi_resource *acpi_res, void *data)
> {
> + struct acpi_resource_address64 addr;
> struct resource *res = data;
>
> memset(res, 0, sizeof(*res));
> - if (acpi_dev_resource_memory(acpi_res, res)) {
> - res->flags &= IORESOURCE_MEM;
> - if (res->flags)
> - return AE_OK;
> - } else if (acpi_dev_resource_address_space(acpi_res, res)) {
> - struct acpi_resource_address64 addr;
> + if (acpi_dev_resource_memory(acpi_res, res))
> + return AE_OK;
>
> - res->flags &= IORESOURCE_MEM;
> - if (res->flags &&
> - ACPI_SUCCESS(acpi_resource_to_address64(acpi_res, &addr)) &&
> - addr.info.mem.caching != ACPI_PREFETCHABLE_MEMORY) {
> - res->start += addr.translation_offset;
> - res->end += addr.translation_offset;
> - return AE_OK;
> - }
> + if (!acpi_dev_resource_address_space(acpi_res, res) ||
> + !is_valid_mem_resource(res))
> + return AE_OK;
> + /*
> + * FIXME: This lacks a proper comment, why the resource
> + * address needs to be translated.
> + */
> + if (ACPI_SUCCESS(acpi_resource_to_address64(acpi_res, &addr)) &&
> + addr.info.mem.caching != ACPI_PREFETCHABLE_MEMORY) {
> + res->start += addr.translation_offset;
> + res->end += addr.translation_offset;
> }
> - res->flags = 0;
> -
> return AE_OK;
> }
>
> @@ -150,7 +154,7 @@ static acpi_status handle_ioapic_add(acp
>
> res = &ioapic->res;
> acpi_walk_resources(handle, METHOD_NAME__CRS, setup_res, res);
> - if (res->flags == IORESOURCE_UNSET) {
> + if (!is_valid_mem_resource(res)) {
> acpi_handle_warn(handle, "failed to get resource\n");
> goto exit_free;
> } else if (request_resource(&iomem_resource, res)) {
>
>

There is minor problem about mem pref handling, original code will ignore them.

with this patch will let it follow through.

should change is_valid_mem_resource to is_valid_mem_nonpref_resource()...

+static inline bool is_valid_mem_nonpref_resource(struct resource *res)
{
return !(res->flags & IORESOURCE_DISABLED) &&
- (res->flags & IORESOURCE_MEM);
+ (res->flags & IORESOURCE_MEM) &&
+ !(res->flags & IORESOURCE_PREFETCH);
}


other than that for whole patch set:
Acked-by: Yinghai Lu <yinghai@xxxxxxxxxx>

Also please check attached following patch that will move code to acpi core.

Thanks

Yinghai
Subject: [PATCH] x86, PCI, ACPI: offset resource in acpi core

Also pass back via offset for pci root bus resource probing.

and set IORESOURCE_PREFETCH...

Signed-off-by: Yinghai Lu <yinghai@xxxxxxxxxx>

---
arch/x86/pci/acpi.c | 29 ++++++-----------------------
drivers/acpi/ioapic.c | 22 ++++++----------------
drivers/acpi/resource.c | 16 +++++++++++-----
drivers/pnp/pnpacpi/rsparser.c | 2 +-
include/linux/acpi.h | 2 +-
5 files changed, 25 insertions(+), 46 deletions(-)

Index: linux-2.6/arch/x86/pci/acpi.c
===================================================================
--- linux-2.6.orig/arch/x86/pci/acpi.c
+++ linux-2.6/arch/x86/pci/acpi.c
@@ -231,7 +231,7 @@ static acpi_status count_resource(struct

memset(&r, 0, sizeof(r));
if (!acpi_dev_resource_memory(acpi_res, &r) &&
- !acpi_dev_resource_address_space(acpi_res, &r))
+ !acpi_dev_resource_address_space(acpi_res, &r, NULL))
return AE_OK;

if (is_valid_resource(&r))
@@ -273,30 +273,13 @@ static bool valid_resource_range(struct
static acpi_status setup_resource(struct acpi_resource *acpi_res, void *data)
{
struct pci_root_info *info = data;
- u64 translation_offset = 0;
+ u64 offset = 0;
struct resource r;

memset(&r, 0, sizeof(r));
- if (!acpi_dev_resource_memory(acpi_res, &r)) {
- struct acpi_resource_address64 addr;
-
- if (!acpi_dev_resource_address_space(acpi_res, &r))
- return AE_OK;
-
- if (ACPI_FAILURE(acpi_resource_to_address64(acpi_res, &addr)))
- return AE_OK;
-
- if (!addr.address_length)
- return AE_OK;
-
- if (addr.resource_type == ACPI_MEMORY_RANGE &&
- addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY)
- r.flags |= IORESOURCE_PREFETCH;
-
- translation_offset = addr.translation_offset;
- r.start += translation_offset;
- r.end += translation_offset;
- }
+ if (!acpi_dev_resource_memory(acpi_res, &r) &&
+ !acpi_dev_resource_address_space(acpi_res, &r, &offset))
+ return AE_OK;

if (!is_valid_resource(&r) ||
!valid_resource_range(&r, &info->bridge->dev))
@@ -304,7 +287,7 @@ static acpi_status setup_resource(struct

r.name = info->name;
info->res[info->res_num] = r;
- info->res_offset[info->res_num] = translation_offset;
+ info->res_offset[info->res_num] = offset;
info->res_num++;
if (!pci_use_crs)
dev_printk(KERN_DEBUG, &info->bridge->dev,
Index: linux-2.6/drivers/acpi/ioapic.c
===================================================================
--- linux-2.6.orig/drivers/acpi/ioapic.c
+++ linux-2.6/drivers/acpi/ioapic.c
@@ -40,33 +40,23 @@ struct acpi_pci_ioapic {
static LIST_HEAD(ioapic_list);
static DEFINE_MUTEX(ioapic_list_lock);

-static inline bool is_valid_mem_resource(struct resource *res)
+static inline bool is_valid_mem_nonpref_resource(struct resource *res)
{
return !(res->flags & IORESOURCE_DISABLED) &&
- (res->flags & IORESOURCE_MEM);
+ (res->flags & IORESOURCE_MEM) &&
+ !(res->flags & IORESOURCE_PREFETCH);
}

static acpi_status setup_res(struct acpi_resource *acpi_res, void *data)
{
- struct acpi_resource_address64 addr;
struct resource *res = data;

memset(res, 0, sizeof(*res));
if (acpi_dev_resource_memory(acpi_res, res))
return AE_OK;

- if (!acpi_dev_resource_address_space(acpi_res, res) ||
- !is_valid_mem_resource(res))
- return AE_OK;
- /*
- * FIXME: This lacks a proper comment, why the resource
- * address needs to be translated.
- */
- if (ACPI_SUCCESS(acpi_resource_to_address64(acpi_res, &addr)) &&
- addr.info.mem.caching != ACPI_PREFETCHABLE_MEMORY) {
- res->start += addr.translation_offset;
- res->end += addr.translation_offset;
- }
+ acpi_dev_resource_address_space(acpi_res, res, NULL);
+
return AE_OK;
}

@@ -154,7 +144,7 @@ static acpi_status handle_ioapic_add(acp

res = &ioapic->res;
acpi_walk_resources(handle, METHOD_NAME__CRS, setup_res, res);
- if (!is_valid_mem_resource(res)) {
+ if (!is_valid_mem_nonpref_resource(res)) {
acpi_handle_warn(handle, "failed to get resource\n");
goto exit_free;
} else if (request_resource(&iomem_resource, res)) {
Index: linux-2.6/drivers/acpi/resource.c
===================================================================
--- linux-2.6.orig/drivers/acpi/resource.c
+++ linux-2.6/drivers/acpi/resource.c
@@ -175,13 +175,14 @@ EXPORT_SYMBOL_GPL(acpi_dev_resource_io);
* acpi_dev_resource_address_space - Extract ACPI address space information.
* @ares: Input ACPI resource object.
* @res: Output generic resource object.
+ * @offset: Output for translation_offset.
*
* Check if the given ACPI resource object represents an address space resource
* and if that's the case, use the information in it to populate the generic
* resource object pointed to by @res.
*/
bool acpi_dev_resource_address_space(struct acpi_resource *ares,
- struct resource *res)
+ struct resource *res, u64 *offset)
{
acpi_status status;
struct acpi_resource_address64 addr;
@@ -199,12 +200,14 @@ bool acpi_dev_resource_address_space(str
}

status = acpi_resource_to_address64(ares, &addr);
- if (ACPI_FAILURE(status))
+ if (ACPI_FAILURE(status) || !addr.address_length)
return false;

- res->start = addr.minimum;
- res->end = addr.maximum;
+ res->start = addr.minimum + addr.translation_offset;
+ res->end = addr.maximum + addr.translation_offset;
window = addr.producer_consumer == ACPI_PRODUCER;
+ if (offset)
+ *offset = addr.translation_offset;

switch(addr.resource_type) {
case ACPI_MEMORY_RANGE:
@@ -212,6 +215,9 @@ bool acpi_dev_resource_address_space(str
res->flags = acpi_dev_memresource_flags(len,
addr.info.mem.write_protect,
window);
+ if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY)
+ res->flags |= IORESOURCE_PREFETCH;
+
break;
case ACPI_IO_RANGE:
io_decode = addr.granularity == 0xfff ?
@@ -471,7 +477,7 @@ static acpi_status acpi_dev_process_reso

if (acpi_dev_resource_memory(ares, &r)
|| acpi_dev_resource_io(ares, &r)
- || acpi_dev_resource_address_space(ares, &r)
+ || acpi_dev_resource_address_space(ares, &r, NULL)
|| acpi_dev_resource_ext_address_space(ares, &r))
return acpi_dev_new_resource_entry(&r, c);

Index: linux-2.6/drivers/pnp/pnpacpi/rsparser.c
===================================================================
--- linux-2.6.orig/drivers/pnp/pnpacpi/rsparser.c
+++ linux-2.6/drivers/pnp/pnpacpi/rsparser.c
@@ -183,7 +183,7 @@ static acpi_status pnpacpi_allocated_res
struct resource r = {0};
int i, flags;

- if (acpi_dev_resource_address_space(res, &r)
+ if (acpi_dev_resource_address_space(res, &r, NULL)
|| acpi_dev_resource_ext_address_space(res, &r)) {
pnp_add_resource(dev, &r);
return AE_OK;
Index: linux-2.6/include/linux/acpi.h
===================================================================
--- linux-2.6.orig/include/linux/acpi.h
+++ linux-2.6/include/linux/acpi.h
@@ -292,7 +292,7 @@ extern int pnpacpi_disabled;
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_address_space(struct acpi_resource *ares,
- struct resource *res);
+ struct resource *res, u64 *offset);
bool acpi_dev_resource_ext_address_space(struct acpi_resource *ares,
struct resource *res);
unsigned long acpi_dev_irq_flags(u8 triggering, u8 polarity, u8 shareable);