2 * early boot framebuffer in guest ram
3 * configured using fw_cfg
5 * Copyright Red Hat, Inc. 2017
8 * Gerd Hoffmann <kraxel@redhat.com>
10 * This work is licensed under the terms of the GNU GPL, version 2 or later.
11 * See the COPYING file in the top-level directory.
13 #include "qemu/osdep.h"
14 #include "qapi/error.h"
15 #include "hw/loader.h"
16 #include "hw/display/ramfb.h"
17 #include "ui/console.h"
18 #include "sysemu/sysemu.h"
20 struct QEMU_PACKED RAMFBCfg
{
31 uint32_t width
, height
;
35 static void ramfb_fw_cfg_write(void *dev
, off_t offset
, size_t len
)
39 uint32_t fourcc
, format
;
40 hwaddr stride
, addr
, length
;
42 s
->width
= be32_to_cpu(s
->cfg
.width
);
43 s
->height
= be32_to_cpu(s
->cfg
.height
);
44 stride
= be32_to_cpu(s
->cfg
.stride
);
45 fourcc
= be32_to_cpu(s
->cfg
.fourcc
);
46 addr
= be64_to_cpu(s
->cfg
.addr
);
47 length
= stride
* s
->height
;
48 format
= qemu_drm_format_to_pixman(fourcc
);
50 fprintf(stderr
, "%s: %dx%d @ 0x%" PRIx64
"\n", __func__
,
51 s
->width
, s
->height
, addr
);
52 framebuffer
= address_space_map(&address_space_memory
,
54 MEMTXATTRS_UNSPECIFIED
);
55 if (!framebuffer
|| length
< stride
* s
->height
) {
60 s
->ds
= qemu_create_displaysurface_from(s
->width
, s
->height
,
61 format
, stride
, framebuffer
);
64 void ramfb_display_update(QemuConsole
*con
, RAMFBState
*s
)
66 if (!s
->width
|| !s
->height
) {
71 dpy_gfx_replace_surface(con
, s
->ds
);
75 /* simple full screen update */
76 dpy_gfx_update_full(con
);
79 RAMFBState
*ramfb_setup(Error
**errp
)
81 FWCfgState
*fw_cfg
= fw_cfg_find();
84 if (!fw_cfg
|| !fw_cfg
->dma_enabled
) {
85 error_setg(errp
, "ramfb device requires fw_cfg with DMA");
89 s
= g_new0(RAMFBState
, 1);
91 rom_add_vga("vgabios-ramfb.bin");
92 fw_cfg_add_file_callback(fw_cfg
, "etc/ramfb",
93 NULL
, ramfb_fw_cfg_write
, s
,
94 &s
->cfg
, sizeof(s
->cfg
), false);