xref: /qemu/include/hw/display/bcm2835_fb.h (revision 7785e8ea)
15e9c2a8dSGrégory ESTRADE /*
25e9c2a8dSGrégory ESTRADE  * Raspberry Pi emulation (c) 2012 Gregory Estrade
35e9c2a8dSGrégory ESTRADE  * Upstreaming code cleanup [including bcm2835_*] (c) 2013 Jan Petrous
45e9c2a8dSGrégory ESTRADE  *
55e9c2a8dSGrégory ESTRADE  * Rasperry Pi 2 emulation and refactoring Copyright (c) 2015, Microsoft
65e9c2a8dSGrégory ESTRADE  * Written by Andrew Baumann
75e9c2a8dSGrégory ESTRADE  *
86111a0c0SPhilippe Mathieu-Daudé  * This work is licensed under the terms of the GNU GPL, version 2 or later.
96111a0c0SPhilippe Mathieu-Daudé  * See the COPYING file in the top-level directory.
105e9c2a8dSGrégory ESTRADE  */
115e9c2a8dSGrégory ESTRADE 
125e9c2a8dSGrégory ESTRADE #ifndef BCM2835_FB_H
135e9c2a8dSGrégory ESTRADE #define BCM2835_FB_H
145e9c2a8dSGrégory ESTRADE 
155e9c2a8dSGrégory ESTRADE #include "hw/sysbus.h"
165e9c2a8dSGrégory ESTRADE #include "ui/console.h"
17db1015e9SEduardo Habkost #include "qom/object.h"
185e9c2a8dSGrégory ESTRADE 
19*7785e8eaSSergey Kambalin #define UPPER_RAM_BASE 0x40000000
20*7785e8eaSSergey Kambalin 
215e9c2a8dSGrégory ESTRADE #define TYPE_BCM2835_FB "bcm2835-fb"
228063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(BCM2835FBState, BCM2835_FB)
235e9c2a8dSGrégory ESTRADE 
24a02755ecSPeter Maydell /*
25a02755ecSPeter Maydell  * Configuration information about the fb which the guest can program
26a02755ecSPeter Maydell  * via the mailbox property interface.
27a02755ecSPeter Maydell  */
28a02755ecSPeter Maydell typedef struct {
29a02755ecSPeter Maydell     uint32_t xres, yres;
30a02755ecSPeter Maydell     uint32_t xres_virtual, yres_virtual;
31a02755ecSPeter Maydell     uint32_t xoffset, yoffset;
32a02755ecSPeter Maydell     uint32_t bpp;
33a02755ecSPeter Maydell     uint32_t base;
34a02755ecSPeter Maydell     uint32_t pixo;
35a02755ecSPeter Maydell     uint32_t alpha;
36a02755ecSPeter Maydell } BCM2835FBConfig;
37a02755ecSPeter Maydell 
38db1015e9SEduardo Habkost struct BCM2835FBState {
395e9c2a8dSGrégory ESTRADE     /*< private >*/
405e9c2a8dSGrégory ESTRADE     SysBusDevice busdev;
415e9c2a8dSGrégory ESTRADE     /*< public >*/
425e9c2a8dSGrégory ESTRADE 
435e9c2a8dSGrégory ESTRADE     uint32_t vcram_base, vcram_size;
445e9c2a8dSGrégory ESTRADE     MemoryRegion *dma_mr;
455e9c2a8dSGrégory ESTRADE     AddressSpace dma_as;
465e9c2a8dSGrégory ESTRADE     MemoryRegion iomem;
475e9c2a8dSGrégory ESTRADE     MemoryRegionSection fbsection;
485e9c2a8dSGrégory ESTRADE     QemuConsole *con;
495e9c2a8dSGrégory ESTRADE     qemu_irq mbox_irq;
505e9c2a8dSGrégory ESTRADE 
515e9c2a8dSGrégory ESTRADE     bool lock, invalidate, pending;
52a02755ecSPeter Maydell 
53a02755ecSPeter Maydell     BCM2835FBConfig config;
549e2938a0SPeter Maydell     BCM2835FBConfig initial_config;
55db1015e9SEduardo Habkost };
565e9c2a8dSGrégory ESTRADE 
57193100b5SPeter Maydell void bcm2835_fb_reconfigure(BCM2835FBState *s, BCM2835FBConfig *newconfig);
585e9c2a8dSGrégory ESTRADE 
599a1f03f4SPeter Maydell /**
609a1f03f4SPeter Maydell  * bcm2835_fb_get_pitch: return number of bytes per line of the framebuffer
619a1f03f4SPeter Maydell  * @config: configuration info for the framebuffer
629a1f03f4SPeter Maydell  *
639a1f03f4SPeter Maydell  * Return the number of bytes per line of the framebuffer, ie the number
649a1f03f4SPeter Maydell  * that must be added to a pixel address to get the address of the pixel
659a1f03f4SPeter Maydell  * directly below it on screen.
669a1f03f4SPeter Maydell  */
bcm2835_fb_get_pitch(BCM2835FBConfig * config)679a1f03f4SPeter Maydell static inline uint32_t bcm2835_fb_get_pitch(BCM2835FBConfig *config)
689a1f03f4SPeter Maydell {
6901f18af9SPeter Maydell     uint32_t xres = MAX(config->xres, config->xres_virtual);
7001f18af9SPeter Maydell     return xres * (config->bpp >> 3);
719a1f03f4SPeter Maydell }
729a1f03f4SPeter Maydell 
739a1f03f4SPeter Maydell /**
749a1f03f4SPeter Maydell  * bcm2835_fb_get_size: return total size of framebuffer in bytes
759a1f03f4SPeter Maydell  * @config: configuration info for the framebuffer
769a1f03f4SPeter Maydell  */
bcm2835_fb_get_size(BCM2835FBConfig * config)779a1f03f4SPeter Maydell static inline uint32_t bcm2835_fb_get_size(BCM2835FBConfig *config)
789a1f03f4SPeter Maydell {
7901f18af9SPeter Maydell     uint32_t yres = MAX(config->yres, config->yres_virtual);
8001f18af9SPeter Maydell     return yres * bcm2835_fb_get_pitch(config);
819a1f03f4SPeter Maydell }
829a1f03f4SPeter Maydell 
83f8add62cSPeter Maydell /**
84f8add62cSPeter Maydell  * bcm2835_fb_validate_config: check provided config
85f8add62cSPeter Maydell  *
86f8add62cSPeter Maydell  * Validates the configuration information provided by the guest and
87f8add62cSPeter Maydell  * adjusts it if necessary.
88f8add62cSPeter Maydell  */
89f8add62cSPeter Maydell void bcm2835_fb_validate_config(BCM2835FBConfig *config);
90f8add62cSPeter Maydell 
915e9c2a8dSGrégory ESTRADE #endif
92