sparc64: improve mmu context handling
cover sparc64: improve mmu context handling
The following series implements more sparc64 MMU bits.
We now support secondary and nucleus contexts referenced by alternate space access instructions, and handle global MMU translation entries.
---
Igor V. Kovalenko (3):
sparc64: more ultrasparc asi extensions for disassembler
sparc64: implement global translation table entries
sparc64: handle asi referencing nucleus and secondary MMU contexts
softmmu_exec.h | 25 ++++ sparc-dis.c | 22 ++++ target-sparc/cpu.h | 31 +++++ target-sparc/exec.h | 4 + target-sparc/helper.c | 71 +++++++---- target-sparc/op_helper.c | 287 ++++++++++++++++++++++++++++++++++------------ 6 files changed, 336 insertions(+), 104 deletions(-)
Signature · 2 lines
Kind regards, Igor V. Kovalenko
PATCH 1/3 sparc64: more ultrasparc asi extensions for disassembler
From: Igor V. Kovalenko <[email protected]>
--- sparc-dis.c | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-)
sparc-dis.c +22 -0
@@ -2153,6 +2153,28 @@ static const arg asi_table_v9[] = { 0x8a, "#ASI_PRIMARY_NOFAULT_LITTLE" }, { 0x8b, "#ASI_SECONDARY_NOFAULT_LITTLE" },/* These are UltraSPARC extensions. */ + { 0x14, "#ASI_PHYS_USE_EC"}, + { 0x15, "#ASI_PHYS_BYPASS_EC_WITH_EBIT"}, + { 0x45, "#ASI_LSU_CONTROL_REG"}, + { 0x47, "#ASI_DCACHE_TAG"}, + { 0x4a, "#ASI_UPA_CONFIG_REG"}, + { 0x50, "#ASI_IMMU" }, + { 0x51, "#ASI_IMMU_TSB_8KB_PTR_REG" }, + { 0x52, "#ASI_IMMU_TSB_64KB_PTR_REG" }, +/*{ 0x53, "#reserved?" },*/ + { 0x54, "#ASI_ITLB_DATA_IN_REG" }, + { 0x55, "#ASI_ITLB_DATA_ACCESS_REG" }, + { 0x56, "#ASI_ITLB_TAG_READ_REG" }, + { 0x57, "#ASI_IMMU_DEMAP" }, + { 0x58, "#ASI_DMMU" }, + { 0x59, "#ASI_DMMU_TSB_8KB_PTR_REG" }, + { 0x5a, "#ASI_DMMU_TSB_64KB_PTR_REG" }, + { 0x5b, "#ASI_DMMU_TSB_DIRECT_PTR_REG" }, + { 0x5c, "#ASI_DTLB_DATA_IN_REG" }, + { 0x5d, "#ASI_DTLB_DATA_ACCESS_REG" }, + { 0x5e, "#ASI_DTLB_TAG_READ_REG" }, + { 0x5f, "#ASI_DMMU_DEMAP" }, + { 0x67, "#ASI_IC_TAG"},/* FIXME: There are dozens of them. Not sure we want them all. Most are for kernel building but some are for vis type stuff. */ { 0, NULL }
PATCH 2/3 sparc64: implement global translation table entries
In reply to Igor V. KovalenkoFrom: Igor V. Kovalenko <[email protected]>
- match global tte against any context
- show global tte in MMU dump
--- target-sparc/cpu.h | 18 ++++++++++++++++ target-sparc/helper.c | 33 ++++++++++++----------------- target-sparc/op_helper.c | 52 ++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 75 insertions(+), 28 deletions(-)
target-sparc/cpu.h +18 -0
@@ -513,6 +513,24 @@ static inline void cpu_set_cwp(CPUSPARCState *env1, int new_cwp)/* sun4m.c, sun4u.c */ void cpu_check_irqs (CPUSPARCState *env); +#if defined (TARGET_SPARC64 ) + +static inline int compare_masked (uint64_t x,uint64_t y,uint64_t mask) +{ +return (x & mask) == (y & mask); +} + +#define MMU_CONTEXT_BITS 13 +#define MMU_CONTEXT_MASK ((1 << MMU_CONTEXT_BITS) - 1) + +static inline int tlb_compare_context (const SparcTLBEntry *tlb, +uint64_t context) +{ +return compare_masked (context, tlb->tag,MMU_CONTEXT_MASK ); +} + +#endif +static inline void PUT_PSR (CPUSPARCState *env1,target_ulong val) { env1->psr = val &PSR_ICC ;
target-sparc/helper.c +14 -19
@@ -381,17 +381,11 @@ static inline target_phys_addr_t ultrasparc_truncate_physical(uint64_t x)* UltraSparc IIi I/DMMUs */ -static inline int compare_masked (uint64_t x,uint64_t y,uint64_t mask) -{ -return (x & mask) == (y & mask); -} -// Returns true if TTE tag is valid and matches virtual address value in context // requires virtual address mask value calculated from TTE entry size static inline int ultrasparc_tag_match (SparcTLBEntry *tlb,uint64_t address,uint64_t context, -target_phys_addr_t *physical, -int is_nucleus) +target_phys_addr_t *physical) {uint64_t mask;
@@ -413,8 +407,7 @@ static inline int ultrasparc_tag_match(SparcTLBEntry *tlb,// valid, context match, virtual address match? if (TTE_IS_VALID (tlb->tte) && - ((is_nucleus &&compare_masked (0 , tlb->tag,0x1fff )) - ||TTE_IS_GLOBAL (tlb->tte) ||compare_masked (context, tlb->tag,0x1fff )) + (TTE_IS_GLOBAL (tlb->tte) ||tlb_compare_context (tlb, context)) &&compare_masked (address, tlb->tag, mask)) {// decode physical address
@@ -431,7 +424,6 @@ static int get_physical_address_data(CPUState *env, {unsigned int i;uint64_t context; -int is_nucleus;if ((env->lsu &DMMU_E ) ==0 ) {/* DMMU disabled */ *physical =ultrasparc_truncate_physical (address);
@@ -439,14 +431,16 @@ static int get_physical_address_data(CPUState *env,return 0 ; } - context = env->dmmu.mmu_primary_context &0x1fff ; - is_nucleus = env->tl >0 ; +if (env->tl ==0 ) { + context = env->dmmu.mmu_primary_context &0x1fff ; + }else { + context =0 ; + }for (i =0 ; i <64 ; i++) {// ctx match, vaddr match, valid? if (ultrasparc_tag_match (&env->dtlb[i], - address, context, physical, - is_nucleus)) { + address, context, physical)) {// access ok? if (((env->dtlb[i].tte &0x4 ) && is_user) || (!(env->dtlb[i].tte &0x2 ) && (rw ==1 ))) {
@@ -492,7 +486,6 @@ static int get_physical_address_code(CPUState *env, {unsigned int i;uint64_t context; -int is_nucleus;if ((env->lsu &IMMU_E ) ==0 || (env->pstate &PS_RED ) !=0 ) {/* IMMU disabled */
@@ -501,14 +494,16 @@ static int get_physical_address_code(CPUState *env,return 0 ; } - context = env->dmmu.mmu_primary_context &0x1fff ; - is_nucleus = env->tl >0 ; +if (env->tl ==0 ) { + context = env->dmmu.mmu_primary_context &0x1fff ; + }else { + context =0 ; + }for (i =0 ; i <64 ; i++) {// ctx match, vaddr match, valid? if (ultrasparc_tag_match (&env->itlb[i], - address, context, physical, - is_nucleus)) { + address, context, physical)) {// access ok? if ((env->itlb[i].tte &0x4 ) && is_user) {if (env->immu.sfsr)/* Fault status register */
target-sparc/op_helper.c +43 -9
67 lines not on this page · raw message
Re: [Qemu-devel] [PATCH 2/3] sparc64: implement global translation table entries
Quoted 6 lines · Igor V. Kovalenko
From: Igor V. Kovalenko <[email protected]>
- match global tte against any context
- show global tte in MMU dumpSigned-off-by Igor V. Kovalenko <[email protected]>
I get this error:
CC sparc64-softmmu/op_helper.o
cc1: warnings being treated as errors /src/qemu/target-sparc/op_helper.c: In function 'demap_tlb':
/src/qemu/target-sparc/op_helper.c:129: error: 'context' may be used uninitialized in this function
Re: [Qemu-devel] [PATCH 2/3] sparc64: implement global translation table entries
Quoted 6 lines · Blue Swirl
Quoted 5 lines · Igor V. Kovalenko
From: Igor V. Kovalenko <[email protected]>
- match global tte against any context
- show global tte in MMU dump
Quoted 9 lines
Quoted 1 line
Signed-off-by Igor V. Kovalenko <[email protected]>I get this error:
CC sparc64-softmmu/op_helper.o
cc1: warnings being treated as errors /src/qemu/target-sparc/op_helper.c: In function 'demap_tlb':
/src/qemu/target-sparc/op_helper.c:129: error: 'context' may be used uninitialized in this function
My gcc (Gentoo 4.4.3-r2 p1.2) is silent, and looking at the change all 4 possible cases are handled in switch statement.
It should initializes context in 3 usable cases and returns from the 4th which is reserved.
How do we fix this issue?
Signature · 2 lines
Kind regards, Igor V. Kovalenko
Re: [Qemu-devel] [PATCH 2/3] sparc64: implement global translation table entries
Quoted 18 lines · Igor Kovalenko
Quoted 6 lines · Blue Swirl
Quoted 5 lines · Igor V. Kovalenko
From: Igor V. Kovalenko <[email protected]>
- match global tte against any context
- show global tte in MMU dumpQuoted 9 lines
Quoted 1 line
Signed-off-by Igor V. Kovalenko <[email protected]>I get this error:
CCsparc64-softmmu/op_helper.o
cc1: warnings being treated as errors /src/qemu/target-sparc/op_helper.c: In function 'demap_tlb':
/src/qemu/target-sparc/op_helper.c:129: error: 'context' may be used uninitialized in this function
Quoted 2 lines
My gcc (Gentoo 4.4.3-r2 p1.2) is silent, and looking at the change all
4 possible cases are handled in switch statement.
I think gcc is not intelligent enough to know that x & 3 has only 4 possible cases. :-)
Quoted 3 lines
It should initializes context in 3 usable cases and returns from the 4th which is reserved.
How do we fix this issue?
I'd add a default case to one of the cases. Another possibility is to initialize the context with 0 and then make one of the cases empty.
Re: [Qemu-devel] [PATCH 2/3] sparc64: implement global translation table entries
Quoted 25 lines · Blue Swirl
Quoted 18 lines · Igor Kovalenko
On Tue, May 4, 2010 at 12:06 AM, Blue Swirl <[email protected]> wrote:
> On 5/3/10, Igor V. Kovalenko <[email protected]> wrote:
>> From: Igor V. Kovalenko <[email protected]>
>>
>> - match global tte against any context
>> - show global tte in MMU dump
>>
>> Signed-off-by: Igor V. Kovalenko <[email protected]> >
> I get this error:
> CC sparc64-softmmu/op_helper.o
> cc1: warnings being treated as errors
> /src/qemu/target-sparc/op_helper.c: In function 'demap_tlb':
> /src/qemu/target-sparc/op_helper.c:129: error: 'context' may be used > uninitialized in this function
>Quoted 2 lines
My gcc (Gentoo 4.4.3-r2 p1.2) is silent, and looking at the change all 4 possible cases are handled in switch statement.
I think gcc is not intelligent enough to know that x & 3 has only 4 possible cases. :-)
Quoted 7 lines
Quoted 3 lines
It should initializes context in 3 usable cases and returns from the 4th which is reserved.
How do we fix this issue?I'd add a default case to one of the cases. Another possibility is to initialize the context with 0 and then make one of the cases empty.
Added default case, resent this patch only.
Signature · 2 lines
Kind regards, Igor V. Kovalenko
PATCH 3/3 sparc64: handle asi referencing nucleus and secondary MMU contexts
In reply to Igor V. KovalenkoFrom: Igor V. Kovalenko <[email protected]>
- increase max supported MMU modes to 6
- handle nucleus context asi
- handle secondary context asi
- handle non-faulting loads from secondary context
--- softmmu_exec.h | 25 ++++- target-sparc/cpu.h | 13 ++- target-sparc/exec.h | 4 + target-sparc/helper.c | 42 ++++++-- target-sparc/op_helper.c | 235 ++++++++++++++++++++++++++++++++++------------ 5 files changed, 241 insertions(+), 78 deletions(-)
softmmu_exec.h +22 -3
@@ -100,9 +100,28 @@#undef MEMSUFFIX#endif /* (NB_MMU_MODES >= 5) */ -#if (NB_MMU_MODES >5 ) -#error "NB_MMU_MODES > 5 is not supported for now" -#endif /* (NB_MMU_MODES > 5) */ +#if (NB_MMU_MODES >=6 ) + +#define ACCESS_TYPE 5 +#define MEMSUFFIX MMU_MODE5_SUFFIX +#define DATA_SIZE 1 +#include "softmmu_header.h" + +#define DATA_SIZE 2 +#include "softmmu_header.h" + +#define DATA_SIZE 4 +#include "softmmu_header.h" + +#define DATA_SIZE 8 +#include "softmmu_header.h" +#undef ACCESS_TYPE +#undef MEMSUFFIX +#endif /* (NB_MMU_MODES >= 6) */ + +#if (NB_MMU_MODES >6 ) +#error "NB_MMU_MODES > 6 is not supported for now" +#endif /* (NB_MMU_MODES > 6) */ /* these access are slower, they must be as rare as possible */ #define ACCESS_TYPE (NB_MMU_MODES)
target-sparc/cpu.h +12 -1
@@ -224,7 +224,7 @@ enum { #if !defined(TARGET_SPARC64) #define NB_MMU_MODES 2 #else -#define NB_MMU_MODES 3 +#define NB_MMU_MODES 6 typedef struct trap_state { uint64_t tpc; uint64_t tnpc;
@@ -571,6 +571,9 @@ static inline void PUT_CWP64(CPUSPARCState *env1, int cwp)#if !defined(CONFIG_USER_ONLY )void do_unassigned_access (target_phys_addr_t addr,int is_write,int is_exec,int is_asi,int size); +target_phys_addr_t cpu_get_phys_page_nofault (CPUState *env,target_ulong addr, +int mmu_idx); +#endif int cpu_sparc_signal_handler (int host_signum,void *pinfo,void *puc);
@@ -587,10 +590,18 @@ int cpu_sparc_signal_handler(int host_signum, void *pinfo, void *puc);#define MMU_MODE1_SUFFIX _kernel#ifdef TARGET_SPARC64 #define MMU_MODE2_SUFFIX _hypv +#define MMU_MODE3_SUFFIX _nucleus +#define MMU_MODE4_SUFFIX _user_secondary +#define MMU_MODE5_SUFFIX _kernel_secondary#endif #define MMU_USER_IDX 0#define MMU_KERNEL_IDX 1#define MMU_HYPV_IDX 2 +#ifdef TARGET_SPARC64 +#define MMU_NUCLEUS_IDX 3 +#define MMU_USER_SECONDARY_IDX 4 +#define MMU_KERNEL_SECONDARY_IDX 5 +#endif static inline int cpu_mmu_index (CPUState *env1) {
target-sparc/exec.h +4 -0
@@ -13,6 +13,10 @@ register struct CPUSPARCState *env asm(AREG0);#include "cpu.h" #include "exec-all.h" +#if !defined(CONFIG_USER_ONLY ) +#include "softmmu_exec.h" +#endif /* !defined(CONFIG_USER_ONLY) */ +/* op_helper.c */ void do_interrupt (CPUState *env);
target-sparc/helper.c +31 -11
109 lines not on this page · raw message
target-sparc/op_helper.c +172 -63
314 lines not on this page · raw message