Skip to content

Commit f2ffa5a

Browse files
Dezhong Diaoglikely
authored andcommitted
of/mips: Add device tree support to MIPS
Add the ability to enable CONFIG_OF on the MIPS architecture. Signed-off-by: Dezhong Diao <dediao@cisco.com> [grant.likely@secretlab.ca: cleared out obsolete hooks, removed ARCH_HAS_DEVTREE_MEM, remove __init tags from header file, removed debugfs support hunk] [ddaney@linux-mips.org: backed out over aggressive trimming of hooks] Acked-by: Ralf Baechle <ralf@linux-mips.org> Tested-by: David Daney <ddaney@caviumnetworks.com> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
1 parent 32c9768 commit f2ffa5a

6 files changed

Lines changed: 163 additions & 0 deletions

File tree

‎arch/mips/Kconfig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,6 +2107,13 @@ config SECCOMP
21072107

21082108
If unsure, say Y. Only embedded should say N here.
21092109

2110+
config USE_OF
2111+
bool "Flattened Device Tree support"
2112+
select OF
2113+
select OF_FLATTREE
2114+
help
2115+
Include support for flattened device tree machine descriptions.
2116+
21102117
endmenu
21112118

21122119
config LOCKDEP_SUPPORT

‎arch/mips/include/asm/irq.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
#include <irq.h>
1818

