rt305x_machdep.c revision 330897
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (C) 2010-2011 by Aleksandr Rybalko. All rights reserved.
5 * Copyright (C) 2007 by Oleksandr Tymoshenko. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 * THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: stable/11/sys/mips/rt305x/rt305x_machdep.c 330897 2018-03-14 03:19:51Z eadler $");
32
33#include "opt_ddb.h"
34
35#include <sys/param.h>
36#include <sys/conf.h>
37#include <sys/kernel.h>
38#include <sys/systm.h>
39#include <sys/imgact.h>
40#include <sys/bio.h>
41#include <sys/buf.h>
42#include <sys/bus.h>
43#include <sys/cpu.h>
44#include <sys/cons.h>
45#include <sys/exec.h>
46#include <sys/ucontext.h>
47#include <sys/proc.h>
48#include <sys/kdb.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>
54#include <sys/user.h>
55
56#include <vm/vm.h>
57#include <vm/vm_object.h>
58#include <vm/vm_page.h>
59
60#include <machine/cache.h>
61#include <machine/clock.h>
62#include <machine/cpu.h>
63#include <machine/cpuinfo.h>
64#include <machine/cpufunc.h>
65#include <machine/cpuregs.h>
66#include <machine/hwfunc.h>
67#include <machine/intr_machdep.h>
68#include <machine/locore.h>
69#include <machine/md_var.h>
70#include <machine/pte.h>
71#include <machine/sigframe.h>
72#include <machine/trap.h>
73#include <machine/vmparam.h>
74
75#include <mips/rt305x/rt305xreg.h>
76#include <mips/rt305x/rt305x_sysctlvar.h>
77
78extern int	*edata;
79extern int	*end;
80static char 	boot1_env[0x1000];
81
82
83void
84platform_cpu_init()
85{
86	/* Nothing special */
87}
88
89static void
90mips_init(void)
91{
92	int i;
93	char *memsize;
94
95	printf("entry: mips_init()\n");
96
97	if ((memsize = kern_getenv("memsize")) != NULL)
98		realmem = btoc(strtol(memsize, NULL, 0) << 20);
99	else
100		realmem = btoc(32 << 20);
101
102
103	bootverbose = 1;
104
105	for (i = 0; i < 10; i++) {
106		phys_avail[i] = 0;
107	}
108
109	/* phys_avail regions are in bytes */
110	dump_avail[0] = phys_avail[0] = MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
111	dump_avail[1] = phys_avail[1] = ctob(realmem);
112
113	physmem = realmem;
114
115	init_param1();
116	init_param2(physmem);
117	mips_cpu_init();
118	pmap_bootstrap();
119	mips_proc0_init();
120	mutex_init();
121	kdb_init();
122#ifdef KDB
123	if (boothowto & RB_KDB)
124		kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
125#endif
126}
127
128void
129platform_reset(void)
130{
131
132#if !defined(MT7620) && !defined(RT5350)
133	__asm __volatile("li	$25, 0xbf000000");
134	__asm __volatile("j	$25");
135#else
136	rt305x_sysctl_set(SYSCTL_RSTCTRL, 1);
137	while (1);
138#endif
139}
140
141void
142platform_start(__register_t a0 __unused, __register_t a1 __unused,
143    __register_t a2 __unused, __register_t a3 __unused)
144{
145	vm_offset_t kernend;
146	uint64_t platform_counter_freq = PLATFORM_COUNTER_FREQ;
147	int i;
148	int argc = a0;
149	char **argv = (char **)MIPS_PHYS_TO_KSEG0(a1);
150	char **envp = (char **)MIPS_PHYS_TO_KSEG0(a2);
151
152	/* clear the BSS and SBSS segments */
153	kernend = (vm_offset_t)&end;
154	memset(&edata, 0, kernend - (vm_offset_t)(&edata));
155
156	mips_postboot_fixup();
157
158	/* Initialize pcpu stuff */
159	mips_pcpu0_init();
160
161	mips_timer_early_init(platform_counter_freq / 2);
162
163	/* initialize console so that we have printf */
164	boothowto |= (RB_SERIAL | RB_MULTIPLE);	/* Use multiple consoles */
165	boothowto |= (RB_VERBOSE);
166	cninit();
167
168	init_static_kenv(boot1_env, sizeof(boot1_env));
169
170	printf("U-Boot args (from %d args):\n", argc - 1);
171
172	if (argc == 1)
173		printf("\tNone\n");
174
175	for (i = 1; i < argc; i++) {
176		char *n = "argv  ", *arg;
177
178		if (i > 99)
179			break;
180
181		if (argv[i])
182		{
183			arg = (char *)(intptr_t)MIPS_PHYS_TO_KSEG0(argv[i]);
184			printf("\targv[%d] = %s\n", i, arg);
185			sprintf(n, "argv%d", i);
186			kern_setenv(n, arg);
187		}
188	}
189
190	printf("Environment:\n");
191
192	for (i = 0; envp[i] && MIPS_IS_VALID_PTR(envp[i]); i++) {
193		char *n, *arg;
194
195		arg = (char *)(intptr_t)MIPS_PHYS_TO_KSEG0(envp[i]);
196		if (! MIPS_IS_VALID_PTR(arg))
197			continue;
198		printf("\t%s\n", arg);
199		n = strsep(&arg, "=");
200		if (arg == NULL)
201			kern_setenv(n, "1");
202		else
203			kern_setenv(n, arg);
204	}
205
206
207	mips_init();
208	mips_timer_init_params(platform_counter_freq, 1);
209}
210