Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: MIT */
0002 /*
0003  * Copyright (C) 2013-2017 Oracle Corporation
0004  * This file is based on ast_drv.h
0005  * Copyright 2012 Red Hat Inc.
0006  * Authors: Dave Airlie <airlied@redhat.com>
0007  *          Michael Thayer <michael.thayer@oracle.com,
0008  *          Hans de Goede <hdegoede@redhat.com>
0009  */
0010 #ifndef __VBOX_DRV_H__
0011 #define __VBOX_DRV_H__
0012 
0013 #include <linux/genalloc.h>
0014 #include <linux/io.h>
0015 #include <linux/irqreturn.h>
0016 #include <linux/string.h>
0017 
0018 #include <drm/drm_encoder.h>
0019 #include <drm/drm_gem.h>
0020 #include <drm/drm_gem_vram_helper.h>
0021 
0022 #include "vboxvideo_guest.h"
0023 #include "vboxvideo_vbe.h"
0024 #include "hgsmi_ch_setup.h"
0025 
0026 #define DRIVER_NAME         "vboxvideo"
0027 #define DRIVER_DESC         "Oracle VM VirtualBox Graphics Card"
0028 #define DRIVER_DATE         "20130823"
0029 
0030 #define DRIVER_MAJOR        1
0031 #define DRIVER_MINOR        0
0032 #define DRIVER_PATCHLEVEL   0
0033 
0034 #define VBOX_MAX_CURSOR_WIDTH  64
0035 #define VBOX_MAX_CURSOR_HEIGHT 64
0036 #define CURSOR_PIXEL_COUNT (VBOX_MAX_CURSOR_WIDTH * VBOX_MAX_CURSOR_HEIGHT)
0037 #define CURSOR_DATA_SIZE (CURSOR_PIXEL_COUNT * 4 + CURSOR_PIXEL_COUNT / 8)
0038 
0039 #define VBOX_MAX_SCREENS  32
0040 
0041 #define GUEST_HEAP_OFFSET(vbox) ((vbox)->full_vram_size - \
0042                  VBVA_ADAPTER_INFORMATION_SIZE)
0043 #define GUEST_HEAP_SIZE   VBVA_ADAPTER_INFORMATION_SIZE
0044 #define GUEST_HEAP_USABLE_SIZE (VBVA_ADAPTER_INFORMATION_SIZE - \
0045                 sizeof(struct hgsmi_host_flags))
0046 #define HOST_FLAGS_OFFSET GUEST_HEAP_USABLE_SIZE
0047 
0048 struct vbox_private {
0049     /* Must be first; or we must define our own release callback */
0050     struct drm_device ddev;
0051 
0052     u8 __iomem *guest_heap;
0053     u8 __iomem *vbva_buffers;
0054     struct gen_pool *guest_pool;
0055     struct vbva_buf_ctx *vbva_info;
0056     bool any_pitch;
0057     u32 num_crtcs;
0058     /* Amount of available VRAM, including space used for buffers. */
0059     u32 full_vram_size;
0060     /* Amount of available VRAM, not including space used for buffers. */
0061     u32 available_vram_size;
0062     /* Array of structures for receiving mode hints. */
0063     struct vbva_modehint *last_mode_hints;
0064 
0065     int fb_mtrr;
0066 
0067     struct mutex hw_mutex; /* protects modeset and accel/vbva accesses */
0068     struct work_struct hotplug_work;
0069     u32 input_mapping_width;
0070     u32 input_mapping_height;
0071     /*
0072      * Is user-space using an X.Org-style layout of one large frame-buffer
0073      * encompassing all screen ones or is the fbdev console active?
0074      */
0075     bool single_framebuffer;
0076     u8 cursor_data[CURSOR_DATA_SIZE];
0077 };
0078 
0079 #undef CURSOR_PIXEL_COUNT
0080 #undef CURSOR_DATA_SIZE
0081 
0082 struct vbox_connector {
0083     struct drm_connector base;
0084     char name[32];
0085     struct vbox_crtc *vbox_crtc;
0086     struct {
0087         u32 width;
0088         u32 height;
0089         bool disconnected;
0090     } mode_hint;
0091 };
0092 
0093 struct vbox_crtc {
0094     struct drm_crtc base;
0095     bool disconnected;
0096     unsigned int crtc_id;
0097     u32 fb_offset;
0098     bool cursor_enabled;
0099     u32 x_hint;
0100     u32 y_hint;
0101     /*
0102      * When setting a mode we not only pass the mode to the hypervisor,
0103      * but also information on how to map / translate input coordinates
0104      * for the emulated USB tablet.  This input-mapping may change when
0105      * the mode on *another* crtc changes.
0106      *
0107      * This means that sometimes we must do a modeset on other crtc-s then
0108      * the one being changed to update the input-mapping. Including crtc-s
0109      * which may be disabled inside the guest (shown as a black window
0110      * on the host unless closed by the user).
0111      *
0112      * With atomic modesetting the mode-info of disabled crtcs gets zeroed
0113      * yet we need it when updating the input-map to avoid resizing the
0114      * window as a side effect of a mode_set on another crtc. Therefor we
0115      * cache the info of the last mode below.
0116      */
0117     u32 width;
0118     u32 height;
0119     u32 x;
0120     u32 y;
0121 };
0122 
0123 struct vbox_encoder {
0124     struct drm_encoder base;
0125 };
0126 
0127 #define to_vbox_crtc(x) container_of(x, struct vbox_crtc, base)
0128 #define to_vbox_connector(x) container_of(x, struct vbox_connector, base)
0129 #define to_vbox_encoder(x) container_of(x, struct vbox_encoder, base)
0130 #define to_vbox_dev(x) container_of(x, struct vbox_private, ddev)
0131 
0132 bool vbox_check_supported(u16 id);
0133 int vbox_hw_init(struct vbox_private *vbox);
0134 void vbox_hw_fini(struct vbox_private *vbox);
0135 
0136 int vbox_mode_init(struct vbox_private *vbox);
0137 void vbox_mode_fini(struct vbox_private *vbox);
0138 
0139 void vbox_report_caps(struct vbox_private *vbox);
0140 
0141 int vbox_mm_init(struct vbox_private *vbox);
0142 
0143 /* vbox_irq.c */
0144 int vbox_irq_init(struct vbox_private *vbox);
0145 void vbox_irq_fini(struct vbox_private *vbox);
0146 void vbox_report_hotplug(struct vbox_private *vbox);
0147 
0148 /* vbox_hgsmi.c */
0149 void *hgsmi_buffer_alloc(struct gen_pool *guest_pool, size_t size,
0150              u8 channel, u16 channel_info);
0151 void hgsmi_buffer_free(struct gen_pool *guest_pool, void *buf);
0152 int hgsmi_buffer_submit(struct gen_pool *guest_pool, void *buf);
0153 
0154 static inline void vbox_write_ioport(u16 index, u16 data)
0155 {
0156     outw(index, VBE_DISPI_IOPORT_INDEX);
0157     outw(data, VBE_DISPI_IOPORT_DATA);
0158 }
0159 
0160 #endif