xref: /openbmc/qemu/include/hw/display/bcm2835_fb.h (revision 38472890)
1 /*
2  * Raspberry Pi emulation (c) 2012 Gregory Estrade
3  * Upstreaming code cleanup [including bcm2835_*] (c) 2013 Jan Petrous
4  *
5  * Rasperry Pi 2 emulation and refactoring Copyright (c) 2015, Microsoft
6  * Written by Andrew Baumann
7  *
8  * This work is licensed under the terms of the GNU GPL, version 2 or later.
9  * See the COPYING file in the top-level directory.
10  */
11 
12 #ifndef BCM2835_FB_H
13 #define BCM2835_FB_H
14 
15 #include "hw/sysbus.h"
16 #include "ui/console.h"
17 
18 #define TYPE_BCM2835_FB "bcm2835-fb"
19 #define BCM2835_FB(obj) OBJECT_CHECK(BCM2835FBState, (obj), TYPE_BCM2835_FB)
20 
21 /*
22  * Configuration information about the fb which the guest can program
23  * via the mailbox property interface.
24  */
25 typedef struct {
26     uint32_t xres, yres;
27     uint32_t xres_virtual, yres_virtual;
28     uint32_t xoffset, yoffset;
29     uint32_t bpp;
30     uint32_t base;
31     uint32_t pixo;
32     uint32_t alpha;
33 } BCM2835FBConfig;
34 
35 typedef struct {
36     /*< private >*/
37     SysBusDevice busdev;
38     /*< public >*/
39 
40     uint32_t vcram_base, vcram_size;
41     MemoryRegion *dma_mr;
42     AddressSpace dma_as;
43     MemoryRegion iomem;
44     MemoryRegionSection fbsection;
45     QemuConsole *con;
46     qemu_irq mbox_irq;
47 
48     bool lock, invalidate, pending;
49 
50     BCM2835FBConfig config;
51     BCM2835FBConfig initial_config;
52 } BCM2835FBState;
53 
54 void bcm2835_fb_reconfigure(BCM2835FBState *s, BCM2835FBConfig *newconfig);
55 
56 /**
57  * bcm2835_fb_get_pitch: return number of bytes per line of the framebuffer
58  * @config: configuration info for the framebuffer
59  *
60  * Return the number of bytes per line of the framebuffer, ie the number
61  * that must be added to a pixel address to get the address of the pixel
62  * directly below it on screen.
63  */
64 static inline uint32_t bcm2835_fb_get_pitch(BCM2835FBConfig *config)
65 {
66     uint32_t xres = MAX(config->xres, config->xres_virtual);
67     return xres * (config->bpp >> 3);
68 }
69 
70 /**
71  * bcm2835_fb_get_size: return total size of framebuffer in bytes
72  * @config: configuration info for the framebuffer
73  */
74 static inline uint32_t bcm2835_fb_get_size(BCM2835FBConfig *config)
75 {
76     uint32_t yres = MAX(config->yres, config->yres_virtual);
77     return yres * bcm2835_fb_get_pitch(config);
78 }
79 
80 /**
81  * bcm2835_fb_validate_config: check provided config
82  *
83  * Validates the configuration information provided by the guest and
84  * adjusts it if necessary.
85  */
86 void bcm2835_fb_validate_config(BCM2835FBConfig *config);
87 
88 #endif
89