Re: [PATCH V4 1/2] ACPI: Add support for ResourceSource/IRQ domain mapping
Just a few nits: Agustin Vega-Frias wrote: +int acpi_irq_domain_register_irq(struct acpi_resource_source *source, u32 hwirq, +int trigger, int polarity) +{ + struct irq_fwspec fwspec; + struct acpi_device *device; + acpi_handle handle; + acpi_status status; + int ret; + + if (source->string_length == 0) Would (!source->string_length) be more meaningful? + return acpi_register_gsi(NULL, hwirq, trigger, polarity); + + status = acpi_get_handle(NULL, source->string_ptr, &handle); + if (ACPI_FAILURE(status)) + return -ENODEV; + + device = acpi_bus_get_acpi_device(handle); + if (!device) + return -ENODEV; + + if (acpi_irq_domain_ensure_probed(device)) + return -ENODEV; + + fwspec.fwnode = &device->fwnode; + fwspec.param[0] = hwirq; + fwspec.param[1] = acpi_dev_get_irq_type(trigger, polarity); + fwspec.param_count = 2; + + ret = irq_create_fwspec_mapping(&fwspec); + acpi_bus_put_acpi_device(device); + return ret; Blank line before 'return'. -static void acpi_dev_get_irqresource(struct resource *res, u32 gsi, +static void acpi_dev_get_irqresource(struct resource *res, u32 hwirq, +struct acpi_resource_source *source, This should probably be a 'const', because ... @@ -448,6 +449,7 @@ bool acpi_dev_resource_interrupt(struct acpi_resource *ares, int index, { struct acpi_resource_irq *irq; struct acpi_resource_extended_irq *ext_irq; + struct acpi_resource_source dummy = { 0, 0, NULL }; ... then you can make this a static const, which will reduce code size and improve performance. @@ -1024,6 +1030,43 @@ struct acpi_probe_entry { (&ACPI_PROBE_TABLE_END(t) - \ &ACPI_PROBE_TABLE(t))); \ }) + +#define ACPI_HID_LEN 9 Please add a comment for this. -- Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
[PATCH V4 1/2] ACPI: Add support for ResourceSource/IRQ domain mapping
This allows irqchip drivers to associate an ACPI DSDT device to an IRQ domain and provides support for using the ResourceSource in Extended IRQ Resources to find the domain and map the IRQs specified on that domain. Signed-off-by: Agustin Vega-Frias --- drivers/acpi/Makefile | 1 + drivers/acpi/irqdomain.c | 135 ++ drivers/acpi/resource.c | 21 +++--- include/asm-generic/vmlinux.lds.h | 1 + include/linux/acpi.h | 50 ++ include/linux/irqchip.h | 17 - 6 files changed, 213 insertions(+), 12 deletions(-) create mode 100644 drivers/acpi/irqdomain.c diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 9ed0878..81bdc95 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -57,6 +57,7 @@ acpi-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o acpi-y += acpi_lpat.o acpi-$(CONFIG_ACPI_GENERIC_GSI) += gsi.o acpi-$(CONFIG_ACPI_WATCHDOG) += acpi_watchdog.o +acpi-y += irqdomain.o # These are (potentially) separate modules diff --git a/drivers/acpi/irqdomain.c b/drivers/acpi/irqdomain.c new file mode 100644 index 000..0429607 --- /dev/null +++ b/drivers/acpi/irqdomain.c @@ -0,0 +1,135 @@ +/* + * ACPI ResourceSource/IRQ domain mapping support + * + * 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. + */ +#include +#include +#include + +/** + * acpi_irq_domain_ensure_probed() - Check if the device has registered + * an IRQ domain and probe as necessary + * + * @device: Device to check and probe + * + * Returns: 0 on success, -ENODEV otherwise + */ +static int acpi_irq_domain_ensure_probed(struct acpi_device *device) +{ + struct acpi_dsdt_probe_entry *entry; + + if (irq_find_matching_fwnode(&device->fwnode, DOMAIN_BUS_ANY) != 0) + return 0; + + for (entry = &__dsdt_acpi_probe_table; +entry < &__dsdt_acpi_probe_table_end; e++) + if (strcmp(e->_hid, acpi_device_hid(device)) == 0) + return e->probe(device); + + return -ENODEV; +} + +/** + * acpi_irq_domain_register_irq() - Register the mapping for an IRQ produced + * by the given acpi_resource_source to a + * Linux IRQ number + * @source: IRQ source + * @hwirq: Hardware IRQ number + * @trigger: trigger type of the IRQ number to be mapped + * @polarity: polarity of the IRQ to be mapped + * + * Returns: a valid linux IRQ number on success + * -ENODEV if the given acpi_resource_source cannot be found + * -EPROBE_DEFER if the IRQ domain has not been registered + * -EINVAL for all other errors + */ +int acpi_irq_domain_register_irq(struct acpi_resource_source *source, u32 hwirq, +int trigger, int polarity) +{ + struct irq_fwspec fwspec; + struct acpi_device *device; + acpi_handle handle; + acpi_status status; + int ret; + + if (source->string_length == 0) + return acpi_register_gsi(NULL, hwirq, trigger, polarity); + + status = acpi_get_handle(NULL, source->string_ptr, &handle); + if (ACPI_FAILURE(status)) + return -ENODEV; + + device = acpi_bus_get_acpi_device(handle); + if (!device) + return -ENODEV; + + if (acpi_irq_domain_ensure_probed(device)) + return -ENODEV; + + fwspec.fwnode = &device->fwnode; + fwspec.param[0] = hwirq; + fwspec.param[1] = acpi_dev_get_irq_type(trigger, polarity); + fwspec.param_count = 2; + + ret = irq_create_fwspec_mapping(&fwspec); + acpi_bus_put_acpi_device(device); + return ret; +} +EXPORT_SYMBOL_GPL(acpi_irq_domain_register_irq); + +/** + * acpi_irq_domain_unregister_irq() - Delete the mapping for an IRQ produced + *by the given acpi_resource_source to a + *Linux IRQ number + * @source: IRQ source + * @hwirq: Hardware IRQ number + * + * Returns: 0 on success + * -ENODEV if the given acpi_resource_source cannot be found + * -EINVAL for all other errors + */ +int acpi_irq_domain_unregister_irq(struct acpi_resource_source *source, + u32 hwirq) +{ + struct irq_domain *domain; + struct acpi_device *device; + acpi_handle handle; + acpi_status