Skip to contentSkip to conversation

powerpc: Add support for Microwatt soft-core

PATCH Superseded Paul Mackerras 4 participants 26 messages Jun 14, 2021 – Jun 18, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover powerpc: Add support for Microwatt soft-core

This series of patches adds support for the Microwatt soft-core. Microwatt is an open-source 64-bit Power ISA processor written in VHDL which targets medium-sized FPGAs such as the Xilinx Artix-7 or the Lattice ECP5. Microwatt currently implements the scalar fixed plus floating-point subset of Power ISA v3.0B plus the radix MMU, but not logical partitioning (i.e. it does not have hypervisor mode, the partition table or nested radix translation).

Paul.

 arch/powerpc/Kconfig                      |   2 +-
 arch/powerpc/boot/Makefile                |   4 +
 arch/powerpc/boot/devtree.c               |  59 ++++---
 arch/powerpc/boot/dts/microwatt.dts       | 145 +++++++++++++++++
 arch/powerpc/boot/microwatt.c             |  19 +++
 arch/powerpc/boot/ns16550.c               |   9 +-
 arch/powerpc/boot/wrapper                 |   5 +
 arch/powerpc/configs/microwatt_defconfig  |  98 ++++++++++++
 arch/powerpc/include/asm/archrandom.h     |  12 +-
 arch/powerpc/include/asm/reg.h            |   1 +
 arch/powerpc/kernel/udbg_16550.c          |  39 +++++
 arch/powerpc/mm/book3s64/radix_pgtable.c  |  13 +-
 arch/powerpc/platforms/Kconfig            |   1 +
 arch/powerpc/platforms/Makefile           |   1 +
 arch/powerpc/platforms/microwatt/Kconfig  |  13 ++
 arch/powerpc/platforms/microwatt/Makefile |   1 +
 arch/powerpc/platforms/microwatt/rng.c    |  48 ++++++
 arch/powerpc/platforms/microwatt/setup.c  |  41 +++++
 arch/powerpc/sysdev/xics/Kconfig          |   3 +
 arch/powerpc/sysdev/xics/Makefile         |   1 +
 arch/powerpc/sysdev/xics/ics-native.c     | 257 ++++++++++++++++++++++++++++++
 arch/powerpc/sysdev/xics/xics-common.c    |   2 +
 22 files changed, 741 insertions(+), 33 deletions(-)
#1 lore raw

PATCH 1/11 powerpc: Add Microwatt platform

Microwatt is a FPGA-based implementation of the Power ISA. It currently only implements little-endian 64-bit mode, and does not (yet) support SMP, VMX, VSX or transactional memory.

This adds a new machine type to support FPGA-based SoCs with a Microwatt core.

---
 arch/powerpc/Kconfig                      |  2 +-
 arch/powerpc/platforms/Kconfig            |  1 +
 arch/powerpc/platforms/Makefile           |  1 +
 arch/powerpc/platforms/microwatt/Kconfig  |  9 +++++++++
 arch/powerpc/platforms/microwatt/Makefile |  1 +
 arch/powerpc/platforms/microwatt/setup.c  | 23 +++++++++++++++++++++++
 6 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/platforms/microwatt/Kconfig
 create mode 100644 arch/powerpc/platforms/microwatt/Makefile
 create mode 100644 arch/powerpc/platforms/microwatt/setup.c
arch/powerpc/Kconfig +1 -1
index 386ae12d8523..5ce51c38a346 100644
@@ -422,7 +422,7 @@ config HUGETLB_PAGE_SIZE_VARIABLE
 
 config MATH_EMULATION
 	bool "Math emulation"
-	depends on 4xx || PPC_8xx || PPC_MPC832x || BOOKE
+	depends on 4xx || PPC_8xx || PPC_MPC832x || BOOKE || PPC_MICROWATT
 	select PPC_FPU_REGS
 	help
 	  Some PowerPC chips designed for embedded applications do not have
arch/powerpc/platforms/Kconfig +1 -0
index 7a5e8f4541e3..74be4d06afbf 100644
@@ -20,6 +20,7 @@ source "arch/powerpc/platforms/embedded6xx/Kconfig"
 source "arch/powerpc/platforms/44x/Kconfig"
 source "arch/powerpc/platforms/40x/Kconfig"
 source "arch/powerpc/platforms/amigaone/Kconfig"
+source "arch/powerpc/platforms/microwatt/Kconfig"
 
 config KVM_GUEST
 	bool "KVM Guest support"
arch/powerpc/platforms/Makefile +1 -0
index 143d4417f6cc..edcb54cdb1a8 100644
@@ -22,3 +22,4 @@ obj-$(CONFIG_PPC_CELL)		+= cell/
 obj-$(CONFIG_PPC_PS3)		+= ps3/
 obj-$(CONFIG_EMBEDDED6xx)	+= embedded6xx/
 obj-$(CONFIG_AMIGAONE)		+= amigaone/
+obj-$(CONFIG_PPC_MICROWATT)	+= microwatt/
arch/powerpc/platforms/microwatt/Kconfig new file +9 -0
new file mode 100644
index 000000000000..3be01e78ce57
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0
+config PPC_MICROWATT
+	depends on PPC_BOOK3S_64 && !SMP
+	bool "Microwatt SoC platform"
+	select PPC_XICS
+	select PPC_NATIVE
+	help
+          This option enables support for FPGA-based Microwatt implementations.
+
arch/powerpc/platforms/microwatt/Makefile new file +1 -0
new file mode 100644
index 000000000000..e6885b3b2ee7
@@ -0,0 +1 @@
+obj-y	+= setup.o
arch/powerpc/platforms/microwatt/setup.c new file +23 -0
new file mode 100644
index 000000000000..d80d52612672
@@ -0,0 +1,23 @@
+/*
+ * Microwatt FPGA-based SoC platform setup code.
+ *
+ * Copyright 2020 Paul Mackerras ([email protected]), IBM Corp.
+ */
+
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/stddef.h>
+#include <linux/init.h>
+#include <asm/machdep.h>
+#include <asm/time.h>
+
+static int __init microwatt_probe(void)
+{
+	return of_machine_is_compatible("microwatt-soc");
+}
+
+define_machine(microwatt) {
+	.name			= "microwatt",
+	.probe			= microwatt_probe,
+	.calibrate_decr		= generic_calibrate_decr,
+};
Signature · 1 line
2.31.1
#2 lore raw

Re: [PATCH 01/11] powerpc: Add Microwatt platform

Hi Paul,

arch/powerpc/Kconfig config HUGETLB_PAGE_SIZE_VARIABLE · line 426

Quoted 9 lines · Paul Mackerras
arch/powerpc/Kconfig +1 -1
@@ -422,7 +422,7 @@ config HUGETLB_PAGE_SIZE_VARIABLE
 
 config MATH_EMULATION
 	bool "Math emulation"
-	depends on 4xx || PPC_8xx || PPC_MPC832x || BOOKE
+	depends on 4xx || PPC_8xx || PPC_MPC832x || BOOKE || PPC_MICROWATT
 	select PPC_FPU_REGS

Why do you need this / want this, since you have FP hardware?

Segher

#3 lore raw

Re: [PATCH 01/11] powerpc: Add Microwatt platform

Quoted 7 lines · Segher Boessenkool

Hi Paul,

Quoted 4 lines · Paul Mackerras
arch/powerpc/Kconfig +0 -0
@@ -422,7 +422,7 @@ config HUGETLB_PAGE_SIZE_VARIABLE
 
Quoted 7 lines

arch/powerpc/Kconfig config HUGETLB_PAGE_SIZE_VARIABLE · line 426

Quoted 5 lines
arch/powerpc/Kconfig +1 -1
 config MATH_EMULATION
 	bool "Math emulation"
-	depends on 4xx || PPC_8xx || PPC_MPC832x || BOOKE
+	depends on 4xx || PPC_8xx || PPC_MPC832x || BOOKE || PPC_MICROWATT
 	select PPC_FPU_REGS

Why do you need this / want this, since you have FP hardware?

The FPU is optional, and doesn't fit in the smaller (-35T) version of the Artix-7 that is readily available.

I should mention this in the commit message.

Paul.

#4 lore raw

PATCH 2/11 powerpc: Add Microwatt device tree

In reply to Paul Mackerras
---
 arch/powerpc/boot/dts/microwatt.dts | 105 ++++++++++++++++++++++++++++
 1 file changed, 105 insertions(+)
 create mode 100644 arch/powerpc/boot/dts/microwatt.dts
