2 * Copyright (c) 2003 Peter Grehan
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.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/module.h>
34 #include <sys/kernel.h>
35 #include <sys/sysctl.h>
36 #include <sys/limits.h>
40 #include <sys/fcntl.h>
41 #include <sys/malloc.h>
43 #include <sys/consio.h>
45 #include <machine/bus.h>
46 #include <machine/sc_machdep.h>
47 #include <machine/vm.h>
51 #include <dev/fb/fbreg.h>
52 #include <dev/syscons/syscons.h>
54 #include <dev/ofw/openfirm.h>
55 #include <dev/ofw/ofw_bus.h>
56 #include <dev/ofw/ofw_pci.h>
57 #include <powerpc/ofw/ofw_syscons.h>
59 static int ofwfb_ignore_mmap_checks = 1;
60 SYSCTL_NODE(_hw, OID_AUTO, ofwfb, CTLFLAG_RD, 0, "ofwfb");
61 SYSCTL_INT(_hw_ofwfb, OID_AUTO, relax_mmap, CTLFLAG_RW,
62 &ofwfb_ignore_mmap_checks, 0, "relaxed mmap bounds checking");
64 extern u_char dflt_font_16[];
65 extern u_char dflt_font_14[];
66 extern u_char dflt_font_8[];
68 static int ofwfb_configure(int flags);
70 static vi_probe_t ofwfb_probe;
71 static vi_init_t ofwfb_init;
72 static vi_get_info_t ofwfb_get_info;
73 static vi_query_mode_t ofwfb_query_mode;
74 static vi_set_mode_t ofwfb_set_mode;
75 static vi_save_font_t ofwfb_save_font;
76 static vi_load_font_t ofwfb_load_font;
77 static vi_show_font_t ofwfb_show_font;
78 static vi_save_palette_t ofwfb_save_palette;
79 static vi_load_palette_t ofwfb_load_palette;
80 static vi_set_border_t ofwfb_set_border;
81 static vi_save_state_t ofwfb_save_state;
82 static vi_load_state_t ofwfb_load_state;
83 static vi_set_win_org_t ofwfb_set_win_org;
84 static vi_read_hw_cursor_t ofwfb_read_hw_cursor;
85 static vi_set_hw_cursor_t ofwfb_set_hw_cursor;
86 static vi_set_hw_cursor_shape_t ofwfb_set_hw_cursor_shape;
87 static vi_blank_display_t ofwfb_blank_display;
88 static vi_mmap_t ofwfb_mmap;
89 static vi_ioctl_t ofwfb_ioctl;
90 static vi_clear_t ofwfb_clear;
91 static vi_fill_rect_t ofwfb_fill_rect;
92 static vi_bitblt_t ofwfb_bitblt;
93 static vi_diag_t ofwfb_diag;
94 static vi_save_cursor_palette_t ofwfb_save_cursor_palette;
95 static vi_load_cursor_palette_t ofwfb_load_cursor_palette;
96 static vi_copy_t ofwfb_copy;
97 static vi_putp_t ofwfb_putp;
98 static vi_putc_t ofwfb_putc;
99 static vi_puts_t ofwfb_puts;
100 static vi_putm_t ofwfb_putm;
102 static video_switch_t ofwfbvidsw = {
103 .probe = ofwfb_probe,
105 .get_info = ofwfb_get_info,
106 .query_mode = ofwfb_query_mode,
107 .set_mode = ofwfb_set_mode,
108 .save_font = ofwfb_save_font,
109 .load_font = ofwfb_load_font,
110 .show_font = ofwfb_show_font,
111 .save_palette = ofwfb_save_palette,
112 .load_palette = ofwfb_load_palette,
113 .set_border = ofwfb_set_border,
114 .save_state = ofwfb_save_state,
115 .load_state = ofwfb_load_state,
116 .set_win_org = ofwfb_set_win_org,
117 .read_hw_cursor = ofwfb_read_hw_cursor,
118 .set_hw_cursor = ofwfb_set_hw_cursor,
119 .set_hw_cursor_shape = ofwfb_set_hw_cursor_shape,
120 .blank_display = ofwfb_blank_display,
122 .ioctl = ofwfb_ioctl,
123 .clear = ofwfb_clear,
124 .fill_rect = ofwfb_fill_rect,
125 .bitblt = ofwfb_bitblt,
127 .save_cursor_palette = ofwfb_save_cursor_palette,
128 .load_cursor_palette = ofwfb_load_cursor_palette,
137 * bitmap depth-specific routines
139 static vi_blank_display_t ofwfb_blank_display8;
140 static vi_putc_t ofwfb_putc8;
141 static vi_putm_t ofwfb_putm8;
142 static vi_set_border_t ofwfb_set_border8;
144 static vi_blank_display_t ofwfb_blank_display32;
145 static vi_putc_t ofwfb_putc32;
146 static vi_putm_t ofwfb_putm32;
147 static vi_set_border_t ofwfb_set_border32;
149 VIDEO_DRIVER(ofwfb, ofwfbvidsw, ofwfb_configure);
151 extern sc_rndr_sw_t txtrndrsw;
152 RENDERER(ofwfb, 0, txtrndrsw, gfb_set);
154 RENDERER_MODULE(ofwfb, gfb_set);
157 * Define the iso6429-1983 colormap
163 } ofwfb_cmap[16] = { /* # R G B Color */
165 { 0x00, 0x00, 0x00 }, /* 0 0 0 0 Black */
166 { 0x00, 0x00, 0xaa }, /* 1 0 0 2/3 Blue */
167 { 0x00, 0xaa, 0x00 }, /* 2 0 2/3 0 Green */
168 { 0x00, 0xaa, 0xaa }, /* 3 0 2/3 2/3 Cyan */
169 { 0xaa, 0x00, 0x00 }, /* 4 2/3 0 0 Red */
170 { 0xaa, 0x00, 0xaa }, /* 5 2/3 0 2/3 Magenta */
171 { 0xaa, 0x55, 0x00 }, /* 6 2/3 1/3 0 Brown */
172 { 0xaa, 0xaa, 0xaa }, /* 7 2/3 2/3 2/3 White */
173 { 0x55, 0x55, 0x55 }, /* 8 1/3 1/3 1/3 Gray */
174 { 0x55, 0x55, 0xff }, /* 9 1/3 1/3 1 Bright Blue */
175 { 0x55, 0xff, 0x55 }, /* 10 1/3 1 1/3 Bright Green */
176 { 0x55, 0xff, 0xff }, /* 11 1/3 1 1 Bright Cyan */
177 { 0xff, 0x55, 0x55 }, /* 12 1 1/3 1/3 Bright Red */
178 { 0xff, 0x55, 0xff }, /* 13 1 1/3 1 Bright Magenta */
179 { 0xff, 0xff, 0x80 }, /* 14 1 1 1/3 Bright Yellow */
180 { 0xff, 0xff, 0xff } /* 15 1 1 1 Bright White */
183 #define TODO printf("%s: unimplemented\n", __func__)
185 static u_int16_t ofwfb_static_window[ROW*COL];
187 static struct ofwfb_softc ofwfb_softc;
190 ofwfb_background(uint8_t attr)
196 ofwfb_foreground(uint8_t attr)
198 return (attr & 0x0f);
202 ofwfb_pix32(int attr)
206 retval = (ofwfb_cmap[attr].blue << 16) |
207 (ofwfb_cmap[attr].green << 8) |
208 ofwfb_cmap[attr].red;
214 ofwfb_configure(int flags)
216 struct ofwfb_softc *sc;
228 TUNABLE_INT_FETCH("hw.syscons.disable", &disable);
238 chosen = OF_finddevice("/chosen");
239 OF_getprop(chosen, "stdout", &stdout, sizeof(stdout));
240 node = OF_instance_to_package(stdout);
243 * The "/chosen/stdout" does not exist try
244 * using "screen" directly.
246 node = OF_finddevice("screen");
248 OF_getprop(node, "device_type", type, sizeof(type));
249 if (strcmp(type, "display") != 0)
252 /* Only support 8 and 32-bit framebuffers */
253 OF_getprop(node, "depth", &depth, sizeof(depth));
255 sc->sc_blank = ofwfb_blank_display8;
256 sc->sc_putc = ofwfb_putc8;
257 sc->sc_putm = ofwfb_putm8;
258 sc->sc_set_border = ofwfb_set_border8;
259 } else if (depth == 32) {
260 sc->sc_blank = ofwfb_blank_display32;
261 sc->sc_putc = ofwfb_putc32;
262 sc->sc_putm = ofwfb_putm32;
263 sc->sc_set_border = ofwfb_set_border32;
267 sc->sc_depth = depth;
270 OF_getprop(node, "height", &sc->sc_height, sizeof(sc->sc_height));
271 OF_getprop(node, "width", &sc->sc_width, sizeof(sc->sc_width));
272 OF_getprop(node, "linebytes", &sc->sc_stride, sizeof(sc->sc_stride));
275 * Grab the physical address of the framebuffer, and then map it
276 * into our memory space. If the MMU is not yet up, it will be
277 * remapped for us when relocation turns on.
279 * XXX We assume #address-cells is 1 at this point.
281 OF_getprop(node, "address", &fb_phys, sizeof(fb_phys));
283 bus_space_map(&bs_be_tag, fb_phys, sc->sc_height * sc->sc_stride,
284 BUS_SPACE_MAP_PREFETCHABLE, &sc->sc_addr);
287 * Get the PCI addresses of the adapter. The node may be the
288 * child of the PCI device: in that case, try the parent for
289 * the assigned-addresses property.
291 len = OF_getprop(node, "assigned-addresses", sc->sc_pciaddrs,
292 sizeof(sc->sc_pciaddrs));
294 len = OF_getprop(OF_parent(node), "assigned-addresses",
295 sc->sc_pciaddrs, sizeof(sc->sc_pciaddrs));
299 sc->sc_num_pciaddrs = len / sizeof(struct ofw_pci_register);
302 ofwfb_init(0, &sc->sc_va, 0);
308 ofwfb_probe(int unit, video_adapter_t **adp, void *arg, int flags)
315 ofwfb_init(int unit, video_adapter_t *adp, int flags)
317 struct ofwfb_softc *sc;
322 sc = (struct ofwfb_softc *)adp;
325 vid_init_struct(adp, "ofwfb", -1, unit);
327 /* The default font size can be overridden by loader */
329 TUNABLE_INT_FETCH("hw.syscons.fsize", &font_height);
330 if (font_height == 8) {
331 sc->sc_font = dflt_font_8;
332 sc->sc_font_height = 8;
333 } else if (font_height == 14) {
334 sc->sc_font = dflt_font_14;
335 sc->sc_font_height = 14;
337 /* default is 8x16 */
338 sc->sc_font = dflt_font_16;
339 sc->sc_font_height = 16;
342 /* The user can set a border in chars - default is 1 char width */
344 TUNABLE_INT_FETCH("hw.syscons.border", &cborder);
346 vi->vi_cheight = sc->sc_font_height;
347 vi->vi_width = sc->sc_width/8 - 2*cborder;
348 vi->vi_height = sc->sc_height/sc->sc_font_height - 2*cborder;
352 * Clamp width/height to syscons maximums
354 if (vi->vi_width > COL)
356 if (vi->vi_height > ROW)
359 sc->sc_xmargin = (sc->sc_width - (vi->vi_width * vi->vi_cwidth)) / 2;
360 sc->sc_ymargin = (sc->sc_height - (vi->vi_height * vi->vi_cheight))/2;
363 * Avoid huge amounts of conditional code in syscons by
364 * defining a dummy h/w text display buffer.
366 adp->va_window = (vm_offset_t) ofwfb_static_window;
369 * Enable future font-loading and flag color support, as well as
370 * adding V_ADP_MODECHANGE so that we ofwfb_set_mode() gets called
371 * when the X server shuts down. This enables us to get the console
372 * back when X disappears.
374 adp->va_flags |= V_ADP_FONT | V_ADP_COLOR | V_ADP_MODECHANGE;
376 ofwfb_set_mode(&sc->sc_va, 0);
378 vid_register(&sc->sc_va);
384 ofwfb_get_info(video_adapter_t *adp, int mode, video_info_t *info)
386 bcopy(&adp->va_info, info, sizeof(*info));
391 ofwfb_query_mode(video_adapter_t *adp, video_info_t *info)
398 ofwfb_set_mode(video_adapter_t *adp, int mode)
400 struct ofwfb_softc *sc;
405 sc = (struct ofwfb_softc *)adp;
408 * Open the display device, which will initialize it.
411 memset(name, 0, sizeof(name));
412 OF_package_to_path(sc->sc_node, name, sizeof(name));
415 if (sc->sc_depth == 8) {
417 * Install the ISO6429 colormap - older OFW systems
418 * don't do this by default
420 for (i = 0; i < 16; i++) {
421 OF_call_method("color!", ih, 4, 1,
430 ofwfb_blank_display(&sc->sc_va, V_DISPLAY_ON);
436 ofwfb_save_font(video_adapter_t *adp, int page, int size, int width,
437 u_char *data, int c, int count)
444 ofwfb_load_font(video_adapter_t *adp, int page, int size, int width,
445 u_char *data, int c, int count)
447 struct ofwfb_softc *sc;
449 sc = (struct ofwfb_softc *)adp;
452 * syscons code has already determined that current width/height
453 * are unchanged for this new font
460 ofwfb_show_font(video_adapter_t *adp, int page)
467 ofwfb_save_palette(video_adapter_t *adp, u_char *palette)
474 ofwfb_load_palette(video_adapter_t *adp, u_char *palette)
481 ofwfb_set_border8(video_adapter_t *adp, int border)
483 struct ofwfb_softc *sc;
488 sc = (struct ofwfb_softc *)adp;
490 bground = ofwfb_background(border);
493 addr = (uint8_t *) sc->sc_addr;
494 for (i = 0; i < sc->sc_ymargin; i++) {
495 for (j = 0; j < sc->sc_width; j++) {
496 *(addr + j) = bground;
498 addr += sc->sc_stride;
502 addr = (uint8_t *) sc->sc_addr + (sc->sc_height - sc->sc_ymargin)*sc->sc_stride;
503 for (i = 0; i < sc->sc_ymargin; i++) {
504 for (j = 0; j < sc->sc_width; j++) {
505 *(addr + j) = bground;
507 addr += sc->sc_stride;
510 /* remaining left and right borders */
511 addr = (uint8_t *) sc->sc_addr + sc->sc_ymargin*sc->sc_stride;
512 for (i = 0; i < sc->sc_height - 2*sc->sc_xmargin; i++) {
513 for (j = 0; j < sc->sc_xmargin; j++) {
514 *(addr + j) = bground;
515 *(addr + j + sc->sc_width - sc->sc_xmargin) = bground;
517 addr += sc->sc_stride;
524 ofwfb_set_border32(video_adapter_t *adp, int border)
526 /* XXX Be lazy for now and blank entire screen */
527 return (ofwfb_blank_display32(adp, border));
531 ofwfb_set_border(video_adapter_t *adp, int border)
533 struct ofwfb_softc *sc;
535 sc = (struct ofwfb_softc *)adp;
537 return ((*sc->sc_set_border)(adp, border));
541 ofwfb_save_state(video_adapter_t *adp, void *p, size_t size)
548 ofwfb_load_state(video_adapter_t *adp, void *p)
555 ofwfb_set_win_org(video_adapter_t *adp, off_t offset)
562 ofwfb_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
571 ofwfb_set_hw_cursor(video_adapter_t *adp, int col, int row)
578 ofwfb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
579 int celsize, int blink)
585 ofwfb_blank_display8(video_adapter_t *adp, int mode)
587 struct ofwfb_softc *sc;
591 sc = (struct ofwfb_softc *)adp;
592 addr = (uint8_t *) sc->sc_addr;
594 /* Could be done a lot faster e.g. 32-bits, or Altivec'd */
595 for (i = 0; i < sc->sc_stride*sc->sc_height; i++)
596 *(addr + i) = ofwfb_background(SC_NORM_ATTR);
602 ofwfb_blank_display32(video_adapter_t *adp, int mode)
604 struct ofwfb_softc *sc;
608 sc = (struct ofwfb_softc *)adp;
609 addr = (uint32_t *) sc->sc_addr;
611 for (i = 0; i < (sc->sc_stride/4)*sc->sc_height; i++)
612 *(addr + i) = ofwfb_pix32(ofwfb_background(SC_NORM_ATTR));
618 ofwfb_blank_display(video_adapter_t *adp, int mode)
620 struct ofwfb_softc *sc;
622 sc = (struct ofwfb_softc *)adp;
624 return ((*sc->sc_blank)(adp, mode));
628 ofwfb_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr,
629 int prot, vm_memattr_t *memattr)
631 struct ofwfb_softc *sc;
634 sc = (struct ofwfb_softc *)adp;
637 * Make sure the requested address lies within the PCI device's
640 for (i = 0; i < sc->sc_num_pciaddrs; i++)
641 if (offset >= sc->sc_pciaddrs[i].phys_lo &&
642 offset < (sc->sc_pciaddrs[i].phys_lo + sc->sc_pciaddrs[i].size_lo))
645 * If this is a prefetchable BAR, we can (and should)
646 * enable write-combining.
648 if (sc->sc_pciaddrs[i].phys_hi &
649 OFW_PCI_PHYS_HI_PREFETCHABLE)
650 *memattr = VM_MEMATTR_WRITE_COMBINING;
659 if (ofwfb_ignore_mmap_checks) {
665 * This might be a legacy VGA mem request: if so, just point it at the
666 * framebuffer, since it shouldn't be touched
668 if (offset < sc->sc_stride*sc->sc_height) {
669 *paddr = sc->sc_addr + offset;
674 * Error if we didn't have a better idea.
676 if (sc->sc_num_pciaddrs == 0)
683 ofwfb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data)
690 ofwfb_clear(video_adapter_t *adp)
697 ofwfb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
704 ofwfb_bitblt(video_adapter_t *adp, ...)
711 ofwfb_diag(video_adapter_t *adp, int level)
718 ofwfb_save_cursor_palette(video_adapter_t *adp, u_char *palette)
725 ofwfb_load_cursor_palette(video_adapter_t *adp, u_char *palette)
732 ofwfb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n)
739 ofwfb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a,
740 int size, int bpp, int bit_ltor, int byte_ltor)
747 ofwfb_putc8(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a)
749 struct ofwfb_softc *sc;
761 sc = (struct ofwfb_softc *)adp;
762 row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
763 col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
764 p = sc->sc_font + c*sc->sc_font_height;
765 addr = (u_int32_t *)((uintptr_t)sc->sc_addr
766 + (row + sc->sc_ymargin)*sc->sc_stride
767 + col + sc->sc_xmargin);
769 fg = ofwfb_foreground(a);
770 bg = ofwfb_background(a);
772 for (i = 0; i < sc->sc_font_height; i++) {
776 * Assume that there is more background than foreground
777 * in characters and init accordingly
779 ch1.l = ch2.l = (bg << 24) | (bg << 16) | (bg << 8) | bg;
782 * Calculate 2 x 4-chars at a time, and then
785 if (fline & 0x80) ch1.c[0] = fg;
786 if (fline & 0x40) ch1.c[1] = fg;
787 if (fline & 0x20) ch1.c[2] = fg;
788 if (fline & 0x10) ch1.c[3] = fg;
790 if (fline & 0x08) ch2.c[0] = fg;
791 if (fline & 0x04) ch2.c[1] = fg;
792 if (fline & 0x02) ch2.c[2] = fg;
793 if (fline & 0x01) ch2.c[3] = fg;
797 addr += (sc->sc_stride / sizeof(u_int32_t));
804 ofwfb_putc32(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a)
806 struct ofwfb_softc *sc;
813 sc = (struct ofwfb_softc *)adp;
814 row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
815 col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
816 p = sc->sc_font + c*sc->sc_font_height;
817 addr = (uint32_t *)sc->sc_addr
818 + (row + sc->sc_ymargin)*(sc->sc_stride/4)
819 + col + sc->sc_xmargin;
821 for (i = 0; i < sc->sc_font_height; i++) {
822 for (j = 0, k = 7; j < 8; j++, k--) {
823 if ((p[i] & (1 << k)) == 0)
824 *(addr + j) = ofwfb_pix32(ofwfb_background(a));
826 *(addr + j) = ofwfb_pix32(ofwfb_foreground(a));
828 addr += (sc->sc_stride/4);
835 ofwfb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a)
837 struct ofwfb_softc *sc;
839 sc = (struct ofwfb_softc *)adp;
841 return ((*sc->sc_putc)(adp, off, c, a));
845 ofwfb_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len)
849 for (i = 0; i < len; i++) {
850 ofwfb_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8);
856 ofwfb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image,
857 uint32_t pixel_mask, int size, int width)
859 struct ofwfb_softc *sc;
861 sc = (struct ofwfb_softc *)adp;
863 return ((*sc->sc_putm)(adp, x, y, pixel_image, pixel_mask, size,
868 ofwfb_putm8(video_adapter_t *adp, int x, int y, uint8_t *pixel_image,
869 uint32_t pixel_mask, int size, int width)
871 struct ofwfb_softc *sc;
876 sc = (struct ofwfb_softc *)adp;
877 addr = (u_int8_t *)((uintptr_t)sc->sc_addr
878 + (y + sc->sc_ymargin)*sc->sc_stride
879 + x + sc->sc_xmargin);
881 fg = ofwfb_foreground(SC_NORM_ATTR);
882 bg = ofwfb_background(SC_NORM_ATTR);
884 for (i = 0; i < size && i+y < sc->sc_height - 2*sc->sc_ymargin; i++) {
886 * Calculate 2 x 4-chars at a time, and then
889 for (j = 0, k = width; j < 8; j++, k--) {
890 if (x + j >= sc->sc_width - 2*sc->sc_xmargin)
893 if (pixel_image[i] & (1 << k))
894 addr[j] = (addr[j] == fg) ? bg : fg;
897 addr += (sc->sc_stride / sizeof(u_int8_t));
904 ofwfb_putm32(video_adapter_t *adp, int x, int y, uint8_t *pixel_image,
905 uint32_t pixel_mask, int size, int width)
907 struct ofwfb_softc *sc;
912 sc = (struct ofwfb_softc *)adp;
913 addr = (uint32_t *)sc->sc_addr
914 + (y + sc->sc_ymargin)*(sc->sc_stride/4)
915 + x + sc->sc_xmargin;
917 fg = ofwfb_pix32(ofwfb_foreground(SC_NORM_ATTR));
918 bg = ofwfb_pix32(ofwfb_background(SC_NORM_ATTR));
920 for (i = 0; i < size && i+y < sc->sc_height - 2*sc->sc_ymargin; i++) {
921 for (j = 0, k = width; j < 8; j++, k--) {
922 if (x + j >= sc->sc_width - 2*sc->sc_xmargin)
925 if (pixel_image[i] & (1 << k))
926 *(addr + j) = (*(addr + j) == fg) ? bg : fg;
928 addr += (sc->sc_stride/4);
935 * Define the syscons nexus device attachment
938 ofwfb_scidentify(driver_t *driver, device_t parent)
943 * Add with a priority guaranteed to make it last on
946 child = BUS_ADD_CHILD(parent, INT_MAX, SC_DRIVER_NAME, 0);
950 ofwfb_scprobe(device_t dev)
954 device_set_desc(dev, "System console");
956 error = sc_probe_unit(device_get_unit(dev),
957 device_get_flags(dev) | SC_AUTODETECT_KBD);
961 /* This is a fake device, so make sure we added it ourselves */
962 return (BUS_PROBE_NOWILDCARD);
966 ofwfb_scattach(device_t dev)
968 return (sc_attach_unit(device_get_unit(dev),
969 device_get_flags(dev) | SC_AUTODETECT_KBD));
972 static device_method_t ofwfb_sc_methods[] = {
973 DEVMETHOD(device_identify, ofwfb_scidentify),
974 DEVMETHOD(device_probe, ofwfb_scprobe),
975 DEVMETHOD(device_attach, ofwfb_scattach),
979 static driver_t ofwfb_sc_driver = {
985 static devclass_t sc_devclass;
987 DRIVER_MODULE(ofwfb, nexus, ofwfb_sc_driver, sc_devclass, 0, 0);
990 * Define a stub keyboard driver in case one hasn't been
991 * compiled into the kernel
993 #include <sys/kbio.h>
994 #include <dev/kbd/kbdreg.h>
996 static int dummy_kbd_configure(int flags);
998 keyboard_switch_t dummysw;
1001 dummy_kbd_configure(int flags)
1006 KEYBOARD_DRIVER(dummy, dummysw, dummy_kbd_configure);
1009 * Utility routines from <dev/fb/fbreg.h>
1012 ofwfb_bcopy(const void *s, void *d, size_t c)
1018 ofwfb_bzero(void *d, size_t c)
1024 ofwfb_fillw(int pat, void *base, size_t cnt)
1026 u_int16_t *bptr = base;
1033 ofwfb_readw(u_int16_t *addr)
1039 ofwfb_writew(u_int16_t *addr, u_int16_t val)