2 * Architecture specific OF callbacks.
4 #include <linux/bootmem.h>
6 #include <linux/interrupt.h>
7 #include <linux/list.h>
9 #include <linux/of_fdt.h>
10 #include <linux/of_address.h>
11 #include <linux/of_platform.h>
12 #include <linux/of_irq.h>
13 #include <linux/slab.h>
14 #include <linux/pci.h>
15 #include <linux/of_pci.h>
18 #include <asm/irq_controller.h>
20 #include <asm/pci_x86.h>
22 __initdata u64 initial_dtb;
23 char __initdata cmd_line[COMMAND_LINE_SIZE];
24 static LIST_HEAD(irq_domains);
25 static DEFINE_RAW_SPINLOCK(big_irq_lock);
27 int __initdata of_ioapic;
29 #ifdef CONFIG_X86_IO_APIC
30 static void add_interrupt_host(struct irq_domain *ih)
34 raw_spin_lock_irqsave(&big_irq_lock, flags);
35 list_add(&ih->l, &irq_domains);
36 raw_spin_unlock_irqrestore(&big_irq_lock, flags);
40 static struct irq_domain *get_ih_from_node(struct device_node *controller)
42 struct irq_domain *ih, *found = NULL;
45 raw_spin_lock_irqsave(&big_irq_lock, flags);
46 list_for_each_entry(ih, &irq_domains, l) {
47 if (ih->controller == controller) {
52 raw_spin_unlock_irqrestore(&big_irq_lock, flags);
56 unsigned int irq_create_of_mapping(struct device_node *controller,
57 const u32 *intspec, unsigned int intsize)
59 struct irq_domain *ih;
63 ih = get_ih_from_node(controller);
66 ret = ih->xlate(ih, intspec, intsize, &virq, &type);
69 if (type == IRQ_TYPE_NONE)
71 /* set the mask if it is different from current */
72 if (type == (irq_to_desc(virq)->status & IRQF_TRIGGER_MASK))
73 set_irq_type(virq, type);
76 EXPORT_SYMBOL_GPL(irq_create_of_mapping);
78 unsigned long pci_address_to_pio(phys_addr_t address)
81 * The ioport address can be directly used by inX / outX
83 BUG_ON(address >= (1 << 16));
84 return (unsigned long)address;
86 EXPORT_SYMBOL_GPL(pci_address_to_pio);
88 void __init early_init_dt_scan_chosen_arch(unsigned long node)
93 void __init early_init_dt_add_memory_arch(u64 base, u64 size)
98 void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
100 return __alloc_bootmem(size, align, __pa(MAX_DMA_ADDRESS));
103 void __init add_dtb(u64 data)
105 initial_dtb = data + offsetof(struct setup_data, data);
109 * CE4100 ids. Will be moved to machine_device_initcall() once we have it.
111 static struct of_device_id __initdata ce4100_ids[] = {
112 { .compatible = "intel,ce4100-cp", },
113 { .compatible = "isa", },
114 { .compatible = "pci", },
118 static int __init add_bus_probe(void)
120 if (!of_have_populated_dt())
123 return of_platform_bus_probe(NULL, ce4100_ids, NULL);
125 module_init(add_bus_probe);
128 static int x86_of_pci_irq_enable(struct pci_dev *dev)
135 ret = pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
141 ret = of_irq_map_pci(dev, &oirq);
145 virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
153 static void x86_of_pci_irq_disable(struct pci_dev *dev)
157 void __cpuinit x86_of_pci_init(void)
159 struct device_node *np;
161 pcibios_enable_irq = x86_of_pci_irq_enable;
162 pcibios_disable_irq = x86_of_pci_irq_disable;
164 for_each_node_by_type(np, "pci") {
167 unsigned int bus_min;
168 struct device_node *child;
170 prop = of_get_property(np, "bus-range", NULL);
173 bus_min = be32_to_cpup(prop);
175 bus = pci_find_bus(0, bus_min);
177 printk(KERN_ERR "Can't find a node for bus %s.\n",
183 bus->self->dev.of_node = np;
185 bus->dev.of_node = np;
187 for_each_child_of_node(np, child) {
191 prop = of_get_property(child, "reg", NULL);
195 devfn = (be32_to_cpup(prop) >> 8) & 0xff;
196 dev = pci_get_slot(bus, devfn);
199 dev->dev.of_node = child;
206 static void __init dtb_setup_hpet(void)
208 #ifdef CONFIG_HPET_TIMER
209 struct device_node *dn;
213 dn = of_find_compatible_node(NULL, NULL, "intel,ce4100-hpet");
216 ret = of_address_to_resource(dn, 0, &r);
221 hpet_address = r.start;
225 static void __init dtb_lapic_setup(void)
227 #ifdef CONFIG_X86_LOCAL_APIC
228 struct device_node *dn;
232 dn = of_find_compatible_node(NULL, NULL, "intel,ce4100-lapic");
236 ret = of_address_to_resource(dn, 0, &r);
240 /* Did the boot loader setup the local APIC ? */
242 if (apic_force_enable(r.start))
245 smp_found_config = 1;
247 register_lapic_address(r.start);
248 generic_processor_info(boot_cpu_physical_apicid,
249 GET_APIC_VERSION(apic_read(APIC_LVR)));
253 #ifdef CONFIG_X86_IO_APIC
254 static unsigned int ioapic_id;
256 static void __init dtb_add_ioapic(struct device_node *dn)
261 ret = of_address_to_resource(dn, 0, &r);
263 printk(KERN_ERR "Can't obtain address from node %s.\n",
267 mp_register_ioapic(++ioapic_id, r.start, gsi_top);
270 static void __init dtb_ioapic_setup(void)
272 struct device_node *dn;
274 for_each_compatible_node(dn, NULL, "intel,ce4100-ioapic")
281 printk(KERN_ERR "Error: No information about IO-APIC in OF.\n");
284 static void __init dtb_ioapic_setup(void) {}
287 static void __init dtb_apic_setup(void)
293 #ifdef CONFIG_OF_FLATTREE
294 static void __init x86_flattree_get_config(void)
302 map_len = max(PAGE_SIZE - (initial_dtb & ~PAGE_MASK),
303 (u64)sizeof(struct boot_param_header));
305 initial_boot_params = early_memremap(initial_dtb, map_len);
306 size = be32_to_cpu(initial_boot_params->totalsize);
307 if (map_len < size) {
308 early_iounmap(initial_boot_params, map_len);
309 initial_boot_params = early_memremap(initial_dtb, size);
313 new_dtb = alloc_bootmem(size);
314 memcpy(new_dtb, initial_boot_params, size);
315 early_iounmap(initial_boot_params, map_len);
317 initial_boot_params = new_dtb;
319 /* root level address cells */
320 of_scan_flat_dt(early_init_dt_scan_root, NULL);
322 unflatten_device_tree();
325 static inline void x86_flattree_get_config(void) { }
328 void __init x86_dtb_init(void)
330 x86_flattree_get_config();
332 if (!of_have_populated_dt())
339 #ifdef CONFIG_X86_IO_APIC
341 struct of_ioapic_type {
347 static struct of_ioapic_type of_ioapic_type[] =
350 .out_type = IRQ_TYPE_EDGE_RISING,
351 .trigger = IOAPIC_EDGE,
355 .out_type = IRQ_TYPE_LEVEL_LOW,
356 .trigger = IOAPIC_LEVEL,
360 .out_type = IRQ_TYPE_LEVEL_HIGH,
361 .trigger = IOAPIC_LEVEL,
365 .out_type = IRQ_TYPE_EDGE_FALLING,
366 .trigger = IOAPIC_EDGE,
371 static int ioapic_xlate(struct irq_domain *id, const u32 *intspec, u32 intsize,
372 u32 *out_hwirq, u32 *out_type)
374 struct io_apic_irq_attr attr;
375 struct of_ioapic_type *it;
382 idx = (u32) id->priv;
383 *out_hwirq = line + mp_gsi_routing[idx].gsi_base;
388 if (type >= ARRAY_SIZE(of_ioapic_type))
391 it = of_ioapic_type + type;
392 *out_type = it->out_type;
394 set_io_apic_irq_attr(&attr, idx, line, it->trigger, it->polarity);
396 return io_apic_setup_irq_pin(*out_hwirq, cpu_to_node(0), &attr);
399 static void __init ioapic_add_ofnode(struct device_node *np)
404 ret = of_address_to_resource(np, 0, &r);
406 printk(KERN_ERR "Failed to obtain address for %s\n",
411 for (i = 0; i < nr_ioapics; i++) {
412 if (r.start == mp_ioapics[i].apicaddr) {
413 struct irq_domain *id;
415 id = kzalloc(sizeof(*id), GFP_KERNEL);
418 id->xlate = ioapic_xlate;
419 id->priv = (void *)i;
420 add_interrupt_host(id);
424 printk(KERN_ERR "IOxAPIC at %s is not registered.\n", np->full_name);
427 void __init x86_add_irq_domains(void)
429 struct device_node *dp;
431 if (!of_have_populated_dt())
434 for_each_node_with_property(dp, "interrupt-controller") {
435 if (of_device_is_compatible(dp, "intel,ce4100-ioapic"))
436 ioapic_add_ofnode(dp);
440 void __init x86_add_irq_domains(void) { }