arch/powerpc/boot/dts/microwatt.dts new file +105 -0
new file mode 100644
index 000000000000..9b2e64da9432
@@ -0,0 +1,105 @@
+/dts-v1/;
+
+/ {
+	#size-cells = <0x02>;
+	#address-cells = <0x02>;
+	model-name = "microwatt";
+	compatible = "microwatt-soc";
+
+	reserved-memory {
+		#size-cells = <0x02>;
+		#address-cells = <0x02>;
+		ranges;
+	};
+
+	memory@0 {
+		device_type = "memory";
+		reg = <0x00000000 0x00000000 0x00000000 0x10000000>;
+	};
+
+	cpus {
+		#size-cells = <0x00>;
+		#address-cells = <0x01>;
+
+		ibm,powerpc-cpu-features {
+			display-name = "Microwatt";
+			isa = <3000>;
+			device_type = "cpu-features";
+			compatible = "ibm,powerpc-cpu-features";
+
+			mmu-radix {
+				isa = <3000>;
+				usable-privilege = <2>;
+				os-support = <0x00>;
+			};
+
+			little-endian {
+				isa = <0>;
+				usable-privilege = <3>;
+				os-support = <0x00>;
+			};
+
+			cache-inhibited-large-page {
+				isa = <0x00>;
+				usable-privilege = <2>;
+				os-support = <0x00>;
+			};
+
+			fixed-point-v3 {
+				isa = <3000>;
+				usable-privilege = <3>;
+			};
+
+			no-execute {
+				isa = <0x00>;
+				usable-privilege = <2>;
+				os-support = <0x00>;
+			};
+
+			floating-point {
+				hfscr-bit-nr = <0x00>;
+				hwcap-bit-nr = <0x1b>;
+				isa = <0x00>;
+				usable-privilege = <0x07>;
+				hv-support = <0x00>;
+				os-support = <0x00>;
+			};
+		};
+
+		PowerPC,Microwatt@0 {
+			i-cache-sets = <2>;
+			ibm,dec-bits = <64>;
+			reservation-granule-size = <64>;
+			clock-frequency = <100000000>;
+			timebase-frequency = <100000000>;
+			i-tlb-sets = <1>;
+			ibm,ppc-interrupt-server#s = <0>;
+			i-cache-block-size = <64>;
+			d-cache-block-size = <64>;
+			ibm,pa-features = [40 00 c2 27 00 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 00 80 00 80 00 00 00 80 00 80 00 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00];
+			d-cache-sets = <2>;
+			ibm,pir = <0x3c>;
+			i-tlb-size = <64>;
+			cpu-version = <0x990000>;
+			status = "okay";
+			i-cache-size = <0x1000>;
+			ibm,processor-radix-AP-encodings = <0x0c 0xa0000010 0x20000015 0x4000001e>;
+			tlb-size = <0>;
+			tlb-sets = <0>;
+			device_type = "cpu";
+			d-tlb-size = <128>;
+			d-tlb-sets = <2>;
+			reg = <0>;
+			general-purpose;
+			64-bit;
+			d-cache-size = <0x1000>;
+			ibm,chip-id = <0x00>;
+		};
+	};
+
+	chosen {
+		bootargs = "";
+		ibm,architecture-vec-5 = [19 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00 40];
+	};
+
+};
Signature · 1 line
2.31.1
#5 lore raw

Re: [PATCH 02/11] powerpc: Add Microwatt device tree

Quoted 1 line · Paul Mackerras

Little bit of change log never hurts :)

Quoted 34 lines
---
 arch/powerpc/boot/dts/microwatt.dts | 105 ++++++++++++++++++++++++++++
 1 file changed, 105 insertions(+)
 create mode 100644 arch/powerpc/boot/dts/microwatt.dts
