18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * linux/arch/arm/mm/proc-v6.S 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2001 Deep Blue Solutions Ltd. 68c2ecf20Sopenharmony_ci * Modified by Catalin Marinas for noMMU support 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * This is the "shell" of the ARMv6 processor support. 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci#include <linux/init.h> 118c2ecf20Sopenharmony_ci#include <linux/linkage.h> 128c2ecf20Sopenharmony_ci#include <linux/pgtable.h> 138c2ecf20Sopenharmony_ci#include <asm/assembler.h> 148c2ecf20Sopenharmony_ci#include <asm/asm-offsets.h> 158c2ecf20Sopenharmony_ci#include <asm/hwcap.h> 168c2ecf20Sopenharmony_ci#include <asm/pgtable-hwdef.h> 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#include "proc-macros.S" 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define D_CACHE_LINE_SIZE 32 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#define TTB_C (1 << 0) 238c2ecf20Sopenharmony_ci#define TTB_S (1 << 1) 248c2ecf20Sopenharmony_ci#define TTB_IMP (1 << 2) 258c2ecf20Sopenharmony_ci#define TTB_RGN_NC (0 << 3) 268c2ecf20Sopenharmony_ci#define TTB_RGN_WBWA (1 << 3) 278c2ecf20Sopenharmony_ci#define TTB_RGN_WT (2 << 3) 288c2ecf20Sopenharmony_ci#define TTB_RGN_WB (3 << 3) 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#define TTB_FLAGS_UP TTB_RGN_WBWA 318c2ecf20Sopenharmony_ci#define PMD_FLAGS_UP PMD_SECT_WB 328c2ecf20Sopenharmony_ci#define TTB_FLAGS_SMP TTB_RGN_WBWA|TTB_S 338c2ecf20Sopenharmony_ci#define PMD_FLAGS_SMP PMD_SECT_WBWA|PMD_SECT_S 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ciENTRY(cpu_v6_proc_init) 368c2ecf20Sopenharmony_ci ret lr 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ciENTRY(cpu_v6_proc_fin) 398c2ecf20Sopenharmony_ci mrc p15, 0, r0, c1, c0, 0 @ ctrl register 408c2ecf20Sopenharmony_ci bic r0, r0, #0x1000 @ ...i............ 418c2ecf20Sopenharmony_ci bic r0, r0, #0x0006 @ .............ca. 428c2ecf20Sopenharmony_ci mcr p15, 0, r0, c1, c0, 0 @ disable caches 438c2ecf20Sopenharmony_ci ret lr 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci/* 468c2ecf20Sopenharmony_ci * cpu_v6_reset(loc) 478c2ecf20Sopenharmony_ci * 488c2ecf20Sopenharmony_ci * Perform a soft reset of the system. Put the CPU into the 498c2ecf20Sopenharmony_ci * same state as it would be if it had been reset, and branch 508c2ecf20Sopenharmony_ci * to what would be the reset vector. 518c2ecf20Sopenharmony_ci * 528c2ecf20Sopenharmony_ci * - loc - location to jump to for soft reset 538c2ecf20Sopenharmony_ci */ 548c2ecf20Sopenharmony_ci .align 5 558c2ecf20Sopenharmony_ci .pushsection .idmap.text, "ax" 568c2ecf20Sopenharmony_ciENTRY(cpu_v6_reset) 578c2ecf20Sopenharmony_ci mrc p15, 0, r1, c1, c0, 0 @ ctrl register 588c2ecf20Sopenharmony_ci bic r1, r1, #0x1 @ ...............m 598c2ecf20Sopenharmony_ci mcr p15, 0, r1, c1, c0, 0 @ disable MMU 608c2ecf20Sopenharmony_ci mov r1, #0 618c2ecf20Sopenharmony_ci mcr p15, 0, r1, c7, c5, 4 @ ISB 628c2ecf20Sopenharmony_ci ret r0 638c2ecf20Sopenharmony_ciENDPROC(cpu_v6_reset) 648c2ecf20Sopenharmony_ci .popsection 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci/* 678c2ecf20Sopenharmony_ci * cpu_v6_do_idle() 688c2ecf20Sopenharmony_ci * 698c2ecf20Sopenharmony_ci * Idle the processor (eg, wait for interrupt). 708c2ecf20Sopenharmony_ci * 718c2ecf20Sopenharmony_ci * IRQs are already disabled. 728c2ecf20Sopenharmony_ci */ 738c2ecf20Sopenharmony_ciENTRY(cpu_v6_do_idle) 748c2ecf20Sopenharmony_ci mov r1, #0 758c2ecf20Sopenharmony_ci mcr p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode 768c2ecf20Sopenharmony_ci mcr p15, 0, r1, c7, c0, 4 @ wait for interrupt 778c2ecf20Sopenharmony_ci ret lr 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ciENTRY(cpu_v6_dcache_clean_area) 808c2ecf20Sopenharmony_ci1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry 818c2ecf20Sopenharmony_ci add r0, r0, #D_CACHE_LINE_SIZE 828c2ecf20Sopenharmony_ci subs r1, r1, #D_CACHE_LINE_SIZE 838c2ecf20Sopenharmony_ci bhi 1b 848c2ecf20Sopenharmony_ci ret lr 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci/* 878c2ecf20Sopenharmony_ci * cpu_v6_switch_mm(pgd_phys, tsk) 888c2ecf20Sopenharmony_ci * 898c2ecf20Sopenharmony_ci * Set the translation table base pointer to be pgd_phys 908c2ecf20Sopenharmony_ci * 918c2ecf20Sopenharmony_ci * - pgd_phys - physical address of new TTB 928c2ecf20Sopenharmony_ci * 938c2ecf20Sopenharmony_ci * It is assumed that: 948c2ecf20Sopenharmony_ci * - we are not using split page tables 958c2ecf20Sopenharmony_ci */ 968c2ecf20Sopenharmony_ciENTRY(cpu_v6_switch_mm) 978c2ecf20Sopenharmony_ci#ifdef CONFIG_MMU 988c2ecf20Sopenharmony_ci mov r2, #0 998c2ecf20Sopenharmony_ci mmid r1, r1 @ get mm->context.id 1008c2ecf20Sopenharmony_ci ALT_SMP(orr r0, r0, #TTB_FLAGS_SMP) 1018c2ecf20Sopenharmony_ci ALT_UP(orr r0, r0, #TTB_FLAGS_UP) 1028c2ecf20Sopenharmony_ci mcr p15, 0, r2, c7, c5, 6 @ flush BTAC/BTB 1038c2ecf20Sopenharmony_ci mcr p15, 0, r2, c7, c10, 4 @ drain write buffer 1048c2ecf20Sopenharmony_ci mcr p15, 0, r0, c2, c0, 0 @ set TTB 0 1058c2ecf20Sopenharmony_ci#ifdef CONFIG_PID_IN_CONTEXTIDR 1068c2ecf20Sopenharmony_ci mrc p15, 0, r2, c13, c0, 1 @ read current context ID 1078c2ecf20Sopenharmony_ci bic r2, r2, #0xff @ extract the PID 1088c2ecf20Sopenharmony_ci and r1, r1, #0xff 1098c2ecf20Sopenharmony_ci orr r1, r1, r2 @ insert into new context ID 1108c2ecf20Sopenharmony_ci#endif 1118c2ecf20Sopenharmony_ci mcr p15, 0, r1, c13, c0, 1 @ set context ID 1128c2ecf20Sopenharmony_ci#endif 1138c2ecf20Sopenharmony_ci ret lr 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci/* 1168c2ecf20Sopenharmony_ci * cpu_v6_set_pte_ext(ptep, pte, ext) 1178c2ecf20Sopenharmony_ci * 1188c2ecf20Sopenharmony_ci * Set a level 2 translation table entry. 1198c2ecf20Sopenharmony_ci * 1208c2ecf20Sopenharmony_ci * - ptep - pointer to level 2 translation table entry 1218c2ecf20Sopenharmony_ci * (hardware version is stored at -1024 bytes) 1228c2ecf20Sopenharmony_ci * - pte - PTE value to store 1238c2ecf20Sopenharmony_ci * - ext - value for extended PTE bits 1248c2ecf20Sopenharmony_ci */ 1258c2ecf20Sopenharmony_ci armv6_mt_table cpu_v6 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ciENTRY(cpu_v6_set_pte_ext) 1288c2ecf20Sopenharmony_ci#ifdef CONFIG_MMU 1298c2ecf20Sopenharmony_ci armv6_set_pte_ext cpu_v6 1308c2ecf20Sopenharmony_ci#endif 1318c2ecf20Sopenharmony_ci ret lr 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci/* Suspend/resume support: taken from arch/arm/mach-s3c64xx/sleep.S */ 1348c2ecf20Sopenharmony_ci.globl cpu_v6_suspend_size 1358c2ecf20Sopenharmony_ci.equ cpu_v6_suspend_size, 4 * 6 1368c2ecf20Sopenharmony_ci#ifdef CONFIG_ARM_CPU_SUSPEND 1378c2ecf20Sopenharmony_ciENTRY(cpu_v6_do_suspend) 1388c2ecf20Sopenharmony_ci stmfd sp!, {r4 - r9, lr} 1398c2ecf20Sopenharmony_ci mrc p15, 0, r4, c13, c0, 0 @ FCSE/PID 1408c2ecf20Sopenharmony_ci#ifdef CONFIG_MMU 1418c2ecf20Sopenharmony_ci mrc p15, 0, r5, c3, c0, 0 @ Domain ID 1428c2ecf20Sopenharmony_ci mrc p15, 0, r6, c2, c0, 1 @ Translation table base 1 1438c2ecf20Sopenharmony_ci#endif 1448c2ecf20Sopenharmony_ci mrc p15, 0, r7, c1, c0, 1 @ auxiliary control register 1458c2ecf20Sopenharmony_ci mrc p15, 0, r8, c1, c0, 2 @ co-processor access control 1468c2ecf20Sopenharmony_ci mrc p15, 0, r9, c1, c0, 0 @ control register 1478c2ecf20Sopenharmony_ci stmia r0, {r4 - r9} 1488c2ecf20Sopenharmony_ci ldmfd sp!, {r4- r9, pc} 1498c2ecf20Sopenharmony_ciENDPROC(cpu_v6_do_suspend) 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ciENTRY(cpu_v6_do_resume) 1528c2ecf20Sopenharmony_ci mov ip, #0 1538c2ecf20Sopenharmony_ci mcr p15, 0, ip, c7, c14, 0 @ clean+invalidate D cache 1548c2ecf20Sopenharmony_ci mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache 1558c2ecf20Sopenharmony_ci mcr p15, 0, ip, c7, c15, 0 @ clean+invalidate cache 1568c2ecf20Sopenharmony_ci mcr p15, 0, ip, c7, c10, 4 @ drain write buffer 1578c2ecf20Sopenharmony_ci mcr p15, 0, ip, c13, c0, 1 @ set reserved context ID 1588c2ecf20Sopenharmony_ci ldmia r0, {r4 - r9} 1598c2ecf20Sopenharmony_ci mcr p15, 0, r4, c13, c0, 0 @ FCSE/PID 1608c2ecf20Sopenharmony_ci#ifdef CONFIG_MMU 1618c2ecf20Sopenharmony_ci mcr p15, 0, r5, c3, c0, 0 @ Domain ID 1628c2ecf20Sopenharmony_ci ALT_SMP(orr r1, r1, #TTB_FLAGS_SMP) 1638c2ecf20Sopenharmony_ci ALT_UP(orr r1, r1, #TTB_FLAGS_UP) 1648c2ecf20Sopenharmony_ci mcr p15, 0, r1, c2, c0, 0 @ Translation table base 0 1658c2ecf20Sopenharmony_ci mcr p15, 0, r6, c2, c0, 1 @ Translation table base 1 1668c2ecf20Sopenharmony_ci mcr p15, 0, ip, c2, c0, 2 @ TTB control register 1678c2ecf20Sopenharmony_ci#endif 1688c2ecf20Sopenharmony_ci mcr p15, 0, r7, c1, c0, 1 @ auxiliary control register 1698c2ecf20Sopenharmony_ci mcr p15, 0, r8, c1, c0, 2 @ co-processor access control 1708c2ecf20Sopenharmony_ci mcr p15, 0, ip, c7, c5, 4 @ ISB 1718c2ecf20Sopenharmony_ci mov r0, r9 @ control register 1728c2ecf20Sopenharmony_ci b cpu_resume_mmu 1738c2ecf20Sopenharmony_ciENDPROC(cpu_v6_do_resume) 1748c2ecf20Sopenharmony_ci#endif 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci string cpu_v6_name, "ARMv6-compatible processor" 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci .align 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci/* 1818c2ecf20Sopenharmony_ci * __v6_setup 1828c2ecf20Sopenharmony_ci * 1838c2ecf20Sopenharmony_ci * Initialise TLB, Caches, and MMU state ready to switch the MMU 1848c2ecf20Sopenharmony_ci * on. Return in r0 the new CP15 C1 control register setting. 1858c2ecf20Sopenharmony_ci * 1868c2ecf20Sopenharmony_ci * We automatically detect if we have a Harvard cache, and use the 1878c2ecf20Sopenharmony_ci * Harvard cache control instructions insead of the unified cache 1888c2ecf20Sopenharmony_ci * control instructions. 1898c2ecf20Sopenharmony_ci * 1908c2ecf20Sopenharmony_ci * This should be able to cover all ARMv6 cores. 1918c2ecf20Sopenharmony_ci * 1928c2ecf20Sopenharmony_ci * It is assumed that: 1938c2ecf20Sopenharmony_ci * - cache type register is implemented 1948c2ecf20Sopenharmony_ci */ 1958c2ecf20Sopenharmony_ci__v6_setup: 1968c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP 1978c2ecf20Sopenharmony_ci ALT_SMP(mrc p15, 0, r0, c1, c0, 1) @ Enable SMP/nAMP mode 1988c2ecf20Sopenharmony_ci ALT_UP(nop) 1998c2ecf20Sopenharmony_ci orr r0, r0, #0x20 2008c2ecf20Sopenharmony_ci ALT_SMP(mcr p15, 0, r0, c1, c0, 1) 2018c2ecf20Sopenharmony_ci ALT_UP(nop) 2028c2ecf20Sopenharmony_ci#endif 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci mov r0, #0 2058c2ecf20Sopenharmony_ci mcr p15, 0, r0, c7, c14, 0 @ clean+invalidate D cache 2068c2ecf20Sopenharmony_ci mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache 2078c2ecf20Sopenharmony_ci mcr p15, 0, r0, c7, c15, 0 @ clean+invalidate cache 2088c2ecf20Sopenharmony_ci#ifdef CONFIG_MMU 2098c2ecf20Sopenharmony_ci mcr p15, 0, r0, c8, c7, 0 @ invalidate I + D TLBs 2108c2ecf20Sopenharmony_ci mcr p15, 0, r0, c2, c0, 2 @ TTB control register 2118c2ecf20Sopenharmony_ci ALT_SMP(orr r4, r4, #TTB_FLAGS_SMP) 2128c2ecf20Sopenharmony_ci ALT_UP(orr r4, r4, #TTB_FLAGS_UP) 2138c2ecf20Sopenharmony_ci ALT_SMP(orr r8, r8, #TTB_FLAGS_SMP) 2148c2ecf20Sopenharmony_ci ALT_UP(orr r8, r8, #TTB_FLAGS_UP) 2158c2ecf20Sopenharmony_ci mcr p15, 0, r8, c2, c0, 1 @ load TTB1 2168c2ecf20Sopenharmony_ci#endif /* CONFIG_MMU */ 2178c2ecf20Sopenharmony_ci mcr p15, 0, r0, c7, c10, 4 @ drain write buffer and 2188c2ecf20Sopenharmony_ci @ complete invalidations 2198c2ecf20Sopenharmony_ci adr r5, v6_crval 2208c2ecf20Sopenharmony_ci ldmia r5, {r5, r6} 2218c2ecf20Sopenharmony_ci ARM_BE8(orr r6, r6, #1 << 25) @ big-endian page tables 2228c2ecf20Sopenharmony_ci mrc p15, 0, r0, c1, c0, 0 @ read control register 2238c2ecf20Sopenharmony_ci bic r0, r0, r5 @ clear bits them 2248c2ecf20Sopenharmony_ci orr r0, r0, r6 @ set them 2258c2ecf20Sopenharmony_ci#ifdef CONFIG_ARM_ERRATA_364296 2268c2ecf20Sopenharmony_ci /* 2278c2ecf20Sopenharmony_ci * Workaround for the 364296 ARM1136 r0p2 erratum (possible cache data 2288c2ecf20Sopenharmony_ci * corruption with hit-under-miss enabled). The conditional code below 2298c2ecf20Sopenharmony_ci * (setting the undocumented bit 31 in the auxiliary control register 2308c2ecf20Sopenharmony_ci * and the FI bit in the control register) disables hit-under-miss 2318c2ecf20Sopenharmony_ci * without putting the processor into full low interrupt latency mode. 2328c2ecf20Sopenharmony_ci */ 2338c2ecf20Sopenharmony_ci ldr r6, =0x4107b362 @ id for ARM1136 r0p2 2348c2ecf20Sopenharmony_ci mrc p15, 0, r5, c0, c0, 0 @ get processor id 2358c2ecf20Sopenharmony_ci teq r5, r6 @ check for the faulty core 2368c2ecf20Sopenharmony_ci mrceq p15, 0, r5, c1, c0, 1 @ load aux control reg 2378c2ecf20Sopenharmony_ci orreq r5, r5, #(1 << 31) @ set the undocumented bit 31 2388c2ecf20Sopenharmony_ci mcreq p15, 0, r5, c1, c0, 1 @ write aux control reg 2398c2ecf20Sopenharmony_ci orreq r0, r0, #(1 << 21) @ low interrupt latency configuration 2408c2ecf20Sopenharmony_ci#endif 2418c2ecf20Sopenharmony_ci ret lr @ return to head.S:__ret 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci /* 2448c2ecf20Sopenharmony_ci * V X F I D LR 2458c2ecf20Sopenharmony_ci * .... ...E PUI. .T.T 4RVI ZFRS BLDP WCAM 2468c2ecf20Sopenharmony_ci * rrrr rrrx xxx0 0101 xxxx xxxx x111 xxxx < forced 2478c2ecf20Sopenharmony_ci * 0 110 0011 1.00 .111 1101 < we want 2488c2ecf20Sopenharmony_ci */ 2498c2ecf20Sopenharmony_ci .type v6_crval, #object 2508c2ecf20Sopenharmony_civ6_crval: 2518c2ecf20Sopenharmony_ci crval clear=0x01e0fb7f, mmuset=0x00c0387d, ucset=0x00c0187c 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci __INITDATA 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci @ define struct processor (see <asm/proc-fns.h> and proc-macros.S) 2568c2ecf20Sopenharmony_ci define_processor_functions v6, dabort=v6_early_abort, pabort=v6_pabort, suspend=1 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci .section ".rodata" 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci string cpu_arch_name, "armv6" 2618c2ecf20Sopenharmony_ci string cpu_elf_name, "v6" 2628c2ecf20Sopenharmony_ci .align 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci .section ".proc.info.init", "a" 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci /* 2678c2ecf20Sopenharmony_ci * Match any ARMv6 processor core. 2688c2ecf20Sopenharmony_ci */ 2698c2ecf20Sopenharmony_ci .type __v6_proc_info, #object 2708c2ecf20Sopenharmony_ci__v6_proc_info: 2718c2ecf20Sopenharmony_ci .long 0x0007b000 2728c2ecf20Sopenharmony_ci .long 0x0007f000 2738c2ecf20Sopenharmony_ci ALT_SMP(.long \ 2748c2ecf20Sopenharmony_ci PMD_TYPE_SECT | \ 2758c2ecf20Sopenharmony_ci PMD_SECT_AP_WRITE | \ 2768c2ecf20Sopenharmony_ci PMD_SECT_AP_READ | \ 2778c2ecf20Sopenharmony_ci PMD_FLAGS_SMP) 2788c2ecf20Sopenharmony_ci ALT_UP(.long \ 2798c2ecf20Sopenharmony_ci PMD_TYPE_SECT | \ 2808c2ecf20Sopenharmony_ci PMD_SECT_AP_WRITE | \ 2818c2ecf20Sopenharmony_ci PMD_SECT_AP_READ | \ 2828c2ecf20Sopenharmony_ci PMD_FLAGS_UP) 2838c2ecf20Sopenharmony_ci .long PMD_TYPE_SECT | \ 2848c2ecf20Sopenharmony_ci PMD_SECT_XN | \ 2858c2ecf20Sopenharmony_ci PMD_SECT_AP_WRITE | \ 2868c2ecf20Sopenharmony_ci PMD_SECT_AP_READ 2878c2ecf20Sopenharmony_ci initfn __v6_setup, __v6_proc_info 2888c2ecf20Sopenharmony_ci .long cpu_arch_name 2898c2ecf20Sopenharmony_ci .long cpu_elf_name 2908c2ecf20Sopenharmony_ci /* See also feat_v6_fixup() for HWCAP_TLS */ 2918c2ecf20Sopenharmony_ci .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP|HWCAP_JAVA|HWCAP_TLS 2928c2ecf20Sopenharmony_ci .long cpu_v6_name 2938c2ecf20Sopenharmony_ci .long v6_processor_functions 2948c2ecf20Sopenharmony_ci .long v6wbi_tlb_fns 2958c2ecf20Sopenharmony_ci .long v6_user_fns 2968c2ecf20Sopenharmony_ci .long v6_cache_fns 2978c2ecf20Sopenharmony_ci .size __v6_proc_info, . - __v6_proc_info 298