2 * Copyright (c) 2006 Wojciech A. Koszek <wkoszek@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
35 #include <sys/kernel.h>
36 #include <sys/systm.h>
37 #include <sys/imgact.h>
44 #include <sys/ucontext.h>
47 #include <sys/ptrace.h>
48 #include <sys/reboot.h>
49 #include <sys/signalvar.h>
50 #include <sys/sysent.h>
51 #include <sys/sysproto.h>
55 #include <vm/vm_object.h>
56 #include <vm/vm_page.h>
57 #include <vm/vm_pager.h>
59 #include <machine/clock.h>
60 #include <machine/cpu.h>
61 #include <machine/cpuregs.h>
62 #include <machine/hwfunc.h>
63 #include <machine/md_var.h>
64 #include <machine/pmap.h>
65 #include <machine/trap.h>
67 #ifdef TICK_USE_YAMON_FREQ
68 #include <mips/malta/yamon.h>
71 #ifdef TICK_USE_MALTA_RTC
72 #include <mips/mips4k/malta/maltareg.h>
73 #include <dev/mc146818/mc146818reg.h>
77 #include <mips/malta/maltareg.h>
83 void lcd_puts(char *);
84 void malta_reset(void);
87 * Offsets to MALTA LCD characters.
89 static int malta_lcd_offs[] = {
103 /* Nothing special */
107 * Put character to Malta LCD at given position.
110 malta_lcd_putc(int pos, char c)
115 if (pos < 0 || pos > 7)
117 addr = (void *)(MALTA_ASCII_BASE + malta_lcd_offs[pos]);
118 ch = (char *)MIPS_PHYS_TO_KSEG0(addr);
123 * Print given string on LCD.
126 malta_lcd_print(char *str)
133 for (i = 0; *str != '\0'; i++, str++)
134 malta_lcd_putc(i, *str);
140 malta_lcd_print("FreeBSD_");
149 #ifdef TICK_USE_MALTA_RTC
150 static __inline uint8_t
154 *((volatile uint8_t *)
155 MIPS_PHYS_TO_KSEG1(MALTA_PCI0_ADDR(MALTA_RTCADR))) = addr;
156 return (*((volatile uint8_t *)
157 MIPS_PHYS_TO_KSEG1(MALTA_PCI0_ADDR(MALTA_RTCDAT))));
161 writertc(uint8_t addr, uint8_t val)
164 *((volatile uint8_t *)
165 MIPS_PHYS_TO_KSEG1(MALTA_PCI0_ADDR(MALTA_RTCADR))) = addr;
166 *((volatile uint8_t *)
167 MIPS_PHYS_TO_KSEG1(MALTA_PCI0_ADDR(MALTA_RTCDAT))) = val;
176 for (i = 0; i < 10; i++) {
180 /* phys_avail regions are in bytes */
181 phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
182 phys_avail[1] = ctob(realmem);
187 init_param2(physmem);
194 if (boothowto & RB_KDB)
195 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
207 platform_identify(void)
213 * Perform a board-level soft-reset.
214 * Note that this is not emulated by gxemul.
221 c = (char *)MIPS_PHYS_TO_KSEG0(MALTA_SOFTRES);
226 platform_trap_enter(void)
232 platform_trap_exit(void)
240 uint64_t platform_counter_freq = 0;
242 #if defined(TICK_USE_YAMON_FREQ)
244 * If we are running on a board which uses YAMON firmware,
245 * then query CPU pipeline clock from the syscon object.
246 * If unsuccessful, use hard-coded default.
248 platform_counter_freq = yamon_getcpufreq();
250 #elif defined(TICK_USE_MALTA_RTC)
252 * If we are running on a board with the MC146818 RTC,
253 * use it to determine CPU pipeline clock frequency.
255 u_int64_t counterval[2];
257 /* Set RTC to binary mode. */
258 writertc(RTC_STATUSB, (rtcin(RTC_STATUSB) | RTCSB_BCD));
260 /* Busy-wait for falling edge of RTC update. */
261 while (((rtcin(RTC_STATUSA) & RTCSA_TUP) == 0))
263 while (((rtcin(RTC_STATUSA)& RTCSA_TUP) != 0))
265 counterval[0] = mips_rd_count();
267 /* Busy-wait for falling edge of RTC update. */
268 while (((rtcin(RTC_STATUSA) & RTCSA_TUP) == 0))
270 while (((rtcin(RTC_STATUSA)& RTCSA_TUP) != 0))
272 counterval[1] = mips_rd_count();
274 platform_counter_freq = counterval[1] - counterval[0];
277 if (platform_counter_freq == 0)
278 platform_counter_freq = MIPS_DEFAULT_HZ;
280 return (platform_counter_freq);
284 platform_start(__register_t a0, __register_t a1, __register_t a2,
288 uint64_t platform_counter_freq;
290 char **argv = (char **)a1;
291 char **envp = (char **)a2;
292 unsigned int memsize = a3;
295 /* clear the BSS and SBSS segments */
296 kernend = (vm_offset_t)&end;
297 memset(&edata, 0, kernend - (vm_offset_t)(&edata));
299 mips_postboot_fixup();
302 platform_counter_freq = malta_cpu_freq();
303 mips_timer_early_init(platform_counter_freq);
306 printf("entry: platform_start()\n");
310 printf("cmd line: ");
311 for (i = 0; i < argc; i++)
312 printf("%s ", argv[i]);
316 for (i = 0; envp[i]; i += 2)
317 printf("\t%s = %s\n", envp[i], envp[i+1]);
319 printf("memsize = %08x\n", memsize);
322 realmem = btoc(memsize);
325 mips_timer_init_params(platform_counter_freq, 0);