arch/powerpc/boot/dts/microwatt.dts new file +22 -0
new file mode 100644
index 000000000000..9b2e64da9432
@@ -0,0 +1,105 @@
+/dts-v1/;
+
+/ {
+	#size-cells = <0x02>;
+	#address-cells = <0x02>;
+	model-name = "microwatt";
+	compatible = "microwatt-soc";
+
+	reserved-memory {
+		#size-cells = <0x02>;
+		#address-cells = <0x02>;
+		ranges;
+	};
+
+	memory@0 {
+		device_type = "memory";
+		reg = <0x00000000 0x00000000 0x00000000 0x10000000>;
+	};
+
+	cpus {
+		#size-cells = <0x00>;
+		#address-cells = <0x01>;

arch/powerpc/boot/dts/microwatt.dts line 32

Quoted 10 lines
arch/powerpc/boot/dts/microwatt.dts new file +10 -0
+
+		ibm,powerpc-cpu-features {
+			display-name = "Microwatt";
+			isa = <3000>;
+			device_type = "cpu-features";
+			compatible = "ibm,powerpc-cpu-features";
+
+			mmu-radix {
+				isa = <3000>;
+				usable-privilege = <2>;

skiboot says 6?

arch/powerpc/boot/dts/microwatt.dts line 37

Quoted 5 lines
arch/powerpc/boot/dts/microwatt.dts new file +5 -0
+				os-support = <0x00>;
+			};
+
+			little-endian {
+				isa = <0>;

I guess you just copied that from skiboot.

The binding says it's required, but AFAICS the kernel doesn't use it.

And isa = 0 mean ISA_BASE, according to the skiboot source.

arch/powerpc/boot/dts/microwatt.dts line 44

Quoted 7 lines
arch/powerpc/boot/dts/microwatt.dts new file +7 -0
+				usable-privilege = <3>;
+				os-support = <0x00>;
+			};
+
+			cache-inhibited-large-page {
+				isa = <0x00>;
+				usable-privilege = <2>;

skiboot says 6, ie. HV and OS.
Don't think it actually matters because you say os-support = 0.

arch/powerpc/boot/dts/microwatt.dts line 50

Quoted 6 lines
arch/powerpc/boot/dts/microwatt.dts new file +6 -0
+				os-support = <0x00>;
+			};
+
+			fixed-point-v3 {
+				isa = <3000>;
+				usable-privilege = <3>;

skiboot says 7.

arch/powerpc/boot/dts/microwatt.dts line 55

Quoted 5 lines
arch/powerpc/boot/dts/microwatt.dts new file +5 -0
+			};
+
+			no-execute {
+				isa = <0x00>;
+				usable-privilege = <2>;

skiboot says 6.

arch/powerpc/boot/dts/microwatt.dts line 61

Quoted 6 lines
arch/powerpc/boot/dts/microwatt.dts new file +6 -0
+				os-support = <0x00>;
+			};
+
+			floating-point {
+				hfscr-bit-nr = <0x00>;
+				hwcap-bit-nr = <0x1b>;

Looks right, bit 27:

#define PPC_FEATURE_HAS_FPU 0x08000000

arch/powerpc/boot/dts/microwatt.dts line 72

Quoted 11 lines
arch/powerpc/boot/dts/microwatt.dts new file +11 -0
+				isa = <0x00>;
+				usable-privilege = <0x07>;
+				hv-support = <0x00>;
+				os-support = <0x00>;
+			};
+		};
+
+		PowerPC,Microwatt@0 {
+			i-cache-sets = <2>;
+			ibm,dec-bits = <64>;
+			reservation-granule-size = <64>;

Never seen that one before.

arch/powerpc/boot/dts/microwatt.dts line 74

Quoted 2 lines
arch/powerpc/boot/dts/microwatt.dts new file +2 -0
+			clock-frequency = <100000000>;
+			timebase-frequency = <100000000>;

Those seem quite high?

arch/powerpc/boot/dts/microwatt.dts line 78

Quoted 4 lines
arch/powerpc/boot/dts/microwatt.dts new file +4 -0
+			i-tlb-sets = <1>;
+			ibm,ppc-interrupt-server#s = <0>;
+			i-cache-block-size = <64>;
+			d-cache-block-size = <64>;

The kernel reads those, but also hard codes 128 in places. See L1_CACHE_BYTES.

arch/powerpc/boot/dts/microwatt.dts line 79

Quoted 1 line
arch/powerpc/boot/dts/microwatt.dts new file +1 -0
+			ibm,pa-features = [40 00 c2 27 00 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 00 80 00 80 00 00 00 80 00 80 00 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00];

Do you need that?

You shouldn't, if we've done things right with the cpu-features support.

arch/powerpc/boot/dts/microwatt.dts line 81

Quoted 2 lines
arch/powerpc/boot/dts/microwatt.dts new file +2 -0
+			d-cache-sets = <2>;
+			ibm,pir = <0x3c>;

Needed?

arch/powerpc/boot/dts/microwatt.dts line 88

Quoted 7 lines
arch/powerpc/boot/dts/microwatt.dts new file +7 -0
+			i-tlb-size = <64>;
+			cpu-version = <0x990000>;
+			status = "okay";
+			i-cache-size = <0x1000>;
+			ibm,processor-radix-AP-encodings = <0x0c 0xa0000010 0x20000015 0x4000001e>;
+			tlb-size = <0>;
+			tlb-sets = <0>;

Does the kernel use those? I can't find it.

Quoted 4 lines
arch/powerpc/boot/dts/microwatt.dts new file +4 -0
+			device_type = "cpu";
+			d-tlb-size = <128>;
+			d-tlb-sets = <2>;
+			reg = <0>;

arch/powerpc/boot/dts/microwatt.dts line 102

Quoted 10 lines
arch/powerpc/boot/dts/microwatt.dts new file +10 -0
+			general-purpose;
+			64-bit;
+			d-cache-size = <0x1000>;
+			ibm,chip-id = <0x00>;
+		};
+	};
+
+	chosen {
+		bootargs = "";
+		ibm,architecture-vec-5 = [19 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00 40];

Do you need that?

I assume you run with MSR[HV] = 1 (you don't say anywhere), in which case we never look at that property.

cheers

#6 lore raw

Re: [PATCH 02/11] powerpc: Add Microwatt device tree

Quoted 43 lines · Michael Ellerman
Quoted 1 line · Paul Mackerras

Little bit of change log never hurts :)

Quoted 38 lines
---
 arch/powerpc/boot/dts/microwatt.dts | 105 ++++++++++++++++++++++++++++
 1 file changed, 105 insertions(+)
 create mode 100644 arch/powerpc/boot/dts/microwatt.dts
arch/powerpc/boot/dts/microwatt.dts new file +26 -0
new file mode 100644
index 000000000000..9b2e64da9432
@@ -0,0 +1,105 @@
+/dts-v1/;
+
+/ {
+	#size-cells = <0x02>;
+	#address-cells = <0x02>;
+	model-name = "microwatt";
+	compatible = "microwatt-soc";
+
+	reserved-memory {
+		#size-cells = <0x02>;
+		#address-cells = <0x02>;
+		ranges;
+	};
+
+	memory@0 {
+		device_type = "memory";
+		reg = <0x00000000 0x00000000 0x00000000 0x10000000>;
+	};
+
+	cpus {
+		#size-cells = <0x00>;
+		#address-cells = <0x01>;
+
+		ibm,powerpc-cpu-features {
+			display-name = "Microwatt";
+			isa = <3000>;
Quoted 8 lines

arch/powerpc/boot/dts/microwatt.dts line 32

Quoted 6 lines
arch/powerpc/boot/dts/microwatt.dts new file +6 -0
+			device_type = "cpu-features";
+			compatible = "ibm,powerpc-cpu-features";
+
+			mmu-radix {
+				isa = <3000>;
+				usable-privilege = <2>;

skiboot says 6?

That's for a machine with hypervisor mode - if I make it 6 here, then the kernel prints a message about "HV feature passed to guest" and then another about "missing dependency" and ends up not enabling the feature.

Note that microwatt usually has MSR[HV] = 0 (you can set it to 1 but it doesn't do anything). Arguably it should force it to 1 always, but if I do that, then the kernel starts trying to execute hrfid instructions, which microwatt doesn't have (for example in masked_Hinterrupt).

Quoted 11 lines

arch/powerpc/boot/dts/microwatt.dts line 37

Quoted 5 lines
arch/powerpc/boot/dts/microwatt.dts new file +5 -0
+				os-support = <0x00>;
+			};
+
+			little-endian {
+				isa = <0>;

I guess you just copied that from skiboot.

The binding says it's required, but AFAICS the kernel doesn't use it.

And isa = 0 mean ISA_BASE, according to the skiboot source.

I changed it to 2050 since true little-endian mode was introduced for POWER6.

Quoted 6 lines

arch/powerpc/boot/dts/microwatt.dts line 72

Quoted 4 lines
arch/powerpc/boot/dts/microwatt.dts new file +4 -0
+		PowerPC,Microwatt@0 {
+			i-cache-sets = <2>;
+			ibm,dec-bits = <64>;
+			reservation-granule-size = <64>;

Never seen that one before.

It's in PAPR+ (D.6.1.4, CPU Node Properties).

Quoted 4 lines

arch/powerpc/boot/dts/microwatt.dts line 74

Quoted 2 lines
arch/powerpc/boot/dts/microwatt.dts new file +2 -0
+			clock-frequency = <100000000>;
+			timebase-frequency = <100000000>;

Those seem quite high?

No, 100MHz is correct.

Quoted 6 lines

arch/powerpc/boot/dts/microwatt.dts line 78

Quoted 4 lines
arch/powerpc/boot/dts/microwatt.dts new file +4 -0
+			i-tlb-sets = <1>;
+			ibm,ppc-interrupt-server#s = <0>;
+			i-cache-block-size = <64>;
+			d-cache-block-size = <64>;

The kernel reads those, but also hard codes 128 in places.

Interesting, because it all seems to work. I assume the critical thing is doing the right dcbz's.

Quoted 7 lines

See L1_CACHE_BYTES.

arch/powerpc/boot/dts/microwatt.dts line 79

Quoted 1 line
arch/powerpc/boot/dts/microwatt.dts new file +1 -0
+			ibm,pa-features = [40 00 c2 27 00 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 00 80 00 80 00 00 00 80 00 80 00 00 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00];

Do you need that?

You shouldn't, if we've done things right with the cpu-features support.

Turns out I don't need it.

Quoted 4 lines

arch/powerpc/boot/dts/microwatt.dts line 81

Quoted 2 lines
arch/powerpc/boot/dts/microwatt.dts new file +2 -0
+			d-cache-sets = <2>;
+			ibm,pir = <0x3c>;

Needed?

Nope.

Quoted 27 lines

arch/powerpc/boot/dts/microwatt.dts line 88

Quoted 7 lines
arch/powerpc/boot/dts/microwatt.dts new file +7 -0
+			i-tlb-size = <64>;
+			cpu-version = <0x990000>;
+			status = "okay";
+			i-cache-size = <0x1000>;
+			ibm,processor-radix-AP-encodings = <0x0c 0xa0000010 0x20000015 0x4000001e>;
+			tlb-size = <0>;
+			tlb-sets = <0>;

Does the kernel use those? I can't find it.

Quoted 4 lines
arch/powerpc/boot/dts/microwatt.dts new file +4 -0
+			device_type = "cpu";
+			d-tlb-size = <128>;
+			d-tlb-sets = <2>;
+			reg = <0>;

arch/powerpc/boot/dts/microwatt.dts line 102

Quoted 10 lines
arch/powerpc/boot/dts/microwatt.dts new file +10 -0
+			general-purpose;
+			64-bit;
+			d-cache-size = <0x1000>;
+			ibm,chip-id = <0x00>;
+		};
+	};
+
+	chosen {
+		bootargs = "";
+		ibm,architecture-vec-5 = [19 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00 40];

Do you need that?

Quoted 2 lines

I assume you run with MSR[HV] = 1 (you don't say anywhere), in which case we never look at that property.

I do need that given we're running with MSR[HV] = 0; without that the kernel assumes HPT mode.

Paul.

#7 lore raw

PATCH 3/11 powerpc/radix: Add support for microwatt's PRTBL SPR

In reply to Paul Mackerras

Microwatt currently doesn't implement hypervisor mode and therefore doesn't implement the partition table. It does implement the process table and radix page table walks.

This adds code to write the base address of the process table to the PRTBL SPR, which has been assigned SPR 720 for now, as that is in the range of SPR numbers assigned for experimental use. PRTBL is only written when we have neither the FW_FEATURE_LPAR feature nor the CPU_FTR_HVMODE feature.

---
 arch/powerpc/include/asm/reg.h           |  1 +
 arch/powerpc/mm/book3s64/radix_pgtable.c | 13 +++++++++----
 2 files changed, 10 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/reg.h +1 -0
index da103e92c112..3200a2522d6c 100644
@@ -729,6 +729,7 @@
 #endif
 #define SPRN_TIR	0x1BE	/* Thread Identification Register */
 #define SPRN_PTCR	0x1D0	/* Partition table control Register */
+#define SPRN_PRTBL	0x2D0	/* Process table pointer */
 #define SPRN_PSPB	0x09F	/* Problem State Priority Boost reg */
 #define SPRN_PTEHI	0x3D5	/* 981 7450 PTE HI word (S/W TLB load) */
 #define SPRN_PTELO	0x3D6	/* 982 7450 PTE LO word (S/W TLB load) */
arch/powerpc/mm/book3s64/radix_pgtable.c +9 -4
index 98f0b243c1ab..6595859173a7 100644
@@ -646,10 +646,15 @@ void __init radix__early_init_mmu(void)
 	radix_init_pgtable();
 
 	if (!firmware_has_feature(FW_FEATURE_LPAR)) {
-		lpcr = mfspr(SPRN_LPCR);
-		mtspr(SPRN_LPCR, lpcr | LPCR_UPRT | LPCR_HR);
-		radix_init_partition_table();
-		radix_init_amor();
+		if (cpu_has_feature(CPU_FTR_HVMODE)) {
+			lpcr = mfspr(SPRN_LPCR);
+			mtspr(SPRN_LPCR, lpcr | LPCR_UPRT | LPCR_HR);
+			radix_init_partition_table();
+			radix_init_amor();
+		} else {
+			mtspr(SPRN_PRTBL, (__pa(process_tb) |
+					   (PRTB_SIZE_SHIFT - 12)));
+		}
 	} else {
 		radix_init_pseries();
 	}
Signature · 1 line
2.31.1
#8 lore raw

Re: [PATCH 03/11] powerpc/radix: Add support for microwatt's PRTBL SPR

Excerpts from Paul Mackerras's message of June 15, 2021 8:59 am:

Quoted 6 lines

Microwatt currently doesn't implement hypervisor mode and therefore doesn't implement the partition table. It does implement the process table and radix page table walks.

This adds code to write the base address of the process table to the PRTBL SPR,

Is there a particular reason you haven't called it PRTCR or similar to match PTCR?

Quoted 4 lines

which has been assigned SPR 720 for now, as that is in the range of SPR numbers assigned for experimental use. PRTBL is only written when we have neither the FW_FEATURE_LPAR feature nor the CPU_FTR_HVMODE feature.

Seems like reasonable architecture for a non-HV platform.

Could it have a comment to say it's not architected, and a microwatt ifdef until that changes?

The patch also does avoid touching LPCR or initing amor...

Thanks,
Nick

Quoted 47 lines
---
 arch/powerpc/include/asm/reg.h           |  1 +
 arch/powerpc/mm/book3s64/radix_pgtable.c | 13 +++++++++----
 2 files changed, 10 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/reg.h +1 -0
index da103e92c112..3200a2522d6c 100644
@@ -729,6 +729,7 @@
 #endif
 #define SPRN_TIR	0x1BE	/* Thread Identification Register */
 #define SPRN_PTCR	0x1D0	/* Partition table control Register */
+#define SPRN_PRTBL	0x2D0	/* Process table pointer */
 #define SPRN_PSPB	0x09F	/* Problem State Priority Boost reg */
 #define SPRN_PTEHI	0x3D5	/* 981 7450 PTE HI word (S/W TLB load) */
 #define SPRN_PTELO	0x3D6	/* 982 7450 PTE LO word (S/W TLB load) */
arch/powerpc/mm/book3s64/radix_pgtable.c +9 -4
index 98f0b243c1ab..6595859173a7 100644
@@ -646,10 +646,15 @@ void __init radix__early_init_mmu(void)
 	radix_init_pgtable();
 
 	if (!firmware_has_feature(FW_FEATURE_LPAR)) {
-		lpcr = mfspr(SPRN_LPCR);
-		mtspr(SPRN_LPCR, lpcr | LPCR_UPRT | LPCR_HR);
-		radix_init_partition_table();
-		radix_init_amor();
+		if (cpu_has_feature(CPU_FTR_HVMODE)) {
+			lpcr = mfspr(SPRN_LPCR);
+			mtspr(SPRN_LPCR, lpcr | LPCR_UPRT | LPCR_HR);
+			radix_init_partition_table();
+			radix_init_amor();
+		} else {
+			mtspr(SPRN_PRTBL, (__pa(process_tb) |
+					   (PRTB_SIZE_SHIFT - 12)));
+		}
 	} else {
 		radix_init_pseries();
 	}
Signature · 1 line
2.31.1
#9 lore raw

PATCH 4/11 powerpc/microwatt: Populate platform bus from device-tree

In reply to Paul Mackerras

From: Benjamin Herrenschmidt <[email protected]>

Just like any other embedded platform.

Add an empty soc node.

---
 arch/powerpc/boot/dts/microwatt.dts      | 7 +++++++
 arch/powerpc/platforms/microwatt/setup.c | 8 ++++++++
 2 files changed, 15 insertions(+)
arch/powerpc/boot/dts/microwatt.dts +7 -0
index 9b2e64da9432..a72177e5041d 100644
@@ -102,4 +102,11 @@ chosen {
 		ibm,architecture-vec-5 = [19 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00 40];
 	};
 
+	soc@c0000000 {
+		compatible = "simple-bus";
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		ranges = <0 0 0xc0000000 0x40000000>;
+	};
 };
arch/powerpc/platforms/microwatt/setup.c +8 -0
index d80d52612672..5af4adf881bc 100644
@@ -8,6 +8,8 @@
 #include <linux/kernel.h>
 #include <linux/stddef.h>
 #include <linux/init.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
 #include <asm/machdep.h>
 #include <asm/time.h>
 
@@ -16,6 +18,12 @@ static int __init microwatt_probe(void)
 	return of_machine_is_compatible("microwatt-soc");
 }
 
+static int __init microwatt_populate(void)
+{
+	return of_platform_default_populate(NULL, NULL, NULL);
+}
+machine_arch_initcall(microwatt, microwatt_populate);
+
 define_machine(microwatt) {
 	.name			= "microwatt",
 	.probe			= microwatt_probe,
Signature · 1 line
2.31.1
#10 lore raw

PATCH 5/11 powerpc/xics: Add a native ICS backend for microwatt

In reply to Paul Mackerras

From: Benjamin Herrenschmidt <[email protected]>

This is a simple native ICS backend that matches the layout of the Microwatt implementation of ICS.

---
 arch/powerpc/boot/dts/microwatt.dts      |  18 ++
 arch/powerpc/platforms/microwatt/Kconfig |   2 +
 arch/powerpc/platforms/microwatt/setup.c |   8 +
 arch/powerpc/sysdev/xics/Kconfig         |   3 +
 arch/powerpc/sysdev/xics/Makefile        |   1 +
 arch/powerpc/sysdev/xics/ics-native.c    | 257 +++++++++++++++++++++++
 arch/powerpc/sysdev/xics/xics-common.c   |   2 +
 7 files changed, 291 insertions(+)
 create mode 100644 arch/powerpc/sysdev/xics/ics-native.c
arch/powerpc/boot/dts/microwatt.dts +18 -0
index a72177e5041d..2e75600320e8 100644
@@ -106,7 +106,25 @@ soc@c0000000 {
 		compatible = "simple-bus";
 		#address-cells = <1>;
 		#size-cells = <1>;
+		interrupt-parent = <&ICS>;
 
 		ranges = <0 0 0xc0000000 0x40000000>;
+
+		interrupt-controller@4000 {
+			compatible = "openpower,xics-presentation", "ibm,ppc-xicp";
+			ibm,interrupt-server-ranges = <0x0 0x1>;
+			reg = <0x4000 0x100>;
+		};
+
+		ICS: interrupt-controller@5000 {
+			compatible = "openpower,xics-sources";
+			interrupt-controller;
+			interrupt-ranges = <0x10 0x10>;
+			reg = <0x5000 0x100>;
+			#address-cells = <0>;
+			#size-cells = <0>;
+			#interrupt-cells = <2>;
+		};
+
 	};
 };
arch/powerpc/platforms/microwatt/Kconfig +2 -0
index 3be01e78ce57..b52c869c0eb8 100644
@@ -3,6 +3,8 @@ config PPC_MICROWATT
 	depends on PPC_BOOK3S_64 && !SMP
 	bool "Microwatt SoC platform"
 	select PPC_XICS
+	select PPC_ICS_NATIVE
+	select PPC_ICP_NATIVE
 	select PPC_NATIVE
 	help
           This option enables support for FPGA-based Microwatt implementations.
arch/powerpc/platforms/microwatt/setup.c +8 -0
index 5af4adf881bc..1c1b7791fa57 100644
@@ -10,8 +10,15 @@
 #include <linux/init.h>
 #include <linux/of.h>
 #include <linux/of_platform.h>
+
 #include <asm/machdep.h>
 #include <asm/time.h>
+#include <asm/xics.h>
+
+static void __init microwatt_init_IRQ(void)
+{
+	xics_init();
+}
 
 static int __init microwatt_probe(void)
 {
@@ -27,5 +34,6 @@ machine_arch_initcall(microwatt, microwatt_populate);
 define_machine(microwatt) {
 	.name			= "microwatt",
 	.probe			= microwatt_probe,
+	.init_IRQ		= microwatt_init_IRQ,
 	.calibrate_decr		= generic_calibrate_decr,
 };
arch/powerpc/sysdev/xics/Kconfig +3 -0
index 304614c920aa..063d9195891f 100644
@@ -12,3 +12,6 @@ config PPC_ICP_HV
 
 config PPC_ICS_RTAS
 	def_bool n
+
+config PPC_ICS_NATIVE
+	def_bool n
arch/powerpc/sysdev/xics/Makefile +1 -0
index ba1e3117b1c0..747063927c6c 100644
@@ -4,4 +4,5 @@ obj-y				+= xics-common.o
 obj-$(CONFIG_PPC_ICP_NATIVE)	+= icp-native.o
 obj-$(CONFIG_PPC_ICP_HV)	+= icp-hv.o
 obj-$(CONFIG_PPC_ICS_RTAS)	+= ics-rtas.o
+obj-$(CONFIG_PPC_ICS_NATIVE)	+= ics-native.o
 obj-$(CONFIG_PPC_POWERNV)	+= ics-opal.o icp-opal.o
arch/powerpc/sysdev/xics/ics-native.c new file +257 -0

257 lines not on this page · raw message

arch/powerpc/sysdev/xics/xics-common.c +2 -0
index 7e4305c01bac..de41ab91f793 100644
@@ -476,6 +476,8 @@ void __init xics_init(void)
 	rc = ics_rtas_init();
 	if (rc < 0)
 		rc = ics_opal_init();
+	if (rc < 0)
+		rc = ics_native_init();
 	if (rc < 0)
 		pr_warn("XICS: Cannot find a Source Controller !\n");
 
Signature · 1 line
2.31.1
#11 lore raw

PATCH 6/11 powerpc: microwatt: Use standard 16550 UART for console

In reply to Paul Mackerras

From: Benjamin Herrenschmidt <[email protected]>

This adds support to the Microwatt platform to use the standard 1655-style UART which available in the standalone Microwatt FPGA.

---
 arch/powerpc/boot/dts/microwatt.dts      | 25 ++++++++++++---
 arch/powerpc/kernel/udbg_16550.c         | 39 ++++++++++++++++++++++++
 arch/powerpc/platforms/microwatt/Kconfig |  1 +
 arch/powerpc/platforms/microwatt/setup.c |  2 ++
 4 files changed, 62 insertions(+), 5 deletions(-)
arch/powerpc/boot/dts/microwatt.dts +20 -5
index 2e75600320e8..dbde200d4692 100644
@@ -6,6 +6,10 @@ / {
 	model-name = "microwatt";
 	compatible = "microwatt-soc";
 
+	aliases {
+		serial0 = &UART0;
+	};
+
 	reserved-memory {
 		#size-cells = <0x02>;
 		#address-cells = <0x02>;
@@ -97,11 +101,6 @@ PowerPC,Microwatt@0 {
 		};
 	};
 
-	chosen {
-		bootargs = "";
-		ibm,architecture-vec-5 = [19 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00 40];
-	};
-
 	soc@c0000000 {
 		compatible = "simple-bus";
 		#address-cells = <1>;
@@ -126,5 +125,21 @@ ICS: interrupt-controller@5000 {
 			#interrupt-cells = <2>;
 		};
 
+		UART0: serial@2000 {
+			device_type = "serial";
+			compatible = "ns16550";
+			reg = <0x2000 0x8>;
+			clock-frequency = <100000000>;
+			current-speed = <115200>;
+			reg-shift = <2>;
+			fifo-size = <16>;
+			interrupts = <0x10 0x1>;
+		};
+	};
+
+	chosen {
+		bootargs = "";
+		ibm,architecture-vec-5 = [19 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00 40];
+		stdout-path = &UART0;
 	};
 };
arch/powerpc/kernel/udbg_16550.c +39 -0
index 9356b60d6030..8513aa49614e 100644
@@ -296,3 +296,42 @@ void __init udbg_init_40x_realmode(void)
 }
 
 #endif /* CONFIG_PPC_EARLY_DEBUG_40x */
+
+#ifdef CONFIG_PPC_EARLY_DEBUG_MICROWATT
+
+#define UDBG_UART_MW_ADDR	((void __iomem *)0xc0002000)
+
+static u8 udbg_uart_in_isa300_rm(unsigned int reg)
+{
+	uint64_t msr = mfmsr();
+	uint8_t  c;
+
+	mtmsr(msr & ~(MSR_EE|MSR_DR));
+	isync();
+	eieio();
+	c = __raw_rm_readb(UDBG_UART_MW_ADDR + (reg << 2));
+	mtmsr(msr);
+	isync();
+	return c;
+}
+
+static void udbg_uart_out_isa300_rm(unsigned int reg, u8 val)
+{
+	uint64_t msr = mfmsr();
+
+	mtmsr(msr & ~(MSR_EE|MSR_DR));
+	isync();
+	eieio();
+	__raw_rm_writeb(val, UDBG_UART_MW_ADDR + (reg << 2));
+	mtmsr(msr);
+	isync();
+}
+
+void __init udbg_init_debug_microwatt(void)
+{
+	udbg_uart_in = udbg_uart_in_isa300_rm;
+	udbg_uart_out = udbg_uart_out_isa300_rm;
+	udbg_use_uart();
+}
+
+#endif /* CONFIG_PPC_EARLY_DEBUG_MICROWATT */
arch/powerpc/platforms/microwatt/Kconfig +1 -0
index b52c869c0eb8..50ed0cedb5f1 100644
@@ -6,6 +6,7 @@ config PPC_MICROWATT
 	select PPC_ICS_NATIVE
 	select PPC_ICP_NATIVE
 	select PPC_NATIVE
+	select PPC_UDBG_16550
 	help
           This option enables support for FPGA-based Microwatt implementations.
 
arch/powerpc/platforms/microwatt/setup.c +2 -0
index 1c1b7791fa57..0b02603bdb74 100644
@@ -14,6 +14,7 @@
 #include <asm/machdep.h>
 #include <asm/time.h>
 #include <asm/xics.h>
+#include <asm/udbg.h>
 
 static void __init microwatt_init_IRQ(void)
 {
@@ -35,5 +36,6 @@ define_machine(microwatt) {
 	.name			= "microwatt",
 	.probe			= microwatt_probe,
 	.init_IRQ		= microwatt_init_IRQ,
+	.progress		= udbg_progress,
 	.calibrate_decr		= generic_calibrate_decr,
 };
Signature · 1 line
2.31.1
#12 lore raw

Re: [PATCH 06/11] powerpc: microwatt: Use standard 16550 UART for console

Quoted 2 lines · Paul Mackerras

This adds support to the Microwatt platform to use the standard 1655-style UART which available in the standalone Microwatt FPGA.

16550... 1655 is a DAC apparently :-)

Segher

#13 lore raw

PATCH 7/11 powerpc: Add support for microwatt's hardware random number generator

In reply to Paul Mackerras

This is accessed using the DARN instruction and should probably be done more generically.

---
 arch/powerpc/include/asm/archrandom.h     | 12 +++++-
 arch/powerpc/platforms/microwatt/Kconfig  |  1 +
 arch/powerpc/platforms/microwatt/Makefile |  2 +-
 arch/powerpc/platforms/microwatt/rng.c    | 48 +++++++++++++++++++++++
 4 files changed, 61 insertions(+), 2 deletions(-)
 create mode 100644 arch/powerpc/platforms/microwatt/rng.c
arch/powerpc/include/asm/archrandom.h +11 -1
index 9a53e29680f4..e8ae0f7740f9 100644
@@ -8,12 +8,22 @@
 
 static inline bool __must_check arch_get_random_long(unsigned long *v)
 {
+	if (ppc_md.get_random_seed)
+		return ppc_md.get_random_seed(v);
+
 	return false;
 }
 
 static inline bool __must_check arch_get_random_int(unsigned int *v)
 {
-	return false;
+	unsigned long val;
+	bool rc;
+
+	rc = arch_get_random_long(&val);
+	if (rc)
+		*v = val;
+
+	return rc;
 }
 
 static inline bool __must_check arch_get_random_seed_long(unsigned long *v)
arch/powerpc/platforms/microwatt/Kconfig +1 -0
index 50ed0cedb5f1..8f6a81978461 100644
@@ -7,6 +7,7 @@ config PPC_MICROWATT
 	select PPC_ICP_NATIVE
 	select PPC_NATIVE
 	select PPC_UDBG_16550
+	select ARCH_RANDOM
 	help
           This option enables support for FPGA-based Microwatt implementations.
 
arch/powerpc/platforms/microwatt/Makefile +1 -1
index e6885b3b2ee7..116d6d3ad3f0 100644
@@ -1 +1 @@
-obj-y	+= setup.o
+obj-y	+= setup.o rng.o
arch/powerpc/platforms/microwatt/rng.c new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
2.31.1
#14 lore raw

Re: [PATCH 07/11] powerpc: Add support for microwatt's hardware random number generator

Excerpts from Paul Mackerras's message of June 15, 2021 9:02 am:

Quoted 29 lines

This is accessed using the DARN instruction and should probably be done more generically.

---
 arch/powerpc/include/asm/archrandom.h     | 12 +++++-
 arch/powerpc/platforms/microwatt/Kconfig  |  1 +
 arch/powerpc/platforms/microwatt/Makefile |  2 +-
 arch/powerpc/platforms/microwatt/rng.c    | 48 +++++++++++++++++++++++
 4 files changed, 61 insertions(+), 2 deletions(-)
 create mode 100644 arch/powerpc/platforms/microwatt/rng.c
arch/powerpc/include/asm/archrandom.h +3 -1
index 9a53e29680f4..e8ae0f7740f9 100644
@@ -8,12 +8,22 @@
 
 static inline bool __must_check arch_get_random_long(unsigned long *v)
 {
+	if (ppc_md.get_random_seed)
+		return ppc_md.get_random_seed(v);
+
 	return false;
 }
 
 static inline bool __must_check arch_get_random_int(unsigned int *v)
 {
-	return false;

arch/powerpc/include/asm/archrandom.h line 28

Quoted 10 lines
arch/powerpc/include/asm/archrandom.h +8 -0
+	unsigned long val;
+	bool rc;
+
+	rc = arch_get_random_long(&val);
+	if (rc)
+		*v = val;
+
+	return rc;
 }
 

I would be happier if you didn't change this (or at least put it in its own patch explaining why it's not going to slow down other platforms).

I'm assuming the main problem you have is seeding the rngs at boot? It should be enough to have ppc_md.get_random_seed for that.

(BTW I wonder should lib/random32.c be changed to call arch_get_random_seed_long() for seeding)

Quoted 78 lines
arch/powerpc/include/asm/archrandom.h +0 -0
 static inline bool __must_check arch_get_random_seed_long(unsigned long *v)
arch/powerpc/platforms/microwatt/Kconfig +1 -0
index 50ed0cedb5f1..8f6a81978461 100644
@@ -7,6 +7,7 @@ config PPC_MICROWATT
 	select PPC_ICP_NATIVE
 	select PPC_NATIVE
 	select PPC_UDBG_16550
+	select ARCH_RANDOM
 	help
           This option enables support for FPGA-based Microwatt implementations.
 
arch/powerpc/platforms/microwatt/Makefile +1 -1
index e6885b3b2ee7..116d6d3ad3f0 100644
@@ -1 +1 @@
-obj-y	+= setup.o
+obj-y	+= setup.o rng.o
arch/powerpc/platforms/microwatt/rng.c new file +48 -0
new file mode 100644
index 000000000000..3d8ee6eb7dad
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Derived from arch/powerpc/platforms/powernv/rng.c, which is:
+ * Copyright 2013, Michael Ellerman, IBM Corporation.
+ */
+
+#define pr_fmt(fmt)	"microwatt-rng: " fmt
+
+#include <linux/kernel.h>
+#include <linux/smp.h>
+#include <asm/archrandom.h>
+#include <asm/cputable.h>
+#include <asm/machdep.h>
+
+#define DARN_ERR 0xFFFFFFFFFFFFFFFFul
+
+int microwatt_get_random_darn(unsigned long *v)
+{
+	unsigned long val;
+
+	/* Using DARN with L=1 - 64-bit conditioned random number */
+	asm volatile(PPC_DARN(%0, 1) : "=r"(val));
+
+	if (val == DARN_ERR)
+		return 0;
+
+	*v = val;
+
+	return 1;
+}
+
+static __init int rng_init(void)
+{
+	unsigned long val;
+	int i;
+
+	for (i = 0; i < 10; i++) {
+		if (microwatt_get_random_darn(&val)) {
+			ppc_md.get_random_seed = microwatt_get_random_darn;
+			return 0;
+		}
+	}
+
+	pr_warn("Unable to use DARN for get_random_seed()\n");
+
+	return -EIO;
+}
+machine_subsys_initcall(, rng_init);
Signature · 1 line
2.31.1
#15 lore raw

Re: [PATCH 07/11] powerpc: Add support for microwatt's hardware random number generator

Quoted 27 lines · Nicholas Piggin

Excerpts from Paul Mackerras's message of June 15, 2021 9:02 am:

Quoted 26 lines

This is accessed using the DARN instruction and should probably be done more generically.

---
 arch/powerpc/include/asm/archrandom.h     | 12 +++++-
 arch/powerpc/platforms/microwatt/Kconfig  |  1 +
 arch/powerpc/platforms/microwatt/Makefile |  2 +-
 arch/powerpc/platforms/microwatt/rng.c    | 48 +++++++++++++++++++++++
 4 files changed, 61 insertions(+), 2 deletions(-)
 create mode 100644 arch/powerpc/platforms/microwatt/rng.c
arch/powerpc/include/asm/archrandom.h +3 -0
index 9a53e29680f4..e8ae0f7740f9 100644
@@ -8,12 +8,22 @@
 
 static inline bool __must_check arch_get_random_long(unsigned long *v)
 {
+	if (ppc_md.get_random_seed)
+		return ppc_md.get_random_seed(v);
+
 	return false;
 }
 
Quoted 16 lines

arch/powerpc/include/asm/archrandom.h line 28

Quoted 13 lines
arch/powerpc/include/asm/archrandom.h +8 -1
 static inline bool __must_check arch_get_random_int(unsigned int *v)
 {
-	return false;
+	unsigned long val;
+	bool rc;
+
+	rc = arch_get_random_long(&val);
+	if (rc)
+		*v = val;
+
+	return rc;
 }
 

I would be happier if you didn't change this (or at least put it in its own patch explaining why it's not going to slow down other platforms).

It would essentially be a revert of 01c9348c7620 ("powerpc: Use hardware RNG for arch_get_random_seed_* not arch_get_random_*")

Which would be ironic :)

cheers

#16 lore raw

Re: [PATCH 07/11] powerpc: Add support for microwatt's hardware random number generator

Quoted 8 lines · Michael Ellerman
Quoted 2 lines · Nicholas Piggin

I would be happier if you didn't change this (or at least put it in its own patch explaining why it's not going to slow down other platforms).

It would essentially be a revert of 01c9348c7620 ("powerpc: Use hardware RNG for arch_get_random_seed_* not arch_get_random_*")

Which would be ironic :)

You expect me to remember things I did 6 years ago? :)

