Skip to contentSkip to conversation

MIPS: import CPU and cache detection code from Linux

RFC Superseded Antony Pavlov 3 participants 7 messages May 21, 2012 – May 22, 2012

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover MIPS: import CPU and cache detection code from Linux

THE PATCHES HAVE PRELIMINARY STATUS. PLEASE, DON'T COMMIT IT!

The patches lack support of Ingenic and Broadcom chips!

This patch series introduces MIPS cache support to barebox. It adds functions to detect CPU capabilities.

[RFC 1/3] MIPS: introduce C architecture-specific low-level init [RFC 2/3] MIPS: import CPU and cache detection code from Linux [RFC 3/3] MIPS: cpuinfo: import CPU message from Linux

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw

RFC 1/3 MIPS: introduce C architecture-specific low-level init

---
 arch/mips/boot/Makefile     |    1 +
 arch/mips/boot/main_entry.c |   45 +++++++++++++++++++++++++++++++++++++++++++
 arch/mips/boot/start.S      |   14 ++------------
 3 files changed, 48 insertions(+), 12 deletions(-)
 create mode 100644 arch/mips/boot/main_entry.c
arch/mips/boot/Makefile +1 -0
index f9151d2..d6d28ce 100644
@@ -1 +1,2 @@
 obj-y += start.o
+obj-y += main_entry.o
arch/mips/boot/main_entry.c new file +45 -0

45 lines not on this page · raw message

arch/mips/boot/start.S +2 -12
index e8868e1..dd302fc 100644
@@ -79,7 +79,7 @@ __start:
 
 	la	a1, _start	/* link (RAM) _start address */
 
-	beq	a0, a1, clear_bss
+	beq	a0, a1, stack_setup
 	 nop
 
 	la	t0, _start
@@ -105,16 +105,6 @@ copy_loop:
 	blez		t3, copy_loop
 	addi		a1, LONGSIZE * 4
 
-clear_bss:
-	la	t0, __bss_start
-	sw	zero, (t0)
-	la	t1, _end - 4
-1:
-	addiu	t0, LONGSIZE
-	sw	zero, (t0)
-	bne	t0, t1, 1b
-	 nop
-
 	/*
 	 * Dominic Sweetman, See MIPS Run, Morgan Kaufmann, 2nd edition, 2006
 	 *
@@ -144,7 +134,7 @@ stack_setup:
 	/* reserve four 32-bit argument slots */
 	addiu	sp, -16
 
-	la	v0, start_barebox
+	la	v0, main_entry
 	jal     v0
 	 nop
 
Signature · 7 lines
1.7.10


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#3 lore raw

RFC 2/3 MIPS: import CPU and cache detection code from Linux

In reply to Antony Pavlov
---
 arch/mips/boot/main_entry.c          |    9 ++
 arch/mips/include/asm/bitops.h       |    2 +-
 arch/mips/include/asm/cpu-features.h |  254 ++++++++++++++++++++++++++++++++++
 arch/mips/include/asm/cpu-info.h     |   71 ++++++++++
 arch/mips/include/asm/cpu.h          |  153 ++++++++++++++++++++
 arch/mips/lib/Makefile               |    4 +
 arch/mips/lib/c-r4k.c                |   85 ++++++++++++
 arch/mips/lib/cpu-probe.c            |  103 ++++++++++++++
 8 files changed, 680 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/include/asm/cpu-features.h
 create mode 100644 arch/mips/include/asm/cpu-info.h
 create mode 100644 arch/mips/include/asm/cpu.h
 create mode 100644 arch/mips/lib/c-r4k.c
 create mode 100644 arch/mips/lib/cpu-probe.c
arch/mips/boot/main_entry.c +9 -0
index fa072de..da482cf 100644
@@ -26,6 +26,7 @@
 #include <common.h>
 #include <string.h>
 #include <asm/sections.h>
+#include <asm/cpu-features.h>
 
 extern void start_barebox(void);
 
@@ -41,5 +42,13 @@ void main_entry(void)
 	/* clear the BSS first */
 	memset(__bss_start, 0x00, __bss_stop - __bss_start);
 
