1/*- 2 * Copyright (C) 2006-2012 Semihalf 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 ``AS IS'' AND ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 17 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 19 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 21 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 22 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25/*- 26 * Copyright (C) 2001 Benno Rice 27 * All rights reserved. 28 * 29 * Redistribution and use in source and binary forms, with or without 30 * modification, are permitted provided that the following conditions 31 * are met: 32 * 1. Redistributions of source code must retain the above copyright 33 * notice, this list of conditions and the following disclaimer. 34 * 2. Redistributions in binary form must reproduce the above copyright 35 * notice, this list of conditions and the following disclaimer in the 36 * documentation and/or other materials provided with the distribution. 37 * 38 * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR 39 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 40 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 41 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 43 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 44 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 45 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 46 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 47 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 48 * $NetBSD: machdep.c,v 1.74.2.1 2000/11/01 16:13:48 tv Exp $ 49 */ 50/*- 51 * Copyright (C) 1995, 1996 Wolfgang Solfrank. 52 * Copyright (C) 1995, 1996 TooLs GmbH. 53 * All rights reserved. 54 * 55 * Redistribution and use in source and binary forms, with or without 56 * modification, are permitted provided that the following conditions 57 * are met: 58 * 1. Redistributions of source code must retain the above copyright 59 * notice, this list of conditions and the following disclaimer. 60 * 2. Redistributions in binary form must reproduce the above copyright 61 * notice, this list of conditions and the following disclaimer in the 62 * documentation and/or other materials provided with the distribution. 63 * 3. All advertising materials mentioning features or use of this software 64 * must display the following acknowledgement: 65 * This product includes software developed by TooLs GmbH. 66 * 4. The name of TooLs GmbH may not be used to endorse or promote products 67 * derived from this software without specific prior written permission. 68 * 69 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 70 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 71 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 72 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 73 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 74 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 75 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 76 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 77 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 78 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 79 */ 80 81#include <sys/cdefs.h>
| 1/*- 2 * Copyright (C) 2006-2012 Semihalf 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 ``AS IS'' AND ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 17 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 19 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 21 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 22 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25/*- 26 * Copyright (C) 2001 Benno Rice 27 * All rights reserved. 28 * 29 * Redistribution and use in source and binary forms, with or without 30 * modification, are permitted provided that the following conditions 31 * are met: 32 * 1. Redistributions of source code must retain the above copyright 33 * notice, this list of conditions and the following disclaimer. 34 * 2. Redistributions in binary form must reproduce the above copyright 35 * notice, this list of conditions and the following disclaimer in the 36 * documentation and/or other materials provided with the distribution. 37 * 38 * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR 39 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 40 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 41 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 43 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 44 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 45 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 46 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 47 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 48 * $NetBSD: machdep.c,v 1.74.2.1 2000/11/01 16:13:48 tv Exp $ 49 */ 50/*- 51 * Copyright (C) 1995, 1996 Wolfgang Solfrank. 52 * Copyright (C) 1995, 1996 TooLs GmbH. 53 * All rights reserved. 54 * 55 * Redistribution and use in source and binary forms, with or without 56 * modification, are permitted provided that the following conditions 57 * are met: 58 * 1. Redistributions of source code must retain the above copyright 59 * notice, this list of conditions and the following disclaimer. 60 * 2. Redistributions in binary form must reproduce the above copyright 61 * notice, this list of conditions and the following disclaimer in the 62 * documentation and/or other materials provided with the distribution. 63 * 3. All advertising materials mentioning features or use of this software 64 * must display the following acknowledgement: 65 * This product includes software developed by TooLs GmbH. 66 * 4. The name of TooLs GmbH may not be used to endorse or promote products 67 * derived from this software without specific prior written permission. 68 * 69 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 70 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 71 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 72 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 73 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 74 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 75 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 76 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 77 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 78 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 79 */ 80 81#include <sys/cdefs.h>
|
82__FBSDID("$FreeBSD: head/sys/powerpc/booke/booke_machdep.c 292073 2015-12-11 01:34:13Z jhibbits $");
| 82__FBSDID("$FreeBSD: head/sys/powerpc/booke/booke_machdep.c 292903 2015-12-30 03:43:25Z jhibbits $");
|
83 84#include "opt_compat.h" 85#include "opt_ddb.h" 86#include "opt_hwpmc_hooks.h" 87#include "opt_kstack_pages.h" 88#include "opt_platform.h" 89 90#include <sys/cdefs.h> 91#include <sys/types.h> 92#include <sys/param.h> 93#include <sys/proc.h> 94#include <sys/systm.h> 95#include <sys/time.h> 96#include <sys/bio.h> 97#include <sys/buf.h> 98#include <sys/bus.h> 99#include <sys/cons.h> 100#include <sys/cpu.h> 101#include <sys/kdb.h> 102#include <sys/kernel.h> 103#include <sys/lock.h> 104#include <sys/mutex.h> 105#include <sys/rwlock.h> 106#include <sys/sysctl.h> 107#include <sys/exec.h> 108#include <sys/ktr.h> 109#include <sys/syscallsubr.h> 110#include <sys/sysproto.h> 111#include <sys/signalvar.h> 112#include <sys/sysent.h> 113#include <sys/imgact.h> 114#include <sys/msgbuf.h> 115#include <sys/ptrace.h> 116 117#include <vm/vm.h> 118#include <vm/pmap.h> 119#include <vm/vm_page.h> 120#include <vm/vm_object.h> 121#include <vm/vm_pager.h> 122 123#include <machine/cpu.h> 124#include <machine/kdb.h> 125#include <machine/reg.h> 126#include <machine/vmparam.h> 127#include <machine/spr.h> 128#include <machine/hid.h> 129#include <machine/psl.h> 130#include <machine/trap.h> 131#include <machine/md_var.h> 132#include <machine/mmuvar.h> 133#include <machine/sigframe.h> 134#include <machine/machdep.h> 135#include <machine/metadata.h> 136#include <machine/platform.h> 137 138#include <sys/linker.h> 139#include <sys/reboot.h> 140 141#include <contrib/libfdt/libfdt.h> 142#include <dev/fdt/fdt_common.h> 143#include <dev/ofw/openfirm.h> 144 145#if defined(MPC85XX) || defined(QORIQ_DPAA) 146#include <powerpc/mpc85xx/mpc85xx.h> 147#endif 148 149#ifdef DDB 150#include <ddb/ddb.h> 151#endif 152 153#ifdef DEBUG 154#define debugf(fmt, args...) printf(fmt, ##args) 155#else 156#define debugf(fmt, args...) 157#endif 158 159extern unsigned char kernel_text[]; 160extern unsigned char _etext[]; 161extern unsigned char _edata[]; 162extern unsigned char __bss_start[]; 163extern unsigned char __sbss_start[]; 164extern unsigned char __sbss_end[]; 165extern unsigned char _end[]; 166extern vm_offset_t __endkernel; 167 168/* 169 * Bootinfo is passed to us by legacy loaders. Save the address of the 170 * structure to handle backward compatibility. 171 */ 172uint32_t *bootinfo; 173 174void print_kernel_section_addr(void); 175void print_kenv(void); 176uintptr_t booke_init(uint32_t, uint32_t); 177void ivor_setup(void); 178 179extern void *interrupt_vector_base; 180extern void *int_critical_input; 181extern void *int_machine_check; 182extern void *int_data_storage; 183extern void *int_instr_storage; 184extern void *int_external_input; 185extern void *int_alignment; 186extern void *int_fpu; 187extern void *int_program; 188extern void *int_syscall; 189extern void *int_decrementer; 190extern void *int_fixed_interval_timer; 191extern void *int_watchdog; 192extern void *int_data_tlb_error; 193extern void *int_inst_tlb_error; 194extern void *int_debug; 195extern void *int_vec; 196extern void *int_vecast; 197#ifdef HWPMC_HOOKS 198extern void *int_performance_counter; 199#endif 200 201#define SET_TRAP(ivor, handler) \ 202 KASSERT(((uintptr_t)(&handler) & ~0xffffUL) == \ 203 ((uintptr_t)(&interrupt_vector_base) & ~0xffffUL), \ 204 ("Handler " #handler " too far from interrupt vector base")); \ 205 mtspr(ivor, (uintptr_t)(&handler) & 0xffffUL); 206 207uintptr_t powerpc_init(vm_offset_t fdt, vm_offset_t, vm_offset_t, void *mdp); 208void booke_cpu_init(void); 209 210void 211booke_cpu_init(void) 212{ 213 214 pmap_mmu_install(MMU_TYPE_BOOKE, BUS_PROBE_GENERIC); 215} 216 217void 218ivor_setup(void) 219{ 220 221 mtspr(SPR_IVPR, ((uintptr_t)&interrupt_vector_base) & 0xffff0000); 222 223 SET_TRAP(SPR_IVOR0, int_critical_input); 224 SET_TRAP(SPR_IVOR1, int_machine_check); 225 SET_TRAP(SPR_IVOR2, int_data_storage); 226 SET_TRAP(SPR_IVOR3, int_instr_storage); 227 SET_TRAP(SPR_IVOR4, int_external_input); 228 SET_TRAP(SPR_IVOR5, int_alignment); 229 SET_TRAP(SPR_IVOR6, int_program); 230 SET_TRAP(SPR_IVOR8, int_syscall); 231 SET_TRAP(SPR_IVOR10, int_decrementer); 232 SET_TRAP(SPR_IVOR11, int_fixed_interval_timer); 233 SET_TRAP(SPR_IVOR12, int_watchdog); 234 SET_TRAP(SPR_IVOR13, int_data_tlb_error); 235 SET_TRAP(SPR_IVOR14, int_inst_tlb_error); 236 SET_TRAP(SPR_IVOR15, int_debug); 237#ifdef HWPMC_HOOKS 238 SET_TRAP(SPR_IVOR35, int_performance_counter); 239#endif 240 switch ((mfpvr() >> 16) & 0xffff) { 241 case FSL_E6500: 242 SET_TRAP(SPR_IVOR32, int_vec); 243 SET_TRAP(SPR_IVOR33, int_vecast); 244 /* FALLTHROUGH */ 245 case FSL_E500mc: 246 case FSL_E5500: 247 SET_TRAP(SPR_IVOR7, int_fpu); 248 } 249} 250 251static int 252booke_check_for_fdt(uint32_t arg1, vm_offset_t *dtbp) 253{ 254 void *ptr; 255 256 if (arg1 % 8 != 0) 257 return (-1); 258 259 ptr = (void *)pmap_early_io_map(arg1, PAGE_SIZE); 260 if (fdt_check_header(ptr) != 0) 261 return (-1); 262 263 *dtbp = (vm_offset_t)ptr; 264 265 return (0); 266} 267 268uintptr_t 269booke_init(uint32_t arg1, uint32_t arg2) 270{ 271 uintptr_t ret; 272 void *mdp; 273 vm_offset_t dtbp, end; 274 275 end = (uintptr_t)_end; 276 dtbp = (vm_offset_t)NULL; 277 278 /* Set up TLB initially */ 279 bootinfo = NULL; 280 bzero(__sbss_start, __sbss_end - __sbss_start); 281 bzero(__bss_start, _end - __bss_start); 282 tlb1_init(); 283 284 /* 285 * Handle the various ways we can get loaded and started: 286 * - FreeBSD's loader passes the pointer to the metadata 287 * in arg1, with arg2 undefined. arg1 has a value that's 288 * relative to the kernel's link address (i.e. larger 289 * than 0xc0000000). 290 * - Juniper's loader passes the metadata pointer in arg2 291 * and sets arg1 to zero. This is to signal that the 292 * loader maps the kernel and starts it at its link 293 * address (unlike the FreeBSD loader). 294 * - U-Boot passes the standard argc and argv parameters 295 * in arg1 and arg2 (resp). arg1 is between 1 and some 296 * relatively small number, such as 64K. arg2 is the 297 * physical address of the argv vector. 298 * - ePAPR loaders pass an FDT blob in r3 (arg1) and the magic hex 299 * string 0x45504150 ('EPAP') in r6 (which has been lost by now). 300 * r4 (arg2) is supposed to be set to zero, but is not always. 301 */ 302 303 if (arg1 == 0) /* Juniper loader */ 304 mdp = (void *)arg2; 305 else if (booke_check_for_fdt(arg1, &dtbp) == 0) { /* ePAPR */ 306 end = roundup(end, 8); 307 memmove((void *)end, (void *)dtbp, fdt_totalsize((void *)dtbp)); 308 dtbp = end; 309 end += fdt_totalsize((void *)dtbp); 310 __endkernel = end; 311 mdp = NULL; 312 } else if (arg1 > (uintptr_t)kernel_text) /* FreeBSD loader */ 313 mdp = (void *)arg1; 314 else /* U-Boot */ 315 mdp = NULL; 316 317 ret = powerpc_init(dtbp, 0, 0, mdp); 318
| 83 84#include "opt_compat.h" 85#include "opt_ddb.h" 86#include "opt_hwpmc_hooks.h" 87#include "opt_kstack_pages.h" 88#include "opt_platform.h" 89 90#include <sys/cdefs.h> 91#include <sys/types.h> 92#include <sys/param.h> 93#include <sys/proc.h> 94#include <sys/systm.h> 95#include <sys/time.h> 96#include <sys/bio.h> 97#include <sys/buf.h> 98#include <sys/bus.h> 99#include <sys/cons.h> 100#include <sys/cpu.h> 101#include <sys/kdb.h> 102#include <sys/kernel.h> 103#include <sys/lock.h> 104#include <sys/mutex.h> 105#include <sys/rwlock.h> 106#include <sys/sysctl.h> 107#include <sys/exec.h> 108#include <sys/ktr.h> 109#include <sys/syscallsubr.h> 110#include <sys/sysproto.h> 111#include <sys/signalvar.h> 112#include <sys/sysent.h> 113#include <sys/imgact.h> 114#include <sys/msgbuf.h> 115#include <sys/ptrace.h> 116 117#include <vm/vm.h> 118#include <vm/pmap.h> 119#include <vm/vm_page.h> 120#include <vm/vm_object.h> 121#include <vm/vm_pager.h> 122 123#include <machine/cpu.h> 124#include <machine/kdb.h> 125#include <machine/reg.h> 126#include <machine/vmparam.h> 127#include <machine/spr.h> 128#include <machine/hid.h> 129#include <machine/psl.h> 130#include <machine/trap.h> 131#include <machine/md_var.h> 132#include <machine/mmuvar.h> 133#include <machine/sigframe.h> 134#include <machine/machdep.h> 135#include <machine/metadata.h> 136#include <machine/platform.h> 137 138#include <sys/linker.h> 139#include <sys/reboot.h> 140 141#include <contrib/libfdt/libfdt.h> 142#include <dev/fdt/fdt_common.h> 143#include <dev/ofw/openfirm.h> 144 145#if defined(MPC85XX) || defined(QORIQ_DPAA) 146#include <powerpc/mpc85xx/mpc85xx.h> 147#endif 148 149#ifdef DDB 150#include <ddb/ddb.h> 151#endif 152 153#ifdef DEBUG 154#define debugf(fmt, args...) printf(fmt, ##args) 155#else 156#define debugf(fmt, args...) 157#endif 158 159extern unsigned char kernel_text[]; 160extern unsigned char _etext[]; 161extern unsigned char _edata[]; 162extern unsigned char __bss_start[]; 163extern unsigned char __sbss_start[]; 164extern unsigned char __sbss_end[]; 165extern unsigned char _end[]; 166extern vm_offset_t __endkernel; 167 168/* 169 * Bootinfo is passed to us by legacy loaders. Save the address of the 170 * structure to handle backward compatibility. 171 */ 172uint32_t *bootinfo; 173 174void print_kernel_section_addr(void); 175void print_kenv(void); 176uintptr_t booke_init(uint32_t, uint32_t); 177void ivor_setup(void); 178 179extern void *interrupt_vector_base; 180extern void *int_critical_input; 181extern void *int_machine_check; 182extern void *int_data_storage; 183extern void *int_instr_storage; 184extern void *int_external_input; 185extern void *int_alignment; 186extern void *int_fpu; 187extern void *int_program; 188extern void *int_syscall; 189extern void *int_decrementer; 190extern void *int_fixed_interval_timer; 191extern void *int_watchdog; 192extern void *int_data_tlb_error; 193extern void *int_inst_tlb_error; 194extern void *int_debug; 195extern void *int_vec; 196extern void *int_vecast; 197#ifdef HWPMC_HOOKS 198extern void *int_performance_counter; 199#endif 200 201#define SET_TRAP(ivor, handler) \ 202 KASSERT(((uintptr_t)(&handler) & ~0xffffUL) == \ 203 ((uintptr_t)(&interrupt_vector_base) & ~0xffffUL), \ 204 ("Handler " #handler " too far from interrupt vector base")); \ 205 mtspr(ivor, (uintptr_t)(&handler) & 0xffffUL); 206 207uintptr_t powerpc_init(vm_offset_t fdt, vm_offset_t, vm_offset_t, void *mdp); 208void booke_cpu_init(void); 209 210void 211booke_cpu_init(void) 212{ 213 214 pmap_mmu_install(MMU_TYPE_BOOKE, BUS_PROBE_GENERIC); 215} 216 217void 218ivor_setup(void) 219{ 220 221 mtspr(SPR_IVPR, ((uintptr_t)&interrupt_vector_base) & 0xffff0000); 222 223 SET_TRAP(SPR_IVOR0, int_critical_input); 224 SET_TRAP(SPR_IVOR1, int_machine_check); 225 SET_TRAP(SPR_IVOR2, int_data_storage); 226 SET_TRAP(SPR_IVOR3, int_instr_storage); 227 SET_TRAP(SPR_IVOR4, int_external_input); 228 SET_TRAP(SPR_IVOR5, int_alignment); 229 SET_TRAP(SPR_IVOR6, int_program); 230 SET_TRAP(SPR_IVOR8, int_syscall); 231 SET_TRAP(SPR_IVOR10, int_decrementer); 232 SET_TRAP(SPR_IVOR11, int_fixed_interval_timer); 233 SET_TRAP(SPR_IVOR12, int_watchdog); 234 SET_TRAP(SPR_IVOR13, int_data_tlb_error); 235 SET_TRAP(SPR_IVOR14, int_inst_tlb_error); 236 SET_TRAP(SPR_IVOR15, int_debug); 237#ifdef HWPMC_HOOKS 238 SET_TRAP(SPR_IVOR35, int_performance_counter); 239#endif 240 switch ((mfpvr() >> 16) & 0xffff) { 241 case FSL_E6500: 242 SET_TRAP(SPR_IVOR32, int_vec); 243 SET_TRAP(SPR_IVOR33, int_vecast); 244 /* FALLTHROUGH */ 245 case FSL_E500mc: 246 case FSL_E5500: 247 SET_TRAP(SPR_IVOR7, int_fpu); 248 } 249} 250 251static int 252booke_check_for_fdt(uint32_t arg1, vm_offset_t *dtbp) 253{ 254 void *ptr; 255 256 if (arg1 % 8 != 0) 257 return (-1); 258 259 ptr = (void *)pmap_early_io_map(arg1, PAGE_SIZE); 260 if (fdt_check_header(ptr) != 0) 261 return (-1); 262 263 *dtbp = (vm_offset_t)ptr; 264 265 return (0); 266} 267 268uintptr_t 269booke_init(uint32_t arg1, uint32_t arg2) 270{ 271 uintptr_t ret; 272 void *mdp; 273 vm_offset_t dtbp, end; 274 275 end = (uintptr_t)_end; 276 dtbp = (vm_offset_t)NULL; 277 278 /* Set up TLB initially */ 279 bootinfo = NULL; 280 bzero(__sbss_start, __sbss_end - __sbss_start); 281 bzero(__bss_start, _end - __bss_start); 282 tlb1_init(); 283 284 /* 285 * Handle the various ways we can get loaded and started: 286 * - FreeBSD's loader passes the pointer to the metadata 287 * in arg1, with arg2 undefined. arg1 has a value that's 288 * relative to the kernel's link address (i.e. larger 289 * than 0xc0000000). 290 * - Juniper's loader passes the metadata pointer in arg2 291 * and sets arg1 to zero. This is to signal that the 292 * loader maps the kernel and starts it at its link 293 * address (unlike the FreeBSD loader). 294 * - U-Boot passes the standard argc and argv parameters 295 * in arg1 and arg2 (resp). arg1 is between 1 and some 296 * relatively small number, such as 64K. arg2 is the 297 * physical address of the argv vector. 298 * - ePAPR loaders pass an FDT blob in r3 (arg1) and the magic hex 299 * string 0x45504150 ('EPAP') in r6 (which has been lost by now). 300 * r4 (arg2) is supposed to be set to zero, but is not always. 301 */ 302 303 if (arg1 == 0) /* Juniper loader */ 304 mdp = (void *)arg2; 305 else if (booke_check_for_fdt(arg1, &dtbp) == 0) { /* ePAPR */ 306 end = roundup(end, 8); 307 memmove((void *)end, (void *)dtbp, fdt_totalsize((void *)dtbp)); 308 dtbp = end; 309 end += fdt_totalsize((void *)dtbp); 310 __endkernel = end; 311 mdp = NULL; 312 } else if (arg1 > (uintptr_t)kernel_text) /* FreeBSD loader */ 313 mdp = (void *)arg1; 314 else /* U-Boot */ 315 mdp = NULL; 316 317 ret = powerpc_init(dtbp, 0, 0, mdp); 318
|
319 /* Enable L1 caches */
| 319 /* Default to 32 byte cache line size. */ 320 switch ((mfpvr()) >> 16) { 321 case FSL_E500mc: 322 case FSL_E5500: 323 case FSL_E6500: 324 cacheline_size = 64; 325 break; 326 } 327 328 /* Enable caches */
|
320 booke_enable_l1_cache();
| 329 booke_enable_l1_cache();
|
| 330 booke_enable_l2_cache();
|
321
| 331
|
| 332 booke_enable_bpred(); 333
|
322 return (ret); 323} 324 325#define RES_GRANULE 32 326extern uint32_t tlb0_miss_locks[]; 327 328/* Initialise a struct pcpu. */ 329void 330cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t sz) 331{ 332 333 pcpu->pc_tid_next = TID_MIN; 334 335#ifdef SMP 336 uint32_t *ptr; 337 int words_per_gran = RES_GRANULE / sizeof(uint32_t); 338 339 ptr = &tlb0_miss_locks[cpuid * words_per_gran]; 340 pcpu->pc_booke_tlb_lock = ptr; 341 *ptr = TLB_UNLOCKED; 342 *(ptr + 1) = 0; /* recurse counter */ 343#endif 344} 345 346/* Shutdown the CPU as much as possible. */ 347void 348cpu_halt(void) 349{ 350 351 mtmsr(mfmsr() & ~(PSL_CE | PSL_EE | PSL_ME | PSL_DE)); 352 while (1) 353 ; 354} 355 356int 357ptrace_single_step(struct thread *td) 358{ 359 struct trapframe *tf; 360 361 tf = td->td_frame; 362 tf->srr1 |= PSL_DE; 363 tf->cpu.booke.dbcr0 |= (DBCR0_IDM | DBCR0_IC); 364 return (0); 365} 366 367int 368ptrace_clear_single_step(struct thread *td) 369{ 370 struct trapframe *tf; 371 372 tf = td->td_frame; 373 tf->srr1 &= ~PSL_DE; 374 tf->cpu.booke.dbcr0 &= ~(DBCR0_IDM | DBCR0_IC); 375 return (0); 376} 377 378void 379kdb_cpu_clear_singlestep(void) 380{ 381 register_t r; 382 383 r = mfspr(SPR_DBCR0); 384 mtspr(SPR_DBCR0, r & ~DBCR0_IC); 385 kdb_frame->srr1 &= ~PSL_DE; 386} 387 388void 389kdb_cpu_set_singlestep(void) 390{ 391 register_t r; 392 393 r = mfspr(SPR_DBCR0); 394 mtspr(SPR_DBCR0, r | DBCR0_IC | DBCR0_IDM); 395 kdb_frame->srr1 |= PSL_DE; 396} 397
| 334 return (ret); 335} 336 337#define RES_GRANULE 32 338extern uint32_t tlb0_miss_locks[]; 339 340/* Initialise a struct pcpu. */ 341void 342cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t sz) 343{ 344 345 pcpu->pc_tid_next = TID_MIN; 346 347#ifdef SMP 348 uint32_t *ptr; 349 int words_per_gran = RES_GRANULE / sizeof(uint32_t); 350 351 ptr = &tlb0_miss_locks[cpuid * words_per_gran]; 352 pcpu->pc_booke_tlb_lock = ptr; 353 *ptr = TLB_UNLOCKED; 354 *(ptr + 1) = 0; /* recurse counter */ 355#endif 356} 357 358/* Shutdown the CPU as much as possible. */ 359void 360cpu_halt(void) 361{ 362 363 mtmsr(mfmsr() & ~(PSL_CE | PSL_EE | PSL_ME | PSL_DE)); 364 while (1) 365 ; 366} 367 368int 369ptrace_single_step(struct thread *td) 370{ 371 struct trapframe *tf; 372 373 tf = td->td_frame; 374 tf->srr1 |= PSL_DE; 375 tf->cpu.booke.dbcr0 |= (DBCR0_IDM | DBCR0_IC); 376 return (0); 377} 378 379int 380ptrace_clear_single_step(struct thread *td) 381{ 382 struct trapframe *tf; 383 384 tf = td->td_frame; 385 tf->srr1 &= ~PSL_DE; 386 tf->cpu.booke.dbcr0 &= ~(DBCR0_IDM | DBCR0_IC); 387 return (0); 388} 389 390void 391kdb_cpu_clear_singlestep(void) 392{ 393 register_t r; 394 395 r = mfspr(SPR_DBCR0); 396 mtspr(SPR_DBCR0, r & ~DBCR0_IC); 397 kdb_frame->srr1 &= ~PSL_DE; 398} 399 400void 401kdb_cpu_set_singlestep(void) 402{ 403 register_t r; 404 405 r = mfspr(SPR_DBCR0); 406 mtspr(SPR_DBCR0, r | DBCR0_IC | DBCR0_IDM); 407 kdb_frame->srr1 |= PSL_DE; 408} 409
|