Deleted Added
full compact
beri_machdep.c (245329) beri_machdep.c (245330)
1/*-
2 * Copyright (c) 2006 Wojciech A. Koszek <wkoszek@FreeBSD.org>
3 * Copyright (c) 2012 Robert N. M. Watson
4 * All rights reserved.
5 *
6 * This software was developed by SRI International and the University of
7 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
8 * ("CTSRD"), as part of the DARPA CRASH research programme.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2006 Wojciech A. Koszek <wkoszek@FreeBSD.org>
3 * Copyright (c) 2012 Robert N. M. Watson
4 * All rights reserved.
5 *
6 * This software was developed by SRI International and the University of
7 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
8 * ("CTSRD"), as part of the DARPA CRASH research programme.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/mips/beri/beri_machdep.c 245329 2013-01-12 12:34:59Z rwatson $");
32__FBSDID("$FreeBSD: head/sys/mips/beri/beri_machdep.c 245330 2013-01-12 13:20:21Z rwatson $");
33
34#include "opt_ddb.h"
35#include "opt_platform.h"
36
37#include <sys/param.h>
38#include <sys/conf.h>
39#include <sys/kernel.h>
40#include <sys/systm.h>
41#include <sys/imgact.h>
42#include <sys/bio.h>
43#include <sys/buf.h>
44#include <sys/bus.h>
45#include <sys/cpu.h>
46#include <sys/cons.h>
47#include <sys/exec.h>
33
34#include "opt_ddb.h"
35#include "opt_platform.h"
36
37#include <sys/param.h>
38#include <sys/conf.h>
39#include <sys/kernel.h>
40#include <sys/systm.h>
41#include <sys/imgact.h>
42#include <sys/bio.h>
43#include <sys/buf.h>
44#include <sys/bus.h>
45#include <sys/cpu.h>
46#include <sys/cons.h>
47#include <sys/exec.h>
48#include <sys/linker.h>
48#include <sys/ucontext.h>
49#include <sys/proc.h>
50#include <sys/kdb.h>
51#include <sys/ptrace.h>
52#include <sys/reboot.h>
53#include <sys/signalvar.h>
54#include <sys/sysent.h>
55#include <sys/sysproto.h>
56#include <sys/user.h>
57
58#ifdef FDT
59#include <dev/fdt/fdt_common.h>
60#include <dev/ofw/openfirm.h>
61#endif
62
63#include <vm/vm.h>
64#include <vm/vm_object.h>
65#include <vm/vm_page.h>
66#include <vm/vm_pager.h>
67
68#include <machine/clock.h>
69#include <machine/cpu.h>
70#include <machine/cpuregs.h>
71#include <machine/hwfunc.h>
72#include <machine/md_var.h>
49#include <sys/ucontext.h>
50#include <sys/proc.h>
51#include <sys/kdb.h>
52#include <sys/ptrace.h>
53#include <sys/reboot.h>
54#include <sys/signalvar.h>
55#include <sys/sysent.h>
56#include <sys/sysproto.h>
57#include <sys/user.h>
58
59#ifdef FDT
60#include <dev/fdt/fdt_common.h>
61#include <dev/ofw/openfirm.h>
62#endif
63
64#include <vm/vm.h>
65#include <vm/vm_object.h>
66#include <vm/vm_page.h>
67#include <vm/vm_pager.h>
68
69#include <machine/clock.h>
70#include <machine/cpu.h>
71#include <machine/cpuregs.h>
72#include <machine/hwfunc.h>
73#include <machine/md_var.h>
74#include <machine/metadata.h>
73#include <machine/pmap.h>
74#include <machine/trap.h>
75
76extern int *edata;
77extern int *end;
78
79void
80platform_cpu_init()
81{
82 /* Nothing special */
83}
84
85static void
86mips_init(void)
87{
88 int i;
89
90 for (i = 0; i < 10; i++) {
91 phys_avail[i] = 0;
92 }
93
94 /* phys_avail regions are in bytes */
95 phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
96 phys_avail[1] = ctob(realmem);
97
98 dump_avail[0] = phys_avail[0];
99 dump_avail[1] = phys_avail[1];
100
101 physmem = realmem;
102
103 init_param1();
104 init_param2(physmem);
105 mips_cpu_init();
106 pmap_bootstrap();
107 mips_proc0_init();
108 mutex_init();
109 kdb_init();
110#ifdef KDB
111 if (boothowto & RB_KDB)
112 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
113#endif
114}
115
116/*
117 * Perform a board-level soft-reset.
118 *
119 * XXXRW: BERI doesn't yet have a board-level soft-reset.
120 */
121void
122platform_reset(void)
123{
124
125 panic("%s: not yet", __func__);
126}
127
128void
129platform_start(__register_t a0, __register_t a1, __register_t a2,
130 __register_t a3)
131{
132 vm_offset_t kernend;
133 uint64_t platform_counter_freq;
134 int argc = a0;
135 char **argv = (char **)a1;
136 char **envp = (char **)a2;
137 unsigned int memsize = a3;
75#include <machine/pmap.h>
76#include <machine/trap.h>
77
78extern int *edata;
79extern int *end;
80
81void
82platform_cpu_init()
83{
84 /* Nothing special */
85}
86
87static void
88mips_init(void)
89{
90 int i;
91
92 for (i = 0; i < 10; i++) {
93 phys_avail[i] = 0;
94 }
95
96 /* phys_avail regions are in bytes */
97 phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
98 phys_avail[1] = ctob(realmem);
99
100 dump_avail[0] = phys_avail[0];
101 dump_avail[1] = phys_avail[1];
102
103 physmem = realmem;
104
105 init_param1();
106 init_param2(physmem);
107 mips_cpu_init();
108 pmap_bootstrap();
109 mips_proc0_init();
110 mutex_init();
111 kdb_init();
112#ifdef KDB
113 if (boothowto & RB_KDB)
114 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
115#endif
116}
117
118/*
119 * Perform a board-level soft-reset.
120 *
121 * XXXRW: BERI doesn't yet have a board-level soft-reset.
122 */
123void
124platform_reset(void)
125{
126
127 panic("%s: not yet", __func__);
128}
129
130void
131platform_start(__register_t a0, __register_t a1, __register_t a2,
132 __register_t a3)
133{
134 vm_offset_t kernend;
135 uint64_t platform_counter_freq;
136 int argc = a0;
137 char **argv = (char **)a1;
138 char **envp = (char **)a2;
139 unsigned int memsize = a3;
140#ifdef FDT
141 vm_offset_t dtbp;
142 void *kmdp;
143#endif
138 int i;
139
140 /* clear the BSS and SBSS segments */
141 kernend = (vm_offset_t)&end;
142 memset(&edata, 0, kernend - (vm_offset_t)(&edata));
143
144 mips_postboot_fixup();
145
146 mips_pcpu0_init();
147
148#ifdef FDT
144 int i;
145
146 /* clear the BSS and SBSS segments */
147 kernend = (vm_offset_t)&end;
148 memset(&edata, 0, kernend - (vm_offset_t)(&edata));
149
150 mips_postboot_fixup();
151
152 mips_pcpu0_init();
153
154#ifdef FDT
149#ifndef FDT_DTB_STATIC
150#error "mips_init with FDT requires FDT_DTB_STATIC"
155 /*
156 * Find the dtb passed in by the boot loader (currently fictional).
157 */
158 kmdp = preload_search_by_type("elf kernel");
159 if (kmdp != NULL)
160 dtbp = MD_FETCH(kmdp, MODINFOMD_DTBP, vm_offset_t);
161 else
162 dtbp = (vm_offset_t)NULL;
163
164#if defined(FDT_DTB_STATIC)
165 /*
166 * In case the device tree blob was not retrieved (from metadata) try
167 * to use the statically embedded one.
168 */
169 if (dtbp == (vm_offset_t)NULL)
170 dtbp = (vm_offset_t)&fdt_static_dtb;
171#else
172#error "Non-static FDT not yet supported on BERI"
151#endif
152
153 if (OF_install(OFW_FDT, 0) == FALSE)
154 while (1);
155 if (OF_init(&fdt_static_dtb) != 0)
156 while (1);
157#endif
158
159 /*
160 * XXXRW: We have no way to compare wallclock time to cycle rate on
161 * BERI, so for now assume we run at the MALTA default (100MHz).
162 */
163 platform_counter_freq = MIPS_DEFAULT_HZ;
164 mips_timer_early_init(platform_counter_freq);
165
166 cninit();
167 printf("entry: platform_start()\n");
168
169 bootverbose = 1;
170 if (bootverbose) {
171 printf("cmd line: ");
172 for (i = 0; i < argc; i++)
173 printf("%s ", argv[i]);
174 printf("\n");
175
176 printf("envp:\n");
177 for (i = 0; envp[i]; i += 2)
178 printf("\t%s = %s\n", envp[i], envp[i+1]);
179
180 printf("memsize = %08x\n", memsize);
181 }
182
183 realmem = btoc(memsize);
184 mips_init();
185
186 mips_timer_init_params(platform_counter_freq, 0);
187}
173#endif
174
175 if (OF_install(OFW_FDT, 0) == FALSE)
176 while (1);
177 if (OF_init(&fdt_static_dtb) != 0)
178 while (1);
179#endif
180
181 /*
182 * XXXRW: We have no way to compare wallclock time to cycle rate on
183 * BERI, so for now assume we run at the MALTA default (100MHz).
184 */
185 platform_counter_freq = MIPS_DEFAULT_HZ;
186 mips_timer_early_init(platform_counter_freq);
187
188 cninit();
189 printf("entry: platform_start()\n");
190
191 bootverbose = 1;
192 if (bootverbose) {
193 printf("cmd line: ");
194 for (i = 0; i < argc; i++)
195 printf("%s ", argv[i]);
196 printf("\n");
197
198 printf("envp:\n");
199 for (i = 0; envp[i]; i += 2)
200 printf("\t%s = %s\n", envp[i], envp[i+1]);
201
202 printf("memsize = %08x\n", memsize);
203 }
204
205 realmem = btoc(memsize);
206 mips_init();
207
208 mips_timer_init_params(platform_counter_freq, 0);
209}