I'll take this part out. My thinking originally was that since darn on Microwatt is a single-cycle instruction, it would be faster to use darn every time rather than run a software PRNG seeded from darn. It's not critical though.

Paul.

#17 lore raw

PATCH 8/11 powerpc/microwatt: Add microwatt_defconfig

In reply to Paul Mackerras
---
 arch/powerpc/configs/microwatt_defconfig | 98 ++++++++++++++++++++++++
 1 file changed, 98 insertions(+)
 create mode 100644 arch/powerpc/configs/microwatt_defconfig
arch/powerpc/configs/microwatt_defconfig new file +98 -0
new file mode 100644
index 000000000000..a08b739123da
@@ -0,0 +1,98 @@
+# CONFIG_SWAP is not set
+# CONFIG_CROSS_MEMORY_ATTACH is not set
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_PREEMPT_VOLUNTARY=y
+CONFIG_TICK_CPU_ACCOUNTING=y
+CONFIG_LOG_BUF_SHIFT=16
+CONFIG_PRINTK_SAFE_LOG_BUF_SHIFT=12
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_KALLSYMS_ALL=y
+CONFIG_EMBEDDED=y
+# CONFIG_VM_EVENT_COUNTERS is not set
+# CONFIG_SLUB_DEBUG is not set
+# CONFIG_COMPAT_BRK is not set
+# CONFIG_SLAB_MERGE_DEFAULT is not set
+CONFIG_PPC64=y
+# CONFIG_PPC_KUEP is not set
+# CONFIG_PPC_KUAP is not set
+CONFIG_CPU_LITTLE_ENDIAN=y
+CONFIG_NR_IRQS=64
+CONFIG_PANIC_TIMEOUT=10
+# CONFIG_PPC_POWERNV is not set
+# CONFIG_PPC_PSERIES is not set
+CONFIG_PPC_MICROWATT=y
+# CONFIG_PPC_OF_BOOT_TRAMPOLINE is not set
+CONFIG_CPU_FREQ=y
+CONFIG_HZ_100=y
+# CONFIG_PPC_MEM_KEYS is not set
+# CONFIG_SECCOMP is not set
+# CONFIG_MQ_IOSCHED_KYBER is not set
+# CONFIG_COREDUMP is not set
+# CONFIG_COMPACTION is not set
+# CONFIG_MIGRATION is not set
+CONFIG_NET=y
+CONFIG_PACKET=y
+CONFIG_PACKET_DIAG=y
+CONFIG_UNIX=y
+CONFIG_UNIX_DIAG=y
+CONFIG_INET=y
+CONFIG_INET_UDP_DIAG=y
+CONFIG_INET_RAW_DIAG=y
+# CONFIG_WIRELESS is not set
+CONFIG_DEVTMPFS=y
+CONFIG_DEVTMPFS_MOUNT=y
+# CONFIG_STANDALONE is not set
+# CONFIG_PREVENT_FIRMWARE_BUILD is not set
+# CONFIG_FW_LOADER is not set
+# CONFIG_ALLOW_DEV_COREDUMP is not set
+CONFIG_MTD=y
+CONFIG_MTD_BLOCK=y
+CONFIG_MTD_PARTITIONED_MASTER=y
+CONFIG_MTD_SPI_NOR=y
+CONFIG_BLK_DEV_LOOP=y
+CONFIG_BLK_DEV_RAM=y
+CONFIG_NETDEVICES=y
+# CONFIG_WLAN is not set
+# CONFIG_INPUT is not set
+# CONFIG_SERIO is not set
+# CONFIG_VT is not set
+CONFIG_SERIAL_8250=y
+# CONFIG_SERIAL_8250_DEPRECATED_OPTIONS is not set
+CONFIG_SERIAL_8250_CONSOLE=y
+CONFIG_SERIAL_OF_PLATFORM=y
+CONFIG_SERIAL_NONSTANDARD=y
+# CONFIG_NVRAM is not set
+CONFIG_RANDOM_TRUST_CPU=y
+CONFIG_SPI=y
+CONFIG_SPI_DEBUG=y
+CONFIG_SPI_BITBANG=y
+CONFIG_SPI_SPIDEV=y
+# CONFIG_HWMON is not set
+# CONFIG_USB_SUPPORT is not set
+# CONFIG_VIRTIO_MENU is not set
+# CONFIG_IOMMU_SUPPORT is not set
+# CONFIG_NVMEM is not set
+CONFIG_EXT4_FS=y
+# CONFIG_FILE_LOCKING is not set
+# CONFIG_DNOTIFY is not set
+# CONFIG_INOTIFY_USER is not set
+# CONFIG_MISC_FILESYSTEMS is not set
+# CONFIG_CRYPTO_HW is not set
+# CONFIG_XZ_DEC_X86 is not set
+# CONFIG_XZ_DEC_IA64 is not set
+# CONFIG_XZ_DEC_ARM is not set
+# CONFIG_XZ_DEC_ARMTHUMB is not set
+# CONFIG_XZ_DEC_SPARC is not set
+CONFIG_PRINTK_TIME=y
+# CONFIG_SYMBOLIC_ERRNAME is not set
+# CONFIG_DEBUG_BUGVERBOSE is not set
+# CONFIG_DEBUG_MISC is not set
+# CONFIG_SCHED_DEBUG is not set
+# CONFIG_FTRACE is not set
+# CONFIG_STRICT_DEVMEM is not set
+CONFIG_PPC_DISABLE_WERROR=y
+CONFIG_XMON=y
+CONFIG_XMON_DEFAULT=y
+# CONFIG_XMON_DEFAULT_RO_MODE is not set
+# CONFIG_RUNTIME_TESTING_MENU is not set
Signature · 1 line
2.31.1
#18 lore raw

