Skip to contentSkip to conversation

PPC 85xx: Add support for QEMU's ppce500 PV machine

PATCH Superseded Alexander Graf 4 participants 18 messages Jan 19, 2014 – Mar 6, 2014 PowerPC

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover PPC 85xx: Add support for QEMU's ppce500 PV machine

In QEMU we implement a PV machine type called "ppce500". That board is able to run any e500+ FSL cores (e500v2, e500mc, e5500, e6500).

It is heavily inspired by the MPC8544DS SoC and board combination, but implements only the bare minimum to make Linux happy enough to drive a virtual machine.

This patch set implements support for this PV machine type in U-Boot, enabling users to run their virtual machines with netboot, u-boot payload binaries or other fun things they come up with.

Alexander Graf (3):
PPC 85xx: Detect e500v2 / e500mc during runtime
PPC 85xx: Add ELF entry point
PPC 85xx: Add qemu-ppce500 machine

 arch/powerpc/cpu/mpc85xx/fixed_ivor.S       |   21 ++-
 arch/powerpc/cpu/mpc85xx/start.S            |    7 +
 arch/powerpc/cpu/mpc85xx/u-boot.lds         |    1 +
 arch/powerpc/include/asm/config_mpc85xx.h   |    4 +
 board/freescale/qemu-ppce500/Makefile       |   10 ++
 board/freescale/qemu-ppce500/qemu-ppce500.c |  260 +++++++++++++++++++++++++++
 board/freescale/qemu-ppce500/tlb.c          |   59 ++++++
 boards.cfg                                  |    1 +
 include/configs/qemu-ppce500.h              |  235 ++++++++++++++++++++++++
 9 files changed, 593 insertions(+), 5 deletions(-)
 create mode 100644 board/freescale/qemu-ppce500/Makefile
 create mode 100644 board/freescale/qemu-ppce500/qemu-ppce500.c
 create mode 100644 board/freescale/qemu-ppce500/tlb.c
 create mode 100644 include/configs/qemu-ppce500.h
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/3 PPC 85xx: Detect e500v2 / e500mc during runtime

With the qemu-ppce500 machine type we can run the same board with either an e500v2 or an e500mc core plugged in.

This means that the IVOR setup can't be based on compile time decisions, so instead we have to do a runtime check which CPU generation we're running on.

---
 arch/powerpc/cpu/mpc85xx/fixed_ivor.S |   21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
arch/powerpc/cpu/mpc85xx/fixed_ivor.S +16 -5
index ebbb8c0..635a97e 100644
@@ -36,17 +36,25 @@
 	SET_IVOR(14, 0x1e0) /* Instruction TLB Error */
 	SET_IVOR(15, 0x040) /* Debug */
 
-/* e500v1 & e500v2 only */
-#ifndef CONFIG_E500MC
+	/* Check for CPU */
+	mfpvr	r3
+	srwi	r3, r3, 16
+	/* Compare with e500mc PVR major number */
+	li	r4, 0
+	ori	r4, r4, 0x8023
+	cmpw	r3, r4
+
+	/* e500v1 & e500v2 only */
+	bge	1f
 	SET_IVOR(32, 0x200) /* SPE Unavailable */
 	SET_IVOR(33, 0x220) /* Embedded FP Data */
 	SET_IVOR(34, 0x240) /* Embedded FP Round */
-#endif
+1:
 
 	SET_IVOR(35, 0x260) /* Performance monitor */
 
-/* e500mc only */
-#ifdef CONFIG_E500MC
+	/* e500mc only */
+	blt	2f
 	SET_IVOR(36, 0x280) /* Processor doorbell */
 	SET_IVOR(37, 0x2a0) /* Processor doorbell critical */
 	SET_IVOR(38, 0x2c0) /* Guest Processor doorbell */
@@ -54,6 +62,8 @@
 	SET_IVOR(40, 0x300) /* Hypervisor system call */
 	SET_IVOR(41, 0x320) /* Hypervisor Priviledge */
 
+#ifndef CONFIG_QEMU_E500
+	/* QEMU guests runs in guest mode and can't access GIVORs */
 	SET_GIVOR(2, 0x060) /* Guest Data Storage */
 	SET_GIVOR(3, 0x080) /* Guest Instruction Storage */
 	SET_GIVOR(4, 0x0a0) /* Guest External Input */
@@ -61,3 +71,4 @@
 	SET_GIVOR(13, 0x1c0) /* Guest Data TLB Error */
 	SET_GIVOR(14, 0x1e0) /* Guest Instruction TLB Error */
 #endif
+2:
Signature · 1 line
1.7.10.4
#8 lore raw

PATCH 2/3 PPC 85xx: Add ELF entry point

In reply to Alexander Graf

We want to be able to directly execute the ELF binary without going through the u-boot.bin one.

To know where we have to start executing this ELF binary we have to tell the linker where our entry point is.

---
 arch/powerpc/cpu/mpc85xx/u-boot.lds |    1 +
 1 file changed, 1 insertion(+)
arch/powerpc/cpu/mpc85xx/u-boot.lds +1 -0
index 2af4c80..b34d212 100644
@@ -13,6 +13,7 @@
 #endif
 
 OUTPUT_ARCH(powerpc)
+ENTRY(_start_e500)
 
 PHDRS
 {
Signature · 1 line
1.7.10.4
#9 lore raw

PATCH 3/3 PPC 85xx: Add qemu-ppce500 machine

In reply to Alexander Graf

For KVM we have a special PV machine type called "ppce500". This machine is inspired by the MPC8544DS board, but implements a lot less features than that one.

It also provides more PCI slots and is supposed to be enumerated by device tree only.

This patch adds support for the current generation ppce500 machine as it is implemented today.

---
 arch/powerpc/cpu/mpc85xx/start.S            |    7 +
 arch/powerpc/include/asm/config_mpc85xx.h   |    4 +
 board/freescale/qemu-ppce500/Makefile       |   10 ++
 board/freescale/qemu-ppce500/qemu-ppce500.c |  260 +++++++++++++++++++++++++++
 board/freescale/qemu-ppce500/tlb.c          |   59 ++++++
 boards.cfg                                  |    1 +
 include/configs/qemu-ppce500.h              |  235 ++++++++++++++++++++++++
 7 files changed, 576 insertions(+)
 create mode 100644 board/freescale/qemu-ppce500/Makefile
 create mode 100644 board/freescale/qemu-ppce500/qemu-ppce500.c
 create mode 100644 board/freescale/qemu-ppce500/tlb.c
 create mode 100644 include/configs/qemu-ppce500.h
arch/powerpc/cpu/mpc85xx/start.S +7 -0
index db84d10..ccbcc03 100644
@@ -80,6 +80,13 @@ _start_e500:
 	li	r1,MSR_DE
 	mtmsr 	r1
 
+#ifdef CONFIG_QEMU_E500
+	/* Save our ePAPR device tree off before we clobber it */
+	lis	r2, CONFIG_QEMU_DT_ADDR at h
+	ori	r2, r2, CONFIG_QEMU_DT_ADDR at l
+	stw	r3, 0(r2)
+#endif
+
 #ifdef CONFIG_SYS_FSL_ERRATUM_A004510
 	mfspr	r3,SPRN_SVR
 	rlwinm	r3,r3,0,0xff
arch/powerpc/include/asm/config_mpc85xx.h +4 -0
index 54ce2f0..a0ab453 100644
@@ -776,6 +776,10 @@ defined(CONFIG_PPC_T1020) || defined(CONFIG_PPC_T1022)
 #define CONFIG_SYS_CCSRBAR_DEFAULT	0xff700000
 #define CONFIG_SYS_FSL_ERRATUM_A005125
 
+#elif defined(CONFIG_QEMU_E500)
+#define CONFIG_MAX_CPUS			1
+#define CONFIG_SYS_CCSRBAR_DEFAULT	0xe0000000
+
 #else
 #error Processor type not defined for this platform
 #endif
board/freescale/qemu-ppce500/Makefile new file +10 -0
new file mode 100644
index 0000000..193b160
@@ -0,0 +1,10 @@
+#
+# Copyright 2007 Freescale Semiconductor, Inc.
+# (C) Copyright 2001-2006
+# Wolfgang Denk, DENX Software Engineering, wd at denx.de.
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-y	+= qemu-ppce500.o
+obj-y	+= tlb.o
board/freescale/qemu-ppce500/qemu-ppce500.c new file +260 -0

260 lines not on this page · raw message

board/freescale/qemu-ppce500/tlb.c new file +59 -0

59 lines not on this page · raw message

boards.cfg +1 -0
index d177f82..ab50982 100644
@@ -986,6 +986,7 @@ Active  powerpc     mpc85xx        -           freescale       t2080qds
 Active  powerpc     mpc85xx        -           freescale       t2080qds            T2080QDS_SPIFLASH     T2080QDS:PPC_T2080,RAMBOOT_PBL,SPIFLASH,SYS_TEXT_BASE=0xFFF80000
 Active  powerpc     mpc85xx        -           freescale       t2080qds            T2080QDS_NAND         T2080QDS:PPC_T2080,RAMBOOT_PBL,NAND,SYS_TEXT_BASE=0xFFF80000
 Active  powerpc     mpc85xx        -           freescale       t2080qds            T2080QDS_SRIO_PCIE_BOOT  T2080QDS:PPC_T2080,SRIO_PCIE_BOOT_SLAVE,SYS_TEXT_BASE=0xFFF80000
+Active  powerpc     mpc85xx        -           freescale       qemu-ppce500        qemu-ppce500                         -                                                                                                                                 Alexander Graf <[email protected]>
 Active  powerpc     mpc85xx        -           gdsys           p1022               controlcenterd_36BIT_SDCARD          controlcenterd:36BIT,SDCARD                                                                                                       Dirk Eibach <[email protected]>
 Active  powerpc     mpc85xx        -           gdsys           p1022               controlcenterd_36BIT_SDCARD_DEVELOP  controlcenterd:36BIT,SDCARD,DEVELOP                                                                                               Dirk Eibach <[email protected]>
 Active  powerpc     mpc85xx        -           gdsys           p1022               controlcenterd_TRAILBLAZER           controlcenterd:TRAILBLAZER,SPIFLASH                                                                                               Dirk Eibach <[email protected]>
include/configs/qemu-ppce500.h new file +235 -0

235 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#10 lore raw

PATCH 3/3 PPC 85xx: Add qemu-ppce500 machine

Quoted 30 lines · Alexander Graf

For KVM we have a special PV machine type called "ppce500". This machine is inspired by the MPC8544DS board, but implements a lot less features than that one.

It also provides more PCI slots and is supposed to be enumerated by device tree only.

This patch adds support for the current generation ppce500 machine as it is implemented today.

---
 arch/powerpc/cpu/mpc85xx/start.S            |    7 +
 arch/powerpc/include/asm/config_mpc85xx.h   |    4 +
 board/freescale/qemu-ppce500/Makefile       |   10 ++
 board/freescale/qemu-ppce500/qemu-ppce500.c |  260 +++++++++++++++++++++++++++
 board/freescale/qemu-ppce500/tlb.c          |   59 ++++++
 boards.cfg                                  |    1 +
 include/configs/qemu-ppce500.h              |  235 ++++++++++++++++++++++++
 7 files changed, 576 insertions(+)
 create mode 100644 board/freescale/qemu-ppce500/Makefile
 create mode 100644 board/freescale/qemu-ppce500/qemu-ppce500.c
 create mode 100644 board/freescale/qemu-ppce500/tlb.c
 create mode 100644 include/configs/qemu-ppce500.h
arch/powerpc/cpu/mpc85xx/start.S +0 -0
index db84d10..ccbcc03 100644

arch/powerpc/cpu/mpc85xx/start.S _start_e500: · line 88

Quoted 9 lines
arch/powerpc/cpu/mpc85xx/start.S +6 -0
@@ -80,6 +80,13 @@ _start_e500:
 	li	r1,MSR_DE
 	mtmsr 	r1
 
+#ifdef CONFIG_QEMU_E500
+	/* Save our ePAPR device tree off before we clobber it */
+	lis	r2, CONFIG_QEMU_DT_ADDR at h
+	ori	r2, r2, CONFIG_QEMU_DT_ADDR at l
+	stw	r3, 0(r2)
+#endif

r2 has a special purpose -- please don't use it for other things, even if it's too early to be a problem and other code is similarly bad.

Instead of saving the DT pointer in some random hardcoded address, how about sticking it in a callee-saved register until you're able to store it in the global data struct?

arch/powerpc/include/asm/config_mpc85xx.h defined(CONFIG_PPC_T1020) || defined(CONFIG_PPC_T1022) · line 781

Quoted 11 lines
arch/powerpc/include/asm/config_mpc85xx.h +3 -0
index 54ce2f0..a0ab453 100644
@@ -776,6 +776,10 @@ defined(CONFIG_PPC_T1020) || defined(CONFIG_PPC_T1022)
 #define CONFIG_SYS_CCSRBAR_DEFAULT	0xff700000
 #define CONFIG_SYS_FSL_ERRATUM_A005125
 
+#elif defined(CONFIG_QEMU_E500)
+#define CONFIG_MAX_CPUS			1
+#define CONFIG_SYS_CCSRBAR_DEFAULT	0xe0000000

This is supposed to come from the device tree. We will want to change that address eventually to support larger guest memory.

Quoted 17 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +11 -0
new file mode 100644
index 0000000..c6c4b4a
@@ -0,0 +1,260 @@
+/*
+ * Copyright 2007,2009-2014 Freescale Semiconductor, Inc.
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <pci.h>
+#include <asm/processor.h>
+#include <asm/mmu.h>

board/freescale/qemu-ppce500/qemu-ppce500.c line 21

Quoted 10 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +10 -0
+#include <asm/immap_85xx.h>
+#include <asm/fsl_pci.h>
+#include <asm/io.h>
+#include <miiphy.h>
+#include <libfdt.h>
+#include <fdt_support.h>
+#include <netdev.h>
+#include <fdtdec.h>
+#include <errno.h>
+#include <malloc.h>

Do you really need all these headers? miiphy?

Quoted 8 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +8 -0
+int checkboard(void)
+{
+	return 0;
+}
+
+static struct pci_controller pci1_hose;
+
+void pci_init_board(void)

board/freescale/qemu-ppce500/qemu-ppce500.c line 40

Quoted 10 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +10 -0
+{
+	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
+	struct fsl_pci_info pci_info;
+	u32 devdisr, pordevsr;
+	u32 porpllsr, pci_agent, pci_speed, pci_32, pci_arb, pci_clk_sel;
+	int first_free_busno = 0;
+
+	devdisr = in_be32(&gur->devdisr);
+	pordevsr = in_be32(&gur->pordevsr);
+	porpllsr = in_be32(&gur->porpllsr);

Why are you reading registers that don't exist in QEMU?

board/freescale/qemu-ppce500/qemu-ppce500.c line 77

Quoted 7 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +7 -0
+int last_stage_init(void)
+{
+	int ret;
+	int len = 0;
+	const void *prop;
+	int chosen;
+        uint32_t *dt_base_ptr = (void*)CONFIG_QEMU_DT_ADDR;

Whitespace

board/freescale/qemu-ppce500/qemu-ppce500.c line 82

Quoted 5 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +5 -0
+	uint32_t dt_base = *dt_base_ptr;
+	uint32_t dt_size;
+	void *fdt;
+
+	dt_size = fdt_totalsize((void*)dt_base);

Please put a space before the * in casts.

Quoted 11 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +11 -0
+	/* Reserve 4k for dtb tweaks */
+	dt_size += 4096;
+	fdt = malloc(dt_size);
+
+	/* Open device tree */
+	ret = fdt_open_into((void*)dt_base, fdt, dt_size);
+	if (ret) {
+		printf("Couldn't open fdt at %x\n", dt_base);
+		return -EIO;
+	}
+

board/freescale/qemu-ppce500/qemu-ppce500.c line 104

Quoted 10 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +10 -0
+	chosen = fdt_path_offset(fdt, "/chosen");
+	if (chosen < 0) {
+		printf("Couldn't find /chosen node in fdt\n");
+		return -EIO;
+	}
+
+	prop = fdt_getprop(fdt, chosen, "qemu,boot-kernel", &len);
+	if (prop && (len >= 8)) {
+		/* -kernel boot */
+		setenv_hex("kernel_addr", *(uint64_t*)prop);

Don't cast away the const. This looks like the only place you use prop; why not make it uint64_t to begin with?

board/freescale/qemu-ppce500/qemu-ppce500.c line 110

Quoted 5 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +5 -0
+		/*
+		 * We already know where the initrd is inside the dtb, so no
+		 * need to override it
+		 */
+			setenv("ramdisk_addr", "-");

Indentation.

What if the user wants to specify the initrd from within U-Boot? This should be handled via the default environment, not by overriding the user's choice.

board/freescale/qemu-ppce500/qemu-ppce500.c line 114

Quoted 4 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +4 -0
+	}
+
+	/* Give the user a variable for the host fdt */
+	setenv_hex("fdt_addr", (int)dt_base);

Unnecessary cast.

board/freescale/qemu-ppce500/qemu-ppce500.c line 119

Quoted 5 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +5 -0
+
+	free(fdt);
+
+	return 0;
+}

