Ignore:
File:
1 edited

Legend:

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

    rc8a5c8c r93d8022  
    4141#include <print.h>
    4242
     43#ifdef CONFIG_FPU
     44#include <arch/fpu_context.h>
     45#endif
     46
    4347static inline unsigned log2(unsigned val)
    4448{
     
    6064static const char * implementer(unsigned id)
    6165{
    62         switch (id)
    63         {
     66        switch (id) {
    6467        case 0x41: return "ARM Limited";
    6568        case 0x44: return "Digital Equipment Corporation";
     
    127130{
    128131        uint32_t control_reg = SCTLR_read();
    129        
     132
     133        dcache_invalidate();
     134        read_barrier();
     135
    130136        /* Turn off tex remap, RAZ/WI prior to armv7 */
    131137        control_reg &= ~SCTLR_TEX_REMAP_EN_FLAG;
     
    157163#endif
    158164#ifdef PROCESSOR_ARCH_armv7_a
    159          /* ICache coherency is elaborate on in barrier.h.
     165         /* ICache coherency is elaborated on in barrier.h.
    160166          * VIPT and PIPT caches need maintenance only on code modify,
    161167          * so it should be safe for general use.
     
    166172                control_reg |=
    167173                    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);
    168177        }
    169178#endif
     
    204213#ifdef PROCESSOR_ARCH_armv7_a
    205214        CSSELR_write((level & CCSELR_LEVEL_MASK) << CCSELR_LEVEL_SHIFT);
    206         const unsigned ls_log = 2 +
    207             ((CCSIDR_read() >> CCSIDR_LINESIZE_SHIFT) & CCSIDR_LINESIZE_MASK);
    208         return ls_log + 2; //return log2(bytes)
     215        const uint32_t ccsidr = CCSIDR_read();
     216        return CCSIDR_LINESIZE_LOG(ccsidr);
    209217#endif
    210218        return 0;
     
    217225#ifdef PROCESSOR_ARCH_armv7_a
    218226        CSSELR_write((level & CCSELR_LEVEL_MASK) << CCSELR_LEVEL_SHIFT);
    219         const unsigned ways = 1 +
    220             ((CCSIDR_read() >> CCSIDR_ASSOC_SHIFT) & CCSIDR_ASSOC_MASK);
    221         return ways;
     227        const uint32_t ccsidr = CCSIDR_read();
     228        return CCSIDR_WAYS(ccsidr);
    222229#endif
    223230        return 0;
     
    229236#ifdef PROCESSOR_ARCH_armv7_a
    230237        CSSELR_write((level & CCSELR_LEVEL_MASK) << CCSELR_LEVEL_SHIFT);
    231         const unsigned sets = 1 +
    232             ((CCSIDR_read() >> CCSIDR_NUMSETS_SHIFT) & CCSIDR_NUMSETS_MASK);
    233         return sets;
     238        const uint32_t ccsidr = CCSIDR_read();
     239        return CCSIDR_SETS(ccsidr);
    234240#endif
    235241        return 0;
     
    241247#ifdef PROCESSOR_ARCH_armv7_a
    242248        const uint32_t val = CLIDR_read();
    243         for (unsigned i = 1; i <= 7; ++i) {
     249        for (unsigned i = 0; i < 8; ++i) {
    244250                const unsigned ctype = CLIDR_CACHE(i, val);
    245251                switch (ctype) {
     
    280286                const unsigned ways = dcache_ways(i);
    281287                const unsigned sets = dcache_sets(i);
    282                 const unsigned way_shift =  31 - log2(ways);
     288                const unsigned way_shift = 32 - log2(ways);
    283289                const unsigned set_shift = dcache_linesize_log(i);
    284290                dcache_clean_manual(i, false, ways, sets, way_shift, set_shift);
     
    293299                const unsigned ways = dcache_ways(i);
    294300                const unsigned sets = dcache_sets(i);
    295                 const unsigned way_shift =  31 - log2(ways);
     301                const unsigned way_shift = 32 - log2(ways);
    296302                const unsigned set_shift = dcache_linesize_log(i);
    297303                dcache_clean_manual(i, true, ways, sets, way_shift, set_shift);
     
    319325void icache_invalidate(void)
    320326{
     327#if defined(PROCESSOR_ARCH_armv7_a)
    321328        ICIALLU_write(0);
     329#else
     330        ICIALL_write(0);
     331#endif
     332}
     333
     334#if !defined(PROCESSOR_ARCH_armv7_a)
     335static 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
     346void 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
     358void 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
    322368}
    323369
Note: See TracChangeset for help on using the changeset viewer.