arm_platform.c revision 1.2.6.2 1 /* $NetBSD: arm_platform.c,v 1.2.6.2 2020/04/08 14:07:29 martin Exp $ */
2
3 /*-
4 * Copyright (c) 2020 Jared 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 /*
30 * This is the default Arm FDT platform implementation. It assumes the
31 * following:
32 *
33 * - Generic timer
34 * - PSCI support
35 * - Console UART is pre-configured by firmware
36 */
37
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: arm_platform.c,v 1.2.6.2 2020/04/08 14:07:29 martin Exp $");
40
41 #include <sys/param.h>
42 #include <sys/bus.h>
43 #include <sys/cpu.h>
44 #include <sys/device.h>
45 #include <sys/termios.h>
46
47 #include <dev/fdt/fdtvar.h>
48 #include <arm/fdt/arm_fdtvar.h>
49
50 #include <uvm/uvm_extern.h>
51
52 #include <machine/bootconfig.h>
53
54 #include <arm/cpufunc.h>
55
56 #include <arm/cortex/gtmr_var.h>
57
58 #include <arm/arm/psci.h>
59 #include <arm/fdt/psci_fdtvar.h>
60
61 #include <libfdt.h>
62
63 #include <arch/evbarm/fdt/platform.h>
64
65 extern struct arm32_bus_dma_tag arm_generic_dma_tag;
66 extern struct bus_space arm_generic_bs_tag;
67 extern struct bus_space arm_generic_a4x_bs_tag;
68
69 static void
70 arm_platform_init_attach_args(struct fdt_attach_args *faa)
71 {
72 faa->faa_bst = &arm_generic_bs_tag;
73 faa->faa_a4x_bst = &arm_generic_a4x_bs_tag;
74 faa->faa_dmat = &arm_generic_dma_tag;
75 }
76
77 static void
78 arm_platform_device_register(device_t self, void *aux)
79 {
80 }
81
82 static const struct pmap_devmap *
83 arm_platform_devmap(void)
84 {
85 static const struct pmap_devmap devmap_empty[] = {
86 DEVMAP_ENTRY_END
87 };
88 static struct pmap_devmap devmap_uart[] = {
89 DEVMAP_ENTRY(KERNEL_IO_VBASE, 0, PAGE_SIZE),
90 DEVMAP_ENTRY_END
91 };
92 bus_addr_t uart_base;
93
94 const int phandle = fdtbus_get_stdout_phandle();
95 if (phandle <= 0)
96 return devmap_empty;
97
98 if (fdtbus_get_reg(phandle, 0, &uart_base, NULL) != 0)
99 return devmap_empty;
100
101 devmap_uart[0].pd_pa = DEVMAP_ALIGN(uart_base);
102
103 return devmap_uart;
104 }
105
106 static u_int
107 arm_platform_uart_freq(void)
108 {
109 return 0;
110 }
111
112 static const struct arm_platform arm_platform = {
113 .ap_devmap = arm_platform_devmap,
114 .ap_bootstrap = arm_fdt_cpu_bootstrap,
115 .ap_init_attach_args = arm_platform_init_attach_args,
116 .ap_device_register = arm_platform_device_register,
117 .ap_reset = psci_fdt_reset,
118 .ap_delay = gtmr_delay,
119 .ap_uart_freq = arm_platform_uart_freq,
120 .ap_mpstart = arm_fdt_cpu_mpstart,
121 };
122
123 ARM_PLATFORM(arm, ARM_PLATFORM_DEFAULT, &arm_platform);
124