tga.c revision 1.10 1 1.10 mrg /* $NetBSD: tga.c,v 1.10 1998/11/19 15:38:25 mrg 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.8 thorpej #include "opt_uvm.h"
31 1.8 thorpej
32 1.1 drochner #include <sys/param.h>
33 1.1 drochner #include <sys/systm.h>
34 1.1 drochner #include <sys/kernel.h>
35 1.1 drochner #include <sys/device.h>
36 1.1 drochner #include <sys/conf.h>
37 1.1 drochner #include <sys/malloc.h>
38 1.1 drochner #include <sys/buf.h>
39 1.1 drochner #include <sys/ioctl.h>
40 1.1 drochner
41 1.8 thorpej #include <vm/vm.h>
42 1.8 thorpej
43 1.1 drochner #include <machine/bus.h>
44 1.1 drochner #include <machine/intr.h>
45 1.1 drochner
46 1.1 drochner #include <dev/pci/pcireg.h>
47 1.1 drochner #include <dev/pci/pcivar.h>
48 1.1 drochner #include <dev/pci/pcidevs.h>
49 1.1 drochner #include <dev/pci/tgareg.h>
50 1.1 drochner #include <dev/pci/tgavar.h>
51 1.1 drochner #include <dev/ic/bt485reg.h>
52 1.1 drochner
53 1.1 drochner #include <dev/rcons/raster.h>
54 1.1 drochner #include <dev/wscons/wsconsio.h>
55 1.1 drochner #include <dev/wscons/wscons_raster.h>
56 1.1 drochner #include <dev/wscons/wsdisplayvar.h>
57 1.1 drochner
58 1.1 drochner #ifdef __alpha__
59 1.1 drochner #include <machine/pte.h>
60 1.1 drochner #endif
61 1.1 drochner
62 1.1 drochner int tgamatch __P((struct device *, struct cfdata *, void *));
63 1.1 drochner void tgaattach __P((struct device *, struct device *, void *));
64 1.1 drochner int tgaprint __P((void *, const char *));
65 1.1 drochner
66 1.1 drochner struct cfattach tga_ca = {
67 1.1 drochner sizeof(struct tga_softc), tgamatch, tgaattach,
68 1.1 drochner };
69 1.1 drochner
70 1.1 drochner int tga_identify __P((tga_reg_t *));
71 1.1 drochner const struct tga_conf *tga_getconf __P((int));
72 1.1 drochner void tga_getdevconfig __P((bus_space_tag_t memt, pci_chipset_tag_t pc,
73 1.1 drochner pcitag_t tag, struct tga_devconfig *dc));
74 1.1 drochner
75 1.1 drochner struct tga_devconfig tga_console_dc;
76 1.1 drochner
77 1.1 drochner struct wsdisplay_emulops tga_emulops = {
78 1.1 drochner rcons_cursor, /* could use hardware cursor; punt */
79 1.6 drochner rcons_mapchar,
80 1.5 drochner rcons_putchar,
81 1.1 drochner rcons_copycols,
82 1.1 drochner rcons_erasecols,
83 1.1 drochner rcons_copyrows,
84 1.1 drochner rcons_eraserows,
85 1.4 drochner rcons_alloc_attr
86 1.1 drochner };
87 1.1 drochner
88 1.1 drochner struct wsscreen_descr tga_stdscreen = {
89 1.1 drochner "std",
90 1.4 drochner 0, 0, /* will be filled in -- XXX shouldn't, it's global */
91 1.1 drochner &tga_emulops,
92 1.4 drochner 0, 0,
93 1.4 drochner WSSCREEN_REVERSE
94 1.1 drochner };
95 1.1 drochner
96 1.1 drochner const struct wsscreen_descr *_tga_scrlist[] = {
97 1.1 drochner &tga_stdscreen,
98 1.1 drochner /* XXX other formats, graphics screen? */
99 1.1 drochner };
100 1.1 drochner
101 1.1 drochner struct wsscreen_list tga_screenlist = {
102 1.1 drochner sizeof(_tga_scrlist) / sizeof(struct wsscreen_descr *), _tga_scrlist
103 1.1 drochner };
104 1.1 drochner
105 1.1 drochner int tga_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
106 1.1 drochner int tga_mmap __P((void *, off_t, int));
107 1.1 drochner static int tga_alloc_screen __P((void *, const struct wsscreen_descr *,
108 1.4 drochner void **, int *, int *, long *));
109 1.1 drochner static void tga_free_screen __P((void *, void *));
110 1.1 drochner static void tga_show_screen __P((void *, void *));
111 1.1 drochner static int tga_load_font __P((void *, void *, int, int, int, void *));
112 1.1 drochner
113 1.1 drochner struct wsdisplay_accessops tga_accessops = {
114 1.1 drochner tga_ioctl,
115 1.1 drochner tga_mmap,
116 1.1 drochner tga_alloc_screen,
117 1.1 drochner tga_free_screen,
118 1.1 drochner tga_show_screen,
119 1.1 drochner tga_load_font
120 1.1 drochner };
121 1.1 drochner
122 1.1 drochner void tga_blank __P((struct tga_devconfig *));
123 1.1 drochner void tga_unblank __P((struct tga_devconfig *));
124 1.1 drochner
125 1.1 drochner int
126 1.1 drochner tgamatch(parent, match, aux)
127 1.1 drochner struct device *parent;
128 1.1 drochner struct cfdata *match;
129 1.1 drochner void *aux;
130 1.1 drochner {
131 1.1 drochner struct pci_attach_args *pa = aux;
132 1.1 drochner
133 1.1 drochner if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_DEC ||
134 1.1 drochner PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_DEC_21030)
135 1.1 drochner return (0);
136 1.1 drochner
137 1.1 drochner return (10);
138 1.1 drochner }
139 1.1 drochner
140 1.1 drochner void
141 1.1 drochner tga_getdevconfig(memt, pc, tag, dc)
142 1.1 drochner bus_space_tag_t memt;
143 1.1 drochner pci_chipset_tag_t pc;
144 1.1 drochner pcitag_t tag;
145 1.1 drochner struct tga_devconfig *dc;
146 1.1 drochner {
147 1.1 drochner const struct tga_conf *tgac;
148 1.1 drochner const struct tga_ramdac_conf *tgar;
149 1.1 drochner struct raster *rap;
150 1.1 drochner struct rcons *rcp;
151 1.1 drochner bus_size_t pcisize;
152 1.1 drochner int i, flags;
153 1.1 drochner
154 1.1 drochner dc->dc_memt = memt;
155 1.1 drochner dc->dc_pc = pc;
156 1.1 drochner
157 1.1 drochner dc->dc_pcitag = tag;
158 1.1 drochner
159 1.1 drochner /* XXX magic number */
160 1.1 drochner if (pci_mapreg_info(pc, tag, 0x10,
161 1.1 drochner PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
162 1.1 drochner &dc->dc_pcipaddr, &pcisize, &flags))
163 1.1 drochner return;
164 1.1 drochner if ((flags & BUS_SPACE_MAP_CACHEABLE) == 0) /* XXX */
165 1.1 drochner panic("tga memory not cacheable");
166 1.1 drochner
167 1.1 drochner if (bus_space_map(memt, dc->dc_pcipaddr, pcisize,
168 1.1 drochner BUS_SPACE_MAP_CACHEABLE | BUS_SPACE_MAP_LINEAR, &dc->dc_vaddr))
169 1.1 drochner return;
170 1.1 drochner #ifdef __alpha__
171 1.1 drochner dc->dc_paddr = ALPHA_K0SEG_TO_PHYS(dc->dc_vaddr); /* XXX */
172 1.1 drochner #endif
173 1.1 drochner
174 1.1 drochner dc->dc_regs = (tga_reg_t *)(dc->dc_vaddr + TGA_MEM_CREGS);
175 1.1 drochner dc->dc_tga_type = tga_identify(dc->dc_regs);
176 1.1 drochner tgac = dc->dc_tgaconf = tga_getconf(dc->dc_tga_type);
177 1.1 drochner if (tgac == NULL)
178 1.1 drochner return;
179 1.1 drochner
180 1.1 drochner #if 0
181 1.1 drochner /* XXX on the Alpha, pcisize = 4 * cspace_size. */
182 1.1 drochner if (tgac->tgac_cspace_size != pcisize) /* sanity */
183 1.1 drochner panic("tga_getdevconfig: memory size mismatch?");
184 1.1 drochner #endif
185 1.1 drochner
186 1.1 drochner tgar = tgac->tgac_ramdac;
187 1.1 drochner
188 1.1 drochner switch (dc->dc_regs[TGA_REG_VHCR] & 0x1ff) { /* XXX */
189 1.1 drochner case 0:
190 1.1 drochner dc->dc_wid = 8192;
191 1.1 drochner break;
192 1.1 drochner
193 1.1 drochner case 1:
194 1.1 drochner dc->dc_wid = 8196;
195 1.1 drochner break;
196 1.1 drochner
197 1.1 drochner default:
198 1.1 drochner dc->dc_wid = (dc->dc_regs[TGA_REG_VHCR] & 0x1ff) * 4; /* XXX */
199 1.1 drochner break;
200 1.1 drochner }
201 1.1 drochner
202 1.1 drochner dc->dc_rowbytes = dc->dc_wid * (dc->dc_tgaconf->tgac_phys_depth / 8);
203 1.1 drochner
204 1.1 drochner if ((dc->dc_regs[TGA_REG_VHCR] & 0x00000001) != 0 && /* XXX */
205 1.1 drochner (dc->dc_regs[TGA_REG_VHCR] & 0x80000000) != 0) { /* XXX */
206 1.1 drochner dc->dc_wid -= 4;
207 1.1 drochner /*
208 1.1 drochner * XXX XXX turning off 'odd' shouldn't be necesssary,
209 1.1 drochner * XXX XXX but i can't make X work with the weird size.
210 1.1 drochner */
211 1.1 drochner dc->dc_regs[TGA_REG_VHCR] &= ~0x80000001;
212 1.1 drochner dc->dc_rowbytes =
213 1.1 drochner dc->dc_wid * (dc->dc_tgaconf->tgac_phys_depth / 8);
214 1.1 drochner }
215 1.1 drochner
216 1.1 drochner dc->dc_ht = (dc->dc_regs[TGA_REG_VVCR] & 0x7ff); /* XXX */
217 1.1 drochner
218 1.1 drochner /* XXX this seems to be what DEC does */
219 1.1 drochner dc->dc_regs[TGA_REG_CCBR] = 0;
220 1.1 drochner dc->dc_regs[TGA_REG_VVBR] = 1;
221 1.1 drochner dc->dc_videobase = dc->dc_vaddr + tgac->tgac_dbuf[0] +
222 1.1 drochner 1 * tgac->tgac_vvbr_units;
223 1.1 drochner dc->dc_blanked = 1;
224 1.1 drochner tga_unblank(dc);
225 1.1 drochner
226 1.1 drochner /*
227 1.1 drochner * Set all bits in the pixel mask, to enable writes to all pixels.
228 1.1 drochner * It seems that the console firmware clears some of them
229 1.1 drochner * under some circumstances, which causes cute vertical stripes.
230 1.1 drochner */
231 1.1 drochner dc->dc_regs[TGA_REG_GPXR_P] = 0xffffffff;
232 1.1 drochner
233 1.1 drochner /* clear the screen */
234 1.1 drochner for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
235 1.1 drochner *(u_int32_t *)(dc->dc_videobase + i) = 0;
236 1.1 drochner
237 1.1 drochner /* initialize the raster */
238 1.1 drochner rap = &dc->dc_raster;
239 1.1 drochner rap->width = dc->dc_wid;
240 1.1 drochner rap->height = dc->dc_ht;
241 1.1 drochner rap->depth = tgac->tgac_phys_depth;
242 1.1 drochner rap->linelongs = dc->dc_rowbytes / sizeof(u_int32_t);
243 1.1 drochner rap->pixels = (u_int32_t *)dc->dc_videobase;
244 1.1 drochner
245 1.1 drochner /* initialize the raster console blitter */
246 1.1 drochner rcp = &dc->dc_rcons;
247 1.1 drochner rcp->rc_sp = rap;
248 1.1 drochner rcp->rc_crow = rcp->rc_ccol = -1;
249 1.1 drochner rcp->rc_crowp = &rcp->rc_crow;
250 1.1 drochner rcp->rc_ccolp = &rcp->rc_ccol;
251 1.1 drochner rcons_init(rcp, 34, 80);
252 1.1 drochner
253 1.1 drochner tga_stdscreen.nrows = dc->dc_rcons.rc_maxrow;
254 1.1 drochner tga_stdscreen.ncols = dc->dc_rcons.rc_maxcol;
255 1.1 drochner }
256 1.1 drochner
257 1.1 drochner void
258 1.1 drochner tgaattach(parent, self, aux)
259 1.1 drochner struct device *parent, *self;
260 1.1 drochner void *aux;
261 1.1 drochner {
262 1.1 drochner struct pci_attach_args *pa = aux;
263 1.1 drochner struct tga_softc *sc = (struct tga_softc *)self;
264 1.1 drochner struct wsemuldisplaydev_attach_args aa;
265 1.1 drochner pci_intr_handle_t intrh;
266 1.1 drochner const char *intrstr;
267 1.1 drochner u_int8_t rev;
268 1.1 drochner int console;
269 1.1 drochner
270 1.1 drochner #ifdef __alpha__
271 1.1 drochner console = (pa->pa_tag == tga_console_dc.dc_pcitag);
272 1.1 drochner #else
273 1.1 drochner console = 0;
274 1.1 drochner #endif
275 1.1 drochner if (console) {
276 1.1 drochner sc->sc_dc = &tga_console_dc;
277 1.1 drochner sc->nscreens = 1;
278 1.1 drochner } else {
279 1.1 drochner sc->sc_dc = (struct tga_devconfig *)
280 1.1 drochner malloc(sizeof(struct tga_devconfig), M_DEVBUF, M_WAITOK);
281 1.9 drochner bzero(sc->sc_dc, sizeof(struct tga_devconfig));
282 1.1 drochner tga_getdevconfig(pa->pa_memt, pa->pa_pc, pa->pa_tag, sc->sc_dc);
283 1.1 drochner }
284 1.1 drochner if (sc->sc_dc->dc_vaddr == NULL) {
285 1.1 drochner printf(": couldn't map memory space; punt!\n");
286 1.1 drochner return;
287 1.1 drochner }
288 1.1 drochner
289 1.1 drochner /* XXX say what's going on. */
290 1.1 drochner intrstr = NULL;
291 1.1 drochner if (sc->sc_dc->dc_tgaconf->tgac_ramdac->tgar_intr != NULL) {
292 1.1 drochner if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
293 1.1 drochner pa->pa_intrline, &intrh)) {
294 1.1 drochner printf(": couldn't map interrupt");
295 1.1 drochner return;
296 1.1 drochner }
297 1.1 drochner intrstr = pci_intr_string(pa->pa_pc, intrh);
298 1.1 drochner sc->sc_intr = pci_intr_establish(pa->pa_pc, intrh, IPL_TTY,
299 1.1 drochner sc->sc_dc->dc_tgaconf->tgac_ramdac->tgar_intr, sc->sc_dc);
300 1.1 drochner if (sc->sc_intr == NULL) {
301 1.1 drochner printf(": couldn't establish interrupt");
302 1.1 drochner if (intrstr != NULL)
303 1.1 drochner printf("at %s", intrstr);
304 1.1 drochner printf("\n");
305 1.1 drochner return;
306 1.1 drochner }
307 1.1 drochner }
308 1.1 drochner
309 1.1 drochner /*
310 1.1 drochner * Initialize the RAMDAC and allocate any private storage it needs.
311 1.1 drochner * Initialization includes disabling cursor, setting a sane
312 1.1 drochner * colormap, etc.
313 1.1 drochner */
314 1.1 drochner (*sc->sc_dc->dc_tgaconf->tgac_ramdac->tgar_init)(sc->sc_dc, 1);
315 1.1 drochner
316 1.1 drochner printf(": DC21030 ");
317 1.1 drochner rev = PCI_REVISION(pa->pa_class);
318 1.1 drochner switch (rev) {
319 1.1 drochner case 1: case 2: case 3:
320 1.1 drochner printf("step %c", 'A' + rev - 1);
321 1.1 drochner break;
322 1.1 drochner
323 1.1 drochner default:
324 1.1 drochner printf("unknown stepping (0x%x)", rev);
325 1.1 drochner break;
326 1.1 drochner }
327 1.1 drochner printf(", ");
328 1.1 drochner
329 1.1 drochner if (sc->sc_dc->dc_tgaconf == NULL) {
330 1.1 drochner printf("unknown board configuration\n");
331 1.1 drochner return;
332 1.1 drochner }
333 1.1 drochner printf("board type %s\n", sc->sc_dc->dc_tgaconf->tgac_name);
334 1.1 drochner printf("%s: %d x %d, %dbpp, %s RAMDAC\n", sc->sc_dev.dv_xname,
335 1.1 drochner sc->sc_dc->dc_wid, sc->sc_dc->dc_ht,
336 1.1 drochner sc->sc_dc->dc_tgaconf->tgac_phys_depth,
337 1.1 drochner sc->sc_dc->dc_tgaconf->tgac_ramdac->tgar_name);
338 1.1 drochner
339 1.1 drochner if (intrstr != NULL)
340 1.1 drochner printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
341 1.1 drochner intrstr);
342 1.1 drochner
343 1.1 drochner aa.console = console;
344 1.1 drochner aa.scrdata = &tga_screenlist;
345 1.1 drochner aa.accessops = &tga_accessops;
346 1.1 drochner aa.accesscookie = sc;
347 1.1 drochner
348 1.1 drochner config_found(self, &aa, wsemuldisplaydevprint);
349 1.1 drochner }
350 1.1 drochner
351 1.1 drochner int
352 1.1 drochner tga_ioctl(v, cmd, data, flag, p)
353 1.1 drochner void *v;
354 1.1 drochner u_long cmd;
355 1.1 drochner caddr_t data;
356 1.1 drochner int flag;
357 1.1 drochner struct proc *p;
358 1.1 drochner {
359 1.1 drochner struct tga_softc *sc = v;
360 1.1 drochner struct tga_devconfig *dc = sc->sc_dc;
361 1.1 drochner const struct tga_ramdac_conf *tgar = dc->dc_tgaconf->tgac_ramdac;
362 1.1 drochner
363 1.1 drochner switch (cmd) {
364 1.1 drochner case WSDISPLAYIO_GTYPE:
365 1.1 drochner *(u_int *)data = WSDISPLAY_TYPE_TGA;
366 1.1 drochner return (0);
367 1.1 drochner
368 1.1 drochner case WSDISPLAYIO_GINFO:
369 1.1 drochner #define wsd_fbip ((struct wsdisplay_fbinfo *)data)
370 1.1 drochner wsd_fbip->height = sc->sc_dc->dc_ht;
371 1.1 drochner wsd_fbip->width = sc->sc_dc->dc_wid;
372 1.1 drochner wsd_fbip->depth = sc->sc_dc->dc_tgaconf->tgac_phys_depth;
373 1.1 drochner wsd_fbip->cmsize = 256; /* XXX ??? */
374 1.1 drochner #undef fbt
375 1.1 drochner return (0);
376 1.1 drochner
377 1.1 drochner case WSDISPLAYIO_GETCMAP:
378 1.1 drochner return (*tgar->tgar_get_cmap)(dc,
379 1.1 drochner (struct wsdisplay_cmap *)data);
380 1.1 drochner
381 1.1 drochner case WSDISPLAYIO_PUTCMAP:
382 1.1 drochner return (*tgar->tgar_set_cmap)(dc,
383 1.1 drochner (struct wsdisplay_cmap *)data);
384 1.1 drochner
385 1.1 drochner case WSDISPLAYIO_GVIDEO:
386 1.1 drochner if (*(u_int *)data == WSDISPLAYIO_VIDEO_OFF)
387 1.1 drochner tga_blank(sc->sc_dc);
388 1.1 drochner else
389 1.1 drochner tga_unblank(sc->sc_dc);
390 1.1 drochner return (0);
391 1.1 drochner
392 1.1 drochner case WSDISPLAYIO_SVIDEO:
393 1.1 drochner *(u_int *)data = dc->dc_blanked ?
394 1.1 drochner WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
395 1.1 drochner return (0);
396 1.1 drochner
397 1.1 drochner case WSDISPLAYIO_GCURPOS:
398 1.1 drochner return (*tgar->tgar_get_curpos)(dc,
399 1.1 drochner (struct wsdisplay_curpos *)data);
400 1.1 drochner
401 1.1 drochner case WSDISPLAYIO_SCURPOS:
402 1.1 drochner return (*tgar->tgar_set_curpos)(dc,
403 1.1 drochner (struct wsdisplay_curpos *)data);
404 1.1 drochner
405 1.1 drochner case WSDISPLAYIO_GCURMAX:
406 1.1 drochner return (*tgar->tgar_get_curmax)(dc,
407 1.1 drochner (struct wsdisplay_curpos *)data);
408 1.1 drochner
409 1.1 drochner case WSDISPLAYIO_GCURSOR:
410 1.1 drochner return (*tgar->tgar_get_cursor)(dc,
411 1.1 drochner (struct wsdisplay_cursor *)data);
412 1.1 drochner
413 1.1 drochner case WSDISPLAYIO_SCURSOR:
414 1.1 drochner return (*tgar->tgar_set_cursor)(dc,
415 1.1 drochner (struct wsdisplay_cursor *)data);
416 1.1 drochner }
417 1.1 drochner return (-1);
418 1.1 drochner }
419 1.1 drochner
420 1.1 drochner int
421 1.1 drochner tga_mmap(v, offset, prot)
422 1.1 drochner void *v;
423 1.1 drochner off_t offset;
424 1.1 drochner int prot;
425 1.1 drochner {
426 1.1 drochner
427 1.1 drochner /* XXX NEW MAPPING CODE... */
428 1.1 drochner
429 1.1 drochner #ifdef __alpha__
430 1.1 drochner struct tga_softc *sc = v;
431 1.1 drochner
432 1.10 mrg if (offset >= sc->sc_dc->dc_tgaconf->tgac_cspace_size || offset < 0)
433 1.1 drochner return -1;
434 1.1 drochner return alpha_btop(sc->sc_dc->dc_paddr + offset);
435 1.1 drochner #else
436 1.1 drochner return (-1);
437 1.1 drochner #endif
438 1.1 drochner }
439 1.1 drochner
440 1.1 drochner int
441 1.4 drochner tga_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
442 1.1 drochner void *v;
443 1.1 drochner const struct wsscreen_descr *type;
444 1.1 drochner void **cookiep;
445 1.1 drochner int *curxp, *curyp;
446 1.4 drochner long *attrp;
447 1.1 drochner {
448 1.1 drochner struct tga_softc *sc = v;
449 1.4 drochner long defattr;
450 1.1 drochner
451 1.1 drochner if (sc->nscreens > 0)
452 1.1 drochner return (ENOMEM);
453 1.1 drochner
454 1.1 drochner *cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */
455 1.1 drochner *curxp = 0;
456 1.1 drochner *curyp = 0;
457 1.4 drochner rcons_alloc_attr(&sc->sc_dc->dc_rcons, 0, 0, 0, &defattr);
458 1.4 drochner *attrp = defattr;
459 1.2 drochner sc->nscreens++;
460 1.1 drochner return (0);
461 1.1 drochner }
462 1.1 drochner
463 1.1 drochner void
464 1.1 drochner tga_free_screen(v, cookie)
465 1.1 drochner void *v;
466 1.1 drochner void *cookie;
467 1.1 drochner {
468 1.1 drochner struct tga_softc *sc = v;
469 1.1 drochner
470 1.1 drochner if (sc->sc_dc == &tga_console_dc)
471 1.1 drochner panic("tga_free_screen: console");
472 1.1 drochner
473 1.1 drochner sc->nscreens--;
474 1.1 drochner }
475 1.1 drochner
476 1.1 drochner void
477 1.1 drochner tga_show_screen(v, cookie)
478 1.1 drochner void *v;
479 1.1 drochner void *cookie;
480 1.1 drochner {
481 1.1 drochner }
482 1.1 drochner
483 1.1 drochner static int
484 1.1 drochner tga_load_font(v, cookie, first, num, stride, data)
485 1.1 drochner void *v;
486 1.1 drochner void *cookie;
487 1.1 drochner int first, num, stride;
488 1.1 drochner void *data;
489 1.1 drochner {
490 1.1 drochner return (EINVAL);
491 1.1 drochner }
492 1.1 drochner
493 1.1 drochner int
494 1.1 drochner tga_cnattach(iot, memt, pc, bus, device, function)
495 1.1 drochner bus_space_tag_t iot, memt;
496 1.1 drochner pci_chipset_tag_t pc;
497 1.1 drochner int bus, device, function;
498 1.1 drochner {
499 1.1 drochner struct tga_devconfig *dcp = &tga_console_dc;
500 1.4 drochner long defattr;
501 1.1 drochner
502 1.1 drochner tga_getdevconfig(memt, pc,
503 1.1 drochner pci_make_tag(pc, bus, device, function), dcp);
504 1.1 drochner
505 1.1 drochner /* sanity checks */
506 1.1 drochner if (dcp->dc_vaddr == NULL)
507 1.1 drochner panic("tga_console(%d, %d): couldn't map memory space",
508 1.1 drochner device, function);
509 1.1 drochner if (dcp->dc_tgaconf == NULL)
510 1.1 drochner panic("tga_console(%d, %d): unknown board configuration",
511 1.1 drochner device, function);
512 1.1 drochner
513 1.1 drochner /*
514 1.1 drochner * Initialize the RAMDAC but DO NOT allocate any private storage.
515 1.1 drochner * Initialization includes disabling cursor, setting a sane
516 1.1 drochner * colormap, etc. It will be reinitialized in tgaattach().
517 1.1 drochner */
518 1.1 drochner (*dcp->dc_tgaconf->tgac_ramdac->tgar_init)(dcp, 0);
519 1.1 drochner
520 1.4 drochner rcons_alloc_attr(&dcp->dc_rcons, 0, 0, 0, &defattr);
521 1.4 drochner
522 1.1 drochner wsdisplay_cnattach(&tga_stdscreen, &dcp->dc_rcons,
523 1.4 drochner 0, 0, defattr);
524 1.1 drochner
525 1.1 drochner return(0);
526 1.1 drochner }
527 1.1 drochner
528 1.1 drochner /*
529 1.1 drochner * Functions to blank and unblank the display.
530 1.1 drochner */
531 1.1 drochner void
532 1.1 drochner tga_blank(dc)
533 1.1 drochner struct tga_devconfig *dc;
534 1.1 drochner {
535 1.1 drochner
536 1.1 drochner if (!dc->dc_blanked) {
537 1.1 drochner dc->dc_blanked = 1;
538 1.3 thorpej dc->dc_regs[TGA_REG_VVVR] |= VVR_BLANK; /* XXX */
539 1.1 drochner }
540 1.1 drochner }
541 1.1 drochner
542 1.1 drochner void
543 1.1 drochner tga_unblank(dc)
544 1.1 drochner struct tga_devconfig *dc;
545 1.1 drochner {
546 1.1 drochner
547 1.1 drochner if (dc->dc_blanked) {
548 1.1 drochner dc->dc_blanked = 0;
549 1.3 thorpej dc->dc_regs[TGA_REG_VVVR] &= ~VVR_BLANK; /* XXX */
550 1.1 drochner }
551 1.1 drochner }
552 1.1 drochner
553 1.1 drochner /*
554 1.1 drochner * Functions to manipulate the built-in cursor handing hardware.
555 1.1 drochner */
556 1.1 drochner int
557 1.1 drochner tga_builtin_set_cursor(dc, cursorp)
558 1.1 drochner struct tga_devconfig *dc;
559 1.1 drochner struct wsdisplay_cursor *cursorp;
560 1.1 drochner {
561 1.8 thorpej int count, error, v;
562 1.1 drochner
563 1.1 drochner v = cursorp->which;
564 1.8 thorpej if (v & WSDISPLAY_CURSOR_DOCMAP) {
565 1.8 thorpej error = (*dc->dc_tgaconf->tgac_ramdac->tgar_check_curcmap)(dc,
566 1.8 thorpej cursorp);
567 1.8 thorpej if (error)
568 1.8 thorpej return (error);
569 1.8 thorpej }
570 1.1 drochner if (v & WSDISPLAY_CURSOR_DOSHAPE) {
571 1.1 drochner if ((u_int)cursorp->size.x != 64 ||
572 1.1 drochner (u_int)cursorp->size.y > 64)
573 1.1 drochner return (EINVAL);
574 1.1 drochner /* The cursor is 2 bits deep, and there is no mask */
575 1.1 drochner count = (cursorp->size.y * 64 * 2) / NBBY;
576 1.8 thorpej #if defined(UVM)
577 1.8 thorpej if (!uvm_useracc(cursorp->image, count, B_READ))
578 1.8 thorpej return (EFAULT);
579 1.8 thorpej #else
580 1.1 drochner if (!useracc(cursorp->image, count, B_READ))
581 1.1 drochner return (EFAULT);
582 1.8 thorpej #endif
583 1.1 drochner }
584 1.1 drochner if (v & WSDISPLAY_CURSOR_DOHOT) /* not supported */
585 1.1 drochner return EINVAL;
586 1.1 drochner
587 1.1 drochner /* parameters are OK; do it */
588 1.1 drochner if (v & WSDISPLAY_CURSOR_DOCUR) {
589 1.1 drochner if (cursorp->enable)
590 1.1 drochner dc->dc_regs[TGA_REG_VVVR] |= 0x04; /* XXX */
591 1.1 drochner else
592 1.1 drochner dc->dc_regs[TGA_REG_VVVR] &= ~0x04; /* XXX */
593 1.1 drochner }
594 1.1 drochner if (v & WSDISPLAY_CURSOR_DOPOS) {
595 1.1 drochner dc->dc_regs[TGA_REG_CXYR] = ((cursorp->pos.y & 0xfff) << 12) |
596 1.1 drochner (cursorp->pos.x & 0xfff);
597 1.1 drochner }
598 1.1 drochner if (v & WSDISPLAY_CURSOR_DOCMAP) {
599 1.8 thorpej /* can't fail. */
600 1.8 thorpej (*dc->dc_tgaconf->tgac_ramdac->tgar_set_curcmap)(dc, cursorp);
601 1.1 drochner }
602 1.1 drochner if (v & WSDISPLAY_CURSOR_DOSHAPE) {
603 1.8 thorpej count = ((64 * 2) / NBBY) * cursorp->size.y;
604 1.1 drochner dc->dc_regs[TGA_REG_CCBR] =
605 1.1 drochner (dc->dc_regs[TGA_REG_CCBR] & ~0xfc00) |
606 1.1 drochner (cursorp->size.y << 10);
607 1.1 drochner copyin(cursorp->image, (char *)(dc->dc_vaddr +
608 1.1 drochner (dc->dc_regs[TGA_REG_CCBR] & 0x3ff)),
609 1.1 drochner count); /* can't fail. */
610 1.1 drochner }
611 1.1 drochner return (0);
612 1.1 drochner }
613 1.1 drochner
614 1.1 drochner int
615 1.1 drochner tga_builtin_get_cursor(dc, cursorp)
616 1.1 drochner struct tga_devconfig *dc;
617 1.1 drochner struct wsdisplay_cursor *cursorp;
618 1.1 drochner {
619 1.1 drochner int count, error;
620 1.1 drochner
621 1.1 drochner cursorp->which = WSDISPLAY_CURSOR_DOALL &
622 1.1 drochner ~(WSDISPLAY_CURSOR_DOHOT | WSDISPLAY_CURSOR_DOCMAP);
623 1.1 drochner cursorp->enable = (dc->dc_regs[TGA_REG_VVVR] & 0x04) != 0;
624 1.1 drochner cursorp->pos.x = dc->dc_regs[TGA_REG_CXYR] & 0xfff;
625 1.1 drochner cursorp->pos.y = (dc->dc_regs[TGA_REG_CXYR] >> 12) & 0xfff;
626 1.1 drochner cursorp->size.x = 64;
627 1.1 drochner cursorp->size.y = (dc->dc_regs[TGA_REG_CCBR] >> 10) & 0x3f;
628 1.1 drochner
629 1.1 drochner if (cursorp->image != NULL) {
630 1.1 drochner count = (cursorp->size.y * 64 * 2) / NBBY;
631 1.1 drochner error = copyout((char *)(dc->dc_vaddr +
632 1.1 drochner (dc->dc_regs[TGA_REG_CCBR] & 0x3ff)),
633 1.1 drochner cursorp->image, count);
634 1.1 drochner if (error)
635 1.1 drochner return (error);
636 1.1 drochner /* No mask */
637 1.1 drochner }
638 1.8 thorpej error = (*dc->dc_tgaconf->tgac_ramdac->tgar_get_curcmap)(dc, cursorp);
639 1.8 thorpej return (error);
640 1.1 drochner }
641 1.1 drochner
642 1.1 drochner int
643 1.1 drochner tga_builtin_set_curpos(dc, curposp)
644 1.1 drochner struct tga_devconfig *dc;
645 1.1 drochner struct wsdisplay_curpos *curposp;
646 1.1 drochner {
647 1.1 drochner
648 1.1 drochner dc->dc_regs[TGA_REG_CXYR] =
649 1.1 drochner ((curposp->y & 0xfff) << 12) | (curposp->x & 0xfff);
650 1.1 drochner return (0);
651 1.1 drochner }
652 1.1 drochner
653 1.1 drochner int
654 1.1 drochner tga_builtin_get_curpos(dc, curposp)
655 1.1 drochner struct tga_devconfig *dc;
656 1.1 drochner struct wsdisplay_curpos *curposp;
657 1.1 drochner {
658 1.1 drochner
659 1.1 drochner curposp->x = dc->dc_regs[TGA_REG_CXYR] & 0xfff;
660 1.1 drochner curposp->y = (dc->dc_regs[TGA_REG_CXYR] >> 12) & 0xfff;
661 1.1 drochner return (0);
662 1.1 drochner }
663 1.1 drochner
664 1.1 drochner int
665 1.1 drochner tga_builtin_get_curmax(dc, curposp)
666 1.1 drochner struct tga_devconfig *dc;
667 1.1 drochner struct wsdisplay_curpos *curposp;
668 1.1 drochner {
669 1.1 drochner
670 1.1 drochner curposp->x = curposp->y = 64;
671 1.1 drochner return (0);
672 1.1 drochner }
673