2 * Copyright (c) 2002 Bang Jun-Young
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * from: NetBSD: machfb.c,v 1.23 2005/03/07 21:45:24 martin Exp
30 * Copyright (c) 2005 Marius Strobl <marius@FreeBSD.org>
31 * All rights reserved.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions, and the following disclaimer,
38 * without modification, immediately at the beginning of the file.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in
41 * the documentation and/or other materials provided with the
44 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
48 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 #include <sys/cdefs.h>
58 __FBSDID("$FreeBSD$");
61 * Driver for ATI Mach64 graphics chips. Some code is derived from the
62 * ATI Rage Pro and Derivatives Programmer's Guide.
65 #include <sys/param.h>
66 #include <sys/systm.h>
68 #include <sys/consio.h>
69 #include <sys/eventhandler.h>
71 #include <sys/kernel.h>
72 #include <sys/module.h>
73 #include <sys/resource.h>
75 #include <dev/ofw/ofw_bus.h>
76 #include <dev/ofw/openfirm.h>
78 #include <machine/bus.h>
79 #include <machine/bus_private.h>
80 #include <machine/ofw_machdep.h>
81 #include <machine/resource.h>
82 #include <machine/sc_machdep.h>
86 #include <dev/fb/fbreg.h>
87 #include <dev/fb/gallant12x22.h>
88 #include <dev/fb/machfbreg.h>
89 #include <dev/pci/pcivar.h>
90 #include <dev/pci/pcireg.h>
91 #include <dev/syscons/syscons.h>
93 /* #define MACHFB_DEBUG */
95 #define MACHFB_DRIVER_NAME "machfb"
97 #define MACH64_REG_OFF 0x7ffc00
98 #define MACH64_REG_SIZE 1024
100 struct machfb_softc {
101 video_adapter_t sc_va; /* must be first */
110 struct resource *sc_memres;
111 struct resource *sc_viores;
112 struct resource *sc_vmemres;
113 bus_space_tag_t sc_memt;
114 bus_space_tag_t sc_regt;
115 bus_space_tag_t sc_viot;
116 bus_space_tag_t sc_vmemt;
117 bus_space_handle_t sc_memh;
118 bus_space_handle_t sc_regh;
119 bus_space_handle_t sc_vioh;
120 bus_space_handle_t sc_vmemh;
135 int sc_mclk_post_div;
140 vm_offset_t sc_curoff;
145 #define MACHFB_DRAW_CHAR (1 << 0)
146 #define MACHFB_DRAW_FILLRECT (1 << 1)
149 #define MACHFB_CONSOLE (1 << 0)
150 #define MACHFB_CUREN (1 << 1)
151 #define MACHFB_DSP (1 << 2)
154 static const struct {
157 uint32_t ramdac_freq;
159 { ATI_MACH64_CT, "ATI Mach64 CT", 135000 },
160 { ATI_RAGE_PRO_AGP, "ATI 3D Rage Pro (AGP)", 230000 },
161 { ATI_RAGE_PRO_AGP1X, "ATI 3D Rage Pro (AGP 1x)", 230000 },
162 { ATI_RAGE_PRO_PCI_B, "ATI 3D Rage Pro Turbo", 230000 },
163 { ATI_RAGE_XC_PCI66, "ATI Rage XL (PCI66)", 230000 },
164 { ATI_RAGE_XL_AGP, "ATI Rage XL (AGP)", 230000 },
165 { ATI_RAGE_XC_AGP, "ATI Rage XC (AGP)", 230000 },
166 { ATI_RAGE_XL_PCI66, "ATI Rage XL (PCI66)", 230000 },
167 { ATI_RAGE_PRO_PCI_P, "ATI 3D Rage Pro", 230000 },
168 { ATI_RAGE_PRO_PCI_L, "ATI 3D Rage Pro (limited 3D)", 230000 },
169 { ATI_RAGE_XL_PCI, "ATI Rage XL", 230000 },
170 { ATI_RAGE_XC_PCI, "ATI Rage XC", 230000 },
171 { ATI_RAGE_II, "ATI 3D Rage I/II", 135000 },
172 { ATI_RAGE_IIP, "ATI 3D Rage II+", 200000 },
173 { ATI_RAGE_IIC_PCI, "ATI 3D Rage IIC", 230000 },
174 { ATI_RAGE_IIC_AGP_B, "ATI 3D Rage IIC (AGP)", 230000 },
175 { ATI_RAGE_IIC_AGP_P, "ATI 3D Rage IIC (AGP)", 230000 },
176 { ATI_RAGE_LT_PRO_AGP, "ATI 3D Rage LT Pro (AGP 133MHz)", 230000 },
177 { ATI_RAGE_MOB_M3_PCI, "ATI Rage Mobility M3", 230000 },
178 { ATI_RAGE_MOB_M3_AGP, "ATI Rage Mobility M3 (AGP)", 230000 },
179 { ATI_RAGE_LT, "ATI 3D Rage LT", 230000 },
180 { ATI_RAGE_LT_PRO_PCI, "ATI 3D Rage LT Pro", 230000 },
181 { ATI_RAGE_MOBILITY, "ATI Rage Mobility", 230000 },
182 { ATI_RAGE_L_MOBILITY, "ATI Rage L Mobility", 230000 },
183 { ATI_RAGE_LT_PRO, "ATI 3D Rage LT Pro", 230000 },
184 { ATI_RAGE_LT_PRO2, "ATI 3D Rage LT Pro", 230000 },
185 { ATI_RAGE_MOB_M1_PCI, "ATI Rage Mobility M1 (PCI)", 230000 },
186 { ATI_RAGE_L_MOB_M1_PCI, "ATI Rage L Mobility (PCI)", 230000 },
187 { ATI_MACH64_VT, "ATI Mach64 VT", 170000 },
188 { ATI_MACH64_VTB, "ATI Mach64 VTB", 200000 },
189 { ATI_MACH64_VT4, "ATI Mach64 VT4", 230000 }
192 static const struct machfb_cmap {
196 } machfb_default_cmap[16] = {
197 {0x00, 0x00, 0x00}, /* black */
198 {0x00, 0x00, 0xff}, /* blue */
199 {0x00, 0xff, 0x00}, /* green */
200 {0x00, 0xc0, 0xc0}, /* cyan */
201 {0xff, 0x00, 0x00}, /* red */
202 {0xc0, 0x00, 0xc0}, /* magenta */
203 {0xc0, 0xc0, 0x00}, /* brown */
204 {0xc0, 0xc0, 0xc0}, /* light grey */
205 {0x80, 0x80, 0x80}, /* dark grey */
206 {0x80, 0x80, 0xff}, /* light blue */
207 {0x80, 0xff, 0x80}, /* light green */
208 {0x80, 0xff, 0xff}, /* light cyan */
209 {0xff, 0x80, 0x80}, /* light red */
210 {0xff, 0x80, 0xff}, /* light magenta */
211 {0xff, 0xff, 0x80}, /* yellow */
212 {0xff, 0xff, 0xff} /* white */
215 #define MACHFB_CMAP_OFF 16
217 static const u_char machfb_mouse_pointer_bits[64][8] = {
218 { 0x00, 0x00, }, /* ............ */
219 { 0x80, 0x00, }, /* *........... */
220 { 0xc0, 0x00, }, /* **.......... */
221 { 0xe0, 0x00, }, /* ***......... */
222 { 0xf0, 0x00, }, /* ****........ */
223 { 0xf8, 0x00, }, /* *****....... */
224 { 0xfc, 0x00, }, /* ******...... */
225 { 0xfe, 0x00, }, /* *******..... */
226 { 0xff, 0x00, }, /* ********.... */
227 { 0xff, 0x80, }, /* *********... */
228 { 0xfc, 0xc0, }, /* ******..**.. */
229 { 0xdc, 0x00, }, /* **.***...... */
230 { 0x8e, 0x00, }, /* *...***..... */
231 { 0x0e, 0x00, }, /* ....***..... */
232 { 0x07, 0x00, }, /* .....***.... */
233 { 0x04, 0x00, }, /* .....*...... */
234 { 0x00, 0x00, }, /* ............ */
235 { 0x00, 0x00, }, /* ............ */
236 { 0x00, 0x00, }, /* ............ */
237 { 0x00, 0x00, }, /* ............ */
238 { 0x00, 0x00, }, /* ............ */
239 { 0x00, 0x00, }, /* ............ */
243 * Lookup table to perform a bit-swap of the mouse pointer bits,
244 * map set bits to CUR_CLR0 and unset bits to transparent.
246 static const u_char machfb_mouse_pointer_lut[] = {
247 0xaa, 0x2a, 0x8a, 0x0a, 0xa2, 0x22, 0x82, 0x02,
248 0xa8, 0x28, 0x88, 0x08, 0xa0, 0x20, 0x80, 0x00
251 static const char *machfb_memtype_names[] = {
252 "(N/A)", "DRAM", "EDO DRAM", "EDO DRAM", "SDRAM", "SGRAM", "WRAM",
256 static struct machfb_softc machfb_softc;
257 static struct bus_space_tag machfb_bst_store[1];
259 static device_probe_t machfb_pci_probe;
260 static device_attach_t machfb_pci_attach;
261 static device_detach_t machfb_pci_detach;
263 static device_method_t machfb_methods[] = {
264 /* Device interface */
265 DEVMETHOD(device_probe, machfb_pci_probe),
266 DEVMETHOD(device_attach, machfb_pci_attach),
267 DEVMETHOD(device_detach, machfb_pci_detach),
272 static driver_t machfb_pci_driver = {
275 sizeof(struct machfb_softc),
278 static devclass_t machfb_devclass;
280 DRIVER_MODULE(machfb, pci, machfb_pci_driver, machfb_devclass, 0, 0);
281 MODULE_DEPEND(machfb, pci, 1, 1, 1);
283 static void machfb_cursor_enable(struct machfb_softc *, int);
284 static int machfb_cursor_install(struct machfb_softc *);
285 static int machfb_get_memsize(struct machfb_softc *);
286 static void machfb_reset_engine(struct machfb_softc *);
287 static void machfb_init_engine(struct machfb_softc *);
289 static void machfb_adjust_frame(struct machfb_softc *, int, int);
291 static void machfb_shutdown_final(void *);
292 static void machfb_shutdown_reset(void *);
294 static int machfb_configure(int);
296 static vi_probe_t machfb_probe;
297 static vi_init_t machfb_init;
298 static vi_get_info_t machfb_get_info;
299 static vi_query_mode_t machfb_query_mode;
300 static vi_set_mode_t machfb_set_mode;
301 static vi_save_font_t machfb_save_font;
302 static vi_load_font_t machfb_load_font;
303 static vi_show_font_t machfb_show_font;
304 static vi_save_palette_t machfb_save_palette;
305 static vi_load_palette_t machfb_load_palette;
306 static vi_set_border_t machfb_set_border;
307 static vi_save_state_t machfb_save_state;
308 static vi_load_state_t machfb_load_state;
309 static vi_set_win_org_t machfb_set_win_org;
310 static vi_read_hw_cursor_t machfb_read_hw_cursor;
311 static vi_set_hw_cursor_t machfb_set_hw_cursor;
312 static vi_set_hw_cursor_shape_t machfb_set_hw_cursor_shape;
313 static vi_blank_display_t machfb_blank_display;
314 static vi_mmap_t machfb_mmap;
315 static vi_ioctl_t machfb_ioctl;
316 static vi_clear_t machfb_clear;
317 static vi_fill_rect_t machfb_fill_rect;
318 static vi_bitblt_t machfb_bitblt;
319 static vi_diag_t machfb_diag;
320 static vi_save_cursor_palette_t machfb_save_cursor_palette;
321 static vi_load_cursor_palette_t machfb_load_cursor_palette;
322 static vi_copy_t machfb_copy;
323 static vi_putp_t machfb_putp;
324 static vi_putc_t machfb_putc;
325 static vi_puts_t machfb_puts;
326 static vi_putm_t machfb_putm;
328 static video_switch_t machfbvidsw = {
329 .probe = machfb_probe,
331 .get_info = machfb_get_info,
332 .query_mode = machfb_query_mode,
333 .set_mode = machfb_set_mode,
334 .save_font = machfb_save_font,
335 .load_font = machfb_load_font,
336 .show_font = machfb_show_font,
337 .save_palette = machfb_save_palette,
338 .load_palette = machfb_load_palette,
339 .set_border = machfb_set_border,
340 .save_state = machfb_save_state,
341 .load_state = machfb_load_state,
342 .set_win_org = machfb_set_win_org,
343 .read_hw_cursor = machfb_read_hw_cursor,
344 .set_hw_cursor = machfb_set_hw_cursor,
345 .set_hw_cursor_shape = machfb_set_hw_cursor_shape,
346 .blank_display = machfb_blank_display,
348 .ioctl = machfb_ioctl,
349 .clear = machfb_clear,
350 .fill_rect = machfb_fill_rect,
351 .bitblt = machfb_bitblt,
355 .save_cursor_palette = machfb_save_cursor_palette,
356 .load_cursor_palette = machfb_load_cursor_palette,
364 VIDEO_DRIVER(machfb, machfbvidsw, machfb_configure);
366 extern sc_rndr_sw_t txtrndrsw;
367 RENDERER(machfb, 0, txtrndrsw, gfb_set);
369 RENDERER_MODULE(machfb, gfb_set);
372 * Inline functions for getting access to register aperture.
374 static inline uint32_t regr(struct machfb_softc *, uint32_t);
375 static inline uint8_t regrb(struct machfb_softc *, uint32_t);
376 static inline void regw(struct machfb_softc *, uint32_t, uint32_t);
377 static inline void regwb(struct machfb_softc *, uint32_t, uint8_t);
378 static inline void regwb_pll(struct machfb_softc *, uint32_t, uint8_t);
380 static inline uint32_t
381 regr(struct machfb_softc *sc, uint32_t index)
384 return bus_space_read_4(sc->sc_regt, sc->sc_regh, index);
387 static inline uint8_t
388 regrb(struct machfb_softc *sc, uint32_t index)
391 return bus_space_read_1(sc->sc_regt, sc->sc_regh, index);
395 regw(struct machfb_softc *sc, uint32_t index, uint32_t data)
398 bus_space_write_4(sc->sc_regt, sc->sc_regh, index, data);
399 bus_space_barrier(sc->sc_regt, sc->sc_regh, index, 4,
400 BUS_SPACE_BARRIER_WRITE);
404 regwb(struct machfb_softc *sc, uint32_t index, uint8_t data)
407 bus_space_write_1(sc->sc_regt, sc->sc_regh, index, data);
408 bus_space_barrier(sc->sc_regt, sc->sc_regh, index, 1,
409 BUS_SPACE_BARRIER_WRITE);
413 regwb_pll(struct machfb_softc *sc, uint32_t index, uint8_t data)
416 regwb(sc, CLOCK_CNTL + 1, (index << 2) | PLL_WR_EN);
417 regwb(sc, CLOCK_CNTL + 2, data);
418 regwb(sc, CLOCK_CNTL + 1, (index << 2) & ~PLL_WR_EN);
422 wait_for_fifo(struct machfb_softc *sc, uint8_t v)
425 while ((regr(sc, FIFO_STAT) & 0xffff) > (0x8000 >> v))
430 wait_for_idle(struct machfb_softc *sc)
433 wait_for_fifo(sc, 16);
434 while ((regr(sc, GUI_STAT) & 1) != 0)
439 * Inline functions for setting the background and foreground colors.
441 static inline void machfb_setbg(struct machfb_softc *sc, int bg);
442 static inline void machfb_setfg(struct machfb_softc *sc, int fg);
445 machfb_setbg(struct machfb_softc *sc, int bg)
448 if (bg == sc->sc_bg_cache)
450 sc->sc_bg_cache = bg;
451 wait_for_fifo(sc, 1);
452 regw(sc, DP_BKGD_CLR, bg + MACHFB_CMAP_OFF);
456 machfb_setfg(struct machfb_softc *sc, int fg)
459 if (fg == sc->sc_fg_cache)
461 sc->sc_fg_cache = fg;
462 wait_for_fifo(sc, 1);
463 regw(sc, DP_FRGD_CLR, fg + MACHFB_CMAP_OFF);
467 * video driver interface
470 machfb_configure(int flags)
472 struct machfb_softc *sc;
473 phandle_t chosen, output;
480 * For the high-level console probing return the number of
481 * registered adapters.
483 if (!(flags & VIO_PROBE_ONLY)) {
484 for (i = 0; vid_find_adapter(MACHFB_DRIVER_NAME, i) >= 0; i++)
489 /* Low-level console probing and initialization. */
492 if (sc->sc_va.va_flags & V_ADP_REGISTERED)
495 if ((chosen = OF_finddevice("/chosen")) == -1) /* Quis contra nos? */
497 if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1)
499 if ((output = OF_instance_to_package(stdout)) == -1)
501 if ((OF_getprop(output, "vendor-id", &id, sizeof(id)) == -1) ||
504 if (OF_getprop(output, "device-id", &id, sizeof(id)) == -1)
506 for (i = 0; i < sizeof(machfb_info) / sizeof(machfb_info[0]); i++) {
507 if (id == machfb_info[i].chip_id) {
508 sc->sc_flags = MACHFB_CONSOLE;
509 sc->sc_node = output;
514 if (!(sc->sc_flags & MACHFB_CONSOLE))
517 if (OF_getprop(output, "revision-id", &sc->sc_chip_rev,
518 sizeof(sc->sc_chip_rev)) == -1)
520 if (OF_decode_addr(output, 0, &space, &addr) != 0)
522 sc->sc_memt = &machfb_bst_store[0];
523 sc->sc_memh = sparc64_fake_bustag(space, addr, sc->sc_memt);
524 sc->sc_regt = sc->sc_memt;
525 bus_space_subregion(sc->sc_regt, sc->sc_memh, MACH64_REG_OFF,
526 MACH64_REG_SIZE, &sc->sc_regh);
528 if (machfb_init(0, &sc->sc_va, 0) < 0)
532 /* Return number of found adapters. */
537 machfb_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
544 machfb_init(int unit, video_adapter_t *adp, int flags)
546 struct machfb_softc *sc;
551 uint8_t dac_mask, dac_rindex, dac_windex;
553 sc = (struct machfb_softc *)adp;
556 if ((regr(sc, CONFIG_CHIP_ID) & 0xffff) != sc->sc_chip_id)
559 sc->sc_ramdac_freq = 0;
560 for (i = 0; i < sizeof(machfb_info) / sizeof(machfb_info[0]); i++) {
561 if (sc->sc_chip_id == machfb_info[i].chip_id) {
562 sc->sc_ramdac_freq = machfb_info[i].ramdac_freq;
566 if (sc->sc_ramdac_freq == 0)
568 if (sc->sc_chip_id == ATI_RAGE_II && sc->sc_chip_rev & 0x07)
569 sc->sc_ramdac_freq = 170000;
571 vid_init_struct(adp, MACHFB_DRIVER_NAME, -1, unit);
573 if (OF_getprop(sc->sc_node, "height", &sc->sc_height,
574 sizeof(sc->sc_height)) == -1)
576 if (OF_getprop(sc->sc_node, "width", &sc->sc_width,
577 sizeof(sc->sc_width)) == -1)
579 if (OF_getprop(sc->sc_node, "depth", &sc->sc_depth,
580 sizeof(sc->sc_depth)) == -1)
582 if ((options = OF_finddevice("/options")) == -1)
584 if (OF_getprop(options, "screen-#rows", buf, sizeof(buf)) == -1)
586 vi->vi_height = strtol(buf, NULL, 10);
587 if (OF_getprop(options, "screen-#columns", buf, sizeof(buf)) == -1)
589 vi->vi_width = strtol(buf, NULL, 10);
592 vi->vi_flags = V_INFO_COLOR;
593 vi->vi_mem_model = V_INFO_MM_OTHER;
595 sc->sc_font = gallant12x22_data;
596 sc->sc_cbwidth = howmany(vi->vi_cwidth, 8); /* width in bytes */
597 sc->sc_xmargin = (sc->sc_width - (vi->vi_width * vi->vi_cwidth)) / 2;
598 sc->sc_ymargin = (sc->sc_height - (vi->vi_height * vi->vi_cheight)) / 2;
600 if (sc->sc_chip_id != ATI_MACH64_CT &&
601 !((sc->sc_chip_id == ATI_MACH64_VT ||
602 sc->sc_chip_id == ATI_RAGE_II) &&
603 (sc->sc_chip_rev & 0x07) == 0))
604 sc->sc_flags |= MACHFB_DSP;
606 sc->sc_memsize = machfb_get_memsize(sc);
607 if (sc->sc_memsize == 8192)
608 /* The last page is used as register aperture. */
610 sc->sc_memtype = regr(sc, CONFIG_STAT0) & 0x07;
612 if ((sc->sc_chip_id >= ATI_RAGE_XC_PCI66 &&
613 sc->sc_chip_id <= ATI_RAGE_XL_PCI66) ||
614 (sc->sc_chip_id >= ATI_RAGE_XL_PCI &&
615 sc->sc_chip_id <= ATI_RAGE_XC_PCI))
616 sc->sc_ref_freq = 29498;
618 sc->sc_ref_freq = 14318;
620 regwb(sc, CLOCK_CNTL + 1, PLL_REF_DIV << 2);
621 sc->sc_ref_div = regrb(sc, CLOCK_CNTL + 2);
622 regwb(sc, CLOCK_CNTL + 1, MCLK_FB_DIV << 2);
623 sc->sc_mclk_fb_div = regrb(sc, CLOCK_CNTL + 2);
624 sc->sc_mem_freq = (2 * sc->sc_ref_freq * sc->sc_mclk_fb_div) /
625 (sc->sc_ref_div * 2);
626 sc->sc_mclk_post_div = (sc->sc_mclk_fb_div * 2 * sc->sc_ref_freq) /
627 (sc->sc_mem_freq * sc->sc_ref_div);
629 machfb_init_engine(sc);
631 mach64_adjust_frame(0, 0);
633 machfb_set_mode(adp, 0);
636 * Install our 16-color color map. This is done only once and with
637 * an offset of 16 on sparc64 as there the OBP driver expects white
638 * to be at index 0 and black at 255 (some versions also use 1 - 8
639 * for color text support or the full palette for the boot banner
640 * logo but no versions seems to use the ISO 6429-1983 color map).
641 * Otherwise the colors are inverted when back in the OFW.
643 dac_rindex = regrb(sc, DAC_RINDEX);
644 dac_windex = regrb(sc, DAC_WINDEX);
645 dac_mask = regrb(sc, DAC_MASK);
646 regwb(sc, DAC_MASK, 0xff);
647 regwb(sc, DAC_WINDEX, MACHFB_CMAP_OFF);
648 for (i = 0; i < 16; i++) {
649 regwb(sc, DAC_DATA, machfb_default_cmap[i].red);
650 regwb(sc, DAC_DATA, machfb_default_cmap[i].green);
651 regwb(sc, DAC_DATA, machfb_default_cmap[i].blue);
653 regwb(sc, DAC_MASK, dac_mask);
654 regwb(sc, DAC_RINDEX, dac_rindex);
655 regwb(sc, DAC_WINDEX, dac_windex);
657 machfb_blank_display(adp, V_DISPLAY_ON);
661 * Setting V_ADP_MODECHANGE serves as hack so machfb_set_mode()
662 * (which will invalidate our caches) is called as a precaution
663 * when the X server shuts down.
665 adp->va_flags |= V_ADP_COLOR | V_ADP_MODECHANGE | V_ADP_PALETTE |
666 V_ADP_BORDER | V_ADP_INITIALIZED;
667 if (vid_register(adp) < 0)
669 adp->va_flags |= V_ADP_REGISTERED;
675 machfb_get_info(video_adapter_t *adp, int mode, video_info_t *info)
678 bcopy(&adp->va_info, info, sizeof(*info));
684 machfb_query_mode(video_adapter_t *adp, video_info_t *info)
691 machfb_set_mode(video_adapter_t *adp, int mode)
693 struct machfb_softc *sc;
695 sc = (struct machfb_softc *)adp;
697 sc->sc_bg_cache = -1;
698 sc->sc_fg_cache = -1;
699 sc->sc_draw_cache = -1;
705 machfb_save_font(video_adapter_t *adp, int page, int size, int width,
706 u_char *data, int c, int count)
713 machfb_load_font(video_adapter_t *adp, int page, int size, int width,
714 u_char *data, int c, int count)
721 machfb_show_font(video_adapter_t *adp, int page)
728 machfb_save_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_RINDEX, 0x0);
741 for (i = 0; i < 256 * 3; i++)
742 palette[i] = regrb(sc, DAC_DATA);
743 regwb(sc, DAC_MASK, dac_mask);
744 regwb(sc, DAC_RINDEX, dac_rindex);
745 regwb(sc, DAC_WINDEX, dac_windex);
751 machfb_load_palette(video_adapter_t *adp, u_char *palette)
753 struct machfb_softc *sc;
755 uint8_t dac_mask, dac_rindex, dac_windex;
757 sc = (struct machfb_softc *)adp;
759 dac_rindex = regrb(sc, DAC_RINDEX);
760 dac_windex = regrb(sc, DAC_WINDEX);
761 dac_mask = regrb(sc, DAC_MASK);
762 regwb(sc, DAC_MASK, 0xff);
763 regwb(sc, DAC_WINDEX, 0x0);
764 for (i = 0; i < 256 * 3; i++)
765 regwb(sc, DAC_DATA, palette[i]);
766 regwb(sc, DAC_MASK, dac_mask);
767 regwb(sc, DAC_RINDEX, dac_rindex);
768 regwb(sc, DAC_WINDEX, dac_windex);
774 machfb_set_border(video_adapter_t *adp, int border)
776 struct machfb_softc *sc;
778 sc = (struct machfb_softc *)adp;
780 machfb_fill_rect(adp, border, 0, 0, sc->sc_width, sc->sc_ymargin);
781 machfb_fill_rect(adp, border, 0, sc->sc_height - sc->sc_ymargin,
782 sc->sc_width, sc->sc_ymargin);
783 machfb_fill_rect(adp, border, 0, 0, sc->sc_xmargin, sc->sc_height);
784 machfb_fill_rect(adp, border, sc->sc_width - sc->sc_xmargin, 0,
785 sc->sc_xmargin, sc->sc_height);
791 machfb_save_state(video_adapter_t *adp, void *p, size_t size)
798 machfb_load_state(video_adapter_t *adp, void *p)
805 machfb_set_win_org(video_adapter_t *adp, off_t offset)
812 machfb_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
822 machfb_set_hw_cursor(video_adapter_t *adp, int col, int row)
829 machfb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
830 int celsize, int blink)
837 machfb_blank_display(video_adapter_t *adp, int mode)
839 struct machfb_softc *sc;
840 uint32_t crtc_gen_cntl;
842 sc = (struct machfb_softc *)adp;
844 crtc_gen_cntl = (regr(sc, CRTC_GEN_CNTL) | CRTC_EXT_DISP_EN | CRTC_EN) &
845 ~(CRTC_HSYNC_DIS | CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS);
849 case V_DISPLAY_BLANK:
850 crtc_gen_cntl |= CRTC_HSYNC_DIS | CRTC_VSYNC_DIS |
853 case V_DISPLAY_STAND_BY:
854 crtc_gen_cntl |= CRTC_HSYNC_DIS | CRTC_DISPLAY_DIS;
856 case V_DISPLAY_SUSPEND:
857 crtc_gen_cntl |= CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS;
860 regw(sc, CRTC_GEN_CNTL, crtc_gen_cntl);
866 machfb_mmap(video_adapter_t *adp, vm_offset_t offset, vm_paddr_t *paddr,
869 struct machfb_softc *sc;
871 sc = (struct machfb_softc *)adp;
873 if (adp->va_io_base != 0 && offset >= adp->va_io_base &&
874 offset < adp->va_io_base + adp->va_io_size) {
875 *paddr = sc->sc_vioh + offset - adp->va_io_size;
879 if (adp->va_mem_base != 0 && offset >= adp->va_mem_base &&
880 offset < adp->va_mem_base + adp->va_mem_size) {
881 *paddr = sc->sc_vmemh + offset - adp->va_mem_base;
885 if (offset >= adp->va_registers &&
886 offset < adp->va_registers + adp->va_registers_size) {
887 *paddr = sc->sc_memh + offset - adp->va_registers;
891 /* 'regular' framebuffer mmap()ing */
892 if (offset < adp->va_window_size) {
893 *paddr = adp->va_window + offset;
901 machfb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data)
903 struct machfb_softc *sc;
904 struct fbcursor *fbc;
907 sc = (struct machfb_softc *)adp;
911 fb = (struct fbtype *)data;
912 fb->fb_type = FBTYPE_PCIMISC;
913 fb->fb_height = sc->sc_height;
914 fb->fb_width = sc->sc_width;
915 fb->fb_depth = sc->sc_depth;
916 if (sc->sc_depth <= 1 || sc->sc_depth > 8)
919 fb->fb_cmsize = 1 << sc->sc_depth;
920 fb->fb_size = adp->va_buffer_size;
923 fbc = (struct fbcursor *)data;
924 if (fbc->set & FB_CUR_SETCUR && fbc->enable == 0) {
925 machfb_cursor_enable(sc, 0);
926 sc->sc_flags &= ~MACHFB_CUREN;
931 return (fb_commonioctl(adp, cmd, data));
938 machfb_clear(video_adapter_t *adp)
940 struct machfb_softc *sc;
942 sc = (struct machfb_softc *)adp;
944 machfb_fill_rect(adp, (SC_NORM_ATTR >> 4) & 0xf, 0, 0, sc->sc_width,
951 machfb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
953 struct machfb_softc *sc;
955 sc = (struct machfb_softc *)adp;
957 if (sc->sc_draw_cache != MACHFB_DRAW_FILLRECT) {
958 wait_for_fifo(sc, 7);
959 regw(sc, DP_WRITE_MASK, 0xff);
960 regw(sc, DP_PIX_WIDTH, DST_8BPP | SRC_8BPP | HOST_8BPP);
961 regw(sc, DP_SRC, FRGD_SRC_FRGD_CLR);
962 regw(sc, DP_MIX, MIX_SRC << 16);
963 regw(sc, CLR_CMP_CNTL, 0); /* no transparency */
964 regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT);
965 regw(sc, DST_CNTL, DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM);
966 sc->sc_draw_cache = MACHFB_DRAW_FILLRECT;
968 machfb_setfg(sc, val);
969 wait_for_fifo(sc, 4);
970 regw(sc, SRC_Y_X, (x << 16) | y);
971 regw(sc, SRC_WIDTH1, cx);
972 regw(sc, DST_Y_X, (x << 16) | y);
973 regw(sc, DST_HEIGHT_WIDTH, (cx << 16) | cy);
979 machfb_bitblt(video_adapter_t *adp, ...)
986 machfb_diag(video_adapter_t *adp, int level)
990 fb_dump_adp_info(adp->va_name, adp, level);
991 machfb_get_info(adp, 0, &info);
992 fb_dump_mode_info(adp->va_name, adp, &info, level);
998 machfb_save_cursor_palette(video_adapter_t *adp, u_char *palette)
1005 machfb_load_cursor_palette(video_adapter_t *adp, u_char *palette)
1012 machfb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n)
1019 machfb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a,
1020 int size, int bpp, int bit_ltor, int byte_ltor)
1027 machfb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a)
1029 struct machfb_softc *sc;
1033 sc = (struct machfb_softc *)adp;
1035 if (sc->sc_draw_cache != MACHFB_DRAW_CHAR) {
1036 wait_for_fifo(sc, 8);
1037 regw(sc, DP_WRITE_MASK, 0xff); /* XXX only good for 8 bit */
1038 regw(sc, DP_PIX_WIDTH, DST_8BPP | SRC_1BPP | HOST_1BPP);
1039 regw(sc, DP_SRC, MONO_SRC_HOST | BKGD_SRC_BKGD_CLR |
1041 regw(sc, DP_MIX ,((MIX_SRC & 0xffff) << 16) | MIX_SRC);
1042 regw(sc, CLR_CMP_CNTL, 0); /* no transparency */
1043 regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT);
1044 regw(sc, DST_CNTL, DST_Y_TOP_TO_BOTTOM | DST_X_LEFT_TO_RIGHT);
1045 regw(sc, HOST_CNTL, HOST_BYTE_ALIGN);
1046 sc->sc_draw_cache = MACHFB_DRAW_CHAR;
1048 machfb_setbg(sc, (a >> 4) & 0xf);
1049 machfb_setfg(sc, a & 0xf);
1050 wait_for_fifo(sc, 4 + (adp->va_info.vi_cheight / sc->sc_cbwidth));
1051 regw(sc, SRC_Y_X, 0);
1052 regw(sc, SRC_WIDTH1, adp->va_info.vi_cwidth);
1053 regw(sc, DST_Y_X, ((((off % adp->va_info.vi_width) *
1054 adp->va_info.vi_cwidth) + sc->sc_xmargin) << 16) |
1055 (((off / adp->va_info.vi_width) * adp->va_info.vi_cheight) +
1057 regw(sc, DST_HEIGHT_WIDTH, (adp->va_info.vi_cwidth << 16) |
1058 adp->va_info.vi_cheight);
1059 p = sc->sc_font + (c * adp->va_info.vi_cheight * sc->sc_cbwidth);
1060 for (i = 0; i < adp->va_info.vi_cheight * sc->sc_cbwidth; i += 4)
1061 regw(sc, HOST_DATA0 + i, (p[i + 3] << 24 | p[i + 2] << 16 |
1062 p[i + 1] << 8 | p[i]));
1068 machfb_puts(video_adapter_t *adp, vm_offset_t off, uint16_t *s, int len)
1070 struct machfb_softc *sc;
1071 int blanks, i, x1, x2, y1, y2;
1072 uint8_t a, c, color1, color2;
1074 sc = (struct machfb_softc *)adp;
1076 #define MACHFB_BLANK machfb_fill_rect(adp, color1, x1, y1, \
1077 blanks * adp->va_info.vi_cwidth, \
1078 adp->va_info.vi_cheight)
1080 blanks = color1 = x1 = y1 = 0;
1081 for (i = 0; i < len; i++) {
1083 * Accelerate continuous blanks by drawing a respective
1084 * rectangle instead. Drawing a rectangle of any size
1085 * takes about the same number of operations as drawing
1086 * a single character.
1089 a = (s[i] & 0xff00) >> 8;
1090 if (c == 0x00 || c == 0x20 || c == 0xdb || c == 0xff) {
1091 color2 = (a >> (c == 0xdb ? 0 : 4) & 0xf);
1092 x2 = (((off + i) % adp->va_info.vi_width) *
1093 adp->va_info.vi_cwidth) + sc->sc_xmargin;
1094 y2 = (((off + i) / adp->va_info.vi_width) *
1095 adp->va_info.vi_cheight) + sc->sc_ymargin;
1101 } else if (color1 != color2 || y1 != y2) {
1114 (*vidsw[adp->va_index]->putc)(adp, off + i, c, a);
1126 machfb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image,
1127 uint32_t pixel_mask, int size, int width)
1129 struct machfb_softc *sc;
1132 sc = (struct machfb_softc *)adp;
1134 if ((!(sc->sc_flags & MACHFB_CUREN)) &&
1135 (error = machfb_cursor_install(sc)) < 0)
1139 * The hardware cursor always must be disabled when
1140 * fiddling with its bits otherwise some artifacts
1141 * may appear on the screen.
1143 machfb_cursor_enable(sc, 0);
1146 regw(sc, CUR_HORZ_VERT_OFF, 0);
1147 if ((regr(sc, GEN_TEST_CNTL) & CRTC_DBL_SCAN_EN) != 0)
1149 regw(sc, CUR_HORZ_VERT_POSN, ((y + sc->sc_ymargin) << 16) |
1150 (x + sc->sc_xmargin));
1151 machfb_cursor_enable(sc, 1);
1152 sc->sc_flags |= MACHFB_CUREN;
1161 machfb_pci_probe(device_t dev)
1165 if (pci_get_class(dev) != PCIC_DISPLAY ||
1166 pci_get_subclass(dev) != PCIS_DISPLAY_VGA)
1169 for (i = 0; i < sizeof(machfb_info) / sizeof(machfb_info[0]); i++) {
1170 if (pci_get_device(dev) == machfb_info[i].chip_id) {
1171 device_set_desc(dev, machfb_info[i].name);
1172 return (BUS_PROBE_DEFAULT);
1180 machfb_pci_attach(device_t dev)
1182 struct machfb_softc *sc;
1183 video_adapter_t *adp;
1186 uint32_t *p32, saved_value;
1190 node = ofw_bus_get_node(dev);
1191 if ((sc = (struct machfb_softc *)vid_get_adapter(vid_find_adapter(
1192 MACHFB_DRIVER_NAME, 0))) != NULL && sc->sc_node == node) {
1193 device_printf(dev, "console\n");
1194 device_set_softc(dev, sc);
1196 sc = device_get_softc(dev);
1197 bzero(sc, sizeof(struct machfb_softc));
1200 sc->sc_chip_id = pci_get_device(dev);
1201 sc->sc_chip_rev = pci_get_revid(dev);
1206 * Regardless whether we are the console and already allocated
1207 * resources in machfb_configure() or not we have to allocate
1208 * them here (again) in order for rman_get_virtual() to work.
1211 /* Enable memory and IO access. */
1212 pci_write_config(dev, PCIR_COMMAND,
1213 pci_read_config(dev, PCIR_COMMAND, 2) | PCIM_CMD_PORTEN |
1216 sc->sc_memrid = PCIR_BAR(0);
1217 if ((sc->sc_memres = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
1218 &sc->sc_memrid, RF_ACTIVE)) == NULL) {
1219 device_printf(dev, "cannot allocate memory resources\n");
1222 sc->sc_memt = rman_get_bustag(sc->sc_memres);
1223 sc->sc_memh = rman_get_bushandle(sc->sc_memres);
1224 adp->va_registers = rman_get_start(sc->sc_memres);
1225 adp->va_registers_size = rman_get_size(sc->sc_memres);
1226 sc->sc_regt = sc->sc_memt;
1227 bus_space_subregion(sc->sc_regt, sc->sc_memh, MACH64_REG_OFF,
1228 MACH64_REG_SIZE, &sc->sc_regh);
1229 adp->va_buffer = (vm_offset_t)rman_get_virtual(sc->sc_memres);
1230 adp->va_buffer_size = rman_get_size(sc->sc_memres);
1233 * Depending on the firmware version the VGA I/O and/or memory
1234 * resources of the Mach64 chips come up disabled. We generally
1235 * enable them above (pci(4) actually already did this unless
1236 * pci_enable_io_modes is not set) but this doesn't necessarily
1237 * mean that we get valid ones. Invalid resources seem to have
1238 * in common that they start at address 0. We don't allocate
1239 * them in this case in order to avoid warnings in apb(4) and
1240 * crashes when using these invalid resources. Xorg is aware
1241 * of this and doesn't use the VGA resources in this case (but
1242 * demands them if they are valid).
1244 sc->sc_viorid = PCIR_BAR(1);
1245 if (bus_get_resource_start(dev, SYS_RES_IOPORT, sc->sc_viorid) != 0) {
1246 if ((sc->sc_viores = bus_alloc_resource_any(dev,
1247 SYS_RES_IOPORT, &sc->sc_viorid, RF_ACTIVE)) == NULL) {
1249 "cannot allocate VGA I/O resources\n");
1253 sc->sc_viot = rman_get_bustag(sc->sc_viores);
1254 sc->sc_vioh = rman_get_bushandle(sc->sc_viores);
1255 adp->va_io_base = rman_get_start(sc->sc_viores);
1256 adp->va_io_size = rman_get_size(sc->sc_viores);
1259 sc->sc_vmemrid = PCIR_BAR(2);
1260 if (bus_get_resource_start(dev, SYS_RES_MEMORY, sc->sc_vmemrid) != 0) {
1261 if ((sc->sc_vmemres = bus_alloc_resource_any(dev,
1262 SYS_RES_MEMORY, &sc->sc_vmemrid, RF_ACTIVE)) == NULL) {
1264 "cannot allocate VGA memory resources\n");
1268 sc->sc_vmemt = rman_get_bustag(sc->sc_vmemres);
1269 sc->sc_vmemh = rman_get_bushandle(sc->sc_vmemres);
1270 adp->va_mem_base = rman_get_start(sc->sc_vmemres);
1271 adp->va_mem_size = rman_get_size(sc->sc_vmemres);
1275 "%d MB aperture at 0x%08x, %d KB registers at 0x%08x\n",
1276 (u_int)(adp->va_buffer_size / (1024 * 1024)),
1277 (u_int)adp->va_buffer, MACH64_REG_SIZE / 1024,
1278 (u_int)sc->sc_regh);
1280 if (!(sc->sc_flags & MACHFB_CONSOLE)) {
1281 if ((sw = vid_get_switch(MACHFB_DRIVER_NAME)) == NULL) {
1282 device_printf(dev, "cannot get video switch\n");
1287 * During device configuration we don't necessarily probe
1288 * the adapter which is the console first so we can't use
1289 * the device unit number for the video adapter unit. The
1290 * worst case would be that we use the video adapter unit
1291 * 0 twice. As it doesn't really matter which unit number
1292 * the corresponding video adapter has just use the next
1295 for (i = 0; i < devclass_get_maxunit(machfb_devclass); i++)
1296 if (vid_find_adapter(MACHFB_DRIVER_NAME, i) < 0)
1298 if ((error = sw->init(i, adp, 0)) != 0) {
1299 device_printf(dev, "cannot initialize adapter\n");
1305 "%ld KB %s %d.%d MHz, maximum RAMDAC clock %d MHz, %sDSP\n",
1306 (u_long)sc->sc_memsize, machfb_memtype_names[sc->sc_memtype],
1307 sc->sc_mem_freq / 1000, sc->sc_mem_freq % 1000,
1308 sc->sc_ramdac_freq / 1000,
1309 (sc->sc_flags & MACHFB_DSP) ? "" : "no ");
1310 device_printf(dev, "resolution %dx%d at %d bpp\n",
1311 sc->sc_width, sc->sc_height, sc->sc_depth);
1314 * Test whether the aperture is byte swapped or not, set
1315 * va_window and va_window_size as appropriate.
1317 p32 = (uint32_t *)adp->va_buffer;
1319 p = (uint8_t *)adp->va_buffer;
1321 if (!(p[0] == 0x12 && p[1] == 0x34 && p[2] == 0x56 && p[3] == 0x78)) {
1322 adp->va_window = adp->va_buffer + 0x800000;
1323 adp->va_window_size = adp->va_buffer_size - 0x800000;
1325 adp->va_window = adp->va_buffer;
1326 adp->va_window_size = adp->va_buffer_size;
1329 adp->va_window_gran = adp->va_window_size;
1332 * Allocate one page for the mouse pointer image at the end of
1333 * the little endian aperture, right before the memory mapped
1334 * registers that might also reside there. Must be done after
1335 * sc_memsize was set and possibly adjusted to account for the
1336 * memory mapped registers.
1338 sc->sc_curoff = (sc->sc_memsize * 1024) - PAGE_SIZE;
1339 sc->sc_memsize -= PAGE_SIZE / 1024;
1340 machfb_cursor_enable(sc, 0);
1341 /* Initialize with an all transparent image. */
1342 memset((void *)(adp->va_buffer + sc->sc_curoff), 0xaa, PAGE_SIZE);
1345 * Register a handler that performs some cosmetic surgery like
1346 * turning off the mouse pointer on halt in preparation for
1347 * handing the screen over to the OFW. Register another handler
1348 * that turns off the CRTC when resetting, otherwise the OFW
1349 * boot command issued by cpu_reset() just doesn't work.
1351 EVENTHANDLER_REGISTER(shutdown_final, machfb_shutdown_final, sc,
1352 SHUTDOWN_PRI_DEFAULT);
1353 EVENTHANDLER_REGISTER(shutdown_reset, machfb_shutdown_reset, sc,
1354 SHUTDOWN_PRI_DEFAULT);
1359 if (sc->sc_vmemres != NULL)
1360 bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_vmemrid,
1363 if (sc->sc_viores != NULL)
1364 bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_viorid,
1367 bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_memrid, sc->sc_memres);
1373 machfb_pci_detach(device_t dev)
1380 * internal functions
1383 machfb_cursor_enable(struct machfb_softc *sc, int onoff)
1387 regw(sc, GEN_TEST_CNTL,
1388 regr(sc, GEN_TEST_CNTL) | HWCURSOR_ENABLE);
1390 regw(sc, GEN_TEST_CNTL,
1391 regr(sc, GEN_TEST_CNTL) &~ HWCURSOR_ENABLE);
1395 machfb_cursor_install(struct machfb_softc *sc)
1401 if (sc->sc_curoff == 0)
1404 machfb_cursor_enable(sc, 0);
1405 regw(sc, CUR_OFFSET, sc->sc_curoff >> 3);
1406 fg = SC_NORM_ATTR & 0xf;
1407 regw(sc, CUR_CLR0, machfb_default_cmap[fg].red << 24 |
1408 machfb_default_cmap[fg].green << 16 |
1409 machfb_default_cmap[fg].blue << 8);
1410 p = (uint16_t *)(sc->sc_va.va_buffer + sc->sc_curoff);
1411 for (i = 0; i < 64; i++)
1412 for (j = 0; j < 8; j++)
1413 *(p++) = machfb_mouse_pointer_lut[
1414 machfb_mouse_pointer_bits[i][j] >> 4] |
1415 machfb_mouse_pointer_lut[
1416 machfb_mouse_pointer_bits[i][j] & 0x0f] << 8;
1422 machfb_get_memsize(struct machfb_softc *sc)
1426 512, 1024, 2048, 4096, 6144, 8192, 12288, 16384
1429 tmp = regr(sc, MEM_CNTL);
1431 printf("memcntl=0x%08x\n", tmp);
1433 if (sc->sc_flags & MACHFB_DSP) {
1436 memsize = (tmp + 1) * 512;
1438 memsize = (tmp - 3) * 1024;
1440 memsize = (tmp - 7) * 2048;
1442 memsize = mem_tab[tmp & 0x07];
1448 machfb_reset_engine(struct machfb_softc *sc)
1452 regw(sc, GEN_TEST_CNTL, regr(sc, GEN_TEST_CNTL) & ~GUI_ENGINE_ENABLE);
1454 /* Enable engine. */
1455 regw(sc, GEN_TEST_CNTL, regr(sc, GEN_TEST_CNTL) | GUI_ENGINE_ENABLE);
1458 * Ensure engine is not locked up by clearing any FIFO or
1461 regw(sc, BUS_CNTL, regr(sc, BUS_CNTL) | BUS_HOST_ERR_ACK |
1466 machfb_init_engine(struct machfb_softc *sc)
1468 uint32_t pitch_value;
1470 pitch_value = sc->sc_width;
1472 if (sc->sc_depth == 24)
1475 machfb_reset_engine(sc);
1477 wait_for_fifo(sc, 14);
1479 regw(sc, CONTEXT_MASK, 0xffffffff);
1481 regw(sc, DST_OFF_PITCH, (pitch_value / 8) << 22);
1483 regw(sc, DST_Y_X, 0);
1484 regw(sc, DST_HEIGHT, 0);
1485 regw(sc, DST_BRES_ERR, 0);
1486 regw(sc, DST_BRES_INC, 0);
1487 regw(sc, DST_BRES_DEC, 0);
1489 regw(sc, DST_CNTL, DST_LAST_PEL | DST_X_LEFT_TO_RIGHT |
1490 DST_Y_TOP_TO_BOTTOM);
1492 regw(sc, SRC_OFF_PITCH, (pitch_value / 8) << 22);
1494 regw(sc, SRC_Y_X, 0);
1495 regw(sc, SRC_HEIGHT1_WIDTH1, 1);
1496 regw(sc, SRC_Y_X_START, 0);
1497 regw(sc, SRC_HEIGHT2_WIDTH2, 1);
1499 regw(sc, SRC_CNTL, SRC_LINE_X_LEFT_TO_RIGHT);
1501 wait_for_fifo(sc, 13);
1502 regw(sc, HOST_CNTL, 0);
1504 regw(sc, PAT_REG0, 0);
1505 regw(sc, PAT_REG1, 0);
1506 regw(sc, PAT_CNTL, 0);
1508 regw(sc, SC_LEFT, 0);
1509 regw(sc, SC_TOP, 0);
1510 regw(sc, SC_BOTTOM, sc->sc_height - 1);
1511 regw(sc, SC_RIGHT, pitch_value - 1);
1513 regw(sc, DP_BKGD_CLR, 0);
1514 regw(sc, DP_FRGD_CLR, 0xffffffff);
1515 regw(sc, DP_WRITE_MASK, 0xffffffff);
1516 regw(sc, DP_MIX, (MIX_SRC << 16) | MIX_DST);
1518 regw(sc, DP_SRC, FRGD_SRC_FRGD_CLR);
1520 wait_for_fifo(sc, 3);
1521 regw(sc, CLR_CMP_CLR, 0);
1522 regw(sc, CLR_CMP_MASK, 0xffffffff);
1523 regw(sc, CLR_CMP_CNTL, 0);
1525 wait_for_fifo(sc, 2);
1526 switch (sc->sc_depth) {
1528 regw(sc, DP_PIX_WIDTH, HOST_8BPP | SRC_8BPP | DST_8BPP);
1529 regw(sc, DP_CHAIN_MASK, DP_CHAIN_8BPP);
1530 regw(sc, DAC_CNTL, regr(sc, DAC_CNTL) | DAC_8BIT_EN);
1534 regw(sc, DP_PIX_WIDTH, HOST_32BPP | SRC_32BPP | DST_32BPP);
1535 regw(sc, DP_CHAIN_MASK, DP_CHAIN_32BPP);
1536 regw(sc, DAC_CNTL, regr(sc, DAC_CNTL) | DAC_8BIT_EN);
1541 wait_for_fifo(sc, 2);
1542 regw(sc, CRTC_INT_CNTL, regr(sc, CRTC_INT_CNTL) & ~0x20);
1543 regw(sc, GUI_TRAJ_CNTL, DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM);
1550 machfb_adjust_frame(struct machfb_softc *sc, int x, int y)
1554 offset = ((x + y * sc->sc_width) * (sc->sc_depth >> 3)) >> 3;
1556 regw(sc, CRTC_OFF_PITCH, (regr(sc, CRTC_OFF_PITCH) & 0xfff00000) |
1562 machfb_shutdown_final(void *v)
1564 struct machfb_softc *sc = v;
1566 machfb_cursor_enable(sc, 0);
1568 * In case this is the console set the cursor of the stdout
1569 * instance to the start of the last line so OFW output ends
1570 * up beneath what FreeBSD left on the screen.
1572 if (sc->sc_flags & MACHFB_CONSOLE) {
1573 OF_interpret("stdout @ is my-self 0 to column#", 0);
1574 OF_interpret("stdout @ is my-self #lines 1 - to line#", 0);
1579 machfb_shutdown_reset(void *v)
1581 struct machfb_softc *sc = v;
1583 machfb_blank_display(&sc->sc_va, V_DISPLAY_STAND_BY);