ACPI: introduce acpi_get_generic_resources
RFC PATCH 3/6 ACPI: introduce acpi_get_generic_resources
Quoted 1 line
From
9a851d177794129a89f720c7122cb39fd163126bMon Sep 17 00:00:00 2001
From: Zhang Rui <[email protected]>
Date: Fri, 28 Sep 2012 08:34:05 +0800
Subject: [RFC PATCH 3/6] ACPI: introduce acpi_get_generic_resources
Introduce acpi_get_generic_resources() to convert
ACPI style resources to struct resource.
--- drivers/acpi/Makefile | 1 + drivers/acpi/resource.c | 165 +++++++++++++++++++++++++++++++++++++++++++++++ include/acpi/acpi_bus.h | 1 + 3 files changed, 167 insertions(+), 0 deletions(-) create mode 100644 drivers/acpi/resource.c
drivers/acpi/Makefile +1 -0
@@ -46,6 +46,7 @@ acpi-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o ifdef CONFIG_ACPI_VIDEO acpi-y += video_detect.o endif +acpi-y += resource.o # These are (potentially) separate modules obj-$(CONFIG_ACPI_AC) += ac.o
drivers/acpi/resource.c new file +165 -0
165 lines not on this page · raw message
include/acpi/acpi_bus.h +1 -0
@@ -381,6 +381,7 @@ int acpi_match_device_ids(struct acpi_device *device,int acpi_match_device_id (const struct device *,const char *);int acpi_create_dir (struct acpi_device *);void acpi_remove_dir (struct acpi_device *); +int acpi_get_generic_resources (struct acpi_device *,struct resource **);/* * Bind physical devices with ACPI devices
Signature · 1 line
1.7.7.6
Quoted 7 lines · Zhang Rui
From
9a851d177794129a89f720c7122cb39fd163126bMon Sep 17 00:00:00 2001
From: Zhang Rui <[email protected]>
Date: Fri, 28 Sep 2012 08:34:05 +0800
Subject: [RFC PATCH 3/6] ACPI: introduceacpi_get_generic_resourcesIntroduce
acpi_get_generic_resources()to convert
ACPI style resources to struct resource.
This seems obviously similar to drivers/pnp/pnpacpi/rsparser.c, but only handles a few of the resource types. Do you plan to extend this to support everything rsparser.c supports? Do you envision replacing the current PNPACPI/PNPBIOS/ISAPNP stuff with something built on what you're doing here? We already have two ways for drivers to bind to ACPI devices (pnp_register_driver() and acpi_bus_register_driver()). I hope we are moving toward *one* way rather than three ways :)
Quoted 212 lines
Signed-off-by Zhang Rui <[email protected]>--- drivers/acpi/Makefile | 1 + drivers/acpi/resource.c | 165 +++++++++++++++++++++++++++++++++++++++++++++++ include/acpi/acpi_bus.h | 1 + 3 files changed, 167 insertions(+), 0 deletions(-) create mode 100644 drivers/acpi/resource.cdrivers/acpi/Makefile +1
-0@@ -46,6 +46,7 @@ acpi-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o ifdef CONFIG_ACPI_VIDEO acpi-y += video_detect.o endif +acpi-y += resource.o # These are (potentially) separate modules obj-$(CONFIG_ACPI_AC) += ac.odrivers/acpi/resource.c new file +165
-0@@ -0,0 +1,165 @@ +/* +* resource.c -- convert ACPI resource to generic resource +* +* Copyright (c) 2012 Zhang Rui <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2. +* +* This program is distributed in the hope that 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. +* +*/ +#include <linux/kernel.h> +#include <linux/export.h> +#include <linux/acpi.h> + +static int irq_flags (int triggering,int polarity,int sharable) +{ +int flags; + +if (triggering ==ACPI_LEVEL_SENSITIVE ) { +if (polarity ==ACPI_ACTIVE_LOW ) + flags =IORESOURCE_IRQ_LOWLEVEL ; +else + flags =IORESOURCE_IRQ_HIGHLEVEL ; + }else { +if (polarity ==ACPI_ACTIVE_LOW ) + flags =IORESOURCE_IRQ_LOWEDGE ; +else + flags =IORESOURCE_IRQ_HIGHEDGE ; + } + +if (sharable ==ACPI_SHARED ) + flags |=IORESOURCE_IRQ_SHAREABLE ; + +return flags; +} + +static void acpi_get_irq_resource (struct acpi_resource *res, +struct resource *resource) +{ +struct acpi_resource_irq *irq = &res->data.irq; +int t, p; + +if (irq->interrupt_count ==0 ) + resource->flags =IORESOURCE_DISABLED ; + +if (!acpi_get_override_irq (irq->interrupts[0 ], &t, &p)) { + t = t ?ACPI_LEVEL_SENSITIVE :ACPI_EDGE_SENSITIVE ; + p = p ?ACPI_ACTIVE_LOW :ACPI_ACTIVE_HIGH ; + +if (irq->triggering != t || irq->polarity != p) { + irq->triggering = t; + irq->polarity = p; + } + } + + resource->flags = +irq_flags (irq->triggering, irq->polarity, irq->sharable); + resource->flags |=IORESOURCE_IRQ ; + resource->start = irq->interrupts[0 ]; + resource->end = irq->interrupts[0 ]; +} + +static void acpi_get_extended_irq_resource (struct acpi_resource *res, +struct resource *resource) +{ +struct acpi_resource_extended_irq *irq = &res->data.extended_irq; +int t, p; + +if (irq->interrupt_count ==0 ) + resource->flags =IORESOURCE_DISABLED ; + +if (!acpi_get_override_irq (irq->interrupts[0 ], &t, &p)) { + t = t ?ACPI_LEVEL_SENSITIVE :ACPI_EDGE_SENSITIVE ; + p = p ?ACPI_ACTIVE_LOW :ACPI_ACTIVE_HIGH ; + +if (irq->triggering != t || irq->polarity != p) { + irq->triggering = t; + irq->polarity = p; + } + } + + resource->flags = +irq_flags (irq->triggering, irq->polarity, irq->sharable); + resource->flags |=IORESOURCE_IRQ ; + resource->start = irq->interrupts[0 ]; + resource->end = irq->interrupts[0 ]; +} + +static void acpi_get_mem_resource (struct acpi_resource *res, +struct resource *resource) +{ +struct acpi_resource_fixed_memory32 *mem = &res->data.fixed_memory32; + +if (mem->address_length ==0 ) + resource->flags |=IORESOURCE_DISABLED ; +if (mem->write_protect ==ACPI_READ_WRITE_MEMORY ) + resource->flags |=IORESOURCE_MEM_WRITEABLE ; + + resource->flags |=IORESOURCE_MEM ; + resource->start = mem->address; + resource->end = mem->address + mem->address_length -1 ; +} + +int acpi_get_generic_resources (struct acpi_device *device, +struct resource **resources) +{ +acpi_status status; +struct acpi_buffer buffer; +struct acpi_resource *res; +struct resource *p; +int res_count; +int i; + + status =acpi_get_current_resources (device->handle, &buffer); +if (ACPI_FAILURE (status)) { +dev_err (&device->dev,"can't get ACPI resources\n" ); +return -EINVAL ; + } + + res_count = (buffer.length -1 ) /sizeof (struct acpi_resource ) -1 ; + p =kzalloc (sizeof (struct resource ) * res_count,GFP_KERNEL ); +if (!resources) { +kfree (buffer.pointer); +return -ENOMEM ; + } + + res = (struct acpi_resource *)buffer.pointer; + i =0 ; + +while (res->type !=ACPI_RESOURCE_TYPE_END_TAG ) { + +switch (res->type) { +case ACPI_RESOURCE_TYPE_IRQ : +acpi_get_irq_resource (res, &p[i]); +break ; +case ACPI_RESOURCE_TYPE_EXTENDED_IRQ : +acpi_get_extended_irq_resource (res, &p[i]); +break ; +case ACPI_RESOURCE_TYPE_MEMORY32 : +acpi_get_mem_resource (res, &p[i]); +break ; +default : + i--; +break ; + } + i++; + res =ACPI_NEXT_RESOURCE (res); + } + +/* Get rid of unsupported ACPI resources */ +if (i != res_count) + p = +kmemdup (p,sizeof (struct resource ) * i,GFP_KERNEL ); + + *resources = p; +kfree (buffer.pointer); +return i; +} + +EXPORT_SYMBOL (acpi_get_generic_resources);include/acpi/acpi_bus.h +1
-1@@ -381,6 +381,7 @@ int acpi_match_device_ids(struct acpi_device *device,int acpi_match_device_id (const struct device *,const char *);int acpi_create_dir (struct acpi_device *);void acpi_remove_dir (struct acpi_device *); +int acpi_get_generic_resources (struct acpi_device *,struct resource **);/* * Bind physical devices with ACPI devices -- 1.7.7.6
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html