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