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