Annotation of sys/arch/hp300/dev/sti_sgc.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: sti_sgc.c,v 1.14 2007/05/26 00:36:03 krw Exp $ */
2:
3: /*
4: * Copyright (c) 2005, Miodrag Vallat
5: *
6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
9: * 1. Redistributions of source code must retain the above copyright
10: * notice, this list of conditions and the following disclaimer.
11: * 2. Redistributions in binary form must reproduce the above copyright
12: * notice, this list of conditions and the following disclaimer in the
13: * documentation and/or other materials provided with the distribution.
14: *
15: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18: * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25: * POSSIBILITY OF SUCH DAMAGE.
26: *
27: */
28:
29: #include <sys/param.h>
30: #include <sys/systm.h>
31: #include <sys/conf.h>
32: #include <sys/device.h>
33:
34: #include <machine/autoconf.h>
35: #include <machine/bus.h>
36: #include <machine/cpu.h>
37:
38: #include <hp300/dev/sgcreg.h>
39: #include <hp300/dev/sgcvar.h>
40:
41: #include <dev/wscons/wsdisplayvar.h>
42: #include <dev/wscons/wsconsio.h>
43:
44: #include <dev/ic/stireg.h>
45: #include <dev/ic/stivar.h>
46:
47: #include <uvm/uvm_extern.h>
48:
49: void sti_sgc_attach(struct device *, struct device *, void *);
50: int sti_sgc_match(struct device *, void *, void *);
51: int sti_sgc_probe(bus_space_tag_t, int);
52:
53: struct cfattach sti_sgc_ca = {
54: sizeof(struct sti_softc), sti_sgc_match, sti_sgc_attach
55: };
56:
57: /* Console data */
58: struct sti_screen stifb_cn;
59: bus_addr_t stifb_cn_bases[STI_REGION_MAX];
60:
61: int
62: sti_sgc_match(struct device *parent, void *match, void *aux)
63: {
64: struct sgc_attach_args *saa = aux;
65:
66: /*
67: * If we already probed it successfully as a console device, go ahead,
68: * since we will not be able to bus_space_map() again.
69: */
70: if (SGC_SLOT_TO_CONSCODE(saa->saa_slot) == conscode)
71: return (1);
72:
73: return (sti_sgc_probe(saa->saa_iot, saa->saa_slot));
74: }
75:
76: void
77: sti_sgc_attach(struct device *parent, struct device *self, void *aux)
78: {
79: struct sti_softc *sc = (void *)self;
80: struct sgc_attach_args *saa = aux;
81: bus_addr_t base;
82: bus_space_handle_t ioh;
83: u_int romend;
84: int i;
85:
86: /*
87: * If we already probed it successfully as a console device, go ahead,
88: * since we will not be able to bus_space_map() again.
89: */
90: if (SGC_SLOT_TO_CONSCODE(saa->saa_slot) == conscode) {
91: sc->sc_flags |= STI_CONSOLE | STI_ATTACHED;
92: sc->sc_scr = &stifb_cn;
93: bcopy(stifb_cn_bases, sc->bases, sizeof(sc->bases));
94:
95: sti_describe(sc);
96: } else {
97: base = (bus_addr_t)sgc_slottopa(saa->saa_slot);
98:
99: if (bus_space_map(saa->saa_iot, base, PAGE_SIZE, 0, &ioh)) {
100: printf(": can't map frame buffer");
101: return;
102: }
103:
104: /*
105: * Compute real PROM size
106: */
107: romend = sti_rom_size(saa->saa_iot, ioh);
108:
109: bus_space_unmap(saa->saa_iot, ioh, PAGE_SIZE);
110:
111: if (bus_space_map(saa->saa_iot, base, romend, 0, &ioh)) {
112: printf(": can't map frame buffer");
113: return;
114: }
115:
116: sc->memt = sc->iot = saa->saa_iot;
117: sc->romh = ioh;
118: sc->bases[0] = sc->romh;
119: for (i = 1; i < STI_REGION_MAX; i++)
120: sc->bases[i] = base;
121:
122: if (sti_attach_common(sc, STI_CODEBASE_M68K) != 0)
123: return;
124: }
125:
126: sti_end_attach(sc);
127: }
128:
129: int
130: sti_sgc_probe(bus_space_tag_t iot, int slot)
131: {
132: bus_space_handle_t ioh;
133: int devtype;
134:
135: if (bus_space_map(iot, (bus_addr_t)sgc_slottopa(slot),
136: PAGE_SIZE, 0, &ioh))
137: return (0);
138:
139: devtype = bus_space_read_1(iot, ioh, 3);
140:
141: bus_space_unmap(iot, ioh, PAGE_SIZE);
142:
143: /*
144: * This might not be reliable enough. On the other hand, non-STI
145: * SGC cards will apparently not initialize in an hp300, to the
146: * point of not even answering bus probes (checked with an
147: * Harmony/FDDI SGC card).
148: */
149: if (devtype != STI_DEVTYPE1 && devtype != STI_DEVTYPE4)
150: return (0);
151:
152: return (1);
153: }
154:
155: /*
156: * Console code
157: */
158:
159: int sti_console_scan(int);
160: void sticninit(void);
161:
162: int
163: sti_console_scan(int slot)
164: {
165: extern struct hp300_bus_space_tag hp300_mem_tag;
166: bus_space_tag_t iot;
167:
168: iot = &hp300_mem_tag;
169: return (sti_sgc_probe(iot, slot));
170: }
171:
172: void
173: sticninit()
174: {
175: extern struct hp300_bus_space_tag hp300_mem_tag;
176: bus_space_tag_t iot;
177: bus_addr_t base;
178: int i;
179:
180: /*
181: * We are not interested by the *first* console pass.
182: */
183: if (consolepass == 0)
184: return;
185:
186: iot = &hp300_mem_tag;
187: base = (bus_addr_t)sgc_slottopa(CONSCODE_TO_SGC_SLOT(conscode));
188:
189: /* stifb_cn_bases[0] will be fixed in sti_cnattach() */
190: for (i = 0; i < STI_REGION_MAX; i++)
191: stifb_cn_bases[i] = base;
192:
193: sti_cnattach(&stifb_cn, iot, stifb_cn_bases, STI_CODEBASE_M68K);
194: sti_clear(&stifb_cn);
195:
196: /*
197: * Since the copyright notice could not be displayed before,
198: * display it again now.
199: */
200: printf("%s\n", copyright);
201: }
CVSweb