Why is the device tree handling here different from anything else we already have? In particular, why do you create a temporary fdt (with space for tweaks that never happen) just to read from it?

board/freescale/qemu-ppce500/qemu-ppce500.c line 126

Quoted 6 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +6 -0
+static uint64_t get_linear_ram_size(void)
+{
+	const void *prop;
+	int memory;
+	int len;
+        uint32_t *dt_base_ptr = (void*)CONFIG_QEMU_DT_ADDR;

Whitespace.

Quoted 8 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +7 -0
+	void *fdt = &dt_base_ptr[1];
 
+	int ret;
+	uint32_t dt_base = *dt_base_ptr;
+	uint32_t dt_size = 1024 * 1024;
+
+	ret = fdt_open_into((void*)dt_base, fdt, dt_size);
+	if (ret)

board/freescale/qemu-ppce500/qemu-ppce500.c line 143

Quoted 10 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +10 -0
+		panic("Couldn't open fdt");
+
+	memory = fdt_path_offset(fdt, "/memory");
+	prop = fdt_getprop(fdt, memory, "reg", &len);
+
+	if (prop && len >= 16)
+		return *(uint64_t*)(prop+8);
+
+	panic("Couldn't determine RAM size");
+}

Again, there's no need to create a temporary fdt copy every time you want to read from it.

What if memory doesn't start at zero (e.g. for e500v2 VFIO)?

board/freescale/qemu-ppce500/qemu-ppce500.c line 150

Quoted 6 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +6 -0
+unsigned long
+get_board_sys_clk(ulong dummy)
+{
+	/* The actual clock doesn't matter in a PV machine */
+	return 33333333;
+}

s/doesn't matter/doesn't exist/

Where is this used from? Can it be skipped for this target? Is the CPU timebase handled properly?

board/freescale/qemu-ppce500/qemu-ppce500.c line 156

Quoted 4 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +4 -0
+int board_phy_config(struct phy_device *phydev)
+{
+	return 0;
+}

Why?

mpc8544ds is the only board in boards/freescale that has this, so it's clearly optional, and you clearly don't need it...

Just because QEMU started with mpc8544ds doesn't mean this needs to be a copy-and-paste of the U-Boot mpc8544ds code. In fact it's better if it isn't to reduce the likelihood of accidentally depending on hardcoded addresses and such.

Quoted 24 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +24 -0
+int board_eth_init(bd_t *bis)
+{
+	return pci_eth_init(bis);
+}
+
+#if defined(CONFIG_OF_BOARD_SETUP)
+void ft_board_setup(void *blob, bd_t *bd)
+{
+	FT_FSL_PCI_SETUP;
+}
+#endif
+
+void print_laws(void)
+{
+	/* We don't emulate LAWs yet */
+}
+
+static void fixup_tlb1(uint64_t ram_size)
+{
+	u32 mas0, mas1, mas2, mas3, mas7;
+	long tmp;
+
+	/* Flush TLB0 - it only contains stale maps by now */
+	invalidate_tlb(0);

board/freescale/qemu-ppce500/qemu-ppce500.c line 192

Quoted 10 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +10 -0
+
+	/* Create a temporary AS=1 map for ourselves */
+        mas0 = MAS0_TLBSEL(1) | MAS0_ESEL(13);
+        mas1 = MAS1_VALID | MAS1_TID(0) | MAS1_TS | MAS1_TSIZE(BOOKE_PAGESZ_64M);
+        mas2 = FSL_BOOKE_MAS2(0, 0);
+        mas3 = FSL_BOOKE_MAS3(CONFIG_SYS_DDR_SDRAM_BASE, 0,
+			      MAS3_SW|MAS3_SR|MAS3_SX);
+        mas7 = FSL_BOOKE_MAS7(CONFIG_SYS_DDR_SDRAM_BASE);
+
+        write_tlb(mas0, mas1, mas2, mas3, mas7);

Whitespace. Please run scripts/checkpatch.pl.

Quoted 25 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +25 -0
+
+	/* Enter AS=1 */
+	asm volatile(
+		"mfmsr	%0			\n"
+		"ori	%0, %0, 0x30		\n"
+		"mtsrr1	%0			\n"
+		"bl	1f			\n"
+		"1:				\n"
+		"mflr	%0			\n"
+		"addi	%0, %0, 16		\n"
+		"mtsrr0	%0			\n"
+		"rfi				\n"
+	: "=r"(tmp) : : "lr");
+
+	/* Now we live in AS=1, so we can flush all old maps */
+	clear_ddr_tlbs(ram_size >> 20);
+	/* and create new ones */
+	setup_ddr_tlbs(ram_size >> 20);
+
+	/* Now we can safely go back to AS=0 */
+	asm volatile(
+		"mfmsr	%0			\n"
+		"subi	%0, %0, 0x30		\n"
+		"mtsrr1	%0			\n"
+		"bl	1f			\n"

board/freescale/qemu-ppce500/qemu-ppce500.c line 227

Quoted 10 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +10 -0
+		"1:				\n"
+		"mflr	%0			\n"
+		"addi	%0, %0, 16		\n"
+		"mtsrr0	%0			\n"
+		"rfi				\n"
+	: "=r"(tmp) : : "lr");
+
+	/* And remove our AS=1 map */
+	disable_tlb(13);
+}

Why aren't we already in AS1? What code are you replacing with this?

Quoted 22 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +22 -0
+phys_size_t fixed_sdram(void)
+{
+	uint64_t ram_size;
+
+	ram_size = get_linear_ram_size();
+
+	/*
+	 * At this point we know that we're running in RAM, but within the
+	 * first 64MB because we don't have a mapping for anything else.
+	 *
+	 * Replace that mapping with real maps for our full RAM range.
+	 */
+	fixup_tlb1(ram_size);
+
+	return ram_size;
+}
+
+phys_size_t fsl_ddr_sdram_size(void)
+{
+	return fixed_sdram();
+}
+

board/freescale/qemu-ppce500/qemu-ppce500.c line 260

Quoted 10 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +10 -0
+void init_laws(void)
+{
+	/* We don't emulate LAWs yet */
+}
+
+int set_next_law(phys_addr_t addr, enum law_size sz, enum law_trgt_if id)
+{
+	/* We don't emulate LAWs yet */
+	return 0;
+}

What is calling set_next_law()?

Quoted 22 lines
board/freescale/qemu-ppce500/tlb.c new file +16 -0
new file mode 100644
index 0000000..cdc7013
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2008 Freescale Semiconductor, Inc.
+ *
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, wd at denx.de.
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/mmu.h>
+
+struct fsl_e_tlb_entry tlb_table[] = {
+	/* TLB 0 - for temp stack in cache */
+	SET_TLB_ENTRY(0, CONFIG_SYS_INIT_RAM_ADDR, CONFIG_SYS_INIT_RAM_ADDR,
+		      MAS3_SX|MAS3_SW|MAS3_SR, 0,

board/freescale/qemu-ppce500/tlb.c line 26

Quoted 10 lines
board/freescale/qemu-ppce500/tlb.c new file +10 -0
+		      0, 0, BOOKE_PAGESZ_4K, 0),
+	SET_TLB_ENTRY(0, CONFIG_SYS_INIT_RAM_ADDR + 4 * 1024 , CONFIG_SYS_INIT_RAM_ADDR + 4 * 1024,
+		      MAS3_SX|MAS3_SW|MAS3_SR, 0,
+		      0, 0, BOOKE_PAGESZ_4K, 0),
+	SET_TLB_ENTRY(0, CONFIG_SYS_INIT_RAM_ADDR + 8 * 1024 , CONFIG_SYS_INIT_RAM_ADDR + 8 * 1024,
+		      MAS3_SX|MAS3_SW|MAS3_SR, 0,
+		      0, 0, BOOKE_PAGESZ_4K, 0),
+	SET_TLB_ENTRY(0, CONFIG_SYS_INIT_RAM_ADDR + 12 * 1024 , CONFIG_SYS_INIT_RAM_ADDR + 12 * 1024,
+		      MAS3_SX|MAS3_SW|MAS3_SR, 0,
+		      0, 0, BOOKE_PAGESZ_4K, 0),

Isn't this just normal RAM? Thus, aren't you creating overlapping TLB entries here?

Quoted 21 lines
board/freescale/qemu-ppce500/tlb.c new file +21 -0
+	/*
+	 * TLB 0:	64M	Cacheable
+	 * 0x00000000	64M	Covers RAM at 0x00000000
+	 */
+	SET_TLB_ENTRY(1, CONFIG_SYS_BOOT_BLOCK, CONFIG_SYS_BOOT_BLOCK,
+		      MAS3_SX|MAS3_SW|MAS3_SR, 0,
+		      0, 0, BOOKE_PAGESZ_64M, 1),
+
+	/*
+	 * TLB 1:	256M	Non-cacheable, guarded
+	 */
+	SET_TLB_ENTRY(1, CONFIG_SYS_PCI_VIRT, CONFIG_SYS_PCI_PHYS,
+		      MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
+		      0, 1, BOOKE_PAGESZ_256M, 1),
+
+	/*
+	 * TLB 2:	256M	Non-cacheable, guarded
+	 */
+	SET_TLB_ENTRY(1, CONFIG_SYS_PCI_VIRT + 0x10000000, CONFIG_SYS_PCI_PHYS + 0x10000000,
+		      MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
+		      0, 2, BOOKE_PAGESZ_256M, 1),

board/freescale/qemu-ppce500/tlb.c line 57

Quoted 10 lines
board/freescale/qemu-ppce500/tlb.c new file +10 -0
+
+	/*
+	 * TLB 3:	64M	Non-cacheable, guarded
+	 * 0xe000_0000	1M	CCSRBAR
+	 * 0xe100_0000	255M	PCI IO range
+	 */
+	SET_TLB_ENTRY(1, CONFIG_SYS_CCSRBAR, CONFIG_SYS_CCSRBAR_PHYS,
+		      MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
+		      0, 3, BOOKE_PAGESZ_64M, 1),
+};

These should not be executable.

Quoted 35 lines
board/freescale/qemu-ppce500/tlb.c new file +2 -0
+
+int num_tlb_entries = ARRAY_SIZE(tlb_table);
boards.cfg +1 -0
index d177f82..ab50982 100644
@@ -986,6 +986,7 @@ Active  powerpc     mpc85xx        -           freescale       t2080qds
 Active  powerpc     mpc85xx        -           freescale       t2080qds            T2080QDS_SPIFLASH     T2080QDS:PPC_T2080,RAMBOOT_PBL,SPIFLASH,SYS_TEXT_BASE=0xFFF80000
 Active  powerpc     mpc85xx        -           freescale       t2080qds            T2080QDS_NAND         T2080QDS:PPC_T2080,RAMBOOT_PBL,NAND,SYS_TEXT_BASE=0xFFF80000
 Active  powerpc     mpc85xx        -           freescale       t2080qds            T2080QDS_SRIO_PCIE_BOOT  T2080QDS:PPC_T2080,SRIO_PCIE_BOOT_SLAVE,SYS_TEXT_BASE=0xFFF80000
