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 uint64_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 void *buffer_table; 68 struct drv_array *mappings; 69 struct drv_array *combos; 70 pthread_mutex_t driver_lock; 71 bool compression; 72 }; 73 74 struct backend { 75 char *name; 76 int (*init)(struct driver *drv); 77 void (*close)(struct driver *drv); 78 int (*bo_create)(struct bo *bo, uint32_t width, uint32_t height, uint32_t format, 79 uint64_t use_flags); 80 int (*bo_create_with_modifiers)(struct bo *bo, uint32_t width, uint32_t height, 81 uint32_t format, const uint64_t *modifiers, uint32_t count); 82 // Either both or neither _metadata functions must be implemented. 83 // If the functions are implemented, bo_create and bo_create_with_modifiers must not be. 84 int (*bo_compute_metadata)(struct bo *bo, uint32_t width, uint32_t height, uint32_t format, 85 uint64_t use_flags, const uint64_t *modifiers, uint32_t count); 86 int (*bo_create_from_metadata)(struct bo *bo); 87 int (*bo_destroy)(struct bo *bo); 88 int (*bo_import)(struct bo *bo, struct drv_import_fd_data *data); 89 void *(*bo_map)(struct bo *bo, struct vma *vma, size_t plane, uint32_t map_flags); 90 int (*bo_unmap)(struct bo *bo, struct vma *vma); 91 int (*bo_invalidate)(struct bo *bo, struct mapping *mapping); 92 int (*bo_flush)(struct bo *bo, struct mapping *mapping); 93 uint32_t (*resolve_format)(struct driver *drv, uint32_t format, uint64_t use_flags); 94 size_t (*num_planes_from_modifier)(struct driver *drv, uint32_t format, uint64_t modifier); 95 int (*resource_info)(struct bo *bo, uint32_t strides[DRV_MAX_PLANES], 96 uint32_t offsets[DRV_MAX_PLANES], uint64_t *format_modifier); 97 }; 98 99 // clang-format off 100 #define BO_USE_RENDER_MASK (BO_USE_LINEAR | BO_USE_RENDERING | BO_USE_RENDERSCRIPT | \ 101 BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | \ 102 BO_USE_SW_WRITE_RARELY | BO_USE_TEXTURE | BO_USE_FRONT_RENDERING) 103 104 #define BO_USE_TEXTURE_MASK (BO_USE_LINEAR | BO_USE_RENDERSCRIPT | BO_USE_SW_READ_OFTEN | \ 105 BO_USE_SW_WRITE_OFTEN | BO_USE_SW_READ_RARELY | \ 106 BO_USE_SW_WRITE_RARELY | BO_USE_TEXTURE | BO_USE_FRONT_RENDERING) 107 108 #define BO_USE_SW_MASK (BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | \ 109 BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY | BO_USE_FRONT_RENDERING) 110 111 #define BO_USE_NON_GPU_HW (BO_USE_SCANOUT | BO_USE_CAMERA_WRITE | BO_USE_CAMERA_READ | \ 112 BO_USE_HW_VIDEO_ENCODER | BO_USE_HW_VIDEO_DECODER) 113 114 #ifndef DRM_FORMAT_MOD_LINEAR 115 #define DRM_FORMAT_MOD_LINEAR DRM_FORMAT_MOD_NONE 116 #endif 117 118 #define LINEAR_METADATA (struct format_metadata) { 1, 0, DRM_FORMAT_MOD_LINEAR } 119 // clang-format on 120 121 #endif 122