AMD64 - Refactor uio_resid and size_t assumptions.
[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 $
4e193d20 29 * $DragonFly: src/sys/dev/video/fb/fb.c,v 1.19 2008/01/09 21:29:11 swildner 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>
dc62b251 42#include <sys/linker_set.h>
335dda38 43#include <sys/device.h>
052b6ffa 44#include <sys/thread2.h>
984263bc
MD
45
46#include <vm/vm.h>
47#include <vm/pmap.h>
48
1f2de5d4 49#include "fbreg.h"
984263bc 50
dc62b251
MD
51SET_DECLARE(videodriver_set, const video_driver_t);
52
984263bc
MD
53/* local arrays */
54
55/*
56 * We need at least one entry each in order to initialize a video card
57 * for the kernel console. The arrays will be increased dynamically
58 * when necessary.
59 */
60
61static int vid_malloc;
62static int adapters = 1;
63static video_adapter_t *adp_ini;
64static video_adapter_t **adapter = &adp_ini;
65static video_switch_t *vidsw_ini;
66 video_switch_t **vidsw = &vidsw_ini;
67
68#ifdef FB_INSTALL_CDEV
b13267a5
MD
69static cdev_t vidcdevsw_ini;
70static cdev_t *vidcdevsw = &vidcdevsw_ini;
984263bc
MD
71#endif
72
73#define ARRAY_DELTA 4
74
75static int
76vid_realloc_array(void)
77{
78 video_adapter_t **new_adp;
79 video_switch_t **new_vidsw;
80#ifdef FB_INSTALL_CDEV
b13267a5 81 cdev_t *new_cdevsw;
984263bc
MD
82#endif
83 int newsize;
984263bc
MD
84
85 if (!vid_malloc)
86 return ENOMEM;
87
052b6ffa 88 crit_enter();
984263bc 89 newsize = ((adapters + ARRAY_DELTA)/ARRAY_DELTA)*ARRAY_DELTA;
efda3bd0
MD
90 new_adp = kmalloc(sizeof(*new_adp)*newsize, M_DEVBUF, M_WAITOK | M_ZERO);
91 new_vidsw = kmalloc(sizeof(*new_vidsw)*newsize, M_DEVBUF,
0dcfa558 92 M_WAITOK | M_ZERO);
984263bc 93#ifdef FB_INSTALL_CDEV
efda3bd0 94 new_cdevsw = kmalloc(sizeof(*new_cdevsw)*newsize, M_DEVBUF,
0dcfa558 95 M_WAITOK | M_ZERO);
984263bc 96#endif
984263bc
MD
97 bcopy(adapter, new_adp, sizeof(*adapter)*adapters);
98 bcopy(vidsw, new_vidsw, sizeof(*vidsw)*adapters);
99#ifdef FB_INSTALL_CDEV
984263bc
MD
100 bcopy(vidcdevsw, new_cdevsw, sizeof(*vidcdevsw)*adapters);
101#endif
102 if (adapters > 1) {
efda3bd0
MD
103 kfree(adapter, M_DEVBUF);
104 kfree(vidsw, M_DEVBUF);
984263bc 105#ifdef FB_INSTALL_CDEV
efda3bd0 106 kfree(vidcdevsw, M_DEVBUF);
984263bc
MD
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;
052b6ffa 115 crit_exit();
984263bc
MD
116
117 if (bootverbose)
e3869ec7 118 kprintf("fb: new array size %d\n", adapters);
984263bc
MD
119
120 return 0;
121}
122
123static void
124vid_malloc_init(void *arg)
125{
126 vid_malloc = TRUE;
127}
128
ba39e2e0 129SYSINIT(vid_mem, SI_BOOT1_POST, SI_ORDER_ANY, vid_malloc_init, NULL);
984263bc
MD
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 */
139void
140vid_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 */
149int
150vid_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;
dc62b251
MD
167 SET_FOREACH(list, videodriver_set) {
168 p = *list;
984263bc
MD
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
179int
180vid_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 */
3d8ba483
SW
193video_switch_t *
194vid_get_switch(char *name)
984263bc
MD
195{
196 const video_driver_t **list;
197 const video_driver_t *p;
198
dc62b251
MD
199 SET_FOREACH(list, videodriver_set) {
200 p = *list;
984263bc
MD
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 */
216int
217vid_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 */
234int
235vid_allocate(char *driver, int unit, void *id)
236{
237 int index;
984263bc 238
052b6ffa 239 crit_enter();
984263bc
MD
240 index = vid_find_adapter(driver, unit);
241 if (index >= 0) {
242 if (adapter[index]->va_token) {
052b6ffa 243 crit_exit();
984263bc
MD
244 return -1;
245 }
246 adapter[index]->va_token = id;
247 }
052b6ffa 248 crit_exit();
984263bc
MD
249 return index;
250}
251
252int
253vid_release(video_adapter_t *adp, void *id)
254{
255 int error;
984263bc 256
052b6ffa 257 crit_enter();
984263bc
MD
258 if (adp->va_token == NULL) {
259 error = EINVAL;
260 } else if (adp->va_token != id) {
261 error = EPERM;
262 } else {
263 adp->va_token = NULL;
264 error = 0;
265 }
052b6ffa 266 crit_exit();
984263bc
MD
267 return error;
268}
269
270/* Get a video adapter structure */
3d8ba483
SW
271video_adapter_t *
272vid_get_adapter(int index)
984263bc
MD
273{
274 if ((index < 0) || (index >= adapters))
275 return NULL;
276 return adapter[index];
277}
278
279/* Configure drivers: this is a backdoor for the console driver XXX */
280int
281vid_configure(int flags)
282{
283 const video_driver_t **list;
284 const video_driver_t *p;
285
dc62b251
MD
286 SET_FOREACH(list, videodriver_set) {
287 p = *list;
984263bc
MD
288 if (p->configure != NULL)
289 (*p->configure)(flags);
290 }
291
292 return 0;
293}
294
295/*
296 * Virtual frame buffer cdev driver functions
297 * The virtual frame buffer driver dispatches driver functions to
298 * appropriate subdrivers.
299 */
300
301#define FB_DRIVER_NAME "fb"
302
303#ifdef FB_INSTALL_CDEV
304
305#if experimental
306
307static devclass_t fb_devclass;
308
309static int fbprobe(device_t dev);
310static int fbattach(device_t dev);
311
312static device_method_t fb_methods[] = {
313 DEVMETHOD(device_probe, fbprobe),
314 DEVMETHOD(device_attach, fbattach),
315
316 DEVMETHOD(bus_print_child, bus_generic_print_child),
317 { 0, 0 }
318};
319
320static driver_t fb_driver = {
321 FB_DRIVER_NAME,
322 fb_methods,
323 0,
324};
325
326static int
327fbprobe(device_t dev)
328{
329 int unit;
330
331 unit = device_get_unit(dev);
332 if (unit >= adapters)
333 return ENXIO;
334 if (adapter[unit] == NULL)
335 return ENXIO;
336
337 device_set_desc(dev, "generic frame buffer");
338 return 0;
339}
340
341static int
342fbattach(device_t dev)
343{
e3869ec7 344 kprintf("fbattach: about to attach children\n");
984263bc
MD
345 bus_generic_attach(dev);
346 return 0;
347}
348
349#endif /* experimental */
350
351#define FB_UNIT(dev) minor(dev)
352#define FB_MKMINOR(unit) (u)
353
fef8985e 354static d_default_t fboperate;
984263bc 355static d_open_t fbopen;
984263bc
MD
356
357#define CDEV_MAJOR 123 /* XXX */
358
fef8985e
MD
359static struct dev_ops fb_ops = {
360 { FB_DRIVER_NAME, CDEV_MAJOR, 0 },
361 .d_default = fboperate,
362 .d_open = fbopen
984263bc
MD
363};
364
365static void
366vfbattach(void *arg)
367{
368 static int fb_devsw_installed = FALSE;
369
370 if (!fb_devsw_installed) {
7e0245d8 371#if 0
fef8985e 372 dev_ops_add(&fb_ops, 0, 0);
7e0245d8 373#endif
984263bc
MD
374 fb_devsw_installed = TRUE;
375 }
376}
377
378PSEUDO_SET(vfbattach, fb);
379
335dda38
MD
380/*
381 * Note: dev represents the actual video device, not the frame buffer
382 */
984263bc 383int
b13267a5 384fb_attach(cdev_t dev, video_adapter_t *adp)
984263bc 385{
984263bc
MD
386 if (adp->va_index >= adapters)
387 return EINVAL;
388 if (adapter[adp->va_index] != adp)
389 return EINVAL;
390
052b6ffa 391 crit_enter();
e4c9c0c8 392 reference_dev(dev);
984263bc 393 adp->va_minor = minor(dev);
e4c9c0c8 394 vidcdevsw[adp->va_index] = dev;
052b6ffa 395 crit_exit();
984263bc 396
e3869ec7 397 kprintf("fb%d at %s%d\n", adp->va_index, adp->va_name, adp->va_unit);
984263bc
MD
398 return 0;
399}
400
335dda38
MD
401/*
402 * Note: dev represents the actual video device, not the frame buffer
403 */
984263bc 404int
b13267a5 405fb_detach(cdev_t dev, video_adapter_t *adp)
984263bc 406{
984263bc
MD
407 if (adp->va_index >= adapters)
408 return EINVAL;
409 if (adapter[adp->va_index] != adp)
410 return EINVAL;
e4c9c0c8 411 if (vidcdevsw[adp->va_index] != dev)
984263bc
MD
412 return EINVAL;
413
052b6ffa 414 crit_enter();
984263bc 415 vidcdevsw[adp->va_index] = NULL;
052b6ffa 416 crit_exit();
e4c9c0c8 417 release_dev(dev);
984263bc
MD
418 return 0;
419}
420
421static int
fef8985e 422fbopen(struct dev_open_args *ap)
984263bc 423{
b13267a5 424 cdev_t dev = ap->a_head.a_dev;
984263bc 425 int unit;
b13267a5 426 cdev_t fdev;
984263bc
MD
427
428 unit = FB_UNIT(dev);
fef8985e 429 if (unit < 0 || unit >= adapters)
984263bc 430 return ENXIO;
e4c9c0c8 431 if ((fdev = vidcdevsw[unit]) == NULL)
984263bc 432 return ENXIO;
fef8985e 433 return dev_dopen(fdev, ap->a_oflags, ap->a_devtype, ap->a_cred);
984263bc
MD
434}
435
436static int
fef8985e 437fboperate(struct dev_generic_args *ap)
984263bc 438{
b13267a5 439 cdev_t dev = ap->a_dev;
984263bc 440 int unit;
b13267a5 441 cdev_t fdev;
984263bc
MD
442
443 unit = FB_UNIT(dev);
e4c9c0c8 444 if ((fdev = vidcdevsw[unit]) == NULL)
984263bc 445 return ENXIO;
fef8985e
MD
446 ap->a_dev = fdev;
447 return dev_doperate(ap);
984263bc
MD
448}
449
984263bc
MD
450/*
451 * Generic frame buffer cdev driver functions
452 * Frame buffer subdrivers may call these functions to implement common
453 * driver functions.
454 */
455
456int genfbopen(genfb_softc_t *sc, video_adapter_t *adp, int flag, int mode,
fef8985e 457 struct ucred *cred)
984263bc 458{
052b6ffa 459 crit_enter();
984263bc
MD
460 if (!(sc->gfb_flags & FB_OPEN))
461 sc->gfb_flags |= FB_OPEN;
052b6ffa 462 crit_exit();
984263bc
MD
463 return 0;
464}
465
fef8985e 466int genfbclose(genfb_softc_t *sc, video_adapter_t *adp, int flag, int mode)
984263bc 467{
052b6ffa 468 crit_enter();
984263bc 469 sc->gfb_flags &= ~FB_OPEN;
052b6ffa 470 crit_exit();
984263bc
MD
471 return 0;
472}
473
474int genfbread(genfb_softc_t *sc, video_adapter_t *adp, struct uio *uio,
475 int flag)
476{
477 int size;
478 int offset;
479 int error;
480 int len;
481
482 error = 0;
483 size = adp->va_buffer_size/adp->va_info.vi_planes;
484 while (uio->uio_resid > 0) {
485 if (uio->uio_offset >= size)
486 break;
487 offset = uio->uio_offset%adp->va_window_size;
e54488bb 488 len = (int)szmin(uio->uio_resid, size - uio->uio_offset);
984263bc
MD
489 len = imin(len, adp->va_window_size - offset);
490 if (len <= 0)
491 break;
492 (*vidsw[adp->va_index]->set_win_org)(adp, uio->uio_offset);
e54488bb
MD
493 error = uiomove((caddr_t)(adp->va_window + offset),
494 (size_t)len, uio);
984263bc
MD
495 if (error)
496 break;
497 }
498 return error;
499}
500
501int genfbwrite(genfb_softc_t *sc, video_adapter_t *adp, struct uio *uio,
502 int flag)
503{
504 return ENODEV;
505}
506
507int genfbioctl(genfb_softc_t *sc, video_adapter_t *adp, u_long cmd,
fef8985e 508 caddr_t arg, int flag, struct ucred *cred)
984263bc
MD
509{
510 int error;
511
512 if (adp == NULL) /* XXX */
513 return ENXIO;
514 error = (*vidsw[adp->va_index]->ioctl)(adp, cmd, arg);
515 if (error == ENOIOCTL)
516 error = ENODEV;
517 return error;
518}
519
520int genfbmmap(genfb_softc_t *sc, video_adapter_t *adp, vm_offset_t offset,
521 int prot)
522{
523 return (*vidsw[adp->va_index]->mmap)(adp, offset, prot);
524}
525
526#endif /* FB_INSTALL_CDEV */
527
3d8ba483
SW
528static char *
529adapter_name(int type)
984263bc
MD
530{
531 static struct {
532 int type;
533 char *name;
534 } names[] = {
535 { KD_MONO, "MDA" },
536 { KD_HERCULES, "Hercules" },
537 { KD_CGA, "CGA" },
538 { KD_EGA, "EGA" },
539 { KD_VGA, "VGA" },
984263bc
MD
540 { KD_TGA, "TGA" },
541 { -1, "Unknown" },
542 };
543 int i;
544
545 for (i = 0; names[i].type != -1; ++i)
546 if (names[i].type == type)
547 break;
548 return names[i].name;
549}
550
551/*
552 * Generic low-level frame buffer functions
553 * The low-level functions in the frame buffer subdriver may use these
554 * functions.
555 */
556
557void
558fb_dump_adp_info(char *driver, video_adapter_t *adp, int level)
559{
560 if (level <= 0)
561 return;
562
e3869ec7 563 kprintf("%s%d: %s%d, %s, type:%s (%d), flags:0x%x\n",
984263bc
MD
564 FB_DRIVER_NAME, adp->va_index, driver, adp->va_unit, adp->va_name,
565 adapter_name(adp->va_type), adp->va_type, adp->va_flags);
4e193d20 566 kprintf("%s%d: port:0x%x-0x%x, mem:0x%x 0x%x\n",
984263bc
MD
567 FB_DRIVER_NAME, adp->va_index,
568 adp->va_io_base, adp->va_io_base + adp->va_io_size - 1,
4e193d20 569 adp->va_mem_base, adp->va_mem_size);
e3869ec7 570 kprintf("%s%d: init mode:%d, bios mode:%d, current mode:%d\n",
984263bc
MD
571 FB_DRIVER_NAME, adp->va_index,
572 adp->va_initial_mode, adp->va_initial_bios_mode, adp->va_mode);
e3869ec7 573 kprintf("%s%d: window:%p size:%dk gran:%dk, buf:%p size:%dk\n",
984263bc
MD
574 FB_DRIVER_NAME, adp->va_index,
575 (void *)adp->va_window, (int)adp->va_window_size/1024,
576 (int)adp->va_window_gran/1024, (void *)adp->va_buffer,
577 (int)adp->va_buffer_size/1024);
578}
579
580void
581fb_dump_mode_info(char *driver, video_adapter_t *adp, video_info_t *info,
582 int level)
583{
584 if (level <= 0)
585 return;
586
e3869ec7 587 kprintf("%s%d: %s, mode:%d, flags:0x%x ",
984263bc
MD
588 driver, adp->va_unit, adp->va_name, info->vi_mode, info->vi_flags);
589 if (info->vi_flags & V_INFO_GRAPHICS)
e3869ec7 590 kprintf("G %dx%dx%d, %d plane(s), font:%dx%d, ",
984263bc
MD
591 info->vi_width, info->vi_height,
592 info->vi_depth, info->vi_planes,
593 info->vi_cwidth, info->vi_cheight);
594 else
e3869ec7 595 kprintf("T %dx%d, font:%dx%d, ",
984263bc
MD
596 info->vi_width, info->vi_height,
597 info->vi_cwidth, info->vi_cheight);
e3869ec7 598 kprintf("win:0x%x\n", info->vi_window);
984263bc
MD
599}
600
601int
602fb_type(int adp_type)
603{
604 static struct {
605 int fb_type;
606 int va_type;
607 } types[] = {
608 { FBTYPE_MDA, KD_MONO },
609 { FBTYPE_HERCULES, KD_HERCULES },
610 { FBTYPE_CGA, KD_CGA },
611 { FBTYPE_EGA, KD_EGA },
612 { FBTYPE_VGA, KD_VGA },
984263bc
MD
613 { FBTYPE_TGA, KD_TGA },
614 };
615 int i;
616
617 for (i = 0; i < sizeof(types)/sizeof(types[0]); ++i) {
618 if (types[i].va_type == adp_type)
619 return types[i].fb_type;
620 }
621 return -1;
622}
623
624int
625fb_commonioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
626{
627 int error;
984263bc
MD
628
629 /* assert(adp != NULL) */
630
631 error = 0;
052b6ffa 632 crit_enter();
984263bc
MD
633
634 switch (cmd) {
635
636 case FBIO_ADAPTER: /* get video adapter index */
637 *(int *)arg = adp->va_index;
638 break;
639
640 case FBIO_ADPTYPE: /* get video adapter type */
641 *(int *)arg = adp->va_type;
642 break;
643
644 case FBIO_ADPINFO: /* get video adapter info */
645 ((video_adapter_info_t *)arg)->va_index = adp->va_index;
646 ((video_adapter_info_t *)arg)->va_type = adp->va_type;
647 bcopy(adp->va_name, ((video_adapter_info_t *)arg)->va_name,
648 imin(strlen(adp->va_name) + 1,
649 sizeof(((video_adapter_info_t *)arg)->va_name)));
650 ((video_adapter_info_t *)arg)->va_unit = adp->va_unit;
651 ((video_adapter_info_t *)arg)->va_flags = adp->va_flags;
652 ((video_adapter_info_t *)arg)->va_io_base = adp->va_io_base;
653 ((video_adapter_info_t *)arg)->va_io_size = adp->va_io_size;
984263bc
MD
654 ((video_adapter_info_t *)arg)->va_mem_base = adp->va_mem_base;
655 ((video_adapter_info_t *)arg)->va_mem_size = adp->va_mem_size;
656 ((video_adapter_info_t *)arg)->va_window
657#ifdef __i386__
658 = vtophys(adp->va_window);
659#else
660 = adp->va_window;
661#endif
662 ((video_adapter_info_t *)arg)->va_window_size
663 = adp->va_window_size;
664 ((video_adapter_info_t *)arg)->va_window_gran
665 = adp->va_window_gran;
666 ((video_adapter_info_t *)arg)->va_window_orig
667 = adp->va_window_orig;
668 ((video_adapter_info_t *)arg)->va_unused0
669#ifdef __i386__
670 = (adp->va_buffer) ? vtophys(adp->va_buffer) : 0;
671#else
672 = adp->va_buffer;
673#endif
674 ((video_adapter_info_t *)arg)->va_buffer_size
675 = adp->va_buffer_size;
676 ((video_adapter_info_t *)arg)->va_mode = adp->va_mode;
677 ((video_adapter_info_t *)arg)->va_initial_mode
678 = adp->va_initial_mode;
679 ((video_adapter_info_t *)arg)->va_initial_bios_mode
680 = adp->va_initial_bios_mode;
681 ((video_adapter_info_t *)arg)->va_line_width
682 = adp->va_line_width;
683 ((video_adapter_info_t *)arg)->va_disp_start.x
684 = adp->va_disp_start.x;
685 ((video_adapter_info_t *)arg)->va_disp_start.y
686 = adp->va_disp_start.y;
687 break;
688
689 case FBIO_MODEINFO: /* get mode information */
690 error = (*vidsw[adp->va_index]->get_info)(adp,
691 ((video_info_t *)arg)->vi_mode,
692 (video_info_t *)arg);
693 if (error)
694 error = ENODEV;
695 break;
696
697 case FBIO_FINDMODE: /* find a matching video mode */
698 error = (*vidsw[adp->va_index]->query_mode)(adp,
699 (video_info_t *)arg);
700 break;
701
702 case FBIO_GETMODE: /* get video mode */
703 *(int *)arg = adp->va_mode;
704 break;
705
706 case FBIO_SETMODE: /* set video mode */
707 error = (*vidsw[adp->va_index]->set_mode)(adp, *(int *)arg);
708 if (error)
709 error = ENODEV; /* EINVAL? */
710 break;
711
712 case FBIO_GETWINORG: /* get frame buffer window origin */
713 *(u_int *)arg = adp->va_window_orig;
714 break;
715
716 case FBIO_GETDISPSTART: /* get display start address */
717 ((video_display_start_t *)arg)->x = adp->va_disp_start.x;
718 ((video_display_start_t *)arg)->y = adp->va_disp_start.y;
719 break;
720
721 case FBIO_GETLINEWIDTH: /* get scan line width in bytes */
722 *(u_int *)arg = adp->va_line_width;
723 break;
724
725 case FBIO_GETPALETTE: /* get color palette */
726 case FBIO_SETPALETTE: /* set color palette */
727 /* XXX */
728
729 case FBIOPUTCMAP:
730 case FBIOGETCMAP:
731 /* XXX */
732
733 case FBIO_SETWINORG: /* set frame buffer window origin */
734 case FBIO_SETDISPSTART: /* set display start address */
735 case FBIO_SETLINEWIDTH: /* set scan line width in pixel */
736
737 case FBIOGTYPE:
738 case FBIOGATTR:
739 case FBIOSVIDEO:
740 case FBIOGVIDEO:
741 case FBIOSCURSOR:
742 case FBIOGCURSOR:
743 case FBIOSCURPOS:
744 case FBIOGCURPOS:
745 case FBIOGCURMAX:
746
747 default:
748 error = ENODEV;
749 break;
750 }
751
052b6ffa 752 crit_exit();
984263bc
MD
753 return error;
754}