use device_private(). thanks to jmcneill for pointing this out.diff -r1.1 -r1.2 src/sys/arch/sparc64/dev/central.c
(mrg)
--- src/sys/arch/sparc64/dev/central.c 2011/07/29 08:37:36 1.1
+++ src/sys/arch/sparc64/dev/central.c 2011/08/01 08:36:39 1.2
@@ -1,201 +1,201 @@ | @@ -1,201 +1,201 @@ | |||
1 | /* $NetBSD: central.c,v 1.1 2011/07/29 08:37:36 mrg Exp $ */ | 1 | /* $NetBSD: central.c,v 1.2 2011/08/01 08:36:39 mrg Exp $ */ | |
2 | /* $OpenBSD: central.c,v 1.7 2010/11/11 17:58:23 miod Exp $ */ | 2 | /* $OpenBSD: central.c,v 1.7 2010/11/11 17:58:23 miod Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (c) 2004 Jason L. Wright (jason@thought.net) | 5 | * Copyright (c) 2004 Jason L. Wright (jason@thought.net) | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
15 | * documentation and/or other materials provided with the distribution. | 15 | * documentation and/or other materials provided with the distribution. | |
16 | * | 16 | * | |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
20 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | 20 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | |
21 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 21 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
25 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | 25 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
26 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 26 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
27 | * POSSIBILITY OF SUCH DAMAGE. | 27 | * POSSIBILITY OF SUCH DAMAGE. | |
28 | */ | 28 | */ | |
29 | 29 | |||
30 | #include <sys/types.h> | 30 | #include <sys/types.h> | |
31 | #include <sys/param.h> | 31 | #include <sys/param.h> | |
32 | #include <sys/systm.h> | 32 | #include <sys/systm.h> | |
33 | #include <sys/kernel.h> | 33 | #include <sys/kernel.h> | |
34 | #include <sys/device.h> | 34 | #include <sys/device.h> | |
35 | #include <sys/conf.h> | 35 | #include <sys/conf.h> | |
36 | #include <sys/malloc.h> | 36 | #include <sys/malloc.h> | |
37 | #include <sys/bus.h> | 37 | #include <sys/bus.h> | |
38 | 38 | |||
39 | #include <machine/autoconf.h> | 39 | #include <machine/autoconf.h> | |
40 | #include <machine/openfirm.h> | 40 | #include <machine/openfirm.h> | |
41 | 41 | |||
42 | #include <sparc64/dev/centralvar.h> | 42 | #include <sparc64/dev/centralvar.h> | |
43 | 43 | |||
44 | struct central_softc { | 44 | struct central_softc { | |
45 | bus_space_tag_t sc_bt; | 45 | bus_space_tag_t sc_bt; | |
46 | bus_space_tag_t sc_cbt; | 46 | bus_space_tag_t sc_cbt; | |
47 | int sc_node; | 47 | int sc_node; | |
48 | int sc_nrange; | 48 | int sc_nrange; | |
49 | struct central_range *sc_range; | 49 | struct central_range *sc_range; | |
50 | }; | 50 | }; | |
51 | 51 | |||
52 | static int central_match(device_t, cfdata_t, void *); | 52 | static int central_match(device_t, cfdata_t, void *); | |
53 | static void central_attach(device_t, device_t, void *); | 53 | static void central_attach(device_t, device_t, void *); | |
54 | 54 | |||
55 | CFATTACH_DECL_NEW(central, sizeof(struct central_softc), | 55 | CFATTACH_DECL_NEW(central, sizeof(struct central_softc), | |
56 | central_match, central_attach, NULL, NULL); | 56 | central_match, central_attach, NULL, NULL); | |
57 | 57 | |||
58 | static int central_print(void *, const char *); | 58 | static int central_print(void *, const char *); | |
59 | static int central_get_string(int, const char *, char **); | 59 | static int central_get_string(int, const char *, char **); | |
60 | 60 | |||
61 | static bus_space_tag_t central_alloc_bus_tag(struct central_softc *); | 61 | static bus_space_tag_t central_alloc_bus_tag(struct central_softc *); | |
62 | static int _central_bus_map( | 62 | static int _central_bus_map( | |
63 | bus_space_tag_t, | 63 | bus_space_tag_t, | |
64 | bus_addr_t, /*offset*/ | 64 | bus_addr_t, /*offset*/ | |
65 | bus_size_t, /*size*/ | 65 | bus_size_t, /*size*/ | |
66 | int, /*flags*/ | 66 | int, /*flags*/ | |
67 | vaddr_t, /* XXX unused -- compat w/sparc */ | 67 | vaddr_t, /* XXX unused -- compat w/sparc */ | |
68 | bus_space_handle_t *); | 68 | bus_space_handle_t *); | |
69 | 69 | |||
70 | static int | 70 | static int | |
71 | central_match(device_t parent, cfdata_t match, void *aux) | 71 | central_match(device_t parent, cfdata_t match, void *aux) | |
72 | { | 72 | { | |
73 | struct mainbus_attach_args *ma = aux; | 73 | struct mainbus_attach_args *ma = aux; | |
74 | 74 | |||
75 | if (strcmp(ma->ma_name, "central") == 0) | 75 | if (strcmp(ma->ma_name, "central") == 0) | |
76 | return (1); | 76 | return (1); | |
77 | return (0); | 77 | return (0); | |
78 | } | 78 | } | |
79 | 79 | |||
80 | static void | 80 | static void | |
81 | central_attach(device_t parent, device_t self, void *aux) | 81 | central_attach(device_t parent, device_t self, void *aux) | |
82 | { | 82 | { | |
83 | struct central_softc *sc = (struct central_softc *)self; | 83 | struct central_softc *sc = device_private(self); | |
84 | struct mainbus_attach_args *ma = aux; | 84 | struct mainbus_attach_args *ma = aux; | |
85 | int node0, node; | 85 | int node0, node; | |
86 | 86 | |||
87 | sc->sc_bt = ma->ma_bustag; | 87 | sc->sc_bt = ma->ma_bustag; | |
88 | sc->sc_node = ma->ma_node; | 88 | sc->sc_node = ma->ma_node; | |
89 | sc->sc_cbt = central_alloc_bus_tag(sc); | 89 | sc->sc_cbt = central_alloc_bus_tag(sc); | |
90 | 90 | |||
91 | prom_getprop(sc->sc_node, "ranges", sizeof(struct central_range), | 91 | prom_getprop(sc->sc_node, "ranges", sizeof(struct central_range), | |
92 | &sc->sc_nrange, (void **)&sc->sc_range); | 92 | &sc->sc_nrange, (void **)&sc->sc_range); | |
93 | 93 | |||
94 | printf("\n"); | 94 | printf("\n"); | |
95 | 95 | |||
96 | node0 = firstchild(sc->sc_node); | 96 | node0 = firstchild(sc->sc_node); | |
97 | for (node = node0; node; node = nextsibling(node)) { | 97 | for (node = node0; node; node = nextsibling(node)) { | |
98 | struct central_attach_args ca; | 98 | struct central_attach_args ca; | |
99 | 99 | |||
100 | bzero(&ca, sizeof(ca)); | 100 | bzero(&ca, sizeof(ca)); | |
101 | ca.ca_node = node; | 101 | ca.ca_node = node; | |
102 | ca.ca_bustag = sc->sc_cbt; | 102 | ca.ca_bustag = sc->sc_cbt; | |
103 | if (central_get_string(ca.ca_node, "name", &ca.ca_name)) { | 103 | if (central_get_string(ca.ca_node, "name", &ca.ca_name)) { | |
104 | printf("can't fetch name for node 0x%x\n", node); | 104 | printf("can't fetch name for node 0x%x\n", node); | |
105 | continue; | 105 | continue; | |
106 | } | 106 | } | |
107 | 107 | |||
108 | prom_getprop(node, "reg", sizeof(struct central_reg), | 108 | prom_getprop(node, "reg", sizeof(struct central_reg), | |
109 | &ca.ca_nreg, (void **)&ca.ca_reg); | 109 | &ca.ca_nreg, (void **)&ca.ca_reg); | |
110 | 110 | |||
111 | (void)config_found(self, (void *)&ca, central_print); | 111 | (void)config_found(self, (void *)&ca, central_print); | |
112 | 112 | |||
113 | if (ca.ca_name != NULL) | 113 | if (ca.ca_name != NULL) | |
114 | free(ca.ca_name, M_DEVBUF); | 114 | free(ca.ca_name, M_DEVBUF); | |
115 | } | 115 | } | |
116 | } | 116 | } | |
117 | 117 | |||
118 | static int | 118 | static int | |
119 | central_get_string(int node, const char *name, char **buf) | 119 | central_get_string(int node, const char *name, char **buf) | |
120 | { | 120 | { | |
121 | int len; | 121 | int len; | |
122 | 122 | |||
123 | len = prom_getproplen(node, name); | 123 | len = prom_getproplen(node, name); | |
124 | if (len < 0) | 124 | if (len < 0) | |
125 | return (len); | 125 | return (len); | |
126 | *buf = (char *)malloc(len + 1, M_DEVBUF, M_NOWAIT); | 126 | *buf = (char *)malloc(len + 1, M_DEVBUF, M_NOWAIT); | |
127 | if (*buf == NULL) | 127 | if (*buf == NULL) | |
128 | return (-1); | 128 | return (-1); | |
129 | 129 | |||
130 | if (len != 0) | 130 | if (len != 0) | |
131 | prom_getpropstringA(node, name, *buf, len + 1); | 131 | prom_getpropstringA(node, name, *buf, len + 1); | |
132 | (*buf)[len] = '\0'; | 132 | (*buf)[len] = '\0'; | |
133 | return (0); | 133 | return (0); | |
134 | } | 134 | } | |
135 | 135 | |||
136 | static int | 136 | static int | |
137 | central_print(void *args, const char *busname) | 137 | central_print(void *args, const char *busname) | |
138 | { | 138 | { | |
139 | struct central_attach_args *ca = args; | 139 | struct central_attach_args *ca = args; | |
140 | char *class; | 140 | char *class; | |
141 | 141 | |||
142 | if (busname != NULL) { | 142 | if (busname != NULL) { | |
143 | printf("\"%s\" at %s", ca->ca_name, busname); | 143 | printf("\"%s\" at %s", ca->ca_name, busname); | |
144 | class = prom_getpropstring(ca->ca_node, "device_type"); | 144 | class = prom_getpropstring(ca->ca_node, "device_type"); | |
145 | if (*class != '\0') | 145 | if (*class != '\0') | |
146 | printf(" class %s", class); | 146 | printf(" class %s", class); | |
147 | } | 147 | } | |
148 | return (UNCONF); | 148 | return (UNCONF); | |
149 | } | 149 | } | |
150 | 150 | |||
151 | static bus_space_tag_t | 151 | static bus_space_tag_t | |
152 | central_alloc_bus_tag(struct central_softc *sc) | 152 | central_alloc_bus_tag(struct central_softc *sc) | |
153 | { | 153 | { | |
154 | struct sparc_bus_space_tag *bt; | 154 | struct sparc_bus_space_tag *bt; | |
155 | 155 | |||
156 | bt = malloc(sizeof(*bt), M_DEVBUF, M_NOWAIT | M_ZERO); | 156 | bt = malloc(sizeof(*bt), M_DEVBUF, M_NOWAIT | M_ZERO); | |
157 | if (bt == NULL) | 157 | if (bt == NULL) | |
158 | panic("central: couldn't alloc bus tag"); | 158 | panic("central: couldn't alloc bus tag"); | |
159 | 159 | |||
160 | bt->cookie = sc; | 160 | bt->cookie = sc; | |
161 | bt->parent = sc->sc_bt; | 161 | bt->parent = sc->sc_bt; | |
162 | #if 0 | 162 | #if 0 | |
163 | bt->asi = bt->parent->asi; | 163 | bt->asi = bt->parent->asi; | |
164 | bt->sasi = bt->parent->sasi; | 164 | bt->sasi = bt->parent->sasi; | |
165 | #endif | 165 | #endif | |
166 | bt->sparc_bus_map = _central_bus_map; | 166 | bt->sparc_bus_map = _central_bus_map; | |
167 | /* XXX bt->sparc_bus_mmap = central_bus_mmap; */ | 167 | /* XXX bt->sparc_bus_mmap = central_bus_mmap; */ | |
168 | /* XXX bt->sparc_intr_establish = upa_intr_establish; */ | 168 | /* XXX bt->sparc_intr_establish = upa_intr_establish; */ | |
169 | return (bt); | 169 | return (bt); | |
170 | } | 170 | } | |
171 | 171 | |||
172 | static int | 172 | static int | |
173 | _central_bus_map(bus_space_tag_t t, bus_addr_t addr, bus_size_t size, int flags, | 173 | _central_bus_map(bus_space_tag_t t, bus_addr_t addr, bus_size_t size, int flags, | |
174 | vaddr_t v, bus_space_handle_t *hp) | 174 | vaddr_t v, bus_space_handle_t *hp) | |
175 | { | 175 | { | |
176 | struct central_softc *sc = t->cookie; | 176 | struct central_softc *sc = t->cookie; | |
177 | int64_t slot = BUS_ADDR_IOSPACE(addr); | 177 | int64_t slot = BUS_ADDR_IOSPACE(addr); | |
178 | int64_t offset = BUS_ADDR_PADDR(addr); | 178 | int64_t offset = BUS_ADDR_PADDR(addr); | |
179 | int i; | 179 | int i; | |
180 | 180 | |||
181 | if (t->parent == NULL || t->parent->sparc_bus_map == NULL) { | 181 | if (t->parent == NULL || t->parent->sparc_bus_map == NULL) { | |
182 | printf("\ncentral_bus_map: invalid parent"); | 182 | printf("\ncentral_bus_map: invalid parent"); | |
183 | return (EINVAL); | 183 | return (EINVAL); | |
184 | } | 184 | } | |
185 | 185 | |||
186 | 186 | |||
187 | for (i = 0; i < sc->sc_nrange; i++) { | 187 | for (i = 0; i < sc->sc_nrange; i++) { | |
188 | bus_addr_t paddr; | 188 | bus_addr_t paddr; | |
189 | 189 | |||
190 | if (sc->sc_range[i].cspace != slot) | 190 | if (sc->sc_range[i].cspace != slot) | |
191 | continue; | 191 | continue; | |
192 | 192 | |||
193 | paddr = offset - sc->sc_range[i].coffset; | 193 | paddr = offset - sc->sc_range[i].coffset; | |
194 | paddr += sc->sc_range[i].poffset; | 194 | paddr += sc->sc_range[i].poffset; | |
195 | paddr |= ((bus_addr_t)sc->sc_range[i].pspace << 32); | 195 | paddr |= ((bus_addr_t)sc->sc_range[i].pspace << 32); | |
196 | 196 | |||
197 | return bus_space_map(t->parent, paddr, size, flags, hp); | 197 | return bus_space_map(t->parent, paddr, size, flags, hp); | |
198 | } | 198 | } | |
199 | 199 | |||
200 | return (EINVAL); | 200 | return (EINVAL); | |
201 | } | 201 | } |
--- src/sys/arch/sparc64/dev/fhc_central.c 2011/07/29 08:37:36 1.1
+++ src/sys/arch/sparc64/dev/fhc_central.c 2011/08/01 08:36:39 1.2
@@ -1,120 +1,120 @@ | @@ -1,120 +1,120 @@ | |||
1 | /* $NetBSD: fhc_central.c,v 1.1 2011/07/29 08:37:36 mrg Exp $ */ | 1 | /* $NetBSD: fhc_central.c,v 1.2 2011/08/01 08:36:39 mrg Exp $ */ | |
2 | /* $OpenBSD: fhc_central.c,v 1.5 2004/09/27 18:32:35 jason Exp $ */ | 2 | /* $OpenBSD: fhc_central.c,v 1.5 2004/09/27 18:32:35 jason Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (c) 2004 Jason L. Wright (jason@thought.net). | 5 | * Copyright (c) 2004 Jason L. Wright (jason@thought.net). | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
15 | * documentation and/or other materials provided with the distribution. | 15 | * documentation and/or other materials provided with the distribution. | |
16 | * | 16 | * | |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
20 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | 20 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | |
21 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 21 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
25 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | 25 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
26 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 26 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
27 | * POSSIBILITY OF SUCH DAMAGE. | 27 | * POSSIBILITY OF SUCH DAMAGE. | |
28 | */ | 28 | */ | |
29 | 29 | |||
30 | #include <sys/types.h> | 30 | #include <sys/types.h> | |
31 | #include <sys/param.h> | 31 | #include <sys/param.h> | |
32 | #include <sys/systm.h> | 32 | #include <sys/systm.h> | |
33 | #include <sys/kernel.h> | 33 | #include <sys/kernel.h> | |
34 | #include <sys/device.h> | 34 | #include <sys/device.h> | |
35 | #include <sys/conf.h> | 35 | #include <sys/conf.h> | |
36 | #include <sys/bus.h> | 36 | #include <sys/bus.h> | |
37 | 37 | |||
38 | #include <machine/autoconf.h> | 38 | #include <machine/autoconf.h> | |
39 | #include <machine/openfirm.h> | 39 | #include <machine/openfirm.h> | |
40 | 40 | |||
41 | #include <sparc64/dev/centralvar.h> | 41 | #include <sparc64/dev/centralvar.h> | |
42 | #include <sparc64/dev/fhcreg.h> | 42 | #include <sparc64/dev/fhcreg.h> | |
43 | #include <sparc64/dev/fhcvar.h> | 43 | #include <sparc64/dev/fhcvar.h> | |
44 | 44 | |||
45 | int fhc_central_match(device_t, cfdata_t, void *); | 45 | int fhc_central_match(device_t, cfdata_t, void *); | |
46 | void fhc_central_attach(device_t, device_t, void *); | 46 | void fhc_central_attach(device_t, device_t, void *); | |
47 | 47 | |||
48 | CFATTACH_DECL_NEW(fhc_central, sizeof(struct fhc_softc), | 48 | CFATTACH_DECL_NEW(fhc_central, sizeof(struct fhc_softc), | |
49 | fhc_central_match, fhc_central_attach, NULL, NULL); | 49 | fhc_central_match, fhc_central_attach, NULL, NULL); | |
50 | 50 | |||
51 | int | 51 | int | |
52 | fhc_central_match(device_t parent, cfdata_t match, void *aux) | 52 | fhc_central_match(device_t parent, cfdata_t match, void *aux) | |
53 | { | 53 | { | |
54 | struct central_attach_args *ca = aux; | 54 | struct central_attach_args *ca = aux; | |
55 | 55 | |||
56 | if (strcmp(ca->ca_name, "fhc") == 0) | 56 | if (strcmp(ca->ca_name, "fhc") == 0) | |
57 | return (1); | 57 | return (1); | |
58 | return (0); | 58 | return (0); | |
59 | } | 59 | } | |
60 | 60 | |||
61 | void | 61 | void | |
62 | fhc_central_attach(device_t parent, device_t self, void *aux) | 62 | fhc_central_attach(device_t parent, device_t self, void *aux) | |
63 | { | 63 | { | |
64 | struct fhc_softc *sc = (struct fhc_softc *)self; | 64 | struct fhc_softc *sc = device_private(self); | |
65 | struct central_attach_args *ca = aux; | 65 | struct central_attach_args *ca = aux; | |
66 | u_int32_t board; | 66 | u_int32_t board; | |
67 | 67 | |||
68 | sc->sc_node = ca->ca_node; | 68 | sc->sc_node = ca->ca_node; | |
69 | sc->sc_bt = ca->ca_bustag; | 69 | sc->sc_bt = ca->ca_bustag; | |
70 | sc->sc_is_central = 1; | 70 | sc->sc_is_central = 1; | |
71 | 71 | |||
72 | if (central_bus_map(sc->sc_bt, ca->ca_reg[0].cbr_slot, | 72 | if (central_bus_map(sc->sc_bt, ca->ca_reg[0].cbr_slot, | |
73 | ca->ca_reg[0].cbr_offset, ca->ca_reg[0].cbr_size, 0, | 73 | ca->ca_reg[0].cbr_offset, ca->ca_reg[0].cbr_size, 0, | |
74 | &sc->sc_preg)) { | 74 | &sc->sc_preg)) { | |
75 | printf(": failed to map preg\n"); | 75 | printf(": failed to map preg\n"); | |
76 | return; | 76 | return; | |
77 | } | 77 | } | |
78 | 78 | |||
79 | if (central_bus_map(sc->sc_bt, ca->ca_reg[1].cbr_slot, | 79 | if (central_bus_map(sc->sc_bt, ca->ca_reg[1].cbr_slot, | |
80 | ca->ca_reg[1].cbr_offset, ca->ca_reg[1].cbr_size, 0, | 80 | ca->ca_reg[1].cbr_offset, ca->ca_reg[1].cbr_size, 0, | |
81 | &sc->sc_ireg)) { | 81 | &sc->sc_ireg)) { | |
82 | printf(": failed to map ireg\n"); | 82 | printf(": failed to map ireg\n"); | |
83 | return; | 83 | return; | |
84 | } | 84 | } | |
85 | 85 | |||
86 | if (central_bus_map(sc->sc_bt, ca->ca_reg[2].cbr_slot, | 86 | if (central_bus_map(sc->sc_bt, ca->ca_reg[2].cbr_slot, | |
87 | ca->ca_reg[2].cbr_offset, ca->ca_reg[2].cbr_size, | 87 | ca->ca_reg[2].cbr_offset, ca->ca_reg[2].cbr_size, | |
88 | BUS_SPACE_MAP_LINEAR, &sc->sc_freg)) { | 88 | BUS_SPACE_MAP_LINEAR, &sc->sc_freg)) { | |
89 | printf(": failed to map freg\n"); | 89 | printf(": failed to map freg\n"); | |
90 | return; | 90 | return; | |
91 | } | 91 | } | |
92 | 92 | |||
93 | if (central_bus_map(sc->sc_bt, ca->ca_reg[3].cbr_slot, | 93 | if (central_bus_map(sc->sc_bt, ca->ca_reg[3].cbr_slot, | |
94 | ca->ca_reg[3].cbr_offset, ca->ca_reg[3].cbr_size, | 94 | ca->ca_reg[3].cbr_offset, ca->ca_reg[3].cbr_size, | |
95 | BUS_SPACE_MAP_LINEAR, &sc->sc_sreg)) { | 95 | BUS_SPACE_MAP_LINEAR, &sc->sc_sreg)) { | |
96 | printf(": failed to map sreg\n"); | 96 | printf(": failed to map sreg\n"); | |
97 | return; | 97 | return; | |
98 | } | 98 | } | |
99 | 99 | |||
100 | if (central_bus_map(sc->sc_bt, ca->ca_reg[4].cbr_slot, | 100 | if (central_bus_map(sc->sc_bt, ca->ca_reg[4].cbr_slot, | |
101 | ca->ca_reg[4].cbr_offset, ca->ca_reg[4].cbr_size, | 101 | ca->ca_reg[4].cbr_offset, ca->ca_reg[4].cbr_size, | |
102 | BUS_SPACE_MAP_LINEAR, &sc->sc_ureg)) { | 102 | BUS_SPACE_MAP_LINEAR, &sc->sc_ureg)) { | |
103 | printf(": failed to map ureg\n"); | 103 | printf(": failed to map ureg\n"); | |
104 | return; | 104 | return; | |
105 | } | 105 | } | |
106 | 106 | |||
107 | if (central_bus_map(sc->sc_bt, ca->ca_reg[5].cbr_slot, | 107 | if (central_bus_map(sc->sc_bt, ca->ca_reg[5].cbr_slot, | |
108 | ca->ca_reg[5].cbr_offset, ca->ca_reg[5].cbr_size, | 108 | ca->ca_reg[5].cbr_offset, ca->ca_reg[5].cbr_size, | |
109 | BUS_SPACE_MAP_LINEAR, &sc->sc_treg)) { | 109 | BUS_SPACE_MAP_LINEAR, &sc->sc_treg)) { | |
110 | printf(": failed to map treg\n"); | 110 | printf(": failed to map treg\n"); | |
111 | return; | 111 | return; | |
112 | } | 112 | } | |
113 | 113 | |||
114 | board = bus_space_read_4(sc->sc_bt, sc->sc_preg, FHC_P_BSR); | 114 | board = bus_space_read_4(sc->sc_bt, sc->sc_preg, FHC_P_BSR); | |
115 | sc->sc_board = ((board >> 16) & 0x1) | ((board >> 12) & 0xe); | 115 | sc->sc_board = ((board >> 16) & 0x1) | ((board >> 12) & 0xe); | |
116 | sc->sc_dev = self; | 116 | sc->sc_dev = self; | |
117 | 117 | |||
118 | fhc_attach(sc); | 118 | fhc_attach(sc); | |
119 | return; | 119 | return; | |
120 | } | 120 | } |
--- src/sys/arch/sparc64/dev/fhc_mainbus.c 2011/07/29 08:37:36 1.1
+++ src/sys/arch/sparc64/dev/fhc_mainbus.c 2011/08/01 08:36:39 1.2
@@ -1,111 +1,111 @@ | @@ -1,111 +1,111 @@ | |||
1 | /* $NetBSD: fhc_mainbus.c,v 1.1 2011/07/29 08:37:36 mrg Exp $ */ | 1 | /* $NetBSD: fhc_mainbus.c,v 1.2 2011/08/01 08:36:39 mrg Exp $ */ | |
2 | /* $OpenBSD: fhc_mainbus.c,v 1.4 2004/09/27 18:32:35 jason Exp $ */ | 2 | /* $OpenBSD: fhc_mainbus.c,v 1.4 2004/09/27 18:32:35 jason Exp $ */ | |
3 | 3 | |||
4 | /* | 4 | /* | |
5 | * Copyright (c) 2004 Jason L. Wright (jason@thought.net). | 5 | * Copyright (c) 2004 Jason L. Wright (jason@thought.net). | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | 10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | 11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | 12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the | |
15 | * documentation and/or other materials provided with the distribution. | 15 | * documentation and/or other materials provided with the distribution. | |
16 | * | 16 | * | |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
20 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | 20 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | |
21 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 21 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
25 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | 25 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
26 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 26 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
27 | * POSSIBILITY OF SUCH DAMAGE. | 27 | * POSSIBILITY OF SUCH DAMAGE. | |
28 | */ | 28 | */ | |
29 | 29 | |||
30 | #include <sys/types.h> | 30 | #include <sys/types.h> | |
31 | #include <sys/param.h> | 31 | #include <sys/param.h> | |
32 | #include <sys/systm.h> | 32 | #include <sys/systm.h> | |
33 | #include <sys/kernel.h> | 33 | #include <sys/kernel.h> | |
34 | #include <sys/device.h> | 34 | #include <sys/device.h> | |
35 | #include <sys/conf.h> | 35 | #include <sys/conf.h> | |
36 | #include <sys/bus.h> | 36 | #include <sys/bus.h> | |
37 | 37 | |||
38 | #include <machine/autoconf.h> | 38 | #include <machine/autoconf.h> | |
39 | #include <machine/openfirm.h> | 39 | #include <machine/openfirm.h> | |
40 | 40 | |||
41 | #include <sparc64/dev/fhcvar.h> | 41 | #include <sparc64/dev/fhcvar.h> | |
42 | 42 | |||
43 | int fhc_mainbus_match(device_t, cfdata_t, void *); | 43 | int fhc_mainbus_match(device_t, cfdata_t, void *); | |
44 | void fhc_mainbus_attach(device_t, device_t, void *); | 44 | void fhc_mainbus_attach(device_t, device_t, void *); | |
45 | 45 | |||
46 | CFATTACH_DECL_NEW(fhc_mainbus, sizeof(struct fhc_softc), | 46 | CFATTACH_DECL_NEW(fhc_mainbus, sizeof(struct fhc_softc), | |
47 | fhc_mainbus_match, fhc_mainbus_attach, NULL, NULL); | 47 | fhc_mainbus_match, fhc_mainbus_attach, NULL, NULL); | |
48 | 48 | |||
49 | int | 49 | int | |
50 | fhc_mainbus_match(device_t parent, cfdata_t match, void *aux) | 50 | fhc_mainbus_match(device_t parent, cfdata_t match, void *aux) | |
51 | { | 51 | { | |
52 | struct mainbus_attach_args *ma = aux; | 52 | struct mainbus_attach_args *ma = aux; | |
53 | 53 | |||
54 | if (strcmp(ma->ma_name, "fhc") == 0) | 54 | if (strcmp(ma->ma_name, "fhc") == 0) | |
55 | return (1); | 55 | return (1); | |
56 | return (0); | 56 | return (0); | |
57 | } | 57 | } | |
58 | 58 | |||
59 | void | 59 | void | |
60 | fhc_mainbus_attach(device_t parent, device_t self, void *aux) | 60 | fhc_mainbus_attach(device_t parent, device_t self, void *aux) | |
61 | { | 61 | { | |
62 | struct fhc_softc *sc = (struct fhc_softc *)self; | 62 | struct fhc_softc *sc = device_private(self); | |
63 | struct mainbus_attach_args *ma = aux; | 63 | struct mainbus_attach_args *ma = aux; | |
64 | 64 | |||
65 | sc->sc_node = ma->ma_node; | 65 | sc->sc_node = ma->ma_node; | |
66 | sc->sc_bt = ma->ma_bustag; | 66 | sc->sc_bt = ma->ma_bustag; | |
67 | sc->sc_is_central = 0; | 67 | sc->sc_is_central = 0; | |
68 | 68 | |||
69 | if (bus_space_map(sc->sc_bt, ma->ma_reg[0].ur_paddr, | 69 | if (bus_space_map(sc->sc_bt, ma->ma_reg[0].ur_paddr, | |
70 | ma->ma_reg[0].ur_len, 0, &sc->sc_preg)) { | 70 | ma->ma_reg[0].ur_len, 0, &sc->sc_preg)) { | |
71 | printf(": failed to map preg\n"); | 71 | printf(": failed to map preg\n"); | |
72 | return; | 72 | return; | |
73 | } | 73 | } | |
74 | 74 | |||
75 | if (bus_space_map(sc->sc_bt, ma->ma_reg[1].ur_paddr, | 75 | if (bus_space_map(sc->sc_bt, ma->ma_reg[1].ur_paddr, | |
76 | ma->ma_reg[1].ur_len, 0, &sc->sc_ireg)) { | 76 | ma->ma_reg[1].ur_len, 0, &sc->sc_ireg)) { | |
77 | printf(": failed to map ireg\n"); | 77 | printf(": failed to map ireg\n"); | |
78 | return; | 78 | return; | |
79 | } | 79 | } | |
80 | 80 | |||
81 | if (bus_space_map(sc->sc_bt, ma->ma_reg[2].ur_paddr, | 81 | if (bus_space_map(sc->sc_bt, ma->ma_reg[2].ur_paddr, | |
82 | ma->ma_reg[2].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_freg)) { | 82 | ma->ma_reg[2].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_freg)) { | |
83 | printf(": failed to map freg\n"); | 83 | printf(": failed to map freg\n"); | |
84 | return; | 84 | return; | |
85 | } | 85 | } | |
86 | 86 | |||
87 | if (bus_space_map(sc->sc_bt, ma->ma_reg[3].ur_paddr, | 87 | if (bus_space_map(sc->sc_bt, ma->ma_reg[3].ur_paddr, | |
88 | ma->ma_reg[3].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_sreg)) { | 88 | ma->ma_reg[3].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_sreg)) { | |
89 | printf(": failed to map sreg\n"); | 89 | printf(": failed to map sreg\n"); | |
90 | return; | 90 | return; | |
91 | } | 91 | } | |
92 | 92 | |||
93 | if (bus_space_map(sc->sc_bt, ma->ma_reg[4].ur_paddr, | 93 | if (bus_space_map(sc->sc_bt, ma->ma_reg[4].ur_paddr, | |
94 | ma->ma_reg[4].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_ureg)) { | 94 | ma->ma_reg[4].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_ureg)) { | |
95 | printf(": failed to map ureg\n"); | 95 | printf(": failed to map ureg\n"); | |
96 | return; | 96 | return; | |
97 | } | 97 | } | |
98 | 98 | |||
99 | if (bus_space_map(sc->sc_bt, ma->ma_reg[5].ur_paddr, | 99 | if (bus_space_map(sc->sc_bt, ma->ma_reg[5].ur_paddr, | |
100 | ma->ma_reg[5].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_treg)) { | 100 | ma->ma_reg[5].ur_len, BUS_SPACE_MAP_LINEAR, &sc->sc_treg)) { | |
101 | printf(": failed to map treg\n"); | 101 | printf(": failed to map treg\n"); | |
102 | return; | 102 | return; | |
103 | } | 103 | } | |
104 | 104 | |||
105 | sc->sc_board = prom_getpropint(sc->sc_node, "board#", -1); | 105 | sc->sc_board = prom_getpropint(sc->sc_node, "board#", -1); | |
106 | sc->sc_dev = self; | 106 | sc->sc_dev = self; | |
107 | 107 | |||
108 | fhc_attach(sc); | 108 | fhc_attach(sc); | |
109 | 109 | |||
110 | return; | 110 | return; | |
111 | } | 111 | } |