| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2013 Red Hat |
|---|
| 3 | 4 | * Author: Rob Clark <robdclark@gmail.com> |
|---|
| 4 | | - * |
|---|
| 5 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 6 | | - * under the terms of the GNU General Public License version 2 as published by |
|---|
| 7 | | - * the Free Software Foundation. |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 10 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 11 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 12 | | - * more details. |
|---|
| 13 | | - * |
|---|
| 14 | | - * You should have received a copy of the GNU General Public License along with |
|---|
| 15 | | - * this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 16 | 5 | */ |
|---|
| 17 | 6 | |
|---|
| 18 | 7 | #ifndef __MSM_GEM_H__ |
|---|
| 19 | 8 | #define __MSM_GEM_H__ |
|---|
| 20 | 9 | |
|---|
| 21 | 10 | #include <linux/kref.h> |
|---|
| 22 | | -#include <linux/reservation.h> |
|---|
| 11 | +#include <linux/dma-resv.h> |
|---|
| 23 | 12 | #include "msm_drv.h" |
|---|
| 24 | 13 | |
|---|
| 25 | 14 | /* Additional internal-use only BO flags: */ |
|---|
| 26 | 15 | #define MSM_BO_STOLEN 0x10000000 /* try to use stolen/splash memory */ |
|---|
| 16 | +#define MSM_BO_MAP_PRIV 0x20000000 /* use IOMMU_PRIV when mapping */ |
|---|
| 27 | 17 | |
|---|
| 28 | 18 | struct msm_gem_address_space { |
|---|
| 29 | 19 | const char *name; |
|---|
| .. | .. |
|---|
| 34 | 24 | spinlock_t lock; /* Protects drm_mm node allocation/removal */ |
|---|
| 35 | 25 | struct msm_mmu *mmu; |
|---|
| 36 | 26 | struct kref kref; |
|---|
| 27 | + |
|---|
| 28 | + /* For address spaces associated with a specific process, this |
|---|
| 29 | + * will be non-NULL: |
|---|
| 30 | + */ |
|---|
| 31 | + struct pid *pid; |
|---|
| 37 | 32 | }; |
|---|
| 38 | 33 | |
|---|
| 39 | 34 | struct msm_gem_vma { |
|---|
| .. | .. |
|---|
| 41 | 36 | uint64_t iova; |
|---|
| 42 | 37 | struct msm_gem_address_space *aspace; |
|---|
| 43 | 38 | struct list_head list; /* node in msm_gem_object::vmas */ |
|---|
| 39 | + bool mapped; |
|---|
| 40 | + int inuse; |
|---|
| 44 | 41 | }; |
|---|
| 45 | 42 | |
|---|
| 46 | 43 | struct msm_gem_object { |
|---|
| .. | .. |
|---|
| 82 | 79 | |
|---|
| 83 | 80 | struct list_head vmas; /* list of msm_gem_vma */ |
|---|
| 84 | 81 | |
|---|
| 85 | | - /* normally (resv == &_resv) except for imported bo's */ |
|---|
| 86 | | - struct reservation_object *resv; |
|---|
| 87 | | - struct reservation_object _resv; |
|---|
| 82 | + struct llist_node freed; |
|---|
| 88 | 83 | |
|---|
| 89 | 84 | /* For physically contiguous buffers. Used when we don't have |
|---|
| 90 | 85 | * an IOMMU. Also used for stolen/splashscreen buffer. |
|---|
| 91 | 86 | */ |
|---|
| 92 | 87 | struct drm_mm_node *vram_node; |
|---|
| 93 | 88 | struct mutex lock; /* Protects resources associated with bo */ |
|---|
| 89 | + |
|---|
| 90 | + char name[32]; /* Identifier to print for the debugfs files */ |
|---|
| 91 | + |
|---|
| 92 | + atomic_t active_count; |
|---|
| 94 | 93 | }; |
|---|
| 95 | 94 | #define to_msm_bo(x) container_of(x, struct msm_gem_object, base) |
|---|
| 96 | 95 | |
|---|
| 97 | 96 | static inline bool is_active(struct msm_gem_object *msm_obj) |
|---|
| 98 | 97 | { |
|---|
| 99 | | - return msm_obj->gpu != NULL; |
|---|
| 98 | + return atomic_read(&msm_obj->active_count); |
|---|
| 100 | 99 | } |
|---|
| 101 | 100 | |
|---|
| 102 | 101 | static inline bool is_purgeable(struct msm_gem_object *msm_obj) |
|---|
| .. | .. |
|---|
| 129 | 128 | |
|---|
| 130 | 129 | void msm_gem_purge(struct drm_gem_object *obj, enum msm_gem_lock subclass); |
|---|
| 131 | 130 | void msm_gem_vunmap(struct drm_gem_object *obj, enum msm_gem_lock subclass); |
|---|
| 131 | +void msm_gem_free_work(struct work_struct *work); |
|---|
| 132 | 132 | |
|---|
| 133 | 133 | /* Created per submit-ioctl, to track bo's and cmdstream bufs, etc, |
|---|
| 134 | 134 | * associated with the cmdstream submission for synchronization (and |
|---|
| .. | .. |
|---|
| 138 | 138 | struct msm_gem_submit { |
|---|
| 139 | 139 | struct drm_device *dev; |
|---|
| 140 | 140 | struct msm_gpu *gpu; |
|---|
| 141 | + struct msm_gem_address_space *aspace; |
|---|
| 141 | 142 | struct list_head node; /* node in ring submit list */ |
|---|
| 142 | 143 | struct list_head bo_list; |
|---|
| 143 | 144 | struct ww_acquire_ctx ticket; |
|---|
| .. | .. |
|---|
| 148 | 149 | bool valid; /* true if no cmdstream patching needed */ |
|---|
| 149 | 150 | bool in_rb; /* "sudo" mode, copy cmds into RB */ |
|---|
| 150 | 151 | struct msm_ringbuffer *ring; |
|---|
| 152 | + struct msm_file_private *ctx; |
|---|
| 151 | 153 | unsigned int nr_cmds; |
|---|
| 152 | 154 | unsigned int nr_bos; |
|---|
| 155 | + u32 ident; /* A "identifier" for the submit for logging */ |
|---|
| 153 | 156 | struct { |
|---|
| 154 | 157 | uint32_t type; |
|---|
| 155 | 158 | uint32_t size; /* in dwords */ |
|---|
| .. | .. |
|---|
| 158 | 161 | } *cmd; /* array of size nr_cmds */ |
|---|
| 159 | 162 | struct { |
|---|
| 160 | 163 | uint32_t flags; |
|---|
| 161 | | - struct msm_gem_object *obj; |
|---|
| 164 | + union { |
|---|
| 165 | + struct msm_gem_object *obj; |
|---|
| 166 | + uint32_t handle; |
|---|
| 167 | + }; |
|---|
| 162 | 168 | uint64_t iova; |
|---|
| 163 | | - } bos[0]; |
|---|
| 169 | + } bos[]; |
|---|
| 164 | 170 | }; |
|---|
| 165 | 171 | |
|---|
| 172 | +/* helper to determine of a buffer in submit should be dumped, used for both |
|---|
| 173 | + * devcoredump and debugfs cmdstream dumping: |
|---|
| 174 | + */ |
|---|
| 175 | +static inline bool |
|---|
| 176 | +should_dump(struct msm_gem_submit *submit, int idx) |
|---|
| 177 | +{ |
|---|
| 178 | + extern bool rd_full; |
|---|
| 179 | + return rd_full || (submit->bos[idx].flags & MSM_SUBMIT_BO_DUMP); |
|---|
| 180 | +} |
|---|
| 181 | + |
|---|
| 166 | 182 | #endif /* __MSM_GEM_H__ */ |
|---|