Pending pseries patches
cover Pending pseries patches
Hi Alex,
Here's another patch of pending pseries patches. 1/8 is what I hope is finally a correct version of the patch to extend FPU state for recent CPUs. The rest is basically preliminary cleanups before adding support for in-kernel XICS emulation. The actual support for the in-kernel XICS is waiting for that support to go into the kernel upstream of course.
PATCH 1/8 target-ppc: Extend FPU state for newer POWER CPUs
This patch adds some extra FPU state to CPUPPCState. Specifically, fpscr is extended to a target_ulong bits, since some recent (64 bit) CPUs now have more status bits than fit inside 32 bits. Also, we add the 32 VSR registers present on CPUs with VSX (these extend the standard FP regs, which together with the Altivec/VMX registers form a 64 x 128bit register file for VSX).
We don't actually support the instructions using these extra registers in TCG yet, but we still need a place to store the state so we can sync it with KVM and savevm/loadvm it. This patch updates the savevm code to not fail on the extended state, but also does not actually save it - that's a project for another patch.
---
v2:
* Used target_ulong instead of uint64_t, since the extended state is used
only on ppc64 targets.
* Fixed the TCG mapping of fpscr to match the new type.
--- target-ppc/cpu.h | 4 +++- target-ppc/machine.c | 8 ++++++-- target-ppc/translate.c | 29 ++++++++++++++++++----------- 3 files changed, 27 insertions(+), 14 deletions(-)
target-ppc/cpu.h +3 -1
@@ -963,7 +963,7 @@ struct CPUPPCState {/* floating point registers */ float64 fpr[32 ];/* floating point status and control register */ -uint32_t fpscr; +target_ulong fpscr;/* Next instruction pointer */ target_ulong nip;
@@ -1014,6 +1014,8 @@ struct CPUPPCState {/* Altivec registers */ ppc_avr_t avr[32 ];uint32_t vscr; +/* VSX registers */ +uint64_t vsr[32 ];/* SPE registers */ uint64_t spe_acc;uint32_t spe_fscr;
target-ppc/machine.c +6 -2
@@ -6,6 +6,7 @@ void cpu_save(QEMUFile *f, void *opaque) {CPUPPCState *env = (CPUPPCState *)opaque;unsigned int i, j; +uint32_t fpscr;for (i =0 ; i <32 ; i++)qemu_put_betls (f, &env->gpr[i]);
@@ -30,7 +31,8 @@ void cpu_save(QEMUFile *f, void *opaque) u.d = env->fpr[i];qemu_put_be64 (f, u.l); } -qemu_put_be32s (f, &env->fpscr); + fpscr = env->fpscr; +qemu_put_be32s (f, &fpscr);qemu_put_sbe32s (f, &env->access_type);#if defined(TARGET_PPC64 )qemu_put_betls (f, &env->asr);
@@ -90,6 +92,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)CPUPPCState *env = (CPUPPCState *)opaque;unsigned int i, j;target_ulong sdr1; +uint32_t fpscr;for (i =0 ; i <32 ; i++)qemu_get_betls (f, &env->gpr[i]);
@@ -114,7 +117,8 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id) u.l =qemu_get_be64 (f); env->fpr[i] = u.d; } -qemu_get_be32s (f, &env->fpscr); +qemu_get_be32s (f, &fpscr); + env->fpscr = fpscr;qemu_get_sbe32s (f, &env->access_type);#if defined(TARGET_PPC64 )qemu_get_betls (f, &env->asr);
target-ppc/translate.c +18 -11
@@ -68,7 +68,7 @@ static TCGv cpu_cfar;#endif static TCGv cpu_xer;static TCGv cpu_reserve; -static TCGv_i32 cpu_fpscr; +static TCGv cpu_fpscr;static TCGv_i32 cpu_access_type;#include "gen-icount.h"
@@ -163,8 +163,8 @@ void ppc_translate_init(void) offsetof(CPUPPCState , reserve_addr), "reserve_addr"); - cpu_fpscr =tcg_global_mem_new_i32 (TCG_AREG0 , - offsetof(CPUPPCState , fpscr),"fpscr" ); + cpu_fpscr =tcg_global_mem_new (TCG_AREG0 , + offsetof(CPUPPCState , fpscr),"fpscr" ); cpu_access_type =tcg_global_mem_new_i32 (TCG_AREG0 , offsetof(CPUPPCState , access_type),"access_type" );
@@ -2302,6 +2302,7 @@ GEN_FLOAT_B(neg, 0x08, 0x01, 0, PPC_FLOAT);/* mcrfs */ static void gen_mcrfs (DisasContext *ctx) { +TCGv tmp =tcg_temp_new ();int bfa;if (unlikely (!ctx->fpu_enabled)) {
@@ -2309,9 +2310,11 @@ static void gen_mcrfs(DisasContext *ctx)return ; } bfa =4 * (7 -crfS (ctx->opcode)); -tcg_gen_shri_i32 (cpu_crf[crfD (ctx->opcode)], cpu_fpscr, bfa); +tcg_gen_shri_tl (tmp, cpu_fpscr, bfa); +tcg_gen_trunc_tl_i32 (cpu_crf[crfD (ctx->opcode)], tmp); +tcg_temp_free (tmp);tcg_gen_andi_i32 (cpu_crf[crfD (ctx->opcode)], cpu_crf[crfD (ctx->opcode)],0xf ); -tcg_gen_andi_i32 (cpu_fpscr, cpu_fpscr, ~(0xF << bfa)); +tcg_gen_andi_tl (cpu_fpscr, cpu_fpscr, ~(0xF << bfa)); }/* mffs */
@@ -2322,7 +2325,7 @@ static void gen_mffs(DisasContext *ctx)return ; }gen_reset_fpstatus (); -tcg_gen_extu_i32_i64 (cpu_fpr[rD (ctx->opcode)], cpu_fpscr); +tcg_gen_extu_tl_i64 (cpu_fpr[rD (ctx->opcode)], cpu_fpscr);gen_compute_fprf (cpu_fpr[rD (ctx->opcode)],0 ,Rc (ctx->opcode) !=0 ); }
@@ -2346,7 +2349,8 @@ static void gen_mtfsb0(DisasContext *ctx)tcg_temp_free_i32 (t0); }if (unlikely (Rc (ctx->opcode) !=0 )) { -tcg_gen_shri_i32 (cpu_crf[1 ], cpu_fpscr,FPSCR_OX ); +tcg_gen_trunc_tl_i32 (cpu_crf[1 ], cpu_fpscr); +tcg_gen_shri_i32 (cpu_crf[1 ], cpu_crf[1 ],FPSCR_OX ); } }
@@ -2371,7 +2375,8 @@ static void gen_mtfsb1(DisasContext *ctx)tcg_temp_free_i32 (t0); }if (unlikely (Rc (ctx->opcode) !=0 )) { -tcg_gen_shri_i32 (cpu_crf[1 ], cpu_fpscr,FPSCR_OX ); +tcg_gen_trunc_tl_i32 (cpu_crf[1 ], cpu_fpscr); +tcg_gen_shri_i32 (cpu_crf[1 ], cpu_crf[1 ],FPSCR_OX ); }/* We can raise a differed exception */ gen_helper_float_check_status (cpu_env);
@@ -2397,7 +2402,8 @@ static void gen_mtfsf(DisasContext *ctx)gen_helper_store_fpscr (cpu_env, cpu_fpr[rB (ctx->opcode)], t0);tcg_temp_free_i32 (t0);if (unlikely (Rc (ctx->opcode) !=0 )) { -tcg_gen_shri_i32 (cpu_crf[1 ], cpu_fpscr,FPSCR_OX ); +tcg_gen_trunc_tl_i32 (cpu_crf[1 ], cpu_fpscr); +tcg_gen_shri_i32 (cpu_crf[1 ], cpu_crf[1 ],FPSCR_OX ); }/* We can raise a differed exception */ gen_helper_float_check_status (cpu_env);
@@ -2425,7 +2431,8 @@ static void gen_mtfsfi(DisasContext *ctx)tcg_temp_free_i64 (t0);tcg_temp_free_i32 (t1);if (unlikely (Rc (ctx->opcode) !=0 )) { -tcg_gen_shri_i32 (cpu_crf[1 ], cpu_fpscr,FPSCR_OX ); +tcg_gen_trunc_tl_i32 (cpu_crf[1 ], cpu_fpscr); +tcg_gen_shri_i32 (cpu_crf[1 ], cpu_crf[1 ],FPSCR_OX ); }/* We can raise a differed exception */ gen_helper_float_check_status (cpu_env);
@@ -9463,7 +9470,7 @@ void cpu_dump_state (CPUPPCState *env, FILE *f, fprintf_function cpu_fprintf,if ((i & (RFPL -1 )) == (RFPL -1 ))cpu_fprintf (f,"\n" ); } -cpu_fprintf (f,"FPSCR %08x\n" , env->fpscr); +cpu_fprintf (f,"FPSCR " TARGET_FMT_lx"\n" , env->fpscr);#if !defined(CONFIG_USER_ONLY ) cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n",
Signature · 1 line
1.7.10.4
PATCH 2/8 pseries: Clean up inconsistent variable name in xics.c
In reply to David GibsonThroughout xics.c 'nr' is used to refer to a global interrupt number, and 'server' is used to refer to an interrupt server number (i.e. CPU number). Except in icp_set_mfrr(), where 'nr' is used as a server number. Fix this confusing inconsistency.
--- hw/xics.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/xics.c +3 -3
@@ -108,13 +108,13 @@ static void icp_set_cppr(struct icp_state *icp, int server, uint8_t cppr) } } -static void icp_set_mfrr (struct icp_state *icp,int nr,uint8_t mfrr) +static void icp_set_mfrr (struct icp_state *icp,int server,uint8_t mfrr) { -struct icp_server_state *ss = icp->ss + nr; +struct icp_server_state *ss = icp->ss + server; ss->mfrr = mfrr;if (mfrr <CPPR (ss)) { -icp_check_ipi (icp, nr); +icp_check_ipi (icp, server); } }
Signature · 1 line
1.7.10.4
PATCH 3/8 pseries: Use #define for XICS base irq number
In reply to David GibsonFrom: Ben Herrenschmidt <[email protected]>
Currently the lowest "real" irq number for the XICS irq controller (as opposed to numbers reserved for IPIs and other special purposes) is hard coded as 16 in two places - in xics_system_init() and in spapr.c.
As well as being generally bad practice, we're going to need to change this number soon to fit in with the in-kernel XICS implementation. This patch adds a #define for this number to avoid future breakage.
--- hw/spapr.c | 2 +- hw/xics.c | 2 +- hw/xics.h | 1 + 3 files changed, 3 insertions(+), 2 deletions(-)
hw/spapr.c +1 -1
@@ -798,7 +798,7 @@ static void ppc_spapr_init(ram_addr_t ram_size,/* Set up Interrupt Controller */ spapr->icp =xics_system_init (XICS_IRQS ); - spapr->next_irq =16 ; + spapr->next_irq =XICS_IRQ_BASE ;/* Set up EPOW events infrastructure */ spapr_events_init (spapr);
hw/xics.c +1 -1
@@ -548,7 +548,7 @@ struct icp_state *xics_system_init(int nr_irqs) ics =g_malloc0 (sizeof (*ics)); ics->nr_irqs = nr_irqs; - ics->offset =16 ; + ics->offset =XICS_IRQ_BASE ; ics->irqs =g_malloc0 (nr_irqs *sizeof (struct ics_irq_state )); icp->ics = ics;
hw/xics.h +1 -0
@@ -28,6 +28,7 @@#define __XICS_H__#define XICS_IPI 0x2 +#define XICS_IRQ_BASE 0x10struct icp_state ;
Signature · 1 line
1.7.10.4
PATCH 4/8 pseries: Cleanup duplications of ics_valid_irq() code
In reply to David GibsonA couple of places in xics.c open-coded the same logic as is already implemented in ics_valid_irq(). This patch fixes the code duplication.
--- hw/xics.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
hw/xics.c +2 -4
@@ -326,8 +326,7 @@ static void ics_eoi(struct ics_state *ics, int nr)qemu_irq xics_get_qirq (struct icp_state *icp,int irq) { -if ((irq < icp->ics->offset) - || (irq >= (icp->ics->offset + icp->ics->nr_irqs))) { +if (!ics_valid_irq (icp->ics, irq)) {return NULL ; }
@@ -336,8 +335,7 @@ qemu_irq xics_get_qirq(struct icp_state *icp, int irq)void xics_set_irq_type (struct icp_state *icp,int irq,bool lsi) { -assert ((irq >= icp->ics->offset) - && (irq < (icp->ics->offset + icp->ics->nr_irqs))); +assert (ics_valid_irq (icp->ics, irq)); icp->ics->irqs[irq - icp->ics->offset].lsi = lsi; }
Signature · 1 line
1.7.10.4
PATCH 5/8 pseries: Move XICS initialization before cpu initialization
In reply to David GibsonFrom: Ben Herrenschmidt <[email protected]>
Currently, the pseries machine initializes the cpus, then the XICS interrupt controller. However, to support the upcoming in-kernel XICS implementation we will need to initialize the irq controller before the vcpus. This patch makes the necesssary rearrangement. This means the xics init code can no longer auto-detect the number of cpus ("interrupt servers" in XICS terminology) and so we must pass that in explicitly from the platform code.
--- hw/spapr.c | 11 +++++++---- hw/xics.c | 52 +++++++++++++++++++++++----------------------------- hw/xics.h | 3 ++- 3 files changed, 32 insertions(+), 34 deletions(-)
hw/spapr.c +7 -4
@@ -744,6 +744,11 @@ static void ppc_spapr_init(ram_addr_t ram_size, spapr->htab_shift++; } +/* Set up Interrupt Controller before we create the VCPUs */ + spapr->icp =xics_system_init (smp_cpus *kvmppc_smt_threads () / smp_threads, +XICS_IRQS ); + spapr->next_irq =XICS_IRQ_BASE ; +/* init CPUs */ if (cpu_model ==NULL ) { cpu_model =kvm_enabled () ?"host" :"POWER7" ;
@@ -756,6 +761,8 @@ static void ppc_spapr_init(ram_addr_t ram_size, } env = &cpu->env; +xics_cpu_setup (spapr->icp, env); +/* Set time-base frequency to 512 MHz */ cpu_ppc_tb_init (env,TIMEBASE_FREQ );
@@ -796,10 +803,6 @@ static void ppc_spapr_init(ram_addr_t ram_size,g_free (filename); -/* Set up Interrupt Controller */ - spapr->icp =xics_system_init (XICS_IRQS ); - spapr->next_irq =XICS_IRQ_BASE ; -/* Set up EPOW events infrastructure */ spapr_events_init (spapr);
hw/xics.c +23 -29
65 lines not on this page · raw message
hw/xics.h +2 -1
@@ -35,6 +35,7 @@ struct icp_state;qemu_irq xics_get_qirq (struct icp_state *icp,int irq);void xics_set_irq_type (struct icp_state *icp,int irq,bool lsi); -struct icp_state *xics_system_init (int nr_irqs); +struct icp_state *xics_system_init (int nr_servers,int nr_irqs); +void xics_cpu_setup (struct icp_state *icp,CPUPPCState *env);#endif /* __XICS_H__ */
Signature · 1 line
1.7.10.4
PATCH 6/8 pseries: Return the token when we register an RTAS call
In reply to David GibsonFrom: Michael Ellerman <[email protected]>
The kernel will soon be able to service some RTAS calls. However the choice of tokens will still be up to userspace. To support this have spapr_rtas_register() return the token that is allocated for an RTAS call, that allows the calling code to tell the kernel what the token value is.
--- hw/spapr.h | 2 +- hw/spapr_rtas.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
hw/spapr.h +1 -1
@@ -320,7 +320,7 @@ static inline void rtas_st(target_ulong phys, int n, uint32_t val)typedef void (*spapr_rtas_fn )(sPAPREnvironment *spapr,uint32_t token,uint32_t nargs,target_ulong args,uint32_t nret,target_ulong rets); -void spapr_rtas_register (const char *name,spapr_rtas_fn fn); +int spapr_rtas_register (const char *name,spapr_rtas_fn fn);target_ulong spapr_rtas_call (sPAPREnvironment *spapr,uint32_t token,uint32_t nargs,target_ulong args,uint32_t nret,target_ulong rets);
hw/spapr_rtas.c +2 -2
@@ -239,7 +239,7 @@ target_ulong spapr_rtas_call(sPAPREnvironment *spapr,return H_PARAMETER ; } -void spapr_rtas_register (const char *name,spapr_rtas_fn fn) +int spapr_rtas_register (const char *name,spapr_rtas_fn fn) {int i;
@@ -255,7 +255,7 @@ void spapr_rtas_register(const char *name, spapr_rtas_fn fn) rtas_next->name = name; rtas_next->fn = fn; - rtas_next++; +return (rtas_next++ - rtas_table) +TOKEN_BASE ; } int spapr_rtas_device_tree_setup(void *fdt, target_phys_addr_t rtas_addr,
Signature · 1 line
1.7.10.4
PATCH 7/8 pseries: Allow RTAS tokens without a qemu handler
In reply to David GibsonFrom: Ben Herrenschmidt <[email protected]>
Kernel-based RTAS calls will not have a qemu handler, but will still be registered in qemu in order to be assigned a token number and appear in the device-tree.
Let's test for the name being NULL rather than the handler when deciding to skip an entry while building the device-tree
--- hw/spapr_rtas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/spapr_rtas.c +1 -1
@@ -298,7 +298,7 @@ int spapr_rtas_device_tree_setup(void *fdt, target_phys_addr_t rtas_addr,for (i =0 ; i <TOKEN_MAX ; i++) {struct rtas_call *call = &rtas_table[i]; -if (!call->fn) { +if (!call->name) {continue ; }
Signature · 1 line
1.7.10.4
PATCH 8/8 pseries: Add tracepoints to the XICS interrupt controller
In reply to David GibsonThis patch adds tracing / debugging calls to the XICS interrupt controller implementation used on the pseries machine.
--- hw/xics.c | 23 ++++++++++++++++++++--- trace-events | 13 +++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-)
hw/xics.c +20 -3
@@ -26,6 +26,7 @@*/ #include "hw.h" +#include "trace.h" #include "hw/spapr.h" #include "hw/xics.h"
@@ -66,6 +67,8 @@ static void icp_check_ipi(struct icp_state *icp, int server)return ; } +trace_xics_icp_check_ipi (server, ss->mfrr); +if (XISR (ss)) {ics_reject (icp->ics,XISR (ss)); }
@@ -120,11 +123,13 @@ static void icp_set_mfrr(struct icp_state *icp, int server, uint8_t mfrr)static uint32_t icp_accept (struct icp_server_state *ss) { -uint32_t xirr; +uint32_t xirr = ss->xirr;qemu_irq_lower (ss->output); - xirr = ss->xirr; ss->xirr = ss->pending_priority <<24 ; + +trace_xics_icp_accept (xirr, ss->xirr); +return xirr; }
@@ -134,6 +139,7 @@ static void icp_eoi(struct icp_state *icp, int server, uint32_t xirr)/* Send EOI -> ICS */ ss->xirr = (ss->xirr & ~CPPR_MASK ) | (xirr &CPPR_MASK ); +trace_xics_icp_eoi (server, xirr, ss->xirr);ics_eoi (icp->ics, xirr &XISR_MASK );if (!XISR (ss)) {icp_resend (icp, server);
@@ -144,6 +150,8 @@ static void icp_irq(struct icp_state *icp, int server, int nr, uint8_t priority) {struct icp_server_state *ss = icp->ss + server; +trace_xics_icp_irq (server, nr, priority); +if ((priority >=CPPR (ss)) || (XISR (ss) && (ss->pending_priority <= priority))) {ics_reject (icp->ics, nr);
@@ -153,6 +161,7 @@ static void icp_irq(struct icp_state *icp, int server, int nr, uint8_t priority) } ss->xirr = (ss->xirr & ~XISR_MASK ) | (nr &XISR_MASK ); ss->pending_priority = priority; +trace_xics_icp_raise (ss->xirr, ss->pending_priority);qemu_irq_raise (ss->output); } }
@@ -217,10 +226,12 @@ static void set_irq_msi(struct ics_state *ics, int srcno, int val) {struct ics_irq_state *irq = ics->irqs + srcno; +trace_xics_set_irq_msi (srcno, srcno + ics->offset); +if (val) {if (irq->priority ==0xff ) { irq->status |=XICS_STATUS_MASKED_PENDING ; -/* masked pending */ ; +trace_xics_masked_pending (); }else {icp_irq (ics->icp, irq->server, srcno + ics->offset, irq->priority); }
@@ -231,6 +242,7 @@ static void set_irq_lsi(struct ics_state *ics, int srcno, int val) {struct ics_irq_state *irq = ics->irqs + srcno; +trace_xics_set_irq_lsi (srcno, srcno + ics->offset);if (val) { irq->status |=XICS_STATUS_ASSERTED ; }else {
@@ -279,6 +291,8 @@ static void ics_write_xive(struct ics_state *ics, int nr, int server, irq->priority = priority; irq->saved_priority = saved_priority; +trace_xics_ics_write_xive (nr, srcno, server, priority); +if (irq->lsi) {write_xive_lsi (ics, srcno); }else {
@@ -290,6 +304,7 @@ static void ics_reject(struct ics_state *ics, int nr) {struct ics_irq_state *irq = ics->irqs + nr - ics->offset; +trace_xics_ics_reject (nr, nr - ics->offset); irq->status |=XICS_STATUS_REJECTED ;/* Irrelevant but harmless for LSI */ irq->status &= ~XICS_STATUS_SENT ;/* Irrelevant but harmless for MSI */ }
@@ -315,6 +330,8 @@ static void ics_eoi(struct ics_state *ics, int nr)int srcno = nr - ics->offset;struct ics_irq_state *irq = ics->irqs + srcno; +trace_xics_ics_eoi (nr); +if (irq->lsi) { irq->status &= ~XICS_STATUS_SENT ; }
trace-events +13 -0
@@ -1001,3 +1001,16 @@ spapr_pci_rtas_ibm_change_msi(unsigned func, unsigned req) "func %u, requested % spapr_pci_rtas_ibm_query_interrupt_source_number(unsigned ioa, unsigned intr) "queries for #%u, IRQ%u" spapr_pci_msi_write(uint64_t addr, uint64_t data, uint32_t dt_irq) "@%"PRIx64"<=%"PRIx64" IRQ %u" spapr_pci_lsi_set(const char *busname, int pin, uint32_t irq) "%s PIN%d IRQ %u" + +# hw/xics.c +xics_icp_check_ipi(int server, uint8_t mfrr) "CPU %d can take IPI mfrr=%#x" +xics_icp_accept(uint32_t old_xirr, uint32_t new_xirr) "icp_accept: XIRR %#"PRIx32"->%#"PRIx32 +xics_icp_eoi(int server, uint32_t xirr, uint32_t new_xirr) "icp_eoi: server %d given XIRR %#"PRIx32" new XIRR %#"PRIx32 +xics_icp_irq(int server, int nr, uint8_t priority) "cpu %d trying to deliver irq %#"PRIx32" priority %#x" +xics_icp_raise(uint32_t xirr, uint8_t pending_priority) "raising IRQ new XIRR=%#x new pending priority=%#x" +xics_set_irq_msi(int srcno, int nr) "set_irq_msi: srcno %d [irq %#x]" +xics_masked_pending(void) "set_irq_msi: masked pending" +xics_set_irq_lsi(int srcno, int nr) "set_irq_lsi: srcno %d [irq %#x]" +xics_ics_write_xive(int nr, int srcno, int server, uint8_t priority) "ics_write_xive: irq %#x [src %d] server %#x prio %#x" +xics_ics_reject(int nr, int srcno) "reject irq %#x [src %d]" +xics_ics_eoi(int nr) "ics_eoi: irq %#x"
Signature · 1 line
1.7.10.4