ite_sti.c revision 1.1.2.2 1 1.1.2.2 rmind /* $NetBSD: ite_sti.c,v 1.1.2.2 2014/05/18 17:45:08 rmind Exp $ */
2 1.1.2.2 rmind /* $OpenBSD: ite_sti.c,v 1.2 2011/08/18 20:02:58 miod Exp $ */
3 1.1.2.2 rmind /*
4 1.1.2.2 rmind * Copyright (c) 2006, 2011, Miodrag Vallat
5 1.1.2.2 rmind * Copyright (c) 2000-2003 Michael Shalayeff
6 1.1.2.2 rmind * All rights reserved.
7 1.1.2.2 rmind *
8 1.1.2.2 rmind * Redistribution and use in source and binary forms, with or without
9 1.1.2.2 rmind * modification, are permitted provided that the following conditions
10 1.1.2.2 rmind * are met:
11 1.1.2.2 rmind * 1. Redistributions of source code must retain the above copyright
12 1.1.2.2 rmind * notice, this list of conditions and the following disclaimer.
13 1.1.2.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
14 1.1.2.2 rmind * notice, this list of conditions and the following disclaimer in the
15 1.1.2.2 rmind * documentation and/or other materials provided with the distribution.
16 1.1.2.2 rmind *
17 1.1.2.2 rmind * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1.2.2 rmind * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.1.2.2 rmind * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1.2.2 rmind * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
21 1.1.2.2 rmind * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 1.1.2.2 rmind * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 1.1.2.2 rmind * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.1.2.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 1.1.2.2 rmind * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26 1.1.2.2 rmind * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 1.1.2.2 rmind * THE POSSIBILITY OF SUCH DAMAGE.
28 1.1.2.2 rmind */
29 1.1.2.2 rmind
30 1.1.2.2 rmind #ifdef ITECONSOLE
31 1.1.2.2 rmind #include <sys/param.h>
32 1.1.2.2 rmind
33 1.1.2.2 rmind #include <lib/libsa/stand.h>
34 1.1.2.2 rmind
35 1.1.2.2 rmind #include <hp300/stand/common/samachdep.h>
36 1.1.2.2 rmind #include <hp300/stand/common/itevar.h>
37 1.1.2.2 rmind
38 1.1.2.2 rmind #if 0
39 1.1.2.2 rmind #include <hp300/dev/dioreg.h>
40 1.1.2.2 rmind #endif
41 1.1.2.2 rmind #include <hp300/dev/sgcreg.h>
42 1.1.2.2 rmind #include <dev/ic/stireg.h>
43 1.1.2.2 rmind
44 1.1.2.2 rmind /*
45 1.1.2.2 rmind * sti-specific data not available in the ite_data structure.
46 1.1.2.2 rmind * Since we will only configure one sti display, it is ok to use a global.
47 1.1.2.2 rmind */
48 1.1.2.2 rmind static struct {
49 1.1.2.2 rmind uint32_t codeptr[STI_CODECNT];
50 1.1.2.2 rmind uint8_t *code;
51 1.1.2.2 rmind uint32_t fontbase;
52 1.1.2.2 rmind u_int firstchar, lastchar;
53 1.1.2.2 rmind struct sti_cfg cfg;
54 1.1.2.2 rmind struct sti_ecfg ecfg;
55 1.1.2.2 rmind } sti;
56 1.1.2.2 rmind
57 1.1.2.2 rmind #define parseshort1(addr, ofs) \
58 1.1.2.2 rmind (((addr)[(ofs) + 3] << 8) | ((addr)[(ofs) + 7]))
59 1.1.2.2 rmind #define parseword1(addr, ofs) \
60 1.1.2.2 rmind (((addr)[(ofs) + 3] << 24) | ((addr)[(ofs) + 7] << 16) | \
61 1.1.2.2 rmind ((addr)[(ofs) + 11] << 8) | ((addr)[(ofs) + 15]))
62 1.1.2.2 rmind
63 1.1.2.2 rmind void sti_do_cursor(struct ite_data *);
64 1.1.2.2 rmind void sti_fontinfo(struct ite_data *);
65 1.1.2.2 rmind void sti_init(int);
66 1.1.2.2 rmind void sti_inqcfg(struct sti_inqconfout *);
67 1.1.2.2 rmind void sti_iteinit_common(struct ite_data *);
68 1.1.2.2 rmind
69 1.1.2.2 rmind #if 0 /* not yet */
70 1.1.2.2 rmind /* kinda similar to sti_dio_probe() */
71 1.1.2.2 rmind int
72 1.1.2.2 rmind sti_dio_probe(struct ite_data *ip)
73 1.1.2.2 rmind {
74 1.1.2.2 rmind int scode = ip->scode;
75 1.1.2.2 rmind uint8_t *id_reg;
76 1.1.2.2 rmind
77 1.1.2.2 rmind id_reg = (uint8_t *)sctoaddr(scode);
78 1.1.2.2 rmind if (id_reg[DIOII_SIZEOFF] < STI_DIO_SIZE - 1)
79 1.1.2.2 rmind return ENODEV;
80 1.1.2.2 rmind
81 1.1.2.2 rmind id_reg = (uint8_t *)sctoaddr(scode + STI_DIO_SCODE_OFFSET);
82 1.1.2.2 rmind if (id_reg[3] != STI_DEVTYPE1)
83 1.1.2.2 rmind return ENODEV;
84 1.1.2.2 rmind
85 1.1.2.2 rmind return 0;
86 1.1.2.2 rmind }
87 1.1.2.2 rmind
88 1.1.2.2 rmind void
89 1.1.2.2 rmind sti_iteinit_dio(struct ite_data *ip)
90 1.1.2.2 rmind {
91 1.1.2.2 rmind
92 1.1.2.2 rmind ip->fbbase = (caddr_t)sctoaddr(ip->scode + STI_DIO_SCODE_OFFSET);
93 1.1.2.2 rmind sti_iteinit_common(ip);
94 1.1.2.2 rmind }
95 1.1.2.2 rmind #endif
96 1.1.2.2 rmind
97 1.1.2.2 rmind void
98 1.1.2.2 rmind sti_iteinit_sgc(struct ite_data *ip)
99 1.1.2.2 rmind {
100 1.1.2.2 rmind
101 1.1.2.2 rmind ip->fbbase = (uint8_t *)IIOV(SGC_BASE + (ip->scode * SGC_DEVSIZE));
102 1.1.2.2 rmind sti_iteinit_common(ip);
103 1.1.2.2 rmind }
104 1.1.2.2 rmind
105 1.1.2.2 rmind /*
106 1.1.2.2 rmind * Initialize the sti device for ite's needs.
107 1.1.2.2 rmind * We don't bother to check for failures since
108 1.1.2.2 rmind * - we are in tight space already
109 1.1.2.2 rmind * - since romputchar() does not work with sti devices, there is no way we
110 1.1.2.2 rmind * can report errors (although we could switch to serial...)
111 1.1.2.2 rmind */
112 1.1.2.2 rmind void
113 1.1.2.2 rmind sti_iteinit_common(struct ite_data *ip)
114 1.1.2.2 rmind {
115 1.1.2.2 rmind int i;
116 1.1.2.2 rmind size_t codesize, memsize;
117 1.1.2.2 rmind uint8_t *va, *code;
118 1.1.2.2 rmind u_int addr, eaddr, reglist, tmp;
119 1.1.2.2 rmind struct sti_inqconfout cfg;
120 1.1.2.2 rmind struct sti_einqconfout ecfg;
121 1.1.2.2 rmind
122 1.1.2.2 rmind memset(&sti, 0, sizeof sti);
123 1.1.2.2 rmind va = (uint8_t *)ip->fbbase;
124 1.1.2.2 rmind
125 1.1.2.2 rmind /*
126 1.1.2.2 rmind * Read the microcode.
127 1.1.2.2 rmind */
128 1.1.2.2 rmind
129 1.1.2.2 rmind for (i = 0; i < STI_CODECNT; i++)
130 1.1.2.2 rmind sti.codeptr[i] =
131 1.1.2.2 rmind parseword1(va, (STI_CODEBASE_M68K << 2) + i * 0x10);
132 1.1.2.2 rmind
133 1.1.2.2 rmind for (i = STI_END; sti.codeptr[i] == 0; i--)
134 1.1.2.2 rmind continue;
135 1.1.2.2 rmind codesize = sti.codeptr[i] - sti.codeptr[STI_BEGIN];
136 1.1.2.2 rmind codesize = (codesize + 3) / 4;
137 1.1.2.2 rmind
138 1.1.2.2 rmind sti.code = (uint8_t *)alloc(codesize);
139 1.1.2.2 rmind code = sti.code;
140 1.1.2.2 rmind addr = (u_int)va + sti.codeptr[STI_BEGIN];
141 1.1.2.2 rmind eaddr = addr + codesize * 4;
142 1.1.2.2 rmind for (; addr < eaddr; addr += 4)
143 1.1.2.2 rmind *code++ = *(uint8_t *)addr;
144 1.1.2.2 rmind
145 1.1.2.2 rmind for (i = STI_CODECNT - 1; i != 0; i--)
146 1.1.2.2 rmind if (sti.codeptr[i] != 0) {
147 1.1.2.2 rmind sti.codeptr[i] -= sti.codeptr[0];
148 1.1.2.2 rmind sti.codeptr[i] /= 4;
149 1.1.2.2 rmind }
150 1.1.2.2 rmind
151 1.1.2.2 rmind sti.codeptr[0] = 0;
152 1.1.2.2 rmind for (i = STI_END; sti.codeptr[i] == 0; i--);
153 1.1.2.2 rmind sti.codeptr[i] = 0;
154 1.1.2.2 rmind
155 1.1.2.2 rmind /*
156 1.1.2.2 rmind * Read the regions list.
157 1.1.2.2 rmind */
158 1.1.2.2 rmind
159 1.1.2.2 rmind reglist = parseword1(va, 0x60);
160 1.1.2.2 rmind for (i = 0; i < STI_REGION_MAX; i++) {
161 1.1.2.2 rmind tmp = parseword1(va, (reglist & ~3) + i * 0x10);
162 1.1.2.2 rmind sti.cfg.regions[i] = (u_int)va + ((tmp >> 18) << 12);
163 1.1.2.2 rmind if (tmp & 0x4000)
164 1.1.2.2 rmind break;
165 1.1.2.2 rmind }
166 1.1.2.2 rmind
167 1.1.2.2 rmind /*
168 1.1.2.2 rmind * Allocate scratch memory for the microcode if it needs it.
169 1.1.2.2 rmind */
170 1.1.2.2 rmind
171 1.1.2.2 rmind sti.cfg.ext_cfg = &sti.ecfg;
172 1.1.2.2 rmind memsize = parseword1(va, 0xa0);
173 1.1.2.2 rmind if (memsize != 0)
174 1.1.2.2 rmind sti.ecfg.addr = alloc(memsize);
175 1.1.2.2 rmind
176 1.1.2.2 rmind /*
177 1.1.2.2 rmind * Initialize the display, and get geometry information.
178 1.1.2.2 rmind */
179 1.1.2.2 rmind
180 1.1.2.2 rmind sti_init(0);
181 1.1.2.2 rmind
182 1.1.2.2 rmind memset(&cfg, 0, sizeof cfg);
183 1.1.2.2 rmind memset(&ecfg, 0, sizeof ecfg);
184 1.1.2.2 rmind cfg.ext = &ecfg;
185 1.1.2.2 rmind sti_inqcfg(&cfg);
186 1.1.2.2 rmind
187 1.1.2.2 rmind if (cfg.owidth == cfg.width && cfg.oheight == cfg.height) {
188 1.1.2.2 rmind sti.cfg.oscr_width = cfg.owidth = cfg.fbwidth - cfg.width;
189 1.1.2.2 rmind sti.cfg.oscr_height = cfg.oheight = cfg.fbheight - cfg.height;
190 1.1.2.2 rmind }
191 1.1.2.2 rmind
192 1.1.2.2 rmind ip->dheight = cfg.height;
193 1.1.2.2 rmind ip->dwidth = cfg.width;
194 1.1.2.2 rmind ip->fbheight = cfg.fbheight;
195 1.1.2.2 rmind ip->fbwidth = cfg.fbwidth;
196 1.1.2.2 rmind
197 1.1.2.2 rmind /*
198 1.1.2.2 rmind * Get ready for ite operation!
199 1.1.2.2 rmind */
200 1.1.2.2 rmind
201 1.1.2.2 rmind sti_init(1);
202 1.1.2.2 rmind sti_fontinfo(ip);
203 1.1.2.2 rmind sti_clear(ip, 0, 0, ip->rows, ip->cols); /* necessary? */
204 1.1.2.2 rmind }
205 1.1.2.2 rmind
206 1.1.2.2 rmind void
207 1.1.2.2 rmind sti_putc(struct ite_data *ip, int c, int dy, int dx)
208 1.1.2.2 rmind {
209 1.1.2.2 rmind sti_unpmv_t unpmv;
210 1.1.2.2 rmind struct {
211 1.1.2.2 rmind struct sti_unpmvflags flags;
212 1.1.2.2 rmind struct sti_unpmvin in;
213 1.1.2.2 rmind struct sti_unpmvout out;
214 1.1.2.2 rmind } a;
215 1.1.2.2 rmind
216 1.1.2.2 rmind memset(&a, 0, sizeof a);
217 1.1.2.2 rmind a.flags.flags = STI_UNPMVF_WAIT;
218 1.1.2.2 rmind a.in.bg_colour = STI_COLOUR_BLACK;
219 1.1.2.2 rmind a.in.fg_colour = STI_COLOUR_WHITE;
220 1.1.2.2 rmind a.in.x = dx * ip->ftwidth;
221 1.1.2.2 rmind a.in.y = dy * ip->ftheight;
222 1.1.2.2 rmind a.in.font_addr = (uint32_t *)((uint8_t *)ip->fbbase + sti.fontbase);
223 1.1.2.2 rmind a.in.index = c;
224 1.1.2.2 rmind
225 1.1.2.2 rmind unpmv = (sti_unpmv_t)(sti.code + sti.codeptr[STI_FONT_UNPMV]);
226 1.1.2.2 rmind (*unpmv)(&a.flags, &a.in, &a.out, &sti.cfg);
227 1.1.2.2 rmind }
228 1.1.2.2 rmind
229 1.1.2.2 rmind void
230 1.1.2.2 rmind sti_cursor(struct ite_data *ip, int flag)
231 1.1.2.2 rmind {
232 1.1.2.2 rmind switch (flag) {
233 1.1.2.2 rmind case MOVE_CURSOR:
234 1.1.2.2 rmind sti_do_cursor(ip);
235 1.1.2.2 rmind /* FALLTHROUGH */
236 1.1.2.2 rmind case DRAW_CURSOR:
237 1.1.2.2 rmind ip->cursorx = ip->curx;
238 1.1.2.2 rmind ip->cursory = ip->cury;
239 1.1.2.2 rmind /* FALLTHROUGH */
240 1.1.2.2 rmind default:
241 1.1.2.2 rmind sti_do_cursor(ip);
242 1.1.2.2 rmind break;
243 1.1.2.2 rmind }
244 1.1.2.2 rmind }
245 1.1.2.2 rmind
246 1.1.2.2 rmind void
247 1.1.2.2 rmind sti_do_cursor(struct ite_data *ip)
248 1.1.2.2 rmind {
249 1.1.2.2 rmind sti_blkmv_t blkmv;
250 1.1.2.2 rmind struct {
251 1.1.2.2 rmind struct sti_blkmvflags flags;
252 1.1.2.2 rmind struct sti_blkmvin in;
253 1.1.2.2 rmind struct sti_blkmvout out;
254 1.1.2.2 rmind } a;
255 1.1.2.2 rmind
256 1.1.2.2 rmind memset(&a, 0, sizeof a);
257 1.1.2.2 rmind a.flags.flags = STI_BLKMVF_WAIT | STI_BLKMVF_COLR;
258 1.1.2.2 rmind a.in.fg_colour = STI_COLOUR_BLACK;
259 1.1.2.2 rmind a.in.bg_colour = STI_COLOUR_WHITE;
260 1.1.2.2 rmind a.in.dstx = a.in.srcx = ip->cursorx * ip->ftwidth;
261 1.1.2.2 rmind a.in.dsty = a.in.srcy = ip->cursory * ip->ftheight;
262 1.1.2.2 rmind a.in.width = ip->ftwidth;
263 1.1.2.2 rmind a.in.height = ip->ftheight;
264 1.1.2.2 rmind
265 1.1.2.2 rmind blkmv = (sti_blkmv_t)(sti.code + sti.codeptr[STI_BLOCK_MOVE]);
266 1.1.2.2 rmind (*blkmv)(&a.flags, &a.in, &a.out, &sti.cfg);
267 1.1.2.2 rmind }
268 1.1.2.2 rmind
269 1.1.2.2 rmind void
270 1.1.2.2 rmind sti_clear(struct ite_data *ip, int sy, int sx, int h, int w)
271 1.1.2.2 rmind {
272 1.1.2.2 rmind sti_blkmv_t blkmv;
273 1.1.2.2 rmind struct {
274 1.1.2.2 rmind struct sti_blkmvflags flags;
275 1.1.2.2 rmind struct sti_blkmvin in;
276 1.1.2.2 rmind struct sti_blkmvout out;
277 1.1.2.2 rmind } a;
278 1.1.2.2 rmind
279 1.1.2.2 rmind memset(&a, 0, sizeof a);
280 1.1.2.2 rmind a.flags.flags = STI_BLKMVF_WAIT | STI_BLKMVF_CLR;
281 1.1.2.2 rmind a.in.bg_colour = STI_COLOUR_BLACK;
282 1.1.2.2 rmind a.in.dstx = a.in.srcx = sx * ip->ftwidth;
283 1.1.2.2 rmind a.in.dsty = a.in.srcy = sy * ip->ftheight;
284 1.1.2.2 rmind a.in.width = w * ip->ftwidth;
285 1.1.2.2 rmind a.in.height = h * ip->ftheight;
286 1.1.2.2 rmind
287 1.1.2.2 rmind blkmv = (sti_blkmv_t)(sti.code + sti.codeptr[STI_BLOCK_MOVE]);
288 1.1.2.2 rmind (*blkmv)(&a.flags, &a.in, &a.out, &sti.cfg);
289 1.1.2.2 rmind }
290 1.1.2.2 rmind
291 1.1.2.2 rmind void
292 1.1.2.2 rmind sti_scroll(struct ite_data *ip)
293 1.1.2.2 rmind {
294 1.1.2.2 rmind sti_blkmv_t blkmv;
295 1.1.2.2 rmind struct {
296 1.1.2.2 rmind struct sti_blkmvflags flags;
297 1.1.2.2 rmind struct sti_blkmvin in;
298 1.1.2.2 rmind struct sti_blkmvout out;
299 1.1.2.2 rmind } a;
300 1.1.2.2 rmind
301 1.1.2.2 rmind memset(&a, 0, sizeof a);
302 1.1.2.2 rmind a.flags.flags = STI_BLKMVF_WAIT;
303 1.1.2.2 rmind a.in.bg_colour = STI_COLOUR_BLACK;
304 1.1.2.2 rmind a.in.fg_colour = STI_COLOUR_WHITE;
305 1.1.2.2 rmind a.in.dstx = a.in.srcx = 0;
306 1.1.2.2 rmind a.in.dsty = 0;
307 1.1.2.2 rmind a.in.srcy = ip->ftheight;
308 1.1.2.2 rmind a.in.width = ip->dwidth;
309 1.1.2.2 rmind a.in.height = (ip->rows - 1) * ip->ftheight;
310 1.1.2.2 rmind
311 1.1.2.2 rmind blkmv = (sti_blkmv_t)(sti.code + sti.codeptr[STI_BLOCK_MOVE]);
312 1.1.2.2 rmind (*blkmv)(&a.flags, &a.in, &a.out, &sti.cfg);
313 1.1.2.2 rmind }
314 1.1.2.2 rmind
315 1.1.2.2 rmind void
316 1.1.2.2 rmind sti_fontinfo(struct ite_data *ip)
317 1.1.2.2 rmind {
318 1.1.2.2 rmind uint32_t fontbase;
319 1.1.2.2 rmind volatile uint8_t *fbbase = ip->fbbase;
320 1.1.2.2 rmind
321 1.1.2.2 rmind fontbase = sti.fontbase = parseword1(fbbase, 0x30) & ~3;
322 1.1.2.2 rmind ip->ftwidth = (uint8_t)fbbase[fontbase + 0x13];
323 1.1.2.2 rmind ip->ftheight = (uint8_t)fbbase[fontbase + 0x17];
324 1.1.2.2 rmind ip->rows = ip->dheight / ip->ftheight;
325 1.1.2.2 rmind ip->cols = ip->dwidth / ip->ftwidth;
326 1.1.2.2 rmind }
327 1.1.2.2 rmind
328 1.1.2.2 rmind void
329 1.1.2.2 rmind sti_init(int full)
330 1.1.2.2 rmind {
331 1.1.2.2 rmind sti_init_t init;
332 1.1.2.2 rmind struct {
333 1.1.2.2 rmind struct sti_initflags flags;
334 1.1.2.2 rmind struct sti_initin in;
335 1.1.2.2 rmind struct sti_initout out;
336 1.1.2.2 rmind } a;
337 1.1.2.2 rmind
338 1.1.2.2 rmind memset(&a, 0, sizeof a);
339 1.1.2.2 rmind a.flags.flags = STI_INITF_WAIT | STI_INITF_CMB | STI_INITF_EBET;
340 1.1.2.2 rmind if (full)
341 1.1.2.2 rmind a.flags.flags |= STI_INITF_TEXT | STI_INITF_PBET |
342 1.1.2.2 rmind STI_INITF_PBETI | STI_INITF_ICMT;
343 1.1.2.2 rmind a.in.text_planes = 1;
344 1.1.2.2 rmind
345 1.1.2.2 rmind init = (sti_init_t)(sti.code + sti.codeptr[STI_INIT_GRAPH]);
346 1.1.2.2 rmind (*init)(&a.flags, &a.in, &a.out, &sti.cfg);
347 1.1.2.2 rmind }
348 1.1.2.2 rmind
349 1.1.2.2 rmind void
350 1.1.2.2 rmind sti_inqcfg(struct sti_inqconfout *ico)
351 1.1.2.2 rmind {
352 1.1.2.2 rmind sti_inqconf_t inqconf;
353 1.1.2.2 rmind struct {
354 1.1.2.2 rmind struct sti_inqconfflags flags;
355 1.1.2.2 rmind struct sti_inqconfin in;
356 1.1.2.2 rmind } a;
357 1.1.2.2 rmind
358 1.1.2.2 rmind memset(&a, 0, sizeof a);
359 1.1.2.2 rmind a.flags.flags = STI_INQCONFF_WAIT;
360 1.1.2.2 rmind
361 1.1.2.2 rmind inqconf = (sti_inqconf_t)(sti.code + sti.codeptr[STI_INQ_CONF]);
362 1.1.2.2 rmind (*inqconf)(&a.flags, &a.in, ico, &sti.cfg);
363 1.1.2.2 rmind }
364 1.1.2.2 rmind
365 1.1.2.2 rmind #endif
366