sb_machdep.c revision 198669
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 198669 2009-10-30 08:53:11Z rrs $");
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
101198669Srrsvoid
102198669Srrsplatform_cpu_init()
103198669Srrs{
104198669Srrs	/* Nothing special */
105198669Srrs}
106198669Srrs
107195333Simpstatic void
108195333Simpmips_init(void)
109195333Simp{
110195333Simp	int i, cfe_mem_idx, tmp;
111195333Simp	uint64_t maxmem;
112195333Simp
113195333Simp#ifdef CFE_ENV
114195333Simp	cfe_env_init();
115195333Simp#endif
116195333Simp
117195333Simp	TUNABLE_INT_FETCH("boothowto", &boothowto);
118195333Simp
119195333Simp	if (boothowto & RB_VERBOSE)
120195333Simp		bootverbose++;
121195333Simp
122195333Simp#ifdef MAXMEM
123195333Simp	tmp = MAXMEM;
124195333Simp#else
125195333Simp	tmp = 0;
126195333Simp#endif
127195333Simp	TUNABLE_INT_FETCH("hw.physmem", &tmp);
128195333Simp	maxmem = (uint64_t)tmp * 1024;
129195333Simp
130195333Simp#ifdef CFE
131195333Simp	/*
132195333Simp	 * Query DRAM memory map from CFE.
133195333Simp	 */
134195333Simp	physmem = 0;
135195333Simp	cfe_mem_idx = 0;
136195333Simp	for (i = 0; i < 10; i += 2) {
137195333Simp		int result;
138195333Simp		uint64_t addr, len, type;
139195333Simp
140195333Simp		result = cfe_enummem(cfe_mem_idx++, 0, &addr, &len, &type);
141195333Simp		if (result < 0) {
142195333Simp			phys_avail[i] = phys_avail[i + 1] = 0;
143195333Simp			break;
144195333Simp		}
145195333Simp
146195333Simp		KASSERT(type == CFE_MI_AVAILABLE,
147195333Simp			("CFE DRAM region is not available?"));
148195333Simp
149195333Simp		if (bootverbose)
150195333Simp			printf("cfe_enummem: 0x%016jx/%llu.\n", addr, len);
151195333Simp
152195333Simp		if (maxmem != 0) {
153195333Simp			if (addr >= maxmem) {
154195333Simp				printf("Ignoring %llu bytes of memory at 0x%jx "
155195333Simp				       "that is above maxmem %dMB\n",
156195333Simp				       len, addr,
157195333Simp				       (int)(maxmem / (1024 * 1024)));
158195333Simp				continue;
159195333Simp			}
160195333Simp
161195333Simp			if (addr + len > maxmem) {
162195333Simp				printf("Ignoring %llu bytes of memory "
163195333Simp				       "that is above maxmem %dMB\n",
164195333Simp				       (addr + len) - maxmem,
165195333Simp				       (int)(maxmem / (1024 * 1024)));
166195333Simp				len = maxmem - addr;
167195333Simp			}
168195333Simp		}
169195333Simp
170195333Simp		phys_avail[i] = addr;
171195333Simp		if (i == 0 && addr == 0) {
172195333Simp			/*
173195333Simp			 * If this is the first physical memory segment probed
174195333Simp			 * from CFE, omit the region at the start of physical
175195333Simp			 * memory where the kernel has been loaded.
176195333Simp			 */
177195333Simp			phys_avail[i] += MIPS_KSEG0_TO_PHYS((vm_offset_t)&end);
178195333Simp		}
179195333Simp		phys_avail[i + 1] = addr + len;
180195333Simp		physmem += len;
181195333Simp	}
182195333Simp
183195333Simp	realmem = btoc(physmem);
184195333Simp#endif
185195333Simp
186195333Simp	physmem = realmem;
187195333Simp
188195333Simp	init_param1();
189195333Simp	init_param2(physmem);
190195333Simp	mips_cpu_init();
191195333Simp	pmap_bootstrap();
192195333Simp	mips_proc0_init();
193195333Simp	mutex_init();
194195333Simp
195195333Simp	kdb_init();
196195333Simp#ifdef KDB
197195333Simp	if (boothowto & RB_KDB)
198195333Simp		kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
199195333Simp#endif
200195333Simp}
201195333Simp
202195333Simpvoid
203195333Simpplatform_halt(void)
204195333Simp{
205195333Simp
206195333Simp}
207195333Simp
208195333Simp
209195333Simpvoid
210195333Simpplatform_identify(void)
211195333Simp{
212195333Simp
213195333Simp}
214195333Simp
215195333Simpvoid
216195333Simpplatform_reset(void)
217195333Simp{
218195333Simp
219195333Simp	/*
220195333Simp	 * XXX SMP
221195333Simp	 * XXX flush data caches
222195333Simp	 */
223195333Simp	sb_system_reset();
224195333Simp}
225195333Simp
226195333Simpvoid
227195333Simpplatform_trap_enter(void)
228195333Simp{
229195333Simp
230195333Simp}
231195333Simp
232195333Simpvoid
233195333Simpplatform_trap_exit(void)
234195333Simp{
235195333Simp
236195333Simp}
237195333Simp
238195333Simpvoid
239195333Simpplatform_start(__register_t a0 __unused, __register_t a1 __unused,
240195333Simp    __register_t a2 __unused, __register_t a3 __unused)
241195333Simp{
242195333Simp	vm_offset_t kernend;
243195333Simp
244195333Simp	/* clear the BSS and SBSS segments */
245195333Simp	memset(&edata, 0, (vm_offset_t)&end - (vm_offset_t)&edata);
246195333Simp	kernend = round_page((vm_offset_t)&end);
247195333Simp
248195333Simp#ifdef CFE
249195333Simp	/*
250195333Simp	 * Initialize CFE firmware trampolines before
251195333Simp	 * we initialize the low-level console.
252195333Simp	 */
253195333Simp	if (cfe_handle != 0)
254195333Simp		cfe_init(cfe_handle, cfe_vector);
255195333Simp#endif
256195333Simp	cninit();
257195333Simp
258195333Simp#ifdef CFE
259195333Simp	if (cfe_handle == 0)
260195333Simp		panic("CFE was not detected by locore.\n");
261195333Simp#endif
262195333Simp	mips_init();
263195333Simp
264195333Simp	mips_timer_init_params(sb_cpu_speed(), 0);
265195333Simp}
266