Skip to contentSkip to conversation

Microwatt updates

PATCH Applied Paul Mackerras 2 participants 7 messages Jan 31, 2025 – Mar 2, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover Microwatt updates

This patch series updates the kernel support for the Microwatt soft-core and its implementation on FPGA systems, particularly the Digilent Arty A7-100 FPGA development board.

Microwatt now supports almost all of the features of the SFFS (Scalar Fixed-point and Floating-point Subset) compliancy subset of Power ISA version 3.1C, including prefixed instructions and the fixed-point hash (ROP mitigation) instructions. It is also now SMP-capable, and a dual-core system will fit on the Arty A7-100 board.

Microwatt does not have broadcast TLB invalidations in SMP systems; the kernel already has code to deal with this. One of the patches in this series provides a config option to allow platforms to select unconditionally the behaviour where cross-CPU TLB invalidations are handled using inter-processor interrupts.

Tested on an Arty A7-100 FPGA board with 2 CPUs. Compile-tested for pseries and powernv.

Paul.
---
v2: Address review comments

 arch/powerpc/boot/dts/microwatt.dts          | 107 +++++++++++++++++++++++----
 arch/powerpc/mm/book3s64/pgtable.c           |   4 +-
 arch/powerpc/platforms/Kconfig.cputype       |  13 ++++
 arch/powerpc/platforms/microwatt/Kconfig     |   3 +-
 arch/powerpc/platforms/microwatt/Makefile    |   1 +
 arch/powerpc/platforms/microwatt/microwatt.h |   1 +
 arch/powerpc/platforms/microwatt/setup.c     |  18 +++++
 arch/powerpc/platforms/microwatt/smp.c       |  80 ++++++++++++++++++++
 arch/powerpc/platforms/powernv/Kconfig       |   1 +
 arch/powerpc/platforms/pseries/Kconfig       |   1 +
 10 files changed, 213 insertions(+), 16 deletions(-)
#1 lore raw

PATCH v2 1/5 powerpc/microwatt: Select COMMON_CLK in order to get the clock framework

This is to allow us to select Litex MMC host controller driver, which drives the litesdcard gateware.

---
 arch/powerpc/platforms/microwatt/Kconfig | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/platforms/microwatt/Kconfig +1 -0
index 6af443a1db99..5e41adadac1f 100644
@@ -6,6 +6,7 @@ config PPC_MICROWATT
 	select PPC_ICS_NATIVE
 	select PPC_ICP_NATIVE
 	select PPC_UDBG_16550
+	select COMMON_CLK
 	help
           This option enables support for FPGA-based Microwatt implementations.
 
Signature · 1 line
2.47.1
#2 lore raw

PATCH v2 2/5 powerpc/microwatt: Device-tree updates

In reply to Paul Mackerras

Microwatt now implements ISA v3.1 (SFFS compliancy subset), including prefixed instructions, scv/rfscv, and the FSCR, HFSCR, TAR, and CTRL registers. The privileged mode of operation is now hypervisor mode and there is no privileged non-hypervisor mode; the MSR[HV] bit is forced to 1.

Besides updating the ibm,powerpc-cpu-features property to reflect the above, this also makes the following changes relating to peripheral devices:

- Add gpio controller.
- Remove high-speed property from SD controller, for the case where the interface is connected through 200 ohm protection resisters.
- Put an alias for the ethernet in /chosen.

---
v2: scv node specifies ISA v3.0

 arch/powerpc/boot/dts/microwatt.dts | 73 ++++++++++++++++++++++++-----
 1 file changed, 62 insertions(+), 11 deletions(-)
arch/powerpc/boot/dts/microwatt.dts +62 -11
index 269e930b3b0b..833d22822189 100644
@@ -1,4 +1,5 @@
 /dts-v1/;
