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