aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86
diff options
context:
space:
mode:
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>2011-02-22 15:07:42 -0500
committerThomas Gleixner <tglx@linutronix.de>2011-02-23 16:27:53 -0500
commit96e0a0797eba35b5420c710b928f19094b2d5c45 (patch)
tree4a9073fc9415b024437a5d8b56791632a14153cf /arch/x86
parentffb9fc68dff38f811eeb24c15aba0418b6a8ee53 (diff)
x86: dtb: Add support for PCI devices backed by dtb nodes
x86_of_pci_init() does two things: - it provides a generic irq enable and disable function. enable queries the device tree for the interrupt information, calls ->xlate on the irq host and updates the pci->irq information for the device. - it walks through PCI bus(es) in the device tree and adds its children (device) nodes to appropriate pci_dev nodes in kernel. So the dtb node information is available at probe time of the PCI device. Adding a PCI bus based on the information in the device tree is currently not supported. Right now direct access via ioports is used. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Tested-by: Dirk Brandewie <dirk.brandewie@gmail.com> Acked-by: Grant Likely <grant.likely@secretlab.ca> Cc: sodaville@linutronix.de Cc: devicetree-discuss@lists.ozlabs.org LKML-Reference: <1298405266-1624-8-git-send-email-bigeasy@linutronix.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'arch/x86')
-rw-r--r--arch/x86/include/asm/prom.h14
-rw-r--r--arch/x86/kernel/devicetree.c83
2 files changed, 97 insertions, 0 deletions
diff --git a/arch/x86/include/asm/prom.h b/arch/x86/include/asm/prom.h
index 35ec32b47500..8fcd519a44dc 100644
--- a/arch/x86/include/asm/prom.h
+++ b/arch/x86/include/asm/prom.h
@@ -16,6 +16,7 @@
16 16
17#include <linux/of.h> 17#include <linux/of.h>
18#include <linux/types.h> 18#include <linux/types.h>
19#include <linux/pci.h>
19 20
20#include <asm/irq.h> 21#include <asm/irq.h>
21#include <asm/atomic.h> 22#include <asm/atomic.h>
@@ -29,8 +30,21 @@ extern void add_dtb(u64 data);
29void x86_dtb_find_config(void); 30void x86_dtb_find_config(void);
30void x86_dtb_get_config(unsigned int unused); 31void x86_dtb_get_config(unsigned int unused);
31void add_interrupt_host(struct irq_domain *ih); 32void add_interrupt_host(struct irq_domain *ih);
33void __cpuinit x86_of_pci_init(void);
34
35static inline struct device_node *pci_device_to_OF_node(struct pci_dev *pdev)
36{
37 return pdev ? pdev->dev.of_node : NULL;
38}
39
40static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
41{
42 return pci_device_to_OF_node(bus->self);
43}
44
32#else 45#else
33static inline void add_dtb(u64 data) { } 46static inline void add_dtb(u64 data) { }
47static inline void x86_of_pci_init(void) { }
34#define x86_dtb_find_config x86_init_noop 48#define x86_dtb_find_config x86_init_noop
35#define x86_dtb_get_config x86_init_uint_noop 49#define x86_dtb_get_config x86_init_uint_noop
36#define of_ioapic 0 50#define of_ioapic 0
diff --git a/arch/x86/kernel/devicetree.c b/arch/x86/kernel/devicetree.c
index dbb3bda40af9..7b574226e0a8 100644
--- a/arch/x86/kernel/devicetree.c
+++ b/arch/x86/kernel/devicetree.c
@@ -9,11 +9,15 @@
9#include <linux/of_fdt.h> 9#include <linux/of_fdt.h>
10#include <linux/of_address.h> 10#include <linux/of_address.h>
11#include <linux/of_platform.h> 11#include <linux/of_platform.h>
12#include <linux/of_irq.h>
12#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/pci.h>
15#include <linux/of_pci.h>
13 16
14#include <asm/hpet.h> 17#include <asm/hpet.h>
15#include <asm/irq_controller.h> 18#include <asm/irq_controller.h>
16#include <asm/apic.h> 19#include <asm/apic.h>
20#include <asm/pci_x86.h>
17 21
18__initdata u64 initial_dtb; 22__initdata u64 initial_dtb;
19char __initdata cmd_line[COMMAND_LINE_SIZE]; 23char __initdata cmd_line[COMMAND_LINE_SIZE];
@@ -99,6 +103,85 @@ void __init add_dtb(u64 data)
99 initial_dtb = data + offsetof(struct setup_data, data); 103 initial_dtb = data + offsetof(struct setup_data, data);
100} 104}
101 105
106#ifdef CONFIG_PCI
107static int x86_of_pci_irq_enable(struct pci_dev *dev)
108{
109 struct of_irq oirq;
110 u32 virq;
111 int ret;
112 u8 pin;
113
114 ret = pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
115 if (ret)
116 return ret;
117 if (!pin)
118 return 0;
119
120 ret = of_irq_map_pci(dev, &oirq);
121 if (ret)
122 return ret;
123
124 virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
125 oirq.size);
126 if (virq == 0)
127 return -EINVAL;
128 dev->irq = virq;
129 return 0;
130}
131
132static void x86_of_pci_irq_disable(struct pci_dev *dev)
133{
134}
135
136void __cpuinit x86_of_pci_init(void)
137{
138 struct device_node *np;
139
140 pcibios_enable_irq = x86_of_pci_irq_enable;
141 pcibios_disable_irq = x86_of_pci_irq_disable;
142
143 for_each_node_by_type(np, "pci") {
144 const void *prop;
145 struct pci_bus *bus;
146 unsigned int bus_min;
147 struct device_node *child;
148
149 prop = of_get_property(np, "bus-range", NULL);
150 if (!prop)
151 continue;
152 bus_min = be32_to_cpup(prop);
153
154 bus = pci_find_bus(0, bus_min);
155 if (!bus) {
156 printk(KERN_ERR "Can't find a node for bus %s.\n",
157 np->full_name);
158 continue;
159 }
160
161 if (bus->self)
162 bus->self->dev.of_node = np;
163 else
164 bus->dev.of_node = np;
165
166 for_each_child_of_node(np, child) {
167 struct pci_dev *dev;
168 u32 devfn;
169
170 prop = of_get_property(child, "reg", NULL);
171 if (!prop)
172 continue;
173
174 devfn = (be32_to_cpup(prop) >> 8) & 0xff;
175 dev = pci_get_slot(bus, devfn);
176 if (!dev)
177 continue;
178 dev->dev.of_node = child;
179 pci_dev_put(dev);
180 }
181 }
182}
183#endif
184
102static void __init dtb_setup_hpet(void) 185static void __init dtb_setup_hpet(void)
103{ 186{
104 struct device_node *dn; 187 struct device_node *dn;