exynos_platform.c revision 1.3 1 /* $NetBSD: exynos_platform.c,v 1.3 2017/06/11 01:09:44 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.3 2017/06/11 01:09:44 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 DEVMAP_ALIGN(a) ((a) & ~L1_S_OFFSET)
61 #define DEVMAP_SIZE(s) roundup2((s), L1_S_SIZE)
62 #define DEVMAP_ENTRY(va, pa, sz) \
63 { \
64 .pd_va = DEVMAP_ALIGN(va), \
65 .pd_pa = DEVMAP_ALIGN(pa), \
66 .pd_size = DEVMAP_SIZE(sz), \
67 .pd_prot = VM_PROT_READ|VM_PROT_WRITE, \
68 .pd_cache = PTE_NOCACHE \
69 }
70 #define DEVMAP_ENTRY_END { 0 }
71
72 static const struct pmap_devmap *
73 exynos_platform_devmap(void)
74 {
75 static const struct pmap_devmap devmap[] = {
76 DEVMAP_ENTRY(EXYNOS_CORE_VBASE,
77 EXYNOS_CORE_PBASE,
78 EXYNOS5_CORE_SIZE),
79 DEVMAP_ENTRY(EXYNOS5_AUDIOCORE_VBASE,
80 EXYNOS5_AUDIOCORE_PBASE,
81 EXYNOS5_AUDIOCORE_SIZE),
82 DEVMAP_ENTRY_END
83 };
84
85 return devmap;
86 }
87
88 #define EXYNOS_IOPHYSTOVIRT(a) \
89 ((vaddr_t)(((a) - EXYNOS_CORE_PBASE) + EXYNOS_CORE_VBASE))
90
91 static void
92 exynos_platform_bootstrap(void)
93 {
94 paddr_t uart_address = armreg_tpidruro_read(); /* XXX */
95 exynos_bootstrap(EXYNOS_CORE_VBASE, EXYNOS_IOPHYSTOVIRT(uart_address));
96 }
97
98 static void
99 exynos_platform_init_attach_args(struct fdt_attach_args *faa)
100 {
101 extern struct bus_space armv7_generic_bs_tag;
102 extern struct bus_space armv7_generic_a4x_bs_tag;
103 extern struct arm32_bus_dma_tag armv7_generic_dma_tag;
104
105 faa->faa_bst = &armv7_generic_bs_tag;
106 faa->faa_a4x_bst = &armv7_generic_a4x_bs_tag;
107 faa->faa_dmat = &armv7_generic_dma_tag;
108 }
109
110 static void
111 exynos_platform_early_putchar(char c)
112 {
113 extern void exynos_putchar(int); /* XXX from exynos_start.S */
114
115 exynos_putchar(c);
116 }
117
118 static void
119 exynos_platform_device_register(device_t self, void *aux)
120 {
121 exynos_device_register(self, aux);
122 }
123
124 static void
125 exynos_platform_reset(void)
126 {
127 printf("%s: not implemented\n", __func__);
128 }
129
130 static void
131 exynos_platform_delay(u_int us)
132 {
133 extern void mct_delay(u_int);
134
135 mct_delay(us);
136 }
137
138 static u_int
139 exynos_platform_uart_freq(void)
140 {
141 return EXYNOS_UART_FREQ;
142 }
143
144 static const struct arm_platform exynos5_platform = {
145 .devmap = exynos_platform_devmap,
146 .bootstrap = exynos_platform_bootstrap,
147 .init_attach_args = exynos_platform_init_attach_args,
148 .early_putchar = exynos_platform_early_putchar,
149 .device_register = exynos_platform_device_register,
150 .reset = exynos_platform_reset,
151 .delay = exynos_platform_delay,
152 .uart_freq = exynos_platform_uart_freq,
153 };
154
155 ARM_PLATFORM(exynos5, "samsung,exynos5", &exynos5_platform);
156