Add initial SPAPR PPC64 architecture support
v4 cover Add initial SPAPR PPC64 architecture support
This series adds support for a PPC64 platform, SPAPR, on top of the previous more general PPC64 CPU support. This platform is paravirtualised, with most of the MMU hypercalls being dealt with in the kernel. Userland needs to describe the environment to the machine with a device tree, cope with some hypercalls (and RTAS calls) for hvconsole, PCI config and IRQs, and emulate the interrupt controller (XICS) and PCI Host Bridge of the SPAPR-esque machine.
With this series, normal pSeries kernels boot fine (including RH kernels that include virtio support out of the box). There is no support for PPC32 or 'bare metal' PPC64 guests as yet.
Processor state is set up as a guest kernel would expect (both primary and secondaries), and SMP is fully supported.
The kernels are loaded as flat binaries and booted directly. The intention is to later support loading firmware such as SLOF.
Some of the code within is borrowed/based upon code in QEMU, particularly the XICS emulation, device tree construction and PCI setup.
-- Changes since V3:
- Gained another patch to provide PPC KVM-PR support (widens userbase :p ) This allocates a page table, sets up a few more regs etc. Also, removes restriction that mandates use of hugepages.
Requires KVM-PR to implement H_BULK_REMOVE (separate patch)
- Cleaned up FDT generation to detect host CPU & generate based on its properties; now supports PPC970 as well as POWER7
- Removed redefinition of hypercall #defines, using <asm/hvcall.h> instead
- More sensible MMIO layering; CPU passes MMIO to PHB, PHB then decides which PCI window is accessed.
- Die if kernel-handled hypercalls ever get to userland
- Build in libfdt as sugggested -- it's small and present in our sourcetree, and removes external dependency on 64bit libfdt (which isn't in some distros).
- Spit & polish
Thanks to David & Alex for the PPC-related reviews!
Matt Evans (7):
kvm tools: PPC64, add HPT/SDR1 for -PR KVM kvm tools: Generate SPAPR PPC64 guest device tree kvm tools: Add SPAPR PPC64 hcall & rtascall structure kvm tools: Add SPAPR PPC64 HV console
kvm tools: Add PPC64 XICS interrupt controller support kvm tools: Add PPC64 PCI Host Bridge
kvm tools: Add PPC64 kvm_cpu__emulate_io()
tools/kvm/Makefile | 31 ++- tools/kvm/powerpc/cpu_info.c | 83 ++++ tools/kvm/powerpc/cpu_info.h | 43 +++ tools/kvm/powerpc/include/kvm/kvm-arch.h | 17 + tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h | 12 +- tools/kvm/powerpc/irq.c | 43 ++- tools/kvm/powerpc/kvm-cpu.c | 64 +++- tools/kvm/powerpc/kvm.c | 290 ++++++++++++++- tools/kvm/powerpc/spapr.h | 93 +++++ tools/kvm/powerpc/spapr_hcall.c | 134 +++++++ tools/kvm/powerpc/spapr_hvcons.c | 102 +++++ tools/kvm/powerpc/spapr_hvcons.h | 19 + tools/kvm/powerpc/spapr_pci.c | 423 +++++++++++++++++++++ tools/kvm/powerpc/spapr_pci.h | 57 +++ tools/kvm/powerpc/spapr_rtas.c | 229 ++++++++++++ tools/kvm/powerpc/xics.c | 514 ++++++++++++++++++++++++++ tools/kvm/powerpc/xics.h | 23 ++ 17 files changed, 2150 insertions(+), 27 deletions(-) create mode 100644 tools/kvm/powerpc/cpu_info.c create mode 100644 tools/kvm/powerpc/cpu_info.h create mode 100644 tools/kvm/powerpc/spapr.h create mode 100644 tools/kvm/powerpc/spapr_hcall.c create mode 100644 tools/kvm/powerpc/spapr_hvcons.c create mode 100644 tools/kvm/powerpc/spapr_hvcons.h create mode 100644 tools/kvm/powerpc/spapr_pci.c create mode 100644 tools/kvm/powerpc/spapr_pci.h create mode 100644 tools/kvm/powerpc/spapr_rtas.c create mode 100644 tools/kvm/powerpc/xics.c create mode 100644 tools/kvm/powerpc/xics.h
PATCH v4 1/7 kvm tools: PPC64, add HPT/SDR1 for -PR KVM
Allocate a page table and point SDR1 to it in order to support the -PR PPC64 KVM mode. (The alternative, -HV mode, is available only on a small set of machines.)
This patch also removes the previous dependency on mapping guest RAM with huge pages; PR KVM doesn't require them so the user isn't forced to use them.
A new option, '--hugetlbfs default', uses a default path for 16M pages for HV mode, if required.
--- tools/kvm/powerpc/include/kvm/kvm-arch.h | 2 ++ tools/kvm/powerpc/kvm-cpu.c | 24 +++++++++++++++++++++--- tools/kvm/powerpc/kvm.c | 25 ++++++++++++++++++------- 3 files changed, 41 insertions(+), 10 deletions(-)
tools/kvm/powerpc/include/kvm/kvm-arch.h +2 -0
@@ -52,6 +52,8 @@ struct kvm {u64 ram_size;void *ram_start; +u64 sdr1; +bool nmi_disabled;bool single_step;
tools/kvm/powerpc/kvm-cpu.c +21 -3
@@ -76,7 +76,8 @@ struct kvm_cpu *kvm_cpu__init(struct kvm *kvm, unsigned long cpu_id)if (vcpu->kvm_run ==MAP_FAILED )die ("unable to mmap vcpu fd" ); -ioctl (vcpu->vcpu_fd,KVM_ENABLE_CAP , &papr_cap); +if (ioctl (vcpu->vcpu_fd,KVM_ENABLE_CAP , &papr_cap) <0 ) +die ("unable to enable PAPR capability" );/* * We start all CPUs, directing non-primary threads into the kernel's
@@ -121,9 +122,26 @@ static void kvm_cpu__setup_regs(struct kvm_cpu *vcpu)static void kvm_cpu__setup_sregs (struct kvm_cpu *vcpu) {/* -* No sregs setup is required on PPC64/SPAPR (but there may be setup -* required for non-paravirtualised platforms, e.g. TLB/SLB setup). +* Some sregs setup to initialise SDR1/PVR/HIOR on PPC64 SPAPR +* platforms using PR KVM. (Technically, this is all ignored on +* SPAPR HV KVM.) Different setup is required for non-PV non-SPAPR +* platforms! (FIXME.) */ +struct kvm_sregs sregs; +struct kvm_one_reg reg = {}; + +if (ioctl (vcpu->vcpu_fd,KVM_GET_SREGS , &sregs) <0 ) +die ("KVM_GET_SREGS failed" ); + + sregs.u.s.sdr1 = vcpu->kvm->sdr1; + +if (ioctl (vcpu->vcpu_fd,KVM_SET_SREGS , &sregs) <0 ) +die ("KVM_SET_SREGS failed" ); + + reg.id =KVM_ONE_REG_PPC_HIOR ; + reg.u.reg64 =0 ; +if (ioctl (vcpu->vcpu_fd,KVM_SET_ONE_REG , ®) <0 ) +die ("KVM_SET_ONE_REG failed" ); }/**
tools/kvm/powerpc/kvm.c +18 -7
@@ -72,19 +72,24 @@ void kvm__arch_set_cmdline(char *cmdline, bool video)void kvm__arch_init (struct kvm *kvm,const char *hugetlbfs_path,u64 ram_size) {int cap_ppc_rma; +unsigned long hpt; kvm->ram_size = ram_size;/* -* Currently, we must map from hugetlbfs; if --hugetlbfs not specified, -* try a default path: +* Currently, HV-mode PPC64 SPAPR requires that we map from hugetlfs. +* Allow a 'default' option to assist. +* PR-mode does not require this. */ -if (!hugetlbfs_path) { - hugetlbfs_path =HUGETLBFS_PATH ; -pr_info ("Using default %s for memory" , hugetlbfs_path); +if (hugetlbfs_path) { +if (!strcmp (hugetlbfs_path,"default" )) + hugetlbfs_path =HUGETLBFS_PATH ; + kvm->ram_start =mmap_hugetlbfs (hugetlbfs_path, kvm->ram_size); + }else { + kvm->ram_start =mmap (0 , kvm->ram_size,PROT_READ |PROT_WRITE , +MAP_ANON |MAP_PRIVATE , +-1 ,0 ); } - - kvm->ram_start =mmap_hugetlbfs (hugetlbfs_path, kvm->ram_size);if (kvm->ram_start ==MAP_FAILED )die ("Couldn't map %lld bytes for RAM (%d)\n" , kvm->ram_size, errno);
@@ -95,6 +100,12 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size) kvm->rtas_gra = kvm->fdt_gra -RTAS_MAX_SIZE ;madvise (kvm->ram_start, kvm->ram_size,MADV_MERGEABLE ); +/* FIXME: SPAPR-PR specific; allocate a guest HPT. */ +if (posix_memalign ((void **)&hpt, (1 <<HPT_ORDER ), (1 <<HPT_ORDER ))) +die ("Can't allocate %d bytes for HPT\n" , (1 <<HPT_ORDER )); + + kvm->sdr1 = ((hpt +0x3ffffULL ) & ~0x3ffffULL ) | (HPT_ORDER -18 ); +/* FIXME: This is book3s-specific */ cap_ppc_rma =ioctl (kvm->sys_fd,KVM_CHECK_EXTENSION ,KVM_CAP_PPC_RMA );if (cap_ppc_rma ==2 )
Signature · 1 line
1.7.0.4
PATCH v4 2/7 kvm tools: Generate SPAPR PPC64 guest device tree
In reply to Matt EvansThe generated DT is the bare minimum structure required for SPAPR (on which subsequent patches for VIO, XICS, PCI etc. will build); root node, cpus, memory.
The DT contains CPU-specific configuration; a very simple 'cpu info' mechanism is added to recognise/differentiate DT entries for POWER7 and PPC970 host CPUs. Future support of more CPUs is possible.
libfdt is included from scripts/dtc/libfdt.
--- tools/kvm/Makefile | 26 ++++- tools/kvm/powerpc/cpu_info.c | 83 ++++++++++++++++ tools/kvm/powerpc/cpu_info.h | 43 ++++++++ tools/kvm/powerpc/include/kvm/kvm-arch.h | 11 ++ tools/kvm/powerpc/kvm-cpu.c | 1 + tools/kvm/powerpc/kvm.c | 154 +++++++++++++++++++++++++++++- 6 files changed, 312 insertions(+), 6 deletions(-) create mode 100644 tools/kvm/powerpc/cpu_info.c create mode 100644 tools/kvm/powerpc/cpu_info.h
tools/kvm/Makefile +21 -5
@@ -105,6 +105,8 @@ ifeq ($(uname_M),x86_64) DEFINES += -DCONFIG_X86_64 endif +LIBFDT_SRC = fdt.o fdt_ro.o fdt_wip.o fdt_sw.o fdt_rw.o fdt_strerror.o +LIBFDT_OBJS = $(patsubst %,../../scripts/dtc/libfdt/%,$(LIBFDT_SRC)) ### Arch-specific stuff
@@ -130,9 +132,14 @@ ifeq ($(uname_M), ppc64) OBJS += powerpc/ioport.o OBJS += powerpc/irq.o OBJS += powerpc/kvm.o + OBJS += powerpc/cpu_info.o OBJS += powerpc/kvm-cpu.o +# We use libfdt, but it's sometimes not packaged 64bit. It's small too, +# so just build it in: + CFLAGS += -I../../scripts/dtc/libfdt + OBJS += $(LIBFDT_OBJS) ARCH_INCLUDE := powerpc/include - CFLAGS += -m64 + CFLAGS += -m64 endif ###
@@ -198,10 +205,6 @@ DEFINES += -DBUILD_ARCH='"$(ARCH)"' KVM_INCLUDE := include CFLAGS += $(CPPFLAGS) $(DEFINES) -I$(KVM_INCLUDE) -I$(ARCH_INCLUDE) -I$(KINCL_PATH)/include -I$(KINCL_PATH)/arch/$(ARCH)/include/ -O2 -fno-strict-aliasing -g -ifneq ($(WERROR),0) - WARNINGS += -Werror -endif - WARNINGS += -Wall WARNINGS += -Wcast-align WARNINGS += -Wformat=2
@@ -220,6 +223,13 @@ WARNINGS += -Wwrite-strings CFLAGS += $(WARNINGS) +# Some targets may use 'external' sources that don't build totally cleanly. +CFLAGS_EASYGOING := $(CFLAGS) + +ifneq ($(WERROR),0) + CFLAGS += -Werror +endif + all: arch_support_check $(PROGRAM) $(PROGRAM_ALIAS) $(GUEST_INIT) $(GUEST_INIT_S2) arch_support_check:
@@ -262,6 +272,12 @@ builtin-help.d: $(KVM_INCLUDE)/common-cmds.h $(OBJS): +# This rule relaxes the -Werror on libfdt, since for now it still has +# a bunch of warnings. :( +../../scripts/dtc/libfdt/%.o: ../../scripts/dtc/libfdt/%.c + $(E) " CC " $@ + $(Q) $(CC) -c $(CFLAGS_EASYGOING) $< -o $@ + util/rbtree.o: ../../lib/rbtree.c $(E) " CC " $@ $(Q) $(CC) -c $(CFLAGS) $< -o $@
tools/kvm/powerpc/cpu_info.c new file +83 -0
83 lines not on this page · raw message
tools/kvm/powerpc/cpu_info.h new file +43 -0
43 lines not on this page · raw message
tools/kvm/powerpc/include/kvm/kvm-arch.h +11 -0
@@ -53,6 +53,7 @@ struct kvm {void *ram_start;u64 sdr1; +u32 pvr;bool nmi_disabled;
@@ -70,4 +71,14 @@ struct kvm { int vm_state; }; +/* Helper for the various bits of code that generate FDT nodes */ +#define _FDT (exp) \ + do { \ + int ret = (exp); \ + if (ret < 0) { \ + die("Error creating device tree: %s: %s\n", \ + #exp, fdt_strerror(ret)); \ + } \ + } while (0) +#endif /* KVM__KVM_ARCH_H */
tools/kvm/powerpc/kvm-cpu.c +1 -0
@@ -134,6 +134,7 @@ static void kvm_cpu__setup_sregs(struct kvm_cpu *vcpu)die ("KVM_GET_SREGS failed" ); sregs.u.s.sdr1 = vcpu->kvm->sdr1; + sregs.pvr = vcpu->kvm->pvr;if (ioctl (vcpu->vcpu_fd,KVM_SET_SREGS , &sregs) <0 )die ("KVM_SET_SREGS failed" );
tools/kvm/powerpc/kvm.c +153 -1
193 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Re: [PATCH V4 2/7] kvm tools: Generate SPAPR PPC64 guest device tree
tools/kvm/powerpc/cpu_info.c line 41
Quoted 10 lines · Matt Evans
tools/kvm/powerpc/cpu_info.c new file +10
-0+static struct cpu_info cpu_power7_info = { + "POWER7", + power7_page_sizes_prop, sizeof(power7_page_sizes_prop), + power7_segment_sizes_prop, sizeof(power7_segment_sizes_prop), + 32, /* SLB size */ + 512000000, /* TB frequency */ + 128, /* d-cache block size */ + 128, /* i-cache block size */ + CPUINFO_FLAG_DFP | CPUINFO_FLAG_VSX | CPUINFO_FLAG_VMX +};
Why don't you use C99 initializers here?
Re: [PATCH V4 2/7] kvm tools: Generate SPAPR PPC64 guest device tree
Quoted 13 lines · Pekka Enberg
tools/kvm/powerpc/cpu_info.c line 41
Quoted 10 lines · Matt Evans
tools/kvm/powerpc/cpu_info.c new file +10
-0+static struct cpu_info cpu_power7_info = { +"POWER7" , + power7_page_sizes_prop,sizeof (power7_page_sizes_prop), + power7_segment_sizes_prop,sizeof (power7_segment_sizes_prop), +32 ,/* SLB size */ +512000000 ,/* TB frequency */ +128 ,/* d-cache block size */ +128 ,/* i-cache block size */ +CPUINFO_FLAG_DFP |CPUINFO_FLAG_VSX |CPUINFO_FLAG_VMX +};Why don't you use C99 initializers here?
...just out of bad bad habit :) Initialisers'd be cleaner, I'll convert them.
Thanks!
Matt
Re: [PATCH V4 2/7] kvm tools: Generate SPAPR PPC64 guest device tree
In reply to Matt EvansQuoted 10 lines · Matt Evans
The generated DT is the bare minimum structure required for SPAPR (on which subsequent patches for VIO, XICS, PCI etc. will build); root node, cpus, memory.
The DT contains CPU-specific configuration; a very simple 'cpu info' mechanism is added to recognise/differentiate DT entries for POWER7 and PPC970 host CPUs. Future support of more CPUs is possible.
libfdt is included from
scripts/dtc/libfdt.Signed-off-by Matt Evans <[email protected]>
For the bits derived from my code:
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [PATCH V4 2/7] kvm tools: Generate SPAPR PPC64 guest device tree
Quoted 8 lines · David Gibson
Quoted 7 lines · Matt Evans
The generated DT is the bare minimum structure required for SPAPR (on which subsequent patches for VIO, XICS, PCI etc. will build); root node, cpus, memory.
The DT contains CPU-specific configuration; a very simple 'cpu info' mechanism is added to recognise/differentiate DT entries for POWER7 and PPC970 host CPUs. Future support of more CPUs is possible.
Quoted 8 lines
Quoted 3 lines
libfdt is included from
scripts/dtc/libfdt.Signed-off-by Matt Evans <[email protected]>For the bits derived from my code:
Signed-off-by David Gibson <[email protected]>
For the bits derived from my code:
Signature · 1 line
Alexey
PATCH v4 3/7 kvm tools: Add SPAPR PPC64 hcall & rtascall structure
In reply to Matt EvansThis patch adds the basic structure for HV calls, their registration and some of the simpler calls. A similar layout for RTAS calls is also added, again with some of the simpler RTAS calls used by the guest. The SPAPR RTAS stub is generated inline. Also, nodes for RTAS are added to the device tree.
--- tools/kvm/Makefile | 2 + tools/kvm/powerpc/kvm-cpu.c | 6 + tools/kvm/powerpc/kvm.c | 41 +++++++- tools/kvm/powerpc/spapr.h | 84 ++++++++++++++ tools/kvm/powerpc/spapr_hcall.c | 134 +++++++++++++++++++++++ tools/kvm/powerpc/spapr_rtas.c | 229 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 495 insertions(+), 1 deletions(-) create mode 100644 tools/kvm/powerpc/spapr.h create mode 100644 tools/kvm/powerpc/spapr_hcall.c create mode 100644 tools/kvm/powerpc/spapr_rtas.c
tools/kvm/Makefile +2 -0
@@ -134,6 +134,8 @@ ifeq ($(uname_M), ppc64) OBJS += powerpc/kvm.o OBJS += powerpc/cpu_info.o OBJS += powerpc/kvm-cpu.o + OBJS += powerpc/spapr_hcall.o + OBJS += powerpc/spapr_rtas.o # We use libfdt, but it's sometimes not packaged 64bit. It's small too, # so just build it in: CFLAGS += -I../../scripts/dtc/libfdt
tools/kvm/powerpc/kvm-cpu.c +6 -0
@@ -14,6 +14,8 @@#include "kvm/util.h" #include "kvm/kvm.h" +#include "spapr.h" +#include <sys/ioctl.h> #include <sys/mman.h> #include <signal.h>
@@ -169,6 +171,10 @@ bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu)bool ret = true;struct kvm_run *run = vcpu->kvm_run;switch (run->exit_reason) { +case KVM_EXIT_PAPR_HCALL : + run->papr_hcall.ret =spapr_hypercall (vcpu, run->papr_hcall.nr, + (target_ulong *)run->papr_hcall.args); +break ;default : ret = false; }
tools/kvm/powerpc/kvm.c +40 -1
65 lines not on this page · raw message
tools/kvm/powerpc/spapr.h new file +84 -0
84 lines not on this page · raw message
tools/kvm/powerpc/spapr_hcall.c new file +134 -0
134 lines not on this page · raw message
tools/kvm/powerpc/spapr_rtas.c new file +229 -0
229 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Re: [PATCH V4 3/7] kvm tools: Add SPAPR PPC64 hcall & rtascall structure
Quoted 1 line · Matt Evans
+#define
DEBUG_SPAPR_HCALLS
I suppose this shouldn't be defined by default?
tools/kvm/powerpc/spapr.h line 51
Quoted 7 lines
tools/kvm/powerpc/spapr.h new file +7
-0+#ifdef DEBUG_SPAPR_HCALLS +#define hcall_dprintf (fmt, ...) \ + do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) +#else +#define hcall_dprintf (fmt, ...) \ + do { } while (0) +#endif
I don't expect you to fix this but this sort of thing really cries out for userspace tracepoints.
Re: [PATCH V4 3/7] kvm tools: Add SPAPR PPC64 hcall & rtascall structure
Quoted 4 lines · Pekka Enberg
Quoted 1 line · Matt Evans
+#define
DEBUG_SPAPR_HCALLSI suppose this shouldn't be defined by default?
Well, I had a bit of a debate about it. I left it on as it is actually interesting whilst experimenting with different SPAPR guests. For instance (and this is really out there, there are other reasons why this won't work) if someone tries an AIX guest it'd be good to see lots of "Unsupported!" spew. (The 'unsupported' message could be a warning but that might also get annoying, OTOH.) I would prefer to leave it on for the moment.
Quoted 11 lines
tools/kvm/powerpc/spapr.h line 51
Quoted 8 lines
tools/kvm/powerpc/spapr.h new file +7
-0+#ifdef DEBUG_SPAPR_HCALLS +#define hcall_dprintf (fmt, ...) \ + do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) +#else +#define hcall_dprintf (fmt, ...) \ + do { } while (0) +#endif I don't expect you to fix this but this sort of thing really cries out for userspace tracepoints.
Ha! Yes...
Cheers,
Matt
PATCH v4 4/7 kvm tools: Add SPAPR PPC64 HV console
In reply to Matt EvansThis adds the console code, plus VIO HV terminal nodes are added to the device tree so the guest kernel will pick it up.
--- tools/kvm/Makefile | 1 + tools/kvm/powerpc/kvm.c | 33 ++++++++++++ tools/kvm/powerpc/spapr_hvcons.c | 102 ++++++++++++++++++++++++++++++++++++++ tools/kvm/powerpc/spapr_hvcons.h | 19 +++++++ 4 files changed, 155 insertions(+), 0 deletions(-) create mode 100644 tools/kvm/powerpc/spapr_hvcons.c create mode 100644 tools/kvm/powerpc/spapr_hvcons.h
tools/kvm/Makefile +1 -0
@@ -136,6 +136,7 @@ ifeq ($(uname_M), ppc64) OBJS += powerpc/kvm-cpu.o OBJS += powerpc/spapr_hcall.o OBJS += powerpc/spapr_rtas.o + OBJS += powerpc/spapr_hvcons.o # We use libfdt, but it's sometimes not packaged 64bit. It's small too, # so just build it in: CFLAGS += -I../../scripts/dtc/libfdt
tools/kvm/powerpc/kvm.c +33 -0
@@ -17,6 +17,7 @@#include "cpu_info.h" #include "spapr.h" +#include "spapr_hvcons.h" #include <linux/kvm.h>
@@ -133,6 +134,8 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size)/* FIXME: SPAPR-specific */ hypercall_init ();register_core_rtas (); +/* Now that hypercalls are initialised, register a couple for the console: */ +spapr_hvcons_init (); }void kvm__arch_delete_ram (struct kvm *kvm)
@@ -151,6 +154,12 @@ void kvm__irq_trigger(struct kvm *kvm, int irq)kvm__irq_line (kvm, irq,0 ); } +void kvm__arch_periodic_poll (struct kvm *kvm) +{ +/* FIXME: Should register callbacks to platform-specific polls */ +spapr_hvcons_poll (kvm); +} +int load_flat_binary (struct kvm *kvm,int fd_kernel,int fd_initrd,const char *kernel_cmdline) {void *p;
@@ -266,6 +275,13 @@ static void setup_fdt(struct kvm *kvm)_FDT (fdt_property (fdt,"linux,initrd-end" , &ird_end_prop,sizeof (ird_end_prop))); } + +/* +* stdout-path: This is assuming we're using the HV console. Also, the +* address is hardwired until we do a VIO bus. +*/ +_FDT (fdt_property_string (fdt,"linux,stdout-path" , +"/vdevice/vty@30000000" ));_FDT (fdt_end_node (fdt));/*
@@ -352,6 +368,23 @@ static void setup_fdt(struct kvm *kvm) }_FDT (fdt_end_node (fdt)); +/* +* VIO: See comment in linux,stdout-path; we don't yet represent a VIO +* bus/address allocation so addresses are hardwired here. +*/ +_FDT (fdt_begin_node (fdt,"vdevice" )); +_FDT (fdt_property_cell (fdt,"#address-cells" ,0x1 )); +_FDT (fdt_property_cell (fdt,"#size-cells" ,0x0 )); +_FDT (fdt_property_string (fdt,"device_type" ,"vdevice" )); +_FDT (fdt_property_string (fdt,"compatible" ,"IBM,vdevice" )); +_FDT (fdt_begin_node (fdt,"vty@30000000" )); +_FDT (fdt_property_string (fdt,"name" ,"vty" )); +_FDT (fdt_property_string (fdt,"device_type" ,"serial" )); +_FDT (fdt_property_string (fdt,"compatible" ,"hvterm1" )); +_FDT (fdt_property_cell (fdt,"reg" ,0x30000000 )); +_FDT (fdt_end_node (fdt)); +_FDT (fdt_end_node (fdt)); +/* Finalise: */ _FDT (fdt_end_node (fdt));/* Root node */ _FDT (fdt_finish (fdt));
tools/kvm/powerpc/spapr_hvcons.c new file +102 -0
102 lines not on this page · raw message
tools/kvm/powerpc/spapr_hvcons.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* SPAPR HV console +* +* Copyright (c) 2011 Matt Evans <[email protected]>, IBM Corporation. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation. +*/ + +#ifndef spapr_hvcons_H +#define spapr_hvcons_H + +#include "kvm/kvm.h" + +void spapr_hvcons_init (void ); +void spapr_hvcons_poll (struct kvm *kvm); + +#endif
Signature · 1 line
1.7.0.4
PATCH v4 5/7 kvm tools: Add PPC64 XICS interrupt controller support
In reply to Matt EvansThis patch adds XICS emulation code (heavily borrowed from QEMU), and wires this into kvm_cpu__irq() to fire a CPU IRQ via KVM. A device tree entry is also added. IPIs work, xics_alloc_irqnum() is added to allocate an external IRQ (which will later be used by the PHB PCI code) and finally, kvm__irq_line() can be called to raise an IRQ on XICS.
--- tools/kvm/Makefile | 1 + tools/kvm/powerpc/include/kvm/kvm-arch.h | 1 + tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h | 2 + tools/kvm/powerpc/irq.c | 25 ++- tools/kvm/powerpc/kvm-cpu.c | 11 + tools/kvm/powerpc/kvm.c | 26 +- tools/kvm/powerpc/xics.c | 514 ++++++++++++++++++++++++++ tools/kvm/powerpc/xics.h | 23 ++ 8 files changed, 596 insertions(+), 7 deletions(-) create mode 100644 tools/kvm/powerpc/xics.c create mode 100644 tools/kvm/powerpc/xics.h
tools/kvm/Makefile +1 -0
@@ -137,6 +137,7 @@ ifeq ($(uname_M), ppc64) OBJS += powerpc/spapr_hcall.o OBJS += powerpc/spapr_rtas.o OBJS += powerpc/spapr_hvcons.o + OBJS += powerpc/xics.o # We use libfdt, but it's sometimes not packaged 64bit. It's small too, # so just build it in: CFLAGS += -I../../scripts/dtc/libfdt
tools/kvm/powerpc/include/kvm/kvm-arch.h +1 -0
@@ -69,6 +69,7 @@ struct kvm {unsigned long initrd_size;const char *name;int vm_state; +struct icp_state *icp; };/* Helper for the various bits of code that generate FDT nodes */
tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h +2 -0
@@ -36,6 +36,8 @@#define MSR_RI (1UL<<1)#define MSR_LE (1UL<<0) +#define POWER7_EXT_IRQ 0 +struct kvm ;struct kvm_cpu {
tools/kvm/powerpc/irq.c +23 -2
@@ -21,6 +21,15 @@#include <stddef.h> #include <stdlib.h> +#include "xics.h" + +#define XICS_IRQS 1024 + +/* +* FIXME: The code in this file assumes an SPAPR guest, using XICS. Make +* generic & cope with multiple PPC platform types. +*/ +int irq__register_device (u32 dev,u8 *num,u8 *pin,u8 *line) { fprintf(stderr, "irq__register_device(%d, [%d], [%d], [%d]\n",
@@ -28,9 +37,21 @@ int irq__register_device(u32 dev, u8 *num, u8 *pin, u8 *line)return 0 ; } -void irq__init (struct kvm *kvm) +int irq__init (struct kvm *kvm) { -fprintf (stderr, __func__); +/* +* kvm->nr_cpus is now valid; for /now/, pass +* this to xics_system_init(), which assumes servers +* are numbered 0..nrcpus. This may not really be true, +* but it is OK currently. +*/ + kvm->icp =xics_system_init (XICS_IRQS , kvm->nrcpus); +return 0 ; +} + +int irq__exit (struct kvm *kvm) +{ +return 0 ; }int irq__add_msix_route (struct kvm *kvm,struct msi_msg *msg)
tools/kvm/powerpc/kvm-cpu.c +11 -0
@@ -15,6 +15,7 @@#include "kvm/kvm.h" #include "spapr.h" +#include "xics.h" #include <sys/ioctl.h> #include <sys/mman.h>
@@ -90,6 +91,9 @@ struct kvm_cpu *kvm_cpu__init(struct kvm *kvm, unsigned long cpu_id)*/ vcpu->is_running = true; +/* Register with IRQ controller (FIXME, assumes XICS) */ +xics_cpu_register (vcpu); +return vcpu; }
@@ -160,6 +164,13 @@ void kvm_cpu__reset_vcpu(struct kvm_cpu *vcpu)/* kvm_cpu__irq - set KVM's IRQ flag on this vcpu */ void kvm_cpu__irq (struct kvm_cpu *vcpu,int pin,int level) { +unsigned int virq = level ?KVM_INTERRUPT_SET_LEVEL :KVM_INTERRUPT_UNSET ; + +/* FIXME: POWER-specific */ +if (pin !=POWER7_EXT_IRQ ) +return ; +if (ioctl (vcpu->vcpu_fd,KVM_INTERRUPT , &virq) <0 ) +pr_warning ("Could not KVM_INTERRUPT." ); }void kvm_cpu__arch_nmi (struct kvm_cpu *cpu)
tools/kvm/powerpc/kvm.c +21 -5
@@ -39,9 +39,13 @@#define HUGETLBFS_PATH "/var/lib/hugetlbfs/global/pagesize-16MB/" +#define PHANDLE_XICP 0x00001111 +static char kern_cmdline[2048 ];struct kvm_ext kvm_req_ext[] = { + {DEFINE_KVM_EXT (KVM_CAP_PPC_UNSET_IRQ ) }, + {DEFINE_KVM_EXT (KVM_CAP_PPC_IRQ_LEVEL ) }, {0 ,0 } };
@@ -143,11 +147,6 @@ void kvm__arch_delete_ram(struct kvm *kvm)munmap (kvm->ram_start, kvm->ram_size); } -void kvm__irq_line (struct kvm *kvm,int irq,int level) -{ -fprintf (stderr,"irq_line(%d, %d)\n" , irq, level); -} -void kvm__irq_trigger (struct kvm *kvm,int irq) {kvm__irq_line (kvm, irq,1 );
@@ -225,6 +224,7 @@ static void setup_fdt(struct kvm *kvm) {uint64_t mem_reg_property[] = {0 ,cpu_to_be64 (kvm->ram_size) };int smp_cpus = kvm->nrcpus; +uint32_t int_server_ranges_prop[] = {0 ,cpu_to_be32 (smp_cpus)};char hypertas_prop_kvm[] ="hcall-pft\0hcall-term\0" "hcall-dabr\0hcall-interrupt\0hcall-tce\0hcall-vio\0" "hcall-splpar\0hcall-bulk" ;
@@ -368,6 +368,22 @@ static void setup_fdt(struct kvm *kvm) }_FDT (fdt_end_node (fdt)); +/* IRQ controller */ +_FDT (fdt_begin_node (fdt,"interrupt-controller@0" )); + +_FDT (fdt_property_string (fdt,"device_type" , +"PowerPC-External-Interrupt-Presentation" )); +_FDT (fdt_property_string (fdt,"compatible" ,"IBM,ppc-xicp" )); +_FDT (fdt_property_cell (fdt,"reg" ,0 )); +_FDT (fdt_property (fdt,"interrupt-controller" ,NULL ,0 )); +_FDT (fdt_property (fdt,"ibm,interrupt-server-ranges" , + int_server_ranges_prop, +sizeof (int_server_ranges_prop))); +_FDT (fdt_property_cell (fdt,"#interrupt-cells" ,2 )); +_FDT (fdt_property_cell (fdt,"linux,phandle" ,PHANDLE_XICP )); +_FDT (fdt_property_cell (fdt,"phandle" ,PHANDLE_XICP )); +_FDT (fdt_end_node (fdt)); +/* * VIO: See comment in linux,stdout-path; we don't yet represent a VIO * bus/address allocation so addresses are hardwired here.
tools/kvm/powerpc/xics.c new file +514 -0
514 lines not on this page · raw message
tools/kvm/powerpc/xics.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* PAPR Virtualized Interrupt System, aka ICS/ICP aka xics +* +* Copyright 2011 Matt Evans <[email protected]>, IBM Corporation. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published +* by the Free Software Foundation. +*/ + +#ifndef XICS_H +#define XICS_H + +#define XICS_IPI 0x2 + +struct kvm_cpu ; +struct icp_state ; + +struct icp_state *xics_system_init (unsigned int nr_irqs,unsigned int nr_cpus); +void xics_cpu_register (struct kvm_cpu *vcpu); +int xics_alloc_irqnum (void ); + +#endif
Signature · 1 line
1.7.0.4
PATCH v4 6/7 kvm tools: Add PPC64 PCI Host Bridge
In reply to Matt EvansThis provides the PCI bridge, definitions for the address layout of the windows and wires in IRQs. Once PCI devices are all registered, they are enumerated and DT nodes generated for each.
--- tools/kvm/powerpc/include/kvm/kvm-arch.h | 3 + tools/kvm/powerpc/irq.c | 18 ++- tools/kvm/powerpc/kvm.c | 11 + tools/kvm/powerpc/spapr.h | 9 + tools/kvm/powerpc/spapr_pci.c | 423 ++++++++++++++++++++++++++++++ tools/kvm/powerpc/spapr_pci.h | 57 ++++ 6 files changed, 519 insertions(+), 2 deletions(-) create mode 100644 tools/kvm/powerpc/spapr_pci.c create mode 100644 tools/kvm/powerpc/spapr_pci.h
tools/kvm/powerpc/include/kvm/kvm-arch.h +3 -0
@@ -40,6 +40,8 @@*/ #define KVM_PCI_MMIO_AREA 0x1000000 +struct spapr_phb ; +struct kvm {int sys_fd;/* For system ioctls(), i.e. /dev/kvm */ int vm_fd;/* For VM ioctls() */
@@ -70,6 +72,7 @@ struct kvm {const char *name;int vm_state;struct icp_state *icp; +struct spapr_phb *phb; };/* Helper for the various bits of code that generate FDT nodes */
tools/kvm/powerpc/irq.c +16 -2
@@ -21,7 +21,10 @@#include <stddef.h> #include <stdlib.h> +#include "kvm/pci.h" +#include "xics.h" +#include "spapr_pci.h" #define XICS_IRQS 1024
@@ -30,10 +33,21 @@* generic & cope with multiple PPC platform types. */ +static int pci_devs =0 ; +int irq__register_device (u32 dev,u8 *num,u8 *pin,u8 *line) { -fprintf (stderr,"irq__register_device(%d, [%d], [%d], [%d]\n" , - dev, *num, *pin, *line); +if (pci_devs >=PCI_MAX_DEVICES ) +die ("Hit PCI device limit!\n" ); + + *num = pci_devs++; + + *pin =1 ; +/* +* Have I said how nasty I find this? Line should be dontcare... PHB +* should determine which CPU/XICS IRQ to fire. +*/ + *line =xics_alloc_irqnum ();return 0 ; }
tools/kvm/powerpc/kvm.c +11 -0
@@ -18,6 +18,7 @@#include "spapr.h" #include "spapr_hvcons.h" +#include "spapr_pci.h" #include <linux/kvm.h>
@@ -140,6 +141,11 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size)register_core_rtas ();/* Now that hypercalls are initialised, register a couple for the console: */ spapr_hvcons_init (); +spapr_create_phb (kvm,"pci" ,SPAPR_PCI_BUID , +SPAPR_PCI_MEM_WIN_ADDR , +SPAPR_PCI_MEM_WIN_SIZE , +SPAPR_PCI_IO_WIN_ADDR , +SPAPR_PCI_IO_WIN_SIZE ); }void kvm__arch_delete_ram (struct kvm *kvm)
@@ -406,6 +412,11 @@ static void setup_fdt(struct kvm *kvm)_FDT (fdt_finish (fdt));_FDT (fdt_open_into (fdt, fdt_dest,FDT_MAX_SIZE )); + +/* PCI */ +if (spapr_populate_pci_devices (kvm,PHANDLE_XICP , fdt_dest)) +die ("Fail populating PCI device nodes" ); +_FDT (fdt_add_mem_rsv (fdt_dest, kvm->rtas_gra, kvm->rtas_size));_FDT (fdt_pack (fdt_dest)); }
tools/kvm/powerpc/spapr.h +9 -0
@@ -81,4 +81,13 @@ target_ulong spapr_rtas_call(struct kvm_cpu *vcpu, uint32_t token, uint32_t nargs, target_ulong args, uint32_t nret, target_ulong rets); +#define SPAPR_PCI_BUID 0x800000020000001ULL +#define SPAPR_PCI_MEM_WIN_ADDR (KVM_MMIO_START + 0xA0000000) +#define SPAPR_PCI_MEM_WIN_SIZE 0x20000000 +#define SPAPR_PCI_IO_WIN_ADDR (SPAPR_PCI_MEM_WIN_ADDR + SPAPR_PCI_MEM_WIN_SIZE) +#define SPAPR_PCI_IO_WIN_SIZE 0x2000000 + +#define SPAPR_PCI_WIN_START SPAPR_PCI_MEM_WIN_ADDR +#define SPAPR_PCI_WIN_END (SPAPR_PCI_IO_WIN_ADDR + SPAPR_PCI_IO_WIN_SIZE) +#endif /* !defined (__HW_SPAPR_H__) */
tools/kvm/powerpc/spapr_pci.c new file +423 -0
423 lines not on this page · raw message
tools/kvm/powerpc/spapr_pci.h new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Re: [PATCH V4 6/7] kvm tools: Add PPC64 PCI Host Bridge
Quoted 5 lines · Matt Evans
This provides the PCI bridge, definitions for the address layout of the windows and wires in IRQs. Once PCI devices are all registered, they are enumerated and DT nodes generated for each.
Signed-off-by Matt Evans <[email protected]>
For the bits derived from my qemu code:
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [PATCH V4 6/7] kvm tools: Add PPC64 PCI Host Bridge
Quoted 11 lines · David Gibson
Quoted 5 lines · Matt Evans
This provides the PCI bridge, definitions for the address layout of the windows and wires in IRQs. Once PCI devices are all registered, they are enumerated and DT nodes generated for each.
Signed-off-by Matt Evans <[email protected]>For the bits derived from my qemu code:
Signed-off-by David Gibson <[email protected]>
For the bits derived from my qemu code:
Signature · 1 line
Alexey
PATCH v4 7/7 kvm tools: Add PPC64 kvm_cpu__emulate_io()
In reply to Matt EvansThis is the final piece of the puzzle for PPC SPAPR PCI; this function splits MMIO accesses into the two PHB windows & directs things to MMIO/IO emulation as appropriate.
--- tools/kvm/Makefile | 1 + tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h | 10 +++++++++- tools/kvm/powerpc/kvm-cpu.c | 22 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletions(-)
tools/kvm/Makefile +1 -0
@@ -137,6 +137,7 @@ ifeq ($(uname_M), ppc64) OBJS += powerpc/spapr_hcall.o OBJS += powerpc/spapr_rtas.o OBJS += powerpc/spapr_hvcons.o + OBJS += powerpc/spapr_pci.o OBJS += powerpc/xics.o # We use libfdt, but it's sometimes not packaged 64bit. It's small too, # so just build it in:
tools/kvm/powerpc/include/kvm/kvm-cpu-arch.h +9 -1
@@ -14,7 +14,7 @@/* Architecture-specific kvm_cpu definitions. */ #include <linux/kvm.h> /* for struct kvm_regs */ - +#include <stdbool.h> #include <pthread.h> #define MSR_SF (1UL<<63)
@@ -65,4 +65,12 @@ struct kvm_cpu {void kvm_cpu__irq (struct kvm_cpu *vcpu,int pin,int level); +/* This is never actually called on PPC. */ +static inline bool kvm_cpu__emulate_io (struct kvm *kvm,u16 port,void *data,int direction,int size,u32 count) +{ +return false; +} + +bool kvm_cpu__emulate_mmio (struct kvm *kvm,u64 phys_addr,u8 *data,u32 len,u8 is_write); +#endif /* KVM__KVM_CPU_ARCH_H */
tools/kvm/powerpc/kvm-cpu.c +22 -0
@@ -15,6 +15,7 @@#include "kvm/kvm.h" #include "spapr.h" +#include "spapr_pci.h" #include "xics.h" #include <sys/ioctl.h>
@@ -24,6 +25,7 @@#include <string.h> #include <errno.h> #include <stdio.h> +#include <assert.h> static int debug_fd;
@@ -192,6 +194,26 @@ bool kvm_cpu__handle_exit(struct kvm_cpu *vcpu)return ret; } +bool kvm_cpu__emulate_mmio (struct kvm *kvm,u64 phys_addr,u8 *data,u32 len,u8 is_write) +{ +/* +* FIXME: This function will need to be split in order to support +* various PowerPC platforms/PHB types, etc. It currently assumes SPAPR +* PPC64 guest. +*/ +bool ret = false; + +if ((phys_addr >=SPAPR_PCI_WIN_START ) && + (phys_addr <SPAPR_PCI_WIN_END )) { + ret =spapr_phb_mmio (kvm, phys_addr, data, len, is_write); + }else { +pr_warning ("MMIO %s unknown address %llx (size %d)!\n" , + is_write ?"write to" :"read from" , + phys_addr, len); + } +return ret; +} +#define CONDSTR_BIT (m, b) (((m) & MSR_##b) ? #b" " : "")void kvm_cpu__show_registers (struct kvm_cpu *vcpu)
Signature · 1 line
1.7.0.4
Quoted 7 lines · Matt Evans
This series adds support for a PPC64 platform, SPAPR, on top of the previous more general PPC64 CPU support. This platform is paravirtualised, with most of the MMU hypercalls being dealt with in the kernel. Userland needs to describe the environment to the machine with a device tree, cope with some hypercalls (and RTAS calls) for hvconsole, PCI config and IRQs, and emulate the interrupt controller (XICS) and PCI Host Bridge of the SPAPR-esque machine.
I think the patches are good to go once we've sorted out the minor nits I pointed out.