+Active  powerpc     mpc85xx        -           freescale       qemu-ppce500        qemu-ppce500                         -                                                                                                                                 Alexander Graf <[email protected]>
 Active  powerpc     mpc85xx        -           gdsys           p1022               controlcenterd_36BIT_SDCARD          controlcenterd:36BIT,SDCARD                                                                                                       Dirk Eibach <[email protected]>
 Active  powerpc     mpc85xx        -           gdsys           p1022               controlcenterd_36BIT_SDCARD_DEVELOP  controlcenterd:36BIT,SDCARD,DEVELOP                                                                                               Dirk Eibach <[email protected]>
 Active  powerpc     mpc85xx        -           gdsys           p1022               controlcenterd_TRAILBLAZER           controlcenterd:TRAILBLAZER,SPIFLASH                                                                                               Dirk Eibach <[email protected]>
include/configs/qemu-ppce500.h new file +15 -0
new file mode 100644
index 0000000..981b016
@@ -0,0 +1,235 @@
+/*
+ * Copyright 2011-2014 Freescale Semiconductor, Inc.
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+/*
+ * Corenet DS style board configuration file
+ */
+#ifndef __QEMU_PPCE500_H
+#define __QEMU_PPCE500_H
+
+#define CONFIG_CMD_REGINFO
+
+/* High Level Configuration Options */

include/configs/qemu-ppce500.h line 25

Quoted 10 lines
include/configs/qemu-ppce500.h new file +10 -0
+#define CONFIG_BOOKE
+#define CONFIG_E500			/* BOOKE e500 family */
+#define CONFIG_MPC85xx			/* MPC85xx/PQ3 platform */
+#define CONFIG_QEMU_E500
+
+#undef CONFIG_SYS_TEXT_BASE
+#define CONFIG_SYS_TEXT_BASE	0xf00000 /* 15 MB */
+
+#undef CONFIG_RESET_VECTOR_ADDRESS
+#define CONFIG_RESET_VECTOR_ADDRESS	(0x1000000 - 4) /* 16 MB */

Does QEMU begin execution here, or at the ELF entry point?

include/configs/qemu-ppce500.h line 35

Quoted 9 lines
include/configs/qemu-ppce500.h new file +9 -0
+#define CONFIG_SYS_RAMBOOT
+
+#define CONFIG_PCI			/* Enable PCI/PCIE */
+#define CONFIG_PCI1		1	/* PCI controller 1 */
+#define CONFIG_FSL_PCI_INIT		/* Use common FSL init code */
+#define CONFIG_SYS_PCI_64BIT		/* enable 64-bit PCI resources */
+
+#define CONFIG_ENV_OVERWRITE
+#define CONFIG_INTERRUPTS		/* enable pci, srio, ddr interrupts */

SRIO and DDR interrupts?

Why do we need CONFIG_INTERRUPTS at all?

include/configs/qemu-ppce500.h line 48

Quoted 2 lines
include/configs/qemu-ppce500.h new file +2 -0
+#define CONFIG_SYS_CCSRBAR		0xe0000000
+#define CONFIG_SYS_CCSRBAR_PHYS_LOW	CONFIG_SYS_CCSRBAR

Again, shouldn't be hardcoded (and must equal the default since QEMU doesn't currently support relocating CCSR)

include/configs/qemu-ppce500.h line 50

Quoted 1 line
include/configs/qemu-ppce500.h new file +1 -0
+#define CONFIG_FW_CFG_ADDR		0xFF7FFFFC

Where did this come from? If this is a new paravirt device please advertise it through the device tree rather than a hardcoded address. And if it must be a hardcoded address, please put it well above 4G.

include/configs/qemu-ppce500.h line 51

Quoted 1 line
include/configs/qemu-ppce500.h new file +1 -0
+#define CONFIG_QEMU_DT_ADDR		((2 * 1024 * 1024) - 4) /* below 2MB */

This is U-Boot-internal and not something hardcoded in QEMU, right?

include/configs/qemu-ppce500.h line 62

Quoted 3 lines
include/configs/qemu-ppce500.h new file +3 -0
+/* CONFIG_NUM_DDR_CONTROLLERS is defined in include/asm/config_mpc85xx.h */
+#define CONFIG_DIMM_SLOTS_PER_CTLR	0
+#define CONFIG_CHIP_SELECTS_PER_CTRL	0

Why are we including code that cares about this?

include/configs/qemu-ppce500.h line 67

Quoted 4 lines
include/configs/qemu-ppce500.h new file +4 -0
+/* Get RAM size from device tree */
+#define CONFIG_DDR_SPD
+
+#define CONFIG_SYS_CLK_FREQ        33000000

Likewise. BTW, this made up sysclock frequency doesn't match the one you made up elsewhere.

include/configs/qemu-ppce500.h line 72

Quoted 5 lines
include/configs/qemu-ppce500.h new file +5 -0
+
+
+/*
+ * IFC Definitions
+ */

There is no IFC.

include/configs/qemu-ppce500.h line 80

Quoted 7 lines
include/configs/qemu-ppce500.h new file +7 -0
+#define CONFIG_SYS_NO_FLASH
+
+#define CONFIG_SYS_BOOT_BLOCK		0x00000000	/* boot TLB */
+#define CONFIG_SYS_FLASH_BASE		0xff800000	/* start of FLASH 8M */
+#define CONFIG_SYS_FLASH_BASE_PHYS	(0xf00000000ull | CONFIG_SYS_FLASH_BASE)
+#define CONFIG_SYS_MAX_FLASH_BANKS	1		/* number of banks */
+#define CONFIG_SYS_MAX_FLASH_SECT	128		/* sectors per device */

NO_FLASH, but flash starts at 0xff800000?

include/configs/qemu-ppce500.h line 83

Quoted 2 lines
include/configs/qemu-ppce500.h new file +2 -0
+#define CONFIG_SYS_MONITOR_BASE		(CONFIG_RESET_VECTOR_ADDRESS - 0x100000 + 4)
+#define CONFIG_SYS_SDRAM_SIZE           64

Why hardcoded to 64 MiB?

Quoted 6 lines
include/configs/qemu-ppce500.h new file +6 -0
+/*
+ * General PCI
+ * Memory space is mapped 1-1, but I/O space must start from 0.
+ */
+
+#define CONFIG_SYS_PCI_VIRT		0xc0000000	/* 512M PCI TLB */

include/configs/qemu-ppce500.h line 145

Quoted 10 lines
include/configs/qemu-ppce500.h new file +10 -0
+#define CONFIG_SYS_PCI_PHYS		0xc0000000	/* 512M PCI TLB */
+
+#define CONFIG_SYS_PCI1_MEM_VIRT	0xc0000000
+#define CONFIG_SYS_PCI1_MEM_BUS	0xc0000000
+#define CONFIG_SYS_PCI1_MEM_PHYS	0xc0000000
+#define CONFIG_SYS_PCI1_MEM_SIZE	0x20000000	/* 512M */
+#define CONFIG_SYS_PCI1_IO_VIRT	0xe1000000
+#define CONFIG_SYS_PCI1_IO_BUS	0x00000000
+#define CONFIG_SYS_PCI1_IO_PHYS	0xe1000000
+#define CONFIG_SYS_PCI1_IO_SIZE	0x00010000	/* 64k */

I assume U-Boot will reprogram PCI based on this, but does QEMU support that for I/O (for memory IIRC it completely ignores the ATMU)? Don't rely on the QEMU address not changing.

include/configs/qemu-ppce500.h line 165

Quoted 5 lines
include/configs/qemu-ppce500.h new file +5 -0
+/*
+ * Environment
+ */
+#define CONFIG_ENV_SIZE		0x2000
+#define CONFIG_ENV_SECT_SIZE	0x10000 /* 64K (one sector) */

Even though ENV_IS_NOWHERE. :-)

include/configs/qemu-ppce500.h line 168

Quoted 2 lines
include/configs/qemu-ppce500.h new file +2 -0
+#define CONFIG_LOADS_ECHO		/* echo on for serial download */
+#define CONFIG_SYS_LOADS_BAUD_CHANGE	/* allow baudrate change */

Baud rate?

include/configs/qemu-ppce500.h line 184

Quoted 8 lines
include/configs/qemu-ppce500.h new file +8 -0
+#define CONFIG_CMD_DHCP
+#define CONFIG_CMD_ELF
+#define CONFIG_CMD_BOOTZ
+#define CONFIG_CMD_ERRATA
+#define CONFIG_CMD_GREPENV
+#define CONFIG_CMD_IRQ
+#define CONFIG_CMD_PING
+#define CONFIG_CMD_SETEXPR

Errata?

include/configs/qemu-ppce500.h line 202

Quoted 5 lines
include/configs/qemu-ppce500.h new file +5 -0
+#ifdef CONFIG_CMD_KGDB
+#define CONFIG_SYS_CBSIZE	1024		/* Console I/O Buffer Size */
+#else
+#define CONFIG_SYS_CBSIZE	256		/* Console I/O Buffer Size */
+#endif

KGDB?

include/configs/qemu-ppce500.h line 217

Quoted 3 lines
include/configs/qemu-ppce500.h new file +3 -0
+#ifdef CONFIG_CMD_KGDB
+#define CONFIG_KGDB_BAUDRATE	230400	/* speed to run kgdb serial port */
+#endif

This is copy-and-paste cruft even on the non-QEMU targets.

-Scott

#2 lore raw

PATCH 1/3 PPC 85xx: Detect e500v2 / e500mc during runtime

In reply to Alexander Graf
Quoted 6 lines · Alexander Graf

With the qemu-ppce500 machine type we can run the same board with either an e500v2 or an e500mc core plugged in.

This means that the IVOR setup can't be based on compile time decisions, so instead we have to do a runtime check which CPU generation we're running on.

Is this really the only place where you ran into this?

Also consider that you'll be adding extra size, and some of our 85xx targets are pretty close to the limit as is (though at least this code isn't used in SPLs).

I guess nobody ever bothered to set IVORs for e6500-specific exceptions.

For that matter, I don't see why we need this code at all. These aren't the addresses that U-Boot keeps its exception vectors at; it's setting them up for the OS, apparently trying to imitate some other type of book3e chip that has fixed ivors. Apparently U-Boot has done this only since 2009 (commit 26f4cdba6b51deab4ec99d60be381244068ef950), so it's not even something that an OS could depend on (and certainly Linux doesn't). So I don't see the point.

-Scott

#3 lore raw

PATCH 1/3 PPC 85xx: Detect e500v2 / e500mc during runtime

Quoted 9 lines · Scott Wood
Quoted 6 lines · Alexander Graf

With the qemu-ppce500 machine type we can run the same board with either an e500v2 or an e500mc core plugged in.

This means that the IVOR setup can't be based on compile time decisions, so instead we have to do a runtime check which CPU generation we're running on.

Is this really the only place where you ran into this?

Yup. At least the only place where the difference actually matters for a VM.

Quoted 6 lines

Also consider that you'll be adding extra size, and some of our 85xx targets are pretty close to the limit as is (though at least this code isn't used in SPLs).

I guess nobody ever bothered to set IVORs for e6500-specific exceptions.

Quoted 7 lines

