xref: /freebsd/sys/arm/broadcom/bcm2835/bcm2835_fb.c (revision 069ac184)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  */
29 
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/bus.h>
33 #include <sys/consio.h>
34 #include <sys/fbio.h>
35 #include <sys/kdb.h>
36 #include <sys/kernel.h>
37 #include <sys/malloc.h>
38 #include <sys/module.h>
39 
40 #include <vm/vm.h>
41 #include <vm/pmap.h>
42 
43 #include <dev/fb/fbreg.h>
44 #include <dev/ofw/ofw_bus.h>
45 #include <dev/ofw/ofw_bus_subr.h>
46 #include <dev/syscons/syscons.h>
47 
48 #include <arm/broadcom/bcm2835/bcm2835_mbox_prop.h>
49 
50 #include "mbox_if.h"
51 
52 struct argb {
53 	uint8_t		a;
54 	uint8_t		r;
55 	uint8_t		g;
56 	uint8_t		b;
57 };
58 
59 static struct argb bcmfb_palette[16] = {
60 	{0x00, 0x00, 0x00, 0x00},
61 	{0x00, 0x00, 0x00, 0xaa},
62 	{0x00, 0x00, 0xaa, 0x00},
63 	{0x00, 0x00, 0xaa, 0xaa},
64 	{0x00, 0xaa, 0x00, 0x00},
65 	{0x00, 0xaa, 0x00, 0xaa},
66 	{0x00, 0xaa, 0x55, 0x00},
67 	{0x00, 0xaa, 0xaa, 0xaa},
68 	{0x00, 0x55, 0x55, 0x55},
69 	{0x00, 0x55, 0x55, 0xff},
70 	{0x00, 0x55, 0xff, 0x55},
71 	{0x00, 0x55, 0xff, 0xff},
72 	{0x00, 0xff, 0x55, 0x55},
73 	{0x00, 0xff, 0x55, 0xff},
74 	{0x00, 0xff, 0xff, 0x55},
75 	{0x00, 0xff, 0xff, 0xff}
76 };
77 
78 /* mouse pointer from dev/syscons/scgfbrndr.c */
79 static u_char mouse_pointer[16] = {
80         0x00, 0x40, 0x60, 0x70, 0x78, 0x7c, 0x7e, 0x68,
81         0x0c, 0x0c, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00
82 };
83 
84 #define	BCMFB_FONT_HEIGHT	16
85 #define	BCMFB_FONT_WIDTH	8
86 #define	FB_WIDTH		640
87 #define	FB_HEIGHT		480
88 #define	FB_DEPTH		24
89 
90 struct bcmsc_softc {
91 	/* Videoadpater part */
92 	video_adapter_t	va;
93 
94 	intptr_t	fb_addr;
95 	intptr_t	fb_paddr;
96 	unsigned int	fb_size;
97 
98 	unsigned int	height;
99 	unsigned int	width;
100 	unsigned int	depth;
101 	unsigned int	stride;
102 
103 	unsigned int	xmargin;
104 	unsigned int	ymargin;
105 
106 	unsigned char	*font;
107 	int		fbswap;
108 	int		initialized;
109 };
110 
111 static struct bcmsc_softc bcmsc;
112 
113 static struct ofw_compat_data compat_data[] = {
114 	{"broadcom,bcm2835-fb",		1},
115 	{"brcm,bcm2708-fb",		1},
116 	{NULL,				0}
117 };
118 
119 static int bcm_fb_probe(device_t);
120 static int bcm_fb_attach(device_t);
121 static void bcmfb_update_margins(video_adapter_t *adp);
122 static int bcmfb_configure(int);
123 
124 static int
125 bcm_fb_probe(device_t dev)
126 {
127 	int error;
128 
129 	if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
130 		return (ENXIO);
131 
132 	device_set_desc(dev, "BCM2835 framebuffer device");
133 	error = sc_probe_unit(device_get_unit(dev),
134 	    device_get_flags(dev) | SC_AUTODETECT_KBD);
135 	if (error != 0)
136 		return (error);
137 
138 	return (BUS_PROBE_DEFAULT);
139 }
140 
141 static int
142 bcm_fb_attach(device_t dev)
143 {
144 	struct bcm2835_fb_config fb;
145 	struct bcmsc_softc *sc;
146 
147 	sc = (struct bcmsc_softc *)vid_get_adapter(vid_find_adapter(
148 	    "bcmfb", 0));
149 	if (sc != NULL)
150 		device_set_softc(dev, sc);
151 	else
152 		sc = device_get_softc(dev);
153 
154 	memset(&fb, 0, sizeof(fb));
155 	if (bcm2835_mbox_fb_get_w_h(&fb) != 0)
156 		return (ENXIO);
157 	fb.bpp = FB_DEPTH;
158 	fb.vxres = fb.xres;
159 	fb.vyres = fb.yres;
160 	fb.xoffset = fb.yoffset = 0;
161 	if (bcm2835_mbox_fb_init(&fb) != 0)
162 		return (ENXIO);
163 
164 	sc->fb_addr = (intptr_t)pmap_mapdev(fb.base, fb.size);
165 	sc->fb_paddr = fb.base;
166 	sc->fb_size = fb.size;
167 	sc->depth = fb.bpp;
168 	sc->stride = fb.pitch;
169 	sc->width = fb.xres;
170 	sc->height = fb.yres;
171 	bcmfb_update_margins(&sc->va);
172 
173 	if (sc_attach_unit(device_get_unit(dev),
174 	    device_get_flags(dev) | SC_AUTODETECT_KBD) != 0) {
175 		device_printf(dev, "failed to attach syscons\n");
176 		return (ENXIO);
177 	}
178 
179 	device_printf(dev, "%dx%d(%dx%d@%d,%d) %dbpp\n", fb.xres, fb.yres,
180 	    fb.vxres, fb.vyres, fb.xoffset, fb.yoffset, fb.bpp);
181 	device_printf(dev,
182 	    "fbswap: %d, pitch %d, base 0x%08x, screen_size %d\n",
183 	    sc->fbswap, fb.pitch, fb.base, fb.size);
184 
185 	return (0);
186 }
187 
188 static device_method_t bcm_fb_methods[] = {
189 	/* Device interface */
190 	DEVMETHOD(device_probe,		bcm_fb_probe),
191 	DEVMETHOD(device_attach,	bcm_fb_attach),
192 	{ 0, 0 }
193 };
194 
195 static driver_t bcm_fb_driver = {
196 	"fb",
197 	bcm_fb_methods,
198 	sizeof(struct bcmsc_softc),
199 };
200 
201 DRIVER_MODULE(bcm2835fb, ofwbus, bcm_fb_driver, 0, 0);
202 DRIVER_MODULE(bcm2835fb, simplebus, bcm_fb_driver, 0, 0);
203 
204 /*
205  * Video driver routines and glue.
206  */
207 static vi_probe_t		bcmfb_probe;
208 static vi_init_t		bcmfb_init;
209 static vi_get_info_t		bcmfb_get_info;
210 static vi_query_mode_t		bcmfb_query_mode;
211 static vi_set_mode_t		bcmfb_set_mode;
212 static vi_save_font_t		bcmfb_save_font;
213 static vi_load_font_t		bcmfb_load_font;
214 static vi_show_font_t		bcmfb_show_font;
215 static vi_save_palette_t	bcmfb_save_palette;
216 static vi_load_palette_t	bcmfb_load_palette;
217 static vi_set_border_t		bcmfb_set_border;
218 static vi_save_state_t		bcmfb_save_state;
219 static vi_load_state_t		bcmfb_load_state;
220 static vi_set_win_org_t		bcmfb_set_win_org;
221 static vi_read_hw_cursor_t	bcmfb_read_hw_cursor;
222 static vi_set_hw_cursor_t	bcmfb_set_hw_cursor;
223 static vi_set_hw_cursor_shape_t	bcmfb_set_hw_cursor_shape;
224 static vi_blank_display_t	bcmfb_blank_display;
225 static vi_mmap_t		bcmfb_mmap;
226 static vi_ioctl_t		bcmfb_ioctl;
227 static vi_clear_t		bcmfb_clear;
228 static vi_fill_rect_t		bcmfb_fill_rect;
229 static vi_bitblt_t		bcmfb_bitblt;
230 static vi_diag_t		bcmfb_diag;
231 static vi_save_cursor_palette_t	bcmfb_save_cursor_palette;
232 static vi_load_cursor_palette_t	bcmfb_load_cursor_palette;
233 static vi_copy_t		bcmfb_copy;
234 static vi_putp_t		bcmfb_putp;
235 static vi_putc_t		bcmfb_putc;
236 static vi_puts_t		bcmfb_puts;
237 static vi_putm_t		bcmfb_putm;
238 
239 static video_switch_t bcmfbvidsw = {
240 	.probe			= bcmfb_probe,
241 	.init			= bcmfb_init,
242 	.get_info		= bcmfb_get_info,
243 	.query_mode		= bcmfb_query_mode,
244 	.set_mode		= bcmfb_set_mode,
245 	.save_font		= bcmfb_save_font,
246 	.load_font		= bcmfb_load_font,
247 	.show_font		= bcmfb_show_font,
248 	.save_palette		= bcmfb_save_palette,
249 	.load_palette		= bcmfb_load_palette,
250 	.set_border		= bcmfb_set_border,
251 	.save_state		= bcmfb_save_state,
252 	.load_state		= bcmfb_load_state,
253 	.set_win_org		= bcmfb_set_win_org,
254 	.read_hw_cursor		= bcmfb_read_hw_cursor,
255 	.set_hw_cursor		= bcmfb_set_hw_cursor,
256 	.set_hw_cursor_shape	= bcmfb_set_hw_cursor_shape,
257 	.blank_display		= bcmfb_blank_display,
258 	.mmap			= bcmfb_mmap,
259 	.ioctl			= bcmfb_ioctl,
260 	.clear			= bcmfb_clear,
261 	.fill_rect		= bcmfb_fill_rect,
262 	.bitblt			= bcmfb_bitblt,
263 	.diag			= bcmfb_diag,
264 	.save_cursor_palette	= bcmfb_save_cursor_palette,
265 	.load_cursor_palette	= bcmfb_load_cursor_palette,
266 	.copy			= bcmfb_copy,
267 	.putp			= bcmfb_putp,
268 	.putc			= bcmfb_putc,
269 	.puts			= bcmfb_puts,
270 	.putm			= bcmfb_putm,
271 };
272 
273 VIDEO_DRIVER(bcmfb, bcmfbvidsw, bcmfb_configure);
274 
275 static vr_init_t bcmrend_init;
276 static vr_clear_t bcmrend_clear;
277 static vr_draw_border_t bcmrend_draw_border;
278 static vr_draw_t bcmrend_draw;
279 static vr_set_cursor_t bcmrend_set_cursor;
280 static vr_draw_cursor_t bcmrend_draw_cursor;
281 static vr_blink_cursor_t bcmrend_blink_cursor;
282 static vr_set_mouse_t bcmrend_set_mouse;
283 static vr_draw_mouse_t bcmrend_draw_mouse;
284 
285 /*
286  * We use our own renderer; this is because we must emulate a hardware
287  * cursor.
288  */
289 static sc_rndr_sw_t bcmrend = {
290 	bcmrend_init,
291 	bcmrend_clear,
292 	bcmrend_draw_border,
293 	bcmrend_draw,
294 	bcmrend_set_cursor,
295 	bcmrend_draw_cursor,
296 	bcmrend_blink_cursor,
297 	bcmrend_set_mouse,
298 	bcmrend_draw_mouse
299 };
300 
301 RENDERER(bcmfb, 0, bcmrend, gfb_set);
302 RENDERER_MODULE(bcmfb, gfb_set);
303 
304 static void
305 bcmrend_init(scr_stat* scp)
306 {
307 }
308 
309 static void
310 bcmrend_clear(scr_stat* scp, int c, int attr)
311 {
312 }
313 
314 static void
315 bcmrend_draw_border(scr_stat* scp, int color)
316 {
317 }
318 
319 static void
320 bcmrend_draw(scr_stat* scp, int from, int count, int flip)
321 {
322 	video_adapter_t* adp = scp->sc->adp;
323 	int i, c, a;
324 
325 	if (!flip) {
326 		/* Normal printing */
327 		vidd_puts(adp, from, (uint16_t*)sc_vtb_pointer(&scp->vtb, from), count);
328 	} else {
329 		/* This is for selections and such: invert the color attribute */
330 		for (i = count; i-- > 0; ++from) {
331 			c = sc_vtb_getc(&scp->vtb, from);
332 			a = sc_vtb_geta(&scp->vtb, from) >> 8;
333 			vidd_putc(adp, from, c, (a >> 4) | ((a & 0xf) << 4));
334 		}
335 	}
336 }
337 
338 static void
339 bcmrend_set_cursor(scr_stat* scp, int base, int height, int blink)
340 {
341 }
342 
343 static void
344 bcmrend_draw_cursor(scr_stat* scp, int off, int blink, int on, int flip)
345 {
346 	int bytes, col, i, j, row;
347 	struct bcmsc_softc *sc;
348 	uint8_t *addr;
349 	video_adapter_t *adp;
350 
351 	adp = scp->sc->adp;
352 	sc = (struct bcmsc_softc *)adp;
353 
354 	if (scp->curs_attr.height <= 0)
355 		return;
356 
357 	if (sc->fb_addr == 0)
358 		return;
359 
360 	if (off >= adp->va_info.vi_width * adp->va_info.vi_height)
361 		return;
362 
363 	/* calculate the coordinates in the video buffer */
364 	row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
365 	col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
366 
367 	addr = (uint8_t *)sc->fb_addr
368 	    + (row + sc->ymargin)*(sc->stride)
369 	    + (sc->depth/8) * (col + sc->xmargin);
370 
371 	bytes = sc->depth / 8;
372 	/* our cursor consists of simply inverting the char under it */
373 	for (i = 0; i < adp->va_info.vi_cheight; i++) {
374 		for (j = 0; j < adp->va_info.vi_cwidth; j++) {
375 			switch (sc->depth) {
376 			case 32:
377 			case 24:
378 				addr[bytes*j + 2] ^= 0xff;
379 				/* FALLTHROUGH */
380 			case 16:
381 				addr[bytes*j + 1] ^= 0xff;
382 				addr[bytes*j] ^= 0xff;
383 				break;
384 			default:
385 				break;
386 			}
387 		}
388 
389 		addr += sc->stride;
390 	}
391 }
392 
393 static void
394 bcmrend_blink_cursor(scr_stat* scp, int at, int flip)
395 {
396 }
397 
398 static void
399 bcmrend_set_mouse(scr_stat* scp)
400 {
401 }
402 
403 static void
404 bcmrend_draw_mouse(scr_stat* scp, int x, int y, int on)
405 {
406 	vidd_putm(scp->sc->adp, x, y, mouse_pointer, 0xffffffff, 16, 8);
407 }
408 
409 static uint16_t bcmfb_static_window[ROW*COL];
410 extern u_char dflt_font_16[];
411 
412 /*
413  * Update videoadapter settings after changing resolution
414  */
415 static void
416 bcmfb_update_margins(video_adapter_t *adp)
417 {
418 	struct bcmsc_softc *sc;
419 	video_info_t *vi;
420 
421 	sc = (struct bcmsc_softc *)adp;
422 	vi = &adp->va_info;
423 
424 	sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2;
425 	sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight)) / 2;
426 }
427 
428 static int
429 bcmfb_configure(int flags)
430 {
431 	char bootargs[2048], *n, *p, *v;
432 	pcell_t cell;
433 	phandle_t chosen, display, root;
434 	struct bcmsc_softc *sc;
435 
436 	sc = &bcmsc;
437 	if (sc->initialized)
438 		return (0);
439 
440 	sc->width = 0;
441 	sc->height = 0;
442 
443 	/*
444 	 * It seems there is no way to let syscons framework know
445 	 * that framebuffer resolution has changed. So just try
446 	 * to fetch data from FDT bootargs, FDT display data and
447 	 * finally go with defaults if everything else has failed.
448 	 */
449 	chosen = OF_finddevice("/chosen");
450 	if (chosen != -1 &&
451 	    OF_getprop(chosen, "bootargs", &bootargs, sizeof(bootargs)) > 0) {
452 		p = bootargs;
453 		while ((v = strsep(&p, " ")) != NULL) {
454 			if (*v == '\0')
455 				continue;
456 			n = strsep(&v, "=");
457 			if (strcmp(n, "bcm2708_fb.fbwidth") == 0 && v != NULL)
458 				sc->width = (unsigned int)strtol(v, NULL, 0);
459 			else if (strcmp(n, "bcm2708_fb.fbheight") == 0 &&
460 			    v != NULL)
461 				sc->height = (unsigned int)strtol(v, NULL, 0);
462 			else if (strcmp(n, "bcm2708_fb.fbswap") == 0 &&
463 			    v != NULL)
464 				if (*v == '1')
465 					sc->fbswap = 1;
466 		}
467 	}
468 
469 	root = OF_finddevice("/");
470 	if ((root != -1) &&
471 	    (display = fdt_find_compatible(root, "broadcom,bcm2835-fb", 1))) {
472 		if (sc->width == 0) {
473 			if ((OF_getencprop(display, "broadcom,width",
474 			    &cell, sizeof(cell))) > 0)
475 				sc->width = cell;
476 		}
477 
478 		if (sc->height == 0) {
479 			if ((OF_getencprop(display, "broadcom,height",
480 			    &cell, sizeof(cell))) > 0)
481 				sc->height = cell;
482 		}
483 	}
484 
485 	if (sc->width == 0)
486 		sc->width = FB_WIDTH;
487 	if (sc->height == 0)
488 		sc->height = FB_HEIGHT;
489 
490 	bcmfb_init(0, &sc->va, 0);
491 	sc->initialized = 1;
492 
493 	return (0);
494 }
495 
496 static int
497 bcmfb_probe(int unit, video_adapter_t **adp, void *arg, int flags)
498 {
499 
500 	return (0);
501 }
502 
503 static int
504 bcmfb_init(int unit, video_adapter_t *adp, int flags)
505 {
506 	struct bcmsc_softc *sc;
507 	video_info_t *vi;
508 
509 	sc = (struct bcmsc_softc *)adp;
510 	vi = &adp->va_info;
511 
512 	vid_init_struct(adp, "bcmfb", -1, unit);
513 
514 	sc->font = dflt_font_16;
515 	vi->vi_cheight = BCMFB_FONT_HEIGHT;
516 	vi->vi_cwidth = BCMFB_FONT_WIDTH;
517 	vi->vi_width = sc->width / vi->vi_cwidth;
518 	vi->vi_height = sc->height / vi->vi_cheight;
519 
520 	/*
521 	 * Clamp width/height to syscons maximums
522 	 */
523 	if (vi->vi_width > COL)
524 		vi->vi_width = COL;
525 	if (vi->vi_height > ROW)
526 		vi->vi_height = ROW;
527 
528 	sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2;
529 	sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight)) / 2;
530 
531 	adp->va_window = (vm_offset_t) bcmfb_static_window;
532 	adp->va_flags |= V_ADP_FONT /* | V_ADP_COLOR | V_ADP_MODECHANGE */;
533 
534 	vid_register(&sc->va);
535 
536 	return (0);
537 }
538 
539 static int
540 bcmfb_get_info(video_adapter_t *adp, int mode, video_info_t *info)
541 {
542 	bcopy(&adp->va_info, info, sizeof(*info));
543 	return (0);
544 }
545 
546 static int
547 bcmfb_query_mode(video_adapter_t *adp, video_info_t *info)
548 {
549 	return (0);
550 }
551 
552 static int
553 bcmfb_set_mode(video_adapter_t *adp, int mode)
554 {
555 	return (0);
556 }
557 
558 static int
559 bcmfb_save_font(video_adapter_t *adp, int page, int size, int width,
560     u_char *data, int c, int count)
561 {
562 	return (0);
563 }
564 
565 static int
566 bcmfb_load_font(video_adapter_t *adp, int page, int size, int width,
567     u_char *data, int c, int count)
568 {
569 	struct bcmsc_softc *sc;
570 
571 	sc = (struct bcmsc_softc *)adp;
572 	sc->font = data;
573 
574 	return (0);
575 }
576 
577 static int
578 bcmfb_show_font(video_adapter_t *adp, int page)
579 {
580 	return (0);
581 }
582 
583 static int
584 bcmfb_save_palette(video_adapter_t *adp, u_char *palette)
585 {
586 	return (0);
587 }
588 
589 static int
590 bcmfb_load_palette(video_adapter_t *adp, u_char *palette)
591 {
592 	return (0);
593 }
594 
595 static int
596 bcmfb_set_border(video_adapter_t *adp, int border)
597 {
598 	return (bcmfb_blank_display(adp, border));
599 }
600 
601 static int
602 bcmfb_save_state(video_adapter_t *adp, void *p, size_t size)
603 {
604 	return (0);
605 }
606 
607 static int
608 bcmfb_load_state(video_adapter_t *adp, void *p)
609 {
610 	return (0);
611 }
612 
613 static int
614 bcmfb_set_win_org(video_adapter_t *adp, off_t offset)
615 {
616 	return (0);
617 }
618 
619 static int
620 bcmfb_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
621 {
622 	*col = *row = 0;
623 
624 	return (0);
625 }
626 
627 static int
628 bcmfb_set_hw_cursor(video_adapter_t *adp, int col, int row)
629 {
630 	return (0);
631 }
632 
633 static int
634 bcmfb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
635     int celsize, int blink)
636 {
637 	return (0);
638 }
639 
640 static int
641 bcmfb_blank_display(video_adapter_t *adp, int mode)
642 {
643 
644 	struct bcmsc_softc *sc;
645 
646 	sc = (struct bcmsc_softc *)adp;
647 	if (sc && sc->fb_addr)
648 		memset((void*)sc->fb_addr, 0, sc->fb_size);
649 
650 	return (0);
651 }
652 
653 static int
654 bcmfb_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr,
655     int prot, vm_memattr_t *memattr)
656 {
657 	struct bcmsc_softc *sc;
658 
659 	sc = (struct bcmsc_softc *)adp;
660 
661 	/*
662 	 * This might be a legacy VGA mem request: if so, just point it at the
663 	 * framebuffer, since it shouldn't be touched
664 	 */
665 	if (offset < sc->stride*sc->height) {
666 		*paddr = sc->fb_paddr + offset;
667 		return (0);
668 	}
669 
670 	return (EINVAL);
671 }
672 
673 static int
674 bcmfb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data)
675 {
676 	struct bcmsc_softc *sc;
677 	struct fbtype *fb;
678 
679 	sc = (struct bcmsc_softc *)adp;
680 
681 	switch (cmd) {
682 	case FBIOGTYPE:
683 		fb = (struct fbtype *)data;
684 		fb->fb_type = FBTYPE_PCIMISC;
685 		fb->fb_height = sc->height;
686 		fb->fb_width = sc->width;
687 		fb->fb_depth = sc->depth;
688 		if (sc->depth <= 1 || sc->depth > 8)
689 			fb->fb_cmsize = 0;
690 		else
691 			fb->fb_cmsize = 1 << sc->depth;
692 		fb->fb_size = sc->fb_size;
693 		break;
694 	default:
695 		return (fb_commonioctl(adp, cmd, data));
696 	}
697 
698 	return (0);
699 }
700 
701 static int
702 bcmfb_clear(video_adapter_t *adp)
703 {
704 
705 	return (bcmfb_blank_display(adp, 0));
706 }
707 
708 static int
709 bcmfb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
710 {
711 
712 	return (0);
713 }
714 
715 static int
716 bcmfb_bitblt(video_adapter_t *adp, ...)
717 {
718 
719 	return (0);
720 }
721 
722 static int
723 bcmfb_diag(video_adapter_t *adp, int level)
724 {
725 
726 	return (0);
727 }
728 
729 static int
730 bcmfb_save_cursor_palette(video_adapter_t *adp, u_char *palette)
731 {
732 
733 	return (0);
734 }
735 
736 static int
737 bcmfb_load_cursor_palette(video_adapter_t *adp, u_char *palette)
738 {
739 
740 	return (0);
741 }
742 
743 static int
744 bcmfb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n)
745 {
746 
747 	return (0);
748 }
749 
750 static int
751 bcmfb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a,
752     int size, int bpp, int bit_ltor, int byte_ltor)
753 {
754 
755 	return (0);
756 }
757 
758 static int
759 bcmfb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a)
760 {
761 	int bytes, col, i, j, k, row;
762 	struct bcmsc_softc *sc;
763 	u_char *p;
764 	uint8_t *addr, fg, bg, color;
765 	uint16_t rgb;
766 
767 	sc = (struct bcmsc_softc *)adp;
768 
769 	if (sc->fb_addr == 0)
770 		return (0);
771 
772 	row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
773 	col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
774 	p = sc->font + c*BCMFB_FONT_HEIGHT;
775 	addr = (uint8_t *)sc->fb_addr
776 	    + (row + sc->ymargin)*(sc->stride)
777 	    + (sc->depth/8) * (col + sc->xmargin);
778 
779 	fg = a & 0xf ;
780 	bg = (a >> 4) & 0xf;
781 
782 	bytes = sc->depth / 8;
783 	for (i = 0; i < BCMFB_FONT_HEIGHT; i++) {
784 		for (j = 0, k = 7; j < 8; j++, k--) {
785 			if ((p[i] & (1 << k)) == 0)
786 				color = bg;
787 			else
788 				color = fg;
789 
790 			switch (sc->depth) {
791 			case 32:
792 			case 24:
793 				if (sc->fbswap) {
794 					addr[bytes * j + 0] =
795 					    bcmfb_palette[color].b;
796 					addr[bytes * j + 1] =
797 					    bcmfb_palette[color].g;
798 					addr[bytes * j + 2] =
799 					    bcmfb_palette[color].r;
800 				} else {
801 					addr[bytes * j + 0] =
802 					    bcmfb_palette[color].r;
803 					addr[bytes * j + 1] =
804 					    bcmfb_palette[color].g;
805 					addr[bytes * j + 2] =
806 					    bcmfb_palette[color].b;
807 				}
808 				if (sc->depth == 32)
809 					addr[bytes * j + 3] =
810 					    bcmfb_palette[color].a;
811 				break;
812 			case 16:
813 				rgb = (bcmfb_palette[color].r >> 3) << 11;
814 				rgb |= (bcmfb_palette[color].g >> 2) << 5;
815 				rgb |= (bcmfb_palette[color].b >> 3);
816 				addr[bytes * j] = rgb & 0xff;
817 				addr[bytes * j + 1] = (rgb >> 8) & 0xff;
818 			default:
819 				/* Not supported yet */
820 				break;
821 			}
822 		}
823 
824 		addr += (sc->stride);
825 	}
826 
827         return (0);
828 }
829 
830 static int
831 bcmfb_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len)
832 {
833 	int i;
834 
835 	for (i = 0; i < len; i++)
836 		bcmfb_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8);
837 
838 	return (0);
839 }
840 
841 static int
842 bcmfb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image,
843     uint32_t pixel_mask, int size, int width)
844 {
845 
846 	return (0);
847 }
848