Home | History | Annotate | Line # | Download | only in arm
arm_sa1100.cpp revision 1.1.4.2
      1  1.1.4.2  matt /*	$NetBSD: arm_sa1100.cpp,v 1.1.4.2 2008/03/23 02:04:03 matt Exp $	*/
      2  1.1.4.2  matt 
      3  1.1.4.2  matt /*-
      4  1.1.4.2  matt  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  1.1.4.2  matt  * All rights reserved.
      6  1.1.4.2  matt  *
      7  1.1.4.2  matt  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1.4.2  matt  * by UCHIYAMA Yasushi.
      9  1.1.4.2  matt  *
     10  1.1.4.2  matt  * Redistribution and use in source and binary forms, with or without
     11  1.1.4.2  matt  * modification, are permitted provided that the following conditions
     12  1.1.4.2  matt  * are met:
     13  1.1.4.2  matt  * 1. Redistributions of source code must retain the above copyright
     14  1.1.4.2  matt  *    notice, this list of conditions and the following disclaimer.
     15  1.1.4.2  matt  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.4.2  matt  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.4.2  matt  *    documentation and/or other materials provided with the distribution.
     18  1.1.4.2  matt  * 3. All advertising materials mentioning features or use of this software
     19  1.1.4.2  matt  *    must display the following acknowledgement:
     20  1.1.4.2  matt  *        This product includes software developed by the NetBSD
     21  1.1.4.2  matt  *        Foundation, Inc. and its contributors.
     22  1.1.4.2  matt  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1.4.2  matt  *    contributors may be used to endorse or promote products derived
     24  1.1.4.2  matt  *    from this software without specific prior written permission.
     25  1.1.4.2  matt  *
     26  1.1.4.2  matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1.4.2  matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1.4.2  matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1.4.2  matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1.4.2  matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1.4.2  matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1.4.2  matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1.4.2  matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1.4.2  matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1.4.2  matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1.4.2  matt  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1.4.2  matt  */
     38  1.1.4.2  matt 
     39  1.1.4.2  matt #include <arm/arm_arch.h>
     40  1.1.4.2  matt #include <console.h>
     41  1.1.4.2  matt #include <memory.h>
     42  1.1.4.2  matt #include <arm/arm_sa1100.h>
     43  1.1.4.2  matt 
     44  1.1.4.2  matt /*
     45  1.1.4.2  matt  * Strong-ARM SA-1100 (e.g. HP-820 JORNADA)
     46  1.1.4.2  matt  */
     47  1.1.4.2  matt 
     48  1.1.4.2  matt #define	PAGE_SIZE		0x1000
     49  1.1.4.2  matt #define	DRAM_BANK_NUM		4		/* total 512MByte */
     50  1.1.4.2  matt #define	DRAM_BANK_SIZE		0x08000000	/* 128Mbyte */
     51  1.1.4.2  matt 
     52  1.1.4.2  matt #define	DRAM_BANK0_START	0xc0000000
     53  1.1.4.2  matt #define	DRAM_BANK0_SIZE		DRAM_BANK_SIZE
     54  1.1.4.2  matt #define	DRAM_BANK1_START	0xc8000000
     55  1.1.4.2  matt #define	DRAM_BANK1_SIZE		DRAM_BANK_SIZE
     56  1.1.4.2  matt #define	DRAM_BANK2_START	0xd0000000
     57  1.1.4.2  matt #define	DRAM_BANK2_SIZE		DRAM_BANK_SIZE
     58  1.1.4.2  matt #define	DRAM_BANK3_START	0xd8000000
     59  1.1.4.2  matt #define	DRAM_BANK3_SIZE		DRAM_BANK_SIZE
     60  1.1.4.2  matt #define	ZERO_BANK_START		0xe0000000
     61  1.1.4.2  matt #define	ZERO_BANK_SIZE		DRAM_BANK_SIZE
     62  1.1.4.2  matt 
     63  1.1.4.2  matt __BEGIN_DECLS
     64  1.1.4.2  matt 
     65  1.1.4.2  matt // 2nd bootloader
     66  1.1.4.2  matt void boot_func(kaddr_t, kaddr_t, kaddr_t, kaddr_t);
     67  1.1.4.2  matt extern char boot_func_end[];
     68  1.1.4.2  matt #define	BOOT_FUNC_START		reinterpret_cast <vaddr_t>(boot_func)
     69  1.1.4.2  matt #define	BOOT_FUNC_END		reinterpret_cast <vaddr_t>(boot_func_end)
     70  1.1.4.2  matt 
     71  1.1.4.2  matt /* jump to 2nd loader */
     72  1.1.4.2  matt void FlatJump(kaddr_t, kaddr_t, kaddr_t, kaddr_t);
     73  1.1.4.2  matt 
     74  1.1.4.2  matt __END_DECLS
     75  1.1.4.2  matt 
     76  1.1.4.2  matt SA1100Architecture::SA1100Architecture(Console *&cons, MemoryManager *&mem)
     77  1.1.4.2  matt 	: ARMArchitecture(cons, mem)
     78  1.1.4.2  matt {
     79  1.1.4.2  matt 	DPRINTF((TEXT("SA-11x0 CPU.\n")));
     80  1.1.4.2  matt }
     81  1.1.4.2  matt 
     82  1.1.4.2  matt SA1100Architecture::~SA1100Architecture(void)
     83  1.1.4.2  matt {
     84  1.1.4.2  matt }
     85  1.1.4.2  matt 
     86  1.1.4.2  matt BOOL
     87  1.1.4.2  matt SA1100Architecture::init(void)
     88  1.1.4.2  matt {
     89  1.1.4.2  matt 	if (!_mem->init()) {
     90  1.1.4.2  matt 		DPRINTF((TEXT("can't initialize memory manager.\n")));
     91  1.1.4.2  matt 		return FALSE;
     92  1.1.4.2  matt 	}
     93  1.1.4.2  matt 	// set D-RAM information
     94  1.1.4.2  matt 	_mem->loadBank(DRAM_BANK0_START, DRAM_BANK_SIZE);
     95  1.1.4.2  matt 	_mem->loadBank(DRAM_BANK1_START, DRAM_BANK_SIZE);
     96  1.1.4.2  matt 	_mem->loadBank(DRAM_BANK2_START, DRAM_BANK_SIZE);
     97  1.1.4.2  matt 	_mem->loadBank(DRAM_BANK3_START, DRAM_BANK_SIZE);
     98  1.1.4.2  matt 
     99  1.1.4.2  matt 	return TRUE;
    100  1.1.4.2  matt }
    101  1.1.4.2  matt 
    102  1.1.4.2  matt void
    103  1.1.4.2  matt SA1100Architecture::testFramebuffer(void)
    104  1.1.4.2  matt {
    105  1.1.4.2  matt 	// get frame buffer address from LCD controller register.
    106  1.1.4.2  matt 	paddr_t fbaddr_p = _mem->readPhysical4(0xb0100010); // 0xc0002e00
    107  1.1.4.2  matt 	// map frame buffer
    108  1.1.4.2  matt 	vaddr_t fbaddr_v = _mem->mapPhysicalPage(fbaddr_p, 0x50000,
    109  1.1.4.2  matt 	    PAGE_READWRITE);
    110  1.1.4.2  matt 
    111  1.1.4.2  matt 	// test frame buffer
    112  1.1.4.2  matt 	int j, k;
    113  1.1.4.2  matt 	DI();
    114  1.1.4.2  matt 	for (j = 0; j < 480; j++)
    115  1.1.4.2  matt 		for (k = 0; k < 640; k++)
    116  1.1.4.2  matt 			VOLATILE_REF8(fbaddr_v + 0x200 + j * 640 + k)
    117  1.1.4.2  matt 			    = j * k & 0xff;
    118  1.1.4.2  matt 	for (j = 120; j < 360; j++)
    119  1.1.4.2  matt 		for (k = 120; k < 520; k++)
    120  1.1.4.2  matt 			VOLATILE_REF8(fbaddr_v + 0x200 + j * 640 + k) = 0x3;
    121  1.1.4.2  matt 	EI();
    122  1.1.4.2  matt 	_mem->unmapPhysicalPage(fbaddr_v);
    123  1.1.4.2  matt }
    124  1.1.4.2  matt 
    125  1.1.4.2  matt void
    126  1.1.4.2  matt SA1100Architecture::testUART(void)
    127  1.1.4.2  matt {
    128  1.1.4.2  matt #define	TBY			VOLATILE_REF(uart + 0x20)
    129  1.1.4.2  matt #define	UTDR			VOLATILE_REF(uart + 0x14)
    130  1.1.4.2  matt #define	TBY_BUSY		while (TBY & 0x1)
    131  1.1.4.2  matt #define	UTDR_PUTCHAR(c)		(UTDR =(c))
    132  1.1.4.2  matt #define	_(c)								\
    133  1.1.4.2  matt __BEGIN_MACRO								\
    134  1.1.4.2  matt 	TBY_BUSY;							\
    135  1.1.4.2  matt 	UTDR_PUTCHAR(c);						\
    136  1.1.4.2  matt __END_MACRO
    137  1.1.4.2  matt 	vaddr_t uart =
    138  1.1.4.2  matt 	    _mem->mapPhysicalPage(0x80050000, 0x100, PAGE_READWRITE);
    139  1.1.4.2  matt 	_('H');_('e');_('l');_('l');_('o');_(' ');
    140  1.1.4.2  matt 	_('W');_('o');_('r');_('l');_('d');_('\r');_('\n');
    141  1.1.4.2  matt 	_mem->unmapPhysicalPage(uart);
    142  1.1.4.2  matt }
    143  1.1.4.2  matt 
    144  1.1.4.2  matt BOOL
    145  1.1.4.2  matt SA1100Architecture::setupLoader(void)
    146  1.1.4.2  matt {
    147  1.1.4.2  matt 	vaddr_t v;
    148  1.1.4.2  matt 	vsize_t sz = BOOT_FUNC_END - BOOT_FUNC_START;
    149  1.1.4.2  matt 
    150  1.1.4.2  matt 	// check 2nd bootloader size.
    151  1.1.4.2  matt 	if (sz > _mem->getPageSize()) {
    152  1.1.4.2  matt 		DPRINTF((TEXT("2nd bootloader size(%dbyte) is larger than page size(%d).\n"),
    153  1.1.4.2  matt 		    sz, _mem->getPageSize()));
    154  1.1.4.2  matt 		return FALSE;
    155  1.1.4.2  matt 	}
    156  1.1.4.2  matt 
    157  1.1.4.2  matt 	// get physical mapped page and copy loader to there.
    158  1.1.4.2  matt 	// don't writeback D-cache here. make sure to writeback before jump.
    159  1.1.4.2  matt 	if (!_mem->getPage(v , _loader_addr)) {
    160  1.1.4.2  matt 		DPRINTF((TEXT("can't get page for 2nd loader.\n")));
    161  1.1.4.2  matt 		return FALSE;
    162  1.1.4.2  matt 	}
    163  1.1.4.2  matt 	DPRINTF((TEXT("2nd bootloader vaddr=0x%08x paddr=0x%08x\n"),
    164  1.1.4.2  matt 	    (unsigned)v,(unsigned)_loader_addr));
    165  1.1.4.2  matt 
    166  1.1.4.2  matt 	memcpy(reinterpret_cast <LPVOID>(v),
    167  1.1.4.2  matt 	    reinterpret_cast <LPVOID>(BOOT_FUNC_START), sz);
    168  1.1.4.2  matt 	DPRINTF((TEXT("2nd bootloader copy done.\n")));
    169  1.1.4.2  matt 
    170  1.1.4.2  matt 	return TRUE;
    171  1.1.4.2  matt }
    172  1.1.4.2  matt 
    173  1.1.4.2  matt void
    174  1.1.4.2  matt SA1100Architecture::jump(paddr_t info, paddr_t pvec)
    175  1.1.4.2  matt {
    176  1.1.4.2  matt 	kaddr_t sp;
    177  1.1.4.2  matt 	vaddr_t v;
    178  1.1.4.2  matt 	paddr_t p;
    179  1.1.4.2  matt 
    180  1.1.4.2  matt 	// stack for bootloader
    181  1.1.4.2  matt 	_mem->getPage(v, p);
    182  1.1.4.2  matt 	sp = ptokv(p) + _mem->getPageSize();
    183  1.1.4.2  matt 	DPRINTF((TEXT("sp for bootloader = %08x + %08x = %08x\n"),
    184  1.1.4.2  matt 	    ptokv(p), _mem->getPageSize(), sp));
    185  1.1.4.2  matt 
    186  1.1.4.2  matt 	// writeback whole D-cache
    187  1.1.4.2  matt 	WritebackDCache();
    188  1.1.4.2  matt 
    189  1.1.4.2  matt 	SetKMode(1);
    190  1.1.4.2  matt 	FlatJump(info, pvec, sp, _loader_addr);
    191  1.1.4.2  matt 	// NOTREACHED
    192  1.1.4.2  matt }
    193