From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48353) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPs3E-0006tC-MO for qemu-devel@nongnu.org; Fri, 05 Sep 2014 07:51:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XPs36-0003cs-7z for qemu-devel@nongnu.org; Fri, 05 Sep 2014 07:51:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1772) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPs36-0003cf-12 for qemu-devel@nongnu.org; Fri, 05 Sep 2014 07:51:28 -0400 From: Gerd Hoffmann Date: Fri, 5 Sep 2014 13:51:13 +0200 Message-Id: <1409917876-21961-6-git-send-email-kraxel@redhat.com> In-Reply-To: <1409917876-21961-1-git-send-email-kraxel@redhat.com> References: <1409917876-21961-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PULL 5/8] console: add qemu_create_displaysurface_guestmem List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Anthony Liguori This patch adds a qemu_create_displaysurface_guestmem helper function. Works simliar to qemu_create_displaysurface_from, but accepts a guest address instead of a host pointer and it handles cpu_physical_memory_{map,unmap} for you. Signed-off-by: Gerd Hoffmann --- include/ui/console.h | 4 ++++ ui/console.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/ui/console.h b/include/ui/console.h index 68ac362..61901f7 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -189,6 +189,10 @@ DisplayState *init_displaystate(void); DisplaySurface *qemu_create_displaysurface_from(int width, int height, pixman_format_code_t format, int linesize, uint8_t *data); +DisplaySurface *qemu_create_displaysurface_guestmem(int width, int height, + pixman_format_code_t format, + int linesize, + uint64_t addr); PixelFormat qemu_different_endianness_pixelformat(int bpp); PixelFormat qemu_default_pixelformat(int bpp); diff --git a/ui/console.c b/ui/console.c index 968aaaf..654c0d3 100644 --- a/ui/console.c +++ b/ui/console.c @@ -28,6 +28,7 @@ #include "qmp-commands.h" #include "sysemu/char.h" #include "trace.h" +#include "exec/memory.h" #define DEFAULT_BACKSCROLL 512 #define CONSOLE_CURSOR_PERIOD 500 @@ -1270,6 +1271,42 @@ DisplaySurface *qemu_create_displaysurface_from(int width, int height, return surface; } +static void qemu_unmap_displaysurface_guestmem(pixman_image_t *image, + void *unused) +{ + void *data = pixman_image_get_data(image); + uint32_t size = pixman_image_get_stride(image) * + pixman_image_get_height(image); + cpu_physical_memory_unmap(data, size, 0, 0); +} + +DisplaySurface *qemu_create_displaysurface_guestmem(int width, int height, + pixman_format_code_t format, + int linesize, uint64_t addr) +{ + DisplaySurface *surface; + hwaddr size; + void *data; + + if (linesize == 0) { + linesize = width * PIXMAN_FORMAT_BPP(format) / 8; + } + + size = linesize * height; + data = cpu_physical_memory_map(addr, &size, 0); + if (size != linesize * height) { + cpu_physical_memory_unmap(data, size, 0, 0); + return NULL; + } + + surface = qemu_create_displaysurface_from + (width, height, format, linesize, data); + pixman_image_set_destroy_function + (surface->image, qemu_unmap_displaysurface_guestmem, NULL); + + return surface; +} + static DisplaySurface *qemu_create_message_surface(int w, int h, const char *msg) { -- 1.8.3.1