Linux Audio

Check our new training course

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