2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2002 Bang Jun-Young
5 * Copyright (c) 2005 Marius Strobl <marius@FreeBSD.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * from: NetBSD: machfb.c,v 1.23 2005/03/07 21:45:24 martin Exp
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
37 * Driver for ATI Mach64 graphics chips. Some code is derived from the
38 * ATI Rage Pro and Derivatives Programmer's Guide.
41 #include <sys/param.h>
42 #include <sys/systm.h>
44 #include <sys/consio.h>
45 #include <sys/endian.h>
46 #include <sys/eventhandler.h>
48 #include <sys/kernel.h>
49 #include <sys/module.h>
50 #include <sys/resource.h>
55 #include <dev/ofw/ofw_bus.h>
56 #include <dev/ofw/openfirm.h>
58 #include <machine/bus.h>
59 #include <machine/bus_private.h>
60 #include <machine/ofw_machdep.h>
61 #include <machine/resource.h>
62 #include <machine/sc_machdep.h>
66 #include <dev/fb/fbreg.h>
67 #include <dev/fb/gfb.h>
68 #include <dev/fb/machfbreg.h>
69 #include <dev/pci/pcivar.h>
70 #include <dev/pci/pcireg.h>
71 #include <dev/syscons/syscons.h>
73 /* #define MACHFB_DEBUG */
75 #define MACHFB_DRIVER_NAME "machfb"
77 #define MACH64_REG_OFF 0x7ffc00
78 #define MACH64_REG_SIZE 1024
81 video_adapter_t sc_va; /* must be first */
87 struct resource *sc_memres;
88 struct resource *sc_vmemres;
89 bus_space_tag_t sc_memt;
90 bus_space_tag_t sc_regt;
91 bus_space_tag_t sc_vmemt;
92 bus_space_handle_t sc_memh;
93 bus_space_handle_t sc_vmemh;
94 bus_space_handle_t sc_regh;
107 u_int sc_ramdac_freq;
111 u_int sc_mclk_post_div;
112 u_int sc_mclk_fb_div;
114 const u_char *sc_font;
116 vm_offset_t sc_curoff;
121 #define MACHFB_DRAW_CHAR (1 << 0)
122 #define MACHFB_DRAW_FILLRECT (1 << 1)
125 #define MACHFB_CONSOLE (1 << 0)
126 #define MACHFB_CUREN (1 << 1)
127 #define MACHFB_DSP (1 << 2)
128 #define MACHFB_SWAP (1 << 3)
131 static const struct {
134 uint32_t ramdac_freq;
136 { ATI_MACH64_CT, "ATI Mach64 CT", 135000 },
137 { ATI_RAGE_PRO_AGP, "ATI 3D Rage Pro (AGP)", 230000 },
138 { ATI_RAGE_PRO_AGP1X, "ATI 3D Rage Pro (AGP 1x)", 230000 },
139 { ATI_RAGE_PRO_PCI_B, "ATI 3D Rage Pro Turbo", 230000 },
140 { ATI_RAGE_XC_PCI66, "ATI Rage XL (PCI66)", 230000 },
141 { ATI_RAGE_XL_AGP, "ATI Rage XL (AGP)", 230000 },
142 { ATI_RAGE_XC_AGP, "ATI Rage XC (AGP)", 230000 },
143 { ATI_RAGE_XL_PCI66, "ATI Rage XL (PCI66)", 230000 },
144 { ATI_RAGE_PRO_PCI_P, "ATI 3D Rage Pro", 230000 },
145 { ATI_RAGE_PRO_PCI_L, "ATI 3D Rage Pro (limited 3D)", 230000 },
146 { ATI_RAGE_XL_PCI, "ATI Rage XL", 230000 },
147 { ATI_RAGE_XC_PCI, "ATI Rage XC", 230000 },
148 { ATI_RAGE_II, "ATI 3D Rage I/II", 135000 },
149 { ATI_RAGE_IIP, "ATI 3D Rage II+", 200000 },
150 { ATI_RAGE_IIC_PCI, "ATI 3D Rage IIC", 230000 },
151 { ATI_RAGE_IIC_AGP_B, "ATI 3D Rage IIC (AGP)", 230000 },
152 { ATI_RAGE_IIC_AGP_P, "ATI 3D Rage IIC (AGP)", 230000 },
153 { ATI_RAGE_LT_PRO_AGP, "ATI 3D Rage LT Pro (AGP 133MHz)", 230000 },
154 { ATI_RAGE_MOB_M3_PCI, "ATI Rage Mobility M3", 230000 },
155 { ATI_RAGE_MOB_M3_AGP, "ATI Rage Mobility M3 (AGP)", 230000 },
156 { ATI_RAGE_LT, "ATI 3D Rage LT", 230000 },
157 { ATI_RAGE_LT_PRO_PCI, "ATI 3D Rage LT Pro", 230000 },
158 { ATI_RAGE_MOBILITY, "ATI Rage Mobility", 230000 },
159 { ATI_RAGE_L_MOBILITY, "ATI Rage L Mobility", 230000 },
160 { ATI_RAGE_LT_PRO, "ATI 3D Rage LT Pro", 230000 },
161 { ATI_RAGE_LT_PRO2, "ATI 3D Rage LT Pro", 230000 },
162 { ATI_RAGE_MOB_M1_PCI, "ATI Rage Mobility M1 (PCI)", 230000 },
163 { ATI_RAGE_L_MOB_M1_PCI, "ATI Rage L Mobility (PCI)", 230000 },
164 { ATI_MACH64_VT, "ATI Mach64 VT", 170000 },
165 { ATI_MACH64_VTB, "ATI Mach64 VTB", 200000 },
166 { ATI_MACH64_VT4, "ATI Mach64 VT4", 230000 }
169 static const struct machfb_cmap {
173 } machfb_default_cmap[16] = {
174 {0x00, 0x00, 0x00}, /* black */
175 {0x00, 0x00, 0xff}, /* blue */
176 {0x00, 0xff, 0x00}, /* green */
177 {0x00, 0xc0, 0xc0}, /* cyan */
178 {0xff, 0x00, 0x00}, /* red */
179 {0xc0, 0x00, 0xc0}, /* magenta */
180 {0xc0, 0xc0, 0x00}, /* brown */
181 {0xc0, 0xc0, 0xc0}, /* light grey */
182 {0x80, 0x80, 0x80}, /* dark grey */
183 {0x80, 0x80, 0xff}, /* light blue */
184 {0x80, 0xff, 0x80}, /* light green */
185 {0x80, 0xff, 0xff}, /* light cyan */
186 {0xff, 0x80, 0x80}, /* light red */
187 {0xff, 0x80, 0xff}, /* light magenta */
188 {0xff, 0xff, 0x80}, /* yellow */
189 {0xff, 0xff, 0xff} /* white */
192 #define MACHFB_CMAP_OFF 16
194 static const u_char machfb_mouse_pointer_bits[64][8] = {
195 { 0x00, 0x00, }, /* ............ */
196 { 0x80, 0x00, }, /* *........... */
197 { 0xc0, 0x00, }, /* **.......... */
198 { 0xe0, 0x00, }, /* ***......... */
199 { 0xf0, 0x00, }, /* ****........ */
200 { 0xf8, 0x00, }, /* *****....... */
201 { 0xfc, 0x00, }, /* ******...... */
202 { 0xfe, 0x00, }, /* *******..... */
203 { 0xff, 0x00, }, /* ********.... */
204 { 0xff, 0x80, }, /* *********... */
205 { 0xfc, 0xc0, }, /* ******..**.. */
206 { 0xdc, 0x00, }, /* **.***...... */
207 { 0x8e, 0x00, }, /* *...***..... */
208 { 0x0e, 0x00, }, /* ....***..... */
209 { 0x07, 0x00, }, /* .....***.... */
210 { 0x04, 0x00, }, /* .....*...... */
211 { 0x00, 0x00, }, /* ............ */
212 { 0x00, 0x00, }, /* ............ */
213 { 0x00, 0x00, }, /* ............ */
214 { 0x00, 0x00, }, /* ............ */
215 { 0x00, 0x00, }, /* ............ */
216 { 0x00, 0x00, }, /* ............ */
220 * Lookup table to perform a bit-swap of the mouse pointer bits,
221 * map set bits to CUR_CLR0 and unset bits to transparent.
223 static const u_char machfb_mouse_pointer_lut[] = {
224 0xaa, 0x2a, 0x8a, 0x0a, 0xa2, 0x22, 0x82, 0x02,
225 0xa8, 0x28, 0x88, 0x08, 0xa0, 0x20, 0x80, 0x00
228 static const char *const machfb_memtype_names[] = {
229 "(N/A)", "DRAM", "EDO DRAM", "EDO DRAM", "SDRAM", "SGRAM", "WRAM",
233 extern const struct gfb_font gallant12x22;
235 static struct machfb_softc machfb_softc;
236 static struct bus_space_tag machfb_bst_store[1];
238 static device_probe_t machfb_pci_probe;
239 static device_attach_t machfb_pci_attach;
240 static device_detach_t machfb_pci_detach;
242 static device_method_t machfb_methods[] = {
243 /* Device interface */
244 DEVMETHOD(device_probe, machfb_pci_probe),
245 DEVMETHOD(device_attach, machfb_pci_attach),
246 DEVMETHOD(device_detach, machfb_pci_detach),
251 static driver_t machfb_pci_driver = {
254 sizeof(struct machfb_softc),
257 static devclass_t machfb_devclass;
259 DRIVER_MODULE(machfb, pci, machfb_pci_driver, machfb_devclass, 0, 0);
260 MODULE_DEPEND(machfb, pci, 1, 1, 1);
262 static void machfb_cursor_enable(struct machfb_softc *, int);
263 static int machfb_cursor_install(struct machfb_softc *);
264 static int machfb_get_memsize(struct machfb_softc *);
265 static void machfb_reset_engine(struct machfb_softc *);
266 static void machfb_init_engine(struct machfb_softc *);
268 static void machfb_adjust_frame(struct machfb_softc *, int, int);
270 static void machfb_shutdown_final(void *);
271 static void machfb_shutdown_reset(void *);
273 static int machfb_configure(int);
275 static vi_probe_t machfb_probe;
276 static vi_init_t machfb_init;
277 static vi_get_info_t machfb_get_info;
278 static vi_query_mode_t machfb_query_mode;
279 static vi_set_mode_t machfb_set_mode;
280 static vi_save_font_t machfb_save_font;
281 static vi_load_font_t machfb_load_font;
282 static vi_show_font_t machfb_show_font;
283 static vi_save_palette_t machfb_save_palette;
284 static vi_load_palette_t machfb_load_palette;
285 static vi_set_border_t machfb_set_border;
286 static vi_save_state_t machfb_save_state;
287 static vi_load_state_t machfb_load_state;
288 static vi_set_win_org_t machfb_set_win_org;
289 static vi_read_hw_cursor_t machfb_read_hw_cursor;
290 static vi_set_hw_cursor_t machfb_set_hw_cursor;
291 static vi_set_hw_cursor_shape_t machfb_set_hw_cursor_shape;
292 static vi_blank_display_t machfb_blank_display;
293 static vi_mmap_t machfb_mmap;
294 static vi_ioctl_t machfb_ioctl;
295 static vi_clear_t machfb_clear;
296 static vi_fill_rect_t machfb_fill_rect;
297 static vi_bitblt_t machfb_bitblt;
298 static vi_diag_t machfb_diag;
299 static vi_save_cursor_palette_t machfb_save_cursor_palette;
300 static vi_load_cursor_palette_t machfb_load_cursor_palette;
301 static vi_copy_t machfb_copy;
302 static vi_putp_t machfb_putp;
303 static vi_putc_t machfb_putc;
304 static vi_puts_t machfb_puts;
305 static vi_putm_t machfb_putm;
307 static video_switch_t machfbvidsw = {
308 .probe = machfb_probe,
310 .get_info = machfb_get_info,
311 .query_mode = machfb_query_mode,
312 .set_mode = machfb_set_mode,
313 .save_font = machfb_save_font,
314 .load_font = machfb_load_font,
315 .show_font = machfb_show_font,
316 .save_palette = machfb_save_palette,
317 .load_palette = machfb_load_palette,
318 .set_border = machfb_set_border,
319 .save_state = machfb_save_state,
320 .load_state = machfb_load_state,
321 .set_win_org = machfb_set_win_org,
322 .read_hw_cursor = machfb_read_hw_cursor,
323 .set_hw_cursor = machfb_set_hw_cursor,
324 .set_hw_cursor_shape = machfb_set_hw_cursor_shape,
325 .blank_display = machfb_blank_display,
327 .ioctl = machfb_ioctl,
328 .clear = machfb_clear,
329 .fill_rect = machfb_fill_rect,
330 .bitblt = machfb_bitblt,
332 .save_cursor_palette = machfb_save_cursor_palette,
333 .load_cursor_palette = machfb_load_cursor_palette,
341 VIDEO_DRIVER(machfb, machfbvidsw, machfb_configure);
343 extern sc_rndr_sw_t txtrndrsw;
344 RENDERER(machfb, 0, txtrndrsw, gfb_set);
346 RENDERER_MODULE(machfb, gfb_set);
349 * Inline functions for getting access to register aperture.
351 static inline uint32_t regr(struct machfb_softc *, uint32_t);
352 static inline uint8_t regrb(struct machfb_softc *, uint32_t);
353 static inline void regw(struct machfb_softc *, uint32_t, uint32_t);
354 static inline void regwb(struct machfb_softc *, uint32_t, uint8_t);
355 static inline void regwb_pll(struct machfb_softc *, uint32_t, uint8_t);
357 static inline uint32_t
358 regr(struct machfb_softc *sc, uint32_t index)
361 return bus_space_read_4(sc->sc_regt, sc->sc_regh, index);
364 static inline uint8_t
365 regrb(struct machfb_softc *sc, uint32_t index)
368 return bus_space_read_1(sc->sc_regt, sc->sc_regh, index);
372 regw(struct machfb_softc *sc, uint32_t index, uint32_t data)
375 bus_space_write_4(sc->sc_regt, sc->sc_regh, index, data);
376 bus_space_barrier(sc->sc_regt, sc->sc_regh, index, 4,
377 BUS_SPACE_BARRIER_WRITE);
381 regwb(struct machfb_softc *sc, uint32_t index, uint8_t data)
384 bus_space_write_1(sc->sc_regt, sc->sc_regh, index, data);
385 bus_space_barrier(sc->sc_regt, sc->sc_regh, index, 1,
386 BUS_SPACE_BARRIER_WRITE);
390 regwb_pll(struct machfb_softc *sc, uint32_t index, uint8_t data)
393 regwb(sc, CLOCK_CNTL + 1, (index << 2) | PLL_WR_EN);
394 regwb(sc, CLOCK_CNTL + 2, data);
395 regwb(sc, CLOCK_CNTL + 1, (index << 2) & ~PLL_WR_EN);
399 wait_for_fifo(struct machfb_softc *sc, uint8_t v)
402 while ((regr(sc, FIFO_STAT) & 0xffff) > (0x8000 >> v))
407 wait_for_idle(struct machfb_softc *sc)
410 wait_for_fifo(sc, 16);
411 while ((regr(sc, GUI_STAT) & 1) != 0)
416 * Inline functions for setting the background and foreground colors.
418 static inline void machfb_setbg(struct machfb_softc *sc, int bg);
419 static inline void machfb_setfg(struct machfb_softc *sc, int fg);
422 machfb_setbg(struct machfb_softc *sc, int bg)
425 if (bg == sc->sc_bg_cache)
427 sc->sc_bg_cache = bg;
428 wait_for_fifo(sc, 1);
429 regw(sc, DP_BKGD_CLR, bg + MACHFB_CMAP_OFF);
433 machfb_setfg(struct machfb_softc *sc, int fg)
436 if (fg == sc->sc_fg_cache)
438 sc->sc_fg_cache = fg;
439 wait_for_fifo(sc, 1);
440 regw(sc, DP_FRGD_CLR, fg + MACHFB_CMAP_OFF);
444 * video driver interface
447 machfb_configure(int flags)
449 struct machfb_softc *sc;
450 phandle_t chosen, output;
457 * For the high-level console probing return the number of
458 * registered adapters.
460 if (!(flags & VIO_PROBE_ONLY)) {
461 for (i = 0; vid_find_adapter(MACHFB_DRIVER_NAME, i) >= 0; i++)
466 /* Low-level console probing and initialization. */
469 if (sc->sc_va.va_flags & V_ADP_REGISTERED)
472 if ((chosen = OF_finddevice("/chosen")) == -1) /* Quis contra nos? */
474 if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1)
476 if ((output = OF_instance_to_package(stdout)) == -1)
478 if ((OF_getprop(output, "vendor-id", &id, sizeof(id)) == -1) ||
481 if (OF_getprop(output, "device-id", &id, sizeof(id)) == -1)
483 for (i = 0; i < nitems(machfb_info); i++) {
484 if (id == machfb_info[i].chip_id) {
485 sc->sc_flags = MACHFB_CONSOLE;
486 sc->sc_node = output;
491 if (!(sc->sc_flags & MACHFB_CONSOLE))
494 if (OF_getprop(output, "revision-id", &sc->sc_chip_rev,
495 sizeof(sc->sc_chip_rev)) == -1)
497 if (OF_decode_addr(output, 0, &space, &addr) != 0)
499 sc->sc_memt = &machfb_bst_store[0];
500 sc->sc_memh = sparc64_fake_bustag(space, addr, sc->sc_memt);
501 sc->sc_regt = sc->sc_memt;
502 bus_space_subregion(sc->sc_regt, sc->sc_memh, MACH64_REG_OFF,
503 MACH64_REG_SIZE, &sc->sc_regh);
505 if (machfb_init(0, &sc->sc_va, 0) < 0)
509 /* Return number of found adapters. */
514 machfb_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
521 machfb_init(int unit, video_adapter_t *adp, int flags)
523 struct machfb_softc *sc;
528 uint8_t dac_mask, dac_rindex, dac_windex;
530 sc = (struct machfb_softc *)adp;
533 if ((regr(sc, CONFIG_CHIP_ID) & 0xffff) != sc->sc_chip_id)
536 sc->sc_ramdac_freq = 0;
537 for (i = 0; i < nitems(machfb_info); i++) {
538 if (sc->sc_chip_id == machfb_info[i].chip_id) {
539 sc->sc_ramdac_freq = machfb_info[i].ramdac_freq;
543 if (sc->sc_ramdac_freq == 0)
545 if (sc->sc_chip_id == ATI_RAGE_II && sc->sc_chip_rev & 0x07)
546 sc->sc_ramdac_freq = 170000;
548 vid_init_struct(adp, MACHFB_DRIVER_NAME, -1, unit);
550 if (OF_getprop(sc->sc_node, "height", &sc->sc_height,
551 sizeof(sc->sc_height)) == -1)
553 if (OF_getprop(sc->sc_node, "width", &sc->sc_width,
554 sizeof(sc->sc_width)) == -1)
556 if (OF_getprop(sc->sc_node, "depth", &sc->sc_depth,
557 sizeof(sc->sc_depth)) == -1)
559 if ((options = OF_finddevice("/options")) == -1)
561 if (OF_getprop(options, "screen-#rows", buf, sizeof(buf)) == -1)
563 vi->vi_height = strtol(buf, NULL, 10);
564 if (OF_getprop(options, "screen-#columns", buf, sizeof(buf)) == -1)
566 vi->vi_width = strtol(buf, NULL, 10);
567 vi->vi_cwidth = gallant12x22.width;
568 vi->vi_cheight = gallant12x22.height;
569 vi->vi_flags = V_INFO_COLOR;
570 vi->vi_mem_model = V_INFO_MM_OTHER;
572 sc->sc_font = gallant12x22.data;
573 sc->sc_cbwidth = howmany(vi->vi_cwidth, NBBY); /* width in bytes */
574 sc->sc_xmargin = (sc->sc_width - (vi->vi_width * vi->vi_cwidth)) / 2;
575 sc->sc_ymargin = (sc->sc_height - (vi->vi_height * vi->vi_cheight)) / 2;
577 if (sc->sc_chip_id != ATI_MACH64_CT &&
578 !((sc->sc_chip_id == ATI_MACH64_VT ||
579 sc->sc_chip_id == ATI_RAGE_II) &&
580 (sc->sc_chip_rev & 0x07) == 0))
581 sc->sc_flags |= MACHFB_DSP;
583 sc->sc_memsize = machfb_get_memsize(sc);
584 if (sc->sc_memsize == 8192)
585 /* The last page is used as register aperture. */
587 sc->sc_memtype = regr(sc, CONFIG_STAT0) & 0x07;
589 if ((sc->sc_chip_id >= ATI_RAGE_XC_PCI66 &&
590 sc->sc_chip_id <= ATI_RAGE_XL_PCI66) ||
591 (sc->sc_chip_id >= ATI_RAGE_XL_PCI &&
592 sc->sc_chip_id <= ATI_RAGE_XC_PCI))
593 sc->sc_ref_freq = 29498;
595 sc->sc_ref_freq = 14318;
597 regwb(sc, CLOCK_CNTL + 1, PLL_REF_DIV << 2);
598 sc->sc_ref_div = regrb(sc, CLOCK_CNTL + 2);
599 regwb(sc, CLOCK_CNTL + 1, MCLK_FB_DIV << 2);
600 sc->sc_mclk_fb_div = regrb(sc, CLOCK_CNTL + 2);
601 sc->sc_mem_freq = (2 * sc->sc_ref_freq * sc->sc_mclk_fb_div) /
602 (sc->sc_ref_div * 2);
603 sc->sc_mclk_post_div = (sc->sc_mclk_fb_div * 2 * sc->sc_ref_freq) /
604 (sc->sc_mem_freq * sc->sc_ref_div);
606 machfb_init_engine(sc);
608 machfb_adjust_frame(0, 0);
610 machfb_set_mode(adp, 0);
613 * Install our 16-color color map. This is done only once and with
614 * an offset of 16 on sparc64 as there the OBP driver expects white
615 * to be at index 0 and black at 255 (some versions also use 1 - 8
616 * for color text support or the full palette for the boot banner
617 * logo but no versions seems to use the ISO 6429-1983 color map).
618 * Otherwise the colors are inverted when back in the OFW.
620 dac_rindex = regrb(sc, DAC_RINDEX);
621 dac_windex = regrb(sc, DAC_WINDEX);
622 dac_mask = regrb(sc, DAC_MASK);
623 regwb(sc, DAC_MASK, 0xff);
624 regwb(sc, DAC_WINDEX, MACHFB_CMAP_OFF);
625 for (i = 0; i < 16; i++) {
626 regwb(sc, DAC_DATA, machfb_default_cmap[i].red);
627 regwb(sc, DAC_DATA, machfb_default_cmap[i].green);
628 regwb(sc, DAC_DATA, machfb_default_cmap[i].blue);
630 regwb(sc, DAC_MASK, dac_mask);
631 regwb(sc, DAC_RINDEX, dac_rindex);
632 regwb(sc, DAC_WINDEX, dac_windex);
634 machfb_blank_display(adp, V_DISPLAY_ON);
638 * Setting V_ADP_MODECHANGE serves as hack so machfb_set_mode()
639 * (which will invalidate our caches) is called as a precaution
640 * when the X server shuts down.
642 adp->va_flags |= V_ADP_COLOR | V_ADP_MODECHANGE | V_ADP_PALETTE |
643 V_ADP_BORDER | V_ADP_INITIALIZED;
644 if (vid_register(adp) < 0)
646 adp->va_flags |= V_ADP_REGISTERED;
652 machfb_get_info(video_adapter_t *adp, int mode, video_info_t *info)
655 bcopy(&adp->va_info, info, sizeof(*info));
661 machfb_query_mode(video_adapter_t *adp, video_info_t *info)
668 machfb_set_mode(video_adapter_t *adp, int mode)
670 struct machfb_softc *sc;
672 sc = (struct machfb_softc *)adp;
674 sc->sc_bg_cache = -1;
675 sc->sc_fg_cache = -1;
676 sc->sc_draw_cache = 0;
682 machfb_save_font(video_adapter_t *adp, int page, int size, int width,
683 u_char *data, int c, int count)
690 machfb_load_font(video_adapter_t *adp, int page, int size, int width,
691 u_char *data, int c, int count)
698 machfb_show_font(video_adapter_t *adp, int page)
705 machfb_save_palette(video_adapter_t *adp, u_char *palette)
707 struct machfb_softc *sc;
709 uint8_t dac_mask, dac_rindex, dac_windex;
711 sc = (struct machfb_softc *)adp;
713 dac_rindex = regrb(sc, DAC_RINDEX);
714 dac_windex = regrb(sc, DAC_WINDEX);
715 dac_mask = regrb(sc, DAC_MASK);
716 regwb(sc, DAC_MASK, 0xff);
717 regwb(sc, DAC_RINDEX, 0x0);
718 for (i = 0; i < 256 * 3; i++)
719 palette[i] = regrb(sc, DAC_DATA);
720 regwb(sc, DAC_MASK, dac_mask);
721 regwb(sc, DAC_RINDEX, dac_rindex);
722 regwb(sc, DAC_WINDEX, dac_windex);
728 machfb_load_palette(video_adapter_t *adp, u_char *palette)
730 struct machfb_softc *sc;
732 uint8_t dac_mask, dac_rindex, dac_windex;
734 sc = (struct machfb_softc *)adp;
736 dac_rindex = regrb(sc, DAC_RINDEX);
737 dac_windex = regrb(sc, DAC_WINDEX);
738 dac_mask = regrb(sc, DAC_MASK);
739 regwb(sc, DAC_MASK, 0xff);
740 regwb(sc, DAC_WINDEX, 0x0);
741 for (i = 0; i < 256 * 3; i++)
742 regwb(sc, DAC_DATA, palette[i]);
743 regwb(sc, DAC_MASK, dac_mask);
744 regwb(sc, DAC_RINDEX, dac_rindex);
745 regwb(sc, DAC_WINDEX, dac_windex);
751 machfb_set_border(video_adapter_t *adp, int border)
753 struct machfb_softc *sc;
755 sc = (struct machfb_softc *)adp;
757 machfb_fill_rect(adp, border, 0, 0, sc->sc_width, sc->sc_ymargin);
758 machfb_fill_rect(adp, border, 0, sc->sc_height - sc->sc_ymargin,
759 sc->sc_width, sc->sc_ymargin);
760 machfb_fill_rect(adp, border, 0, 0, sc->sc_xmargin, sc->sc_height);
761 machfb_fill_rect(adp, border, sc->sc_width - sc->sc_xmargin, 0,
762 sc->sc_xmargin, sc->sc_height);
768 machfb_save_state(video_adapter_t *adp, void *p, size_t size)
775 machfb_load_state(video_adapter_t *adp, void *p)
782 machfb_set_win_org(video_adapter_t *adp, off_t offset)
789 machfb_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
799 machfb_set_hw_cursor(video_adapter_t *adp, int col, int row)
806 machfb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
807 int celsize, int blink)
814 machfb_blank_display(video_adapter_t *adp, int mode)
816 struct machfb_softc *sc;
817 uint32_t crtc_gen_cntl;
819 sc = (struct machfb_softc *)adp;
821 crtc_gen_cntl = (regr(sc, CRTC_GEN_CNTL) | CRTC_EXT_DISP_EN | CRTC_EN) &
822 ~(CRTC_HSYNC_DIS | CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS);
826 case V_DISPLAY_BLANK:
827 crtc_gen_cntl |= CRTC_HSYNC_DIS | CRTC_VSYNC_DIS |
830 case V_DISPLAY_STAND_BY:
831 crtc_gen_cntl |= CRTC_HSYNC_DIS | CRTC_DISPLAY_DIS;
833 case V_DISPLAY_SUSPEND:
834 crtc_gen_cntl |= CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS;
837 regw(sc, CRTC_GEN_CNTL, crtc_gen_cntl);
843 machfb_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr,
844 int prot, vm_memattr_t *memattr)
846 struct machfb_softc *sc;
849 sc = (struct machfb_softc *)adp;
852 /* BAR 2 - VGA memory */
853 if (sc->sc_vmem != 0 && offset >= sc->sc_vmem &&
854 offset < sc->sc_vmem + vi->vi_registers_size) {
855 *paddr = vi->vi_registers + offset - sc->sc_vmem;
859 /* BAR 0 - framebuffer */
860 if (offset >= sc->sc_mem &&
861 offset < sc->sc_mem + vi->vi_buffer_size) {
862 *paddr = vi->vi_buffer + offset - sc->sc_mem;
866 /* 'regular' framebuffer mmap()ing */
867 if (offset < adp->va_window_size) {
868 *paddr = vi->vi_window + offset;
876 machfb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data)
878 struct machfb_softc *sc;
879 struct fbcursor *fbc;
882 sc = (struct machfb_softc *)adp;
886 fb = (struct fbtype *)data;
887 fb->fb_type = FBTYPE_PCIMISC;
888 fb->fb_height = sc->sc_height;
889 fb->fb_width = sc->sc_width;
890 fb->fb_depth = sc->sc_depth;
891 if (sc->sc_depth <= 1 || sc->sc_depth > 8)
894 fb->fb_cmsize = 1 << sc->sc_depth;
895 fb->fb_size = adp->va_buffer_size;
898 fbc = (struct fbcursor *)data;
899 if (fbc->set & FB_CUR_SETCUR && fbc->enable == 0) {
900 machfb_cursor_enable(sc, 0);
901 sc->sc_flags &= ~MACHFB_CUREN;
906 return (fb_commonioctl(adp, cmd, data));
913 machfb_clear(video_adapter_t *adp)
915 struct machfb_softc *sc;
917 sc = (struct machfb_softc *)adp;
919 machfb_fill_rect(adp, (SC_NORM_ATTR >> 4) & 0xf, 0, 0, sc->sc_width,
926 machfb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
928 struct machfb_softc *sc;
930 sc = (struct machfb_softc *)adp;
932 if (sc->sc_draw_cache != MACHFB_DRAW_FILLRECT) {
933 wait_for_fifo(sc, 7);
934 regw(sc, DP_WRITE_MASK, 0xff);
935 regw(sc, DP_PIX_WIDTH, DST_8BPP | SRC_8BPP | HOST_8BPP);
936 regw(sc, DP_SRC, FRGD_SRC_FRGD_CLR);
937 regw(sc, DP_MIX, MIX_SRC << 16);
938 regw(sc, CLR_CMP_CNTL, 0); /* no transparency */
939 regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT);
940 regw(sc, DST_CNTL, DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM);
941 sc->sc_draw_cache = MACHFB_DRAW_FILLRECT;
943 machfb_setfg(sc, val);
944 wait_for_fifo(sc, 4);
945 regw(sc, SRC_Y_X, (x << 16) | y);
946 regw(sc, SRC_WIDTH1, cx);
947 regw(sc, DST_Y_X, (x << 16) | y);
948 regw(sc, DST_HEIGHT_WIDTH, (cx << 16) | cy);
954 machfb_bitblt(video_adapter_t *adp, ...)
961 machfb_diag(video_adapter_t *adp, int level)
965 fb_dump_adp_info(adp->va_name, adp, level);
966 machfb_get_info(adp, 0, &info);
967 fb_dump_mode_info(adp->va_name, adp, &info, level);
973 machfb_save_cursor_palette(video_adapter_t *adp, u_char *palette)
980 machfb_load_cursor_palette(video_adapter_t *adp, u_char *palette)
987 machfb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n)
994 machfb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a,
995 int size, int bpp, int bit_ltor, int byte_ltor)
1002 machfb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a)
1004 struct machfb_softc *sc;
1008 sc = (struct machfb_softc *)adp;
1010 if (sc->sc_draw_cache != MACHFB_DRAW_CHAR) {
1011 wait_for_fifo(sc, 8);
1012 regw(sc, DP_WRITE_MASK, 0xff); /* XXX only good for 8 bit */
1013 regw(sc, DP_PIX_WIDTH, DST_8BPP | SRC_1BPP | HOST_1BPP);
1014 regw(sc, DP_SRC, MONO_SRC_HOST | BKGD_SRC_BKGD_CLR |
1016 regw(sc, DP_MIX ,((MIX_SRC & 0xffff) << 16) | MIX_SRC);
1017 regw(sc, CLR_CMP_CNTL, 0); /* no transparency */
1018 regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT);
1019 regw(sc, DST_CNTL, DST_Y_TOP_TO_BOTTOM | DST_X_LEFT_TO_RIGHT);
1020 regw(sc, HOST_CNTL, HOST_BYTE_ALIGN);
1021 sc->sc_draw_cache = MACHFB_DRAW_CHAR;
1023 machfb_setbg(sc, (a >> 4) & 0xf);
1024 machfb_setfg(sc, a & 0xf);
1025 wait_for_fifo(sc, 4 + (adp->va_info.vi_cheight / sc->sc_cbwidth));
1026 regw(sc, SRC_Y_X, 0);
1027 regw(sc, SRC_WIDTH1, adp->va_info.vi_cwidth);
1028 regw(sc, DST_Y_X, ((((off % adp->va_info.vi_width) *
1029 adp->va_info.vi_cwidth) + sc->sc_xmargin) << 16) |
1030 (((off / adp->va_info.vi_width) * adp->va_info.vi_cheight) +
1032 regw(sc, DST_HEIGHT_WIDTH, (adp->va_info.vi_cwidth << 16) |
1033 adp->va_info.vi_cheight);
1034 p = sc->sc_font + (c * adp->va_info.vi_cheight * sc->sc_cbwidth);
1035 for (i = 0; i < adp->va_info.vi_cheight * sc->sc_cbwidth; i += 4)
1036 regw(sc, HOST_DATA0 + i, (p[i + 3] << 24 | p[i + 2] << 16 |
1037 p[i + 1] << 8 | p[i]));
1043 machfb_puts(video_adapter_t *adp, vm_offset_t off, uint16_t *s, int len)
1045 struct machfb_softc *sc;
1046 int blanks, i, x1, x2, y1, y2;
1047 uint8_t a, c, color1, color2;
1049 sc = (struct machfb_softc *)adp;
1051 #define MACHFB_BLANK machfb_fill_rect(adp, color1, x1, y1, \
1052 blanks * adp->va_info.vi_cwidth, \
1053 adp->va_info.vi_cheight)
1055 blanks = color1 = x1 = y1 = 0;
1056 for (i = 0; i < len; i++) {
1058 * Accelerate continuous blanks by drawing a respective
1059 * rectangle instead. Drawing a rectangle of any size
1060 * takes about the same number of operations as drawing
1061 * a single character.
1064 a = (s[i] & 0xff00) >> 8;
1065 if (c == 0x00 || c == 0x20 || c == 0xdb || c == 0xff) {
1066 color2 = (a >> (c == 0xdb ? 0 : 4) & 0xf);
1067 x2 = (((off + i) % adp->va_info.vi_width) *
1068 adp->va_info.vi_cwidth) + sc->sc_xmargin;
1069 y2 = (((off + i) / adp->va_info.vi_width) *
1070 adp->va_info.vi_cheight) + sc->sc_ymargin;
1076 } else if (color1 != color2 || y1 != y2) {
1089 vidd_putc(adp, off + i, c, a);
1101 machfb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image,
1102 uint32_t pixel_mask, int size, int width)
1104 struct machfb_softc *sc;
1107 sc = (struct machfb_softc *)adp;
1109 if ((!(sc->sc_flags & MACHFB_CUREN)) &&
1110 (error = machfb_cursor_install(sc)) < 0)
1114 * The hardware cursor always must be disabled when
1115 * fiddling with its bits otherwise some artifacts
1116 * may appear on the screen.
1118 machfb_cursor_enable(sc, 0);
1121 regw(sc, CUR_HORZ_VERT_OFF, 0);
1122 if ((regr(sc, GEN_TEST_CNTL) & CRTC_DBL_SCAN_EN) != 0)
1124 regw(sc, CUR_HORZ_VERT_POSN, ((y + sc->sc_ymargin) << 16) |
1125 (x + sc->sc_xmargin));
1126 machfb_cursor_enable(sc, 1);
1127 sc->sc_flags |= MACHFB_CUREN;
1136 machfb_pci_probe(device_t dev)
1140 if (pci_get_class(dev) != PCIC_DISPLAY ||
1141 pci_get_subclass(dev) != PCIS_DISPLAY_VGA)
1144 for (i = 0; i < nitems(machfb_info); i++) {
1145 if (pci_get_device(dev) == machfb_info[i].chip_id) {
1146 device_set_desc(dev, machfb_info[i].name);
1147 return (BUS_PROBE_DEFAULT);
1155 machfb_pci_attach(device_t dev)
1157 struct machfb_softc *sc;
1158 video_adapter_t *adp;
1166 node = ofw_bus_get_node(dev);
1167 if ((sc = (struct machfb_softc *)vid_get_adapter(vid_find_adapter(
1168 MACHFB_DRIVER_NAME, 0))) != NULL && sc->sc_node == node) {
1169 device_printf(dev, "console\n");
1170 device_set_softc(dev, sc);
1172 sc = device_get_softc(dev);
1175 sc->sc_chip_id = pci_get_device(dev);
1176 sc->sc_chip_rev = pci_get_revid(dev);
1182 if ((sc->sc_memres = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
1183 RF_ACTIVE)) == NULL) {
1184 device_printf(dev, "cannot allocate memory resources\n");
1187 sc->sc_memt = rman_get_bustag(sc->sc_memres);
1188 sc->sc_memh = rman_get_bushandle(sc->sc_memres);
1189 sc->sc_mem = rman_get_start(sc->sc_memres);
1190 vi->vi_buffer = sc->sc_memh;
1191 vi->vi_buffer_size = rman_get_size(sc->sc_memres);
1192 if (OF_getprop(sc->sc_node, "address", &u32, sizeof(u32)) > 0 &&
1193 vtophys(u32) == sc->sc_memh)
1194 adp->va_mem_base = u32;
1196 if (bus_space_map(sc->sc_memt, vi->vi_buffer,
1197 vi->vi_buffer_size, BUS_SPACE_MAP_LINEAR,
1198 &sc->sc_memh) != 0) {
1199 device_printf(dev, "cannot map memory resources\n");
1204 (vm_offset_t)rman_get_virtual(sc->sc_memres);
1206 adp->va_mem_size = vi->vi_buffer_size;
1207 adp->va_buffer = adp->va_mem_base;
1208 adp->va_buffer_size = adp->va_mem_size;
1209 sc->sc_regt = sc->sc_memt;
1210 if (bus_space_subregion(sc->sc_regt, sc->sc_memh, MACH64_REG_OFF,
1211 MACH64_REG_SIZE, &sc->sc_regh) != 0) {
1212 device_printf(dev, "cannot allocate register resources\n");
1218 * Depending on the firmware version the VGA I/O and/or memory
1219 * resources of the Mach64 chips come up disabled. These will be
1220 * enabled by pci(4) when activating the resource in question but
1221 * this doesn't necessarily mean that the resource is valid.
1222 * Invalid resources seem to have in common that they start at
1223 * address 0. We don't allocate the VGA memory in this case in
1224 * order to avoid warnings in apb(4) and crashes when using this
1225 * invalid resources. X.Org is aware of this and doesn't use the
1226 * VGA memory resource in this case (but demands it if it's valid).
1229 if (bus_get_resource_start(dev, SYS_RES_MEMORY, rid) != 0) {
1230 if ((sc->sc_vmemres = bus_alloc_resource_any(dev,
1231 SYS_RES_MEMORY, &rid, RF_ACTIVE)) == NULL) {
1233 "cannot allocate VGA memory resources\n");
1237 sc->sc_vmemt = rman_get_bustag(sc->sc_vmemres);
1238 sc->sc_vmemh = rman_get_bushandle(sc->sc_vmemres);
1239 sc->sc_vmem = rman_get_start(sc->sc_vmemres);
1240 vi->vi_registers = sc->sc_vmemh;
1241 vi->vi_registers_size = rman_get_size(sc->sc_vmemres);
1242 if (bus_space_map(sc->sc_vmemt, vi->vi_registers,
1243 vi->vi_registers_size, BUS_SPACE_MAP_LINEAR,
1244 &sc->sc_vmemh) != 0) {
1246 "cannot map VGA memory resources\n");
1251 (vm_offset_t)rman_get_virtual(sc->sc_vmemres);
1252 adp->va_registers_size = vi->vi_registers_size;
1255 if (!(sc->sc_flags & MACHFB_CONSOLE)) {
1256 if ((sw = vid_get_switch(MACHFB_DRIVER_NAME)) == NULL) {
1257 device_printf(dev, "cannot get video switch\n");
1262 * During device configuration we don't necessarily probe
1263 * the adapter which is the console first so we can't use
1264 * the device unit number for the video adapter unit. The
1265 * worst case would be that we use the video adapter unit
1266 * 0 twice. As it doesn't really matter which unit number
1267 * the corresponding video adapter has just use the next
1270 for (i = 0; i < devclass_get_maxunit(machfb_devclass); i++)
1271 if (vid_find_adapter(MACHFB_DRIVER_NAME, i) < 0)
1273 if ((error = sw->init(i, adp, 0)) != 0) {
1274 device_printf(dev, "cannot initialize adapter\n");
1280 * Test whether the aperture is byte swapped or not, set
1281 * va_window and va_window_size as appropriate. Note that
1282 * the aperture could be mapped either big or little endian
1283 * independently of the endianness of the host so this has
1284 * to be a runtime test.
1286 p32 = (uint32_t *)adp->va_buffer;
1288 p = (uint8_t *)adp->va_buffer;
1290 if (!(p[0] == 0x12 && p[1] == 0x34 && p[2] == 0x56 && p[3] == 0x78)) {
1291 adp->va_window = adp->va_buffer + 0x800000;
1292 adp->va_window_size = adp->va_buffer_size - 0x800000;
1293 vi->vi_window = vi->vi_buffer + 0x800000;
1294 vi->vi_window_size = vi->vi_buffer_size - 0x800000;
1295 sc->sc_flags |= MACHFB_SWAP;
1297 adp->va_window = adp->va_buffer;
1298 adp->va_window_size = adp->va_buffer_size;
1299 vi->vi_window = vi->vi_buffer;
1300 vi->vi_window_size = vi->vi_buffer_size;
1303 adp->va_window_gran = adp->va_window_size;
1306 "%d MB aperture at %p %sswapped\n",
1307 (u_int)(adp->va_window_size / (1024 * 1024)),
1308 (void *)adp->va_window, (sc->sc_flags & MACHFB_SWAP) ?
1311 "%ld KB %s %d.%d MHz, maximum RAMDAC clock %d MHz, %sDSP\n",
1312 (u_long)sc->sc_memsize, machfb_memtype_names[sc->sc_memtype],
1313 sc->sc_mem_freq / 1000, sc->sc_mem_freq % 1000,
1314 sc->sc_ramdac_freq / 1000,
1315 (sc->sc_flags & MACHFB_DSP) ? "" : "no ");
1316 device_printf(dev, "resolution %dx%d at %d bpp\n",
1317 sc->sc_width, sc->sc_height, sc->sc_depth);
1320 * Allocate one page for the mouse pointer image at the end of
1321 * the little endian aperture, right before the memory mapped
1322 * registers that might also reside there. Must be done after
1323 * sc_memsize was set and possibly adjusted to account for the
1324 * memory mapped registers.
1326 sc->sc_curoff = (sc->sc_memsize * 1024) - PAGE_SIZE;
1327 sc->sc_memsize -= PAGE_SIZE / 1024;
1328 machfb_cursor_enable(sc, 0);
1329 /* Initialize with an all transparent image. */
1330 memset((void *)(adp->va_buffer + sc->sc_curoff), 0xaa, PAGE_SIZE);
1333 * Register a handler that performs some cosmetic surgery like
1334 * turning off the mouse pointer on halt in preparation for
1335 * handing the screen over to the OFW. Register another handler
1336 * that turns off the CRTC when resetting, otherwise the OFW
1337 * boot command issued by cpu_reset() just doesn't work.
1339 EVENTHANDLER_REGISTER(shutdown_final, machfb_shutdown_final, sc,
1340 SHUTDOWN_PRI_DEFAULT);
1341 EVENTHANDLER_REGISTER(shutdown_reset, machfb_shutdown_reset, sc,
1342 SHUTDOWN_PRI_DEFAULT);
1347 if (adp->va_registers != 0)
1348 bus_space_unmap(sc->sc_vmemt, sc->sc_vmemh,
1349 vi->vi_registers_size);
1351 if (sc->sc_vmemres != NULL)
1352 bus_release_resource(dev, SYS_RES_MEMORY,
1353 rman_get_rid(sc->sc_vmemres), sc->sc_vmemres);
1355 bus_space_unmap(sc->sc_memt, sc->sc_memh, vi->vi_buffer_size);
1357 bus_release_resource(dev, SYS_RES_MEMORY,
1358 rman_get_rid(sc->sc_memres), sc->sc_memres);
1364 machfb_pci_detach(device_t dev)
1371 * internal functions
1374 machfb_cursor_enable(struct machfb_softc *sc, int onoff)
1378 regw(sc, GEN_TEST_CNTL,
1379 regr(sc, GEN_TEST_CNTL) | HWCURSOR_ENABLE);
1381 regw(sc, GEN_TEST_CNTL,
1382 regr(sc, GEN_TEST_CNTL) &~ HWCURSOR_ENABLE);
1386 machfb_cursor_install(struct machfb_softc *sc)
1392 if (sc->sc_curoff == 0)
1395 machfb_cursor_enable(sc, 0);
1396 regw(sc, CUR_OFFSET, sc->sc_curoff >> 3);
1397 fg = SC_NORM_ATTR & 0xf;
1398 regw(sc, CUR_CLR0, machfb_default_cmap[fg].red << 24 |
1399 machfb_default_cmap[fg].green << 16 |
1400 machfb_default_cmap[fg].blue << 8);
1401 p = (uint16_t *)(sc->sc_va.va_buffer + sc->sc_curoff);
1402 for (i = 0; i < 64; i++) {
1403 for (j = 0; j < 8; j++) {
1404 v = machfb_mouse_pointer_lut[
1405 machfb_mouse_pointer_bits[i][j] >> 4] << 8 |
1406 machfb_mouse_pointer_lut[
1407 machfb_mouse_pointer_bits[i][j] & 0x0f];
1408 if (sc->sc_flags & MACHFB_SWAP)
1409 *(p++) = bswap16(v);
1419 machfb_get_memsize(struct machfb_softc *sc)
1422 const int mem_tab[] = {
1423 512, 1024, 2048, 4096, 6144, 8192, 12288, 16384
1426 tmp = regr(sc, MEM_CNTL);
1428 printf("memcntl=0x%08x\n", tmp);
1430 if (sc->sc_flags & MACHFB_DSP) {
1433 memsize = (tmp + 1) * 512;
1435 memsize = (tmp - 3) * 1024;
1437 memsize = (tmp - 7) * 2048;
1439 memsize = mem_tab[tmp & 0x07];
1445 machfb_reset_engine(struct machfb_softc *sc)
1449 regw(sc, GEN_TEST_CNTL, regr(sc, GEN_TEST_CNTL) & ~GUI_ENGINE_ENABLE);
1451 /* Enable engine. */
1452 regw(sc, GEN_TEST_CNTL, regr(sc, GEN_TEST_CNTL) | GUI_ENGINE_ENABLE);
1455 * Ensure engine is not locked up by clearing any FIFO or
1458 regw(sc, BUS_CNTL, regr(sc, BUS_CNTL) | BUS_HOST_ERR_ACK |
1463 machfb_init_engine(struct machfb_softc *sc)
1465 uint32_t pitch_value;
1467 pitch_value = sc->sc_width;
1469 if (sc->sc_depth == 24)
1472 machfb_reset_engine(sc);
1474 wait_for_fifo(sc, 14);
1476 regw(sc, CONTEXT_MASK, 0xffffffff);
1478 regw(sc, DST_OFF_PITCH, (pitch_value / 8) << 22);
1480 regw(sc, DST_Y_X, 0);
1481 regw(sc, DST_HEIGHT, 0);
1482 regw(sc, DST_BRES_ERR, 0);
1483 regw(sc, DST_BRES_INC, 0);
1484 regw(sc, DST_BRES_DEC, 0);
1486 regw(sc, DST_CNTL, DST_LAST_PEL | DST_X_LEFT_TO_RIGHT |
1487 DST_Y_TOP_TO_BOTTOM);
1489 regw(sc, SRC_OFF_PITCH, (pitch_value / 8) << 22);
1491 regw(sc, SRC_Y_X, 0);
1492 regw(sc, SRC_HEIGHT1_WIDTH1, 1);
1493 regw(sc, SRC_Y_X_START, 0);
1494 regw(sc, SRC_HEIGHT2_WIDTH2, 1);
1496 regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT);
1498 wait_for_fifo(sc, 13);
1499 regw(sc, HOST_CNTL, 0);
1501 regw(sc, PAT_REG0, 0);
1502 regw(sc, PAT_REG1, 0);
1503 regw(sc, PAT_CNTL, 0);
1505 regw(sc, SC_LEFT, 0);
1506 regw(sc, SC_TOP, 0);
1507 regw(sc, SC_BOTTOM, sc->sc_height - 1);
1508 regw(sc, SC_RIGHT, pitch_value - 1);
1510 regw(sc, DP_BKGD_CLR, 0);
1511 regw(sc, DP_FRGD_CLR, 0xffffffff);
1512 regw(sc, DP_WRITE_MASK, 0xffffffff);
1513 regw(sc, DP_MIX, (MIX_SRC << 16) | MIX_DST);
1515 regw(sc, DP_SRC, FRGD_SRC_FRGD_CLR);
1517 wait_for_fifo(sc, 3);
1518 regw(sc, CLR_CMP_CLR, 0);
1519 regw(sc, CLR_CMP_MASK, 0xffffffff);
1520 regw(sc, CLR_CMP_CNTL, 0);
1522 wait_for_fifo(sc, 2);
1523 switch (sc->sc_depth) {
1525 regw(sc, DP_PIX_WIDTH, HOST_8BPP | SRC_8BPP | DST_8BPP);
1526 regw(sc, DP_CHAIN_MASK, DP_CHAIN_8BPP);
1527 regw(sc, DAC_CNTL, regr(sc, DAC_CNTL) | DAC_8BIT_EN);
1531 regw(sc, DP_PIX_WIDTH, HOST_32BPP | SRC_32BPP | DST_32BPP);
1532 regw(sc, DP_CHAIN_MASK, DP_CHAIN_32BPP);
1533 regw(sc, DAC_CNTL, regr(sc, DAC_CNTL) | DAC_8BIT_EN);
1538 wait_for_fifo(sc, 2);
1539 regw(sc, CRTC_INT_CNTL, regr(sc, CRTC_INT_CNTL) & ~0x20);
1540 regw(sc, GUI_TRAJ_CNTL, DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM);
1547 machfb_adjust_frame(struct machfb_softc *sc, int x, int y)
1551 offset = ((x + y * sc->sc_width) * (sc->sc_depth >> 3)) >> 3;
1553 regw(sc, CRTC_OFF_PITCH, (regr(sc, CRTC_OFF_PITCH) & 0xfff00000) |
1559 machfb_shutdown_final(void *v)
1561 struct machfb_softc *sc = v;
1563 machfb_cursor_enable(sc, 0);
1565 * In case this is the console set the cursor of the stdout
1566 * instance to the start of the last line so OFW output ends
1567 * up beneath what FreeBSD left on the screen.
1569 if (sc->sc_flags & MACHFB_CONSOLE) {
1570 OF_interpret("stdout @ is my-self 0 to column#", 0);
1571 OF_interpret("stdout @ is my-self #lines 1 - to line#", 0);
1576 machfb_shutdown_reset(void *v)
1578 struct machfb_softc *sc = v;
1580 machfb_blank_display(&sc->sc_va, V_DISPLAY_STAND_BY);