]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/mips/sentry5/s5_machdep.c
MFV: tcpdump 4.3.0.
[FreeBSD/FreeBSD.git] / sys / mips / sentry5 / s5_machdep.c
1 /*-
2  * Copyright (c) 2007 Bruce M. Simpson.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29
30 #include "opt_ddb.h"
31
32 #include <sys/param.h>
33 #include <sys/conf.h>
34 #include <sys/kernel.h>
35 #include <sys/systm.h>
36 #include <sys/imgact.h>
37 #include <sys/bio.h>
38 #include <sys/buf.h>
39 #include <sys/bus.h>
40 #include <sys/cpu.h>
41 #include <sys/cons.h>
42 #include <sys/exec.h>
43 #include <sys/ucontext.h>
44 #include <sys/proc.h>
45 #include <sys/kdb.h>
46 #include <sys/ptrace.h>
47 #include <sys/reboot.h>
48 #include <sys/signalvar.h>
49 #include <sys/sysent.h>
50 #include <sys/sysproto.h>
51 #include <sys/user.h>
52
53 #include <vm/vm.h>
54 #include <vm/vm_object.h>
55 #include <vm/vm_page.h>
56 #include <vm/vm_pager.h>
57
58 #include <machine/cache.h>
59 #include <machine/clock.h>
60 #include <machine/cpu.h>
61 #include <machine/cpuinfo.h>
62 #include <machine/cpufunc.h>
63 #include <machine/cpuregs.h>
64 #include <machine/hwfunc.h>
65 #include <machine/intr_machdep.h>
66 #include <machine/locore.h>
67 #include <machine/md_var.h>
68 #include <machine/pte.h>
69 #include <machine/sigframe.h>
70 #include <machine/trap.h>
71 #include <machine/vmparam.h>
72
73 #include <mips/sentry5/s5reg.h>
74
75 #ifdef CFE
76 #include <dev/cfe/cfe_api.h>
77 #endif
78
79 extern int *edata;
80 extern int *end;
81
82 void
83 platform_cpu_init()
84 {
85         /* Nothing special */
86 }
87
88 static void
89 mips_init(void)
90 {
91         int i, j;
92
93         printf("entry: mips_init()\n");
94
95 #ifdef CFE
96         /*
97          * Query DRAM memory map from CFE.
98          */
99         physmem = 0;
100         for (i = 0; i < 10; i += 2) {
101                 int result;
102                 uint64_t addr, len, type;
103
104                 result = cfe_enummem(i, 0, &addr, &len, &type);
105                 if (result < 0) {
106                         phys_avail[i] = phys_avail[i + 1] = 0;
107                         break;
108                 }
109                 if (type != CFE_MI_AVAILABLE)
110                         continue;
111
112                 phys_avail[i] = addr;
113                 if (i == 0 && addr == 0) {
114                         /*
115                          * If this is the first physical memory segment probed
116                          * from CFE, omit the region at the start of physical
117                          * memory where the kernel has been loaded.
118                          */
119                         phys_avail[i] += MIPS_KSEG0_TO_PHYS(kernel_kseg0_end);
120                 }
121                 phys_avail[i + 1] = addr + len;
122                 physmem += len;
123         }
124
125         realmem = btoc(physmem);
126 #endif
127
128         for (j = 0; j < i; j++)
129                 dump_avail[j] = phys_avail[j];
130
131         physmem = realmem;
132
133         init_param1();
134         init_param2(physmem);
135         mips_cpu_init();
136         pmap_bootstrap();
137         mips_proc0_init();
138         mutex_init();
139         kdb_init();
140 #ifdef KDB
141         if (boothowto & RB_KDB)
142                 kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
143 #endif
144 }
145
146 void
147 platform_reset(void)
148 {
149
150 #if defined(CFE)
151         cfe_exit(0, 0);
152 #else
153         *((volatile uint8_t *)MIPS_PHYS_TO_KSEG1(SENTRY5_EXTIFADR)) = 0x80;
154 #endif
155 }
156
157 void
158 platform_start(__register_t a0, __register_t a1, __register_t a2,
159                __register_t a3)
160 {
161         vm_offset_t kernend;
162         uint64_t platform_counter_freq;
163
164         /* clear the BSS and SBSS segments */
165         kernend = (vm_offset_t)&end;
166         memset(&edata, 0, kernend - (vm_offset_t)(&edata));
167
168         mips_postboot_fixup();
169
170         /* Initialize pcpu stuff */
171         mips_pcpu0_init();
172
173 #ifdef CFE
174         /*
175          * Initialize CFE firmware trampolines before
176          * we initialize the low-level console.
177          *
178          * CFE passes the following values in registers:
179          * a0: firmware handle
180          * a2: firmware entry point
181          * a3: entry point seal
182          */
183         if (a3 == CFE_EPTSEAL)
184                 cfe_init(a0, a2);
185 #endif
186         cninit();
187
188         mips_init();
189
190 # if 0
191         /*
192          * Probe the Broadcom Sentry5's on-chip PLL clock registers
193          * and discover the CPU pipeline clock and bus clock
194          * multipliers from this.
195          * XXX: Wrong place. You have to ask the ChipCommon
196          * or External Interface cores on the SiBa.
197          */
198         uint32_t busmult, cpumult, refclock, clkcfg1;
199 #define S5_CLKCFG1_REFCLOCK_MASK        0x0000001F
200 #define S5_CLKCFG1_BUSMULT_MASK         0x000003E0
201 #define S5_CLKCFG1_BUSMULT_SHIFT        5
202 #define S5_CLKCFG1_CPUMULT_MASK         0xFFFFFC00
203 #define S5_CLKCFG1_CPUMULT_SHIFT        10
204
205         counter_freq = 100000000;       /* XXX */
206
207         clkcfg1 = s5_rd_clkcfg1();
208         printf("clkcfg1 = 0x%08x\n", clkcfg1);
209
210         refclock = clkcfg1 & 0x1F;
211         busmult = ((clkcfg1 & 0x000003E0) >> 5) + 1;
212         cpumult = ((clkcfg1 & 0xFFFFFC00) >> 10) + 1;
213
214         printf("refclock = %u\n", refclock);
215         printf("busmult = %u\n", busmult);
216         printf("cpumult = %u\n", cpumult);
217
218         counter_freq = cpumult * refclock;
219 # else
220         platform_counter_freq = 200 * 1000 * 1000; /* Sentry5 is 200MHz */
221 # endif
222
223         mips_timer_init_params(platform_counter_freq, 0);
224 }