For that matter, I don't see why we need this code at all. These aren't the addresses that U-Boot keeps its exception vectors at; it's setting them up for the OS, apparently trying to imitate some other type of book3e chip that has fixed ivors. Apparently U-Boot has done this only since 2009 (commit 26f4cdba6b51deab4ec99d60be381244068ef950), so it's not even something that an OS could depend on (and certainly Linux doesn't). So I don't see the point.

Kumar, do you remember why you put this in? Was it only for prototyping purposes?

I certainly wouldn't mind removing the whole thing altogether.

Alex

#11 lore raw

PATCH 3/3 PPC 85xx: Add qemu-ppce500 machine

In reply to Scott Wood
Quoted 34 lines · Scott Wood
Quoted 33 lines · Alexander Graf

For KVM we have a special PV machine type called "ppce500". This machine is inspired by the MPC8544DS board, but implements a lot less features than that one.

It also provides more PCI slots and is supposed to be enumerated by device tree only.

This patch adds support for the current generation ppce500 machine as it is implemented today.

---

arch/powerpc/cpu/mpc85xx/start.S            |    7 +
arch/powerpc/include/asm/config_mpc85xx.h   |    4 +
board/freescale/qemu-ppce500/Makefile       |   10 ++
board/freescale/qemu-ppce500/qemu-ppce500.c |  260 +++++++++++++++++++++++++++
board/freescale/qemu-ppce500/tlb.c          |   59 ++++++
boards.cfg                                  |    1 +
include/configs/qemu-ppce500.h              |  235 ++++++++++++++++++++++++
7 files changed, 576 insertions(+)

create mode 100644 board/freescale/qemu-ppce500/Makefile create mode 100644 board/freescale/qemu-ppce500/qemu-ppce500.c create mode 100644 board/freescale/qemu-ppce500/tlb.c create mode 100644 include/configs/qemu-ppce500.h

arch/powerpc/cpu/mpc85xx/start.S +0 -0
index db84d10..ccbcc03 100644
@@ -80,6 +80,13 @@ _start_e500:
 	li	r1,MSR_DE
 	mtmsr 	r1
 
Quoted 9 lines

arch/powerpc/cpu/mpc85xx/start.S _start_e500: · line 88

Quoted 6 lines
arch/powerpc/cpu/mpc85xx/start.S +6 -0
+#ifdef CONFIG_QEMU_E500
+	/* Save our ePAPR device tree off before we clobber it */
+	lis	r2, CONFIG_QEMU_DT_ADDR at h
+	ori	r2, r2, CONFIG_QEMU_DT_ADDR at l
+	stw	r3, 0(r2)
+#endif

r2 has a special purpose -- please don't use it for other things, even if it's too early to be a problem and other code is similarly bad.

Heh, ok. I'll use r4 instead.

Quoted 3 lines

Instead of saving the DT pointer in some random hardcoded address, how about sticking it in a callee-saved register until you're able to store it in the global data struct?

I did that at first but that didn't survive relocation. However, I just remembered that I had my global variable in bss, so maybe relocation doesn't work properly there. Instead I put it in .data now and that seems to work.

It's certainly the nicer solution, I agree.

Quoted 9 lines
Quoted 9 lines
arch/powerpc/include/asm/config_mpc85xx.h +0 -0
index 54ce2f0..a0ab453 100644
@@ -776,6 +776,10 @@ defined(CONFIG_PPC_T1020) || defined(CONFIG_PPC_T1022)
 #define CONFIG_SYS_CCSRBAR_DEFAULT	0xff700000
 #define CONFIG_SYS_FSL_ERRATUM_A005125
 
Quoted 6 lines

arch/powerpc/include/asm/config_mpc85xx.h defined(CONFIG_PPC_T1020) || defined(CONFIG_PPC_T1022) · line 781

Quoted 3 lines
arch/powerpc/include/asm/config_mpc85xx.h +3 -0
+#elif defined(CONFIG_QEMU_E500)
+#define CONFIG_MAX_CPUS			1
+#define CONFIG_SYS_CCSRBAR_DEFAULT	0xe0000000

This is supposed to come from the device tree. We will want to change that address eventually to support larger guest memory.

That's a lot easier said than done. There is a lot of code in u-boot that puts the CCSRBAR or addresses derived from CCSRBAR into arrays which fails miserably when you make it a variable.

It's certainly a reasonably big task.

Quoted 22 lines
Quoted 22 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +15 -0
new file mode 100644
index 0000000..c6c4b4a
@@ -0,0 +1,260 @@
+/*
+ * Copyright 2007,2009-2014 Freescale Semiconductor, Inc.
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <pci.h>
+#include <asm/processor.h>
+#include <asm/mmu.h>
+#include <asm/immap_85xx.h>
+#include <asm/fsl_pci.h>
+#include <asm/io.h>
+#include <miiphy.h>
Quoted 8 lines

board/freescale/qemu-ppce500/qemu-ppce500.c line 21

Quoted 6 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +6 -0
+#include <libfdt.h>
+#include <fdt_support.h>
+#include <netdev.h>
+#include <fdtdec.h>
+#include <errno.h>
+#include <malloc.h>

Do you really need all these headers? miiphy?

Ah, I missed that one during my header cleaning :). Reved that and immap_85xx.h.

Quoted 13 lines
Quoted 13 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +12 -0
+int checkboard(void)
+{
+	return 0;
+}
+
+static struct pci_controller pci1_hose;
+
+void pci_init_board(void)
+{
+	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
+	struct fsl_pci_info pci_info;
+	u32 devdisr, pordevsr;
Quoted 8 lines

board/freescale/qemu-ppce500/qemu-ppce500.c line 40

Quoted 6 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +6 -0
+	u32 porpllsr, pci_agent, pci_speed, pci_32, pci_arb, pci_clk_sel;
+	int first_free_busno = 0;
+
+	devdisr = in_be32(&gur->devdisr);
+	pordevsr = in_be32(&gur->pordevsr);
+	porpllsr = in_be32(&gur->porpllsr);

Why are you reading registers that don't exist in QEMU?

Dropped

Quoted 35 lines

board/freescale/qemu-ppce500/qemu-ppce500.c line 77

Quoted 8 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +7 -0
+int last_stage_init(void)
+{
+	int ret;
+	int len = 0;
+	const void *prop;
+	int chosen;
+        uint32_t *dt_base_ptr = (void*)CONFIG_QEMU_DT_ADDR;

Whitespace

board/freescale/qemu-ppce500/qemu-ppce500.c line 82

Quoted 5 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +5 -0
+	uint32_t dt_base = *dt_base_ptr;
+	uint32_t dt_size;
+	void *fdt;
+
+	dt_size = fdt_totalsize((void*)dt_base);

Please put a space before the * in casts.

Quoted 16 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +16 -0
+	/* Reserve 4k for dtb tweaks */
+	dt_size += 4096;
+	fdt = malloc(dt_size);
+
+	/* Open device tree */
+	ret = fdt_open_into((void*)dt_base, fdt, dt_size);
+	if (ret) {
+		printf("Couldn't open fdt at %x\n", dt_base);
+		return -EIO;
+	}
+
+	chosen = fdt_path_offset(fdt, "/chosen");
+	if (chosen < 0) {
+		printf("Couldn't find /chosen node in fdt\n");
+		return -EIO;
+	}
Quoted 8 lines

board/freescale/qemu-ppce500/qemu-ppce500.c line 104

Quoted 5 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +5 -0
+
+	prop = fdt_getprop(fdt, chosen, "qemu,boot-kernel", &len);
+	if (prop && (len >= 8)) {
+		/* -kernel boot */
+		setenv_hex("kernel_addr", *(uint64_t*)prop);

Don't cast away the const. This looks like the only place you use prop; why not make it uint64_t to begin with?

Good idea. Fixed.

Quoted 9 lines

board/freescale/qemu-ppce500/qemu-ppce500.c line 110

Quoted 6 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +5 -0
+		/*
+		 * We already know where the initrd is inside the dtb, so no
+		 * need to override it
+		 */
+			setenv("ramdisk_addr", "-");

Indentation.

Quoted 3 lines

What if the user wants to specify the initrd from within U-Boot? This should be handled via the default environment, not by overriding the user's choice.

I'm not sure I see the difference. We have the following default boot script:

#define CONFIG_BOOTCOMMAND             \
       "test -n \"$kernel_addr\" && bootm $kernel_addr $ramdisk_addr $fdt_addr\0"

which is the only place where we actually use $ramdisk_addr. If a user wants to specify the initrd within U-Boot he can do that easily because he would specify his own boot command anyway, right?

Maybe I should rename kernel_addr to qemu_kernel_addr and drop ramdisk_addr completely in favor for a - in the bootm command? Yeah, I'll do that :).

Quoted 8 lines

board/freescale/qemu-ppce500/qemu-ppce500.c line 114

Quoted 5 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +4 -0
+	}
+
+	/* Give the user a variable for the host fdt */
+	setenv_hex("fdt_addr", (int)dt_base);

Unnecessary cast.

Quoted 9 lines

board/freescale/qemu-ppce500/qemu-ppce500.c line 119

Quoted 5 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +5 -0
+
+	free(fdt);
+
+	return 0;
+}

Why is the device tree handling here different from anything else we already have? In particular, why do you create a temporary fdt (with space for tweaks that never happen) just to read from it?

Because I had no idea :). Changed to directly use the in-memory fdt.

Quoted 32 lines

board/freescale/qemu-ppce500/qemu-ppce500.c line 126

Quoted 7 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +6 -0
+static uint64_t get_linear_ram_size(void)
+{
+	const void *prop;
+	int memory;
+	int len;
+        uint32_t *dt_base_ptr = (void*)CONFIG_QEMU_DT_ADDR;

Whitespace.

Quoted 8 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +7 -0
+	void *fdt = &dt_base_ptr[1];
 
+	int ret;
+	uint32_t dt_base = *dt_base_ptr;
+	uint32_t dt_size = 1024 * 1024;
+
+	ret = fdt_open_into((void*)dt_base, fdt, dt_size);
+	if (ret)

board/freescale/qemu-ppce500/qemu-ppce500.c line 143

Quoted 10 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +10 -0
+		panic("Couldn't open fdt");
+
+	memory = fdt_path_offset(fdt, "/memory");
+	prop = fdt_getprop(fdt, memory, "reg", &len);
+
+	if (prop && len >= 16)
+		return *(uint64_t*)(prop+8);
+
+	panic("Couldn't determine RAM size");
+}

Again, there's no need to create a temporary fdt copy every time you want to read from it.

Quoted 1 line

What if memory doesn't start at zero (e.g. for e500v2 VFIO)?

In that case we're pretty broken regardless of determining the correct memory size. Can u-boot handle that case at all? How would this work?

Quoted 10 lines

board/freescale/qemu-ppce500/qemu-ppce500.c line 150

Quoted 7 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +6 -0
+unsigned long
+get_board_sys_clk(ulong dummy)
+{
+	/* The actual clock doesn't matter in a PV machine */
+	return 33333333;
+}

s/doesn't matter/doesn't exist/

Quoted 2 lines

Where is this used from? Can it be skipped for this target? Is the CPU timebase handled properly?

Turns out it's not required at all. Must have been a dependency of something I threw away in between.

Quoted 8 lines

board/freescale/qemu-ppce500/qemu-ppce500.c line 156

Quoted 5 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +4 -0
+int board_phy_config(struct phy_device *phydev)
+{
+	return 0;
+}

Why?

Quoted 7 lines

mpc8544ds is the only board in boards/freescale that has this, so it's clearly optional, and you clearly don't need it...

Just because QEMU started with mpc8544ds doesn't mean this needs to be a copy-and-paste of the U-Boot mpc8544ds code. In fact it's better if it isn't to reduce the likelihood of accidentally depending on hardcoded addresses and such.

Yup. I just had to start from somewhere :). Removed.

Quoted 29 lines
Quoted 29 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +28 -0
+int board_eth_init(bd_t *bis)
+{
+	return pci_eth_init(bis);
+}
+
+#if defined(CONFIG_OF_BOARD_SETUP)
+void ft_board_setup(void *blob, bd_t *bd)
+{
+	FT_FSL_PCI_SETUP;
+}
+#endif
+
+void print_laws(void)
+{
+	/* We don't emulate LAWs yet */
+}
+
+static void fixup_tlb1(uint64_t ram_size)
+{
+	u32 mas0, mas1, mas2, mas3, mas7;
+	long tmp;
+
+	/* Flush TLB0 - it only contains stale maps by now */
+	invalidate_tlb(0);
+
+	/* Create a temporary AS=1 map for ourselves */
+        mas0 = MAS0_TLBSEL(1) | MAS0_ESEL(13);
+        mas1 = MAS1_VALID | MAS1_TID(0) | MAS1_TS | MAS1_TSIZE(BOOKE_PAGESZ_64M);
Quoted 8 lines

board/freescale/qemu-ppce500/qemu-ppce500.c line 192

Quoted 6 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +6 -0
+        mas2 = FSL_BOOKE_MAS2(0, 0);
+        mas3 = FSL_BOOKE_MAS3(CONFIG_SYS_DDR_SDRAM_BASE, 0,
+			      MAS3_SW|MAS3_SR|MAS3_SX);
+        mas7 = FSL_BOOKE_MAS7(CONFIG_SYS_DDR_SDRAM_BASE);
+
+        write_tlb(mas0, mas1, mas2, mas3, mas7);

Whitespace. Please run scripts/checkpatch.pl.

I shouldn't copy&paste I suppose :).

Quoted 30 lines
Quoted 30 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +29 -0
+
+	/* Enter AS=1 */
+	asm volatile(
+		"mfmsr	%0			\n"
+		"ori	%0, %0, 0x30		\n"
+		"mtsrr1	%0			\n"
+		"bl	1f			\n"
+		"1:				\n"
+		"mflr	%0			\n"
+		"addi	%0, %0, 16		\n"
+		"mtsrr0	%0			\n"
+		"rfi				\n"
+	: "=r"(tmp) : : "lr");
+
+	/* Now we live in AS=1, so we can flush all old maps */
+	clear_ddr_tlbs(ram_size >> 20);
+	/* and create new ones */
+	setup_ddr_tlbs(ram_size >> 20);
+
+	/* Now we can safely go back to AS=0 */
+	asm volatile(
+		"mfmsr	%0			\n"
+		"subi	%0, %0, 0x30		\n"
+		"mtsrr1	%0			\n"
+		"bl	1f			\n"
+		"1:				\n"
+		"mflr	%0			\n"
+		"addi	%0, %0, 16		\n"
+		"mtsrr0	%0			\n"
Quoted 8 lines

board/freescale/qemu-ppce500/qemu-ppce500.c line 227

Quoted 6 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +6 -0
+		"rfi				\n"
+	: "=r"(tmp) : : "lr");
+
+	/* And remove our AS=1 map */
+	disable_tlb(13);
+}

Why aren't we already in AS1? What code are you replacing with this?

I honestly don't know how it's supposed to work at all usually.

Quoted 27 lines
Quoted 27 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +26 -0
+phys_size_t fixed_sdram(void)
+{
+	uint64_t ram_size;
+
+	ram_size = get_linear_ram_size();
+
+	/*
+	 * At this point we know that we're running in RAM, but within the
+	 * first 64MB because we don't have a mapping for anything else.
+	 *
+	 * Replace that mapping with real maps for our full RAM range.
+	 */
+	fixup_tlb1(ram_size);
+
+	return ram_size;
+}
+
+phys_size_t fsl_ddr_sdram_size(void)
+{
+	return fixed_sdram();
+}
+
+void init_laws(void)
+{
+	/* We don't emulate LAWs yet */
+}
Quoted 8 lines

board/freescale/qemu-ppce500/qemu-ppce500.c line 260

Quoted 6 lines
board/freescale/qemu-ppce500/qemu-ppce500.c new file +6 -0
+
+int set_next_law(phys_addr_t addr, enum law_size sz, enum law_trgt_if id)
+{
+	/* We don't emulate LAWs yet */
+	return 0;
+}

What is calling set_next_law()?

Nothing anymore apparently. Removed.

