OSDN Git Service

Merge android-4.4.143 (7bbfac1) into msm-4.4
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / drivers / gpu / drm / msm / msm_gem.h
1 /*
2  * Copyright (C) 2013 Red Hat
3  * 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  */
17
18 #ifndef __MSM_GEM_H__
19 #define __MSM_GEM_H__
20
21 #include <linux/kref.h>
22 #include <linux/reservation.h>
23 #include <linux/mmu_notifier.h>
24 #include <linux/interval_tree.h>
25 #include "msm_drv.h"
26
27 /* Additional internal-use only BO flags: */
28 #define MSM_BO_STOLEN        0x10000000    /* try to use stolen/splash memory */
29 #define MSM_BO_LOCKED        0x20000000    /* Pages have been securely locked */
30 #define MSM_BO_SVM           0x40000000    /* bo is SVM */
31
32 struct msm_gem_address_space {
33         const char *name;
34         struct msm_mmu *mmu;
35         struct kref kref;
36         struct drm_mm mm;
37         spinlock_t lock; /* Protects drm_mm node allocation/removal */
38         u64 va_len;
39 };
40
41 struct msm_gem_vma {
42         /* Node used by the GPU address space, but not the SDE address space */
43         struct drm_mm_node node;
44         struct msm_gem_address_space *aspace;
45         uint64_t iova;
46         struct list_head list;
47 };
48
49 struct msm_gem_object {
50         struct drm_gem_object base;
51
52         uint32_t flags;
53
54         /* And object is either:
55          *  inactive - on priv->inactive_list
56          *  active   - on one one of the gpu's active_list..  well, at
57          *     least for now we don't have (I don't think) hw sync between
58          *     2d and 3d one devices which have both, meaning we need to
59          *     block on submit if a bo is already on other ring
60          *
61          */
62         struct list_head mm_list;
63         struct msm_gpu *gpu;     /* non-null if active */
64         uint32_t read_fence, write_fence;
65
66         /* Transiently in the process of submit ioctl, objects associated
67          * with the submit are on submit->bo_list.. this only lasts for
68          * the duration of the ioctl, so one bo can never be on multiple
69          * submit lists.
70          */
71         struct list_head submit_entry;
72
73         struct page **pages;
74         struct sg_table *sgt;
75         void *vaddr;
76
77         struct list_head domains;
78
79         /* normally (resv == &_resv) except for imported bo's */
80         struct reservation_object *resv;
81         struct reservation_object _resv;
82
83         /* For physically contiguous buffers.  Used when we don't have
84          * an IOMMU.  Also used for stolen/splashscreen buffer.
85          */
86         struct drm_mm_node *vram_node;
87         struct mutex lock; /* Protects resources associated with bo */
88 };
89 #define to_msm_bo(x) container_of(x, struct msm_gem_object, base)
90
91 struct msm_mmu_notifier {
92         struct mmu_notifier mn;
93         struct mm_struct *mm; /* mm_struct owning the mmu notifier mn */
94         struct hlist_node node;
95         struct rb_root svm_tree; /* interval tree holding all svm bos */
96         spinlock_t svm_tree_lock; /* Protects svm_tree*/
97         struct msm_drm_private *msm_dev;
98         struct kref refcount;
99 };
100
101 struct msm_gem_svm_object {
102         struct msm_gem_object msm_obj_base;
103         uint64_t hostptr;
104         struct mm_struct *mm; /* mm_struct the svm bo belongs to */
105         struct interval_tree_node svm_node;
106         struct msm_mmu_notifier *msm_mn;
107         struct list_head lnode;
108         /* bo has been unmapped on CPU, cannot be part of GPU submits */
109         bool invalid;
110 };
111
112 #define to_msm_svm_obj(x) \
113         ((struct msm_gem_svm_object *) \
114          container_of(x, struct msm_gem_svm_object, msm_obj_base))
115
116
117 static inline bool is_active(struct msm_gem_object *msm_obj)
118 {
119         return msm_obj->gpu != NULL;
120 }
121
122 static inline uint32_t msm_gem_fence(struct msm_gem_object *msm_obj,
123                 uint32_t op)
124 {
125         uint32_t fence = 0;
126
127         if (op & MSM_PREP_READ)
128                 fence = msm_obj->write_fence;
129         if (op & MSM_PREP_WRITE)
130                 fence = max(fence, msm_obj->read_fence);
131
132         return fence;
133 }
134
135 /* Internal submit flags */
136 #define SUBMIT_FLAG_SKIP_HANGCHECK 0x00000001
137
138 /* Created per submit-ioctl, to track bo's and cmdstream bufs, etc,
139  * associated with the cmdstream submission for synchronization (and
140  * make it easier to unwind when things go wrong, etc).  This only
141  * lasts for the duration of the submit-ioctl.
142  */
143 struct msm_gem_submit {
144         struct drm_device *dev;
145         struct msm_gem_address_space *aspace;
146         struct list_head node;   /* node in ring submit list */
147         struct list_head bo_list;
148         struct ww_acquire_ctx ticket;
149         uint32_t fence;
150         int ring;
151         u32 flags;
152         uint64_t profile_buf_iova;
153         struct drm_msm_gem_submit_profile_buffer *profile_buf;
154         bool secure;
155         struct msm_gpu_submitqueue *queue;
156         int tick_index;
157         unsigned int nr_cmds;
158         unsigned int nr_bos;
159         struct {
160                 uint32_t type;
161                 uint32_t size;  /* in dwords */
162                 uint64_t iova;
163                 uint32_t idx;   /* cmdstream buffer idx in bos[] */
164         } *cmd;  /* array of size nr_cmds */
165         struct {
166                 uint32_t flags;
167                 struct msm_gem_object *obj;
168                 uint64_t iova;
169         } bos[0];
170 };
171
172 #endif /* __MSM_GEM_H__ */