PATCH 9/11 powerpc: boot: Fixup device-tree on little endian

In reply to Paul Mackerras

From: Benjamin Herrenschmidt <[email protected]>

This fixes the core devtree.c functions and the ns16550 UART backend.

---
 arch/powerpc/boot/devtree.c | 59 +++++++++++++++++++++----------------
 arch/powerpc/boot/ns16550.c |  9 ++++--
 2 files changed, 41 insertions(+), 27 deletions(-)
arch/powerpc/boot/devtree.c +34 -25
index 5d91036ad626..58fbcfcc98c9 100644
@@ -13,6 +13,7 @@
 #include "string.h"
 #include "stdio.h"
 #include "ops.h"
+#include "of.h"
 
 void dt_fixup_memory(u64 start, u64 size)
 {
@@ -23,21 +24,25 @@ void dt_fixup_memory(u64 start, u64 size)
 	root = finddevice("/");
 	if (getprop(root, "#address-cells", &naddr, sizeof(naddr)) < 0)
 		naddr = 2;
+	else
+		naddr = be32_to_cpu(naddr);
 	if (naddr < 1 || naddr > 2)
 		fatal("Can't cope with #address-cells == %d in /\n\r", naddr);
 
 	if (getprop(root, "#size-cells", &nsize, sizeof(nsize)) < 0)
 		nsize = 1;
+	else
+		nsize = be32_to_cpu(nsize);
 	if (nsize < 1 || nsize > 2)
 		fatal("Can't cope with #size-cells == %d in /\n\r", nsize);
 
 	i = 0;
 	if (naddr == 2)
-		memreg[i++] = start >> 32;
-	memreg[i++] = start & 0xffffffff;
+		memreg[i++] = cpu_to_be32(start >> 32);
+	memreg[i++] = cpu_to_be32(start & 0xffffffff);
 	if (nsize == 2)
-		memreg[i++] = size >> 32;
-	memreg[i++] = size & 0xffffffff;
+		memreg[i++] = cpu_to_be32(size >> 32);
+	memreg[i++] = cpu_to_be32(size & 0xffffffff);
 
 	memory = finddevice("/memory");
 	if (! memory) {
@@ -45,9 +50,9 @@ void dt_fixup_memory(u64 start, u64 size)
 		setprop_str(memory, "device_type", "memory");
 	}
 
-	printf("Memory <- <0x%x", memreg[0]);
+	printf("Memory <- <0x%x", be32_to_cpu(memreg[0]));
 	for (i = 1; i < (naddr + nsize); i++)
-		printf(" 0x%x", memreg[i]);
+		printf(" 0x%x", be32_to_cpu(memreg[i]));
 	printf("> (%ldMB)\n\r", (unsigned long)(size >> 20));
 
 	setprop(memory, "reg", memreg, (naddr + nsize)*sizeof(u32));
@@ -65,10 +70,10 @@ void dt_fixup_cpu_clocks(u32 cpu, u32 tb, u32 bus)
 		printf("CPU bus-frequency <- 0x%x (%dMHz)\n\r", bus, MHZ(bus));
 
 	while ((devp = find_node_by_devtype(devp, "cpu"))) {
-		setprop_val(devp, "clock-frequency", cpu);
-		setprop_val(devp, "timebase-frequency", tb);
+		setprop_val(devp, "clock-frequency", cpu_to_be32(cpu));
+		setprop_val(devp, "timebase-frequency", cpu_to_be32(tb));
 		if (bus > 0)
-			setprop_val(devp, "bus-frequency", bus);
+			setprop_val(devp, "bus-frequency", cpu_to_be32(bus));
 	}
 
 	timebase_period_ns = 1000000000 / tb;
@@ -80,7 +85,7 @@ void dt_fixup_clock(const char *path, u32 freq)
 
 	if (devp) {
 		printf("%s: clock-frequency <- %x (%dMHz)\n\r", path, freq, MHZ(freq));
-		setprop_val(devp, "clock-frequency", freq);
+		setprop_val(devp, "clock-frequency", cpu_to_be32(freq));
 	}
 }
 
