xref: /freebsd/sys/arm64/spe/arm_spe_fdt.c (revision 68f185ccc9f8f9498d536f4737d888b37cf11882)
1*68f185ccSZachary Leaf /*-
2*68f185ccSZachary Leaf  * SPDX-License-Identifier: BSD-2-Clause
3*68f185ccSZachary Leaf  *
4*68f185ccSZachary Leaf  * Copyright (c) 2024 Arm Ltd
5*68f185ccSZachary Leaf  * Copyright (c) 2022 The FreeBSD Foundation
6*68f185ccSZachary Leaf  *
7*68f185ccSZachary Leaf  * Portions of this software were developed by Andrew Turner under sponsorship
8*68f185ccSZachary Leaf  * from the FreeBSD Foundation.
9*68f185ccSZachary Leaf  *
10*68f185ccSZachary Leaf  * Redistribution and use in source and binary forms, with or without
11*68f185ccSZachary Leaf  * modification, are permitted provided that the following conditions
12*68f185ccSZachary Leaf  * are met:
13*68f185ccSZachary Leaf  * 1. Redistributions of source code must retain the above copyright
14*68f185ccSZachary Leaf  *    notice, this list of conditions and the following disclaimer.
15*68f185ccSZachary Leaf  * 2. Redistributions in binary form must reproduce the above copyright
16*68f185ccSZachary Leaf  *    notice, this list of conditions and the following disclaimer in the
17*68f185ccSZachary Leaf  *    documentation and/or other materials provided with the distribution.
18*68f185ccSZachary Leaf  *
19*68f185ccSZachary Leaf  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20*68f185ccSZachary Leaf  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*68f185ccSZachary Leaf  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*68f185ccSZachary Leaf  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23*68f185ccSZachary Leaf  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*68f185ccSZachary Leaf  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*68f185ccSZachary Leaf  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*68f185ccSZachary Leaf  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*68f185ccSZachary Leaf  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*68f185ccSZachary Leaf  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*68f185ccSZachary Leaf  * SUCH DAMAGE.
30*68f185ccSZachary Leaf  */
31*68f185ccSZachary Leaf 
32*68f185ccSZachary Leaf #include <sys/param.h>
33*68f185ccSZachary Leaf #include <sys/bus.h>
34*68f185ccSZachary Leaf #include <sys/kernel.h>
35*68f185ccSZachary Leaf #include <sys/lock.h>
36*68f185ccSZachary Leaf #include <sys/module.h>
37*68f185ccSZachary Leaf #include <sys/mutex.h>
38*68f185ccSZachary Leaf 
39*68f185ccSZachary Leaf #include <dev/ofw/ofw_bus.h>
40*68f185ccSZachary Leaf #include <dev/ofw/ofw_bus_subr.h>
41*68f185ccSZachary Leaf #include <dev/ofw/openfirm.h>
42*68f185ccSZachary Leaf 
43*68f185ccSZachary Leaf #include <arm64/spe/arm_spe_dev.h>
44*68f185ccSZachary Leaf 
45*68f185ccSZachary Leaf static device_probe_t arm_spe_fdt_probe;
46*68f185ccSZachary Leaf 
47*68f185ccSZachary Leaf static struct ofw_compat_data compat_data[] = {
48*68f185ccSZachary Leaf 	{"arm,statistical-profiling-extension-v1",      true},
49*68f185ccSZachary Leaf 	{NULL,                                          false},
50*68f185ccSZachary Leaf };
51*68f185ccSZachary Leaf 
52*68f185ccSZachary Leaf static device_method_t arm_spe_fdt_methods[] = {
53*68f185ccSZachary Leaf 	/* Device interface */
54*68f185ccSZachary Leaf 	DEVMETHOD(device_probe,         arm_spe_fdt_probe),
55*68f185ccSZachary Leaf 
56*68f185ccSZachary Leaf 	DEVMETHOD_END,
57*68f185ccSZachary Leaf };
58*68f185ccSZachary Leaf 
59*68f185ccSZachary Leaf DEFINE_CLASS_1(spe, arm_spe_fdt_driver, arm_spe_fdt_methods,
60*68f185ccSZachary Leaf     sizeof(struct arm_spe_softc), arm_spe_driver);
61*68f185ccSZachary Leaf 
62*68f185ccSZachary Leaf DRIVER_MODULE(spe, simplebus, arm_spe_fdt_driver, 0, 0);
63*68f185ccSZachary Leaf 
64*68f185ccSZachary Leaf static int
arm_spe_fdt_probe(device_t dev)65*68f185ccSZachary Leaf arm_spe_fdt_probe(device_t dev)
66*68f185ccSZachary Leaf {
67*68f185ccSZachary Leaf 	if (!ofw_bus_status_okay(dev))
68*68f185ccSZachary Leaf 		return (ENXIO);
69*68f185ccSZachary Leaf 
70*68f185ccSZachary Leaf 	if (!ofw_bus_search_compatible(dev, compat_data)->ocd_data)
71*68f185ccSZachary Leaf 		return (ENXIO);
72*68f185ccSZachary Leaf 
73*68f185ccSZachary Leaf 	device_set_desc(dev, "ARM Statistical Profiling Extension");
74*68f185ccSZachary Leaf 	return (BUS_PROBE_DEFAULT);
75*68f185ccSZachary Leaf }
76