target/arm/tcg: refine cache descriptions with a wrapper
PATCH v2 1/1 target/arm/tcg: refine cache descriptions with a wrapper
This patch allows for easier manipulation of the cache description register, CCSIDR. Which is helpful for testing as well. Currently numbers get hard-coded and might be prone to errors.
Therefore, this patch adds wrappers for different types of CPUs available in tcg to decribe caches. Two functions make_ccsidr32 and make_ccsidr64 describing descriptions. The 32 bit version receives extra parameters that became unknown later in 64 bit.
For CCSIDR register, 32 bit version follows specification [1]. Conversely, 64 bit version follows specification [2].
[1] B4.1.19, ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition, https://developer.arm.com/documentation/ddi0406
[2] D23.2.29, ARM Architecture Reference Manual for A-profile Architecture,
https://developer.arm.com/documentation/ddi0487/latest/
--- target/arm/cpu-features.h | 53 ++++++++++++++++++++++++ target/arm/cpu64.c | 19 ++++++--- target/arm/tcg/cpu64.c | 86 ++++++++++++++++++--------------------- 3 files changed, 105 insertions(+), 53 deletions(-)
target/arm/cpu-features.h +53 -0
@@ -1022,6 +1022,59 @@ static inline bool isar_feature_any_evt(const ARMISARegisters *id)return isar_feature_aa64_evt (id) ||isar_feature_aa32_evt (id); } +static inline uint64_t make_ccsidr32 (unsigned assoc,unsigned linesize, +unsigned cachesize,uint8_t flags) +{ +unsigned lg_linesize =ctz32 (linesize); +unsigned sets; + +/* +* The 32-bit CCSIDR_EL1 format is: +* [27:13] number of sets - 1 +* [12:3] associativity - 1 +* [2:0] log2(linesize) - 4 +* so 0 == 16 bytes, 1 == 32 bytes, 2 == 64 bytes, etc +*/ +assert (assoc !=0 ); +assert (is_power_of_2 (linesize)); +assert (lg_linesize >=4 && lg_linesize <=7 +4 ); + +/* sets * associativity * linesize == cachesize. */ + sets = cachesize / (assoc * linesize); +assert (cachesize % (assoc * linesize) ==0 ); + +return ((uint64_t )(flags) <<28 ) + | ((sets -1 ) <<13 ) + | ((assoc -1 ) <<3 ) + | (lg_linesize -4 ); +} + +static inline uint64_t make_ccsidr64 (unsigned assoc,unsigned linesize, +unsigned cachesize) +{ +unsigned lg_linesize =ctz32 (linesize); +unsigned sets; + +/* +* The 64-bit CCSIDR_EL1 format is: +* [55:32] number of sets - 1 +* [23:3] associativity - 1 +* [2:0] log2(linesize) - 4 +* so 0 == 16 bytes, 1 == 32 bytes, 2 == 64 bytes, etc +*/ +assert (assoc !=0 ); +assert (is_power_of_2 (linesize)); +assert (lg_linesize >=4 && lg_linesize <=7 +4 ); + +/* sets * associativity * linesize == cachesize. */ + sets = cachesize / (assoc * linesize); +assert (cachesize % (assoc * linesize) ==0 ); + +return ((uint64_t )(sets -1 ) <<32 ) + | ((assoc -1 ) <<3 ) + | (lg_linesize -4 ); +} +/* * Forward to the above feature tests given an ARMCPU pointer. */
target/arm/cpu64.c +13 -6
@@ -23,6 +23,7 @@#include "cpu.h" #include "cpregs.h" #include "qemu/module.h" +#include "qemu/units.h" #include "sysemu/kvm.h" #include "sysemu/hvf.h" #include "sysemu/qtest.h"
@@ -642,9 +643,12 @@ static void aarch64_a57_initfn(Object *obj) cpu->isar.dbgdevid1 =0x2 ; cpu->isar.reset_pmcr_el0 =0x41013000 ; cpu->clidr =0x0a200023 ; - cpu->ccsidr[0 ] =0x701fe00a ;/* 32KB L1 dcache */ - cpu->ccsidr[1 ] =0x201fe012 ;/* 48KB L1 icache */ - cpu->ccsidr[2 ] =0x70ffe07a ;/* 2048KB L2 cache */ +/* 32KB L1 dcache */ + cpu->ccsidr[0 ] =make_ccsidr32 (4 ,64 ,32 * KiB,7 ); +/* 48KB L1 icache */ + cpu->ccsidr[1 ] =make_ccsidr32 (3 ,64 ,48 * KiB,2 ); +/* 2048KB L2 cache */ + cpu->ccsidr[2 ] =make_ccsidr32 (16 ,64 ,2 * MiB,7 ); cpu->dcz_blocksize =4 ;/* 64 bytes */ cpu->gic_num_lrs =4 ; cpu->gic_vpribits =5 ;
@@ -700,9 +704,12 @@ static void aarch64_a53_initfn(Object *obj) cpu->isar.dbgdevid1 =0x1 ; cpu->isar.reset_pmcr_el0 =0x41033000 ; cpu->clidr =0x0a200023 ; - cpu->ccsidr[0 ] =0x700fe01a ;/* 32KB L1 dcache */ - cpu->ccsidr[1 ] =0x201fe00a ;/* 32KB L1 icache */ - cpu->ccsidr[2 ] =0x707fe07a ;/* 1024KB L2 cache */ +/* 32KB L1 dcache */ + cpu->ccsidr[0 ] =make_ccsidr32 (4 ,64 ,32 * KiB,7 ); +/* 32KB L1 icache */ + cpu->ccsidr[1 ] =make_ccsidr32 (1 ,64 ,32 * KiB,2 ); +/* 1024KB L2 cache */ + cpu->ccsidr[2 ] =make_ccsidr32 (16 ,64 ,1 * MiB,7 ); cpu->dcz_blocksize =4 ;/* 64 bytes */ cpu->gic_num_lrs =4 ; cpu->gic_vpribits =5 ;
target/arm/tcg/cpu64.c +39 -47
134 lines not on this page · raw message
Signature · 1 line
2.34.1
Hi Alireza,
Quoted 103 lines · Alireza Sanaee via
This patch allows for easier manipulation of the cache description register, CCSIDR. Which is helpful for testing as well. Currently numbers get hard-coded and might be prone to errors.
Therefore, this patch adds wrappers for different types of CPUs available in tcg to decribe caches. Two functions
make_ccsidr32andmake_ccsidr64describing descriptions. The 32 bit version receives extra parameters that became unknown later in 64 bit.For CCSIDR register, 32 bit version follows specification [1]. Conversely, 64 bit version follows specification [2].
[1] B4.1.19, ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition, https://developer.arm.com/documentation/ddi0406
[2] D23.2.29, ARM Architecture Reference Manual for A-profile Architecture,
https://developer.arm.com/documentation/ddi0487/latest/Signed-off-by Alireza Sanaee <[email protected]>--- target/arm/cpu-features.h | 53 ++++++++++++++++++++++++ target/arm/cpu64.c | 19 ++++++--- target/arm/tcg/cpu64.c | 86 ++++++++++++++++++--------------------- 3 files changed, 105 insertions(+), 53 deletions(-)target/arm/cpu-features.h +53
-0@@ -1022,6 +1022,59 @@ static inline bool isar_feature_any_evt(const ARMISARegisters *id)return isar_feature_aa64_evt (id) ||isar_feature_aa32_evt (id); } +static inline uint64_t make_ccsidr32 (unsigned assoc,unsigned linesize, +unsigned cachesize,uint8_t flags) +{ +unsigned lg_linesize =ctz32 (linesize); +unsigned sets; + +/* +* The 32-bit CCSIDR_EL1 format is: +* [27:13] number of sets - 1 +* [12:3] associativity - 1 +* [2:0] log2(linesize) - 4 +* so 0 == 16 bytes, 1 == 32 bytes, 2 == 64 bytes, etc +*/ +assert (assoc !=0 ); +assert (is_power_of_2 (linesize)); +assert (lg_linesize >=4 && lg_linesize <=7 +4 ); + +/* sets * associativity * linesize == cachesize. */ + sets = cachesize / (assoc * linesize); +assert (cachesize % (assoc * linesize) ==0 ); + +return ((uint64_t )(flags) <<28 ) + | ((sets -1 ) <<13 ) + | ((assoc -1 ) <<3 ) + | (lg_linesize -4 ); +} + +static inline uint64_t make_ccsidr64 (unsigned assoc,unsigned linesize, +unsigned cachesize) +{ +unsigned lg_linesize =ctz32 (linesize); +unsigned sets; + +/* +* The 64-bit CCSIDR_EL1 format is: +* [55:32] number of sets - 1 +* [23:3] associativity - 1 +* [2:0] log2(linesize) - 4 +* so 0 == 16 bytes, 1 == 32 bytes, 2 == 64 bytes, etc +*/ +assert (assoc !=0 ); +assert (is_power_of_2 (linesize)); +assert (lg_linesize >=4 && lg_linesize <=7 +4 ); + +/* sets * associativity * linesize == cachesize. */ + sets = cachesize / (assoc * linesize); +assert (cachesize % (assoc * linesize) ==0 ); + +return ((uint64_t )(sets -1 ) <<32 ) + | ((assoc -1 ) <<3 ) + | (lg_linesize -4 ); +} +/* * Forward to the above feature tests given an ARMCPU pointer. */ target/arm/cpu64.c +1
-0@@ -23,6 +23,7 @@#include "cpu.h" #include "cpregs.h" #include "qemu/module.h" +#include "qemu/units.h" #include "sysemu/kvm.h" #include "sysemu/hvf.h" #include "sysemu/qtest.h" @@ -642,9 +643,12 @@ static void aarch64_a57_initfn(Object *obj) cpu->isar.dbgdevid1 =0x2 ; cpu->isar.reset_pmcr_el0 =0x41013000 ;
target/arm/cpu64.c static void aarch64_a57_initfn(Object *obj) · line 651
Quoted 10 lines
target/arm/cpu64.c +6
-3cpu->clidr =0x0a200023 ; - cpu->ccsidr[0 ] =0x701fe00a ;/* 32KB L1 dcache */ - cpu->ccsidr[1 ] =0x201fe012 ;/* 48KB L1 icache */ - cpu->ccsidr[2 ] =0x70ffe07a ;/* 2048KB L2 cache */ +/* 32KB L1 dcache */ + cpu->ccsidr[0 ] =make_ccsidr32 (4 ,64 ,32 * KiB,7 ); +/* 48KB L1 icache */ + cpu->ccsidr[1 ] =make_ccsidr32 (3 ,64 ,48 * KiB,2 ); +/* 2048KB L2 cache */ + cpu->ccsidr[2 ] =make_ccsidr32 (16 ,64 ,2 * MiB,7 );
I like the uses of make_ccsidrXX() instead of the magic values.
I don't like much the code duplication between make_ccsidrXX() definitions, I'd prefer both call a common (static?) one.
I'm not keen on adding inlined functions in target/arm/cpu-features.h. Just expose the prototype declarations, and keep the definition in .c files. That way we don't need to include "qemu/host-utils.h" to get is_power_of_2() declaration.
Regards,
Phil.
Quoted 120 lines · Philippe Mathieu-Daudé
Hi Alireza,
Quoted 103 lines · Alireza Sanaee via
This patch allows for easier manipulation of the cache description register, CCSIDR. Which is helpful for testing as well. Currently numbers get hard-coded and might be prone to errors.
Therefore, this patch adds wrappers for different types of CPUs available in tcg to decribe caches. Two functions
make_ccsidr32andmake_ccsidr64describing descriptions. The 32 bit version receives extra parameters that became unknown later in 64 bit.For CCSIDR register, 32 bit version follows specification [1]. Conversely, 64 bit version follows specification [2].
[1] B4.1.19, ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition, https://developer.arm.com/documentation/ddi0406
[2] D23.2.29, ARM Architecture Reference Manual for A-profile Architecture,
https://developer.arm.com/documentation/ddi0487/latest/Signed-off-by Alireza Sanaee <[email protected]>--- target/arm/cpu-features.h | 53 ++++++++++++++++++++++++ target/arm/cpu64.c | 19 ++++++--- target/arm/tcg/cpu64.c | 86 ++++++++++++++++++--------------------- 3 files changed, 105 insertions(+), 53 deletions(-)target/arm/cpu-features.h +53
-0@@ -1022,6 +1022,59 @@ static inline bool isar_feature_any_evt(const ARMISARegisters *id)return isar_feature_aa64_evt (id) ||isar_feature_aa32_evt (id); } +static inline uint64_t make_ccsidr32 (unsigned assoc,unsigned linesize, +unsigned cachesize,uint8_t flags) +{ +unsigned lg_linesize =ctz32 (linesize); +unsigned sets; + +/* +* The 32-bit CCSIDR_EL1 format is: +* [27:13] number of sets - 1 +* [12:3] associativity - 1 +* [2:0] log2(linesize) - 4 +* so 0 == 16 bytes, 1 == 32 bytes, 2 == 64 bytes, etc +*/ +assert (assoc !=0 ); +assert (is_power_of_2 (linesize)); +assert (lg_linesize >=4 && lg_linesize <=7 +4 ); + +/* sets * associativity * linesize == cachesize. */ + sets = cachesize / (assoc * linesize); +assert (cachesize % (assoc * linesize) ==0 ); + +return ((uint64_t )(flags) <<28 ) + | ((sets -1 ) <<13 ) + | ((assoc -1 ) <<3 ) + | (lg_linesize -4 ); +} + +static inline uint64_t make_ccsidr64 (unsigned assoc,unsigned linesize, +unsigned cachesize) +{ +unsigned lg_linesize =ctz32 (linesize); +unsigned sets; + +/* +* The 64-bit CCSIDR_EL1 format is: +* [55:32] number of sets - 1 +* [23:3] associativity - 1 +* [2:0] log2(linesize) - 4 +* so 0 == 16 bytes, 1 == 32 bytes, 2 == 64 bytes, etc +*/ +assert (assoc !=0 ); +assert (is_power_of_2 (linesize)); +assert (lg_linesize >=4 && lg_linesize <=7 +4 ); + +/* sets * associativity * linesize == cachesize. */ + sets = cachesize / (assoc * linesize); +assert (cachesize % (assoc * linesize) ==0 ); + +return ((uint64_t )(sets -1 ) <<32 ) + | ((assoc -1 ) <<3 ) + | (lg_linesize -4 ); +} +/* * Forward to the above feature tests given an ARMCPU pointer. */ target/arm/cpu64.c +1
-0@@ -23,6 +23,7 @@#include "cpu.h" #include "cpregs.h" #include "qemu/module.h" +#include "qemu/units.h" #include "sysemu/kvm.h" #include "sysemu/hvf.h" #include "sysemu/qtest.h" @@ -642,9 +643,12 @@ static void aarch64_a57_initfn(Object *obj) cpu->isar.dbgdevid1 =0x2 ; cpu->isar.reset_pmcr_el0 =0x41013000 ;target/arm/cpu64.c static void aarch64_a57_initfn(Object *obj) · line 651
Quoted 10 lines
target/arm/cpu64.c +6
-3cpu->clidr =0x0a200023 ; - cpu->ccsidr[0 ] =0x701fe00a ;/* 32KB L1 dcache */ - cpu->ccsidr[1 ] =0x201fe012 ;/* 48KB L1 icache */ - cpu->ccsidr[2 ] =0x70ffe07a ;/* 2048KB L2 cache */ +/* 32KB L1 dcache */ + cpu->ccsidr[0 ] =make_ccsidr32 (4 ,64 ,32 * KiB,7 ); +/* 48KB L1 icache */ + cpu->ccsidr[1 ] =make_ccsidr32 (3 ,64 ,48 * KiB,2 ); +/* 2048KB L2 cache */ + cpu->ccsidr[2 ] =make_ccsidr32 (16 ,64 ,2 * MiB,7 );I like the uses of
make_ccsidrXX()instead of the magic values.
Quoted 2 lines
I don't like much the code duplication between
make_ccsidrXX()definitions, I'd prefer both call a common (static?) one.
How about we have
typedef enum {
CCSIDR_FORMAT_LEGACY,
CCSIDR_FORMAT_CCIDX,
} CCSIDRFormat;
and a singleuint64_t make_ccsidr(CCSIDRFormat format, unsigned assoc, unsigned
linesize, unsigned cachesize, unsigned flags);
? Since the only difference between the two functions is the final line that assembles the return value, that seems like maybe a better way to avoid the code duplication than a common sub-function.
-- PMM
Quoted 138 lines · On Mon, 2 Sep 2024 11:25:36 +0100 Peter Maydell <[email protected]>…
Quoted 125 lines · Philippe Mathieu-Daudé
Hi Alireza,
Quoted 108 lines · Alireza Sanaee via
This patch allows for easier manipulation of the cache description register, CCSIDR. Which is helpful for testing as well. Currently numbers get hard-coded and might be prone to errors.
Therefore, this patch adds wrappers for different types of CPUs available in tcg to decribe caches. Two functions
make_ccsidr32andmake_ccsidr64describing descriptions. The 32 bit version receives extra parameters that became unknown later in 64 bit.For CCSIDR register, 32 bit version follows specification [1]. Conversely, 64 bit version follows specification [2].
[1] B4.1.19, ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition, https://developer.arm.com/documentation/ddi0406
[2] D23.2.29, ARM Architecture Reference Manual for A-profile Architecture, https://developer.arm.com/documentation/ddi0487/latest/Signed-off-by Alireza Sanaee <[email protected]>--- target/arm/cpu-features.h | 53 ++++++++++++++++++++++++ target/arm/cpu64.c | 19 ++++++--- target/arm/tcg/cpu64.c | 86++++++++++++++++++--------------------- 3 files changed, 105 insertions(+), 53 deletions(-)
target/arm/cpu-features.h +0
-0@@ -1022,6 +1022,59 @@ static inline bool
isar_feature_any_evt(const ARMISARegisters *id)returnisar_feature_aa64_evt(id)||isar_feature_aa32_evt(id); }+static inline
uint64_tmake_ccsidr32(unsigned assoc, unsigned linesize,
+ unsigned cachesize,uint8_t
flags) +{target/arm/cpu-features.h +9
-0+unsigned lg_linesize =ctz32 (linesize); +unsigned sets; + +/* +* The 32-bit CCSIDR_EL1 format is: +* [27:13] number of sets - 1 +* [12:3] associativity - 1 +* [2:0] log2(linesize) - 4 +* so 0 == 16 bytes, 1 == 32 bytes, 2 == 64 bytes, etc
target/arm/cpu-features.h +16
-0+*/ +assert (assoc !=0 ); +assert (is_power_of_2 (linesize)); +assert (lg_linesize >=4 && lg_linesize <=7 +4 ); + +/* sets * associativity * linesize == cachesize. */ + sets = cachesize / (assoc * linesize); +assert (cachesize % (assoc * linesize) ==0 ); + +return ((uint64_t )(flags) <<28 ) + | ((sets -1 ) <<13 ) + | ((assoc -1 ) <<3 ) + | (lg_linesize -4 ); +} + +static inline uint64_t make_ccsidr64(unsigned assoc, unsignedlinesize,
target/arm/cpu-features.h +11
-0+ unsigned cachesize) +{ +unsigned lg_linesize =ctz32 (linesize); +unsigned sets; + +/* +* The 64-bit CCSIDR_EL1 format is: +* [55:32] number of sets - 1 +* [23:3] associativity - 1 +* [2:0] log2(linesize) - 4 +* so 0 == 16 bytes, 1 == 32 bytes, 2 == 64 bytes, etc
target/arm/cpu-features.h +14
-0+*/ +assert (assoc !=0 ); +assert (is_power_of_2 (linesize)); +assert (lg_linesize >=4 && lg_linesize <=7 +4 ); + +/* sets * associativity * linesize == cachesize. */ + sets = cachesize / (assoc * linesize); +assert (cachesize % (assoc * linesize) ==0 ); + +return ((uint64_t )(sets -1 ) <<32 ) + | ((assoc -1 ) <<3 ) + | (lg_linesize -4 ); +} +/* * Forward to the above feature tests given an ARMCPU pointer. */ target/arm/cpu64.c +1
-0@@ -23,6 +23,7 @@#include "cpu.h" #include "cpregs.h" #include "qemu/module.h" +#include "qemu/units.h" #include "sysemu/kvm.h" #include "sysemu/hvf.h" #include "sysemu/qtest.h" @@ -642,9 +643,12 @@ static void aarch64_a57_initfn(Object *obj) cpu->isar.dbgdevid1 =0x2 ; cpu->isar.reset_pmcr_el0 =0x41013000 ;target/arm/cpu64.c static void aarch64_a57_initfn(Object *obj) · line 651
Quoted 10 lines
target/arm/cpu64.c +6
-3cpu->clidr =0x0a200023 ; - cpu->ccsidr[0 ] =0x701fe00a ;/* 32KB L1 dcache */ - cpu->ccsidr[1 ] =0x201fe012 ;/* 48KB L1 icache */ - cpu->ccsidr[2 ] =0x70ffe07a ;/* 2048KB L2 cache */ +/* 32KB L1 dcache */ + cpu->ccsidr[0 ] =make_ccsidr32 (4 ,64 ,32 * KiB,7 ); +/* 48KB L1 icache */ + cpu->ccsidr[1 ] =make_ccsidr32 (3 ,64 ,48 * KiB,2 ); +/* 2048KB L2 cache */ + cpu->ccsidr[2 ] =make_ccsidr32 (16 ,64 ,2 * MiB,7 );I like the uses of
make_ccsidrXX()instead of the magic values.Quoted 2 lines
I don't like much the code duplication between
make_ccsidrXX()definitions, I'd prefer both call a common (static?) one.How about we have
typedef enum {
CCSIDR_FORMAT_LEGACY,
CCSIDR_FORMAT_CCIDX,
} CCSIDRFormat;and a single
uint64_tmake_ccsidr(CCSIDRFormat format, unsigned assoc, unsigned
Quoted 8 lines
linesize, unsigned cachesize, unsigned flags);? Since the only difference between the two functions is the final line that assembles the return value, that seems like maybe a better way to avoid the code duplication than a common sub-function.
-- PMM
I like this suggestion. I can address Philippe's concern too if I move functions around. I thought a bit how to avoid duplication then I ended up saying let's see what others might say.
Alireza
Quoted 29 lines · Alireza Sanaee via
This patch allows for easier manipulation of the cache description register, CCSIDR. Which is helpful for testing as well. Currently numbers get hard-coded and might be prone to errors.
Therefore, this patch adds wrappers for different types of CPUs available in tcg to decribe caches. Two functions
make_ccsidr32andmake_ccsidr64describing descriptions. The 32 bit version receives extra parameters that became unknown later in 64 bit.For CCSIDR register, 32 bit version follows specification [1]. Conversely, 64 bit version follows specification [2].
[1] B4.1.19, ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition, https://developer.arm.com/documentation/ddi0406
[2] D23.2.29, ARM Architecture Reference Manual for A-profile Architecture,
https://developer.arm.com/documentation/ddi0487/latest/Signed-off-by Alireza Sanaee <[email protected]>--- target/arm/cpu-features.h | 53 ++++++++++++++++++++++++ target/arm/cpu64.c | 19 ++++++--- target/arm/tcg/cpu64.c | 86 ++++++++++++++++++--------------------- 3 files changed, 105 insertions(+), 53 deletions(-)target/arm/cpu-features.h +0
-0
target/arm/cpu-features.h static inline bool isar_feature_any_evt(const ARMISARegisters *id) · line 1027
Quoted 6 lines
target/arm/cpu-features.h +3
-0@@ -1022,6 +1022,59 @@ static inline bool isar_feature_any_evt(const ARMISARegisters *id)return isar_feature_aa64_evt (id) ||isar_feature_aa32_evt (id); } +static inline uint64_t make_ccsidr32 (unsigned assoc,unsigned linesize, +unsigned cachesize,uint8_t flags) +{
isn't this returning a 32 bit value?
Quoted 12 lines
target/arm/cpu-features.h +12
-0+unsigned lg_linesize =ctz32 (linesize); +unsigned sets; + +/* +* The 32-bit CCSIDR_EL1 format is: +* [27:13] number of sets - 1 +* [12:3] associativity - 1 +* [2:0] log2(linesize) - 4 +* so 0 == 16 bytes, 1 == 32 bytes, 2 == 64 bytes, etc +*/ +assert (assoc !=0 ); +assert (is_power_of_2 (linesize));
target/arm/cpu-features.h static inline bool isar_feature_any_evt(const ARMISARegisters *id) · line 1049
Quoted 10 lines
target/arm/cpu-features.h +10
-0+assert (lg_linesize >=4 && lg_linesize <=7 +4 ); + +/* sets * associativity * linesize == cachesize. */ + sets = cachesize / (assoc * linesize); +assert (cachesize % (assoc * linesize) ==0 ); + +return ((uint64_t )(flags) <<28 ) + | ((sets -1 ) <<13 ) + | ((assoc -1 ) <<3 ) + | (lg_linesize -4 );
This is a nice improvement but using deposit() will ensure you don't accidentally overflow fields with the shift/or combos. So something like:
uint32_t ccsidr32 = 0; .. ccsidr32 = deposit32(ccsidr32, 28, 4, flags); ccsidr32 = deposit32(ccsidr32, 13, 14, sets - 1); ccsidr32 = deposit32(ccsidr32, 3, 10, assoc - 1); ccsidr32 = deposit32(ccsidr32, 0, 3, lg_linesize - 1);
And leave the compiler to simplify everything (not that it matters that much for an init function).
Actually I note CCSIDR already has some field definitions so it would be:
ccsidr32 = FIELD_DP32(ccsidr32, CCSIDR_EL1, LINESIZE, lg_linesize -1);
etc. Although I notice it two sets of defines to account for FEAT_CCIDX
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Quoted 78 lines · Alex Bennée
Quoted 29 lines · Alireza Sanaee via
This patch allows for easier manipulation of the cache description register, CCSIDR. Which is helpful for testing as well. Currently numbers get hard-coded and might be prone to errors.
Therefore, this patch adds wrappers for different types of CPUs available in tcg to decribe caches. Two functions
make_ccsidr32andmake_ccsidr64describing descriptions. The 32 bit version receives extra parameters that became unknown later in 64 bit.For CCSIDR register, 32 bit version follows specification [1]. Conversely, 64 bit version follows specification [2].
[1] B4.1.19, ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition, https://developer.arm.com/documentation/ddi0406
[2] D23.2.29, ARM Architecture Reference Manual for A-profile Architecture,
https://developer.arm.com/documentation/ddi0487/latest/Signed-off-by Alireza Sanaee <[email protected]>--- target/arm/cpu-features.h | 53 ++++++++++++++++++++++++ target/arm/cpu64.c | 19 ++++++--- target/arm/tcg/cpu64.c | 86 ++++++++++++++++++--------------------- 3 files changed, 105 insertions(+), 53 deletions(-)target/arm/cpu-features.h +0
-0target/arm/cpu-features.h static inline bool isar_feature_any_evt(const ARMISARegisters *id) · line 1027
Quoted 6 lines
target/arm/cpu-features.h +3
-0@@ -1022,6 +1022,59 @@ static inline bool isar_feature_any_evt(const ARMISARegisters *id)return isar_feature_aa64_evt (id) ||isar_feature_aa32_evt (id); } +static inline uint64_t make_ccsidr32 (unsigned assoc,unsigned linesize, +unsigned cachesize,uint8_t flags) +{isn't this returning a 32 bit value?
Quoted 12 lines
target/arm/cpu-features.h +12
-0+unsigned lg_linesize =ctz32 (linesize); +unsigned sets; + +/* +* The 32-bit CCSIDR_EL1 format is: +* [27:13] number of sets - 1 +* [12:3] associativity - 1 +* [2:0] log2(linesize) - 4 +* so 0 == 16 bytes, 1 == 32 bytes, 2 == 64 bytes, etc +*/ +assert (assoc !=0 ); +assert (is_power_of_2 (linesize));target/arm/cpu-features.h static inline bool isar_feature_any_evt(const ARMISARegisters *id) · line 1049
Quoted 10 lines
target/arm/cpu-features.h +10
-0+assert (lg_linesize >=4 && lg_linesize <=7 +4 ); + +/* sets * associativity * linesize == cachesize. */ + sets = cachesize / (assoc * linesize); +assert (cachesize % (assoc * linesize) ==0 ); + +return ((uint64_t )(flags) <<28 ) + | ((sets -1 ) <<13 ) + | ((assoc -1 ) <<3 ) + | (lg_linesize -4 );This is a nice improvement but using
deposit()will ensure you don't accidentally overflow fields with the shift/or combos. So something like:uint32_t ccsidr32 = 0; .. ccsidr32 = deposit32(ccsidr32, 28, 4, flags); ccsidr32 = deposit32(ccsidr32, 13, 14, sets - 1); ccsidr32 = deposit32(ccsidr32, 3, 10, assoc - 1); ccsidr32 = deposit32(ccsidr32, 0, 3, lg_linesize - 1);And leave the compiler to simplify everything (not that it matters that much for an init function).
Quoted 6 lines
Actually I note CCSIDR already has some field definitions so it would be:
ccsidr32 = FIELD_DP32(ccsidr32, CCSIDR_EL1, LINESIZE, lg_linesize -1);etc. Although I notice it two sets of defines to account for
FEAT_CCIDX
Mmm. Though I feel like we (me absolutely included) are rather getting into bikeshedding a fairly simple refactoring patch...
thanks
-- PMM