1 // SPDX-License-Identifier: GPL-2.0
3 * Architecture specific OF callbacks.
5 #include <linux/export.h>
7 #include <linux/interrupt.h>
8 #include <linux/list.h>
10 #include <linux/of_fdt.h>
11 #include <linux/of_address.h>
12 #include <linux/of_platform.h>
13 #include <linux/of_irq.h>
14 #include <linux/slab.h>
15 #include <linux/pci.h>
16 #include <linux/of_pci.h>
17 #include <linux/initrd.h>
19 #include <asm/irqdomain.h>
22 #include <asm/pci_x86.h>
23 #include <asm/setup.h>
24 #include <asm/i8259.h>
26 __initdata u64 initial_dtb
;
27 char __initdata cmd_line
[COMMAND_LINE_SIZE
];
29 int __initdata of_ioapic
;
31 void __init
early_init_dt_scan_chosen_arch(unsigned long node
)
36 void __init
early_init_dt_add_memory_arch(u64 base
, u64 size
)
41 void __init
add_dtb(u64 data
)
43 initial_dtb
= data
+ offsetof(struct setup_data
, data
);
47 * CE4100 ids. Will be moved to machine_device_initcall() once we have it.
49 static struct of_device_id __initdata ce4100_ids
[] = {
50 { .compatible
= "intel,ce4100-cp", },
51 { .compatible
= "isa", },
52 { .compatible
= "pci", },
56 static int __init
add_bus_probe(void)
58 if (!of_have_populated_dt())
61 return of_platform_bus_probe(NULL
, ce4100_ids
, NULL
);
63 device_initcall(add_bus_probe
);
66 struct device_node
*pcibios_get_phb_of_node(struct pci_bus
*bus
)
68 struct device_node
*np
;
70 for_each_node_by_type(np
, "pci") {
74 prop
= of_get_property(np
, "bus-range", NULL
);
77 bus_min
= be32_to_cpup(prop
);
78 if (bus
->number
== bus_min
)
84 static int x86_of_pci_irq_enable(struct pci_dev
*dev
)
90 ret
= pci_read_config_byte(dev
, PCI_INTERRUPT_PIN
, &pin
);
96 virq
= of_irq_parse_and_map_pci(dev
, 0, 0);
103 static void x86_of_pci_irq_disable(struct pci_dev
*dev
)
107 void x86_of_pci_init(void)
109 pcibios_enable_irq
= x86_of_pci_irq_enable
;
110 pcibios_disable_irq
= x86_of_pci_irq_disable
;
114 static void __init
dtb_setup_hpet(void)
116 #ifdef CONFIG_HPET_TIMER
117 struct device_node
*dn
;
121 dn
= of_find_compatible_node(NULL
, NULL
, "intel,ce4100-hpet");
124 ret
= of_address_to_resource(dn
, 0, &r
);
129 hpet_address
= r
.start
;
133 static void __init
dtb_lapic_setup(void)
135 #ifdef CONFIG_X86_LOCAL_APIC
136 struct device_node
*dn
;
140 dn
= of_find_compatible_node(NULL
, NULL
, "intel,ce4100-lapic");
144 ret
= of_address_to_resource(dn
, 0, &r
);
148 /* Did the boot loader setup the local APIC ? */
149 if (!boot_cpu_has(X86_FEATURE_APIC
)) {
150 if (apic_force_enable(r
.start
))
153 smp_found_config
= 1;
155 register_lapic_address(r
.start
);
156 generic_processor_info(boot_cpu_physical_apicid
,
157 GET_APIC_VERSION(apic_read(APIC_LVR
)));
161 #ifdef CONFIG_X86_IO_APIC
162 static unsigned int ioapic_id
;
164 struct of_ioapic_type
{
170 static struct of_ioapic_type of_ioapic_type
[] =
173 .out_type
= IRQ_TYPE_EDGE_RISING
,
174 .trigger
= IOAPIC_EDGE
,
178 .out_type
= IRQ_TYPE_LEVEL_LOW
,
179 .trigger
= IOAPIC_LEVEL
,
183 .out_type
= IRQ_TYPE_LEVEL_HIGH
,
184 .trigger
= IOAPIC_LEVEL
,
188 .out_type
= IRQ_TYPE_EDGE_FALLING
,
189 .trigger
= IOAPIC_EDGE
,
194 static int dt_irqdomain_alloc(struct irq_domain
*domain
, unsigned int virq
,
195 unsigned int nr_irqs
, void *arg
)
197 struct of_phandle_args
*irq_data
= (void *)arg
;
198 struct of_ioapic_type
*it
;
199 struct irq_alloc_info tmp
;
201 if (WARN_ON(irq_data
->args_count
< 2))
203 if (irq_data
->args
[1] >= ARRAY_SIZE(of_ioapic_type
))
206 it
= &of_ioapic_type
[irq_data
->args
[1]];
207 ioapic_set_alloc_attr(&tmp
, NUMA_NO_NODE
, it
->trigger
, it
->polarity
);
208 tmp
.ioapic_id
= mpc_ioapic_id(mp_irqdomain_ioapic_idx(domain
));
209 tmp
.ioapic_pin
= irq_data
->args
[0];
211 return mp_irqdomain_alloc(domain
, virq
, nr_irqs
, &tmp
);
214 static const struct irq_domain_ops ioapic_irq_domain_ops
= {
215 .alloc
= dt_irqdomain_alloc
,
216 .free
= mp_irqdomain_free
,
217 .activate
= mp_irqdomain_activate
,
218 .deactivate
= mp_irqdomain_deactivate
,
221 static void __init
dtb_add_ioapic(struct device_node
*dn
)
225 struct ioapic_domain_cfg cfg
= {
226 .type
= IOAPIC_DOMAIN_DYNAMIC
,
227 .ops
= &ioapic_irq_domain_ops
,
231 ret
= of_address_to_resource(dn
, 0, &r
);
233 printk(KERN_ERR
"Can't obtain address from device node %pOF.\n", dn
);
236 mp_register_ioapic(++ioapic_id
, r
.start
, gsi_top
, &cfg
);
239 static void __init
dtb_ioapic_setup(void)
241 struct device_node
*dn
;
243 for_each_compatible_node(dn
, NULL
, "intel,ce4100-ioapic")
250 printk(KERN_ERR
"Error: No information about IO-APIC in OF.\n");
253 static void __init
dtb_ioapic_setup(void) {}
256 static void __init
dtb_apic_setup(void)
262 #ifdef CONFIG_OF_FLATTREE
263 static void __init
x86_flattree_get_config(void)
271 map_len
= max(PAGE_SIZE
- (initial_dtb
& ~PAGE_MASK
), (u64
)128);
273 initial_boot_params
= dt
= early_memremap(initial_dtb
, map_len
);
274 size
= of_get_flat_dt_size();
275 if (map_len
< size
) {
276 early_memunmap(dt
, map_len
);
277 initial_boot_params
= dt
= early_memremap(initial_dtb
, size
);
281 unflatten_and_copy_device_tree();
282 early_memunmap(dt
, map_len
);
285 static inline void x86_flattree_get_config(void) { }
288 void __init
x86_dtb_init(void)
290 x86_flattree_get_config();
292 if (!of_have_populated_dt())