xref: /openbmc/qemu/include/hw/display/bcm2835_fb.h (revision 839a88e8)
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 #include "qom/object.h"
18 
19 #define UPPER_RAM_BASE 0x40000000
20 
21 #define TYPE_BCM2835_FB "bcm2835-fb"
22 OBJECT_DECLARE_SIMPLE_TYPE(BCM2835FBState, BCM2835_FB)
23 
24 /*
25  * Configuration information about the fb which the guest can program
26  * via the mailbox property interface.
27  */
28 typedef struct {
29     uint32_t xres, yres;
30     uint32_t xres_virtual, yres_virtual;
31     uint32_t xoffset, yoffset;
32     uint32_t bpp;
33     uint32_t base;
34     uint32_t pixo;
35     uint32_t alpha;
36 } BCM2835FBConfig;
37 
38 struct BCM2835FBState {
39     /*< private >*/
40     SysBusDevice busdev;
41     /*< public >*/
42 
43     uint32_t vcram_base, vcram_size;
44     MemoryRegion *dma_mr;
45     AddressSpace dma_as;
46     MemoryRegion iomem;
47     MemoryRegionSection fbsection;
48     QemuConsole *con;
49     qemu_irq mbox_irq;
50 
51     bool lock, invalidate, pending;
52 
53     BCM2835FBConfig config;
54     BCM2835FBConfig initial_config;
55 };
56 
57 void bcm2835_fb_reconfigure(BCM2835FBState *s, BCM2835FBConfig *newconfig);
58 
59 /**
60  * bcm2835_fb_get_pitch: return number of bytes per line of the framebuffer
61  * @config: configuration info for the framebuffer
62  *
63  * Return the number of bytes per line of the framebuffer, ie the number
64  * that must be added to a pixel address to get the address of the pixel
65  * directly below it on screen.
66  */
67 static inline uint32_t bcm2835_fb_get_pitch(BCM2835FBConfig *config)
68 {
69     uint32_t xres = MAX(config->xres, config->xres_virtual);
70     return xres * (config->bpp >> 3);
71 }
72 
73 /**
74  * bcm2835_fb_get_size: return total size of framebuffer in bytes
75  * @config: configuration info for the framebuffer
76  */
77 static inline uint32_t bcm2835_fb_get_size(BCM2835FBConfig *config)
78 {
79     uint32_t yres = MAX(config->yres, config->yres_virtual);
80     return yres * bcm2835_fb_get_pitch(config);
81 }
82 
83 /**
84  * bcm2835_fb_validate_config: check provided config
85  *
86  * Validates the configuration information provided by the guest and
87  * adjusts it if necessary.
88  */
89 void bcm2835_fb_validate_config(BCM2835FBConfig *config);
90 
91 #endif
92