19+
static inline void irq_dispose_mapping(unsigned int virq)
20+
{
21+
return;
22+
}
23+
1924
#ifdef CONFIG_I8259
2025
static inline int irq_canonicalize(int irq)
2126
{

‎arch/mips/include/asm/prom.h‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* arch/mips/include/asm/prom.h
3+
*
4+
* Copyright (C) 2010 Cisco Systems Inc. <dediao@cisco.com>
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 2 as
8+
* published by the Free Software Foundation.
9+
*
10+
*/
11+
#ifndef __ASM_MIPS_PROM_H
12+
#define __ASM_MIPS_PROM_H
13+
14+
#ifdef CONFIG_OF
15+
#include <linux/init.h>
16+
17+
#include <asm/setup.h>
18+
#include <asm/irq.h>
19+
#include <asm/bootinfo.h>
20+
21+
/* which is compatible with the flattened device tree (FDT) */
22+
#define cmd_line arcs_cmdline
23+
24+
extern int early_init_dt_scan_memory_arch(unsigned long node,
25+
const char *uname, int depth, void *data);
26+
27+
extern int reserve_mem_mach(unsigned long addr, unsigned long size);
28+
extern void free_mem_mach(unsigned long addr, unsigned long size);
29+
30+
extern void __init device_tree_init(void);
31+
#else /* CONFIG_OF */
32+
static inline void __init device_tree_init(void) { }
33+
#endif /* CONFIG_OF */
34+
35+
#endif /* _ASM_MIPS_PROM_H */

‎arch/mips/kernel/Makefile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o
9696
obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
9797
obj-$(CONFIG_SPINLOCK_TEST) += spinlock_test.o
9898

99+
obj-$(CONFIG_OF) += prom.o
100+
99101
CFLAGS_cpu-bugs64.o = $(shell if $(CC) $(KBUILD_CFLAGS) -Wa,-mdaddi -c -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-DHAVE_AS_SET_DADDI"; fi)
100102

101103
obj-$(CONFIG_HAVE_STD_PC_SERIAL_PORT) += 8250-platform.o

‎arch/mips/kernel/prom.c‎

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* MIPS support for CONFIG_OF device tree support
3+
*
4+
* Copyright (C) 2010 Cisco Systems Inc. <dediao@cisco.com>
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 2 as
8+
* published by the Free Software Foundation.
9+
*/
10+
11+
#include <linux/init.h>
12+
#include <linux/module.h>
13+
#include <linux/errno.h>
14+
#include <linux/types.h>
15+
#include <linux/bootmem.h>
16+
#include <linux/initrd.h>
17+
#include <linux/debugfs.h>
18+
#include <linux/of.h>
19+
#include <linux/of_fdt.h>
20+
#include <linux/of_irq.h>
21+
#include <linux/of_platform.h>
22+
23+
#include <asm/page.h>
24+
#include <asm/prom.h>
25+
26+
int __init early_init_dt_scan_memory_arch(unsigned long node,
27+
const char *uname, int depth,
28+
void *data)
29+
{
30+
return early_init_dt_scan_memory(node, uname, depth, data);
31+
}
32+
33+
void __init early_init_dt_add_memory_arch(u64 base, u64 size)
34+
{
35+
return add_memory_region(base, size, BOOT_MEM_RAM);
36+
}
37+
38+
int __init reserve_mem_mach(unsigned long addr, unsigned long size)
39+
{
40+
return reserve_bootmem(addr, size, BOOTMEM_DEFAULT);
41+
}
42+
43+
void __init free_mem_mach(unsigned long addr, unsigned long size)
44+
{
45+
return free_bootmem(addr, size);
46+
}
47+
48+
u64 __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
49+
{
50+
return virt_to_phys(
51+
__alloc_bootmem(size, align, __pa(MAX_DMA_ADDRESS))
52+
);
53+
}
54+
55+
#ifdef CONFIG_BLK_DEV_INITRD
56+
void __init early_init_dt_setup_initrd_arch(unsigned long start,
57+
unsigned long end)
58+
{
59+
initrd_start = (unsigned long)__va(start);
60+
initrd_end = (unsigned long)__va(end);
61+
initrd_below_start_ok = 1;
62+
}
63+
#endif
64+
65+
/*
66+
* irq_create_of_mapping - Hook to resolve OF irq specifier into a Linux irq#
67+
*
68+
* Currently the mapping mechanism is trivial; simple flat hwirq numbers are
69+
* mapped 1:1 onto Linux irq numbers. Cascaded irq controllers are not
70+
* supported.
71+
*/
72+
unsigned int irq_create_of_mapping(struct device_node *controller,
73+
const u32 *intspec, unsigned int intsize)
74+
{
75+
return intspec[0];
76+
}
77+
EXPORT_SYMBOL_GPL(irq_create_of_mapping);
78+
79+
void __init early_init_devtree(void *params)
80+
{
81+
/* Setup flat device-tree pointer */
82+
initial_boot_params = params;
83+
84+
/* Retrieve various informations from the /chosen node of the
85+
* device-tree, including the platform type, initrd location and
86+
* size, and more ...
87+
*/
88+
of_scan_flat_dt(early_init_dt_scan_chosen, NULL);
89+
90+
/* Scan memory nodes */
91+
of_scan_flat_dt(early_init_dt_scan_root, NULL);
92+
of_scan_flat_dt(early_init_dt_scan_memory_arch, NULL);
93+
}
94+
95+
void __init device_tree_init(void)
96+
{
97+
unsigned long base, size;
98+
99+
if (!initial_boot_params)
100+
return;
101+
102+
base = virt_to_phys((void *)initial_boot_params);
103+
size = initial_boot_params->totalsize;
104+
105+
/* Before we do anything, lets reserve the dt blob */
106+
reserve_mem_mach(base, size);
107+
108+
unflatten_device_tree();
109+
110+
/* free the space reserved for the dt blob */
111+
free_mem_mach(base, size);
112+
}

‎arch/mips/kernel/setup.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <asm/setup.h>
3232
#include <asm/smp-ops.h>
3333
#include <asm/system.h>
34+
#include <asm/prom.h>
3435

3536
struct cpuinfo_mips cpu_data[NR_CPUS] __read_mostly;
3637

@@ -487,6 +488,7 @@ static void __init arch_mem_init(char **cmdline_p)
487488
}
488489

489490
bootmem_init();
491+
device_tree_init();
490492
sparse_init();
491493
paging_init();
492494
}

0 commit comments

Comments
 (0)