base-files: define yes/no as valid boolean options
[openwrt.git] / target / linux / mvebu / patches-3.10 / 0073-of-pci-add-registry-of-MSI-chips.patch
1 From a05852e828063b6731fcac543b87367c137c16f8 Mon Sep 17 00:00:00 2001
2 From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
3 Date: Thu, 6 Jun 2013 18:21:18 +0200
4 Subject: [PATCH 073/203] of: pci: add registry of MSI chips
5
6 This commit adds a very basic registry of msi_chip structures, so that
7 an IRQ controller driver can register an msi_chip, and a PCIe host
8 controller can find it, based on a 'struct device_node'.
9
10 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
11 Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
12 Acked-by: Rob Herring <rob.herring@calxeda.com>
13 ---
14  drivers/of/of_pci.c    | 45 +++++++++++++++++++++++++++++++++++++++++++++
15  include/linux/msi.h    |  2 ++
16  include/linux/of_pci.h | 12 ++++++++++++
17  3 files changed, 59 insertions(+)
18
19 --- a/drivers/of/of_pci.c
20 +++ b/drivers/of/of_pci.c
21 @@ -89,3 +89,48 @@ int of_pci_parse_bus_range(struct device
22         return 0;
23  }
24  EXPORT_SYMBOL_GPL(of_pci_parse_bus_range);
25 +
26 +#ifdef CONFIG_PCI_MSI
27 +
28 +static LIST_HEAD(of_pci_msi_chip_list);
29 +static DEFINE_MUTEX(of_pci_msi_chip_mutex);
30 +
31 +int of_pci_msi_chip_add(struct msi_chip *chip)
32 +{
33 +       if (!of_property_read_bool(chip->of_node, "msi-controller"))
34 +               return -EINVAL;
35 +
36 +       mutex_lock(&of_pci_msi_chip_mutex);
37 +       list_add(&chip->list, &of_pci_msi_chip_list);
38 +       mutex_unlock(&of_pci_msi_chip_mutex);
39 +
40 +       return 0;
41 +}
42 +EXPORT_SYMBOL_GPL(of_pci_msi_chip_add);
43 +
44 +void of_pci_msi_chip_remove(struct msi_chip *chip)
45 +{
46 +       mutex_lock(&of_pci_msi_chip_mutex);
47 +       list_del(&chip->list);
48 +       mutex_unlock(&of_pci_msi_chip_mutex);
49 +}
50 +EXPORT_SYMBOL_GPL(of_pci_msi_chip_remove);
51 +
52 +struct msi_chip *of_pci_find_msi_chip_by_node(struct device_node *of_node)
53 +{
54 +       struct msi_chip *c;
55 +
56 +       mutex_lock(&of_pci_msi_chip_mutex);
57 +       list_for_each_entry(c, &of_pci_msi_chip_list, list) {
58 +               if (c->of_node == of_node) {
59 +                       mutex_unlock(&of_pci_msi_chip_mutex);
60 +                       return c;
61 +               }
62 +       }
63 +       mutex_unlock(&of_pci_msi_chip_mutex);
64 +
65 +       return NULL;
66 +}
67 +EXPORT_SYMBOL_GPL(of_pci_find_msi_chip_by_node);
68 +
69 +#endif /* CONFIG_PCI_MSI */
70 --- a/include/linux/msi.h
71 +++ b/include/linux/msi.h
72 @@ -67,6 +67,8 @@ void default_restore_msi_irqs(struct pci
73  struct msi_chip {
74         struct module *owner;
75         struct device *dev;
76 +       struct device_node *of_node;
77 +       struct list_head list;
78  
79         int (*setup_irq)(struct msi_chip *chip, struct pci_dev *dev,
80                          struct msi_desc *desc);
81 --- a/include/linux/of_pci.h
82 +++ b/include/linux/of_pci.h
83 @@ -2,6 +2,7 @@
84  #define __OF_PCI_H
85  
86  #include <linux/pci.h>
87 +#include <linux/msi.h>
88  
89  struct pci_dev;
90  struct of_irq;
91 @@ -13,4 +14,15 @@ struct device_node *of_pci_find_child_de
92  int of_pci_get_devfn(struct device_node *np);
93  int of_pci_parse_bus_range(struct device_node *node, struct resource *res);
94  
95 +#if defined(CONFIG_OF) && defined(CONFIG_PCI_MSI)
96 +int of_pci_msi_chip_add(struct msi_chip *chip);
97 +void of_pci_msi_chip_remove(struct msi_chip *chip);
98 +struct msi_chip *of_pci_find_msi_chip_by_node(struct device_node *of_node);
99 +#else
100 +static inline int of_pci_msi_chip_add(struct msi_chip *chip) { return -EINVAL; }
101 +static inline void of_pci_msi_chip_remove(struct msi_chip *chip) { }
102 +static inline struct msi_chip *
103 +of_pci_find_msi_chip_by_node(struct device_node *of_node) { return NULL; }
104 +#endif
105 +
106  #endif