sb_machdep.c revision 195333
1195333Simp/*-
2195333Simp * Copyright (c) 2007 Bruce M. Simpson.
3195333Simp * All rights reserved.
4195333Simp *
5195333Simp * Redistribution and use in source and binary forms, with or without
6195333Simp * modification, are permitted provided that the following conditions
7195333Simp * are met:
8195333Simp * 1. Redistributions of source code must retain the above copyright
9195333Simp *    notice, this list of conditions and the following disclaimer.
10195333Simp * 2. Redistributions in binary form must reproduce the above copyright
11195333Simp *    notice, this list of conditions and the following disclaimer in the
12195333Simp *    documentation and/or other materials provided with the distribution.
13195333Simp *
14195333Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15195333Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16195333Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17195333Simp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18195333Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19195333Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20195333Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21195333Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22195333Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23195333Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24195333Simp * SUCH DAMAGE.
25195333Simp */
26195333Simp
27195333Simp#include <sys/cdefs.h>
28195333Simp__FBSDID("$FreeBSD: projects/mips/sys/mips/sibyte/sb_machdep.c 195333 2009-07-04 03:05:48Z imp $");
29195333Simp
30195333Simp#include <sys/param.h>
31195333Simp#include <machine/cpuregs.h>
32195333Simp
33195333Simp#include "opt_ddb.h"
34195333Simp#include "opt_kdb.h"
35195333Simp
36195333Simp#include <sys/param.h>
37195333Simp#include <sys/conf.h>
38195333Simp#include <sys/kernel.h>
39195333Simp#include <sys/systm.h>
40195333Simp#include <sys/imgact.h>
41195333Simp#include <sys/bio.h>
42195333Simp#include <sys/buf.h>
43195333Simp#include <sys/bus.h>
44195333Simp#include <sys/cpu.h>
45195333Simp#include <sys/cons.h>
46195333Simp#include <sys/exec.h>
47195333Simp#include <sys/ucontext.h>
48195333Simp#include <sys/proc.h>
49195333Simp#include <sys/kdb.h>
50195333Simp#include <sys/ptrace.h>
51195333Simp#include <sys/reboot.h>
52195333Simp#include <sys/signalvar.h>
53195333Simp#include <sys/sysent.h>
54195333Simp#include <sys/sysproto.h>
55195333Simp#include <sys/user.h>
56195333Simp
57195333Simp#include <vm/vm.h>
58195333Simp#include <vm/vm_object.h>
59195333Simp#include <vm/vm_page.h>
60195333Simp#include <vm/vm_pager.h>
61195333Simp
62195333Simp#include <machine/cache.h>
63195333Simp#include <machine/clock.h>
64195333Simp#include <machine/cpu.h>
65195333Simp#include <machine/cpuinfo.h>
66195333Simp#include <machine/cpufunc.h>
67195333Simp#include <machine/cpuregs.h>
68195333Simp#include <machine/hwfunc.h>
69195333Simp#include <machine/intr_machdep.h>
70195333Simp#include <machine/locore.h>
71195333Simp#include <machine/md_var.h>
72195333Simp#include <machine/pte.h>
73195333Simp#include <machine/sigframe.h>
74195333Simp#include <machine/trap.h>
75195333Simp#include <machine/vmparam.h>
76195333Simp
77195333Simp#ifdef CFE
78195333Simp#include <dev/cfe/cfe_api.h>
79195333Simp#endif
80195333Simp
81195333Simp#include "sb_scd.h"
82195333Simp
83195333Simp#ifdef DDB
84195333Simp#ifndef KDB
85195333Simp#error KDB must be enabled in order for DDB to work!
86195333Simp#endif
87195333Simp#endif
88195333Simp
89195333Simp#ifdef CFE
90195333Simpextern uint32_t cfe_handle;
91195333Simpextern uint32_t cfe_vector;
92195333Simp#endif
93195333Simp
94195333Simp#ifdef CFE_ENV
95195333Simpextern void cfe_env_init(void);
96195333Simp#endif
97195333Simp
98195333Simpextern int *edata;
99195333Simpextern int *end;
100195333Simp
101195333Simpstatic void
102195333Simpmips_init(void)
103195333Simp{
104195333Simp	int i, cfe_mem_idx, tmp;
105195333Simp	uint64_t maxmem;
106195333Simp
107195333Simp#ifdef CFE_ENV
108195333Simp	cfe_env_init();
109195333Simp#endif
110195333Simp
111195333Simp	TUNABLE_INT_FETCH("boothowto", &boothowto);
112195333Simp
113195333Simp	if (boothowto & RB_VERBOSE)
114195333Simp		bootverbose++;
115195333Simp
116195333Simp#ifdef MAXMEM
117195333Simp	tmp = MAXMEM;
118195333Simp#else
119195333Simp	tmp = 0;
120195333Simp#endif
121195333Simp	TUNABLE_INT_FETCH("hw.physmem", &tmp);
122195333Simp	maxmem = (uint64_t)tmp * 1024;
123195333Simp
124195333Simp#ifdef CFE
125195333Simp	/*
126195333Simp	 * Query DRAM memory map from CFE.
127195333Simp	 */
128195333Simp	physmem = 0;
129195333Simp	cfe_mem_idx = 0;
130195333Simp	for (i = 0; i < 10; i += 2) {
131195333Simp		int result;
132195333Simp		uint64_t addr, len, type;
133195333Simp
134195333Simp		result = cfe_enummem(cfe_mem_idx++, 0, &addr, &len, &type);
135195333Simp		if (result < 0) {
136195333Simp			phys_avail[i] = phys_avail[i + 1] = 0;
137195333Simp			break;
138195333Simp		}
139195333Simp
140195333Simp		KASSERT(type == CFE_MI_AVAILABLE,
141195333Simp			("CFE DRAM region is not available?"));
142195333Simp
143195333Simp		if (bootverbose)
144195333Simp			printf("cfe_enummem: 0x%016jx/%llu.\n", addr, len);
145195333Simp
146195333Simp		if (maxmem != 0) {
147195333Simp			if (addr >= maxmem) {
148195333Simp				printf("Ignoring %llu bytes of memory at 0x%jx "
149195333Simp				       "that is above maxmem %dMB\n",
150195333Simp				       len, addr,
151195333Simp				       (int)(maxmem / (1024 * 1024)));
152195333Simp				continue;
153195333Simp			}
154195333Simp
155195333Simp			if (addr + len > maxmem) {
156195333Simp				printf("Ignoring %llu bytes of memory "
157195333Simp				       "that is above maxmem %dMB\n",
158195333Simp				       (addr + len) - maxmem,
159195333Simp				       (int)(maxmem / (1024 * 1024)));
160195333Simp				len = maxmem - addr;
161195333Simp			}
162195333Simp		}
163195333Simp
164195333Simp		phys_avail[i] = addr;
165195333Simp		if (i == 0 && addr == 0) {
166195333Simp			/*
167195333Simp			 * If this is the first physical memory segment probed
168195333Simp			 * from CFE, omit the region at the start of physical
169195333Simp			 * memory where the kernel has been loaded.
170195333Simp			 */
171195333Simp			phys_avail[i] += MIPS_KSEG0_TO_PHYS((vm_offset_t)&end);
172195333Simp		}
173195333Simp		phys_avail[i + 1] = addr + len;
174195333Simp		physmem += len;
175195333Simp	}
176195333Simp
177195333Simp	realmem = btoc(physmem);
178195333Simp#endif
179195333Simp
180195333Simp	physmem = realmem;
181195333Simp
182195333Simp	init_param1();
183195333Simp	init_param2(physmem);
184195333Simp	mips_cpu_init();
185195333Simp	pmap_bootstrap();
186195333Simp	mips_proc0_init();
187195333Simp	mutex_init();
188195333Simp
189195333Simp	kdb_init();
190195333Simp#ifdef KDB
191195333Simp	if (boothowto & RB_KDB)
192195333Simp		kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
193195333Simp#endif
194195333Simp}
195195333Simp
196195333Simpvoid
197195333Simpplatform_halt(void)
198195333Simp{
199195333Simp
200195333Simp}
201195333Simp
202195333Simp
203195333Simpvoid
204195333Simpplatform_identify(void)
205195333Simp{
206195333Simp
207195333Simp}
208195333Simp
209195333Simpvoid
210195333Simpplatform_reset(void)
211195333Simp{
212195333Simp
213195333Simp	/*
214195333Simp	 * XXX SMP
215195333Simp	 * XXX flush data caches
216195333Simp	 */
217195333Simp	sb_system_reset();
218195333Simp}
219195333Simp
220195333Simpvoid
221195333Simpplatform_trap_enter(void)
222195333Simp{
223195333Simp
224195333Simp}
225195333Simp
226195333Simpvoid
227195333Simpplatform_trap_exit(void)
228195333Simp{
229195333Simp
230195333Simp}
231195333Simp
232195333Simpvoid
233195333Simpplatform_start(__register_t a0 __unused, __register_t a1 __unused,
234195333Simp    __register_t a2 __unused, __register_t a3 __unused)
235195333Simp{
236195333Simp	vm_offset_t kernend;
237195333Simp
238195333Simp	/* clear the BSS and SBSS segments */
239195333Simp	memset(&edata, 0, (vm_offset_t)&end - (vm_offset_t)&edata);
240195333Simp	kernend = round_page((vm_offset_t)&end);
241195333Simp
242195333Simp#ifdef CFE
243195333Simp	/*
244195333Simp	 * Initialize CFE firmware trampolines before
245195333Simp	 * we initialize the low-level console.
246195333Simp	 */
247195333Simp	if (cfe_handle != 0)
248195333Simp		cfe_init(cfe_handle, cfe_vector);
249195333Simp#endif
250195333Simp	cninit();
251195333Simp
252195333Simp#ifdef CFE
253195333Simp	if (cfe_handle == 0)
254195333Simp		panic("CFE was not detected by locore.\n");
255195333Simp#endif
256195333Simp	mips_init();
257195333Simp
258195333Simp	mips_timer_init_params(sb_cpu_speed(), 0);
259195333Simp}
260