diff options
author | Thomas Petazzoni <thomas.petazzoni@free-electrons.com> | 2013-08-09 16:27:09 -0400 |
---|---|---|
committer | Jason Cooper <jason@lakedaemon.net> | 2013-08-12 11:27:01 -0400 |
commit | 0d5a6db3aa46faafd0212650bfd709d51240d9da (patch) | |
tree | dea9d680f4ae8aea5628ec8d69b72802f0a4bf28 | |
parent | 0cbdcfcf427b63b9670e56760ef5e67cd7081b35 (diff) |
of: pci: add registry of MSI chips
This commit adds a very basic registry of msi_chip structures, so that
an IRQ controller driver can register an msi_chip, and a PCIe host
controller can find it, based on a 'struct device_node'.
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Rob Herring <rob.herring@calxeda.com>
Signed-off-by: Jason Cooper <jason@lakedaemon.net>
-rw-r--r-- | drivers/of/of_pci.c | 45 | ||||
-rw-r--r-- | include/linux/msi.h | 2 | ||||
-rw-r--r-- | include/linux/of_pci.h | 12 |
3 files changed, 59 insertions, 0 deletions
diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c index 42c687a820ac..e5ca00893c0c 100644 --- a/drivers/of/of_pci.c +++ b/drivers/of/of_pci.c | |||
@@ -89,3 +89,48 @@ int of_pci_parse_bus_range(struct device_node *node, struct resource *res) | |||
89 | return 0; | 89 | return 0; |
90 | } | 90 | } |
91 | EXPORT_SYMBOL_GPL(of_pci_parse_bus_range); | 91 | EXPORT_SYMBOL_GPL(of_pci_parse_bus_range); |
92 | |||
93 | #ifdef CONFIG_PCI_MSI | ||
94 | |||
95 | static LIST_HEAD(of_pci_msi_chip_list); | ||
96 | static DEFINE_MUTEX(of_pci_msi_chip_mutex); | ||
97 | |||
98 | int of_pci_msi_chip_add(struct msi_chip *chip) | ||
99 | { | ||
100 | if (!of_property_read_bool(chip->of_node, "msi-controller")) | ||
101 | return -EINVAL; | ||
102 | |||
103 | mutex_lock(&of_pci_msi_chip_mutex); | ||
104 | list_add(&chip->list, &of_pci_msi_chip_list); | ||
105 | mutex_unlock(&of_pci_msi_chip_mutex); | ||
106 | |||
107 | return 0; | ||
108 | } | ||
109 | EXPORT_SYMBOL_GPL(of_pci_msi_chip_add); | ||
110 | |||
111 | void of_pci_msi_chip_remove(struct msi_chip *chip) | ||
112 | { | ||
113 | mutex_lock(&of_pci_msi_chip_mutex); | ||
114 | list_del(&chip->list); | ||
115 | mutex_unlock(&of_pci_msi_chip_mutex); | ||
116 | } | ||
117 | EXPORT_SYMBOL_GPL(of_pci_msi_chip_remove); | ||
118 | |||
119 | struct msi_chip *of_pci_find_msi_chip_by_node(struct device_node *of_node) | ||
120 | { | ||
121 | struct msi_chip *c; | ||
122 | |||
123 | mutex_lock(&of_pci_msi_chip_mutex); | ||
124 | list_for_each_entry(c, &of_pci_msi_chip_list, list) { | ||
125 | if (c->of_node == of_node) { | ||
126 | mutex_unlock(&of_pci_msi_chip_mutex); | ||
127 | return c; | ||
128 | } | ||
129 | } | ||
130 | mutex_unlock(&of_pci_msi_chip_mutex); | ||
131 | |||
132 | return NULL; | ||
133 | } | ||
134 | EXPORT_SYMBOL_GPL(of_pci_find_msi_chip_by_node); | ||
135 | |||
136 | #endif /* CONFIG_PCI_MSI */ | ||
diff --git a/include/linux/msi.h b/include/linux/msi.h index 090ddadbc838..b17ead818aec 100644 --- a/include/linux/msi.h +++ b/include/linux/msi.h | |||
@@ -68,6 +68,8 @@ void default_restore_msi_irqs(struct pci_dev *dev, int irq); | |||
68 | struct msi_chip { | 68 | struct msi_chip { |
69 | struct module *owner; | 69 | struct module *owner; |
70 | struct device *dev; | 70 | struct device *dev; |
71 | struct device_node *of_node; | ||
72 | struct list_head list; | ||
71 | 73 | ||
72 | int (*setup_irq)(struct msi_chip *chip, struct pci_dev *dev, | 74 | int (*setup_irq)(struct msi_chip *chip, struct pci_dev *dev, |
73 | struct msi_desc *desc); | 75 | struct msi_desc *desc); |
diff --git a/include/linux/of_pci.h b/include/linux/of_pci.h index 7a04826018c0..fd9c408631a0 100644 --- a/include/linux/of_pci.h +++ b/include/linux/of_pci.h | |||
@@ -2,6 +2,7 @@ | |||
2 | #define __OF_PCI_H | 2 | #define __OF_PCI_H |
3 | 3 | ||
4 | #include <linux/pci.h> | 4 | #include <linux/pci.h> |
5 | #include <linux/msi.h> | ||
5 | 6 | ||
6 | struct pci_dev; | 7 | struct pci_dev; |
7 | struct of_irq; | 8 | struct of_irq; |
@@ -13,4 +14,15 @@ struct device_node *of_pci_find_child_device(struct device_node *parent, | |||
13 | int of_pci_get_devfn(struct device_node *np); | 14 | int of_pci_get_devfn(struct device_node *np); |
14 | int of_pci_parse_bus_range(struct device_node *node, struct resource *res); | 15 | int of_pci_parse_bus_range(struct device_node *node, struct resource *res); |
15 | 16 | ||
17 | #if defined(CONFIG_OF) && defined(CONFIG_PCI_MSI) | ||
18 | int of_pci_msi_chip_add(struct msi_chip *chip); | ||
19 | void of_pci_msi_chip_remove(struct msi_chip *chip); | ||
20 | struct msi_chip *of_pci_find_msi_chip_by_node(struct device_node *of_node); | ||
21 | #else | ||
22 | static inline int of_pci_msi_chip_add(struct msi_chip *chip) { return -EINVAL; } | ||
23 | static inline void of_pci_msi_chip_remove(struct msi_chip *chip) { } | ||
24 | static inline struct msi_chip * | ||
25 | of_pci_find_msi_chip_by_node(struct device_node *of_node) { return NULL; } | ||
26 | #endif | ||
27 | |||
16 | #endif | 28 | #endif |