Deleted Added
full compact
vesa.c (197496) vesa.c (198251)
1/*-
2 * Copyright (c) 1998 Kazutaka YOKOTA and Michael Smith
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

--- 11 unchanged lines hidden (view full) ---

20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1998 Kazutaka YOKOTA and Michael Smith
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

--- 11 unchanged lines hidden (view full) ---

20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/dev/fb/vesa.c 197496 2009-09-25 18:08:38Z jkim $");
28__FBSDID("$FreeBSD: head/sys/dev/fb/vesa.c 198251 2009-10-19 20:58:10Z jkim $");
29
30#include "opt_vga.h"
31#include "opt_vesa.h"
32
33#ifndef VGA_NO_MODE_CHANGE
34
35#include <sys/param.h>
29
30#include "opt_vga.h"
31#include "opt_vesa.h"
32
33#ifndef VGA_NO_MODE_CHANGE
34
35#include <sys/param.h>
36#include <sys/bus.h>
36#include <sys/systm.h>
37#include <sys/kernel.h>
38#include <sys/module.h>
39#include <sys/malloc.h>
40#include <sys/fbio.h>
41
42#include <vm/vm.h>
43#include <vm/vm_extern.h>
44#include <vm/vm_kern.h>
45#include <vm/vm_param.h>
46#include <vm/pmap.h>
47
48#include <machine/pc/bios.h>
49#include <dev/fb/vesa.h>
50
51#include <dev/fb/fbreg.h>
52#include <dev/fb/vgareg.h>
53
37#include <sys/systm.h>
38#include <sys/kernel.h>
39#include <sys/module.h>
40#include <sys/malloc.h>
41#include <sys/fbio.h>
42
43#include <vm/vm.h>
44#include <vm/vm_extern.h>
45#include <vm/vm_kern.h>
46#include <vm/vm_param.h>
47#include <vm/pmap.h>
48
49#include <machine/pc/bios.h>
50#include <dev/fb/vesa.h>
51
52#include <dev/fb/fbreg.h>
53#include <dev/fb/vgareg.h>
54
55#include <dev/pci/pcivar.h>
56
54#include <isa/isareg.h>
55
56#include <compat/x86bios/x86bios.h>
57
58#define VESA_VIA_CLE266 "VIA CLE266\r\n"
59
60#ifndef VESA_DEBUG
61#define VESA_DEBUG 0

--- 93 unchanged lines hidden (view full) ---

155static char *vesa_venderstr = NULL;
156static char *vesa_prodstr = NULL;
157static char *vesa_revstr = NULL;
158
159/* local macros and functions */
160#define BIOS_SADDRTOLADDR(p) ((((p) & 0xffff0000) >> 12) + ((p) & 0x0000ffff))
161
162static int int10_set_mode(int mode);
57#include <isa/isareg.h>
58
59#include <compat/x86bios/x86bios.h>
60
61#define VESA_VIA_CLE266 "VIA CLE266\r\n"
62
63#ifndef VESA_DEBUG
64#define VESA_DEBUG 0

--- 93 unchanged lines hidden (view full) ---

