Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* Copyright 2019 Linaro, Ltd, Rob Herring <robh@kernel.org> */ |
| 3 | |
| 4 | #ifndef __PANFROST_GEM_H__ |
| 5 | #define __PANFROST_GEM_H__ |
| 6 | |
| 7 | #include <drm/drm_gem_shmem_helper.h> |
| 8 | #include <drm/drm_mm.h> |
| 9 | |
Rob Herring | 7282f76 | 2019-08-13 09:01:15 -0600 | [diff] [blame] | 10 | struct panfrost_mmu; |
| 11 | |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 12 | struct panfrost_gem_object { |
| 13 | struct drm_gem_shmem_object base; |
Rob Herring | 187d292 | 2019-07-26 16:09:43 -0600 | [diff] [blame] | 14 | struct sg_table *sgts; |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 15 | |
Boris Brezillon | bdefca2 | 2020-01-15 20:15:54 -0600 | [diff] [blame] | 16 | /* |
| 17 | * Use a list for now. If searching a mapping ever becomes the |
| 18 | * bottleneck, we should consider using an RB-tree, or even better, |
| 19 | * let the core store drm_gem_object_mapping entries (where we |
| 20 | * could place driver specific data) instead of drm_gem_object ones |
| 21 | * in its drm_file->object_idr table. |
| 22 | * |
| 23 | * struct drm_gem_object_mapping { |
| 24 | * struct drm_gem_object *obj; |
| 25 | * void *driver_priv; |
| 26 | * }; |
| 27 | */ |
| 28 | struct { |
| 29 | struct list_head list; |
| 30 | struct mutex lock; |
| 31 | } mappings; |
| 32 | |
Boris Brezillon | 7e0cf7e | 2019-11-29 14:59:08 +0100 | [diff] [blame] | 33 | /* |
| 34 | * Count the number of jobs referencing this BO so we don't let the |
| 35 | * shrinker reclaim this object prematurely. |
| 36 | */ |
| 37 | atomic_t gpu_usecount; |
| 38 | |
Rob Herring | 203270c | 2019-07-11 15:56:14 -0600 | [diff] [blame] | 39 | bool noexec :1; |
Rob Herring | 187d292 | 2019-07-26 16:09:43 -0600 | [diff] [blame] | 40 | bool is_heap :1; |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 41 | }; |
| 42 | |
Boris Brezillon | bdefca2 | 2020-01-15 20:15:54 -0600 | [diff] [blame] | 43 | struct panfrost_gem_mapping { |
| 44 | struct list_head node; |
| 45 | struct kref refcount; |
| 46 | struct panfrost_gem_object *obj; |
| 47 | struct drm_mm_node mmnode; |
| 48 | struct panfrost_mmu *mmu; |
| 49 | bool active :1; |
| 50 | }; |
| 51 | |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 52 | static inline |
| 53 | struct panfrost_gem_object *to_panfrost_bo(struct drm_gem_object *obj) |
| 54 | { |
| 55 | return container_of(to_drm_gem_shmem_obj(obj), struct panfrost_gem_object, base); |
| 56 | } |
| 57 | |
Boris Brezillon | bdefca2 | 2020-01-15 20:15:54 -0600 | [diff] [blame] | 58 | static inline struct panfrost_gem_mapping * |
| 59 | drm_mm_node_to_panfrost_mapping(struct drm_mm_node *node) |
Rob Herring | 187d292 | 2019-07-26 16:09:43 -0600 | [diff] [blame] | 60 | { |
Boris Brezillon | bdefca2 | 2020-01-15 20:15:54 -0600 | [diff] [blame] | 61 | return container_of(node, struct panfrost_gem_mapping, mmnode); |
Rob Herring | 187d292 | 2019-07-26 16:09:43 -0600 | [diff] [blame] | 62 | } |
| 63 | |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 64 | struct drm_gem_object *panfrost_gem_create_object(struct drm_device *dev, size_t size); |
| 65 | |
| 66 | struct drm_gem_object * |
| 67 | panfrost_gem_prime_import_sg_table(struct drm_device *dev, |
| 68 | struct dma_buf_attachment *attach, |
| 69 | struct sg_table *sgt); |
| 70 | |
Rob Herring | 203270c | 2019-07-11 15:56:14 -0600 | [diff] [blame] | 71 | struct panfrost_gem_object * |
| 72 | panfrost_gem_create_with_handle(struct drm_file *file_priv, |
| 73 | struct drm_device *dev, size_t size, |
| 74 | u32 flags, |
| 75 | uint32_t *handle); |
| 76 | |
Boris Brezillon | 0a52399 | 2019-11-29 14:59:05 +0100 | [diff] [blame] | 77 | int panfrost_gem_open(struct drm_gem_object *obj, struct drm_file *file_priv); |
| 78 | void panfrost_gem_close(struct drm_gem_object *obj, |
| 79 | struct drm_file *file_priv); |
| 80 | |
Boris Brezillon | bdefca2 | 2020-01-15 20:15:54 -0600 | [diff] [blame] | 81 | struct panfrost_gem_mapping * |
| 82 | panfrost_gem_mapping_get(struct panfrost_gem_object *bo, |
| 83 | struct panfrost_file_priv *priv); |
| 84 | void panfrost_gem_mapping_put(struct panfrost_gem_mapping *mapping); |
| 85 | void panfrost_gem_teardown_mappings(struct panfrost_gem_object *bo); |
| 86 | |
Rob Herring | 013b65101 | 2019-08-05 08:33:58 -0600 | [diff] [blame] | 87 | void panfrost_gem_shrinker_init(struct drm_device *dev); |
| 88 | void panfrost_gem_shrinker_cleanup(struct drm_device *dev); |
| 89 | |
Rob Herring | f3ba912 | 2018-09-10 14:27:58 -0500 | [diff] [blame] | 90 | #endif /* __PANFROST_GEM_H__ */ |