Quoted 28 lines
Quoted 28 lines
board/freescale/qemu-ppce500/tlb.c new file +21 -0
new file mode 100644
index 0000000..cdc7013
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2008 Freescale Semiconductor, Inc.
+ *
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, wd at denx.de.
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/mmu.h>
+
+struct fsl_e_tlb_entry tlb_table[] = {
+	/* TLB 0 - for temp stack in cache */
+	SET_TLB_ENTRY(0, CONFIG_SYS_INIT_RAM_ADDR, CONFIG_SYS_INIT_RAM_ADDR,
+		      MAS3_SX|MAS3_SW|MAS3_SR, 0,
+		      0, 0, BOOKE_PAGESZ_4K, 0),
+	SET_TLB_ENTRY(0, CONFIG_SYS_INIT_RAM_ADDR + 4 * 1024 , CONFIG_SYS_INIT_RAM_ADDR + 4 * 1024,
+		      MAS3_SX|MAS3_SW|MAS3_SR, 0,
+		      0, 0, BOOKE_PAGESZ_4K, 0),
+	SET_TLB_ENTRY(0, CONFIG_SYS_INIT_RAM_ADDR + 8 * 1024 , CONFIG_SYS_INIT_RAM_ADDR + 8 * 1024,
Quoted 8 lines

board/freescale/qemu-ppce500/tlb.c line 26

Quoted 5 lines
board/freescale/qemu-ppce500/tlb.c new file +5 -0
+		      MAS3_SX|MAS3_SW|MAS3_SR, 0,
+		      0, 0, BOOKE_PAGESZ_4K, 0),
+	SET_TLB_ENTRY(0, CONFIG_SYS_INIT_RAM_ADDR + 12 * 1024 , CONFIG_SYS_INIT_RAM_ADDR + 12 * 1024,
+		      MAS3_SX|MAS3_SW|MAS3_SR, 0,
+		      0, 0, BOOKE_PAGESZ_4K, 0),

Isn't this just normal RAM? Thus, aren't you creating overlapping TLB entries here?

Indeed. Removed.

Quoted 26 lines
Quoted 26 lines
board/freescale/qemu-ppce500/tlb.c new file +25 -0
+	/*
+	 * TLB 0:	64M	Cacheable
+	 * 0x00000000	64M	Covers RAM at 0x00000000
+	 */
+	SET_TLB_ENTRY(1, CONFIG_SYS_BOOT_BLOCK, CONFIG_SYS_BOOT_BLOCK,
+		      MAS3_SX|MAS3_SW|MAS3_SR, 0,
+		      0, 0, BOOKE_PAGESZ_64M, 1),
+
+	/*
+	 * TLB 1:	256M	Non-cacheable, guarded
+	 */
+	SET_TLB_ENTRY(1, CONFIG_SYS_PCI_VIRT, CONFIG_SYS_PCI_PHYS,
+		      MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
+		      0, 1, BOOKE_PAGESZ_256M, 1),
+
+	/*
+	 * TLB 2:	256M	Non-cacheable, guarded
+	 */
+	SET_TLB_ENTRY(1, CONFIG_SYS_PCI_VIRT + 0x10000000, CONFIG_SYS_PCI_PHYS + 0x10000000,
+		      MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
+		      0, 2, BOOKE_PAGESZ_256M, 1),
+
+	/*
+	 * TLB 3:	64M	Non-cacheable, guarded
+	 * 0xe000_0000	1M	CCSRBAR
Quoted 8 lines

board/freescale/qemu-ppce500/tlb.c line 57

Quoted 6 lines
board/freescale/qemu-ppce500/tlb.c new file +6 -0
+	 * 0xe100_0000	255M	PCI IO range
+	 */
+	SET_TLB_ENTRY(1, CONFIG_SYS_CCSRBAR, CONFIG_SYS_CCSRBAR_PHYS,
+		      MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
+		      0, 3, BOOKE_PAGESZ_64M, 1),
+};

These should not be executable.

Aww :). Fixed.

Quoted 41 lines
Quoted 41 lines
board/freescale/qemu-ppce500/tlb.c new file +2 -0
+
+int num_tlb_entries = ARRAY_SIZE(tlb_table);
boards.cfg +0 -0
index d177f82..ab50982 100644
@@ -986,6 +986,7 @@ Active  powerpc     mpc85xx        -           freescale       t2080qds
Active  powerpc     mpc85xx        -           freescale       t2080qds            T2080QDS_SPIFLASH     T2080QDS:PPC_T2080,RAMBOOT_PBL,SPIFLASH,SYS_TEXT_BASE=0xFFF80000
Active  powerpc     mpc85xx        -           freescale       t2080qds            T2080QDS_NAND         T2080QDS:PPC_T2080,RAMBOOT_PBL,NAND,SYS_TEXT_BASE=0xFFF80000
Active  powerpc     mpc85xx        -           freescale       t2080qds            T2080QDS_SRIO_PCIE_BOOT  T2080QDS:PPC_T2080,SRIO_PCIE_BOOT_SLAVE,SYS_TEXT_BASE=0xFFF80000
+Active  powerpc     mpc85xx        -           freescale       qemu-ppce500        qemu-ppce500                         -                                                                                                                                 Alexander Graf <[email protected]>
Active  powerpc     mpc85xx        -           gdsys           p1022               controlcenterd_36BIT_SDCARD          controlcenterd:36BIT,SDCARD                                                                                                       Dirk Eibach <[email protected]>
Active  powerpc     mpc85xx        -           gdsys           p1022               controlcenterd_36BIT_SDCARD_DEVELOP  controlcenterd:36BIT,SDCARD,DEVELOP                                                                                               Dirk Eibach <[email protected]>
Active  powerpc     mpc85xx        -           gdsys           p1022               controlcenterd_TRAILBLAZER           controlcenterd:TRAILBLAZER,SPIFLASH                                                                                               Dirk Eibach <[email protected]>
include/configs/qemu-ppce500.h new file +19 -0
new file mode 100644
index 0000000..981b016
@@ -0,0 +1,235 @@
+/*
+ * Copyright 2011-2014 Freescale Semiconductor, Inc.
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+/*
+ * Corenet DS style board configuration file
+ */
+#ifndef __QEMU_PPCE500_H
+#define __QEMU_PPCE500_H
+
+#define CONFIG_CMD_REGINFO
+
+/* High Level Configuration Options */
+#define CONFIG_BOOKE
+#define CONFIG_E500			/* BOOKE e500 family */
+#define CONFIG_MPC85xx			/* MPC85xx/PQ3 platform */
+#define CONFIG_QEMU_E500
Quoted 8 lines

include/configs/qemu-ppce500.h line 25

Quoted 6 lines
include/configs/qemu-ppce500.h new file +6 -0
+
+#undef CONFIG_SYS_TEXT_BASE
+#define CONFIG_SYS_TEXT_BASE	0xf00000 /* 15 MB */
+
+#undef CONFIG_RESET_VECTOR_ADDRESS
+#define CONFIG_RESET_VECTOR_ADDRESS	(0x1000000 - 4) /* 16 MB */

Does QEMU begin execution here, or at the ELF entry point?

At the ELF entry point. But I need to define this to something.

Quoted 13 lines

include/configs/qemu-ppce500.h line 35

Quoted 10 lines
include/configs/qemu-ppce500.h new file +9 -0
+#define CONFIG_SYS_RAMBOOT
+
+#define CONFIG_PCI			/* Enable PCI/PCIE */
+#define CONFIG_PCI1		1	/* PCI controller 1 */
+#define CONFIG_FSL_PCI_INIT		/* Use common FSL init code */
+#define CONFIG_SYS_PCI_64BIT		/* enable 64-bit PCI resources */
+
+#define CONFIG_ENV_OVERWRITE
+#define CONFIG_INTERRUPTS		/* enable pci, srio, ddr interrupts */

SRIO and DDR interrupts?

Quoted 1 line

Why do we need CONFIG_INTERRUPTS at all?

We don't. Removed.

Quoted 6 lines

include/configs/qemu-ppce500.h line 48

Quoted 3 lines
include/configs/qemu-ppce500.h new file +2 -0
+#define CONFIG_SYS_CCSRBAR		0xe0000000
+#define CONFIG_SYS_CCSRBAR_PHYS_LOW	CONFIG_SYS_CCSRBAR

Again, shouldn't be hardcoded (and must equal the default since QEMU doesn't currently support relocating CCSR)

Yes.

Quoted 6 lines

include/configs/qemu-ppce500.h line 50

Quoted 2 lines
include/configs/qemu-ppce500.h new file +1 -0
+#define CONFIG_FW_CFG_ADDR		0xFF7FFFFC

Where did this come from? If this is a new paravirt device please advertise it through the device tree rather than a hardcoded address. And if it must be a hardcoded address, please put it well above 4G.

It's a leftover from a time when I used fw_cfg to fetch the dt pointer. Removed.

Quoted 4 lines

include/configs/qemu-ppce500.h line 51

Quoted 2 lines
include/configs/qemu-ppce500.h new file +1 -0
+#define CONFIG_QEMU_DT_ADDR		((2 * 1024 * 1024) - 4) /* below 2MB */

This is U-Boot-internal and not something hardcoded in QEMU, right?

Yes, and it's gone now :).

Quoted 6 lines

include/configs/qemu-ppce500.h line 62

Quoted 4 lines
include/configs/qemu-ppce500.h new file +3 -0
+/* CONFIG_NUM_DDR_CONTROLLERS is defined in include/asm/config_mpc85xx.h */
+#define CONFIG_DIMM_SLOTS_PER_CTLR	0
+#define CONFIG_CHIP_SELECTS_PER_CTRL	0

Why are we including code that cares about this?

In file included from cpu.c:25:0:
/root/u-boot/include/fsl_ddr_sdram.h:183:7: error: 'CONFIG_CHIP_SELECTS_PER_CTRL' undeclared here (not in a function)

So we don't include code, but we include a header that cares.

Quoted 8 lines

include/configs/qemu-ppce500.h line 67

Quoted 5 lines
include/configs/qemu-ppce500.h new file +4 -0
+/* Get RAM size from device tree */
+#define CONFIG_DDR_SPD
+
+#define CONFIG_SYS_CLK_FREQ        33000000

Likewise. BTW, this made up sysclock frequency doesn't match the one you made up elsewhere.

speed.c: In function 'get_sys_info':
speed.c:347:42: error: 'CONFIG_SYS_CLK_FREQ' undeclared (first use in this function)

Quoted 8 lines

include/configs/qemu-ppce500.h line 72

Quoted 6 lines
include/configs/qemu-ppce500.h new file +5 -0
+
+
+/*
+ * IFC Definitions
+ */

There is no IFC.

Removed.

Quoted 10 lines

include/configs/qemu-ppce500.h line 80

Quoted 8 lines
include/configs/qemu-ppce500.h new file +7 -0
+#define CONFIG_SYS_NO_FLASH
+
+#define CONFIG_SYS_BOOT_BLOCK		0x00000000	/* boot TLB */
+#define CONFIG_SYS_FLASH_BASE		0xff800000	/* start of FLASH 8M */
+#define CONFIG_SYS_FLASH_BASE_PHYS	(0xf00000000ull | CONFIG_SYS_FLASH_BASE)
+#define CONFIG_SYS_MAX_FLASH_BANKS	1		/* number of banks */
+#define CONFIG_SYS_MAX_FLASH_SECT	128		/* sectors per device */

NO_FLASH, but flash starts at 0xff800000?

Yeah, I was experimenting with putting up a flash there. Removed.

Quoted 5 lines

include/configs/qemu-ppce500.h line 83

Quoted 3 lines
include/configs/qemu-ppce500.h new file +2 -0
+#define CONFIG_SYS_MONITOR_BASE		(CONFIG_RESET_VECTOR_ADDRESS - 0x100000 + 4)
+#define CONFIG_SYS_SDRAM_SIZE           64

Why hardcoded to 64 MiB?

The define wasn't needed anymore. Removed.

Quoted 13 lines
Quoted 13 lines
include/configs/qemu-ppce500.h new file +12 -0
+/*
+ * General PCI
+ * Memory space is mapped 1-1, but I/O space must start from 0.
+ */
+
+#define CONFIG_SYS_PCI_VIRT		0xc0000000	/* 512M PCI TLB */
+#define CONFIG_SYS_PCI_PHYS		0xc0000000	/* 512M PCI TLB */
+
+#define CONFIG_SYS_PCI1_MEM_VIRT	0xc0000000
+#define CONFIG_SYS_PCI1_MEM_BUS	0xc0000000
+#define CONFIG_SYS_PCI1_MEM_PHYS	0xc0000000
+#define CONFIG_SYS_PCI1_MEM_SIZE	0x20000000	/* 512M */
Quoted 8 lines

include/configs/qemu-ppce500.h line 145

Quoted 4 lines
include/configs/qemu-ppce500.h new file +4 -0
+#define CONFIG_SYS_PCI1_IO_VIRT	0xe1000000
+#define CONFIG_SYS_PCI1_IO_BUS	0x00000000
+#define CONFIG_SYS_PCI1_IO_PHYS	0xe1000000
+#define CONFIG_SYS_PCI1_IO_SIZE	0x00010000	/* 64k */

I assume U-Boot will reprogram PCI based on this, but does QEMU support that for I/O (for memory IIRC it completely ignores the ATMU)? Don't rely on the QEMU address not changing.

It populated its PCI accessor struct based on this. This ideally should be dt based. But for now we have something that works at all :).

Quoted 8 lines

include/configs/qemu-ppce500.h line 165

Quoted 6 lines
include/configs/qemu-ppce500.h new file +5 -0
+/*
+ * Environment
+ */
+#define CONFIG_ENV_SIZE		0x2000
+#define CONFIG_ENV_SECT_SIZE	0x10000 /* 64K (one sector) */

Even though ENV_IS_NOWHERE. :-)

Removed :)

Quoted 5 lines

include/configs/qemu-ppce500.h line 168

Quoted 3 lines
include/configs/qemu-ppce500.h new file +2 -0
+#define CONFIG_LOADS_ECHO		/* echo on for serial download */
+#define CONFIG_SYS_LOADS_BAUD_CHANGE	/* allow baudrate change */

Baud rate?

Removed.

Quoted 11 lines

include/configs/qemu-ppce500.h line 184

Quoted 9 lines
include/configs/qemu-ppce500.h new file +8 -0
+#define CONFIG_CMD_DHCP
+#define CONFIG_CMD_ELF
+#define CONFIG_CMD_BOOTZ
+#define CONFIG_CMD_ERRATA
+#define CONFIG_CMD_GREPENV
+#define CONFIG_CMD_IRQ
+#define CONFIG_CMD_PING
+#define CONFIG_CMD_SETEXPR

Errata?

Eh - removed :)

Quoted 8 lines

include/configs/qemu-ppce500.h line 202

Quoted 6 lines
include/configs/qemu-ppce500.h new file +5 -0
+#ifdef CONFIG_CMD_KGDB
+#define CONFIG_SYS_CBSIZE	1024		/* Console I/O Buffer Size */
+#else
+#define CONFIG_SYS_CBSIZE	256		/* Console I/O Buffer Size */
+#endif

KGDB?

*shrug* I just copied this from somewhere.

Quoted 6 lines

include/configs/qemu-ppce500.h line 217

Quoted 4 lines
include/configs/qemu-ppce500.h new file +3 -0
+#ifdef CONFIG_CMD_KGDB
+#define CONFIG_KGDB_BAUDRATE	230400	/* speed to run kgdb serial port */
+#endif

This is copy-and-paste cruft even on the non-QEMU targets.

Ok, I'll remove it.

Alex

#12 lore raw

PATCH 3/3 PPC 85xx: Add qemu-ppce500 machine

Quoted 52 lines · Alexander Graf
Quoted 34 lines · Scott Wood
Quoted 33 lines · Alexander Graf

For KVM we have a special PV machine type called "ppce500". This machine is inspired by the MPC8544DS board, but implements a lot less features than that one.

It also provides more PCI slots and is supposed to be enumerated by device tree only.

