2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2019 Ruslan Bukin <br@bsdpad.com>
6 * This software was developed by SRI International and the University of
7 * Cambridge Computer Laboratory (Department of Computer Science and
8 * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the
9 * DARPA SSITH research programme.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * Intel Stratix 10 Service Layer
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
40 #include <sys/param.h>
41 #include <sys/systm.h>
43 #include <sys/kernel.h>
44 #include <sys/module.h>
45 #include <sys/malloc.h>
47 #include <sys/timeet.h>
48 #include <sys/timetc.h>
56 #include <dev/fdt/simplebus.h>
57 #include <dev/ofw/openfirm.h>
58 #include <dev/ofw/ofw_bus.h>
59 #include <dev/ofw/ofw_bus_subr.h>
61 #include <arm64/intel/intel-smc.h>
62 #include <arm64/intel/stratix10-svc.h>
64 #include <machine/bus.h>
65 #include <machine/cpu.h>
66 #include <machine/intr.h>
68 struct s10_svc_softc {
71 intel_smc_callfn_t callfn;
75 s10_data_claim(struct s10_svc_softc *sc)
77 struct arm_smccc_res res;
78 register_t a0, a1, a2;
84 a0 = INTEL_SIP_SMC_FPGA_CONFIG_COMPLETED_WRITE;
88 ret = sc->callfn(a0, a1, a2, 0, 0, 0, 0, 0, &res);
89 if (ret == INTEL_SIP_SMC_FPGA_CONFIG_STATUS_BUSY)
99 s10_svc_send(device_t dev, struct s10_svc_msg *msg)
101 struct s10_svc_softc *sc;
102 struct arm_smccc_res res;
103 register_t a0, a1, a2;
106 sc = device_get_softc(dev);
112 switch (msg->command) {
113 case COMMAND_RECONFIG:
114 a0 = INTEL_SIP_SMC_FPGA_CONFIG_START;
117 case COMMAND_RECONFIG_DATA_SUBMIT:
118 a0 = INTEL_SIP_SMC_FPGA_CONFIG_WRITE;
119 a1 = (uint64_t)msg->payload;
120 a2 = (uint64_t)msg->payload_length;
122 case COMMAND_RECONFIG_DATA_CLAIM:
123 ret = s10_data_claim(sc);
129 ret = sc->callfn(a0, a1, a2, 0, 0, 0, 0, 0, &res);
135 s10_svc_allocate_memory(device_t dev, struct s10_svc_mem *mem, int size)
137 struct s10_svc_softc *sc;
139 sc = device_get_softc(dev);
144 if (vmem_alloc(sc->vmem, size,
145 M_FIRSTFIT | M_NOWAIT, &mem->paddr)) {
146 device_printf(dev, "Can't allocate memory\n");
152 mem->vaddr = (vm_offset_t)pmap_mapdev(mem->paddr, mem->size);
158 s10_svc_free_memory(device_t dev, struct s10_svc_mem *mem)
160 struct s10_svc_softc *sc;
162 sc = device_get_softc(dev);
164 vmem_free(sc->vmem, mem->paddr, mem->size);
168 s10_get_memory(struct s10_svc_softc *sc)
170 struct arm_smccc_res res;
175 sc->callfn(INTEL_SIP_SMC_FPGA_CONFIG_GET_MEM,
176 0, 0, 0, 0, 0, 0, 0, &res);
177 if (res.a0 != INTEL_SIP_SMC_STATUS_OK)
180 vmem = vmem_create("stratix10 vmem", 0, 0, PAGE_SIZE,
181 PAGE_SIZE, M_BESTFIT | M_WAITOK);
188 device_printf(sc->dev, "Shared memory address 0x%lx size 0x%lx\n",
191 vmem_add(vmem, addr, size, 0);
198 static intel_smc_callfn_t
199 s10_svc_get_callfn(struct s10_svc_softc *sc, phandle_t node)
203 if ((OF_getprop(node, "method", method, sizeof(method))) > 0) {
204 if (strcmp(method, "hvc") == 0)
205 return (arm_smccc_hvc);
206 else if (strcmp(method, "smc") == 0)
207 return (arm_smccc_smc);
209 device_printf(sc->dev,
210 "Invalid method \"%s\"\n", method);
212 device_printf(sc->dev, "SMC method not provided\n");
218 s10_svc_probe(device_t dev)
221 if (!ofw_bus_status_okay(dev))
224 if (!ofw_bus_is_compatible(dev, "intel,stratix10-svc"))
227 device_set_desc(dev, "Stratix 10 SVC");
229 return (BUS_PROBE_DEFAULT);
233 s10_svc_attach(device_t dev)
235 struct s10_svc_softc *sc;
238 node = ofw_bus_get_node(dev);
240 sc = device_get_softc(dev);
243 if (device_get_unit(dev) != 0)
246 sc->callfn = s10_svc_get_callfn(sc, node);
247 if (sc->callfn == NULL)
250 if (s10_get_memory(sc) != 0)
256 static device_method_t s10_svc_methods[] = {
257 DEVMETHOD(device_probe, s10_svc_probe),
258 DEVMETHOD(device_attach, s10_svc_attach),
262 static driver_t s10_svc_driver = {
265 sizeof(struct s10_svc_softc),
268 static devclass_t s10_svc_devclass;
270 EARLY_DRIVER_MODULE(s10_svc, firmware, s10_svc_driver,
271 s10_svc_devclass, 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);