Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/arm32/src/cpu/cpu.c

    r93d8022 rc8a5c8c  
    4141#include <print.h>
    4242
    43 #ifdef CONFIG_FPU
    44 #include <arch/fpu_context.h>
    45 #endif
    46 
    4743static inline unsigned log2(unsigned val)
    4844{
     
    6460static const char * implementer(unsigned id)
    6561{
    66         switch (id) {
     62        switch (id)
     63        {
    6764        case 0x41: return "ARM Limited";
    6865        case 0x44: return "Digital Equipment Corporation";
     
    130127{
    131128        uint32_t control_reg = SCTLR_read();
    132 
    133         dcache_invalidate();
    134         read_barrier();
    135 
     129       
    136130        /* Turn off tex remap, RAZ/WI prior to armv7 */
    137131        control_reg &= ~SCTLR_TEX_REMAP_EN_FLAG;
     
    163157#endif
    164158#ifdef PROCESSOR_ARCH_armv7_a
    165          /* ICache coherency is elaborated on in barrier.h.
     159         /* ICache coherency is elaborate on in barrier.h.
    166160          * VIPT and PIPT caches need maintenance only on code modify,
    167161          * so it should be safe for general use.
     
    172166                control_reg |=
    173167                    SCTLR_INST_CACHE_EN_FLAG | SCTLR_BRANCH_PREDICT_EN_FLAG;
    174         } else {
    175                 control_reg &=
    176                     ~(SCTLR_INST_CACHE_EN_FLAG | SCTLR_BRANCH_PREDICT_EN_FLAG);
    177168        }
    178169#endif
     
    213204#ifdef PROCESSOR_ARCH_armv7_a
    214205        CSSELR_write((level & CCSELR_LEVEL_MASK) << CCSELR_LEVEL_SHIFT);
    215         const uint32_t ccsidr = CCSIDR_read();
    216         return CCSIDR_LINESIZE_LOG(ccsidr);
     206        const unsigned ls_log = 2 +
     207            ((CCSIDR_read() >> CCSIDR_LINESIZE_SHIFT) & CCSIDR_LINESIZE_MASK);
     208        return ls_log + 2; //return log2(bytes)
    217209#endif
    218210        return 0;
     
    225217#ifdef PROCESSOR_ARCH_armv7_a
    226218        CSSELR_write((level & CCSELR_LEVEL_MASK) << CCSELR_LEVEL_SHIFT);
    227         const uint32_t ccsidr = CCSIDR_read();
    228         return CCSIDR_WAYS(ccsidr);
     219        const unsigned ways = 1 +
     220            ((CCSIDR_read() >> CCSIDR_ASSOC_SHIFT) & CCSIDR_ASSOC_MASK);
     221        return ways;
    229222#endif
    230223        return 0;
     
    236229#ifdef PROCESSOR_ARCH_armv7_a
    237230        CSSELR_write((level & CCSELR_LEVEL_MASK) << CCSELR_LEVEL_SHIFT);
    238         const uint32_t ccsidr = CCSIDR_read();
    239         return CCSIDR_SETS(ccsidr);
     231        const unsigned sets = 1 +
     232            ((CCSIDR_read() >> CCSIDR_NUMSETS_SHIFT) & CCSIDR_NUMSETS_MASK);
     233        return sets;
    240234#endif
    241235        return 0;
     
    247241#ifdef PROCESSOR_ARCH_armv7_a
    248242        const uint32_t val = CLIDR_read();
    249         for (unsigned i = 0; i < 8; ++i) {
     243        for (unsigned i = 1; i <= 7; ++i) {
    250244                const unsigned ctype = CLIDR_CACHE(i, val);
    251245                switch (ctype) {
     
    286280                const unsigned ways = dcache_ways(i);
    287281                const unsigned sets = dcache_sets(i);
    288                 const unsigned way_shift = 32 - log2(ways);
     282                const unsigned way_shift =  31 - log2(ways);
    289283                const unsigned set_shift = dcache_linesize_log(i);
    290284                dcache_clean_manual(i, false, ways, sets, way_shift, set_shift);
     
    299293                const unsigned ways = dcache_ways(i);
    300294                const unsigned sets = dcache_sets(i);
    301                 const unsigned way_shift = 32 - log2(ways);
     295                const unsigned way_shift =  31 - log2(ways);
    302296                const unsigned set_shift = dcache_linesize_log(i);
    303297                dcache_clean_manual(i, true, ways, sets, way_shift, set_shift);
     
    325319void icache_invalidate(void)
    326320{
    327 #if defined(PROCESSOR_ARCH_armv7_a)
    328321        ICIALLU_write(0);
    329 #else
    330         ICIALL_write(0);
    331 #endif
    332 }
    333 
    334 #if !defined(PROCESSOR_ARCH_armv7_a)
    335 static bool cache_is_unified(void)
    336 {
    337         if (MIDR_read() != CTR_read()) {
    338                 /* We have the CTR register */
    339                 return (CTR_read() & CTR_SEP_FLAG) != CTR_SEP_FLAG;
    340         } else {
    341                 panic("Unknown cache type");
    342         }
    343 }
    344 #endif
    345 
    346 void dcache_invalidate(void)
    347 {
    348 #if defined(PROCESSOR_ARCH_armv7_a)
    349         dcache_flush_invalidate();
    350 #else
    351         if (cache_is_unified())
    352                 CIALL_write(0);
    353         else
    354                 DCIALL_write(0);
    355 #endif
    356 }
    357 
    358 void dcache_clean_mva_pou(uintptr_t mva)
    359 {
    360 #if defined(PROCESSOR_ARCH_armv7_a)
    361         DCCMVAU_write(mva);
    362 #else
    363         if (cache_is_unified())
    364                 CCMVA_write(mva);
    365         else
    366                 DCCMVA_write(mva);
    367 #endif
    368322}
    369323
Note: See TracChangeset for help on using the changeset viewer.