| 1 | /* |
| 2 | * Data structures and functions shared between variants of the macOS |
| 3 | * ParavirtualizedGraphics.framework based apple-gfx display adapter. |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 6 | */ |
| 7 | |
| 8 | #ifndef QEMU_APPLE_GFX_H |
| 9 | #define QEMU_APPLE_GFX_H |
| 10 | |
| 11 | #include "qemu/queue.h" |
| 12 | #include "system/memory.h" |
| 13 | #include "hw/core/qdev-properties.h" |
| 14 | #include "ui/surface.h" |
| 15 | |
| 16 | #define TYPE_APPLE_GFX_MMIO "apple-gfx-mmio" |
| 17 | #define TYPE_APPLE_GFX_PCI "apple-gfx-pci" |
| 18 | |
| 19 | @class PGDeviceDescriptor; |
| 20 | @protocol PGDevice; |
| 21 | @protocol PGDisplay; |
| 22 | @protocol MTLDevice; |
| 23 | @protocol MTLTexture; |
| 24 | @protocol MTLCommandQueue; |
| 25 | |
| 26 | typedef QTAILQ_HEAD(, PGTask_s) PGTaskList; |
| 27 | |
| 28 | typedef struct AppleGFXDisplayMode { |
| 29 | uint16_t width_px; |
| 30 | uint16_t height_px; |
| 31 | uint16_t refresh_rate_hz; |
| 32 | } AppleGFXDisplayMode; |
| 33 | |
| 34 | typedef struct AppleGFXState { |
| 35 | /* Initialised on init/realize() */ |
| 36 | MemoryRegion iomem_gfx; |
| 37 | id<PGDevice> pgdev; |
| 38 | id<PGDisplay> pgdisp; |
| 39 | QemuConsole *con; |
| 40 | id<MTLDevice> mtl; |
| 41 | id<MTLCommandQueue> mtl_queue; |
| 42 | AppleGFXDisplayMode *display_modes; |
| 43 | uint32_t num_display_modes; |
| 44 | |
| 45 | /* List `tasks` is protected by task_mutex */ |
| 46 | QemuMutex task_mutex; |
| 47 | PGTaskList tasks; |
| 48 | |
| 49 | /* Mutable state (BQL protected) */ |
| 50 | QEMUCursor *cursor; |
| 51 | DisplaySurface *surface; |
| 52 | id<MTLTexture> texture; |
| 53 | int8_t pending_frames; /* # guest frames in the rendering pipeline */ |
| 54 | bool gfx_update_requested; /* QEMU display system wants a new frame */ |
| 55 | bool new_frame_ready; /* Guest has rendered a frame, ready to be used */ |
| 56 | bool using_managed_texture_storage; |
| 57 | uint32_t rendering_frame_width; |
| 58 | uint32_t rendering_frame_height; |
| 59 | |
| 60 | /* Mutable state (atomic) */ |
| 61 | bool cursor_show; |
| 62 | } AppleGFXState; |
| 63 | |
| 64 | void apple_gfx_common_init(Object *obj, AppleGFXState *s, const char* obj_name); |
| 65 | bool apple_gfx_common_realize(AppleGFXState *s, DeviceState *dev, |
| 66 | PGDeviceDescriptor *desc, Error **errp); |
| 67 | void *apple_gfx_host_ptr_for_gpa_range(uint64_t guest_physical, |
| 68 | uint64_t length, bool read_only, |
| 69 | MemoryRegion **mapping_in_region); |
| 70 | |
| 71 | extern const PropertyInfo qdev_prop_apple_gfx_display_mode; |
| 72 | |
| 73 | #endif |
| 74 |