Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756438AbbLHNVK (ORCPT ); Tue, 8 Dec 2015 08:21:10 -0500 Received: from mailapp01.imgtec.com ([195.59.15.196]:36218 "EHLO mailapp01.imgtec.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756403AbbLHNVH (ORCPT ); Tue, 8 Dec 2015 08:21:07 -0500 From: Qais Yousef To: CC: , , , , , , , Qais Yousef Subject: [PATCH v4 04/19] genirq: Add struct ipi_mapping and its helper functions Date: Tue, 8 Dec 2015 13:20:15 +0000 Message-ID: <1449580830-23652-5-git-send-email-qais.yousef@imgtec.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1449580830-23652-1-git-send-email-qais.yousef@imgtec.com> References: <1449580830-23652-1-git-send-email-qais.yousef@imgtec.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [192.168.154.94] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6318 Lines: 226 struct ipi_mapping will provide a mechanism for irqchip code to fill out the mapping at reservation and to look it up when sending. The use of this mapping mechanism is optional. Irqchips might have better and simpler ways to represent the mapping without using this. Signed-off-by: Qais Yousef --- include/linux/irq.h | 43 +++++++++++++++++++++ kernel/irq/Makefile | 1 + kernel/irq/ipi.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 kernel/irq/ipi.c diff --git a/include/linux/irq.h b/include/linux/irq.h index 3c1c96786248..14f1c036119c 100644 --- a/include/linux/irq.h +++ b/include/linux/irq.h @@ -128,6 +128,18 @@ struct msi_desc; struct irq_domain; /** + * struct ipi_mapping - IPI mapping information object + * @nr_hwirqs: number of hwirqs mapped + * @nr_cpus: number of cpus the controller can talk to + * @cpumap: per cpu hwirq mapping table + */ +struct ipi_mapping { + unsigned int nr_hwirqs; + unsigned int nr_cpus; + unsigned int cpumap[]; +}; + +/** * struct irq_common_data - per irq data shared by all irqchips * @state_use_accessors: status information for irq chip functions. * Use accessor functions to deal with it @@ -135,6 +147,9 @@ struct irq_domain; * @handler_data: per-IRQ data for the irq_chip methods * @affinity: IRQ affinity on SMP * @msi_desc: MSI descriptor + * @ipi_mapping: Contains the hwirq mapping of IPIs. + * The use of this struct is optional and not all irqchips + * will use it. */ struct irq_common_data { unsigned int state_use_accessors; @@ -144,6 +159,9 @@ struct irq_common_data { void *handler_data; struct msi_desc *msi_desc; cpumask_var_t affinity; +#ifdef CONFIG_GENERIC_IRQ_IPI + struct ipi_mapping *ipi_map; +#endif }; /** @@ -681,6 +699,21 @@ static inline struct cpumask *irq_data_get_affinity_mask(struct irq_data *d) return d->common->affinity; } +#ifdef CONFIG_GENERIC_IRQ_IPI + +static inline struct ipi_mapping *irq_data_get_ipi_map(struct irq_data *d) +{ + return d->common->ipi_map; +} + +static inline void irq_data_set_ipi_map(struct irq_data *d, + struct ipi_mapping *map) +{ + d->common->ipi_map = map; +} + +#endif + unsigned int arch_dynirq_lower_bound(unsigned int from); int __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node, @@ -934,4 +967,14 @@ static inline u32 irq_reg_readl(struct irq_chip_generic *gc, return readl(gc->reg_base + reg_offset); } +#define INVALID_HWIRQ -1 + +struct ipi_mapping *irq_alloc_ipi_mapping(unsigned int nr_cpus); +void irq_free_ipi_mapping(struct ipi_mapping *map); +int irq_map_ipi(struct ipi_mapping *map, + unsigned int cpu, irq_hw_number_t hwirq); +int irq_unmap_ipi(struct ipi_mapping *map, unsigned int cpu); +irq_hw_number_t irq_ipi_mapping_get_hwirq(struct ipi_mapping *map, + unsigned int cpu); + #endif /* _LINUX_IRQ_H */ diff --git a/kernel/irq/Makefile b/kernel/irq/Makefile index 2fc9cbdf35b6..2ee42e95a3ce 100644 --- a/kernel/irq/Makefile +++ b/kernel/irq/Makefile @@ -8,3 +8,4 @@ obj-$(CONFIG_GENERIC_PENDING_IRQ) += migration.o obj-$(CONFIG_GENERIC_IRQ_MIGRATION) += cpuhotplug.o obj-$(CONFIG_PM_SLEEP) += pm.o obj-$(CONFIG_GENERIC_MSI_IRQ) += msi.o +obj-$(CONFIG_GENERIC_IRQ_IPI) += ipi.o diff --git a/kernel/irq/ipi.c b/kernel/irq/ipi.c new file mode 100644 index 000000000000..8cf76852982f --- /dev/null +++ b/kernel/irq/ipi.c @@ -0,0 +1,109 @@ +/* + * linux/kernel/irq/ipi.c + * + * Copyright (C) 2015 Imagination Technologies Ltd + * Author: Qais Yousef + * + * This file contains driver APIs to the IPI subsystem. + */ + +#include +#include + +/** + * irq_alloc_ipi_mapping - allocate memory for struct ipi_mapping + * @nr_cpus: number of CPUs the mapping will have + * + * Will allocate and setup ipi_mapping structure. + * + * Returns a valid ipi_mapping pointer on success and NULL on error. + */ +struct ipi_mapping *irq_alloc_ipi_mapping(unsigned int nr_cpus) +{ + struct ipi_mapping *map; + size_t size; + + size = sizeof(struct ipi_mapping) + BITS_TO_LONGS(nr_cpus) * sizeof(long); + + map = kzalloc(size, GFP_KERNEL); + if (!map) + return NULL; + + map->nr_cpus = nr_cpus; + + memset(map->cpumap, INVALID_HWIRQ, size); + + return map; +} + +/** + * irq_free_ipi_mapping - release mempry associated with ipi_mapping struct + * @map: pointer to struct ipi_mapping to be freed + * + * Release the memory allocated for sturct ipi_mapping to the system. + */ +void irq_free_ipi_mapping(struct ipi_mapping *map) +{ + kfree(map); +} + +/** + * irq_map_ipi - create a CPU to HWIRQ mapping for an IPI + * @map: pointer to the mapping structure + * @cpu: the CPU to map + * @hwirq: the HWIRQ to associate with @cpu + * + * Returns zero on success and negative error number on failure. + */ +int irq_map_ipi(struct ipi_mapping *map, + unsigned int cpu, irq_hw_number_t hwirq) +{ + if (cpu >= map->nr_cpus) + return -EINVAL; + + map->cpumap[cpu] = hwirq; + map->nr_hwirqs++; + + return 0; +} + +/** + * irq_unmap_ipi - remove the CPU mapping of an IPI + * @map: pointer to the mapping structure + * @cpu: the CPU to be unmapped + * + * Mark the IPI mapping of a CPU to INVALID_HWIRQ. + * + * Returns zero on success and negative error number on failure. + */ +int irq_unmap_ipi(struct ipi_mapping *map, unsigned int cpu) +{ + if (cpu >= map->nr_cpus) + return -EINVAL; + + if (map->cpumap[cpu] == INVALID_HWIRQ) + return -EINVAL; + + map->cpumap[cpu] = INVALID_HWIRQ; + map->nr_hwirqs--; + + return 0; +} + +/** + * irq_ipi_mapping_get_hwirq - get the value of hwirq associated with @cpu + * @map: pointer to the mapping structure + * @cpu: the CPU to get its associated hwirq + * + * Return the hwiq asocaited with a @cpu + * + * Returns hwirq value on success and INVALID_HWIRQ on failure. + */ +irq_hw_number_t irq_ipi_mapping_get_hwirq(struct ipi_mapping *map, + unsigned int cpu) +{ + if (cpu >= map->nr_cpus) + return INVALID_HWIRQ; + + return map->cpumap[cpu]; +} -- 2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/