@@ -133,8 +138,12 @@ void dt_get_reg_format(void *node, u32 *naddr, u32 *nsize)
 {
 	if (getprop(node, "#address-cells", naddr, 4) != 4)
 		*naddr = 2;
+	else
+		*naddr = be32_to_cpu(*naddr);
 	if (getprop(node, "#size-cells", nsize, 4) != 4)
 		*nsize = 1;
+	else
+		*nsize = be32_to_cpu(*nsize);
 }
 
 static void copy_val(u32 *dest, u32 *src, int naddr)
@@ -163,9 +172,9 @@ static int add_reg(u32 *reg, u32 *add, int naddr)
 	int i, carry = 0;
 
 	for (i = MAX_ADDR_CELLS - 1; i >= MAX_ADDR_CELLS - naddr; i--) {
-		u64 tmp = (u64)reg[i] + add[i] + carry;
+		u64 tmp = (u64)be32_to_cpu(reg[i]) + be32_to_cpu(add[i]) + carry;
 		carry = tmp >> 32;
-		reg[i] = (u32)tmp;
+		reg[i] = cpu_to_be32((u32)tmp);
 	}
 
 	return !carry;
@@ -180,18 +189,18 @@ static int compare_reg(u32 *reg, u32 *range, u32 *rangesize)
 	u32 end;
 
 	for (i = 0; i < MAX_ADDR_CELLS; i++) {
-		if (reg[i] < range[i])
+		if (be32_to_cpu(reg[i]) < be32_to_cpu(range[i]))
 			return 0;
-		if (reg[i] > range[i])
+		if (be32_to_cpu(reg[i]) > be32_to_cpu(range[i]))
 			break;
 	}
 
 	for (i = 0; i < MAX_ADDR_CELLS; i++) {
-		end = range[i] + rangesize[i];
+		end = be32_to_cpu(range[i]) + be32_to_cpu(rangesize[i]);
 
-		if (reg[i] < end)
+		if (be32_to_cpu(reg[i]) < end)
 			break;
-		if (reg[i] > end)
+		if (be32_to_cpu(reg[i]) > end)
 			return 0;
 	}
 
