spx.c revision 1.1 1 1.1 hans /* $NetBSD: spx.c,v 1.1 2008/08/12 17:54:47 hans Exp $ */
2 1.1 hans /*
3 1.1 hans * SPX/LCSPX/SPXg/SPXgt accelerated framebuffer driver for NetBSD/VAX
4 1.1 hans * Copyright (c) 2005 Blaz Antonic
5 1.1 hans * All rights reserved.
6 1.1 hans *
7 1.1 hans * This software contains code written by Michael L. Hitch.
8 1.1 hans *
9 1.1 hans * Redistribution and use in source and binary forms, with or without
10 1.1 hans * modification, are permitted provided that the following conditions
11 1.1 hans * are met:
12 1.1 hans * 1. Redistributions of source code must retain the above copyright
13 1.1 hans * notice, this list of conditions and the following disclaimer.
14 1.1 hans * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 hans * notice, this list of conditions and the following disclaimer in the
16 1.1 hans * documentation and/or other materials provided with the distribution.
17 1.1 hans * 3. All advertising materials mentioning features or use of this software
18 1.1 hans * must display the abovementioned copyrights
19 1.1 hans * 4. The name of the author may not be used to endorse or promote products
20 1.1 hans * derived from this software without specific prior written permission
21 1.1 hans *
22 1.1 hans * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 hans * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 hans * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 hans * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1 hans * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1 hans * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1 hans * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1 hans * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1 hans * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1 hans * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 hans */
33 1.1 hans
34 1.1 hans #include <sys/cdefs.h>
35 1.1 hans __KERNEL_RCSID(0, "$NetBSD: spx.c,v 1.1 2008/08/12 17:54:47 hans Exp $");
36 1.1 hans
37 1.1 hans #include <sys/param.h>
38 1.1 hans #include <sys/device.h>
39 1.1 hans #include <sys/systm.h>
40 1.1 hans #include <sys/callout.h>
41 1.1 hans #include <sys/time.h>
42 1.1 hans #include <sys/malloc.h>
43 1.1 hans #include <sys/conf.h>
44 1.1 hans #include <sys/kernel.h>
45 1.1 hans
46 1.1 hans #include <uvm/uvm.h>
47 1.1 hans
48 1.1 hans #include <machine/vsbus.h>
49 1.1 hans #include <machine/sid.h>
50 1.1 hans #include <machine/cpu.h>
51 1.1 hans #include <machine/ka420.h>
52 1.1 hans
53 1.1 hans #include <dev/cons.h>
54 1.1 hans
55 1.1 hans #include <dev/dec/dzreg.h>
56 1.1 hans #include <dev/dec/dzvar.h>
57 1.1 hans #include <dev/dec/dzkbdvar.h>
58 1.1 hans
59 1.1 hans #include <dev/wscons/wsdisplayvar.h>
60 1.1 hans #include <dev/wscons/wsconsio.h>
61 1.1 hans #include <dev/wscons/wscons_callbacks.h>
62 1.1 hans #include <dev/wsfont/wsfont.h>
63 1.1 hans
64 1.1 hans #include "machine/scb.h"
65 1.1 hans
66 1.1 hans #include "dzkbd.h"
67 1.1 hans
68 1.1 hans #define CONF_LCSPX 0x02
69 1.1 hans #define CONF_SPXg 0x10
70 1.1 hans
71 1.1 hans #define FB_IS_SPX 1
72 1.1 hans #define FB_IS_SPXg 2
73 1.1 hans
74 1.1 hans /* Screen hardware defs */
75 1.1 hans #define SPX_FB_ADDR 0x38000000 /* Frame buffer */
76 1.1 hans #define SPXg_FB_ADDR_KA46 0x22200000
77 1.1 hans #define SPXg_FB_ADDR_KA49 0x28200000
78 1.1 hans #define SPXg_FB_ADDR ((vax_boardtype == VAX_BTYP_46) ? \
79 1.1 hans SPXg_FB_ADDR_KA46 : SPXg_FB_ADDR_KA49)
80 1.1 hans
81 1.1 hans #define SPXg_WIN_SIZE 0x00100000 /* Window size */
82 1.1 hans /* # of pixels that fit into single window */
83 1.1 hans #define SPXg_WIN_LINEAR (SPXg_WIN_SIZE / 2)
84 1.1 hans
85 1.1 hans #define SPXg_DELAY 5
86 1.1 hans
87 1.1 hans /*
88 1.1 hans * off-screen font storage space
89 1.1 hans * 32x16 glyphs, 256 regular and underliend chars
90 1.1 hans */
91 1.1 hans #define FONT_STORAGE_START (spx_xsize * spx_ysize)
92 1.1 hans #define FONT_STORAGE_SIZE (32 * 16 * 256 * 2)
93 1.1 hans
94 1.1 hans /* register space defines */
95 1.1 hans #define SPX_REG_SIZE 0x00002000
96 1.1 hans #define SPX_REG_ADDR 0x39302000 /* 1st set of SPX registers */
97 1.1 hans
98 1.1 hans #define SPXg_REG_SIZE 0x00004000
99 1.1 hans #define SPXg_REG_ADDR_KA46 0x22004000
100 1.1 hans #define SPXg_REG_ADDR_KA49 0x28004000
101 1.1 hans #define SPXg_REG_ADDR ((vax_boardtype == VAX_BTYP_46) ? \
102 1.1 hans SPXg_REG_ADDR_KA46 : SPXg_REG_ADDR_KA49)
103 1.1 hans
104 1.1 hans #define SPX_REG1_SIZE 0x00001000
105 1.1 hans #define SPX_REG1_ADDR 0x39b00000 /* 2nd set of SPX registers */
106 1.1 hans
107 1.1 hans #define SPXg_REG1_SIZE 0x00001000
108 1.1 hans #define SPXg_REG1_ADDR_KA46 0x22100000
109 1.1 hans #define SPXg_REG1_ADDR_KA49 0x28100000
110 1.1 hans #define SPXg_REG1_ADDR ((vax_boardtype == VAX_BTYP_46) ? \
111 1.1 hans SPXg_REG1_ADDR_KA46 : SPXg_REG1_ADDR_KA49)
112 1.1 hans #define SPX_REG(reg) regaddr[(reg - 0x2000) / 4]
113 1.1 hans #define SPXg_REG(reg) regaddr[(reg - 0x2000) / 2]
114 1.1 hans
115 1.1 hans #define SPX_REG1(reg) regaddr1[(reg) / 4]
116 1.1 hans #define SPXg_REG1(reg) regaddr1[(reg) / 4]
117 1.1 hans
118 1.1 hans /* few SPX register names */
119 1.1 hans #define SPX_COMMAND 0x21ec
120 1.1 hans #define SPX_XSTART 0x21d0
121 1.1 hans #define SPX_YSTART 0x21d4
122 1.1 hans #define SPX_XEND 0x21d8
123 1.1 hans #define SPX_YEND 0x21dc
124 1.1 hans #define SPX_DSTPIX 0x21e0
125 1.1 hans #define SPX_DSTPIX1 0x20e0
126 1.1 hans #define SPX_SRCPIX 0x21e4
127 1.1 hans #define SPX_SRCPIX1 0x20e4
128 1.1 hans #define SPX_MAIN3 0x219c
129 1.1 hans #define SPX_STRIDE 0x21e8 /* SRC | DST */
130 1.1 hans #define SPX_SRCMASK 0x21f0
131 1.1 hans #define SPX_DSTMASK 0x21f4
132 1.1 hans #define SPX_FG 0x2260
133 1.1 hans #define SPX_BG 0x2264
134 1.1 hans #define SPX_DESTLOOP 0x2270
135 1.1 hans #define SPX_MPC 0x21fc
136 1.1 hans
137 1.1 hans /* few SPX opcodes (microcode entry points); rasterop # = opcode ? */
138 1.1 hans #define SPX_OP_FILLRECT 0x19
139 1.1 hans #define SPX_OP_COPYRECT 0x1a
140 1.1 hans
141 1.1 hans /* bt459 locations */
142 1.1 hans #define SPX_BT459_ADDRL 0x39b10000
143 1.1 hans #define SPX_BT459_ADDRH 0x39b14000
144 1.1 hans #define SPX_BT459_REG 0x39b18000
145 1.1 hans #define SPX_BT459_CMAP 0x39b1c000
146 1.1 hans
147 1.1 hans /* bt460 locations */
148 1.1 hans #define SPXg_BT460_BASE_KA46 0x200f0000
149 1.1 hans #define SPXg_BT460_BASE_KA49 0x2a000000
150 1.1 hans #define SPXg_BT460_BASE ((vax_boardtype == VAX_BTYP_46) ? \
151 1.1 hans SPXg_BT460_BASE_KA46 : SPXg_BT460_BASE_KA49)
152 1.1 hans
153 1.1 hans #define SPX_BG_COLOR WS_DEFAULT_BG
154 1.1 hans #define SPX_FG_COLOR WS_DEFAULT_FG
155 1.1 hans
156 1.1 hans /*
157 1.1 hans * cursor X = 0, Y = 0 on-screen bias
158 1.1 hans * FIXME: BIAS for various HW types
159 1.1 hans */
160 1.1 hans #define CUR_XBIAS 360
161 1.1 hans #define CUR_YBIAS 37
162 1.1 hans
163 1.1 hans /* few BT459 & BT460 indirect register defines */
164 1.1 hans #define SPXDAC_REG_CCOLOR_1 0x181
165 1.1 hans #define SPXDAC_REG_CCOLOR_2 0x182
166 1.1 hans #define SPXDAC_REG_CCOLOR_3 0x183
167 1.1 hans #define SPXDAC_REG_ID 0x200
168 1.1 hans #define SPXDAC_REG_CMD0 0x201
169 1.1 hans #define SPXDAC_REG_CMD1 0x202
170 1.1 hans #define SPXDAC_REG_CMD2 0x203
171 1.1 hans #define SPXDAC_REG_PRM 0x204
172 1.1 hans #define SPXDAC_REG_CCR 0x300
173 1.1 hans #define SPXDAC_REG_CXLO 0x301
174 1.1 hans #define SPXDAC_REG_CXHI 0x302
175 1.1 hans #define SPXDAC_REG_CYLO 0x303
176 1.1 hans #define SPXDAC_REG_CYHI 0x304
177 1.1 hans #define SPXDAC_REG_WXLO 0x305
178 1.1 hans #define SPXDAC_REG_WXHI 0x306
179 1.1 hans #define SPXDAC_REG_WYLO 0x307
180 1.1 hans #define SPXDAC_REG_WYHI 0x308
181 1.1 hans #define SPXDAC_REG_WWLO 0x309
182 1.1 hans #define SPXDAC_REG_WWHI 0x30a
183 1.1 hans #define SPXDAC_REG_WHLO 0x30b
184 1.1 hans #define SPXDAC_REG_WHHI 0x30c
185 1.1 hans #define SPXDAC_REG_CRAM_BASE 0x400
186 1.1 hans
187 1.1 hans /*
188 1.1 hans * used to access top/bottom 8 bits of a 16-bit argument for split RAMDAC
189 1.1 hans * addressing
190 1.1 hans */
191 1.1 hans #define HI(x) (((x) >> 8) & 0xff)
192 1.1 hans #define LO(x) ((x) & 0xff)
193 1.1 hans
194 1.1 hans static int spx_match(device_t, cfdata_t, void *);
195 1.1 hans static void spx_attach(device_t, device_t, void *);
196 1.1 hans
197 1.1 hans struct spx_softc {
198 1.1 hans device_t ss_dev;
199 1.1 hans };
200 1.1 hans
201 1.1 hans CFATTACH_DECL_NEW(spx, sizeof(struct spx_softc),
202 1.1 hans spx_match, spx_attach, NULL, NULL);
203 1.1 hans
204 1.1 hans static void spx_cursor(void *, int, int, int);
205 1.1 hans static int spx_mapchar(void *, int, unsigned int *);
206 1.1 hans static void spx_putchar(void *, int, int, u_int, long);
207 1.1 hans static void spx_copycols(void *, int, int, int,int);
208 1.1 hans static void spx_erasecols(void *, int, int, int, long);
209 1.1 hans static void spx_copyrows(void *, int, int, int);
210 1.1 hans static void spx_eraserows(void *, int, int, long);
211 1.1 hans static int spx_allocattr(void *, int, int, int, long *);
212 1.1 hans static int spx_get_cmap(struct wsdisplay_cmap *);
213 1.1 hans static int spx_set_cmap(struct wsdisplay_cmap *);
214 1.1 hans
215 1.1 hans static int spx_map_regs(device_t, u_int, u_int, u_int, u_int);
216 1.1 hans static void SPX_render_font(void);
217 1.1 hans static void SPXg_render_font(void);
218 1.1 hans static int SPX_map_fb(device_t, struct vsbus_attach_args *);
219 1.1 hans static int SPXg_map_fb(device_t, struct vsbus_attach_args *);
220 1.1 hans static void spx_init_common(device_t, struct vsbus_attach_args *);
221 1.1 hans
222 1.1 hans #define SPX_MAP_FB(self, va, type) if (! type ## _map_fb(self, va)) return
223 1.1 hans #define SPX_MAP_REGS(self, type) if (!spx_map_regs(self, \
224 1.1 hans type ## _REG_ADDR, \
225 1.1 hans type ## _REG_SIZE, \
226 1.1 hans type ## _REG1_ADDR, \
227 1.1 hans type ## _REG1_SIZE)) \
228 1.1 hans return
229 1.1 hans
230 1.1 hans const struct wsdisplay_emulops spx_emulops = {
231 1.1 hans spx_cursor,
232 1.1 hans spx_mapchar,
233 1.1 hans spx_putchar,
234 1.1 hans spx_copycols,
235 1.1 hans spx_erasecols,
236 1.1 hans spx_copyrows,
237 1.1 hans spx_eraserows,
238 1.1 hans spx_allocattr
239 1.1 hans };
240 1.1 hans
241 1.1 hans static char spx_stdscreen_name[10] = "160x128";
242 1.1 hans struct wsscreen_descr spx_stdscreen = {
243 1.1 hans spx_stdscreen_name, 160, 128, /* dynamically set */
244 1.1 hans &spx_emulops,
245 1.1 hans 8, 15, /* dynamically set */
246 1.1 hans WSSCREEN_UNDERLINE|WSSCREEN_REVERSE|WSSCREEN_WSCOLORS,
247 1.1 hans };
248 1.1 hans
249 1.1 hans const struct wsscreen_descr *_spx_scrlist[] = {
250 1.1 hans &spx_stdscreen,
251 1.1 hans };
252 1.1 hans
253 1.1 hans const struct wsscreen_list spx_screenlist = {
254 1.1 hans sizeof(_spx_scrlist) / sizeof(struct wsscreen_descr *),
255 1.1 hans _spx_scrlist,
256 1.1 hans };
257 1.1 hans
258 1.1 hans static volatile char *spxaddr;
259 1.1 hans static volatile long *regaddr;
260 1.1 hans static volatile long *regaddr1;
261 1.1 hans
262 1.1 hans static volatile char *bt_addrl;
263 1.1 hans static volatile char *bt_addrh;
264 1.1 hans static volatile char *bt_reg;
265 1.1 hans static volatile char *bt_cmap;
266 1.1 hans static volatile char *bt_wait; /* SPXg/gt only */
267 1.1 hans
268 1.1 hans static int spx_xsize;
269 1.1 hans static int spx_ysize;
270 1.1 hans static int spx_depth;
271 1.1 hans static int spx_cols;
272 1.1 hans static int spx_rows;
273 1.1 hans static long spx_fb_size;
274 1.1 hans
275 1.1 hans /* Our current hardware colormap */
276 1.1 hans static struct hwcmap256 {
277 1.1 hans #define CMAP_SIZE 256 /* 256 R/G/B entries */
278 1.1 hans u_int8_t r[CMAP_SIZE];
279 1.1 hans u_int8_t g[CMAP_SIZE];
280 1.1 hans u_int8_t b[CMAP_SIZE];
281 1.1 hans } spx_cmap;
282 1.1 hans
283 1.1 hans /* The default colormap */
284 1.1 hans static struct {
285 1.1 hans u_int8_t r[8];
286 1.1 hans u_int8_t g[8];
287 1.1 hans u_int8_t b[8];
288 1.1 hans } spx_default_cmap = {
289 1.1 hans { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff },
290 1.1 hans { 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0xff, 0xff },
291 1.1 hans { 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff }
292 1.1 hans };
293 1.1 hans
294 1.1 hans static char fb_type = 0;
295 1.1 hans static char spxg_current_page = 0;
296 1.1 hans #define spxg_switch_page(nr) (SPXg_REG1(0x20) = ((1 << (nr) & 0xff)) << 16)
297 1.1 hans
298 1.1 hans struct wsdisplay_font spx_font;
299 1.1 hans static u_char *qf;
300 1.1 hans static u_short *qf2;
301 1.1 hans
302 1.1 hans #define QCHAR_INVALID(c) (((c) < spx_font.firstchar) || \
303 1.1 hans ((c) >= spx_font.firstchar + spx_font.numchars))
304 1.1 hans #define QCHAR(c) (QCHAR_INVALID(c) ? 0 : (c) - spx_font.firstchar)
305 1.1 hans
306 1.1 hans #define QFONT_INDEX(c, line) (QCHAR(c) * spx_font.fontheight + line)
307 1.1 hans #define QFONT_QF(c, line) qf[QFONT_INDEX(c, line)]
308 1.1 hans #define QFONT_QF2(c, line) qf2[QFONT_INDEX(c, line)]
309 1.1 hans #define QFONT(c, line) (spx_font.stride == 2 ? \
310 1.1 hans QFONT_QF2(c, line) : \
311 1.1 hans QFONT_QF(c, line))
312 1.1 hans
313 1.1 hans /* replicate color value */
314 1.1 hans #define COLOR(x) (((x) << 24) | ((x) << 16) | ((x) << 8) | (x))
315 1.1 hans
316 1.1 hans /* convert coordinates into linear offset */
317 1.1 hans #define LINEAR(x, y) ((y * spx_xsize) + x)
318 1.1 hans
319 1.1 hans /* Linear pixel address */
320 1.1 hans #define SPX_POS(row, col, line, dot) \
321 1.1 hans ((col) * spx_font.fontwidth + \
322 1.1 hans (row) * spx_font.fontheight * spx_xsize + \
323 1.1 hans (line) * spx_xsize + dot)
324 1.1 hans
325 1.1 hans #define SPX_ADDR(row, col, line, dot) spxaddr[SPX_POS(row, col, line, dot)]
326 1.1 hans
327 1.1 hans /* Recalculate absolute pixel address from linear address */
328 1.1 hans #define SPXg_ADDR(linear) spxaddr[((((linear) % SPXg_WIN_LINEAR) / 4) * 8) + \
329 1.1 hans (((linear) % SPXg_WIN_LINEAR) % 4)]
330 1.1 hans
331 1.1 hans
332 1.1 hans static int spx_ioctl(void *, void *, u_long, void *, int, struct lwp *);
333 1.1 hans static paddr_t spx_mmap(void *, void *, off_t, int);
334 1.1 hans static int spx_alloc_screen(void *, const struct wsscreen_descr *,
335 1.1 hans void **, int *, int *, long *);
336 1.1 hans static void spx_free_screen(void *, void *);
337 1.1 hans static int spx_show_screen(void *, void *, int, void (*) (void *, int, int),
338 1.1 hans void *);
339 1.1 hans
340 1.1 hans static void spx_update_cmap(int entry, char red, char green, char blue);
341 1.1 hans static void set_btreg(u_int addr, u_char value);
342 1.1 hans static u_char get_btreg(u_int addr);
343 1.1 hans
344 1.1 hans /* SPXg/gt delay */
345 1.1 hans static void spxg_delay(void);
346 1.1 hans
347 1.1 hans /*
348 1.1 hans * SPX HW accelerated block copy
349 1.1 hans * common code in spx_blkcpy,
350 1.1 hans * HW-specific code accessed through spx_blkcpy_func pointer
351 1.1 hans */
352 1.1 hans static void spx_blkcpy(u_int sxpos, u_int sypos,
353 1.1 hans u_int dxpos, u_int dypos,
354 1.1 hans u_int xdim, u_int ydim);
355 1.1 hans
356 1.1 hans static void SPX_blkcpy(u_int sxpos, u_int sypos,
357 1.1 hans u_int dxpos, u_int dypos,
358 1.1 hans u_int xdim, u_int ydim,
359 1.1 hans char direction);
360 1.1 hans static void SPXg_blkcpy(u_int sxpos, u_int sypos,
361 1.1 hans u_int dxpos, u_int dypos,
362 1.1 hans u_int xdim, u_int ydim,
363 1.1 hans char direction);
364 1.1 hans static void (*spx_blkcpy_func)(u_int, u_int,
365 1.1 hans u_int, u_int,
366 1.1 hans u_int, u_int,
367 1.1 hans char);
368 1.1 hans
369 1.1 hans /* SPX HW accelerated block set, no common code */
370 1.1 hans static void SPX_blkset(u_int xpos, u_int ypos,
371 1.1 hans u_int xdim, u_int ydim, char color);
372 1.1 hans static void SPXg_blkset(u_int xpos, u_int ypos,
373 1.1 hans u_int xdim, u_int ydim, char color);
374 1.1 hans static void (*spx_blkset_func)(u_int, u_int, u_int, u_int, char);
375 1.1 hans #define spx_blkset(x, y, xd, yd, c) spx_blkset_func(x, y, xd, yd, c)
376 1.1 hans
377 1.1 hans /* SPX HW accelerated part of spx_putchar */
378 1.1 hans static void SPX_putchar(int, int, u_int, char, char);
379 1.1 hans static void SPXg_putchar(int, int, u_int, char, char);
380 1.1 hans static void (*spx_putchar_func)(int, int, u_int, char, char);
381 1.1 hans
382 1.1 hans const struct wsdisplay_accessops spx_accessops = {
383 1.1 hans spx_ioctl,
384 1.1 hans spx_mmap,
385 1.1 hans spx_alloc_screen,
386 1.1 hans spx_free_screen,
387 1.1 hans spx_show_screen,
388 1.1 hans 0 /* load_font */
389 1.1 hans };
390 1.1 hans
391 1.1 hans /* TODO allocate ss_image dynamically for consoles beyond first one */
392 1.1 hans struct spx_screen {
393 1.1 hans int ss_curx;
394 1.1 hans int ss_cury;
395 1.1 hans int ss_cur_fg;
396 1.1 hans int ss_cur_bg;
397 1.1 hans struct {
398 1.1 hans u_char data; /* Image character */
399 1.1 hans u_char attr; /* Attribute: 80/70/08/07 */
400 1.1 hans } ss_image[160 * 128]; /* allow for maximum possible cell matrix */
401 1.1 hans };
402 1.1 hans
403 1.1 hans #define SPX_ATTR_UNDERLINE 0x80
404 1.1 hans #define SPX_BG_MASK 0x70
405 1.1 hans #define SPX_ATTR_REVERSE 0x08
406 1.1 hans #define SPX_FG_MASK 0x07
407 1.1 hans
408 1.1 hans static struct spx_screen spx_conscreen;
409 1.1 hans static struct spx_screen *prevscr, *curscr;
410 1.1 hans static struct spx_screen *savescr;
411 1.1 hans
412 1.1 hans static int cur_fg, cur_bg;
413 1.1 hans static int spx_off = 1;
414 1.1 hans
415 1.1 hans static void
416 1.1 hans spx_update_cmap(int entry, char red, char green, char blue)
417 1.1 hans {
418 1.1 hans *bt_addrl = LO(entry);
419 1.1 hans *bt_addrh = HI(entry);
420 1.1 hans if ((entry >= 0x181) && (entry <= 0x183)) {
421 1.1 hans *bt_reg = red;
422 1.1 hans *bt_reg = green;
423 1.1 hans *bt_reg = blue;
424 1.1 hans } else {
425 1.1 hans *bt_cmap = red;
426 1.1 hans *bt_cmap = green;
427 1.1 hans *bt_cmap = blue;
428 1.1 hans }
429 1.1 hans }
430 1.1 hans
431 1.1 hans static void
432 1.1 hans set_btreg(u_int addr, u_char value)
433 1.1 hans {
434 1.1 hans *bt_addrl = LO(addr);
435 1.1 hans *bt_addrh = HI(addr);
436 1.1 hans *bt_reg = value;
437 1.1 hans }
438 1.1 hans
439 1.1 hans static u_char
440 1.1 hans get_btreg(u_int addr)
441 1.1 hans {
442 1.1 hans *bt_addrl = LO(addr);
443 1.1 hans *bt_addrh = HI(addr);
444 1.1 hans return *bt_reg & 0xff;
445 1.1 hans }
446 1.1 hans
447 1.1 hans static void
448 1.1 hans spxg_delay(void)
449 1.1 hans {
450 1.1 hans char i;
451 1.1 hans
452 1.1 hans for (i = 0; i <= SPXg_DELAY; i++)
453 1.1 hans *bt_wait = *bt_wait + i;
454 1.1 hans }
455 1.1 hans
456 1.1 hans static void
457 1.1 hans SPX_blkcpy(u_int sxpos, u_int sypos,
458 1.1 hans u_int dxpos, u_int dypos,
459 1.1 hans u_int xdim, u_int ydim,
460 1.1 hans char direction)
461 1.1 hans {
462 1.1 hans u_int counter = 0xffffe;
463 1.1 hans long temp = 0;
464 1.1 hans
465 1.1 hans SPX_REG(SPX_COMMAND) = 0x84884648 | direction; /* 0x848c4648? */
466 1.1 hans SPX_REG(SPX_XSTART) = dxpos << 16;
467 1.1 hans SPX_REG(SPX_YSTART) = dypos << 16;
468 1.1 hans SPX_REG(SPX_XEND) = (dxpos + xdim) << 16;
469 1.1 hans SPX_REG(SPX_YEND) = (dypos + ydim) << 16;
470 1.1 hans
471 1.1 hans temp = ((SPX_REG1(0x10) & 0xc0) << (30 - 6)) | \
472 1.1 hans ((SPX_REG1(0x10) & 0x3f) << 24);
473 1.1 hans
474 1.1 hans SPX_REG(SPX_DSTPIX) = temp + LINEAR(dxpos, dypos);
475 1.1 hans SPX_REG(SPX_SRCPIX) = temp + LINEAR(sxpos, sypos);
476 1.1 hans SPX_REG(SPX_SRCPIX1) = 0;
477 1.1 hans SPX_REG(SPX_STRIDE) = (spx_xsize << 16) | spx_xsize;
478 1.1 hans SPX_REG(SPX_SRCMASK) = 0xff;
479 1.1 hans SPX_REG(SPX_DSTMASK) = 0xff;
480 1.1 hans
481 1.1 hans SPX_REG(SPX_DESTLOOP) = 0x00112003;
482 1.1 hans SPX_REG(SPX_MPC) = 0x2000 | SPX_OP_COPYRECT;
483 1.1 hans
484 1.1 hans SPX_REG1(0x18) = 0xffffffff;
485 1.1 hans while ((counter) && ((SPX_REG1(0x18) & 2) == 0))
486 1.1 hans counter--;
487 1.1 hans }
488 1.1 hans
489 1.1 hans static void
490 1.1 hans SPXg_blkcpy(u_int sxpos, u_int sypos,
491 1.1 hans u_int dxpos, u_int dypos,
492 1.1 hans u_int xdim, u_int ydim,
493 1.1 hans char direction)
494 1.1 hans {
495 1.1 hans u_int counter = 0xffffe;
496 1.1 hans long temp = 0;
497 1.1 hans
498 1.1 hans SPXg_REG(SPX_COMMAND) = 0x84884648 | direction; spxg_delay();
499 1.1 hans SPXg_REG(SPX_XSTART) = dxpos << 16; spxg_delay();
500 1.1 hans SPXg_REG(SPX_YSTART) = dypos << 16; spxg_delay();
501 1.1 hans SPXg_REG(SPX_XEND) = (dxpos + xdim) << 16; spxg_delay();
502 1.1 hans SPXg_REG(SPX_YEND) = (dypos + ydim) << 16; spxg_delay();
503 1.1 hans
504 1.1 hans temp = 0x3f << 24;
505 1.1 hans
506 1.1 hans SPXg_REG(SPX_DSTPIX) = temp + LINEAR(dxpos, dypos); spxg_delay();
507 1.1 hans SPXg_REG(SPX_DSTPIX1) = 0xff000000; spxg_delay();
508 1.1 hans SPXg_REG(SPX_SRCPIX) = temp + LINEAR(sxpos, sypos); spxg_delay();
509 1.1 hans SPXg_REG(SPX_SRCPIX1) = 0; spxg_delay();
510 1.1 hans SPXg_REG(SPX_STRIDE) = (spx_xsize << 16) | spx_xsize; spxg_delay();
511 1.1 hans SPXg_REG(SPX_SRCMASK) = 0xffffffff; spxg_delay();
512 1.1 hans SPXg_REG(SPX_DSTMASK) = 0xffffffff; spxg_delay();
513 1.1 hans
514 1.1 hans SPXg_REG(SPX_DESTLOOP) = 0x00112003; spxg_delay();
515 1.1 hans SPXg_REG(SPX_MPC) = 0x2000 | SPX_OP_COPYRECT; spxg_delay();
516 1.1 hans
517 1.1 hans while ((counter) && ((SPXg_REG1(0x0) & 0x8000) == 0))
518 1.1 hans counter--;
519 1.1 hans }
520 1.1 hans
521 1.1 hans static void
522 1.1 hans spx_blkcpy(u_int sxpos, u_int sypos,
523 1.1 hans u_int dxpos, u_int dypos,
524 1.1 hans u_int xdim, u_int ydim)
525 1.1 hans {
526 1.1 hans char direction = 0;
527 1.1 hans
528 1.1 hans /* don't waste time checking whether src and dest actually overlap */
529 1.1 hans if (sxpos < dxpos) {
530 1.1 hans direction |= 0x01; /* X decrement */
531 1.1 hans sxpos += xdim;
532 1.1 hans dxpos += xdim;
533 1.1 hans xdim = -xdim;
534 1.1 hans }
535 1.1 hans if (sypos < dypos) {
536 1.1 hans direction |= 0x02; /* Y decrement */
537 1.1 hans sypos += ydim;
538 1.1 hans dypos += ydim;
539 1.1 hans ydim = -ydim;
540 1.1 hans }
541 1.1 hans
542 1.1 hans spx_blkcpy_func(sxpos, sypos, dxpos, dypos, xdim, ydim, direction);
543 1.1 hans }
544 1.1 hans
545 1.1 hans static void
546 1.1 hans SPX_blkset(u_int xpos, u_int ypos, u_int xdim, u_int ydim, char color)
547 1.1 hans {
548 1.1 hans u_int counter = 0xfffe;
549 1.1 hans long temp = 0;
550 1.1 hans
551 1.1 hans SPX_REG(SPX_COMMAND) = 0x84884608;
552 1.1 hans SPX_REG(SPX_XSTART) = xpos << 16;
553 1.1 hans SPX_REG(SPX_YSTART) = ypos << 16;
554 1.1 hans SPX_REG(SPX_XEND) = (xpos + xdim) << 16;
555 1.1 hans SPX_REG(SPX_YEND) = (ypos + ydim) << 16;
556 1.1 hans SPX_REG(SPX_STRIDE) = (spx_xsize << 16) | spx_xsize;
557 1.1 hans SPX_REG(SPX_DESTLOOP) = 0x20102003;
558 1.1 hans
559 1.1 hans temp = ((SPX_REG1(0x10) & 0xc0) << (30 - 6)) |
560 1.1 hans ((SPX_REG1(0x10) & 0x3f) << 24);
561 1.1 hans SPX_REG(SPX_DSTPIX) = temp + LINEAR(xpos, ypos);
562 1.1 hans
563 1.1 hans SPX_REG(SPX_FG) = COLOR(color);
564 1.1 hans
565 1.1 hans SPX_REG(SPX_MPC) = 0x2000 | SPX_OP_FILLRECT;
566 1.1 hans
567 1.1 hans SPX_REG1(0x18) = 0xffffffff;
568 1.1 hans while ((counter) && ((SPX_REG1(0x18) & 2) == 0))
569 1.1 hans counter--;
570 1.1 hans }
571 1.1 hans
572 1.1 hans static void
573 1.1 hans SPXg_blkset(u_int xpos, u_int ypos, u_int xdim, u_int ydim, char color)
574 1.1 hans {
575 1.1 hans u_int counter = 0xfffe;
576 1.1 hans long temp = 0;
577 1.1 hans
578 1.1 hans SPXg_REG(SPX_COMMAND) = 0x84884608; spxg_delay();
579 1.1 hans SPXg_REG(SPX_XSTART) = xpos << 16; spxg_delay();
580 1.1 hans SPXg_REG(SPX_YSTART) = ypos << 16; spxg_delay();
581 1.1 hans SPXg_REG(SPX_XEND) = (xpos + xdim) << 16; spxg_delay();
582 1.1 hans SPXg_REG(SPX_YEND) = (ypos + ydim) << 16; spxg_delay();
583 1.1 hans SPXg_REG(SPX_STRIDE) = (spx_xsize << 16) | spx_xsize; spxg_delay();
584 1.1 hans
585 1.1 hans temp = 0x3f << 24;
586 1.1 hans SPXg_REG(SPX_DSTPIX) = temp + LINEAR(xpos, ypos); spxg_delay();
587 1.1 hans SPXg_REG(SPX_DSTPIX1) = 0xff000000; spxg_delay();
588 1.1 hans
589 1.1 hans SPXg_REG(SPX_FG) = COLOR(color); spxg_delay();
590 1.1 hans
591 1.1 hans SPXg_REG(SPX_DESTLOOP) = 0x20102003; spxg_delay();
592 1.1 hans SPXg_REG(SPX_MPC) = 0x2000 | SPX_OP_FILLRECT; spxg_delay();
593 1.1 hans
594 1.1 hans while ((counter) && ((SPXg_REG1(0x0) & 0x8000) == 0))
595 1.1 hans counter--;
596 1.1 hans }
597 1.1 hans
598 1.1 hans int spx_match(device_t parent, cfdata_t match, void *aux)
599 1.1 hans {
600 1.1 hans struct vsbus_softc *sc = device_private(parent);
601 1.1 hans #if 0
602 1.1 hans struct vsbus_attach_args *va = aux;
603 1.1 hans char *ch = (char *)va->va_addr;
604 1.1 hans #endif
605 1.1 hans
606 1.1 hans /*
607 1.1 hans * FIXME:
608 1.1 hans * add KA46 when/if ever somebody reports SPXg vax_confdata ID on VS 4000/60
609 1.1 hans * Ditto for SPX ID on KA42 & KA43
610 1.1 hans */
611 1.1 hans if (vax_boardtype != VAX_BTYP_49)
612 1.1 hans return 0;
613 1.1 hans
614 1.1 hans /* KA49: Identify framebuffer type */
615 1.1 hans switch (vax_confdata & (CONF_LCSPX | CONF_SPXg)) {
616 1.1 hans case CONF_LCSPX:
617 1.1 hans fb_type = FB_IS_SPX;
618 1.1 hans spx_blkcpy_func = SPX_blkcpy;
619 1.1 hans spx_blkset_func = SPX_blkset;
620 1.1 hans spx_putchar_func = SPX_putchar;
621 1.1 hans break;
622 1.1 hans case CONF_SPXg:
623 1.1 hans fb_type = FB_IS_SPXg;
624 1.1 hans spx_blkcpy_func = SPXg_blkcpy;
625 1.1 hans spx_blkset_func = SPXg_blkset;
626 1.1 hans spx_putchar_func = SPXg_putchar;
627 1.1 hans break;
628 1.1 hans case 0:
629 1.1 hans aprint_error("spx_match: no framebuffer found\n");
630 1.1 hans break;
631 1.1 hans case CONF_LCSPX | CONF_SPXg:
632 1.1 hans panic("spx_match: incorrect FB configuration\n");
633 1.1 hans break;
634 1.1 hans }
635 1.1 hans
636 1.1 hans /* FIXME add RAMDAC ID code ??? */
637 1.1 hans #if 0
638 1.1 hans /*
639 1.1 hans * FIXME:
640 1.1 hans * are memory addresses besides va->va_addr off limits at this time ?
641 1.1 hans * RAMDAC ID register test, should read 0x4a for LCSPX, 0x4b for SPXg
642 1.1 hans */
643 1.1 hans if (get_btreg(SPXDAC_REG_ID) != 0x4a)
644 1.1 hans return 0;
645 1.1 hans #endif
646 1.1 hans
647 1.1 hans sc->sc_mask = 0x04; /* XXX - should be generated */
648 1.1 hans scb_fake(0x14c, 0x15);
649 1.1 hans
650 1.1 hans return 20;
651 1.1 hans }
652 1.1 hans
653 1.1 hans static void
654 1.1 hans spx_attach(device_t parent, device_t self, void *aux)
655 1.1 hans {
656 1.1 hans struct spx_softc *sc = device_private(self);
657 1.1 hans struct vsbus_attach_args *va = aux;
658 1.1 hans struct wsemuldisplaydev_attach_args aa;
659 1.1 hans
660 1.1 hans sc->ss_dev = self;
661 1.1 hans
662 1.1 hans aprint_normal("\n");
663 1.1 hans aa.console = spxaddr != NULL;
664 1.1 hans
665 1.1 hans spx_init_common(self, va);
666 1.1 hans
667 1.1 hans curscr = &spx_conscreen;
668 1.1 hans prevscr = curscr;
669 1.1 hans
670 1.1 hans aa.scrdata = &spx_screenlist;
671 1.1 hans aa.accessops = &spx_accessops;
672 1.1 hans
673 1.1 hans /* enable cursor */
674 1.1 hans set_btreg(SPXDAC_REG_CCR, 0xc1);
675 1.1 hans
676 1.1 hans config_found(self, &aa, wsemuldisplaydevprint);
677 1.1 hans }
678 1.1 hans
679 1.1 hans static int cur_on;
680 1.1 hans
681 1.1 hans static void
682 1.1 hans spx_cursor(void *id, int on, int row, int col)
683 1.1 hans {
684 1.1 hans struct spx_screen *ss = id;
685 1.1 hans int attr, data;
686 1.1 hans
687 1.1 hans attr = ss->ss_image[row * spx_cols + col].attr;
688 1.1 hans data = ss->ss_image[row * spx_cols + col].data;
689 1.1 hans
690 1.1 hans if (attr & SPX_ATTR_REVERSE) {
691 1.1 hans cur_bg = attr & SPX_FG_MASK;
692 1.1 hans cur_fg = (attr & SPX_BG_MASK) >> 4;
693 1.1 hans } else {
694 1.1 hans cur_fg = attr & SPX_FG_MASK;
695 1.1 hans cur_bg = (attr & SPX_BG_MASK) >> 4;
696 1.1 hans }
697 1.1 hans
698 1.1 hans if (ss == curscr) {
699 1.1 hans #ifdef SOFTCURSOR
700 1.1 hans if ((cur_on = on))
701 1.1 hans spx_putchar_func(row, col, data, cur_bg, cur_fg);
702 1.1 hans else
703 1.1 hans spx_putchar_func(row, col, data, cur_fg, cur_bg);
704 1.1 hans #else
705 1.1 hans /* change cursor foreground color colormap entry */
706 1.1 hans spx_update_cmap(SPXDAC_REG_CCOLOR_3,
707 1.1 hans spx_cmap.r[cur_fg],
708 1.1 hans spx_cmap.g[cur_fg],
709 1.1 hans spx_cmap.b[cur_fg]);
710 1.1 hans
711 1.1 hans /* update cursor position registers */
712 1.1 hans set_btreg(SPXDAC_REG_CXLO,
713 1.1 hans LO(col * spx_font.fontwidth + CUR_XBIAS));
714 1.1 hans set_btreg(SPXDAC_REG_CXHI,
715 1.1 hans HI(col * spx_font.fontwidth + CUR_XBIAS));
716 1.1 hans set_btreg(SPXDAC_REG_CYLO,
717 1.1 hans LO(row * spx_font.fontheight + CUR_YBIAS));
718 1.1 hans set_btreg(SPXDAC_REG_CYHI,
719 1.1 hans HI(row * spx_font.fontheight + CUR_YBIAS));
720 1.1 hans
721 1.1 hans if ((cur_on = on))
722 1.1 hans /* enable cursor */
723 1.1 hans set_btreg(SPXDAC_REG_CCR, 0xc1);
724 1.1 hans else
725 1.1 hans /* disable cursor */
726 1.1 hans set_btreg(SPXDAC_REG_CCR, 0x01);
727 1.1 hans #endif
728 1.1 hans }
729 1.1 hans
730 1.1 hans ss->ss_curx = col;
731 1.1 hans ss->ss_cury = row;
732 1.1 hans ss->ss_cur_bg = cur_bg;
733 1.1 hans ss->ss_cur_fg = cur_fg;
734 1.1 hans }
735 1.1 hans
736 1.1 hans static int
737 1.1 hans spx_mapchar(void *id, int uni, unsigned int *index)
738 1.1 hans {
739 1.1 hans if (uni < 256) {
740 1.1 hans *index = uni;
741 1.1 hans return (5);
742 1.1 hans }
743 1.1 hans *index = ' ';
744 1.1 hans return (0);
745 1.1 hans }
746 1.1 hans
747 1.1 hans static void
748 1.1 hans SPX_putchar(int row, int col, u_int c, char dot_fg, char dot_bg)
749 1.1 hans {
750 1.1 hans u_int counter = 0xffffe;
751 1.1 hans long temp = 0;
752 1.1 hans
753 1.1 hans SPX_REG(SPX_FG) = COLOR(dot_fg);
754 1.1 hans SPX_REG(SPX_BG) = COLOR(dot_bg);
755 1.1 hans SPX_REG(SPX_MAIN3) = 0x01010101;
756 1.1 hans SPX_REG(SPX_COMMAND) = 0x84884648;
757 1.1 hans SPX_REG(SPX_XSTART) = (col * spx_font.fontwidth) << 16;
758 1.1 hans SPX_REG(SPX_YSTART) = (row * spx_font.fontheight) << 16;
759 1.1 hans SPX_REG(SPX_XEND) = ((col + 1) * spx_font.fontwidth) << 16;
760 1.1 hans SPX_REG(SPX_YEND) = ((row + 1) * spx_font.fontheight) << 16;
761 1.1 hans
762 1.1 hans temp = ((SPX_REG1(0x10) & 0xc0) << (30 - 6)) | \
763 1.1 hans ((SPX_REG1(0x10) & 0x3f) << 24);
764 1.1 hans
765 1.1 hans SPX_REG(SPX_DSTPIX) = temp + LINEAR(col * spx_font.fontwidth,
766 1.1 hans row * spx_font.fontheight);
767 1.1 hans SPX_REG(SPX_SRCPIX) = temp + FONT_STORAGE_START
768 1.1 hans + (c * spx_font.fontheight * spx_font.fontwidth);
769 1.1 hans SPX_REG(SPX_SRCPIX1) = 0;
770 1.1 hans SPX_REG(SPX_STRIDE) = (spx_font.fontwidth << 16) | spx_xsize;
771 1.1 hans SPX_REG(SPX_SRCMASK) = 0xff;
772 1.1 hans SPX_REG(SPX_DSTMASK) = 0xff;
773 1.1 hans
774 1.1 hans SPX_REG(SPX_DESTLOOP) = 0x20142003;
775 1.1 hans SPX_REG(SPX_MPC) = 0x2000 | SPX_OP_COPYRECT;
776 1.1 hans
777 1.1 hans SPX_REG1(0x18) = 0xffffffff;
778 1.1 hans
779 1.1 hans while ((counter) && ((SPX_REG1(0x18) & 2) == 0))
780 1.1 hans counter--;
781 1.1 hans }
782 1.1 hans
783 1.1 hans static void
784 1.1 hans SPXg_putchar(int row, int col, u_int c, char dot_fg, char dot_bg)
785 1.1 hans {
786 1.1 hans u_int counter = 0xffffe;
787 1.1 hans long temp = 0;
788 1.1 hans
789 1.1 hans SPXg_REG(SPX_FG) = COLOR(dot_fg);
790 1.1 hans spxg_delay();
791 1.1 hans SPXg_REG(SPX_BG) = COLOR(dot_bg);
792 1.1 hans spxg_delay();
793 1.1 hans SPXg_REG(SPX_MAIN3) = 0x01010101;
794 1.1 hans spxg_delay();
795 1.1 hans SPXg_REG(SPX_COMMAND) = 0x84884648;
796 1.1 hans spxg_delay();
797 1.1 hans SPXg_REG(SPX_XSTART) = (col * spx_font.fontwidth) << 16;
798 1.1 hans spxg_delay();
799 1.1 hans SPXg_REG(SPX_YSTART) = (row * spx_font.fontheight) << 16;
800 1.1 hans spxg_delay();
801 1.1 hans SPXg_REG(SPX_XEND) = ((col + 1) * spx_font.fontwidth) << 16;
802 1.1 hans spxg_delay();
803 1.1 hans SPXg_REG(SPX_YEND) = ((row + 1) * spx_font.fontheight) << 16;
804 1.1 hans spxg_delay();
805 1.1 hans
806 1.1 hans temp = 0x3f << 24;
807 1.1 hans
808 1.1 hans SPXg_REG(SPX_DSTPIX) = temp + LINEAR(col * spx_font.fontwidth,
809 1.1 hans row * spx_font.fontheight);
810 1.1 hans spxg_delay();
811 1.1 hans SPXg_REG(SPX_DSTPIX1) = 0xff000000;
812 1.1 hans spxg_delay();
813 1.1 hans SPXg_REG(SPX_SRCPIX) = temp + FONT_STORAGE_START +
814 1.1 hans (c * spx_font.fontheight * spx_font.fontwidth);
815 1.1 hans spxg_delay();
816 1.1 hans SPXg_REG(SPX_SRCPIX1) = 0;
817 1.1 hans spxg_delay();
818 1.1 hans SPXg_REG(SPX_STRIDE) = (spx_font.fontwidth << 16) | spx_xsize;
819 1.1 hans spxg_delay();
820 1.1 hans SPXg_REG(SPX_SRCMASK) = 0xffffffff;
821 1.1 hans spxg_delay();
822 1.1 hans SPXg_REG(SPX_DSTMASK) = 0xffffffff;
823 1.1 hans spxg_delay();
824 1.1 hans
825 1.1 hans SPXg_REG(SPX_DESTLOOP) = 0x20142003;
826 1.1 hans spxg_delay();
827 1.1 hans SPXg_REG(SPX_MPC) = 0x2000 | SPX_OP_COPYRECT;
828 1.1 hans spxg_delay();
829 1.1 hans
830 1.1 hans while ((counter) && ((SPXg_REG1(0x0) & 0x8000) == 0))
831 1.1 hans counter--;
832 1.1 hans }
833 1.1 hans
834 1.1 hans static void
835 1.1 hans spx_putchar(void *id, int row, int col, u_int c, long attr)
836 1.1 hans {
837 1.1 hans struct spx_screen *ss = id;
838 1.1 hans char dot_fg, dot_bg;
839 1.1 hans
840 1.1 hans c &= 0xff;
841 1.1 hans
842 1.1 hans ss->ss_image[row * spx_cols + col].data = c;
843 1.1 hans ss->ss_image[row * spx_cols + col].attr = attr;
844 1.1 hans if (ss != curscr)
845 1.1 hans return;
846 1.1 hans
847 1.1 hans dot_fg = attr & SPX_FG_MASK;
848 1.1 hans dot_bg = (attr & SPX_BG_MASK) >> 4;
849 1.1 hans if (attr & SPX_ATTR_REVERSE) {
850 1.1 hans dot_fg = (attr & SPX_BG_MASK) >> 4;
851 1.1 hans dot_bg = attr & SPX_FG_MASK;
852 1.1 hans }
853 1.1 hans
854 1.1 hans /* adjust glyph index for underlined text */
855 1.1 hans if (attr & SPX_ATTR_UNDERLINE)
856 1.1 hans c += 0x100;
857 1.1 hans
858 1.1 hans spx_putchar_func(row, col, c, dot_fg, dot_bg);
859 1.1 hans }
860 1.1 hans
861 1.1 hans /*
862 1.1 hans * copies columns inside a row.
863 1.1 hans */
864 1.1 hans static void
865 1.1 hans spx_copycols(void *id, int row, int srccol, int dstcol, int ncols)
866 1.1 hans {
867 1.1 hans struct spx_screen *ss = id;
868 1.1 hans
869 1.1 hans bcopy(&ss->ss_image[row * spx_cols + srccol],
870 1.1 hans &ss->ss_image[row * spx_cols + dstcol],
871 1.1 hans ncols * sizeof(ss->ss_image[0]));
872 1.1 hans
873 1.1 hans if (ss == curscr)
874 1.1 hans spx_blkcpy(srccol * spx_font.fontwidth,
875 1.1 hans row * spx_font.fontheight,
876 1.1 hans dstcol * spx_font.fontwidth,
877 1.1 hans row * spx_font.fontheight,
878 1.1 hans ncols * spx_font.fontwidth,
879 1.1 hans spx_font.fontheight);
880 1.1 hans }
881 1.1 hans
882 1.1 hans /*
883 1.1 hans * Erases a bunch of chars inside one row.
884 1.1 hans */
885 1.1 hans static void
886 1.1 hans spx_erasecols(void *id, int row, int startcol, int ncols, long fillattr)
887 1.1 hans {
888 1.1 hans struct spx_screen *ss = id;
889 1.1 hans int offset = row * spx_cols + startcol;
890 1.1 hans int i;
891 1.1 hans
892 1.1 hans bzero(&ss->ss_image[row * spx_cols + startcol],
893 1.1 hans ncols * sizeof(ss->ss_image[0]));
894 1.1 hans
895 1.1 hans for (i = offset; i < offset + ncols; ++i)
896 1.1 hans ss->ss_image[i].attr = fillattr;
897 1.1 hans
898 1.1 hans if (ss == curscr)
899 1.1 hans spx_blkset(startcol * spx_font.fontwidth,
900 1.1 hans row * spx_font.fontheight,
901 1.1 hans ncols * spx_font.fontwidth,
902 1.1 hans spx_font.fontheight,
903 1.1 hans (fillattr & SPX_BG_MASK) >> 4);
904 1.1 hans }
905 1.1 hans
906 1.1 hans static void
907 1.1 hans spx_copyrows(void *id, int srcrow, int dstrow, int nrows)
908 1.1 hans {
909 1.1 hans struct spx_screen *ss = id;
910 1.1 hans
911 1.1 hans bcopy(&ss->ss_image[srcrow * spx_cols],
912 1.1 hans &ss->ss_image[dstrow * spx_cols],
913 1.1 hans nrows * spx_cols * sizeof(ss->ss_image[0]));
914 1.1 hans
915 1.1 hans if (ss == curscr)
916 1.1 hans spx_blkcpy(0, (srcrow * spx_font.fontheight),
917 1.1 hans 0, (dstrow * spx_font.fontheight),
918 1.1 hans spx_xsize, (nrows * spx_font.fontheight));
919 1.1 hans }
920 1.1 hans
921 1.1 hans static void
922 1.1 hans spx_eraserows(void *id, int startrow, int nrows, long fillattr)
923 1.1 hans {
924 1.1 hans struct spx_screen *ss = id;
925 1.1 hans int i;
926 1.1 hans
927 1.1 hans bzero(&ss->ss_image[startrow * spx_cols],
928 1.1 hans nrows * spx_cols * sizeof(ss->ss_image[0]));
929 1.1 hans
930 1.1 hans for (i = startrow * spx_cols; i < startrow + nrows * spx_cols; ++i)
931 1.1 hans ss->ss_image[i].attr = fillattr;
932 1.1 hans
933 1.1 hans if (ss == curscr)
934 1.1 hans spx_blkset(0, (startrow * spx_font.fontheight),
935 1.1 hans spx_xsize, (nrows * spx_font.fontheight),
936 1.1 hans (fillattr & SPX_BG_MASK) >> 4);
937 1.1 hans }
938 1.1 hans
939 1.1 hans static int
940 1.1 hans spx_allocattr(void *id, int fg, int bg, int flags, long *attrp)
941 1.1 hans {
942 1.1 hans long myattr;
943 1.1 hans
944 1.1 hans if (flags & WSATTR_WSCOLORS)
945 1.1 hans myattr = (fg & SPX_FG_MASK) | ((bg << 4) & SPX_BG_MASK);
946 1.1 hans else
947 1.1 hans myattr = WSCOL_WHITE << 4; /* XXXX */
948 1.1 hans if (flags & WSATTR_REVERSE)
949 1.1 hans myattr |= SPX_ATTR_REVERSE;
950 1.1 hans if (flags & WSATTR_UNDERLINE)
951 1.1 hans myattr |= SPX_ATTR_UNDERLINE;
952 1.1 hans *attrp = myattr;
953 1.1 hans return 0;
954 1.1 hans }
955 1.1 hans
956 1.1 hans static int
957 1.1 hans spx_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
958 1.1 hans {
959 1.1 hans struct wsdisplay_fbinfo *fb = data;
960 1.1 hans int i;
961 1.1 hans
962 1.1 hans switch (cmd) {
963 1.1 hans case WSDISPLAYIO_GTYPE:
964 1.1 hans *(u_int *)data = WSDISPLAY_TYPE_SPX;
965 1.1 hans break;
966 1.1 hans
967 1.1 hans case WSDISPLAYIO_GINFO:
968 1.1 hans fb->height = spx_ysize;
969 1.1 hans fb->width = spx_xsize;
970 1.1 hans fb->depth = spx_depth;
971 1.1 hans fb->cmsize = 1 << spx_depth;
972 1.1 hans break;
973 1.1 hans
974 1.1 hans case WSDISPLAYIO_GETCMAP:
975 1.1 hans return spx_get_cmap((struct wsdisplay_cmap *)data);
976 1.1 hans
977 1.1 hans case WSDISPLAYIO_PUTCMAP:
978 1.1 hans return spx_set_cmap((struct wsdisplay_cmap *)data);
979 1.1 hans
980 1.1 hans case WSDISPLAYIO_GMODE:
981 1.1 hans return EPASSTHROUGH;
982 1.1 hans
983 1.1 hans case WSDISPLAYIO_SMODE:
984 1.1 hans /*
985 1.1 hans * if setting WSDISPLAYIO_MODE_EMUL, restore console cmap,
986 1.1 hans * current screen
987 1.1 hans */
988 1.1 hans if (*(u_int *)data == WSDISPLAYIO_MODE_EMUL) {
989 1.1 hans for (i = 0; i < 8; i++) {
990 1.1 hans spx_cmap.r[i] = spx_default_cmap.r[i];
991 1.1 hans spx_cmap.g[i] = spx_default_cmap.g[i];
992 1.1 hans spx_cmap.b[i] = spx_default_cmap.b[i];
993 1.1 hans spx_update_cmap(i, spx_cmap.r[i], spx_cmap.g[i],
994 1.1 hans spx_cmap.b[i]);
995 1.1 hans }
996 1.1 hans if (savescr != NULL)
997 1.1 hans spx_show_screen(NULL, savescr, 0, NULL, NULL);
998 1.1 hans savescr = NULL;
999 1.1 hans } else { /* WSDISPLAYIO_MODE_MAPPED */
1000 1.1 hans savescr = curscr;
1001 1.1 hans curscr = NULL;
1002 1.1 hans /* clear screen? */
1003 1.1 hans }
1004 1.1 hans
1005 1.1 hans return EPASSTHROUGH;
1006 1.1 hans
1007 1.1 hans case WSDISPLAYIO_SVIDEO:
1008 1.1 hans if (*(u_int *)data == WSDISPLAYIO_VIDEO_ON && spx_off) {
1009 1.1 hans /* Unblank video */
1010 1.1 hans set_btreg(SPXDAC_REG_CMD0, 0x48);
1011 1.1 hans
1012 1.1 hans /* Enable sync */
1013 1.1 hans set_btreg(SPXDAC_REG_CMD2, 0xc0);
1014 1.1 hans
1015 1.1 hans spx_off = 0;
1016 1.1 hans } else if (*(u_int *)data == WSDISPLAYIO_VIDEO_OFF && !spx_off) {
1017 1.1 hans /* Blank video */
1018 1.1 hans set_btreg(SPXDAC_REG_CMD0, 68);
1019 1.1 hans
1020 1.1 hans /* Disable sync */
1021 1.1 hans set_btreg(SPXDAC_REG_CMD2, 0x40);
1022 1.1 hans spx_off = 1;
1023 1.1 hans }
1024 1.1 hans break;
1025 1.1 hans
1026 1.1 hans case WSDISPLAYIO_GVIDEO:
1027 1.1 hans *(u_int *)data = spx_off == 0 ?
1028 1.1 hans WSDISPLAYIO_VIDEO_ON : WSDISPLAYIO_VIDEO_OFF;
1029 1.1 hans break;
1030 1.1 hans
1031 1.1 hans default:
1032 1.1 hans return EPASSTHROUGH;
1033 1.1 hans }
1034 1.1 hans return 0;
1035 1.1 hans }
1036 1.1 hans
1037 1.1 hans /*
1038 1.1 hans * Bad idea on SPXg/gt due to windowed framebuffer access
1039 1.1 hans */
1040 1.1 hans static paddr_t
1041 1.1 hans spx_mmap(void *v, void *vs, off_t offset, int prot)
1042 1.1 hans {
1043 1.1 hans if (fb_type != FB_IS_SPX)
1044 1.1 hans return -1;
1045 1.1 hans
1046 1.1 hans if (offset >= spx_fb_size || offset < 0)
1047 1.1 hans return -1;
1048 1.1 hans
1049 1.1 hans return (SPX_FB_ADDR + offset) >> PGSHIFT;
1050 1.1 hans }
1051 1.1 hans
1052 1.1 hans static int
1053 1.1 hans spx_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
1054 1.1 hans int *curxp, int *curyp, long *defattrp)
1055 1.1 hans {
1056 1.1 hans int i;
1057 1.1 hans struct spx_screen *ss;
1058 1.1 hans
1059 1.1 hans ss = malloc(sizeof(struct spx_screen), M_DEVBUF, M_WAITOK | M_ZERO);
1060 1.1 hans
1061 1.1 hans *cookiep = ss;
1062 1.1 hans *curxp = *curyp = 0;
1063 1.1 hans *defattrp = (SPX_BG_COLOR << 4) | SPX_FG_COLOR;
1064 1.1 hans
1065 1.1 hans for (i = 0; i < spx_cols * spx_rows; ++i)
1066 1.1 hans ss->ss_image[i].attr = *defattrp;
1067 1.1 hans
1068 1.1 hans return 0;
1069 1.1 hans }
1070 1.1 hans
1071 1.1 hans static void
1072 1.1 hans spx_free_screen(void *v, void *cookie)
1073 1.1 hans {
1074 1.1 hans /* FIXME add something to actually free malloc()ed screen ? */
1075 1.1 hans }
1076 1.1 hans
1077 1.1 hans static int
1078 1.1 hans spx_show_screen(void *v, void *cookie, int waitok,
1079 1.1 hans void (*cb)(void *, int, int), void *cbarg)
1080 1.1 hans {
1081 1.1 hans struct spx_screen *ss = cookie;
1082 1.1 hans u_int row, col, attr;
1083 1.1 hans u_char c;
1084 1.1 hans
1085 1.1 hans if (ss == curscr)
1086 1.1 hans return (0);
1087 1.1 hans
1088 1.1 hans prevscr = curscr;
1089 1.1 hans curscr = ss;
1090 1.1 hans
1091 1.1 hans for (row = 0; row < spx_rows; row++) {
1092 1.1 hans for (col = 0; col < spx_cols; col++) {
1093 1.1 hans u_int idx = row * spx_cols + col;
1094 1.1 hans attr = ss->ss_image[idx].attr;
1095 1.1 hans c = ss->ss_image[idx].data;
1096 1.1 hans
1097 1.1 hans /* check if cell requires updating */
1098 1.1 hans if ((c != prevscr->ss_image[idx].data) ||
1099 1.1 hans (attr != prevscr->ss_image[idx].attr)) {
1100 1.1 hans if (c < 32) c = 32;
1101 1.1 hans spx_putchar(ss, row, col, c, attr);
1102 1.1 hans }
1103 1.1 hans }
1104 1.1 hans }
1105 1.1 hans
1106 1.1 hans row = ss->ss_cury; col = ss->ss_curx;
1107 1.1 hans
1108 1.1 hans spx_cursor(ss, cur_on, row, col);
1109 1.1 hans
1110 1.1 hans cur_fg = ss->ss_cur_fg;
1111 1.1 hans cur_bg = ss->ss_cur_bg;
1112 1.1 hans
1113 1.1 hans return (0);
1114 1.1 hans }
1115 1.1 hans
1116 1.1 hans static int
1117 1.1 hans spx_get_cmap(struct wsdisplay_cmap *p)
1118 1.1 hans {
1119 1.1 hans u_int index = p->index, count = p->count;
1120 1.1 hans int error;
1121 1.1 hans
1122 1.1 hans if (index >= (1 << spx_depth) || count > (1 << spx_depth) - index)
1123 1.1 hans return (EINVAL);
1124 1.1 hans
1125 1.1 hans error = copyout(&spx_cmap.r[index], p->red, count);
1126 1.1 hans if (error)
1127 1.1 hans return error;
1128 1.1 hans
1129 1.1 hans error = copyout(&spx_cmap.g[index], p->green, count);
1130 1.1 hans if (error)
1131 1.1 hans return error;
1132 1.1 hans
1133 1.1 hans error = copyout(&spx_cmap.b[index], p->blue, count);
1134 1.1 hans return error;
1135 1.1 hans }
1136 1.1 hans
1137 1.1 hans static int
1138 1.1 hans spx_set_cmap(struct wsdisplay_cmap *p)
1139 1.1 hans {
1140 1.1 hans u_int index = p->index, count = p->count;
1141 1.1 hans int error, s;
1142 1.1 hans
1143 1.1 hans if (index >= (1 << spx_depth) || count > (1 << spx_depth) - index)
1144 1.1 hans return (EINVAL);
1145 1.1 hans
1146 1.1 hans error = copyin(p->red, &spx_cmap.r[index], count);
1147 1.1 hans if (error)
1148 1.1 hans return error;
1149 1.1 hans
1150 1.1 hans error = copyin(p->green, &spx_cmap.g[index], count);
1151 1.1 hans if (error)
1152 1.1 hans return error;
1153 1.1 hans
1154 1.1 hans error = copyin(p->blue, &spx_cmap.b[index], count);
1155 1.1 hans
1156 1.1 hans if (error)
1157 1.1 hans return error;
1158 1.1 hans
1159 1.1 hans s = spltty();
1160 1.1 hans while (count-- > 0) {
1161 1.1 hans spx_update_cmap(index,
1162 1.1 hans spx_cmap.r[index],
1163 1.1 hans spx_cmap.g[index],
1164 1.1 hans spx_cmap.b[index]);
1165 1.1 hans index++;
1166 1.1 hans }
1167 1.1 hans splx(s);
1168 1.1 hans return (0);
1169 1.1 hans }
1170 1.1 hans
1171 1.1 hans cons_decl(spx);
1172 1.1 hans
1173 1.1 hans void
1174 1.1 hans spxcninit(struct consdev *cndev)
1175 1.1 hans {
1176 1.1 hans int i;
1177 1.1 hans
1178 1.1 hans spx_blkset(0, 0, spx_xsize, spx_ysize, SPX_BG_COLOR);
1179 1.1 hans
1180 1.1 hans curscr = &spx_conscreen;
1181 1.1 hans
1182 1.1 hans for (i = 0; i < spx_cols * spx_rows; i++)
1183 1.1 hans spx_conscreen.ss_image[i].attr =
1184 1.1 hans (SPX_BG_COLOR << 4) | SPX_FG_COLOR;
1185 1.1 hans wsdisplay_cnattach(&spx_stdscreen, &spx_conscreen, 0, 0,
1186 1.1 hans (SPX_BG_COLOR << 4) | SPX_FG_COLOR);
1187 1.1 hans cn_tab->cn_pri = CN_INTERNAL;
1188 1.1 hans
1189 1.1 hans #if NDZKBD > 0
1190 1.1 hans dzkbd_cnattach(0); /* Connect keyboard and screen together */
1191 1.1 hans #endif
1192 1.1 hans }
1193 1.1 hans
1194 1.1 hans /*
1195 1.1 hans * Called very early to setup the glass tty as console.
1196 1.1 hans * Because it's called before the VM system is inited, virtual memory
1197 1.1 hans * for the framebuffer can be stolen directly without disturbing anything.
1198 1.1 hans */
1199 1.1 hans void
1200 1.1 hans spxcnprobe(struct consdev *cndev)
1201 1.1 hans {
1202 1.1 hans extern const struct cdevsw wsdisplay_cdevsw;
1203 1.1 hans
1204 1.1 hans /* Only for VS 4000/90, 90A and 96 with LCSPX or SPXg/gt*/
1205 1.1 hans if ((vax_boardtype != VAX_BTYP_49) ||
1206 1.1 hans ((vax_confdata & (CONF_LCSPX | CONF_SPXg)) != 0))
1207 1.1 hans return;
1208 1.1 hans
1209 1.1 hans if (((vax_confdata & 8) && (vax_boardtype == VAX_BTYP_49)) ||
1210 1.1 hans (((vax_confdata & KA420_CFG_L3CON) ||
1211 1.1 hans (vax_confdata & KA420_CFG_MULTU)) &&
1212 1.1 hans ((vax_boardtype == VAX_BTYP_420) ||
1213 1.1 hans (vax_boardtype == VAX_BTYP_43)))) {
1214 1.1 hans aprint_normal("spxcnprobe: Diagnostic console\n");
1215 1.1 hans return; /* Diagnostic console */
1216 1.1 hans }
1217 1.1 hans
1218 1.1 hans /* KA49: Identify framebuffer type */
1219 1.1 hans switch (vax_confdata & (CONF_LCSPX | CONF_SPXg)) {
1220 1.1 hans case CONF_LCSPX:
1221 1.1 hans fb_type = FB_IS_SPX;
1222 1.1 hans spx_blkcpy_func = SPX_blkcpy;
1223 1.1 hans spx_blkset_func = SPX_blkset;
1224 1.1 hans break;
1225 1.1 hans case CONF_SPXg:
1226 1.1 hans fb_type = FB_IS_SPXg;
1227 1.1 hans spx_blkcpy_func = SPXg_blkcpy;
1228 1.1 hans spx_blkset_func = SPXg_blkset;
1229 1.1 hans break;
1230 1.1 hans case 0:
1231 1.1 hans aprint_error("spxcnprobe: no framebuffer found\n");
1232 1.1 hans break;
1233 1.1 hans case CONF_LCSPX | CONF_SPXg:
1234 1.1 hans panic("spxcnprobe: incorrect FB configuration\n"); break;
1235 1.1 hans }
1236 1.1 hans
1237 1.1 hans spx_init_common(NULL, NULL);
1238 1.1 hans
1239 1.1 hans cndev->cn_pri = CN_INTERNAL;
1240 1.1 hans cndev->cn_dev = makedev(cdevsw_lookup_major(&wsdisplay_cdevsw), 0);
1241 1.1 hans }
1242 1.1 hans
1243 1.1 hans static int
1244 1.1 hans spx_map_regs(device_t self,
1245 1.1 hans u_int raddr, u_int rsize, u_int r1addr, u_int r1size)
1246 1.1 hans {
1247 1.1 hans extern vaddr_t virtual_avail;
1248 1.1 hans
1249 1.1 hans if (!self) {
1250 1.1 hans regaddr = (long*)virtual_avail;
1251 1.1 hans virtual_avail += rsize;
1252 1.1 hans ioaccess((vaddr_t)regaddr, raddr, rsize/VAX_NBPG);
1253 1.1 hans
1254 1.1 hans regaddr1 = (long*)virtual_avail;
1255 1.1 hans virtual_avail += r1size;
1256 1.1 hans ioaccess((vaddr_t)regaddr1, r1addr, r1size/VAX_NBPG);
1257 1.1 hans
1258 1.1 hans return 1;
1259 1.1 hans }
1260 1.1 hans
1261 1.1 hans regaddr = (long*)vax_map_physmem(raddr, rsize/VAX_NBPG);
1262 1.1 hans if (regaddr == 0) {
1263 1.1 hans aprint_error_dev(self,
1264 1.1 hans "unable to allocate register memory (1).\n");
1265 1.1 hans return 0;
1266 1.1 hans }
1267 1.1 hans
1268 1.1 hans regaddr1 = (long*)vax_map_physmem(r1addr, r1size/VAX_NBPG);
1269 1.1 hans if (regaddr1 == 0) {
1270 1.1 hans aprint_error_dev(self,
1271 1.1 hans "unable to allocate register memory (2).\n");
1272 1.1 hans return 0;
1273 1.1 hans }
1274 1.1 hans
1275 1.1 hans return 1;
1276 1.1 hans }
1277 1.1 hans
1278 1.1 hans static int
1279 1.1 hans SPX_map_fb(device_t self, struct vsbus_attach_args *va)
1280 1.1 hans {
1281 1.1 hans int fbsize = (spx_fb_size + FONT_STORAGE_SIZE)/VAX_NBPG;
1282 1.1 hans extern vaddr_t virtual_avail;
1283 1.1 hans
1284 1.1 hans if (!self) {
1285 1.1 hans spxaddr = (char *)virtual_avail;
1286 1.1 hans virtual_avail += (spx_fb_size + FONT_STORAGE_SIZE);
1287 1.1 hans ioaccess((vaddr_t)spxaddr, SPX_FB_ADDR, fbsize);
1288 1.1 hans
1289 1.1 hans bt_addrl = (char *)virtual_avail;
1290 1.1 hans virtual_avail += VAX_NBPG;
1291 1.1 hans ioaccess((vaddr_t)bt_addrl, SPX_BT459_ADDRL, 1);
1292 1.1 hans
1293 1.1 hans bt_addrh = (char *)virtual_avail;
1294 1.1 hans virtual_avail += VAX_NBPG;
1295 1.1 hans ioaccess((vaddr_t)bt_addrh, SPX_BT459_ADDRH, 1);
1296 1.1 hans
1297 1.1 hans bt_reg = (char *)virtual_avail;
1298 1.1 hans virtual_avail += VAX_NBPG;
1299 1.1 hans ioaccess((vaddr_t)bt_reg, SPX_BT459_REG, 1);
1300 1.1 hans
1301 1.1 hans bt_cmap = (char *)virtual_avail;
1302 1.1 hans virtual_avail += VAX_NBPG;
1303 1.1 hans ioaccess((vaddr_t)bt_cmap, SPX_BT459_CMAP, 1);
1304 1.1 hans
1305 1.1 hans return 1;
1306 1.1 hans }
1307 1.1 hans
1308 1.1 hans spxaddr = (char *)vax_map_physmem(va->va_paddr, fbsize);
1309 1.1 hans if (spxaddr == 0) {
1310 1.1 hans aprint_error_dev(self, "unable to map framebuffer memory.\n");
1311 1.1 hans return 0;
1312 1.1 hans }
1313 1.1 hans
1314 1.1 hans /* map all four RAMDAC registers */
1315 1.1 hans bt_addrl = (char *)vax_map_physmem(SPX_BT459_ADDRL, 1);
1316 1.1 hans if (bt_addrl == 0) {
1317 1.1 hans aprint_error_dev(self,
1318 1.1 hans "unable to map BT459 Low Address register.\n");
1319 1.1 hans return 0;
1320 1.1 hans }
1321 1.1 hans
1322 1.1 hans bt_addrh = (char *)vax_map_physmem(SPX_BT459_ADDRH, 1);
1323 1.1 hans if (bt_addrh == 0) {
1324 1.1 hans aprint_error_dev(self,
1325 1.1 hans "unable to map BT459 High Address register.\n");
1326 1.1 hans return 0;
1327 1.1 hans }
1328 1.1 hans
1329 1.1 hans bt_reg = (char *)vax_map_physmem(SPX_BT459_REG, 1);
1330 1.1 hans if (bt_reg == 0) {
1331 1.1 hans aprint_error_dev(self,
1332 1.1 hans "unable to map BT459 I/O Register.\n");
1333 1.1 hans return 0;
1334 1.1 hans }
1335 1.1 hans
1336 1.1 hans bt_cmap = (char *)vax_map_physmem(SPX_BT459_CMAP, 1);
1337 1.1 hans if (bt_cmap == 0) {
1338 1.1 hans aprint_error_dev(self,
1339 1.1 hans "unable to map BT459 Color Map register.\n");
1340 1.1 hans return 0;
1341 1.1 hans }
1342 1.1 hans
1343 1.1 hans return 1;
1344 1.1 hans }
1345 1.1 hans
1346 1.1 hans static int
1347 1.1 hans SPXg_map_fb(device_t self, struct vsbus_attach_args *va)
1348 1.1 hans {
1349 1.1 hans int fbsize = SPXg_WIN_SIZE/VAX_NBPG;
1350 1.1 hans extern vaddr_t virtual_avail;
1351 1.1 hans
1352 1.1 hans if (!self) {
1353 1.1 hans spxaddr = (char *)virtual_avail;
1354 1.1 hans virtual_avail += SPXg_WIN_SIZE;
1355 1.1 hans ioaccess((vaddr_t)spxaddr, SPXg_FB_ADDR, fbsize);
1356 1.1 hans
1357 1.1 hans bt_addrl = (char *)virtual_avail;
1358 1.1 hans virtual_avail += VAX_NBPG;
1359 1.1 hans ioaccess((vaddr_t)bt_addrl, SPXg_BT460_BASE, 1);
1360 1.1 hans
1361 1.1 hans bt_addrh = bt_addrl + 0x04;
1362 1.1 hans bt_reg = bt_addrl + 0x08;
1363 1.1 hans bt_cmap = bt_addrl + 0x0c;
1364 1.1 hans bt_wait = bt_addrl + 0x34;
1365 1.1 hans
1366 1.1 hans return 1;
1367 1.1 hans }
1368 1.1 hans
1369 1.1 hans spxaddr = (char *)vax_map_physmem(va->va_paddr, fbsize);
1370 1.1 hans if (spxaddr == 0) {
1371 1.1 hans aprint_error_dev(self,
1372 1.1 hans "unable to map framebuffer memory window.\n");
1373 1.1 hans return 0;
1374 1.1 hans }
1375 1.1 hans
1376 1.1 hans bt_addrl = (char *)vax_map_physmem(SPXg_BT460_BASE, 1);
1377 1.1 hans if (bt_addrl == 0) {
1378 1.1 hans aprint_error_dev(self,
1379 1.1 hans "unable to map BT460 Low Address register.\n");
1380 1.1 hans return 0;
1381 1.1 hans }
1382 1.1 hans bt_addrh = bt_addrl + 0x04;
1383 1.1 hans bt_reg = bt_addrl + 0x08;
1384 1.1 hans bt_cmap = bt_addrl + 0x0c;
1385 1.1 hans bt_wait = bt_addrl + 0x34;
1386 1.1 hans
1387 1.1 hans return 1;
1388 1.1 hans }
1389 1.1 hans
1390 1.1 hans static void
1391 1.1 hans SPX_render_font(void)
1392 1.1 hans {
1393 1.1 hans volatile char *fontaddr = spxaddr + FONT_STORAGE_START;
1394 1.1 hans int i, j, k, ch, pixel;
1395 1.1 hans
1396 1.1 hans for (i = 0; i < 256; i++) for (j = 0; j < spx_font.fontheight; j++) {
1397 1.1 hans ch = QFONT(i, j);
1398 1.1 hans
1399 1.1 hans /* regular characters */
1400 1.1 hans pixel = ((i * spx_font.fontheight)+ j) * spx_font.fontwidth;
1401 1.1 hans for (k = 0; k < spx_font.fontwidth; k++)
1402 1.1 hans if (ch & (1 << k))
1403 1.1 hans fontaddr[pixel++] = 0xff;
1404 1.1 hans else
1405 1.1 hans fontaddr[pixel++] = 0x00;
1406 1.1 hans
1407 1.1 hans /* underlined characters */
1408 1.1 hans pixel = (((i + 256) * spx_font.fontheight) + j)
1409 1.1 hans * spx_font.fontwidth;
1410 1.1 hans for (k = 0; k < spx_font.fontwidth; k++)
1411 1.1 hans if ((ch & (1 << k)) || (j == (spx_font.fontheight - 1)))
1412 1.1 hans fontaddr[pixel++] = 0xff;
1413 1.1 hans else
1414 1.1 hans fontaddr[pixel++] = 0x00;
1415 1.1 hans }
1416 1.1 hans }
1417 1.1 hans
1418 1.1 hans static void
1419 1.1 hans SPXg_render_font(void)
1420 1.1 hans {
1421 1.1 hans int i, j, k, ch, pixel;
1422 1.1 hans
1423 1.1 hans for (i = 0; i < 256; i++) for (j = 0; j < spx_font.fontheight; j++) {
1424 1.1 hans ch = QFONT(i, j);
1425 1.1 hans /* regular characters */
1426 1.1 hans for (k = 0; k < spx_font.fontwidth; k++) {
1427 1.1 hans pixel = FONT_STORAGE_START
1428 1.1 hans + (((i * spx_font.fontheight) + j)
1429 1.1 hans * spx_font.fontwidth) + k;
1430 1.1 hans if ((pixel / SPXg_WIN_LINEAR) != spxg_current_page) {
1431 1.1 hans spxg_switch_page(pixel / SPXg_WIN_LINEAR);
1432 1.1 hans spxg_current_page = (pixel / SPXg_WIN_LINEAR);
1433 1.1 hans }
1434 1.1 hans SPXg_ADDR(pixel) = ch & (1 << k) ? 0xff : 0x00;
1435 1.1 hans spxg_delay();
1436 1.1 hans }
1437 1.1 hans
1438 1.1 hans /* underlined characters */
1439 1.1 hans for (k = 0; k < spx_font.fontwidth; k++) {
1440 1.1 hans pixel = FONT_STORAGE_START
1441 1.1 hans + ((((i + 256) * spx_font.fontheight) + j)
1442 1.1 hans * spx_font.fontwidth) + k;
1443 1.1 hans if ((pixel / SPXg_WIN_LINEAR) != spxg_current_page) {
1444 1.1 hans spxg_switch_page(pixel / SPXg_WIN_LINEAR);
1445 1.1 hans spxg_current_page = (pixel / SPXg_WIN_LINEAR);
1446 1.1 hans }
1447 1.1 hans if ((ch & (1 << k)) || (j == (spx_font.fontheight - 1)))
1448 1.1 hans SPXg_ADDR(pixel) = 0xff;
1449 1.1 hans else
1450 1.1 hans SPXg_ADDR(pixel) = 0x00;
1451 1.1 hans spxg_delay();
1452 1.1 hans }
1453 1.1 hans }
1454 1.1 hans }
1455 1.1 hans
1456 1.1 hans static void
1457 1.1 hans spx_init_common(device_t self, struct vsbus_attach_args *va)
1458 1.1 hans {
1459 1.1 hans u_int i, j, k;
1460 1.1 hans int cookie;
1461 1.1 hans struct wsdisplay_font *wf;
1462 1.1 hans
1463 1.1 hans /* map SPX registers first */
1464 1.1 hans if (fb_type == FB_IS_SPX) {
1465 1.1 hans SPX_MAP_REGS(self, SPX);
1466 1.1 hans } else if(fb_type == FB_IS_SPXg) {
1467 1.1 hans SPX_MAP_REGS(self, SPXg);
1468 1.1 hans }
1469 1.1 hans
1470 1.1 hans if (fb_type == FB_IS_SPXg)
1471 1.1 hans spxg_switch_page(0);
1472 1.1 hans
1473 1.1 hans /* any KA42/43 SPX resolution detection code should be placed here */
1474 1.1 hans spx_depth = 8;
1475 1.1 hans spx_xsize = 1280;
1476 1.1 hans spx_ysize = 1024;
1477 1.1 hans
1478 1.1 hans wsfont_init();
1479 1.1 hans
1480 1.1 hans cookie = wsfont_find(NULL, 12, 21, 0, WSDISPLAY_FONTORDER_R2L,
1481 1.1 hans WSDISPLAY_FONTORDER_L2R);
1482 1.1 hans if (cookie == -1)
1483 1.1 hans cookie = wsfont_find(NULL, 16, 0, 0, WSDISPLAY_FONTORDER_R2L, 0);
1484 1.1 hans if (cookie == -1)
1485 1.1 hans cookie = wsfont_find(NULL, 12, 0, 0, WSDISPLAY_FONTORDER_R2L, 0);
1486 1.1 hans if (cookie == -1)
1487 1.1 hans cookie = wsfont_find(NULL, 8, 0, 0, WSDISPLAY_FONTORDER_R2L, 0);
1488 1.1 hans if (cookie == -1)
1489 1.1 hans cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_R2L,
1490 1.1 hans WSDISPLAY_FONTORDER_L2R);
1491 1.1 hans
1492 1.1 hans if (cookie == -1)
1493 1.1 hans aprint_error_dev(self, "spx_common_init: cookie = -1\n");
1494 1.1 hans
1495 1.1 hans if (cookie == -1 || wsfont_lock(cookie, &wf))
1496 1.1 hans panic("spx_common_init: unable to load console font");
1497 1.1 hans
1498 1.1 hans spx_font = *wf;
1499 1.1 hans
1500 1.1 hans if (self != NULL) {
1501 1.1 hans aprint_normal_dev(self, "Using %s %dx%d font\n", wf->name,
1502 1.1 hans spx_font.fontwidth, spx_font.fontheight);
1503 1.1 hans }
1504 1.1 hans
1505 1.1 hans spx_cols = spx_xsize / spx_font.fontwidth;
1506 1.1 hans spx_rows = spx_ysize / spx_font.fontheight;
1507 1.1 hans spx_fb_size = spx_xsize * spx_ysize;
1508 1.1 hans spx_stdscreen.ncols = spx_cols;
1509 1.1 hans spx_stdscreen.nrows = spx_rows;
1510 1.1 hans spx_stdscreen.fontwidth = spx_font.fontwidth;
1511 1.1 hans spx_stdscreen.fontheight = spx_font.fontheight;
1512 1.1 hans sprintf(spx_stdscreen_name, "%dx%d", spx_cols, spx_rows);
1513 1.1 hans
1514 1.1 hans /* for SPXg spx_fb_size represents FB window size, not FB length */
1515 1.1 hans if (fb_type == FB_IS_SPXg)
1516 1.1 hans spx_fb_size = SPXg_WIN_SIZE;
1517 1.1 hans
1518 1.1 hans qf = spx_font.data;
1519 1.1 hans qf2 = (u_short *)spx_font.data;
1520 1.1 hans
1521 1.1 hans if (fb_type == FB_IS_SPX) {
1522 1.1 hans SPX_MAP_FB(self, va, SPX);
1523 1.1 hans } else if (fb_type == FB_IS_SPXg) {
1524 1.1 hans SPX_MAP_FB(self, va, SPXg);
1525 1.1 hans }
1526 1.1 hans
1527 1.1 hans /* display FB type based on RAMDAC ID */
1528 1.1 hans switch (get_btreg(SPXDAC_REG_ID) & 0xff) {
1529 1.1 hans case 0x4a:
1530 1.1 hans aprint_normal_dev(
1531 1.1 hans self, "RAMDAC ID: 0x%x, Bt459 (SPX/LCSPX) RAMDAC type\n",
1532 1.1 hans get_btreg(SPXDAC_REG_ID) & 0xff);
1533 1.1 hans break;
1534 1.1 hans
1535 1.1 hans case 0x4b:
1536 1.1 hans aprint_normal_dev(
1537 1.1 hans self, "RAMDAC ID: 0x%x, Bt460 (SPXg) RAMDAC type\n",
1538 1.1 hans get_btreg(SPXDAC_REG_ID) & 0xff);
1539 1.1 hans break;
1540 1.1 hans default:
1541 1.1 hans aprint_error_dev(self, "unknown RAMDAC type 0x%x\n",
1542 1.1 hans get_btreg(SPXDAC_REG_ID) & 0xff);
1543 1.1 hans }
1544 1.1 hans
1545 1.1 hans /* render font glyphs to off-screen memory */
1546 1.1 hans if (fb_type == FB_IS_SPX)
1547 1.1 hans SPX_render_font();
1548 1.1 hans else if (fb_type == FB_IS_SPXg)
1549 1.1 hans SPXg_render_font();
1550 1.1 hans
1551 1.1 hans /* set up default console color palette */
1552 1.1 hans for (i = 0; i < 8; i++) {
1553 1.1 hans spx_cmap.r[i] = spx_default_cmap.r[i];
1554 1.1 hans spx_cmap.g[i] = spx_default_cmap.g[i];
1555 1.1 hans spx_cmap.b[i] = spx_default_cmap.b[i];
1556 1.1 hans spx_update_cmap(i, spx_cmap.r[i], spx_cmap.g[i], spx_cmap.b[i]);
1557 1.1 hans }
1558 1.1 hans
1559 1.1 hans /*
1560 1.1 hans * Build 64x64 console cursor bitmap based on font dimensions.
1561 1.1 hans * Palette colors are not used, but 4 pixels 2bpp of cursor sprite,
1562 1.1 hans * fg/bg respectively.
1563 1.1 hans */
1564 1.1 hans for (i = 0; i < 1024; i++)
1565 1.1 hans set_btreg(SPXDAC_REG_CRAM_BASE + i, 0);
1566 1.1 hans
1567 1.1 hans /* build cursor line, 1 to 3 pixels high depending on font height */
1568 1.1 hans if (spx_font.fontheight > 26)
1569 1.1 hans i = spx_font.fontheight - 3;
1570 1.1 hans else if (spx_font.fontheight > 16)
1571 1.1 hans i = spx_font.fontheight - 2;
1572 1.1 hans else
1573 1.1 hans i = spx_font.fontheight - 1;
1574 1.1 hans
1575 1.1 hans for (; i <= spx_font.fontheight - 1; i++) {
1576 1.1 hans for (j = 0; j < (spx_font.fontwidth >> 2); j++)
1577 1.1 hans set_btreg(SPXDAC_REG_CRAM_BASE + i*16 + j, 0xff);
1578 1.1 hans k = (spx_font.fontwidth & 3) << 1;
1579 1.1 hans set_btreg(SPXDAC_REG_CRAM_BASE + i*16 + j, (1 << k) - 1);
1580 1.1 hans }
1581 1.1 hans
1582 1.1 hans if (fb_type == FB_IS_SPX) {
1583 1.1 hans /* set SPX write/read plane masks */
1584 1.1 hans SPX_REG(0x3170) = 0xffffffff;
1585 1.1 hans SPX_REG(0x3174) = 0xffffffff;
1586 1.1 hans }
1587 1.1 hans
1588 1.1 hans /* RAMDAC type-specific configuration */
1589 1.1 hans if (fb_type == FB_IS_SPX)
1590 1.1 hans set_btreg(SPXDAC_REG_CMD2, 0xc0);
1591 1.1 hans
1592 1.1 hans /* common configuration */
1593 1.1 hans set_btreg(SPXDAC_REG_CMD0, 0x48);
1594 1.1 hans set_btreg(SPXDAC_REG_CMD1, 0x00);
1595 1.1 hans set_btreg(SPXDAC_REG_PRM, 0xff);
1596 1.1 hans
1597 1.1 hans set_btreg(SPXDAC_REG_CXLO, 0);
1598 1.1 hans set_btreg(SPXDAC_REG_CXHI, 0);
1599 1.1 hans set_btreg(SPXDAC_REG_CYLO, 0);
1600 1.1 hans set_btreg(SPXDAC_REG_CYHI, 0);
1601 1.1 hans
1602 1.1 hans set_btreg(SPXDAC_REG_WXLO, 0);
1603 1.1 hans set_btreg(SPXDAC_REG_WXHI, 0);
1604 1.1 hans set_btreg(SPXDAC_REG_WYLO, 0);
1605 1.1 hans set_btreg(SPXDAC_REG_WYHI, 0);
1606 1.1 hans
1607 1.1 hans set_btreg(SPXDAC_REG_WWLO, 0);
1608 1.1 hans set_btreg(SPXDAC_REG_WWHI, 0);
1609 1.1 hans set_btreg(SPXDAC_REG_WHLO, 0);
1610 1.1 hans set_btreg(SPXDAC_REG_WHHI, 0);
1611 1.1 hans }
1612