11.7Sskrll/*	$NetBSD: imx31lk_start.S,v 1.7 2020/11/28 14:29:31 skrll Exp $	*/
21.4Smatt/*-
31.4Smatt * Copyright (c) 2011 The NetBSD Foundation, Inc.
41.4Smatt * All rights reserved.
51.4Smatt *
61.4Smatt * This code is derived from software contributed to The NetBSD Foundation
71.4Smatt * by Matt Thomas of 3am Software Foundry.
81.4Smatt *
91.4Smatt * Redistribution and use in source and binary forms, with or without
101.4Smatt * modification, are permitted provided that the following conditions
111.4Smatt * are met:
121.4Smatt * 1. Redistributions of source code must retain the above copyright
131.4Smatt *    notice, this list of conditions and the following disclaimer.
141.4Smatt * 2. Redistributions in binary form must reproduce the above copyright
151.4Smatt *    notice, this list of conditions and the following disclaimer in the
161.4Smatt *    documentation and/or other materials provided with the distribution.
171.4Smatt *
181.4Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
191.4Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
201.4Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
211.4Smatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
221.4Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
231.4Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
241.4Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
251.4Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
261.4Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
271.4Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
281.4Smatt * POSSIBILITY OF SUCH DAMAGE.
291.4Smatt */
301.2Smatt
311.2Smatt#include <machine/asm.h>
321.2Smatt#include <arm/armreg.h>
331.4Smatt#include "assym.h"
341.2Smatt
351.7SskrllRCSID("$NetBSD: imx31lk_start.S,v 1.7 2020/11/28 14:29:31 skrll Exp $")
361.2Smatt
371.2Smatt#ifndef SDRAM_START
381.2Smatt#define SDRAM_START 0x80000000
391.2Smatt#endif
401.2Smatt
411.3Suebayasi/*
421.3Suebayasi * L1 == "Level One" == "first-level"
431.3Suebayasi * L2 == "Level Two" == "second-level"
441.3Suebayasi */
451.2Smatt
461.2Smatt	.text
471.2Smatt
481.2Smatt	.global _C_LABEL(imx31lk_start)
491.7Sskrll
501.7SskrllENTRY_NP(imx31lk_start)
511.5Smatt	cpsid	if, #PSR_SVC32_MODE
521.2Smatt
531.2Smatt	/*
541.2Smatt	 * Firmware already mapped SDRAM VA == PA. at 0x800..
551.2Smatt	 * now map SDRAM also at VA 0x800...
561.2Smatt	 */
571.3Suebayasi	mrc	p15, 0, r0, c2, c0, 0		/* L1 table addr into r0 */
581.5Smatt#ifdef ARM_MMU_EXTENDED
591.5Smatt	mcr	p15, 0, r0, c2, c0, 1		/* copy it to TTBR1 */
601.5Smatt	mov	r3, #TTBCR_S_N_1
611.5Smatt	mcr	p15, 0, r3, c2, c0, 2		/* set TTBCR to enable TTBR1 */
621.5Smatt#endif
631.2Smatt
641.7Sskrll	ldr	r1, =KERNEL_BASE
651.7Sskrll	lsr	r1, r1, L1_S_SHIFT
661.5Smatt	add	r2, r1, #0x80			/* 128 1MB entries */
671.5Smatt	ldr	r3, .Lsdram_pde
681.2Smatt1:
691.2Smatt	/* and looplooploop */
701.5Smatt	str	r3, [r0, r1, lsl #2]
711.5Smatt	add	r3, r3, #L1_S_SIZE
721.5Smatt	add	r1, r1, #1
731.5Smatt	cmp	r1, r2
741.5Smatt	blt	1b
751.2Smatt
761.2Smatt	/*
771.2Smatt	 * Map an L1 section for each device to make this easy.
781.2Smatt	 */
791.2Smatt	/* UART1 */
801.5Smatt	mov	r1, #0xfd0			/* offset to 0xfd000000 */
811.2Smatt
821.5Smatt	ldr	r3, .Lio_pde
831.5Smatt	str	r3, [r0, r1, lsl #2]
841.2Smatt
851.2Smatt	/* etc, TBD... */
861.2Smatt
871.2Smatt	/*
881.2Smatt	 * Make domain control go full art.
891.2Smatt	 */
901.5Smatt	mov	r0, #((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL * 2))|DOMAIN_CLIENT)
911.2Smatt	mcr	p15, 0, r0, c3, c0, 0
921.2Smatt
931.2Smatt	/*
941.5Smatt	 * Now let's clean the cache again to make sure everything is in place.
951.2Smatt	 */
961.5Smatt	bl	_C_LABEL(arm11x6_idcache_wbinv_all)
971.2Smatt
981.2Smatt	/* Invalidate TLBs just to be sure */
991.5Smatt	mov	r0, #0
1001.2Smatt	mcr     p15, 0, r0, c8, c7, 0
1011.2Smatt
1021.2Smatt	/*
1031.2Smatt	 * You are standing at the gate to NetBSD. --More--
1041.2Smatt	 * Unspeakable cruelty and harm lurk down there. --More--
1051.2Smatt	 * Are you sure you want to enter?
1061.2Smatt	 */
1071.5Smatt#ifdef KERNEL_BASES_EQUAL
1081.5Smatt	b	start
1091.5Smatt#else
1101.5Smatt	adr	r0, .Lstart
1111.5Smatt	ldr	ip, [r0]
1121.5Smatt	bx	ip
1131.5Smatt#endif
1141.2Smatt
1151.2Smatt/* symbol to use for address calculation in the right VA */
1161.5Smatt#ifndef KERNEL_BASES_EQUAL
1171.2Smatt.Lstart:
1181.2Smatt	.word	start
1191.5Smatt#endif
1201.2Smatt
1211.5Smatt#if L1_S_DOM_KERNEL
1221.5Smatt#error kernel domain (L1_S_DOM_KERNEL) is not 0
1231.5Smatt#endif
1241.2Smatt
1251.5Smatt.Lsdram_pde:
1261.5Smatt	.word	0x80000000|L1_S_AP_KRW|L1_S_C|L1_S_B|L1_TYPE_S
1271.5Smatt.Lio_pde:
1281.5Smatt	.word	0x43f00000|L1_S_AP_KRW|L1_TYPE_S
1291.5SmattEND(imx31lk_start)
130