booke_machdep.c revision 1.4.2.2 1 1.4.2.2 rmind /*-
2 1.4.2.2 rmind * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
3 1.4.2.2 rmind * All rights reserved.
4 1.4.2.2 rmind *
5 1.4.2.2 rmind * This code is derived from software contributed to The NetBSD Foundation
6 1.4.2.2 rmind * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects
7 1.4.2.2 rmind * Agency and which was developed by Matt Thomas of 3am Software Foundry.
8 1.4.2.2 rmind *
9 1.4.2.2 rmind * This material is based upon work supported by the Defense Advanced Research
10 1.4.2.2 rmind * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under
11 1.4.2.2 rmind * Contract No. N66001-09-C-2073.
12 1.4.2.2 rmind * Approved for Public Release, Distribution Unlimited
13 1.4.2.2 rmind *
14 1.4.2.2 rmind * Redistribution and use in source and binary forms, with or without
15 1.4.2.2 rmind * modification, are permitted provided that the following conditions
16 1.4.2.2 rmind * are met:
17 1.4.2.2 rmind * 1. Redistributions of source code must retain the above copyright
18 1.4.2.2 rmind * notice, this list of conditions and the following disclaimer.
19 1.4.2.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
20 1.4.2.2 rmind * notice, this list of conditions and the following disclaimer in the
21 1.4.2.2 rmind * documentation and/or other materials provided with the distribution.
22 1.4.2.2 rmind *
23 1.4.2.2 rmind * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 1.4.2.2 rmind * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 1.4.2.2 rmind * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 1.4.2.2 rmind * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 1.4.2.2 rmind * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 1.4.2.2 rmind * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 1.4.2.2 rmind * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.4.2.2 rmind * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 1.4.2.2 rmind * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 1.4.2.2 rmind * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 1.4.2.2 rmind * POSSIBILITY OF SUCH DAMAGE.
34 1.4.2.2 rmind */
35 1.4.2.2 rmind
36 1.4.2.2 rmind #define __INTR_PRIVATE
37 1.4.2.2 rmind #define _POWERPC_BUS_DMA_PRIVATE
38 1.4.2.2 rmind
39 1.4.2.2 rmind #include <sys/cdefs.h>
40 1.4.2.2 rmind
41 1.4.2.2 rmind #include <sys/param.h>
42 1.4.2.2 rmind #include <sys/cpu.h>
43 1.4.2.2 rmind #include <sys/device.h>
44 1.4.2.2 rmind #include <sys/intr.h>
45 1.4.2.2 rmind #include <sys/mount.h>
46 1.4.2.2 rmind #include <sys/msgbuf.h>
47 1.4.2.2 rmind #include <sys/kernel.h>
48 1.4.2.2 rmind #include <sys/reboot.h>
49 1.4.2.2 rmind #include <sys/bus.h>
50 1.4.2.2 rmind
51 1.4.2.2 rmind #include <uvm/uvm_extern.h>
52 1.4.2.2 rmind
53 1.4.2.2 rmind #include <powerpc/spr.h>
54 1.4.2.2 rmind #include <powerpc/booke/spr.h>
55 1.4.2.2 rmind #include <powerpc/booke/cpuvar.h>
56 1.4.2.2 rmind
57 1.4.2.2 rmind /*
58 1.4.2.2 rmind * Global variables used here and there
59 1.4.2.2 rmind */
60 1.4.2.2 rmind paddr_t msgbuf_paddr;
61 1.4.2.2 rmind psize_t pmemsize;
62 1.4.2.2 rmind struct vm_map *phys_map;
63 1.4.2.2 rmind
64 1.4.2.2 rmind static bus_addr_t booke_dma_phys_to_bus_mem(bus_dma_tag_t, bus_addr_t);
65 1.4.2.2 rmind static bus_addr_t booke_dma_bus_mem_to_phys(bus_dma_tag_t, bus_addr_t);
66 1.4.2.2 rmind
67 1.4.2.2 rmind
68 1.4.2.2 rmind struct powerpc_bus_dma_tag booke_bus_dma_tag = {
69 1.4.2.2 rmind ._dmamap_create = _bus_dmamap_create,
70 1.4.2.2 rmind ._dmamap_destroy = _bus_dmamap_destroy,
71 1.4.2.2 rmind ._dmamap_load = _bus_dmamap_load,
72 1.4.2.2 rmind ._dmamap_load_mbuf = _bus_dmamap_load_mbuf,
73 1.4.2.2 rmind ._dmamap_load_uio = _bus_dmamap_load_uio,
74 1.4.2.2 rmind ._dmamap_load_raw = _bus_dmamap_load_raw,
75 1.4.2.2 rmind ._dmamap_unload = _bus_dmamap_unload,
76 1.4.2.2 rmind ._dmamap_sync = _bus_dmamap_sync,
77 1.4.2.2 rmind ._dmamem_alloc = _bus_dmamem_alloc,
78 1.4.2.2 rmind ._dmamem_free = _bus_dmamem_free,
79 1.4.2.2 rmind ._dmamem_map = _bus_dmamem_map,
80 1.4.2.2 rmind ._dmamem_unmap = _bus_dmamem_unmap,
81 1.4.2.2 rmind ._dmamem_mmap = _bus_dmamem_mmap,
82 1.4.2.2 rmind ._dma_phys_to_bus_mem = booke_dma_phys_to_bus_mem,
83 1.4.2.2 rmind ._dma_bus_mem_to_phys = booke_dma_bus_mem_to_phys,
84 1.4.2.2 rmind };
85 1.4.2.2 rmind
86 1.4.2.2 rmind static bus_addr_t
87 1.4.2.2 rmind booke_dma_phys_to_bus_mem(bus_dma_tag_t t, bus_addr_t a)
88 1.4.2.2 rmind {
89 1.4.2.2 rmind return a;
90 1.4.2.2 rmind }
91 1.4.2.2 rmind
92 1.4.2.2 rmind static bus_addr_t
93 1.4.2.2 rmind booke_dma_bus_mem_to_phys(bus_dma_tag_t t, bus_addr_t a)
94 1.4.2.2 rmind {
95 1.4.2.2 rmind return a;
96 1.4.2.2 rmind }
97 1.4.2.2 rmind
98 1.4.2.2 rmind static int
99 1.4.2.2 rmind null_splraise(int ipl)
100 1.4.2.2 rmind {
101 1.4.2.2 rmind int cpl = curcpu()->ci_cpl;
102 1.4.2.2 rmind curcpu()->ci_cpl = ipl;
103 1.4.2.2 rmind return cpl;
104 1.4.2.2 rmind }
105 1.4.2.2 rmind
106 1.4.2.2 rmind static void
107 1.4.2.2 rmind null_splx(int ipl)
108 1.4.2.2 rmind {
109 1.4.2.2 rmind curcpu()->ci_cpl = ipl;
110 1.4.2.2 rmind }
111 1.4.2.2 rmind
112 1.4.2.2 rmind static const struct intrsw null_intrsw = {
113 1.4.2.2 rmind .intrsw_splraise = null_splraise,
114 1.4.2.2 rmind .intrsw_splx = null_splx,
115 1.4.2.2 rmind };
116 1.4.2.2 rmind
117 1.4.2.2 rmind const struct intrsw *powerpc_intrsw = &null_intrsw;
118 1.4.2.2 rmind struct cpu_md_ops cpu_md_ops;
119 1.4.2.2 rmind extern struct cpu_info cpu_info[1];
120 1.4.2.2 rmind
121 1.4.2.2 rmind #if 0
122 1.4.2.2 rmind pt_entry_t ptp0[NPTEPG] = {
123 1.4.2.2 rmind [(0x20000 & SEGOFSET) >> PGSHIFT] = 0x00020000|PTE_xR|PTE_xX|PTE_M,
124 1.4.2.2 rmind };
125 1.4.2.2 rmind
126 1.4.2.2 rmind struct pmap_segtab pmap_kern_segtab = {
127 1.4.2.2 rmind .seg_tab[0x20000 >> SEGSHIFT] = ptp0,
128 1.4.2.2 rmind };
129 1.4.2.2 rmind #endif
130 1.4.2.2 rmind
131 1.4.2.2 rmind struct cpu_softc cpu_softc[1] = {
132 1.4.2.2 rmind [0] = {
133 1.4.2.2 rmind .cpu_ci = cpu_info,
134 1.4.2.2 rmind },
135 1.4.2.2 rmind };
136 1.4.2.2 rmind struct cpu_info cpu_info[1] = {
137 1.4.2.2 rmind [0] = {
138 1.4.2.2 rmind .ci_curlwp = &lwp0,
139 1.4.2.2 rmind .ci_tlb_info = &pmap_tlb0_info,
140 1.4.2.2 rmind .ci_softc = cpu_softc,
141 1.4.2.2 rmind .ci_cpl = IPL_HIGH,
142 1.4.2.2 rmind .ci_fpulwp = &lwp0,
143 1.4.2.2 rmind .ci_veclwp = &lwp0,
144 1.4.2.2 rmind #if 0
145 1.4.2.2 rmind .ci_pmap_kern_segtab = &pmap_kern_segtab,
146 1.4.2.2 rmind #endif
147 1.4.2.2 rmind },
148 1.4.2.2 rmind };
149 1.4.2.2 rmind
150 1.4.2.2 rmind /*
151 1.4.2.2 rmind * This should probably be in autoconf! XXX
152 1.4.2.2 rmind */
153 1.4.2.2 rmind char cpu_model[80];
154 1.4.2.2 rmind char machine[] = MACHINE; /* from <machine/param.h> */
155 1.4.2.2 rmind char machine_arch[] = MACHINE_ARCH; /* from <machine/param.h> */
156 1.4.2.2 rmind
157 1.4.2.2 rmind char bootpath[256];
158 1.4.2.2 rmind
159 1.4.2.2 rmind #if NKSYMS || defined(DDB) || defined(MODULAR)
160 1.4.2.2 rmind void *startsym, *endsym;
161 1.4.2.2 rmind #endif
162 1.4.2.2 rmind
163 1.4.2.2 rmind int fake_mapiodev = 1;
164 1.4.2.2 rmind
165 1.4.2.2 rmind void lcsplx(int);
166 1.4.2.2 rmind
167 1.4.2.2 rmind void
168 1.4.2.2 rmind booke_cpu_startup(const char *model)
169 1.4.2.2 rmind {
170 1.4.2.2 rmind vaddr_t minaddr, maxaddr;
171 1.4.2.2 rmind char pbuf[9];
172 1.4.2.2 rmind
173 1.4.2.2 rmind strlcpy(cpu_model, model, sizeof(cpu_model));
174 1.4.2.2 rmind
175 1.4.2.2 rmind printf("%s%s", copyright, version);
176 1.4.2.2 rmind
177 1.4.2.2 rmind format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
178 1.4.2.2 rmind printf("total memory = %s\n", pbuf);
179 1.4.2.2 rmind
180 1.4.2.2 rmind minaddr = 0;
181 1.4.2.2 rmind /*
182 1.4.2.2 rmind * Allocate a submap for physio
183 1.4.2.2 rmind */
184 1.4.2.2 rmind phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
185 1.4.2.2 rmind VM_PHYS_SIZE, 0, false, NULL);
186 1.4.2.2 rmind
187 1.4.2.2 rmind /*
188 1.4.2.2 rmind * No need to allocate an mbuf cluster submap. Mbuf clusters
189 1.4.2.2 rmind * are allocated via the pool allocator, and we use direct-mapped
190 1.4.2.2 rmind * pool pages.
191 1.4.2.2 rmind */
192 1.4.2.2 rmind
193 1.4.2.2 rmind format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
194 1.4.2.2 rmind printf("avail memory = %s\n", pbuf);
195 1.4.2.2 rmind
196 1.4.2.2 rmind /*
197 1.4.2.2 rmind * Set up the board properties database.
198 1.4.2.2 rmind */
199 1.4.2.2 rmind board_info_init();
200 1.4.2.2 rmind
201 1.4.2.2 rmind /*
202 1.4.2.2 rmind * Now that we have VM, malloc()s are OK in bus_space.
203 1.4.2.2 rmind */
204 1.4.2.2 rmind bus_space_mallocok();
205 1.4.2.2 rmind fake_mapiodev = 0;
206 1.4.2.2 rmind }
207 1.4.2.2 rmind
208 1.4.2.2 rmind static void
209 1.4.2.2 rmind dumpsys(void)
210 1.4.2.2 rmind {
211 1.4.2.2 rmind
212 1.4.2.2 rmind printf("dumpsys: TBD\n");
213 1.4.2.2 rmind }
214 1.4.2.2 rmind
215 1.4.2.2 rmind /*
216 1.4.2.2 rmind * Halt or reboot the machine after syncing/dumping according to howto.
217 1.4.2.2 rmind */
218 1.4.2.2 rmind void
219 1.4.2.2 rmind cpu_reboot(int howto, char *what)
220 1.4.2.2 rmind {
221 1.4.2.2 rmind static int syncing;
222 1.4.2.2 rmind static char str[256];
223 1.4.2.2 rmind char *ap = str, *ap1 = ap;
224 1.4.2.2 rmind
225 1.4.2.2 rmind boothowto = howto;
226 1.4.2.2 rmind if (!cold && !(howto & RB_NOSYNC) && !syncing) {
227 1.4.2.2 rmind syncing = 1;
228 1.4.2.2 rmind vfs_shutdown(); /* sync */
229 1.4.2.2 rmind resettodr(); /* set wall clock */
230 1.4.2.2 rmind }
231 1.4.2.2 rmind
232 1.4.2.2 rmind splhigh();
233 1.4.2.2 rmind
234 1.4.2.2 rmind if (!cold && (howto & RB_DUMP))
235 1.4.2.2 rmind dumpsys();
236 1.4.2.2 rmind
237 1.4.2.2 rmind doshutdownhooks();
238 1.4.2.2 rmind
239 1.4.2.2 rmind pmf_system_shutdown(boothowto);
240 1.4.2.2 rmind
241 1.4.2.2 rmind if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
242 1.4.2.2 rmind /* Power off here if we know how...*/
243 1.4.2.2 rmind }
244 1.4.2.2 rmind
245 1.4.2.2 rmind if (howto & RB_HALT) {
246 1.4.2.2 rmind printf("halted\n\n");
247 1.4.2.2 rmind
248 1.4.2.2 rmind goto reboot; /* XXX for now... */
249 1.4.2.2 rmind
250 1.4.2.2 rmind #ifdef DDB
251 1.4.2.2 rmind printf("dropping to debugger\n");
252 1.4.2.2 rmind while(1)
253 1.4.2.2 rmind Debugger();
254 1.4.2.2 rmind #endif
255 1.4.2.2 rmind }
256 1.4.2.2 rmind
257 1.4.2.2 rmind printf("rebooting\n\n");
258 1.4.2.2 rmind if (what && *what) {
259 1.4.2.2 rmind if (strlen(what) > sizeof str - 5)
260 1.4.2.2 rmind printf("boot string too large, ignored\n");
261 1.4.2.2 rmind else {
262 1.4.2.2 rmind strcpy(str, what);
263 1.4.2.2 rmind ap1 = ap = str + strlen(str);
264 1.4.2.2 rmind *ap++ = ' ';
265 1.4.2.2 rmind }
266 1.4.2.2 rmind }
267 1.4.2.2 rmind *ap++ = '-';
268 1.4.2.2 rmind if (howto & RB_SINGLE)
269 1.4.2.2 rmind *ap++ = 's';
270 1.4.2.2 rmind if (howto & RB_KDB)
271 1.4.2.2 rmind *ap++ = 'd';
272 1.4.2.2 rmind *ap++ = 0;
273 1.4.2.2 rmind if (ap[-2] == '-')
274 1.4.2.2 rmind *ap1 = 0;
275 1.4.2.2 rmind
276 1.4.2.2 rmind /* flush cache for msgbuf */
277 1.4.2.2 rmind dcache_wb(msgbuf_paddr, round_page(MSGBUFSIZE));
278 1.4.2.2 rmind
279 1.4.2.2 rmind reboot:
280 1.4.2.2 rmind __asm volatile("msync; isync");
281 1.4.2.2 rmind (*cpu_md_ops.md_cpu_reset)();
282 1.4.2.2 rmind
283 1.4.2.2 rmind printf("%s: md_cpu_reset() failed!\n", __func__);
284 1.4.2.2 rmind #ifdef DDB
285 1.4.2.2 rmind for (;;)
286 1.4.2.2 rmind Debugger();
287 1.4.2.2 rmind #else
288 1.4.2.2 rmind for (;;)
289 1.4.2.2 rmind /* nothing */;
290 1.4.2.2 rmind #endif
291 1.4.2.2 rmind }
292 1.4.2.2 rmind void
293 1.4.2.2 rmind lcsplx(int spl)
294 1.4.2.2 rmind {
295 1.4.2.2 rmind splx(spl);
296 1.4.2.2 rmind }
297 1.4.2.2 rmind
298 1.4.2.2 rmind /*
299 1.4.2.2 rmind * mapiodev:
300 1.4.2.2 rmind *
301 1.4.2.2 rmind * Allocate vm space and mapin the I/O address. Use reserved TLB
302 1.4.2.2 rmind * mapping if one is found.
303 1.4.2.2 rmind */
304 1.4.2.2 rmind void *
305 1.4.2.2 rmind mapiodev(paddr_t pa, psize_t len)
306 1.4.2.2 rmind {
307 1.4.2.2 rmind const vsize_t off = pa & PAGE_MASK;
308 1.4.2.2 rmind
309 1.4.2.2 rmind /*
310 1.4.2.2 rmind * See if we have reserved TLB entry for the pa. This needs to be
311 1.4.2.2 rmind * true for console as we can't use uvm during early bootstrap.
312 1.4.2.2 rmind */
313 1.4.2.2 rmind void * const p = tlb_mapiodev(pa, len);
314 1.4.2.2 rmind if (p != NULL)
315 1.4.2.2 rmind return p;
316 1.4.2.2 rmind
317 1.4.2.2 rmind if (fake_mapiodev)
318 1.4.2.2 rmind panic("mapiodev: no TLB entry reserved for %llx+%llx",
319 1.4.2.2 rmind (long long)pa, (long long)len);
320 1.4.2.2 rmind
321 1.4.2.2 rmind pa = trunc_page(pa);
322 1.4.2.2 rmind len = round_page(off + len);
323 1.4.2.2 rmind vaddr_t va = uvm_km_alloc(kernel_map, len, 0, UVM_KMF_VAONLY);
324 1.4.2.2 rmind
325 1.4.2.2 rmind if (va == 0)
326 1.4.2.2 rmind return NULL;
327 1.4.2.2 rmind
328 1.4.2.2 rmind for (va += len, pa += len; len > 0; len -= PAGE_SIZE) {
329 1.4.2.2 rmind va -= PAGE_SIZE;
330 1.4.2.2 rmind pa -= PAGE_SIZE;
331 1.4.2.2 rmind pmap_kenter_pa(va, pa, VM_PROT_READ|VM_PROT_WRITE,
332 1.4.2.2 rmind PMAP_NOCACHE);
333 1.4.2.2 rmind }
334 1.4.2.2 rmind pmap_update(pmap_kernel());
335 1.4.2.2 rmind return (void *)(va + off);
336 1.4.2.2 rmind }
337 1.4.2.2 rmind
338 1.4.2.2 rmind void
339 1.4.2.2 rmind unmapiodev(vaddr_t va, vsize_t len)
340 1.4.2.2 rmind {
341 1.4.2.2 rmind /* Nothing to do for reserved (ie. not uvm_km_alloc'd) mappings. */
342 1.4.2.2 rmind if (va < VM_MIN_KERNEL_ADDRESS || va > VM_MAX_KERNEL_ADDRESS) {
343 1.4.2.2 rmind tlb_unmapiodev(va, len);
344 1.4.2.2 rmind return;
345 1.4.2.2 rmind }
346 1.4.2.2 rmind
347 1.4.2.2 rmind len = round_page((va & PAGE_MASK) + len);
348 1.4.2.2 rmind va = trunc_page(va);
349 1.4.2.2 rmind
350 1.4.2.2 rmind pmap_kremove(va, len);
351 1.4.2.2 rmind uvm_km_free(kernel_map, va, len, UVM_KMF_VAONLY);
352 1.4.2.2 rmind }
353 1.4.2.2 rmind
354 1.4.2.2 rmind void
355 1.4.2.2 rmind cpu_evcnt_attach(struct cpu_info *ci)
356 1.4.2.2 rmind {
357 1.4.2.2 rmind struct cpu_softc * const cpu = ci->ci_softc;
358 1.4.2.2 rmind const char * const xname = device_xname(ci->ci_dev);
359 1.4.2.2 rmind
360 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_clock, EVCNT_TYPE_INTR,
361 1.4.2.2 rmind NULL, xname, "clock");
362 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&cpu->cpu_ev_late_clock, EVCNT_TYPE_INTR,
363 1.4.2.2 rmind NULL, xname, "late clock");
364 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&cpu->cpu_ev_exec_trap_sync, EVCNT_TYPE_TRAP,
365 1.4.2.2 rmind NULL, xname, "exec pages synced (trap)");
366 1.4.2.2 rmind #ifndef __HAVE_FAST_SOFTINTS
367 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_softclock, EVCNT_TYPE_INTR,
368 1.4.2.2 rmind NULL, xname, "soft clock");
369 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_softnet, EVCNT_TYPE_INTR,
370 1.4.2.2 rmind NULL, xname, "soft net");
371 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_softserial, EVCNT_TYPE_INTR,
372 1.4.2.2 rmind NULL, xname, "soft serial");
373 1.4.2.2 rmind #endif
374 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_traps, EVCNT_TYPE_TRAP,
375 1.4.2.2 rmind NULL, xname, "traps");
376 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_kdsi, EVCNT_TYPE_TRAP,
377 1.4.2.2 rmind &ci->ci_ev_traps, xname, "kernel DSI traps");
378 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_udsi, EVCNT_TYPE_TRAP,
379 1.4.2.2 rmind &ci->ci_ev_traps, xname, "user DSI traps");
380 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_udsi_fatal, EVCNT_TYPE_TRAP,
381 1.4.2.2 rmind &ci->ci_ev_udsi, xname, "user DSI failures");
382 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_kisi, EVCNT_TYPE_TRAP,
383 1.4.2.2 rmind &ci->ci_ev_traps, xname, "kernel ISI traps");
384 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_isi, EVCNT_TYPE_TRAP,
385 1.4.2.2 rmind &ci->ci_ev_traps, xname, "user ISI traps");
386 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_isi_fatal, EVCNT_TYPE_TRAP,
387 1.4.2.2 rmind &ci->ci_ev_isi, xname, "user ISI failures");
388 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_scalls, EVCNT_TYPE_TRAP,
389 1.4.2.2 rmind &ci->ci_ev_traps, xname, "system call traps");
390 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_pgm, EVCNT_TYPE_TRAP,
391 1.4.2.2 rmind &ci->ci_ev_traps, xname, "PGM traps");
392 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_debug, EVCNT_TYPE_TRAP,
393 1.4.2.2 rmind &ci->ci_ev_traps, xname, "debug traps");
394 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_fpu, EVCNT_TYPE_TRAP,
395 1.4.2.2 rmind &ci->ci_ev_traps, xname, "FPU unavailable traps");
396 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_fpusw, EVCNT_TYPE_MISC,
397 1.4.2.2 rmind &ci->ci_ev_fpu, xname, "FPU context switches");
398 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_ali, EVCNT_TYPE_TRAP,
399 1.4.2.2 rmind &ci->ci_ev_traps, xname, "user alignment traps");
400 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_ali_fatal, EVCNT_TYPE_TRAP,
401 1.4.2.2 rmind &ci->ci_ev_ali, xname, "user alignment traps");
402 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_umchk, EVCNT_TYPE_TRAP,
403 1.4.2.2 rmind &ci->ci_ev_umchk, xname, "user MCHK failures");
404 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_vec, EVCNT_TYPE_TRAP,
405 1.4.2.2 rmind &ci->ci_ev_traps, xname, "SPE unavailable");
406 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_vecsw, EVCNT_TYPE_MISC,
407 1.4.2.2 rmind &ci->ci_ev_vec, xname, "SPE context switches");
408 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_ipi, EVCNT_TYPE_INTR,
409 1.4.2.2 rmind NULL, xname, "IPIs");
410 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_tlbmiss_soft, EVCNT_TYPE_TRAP,
411 1.4.2.2 rmind &ci->ci_ev_traps, xname, "soft tlb misses");
412 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_dtlbmiss_hard, EVCNT_TYPE_TRAP,
413 1.4.2.2 rmind &ci->ci_ev_traps, xname, "data tlb misses");
414 1.4.2.2 rmind evcnt_attach_dynamic_nozero(&ci->ci_ev_itlbmiss_hard, EVCNT_TYPE_TRAP,
415 1.4.2.2 rmind &ci->ci_ev_traps, xname, "inst tlb misses");
416 1.4.2.2 rmind }
417 1.4.2.2 rmind
418 1.4.2.2 rmind uint32_t
419 1.4.2.2 rmind cpu_read_4(bus_addr_t a)
420 1.4.2.2 rmind {
421 1.4.2.2 rmind struct cpu_softc * const cpu = curcpu()->ci_softc;
422 1.4.2.2 rmind // printf(" %s(%p, %x, %x)", __func__, cpu->cpu_bst, cpu->cpu_bsh, a);
423 1.4.2.2 rmind return bus_space_read_4(cpu->cpu_bst, cpu->cpu_bsh, a);
424 1.4.2.2 rmind }
425 1.4.2.2 rmind
426 1.4.2.2 rmind uint8_t
427 1.4.2.2 rmind cpu_read_1(bus_addr_t a)
428 1.4.2.2 rmind {
429 1.4.2.2 rmind struct cpu_softc * const cpu = curcpu()->ci_softc;
430 1.4.2.2 rmind // printf(" %s(%p, %x, %x)", __func__, cpu->cpu_bst, cpu->cpu_bsh, a);
431 1.4.2.2 rmind return bus_space_read_1(cpu->cpu_bst, cpu->cpu_bsh, a);
432 1.4.2.2 rmind }
433 1.4.2.2 rmind
434 1.4.2.2 rmind void
435 1.4.2.2 rmind cpu_write_4(bus_addr_t a, uint32_t v)
436 1.4.2.2 rmind {
437 1.4.2.2 rmind struct cpu_softc * const cpu = curcpu()->ci_softc;
438 1.4.2.2 rmind bus_space_write_4(cpu->cpu_bst, cpu->cpu_bsh, a, v);
439 1.4.2.2 rmind }
440 1.4.2.2 rmind
441 1.4.2.2 rmind void
442 1.4.2.2 rmind cpu_write_1(bus_addr_t a, uint8_t v)
443 1.4.2.2 rmind {
444 1.4.2.2 rmind struct cpu_softc * const cpu = curcpu()->ci_softc;
445 1.4.2.2 rmind bus_space_write_1(cpu->cpu_bst, cpu->cpu_bsh, a, v);
446 1.4.2.2 rmind }
447 1.4.2.2 rmind
448 1.4.2.2 rmind void
449 1.4.2.2 rmind booke_sstep(struct trapframe *tf)
450 1.4.2.2 rmind {
451 1.4.2.2 rmind KASSERT(tf->tf_srr1 & PSL_DE);
452 1.4.2.2 rmind const uint32_t insn = ufetch_32((const void *)tf->tf_srr0);
453 1.4.2.2 rmind register_t dbcr0 = DBCR0_IAC1 | DBCR0_IDM;
454 1.4.2.2 rmind register_t dbcr1 = DBCR1_IAC1US_USER | DBCR1_IAC1ER_DS1;
455 1.4.2.2 rmind if ((insn >> 28) == 4) {
456 1.4.2.2 rmind uint32_t iac2 = 0;
457 1.4.2.2 rmind if ((insn >> 26) == 0x12) {
458 1.4.2.2 rmind const int32_t off = (((int32_t)insn << 6) >> 6) & ~3;
459 1.4.2.2 rmind iac2 = ((insn & 2) ? 0 : tf->tf_srr0) + off;
460 1.4.2.2 rmind dbcr0 |= DBCR0_IAC2;
461 1.4.2.2 rmind } else if ((insn >> 26) == 0x10) {
462 1.4.2.2 rmind const int16_t off = insn & ~3;
463 1.4.2.2 rmind iac2 = ((insn & 2) ? 0 : tf->tf_srr0) + off;
464 1.4.2.2 rmind dbcr0 |= DBCR0_IAC2;
465 1.4.2.2 rmind } else if ((insn & 0xfc00ffde) == 0x4c000420) {
466 1.4.2.2 rmind iac2 = tf->tf_ctr;
467 1.4.2.2 rmind dbcr0 |= DBCR0_IAC2;
468 1.4.2.2 rmind } else if ((insn & 0xfc00ffde) == 0x4c000020) {
469 1.4.2.2 rmind iac2 = tf->tf_lr;
470 1.4.2.2 rmind dbcr0 |= DBCR0_IAC2;
471 1.4.2.2 rmind }
472 1.4.2.2 rmind if (dbcr0 & DBCR0_IAC2) {
473 1.4.2.2 rmind dbcr1 |= DBCR1_IAC2US_USER | DBCR1_IAC2ER_DS1;
474 1.4.2.2 rmind mtspr(SPR_IAC2, iac2);
475 1.4.2.2 rmind }
476 1.4.2.2 rmind }
477 1.4.2.2 rmind mtspr(SPR_IAC1, tf->tf_srr0 + 4);
478 1.4.2.2 rmind mtspr(SPR_DBCR1, dbcr1);
479 1.4.2.2 rmind mtspr(SPR_DBCR0, dbcr0);
480 1.4.2.2 rmind }
481