xref: /openbsd/sys/arch/sparc64/dev/cmp.c (revision 9079f3ed)
1*9079f3edSkettenis /*	$OpenBSD: cmp.c,v 1.1 2008/06/10 00:02:09 kettenis Exp $	*/
2*9079f3edSkettenis /*
3*9079f3edSkettenis  * Copyright (c) 2008 Mark Kettenis
4*9079f3edSkettenis  *
5*9079f3edSkettenis  * Permission to use, copy, modify, and distribute this software for any
6*9079f3edSkettenis  * purpose with or without fee is hereby granted, provided that the above
7*9079f3edSkettenis  * copyright notice and this permission notice appear in all copies.
8*9079f3edSkettenis  *
9*9079f3edSkettenis  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*9079f3edSkettenis  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*9079f3edSkettenis  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*9079f3edSkettenis  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*9079f3edSkettenis  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*9079f3edSkettenis  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*9079f3edSkettenis  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*9079f3edSkettenis  */
17*9079f3edSkettenis 
18*9079f3edSkettenis #include <sys/param.h>
19*9079f3edSkettenis #include <sys/device.h>
20*9079f3edSkettenis #include <sys/systm.h>
21*9079f3edSkettenis 
22*9079f3edSkettenis #include <machine/autoconf.h>
23*9079f3edSkettenis #include <machine/openfirm.h>
24*9079f3edSkettenis 
25*9079f3edSkettenis int	cmp_match(struct device *, void *, void *);
26*9079f3edSkettenis void	cmp_attach(struct device *, struct device *, void *);
27*9079f3edSkettenis 
28*9079f3edSkettenis struct cfattach cmp_ca = {
29*9079f3edSkettenis 	sizeof(struct device), cmp_match, cmp_attach
30*9079f3edSkettenis };
31*9079f3edSkettenis 
32*9079f3edSkettenis struct cfdriver cmp_cd = {
33*9079f3edSkettenis 	NULL, "cmp", DV_DULL
34*9079f3edSkettenis };
35*9079f3edSkettenis 
36*9079f3edSkettenis int	cmp_print(void *, const char *);
37*9079f3edSkettenis 
38*9079f3edSkettenis int
39*9079f3edSkettenis cmp_match(struct device *parent, void *match, void *aux)
40*9079f3edSkettenis {
41*9079f3edSkettenis 	struct mainbus_attach_args *ma = aux;
42*9079f3edSkettenis 
43*9079f3edSkettenis 	if (strcmp(ma->ma_name, "cmp") == 0)
44*9079f3edSkettenis 		return (1);
45*9079f3edSkettenis 
46*9079f3edSkettenis 	return (0);
47*9079f3edSkettenis }
48*9079f3edSkettenis 
49*9079f3edSkettenis void
50*9079f3edSkettenis cmp_attach(struct device *parent, struct device *self, void *aux)
51*9079f3edSkettenis {
52*9079f3edSkettenis 	struct mainbus_attach_args *ma = aux;
53*9079f3edSkettenis 	struct mainbus_attach_args nma;
54*9079f3edSkettenis 	char buf[32];
55*9079f3edSkettenis 	int node;
56*9079f3edSkettenis 
57*9079f3edSkettenis 	printf("\n");
58*9079f3edSkettenis 
59*9079f3edSkettenis 	for (node = OF_child(ma->ma_node); node; node = OF_peer(node)) {
60*9079f3edSkettenis 		if (!checkstatus(node))
61*9079f3edSkettenis 			continue;
62*9079f3edSkettenis 
63*9079f3edSkettenis 		OF_getprop(node, "name", buf, sizeof(buf));
64*9079f3edSkettenis 		if (strcmp(buf, "cpu") == 0)
65*9079f3edSkettenis 			OF_getprop(node, "compatible", buf, sizeof(buf));
66*9079f3edSkettenis 
67*9079f3edSkettenis 		bzero(&nma, sizeof(nma));
68*9079f3edSkettenis 		nma.ma_node = node;
69*9079f3edSkettenis 		nma.ma_name = buf;
70*9079f3edSkettenis 		getprop(node, "reg", sizeof(*nma.ma_reg),
71*9079f3edSkettenis 		    &nma.ma_nreg, (void **)&nma.ma_reg);
72*9079f3edSkettenis 		config_found(self, &nma, cmp_print);
73*9079f3edSkettenis 	}
74*9079f3edSkettenis }
75*9079f3edSkettenis 
76*9079f3edSkettenis int
77*9079f3edSkettenis cmp_print(void *aux, const char *name)
78*9079f3edSkettenis {
79*9079f3edSkettenis 	struct mainbus_attach_args *ma = aux;
80*9079f3edSkettenis 
81*9079f3edSkettenis 	if (name)
82*9079f3edSkettenis 		printf("\"%s\" at %s", ma->ma_name, name);
83*9079f3edSkettenis 	return (UNCONF);
84*9079f3edSkettenis }
85