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