This patch adds support for the current generation ppce500 machine as it is implemented today.

---

arch/powerpc/cpu/mpc85xx/start.S            |    7 +
arch/powerpc/include/asm/config_mpc85xx.h   |    4 +
board/freescale/qemu-ppce500/Makefile       |   10 ++
board/freescale/qemu-ppce500/qemu-ppce500.c |  260 +++++++++++++++++++++++++++
board/freescale/qemu-ppce500/tlb.c          |   59 ++++++
boards.cfg                                  |    1 +
include/configs/qemu-ppce500.h              |  235 ++++++++++++++++++++++++
7 files changed, 576 insertions(+)

create mode 100644 board/freescale/qemu-ppce500/Makefile create mode 100644 board/freescale/qemu-ppce500/qemu-ppce500.c create mode 100644 board/freescale/qemu-ppce500/tlb.c create mode 100644 include/configs/qemu-ppce500.h

arch/powerpc/cpu/mpc85xx/start.S +0 -0
index db84d10..ccbcc03 100644
@@ -80,6 +80,13 @@ _start_e500:
 	li	r1,MSR_DE
 	mtmsr 	r1
 
Quoted 9 lines

arch/powerpc/cpu/mpc85xx/start.S _start_e500: · line 88

Quoted 6 lines
arch/powerpc/cpu/mpc85xx/start.S +6 -0
+#ifdef CONFIG_QEMU_E500
+	/* Save our ePAPR device tree off before we clobber it */
+	lis	r2, CONFIG_QEMU_DT_ADDR at h
+	ori	r2, r2, CONFIG_QEMU_DT_ADDR at l
+	stw	r3, 0(r2)
+#endif

r2 has a special purpose -- please don't use it for other things, even if it's too early to be a problem and other code is similarly bad.

Heh, ok. I'll use r4 instead.

Quoted 3 lines

Instead of saving the DT pointer in some random hardcoded address, how about sticking it in a callee-saved register until you're able to store it in the global data struct?

Quoted 6 lines

I did that at first but that didn't survive relocation. However, I just remembered that I had my global variable in bss, so maybe relocation doesn't work properly there. Instead I put it in .data now and that seems to work.

It's certainly the nicer solution, I agree.

I don't mean a global variable, but a field in the global data struct (gd_t). BSS should not be accessed, and global variables should not be written, before relocation (although you may get away with the latter pre-relocation in ramboot cases, you still shouldn't).

Quoted 12 lines
Quoted 11 lines

arch/powerpc/cpu/mpc85xx/start.S _start_e500:

Quoted 5 lines
arch/powerpc/cpu/mpc85xx/start.S +5 -0
+		/*
+		 * We already know where the initrd is inside the dtb, so no
+		 * need to override it
+		 */
+			setenv("ramdisk_addr", "-");

Indentation.

What if the user wants to specify the initrd from within U-Boot? This should be handled via the default environment, not by overriding the user's choice.

Quoted 8 lines

I'm not sure I see the difference. We have the following default boot script:

#define CONFIG_BOOTCOMMAND             \
       "test -n \"$kernel_addr\" && bootm $kernel_addr $ramdisk_addr $fdt_addr\0"

which is the only place where we actually use $ramdisk_addr. If a user wants to specify the initrd within U-Boot he can do that easily because he would specify his own boot command anyway, right?

Oh. I was confusing it with the existing $ramdiskaddr. So I'm changing my objection to the fact that it's confusing. :-)

Likewise $fdt_addr versus $fdtaddr.

Quoted 3 lines

Maybe I should rename kernel_addr to qemu_kernel_addr and drop ramdisk_addr completely in favor for a - in the bootm command? Yeah, I'll do that :).

OK.

Quoted 16 lines
Quoted 16 lines

arch/powerpc/cpu/mpc85xx/start.S

Quoted 12 lines
arch/powerpc/cpu/mpc85xx/start.S +12 -0
+	ret = fdt_open_into((void*)dt_base, fdt, dt_size);
+	if (ret)
+		panic("Couldn't open fdt");
+
+	memory = fdt_path_offset(fdt, "/memory");
+	prop = fdt_getprop(fdt, memory, "reg", &len);
+
+	if (prop && len >= 16)
+		return *(uint64_t*)(prop+8);
+
+	panic("Couldn't determine RAM size");
+}

Again, there's no need to create a temporary fdt copy every time you want to read from it.

Quoted 3 lines
Quoted 1 line

What if memory doesn't start at zero (e.g. for e500v2 VFIO)?

In that case we're pretty broken regardless of determining the correct memory size. Can u-boot handle that case at all? How would this work?

U-Boot can handle this on other architectures. Not sure about the PPC code.

Quoted 9 lines
Quoted 9 lines

arch/powerpc/cpu/mpc85xx/start.S

Quoted 6 lines
arch/powerpc/cpu/mpc85xx/start.S +6 -0
+unsigned long
+get_board_sys_clk(ulong dummy)
+{
+	/* The actual clock doesn't matter in a PV machine */
+	return 33333333;
+}

s/doesn't matter/doesn't exist/

Quoted 4 lines
Quoted 2 lines

Where is this used from? Can it be skipped for this target? Is the CPU timebase handled properly?

Turns out it's not required at all. Must have been a dependency of something I threw away in between.

OK. I'm still curious about how the timebase frequency is handled.

Quoted 37 lines
Quoted 28 lines
Quoted 28 lines
arch/powerpc/cpu/mpc85xx/start.S +28 -0
+	/* Enter AS=1 */
+	asm volatile(
+		"mfmsr	%0			\n"
+		"ori	%0, %0, 0x30		\n"
+		"mtsrr1	%0			\n"
+		"bl	1f			\n"
+		"1:				\n"
+		"mflr	%0			\n"
+		"addi	%0, %0, 16		\n"
+		"mtsrr0	%0			\n"
+		"rfi				\n"
+	: "=r"(tmp) : : "lr");
+
+	/* Now we live in AS=1, so we can flush all old maps */
+	clear_ddr_tlbs(ram_size >> 20);
+	/* and create new ones */
+	setup_ddr_tlbs(ram_size >> 20);
+
+	/* Now we can safely go back to AS=0 */
+	asm volatile(
+		"mfmsr	%0			\n"
+		"subi	%0, %0, 0x30		\n"
+		"mtsrr1	%0			\n"
+		"bl	1f			\n"
+		"1:				\n"
+		"mflr	%0			\n"
+		"addi	%0, %0, 16		\n"
+		"mtsrr0	%0			\n"
Quoted 8 lines

arch/powerpc/cpu/mpc85xx/start.S

Quoted 6 lines
arch/powerpc/cpu/mpc85xx/start.S +6 -0
+		"rfi				\n"
+	: "=r"(tmp) : : "lr");
+
+	/* And remove our AS=1 map */
+	disable_tlb(13);
+}

Why aren't we already in AS1? What code are you replacing with this?

Quoted 1 line

I honestly don't know how it's supposed to work at all usually.

Usually we enter AS1 from start.S during early boot (see switch_as), and return to AS0 later in start.S (see _start_cont) after calling cpu_init_early_f().

Quoted 6 lines
Quoted 4 lines

arch/powerpc/cpu/mpc85xx/start.S

Quoted 2 lines
arch/powerpc/cpu/mpc85xx/start.S +2 -0
+#undef CONFIG_RESET_VECTOR_ADDRESS
+#define CONFIG_RESET_VECTOR_ADDRESS	(0x1000000 - 4) /* 16 MB */

Does QEMU begin execution here, or at the ELF entry point?

At the ELF entry point. But I need to define this to something.

Set CONFIG_SYS_MPC85XX_NO_RESETVEC.

Quoted 10 lines
Quoted 5 lines

arch/powerpc/cpu/mpc85xx/start.S

Quoted 3 lines
arch/powerpc/cpu/mpc85xx/start.S +3 -0
+/* CONFIG_NUM_DDR_CONTROLLERS is defined in include/asm/config_mpc85xx.h */
+#define CONFIG_DIMM_SLOTS_PER_CTLR	0
+#define CONFIG_CHIP_SELECTS_PER_CTRL	0

Why are we including code that cares about this?

In file included from cpu.c:25:0:
/root/u-boot/include/fsl_ddr_sdram.h:183:7: error: 'CONFIG_CHIP_SELECTS_PER_CTRL' undeclared here (not in a function)

So we don't include code, but we include a header that cares.

I see. Would be nice to clean that up at some point, but OK for now.

Quoted 10 lines
Quoted 7 lines

arch/powerpc/cpu/mpc85xx/start.S

Quoted 4 lines
arch/powerpc/cpu/mpc85xx/start.S +4 -0
+/* Get RAM size from device tree */
+#define CONFIG_DDR_SPD
+
+#define CONFIG_SYS_CLK_FREQ        33000000

Likewise. BTW, this made up sysclock frequency doesn't match the one you made up elsewhere.

speed.c: In function 'get_sys_info':
speed.c:347:42: error: 'CONFIG_SYS_CLK_FREQ' undeclared (first use in this function)

What do we need from speed.c?

-Scott

#13 lore raw

PATCH 3/3 PPC 85xx: Add qemu-ppce500 machine

Quoted 58 lines · Scott Wood
Quoted 57 lines · Alexander Graf
Quoted 34 lines · Scott Wood
Quoted 33 lines · Alexander Graf

For KVM we have a special PV machine type called "ppce500". This machine is inspired by the MPC8544DS board, but implements a lot less features than that one.

It also provides more PCI slots and is supposed to be enumerated by device tree only.

This patch adds support for the current generation ppce500 machine as it is implemented today.

---

arch/powerpc/cpu/mpc85xx/start.S            |    7 +
arch/powerpc/include/asm/config_mpc85xx.h   |    4 +
board/freescale/qemu-ppce500/Makefile       |   10 ++
board/freescale/qemu-ppce500/qemu-ppce500.c |  260 +++++++++++++++++++++++++++
board/freescale/qemu-ppce500/tlb.c          |   59 ++++++
boards.cfg                                  |    1 +
include/configs/qemu-ppce500.h              |  235 ++++++++++++++++++++++++
7 files changed, 576 insertions(+)

create mode 100644 board/freescale/qemu-ppce500/Makefile create mode 100644 board/freescale/qemu-ppce500/qemu-ppce500.c create mode 100644 board/freescale/qemu-ppce500/tlb.c create mode 100644 include/configs/qemu-ppce500.h

arch/powerpc/cpu/mpc85xx/start.S +0 -0
index db84d10..ccbcc03 100644
@@ -80,6 +80,13 @@ _start_e500:
 	li	r1,MSR_DE
 	mtmsr 	r1
 
Quoted 9 lines

arch/powerpc/cpu/mpc85xx/start.S _start_e500: · line 88

Quoted 6 lines
arch/powerpc/cpu/mpc85xx/start.S +6 -0
+#ifdef CONFIG_QEMU_E500
+	/* Save our ePAPR device tree off before we clobber it */
+	lis	r2, CONFIG_QEMU_DT_ADDR at h
+	ori	r2, r2, CONFIG_QEMU_DT_ADDR at l
+	stw	r3, 0(r2)
+#endif

r2 has a special purpose -- please don't use it for other things, even if it's too early to be a problem and other code is similarly bad.

Heh, ok. I'll use r4 instead.

Quoted 3 lines

Instead of saving the DT pointer in some random hardcoded address, how about sticking it in a callee-saved register until you're able to store it in the global data struct?

I did that at first but that didn't survive relocation. However, I just remembered that I had my global variable in bss, so maybe relocation doesn't work properly there. Instead I put it in .data now and that seems to work.

Quoted 6 lines
Quoted 1 line

It's certainly the nicer solution, I agree.

I don't mean a global variable, but a field in the global data struct (gd_t). BSS should not be accessed, and global variables should not be written, before relocation (although you may get away with the latter pre-relocation in ramboot cases, you still shouldn't).

But the global data gets cleared in cpu_init_early_f(). So I'd have to shove it to some non-volatile, make sure no other code uses that particular register and then move it into gd. And how do I get offsets into the gd structure from asm in the first place?

Or are you suggesting I move r3 into r2x, leave it there until after cpu_init_early_f(), copy it back to r3 and then call a C helper that puts it into gd? Sounds quite excessive for something that works quite well with a global variable in .data :).

Quoted 18 lines
Quoted 18 lines
Quoted 9 lines

arch/powerpc/cpu/mpc85xx/start.S _start_e500:

Quoted 6 lines
arch/powerpc/cpu/mpc85xx/start.S +5 -0
+		/*
+		 * We already know where the initrd is inside the dtb, so no
+		 * need to override it
+		 */
+			setenv("ramdisk_addr", "-");

Indentation.

Quoted 3 lines

What if the user wants to specify the initrd from within U-Boot? This should be handled via the default environment, not by overriding the user's choice.

I'm not sure I see the difference. We have the following default boot script:

#define CONFIG_BOOTCOMMAND             \
      "test -n \"$kernel_addr\" && bootm $kernel_addr $ramdisk_addr $fdt_addr\0"
Quoted 8 lines
Quoted 3 lines

which is the only place where we actually use $ramdisk_addr. If a user wants to specify the initrd within U-Boot he can do that easily because he would specify his own boot command anyway, right?

Oh. I was confusing it with the existing $ramdiskaddr. So I'm changing my objection to the fact that it's confusing. :-)

Likewise $fdt_addr versus $fdtaddr.

Mind to explain what the difference is between $fdtaddr, $fdt_addr (pxe boot?) and $fdt_addr_r? Which one should I set?

Quoted 23 lines
Quoted 4 lines

Maybe I should rename kernel_addr to qemu_kernel_addr and drop ramdisk_addr completely in favor for a - in the bootm command? Yeah, I'll do that :).

OK.

Quoted 16 lines
Quoted 16 lines

arch/powerpc/cpu/mpc85xx/start.S

Quoted 12 lines
arch/powerpc/cpu/mpc85xx/start.S +12 -0
+	ret = fdt_open_into((void*)dt_base, fdt, dt_size);
+	if (ret)
+		panic("Couldn't open fdt");
+
+	memory = fdt_path_offset(fdt, "/memory");
+	prop = fdt_getprop(fdt, memory, "reg", &len);
+
+	if (prop && len >= 16)
+		return *(uint64_t*)(prop+8);
+
+	panic("Couldn't determine RAM size");
+}

