xref: /netbsd-src/sys/arch/hpc/stand/hpcboot/arm/arm_pxa2x0.cpp (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1 /*	$NetBSD: arm_pxa2x0.cpp,v 1.2 2008/04/28 20:23:20 martin Exp $	*/
2 
3 /*-
4  * Copyright (c) 2008 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by UCHIYAMA Yasushi.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <arm/arm_arch.h>
33 #include <console.h>
34 #include <memory.h>
35 #include <arm/arm_pxa2x0.h>
36 
37 /*
38  * Intel XScale PXA 2x0
39  */
40 
41 #define	PAGE_SIZE		0x1000
42 #define	DRAM_BANK_NUM		4		/* total 256MByte */
43 #define	DRAM_BANK_SIZE		0x04000000	/* 64Mbyte */
44 
45 #define	DRAM_BANK0_START	0xa0000000
46 #define	DRAM_BANK0_SIZE		DRAM_BANK_SIZE
47 #define	DRAM_BANK1_START	0xa4000000
48 #define	DRAM_BANK1_SIZE		DRAM_BANK_SIZE
49 #define	DRAM_BANK2_START	0xa8000000
50 #define	DRAM_BANK2_SIZE		DRAM_BANK_SIZE
51 #define	DRAM_BANK3_START	0xac000000
52 #define	DRAM_BANK3_SIZE		DRAM_BANK_SIZE
53 #define	ZERO_BANK_START		0xe0000000
54 #define	ZERO_BANK_SIZE		DRAM_BANK_SIZE
55 
56 __BEGIN_DECLS
57 
58 // 2nd bootloader
59 void boot_func(kaddr_t, kaddr_t, kaddr_t, kaddr_t);
60 extern char boot_func_end[];
61 #define	BOOT_FUNC_START		reinterpret_cast <vaddr_t>(boot_func)
62 #define	BOOT_FUNC_END		reinterpret_cast <vaddr_t>(boot_func_end)
63 
64 /* jump to 2nd loader */
65 void FlatJump(kaddr_t, kaddr_t, kaddr_t, kaddr_t);
66 
67 __END_DECLS
68 
69 PXA2X0Architecture::PXA2X0Architecture(Console *&cons, MemoryManager *&mem)
70 	: ARMArchitecture(cons, mem)
71 {
72 	DPRINTF((TEXT("PXA-2x0 CPU.\n")));
73 }
74 
75 PXA2X0Architecture::~PXA2X0Architecture(void)
76 {
77 }
78 
79 BOOL
80 PXA2X0Architecture::init(void)
81 {
82 	if (!_mem->init()) {
83 		DPRINTF((TEXT("can't initialize memory manager.\n")));
84 		return FALSE;
85 	}
86 	// set D-RAM information
87 	_mem->loadBank(DRAM_BANK0_START, DRAM_BANK_SIZE);
88 	_mem->loadBank(DRAM_BANK1_START, DRAM_BANK_SIZE);
89 	_mem->loadBank(DRAM_BANK2_START, DRAM_BANK_SIZE);
90 	_mem->loadBank(DRAM_BANK3_START, DRAM_BANK_SIZE);
91 
92 #ifdef HW_TEST
93 	DPRINTF((TEXT("Testing framebuffer.\n")));
94 	testFramebuffer();
95 
96 	DPRINTF((TEXT("Testing UART.\n")));
97 	testUART();
98 #endif
99 
100 	return TRUE;
101 }
102 
103 void
104 PXA2X0Architecture::testFramebuffer(void)
105 {
106 	DPRINTF((TEXT("No framebuffer test yet.\n")));
107 }
108 
109 void
110 PXA2X0Architecture::testUART(void)
111 {
112 #define	COM_DATA		VOLATILE_REF8(uart + 0x00)
113 #define COM_IIR			VOLATILE_REF8(uart + 0x08)
114 #define	COM_LSR			VOLATILE_REF8(uart + 0x14)
115 #define LSR_TXRDY		0x20
116 #define	COM_TX_CHECK		while (!(COM_LSR & LSR_TXRDY))
117 #define	COM_PUTCHAR(c)		(COM_DATA = (c))
118 #define	COM_CLR_INTS		((void)COM_IIR)
119 #define	_(c)								\
120 __BEGIN_MACRO								\
121 	COM_TX_CHECK;							\
122 	COM_PUTCHAR(c);							\
123 	COM_TX_CHECK;							\
124 	COM_CLR_INTS;							\
125 __END_MACRO
126 
127 	vaddr_t uart =
128 	    _mem->mapPhysicalPage(0x40100000, 0x100, PAGE_READWRITE);
129 
130 	// Don't turn on the enable-UART bit in the IER; this seems to
131 	// result in WinCE losing the port (and nothing working later).
132 	// All that should be taken care of by using WinCE to open the
133 	// port before we actually use it.
134 
135 	_('H');_('e');_('l');_('l');_('o');_(' ');
136 	_('W');_('o');_('r');_('l');_('d');_('\r');_('\n');
137 
138 	_mem->unmapPhysicalPage(uart);
139 }
140 
141 BOOL
142 PXA2X0Architecture::setupLoader(void)
143 {
144 	vaddr_t v;
145 	vsize_t sz = BOOT_FUNC_END - BOOT_FUNC_START;
146 
147 	// check 2nd bootloader size.
148 	if (sz > _mem->getPageSize()) {
149 		DPRINTF((TEXT("2nd bootloader size(%dbyte) is larger than page size(%d).\n"),
150 		    sz, _mem->getPageSize()));
151 		return FALSE;
152 	}
153 
154 	// get physical mapped page and copy loader to there.
155 	// don't writeback D-cache here. make sure to writeback before jump.
156 	if (!_mem->getPage(v , _loader_addr)) {
157 		DPRINTF((TEXT("can't get page for 2nd loader.\n")));
158 		return FALSE;
159 	}
160 	DPRINTF((TEXT("2nd bootloader vaddr=0x%08x paddr=0x%08x\n"),
161 	    (unsigned)v,(unsigned)_loader_addr));
162 
163 	memcpy(reinterpret_cast <LPVOID>(v),
164 	    reinterpret_cast <LPVOID>(BOOT_FUNC_START), sz);
165 	DPRINTF((TEXT("2nd bootloader copy done.\n")));
166 
167 	return TRUE;
168 }
169 
170 void
171 PXA2X0Architecture::jump(paddr_t info, paddr_t pvec)
172 {
173 	kaddr_t sp;
174 	vaddr_t v;
175 	paddr_t p;
176 
177 	// stack for bootloader
178 	_mem->getPage(v, p);
179 	sp = ptokv(p) + _mem->getPageSize();
180 	DPRINTF((TEXT("sp for bootloader = %08x + %08x = %08x\n"),
181 	    ptokv(p), _mem->getPageSize(), sp));
182 
183 	// writeback whole D-cache
184 	WritebackDCache();
185 
186 	SetKMode(1);
187 	FlatJump(info, pvec, sp, _loader_addr);
188 	// NOTREACHED
189 }
190