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> |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 11 | #include <stdint.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <sys/types.h> |
| 14 | |
| 15 | #include "drv.h" |
| 16 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 17 | struct bo { |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 18 | struct driver *drv; |
| 19 | uint32_t width; |
| 20 | uint32_t height; |
| 21 | uint32_t format; |
| 22 | uint32_t tiling; |
| 23 | size_t num_planes; |
| 24 | union bo_handle handles[DRV_MAX_PLANES]; |
| 25 | uint32_t offsets[DRV_MAX_PLANES]; |
| 26 | uint32_t sizes[DRV_MAX_PLANES]; |
| 27 | uint32_t strides[DRV_MAX_PLANES]; |
| 28 | uint64_t format_modifiers[DRV_MAX_PLANES]; |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 29 | uint64_t use_flags; |
Gurchetan Singh | a40ca9e | 2016-08-29 19:51:45 -0700 | [diff] [blame] | 30 | size_t total_size; |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 31 | void *priv; |
| 32 | }; |
| 33 | |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 34 | struct kms_item { |
Gurchetan Singh | 179687e | 2016-10-28 10:07:35 -0700 | [diff] [blame] | 35 | uint32_t format; |
| 36 | uint64_t modifier; |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 37 | uint64_t use_flags; |
Gurchetan Singh | 179687e | 2016-10-28 10:07:35 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 40 | struct format_metadata { |
| 41 | uint32_t priority; |
| 42 | uint32_t tiling; |
| 43 | uint64_t modifier; |
| 44 | }; |
| 45 | |
| 46 | struct combination { |
| 47 | uint32_t format; |
| 48 | struct format_metadata metadata; |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 49 | uint64_t use_flags; |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | struct combinations { |
| 53 | struct combination *data; |
| 54 | uint32_t size; |
| 55 | uint32_t allocations; |
Gurchetan Singh | 179687e | 2016-10-28 10:07:35 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
Ege Mihmanli | 96b7d46 | 2017-09-19 20:13:26 -0700 | [diff] [blame] | 58 | struct driver { |
| 59 | int fd; |
Gurchetan Singh | 3e9d383 | 2017-10-31 10:36:25 -0700 | [diff] [blame^] | 60 | const struct backend *backend; |
Ege Mihmanli | 96b7d46 | 2017-09-19 20:13:26 -0700 | [diff] [blame] | 61 | void *priv; |
| 62 | void *buffer_table; |
| 63 | void *map_table; |
| 64 | struct combinations combos; |
| 65 | pthread_mutex_t driver_lock; |
| 66 | }; |
| 67 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 68 | struct backend { |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 69 | char *name; |
| 70 | int (*init)(struct driver *drv); |
| 71 | void (*close)(struct driver *drv); |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 72 | 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] | 73 | uint64_t use_flags); |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 74 | int (*bo_create_with_modifiers)(struct bo *bo, uint32_t width, uint32_t height, |
| 75 | uint32_t format, const uint64_t *modifiers, uint32_t count); |
Gurchetan Singh | 71611d6 | 2017-01-03 16:49:56 -0800 | [diff] [blame] | 76 | int (*bo_destroy)(struct bo *bo); |
| 77 | int (*bo_import)(struct bo *bo, struct drv_import_fd_data *data); |
Gurchetan Singh | cfb8876 | 2017-09-28 17:14:50 -0700 | [diff] [blame] | 78 | void *(*bo_map)(struct bo *bo, struct map_info *data, size_t plane, uint32_t map_flags); |
Gurchetan Singh | 44d1fe4 | 2016-12-14 08:51:28 -0800 | [diff] [blame] | 79 | int (*bo_unmap)(struct bo *bo, struct map_info *data); |
Gurchetan Singh | c2ad63e | 2017-10-09 17:59:47 -0700 | [diff] [blame] | 80 | int (*bo_invalidate)(struct bo *bo, struct map_info *data); |
Gurchetan Singh | ff74141 | 2017-09-13 17:54:36 -0700 | [diff] [blame] | 81 | int (*bo_flush)(struct bo *bo, struct map_info *data); |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 82 | uint32_t (*resolve_format)(uint32_t format, uint64_t use_flags); |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 85 | // clang-format off |
Tomasz Figa | e0807b1 | 2017-08-04 12:50:03 +0900 | [diff] [blame] | 86 | #define BO_USE_RENDER_MASK BO_USE_LINEAR | BO_USE_PROTECTED | BO_USE_RENDERING | \ |
| 87 | BO_USE_RENDERSCRIPT | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | \ |
| 88 | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY | BO_USE_TEXTURE |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 89 | |
Tomasz Figa | e0807b1 | 2017-08-04 12:50:03 +0900 | [diff] [blame] | 90 | #define BO_USE_TEXTURE_MASK BO_USE_LINEAR | BO_USE_PROTECTED | BO_USE_RENDERSCRIPT | \ |
| 91 | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN | \ |
| 92 | BO_USE_SW_READ_RARELY | BO_USE_SW_WRITE_RARELY | BO_USE_TEXTURE |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 93 | |
| 94 | #define LINEAR_METADATA (struct format_metadata) { 0, 1, DRM_FORMAT_MOD_NONE } |
| 95 | // clang-format on |
| 96 | |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 97 | #endif |