Implement emulation of pSeries logical partitions (v6)
cover Implement emulation of pSeries logical partitions (v6)
This patch series adds a "pseries" machine to qemu, allowing it to emulate IBM pSeries logical partitions. More specifically it implements the interface defined by the "PowerPC Architecture Platform Requirements" document (PAPR, or sPAPR for short).
Along the way we add a bunch of support for more modern ppc CPUs than are currently supported. It also makes some significant cleanups to the translation code for hash page table based ppc MMUs.
Please apply.
---
Changes since v5 of this series:
* Include source for SLOF as a git submodule
* Move our private hcalls (well. only one so far) to a range explicitly reserved by PAPR for this purpose.
* Allocate an ample 1024 irqs in the XICS controller, rather than having a somewhat dubious calculation of precisely how many we need.
Changes since v4 of this series:
* Fix build breakages for powerpc targets other than ppc64 full system.
* Since the pseries platform requires libfdt, only compile it when configured with --enable-fdt
* Give an informative error if invoked with insufficient guest RAM to run the partition firmware. Without this, giving insufficient RAM
- such as qemu's default 64M - would lead to the firmware failing cryptically partway through boot.
Changes since v3 of this series:
* Many, many checkpatch fixups
* Integrated feedback from qemu-devel list
* Added in-partition SLOF firmware
Changes since v2 of this series:
* Assorted bugfixes and cleanups.
Changes since v1 of this series:
* numerous coding style fixups
* incorporated most review comments from initial version
* moved to a wholly dynamic hypercall registration scheme
* assorted other cleanups
* many more patches implementing VIO devices
PATCH 1/27 Clean up PowerPC SLB handling code
Currently the SLB information when emulating a PowerPC 970 is storeed in a structure with the unhelpfully named fields 'tmp' and 'tmp64'. While the layout in these fields does match the description of the SLB in the architecture document, it is not convenient either for looking up the SLB, or for emulating the slbmte instruction.
This patch, therefore, reorganizes the SLB entry structure to be divided in the the "ESID related" and "VSID related" fields as they are divided in instructions accessing the SLB.
In addition to making the code smaller and more readable, this will make it easier to implement for the 1TB segments used in more recent PowerPC chips.
--- target-ppc/cpu.h | 29 +++++++- target-ppc/helper.c | 178 ++++++++++++++---------------------------------- target-ppc/helper.h | 1 - target-ppc/op_helper.c | 9 +-- 4 files changed, 80 insertions(+), 137 deletions(-)
target-ppc/cpu.h +26 -3
@@ -43,6 +43,8 @@# define TARGET_VIRT_ADDR_SPACE_BITS 64#endif +#define TARGET_PAGE_BITS_16M 24 +#else /* defined (TARGET_PPC64) */ /* PowerPC 32 definitions */ #define TARGET_LONG_BITS 32
@@ -359,10 +361,31 @@ union ppc_tlb_t {typedef struct ppc_slb_t ppc_slb_t ;struct ppc_slb_t { -uint64_t tmp64; -uint32_t tmp; +uint64_t esid; +uint64_t vsid; }; +/* Bits in the SLB ESID word */ +#define SLB_ESID_ESID 0xFFFFFFFFF0000000ULL +#define SLB_ESID_V 0x0000000008000000ULL/* valid */ + +/* Bits in the SLB VSID word */ +#define SLB_VSID_SHIFT 12 +#define SLB_VSID_SSIZE_SHIFT 62 +#define SLB_VSID_B 0xc000000000000000ULL +#define SLB_VSID_B_256M 0x0000000000000000ULL +#define SLB_VSID_VSID 0x3FFFFFFFFFFFF000ULL +#define SLB_VSID_KS 0x0000000000000800ULL +#define SLB_VSID_KP 0x0000000000000400ULL +#define SLB_VSID_N 0x0000000000000200ULL/* no-execute */ +#define SLB_VSID_L 0x0000000000000100ULL +#define SLB_VSID_C 0x0000000000000080ULL/* class */ +#define SLB_VSID_LP 0x0000000000000030ULL +#define SLB_VSID_ATTR 0x0000000000000FFFULL + +#define SEGMENT_SHIFT_256M 28 +#define SEGMENT_MASK_256M (~((1ULL << SEGMENT_SHIFT_256M) - 1)) +/*****************************************************************************/ /* Machine state register bits definition */ #define MSR_SF 63/* Sixty-four-bit mode hflags */
@@ -755,7 +778,7 @@ void ppc_store_sdr1 (CPUPPCState *env, target_ulong value);void ppc_store_asr (CPUPPCState *env,target_ulong value);target_ulong ppc_load_slb (CPUPPCState *env,int slb_nr);target_ulong ppc_load_sr (CPUPPCState *env,int sr_nr); -void ppc_store_slb (CPUPPCState *env,target_ulong rb,target_ulong rs); +int ppc_store_slb (CPUPPCState *env,target_ulong rb,target_ulong rs);#endif /* defined(TARGET_PPC64) */ void ppc_store_sr (CPUPPCState *env,int srnum,target_ulong value);#endif /* !defined(CONFIG_USER_ONLY) */
target-ppc/helper.c +50 -126
238 lines not on this page · raw message
target-ppc/helper.h +0 -1
@@ -340,7 +340,6 @@ DEF_HELPER_1(74xx_tlbi, void, tl) DEF_HELPER_FLAGS_0(tlbia, TCG_CALL_CONST, void) DEF_HELPER_FLAGS_1(tlbie, TCG_CALL_CONST, void, tl)#if defined(TARGET_PPC64 ) -DEF_HELPER_FLAGS_1(load_slb, TCG_CALL_CONST, tl, tl) DEF_HELPER_FLAGS_2(store_slb, TCG_CALL_CONST, void, tl, tl) DEF_HELPER_FLAGS_0(slbia, TCG_CALL_CONST, void)DEF_HELPER_FLAGS_1 (slbie,TCG_CALL_CONST , void, tl)
target-ppc/op_helper.c +3 -6
@@ -3746,14 +3746,11 @@ void helper_store_sr (target_ulong sr_num, target_ulong val)/* SLB management */ #if defined(TARGET_PPC64 ) -target_ulong helper_load_slb (target_ulong slb_nr) -{ -return ppc_load_slb (env, slb_nr); -} -void helper_store_slb (target_ulong rb,target_ulong rs) { -ppc_store_slb (env, rb, rs); +if (ppc_store_slb (env, rb, rs) <0 ) { +helper_raise_exception_err (POWERPC_EXCP_PROGRAM ,POWERPC_EXCP_INVAL ); + } }void helper_slbia (void )
Signature · 1 line
1.7.1
PATCH 2/27 Allow qemu_devtree_setprop() to take arbitrary values
In reply to David GibsonFrom: David Gibson <[email protected]>
Currently qemu_devtree_setprop() expects the new property value to be given as a uint32_t *. While property values consisting of u32s are common, in general they can have any bytestring value.
Therefore, this patch alters the function to take a void * instead, allowing callers to easily give anything as the property value.
--- device_tree.c | 2 +- device_tree.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
device_tree.c +1 -1
@@ -74,7 +74,7 @@ fail: }int qemu_devtree_setprop (void *fdt,const char *node_path, -const char *property,uint32_t *val_array,int size) +const char *property,void *val_array,int size) {int offset;
device_tree.h +1 -1
@@ -17,7 +17,7 @@void *load_device_tree (const char *filename_path,int *sizep);int qemu_devtree_setprop (void *fdt,const char *node_path, -const char *property,uint32_t *val_array,int size); +const char *property,void *val_array,int size);int qemu_devtree_setprop_cell (void *fdt,const char *node_path,const char *property,uint32_t val); int qemu_devtree_setprop_string(void *fdt, const char *node_path,
Signature · 1 line
1.7.1
PATCH 3/27 Add a hook to allow hypercalls to be emulated on PowerPC
In reply to David GibsonPowerPC and POWER chips since the POWER4 and 970 have a special hypervisor mode, and a corresponding form of the system call instruction which traps to the hypervisor.
qemu currently has stub implementations of hypervisor mode. That is, the outline is there to allow qemu to run a PowerPC hypervisor under emulation. There are a number of details missing so this won't actually work at present, but the idea is there.
What there is no provision at all, is for qemu to instead emulate the hypervisor itself. That is to have hypercalls trap into qemu and their result be emulated from qemu, rather than running hypervisor code within the emulated system.
Hypervisor hardware aware KVM implementations are in the works and it would be useful for debugging and development to also allow full emulation of the same para-virtualized guests as such a KVM.
Therefore, this patch adds a hook which will allow a machine to set up emulation of hypervisor calls.
--- target-ppc/cpu.h | 2 ++ target-ppc/helper.c | 8 ++++++++ 2 files changed, 10 insertions(+), 0 deletions(-)
target-ppc/cpu.h +2 -0
@@ -1646,4 +1646,6 @@ static inline void cpu_set_tls(CPUState *env, target_ulong newtls) #endif } +extern void (*cpu_ppc_hypercall)(CPUState *); +#endif /* !defined (__CPU_PPC_H__) */
target-ppc/helper.c +8 -0
@@ -70,6 +70,10 @@# define LOG_EXCP (...) do { } while (0)#endif +/*****************************************************************************/ +/* PowerPC Hypercall emulation */ + +void (*cpu_ppc_hypercall)(CPUState *);/*****************************************************************************/ /* PowerPC MMU emulation */
@@ -2152,6 +2156,10 @@ static inline void powerpc_excp(CPUState *env, int excp_model, int excp)case POWERPC_EXCP_SYSCALL :/* System call exception */ dump_syscall (env); lev = env->error_code; +if ((lev ==1 ) && cpu_ppc_hypercall) { +cpu_ppc_hypercall (env); +return ; + }if (lev ==1 || (lpes0 ==0 && lpes1 ==0 )) new_msr |= (target_ulong )MSR_HVB ; goto store_next;
Signature · 1 line
1.7.1
PATCH 4/27 Implement PowerPC slbmfee and slbmfev instructions
In reply to David GibsonFor a 64-bit PowerPC target, qemu correctly implements translation through the segment lookaside buffer. Likewise it supports the slbmte instruction which is used to load entries into the SLB.
However, it does not emulate the slbmfee and slbmfev instructions which read SLB entries back into registers. Because these are only occasionally used in guests (mostly for debugging) we get away with it.
However, given the recent SLB cleanups, it becomes quite easy to implement these, and thereby allow, amongst other things, a guest Linux to use xmon's command to dump the SLB.
--- target-ppc/cpu.h | 2 ++ target-ppc/helper.c | 26 ++++++++++++++++++++++++++ target-ppc/helper.h | 2 ++ target-ppc/op_helper.c | 20 ++++++++++++++++++++ target-ppc/translate.c | 31 ++++++++++++++++++++++++++++++- 5 files changed, 80 insertions(+), 1 deletions(-)
target-ppc/cpu.h +2 -0
@@ -779,6 +779,8 @@ void ppc_store_asr (CPUPPCState *env, target_ulong value);target_ulong ppc_load_slb (CPUPPCState *env,int slb_nr);target_ulong ppc_load_sr (CPUPPCState *env,int sr_nr);int ppc_store_slb (CPUPPCState *env,target_ulong rb,target_ulong rs); +int ppc_load_slb_esid (CPUPPCState *env,target_ulong rb,target_ulong *rt); +int ppc_load_slb_vsid (CPUPPCState *env,target_ulong rb,target_ulong *rt);#endif /* defined(TARGET_PPC64) */ void ppc_store_sr (CPUPPCState *env,int srnum,target_ulong value);#endif /* !defined(CONFIG_USER_ONLY) */
target-ppc/helper.c +26 -0
@@ -774,6 +774,32 @@ int ppc_store_slb (CPUPPCState *env, target_ulong rb, target_ulong rs) return 0; } + +int ppc_load_slb_esid (CPUPPCState *env,target_ulong rb,target_ulong *rt) +{ +int slot = rb &0xfff ; +ppc_slb_t *slb = &env->slb[slot]; + +if (slot >= env->slb_nr) { +return -1 ; + } + + *rt = slb->esid; +return 0 ; +} + +int ppc_load_slb_vsid (CPUPPCState *env,target_ulong rb,target_ulong *rt) +{ +int slot = rb &0xfff ; +ppc_slb_t *slb = &env->slb[slot]; + +if (slot >= env->slb_nr) { +return -1 ; + } + + *rt = slb->vsid; +return 0 ; +}#endif /* defined(TARGET_PPC64) */ /* Perform segment based translation */
target-ppc/helper.h +2 -0
@@ -341,6 +341,8 @@ DEF_HELPER_FLAGS_0(tlbia, TCG_CALL_CONST, void) DEF_HELPER_FLAGS_1(tlbie, TCG_CALL_CONST, void, tl)#if defined(TARGET_PPC64 ) DEF_HELPER_FLAGS_2(store_slb, TCG_CALL_CONST, void, tl, tl) +DEF_HELPER_1(load_slb_esid, tl, tl) +DEF_HELPER_1(load_slb_vsid, tl, tl) DEF_HELPER_FLAGS_0(slbia, TCG_CALL_CONST, void) DEF_HELPER_FLAGS_1(slbie, TCG_CALL_CONST, void, tl)#endif
target-ppc/op_helper.c +20 -0
@@ -3753,6 +3753,26 @@ void helper_store_slb (target_ulong rb, target_ulong rs) } } +target_ulong helper_load_slb_esid (target_ulong rb) +{ +target_ulong rt; + +if (ppc_load_slb_esid (env, rb, &rt) <0 ) { +helper_raise_exception_err (POWERPC_EXCP_PROGRAM ,POWERPC_EXCP_INVAL ); + } +return rt; +} + +target_ulong helper_load_slb_vsid (target_ulong rb) +{ +target_ulong rt; + +if (ppc_load_slb_vsid (env, rb, &rt) <0 ) { +helper_raise_exception_err (POWERPC_EXCP_PROGRAM ,POWERPC_EXCP_INVAL ); + } +return rt; +} +void helper_slbia (void ) {ppc_slb_invalidate_all (env);
target-ppc/translate.c +30 -1
@@ -4227,6 +4227,33 @@ static void gen_slbmte(DisasContext *ctx)#endif } +static void gen_slbmfee (DisasContext *ctx) +{ +#if defined(CONFIG_USER_ONLY ) +gen_inval_exception (ctx,POWERPC_EXCP_PRIV_REG ); +#else +if (unlikely (!ctx->mem_idx)) { +gen_inval_exception (ctx,POWERPC_EXCP_PRIV_REG ); +return ; + } +gen_helper_load_slb_esid (cpu_gpr[rS (ctx->opcode)], + cpu_gpr[rB (ctx->opcode)]); +#endif +} + +static void gen_slbmfev (DisasContext *ctx) +{ +#if defined(CONFIG_USER_ONLY ) +gen_inval_exception (ctx,POWERPC_EXCP_PRIV_REG ); +#else +if (unlikely (!ctx->mem_idx)) { +gen_inval_exception (ctx,POWERPC_EXCP_PRIV_REG ); +return ; + } +gen_helper_load_slb_vsid (cpu_gpr[rS (ctx->opcode)], + cpu_gpr[rB (ctx->opcode)]); +#endif +}#endif /* defined(TARGET_PPC64) */ /*** Lookaside buffer management ***/
@@ -8300,7 +8327,9 @@ GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,GEN_HANDLER2 (mtsr_64b,"mtsr" ,0x1F ,0x12 ,0x06 ,0x0010F801 ,PPC_SEGMENT_64B ),GEN_HANDLER2 (mtsrin_64b,"mtsrin" ,0x1F ,0x12 ,0x07 ,0x001F0001 ,PPC_SEGMENT_64B ), -GEN_HANDLER2 (slbmte,"slbmte" ,0x1F ,0x12 ,0x0C ,0x00000000 ,PPC_SEGMENT_64B ), +GEN_HANDLER2 (slbmte,"slbmte" ,0x1F ,0x12 ,0x0C ,0x001F0001 ,PPC_SEGMENT_64B ), +GEN_HANDLER2 (slbmfee,"slbmfee" ,0x1F ,0x13 ,0x1C ,0x001F0001 ,PPC_SEGMENT_64B ), +GEN_HANDLER2 (slbmfev,"slbmfev" ,0x1F ,0x13 ,0x1A ,0x001F0001 ,PPC_SEGMENT_64B ), #endifGEN_HANDLER (tlbia,0x1F ,0x12 ,0x0B ,0x03FFFC01 ,PPC_MEM_TLBIA ), GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE),
Signature · 1 line
1.7.1
PATCH 5/27 Implement missing parts of the logic for the POWER PURR
In reply to David GibsonThe PURR (Processor Utilization Resource Register) is a register found on recent POWER CPUs. The guts of implementing it at least enough to get by are already present in qemu, however some of the helper functions needed to actually wire it up are missing.
This patch adds the necessary glue, so that the PURR can be wired up when we implement newer POWER CPU targets which include it.
--- target-ppc/helper.h | 1 + target-ppc/op_helper.c | 7 +++++++ target-ppc/translate_init.c | 8 ++++++++ 3 files changed, 16 insertions(+), 0 deletions(-)
target-ppc/helper.h +1 -0
@@ -376,6 +376,7 @@ DEF_HELPER_0(load_601_rtcu, tl)#if !defined(CONFIG_USER_ONLY )#if defined(TARGET_PPC64 ) DEF_HELPER_1(store_asr, void, tl) +DEF_HELPER_0(load_purr, tl)#endif DEF_HELPER_1(store_sdr1, void, tl)DEF_HELPER_1 (store_tbl, void, tl)
target-ppc/op_helper.c +7 -0
@@ -86,6 +86,13 @@ target_ulong helper_load_atbu (void)return cpu_ppc_load_atbu (env); } +#if defined(TARGET_PPC64 ) && !defined(CONFIG_USER_ONLY ) +target_ulong helper_load_purr (void ) +{ +return (target_ulong )cpu_ppc_load_purr (env); +} +#endif +target_ulong helper_load_601_rtcl (void ) {return cpu_ppc601_load_rtcl (env);
target-ppc/translate_init.c +8 -0
@@ -251,6 +251,14 @@ static void spr_write_atbu (void *opaque, int sprn, int gprn) {gen_helper_store_atbu (cpu_gpr[gprn]); } + +#if defined(TARGET_PPC64 ) +__attribute__ (( unused )) +static void spr_read_purr (void *opaque,int gprn,int sprn) +{ +gen_helper_load_purr (cpu_gpr[gprn]); +} +#endif #endif #if !defined(CONFIG_USER_ONLY )
Signature · 1 line
1.7.1
PATCH 6/27 Correct ppc popcntb logic, implement popcntw and popcntd
In reply to David GibsonFrom: David Gibson <[email protected]>
qemu already includes support for the popcntb instruction introduced in POWER5 (although it doesn't actually allow you to choose POWER5).
However, the logic is slightly incorrect: it will generate results truncated to 32-bits when the CPU is in 32-bit mode. This is not normal for powerpc - generally arithmetic instructions on a 64-bit powerpc cpu will generate full 64 bit results, it's just that only the low 32 bits will be significant for condition codes.
This patch corrects this nit, which actually simplifies the code slightly.
In addition, this patch implements the popcntw and popcntd instructions added in POWER7, in preparation for allowing POWER7 as an emulated CPU.
--- target-ppc/cpu.h | 2 + target-ppc/helper.h | 3 +- target-ppc/op_helper.c | 55 +++++++++++++++++++++++++++++++++++++++++++---- target-ppc/translate.c | 20 +++++++++++++---- 4 files changed, 69 insertions(+), 11 deletions(-)
target-ppc/cpu.h +2 -0
@@ -1505,6 +1505,8 @@ enum {PPC_DCRX =0x2000000000000000ULL ,/* user-mode DCR access, implemented in PowerPC 460 */ PPC_DCRUX =0x4000000000000000ULL , +/* popcntw and popcntd instructions */ + PPC_POPCNTWD = 0x8000000000000000ULL, };/*****************************************************************************/
target-ppc/helper.h +2 -1
@@ -38,10 +38,11 @@ DEF_HELPER_2(mulldo, i64, i64, i64) DEF_HELPER_FLAGS_1(cntlzw, TCG_CALL_CONST | TCG_CALL_PURE, tl, tl) DEF_HELPER_FLAGS_1(popcntb, TCG_CALL_CONST | TCG_CALL_PURE, tl, tl) +DEF_HELPER_FLAGS_1(popcntw, TCG_CALL_CONST | TCG_CALL_PURE, tl, tl) DEF_HELPER_2(sraw, tl, tl, tl)#if defined(TARGET_PPC64 ) DEF_HELPER_FLAGS_1(cntlzd, TCG_CALL_CONST | TCG_CALL_PURE, tl, tl) -DEF_HELPER_FLAGS_1(popcntb_64, TCG_CALL_CONST | TCG_CALL_PURE, tl, tl) +DEF_HELPER_FLAGS_1(popcntd, TCG_CALL_CONST | TCG_CALL_PURE, tl, tl) DEF_HELPER_2(srad, tl, tl, tl)#endif
target-ppc/op_helper.c +50 -5
68 lines not on this page · raw message
target-ppc/translate.c +15 -5
@@ -1483,13 +1483,21 @@ static void gen_xoris(DisasContext *ctx)/* popcntb : PowerPC 2.03 specification */ static void gen_popcntb (DisasContext *ctx) { +gen_helper_popcntb (cpu_gpr[rA (ctx->opcode)], cpu_gpr[rS (ctx->opcode)]); +} + +static void gen_popcntw (DisasContext *ctx) +{ +gen_helper_popcntw (cpu_gpr[rA (ctx->opcode)], cpu_gpr[rS (ctx->opcode)]); +} +#if defined(TARGET_PPC64 ) -if (ctx->sf_mode) -gen_helper_popcntb_64 (cpu_gpr[rA (ctx->opcode)], cpu_gpr[rS (ctx->opcode)]); - else -#endif -gen_helper_popcntb (cpu_gpr[rA (ctx->opcode)], cpu_gpr[rS (ctx->opcode)]); +/* popcntd: PowerPC 2.06 specification */ +static void gen_popcntd (DisasContext *ctx) +{ +gen_helper_popcntd (cpu_gpr[rA (ctx->opcode)], cpu_gpr[rS (ctx->opcode)]); } +#endif #if defined(TARGET_PPC64 )/* extsw & extsw. */
@@ -8226,7 +8234,9 @@ GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB), +GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD),#if defined(TARGET_PPC64 ) +GEN_HANDLER (popcntd,0x1F ,0x1A ,0x0F ,0x0000F801 ,PPC_POPCNTWD ),GEN_HANDLER (cntlzd,0x1F ,0x1A ,0x01 ,0x00000000 ,PPC_64B ), #endif GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 06/27] Correct ppc popcntb logic, implement popcntw and popcntd
Quoted 96 lines · David Gibson
From: David Gibson <[email protected]>
qemu already includes support for the popcntb instruction introduced in POWER5 (although it doesn't actually allow you to choose POWER5).
However, the logic is slightly incorrect: it will generate results truncated to 32-bits when the CPU is in 32-bit mode. This is not normal for powerpc - generally arithmetic instructions on a 64-bit powerpc cpu will generate full 64 bit results, it's just that only the low 32 bits will be significant for condition codes.
This patch corrects this nit, which actually simplifies the code slightly.
In addition, this patch implements the popcntw and popcntd instructions added in POWER7, in preparation for allowing POWER7 as an emulated CPU.
Signed-off-by David Gibson <[email protected]>--- target-ppc/cpu.h | 2 + target-ppc/helper.h | 3 +- target-ppc/op_helper.c | 55 +++++++++++++++++++++++++++++++++++++++++++---- target-ppc/translate.c | 20 +++++++++++++---- 4 files changed, 69 insertions(+), 11 deletions(-)target-ppc/cpu.h +2
-0@@ -1505,6 +1505,8 @@ enum {PPC_DCRX =0x2000000000000000ULL ,/* user-mode DCR access, implemented in PowerPC 460 */ PPC_DCRUX =0x4000000000000000ULL , +/* popcntw and popcntd instructions */ + PPC_POPCNTWD = 0x8000000000000000ULL, };/*****************************************************************************/ target-ppc/helper.h +2
-1@@ -38,10 +38,11 @@ DEF_HELPER_2(mulldo, i64, i64, i64) DEF_HELPER_FLAGS_1(cntlzw, TCG_CALL_CONST | TCG_CALL_PURE, tl, tl) DEF_HELPER_FLAGS_1(popcntb, TCG_CALL_CONST | TCG_CALL_PURE, tl, tl) +DEF_HELPER_FLAGS_1(popcntw, TCG_CALL_CONST | TCG_CALL_PURE, tl, tl) DEF_HELPER_2(sraw, tl, tl, tl)#if defined(TARGET_PPC64 ) DEF_HELPER_FLAGS_1(cntlzd, TCG_CALL_CONST | TCG_CALL_PURE, tl, tl) -DEF_HELPER_FLAGS_1(popcntb_64, TCG_CALL_CONST | TCG_CALL_PURE, tl, tl) +DEF_HELPER_FLAGS_1(popcntd, TCG_CALL_CONST | TCG_CALL_PURE, tl, tl) DEF_HELPER_2(srad, tl, tl, tl)#endif target-ppc/op_helper.c +33
-0@@ -499,6 +499,50 @@ target_ulong helper_srad (target_ulong value, target_ulong shift) }#endif +#if defined(TARGET_PPC64 ) +target_ulong helper_popcntb (target_ulong val) +{ + val = (val &0x5555555555555555ULL ) + ((val >>1 ) & +0x5555555555555555ULL ); + val = (val &0x3333333333333333ULL ) + ((val >>2 ) & +0x3333333333333333ULL ); + val = (val &0x0f0f0f0f0f0f0f0fULL ) + ((val >>4 ) & +0x0f0f0f0f0f0f0f0fULL ); +return val; +} + +target_ulong helper_popcntw (target_ulong val) +{ + val = (val &0x5555555555555555ULL ) + ((val >>1 ) & +0x5555555555555555ULL ); + val = (val &0x3333333333333333ULL ) + ((val >>2 ) & +0x3333333333333333ULL ); + val = (val &0x0f0f0f0f0f0f0f0fULL ) + ((val >>4 ) & +0x0f0f0f0f0f0f0f0fULL ); + val = (val &0x00ff00ff00ff00ffULL ) + ((val >>8 ) & +0x00ff00ff00ff00ffULL ); + val = (val &0x0000ffff0000ffffULL ) + ((val >>16 ) & +0x0000ffff0000ffffULL ); +return val; +} + +target_ulong helper_popcntd (target_ulong val) +{ + val = (val &0x5555555555555555ULL ) + ((val >>1 ) & +0x5555555555555555ULL ); + val = (val &0x3333333333333333ULL ) + ((val >>2 ) & +0x3333333333333333ULL );
target-ppc/op_helper.c target_ulong helper_srad (target_ulong value, target_ulong shift) · line 544
Quoted 10 lines
target-ppc/op_helper.c +10
-0+ val = (val &0x0f0f0f0f0f0f0f0fULL ) + ((val >>4 ) & +0x0f0f0f0f0f0f0f0fULL ); + val = (val &0x00ff00ff00ff00ffULL ) + ((val >>8 ) & +0x00ff00ff00ff00ffULL ); + val = (val &0x0000ffff0000ffffULL ) + ((val >>16 ) & +0x0000ffff0000ffffULL ); + val = (val &0x00000000ffffffffULL ) + ((val >>32 ) & +0x00000000ffffffffULL ); +return val; +}
I probably arrive a bit late, but note that for this one you can use ctpop64() (from host-utils.h), which also uses a GCC builtin when available.
Quoted 69 lines
target-ppc/op_helper.c +7
-5+#else target_ulong helper_popcntb (target_ulong val) { val = (val &0x55555555 ) + ((val >>1 ) &0x55555555 );@@ -507,12 +551,13 @@ target_ulong helper_popcntb (target_ulong val) return val; } -#if defined(TARGET_PPC64 ) -target_ulong helper_popcntb_64 (target_ulong val) +target_ulong helper_popcntw (target_ulong val) { - val = (val &0x5555555555555555ULL ) + ((val >>1 ) &0x5555555555555555ULL ); - val = (val &0x3333333333333333ULL ) + ((val >>2 ) &0x3333333333333333ULL ); - val = (val &0x0f0f0f0f0f0f0f0fULL ) + ((val >>4 ) &0x0f0f0f0f0f0f0f0fULL ); + val = (val &0x55555555 ) + ((val >>1 ) &0x55555555 ); + val = (val &0x33333333 ) + ((val >>2 ) &0x33333333 ); + val = (val &0x0f0f0f0f ) + ((val >>4 ) &0x0f0f0f0f ); + val = (val &0x00ff00ff ) + ((val >>8 ) &0x00ff00ff ); + val = (val &0x0000ffff ) + ((val >>16 ) &0x0000ffff );return val; }#endif target-ppc/translate.c +15
-5@@ -1483,13 +1483,21 @@ static void gen_xoris(DisasContext *ctx)/* popcntb : PowerPC 2.03 specification */ static void gen_popcntb (DisasContext *ctx) { +gen_helper_popcntb (cpu_gpr[rA (ctx->opcode)], cpu_gpr[rS (ctx->opcode)]); +} + +static void gen_popcntw (DisasContext *ctx) +{ +gen_helper_popcntw (cpu_gpr[rA (ctx->opcode)], cpu_gpr[rS (ctx->opcode)]); +} +#if defined(TARGET_PPC64 ) -if (ctx->sf_mode) -gen_helper_popcntb_64 (cpu_gpr[rA (ctx->opcode)], cpu_gpr[rS (ctx->opcode)]); - else -#endif -gen_helper_popcntb (cpu_gpr[rA (ctx->opcode)], cpu_gpr[rS (ctx->opcode)]); +/* popcntd: PowerPC 2.06 specification */ +static void gen_popcntd (DisasContext *ctx) +{ +gen_helper_popcntd (cpu_gpr[rA (ctx->opcode)], cpu_gpr[rS (ctx->opcode)]); } +#endif #if defined(TARGET_PPC64 )/* extsw & extsw. */ @@ -8226,7 +8234,9 @@ GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB), +GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD),#if defined(TARGET_PPC64 ) +GEN_HANDLER (popcntd,0x1F ,0x1A ,0x0F ,0x0000F801 ,PPC_POPCNTWD ),GEN_HANDLER (cntlzd,0x1F ,0x1A ,0x01 ,0x00000000 ,PPC_64B ), #endif GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),Signature · 1 line
1.7.1
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
Re: [Qemu-devel] [PATCH 06/27] Correct ppc popcntb logic, implement popcntw and popcntd
Quoted 103 lines · Aurelien Jarno
Quoted 102 lines · David Gibson
From: David Gibson <[email protected]>
qemu already includes support for the popcntb instruction introduced in POWER5 (although it doesn't actually allow you to choose POWER5).
However, the logic is slightly incorrect: it will generate results truncated to 32-bits when the CPU is in 32-bit mode. This is not normal for powerpc - generally arithmetic instructions on a 64-bit powerpc cpu will generate full 64 bit results, it's just that only the low 32 bits will be significant for condition codes.
This patch corrects this nit, which actually simplifies the code slightly.
In addition, this patch implements the popcntw and popcntd instructions added in POWER7, in preparation for allowing POWER7 as an emulated CPU.
Signed-off-by David Gibson <[email protected]>---
target-ppc/cpu.h | 2 + target-ppc/helper.h | 3 +- target-ppc/op_helper.c | 55 +++++++++++++++++++++++++++++++++++++++++++---- target-ppc/translate.c | 20 +++++++++++++---- 4 files changed, 69 insertions(+), 11 deletions(-)target-ppc/cpu.h +2
-0@@ -1505,6 +1505,8 @@ enum {PPC_DCRX =0x2000000000000000ULL ,/* user-mode DCR access, implemented in PowerPC 460 */ PPC_DCRUX =0x4000000000000000ULL , +/* popcntw and popcntd instructions */ + PPC_POPCNTWD = 0x8000000000000000ULL, };/*****************************************************************************/ target-ppc/helper.h +2
-1@@ -38,10 +38,11 @@ DEF_HELPER_2(mulldo, i64, i64, i64) DEF_HELPER_FLAGS_1(cntlzw, TCG_CALL_CONST | TCG_CALL_PURE, tl, tl) DEF_HELPER_FLAGS_1(popcntb, TCG_CALL_CONST | TCG_CALL_PURE, tl, tl) +DEF_HELPER_FLAGS_1(popcntw, TCG_CALL_CONST | TCG_CALL_PURE, tl, tl) DEF_HELPER_2(sraw, tl, tl, tl)#if defined(TARGET_PPC64 ) DEF_HELPER_FLAGS_1(cntlzd, TCG_CALL_CONST | TCG_CALL_PURE, tl, tl) -DEF_HELPER_FLAGS_1(popcntb_64, TCG_CALL_CONST | TCG_CALL_PURE, tl, tl) +DEF_HELPER_FLAGS_1(popcntd, TCG_CALL_CONST | TCG_CALL_PURE, tl, tl) DEF_HELPER_2(srad, tl, tl, tl)#endif target-ppc/op_helper.c +39
-0@@ -499,6 +499,50 @@ target_ulong helper_srad (target_ulong value, target_ulong shift) }#endif +#if defined(TARGET_PPC64 ) +target_ulong helper_popcntb (target_ulong val) +{ + val = (val &0x5555555555555555ULL ) + ((val >>1 ) & +0x5555555555555555ULL ); + val = (val &0x3333333333333333ULL ) + ((val >>2 ) & +0x3333333333333333ULL ); + val = (val &0x0f0f0f0f0f0f0f0fULL ) + ((val >>4 ) & +0x0f0f0f0f0f0f0f0fULL ); +return val; +} + +target_ulong helper_popcntw (target_ulong val) +{ + val = (val &0x5555555555555555ULL ) + ((val >>1 ) & +0x5555555555555555ULL ); + val = (val &0x3333333333333333ULL ) + ((val >>2 ) & +0x3333333333333333ULL ); + val = (val &0x0f0f0f0f0f0f0f0fULL ) + ((val >>4 ) & +0x0f0f0f0f0f0f0f0fULL ); + val = (val &0x00ff00ff00ff00ffULL ) + ((val >>8 ) & +0x00ff00ff00ff00ffULL ); + val = (val &0x0000ffff0000ffffULL ) + ((val >>16 ) & +0x0000ffff0000ffffULL ); +return val; +} + +target_ulong helper_popcntd (target_ulong val) +{ + val = (val &0x5555555555555555ULL ) + ((val >>1 ) & +0x5555555555555555ULL ); + val = (val &0x3333333333333333ULL ) + ((val >>2 ) & +0x3333333333333333ULL ); + val = (val &0x0f0f0f0f0f0f0f0fULL ) + ((val >>4 ) & +0x0f0f0f0f0f0f0f0fULL ); + val = (val &0x00ff00ff00ff00ffULL ) + ((val >>8 ) & +0x00ff00ff00ff00ffULL ); + val = (val &0x0000ffff0000ffffULL ) + ((val >>16 ) & +0x0000ffff0000ffffULL );
Quoted 8 lines
target-ppc/op_helper.c target_ulong helper_srad (target_ulong value, target_ulong shift) · line 544
Quoted 4 lines
target-ppc/op_helper.c +4
-0+ val = (val &0x00000000ffffffffULL ) + ((val >>32 ) & +0x00000000ffffffffULL ); +return val; +}I probably arrive a bit late, but note that for this one you can use
ctpop64()(fromhost-utils.h), which also uses a GCC builtin when available.
Ah, nice. David - sounds like a good chance for a follow-up patch :)
Alex
Re: [Qemu-devel] [PATCH 06/27] Correct ppc popcntb logic, implement popcntw and popcntd
Quoted 2 lines · Alexander Graf
Quoted 1 line · Aurelien Jarno
On Fri, Apr 01, 2011 at 03:15:13PM +1100, David Gibson wrote:
[snip]
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
target-ppc/op_helper.c +12
-0+target_ulong helper_popcntd (target_ulong val) +{ + val = (val &0x5555555555555555ULL ) + ((val >>1 ) & +0x5555555555555555ULL ); + val = (val &0x3333333333333333ULL ) + ((val >>2 ) & +0x3333333333333333ULL ); + val = (val &0x0f0f0f0f0f0f0f0fULL ) + ((val >>4 ) & +0x0f0f0f0f0f0f0f0fULL ); + val = (val &0x00ff00ff00ff00ffULL ) + ((val >>8 ) & +0x00ff00ff00ff00ffULL ); + val = (val &0x0000ffff0000ffffULL ) + ((val >>16 ) & +0x0000ffff0000ffffULL );Quoted 8 lines
target-ppc/op_helper.c target_ulong helper_srad (target_ulong value, target_ulong shift) · line 544
Quoted 4 lines
target-ppc/op_helper.c +4
-0+ val = (val &0x00000000ffffffffULL ) + ((val >>32 ) & +0x00000000ffffffffULL ); +return val; +}I probably arrive a bit late, but note that for this one you can use
ctpop64()(fromhost-utils.h), which also uses a GCC builtin when available.
Quoted 1 line
Ah, nice. David - sounds like a good chance for a follow-up patch :)
Done. I'll send it when I next send a batch for merging.
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
PATCH 7/27 Clean up slb_lookup() function
In reply to David GibsonThe slb_lookup() function, used in the ppc translation path returns a number of slb entry fields in reference parameters. However, only one of the two callers of slb_lookup() actually wants this information.
This patch, therefore, makes slb_lookup() return a simple pointer to the located SLB entry (or NULL), and the caller which needs the fields can extract them itself.
--- target-ppc/helper.c | 45 ++++++++++++++++++--------------------------- 1 files changed, 18 insertions(+), 27 deletions(-)
target-ppc/helper.c +18 -27
@@ -676,9 +676,7 @@ static inline int find_pte(CPUState *env, mmu_ctx_t *ctx, int h, int rw, }#if defined(TARGET_PPC64 ) -static inline int slb_lookup (CPUPPCState *env,target_ulong eaddr, -target_ulong *vsid,target_ulong *page_mask, -int *attr,int *target_page_bits) +static inline ppc_slb_t *slb_lookup (CPUPPCState *env,target_ulong eaddr) {uint64_t esid;int n;
@@ -693,19 +691,11 @@ static inline int slb_lookup(CPUPPCState *env, target_ulong eaddr,LOG_SLB ("%s: slot %d %016" PRIx64" %016" PRIx64"\n" , __func__, n, slb->esid, slb->vsid);if (slb->esid == esid) { - *vsid = (slb->vsid &SLB_VSID_VSID ) >>SLB_VSID_SHIFT ; - *page_mask = ~SEGMENT_MASK_256M ; - *attr = slb->vsid &SLB_VSID_ATTR ; -if (target_page_bits) { - *target_page_bits = (slb->vsid &SLB_VSID_L ) - ?TARGET_PAGE_BITS_16M - :TARGET_PAGE_BITS ; - } -return n; +return slb; } } -return -5 ; +return NULL ; }void ppc_slb_invalidate_all (CPUPPCState *env)
@@ -732,18 +722,13 @@ void ppc_slb_invalidate_all (CPUPPCState *env)void ppc_slb_invalidate_one (CPUPPCState *env,uint64_t T0 ) { -target_ulong vsid, page_mask; -int attr; -int n;ppc_slb_t *slb; - n =slb_lookup (env,T0 , &vsid, &page_mask, &attr,NULL ); -if (n <0 ) { + slb =slb_lookup (env,T0 ); +if (!slb) {return ; } - slb = &env->slb[n]; -if (slb->esid &SLB_ESID_V ) { slb->esid &= ~SLB_ESID_V ;
@@ -822,16 +807,22 @@ static inline int get_segment(CPUState *env, mmu_ctx_t *ctx, pr = msr_pr;#if defined(TARGET_PPC64 )if (env->mmu_model &POWERPC_MMU_64 ) { -int attr; +ppc_slb_t *slb;LOG_MMU ("Check SLBs\n" ); - ret =slb_lookup (env, eaddr, &vsid, &page_mask, &attr, - &target_page_bits); -if (ret <0 ) -return ret; - ctx->key = !!(pr ? (attr &SLB_VSID_KP ) : (attr &SLB_VSID_KS )); + slb =slb_lookup (env, eaddr); +if (!slb) { +return -5 ; + } + + vsid = (slb->vsid &SLB_VSID_VSID ) >>SLB_VSID_SHIFT ; + page_mask = ~SEGMENT_MASK_256M ; + target_page_bits = (slb->vsid &SLB_VSID_L ) + ?TARGET_PAGE_BITS_16M :TARGET_PAGE_BITS ; + ctx->key = !!(pr ? (slb->vsid &SLB_VSID_KP ) + : (slb->vsid &SLB_VSID_KS )); ds =0 ; - ctx->nx = !!(attr &SLB_VSID_N ); + ctx->nx = !!(slb->vsid &SLB_VSID_N ); ctx->eaddr = eaddr; vsid_mask =0x00003FFFFFFFFF80ULL ; vsid_sh =7 ;
Signature · 1 line
1.7.1
PATCH 8/27 Parse SDR1 on mtspr instead of at translate time
In reply to David GibsonOn ppc machines with hash table MMUs, the special purpose register SDR1 contains both the base address of the encoded size (hashed) page tables.
At present, we interpret the SDR1 value within the address translation path. But because the encodings of the size for 32-bit and 64-bit are different this makes for a confusing branch on the MMU type with a bunch of curly shifts and masks in the middle of the translate path.
This patch cleans things up by moving the interpretation on SDR1 into the helper function handling the write to the register. This leaves a simple pre-sanitized base address and mask for the hash table in the CPUState structure which is easier to work with in the translation path.
This makes the translation path more readable. It addresses the FIXME comment currently in the mtsdr1 helper, by validating the SDR1 value during interpretation. Finally it opens the way for emulating a pSeries-style partition where the hash table used for translation is not mapped into the guests's RAM.
--- monitor.c | 2 +- target-ppc/cpu.h | 11 +++++- target-ppc/helper.c | 80 ++++++++++++++++++++++++------------------- target-ppc/kvm.c | 2 +- target-ppc/machine.c | 6 ++- target-ppc/translate.c | 2 +- target-ppc/translate_init.c | 7 +--- 7 files changed, 63 insertions(+), 47 deletions(-)
monitor.c +1 -1
@@ -3462,7 +3462,7 @@ static const MonitorDef monitor_defs[] = { { "asr", offsetof(CPUState, asr) }, #endif /* Segment registers */ - { "sdr1", offsetof(CPUState, sdr1) }, + { "sdr1", offsetof(CPUState, spr[SPR_SDR1]) }, { "sr0", offsetof(CPUState, sr[0]) }, { "sr1", offsetof(CPUState, sr[1]) }, { "sr2", offsetof(CPUState, sr[2]) },
target-ppc/cpu.h +10 -1
@@ -359,6 +359,14 @@ union ppc_tlb_t { };#endif +#define SDR_32_HTABORG 0xFFFF0000UL +#define SDR_32_HTABMASK 0x000001FFUL + +#if defined(TARGET_PPC64 ) +#define SDR_64_HTABORG 0xFFFFFFFFFFFC0000ULL +#define SDR_64_HTABSIZE 0x000000000000001FULL +#endif /* defined(TARGET_PPC64 */ +typedef struct ppc_slb_t ppc_slb_t ;struct ppc_slb_t {uint64_t esid;
@@ -642,7 +650,8 @@ struct CPUPPCState {int slb_nr;#endif /* segment registers */ -target_ulong sdr1; +target_phys_addr_t htab_base; +target_phys_addr_t htab_mask;target_ulong sr[32 ];/* BATs */ int nb_BATs;
target-ppc/helper.c +45 -35
140 lines not on this page · raw message
target-ppc/kvm.c +1 -1
@@ -169,7 +169,7 @@ int kvm_arch_get_registers(CPUState *env)#ifdef KVM_CAP_PPC_SEGSTATE if (kvm_check_extension (env->kvm_state,KVM_CAP_PPC_SEGSTATE )) { - env->sdr1 = sregs.u.s.sdr1; +ppc_store_sdr1 (env, sregs.u.s.sdr1);/* Sync SLB */ #ifdef TARGET_PPC64
target-ppc/machine.c +4 -2
@@ -37,7 +37,7 @@ void cpu_save(QEMUFile *f, void *opaque)qemu_put_betls (f, &env->asr);qemu_put_sbe32s (f, &env->slb_nr);#endif -qemu_put_betls (f, &env->sdr1); +qemu_put_betls (f, &env->spr[SPR_SDR1 ]);for (i =0 ; i <32 ; i++)qemu_put_betls (f, &env->sr[i]);for (i =0 ; i <2 ; i++)
@@ -93,6 +93,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id) {CPUState *env = (CPUState *)opaque;unsigned int i, j; +target_ulong sdr1;for (i =0 ; i <32 ; i++)qemu_get_betls (f, &env->gpr[i]);
@@ -124,7 +125,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)qemu_get_betls (f, &env->asr);qemu_get_sbe32s (f, &env->slb_nr);#endif -qemu_get_betls (f, &env->sdr1); +qemu_get_betls (f, &sdr1);for (i =0 ; i <32 ; i++)qemu_get_betls (f, &env->sr[i]);for (i =0 ; i <2 ; i++)
@@ -152,6 +153,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)#endif for (i =0 ; i <1024 ; i++)qemu_get_betls (f, &env->spr[i]); +ppc_store_sdr1 (env, sdr1);qemu_get_be32s (f, &env->vscr);qemu_get_be64s (f, &env->spe_acc);qemu_get_be32s (f, &env->spe_fscr);
target-ppc/translate.c +1 -1
@@ -9126,7 +9126,7 @@ void cpu_dump_state (CPUState *env, FILE *f, fprintf_function cpu_fprintf,#if !defined(CONFIG_USER_ONLY )cpu_fprintf (f,"SRR0 " TARGET_FMT_lx" SRR1 " TARGET_FMT_lx" SDR1 " TARGET_FMT_lx"\n" , env->spr[SPR_SRR0 ], env->spr[SPR_SRR1 ], - env->sdr1); + env->spr[SPR_SDR1 ]);#endif #undef RGPL
target-ppc/translate_init.c +1 -6
@@ -343,11 +343,6 @@ static void spr_write_dbatl_h (void *opaque, int sprn, int gprn) }/* SDR1 */ -static void spr_read_sdr1 (void *opaque,int gprn,int sprn) -{ -tcg_gen_ld_tl (cpu_gpr[gprn], cpu_env, offsetof(CPUState , sdr1)); -} -static void spr_write_sdr1 (void *opaque,int sprn,int gprn) {gen_helper_store_sdr1 (cpu_gpr[gprn]);
@@ -671,7 +666,7 @@ static void gen_spr_ne_601 (CPUPPCState *env)/* Memory management */ spr_register (env,SPR_SDR1 ,"SDR1" ,SPR_NOACCESS ,SPR_NOACCESS , - &spr_read_sdr1, &spr_write_sdr1, + &spr_read_generic, &spr_write_sdr1,0x00000000 ); }
Signature · 1 line
1.7.1
PATCH 9/27 Use "hash" more consistently in ppc mmu code
In reply to David GibsonCurrently, get_segment() has a variable called hash. However it doesn't (quite) get the hash value for the ppc hashed page table. Instead it gets the hash shifted - effectively the offset of the hash bucket within the hash page table.
As well, as being different to the normal use of plain "hash" in the architecture documentation, this usage necessitates some awkward 32/64 dependent masks and shifts which clutter up the path in get_segment().
This patch alters the code to use raw hash values through get_segment() including storing raw hashes instead of pte group offsets in the ctx structure. This cleans up the path noticeably.
This does necessitate 32/64 dependent shifts when the hash values are taken out of the ctx structure and used, but those paths already have 32/64 bit variants so this is less awkward than it was in get_segment().
--- target-ppc/cpu.h | 5 ++- target-ppc/helper.c | 95 ++++++++++++++++++++++++-------------------------- 2 files changed, 50 insertions(+), 50 deletions(-)
target-ppc/cpu.h +4 -1
@@ -367,6 +367,9 @@ union ppc_tlb_t {#define SDR_64_HTABSIZE 0x000000000000001FULL#endif /* defined(TARGET_PPC64 */ +#define HASH_PTE_SIZE_32 8 +#define HASH_PTE_SIZE_64 16 +typedef struct ppc_slb_t ppc_slb_t ;struct ppc_slb_t {uint64_t esid;
@@ -744,7 +747,7 @@ struct mmu_ctx_t {target_phys_addr_t raddr;/* Real address */ target_phys_addr_t eaddr;/* Effective address */ int prot;/* Protection bits */ -target_phys_addr_t pg_addr[2 ];/* PTE tables base addresses */ +target_phys_addr_t hash[2 ];/* Pagetable hash values */ target_ulong ptem;/* Virtual segment ID | API */ int key;/* Access key */ int nx;/* Non-execute area */
target-ppc/helper.c +46 -49
208 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 10/27 Better factor the ppc hash translation path
In reply to David GibsonCurrently the path handling hash page table translation in get_segment() has a mix of common and 32 or 64 bit specific code. However the division is not done terribly well which results in a lot of messy code flipping between common and divided paths.
This patch improves the organization, consolidating several divided paths into one. This in turn allows simplification of some code in get_segment(), removing a number of ugly interim variables.
This new factorization will also make it easier to add support for the 1T segments added in newer CPUs.
--- target-ppc/cpu.h | 1 + target-ppc/helper.c | 67 ++++++++++++++------------------------------------ 2 files changed, 20 insertions(+), 48 deletions(-)
target-ppc/cpu.h +1 -0
@@ -386,6 +386,7 @@ struct ppc_slb_t {#define SLB_VSID_B 0xc000000000000000ULL#define SLB_VSID_B_256M 0x0000000000000000ULL#define SLB_VSID_VSID 0x3FFFFFFFFFFFF000ULL +#define SLB_VSID_PTEM (SLB_VSID_B | SLB_VSID_VSID)#define SLB_VSID_KS 0x0000000000000800ULL#define SLB_VSID_KP 0x0000000000000400ULL#define SLB_VSID_N 0x0000000000000200ULL/* no-execute */
target-ppc/helper.c +19 -48
140 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 11/27 Support 1T segments on ppc
In reply to David GibsonTraditionally, the "segments" used for the two-stage translation used on powerpc MMUs were 256MB in size. This was the only option on all hash page table based 32-bit powerpc cpus, and on the earlier 64-bit hash page table based cpus. However, newer 64-bit cpus also permit 1TB segments
This patch adds support for 1TB segment translation to the qemu code.
--- target-ppc/cpu.h | 7 +++++++ target-ppc/helper.c | 50 ++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 45 insertions(+), 12 deletions(-)
target-ppc/cpu.h +7 -0
@@ -114,6 +114,7 @@ enum powerpc_mmu_t { POWERPC_MMU_601 = 0x0000000A,#if defined(TARGET_PPC64 )#define POWERPC_MMU_64 0x00010000 +#define POWERPC_MMU_1TSEG 0x00020000/* 64 bits PowerPC MMU */ POWERPC_MMU_64B = POWERPC_MMU_64 | 0x00000001,/* 620 variant (no segment exceptions) */
@@ -382,9 +383,11 @@ struct ppc_slb_t {/* Bits in the SLB VSID word */ #define SLB_VSID_SHIFT 12 +#define SLB_VSID_SHIFT_1T 24#define SLB_VSID_SSIZE_SHIFT 62#define SLB_VSID_B 0xc000000000000000ULL#define SLB_VSID_B_256M 0x0000000000000000ULL +#define SLB_VSID_B_1T 0x4000000000000000ULL#define SLB_VSID_VSID 0x3FFFFFFFFFFFF000ULL#define SLB_VSID_PTEM (SLB_VSID_B | SLB_VSID_VSID)#define SLB_VSID_KS 0x0000000000000800ULL
@@ -398,6 +401,10 @@ struct ppc_slb_t {#define SEGMENT_SHIFT_256M 28#define SEGMENT_MASK_256M (~((1ULL << SEGMENT_SHIFT_256M) - 1)) +#define SEGMENT_SHIFT_1T 40 +#define SEGMENT_MASK_1T (~((1ULL << SEGMENT_SHIFT_1T) - 1)) + +/*****************************************************************************/ /* Machine state register bits definition */ #define MSR_SF 63/* Sixty-four-bit mode hflags */
target-ppc/helper.c +38 -12
95 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 12/27 Add POWER7 support for ppc
In reply to David GibsonThis adds emulation support for the recent POWER7 cpu to qemu. It's far from perfect - it's missing a number of POWER7 features so far, including any support for VSX or decimal floating point instructions. However, it's close enough to boot a kernel with the POWER7 PVR.
--- hw/ppc.c | 35 ++++++++++++++ hw/ppc.h | 1 + target-ppc/cpu.h | 16 ++++++ target-ppc/helper.c | 6 ++ target-ppc/translate_init.c | 107 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 165 insertions(+), 0 deletions(-)
hw/ppc.c +35 -0
@@ -247,6 +247,41 @@ void ppc970_irq_init (CPUState *env) env->irq_inputs = (void **)qemu_allocate_irqs (&ppc970_set_irq, env, PPC970_INPUT_NB); } + +/* POWER7 internal IRQ controller */ +static void power7_set_irq (void *opaque,int pin,int level) +{ +CPUState *env = opaque; +int cur_level; + +LOG_IRQ ("%s: env %p pin %d level %d\n" , __func__, + env, pin, level); + cur_level = (env->irq_input_state >> pin) &1 ; + +switch (pin) { +case POWER7_INPUT_INT : +/* Level sensitive - active high */ +LOG_IRQ ("%s: set the external IRQ state to %d\n" , + __func__, level); +ppc_set_irq (env,PPC_INTERRUPT_EXT , level); +break ; +default : +/* Unknown pin - do nothing */ +LOG_IRQ ("%s: unknown IRQ pin %d\n" , __func__, pin); +return ; + } +if (level) { + env->irq_input_state |=1 << pin; + }else { + env->irq_input_state &= ~(1 << pin); + } +} + +void ppcPOWER7_irq_init (CPUState *env) +{ + env->irq_inputs = (void **)qemu_allocate_irqs (&power7_set_irq, env, +POWER7_INPUT_NB ); +}#endif /* defined(TARGET_PPC64) */ /* PowerPC 40x internal IRQ controller */
hw/ppc.h +1 -0
@@ -36,6 +36,7 @@ void ppc40x_irq_init (CPUState *env);void ppce500_irq_init (CPUState *env);void ppc6xx_irq_init (CPUState *env);void ppc970_irq_init (CPUState *env); +void ppcPOWER7_irq_init (CPUState *env);/* PPC machines for OpenBIOS */ enum {
target-ppc/cpu.h +16 -0
@@ -119,6 +119,8 @@ enum powerpc_mmu_t {POWERPC_MMU_64B =POWERPC_MMU_64 |0x00000001 ,/* 620 variant (no segment exceptions) */ POWERPC_MMU_620 =POWERPC_MMU_64 |0x00000002 , +/* Architecture 2.06 variant */ + POWERPC_MMU_2_06 = POWERPC_MMU_64 | POWERPC_MMU_1TSEG | 0x00000003, #endif /* defined(TARGET_PPC64) */ };
@@ -154,6 +156,8 @@ enum powerpc_excp_t {#if defined(TARGET_PPC64 )/* PowerPC 970 exception model */ POWERPC_EXCP_970, + /* POWER7 exception model */ + POWERPC_EXCP_POWER7,#endif /* defined(TARGET_PPC64) */ };
@@ -289,6 +293,8 @@ enum powerpc_input_t {PPC_FLAGS_INPUT_405 ,/* PowerPC 970 bus */ PPC_FLAGS_INPUT_970 , +/* PowerPC POWER7 bus */ +PPC_FLAGS_INPUT_POWER7 ,/* PowerPC 401 bus */ PPC_FLAGS_INPUT_401,/* Freescale RCPU bus */
@@ -1001,6 +1007,7 @@ static inline void cpu_clone_regs(CPUState *env, target_ulong newsp)#define SPR_HSPRG1 (0x131)#define SPR_HDSISR (0x132)#define SPR_HDAR (0x133) +#define SPR_SPURR (0x134)#define SPR_BOOKE_DBCR0 (0x134)#define SPR_IBCR (0x135)#define SPR_PURR (0x135)
@@ -1625,6 +1632,15 @@ enum {PPC970_INPUT_THINT =6 , PPC970_INPUT_NB, }; + +enum { +/* POWER7 input pins */ +POWER7_INPUT_INT =0 , +/* POWER7 probably has other inputs, but we don't care about them +* for any existing machine. We can wire these up when we need +* them */ +POWER7_INPUT_NB , +};#endif /* Hardware exceptions definitions */
target-ppc/helper.c +6 -0
@@ -1200,6 +1200,7 @@ static inline int check_physical(CPUState *env, mmu_ctx_t *ctx,#if defined(TARGET_PPC64 )case POWERPC_MMU_620 :case POWERPC_MMU_64B : +case POWERPC_MMU_2_06 :/* Real address are 60 bits long */ ctx->raddr &=0x0FFFFFFFFFFFFFFFULL ; ctx->prot |=PAGE_WRITE ;
@@ -1277,6 +1278,7 @@ int get_physical_address (CPUState *env, mmu_ctx_t *ctx, target_ulong eaddr,#if defined(TARGET_PPC64 )case POWERPC_MMU_620 :case POWERPC_MMU_64B : +case POWERPC_MMU_2_06 :#endif if (ret <0 ) {/* We didn't match any BAT entry or don't have BATs */
@@ -1376,6 +1378,7 @@ int cpu_ppc_handle_mmu_fault (CPUState *env, target_ulong address, int rw,#if defined(TARGET_PPC64 )case POWERPC_MMU_620 :case POWERPC_MMU_64B : +case POWERPC_MMU_2_06 :#endif env->exception_index =POWERPC_EXCP_ISI ; env->error_code =0x40000000 ;
@@ -1485,6 +1488,7 @@ int cpu_ppc_handle_mmu_fault (CPUState *env, target_ulong address, int rw,#if defined(TARGET_PPC64 )case POWERPC_MMU_620 :case POWERPC_MMU_64B : +case POWERPC_MMU_2_06 :#endif env->exception_index =POWERPC_EXCP_DSI ; env->error_code =0 ;
@@ -1808,6 +1812,7 @@ void ppc_tlb_invalidate_all (CPUPPCState *env)#if defined(TARGET_PPC64 )case POWERPC_MMU_620 :case POWERPC_MMU_64B : +case POWERPC_MMU_2_06 :#endif /* defined(TARGET_PPC64) */ tlb_flush (env,1 );break ;
@@ -1875,6 +1880,7 @@ void ppc_tlb_invalidate_one (CPUPPCState *env, target_ulong addr)#if defined(TARGET_PPC64 )case POWERPC_MMU_620 :case POWERPC_MMU_64B : +case POWERPC_MMU_2_06 :/* tlbie invalidate TLBs for all segments */ /* XXX: given the fact that there are too many segments to invalidate, * and we still don't have a tlb_flush_mask(env, n, mask) in Qemu,
target-ppc/translate_init.c +107 -0
137 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 13/27 Start implementing pSeries logical partition machine
In reply to David GibsonThis patch adds a "pseries" machine to qemu. This aims to emulate a logical partition on an IBM pSeries machine, compliant to the "PowerPC Architecture Platform Requirements" (PAPR) document.
This initial version is quite limited, it implements a basic machine and PAPR hypercall emulation. So far only one hypercall is present - H_PUT_TERM_CHAR - so that a (write-only) console is available.
Multiple CPUs are permitted, with SMP entry handled kexec() style.
The machine so far more resembles an old POWER4 style "full system partition" rather than a modern LPAR, in that the guest manages the page tables directly, rather than via hypercalls.
The machine requires qemu to be configured with --enable-fdt. The machine can (so far) only be booted with -kernel - i.e. no partition firmware is provided.
--- Makefile.target | 4 + hw/spapr.c | 313 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/spapr.h | 257 ++++++++++++++++++++++++++++++++++++++++++++ hw/spapr_hcall.c | 41 +++++++ 4 files changed, 615 insertions(+), 0 deletions(-) create mode 100644 hw/spapr.c create mode 100644 hw/spapr.h create mode 100644 hw/spapr_hcall.c
Makefile.target +4 -0
@@ -231,6 +231,10 @@ obj-ppc-y += ppc_prep.o obj-ppc-y += ppc_oldworld.o # NewWorld PowerMac obj-ppc-y += ppc_newworld.o +# IBM pSeries (sPAPR)i +ifeq ($(CONFIG_FDT)$(TARGET_PPC64),yy) +obj-ppc-y += spapr.o spapr_hcall.o +endif # PowerPC 4xx boards obj-ppc-y += ppc4xx_devs.o ppc4xx_pci.o ppc405_uc.o ppc405_boards.o obj-ppc-y += ppc440.o ppc440_bamboo.o
hw/spapr.c new file +313 -0
313 lines not on this page · raw message
hw/spapr.h new file +257 -0
257 lines not on this page · raw message
hw/spapr_hcall.c new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 14/27 Implement the bus structure for PAPR virtual IO
In reply to David GibsonThis extends the "pseries" (PAPR) machine to include a virtual IO bus supporting the PAPR defined hypercall based virtual IO mechanisms.
So far only one VIO device is provided, the vty / vterm, providing a full console (polled only, for now).
--- Makefile.target | 5 +- hw/spapr.c | 48 ++++++++----- hw/spapr.h | 3 + hw/spapr_vio.c | 214 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/spapr_vio.h | 50 +++++++++++++ hw/spapr_vty.c | 150 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 450 insertions(+), 20 deletions(-) create mode 100644 hw/spapr_vio.c create mode 100644 hw/spapr_vio.h create mode 100644 hw/spapr_vty.c
Makefile.target +3 -2
@@ -231,9 +231,10 @@ obj-ppc-y += ppc_prep.o obj-ppc-y += ppc_oldworld.o # NewWorld PowerMac obj-ppc-y += ppc_newworld.o -# IBM pSeries (sPAPR)i +# IBM pSeries (sPAPR) ifeq ($(CONFIG_FDT)$(TARGET_PPC64),yy) -obj-ppc-y += spapr.o spapr_hcall.o +obj-ppc-y += spapr.o spapr_hcall.o spapr_vio.o +obj-ppc-y += spapr_vty.o endif # PowerPC 4xx boards obj-ppc-y += ppc4xx_devs.o ppc4xx_pci.o ppc405_uc.o ppc405_boards.o
hw/spapr.c +30 -18
93 lines not on this page · raw message
hw/spapr.h +3 -0
@@ -1,7 +1,10 @@#if !defined(__HW_SPAPR_H__)#define __HW_SPAPR_H__ +struct VIOsPAPRBus ; +typedef struct sPAPREnvironment { +struct VIOsPAPRBus *vio_bus; }sPAPREnvironment ;#define H_SUCCESS 0
hw/spapr_vio.c new file +214 -0
214 lines not on this page · raw message
hw/spapr_vio.h new file +50 -0
50 lines not on this page · raw message
hw/spapr_vty.c new file +150 -0
150 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 15/27 Virtual hash page table handling on pSeries machine
In reply to David GibsonOn pSeries logical partitions, excepting the old POWER4-style full system partitions, the guest does not have direct access to the hardware page table. Instead, the pagetable exists in hypervisor memory, and the guest must manipulate it with hypercalls.
However, our current pSeries emulation more closely resembles the old style where the guest must set up and handle the pagetables itself. This patch converts it to act like a modern partition.
This involves two things: first, the hash translation path is modified to permit the has table to be stored externally to the emulated machine's RAM. The pSeries machine init code configures the CPUs to use this mode.
Secondly, we emulate the PAPR hypercalls for manipulating the external hashed page table.
--- hw/spapr.c | 35 ++++++- hw/spapr_hcall.c | 254 +++++++++++++++++++++++++++++++++++++++++++++++++++ target-ppc/cpu.h | 2 + target-ppc/helper.c | 36 ++++++-- 4 files changed, 315 insertions(+), 12 deletions(-)
hw/spapr.c +31 -4
@@ -52,12 +52,15 @@ static void *spapr_create_fdt(int *fdt_size, ram_addr_t ramsize,sPAPREnvironment *spapr, target_phys_addr_t initrd_base, target_phys_addr_t initrd_size, - const char *kernel_cmdline) + const char *kernel_cmdline, + long hash_shift) { void *fdt;uint64_t mem_reg_property[] = {0 ,cpu_to_be64 (ramsize) };uint32_t start_prop =cpu_to_be32 (initrd_base);uint32_t end_prop =cpu_to_be32 (initrd_base + initrd_size); +uint32_t pft_size_prop[] = {0 ,cpu_to_be32 (hash_shift)}; +char hypertas_prop[] ="hcall-pft\0hcall-term" ;int i;char *modelname;int ret;
@@ -145,6 +148,8 @@ static void *spapr_create_fdt(int *fdt_size, ram_addr_t ramsize,* full emu, for kvm we should copy it from the host */ _FDT ((fdt_property_cell (fdt,"clock-frequency" ,1000000000 )));_FDT ((fdt_property_cell (fdt,"ibm,slb-size" , env->slb_nr))); +_FDT ((fdt_property (fdt,"ibm,pft-size" , + pft_size_prop,sizeof (pft_size_prop))));_FDT ((fdt_property_string (fdt,"status" ,"okay" )));_FDT ((fdt_property (fdt,"64-bit" ,NULL ,0 )));
@@ -160,6 +165,14 @@ static void *spapr_create_fdt(int *fdt_size, ram_addr_t ramsize,_FDT ((fdt_end_node (fdt))); +/* RTAS */ +_FDT ((fdt_begin_node (fdt,"rtas" ))); + +_FDT ((fdt_property (fdt,"ibm,hypertas-functions" , hypertas_prop, +sizeof (hypertas_prop)))); + +_FDT ((fdt_end_node (fdt))); +/* vdevice */ _FDT ((fdt_begin_node (fdt,"vdevice" )));
@@ -208,12 +221,13 @@ static void ppc_spapr_init(ram_addr_t ram_size, const char *cpu_model) {CPUState *envs[MAX_CPUS ]; -void *fdt; +void *fdt, *htab;int i;ram_addr_t ram_offset;target_phys_addr_t fdt_addr;uint32_t kernel_base, initrd_base; -long kernel_size, initrd_size; +long kernel_size, initrd_size, htab_size; +long pteg_shift =17 ;int fdt_size; spapr =qemu_malloc (sizeof (*spapr));
@@ -250,6 +264,18 @@ static void ppc_spapr_init(ram_addr_t ram_size, ram_offset =qemu_ram_alloc (NULL ,"ppc_spapr.ram" , ram_size);cpu_register_physical_memory (0 , ram_size, ram_offset); +/* allocate hash page table. For now we always make this 16mb, +* later we should probably make it scale to the size of guest +* RAM */ + htab_size =1ULL << (pteg_shift +7 ); + htab =qemu_mallocz (htab_size); + +for (i =0 ; i < smp_cpus; i++) { + envs[i]->external_htab = htab; + envs[i]->htab_base =-1 ; + envs[i]->htab_mask = htab_size -1 ; + } + spapr->vio_bus =spapr_vio_bus_init ();for (i =0 ; i <MAX_SERIAL_PORTS ; i++) {
@@ -296,7 +322,8 @@ static void ppc_spapr_init(ram_addr_t ram_size,/* Prepare the device tree */ fdt =spapr_create_fdt (&fdt_size, ram_size, cpu_model, envs, spapr, - initrd_base, initrd_size, kernel_cmdline); + initrd_base, initrd_size, kernel_cmdline, + pteg_shift +7 );assert (fdt !=NULL );cpu_physical_memory_write (fdt_addr, fdt, fdt_size);
hw/spapr_hcall.c +254 -0
265 lines not on this page · raw message
target-ppc/cpu.h +2 -0
@@ -670,6 +670,8 @@ struct CPUPPCState {target_phys_addr_t htab_base;target_phys_addr_t htab_mask;target_ulong sr[32 ]; +/* externally stored hash table */ +uint8_t *external_htab;/* BATs */ int nb_BATs;target_ulong DBAT [2 ][8 ];
target-ppc/helper.c +28 -8
@@ -589,8 +589,13 @@ static inline int _find_pte(CPUState *env, mmu_ctx_t *ctx, int is_64b, int h,for (i =0 ; i <8 ; i++) {#if defined(TARGET_PPC64 )if (is_64b) { - pte0 =ldq_phys (env->htab_base + pteg_off + (i *16 )); - pte1 =ldq_phys (env->htab_base + pteg_off + (i *16 ) +8 ); +if (env->external_htab) { + pte0 =ldq_p (env->external_htab + pteg_off + (i *16 )); + pte1 =ldq_p (env->external_htab + pteg_off + (i *16 ) +8 ); + }else { + pte0 =ldq_phys (env->htab_base + pteg_off + (i *16 )); + pte1 =ldq_phys (env->htab_base + pteg_off + (i *16 ) +8 ); + }/* We have a TLB that saves 4K pages, so let's * split a huge page to 4k chunks */
@@ -606,8 +611,13 @@ static inline int _find_pte(CPUState *env, mmu_ctx_t *ctx, int is_64b, int h, } else#endif { - pte0 =ldl_phys (env->htab_base + pteg_off + (i *8 )); - pte1 =ldl_phys (env->htab_base + pteg_off + (i *8 ) +4 ); +if (env->external_htab) { + pte0 =ldl_p (env->external_htab + pteg_off + (i *8 )); + pte1 =ldl_p (env->external_htab + pteg_off + (i *8 ) +4 ); + }else { + pte0 =ldl_phys (env->htab_base + pteg_off + (i *8 )); + pte1 =ldl_phys (env->htab_base + pteg_off + (i *8 ) +4 ); + } r =pte32_check (ctx, pte0, pte1, h, rw, type); LOG_MMU("Load pte from " TARGET_FMT_lx " => " TARGET_FMT_lx " " TARGET_FMT_lx " %d %d %d " TARGET_FMT_lx "\n",
@@ -647,13 +657,23 @@ static inline int _find_pte(CPUState *env, mmu_ctx_t *ctx, int is_64b, int h,if (pte_update_flags (ctx, &pte1, ret, rw) ==1 ) {#if defined(TARGET_PPC64 )if (is_64b) { -stq_phys_notdirty (env->htab_base + pteg_off + (good *16 ) +8 , - pte1); +if (env->external_htab) { +stq_p (env->external_htab + pteg_off + (good *16 ) +8 , + pte1); + }else { +stq_phys_notdirty (env->htab_base + pteg_off + + (good *16 ) +8 , pte1); + } } else#endif { -stl_phys_notdirty (env->htab_base + pteg_off + (good *8 ) +4 , - pte1); +if (env->external_htab) { +stl_p (env->external_htab + pteg_off + (good *8 ) +4 , + pte1); + }else { +stl_phys_notdirty (env->htab_base + pteg_off + + (good *8 ) +4 , pte1); + } } } }
Signature · 1 line
1.7.1
PATCH 16/27 Implement hcall based RTAS for pSeries machines
In reply to David GibsonOn pSeries machines, operating systems can instantiate "RTAS" (Run-Time Abstraction Services), a runtime component of the firmware which implements a number of low-level, infrequently used operations. On logical partitions under a hypervisor, many of the RTAS functions require hypervisor privilege. For simplicity, therefore, hypervisor systems typically implement the in-partition RTAS as just a tiny wrapper around a hypercall which actually implements the various RTAS functions.
This patch implements such a hypercall based RTAS for our emulated pSeries machine. A tiny in-partition "firmware" calls a new hypercall, which looks up available RTAS services in a table.
--- Makefile | 3 +- Makefile.target | 2 +- configure | 4 +- hw/spapr.c | 26 +++++++- hw/spapr.h | 32 ++++++++++ hw/spapr_hcall.c | 44 +++++++++++--- hw/spapr_rtas.c | 131 +++++++++++++++++++++++++++++++++++++++ pc-bios/spapr-rtas.bin | Bin 0 -> 20 bytes pc-bios/spapr-rtas/Makefile | 24 +++++++ pc-bios/spapr-rtas/spapr-rtas.S | 37 +++++++++++ 10 files changed, 289 insertions(+), 14 deletions(-) create mode 100644 hw/spapr_rtas.c create mode 100755 pc-bios/spapr-rtas.bin create mode 100644 pc-bios/spapr-rtas/Makefile create mode 100644 pc-bios/spapr-rtas/spapr-rtas.S
Makefile +2 -1
@@ -213,7 +213,8 @@ pxe-ne2k_pci.bin pxe-pcnet.bin \ pxe-rtl8139.bin pxe-virtio.bin \ bamboo.dtb petalogix-s3adsp1800.dtb petalogix-ml605.dtb \ multiboot.bin linuxboot.bin \ -s390-zipl.rom +s390-zipl.rom \ +spapr-rtas.bin else BLOBS= endif
Makefile.target +1 -1
@@ -233,7 +233,7 @@ obj-ppc-y += ppc_oldworld.o obj-ppc-y += ppc_newworld.o # IBM pSeries (sPAPR) ifeq ($(CONFIG_FDT)$(TARGET_PPC64),yy) -obj-ppc-y += spapr.o spapr_hcall.o spapr_vio.o +obj-ppc-y += spapr.o spapr_hcall.o spapr_rtas.o spapr_vio.o obj-ppc-y += spapr_vty.o endif # PowerPC 4xx boards
configure +3 -1
@@ -2461,7 +2461,9 @@ if test \( "$cpu" = "i386" -o "$cpu" = "x86_64" \) -a \ "$softmmu" = yes ; then roms="optionrom" fi - +if test "$cpu" = "ppc64" ; then + roms="$roms spapr-rtas" +fi echo "Install prefix $prefix" echo "BIOS directory `eval echo $datadir`"
hw/spapr.c +23 -3
@@ -40,6 +40,7 @@#define KERNEL_LOAD_ADDR 0x00000000#define INITRD_LOAD_ADDR 0x02800000#define FDT_MAX_SIZE 0x10000 +#define RTAS_MAX_SIZE 0x10000#define TIMEBASE_FREQ 512000000ULL
@@ -53,6 +54,8 @@ static void *spapr_create_fdt(int *fdt_size, ram_addr_t ramsize,target_phys_addr_t initrd_base, target_phys_addr_t initrd_size, const char *kernel_cmdline, + target_phys_addr_t rtas_addr, + target_phys_addr_t rtas_size, long hash_shift) { void *fdt;
@@ -195,6 +198,12 @@ static void *spapr_create_fdt(int *fdt_size, ram_addr_t ramsize,exit (1 ); } +/* RTAS */ + ret =spapr_rtas_device_tree_setup (fdt, rtas_addr, rtas_size); +if (ret <0 ) { +fprintf (stderr,"Couldn't set up RTAS device tree properties\n" ); + } +_FDT ((fdt_pack (fdt))); *fdt_size =fdt_totalsize (fdt);
@@ -224,11 +233,12 @@ static void ppc_spapr_init(ram_addr_t ram_size,void *fdt, *htab;int i;ram_addr_t ram_offset; -target_phys_addr_t fdt_addr; +target_phys_addr_t fdt_addr, rtas_addr;uint32_t kernel_base, initrd_base; -long kernel_size, initrd_size, htab_size; +long kernel_size, initrd_size, htab_size, rtas_size;long pteg_shift =17 ;int fdt_size; +char *filename; spapr =qemu_malloc (sizeof (*spapr)); cpu_ppc_hypercall = emulate_spapr_hypercall;
@@ -237,6 +247,8 @@ static void ppc_spapr_init(ram_addr_t ram_size,* 2GB, so that it can be processed with 32-bit code if * necessary */ fdt_addr =MIN (ram_size,0x80000000 ) -FDT_MAX_SIZE ; +/* RTAS goes just below that */ + rtas_addr = fdt_addr -RTAS_MAX_SIZE ;/* init CPUs */ if (cpu_model ==NULL ) {
@@ -276,6 +288,14 @@ static void ppc_spapr_init(ram_addr_t ram_size, envs[i]->htab_mask = htab_size -1 ; } + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS ,"spapr-rtas.bin" ); + rtas_size =load_image_targphys (filename, rtas_addr, ram_size - rtas_addr); +if (rtas_size <0 ) { +hw_error ("qemu: could not load LPAR rtas '%s'\n" , filename); +exit (1 ); + } +qemu_free (filename); + spapr->vio_bus =spapr_vio_bus_init ();for (i =0 ; i <MAX_SERIAL_PORTS ; i++) {
@@ -323,7 +343,7 @@ static void ppc_spapr_init(ram_addr_t ram_size,/* Prepare the device tree */ fdt =spapr_create_fdt (&fdt_size, ram_size, cpu_model, envs, spapr, initrd_base, initrd_size, kernel_cmdline, - pteg_shift +7 ); + rtas_addr, rtas_size, pteg_shift +7 );assert (fdt !=NULL );cpu_physical_memory_write (fdt_addr, fdt, fdt_size);
hw/spapr.h +32 -0
@@ -237,6 +237,18 @@ typedef struct sPAPREnvironment {#define H_GET_MPP 0x2D4#define MAX_HCALL_OPCODE H_GET_MPP +/* The hcalls above are standardized in PAPR and implemented by pHyp +* as well. +* +* We also need some hcalls which are specific to qemu / KVM-on-POWER. +* So far we just need one for H_RTAS, but in future we'll need more +* for extensions like virtio. We put those into the 0xf000-0xfffc +* range which is reserved by PAPR for "platform-specific" hcalls. +*/ +#define KVMPPC_HCALL_BASE 0xf000 +#define KVMPPC_H_RTAS (KVMPPC_HCALL_BASE + 0x0) +#define KVMPPC_HCALL_MAX KVMPPC_H_RTAS +extern sPAPREnvironment *spapr;/*#define DEBUG_SPAPR_HCALLS*/
@@ -257,4 +269,24 @@ void spapr_register_hypercall(target_ulong opcode, spapr_hcall_fn fn);target_ulong spapr_hypercall (CPUState *env,target_ulong opcode,target_ulong *args); +static inline uint32_t rtas_ld (target_ulong phys,int n) +{ +return ldl_phys (phys +4 *n); +} + +static inline void rtas_st (target_ulong phys,int n,uint32_t val) +{ +stl_phys (phys +4 *n, 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); +target_ulong spapr_rtas_call (sPAPREnvironment *spapr, +uint32_t token,uint32_t nargs,target_ulong args, +uint32_t nret,target_ulong rets); +int spapr_rtas_device_tree_setup (void *fdt,target_phys_addr_t rtas_addr, +target_phys_addr_t rtas_size); +#endif /* !defined (__HW_SPAPR_H__) */
hw/spapr_hcall.c +36 -8
68 lines not on this page · raw message
hw/spapr_rtas.c new file +131 -0
131 lines not on this page · raw message
pc-bios/spapr-rtas.bin new file binary +0 -0
pc-bios/spapr-rtas/Makefile new file +24 -0
@@ -0,0 +1,24 @@ +all: build-all +# Dummy command so that make thinks it has done something + @true + +include ../../config-host.mak +include $(SRC_PATH)/rules.mak + +$(call set-vpath, $(SRC_PATH)/pc-bios/spapr-rtas) + +.PHONY : all clean build-all + +#CFLAGS += -I$(SRC_PATH) +#QEMU_CFLAGS = $(CFLAGS) + +build-all: spapr-rtas.bin + +%.img: %.o + $(call quiet-command,$(CC) -nostdlib -o $@ $<," Building $(TARGET_DIR)$@") + +%.bin: %.img + $(call quiet-command,$(OBJCOPY) -O binary -j .text $< $@," Building $(TARGET_DIR)$@") + +clean: + rm -f *.o *.d *.img *.bin *~
pc-bios/spapr-rtas/spapr-rtas.S new file +37 -0
@@ -0,0 +1,37 @@ +/* + * QEMU PowerPC pSeries Logical Partition (aka sPAPR) hardware System Emulator + * + * Trivial in-partition RTAS implementation, based on a hypercall + * + * Copyright (c) 2010,2011 David Gibson, IBM Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +#define KVMPPC_HCALL_BASE 0xf000 +#define KVMPPC_H_RTAS (KVMPPC_HCALL_BASE + 0x0) + +.globl _start +_start: + mr 4,3 + lis 3,KVMPPC_H_RTAS@h + ori 3,3,KVMPPC_H_RTAS@l + sc 1 + blr
Signature · 1 line
1.7.1
PATCH 17/27 Implement assorted pSeries hcalls and RTAS methods
In reply to David GibsonThis patch adds several small utility hypercalls and RTAS methods to the pSeries platform emulation. Specifically:
* 'display-character' rtas call
This just prints a character to the console, it's occasionally used for early debug of the OS. The support includes a hack to make this RTAS call respond on the normal token value present on real hardware, since some early debugging tools just assume this value without checking the device tree.
* 'get-time-of-day' rtas call
This one just takes the host real time, converts to the PAPR described format and returns it to the guest.
* 'power-off' rtas call
This one shuts down the emulated system.
* H_DABR hypercall
On pSeries, the DABR debug register is usually a hypervisor resource and virtualized through this hypercall. If the hypercall is not present, Linux will under some circumstances attempt to manipulate the DABR directly which will fail on this emulated machine.
This stub implementation is enough to stop that behaviour, although it doesn't actually implement the requested DABR operations as yet.
--- hw/spapr.c | 2 +- hw/spapr_hcall.c | 10 ++++++++ hw/spapr_rtas.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletions(-)
hw/spapr.c +1 -1
@@ -63,7 +63,7 @@ static void *spapr_create_fdt(int *fdt_size, ram_addr_t ramsize,uint32_t start_prop =cpu_to_be32 (initrd_base);uint32_t end_prop =cpu_to_be32 (initrd_base + initrd_size);uint32_t pft_size_prop[] = {0 ,cpu_to_be32 (hash_shift)}; -char hypertas_prop[] ="hcall-pft\0hcall-term" ; +char hypertas_prop[] ="hcall-pft\0hcall-term\0hcall-dabr" ;int i;char *modelname;int ret;
hw/spapr_hcall.c +10 -0
@@ -248,6 +248,13 @@ static target_ulong h_protect(CPUState *env, sPAPREnvironment *spapr,return H_SUCCESS ; } +static target_ulong h_set_dabr (CPUState *env,sPAPREnvironment *spapr, +target_ulong opcode,target_ulong *args) +{ +/* FIXME: actually implement this */ +return H_HARDWARE ; +} +static target_ulong h_rtas (CPUState *env,sPAPREnvironment *spapr,target_ulong opcode,target_ulong *args) {
@@ -317,6 +324,9 @@ static void hypercall_init(void)spapr_register_hypercall (H_REMOVE , h_remove);spapr_register_hypercall (H_PROTECT , h_protect); +/* hcall-dabr */ +spapr_register_hypercall (H_SET_DABR , h_set_dabr); +/* qemu/KVM-PPC specific hcalls */ spapr_register_hypercall (KVMPPC_H_RTAS , h_rtas); }
hw/spapr_rtas.c +69 -0
84 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 18/27 Implement the PAPR (pSeries) virtualized interrupt controller (xics)
In reply to David GibsonPAPR defines an interrupt control architecture which is logically divided into ICS (Interrupt Control Presentation, each unit is responsible for presenting interrupts to a particular "interrupt server", i.e. CPU) and ICS (Interrupt Control Source, each unit responsible for one or more hardware interrupts as numbered globally across the system). All PAPR virtual IO devices expect to deliver interrupts via this mechanism. In Linux, this interrupt controller system is handled by the "xics" driver.
On pSeries systems, access to the interrupt controller is virtualized via hypercalls and RTAS methods. However, the virtualized interface is very similar to the underlying interrupt controller hardware, and similar PICs exist un-virtualized in some other systems.
This patch implements both the ICP and ICS sides of the PAPR interrupt controller. For now, only the hypercall virtualized interface is provided, however it would be relatively straightforward to graft an emulated register interface onto the underlying interrupt logic if we want to add a machine with a hardware ICS/ICP system in the future.
There are some limitations in this implementation: it is assumed for now that only one instance of the ICS exists, although a full xics system can have several, each responsible for a different group of hardware irqs. ICP/ICS can handle both level-sensitve (LSI) and message signalled (MSI) interrupt inputs. For now, this implementation supports only MSI interrupts, since that is used by PAPR virtual IO devices.
--- Makefile.target | 2 +- hw/spapr.c | 27 +++ hw/spapr.h | 2 + hw/xics.c | 486 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/xics.h | 39 +++++ 5 files changed, 555 insertions(+), 1 deletions(-) create mode 100644 hw/xics.c create mode 100644 hw/xics.h
Makefile.target +1 -1
@@ -234,7 +234,7 @@ obj-ppc-y += ppc_newworld.o # IBM pSeries (sPAPR) ifeq ($(CONFIG_FDT)$(TARGET_PPC64),yy) obj-ppc-y += spapr.o spapr_hcall.o spapr_rtas.o spapr_vio.o -obj-ppc-y += spapr_vty.o +obj-ppc-y += xics.o spapr_vty.o endif # PowerPC 4xx boards obj-ppc-y += ppc4xx_devs.o ppc4xx_pci.o ppc405_uc.o ppc405_boards.o
hw/spapr.c +27 -0
@@ -34,6 +34,7 @@#include "hw/spapr.h" #include "hw/spapr_vio.h" +#include "hw/xics.h" #include <libfdt.h>
@@ -45,6 +46,7 @@#define TIMEBASE_FREQ 512000000ULL#define MAX_CPUS 32 +#define XICS_IRQS 1024sPAPREnvironment *spapr;
@@ -64,6 +66,7 @@ static void *spapr_create_fdt(int *fdt_size, ram_addr_t ramsize,uint32_t end_prop =cpu_to_be32 (initrd_base + initrd_size);uint32_t pft_size_prop[] = {0 ,cpu_to_be32 (hash_shift)};char hypertas_prop[] ="hcall-pft\0hcall-term\0hcall-dabr" ; +uint32_t interrupt_server_ranges_prop[] = {0 ,cpu_to_be32 (smp_cpus)};int i;char *modelname;int ret;
@@ -125,6 +128,7 @@ static void *spapr_create_fdt(int *fdt_size, ram_addr_t ramsize,for (i =0 ; i < smp_cpus; i++) {CPUState *env = envs[i]; +uint32_t gserver_prop[] = {cpu_to_be32 (i),0 };/* HACK! */ char *nodename;uint32_t segs[] = {cpu_to_be32 (28 ),cpu_to_be32 (40 ),0xffffffff ,0xffffffff };
@@ -155,6 +159,9 @@ static void *spapr_create_fdt(int *fdt_size, ram_addr_t ramsize, pft_size_prop, sizeof(pft_size_prop))));_FDT ((fdt_property_string (fdt,"status" ,"okay" )));_FDT ((fdt_property (fdt,"64-bit" ,NULL ,0 ))); +_FDT ((fdt_property_cell (fdt,"ibm,ppc-interrupt-server#s" , i))); +_FDT ((fdt_property (fdt,"ibm,ppc-interrupt-gserver#s" , + gserver_prop,sizeof (gserver_prop))));if (envs[i]->mmu_model &POWERPC_MMU_1TSEG ) { _FDT((fdt_property(fdt, "ibm,processor-segment-sizes",
@@ -176,6 +183,20 @@ static void *spapr_create_fdt(int *fdt_size, ram_addr_t ramsize,_FDT ((fdt_end_node (fdt))); +/* interrupt 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" , + interrupt_server_ranges_prop, +sizeof (interrupt_server_ranges_prop)))); + +_FDT ((fdt_end_node (fdt))); +/* vdevice */ _FDT ((fdt_begin_node (fdt,"vdevice" )));
@@ -183,6 +204,8 @@ static void *spapr_create_fdt(int *fdt_size, ram_addr_t ramsize,_FDT ((fdt_property_string (fdt,"compatible" ,"IBM,vdevice" )));_FDT ((fdt_property_cell (fdt,"#address-cells" ,0x1 )));_FDT ((fdt_property_cell (fdt,"#size-cells" ,0x0 ))); +_FDT ((fdt_property_cell (fdt,"#interrupt-cells" ,0x2 ))); +_FDT ((fdt_property (fdt,"interrupt-controller" ,NULL ,0 )));_FDT ((fdt_end_node (fdt)));
@@ -296,6 +319,10 @@ static void ppc_spapr_init(ram_addr_t ram_size, }qemu_free (filename); +/* Set up Interrupt Controller */ + spapr->icp =xics_system_init (smp_cpus, envs,XICS_IRQS ); + +/* Set up VIO bus */ spapr->vio_bus =spapr_vio_bus_init ();for (i =0 ; i <MAX_SERIAL_PORTS ; i++) {
hw/spapr.h +2 -0
@@ -2,9 +2,11 @@#define __HW_SPAPR_H__struct VIOsPAPRBus ; +struct icp_state ;typedef struct sPAPREnvironment {struct VIOsPAPRBus *vio_bus; +struct icp_state *icp; }sPAPREnvironment ;#define H_SUCCESS 0
hw/xics.c new file +486 -0
486 lines not on this page · raw message
hw/xics.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* QEMU PowerPC pSeries Logical Partition (aka sPAPR) hardware System Emulator +* +* PAPR Virtualized Interrupt System, aka ICS/ICP aka xics +* +* Copyright (c) 2010,2011 David Gibson, IBM Corporation. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +* +*/ +#if !defined(__XICS_H__) +#define __XICS_H__ + +#define XICS_IPI 0x2 + +struct icp_state ; + +qemu_irq xics_find_qirq (struct icp_state *icp,int irq); + +struct icp_state *xics_system_init (int nr_servers,CPUState *servers[], +int nr_irqs); + +#endif /* __XICS_H__ */
Signature · 1 line
1.7.1
PATCH 19/27 Add PAPR H_VIO_SIGNAL hypercall and infrastructure for VIO interrupts
In reply to David GibsonThis patch adds infrastructure to support interrupts from PAPR virtual IO devices. This includes correctly advertising those interrupts in the device tree, and implementing the H_VIO_SIGNAL hypercall, used to enable and disable individual device interrupts.
--- hw/spapr.c | 2 +- hw/spapr_vio.c | 37 +++++++++++++++++++++++++++++++++++++ hw/spapr_vio.h | 6 ++++++ 3 files changed, 44 insertions(+), 1 deletions(-)
hw/spapr.c +1 -1
@@ -65,7 +65,7 @@ static void *spapr_create_fdt(int *fdt_size, ram_addr_t ramsize,uint32_t start_prop =cpu_to_be32 (initrd_base);uint32_t end_prop =cpu_to_be32 (initrd_base + initrd_size);uint32_t pft_size_prop[] = {0 ,cpu_to_be32 (hash_shift)}; -char hypertas_prop[] ="hcall-pft\0hcall-term\0hcall-dabr" ; +char hypertas_prop[] ="hcall-pft\0hcall-term\0hcall-dabr\0hcall-interrupt" ;uint32_t interrupt_server_ranges_prop[] = {0 ,cpu_to_be32 (smp_cpus)};int i;char *modelname;
hw/spapr_vio.c +37 -0
@@ -105,6 +105,16 @@ static int vio_make_devnode(VIOsPAPRDevice *dev, } } +if (dev->qirq) { +uint32_t ints_prop[] = {cpu_to_be32 (dev->vio_irq_num),0 }; + + ret =fdt_setprop (fdt, node_off,"interrupts" , ints_prop, +sizeof (ints_prop)); +if (ret <0 ) { +return ret; + } + } +if (info->devnode) { ret = (info->devnode)(dev, fdt, node_off);if (ret <0 ) {
@@ -140,6 +150,30 @@ void spapr_vio_bus_register_withprop(VIOsPAPRDeviceInfo *info)qdev_register (&info->qdev); } +static target_ulong h_vio_signal (CPUState *env,sPAPREnvironment *spapr, +target_ulong opcode, +target_ulong *args) +{ +target_ulong reg = args[0 ]; +target_ulong mode = args[1 ]; +VIOsPAPRDevice *dev =spapr_vio_find_by_reg (spapr->vio_bus, reg); +VIOsPAPRDeviceInfo *info; + +if (!dev) { +return H_PARAMETER ; + } + + info = (VIOsPAPRDeviceInfo *)dev->qdev.info; + +if (mode & ~info->signal_mask) { +return H_PARAMETER ; + } + + dev->signal_state = mode; + +return H_SUCCESS ; +} +VIOsPAPRBus *spapr_vio_bus_init (void ) {VIOsPAPRBus *bus;
@@ -156,6 +190,9 @@ VIOsPAPRBus *spapr_vio_bus_init(void) qbus =qbus_create (&spapr_vio_bus_info, dev,"spapr-vio" ); bus =DO_UPCAST (VIOsPAPRBus, bus, qbus); +/* hcall-vio */ +spapr_register_hypercall (H_VIO_SIGNAL , h_vio_signal); +for (qinfo = device_info_list; qinfo; qinfo = qinfo->next) {VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)qinfo;
hw/spapr_vio.h +6 -0
@@ -24,6 +24,9 @@typedef struct VIOsPAPRDevice {DeviceState qdev;uint32_t reg; +qemu_irq qirq; +uint32_t vio_irq_num; +target_ulong signal_state; }VIOsPAPRDevice ; typedef struct VIOsPAPRBus {
@@ -33,6 +36,7 @@ typedef struct VIOsPAPRBus { typedef struct { DeviceInfo qdev; const char *dt_name, *dt_type, *dt_compatible; + target_ulong signal_mask; int (*init)(VIOsPAPRDevice *dev); void (*hcalls)(VIOsPAPRBus *bus); int (*devnode)(VIOsPAPRDevice *dev, void *fdt, int node_off);
@@ -43,6 +47,8 @@ extern VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg);extern void spapr_vio_bus_register_withprop (VIOsPAPRDeviceInfo *info);extern int spapr_populate_vdevice (VIOsPAPRBus *bus,void *fdt); +extern int spapr_vio_signal (VIOsPAPRDevice *dev,target_ulong mode); +void vty_putchars (VIOsPAPRDevice *sdev,uint8_t *buf,int len);void spapr_vty_create (VIOsPAPRBus *bus,uint32_t reg,CharDriverState *chardev);
Signature · 1 line
1.7.1
PATCH 20/27 Add (virtual) interrupt to PAPR virtual tty device
In reply to David GibsonNow that we have implemented the PAPR "xics" virtualized interrupt controller, we can add interrupts in PAPR VIO devices. This patch adds interrupt support to the PAPR virtual tty/console device.
--- hw/spapr.c | 6 ++++-- hw/spapr_vio.h | 3 ++- hw/spapr_vty.c | 11 ++++++++++- 3 files changed, 16 insertions(+), 4 deletions(-)
hw/spapr.c +4 -2
@@ -262,6 +262,7 @@ static void ppc_spapr_init(ram_addr_t ram_size,long pteg_shift =17 ;int fdt_size;char *filename; +int irq =16 ; spapr =qemu_malloc (sizeof (*spapr)); cpu_ppc_hypercall = emulate_spapr_hypercall;
@@ -325,9 +326,10 @@ static void ppc_spapr_init(ram_addr_t ram_size,/* Set up VIO bus */ spapr->vio_bus =spapr_vio_bus_init (); -for (i =0 ; i <MAX_SERIAL_PORTS ; i++) { +for (i =0 ; i <MAX_SERIAL_PORTS ; i++, irq++) {if (serial_hds[i]) { -spapr_vty_create (spapr->vio_bus, i, serial_hds[i]); +spapr_vty_create (spapr->vio_bus, i, serial_hds[i], +xics_find_qirq (spapr->icp, irq), irq); } }
hw/spapr_vio.h +2 -1
@@ -51,6 +51,7 @@ extern int spapr_vio_signal(VIOsPAPRDevice *dev, target_ulong mode);void vty_putchars (VIOsPAPRDevice *sdev,uint8_t *buf,int len);void spapr_vty_create (VIOsPAPRBus *bus, -uint32_t reg,CharDriverState *chardev); +uint32_t reg,CharDriverState *chardev, +qemu_irq qirq,uint32_t vio_irq_num);#endif /* _HW_SPAPR_VIO_H */
hw/spapr_vty.c +10 -1
@@ -24,6 +24,10 @@ static void vty_receive(void *opaque, const uint8_t *buf, int size)VIOsPAPRVTYDevice *dev = (VIOsPAPRVTYDevice *)opaque;int i; +if ((dev->in == dev->out) && size) { +/* toggle line to simulate edge interrupt */ +qemu_irq_pulse (dev->sdev.qirq); + }for (i =0 ; i < size; i++) {assert ((dev->in - dev->out) <VTERM_BUFSIZE ); dev->buf[dev->in++ %VTERM_BUFSIZE ] = buf[i];
@@ -112,14 +116,19 @@ static target_ulong h_get_term_char(CPUState *env, sPAPREnvironment *spapr, }void spapr_vty_create (VIOsPAPRBus *bus, -uint32_t reg,CharDriverState *chardev) +uint32_t reg,CharDriverState *chardev, +qemu_irq qirq,uint32_t vio_irq_num) {DeviceState *dev; +VIOsPAPRDevice *sdev; dev =qdev_create (&bus->bus,"spapr-vty" );qdev_prop_set_uint32 (dev,"reg" , reg);qdev_prop_set_chr (dev,"chardev" , chardev);qdev_init_nofail (dev); + sdev = (VIOsPAPRDevice *)dev; + sdev->qirq = qirq; + sdev->vio_irq_num = vio_irq_num; }static void vty_hcalls (VIOsPAPRBus *bus)
Signature · 1 line
1.7.1
PATCH 21/27 Implement TCE translation for sPAPR VIO
In reply to David GibsonThis patch implements the necessary infrastructure and hypercalls for sPAPR's TCE (Translation Control Entry) IOMMU mechanism. This is necessary for all virtual IO devices which do DMA (i.e. nearly all of them).
--- hw/spapr.c | 3 +- hw/spapr_vio.c | 238 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/spapr_vio.h | 32 ++++++++ 3 files changed, 272 insertions(+), 1 deletions(-)
hw/spapr.c +2 -1
@@ -65,7 +65,8 @@ static void *spapr_create_fdt(int *fdt_size, ram_addr_t ramsize,uint32_t start_prop =cpu_to_be32 (initrd_base);uint32_t end_prop =cpu_to_be32 (initrd_base + initrd_size);uint32_t pft_size_prop[] = {0 ,cpu_to_be32 (hash_shift)}; -char hypertas_prop[] ="hcall-pft\0hcall-term\0hcall-dabr\0hcall-interrupt" ; +char hypertas_prop[] ="hcall-pft\0hcall-term\0hcall-dabr\0hcall-interrupt" +"\0hcall-tce" ;uint32_t interrupt_server_ranges_prop[] = {0 ,cpu_to_be32 (smp_cpus)};int i;char *modelname;
hw/spapr_vio.c +238 -0
268 lines not on this page · raw message
hw/spapr_vio.h +32 -0
@@ -21,12 +21,29 @@* License along with this library; if not, see <http://www.gnu.org/licenses/>. */ +#define SPAPR_VIO_TCE_PAGE_SHIFT 12 +#define SPAPR_VIO_TCE_PAGE_SIZE (1ULL << SPAPR_VIO_TCE_PAGE_SHIFT) +#define SPAPR_VIO_TCE_PAGE_MASK (SPAPR_VIO_TCE_PAGE_SIZE - 1) + +enum VIOsPAPR_TCEAccess { +SPAPR_TCE_FAULT =0 , +SPAPR_TCE_RO =1 , +SPAPR_TCE_WO =2 , +SPAPR_TCE_RW =3 , +}; + +typedef struct VIOsPAPR_RTCE { +uint64_t tce; +}VIOsPAPR_RTCE ; +typedef struct VIOsPAPRDevice {DeviceState qdev;uint32_t reg;qemu_irq qirq;uint32_t vio_irq_num;target_ulong signal_state; +uint32_t rtce_window_size; +VIOsPAPR_RTCE *rtce_table; }VIOsPAPRDevice ; typedef struct VIOsPAPRBus {
@@ -49,6 +66,21 @@ extern int spapr_populate_vdevice(VIOsPAPRBus *bus, void *fdt);extern int spapr_vio_signal (VIOsPAPRDevice *dev,target_ulong mode); +int spapr_vio_check_tces (VIOsPAPRDevice *dev,target_ulong ioba, +target_ulong len, +enum VIOsPAPR_TCEAccess access); + +int spapr_tce_dma_read (VIOsPAPRDevice *dev,uint64_t taddr, +void *buf,uint32_t size); +int spapr_tce_dma_write (VIOsPAPRDevice *dev,uint64_t taddr, +const void *buf,uint32_t size); +int spapr_tce_dma_zero (VIOsPAPRDevice *dev,uint64_t taddr,uint32_t size); +void stb_tce (VIOsPAPRDevice *dev,uint64_t taddr,uint8_t val); +void sth_tce (VIOsPAPRDevice *dev,uint64_t taddr,uint16_t val); +void stw_tce (VIOsPAPRDevice *dev,uint64_t taddr,uint32_t val); +void stq_tce (VIOsPAPRDevice *dev,uint64_t taddr,uint64_t val); +uint64_t ldq_tce (VIOsPAPRDevice *dev,uint64_t taddr); +void vty_putchars (VIOsPAPRDevice *sdev,uint8_t *buf,int len); void spapr_vty_create(VIOsPAPRBus *bus, uint32_t reg, CharDriverState *chardev,
Signature · 1 line
1.7.1
PATCH 22/27 Implement sPAPR Virtual LAN (ibmveth)
In reply to David GibsonThis patch implements the PAPR specified Inter Virtual Machine Logical LAN; that is the virtual hardware used by the Linux ibmveth driver.
--- Makefile.target | 2 +- hw/spapr.c | 19 ++ hw/spapr_llan.c | 521 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/spapr_vio.h | 3 + 4 files changed, 544 insertions(+), 1 deletions(-) create mode 100644 hw/spapr_llan.c
Makefile.target +1 -1
@@ -234,7 +234,7 @@ obj-ppc-y += ppc_newworld.o # IBM pSeries (sPAPR) ifeq ($(CONFIG_FDT)$(TARGET_PPC64),yy) obj-ppc-y += spapr.o spapr_hcall.o spapr_rtas.o spapr_vio.o -obj-ppc-y += xics.o spapr_vty.o +obj-ppc-y += xics.o spapr_vty.o spapr_llan.o endif # PowerPC 4xx boards obj-ppc-y += ppc4xx_devs.o ppc4xx_pci.o ppc405_uc.o ppc405_boards.o
hw/spapr.c +19 -0
@@ -27,6 +27,7 @@#include "sysemu.h" #include "hw.h" #include "elf.h" +#include "net.h" #include "hw/boards.h" #include "hw/ppc.h"
@@ -334,6 +335,24 @@ static void ppc_spapr_init(ram_addr_t ram_size, } } +for (i =0 ; i < nb_nics; i++, irq++) { +NICInfo *nd = &nd_table[i]; + +if (!nd->model) { + nd->model =qemu_strdup ("ibmveth" ); + } + +if (strcmp (nd->model,"ibmveth" ) ==0 ) { +spapr_vlan_create (spapr->vio_bus,0x1000 + i, nd, +xics_find_qirq (spapr->icp, irq), irq); + }else { +fprintf (stderr,"pSeries (sPAPR) platform does not support " +"NIC model '%s' (only ibmveth is supported)\n" , + nd->model); +exit (1 ); + } + } +if (kernel_filename) {uint64_t lowaddr =0 ;
hw/spapr_llan.c new file +521 -0
521 lines not on this page · raw message
hw/spapr_vio.h +3 -0
@@ -86,4 +86,7 @@ void spapr_vty_create(VIOsPAPRBus *bus, uint32_t reg, CharDriverState *chardev, qemu_irq qirq, uint32_t vio_irq_num); +void spapr_vlan_create (VIOsPAPRBus *bus,uint32_t reg,NICInfo *nd, +qemu_irq qirq,uint32_t vio_irq_num); +#endif /* _HW_SPAPR_VIO_H */
Signature · 1 line
1.7.1
PATCH 23/27 Implement PAPR CRQ hypercalls
In reply to David GibsonFrom: Ben Herrenschmidt <[email protected]>
This patch implements the infrastructure and hypercalls necessary for the PAPR specified CRQ (Command Request Queue) mechanism. This general request queueing system is used by many of the PAPR virtual IO devices, including the virtual scsi adapter.
--- hw/spapr.c | 2 +- hw/spapr_vio.c | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/spapr_vio.h | 12 ++++ target-ppc/kvm_ppc.h | 11 ++++ 4 files changed, 184 insertions(+), 1 deletions(-)
hw/spapr.c +1 -1
@@ -67,7 +67,7 @@ static void *spapr_create_fdt(int *fdt_size, ram_addr_t ramsize,uint32_t end_prop =cpu_to_be32 (initrd_base + initrd_size);uint32_t pft_size_prop[] = {0 ,cpu_to_be32 (hash_shift)};char hypertas_prop[] ="hcall-pft\0hcall-term\0hcall-dabr\0hcall-interrupt" -"\0hcall-tce" ; +"\0hcall-tce\0hcall-vio" ;uint32_t interrupt_server_ranges_prop[] = {0 ,cpu_to_be32 (smp_cpus)};int i;char *modelname;
hw/spapr_vio.c +160 -0
178 lines not on this page · raw message
hw/spapr_vio.h +12 -0
@@ -32,10 +32,19 @@ enum VIOsPAPR_TCEAccess { SPAPR_TCE_RW = 3, }; +struct VIOsPAPRDevice ; +typedef struct VIOsPAPR_RTCE {uint64_t tce; }VIOsPAPR_RTCE ; +typedef struct VIOsPAPR_CRQ { +uint64_t qladdr; +uint32_t qsize; +uint32_t qnext; +int (*SendFunc)(struct VIOsPAPRDevice *vdev,uint8_t *crq); +}VIOsPAPR_CRQ ; + typedef struct VIOsPAPRDevice { DeviceState qdev; uint32_t reg;
@@ -44,6 +53,7 @@ typedef struct VIOsPAPRDevice {target_ulong signal_state;uint32_t rtce_window_size;VIOsPAPR_RTCE *rtce_table; +VIOsPAPR_CRQ crq; } VIOsPAPRDevice; typedef struct VIOsPAPRBus {
@@ -81,6 +91,8 @@ void stw_tce(VIOsPAPRDevice *dev, uint64_t taddr, uint32_t val);void stq_tce (VIOsPAPRDevice *dev,uint64_t taddr,uint64_t val);uint64_t ldq_tce (VIOsPAPRDevice *dev,uint64_t taddr); +int spapr_vio_send_crq (VIOsPAPRDevice *dev,uint8_t *crq); +void vty_putchars (VIOsPAPRDevice *sdev,uint8_t *buf,int len); void spapr_vty_create(VIOsPAPRBus *bus, uint32_t reg, CharDriverState *chardev,
target-ppc/kvm_ppc.h +11 -0
@@ -18,6 +18,17 @@ uint32_t kvmppc_get_tbfreq(void);int kvmppc_get_hypercall (CPUState *env,uint8_t *buf,int buf_len);int kvmppc_set_interrupt (CPUState *env,int irq,int level); +#ifndef CONFIG_KVM +#define kvmppc_eieio () do { } while (0) +#else +#define kvmppc_eieio () \ + do { \ + if (kvm_enabled()) { \ + asm volatile("eieio" : : : "memory"); \ + } \ + } while (0) +#endif +#ifndef KVM_INTERRUPT_SET #define KVM_INTERRUPT_SET -1#endif
Signature · 1 line
1.7.1
PATCH 24/27 Implement PAPR virtual SCSI interface (ibmvscsi)
In reply to David GibsonFrom: Ben Herrenschmidt <[email protected]>
This patch implements the infrastructure and hypercalls necessary for the PAPR specified Virtual SCSI interface. This is the normal method for providing (virtual) disks to PAPR partitions.
--- Makefile.target | 2 +- hw/ppc-viosrp.h | 216 ++++++++++++ hw/spapr.c | 8 + hw/spapr_vio.h | 3 + hw/spapr_vscsi.c | 988 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/srp.h | 240 +++++++++++++ 6 files changed, 1456 insertions(+), 1 deletions(-) create mode 100644 hw/ppc-viosrp.h create mode 100644 hw/spapr_vscsi.c create mode 100644 hw/srp.h
Makefile.target +1 -1
@@ -234,7 +234,7 @@ obj-ppc-y += ppc_newworld.o # IBM pSeries (sPAPR) ifeq ($(CONFIG_FDT)$(TARGET_PPC64),yy) obj-ppc-y += spapr.o spapr_hcall.o spapr_rtas.o spapr_vio.o -obj-ppc-y += xics.o spapr_vty.o spapr_llan.o +obj-ppc-y += xics.o spapr_vty.o spapr_llan.o spapr_vscsi.o endif # PowerPC 4xx boards obj-ppc-y += ppc4xx_devs.o ppc4xx_pci.o ppc405_uc.o ppc405_boards.o
hw/ppc-viosrp.h new file +216 -0
216 lines not on this page · raw message
hw/spapr.c +8 -0
@@ -28,6 +28,7 @@#include "hw.h" #include "elf.h" #include "net.h" +#include "blockdev.h" #include "hw/boards.h" #include "hw/ppc.h"
@@ -353,6 +354,12 @@ static void ppc_spapr_init(ram_addr_t ram_size, } } +for (i =0 ; i <=drive_get_max_bus (IF_SCSI ); i++) { +spapr_vscsi_create (spapr->vio_bus,0x2000 + i, +xics_find_qirq (spapr->icp, irq), irq); + irq++; + } +if (kernel_filename) {uint64_t lowaddr =0 ;
@@ -411,6 +418,7 @@ static QEMUMachine spapr_machine = { .max_cpus = MAX_CPUS, .no_vga = 1, .no_parallel = 1, + .use_scsi = 1, };static void spapr_machine_init (void )
hw/spapr_vio.h +3 -0
@@ -101,4 +101,7 @@ void spapr_vty_create(VIOsPAPRBus *bus,void spapr_vlan_create (VIOsPAPRBus *bus,uint32_t reg,NICInfo *nd,qemu_irq qirq,uint32_t vio_irq_num); +void spapr_vscsi_create (VIOsPAPRBus *bus,uint32_t reg, +qemu_irq qirq,uint32_t vio_irq_num); +#endif /* _HW_SPAPR_VIO_H */
hw/spapr_vscsi.c new file +988 -0
988 lines not on this page · raw message
hw/srp.h new file +240 -0
240 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 25/27 Add a PAPR TCE-bypass mechanism for the pSeries machine
In reply to David GibsonFrom: Ben Herrenschmidt <[email protected]>
Usually, PAPR virtual IO devices use a virtual IOMMU mechanism, TCEs, to mediate all DMA transfers. While this is necessary for some sorts of operation, it can be complex to program and slow for others.
This patch implements a mechanism for bypassing TCE translation, treating "IO" addresses as plain (guest) physical memory addresses. This has two main uses:
* Simple, but 64-bit aware programs like firmwares can use the VIO devices
without the complexity of TCE setup.
* The guest OS can optionally use the TCE bypass to improve performance in
suitable situations.
The mechanism used is a per-device flag which disables TCE translation. The flag is toggled with some (hypervisor-implemented) RTAS methods.
--- hw/spapr_vio.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/spapr_vio.h | 5 +++ 2 files changed, 87 insertions(+), 0 deletions(-)
hw/spapr_vio.c +82 -0
@@ -226,6 +226,12 @@ int spapr_tce_dma_write(VIOsPAPRDevice *dev, uint64_t taddr, const void *buf, (unsigned long long)taddr, size);#endif +/* Check for bypass */ +if (dev->flags &VIO_PAPR_FLAG_DMA_BYPASS ) { +cpu_physical_memory_write (taddr, buf, size); +return 0 ; + } +while (size) {uint64_t tce;uint32_t lsize;
@@ -313,6 +319,12 @@ int spapr_tce_dma_read(VIOsPAPRDevice *dev, uint64_t taddr, void *buf, (unsigned long long)taddr, size);#endif +/* Check for bypass */ +if (dev->flags &VIO_PAPR_FLAG_DMA_BYPASS ) { +cpu_physical_memory_read (taddr, buf, size); +return 0 ; + } +while (size) {uint64_t tce;uint32_t lsize;
@@ -513,6 +525,72 @@ int spapr_vio_send_crq(VIOsPAPRDevice *dev, uint8_t *crq)return 0 ; } +/* "quiesce" handling */ + +static void spapr_vio_quiesce_one (VIOsPAPRDevice *dev) +{ + dev->flags &= ~VIO_PAPR_FLAG_DMA_BYPASS ; + +if (dev->rtce_table) { +size_t size = (dev->rtce_window_size >>SPAPR_VIO_TCE_PAGE_SHIFT ) + *sizeof (VIOsPAPR_RTCE); +memset (dev->rtce_table,0 , size); + } + + dev->crq.qladdr =0 ; + dev->crq.qsize =0 ; + dev->crq.qnext =0 ; +} + +static void rtas_set_tce_bypass (sPAPREnvironment *spapr,uint32_t token, +uint32_t nargs,target_ulong args, +uint32_t nret,target_ulong rets) +{ +VIOsPAPRBus *bus = spapr->vio_bus; +VIOsPAPRDevice *dev; +uint32_t unit, enable; + +if (nargs !=2 ) { +rtas_st (rets,0 ,-3 ); +return ; + } + unit =rtas_ld (args,0 ); + enable =rtas_ld (args,1 ); + dev =spapr_vio_find_by_reg (bus, unit); +if (!dev) { +rtas_st (rets,0 ,-3 ); +return ; + } +if (enable) { + dev->flags |=VIO_PAPR_FLAG_DMA_BYPASS ; + }else { + dev->flags &= ~VIO_PAPR_FLAG_DMA_BYPASS ; + } + +rtas_st (rets,0 ,0 ); +} + +static void rtas_quiesce (sPAPREnvironment *spapr,uint32_t token, +uint32_t nargs,target_ulong args, +uint32_t nret,target_ulong rets) +{ +VIOsPAPRBus *bus = spapr->vio_bus; +DeviceState *qdev; +VIOsPAPRDevice *dev =NULL ; + +if (nargs !=0 ) { +rtas_st (rets,0 ,-3 ); +return ; + } + + QLIST_FOREACH(qdev, &bus->bus.children, sibling) { + dev = (VIOsPAPRDevice *)qdev; +spapr_vio_quiesce_one (dev); + } + +rtas_st (rets,0 ,0 ); +} +static int spapr_vio_busdev_init (DeviceState *qdev,DeviceInfo *qinfo) {VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)qinfo;
@@ -591,6 +669,10 @@ VIOsPAPRBus *spapr_vio_bus_init(void)spapr_register_hypercall (H_SEND_CRQ , h_send_crq);spapr_register_hypercall (H_ENABLE_CRQ , h_enable_crq); +/* RTAS calls */ +spapr_rtas_register ("ibm,set-tce-bypass" , rtas_set_tce_bypass); +spapr_rtas_register ("quiesce" , rtas_quiesce); +for (qinfo = device_info_list; qinfo; qinfo = qinfo->next) {VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)qinfo;
hw/spapr_vio.h +5 -0
@@ -48,6 +48,8 @@ typedef struct VIOsPAPR_CRQ { typedef struct VIOsPAPRDevice { DeviceState qdev; uint32_t reg; + uint32_t flags; +#define VIO_PAPR_FLAG_DMA_BYPASS 0x1 qemu_irq qirq; uint32_t vio_irq_num; target_ulong signal_state;
@@ -104,4 +106,7 @@ void spapr_vlan_create(VIOsPAPRBus *bus, uint32_t reg, NICInfo *nd,void spapr_vscsi_create (VIOsPAPRBus *bus,uint32_t reg,qemu_irq qirq,uint32_t vio_irq_num); +int spapr_tce_set_bypass (uint32_t unit,uint32_t enable); +void spapr_vio_quiesce (void ); +#endif /* _HW_SPAPR_VIO_H */
Signature · 1 line
1.7.1
PATCH 26/27 Implement PAPR VPA functions for pSeries shared processor partitions
In reply to David GibsonShared-processor partitions are those where a CPU is time-sliced between partitions, rather than being permanently dedicated to a single partition. qemu emulated partitions, since they are just scheduled with the qemu user process, behave mostly like shared processor partitions.
In order to better support shared processor partitions (splpar), PAPR defines the "VPA" (Virtual Processor Area), a shared memory communication channel between the hypervisor and partitions. There are also two additional shared memory communication areas for specialized purposes associated with the VPA.
A VPA is not essential for operating an splpar, though it can be necessary for obtaining accurate performance measurements in the presence of runtime partition switching.
Most importantly, however, the VPA is a prerequisite for PAPR's H_CEDE, hypercall, which allows a partition OS to give up it's shared processor timeslices to other partitions when idle.
This patch implements the VPA and H_CEDE hypercalls in qemu. We don't implement any of the more advanced statistics which can be communicated through the VPA. However, this is enough to make normal pSeries kernels do an effective power-save idle on an emulated pSeries, significantly reducing the host load of a qemu emulated pSeries running an idle guest OS.
--- hw/spapr.c | 2 +- hw/spapr_hcall.c | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ target-ppc/cpu.h | 7 ++ 3 files changed, 200 insertions(+), 1 deletions(-)
hw/spapr.c +1 -1
@@ -68,7 +68,7 @@ static void *spapr_create_fdt(int *fdt_size, ram_addr_t ramsize,uint32_t end_prop =cpu_to_be32 (initrd_base + initrd_size);uint32_t pft_size_prop[] = {0 ,cpu_to_be32 (hash_shift)};char hypertas_prop[] ="hcall-pft\0hcall-term\0hcall-dabr\0hcall-interrupt" -"\0hcall-tce\0hcall-vio" ; +"\0hcall-tce\0hcall-vio\0hcall-splpar" ;uint32_t interrupt_server_ranges_prop[] = {0 ,cpu_to_be32 (smp_cpus)};int i;char *modelname;
hw/spapr_hcall.c +192 -0
210 lines not on this page · raw message
target-ppc/cpu.h +7 -0
@@ -721,6 +721,13 @@ struct CPUPPCState {uint32_t flags;uint64_t insns_flags; +#if defined(TARGET_PPC64 ) && !defined(CONFIG_USER_ONLY ) +target_phys_addr_t vpa; +target_phys_addr_t slb_shadow; +target_phys_addr_t dispatch_trace_log; +uint32_t dtl_size; +#endif /* TARGET_PPC64 */ +int error_code;uint32_t pending_interrupts;#if !defined(CONFIG_USER_ONLY )
Signature · 1 line
1.7.1
Quoted 10 lines · David Gibson
This patch series adds a "pseries" machine to qemu, allowing it to emulate IBM pSeries logical partitions. More specifically it implements the interface defined by the "PowerPC Architecture Platform Requirements" document (PAPR, or sPAPR for short).
Along the way we add a bunch of support for more modern ppc CPUs than are currently supported. It also makes some significant cleanups to the translation code for hash page table based ppc MMUs.
Please apply.
Anyone with commit rights able to merge this? Full series is:
Alex
Quoted 7 lines · Alexander Graf
Quoted 5 lines · David Gibson
This patch series adds a "pseries" machine to qemu, allowing it to emulate IBM pSeries logical partitions. More specifically it implements the interface defined by the "PowerPC Architecture Platform Requirements" document (PAPR, or sPAPR for short).
Quoted 6 lines
Quoted 5 lines
Along the way we add a bunch of support for more modern ppc CPUs than are currently supported. It also makes some significant cleanups to the translation code for hash page table based ppc MMUs.
Please apply.
Anyone with commit rights able to merge this? Full series is:
Yup, ideally I'd prefer to get a pull request from you with a Signed-off-by though.
If it's too much trouble, I'll do it myself.
Regards,
Anthony Liguori
Quoted 5 lines
Acked-by Alexander Graf<[email protected]>Alex
Quoted 12 lines · Anthony Liguori
Quoted 11 lines · Alexander Graf
Quoted 9 lines · David Gibson
This patch series adds a "pseries" machine to qemu, allowing it to emulate IBM pSeries logical partitions. More specifically it implements the interface defined by the "PowerPC Architecture Platform Requirements" document (PAPR, or sPAPR for short).
Along the way we add a bunch of support for more modern ppc CPUs than are currently supported. It also makes some significant cleanups to the translation code for hash page table based ppc MMUs.
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Please apply.
Anyone with commit rights able to merge this? Full series is:
Yup, ideally I'd prefer to get a pull request from you with a Signed-off-by though.
If it's too much trouble, I'll do it myself.
Ah, sure, I can do that.
Alex
Quoted 10 lines · David Gibson
This patch series adds a "pseries" machine to qemu, allowing it to emulate IBM pSeries logical partitions. More specifically it implements the interface defined by the "PowerPC Architecture Platform Requirements" document (PAPR, or sPAPR for short).
Along the way we add a bunch of support for more modern ppc CPUs than are currently supported. It also makes some significant cleanups to the translation code for hash page table based ppc MMUs.
Please apply.
So what's a typical invocation for this? Is:
qemu-system-ppc64 -m pseries foo.img -nographics
Enough or is something more sophisticated required?
Regards,
Anthony Liguori
Quoted 34 lines
---
Changes since v5 of this series:
* Include source for SLOF as a git submodule
* Move our private hcalls (well. only one so far) to a range explicitly reserved by PAPR for this purpose.
* Allocate an ample 1024 irqs in the XICS controller, rather than having a somewhat dubious calculation of precisely how many we need.Changes since v4 of this series:
* Fix build breakages for powerpc targets other than ppc64 full system.
* Since the pseries platform requires libfdt, only compile it whenconfigured with --enable-fdt* Give an informative error if invoked with insufficient guest RAM to run the partition firmware. Without this, giving insufficient RAM
- such as qemu's default 64M - would lead to the firmware failing cryptically partway through boot.Changes since v3 of this series:
* Many, many checkpatch fixups
* Integrated feedback from qemu-devel list
* Added in-partition SLOF firmwareChanges since v2 of this series:
* Assorted bugfixes and cleanups.Changes since v1 of this series:
* numerous coding style fixups
* incorporated most review comments from initial version
* moved to a wholly dynamic hypercall registration scheme
* assorted other cleanups
* many more patches implementing VIO devices
Quoted 10 lines · Anthony Liguori
Quoted 9 lines · David Gibson
This patch series adds a "pseries" machine to qemu, allowing it to emulate IBM pSeries logical partitions. More specifically it implements the interface defined by the "PowerPC Architecture Platform Requirements" document (PAPR, or sPAPR for short).
Along the way we add a bunch of support for more modern ppc CPUs than are currently supported. It also makes some significant cleanups to the translation code for hash page table based ppc MMUs.
Quoted 5 lines
Quoted 1 line
Please apply.
So what's a typical invocation for this? Is:
qemu-system-ppc64 -m pseries foo.img -nographics
If you run an image that requires firmare, you also need to pass in -m with at least 512MB, otherwise yes, that's how it works :).
Alex
Quoted 12 lines · Alexander Graf
Quoted 10 lines · Anthony Liguori
Quoted 9 lines · David Gibson
This patch series adds a "pseries" machine to qemu, allowing it to emulate IBM pSeries logical partitions. More specifically it implements the interface defined by the "PowerPC Architecture Platform Requirements" document (PAPR, or sPAPR for short).
Along the way we add a bunch of support for more modern ppc CPUs than are currently supported. It also makes some significant cleanups to the translation code for hash page table based ppc MMUs.
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
Please apply.
So what's a typical invocation for this? Is:
qemu-system-ppc64 -m pseries foo.img -nographics
If you run an image that requires firmare, you also need to pass in -m with at least 512MB, otherwise yes, that's how it works :).
FYI, trying to do a Debian install results in:
Trying to write invalid spr 536 218 at 00000000014034d4
Followed by a tight loop of writing empty characters to the serial port.
My command is:
ppc64-softmmu/qemu-system-ppc64 -cdrom ~/isos/debian-6.0.1a-powerpc-DVD-1.iso -boot d -m 512 -serial vc -monitor stdio -M pseries
Regards,
Anthony Liguori
Quoted 3 lines
Alex
Quoted 21 lines · Anthony Liguori
Quoted 12 lines · Alexander Graf
Quoted 10 lines · Anthony Liguori
Quoted 9 lines · David Gibson
This patch series adds a "pseries" machine to qemu, allowing it to emulate IBM pSeries logical partitions. More specifically it implements the interface defined by the "PowerPC Architecture Platform Requirements" document (PAPR, or sPAPR for short).
Along the way we add a bunch of support for more modern ppc CPUs than are currently supported. It also makes some significant cleanups to the translation code for hash page table based ppc MMUs.
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
Please apply.
So what's a typical invocation for this? Is:
qemu-system-ppc64 -m pseries foo.img -nographics
If you run an image that requires firmare, you also need to pass in -m with at least 512MB, otherwise yes, that's how it works :).
FYI, trying to do a Debian install results in:
Quoted 7 lines
Trying to write invalid spr 536 218 at
00000000014034d4Followed by a tight loop of writing empty characters to the serial port.
My command is:
ppc64-softmmu/qemu-system-ppc64 -cdrom ~/isos/debian-6.0.1a-powerpc-DVD-1.iso -boot d -m 512 -serial vc -monitor stdio -M pseries
Weird. SLES11SP1 works pretty well:
agraf@toonie:~/git/qemu> ./ppc64-softmmu/qemu-system-ppc64 -M pseries -nographic -m 1G -cdrom /mounts/dist/install/SLES-11-SP1-GM/SLES-11-SP1-DVD-ppc64-GM-DVD1.iso
SLOF ********************************************************************** QEMU Starting
Build Date = Mar 23 2011 15:55:48
FW Version = dgibson@(private build)
Press "s" to enter Open Firmware.
Populating /vdevice methods
Populating /vdevice/vty@0
Populating /vdevice/l-lan@1000
Populating /vdevice/v-scsi@2000
VSCSI: Initializing
VSCSI: Looking for disks
SCSI ID 2 CD-ROM : "QEMU QEMU CD-ROM 0.14"
No NVRAM common partition, re-initializing...
Welcome to Open Firmware
Copyright (c) 2004, 2011 IBM Corporation All rights reserved. This program and the accompanying materials are made available under the terms of the BSD License available at
http://www.opensource.org/licenses/bsd-license.php
Trying to load: from: disk ... E3405: No such device Trying to load: from: cdrom ... Successfully loaded
yaboot starting: loaded at 00040000 000657a8 (0/0/0e1004c4; sp: 0e149ff0) Config file 'yaboot.cnf' read, 285 bytes
Welcome to SuSE Linux Enterprise 11!
Type "install" to start the YaST installer on this CD/DVD Type "slp" to start the YaST install via network Type "rescue" to start the rescue system on this CD/DVD
Welcome to yaboot version r22.8-r1190.SuSE
booted from '/vdevice/v-scsi@2000/cdrom@2,0:\suseboot\yaboot.ibm' running with firmware 'SLOF,HEAD' on model 'QEMU'
Enter "help" to get some basic usage information
boot:
Please wait, loading kernel...
Allocated 01800000 bytes for executable @ 00d00000
Elf32 kernel loaded...
SuSE Linux zImage starting: loaded at 00d00000-0239cd30 (4000000/0/0e1004c4; sp: 0e149d70)
uncompressing ELF header done. (00000100 bytes)
Allocated 0164c090 bytes for kernel @ 02500000
Allocated 0122a5ba bytes for initrd @ 03b4d000
uncompressing kernel done. (00f5a920 bytes)
entering kernel at 02510000(3b4d000/122a5ba/0e1004c4)
OF stdout device is: /vdevice/vty@0
Preparing to boot Linux version 2.6.32.12-0.7-ppc64 (geeko@buildhost) (gcc version 4.3.4 [gcc-4_3-branch revision 152973] (SUSE Linux) ) #1 SMP 2010-05-20 11:14:20 +0200 Max number of cores passed to firmware: 0x0000000000000400
Calling ibm,client-architecture-support... not implemented
couldn't open /packages/elf-loader
command line: quiet sysrq=1 insmod=sym53c8xx insmod=ipr
memory layout at init:
memory_limit : 0000000000000000 (16 MB aligned)
alloc_bottom : 0000000004d80000
alloc_top : 0000000030000000
alloc_top_hi : 0000000040000000
rmo_top : 0000000030000000
ram_top : 0000000040000000
instantiating rtas at 0x000000002fff0000... done
boot cpu hw idx 0000000000000000
copying OF device tree...
Building dt strings...
Building dt structure...
Device tree strings 0x0000000004d90000 -> 0x0000000004d904e4
Device tree struct 0x0000000004da0000 -> 0x0000000004db0000
Calling quiesce...
VSCSI: Cleaning up
returning from prom_init
CF000012
CF000015ch
CF000020ne
CF000021t
SUSE Linux
#1 SMP 2010-05-2rtas_flash: no firmware flash support
Moving into tmpfs... done.
Integrating /parts/00_lib
insmod /modules/squashfs.ko
mount: /parts/00_lib: we need a loop device
mount: using /dev/loop0
Integrating /parts/01_usr
mount: /parts/01_usr: we need a loop device
mount: using /dev/loop1
Quoted 1 line
Quoted 1 line
Quoted 1 line
SUSE Linux Enterprise Server 11 installation program v3.3.59 (c) 1996-2010 SUSE Linux Products GmbH <<<
Starting udev...
[...]
Quoted 12 lines · Alexander Graf
Quoted 10 lines · Anthony Liguori
Quoted 9 lines · David Gibson
This patch series adds a "pseries" machine to qemu, allowing it to emulate IBM pSeries logical partitions. More specifically it implements the interface defined by the "PowerPC Architecture Platform Requirements" document (PAPR, or sPAPR for short).
Along the way we add a bunch of support for more modern ppc CPUs than are currently supported. It also makes some significant cleanups to the translation code for hash page table based ppc MMUs.
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
Please apply.
So what's a typical invocation for this? Is:
qemu-system-ppc64 -m pseries foo.img -nographics
If you run an image that requires firmare, you also need to pass in -m with at least 512MB, otherwise yes, that's how it works :).
Here's the output on the serial console. Looks like it's in a tight loop probably writing \r or something and redrawing the prompt which our console emulation doesn't like.
E3406: Client application returned an error: undefined word
..`. .. ....... .. ...... .......
..`...`''.`'. .''``````..''. .`''```''`. `''``````
.`` .:' ': `''..... .''. ''` .''..''.......
``.':.';. ``````''`.''. .''. ''``''`````'`
``.':':` .....`''.`'`...... `'`.....`''.`'`
.`.`'`` .'`'`````. ``'''''' ``''`'''`. `'` Type 'boot' and press return to continue booting the system.
Type 'reset-all' and press return to reboot the system.
( 700 ) Program Exception [ 1 ]
R0 .. R7 R8 .. R15 R16 .. R23 R24 .. R31 000000000e14c0b8 0000000000000000 000000000e952e14 000000000e952e16 000000000e952da0 0000000000000000 0000000000000001 000000000e952e18 000000000e10e680 0000000000000000 0000000000000000 000000000e953020 0000000000000000 000000000e950008 0000000000010000 0000000000000000 0000000000000000 0000000048000024 000000000e1069d0 ffffffffffffffff 0000000000000001 0000000000000000 000000000e952e15 000000000e952f17 000000000e138020 0000000000000000 000000000e952e10 0000000000000008 000000000e14c0c8 000000000e950010 0000000000000003 600000002c050000
CR / XER LR / CTR SRR0 / SRR1 DAR / DSISR
88000022 0000000000000028 000000000049c33c 0000000000000000
0000000020000000 0000000000000000 0000000000082000 00000000
Regards,
Anthony Liguori
Quoted 3 lines
Alex
Quoted 30 lines · Anthony Liguori
Quoted 12 lines · Alexander Graf
Quoted 10 lines · Anthony Liguori
Quoted 9 lines · David Gibson
This patch series adds a "pseries" machine to qemu, allowing it to emulate IBM pSeries logical partitions. More specifically it implements the interface defined by the "PowerPC Architecture Platform Requirements" document (PAPR, or sPAPR for short).
Along the way we add a bunch of support for more modern ppc CPUs than are currently supported. It also makes some significant cleanups to the translation code for hash page table based ppc MMUs.
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
Please apply.
So what's a typical invocation for this? Is:
qemu-system-ppc64 -m pseries foo.img -nographics
If you run an image that requires firmare, you also need to pass in -m with at least 512MB, otherwise yes, that's how it works :).
Here's the output on the serial console. Looks like it's in a tight loop probably writing \r or something and redrawing the prompt which our console emulation doesn't like.
E3406: Client application returned an error: undefined word
..`. .. ....... .. ...... ....... ..`...`''.`'. .''``````..''. .`''```''`. `''`````` .`` .:' ': `''..... .''. ''` .''..''....... ``.':.';. ``````''`.''. .''. ''``''`````'` ``.':':` .....`''.`'`...... `'`.....`''.`'` .`.`'`` .'`'`````. ``'''''' ``''`'''`. `'`
Quoted 6 lines
Type 'boot' and press return to continue booting the system.
Type 'reset-all' and press return to reboot the system.( 700 ) Program Exception [ 1 ]
This probably means that you're trying to run a ppc32 kernel :). No promises on that guess though.
Alex
Quoted 38 lines · Alexander Graf
Quoted 35 lines · Anthony Liguori
Quoted 12 lines · Alexander Graf
Quoted 10 lines · Anthony Liguori
Quoted 9 lines · David Gibson
This patch series adds a "pseries" machine to qemu, allowing it to emulate IBM pSeries logical partitions. More specifically it implements the interface defined by the "PowerPC Architecture Platform Requirements" document (PAPR, or sPAPR for short).
Along the way we add a bunch of support for more modern ppc CPUs than are currently supported. It also makes some significant cleanups to the translation code for hash page table based ppc MMUs.
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
Please apply.
So what's a typical invocation for this? Is:
qemu-system-ppc64 -m pseries foo.img -nographics
If you run an image that requires firmare, you also need to pass in -m with at least 512MB, otherwise yes, that's how it works :).
Here's the output on the serial console. Looks like it's in a tight loop probably writing \r or something and redrawing the prompt which our console emulation doesn't like.
E3406: Client application returned an error: undefined word
..`. .. ....... .. ...... ....... ..`...`''.`'. .''``````..''. .`''```''`. `''`````` .`` .:' ': `''..... .''. ''` .''..''....... ``.':.';. ``````''`.''. .''. ''``''`````'` ``.':':` .....`''.`'`...... `'`.....`''.`'` .`.`'`` .'`'`````. ``'''''' ``''`'''`. `'`Type 'boot' and press return to continue booting the system.
Type 'reset-all' and press return to reboot the system.
Quoted 3 lines
Quoted 1 line
( 700 ) Program Exception [ 1 ]
This probably means that you're trying to run a ppc32 kernel :). No promises on that guess though.
Yup, manually specifying "install64" works.
Alex
Quoted 38 lines · Alexander Graf
Quoted 36 lines · Alexander Graf
Quoted 34 lines · Anthony Liguori
Quoted 12 lines · Alexander Graf
Quoted 10 lines · Anthony Liguori
Quoted 9 lines · David Gibson
This patch series adds a "pseries" machine to qemu, allowing it to emulate IBM pSeries logical partitions. More specifically it implements the interface defined by the "PowerPC Architecture Platform Requirements" document (PAPR, or sPAPR for short).
Along the way we add a bunch of support for more modern ppc CPUs than are currently supported. It also makes some significant cleanups to the translation code for hash page table based ppc MMUs.
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
Please apply.
So what's a typical invocation for this? Is:
qemu-system-ppc64 -m pseries foo.img -nographics
If you run an image that requires firmare, you also need to pass in -m with at least 512MB, otherwise yes, that's how it works :).
Here's the output on the serial console. Looks like it's in a tight loop probably writing \r or something and redrawing the prompt which our console emulation doesn't like.
E3406: Client application returned an error: undefined word
..`. .. ....... .. ...... ....... ..`...`''.`'. .''``````..''. .`''```''`. `''`````` .`` .:' ': `''..... .''. ''` .''..''....... ``.':.';. ``````''`.''. .''. ''``''`````'` ``.':':` .....`''.`'`...... `'`.....`''.`'` .`.`'`` .'`'`````. ``'''''' ``''`'''`. `'`Type 'boot' and press return to continue booting the system.
Type 'reset-all' and press return to reboot the system.
Quoted 3 lines
Quoted 2 lines
Quoted 1 line
( 700 ) Program Exception [ 1 ]
This probably means that you're trying to run a ppc32 kernel :). No promises on that guess though.
Yup, manually specifying "install64" works.
Ah, perfect! I guess I'm showing my naivety when it comes to Power here :-)
Regards,
Anthony Liguori
Quoted 3 lines
Alex
Quoted 39 lines · Anthony Liguori
Quoted 38 lines · Alexander Graf
Quoted 36 lines · Alexander Graf
Quoted 34 lines · Anthony Liguori
Quoted 12 lines · Alexander Graf
Quoted 10 lines · Anthony Liguori
Quoted 9 lines · David Gibson
This patch series adds a "pseries" machine to qemu, allowing it to emulate IBM pSeries logical partitions. More specifically it implements the interface defined by the "PowerPC Architecture Platform Requirements" document (PAPR, or sPAPR for short).
Along the way we add a bunch of support for more modern ppc CPUs than are currently supported. It also makes some significant cleanups to the translation code for hash page table based ppc MMUs.
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
Please apply.
So what's a typical invocation for this? Is:
qemu-system-ppc64 -m pseries foo.img -nographics
If you run an image that requires firmare, you also need to pass in -m with at least 512MB, otherwise yes, that's how it works :).
Here's the output on the serial console. Looks like it's in a tight loop probably writing \r or something and redrawing the prompt which our console emulation doesn't like.
E3406: Client application returned an error: undefined word
..`. .. ....... .. ...... ....... ..`...`''.`'. .''``````..''. .`''```''`. `''`````` .`` .:' ': `''..... .''. ''` .''..''....... ``.':.';. ``````''`.''. .''. ''``''`````'` ``.':':` .....`''.`'`...... `'`.....`''.`'` .`.`'`` .'`'`````. ``'''''' ``''`'''`. `'`Type 'boot' and press return to continue booting the system.
Type 'reset-all' and press return to reboot the system.
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line
( 700 ) Program Exception [ 1 ]
This probably means that you're trying to run a ppc32 kernel :). No promises on that guess though.
Yup, manually specifying "install64" works.
Ah, perfect! I guess I'm showing my naivety when it comes to Power here :-)
Well, the bootloader should actually be able to detect if it needs to load the ppc64 or ppc32 kernel. I'm not sure why it doesn't. It's either a bug in Debian or in SLOF :).
Alex