From: Paul Mackerras <hidden> Date: 2021-06-18 03:55:40
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 or nested
radix translation).
Changes in v2:
- Dropped the patch that adds support for the PRTBL register, since it
is not architected. Instead, I have added support for a 1-entry
partition table to Microwatt and implemented the PTCR register.
- Updated the device tree.
- Dropped the change to archrandom.h.
- Combined patches 10 and 11 of the previous series into one.
Paul.
arch/powerpc/Kconfig | 2 +-
arch/powerpc/boot/Makefile | 4 +
arch/powerpc/boot/devtree.c | 59 ++++---
arch/powerpc/boot/dts/microwatt.dts | 138 ++++++++++++++++
arch/powerpc/boot/microwatt.c | 24 +++
arch/powerpc/boot/ns16550.c | 9 +-
arch/powerpc/boot/wrapper | 5 +
arch/powerpc/configs/microwatt_defconfig | 98 ++++++++++++
arch/powerpc/kernel/udbg_16550.c | 39 +++++
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 +
19 files changed, 718 insertions(+), 28 deletions(-)
@@ -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
From: Paul Mackerras <hidden> Date: 2021-06-18 03:52:42
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
This adds support to the Microwatt platform to use the standard
16550-style UART which available in the standalone Microwatt FPGA.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Paul Mackerras <redacted>
---
arch/powerpc/boot/dts/microwatt.dts | 27 ++++++++++++----
arch/powerpc/kernel/udbg_16550.c | 39 ++++++++++++++++++++++++
arch/powerpc/platforms/microwatt/Kconfig | 1 +
arch/powerpc/platforms/microwatt/setup.c | 2 ++
4 files changed, 63 insertions(+), 6 deletions(-)
From: Paul Mackerras <hidden> Date: 2021-06-18 03:53:07
Microwatt currently runs with MSR[HV] = 0, hence the usable-privilege
properties don't have bit 2 (for HV support) set, and we need the
/chosen/ibm,architecture-vec-5 property.
Signed-off-by: Paul Mackerras <redacted>
---
arch/powerpc/boot/dts/microwatt.dts | 98 +++++++++++++++++++++++++++++
1 file changed, 98 insertions(+)
create mode 100644 arch/powerpc/boot/dts/microwatt.dts
From: Paul Mackerras <hidden> Date: 2021-06-18 03:53:31
From: Joel Stanley <joel@jms.id.au>
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
Signed-off-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Paul Mackerras <redacted>
---
arch/powerpc/boot/Makefile | 4 ++++
arch/powerpc/boot/microwatt.c | 24 ++++++++++++++++++++++++
arch/powerpc/boot/wrapper | 5 +++++
3 files changed, 33 insertions(+)
create mode 100644 arch/powerpc/boot/microwatt.c
@@ -355,6 +357,8 @@ image-$(CONFIG_MVME5100) += dtbImage.mvme5100# Board port in arch/powerpc/platform/amigaone/Kconfigimage-$(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
@@ -240,7 +249,6 @@ static int dt_xlate(void *node, int res, int reglen, unsigned long *addr,return0;dt_get_reg_format(parent,&naddr,&nsize);-if(nsize>2)return0;
@@ -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)return0;
@@ -296,8 +303,7 @@ static int dt_xlate(void *node, int res, int reglen, unsigned long *addr,if(naddr>2)return0;-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)intdt_get_virtual_reg(void*node,void**addr,intnres){unsignedlongxaddr;-intn;+intn,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]);returnn/4;+}for(n=0;n<nres;n++){if(!dt_xlate_reg(node,n,&xaddr,NULL))
From: Paul Mackerras <hidden> Date: 2021-06-18 03:54:23
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. It has an
optional FPU, and an optional MMU (required for running Linux,
obviously) which implements a configurable radix tree but not
hypervisor mode or nested radix translation.
This adds a new machine type to support FPGA-based SoCs with a
Microwatt core. CONFIG_MATH_EMULATION can be selected for Microwatt
SOCs which don't have the FPU.
Signed-off-by: Paul Mackerras <redacted>
---
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
From: Paul Mackerras <hidden> Date: 2021-06-18 03:54:46
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Just like any other embedded platform.
Add an empty soc node.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Paul Mackerras <redacted>
---
arch/powerpc/boot/dts/microwatt.dts | 7 +++++++
arch/powerpc/platforms/microwatt/setup.c | 8 ++++++++
2 files changed, 15 insertions(+)
@@ -0,0 +1,257 @@+// SPDX-License-Identifier: GPL-2.0-or-later+/*+*ICSbackendforOPALmanagedinterrupts.+*+*Copyright2011IBMCorp.+*/++//#define DEBUG++#include<linux/types.h>+#include<linux/kernel.h>+#include<linux/irq.h>+#include<linux/smp.h>+#include<linux/interrupt.h>+#include<linux/init.h>+#include<linux/cpu.h>+#include<linux/of.h>+#include<linux/spinlock.h>+#include<linux/msi.h>+#include<linux/list.h>++#include<asm/prom.h>+#include<asm/smp.h>+#include<asm/machdep.h>+#include<asm/irq.h>+#include<asm/errno.h>+#include<asm/xics.h>+#include<asm/opal.h>+#include<asm/firmware.h>++structics_native{+structicsics;+structdevice_node*node;+void__iomem*base;+u32ibase;+u32icount;+};+#define to_ics_native(_ics) container_of(_ics, struct ics_native, ics)++staticvoid__iomem*ics_native_xive(structics_native*in,unsignedintvec)+{+returnin->base+0x800+((vec-in->ibase)<<2);+}++staticvoidics_native_unmask_irq(structirq_data*d)+{+unsignedintvec=(unsignedint)irqd_to_hwirq(d);+structics*ics=irq_data_get_irq_chip_data(d);+structics_native*in=to_ics_native(ics);+unsignedintserver;++pr_devel("ics-native: unmask virq %d [hw 0x%x]\n",d->irq,vec);++if(vec<in->ibase||vec>=(in->ibase+in->icount))+return;++server=xics_get_irq_server(d->irq,irq_data_get_affinity_mask(d),0);+out_be32(ics_native_xive(in,vec),(server<<8)|DEFAULT_PRIORITY);+}++staticunsignedintics_native_startup(structirq_data*d)+{+#ifdef CONFIG_PCI_MSI+/*+*ThegenericMSIcodereturnswiththeinterruptdisabledonthe+*card,usingtheMSImaskbits.Firmwaredoesn'tappeartounmask+*atthatlevel,sowedoitherebyhand.+*/+if(irq_data_get_msi_desc(d))+pci_msi_unmask_irq(d);+#endif++/* unmask it */+ics_native_unmask_irq(d);+return0;+}++staticvoidics_native_do_mask(structics_native*in,unsignedintvec)+{+out_be32(ics_native_xive(in,vec),0xff);+}++staticvoidics_native_mask_irq(structirq_data*d)+{+unsignedintvec=(unsignedint)irqd_to_hwirq(d);+structics*ics=irq_data_get_irq_chip_data(d);+structics_native*in=to_ics_native(ics);++pr_devel("ics-native: mask virq %d [hw 0x%x]\n",d->irq,vec);++if(vec<in->ibase||vec>=(in->ibase+in->icount))+return;+ics_native_do_mask(in,vec);+}++staticintics_native_set_affinity(structirq_data*d,+conststructcpumask*cpumask,+boolforce)+{+unsignedintvec=(unsignedint)irqd_to_hwirq(d);+structics*ics=irq_data_get_irq_chip_data(d);+structics_native*in=to_ics_native(ics);+intserver;+u32xive;++if(vec<in->ibase||vec>=(in->ibase+in->icount))+return-EINVAL;++server=xics_get_irq_server(d->irq,cpumask,1);+if(server==-1){+pr_warn("%s: No online cpus in the mask %*pb for irq %d\n",+__func__,cpumask_pr_args(cpumask),d->irq);+return-1;+}++xive=in_be32(ics_native_xive(in,vec));+xive=(xive&0xff)|(server<<8);+out_be32(ics_native_xive(in,vec),xive);++returnIRQ_SET_MASK_OK;+}++staticstructirq_chipics_native_irq_chip={+.name="ICS",+.irq_startup=ics_native_startup,+.irq_mask=ics_native_mask_irq,+.irq_unmask=ics_native_unmask_irq,+.irq_eoi=NULL,/* Patched at init time */+.irq_set_affinity=ics_native_set_affinity,+.irq_set_type=xics_set_irq_type,+.irq_retrigger=xics_retrigger,+};++staticintics_native_map(structics*ics,unsignedintvirq)+{+unsignedintvec=(unsignedint)virq_to_hw(virq);+structics_native*in=to_ics_native(ics);++pr_devel("%s: vec=0x%x\n",__func__,vec);++if(vec<in->ibase||vec>=(in->ibase+in->icount))+return-EINVAL;++irq_set_chip_and_handler(virq,&ics_native_irq_chip,handle_fasteoi_irq);+irq_set_chip_data(virq,ics);++return0;+}++staticvoidics_native_mask_unknown(structics*ics,unsignedlongvec)+{+structics_native*in=to_ics_native(ics);++if(vec<in->ibase||vec>=(in->ibase+in->icount))+return;++ics_native_do_mask(in,vec);+}++staticlongics_native_get_server(structics*ics,unsignedlongvec)+{+structics_native*in=to_ics_native(ics);+u32xive;++if(vec<in->ibase||vec>=(in->ibase+in->icount))+return-EINVAL;++xive=in_be32(ics_native_xive(in,vec));+return(xive>>8)&0xfff;+}++staticintics_native_host_match(structics*ics,structdevice_node*node)+{+structics_native*in=to_ics_native(ics);++returnin->node==node;+}++staticstructicsics_native_template={+.map=ics_native_map,+.mask_unknown=ics_native_mask_unknown,+.get_server=ics_native_get_server,+.host_match=ics_native_host_match,+};++staticint__initics_native_add_one(structdevice_node*np)+{+structics_native*ics;+u32ranges[2];+intrc,count;++ics=kzalloc(sizeof(structics_native),GFP_KERNEL);+if(!ics)+return-ENOMEM;+ics->node=of_node_get(np);+memcpy(&ics->ics,&ics_native_template,sizeof(structics));++ics->base=of_iomap(np,0);+if(!ics->base){+pr_err("Failed to map %pOFP\n",np);+rc=-ENOMEM;+gotofail;+}++count=of_property_count_u32_elems(np,"interrupt-ranges");+if(count<2||count&1){+pr_err("Failed to read interrupt-ranges of %pOFP\n",np);+rc=-EINVAL;+gotofail;+}+if(count>2){+pr_warn("ICS %pOFP has %d ranges, only one supported\n",+np,count>>1);+}+rc=of_property_read_u32_array(np,"interrupt-ranges",+ranges,2);+if(rc){+pr_err("Failed to read interrupt-ranges of %pOFP\n",np);+gotofail;+}+ics->ibase=ranges[0];+ics->icount=ranges[1];++pr_info("ICS native initialized for sources %d..%d\n",+ics->ibase,ics->ibase+ics->icount-1);++/* Register ourselves */+xics_register_ics(&ics->ics);++return0;+fail:+of_node_put(ics->node);+kfree(ics);+returnrc;+}++int__initics_native_init(void)+{+structdevice_node*ics;+boolfound_one=false;++/* We need to patch our irq chip's EOI to point to the+*rightICP+*/+ics_native_irq_chip.irq_eoi=icp_ops->eoi;++/* Find native ICS in the device-tree */+for_each_compatible_node(ics,NULL,"openpower,xics-sources"){+if(ics_native_add_one(ics)==0)+found_one=true;+}++if(found_one)+pr_info("ICS native backend registered\n");++returnfound_one?0:-ENODEV;+}
@@ -0,0 +1,48 @@+// SPDX-License-Identifier: GPL-2.0-or-later+/*+*Derivedfromarch/powerpc/platforms/powernv/rng.c,whichis:+*Copyright2013,MichaelEllerman,IBMCorporation.+*/++#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++intmicrowatt_get_random_darn(unsignedlong*v)+{+unsignedlongval;++/* Using DARN with L=1 - 64-bit conditioned random number */+asmvolatile(PPC_DARN(%0,1):"=r"(val));++if(val==DARN_ERR)+return0;++*v=val;++return1;+}++static__initintrng_init(void)+{+unsignedlongval;+inti;++for(i=0;i<10;i++){+if(microwatt_get_random_darn(&val)){+ppc_md.get_random_seed=microwatt_get_random_darn;+return0;+}+}++pr_warn("Unable to use DARN for get_random_seed()\n");++return-EIO;+}+machine_subsys_initcall(,rng_init);
From: Nicholas Piggin <npiggin@gmail.com> Date: 2021-06-18 07:41:36
Excerpts from Paul Mackerras's message of June 18, 2021 1:46 pm:
quoted hunk
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
This adds support to the Microwatt platform to use the standard
16550-style UART which available in the standalone Microwatt FPGA.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Paul Mackerras <redacted>
---
arch/powerpc/boot/dts/microwatt.dts | 27 ++++++++++++----
arch/powerpc/kernel/udbg_16550.c | 39 ++++++++++++++++++++++++
arch/powerpc/platforms/microwatt/Kconfig | 1 +
arch/powerpc/platforms/microwatt/setup.c | 2 ++
4 files changed, 63 insertions(+), 6 deletions(-)
Why is realmode required? No cache inhibited mappings yet?
mtmsrd with L=0 is defined to be context synchronizing in isa 3, so I
don't think the isync would be required. There is a bit of code around
arch/powerpc that does this, maybe it used to be needed or some other
implementations needed it?
That's just for my curiosity, it doesn't really hurt to have them
there.
Thanks,
Nick
From: Paul Mackerras <hidden> Date: 2021-06-18 12:13:26
On Fri, Jun 18, 2021 at 05:40:40PM +1000, Nicholas Piggin wrote:
Excerpts from Paul Mackerras's message of June 18, 2021 1:46 pm:
quoted
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
This adds support to the Microwatt platform to use the standard
16550-style UART which available in the standalone Microwatt FPGA.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Paul Mackerras <redacted>
Why is realmode required? No cache inhibited mappings yet?
Because it's EARLY debug, for use in the very early stages of boot
when the kernel's radix tree may or may not have been initialized.
The easiest way to make a function that works correctly whether or not
the radix tree has been initialized and the MMU turned on is to
temporarily turn off the MMU for data accesses and use lbzcix/stbcix
(which Microwatt has, even though it doesn't implement hypervisor
mode).
(I don't know which "yet" you meant - "yet" in the process of booting a
kernel, or "yet" in the process of Microwatt's development? Microwatt
certainly does have cache-inhibited mappings and has done since the
MMU was first introduced.)
In fact the defconfig I add later in the series doesn't enable
CONFIG_PPC_EARLY_DEBUG_MICROWATT, but it's there if it's needed for
debugging.
mtmsrd with L=0 is defined to be context synchronizing in isa 3, so I
don't think the isync would be required. There is a bit of code around
arch/powerpc that does this, maybe it used to be needed or some other
implementations needed it?
That's just for my curiosity, it doesn't really hurt to have them
there.
Right, and in fact mtmsrd is marked as a single-issue instruction in
Microwatt, so it should work with no isyncs or eieios. Presumably Ben
copied the isync/eieio pattern from somewhere else.
Paul.
From: Nicholas Piggin <npiggin@gmail.com> Date: 2021-06-19 02:59:32
Excerpts from Paul Mackerras's message of June 18, 2021 10:12 pm:
On Fri, Jun 18, 2021 at 05:40:40PM +1000, Nicholas Piggin wrote:
quoted
Excerpts from Paul Mackerras's message of June 18, 2021 1:46 pm:
quoted
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
This adds support to the Microwatt platform to use the standard
16550-style UART which available in the standalone Microwatt FPGA.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Paul Mackerras <redacted>
Why is realmode required? No cache inhibited mappings yet?
Because it's EARLY debug, for use in the very early stages of boot
when the kernel's radix tree may or may not have been initialized.
The easiest way to make a function that works correctly whether or not
the radix tree has been initialized and the MMU turned on is to
temporarily turn off the MMU for data accesses and use lbzcix/stbcix
Ah makes sense.
(which Microwatt has, even though it doesn't implement hypervisor
mode).
(I don't know which "yet" you meant - "yet" in the process of booting a
kernel, or "yet" in the process of Microwatt's development? Microwatt
certainly does have cache-inhibited mappings and has done since the
MMU was first introduced.)
I did mean mappings to the UART, but good to get both answers :D
In fact the defconfig I add later in the series doesn't enable
CONFIG_PPC_EARLY_DEBUG_MICROWATT, but it's there if it's needed for
debugging.
quoted
mtmsrd with L=0 is defined to be context synchronizing in isa 3, so I
don't think the isync would be required. There is a bit of code around
arch/powerpc that does this, maybe it used to be needed or some other
implementations needed it?
That's just for my curiosity, it doesn't really hurt to have them
there.
Right, and in fact mtmsrd is marked as a single-issue instruction in
Microwatt, so it should work with no isyncs or eieios. Presumably Ben
copied the isync/eieio pattern from somewhere else.
Makes sense. Well I don't have any objection to the series.
Thanks,
Nick
From: Nicholas Piggin <npiggin@gmail.com> Date: 2021-06-19 03:04:14
Excerpts from Paul Mackerras's message of June 18, 2021 1:43 pm:
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. It has an
optional FPU, and an optional MMU (required for running Linux,
obviously) which implements a configurable radix tree but not
hypervisor mode or nested radix translation.
This adds a new machine type to support FPGA-based SoCs with a
Microwatt core. CONFIG_MATH_EMULATION can be selected for Microwatt
SOCs which don't have the FPU.
The only thing I can think of is you may want to select PPC_RADIX and
other possible things that are required, but that's not a big deal at
the moment. I have a few kernel size reduction config patches (like
CONFIG_PPC_HASH) I might be able to upstream now for Microwatt, so I
could do a bit of a pass over the Kconfig stuff at that point.
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
From: Nicholas Piggin <npiggin@gmail.com> Date: 2021-06-19 03:09:40
Excerpts from Paul Mackerras's message of June 18, 2021 1:47 pm:
Microwatt's hardware RNG is accessed using the DARN instruction.
I think we're getting a platforms/book3s soon with the VAS patches,
might be a place to add the get_random_darn function.
Huh, DARN is unprivileged right? And yet we haven't wired it up in
pseries it still uses an hcall.
Anyway that's all stuff to sort out later.
Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
@@ -0,0 +1,48 @@+// SPDX-License-Identifier: GPL-2.0-or-later+/*+*Derivedfromarch/powerpc/platforms/powernv/rng.c,whichis:+*Copyright2013,MichaelEllerman,IBMCorporation.+*/++#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++intmicrowatt_get_random_darn(unsignedlong*v)+{+unsignedlongval;++/* Using DARN with L=1 - 64-bit conditioned random number */+asmvolatile(PPC_DARN(%0,1):"=r"(val));++if(val==DARN_ERR)+return0;++*v=val;++return1;+}++static__initintrng_init(void)+{+unsignedlongval;+inti;++for(i=0;i<10;i++){+if(microwatt_get_random_darn(&val)){+ppc_md.get_random_seed=microwatt_get_random_darn;+return0;+}+}++pr_warn("Unable to use DARN for get_random_seed()\n");++return-EIO;+}+machine_subsys_initcall(,rng_init);
From: Nicholas Piggin <npiggin@gmail.com> Date: 2021-06-19 03:16:47
Excerpts from Paul Mackerras's message of June 18, 2021 1:49 pm:
From: Joel Stanley <joel@jms.id.au>
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
Signed-off-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Paul Mackerras <redacted>
Thanks for folding and commenting that change. Ack for this and the rest
of the platform and dt and interrupt handling patches FWIW, but I don't
know much about any of these areas to give an informed review.
Thanks,
Nick
@@ -355,6 +357,8 @@ image-$(CONFIG_MVME5100) += dtbImage.mvme5100# Board port in arch/powerpc/platform/amigaone/Kconfigimage-$(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
On Sat, Jun 19, 2021 at 01:08:51PM +1000, Nicholas Piggin wrote:
Excerpts from Paul Mackerras's message of June 18, 2021 1:47 pm:
quoted
Microwatt's hardware RNG is accessed using the DARN instruction.
I think we're getting a platforms/book3s soon with the VAS patches,
might be a place to add the get_random_darn function.
Huh, DARN is unprivileged right?
It is, that's the whole point: to make it very very cheap for user
software it has to be an unprivileged instruction.
Segher
On Fri, Jun 18, 2021 at 01:42:53PM +1000, Paul Mackerras wrote:
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 or nested
radix translation).
For the whole series:
Reviewed-by: Segher Boessenkool <redacted>
I didn't see anything in this revision that would prevent it from
being included upstream (that HV=1 thing should be fixed sooner rather
than later, but that is not a kernel problem). Looks in great state :-)
Segher
From: Nicholas Piggin <npiggin@gmail.com> Date: 2021-06-20 08:20:29
Excerpts from Segher Boessenkool's message of June 20, 2021 12:36 am:
On Sat, Jun 19, 2021 at 01:08:51PM +1000, Nicholas Piggin wrote:
quoted
Excerpts from Paul Mackerras's message of June 18, 2021 1:47 pm:
quoted
Microwatt's hardware RNG is accessed using the DARN instruction.
I think we're getting a platforms/book3s soon with the VAS patches,
might be a place to add the get_random_darn function.
Huh, DARN is unprivileged right?
It is, that's the whole point: to make it very very cheap for user
software it has to be an unprivileged instruction.
Right, I was just doing a double-take. In that case we should enable it
in the pseries random number code as well, so it really would be a
generic isa 3.0 function that all (microwatt, powernv, pseries) could
use AFAIKS.
Thanks,
Nick
From: Paul Mackerras <hidden> Date: 2021-06-20 21:55:00
On Sat, Jun 19, 2021 at 09:26:16AM -0500, Segher Boessenkool wrote:
On Fri, Jun 18, 2021 at 01:44:16PM +1000, Paul Mackerras wrote:
quoted
Microwatt currently runs with MSR[HV] = 0,
That isn't compliant though? If your implementation does not have LPAR
it must set MSR[HV]=1 always.
True - but if I actually do that, Linux starts trying to use hrfid
(for example in masked_Hinterrupt), which Microwatt doesn't have.
Something for Nick to fix. :)
Paul.
On Sun, Jun 20, 2021 at 10:08:58PM +1000, Paul Mackerras wrote:
On Sat, Jun 19, 2021 at 09:26:16AM -0500, Segher Boessenkool wrote:
quoted
On Fri, Jun 18, 2021 at 01:44:16PM +1000, Paul Mackerras wrote:
quoted
Microwatt currently runs with MSR[HV] = 0,
That isn't compliant though? If your implementation does not have LPAR
it must set MSR[HV]=1 always.
True - but if I actually do that, Linux starts trying to use hrfid
(for example in masked_Hinterrupt), which Microwatt doesn't have.
Something for Nick to fix. :)
That looks like it needs fixing, yes (it is hard to actually read). But
one thing you can do to make this Just Work is to make hrfid do exactly
the same as rfid, i.e. decode hrfid (01000 10010) as rfid (00000 10010).
That probably makes things run already, you don't even need to alias
to SPRs HSRRn (01001 1101n) to SRRn (00000 1101n) :-)
Segher
From: Michael Ellerman <hidden> Date: 2021-06-24 14:05:59
On Fri, 18 Jun 2021 13:42:53 +1000, Paul Mackerras wrote:
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 or nested
radix translation).
[...]
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
This adds support to the Microwatt platform to use the standard
16550-style UART which available in the standalone Microwatt FPGA.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Paul Mackerras <redacted>
---
arch/powerpc/boot/dts/microwatt.dts | 27 ++++++++++++----
arch/powerpc/kernel/udbg_16550.c | 39 ++++++++++++++++++++++++
arch/powerpc/platforms/microwatt/Kconfig | 1 +
arch/powerpc/platforms/microwatt/setup.c | 2 ++
4 files changed, 63 insertions(+), 6 deletions(-)
How do you make sure that GCC won't emit any access to the stack between the two mtmsr() ?
What about using real_205_readb() and real_205_writeb() instead ?
How do you make sure that GCC won't emit any access to the stack between
the two mtmsr() ?
The mtmsr are asm with a memory clobber so nothing will be moved between
these, and it is very unlikely anything will sprout up here out of
nothing. But yes, this whole thing should be written as real asm (or as
one huge inline asm, but ugh).
Segher