xref: /aosp_15_r20/external/minigbm/drv_helpers.h (revision d95af8df99a05bcb8679a54dc3ab8e5cd312b38e)
1 /*
2  * Copyright 2014 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_HELPERS_H
8 #define DRV_HELPERS_H
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #include <stdbool.h>
15 
16 #include "drv.h"
17 #include "drv_array_helpers.h"
18 
19 #ifndef PAGE_SIZE
20 #define PAGE_SIZE 0x1000
21 #endif
22 
23 struct format_metadata;
24 
25 uint32_t drv_height_from_format(uint32_t format, uint32_t height, size_t plane);
26 uint32_t drv_vertical_subsampling_from_format(uint32_t format, size_t plane);
27 uint32_t drv_size_from_format(uint32_t format, uint32_t stride, uint32_t height, size_t plane);
28 int drv_bo_from_format(struct bo *bo, uint32_t stride, uint32_t stride_align,
29 		       uint32_t aligned_height, uint32_t format);
30 int drv_bo_from_format_and_padding(struct bo *bo, uint32_t stride, uint32_t stride_align,
31 				   uint32_t aligned_height, uint32_t format,
32 				   uint32_t padding[DRV_MAX_PLANES]);
33 int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
34 		       uint64_t use_flags);
35 int drv_dumb_bo_create_ex(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
36 			  uint64_t use_flags, uint64_t quirks);
37 int drv_dumb_bo_destroy(struct bo *bo);
38 int drv_gem_close(struct driver *drv, uint32_t gem_handle);
39 int drv_gem_bo_destroy(struct bo *bo);
40 int drv_prime_bo_import(struct bo *bo, struct drv_import_fd_data *data);
41 void *drv_dumb_bo_map(struct bo *bo, struct vma *vma, uint32_t map_flags);
42 int drv_bo_munmap(struct bo *bo, struct vma *vma);
43 int drv_get_prot(uint32_t map_flags);
44 void drv_add_combination(struct driver *drv, uint32_t format, struct format_metadata *metadata,
45 			 uint64_t usage);
46 void drv_add_combinations(struct driver *drv, const uint32_t *formats, uint32_t num_formats,
47 			  struct format_metadata *metadata, uint64_t usage);
48 void drv_modify_combination(struct driver *drv, uint32_t format, struct format_metadata *metadata,
49 			    uint64_t usage);
50 int drv_modify_linear_combinations(struct driver *drv);
51 uint64_t drv_pick_modifier(const uint64_t *modifiers, uint32_t count,
52 			   const uint64_t *modifier_order, uint32_t order_count);
53 bool drv_has_modifier(const uint64_t *list, uint32_t count, uint64_t modifier);
54 void drv_resolve_format_and_use_flags_helper(struct driver *drv, uint32_t format,
55 					     uint64_t use_flags, uint32_t *out_format,
56 					     uint64_t *out_use_flags);
57 
58 /*
59  * Get an option. Should return NULL if specified option is not set.
60  */
61 const char *drv_get_os_option(const char *name);
62 
63 struct lru_entry {
64 	struct lru_entry *next;
65 	struct lru_entry *prev;
66 };
67 
68 struct lru {
69 	struct lru_entry head;
70 	int count;
71 	int max;
72 };
73 
74 struct lru_entry *lru_find(struct lru *lru, bool (*eq)(struct lru_entry *e, void *data),
75 			   void *data);
76 void lru_insert(struct lru *lru, struct lru_entry *entry);
77 void lru_init(struct lru *lru, int max);
78 
79 #ifdef __cplusplus
80 }
81 #endif
82 
83 #endif
84