158static char *vesa_venderstr = NULL;
159static char *vesa_prodstr = NULL;
160static char *vesa_revstr = NULL;
161
162/* local macros and functions */
163#define BIOS_SADDRTOLADDR(p) ((((p) & 0xffff0000) >> 12) + ((p) & 0x0000ffff))
164
165static int int10_set_mode(int mode);
166static int vesa_bios_post(void);
163static int vesa_bios_get_mode(int mode, struct vesa_mode *vmode);
167static int vesa_bios_get_mode(int mode, struct vesa_mode *vmode);
168static int vesa_bios_get_current_mode(void);
164static int vesa_bios_set_mode(int mode);
165static int vesa_bios_get_dac(void);
166static int vesa_bios_set_dac(int bits);
167static int vesa_bios_save_palette(int start, int colors, u_char *palette,
168 int bits);
169static int vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g,
170 u_char *b, int bits);
171static int vesa_bios_load_palette(int start, int colors, u_char *palette,

--- 45 unchanged lines hidden (view full) ---

217}
218
219/* INT 10 BIOS calls */
220static int
221int10_set_mode(int mode)
222{
223 x86regs_t regs;
224
169static int vesa_bios_set_mode(int mode);
170static int vesa_bios_get_dac(void);
171static int vesa_bios_set_dac(int bits);
172static int vesa_bios_save_palette(int start, int colors, u_char *palette,
173 int bits);
174static int vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g,
175 u_char *b, int bits);
176static int vesa_bios_load_palette(int start, int colors, u_char *palette,

--- 45 unchanged lines hidden (view full) ---

222}
223
224/* INT 10 BIOS calls */
225static int
226int10_set_mode(int mode)
227{
228 x86regs_t regs;
229
225 bzero(&regs, sizeof(regs));
226 regs.R_EAX = 0x0000 | mode;
230 x86bios_init_regs(&regs);
231 regs.R_AL = mode;
227
228 x86bios_intr(&regs, 0x10);
229
232
233 x86bios_intr(&regs, 0x10);
234
230 return 0;
235 return (0);
231}
232
236}
237
238static int
239vesa_bios_post(void)
240{
241 x86regs_t regs;
242 devclass_t dc;
243 device_t *devs;
244 device_t dev;
245 int count, i, is_pci;
246
247 if (x86bios_get_orm(0xc0000) == NULL)
248 return (1);
249
250 dev = NULL;
251 is_pci = 0;
252
253 /* Find the matching PCI video controller. */
254 dc = devclass_find("vgapci");
255 if (dc != NULL && devclass_get_devices(dc, &devs, &count) == 0) {
256 for (dev = NULL, i = 0; dev == NULL && i < count; devs++, i++)
257 if (x86bios_match_device(0xc0000, *devs) &&
258 device_get_flags(*devs) != 0) {
259 dev = *devs;
260 is_pci = 1;
261 break;
262 }
263 free(devs, M_TEMP);
264 }
265
266 /* Try VGA if a PCI device is not found. */
267 if (dev == NULL) {
268 dc = devclass_find(VGA_DRIVER_NAME);
269 if (dc != NULL)
270 dev = devclass_get_device(dc, 0);
271 }
272
273 if (bootverbose)
274 printf("%s: calling BIOS POST\n",
275 dev == NULL ? "VESA" : device_get_nameunit(dev));
276
277 x86bios_init_regs(&regs);
278 if (is_pci) {
279 regs.R_AH = pci_get_bus(dev);
280 regs.R_AL = (pci_get_slot(dev) << 3) |
281 (pci_get_function(dev) & 0x07);
282 }
283 regs.R_DL = 0x80;
284 x86bios_call(&regs, 0xc000, 0x0003);
285 return (0);
286}
287
233/* VESA BIOS calls */
234static int
235vesa_bios_get_mode(int mode, struct vesa_mode *vmode)
236{
237 x86regs_t regs;
288/* VESA BIOS calls */
289static int
290vesa_bios_get_mode(int mode, struct vesa_mode *vmode)
291{
292 x86regs_t regs;
238 int offs;
239 u_char *buf;
293 uint32_t offs;
294 void *buf;
240
295
241 bzero(&regs, sizeof(regs));
242 regs.R_EAX = 0x4f01;
243 regs.R_ECX = mode;
296 buf = x86bios_alloc(&offs, sizeof(*vmode));
297 if (buf == NULL)
298 return (1);
244
299
245 buf = (u_char *)x86bios_alloc(1, &offs);
300 x86bios_init_regs(&regs);
301 regs.R_AX = 0x4f01;
302 regs.R_CX = mode;
246
303
247 regs.R_ES = SEG_ADDR(offs);
248 regs.R_DI = SEG_OFF(offs);
304 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
305 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
249
250 x86bios_intr(&regs, 0x10);
251
306
307 x86bios_intr(&regs, 0x10);
308
252 if ((regs.R_AX & 0xff) != 0x4f)
253 {
254 x86bios_free(buf, 1);
255 return 1;
309 if (regs.R_AX != 0x004f) {
310 x86bios_free(buf, sizeof(*vmode));
311 return (1);
256 }
257
258 bcopy(buf, vmode, sizeof(*vmode));
312 }
313
314 bcopy(buf, vmode, sizeof(*vmode));
259 x86bios_free(buf, 1);
315 x86bios_free(buf, sizeof(*vmode));
260
316
261 return 0;
317 return (0);
262}
263
264static int
318}
319
320static int
321vesa_bios_get_current_mode(void)
322{
323 x86regs_t regs;
324
325 x86bios_init_regs(&regs);
326 regs.R_AX = 0x4f03;
327
328 x86bios_intr(&regs, 0x10);
329
330 if (regs.R_AX != 0x004f)
331 return (-1);
332
333 return (regs.R_BX);
334}
335
336static int
265vesa_bios_set_mode(int mode)
266{
267 x86regs_t regs;
268
337vesa_bios_set_mode(int mode)
338{
339 x86regs_t regs;
340
269 bzero(&regs, sizeof(regs));
270 regs.R_EAX = 0x4f02;
271 regs.R_EBX = mode;
341 x86bios_init_regs(&regs);
342 regs.R_AX = 0x4f02;
343 regs.R_BX = mode;
272
273 x86bios_intr(&regs, 0x10);
274
344
345 x86bios_intr(&regs, 0x10);
346
275 return ((regs.R_AX & 0xff) != 0x4f);
347 return (regs.R_AX != 0x004f);
276}
277
278static int
279vesa_bios_get_dac(void)
280{
281 x86regs_t regs;
282
348}
349
350static int
351vesa_bios_get_dac(void)
352{
353 x86regs_t regs;
354
283 bzero(&regs, sizeof(regs));
284 regs.R_EAX = 0x4f08;
285 regs.R_EBX = 1;
355 x86bios_init_regs(&regs);
356 regs.R_AX = 0x4f08;
357 regs.R_BL = 1;
286
287 x86bios_intr(&regs, 0x10);
288
358
359 x86bios_intr(&regs, 0x10);
360
289 if ((regs.R_AX & 0xff) != 0x4f)
290 return 6;
361 if (regs.R_AX != 0x004f)
362 return (6);
291
363
292 return ((regs.R_EBX >> 8) & 0x00ff);
364 return (regs.R_BH);
293}
294
295static int
296vesa_bios_set_dac(int bits)
297{
298 x86regs_t regs;
299
365}
366
367static int
368vesa_bios_set_dac(int bits)
369{
370 x86regs_t regs;
371
300 bzero(&regs, sizeof(regs));
301 regs.R_EAX = 0x4f08;
302 regs.R_EBX = (bits << 8);
372 x86bios_init_regs(&regs);
373 regs.R_AX = 0x4f08;
374 /* regs.R_BL = 0; */
375 regs.R_BH = bits;
303
304 x86bios_intr(&regs, 0x10);
305
376
377 x86bios_intr(&regs, 0x10);
378
306 if ((regs.R_AX & 0xff) != 0x4f)
307 return 6;
379 if (regs.R_AX != 0x004f)
380 return (6);
308
381
309 return ((regs.R_EBX >> 8) & 0x00ff);
382 return (regs.R_BH);
310}
311
312static int
313vesa_bios_save_palette(int start, int colors, u_char *palette, int bits)
314{
315 x86regs_t regs;
383}
384
385static int
386vesa_bios_save_palette(int start, int colors, u_char *palette, int bits)
387{
388 x86regs_t regs;
316 int offs;
389 uint32_t offs;
317 u_char *p;
318 int i;
319
390 u_char *p;
391 int i;
392
320 bzero(&regs, sizeof(regs));
321 regs.R_EAX = 0x4f09;
322 regs.R_EBX = 1;
323 regs.R_ECX = colors;
324 regs.R_EDX = start;
393 p = (u_char *)x86bios_alloc(&offs, colors * 4);
394 if (p == NULL)
395 return (1);
325
396
326 p = (u_char *)x86bios_alloc(1, &offs);
397 x86bios_init_regs(&regs);
398 regs.R_AX = 0x4f09;
399 regs.R_BL = 1;
400 regs.R_CX = colors;
401 regs.R_DX = start;
327
402
328 regs.R_ES = SEG_ADDR(offs);
329 regs.R_DI = SEG_OFF(offs);
403 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
404 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
330
331 x86bios_intr(&regs, 0x10);
332
405
406 x86bios_intr(&regs, 0x10);
407
333 if ((regs.R_AX & 0xff) != 0x4f)
334 {
335 x86bios_free(p, 1);
336 return 1;
408 if (regs.R_AX != 0x004f) {
409 x86bios_free(p, colors * 4);
410 return (1);
337 }
338
339 bits = 8 - bits;
340 for (i = 0; i < colors; ++i) {
341 palette[i*3] = p[i*4 + 2] << bits;
342 palette[i*3 + 1] = p[i*4 + 1] << bits;
343 palette[i*3 + 2] = p[i*4] << bits;
344 }
411 }
412
413 bits = 8 - bits;
414 for (i = 0; i < colors; ++i) {
415 palette[i*3] = p[i*4 + 2] << bits;
416 palette[i*3 + 1] = p[i*4 + 1] << bits;
417 palette[i*3 + 2] = p[i*4] << bits;
418 }
419 x86bios_free(p, colors * 4);
345
420
346 x86bios_free(p, 1);
347 return 0;
421 return (0);
348}
349
350static int
351vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
352 int bits)
353{
354 x86regs_t regs;
422}
423
424static int
425vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
426 int bits)
427{
428 x86regs_t regs;
355 int offs;
429 uint32_t offs;
356 u_char *p;
357 int i;
358
430 u_char *p;
431 int i;
432
359 bzero(&regs, sizeof(regs));
360 regs.R_EAX = 0x4f09;
361 regs.R_EBX = 1;
362 regs.R_ECX = colors;
363 regs.R_EDX = start;
433 p = (u_char *)x86bios_alloc(&offs, colors * 4);
434 if (p == NULL)
435 return (1);
364
436
365 p = (u_char *)x86bios_alloc(1, &offs);
437 x86bios_init_regs(&regs);
438 regs.R_AX = 0x4f09;
439 regs.R_BL = 1;
440 regs.R_CX = colors;
441 regs.R_DX = start;
366
442
367 regs.R_ES = SEG_ADDR(offs);
368 regs.R_DI = SEG_OFF(offs);
443 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
444 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
369
370 x86bios_intr(&regs, 0x10);
371
445
446 x86bios_intr(&regs, 0x10);
447
372 if ((regs.R_AX & 0xff) != 0x4f)
373 {
374 x86bios_free(p, 1);
375 return 1;
448 if (regs.R_AX != 0x004f) {
449 x86bios_free(p, colors * 4);
450 return (1);
376 }
377
378 bits = 8 - bits;
379 for (i = 0; i < colors; ++i) {
380 r[i] = p[i*4 + 2] << bits;
381 g[i] = p[i*4 + 1] << bits;
382 b[i] = p[i*4] << bits;
383 }
451 }
452
453 bits = 8 - bits;
454 for (i = 0; i < colors; ++i) {
455 r[i] = p[i*4 + 2] << bits;
456 g[i] = p[i*4 + 1] << bits;
457 b[i] = p[i*4] << bits;
458 }
459 x86bios_free(p, colors * 4);
384
460
385 x86bios_free(p, 1);
386 return 0;
461 return (0);
387}
388
389static int
390vesa_bios_load_palette(int start, int colors, u_char *palette, int bits)
391{
392 x86regs_t regs;
462}
463
464static int
465vesa_bios_load_palette(int start, int colors, u_char *palette, int bits)
466{
467 x86regs_t regs;
393 int offs;
468 uint32_t offs;
394 u_char *p;
395 int i;
396
469 u_char *p;
470 int i;
471
397 p = (u_char *)x86bios_alloc(1, &offs);
472 p = (u_char *)x86bios_alloc(&offs, colors * 4);
473 if (p == NULL)
474 return (1);
398
475
476 x86bios_init_regs(&regs);
477 regs.R_AX = 0x4f09;
478 /* regs.R_BL = 0; */
479 regs.R_CX = colors;
480 regs.R_DX = start;
481
482 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
483 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
484
399 bits = 8 - bits;
400 for (i = 0; i < colors; ++i) {
401 p[i*4] = palette[i*3 + 2] >> bits;
402 p[i*4 + 1] = palette[i*3 + 1] >> bits;
403 p[i*4 + 2] = palette[i*3] >> bits;
404 p[i*4 + 3] = 0;
405 }
485 bits = 8 - bits;
486 for (i = 0; i < colors; ++i) {
487 p[i*4] = palette[i*3 + 2] >> bits;
488 p[i*4 + 1] = palette[i*3 + 1] >> bits;
489 p[i*4 + 2] = palette[i*3] >> bits;
490 p[i*4 + 3] = 0;
491 }
406
407 bzero(&regs, sizeof(regs));
408 regs.R_EAX = 0x4f09;
409 regs.R_EBX = 0;
410 regs.R_ECX = colors;
411 regs.R_EDX = start;
412
413 regs.R_ES = SEG_ADDR(offs);
414 regs.R_DI = SEG_OFF(offs);
415
416 x86bios_intr(&regs, 0x10);
492 x86bios_intr(&regs, 0x10);
493 x86bios_free(p, colors * 4);
417
494
418 x86bios_free(p, 1);
419
420 return ((regs.R_AX & 0xff) != 0x4f);
495 return (regs.R_AX != 0x004f);
421}
422
423#ifdef notyet
424static int
425vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
426 int bits)
427{
428 x86regs_t regs;
496}
497
498#ifdef notyet
499static int
500vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
501 int bits)
502{
503 x86regs_t regs;
429 int offs;
504 uint32_t offs;
430 u_char *p;
431 int i;
432
505 u_char *p;
506 int i;
507
433 p = (u_char *)x86bios_alloc(1, &offs);
508 p = (u_char *)x86bios_alloc(&offs, colors * 4);
509 if (p == NULL)
510 return (1);
434
511
512 x86bios_init_regs(&regs);
513 regs.R_AX = 0x4f09;
514 /* regs.R_BL = 0; */
515 regs.R_CX = colors;
516 regs.R_DX = start;
517
518 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
519 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
520
435 bits = 8 - bits;
436 for (i = 0; i < colors; ++i) {
437 p[i*4] = b[i] >> bits;
438 p[i*4 + 1] = g[i] >> bits;
439 p[i*4 + 2] = r[i] >> bits;
440 p[i*4 + 3] = 0;
441 }
521 bits = 8 - bits;
522 for (i = 0; i < colors; ++i) {
523 p[i*4] = b[i] >> bits;
524 p[i*4 + 1] = g[i] >> bits;
525 p[i*4 + 2] = r[i] >> bits;
526 p[i*4 + 3] = 0;
527 }
442
443 bzero(&regs, sizeof(regs));
444 regs.R_EAX = 0x4f09;
445 regs.R_EBX = 0;
446 regs.R_ECX = colors;
447 regs.R_EDX = start;
448
449 regs.R_ES = SEG_ADDR(offs);
450 regs.R_DI = SEG_OFF(offs);
451
452 x86bios_intr(&regs, 0x10);
528 x86bios_intr(&regs, 0x10);
529 x86bios_free(p, colors * 4);
453
530
454 x86bios_free(p, 1);
455
456 return ((regs.R_AX & 0xff) != 0x4f);
531 return (regs.R_AX != 0x004f);
457}
458#endif
459
460static int
461vesa_bios_state_buf_size(void)
462{
463 x86regs_t regs;
464
532}
533#endif
534
535static int
536vesa_bios_state_buf_size(void)
537{
538 x86regs_t regs;
539
465 bzero(&regs, sizeof(regs));
466 regs.R_EAX = 0x4f04;
467 regs.R_ECX = STATE_ALL;
468 regs.R_EDX = STATE_SIZE;
540 x86bios_init_regs(&regs);
541 regs.R_AX = 0x4f04;
542 /* regs.R_DL = STATE_SIZE; */
543 regs.R_CX = STATE_ALL;
469
470 x86bios_intr(&regs, 0x10);
471
544
545 x86bios_intr(&regs, 0x10);
546
472 if ((regs.R_AX & 0xff) != 0x4f)
473 return 0;
547 if (regs.R_AX != 0x004f)
548 return (0);
474
549
475 return regs.R_BX * 64;
550 return (regs.R_BX * 64);
476}
477
478static int
479vesa_bios_save_restore(int code, void *p, size_t size)
480{
481 x86regs_t regs;
551}
552
553static int
554vesa_bios_save_restore(int code, void *p, size_t size)
555{
556 x86regs_t regs;
482 int offs;
483 u_char *buf;
557 uint32_t offs;
558 void *buf;
484
485 if (size > VESA_BIOS_BUFSIZE)
486 return (1);
487
559
560 if (size > VESA_BIOS_BUFSIZE)
561 return (1);
562
488 bzero(&regs, sizeof(regs));
489 regs.R_EAX = 0x4f04;
490 regs.R_ECX = STATE_ALL;
491 regs.R_EDX = code;
563 if (code != STATE_SAVE && code != STATE_LOAD)
564 return (1);
492
565
493 buf = (u_char *)x86bios_alloc(1, &offs);
566 buf = x86bios_alloc(&offs, size);
494
567
495 regs.R_ES = SEG_ADDR(offs);
496 regs.R_DI = SEG_OFF(offs);
568 x86bios_init_regs(&regs);
569 regs.R_AX = 0x4f04;
570 regs.R_DL = code;
571 regs.R_CX = STATE_ALL;
497
572
498 bcopy(p, buf, size);
573 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
574 regs.R_BX = X86BIOS_PHYSTOOFF(offs);
499
575
500 x86bios_intr(&regs, 0x10);
576 switch (code) {
577 case STATE_SAVE:
578 x86bios_intr(&regs, 0x10);
579 bcopy(buf, p, size);
580 break;
581 case STATE_LOAD:
582 bcopy(p, buf, size);
583 x86bios_intr(&regs, 0x10);
584 break;
585 }
586 x86bios_free(buf, size);
501
587
502 bcopy(buf, p, size);
503
504 x86bios_free(p, 1);
505
506 return ((regs.R_AX & 0xff) != 0x4f);
588 return (regs.R_AX != 0x004f);
507}
508
509static int
510vesa_bios_get_line_length(void)
511{
512 x86regs_t regs;
513
589}
590
591static int
592vesa_bios_get_line_length(void)
593{
594 x86regs_t regs;
595
514 bzero(&regs, sizeof(regs));
515 regs.R_EAX = 0x4f06;
516 regs.R_EBX = 1;
596 x86bios_init_regs(&regs);
597 regs.R_AX = 0x4f06;
598 regs.R_BL = 1;
517
518 x86bios_intr(&regs, 0x10);
519
599
600 x86bios_intr(&regs, 0x10);
601
520 if ((regs.R_AX & 0xff) != 0x4f)
521 return -1;
602 if (regs.R_AX != 0x004f)
603 return (-1);
522
604
523 return regs.R_BX;
605 return (regs.R_BX);
524}
525
526static int
527vesa_bios_set_line_length(int pixel, int *bytes, int *lines)
528{
529 x86regs_t regs;
530
606}
607
608static int
609vesa_bios_set_line_length(int pixel, int *bytes, int *lines)
610{
611 x86regs_t regs;
612
531 bzero(&regs, sizeof(regs));
532 regs.R_EAX = 0x4f06;
533 regs.R_EBX = 0;
534 regs.R_ECX = pixel;
613 x86bios_init_regs(&regs);
614 regs.R_AX = 0x4f06;
615 /* regs.R_BL = 0; */
616 regs.R_CX = pixel;
535
536 x86bios_intr(&regs, 0x10);
537
538#if VESA_DEBUG > 1
539 printf("bx:%d, cx:%d, dx:%d\n", regs.R_BX, regs.R_CX, regs.R_DX);
540#endif
617
618 x86bios_intr(&regs, 0x10);
619
620#if VESA_DEBUG > 1
621 printf("bx:%d, cx:%d, dx:%d\n", regs.R_BX, regs.R_CX, regs.R_DX);
622#endif
541 if ((regs.R_AX & 0xff) != 0x4f)
542 return -1;
623 if (regs.R_AX != 0x004f)
624 return (-1);
543
625
544 if (bytes)
626 if (bytes != NULL)
545 *bytes = regs.R_BX;
627 *bytes = regs.R_BX;
546 if (lines)
628 if (lines != NULL)
547 *lines = regs.R_DX;
548
629 *lines = regs.R_DX;
630
549 return 0;
631 return (0);
550}
551
552#if 0
553static int
554vesa_bios_get_start(int *x, int *y)
555{
556 x86regs_t regs;
557
632}
633
634#if 0
635static int
636vesa_bios_get_start(int *x, int *y)
637{
638 x86regs_t regs;
639
558 bzero(&regs, sizeof(regs));
559 regs.R_EAX = 0x4f07;
560 regs.R_EBX = 1;
640 x86bios_init_regs(&regs);
641 regs.R_AX = 0x4f07;
642 regs.R_BL = 1;
561
562 x86bios_intr(&regs, 0x10);
563
643
644 x86bios_intr(&regs, 0x10);
645
564 if ((regs.R_AX & 0xff) != 0x4f)
565 return -1;
646 if (regs.R_AX != 0x004f)
647 return (-1);
566
567 *x = regs.R_CX;
568 *y = regs.R_DX;
569
648
649 *x = regs.R_CX;
650 *y = regs.R_DX;
651
570 return 0;
652 return (0);
571}
572#endif
573
574static int
575vesa_bios_set_start(int x, int y)
576{
577 x86regs_t regs;
578
653}
654#endif
655
656static int
657vesa_bios_set_start(int x, int y)
658{
659 x86regs_t regs;
660
579 bzero(&regs, sizeof(regs));
580 regs.R_EAX = 0x4f07;
581 regs.R_EBX = 0x80;
582 regs.R_EDX = y;
583 regs.R_ECX = x;
661 x86bios_init_regs(&regs);
662 regs.R_AX = 0x4f07;
663 regs.R_BL = 0x80;
664 regs.R_CX = x;
665 regs.R_DX = y;
584
585 x86bios_intr(&regs, 0x10);
586
666
667 x86bios_intr(&regs, 0x10);
668
587 return ((regs.R_AX & 0xff) != 0x4f);
669 return (regs.R_AX != 0x004f);
588}
589
590/* map a generic video mode to a known mode */
591static int
592vesa_map_gen_mode_num(int type, int color, int mode)
593{
594 static struct {
595 int from;
596 int to;
597 } mode_map[] = {
598 { M_TEXT_132x25, M_VESA_C132x25 },
599 { M_TEXT_132x43, M_VESA_C132x43 },
600 { M_TEXT_132x50, M_VESA_C132x50 },
601 { M_TEXT_132x60, M_VESA_C132x60 },
602 };
603 int i;
604
605 for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) {
606 if (mode_map[i].from == mode)
670}
671
672/* map a generic video mode to a known mode */
673static int
674vesa_map_gen_mode_num(int type, int color, int mode)
675{
676 static struct {
677 int from;
678 int to;
679 } mode_map[] = {
680 { M_TEXT_132x25, M_VESA_C132x25 },
681 { M_TEXT_132x43, M_VESA_C132x43 },
682 { M_TEXT_132x50, M_VESA_C132x50 },
683 { M_TEXT_132x60, M_VESA_C132x60 },
684 };
685 int i;
686
687 for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) {
688 if (mode_map[i].from == mode)
607 return mode_map[i].to;
689 return (mode_map[i].to);
608 }
690 }
609 return mode;
691 return (mode);
610}
611
612static int
613vesa_translate_flags(u_int16_t vflags)
614{
615 static struct {
616 u_int16_t mask;
617 int set;

--- 5 unchanged lines hidden (view full) ---

623 };
624 int flags;
625 int i;
626
627 for (flags = 0, i = 0; i < sizeof(ftable)/sizeof(ftable[0]); ++i) {
628 flags |= (vflags & ftable[i].mask) ?
629 ftable[i].set : ftable[i].reset;
630 }
692}
693
694static int
695vesa_translate_flags(u_int16_t vflags)
696{
697 static struct {
698 u_int16_t mask;
699 int set;

--- 5 unchanged lines hidden (view full) ---

705 };
706 int flags;
707 int i;
708
709 for (flags = 0, i = 0; i < sizeof(ftable)/sizeof(ftable[0]); ++i) {
710 flags |= (vflags & ftable[i].mask) ?
711 ftable[i].set : ftable[i].reset;
712 }
631 return flags;
713 return (flags);
632}
633
634static int
635vesa_translate_mmodel(u_int8_t vmodel)
636{
637 static struct {
638 u_int8_t vmodel;
639 int mmodel;

--- 4 unchanged lines hidden (view full) ---

644 { V_MMEGA, V_INFO_MM_PLANAR },
645 { V_MMPACKED, V_INFO_MM_PACKED },
646 { V_MMDIRCOLOR, V_INFO_MM_DIRECT },
647 };
648 int i;
649
650 for (i = 0; mtable[i].mmodel >= 0; ++i) {
651 if (mtable[i].vmodel == vmodel)
714}
715
716static int
717vesa_translate_mmodel(u_int8_t vmodel)
718{
719 static struct {
720 u_int8_t vmodel;
721 int mmodel;

--- 4 unchanged lines hidden (view full) ---

726 { V_MMEGA, V_INFO_MM_PLANAR },
727 { V_MMPACKED, V_INFO_MM_PACKED },
728 { V_MMDIRCOLOR, V_INFO_MM_DIRECT },
729 };
730 int i;
731
732 for (i = 0; mtable[i].mmodel >= 0; ++i) {
733 if (mtable[i].vmodel == vmodel)
652 return mtable[i].mmodel;
734 return (mtable[i].mmodel);
653 }
735 }
654 return V_INFO_MM_OTHER;
736 return (V_INFO_MM_OTHER);
655}
656
657static int
658vesa_get_line_width(video_info_t *info)
659{
660 int len;
661 int width;
662

--- 17 unchanged lines hidden (view full) ---

680 return (width * 4);
681 }
682
683 len = vesa_bios_get_line_length();
684
685 return (len > 0 ? len : width);
686}
687
737}
738
739static int
740vesa_get_line_width(video_info_t *info)
741{
742 int len;
743 int width;
744

--- 17 unchanged lines hidden (view full) ---

762 return (width * 4);
763 }
764
765 len = vesa_bios_get_line_length();
766
767 return (len > 0 ? len : width);
768}
769
770#define VESA_MAXSTR 256
771
772#define VESA_STRCPY(dst, src) do { \
773 char *str; \
774 int i; \
775 dst = malloc(VESA_MAXSTR, M_DEVBUF, M_WAITOK); \
776 str = x86bios_offset(BIOS_SADDRTOLADDR(src)); \
777 for (i = 0; i < VESA_MAXSTR - 1 && str[i] != '\0'; i++) \
778 dst[i] = str[i]; \
779 dst[i] = '\0'; \
780} while (0)
781
688static int
689vesa_bios_init(void)
690{
691 static struct vesa_info buf;
692 struct vesa_mode vmode;
693 video_info_t *p;
694 x86regs_t regs;
695 size_t bsize;
782static int
783vesa_bios_init(void)
784{
785 static struct vesa_info buf;
786 struct vesa_mode vmode;
787 video_info_t *p;
788 x86regs_t regs;
789 size_t bsize;
696 int offs;
697 u_char *vmbuf;
790 void *vmbuf;
791 uint32_t offs;
792 uint16_t vers;
698 int is_via_cle266;
699 int modes;
700 int i;
701
702 if (vesa_init_done)
793 int is_via_cle266;
794 int modes;
795 int i;
796
797 if (vesa_init_done)
703 return 0;
798 return (0);
704
705 has_vesa_bios = FALSE;
706 vesa_adp_info = NULL;
707 vesa_vmode_max = 0;
708 vesa_vmode[0].vi_mode = EOT;
709
799
800 has_vesa_bios = FALSE;
801 vesa_adp_info = NULL;
802 vesa_vmode_max = 0;
803 vesa_vmode[0].vi_mode = EOT;
804
710 vmbuf = (u_char *)x86bios_alloc(1, &offs);
711 bcopy("VBE2", vmbuf, 4); /* try for VBE2 data */
805 /*
806 * If the VBE real mode interrupt vector is not found, try BIOS POST.
807 */
808 if (x86bios_get_intr(0x10) == 0) {
809 if (vesa_bios_post() != 0)
810 return (1);
811 offs = x86bios_get_intr(0x10);
812 if (offs == 0)
813 return (1);
814 if (bootverbose)
815 printf("VESA: interrupt vector installed (0x%x)\n",
816 BIOS_SADDRTOLADDR(offs));
817 }
712
818
713 bzero(&regs, sizeof(regs));
714 regs.R_EAX = 0x4f00;
715 regs.R_ES = SEG_ADDR(offs);
716 regs.R_DI = SEG_OFF(offs);
819 x86bios_init_regs(&regs);
820 regs.R_AX = 0x4f00;
717
821
822 vmbuf = x86bios_alloc(&offs, sizeof(buf));
823 if (vmbuf == NULL)
824 return (1);
825
826 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
827 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
828
829 bcopy("VBE2", vmbuf, 4); /* try for VBE2 data */
718 x86bios_intr(&regs, 0x10);
719
830 x86bios_intr(&regs, 0x10);
831
720 if (((regs.R_AX & 0xff) != 0x4f) || bcmp("VESA", vmbuf, 4))
721 return 1;
832 if (regs.R_AX != 0x004f || bcmp("VESA", vmbuf, 4) != 0)
833 goto fail;
722
723 bcopy(vmbuf, &buf, sizeof(buf));
724
725 vesa_adp_info = &buf;
726 if (bootverbose) {
727 printf("VESA: information block\n");
728 dump_buffer((u_char *)&buf, sizeof(buf));
729 }
834
835 bcopy(vmbuf, &buf, sizeof(buf));
836
837 vesa_adp_info = &buf;
838 if (bootverbose) {
839 printf("VESA: information block\n");
840 dump_buffer((u_char *)&buf, sizeof(buf));
841 }
730 if (vesa_adp_info->v_version < 0x0102) {
842
843 vers = buf.v_version = le16toh(buf.v_version);
844 buf.v_oemstr = le32toh(buf.v_oemstr);
845 buf.v_flags = le32toh(buf.v_flags);
846 buf.v_modetable = le32toh(buf.v_modetable);
847 buf.v_memsize = le16toh(buf.v_memsize);
848 buf.v_revision = le16toh(buf.v_revision);
849 buf.v_venderstr = le32toh(buf.v_venderstr);
850 buf.v_prodstr = le32toh(buf.v_prodstr);
851 buf.v_revstr = le32toh(buf.v_revstr);
852
853 if (vers < 0x0102) {
731 printf("VESA: VBE version %d.%d is not supported; "
732 "version 1.2 or later is required.\n",
854 printf("VESA: VBE version %d.%d is not supported; "
855 "version 1.2 or later is required.\n",
733 ((vesa_adp_info->v_version & 0xf000) >> 12) * 10
734 + ((vesa_adp_info->v_version & 0x0f00) >> 8),
735 ((vesa_adp_info->v_version & 0x00f0) >> 4) * 10
736 + (vesa_adp_info->v_version & 0x000f));
737 return 1;
856 ((vers & 0xf000) >> 12) * 10 + ((vers & 0x0f00) >> 8),
857 ((vers & 0x00f0) >> 4) * 10 + (vers & 0x000f));
858 return (1);
738 }
739
859 }
860
740 vesa_oemstr = (char *)x86bios_offset(FARP(vesa_adp_info->v_oemstr));
741
742 is_via_cle266 = strcmp(vesa_oemstr, VESA_VIA_CLE266) == 0;
743
744 if (vesa_adp_info->v_version >= 0x0200) {
745 vesa_venderstr = (char *)x86bios_offset(FARP(vesa_adp_info->v_venderstr));
746 vesa_prodstr = (char *)x86bios_offset(FARP(vesa_adp_info->v_prodstr));
747 vesa_revstr = (char *)x86bios_offset(FARP(vesa_adp_info->v_revstr));
861 VESA_STRCPY(vesa_oemstr, buf.v_oemstr);
862 if (vers >= 0x0200) {
863 VESA_STRCPY(vesa_venderstr, buf.v_venderstr);
864 VESA_STRCPY(vesa_prodstr, buf.v_prodstr);
865 VESA_STRCPY(vesa_revstr, buf.v_revstr);
748 }
866 }
867 is_via_cle266 = strncmp(vesa_oemstr, VESA_VIA_CLE266,
868 sizeof(VESA_VIA_CLE266)) == 0;
749
869
750 vesa_vmodetab = (uint16_t *)x86bios_offset(FARP(vesa_adp_info->v_modetable));
870 if (buf.v_modetable == 0)
871 goto fail;
751
872
752 if (vesa_vmodetab == NULL)
753 return 1;
873 vesa_vmodetab = x86bios_offset(BIOS_SADDRTOLADDR(buf.v_modetable));
754
755 for (i = 0, modes = 0;
756 (i < (M_VESA_MODE_MAX - M_VESA_BASE + 1))
757 && (vesa_vmodetab[i] != 0xffff); ++i) {
874
875 for (i = 0, modes = 0;
876 (i < (M_VESA_MODE_MAX - M_VESA_BASE + 1))
877 && (vesa_vmodetab[i] != 0xffff); ++i) {
878 vesa_vmodetab[i] = le16toh(vesa_vmodetab[i]);
758 if (vesa_bios_get_mode(vesa_vmodetab[i], &vmode))
759 continue;
760
761 /* reject unsupported modes */
762#if 0
763 if ((vmode.v_modeattr & (V_MODESUPP | V_MODEOPTINFO
764 | V_MODENONVGA))
765 != (V_MODESUPP | V_MODEOPTINFO))

--- 117 unchanged lines hidden (view full) ---

883#endif
884 continue;
885 }
886
887 ++modes;
888 }
889 vesa_vmode[modes].vi_mode = EOT;
890
879 if (vesa_bios_get_mode(vesa_vmodetab[i], &vmode))
880 continue;
881
882 /* reject unsupported modes */
883#if 0
884 if ((vmode.v_modeattr & (V_MODESUPP | V_MODEOPTINFO
885 | V_MODENONVGA))
886 != (V_MODESUPP | V_MODEOPTINFO))

--- 117 unchanged lines hidden (view full) ---

1004#endif
1005 continue;
1006 }
1007
1008 ++modes;
1009 }
1010 vesa_vmode[modes].vi_mode = EOT;
1011
891 x86bios_free(vmbuf, 1);
892
893 if (bootverbose)
894 printf("VESA: %d mode(s) found\n", modes);
895
896 has_vesa_bios = (modes > 0);
897 if (!has_vesa_bios)
1012 if (bootverbose)
1013 printf("VESA: %d mode(s) found\n", modes);
1014
1015 has_vesa_bios = (modes > 0);
1016 if (!has_vesa_bios)
898 return (1);
1017 goto fail;
899
1018
1019 x86bios_free(vmbuf, sizeof(buf));
900 return (0);
1020 return (0);
1021
1022fail:
1023 if (vmbuf != NULL)
1024 x86bios_free(vmbuf, sizeof(buf));
1025 if (vesa_oemstr != NULL) {
1026 free(vesa_oemstr, M_DEVBUF);
1027 vesa_oemstr = NULL;
1028 }
1029 if (vesa_venderstr != NULL) {
1030 free(vesa_venderstr, M_DEVBUF);
1031 vesa_venderstr = NULL;
1032 }
1033 if (vesa_prodstr != NULL) {
1034 free(vesa_prodstr, M_DEVBUF);
1035 vesa_prodstr = NULL;
1036 }
1037 if (vesa_revstr != NULL) {
1038 free(vesa_revstr, M_DEVBUF);
1039 vesa_revstr = NULL;
1040 }
1041 return (1);
901}
902
903static void
904vesa_clear_modes(video_info_t *info, int color)
905{
906 while (info->vi_mode != EOT) {
907 if ((info->vi_flags & V_INFO_COLOR) != color)
908 info->vi_mode = NA;

--- 32 unchanged lines hidden (view full) ---

941vesa_configure(int flags)
942{
943 video_adapter_t *adp;
944 int adapters;
945 int error;
946 int i;
947
948 if (vesa_init_done)
1042}
1043
1044static void
1045vesa_clear_modes(video_info_t *info, int color)
1046{
1047 while (info->vi_mode != EOT) {
1048 if ((info->vi_flags & V_INFO_COLOR) != color)
1049 info->vi_mode = NA;

--- 32 unchanged lines hidden (view full) ---

1082vesa_configure(int flags)
1083{
1084 video_adapter_t *adp;
1085 int adapters;
1086 int error;
1087 int i;
1088
1089 if (vesa_init_done)
949 return 0;
1090 return (0);
950 if (flags & VIO_PROBE_ONLY)
1091 if (flags & VIO_PROBE_ONLY)
951 return 0; /* XXX */
1092 return (0);
952
953 /*
954 * If the VESA module has already been loaded, abort loading
955 * the module this time.
956 */
957 for (i = 0; (adp = vid_get_adapter(i)) != NULL; ++i) {
958 if (adp->va_flags & V_ADP_VESA)
1093
1094 /*
1095 * If the VESA module has already been loaded, abort loading
1096 * the module this time.
1097 */
1098 for (i = 0; (adp = vid_get_adapter(i)) != NULL; ++i) {
1099 if (adp->va_flags & V_ADP_VESA)
959 return ENXIO;
1100 return (ENXIO);
960 if (adp->va_type == KD_VGA)
961 break;
962 }
1101 if (adp->va_type == KD_VGA)
1102 break;
1103 }
1104
963 /*
964 * The VGA adapter is not found. This is because either
965 * 1) the VGA driver has not been initialized, or 2) the VGA card
966 * is not present. If 1) is the case, we shall defer
967 * initialization for now and try again later.
968 */
969 if (adp == NULL) {
970 vga_sub_configure = vesa_configure;
1105 /*
1106 * The VGA adapter is not found. This is because either
1107 * 1) the VGA driver has not been initialized, or 2) the VGA card
1108 * is not present. If 1) is the case, we shall defer
1109 * initialization for now and try again later.
1110 */
1111 if (adp == NULL) {
1112 vga_sub_configure = vesa_configure;
971 return ENODEV;
1113 return (ENODEV);
972 }
973
974 /* count number of registered adapters */
975 for (++i; vid_get_adapter(i) != NULL; ++i)
976 ;
977 adapters = i;
978
979 /* call VESA BIOS */
980 vesa_adp = adp;
981 if (vesa_bios_init()) {
982 vesa_adp = NULL;
1114 }
1115
1116 /* count number of registered adapters */
1117 for (++i; vid_get_adapter(i) != NULL; ++i)
1118 ;
1119 adapters = i;
1120
1121 /* call VESA BIOS */
1122 vesa_adp = adp;
1123 if (vesa_bios_init()) {
1124 vesa_adp = NULL;
983 return ENXIO;
1125 return (ENXIO);
984 }
985 vesa_adp->va_flags |= V_ADP_VESA;
986
987 /* remove conflicting modes if we have more than one adapter */
988 if (adapters > 1) {
989 vesa_clear_modes(vesa_vmode,
990 (vesa_adp->va_flags & V_ADP_COLOR) ?
991 V_INFO_COLOR : 0);
992 }
993
994 if ((error = vesa_load_ioctl()) == 0) {
995 prevvidsw = vidsw[vesa_adp->va_index];
996 vidsw[vesa_adp->va_index] = &vesavidsw;
997 vesa_init_done = TRUE;
998 } else {
999 vesa_adp = NULL;
1126 }
1127 vesa_adp->va_flags |= V_ADP_VESA;
1128
1129 /* remove conflicting modes if we have more than one adapter */
1130 if (adapters > 1) {
1131 vesa_clear_modes(vesa_vmode,
1132 (vesa_adp->va_flags & V_ADP_COLOR) ?
1133 V_INFO_COLOR : 0);
1134 }
1135
1136 if ((error = vesa_load_ioctl()) == 0) {
1137 prevvidsw = vidsw[vesa_adp->va_index];
1138 vidsw[vesa_adp->va_index] = &vesavidsw;
1139 vesa_init_done = TRUE;
1140 } else {
1141 vesa_adp = NULL;
1000 return error;
1142 return (error);
1001 }
1002
1143 }
1144
1003 return 0;
1145 return (0);
1004}
1005
1006#if 0
1007static int
1008vesa_nop(void)
1009{
1146}
1147
1148#if 0
1149static int
1150vesa_nop(void)
1151{
1010 return 0;
1152
1153 return (0);
1011}
1012#endif
1013
1014static int
1015vesa_error(void)
1016{
1154}
1155#endif
1156
1157static int
1158vesa_error(void)
1159{
1017 return 1;
1160
1161 return (1);
1018}
1019
1020static int
1021vesa_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
1022{
1162}
1163
1164static int
1165vesa_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
1166{
1023 return (*prevvidsw->probe)(unit, adpp, arg, flags);
1167
1168 return ((*prevvidsw->probe)(unit, adpp, arg, flags));
1024}
1025
1026static int
1027vesa_init(int unit, video_adapter_t *adp, int flags)
1028{
1169}
1170
1171static int
1172vesa_init(int unit, video_adapter_t *adp, int flags)
1173{
1029 return (*prevvidsw->init)(unit, adp, flags);
1174
1175 return ((*prevvidsw->init)(unit, adp, flags));
1030}
1031
1032static int
1033vesa_get_info(video_adapter_t *adp, int mode, video_info_t *info)
1034{
1035 int i;
1036
1037 if ((*prevvidsw->get_info)(adp, mode, info) == 0)
1176}
1177
1178static int
1179vesa_get_info(video_adapter_t *adp, int mode, video_info_t *info)
1180{
1181 int i;
1182
1183 if ((*prevvidsw->get_info)(adp, mode, info) == 0)
1038 return 0;
1184 return (0);
1039
1040 if (adp != vesa_adp)
1185
1186 if (adp != vesa_adp)
1041 return 1;
1187 return (1);
1042
1043 mode = vesa_map_gen_mode_num(vesa_adp->va_type,
1044 vesa_adp->va_flags & V_ADP_COLOR, mode);
1045 for (i = 0; vesa_vmode[i].vi_mode != EOT; ++i) {
1046 if (vesa_vmode[i].vi_mode == NA)
1047 continue;
1048 if (vesa_vmode[i].vi_mode == mode) {
1049 *info = vesa_vmode[i];
1188
1189 mode = vesa_map_gen_mode_num(vesa_adp->va_type,
1190 vesa_adp->va_flags & V_ADP_COLOR, mode);
1191 for (i = 0; vesa_vmode[i].vi_mode != EOT; ++i) {
1192 if (vesa_vmode[i].vi_mode == NA)
1193 continue;
1194 if (vesa_vmode[i].vi_mode == mode) {
1195 *info = vesa_vmode[i];
1050 return 0;
1196 return (0);
1051 }
1052 }
1197 }
1198 }
1053 return 1;
1199 return (1);
1054}
1055
1056static int
1057vesa_query_mode(video_adapter_t *adp, video_info_t *info)
1058{
1059 int i;
1060
1061 if ((*prevvidsw->query_mode)(adp, info) == 0)
1200}
1201
1202static int
1203vesa_query_mode(video_adapter_t *adp, video_info_t *info)
1204{
1205 int i;
1206
1207 if ((*prevvidsw->query_mode)(adp, info) == 0)
1062 return 0;
1208 return (0);
1063 if (adp != vesa_adp)
1209 if (adp != vesa_adp)
1064 return ENODEV;
1210 return (ENODEV);
1065
1066 for (i = 0; vesa_vmode[i].vi_mode != EOT; ++i) {
1067 if ((info->vi_width != 0)
1068 && (info->vi_width != vesa_vmode[i].vi_width))
1069 continue;
1070 if ((info->vi_height != 0)
1071 && (info->vi_height != vesa_vmode[i].vi_height))
1072 continue;

--- 9 unchanged lines hidden (view full) ---

1082 if ((info->vi_planes != 0)
1083 && (info->vi_planes != vesa_vmode[i].vi_planes))
1084 continue;
1085 /* pixel format, memory model */
1086 if ((info->vi_flags != 0)
1087 && (info->vi_flags != vesa_vmode[i].vi_flags))
1088 continue;
1089 *info = vesa_vmode[i];
1211
1212 for (i = 0; vesa_vmode[i].vi_mode != EOT; ++i) {
1213 if ((info->vi_width != 0)
1214 && (info->vi_width != vesa_vmode[i].vi_width))
1215 continue;
1216 if ((info->vi_height != 0)
1217 && (info->vi_height != vesa_vmode[i].vi_height))
1218 continue;

--- 9 unchanged lines hidden (view full) ---

1228 if ((info->vi_planes != 0)
1229 && (info->vi_planes != vesa_vmode[i].vi_planes))
1230 continue;
1231 /* pixel format, memory model */
1232 if ((info->vi_flags != 0)
1233 && (info->vi_flags != vesa_vmode[i].vi_flags))
1234 continue;
1235 *info = vesa_vmode[i];
1090 return 0;
1236 return (0);
1091 }
1237 }
1092 return ENODEV;
1238 return (ENODEV);
1093}
1094
1095static int
1096vesa_set_mode(video_adapter_t *adp, int mode)
1097{
1098 video_info_t info;
1099
1100 if (adp != vesa_adp)
1239}
1240
1241static int
1242vesa_set_mode(video_adapter_t *adp, int mode)
1243{
1244 video_info_t info;
1245
1246 if (adp != vesa_adp)
1101 return (*prevvidsw->set_mode)(adp, mode);
1247 return ((*prevvidsw->set_mode)(adp, mode));
1102
1103 mode = vesa_map_gen_mode_num(adp->va_type,
1104 adp->va_flags & V_ADP_COLOR, mode);
1105#if VESA_DEBUG > 0
1106 printf("VESA: set_mode(): %d(%x) -> %d(%x)\n",
1107 adp->va_mode, adp->va_mode, mode, mode);
1108#endif
1109 /*

--- 14 unchanged lines hidden (view full) ---

1124 * Once (*prevvidsw->get_info)() succeeded,
1125 * (*prevvidsw->set_mode)() below won't fail...
1126 */
1127 }
1128 }
1129
1130 /* we may not need to handle this mode after all... */
1131 if ((*prevvidsw->set_mode)(adp, mode) == 0)
1248
1249 mode = vesa_map_gen_mode_num(adp->va_type,
1250 adp->va_flags & V_ADP_COLOR, mode);
1251#if VESA_DEBUG > 0
1252 printf("VESA: set_mode(): %d(%x) -> %d(%x)\n",
1253 adp->va_mode, adp->va_mode, mode, mode);
1254#endif
1255 /*

--- 14 unchanged lines hidden (view full) ---

1270 * Once (*prevvidsw->get_info)() succeeded,
1271 * (*prevvidsw->set_mode)() below won't fail...
1272 */
1273 }
1274 }
1275
1276 /* we may not need to handle this mode after all... */
1277 if ((*prevvidsw->set_mode)(adp, mode) == 0)
1132 return 0;
1278 return (0);
1133
1134 /* is the new mode supported? */
1135 if (vesa_get_info(adp, mode, &info))
1279
1280 /* is the new mode supported? */
1281 if (vesa_get_info(adp, mode, &info))
1136 return 1;
1282 return (1);
1137 /* assert(VESA_MODE(mode)); */
1138
1139#if VESA_DEBUG > 0
1140 printf("VESA: about to set a VESA mode...\n");
1141#endif
1142 /* don't use the linear frame buffer for text modes. XXX */
1143 if (!(info.vi_flags & V_INFO_GRAPHICS))
1144 info.vi_flags &= ~V_INFO_LINEAR;
1145
1146 if (vesa_bios_set_mode(mode | ((info.vi_flags & V_INFO_LINEAR) ? 0x4000 : 0)))
1283 /* assert(VESA_MODE(mode)); */
1284
1285#if VESA_DEBUG > 0
1286 printf("VESA: about to set a VESA mode...\n");
1287#endif
1288 /* don't use the linear frame buffer for text modes. XXX */
1289 if (!(info.vi_flags & V_INFO_GRAPHICS))
1290 info.vi_flags &= ~V_INFO_LINEAR;
1291
1292 if (vesa_bios_set_mode(mode | ((info.vi_flags & V_INFO_LINEAR) ? 0x4000 : 0)))
1147 return 1;
1293 return (1);
1148
1149 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1150 vesa_unmap_buffer(adp->va_buffer,
1151 vesa_adp_info->v_memsize*64*1024);
1152
1153#if VESA_DEBUG > 0
1154 printf("VESA: mode set!\n");
1155#endif

--- 29 unchanged lines hidden (view full) ---

1185 printf("vesa_set_mode(): vi_width:%d, line_width:%d\n",
1186 info.vi_width, vesa_adp->va_line_width);
1187#endif
1188 bcopy(&info, &vesa_adp->va_info, sizeof(vesa_adp->va_info));
1189
1190 /* move hardware cursor out of the way */
1191 (*vidsw[vesa_adp->va_index]->set_hw_cursor)(vesa_adp, -1, -1);
1192
1294
1295 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1296 vesa_unmap_buffer(adp->va_buffer,
1297 vesa_adp_info->v_memsize*64*1024);
1298
1299#if VESA_DEBUG > 0
1300 printf("VESA: mode set!\n");
1301#endif

--- 29 unchanged lines hidden (view full) ---

1331 printf("vesa_set_mode(): vi_width:%d, line_width:%d\n",
1332 info.vi_width, vesa_adp->va_line_width);
1333#endif
1334 bcopy(&info, &vesa_adp->va_info, sizeof(vesa_adp->va_info));
1335
1336 /* move hardware cursor out of the way */
1337 (*vidsw[vesa_adp->va_index]->set_hw_cursor)(vesa_adp, -1, -1);
1338
1193 return 0;
1339 return (0);
1194}
1195
1196static int
1197vesa_save_font(video_adapter_t *adp, int page, int fontsize, int fontwidth,
1198 u_char *data, int ch, int count)
1199{
1340}
1341
1342static int
1343vesa_save_font(video_adapter_t *adp, int page, int fontsize, int fontwidth,
1344 u_char *data, int ch, int count)
1345{
1200 return (*prevvidsw->save_font)(adp, page, fontsize, fontwidth, data,
1201 ch, count);
1346
1347 return ((*prevvidsw->save_font)(adp, page, fontsize, fontwidth, data,
1348 ch, count));
1202}
1203
1204static int
1205vesa_load_font(video_adapter_t *adp, int page, int fontsize, int fontwidth,
1206 u_char *data, int ch, int count)
1207{
1349}
1350
1351static int
1352vesa_load_font(video_adapter_t *adp, int page, int fontsize, int fontwidth,
1353 u_char *data, int ch, int count)
1354{
1208 return (*prevvidsw->load_font)(adp, page, fontsize, fontwidth, data,
1209 ch, count);
1355
1356 return ((*prevvidsw->load_font)(adp, page, fontsize, fontwidth, data,
1357 ch, count));
1210}
1211
1212static int
1213vesa_show_font(video_adapter_t *adp, int page)
1214{
1358}
1359
1360static int
1361vesa_show_font(video_adapter_t *adp, int page)
1362{
1215 return (*prevvidsw->show_font)(adp, page);
1363
1364 return ((*prevvidsw->show_font)(adp, page));
1216}
1217
1218static int
1219vesa_save_palette(video_adapter_t *adp, u_char *palette)
1220{
1221 int bits;
1222 int error;
1223
1224 if ((adp == vesa_adp) && (vesa_adp_info->v_flags & V_DAC8)
1225 && VESA_MODE(adp->va_mode)) {
1226 bits = vesa_bios_get_dac();
1227 error = vesa_bios_save_palette(0, 256, palette, bits);
1228 if (error == 0)
1365}
1366
1367static int
1368vesa_save_palette(video_adapter_t *adp, u_char *palette)
1369{
1370 int bits;
1371 int error;
1372
1373 if ((adp == vesa_adp) && (vesa_adp_info->v_flags & V_DAC8)
1374 && VESA_MODE(adp->va_mode)) {
1375 bits = vesa_bios_get_dac();
1376 error = vesa_bios_save_palette(0, 256, palette, bits);
1377 if (error == 0)
1229 return 0;
1378 return (0);
1230 if (bits != 6)
1379 if (bits != 6)
1231 return error;
1380 return (error);
1232 }
1233
1381 }
1382
1234 return (*prevvidsw->save_palette)(adp, palette);
1383 return ((*prevvidsw->save_palette)(adp, palette));
1235}
1236
1237static int
1238vesa_load_palette(video_adapter_t *adp, u_char *palette)
1239{
1240#ifdef notyet
1241 int bits;
1242 int error;
1243
1244 if ((adp == vesa_adp) && (vesa_adp_info->v_flags & V_DAC8)
1245 && VESA_MODE(adp->va_mode) && ((bits = vesa_bios_set_dac(8)) > 6)) {
1246 error = vesa_bios_load_palette(0, 256, palette, bits);
1247 if (error == 0)
1384}
1385
1386static int
1387vesa_load_palette(video_adapter_t *adp, u_char *palette)
1388{
1389#ifdef notyet
1390 int bits;
1391 int error;
1392
1393 if ((adp == vesa_adp) && (vesa_adp_info->v_flags & V_DAC8)
1394 && VESA_MODE(adp->va_mode) && ((bits = vesa_bios_set_dac(8)) > 6)) {
1395 error = vesa_bios_load_palette(0, 256, palette, bits);
1396 if (error == 0)
1248 return 0;
1397 return (0);
1249 if (vesa_bios_set_dac(6) != 6)
1398 if (vesa_bios_set_dac(6) != 6)
1250 return 1;
1399 return (1);
1251 }
1252#endif /* notyet */
1253
1400 }
1401#endif /* notyet */
1402
1254 return (*prevvidsw->load_palette)(adp, palette);
1403 return ((*prevvidsw->load_palette)(adp, palette));
1255}
1256
1257static int
1258vesa_set_border(video_adapter_t *adp, int color)
1259{
1404}
1405
1406static int
1407vesa_set_border(video_adapter_t *adp, int color)
1408{
1260 return (*prevvidsw->set_border)(adp, color);
1409
1410 return ((*prevvidsw->set_border)(adp, color));
1261}
1262
1263static int
1264vesa_save_state(video_adapter_t *adp, void *p, size_t size)
1265{
1411}
1412
1413static int
1414vesa_save_state(video_adapter_t *adp, void *p, size_t size)
1415{
1416
1266 if (adp != vesa_adp)
1417 if (adp != vesa_adp)
1267 return (*prevvidsw->save_state)(adp, p, size);
1418 return ((*prevvidsw->save_state)(adp, p, size));
1268
1269 if (vesa_state_buf_size == 0)
1270 vesa_state_buf_size = vesa_bios_state_buf_size();
1271 if (size == 0)
1272 return (sizeof(int) + vesa_state_buf_size);
1273 else if (size < (sizeof(int) + vesa_state_buf_size))
1419
1420 if (vesa_state_buf_size == 0)
1421 vesa_state_buf_size = vesa_bios_state_buf_size();
1422 if (size == 0)
1423 return (sizeof(int) + vesa_state_buf_size);
1424 else if (size < (sizeof(int) + vesa_state_buf_size))
1274 return 1;
1425 return (1);
1275
1276 ((adp_state_t *)p)->sig = V_STATE_SIG;
1277 bzero(((adp_state_t *)p)->regs, vesa_state_buf_size);
1426
1427 ((adp_state_t *)p)->sig = V_STATE_SIG;
1428 bzero(((adp_state_t *)p)->regs, vesa_state_buf_size);
1278 return vesa_bios_save_restore(STATE_SAVE, ((adp_state_t *)p)->regs,
1279 vesa_state_buf_size);
1429 return (vesa_bios_save_restore(STATE_SAVE, ((adp_state_t *)p)->regs,
1430 vesa_state_buf_size));
1280}
1281
1282static int
1283vesa_load_state(video_adapter_t *adp, void *p)
1284{
1431}
1432
1433static int
1434vesa_load_state(video_adapter_t *adp, void *p)
1435{
1436 int flags, mode, ret;
1437
1285 if ((adp != vesa_adp) || (((adp_state_t *)p)->sig != V_STATE_SIG))
1438 if ((adp != vesa_adp) || (((adp_state_t *)p)->sig != V_STATE_SIG))
1286 return (*prevvidsw->load_state)(adp, p);
1439 return ((*prevvidsw->load_state)(adp, p));
1287
1440
1288 return vesa_bios_save_restore(STATE_LOAD, ((adp_state_t *)p)->regs,
1289 vesa_state_buf_size);
1441 ret = vesa_bios_save_restore(STATE_LOAD, ((adp_state_t *)p)->regs,
1442 vesa_state_buf_size);
1443
1444 /*
1445 * If the current mode is not restored properly, try BIOS POST and
1446 * force setting the mode.
1447 */
1448 flags = adp->va_info.vi_flags;
1449 if (!(flags & V_INFO_GRAPHICS))
1450 flags &= ~V_INFO_LINEAR;
1451 mode = adp->va_mode | ((flags & V_INFO_LINEAR) ? 0x4000 : 0);
1452 if (vesa_bios_get_current_mode() != mode && vesa_bios_post() == 0 &&
1453 x86bios_get_intr(0x10) != 0) {
1454 int10_set_mode(adp->va_initial_bios_mode);
1455 vesa_bios_set_mode(mode);
1456 }
1457 return (ret);
1290}
1291
1292#if 0
1293static int
1294vesa_get_origin(video_adapter_t *adp, off_t *offset)
1295{
1296 x86regs_t regs;
1297
1458}
1459
1460#if 0
1461static int
1462vesa_get_origin(video_adapter_t *adp, off_t *offset)
1463{
1464 x86regs_t regs;
1465
1298 bzero(&regs, sizeof(regs));
1299 regs.R_EAX = 0x4f05;
1300 regs.R_EBX = 0x10;
1466 x86bios_init_regs(&regs);
1467 regs.R_AX = 0x4f05;
1468 regs.R_BL = 0x10;
1301
1302 x86bios_intr(&regs, 0x10);
1303
1469
1470 x86bios_intr(&regs, 0x10);
1471
1304 if ((regs.R_AX & 0xff) != 0x4f)
1305 return 1;
1472 if (regs.R_AX != 0x004f)
1473 return (1);
1306 *offset = regs.DX * adp->va_window_gran;
1307
1474 *offset = regs.DX * adp->va_window_gran;
1475
1308 return 0;
1476 return (0);
1309}
1310#endif
1311
1312static int
1313vesa_set_origin(video_adapter_t *adp, off_t offset)
1314{
1315 x86regs_t regs;
1316
1317 /*
1318 * This function should return as quickly as possible to
1319 * maintain good performance of the system. For this reason,
1320 * error checking is kept minimal and let the VESA BIOS to
1321 * detect error.
1322 */
1323 if (adp != vesa_adp)
1477}
1478#endif
1479
1480static int
1481vesa_set_origin(video_adapter_t *adp, off_t offset)
1482{
1483 x86regs_t regs;
1484
1485 /*
1486 * This function should return as quickly as possible to
1487 * maintain good performance of the system. For this reason,
1488 * error checking is kept minimal and let the VESA BIOS to
1489 * detect error.
1490 */
1491 if (adp != vesa_adp)
1324 return (*prevvidsw->set_win_org)(adp, offset);
1492 return ((*prevvidsw->set_win_org)(adp, offset));
1325
1326 /* if this is a linear frame buffer, do nothing */
1327 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1493
1494 /* if this is a linear frame buffer, do nothing */
1495 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1328 return 0;
1496 return (0);
1329 /* XXX */
1330 if (adp->va_window_gran == 0)
1497 /* XXX */
1498 if (adp->va_window_gran == 0)
1331 return 1;
1499 return (1);
1332
1500
1333 bzero(&regs, sizeof(regs));
1334 regs.R_EAX = 0x4f05;
1335 regs.R_EBX = 0;
1336 regs.R_EDX = offset / adp->va_window_gran;
1501 x86bios_init_regs(&regs);
1502 regs.R_AX = 0x4f05;
1503 regs.R_DX = offset / adp->va_window_gran;
1504
1337 x86bios_intr(&regs, 0x10);
1338
1505 x86bios_intr(&regs, 0x10);
1506
1339 if ((regs.R_AX & 0xff) != 0x4f)
1340 return 1;
1507 if (regs.R_AX != 0x004f)
1508 return (1);
1341
1509
1342 bzero(&regs, sizeof(regs));
1343 regs.R_EAX = 0x4f05;
1344 regs.R_EBX = 1;
1345 regs.R_EDX = offset / adp->va_window_gran;
1510 x86bios_init_regs(&regs);
1511 regs.R_AX = 0x4f05;
1512 regs.R_BL = 1;
1513 regs.R_DX = offset / adp->va_window_gran;
1346 x86bios_intr(&regs, 0x10);
1347
1348 adp->va_window_orig = (offset/adp->va_window_gran)*adp->va_window_gran;
1514 x86bios_intr(&regs, 0x10);
1515
1516 adp->va_window_orig = (offset/adp->va_window_gran)*adp->va_window_gran;
1349 return 0; /* XXX */
1517 return (0); /* XXX */
1350}
1351
1352static int
1353vesa_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
1354{
1518}
1519
1520static int
1521vesa_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
1522{
1355 return (*prevvidsw->read_hw_cursor)(adp, col, row);
1523
1524 return ((*prevvidsw->read_hw_cursor)(adp, col, row));
1356}
1357
1358static int
1359vesa_set_hw_cursor(video_adapter_t *adp, int col, int row)
1360{
1525}
1526
1527static int
1528vesa_set_hw_cursor(video_adapter_t *adp, int col, int row)
1529{
1361 return (*prevvidsw->set_hw_cursor)(adp, col, row);
1530
1531 return ((*prevvidsw->set_hw_cursor)(adp, col, row));
1362}
1363
1364static int
1365vesa_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
1366 int celsize, int blink)
1367{
1532}
1533
1534static int
1535vesa_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
1536 int celsize, int blink)
1537{
1368 return (*prevvidsw->set_hw_cursor_shape)(adp, base, height, celsize,
1369 blink);
1538
1539 return ((*prevvidsw->set_hw_cursor_shape)(adp, base, height, celsize,
1540 blink));
1370}
1371
1372static int
1373vesa_blank_display(video_adapter_t *adp, int mode)
1374{
1541}
1542
1543static int
1544vesa_blank_display(video_adapter_t *adp, int mode)
1545{
1546
1375 /* XXX: use VESA DPMS */
1547 /* XXX: use VESA DPMS */
1376 return (*prevvidsw->blank_display)(adp, mode);
1548 return ((*prevvidsw->blank_display)(adp, mode));
1377}
1378
1379static int
1380vesa_mmap(video_adapter_t *adp, vm_offset_t offset, vm_paddr_t *paddr,
1381 int prot)
1382{
1549}
1550
1551static int
1552vesa_mmap(video_adapter_t *adp, vm_offset_t offset, vm_paddr_t *paddr,
1553 int prot)
1554{
1555
1383#if VESA_DEBUG > 0
1384 printf("vesa_mmap(): window:0x%tx, buffer:0x%tx, offset:0x%tx\n",
1385 adp->va_info.vi_window, adp->va_info.vi_buffer, offset);
1386#endif
1387
1556#if VESA_DEBUG > 0
1557 printf("vesa_mmap(): window:0x%tx, buffer:0x%tx, offset:0x%tx\n",
1558 adp->va_info.vi_window, adp->va_info.vi_buffer, offset);
1559#endif
1560
1388 if ((adp == vesa_adp) && (adp->va_info.vi_flags & V_INFO_LINEAR)) {
1561 if ((adp == vesa_adp) &&
1562 (adp->va_info.vi_flags & V_INFO_LINEAR) != 0) {
1389 /* va_window_size == va_buffer_size/vi_planes */
1390 /* XXX: is this correct? */
1391 if (offset > adp->va_window_size - PAGE_SIZE)
1563 /* va_window_size == va_buffer_size/vi_planes */
1564 /* XXX: is this correct? */
1565 if (offset > adp->va_window_size - PAGE_SIZE)
1392 return -1;
1566 return (-1);
1393 *paddr = adp->va_info.vi_buffer + offset;
1567 *paddr = adp->va_info.vi_buffer + offset;
1394 return 0;
1395 } else {
1396 return (*prevvidsw->mmap)(adp, offset, paddr, prot);
1568 return (0);
1397 }
1569 }
1570 return ((*prevvidsw->mmap)(adp, offset, paddr, prot));
1398}
1399
1400static int
1401vesa_clear(video_adapter_t *adp)
1402{
1571}
1572
1573static int
1574vesa_clear(video_adapter_t *adp)
1575{
1403 return (*prevvidsw->clear)(adp);
1576
1577 return ((*prevvidsw->clear)(adp));
1404}
1405
1406static int
1407vesa_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
1408{
1578}
1579
1580static int
1581vesa_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
1582{
1409 return (*prevvidsw->fill_rect)(adp, val, x, y, cx, cy);
1583
1584 return ((*prevvidsw->fill_rect)(adp, val, x, y, cx, cy));
1410}
1411
1412static int
1413vesa_bitblt(video_adapter_t *adp,...)
1414{
1585}
1586
1587static int
1588vesa_bitblt(video_adapter_t *adp,...)
1589{
1590
1415 /* FIXME */
1591 /* FIXME */
1416 return 1;
1592 return (1);
1417}
1418
1419static int
1420get_palette(video_adapter_t *adp, int base, int count,
1421 u_char *red, u_char *green, u_char *blue, u_char *trans)
1422{
1423 u_char *r;
1424 u_char *g;
1425 u_char *b;
1426 int bits;
1427 int error;
1428
1429 if ((base < 0) || (base >= 256) || (count < 0) || (count > 256))
1593}
1594
1595static int
1596get_palette(video_adapter_t *adp, int base, int count,
1597 u_char *red, u_char *green, u_char *blue, u_char *trans)
1598{
1599 u_char *r;
1600 u_char *g;
1601 u_char *b;
1602 int bits;
1603 int error;
1604
1605 if ((base < 0) || (base >= 256) || (count < 0) || (count > 256))
1430 return 1;
1606 return (1);
1431 if ((base + count) > 256)
1607 if ((base + count) > 256)
1432 return 1;
1608 return (1);
1433 if (!(vesa_adp_info->v_flags & V_DAC8) || !VESA_MODE(adp->va_mode))
1609 if (!(vesa_adp_info->v_flags & V_DAC8) || !VESA_MODE(adp->va_mode))
1434 return 1;
1610 return (1);
1435
1436 bits = vesa_bios_get_dac();
1437 if (bits <= 6)
1611
1612 bits = vesa_bios_get_dac();
1613 if (bits <= 6)
1438 return 1;
1614 return (1);
1439
1440 r = malloc(count*3, M_DEVBUF, M_WAITOK);
1441 g = r + count;
1442 b = g + count;
1443 error = vesa_bios_save_palette2(base, count, r, g, b, bits);
1444 if (error == 0) {
1445 copyout(r, red, count);
1446 copyout(g, green, count);
1447 copyout(b, blue, count);
1448 if (trans != NULL) {
1449 bzero(r, count);
1450 copyout(r, trans, count);
1451 }
1452 }
1453 free(r, M_DEVBUF);
1454
1455 /* if error && bits != 6 at this point, we are in trouble... XXX */
1615
1616 r = malloc(count*3, M_DEVBUF, M_WAITOK);
1617 g = r + count;
1618 b = g + count;
1619 error = vesa_bios_save_palette2(base, count, r, g, b, bits);
1620 if (error == 0) {
1621 copyout(r, red, count);
1622 copyout(g, green, count);
1623 copyout(b, blue, count);
1624 if (trans != NULL) {
1625 bzero(r, count);
1626 copyout(r, trans, count);
1627 }
1628 }
1629 free(r, M_DEVBUF);
1630
1631 /* if error && bits != 6 at this point, we are in trouble... XXX */
1456 return error;
1632 return (error);
1457}
1458
1459static int
1460set_palette(video_adapter_t *adp, int base, int count,
1461 u_char *red, u_char *green, u_char *blue, u_char *trans)
1462{
1633}
1634
1635static int
1636set_palette(video_adapter_t *adp, int base, int count,
1637 u_char *red, u_char *green, u_char *blue, u_char *trans)
1638{
1463 return 1;
1639 return (1);
1464#ifdef notyet
1465 u_char *r;
1466 u_char *g;
1467 u_char *b;
1468 int bits;
1469 int error;
1470
1471 if ((base < 0) || (base >= 256) || (base + count > 256))
1640#ifdef notyet
1641 u_char *r;
1642 u_char *g;
1643 u_char *b;
1644 int bits;
1645 int error;
1646
1647 if ((base < 0) || (base >= 256) || (base + count > 256))
1472 return 1;
1648 return (1);
1473 if (!(vesa_adp_info->v_flags & V_DAC8) || !VESA_MODE(adp->va_mode)
1474 || ((bits = vesa_bios_set_dac(8)) <= 6))
1649 if (!(vesa_adp_info->v_flags & V_DAC8) || !VESA_MODE(adp->va_mode)
1650 || ((bits = vesa_bios_set_dac(8)) <= 6))
1475 return 1;
1651 return (1);
1476
1477 r = malloc(count*3, M_DEVBUF, M_WAITOK);
1478 g = r + count;
1479 b = g + count;
1480 copyin(red, r, count);
1481 copyin(green, g, count);
1482 copyin(blue, b, count);
1483
1484 error = vesa_bios_load_palette2(base, count, r, g, b, bits);
1485 free(r, M_DEVBUF);
1486 if (error == 0)
1652
1653 r = malloc(count*3, M_DEVBUF, M_WAITOK);
1654 g = r + count;
1655 b = g + count;
1656 copyin(red, r, count);
1657 copyin(green, g, count);
1658 copyin(blue, b, count);
1659
1660 error = vesa_bios_load_palette2(base, count, r, g, b, bits);
1661 free(r, M_DEVBUF);
1662 if (error == 0)
1487 return 0;
1663 return (0);
1488
1489 /* if the following call fails, we are in trouble... XXX */
1490 vesa_bios_set_dac(6);
1664
1665 /* if the following call fails, we are in trouble... XXX */
1666 vesa_bios_set_dac(6);
1491 return 1;
1667 return (1);
1492#endif /* notyet */
1493}
1494
1495static int
1496vesa_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
1497{
1498 int bytes;
1499
1500 if (adp != vesa_adp)
1668#endif /* notyet */
1669}
1670
1671static int
1672vesa_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
1673{
1674 int bytes;
1675
1676 if (adp != vesa_adp)
1501 return (*prevvidsw->ioctl)(adp, cmd, arg);
1677 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1502
1503 switch (cmd) {
1504 case FBIO_SETWINORG: /* set frame buffer window origin */
1505 if (!VESA_MODE(adp->va_mode))
1506 return (*prevvidsw->ioctl)(adp, cmd, arg);
1507 return (vesa_set_origin(adp, *(off_t *)arg) ? ENODEV : 0);
1508
1509 case FBIO_SETDISPSTART: /* set display start address */
1510 if (!VESA_MODE(adp->va_mode))
1678
1679 switch (cmd) {
1680 case FBIO_SETWINORG: /* set frame buffer window origin */
1681 if (!VESA_MODE(adp->va_mode))
1682 return (*prevvidsw->ioctl)(adp, cmd, arg);
1683 return (vesa_set_origin(adp, *(off_t *)arg) ? ENODEV : 0);
1684
1685 case FBIO_SETDISPSTART: /* set display start address */
1686 if (!VESA_MODE(adp->va_mode))
1511 return (*prevvidsw->ioctl)(adp, cmd, arg);
1687 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1512 if (vesa_bios_set_start(((video_display_start_t *)arg)->x,
1513 ((video_display_start_t *)arg)->y))
1688 if (vesa_bios_set_start(((video_display_start_t *)arg)->x,
1689 ((video_display_start_t *)arg)->y))
1514 return ENODEV;
1690 return (ENODEV);
1515 adp->va_disp_start.x = ((video_display_start_t *)arg)->x;
1516 adp->va_disp_start.y = ((video_display_start_t *)arg)->y;
1691 adp->va_disp_start.x = ((video_display_start_t *)arg)->x;
1692 adp->va_disp_start.y = ((video_display_start_t *)arg)->y;
1517 return 0;
1693 return (0);
1518
1519 case FBIO_SETLINEWIDTH: /* set line length in pixel */
1520 if (!VESA_MODE(adp->va_mode))
1694
1695 case FBIO_SETLINEWIDTH: /* set line length in pixel */
1696 if (!VESA_MODE(adp->va_mode))
1521 return (*prevvidsw->ioctl)(adp, cmd, arg);
1697 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1522 if (vesa_bios_set_line_length(*(u_int *)arg, &bytes, NULL))
1698 if (vesa_bios_set_line_length(*(u_int *)arg, &bytes, NULL))
1523 return ENODEV;
1699 return (ENODEV);
1524 adp->va_line_width = bytes;
1525#if VESA_DEBUG > 1
1526 printf("new line width:%d\n", adp->va_line_width);
1527#endif
1700 adp->va_line_width = bytes;
1701#if VESA_DEBUG > 1
1702 printf("new line width:%d\n", adp->va_line_width);
1703#endif
1528 return 0;
1704 return (0);
1529
1530 case FBIO_GETPALETTE: /* get color palette */
1531 if (get_palette(adp, ((video_color_palette_t *)arg)->index,
1532 ((video_color_palette_t *)arg)->count,
1533 ((video_color_palette_t *)arg)->red,
1534 ((video_color_palette_t *)arg)->green,
1535 ((video_color_palette_t *)arg)->blue,
1536 ((video_color_palette_t *)arg)->transparent))
1705
1706 case FBIO_GETPALETTE: /* get color palette */
1707 if (get_palette(adp, ((video_color_palette_t *)arg)->index,
1708 ((video_color_palette_t *)arg)->count,
1709 ((video_color_palette_t *)arg)->red,
1710 ((video_color_palette_t *)arg)->green,
1711 ((video_color_palette_t *)arg)->blue,
1712 ((video_color_palette_t *)arg)->transparent))
1537 return (*prevvidsw->ioctl)(adp, cmd, arg);
1538 return 0;
1713 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1714 return (0);
1539
1540
1541 case FBIO_SETPALETTE: /* set color palette */
1542 if (set_palette(adp, ((video_color_palette_t *)arg)->index,
1543 ((video_color_palette_t *)arg)->count,
1544 ((video_color_palette_t *)arg)->red,
1545 ((video_color_palette_t *)arg)->green,
1546 ((video_color_palette_t *)arg)->blue,
1547 ((video_color_palette_t *)arg)->transparent))
1715
1716
1717 case FBIO_SETPALETTE: /* set color palette */
1718 if (set_palette(adp, ((video_color_palette_t *)arg)->index,
1719 ((video_color_palette_t *)arg)->count,
1720 ((video_color_palette_t *)arg)->red,
1721 ((video_color_palette_t *)arg)->green,
1722 ((video_color_palette_t *)arg)->blue,
1723 ((video_color_palette_t *)arg)->transparent))
1548 return (*prevvidsw->ioctl)(adp, cmd, arg);
1549 return 0;
1724 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1725 return (0);
1550
1551 case FBIOGETCMAP: /* get color palette */
1552 if (get_palette(adp, ((struct fbcmap *)arg)->index,
1553 ((struct fbcmap *)arg)->count,
1554 ((struct fbcmap *)arg)->red,
1555 ((struct fbcmap *)arg)->green,
1556 ((struct fbcmap *)arg)->blue, NULL))
1726
1727 case FBIOGETCMAP: /* get color palette */
1728 if (get_palette(adp, ((struct fbcmap *)arg)->index,
1729 ((struct fbcmap *)arg)->count,
1730 ((struct fbcmap *)arg)->red,
1731 ((struct fbcmap *)arg)->green,
1732 ((struct fbcmap *)arg)->blue, NULL))
1557 return (*prevvidsw->ioctl)(adp, cmd, arg);
1558 return 0;
1733 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1734 return (0);
1559
1560 case FBIOPUTCMAP: /* set color palette */
1561 if (set_palette(adp, ((struct fbcmap *)arg)->index,
1562 ((struct fbcmap *)arg)->count,
1563 ((struct fbcmap *)arg)->red,
1564 ((struct fbcmap *)arg)->green,
1565 ((struct fbcmap *)arg)->blue, NULL))
1735
1736 case FBIOPUTCMAP: /* set color palette */
1737 if (set_palette(adp, ((struct fbcmap *)arg)->index,
1738 ((struct fbcmap *)arg)->count,
1739 ((struct fbcmap *)arg)->red,
1740 ((struct fbcmap *)arg)->green,
1741 ((struct fbcmap *)arg)->blue, NULL))
1566 return (*prevvidsw->ioctl)(adp, cmd, arg);
1567 return 0;
1742 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1743 return (0);
1568
1569 default:
1744
1745 default:
1570 return (*prevvidsw->ioctl)(adp, cmd, arg);
1746 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1571 }
1572}
1573
1574static int
1575vesa_diag(video_adapter_t *adp, int level)
1576{
1577 int error;
1578
1579 /* call the previous handler first */
1580 error = (*prevvidsw->diag)(adp, level);
1581 if (error)
1747 }
1748}
1749
1750static int
1751vesa_diag(video_adapter_t *adp, int level)
1752{
1753 int error;
1754
1755 /* call the previous handler first */
1756 error = (*prevvidsw->diag)(adp, level);
1757 if (error)
1582 return error;
1758 return (error);
1583
1584 if (adp != vesa_adp)
1759
1760 if (adp != vesa_adp)
1585 return 1;
1761 return (1);
1586
1587 if (level <= 0)
1762
1763 if (level <= 0)
1588 return 0;
1764 return (0);
1589
1765
1590 return 0;
1766 return (0);
1591}
1592
1593static int
1594vesa_bios_info(int level)
1595{
1596#if VESA_DEBUG > 1
1597 struct vesa_mode vmode;
1598 int i;
1599#endif
1767}
1768
1769static int
1770vesa_bios_info(int level)
1771{
1772#if VESA_DEBUG > 1
1773 struct vesa_mode vmode;
1774 int i;
1775#endif
1776 uint16_t vers;
1600
1777
1778 vers = vesa_adp_info->v_version;
1779
1601 if (bootverbose) {
1602 /* general adapter information */
1603 printf(
1604 "VESA: v%d.%d, %dk memory, flags:0x%x, mode table:%p (%x)\n",
1780 if (bootverbose) {
1781 /* general adapter information */
1782 printf(
1783 "VESA: v%d.%d, %dk memory, flags:0x%x, mode table:%p (%x)\n",
1605 ((vesa_adp_info->v_version & 0xf000) >> 12) * 10 +
1606 ((vesa_adp_info->v_version & 0x0f00) >> 8),
1607 ((vesa_adp_info->v_version & 0x00f0) >> 4) * 10 +
1608 (vesa_adp_info->v_version & 0x000f),
1784 (vers >> 12) * 10 + ((vers & 0x0f00) >> 8),
1785 ((vers & 0x00f0) >> 4) * 10 + (vers & 0x000f),
1609 vesa_adp_info->v_memsize * 64, vesa_adp_info->v_flags,
1610 vesa_vmodetab, vesa_adp_info->v_modetable);
1611
1612 /* OEM string */
1613 if (vesa_oemstr != NULL)
1614 printf("VESA: %s\n", vesa_oemstr);
1615 }
1616
1617 if (level <= 0)
1786 vesa_adp_info->v_memsize * 64, vesa_adp_info->v_flags,
1787 vesa_vmodetab, vesa_adp_info->v_modetable);
1788
1789 /* OEM string */
1790 if (vesa_oemstr != NULL)
1791 printf("VESA: %s\n", vesa_oemstr);
1792 }
1793
1794 if (level <= 0)
1618 return 0;
1795 return (0);
1619
1796
1620 if (vesa_adp_info->v_version >= 0x0200 && bootverbose) {
1797 if (vers >= 0x0200 && bootverbose) {
1621 /* vender name, product name, product revision */
1622 printf("VESA: %s %s %s\n",
1623 (vesa_venderstr != NULL) ? vesa_venderstr : "unknown",
1624 (vesa_prodstr != NULL) ? vesa_prodstr : "unknown",
1625 (vesa_revstr != NULL) ? vesa_revstr : "?");
1626 }
1627
1628#if VESA_DEBUG > 1

--- 30 unchanged lines hidden (view full) ---

1659 printf("VESA: window A:0x%x (%x), window B:0x%x (%x), ",
1660 vmode.v_waseg, vmode.v_waattr,
1661 vmode.v_wbseg, vmode.v_wbattr);
1662 printf("size:%dk, gran:%dk\n",
1663 vmode.v_wsize, vmode.v_wgran);
1664 }
1665#endif /* VESA_DEBUG > 1 */
1666
1798 /* vender name, product name, product revision */
1799 printf("VESA: %s %s %s\n",
1800 (vesa_venderstr != NULL) ? vesa_venderstr : "unknown",
1801 (vesa_prodstr != NULL) ? vesa_prodstr : "unknown",
1802 (vesa_revstr != NULL) ? vesa_revstr : "?");
1803 }
1804
1805#if VESA_DEBUG > 1

