exynos_soc.c revision 1.4 1 /* $NetBSD: exynos_soc.c,v 1.4 2014/04/13 20:52:29 reinoud Exp $ */
2 /*-
3 * Copyright (c) 2014 The NetBSD Foundation, Inc.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Reinoud Zandijk.
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 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "opt_exynos.h"
32
33 #define _ARM32_BUS_DMA_PRIVATE
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(1, "$NetBSD: exynos_soc.c,v 1.4 2014/04/13 20:52:29 reinoud Exp $");
37
38 #include <sys/param.h>
39 #include <sys/bus.h>
40 #include <sys/cpu.h>
41 #include <sys/device.h>
42
43 #include <prop/proplib.h>
44
45 #include <net/if.h>
46 #include <net/if_ether.h>
47
48 #include <arm/locore.h>
49
50 #include <arm/mainbus/mainbus.h>
51 #include <arm/cortex/mpcore_var.h>
52
53 #include <arm/samsung/exynos_reg.h>
54 #include <arm/samsung/exynos_var.h>
55 #include <arm/samsung/smc.h>
56
57 #include <arm/cortex/pl310_var.h>
58 #include <arm/cortex/pl310_reg.h>
59
60 /* XXXNH */
61 #include <evbarm/odroid/platform.h>
62
63 bus_space_handle_t exynos_core_bsh;
64
65 /* these variables are retrieved in start.S and stored in .data */
66 uint32_t exynos_soc_id = 0;
67 uint32_t exynos_pop_id = 0;
68
69
70 /*
71 * the early serial console
72 */
73 #ifdef EXYNOS_CONSOLE_EARLY
74
75 #include "opt_sscom.h"
76 #include <arm/samsung/sscom_reg.h>
77 #include <arm/samsung/sscom_var.h>
78 #include <dev/cons.h>
79
80 static volatile uint8_t *uart_base;
81
82 #define CON_REG(a) (*((volatile uint32_t *)(uart_base + (a))))
83
84 static int
85 exynos_cngetc(dev_t dv)
86 {
87 if ((CON_REG(SSCOM_UTRSTAT) & UTRSTAT_RXREADY) == 0)
88 return -1;
89
90 return CON_REG(SSCOM_URXH);
91 }
92
93 static void
94 exynos_cnputc(dev_t dv, int c)
95 {
96 int timo = 150000;
97
98 while ((CON_REG(SSCOM_UFSTAT) & UFSTAT_TXFULL) && --timo > 0);
99
100 CON_REG(SSCOM_UTXH) = c & 0xff;
101 }
102
103 static struct consdev exynos_earlycons = {
104 .cn_putc = exynos_cnputc,
105 .cn_getc = exynos_cngetc,
106 .cn_pollc = nullcnpollc,
107 };
108 #endif /* EXYNOS_CONSOLE_EARLY */
109
110
111 #ifdef ARM_TRUSTZONE_FIRMWARE
112 int
113 exynos_do_idle(void)
114 {
115 exynos_smc(SMC_CMD_SLEEP, 0, 0, 0);
116
117 return 0;
118 }
119
120
121 int
122 exynos_set_cpu_boot_addr(int cpu, vaddr_t boot_addr)
123 {
124 /* XXX we need to map in iRAM space for this XXX */
125 return 0;
126 }
127
128
129 int
130 exynos_cpu_boot(int cpu)
131 {
132 exynos_smc(SMC_CMD_CPU1BOOT, cpu, 0, 0);
133
134 return 0;
135 }
136
137
138 /*
139 * The latency values used below are `magic' and probably chosen empiricaly.
140 * For the 4210 variant the data latency is lower, a 0x110. This is currently
141 * not enforced.
142 *
143 * The prefetch values are also different for the revision 0 of the
144 * Exynos4412, but why?
145 */
146
147 int
148 exynos_l2cc_init(void)
149 {
150 const uint32_t tag_latency = 0x110;
151 const uint32_t data_latency = IS_EXYNOS4410_P() ? 0x110 : 0x120;
152 const uint32_t prefetch4412 = /* 0111 0001 0000 0000 0000 0000 0000 0111 */
153 PREFETCHCTL_DBLLINEF_EN |
154 PREFETCHCTL_INSTRPREF_EN |
155 PREFETCHCTL_DATAPREF_EN |
156 PREFETCHCTL_PREF_DROP_EN |
157 PREFETCHCTL_PREFETCH_OFFSET_7;
158 const uint32_t prefetch4412_r0 = /* 0011 0000 0000 0000 0000 0000 0000 0111 */
159 PREFETCHCTL_INSTRPREF_EN |
160 PREFETCHCTL_DATAPREF_EN |
161 PREFETCHCTL_PREFETCH_OFFSET_7;
162 const uint32_t aux_val = /* 0111 1100 0100 0111 0000 0000 0000 0001 */
163 AUXCTL_EARLY_BRESP_EN |
164 AUXCTL_I_PREFETCH |
165 AUXCTL_D_PREFETCH |
166 AUXCTL_NS_INT_ACC_CTL |
167 AUXCTL_NS_INT_LOCK_EN |
168 AUXCTL_SHARED_ATT_OVR |
169 AUXCTL_WAY_SIZE_RSVD7 << 16 | /* why rsvd7 ??? */
170 AUXCTL_FULL_LINE_WR0;
171 const uint32_t aux_keepmask = /* 1100 0010 0000 0000 1111 1111 1111 1111 */
172 AUXCTL_RSVD31 |
173 AUXCTL_EARLY_BRESP_EN |
174 AUXCTL_CACHE_REPL_RR |
175
176 AUXCTL_SH_ATTR_INV_ENA|
177 AUXCTL_EXCL_CACHE_CFG |
178 AUXCTL_ST_BUF_DEV_LIM_EN |
179 AUXCTL_HIPRO_SO_DEV_EN |
180 AUXCTL_FULL_LINE_WR0 |
181 0xffff;
182 uint32_t prefetch;
183
184 /* check the bitmaps are the same as the linux implementation uses */
185 KASSERT(prefetch4412 == 0x71000007);
186 KASSERT(prefetch4412_r0 == 0x30000007);
187 KASSERT(aux_val == 0x7C470001);
188 KASSERT(aux_keepmask == 0xC200FFFF);
189
190 if (IS_EXYNOS4412_R0_P())
191 prefetch = prefetch4412_r0;
192 else
193 prefetch = prefetch4412; /* newer than >= r1_0 */
194 ;
195
196 exynos_smc(SMC_CMD_L2X0SETUP1, tag_latency, data_latency, prefetch);
197 exynos_smc(SMC_CMD_L2X0SETUP2,
198 POWERCTL_DYNCLKGATE | POWERCTL_STANDBY,
199 aux_val, aux_keepmask);
200 exynos_smc(SMC_CMD_L2X0INVALL, 0, 0, 0);
201 exynos_smc(SMC_CMD_L2X0CTRL, 1, 0, 0);
202
203 return 0;
204 }
205 #endif /* ARM_TRUSTZONE_FIRMWARE */
206
207
208 void
209 exynos_bootstrap(vaddr_t iobase, vaddr_t uartbase)
210 {
211 // int error;
212
213 /* set up early console so we can use printf() and friends */
214 #ifdef EXYNOS_CONSOLE_EARLY
215 uart_base = (volatile uint8_t *) uartbase;
216 cn_tab = &exynos_earlycons;
217 printf("Exynos early console operational\n\n");
218 #endif
219 #if 0
220 /* map in the exynos io registers */
221 error = bus_space_map(&exynos_bs_tag, EXYNOS_CORE_PBASE,
222 0x04000000 /*EXYNOS_CORE_SIZE*/, 0, &exynos_core_bsh);
223 if (error)
224 panic("%s: failed to map in Exynos io registers: %d",
225 __func__, error);
226 KASSERT(exynos_core_bsh == iobase);
227 #endif
228 }
229
230
231 void
232 exynos_device_register(device_t self, void *aux)
233 {
234 if (device_is_a(self, "armperiph")
235 && device_is_a(device_parent(self), "mainbus")) {
236 /*
237 * XXX KLUDGE ALERT XXX
238 * The iot mainbus supplies is completely wrong since it scales
239 * addresses by 2. The simpliest remedy is to replace with our
240 * bus space used for the armcore regisers (which armperiph uses).
241 */
242 struct mainbus_attach_args * const mb = aux;
243 mb->mb_iot = &exynos_bs_tag;
244 return;
245 }
246 if (device_is_a(self, "armgic")
247 && device_is_a(device_parent(self), "armperiph")) {
248 /*
249 * The Exynos4420 armgic is located at a different location!
250 */
251
252 extern uint32_t exynos_soc_id;
253 switch (EXYNOS_PRODUCT_ID(exynos_soc_id)) {
254 #if defined(EXYNOS5)
255 case 0xe5410:
256 #if 0
257 mpcaa->mpcaa_off1 = EXYNOS5_GIC_IOP_DISTRIBUTOR_OFFSET;
258 mpcaa->mpcaa_off2 = EXYNOS5_GIC_IOP_CONTROLLER_OFFSET;
259 #endif
260 break;
261 #endif
262 #if defined(EXYNOS4)
263 case 0xe4410:
264 case 0xe4412: {
265 struct mpcore_attach_args * const mpcaa = aux;
266 mpcaa->mpcaa_memh = EXYNOS_CORE_VBASE;
267 mpcaa->mpcaa_off1 = EXYNOS4_GIC_DISTRIBUTOR_OFFSET;
268 mpcaa->mpcaa_off2 = EXYNOS4_GIC_CNTR_OFFSET;
269 break;
270 }
271 #endif
272 default:
273 panic("%s: unknown SoC product id %#x", __func__,
274 (u_int)EXYNOS_PRODUCT_ID(exynos_soc_id));
275 }
276 return;
277 }
278 #if defined(CPU_CORTEXA7) || defined(CPU_CORTEXA15)
279 if (device_is_a(self, "armgtmr")) {
280 /*
281 * The frequency of the generic timer is the reference
282 * frequency.
283 */
284 prop_dictionary_set_uint32(device_properties(self),
285 "frequency", 24000000);
286 return;
287 }
288 #endif
289
290 exyo_device_register(self, aux);
291 }
292
293