Home | History | Annotate | Line # | Download | only in marvell
marvell_start.S revision 1.1.8.1
      1  1.1.8.1    bouyer /*	$NetBSD: marvell_start.S,v 1.1.8.1 2011/02/08 16:19:17 bouyer Exp $ */
      2      1.1  kiyohara /*
      3      1.1  kiyohara  * Copyright (C) 2005, 2006 WIDE Project and SOUM Corporation.
      4      1.1  kiyohara  * All rights reserved.
      5      1.1  kiyohara  *
      6      1.1  kiyohara  * Written by Takashi Kiyohara and Susumu Miki for WIDE Project and SOUM
      7      1.1  kiyohara  * Corporation.
      8      1.1  kiyohara  *
      9      1.1  kiyohara  * Redistribution and use in source and binary forms, with or without
     10      1.1  kiyohara  * modification, are permitted provided that the following conditions
     11      1.1  kiyohara  * are met:
     12      1.1  kiyohara  * 1. Redistributions of source code must retain the above copyright
     13      1.1  kiyohara  *    notice, this list of conditions and the following disclaimer.
     14      1.1  kiyohara  * 2. Redistributions in binary form must reproduce the above copyright
     15      1.1  kiyohara  *    notice, this list of conditions and the following disclaimer in the
     16      1.1  kiyohara  *    documentation and/or other materials provided with the distribution.
     17      1.1  kiyohara  * 3. Neither the name of the project nor the name of SOUM Corporation
     18      1.1  kiyohara  *    may be used to endorse or promote products derived from this software
     19      1.1  kiyohara  *    without specific prior written permission.
     20      1.1  kiyohara  *
     21      1.1  kiyohara  * THIS SOFTWARE IS PROVIDED BY THE PROJECT and SOUM CORPORATION ``AS IS''
     22      1.1  kiyohara  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     23      1.1  kiyohara  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     24      1.1  kiyohara  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT AND SOUM CORPORATION
     25      1.1  kiyohara  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26      1.1  kiyohara  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27      1.1  kiyohara  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28      1.1  kiyohara  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29      1.1  kiyohara  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30      1.1  kiyohara  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     31      1.1  kiyohara  * POSSIBILITY OF SUCH DAMAGE.
     32      1.1  kiyohara  */
     33      1.1  kiyohara /*
     34      1.1  kiyohara  * Copyright (c) 2002, 2003  Genetec Corporation.  All rights reserved.
     35      1.1  kiyohara  * Written by Hiroyuki Bessho for Genetec Corporation.
     36      1.1  kiyohara  *
     37      1.1  kiyohara  * Redistribution and use in source and binary forms, with or without
     38      1.1  kiyohara  * modification, are permitted provided that the following conditions
     39      1.1  kiyohara  * are met:
     40      1.1  kiyohara  * 1. Redistributions of source code must retain the above copyright
     41      1.1  kiyohara  *    notice, this list of conditions and the following disclaimer.
     42      1.1  kiyohara  * 2. Redistributions in binary form must reproduce the above copyright
     43      1.1  kiyohara  *    notice, this list of conditions and the following disclaimer in the
     44      1.1  kiyohara  *    documentation and/or other materials provided with the distribution.
     45      1.1  kiyohara  * 3. The name of Genetec Corporation may not be used to endorse or
     46      1.1  kiyohara  *    promote products derived from this software without specific prior
     47      1.1  kiyohara  *    written permission.
     48      1.1  kiyohara  *
     49      1.1  kiyohara  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     50      1.1  kiyohara  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     51      1.1  kiyohara  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     52      1.1  kiyohara  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     53      1.1  kiyohara  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     54      1.1  kiyohara  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     55      1.1  kiyohara  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     56      1.1  kiyohara  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     57      1.1  kiyohara  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     58      1.1  kiyohara  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     59      1.1  kiyohara  * POSSIBILITY OF SUCH DAMAGE.
     60      1.1  kiyohara  */
     61      1.1  kiyohara 
     62      1.1  kiyohara #include "opt_cputypes.h"
     63      1.1  kiyohara #include <machine/asm.h>
     64      1.1  kiyohara #include <arm/armreg.h>
     65  1.1.8.1    bouyer #include "assym.h"
     66  1.1.8.1    bouyer 
     67  1.1.8.1    bouyer RCSID("$NetBSD: marvell_start.S,v 1.1.8.1 2011/02/08 16:19:17 bouyer Exp $")
     68      1.1  kiyohara 
     69      1.1  kiyohara #ifndef SDRAM_START
     70      1.1  kiyohara #define SDRAM_START	0x00000000
     71      1.1  kiyohara #endif
     72      1.1  kiyohara 
     73      1.1  kiyohara /*
     74      1.1  kiyohara  * CPWAIT -- Canonical method to wait for CP15 update.
     75      1.1  kiyohara  * NOTE: Clobbers the specified temp reg.
     76      1.1  kiyohara  * copied from arm/arm/cpufunc_asm_xscale.S
     77      1.1  kiyohara  * XXX: better be in a common header file.
     78      1.1  kiyohara  */
     79      1.1  kiyohara #define	CPWAIT_BRANCH							 \
     80      1.1  kiyohara 	sub	pc, pc, #4
     81      1.1  kiyohara 
     82      1.1  kiyohara #define	CPWAIT(tmp)							 \
     83      1.1  kiyohara 	mrc	p15, 0, tmp, c2, c0, 0	/* arbitrary read of CP15 */	;\
     84      1.1  kiyohara 	mov	tmp, tmp		/* wait for it to complete */	;\
     85      1.1  kiyohara 	CPWAIT_BRANCH			/* branch to next insn */
     86      1.1  kiyohara 
     87      1.1  kiyohara /*
     88      1.1  kiyohara  * Kernel start routine for Marvell boards
     89      1.1  kiyohara  * this code is excuted at the very first after the kernel is loaded
     90      1.1  kiyohara  * by U-Boot.
     91      1.1  kiyohara  */
     92      1.1  kiyohara 	.text
     93      1.1  kiyohara 
     94      1.1  kiyohara 	.global	_C_LABEL(marvell_start)
     95      1.1  kiyohara _C_LABEL(marvell_start):
     96      1.1  kiyohara 	/* The Loader for Marvell board is u-boot.  it's running on RAM */
     97      1.1  kiyohara 	/*
     98      1.1  kiyohara 	 *  Kernel is loaded in SDRAM (0x00200000..), and is expected to run
     99      1.1  kiyohara 	 *  in VA 0xc0200000..
    100      1.1  kiyohara 	 */
    101      1.1  kiyohara 
    102      1.1  kiyohara #ifdef CPU_SHEEVA
    103      1.1  kiyohara 	mrc	p15, 0, r4, c0, c0, 0
    104      1.1  kiyohara 	and	r4, r4, #CPU_ID_CPU_MASK
    105      1.1  kiyohara 	adr	r5, sheeva_cores_start
    106      1.1  kiyohara 	adr	r6, sheeva_cores_end
    107      1.1  kiyohara 1:
    108      1.1  kiyohara 	cmp	r5, r6
    109      1.1  kiyohara 	beq	2f
    110      1.1  kiyohara 	ldmia	r5!, {r7}
    111      1.1  kiyohara 	cmp	r4, r7
    112      1.1  kiyohara 	bne	1b
    113      1.1  kiyohara 
    114      1.1  kiyohara 	/* Make sure L2 is disabled */
    115      1.1  kiyohara 	mrc	p15, 1, r0, c15, c1, 0	@ Get Marvell Extra Features Register
    116      1.1  kiyohara 	bic	r0, r0, #0x00400000	@ disable L2 cache
    117      1.1  kiyohara 	mcr	p15, 1, r0, c15, c1, 0
    118      1.1  kiyohara 2:
    119      1.1  kiyohara #endif
    120      1.1  kiyohara 	/* save u-boot's args */
    121      1.1  kiyohara 	adr	r4, u_boot_args
    122      1.1  kiyohara 	nop
    123      1.1  kiyohara 	nop
    124      1.1  kiyohara 	nop
    125      1.1  kiyohara 	stmia	r4!, {r0, r1, r2, r3}
    126      1.1  kiyohara 	nop
    127      1.1  kiyohara 	nop
    128      1.1  kiyohara 	nop
    129      1.1  kiyohara 
    130      1.1  kiyohara 	/* build page table from scratch */
    131      1.1  kiyohara 	ldr	r0, Lstartup_pagetable		/* pagetable */
    132      1.1  kiyohara 	adr	r4, mmu_init_table
    133      1.1  kiyohara 	b	3f
    134      1.1  kiyohara 
    135      1.1  kiyohara 2:
    136      1.1  kiyohara 	str	r3, [r0, r2]
    137      1.1  kiyohara 	add	r2, r2, #4
    138      1.1  kiyohara 	add	r3, r3, #(L1_S_SIZE)
    139      1.1  kiyohara 	adds	r1, r1, #-1
    140      1.1  kiyohara 	bhi	2b
    141      1.1  kiyohara 3:
    142      1.1  kiyohara 	ldmia	r4!, {r1, r2, r3}	/* # of sections, VA, PA|attr */
    143      1.1  kiyohara 	cmp	r1, #0
    144      1.1  kiyohara 	bne	2b
    145      1.1  kiyohara 
    146      1.1  kiyohara 	mcr	p15, 0, r0, c2, c0, 0	/* Set TTB */
    147      1.1  kiyohara 	mcr	p15, 0, r0, c8, c7, 0	/* Flush TLB */
    148      1.1  kiyohara 	mov	r0, #0
    149      1.1  kiyohara 	mcr	p15, 0, r0, c7, c6, 0	/* Invalidate D cache */
    150      1.1  kiyohara 	mcr	p15, 0, r0, c7, c10, 4	/* Drain write-buffer */
    151      1.1  kiyohara 
    152      1.1  kiyohara 	/* Ensure safe Translation Table. */
    153      1.1  kiyohara 
    154      1.1  kiyohara 	/* Set the Domain Access register.  Very important! */
    155      1.1  kiyohara         mov     r0, #((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT)
    156      1.1  kiyohara 	mcr	p15, 0, r0, c3, c0, 0
    157      1.1  kiyohara 
    158      1.1  kiyohara 	/* Enable MMU */
    159      1.1  kiyohara 	mrc	p15, 0, r0, c1, c0, 0
    160      1.1  kiyohara 	orr	r0, r0, #CPU_CONTROL_SYST_ENABLE
    161      1.1  kiyohara 	orr	r0, r0, #CPU_CONTROL_MMU_ENABLE
    162      1.1  kiyohara 	mcr	p15, 0, r0, c1, c0, 0
    163      1.1  kiyohara 	CPWAIT(r0)
    164      1.1  kiyohara 
    165      1.1  kiyohara 	/* Jump to kernel code in TRUE VA */
    166      1.1  kiyohara 	adr	r0, Lstart
    167      1.1  kiyohara 	ldr	pc, [r0]
    168      1.1  kiyohara 
    169      1.1  kiyohara Lstart:
    170      1.1  kiyohara 	.word	start
    171      1.1  kiyohara 
    172      1.1  kiyohara #ifndef STARTUP_PAGETABLE_ADDR
    173      1.1  kiyohara #define STARTUP_PAGETABLE_ADDR 0x00004000	/* aligned 16kByte */
    174      1.1  kiyohara #endif
    175      1.1  kiyohara Lstartup_pagetable:
    176      1.1  kiyohara 	.word	STARTUP_PAGETABLE_ADDR
    177      1.1  kiyohara 
    178      1.1  kiyohara 	.globl	_C_LABEL(u_boot_args)
    179      1.1  kiyohara u_boot_args:
    180      1.1  kiyohara 	.space	16			/* r0, r1, r2, r3 */
    181      1.1  kiyohara 
    182      1.1  kiyohara #ifdef CPU_SHEEVA
    183      1.1  kiyohara sheeva_cores_start:
    184      1.1  kiyohara 	.word	CPU_ID_MV88SV131
    185      1.1  kiyohara 	.word	CPU_ID_MV88FR571_VD		/* Is it Sheeva? */
    186      1.1  kiyohara sheeva_cores_end:
    187      1.1  kiyohara #endif
    188      1.1  kiyohara 
    189      1.1  kiyohara #define MMU_INIT(va,pa,n_sec,attr) \
    190      1.1  kiyohara 	.word	n_sec					    ; \
    191      1.1  kiyohara 	.word	4 * ((va) >> L1_S_SHIFT)		    ; \
    192      1.1  kiyohara 	.word	(pa) | (attr)				    ;
    193      1.1  kiyohara 
    194      1.1  kiyohara mmu_init_table:
    195      1.1  kiyohara 	/* fill all table VA==PA */
    196      1.1  kiyohara 	MMU_INIT(0x00000000, 0x00000000,
    197  1.1.8.1    bouyer 	    1 << (32 - L1_S_SHIFT), L1_TYPE_S | L1_S_AP_KRW)
    198      1.1  kiyohara 
    199      1.1  kiyohara 	/* map SDRAM VA==PA, WT cacheable */
    200      1.1  kiyohara 	MMU_INIT(SDRAM_START, SDRAM_START,
    201  1.1.8.1    bouyer 	    128, L1_TYPE_S | L1_S_C | L1_S_AP_KRW)
    202      1.1  kiyohara 
    203      1.1  kiyohara 	/* map VA 0xc0000000..0xc7ffffff to PA 0x00000000..0x07ffffff */
    204      1.1  kiyohara 	MMU_INIT(0xc0000000, SDRAM_START,
    205  1.1.8.1    bouyer 	    128, L1_TYPE_S | L1_S_C | L1_S_AP_KRW)
    206      1.1  kiyohara 
    207      1.1  kiyohara 	.word	0			/* end of table */
    208