tga.c revision 1.16 1 1.16 drochner /* $NetBSD: tga.c,v 1.16 2000/01/25 22:30:05 drochner Exp $ */
2 1.1 drochner
3 1.1 drochner /*
4 1.1 drochner * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 1.1 drochner * All rights reserved.
6 1.1 drochner *
7 1.1 drochner * Author: Chris G. Demetriou
8 1.1 drochner *
9 1.1 drochner * Permission to use, copy, modify and distribute this software and
10 1.1 drochner * its documentation is hereby granted, provided that both the copyright
11 1.1 drochner * notice and this permission notice appear in all copies of the
12 1.1 drochner * software, derivative works or modified versions, and any portions
13 1.1 drochner * thereof, and that both notices appear in supporting documentation.
14 1.1 drochner *
15 1.1 drochner * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 1.1 drochner * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 1.1 drochner * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 1.1 drochner *
19 1.1 drochner * Carnegie Mellon requests users of this software to return to
20 1.1 drochner *
21 1.1 drochner * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 1.1 drochner * School of Computer Science
23 1.1 drochner * Carnegie Mellon University
24 1.1 drochner * Pittsburgh PA 15213-3890
25 1.1 drochner *
26 1.1 drochner * any improvements or extensions that they make and grant Carnegie the
27 1.1 drochner * rights to redistribute these changes.
28 1.1 drochner */
29 1.1 drochner
30 1.1 drochner #include <sys/param.h>
31 1.1 drochner #include <sys/systm.h>
32 1.1 drochner #include <sys/kernel.h>
33 1.1 drochner #include <sys/device.h>
34 1.1 drochner #include <sys/conf.h>
35 1.1 drochner #include <sys/malloc.h>
36 1.1 drochner #include <sys/buf.h>
37 1.1 drochner #include <sys/ioctl.h>
38 1.1 drochner
39 1.8 thorpej #include <vm/vm.h>
40 1.8 thorpej
41 1.1 drochner #include <machine/bus.h>
42 1.1 drochner #include <machine/intr.h>
43 1.1 drochner
44 1.1 drochner #include <dev/pci/pcireg.h>
45 1.1 drochner #include <dev/pci/pcivar.h>
46 1.1 drochner #include <dev/pci/pcidevs.h>
47 1.1 drochner #include <dev/pci/tgareg.h>
48 1.1 drochner #include <dev/pci/tgavar.h>
49 1.1 drochner #include <dev/ic/bt485reg.h>
50 1.1 drochner
51 1.1 drochner #include <dev/rcons/raster.h>
52 1.1 drochner #include <dev/wscons/wsconsio.h>
53 1.1 drochner #include <dev/wscons/wscons_raster.h>
54 1.1 drochner #include <dev/wscons/wsdisplayvar.h>
55 1.1 drochner
56 1.1 drochner #ifdef __alpha__
57 1.1 drochner #include <machine/pte.h>
58 1.1 drochner #endif
59 1.1 drochner
60 1.1 drochner int tgamatch __P((struct device *, struct cfdata *, void *));
61 1.1 drochner void tgaattach __P((struct device *, struct device *, void *));
62 1.1 drochner int tgaprint __P((void *, const char *));
63 1.1 drochner
64 1.1 drochner struct cfattach tga_ca = {
65 1.1 drochner sizeof(struct tga_softc), tgamatch, tgaattach,
66 1.1 drochner };
67 1.1 drochner
68 1.1 drochner int tga_identify __P((tga_reg_t *));
69 1.1 drochner const struct tga_conf *tga_getconf __P((int));
70 1.1 drochner void tga_getdevconfig __P((bus_space_tag_t memt, pci_chipset_tag_t pc,
71 1.1 drochner pcitag_t tag, struct tga_devconfig *dc));
72 1.1 drochner
73 1.1 drochner struct tga_devconfig tga_console_dc;
74 1.1 drochner
75 1.14 ross int tga_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
76 1.14 ross int tga_mmap __P((void *, off_t, int));
77 1.14 ross static void tga_copyrows __P((void *, int, int, int));
78 1.14 ross static void tga_copycols __P((void *, int, int, int, int));
79 1.14 ross static int tga_alloc_screen __P((void *, const struct wsscreen_descr *,
80 1.14 ross void **, int *, int *, long *));
81 1.14 ross static void tga_free_screen __P((void *, void *));
82 1.15 drochner static int tga_show_screen __P((void *, void *, int,
83 1.15 drochner void (*) (void *, int, int), void *));
84 1.14 ross static int tga_rop __P((struct raster *, int, int, int, int, int,
85 1.14 ross struct raster *, int, int));
86 1.14 ross static int tga_rop_nosrc __P((struct raster *, int, int, int, int, int));
87 1.14 ross static int tga_rop_htov __P((struct raster *, int, int, int, int,
88 1.14 ross int, struct raster *, int, int ));
89 1.14 ross static int tga_rop_vtov __P((struct raster *, int, int, int, int,
90 1.14 ross int, struct raster *, int, int ));
91 1.14 ross
92 1.1 drochner struct wsdisplay_emulops tga_emulops = {
93 1.1 drochner rcons_cursor, /* could use hardware cursor; punt */
94 1.6 drochner rcons_mapchar,
95 1.5 drochner rcons_putchar,
96 1.14 ross tga_copycols,
97 1.1 drochner rcons_erasecols,
98 1.14 ross tga_copyrows,
99 1.1 drochner rcons_eraserows,
100 1.4 drochner rcons_alloc_attr
101 1.1 drochner };
102 1.1 drochner
103 1.1 drochner struct wsscreen_descr tga_stdscreen = {
104 1.1 drochner "std",
105 1.4 drochner 0, 0, /* will be filled in -- XXX shouldn't, it's global */
106 1.1 drochner &tga_emulops,
107 1.4 drochner 0, 0,
108 1.4 drochner WSSCREEN_REVERSE
109 1.1 drochner };
110 1.1 drochner
111 1.1 drochner const struct wsscreen_descr *_tga_scrlist[] = {
112 1.1 drochner &tga_stdscreen,
113 1.1 drochner /* XXX other formats, graphics screen? */
114 1.1 drochner };
115 1.1 drochner
116 1.1 drochner struct wsscreen_list tga_screenlist = {
117 1.1 drochner sizeof(_tga_scrlist) / sizeof(struct wsscreen_descr *), _tga_scrlist
118 1.1 drochner };
119 1.1 drochner
120 1.1 drochner struct wsdisplay_accessops tga_accessops = {
121 1.1 drochner tga_ioctl,
122 1.1 drochner tga_mmap,
123 1.1 drochner tga_alloc_screen,
124 1.1 drochner tga_free_screen,
125 1.1 drochner tga_show_screen,
126 1.11 drochner 0 /* load_font */
127 1.1 drochner };
128 1.1 drochner
129 1.1 drochner void tga_blank __P((struct tga_devconfig *));
130 1.1 drochner void tga_unblank __P((struct tga_devconfig *));
131 1.1 drochner
132 1.1 drochner int
133 1.1 drochner tgamatch(parent, match, aux)
134 1.1 drochner struct device *parent;
135 1.1 drochner struct cfdata *match;
136 1.1 drochner void *aux;
137 1.1 drochner {
138 1.1 drochner struct pci_attach_args *pa = aux;
139 1.1 drochner
140 1.1 drochner if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_DEC ||
141 1.1 drochner PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_DEC_21030)
142 1.1 drochner return (0);
143 1.1 drochner
144 1.1 drochner return (10);
145 1.1 drochner }
146 1.1 drochner
147 1.1 drochner void
148 1.1 drochner tga_getdevconfig(memt, pc, tag, dc)
149 1.1 drochner bus_space_tag_t memt;
150 1.1 drochner pci_chipset_tag_t pc;
151 1.1 drochner pcitag_t tag;
152 1.1 drochner struct tga_devconfig *dc;
153 1.1 drochner {
154 1.1 drochner const struct tga_conf *tgac;
155 1.1 drochner const struct tga_ramdac_conf *tgar;
156 1.1 drochner struct raster *rap;
157 1.1 drochner struct rcons *rcp;
158 1.1 drochner bus_size_t pcisize;
159 1.1 drochner int i, flags;
160 1.1 drochner
161 1.1 drochner dc->dc_memt = memt;
162 1.1 drochner dc->dc_pc = pc;
163 1.1 drochner
164 1.1 drochner dc->dc_pcitag = tag;
165 1.1 drochner
166 1.1 drochner /* XXX magic number */
167 1.1 drochner if (pci_mapreg_info(pc, tag, 0x10,
168 1.1 drochner PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
169 1.1 drochner &dc->dc_pcipaddr, &pcisize, &flags))
170 1.1 drochner return;
171 1.16 drochner if ((flags & BUS_SPACE_MAP_PREFETCHABLE) == 0) /* XXX */
172 1.16 drochner panic("tga memory not prefetchable");
173 1.1 drochner
174 1.1 drochner if (bus_space_map(memt, dc->dc_pcipaddr, pcisize,
175 1.16 drochner BUS_SPACE_MAP_PREFETCHABLE | BUS_SPACE_MAP_LINEAR, &dc->dc_vaddr))
176 1.1 drochner return;
177 1.1 drochner #ifdef __alpha__
178 1.1 drochner dc->dc_paddr = ALPHA_K0SEG_TO_PHYS(dc->dc_vaddr); /* XXX */
179 1.1 drochner #endif
180 1.1 drochner
181 1.1 drochner dc->dc_regs = (tga_reg_t *)(dc->dc_vaddr + TGA_MEM_CREGS);
182 1.1 drochner dc->dc_tga_type = tga_identify(dc->dc_regs);
183 1.1 drochner tgac = dc->dc_tgaconf = tga_getconf(dc->dc_tga_type);
184 1.1 drochner if (tgac == NULL)
185 1.1 drochner return;
186 1.1 drochner
187 1.1 drochner #if 0
188 1.1 drochner /* XXX on the Alpha, pcisize = 4 * cspace_size. */
189 1.1 drochner if (tgac->tgac_cspace_size != pcisize) /* sanity */
190 1.1 drochner panic("tga_getdevconfig: memory size mismatch?");
191 1.1 drochner #endif
192 1.1 drochner
193 1.1 drochner tgar = tgac->tgac_ramdac;
194 1.1 drochner
195 1.1 drochner switch (dc->dc_regs[TGA_REG_VHCR] & 0x1ff) { /* XXX */
196 1.1 drochner case 0:
197 1.1 drochner dc->dc_wid = 8192;
198 1.1 drochner break;
199 1.1 drochner
200 1.1 drochner case 1:
201 1.1 drochner dc->dc_wid = 8196;
202 1.1 drochner break;
203 1.1 drochner
204 1.1 drochner default:
205 1.1 drochner dc->dc_wid = (dc->dc_regs[TGA_REG_VHCR] & 0x1ff) * 4; /* XXX */
206 1.1 drochner break;
207 1.1 drochner }
208 1.1 drochner
209 1.1 drochner dc->dc_rowbytes = dc->dc_wid * (dc->dc_tgaconf->tgac_phys_depth / 8);
210 1.1 drochner
211 1.1 drochner if ((dc->dc_regs[TGA_REG_VHCR] & 0x00000001) != 0 && /* XXX */
212 1.1 drochner (dc->dc_regs[TGA_REG_VHCR] & 0x80000000) != 0) { /* XXX */
213 1.1 drochner dc->dc_wid -= 4;
214 1.1 drochner /*
215 1.1 drochner * XXX XXX turning off 'odd' shouldn't be necesssary,
216 1.1 drochner * XXX XXX but i can't make X work with the weird size.
217 1.1 drochner */
218 1.1 drochner dc->dc_regs[TGA_REG_VHCR] &= ~0x80000001;
219 1.1 drochner dc->dc_rowbytes =
220 1.1 drochner dc->dc_wid * (dc->dc_tgaconf->tgac_phys_depth / 8);
221 1.1 drochner }
222 1.1 drochner
223 1.1 drochner dc->dc_ht = (dc->dc_regs[TGA_REG_VVCR] & 0x7ff); /* XXX */
224 1.1 drochner
225 1.1 drochner /* XXX this seems to be what DEC does */
226 1.1 drochner dc->dc_regs[TGA_REG_CCBR] = 0;
227 1.1 drochner dc->dc_regs[TGA_REG_VVBR] = 1;
228 1.1 drochner dc->dc_videobase = dc->dc_vaddr + tgac->tgac_dbuf[0] +
229 1.1 drochner 1 * tgac->tgac_vvbr_units;
230 1.1 drochner dc->dc_blanked = 1;
231 1.1 drochner tga_unblank(dc);
232 1.1 drochner
233 1.1 drochner /*
234 1.1 drochner * Set all bits in the pixel mask, to enable writes to all pixels.
235 1.1 drochner * It seems that the console firmware clears some of them
236 1.1 drochner * under some circumstances, which causes cute vertical stripes.
237 1.1 drochner */
238 1.1 drochner dc->dc_regs[TGA_REG_GPXR_P] = 0xffffffff;
239 1.1 drochner
240 1.1 drochner /* clear the screen */
241 1.1 drochner for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
242 1.1 drochner *(u_int32_t *)(dc->dc_videobase + i) = 0;
243 1.1 drochner
244 1.1 drochner /* initialize the raster */
245 1.1 drochner rap = &dc->dc_raster;
246 1.1 drochner rap->width = dc->dc_wid;
247 1.1 drochner rap->height = dc->dc_ht;
248 1.1 drochner rap->depth = tgac->tgac_phys_depth;
249 1.1 drochner rap->linelongs = dc->dc_rowbytes / sizeof(u_int32_t);
250 1.1 drochner rap->pixels = (u_int32_t *)dc->dc_videobase;
251 1.14 ross rap->data = (caddr_t)dc;
252 1.1 drochner
253 1.1 drochner /* initialize the raster console blitter */
254 1.1 drochner rcp = &dc->dc_rcons;
255 1.1 drochner rcp->rc_sp = rap;
256 1.1 drochner rcp->rc_crow = rcp->rc_ccol = -1;
257 1.1 drochner rcp->rc_crowp = &rcp->rc_crow;
258 1.1 drochner rcp->rc_ccolp = &rcp->rc_ccol;
259 1.1 drochner rcons_init(rcp, 34, 80);
260 1.1 drochner
261 1.1 drochner tga_stdscreen.nrows = dc->dc_rcons.rc_maxrow;
262 1.1 drochner tga_stdscreen.ncols = dc->dc_rcons.rc_maxcol;
263 1.1 drochner }
264 1.1 drochner
265 1.1 drochner void
266 1.1 drochner tgaattach(parent, self, aux)
267 1.1 drochner struct device *parent, *self;
268 1.1 drochner void *aux;
269 1.1 drochner {
270 1.1 drochner struct pci_attach_args *pa = aux;
271 1.1 drochner struct tga_softc *sc = (struct tga_softc *)self;
272 1.1 drochner struct wsemuldisplaydev_attach_args aa;
273 1.1 drochner pci_intr_handle_t intrh;
274 1.1 drochner const char *intrstr;
275 1.1 drochner u_int8_t rev;
276 1.1 drochner int console;
277 1.1 drochner
278 1.1 drochner #ifdef __alpha__
279 1.1 drochner console = (pa->pa_tag == tga_console_dc.dc_pcitag);
280 1.1 drochner #else
281 1.1 drochner console = 0;
282 1.1 drochner #endif
283 1.1 drochner if (console) {
284 1.1 drochner sc->sc_dc = &tga_console_dc;
285 1.1 drochner sc->nscreens = 1;
286 1.1 drochner } else {
287 1.1 drochner sc->sc_dc = (struct tga_devconfig *)
288 1.1 drochner malloc(sizeof(struct tga_devconfig), M_DEVBUF, M_WAITOK);
289 1.9 drochner bzero(sc->sc_dc, sizeof(struct tga_devconfig));
290 1.1 drochner tga_getdevconfig(pa->pa_memt, pa->pa_pc, pa->pa_tag, sc->sc_dc);
291 1.1 drochner }
292 1.1 drochner if (sc->sc_dc->dc_vaddr == NULL) {
293 1.1 drochner printf(": couldn't map memory space; punt!\n");
294 1.1 drochner return;
295 1.1 drochner }
296 1.1 drochner
297 1.1 drochner /* XXX say what's going on. */
298 1.1 drochner intrstr = NULL;
299 1.1 drochner if (sc->sc_dc->dc_tgaconf->tgac_ramdac->tgar_intr != NULL) {
300 1.1 drochner if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
301 1.1 drochner pa->pa_intrline, &intrh)) {
302 1.1 drochner printf(": couldn't map interrupt");
303 1.1 drochner return;
304 1.1 drochner }
305 1.1 drochner intrstr = pci_intr_string(pa->pa_pc, intrh);
306 1.1 drochner sc->sc_intr = pci_intr_establish(pa->pa_pc, intrh, IPL_TTY,
307 1.1 drochner sc->sc_dc->dc_tgaconf->tgac_ramdac->tgar_intr, sc->sc_dc);
308 1.1 drochner if (sc->sc_intr == NULL) {
309 1.1 drochner printf(": couldn't establish interrupt");
310 1.1 drochner if (intrstr != NULL)
311 1.1 drochner printf("at %s", intrstr);
312 1.1 drochner printf("\n");
313 1.1 drochner return;
314 1.1 drochner }
315 1.1 drochner }
316 1.1 drochner
317 1.1 drochner /*
318 1.1 drochner * Initialize the RAMDAC and allocate any private storage it needs.
319 1.1 drochner * Initialization includes disabling cursor, setting a sane
320 1.1 drochner * colormap, etc.
321 1.1 drochner */
322 1.1 drochner (*sc->sc_dc->dc_tgaconf->tgac_ramdac->tgar_init)(sc->sc_dc, 1);
323 1.1 drochner
324 1.1 drochner printf(": DC21030 ");
325 1.1 drochner rev = PCI_REVISION(pa->pa_class);
326 1.1 drochner switch (rev) {
327 1.1 drochner case 1: case 2: case 3:
328 1.1 drochner printf("step %c", 'A' + rev - 1);
329 1.1 drochner break;
330 1.1 drochner
331 1.1 drochner default:
332 1.1 drochner printf("unknown stepping (0x%x)", rev);
333 1.1 drochner break;
334 1.1 drochner }
335 1.1 drochner printf(", ");
336 1.1 drochner
337 1.1 drochner if (sc->sc_dc->dc_tgaconf == NULL) {
338 1.1 drochner printf("unknown board configuration\n");
339 1.1 drochner return;
340 1.1 drochner }
341 1.1 drochner printf("board type %s\n", sc->sc_dc->dc_tgaconf->tgac_name);
342 1.1 drochner printf("%s: %d x %d, %dbpp, %s RAMDAC\n", sc->sc_dev.dv_xname,
343 1.1 drochner sc->sc_dc->dc_wid, sc->sc_dc->dc_ht,
344 1.1 drochner sc->sc_dc->dc_tgaconf->tgac_phys_depth,
345 1.1 drochner sc->sc_dc->dc_tgaconf->tgac_ramdac->tgar_name);
346 1.1 drochner
347 1.1 drochner if (intrstr != NULL)
348 1.1 drochner printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
349 1.1 drochner intrstr);
350 1.1 drochner
351 1.1 drochner aa.console = console;
352 1.1 drochner aa.scrdata = &tga_screenlist;
353 1.1 drochner aa.accessops = &tga_accessops;
354 1.1 drochner aa.accesscookie = sc;
355 1.1 drochner
356 1.1 drochner config_found(self, &aa, wsemuldisplaydevprint);
357 1.1 drochner }
358 1.1 drochner
359 1.1 drochner int
360 1.1 drochner tga_ioctl(v, cmd, data, flag, p)
361 1.1 drochner void *v;
362 1.1 drochner u_long cmd;
363 1.1 drochner caddr_t data;
364 1.1 drochner int flag;
365 1.1 drochner struct proc *p;
366 1.1 drochner {
367 1.1 drochner struct tga_softc *sc = v;
368 1.1 drochner struct tga_devconfig *dc = sc->sc_dc;
369 1.1 drochner const struct tga_ramdac_conf *tgar = dc->dc_tgaconf->tgac_ramdac;
370 1.1 drochner
371 1.1 drochner switch (cmd) {
372 1.1 drochner case WSDISPLAYIO_GTYPE:
373 1.1 drochner *(u_int *)data = WSDISPLAY_TYPE_TGA;
374 1.1 drochner return (0);
375 1.1 drochner
376 1.1 drochner case WSDISPLAYIO_GINFO:
377 1.1 drochner #define wsd_fbip ((struct wsdisplay_fbinfo *)data)
378 1.1 drochner wsd_fbip->height = sc->sc_dc->dc_ht;
379 1.1 drochner wsd_fbip->width = sc->sc_dc->dc_wid;
380 1.1 drochner wsd_fbip->depth = sc->sc_dc->dc_tgaconf->tgac_phys_depth;
381 1.1 drochner wsd_fbip->cmsize = 256; /* XXX ??? */
382 1.12 thorpej #undef wsd_fbip
383 1.1 drochner return (0);
384 1.1 drochner
385 1.1 drochner case WSDISPLAYIO_GETCMAP:
386 1.1 drochner return (*tgar->tgar_get_cmap)(dc,
387 1.1 drochner (struct wsdisplay_cmap *)data);
388 1.1 drochner
389 1.1 drochner case WSDISPLAYIO_PUTCMAP:
390 1.1 drochner return (*tgar->tgar_set_cmap)(dc,
391 1.1 drochner (struct wsdisplay_cmap *)data);
392 1.1 drochner
393 1.12 thorpej case WSDISPLAYIO_SVIDEO:
394 1.1 drochner if (*(u_int *)data == WSDISPLAYIO_VIDEO_OFF)
395 1.1 drochner tga_blank(sc->sc_dc);
396 1.1 drochner else
397 1.1 drochner tga_unblank(sc->sc_dc);
398 1.1 drochner return (0);
399 1.1 drochner
400 1.12 thorpej case WSDISPLAYIO_GVIDEO:
401 1.1 drochner *(u_int *)data = dc->dc_blanked ?
402 1.1 drochner WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
403 1.1 drochner return (0);
404 1.1 drochner
405 1.1 drochner case WSDISPLAYIO_GCURPOS:
406 1.1 drochner return (*tgar->tgar_get_curpos)(dc,
407 1.1 drochner (struct wsdisplay_curpos *)data);
408 1.1 drochner
409 1.1 drochner case WSDISPLAYIO_SCURPOS:
410 1.1 drochner return (*tgar->tgar_set_curpos)(dc,
411 1.1 drochner (struct wsdisplay_curpos *)data);
412 1.1 drochner
413 1.1 drochner case WSDISPLAYIO_GCURMAX:
414 1.1 drochner return (*tgar->tgar_get_curmax)(dc,
415 1.1 drochner (struct wsdisplay_curpos *)data);
416 1.1 drochner
417 1.1 drochner case WSDISPLAYIO_GCURSOR:
418 1.1 drochner return (*tgar->tgar_get_cursor)(dc,
419 1.1 drochner (struct wsdisplay_cursor *)data);
420 1.1 drochner
421 1.1 drochner case WSDISPLAYIO_SCURSOR:
422 1.1 drochner return (*tgar->tgar_set_cursor)(dc,
423 1.1 drochner (struct wsdisplay_cursor *)data);
424 1.1 drochner }
425 1.1 drochner return (-1);
426 1.1 drochner }
427 1.1 drochner
428 1.1 drochner int
429 1.1 drochner tga_mmap(v, offset, prot)
430 1.1 drochner void *v;
431 1.1 drochner off_t offset;
432 1.1 drochner int prot;
433 1.1 drochner {
434 1.1 drochner
435 1.1 drochner /* XXX NEW MAPPING CODE... */
436 1.1 drochner
437 1.1 drochner #ifdef __alpha__
438 1.1 drochner struct tga_softc *sc = v;
439 1.1 drochner
440 1.10 mrg if (offset >= sc->sc_dc->dc_tgaconf->tgac_cspace_size || offset < 0)
441 1.1 drochner return -1;
442 1.1 drochner return alpha_btop(sc->sc_dc->dc_paddr + offset);
443 1.1 drochner #else
444 1.1 drochner return (-1);
445 1.1 drochner #endif
446 1.1 drochner }
447 1.1 drochner
448 1.1 drochner int
449 1.4 drochner tga_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
450 1.1 drochner void *v;
451 1.1 drochner const struct wsscreen_descr *type;
452 1.1 drochner void **cookiep;
453 1.1 drochner int *curxp, *curyp;
454 1.4 drochner long *attrp;
455 1.1 drochner {
456 1.1 drochner struct tga_softc *sc = v;
457 1.4 drochner long defattr;
458 1.1 drochner
459 1.1 drochner if (sc->nscreens > 0)
460 1.1 drochner return (ENOMEM);
461 1.1 drochner
462 1.1 drochner *cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */
463 1.1 drochner *curxp = 0;
464 1.1 drochner *curyp = 0;
465 1.4 drochner rcons_alloc_attr(&sc->sc_dc->dc_rcons, 0, 0, 0, &defattr);
466 1.4 drochner *attrp = defattr;
467 1.2 drochner sc->nscreens++;
468 1.1 drochner return (0);
469 1.1 drochner }
470 1.1 drochner
471 1.1 drochner void
472 1.1 drochner tga_free_screen(v, cookie)
473 1.1 drochner void *v;
474 1.1 drochner void *cookie;
475 1.1 drochner {
476 1.1 drochner struct tga_softc *sc = v;
477 1.1 drochner
478 1.1 drochner if (sc->sc_dc == &tga_console_dc)
479 1.1 drochner panic("tga_free_screen: console");
480 1.1 drochner
481 1.1 drochner sc->nscreens--;
482 1.1 drochner }
483 1.1 drochner
484 1.15 drochner int
485 1.15 drochner tga_show_screen(v, cookie, waitok, cb, cbarg)
486 1.1 drochner void *v;
487 1.1 drochner void *cookie;
488 1.15 drochner int waitok;
489 1.15 drochner void (*cb) __P((void *, int, int));
490 1.15 drochner void *cbarg;
491 1.1 drochner {
492 1.15 drochner
493 1.15 drochner return (0);
494 1.1 drochner }
495 1.1 drochner
496 1.1 drochner int
497 1.1 drochner tga_cnattach(iot, memt, pc, bus, device, function)
498 1.1 drochner bus_space_tag_t iot, memt;
499 1.1 drochner pci_chipset_tag_t pc;
500 1.1 drochner int bus, device, function;
501 1.1 drochner {
502 1.1 drochner struct tga_devconfig *dcp = &tga_console_dc;
503 1.4 drochner long defattr;
504 1.1 drochner
505 1.1 drochner tga_getdevconfig(memt, pc,
506 1.1 drochner pci_make_tag(pc, bus, device, function), dcp);
507 1.1 drochner
508 1.1 drochner /* sanity checks */
509 1.1 drochner if (dcp->dc_vaddr == NULL)
510 1.1 drochner panic("tga_console(%d, %d): couldn't map memory space",
511 1.1 drochner device, function);
512 1.1 drochner if (dcp->dc_tgaconf == NULL)
513 1.1 drochner panic("tga_console(%d, %d): unknown board configuration",
514 1.1 drochner device, function);
515 1.1 drochner
516 1.1 drochner /*
517 1.1 drochner * Initialize the RAMDAC but DO NOT allocate any private storage.
518 1.1 drochner * Initialization includes disabling cursor, setting a sane
519 1.1 drochner * colormap, etc. It will be reinitialized in tgaattach().
520 1.1 drochner */
521 1.1 drochner (*dcp->dc_tgaconf->tgac_ramdac->tgar_init)(dcp, 0);
522 1.1 drochner
523 1.4 drochner rcons_alloc_attr(&dcp->dc_rcons, 0, 0, 0, &defattr);
524 1.4 drochner
525 1.1 drochner wsdisplay_cnattach(&tga_stdscreen, &dcp->dc_rcons,
526 1.4 drochner 0, 0, defattr);
527 1.1 drochner
528 1.1 drochner return(0);
529 1.1 drochner }
530 1.1 drochner
531 1.1 drochner /*
532 1.1 drochner * Functions to blank and unblank the display.
533 1.1 drochner */
534 1.1 drochner void
535 1.1 drochner tga_blank(dc)
536 1.1 drochner struct tga_devconfig *dc;
537 1.1 drochner {
538 1.1 drochner
539 1.1 drochner if (!dc->dc_blanked) {
540 1.1 drochner dc->dc_blanked = 1;
541 1.3 thorpej dc->dc_regs[TGA_REG_VVVR] |= VVR_BLANK; /* XXX */
542 1.1 drochner }
543 1.1 drochner }
544 1.1 drochner
545 1.1 drochner void
546 1.1 drochner tga_unblank(dc)
547 1.1 drochner struct tga_devconfig *dc;
548 1.1 drochner {
549 1.1 drochner
550 1.1 drochner if (dc->dc_blanked) {
551 1.1 drochner dc->dc_blanked = 0;
552 1.3 thorpej dc->dc_regs[TGA_REG_VVVR] &= ~VVR_BLANK; /* XXX */
553 1.1 drochner }
554 1.1 drochner }
555 1.1 drochner
556 1.1 drochner /*
557 1.1 drochner * Functions to manipulate the built-in cursor handing hardware.
558 1.1 drochner */
559 1.1 drochner int
560 1.1 drochner tga_builtin_set_cursor(dc, cursorp)
561 1.1 drochner struct tga_devconfig *dc;
562 1.1 drochner struct wsdisplay_cursor *cursorp;
563 1.1 drochner {
564 1.8 thorpej int count, error, v;
565 1.1 drochner
566 1.1 drochner v = cursorp->which;
567 1.8 thorpej if (v & WSDISPLAY_CURSOR_DOCMAP) {
568 1.8 thorpej error = (*dc->dc_tgaconf->tgac_ramdac->tgar_check_curcmap)(dc,
569 1.8 thorpej cursorp);
570 1.8 thorpej if (error)
571 1.8 thorpej return (error);
572 1.8 thorpej }
573 1.1 drochner if (v & WSDISPLAY_CURSOR_DOSHAPE) {
574 1.1 drochner if ((u_int)cursorp->size.x != 64 ||
575 1.1 drochner (u_int)cursorp->size.y > 64)
576 1.1 drochner return (EINVAL);
577 1.1 drochner /* The cursor is 2 bits deep, and there is no mask */
578 1.1 drochner count = (cursorp->size.y * 64 * 2) / NBBY;
579 1.8 thorpej if (!uvm_useracc(cursorp->image, count, B_READ))
580 1.8 thorpej return (EFAULT);
581 1.1 drochner }
582 1.1 drochner if (v & WSDISPLAY_CURSOR_DOHOT) /* not supported */
583 1.1 drochner return EINVAL;
584 1.1 drochner
585 1.1 drochner /* parameters are OK; do it */
586 1.1 drochner if (v & WSDISPLAY_CURSOR_DOCUR) {
587 1.1 drochner if (cursorp->enable)
588 1.1 drochner dc->dc_regs[TGA_REG_VVVR] |= 0x04; /* XXX */
589 1.1 drochner else
590 1.1 drochner dc->dc_regs[TGA_REG_VVVR] &= ~0x04; /* XXX */
591 1.1 drochner }
592 1.1 drochner if (v & WSDISPLAY_CURSOR_DOPOS) {
593 1.1 drochner dc->dc_regs[TGA_REG_CXYR] = ((cursorp->pos.y & 0xfff) << 12) |
594 1.1 drochner (cursorp->pos.x & 0xfff);
595 1.1 drochner }
596 1.1 drochner if (v & WSDISPLAY_CURSOR_DOCMAP) {
597 1.8 thorpej /* can't fail. */
598 1.8 thorpej (*dc->dc_tgaconf->tgac_ramdac->tgar_set_curcmap)(dc, cursorp);
599 1.1 drochner }
600 1.1 drochner if (v & WSDISPLAY_CURSOR_DOSHAPE) {
601 1.8 thorpej count = ((64 * 2) / NBBY) * cursorp->size.y;
602 1.1 drochner dc->dc_regs[TGA_REG_CCBR] =
603 1.1 drochner (dc->dc_regs[TGA_REG_CCBR] & ~0xfc00) |
604 1.1 drochner (cursorp->size.y << 10);
605 1.1 drochner copyin(cursorp->image, (char *)(dc->dc_vaddr +
606 1.1 drochner (dc->dc_regs[TGA_REG_CCBR] & 0x3ff)),
607 1.1 drochner count); /* can't fail. */
608 1.1 drochner }
609 1.1 drochner return (0);
610 1.1 drochner }
611 1.1 drochner
612 1.1 drochner int
613 1.1 drochner tga_builtin_get_cursor(dc, cursorp)
614 1.1 drochner struct tga_devconfig *dc;
615 1.1 drochner struct wsdisplay_cursor *cursorp;
616 1.1 drochner {
617 1.1 drochner int count, error;
618 1.1 drochner
619 1.1 drochner cursorp->which = WSDISPLAY_CURSOR_DOALL &
620 1.1 drochner ~(WSDISPLAY_CURSOR_DOHOT | WSDISPLAY_CURSOR_DOCMAP);
621 1.1 drochner cursorp->enable = (dc->dc_regs[TGA_REG_VVVR] & 0x04) != 0;
622 1.1 drochner cursorp->pos.x = dc->dc_regs[TGA_REG_CXYR] & 0xfff;
623 1.1 drochner cursorp->pos.y = (dc->dc_regs[TGA_REG_CXYR] >> 12) & 0xfff;
624 1.1 drochner cursorp->size.x = 64;
625 1.1 drochner cursorp->size.y = (dc->dc_regs[TGA_REG_CCBR] >> 10) & 0x3f;
626 1.1 drochner
627 1.1 drochner if (cursorp->image != NULL) {
628 1.1 drochner count = (cursorp->size.y * 64 * 2) / NBBY;
629 1.1 drochner error = copyout((char *)(dc->dc_vaddr +
630 1.1 drochner (dc->dc_regs[TGA_REG_CCBR] & 0x3ff)),
631 1.1 drochner cursorp->image, count);
632 1.1 drochner if (error)
633 1.1 drochner return (error);
634 1.1 drochner /* No mask */
635 1.1 drochner }
636 1.8 thorpej error = (*dc->dc_tgaconf->tgac_ramdac->tgar_get_curcmap)(dc, cursorp);
637 1.8 thorpej return (error);
638 1.1 drochner }
639 1.1 drochner
640 1.1 drochner int
641 1.1 drochner tga_builtin_set_curpos(dc, curposp)
642 1.1 drochner struct tga_devconfig *dc;
643 1.1 drochner struct wsdisplay_curpos *curposp;
644 1.1 drochner {
645 1.1 drochner
646 1.1 drochner dc->dc_regs[TGA_REG_CXYR] =
647 1.1 drochner ((curposp->y & 0xfff) << 12) | (curposp->x & 0xfff);
648 1.1 drochner return (0);
649 1.1 drochner }
650 1.1 drochner
651 1.1 drochner int
652 1.1 drochner tga_builtin_get_curpos(dc, curposp)
653 1.1 drochner struct tga_devconfig *dc;
654 1.1 drochner struct wsdisplay_curpos *curposp;
655 1.1 drochner {
656 1.1 drochner
657 1.1 drochner curposp->x = dc->dc_regs[TGA_REG_CXYR] & 0xfff;
658 1.1 drochner curposp->y = (dc->dc_regs[TGA_REG_CXYR] >> 12) & 0xfff;
659 1.1 drochner return (0);
660 1.1 drochner }
661 1.1 drochner
662 1.1 drochner int
663 1.1 drochner tga_builtin_get_curmax(dc, curposp)
664 1.1 drochner struct tga_devconfig *dc;
665 1.1 drochner struct wsdisplay_curpos *curposp;
666 1.1 drochner {
667 1.1 drochner
668 1.1 drochner curposp->x = curposp->y = 64;
669 1.1 drochner return (0);
670 1.14 ross }
671 1.14 ross
672 1.14 ross /*
673 1.14 ross * Copy columns (characters) in a row (line).
674 1.14 ross */
675 1.14 ross void
676 1.14 ross tga_copycols(id, row, srccol, dstcol, ncols)
677 1.14 ross void *id;
678 1.14 ross int row, srccol, dstcol, ncols;
679 1.14 ross {
680 1.14 ross struct rcons *rc = id;
681 1.14 ross int y, srcx, dstx, nx;
682 1.14 ross
683 1.14 ross y = rc->rc_yorigin + rc->rc_font->height * row;
684 1.14 ross srcx = rc->rc_xorigin + rc->rc_font->width * srccol;
685 1.14 ross dstx = rc->rc_xorigin + rc->rc_font->width * dstcol;
686 1.14 ross nx = rc->rc_font->width * ncols;
687 1.14 ross
688 1.14 ross tga_rop(rc->rc_sp, dstx, y,
689 1.14 ross nx, rc->rc_font->height, RAS_SRC,
690 1.14 ross rc->rc_sp, srcx, y);
691 1.14 ross }
692 1.14 ross
693 1.14 ross /*
694 1.14 ross * Copy rows (lines).
695 1.14 ross */
696 1.14 ross void
697 1.14 ross tga_copyrows(id, srcrow, dstrow, nrows)
698 1.14 ross void *id;
699 1.14 ross int srcrow, dstrow, nrows;
700 1.14 ross {
701 1.14 ross struct rcons *rc = id;
702 1.14 ross int srcy, dsty, ny;
703 1.14 ross
704 1.14 ross srcy = rc->rc_yorigin + rc->rc_font->height * srcrow;
705 1.14 ross dsty = rc->rc_yorigin + rc->rc_font->height * dstrow;
706 1.14 ross ny = rc->rc_font->height * nrows;
707 1.14 ross
708 1.14 ross tga_rop(rc->rc_sp, rc->rc_xorigin, dsty,
709 1.14 ross rc->rc_raswidth, ny, RAS_SRC,
710 1.14 ross rc->rc_sp, rc->rc_xorigin, srcy);
711 1.14 ross }
712 1.14 ross
713 1.14 ross /* Do we need the src? */
714 1.14 ross static int needsrc[16] = { 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0 };
715 1.14 ross
716 1.14 ross /* A mapping between our API and the TGA card */
717 1.14 ross static int map_rop[16] = { 0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6,
718 1.14 ross 0xe, 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf
719 1.14 ross };
720 1.14 ross
721 1.14 ross /*
722 1.14 ross * Generic TGA raster op.
723 1.14 ross * This covers all possible raster ops, and
724 1.14 ross * clips the sizes and all of that.
725 1.14 ross */
726 1.14 ross static int
727 1.14 ross tga_rop(dst, dx, dy, w, h, rop, src, sx, sy)
728 1.14 ross struct raster *dst;
729 1.14 ross int dx, dy, w, h, rop;
730 1.14 ross struct raster *src;
731 1.14 ross int sx, sy;
732 1.14 ross {
733 1.14 ross if (!dst)
734 1.14 ross return -1;
735 1.14 ross if (dst->data == NULL)
736 1.14 ross return -1; /* we should be writing to a screen */
737 1.14 ross if (needsrc[RAS_GETOP(rop)]) {
738 1.14 ross if (src == (struct raster *) 0)
739 1.14 ross return -1; /* We want a src */
740 1.14 ross /* Clip against src */
741 1.14 ross if (sx < 0) {
742 1.14 ross w += sx;
743 1.14 ross sx = 0;
744 1.14 ross }
745 1.14 ross if (sy < 0) {
746 1.14 ross h += sy;
747 1.14 ross sy = 0;
748 1.14 ross }
749 1.14 ross if (sx + w > src->width)
750 1.14 ross w = src->width - sx;
751 1.14 ross if (sy + h > src->height)
752 1.14 ross h = src->height - sy;
753 1.14 ross } else {
754 1.14 ross if (src != (struct raster *) 0)
755 1.14 ross return -1; /* We need no src */
756 1.14 ross }
757 1.14 ross /* Clip against dst. We modify src regardless of using it,
758 1.14 ross * since it really doesn't matter.
759 1.14 ross */
760 1.14 ross if (dx < 0) {
761 1.14 ross w += dx;
762 1.14 ross sx -= dx;
763 1.14 ross dx = 0;
764 1.14 ross }
765 1.14 ross if (dy < 0) {
766 1.14 ross h += dy;
767 1.14 ross sy -= dy;
768 1.14 ross dy = 0;
769 1.14 ross }
770 1.14 ross if (dx + w > dst->width)
771 1.14 ross w = dst->width - dx;
772 1.14 ross if (dy + h > dst->height)
773 1.14 ross h = dst->height - dy;
774 1.14 ross if (w <= 0 || h <= 0)
775 1.14 ross return 0; /* Vacuously true; */
776 1.14 ross if (!src)
777 1.14 ross return tga_rop_nosrc(dst, dx, dy, w, h, rop);
778 1.14 ross if (src->data == NULL)
779 1.14 ross return tga_rop_htov(dst, dx, dy, w, h, rop, src, sx, sy);
780 1.14 ross else
781 1.14 ross return tga_rop_vtov(dst, dx, dy, w, h, rop, src, sx, sy);
782 1.14 ross }
783 1.14 ross
784 1.14 ross /*
785 1.14 ross * No source raster ops.
786 1.14 ross * This function deals with all raster ops that don't require a src.
787 1.14 ross */
788 1.14 ross static int
789 1.14 ross tga_rop_nosrc(dst, dx, dy, w, h, rop)
790 1.14 ross struct raster *dst;
791 1.14 ross int dx, dy, w, h, rop;
792 1.14 ross {
793 1.14 ross return raster_op(dst, dx, dy, w, h, rop, NULL, 0, 0);
794 1.14 ross }
795 1.14 ross
796 1.14 ross /*
797 1.14 ross * Host to Video raster ops.
798 1.14 ross * This function deals with all raster ops that have a src that is host memory.
799 1.14 ross */
800 1.14 ross static int
801 1.14 ross tga_rop_htov(dst, dx, dy, w, h, rop, src, sx, sy)
802 1.14 ross struct raster *dst;
803 1.14 ross int dx, dy, w, h, rop;
804 1.14 ross struct raster *src;
805 1.14 ross int sx, sy;
806 1.14 ross {
807 1.14 ross return raster_op(dst, dx, dy, w, h, rop, src, sx, sy);
808 1.14 ross }
809 1.14 ross
810 1.14 ross /*
811 1.14 ross * Video to Video raster ops.
812 1.14 ross * This function deals with all raster ops that have a src and dst
813 1.14 ross * that are on the card.
814 1.14 ross */
815 1.14 ross static int
816 1.14 ross tga_rop_vtov(dst, dx, dy, w, h, rop, src, sx, sy)
817 1.14 ross struct raster *dst;
818 1.14 ross int dx, dy, w, h, rop;
819 1.14 ross struct raster *src;
820 1.14 ross int sx, sy;
821 1.14 ross {
822 1.14 ross struct tga_devconfig *dc = (struct tga_devconfig *)dst->data;
823 1.14 ross tga_reg_t *regs0 = dc->dc_regs;
824 1.14 ross tga_reg_t *regs1 = regs0 + 16 * 1024; /* register alias 1 */
825 1.14 ross tga_reg_t *regs2 = regs1 + 16 * 1024; /* register alias 2 */
826 1.14 ross tga_reg_t *regs3 = regs2 + 16 * 1024; /* register alias 3 */
827 1.14 ross int srcb, dstb;
828 1.14 ross int x, y;
829 1.14 ross int xstart, xend, xdir, xinc;
830 1.14 ross int ystart, yend, ydir, yinc;
831 1.14 ross int offset = 1 * dc->dc_tgaconf->tgac_vvbr_units;
832 1.14 ross
833 1.14 ross /*
834 1.14 ross * I don't yet want to deal with unaligned guys, really. And we don't
835 1.14 ross * deal with copies from one card to another.
836 1.14 ross */
837 1.14 ross if (dx % 8 != 0 || sx % 8 != 0 || src != dst)
838 1.14 ross return raster_op(dst, dx, dy, w, h, rop, src, sx, sy);
839 1.14 ross
840 1.14 ross if (sy >= dy) {
841 1.14 ross ystart = 0;
842 1.14 ross yend = h;
843 1.14 ross ydir = 1;
844 1.14 ross } else {
845 1.14 ross ystart = h;
846 1.14 ross yend = 0;
847 1.14 ross ydir = -1;
848 1.14 ross }
849 1.14 ross if (sx >= dx) {
850 1.14 ross xstart = 0;
851 1.14 ross xend = w * (dst->depth / 8);
852 1.14 ross xdir = 1;
853 1.14 ross } else {
854 1.14 ross xstart = w * (dst->depth / 8);
855 1.14 ross xend = 0;
856 1.14 ross xdir = -1;
857 1.14 ross }
858 1.14 ross xinc = xdir * 4 * 64;
859 1.14 ross yinc = ydir * dst->linelongs * 4;
860 1.14 ross ystart *= dst->linelongs * 4;
861 1.14 ross yend *= dst->linelongs * 4;
862 1.14 ross srcb = offset + sy * src->linelongs * 4 + sx;
863 1.14 ross dstb = offset + dy * dst->linelongs * 4 + dx;
864 1.14 ross regs3[TGA_REG_GMOR] = 0x0007; /* Copy mode */
865 1.14 ross regs3[TGA_REG_GOPR] = map_rop[rop]; /* Set up the op */
866 1.14 ross for (y = ystart; (ydir * y) < (ydir * yend); y += yinc) {
867 1.14 ross for (x = xstart; (xdir * x) < (xdir * xend); x += xinc) {
868 1.14 ross regs0[TGA_REG_GCSR] = srcb + y + x + 3 * 64;
869 1.14 ross regs0[TGA_REG_GCDR] = dstb + y + x + 3 * 64;
870 1.14 ross regs1[TGA_REG_GCSR] = srcb + y + x + 2 * 64;
871 1.14 ross regs1[TGA_REG_GCDR] = dstb + y + x + 2 * 64;
872 1.14 ross regs2[TGA_REG_GCSR] = srcb + y + x + 1 * 64;
873 1.14 ross regs2[TGA_REG_GCDR] = dstb + y + x + 1 * 64;
874 1.14 ross regs3[TGA_REG_GCSR] = srcb + y + x + 0 * 64;
875 1.14 ross regs3[TGA_REG_GCDR] = dstb + y + x + 0 * 64;
876 1.14 ross }
877 1.14 ross }
878 1.14 ross regs0[TGA_REG_GOPR] = 0x0003; /* op -> dst = src */
879 1.14 ross regs0[TGA_REG_GMOR] = 0x0000; /* Simple mode */
880 1.14 ross return 0;
881 1.1 drochner }
882