Again, there's no need to create a temporary fdt copy every time you want to read from it.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

What if memory doesn't start at zero (e.g. for e500v2 VFIO)?

In that case we're pretty broken regardless of determining the correct memory size. Can u-boot handle that case at all? How would this work?

U-Boot can handle this on other architectures. Not sure about the PPC code.

It's handled through preprocessor configuration magic again. I'll leave that for later though.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

arch/powerpc/cpu/mpc85xx/start.S

Quoted 7 lines
arch/powerpc/cpu/mpc85xx/start.S +6 -0
+unsigned long
+get_board_sys_clk(ulong dummy)
+{
+	/* The actual clock doesn't matter in a PV machine */
+	return 33333333;
+}

s/doesn't matter/doesn't exist/

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Where is this used from? Can it be skipped for this target? Is the CPU timebase handled properly?

Turns out it's not required at all. Must have been a dependency of something I threw away in between.

OK. I'm still curious about how the timebase frequency is handled.

Incorrectly. The question is whether it matters.

Quoted 38 lines
Quoted 38 lines
Quoted 37 lines
Quoted 25 lines
arch/powerpc/cpu/mpc85xx/start.S +24 -0
+	/* Enter AS=1 */
+	asm volatile(
+		"mfmsr	%0			\n"
+		"ori	%0, %0, 0x30		\n"
+		"mtsrr1	%0			\n"
+		"bl	1f			\n"
+		"1:				\n"
+		"mflr	%0			\n"
+		"addi	%0, %0, 16		\n"
+		"mtsrr0	%0			\n"
+		"rfi				\n"
+	: "=r"(tmp) : : "lr");
+
+	/* Now we live in AS=1, so we can flush all old maps */
+	clear_ddr_tlbs(ram_size >> 20);
+	/* and create new ones */
+	setup_ddr_tlbs(ram_size >> 20);
+
+	/* Now we can safely go back to AS=0 */
+	asm volatile(
+		"mfmsr	%0			\n"
+		"subi	%0, %0, 0x30		\n"
+		"mtsrr1	%0			\n"
+		"bl	1f			\n"

arch/powerpc/cpu/mpc85xx/start.S

Quoted 10 lines
arch/powerpc/cpu/mpc85xx/start.S +10 -0
+		"1:				\n"
+		"mflr	%0			\n"
+		"addi	%0, %0, 16		\n"
+		"mtsrr0	%0			\n"
+		"rfi				\n"
+	: "=r"(tmp) : : "lr");
+
+	/* And remove our AS=1 map */
+	disable_tlb(13);
+}

Why aren't we already in AS1? What code are you replacing with this?

Quoted 5 lines
Quoted 1 line

I honestly don't know how it's supposed to work at all usually.

Usually we enter AS1 from start.S during early boot (see switch_as), and return to AS0 later in start.S (see _start_cont) after calling cpu_init_early_f().

Right, but the only function that gets called in AS=1 is cpu_init_early_f() which is CPU, not board specific. I really don't want to mess with common code too much unless I'm 100% sure I don't break it and it doesn't break me next time.

So I need to run this from AS=0 context, which means we need to quickly go out of AS=0, modify the AS=0 map and go back into AS=0.

Quoted 9 lines
Quoted 7 lines
Quoted 5 lines

arch/powerpc/cpu/mpc85xx/start.S

Quoted 3 lines
arch/powerpc/cpu/mpc85xx/start.S +2 -0
+#undef CONFIG_RESET_VECTOR_ADDRESS
+#define CONFIG_RESET_VECTOR_ADDRESS	(0x1000000 - 4) /* 16 MB */

Does QEMU begin execution here, or at the ELF entry point?

At the ELF entry point. But I need to define this to something.

Set CONFIG_SYS_MPC85XX_NO_RESETVEC.

Sounds easy, but doesn't boot anymore now. I guess I'll need to figure out where in that fragile TLB setup mess it fails this time.

Quoted 22 lines
Quoted 11 lines
Quoted 6 lines

arch/powerpc/cpu/mpc85xx/start.S

Quoted 4 lines
arch/powerpc/cpu/mpc85xx/start.S +3 -0
+/* CONFIG_NUM_DDR_CONTROLLERS is defined in include/asm/config_mpc85xx.h */
+#define CONFIG_DIMM_SLOTS_PER_CTLR	0
+#define CONFIG_CHIP_SELECTS_PER_CTRL	0

Why are we including code that cares about this?

In file included from cpu.c:25:0:
/root/u-boot/include/fsl_ddr_sdram.h:183:7: error: 'CONFIG_CHIP_SELECTS_PER_CTRL' undeclared here (not in a function)

So we don't include code, but we include a header that cares.

I see. Would be nice to clean that up at some point, but OK for now.

Quoted 8 lines
Quoted 7 lines

arch/powerpc/cpu/mpc85xx/start.S

Quoted 4 lines
arch/powerpc/cpu/mpc85xx/start.S +4 -0
+/* Get RAM size from device tree */
+#define CONFIG_DDR_SPD
+
+#define CONFIG_SYS_CLK_FREQ        33000000

Likewise. BTW, this made up sysclock frequency doesn't match the one you made up elsewhere.

Quoted 4 lines
Quoted 2 lines

speed.c: In function 'get_sys_info':
speed.c:347:42: error: 'CONFIG_SYS_CLK_FREQ' undeclared (first use in this function)

What do we need from speed.c?

Nothing really, but it gets included unconditionally in arch/powerpc/cpu/mpc85xx/Makefile so I can't override it with my own stubs.

Alex

#14 lore raw

PATCH 3/3 PPC 85xx: Add qemu-ppce500 machine

Quoted 62 lines · Alexander Graf
Quoted 60 lines · Scott Wood
Quoted 58 lines · Alexander Graf
Quoted 34 lines · Scott Wood
Quoted 33 lines · Alexander Graf

For KVM we have a special PV machine type called "ppce500". This machine is inspired by the MPC8544DS board, but implements a lot less features than that one.

It also provides more PCI slots and is supposed to be enumerated by device tree only.

This patch adds support for the current generation ppce500 machine as it is implemented today.

---

arch/powerpc/cpu/mpc85xx/start.S            |    7 +
arch/powerpc/include/asm/config_mpc85xx.h   |    4 +
board/freescale/qemu-ppce500/Makefile       |   10 ++
board/freescale/qemu-ppce500/qemu-ppce500.c |  260 +++++++++++++++++++++++++++
board/freescale/qemu-ppce500/tlb.c          |   59 ++++++
boards.cfg                                  |    1 +
include/configs/qemu-ppce500.h              |  235 ++++++++++++++++++++++++
7 files changed, 576 insertions(+)

create mode 100644 board/freescale/qemu-ppce500/Makefile create mode 100644 board/freescale/qemu-ppce500/qemu-ppce500.c create mode 100644 board/freescale/qemu-ppce500/tlb.c create mode 100644 include/configs/qemu-ppce500.h

arch/powerpc/cpu/mpc85xx/start.S +0 -0
index db84d10..ccbcc03 100644
@@ -80,6 +80,13 @@ _start_e500:
 	li	r1,MSR_DE
 	mtmsr 	r1
 
Quoted 9 lines

arch/powerpc/cpu/mpc85xx/start.S _start_e500: · line 88

Quoted 6 lines
arch/powerpc/cpu/mpc85xx/start.S +6 -0
+#ifdef CONFIG_QEMU_E500
+	/* Save our ePAPR device tree off before we clobber it */
+	lis	r2, CONFIG_QEMU_DT_ADDR at h
+	ori	r2, r2, CONFIG_QEMU_DT_ADDR at l
+	stw	r3, 0(r2)
+#endif

r2 has a special purpose -- please don't use it for other things, even if it's too early to be a problem and other code is similarly bad.

Heh, ok. I'll use r4 instead.

Quoted 3 lines

Instead of saving the DT pointer in some random hardcoded address, how about sticking it in a callee-saved register until you're able to store it in the global data struct?

I did that at first but that didn't survive relocation. However, I just remembered that I had my global variable in bss, so maybe relocation doesn't work properly there. Instead I put it in .data now and that seems to work.

It's certainly the nicer solution, I agree.

Quoted 8 lines
Quoted 4 lines

I don't mean a global variable, but a field in the global data struct (gd_t). BSS should not be accessed, and global variables should not be written, before relocation (although you may get away with the latter pre-relocation in ramboot cases, you still shouldn't).

But the global data gets cleared in cpu_init_early_f(). So I'd have to shove it to some non-volatile, make sure no other code uses that particular register and then move it into gd.

Right.

Quoted 1 line

And how do I get offsets into the gd structure from asm in the first place?

See lib/asm-offsets.c

Quoted 4 lines

Or are you suggesting I move r3 into r2x, leave it there until after cpu_init_early_f(), copy it back to r3 and then call a C helper that puts it into gd? Sounds quite excessive for something that works quite well with a global variable in .data :).

It only works because you are booting directly from RAM, and the variable you're writing to isn't subject to relocation, and isn't in the BSS (unlike most uninitialized/zero-initialized data). It's not good practice. What if you later want to simulate NOR flash and boot from that?

Quoted 10 lines
Quoted 8 lines
Quoted 3 lines

which is the only place where we actually use $ramdisk_addr. If a user wants to specify the initrd within U-Boot he can do that easily because he would specify his own boot command anyway, right?

Oh. I was confusing it with the existing $ramdiskaddr. So I'm changing my objection to the fact that it's confusing. :-)

Likewise $fdt_addr versus $fdtaddr.

Mind to explain what the difference is between $fdtaddr, $fdt_addr (pxe boot?) and $fdt_addr_r? Which one should I set?

I don't know what the "_r" is supposed to mean, but the underscore seems to just be something that varies from board to board. Our boards use $fdtaddr and until now I didn't realize other boards do it differently.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

arch/powerpc/cpu/mpc85xx/start.S _start_e500:

Quoted 6 lines
arch/powerpc/cpu/mpc85xx/start.S +6 -0
+unsigned long
+get_board_sys_clk(ulong dummy)
+{
+	/* The actual clock doesn't matter in a PV machine */
+	return 33333333;
+}

s/doesn't matter/doesn't exist/

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Where is this used from? Can it be skipped for this target? Is the CPU timebase handled properly?

Turns out it's not required at all. Must have been a dependency of something I threw away in between.

OK. I'm still curious about how the timebase frequency is handled.

Incorrectly. The question is whether it matters.

Incorrectly for U-Boot's own use? Incorrectly for passing to Linux?

The latter case definitely matters. The former case would affect the boot delay, so it needs to be at least reasonably close.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Why aren't we already in AS1? What code are you replacing with this?

I honestly don't know how it's supposed to work at all usually.

Usually we enter AS1 from start.S during early boot (see switch_as), and return to AS0 later in start.S (see _start_cont) after calling cpu_init_early_f().

Quoted 7 lines

Right, but the only function that gets called in AS=1 is cpu_init_early_f() which is CPU, not board specific. I really don't want to mess with common code too much unless I'm 100% sure I don't break it and it doesn't break me next time.

So I need to run this from AS=0 context, which means we need to quickly go out of AS=0, modify the AS=0 map and go back into AS=0.

What sort of messing would you need to do to cpu_init_early_f()? What part of the normal workflow breaks under QEMU?

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

arch/powerpc/cpu/mpc85xx/start.S

Quoted 4 lines
arch/powerpc/cpu/mpc85xx/start.S +4 -0
+/* Get RAM size from device tree */
+#define CONFIG_DDR_SPD
+
+#define CONFIG_SYS_CLK_FREQ        33000000

Likewise. BTW, this made up sysclock frequency doesn't match the one you made up elsewhere.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

speed.c: In function 'get_sys_info':
speed.c:347:42: error: 'CONFIG_SYS_CLK_FREQ' undeclared (first use in this function)

What do we need from speed.c?

Nothing really, but it gets included unconditionally in arch/powerpc/cpu/mpc85xx/Makefile so I can't override it with my own stubs.

You could stick an ifndef CONFIG_QEMU_E500 in there I guess, or define it to be zero and make sure you don't call any of those functions that depend on it.

-Scott

#15 lore raw

PATCH 3/3 PPC 85xx: Add qemu-ppce500 machine

Quoted 83 lines · Scott Wood
Quoted 62 lines · Alexander Graf
Quoted 60 lines · Scott Wood
Quoted 58 lines · Alexander Graf
Quoted 34 lines · Scott Wood
Quoted 33 lines · Alexander Graf

For KVM we have a special PV machine type called "ppce500". This machine is inspired by the MPC8544DS board, but implements a lot less features than that one.

It also provides more PCI slots and is supposed to be enumerated by device tree only.

This patch adds support for the current generation ppce500 machine as it is implemented today.

---

arch/powerpc/cpu/mpc85xx/start.S            |    7 +
arch/powerpc/include/asm/config_mpc85xx.h   |    4 +
board/freescale/qemu-ppce500/Makefile       |   10 ++
board/freescale/qemu-ppce500/qemu-ppce500.c |  260 +++++++++++++++++++++++++++
board/freescale/qemu-ppce500/tlb.c          |   59 ++++++
boards.cfg                                  |    1 +
include/configs/qemu-ppce500.h              |  235 ++++++++++++++++++++++++
7 files changed, 576 insertions(+)

create mode 100644 board/freescale/qemu-ppce500/Makefile create mode 100644 board/freescale/qemu-ppce500/qemu-ppce500.c create mode 100644 board/freescale/qemu-ppce500/tlb.c create mode 100644 include/configs/qemu-ppce500.h

arch/powerpc/cpu/mpc85xx/start.S +0 -0
index db84d10..ccbcc03 100644
@@ -80,6 +80,13 @@ _start_e500:
 	li	r1,MSR_DE
 	mtmsr 	r1
 
Quoted 9 lines

arch/powerpc/cpu/mpc85xx/start.S _start_e500: · line 88

Quoted 6 lines
arch/powerpc/cpu/mpc85xx/start.S +6 -0
+#ifdef CONFIG_QEMU_E500
+	/* Save our ePAPR device tree off before we clobber it */
+	lis	r2, CONFIG_QEMU_DT_ADDR at h
+	ori	r2, r2, CONFIG_QEMU_DT_ADDR at l
+	stw	r3, 0(r2)
+#endif

r2 has a special purpose -- please don't use it for other things, even if it's too early to be a problem and other code is similarly bad.

