xref: /freebsd/sys/powerpc/powernv/powernv_centaur.c (revision 38a52bd3b5cac3da6f7f6eef3dd050e6aa08ebb3)
1 /*-
2  * Copyright (c) 2017-2018 QCM Technologies.
3  * Copyright (c) 2017-2018 Semihalf.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  */
29 
30 #include "opt_platform.h"
31 
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
34 
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/bus.h>
38 #include <sys/conf.h>
39 #include <sys/kernel.h>
40 #include <sys/lock.h>
41 #include <sys/mbuf.h>
42 #include <sys/malloc.h>
43 #include <sys/module.h>
44 #include <sys/mutex.h>
45 #include <sys/rman.h>
46 #include <machine/bus.h>
47 
48 #ifdef FDT
49 #include <dev/ofw/ofw_bus.h>
50 #include <dev/ofw/ofw_bus_subr.h>
51 #endif
52 
53 struct powernv_centaur_softc
54 {
55 
56 };
57 
58 static int powernv_centaur_attach(device_t);
59 static int powernv_centaur_probe(device_t);
60 static const struct ofw_bus_devinfo *
61     powernv_centaur_get_devinfo(device_t, device_t);
62 
63 static device_method_t powernv_centaur_methods[] = {
64 	/* Device interface */
65 	DEVMETHOD(device_probe,		powernv_centaur_probe),
66 	DEVMETHOD(device_attach,	powernv_centaur_attach),
67 
68 	/* ofw_bus interface */
69 	DEVMETHOD(ofw_bus_get_devinfo,	powernv_centaur_get_devinfo),
70 	DEVMETHOD(ofw_bus_get_compat,	ofw_bus_gen_get_compat),
71 	DEVMETHOD(ofw_bus_get_model,	ofw_bus_gen_get_model),
72 	DEVMETHOD(ofw_bus_get_name,	ofw_bus_gen_get_name),
73 	DEVMETHOD(ofw_bus_get_node,	ofw_bus_gen_get_node),
74 	DEVMETHOD(ofw_bus_get_type,	ofw_bus_gen_get_type),
75 
76 	DEVMETHOD_END
77 };
78 
79 static int
80 powernv_centaur_probe(device_t dev)
81 {
82 
83 	if (!(ofw_bus_is_compatible(dev, "ibm,centaur")))
84 		return (ENXIO);
85 
86 	device_set_desc(dev, "centaur");
87 	return (0);
88 }
89 
90 static int
91 powernv_centaur_attach(device_t dev)
92 {
93 	phandle_t child;
94 	device_t cdev;
95 	struct ofw_bus_devinfo *dinfo;
96 
97 	for (child = OF_child(ofw_bus_get_node(dev)); child != 0;
98 	    child = OF_peer(child)) {
99 		dinfo = malloc(sizeof(*dinfo), M_DEVBUF, M_WAITOK | M_ZERO);
100 		if (ofw_bus_gen_setup_devinfo(dinfo, child) != 0) {
101 			free(dinfo, M_DEVBUF);
102 			continue;
103 		}
104 		cdev = device_add_child(dev, NULL, -1);
105 		if (cdev == NULL) {
106 			device_printf(dev, "<%s>: device_add_child failed\n",
107 			    dinfo->obd_name);
108 			ofw_bus_gen_destroy_devinfo(dinfo);
109 			free(dinfo, M_DEVBUF);
110 			continue;
111 		}
112 		device_set_ivars(cdev, dinfo);
113 	}
114 
115 	return (bus_generic_attach(dev));
116 }
117 
118 static const struct ofw_bus_devinfo *
119 powernv_centaur_get_devinfo(device_t dev, device_t child)
120 {
121         return (device_get_ivars(child));
122 }
123 
124 DEFINE_CLASS_0(powernv_centaur, powernv_centaur_driver, powernv_centaur_methods,
125     sizeof(struct powernv_centaur_softc));
126 DRIVER_MODULE(powernv_centaur, ofwbus, powernv_centaur_driver, NULL, NULL);
127