tga.c revision 1.41 1 1.41 atatat /* $NetBSD: tga.c,v 1.41 2002/03/17 19:41:00 atatat 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.37 lukem
30 1.37 lukem #include <sys/cdefs.h>
31 1.41 atatat __KERNEL_RCSID(0, "$NetBSD: tga.c,v 1.41 2002/03/17 19:41:00 atatat Exp $");
32 1.1 drochner
33 1.1 drochner #include <sys/param.h>
34 1.1 drochner #include <sys/systm.h>
35 1.1 drochner #include <sys/kernel.h>
36 1.1 drochner #include <sys/device.h>
37 1.1 drochner #include <sys/conf.h>
38 1.1 drochner #include <sys/malloc.h>
39 1.1 drochner #include <sys/buf.h>
40 1.1 drochner #include <sys/ioctl.h>
41 1.8 thorpej
42 1.1 drochner #include <machine/bus.h>
43 1.1 drochner #include <machine/intr.h>
44 1.1 drochner
45 1.1 drochner #include <dev/pci/pcireg.h>
46 1.1 drochner #include <dev/pci/pcivar.h>
47 1.1 drochner #include <dev/pci/pcidevs.h>
48 1.1 drochner #include <dev/pci/tgareg.h>
49 1.1 drochner #include <dev/pci/tgavar.h>
50 1.1 drochner #include <dev/ic/bt485reg.h>
51 1.17 elric #include <dev/ic/bt485var.h>
52 1.22 nathanw #include <dev/ic/bt463reg.h>
53 1.22 nathanw #include <dev/ic/bt463var.h>
54 1.38 elric #include <dev/ic/ibm561var.h>
55 1.1 drochner
56 1.1 drochner #include <dev/wscons/wsconsio.h>
57 1.1 drochner #include <dev/wscons/wscons_raster.h>
58 1.23 nathanw #include <dev/rasops/rasops.h>
59 1.23 nathanw #include <dev/wsfont/wsfont.h>
60 1.28 mjacob #include <uvm/uvm_extern.h>
61 1.1 drochner
62 1.1 drochner #ifdef __alpha__
63 1.1 drochner #include <machine/pte.h>
64 1.1 drochner #endif
65 1.24 soda #ifdef __mips__
66 1.24 soda #include <mips/pte.h>
67 1.24 soda #endif
68 1.1 drochner
69 1.1 drochner int tgamatch __P((struct device *, struct cfdata *, void *));
70 1.1 drochner void tgaattach __P((struct device *, struct device *, void *));
71 1.1 drochner int tgaprint __P((void *, const char *));
72 1.1 drochner
73 1.1 drochner struct cfattach tga_ca = {
74 1.1 drochner sizeof(struct tga_softc), tgamatch, tgaattach,
75 1.1 drochner };
76 1.1 drochner
77 1.21 nathanw int tga_identify __P((struct tga_devconfig *));
78 1.1 drochner const struct tga_conf *tga_getconf __P((int));
79 1.34 elric static void tga_init __P((bus_space_tag_t memt, pci_chipset_tag_t pc,
80 1.19 elric pcitag_t tag, struct tga_devconfig *dc));
81 1.1 drochner
82 1.34 elric static int tga_matchcommon __P((bus_space_tag_t, pci_chipset_tag_t, pcitag_t));
83 1.34 elric static void tga_mapaddrs __P((bus_space_tag_t memt, pci_chipset_tag_t pc,
84 1.34 elric pcitag_t, bus_size_t *pcisize, struct tga_devconfig *dc));
85 1.38 elric unsigned tga_getdotclock __P((struct tga_devconfig *dc));
86 1.34 elric
87 1.1 drochner struct tga_devconfig tga_console_dc;
88 1.1 drochner
89 1.14 ross int tga_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
90 1.26 simonb paddr_t tga_mmap __P((void *, off_t, int));
91 1.14 ross static void tga_copyrows __P((void *, int, int, int));
92 1.14 ross static void tga_copycols __P((void *, int, int, int, int));
93 1.14 ross static int tga_alloc_screen __P((void *, const struct wsscreen_descr *,
94 1.14 ross void **, int *, int *, long *));
95 1.14 ross static void tga_free_screen __P((void *, void *));
96 1.15 drochner static int tga_show_screen __P((void *, void *, int,
97 1.15 drochner void (*) (void *, int, int), void *));
98 1.23 nathanw static int tga_rop __P((struct rasops_info *, int, int, int, int, int,
99 1.23 nathanw struct rasops_info *, int, int));
100 1.23 nathanw static int tga_rop_vtov __P((struct rasops_info *, int, int, int, int,
101 1.23 nathanw int, struct rasops_info *, int, int ));
102 1.23 nathanw static void tga_putchar __P((void *c, int row, int col,
103 1.23 nathanw u_int uc, long attr));
104 1.23 nathanw static void tga_eraserows __P((void *, int, int, long));
105 1.23 nathanw static void tga_erasecols __P((void *, int, int, int, long));
106 1.38 elric void tga2_init __P((struct tga_devconfig *));
107 1.17 elric
108 1.22 nathanw static void tga_config_interrupts __P((struct device *));
109 1.22 nathanw
110 1.17 elric /* RAMDAC interface functions */
111 1.22 nathanw static int tga_sched_update __P((void *, void (*)(void *)));
112 1.22 nathanw static void tga_ramdac_wr __P((void *, u_int, u_int8_t));
113 1.22 nathanw static u_int8_t tga_ramdac_rd __P((void *, u_int));
114 1.22 nathanw static void tga_bt463_wr __P((void *, u_int, u_int8_t));
115 1.22 nathanw static u_int8_t tga_bt463_rd __P((void *, u_int));
116 1.22 nathanw static void tga2_ramdac_wr __P((void *, u_int, u_int8_t));
117 1.22 nathanw static u_int8_t tga2_ramdac_rd __P((void *, u_int));
118 1.17 elric
119 1.17 elric /* Interrupt handler */
120 1.22 nathanw static int tga_intr __P((void *));
121 1.14 ross
122 1.23 nathanw /* The NULL entries will get filled in by rasops_init().
123 1.23 nathanw * XXX and the non-NULL ones will be overwritten; reset after calling it.
124 1.23 nathanw */
125 1.1 drochner struct wsdisplay_emulops tga_emulops = {
126 1.23 nathanw NULL,
127 1.23 nathanw NULL,
128 1.23 nathanw tga_putchar,
129 1.14 ross tga_copycols,
130 1.23 nathanw tga_erasecols,
131 1.14 ross tga_copyrows,
132 1.23 nathanw tga_eraserows,
133 1.23 nathanw NULL,
134 1.1 drochner };
135 1.1 drochner
136 1.1 drochner struct wsscreen_descr tga_stdscreen = {
137 1.1 drochner "std",
138 1.4 drochner 0, 0, /* will be filled in -- XXX shouldn't, it's global */
139 1.1 drochner &tga_emulops,
140 1.4 drochner 0, 0,
141 1.4 drochner WSSCREEN_REVERSE
142 1.1 drochner };
143 1.1 drochner
144 1.1 drochner const struct wsscreen_descr *_tga_scrlist[] = {
145 1.1 drochner &tga_stdscreen,
146 1.1 drochner /* XXX other formats, graphics screen? */
147 1.1 drochner };
148 1.1 drochner
149 1.1 drochner struct wsscreen_list tga_screenlist = {
150 1.1 drochner sizeof(_tga_scrlist) / sizeof(struct wsscreen_descr *), _tga_scrlist
151 1.1 drochner };
152 1.1 drochner
153 1.1 drochner struct wsdisplay_accessops tga_accessops = {
154 1.1 drochner tga_ioctl,
155 1.1 drochner tga_mmap,
156 1.1 drochner tga_alloc_screen,
157 1.1 drochner tga_free_screen,
158 1.1 drochner tga_show_screen,
159 1.11 drochner 0 /* load_font */
160 1.1 drochner };
161 1.1 drochner
162 1.22 nathanw static void tga_blank __P((struct tga_devconfig *));
163 1.22 nathanw static void tga_unblank __P((struct tga_devconfig *));
164 1.1 drochner
165 1.1 drochner int
166 1.34 elric tga_cnmatch(iot, memt, pc, tag)
167 1.34 elric bus_space_tag_t iot, memt;
168 1.34 elric pci_chipset_tag_t pc;
169 1.34 elric pcitag_t tag;
170 1.34 elric {
171 1.34 elric return tga_matchcommon(memt, pc, tag);
172 1.34 elric }
173 1.34 elric
174 1.34 elric int
175 1.1 drochner tgamatch(parent, match, aux)
176 1.1 drochner struct device *parent;
177 1.1 drochner struct cfdata *match;
178 1.1 drochner void *aux;
179 1.1 drochner {
180 1.1 drochner struct pci_attach_args *pa = aux;
181 1.1 drochner
182 1.17 elric if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_DEC)
183 1.1 drochner return (0);
184 1.1 drochner
185 1.17 elric switch (PCI_PRODUCT(pa->pa_id)) {
186 1.17 elric case PCI_PRODUCT_DEC_21030:
187 1.17 elric case PCI_PRODUCT_DEC_PBXGB:
188 1.34 elric break;
189 1.17 elric default:
190 1.17 elric return 0;
191 1.17 elric }
192 1.34 elric
193 1.34 elric /* short-circuit the following test, as we
194 1.34 elric * already have the memory mapped and hence
195 1.34 elric * cannot perform it---and we are the console
196 1.34 elric * anyway.
197 1.34 elric */
198 1.34 elric if (pa->pa_tag == tga_console_dc.dc_pcitag)
199 1.34 elric return 10;
200 1.34 elric
201 1.34 elric return tga_matchcommon(pa->pa_memt, pa->pa_pc, pa->pa_tag);
202 1.34 elric }
203 1.34 elric
204 1.34 elric static int
205 1.34 elric tga_matchcommon(memt, pc, tag)
206 1.34 elric bus_space_tag_t memt;
207 1.34 elric pci_chipset_tag_t pc;
208 1.34 elric pcitag_t tag;
209 1.34 elric {
210 1.34 elric struct tga_devconfig tmp_dc;
211 1.34 elric struct tga_devconfig *dc = &tmp_dc;
212 1.34 elric bus_size_t pcisize;
213 1.34 elric
214 1.34 elric tga_mapaddrs(memt, pc, tag, &pcisize, dc);
215 1.34 elric dc->dc_tga_type = tga_identify(dc);
216 1.34 elric
217 1.34 elric dc->dc_tgaconf = tga_getconf(dc->dc_tga_type);
218 1.34 elric bus_space_unmap(memt, dc->dc_memh, pcisize);
219 1.34 elric if (dc->dc_tgaconf)
220 1.34 elric return 10;
221 1.34 elric return 0;
222 1.1 drochner }
223 1.1 drochner
224 1.22 nathanw static void
225 1.34 elric tga_mapaddrs(memt, pc, tag, pcisize, dc)
226 1.1 drochner bus_space_tag_t memt;
227 1.1 drochner pci_chipset_tag_t pc;
228 1.1 drochner pcitag_t tag;
229 1.34 elric bus_size_t *pcisize;
230 1.1 drochner struct tga_devconfig *dc;
231 1.1 drochner {
232 1.34 elric int flags;
233 1.1 drochner
234 1.1 drochner dc->dc_memt = memt;
235 1.34 elric dc->dc_tgaconf = NULL;
236 1.1 drochner
237 1.1 drochner /* XXX magic number */
238 1.1 drochner if (pci_mapreg_info(pc, tag, 0x10,
239 1.1 drochner PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
240 1.34 elric &dc->dc_pcipaddr, pcisize, &flags))
241 1.34 elric panic("tga_mapaddrs: pci_mapreg_info() failed");
242 1.16 drochner if ((flags & BUS_SPACE_MAP_PREFETCHABLE) == 0) /* XXX */
243 1.16 drochner panic("tga memory not prefetchable");
244 1.1 drochner
245 1.34 elric if (bus_space_map(memt, dc->dc_pcipaddr, *pcisize,
246 1.21 nathanw BUS_SPACE_MAP_PREFETCHABLE | BUS_SPACE_MAP_LINEAR, &dc->dc_memh))
247 1.34 elric panic("tga_mapaddrs: could not map TGA address space");
248 1.23 nathanw dc->dc_vaddr = (vaddr_t) bus_space_vaddr(memt, dc->dc_memh);
249 1.1 drochner
250 1.21 nathanw bus_space_subregion(dc->dc_memt, dc->dc_memh,
251 1.21 nathanw TGA_MEM_CREGS, TGA_CREGS_SIZE,
252 1.21 nathanw &dc->dc_regs);
253 1.34 elric }
254 1.34 elric
255 1.34 elric static void
256 1.34 elric tga_init(memt, pc, tag, dc)
257 1.34 elric bus_space_tag_t memt;
258 1.34 elric pci_chipset_tag_t pc;
259 1.34 elric pcitag_t tag;
260 1.34 elric struct tga_devconfig *dc;
261 1.34 elric {
262 1.34 elric const struct tga_conf *tgac;
263 1.34 elric struct rasops_info *rip;
264 1.34 elric int cookie;
265 1.34 elric bus_size_t pcisize;
266 1.34 elric int i;
267 1.34 elric
268 1.34 elric dc->dc_pcitag = tag;
269 1.34 elric tga_mapaddrs(memt, pc, tag, &pcisize, dc);
270 1.21 nathanw dc->dc_tga_type = tga_identify(dc);
271 1.1 drochner tgac = dc->dc_tgaconf = tga_getconf(dc->dc_tga_type);
272 1.1 drochner #if 0
273 1.1 drochner /* XXX on the Alpha, pcisize = 4 * cspace_size. */
274 1.1 drochner if (tgac->tgac_cspace_size != pcisize) /* sanity */
275 1.34 elric panic("tga_init: memory size mismatch?");
276 1.1 drochner #endif
277 1.1 drochner
278 1.21 nathanw switch (TGARREG(dc, TGA_REG_GREV) & 0xff) {
279 1.19 elric case 0x01:
280 1.19 elric case 0x02:
281 1.19 elric case 0x03:
282 1.19 elric case 0x04:
283 1.19 elric dc->dc_tga2 = 0;
284 1.19 elric break;
285 1.19 elric case 0x20:
286 1.19 elric case 0x21:
287 1.19 elric case 0x22:
288 1.19 elric dc->dc_tga2 = 1;
289 1.19 elric break;
290 1.19 elric default:
291 1.34 elric panic("tga_init: TGA Revision not recognized");
292 1.19 elric }
293 1.19 elric
294 1.38 elric if (dc->dc_tga2)
295 1.38 elric tga2_init(dc);
296 1.22 nathanw
297 1.21 nathanw switch (TGARREG(dc, TGA_REG_VHCR) & 0x1ff) { /* XXX */
298 1.1 drochner case 0:
299 1.1 drochner dc->dc_wid = 8192;
300 1.1 drochner break;
301 1.1 drochner
302 1.1 drochner case 1:
303 1.1 drochner dc->dc_wid = 8196;
304 1.1 drochner break;
305 1.1 drochner
306 1.1 drochner default:
307 1.21 nathanw dc->dc_wid = (TGARREG(dc, TGA_REG_VHCR) & 0x1ff) * 4; /* XXX */
308 1.1 drochner break;
309 1.29 thorpej }
310 1.29 thorpej
311 1.29 thorpej /*
312 1.29 thorpej * XXX XXX Turning off "odd" shouldn't be necessary,
313 1.29 thorpej * XXX XXX but I can't make X work with the weird size.
314 1.29 thorpej */
315 1.29 thorpej if ((TGARREG(dc, TGA_REG_VHCR) & 0x00000001) != 0 && /* XXX */
316 1.29 thorpej (TGARREG(dc, TGA_REG_VHCR) & 0x80000000) != 0) { /* XXX */
317 1.29 thorpej TGAWREG(dc, TGA_REG_VHCR,
318 1.29 thorpej (TGARREG(dc, TGA_REG_VHCR) & ~0x80000001));
319 1.29 thorpej dc->dc_wid -= 4;
320 1.1 drochner }
321 1.1 drochner
322 1.1 drochner dc->dc_rowbytes = dc->dc_wid * (dc->dc_tgaconf->tgac_phys_depth / 8);
323 1.21 nathanw dc->dc_ht = (TGARREG(dc, TGA_REG_VVCR) & 0x7ff); /* XXX */
324 1.1 drochner
325 1.1 drochner /* XXX this seems to be what DEC does */
326 1.21 nathanw TGAWREG(dc, TGA_REG_CCBR, 0);
327 1.21 nathanw TGAWREG(dc, TGA_REG_VVBR, 1);
328 1.1 drochner dc->dc_videobase = dc->dc_vaddr + tgac->tgac_dbuf[0] +
329 1.1 drochner 1 * tgac->tgac_vvbr_units;
330 1.1 drochner dc->dc_blanked = 1;
331 1.1 drochner tga_unblank(dc);
332 1.1 drochner
333 1.1 drochner /*
334 1.1 drochner * Set all bits in the pixel mask, to enable writes to all pixels.
335 1.1 drochner * It seems that the console firmware clears some of them
336 1.1 drochner * under some circumstances, which causes cute vertical stripes.
337 1.1 drochner */
338 1.21 nathanw TGAWREG(dc, TGA_REG_GPXR_P, 0xffffffff);
339 1.1 drochner
340 1.1 drochner /* clear the screen */
341 1.1 drochner for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
342 1.1 drochner *(u_int32_t *)(dc->dc_videobase + i) = 0;
343 1.1 drochner
344 1.23 nathanw /* Initialize rasops descriptor */
345 1.23 nathanw rip = &dc->dc_rinfo;
346 1.23 nathanw rip->ri_flg = RI_CENTER;
347 1.23 nathanw rip->ri_depth = tgac->tgac_phys_depth;
348 1.23 nathanw rip->ri_bits = (void *)dc->dc_videobase;
349 1.23 nathanw rip->ri_width = dc->dc_wid;
350 1.23 nathanw rip->ri_height = dc->dc_ht;
351 1.23 nathanw rip->ri_stride = dc->dc_rowbytes;
352 1.23 nathanw rip->ri_hw = dc;
353 1.23 nathanw
354 1.23 nathanw if (tgac->tgac_phys_depth == 32) {
355 1.23 nathanw rip->ri_rnum = 8;
356 1.23 nathanw rip->ri_gnum = 8;
357 1.23 nathanw rip->ri_bnum = 8;
358 1.23 nathanw rip->ri_rpos = 16;
359 1.23 nathanw rip->ri_gpos = 8;
360 1.23 nathanw rip->ri_bpos = 0;
361 1.23 nathanw }
362 1.23 nathanw
363 1.23 nathanw wsfont_init();
364 1.23 nathanw /* prefer 8 pixel wide font */
365 1.40 ad cookie = wsfont_find(NULL, 8, 0, 0, WSDISPLAY_FONTORDER_R2L,
366 1.40 ad WSDISPLAY_FONTORDER_L2R);
367 1.40 ad if (cookie <= 0)
368 1.40 ad cookie = wsfont_find(NULL, 0, 0, 0, WSDISPLAY_FONTORDER_R2L,
369 1.40 ad WSDISPLAY_FONTORDER_L2R);
370 1.23 nathanw if (cookie <= 0) {
371 1.23 nathanw printf("tga: no appropriate fonts.\n");
372 1.23 nathanw return;
373 1.23 nathanw }
374 1.23 nathanw
375 1.23 nathanw /* the accelerated tga_putchar() needs LSbit left */
376 1.40 ad if (wsfont_lock(cookie, &dc->dc_rinfo.ri_font)) {
377 1.23 nathanw printf("tga: couldn't lock font\n");
378 1.23 nathanw return;
379 1.23 nathanw }
380 1.23 nathanw dc->dc_rinfo.ri_wsfcookie = cookie;
381 1.23 nathanw
382 1.23 nathanw rasops_init(rip, 34, 80);
383 1.23 nathanw
384 1.23 nathanw /* add our accelerated functions */
385 1.23 nathanw /* XXX shouldn't have to do this; rasops should leave non-NULL
386 1.23 nathanw * XXX entries alone.
387 1.23 nathanw */
388 1.23 nathanw dc->dc_rinfo.ri_ops.copyrows = tga_copyrows;
389 1.23 nathanw dc->dc_rinfo.ri_ops.eraserows = tga_eraserows;
390 1.23 nathanw dc->dc_rinfo.ri_ops.erasecols = tga_erasecols;
391 1.23 nathanw dc->dc_rinfo.ri_ops.copycols = tga_copycols;
392 1.23 nathanw dc->dc_rinfo.ri_ops.putchar = tga_putchar;
393 1.23 nathanw
394 1.23 nathanw tga_stdscreen.nrows = dc->dc_rinfo.ri_rows;
395 1.23 nathanw tga_stdscreen.ncols = dc->dc_rinfo.ri_cols;
396 1.23 nathanw tga_stdscreen.textops = &dc->dc_rinfo.ri_ops;
397 1.23 nathanw tga_stdscreen.capabilities = dc->dc_rinfo.ri_caps;
398 1.1 drochner
399 1.22 nathanw
400 1.22 nathanw dc->dc_intrenabled = 0;
401 1.1 drochner }
402 1.1 drochner
403 1.1 drochner void
404 1.1 drochner tgaattach(parent, self, aux)
405 1.1 drochner struct device *parent, *self;
406 1.1 drochner void *aux;
407 1.1 drochner {
408 1.1 drochner struct pci_attach_args *pa = aux;
409 1.1 drochner struct tga_softc *sc = (struct tga_softc *)self;
410 1.1 drochner struct wsemuldisplaydev_attach_args aa;
411 1.1 drochner pci_intr_handle_t intrh;
412 1.1 drochner const char *intrstr;
413 1.1 drochner u_int8_t rev;
414 1.1 drochner int console;
415 1.1 drochner
416 1.25 soda #if defined(__alpha__) || defined(arc)
417 1.1 drochner console = (pa->pa_tag == tga_console_dc.dc_pcitag);
418 1.1 drochner #else
419 1.1 drochner console = 0;
420 1.1 drochner #endif
421 1.1 drochner if (console) {
422 1.1 drochner sc->sc_dc = &tga_console_dc;
423 1.1 drochner sc->nscreens = 1;
424 1.1 drochner } else {
425 1.1 drochner sc->sc_dc = (struct tga_devconfig *)
426 1.39 tsutsui malloc(sizeof(struct tga_devconfig), M_DEVBUF,
427 1.39 tsutsui M_WAITOK|M_ZERO);
428 1.34 elric tga_init(pa->pa_memt, pa->pa_pc, pa->pa_tag, sc->sc_dc);
429 1.1 drochner }
430 1.1 drochner if (sc->sc_dc->dc_vaddr == NULL) {
431 1.1 drochner printf(": couldn't map memory space; punt!\n");
432 1.1 drochner return;
433 1.1 drochner }
434 1.1 drochner
435 1.1 drochner /* XXX say what's going on. */
436 1.1 drochner intrstr = NULL;
437 1.30 sommerfe if (pci_intr_map(pa, &intrh)) {
438 1.17 elric printf(": couldn't map interrupt");
439 1.17 elric return;
440 1.17 elric }
441 1.17 elric intrstr = pci_intr_string(pa->pa_pc, intrh);
442 1.17 elric sc->sc_intr = pci_intr_establish(pa->pa_pc, intrh, IPL_TTY, tga_intr,
443 1.17 elric sc->sc_dc);
444 1.17 elric if (sc->sc_intr == NULL) {
445 1.17 elric printf(": couldn't establish interrupt");
446 1.17 elric if (intrstr != NULL)
447 1.17 elric printf("at %s", intrstr);
448 1.17 elric printf("\n");
449 1.17 elric return;
450 1.1 drochner }
451 1.1 drochner
452 1.1 drochner rev = PCI_REVISION(pa->pa_class);
453 1.1 drochner switch (rev) {
454 1.17 elric case 0x1:
455 1.17 elric case 0x2:
456 1.17 elric case 0x3:
457 1.17 elric printf(": DC21030 step %c", 'A' + rev - 1);
458 1.17 elric break;
459 1.17 elric case 0x20:
460 1.17 elric printf(": TGA2 abstract software model");
461 1.17 elric break;
462 1.19 elric case 0x21:
463 1.19 elric case 0x22:
464 1.17 elric printf(": TGA2 pass %d", rev - 0x20);
465 1.1 drochner break;
466 1.1 drochner
467 1.1 drochner default:
468 1.1 drochner printf("unknown stepping (0x%x)", rev);
469 1.1 drochner break;
470 1.1 drochner }
471 1.1 drochner printf(", ");
472 1.1 drochner
473 1.17 elric /*
474 1.17 elric * Get RAMDAC function vectors and call the RAMDAC functions
475 1.17 elric * to allocate its private storage and pass that back to us.
476 1.17 elric */
477 1.22 nathanw
478 1.22 nathanw sc->sc_dc->dc_ramdac_funcs = sc->sc_dc->dc_tgaconf->ramdac_funcs();
479 1.19 elric if (!sc->sc_dc->dc_tga2) {
480 1.22 nathanw if (sc->sc_dc->dc_tgaconf->ramdac_funcs == bt485_funcs)
481 1.22 nathanw sc->sc_dc->dc_ramdac_cookie =
482 1.22 nathanw sc->sc_dc->dc_ramdac_funcs->ramdac_register(sc->sc_dc,
483 1.22 nathanw tga_sched_update, tga_ramdac_wr, tga_ramdac_rd);
484 1.22 nathanw else
485 1.22 nathanw sc->sc_dc->dc_ramdac_cookie =
486 1.22 nathanw sc->sc_dc->dc_ramdac_funcs->ramdac_register(sc->sc_dc,
487 1.22 nathanw tga_sched_update, tga_bt463_wr, tga_bt463_rd);
488 1.17 elric } else {
489 1.22 nathanw sc->sc_dc->dc_ramdac_cookie =
490 1.22 nathanw sc->sc_dc->dc_ramdac_funcs->ramdac_register(sc->sc_dc,
491 1.22 nathanw tga_sched_update, tga2_ramdac_wr, tga2_ramdac_rd);
492 1.38 elric
493 1.38 elric /* XXX this is a bit of a hack, setting the dotclock here */
494 1.38 elric if (sc->sc_dc->dc_tgaconf->ramdac_funcs != bt485_funcs)
495 1.38 elric (*sc->sc_dc->dc_ramdac_funcs->ramdac_set_dotclock)
496 1.38 elric (sc->sc_dc->dc_ramdac_cookie,
497 1.38 elric tga_getdotclock(sc->sc_dc));
498 1.17 elric }
499 1.17 elric
500 1.17 elric /*
501 1.17 elric * Initialize the RAMDAC. Initialization includes disabling
502 1.38 elric * cursor, setting a sane colormap, etc. We presume that we've
503 1.38 elric * filled in the necessary dot clock for PowerStorm 4d20.
504 1.17 elric */
505 1.17 elric (*sc->sc_dc->dc_ramdac_funcs->ramdac_init)(sc->sc_dc->dc_ramdac_cookie);
506 1.21 nathanw TGAWREG(sc->sc_dc, TGA_REG_SISR, 0x00000001); /* XXX */
507 1.17 elric
508 1.1 drochner if (sc->sc_dc->dc_tgaconf == NULL) {
509 1.1 drochner printf("unknown board configuration\n");
510 1.1 drochner return;
511 1.1 drochner }
512 1.1 drochner printf("board type %s\n", sc->sc_dc->dc_tgaconf->tgac_name);
513 1.1 drochner printf("%s: %d x %d, %dbpp, %s RAMDAC\n", sc->sc_dev.dv_xname,
514 1.1 drochner sc->sc_dc->dc_wid, sc->sc_dc->dc_ht,
515 1.1 drochner sc->sc_dc->dc_tgaconf->tgac_phys_depth,
516 1.17 elric sc->sc_dc->dc_ramdac_funcs->ramdac_name);
517 1.1 drochner
518 1.1 drochner if (intrstr != NULL)
519 1.1 drochner printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
520 1.1 drochner intrstr);
521 1.1 drochner
522 1.1 drochner aa.console = console;
523 1.1 drochner aa.scrdata = &tga_screenlist;
524 1.1 drochner aa.accessops = &tga_accessops;
525 1.1 drochner aa.accesscookie = sc;
526 1.1 drochner
527 1.1 drochner config_found(self, &aa, wsemuldisplaydevprint);
528 1.22 nathanw
529 1.22 nathanw config_interrupts(self, tga_config_interrupts);
530 1.22 nathanw }
531 1.22 nathanw
532 1.22 nathanw static void
533 1.22 nathanw tga_config_interrupts (d)
534 1.22 nathanw struct device *d;
535 1.22 nathanw {
536 1.22 nathanw struct tga_softc *sc = (struct tga_softc *)d;
537 1.22 nathanw sc->sc_dc->dc_intrenabled = 1;
538 1.1 drochner }
539 1.1 drochner
540 1.1 drochner int
541 1.1 drochner tga_ioctl(v, cmd, data, flag, p)
542 1.1 drochner void *v;
543 1.1 drochner u_long cmd;
544 1.1 drochner caddr_t data;
545 1.1 drochner int flag;
546 1.1 drochner struct proc *p;
547 1.1 drochner {
548 1.1 drochner struct tga_softc *sc = v;
549 1.1 drochner struct tga_devconfig *dc = sc->sc_dc;
550 1.17 elric struct ramdac_funcs *dcrf = dc->dc_ramdac_funcs;
551 1.17 elric struct ramdac_cookie *dcrc = dc->dc_ramdac_cookie;
552 1.1 drochner
553 1.1 drochner switch (cmd) {
554 1.1 drochner case WSDISPLAYIO_GTYPE:
555 1.1 drochner *(u_int *)data = WSDISPLAY_TYPE_TGA;
556 1.1 drochner return (0);
557 1.1 drochner
558 1.1 drochner case WSDISPLAYIO_GINFO:
559 1.1 drochner #define wsd_fbip ((struct wsdisplay_fbinfo *)data)
560 1.1 drochner wsd_fbip->height = sc->sc_dc->dc_ht;
561 1.1 drochner wsd_fbip->width = sc->sc_dc->dc_wid;
562 1.1 drochner wsd_fbip->depth = sc->sc_dc->dc_tgaconf->tgac_phys_depth;
563 1.38 elric #if 0
564 1.1 drochner wsd_fbip->cmsize = 256; /* XXX ??? */
565 1.38 elric #else
566 1.38 elric wsd_fbip->cmsize = 1024; /* XXX ??? */
567 1.38 elric #endif
568 1.12 thorpej #undef wsd_fbip
569 1.1 drochner return (0);
570 1.1 drochner
571 1.1 drochner case WSDISPLAYIO_GETCMAP:
572 1.17 elric return (*dcrf->ramdac_get_cmap)(dcrc,
573 1.1 drochner (struct wsdisplay_cmap *)data);
574 1.1 drochner
575 1.1 drochner case WSDISPLAYIO_PUTCMAP:
576 1.17 elric return (*dcrf->ramdac_set_cmap)(dcrc,
577 1.1 drochner (struct wsdisplay_cmap *)data);
578 1.1 drochner
579 1.12 thorpej case WSDISPLAYIO_SVIDEO:
580 1.1 drochner if (*(u_int *)data == WSDISPLAYIO_VIDEO_OFF)
581 1.1 drochner tga_blank(sc->sc_dc);
582 1.1 drochner else
583 1.1 drochner tga_unblank(sc->sc_dc);
584 1.1 drochner return (0);
585 1.1 drochner
586 1.12 thorpej case WSDISPLAYIO_GVIDEO:
587 1.1 drochner *(u_int *)data = dc->dc_blanked ?
588 1.1 drochner WSDISPLAYIO_VIDEO_OFF : WSDISPLAYIO_VIDEO_ON;
589 1.1 drochner return (0);
590 1.1 drochner
591 1.1 drochner case WSDISPLAYIO_GCURPOS:
592 1.17 elric return (*dcrf->ramdac_get_curpos)(dcrc,
593 1.1 drochner (struct wsdisplay_curpos *)data);
594 1.1 drochner
595 1.1 drochner case WSDISPLAYIO_SCURPOS:
596 1.17 elric return (*dcrf->ramdac_set_curpos)(dcrc,
597 1.1 drochner (struct wsdisplay_curpos *)data);
598 1.1 drochner
599 1.1 drochner case WSDISPLAYIO_GCURMAX:
600 1.17 elric return (*dcrf->ramdac_get_curmax)(dcrc,
601 1.1 drochner (struct wsdisplay_curpos *)data);
602 1.1 drochner
603 1.1 drochner case WSDISPLAYIO_GCURSOR:
604 1.17 elric return (*dcrf->ramdac_get_cursor)(dcrc,
605 1.1 drochner (struct wsdisplay_cursor *)data);
606 1.1 drochner
607 1.1 drochner case WSDISPLAYIO_SCURSOR:
608 1.17 elric return (*dcrf->ramdac_set_cursor)(dcrc,
609 1.1 drochner (struct wsdisplay_cursor *)data);
610 1.1 drochner }
611 1.41 atatat return (EPASSTHROUGH);
612 1.1 drochner }
613 1.1 drochner
614 1.22 nathanw static int
615 1.17 elric tga_sched_update(v, f)
616 1.17 elric void *v;
617 1.17 elric void (*f) __P((void *));
618 1.17 elric {
619 1.17 elric struct tga_devconfig *dc = v;
620 1.17 elric
621 1.22 nathanw if (dc->dc_intrenabled) {
622 1.22 nathanw /* Arrange for f to be called at the next end-of-frame interrupt */
623 1.22 nathanw dc->dc_ramdac_intr = f;
624 1.22 nathanw TGAWREG(dc, TGA_REG_SISR, 0x00010000);
625 1.22 nathanw } else {
626 1.22 nathanw /* Spin until the end-of-frame, then call f */
627 1.22 nathanw TGAWREG(dc, TGA_REG_SISR, 0x00010001);
628 1.22 nathanw TGAREGWB(dc, TGA_REG_SISR, 1);
629 1.22 nathanw while ((TGARREG(dc, TGA_REG_SISR) & 0x00000001) == 0)
630 1.22 nathanw ;
631 1.22 nathanw f(dc->dc_ramdac_cookie);
632 1.22 nathanw TGAWREG(dc, TGA_REG_SISR, 0x00000001);
633 1.22 nathanw TGAREGWB(dc, TGA_REG_SISR, 1);
634 1.22 nathanw }
635 1.22 nathanw
636 1.17 elric return 0;
637 1.17 elric }
638 1.17 elric
639 1.22 nathanw static int
640 1.17 elric tga_intr(v)
641 1.17 elric void *v;
642 1.17 elric {
643 1.17 elric struct tga_devconfig *dc = v;
644 1.17 elric struct ramdac_cookie *dcrc= dc->dc_ramdac_cookie;
645 1.17 elric
646 1.22 nathanw u_int32_t reg;
647 1.22 nathanw
648 1.22 nathanw reg = TGARREG(dc, TGA_REG_SISR);
649 1.22 nathanw if (( reg & 0x00010001) != 0x00010001) {
650 1.22 nathanw /* Odd. We never set any of the other interrupt enables. */
651 1.22 nathanw if ((reg & 0x1f) != 0) {
652 1.22 nathanw /* Clear the mysterious pending interrupts. */
653 1.22 nathanw TGAWREG(dc, TGA_REG_SISR, (reg & 0x1f));
654 1.22 nathanw TGAREGWB(dc, TGA_REG_SISR, 1);
655 1.22 nathanw /* This was our interrupt, even if we're puzzled as to why
656 1.22 nathanw * we got it. Don't make the interrupt handler think it
657 1.22 nathanw * was a stray.
658 1.22 nathanw */
659 1.22 nathanw return -1;
660 1.22 nathanw } else {
661 1.22 nathanw return 0;
662 1.22 nathanw }
663 1.22 nathanw }
664 1.32 elric /* if we have something to do, do it */
665 1.32 elric if (dc->dc_ramdac_intr) {
666 1.32 elric dc->dc_ramdac_intr(dcrc);
667 1.32 elric dc->dc_ramdac_intr = NULL;
668 1.32 elric }
669 1.21 nathanw TGAWREG(dc, TGA_REG_SISR, 0x00000001);
670 1.22 nathanw TGAREGWB(dc, TGA_REG_SISR, 1);
671 1.17 elric return (1);
672 1.17 elric }
673 1.17 elric
674 1.26 simonb paddr_t
675 1.1 drochner tga_mmap(v, offset, prot)
676 1.1 drochner void *v;
677 1.1 drochner off_t offset;
678 1.1 drochner int prot;
679 1.1 drochner {
680 1.1 drochner struct tga_softc *sc = v;
681 1.1 drochner
682 1.10 mrg if (offset >= sc->sc_dc->dc_tgaconf->tgac_cspace_size || offset < 0)
683 1.1 drochner return -1;
684 1.24 soda
685 1.36 thorpej return (bus_space_mmap(sc->sc_dc->dc_memt, sc->sc_dc->dc_pcipaddr,
686 1.36 thorpej offset, prot, BUS_SPACE_MAP_LINEAR));
687 1.1 drochner }
688 1.1 drochner
689 1.22 nathanw static int
690 1.4 drochner tga_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
691 1.1 drochner void *v;
692 1.1 drochner const struct wsscreen_descr *type;
693 1.1 drochner void **cookiep;
694 1.1 drochner int *curxp, *curyp;
695 1.4 drochner long *attrp;
696 1.1 drochner {
697 1.1 drochner struct tga_softc *sc = v;
698 1.4 drochner long defattr;
699 1.1 drochner
700 1.1 drochner if (sc->nscreens > 0)
701 1.1 drochner return (ENOMEM);
702 1.1 drochner
703 1.23 nathanw *cookiep = &sc->sc_dc->dc_rinfo; /* one and only for now */
704 1.1 drochner *curxp = 0;
705 1.1 drochner *curyp = 0;
706 1.23 nathanw sc->sc_dc->dc_rinfo.ri_ops.alloc_attr(&sc->sc_dc->dc_rinfo,
707 1.23 nathanw 0, 0, 0, &defattr);
708 1.4 drochner *attrp = defattr;
709 1.2 drochner sc->nscreens++;
710 1.1 drochner return (0);
711 1.1 drochner }
712 1.1 drochner
713 1.22 nathanw static void
714 1.1 drochner tga_free_screen(v, cookie)
715 1.1 drochner void *v;
716 1.1 drochner void *cookie;
717 1.1 drochner {
718 1.1 drochner struct tga_softc *sc = v;
719 1.1 drochner
720 1.1 drochner if (sc->sc_dc == &tga_console_dc)
721 1.1 drochner panic("tga_free_screen: console");
722 1.1 drochner
723 1.1 drochner sc->nscreens--;
724 1.1 drochner }
725 1.1 drochner
726 1.22 nathanw static int
727 1.15 drochner tga_show_screen(v, cookie, waitok, cb, cbarg)
728 1.1 drochner void *v;
729 1.1 drochner void *cookie;
730 1.15 drochner int waitok;
731 1.15 drochner void (*cb) __P((void *, int, int));
732 1.15 drochner void *cbarg;
733 1.1 drochner {
734 1.15 drochner
735 1.15 drochner return (0);
736 1.1 drochner }
737 1.1 drochner
738 1.1 drochner int
739 1.1 drochner tga_cnattach(iot, memt, pc, bus, device, function)
740 1.1 drochner bus_space_tag_t iot, memt;
741 1.1 drochner pci_chipset_tag_t pc;
742 1.1 drochner int bus, device, function;
743 1.1 drochner {
744 1.1 drochner struct tga_devconfig *dcp = &tga_console_dc;
745 1.4 drochner long defattr;
746 1.1 drochner
747 1.34 elric tga_init(memt, pc, pci_make_tag(pc, bus, device, function), dcp);
748 1.1 drochner
749 1.1 drochner /* sanity checks */
750 1.1 drochner if (dcp->dc_vaddr == NULL)
751 1.1 drochner panic("tga_console(%d, %d): couldn't map memory space",
752 1.1 drochner device, function);
753 1.1 drochner if (dcp->dc_tgaconf == NULL)
754 1.1 drochner panic("tga_console(%d, %d): unknown board configuration",
755 1.1 drochner device, function);
756 1.1 drochner
757 1.1 drochner /*
758 1.1 drochner * Initialize the RAMDAC but DO NOT allocate any private storage.
759 1.1 drochner * Initialization includes disabling cursor, setting a sane
760 1.1 drochner * colormap, etc. It will be reinitialized in tgaattach().
761 1.1 drochner */
762 1.38 elric if (dcp->dc_tga2) {
763 1.38 elric if (dcp->dc_tgaconf->ramdac_funcs == bt485_funcs)
764 1.38 elric bt485_cninit(dcp, tga_sched_update, tga2_ramdac_wr,
765 1.38 elric tga2_ramdac_rd);
766 1.38 elric else
767 1.38 elric ibm561_cninit(dcp, tga_sched_update, tga2_ramdac_wr,
768 1.38 elric tga2_ramdac_rd, tga_getdotclock(dcp));
769 1.38 elric } else {
770 1.23 nathanw if (dcp->dc_tgaconf->ramdac_funcs == bt485_funcs)
771 1.23 nathanw bt485_cninit(dcp, tga_sched_update, tga_ramdac_wr,
772 1.23 nathanw tga_ramdac_rd);
773 1.23 nathanw else {
774 1.23 nathanw bt463_cninit(dcp, tga_sched_update, tga_bt463_wr,
775 1.23 nathanw tga_bt463_rd);
776 1.23 nathanw }
777 1.23 nathanw }
778 1.23 nathanw dcp->dc_rinfo.ri_ops.alloc_attr(&dcp->dc_rinfo, 0, 0, 0, &defattr);
779 1.23 nathanw wsdisplay_cnattach(&tga_stdscreen, &dcp->dc_rinfo, 0, 0, defattr);
780 1.23 nathanw
781 1.1 drochner return(0);
782 1.1 drochner }
783 1.1 drochner
784 1.1 drochner /*
785 1.1 drochner * Functions to blank and unblank the display.
786 1.1 drochner */
787 1.22 nathanw static void
788 1.1 drochner tga_blank(dc)
789 1.1 drochner struct tga_devconfig *dc;
790 1.1 drochner {
791 1.1 drochner
792 1.1 drochner if (!dc->dc_blanked) {
793 1.1 drochner dc->dc_blanked = 1;
794 1.21 nathanw /* XXX */
795 1.21 nathanw TGAWREG(dc, TGA_REG_VVVR, TGARREG(dc, TGA_REG_VVVR) | VVR_BLANK);
796 1.1 drochner }
797 1.1 drochner }
798 1.1 drochner
799 1.22 nathanw static void
800 1.1 drochner tga_unblank(dc)
801 1.1 drochner struct tga_devconfig *dc;
802 1.1 drochner {
803 1.1 drochner
804 1.1 drochner if (dc->dc_blanked) {
805 1.1 drochner dc->dc_blanked = 0;
806 1.21 nathanw /* XXX */
807 1.21 nathanw TGAWREG(dc, TGA_REG_VVVR, TGARREG(dc, TGA_REG_VVVR) & ~VVR_BLANK);
808 1.1 drochner }
809 1.1 drochner }
810 1.1 drochner
811 1.1 drochner /*
812 1.1 drochner * Functions to manipulate the built-in cursor handing hardware.
813 1.1 drochner */
814 1.1 drochner int
815 1.1 drochner tga_builtin_set_cursor(dc, cursorp)
816 1.1 drochner struct tga_devconfig *dc;
817 1.1 drochner struct wsdisplay_cursor *cursorp;
818 1.1 drochner {
819 1.17 elric struct ramdac_funcs *dcrf = dc->dc_ramdac_funcs;
820 1.17 elric struct ramdac_cookie *dcrc = dc->dc_ramdac_cookie;
821 1.35 jdolecek u_int count, v;
822 1.35 jdolecek int error;
823 1.1 drochner
824 1.1 drochner v = cursorp->which;
825 1.8 thorpej if (v & WSDISPLAY_CURSOR_DOCMAP) {
826 1.17 elric error = dcrf->ramdac_check_curcmap(dcrc, cursorp);
827 1.8 thorpej if (error)
828 1.8 thorpej return (error);
829 1.8 thorpej }
830 1.1 drochner if (v & WSDISPLAY_CURSOR_DOSHAPE) {
831 1.1 drochner if ((u_int)cursorp->size.x != 64 ||
832 1.1 drochner (u_int)cursorp->size.y > 64)
833 1.1 drochner return (EINVAL);
834 1.1 drochner /* The cursor is 2 bits deep, and there is no mask */
835 1.1 drochner count = (cursorp->size.y * 64 * 2) / NBBY;
836 1.8 thorpej if (!uvm_useracc(cursorp->image, count, B_READ))
837 1.8 thorpej return (EFAULT);
838 1.1 drochner }
839 1.1 drochner if (v & WSDISPLAY_CURSOR_DOHOT) /* not supported */
840 1.1 drochner return EINVAL;
841 1.1 drochner
842 1.1 drochner /* parameters are OK; do it */
843 1.1 drochner if (v & WSDISPLAY_CURSOR_DOCUR) {
844 1.1 drochner if (cursorp->enable)
845 1.21 nathanw /* XXX */
846 1.21 nathanw TGAWREG(dc, TGA_REG_VVVR, TGARREG(dc, TGA_REG_VVVR) | 0x04);
847 1.1 drochner else
848 1.21 nathanw /* XXX */
849 1.21 nathanw TGAWREG(dc, TGA_REG_VVVR, TGARREG(dc, TGA_REG_VVVR) & ~0x04);
850 1.1 drochner }
851 1.1 drochner if (v & WSDISPLAY_CURSOR_DOPOS) {
852 1.21 nathanw TGAWREG(dc, TGA_REG_CXYR,
853 1.21 nathanw ((cursorp->pos.y & 0xfff) << 12) | (cursorp->pos.x & 0xfff));
854 1.1 drochner }
855 1.1 drochner if (v & WSDISPLAY_CURSOR_DOCMAP) {
856 1.8 thorpej /* can't fail. */
857 1.17 elric dcrf->ramdac_set_curcmap(dcrc, cursorp);
858 1.1 drochner }
859 1.1 drochner if (v & WSDISPLAY_CURSOR_DOSHAPE) {
860 1.8 thorpej count = ((64 * 2) / NBBY) * cursorp->size.y;
861 1.21 nathanw TGAWREG(dc, TGA_REG_CCBR,
862 1.21 nathanw (TGARREG(dc, TGA_REG_CCBR) & ~0xfc00) | (cursorp->size.y << 10));
863 1.1 drochner copyin(cursorp->image, (char *)(dc->dc_vaddr +
864 1.21 nathanw (TGARREG(dc, TGA_REG_CCBR) & 0x3ff)),
865 1.1 drochner count); /* can't fail. */
866 1.1 drochner }
867 1.1 drochner return (0);
868 1.1 drochner }
869 1.1 drochner
870 1.1 drochner int
871 1.1 drochner tga_builtin_get_cursor(dc, cursorp)
872 1.1 drochner struct tga_devconfig *dc;
873 1.1 drochner struct wsdisplay_cursor *cursorp;
874 1.1 drochner {
875 1.17 elric struct ramdac_funcs *dcrf = dc->dc_ramdac_funcs;
876 1.17 elric struct ramdac_cookie *dcrc = dc->dc_ramdac_cookie;
877 1.1 drochner int count, error;
878 1.1 drochner
879 1.1 drochner cursorp->which = WSDISPLAY_CURSOR_DOALL &
880 1.1 drochner ~(WSDISPLAY_CURSOR_DOHOT | WSDISPLAY_CURSOR_DOCMAP);
881 1.21 nathanw cursorp->enable = (TGARREG(dc, TGA_REG_VVVR) & 0x04) != 0;
882 1.21 nathanw cursorp->pos.x = TGARREG(dc, TGA_REG_CXYR) & 0xfff;
883 1.21 nathanw cursorp->pos.y = (TGARREG(dc, TGA_REG_CXYR) >> 12) & 0xfff;
884 1.1 drochner cursorp->size.x = 64;
885 1.21 nathanw cursorp->size.y = (TGARREG(dc, TGA_REG_CCBR) >> 10) & 0x3f;
886 1.1 drochner
887 1.1 drochner if (cursorp->image != NULL) {
888 1.1 drochner count = (cursorp->size.y * 64 * 2) / NBBY;
889 1.1 drochner error = copyout((char *)(dc->dc_vaddr +
890 1.21 nathanw (TGARREG(dc, TGA_REG_CCBR) & 0x3ff)),
891 1.1 drochner cursorp->image, count);
892 1.1 drochner if (error)
893 1.1 drochner return (error);
894 1.1 drochner /* No mask */
895 1.1 drochner }
896 1.17 elric error = dcrf->ramdac_get_curcmap(dcrc, cursorp);
897 1.8 thorpej return (error);
898 1.1 drochner }
899 1.1 drochner
900 1.1 drochner int
901 1.1 drochner tga_builtin_set_curpos(dc, curposp)
902 1.1 drochner struct tga_devconfig *dc;
903 1.1 drochner struct wsdisplay_curpos *curposp;
904 1.1 drochner {
905 1.1 drochner
906 1.21 nathanw TGAWREG(dc, TGA_REG_CXYR,
907 1.21 nathanw ((curposp->y & 0xfff) << 12) | (curposp->x & 0xfff));
908 1.1 drochner return (0);
909 1.1 drochner }
910 1.1 drochner
911 1.1 drochner int
912 1.1 drochner tga_builtin_get_curpos(dc, curposp)
913 1.1 drochner struct tga_devconfig *dc;
914 1.1 drochner struct wsdisplay_curpos *curposp;
915 1.1 drochner {
916 1.1 drochner
917 1.21 nathanw curposp->x = TGARREG(dc, TGA_REG_CXYR) & 0xfff;
918 1.21 nathanw curposp->y = (TGARREG(dc, TGA_REG_CXYR) >> 12) & 0xfff;
919 1.1 drochner return (0);
920 1.1 drochner }
921 1.1 drochner
922 1.1 drochner int
923 1.1 drochner tga_builtin_get_curmax(dc, curposp)
924 1.1 drochner struct tga_devconfig *dc;
925 1.1 drochner struct wsdisplay_curpos *curposp;
926 1.1 drochner {
927 1.1 drochner
928 1.1 drochner curposp->x = curposp->y = 64;
929 1.1 drochner return (0);
930 1.14 ross }
931 1.14 ross
932 1.14 ross /*
933 1.14 ross * Copy columns (characters) in a row (line).
934 1.14 ross */
935 1.22 nathanw static void
936 1.14 ross tga_copycols(id, row, srccol, dstcol, ncols)
937 1.14 ross void *id;
938 1.14 ross int row, srccol, dstcol, ncols;
939 1.14 ross {
940 1.23 nathanw struct rasops_info *ri = id;
941 1.14 ross int y, srcx, dstx, nx;
942 1.14 ross
943 1.23 nathanw y = ri->ri_font->fontheight * row;
944 1.23 nathanw srcx = ri->ri_font->fontwidth * srccol;
945 1.23 nathanw dstx = ri->ri_font->fontwidth * dstcol;
946 1.23 nathanw nx = ri->ri_font->fontwidth * ncols;
947 1.23 nathanw
948 1.23 nathanw tga_rop(ri, dstx, y,
949 1.23 nathanw nx, ri->ri_font->fontheight, RAS_SRC,
950 1.23 nathanw ri, srcx, y);
951 1.14 ross }
952 1.14 ross
953 1.14 ross /*
954 1.14 ross * Copy rows (lines).
955 1.14 ross */
956 1.22 nathanw static void
957 1.14 ross tga_copyrows(id, srcrow, dstrow, nrows)
958 1.14 ross void *id;
959 1.14 ross int srcrow, dstrow, nrows;
960 1.14 ross {
961 1.23 nathanw struct rasops_info *ri = id;
962 1.14 ross int srcy, dsty, ny;
963 1.14 ross
964 1.23 nathanw srcy = ri->ri_font->fontheight * srcrow;
965 1.23 nathanw dsty = ri->ri_font->fontheight * dstrow;
966 1.23 nathanw ny = ri->ri_font->fontheight * nrows;
967 1.23 nathanw
968 1.23 nathanw tga_rop(ri, 0, dsty,
969 1.23 nathanw ri->ri_emuwidth, ny, RAS_SRC,
970 1.23 nathanw ri, 0, srcy);
971 1.14 ross }
972 1.14 ross
973 1.14 ross /* Do we need the src? */
974 1.14 ross static int needsrc[16] = { 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0 };
975 1.14 ross
976 1.14 ross /* A mapping between our API and the TGA card */
977 1.14 ross static int map_rop[16] = { 0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6,
978 1.14 ross 0xe, 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf
979 1.14 ross };
980 1.14 ross
981 1.14 ross /*
982 1.14 ross * Generic TGA raster op.
983 1.14 ross * This covers all possible raster ops, and
984 1.14 ross * clips the sizes and all of that.
985 1.14 ross */
986 1.14 ross static int
987 1.14 ross tga_rop(dst, dx, dy, w, h, rop, src, sx, sy)
988 1.23 nathanw struct rasops_info *dst;
989 1.14 ross int dx, dy, w, h, rop;
990 1.23 nathanw struct rasops_info *src;
991 1.14 ross int sx, sy;
992 1.14 ross {
993 1.14 ross if (!dst)
994 1.14 ross return -1;
995 1.14 ross if (needsrc[RAS_GETOP(rop)]) {
996 1.23 nathanw if (src == NULL)
997 1.14 ross return -1; /* We want a src */
998 1.14 ross /* Clip against src */
999 1.14 ross if (sx < 0) {
1000 1.14 ross w += sx;
1001 1.14 ross sx = 0;
1002 1.14 ross }
1003 1.14 ross if (sy < 0) {
1004 1.14 ross h += sy;
1005 1.14 ross sy = 0;
1006 1.14 ross }
1007 1.23 nathanw if (sx + w > src->ri_emuwidth)
1008 1.23 nathanw w = src->ri_emuwidth - sx;
1009 1.23 nathanw if (sy + h > src->ri_emuheight)
1010 1.23 nathanw h = src->ri_emuheight - sy;
1011 1.14 ross } else {
1012 1.23 nathanw if (src != NULL)
1013 1.14 ross return -1; /* We need no src */
1014 1.14 ross }
1015 1.14 ross /* Clip against dst. We modify src regardless of using it,
1016 1.14 ross * since it really doesn't matter.
1017 1.14 ross */
1018 1.14 ross if (dx < 0) {
1019 1.14 ross w += dx;
1020 1.14 ross sx -= dx;
1021 1.14 ross dx = 0;
1022 1.14 ross }
1023 1.14 ross if (dy < 0) {
1024 1.14 ross h += dy;
1025 1.14 ross sy -= dy;
1026 1.14 ross dy = 0;
1027 1.14 ross }
1028 1.23 nathanw if (dx + w > dst->ri_emuwidth)
1029 1.23 nathanw w = dst->ri_emuwidth - dx;
1030 1.23 nathanw if (dy + h > dst->ri_emuheight)
1031 1.23 nathanw h = dst->ri_emuheight - dy;
1032 1.14 ross if (w <= 0 || h <= 0)
1033 1.14 ross return 0; /* Vacuously true; */
1034 1.23 nathanw if (!src) {
1035 1.23 nathanw /* XXX Punt! */
1036 1.23 nathanw return -1;
1037 1.23 nathanw }
1038 1.23 nathanw return tga_rop_vtov(dst, dx, dy, w, h, rop, src, sx, sy);
1039 1.14 ross }
1040 1.14 ross
1041 1.14 ross
1042 1.14 ross
1043 1.14 ross /*
1044 1.14 ross * Video to Video raster ops.
1045 1.14 ross * This function deals with all raster ops that have a src and dst
1046 1.14 ross * that are on the card.
1047 1.14 ross */
1048 1.14 ross static int
1049 1.14 ross tga_rop_vtov(dst, dx, dy, w, h, rop, src, sx, sy)
1050 1.23 nathanw struct rasops_info *dst;
1051 1.14 ross int dx, dy, w, h, rop;
1052 1.23 nathanw struct rasops_info *src;
1053 1.14 ross int sx, sy;
1054 1.14 ross {
1055 1.23 nathanw struct tga_devconfig *dc = (struct tga_devconfig *)dst->ri_hw;
1056 1.31 nathanw int srcb, dstb, tga_srcb, tga_dstb;
1057 1.31 nathanw int x, y, wb;
1058 1.31 nathanw int xstart, xend, xdir;
1059 1.14 ross int ystart, yend, ydir, yinc;
1060 1.31 nathanw int xleft, lastx, lastleft;
1061 1.14 ross int offset = 1 * dc->dc_tgaconf->tgac_vvbr_units;
1062 1.14 ross
1063 1.14 ross /*
1064 1.14 ross * I don't yet want to deal with unaligned guys, really. And we don't
1065 1.14 ross * deal with copies from one card to another.
1066 1.14 ross */
1067 1.23 nathanw if (dx % 8 != 0 || sx % 8 != 0 || src != dst) {
1068 1.23 nathanw /* XXX Punt! */
1069 1.23 nathanw /* XXX should never happen, since it's only being used to
1070 1.23 nathanw * XXX copy 8-pixel-wide characters.
1071 1.23 nathanw */
1072 1.23 nathanw return -1;
1073 1.23 nathanw }
1074 1.14 ross
1075 1.31 nathanw wb = w * (dst->ri_depth / 8);
1076 1.14 ross if (sy >= dy) {
1077 1.14 ross ystart = 0;
1078 1.14 ross yend = h;
1079 1.14 ross ydir = 1;
1080 1.14 ross } else {
1081 1.14 ross ystart = h;
1082 1.14 ross yend = 0;
1083 1.14 ross ydir = -1;
1084 1.14 ross }
1085 1.31 nathanw if (sx >= dx) { /* moving to the left */
1086 1.14 ross xstart = 0;
1087 1.31 nathanw xend = w * (dst->ri_depth / 8) - 4;
1088 1.14 ross xdir = 1;
1089 1.31 nathanw } else { /* moving to the right */
1090 1.31 nathanw xstart = wb - ( wb >= 4*64 ? 4*64 : wb >= 64 ? 64 : 4 );
1091 1.14 ross xend = 0;
1092 1.14 ross xdir = -1;
1093 1.14 ross }
1094 1.31 nathanw #define XINC4 4
1095 1.31 nathanw #define XINC64 64
1096 1.31 nathanw #define XINC256 (64*4)
1097 1.23 nathanw yinc = ydir * dst->ri_stride;
1098 1.23 nathanw ystart *= dst->ri_stride;
1099 1.23 nathanw yend *= dst->ri_stride;
1100 1.31 nathanw
1101 1.31 nathanw srcb = sy * src->ri_stride + sx * (src->ri_depth/8);
1102 1.31 nathanw dstb = dy * dst->ri_stride + dx * (dst->ri_depth/8);
1103 1.31 nathanw tga_srcb = offset + (sy + src->ri_yorigin) * src->ri_stride +
1104 1.31 nathanw (sx + src->ri_xorigin) * (src->ri_depth/8);
1105 1.31 nathanw tga_dstb = offset + (dy + dst->ri_yorigin) * dst->ri_stride +
1106 1.31 nathanw (dx + dst->ri_xorigin) * (dst->ri_depth/8);
1107 1.31 nathanw
1108 1.21 nathanw TGAWALREG(dc, TGA_REG_GMOR, 3, 0x0007); /* Copy mode */
1109 1.31 nathanw TGAWALREG(dc, TGA_REG_GOPR, 3, map_rop[rop]); /* Set up the op */
1110 1.31 nathanw
1111 1.31 nathanw /*
1112 1.31 nathanw * we have 3 sizes of pixels to move in X direction:
1113 1.31 nathanw * 4 * 64 (unrolled TGA ops)
1114 1.31 nathanw * 64 (single TGA op)
1115 1.31 nathanw * 4 (CPU, using long word)
1116 1.31 nathanw */
1117 1.31 nathanw
1118 1.31 nathanw if (xdir == 1) { /* move to the left */
1119 1.31 nathanw
1120 1.31 nathanw for (y = ystart; (ydir * y) <= (ydir * yend); y += yinc) {
1121 1.31 nathanw
1122 1.31 nathanw /* 4*64 byte chunks */
1123 1.31 nathanw for (xleft = wb, x = xstart;
1124 1.31 nathanw x <= xend && xleft >= 4*64;
1125 1.31 nathanw x += XINC256, xleft -= XINC256) {
1126 1.31 nathanw
1127 1.31 nathanw /* XXX XXX Eight writes to different addresses should fill
1128 1.31 nathanw * XXX XXX up the write buffers on 21064 and 21164 chips,
1129 1.31 nathanw * XXX XXX but later CPUs might have larger write buffers which
1130 1.31 nathanw * XXX XXX require further unrolling of this loop, or the
1131 1.31 nathanw * XXX XXX insertion of memory barriers.
1132 1.31 nathanw */
1133 1.31 nathanw TGAWALREG(dc, TGA_REG_GCSR, 0, tga_srcb + y + x + 0 * 64);
1134 1.31 nathanw TGAWALREG(dc, TGA_REG_GCDR, 0, tga_dstb + y + x + 0 * 64);
1135 1.31 nathanw TGAWALREG(dc, TGA_REG_GCSR, 1, tga_srcb + y + x + 1 * 64);
1136 1.31 nathanw TGAWALREG(dc, TGA_REG_GCDR, 1, tga_dstb + y + x + 1 * 64);
1137 1.31 nathanw TGAWALREG(dc, TGA_REG_GCSR, 2, tga_srcb + y + x + 2 * 64);
1138 1.31 nathanw TGAWALREG(dc, TGA_REG_GCDR, 2, tga_dstb + y + x + 2 * 64);
1139 1.31 nathanw TGAWALREG(dc, TGA_REG_GCSR, 3, tga_srcb + y + x + 3 * 64);
1140 1.31 nathanw TGAWALREG(dc, TGA_REG_GCDR, 3, tga_dstb + y + x + 3 * 64);
1141 1.31 nathanw }
1142 1.31 nathanw
1143 1.31 nathanw /* 64 byte chunks */
1144 1.31 nathanw for ( ; x <= xend && xleft >= 64;
1145 1.31 nathanw x += XINC64, xleft -= XINC64) {
1146 1.31 nathanw TGAWALREG(dc, TGA_REG_GCSR, 0, tga_srcb + y + x + 0 * 64);
1147 1.31 nathanw TGAWALREG(dc, TGA_REG_GCDR, 0, tga_dstb + y + x + 0 * 64);
1148 1.31 nathanw }
1149 1.31 nathanw lastx = x; lastleft = xleft; /* remember for CPU loop */
1150 1.31 nathanw
1151 1.31 nathanw }
1152 1.31 nathanw TGAWALREG(dc, TGA_REG_GOPR, 0, 0x0003); /* op -> dst = src */
1153 1.31 nathanw TGAWALREG(dc, TGA_REG_GMOR, 0, 0x0000); /* Simple mode */
1154 1.31 nathanw
1155 1.31 nathanw for (y = ystart; (ydir * y) <= (ydir * yend); y += yinc) {
1156 1.31 nathanw /* 4 byte granularity */
1157 1.31 nathanw for (x = lastx, xleft = lastleft;
1158 1.31 nathanw x <= xend && xleft >= 4;
1159 1.31 nathanw x += XINC4, xleft -= XINC4) {
1160 1.31 nathanw *(uint32_t *)(dst->ri_bits + dstb + y + x) =
1161 1.31 nathanw *(uint32_t *)(dst->ri_bits + srcb + y + x);
1162 1.31 nathanw }
1163 1.31 nathanw }
1164 1.31 nathanw }
1165 1.31 nathanw else { /* above move to the left, below move to the right */
1166 1.31 nathanw
1167 1.31 nathanw for (y = ystart; (ydir * y) <= (ydir * yend); y += yinc) {
1168 1.31 nathanw
1169 1.31 nathanw /* 4*64 byte chunks */
1170 1.31 nathanw for (xleft = wb, x = xstart;
1171 1.31 nathanw x >= xend && xleft >= 4*64;
1172 1.31 nathanw x -= XINC256, xleft -= XINC256) {
1173 1.31 nathanw
1174 1.31 nathanw /* XXX XXX Eight writes to different addresses should fill
1175 1.31 nathanw * XXX XXX up the write buffers on 21064 and 21164 chips,
1176 1.31 nathanw * XXX XXX but later CPUs might have larger write buffers which
1177 1.31 nathanw * XXX XXX require further unrolling of this loop, or the
1178 1.31 nathanw * XXX XXX insertion of memory barriers.
1179 1.31 nathanw */
1180 1.31 nathanw TGAWALREG(dc, TGA_REG_GCSR, 0, tga_srcb + y + x + 3 * 64);
1181 1.31 nathanw TGAWALREG(dc, TGA_REG_GCDR, 0, tga_dstb + y + x + 3 * 64);
1182 1.31 nathanw TGAWALREG(dc, TGA_REG_GCSR, 1, tga_srcb + y + x + 2 * 64);
1183 1.31 nathanw TGAWALREG(dc, TGA_REG_GCDR, 1, tga_dstb + y + x + 2 * 64);
1184 1.31 nathanw TGAWALREG(dc, TGA_REG_GCSR, 2, tga_srcb + y + x + 1 * 64);
1185 1.31 nathanw TGAWALREG(dc, TGA_REG_GCDR, 2, tga_dstb + y + x + 1 * 64);
1186 1.31 nathanw TGAWALREG(dc, TGA_REG_GCSR, 3, tga_srcb + y + x + 0 * 64);
1187 1.31 nathanw TGAWALREG(dc, TGA_REG_GCDR, 3, tga_dstb + y + x + 0 * 64);
1188 1.31 nathanw }
1189 1.31 nathanw
1190 1.31 nathanw if (xleft) x += XINC256 - XINC64;
1191 1.31 nathanw
1192 1.31 nathanw /* 64 byte chunks */
1193 1.31 nathanw for ( ; x >= xend && xleft >= 64;
1194 1.31 nathanw x -= XINC64, xleft -= XINC64) {
1195 1.31 nathanw TGAWALREG(dc, TGA_REG_GCSR, 0, tga_srcb + y + x + 0 * 64);
1196 1.31 nathanw TGAWALREG(dc, TGA_REG_GCDR, 0, tga_dstb + y + x + 0 * 64);
1197 1.31 nathanw }
1198 1.31 nathanw if (xleft) x += XINC64 - XINC4;
1199 1.31 nathanw lastx = x; lastleft = xleft; /* remember for CPU loop */
1200 1.31 nathanw }
1201 1.31 nathanw TGAWALREG(dc, TGA_REG_GOPR, 0, 0x0003); /* op -> dst = src */
1202 1.31 nathanw TGAWALREG(dc, TGA_REG_GMOR, 0, 0x0000); /* Simple mode */
1203 1.31 nathanw
1204 1.31 nathanw for (y = ystart; (ydir * y) <= (ydir * yend); y += yinc) {
1205 1.31 nathanw /* 4 byte granularity */
1206 1.31 nathanw for (x = lastx, xleft = lastleft;
1207 1.31 nathanw x >= xend && xleft >= 4;
1208 1.31 nathanw x -= XINC4, xleft -= XINC4) {
1209 1.31 nathanw *(uint32_t *)(dst->ri_bits + dstb + y + x) =
1210 1.31 nathanw *(uint32_t *)(dst->ri_bits + srcb + y + x);
1211 1.31 nathanw }
1212 1.14 ross }
1213 1.14 ross }
1214 1.14 ross return 0;
1215 1.17 elric }
1216 1.23 nathanw
1217 1.23 nathanw
1218 1.23 nathanw void tga_putchar (c, row, col, uc, attr)
1219 1.23 nathanw void *c;
1220 1.23 nathanw int row, col;
1221 1.23 nathanw u_int uc;
1222 1.23 nathanw long attr;
1223 1.23 nathanw {
1224 1.23 nathanw struct rasops_info *ri = c;
1225 1.23 nathanw struct tga_devconfig *dc = ri->ri_hw;
1226 1.23 nathanw int fs, height, width;
1227 1.23 nathanw u_char *fr;
1228 1.23 nathanw int32_t *rp;
1229 1.23 nathanw
1230 1.23 nathanw rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
1231 1.23 nathanw
1232 1.23 nathanw height = ri->ri_font->fontheight;
1233 1.23 nathanw width = ri->ri_font->fontwidth;
1234 1.23 nathanw
1235 1.23 nathanw uc -= ri->ri_font->firstchar;
1236 1.23 nathanw fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
1237 1.23 nathanw fs = ri->ri_font->stride;
1238 1.23 nathanw
1239 1.23 nathanw /* Set foreground and background color. XXX memoize this somehow?
1240 1.23 nathanw * The rasops code has already expanded the color entry to 32 bits
1241 1.23 nathanw * for us, even for 8-bit displays, so we don't have to do anything.
1242 1.23 nathanw */
1243 1.23 nathanw TGAWREG(dc, TGA_REG_GFGR, ri->ri_devcmap[(attr >> 24) & 15]);
1244 1.23 nathanw TGAWREG(dc, TGA_REG_GBGR, ri->ri_devcmap[(attr >> 16) & 15]);
1245 1.23 nathanw
1246 1.23 nathanw /* Set raster operation to "copy"... */
1247 1.23 nathanw if (ri->ri_depth == 8)
1248 1.23 nathanw TGAWREG(dc, TGA_REG_GOPR, 0x3);
1249 1.23 nathanw else /* ... and in 24-bit mode, set the destination bitmap to 24-bit. */
1250 1.23 nathanw TGAWREG(dc, TGA_REG_GOPR, 0x3 | (0x3 << 8));
1251 1.23 nathanw
1252 1.23 nathanw /* Set which pixels we're drawing (of a possible 32). */
1253 1.23 nathanw TGAWREG(dc, TGA_REG_GPXR_P, (1 << width) - 1);
1254 1.23 nathanw
1255 1.23 nathanw /* Set drawing mode to opaque stipple. */
1256 1.23 nathanw TGAWREG(dc, TGA_REG_GMOR, 0x1);
1257 1.23 nathanw
1258 1.23 nathanw /* Insert write barrier before actually sending data */
1259 1.23 nathanw /* XXX Abuses the fact that there is only one write barrier on Alphas */
1260 1.23 nathanw TGAREGWB(dc, TGA_REG_GMOR, 1);
1261 1.23 nathanw
1262 1.23 nathanw while(height--) {
1263 1.23 nathanw /* The actual stipple write */
1264 1.23 nathanw *rp = fr[0] | (fr[1] << 8) | (fr[2] << 16) | (fr[3] << 24);
1265 1.23 nathanw
1266 1.23 nathanw fr += fs;
1267 1.23 nathanw rp = (int32_t *)((caddr_t)rp + ri->ri_stride);
1268 1.23 nathanw }
1269 1.23 nathanw
1270 1.23 nathanw /* Do underline */
1271 1.23 nathanw if ((attr & 1) != 0) {
1272 1.23 nathanw rp = (int32_t *)((caddr_t)rp - (ri->ri_stride << 1));
1273 1.23 nathanw *rp = 0xffffffff;
1274 1.23 nathanw }
1275 1.23 nathanw
1276 1.23 nathanw /* Set grapics mode back to normal. */
1277 1.23 nathanw TGAWREG(dc, TGA_REG_GMOR, 0);
1278 1.23 nathanw TGAWREG(dc, TGA_REG_GPXR_P, 0xffffffff);
1279 1.23 nathanw
1280 1.23 nathanw }
1281 1.23 nathanw
1282 1.23 nathanw static void
1283 1.23 nathanw tga_eraserows(c, row, num, attr)
1284 1.23 nathanw void *c;
1285 1.23 nathanw int row, num;
1286 1.23 nathanw long attr;
1287 1.23 nathanw {
1288 1.23 nathanw struct rasops_info *ri = c;
1289 1.23 nathanw struct tga_devconfig *dc = ri->ri_hw;
1290 1.23 nathanw int32_t color, lines, pixels;
1291 1.23 nathanw int32_t *rp;
1292 1.23 nathanw
1293 1.23 nathanw color = ri->ri_devcmap[(attr >> 16) & 15];
1294 1.23 nathanw rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale);
1295 1.23 nathanw lines = num * ri->ri_font->fontheight;
1296 1.23 nathanw pixels = ri->ri_emuwidth - 1;
1297 1.23 nathanw
1298 1.23 nathanw /* Set fill color in block-color registers */
1299 1.23 nathanw TGAWREG(dc, TGA_REG_GBCR0, color);
1300 1.23 nathanw TGAWREG(dc, TGA_REG_GBCR1, color);
1301 1.23 nathanw if (ri->ri_depth != 8) {
1302 1.23 nathanw TGAWREG(dc, TGA_REG_GBCR2, color);
1303 1.23 nathanw TGAWREG(dc, TGA_REG_GBCR3, color);
1304 1.23 nathanw TGAWREG(dc, TGA_REG_GBCR4, color);
1305 1.23 nathanw TGAWREG(dc, TGA_REG_GBCR5, color);
1306 1.23 nathanw TGAWREG(dc, TGA_REG_GBCR6, color);
1307 1.23 nathanw TGAWREG(dc, TGA_REG_GBCR7, color);
1308 1.23 nathanw }
1309 1.23 nathanw
1310 1.23 nathanw /* Set raster operation to "copy"... */
1311 1.23 nathanw if (ri->ri_depth == 8)
1312 1.23 nathanw TGAWREG(dc, TGA_REG_GOPR, 0x3);
1313 1.23 nathanw else /* ... and in 24-bit mode, set the destination bitmap to 24-bit. */
1314 1.23 nathanw TGAWREG(dc, TGA_REG_GOPR, 0x3 | (0x3 << 8));
1315 1.23 nathanw
1316 1.23 nathanw /* Set which pixels we're drawing (of a possible 32). */
1317 1.23 nathanw TGAWREG(dc, TGA_REG_GDAR, 0xffffffff);
1318 1.23 nathanw
1319 1.23 nathanw /* Set drawing mode to block fill. */
1320 1.23 nathanw TGAWREG(dc, TGA_REG_GMOR, 0x2d);
1321 1.23 nathanw
1322 1.23 nathanw /* Insert write barrier before actually sending data */
1323 1.23 nathanw /* XXX Abuses the fact that there is only one write barrier on Alphas */
1324 1.23 nathanw TGAREGWB(dc, TGA_REG_GMOR, 1);
1325 1.23 nathanw
1326 1.23 nathanw while (lines--) {
1327 1.23 nathanw *rp = pixels;
1328 1.23 nathanw rp = (int32_t *)((caddr_t)rp + ri->ri_stride);
1329 1.23 nathanw }
1330 1.23 nathanw
1331 1.23 nathanw /* Set grapics mode back to normal. */
1332 1.23 nathanw TGAWREG(dc, TGA_REG_GMOR, 0);
1333 1.23 nathanw
1334 1.23 nathanw }
1335 1.23 nathanw
1336 1.23 nathanw static void
1337 1.23 nathanw tga_erasecols (c, row, col, num, attr)
1338 1.23 nathanw void *c;
1339 1.23 nathanw int row, col, num;
1340 1.23 nathanw long attr;
1341 1.23 nathanw {
1342 1.23 nathanw struct rasops_info *ri = c;
1343 1.23 nathanw struct tga_devconfig *dc = ri->ri_hw;
1344 1.23 nathanw int32_t color, lines, pixels;
1345 1.23 nathanw int32_t *rp;
1346 1.23 nathanw
1347 1.23 nathanw color = ri->ri_devcmap[(attr >> 16) & 15];
1348 1.23 nathanw rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
1349 1.23 nathanw lines = ri->ri_font->fontheight;
1350 1.23 nathanw pixels = (num * ri->ri_font->fontwidth) - 1;
1351 1.23 nathanw
1352 1.23 nathanw /* Set fill color in block-color registers */
1353 1.23 nathanw TGAWREG(dc, TGA_REG_GBCR0, color);
1354 1.23 nathanw TGAWREG(dc, TGA_REG_GBCR1, color);
1355 1.23 nathanw if (ri->ri_depth != 8) {
1356 1.23 nathanw TGAWREG(dc, TGA_REG_GBCR2, color);
1357 1.23 nathanw TGAWREG(dc, TGA_REG_GBCR3, color);
1358 1.23 nathanw TGAWREG(dc, TGA_REG_GBCR4, color);
1359 1.23 nathanw TGAWREG(dc, TGA_REG_GBCR5, color);
1360 1.23 nathanw TGAWREG(dc, TGA_REG_GBCR6, color);
1361 1.23 nathanw TGAWREG(dc, TGA_REG_GBCR7, color);
1362 1.23 nathanw }
1363 1.23 nathanw
1364 1.23 nathanw /* Set raster operation to "copy"... */
1365 1.23 nathanw if (ri->ri_depth == 8)
1366 1.23 nathanw TGAWREG(dc, TGA_REG_GOPR, 0x3);
1367 1.23 nathanw else /* ... and in 24-bit mode, set the destination bitmap to 24-bit. */
1368 1.23 nathanw TGAWREG(dc, TGA_REG_GOPR, 0x3 | (0x3 << 8));
1369 1.23 nathanw
1370 1.23 nathanw /* Set which pixels we're drawing (of a possible 32). */
1371 1.23 nathanw TGAWREG(dc, TGA_REG_GDAR, 0xffffffff);
1372 1.23 nathanw
1373 1.23 nathanw /* Set drawing mode to block fill. */
1374 1.23 nathanw TGAWREG(dc, TGA_REG_GMOR, 0x2d);
1375 1.23 nathanw
1376 1.23 nathanw /* Insert write barrier before actually sending data */
1377 1.23 nathanw /* XXX Abuses the fact that there is only one write barrier on Alphas */
1378 1.23 nathanw TGAREGWB(dc, TGA_REG_GMOR, 1);
1379 1.23 nathanw
1380 1.23 nathanw while (lines--) {
1381 1.23 nathanw *rp = pixels;
1382 1.23 nathanw rp = (int32_t *)((caddr_t)rp + ri->ri_stride);
1383 1.23 nathanw }
1384 1.23 nathanw
1385 1.23 nathanw /* Set grapics mode back to normal. */
1386 1.23 nathanw TGAWREG(dc, TGA_REG_GMOR, 0);
1387 1.23 nathanw }
1388 1.23 nathanw
1389 1.17 elric
1390 1.22 nathanw static void
1391 1.17 elric tga_ramdac_wr(v, btreg, val)
1392 1.17 elric void *v;
1393 1.17 elric u_int btreg;
1394 1.17 elric u_int8_t val;
1395 1.17 elric {
1396 1.17 elric struct tga_devconfig *dc = v;
1397 1.17 elric
1398 1.17 elric if (btreg > BT485_REG_MAX)
1399 1.17 elric panic("tga_ramdac_wr: reg %d out of range\n", btreg);
1400 1.17 elric
1401 1.21 nathanw TGAWREG(dc, TGA_REG_EPDR, (btreg << 9) | (0 << 8 ) | val); /* XXX */
1402 1.21 nathanw TGAREGWB(dc, TGA_REG_EPDR, 1);
1403 1.17 elric }
1404 1.17 elric
1405 1.22 nathanw static void
1406 1.17 elric tga2_ramdac_wr(v, btreg, val)
1407 1.17 elric void *v;
1408 1.17 elric u_int btreg;
1409 1.17 elric u_int8_t val;
1410 1.17 elric {
1411 1.17 elric struct tga_devconfig *dc = v;
1412 1.21 nathanw bus_space_handle_t ramdac;
1413 1.17 elric
1414 1.17 elric if (btreg > BT485_REG_MAX)
1415 1.17 elric panic("tga_ramdac_wr: reg %d out of range\n", btreg);
1416 1.17 elric
1417 1.21 nathanw bus_space_subregion(dc->dc_memt, dc->dc_memh, TGA2_MEM_RAMDAC +
1418 1.21 nathanw (0xe << 12) + (btreg << 8), 4, &ramdac);
1419 1.21 nathanw bus_space_write_4(dc->dc_memt, ramdac, 0, val & 0xff);
1420 1.21 nathanw bus_space_barrier(dc->dc_memt, ramdac, 0, 4, BUS_SPACE_BARRIER_WRITE);
1421 1.17 elric }
1422 1.17 elric
1423 1.22 nathanw static u_int8_t
1424 1.22 nathanw tga_bt463_rd(v, btreg)
1425 1.22 nathanw void *v;
1426 1.22 nathanw u_int btreg;
1427 1.22 nathanw {
1428 1.22 nathanw struct tga_devconfig *dc = v;
1429 1.22 nathanw tga_reg_t rdval;
1430 1.22 nathanw
1431 1.22 nathanw /*
1432 1.22 nathanw * Strobe CE# (high->low->high) since status and data are latched on
1433 1.22 nathanw * the falling and rising edges (repsectively) of this active-low signal.
1434 1.22 nathanw */
1435 1.22 nathanw
1436 1.22 nathanw TGAREGWB(dc, TGA_REG_EPSR, 1);
1437 1.22 nathanw TGAWREG(dc, TGA_REG_EPSR, (btreg << 2) | 2 | 1);
1438 1.22 nathanw TGAREGWB(dc, TGA_REG_EPSR, 1);
1439 1.22 nathanw TGAWREG(dc, TGA_REG_EPSR, (btreg << 2) | 2 | 0);
1440 1.22 nathanw
1441 1.22 nathanw TGAREGRB(dc, TGA_REG_EPSR, 1);
1442 1.22 nathanw
1443 1.22 nathanw rdval = TGARREG(dc, TGA_REG_EPDR);
1444 1.22 nathanw TGAREGWB(dc, TGA_REG_EPSR, 1);
1445 1.22 nathanw TGAWREG(dc, TGA_REG_EPSR, (btreg << 2) | 2 | 1);
1446 1.22 nathanw
1447 1.22 nathanw return (rdval >> 16) & 0xff;
1448 1.22 nathanw }
1449 1.22 nathanw
1450 1.22 nathanw static void
1451 1.22 nathanw tga_bt463_wr(v, btreg, val)
1452 1.22 nathanw void *v;
1453 1.22 nathanw u_int btreg;
1454 1.22 nathanw u_int8_t val;
1455 1.22 nathanw {
1456 1.22 nathanw struct tga_devconfig *dc = v;
1457 1.22 nathanw
1458 1.22 nathanw /*
1459 1.22 nathanw * In spite of the 21030 documentation, to set the MPU bus bits for
1460 1.22 nathanw * a write, you set them in the upper bits of EPDR, not EPSR.
1461 1.22 nathanw */
1462 1.22 nathanw
1463 1.22 nathanw /*
1464 1.22 nathanw * Strobe CE# (high->low->high) since status and data are latched on
1465 1.22 nathanw * the falling and rising edges of this active-low signal.
1466 1.22 nathanw */
1467 1.22 nathanw
1468 1.22 nathanw TGAREGWB(dc, TGA_REG_EPDR, 1);
1469 1.22 nathanw TGAWREG(dc, TGA_REG_EPDR, (btreg << 10) | 0x100 | val);
1470 1.22 nathanw TGAREGWB(dc, TGA_REG_EPDR, 1);
1471 1.22 nathanw TGAWREG(dc, TGA_REG_EPDR, (btreg << 10) | 0x000 | val);
1472 1.22 nathanw TGAREGWB(dc, TGA_REG_EPDR, 1);
1473 1.22 nathanw TGAWREG(dc, TGA_REG_EPDR, (btreg << 10) | 0x100 | val);
1474 1.22 nathanw
1475 1.22 nathanw }
1476 1.22 nathanw
1477 1.22 nathanw static u_int8_t
1478 1.17 elric tga_ramdac_rd(v, btreg)
1479 1.17 elric void *v;
1480 1.17 elric u_int btreg;
1481 1.17 elric {
1482 1.17 elric struct tga_devconfig *dc = v;
1483 1.17 elric tga_reg_t rdval;
1484 1.17 elric
1485 1.17 elric if (btreg > BT485_REG_MAX)
1486 1.17 elric panic("tga_ramdac_rd: reg %d out of range\n", btreg);
1487 1.17 elric
1488 1.21 nathanw TGAWREG(dc, TGA_REG_EPSR, (btreg << 1) | 0x1); /* XXX */
1489 1.21 nathanw TGAREGWB(dc, TGA_REG_EPSR, 1);
1490 1.17 elric
1491 1.21 nathanw rdval = TGARREG(dc, TGA_REG_EPDR);
1492 1.17 elric return (rdval >> 16) & 0xff; /* XXX */
1493 1.17 elric }
1494 1.17 elric
1495 1.22 nathanw static u_int8_t
1496 1.17 elric tga2_ramdac_rd(v, btreg)
1497 1.17 elric void *v;
1498 1.17 elric u_int btreg;
1499 1.17 elric {
1500 1.17 elric struct tga_devconfig *dc = v;
1501 1.21 nathanw bus_space_handle_t ramdac;
1502 1.17 elric u_int8_t retval;
1503 1.17 elric
1504 1.17 elric if (btreg > BT485_REG_MAX)
1505 1.17 elric panic("tga_ramdac_rd: reg %d out of range\n", btreg);
1506 1.17 elric
1507 1.21 nathanw bus_space_subregion(dc->dc_memt, dc->dc_memh, TGA2_MEM_RAMDAC +
1508 1.21 nathanw (0xe << 12) + (btreg << 8), 4, &ramdac);
1509 1.21 nathanw retval = bus_space_read_4(dc->dc_memt, ramdac, 0) & 0xff;
1510 1.21 nathanw bus_space_barrier(dc->dc_memt, ramdac, 0, 4, BUS_SPACE_BARRIER_READ);
1511 1.17 elric return retval;
1512 1.17 elric }
1513 1.17 elric
1514 1.17 elric #include <dev/ic/decmonitors.c>
1515 1.17 elric void tga2_ics9110_wr __P((
1516 1.17 elric struct tga_devconfig *dc,
1517 1.17 elric int dotclock
1518 1.17 elric ));
1519 1.17 elric
1520 1.38 elric struct monitor *tga_getmonitor __P((struct tga_devconfig *dc));
1521 1.38 elric
1522 1.17 elric void
1523 1.38 elric tga2_init(dc)
1524 1.17 elric struct tga_devconfig *dc;
1525 1.17 elric {
1526 1.38 elric struct monitor *m = tga_getmonitor(dc);
1527 1.17 elric
1528 1.38 elric /* Deal with the dot clocks.
1529 1.38 elric */
1530 1.38 elric if (dc->dc_tga_type == TGA_TYPE_POWERSTORM_4D20) {
1531 1.38 elric /* Set this up as a reference clock for the
1532 1.38 elric * ibm561's PLL.
1533 1.38 elric */
1534 1.38 elric tga2_ics9110_wr(dc, 14300000);
1535 1.38 elric /* XXX Can't set up the dotclock properly, until such time
1536 1.38 elric * as the RAMDAC is configured.
1537 1.38 elric */
1538 1.38 elric } else {
1539 1.38 elric /* otherwise the ics9110 is our clock. */
1540 1.38 elric tga2_ics9110_wr(dc, m->dotclock);
1541 1.38 elric }
1542 1.21 nathanw #if 0
1543 1.21 nathanw TGAWREG(dc, TGA_REG_VHCR,
1544 1.38 elric ((m->hbp / 4) << 21) |
1545 1.38 elric ((m->hsync / 4) << 14) |
1546 1.38 elric (((m->hfp - 4) / 4) << 9) |
1547 1.38 elric ((m->cols + 4) / 4));
1548 1.17 elric #else
1549 1.21 nathanw TGAWREG(dc, TGA_REG_VHCR,
1550 1.38 elric ((m->hbp / 4) << 21) |
1551 1.38 elric ((m->hsync / 4) << 14) |
1552 1.38 elric (((m->hfp) / 4) << 9) |
1553 1.38 elric ((m->cols) / 4));
1554 1.17 elric #endif
1555 1.21 nathanw TGAWREG(dc, TGA_REG_VVCR,
1556 1.38 elric (m->vbp << 22) |
1557 1.38 elric (m->vsync << 16) |
1558 1.38 elric (m->vfp << 11) |
1559 1.38 elric (m->rows));
1560 1.21 nathanw TGAWREG(dc, TGA_REG_VVBR, 1);
1561 1.21 nathanw TGAREGRWB(dc, TGA_REG_VHCR, 3);
1562 1.21 nathanw TGAWREG(dc, TGA_REG_VVVR, TGARREG(dc, TGA_REG_VVVR) | 1);
1563 1.21 nathanw TGAREGRWB(dc, TGA_REG_VVVR, 1);
1564 1.21 nathanw TGAWREG(dc, TGA_REG_GPMR, 0xffffffff);
1565 1.21 nathanw TGAREGRWB(dc, TGA_REG_GPMR, 1);
1566 1.17 elric }
1567 1.17 elric
1568 1.17 elric void
1569 1.17 elric tga2_ics9110_wr(dc, dotclock)
1570 1.17 elric struct tga_devconfig *dc;
1571 1.17 elric int dotclock;
1572 1.17 elric {
1573 1.21 nathanw bus_space_handle_t clock;
1574 1.17 elric u_int32_t valU;
1575 1.17 elric int N, M, R, V, X;
1576 1.17 elric int i;
1577 1.17 elric
1578 1.17 elric switch (dotclock) {
1579 1.17 elric case 130808000:
1580 1.17 elric N = 0x40; M = 0x7; V = 0x0; X = 0x1; R = 0x1; break;
1581 1.17 elric case 119840000:
1582 1.17 elric N = 0x2d; M = 0x2b; V = 0x1; X = 0x1; R = 0x1; break;
1583 1.17 elric case 108180000:
1584 1.17 elric N = 0x11; M = 0x9; V = 0x1; X = 0x1; R = 0x2; break;
1585 1.17 elric case 103994000:
1586 1.17 elric N = 0x6d; M = 0xf; V = 0x0; X = 0x1; R = 0x1; break;
1587 1.17 elric case 175000000:
1588 1.17 elric N = 0x5F; M = 0x3E; V = 0x1; X = 0x1; R = 0x1; break;
1589 1.17 elric case 75000000:
1590 1.17 elric N = 0x6e; M = 0x15; V = 0x0; X = 0x1; R = 0x1; break;
1591 1.17 elric case 74000000:
1592 1.17 elric N = 0x2a; M = 0x41; V = 0x1; X = 0x1; R = 0x1; break;
1593 1.17 elric case 69000000:
1594 1.17 elric N = 0x35; M = 0xb; V = 0x0; X = 0x1; R = 0x1; break;
1595 1.17 elric case 65000000:
1596 1.17 elric N = 0x6d; M = 0x0c; V = 0x0; X = 0x1; R = 0x2; break;
1597 1.17 elric case 50000000:
1598 1.17 elric N = 0x37; M = 0x3f; V = 0x1; X = 0x1; R = 0x2; break;
1599 1.17 elric case 40000000:
1600 1.17 elric N = 0x5f; M = 0x11; V = 0x0; X = 0x1; R = 0x2; break;
1601 1.17 elric case 31500000:
1602 1.17 elric N = 0x16; M = 0x05; V = 0x0; X = 0x1; R = 0x2; break;
1603 1.17 elric case 25175000:
1604 1.17 elric N = 0x66; M = 0x1d; V = 0x0; X = 0x1; R = 0x2; break;
1605 1.17 elric case 135000000:
1606 1.17 elric N = 0x42; M = 0x07; V = 0x0; X = 0x1; R = 0x1; break;
1607 1.17 elric case 110000000:
1608 1.17 elric N = 0x60; M = 0x32; V = 0x1; X = 0x1; R = 0x2; break;
1609 1.17 elric case 202500000:
1610 1.17 elric N = 0x60; M = 0x32; V = 0x1; X = 0x1; R = 0x2; break;
1611 1.38 elric case 14300000: /* this one is just a ref clock */
1612 1.38 elric N = 0x03; M = 0x03; V = 0x1; X = 0x1; R = 0x3; break;
1613 1.17 elric default:
1614 1.17 elric panic("unrecognized clock rate %d\n", dotclock);
1615 1.17 elric }
1616 1.17 elric
1617 1.17 elric /* XXX -- hard coded, bad */
1618 1.17 elric valU = N | ( M << 7 ) | (V << 14);
1619 1.17 elric valU |= (X << 15) | (R << 17);
1620 1.17 elric valU |= 0x17 << 19;
1621 1.17 elric
1622 1.21 nathanw bus_space_subregion(dc->dc_memt, dc->dc_memh, TGA2_MEM_EXTDEV +
1623 1.21 nathanw TGA2_MEM_CLOCK + (0xe << 12), 4, &clock); /* XXX */
1624 1.17 elric
1625 1.21 nathanw for (i=24; i>0; i--) {
1626 1.21 nathanw u_int32_t writeval;
1627 1.17 elric
1628 1.21 nathanw writeval = valU & 0x1;
1629 1.21 nathanw if (i == 1)
1630 1.21 nathanw writeval |= 0x2;
1631 1.21 nathanw valU >>= 1;
1632 1.21 nathanw bus_space_write_4(dc->dc_memt, clock, 0, writeval);
1633 1.21 nathanw bus_space_barrier(dc->dc_memt, clock, 0, 4, BUS_SPACE_BARRIER_WRITE);
1634 1.17 elric }
1635 1.21 nathanw bus_space_subregion(dc->dc_memt, dc->dc_memh, TGA2_MEM_EXTDEV +
1636 1.21 nathanw TGA2_MEM_CLOCK + (0xe << 12) + (0x1 << 11) + (0x1 << 11), 4,
1637 1.21 nathanw &clock); /* XXX */
1638 1.21 nathanw bus_space_write_4(dc->dc_memt, clock, 0, 0x0);
1639 1.21 nathanw bus_space_barrier(dc->dc_memt, clock, 0, 0, BUS_SPACE_BARRIER_WRITE);
1640 1.38 elric }
1641 1.38 elric
1642 1.38 elric struct monitor *
1643 1.38 elric tga_getmonitor(dc)
1644 1.38 elric struct tga_devconfig *dc;
1645 1.38 elric {
1646 1.38 elric return &decmonitors[(~TGARREG(dc, TGA_REG_GREV) >> 16) & 0x0f];
1647 1.38 elric }
1648 1.38 elric
1649 1.38 elric unsigned
1650 1.38 elric tga_getdotclock(dc)
1651 1.38 elric struct tga_devconfig *dc;
1652 1.38 elric {
1653 1.38 elric return tga_getmonitor(dc)->dotclock;
1654 1.1 drochner }
1655