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