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 int (*init)(struct driver *drv); 78 void (*close)(struct driver *drv); 79 int (*bo_create)(struct bo *bo, uint32_t width, uint32_t height, uint32_t format, 80 uint64_t use_flags); 81 int (*bo_create_with_modifiers)(struct bo *bo, uint32_t width, uint32_t height, 82 uint32_t format, const uint64_t *modifiers, uint32_t count); 83 // Either both or neither _metadata functions must be implemented. 84 // If the functions are implemented, bo_create and bo_create_with_modifiers must not be. 85 int (*bo_compute_metadata)(struct bo *bo, uint32_t width, uint32_t height, uint32_t format, 86 uint64_t use_flags, const uint64_t *modifiers, uint32_t count); 87 int (*bo_create_from_metadata)(struct bo *bo); 88 /* Called for every non-test-buffer BO on free */ 89 int (*bo_release)(struct bo *bo); 90 /* Called on free if this bo is the last object referencing the contained GEM BOs */ 91 int (*bo_destroy)(struct bo *bo); 92 int (*bo_import)(struct bo *bo, struct drv_import_fd_data *data); 93 void *(*bo_map)(struct bo *bo, struct vma *vma, size_t plane, uint32_t map_flags); 94 int (*bo_unmap)(struct bo *bo, struct vma *vma); 95 int (*bo_invalidate)(struct bo *bo, struct mapping *mapping); 96 int (*bo_flush)(struct bo *bo, struct mapping *mapping); 97 void (*resolve_format_and_use_flags)(struct driver *drv, uint32_t format, 98 uint64_t use_flags, uint32_t *out_format, 99 uint64_t *out_use_flags); 100 size_t (*num_planes_from_modifier)(struct driver *drv, uint32_t format, uint64_t modifier); 101 int (*resource_info)(struct bo *bo, uint32_t strides[DRV_MAX_PLANES], 102 uint32_t offsets[DRV_MAX_PLANES], uint64_t *format_modifier); 103 uint32_t (*get_max_texture_2d_size)(struct driver *drv); 104 }; 105 106 // clang-format off 107 #define BO_USE_RENDER_MASK (BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_RENDERSCRIPT | \ 108 BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | \ 109 BO_USE_SW_WRITE_RARELY | BO_USE_TEXTURE | BO_USE_FRONT_RENDERING) 110 111 #define BO_USE_TEXTURE_MASK (BO_USE_LINEAR | BO_USE_RENDERSCRIPT | BO_USE_SW_READ_OFTEN | \ 112 BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | \ 113 BO_USE_SW_WRITE_RARELY | BO_USE_TEXTURE | BO_USE_FRONT_RENDERING) 114 115 #define BO_USE_SW_MASK (BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | \ 116 BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY | BO_USE_FRONT_RENDERING) 117 118 #define BO_USE_NON_GPU_HW (BO_USE_SCANOUT | BO_USE_CAMERA_WRITE | BO_USE_CAMERA_READ | \ 119 BO_USE_HW_VIDEO_ENCODER | BO_USE_HW_VIDEO_DECODER) 120 121 #ifndef DRM_FORMAT_MOD_LINEAR 122 #define DRM_FORMAT_MOD_LINEAR DRM_FORMAT_MOD_NONE 123 #endif 124 125 #define LINEAR_METADATA (struct format_metadata) { 1, 0, DRM_FORMAT_MOD_LINEAR } 126 // clang-format on 127 128 #endif 129