svn commit: r233581 - stable/9/sys/dev/fb
Jung-uk Kim
jkim at FreeBSD.org
Tue Mar 27 23:59:49 UTC 2012
Author: jkim
Date: Tue Mar 27 23:59:48 2012
New Revision: 233581
URL: http://svn.freebsd.org/changeset/base/233581
Log:
MFC: r233042, r233054, r233056, r233187
- Do not unnecessarily clear display memory when switching modes.
- Remove unnecessary static variable initializations and duplicate codes.
- Consistently use bcopy(9) over memcpy(9).
- Save and restore linear frame buffer between suspend and resume.
Modified:
stable/9/sys/dev/fb/vesa.c
Directory Properties:
stable/9/sys/ (props changed)
Modified: stable/9/sys/dev/fb/vesa.c
==============================================================================
--- stable/9/sys/dev/fb/vesa.c Tue Mar 27 23:43:01 2012 (r233580)
+++ stable/9/sys/dev/fb/vesa.c Tue Mar 27 23:59:48 2012 (r233581)
@@ -81,23 +81,25 @@ typedef struct adp_state adp_state_t;
static struct mtx vesa_lock;
static int vesa_state;
-static void *vesa_state_buf = NULL;
-static uint32_t vesa_state_buf_offs = 0;
-static ssize_t vesa_state_buf_size = 0;
-
-static u_char *vesa_palette = NULL;
-static uint32_t vesa_palette_offs = 0;
-
-static void *vesa_bios = NULL;
-static uint32_t vesa_bios_offs = VESA_BIOS_OFFSET;
-static uint32_t vesa_bios_int10 = 0;
-static size_t vesa_bios_size = 0;
+static void *vesa_state_buf;
+static uint32_t vesa_state_buf_offs;
+static ssize_t vesa_state_buf_size;
+
+static u_char *vesa_palette;
+static uint32_t vesa_palette_offs;
+
+static void *vesa_vmem_buf;
+
+static void *vesa_bios;
+static uint32_t vesa_bios_offs;
+static uint32_t vesa_bios_int10;
+static size_t vesa_bios_size;
/* VESA video adapter */
-static video_adapter_t *vesa_adp = NULL;
+static video_adapter_t *vesa_adp;
SYSCTL_NODE(_debug, OID_AUTO, vesa, CTLFLAG_RD, NULL, "VESA debugging");
-static int vesa_shadow_rom = 0;
+static int vesa_shadow_rom;
TUNABLE_INT("debug.vesa.shadow_rom", &vesa_shadow_rom);
SYSCTL_INT(_debug_vesa, OID_AUTO, shadow_rom, CTLFLAG_RDTUN, &vesa_shadow_rom,
0, "Enable video BIOS shadow");
@@ -171,18 +173,16 @@ static video_switch_t *prevvidsw;
#define MODE_TABLE_DELTA 8
-static int vesa_vmode_max = 0;
-static video_info_t vesa_vmode_empty = { EOT };
-static video_info_t *vesa_vmode = &vesa_vmode_empty;
-
-static int vesa_init_done = FALSE;
-static int has_vesa_bios = FALSE;
-static struct vesa_info *vesa_adp_info = NULL;
-static u_int16_t *vesa_vmodetab = NULL;
-static char *vesa_oemstr = NULL;
-static char *vesa_venderstr = NULL;
-static char *vesa_prodstr = NULL;
-static char *vesa_revstr = NULL;
+static int vesa_vmode_max;
+static video_info_t *vesa_vmode;
+
+static int vesa_init_done;
+static struct vesa_info *vesa_adp_info;
+static u_int16_t *vesa_vmodetab;
+static char *vesa_oemstr;
+static char *vesa_venderstr;
+static char *vesa_prodstr;
+static char *vesa_revstr;
/* local macros and functions */
#define BIOS_SADDRTOLADDR(p) ((((p) & 0xffff0000) >> 12) + ((p) & 0x0000ffff))
@@ -221,6 +221,7 @@ static int vesa_translate_flags(u_int16_
static int vesa_translate_mmodel(u_int8_t vmodel);
static int vesa_get_bpscanline(struct vesa_mode *vmode);
static int vesa_bios_init(void);
+static void vesa_bios_uninit(void);
static void vesa_clear_modes(video_info_t *info, int color);
#if 0
@@ -773,11 +774,7 @@ vesa_bios_init(void)
if (vesa_init_done)
return (0);
- has_vesa_bios = FALSE;
- vesa_adp_info = NULL;
vesa_bios_offs = VESA_BIOS_OFFSET;
- vesa_vmode_max = 0;
- vesa_vmode[0].vi_mode = EOT;
/*
* If the VBE real mode interrupt vector is not found, try BIOS POST.
@@ -804,7 +801,7 @@ vesa_bios_init(void)
vesa_bios_size > (vesa_bios_int10 & 0xffff)) {
vesa_bios = x86bios_alloc(&vesa_bios_offs,
vesa_bios_size, M_WAITOK);
- memcpy(vesa_bios, vbios, vesa_bios_size);
+ bcopy(vbios, vesa_bios, vesa_bios_size);
offs = ((vesa_bios_offs << 12) & 0xffff0000) +
(vesa_bios_int10 & 0xffff);
x86bios_set_intr(0x10, offs);
@@ -1030,8 +1027,7 @@ vesa_bios_init(void)
if (bootverbose)
printf("VESA: %d mode(s) found\n", modes);
- has_vesa_bios = (modes > 0);
- if (!has_vesa_bios)
+ if (modes == 0)
goto fail;
x86bios_free(vmbuf, sizeof(*buf));
@@ -1052,14 +1048,21 @@ vesa_bios_init(void)
return (0);
fail:
+ x86bios_free(vmbuf, sizeof(buf));
+ vesa_bios_uninit();
+ return (1);
+}
+
+static void
+vesa_bios_uninit(void)
+{
+
if (vesa_bios != NULL) {
x86bios_set_intr(0x10, vesa_bios_int10);
vesa_bios_offs = VESA_BIOS_OFFSET;
x86bios_free(vesa_bios, vesa_bios_size);
vesa_bios = NULL;
}
- if (vmbuf != NULL)
- x86bios_free(vmbuf, sizeof(buf));
if (vesa_adp_info != NULL) {
free(vesa_adp_info, M_DEVBUF);
vesa_adp_info = NULL;
@@ -1080,7 +1083,15 @@ fail:
free(vesa_revstr, M_DEVBUF);
vesa_revstr = NULL;
}
- return (1);
+ if (vesa_vmode != NULL) {
+ free(vesa_vmode, M_DEVBUF);
+ vesa_vmode = NULL;
+ }
+ if (vesa_palette != NULL) {
+ x86bios_free(vesa_palette,
+ VESA_PALETTE_SIZE + vesa_state_buf_size);
+ vesa_palette = NULL;
+ }
}
static void
@@ -1313,7 +1324,7 @@ vesa_set_mode(video_adapter_t *adp, int
if ((info.vi_flags & V_INFO_LINEAR) != 0)
mode |= 0x4000;
- if (vesa_bios_set_mode(mode))
+ if (vesa_bios_set_mode(mode | 0x8000))
return (1);
/* Palette format is reset by the above VBE function call. */
@@ -1450,6 +1461,8 @@ vesa_set_border(video_adapter_t *adp, in
static int
vesa_save_state(video_adapter_t *adp, void *p, size_t size)
{
+ vm_offset_t buf;
+ size_t bsize;
if (adp != vesa_adp || vesa_state_buf_size == 0)
return ((*prevvidsw->save_state)(adp, p, size));
@@ -1459,6 +1472,14 @@ vesa_save_state(video_adapter_t *adp, vo
if (size < (offsetof(adp_state_t, regs) + vesa_state_buf_size))
return (EINVAL);
+ buf = adp->va_buffer;
+ if (buf != 0) {
+ bsize = adp->va_buffer_size;
+ vesa_vmem_buf = malloc(bsize, M_DEVBUF, M_NOWAIT);
+ if (vesa_vmem_buf != NULL)
+ bcopy((void *)buf, vesa_vmem_buf, bsize);
+ } else
+ vesa_vmem_buf = NULL;
((adp_state_t *)p)->sig = V_STATE_SIG;
bzero(((adp_state_t *)p)->regs, vesa_state_buf_size);
return (vesa_bios_save_restore(STATE_SAVE, ((adp_state_t *)p)->regs));
@@ -1467,6 +1488,8 @@ vesa_save_state(video_adapter_t *adp, vo
static int
vesa_load_state(video_adapter_t *adp, void *p)
{
+ vm_offset_t buf;
+ size_t bsize;
int mode;
if (adp != vesa_adp)
@@ -1474,6 +1497,7 @@ vesa_load_state(video_adapter_t *adp, vo
/* Try BIOS POST to restore a sane state. */
(void)vesa_bios_post();
+ bsize = adp->va_buffer_size;
mode = adp->va_mode;
(void)vesa_set_mode(adp, adp->va_initial_mode);
if (mode != adp->va_initial_mode)
@@ -1481,6 +1505,12 @@ vesa_load_state(video_adapter_t *adp, vo
if (((adp_state_t *)p)->sig != V_STATE_SIG)
return ((*prevvidsw->load_state)(adp, p));
+ if (vesa_vmem_buf != NULL) {
+ buf = adp->va_buffer;
+ if (buf != 0)
+ bcopy(vesa_vmem_buf, (void *)buf, bsize);
+ free(vesa_vmem_buf, M_DEVBUF);
+ }
return (vesa_bios_save_restore(STATE_LOAD, ((adp_state_t *)p)->regs));
}
@@ -1911,26 +1941,7 @@ vesa_unload(void)
}
}
- if (vesa_bios != NULL) {
- x86bios_set_intr(0x10, vesa_bios_int10);
- x86bios_free(vesa_bios, vesa_bios_size);
- }
- if (vesa_adp_info != NULL)
- free(vesa_adp_info, M_DEVBUF);
- if (vesa_oemstr != NULL)
- free(vesa_oemstr, M_DEVBUF);
- if (vesa_venderstr != NULL)
- free(vesa_venderstr, M_DEVBUF);
- if (vesa_prodstr != NULL)
- free(vesa_prodstr, M_DEVBUF);
- if (vesa_revstr != NULL)
- free(vesa_revstr, M_DEVBUF);
- if (vesa_vmode != &vesa_vmode_empty)
- free(vesa_vmode, M_DEVBUF);
- if (vesa_palette != NULL)
- x86bios_free(vesa_palette,
- VESA_PALETTE_SIZE + vesa_state_buf_size);
-
+ vesa_bios_uninit();
mtx_destroy(&vesa_lock);
return (error);
More information about the svn-src-stable-9
mailing list