No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / hpc / stand / hpcboot / arm / arm_sa1100.cpp
bloba3d2750452b3544c15dc0559e1add4696a6784a3
1 /* $NetBSD: arm_sa1100.cpp,v 1.1 2008/03/08 02:26:03 rafal Exp $ */
3 /*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
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.
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.
32 #include <arm/arm_arch.h>
33 #include <console.h>
34 #include <memory.h>
35 #include <arm/arm_sa1100.h>
38 * Strong-ARM SA-1100 (e.g. HP-820 JORNADA)
41 #define PAGE_SIZE 0x1000
42 #define DRAM_BANK_NUM 4 /* total 512MByte */
43 #define DRAM_BANK_SIZE 0x08000000 /* 128Mbyte */
45 #define DRAM_BANK0_START 0xc0000000
46 #define DRAM_BANK0_SIZE DRAM_BANK_SIZE
47 #define DRAM_BANK1_START 0xc8000000
48 #define DRAM_BANK1_SIZE DRAM_BANK_SIZE
49 #define DRAM_BANK2_START 0xd0000000
50 #define DRAM_BANK2_SIZE DRAM_BANK_SIZE
51 #define DRAM_BANK3_START 0xd8000000
52 #define DRAM_BANK3_SIZE DRAM_BANK_SIZE
53 #define ZERO_BANK_START 0xe0000000
54 #define ZERO_BANK_SIZE DRAM_BANK_SIZE
56 __BEGIN_DECLS
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)
64 /* jump to 2nd loader */
65 void FlatJump(kaddr_t, kaddr_t, kaddr_t, kaddr_t);
67 __END_DECLS
69 SA1100Architecture::SA1100Architecture(Console *&cons, MemoryManager *&mem)
70 : ARMArchitecture(cons, mem)
72 DPRINTF((TEXT("SA-11x0 CPU.\n")));
75 SA1100Architecture::~SA1100Architecture(void)
79 BOOL
80 SA1100Architecture::init(void)
82 if (!_mem->init()) {
83 DPRINTF((TEXT("can't initialize memory manager.\n")));
84 return FALSE;
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);
92 return TRUE;
95 void
96 SA1100Architecture::testFramebuffer(void)
98 // get frame buffer address from LCD controller register.
99 paddr_t fbaddr_p = _mem->readPhysical4(0xb0100010); // 0xc0002e00
100 // map frame buffer
101 vaddr_t fbaddr_v = _mem->mapPhysicalPage(fbaddr_p, 0x50000,
102 PAGE_READWRITE);
104 // test frame buffer
105 int j, k;
106 DI();
107 for (j = 0; j < 480; j++)
108 for (k = 0; k < 640; k++)
109 VOLATILE_REF8(fbaddr_v + 0x200 + j * 640 + k)
110 = j * k & 0xff;
111 for (j = 120; j < 360; j++)
112 for (k = 120; k < 520; k++)
113 VOLATILE_REF8(fbaddr_v + 0x200 + j * 640 + k) = 0x3;
114 EI();
115 _mem->unmapPhysicalPage(fbaddr_v);
118 void
119 SA1100Architecture::testUART(void)
121 #define TBY VOLATILE_REF(uart + 0x20)
122 #define UTDR VOLATILE_REF(uart + 0x14)
123 #define TBY_BUSY while (TBY & 0x1)
124 #define UTDR_PUTCHAR(c) (UTDR =(c))
125 #define _(c) \
126 __BEGIN_MACRO \
127 TBY_BUSY; \
128 UTDR_PUTCHAR(c); \
129 __END_MACRO
130 vaddr_t uart =
131 _mem->mapPhysicalPage(0x80050000, 0x100, PAGE_READWRITE);
132 _('H');_('e');_('l');_('l');_('o');_(' ');
133 _('W');_('o');_('r');_('l');_('d');_('\r');_('\n');
134 _mem->unmapPhysicalPage(uart);
137 BOOL
138 SA1100Architecture::setupLoader(void)
140 vaddr_t v;
141 vsize_t sz = BOOT_FUNC_END - BOOT_FUNC_START;
143 // check 2nd bootloader size.
144 if (sz > _mem->getPageSize()) {
145 DPRINTF((TEXT("2nd bootloader size(%dbyte) is larger than page size(%d).\n"),
146 sz, _mem->getPageSize()));
147 return FALSE;
150 // get physical mapped page and copy loader to there.
151 // don't writeback D-cache here. make sure to writeback before jump.
152 if (!_mem->getPage(v , _loader_addr)) {
153 DPRINTF((TEXT("can't get page for 2nd loader.\n")));
154 return FALSE;
156 DPRINTF((TEXT("2nd bootloader vaddr=0x%08x paddr=0x%08x\n"),
157 (unsigned)v,(unsigned)_loader_addr));
159 memcpy(reinterpret_cast <LPVOID>(v),
160 reinterpret_cast <LPVOID>(BOOT_FUNC_START), sz);
161 DPRINTF((TEXT("2nd bootloader copy done.\n")));
163 return TRUE;
166 void
167 SA1100Architecture::jump(paddr_t info, paddr_t pvec)
169 kaddr_t sp;
170 vaddr_t v;
171 paddr_t p;
173 // stack for bootloader
174 _mem->getPage(v, p);
175 sp = ptokv(p) + _mem->getPageSize();
176 DPRINTF((TEXT("sp for bootloader = %08x + %08x = %08x\n"),
177 ptokv(p), _mem->getPageSize(), sp));
179 // writeback whole D-cache
180 WritebackDCache();
182 SetKMode(1);
183 FlatJump(info, pvec, sp, _loader_addr);
184 // NOTREACHED