exynos_platform.c revision 1.18 1 1.18 skrll /* $NetBSD: exynos_platform.c,v 1.18 2018/10/08 08:17:00 skrll Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.1 jmcneill * Copyright (c) 2017 Jared D. McNeill <jmcneill (at) invisible.ca>
5 1.1 jmcneill * All rights reserved.
6 1.1 jmcneill *
7 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
8 1.1 jmcneill * modification, are permitted provided that the following conditions
9 1.1 jmcneill * are met:
10 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
11 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
12 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
14 1.1 jmcneill * documentation and/or other materials provided with the distribution.
15 1.1 jmcneill *
16 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 jmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 jmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 jmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 jmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1 jmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1 jmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1 jmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1 jmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 jmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 jmcneill * SUCH DAMAGE.
27 1.1 jmcneill */
28 1.1 jmcneill
29 1.11 skrll #include "opt_arm_debug.h"
30 1.17 skrll #include "opt_console.h"
31 1.1 jmcneill #include "opt_exynos.h"
32 1.1 jmcneill #include "opt_multiprocessor.h"
33 1.17 skrll #include "opt_console.h"
34 1.1 jmcneill
35 1.1 jmcneill #include "ukbd.h"
36 1.1 jmcneill
37 1.1 jmcneill #include <sys/cdefs.h>
38 1.18 skrll __KERNEL_RCSID(0, "$NetBSD: exynos_platform.c,v 1.18 2018/10/08 08:17:00 skrll Exp $");
39 1.1 jmcneill
40 1.1 jmcneill #include <sys/param.h>
41 1.1 jmcneill #include <sys/bus.h>
42 1.1 jmcneill #include <sys/cpu.h>
43 1.1 jmcneill #include <sys/device.h>
44 1.1 jmcneill #include <sys/termios.h>
45 1.1 jmcneill
46 1.1 jmcneill #include <dev/fdt/fdtvar.h>
47 1.1 jmcneill
48 1.1 jmcneill #include <uvm/uvm_extern.h>
49 1.1 jmcneill
50 1.1 jmcneill #include <machine/bootconfig.h>
51 1.1 jmcneill #include <arm/cpufunc.h>
52 1.1 jmcneill
53 1.1 jmcneill #include <arm/samsung/exynos_reg.h>
54 1.1 jmcneill #include <arm/samsung/exynos_var.h>
55 1.10 jmcneill #include <arm/samsung/mct_var.h>
56 1.13 skrll #include <arm/samsung/sscom_reg.h>
57 1.1 jmcneill
58 1.2 jmcneill #include <evbarm/exynos/platform.h>
59 1.2 jmcneill
60 1.1 jmcneill #include <arm/fdt/arm_fdtvar.h>
61 1.1 jmcneill
62 1.13 skrll void exynos_platform_early_putchar(char);
63 1.13 skrll
64 1.6 jmcneill #define EXYNOS5_SWRESET_REG 0x10040400
65 1.6 jmcneill
66 1.2 jmcneill #define EXYNOS_IOPHYSTOVIRT(a) \
67 1.2 jmcneill ((vaddr_t)(((a) - EXYNOS_CORE_PBASE) + EXYNOS_CORE_VBASE))
68 1.2 jmcneill
69 1.15 jmcneill #define EXYNOS5800_PMU_BASE 0x10040000
70 1.15 jmcneill #define EXYNOS5800_PMU_SIZE 0x20000
71 1.15 jmcneill #define EXYNOS5800_PMU_CORE_CONFIG(n) (0x2000 + 0x80 * (n))
72 1.15 jmcneill #define EXYNOS5800_PMU_CORE_STATUS(n) (0x2004 + 0x80 * (n))
73 1.15 jmcneill #define EXYNOS5800_PMU_CORE_POWER_EN 0x3
74 1.15 jmcneill #define EXYNOS5800_SYSRAM_BASE 0x0207301c
75 1.15 jmcneill #define EXYNOS5800_SYSRAM_SIZE 0x4
76 1.15 jmcneill
77 1.15 jmcneill static void
78 1.15 jmcneill exynos5800_mp_bootstrap(void)
79 1.15 jmcneill {
80 1.15 jmcneill #if defined(MULTIPROCESSOR)
81 1.15 jmcneill extern void cortex_mpstart(void);
82 1.15 jmcneill bus_space_tag_t bst = &armv7_generic_bs_tag;
83 1.15 jmcneill bus_space_handle_t pmu_bsh, sysram_bsh;
84 1.15 jmcneill uint32_t val, started = 0;
85 1.15 jmcneill int n;
86 1.15 jmcneill
87 1.15 jmcneill arm_cpu_max = 1 + __SHIFTOUT(armreg_l2ctrl_read(), L2CTRL_NUMCPU);
88 1.15 jmcneill
89 1.15 jmcneill bus_space_map(bst, EXYNOS5800_PMU_BASE, EXYNOS5800_PMU_SIZE, 0, &pmu_bsh);
90 1.15 jmcneill bus_space_map(bst, EXYNOS5800_SYSRAM_BASE, EXYNOS5800_SYSRAM_SIZE, 0, &sysram_bsh);
91 1.15 jmcneill
92 1.15 jmcneill bus_space_write_4(bst, sysram_bsh, 0, (uint32_t)cortex_mpstart);
93 1.15 jmcneill bus_space_barrier(bst, sysram_bsh, 0, 4, BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE);
94 1.15 jmcneill
95 1.15 jmcneill for (n = 1; n < arm_cpu_max; n++) {
96 1.15 jmcneill bus_space_write_4(bst, pmu_bsh, EXYNOS5800_PMU_CORE_CONFIG(n),
97 1.15 jmcneill EXYNOS5800_PMU_CORE_POWER_EN);
98 1.15 jmcneill for (u_int i = 0x01000000; i > 0; i--) {
99 1.15 jmcneill val = bus_space_read_4(bst, pmu_bsh, EXYNOS5800_PMU_CORE_STATUS(n));
100 1.15 jmcneill if ((val & EXYNOS5800_PMU_CORE_POWER_EN) == EXYNOS5800_PMU_CORE_POWER_EN) {
101 1.15 jmcneill started |= __BIT(n);
102 1.15 jmcneill break;
103 1.15 jmcneill }
104 1.15 jmcneill }
105 1.15 jmcneill }
106 1.15 jmcneill
107 1.15 jmcneill for (u_int i = 0x10000000; i > 0; i--) {
108 1.15 jmcneill arm_dmb();
109 1.15 jmcneill if (arm_cpu_hatched == started)
110 1.15 jmcneill break;
111 1.15 jmcneill }
112 1.15 jmcneill
113 1.15 jmcneill bus_space_unmap(bst, sysram_bsh, EXYNOS5800_SYSRAM_SIZE);
114 1.15 jmcneill bus_space_unmap(bst, pmu_bsh, EXYNOS5800_PMU_SIZE);
115 1.15 jmcneill #endif
116 1.15 jmcneill }
117 1.15 jmcneill
118 1.15 jmcneill static struct of_compat_data mp_compat_data[] = {
119 1.15 jmcneill { "samsung,exynos5800", (uintptr_t)exynos5800_mp_bootstrap },
120 1.15 jmcneill { NULL }
121 1.15 jmcneill };
122 1.15 jmcneill
123 1.1 jmcneill static void
124 1.1 jmcneill exynos_platform_bootstrap(void)
125 1.1 jmcneill {
126 1.13 skrll
127 1.15 jmcneill void (*mp_bootstrap)(void) = NULL;
128 1.15 jmcneill const struct of_compat_data *cd = of_search_compatible(OF_finddevice("/"), mp_compat_data);
129 1.15 jmcneill if (cd)
130 1.15 jmcneill mp_bootstrap = (void (*)(void))cd->data;
131 1.15 jmcneill
132 1.15 jmcneill if (mp_bootstrap)
133 1.15 jmcneill mp_bootstrap();
134 1.1 jmcneill }
135 1.1 jmcneill
136 1.1 jmcneill static void
137 1.1 jmcneill exynos_platform_init_attach_args(struct fdt_attach_args *faa)
138 1.1 jmcneill {
139 1.1 jmcneill extern struct bus_space armv7_generic_bs_tag;
140 1.1 jmcneill extern struct bus_space armv7_generic_a4x_bs_tag;
141 1.9 ryo extern struct arm32_bus_dma_tag arm_generic_dma_tag;
142 1.1 jmcneill
143 1.1 jmcneill faa->faa_bst = &armv7_generic_bs_tag;
144 1.1 jmcneill faa->faa_a4x_bst = &armv7_generic_a4x_bs_tag;
145 1.9 ryo faa->faa_dmat = &arm_generic_dma_tag;
146 1.1 jmcneill }
147 1.1 jmcneill
148 1.13 skrll
149 1.13 skrll void
150 1.1 jmcneill exynos_platform_early_putchar(char c)
151 1.1 jmcneill {
152 1.13 skrll #ifdef CONSADDR
153 1.13 skrll #define CONSADDR_VA (CONSADDR - EXYNOS_CORE_PBASE + EXYNOS_CORE_VBASE)
154 1.2 jmcneill
155 1.13 skrll volatile uint32_t *uartaddr = cpu_earlydevice_va_p() ?
156 1.13 skrll (volatile uint32_t *)CONSADDR_VA :
157 1.13 skrll (volatile uint32_t *)CONSADDR;
158 1.14 skrll
159 1.13 skrll while ((uartaddr[SSCOM_UFSTAT / 4] & UFSTAT_TXFULL) != 0)
160 1.13 skrll ;
161 1.13 skrll
162 1.13 skrll uartaddr[SSCOM_UTXH / 4] = c;
163 1.4 jmcneill #endif
164 1.1 jmcneill }
165 1.1 jmcneill
166 1.1 jmcneill static void
167 1.1 jmcneill exynos_platform_device_register(device_t self, void *aux)
168 1.1 jmcneill {
169 1.1 jmcneill exynos_device_register(self, aux);
170 1.1 jmcneill }
171 1.1 jmcneill
172 1.1 jmcneill static void
173 1.6 jmcneill exynos5_platform_reset(void)
174 1.1 jmcneill {
175 1.6 jmcneill bus_space_tag_t bst = &armv7_generic_bs_tag;
176 1.6 jmcneill bus_space_handle_t bsh;
177 1.6 jmcneill
178 1.6 jmcneill bus_space_map(bst, EXYNOS5_SWRESET_REG, 4, 0, &bsh);
179 1.6 jmcneill bus_space_write_4(bst, bsh, 0, 1);
180 1.1 jmcneill }
181 1.1 jmcneill
182 1.1 jmcneill static u_int
183 1.1 jmcneill exynos_platform_uart_freq(void)
184 1.1 jmcneill {
185 1.1 jmcneill return EXYNOS_UART_FREQ;
186 1.1 jmcneill }
187 1.1 jmcneill
188 1.13 skrll
189 1.13 skrll #if defined(SOC_EXYNOS4)
190 1.13 skrll static const struct pmap_devmap *
191 1.13 skrll exynos4_platform_devmap(void)
192 1.13 skrll {
193 1.13 skrll static const struct pmap_devmap devmap[] = {
194 1.13 skrll DEVMAP_ENTRY(EXYNOS_CORE_VBASE,
195 1.13 skrll EXYNOS_CORE_PBASE,
196 1.13 skrll EXYNOS4_CORE_SIZE),
197 1.13 skrll DEVMAP_ENTRY(EXYNOS4_AUDIOCORE_VBASE,
198 1.13 skrll EXYNOS4_AUDIOCORE_PBASE,
199 1.13 skrll EXYNOS4_AUDIOCORE_SIZE),
200 1.13 skrll DEVMAP_ENTRY_END
201 1.13 skrll };
202 1.13 skrll
203 1.13 skrll return devmap;
204 1.13 skrll }
205 1.13 skrll
206 1.18 skrll static void
207 1.18 skrll exynos4_platform_bootstrap(void)
208 1.18 skrll {
209 1.18 skrll
210 1.18 skrll exynos_bootstrap(4);
211 1.18 skrll
212 1.18 skrll exynos_platform_bootstrap();
213 1.18 skrll }
214 1.18 skrll
215 1.13 skrll static const struct arm_platform exynos4_platform = {
216 1.13 skrll .ap_devmap = exynos4_platform_devmap,
217 1.18 skrll .ap_bootstrap = exynos4_platform_bootstrap,
218 1.13 skrll .ap_init_attach_args = exynos_platform_init_attach_args,
219 1.13 skrll .ap_early_putchar = exynos_platform_early_putchar,
220 1.13 skrll .ap_device_register = exynos_platform_device_register,
221 1.13 skrll .ap_reset = exynos5_platform_reset,
222 1.13 skrll .ap_delay = mct_delay,
223 1.13 skrll .ap_uart_freq = exynos_platform_uart_freq,
224 1.13 skrll };
225 1.13 skrll
226 1.13 skrll ARM_PLATFORM(exynos4, "samsung,exynos4", &exynos4_platform);
227 1.13 skrll #endif
228 1.13 skrll
229 1.13 skrll
230 1.13 skrll #if defined(SOC_EXYNOS5)
231 1.13 skrll static const struct pmap_devmap *
232 1.13 skrll exynos5_platform_devmap(void)
233 1.13 skrll {
234 1.13 skrll static const struct pmap_devmap devmap[] = {
235 1.13 skrll DEVMAP_ENTRY(EXYNOS_CORE_VBASE,
236 1.13 skrll EXYNOS_CORE_PBASE,
237 1.13 skrll EXYNOS5_CORE_SIZE),
238 1.13 skrll DEVMAP_ENTRY(EXYNOS5_AUDIOCORE_VBASE,
239 1.13 skrll EXYNOS5_AUDIOCORE_PBASE,
240 1.13 skrll EXYNOS5_AUDIOCORE_SIZE),
241 1.15 jmcneill DEVMAP_ENTRY(EXYNOS5_SYSRAM_VBASE,
242 1.15 jmcneill EXYNOS5_SYSRAM_PBASE,
243 1.15 jmcneill EXYNOS5_SYSRAM_SIZE),
244 1.13 skrll DEVMAP_ENTRY_END
245 1.13 skrll };
246 1.13 skrll
247 1.13 skrll return devmap;
248 1.13 skrll }
249 1.13 skrll
250 1.18 skrll static void
251 1.18 skrll exynos5_platform_bootstrap(void)
252 1.18 skrll {
253 1.18 skrll
254 1.18 skrll exynos_bootstrap(5);
255 1.18 skrll
256 1.18 skrll exynos_platform_bootstrap();
257 1.18 skrll }
258 1.18 skrll
259 1.1 jmcneill static const struct arm_platform exynos5_platform = {
260 1.13 skrll .ap_devmap = exynos5_platform_devmap,
261 1.18 skrll .ap_bootstrap = exynos5_platform_bootstrap,
262 1.12 skrll .ap_init_attach_args = exynos_platform_init_attach_args,
263 1.12 skrll .ap_early_putchar = exynos_platform_early_putchar,
264 1.12 skrll .ap_device_register = exynos_platform_device_register,
265 1.12 skrll .ap_reset = exynos5_platform_reset,
266 1.12 skrll .ap_delay = mct_delay,
267 1.12 skrll .ap_uart_freq = exynos_platform_uart_freq,
268 1.1 jmcneill };
269 1.1 jmcneill
270 1.1 jmcneill ARM_PLATFORM(exynos5, "samsung,exynos5", &exynos5_platform);
271 1.13 skrll #endif
272