aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
Diffstat (limited to 'hw')
-rw-r--r--hw/fw_cfg.c102
-rw-r--r--hw/opencores_eth.c29
-rw-r--r--hw/qxl-render.c36
-rw-r--r--hw/qxl.c26
-rw-r--r--hw/qxl.h3
-rw-r--r--hw/sysbus.c2
6 files changed, 109 insertions, 89 deletions
diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index 8df265c61d..dbcb888bbd 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -60,71 +60,55 @@ struct FWCfgState {
#define JPG_FILE 0
#define BMP_FILE 1
-static FILE *probe_splashfile(char *filename, int *file_sizep, int *file_typep)
+static char *read_splashfile(char *filename, int *file_sizep, int *file_typep)
{
- FILE *fp = NULL;
- int fop_ret;
- int file_size;
+ GError *err = NULL;
+ gboolean res;
+ gchar *content;
int file_type = -1;
- unsigned char buf[2] = {0, 0};
- unsigned int filehead_value = 0;
+ unsigned int filehead = 0;
int bmp_bpp;
- fp = fopen(filename, "rb");
- if (fp == NULL) {
- error_report("failed to open file '%s'.", filename);
- return fp;
+ res = g_file_get_contents(filename, &content, (gsize *)file_sizep, &err);
+ if (res == FALSE) {
+ error_report("failed to read splash file '%s'", filename);
+ g_error_free(err);
+ return NULL;
}
+
/* check file size */
- fseek(fp, 0L, SEEK_END);
- file_size = ftell(fp);
- if (file_size < 2) {
- error_report("file size is less than 2 bytes '%s'.", filename);
- fclose(fp);
- fp = NULL;
- return fp;
+ if (*file_sizep < 30) {
+ goto error;
}
+
/* check magic ID */
- fseek(fp, 0L, SEEK_SET);
- fop_ret = fread(buf, 1, 2, fp);
- if (fop_ret != 2) {
- error_report("Could not read header from '%s': %s",
- filename, strerror(errno));
- fclose(fp);
- fp = NULL;
- return fp;
- }
- filehead_value = (buf[0] + (buf[1] << 8)) & 0xffff;
- if (filehead_value == 0xd8ff) {
+ filehead = ((content[0] & 0xff) + (content[1] << 8)) & 0xffff;
+ if (filehead == 0xd8ff) {
file_type = JPG_FILE;
+ } else if (filehead == 0x4d42) {
+ file_type = BMP_FILE;
} else {
- if (filehead_value == 0x4d42) {
- file_type = BMP_FILE;
- }
- }
- if (file_type < 0) {
- error_report("'%s' not jpg/bmp file,head:0x%x.",
- filename, filehead_value);
- fclose(fp);
- fp = NULL;
- return fp;
+ goto error;
}
+
/* check BMP bpp */
if (file_type == BMP_FILE) {
- fseek(fp, 28, SEEK_SET);
- fop_ret = fread(buf, 1, 2, fp);
- bmp_bpp = (buf[0] + (buf[1] << 8)) & 0xffff;
+ bmp_bpp = (content[28] + (content[29] << 8)) & 0xffff;
if (bmp_bpp != 24) {
- error_report("only 24bpp bmp file is supported.");
- fclose(fp);
- fp = NULL;
- return fp;
+ goto error;
}
}
+
/* return values */
- *file_sizep = file_size;
*file_typep = file_type;
- return fp;
+
+ return content;
+
+error:
+ error_report("splash file '%s' format not recognized; must be JPEG "
+ "or 24 bit BMP", filename);
+ g_free(content);
+ return NULL;
}
static void fw_cfg_bootsplash(FWCfgState *s)
@@ -132,9 +116,7 @@ static void fw_cfg_bootsplash(FWCfgState *s)
int boot_splash_time = -1;
const char *boot_splash_filename = NULL;
char *p;
- char *filename;
- FILE *fp;
- int fop_ret;
+ char *filename, *file_data;
int file_size;
int file_type = -1;
const char *temp;
@@ -174,27 +156,19 @@ static void fw_cfg_bootsplash(FWCfgState *s)
error_report("failed to find file '%s'.", boot_splash_filename);
return;
}
- /* probing the file */
- fp = probe_splashfile(filename, &file_size, &file_type);
- if (fp == NULL) {
+
+ /* loading file data */
+ file_data = read_splashfile(filename, &file_size, &file_type);
+ if (file_data == NULL) {
g_free(filename);
return;
}
- /* loading file data */
if (boot_splash_filedata != NULL) {
g_free(boot_splash_filedata);
}
- boot_splash_filedata = g_malloc(file_size);
+ boot_splash_filedata = (uint8_t *)file_data;
boot_splash_filedata_size = file_size;
- fseek(fp, 0L, SEEK_SET);
- fop_ret = fread(boot_splash_filedata, 1, file_size, fp);
- if (fop_ret != file_size) {
- error_report("failed to read data from '%s'.",
- boot_splash_filename);
- fclose(fp);
- return;
- }
- fclose(fp);
+
/* insert data */
if (file_type == JPG_FILE) {
fw_cfg_add_file(s, "bootsplash.jpg",
diff --git a/hw/opencores_eth.c b/hw/opencores_eth.c
index 64b616ec1c..2c1e475395 100644
--- a/hw/opencores_eth.c
+++ b/hw/opencores_eth.c
@@ -382,6 +382,7 @@ static ssize_t open_eth_receive(VLANClientState *nc,
OpenEthState *s = DO_UPCAST(NICState, nc, nc)->opaque;
size_t maxfl = GET_REGFIELD(s, PACKETLEN, MAXFL);
size_t minfl = GET_REGFIELD(s, PACKETLEN, MINFL);
+ size_t fcsl = 4;
bool miss = true;
trace_open_eth_receive((unsigned)size);
@@ -418,6 +419,7 @@ static ssize_t open_eth_receive(VLANClientState *nc,
#else
{
#endif
+ static const uint8_t zero[64] = {0};
desc *desc = rx_desc(s);
size_t copy_size = GET_REGBIT(s, MODER, HUGEN) ? 65536 : maxfl;
@@ -426,11 +428,13 @@ static ssize_t open_eth_receive(VLANClientState *nc,
if (copy_size > size) {
copy_size = size;
+ } else {
+ fcsl = 0;
}
if (miss) {
desc->len_flags |= RXD_M;
}
- if (size > maxfl) {
+ if (GET_REGBIT(s, MODER, HUGEN) && size > maxfl) {
desc->len_flags |= RXD_TL;
}
#ifdef USE_RECSMALL
@@ -442,13 +446,28 @@ static ssize_t open_eth_receive(VLANClientState *nc,
cpu_physical_memory_write(desc->buf_ptr, buf, copy_size);
if (GET_REGBIT(s, MODER, PAD) && copy_size < minfl) {
- static const uint8_t zero[65536] = {0};
+ if (minfl - copy_size > fcsl) {
+ fcsl = 0;
+ } else {
+ fcsl -= minfl - copy_size;
+ }
+ while (copy_size < minfl) {
+ size_t zero_sz = minfl - copy_size < sizeof(zero) ?
+ minfl - copy_size : sizeof(zero);
- cpu_physical_memory_write(desc->buf_ptr + copy_size,
- zero, minfl - copy_size);
- copy_size = minfl;
+ cpu_physical_memory_write(desc->buf_ptr + copy_size,
+ zero, zero_sz);
+ copy_size += zero_sz;
+ }
}
+ /* There's no FCS in the frames handed to us by the QEMU, zero fill it.
+ * Don't do it if the frame is cut at the MAXFL or padded with 4 or
+ * more bytes to the MINFL.
+ */
+ cpu_physical_memory_write(desc->buf_ptr + copy_size, zero, fcsl);
+ copy_size += fcsl;
+
SET_FIELD(desc->len_flags, RXD_LEN, copy_size);
if ((desc->len_flags & RXD_WRAP) || s->rx_desc == 0x7f) {
diff --git a/hw/qxl-render.c b/hw/qxl-render.c
index c290739de0..2c51ba9806 100644
--- a/hw/qxl-render.c
+++ b/hw/qxl-render.c
@@ -28,16 +28,16 @@ static void qxl_flip(PCIQXLDevice *qxl, QXLRect *rect)
int len, i;
src += (qxl->guest_primary.surface.height - rect->top - 1) *
- qxl->guest_primary.stride;
- dst += rect->top * qxl->guest_primary.stride;
+ qxl->guest_primary.abs_stride;
+ dst += rect->top * qxl->guest_primary.abs_stride;
src += rect->left * qxl->guest_primary.bytes_pp;
dst += rect->left * qxl->guest_primary.bytes_pp;
len = (rect->right - rect->left) * qxl->guest_primary.bytes_pp;
for (i = rect->top; i < rect->bottom; i++) {
memcpy(dst, src, len);
- dst += qxl->guest_primary.stride;
- src -= qxl->guest_primary.stride;
+ dst += qxl->guest_primary.abs_stride;
+ src -= qxl->guest_primary.abs_stride;
}
}
@@ -45,7 +45,8 @@ void qxl_render_resize(PCIQXLDevice *qxl)
{
QXLSurfaceCreate *sc = &qxl->guest_primary.surface;
- qxl->guest_primary.stride = sc->stride;
+ qxl->guest_primary.qxl_stride = sc->stride;
+ qxl->guest_primary.abs_stride = abs(sc->stride);
qxl->guest_primary.resized++;
switch (sc->format) {
case SPICE_SURFACE_FMT_16_555:
@@ -75,7 +76,14 @@ void qxl_render_update(PCIQXLDevice *qxl)
VGACommonState *vga = &qxl->vga;
QXLRect dirty[32], update;
void *ptr;
- int i;
+ int i, redraw = 0;
+
+ if (!is_buffer_shared(vga->ds->surface)) {
+ dprint(qxl, 1, "%s: restoring shared displaysurface\n", __func__);
+ qxl->guest_primary.resized++;
+ qxl->guest_primary.commands++;
+ redraw = 1;
+ }
if (qxl->guest_primary.resized) {
qxl->guest_primary.resized = 0;
@@ -87,11 +95,11 @@ void qxl_render_update(PCIQXLDevice *qxl)
qemu_free_displaysurface(vga->ds);
qxl->guest_primary.data = memory_region_get_ram_ptr(&qxl->vga.vram);
- if (qxl->guest_primary.stride < 0) {
+ if (qxl->guest_primary.qxl_stride < 0) {
/* spice surface is upside down -> need extra buffer to flip */
- qxl->guest_primary.stride = -qxl->guest_primary.stride;
- qxl->guest_primary.flipped = g_malloc(qxl->guest_primary.surface.width *
- qxl->guest_primary.stride);
+ qxl->guest_primary.flipped =
+ g_malloc(qxl->guest_primary.surface.width *
+ qxl->guest_primary.abs_stride);
ptr = qxl->guest_primary.flipped;
} else {
ptr = qxl->guest_primary.data;
@@ -100,7 +108,7 @@ void qxl_render_update(PCIQXLDevice *qxl)
__FUNCTION__,
qxl->guest_primary.surface.width,
qxl->guest_primary.surface.height,
- qxl->guest_primary.stride,
+ qxl->guest_primary.qxl_stride,
qxl->guest_primary.bytes_pp,
qxl->guest_primary.bits_pp,
qxl->guest_primary.flipped ? "yes" : "no");
@@ -108,7 +116,7 @@ void qxl_render_update(PCIQXLDevice *qxl)
qemu_create_displaysurface_from(qxl->guest_primary.surface.width,
qxl->guest_primary.surface.height,
qxl->guest_primary.bits_pp,
- qxl->guest_primary.stride,
+ qxl->guest_primary.abs_stride,
ptr);
dpy_resize(vga->ds);
}
@@ -126,6 +134,10 @@ void qxl_render_update(PCIQXLDevice *qxl)
memset(dirty, 0, sizeof(dirty));
qxl_spice_update_area(qxl, 0, &update,
dirty, ARRAY_SIZE(dirty), 1, QXL_SYNC);
+ if (redraw) {
+ memset(dirty, 0, sizeof(dirty));
+ dirty[0] = update;
+ }
for (i = 0; i < ARRAY_SIZE(dirty); i++) {
if (qemu_spice_rect_is_empty(dirty+i)) {
diff --git a/hw/qxl.c b/hw/qxl.c
index 12f71aa56c..84ffd45c0c 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -1663,12 +1663,25 @@ static int qxl_pre_load(void *opaque)
return 0;
}
+static void qxl_create_memslots(PCIQXLDevice *d)
+{
+ int i;
+
+ for (i = 0; i < NUM_MEMSLOTS; i++) {
+ if (!d->guest_slots[i].active) {
+ continue;
+ }
+ dprint(d, 1, "%s: restoring guest slot %d\n", __func__, i);
+ qxl_add_memslot(d, i, 0, QXL_SYNC);
+ }
+}
+
static int qxl_post_load(void *opaque, int version)
{
PCIQXLDevice* d = opaque;
uint8_t *ram_start = d->vga.vram_ptr;
QXLCommandExt *cmds;
- int in, out, i, newmode;
+ int in, out, newmode;
dprint(d, 1, "%s: start\n", __FUNCTION__);
@@ -1685,19 +1698,16 @@ static int qxl_post_load(void *opaque, int version)
qxl_mode_to_string(d->mode));
newmode = d->mode;
d->mode = QXL_MODE_UNDEFINED;
+
switch (newmode) {
case QXL_MODE_UNDEFINED:
break;
case QXL_MODE_VGA:
+ qxl_create_memslots(d);
qxl_enter_vga_mode(d);
break;
case QXL_MODE_NATIVE:
- for (i = 0; i < NUM_MEMSLOTS; i++) {
- if (!d->guest_slots[i].active) {
- continue;
- }
- qxl_add_memslot(d, i, 0, QXL_SYNC);
- }
+ qxl_create_memslots(d);
qxl_create_guest_primary(d, 1, QXL_SYNC);
/* replay surface-create and cursor-set commands */
@@ -1722,6 +1732,8 @@ static int qxl_post_load(void *opaque, int version)
break;
case QXL_MODE_COMPAT:
+ /* note: no need to call qxl_create_memslots, qxl_set_mode
+ * creates the mem slot. */
qxl_set_mode(d, d->shadow_rom.mode, 1);
break;
}
diff --git a/hw/qxl.h b/hw/qxl.h
index 37b2619e55..766aa6d68e 100644
--- a/hw/qxl.h
+++ b/hw/qxl.h
@@ -48,7 +48,8 @@ typedef struct PCIQXLDevice {
QXLSurfaceCreate surface;
uint32_t commands;
uint32_t resized;
- int32_t stride;
+ int32_t qxl_stride;
+ uint32_t abs_stride;
uint32_t bits_pp;
uint32_t bytes_pp;
uint8_t *data, *flipped;
diff --git a/hw/sysbus.c b/hw/sysbus.c
index 4fab5a41b2..fd2fc6a51d 100644
--- a/hw/sysbus.c
+++ b/hw/sysbus.c
@@ -198,6 +198,7 @@ DeviceState *sysbus_create_varargs(const char *name,
sysbus_connect_irq(s, n, irq);
n++;
}
+ va_end(va);
return dev;
}
@@ -229,6 +230,7 @@ DeviceState *sysbus_try_create_varargs(const char *name,
sysbus_connect_irq(s, n, irq);
n++;
}
+ va_end(va);
return dev;
}