2 * linux/kernel/irq/msi.c
4 * Copyright (C) 2014 Intel Corp.
5 * Author: Jiang Liu <jiang.liu@linux.intel.com>
7 * This file is licensed under GPLv2.
9 * This file contains common code to support Message Signalled Interrupt for
10 * PCI compatible and non PCI compatible devices.
12 #include <linux/irq.h>
13 #include <linux/irqdomain.h>
14 #include <linux/msi.h>
16 #ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
18 * msi_domain_set_affinity - Generic affinity setter function for MSI domains
19 * @irq_data: The irq data associated to the interrupt
20 * @mask: The affinity mask to set
21 * @force: Flag to enforce setting (disable online checks)
23 * Intended to be used by MSI interrupt controllers which are
24 * implemented with hierarchical domains.
26 int msi_domain_set_affinity(struct irq_data *irq_data,
27 const struct cpumask *mask, bool force)
29 struct irq_data *parent = irq_data->parent_data;
33 ret = parent->chip->irq_set_affinity(parent, mask, force);
34 if (ret >= 0 && ret != IRQ_SET_MASK_OK_DONE) {
35 BUG_ON(irq_chip_compose_msi_msg(irq_data, &msg));
36 irq_chip_write_msi_msg(irq_data, &msg);
42 static void msi_domain_activate(struct irq_domain *domain,
43 struct irq_data *irq_data)
47 BUG_ON(irq_chip_compose_msi_msg(irq_data, &msg));
48 irq_chip_write_msi_msg(irq_data, &msg);
51 static void msi_domain_deactivate(struct irq_domain *domain,
52 struct irq_data *irq_data)
56 memset(&msg, 0, sizeof(msg));
57 irq_chip_write_msi_msg(irq_data, &msg);
60 static int msi_domain_alloc(struct irq_domain *domain, unsigned int virq,
61 unsigned int nr_irqs, void *arg)
63 struct msi_domain_info *info = domain->host_data;
64 struct msi_domain_ops *ops = info->ops;
65 irq_hw_number_t hwirq = ops->get_hwirq(info, arg);
68 if (irq_find_mapping(domain, hwirq) > 0)
71 ret = irq_domain_alloc_irqs_parent(domain, virq, nr_irqs, arg);
75 for (i = 0; i < nr_irqs; i++) {
76 ret = ops->msi_init(domain, info, virq + i, hwirq + i, arg);
80 ops->msi_free(domain, info, virq + i);
82 irq_domain_free_irqs_top(domain, virq, nr_irqs);
90 static void msi_domain_free(struct irq_domain *domain, unsigned int virq,
93 struct msi_domain_info *info = domain->host_data;
96 if (info->ops->msi_free) {
97 for (i = 0; i < nr_irqs; i++)
98 info->ops->msi_free(domain, info, virq + i);
100 irq_domain_free_irqs_top(domain, virq, nr_irqs);
103 static struct irq_domain_ops msi_domain_ops = {
104 .alloc = msi_domain_alloc,
105 .free = msi_domain_free,
106 .activate = msi_domain_activate,
107 .deactivate = msi_domain_deactivate,
111 * msi_create_irq_domain - Create a MSI interrupt domain
112 * @of_node: Optional device-tree node of the interrupt controller
113 * @info: MSI domain info
114 * @parent: Parent irq domain
116 struct irq_domain *msi_create_irq_domain(struct device_node *of_node,
117 struct msi_domain_info *info,
118 struct irq_domain *parent)
120 struct irq_domain *domain;
122 domain = irq_domain_add_tree(of_node, &msi_domain_ops, info);
124 domain->parent = parent;
130 * msi_get_domain_info - Get the MSI interrupt domain info for @domain
131 * @domain: The interrupt domain to retrieve data from
133 * Returns the pointer to the msi_domain_info stored in
134 * @domain->host_data.
136 struct msi_domain_info *msi_get_domain_info(struct irq_domain *domain)
138 return (struct msi_domain_info *)domain->host_data;
141 #endif /* CONFIG_GENERIC_MSI_IRQ_DOMAIN */