xref: /freebsd/sys/dev/fb/fb.c (revision 7660b554bc59a07be0431c17e0e33815818baa69)
1 /*-
2  * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer as
10  *    the first lines of this file unmodified.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31 
32 #include "opt_fb.h"
33 
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/conf.h>
37 #include <sys/bus.h>
38 #include <sys/kernel.h>
39 #include <sys/malloc.h>
40 #include <sys/module.h>
41 #include <sys/uio.h>
42 #include <sys/fbio.h>
43 #include <sys/linker_set.h>
44 
45 #include <vm/vm.h>
46 #include <vm/pmap.h>
47 
48 #include <dev/fb/fbreg.h>
49 
50 SET_DECLARE(videodriver_set, const video_driver_t);
51 
52 /* local arrays */
53 
54 /*
55  * We need at least one entry each in order to initialize a video card
56  * for the kernel console.  The arrays will be increased dynamically
57  * when necessary.
58  */
59 
60 static int		vid_malloc;
61 static int		adapters = 1;
62 static video_adapter_t	*adp_ini;
63 static video_adapter_t	**adapter = &adp_ini;
64 static video_switch_t	*vidsw_ini;
65        video_switch_t	**vidsw = &vidsw_ini;
66 
67 #ifdef FB_INSTALL_CDEV
68 static struct cdevsw	*vidcdevsw_ini;
69 static struct cdevsw	**vidcdevsw = &vidcdevsw_ini;
70 #endif
71 
72 #define ARRAY_DELTA	4
73 
74 static int
75 vid_realloc_array(void)
76 {
77 	video_adapter_t **new_adp;
78 	video_switch_t **new_vidsw;
79 #ifdef FB_INSTALL_CDEV
80 	struct cdevsw **new_cdevsw;
81 #endif
82 	int newsize;
83 	int s;
84 
85 	if (!vid_malloc)
86 		return ENOMEM;
87 
88 	s = spltty();
89 	newsize = ((adapters + ARRAY_DELTA)/ARRAY_DELTA)*ARRAY_DELTA;
90 	new_adp = malloc(sizeof(*new_adp)*newsize, M_DEVBUF, M_WAITOK | M_ZERO);
91 	new_vidsw = malloc(sizeof(*new_vidsw)*newsize, M_DEVBUF,
92 	    M_WAITOK | M_ZERO);
93 #ifdef FB_INSTALL_CDEV
94 	new_cdevsw = malloc(sizeof(*new_cdevsw)*newsize, M_DEVBUF,
95 	    M_WAITOK | M_ZERO);
96 #endif
97 	bcopy(adapter, new_adp, sizeof(*adapter)*adapters);
98 	bcopy(vidsw, new_vidsw, sizeof(*vidsw)*adapters);
99 #ifdef FB_INSTALL_CDEV
100 	bcopy(vidcdevsw, new_cdevsw, sizeof(*vidcdevsw)*adapters);
101 #endif
102 	if (adapters > 1) {
103 		free(adapter, M_DEVBUF);
104 		free(vidsw, M_DEVBUF);
105 #ifdef FB_INSTALL_CDEV
106 		free(vidcdevsw, M_DEVBUF);
107 #endif
108 	}
109 	adapter = new_adp;
110 	vidsw = new_vidsw;
111 #ifdef FB_INSTALL_CDEV
112 	vidcdevsw = new_cdevsw;
113 #endif
114 	adapters = newsize;
115 	splx(s);
116 
117 	if (bootverbose)
118 		printf("fb: new array size %d\n", adapters);
119 
120 	return 0;
121 }
122 
123 static void
124 vid_malloc_init(void *arg)
125 {
126 	vid_malloc = TRUE;
127 }
128 
129 SYSINIT(vid_mem, SI_SUB_KMEM, SI_ORDER_ANY, vid_malloc_init, NULL);
130 
131 /*
132  * Low-level frame buffer driver functions
133  * frame buffer subdrivers, such as the VGA driver, call these functions
134  * to initialize the video_adapter structure and register it to the virtual
135  * frame buffer driver `fb'.
136  */
137 
138 /* initialize the video_adapter_t structure */
139 void
140 vid_init_struct(video_adapter_t *adp, char *name, int type, int unit)
141 {
142 	adp->va_flags = 0;
143 	adp->va_name = name;
144 	adp->va_type = type;
145 	adp->va_unit = unit;
146 }
147 
148 /* Register a video adapter */
149 int
150 vid_register(video_adapter_t *adp)
151 {
152 	const video_driver_t **list;
153 	const video_driver_t *p;
154 	int index;
155 
156 	for (index = 0; index < adapters; ++index) {
157 		if (adapter[index] == NULL)
158 			break;
159 	}
160 	if (index >= adapters) {
161 		if (vid_realloc_array())
162 			return -1;
163 	}
164 
165 	adp->va_index = index;
166 	adp->va_token = NULL;
167 	SET_FOREACH(list, videodriver_set) {
168 		p = *list;
169 		if (strcmp(p->name, adp->va_name) == 0) {
170 			adapter[index] = adp;
171 			vidsw[index] = p->vidsw;
172 			return index;
173 		}
174 	}
175 
176 	return -1;
177 }
178 
179 int
180 vid_unregister(video_adapter_t *adp)
181 {
182 	if ((adp->va_index < 0) || (adp->va_index >= adapters))
183 		return ENOENT;
184 	if (adapter[adp->va_index] != adp)
185 		return ENOENT;
186 
187 	adapter[adp->va_index] = NULL;
188 	vidsw[adp->va_index] = NULL;
189 	return 0;
190 }
191 
192 /* Get video I/O function table */
193 video_switch_t
194 *vid_get_switch(char *name)
195 {
196 	const video_driver_t **list;
197 	const video_driver_t *p;
198 
199 	SET_FOREACH(list, videodriver_set) {
200 		p = *list;
201 		if (strcmp(p->name, name) == 0)
202 			return p->vidsw;
203 	}
204 
205 	return NULL;
206 }
207 
208 /*
209  * Video card client functions
210  * Video card clients, such as the console driver `syscons' and the frame
211  * buffer cdev driver, use these functions to claim and release a card for
212  * exclusive use.
213  */
214 
215 /* find the video card specified by a driver name and a unit number */
216 int
217 vid_find_adapter(char *driver, int unit)
218 {
219 	int i;
220 
221 	for (i = 0; i < adapters; ++i) {
222 		if (adapter[i] == NULL)
223 			continue;
224 		if (strcmp("*", driver) && strcmp(adapter[i]->va_name, driver))
225 			continue;
226 		if ((unit != -1) && (adapter[i]->va_unit != unit))
227 			continue;
228 		return i;
229 	}
230 	return -1;
231 }
232 
233 /* allocate a video card */
234 int
235 vid_allocate(char *driver, int unit, void *id)
236 {
237 	int index;
238 	int s;
239 
240 	s = spltty();
241 	index = vid_find_adapter(driver, unit);
242 	if (index >= 0) {
243 		if (adapter[index]->va_token) {
244 			splx(s);
245 			return -1;
246 		}
247 		adapter[index]->va_token = id;
248 	}
249 	splx(s);
250 	return index;
251 }
252 
253 int
254 vid_release(video_adapter_t *adp, void *id)
255 {
256 	int error;
257 	int s;
258 
259 	s = spltty();
260 	if (adp->va_token == NULL) {
261 		error = EINVAL;
262 	} else if (adp->va_token != id) {
263 		error = EPERM;
264 	} else {
265 		adp->va_token = NULL;
266 		error = 0;
267 	}
268 	splx(s);
269 	return error;
270 }
271 
272 /* Get a video adapter structure */
273 video_adapter_t
274 *vid_get_adapter(int index)
275 {
276 	if ((index < 0) || (index >= adapters))
277 		return NULL;
278 	return adapter[index];
279 }
280 
281 /* Configure drivers: this is a backdoor for the console driver XXX */
282 int
283 vid_configure(int flags)
284 {
285 	const video_driver_t **list;
286 	const video_driver_t *p;
287 
288 	SET_FOREACH(list, videodriver_set) {
289 		p = *list;
290 		if (p->configure != NULL)
291 			(*p->configure)(flags);
292 	}
293 
294 	return 0;
295 }
296 
297 /*
298  * Virtual frame buffer cdev driver functions
299  * The virtual frame buffer driver dispatches driver functions to
300  * appropriate subdrivers.
301  */
302 
303 #define FB_DRIVER_NAME	"fb"
304 
305 #ifdef FB_INSTALL_CDEV
306 
307 #if experimental
308 
309 static devclass_t	fb_devclass;
310 
311 static int		fbprobe(device_t dev);
312 static int		fbattach(device_t dev);
313 
314 static device_method_t fb_methods[] = {
315 	DEVMETHOD(device_probe,		fbprobe),
316 	DEVMETHOD(device_attach,	fbattach),
317 
318 	DEVMETHOD(bus_print_child,	bus_generic_print_child),
319 	{ 0, 0 }
320 };
321 
322 static driver_t fb_driver = {
323 	FB_DRIVER_NAME,
324 	fb_methods,
325 	0,
326 };
327 
328 static int
329 fbprobe(device_t dev)
330 {
331 	int unit;
332 
333 	unit = device_get_unit(dev);
334 	if (unit >= adapters)
335 		return ENXIO;
336 	if (adapter[unit] == NULL)
337 		return ENXIO;
338 
339 	device_set_desc(dev, "generic frame buffer");
340 	return 0;
341 }
342 
343 static int
344 fbattach(device_t dev)
345 {
346 	printf("fbattach: about to attach children\n");
347 	bus_generic_attach(dev);
348 	return 0;
349 }
350 
351 #endif /* experimental */
352 
353 #define FB_UNIT(dev)	minor(dev)
354 #define FB_MKMINOR(unit) (u)
355 
356 #if experimental
357 static d_open_t		fbopen;
358 static d_close_t	fbclose;
359 static d_read_t		fbread;
360 static d_write_t	fbwrite;
361 static d_ioctl_t	fbioctl;
362 static d_mmap_t		fbmmap;
363 
364 #define CDEV_MAJOR	123	/* XXX */
365 
366 static struct cdevsw fb_cdevsw = {
367 	.d_open =	fbopen,
368 	.d_close =	fbclose,
369 	.d_read =	fbread,
370 	.d_write =	fbwrite,
371 	.d_ioctl =	fbioctl,
372 	.d_mmap =	fbmmap,
373 	.d_name =	FB_DRIVER_NAME,
374 	.d_maj =	CDEV_MAJOR,
375 };
376 #endif
377 
378 
379 static int
380 fb_modevent(module_t mod, int type, void *data)
381 {
382 
383 	switch (type) {
384 	case MOD_LOAD:
385 		break;
386 	case MOD_UNLOAD:
387 		printf("fb module unload - not possible for this module type\n");
388 		return EINVAL;
389 	}
390 	return 0;
391 }
392 
393 static moduledata_t fb_mod = {
394 	"fb",
395 	fb_modevent,
396 	NULL
397 };
398 
399 DECLARE_MODULE(fb, fb_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
400 
401 int
402 fb_attach(dev_t dev, video_adapter_t *adp, struct cdevsw *cdevsw)
403 {
404 	int s;
405 
406 	if (adp->va_index >= adapters)
407 		return EINVAL;
408 	if (adapter[adp->va_index] != adp)
409 		return EINVAL;
410 
411 	s = spltty();
412 	adp->va_minor = minor(dev);
413 	vidcdevsw[adp->va_index] = cdevsw;
414 	splx(s);
415 
416 	printf("fb%d at %s%d\n", adp->va_index, adp->va_name, adp->va_unit);
417 	return 0;
418 }
419 
420 int
421 fb_detach(dev_t dev, video_adapter_t *adp, struct cdevsw *cdevsw)
422 {
423 	int s;
424 
425 	if (adp->va_index >= adapters)
426 		return EINVAL;
427 	if (adapter[adp->va_index] != adp)
428 		return EINVAL;
429 	if (vidcdevsw[adp->va_index] != cdevsw)
430 		return EINVAL;
431 
432 	s = spltty();
433 	vidcdevsw[adp->va_index] = NULL;
434 	splx(s);
435 	return 0;
436 }
437 
438 #if experimental
439 static int
440 fbopen(dev_t dev, int flag, int mode, struct thread *td)
441 {
442 	int unit;
443 
444 	unit = FB_UNIT(dev);
445 	if (unit >= adapters)
446 		return ENXIO;
447 	if (vidcdevsw[unit] == NULL)
448 		return ENXIO;
449 	return (*vidcdevsw[unit]->d_open)(makedev(0, adapter[unit]->va_minor),
450 					  flag, mode, td);
451 }
452 
453 static int
454 fbclose(dev_t dev, int flag, int mode, struct thread *td)
455 {
456 	int unit;
457 
458 	unit = FB_UNIT(dev);
459 	if (vidcdevsw[unit] == NULL)
460 		return ENXIO;
461 	return (*vidcdevsw[unit]->d_close)(makedev(0, adapter[unit]->va_minor),
462 					   flag, mode, td);
463 }
464 
465 static int
466 fbread(dev_t dev, struct uio *uio, int flag)
467 {
468 	int unit;
469 
470 	unit = FB_UNIT(dev);
471 	if (vidcdevsw[unit] == NULL)
472 		return ENXIO;
473 	return (*vidcdevsw[unit]->d_read)(makedev(0, adapter[unit]->va_minor),
474 					  uio, flag);
475 }
476 
477 static int
478 fbwrite(dev_t dev, struct uio *uio, int flag)
479 {
480 	int unit;
481 
482 	unit = FB_UNIT(dev);
483 	if (vidcdevsw[unit] == NULL)
484 		return ENXIO;
485 	return (*vidcdevsw[unit]->d_write)(makedev(0, adapter[unit]->va_minor),
486 					   uio, flag);
487 }
488 
489 static int
490 fbioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
491 {
492 	int unit;
493 
494 	unit = FB_UNIT(dev);
495 	if (vidcdevsw[unit] == NULL)
496 		return ENXIO;
497 	return (*vidcdevsw[unit]->d_ioctl)(makedev(0, adapter[unit]->va_minor),
498 					   cmd, arg, flag, td);
499 }
500 
501 static int
502 fbmmap(dev_t dev, vm_offset_t offset, vm_paddr_t *paddr, int nprot)
503 {
504 	int unit;
505 
506 	unit = FB_UNIT(dev);
507 	if (vidcdevsw[unit] == NULL)
508 		return ENXIO;
509 	return (*vidcdevsw[unit]->d_mmap)(makedev(0, adapter[unit]->va_minor),
510 					  offset, paddr, nprot);
511 }
512 
513 DEV_DRIVER_MODULE(fb, foo, fb_driver, fb_devclass, fb_cdevsw, 0, 0);
514 #endif
515 
516 /*
517  * Generic frame buffer cdev driver functions
518  * Frame buffer subdrivers may call these functions to implement common
519  * driver functions.
520  */
521 
522 int genfbopen(genfb_softc_t *sc, video_adapter_t *adp, int flag, int mode,
523 	      struct thread *td)
524 {
525 	int s;
526 
527 	s = spltty();
528 	if (!(sc->gfb_flags & FB_OPEN))
529 		sc->gfb_flags |= FB_OPEN;
530 	splx(s);
531 	return 0;
532 }
533 
534 int genfbclose(genfb_softc_t *sc, video_adapter_t *adp, int flag, int mode,
535 	       struct thread *td)
536 {
537 	int s;
538 
539 	s = spltty();
540 	sc->gfb_flags &= ~FB_OPEN;
541 	splx(s);
542 	return 0;
543 }
544 
545 int genfbread(genfb_softc_t *sc, video_adapter_t *adp, struct uio *uio,
546 	      int flag)
547 {
548 	int size;
549 	int offset;
550 	int error;
551 	int len;
552 
553 	error = 0;
554 	size = adp->va_buffer_size/adp->va_info.vi_planes;
555 	while (uio->uio_resid > 0) {
556 		if (uio->uio_offset >= size)
557 			break;
558 		offset = uio->uio_offset%adp->va_window_size;
559 		len = imin(uio->uio_resid, size - uio->uio_offset);
560 		len = imin(len, adp->va_window_size - offset);
561 		if (len <= 0)
562 			break;
563 		(*vidsw[adp->va_index]->set_win_org)(adp, uio->uio_offset);
564 		error = uiomove((caddr_t)(adp->va_window + offset), len, uio);
565 		if (error)
566 			break;
567 	}
568 	return error;
569 }
570 
571 int genfbwrite(genfb_softc_t *sc, video_adapter_t *adp, struct uio *uio,
572 	       int flag)
573 {
574 	return ENODEV;
575 }
576 
577 int genfbioctl(genfb_softc_t *sc, video_adapter_t *adp, u_long cmd,
578 	       caddr_t arg, int flag, struct thread *td)
579 {
580 	int error;
581 
582 	if (adp == NULL)	/* XXX */
583 		return ENXIO;
584 	error = (*vidsw[adp->va_index]->ioctl)(adp, cmd, arg);
585 	if (error == ENOIOCTL)
586 		error = ENODEV;
587 	return error;
588 }
589 
590 int genfbmmap(genfb_softc_t *sc, video_adapter_t *adp, vm_offset_t offset,
591 	      vm_offset_t *paddr, int prot)
592 {
593 	return (*vidsw[adp->va_index]->mmap)(adp, offset, paddr, prot);
594 }
595 
596 #endif /* FB_INSTALL_CDEV */
597 
598 static char
599 *adapter_name(int type)
600 {
601     static struct {
602 	int type;
603 	char *name;
604     } names[] = {
605 	{ KD_MONO,	"MDA" },
606 	{ KD_HERCULES,	"Hercules" },
607 	{ KD_CGA,	"CGA" },
608 	{ KD_EGA,	"EGA" },
609 	{ KD_VGA,	"VGA" },
610 	{ KD_PC98,	"PC-98x1" },
611 	{ KD_TGA,	"TGA" },
612 	{ -1,		"Unknown" },
613     };
614     int i;
615 
616     for (i = 0; names[i].type != -1; ++i)
617 	if (names[i].type == type)
618 	    break;
619     return names[i].name;
620 }
621 
622 /*
623  * Generic low-level frame buffer functions
624  * The low-level functions in the frame buffer subdriver may use these
625  * functions.
626  */
627 
628 void
629 fb_dump_adp_info(char *driver, video_adapter_t *adp, int level)
630 {
631     if (level <= 0)
632 	return;
633 
634     printf("%s%d: %s%d, %s, type:%s (%d), flags:0x%x\n",
635 	   FB_DRIVER_NAME, adp->va_index, driver, adp->va_unit, adp->va_name,
636 	   adapter_name(adp->va_type), adp->va_type, adp->va_flags);
637     printf("%s%d: port:0x%lx-0x%lx, crtc:0x%lx, mem:0x%lx 0x%x\n",
638 	   FB_DRIVER_NAME, adp->va_index, (u_long)adp->va_io_base,
639 	   (u_long)adp->va_io_base + adp->va_io_size - 1,
640 	   (u_long)adp->va_crtc_addr, (u_long)adp->va_mem_base,
641 	   adp->va_mem_size);
642     printf("%s%d: init mode:%d, bios mode:%d, current mode:%d\n",
643 	   FB_DRIVER_NAME, adp->va_index,
644 	   adp->va_initial_mode, adp->va_initial_bios_mode, adp->va_mode);
645     printf("%s%d: window:%p size:%dk gran:%dk, buf:%p size:%dk\n",
646 	   FB_DRIVER_NAME, adp->va_index,
647 	   (void *)adp->va_window, (int)adp->va_window_size/1024,
648 	   (int)adp->va_window_gran/1024, (void *)adp->va_buffer,
649 	   (int)adp->va_buffer_size/1024);
650 }
651 
652 void
653 fb_dump_mode_info(char *driver, video_adapter_t *adp, video_info_t *info,
654 		  int level)
655 {
656     if (level <= 0)
657 	return;
658 
659     printf("%s%d: %s, mode:%d, flags:0x%x ",
660 	   driver, adp->va_unit, adp->va_name, info->vi_mode, info->vi_flags);
661     if (info->vi_flags & V_INFO_GRAPHICS)
662 	printf("G %dx%dx%d, %d plane(s), font:%dx%d, ",
663 	       info->vi_width, info->vi_height,
664 	       info->vi_depth, info->vi_planes,
665 	       info->vi_cwidth, info->vi_cheight);
666     else
667 	printf("T %dx%d, font:%dx%d, ",
668 	       info->vi_width, info->vi_height,
669 	       info->vi_cwidth, info->vi_cheight);
670     printf("win:0x%lx\n", (u_long)info->vi_window);
671 }
672 
673 int
674 fb_type(int adp_type)
675 {
676 	static struct {
677 		int	fb_type;
678 		int	va_type;
679 	} types[] = {
680 		{ FBTYPE_MDA,		KD_MONO },
681 		{ FBTYPE_HERCULES,	KD_HERCULES },
682 		{ FBTYPE_CGA,		KD_CGA },
683 		{ FBTYPE_EGA,		KD_EGA },
684 		{ FBTYPE_VGA,		KD_VGA },
685 		{ FBTYPE_PC98,		KD_PC98 },
686 		{ FBTYPE_TGA,		KD_TGA },
687 	};
688 	int i;
689 
690 	for (i = 0; i < sizeof(types)/sizeof(types[0]); ++i) {
691 		if (types[i].va_type == adp_type)
692 			return types[i].fb_type;
693 	}
694 	return -1;
695 }
696 
697 int
698 fb_commonioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
699 {
700 	int error;
701 	int s;
702 
703 	/* assert(adp != NULL) */
704 
705 	error = 0;
706 	s = spltty();
707 
708 	switch (cmd) {
709 
710 	case FBIO_ADAPTER:	/* get video adapter index */
711 		*(int *)arg = adp->va_index;
712 		break;
713 
714 	case FBIO_ADPTYPE:	/* get video adapter type */
715 		*(int *)arg = adp->va_type;
716 		break;
717 
718 	case FBIO_ADPINFO:	/* get video adapter info */
719 	        ((video_adapter_info_t *)arg)->va_index = adp->va_index;
720 		((video_adapter_info_t *)arg)->va_type = adp->va_type;
721 		bcopy(adp->va_name, ((video_adapter_info_t *)arg)->va_name,
722 		      imin(strlen(adp->va_name) + 1,
723 			   sizeof(((video_adapter_info_t *)arg)->va_name)));
724 		((video_adapter_info_t *)arg)->va_unit = adp->va_unit;
725 		((video_adapter_info_t *)arg)->va_flags = adp->va_flags;
726 		((video_adapter_info_t *)arg)->va_io_base = adp->va_io_base;
727 		((video_adapter_info_t *)arg)->va_io_size = adp->va_io_size;
728 		((video_adapter_info_t *)arg)->va_crtc_addr = adp->va_crtc_addr;
729 		((video_adapter_info_t *)arg)->va_mem_base = adp->va_mem_base;
730 		((video_adapter_info_t *)arg)->va_mem_size = adp->va_mem_size;
731 		((video_adapter_info_t *)arg)->va_window
732 #ifdef __i386__
733 			= vtophys(adp->va_window);
734 #else
735 			= adp->va_window;
736 #endif
737 		((video_adapter_info_t *)arg)->va_window_size
738 			= adp->va_window_size;
739 		((video_adapter_info_t *)arg)->va_window_gran
740 			= adp->va_window_gran;
741 		((video_adapter_info_t *)arg)->va_window_orig
742 			= adp->va_window_orig;
743 		((video_adapter_info_t *)arg)->va_unused0
744 #ifdef __i386__
745 			= (adp->va_buffer) ? vtophys(adp->va_buffer) : 0;
746 #else
747 			= adp->va_buffer;
748 #endif
749 		((video_adapter_info_t *)arg)->va_buffer_size
750 			= adp->va_buffer_size;
751 		((video_adapter_info_t *)arg)->va_mode = adp->va_mode;
752 		((video_adapter_info_t *)arg)->va_initial_mode
753 			= adp->va_initial_mode;
754 		((video_adapter_info_t *)arg)->va_initial_bios_mode
755 			= adp->va_initial_bios_mode;
756 		((video_adapter_info_t *)arg)->va_line_width
757 			= adp->va_line_width;
758 		((video_adapter_info_t *)arg)->va_disp_start.x
759 			= adp->va_disp_start.x;
760 		((video_adapter_info_t *)arg)->va_disp_start.y
761 			= adp->va_disp_start.y;
762 		break;
763 
764 	case FBIO_MODEINFO:	/* get mode information */
765 		error = (*vidsw[adp->va_index]->get_info)(adp,
766 				((video_info_t *)arg)->vi_mode,
767 				(video_info_t *)arg);
768 		if (error)
769 			error = ENODEV;
770 		break;
771 
772 	case FBIO_FINDMODE:	/* find a matching video mode */
773 		error = (*vidsw[adp->va_index]->query_mode)(adp,
774 				(video_info_t *)arg);
775 		break;
776 
777 	case FBIO_GETMODE:	/* get video mode */
778 		*(int *)arg = adp->va_mode;
779 		break;
780 
781 	case FBIO_SETMODE:	/* set video mode */
782 		error = (*vidsw[adp->va_index]->set_mode)(adp, *(int *)arg);
783 		if (error)
784 			error = ENODEV;	/* EINVAL? */
785 		break;
786 
787 	case FBIO_GETWINORG:	/* get frame buffer window origin */
788 		*(u_int *)arg = adp->va_window_orig;
789 		break;
790 
791 	case FBIO_GETDISPSTART:	/* get display start address */
792 		((video_display_start_t *)arg)->x = adp->va_disp_start.x;
793 		((video_display_start_t *)arg)->y = adp->va_disp_start.y;
794 		break;
795 
796 	case FBIO_GETLINEWIDTH:	/* get scan line width in bytes */
797 		*(u_int *)arg = adp->va_line_width;
798 		break;
799 
800 	case FBIO_BLANK:	/* blank display */
801 		error = (*vidsw[adp->va_index]->blank_display)(adp, *(int *)arg);
802 		break;
803 
804 	case FBIO_GETPALETTE:	/* get color palette */
805 	case FBIO_SETPALETTE:	/* set color palette */
806 		/* XXX */
807 
808 	case FBIOPUTCMAP:
809 	case FBIOGETCMAP:
810 	case FBIOPUTCMAPI:
811 	case FBIOGETCMAPI:
812 		/* XXX */
813 
814 	case FBIO_SETWINORG:	/* set frame buffer window origin */
815 	case FBIO_SETDISPSTART:	/* set display start address */
816 	case FBIO_SETLINEWIDTH:	/* set scan line width in pixel */
817 
818 	case FBIOGTYPE:
819 	case FBIOGATTR:
820 	case FBIOSVIDEO:
821 	case FBIOGVIDEO:
822 	case FBIOVERTICAL:
823 	case FBIOSCURSOR:
824 	case FBIOGCURSOR:
825 	case FBIOSCURPOS:
826 	case FBIOGCURPOS:
827 	case FBIOGCURMAX:
828 	case FBIOMONINFO:
829 	case FBIOGXINFO:
830 
831 	default:
832 		error = ENODEV;
833 		break;
834 	}
835 
836 	splx(s);
837 	return error;
838 }
839