Ignore:
File:
1 edited

Legend:

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

    r93d8022 r2e55443  
    3737#include <arch/asm.h>
    3838#include <arch/mm.h>
    39 #include <arch/cp15.h>
    40 
    41 #ifdef PROCESSOR_ARCH_armv7_a
    42 static unsigned log2(unsigned val)
    43 {
    44         unsigned log = 0;
    45         while (val >> log++);
    46         return log - 2;
    47 }
    48 
    49 static 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 */
    68 static 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
    8539
    8640/** Disable the MMU */
     
    10660static inline int section_cacheable(pfn_t section)
    10761{
    108         const unsigned long address = section << PTE_SECTION_SHIFT;
    10962#ifdef MACHINE_gta02
    110         if (address < GTA02_IOMEM_START || address >= GTA02_IOMEM_END)
     63        unsigned long address = section << PTE_SECTION_SHIFT;
     64
     65        if (address >= GTA02_IOMEM_START && address < GTA02_IOMEM_END)
     66                return 0;
     67        else
    11168                return 1;
    11269#elif defined MACHINE_beagleboardxm
     70        const unsigned long address = section << PTE_SECTION_SHIFT;
    11371        if (address >= BBXM_RAM_START && address < BBXM_RAM_END)
    11472                return 1;
    11573#elif defined MACHINE_beaglebone
     74        const unsigned long address = section << PTE_SECTION_SHIFT;
    11675        if (address >= AM335x_RAM_START && address < AM335x_RAM_END)
    11776                return 1;
    118 #elif defined MACHINE_raspberrypi
    119         if (address < BCM2835_RAM_END)
    120                 return 1;
    12177#endif
    122         return address * 0;
     78        return 0;
    12379}
    12480
     
    13995{
    14096        pte->descriptor_type = PTE_DESCRIPTOR_SECTION;
     97        pte->bufferable = 1;
     98        pte->cacheable = section_cacheable(frame);
    14199        pte->xn = 0;
    142100        pte->domain = 0;
    143101        pte->should_be_zero_1 = 0;
    144102        pte->access_permission_0 = PTE_AP_USER_NO_KERNEL_RW;
    145 #if defined(PROCESSOR_ARCH_armv6) || defined(PROCESSOR_ARCH_armv7_a)
    146         /*
    147          * Keeps this setting in sync with memory type attributes in:
    148          * init_boot_pt (boot/arch/arm32/src/mm.c)
    149          * set_pt_level1_flags (kernel/arch/arm32/include/arch/mm/page_armv6.h)
    150          * set_ptl0_addr (kernel/arch/arm32/include/arch/mm/page.h)
    151          */
    152         pte->tex = section_cacheable(frame) ? 5 : 0;
    153         pte->cacheable = section_cacheable(frame) ? 0 : 0;
    154         pte->bufferable = section_cacheable(frame) ? 1 : 1;
    155 #else
    156         pte->bufferable = section_cacheable(frame);
    157         pte->cacheable = section_cacheable(frame);
    158103        pte->tex = 0;
    159 #endif
    160104        pte->access_permission_1 = 0;
    161105        pte->shareable = 0;
     
    169113static void init_boot_pt(void)
    170114{
    171         /*
    172          * Create 1:1 virtual-physical mapping.
    173          * Physical memory on BBxM a BBone starts at 2GB
    174          * boundary, icp has a memory mirror at 2GB.
    175          * (ARM Integrator Core Module User guide ch. 6.3,  p. 6-7)
    176          * gta02 somehow works (probably due to limited address size),
    177          * s3c2442b manual ch. 5, p.5-1:
    178          * "Address space: 128Mbytes per bank (total 1GB/8 banks)"
    179          */
    180         for (pfn_t page = 0; page < PTL0_ENTRIES; ++page)
     115        const pfn_t split_page = PTL0_ENTRIES;
     116        /* Create 1:1 virtual-physical mapping (in lower 2 GB). */
     117        pfn_t page;
     118        for (page = 0; page < split_page; page++)
    181119                init_ptl0_section(&boot_pt[page], page);
    182 
    183         /*
    184          * Tell MMU page might be cached. Keeps this setting in sync
    185          * with memory type attributes in:
    186          * init_ptl0_section (boot/arch/arm32/src/mm.c)
    187          * set_pt_level1_flags (kernel/arch/arm32/include/arch/mm/page_armv6.h)
    188          * set_ptl0_addr (kernel/arch/arm32/include/arch/mm/page.h)
    189          */
    190         uint32_t val = (uint32_t)boot_pt & TTBR_ADDR_MASK;
    191 #if defined(PROCESSOR_ARCH_armv6) || defined(PROCESSOR_ARCH_armv7_a)
    192         // FIXME: TTBR_RGN_WBWA_CACHE is unpredictable on ARMv6
    193         val |= TTBR_RGN_WBWA_CACHE | TTBR_C_FLAG;
    194 #endif
    195         TTBR0_write(val);
     120       
     121        asm volatile (
     122                "mcr p15, 0, %[pt], c2, c0, 0\n"
     123                :: [pt] "r" (boot_pt)
     124        );
    196125}
    197126
    198 static void enable_paging(void)
     127static void enable_paging()
    199128{
    200         /*
    201          * c3   - each two bits controls access to the one of domains (16)
     129        /* c3   - each two bits controls access to the one of domains (16)
    202130         * 0b01 - behave as a client (user) of a domain
    203131         */
     
    213141                 * we disable caches before jumping to kernel
    214142                 * so this is safe for all archs.
    215                  * Enable VMSAv6 the bit (23) is only writable on ARMv6.
    216                  * (and QEMU)
    217143                 */
    218 #ifdef PROCESSOR_ARCH_armv6
    219                 "ldr r1, =0x00801805\n"
    220 #else
    221144                "ldr r1, =0x00001805\n"
    222 #endif
    223145               
    224146                "orr r0, r0, r1\n"
     
    236158
    237159/** Start the MMU - initialize page table and enable paging. */
    238 void mmu_start(void)
    239 {
     160void mmu_start() {
    240161        disable_paging();
    241 #ifdef PROCESSOR_ARCH_armv7_a
    242         /* Make sure we run in memory code when caches are enabled,
    243          * make sure we read memory data too. This part is ARMv7 specific as
    244          * ARMv7 no longer invalidates caches on restart.
    245          * See chapter B2.2.2 of ARM Architecture Reference Manual p. B2-1263*/
    246         cache_invalidate();
    247 #endif
    248162        init_boot_pt();
    249163        enable_paging();
Note: See TracChangeset for help on using the changeset viewer.