Changeset 67d02bb in mainline


Ignore:
Timestamp:
2013-08-03T22:31:18Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
186b919
Parents:
296a80e
Message:

rm32, boot: Clear entire Dcache on startup.

Specs require this.

Location:
boot/arch/arm32
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • boot/arch/arm32/src/main.c

    r296a80e r67d02bb  
    5353extern void *bdata_end;
    5454
    55 
    56 static inline void invalidate_icache(void)
    57 {
    58         /* ICIALLU Invalidate entire ICache */
    59         asm volatile ("mov r0, #0\n" "mcr p15, 0, r0, c7, c5, 0\n" ::: "r0" );
    60 }
    61 
    62 static inline void invalidate_dcache(void *address, size_t size)
    63 {
    64         const uintptr_t addr = (uintptr_t)address;
    65         for (uintptr_t a = addr; a < addr + size; a += 4) {
    66                 /* DCIMVAC - invalidate by address to the point of coherence */
    67                 asm volatile ("mcr p15, 0, %[a], c7, c6, 1\n" :: [a]"r"(a) : );
    68         }
    69 }
    70 
    7155static inline void clean_dcache_poc(void *address, size_t size)
    7256{
     
    8266void bootstrap(void)
    8367{
    84         /* Make sure we run in memory code when caches are enabled,
    85          * make sure we read memory data too. This part is ARMv7 specific as
    86          * ARMv7 no longer invalidates caches on restart.
    87          * See chapter B2.2.2 of ARM Architecture Reference Manual p. B2-1263*/
    88         invalidate_icache();
    89         invalidate_dcache(&bdata_start, &bdata_end - &bdata_start);
    90 
    9168        /* Enable MMU and caches */
    9269        mmu_start();
     
    10582                    components[i].start, components[i].name, components[i].inflated,
    10683                    components[i].size);
    107                 /* Make sure there is no cache garbage in read locations */
    108                 invalidate_dcache(components[i].start, components[i].size);
    10984        }
    11085       
  • boot/arch/arm32/src/mm.c

    r296a80e r67d02bb  
    3737#include <arch/asm.h>
    3838#include <arch/mm.h>
     39#include <arch/cp15.h>
     40
     41#ifdef PROCESSOR_ARCH_armv7_a
     42static unsigned log2(unsigned val)
     43{
     44        unsigned log = 0;
     45        while (val >> log++);
     46        return log - 2;
     47}
     48
     49static void dcache_invalidate_level(unsigned level)
     50{
     51        CSSELR_write(level << 1);
     52        const uint32_t ccsidr = CCSIDR_read();
     53        const unsigned sets = CCSIDR_SETS(ccsidr);
     54        const unsigned ways = CCSIDR_WAYS(ccsidr);
     55        const unsigned line_log = CCSIDR_LINESIZE_LOG(ccsidr);
     56        const unsigned set_shift = line_log;
     57        const unsigned way_shift = 32 - log2(ways);
     58
     59        for (unsigned k = 0; k < ways; ++k)
     60                for (unsigned j = 0; j < sets; ++j) {
     61                        const uint32_t val = (level << 1) |
     62                            (j << set_shift) | (k << way_shift);
     63                        DCISW_write(val);
     64                }
     65}
     66
     67/** invalidate all dcaches -- armv7 */
     68static void cache_invalidate(void)
     69{
     70        const uint32_t cinfo = CLIDR_read();
     71        for (unsigned i = 0; i < 7; ++i) {
     72                switch (CLIDR_CACHE(i, cinfo))
     73                {
     74                case CLIDR_DCACHE_ONLY:
     75                case CLIDR_SEP_CACHE:
     76                case CLIDR_UNI_CACHE:
     77                        dcache_invalidate_level(i);
     78                }
     79        }
     80        asm volatile ( "dsb\n" );
     81        ICIALLU_write(0);
     82        asm volatile ( "isb\n" );
     83}
     84#endif
    3985
    4086/** Disable the MMU */
     
    156202void mmu_start() {
    157203        disable_paging();
     204#ifdef PROCESSOR_ARCH_armv7_a
     205        /* Make sure we run in memory code when caches are enabled,
     206         * make sure we read memory data too. This part is ARMv7 specific as
     207         * ARMv7 no longer invalidates caches on restart.
     208         * See chapter B2.2.2 of ARM Architecture Reference Manual p. B2-1263*/
     209        cache_invalidate();
     210#endif
    158211        init_boot_pt();
    159212        enable_paging();
Note: See TracChangeset for help on using the changeset viewer.