mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 17:53:56 -06:00
virtio-gpu: factor out restore mapping
The same function is going to be used next to restore "blob" resources. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Acked-by: Peter Xu <peterx@redhat.com>
This commit is contained in:
parent
9c549ab689
commit
e92ffae6ba
1 changed files with 33 additions and 27 deletions
|
@ -1233,6 +1233,35 @@ static int virtio_gpu_save(QEMUFile *f, void *opaque, size_t size,
|
||||||
return vmstate_save_state(f, &vmstate_virtio_gpu_scanouts, g, NULL);
|
return vmstate_save_state(f, &vmstate_virtio_gpu_scanouts, g, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool virtio_gpu_load_restore_mapping(VirtIOGPU *g,
|
||||||
|
struct virtio_gpu_simple_resource *res)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < res->iov_cnt; i++) {
|
||||||
|
hwaddr len = res->iov[i].iov_len;
|
||||||
|
res->iov[i].iov_base =
|
||||||
|
dma_memory_map(VIRTIO_DEVICE(g)->dma_as, res->addrs[i], &len,
|
||||||
|
DMA_DIRECTION_TO_DEVICE, MEMTXATTRS_UNSPECIFIED);
|
||||||
|
|
||||||
|
if (!res->iov[i].iov_base || len != res->iov[i].iov_len) {
|
||||||
|
/* Clean up the half-a-mapping we just created... */
|
||||||
|
if (res->iov[i].iov_base) {
|
||||||
|
dma_memory_unmap(VIRTIO_DEVICE(g)->dma_as, res->iov[i].iov_base,
|
||||||
|
len, DMA_DIRECTION_TO_DEVICE, 0);
|
||||||
|
}
|
||||||
|
/* ...and the mappings for previous loop iterations */
|
||||||
|
res->iov_cnt = i;
|
||||||
|
virtio_gpu_cleanup_mapping(g, res);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QTAILQ_INSERT_HEAD(&g->reslist, res, next);
|
||||||
|
g->hostmem += res->hostmem;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,
|
static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,
|
||||||
const VMStateField *field)
|
const VMStateField *field)
|
||||||
{
|
{
|
||||||
|
@ -1297,35 +1326,12 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,
|
||||||
qemu_get_buffer(f, (void *)pixman_image_get_data(res->image),
|
qemu_get_buffer(f, (void *)pixman_image_get_data(res->image),
|
||||||
pixman_image_get_stride(res->image) * res->height);
|
pixman_image_get_stride(res->image) * res->height);
|
||||||
|
|
||||||
/* restore mapping */
|
if (!virtio_gpu_load_restore_mapping(g, res)) {
|
||||||
for (i = 0; i < res->iov_cnt; i++) {
|
pixman_image_unref(res->image);
|
||||||
hwaddr len = res->iov[i].iov_len;
|
g_free(res);
|
||||||
res->iov[i].iov_base =
|
return -EINVAL;
|
||||||
dma_memory_map(VIRTIO_DEVICE(g)->dma_as, res->addrs[i], &len,
|
|
||||||
DMA_DIRECTION_TO_DEVICE,
|
|
||||||
MEMTXATTRS_UNSPECIFIED);
|
|
||||||
|
|
||||||
if (!res->iov[i].iov_base || len != res->iov[i].iov_len) {
|
|
||||||
/* Clean up the half-a-mapping we just created... */
|
|
||||||
if (res->iov[i].iov_base) {
|
|
||||||
dma_memory_unmap(VIRTIO_DEVICE(g)->dma_as,
|
|
||||||
res->iov[i].iov_base,
|
|
||||||
len,
|
|
||||||
DMA_DIRECTION_TO_DEVICE,
|
|
||||||
0);
|
|
||||||
}
|
|
||||||
/* ...and the mappings for previous loop iterations */
|
|
||||||
res->iov_cnt = i;
|
|
||||||
virtio_gpu_cleanup_mapping(g, res);
|
|
||||||
pixman_image_unref(res->image);
|
|
||||||
g_free(res);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QTAILQ_INSERT_HEAD(&g->reslist, res, next);
|
|
||||||
g->hostmem += res->hostmem;
|
|
||||||
|
|
||||||
resource_id = qemu_get_be32(f);
|
resource_id = qemu_get_be32(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue