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