exynos_platform.c revision 1.6 1 /* $NetBSD: exynos_platform.c,v 1.6 2017/06/20 19:13:34 jmcneill Exp $ */
2
3 /*-
4 * Copyright (c) 2017 Jared D. McNeill <jmcneill (at) invisible.ca>
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,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 #include "opt_exynos.h"
30 #include "opt_multiprocessor.h"
31 #include "opt_fdt_arm.h"
32
33 #include "ukbd.h"
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: exynos_platform.c,v 1.6 2017/06/20 19:13:34 jmcneill Exp $");
37
38 #include <sys/param.h>
39 #include <sys/bus.h>
40 #include <sys/cpu.h>
41 #include <sys/device.h>
42 #include <sys/termios.h>
43
44 #include <dev/fdt/fdtvar.h>
45
46 #include <uvm/uvm_extern.h>
47
48 #include <machine/bootconfig.h>
49 #include <arm/cpufunc.h>
50
51 #include <arm/samsung/exynos_reg.h>
52 #include <arm/samsung/exynos_var.h>
53
54 #include <evbarm/exynos/platform.h>
55
56 #include <arm/cortex/gtmr_var.h>
57
58 #include <arm/fdt/arm_fdtvar.h>
59
60 #define EXYNOS5_SWRESET_REG 0x10040400
61
62 #define DEVMAP_ALIGN(a) ((a) & ~L1_S_OFFSET)
63 #define DEVMAP_SIZE(s) roundup2((s), L1_S_SIZE)
64 #define DEVMAP_ENTRY(va, pa, sz) \
65 { \
66 .pd_va = DEVMAP_ALIGN(va), \
67 .pd_pa = DEVMAP_ALIGN(pa), \
68 .pd_size = DEVMAP_SIZE(sz), \
69 .pd_prot = VM_PROT_READ|VM_PROT_WRITE, \
70 .pd_cache = PTE_NOCACHE \
71 }
72 #define DEVMAP_ENTRY_END { 0 }
73
74 static const struct pmap_devmap *
75 exynos_platform_devmap(void)
76 {
77 static const struct pmap_devmap devmap[] = {
78 DEVMAP_ENTRY(EXYNOS_CORE_VBASE,
79 EXYNOS_CORE_PBASE,
80 EXYNOS5_CORE_SIZE),
81 DEVMAP_ENTRY(EXYNOS5_AUDIOCORE_VBASE,
82 EXYNOS5_AUDIOCORE_PBASE,
83 EXYNOS5_AUDIOCORE_SIZE),
84 DEVMAP_ENTRY_END
85 };
86
87 return devmap;
88 }
89
90 #define EXYNOS_IOPHYSTOVIRT(a) \
91 ((vaddr_t)(((a) - EXYNOS_CORE_PBASE) + EXYNOS_CORE_VBASE))
92
93 static void
94 exynos_platform_bootstrap(void)
95 {
96 paddr_t uart_address = armreg_tpidruro_read(); /* XXX */
97 exynos_bootstrap(EXYNOS_CORE_VBASE, EXYNOS_IOPHYSTOVIRT(uart_address));
98 }
99
100 static void
101 exynos_platform_init_attach_args(struct fdt_attach_args *faa)
102 {
103 extern struct bus_space armv7_generic_bs_tag;
104 extern struct bus_space armv7_generic_a4x_bs_tag;
105 extern struct arm32_bus_dma_tag armv7_generic_dma_tag;
106
107 faa->faa_bst = &armv7_generic_bs_tag;
108 faa->faa_a4x_bst = &armv7_generic_a4x_bs_tag;
109 faa->faa_dmat = &armv7_generic_dma_tag;
110 }
111
112 static void
113 exynos_platform_early_putchar(char c)
114 {
115 #if defined(VERBOSE_INIT_ARM)
116 extern void exynos_putchar(int); /* XXX from exynos_start.S */
117
118 exynos_putchar(c);
119 #endif
120 }
121
122 static void
123 exynos_platform_device_register(device_t self, void *aux)
124 {
125 exynos_device_register(self, aux);
126 }
127
128 static void
129 exynos5_platform_reset(void)
130 {
131 bus_space_tag_t bst = &armv7_generic_bs_tag;
132 bus_space_handle_t bsh;
133
134 bus_space_map(bst, EXYNOS5_SWRESET_REG, 4, 0, &bsh);
135 bus_space_write_4(bst, bsh, 0, 1);
136 }
137
138 static void
139 exynos_platform_delay(u_int us)
140 {
141 gtmr_delay(us);
142 }
143
144 static u_int
145 exynos_platform_uart_freq(void)
146 {
147 return EXYNOS_UART_FREQ;
148 }
149
150 static const struct arm_platform exynos5_platform = {
151 .devmap = exynos_platform_devmap,
152 .bootstrap = exynos_platform_bootstrap,
153 .init_attach_args = exynos_platform_init_attach_args,
154 .early_putchar = exynos_platform_early_putchar,
155 .device_register = exynos_platform_device_register,
156 .reset = exynos5_platform_reset,
157 .delay = exynos_platform_delay,
158 .uart_freq = exynos_platform_uart_freq,
159 };
160
161 ARM_PLATFORM(exynos5, "samsung,exynos5", &exynos5_platform);
162