Heh, ok. I'll use r4 instead.

Quoted 3 lines

Instead of saving the DT pointer in some random hardcoded address, how about sticking it in a callee-saved register until you're able to store it in the global data struct?

I did that at first but that didn't survive relocation. However, I just remembered that I had my global variable in bss, so maybe relocation doesn't work properly there. Instead I put it in .data now and that seems to work.

It's certainly the nicer solution, I agree.

Quoted 8 lines
Quoted 4 lines

I don't mean a global variable, but a field in the global data struct (gd_t). BSS should not be accessed, and global variables should not be written, before relocation (although you may get away with the latter pre-relocation in ramboot cases, you still shouldn't).

But the global data gets cleared in cpu_init_early_f(). So I'd have to shove it to some non-volatile, make sure no other code uses that particular register and then move it into gd.

Right.

Quoted 1 line

And how do I get offsets into the gd structure from asm in the first place?

See lib/asm-offsets.c

Quoted 4 lines

Or are you suggesting I move r3 into r2x, leave it there until after cpu_init_early_f(), copy it back to r3 and then call a C helper that puts it into gd? Sounds quite excessive for something that works quite well with a global variable in .data :).

Quoted 5 lines

It only works because you are booting directly from RAM, and the variable you're writing to isn't subject to relocation, and isn't in the BSS (unlike most uninitialized/zero-initialized data). It's not good practice. What if you later want to simulate NOR flash and boot from that?

Ok, I'll change it :)

Saving it from asm only doesn't work though because we end up accessing the fdt pointer inside of cpu_early_init_f() which clears the gd. I've made the fdt pointer a function argument now.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

which is the only place where we actually use $ramdisk_addr. If a user wants to specify the initrd within U-Boot he can do that easily because he would specify his own boot command anyway, right?

Oh. I was confusing it with the existing $ramdiskaddr. So I'm changing my objection to the fact that it's confusing. :-)

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Likewise $fdt_addr versus $fdtaddr.

Mind to explain what the difference is between $fdtaddr, $fdt_addr (pxe boot?) and $fdt_addr_r? Which one should I set?

I don't know what the "_r" is supposed to mean, but the underscore seems to just be something that varies from board to board. Our boards use $fdtaddr and until now I didn't realize other boards do it differently.

Bah - I'll just set all of them.

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 10 lines

arch/powerpc/cpu/mpc85xx/start.S _start_e500:

Quoted 7 lines
arch/powerpc/cpu/mpc85xx/start.S +6 -0
+unsigned long
+get_board_sys_clk(ulong dummy)
+{
+	/* The actual clock doesn't matter in a PV machine */
+	return 33333333;
+}

s/doesn't matter/doesn't exist/

Quoted 2 lines

Where is this used from? Can it be skipped for this target? Is the CPU timebase handled properly?

Turns out it's not required at all. Must have been a dependency of something I threw away in between.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

OK. I'm still curious about how the timebase frequency is handled.

Incorrectly. The question is whether it matters.

Incorrectly for U-Boot's own use? Incorrectly for passing to Linux?

The latter case definitely matters. The former case would affect the boot delay, so it needs to be at least reasonably close.

We don't modify the DT when passing it to Linux. That would mess up quite a number of things (SMP among others).

As for internal use, it's definitely close enough on everything I tested it on.

Quoted 14 lines
Quoted 14 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Why aren't we already in AS1? What code are you replacing with this?

I honestly don't know how it's supposed to work at all usually.

Usually we enter AS1 from start.S during early boot (see switch_as), and return to AS0 later in start.S (see _start_cont) after calling cpu_init_early_f().

Right, but the only function that gets called in AS=1 is cpu_init_early_f() which is CPU, not board specific. I really don't want to mess with common code too much unless I'm 100% sure I don't break it and it doesn't break me next time.

Quoted 5 lines
Quoted 2 lines

So I need to run this from AS=0 context, which means we need to quickly go out of AS=0, modify the AS=0 map and go back into AS=0.

What sort of messing would you need to do to cpu_init_early_f()? What part of the normal workflow breaks under QEMU?

#ifndef CONFIG_FSL_CORENET
#if (defined(CONFIG_SYS_RAMBOOT) || defined(CONFIG_SPL)) && \
!defined(CONFIG_SYS_INIT_L2_ADDR)
phys_size_t initdram(int board_type)
{

#if defined(CONFIG_SPD_EEPROM) || defined(CONFIG_DDR_SPD)
        return fsl_ddr_sdram_size();
#else
        return (phys_size_t)CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;

#endif
}
#else /* CONFIG_SYS_RAMBOOT */
phys_size_t initdram(int board_type)
{
[...]

        dram_size = setup_ddr_tlbs(dram_size / 0x100000);

[...]

So because we set CONFIG_SYS_RAMBOOT we never call setup_ddr_tlbs() but instead have to do it ourselves in fsl_ddr_sdram_size(). I'll move the TLB fixup there.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines

arch/powerpc/cpu/mpc85xx/start.S

Quoted 5 lines
arch/powerpc/cpu/mpc85xx/start.S +4 -0
+/* Get RAM size from device tree */
+#define CONFIG_DDR_SPD
+
+#define CONFIG_SYS_CLK_FREQ        33000000

Likewise. BTW, this made up sysclock frequency doesn't match the one you made up elsewhere.

speed.c: In function 'get_sys_info':
speed.c:347:42: error: 'CONFIG_SYS_CLK_FREQ' undeclared (first use in this function)

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

What do we need from speed.c?

Nothing really, but it gets included unconditionally in arch/powerpc/cpu/mpc85xx/Makefile so I can't override it with my own stubs.

You could stick an ifndef CONFIG_QEMU_E500 in there I guess, or define it to be zero and make sure you don't call any of those functions that depend on it.

Hrm, let me try that.

Alex

#16 lore raw

PATCH 3/3 PPC 85xx: Add qemu-ppce500 machine

Quoted 15 lines · Alexander Graf
Quoted 13 lines · Scott Wood
Quoted 12 lines · Alexander Graf
Quoted 9 lines · Scott Wood
Quoted 3 lines · Alexander Graf

which is the only place where we actually use $ramdisk_addr. If a user wants to specify the initrd within U-Boot he can do that easily because he would specify his own boot command anyway, right?

Oh. I was confusing it with the existing $ramdiskaddr. So I'm changing my objection to the fact that it's confusing. :-)

Likewise $fdt_addr versus $fdtaddr.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Mind to explain what the difference is between $fdtaddr, $fdt_addr (pxe boot?) and $fdt_addr_r? Which one should I set?

I don't know what the "_r" is supposed to mean, but the underscore seems to just be something that varies from board to board. Our boards use $fdtaddr and until now I didn't realize other boards do it differently.

Bah - I'll just set all of them.

Ugh, no.

It looks like these are documented in README (and our use of fdtaddr is nonstandard, though the README does state that they're just suggestions). fdt_addr is supposed to be the address in flash, and fdt_addr_r is supposed to be the address in RAM.

Quoted 18 lines
Quoted 2 lines

What sort of messing would you need to do to cpu_init_early_f()? What part of the normal workflow breaks under QEMU?

#ifndef CONFIG_FSL_CORENET
#if (defined(CONFIG_SYS_RAMBOOT) || defined(CONFIG_SPL)) && \
!defined(CONFIG_SYS_INIT_L2_ADDR)
phys_size_t initdram(int board_type)
{

#if defined(CONFIG_SPD_EEPROM) || defined(CONFIG_DDR_SPD)
        return fsl_ddr_sdram_size();
#else
        return (phys_size_t)CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;

#endif
}
#else /* CONFIG_SYS_RAMBOOT */
phys_size_t initdram(int board_type)
{
[...]

Quoted 6 lines
        dram_size = setup_ddr_tlbs(dram_size / 0x100000);

[...]

So because we set CONFIG_SYS_RAMBOOT we never call setup_ddr_tlbs() but instead have to do it ourselves in fsl_ddr_sdram_size(). I'll move the TLB fixup there.

That looks like a bug in RAMBOOT handling, not specific to the QEMU target.

You shouldn't be calling fsl_ddr_sdram_size() at all -- there's no emulated SPD EEPROM.

For that matter, I don't see much in cpu.c that we really want to use for the QEMU target.

-Scott

#17 lore raw

PATCH 3/3 PPC 85xx: Add qemu-ppce500 machine

In reply to Alexander Graf
Quoted 2 lines · Alexander Graf

Hrm, let me try that.

Looks you got plenty feedback from Scott. I am going to mark this set as "change requested" so they will drop off from my to-do list. Please submit a v2 when they are ready (all three patches together) with change log.

York

#4 lore raw

PATCH 1/3 PPC 85xx: Detect e500v2 / e500mc during runtime

In reply to Alexander Graf
Quoted 29 lines · Alexander Graf
Quoted 9 lines · Scott Wood
Quoted 6 lines · Alexander Graf

With the qemu-ppce500 machine type we can run the same board with either an e500v2 or an e500mc core plugged in.

This means that the IVOR setup can't be based on compile time decisions, so instead we have to do a runtime check which CPU generation we're running on.

Is this really the only place where you ran into this?

Yup. At least the only place where the difference actually matters for a VM.

Quoted 6 lines

Also consider that you'll be adding extra size, and some of our 85xx targets are pretty close to the limit as is (though at least this code isn't used in SPLs).

I guess nobody ever bothered to set IVORs for e6500-specific exceptions.

Quoted 7 lines

For that matter, I don't see why we need this code at all. These aren't the addresses that U-Boot keeps its exception vectors at; it's setting them up for the OS, apparently trying to imitate some other type of book3e chip that has fixed ivors. Apparently U-Boot has done this only since 2009 (commit 26f4cdba6b51deab4ec99d60be381244068ef950), so it's not even something that an OS could depend on (and certainly Linux doesn't). So I don't see the point.

Quoted 6 lines

Kumar, do you remember why you put this in? Was it only for prototyping purposes?

I certainly wouldn't mind removing the whole thing altogether.

Alex

I feel like we did have some support for timer & external interrupts in u-boot. Its been a while since I looked.

- k

#5 lore raw

PATCH 1/3 PPC 85xx: Detect e500v2 / e500mc during runtime

Quoted 33 lines · Kumar Gala
Quoted 31 lines · Alexander Graf
Quoted 9 lines · Scott Wood
Quoted 6 lines · Alexander Graf

With the qemu-ppce500 machine type we can run the same board with either an e500v2 or an e500mc core plugged in.

This means that the IVOR setup can't be based on compile time decisions, so instead we have to do a runtime check which CPU generation we're running on.

Is this really the only place where you ran into this?

Yup. At least the only place where the difference actually matters for a VM.

Quoted 6 lines

Also consider that you'll be adding extra size, and some of our 85xx targets are pretty close to the limit as is (though at least this code isn't used in SPLs).

I guess nobody ever bothered to set IVORs for e6500-specific exceptions.

Quoted 7 lines

For that matter, I don't see why we need this code at all. These aren't the addresses that U-Boot keeps its exception vectors at; it's setting them up for the OS, apparently trying to imitate some other type of book3e chip that has fixed ivors. Apparently U-Boot has done this only since 2009 (commit 26f4cdba6b51deab4ec99d60be381244068ef950), so it's not even something that an OS could depend on (and certainly Linux doesn't). So I don't see the point.

Kumar, do you remember why you put this in? Was it only for prototyping purposes?

Quoted 7 lines
Quoted 4 lines

I certainly wouldn't mind removing the whole thing altogether.

Alex

I feel like we did have some support for timer & external interrupts in u-boot. Its been a while since I looked.

This has nothing to do with U-Boot's own exception handlers -- this is what U-Boot is currently doing just prior to entering the OS.

-Scott

#6 lore raw

PATCH 1/3 PPC 85xx: Detect e500v2 / e500mc during runtime

Quoted 40 lines · Scott Wood
Quoted 39 lines · Kumar Gala
Quoted 35 lines · Alexander Graf
Quoted 9 lines · Scott Wood
Quoted 6 lines · Alexander Graf

With the qemu-ppce500 machine type we can run the same board with either an e500v2 or an e500mc core plugged in.

This means that the IVOR setup can't be based on compile time decisions, so instead we have to do a runtime check which CPU generation we're running on.

Is this really the only place where you ran into this?

Yup. At least the only place where the difference actually matters for a VM.

Quoted 6 lines

Also consider that you'll be adding extra size, and some of our 85xx targets are pretty close to the limit as is (though at least this code isn't used in SPLs).

I guess nobody ever bothered to set IVORs for e6500-specific exceptions.

Quoted 7 lines

For that matter, I don't see why we need this code at all. These aren't the addresses that U-Boot keeps its exception vectors at; it's setting them up for the OS, apparently trying to imitate some other type of book3e chip that has fixed ivors. Apparently U-Boot has done this only since 2009 (commit 26f4cdba6b51deab4ec99d60be381244068ef950), so it's not even something that an OS could depend on (and certainly Linux doesn't). So I don't see the point.

Kumar, do you remember why you put this in? Was it only for prototyping purposes?

I certainly wouldn't mind removing the whole thing altogether.

Alex

Quoted 7 lines
Quoted 1 line

I feel like we did have some support for timer & external interrupts in u-boot. Its been a while since I looked.

This has nothing to do with U-Boot's own exception handlers -- this is what U-Boot is currently doing just prior to entering the OS.

-Scott

Oh, right. Did e6500 move to fixed IVORs? If not this can probably be removed as I doubt there will be a new core from FSL that would require this. It was meant as a transition for any OS that cared (if my memory serves me).

- k

#7 lore raw

PATCH 1/3 PPC 85xx: Detect e500v2 / e500mc during runtime

Quoted 5 lines · Kumar Gala
Quoted 3 lines · Scott Wood

This has nothing to do with U-Boot's own exception handlers -- this is what U-Boot is currently doing just prior to entering the OS.

Quoted 7 lines
Quoted 2 lines

-Scott

Oh, right. Did e6500 move to fixed IVORs? If not this can probably be removed as I doubt there will be a new core from FSL that would require this. It was meant as a transition for any OS that cared (if my memory serves me).

e6500 does not have fixed IVORs. I'm not sure why it would matter even if it did. An OS should know whether it is running on a chip with fixed IVORs and behave appropriately, rather than assuming the bootloader fixes things up on older chips to look like newer chips.

-Scott