tfb.c revision 1.11.4.2 1 1.11.4.2 thorpej /* $NetBSD: tfb.c,v 1.11.4.2 1999/07/01 23:37:32 thorpej Exp $ */
2 1.2 nisimura
3 1.2 nisimura /*
4 1.11.4.2 thorpej * Copyright (c) 1998, 1999 Tohru Nishimura. All rights reserved.
5 1.2 nisimura *
6 1.2 nisimura * Redistribution and use in source and binary forms, with or without
7 1.2 nisimura * modification, are permitted provided that the following conditions
8 1.2 nisimura * are met:
9 1.2 nisimura * 1. Redistributions of source code must retain the above copyright
10 1.2 nisimura * notice, this list of conditions and the following disclaimer.
11 1.2 nisimura * 2. Redistributions in binary form must reproduce the above copyright
12 1.2 nisimura * notice, this list of conditions and the following disclaimer in the
13 1.2 nisimura * documentation and/or other materials provided with the distribution.
14 1.2 nisimura * 3. All advertising materials mentioning features or use of this software
15 1.2 nisimura * must display the following acknowledgement:
16 1.2 nisimura * This product includes software developed by Tohru Nishimura
17 1.2 nisimura * for the NetBSD Project.
18 1.2 nisimura * 4. The name of the author may not be used to endorse or promote products
19 1.2 nisimura * derived from this software without specific prior written permission
20 1.2 nisimura *
21 1.2 nisimura * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.2 nisimura * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.2 nisimura * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.2 nisimura * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.2 nisimura * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.2 nisimura * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.2 nisimura * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.2 nisimura * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.2 nisimura * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.2 nisimura * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.2 nisimura */
32 1.1 nisimura
33 1.1 nisimura #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
34 1.1 nisimura
35 1.11.4.2 thorpej __KERNEL_RCSID(0, "$NetBSD: tfb.c,v 1.11.4.2 1999/07/01 23:37:32 thorpej Exp $");
36 1.1 nisimura
37 1.1 nisimura #include <sys/param.h>
38 1.1 nisimura #include <sys/systm.h>
39 1.1 nisimura #include <sys/kernel.h>
40 1.1 nisimura #include <sys/device.h>
41 1.1 nisimura #include <sys/malloc.h>
42 1.1 nisimura #include <sys/buf.h>
43 1.1 nisimura #include <sys/ioctl.h>
44 1.1 nisimura #include <vm/vm.h>
45 1.1 nisimura
46 1.1 nisimura #include <machine/bus.h>
47 1.1 nisimura #include <machine/intr.h>
48 1.1 nisimura
49 1.1 nisimura #include <dev/rcons/raster.h>
50 1.1 nisimura #include <dev/wscons/wsconsio.h>
51 1.1 nisimura #include <dev/wscons/wscons_raster.h>
52 1.1 nisimura #include <dev/wscons/wsdisplayvar.h>
53 1.1 nisimura
54 1.1 nisimura #include <dev/tc/tcvar.h>
55 1.1 nisimura #include <dev/ic/bt463reg.h>
56 1.1 nisimura #include <dev/ic/bt431reg.h>
57 1.1 nisimura
58 1.1 nisimura #include <uvm/uvm_extern.h>
59 1.1 nisimura
60 1.8 thorpej #if defined(pmax)
61 1.1 nisimura #define machine_btop(x) mips_btop(x)
62 1.1 nisimura #define MACHINE_KSEG0_TO_PHYS(x) MIPS_KSEG0_TO_PHYS(x)
63 1.1 nisimura
64 1.4 nisimura /*
65 1.11.4.2 thorpej * struct bt463reg {
66 1.11.4.2 thorpej * u_int8_t bt_lo;
67 1.11.4.2 thorpej * unsigned : 24;
68 1.11.4.2 thorpej * u_int8_t bt_hi;
69 1.11.4.2 thorpej * unsigned : 24;
70 1.11.4.2 thorpej * u_int8_t bt_reg;
71 1.11.4.2 thorpej * unsigned : 24;
72 1.11.4.2 thorpej * u_int8_t bt_cmap;
73 1.11.4.2 thorpej * };
74 1.11.4.2 thorpej *
75 1.6 nisimura * N.B. a pair of Bt431s are located adjascently.
76 1.4 nisimura * struct bt431twin {
77 1.4 nisimura * struct {
78 1.4 nisimura * u_int8_t u0; for sprite image
79 1.4 nisimura * u_int8_t u1; for sprite mask
80 1.4 nisimura * unsigned :16;
81 1.4 nisimura * } bt_lo;
82 1.4 nisimura * ...
83 1.11.4.2 thorpej *
84 1.11.4.2 thorpej * struct bt431reg {
85 1.11.4.2 thorpej * u_int16_t bt_lo;
86 1.11.4.2 thorpej * unsigned : 16;
87 1.11.4.2 thorpej * u_int16_t bt_hi;
88 1.11.4.2 thorpej * unsigned : 16;
89 1.11.4.2 thorpej * u_int16_t bt_ram;
90 1.11.4.2 thorpej * unsigned : 16;
91 1.11.4.2 thorpej * u_int16_t bt_ctl;
92 1.11.4.2 thorpej * };
93 1.4 nisimura */
94 1.11.4.2 thorpej
95 1.11.4.2 thorpej #define BYTE(base, index) *((u_int8_t *)(base) + ((index)<<2))
96 1.11.4.2 thorpej #define HALF(base, index) *((u_int16_t *)(base) + ((index)<<1))
97 1.11.4.2 thorpej
98 1.1 nisimura #endif
99 1.1 nisimura
100 1.1 nisimura #if defined(__alpha__) || defined(alpha)
101 1.1 nisimura #define machine_btop(x) alpha_btop(x)
102 1.1 nisimura #define MACHINE_KSEG0_TO_PHYS(x) ALPHA_K0SEG_TO_PHYS(x)
103 1.1 nisimura
104 1.11.4.2 thorpej /*
105 1.11.4.2 thorpej * struct bt463reg {
106 1.11.4.2 thorpej * u_int32_t bt_lo;
107 1.11.4.2 thorpej * u_int32_t bt_hi;
108 1.11.4.2 thorpej * u_int32_t bt_reg;
109 1.11.4.2 thorpej * u_int32_t bt_cmap;
110 1.11.4.2 thorpej * };
111 1.11.4.2 thorpej *
112 1.11.4.2 thorpej * struct bt431reg {
113 1.11.4.2 thorpej * u_int32_t bt_lo;
114 1.11.4.2 thorpej * u_int32_t bt_hi;
115 1.11.4.2 thorpej * u_int32_t bt_ram;
116 1.11.4.2 thorpej * u_int32_t bt_ctl;
117 1.11.4.2 thorpej * };
118 1.11.4.2 thorpej */
119 1.11.4.2 thorpej
120 1.11.4.2 thorpej #define BYTE(base, index) *((u_int32_t *)(base) + (index))
121 1.11.4.2 thorpej #define HALF(base, index) *((u_int32_t *)(base) + (index))
122 1.1 nisimura
123 1.1 nisimura #endif
124 1.1 nisimura
125 1.11.4.2 thorpej /* Bt463 hardware registers */
126 1.11.4.2 thorpej #define bt_lo 0
127 1.11.4.2 thorpej #define bt_hi 1
128 1.11.4.2 thorpej #define bt_ram 2
129 1.11.4.2 thorpej #define bt_ctl 3
130 1.11.4.2 thorpej
131 1.11.4.2 thorpej /* Bt431 hardware registers */
132 1.11.4.2 thorpej #define bt_reg 2
133 1.11.4.2 thorpej #define bt_cmap 3
134 1.11.4.2 thorpej
135 1.11.4.2 thorpej #define SELECT463(vdac, regno) do { \
136 1.11.4.2 thorpej BYTE(vdac, bt_lo) = (regno) & 0x00ff; \
137 1.11.4.2 thorpej BYTE(vdac, bt_hi) = ((regno)& 0xff00) >> 8; \
138 1.11.4.2 thorpej tc_wmb(); \
139 1.11.4.2 thorpej } while (0)
140 1.11.4.2 thorpej
141 1.11.4.2 thorpej #define TWIN(x) ((x) | ((x) << 8))
142 1.11.4.2 thorpej #define TWIN_LO(x) (twin = (x) & 0x00ff, (twin << 8) | twin)
143 1.11.4.2 thorpej #define TWIN_HI(x) (twin = (x) & 0xff00, twin | (twin >> 8))
144 1.11.4.2 thorpej
145 1.11.4.2 thorpej #define SELECT431(curs, regno) do { \
146 1.11.4.2 thorpej HALF(curs, bt_lo) = TWIN(regno);\
147 1.11.4.2 thorpej HALF(curs, bt_hi) = 0; \
148 1.11.4.2 thorpej tc_wmb(); \
149 1.11.4.2 thorpej } while (0)
150 1.1 nisimura
151 1.1 nisimura struct fb_devconfig {
152 1.1 nisimura vaddr_t dc_vaddr; /* memory space virtual base address */
153 1.1 nisimura paddr_t dc_paddr; /* memory space physical base address */
154 1.1 nisimura vsize_t dc_size; /* size of slot memory */
155 1.1 nisimura int dc_wid; /* width of frame buffer */
156 1.1 nisimura int dc_ht; /* height of frame buffer */
157 1.1 nisimura int dc_depth; /* depth, bits per pixel */
158 1.1 nisimura int dc_rowbytes; /* bytes in a FB scan line */
159 1.1 nisimura vaddr_t dc_videobase; /* base of flat frame buffer */
160 1.1 nisimura struct raster dc_raster; /* raster description */
161 1.1 nisimura struct rcons dc_rcons; /* raster blitter control info */
162 1.1 nisimura int dc_blanked; /* currently has video disabled */
163 1.1 nisimura };
164 1.1 nisimura
165 1.11.4.1 thorpej struct hwcmap256 {
166 1.1 nisimura #define CMAP_SIZE 256 /* R/G/B entries */
167 1.1 nisimura u_int8_t r[CMAP_SIZE];
168 1.1 nisimura u_int8_t g[CMAP_SIZE];
169 1.1 nisimura u_int8_t b[CMAP_SIZE];
170 1.1 nisimura };
171 1.1 nisimura
172 1.11.4.1 thorpej struct hwcursor64 {
173 1.1 nisimura struct wsdisplay_curpos cc_pos;
174 1.1 nisimura struct wsdisplay_curpos cc_hot;
175 1.1 nisimura struct wsdisplay_curpos cc_size;
176 1.11.4.1 thorpej struct wsdisplay_curpos cc_magic;
177 1.1 nisimura #define CURSOR_MAX_SIZE 64
178 1.1 nisimura u_int8_t cc_color[6];
179 1.1 nisimura u_int64_t cc_image[64 + 64];
180 1.1 nisimura };
181 1.1 nisimura
182 1.1 nisimura struct tfb_softc {
183 1.1 nisimura struct device sc_dev;
184 1.1 nisimura struct fb_devconfig *sc_dc; /* device configuration */
185 1.11.4.1 thorpej struct hwcmap256 sc_cmap; /* software copy of colormap */
186 1.11.4.1 thorpej struct hwcursor64 sc_cursor; /* software copy of cursor */
187 1.1 nisimura int sc_curenb; /* cursor sprite enabled */
188 1.1 nisimura int sc_changed; /* need update of colormap */
189 1.1 nisimura #define DATA_ENB_CHANGED 0x01 /* cursor enable changed */
190 1.1 nisimura #define DATA_CURCMAP_CHANGED 0x02 /* cursor colormap changed */
191 1.1 nisimura #define DATA_CURSHAPE_CHANGED 0x04 /* cursor size, image, mask changed */
192 1.1 nisimura #define DATA_CMAP_CHANGED 0x08 /* colormap changed */
193 1.1 nisimura #define DATA_ALL_CHANGED 0x0f
194 1.1 nisimura int nscreens;
195 1.11.4.1 thorpej };
196 1.11.4.1 thorpej
197 1.3 nisimura #define TX_MAGIC_X 220
198 1.3 nisimura #define TX_MAGIC_Y 35
199 1.1 nisimura
200 1.3 nisimura #define TX_BT463_OFFSET 0x040000
201 1.3 nisimura #define TX_BT431_OFFSET 0x040010
202 1.3 nisimura #define TX_CONTROL 0x040030
203 1.3 nisimura #define TX_MAP_REGISTER 0x040030
204 1.3 nisimura #define TX_PIP_OFFSET 0x0800c0
205 1.3 nisimura #define TX_SELECTION 0x100000
206 1.3 nisimura #define TX_8FB_OFFSET 0x200000
207 1.3 nisimura #define TX_8FB_SIZE 0x100000
208 1.3 nisimura #define TX_24FB_OFFSET 0x400000
209 1.3 nisimura #define TX_24FB_SIZE 0x400000
210 1.3 nisimura #define TX_VIDEO_ENABLE 0xa00000
211 1.3 nisimura
212 1.3 nisimura #define TX_CTL_VIDEO_ON 0x80
213 1.3 nisimura #define TX_CTL_INT_ENA 0x40
214 1.3 nisimura #define TX_CTL_INT_PEND 0x20
215 1.3 nisimura #define TX_CTL_SEG_ENA 0x10
216 1.3 nisimura #define TX_CTL_SEG 0x0f
217 1.3 nisimura
218 1.1 nisimura int tfbmatch __P((struct device *, struct cfdata *, void *));
219 1.1 nisimura void tfbattach __P((struct device *, struct device *, void *));
220 1.1 nisimura
221 1.1 nisimura struct cfattach tfb_ca = {
222 1.1 nisimura sizeof(struct tfb_softc), tfbmatch, tfbattach,
223 1.1 nisimura };
224 1.1 nisimura
225 1.1 nisimura void tfb_getdevconfig __P((tc_addr_t, struct fb_devconfig *));
226 1.1 nisimura struct fb_devconfig tfb_console_dc;
227 1.1 nisimura tc_addr_t tfb_consaddr;
228 1.1 nisimura
229 1.1 nisimura struct wsdisplay_emulops tfb_emulops = {
230 1.1 nisimura rcons_cursor, /* could use hardware cursor; punt */
231 1.1 nisimura rcons_mapchar,
232 1.1 nisimura rcons_putchar,
233 1.1 nisimura rcons_copycols,
234 1.1 nisimura rcons_erasecols,
235 1.1 nisimura rcons_copyrows,
236 1.1 nisimura rcons_eraserows,
237 1.1 nisimura rcons_alloc_attr
238 1.1 nisimura };
239 1.1 nisimura
240 1.1 nisimura struct wsscreen_descr tfb_stdscreen = {
241 1.1 nisimura "std", 0, 0,
242 1.1 nisimura &tfb_emulops,
243 1.1 nisimura 0, 0,
244 1.1 nisimura 0
245 1.1 nisimura };
246 1.1 nisimura
247 1.1 nisimura const struct wsscreen_descr *_tfb_scrlist[] = {
248 1.1 nisimura &tfb_stdscreen,
249 1.1 nisimura };
250 1.1 nisimura
251 1.1 nisimura struct wsscreen_list tfb_screenlist = {
252 1.1 nisimura sizeof(_tfb_scrlist) / sizeof(struct wsscreen_descr *), _tfb_scrlist
253 1.1 nisimura };
254 1.1 nisimura
255 1.1 nisimura int tfbioctl __P((void *, u_long, caddr_t, int, struct proc *));
256 1.1 nisimura int tfbmmap __P((void *, off_t, int));
257 1.1 nisimura
258 1.1 nisimura int tfb_alloc_screen __P((void *, const struct wsscreen_descr *,
259 1.1 nisimura void **, int *, int *, long *));
260 1.1 nisimura void tfb_free_screen __P((void *, void *));
261 1.1 nisimura void tfb_show_screen __P((void *, void *));
262 1.1 nisimura
263 1.1 nisimura struct wsdisplay_accessops tfb_accessops = {
264 1.1 nisimura tfbioctl,
265 1.1 nisimura tfbmmap,
266 1.1 nisimura tfb_alloc_screen,
267 1.1 nisimura tfb_free_screen,
268 1.1 nisimura tfb_show_screen,
269 1.7 drochner 0 /* load_font */
270 1.1 nisimura };
271 1.1 nisimura
272 1.1 nisimura int tfb_cnattach __P((tc_addr_t));
273 1.1 nisimura int tfbintr __P((void *));
274 1.1 nisimura void tfbinit __P((struct fb_devconfig *));
275 1.1 nisimura
276 1.1 nisimura static int get_cmap __P((struct tfb_softc *, struct wsdisplay_cmap *));
277 1.1 nisimura static int set_cmap __P((struct tfb_softc *, struct wsdisplay_cmap *));
278 1.1 nisimura static int set_cursor __P((struct tfb_softc *, struct wsdisplay_cursor *));
279 1.1 nisimura static int get_cursor __P((struct tfb_softc *, struct wsdisplay_cursor *));
280 1.1 nisimura static void set_curpos __P((struct tfb_softc *, struct wsdisplay_curpos *));
281 1.1 nisimura static void bt431_set_curpos __P((struct tfb_softc *));
282 1.1 nisimura
283 1.3 nisimura /* bit order reverse */
284 1.3 nisimura const static u_int8_t flip[256] = {
285 1.3 nisimura 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
286 1.3 nisimura 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
287 1.3 nisimura 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
288 1.3 nisimura 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
289 1.3 nisimura 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
290 1.3 nisimura 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
291 1.3 nisimura 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
292 1.3 nisimura 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
293 1.3 nisimura 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
294 1.3 nisimura 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
295 1.3 nisimura 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
296 1.3 nisimura 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
297 1.3 nisimura 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
298 1.3 nisimura 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
299 1.3 nisimura 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
300 1.3 nisimura 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
301 1.3 nisimura 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
302 1.3 nisimura 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
303 1.3 nisimura 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
304 1.3 nisimura 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
305 1.3 nisimura 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
306 1.3 nisimura 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
307 1.3 nisimura 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
308 1.3 nisimura 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
309 1.3 nisimura 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
310 1.3 nisimura 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
311 1.3 nisimura 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
312 1.3 nisimura 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
313 1.3 nisimura 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
314 1.3 nisimura 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
315 1.3 nisimura 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
316 1.3 nisimura 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
317 1.3 nisimura };
318 1.1 nisimura
319 1.1 nisimura int
320 1.1 nisimura tfbmatch(parent, match, aux)
321 1.1 nisimura struct device *parent;
322 1.1 nisimura struct cfdata *match;
323 1.1 nisimura void *aux;
324 1.1 nisimura {
325 1.1 nisimura struct tc_attach_args *ta = aux;
326 1.1 nisimura
327 1.1 nisimura if (strncmp("PMAG-RO ", ta->ta_modname, TC_ROM_LLEN) != 0
328 1.1 nisimura && strncmp("PMAG-JA ", ta->ta_modname, TC_ROM_LLEN) != 0)
329 1.1 nisimura return (0);
330 1.1 nisimura
331 1.1 nisimura return (1);
332 1.1 nisimura }
333 1.1 nisimura
334 1.1 nisimura void
335 1.1 nisimura tfb_getdevconfig(dense_addr, dc)
336 1.1 nisimura tc_addr_t dense_addr;
337 1.1 nisimura struct fb_devconfig *dc;
338 1.1 nisimura {
339 1.1 nisimura struct raster *rap;
340 1.1 nisimura struct rcons *rcp;
341 1.1 nisimura int i;
342 1.1 nisimura
343 1.1 nisimura dc->dc_vaddr = dense_addr;
344 1.1 nisimura dc->dc_paddr = MACHINE_KSEG0_TO_PHYS(dc->dc_vaddr);
345 1.1 nisimura
346 1.1 nisimura dc->dc_wid = 1280;
347 1.1 nisimura dc->dc_ht = 1024;
348 1.1 nisimura dc->dc_depth = 8;
349 1.1 nisimura dc->dc_rowbytes = 1280;
350 1.1 nisimura dc->dc_videobase = dc->dc_vaddr + TX_8FB_OFFSET;
351 1.1 nisimura dc->dc_blanked = 0;
352 1.1 nisimura
353 1.1 nisimura /* initialize colormap and cursor resource */
354 1.1 nisimura tfbinit(dc);
355 1.1 nisimura
356 1.1 nisimura /* clear the screen */
357 1.1 nisimura for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
358 1.1 nisimura *(u_int32_t *)(dc->dc_videobase + i) = 0x0;
359 1.1 nisimura
360 1.1 nisimura /* initialize the raster */
361 1.1 nisimura rap = &dc->dc_raster;
362 1.1 nisimura rap->width = dc->dc_wid;
363 1.1 nisimura rap->height = dc->dc_ht;
364 1.1 nisimura rap->depth = dc->dc_depth;
365 1.1 nisimura rap->linelongs = dc->dc_rowbytes / sizeof(u_int32_t);
366 1.1 nisimura rap->pixels = (u_int32_t *)dc->dc_videobase;
367 1.1 nisimura
368 1.1 nisimura /* initialize the raster console blitter */
369 1.1 nisimura rcp = &dc->dc_rcons;
370 1.1 nisimura rcp->rc_sp = rap;
371 1.1 nisimura rcp->rc_crow = rcp->rc_ccol = -1;
372 1.1 nisimura rcp->rc_crowp = &rcp->rc_crow;
373 1.1 nisimura rcp->rc_ccolp = &rcp->rc_ccol;
374 1.1 nisimura rcons_init(rcp, 34, 80);
375 1.1 nisimura
376 1.1 nisimura tfb_stdscreen.nrows = dc->dc_rcons.rc_maxrow;
377 1.1 nisimura tfb_stdscreen.ncols = dc->dc_rcons.rc_maxcol;
378 1.1 nisimura }
379 1.1 nisimura
380 1.1 nisimura void
381 1.1 nisimura tfbattach(parent, self, aux)
382 1.1 nisimura struct device *parent, *self;
383 1.1 nisimura void *aux;
384 1.1 nisimura {
385 1.1 nisimura struct tfb_softc *sc = (struct tfb_softc *)self;
386 1.1 nisimura struct tc_attach_args *ta = aux;
387 1.1 nisimura struct wsemuldisplaydev_attach_args waa;
388 1.11.4.1 thorpej struct hwcmap256 *cm;
389 1.11.4.1 thorpej int console;
390 1.1 nisimura
391 1.1 nisimura console = (ta->ta_addr == tfb_consaddr);
392 1.1 nisimura if (console) {
393 1.1 nisimura sc->sc_dc = &tfb_console_dc;
394 1.1 nisimura sc->nscreens = 1;
395 1.1 nisimura }
396 1.1 nisimura else {
397 1.1 nisimura sc->sc_dc = (struct fb_devconfig *)
398 1.1 nisimura malloc(sizeof(struct fb_devconfig), M_DEVBUF, M_WAITOK);
399 1.1 nisimura tfb_getdevconfig(ta->ta_addr, sc->sc_dc);
400 1.1 nisimura }
401 1.1 nisimura printf(": %d x %d, %dbpp\n", sc->sc_dc->dc_wid, sc->sc_dc->dc_ht,
402 1.1 nisimura sc->sc_dc->dc_depth);
403 1.1 nisimura
404 1.1 nisimura cm = &sc->sc_cmap;
405 1.11.4.1 thorpej memset(cm, 255, sizeof(struct hwcmap256)); /* XXX */
406 1.11.4.1 thorpej cm->r[0] = cm->g[0] = cm->b[0] = 0; /* XXX */
407 1.11.4.1 thorpej
408 1.11.4.1 thorpej sc->sc_cursor.cc_magic.x = TX_MAGIC_X;
409 1.11.4.1 thorpej sc->sc_cursor.cc_magic.y = TX_MAGIC_Y;
410 1.1 nisimura
411 1.1 nisimura tc_intr_establish(parent, ta->ta_cookie, TC_IPL_TTY, tfbintr, sc);
412 1.11.4.1 thorpej
413 1.1 nisimura *(u_int8_t *)(sc->sc_dc->dc_vaddr + TX_CONTROL) &= ~0x40;
414 1.1 nisimura *(u_int8_t *)(sc->sc_dc->dc_vaddr + TX_CONTROL) |= 0x40;
415 1.1 nisimura
416 1.1 nisimura waa.console = console;
417 1.1 nisimura waa.scrdata = &tfb_screenlist;
418 1.1 nisimura waa.accessops = &tfb_accessops;
419 1.1 nisimura waa.accesscookie = sc;
420 1.1 nisimura
421 1.1 nisimura config_found(self, &waa, wsemuldisplaydevprint);
422 1.1 nisimura }
423 1.1 nisimura
424 1.1 nisimura int
425 1.1 nisimura tfbioctl(v, cmd, data, flag, p)
426 1.1 nisimura void *v;
427 1.1 nisimura u_long cmd;
428 1.1 nisimura caddr_t data;
429 1.1 nisimura int flag;
430 1.1 nisimura struct proc *p;
431 1.1 nisimura {
432 1.1 nisimura struct tfb_softc *sc = v;
433 1.1 nisimura struct fb_devconfig *dc = sc->sc_dc;
434 1.1 nisimura int turnoff;
435 1.1 nisimura
436 1.1 nisimura switch (cmd) {
437 1.1 nisimura case WSDISPLAYIO_GTYPE:
438 1.1 nisimura *(u_int *)data = /* WSDISPLAY_TYPE_TX */ 0x19980910;
439 1.1 nisimura return (0);
440 1.1 nisimura
441 1.1 nisimura case WSDISPLAYIO_GINFO:
442 1.1 nisimura #define wsd_fbip ((struct wsdisplay_fbinfo *)data)
443 1.1 nisimura wsd_fbip->height = sc->sc_dc->dc_ht;
444 1.1 nisimura wsd_fbip->width = sc->sc_dc->dc_wid;
445 1.1 nisimura wsd_fbip->depth = sc->sc_dc->dc_depth;
446 1.1 nisimura wsd_fbip->cmsize = CMAP_SIZE;
447 1.1 nisimura #undef fbt
448 1.1 nisimura return (0);
449 1.1 nisimura
450 1.1 nisimura case WSDISPLAYIO_GETCMAP:
451 1.1 nisimura return get_cmap(sc, (struct wsdisplay_cmap *)data);
452 1.1 nisimura
453 1.1 nisimura case WSDISPLAYIO_PUTCMAP:
454 1.1 nisimura return set_cmap(sc, (struct wsdisplay_cmap *)data);
455 1.1 nisimura
456 1.1 nisimura case WSDISPLAYIO_SVIDEO:
457 1.1 nisimura turnoff = *(int *)data == WSDISPLAYIO_VIDEO_OFF;
458 1.1 nisimura if ((dc->dc_blanked == 0) ^ turnoff) {
459 1.1 nisimura dc->dc_blanked = turnoff;
460 1.11.4.2 thorpej #if 0 /* XXX later XXX */
461 1.11.4.2 thorpej To turn off;
462 1.11.4.2 thorpej - clear the MSB of TX control register; &= ~0x80,
463 1.11.4.2 thorpej - assign Bt431 register #0 with value 0x4 to hide sprite cursor.
464 1.11.4.2 thorpej #endif /* XXX XXX XXX */
465 1.1 nisimura }
466 1.1 nisimura return (0);
467 1.1 nisimura
468 1.1 nisimura case WSDISPLAYIO_GVIDEO:
469 1.1 nisimura *(u_int *)data = dc->dc_blanked ?
470 1.1 nisimura WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
471 1.1 nisimura return (0);
472 1.1 nisimura
473 1.1 nisimura case WSDISPLAYIO_GCURPOS:
474 1.1 nisimura *(struct wsdisplay_curpos *)data = sc->sc_cursor.cc_pos;
475 1.1 nisimura return (0);
476 1.1 nisimura
477 1.1 nisimura case WSDISPLAYIO_SCURPOS:
478 1.1 nisimura set_curpos(sc, (struct wsdisplay_curpos *)data);
479 1.1 nisimura bt431_set_curpos(sc);
480 1.1 nisimura return (0);
481 1.1 nisimura
482 1.1 nisimura case WSDISPLAYIO_GCURMAX:
483 1.1 nisimura ((struct wsdisplay_curpos *)data)->x =
484 1.1 nisimura ((struct wsdisplay_curpos *)data)->y = CURSOR_MAX_SIZE;
485 1.1 nisimura return (0);
486 1.1 nisimura
487 1.1 nisimura case WSDISPLAYIO_GCURSOR:
488 1.1 nisimura return get_cursor(sc, (struct wsdisplay_cursor *)data);
489 1.1 nisimura
490 1.1 nisimura case WSDISPLAYIO_SCURSOR:
491 1.1 nisimura return set_cursor(sc, (struct wsdisplay_cursor *)data);
492 1.1 nisimura }
493 1.6 nisimura return (ENOTTY);
494 1.1 nisimura }
495 1.1 nisimura
496 1.1 nisimura int
497 1.1 nisimura tfbmmap(v, offset, prot)
498 1.1 nisimura void *v;
499 1.1 nisimura off_t offset;
500 1.1 nisimura int prot;
501 1.1 nisimura {
502 1.1 nisimura struct tfb_softc *sc = v;
503 1.1 nisimura
504 1.5 mrg if (offset >= TX_8FB_SIZE || offset < 0)
505 1.1 nisimura return (-1);
506 1.1 nisimura return machine_btop(sc->sc_dc->dc_paddr + TX_8FB_OFFSET + offset);
507 1.1 nisimura }
508 1.1 nisimura
509 1.1 nisimura int
510 1.1 nisimura tfb_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
511 1.1 nisimura void *v;
512 1.1 nisimura const struct wsscreen_descr *type;
513 1.1 nisimura void **cookiep;
514 1.1 nisimura int *curxp, *curyp;
515 1.1 nisimura long *attrp;
516 1.1 nisimura {
517 1.1 nisimura struct tfb_softc *sc = v;
518 1.1 nisimura long defattr;
519 1.1 nisimura
520 1.1 nisimura if (sc->nscreens > 0)
521 1.1 nisimura return (ENOMEM);
522 1.1 nisimura
523 1.1 nisimura *cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */
524 1.1 nisimura *curxp = 0;
525 1.1 nisimura *curyp = 0;
526 1.1 nisimura rcons_alloc_attr(&sc->sc_dc->dc_rcons, 0, 0, 0, &defattr);
527 1.1 nisimura *attrp = defattr;
528 1.1 nisimura sc->nscreens++;
529 1.1 nisimura return (0);
530 1.1 nisimura }
531 1.1 nisimura
532 1.1 nisimura void
533 1.1 nisimura tfb_free_screen(v, cookie)
534 1.1 nisimura void *v;
535 1.1 nisimura void *cookie;
536 1.1 nisimura {
537 1.1 nisimura struct tfb_softc *sc = v;
538 1.1 nisimura
539 1.1 nisimura if (sc->sc_dc == &tfb_console_dc)
540 1.1 nisimura panic("tfb_free_screen: console");
541 1.1 nisimura
542 1.1 nisimura sc->nscreens--;
543 1.1 nisimura }
544 1.1 nisimura
545 1.1 nisimura void
546 1.1 nisimura tfb_show_screen(v, cookie)
547 1.1 nisimura void *v;
548 1.1 nisimura void *cookie;
549 1.1 nisimura {
550 1.1 nisimura }
551 1.1 nisimura
552 1.1 nisimura int
553 1.1 nisimura tfb_cnattach(addr)
554 1.1 nisimura tc_addr_t addr;
555 1.1 nisimura {
556 1.1 nisimura struct fb_devconfig *dcp = &tfb_console_dc;
557 1.1 nisimura long defattr;
558 1.1 nisimura
559 1.1 nisimura tfb_getdevconfig(addr, dcp);
560 1.1 nisimura
561 1.1 nisimura rcons_alloc_attr(&dcp->dc_rcons, 0, 0, 0, &defattr);
562 1.1 nisimura
563 1.1 nisimura wsdisplay_cnattach(&tfb_stdscreen, &dcp->dc_rcons,
564 1.1 nisimura 0, 0, defattr);
565 1.1 nisimura tfb_consaddr = addr;
566 1.1 nisimura return(0);
567 1.1 nisimura }
568 1.1 nisimura
569 1.1 nisimura int
570 1.1 nisimura tfbintr(arg)
571 1.1 nisimura void *arg;
572 1.1 nisimura {
573 1.1 nisimura struct tfb_softc *sc = arg;
574 1.3 nisimura caddr_t tfbbase;
575 1.11.4.2 thorpej void *vdac, *curs;
576 1.1 nisimura int v;
577 1.1 nisimura
578 1.1 nisimura if (sc->sc_changed == 0)
579 1.1 nisimura return (1);
580 1.1 nisimura
581 1.3 nisimura tfbbase = (caddr_t)sc->sc_dc->dc_vaddr;
582 1.1 nisimura vdac = (void *)(tfbbase + TX_BT463_OFFSET);
583 1.1 nisimura curs = (void *)(tfbbase + TX_BT431_OFFSET);
584 1.3 nisimura *(u_int8_t *)(tfbbase + TX_CONTROL) &= ~0x40;
585 1.1 nisimura v = sc->sc_changed;
586 1.1 nisimura sc->sc_changed = 0;
587 1.1 nisimura if (v & DATA_ENB_CHANGED) {
588 1.11.4.2 thorpej SELECT431(curs, BT431_REG_COMMAND);
589 1.11.4.2 thorpej HALF(curs, bt_ctl) = (sc->sc_curenb) ? 0x4444 : 0x0404;
590 1.1 nisimura }
591 1.1 nisimura if (v & DATA_CURCMAP_CHANGED) {
592 1.1 nisimura u_int8_t *cp = sc->sc_cursor.cc_color;
593 1.1 nisimura
594 1.11.4.2 thorpej SELECT463(vdac, BT463_IREG_CURSOR_COLOR_0);
595 1.11.4.2 thorpej BYTE(vdac, bt_reg) = cp[1]; tc_wmb();
596 1.11.4.2 thorpej BYTE(vdac, bt_reg) = cp[3]; tc_wmb();
597 1.11.4.2 thorpej BYTE(vdac, bt_reg) = cp[5]; tc_wmb();
598 1.11.4.2 thorpej
599 1.11.4.2 thorpej BYTE(vdac, bt_reg) = cp[0]; tc_wmb();
600 1.11.4.2 thorpej BYTE(vdac, bt_reg) = cp[2]; tc_wmb();
601 1.11.4.2 thorpej BYTE(vdac, bt_reg) = cp[4]; tc_wmb();
602 1.11.4.2 thorpej
603 1.11.4.2 thorpej BYTE(vdac, bt_reg) = cp[1]; tc_wmb();
604 1.11.4.2 thorpej BYTE(vdac, bt_reg) = cp[3]; tc_wmb();
605 1.11.4.2 thorpej BYTE(vdac, bt_reg) = cp[5]; tc_wmb();
606 1.11.4.2 thorpej
607 1.11.4.2 thorpej BYTE(vdac, bt_reg) = cp[1]; tc_wmb();
608 1.11.4.2 thorpej BYTE(vdac, bt_reg) = cp[3]; tc_wmb();
609 1.11.4.2 thorpej BYTE(vdac, bt_reg) = cp[5]; tc_wmb();
610 1.1 nisimura }
611 1.1 nisimura if (v & DATA_CURSHAPE_CHANGED) {
612 1.3 nisimura u_int8_t *ip, *mp, img, msk;
613 1.3 nisimura int bcnt;
614 1.1 nisimura
615 1.3 nisimura ip = (u_int8_t *)sc->sc_cursor.cc_image;
616 1.3 nisimura mp = (u_int8_t *)(sc->sc_cursor.cc_image + CURSOR_MAX_SIZE);
617 1.1 nisimura
618 1.3 nisimura bcnt = 0;
619 1.11.4.2 thorpej SELECT431(curs, BT431_REG_CRAM_BASE+0);
620 1.3 nisimura /* 64 pixel scan line is consisted with 16 byte cursor ram */
621 1.3 nisimura while (bcnt < sc->sc_cursor.cc_size.y * 16) {
622 1.3 nisimura /* pad right half 32 pixel when smaller than 33 */
623 1.3 nisimura if ((bcnt & 0x8) && sc->sc_cursor.cc_size.x < 33) {
624 1.11.4.2 thorpej HALF(curs, bt_ram) = 0;
625 1.3 nisimura tc_wmb();
626 1.3 nisimura }
627 1.3 nisimura else {
628 1.3 nisimura img = *ip++;
629 1.3 nisimura msk = *mp++;
630 1.3 nisimura img &= msk; /* cookie off image */
631 1.11.4.2 thorpej HALF(curs, bt_ram) = (flip[msk] << 8) | flip[img];
632 1.3 nisimura tc_wmb();
633 1.3 nisimura }
634 1.3 nisimura bcnt += 2;
635 1.3 nisimura }
636 1.3 nisimura /* pad unoccupied scan lines */
637 1.3 nisimura while (bcnt < CURSOR_MAX_SIZE * 16) {
638 1.11.4.2 thorpej HALF(curs, bt_ram) = 0;
639 1.1 nisimura tc_wmb();
640 1.3 nisimura bcnt += 2;
641 1.1 nisimura }
642 1.1 nisimura }
643 1.1 nisimura if (v & DATA_CMAP_CHANGED) {
644 1.11.4.1 thorpej struct hwcmap256 *cm = &sc->sc_cmap;
645 1.1 nisimura int index;
646 1.1 nisimura
647 1.11.4.2 thorpej SELECT463(vdac, BT463_IREG_CPALETTE_RAM);
648 1.1 nisimura for (index = 0; index < CMAP_SIZE; index++) {
649 1.11.4.2 thorpej BYTE(vdac, bt_cmap) = cm->r[index];
650 1.11.4.2 thorpej BYTE(vdac, bt_cmap) = cm->g[index];
651 1.11.4.2 thorpej BYTE(vdac, bt_cmap) = cm->b[index];
652 1.1 nisimura }
653 1.1 nisimura }
654 1.3 nisimura *(u_int8_t *)(tfbbase + TX_CONTROL) |= 0x40;
655 1.1 nisimura return (1);
656 1.1 nisimura }
657 1.1 nisimura
658 1.1 nisimura void
659 1.1 nisimura tfbinit(dc)
660 1.1 nisimura struct fb_devconfig *dc;
661 1.1 nisimura {
662 1.1 nisimura caddr_t tfbbase = (caddr_t)dc->dc_vaddr;
663 1.11.4.2 thorpej void *vdac = (void *)(tfbbase + TX_BT463_OFFSET);
664 1.11.4.2 thorpej void *curs = (void *)(tfbbase + TX_BT431_OFFSET);
665 1.1 nisimura int i;
666 1.1 nisimura
667 1.11.4.2 thorpej SELECT463(vdac, BT463_IREG_COMMAND_0);
668 1.11.4.2 thorpej BYTE(vdac, bt_reg) = 0x40; tc_wmb();
669 1.11.4.2 thorpej BYTE(vdac, bt_reg) = 0x46; tc_wmb();
670 1.11.4.2 thorpej BYTE(vdac, bt_reg) = 0xc0; tc_wmb();
671 1.11.4.2 thorpej BYTE(vdac, bt_reg) = 0; tc_wmb(); /* !? 204 !? */
672 1.11.4.2 thorpej BYTE(vdac, bt_reg) = 0xff; tc_wmb(); /* plane 0:7 */
673 1.11.4.2 thorpej BYTE(vdac, bt_reg) = 0xff; tc_wmb(); /* plane 8:15 */
674 1.11.4.2 thorpej BYTE(vdac, bt_reg) = 0xff; tc_wmb(); /* plane 16:23 */
675 1.11.4.2 thorpej BYTE(vdac, bt_reg) = 0xff; tc_wmb(); /* plane 24:27 */
676 1.11.4.2 thorpej BYTE(vdac, bt_reg) = 0x00; tc_wmb(); /* blink 0:7 */
677 1.11.4.2 thorpej BYTE(vdac, bt_reg) = 0x00; tc_wmb(); /* blink 8:15 */
678 1.11.4.2 thorpej BYTE(vdac, bt_reg) = 0x00; tc_wmb(); /* blink 16:23 */
679 1.11.4.2 thorpej BYTE(vdac, bt_reg) = 0x00; tc_wmb(); /* blink 24:27 */
680 1.11.4.2 thorpej BYTE(vdac, bt_reg) = 0x00; tc_wmb();
681 1.11.4.2 thorpej
682 1.11.4.2 thorpej #if 0 /* XXX WHAT'S TX REALLY DOING HERE? XXX */
683 1.11.4.2 thorpej {
684 1.11.4.2 thorpej static struct {
685 1.11.4.2 thorpej u_int8_t x, y, z, u;
686 1.11.4.2 thorpej } windowtype[BT463_IREG_WINDOW_TYPE_TABLE] = {
687 1.11.4.2 thorpej { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
688 1.11.4.2 thorpej { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
689 1.11.4.2 thorpej { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
690 1.11.4.2 thorpej { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },
691 1.11.4.2 thorpej };
692 1.1 nisimura
693 1.11.4.2 thorpej SELECT463(vdac, BT463_IREG_WINDOW_TYPE_TABLE);
694 1.3 nisimura for (i = 0; i < BT463_NWTYPE_ENTRIES; i++) {
695 1.11.4.2 thorpej BYTE(vdac, bt_reg) = windowtype[i].x;
696 1.11.4.2 thorpej BYTE(vdac, bt_reg) = windowtype[i].y;
697 1.11.4.2 thorpej BYTE(vdac, bt_reg) = windowtype[i].z;
698 1.11.4.2 thorpej }
699 1.11.4.2 thorpej }
700 1.11.4.2 thorpej #endif
701 1.11.4.2 thorpej
702 1.11.4.2 thorpej SELECT463(vdac, BT463_IREG_CPALETTE_RAM);
703 1.11.4.2 thorpej BYTE(vdac, bt_cmap) = 0; tc_wmb();
704 1.11.4.2 thorpej BYTE(vdac, bt_cmap) = 0; tc_wmb();
705 1.11.4.2 thorpej BYTE(vdac, bt_cmap) = 0; tc_wmb();
706 1.11.4.2 thorpej for (i = 1; i < 256; i++) {
707 1.11.4.2 thorpej BYTE(vdac, bt_cmap) = 0xff; tc_wmb();
708 1.11.4.2 thorpej BYTE(vdac, bt_cmap) = 0xff; tc_wmb();
709 1.11.4.2 thorpej BYTE(vdac, bt_cmap) = 0xff; tc_wmb();
710 1.11.4.2 thorpej }
711 1.11.4.2 thorpej
712 1.11.4.2 thorpej SELECT463(vdac, BT463_IREG_CURSOR_COLOR_0);
713 1.11.4.2 thorpej BYTE(vdac, bt_reg) = 0; tc_wmb();
714 1.11.4.2 thorpej BYTE(vdac, bt_reg) = 0; tc_wmb();
715 1.11.4.2 thorpej BYTE(vdac, bt_reg) = 0; tc_wmb();
716 1.11.4.2 thorpej BYTE(vdac, bt_reg) = 0xff; tc_wmb();
717 1.11.4.2 thorpej BYTE(vdac, bt_reg) = 0xff; tc_wmb();
718 1.11.4.2 thorpej BYTE(vdac, bt_reg) = 0xff; tc_wmb();
719 1.11.4.2 thorpej for (i = 2; i < 256; i++) {
720 1.11.4.2 thorpej BYTE(vdac, bt_cmap) = 0; tc_wmb();
721 1.11.4.2 thorpej BYTE(vdac, bt_cmap) = 0; tc_wmb();
722 1.11.4.2 thorpej BYTE(vdac, bt_cmap) = 0; tc_wmb();
723 1.11.4.2 thorpej }
724 1.11.4.2 thorpej
725 1.11.4.2 thorpej SELECT431(curs, BT431_REG_COMMAND);
726 1.11.4.2 thorpej HALF(curs, bt_ctl) = 0x0404; tc_wmb();
727 1.11.4.2 thorpej HALF(curs, bt_ctl) = 0; /* XLO */ tc_wmb();
728 1.11.4.2 thorpej HALF(curs, bt_ctl) = 0; /* XHI */ tc_wmb();
729 1.11.4.2 thorpej HALF(curs, bt_ctl) = 0; /* YLO */ tc_wmb();
730 1.11.4.2 thorpej HALF(curs, bt_ctl) = 0; /* YHI */ tc_wmb();
731 1.11.4.2 thorpej HALF(curs, bt_ctl) = 0; /* XWLO */ tc_wmb();
732 1.11.4.2 thorpej HALF(curs, bt_ctl) = 0; /* XWHI */ tc_wmb();
733 1.11.4.2 thorpej HALF(curs, bt_ctl) = 0; /* WYLO */ tc_wmb();
734 1.11.4.2 thorpej HALF(curs, bt_ctl) = 0; /* WYLO */ tc_wmb();
735 1.11.4.2 thorpej HALF(curs, bt_ctl) = 0; /* WWLO */ tc_wmb();
736 1.11.4.2 thorpej HALF(curs, bt_ctl) = 0; /* WWHI */ tc_wmb();
737 1.11.4.2 thorpej HALF(curs, bt_ctl) = 0; /* WHLO */ tc_wmb();
738 1.11.4.2 thorpej HALF(curs, bt_ctl) = 0; /* WHHI */ tc_wmb();
739 1.11.4.2 thorpej
740 1.11.4.2 thorpej SELECT431(curs, BT431_REG_CRAM_BASE);
741 1.11.4.2 thorpej for (i = 0; i < 512; i++) {
742 1.11.4.2 thorpej HALF(curs, bt_ram) = 0; tc_wmb();
743 1.11.4.2 thorpej }
744 1.1 nisimura }
745 1.1 nisimura
746 1.1 nisimura static int
747 1.1 nisimura get_cmap(sc, p)
748 1.1 nisimura struct tfb_softc *sc;
749 1.1 nisimura struct wsdisplay_cmap *p;
750 1.1 nisimura {
751 1.1 nisimura u_int index = p->index, count = p->count;
752 1.1 nisimura
753 1.1 nisimura if (index >= CMAP_SIZE || (index + count) > CMAP_SIZE)
754 1.1 nisimura return (EINVAL);
755 1.1 nisimura
756 1.10 mrg if (!uvm_useracc(p->red, count, B_WRITE) ||
757 1.10 mrg !uvm_useracc(p->green, count, B_WRITE) ||
758 1.10 mrg !uvm_useracc(p->blue, count, B_WRITE))
759 1.1 nisimura return (EFAULT);
760 1.1 nisimura
761 1.1 nisimura copyout(&sc->sc_cmap.r[index], p->red, count);
762 1.1 nisimura copyout(&sc->sc_cmap.g[index], p->green, count);
763 1.1 nisimura copyout(&sc->sc_cmap.b[index], p->blue, count);
764 1.1 nisimura
765 1.1 nisimura return (0);
766 1.1 nisimura }
767 1.1 nisimura
768 1.1 nisimura static int
769 1.1 nisimura set_cmap(sc, p)
770 1.1 nisimura struct tfb_softc *sc;
771 1.1 nisimura struct wsdisplay_cmap *p;
772 1.1 nisimura {
773 1.1 nisimura u_int index = p->index, count = p->count;
774 1.1 nisimura
775 1.1 nisimura if (index >= CMAP_SIZE || (index + count) > CMAP_SIZE)
776 1.1 nisimura return (EINVAL);
777 1.1 nisimura
778 1.10 mrg if (!uvm_useracc(p->red, count, B_READ) ||
779 1.10 mrg !uvm_useracc(p->green, count, B_READ) ||
780 1.10 mrg !uvm_useracc(p->blue, count, B_READ))
781 1.1 nisimura return (EFAULT);
782 1.1 nisimura
783 1.1 nisimura copyin(p->red, &sc->sc_cmap.r[index], count);
784 1.1 nisimura copyin(p->green, &sc->sc_cmap.g[index], count);
785 1.1 nisimura copyin(p->blue, &sc->sc_cmap.b[index], count);
786 1.1 nisimura
787 1.1 nisimura sc->sc_changed |= DATA_CMAP_CHANGED;
788 1.1 nisimura
789 1.1 nisimura return (0);
790 1.1 nisimura }
791 1.1 nisimura
792 1.1 nisimura static int
793 1.1 nisimura set_cursor(sc, p)
794 1.1 nisimura struct tfb_softc *sc;
795 1.1 nisimura struct wsdisplay_cursor *p;
796 1.1 nisimura {
797 1.1 nisimura #define cc (&sc->sc_cursor)
798 1.4 nisimura int v, index, count, icount;
799 1.1 nisimura
800 1.1 nisimura v = p->which;
801 1.1 nisimura if (v & WSDISPLAY_CURSOR_DOCMAP) {
802 1.1 nisimura index = p->cmap.index;
803 1.1 nisimura count = p->cmap.count;
804 1.1 nisimura if (index >= 2 || (index + count) > 2)
805 1.1 nisimura return (EINVAL);
806 1.10 mrg if (!uvm_useracc(p->cmap.red, count, B_READ) ||
807 1.10 mrg !uvm_useracc(p->cmap.green, count, B_READ) ||
808 1.10 mrg !uvm_useracc(p->cmap.blue, count, B_READ))
809 1.1 nisimura return (EFAULT);
810 1.1 nisimura }
811 1.1 nisimura if (v & WSDISPLAY_CURSOR_DOSHAPE) {
812 1.1 nisimura if (p->size.x > CURSOR_MAX_SIZE || p->size.y > CURSOR_MAX_SIZE)
813 1.1 nisimura return (EINVAL);
814 1.4 nisimura icount = ((p->size.x < 33) ? 4 : 8) * p->size.y;
815 1.10 mrg if (!uvm_useracc(p->image, icount, B_READ) ||
816 1.10 mrg !uvm_useracc(p->mask, icount, B_READ))
817 1.1 nisimura return (EFAULT);
818 1.1 nisimura }
819 1.1 nisimura if (v & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOCUR)) {
820 1.1 nisimura if (v & WSDISPLAY_CURSOR_DOCUR)
821 1.1 nisimura cc->cc_hot = p->hot;
822 1.1 nisimura if (v & WSDISPLAY_CURSOR_DOPOS)
823 1.1 nisimura set_curpos(sc, &p->pos);
824 1.1 nisimura bt431_set_curpos(sc);
825 1.1 nisimura }
826 1.1 nisimura
827 1.1 nisimura sc->sc_changed = 0;
828 1.1 nisimura if (v & WSDISPLAY_CURSOR_DOCUR) {
829 1.1 nisimura sc->sc_curenb = p->enable;
830 1.1 nisimura sc->sc_changed |= DATA_ENB_CHANGED;
831 1.1 nisimura }
832 1.1 nisimura if (v & WSDISPLAY_CURSOR_DOCMAP) {
833 1.1 nisimura copyin(p->cmap.red, &cc->cc_color[index], count);
834 1.1 nisimura copyin(p->cmap.green, &cc->cc_color[index + 2], count);
835 1.1 nisimura copyin(p->cmap.blue, &cc->cc_color[index + 4], count);
836 1.1 nisimura sc->sc_changed |= DATA_CURCMAP_CHANGED;
837 1.1 nisimura }
838 1.1 nisimura if (v & WSDISPLAY_CURSOR_DOSHAPE) {
839 1.1 nisimura cc->cc_size = p->size;
840 1.1 nisimura memset(cc->cc_image, 0, sizeof cc->cc_image);
841 1.4 nisimura copyin(p->image, cc->cc_image, icount);
842 1.4 nisimura copyin(p->mask, cc->cc_image+CURSOR_MAX_SIZE, icount);
843 1.1 nisimura sc->sc_changed |= DATA_CURSHAPE_CHANGED;
844 1.1 nisimura }
845 1.1 nisimura
846 1.1 nisimura return (0);
847 1.1 nisimura #undef cc
848 1.1 nisimura }
849 1.1 nisimura
850 1.1 nisimura static int
851 1.1 nisimura get_cursor(sc, p)
852 1.1 nisimura struct tfb_softc *sc;
853 1.1 nisimura struct wsdisplay_cursor *p;
854 1.1 nisimura {
855 1.1 nisimura return (ENOTTY); /* XXX */
856 1.1 nisimura }
857 1.1 nisimura
858 1.1 nisimura static void
859 1.1 nisimura set_curpos(sc, curpos)
860 1.1 nisimura struct tfb_softc *sc;
861 1.1 nisimura struct wsdisplay_curpos *curpos;
862 1.1 nisimura {
863 1.1 nisimura struct fb_devconfig *dc = sc->sc_dc;
864 1.1 nisimura int x = curpos->x, y = curpos->y;
865 1.1 nisimura
866 1.1 nisimura if (y < 0)
867 1.1 nisimura y = 0;
868 1.3 nisimura else if (y > dc->dc_ht)
869 1.3 nisimura y = dc->dc_ht;
870 1.1 nisimura if (x < 0)
871 1.1 nisimura x = 0;
872 1.3 nisimura else if (x > dc->dc_wid)
873 1.3 nisimura x = dc->dc_wid;
874 1.1 nisimura sc->sc_cursor.cc_pos.x = x;
875 1.1 nisimura sc->sc_cursor.cc_pos.y = y;
876 1.1 nisimura }
877 1.1 nisimura
878 1.11.4.2 thorpej void
879 1.1 nisimura bt431_set_curpos(sc)
880 1.1 nisimura struct tfb_softc *sc;
881 1.1 nisimura {
882 1.1 nisimura caddr_t tfbbase = (caddr_t)sc->sc_dc->dc_vaddr;
883 1.11.4.2 thorpej void *curs = (void *)(tfbbase + TX_BT431_OFFSET);
884 1.1 nisimura u_int16_t twin;
885 1.3 nisimura int x, y, s;
886 1.1 nisimura
887 1.3 nisimura x = sc->sc_cursor.cc_pos.x - sc->sc_cursor.cc_hot.x;
888 1.3 nisimura y = sc->sc_cursor.cc_pos.y - sc->sc_cursor.cc_hot.y;
889 1.11.4.1 thorpej
890 1.11.4.1 thorpej x += sc->sc_cursor.cc_magic.x;
891 1.11.4.1 thorpej y += sc->sc_cursor.cc_magic.y;
892 1.1 nisimura
893 1.1 nisimura s = spltty();
894 1.1 nisimura
895 1.11.4.2 thorpej SELECT431(curs, BT431_REG_CURSOR_X_LOW);
896 1.11.4.2 thorpej HALF(curs, bt_ctl) = TWIN_LO(x); tc_wmb();
897 1.11.4.2 thorpej HALF(curs, bt_ctl) = TWIN_HI(x); tc_wmb();
898 1.11.4.2 thorpej HALF(curs, bt_ctl) = TWIN_LO(y); tc_wmb();
899 1.11.4.2 thorpej HALF(curs, bt_ctl) = TWIN_HI(y); tc_wmb();
900 1.1 nisimura
901 1.1 nisimura splx(s);
902 1.1 nisimura }
903