acpi: implement Generic Event Device
Subsystems (2)
PATCH 1/1 acpi: implement Generic Event Device
Generic Event Device described in ACPI 6.1 allows platforms to handle platform interrupts in ACPI ASL statements. It borrows constructs like _EVT from GPIO events. All interrupts are listed in _CRS and the handler is written in _EVT method. Here is an example.
Device (GED0)
{
Name (_HID, "ACPI0013")
Name (_UID, 0)
Name(_CRS, ResourceTemplate ()
{
Interrupt(ResourceConsumer, Edge, ActiveHigh, Shared, , , )
{123}
})
Method (_EVT, 1) {
if (Lequal(123, Arg0))
{
}
}
}Wake capability has not been implemented yet.
--- drivers/acpi/Makefile | 1 + drivers/acpi/evged.c | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 drivers/acpi/evged.c
drivers/acpi/Makefile +1 -0
@@ -46,6 +46,7 @@ acpi-y += acpi_pnp.o acpi-y += int340x_thermal.o acpi-y += power.o acpi-y += event.o +acpi-$(CONFIG_ACPI_REDUCED_HARDWARE_ONLY) += evged.o acpi-y += sysfs.o acpi-y += property.o acpi-$(CONFIG_X86) += acpi_cmos_rtc.o
drivers/acpi/evged.c new file +162 -0
162 lines not on this page · raw message
Signature · 2 lines
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
kbuild test robot
build bot[PATCH] acpi: fix platform_no_drv_owner.cocci warnings
drivers/acpi/evged.c:152:3-8: No need to set .owner here. The core will do it.
drivers/acpi/evged.c:152:3-8: No need to set .owner here. The core will do it.
Remove .owner field if calls are used which set it automatically
Generated by: scripts/coccinelle/api/platform_no_drv_owner.cocci
---
evged.c | 1 - 1 file changed, 1 deletion(-)
drivers/acpi/evged.c +0 -1
@@ -149,7 +149,6 @@ static struct platform_driver ged_driver .probe = ged_probe, .driver = { .name = MODULE_NAME, - .owner = THIS_MODULE, .acpi_match_table = ACPI_PTR(ged_acpi_ids), }, };
kbuild test robot
build botcoccinelle warnings: (new ones prefixed by >>)
Hi Sinan,
[auto build test WARNING on pm/linux-next]
[also build test WARNING on v4.5-rc1 next-20160125]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
url: https://github.com/0day-ci/linux/commits/Sinan-Kaya/acpi-implement-Generic-Event-Device/20160126-053245 base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
coccinelle warnings: (new ones prefixed by >>)
>> drivers/acpi/evged.c:152:3-8: No need to set .owner here. The core will do it.
Please review and possibly fold the followup patch.
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
On Mon, Jan 25, 2016 at 11:29 PM, Sinan Kaya <[email protected]> wrote:
Few comments below.
Quoted 3 lines
Generic Event Device described in ACPI 6.1 allows platforms to handle platform interrupts in ACPI ASL statements. It borrows constructs like
_EVTfrom GPIO events.
Can it share code with gpiolib-acpi.c ? I see some duplication.
Quoted 59 lines
All interrupts are listed in
_CRSand the handler
is written in_EVTmethod. Here is an example.Device (GED0)
{Name (_HID, "ACPI0013") Name (_UID, 0) Name(_CRS, ResourceTemplate () { Interrupt(ResourceConsumer, Edge, ActiveHigh, Shared, , , ) {123} }) Method (_EVT, 1) { if (Lequal(123, Arg0)) { } } }Wake capability has not been implemented yet.
Signed-off-by Sinan Kaya <[email protected]>--- drivers/acpi/Makefile | 1 + drivers/acpi/evged.c | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 drivers/acpi/evged.cdrivers/acpi/Makefile +1
-0@@ -46,6 +46,7 @@ acpi-y += acpi_pnp.o acpi-y += int340x_thermal.o acpi-y += power.o acpi-y += event.o +acpi-$(CONFIG_ACPI_REDUCED_HARDWARE_ONLY) += evged.o acpi-y += sysfs.o acpi-y += property.o acpi-$(CONFIG_X86) += acpi_cmos_rtc.odrivers/acpi/evged.c new file +9
-0@@ -0,0 +1,162 @@ +/* +* Generic Event Device for ACPI. +* +* Copyright (c) 2016, The Linux Foundation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +*
drivers/acpi/evged.c line 19
Quoted 10 lines
drivers/acpi/evged.c new file +10
-0+* 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. +* +* Generic Event Device allows platforms to handle +* interrupts in ACPI ASL statements. It follows very similar +* _EVT method approach from GPIO events. +* All interrupts are listed in _CRS and the handler +* is written in _EVT method. Here is an example.
Can it be wider on screen?
Quoted 98 lines
drivers/acpi/evged.c new file +95
-0+* +* Device (GED0) +* { +* +* Name (_HID, "ACPI0013") +* Name (_UID, 0) +* Method (_CRS, 0x0, Serialized) +* { +* Name (RBUF, ResourceTemplate () +* { +* Interrupt(ResourceConsumer, Edge, ActiveHigh, Shared, , , ) +* {123} +* } +* }) +* +* Method (_EVT, 1) { +* if (Lequal(123, Arg0)) +* { +* } +* } +* } +* +*/ + +#include <linux/err.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/list.h> +#include <linux/platform_device.h> +#include <linux/acpi.h> + +#define MODULE_NAME "acpi-ged" + +struct acpi_ged_event { +struct list_head node; +struct device *dev; +unsigned int gsi; +unsigned int irq; +acpi_handle handle; +}; + +static irqreturn_t acpi_ged_irq_handler (int irq,void *data) +{ +struct acpi_ged_event *event = data; +acpi_status acpi_ret; + + acpi_ret =acpi_execute_simple_method (event->handle,NULL , event->gsi); +if (ACPI_FAILURE (acpi_ret)) +dev_err_once (event->dev,"IRQ method execution failed\n" ); + +return IRQ_HANDLED ; +} + +static acpi_status acpi_ged_request_interrupt (struct acpi_resource *ares, +void *context) +{ +struct acpi_ged_event *event; +unsigned int irq; +unsigned int gsi; +unsigned int irqflags =IRQF_ONESHOT ; +struct device *dev = context; +acpi_handle handle =ACPI_HANDLE (dev); +acpi_handle evt_handle; +struct resource r; +struct acpi_resource_irq *p = &ares->data.irq; +struct acpi_resource_extended_irq *pext = &ares->data.extended_irq; + +if (ares->type ==ACPI_RESOURCE_TYPE_END_TAG ) +return AE_OK ; + +if (!acpi_dev_resource_interrupt (ares,0 , &r)) { +dev_err (dev,"unable to parse IRQ resource\n" ); +return AE_ERROR ; + } +if (ares->type ==ACPI_RESOURCE_TYPE_IRQ ) + gsi = p->interrupts[0 ]; +else + gsi = pext->interrupts[0 ]; + + irq = r.start; + +if (ACPI_FAILURE (acpi_get_handle (handle,"_EVT" , &evt_handle))) { +dev_err (dev,"cannot locate _EVT method\n" ); +return AE_ERROR ; + } + +dev_info (dev,"GED listening GSI %u @ IRQ %u\n" , gsi, irq); + + event =devm_kzalloc (dev,sizeof (*event),GFP_KERNEL ); +if (!event) +return AE_ERROR ; + + event->gsi = gsi; + event->dev = dev; + event->irq = irq;
drivers/acpi/evged.c line 124
Quoted 10 lines
drivers/acpi/evged.c new file +10
-0+ event->handle = evt_handle; + +if (r.flags &IORESOURCE_IRQ_SHAREABLE ) + irqflags |=IRQF_SHARED ; + +if (devm_request_threaded_irq (dev, irq,NULL , acpi_ged_irq_handler, + irqflags,"ACPI:Ged" , event)) { +dev_err (dev,"failed to setup event handler for irq %u\n" , irq); +return AE_ERROR ; + }
The above part is clearly belongs to ged_probe().
Quoted 19 lines
drivers/acpi/evged.c new file +19
-0+ +return AE_OK ; +} + +static int ged_probe (struct platform_device *pdev) +{ +acpi_status acpi_ret; + + acpi_ret =acpi_walk_resources (ACPI_HANDLE (&pdev->dev),"_CRS" , + acpi_ged_request_interrupt, &pdev->dev); +if (ACPI_FAILURE (acpi_ret)) { +dev_err (&pdev->dev,"unable to parse the _CRS record\n" ); +return -EINVAL ; + } + +return 0 ; +} + +static const struct acpi_device_id ged_acpi_ids[] = {
drivers/acpi/evged.c line 152
Quoted 10 lines
drivers/acpi/evged.c new file +9
-0+ {"ACPI0013"}, + {}, +}; + +static struct platform_driver ged_driver = { + .probe = ged_probe, + .driver = { + .name = MODULE_NAME, + .owner = THIS_MODULE,
Do you need this one?
drivers/acpi/evged.c line 162
Quoted 11 lines
drivers/acpi/evged.c new file +10
-0+ .acpi_match_table = ACPI_PTR(ged_acpi_ids), + }, +}; + +static int __init ged_init (void ) +{ +return platform_driver_register (&ged_driver); +} + +subsys_initcall (ged_init);
Any specific reason to have on that level?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 9 lines · Andy Shevchenko
On Mon, Jan 25, 2016 at 11:29 PM, Sinan Kaya <[email protected]> wrote:
Few comments below.
Quoted 3 lines
Generic Event Device described in ACPI 6.1 allows platforms to handle platform interrupts in ACPI ASL statements. It borrows constructs like
_EVTfrom GPIO events.Can it share code with
gpiolib-acpi.c? I see some duplication.
The interrupt registration mechanism could be made common but they have their own data structure types.
Can Rafael think of any higher level API like acpi_dev_resource_interrupt below?
Quoted 64 lines
Quoted 64 lines
All interrupts are listed in
_CRSand the handler
is written in_EVTmethod. Here is an example.Device (GED0)
{Name (_HID, "ACPI0013") Name (_UID, 0) Name(_CRS, ResourceTemplate () { Interrupt(ResourceConsumer, Edge, ActiveHigh, Shared, , , ) {123} }) Method (_EVT, 1) { if (Lequal(123, Arg0)) { } } }Wake capability has not been implemented yet.
Signed-off-by Sinan Kaya <[email protected]>--- drivers/acpi/Makefile | 1 + drivers/acpi/evged.c | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 drivers/acpi/evged.cdrivers/acpi/Makefile +1
-0@@ -46,6 +46,7 @@ acpi-y += acpi_pnp.o acpi-y += int340x_thermal.o acpi-y += power.o acpi-y += event.o +acpi-$(CONFIG_ACPI_REDUCED_HARDWARE_ONLY) += evged.o acpi-y += sysfs.o acpi-y += property.o acpi-$(CONFIG_X86) += acpi_cmos_rtc.odrivers/acpi/evged.c new file +13
-0@@ -0,0 +1,162 @@ +/* +* Generic Event Device for ACPI. +* +* Copyright (c) 2016, The Linux Foundation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* 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.
Quoted 9 lines
drivers/acpi/evged.c line 19
Quoted 6 lines
drivers/acpi/evged.c new file +6
-0+* +* Generic Event Device allows platforms to handle +* interrupts in ACPI ASL statements. It follows very similar +* _EVT method approach from GPIO events. +* All interrupts are listed in _CRS and the handler +* is written in _EVT method. Here is an example. Can it be wider on screen?
sure
Quoted 13 lines
Quoted 13 lines
drivers/acpi/evged.c new file +12
-0+ + event =devm_kzalloc (dev,sizeof (*event),GFP_KERNEL ); +if (!event) +return AE_ERROR ; + + event->gsi = gsi; + event->dev = dev; + event->irq = irq; + event->handle = evt_handle; + +if (r.flags &IORESOURCE_IRQ_SHAREABLE ) + irqflags |=IRQF_SHARED ;
Quoted 9 lines
drivers/acpi/evged.c line 124
Quoted 6 lines
drivers/acpi/evged.c new file +6
-0+ +if (devm_request_threaded_irq (dev, irq,NULL , acpi_ged_irq_handler, + irqflags,"ACPI:Ged" , event)) { +dev_err (dev,"failed to setup event handler for irq %u\n" , irq); +return AE_ERROR ; + }The above part is clearly belongs to
ged_probe().
It depends. The implementation needs to find all the interrupt entries in _CRS. That's why, the interrupt registration is done inside the ACPI callback.
I originally tried using the platform_get_irq() method rather than walking the ACPI resources. Any resource listed in _CRS is accessible via standard platform API. However, I couldn't obtain the shareability and other edge/level attributes through the standard APIs. Most drivers I have seen hardcode this information when calling devm_request_threaded_irq function.
Here, the type of interrupt is declared in the ACPI and the registration is done based on passed attributes.
Quoted 28 lines
Quoted 27 lines
drivers/acpi/evged.c new file +27
-0+ +return AE_OK ; +} + +static int ged_probe (struct platform_device *pdev) +{ +acpi_status acpi_ret; + + acpi_ret =acpi_walk_resources (ACPI_HANDLE (&pdev->dev),"_CRS" , + acpi_ged_request_interrupt, &pdev->dev); +if (ACPI_FAILURE (acpi_ret)) { +dev_err (&pdev->dev,"unable to parse the _CRS record\n" ); +return -EINVAL ; + } + +return 0 ; +} + +static const struct acpi_device_id ged_acpi_ids[] = { + {"ACPI0013" }, + {}, +}; + +static struct platform_driver ged_driver = { + .probe = ged_probe, + .driver = { + .name =MODULE_NAME ,
Quoted 3 lines
drivers/acpi/evged.c line 152
Quoted 1 line
drivers/acpi/evged.c new file +1
-0+ .owner = THIS_MODULE,Do you need this one?
I'll get rid of it.
Quoted 12 lines
Quoted 11 lines
drivers/acpi/evged.c new file +9
-0+ .acpi_match_table = ACPI_PTR(ged_acpi_ids), + }, +}; + +static int __init ged_init (void ) +{ +return platform_driver_register (&ged_driver); +} +
Quoted 4 lines
drivers/acpi/evged.c line 162
Quoted 1 line
drivers/acpi/evged.c new file +1
-0+subsys_initcall (ged_init);Any specific reason to have on that level?
changed to module_platform_driver(ged_driver);
Signature · 3 lines
Sinan Kaya Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project