1*83d290c5STom Rini/* SPDX-License-Identifier: GPL-2.0+ */ 2fe5ea57bSMasahiro Yamada/* 34bab70a7SMasahiro Yamada * Copyright (C) 2012-2015 Panasonic Corporation 44bab70a7SMasahiro Yamada * Copyright (C) 2015-2016 Socionext Inc. 54bab70a7SMasahiro Yamada * Author: Masahiro Yamada <yamada.masahiro@socionext.com> 6fe5ea57bSMasahiro Yamada */ 7fe5ea57bSMasahiro Yamada 8fe5ea57bSMasahiro Yamada#include <config.h> 9fe5ea57bSMasahiro Yamada#include <linux/linkage.h> 10fe5ea57bSMasahiro Yamada#include <linux/sizes.h> 11fe5ea57bSMasahiro Yamada#include <asm/system.h> 12fe5ea57bSMasahiro Yamada 13fe5ea57bSMasahiro YamadaENTRY(lowlevel_init) 14fe5ea57bSMasahiro Yamada mov r8, lr @ persevere link reg across call 15fe5ea57bSMasahiro Yamada 16fe5ea57bSMasahiro Yamada /* 17fe5ea57bSMasahiro Yamada * The UniPhier Boot ROM loads SPL code to the L2 cache. 18fe5ea57bSMasahiro Yamada * But CPUs can only do instruction fetch now because start.S has 19fe5ea57bSMasahiro Yamada * cleared C and M bits. 20fe5ea57bSMasahiro Yamada * First we need to turn on MMU and Dcache again to get back 21fe5ea57bSMasahiro Yamada * data access to L2. 22fe5ea57bSMasahiro Yamada */ 23fe5ea57bSMasahiro Yamada mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register) 24fe5ea57bSMasahiro Yamada orr r0, r0, #(CR_C | CR_M) @ enable MMU and Dcache 25fe5ea57bSMasahiro Yamada mcr p15, 0, r0, c1, c0, 0 26fe5ea57bSMasahiro Yamada 270aa8b2c3SMasahiro Yamada#ifdef CONFIG_DEBUG_LL 280aa8b2c3SMasahiro Yamada bl debug_ll_init 290aa8b2c3SMasahiro Yamada#endif 300aa8b2c3SMasahiro Yamada 314cb9399eSMasahiro Yamada bl setup_init_ram @ RAM area for stack and page table 32fe5ea57bSMasahiro Yamada 33fe5ea57bSMasahiro Yamada /* 34fe5ea57bSMasahiro Yamada * Now we are using the page table embedded in the Boot ROM. 3500aa453eSMasahiro Yamada * What we need to do next is to create a page table and switch 3600aa453eSMasahiro Yamada * over to it. 37fe5ea57bSMasahiro Yamada */ 38fe5ea57bSMasahiro Yamada bl create_page_table 39c09d2905SHans de Goede bl __v7_flush_dcache_all 40fe5ea57bSMasahiro Yamada 41fe5ea57bSMasahiro Yamada /* Disable MMU and Dcache before switching Page Table */ 42fe5ea57bSMasahiro Yamada mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register) 43fe5ea57bSMasahiro Yamada bic r0, r0, #(CR_C | CR_M) @ disable MMU and Dcache 44fe5ea57bSMasahiro Yamada mcr p15, 0, r0, c1, c0, 0 45fe5ea57bSMasahiro Yamada 46fe5ea57bSMasahiro Yamada bl enable_mmu 47fe5ea57bSMasahiro Yamada 48fe5ea57bSMasahiro Yamada mov lr, r8 @ restore link 49fe5ea57bSMasahiro Yamada mov pc, lr @ back to my caller 50fe5ea57bSMasahiro YamadaENDPROC(lowlevel_init) 51fe5ea57bSMasahiro Yamada 52fe5ea57bSMasahiro YamadaENTRY(enable_mmu) 53fe5ea57bSMasahiro Yamada mrc p15, 0, r0, c2, c0, 2 @ TTBCR (Translation Table Base Control Register) 54fe5ea57bSMasahiro Yamada bic r0, r0, #0x37 55fe5ea57bSMasahiro Yamada orr r0, r0, #0x20 @ disable TTBR1 56fe5ea57bSMasahiro Yamada mcr p15, 0, r0, c2, c0, 2 57fe5ea57bSMasahiro Yamada 58fe5ea57bSMasahiro Yamada orr r0, r12, #0x8 @ Outer Cacheability for table walks: WBWA 59fe5ea57bSMasahiro Yamada mcr p15, 0, r0, c2, c0, 0 @ TTBR0 60fe5ea57bSMasahiro Yamada 61fe5ea57bSMasahiro Yamada mov r0, #0 62fe5ea57bSMasahiro Yamada mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs 63fe5ea57bSMasahiro Yamada 64fe5ea57bSMasahiro Yamada mov r0, #-1 @ manager for all domains (No permission check) 65fe5ea57bSMasahiro Yamada mcr p15, 0, r0, c3, c0, 0 @ DACR (Domain Access Control Register) 66fe5ea57bSMasahiro Yamada 67fe5ea57bSMasahiro Yamada dsb 68fe5ea57bSMasahiro Yamada isb 69fe5ea57bSMasahiro Yamada /* 70fe5ea57bSMasahiro Yamada * MMU on: 71fe5ea57bSMasahiro Yamada * TLBs was already invalidated in "../start.S" 72fe5ea57bSMasahiro Yamada * So, we don't need to invalidate it here. 73fe5ea57bSMasahiro Yamada */ 74fe5ea57bSMasahiro Yamada mrc p15, 0, r0, c1, c0, 0 @ SCTLR (System Control Register) 75fe5ea57bSMasahiro Yamada orr r0, r0, #(CR_C | CR_M) @ MMU and Dcache enable 76fe5ea57bSMasahiro Yamada mcr p15, 0, r0, c1, c0, 0 77fe5ea57bSMasahiro Yamada 78fe5ea57bSMasahiro Yamada mov pc, lr 79fe5ea57bSMasahiro YamadaENDPROC(enable_mmu) 80fe5ea57bSMasahiro Yamada 81fe5ea57bSMasahiro Yamada/* 82fe5ea57bSMasahiro Yamada * For PH1-Pro4 or older SoCs, the size of WAY is 32KB. 83fe5ea57bSMasahiro Yamada * It is large enough for tmp RAM. 84fe5ea57bSMasahiro Yamada */ 85fe5ea57bSMasahiro Yamada#define BOOT_RAM_SIZE (SZ_32K) 86fe5ea57bSMasahiro Yamada#define BOOT_RAM_BASE ((CONFIG_SPL_STACK) - (BOOT_RAM_SIZE)) 870efbbc5cSMasahiro Yamada#define BOOT_RAM_WAYS (0x00000100) @ way 8 880efbbc5cSMasahiro Yamada 890efbbc5cSMasahiro Yamada#define SSCO_BASE 0x506c0000 900efbbc5cSMasahiro Yamada#define SSCOPE 0x244 910efbbc5cSMasahiro Yamada#define SSCOQM 0x248 920efbbc5cSMasahiro Yamada#define SSCOQAD 0x24c 930efbbc5cSMasahiro Yamada#define SSCOQSZ 0x250 940efbbc5cSMasahiro Yamada#define SSCOQWN 0x258 950efbbc5cSMasahiro Yamada#define SSCOPPQSEF 0x25c 960efbbc5cSMasahiro Yamada#define SSCOLPQS 0x260 97fe5ea57bSMasahiro Yamada 98fe5ea57bSMasahiro YamadaENTRY(setup_init_ram) 990efbbc5cSMasahiro Yamada ldr r1, = SSCO_BASE 1000efbbc5cSMasahiro Yamada 1010efbbc5cSMasahiro Yamada /* Touch to zero for the boot way */ 1020efbbc5cSMasahiro Yamada0: ldr r0, = 0x00408006 @ touch to zero with address range 1030efbbc5cSMasahiro Yamada str r0, [r1, #SSCOQM] 104fe5ea57bSMasahiro Yamada ldr r0, = BOOT_RAM_BASE 1050efbbc5cSMasahiro Yamada str r0, [r1, #SSCOQAD] 106fe5ea57bSMasahiro Yamada ldr r0, = BOOT_RAM_SIZE 1070efbbc5cSMasahiro Yamada str r0, [r1, #SSCOQSZ] 1080efbbc5cSMasahiro Yamada ldr r0, = BOOT_RAM_WAYS 1090efbbc5cSMasahiro Yamada str r0, [r1, #SSCOQWN] 1100efbbc5cSMasahiro Yamada ldr r0, [r1, #SSCOPPQSEF] 111fe5ea57bSMasahiro Yamada cmp r0, #0 @ check if the command is successfully set 112fe5ea57bSMasahiro Yamada bne 0b @ try again if an error occurs 113fe5ea57bSMasahiro Yamada 1140efbbc5cSMasahiro Yamada1: ldr r0, [r1, #SSCOLPQS] 115fe5ea57bSMasahiro Yamada cmp r0, #0x4 116fe5ea57bSMasahiro Yamada bne 1b @ wait until the operation is completed 1170efbbc5cSMasahiro Yamada str r0, [r1, #SSCOLPQS] @ clear the complete notification flag 118fe5ea57bSMasahiro Yamada 119fe5ea57bSMasahiro Yamada mov pc, lr 120fe5ea57bSMasahiro YamadaENDPROC(setup_init_ram) 121fe5ea57bSMasahiro Yamada 122fe5ea57bSMasahiro Yamada#define DEVICE 0x00002002 /* Non-shareable Device */ 123fe5ea57bSMasahiro Yamada#define NORMAL 0x0000000e /* Normal Memory Write-Back, No Write-Allocate */ 124fe5ea57bSMasahiro Yamada 125fe5ea57bSMasahiro YamadaENTRY(create_page_table) 126fe5ea57bSMasahiro Yamada ldr r0, = DEVICE 127fe5ea57bSMasahiro Yamada ldr r1, = BOOT_RAM_BASE 128fe5ea57bSMasahiro Yamada mov r12, r1 @ r12 is preserved during D-cache flush 129fe5ea57bSMasahiro Yamada0: str r0, [r1], #4 @ specify all the sections as Device 130fe5ea57bSMasahiro Yamada adds r0, r0, #0x00100000 131fe5ea57bSMasahiro Yamada bcc 0b 132fe5ea57bSMasahiro Yamada 133fe5ea57bSMasahiro Yamada ldr r0, = NORMAL 134fe5ea57bSMasahiro Yamada str r0, [r12] @ mark the first section as Normal 135fe5ea57bSMasahiro Yamada add r0, r0, #0x00100000 136fe5ea57bSMasahiro Yamada str r0, [r12, #4] @ mark the second section as Normal 137fe5ea57bSMasahiro Yamada mov pc, lr 138fe5ea57bSMasahiro YamadaENDPROC(create_page_table) 139