acpi_platform.c revision 1.1 1 /* $NetBSD: acpi_platform.c,v 1.1 2018/10/12 22:20:04 jmcneill Exp $ */
2
3 /*-
4 * Copyright (c) 2018 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jared McNeill <jmcneill (at) invisible.ca>.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: acpi_platform.c,v 1.1 2018/10/12 22:20:04 jmcneill Exp $");
34
35 #include <sys/param.h>
36 #include <sys/bus.h>
37 #include <sys/cpu.h>
38 #include <sys/device.h>
39 #include <sys/termios.h>
40
41 #include <dev/fdt/fdtvar.h>
42 #include <arm/fdt/arm_fdtvar.h>
43
44 #include <uvm/uvm_extern.h>
45
46 #include <machine/bootconfig.h>
47 #include <arm/cpufunc.h>
48 #include <arm/locore.h>
49
50 #include <arm/cortex/gtmr_var.h>
51
52 #include <arm/arm/psci.h>
53 #include <arm/fdt/psci_fdtvar.h>
54
55 #include <evbarm/fdt/platform.h>
56
57 #include <evbarm/dev/plcomreg.h>
58 #include <evbarm/dev/plcomvar.h>
59 #include <dev/ic/ns16550reg.h>
60 #include <dev/ic/comreg.h>
61
62 #include <dev/acpi/acpireg.h>
63 #include <dev/acpi/acpivar.h>
64 #include <arch/arm/acpi/acpi_table.h>
65
66 #define SPCR_INTERFACE_TYPE_PL011 0x0003
67
68 extern struct bus_space arm_generic_bs_tag;
69
70 static struct plcom_instance plcom_console;
71
72 static const struct pmap_devmap *
73 acpi_platform_devmap(void)
74 {
75 static const struct pmap_devmap devmap[] = {
76 DEVMAP_ENTRY_END
77 };
78
79 return devmap;
80 }
81
82 static void
83 acpi_platform_bootstrap(void)
84 {
85 }
86
87 static void
88 acpi_platform_startup(void)
89 {
90 ACPI_TABLE_SPCR *spcr;
91 ACPI_TABLE_FADT *fadt;
92 ACPI_TABLE_MADT *madt;
93
94 /*
95 * Setup serial console device
96 */
97 if (ACPI_SUCCESS(acpi_table_find(ACPI_SIG_SPCR, (void **)&spcr))) {
98 if (spcr->InterfaceType == SPCR_INTERFACE_TYPE_PL011 &&
99 spcr->SerialPort.SpaceId == ACPI_ADR_SPACE_SYSTEM_MEMORY &&
100 spcr->SerialPort.Address != 0) {
101
102 plcom_console.pi_type = PLCOM_TYPE_PL011;
103 plcom_console.pi_flags = PLC_FLAG_32BIT_ACCESS;
104 plcom_console.pi_iot = &arm_generic_bs_tag;
105 plcom_console.pi_iobase = spcr->SerialPort.Address;
106 plcom_console.pi_size = PL011COM_UART_SIZE;
107
108 plcomcnattach(&plcom_console, 115200 /* XXX */, 0, TTYDEF_CFLAG, -1);
109 }
110 acpi_table_unmap((ACPI_TABLE_HEADER *)spcr);
111 }
112
113 /*
114 * Initialize PSCI 0.2+ if implemented
115 */
116 if (ACPI_SUCCESS(acpi_table_find(ACPI_SIG_FADT, (void **)&fadt))) {
117 if (fadt->ArmBootFlags & ACPI_FADT_PSCI_COMPLIANT) {
118 if (fadt->ArmBootFlags & ACPI_FADT_PSCI_USE_HVC) {
119 psci_init(psci_call_hvc);
120 } else {
121 psci_init(psci_call_smc);
122 }
123 }
124 acpi_table_unmap((ACPI_TABLE_HEADER *)fadt);
125 }
126
127 /*
128 * Count CPUs
129 */
130 if (ACPI_SUCCESS(acpi_table_find(ACPI_SIG_MADT, (void **)&madt))) {
131 char *end = (char *)madt + madt->Header.Length;
132 char *where = (char *)madt + sizeof(ACPI_TABLE_MADT);
133 while (where < end) {
134 ACPI_SUBTABLE_HEADER *subtable = (ACPI_SUBTABLE_HEADER *)where;
135 if (subtable->Type == ACPI_MADT_TYPE_GENERIC_INTERRUPT)
136 arm_cpu_max++;
137 where += subtable->Length;
138 }
139 acpi_table_unmap((ACPI_TABLE_HEADER *)madt);
140 }
141 }
142
143 static void
144 acpi_platform_init_attach_args(struct fdt_attach_args *faa)
145 {
146 extern struct arm32_bus_dma_tag arm_generic_dma_tag;
147 extern struct bus_space arm_generic_bs_tag;
148 extern struct bus_space arm_generic_a4x_bs_tag;
149
150 faa->faa_bst = &arm_generic_bs_tag;
151 faa->faa_a4x_bst = &arm_generic_a4x_bs_tag;
152 faa->faa_dmat = &arm_generic_dma_tag;
153 }
154
155 static void
156 acpi_platform_early_putchar(char c)
157 {
158 }
159
160 static void
161 acpi_platform_device_register(device_t self, void *aux)
162 {
163 }
164
165 static u_int
166 acpi_platform_uart_freq(void)
167 {
168 return 0;
169 }
170
171 static const struct arm_platform acpi_platform = {
172 .ap_devmap = acpi_platform_devmap,
173 .ap_bootstrap = acpi_platform_bootstrap,
174 .ap_startup = acpi_platform_startup,
175 .ap_init_attach_args = acpi_platform_init_attach_args,
176 .ap_early_putchar = acpi_platform_early_putchar,
177 .ap_device_register = acpi_platform_device_register,
178 .ap_reset = psci_fdt_reset,
179 .ap_delay = gtmr_delay,
180 .ap_uart_freq = acpi_platform_uart_freq,
181 };
182
183 ARM_PLATFORM(virt, "netbsd,generic-acpi", &acpi_platform);
184