sparc64 support TSB related MMU registers
PATCH 1/1 sparc64 support TSB related MMU registers
Hi!
This change allows reading ultrasparc I/D MMU TSB tag target register and TSB pointer register (8k and 64k).
Linux kernel uses TSB for memory management, and with this change it now can use early allocation routines.
I'm testing with linux-2.6.29.1 minimalistic sparc64 uniprocessor build, now kernel is able to start build device tree. Without the change kernel was not able to handle D-MMU miss while creating first device tree node.
Currently it stops shortly after building device tree, trying to find out path to console.
(PS with openbios instance-to-path method fails in client interface call, in the same way
it fails without loading kernel when I try invoking get-instance-path on stdin handle from command prompt.
there fmove invokes memmove() with size argument looking like some pointer which leads to unhandled D-MMU fault)
Signature · 2 lines
Kind regards, Igor V. Kovalenko
op_helper.c +94 -6
@@ -39,6 +39,55 @@#endif #endif +// Calculates TSB pointer value for fault page size 8k or 64k +static uint64_t ultrasparc_tsb_pointer_value (uint64_t tsb_register,uint64_t tag_access_register,int page_size) +{ + +uint64_t tsb_base = tsb_register & ~0x1fffULL ; +int tsb_split = (env->dmmuregs[5 ] &0x1000ULL )?1 :0 ; +int tsb_size = env->dmmuregs[5 ] &0xf ; + +//uint64_t tag_access_context = tag_access_register & 0x1fffULL; +uint64_t tag_access_va = tag_access_register & ~0x1fffULL ; + +// now reorder bits +uint64_t tsb_base_mask = ~0x1fffULL ; +uint64_t va = tag_access_va; + +// move va bits to correct position +if (page_size ==8 *1024 ) { +// VA<21+N:13> 0000 + va >>=9 ; + }else if (page_size ==64 *1024 ) { +// VA<24+N:16> 0000 + va >>=12 ; + } + +if (tsb_size) + tsb_base_mask <<= tsb_size; + +// calculate tsb_base mask and adjust va if split is in use +if (tsb_split) { +//For a split TSB (TSB register split field=1): +if (page_size ==8 *1024 ) { +//8K_POINTER = TSB_Base<63:14+N> 0 VA<21+N:13> 0000 + va &= ~(1ULL << (13 + tsb_size)); + }else if (page_size ==64 *1024 ) { +//64K_POINTER = TSB_Base<63:14+N> 1 VA<24+N:16> 0000 + va |= (1ULL << (13 + tsb_size)); + } + tsb_base_mask <<=1 ; + } + +return ((tsb_base & tsb_base_mask) | (va & ~tsb_base_mask)) & ~0xfULL ; +} + +// Calculates tag target register value by reordering bits in tag access register +static uint64_t ultrasparc_tag_target_value (uint64_t tag_access_register) +{ +return (((tag_access_register &0x1fff )<<48 )|(tag_access_register >>22 )); +} +static inline void address_mask (CPUState *env1,target_ulong *addr) {#ifdef TARGET_SPARC64
@@ -1652,13 +1701,32 @@ {int reg = (addr >>3 ) &0xf ; - ret = env->immuregs[reg]; +if (reg ==0 ) + { +// I-TSB Tag Target register + ret =ultrasparc_tag_target_value (env->immuregs[6 ]); + } +else + { + ret = env->immuregs[reg]; + } +break ; }case 0x51 :// I-MMU 8k TSB pointer + { +// env->immuregs[5] holds I-MMU TSB register value +// env->immuregs[6] holds I-MMU Tag Access register value + ret =ultrasparc_tsb_pointer_value (env->immuregs[5 ], env->immuregs[6 ],8 *1024 ); +break ; + }case 0x52 :// I-MMU 64k TSB pointer -// XXX -break ; + { +// env->immuregs[5] holds I-MMU TSB register value +// env->immuregs[6] holds I-MMU Tag Access register value + ret =ultrasparc_tsb_pointer_value (env->immuregs[5 ], env->immuregs[6 ],64 *1024 ); +break ; + }case 0x55 :// I-MMU data access {int reg = (addr >>3 ) &0x3f ;
@@ -1677,9 +1745,31 @@ {int reg = (addr >>3 ) &0xf ; - ret = env->dmmuregs[reg]; +if (reg ==0 ) + { +// D-TSB Tag Target register + ret =ultrasparc_tag_target_value (env->dmmuregs[6 ]); + } +else + { + ret = env->dmmuregs[reg]; + }break ; } +case 0x59 :// D-MMU 8k TSB pointer + { +// env->dmmuregs[5] holds D-MMU TSB register value +// env->dmmuregs[6] holds D-MMU Tag Access register value + ret =ultrasparc_tsb_pointer_value (env->dmmuregs[5 ], env->dmmuregs[6 ],8 *1024 ); +break ; + } +case 0x5a :// D-MMU 64k TSB pointer + { +// env->dmmuregs[5] holds D-MMU TSB register value +// env->dmmuregs[6] holds D-MMU Tag Access register value + ret =ultrasparc_tsb_pointer_value (env->dmmuregs[5 ], env->dmmuregs[6 ],64 *1024 ); +break ; + }case 0x5d :// D-MMU data access {int reg = (addr >>3 ) &0x3f ;
@@ -1707,8 +1797,6 @@case 0x76 :// E-cache tag case 0x7e :// E-cache tag break ; -case 0x59 :// D-MMU 8k TSB pointer -case 0x5a :// D-MMU 64k TSB pointer case 0x5b :// D-MMU data pointer case 0x48 :// Interrupt dispatch, RO case 0x49 :// Interrupt data receive
Quoted 7 lines · Igor Kovalenko
Hi!
This change allows reading ultrasparc I/D MMU TSB tag target register and TSB pointer register (8k and 64k).
Linux kernel uses TSB for memory management, and with this change it now can use early allocation routines.
Quoted 6 lines
I'm testing with linux-2.6.29.1 minimalistic sparc64 uniprocessor build, now kernel is able to start build device tree. Without the change kernel was not able to handle D-MMU miss while creating first device tree node.
Currently it stops shortly after building device tree, trying to find out path to console.
Nice, though I didn't notice any visible improvement in my tests.
About the patch, there are a few problems:
- it breaks Sparc32
- commented out code is ugly
- if and else should be on the same line as '{' or '}'
- long lines should be wrapped
- in the line:
+ return (((tag_access_register & 0x1fff)<<48)|(tag_access_register >> 22));
there should be white space between ) and << and 48.
Quoted 6 lines
(PS with openbios instance-to-path method fails in client interface call, in the same way
it fails without loading kernel when I try invoking get-instance-path on stdin handle from command prompt.
there fmove invokesmemmove()with size argument looking like some pointer which leads to unhandled D-MMU fault)
Similar very obscure problem was fixed with PPC (r481), the bug was with the PCI nodes.
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 sparc64 support TSB related MMU registers
Posting updated patch to the list...
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines · Blue Swirl
>
> Nice, though I didn't notice any visible improvement in my tests.This early in boot process there is not much to output; and I test recent kernel which may use different startup sequence.
I modified openbios cif handler to output arguments and I now can see visible difference.
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
>
> About the patch, there are a few problems:
> - it breaks Sparc32You mean it stops working?
Does not even build.
Fixed now.
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
> - commented out code is ugly
> - if and else should be on the same line as '{' or '}'
> - long lines should be wrapped
> - in the line:
> + return (((tag_access_register& 0x1fff)<<48)|(tag_access_register >> 22)); > there should be white space between ) and << and 48.
>
Quoted 3 lines
Quoted 3 lines
Also the ")|(" in between is crowded.
Maybe the coding style does not describe this well enough.
BTW Supplying indent template would be great.
Please see the updated patch qemu-sparc64-tsb-asi-2.patch attached.
Signature · 2 lines
Kind regards, Igor V. Kovalenko
op_helper.c +93 -6
@@ -39,6 +39,56 @@#endif #endif +#ifdef TARGET_SPARC64 +// Calculates TSB pointer value for fault page size 8k or 64k +static uint64_t ultrasparc_tsb_pointer (uint64_t tsb_register, +uint64_t tag_access_register, +int page_size) +{ +uint64_t tsb_base = tsb_register & ~0x1fffULL ; +int tsb_split = (env->dmmuregs[5 ] &0x1000ULL ) ?1 :0 ; +int tsb_size = env->dmmuregs[5 ] &0xf ; + +// discard lower 13 bits which hold tag access context +uint64_t tag_access_va = tag_access_register & ~0x1fffULL ; + +// now reorder bits +uint64_t tsb_base_mask = ~0x1fffULL ; +uint64_t va = tag_access_va; + +// move va bits to correct position +if (page_size ==8 *1024 ) { + va >>=9 ; + }else if (page_size ==64 *1024 ) { + va >>=12 ; + } + +if (tsb_size) { + tsb_base_mask <<= tsb_size; + } + +// calculate tsb_base mask and adjust va if split is in use +if (tsb_split) { +if (page_size ==8 *1024 ) { + va &= ~(1ULL << (13 + tsb_size)); + }else if (page_size ==64 *1024 ) { + va |= (1ULL << (13 + tsb_size)); + } + tsb_base_mask <<=1 ; + } + +return ((tsb_base & tsb_base_mask) | (va & ~tsb_base_mask)) & ~0xfULL ; +} + +// Calculates tag target register value by reordering bits +// in tag access register +static uint64_t ultrasparc_tag_target (uint64_t tag_access_register) +{ +return ((tag_access_register &0x1fff ) <<48 ) | (tag_access_register >>22 ); +} + +#endif +static inline void address_mask (CPUState *env1,target_ulong *addr) {#ifdef TARGET_SPARC64
@@ -1652,13 +1702,31 @@ {int reg = (addr >>3 ) &0xf ; - ret = env->immuregs[reg]; +if (reg ==0 ) { +// I-TSB Tag Target register + ret =ultrasparc_tag_target (env->immuregs[6 ]); + }else { + ret = env->immuregs[reg]; + } +break ; }case 0x51 :// I-MMU 8k TSB pointer + { +// env->immuregs[5] holds I-MMU TSB register value +// env->immuregs[6] holds I-MMU Tag Access register value + ret =ultrasparc_tsb_pointer (env->immuregs[5 ], env->immuregs[6 ], +8 *1024 ); +break ; + }case 0x52 :// I-MMU 64k TSB pointer -// XXX -break ; + { +// env->immuregs[5] holds I-MMU TSB register value +// env->immuregs[6] holds I-MMU Tag Access register value + ret =ultrasparc_tsb_pointer (env->immuregs[5 ], env->immuregs[6 ], +64 *1024 ); +break ; + }case 0x55 :// I-MMU data access {int reg = (addr >>3 ) &0x3f ;
@@ -1677,9 +1745,30 @@ {int reg = (addr >>3 ) &0xf ; - ret = env->dmmuregs[reg]; +if (reg ==0 ) { +// D-TSB Tag Target register + ret =ultrasparc_tag_target (env->dmmuregs[6 ]); + }else { + ret = env->dmmuregs[reg]; + }break ; } +case 0x59 :// D-MMU 8k TSB pointer + { +// env->dmmuregs[5] holds D-MMU TSB register value +// env->dmmuregs[6] holds D-MMU Tag Access register value + ret =ultrasparc_tsb_pointer (env->dmmuregs[5 ], env->dmmuregs[6 ], +8 *1024 ); +break ; + } +case 0x5a :// D-MMU 64k TSB pointer + { +// env->dmmuregs[5] holds D-MMU TSB register value +// env->dmmuregs[6] holds D-MMU Tag Access register value + ret =ultrasparc_tsb_pointer (env->dmmuregs[5 ], env->dmmuregs[6 ], +64 *1024 ); +break ; + }case 0x5d :// D-MMU data access {int reg = (addr >>3 ) &0x3f ;
@@ -1707,8 +1796,6 @@case 0x76 :// E-cache tag case 0x7e :// E-cache tag break ; -case 0x59 :// D-MMU 8k TSB pointer -case 0x5a :// D-MMU 64k TSB pointer case 0x5b :// D-MMU data pointer case 0x48 :// Interrupt dispatch, RO case 0x49 :// Interrupt data receive
Blue Swirl
AppliedQuoted 1 line · Igor Kovalenko
Posting updated patch to the list...
Thanks, applied.
Quoted 8 lines · Blue Swirl
Quoted 7 lines · Igor Kovalenko
Hi!
This change allows reading ultrasparc I/D MMU TSB tag target register and TSB pointer register (8k and 64k).
Linux kernel uses TSB for memory management, and with this change it now can use early allocation routines.
Quoted 8 lines
Quoted 6 lines
I'm testing with linux-2.6.29.1 minimalistic sparc64 uniprocessor build, now kernel is able to start build device tree. Without the change kernel was not able to handle D-MMU miss while creating first device tree node.
Currently it stops shortly after building device tree, trying to find out path to console.Nice, though I didn't notice any visible improvement in my tests.
Here is the missing part in qemu-sparc64-mmu-pagesize.patch This fixes TLB match code to respect page size, otherwise 4M page mappings may be not found.
Also this corrects a typo in get_physical_address_code which uses a register from DMMU instead of IMMU.
Please apply.
get_physical_address_data/code probably needs some code reuse refactoring.
Quoted 9 lines
Quoted 6 lines
(PS with openbios instance-to-path method fails in client interface call, in the same way
it fails without loading kernel when I try invoking get-instance-path on stdin handle from command prompt.
there fmove invokesmemmove()with size argument looking like some pointer which leads to unhandled D-MMU fault)Similar very obscure problem was fixed with PPC (r481), the bug was with the PCI nodes.
Here (r484) on sparc64 it hangs in the same place.
Signature · 2 lines
Kind regards, Igor V. Kovalenko
target-sparc/helper.c +7 -7
@@ -404,7 +404,7 @@ static int get_physical_address_data(CPU }// ctx match, vaddr match, valid? if (env->dmmuregs[1 ] == (env->dtlb_tag[i] &0x1fff ) && - (address & mask) == (env->dtlb_tag[i] & ~0x1fffULL ) && + (address & mask) == (env->dtlb_tag[i] & mask) && (env->dtlb_tte[i] &0x8000000000000000ULL )) {// access ok? if (((env->dtlb_tte[i] & 0x4) && is_user) ||
@@ -420,8 +420,8 @@ static int get_physical_address_data(CPU#endif return 1 ; } - *physical = (env->dtlb_tte[i] & mask &0x1fffffff000ULL ) + - (address & ~mask &0x1fffffff000ULL ); + *physical = ((env->dtlb_tte[i] & mask) | (address & ~mask)) & +0x1ffffffe000ULL ; *prot =PAGE_READ ;if (env->dtlb_tte[i] &0x2 ) *prot |=PAGE_WRITE ;
@@ -467,7 +467,7 @@ static int get_physical_address_code(CPU }// ctx match, vaddr match, valid? if (env->dmmuregs[1 ] == (env->itlb_tag[i] &0x1fff ) && - (address & mask) == (env->itlb_tag[i] & ~0x1fffULL ) && + (address & mask) == (env->itlb_tag[i] & mask) && (env->itlb_tte[i] &0x8000000000000000ULL )) {// access ok? if ((env->itlb_tte[i] &0x4 ) && is_user) {
@@ -481,8 +481,8 @@ static int get_physical_address_code(CPU#endif return 1 ; } - *physical = (env->itlb_tte[i] & mask &0x1fffffff000ULL ) + - (address & ~mask &0x1fffffff000ULL ); + *physical = ((env->itlb_tte[i] & mask) | (address & ~mask)) & +0x1ffffffe000ULL ; *prot =PAGE_EXEC ;return 0 ; }
@@ -490,7 +490,7 @@ static int get_physical_address_code(CPU#ifdef DEBUG_MMU printf ("TMISS at 0x%" PRIx64"\n" , address);#endif - env->immuregs[6 ] = (address & ~0x1fffULL ) | (env->dmmuregs[1 ] &0x1fff ); + env->immuregs[6 ] = (address & ~0x1fffULL ) | (env->immuregs[1 ] &0x1fff ); env->exception_index =TT_TMISS ;return 1 ; }
Quoted 20 lines · Igor Kovalenko
Quoted 8 lines · Blue Swirl
Quoted 7 lines · Igor Kovalenko
Hi!
This change allows reading ultrasparc I/D MMU TSB tag target register and TSB pointer register (8k and 64k).
Linux kernel uses TSB for memory management, and with this change it now can use early allocation routines.Quoted 8 lines
Quoted 6 lines
I'm testing with linux-2.6.29.1 minimalistic sparc64 uniprocessor build, now kernel is able to start build device tree. Without the change kernel was not able to handle D-MMU miss while creating first device tree node.
Currently it stops shortly after building device tree, trying to find out path to console.Nice, though I didn't notice any visible improvement in my tests.
Quoted 7 lines
Here is the missing part in qemu-sparc64-mmu-pagesize.patch
This fixes TLB match code to respect page size, otherwise 4M page mappings may be not found.
Also this corrects a typo inget_physical_address_codewhich uses a register from DMMU instead of IMMU.Please apply.
Looks OK. Please resubmit with only the commit changelog material and a Sign-off. I'm still learning git (with qgit), I don't know how to trim the commit message yet. Or maybe that is not the "git way"?
Quoted 1 line
get_physical_address_data/code probably needs some code reuse refactoring.
True.