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