2 * Copyright (c) 2007 Bruce M. Simpson.
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
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
34 #include <sys/kernel.h>
35 #include <sys/systm.h>
36 #include <sys/imgact.h>
43 #include <sys/ucontext.h>
46 #include <sys/ptrace.h>
47 #include <sys/reboot.h>
48 #include <sys/signalvar.h>
49 #include <sys/sysent.h>
50 #include <sys/sysproto.h>
54 #include <vm/vm_object.h>
55 #include <vm/vm_page.h>
57 #include <machine/cache.h>
58 #include <machine/clock.h>
59 #include <machine/cpu.h>
60 #include <machine/cpuinfo.h>
61 #include <machine/cpufunc.h>
62 #include <machine/cpuregs.h>
63 #include <machine/hwfunc.h>
64 #include <machine/intr_machdep.h>
65 #include <machine/locore.h>
66 #include <machine/md_var.h>
67 #include <machine/pte.h>
68 #include <machine/sigframe.h>
69 #include <machine/trap.h>
70 #include <machine/vmparam.h>
72 #include <mips/sentry5/s5reg.h>
75 #include <dev/cfe/cfe_api.h>
92 printf("entry: mips_init()\n");
96 * Query DRAM memory map from CFE.
99 for (i = 0; i < 10; i += 2) {
101 uint64_t addr, len, type;
103 result = cfe_enummem(i, 0, &addr, &len, &type);
105 phys_avail[i] = phys_avail[i + 1] = 0;
108 if (type != CFE_MI_AVAILABLE)
111 phys_avail[i] = addr;
112 if (i == 0 && addr == 0) {
114 * If this is the first physical memory segment probed
115 * from CFE, omit the region at the start of physical
116 * memory where the kernel has been loaded.
118 phys_avail[i] += MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
120 phys_avail[i + 1] = addr + len;
124 realmem = btoc(physmem);
127 for (j = 0; j < i; j++)
128 dump_avail[j] = phys_avail[j];
133 init_param2(physmem);
140 if (boothowto & RB_KDB)
141 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
152 *((volatile uint8_t *)MIPS_PHYS_TO_KSEG1(SENTRY5_EXTIFADR)) = 0x80;
157 platform_start(__register_t a0, __register_t a1, __register_t a2,
161 uint64_t platform_counter_freq;
163 /* clear the BSS and SBSS segments */
164 kernend = (vm_offset_t)&end;
165 memset(&edata, 0, kernend - (vm_offset_t)(&edata));
167 mips_postboot_fixup();
169 /* Initialize pcpu stuff */
174 * Initialize CFE firmware trampolines before
175 * we initialize the low-level console.
177 * CFE passes the following values in registers:
178 * a0: firmware handle
179 * a2: firmware entry point
180 * a3: entry point seal
182 if (a3 == CFE_EPTSEAL)
191 * Probe the Broadcom Sentry5's on-chip PLL clock registers
192 * and discover the CPU pipeline clock and bus clock
193 * multipliers from this.
194 * XXX: Wrong place. You have to ask the ChipCommon
195 * or External Interface cores on the SiBa.
197 uint32_t busmult, cpumult, refclock, clkcfg1;
198 #define S5_CLKCFG1_REFCLOCK_MASK 0x0000001F
199 #define S5_CLKCFG1_BUSMULT_MASK 0x000003E0
200 #define S5_CLKCFG1_BUSMULT_SHIFT 5
201 #define S5_CLKCFG1_CPUMULT_MASK 0xFFFFFC00
202 #define S5_CLKCFG1_CPUMULT_SHIFT 10
204 counter_freq = 100000000; /* XXX */
206 clkcfg1 = s5_rd_clkcfg1();
207 printf("clkcfg1 = 0x%08x\n", clkcfg1);
209 refclock = clkcfg1 & 0x1F;
210 busmult = ((clkcfg1 & 0x000003E0) >> 5) + 1;
211 cpumult = ((clkcfg1 & 0xFFFFFC00) >> 10) + 1;
213 printf("refclock = %u\n", refclock);
214 printf("busmult = %u\n", busmult);
215 printf("cpumult = %u\n", cpumult);
217 counter_freq = cpumult * refclock;
219 platform_counter_freq = 200 * 1000 * 1000; /* Sentry5 is 200MHz */
222 mips_timer_init_params(platform_counter_freq, 0);