@@ -240,7 +249,6 @@ static int dt_xlate(void *node, int res, int reglen, unsigned long *addr,
 		return 0;
 
 	dt_get_reg_format(parent, &naddr, &nsize);
-
 	if (nsize > 2)
 		return 0;
 
@@ -252,10 +260,10 @@ static int dt_xlate(void *node, int res, int reglen, unsigned long *addr,
 
 	copy_val(last_addr, prop_buf + offset, naddr);
 
-	ret_size = prop_buf[offset + naddr];
+	ret_size = be32_to_cpu(prop_buf[offset + naddr]);
 	if (nsize == 2) {
 		ret_size <<= 32;
-		ret_size |= prop_buf[offset + naddr + 1];
+		ret_size |= be32_to_cpu(prop_buf[offset + naddr + 1]);
 	}
 
 	for (;;) {
@@ -278,7 +286,6 @@ static int dt_xlate(void *node, int res, int reglen, unsigned long *addr,
 
 		offset = find_range(last_addr, prop_buf, prev_naddr,
 		                    naddr, prev_nsize, buflen / 4);
-
 		if (offset < 0)
 			return 0;
 
@@ -296,8 +303,7 @@ static int dt_xlate(void *node, int res, int reglen, unsigned long *addr,
 	if (naddr > 2)
 		return 0;
 
-	ret_addr = ((u64)last_addr[2] << 32) | last_addr[3];
-
+	ret_addr = ((u64)be32_to_cpu(last_addr[2]) << 32) | be32_to_cpu(last_addr[3]);
 	if (sizeof(void *) == 4 &&
 	    (ret_addr >= 0x100000000ULL || ret_size > 0x100000000ULL ||
 	     ret_addr + ret_size > 0x100000000ULL))
@@ -350,11 +356,14 @@ int dt_is_compatible(void *node, const char *compat)
 int dt_get_virtual_reg(void *node, void **addr, int nres)
 {
 	unsigned long xaddr;
-	int n;
+	int n, i;
 
 	n = getprop(node, "virtual-reg", addr, nres * 4);
-	if (n > 0)
+	if (n > 0) {
+		for (i = 0; i < n/4; i ++)
+			((u32 *)addr)[i] = be32_to_cpu(((u32 *)addr)[i]);
 		return n / 4;
+	}
 
 	for (n = 0; n < nres; n++) {
 		if (!dt_xlate_reg(node, n, &xaddr, NULL))
arch/powerpc/boot/ns16550.c +7 -2
index b0da4466d419..f16d2be1d0f3 100644
@@ -15,6 +15,7 @@
 #include "stdio.h"
 #include "io.h"
 #include "ops.h"
+#include "of.h"
 
 #define UART_DLL	0	/* Out: Divisor Latch Low */
 #define UART_DLM	1	/* Out: Divisor Latch High */
@@ -58,16 +59,20 @@ int ns16550_console_init(void *devp, struct serial_console_data *scdp)
 	int n;
 	u32 reg_offset;
 
-	if (dt_get_virtual_reg(devp, (void **)&reg_base, 1) < 1)
+	if (dt_get_virtual_reg(devp, (void **)&reg_base, 1) < 1) {
+		printf("virt reg parse fail...\r\n");
 		return -1;
+	}
 
 	n = getprop(devp, "reg-offset", &reg_offset, sizeof(reg_offset));
 	if (n == sizeof(reg_offset))
-		reg_base += reg_offset;
+		reg_base += be32_to_cpu(reg_offset);
 
 	n = getprop(devp, "reg-shift", &reg_shift, sizeof(reg_shift));
 	if (n != sizeof(reg_shift))
 		reg_shift = 0;
+	else
+		reg_shift = be32_to_cpu(reg_shift);
 
 	scdp->open = ns16550_open;
 	scdp->putc = ns16550_putc;
Signature · 1 line
2.31.1
#19 lore raw

PATCH 10/11 powerpc/microwatt: Add a boot wrapper for Microwatt

In reply to Paul Mackerras

From: Joel Stanley <[email protected]>

This allows microwatt's kernel to be built with an embedded device tree.

Load to arch/powerpc/boot/dtbImage.microwatt to 0x500000:

mw_debug -b fpga stop load arch/powerpc/boot/dtbImage.microwatt 500000 start

---
 arch/powerpc/boot/Makefile    |  4 ++++
 arch/powerpc/boot/microwatt.c | 18 ++++++++++++++++++
 arch/powerpc/boot/wrapper     |  5 +++++
 3 files changed, 27 insertions(+)
 create mode 100644 arch/powerpc/boot/microwatt.c
arch/powerpc/boot/Makefile +4 -0
index 2b8da923ceca..dfaa4094fcae 100644
@@ -163,6 +163,8 @@ src-plat-$(CONFIG_PPC_POWERNV) += pseries-head.S
 src-plat-$(CONFIG_PPC_IBM_CELL_BLADE) += pseries-head.S
 src-plat-$(CONFIG_MVME7100) += motload-head.S mvme7100.c
 
+src-plat-$(CONFIG_PPC_MICROWATT) += fixed-head.S microwatt.c
+
 src-wlib := $(sort $(src-wlib-y))
 src-plat := $(sort $(src-plat-y))
 src-boot := $(src-wlib) $(src-plat) empty.c
@@ -355,6 +357,8 @@ image-$(CONFIG_MVME5100)		+= dtbImage.mvme5100
 # Board port in arch/powerpc/platform/amigaone/Kconfig
 image-$(CONFIG_AMIGAONE)		+= cuImage.amigaone
 
+image-$(CONFIG_PPC_MICROWATT)		+= dtbImage.microwatt
+
 # For 32-bit powermacs, build the COFF and miboot images
 # as well as the ELF images.
 ifdef CONFIG_PPC32
arch/powerpc/boot/microwatt.c new file +18 -0
new file mode 100644
index 000000000000..ac922dd0aa4d
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <stddef.h>
+#include "stdio.h"
+#include "types.h"
+#include "io.h"
+#include "ops.h"
+
+BSS_STACK(8192);
+
+void platform_init(unsigned long r3, unsigned long r4, unsigned long r5)
+{
+	unsigned long heapsize = 16*1024*1024 - (unsigned long)_end;
+
+	simple_alloc_init(_end, heapsize, 32, 64);
+	fdt_init(_dtb_start);
+	serial_console_init();
+}
arch/powerpc/boot/wrapper +5 -0
index 41fa0a8715e3..ae48fffa1e13 100755
@@ -342,6 +342,11 @@ gamecube|wii)
     link_address='0x600000'
     platformo="$object/$platform-head.o $object/$platform.o"
     ;;
+microwatt)
+    link_address='0x500000'
+    platformo="$object/fixed-head.o $object/$platform.o"
+    binary=y
+    ;;
 treeboot-currituck)
     link_address='0x1000000'
     ;;
Signature · 1 line
2.31.1
#20 lore raw

PATCH 11/11 powerpc/microwatt: Disable interrupts in boot wrapper main program

In reply to Paul Mackerras

This ensures that we don't get a decrementer interrupt arriving before we have set up a handler for it.

---
 arch/powerpc/boot/microwatt.c | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/boot/microwatt.c +1 -0
index ac922dd0aa4d..86a07bceaadf 100644
@@ -12,6 +12,7 @@ void platform_init(unsigned long r3, unsigned long r4, unsigned long r5)
 {
 	unsigned long heapsize = 16*1024*1024 - (unsigned long)_end;
 
+	__asm__ volatile("mtmsrd %0,1" : : "r" (0));
 	simple_alloc_init(_end, heapsize, 32, 64);
 	fdt_init(_dtb_start);
 	serial_console_init();
Signature · 1 line
2.31.1
#21 lore raw

Re: [PATCH 11/11] powerpc/microwatt: Disable interrupts in boot wrapper main program

Excerpts from Paul Mackerras's message of June 15, 2021 9:05 am:

Quoted 2 lines

This ensures that we don't get a decrementer interrupt arriving before we have set up a handler for it.

Would this be better off merged in the previous patch (maybe with comment)? Why don't other platform_init()s seem to require this?

Thanks,
Nick

Quoted 22 lines
---
 arch/powerpc/boot/microwatt.c | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/boot/microwatt.c +1 -0
index ac922dd0aa4d..86a07bceaadf 100644
@@ -12,6 +12,7 @@ void platform_init(unsigned long r3, unsigned long r4, unsigned long r5)
 {
 	unsigned long heapsize = 16*1024*1024 - (unsigned long)_end;
 
+	__asm__ volatile("mtmsrd %0,1" : : "r" (0));
 	simple_alloc_init(_end, heapsize, 32, 64);
 	fdt_init(_dtb_start);
 	serial_console_init();
Signature · 1 line
2.31.1
#22 lore raw

Re: [PATCH 11/11] powerpc/microwatt: Disable interrupts in boot wrapper main program

In reply to Paul Mackerras
Quoted 2 lines · Paul Mackerras

This ensures that we don't get a decrementer interrupt arriving before we have set up a handler for it.

Maybe add a comment saying this is setting MSR[EE]=0 for that? Or do other bits here matter as well?

Segher

#23 lore raw

Re: [PATCH 11/11] powerpc/microwatt: Disable interrupts in boot wrapper main program

Excerpts from Segher Boessenkool's message of June 17, 2021 9:37 am:

Quoted 6 lines · Paul Mackerras
Quoted 2 lines

This ensures that we don't get a decrementer interrupt arriving before we have set up a handler for it.

Maybe add a comment saying this is setting MSR[EE]=0 for that? Or do other bits here matter as well?

Hmm, it actually clears MSR[RI] as well.

__hard_irq_disable() is what we want here, unless the MSR[RI] clearing is required as well, in which case there is __hard_EE_RI_disable().

Thanks,
Nick

#24 lore raw

Re: [PATCH 11/11] powerpc/microwatt: Disable interrupts in boot wrapper main program

Quoted 5 lines · Nicholas Piggin

Excerpts from Segher Boessenkool's message of June 17, 2021 9:37 am:

Quoted 4 lines · Paul Mackerras
Quoted 2 lines

This ensures that we don't get a decrementer interrupt arriving before we have set up a handler for it.

Quoted 7 lines
Quoted 2 lines

Maybe add a comment saying this is setting MSR[EE]=0 for that? Or do other bits here matter as well?

Hmm, it actually clears MSR[RI] as well.

__hard_irq_disable() is what we want here, unless the MSR[RI] clearing is required as well, in which case there is __hard_EE_RI_disable().

But neither of those exist in the boot wrapper (yet).

cheers

#25 lore raw

Re: [PATCH 11/11] powerpc/microwatt: Disable interrupts in boot wrapper main program

In reply to Nicholas Piggin
Quoted 5 lines · Nicholas Piggin

Excerpts from Segher Boessenkool's message of June 17, 2021 9:37 am:

Quoted 4 lines · Paul Mackerras
Quoted 2 lines

This ensures that we don't get a decrementer interrupt arriving before we have set up a handler for it.

Quoted 7 lines
Quoted 2 lines

Maybe add a comment saying this is setting MSR[EE]=0 for that? Or do other bits here matter as well?

Hmm, it actually clears MSR[RI] as well.

__hard_irq_disable() is what we want here, unless the MSR[RI] clearing is required as well, in which case there is __hard_EE_RI_disable().

I don't think it matters if MSR[RI] is set or not here, nothing will try to recover from an actual reboot I hope :-)

Segher