machdep.c revision 1.25.2.1 1 /* $NetBSD: machdep.c,v 1.25.2.1 2021/04/03 22:28:25 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 2006 Jachym Holecek
5 * All rights reserved.
6 *
7 * Written for DFC Design, s.r.o.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * Based on Walnut and Explora.
34 */
35
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.25.2.1 2021/04/03 22:28:25 thorpej Exp $");
38
39 #include "opt_compat_netbsd.h"
40 #include "opt_ddb.h"
41 #include "opt_virtex.h"
42 #include "opt_kgdb.h"
43
44 #include <sys/param.h>
45 #include <sys/boot_flag.h>
46 #include <sys/buf.h>
47 #include <sys/bus.h>
48 #include <sys/device.h>
49 #include <sys/exec.h>
50 #include <sys/malloc.h>
51 #include <sys/mbuf.h>
52 #include <sys/module.h>
53 #include <sys/mount.h>
54 #include <sys/msgbuf.h>
55 #include <sys/kernel.h>
56 #include <sys/ksyms.h>
57 #include <sys/proc.h>
58 #include <sys/reboot.h>
59 #include <sys/syscallargs.h>
60 #include <sys/syslog.h>
61 #include <sys/systm.h>
62
63 #include <uvm/uvm_extern.h>
64
65 #include <dev/cons.h>
66
67 #include <machine/powerpc.h>
68
69 #include <powerpc/trap.h>
70 #include <powerpc/pcb.h>
71
72 #include <powerpc/spr.h>
73 #include <powerpc/ibm4xx/spr.h>
74
75 #include <powerpc/ibm4xx/cpu.h>
76
77 #include <evbppc/virtex/dcr.h>
78 #include <evbppc/virtex/virtex.h>
79
80 #include "ksyms.h"
81
82 #if defined(DDB)
83 #include <powerpc/db_machdep.h>
84 #include <ddb/db_extern.h>
85 #endif
86
87 #if defined(KGDB)
88 #include <sys/kgdb.h>
89 #endif
90
91 void initppc(vaddr_t, vaddr_t);
92
93 /* BSS segment start & end. */
94 extern char edata[], end[];
95
96 /* One region holds all memory, the other is terminator expected by 405 pmap. */
97 #define MEMREGIONS 2
98 struct mem_region physmemr[MEMREGIONS];
99 struct mem_region availmemr[MEMREGIONS];
100
101 /* Maximum TLB page size. */
102 #define TLB_PG_SIZE (16*1024*1024)
103
104 void
105 initppc(vaddr_t startkernel, vaddr_t endkernel)
106 {
107 paddr_t addr, memsize;
108
109 /* Initialize cache info for memcpy, memset, etc. */
110 cpu_probe_cache();
111
112 memset(physmemr, 0, sizeof(physmemr)); /* [1].size = 0 */
113 memset(availmemr, 0, sizeof(availmemr)); /* [1].size = 0 */
114
115 memsize = (PHYSMEM * 1024 * 1024) & ~PGOFSET;
116
117 physmemr[0].start = 0;
118 physmemr[0].size = memsize;
119
120 availmemr[0].start = startkernel;
121 availmemr[0].size = memsize - availmemr[0].start;
122
123 /* Map kernel memory linearly. */
124 for (addr = 0; addr < endkernel; addr += TLB_PG_SIZE)
125 ppc4xx_tlb_reserve(addr, addr, TLB_PG_SIZE, TLB_EX);
126
127 /* Give design-specific code a hint for reserved mappings. */
128 virtex_machdep_init(roundup(memsize, TLB_PG_SIZE), TLB_PG_SIZE,
129 physmemr, availmemr);
130
131 ibm4xx_init(startkernel, endkernel, pic_ext_intr);
132
133 #ifdef DDB
134 if (boothowto & RB_KDB)
135 Debugger();
136 #endif
137
138 #ifdef KGDB
139 /*
140 * Now trap to KGDB
141 */
142 kgdb_connect(1);
143 #endif /* KGDB */
144
145 /*
146 * Look for the ibm4xx modules in the right place.
147 */
148 module_machine = module_machine_ibm4xx;
149 }
150
151 /*
152 * Machine dependent startup code.
153 */
154
155 void
156 cpu_startup(void)
157 {
158 /* For use by propdb. */
159 static u_int memsize = PHYSMEM * 1024 * 1024;
160 static u_int cpuspeed = CPUFREQ * 1000 * 1000;
161 prop_number_t pn;
162
163 vaddr_t minaddr, maxaddr;
164 char pbuf[9];
165
166 curcpu()->ci_khz = cpuspeed / 1000;
167
168 /* Initialize error message buffer. */
169 initmsgbuf((void *)msgbuf, round_page(MSGBUFSIZE));
170
171 printf("%s%s", copyright, version);
172
173 format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
174 printf("total memory = %s\n", pbuf);
175
176 minaddr = 0;
177 /*
178 * Allocate a submap for physio
179 */
180 phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
181 VM_PHYS_SIZE, 0, false, NULL);
182
183 /*
184 * No need to allocate an mbuf cluster submap. Mbuf clusters
185 * are allocated via the pool allocator, and we use direct-mapped
186 * pool pages.
187 */
188
189 format_bytes(pbuf, sizeof(pbuf), ptoa(uvm_availmem(false)));
190 printf("avail memory = %s\n", pbuf);
191
192 /*
193 * Set up the board properties database.
194 */
195 board_info_init();
196
197 pn = prop_number_create_integer(memsize);
198 KASSERT(pn != NULL);
199 if (prop_dictionary_set(board_properties, "mem-size", pn) == false)
200 panic("setting mem-size");
201 prop_object_release(pn);
202
203 pn = prop_number_create_integer(cpuspeed);
204 KASSERT(pn != NULL);
205 if (prop_dictionary_set(board_properties, "processor-frequency",
206 pn) == false)
207 panic("setting processor-frequency");
208 prop_object_release(pn);
209
210 /*
211 * Now that we have VM, malloc()s are OK in bus_space.
212 */
213 bus_space_mallocok();
214 fake_mapiodev = 0;
215 }
216
217 /* Hook used by 405 pmap module. */
218 void
219 mem_regions(struct mem_region **mem, struct mem_region **avail)
220 {
221 *mem = physmemr;
222 *avail = availmemr;
223 }
224