--- 30 unchanged lines hidden (view full) ---

1836 printf("VESA: window A:0x%x (%x), window B:0x%x (%x), ",
1837 vmode.v_waseg, vmode.v_waattr,
1838 vmode.v_wbseg, vmode.v_wbattr);
1839 printf("size:%dk, gran:%dk\n",
1840 vmode.v_wsize, vmode.v_wgran);
1841 }
1842#endif /* VESA_DEBUG > 1 */
1843
1667 return 0;
1844 return (0);
1668}
1669
1670/* module loading */
1671
1672static int
1673vesa_load(void)
1674{
1675 int error;
1676 int s;
1677
1678 if (vesa_init_done)
1845}
1846
1847/* module loading */
1848
1849static int
1850vesa_load(void)
1851{
1852 int error;
1853 int s;
1854
1855 if (vesa_init_done)
1679 return 0;
1856 return (0);
1680
1681 /* locate a VGA adapter */
1682 s = spltty();
1683 vesa_adp = NULL;
1684 error = vesa_configure(0);
1685 splx(s);
1686
1687 if (error == 0)
1688 vesa_bios_info(bootverbose);
1689
1857
1858 /* locate a VGA adapter */
1859 s = spltty();
1860 vesa_adp = NULL;
1861 error = vesa_configure(0);
1862 splx(s);
1863
1864 if (error == 0)
1865 vesa_bios_info(bootverbose);
1866
1690 return error;
1867 return (error);
1691}
1692
1693static int
1694vesa_unload(void)
1695{
1696 u_char palette[256*3];
1697 int error;
1698 int bits;
1699 int s;
1700
1701 /* if the adapter is currently in a VESA mode, don't unload */
1702 if ((vesa_adp != NULL) && VESA_MODE(vesa_adp->va_mode))
1868}
1869
1870static int
1871vesa_unload(void)
1872{
1873 u_char palette[256*3];
1874 int error;
1875 int bits;
1876 int s;
1877
1878 /* if the adapter is currently in a VESA mode, don't unload */
1879 if ((vesa_adp != NULL) && VESA_MODE(vesa_adp->va_mode))
1703 return EBUSY;
1880 return (EBUSY);
1704 /*
1705 * FIXME: if there is at least one vty which is in a VESA mode,
1706 * we shouldn't be unloading! XXX
1707 */
1708
1709 s = spltty();
1710 if ((error = vesa_unload_ioctl()) == 0) {
1711 if (vesa_adp != NULL) {

--- 8 unchanged lines hidden (view full) ---

1720 }
1721 }
1722 vesa_adp->va_flags &= ~V_ADP_VESA;
1723 vidsw[vesa_adp->va_index] = prevvidsw;
1724 }
1725 }
1726 splx(s);
1727
1881 /*
1882 * FIXME: if there is at least one vty which is in a VESA mode,
1883 * we shouldn't be unloading! XXX
1884 */
1885
1886 s = spltty();
1887 if ((error = vesa_unload_ioctl()) == 0) {
1888 if (vesa_adp != NULL) {

--- 8 unchanged lines hidden (view full) ---

1897 }
1898 }
1899 vesa_adp->va_flags &= ~V_ADP_VESA;
1900 vidsw[vesa_adp->va_index] = prevvidsw;
1901 }
1902 }
1903 splx(s);
1904
1728 return error;
1905 if (vesa_oemstr != NULL)
1906 free(vesa_oemstr, M_DEVBUF);
1907 if (vesa_venderstr != NULL)
1908 free(vesa_venderstr, M_DEVBUF);
1909 if (vesa_prodstr != NULL)
1910 free(vesa_prodstr, M_DEVBUF);
1911 if (vesa_revstr != NULL)
1912 free(vesa_revstr, M_DEVBUF);
1913 if (vesa_vmode != &vesa_vmode_empty)
1914 free(vesa_vmode, M_DEVBUF);
1915 return (error);
1729}
1730
1731static int
1732vesa_mod_event(module_t mod, int type, void *data)
1733{
1916}
1917
1918static int
1919vesa_mod_event(module_t mod, int type, void *data)
1920{
1921
1734 switch (type) {
1735 case MOD_LOAD:
1922 switch (type) {
1923 case MOD_LOAD:
1736 return vesa_load();
1924 return (vesa_load());
1737 case MOD_UNLOAD:
1925 case MOD_UNLOAD:
1738 return vesa_unload();
1739 default:
1740 return EOPNOTSUPP;
1926 return (vesa_unload());
1741 }
1927 }
1742 return 0;
1928 return (EOPNOTSUPP);
1743}
1744
1745static moduledata_t vesa_mod = {
1746 "vesa",
1747 vesa_mod_event,
1748 NULL,
1749};
1750
1751DECLARE_MODULE(vesa, vesa_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
1752MODULE_DEPEND(vesa, x86bios, 1, 1, 1);
1753
1754#endif /* VGA_NO_MODE_CHANGE */
1929}
1930
1931static moduledata_t vesa_mod = {
1932 "vesa",
1933 vesa_mod_event,
1934 NULL,
1935};
1936
1937DECLARE_MODULE(vesa, vesa_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
1938MODULE_DEPEND(vesa, x86bios, 1, 1, 1);
1939
1940#endif /* VGA_NO_MODE_CHANGE */