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