+	cpu_probe();
+
+	if (cpu_has_4k_cache) {
+		extern void __weak r4k_cache_init(void);
+
+		r4k_cache_init();
+	}
+
 	start_barebox();
 }
arch/mips/include/asm/bitops.h +1 -1
index 36d34b6..001ebf2 100644
@@ -27,6 +27,6 @@
 #ifndef _ASM_MIPS_BITOPS_H_
 #define _ASM_MIPS_BITOPS_H_
 
-/* nothing special yet */
+#include <asm-generic/bitops/__ffs.h>
 
 #endif /* _ASM_MIPS_BITOPS_H_ */
arch/mips/include/asm/cpu-features.h new file +254 -0

254 lines not on this page · raw message

arch/mips/include/asm/cpu-info.h new file +71 -0

71 lines not on this page · raw message

arch/mips/include/asm/cpu.h new file +153 -0

153 lines not on this page · raw message

arch/mips/lib/Makefile +4 -0
index 85aa194..b99bb71 100644
@@ -4,6 +4,10 @@ obj-y += lshrdi3.o
 obj-y += ashldi3.o
 obj-y += ashrdi3.o
 obj-y += memory.o
+obj-y += cpu-probe.o
+
+obj-$(CONFIG_CPU_MIPS32) += c-r4k.o
+obj-$(CONFIG_CPU_MIPS64) += c-r4k.o
 
 obj-$(CONFIG_CMD_MIPS_CPUINFO) += cpuinfo.o
 obj-$(CONFIG_CMD_BOOTM)	+= bootm.o
arch/mips/lib/c-r4k.c new file +85 -0

85 lines not on this page · raw message

arch/mips/lib/cpu-probe.c new file +103 -0

103 lines not on this page · raw message

Signature · 7 lines
1.7.10


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

RFC 3/3 MIPS: cpuinfo: import CPU message from Linux

In reply to Antony Pavlov
---
 arch/mips/lib/cpuinfo.c |   27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
arch/mips/lib/cpuinfo.c +25 -2
index fc8fb00..71477a8 100644
@@ -23,11 +23,34 @@
 #include <common.h>
 #include <command.h>
 #include <asm/mipsregs.h>
+#include <asm/cpu-info.h>
+
+static char *way_string[] /* __cpuinitdata */= { NULL, "direct mapped", "2-way",
+	"3-way", "4-way", "5-way", "6-way", "7-way", "8-way"
+};
 
 static int do_cpuinfo(int argc, char *argv[])
 {
-	printf("CP0_PRID = 0x%08x\n", read_c0_prid());
-	printf("CP0_CONFIG = 0x%08x\n", read_c0_config());
+	unsigned int icache_size, dcache_size;
+	struct cpuinfo_mips *c = &current_cpu_data;
+
+	printk(KERN_INFO "CPU revision is: %08x (%s)\n",
+		current_cpu_data.processor_id, __cpu_name);
+
+	icache_size = c->icache.sets * c->icache.ways * c->icache.linesz;
+	dcache_size = c->dcache.sets * c->dcache.ways * c->dcache.linesz;
+
+	printk("Primary instruction cache %ldkB, %s, %s, linesize %d bytes.\n",
+	       icache_size >> 10,
+	       c->icache.flags & MIPS_CACHE_VTAG ? "VIVT" : "VIPT",
+	       way_string[c->icache.ways], c->icache.linesz);
+
+	printk("Primary data cache %ldkB, %s, %s, %s, linesize %d bytes\n",
+	       dcache_size >> 10, way_string[c->dcache.ways],
+	       (c->dcache.flags & MIPS_CACHE_PINDEX) ? "PIPT" : "VIPT",
+	       (c->dcache.flags & MIPS_CACHE_ALIASES) ?
+			"cache aliases" : "no aliases",
+	       c->dcache.linesz);
 
 	return 0;
 }
Signature · 7 lines
1.7.10


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw
In reply to Antony Pavlov
Quoted 1 line · Antony Pavlov

THE PATCHES HAVE PRELIMINARY STATUS. PLEASE, DON'T COMMIT IT!

That was clear enough, even for me ;)

Unfortunately I can't say anything to this series as I've never used MIPS.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox