162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright (C) 2015 Red Hat, Inc.
362306a36Sopenharmony_ci * All Rights Reserved.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining
662306a36Sopenharmony_ci * a copy of this software and associated documentation files (the
762306a36Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
862306a36Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
962306a36Sopenharmony_ci * distribute, sublicense, and/or sell copies of the Software, and to
1062306a36Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
1162306a36Sopenharmony_ci * the following conditions:
1262306a36Sopenharmony_ci *
1362306a36Sopenharmony_ci * The above copyright notice and this permission notice (including the
1462306a36Sopenharmony_ci * next paragraph) shall be included in all copies or substantial
1562306a36Sopenharmony_ci * portions of the Software.
1662306a36Sopenharmony_ci *
1762306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1862306a36Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1962306a36Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
2062306a36Sopenharmony_ci * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
2162306a36Sopenharmony_ci * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2262306a36Sopenharmony_ci * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2362306a36Sopenharmony_ci * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2462306a36Sopenharmony_ci */
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#ifndef VIRTIO_DRV_H
2762306a36Sopenharmony_ci#define VIRTIO_DRV_H
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci#include <linux/dma-direction.h>
3062306a36Sopenharmony_ci#include <linux/virtio.h>
3162306a36Sopenharmony_ci#include <linux/virtio_ids.h>
3262306a36Sopenharmony_ci#include <linux/virtio_config.h>
3362306a36Sopenharmony_ci#include <linux/virtio_gpu.h>
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#include <drm/drm_atomic.h>
3662306a36Sopenharmony_ci#include <drm/drm_drv.h>
3762306a36Sopenharmony_ci#include <drm/drm_encoder.h>
3862306a36Sopenharmony_ci#include <drm/drm_fourcc.h>
3962306a36Sopenharmony_ci#include <drm/drm_framebuffer.h>
4062306a36Sopenharmony_ci#include <drm/drm_gem.h>
4162306a36Sopenharmony_ci#include <drm/drm_gem_shmem_helper.h>
4262306a36Sopenharmony_ci#include <drm/drm_ioctl.h>
4362306a36Sopenharmony_ci#include <drm/drm_probe_helper.h>
4462306a36Sopenharmony_ci#include <drm/virtgpu_drm.h>
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci#define DRIVER_NAME "virtio_gpu"
4762306a36Sopenharmony_ci#define DRIVER_DESC "virtio GPU"
4862306a36Sopenharmony_ci#define DRIVER_DATE "0"
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci#define DRIVER_MAJOR 0
5162306a36Sopenharmony_ci#define DRIVER_MINOR 1
5262306a36Sopenharmony_ci#define DRIVER_PATCHLEVEL 0
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci#define STATE_INITIALIZING 0
5562306a36Sopenharmony_ci#define STATE_OK 1
5662306a36Sopenharmony_ci#define STATE_ERR 2
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci#define MAX_CAPSET_ID 63
5962306a36Sopenharmony_ci#define MAX_RINGS 64
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_cistruct virtio_gpu_object_params {
6262306a36Sopenharmony_ci	unsigned long size;
6362306a36Sopenharmony_ci	bool dumb;
6462306a36Sopenharmony_ci	/* 3d */
6562306a36Sopenharmony_ci	bool virgl;
6662306a36Sopenharmony_ci	bool blob;
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci	/* classic resources only */
6962306a36Sopenharmony_ci	uint32_t format;
7062306a36Sopenharmony_ci	uint32_t width;
7162306a36Sopenharmony_ci	uint32_t height;
7262306a36Sopenharmony_ci	uint32_t target;
7362306a36Sopenharmony_ci	uint32_t bind;
7462306a36Sopenharmony_ci	uint32_t depth;
7562306a36Sopenharmony_ci	uint32_t array_size;
7662306a36Sopenharmony_ci	uint32_t last_level;
7762306a36Sopenharmony_ci	uint32_t nr_samples;
7862306a36Sopenharmony_ci	uint32_t flags;
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci	/* blob resources only */
8162306a36Sopenharmony_ci	uint32_t ctx_id;
8262306a36Sopenharmony_ci	uint32_t blob_mem;
8362306a36Sopenharmony_ci	uint32_t blob_flags;
8462306a36Sopenharmony_ci	uint64_t blob_id;
8562306a36Sopenharmony_ci};
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_cistruct virtio_gpu_object {
8862306a36Sopenharmony_ci	struct drm_gem_shmem_object base;
8962306a36Sopenharmony_ci	uint32_t hw_res_handle;
9062306a36Sopenharmony_ci	bool dumb;
9162306a36Sopenharmony_ci	bool created;
9262306a36Sopenharmony_ci	bool host3d_blob, guest_blob;
9362306a36Sopenharmony_ci	uint32_t blob_mem, blob_flags;
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci	int uuid_state;
9662306a36Sopenharmony_ci	uuid_t uuid;
9762306a36Sopenharmony_ci};
9862306a36Sopenharmony_ci#define gem_to_virtio_gpu_obj(gobj) \
9962306a36Sopenharmony_ci	container_of((gobj), struct virtio_gpu_object, base.base)
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_cistruct virtio_gpu_object_shmem {
10262306a36Sopenharmony_ci	struct virtio_gpu_object base;
10362306a36Sopenharmony_ci};
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_cistruct virtio_gpu_object_vram {
10662306a36Sopenharmony_ci	struct virtio_gpu_object base;
10762306a36Sopenharmony_ci	uint32_t map_state;
10862306a36Sopenharmony_ci	uint32_t map_info;
10962306a36Sopenharmony_ci	struct drm_mm_node vram_node;
11062306a36Sopenharmony_ci};
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci#define to_virtio_gpu_shmem(virtio_gpu_object) \
11362306a36Sopenharmony_ci	container_of((virtio_gpu_object), struct virtio_gpu_object_shmem, base)
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci#define to_virtio_gpu_vram(virtio_gpu_object) \
11662306a36Sopenharmony_ci	container_of((virtio_gpu_object), struct virtio_gpu_object_vram, base)
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_cistruct virtio_gpu_object_array {
11962306a36Sopenharmony_ci	struct ww_acquire_ctx ticket;
12062306a36Sopenharmony_ci	struct list_head next;
12162306a36Sopenharmony_ci	u32 nents, total;
12262306a36Sopenharmony_ci	struct drm_gem_object *objs[];
12362306a36Sopenharmony_ci};
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_cistruct virtio_gpu_vbuffer;
12662306a36Sopenharmony_cistruct virtio_gpu_device;
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_citypedef void (*virtio_gpu_resp_cb)(struct virtio_gpu_device *vgdev,
12962306a36Sopenharmony_ci				   struct virtio_gpu_vbuffer *vbuf);
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_cistruct virtio_gpu_fence_driver {
13262306a36Sopenharmony_ci	atomic64_t       last_fence_id;
13362306a36Sopenharmony_ci	uint64_t         current_fence_id;
13462306a36Sopenharmony_ci	uint64_t         context;
13562306a36Sopenharmony_ci	struct list_head fences;
13662306a36Sopenharmony_ci	spinlock_t       lock;
13762306a36Sopenharmony_ci};
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_cistruct virtio_gpu_fence_event {
14062306a36Sopenharmony_ci	struct drm_pending_event base;
14162306a36Sopenharmony_ci	struct drm_event event;
14262306a36Sopenharmony_ci};
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_cistruct virtio_gpu_fence {
14562306a36Sopenharmony_ci	struct dma_fence f;
14662306a36Sopenharmony_ci	uint32_t ring_idx;
14762306a36Sopenharmony_ci	uint64_t fence_id;
14862306a36Sopenharmony_ci	bool emit_fence_info;
14962306a36Sopenharmony_ci	struct virtio_gpu_fence_event *e;
15062306a36Sopenharmony_ci	struct virtio_gpu_fence_driver *drv;
15162306a36Sopenharmony_ci	struct list_head node;
15262306a36Sopenharmony_ci};
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_cistruct virtio_gpu_vbuffer {
15562306a36Sopenharmony_ci	char *buf;
15662306a36Sopenharmony_ci	int size;
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ci	void *data_buf;
15962306a36Sopenharmony_ci	uint32_t data_size;
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci	char *resp_buf;
16262306a36Sopenharmony_ci	int resp_size;
16362306a36Sopenharmony_ci	virtio_gpu_resp_cb resp_cb;
16462306a36Sopenharmony_ci	void *resp_cb_data;
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_ci	struct virtio_gpu_object_array *objs;
16762306a36Sopenharmony_ci	struct list_head list;
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ci	uint32_t seqno;
17062306a36Sopenharmony_ci};
17162306a36Sopenharmony_ci
17262306a36Sopenharmony_cistruct virtio_gpu_output {
17362306a36Sopenharmony_ci	int index;
17462306a36Sopenharmony_ci	struct drm_crtc crtc;
17562306a36Sopenharmony_ci	struct drm_connector conn;
17662306a36Sopenharmony_ci	struct drm_encoder enc;
17762306a36Sopenharmony_ci	struct virtio_gpu_display_one info;
17862306a36Sopenharmony_ci	struct virtio_gpu_update_cursor cursor;
17962306a36Sopenharmony_ci	struct edid *edid;
18062306a36Sopenharmony_ci	int cur_x;
18162306a36Sopenharmony_ci	int cur_y;
18262306a36Sopenharmony_ci	bool needs_modeset;
18362306a36Sopenharmony_ci};
18462306a36Sopenharmony_ci#define drm_crtc_to_virtio_gpu_output(x) \
18562306a36Sopenharmony_ci	container_of(x, struct virtio_gpu_output, crtc)
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_cistruct virtio_gpu_framebuffer {
18862306a36Sopenharmony_ci	struct drm_framebuffer base;
18962306a36Sopenharmony_ci	struct virtio_gpu_fence *fence;
19062306a36Sopenharmony_ci};
19162306a36Sopenharmony_ci#define to_virtio_gpu_framebuffer(x) \
19262306a36Sopenharmony_ci	container_of(x, struct virtio_gpu_framebuffer, base)
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_cistruct virtio_gpu_queue {
19562306a36Sopenharmony_ci	struct virtqueue *vq;
19662306a36Sopenharmony_ci	spinlock_t qlock;
19762306a36Sopenharmony_ci	wait_queue_head_t ack_queue;
19862306a36Sopenharmony_ci	struct work_struct dequeue_work;
19962306a36Sopenharmony_ci	uint32_t seqno;
20062306a36Sopenharmony_ci};
20162306a36Sopenharmony_ci
20262306a36Sopenharmony_cistruct virtio_gpu_drv_capset {
20362306a36Sopenharmony_ci	uint32_t id;
20462306a36Sopenharmony_ci	uint32_t max_version;
20562306a36Sopenharmony_ci	uint32_t max_size;
20662306a36Sopenharmony_ci};
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_cistruct virtio_gpu_drv_cap_cache {
20962306a36Sopenharmony_ci	struct list_head head;
21062306a36Sopenharmony_ci	void *caps_cache;
21162306a36Sopenharmony_ci	uint32_t id;
21262306a36Sopenharmony_ci	uint32_t version;
21362306a36Sopenharmony_ci	uint32_t size;
21462306a36Sopenharmony_ci	atomic_t is_valid;
21562306a36Sopenharmony_ci};
21662306a36Sopenharmony_ci
21762306a36Sopenharmony_cistruct virtio_gpu_device {
21862306a36Sopenharmony_ci	struct drm_device *ddev;
21962306a36Sopenharmony_ci
22062306a36Sopenharmony_ci	struct virtio_device *vdev;
22162306a36Sopenharmony_ci
22262306a36Sopenharmony_ci	struct virtio_gpu_output outputs[VIRTIO_GPU_MAX_SCANOUTS];
22362306a36Sopenharmony_ci	uint32_t num_scanouts;
22462306a36Sopenharmony_ci
22562306a36Sopenharmony_ci	struct virtio_gpu_queue ctrlq;
22662306a36Sopenharmony_ci	struct virtio_gpu_queue cursorq;
22762306a36Sopenharmony_ci	struct kmem_cache *vbufs;
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci	atomic_t pending_commands;
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_ci	struct ida	resource_ida;
23262306a36Sopenharmony_ci
23362306a36Sopenharmony_ci	wait_queue_head_t resp_wq;
23462306a36Sopenharmony_ci	/* current display info */
23562306a36Sopenharmony_ci	spinlock_t display_info_lock;
23662306a36Sopenharmony_ci	bool display_info_pending;
23762306a36Sopenharmony_ci
23862306a36Sopenharmony_ci	struct virtio_gpu_fence_driver fence_drv;
23962306a36Sopenharmony_ci
24062306a36Sopenharmony_ci	struct ida	ctx_id_ida;
24162306a36Sopenharmony_ci
24262306a36Sopenharmony_ci	bool has_virgl_3d;
24362306a36Sopenharmony_ci	bool has_edid;
24462306a36Sopenharmony_ci	bool has_indirect;
24562306a36Sopenharmony_ci	bool has_resource_assign_uuid;
24662306a36Sopenharmony_ci	bool has_resource_blob;
24762306a36Sopenharmony_ci	bool has_host_visible;
24862306a36Sopenharmony_ci	bool has_context_init;
24962306a36Sopenharmony_ci	struct virtio_shm_region host_visible_region;
25062306a36Sopenharmony_ci	struct drm_mm host_visible_mm;
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_ci	struct work_struct config_changed_work;
25362306a36Sopenharmony_ci
25462306a36Sopenharmony_ci	struct work_struct obj_free_work;
25562306a36Sopenharmony_ci	spinlock_t obj_free_lock;
25662306a36Sopenharmony_ci	struct list_head obj_free_list;
25762306a36Sopenharmony_ci
25862306a36Sopenharmony_ci	struct virtio_gpu_drv_capset *capsets;
25962306a36Sopenharmony_ci	uint32_t num_capsets;
26062306a36Sopenharmony_ci	uint64_t capset_id_mask;
26162306a36Sopenharmony_ci	struct list_head cap_cache;
26262306a36Sopenharmony_ci
26362306a36Sopenharmony_ci	/* protects uuid state when exporting */
26462306a36Sopenharmony_ci	spinlock_t resource_export_lock;
26562306a36Sopenharmony_ci	/* protects map state and host_visible_mm */
26662306a36Sopenharmony_ci	spinlock_t host_visible_lock;
26762306a36Sopenharmony_ci};
26862306a36Sopenharmony_ci
26962306a36Sopenharmony_cistruct virtio_gpu_fpriv {
27062306a36Sopenharmony_ci	uint32_t ctx_id;
27162306a36Sopenharmony_ci	uint32_t context_init;
27262306a36Sopenharmony_ci	bool context_created;
27362306a36Sopenharmony_ci	uint32_t num_rings;
27462306a36Sopenharmony_ci	uint64_t base_fence_ctx;
27562306a36Sopenharmony_ci	uint64_t ring_idx_mask;
27662306a36Sopenharmony_ci	struct mutex context_lock;
27762306a36Sopenharmony_ci};
27862306a36Sopenharmony_ci
27962306a36Sopenharmony_ci/* virtgpu_ioctl.c */
28062306a36Sopenharmony_ci#define DRM_VIRTIO_NUM_IOCTLS 12
28162306a36Sopenharmony_ciextern struct drm_ioctl_desc virtio_gpu_ioctls[DRM_VIRTIO_NUM_IOCTLS];
28262306a36Sopenharmony_civoid virtio_gpu_create_context(struct drm_device *dev, struct drm_file *file);
28362306a36Sopenharmony_ci
28462306a36Sopenharmony_ci/* virtgpu_kms.c */
28562306a36Sopenharmony_ciint virtio_gpu_init(struct virtio_device *vdev, struct drm_device *dev);
28662306a36Sopenharmony_civoid virtio_gpu_deinit(struct drm_device *dev);
28762306a36Sopenharmony_civoid virtio_gpu_release(struct drm_device *dev);
28862306a36Sopenharmony_ciint virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file);
28962306a36Sopenharmony_civoid virtio_gpu_driver_postclose(struct drm_device *dev, struct drm_file *file);
29062306a36Sopenharmony_ci
29162306a36Sopenharmony_ci/* virtgpu_gem.c */
29262306a36Sopenharmony_ciint virtio_gpu_gem_object_open(struct drm_gem_object *obj,
29362306a36Sopenharmony_ci			       struct drm_file *file);
29462306a36Sopenharmony_civoid virtio_gpu_gem_object_close(struct drm_gem_object *obj,
29562306a36Sopenharmony_ci				 struct drm_file *file);
29662306a36Sopenharmony_ciint virtio_gpu_mode_dumb_create(struct drm_file *file_priv,
29762306a36Sopenharmony_ci				struct drm_device *dev,
29862306a36Sopenharmony_ci				struct drm_mode_create_dumb *args);
29962306a36Sopenharmony_ciint virtio_gpu_mode_dumb_mmap(struct drm_file *file_priv,
30062306a36Sopenharmony_ci			      struct drm_device *dev,
30162306a36Sopenharmony_ci			      uint32_t handle, uint64_t *offset_p);
30262306a36Sopenharmony_ci
30362306a36Sopenharmony_cistruct virtio_gpu_object_array *virtio_gpu_array_alloc(u32 nents);
30462306a36Sopenharmony_cistruct virtio_gpu_object_array*
30562306a36Sopenharmony_civirtio_gpu_array_from_handles(struct drm_file *drm_file, u32 *handles, u32 nents);
30662306a36Sopenharmony_civoid virtio_gpu_array_add_obj(struct virtio_gpu_object_array *objs,
30762306a36Sopenharmony_ci			      struct drm_gem_object *obj);
30862306a36Sopenharmony_ciint virtio_gpu_array_lock_resv(struct virtio_gpu_object_array *objs);
30962306a36Sopenharmony_civoid virtio_gpu_array_unlock_resv(struct virtio_gpu_object_array *objs);
31062306a36Sopenharmony_civoid virtio_gpu_array_add_fence(struct virtio_gpu_object_array *objs,
31162306a36Sopenharmony_ci				struct dma_fence *fence);
31262306a36Sopenharmony_civoid virtio_gpu_array_put_free(struct virtio_gpu_object_array *objs);
31362306a36Sopenharmony_civoid virtio_gpu_array_put_free_delayed(struct virtio_gpu_device *vgdev,
31462306a36Sopenharmony_ci				       struct virtio_gpu_object_array *objs);
31562306a36Sopenharmony_civoid virtio_gpu_array_put_free_work(struct work_struct *work);
31662306a36Sopenharmony_ci
31762306a36Sopenharmony_ci/* virtgpu_vq.c */
31862306a36Sopenharmony_ciint virtio_gpu_alloc_vbufs(struct virtio_gpu_device *vgdev);
31962306a36Sopenharmony_civoid virtio_gpu_free_vbufs(struct virtio_gpu_device *vgdev);
32062306a36Sopenharmony_civoid virtio_gpu_cmd_create_resource(struct virtio_gpu_device *vgdev,
32162306a36Sopenharmony_ci				    struct virtio_gpu_object *bo,
32262306a36Sopenharmony_ci				    struct virtio_gpu_object_params *params,
32362306a36Sopenharmony_ci				    struct virtio_gpu_object_array *objs,
32462306a36Sopenharmony_ci				    struct virtio_gpu_fence *fence);
32562306a36Sopenharmony_civoid virtio_gpu_cmd_unref_resource(struct virtio_gpu_device *vgdev,
32662306a36Sopenharmony_ci				   struct virtio_gpu_object *bo);
32762306a36Sopenharmony_civoid virtio_gpu_cmd_transfer_to_host_2d(struct virtio_gpu_device *vgdev,
32862306a36Sopenharmony_ci					uint64_t offset,
32962306a36Sopenharmony_ci					uint32_t width, uint32_t height,
33062306a36Sopenharmony_ci					uint32_t x, uint32_t y,
33162306a36Sopenharmony_ci					struct virtio_gpu_object_array *objs,
33262306a36Sopenharmony_ci					struct virtio_gpu_fence *fence);
33362306a36Sopenharmony_civoid virtio_gpu_cmd_resource_flush(struct virtio_gpu_device *vgdev,
33462306a36Sopenharmony_ci				   uint32_t resource_id,
33562306a36Sopenharmony_ci				   uint32_t x, uint32_t y,
33662306a36Sopenharmony_ci				   uint32_t width, uint32_t height,
33762306a36Sopenharmony_ci				   struct virtio_gpu_object_array *objs,
33862306a36Sopenharmony_ci				   struct virtio_gpu_fence *fence);
33962306a36Sopenharmony_civoid virtio_gpu_cmd_set_scanout(struct virtio_gpu_device *vgdev,
34062306a36Sopenharmony_ci				uint32_t scanout_id, uint32_t resource_id,
34162306a36Sopenharmony_ci				uint32_t width, uint32_t height,
34262306a36Sopenharmony_ci				uint32_t x, uint32_t y);
34362306a36Sopenharmony_civoid virtio_gpu_object_attach(struct virtio_gpu_device *vgdev,
34462306a36Sopenharmony_ci			      struct virtio_gpu_object *obj,
34562306a36Sopenharmony_ci			      struct virtio_gpu_mem_entry *ents,
34662306a36Sopenharmony_ci			      unsigned int nents);
34762306a36Sopenharmony_ciint virtio_gpu_attach_status_page(struct virtio_gpu_device *vgdev);
34862306a36Sopenharmony_ciint virtio_gpu_detach_status_page(struct virtio_gpu_device *vgdev);
34962306a36Sopenharmony_civoid virtio_gpu_cursor_ping(struct virtio_gpu_device *vgdev,
35062306a36Sopenharmony_ci			    struct virtio_gpu_output *output);
35162306a36Sopenharmony_ciint virtio_gpu_cmd_get_display_info(struct virtio_gpu_device *vgdev);
35262306a36Sopenharmony_ciint virtio_gpu_cmd_get_capset_info(struct virtio_gpu_device *vgdev, int idx);
35362306a36Sopenharmony_ciint virtio_gpu_cmd_get_capset(struct virtio_gpu_device *vgdev,
35462306a36Sopenharmony_ci			      int idx, int version,
35562306a36Sopenharmony_ci			      struct virtio_gpu_drv_cap_cache **cache_p);
35662306a36Sopenharmony_ciint virtio_gpu_cmd_get_edids(struct virtio_gpu_device *vgdev);
35762306a36Sopenharmony_civoid virtio_gpu_cmd_context_create(struct virtio_gpu_device *vgdev, uint32_t id,
35862306a36Sopenharmony_ci				   uint32_t context_init, uint32_t nlen,
35962306a36Sopenharmony_ci				   const char *name);
36062306a36Sopenharmony_civoid virtio_gpu_cmd_context_destroy(struct virtio_gpu_device *vgdev,
36162306a36Sopenharmony_ci				    uint32_t id);
36262306a36Sopenharmony_civoid virtio_gpu_cmd_context_attach_resource(struct virtio_gpu_device *vgdev,
36362306a36Sopenharmony_ci					    uint32_t ctx_id,
36462306a36Sopenharmony_ci					    struct virtio_gpu_object_array *objs);
36562306a36Sopenharmony_civoid virtio_gpu_cmd_context_detach_resource(struct virtio_gpu_device *vgdev,
36662306a36Sopenharmony_ci					    uint32_t ctx_id,
36762306a36Sopenharmony_ci					    struct virtio_gpu_object_array *objs);
36862306a36Sopenharmony_civoid virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev,
36962306a36Sopenharmony_ci			   void *data, uint32_t data_size,
37062306a36Sopenharmony_ci			   uint32_t ctx_id,
37162306a36Sopenharmony_ci			   struct virtio_gpu_object_array *objs,
37262306a36Sopenharmony_ci			   struct virtio_gpu_fence *fence);
37362306a36Sopenharmony_civoid virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev,
37462306a36Sopenharmony_ci					  uint32_t ctx_id,
37562306a36Sopenharmony_ci					  uint64_t offset, uint32_t level,
37662306a36Sopenharmony_ci					  uint32_t stride,
37762306a36Sopenharmony_ci					  uint32_t layer_stride,
37862306a36Sopenharmony_ci					  struct drm_virtgpu_3d_box *box,
37962306a36Sopenharmony_ci					  struct virtio_gpu_object_array *objs,
38062306a36Sopenharmony_ci					  struct virtio_gpu_fence *fence);
38162306a36Sopenharmony_civoid virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev,
38262306a36Sopenharmony_ci					uint32_t ctx_id,
38362306a36Sopenharmony_ci					uint64_t offset, uint32_t level,
38462306a36Sopenharmony_ci					uint32_t stride,
38562306a36Sopenharmony_ci					uint32_t layer_stride,
38662306a36Sopenharmony_ci					struct drm_virtgpu_3d_box *box,
38762306a36Sopenharmony_ci					struct virtio_gpu_object_array *objs,
38862306a36Sopenharmony_ci					struct virtio_gpu_fence *fence);
38962306a36Sopenharmony_civoid
39062306a36Sopenharmony_civirtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev,
39162306a36Sopenharmony_ci				  struct virtio_gpu_object *bo,
39262306a36Sopenharmony_ci				  struct virtio_gpu_object_params *params,
39362306a36Sopenharmony_ci				  struct virtio_gpu_object_array *objs,
39462306a36Sopenharmony_ci				  struct virtio_gpu_fence *fence);
39562306a36Sopenharmony_civoid virtio_gpu_ctrl_ack(struct virtqueue *vq);
39662306a36Sopenharmony_civoid virtio_gpu_cursor_ack(struct virtqueue *vq);
39762306a36Sopenharmony_civoid virtio_gpu_fence_ack(struct virtqueue *vq);
39862306a36Sopenharmony_civoid virtio_gpu_dequeue_ctrl_func(struct work_struct *work);
39962306a36Sopenharmony_civoid virtio_gpu_dequeue_cursor_func(struct work_struct *work);
40062306a36Sopenharmony_civoid virtio_gpu_dequeue_fence_func(struct work_struct *work);
40162306a36Sopenharmony_ci
40262306a36Sopenharmony_civoid virtio_gpu_notify(struct virtio_gpu_device *vgdev);
40362306a36Sopenharmony_ci
40462306a36Sopenharmony_ciint
40562306a36Sopenharmony_civirtio_gpu_cmd_resource_assign_uuid(struct virtio_gpu_device *vgdev,
40662306a36Sopenharmony_ci				    struct virtio_gpu_object_array *objs);
40762306a36Sopenharmony_ci
40862306a36Sopenharmony_ciint virtio_gpu_cmd_map(struct virtio_gpu_device *vgdev,
40962306a36Sopenharmony_ci		       struct virtio_gpu_object_array *objs, uint64_t offset);
41062306a36Sopenharmony_ci
41162306a36Sopenharmony_civoid virtio_gpu_cmd_unmap(struct virtio_gpu_device *vgdev,
41262306a36Sopenharmony_ci			  struct virtio_gpu_object *bo);
41362306a36Sopenharmony_ci
41462306a36Sopenharmony_civoid
41562306a36Sopenharmony_civirtio_gpu_cmd_resource_create_blob(struct virtio_gpu_device *vgdev,
41662306a36Sopenharmony_ci				    struct virtio_gpu_object *bo,
41762306a36Sopenharmony_ci				    struct virtio_gpu_object_params *params,
41862306a36Sopenharmony_ci				    struct virtio_gpu_mem_entry *ents,
41962306a36Sopenharmony_ci				    uint32_t nents);
42062306a36Sopenharmony_civoid
42162306a36Sopenharmony_civirtio_gpu_cmd_set_scanout_blob(struct virtio_gpu_device *vgdev,
42262306a36Sopenharmony_ci				uint32_t scanout_id,
42362306a36Sopenharmony_ci				struct virtio_gpu_object *bo,
42462306a36Sopenharmony_ci				struct drm_framebuffer *fb,
42562306a36Sopenharmony_ci				uint32_t width, uint32_t height,
42662306a36Sopenharmony_ci				uint32_t x, uint32_t y);
42762306a36Sopenharmony_ci
42862306a36Sopenharmony_ci/* virtgpu_display.c */
42962306a36Sopenharmony_ciint virtio_gpu_modeset_init(struct virtio_gpu_device *vgdev);
43062306a36Sopenharmony_civoid virtio_gpu_modeset_fini(struct virtio_gpu_device *vgdev);
43162306a36Sopenharmony_ci
43262306a36Sopenharmony_ci/* virtgpu_plane.c */
43362306a36Sopenharmony_ciuint32_t virtio_gpu_translate_format(uint32_t drm_fourcc);
43462306a36Sopenharmony_cistruct drm_plane *virtio_gpu_plane_init(struct virtio_gpu_device *vgdev,
43562306a36Sopenharmony_ci					enum drm_plane_type type,
43662306a36Sopenharmony_ci					int index);
43762306a36Sopenharmony_ci
43862306a36Sopenharmony_ci/* virtgpu_fence.c */
43962306a36Sopenharmony_cistruct virtio_gpu_fence *virtio_gpu_fence_alloc(struct virtio_gpu_device *vgdev,
44062306a36Sopenharmony_ci						uint64_t base_fence_ctx,
44162306a36Sopenharmony_ci						uint32_t ring_idx);
44262306a36Sopenharmony_civoid virtio_gpu_fence_emit(struct virtio_gpu_device *vgdev,
44362306a36Sopenharmony_ci			  struct virtio_gpu_ctrl_hdr *cmd_hdr,
44462306a36Sopenharmony_ci			  struct virtio_gpu_fence *fence);
44562306a36Sopenharmony_civoid virtio_gpu_fence_event_process(struct virtio_gpu_device *vdev,
44662306a36Sopenharmony_ci				    u64 fence_id);
44762306a36Sopenharmony_ci
44862306a36Sopenharmony_ci/* virtgpu_object.c */
44962306a36Sopenharmony_civoid virtio_gpu_cleanup_object(struct virtio_gpu_object *bo);
45062306a36Sopenharmony_cistruct drm_gem_object *virtio_gpu_create_object(struct drm_device *dev,
45162306a36Sopenharmony_ci						size_t size);
45262306a36Sopenharmony_ciint virtio_gpu_object_create(struct virtio_gpu_device *vgdev,
45362306a36Sopenharmony_ci			     struct virtio_gpu_object_params *params,
45462306a36Sopenharmony_ci			     struct virtio_gpu_object **bo_ptr,
45562306a36Sopenharmony_ci			     struct virtio_gpu_fence *fence);
45662306a36Sopenharmony_ci
45762306a36Sopenharmony_cibool virtio_gpu_is_shmem(struct virtio_gpu_object *bo);
45862306a36Sopenharmony_ci
45962306a36Sopenharmony_ciint virtio_gpu_resource_id_get(struct virtio_gpu_device *vgdev,
46062306a36Sopenharmony_ci			       uint32_t *resid);
46162306a36Sopenharmony_ci/* virtgpu_prime.c */
46262306a36Sopenharmony_ciint virtio_gpu_resource_assign_uuid(struct virtio_gpu_device *vgdev,
46362306a36Sopenharmony_ci				    struct virtio_gpu_object *bo);
46462306a36Sopenharmony_cistruct dma_buf *virtgpu_gem_prime_export(struct drm_gem_object *obj,
46562306a36Sopenharmony_ci					 int flags);
46662306a36Sopenharmony_cistruct drm_gem_object *virtgpu_gem_prime_import(struct drm_device *dev,
46762306a36Sopenharmony_ci						struct dma_buf *buf);
46862306a36Sopenharmony_ciint virtgpu_gem_prime_get_uuid(struct drm_gem_object *obj,
46962306a36Sopenharmony_ci			       uuid_t *uuid);
47062306a36Sopenharmony_cistruct drm_gem_object *virtgpu_gem_prime_import_sg_table(
47162306a36Sopenharmony_ci	struct drm_device *dev, struct dma_buf_attachment *attach,
47262306a36Sopenharmony_ci	struct sg_table *sgt);
47362306a36Sopenharmony_ci
47462306a36Sopenharmony_ci/* virtgpu_debugfs.c */
47562306a36Sopenharmony_civoid virtio_gpu_debugfs_init(struct drm_minor *minor);
47662306a36Sopenharmony_ci
47762306a36Sopenharmony_ci/* virtgpu_vram.c */
47862306a36Sopenharmony_cibool virtio_gpu_is_vram(struct virtio_gpu_object *bo);
47962306a36Sopenharmony_ciint virtio_gpu_vram_create(struct virtio_gpu_device *vgdev,
48062306a36Sopenharmony_ci			   struct virtio_gpu_object_params *params,
48162306a36Sopenharmony_ci			   struct virtio_gpu_object **bo_ptr);
48262306a36Sopenharmony_cistruct sg_table *virtio_gpu_vram_map_dma_buf(struct virtio_gpu_object *bo,
48362306a36Sopenharmony_ci					     struct device *dev,
48462306a36Sopenharmony_ci					     enum dma_data_direction dir);
48562306a36Sopenharmony_civoid virtio_gpu_vram_unmap_dma_buf(struct device *dev,
48662306a36Sopenharmony_ci				   struct sg_table *sgt,
48762306a36Sopenharmony_ci				   enum dma_data_direction dir);
48862306a36Sopenharmony_ci
48962306a36Sopenharmony_ci/* virtgpu_submit.c */
49062306a36Sopenharmony_ciint virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
49162306a36Sopenharmony_ci				struct drm_file *file);
49262306a36Sopenharmony_ci
49362306a36Sopenharmony_ci#endif
494