1 /* $NetBSD: kloader_machdep.c,v 1.3 2021/08/17 22:00:29 andvar Exp $ */
2
3 /*-
4 * Copyright (C) 2012 NONAKA Kimihiro <nonaka@netbsd.org>
5 * 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 BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: kloader_machdep.c,v 1.3 2021/08/17 22:00:29 andvar Exp $");
30
31 #include "debug_kloader.h"
32 #include "opt_cputypes.h"
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/device.h>
37
38 #include <machine/kloader.h>
39 #include <machine/pmap.h>
40
41 #include <arm/cpufunc.h>
42 #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
43 #include <arm/xscale/pxa2x0reg.h>
44 #endif
45
46 kloader_jumpfunc_t kloader_hpcarm_jump __attribute__((__noreturn__));
47 void kloader_hpcarm_reset(void);
48 #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
49 kloader_bootfunc_t kloader_pxa2x0_boot __attribute__((__noreturn__));
50 #endif
51
52 struct kloader_ops kloader_hpcarm_ops = {
53 .jump = kloader_hpcarm_jump,
54 #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
55 .boot = kloader_pxa2x0_boot,
56 #endif
57 .reset = kloader_hpcarm_reset,
58 };
59
60 void
kloader_reboot_setup(const char * filename)61 kloader_reboot_setup(const char *filename)
62 {
63
64 __kloader_reboot_setup(&kloader_hpcarm_ops, filename);
65 }
66
67 void
kloader_hpcarm_reset(void)68 kloader_hpcarm_reset(void)
69 {
70 extern void (*__cpu_reset)(void) __dead;
71
72 __cpu_reset();
73 /*NOTREACHED*/
74 }
75
76 void
kloader_hpcarm_jump(kloader_bootfunc_t func,vaddr_t sp,struct kloader_bootinfo * kbi,struct kloader_page_tag * tag)77 kloader_hpcarm_jump(kloader_bootfunc_t func, vaddr_t sp,
78 struct kloader_bootinfo *kbi, struct kloader_page_tag *tag)
79 {
80
81 disable_interrupts(I32_bit|F32_bit);
82 cpu_idcache_wbinv_all();
83
84 /* jump to 2nd boot-loader */
85 (*func)(kbi, tag);
86 __builtin_unreachable();
87 }
88
89 /*
90 * Physical address to virtual address
91 */
92 vaddr_t
kloader_phystov(paddr_t pa)93 kloader_phystov(paddr_t pa)
94 {
95 vaddr_t va;
96 int error;
97
98 #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
99 va = KERNEL_BASE + pa - PXA2X0_SDRAM0_START;
100 #else
101 #error No support KLOADER with specific CPU type.
102 #endif
103 error = pmap_enter(pmap_kernel(), va, pa, VM_PROT_ALL, 0);
104 if (error) {
105 printf("%s: map failed: pa=0x%lx, va=0x%lx, error=%d\n",
106 __func__, pa, va, error);
107 }
108 return va;
109 }
110