Home | History | Annotate | Line # | Download | only in vboxvideo
      1 /*	$NetBSD: vbox_drv.h,v 1.2 2021/12/18 23:45:44 riastradh Exp $	*/
      2 
      3 /* SPDX-License-Identifier: MIT */
      4 /*
      5  * Copyright (C) 2013-2017 Oracle Corporation
      6  * This file is based on ast_drv.h
      7  * Copyright 2012 Red Hat Inc.
      8  * Authors: Dave Airlie <airlied (at) redhat.com>
      9  *          Michael Thayer <michael.thayer (at) oracle.com,
     10  *          Hans de Goede <hdegoede (at) redhat.com>
     11  */
     12 #ifndef __VBOX_DRV_H__
     13 #define __VBOX_DRV_H__
     14 
     15 #include <linux/genalloc.h>
     16 #include <linux/io.h>
     17 #include <linux/irqreturn.h>
     18 #include <linux/string.h>
     19 
     20 #include <drm/drm_encoder.h>
     21 #include <drm/drm_gem.h>
     22 #include <drm/drm_gem_vram_helper.h>
     23 
     24 #include "vboxvideo_guest.h"
     25 #include "vboxvideo_vbe.h"
     26 #include "hgsmi_ch_setup.h"
     27 
     28 #define DRIVER_NAME         "vboxvideo"
     29 #define DRIVER_DESC         "Oracle VM VirtualBox Graphics Card"
     30 #define DRIVER_DATE         "20130823"
     31 
     32 #define DRIVER_MAJOR        1
     33 #define DRIVER_MINOR        0
     34 #define DRIVER_PATCHLEVEL   0
     35 
     36 #define VBOX_MAX_CURSOR_WIDTH  64
     37 #define VBOX_MAX_CURSOR_HEIGHT 64
     38 #define CURSOR_PIXEL_COUNT (VBOX_MAX_CURSOR_WIDTH * VBOX_MAX_CURSOR_HEIGHT)
     39 #define CURSOR_DATA_SIZE (CURSOR_PIXEL_COUNT * 4 + CURSOR_PIXEL_COUNT / 8)
     40 
     41 #define VBOX_MAX_SCREENS  32
     42 
     43 #define GUEST_HEAP_OFFSET(vbox) ((vbox)->full_vram_size - \
     44 				 VBVA_ADAPTER_INFORMATION_SIZE)
     45 #define GUEST_HEAP_SIZE   VBVA_ADAPTER_INFORMATION_SIZE
     46 #define GUEST_HEAP_USABLE_SIZE (VBVA_ADAPTER_INFORMATION_SIZE - \
     47 				sizeof(struct hgsmi_host_flags))
     48 #define HOST_FLAGS_OFFSET GUEST_HEAP_USABLE_SIZE
     49 
     50 struct vbox_private {
     51 	/* Must be first; or we must define our own release callback */
     52 	struct drm_device ddev;
     53 
     54 	u8 __iomem *guest_heap;
     55 	u8 __iomem *vbva_buffers;
     56 	struct gen_pool *guest_pool;
     57 	struct vbva_buf_ctx *vbva_info;
     58 	bool any_pitch;
     59 	u32 num_crtcs;
     60 	/* Amount of available VRAM, including space used for buffers. */
     61 	u32 full_vram_size;
     62 	/* Amount of available VRAM, not including space used for buffers. */
     63 	u32 available_vram_size;
     64 	/* Array of structures for receiving mode hints. */
     65 	struct vbva_modehint *last_mode_hints;
     66 
     67 	int fb_mtrr;
     68 
     69 	struct mutex hw_mutex; /* protects modeset and accel/vbva accesses */
     70 	struct work_struct hotplug_work;
     71 	u32 input_mapping_width;
     72 	u32 input_mapping_height;
     73 	/*
     74 	 * Is user-space using an X.Org-style layout of one large frame-buffer
     75 	 * encompassing all screen ones or is the fbdev console active?
     76 	 */
     77 	bool single_framebuffer;
     78 	u8 cursor_data[CURSOR_DATA_SIZE];
     79 };
     80 
     81 #undef CURSOR_PIXEL_COUNT
     82 #undef CURSOR_DATA_SIZE
     83 
     84 struct vbox_connector {
     85 	struct drm_connector base;
     86 	char name[32];
     87 	struct vbox_crtc *vbox_crtc;
     88 	struct {
     89 		u32 width;
     90 		u32 height;
     91 		bool disconnected;
     92 	} mode_hint;
     93 };
     94 
     95 struct vbox_crtc {
     96 	struct drm_crtc base;
     97 	bool disconnected;
     98 	unsigned int crtc_id;
     99 	u32 fb_offset;
    100 	bool cursor_enabled;
    101 	u32 x_hint;
    102 	u32 y_hint;
    103 	/*
    104 	 * When setting a mode we not only pass the mode to the hypervisor,
    105 	 * but also information on how to map / translate input coordinates
    106 	 * for the emulated USB tablet.  This input-mapping may change when
    107 	 * the mode on *another* crtc changes.
    108 	 *
    109 	 * This means that sometimes we must do a modeset on other crtc-s then
    110 	 * the one being changed to update the input-mapping. Including crtc-s
    111 	 * which may be disabled inside the guest (shown as a black window
    112 	 * on the host unless closed by the user).
    113 	 *
    114 	 * With atomic modesetting the mode-info of disabled crtcs gets zeroed
    115 	 * yet we need it when updating the input-map to avoid resizing the
    116 	 * window as a side effect of a mode_set on another crtc. Therefor we
    117 	 * cache the info of the last mode below.
    118 	 */
    119 	u32 width;
    120 	u32 height;
    121 	u32 x;
    122 	u32 y;
    123 };
    124 
    125 struct vbox_encoder {
    126 	struct drm_encoder base;
    127 };
    128 
    129 #define to_vbox_crtc(x) container_of(x, struct vbox_crtc, base)
    130 #define to_vbox_connector(x) container_of(x, struct vbox_connector, base)
    131 #define to_vbox_encoder(x) container_of(x, struct vbox_encoder, base)
    132 
    133 bool vbox_check_supported(u16 id);
    134 int vbox_hw_init(struct vbox_private *vbox);
    135 void vbox_hw_fini(struct vbox_private *vbox);
    136 
    137 int vbox_mode_init(struct vbox_private *vbox);
    138 void vbox_mode_fini(struct vbox_private *vbox);
    139 
    140 void vbox_report_caps(struct vbox_private *vbox);
    141 
    142 int vbox_mm_init(struct vbox_private *vbox);
    143 void vbox_mm_fini(struct vbox_private *vbox);
    144 
    145 /* vbox_irq.c */
    146 int vbox_irq_init(struct vbox_private *vbox);
    147 void vbox_irq_fini(struct vbox_private *vbox);
    148 void vbox_report_hotplug(struct vbox_private *vbox);
    149 irqreturn_t vbox_irq_handler(int irq, void *arg);
    150 
    151 /* vbox_hgsmi.c */
    152 void *hgsmi_buffer_alloc(struct gen_pool *guest_pool, size_t size,
    153 			 u8 channel, u16 channel_info);
    154 void hgsmi_buffer_free(struct gen_pool *guest_pool, void *buf);
    155 int hgsmi_buffer_submit(struct gen_pool *guest_pool, void *buf);
    156 
    157 static inline void vbox_write_ioport(u16 index, u16 data)
    158 {
    159 	outw(index, VBE_DISPI_IOPORT_INDEX);
    160 	outw(data, VBE_DISPI_IOPORT_DATA);
    161 }
    162 
    163 #endif
    164