sgc.c revision 1.2.6.2 1 1.2.6.2 jruoho /* $NetBSD: sgc.c,v 1.2.6.2 2011/06/06 09:05:36 jruoho Exp $ */
2 1.2.6.2 jruoho /* $OpenBSD: sgc.c,v 1.6 2010/04/15 20:35:21 miod Exp $ */
3 1.2.6.2 jruoho
4 1.2.6.2 jruoho /*
5 1.2.6.2 jruoho * Copyright (c) 2005, Miodrag Vallat
6 1.2.6.2 jruoho *
7 1.2.6.2 jruoho * Redistribution and use in source and binary forms, with or without
8 1.2.6.2 jruoho * modification, are permitted provided that the following conditions
9 1.2.6.2 jruoho * are met:
10 1.2.6.2 jruoho * 1. Redistributions of source code must retain the above copyright
11 1.2.6.2 jruoho * notice, this list of conditions and the following disclaimer.
12 1.2.6.2 jruoho * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.6.2 jruoho * notice, this list of conditions and the following disclaimer in the
14 1.2.6.2 jruoho * documentation and/or other materials provided with the distribution.
15 1.2.6.2 jruoho *
16 1.2.6.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.2.6.2 jruoho * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 1.2.6.2 jruoho * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 1.2.6.2 jruoho * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 1.2.6.2 jruoho * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 1.2.6.2 jruoho * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 1.2.6.2 jruoho * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.2.6.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 1.2.6.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 1.2.6.2 jruoho * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.2.6.2 jruoho * POSSIBILITY OF SUCH DAMAGE.
27 1.2.6.2 jruoho *
28 1.2.6.2 jruoho */
29 1.2.6.2 jruoho
30 1.2.6.2 jruoho /*
31 1.2.6.2 jruoho * SGC bus attachment and mapping glue.
32 1.2.6.2 jruoho */
33 1.2.6.2 jruoho
34 1.2.6.2 jruoho #include <sys/param.h>
35 1.2.6.2 jruoho #include <sys/systm.h>
36 1.2.6.2 jruoho #include <sys/device.h>
37 1.2.6.2 jruoho #include <sys/kernel.h>
38 1.2.6.2 jruoho #include <sys/bus.h>
39 1.2.6.2 jruoho #include <sys/cpu.h>
40 1.2.6.2 jruoho
41 1.2.6.2 jruoho #include <machine/autoconf.h>
42 1.2.6.2 jruoho #include <machine/hp300spu.h>
43 1.2.6.2 jruoho
44 1.2.6.2 jruoho #include <hp300/dev/sgcreg.h>
45 1.2.6.2 jruoho #include <hp300/dev/sgcvar.h>
46 1.2.6.2 jruoho
47 1.2.6.2 jruoho #ifdef SGC_DEBUG
48 1.2.6.2 jruoho #define DPRINTF(x) printf x
49 1.2.6.2 jruoho #else
50 1.2.6.2 jruoho #define DPRINTF(x) do {} while (/* CONSTCOND */ 0)
51 1.2.6.2 jruoho #endif
52 1.2.6.2 jruoho
53 1.2.6.2 jruoho struct sgc_softc {
54 1.2.6.2 jruoho device_t sc_dev;
55 1.2.6.2 jruoho struct bus_space_tag sc_tag;
56 1.2.6.2 jruoho };
57 1.2.6.2 jruoho
58 1.2.6.2 jruoho static int sgcmatch(device_t, cfdata_t, void *);
59 1.2.6.2 jruoho static void sgcattach(device_t, device_t, void *);
60 1.2.6.2 jruoho static int sgcprint(void *, const char *);
61 1.2.6.2 jruoho
62 1.2.6.2 jruoho CFATTACH_DECL_NEW(sgc, sizeof(struct sgc_softc),
63 1.2.6.2 jruoho sgcmatch, sgcattach, NULL, NULL);
64 1.2.6.2 jruoho
65 1.2.6.2 jruoho int
66 1.2.6.2 jruoho sgcmatch(device_t parent, cfdata_t cf, void *aux)
67 1.2.6.2 jruoho {
68 1.2.6.2 jruoho static int sgc_matched = 0;
69 1.2.6.2 jruoho
70 1.2.6.2 jruoho /* Allow only one instance. */
71 1.2.6.2 jruoho if (sgc_matched)
72 1.2.6.2 jruoho return 0;
73 1.2.6.2 jruoho
74 1.2.6.2 jruoho /*
75 1.2.6.2 jruoho * Leave out machines which can not have an SGC bus.
76 1.2.6.2 jruoho */
77 1.2.6.2 jruoho
78 1.2.6.2 jruoho switch (machineid) {
79 1.2.6.2 jruoho #if 0
80 1.2.6.2 jruoho case HP_362:
81 1.2.6.2 jruoho case HP_382:
82 1.2.6.2 jruoho #endif
83 1.2.6.2 jruoho case HP_400:
84 1.2.6.2 jruoho case HP_425:
85 1.2.6.2 jruoho case HP_433:
86 1.2.6.2 jruoho return sgc_matched = 1;
87 1.2.6.2 jruoho default:
88 1.2.6.2 jruoho return 0;
89 1.2.6.2 jruoho }
90 1.2.6.2 jruoho }
91 1.2.6.2 jruoho
92 1.2.6.2 jruoho void
93 1.2.6.2 jruoho sgcattach(device_t parent, device_t self, void *aux)
94 1.2.6.2 jruoho {
95 1.2.6.2 jruoho struct sgc_softc *sc;
96 1.2.6.2 jruoho struct sgc_attach_args saa;
97 1.2.6.2 jruoho paddr_t pa;
98 1.2.6.2 jruoho void *va;
99 1.2.6.2 jruoho int slot, rv;
100 1.2.6.2 jruoho bus_space_tag_t bst;
101 1.2.6.2 jruoho bus_space_handle_t bsh;
102 1.2.6.2 jruoho
103 1.2.6.2 jruoho sc = device_private(self);
104 1.2.6.2 jruoho sc->sc_dev = self;
105 1.2.6.2 jruoho aprint_normal("\n");
106 1.2.6.2 jruoho
107 1.2.6.2 jruoho bst = &sc->sc_tag;
108 1.2.6.2 jruoho memset(bst, 0, sizeof(struct bus_space_tag));
109 1.2.6.2 jruoho bst->bustype = HP300_BUS_SPACE_SGC;
110 1.2.6.2 jruoho
111 1.2.6.2 jruoho for (slot = 0; slot < SGC_NSLOTS; slot++) {
112 1.2.6.2 jruoho pa = sgc_slottopa(slot);
113 1.2.6.2 jruoho if (bus_space_map(bst, pa, PAGE_SIZE, 0, &bsh) != 0) {
114 1.2.6.2 jruoho aprint_error_dev(self, "can't map slot %d\n", slot);
115 1.2.6.2 jruoho continue;
116 1.2.6.2 jruoho }
117 1.2.6.2 jruoho va = bus_space_vaddr(bst, bsh);
118 1.2.6.2 jruoho
119 1.2.6.2 jruoho /* Check for hardware. */
120 1.2.6.2 jruoho rv = badaddr(va);
121 1.2.6.2 jruoho bus_space_unmap(bst, bsh, PAGE_SIZE);
122 1.2.6.2 jruoho
123 1.2.6.2 jruoho if (rv != 0) {
124 1.2.6.2 jruoho DPRINTF(("%s: no valid device at slot %d\n",
125 1.2.6.2 jruoho device_xname(self), slot));
126 1.2.6.2 jruoho continue;
127 1.2.6.2 jruoho }
128 1.2.6.2 jruoho
129 1.2.6.2 jruoho memset(&saa, 0, sizeof(saa));
130 1.2.6.2 jruoho saa.saa_iot = bst;
131 1.2.6.2 jruoho saa.saa_slot = slot;
132 1.2.6.2 jruoho
133 1.2.6.2 jruoho /* Attach matching device. */
134 1.2.6.2 jruoho config_found(self, &saa, sgcprint);
135 1.2.6.2 jruoho }
136 1.2.6.2 jruoho }
137 1.2.6.2 jruoho
138 1.2.6.2 jruoho int
139 1.2.6.2 jruoho sgcprint(void *aux, const char *pnp)
140 1.2.6.2 jruoho {
141 1.2.6.2 jruoho struct sgc_attach_args *saa = aux;
142 1.2.6.2 jruoho
143 1.2.6.2 jruoho if (pnp)
144 1.2.6.2 jruoho aprint_normal("unknown SGC card at %s", pnp);
145 1.2.6.2 jruoho aprint_normal(" slot %d", saa->saa_slot);
146 1.2.6.2 jruoho return UNCONF;
147 1.2.6.2 jruoho }
148 1.2.6.2 jruoho
149 1.2.6.2 jruoho /*
150 1.2.6.2 jruoho * Convert a slot number to a system physical address.
151 1.2.6.2 jruoho * This is needed for bus_space.
152 1.2.6.2 jruoho */
153 1.2.6.2 jruoho paddr_t
154 1.2.6.2 jruoho sgc_slottopa(int slot)
155 1.2.6.2 jruoho {
156 1.2.6.2 jruoho paddr_t rval;
157 1.2.6.2 jruoho
158 1.2.6.2 jruoho if (slot < 0 || slot >= SGC_NSLOTS)
159 1.2.6.2 jruoho rval = 0;
160 1.2.6.2 jruoho else
161 1.2.6.2 jruoho rval = SGC_BASE + (slot * SGC_DEVSIZE);
162 1.2.6.2 jruoho
163 1.2.6.2 jruoho return rval;
164 1.2.6.2 jruoho }
165