2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2007 Bruce M. Simpson.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
35 #include <sys/param.h>
37 #include <sys/kernel.h>
38 #include <sys/systm.h>
39 #include <sys/imgact.h>
46 #include <sys/ucontext.h>
49 #include <sys/ptrace.h>
50 #include <sys/reboot.h>
51 #include <sys/signalvar.h>
52 #include <sys/sysent.h>
53 #include <sys/sysproto.h>
55 #include <sys/timetc.h>
58 #include <vm/vm_object.h>
59 #include <vm/vm_page.h>
61 #include <machine/cache.h>
62 #include <machine/clock.h>
63 #include <machine/cpu.h>
64 #include <machine/cpuinfo.h>
65 #include <machine/cpufunc.h>
66 #include <machine/cpuregs.h>
67 #include <machine/hwfunc.h>
68 #include <machine/intr_machdep.h>
69 #include <machine/locore.h>
70 #include <machine/md_var.h>
71 #include <machine/pte.h>
72 #include <machine/sigframe.h>
73 #include <machine/trap.h>
74 #include <machine/vmparam.h>
78 #include <machine/smp.h>
82 #include <dev/cfe/cfe_api.h>
89 #error KDB must be enabled in order for DDB to work!
94 extern void cfe_env_init(void);
100 extern char MipsTLBMiss[], MipsTLBMissEnd[];
105 /* Nothing special */
109 sb_intr_init(int cpuid)
114 * Disable all sources to the interrupt mapper and setup the mapping
115 * between an interrupt source and the mips hard interrupt number.
117 for (intsrc = 0; intsrc < NUM_INTSRC; ++intsrc) {
118 intrnum = sb_route_intsrc(intsrc);
119 sb_disable_intsrc(cpuid, intsrc);
120 sb_write_intmap(cpuid, intsrc, intrnum);
123 * Set up the mailbox interrupt mapping.
125 * The mailbox interrupt is "special" in that it is not shared
126 * with any other interrupt source.
128 if (intsrc == INTSRC_MAILBOX3) {
129 intrnum = platform_ipi_hardintr_num();
130 sb_write_intmap(cpuid, INTSRC_MAILBOX3, intrnum);
131 sb_enable_intsrc(cpuid, INTSRC_MAILBOX3);
140 int i, j, cfe_mem_idx, tmp;
147 TUNABLE_INT_FETCH("boothowto", &boothowto);
149 if (boothowto & RB_VERBOSE)
157 TUNABLE_INT_FETCH("hw.physmem", &tmp);
158 maxmem = (uint64_t)tmp * 1024;
162 * If we used vm_paddr_t consistently in pmap, etc., we could
163 * use 64-bit page numbers on !n64 systems, too, like i386
166 #if !defined(__mips_n64)
167 if (maxmem == 0 || maxmem > 0xffffffff)
173 * Query DRAM memory map from CFE.
177 for (i = 0; i < 10; i += 2) {
179 uint64_t addr, len, type;
181 result = cfe_enummem(cfe_mem_idx++, 0, &addr, &len, &type);
183 phys_avail[i] = phys_avail[i + 1] = 0;
187 KASSERT(type == CFE_MI_AVAILABLE,
188 ("CFE DRAM region is not available?"));
191 printf("cfe_enummem: 0x%016jx/%ju.\n", addr, len);
194 if (addr >= maxmem) {
195 printf("Ignoring %ju bytes of memory at 0x%jx "
196 "that is above maxmem %dMB\n",
198 (int)(maxmem / (1024 * 1024)));
202 if (addr + len > maxmem) {
203 printf("Ignoring %ju bytes of memory "
204 "that is above maxmem %dMB\n",
205 (addr + len) - maxmem,
206 (int)(maxmem / (1024 * 1024)));
211 phys_avail[i] = addr;
212 if (i == 0 && addr == 0) {
214 * If this is the first physical memory segment probed
215 * from CFE, omit the region at the start of physical
216 * memory where the kernel has been loaded.
218 phys_avail[i] += MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
220 phys_avail[i + 1] = addr + len;
224 realmem = btoc(physmem);
227 for (j = 0; j < i; j++)
228 dump_avail[j] = phys_avail[j];
233 init_param2(physmem);
237 * Sibyte has a L1 data cache coherent with DMA. This includes
238 * on-chip network interfaces as well as PCI/HyperTransport bus
241 cpuinfo.cache_coherent_dma = TRUE;
245 * The kernel is running in 32-bit mode but the CFE is running in
246 * 64-bit mode. So the SR_KX bit in the status register is turned
247 * on by the CFE every time we call into it - for e.g. CFE_CONSOLE.
249 * This means that if get a TLB miss for any address above 0xc0000000
250 * and the SR_KX bit is set then we will end up in the XTLB exception
253 * For now work around this by copying the TLB exception handling
254 * code to the XTLB exception vector.
257 bcopy(MipsTLBMiss, (void *)MIPS_XTLB_MISS_EXC_VEC,
258 MipsTLBMissEnd - MipsTLBMiss);
260 mips_icache_sync_all();
261 mips_dcache_wbinv_all();
270 if (boothowto & RB_KDB)
271 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
281 * XXX flush data caches
287 kseg0_map_coherent(void)
290 const int CFG_K0_COHERENT = 5;
292 config = mips_rd_config();
293 config &= ~MIPS_CONFIG_K0_MASK;
294 config |= CFG_K0_COHERENT;
295 mips_wr_config(config);
300 platform_ipi_send(int cpuid)
302 KASSERT(cpuid == 0 || cpuid == 1,
303 ("platform_ipi_send: invalid cpuid %d", cpuid));
305 sb_set_mailbox(cpuid, 1ULL);
309 platform_ipi_clear(void)
313 cpuid = PCPU_GET(cpuid);
314 sb_clear_mailbox(cpuid, 1ULL);
318 platform_ipi_hardintr_num(void)
325 platform_ipi_softintr_num(void)
332 platform_smp_topo(void)
335 return (smp_topo_none());
339 platform_init_ap(int cpuid)
341 int ipi_int_mask, clock_int_mask;
343 KASSERT(cpuid == 1, ("AP has an invalid cpu id %d", cpuid));
346 * Make sure that kseg0 is mapped cacheable-coherent
348 kseg0_map_coherent();
353 * Unmask the clock and ipi interrupts.
355 clock_int_mask = hard_int_mask(5);
356 ipi_int_mask = hard_int_mask(platform_ipi_hardintr_num());
357 set_intr_mask(ipi_int_mask | clock_int_mask);
361 platform_start_ap(int cpuid)
366 if ((error = cfe_cpu_start(cpuid, mpentry, 0, 0, 0))) {
367 printf("cfe_cpu_start error: %d\n", error);
379 sb_get_timecount(struct timecounter *tc)
382 return ((u_int)sb_zbbus_cycle_count());
386 sb_timecounter_init(void)
388 static struct timecounter sb_timecounter = {
393 "sibyte_zbbus_counter",
398 * The ZBbus cycle counter runs at half the cpu frequency.
400 sb_timecounter.tc_frequency = sb_cpu_speed() / 2;
401 platform_timecounter = &sb_timecounter;
405 platform_start(__register_t a0, __register_t a1, __register_t a2,
409 * Make sure that kseg0 is mapped cacheable-coherent
411 kseg0_map_coherent();
413 /* clear the BSS and SBSS segments */
414 memset(&edata, 0, (vm_offset_t)&end - (vm_offset_t)&edata);
415 mips_postboot_fixup();
418 sb_timecounter_init();
420 /* Initialize pcpu stuff */
425 * Initialize CFE firmware trampolines before
426 * we initialize the low-level console.
428 * CFE passes the following values in registers:
429 * a0: firmware handle
430 * a2: firmware entry point
431 * a3: entry point seal
433 if (a3 == CFE_EPTSEAL)
440 mips_timer_init_params(sb_cpu_speed(), 0);