• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 The Chromium OS Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6 
7 #ifndef DRV_PRIV_H
8 #define DRV_PRIV_H
9 
10 #include <pthread.h>
11 #include <stdbool.h>
12 #include <stdint.h>
13 #include <stdlib.h>
14 #include <sys/types.h>
15 
16 #include "drv.h"
17 
18 struct bo_metadata {
19 	uint32_t width;
20 	uint32_t height;
21 	uint32_t format;
22 	uint32_t tiling;
23 	size_t num_planes;
24 	uint32_t offsets[DRV_MAX_PLANES];
25 	uint32_t sizes[DRV_MAX_PLANES];
26 	uint32_t strides[DRV_MAX_PLANES];
27 	uint64_t format_modifier;
28 	uint64_t use_flags;
29 	size_t total_size;
30 
31 	/*
32 	 * Most of the following metadata is virtgpu cross_domain specific.  However, that backend
33 	 * needs to know traditional metadata (strides, offsets) in addition to this backend
34 	 * specific metadata.  It's easiest just to stuff all the metadata here rather than
35 	 * having two metadata structs.
36 	 */
37 	uint32_t blob_id;
38 	uint32_t map_info;
39 	int32_t memory_idx;
40 	int32_t physical_device_idx;
41 };
42 
43 struct bo {
44 	struct driver *drv;
45 	struct bo_metadata meta;
46 	bool is_test_buffer;
47 	union bo_handle handles[DRV_MAX_PLANES];
48 	void *priv;
49 };
50 
51 struct format_metadata {
52 	uint32_t priority;
53 	uint32_t tiling;
54 	uint64_t modifier;
55 };
56 
57 struct combination {
58 	uint32_t format;
59 	struct format_metadata metadata;
60 	uint64_t use_flags;
61 };
62 
63 struct driver {
64 	int fd;
65 	const struct backend *backend;
66 	void *priv;
67 	pthread_mutex_t buffer_table_lock;
68 	void *buffer_table;
69 	pthread_mutex_t mappings_lock;
70 	struct drv_array *mappings;
71 	struct drv_array *combos;
72 	bool compression;
73 };
74 
75 struct backend {
76 	char *name;
77 	void (*preload)(bool load);
78 	int (*init)(struct driver *drv);
79 	void (*close)(struct driver *drv);
80 	int (*bo_create)(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
81 			 uint64_t use_flags);
82 	int (*bo_create_with_modifiers)(struct bo *bo, uint32_t width, uint32_t height,
83 					uint32_t format, const uint64_t *modifiers, uint32_t count);
84 	// Either both or neither _metadata functions must be implemented.
85 	// If the functions are implemented, bo_create and bo_create_with_modifiers must not be.
86 	int (*bo_compute_metadata)(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
87 				   uint64_t use_flags, const uint64_t *modifiers, uint32_t count);
88 	int (*bo_create_from_metadata)(struct bo *bo);
89 	/* Called for every non-test-buffer BO on free */
90 	int (*bo_release)(struct bo *bo);
91 	/* Called on free if this bo is the last object referencing the contained GEM BOs */
92 	int (*bo_destroy)(struct bo *bo);
93 	int (*bo_import)(struct bo *bo, struct drv_import_fd_data *data);
94 	void *(*bo_map)(struct bo *bo, struct vma *vma, uint32_t map_flags);
95 	int (*bo_unmap)(struct bo *bo, struct vma *vma);
96 	int (*bo_invalidate)(struct bo *bo, struct mapping *mapping);
97 	int (*bo_flush)(struct bo *bo, struct mapping *mapping);
98 	void (*resolve_format_and_use_flags)(struct driver *drv, uint32_t format,
99 					     uint64_t use_flags, uint32_t *out_format,
100 					     uint64_t *out_use_flags);
101 	size_t (*num_planes_from_modifier)(struct driver *drv, uint32_t format, uint64_t modifier);
102 	int (*resource_info)(struct bo *bo, uint32_t strides[DRV_MAX_PLANES],
103 			     uint32_t offsets[DRV_MAX_PLANES], uint64_t *format_modifier);
104 	uint32_t (*get_max_texture_2d_size)(struct driver *drv);
105 };
106 
107 // clang-format off
108 #define BO_USE_RENDER_MASK (BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_RENDERSCRIPT | \
109 			    BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | \
110 			    BO_USE_SW_WRITE_RARELY | BO_USE_TEXTURE | BO_USE_FRONT_RENDERING)
111 
112 #define BO_USE_TEXTURE_MASK (BO_USE_LINEAR | BO_USE_RENDERSCRIPT | BO_USE_SW_READ_OFTEN | \
113 			     BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | \
114 			     BO_USE_SW_WRITE_RARELY | BO_USE_TEXTURE | BO_USE_FRONT_RENDERING)
115 
116 #define BO_USE_SW_MASK (BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | \
117 			BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY | BO_USE_FRONT_RENDERING)
118 
119 #define BO_USE_GPU_HW (BO_USE_RENDERING | BO_USE_TEXTURE | BO_USE_GPU_DATA_BUFFER)
120 
121 #define BO_USE_NON_GPU_HW (BO_USE_SCANOUT | BO_USE_CAMERA_WRITE | BO_USE_CAMERA_READ | \
122 			   BO_USE_HW_VIDEO_ENCODER | BO_USE_HW_VIDEO_DECODER | BO_USE_SENSOR_DIRECT_DATA)
123 
124 #define BO_USE_HW_MASK	(BO_USE_GPU_HW | BO_USE_NON_GPU_HW)
125 
126 #ifndef DRM_FORMAT_MOD_LINEAR
127 #define DRM_FORMAT_MOD_LINEAR DRM_FORMAT_MOD_NONE
128 #endif
129 
130 #define LINEAR_METADATA (struct format_metadata) { 1, 0, DRM_FORMAT_MOD_LINEAR }
131 
132 #define MESA_LLVMPIPE_MAX_TEXTURE_2D_LEVELS 15
133 #define MESA_LLVMPIPE_MAX_TEXTURE_2D_SIZE (1 << (MESA_LLVMPIPE_MAX_TEXTURE_2D_LEVELS - 1))
134 #define MESA_LLVMPIPE_TILE_ORDER 6
135 #define MESA_LLVMPIPE_TILE_SIZE (1 << MESA_LLVMPIPE_TILE_ORDER)
136 
137 // clang-format on
138 
139 #endif
140