beri_machdep.c revision 245329
1239671Srwatson/*-
2239671Srwatson * Copyright (c) 2006 Wojciech A. Koszek <wkoszek@FreeBSD.org>
3244899Srwatson * Copyright (c) 2012 Robert N. M. Watson
4239671Srwatson * All rights reserved.
5239671Srwatson *
6244899Srwatson * This software was developed by SRI International and the University of
7244899Srwatson * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
8244899Srwatson * ("CTSRD"), as part of the DARPA CRASH research programme.
9244899Srwatson *
10239671Srwatson * Redistribution and use in source and binary forms, with or without
11239671Srwatson * modification, are permitted provided that the following conditions
12239671Srwatson * are met:
13239671Srwatson * 1. Redistributions of source code must retain the above copyright
14239671Srwatson *    notice, this list of conditions and the following disclaimer.
15239671Srwatson * 2. Redistributions in binary form must reproduce the above copyright
16239671Srwatson *    notice, this list of conditions and the following disclaimer in the
17239671Srwatson *    documentation and/or other materials provided with the distribution.
18239671Srwatson *
19239671Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20239671Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21239671Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22239671Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23239671Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24239671Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25239671Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26239671Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27239671Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28239671Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29239671Srwatson * SUCH DAMAGE.
30239671Srwatson */
31239671Srwatson#include <sys/cdefs.h>
32239671Srwatson__FBSDID("$FreeBSD: head/sys/mips/beri/beri_machdep.c 245329 2013-01-12 12:34:59Z rwatson $");
33239671Srwatson
34239671Srwatson#include "opt_ddb.h"
35244899Srwatson#include "opt_platform.h"
36239671Srwatson
37239671Srwatson#include <sys/param.h>
38239671Srwatson#include <sys/conf.h>
39239671Srwatson#include <sys/kernel.h>
40239671Srwatson#include <sys/systm.h>
41239671Srwatson#include <sys/imgact.h>
42239671Srwatson#include <sys/bio.h>
43239671Srwatson#include <sys/buf.h>
44239671Srwatson#include <sys/bus.h>
45239671Srwatson#include <sys/cpu.h>
46239671Srwatson#include <sys/cons.h>
47239671Srwatson#include <sys/exec.h>
48239671Srwatson#include <sys/ucontext.h>
49239671Srwatson#include <sys/proc.h>
50239671Srwatson#include <sys/kdb.h>
51239671Srwatson#include <sys/ptrace.h>
52239671Srwatson#include <sys/reboot.h>
53239671Srwatson#include <sys/signalvar.h>
54239671Srwatson#include <sys/sysent.h>
55239671Srwatson#include <sys/sysproto.h>
56239671Srwatson#include <sys/user.h>
57239671Srwatson
58244942Srwatson#ifdef FDT
59244899Srwatson#include <dev/fdt/fdt_common.h>
60244899Srwatson#include <dev/ofw/openfirm.h>
61244942Srwatson#endif
62244899Srwatson
63239671Srwatson#include <vm/vm.h>
64239671Srwatson#include <vm/vm_object.h>
65239671Srwatson#include <vm/vm_page.h>
66239671Srwatson#include <vm/vm_pager.h>
67239671Srwatson
68239671Srwatson#include <machine/clock.h>
69239671Srwatson#include <machine/cpu.h>
70239671Srwatson#include <machine/cpuregs.h>
71239671Srwatson#include <machine/hwfunc.h>
72239671Srwatson#include <machine/md_var.h>
73239671Srwatson#include <machine/pmap.h>
74239671Srwatson#include <machine/trap.h>
75239671Srwatson
76239671Srwatsonextern int	*edata;
77239671Srwatsonextern int	*end;
78239671Srwatson
79239671Srwatsonvoid
80239671Srwatsonplatform_cpu_init()
81239671Srwatson{
82239671Srwatson	/* Nothing special */
83239671Srwatson}
84239671Srwatson
85239671Srwatsonstatic void
86239671Srwatsonmips_init(void)
87239671Srwatson{
88239671Srwatson	int i;
89239671Srwatson
90239671Srwatson	for (i = 0; i < 10; i++) {
91239671Srwatson		phys_avail[i] = 0;
92239671Srwatson	}
93239671Srwatson
94239671Srwatson	/* phys_avail regions are in bytes */
95239671Srwatson	phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
96239671Srwatson	phys_avail[1] = ctob(realmem);
97239671Srwatson
98239671Srwatson	dump_avail[0] = phys_avail[0];
99239671Srwatson	dump_avail[1] = phys_avail[1];
100239671Srwatson
101239671Srwatson	physmem = realmem;
102239671Srwatson
103239671Srwatson	init_param1();
104239671Srwatson	init_param2(physmem);
105239671Srwatson	mips_cpu_init();
106239671Srwatson	pmap_bootstrap();
107239671Srwatson	mips_proc0_init();
108239671Srwatson	mutex_init();
109239671Srwatson	kdb_init();
110239671Srwatson#ifdef KDB
111239671Srwatson	if (boothowto & RB_KDB)
112239671Srwatson		kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
113239671Srwatson#endif
114239671Srwatson}
115239671Srwatson
116239671Srwatson/*
117239671Srwatson * Perform a board-level soft-reset.
118239671Srwatson *
119239671Srwatson * XXXRW: BERI doesn't yet have a board-level soft-reset.
120239671Srwatson */
121239671Srwatsonvoid
122239671Srwatsonplatform_reset(void)
123239671Srwatson{
124239671Srwatson
125239671Srwatson	panic("%s: not yet", __func__);
126239671Srwatson}
127239671Srwatson
128239671Srwatsonvoid
129239671Srwatsonplatform_start(__register_t a0, __register_t a1,  __register_t a2,
130239671Srwatson    __register_t a3)
131239671Srwatson{
132239671Srwatson	vm_offset_t kernend;
133239671Srwatson	uint64_t platform_counter_freq;
134239671Srwatson	int argc = a0;
135239671Srwatson	char **argv = (char **)a1;
136239671Srwatson	char **envp = (char **)a2;
137239671Srwatson	unsigned int memsize = a3;
138239671Srwatson	int i;
139239671Srwatson
140239671Srwatson	/* clear the BSS and SBSS segments */
141239671Srwatson	kernend = (vm_offset_t)&end;
142239671Srwatson	memset(&edata, 0, kernend - (vm_offset_t)(&edata));
143239671Srwatson
144239671Srwatson	mips_postboot_fixup();
145239671Srwatson
146239671Srwatson	mips_pcpu0_init();
147239671Srwatson
148245329Srwatson#ifdef FDT
149245329Srwatson#ifndef FDT_DTB_STATIC
150245329Srwatson#error	"mips_init with FDT requires FDT_DTB_STATIC"
151245329Srwatson#endif
152245329Srwatson
153245329Srwatson	if (OF_install(OFW_FDT, 0) == FALSE)
154245329Srwatson		while (1);
155245329Srwatson	if (OF_init(&fdt_static_dtb) != 0)
156245329Srwatson		while (1);
157245329Srwatson#endif
158245329Srwatson
159239671Srwatson	/*
160239671Srwatson	 * XXXRW: We have no way to compare wallclock time to cycle rate on
161239671Srwatson	 * BERI, so for now assume we run at the MALTA default (100MHz).
162239671Srwatson	 */
163239671Srwatson	platform_counter_freq = MIPS_DEFAULT_HZ;
164239671Srwatson	mips_timer_early_init(platform_counter_freq);
165239671Srwatson
166239671Srwatson	cninit();
167239671Srwatson	printf("entry: platform_start()\n");
168239671Srwatson
169239671Srwatson	bootverbose = 1;
170239671Srwatson	if (bootverbose) {
171239671Srwatson		printf("cmd line: ");
172239671Srwatson		for (i = 0; i < argc; i++)
173239671Srwatson			printf("%s ", argv[i]);
174239671Srwatson		printf("\n");
175239671Srwatson
176239671Srwatson		printf("envp:\n");
177239671Srwatson		for (i = 0; envp[i]; i += 2)
178239671Srwatson			printf("\t%s = %s\n", envp[i], envp[i+1]);
179239671Srwatson
180239671Srwatson		printf("memsize = %08x\n", memsize);
181239671Srwatson	}
182239671Srwatson
183239671Srwatson	realmem = btoc(memsize);
184239671Srwatson	mips_init();
185239671Srwatson
186239671Srwatson	mips_timer_init_params(platform_counter_freq, 0);
187239671Srwatson}
188