+#include <dt-bindings/gpio/gpio.h>
 
 / {
 	#size-cells = <0x02>;
@@ -8,6 +9,7 @@ / {
 
 	aliases {
 		serial0 = &UART0;
+		ethernet = &enet0;
 	};
 
 	reserved-memory {
@@ -35,40 +37,79 @@ cpus {
 
 		ibm,powerpc-cpu-features {
 			display-name = "Microwatt";
-			isa = <3000>;
+			isa = <3010>;
 			device_type = "cpu-features";
 			compatible = "ibm,powerpc-cpu-features";
 
 			mmu-radix {
 				isa = <3000>;
-				usable-privilege = <2>;
+				usable-privilege = <6>;
+				os-support = <0>;
 			};
 
 			little-endian {
-				isa = <2050>;
-				usable-privilege = <3>;
+				isa = <0>;
+				usable-privilege = <7>;
+				os-support = <0>;
 				hwcap-bit-nr = <1>;
 			};
 
 			cache-inhibited-large-page {
-				isa = <2040>;
-				usable-privilege = <2>;
+				isa = <0>;
+				usable-privilege = <6>;
+				os-support = <0>;
 			};
 
 			fixed-point-v3 {
 				isa = <3000>;
-				usable-privilege = <3>;
+				usable-privilege = <7>;
 			};
 
 			no-execute {
-				isa = <2010>;
+				isa = <0x00>;
 				usable-privilege = <2>;
+				os-support = <0>;
 			};
 
 			floating-point {
+				hfscr-bit-nr = <0>;
 				hwcap-bit-nr = <27>;
 				isa = <0>;
-				usable-privilege = <3>;
+				usable-privilege = <7>;
+				hv-support = <1>;
+				os-support = <0>;
+			};
+
+			prefixed-instructions {
+				hfscr-bit-nr = <13>;
+				fscr-bit-nr = <13>;
+				isa = <3010>;
+				usable-privilege = <7>;
+				os-support = <1>;
+				hv-support = <1>;
+			};
+
+			tar {
+				hfscr-bit-nr = <8>;
+				fscr-bit-nr = <8>;
+				isa = <2070>;
+				usable-privilege = <7>;
+				os-support = <1>;
+				hv-support = <1>;
+				hwcap-bit-nr = <58>;
+			};
+
+			control-register {
+				isa = <0>;
+				usable-privilege = <7>;
+			};
+
+			system-call-vectored {
+				isa = <3000>;
+				usable-privilege = <7>;
+				os-support = <1>;
+				fscr-bit-nr = <12>;
+				hwcap-bit-nr = <52>;
 			};
 		};
 
@@ -138,7 +179,18 @@ UART0: serial@2000 {
 			interrupts = <0x10 0x1>;
 		};
 
-		ethernet@8020000 {
+		gpio: gpio@7000 {
+			device_type = "gpio";
+			compatible = "faraday,ftgpio010";
+			gpio-controller;
+			#gpio-cells = <2>;
+			reg = <0x7000 0x80>;
+			interrupts = <0x14 1>;
+			interrupt-controller;
+			#interrupt-cells = <2>;
+		};
+
+		enet0: ethernet@8020000 {
 			compatible = "litex,liteeth";
 			reg = <0x8021000 0x100
 				0x8020800 0x100
@@ -160,7 +212,6 @@ mmc@8040000 {
 			reg-names = "phy", "core", "reader", "writer", "irq";
 			bus-width = <4>;
 			interrupts = <0x13 1>;
-			cap-sd-highspeed;
 			clocks = <&sys_clk>;
 		};
 	};
Signature · 1 line
2.47.1
#3 lore raw

PATCH v2 3/5 powerpc/microwatt: Define an idle power-save function

In reply to Paul Mackerras

This uses the 'wait' instruction to pause instruction execution when idle until an interrupt occurs.

---
v2: Use prep_irq_for_idle_irqsoff()

 arch/powerpc/platforms/microwatt/setup.c | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/powerpc/platforms/microwatt/setup.c +9 -0
index 5e1c0997170d..a942c446aeab 100644
@@ -34,10 +34,19 @@ static void __init microwatt_setup_arch(void)
 	microwatt_rng_init();
 }
 
+static void microwatt_idle(void)
+{
+	if (!prep_irq_for_idle_irqsoff())
+		return;
+
+	__asm__ __volatile__ ("wait");
+}
+
 define_machine(microwatt) {
 	.name			= "microwatt",
 	.compatible		= "microwatt-soc",
 	.init_IRQ		= microwatt_init_IRQ,
 	.setup_arch		= microwatt_setup_arch,
 	.progress		= udbg_progress,
+	.power_save		= microwatt_idle,
 };
Signature · 1 line
2.47.1
#4 lore raw

PATCH v2 4/5 powerpc: Define config option for processors with broadcast TLBIE

In reply to Paul Mackerras

Power ISA v3.0 (and later) implementations in the Linux Compliancy Subset and lower are not required to implement broadcast TLBIE, and in fact Microwatt doesn't.

To avoid the need to specify "disable_tlbie" on the kernel command line on SMP Microwatt systems, this defines a config option that asserts that the platform implements broadcast TLBIE. This option is selected by the pseries and powernv platforms, but not by microwatt. Note that this option is only relevant when the radix MMU is being used, so platforms without a radix MMU don't need it.

---
v2: Made the option positive (has broadcast) rather than negative

 arch/powerpc/mm/book3s64/pgtable.c     |  4 ++--
 arch/powerpc/platforms/Kconfig.cputype | 13 +++++++++++++
 arch/powerpc/platforms/powernv/Kconfig |  1 +
 arch/powerpc/platforms/pseries/Kconfig |  1 +
 4 files changed, 17 insertions(+), 2 deletions(-)
arch/powerpc/mm/book3s64/pgtable.c +2 -2
index 374542528080..da0bba29a9d7 100644
@@ -591,7 +591,7 @@ int pmd_move_must_withdraw(struct spinlock *new_pmd_ptl,
 /*
  * Does the CPU support tlbie?
  */
-bool tlbie_capable __read_mostly = true;
+bool tlbie_capable __read_mostly = IS_ENABLED(CONFIG_PPC_RADIX_BROADCAST_TLBIE);
 EXPORT_SYMBOL(tlbie_capable);
 
 /*
@@ -599,7 +599,7 @@ EXPORT_SYMBOL(tlbie_capable);
  * address spaces? tlbie may still be used for nMMU accelerators, and for KVM
  * guest address spaces.
  */
-bool tlbie_enabled __read_mostly = true;
+bool tlbie_enabled __read_mostly = IS_ENABLED(CONFIG_PPC_RADIX_BROADCAST_TLBIE);
 
 static int __init setup_disable_tlbie(char *str)
 {
arch/powerpc/platforms/Kconfig.cputype +13 -0
index 1453ccc900c4..613b383ed8b3 100644
@@ -449,6 +449,19 @@ config PPC_RADIX_MMU_DEFAULT
 
 	  If you're unsure, say Y.
 
+config PPC_RADIX_BROADCAST_TLBIE
+	bool
+	depends on PPC_RADIX_MMU
+	help
+	  Power ISA v3.0 and later implementations in the Linux Compliancy Subset
+	  and lower are not required to implement broadcast TLBIE instructions.
+	  Platforms with CPUs that do implement TLBIE broadcast, that is, where
+	  a TLB invalidation instruction performed on one CPU operates on the
+	  TLBs of all CPUs in the system, should select this option.  If this
+	  option is selected, the disable_tlbie kernel command line option can
+	  be used to cause global TLB invalidations to be done via IPIs; without
+	  it, IPIs will be used unconditionally.
+
 config PPC_KERNEL_PREFIXED
 	depends on PPC_HAVE_PREFIXED_SUPPORT
 	depends on CC_HAS_PREFIXED
arch/powerpc/platforms/powernv/Kconfig +1 -0
index 70a46acc70d6..3fbe0295ce14 100644
@@ -17,6 +17,7 @@ config PPC_POWERNV
 	select MMU_NOTIFIER
 	select FORCE_SMP
 	select ARCH_SUPPORTS_PER_VMA_LOCK
+	select PPC_RADIX_BROADCAST_TLBIE
 	default y
 
 config OPAL_PRD
arch/powerpc/platforms/pseries/Kconfig +1 -0
index 42fc66e97539..206dfa0a3b33 100644
@@ -23,6 +23,7 @@ config PPC_PSERIES
 	select FORCE_SMP
 	select SWIOTLB
 	select ARCH_SUPPORTS_PER_VMA_LOCK
+	select PPC_RADIX_BROADCAST_TLBIE
 	default y
 
 config PARAVIRT
Signature · 1 line
2.47.1
#5 lore raw

PATCH v2 5/5 powerpc/microwatt: Add SMP support

In reply to Paul Mackerras

This adds support for Microwatt systems with more than one core, and updates the device tree for a 2-core version.

The secondary CPUs are started and sent to spin in __secondary_hold very early on, in the platform probe function. The reason for doing this is so that they are there when smp_release_cpus() gets called, which is before the platform init_smp function or even the platform setup_arch function gets called.

Note that having two CPUs in the device tree doesn't preclude operation with only one CPU. The SYSCON_CPU_CTRL register has a read-only field which indicates the number of CPU cores, so microwatt_init_smp() will only start as many CPU cores as are present in the system, and any extra CPU device-tree nodes will just be ignored.

---
v2: Addressed review comments
- use IS_ENABLED()
- define and use SYSCON_LENGTH
- use PPC_RAW_MFSPR and PPC_RAW_BRANCH

 arch/powerpc/boot/dts/microwatt.dts          | 34 ++++++++-
 arch/powerpc/platforms/microwatt/Kconfig     |  2 +-
 arch/powerpc/platforms/microwatt/Makefile    |  1 +
 arch/powerpc/platforms/microwatt/microwatt.h |  1 +
 arch/powerpc/platforms/microwatt/setup.c     |  9 +++
 arch/powerpc/platforms/microwatt/smp.c       | 80 ++++++++++++++++++++
 6 files changed, 124 insertions(+), 3 deletions(-)
 create mode 100644 arch/powerpc/platforms/microwatt/smp.c
arch/powerpc/boot/dts/microwatt.dts +32 -2
index 833d22822189..c4e4d2a9b460 100644
@@ -142,6 +142,36 @@ PowerPC,Microwatt@0 {
 			ibm,mmu-lpid-bits = <12>;
 			ibm,mmu-pid-bits = <20>;
 		};
+
+		PowerPC,Microwatt@1 {
+			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 = <1>;
+			i-cache-block-size = <64>;
+			d-cache-block-size = <64>;
+			d-cache-sets = <2>;
+			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 = <1>;
+			general-purpose;
+			64-bit;
+			d-cache-size = <0x1000>;
+			ibm,chip-id = <0>;
+			ibm,mmu-lpid-bits = <12>;
+			ibm,mmu-pid-bits = <20>;
+		};
 	};
 
 	soc@c0000000 {
@@ -154,8 +184,8 @@ soc@c0000000 {
 
 		interrupt-controller@4000 {
 			compatible = "openpower,xics-presentation", "ibm,ppc-xicp";
-			ibm,interrupt-server-ranges = <0x0 0x1>;
-			reg = <0x4000 0x100>;
+			ibm,interrupt-server-ranges = <0x0 0x2>;
+			reg = <0x4000 0x10 0x4010 0x10>;
 		};
 
 		ICS: interrupt-controller@5000 {
arch/powerpc/platforms/microwatt/Kconfig +1 -1
index 5e41adadac1f..cb2aff635bb0 100644
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 config PPC_MICROWATT
-	depends on PPC_BOOK3S_64 && !SMP
+	depends on PPC_BOOK3S_64
 	bool "Microwatt SoC platform"
 	select PPC_XICS
 	select PPC_ICS_NATIVE
arch/powerpc/platforms/microwatt/Makefile +1 -0
index 116d6d3ad3f0..d973b2ab4042 100644
@@ -1 +1,2 @@
 obj-y	+= setup.o rng.o
+obj-$(CONFIG_SMP) += smp.o
arch/powerpc/platforms/microwatt/microwatt.h +1 -0
index 335417e95e66..891aa2800768 100644
@@ -3,5 +3,6 @@
 #define _MICROWATT_H
 
 void microwatt_rng_init(void);
+void microwatt_init_smp(void);
 
 #endif /* _MICROWATT_H */
arch/powerpc/platforms/microwatt/setup.c +9 -0
index a942c446aeab..6af2ccef736c 100644
@@ -29,6 +29,14 @@ static int __init microwatt_populate(void)
 }
 machine_arch_initcall(microwatt, microwatt_populate);
 
+static int __init microwatt_probe(void)
+{
+	/* Main reason for having this is to start the other CPU(s) */
+	if (IS_ENABLED(CONFIG_SMP))
+		microwatt_init_smp();
+	return 1;
+}
+
 static void __init microwatt_setup_arch(void)
 {
 	microwatt_rng_init();
@@ -45,6 +53,7 @@ static void microwatt_idle(void)
 define_machine(microwatt) {
 	.name			= "microwatt",
 	.compatible		= "microwatt-soc",
+	.probe			= microwatt_probe,
 	.init_IRQ		= microwatt_init_IRQ,
 	.setup_arch		= microwatt_setup_arch,
 	.progress		= udbg_progress,
arch/powerpc/platforms/microwatt/smp.c new file +80 -0

80 lines not on this page · raw message

Signature · 1 line
2.47.1
maintainer Applied
#6 lore raw
In reply to Paul Mackerras
Quoted 11 lines · Paul Mackerras

This patch series updates the kernel support for the Microwatt soft-core and its implementation on FPGA systems, particularly the Digilent Arty A7-100 FPGA development board.

Microwatt now supports almost all of the features of the SFFS (Scalar Fixed-point and Floating-point Subset) compliancy subset of Power ISA version 3.1C, including prefixed instructions and the fixed-point hash (ROP mitigation) instructions. It is also now SMP-capable, and a dual-core system will fit on the Arty A7-100 board.

[...]

Applied to powerpc/next.

[1/5] powerpc/microwatt: Select COMMON_CLK in order to get the clock framework

      https://git.kernel.org/powerpc/c/81bb6490b78aab8cbfc2d0670f177233d2fa15f5
[2/5] powerpc/microwatt: Device-tree updates
      https://git.kernel.org/powerpc/c/78099fe1e3b5b72d4627f360b59a3470b1547bad
[3/5] powerpc/microwatt: Define an idle power-save function
      https://git.kernel.org/powerpc/c/2b0a438d5380c32817e1b2c883bd0494461e9f4f
[4/5] powerpc: Define config option for processors with broadcast TLBIE
      https://git.kernel.org/powerpc/c/3d45a3d0d2e6b5cf47c6f0ab890f6ce762d9fd23
[5/5] powerpc/microwatt: Add SMP support
      https://git.kernel.org/powerpc/c/aca95fb6bb572a77f39d42d83ab72a965026577d

Thanks