2 * Copyright (c) 2002 Bang Jun-Young
3 * Copyright (c) 2005 Marius Strobl <marius@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * from: NetBSD: machfb.c,v 1.23 2005/03/07 21:45:24 martin Exp
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
35 * Driver for ATI Mach64 graphics chips. Some code is derived from the
36 * ATI Rage Pro and Derivatives Programmer's Guide.
39 #include <sys/param.h>
40 #include <sys/systm.h>
42 #include <sys/consio.h>
43 #include <sys/endian.h>
44 #include <sys/eventhandler.h>
46 #include <sys/kernel.h>
47 #include <sys/module.h>
48 #include <sys/resource.h>
53 #include <dev/ofw/ofw_bus.h>
54 #include <dev/ofw/openfirm.h>
56 #include <machine/bus.h>
57 #include <machine/bus_private.h>
58 #include <machine/ofw_machdep.h>
59 #include <machine/pmap.h>
60 #include <machine/resource.h>
61 #include <machine/sc_machdep.h>
65 #include <dev/fb/fbreg.h>
66 #include <dev/fb/gfb.h>
67 #include <dev/fb/machfbreg.h>
68 #include <dev/pci/pcivar.h>
69 #include <dev/pci/pcireg.h>
70 #include <dev/syscons/syscons.h>
72 /* #define MACHFB_DEBUG */
74 #define MACHFB_DRIVER_NAME "machfb"
76 #define MACH64_REG_OFF 0x7ffc00
77 #define MACH64_REG_SIZE 1024
80 video_adapter_t sc_va; /* must be first */
86 struct resource *sc_memres;
87 struct resource *sc_vmemres;
88 bus_space_tag_t sc_memt;
89 bus_space_tag_t sc_regt;
90 bus_space_handle_t sc_memh;
91 bus_space_handle_t sc_regh;
104 u_int sc_ramdac_freq;
108 u_int sc_mclk_post_div;
109 u_int sc_mclk_fb_div;
111 const u_char *sc_font;
113 vm_offset_t sc_curoff;
118 #define MACHFB_DRAW_CHAR (1 << 0)
119 #define MACHFB_DRAW_FILLRECT (1 << 1)
122 #define MACHFB_CONSOLE (1 << 0)
123 #define MACHFB_CUREN (1 << 1)
124 #define MACHFB_DSP (1 << 2)
125 #define MACHFB_SWAP (1 << 3)
128 static const struct {
131 uint32_t ramdac_freq;
132 } const machfb_info[] = {
133 { ATI_MACH64_CT, "ATI Mach64 CT", 135000 },
134 { ATI_RAGE_PRO_AGP, "ATI 3D Rage Pro (AGP)", 230000 },
135 { ATI_RAGE_PRO_AGP1X, "ATI 3D Rage Pro (AGP 1x)", 230000 },
136 { ATI_RAGE_PRO_PCI_B, "ATI 3D Rage Pro Turbo", 230000 },
137 { ATI_RAGE_XC_PCI66, "ATI Rage XL (PCI66)", 230000 },
138 { ATI_RAGE_XL_AGP, "ATI Rage XL (AGP)", 230000 },
139 { ATI_RAGE_XC_AGP, "ATI Rage XC (AGP)", 230000 },
140 { ATI_RAGE_XL_PCI66, "ATI Rage XL (PCI66)", 230000 },
141 { ATI_RAGE_PRO_PCI_P, "ATI 3D Rage Pro", 230000 },
142 { ATI_RAGE_PRO_PCI_L, "ATI 3D Rage Pro (limited 3D)", 230000 },
143 { ATI_RAGE_XL_PCI, "ATI Rage XL", 230000 },
144 { ATI_RAGE_XC_PCI, "ATI Rage XC", 230000 },
145 { ATI_RAGE_II, "ATI 3D Rage I/II", 135000 },
146 { ATI_RAGE_IIP, "ATI 3D Rage II+", 200000 },
147 { ATI_RAGE_IIC_PCI, "ATI 3D Rage IIC", 230000 },
148 { ATI_RAGE_IIC_AGP_B, "ATI 3D Rage IIC (AGP)", 230000 },
149 { ATI_RAGE_IIC_AGP_P, "ATI 3D Rage IIC (AGP)", 230000 },
150 { ATI_RAGE_LT_PRO_AGP, "ATI 3D Rage LT Pro (AGP 133MHz)", 230000 },
151 { ATI_RAGE_MOB_M3_PCI, "ATI Rage Mobility M3", 230000 },
152 { ATI_RAGE_MOB_M3_AGP, "ATI Rage Mobility M3 (AGP)", 230000 },
153 { ATI_RAGE_LT, "ATI 3D Rage LT", 230000 },
154 { ATI_RAGE_LT_PRO_PCI, "ATI 3D Rage LT Pro", 230000 },
155 { ATI_RAGE_MOBILITY, "ATI Rage Mobility", 230000 },
156 { ATI_RAGE_L_MOBILITY, "ATI Rage L Mobility", 230000 },
157 { ATI_RAGE_LT_PRO, "ATI 3D Rage LT Pro", 230000 },
158 { ATI_RAGE_LT_PRO2, "ATI 3D Rage LT Pro", 230000 },
159 { ATI_RAGE_MOB_M1_PCI, "ATI Rage Mobility M1 (PCI)", 230000 },
160 { ATI_RAGE_L_MOB_M1_PCI, "ATI Rage L Mobility (PCI)", 230000 },
161 { ATI_MACH64_VT, "ATI Mach64 VT", 170000 },
162 { ATI_MACH64_VTB, "ATI Mach64 VTB", 200000 },
163 { ATI_MACH64_VT4, "ATI Mach64 VT4", 230000 }
166 static const struct machfb_cmap {
170 } const machfb_default_cmap[16] = {
171 {0x00, 0x00, 0x00}, /* black */
172 {0x00, 0x00, 0xff}, /* blue */
173 {0x00, 0xff, 0x00}, /* green */
174 {0x00, 0xc0, 0xc0}, /* cyan */
175 {0xff, 0x00, 0x00}, /* red */
176 {0xc0, 0x00, 0xc0}, /* magenta */
177 {0xc0, 0xc0, 0x00}, /* brown */
178 {0xc0, 0xc0, 0xc0}, /* light grey */
179 {0x80, 0x80, 0x80}, /* dark grey */
180 {0x80, 0x80, 0xff}, /* light blue */
181 {0x80, 0xff, 0x80}, /* light green */
182 {0x80, 0xff, 0xff}, /* light cyan */
183 {0xff, 0x80, 0x80}, /* light red */
184 {0xff, 0x80, 0xff}, /* light magenta */
185 {0xff, 0xff, 0x80}, /* yellow */
186 {0xff, 0xff, 0xff} /* white */
189 #define MACHFB_CMAP_OFF 16
191 static const u_char const machfb_mouse_pointer_bits[64][8] = {
192 { 0x00, 0x00, }, /* ............ */
193 { 0x80, 0x00, }, /* *........... */
194 { 0xc0, 0x00, }, /* **.......... */
195 { 0xe0, 0x00, }, /* ***......... */
196 { 0xf0, 0x00, }, /* ****........ */
197 { 0xf8, 0x00, }, /* *****....... */
198 { 0xfc, 0x00, }, /* ******...... */
199 { 0xfe, 0x00, }, /* *******..... */
200 { 0xff, 0x00, }, /* ********.... */
201 { 0xff, 0x80, }, /* *********... */
202 { 0xfc, 0xc0, }, /* ******..**.. */
203 { 0xdc, 0x00, }, /* **.***...... */
204 { 0x8e, 0x00, }, /* *...***..... */
205 { 0x0e, 0x00, }, /* ....***..... */
206 { 0x07, 0x00, }, /* .....***.... */
207 { 0x04, 0x00, }, /* .....*...... */
208 { 0x00, 0x00, }, /* ............ */
209 { 0x00, 0x00, }, /* ............ */
210 { 0x00, 0x00, }, /* ............ */
211 { 0x00, 0x00, }, /* ............ */
212 { 0x00, 0x00, }, /* ............ */
213 { 0x00, 0x00, }, /* ............ */
217 * Lookup table to perform a bit-swap of the mouse pointer bits,
218 * map set bits to CUR_CLR0 and unset bits to transparent.
220 static const u_char const machfb_mouse_pointer_lut[] = {
221 0xaa, 0x2a, 0x8a, 0x0a, 0xa2, 0x22, 0x82, 0x02,
222 0xa8, 0x28, 0x88, 0x08, 0xa0, 0x20, 0x80, 0x00
225 static const char *const machfb_memtype_names[] = {
226 "(N/A)", "DRAM", "EDO DRAM", "EDO DRAM", "SDRAM", "SGRAM", "WRAM",
230 extern const struct gfb_font gallant12x22;
232 static struct machfb_softc machfb_softc;
233 static struct bus_space_tag machfb_bst_store[1];
235 static device_probe_t machfb_pci_probe;
236 static device_attach_t machfb_pci_attach;
237 static device_detach_t machfb_pci_detach;
239 static device_method_t machfb_methods[] = {
240 /* Device interface */
241 DEVMETHOD(device_probe, machfb_pci_probe),
242 DEVMETHOD(device_attach, machfb_pci_attach),
243 DEVMETHOD(device_detach, machfb_pci_detach),
248 static driver_t machfb_pci_driver = {
251 sizeof(struct machfb_softc),
254 static devclass_t machfb_devclass;
256 DRIVER_MODULE(machfb, pci, machfb_pci_driver, machfb_devclass, 0, 0);
257 MODULE_DEPEND(machfb, pci, 1, 1, 1);
259 static void machfb_cursor_enable(struct machfb_softc *, int);
260 static int machfb_cursor_install(struct machfb_softc *);
261 static int machfb_get_memsize(struct machfb_softc *);
262 static void machfb_reset_engine(struct machfb_softc *);
263 static void machfb_init_engine(struct machfb_softc *);
265 static void machfb_adjust_frame(struct machfb_softc *, int, int);
267 static void machfb_shutdown_final(void *);
268 static void machfb_shutdown_reset(void *);
270 static int machfb_configure(int);
272 static vi_probe_t machfb_probe;
273 static vi_init_t machfb_init;
274 static vi_get_info_t machfb_get_info;
275 static vi_query_mode_t machfb_query_mode;
276 static vi_set_mode_t machfb_set_mode;
277 static vi_save_font_t machfb_save_font;
278 static vi_load_font_t machfb_load_font;
279 static vi_show_font_t machfb_show_font;
280 static vi_save_palette_t machfb_save_palette;
281 static vi_load_palette_t machfb_load_palette;
282 static vi_set_border_t machfb_set_border;
283 static vi_save_state_t machfb_save_state;
284 static vi_load_state_t machfb_load_state;
285 static vi_set_win_org_t machfb_set_win_org;
286 static vi_read_hw_cursor_t machfb_read_hw_cursor;
287 static vi_set_hw_cursor_t machfb_set_hw_cursor;
288 static vi_set_hw_cursor_shape_t machfb_set_hw_cursor_shape;
289 static vi_blank_display_t machfb_blank_display;
290 static vi_mmap_t machfb_mmap;
291 static vi_ioctl_t machfb_ioctl;
292 static vi_clear_t machfb_clear;
293 static vi_fill_rect_t machfb_fill_rect;
294 static vi_bitblt_t machfb_bitblt;
295 static vi_diag_t machfb_diag;
296 static vi_save_cursor_palette_t machfb_save_cursor_palette;
297 static vi_load_cursor_palette_t machfb_load_cursor_palette;
298 static vi_copy_t machfb_copy;
299 static vi_putp_t machfb_putp;
300 static vi_putc_t machfb_putc;
301 static vi_puts_t machfb_puts;
302 static vi_putm_t machfb_putm;
304 static video_switch_t machfbvidsw = {
305 .probe = machfb_probe,
307 .get_info = machfb_get_info,
308 .query_mode = machfb_query_mode,
309 .set_mode = machfb_set_mode,
310 .save_font = machfb_save_font,
311 .load_font = machfb_load_font,
312 .show_font = machfb_show_font,
313 .save_palette = machfb_save_palette,
314 .load_palette = machfb_load_palette,
315 .set_border = machfb_set_border,
316 .save_state = machfb_save_state,
317 .load_state = machfb_load_state,
318 .set_win_org = machfb_set_win_org,
319 .read_hw_cursor = machfb_read_hw_cursor,
320 .set_hw_cursor = machfb_set_hw_cursor,
321 .set_hw_cursor_shape = machfb_set_hw_cursor_shape,
322 .blank_display = machfb_blank_display,
324 .ioctl = machfb_ioctl,
325 .clear = machfb_clear,
326 .fill_rect = machfb_fill_rect,
327 .bitblt = machfb_bitblt,
329 .save_cursor_palette = machfb_save_cursor_palette,
330 .load_cursor_palette = machfb_load_cursor_palette,
338 VIDEO_DRIVER(machfb, machfbvidsw, machfb_configure);
340 extern sc_rndr_sw_t txtrndrsw;
341 RENDERER(machfb, 0, txtrndrsw, gfb_set);
343 RENDERER_MODULE(machfb, gfb_set);
346 * Inline functions for getting access to register aperture.
348 static inline uint32_t regr(struct machfb_softc *, uint32_t);
349 static inline uint8_t regrb(struct machfb_softc *, uint32_t);
350 static inline void regw(struct machfb_softc *, uint32_t, uint32_t);
351 static inline void regwb(struct machfb_softc *, uint32_t, uint8_t);
352 static inline void regwb_pll(struct machfb_softc *, uint32_t, uint8_t);
354 static inline uint32_t
355 regr(struct machfb_softc *sc, uint32_t index)
358 return bus_space_read_4(sc->sc_regt, sc->sc_regh, index);
361 static inline uint8_t
362 regrb(struct machfb_softc *sc, uint32_t index)
365 return bus_space_read_1(sc->sc_regt, sc->sc_regh, index);
369 regw(struct machfb_softc *sc, uint32_t index, uint32_t data)
372 bus_space_write_4(sc->sc_regt, sc->sc_regh, index, data);
373 bus_space_barrier(sc->sc_regt, sc->sc_regh, index, 4,
374 BUS_SPACE_BARRIER_WRITE);
378 regwb(struct machfb_softc *sc, uint32_t index, uint8_t data)
381 bus_space_write_1(sc->sc_regt, sc->sc_regh, index, data);
382 bus_space_barrier(sc->sc_regt, sc->sc_regh, index, 1,
383 BUS_SPACE_BARRIER_WRITE);
387 regwb_pll(struct machfb_softc *sc, uint32_t index, uint8_t data)
390 regwb(sc, CLOCK_CNTL + 1, (index << 2) | PLL_WR_EN);
391 regwb(sc, CLOCK_CNTL + 2, data);
392 regwb(sc, CLOCK_CNTL + 1, (index << 2) & ~PLL_WR_EN);
396 wait_for_fifo(struct machfb_softc *sc, uint8_t v)
399 while ((regr(sc, FIFO_STAT) & 0xffff) > (0x8000 >> v))
404 wait_for_idle(struct machfb_softc *sc)
407 wait_for_fifo(sc, 16);
408 while ((regr(sc, GUI_STAT) & 1) != 0)
413 * Inline functions for setting the background and foreground colors.
415 static inline void machfb_setbg(struct machfb_softc *sc, int bg);
416 static inline void machfb_setfg(struct machfb_softc *sc, int fg);
419 machfb_setbg(struct machfb_softc *sc, int bg)
422 if (bg == sc->sc_bg_cache)
424 sc->sc_bg_cache = bg;
425 wait_for_fifo(sc, 1);
426 regw(sc, DP_BKGD_CLR, bg + MACHFB_CMAP_OFF);
430 machfb_setfg(struct machfb_softc *sc, int fg)
433 if (fg == sc->sc_fg_cache)
435 sc->sc_fg_cache = fg;
436 wait_for_fifo(sc, 1);
437 regw(sc, DP_FRGD_CLR, fg + MACHFB_CMAP_OFF);
441 * video driver interface
444 machfb_configure(int flags)
446 struct machfb_softc *sc;
447 phandle_t chosen, output;
454 * For the high-level console probing return the number of
455 * registered adapters.
457 if (!(flags & VIO_PROBE_ONLY)) {
458 for (i = 0; vid_find_adapter(MACHFB_DRIVER_NAME, i) >= 0; i++)
463 /* Low-level console probing and initialization. */
466 if (sc->sc_va.va_flags & V_ADP_REGISTERED)
469 if ((chosen = OF_finddevice("/chosen")) == -1) /* Quis contra nos? */
471 if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1)
473 if ((output = OF_instance_to_package(stdout)) == -1)
475 if ((OF_getprop(output, "vendor-id", &id, sizeof(id)) == -1) ||
478 if (OF_getprop(output, "device-id", &id, sizeof(id)) == -1)
480 for (i = 0; i < sizeof(machfb_info) / sizeof(machfb_info[0]); i++) {
481 if (id == machfb_info[i].chip_id) {
482 sc->sc_flags = MACHFB_CONSOLE;
483 sc->sc_node = output;
488 if (!(sc->sc_flags & MACHFB_CONSOLE))
491 if (OF_getprop(output, "revision-id", &sc->sc_chip_rev,
492 sizeof(sc->sc_chip_rev)) == -1)
494 if (OF_decode_addr(output, 0, &space, &addr) != 0)
496 sc->sc_memt = &machfb_bst_store[0];
497 sc->sc_memh = sparc64_fake_bustag(space, addr, sc->sc_memt);
498 sc->sc_regt = sc->sc_memt;
499 bus_space_subregion(sc->sc_regt, sc->sc_memh, MACH64_REG_OFF,
500 MACH64_REG_SIZE, &sc->sc_regh);
502 if (machfb_init(0, &sc->sc_va, 0) < 0)
506 /* Return number of found adapters. */
511 machfb_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
518 machfb_init(int unit, video_adapter_t *adp, int flags)
520 struct machfb_softc *sc;
525 uint8_t dac_mask, dac_rindex, dac_windex;
527 sc = (struct machfb_softc *)adp;
530 if ((regr(sc, CONFIG_CHIP_ID) & 0xffff) != sc->sc_chip_id)
533 sc->sc_ramdac_freq = 0;
534 for (i = 0; i < sizeof(machfb_info) / sizeof(machfb_info[0]); i++) {
535 if (sc->sc_chip_id == machfb_info[i].chip_id) {
536 sc->sc_ramdac_freq = machfb_info[i].ramdac_freq;
540 if (sc->sc_ramdac_freq == 0)
542 if (sc->sc_chip_id == ATI_RAGE_II && sc->sc_chip_rev & 0x07)
543 sc->sc_ramdac_freq = 170000;
545 vid_init_struct(adp, MACHFB_DRIVER_NAME, -1, unit);
547 if (OF_getprop(sc->sc_node, "height", &sc->sc_height,
548 sizeof(sc->sc_height)) == -1)
550 if (OF_getprop(sc->sc_node, "width", &sc->sc_width,
551 sizeof(sc->sc_width)) == -1)
553 if (OF_getprop(sc->sc_node, "depth", &sc->sc_depth,
554 sizeof(sc->sc_depth)) == -1)
556 if ((options = OF_finddevice("/options")) == -1)
558 if (OF_getprop(options, "screen-#rows", buf, sizeof(buf)) == -1)
560 vi->vi_height = strtol(buf, NULL, 10);
561 if (OF_getprop(options, "screen-#columns", buf, sizeof(buf)) == -1)
563 vi->vi_width = strtol(buf, NULL, 10);
564 vi->vi_cwidth = gallant12x22.width;
565 vi->vi_cheight = gallant12x22.height;
566 vi->vi_flags = V_INFO_COLOR;
567 vi->vi_mem_model = V_INFO_MM_OTHER;
569 sc->sc_font = gallant12x22.data;
570 sc->sc_cbwidth = howmany(vi->vi_cwidth, NBBY); /* width in bytes */
571 sc->sc_xmargin = (sc->sc_width - (vi->vi_width * vi->vi_cwidth)) / 2;
572 sc->sc_ymargin = (sc->sc_height - (vi->vi_height * vi->vi_cheight)) / 2;
574 if (sc->sc_chip_id != ATI_MACH64_CT &&
575 !((sc->sc_chip_id == ATI_MACH64_VT ||
576 sc->sc_chip_id == ATI_RAGE_II) &&
577 (sc->sc_chip_rev & 0x07) == 0))
578 sc->sc_flags |= MACHFB_DSP;
580 sc->sc_memsize = machfb_get_memsize(sc);
581 if (sc->sc_memsize == 8192)
582 /* The last page is used as register aperture. */
584 sc->sc_memtype = regr(sc, CONFIG_STAT0) & 0x07;
586 if ((sc->sc_chip_id >= ATI_RAGE_XC_PCI66 &&
587 sc->sc_chip_id <= ATI_RAGE_XL_PCI66) ||
588 (sc->sc_chip_id >= ATI_RAGE_XL_PCI &&
589 sc->sc_chip_id <= ATI_RAGE_XC_PCI))
590 sc->sc_ref_freq = 29498;
592 sc->sc_ref_freq = 14318;
594 regwb(sc, CLOCK_CNTL + 1, PLL_REF_DIV << 2);
595 sc->sc_ref_div = regrb(sc, CLOCK_CNTL + 2);
596 regwb(sc, CLOCK_CNTL + 1, MCLK_FB_DIV << 2);
597 sc->sc_mclk_fb_div = regrb(sc, CLOCK_CNTL + 2);
598 sc->sc_mem_freq = (2 * sc->sc_ref_freq * sc->sc_mclk_fb_div) /
599 (sc->sc_ref_div * 2);
600 sc->sc_mclk_post_div = (sc->sc_mclk_fb_div * 2 * sc->sc_ref_freq) /
601 (sc->sc_mem_freq * sc->sc_ref_div);
603 machfb_init_engine(sc);
605 machfb_adjust_frame(0, 0);
607 machfb_set_mode(adp, 0);
610 * Install our 16-color color map. This is done only once and with
611 * an offset of 16 on sparc64 as there the OBP driver expects white
612 * to be at index 0 and black at 255 (some versions also use 1 - 8
613 * for color text support or the full palette for the boot banner
614 * logo but no versions seems to use the ISO 6429-1983 color map).
615 * Otherwise the colors are inverted when back in the OFW.
617 dac_rindex = regrb(sc, DAC_RINDEX);
618 dac_windex = regrb(sc, DAC_WINDEX);
619 dac_mask = regrb(sc, DAC_MASK);
620 regwb(sc, DAC_MASK, 0xff);
621 regwb(sc, DAC_WINDEX, MACHFB_CMAP_OFF);
622 for (i = 0; i < 16; i++) {
623 regwb(sc, DAC_DATA, machfb_default_cmap[i].red);
624 regwb(sc, DAC_DATA, machfb_default_cmap[i].green);
625 regwb(sc, DAC_DATA, machfb_default_cmap[i].blue);
627 regwb(sc, DAC_MASK, dac_mask);
628 regwb(sc, DAC_RINDEX, dac_rindex);
629 regwb(sc, DAC_WINDEX, dac_windex);
631 machfb_blank_display(adp, V_DISPLAY_ON);
635 * Setting V_ADP_MODECHANGE serves as hack so machfb_set_mode()
636 * (which will invalidate our caches) is called as a precaution
637 * when the X server shuts down.
639 adp->va_flags |= V_ADP_COLOR | V_ADP_MODECHANGE | V_ADP_PALETTE |
640 V_ADP_BORDER | V_ADP_INITIALIZED;
641 if (vid_register(adp) < 0)
643 adp->va_flags |= V_ADP_REGISTERED;
649 machfb_get_info(video_adapter_t *adp, int mode, video_info_t *info)
652 bcopy(&adp->va_info, info, sizeof(*info));
658 machfb_query_mode(video_adapter_t *adp, video_info_t *info)
665 machfb_set_mode(video_adapter_t *adp, int mode)
667 struct machfb_softc *sc;
669 sc = (struct machfb_softc *)adp;
671 sc->sc_bg_cache = -1;
672 sc->sc_fg_cache = -1;
673 sc->sc_draw_cache = 0;
679 machfb_save_font(video_adapter_t *adp, int page, int size, int width,
680 u_char *data, int c, int count)
687 machfb_load_font(video_adapter_t *adp, int page, int size, int width,
688 u_char *data, int c, int count)
695 machfb_show_font(video_adapter_t *adp, int page)
702 machfb_save_palette(video_adapter_t *adp, u_char *palette)
704 struct machfb_softc *sc;
706 uint8_t dac_mask, dac_rindex, dac_windex;
708 sc = (struct machfb_softc *)adp;
710 dac_rindex = regrb(sc, DAC_RINDEX);
711 dac_windex = regrb(sc, DAC_WINDEX);
712 dac_mask = regrb(sc, DAC_MASK);
713 regwb(sc, DAC_MASK, 0xff);
714 regwb(sc, DAC_RINDEX, 0x0);
715 for (i = 0; i < 256 * 3; i++)
716 palette[i] = regrb(sc, DAC_DATA);
717 regwb(sc, DAC_MASK, dac_mask);
718 regwb(sc, DAC_RINDEX, dac_rindex);
719 regwb(sc, DAC_WINDEX, dac_windex);
725 machfb_load_palette(video_adapter_t *adp, u_char *palette)
727 struct machfb_softc *sc;
729 uint8_t dac_mask, dac_rindex, dac_windex;
731 sc = (struct machfb_softc *)adp;
733 dac_rindex = regrb(sc, DAC_RINDEX);
734 dac_windex = regrb(sc, DAC_WINDEX);
735 dac_mask = regrb(sc, DAC_MASK);
736 regwb(sc, DAC_MASK, 0xff);
737 regwb(sc, DAC_WINDEX, 0x0);
738 for (i = 0; i < 256 * 3; i++)
739 regwb(sc, DAC_DATA, palette[i]);
740 regwb(sc, DAC_MASK, dac_mask);
741 regwb(sc, DAC_RINDEX, dac_rindex);
742 regwb(sc, DAC_WINDEX, dac_windex);
748 machfb_set_border(video_adapter_t *adp, int border)
750 struct machfb_softc *sc;
752 sc = (struct machfb_softc *)adp;
754 machfb_fill_rect(adp, border, 0, 0, sc->sc_width, sc->sc_ymargin);
755 machfb_fill_rect(adp, border, 0, sc->sc_height - sc->sc_ymargin,
756 sc->sc_width, sc->sc_ymargin);
757 machfb_fill_rect(adp, border, 0, 0, sc->sc_xmargin, sc->sc_height);
758 machfb_fill_rect(adp, border, sc->sc_width - sc->sc_xmargin, 0,
759 sc->sc_xmargin, sc->sc_height);
765 machfb_save_state(video_adapter_t *adp, void *p, size_t size)
772 machfb_load_state(video_adapter_t *adp, void *p)
779 machfb_set_win_org(video_adapter_t *adp, off_t offset)
786 machfb_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
796 machfb_set_hw_cursor(video_adapter_t *adp, int col, int row)
803 machfb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
804 int celsize, int blink)
811 machfb_blank_display(video_adapter_t *adp, int mode)
813 struct machfb_softc *sc;
814 uint32_t crtc_gen_cntl;
816 sc = (struct machfb_softc *)adp;
818 crtc_gen_cntl = (regr(sc, CRTC_GEN_CNTL) | CRTC_EXT_DISP_EN | CRTC_EN) &
819 ~(CRTC_HSYNC_DIS | CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS);
823 case V_DISPLAY_BLANK:
824 crtc_gen_cntl |= CRTC_HSYNC_DIS | CRTC_VSYNC_DIS |
827 case V_DISPLAY_STAND_BY:
828 crtc_gen_cntl |= CRTC_HSYNC_DIS | CRTC_DISPLAY_DIS;
830 case V_DISPLAY_SUSPEND:
831 crtc_gen_cntl |= CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS;
834 regw(sc, CRTC_GEN_CNTL, crtc_gen_cntl);
840 machfb_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr,
841 int prot, vm_memattr_t *memattr)
843 struct machfb_softc *sc;
846 sc = (struct machfb_softc *)adp;
849 /* BAR 2 - VGA memory */
850 if (sc->sc_vmem != 0 && offset >= sc->sc_vmem &&
851 offset < sc->sc_vmem + vi->vi_registers_size) {
852 *paddr = vi->vi_registers + offset - sc->sc_vmem;
856 /* BAR 0 - framebuffer */
857 if (offset >= sc->sc_mem &&
858 offset < sc->sc_mem + vi->vi_buffer_size) {
859 *paddr = vi->vi_buffer + offset - sc->sc_mem;
863 /* 'regular' framebuffer mmap()ing */
864 if (offset < adp->va_window_size) {
865 *paddr = vi->vi_window + offset;
873 machfb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data)
875 struct machfb_softc *sc;
876 struct fbcursor *fbc;
879 sc = (struct machfb_softc *)adp;
883 fb = (struct fbtype *)data;
884 fb->fb_type = FBTYPE_PCIMISC;
885 fb->fb_height = sc->sc_height;
886 fb->fb_width = sc->sc_width;
887 fb->fb_depth = sc->sc_depth;
888 if (sc->sc_depth <= 1 || sc->sc_depth > 8)
891 fb->fb_cmsize = 1 << sc->sc_depth;
892 fb->fb_size = adp->va_buffer_size;
895 fbc = (struct fbcursor *)data;
896 if (fbc->set & FB_CUR_SETCUR && fbc->enable == 0) {
897 machfb_cursor_enable(sc, 0);
898 sc->sc_flags &= ~MACHFB_CUREN;
903 return (fb_commonioctl(adp, cmd, data));
910 machfb_clear(video_adapter_t *adp)
912 struct machfb_softc *sc;
914 sc = (struct machfb_softc *)adp;
916 machfb_fill_rect(adp, (SC_NORM_ATTR >> 4) & 0xf, 0, 0, sc->sc_width,
923 machfb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
925 struct machfb_softc *sc;
927 sc = (struct machfb_softc *)adp;
929 if (sc->sc_draw_cache != MACHFB_DRAW_FILLRECT) {
930 wait_for_fifo(sc, 7);
931 regw(sc, DP_WRITE_MASK, 0xff);
932 regw(sc, DP_PIX_WIDTH, DST_8BPP | SRC_8BPP | HOST_8BPP);
933 regw(sc, DP_SRC, FRGD_SRC_FRGD_CLR);
934 regw(sc, DP_MIX, MIX_SRC << 16);
935 regw(sc, CLR_CMP_CNTL, 0); /* no transparency */
936 regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT);
937 regw(sc, DST_CNTL, DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM);
938 sc->sc_draw_cache = MACHFB_DRAW_FILLRECT;
940 machfb_setfg(sc, val);
941 wait_for_fifo(sc, 4);
942 regw(sc, SRC_Y_X, (x << 16) | y);
943 regw(sc, SRC_WIDTH1, cx);
944 regw(sc, DST_Y_X, (x << 16) | y);
945 regw(sc, DST_HEIGHT_WIDTH, (cx << 16) | cy);
951 machfb_bitblt(video_adapter_t *adp, ...)
958 machfb_diag(video_adapter_t *adp, int level)
962 fb_dump_adp_info(adp->va_name, adp, level);
963 machfb_get_info(adp, 0, &info);
964 fb_dump_mode_info(adp->va_name, adp, &info, level);
970 machfb_save_cursor_palette(video_adapter_t *adp, u_char *palette)
977 machfb_load_cursor_palette(video_adapter_t *adp, u_char *palette)
984 machfb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n)
991 machfb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a,
992 int size, int bpp, int bit_ltor, int byte_ltor)
999 machfb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a)
1001 struct machfb_softc *sc;
1005 sc = (struct machfb_softc *)adp;
1007 if (sc->sc_draw_cache != MACHFB_DRAW_CHAR) {
1008 wait_for_fifo(sc, 8);
1009 regw(sc, DP_WRITE_MASK, 0xff); /* XXX only good for 8 bit */
1010 regw(sc, DP_PIX_WIDTH, DST_8BPP | SRC_1BPP | HOST_1BPP);
1011 regw(sc, DP_SRC, MONO_SRC_HOST | BKGD_SRC_BKGD_CLR |
1013 regw(sc, DP_MIX ,((MIX_SRC & 0xffff) << 16) | MIX_SRC);
1014 regw(sc, CLR_CMP_CNTL, 0); /* no transparency */
1015 regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT);
1016 regw(sc, DST_CNTL, DST_Y_TOP_TO_BOTTOM | DST_X_LEFT_TO_RIGHT);
1017 regw(sc, HOST_CNTL, HOST_BYTE_ALIGN);
1018 sc->sc_draw_cache = MACHFB_DRAW_CHAR;
1020 machfb_setbg(sc, (a >> 4) & 0xf);
1021 machfb_setfg(sc, a & 0xf);
1022 wait_for_fifo(sc, 4 + (adp->va_info.vi_cheight / sc->sc_cbwidth));
1023 regw(sc, SRC_Y_X, 0);
1024 regw(sc, SRC_WIDTH1, adp->va_info.vi_cwidth);
1025 regw(sc, DST_Y_X, ((((off % adp->va_info.vi_width) *
1026 adp->va_info.vi_cwidth) + sc->sc_xmargin) << 16) |
1027 (((off / adp->va_info.vi_width) * adp->va_info.vi_cheight) +
1029 regw(sc, DST_HEIGHT_WIDTH, (adp->va_info.vi_cwidth << 16) |
1030 adp->va_info.vi_cheight);
1031 p = sc->sc_font + (c * adp->va_info.vi_cheight * sc->sc_cbwidth);
1032 for (i = 0; i < adp->va_info.vi_cheight * sc->sc_cbwidth; i += 4)
1033 regw(sc, HOST_DATA0 + i, (p[i + 3] << 24 | p[i + 2] << 16 |
1034 p[i + 1] << 8 | p[i]));
1040 machfb_puts(video_adapter_t *adp, vm_offset_t off, uint16_t *s, int len)
1042 struct machfb_softc *sc;
1043 int blanks, i, x1, x2, y1, y2;
1044 uint8_t a, c, color1, color2;
1046 sc = (struct machfb_softc *)adp;
1048 #define MACHFB_BLANK machfb_fill_rect(adp, color1, x1, y1, \
1049 blanks * adp->va_info.vi_cwidth, \
1050 adp->va_info.vi_cheight)
1052 blanks = color1 = x1 = y1 = 0;
1053 for (i = 0; i < len; i++) {
1055 * Accelerate continuous blanks by drawing a respective
1056 * rectangle instead. Drawing a rectangle of any size
1057 * takes about the same number of operations as drawing
1058 * a single character.
1061 a = (s[i] & 0xff00) >> 8;
1062 if (c == 0x00 || c == 0x20 || c == 0xdb || c == 0xff) {
1063 color2 = (a >> (c == 0xdb ? 0 : 4) & 0xf);
1064 x2 = (((off + i) % adp->va_info.vi_width) *
1065 adp->va_info.vi_cwidth) + sc->sc_xmargin;
1066 y2 = (((off + i) / adp->va_info.vi_width) *
1067 adp->va_info.vi_cheight) + sc->sc_ymargin;
1073 } else if (color1 != color2 || y1 != y2) {
1086 vidd_putc(adp, off + i, c, a);
1098 machfb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image,
1099 uint32_t pixel_mask, int size, int width)
1101 struct machfb_softc *sc;
1104 sc = (struct machfb_softc *)adp;
1106 if ((!(sc->sc_flags & MACHFB_CUREN)) &&
1107 (error = machfb_cursor_install(sc)) < 0)
1111 * The hardware cursor always must be disabled when
1112 * fiddling with its bits otherwise some artifacts
1113 * may appear on the screen.
1115 machfb_cursor_enable(sc, 0);
1118 regw(sc, CUR_HORZ_VERT_OFF, 0);
1119 if ((regr(sc, GEN_TEST_CNTL) & CRTC_DBL_SCAN_EN) != 0)
1121 regw(sc, CUR_HORZ_VERT_POSN, ((y + sc->sc_ymargin) << 16) |
1122 (x + sc->sc_xmargin));
1123 machfb_cursor_enable(sc, 1);
1124 sc->sc_flags |= MACHFB_CUREN;
1133 machfb_pci_probe(device_t dev)
1137 if (pci_get_class(dev) != PCIC_DISPLAY ||
1138 pci_get_subclass(dev) != PCIS_DISPLAY_VGA)
1141 for (i = 0; i < sizeof(machfb_info) / sizeof(machfb_info[0]); i++) {
1142 if (pci_get_device(dev) == machfb_info[i].chip_id) {
1143 device_set_desc(dev, machfb_info[i].name);
1144 return (BUS_PROBE_DEFAULT);
1152 machfb_pci_attach(device_t dev)
1154 struct machfb_softc *sc;
1155 video_adapter_t *adp;
1163 node = ofw_bus_get_node(dev);
1164 if ((sc = (struct machfb_softc *)vid_get_adapter(vid_find_adapter(
1165 MACHFB_DRIVER_NAME, 0))) != NULL && sc->sc_node == node) {
1166 device_printf(dev, "console\n");
1167 device_set_softc(dev, sc);
1169 sc = device_get_softc(dev);
1172 sc->sc_chip_id = pci_get_device(dev);
1173 sc->sc_chip_rev = pci_get_revid(dev);
1179 * Allocate resources regardless of whether we are the console
1180 * and already obtained the bus tag and handle for the framebuffer
1181 * in machfb_configure() or not so the resources are marked as
1182 * taken in the respective RMAN.
1185 /* Enable memory and IO access. */
1186 pci_write_config(dev, PCIR_COMMAND,
1187 pci_read_config(dev, PCIR_COMMAND, 2) | PCIM_CMD_PORTEN |
1191 * NB: we need to take care that the framebuffer isn't mapped
1192 * in twice as besides wasting resources this isn't possible with
1196 if ((sc->sc_memres = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
1197 &rid, 0)) == NULL) {
1198 device_printf(dev, "cannot allocate memory resources\n");
1201 if (OF_getprop(sc->sc_node, "address", &u32, sizeof(u32)) > 0 &&
1202 vtophys(u32) == rman_get_bushandle(sc->sc_memres))
1203 adp->va_mem_base = u32;
1205 bus_release_resource(dev, SYS_RES_MEMORY,
1206 rman_get_rid(sc->sc_memres), sc->sc_memres);
1208 if ((sc->sc_memres = bus_alloc_resource_any(dev,
1209 SYS_RES_MEMORY, &rid, RF_ACTIVE)) == NULL) {
1211 "cannot allocate memory resources\n");
1215 (vm_offset_t)rman_get_virtual(sc->sc_memres);
1217 sc->sc_memt = rman_get_bustag(sc->sc_memres);
1218 sc->sc_memh = rman_get_bushandle(sc->sc_memres);
1219 sc->sc_regt = sc->sc_memt;
1220 bus_space_subregion(sc->sc_regt, sc->sc_memh, MACH64_REG_OFF,
1221 MACH64_REG_SIZE, &sc->sc_regh);
1222 adp->va_mem_size = rman_get_size(sc->sc_memres);
1223 adp->va_buffer = adp->va_mem_base;
1224 adp->va_buffer_size = adp->va_mem_size;
1225 sc->sc_mem = rman_get_start(sc->sc_memres);
1226 vi->vi_buffer = sc->sc_memh;
1227 vi->vi_buffer_size = adp->va_buffer_size;
1230 * Depending on the firmware version the VGA I/O and/or memory
1231 * resources of the Mach64 chips come up disabled. We generally
1232 * enable them above (pci(4) actually already did this unless
1233 * pci_enable_io_modes is not set) but this doesn't necessarily
1234 * mean that we get valid ones. Invalid resources seem to have
1235 * in common that they start at address 0. We don't allocate
1236 * them in this case in order to avoid warnings in apb(4) and
1237 * crashes when using these invalid resources. X.Org is aware
1238 * of this and doesn't use the VGA resources in this case (but
1239 * demands them if they are valid).
1242 if (bus_get_resource_start(dev, SYS_RES_MEMORY, rid) != 0) {
1243 if ((sc->sc_vmemres = bus_alloc_resource_any(dev,
1244 SYS_RES_MEMORY, &rid, RF_ACTIVE)) == NULL) {
1246 "cannot allocate VGA memory resources\n");
1251 (vm_offset_t)rman_get_virtual(sc->sc_vmemres);
1252 adp->va_registers_size = rman_get_size(sc->sc_vmemres);
1253 sc->sc_vmem = rman_get_start(sc->sc_vmemres);
1254 vi->vi_registers = rman_get_bushandle(sc->sc_vmemres);
1255 vi->vi_registers_size = adp->va_registers_size;
1258 if (!(sc->sc_flags & MACHFB_CONSOLE)) {
1259 if ((sw = vid_get_switch(MACHFB_DRIVER_NAME)) == NULL) {
1260 device_printf(dev, "cannot get video switch\n");
1265 * During device configuration we don't necessarily probe
1266 * the adapter which is the console first so we can't use
1267 * the device unit number for the video adapter unit. The
1268 * worst case would be that we use the video adapter unit
1269 * 0 twice. As it doesn't really matter which unit number
1270 * the corresponding video adapter has just use the next
1273 for (i = 0; i < devclass_get_maxunit(machfb_devclass); i++)
1274 if (vid_find_adapter(MACHFB_DRIVER_NAME, i) < 0)
1276 if ((error = sw->init(i, adp, 0)) != 0) {
1277 device_printf(dev, "cannot initialize adapter\n");
1283 * Test whether the aperture is byte swapped or not, set
1284 * va_window and va_window_size as appropriate. Note that
1285 * the aperture could be mapped either big or little endian
1286 * on independently of the endianess of the host so this
1287 * has to be a runtime test.
1289 p32 = (uint32_t *)adp->va_buffer;
1291 p = (uint8_t *)adp->va_buffer;
1293 if (!(p[0] == 0x12 && p[1] == 0x34 && p[2] == 0x56 && p[3] == 0x78)) {
1294 adp->va_window = adp->va_buffer + 0x800000;
1295 adp->va_window_size = adp->va_buffer_size - 0x800000;
1296 vi->vi_window = vi->vi_buffer + 0x800000;
1297 vi->vi_window_size = vi->vi_buffer_size - 0x800000;
1298 sc->sc_flags |= MACHFB_SWAP;
1300 adp->va_window = adp->va_buffer;
1301 adp->va_window_size = adp->va_buffer_size;
1302 vi->vi_window = vi->vi_buffer;
1303 vi->vi_window_size = vi->vi_buffer_size;
1306 adp->va_window_gran = adp->va_window_size;
1309 "%d MB aperture at %p %sswapped\n",
1310 (u_int)(adp->va_window_size / (1024 * 1024)),
1311 (void *)adp->va_window, (sc->sc_flags & MACHFB_SWAP) ?
1314 "%ld KB %s %d.%d MHz, maximum RAMDAC clock %d MHz, %sDSP\n",
1315 (u_long)sc->sc_memsize, machfb_memtype_names[sc->sc_memtype],
1316 sc->sc_mem_freq / 1000, sc->sc_mem_freq % 1000,
1317 sc->sc_ramdac_freq / 1000,
1318 (sc->sc_flags & MACHFB_DSP) ? "" : "no ");
1319 device_printf(dev, "resolution %dx%d at %d bpp\n",
1320 sc->sc_width, sc->sc_height, sc->sc_depth);
1323 * Allocate one page for the mouse pointer image at the end of
1324 * the little endian aperture, right before the memory mapped
1325 * registers that might also reside there. Must be done after
1326 * sc_memsize was set and possibly adjusted to account for the
1327 * memory mapped registers.
1329 sc->sc_curoff = (sc->sc_memsize * 1024) - PAGE_SIZE;
1330 sc->sc_memsize -= PAGE_SIZE / 1024;
1331 machfb_cursor_enable(sc, 0);
1332 /* Initialize with an all transparent image. */
1333 memset((void *)(adp->va_buffer + sc->sc_curoff), 0xaa, PAGE_SIZE);
1336 * Register a handler that performs some cosmetic surgery like
1337 * turning off the mouse pointer on halt in preparation for
1338 * handing the screen over to the OFW. Register another handler
1339 * that turns off the CRTC when resetting, otherwise the OFW
1340 * boot command issued by cpu_reset() just doesn't work.
1342 EVENTHANDLER_REGISTER(shutdown_final, machfb_shutdown_final, sc,
1343 SHUTDOWN_PRI_DEFAULT);
1344 EVENTHANDLER_REGISTER(shutdown_reset, machfb_shutdown_reset, sc,
1345 SHUTDOWN_PRI_DEFAULT);
1350 if (sc->sc_vmemres != NULL)
1351 bus_release_resource(dev, SYS_RES_MEMORY,
1352 rman_get_rid(sc->sc_vmemres), sc->sc_vmemres);
1354 bus_release_resource(dev, SYS_RES_MEMORY,
1355 rman_get_rid(sc->sc_memres), sc->sc_memres);
1361 machfb_pci_detach(device_t dev)
1368 * internal functions
1371 machfb_cursor_enable(struct machfb_softc *sc, int onoff)
1375 regw(sc, GEN_TEST_CNTL,
1376 regr(sc, GEN_TEST_CNTL) | HWCURSOR_ENABLE);
1378 regw(sc, GEN_TEST_CNTL,
1379 regr(sc, GEN_TEST_CNTL) &~ HWCURSOR_ENABLE);
1383 machfb_cursor_install(struct machfb_softc *sc)
1389 if (sc->sc_curoff == 0)
1392 machfb_cursor_enable(sc, 0);
1393 regw(sc, CUR_OFFSET, sc->sc_curoff >> 3);
1394 fg = SC_NORM_ATTR & 0xf;
1395 regw(sc, CUR_CLR0, machfb_default_cmap[fg].red << 24 |
1396 machfb_default_cmap[fg].green << 16 |
1397 machfb_default_cmap[fg].blue << 8);
1398 p = (uint16_t *)(sc->sc_va.va_buffer + sc->sc_curoff);
1399 for (i = 0; i < 64; i++) {
1400 for (j = 0; j < 8; j++) {
1401 v = machfb_mouse_pointer_lut[
1402 machfb_mouse_pointer_bits[i][j] >> 4] << 8 |
1403 machfb_mouse_pointer_lut[
1404 machfb_mouse_pointer_bits[i][j] & 0x0f];
1405 if (sc->sc_flags & MACHFB_SWAP)
1406 *(p++) = bswap16(v);
1416 machfb_get_memsize(struct machfb_softc *sc)
1419 const int const mem_tab[] = {
1420 512, 1024, 2048, 4096, 6144, 8192, 12288, 16384
1423 tmp = regr(sc, MEM_CNTL);
1425 printf("memcntl=0x%08x\n", tmp);
1427 if (sc->sc_flags & MACHFB_DSP) {
1430 memsize = (tmp + 1) * 512;
1432 memsize = (tmp - 3) * 1024;
1434 memsize = (tmp - 7) * 2048;
1436 memsize = mem_tab[tmp & 0x07];
1442 machfb_reset_engine(struct machfb_softc *sc)
1446 regw(sc, GEN_TEST_CNTL, regr(sc, GEN_TEST_CNTL) & ~GUI_ENGINE_ENABLE);
1448 /* Enable engine. */
1449 regw(sc, GEN_TEST_CNTL, regr(sc, GEN_TEST_CNTL) | GUI_ENGINE_ENABLE);
1452 * Ensure engine is not locked up by clearing any FIFO or
1455 regw(sc, BUS_CNTL, regr(sc, BUS_CNTL) | BUS_HOST_ERR_ACK |
1460 machfb_init_engine(struct machfb_softc *sc)
1462 uint32_t pitch_value;
1464 pitch_value = sc->sc_width;
1466 if (sc->sc_depth == 24)
1469 machfb_reset_engine(sc);
1471 wait_for_fifo(sc, 14);
1473 regw(sc, CONTEXT_MASK, 0xffffffff);
1475 regw(sc, DST_OFF_PITCH, (pitch_value / 8) << 22);
1477 regw(sc, DST_Y_X, 0);
1478 regw(sc, DST_HEIGHT, 0);
1479 regw(sc, DST_BRES_ERR, 0);
1480 regw(sc, DST_BRES_INC, 0);
1481 regw(sc, DST_BRES_DEC, 0);
1483 regw(sc, DST_CNTL, DST_LAST_PEL | DST_X_LEFT_TO_RIGHT |
1484 DST_Y_TOP_TO_BOTTOM);
1486 regw(sc, SRC_OFF_PITCH, (pitch_value / 8) << 22);
1488 regw(sc, SRC_Y_X, 0);
1489 regw(sc, SRC_HEIGHT1_WIDTH1, 1);
1490 regw(sc, SRC_Y_X_START, 0);
1491 regw(sc, SRC_HEIGHT2_WIDTH2, 1);
1493 regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT);
1495 wait_for_fifo(sc, 13);
1496 regw(sc, HOST_CNTL, 0);
1498 regw(sc, PAT_REG0, 0);
1499 regw(sc, PAT_REG1, 0);
1500 regw(sc, PAT_CNTL, 0);
1502 regw(sc, SC_LEFT, 0);
1503 regw(sc, SC_TOP, 0);
1504 regw(sc, SC_BOTTOM, sc->sc_height - 1);
1505 regw(sc, SC_RIGHT, pitch_value - 1);
1507 regw(sc, DP_BKGD_CLR, 0);
1508 regw(sc, DP_FRGD_CLR, 0xffffffff);
1509 regw(sc, DP_WRITE_MASK, 0xffffffff);
1510 regw(sc, DP_MIX, (MIX_SRC << 16) | MIX_DST);
1512 regw(sc, DP_SRC, FRGD_SRC_FRGD_CLR);
1514 wait_for_fifo(sc, 3);
1515 regw(sc, CLR_CMP_CLR, 0);
1516 regw(sc, CLR_CMP_MASK, 0xffffffff);
1517 regw(sc, CLR_CMP_CNTL, 0);
1519 wait_for_fifo(sc, 2);
1520 switch (sc->sc_depth) {
1522 regw(sc, DP_PIX_WIDTH, HOST_8BPP | SRC_8BPP | DST_8BPP);
1523 regw(sc, DP_CHAIN_MASK, DP_CHAIN_8BPP);
1524 regw(sc, DAC_CNTL, regr(sc, DAC_CNTL) | DAC_8BIT_EN);
1528 regw(sc, DP_PIX_WIDTH, HOST_32BPP | SRC_32BPP | DST_32BPP);
1529 regw(sc, DP_CHAIN_MASK, DP_CHAIN_32BPP);
1530 regw(sc, DAC_CNTL, regr(sc, DAC_CNTL) | DAC_8BIT_EN);
1535 wait_for_fifo(sc, 2);
1536 regw(sc, CRTC_INT_CNTL, regr(sc, CRTC_INT_CNTL) & ~0x20);
1537 regw(sc, GUI_TRAJ_CNTL, DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM);
1544 machfb_adjust_frame(struct machfb_softc *sc, int x, int y)
1548 offset = ((x + y * sc->sc_width) * (sc->sc_depth >> 3)) >> 3;
1550 regw(sc, CRTC_OFF_PITCH, (regr(sc, CRTC_OFF_PITCH) & 0xfff00000) |
1556 machfb_shutdown_final(void *v)
1558 struct machfb_softc *sc = v;
1560 machfb_cursor_enable(sc, 0);
1562 * In case this is the console set the cursor of the stdout
1563 * instance to the start of the last line so OFW output ends
1564 * up beneath what FreeBSD left on the screen.
1566 if (sc->sc_flags & MACHFB_CONSOLE) {
1567 OF_interpret("stdout @ is my-self 0 to column#", 0);
1568 OF_interpret("stdout @ is my-self #lines 1 - to line#", 0);
1573 machfb_shutdown_reset(void *v)
1575 struct machfb_softc *sc = v;
1577 machfb_blank_display(&sc->sc_va, V_DISPLAY_STAND_BY);