Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 1 | /* |
Daniele Castagna | 7a755de | 2016-12-16 17:32:30 -0500 | [diff] [blame] | 2 | * Copyright 2016 The Chromium OS Authors. All rights reserved. |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 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 | |
Gurchetan Singh | 2e786ad | 2016-08-24 18:31:23 -0700 | [diff] [blame] | 10 | #include <pthread.h> |
David Stevens | 26fe682 | 2020-03-09 12:23:42 +0000 | [diff] [blame] | 11 | #include <stdbool.h> |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 12 | #include <stdint.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <sys/types.h> |
| 15 | |
| 16 | #include "drv.h" |
| 17 | |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 18 | struct bo_metadata { |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 19 | uint32_t width; |
| 20 | uint32_t height; |
| 21 | uint32_t format; |
| 22 | uint32_t tiling; |
| 23 | size_t num_planes; |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 24 | uint32_t offsets[DRV_MAX_PLANES]; |
| 25 | uint32_t sizes[DRV_MAX_PLANES]; |
| 26 | uint32_t strides[DRV_MAX_PLANES]; |
Gurchetan Singh | 52155b4 | 2021-01-27 17:55:17 -0800 | [diff] [blame] | 27 | uint64_t format_modifier; |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 28 | uint64_t use_flags; |
Gurchetan Singh | a40ca9e | 2016-08-29 19:51:45 -0700 | [diff] [blame] | 29 | size_t total_size; |
Gurchetan Singh | 73c141e | 2021-01-21 14:51:19 -0800 | [diff] [blame] | 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; |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | struct bo { |
| 44 | struct driver *drv; |
| 45 | struct bo_metadata meta; |
David Stevens | 26fe682 | 2020-03-09 12:23:42 +0000 | [diff] [blame] | 46 | bool is_test_buffer; |
Gurchetan Singh | 298b757 | 2019-09-19 09:55:18 -0700 | [diff] [blame] | 47 | union bo_handle handles[DRV_MAX_PLANES]; |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 48 | void *priv; |
| 49 | }; |
| 50 | |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 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; |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 60 | uint64_t use_flags; |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 61 | }; |
| 62 | |
Ege Mihmanli | 96b7d46 | 2017-09-19 20:13:26 -0700 | [diff] [blame] | 63 | struct driver { |
| 64 | int fd; |
Gurchetan Singh | 3e9d383 | 2017-10-31 10:36:25 -0700 | [diff] [blame] | 65 | const struct backend *backend; |
Ege Mihmanli | 96b7d46 | 2017-09-19 20:13:26 -0700 | [diff] [blame] | 66 | void *priv; |
| 67 | void *buffer_table; |
Gurchetan Singh | cfedbcc | 2017-11-02 17:32:00 -0700 | [diff] [blame] | 68 | struct drv_array *mappings; |
Gurchetan Singh | bc9a87d | 2017-11-03 17:17:35 -0700 | [diff] [blame] | 69 | struct drv_array *combos; |
Ege Mihmanli | 96b7d46 | 2017-09-19 20:13:26 -0700 | [diff] [blame] | 70 | pthread_mutex_t driver_lock; |
Pilar Molina Lopez | 28cf2f1 | 2020-11-12 18:19:42 -0500 | [diff] [blame] | 71 | bool compression; |
Ege Mihmanli | 96b7d46 | 2017-09-19 20:13:26 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 74 | struct backend { |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 75 | char *name; |
| 76 | int (*init)(struct driver *drv); |
| 77 | void (*close)(struct driver *drv); |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 78 | int (*bo_create)(struct bo *bo, uint32_t width, uint32_t height, uint32_t format, |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 79 | uint64_t use_flags); |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 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); |
David Stevens | 26fe682 | 2020-03-09 12:23:42 +0000 | [diff] [blame] | 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); |
Gurchetan Singh | 71611d6 | 2017-01-03 16:49:56 -0800 | [diff] [blame] | 87 | int (*bo_destroy)(struct bo *bo); |
| 88 | int (*bo_import)(struct bo *bo, struct drv_import_fd_data *data); |
Gurchetan Singh | ee43c30 | 2017-11-14 18:20:27 -0800 | [diff] [blame] | 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); |
Gurchetan Singh | 47e629b | 2017-11-02 14:07:18 -0700 | [diff] [blame] | 91 | int (*bo_invalidate)(struct bo *bo, struct mapping *mapping); |
| 92 | int (*bo_flush)(struct bo *bo, struct mapping *mapping); |
Gurchetan Singh | 0d44d48 | 2019-06-04 19:39:51 -0700 | [diff] [blame] | 93 | uint32_t (*resolve_format)(struct driver *drv, uint32_t format, uint64_t use_flags); |
ChromeOS Developer | 44588bb | 2020-03-02 16:32:09 +0100 | [diff] [blame] | 94 | size_t (*num_planes_from_modifier)(struct driver *drv, uint32_t format, uint64_t modifier); |
Gurchetan Singh | bc4f023 | 2019-06-27 20:05:54 -0700 | [diff] [blame] | 95 | int (*resource_info)(struct bo *bo, uint32_t strides[DRV_MAX_PLANES], |
Yiwei Zhang | a1e93fd | 2021-04-30 07:01:55 +0000 | [diff] [blame^] | 96 | uint32_t offsets[DRV_MAX_PLANES], uint64_t *format_modifier); |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 99 | // clang-format off |
Gurchetan Singh | bbba9dd | 2020-10-12 17:31:10 -0700 | [diff] [blame] | 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 | \ |
Rob Clark | 39d9f8b | 2021-04-01 14:27:22 -0700 | [diff] [blame] | 102 | BO_USE_SW_WRITE_RARELY | BO_USE_TEXTURE | BO_USE_FRONT_RENDERING) |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 103 | |
Gurchetan Singh | bbba9dd | 2020-10-12 17:31:10 -0700 | [diff] [blame] | 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 | \ |
Rob Clark | 39d9f8b | 2021-04-01 14:27:22 -0700 | [diff] [blame] | 106 | BO_USE_SW_WRITE_RARELY | BO_USE_TEXTURE | BO_USE_FRONT_RENDERING) |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 107 | |
David Stevens | baab6c8 | 2020-02-26 17:14:43 +0900 | [diff] [blame] | 108 | #define BO_USE_SW_MASK (BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | \ |
Rob Clark | 39d9f8b | 2021-04-01 14:27:22 -0700 | [diff] [blame] | 109 | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY | BO_USE_FRONT_RENDERING) |
David Stevens | baab6c8 | 2020-02-26 17:14:43 +0900 | [diff] [blame] | 110 | |
| 111 | #define BO_USE_NON_GPU_HW (BO_USE_SCANOUT | BO_USE_CAMERA_WRITE | BO_USE_CAMERA_READ | \ |
Gurchetan Singh | bbba9dd | 2020-10-12 17:31:10 -0700 | [diff] [blame] | 112 | BO_USE_HW_VIDEO_ENCODER | BO_USE_HW_VIDEO_DECODER) |
Dominik Behr | fa17cdd | 2017-11-30 12:23:06 -0800 | [diff] [blame] | 113 | |
Alistair Strachan | a50131a | 2018-03-19 14:04:23 -0700 | [diff] [blame] | 114 | #ifndef DRM_FORMAT_MOD_LINEAR |
| 115 | #define DRM_FORMAT_MOD_LINEAR DRM_FORMAT_MOD_NONE |
| 116 | #endif |
| 117 | |
Satyajit | cdcebd8 | 2018-01-12 14:49:05 +0530 | [diff] [blame] | 118 | #define LINEAR_METADATA (struct format_metadata) { 1, 0, DRM_FORMAT_MOD_LINEAR } |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 119 | // clang-format on |
| 120 | |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 121 | #endif |