18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* Copyright 2019 Linaro, Ltd, Rob Herring <robh@kernel.org> */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#ifndef __PANFROST_GEM_H__ 58c2ecf20Sopenharmony_ci#define __PANFROST_GEM_H__ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include <drm/drm_gem_shmem_helper.h> 88c2ecf20Sopenharmony_ci#include <drm/drm_mm.h> 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_cistruct panfrost_mmu; 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_cistruct panfrost_gem_object { 138c2ecf20Sopenharmony_ci struct drm_gem_shmem_object base; 148c2ecf20Sopenharmony_ci struct sg_table *sgts; 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci /* 178c2ecf20Sopenharmony_ci * Use a list for now. If searching a mapping ever becomes the 188c2ecf20Sopenharmony_ci * bottleneck, we should consider using an RB-tree, or even better, 198c2ecf20Sopenharmony_ci * let the core store drm_gem_object_mapping entries (where we 208c2ecf20Sopenharmony_ci * could place driver specific data) instead of drm_gem_object ones 218c2ecf20Sopenharmony_ci * in its drm_file->object_idr table. 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * struct drm_gem_object_mapping { 248c2ecf20Sopenharmony_ci * struct drm_gem_object *obj; 258c2ecf20Sopenharmony_ci * void *driver_priv; 268c2ecf20Sopenharmony_ci * }; 278c2ecf20Sopenharmony_ci */ 288c2ecf20Sopenharmony_ci struct { 298c2ecf20Sopenharmony_ci struct list_head list; 308c2ecf20Sopenharmony_ci struct mutex lock; 318c2ecf20Sopenharmony_ci } mappings; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci /* 348c2ecf20Sopenharmony_ci * Count the number of jobs referencing this BO so we don't let the 358c2ecf20Sopenharmony_ci * shrinker reclaim this object prematurely. 368c2ecf20Sopenharmony_ci */ 378c2ecf20Sopenharmony_ci atomic_t gpu_usecount; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci bool noexec :1; 408c2ecf20Sopenharmony_ci bool is_heap :1; 418c2ecf20Sopenharmony_ci}; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_cistruct panfrost_gem_mapping { 448c2ecf20Sopenharmony_ci struct list_head node; 458c2ecf20Sopenharmony_ci struct kref refcount; 468c2ecf20Sopenharmony_ci struct panfrost_gem_object *obj; 478c2ecf20Sopenharmony_ci struct drm_mm_node mmnode; 488c2ecf20Sopenharmony_ci struct panfrost_mmu *mmu; 498c2ecf20Sopenharmony_ci bool active :1; 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistatic inline 538c2ecf20Sopenharmony_cistruct panfrost_gem_object *to_panfrost_bo(struct drm_gem_object *obj) 548c2ecf20Sopenharmony_ci{ 558c2ecf20Sopenharmony_ci return container_of(to_drm_gem_shmem_obj(obj), struct panfrost_gem_object, base); 568c2ecf20Sopenharmony_ci} 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cistatic inline struct panfrost_gem_mapping * 598c2ecf20Sopenharmony_cidrm_mm_node_to_panfrost_mapping(struct drm_mm_node *node) 608c2ecf20Sopenharmony_ci{ 618c2ecf20Sopenharmony_ci return container_of(node, struct panfrost_gem_mapping, mmnode); 628c2ecf20Sopenharmony_ci} 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_cistruct drm_gem_object *panfrost_gem_create_object(struct drm_device *dev, size_t size); 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistruct drm_gem_object * 678c2ecf20Sopenharmony_cipanfrost_gem_prime_import_sg_table(struct drm_device *dev, 688c2ecf20Sopenharmony_ci struct dma_buf_attachment *attach, 698c2ecf20Sopenharmony_ci struct sg_table *sgt); 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_cistruct panfrost_gem_object * 728c2ecf20Sopenharmony_cipanfrost_gem_create(struct drm_device *dev, size_t size, u32 flags); 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ciint panfrost_gem_open(struct drm_gem_object *obj, struct drm_file *file_priv); 758c2ecf20Sopenharmony_civoid panfrost_gem_close(struct drm_gem_object *obj, 768c2ecf20Sopenharmony_ci struct drm_file *file_priv); 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_cistruct panfrost_gem_mapping * 798c2ecf20Sopenharmony_cipanfrost_gem_mapping_get(struct panfrost_gem_object *bo, 808c2ecf20Sopenharmony_ci struct panfrost_file_priv *priv); 818c2ecf20Sopenharmony_civoid panfrost_gem_mapping_put(struct panfrost_gem_mapping *mapping); 828c2ecf20Sopenharmony_civoid panfrost_gem_teardown_mappings_locked(struct panfrost_gem_object *bo); 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_civoid panfrost_gem_shrinker_init(struct drm_device *dev); 858c2ecf20Sopenharmony_civoid panfrost_gem_shrinker_cleanup(struct drm_device *dev); 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci#endif /* __PANFROST_GEM_H__ */ 88