Loading...
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2015-2018 Etnaviv Project
4 */
5
6#ifndef __ETNAVIV_GEM_H__
7#define __ETNAVIV_GEM_H__
8
9#include <linux/dma-resv.h>
10#include "etnaviv_cmdbuf.h"
11#include "etnaviv_drv.h"
12
13struct dma_fence;
14struct etnaviv_gem_ops;
15struct etnaviv_gem_object;
16
17struct etnaviv_gem_userptr {
18 uintptr_t ptr;
19 struct mm_struct *mm;
20 bool ro;
21};
22
23struct etnaviv_vram_mapping {
24 struct list_head obj_node;
25 struct list_head scan_node;
26 struct list_head mmu_node;
27 struct etnaviv_gem_object *object;
28 struct etnaviv_iommu_context *context;
29 struct drm_mm_node vram_node;
30 unsigned int use;
31 u32 iova;
32};
33
34struct etnaviv_gem_object {
35 struct drm_gem_object base;
36 const struct etnaviv_gem_ops *ops;
37 struct mutex lock;
38
39 u32 flags;
40
41 struct list_head gem_node;
42 struct etnaviv_gpu *gpu; /* non-null if active */
43 atomic_t gpu_active;
44 u32 access;
45
46 struct page **pages;
47 struct sg_table *sgt;
48 void *vaddr;
49
50 struct list_head vram_list;
51
52 /* cache maintenance */
53 u32 last_cpu_prep_op;
54
55 struct etnaviv_gem_userptr userptr;
56};
57
58static inline
59struct etnaviv_gem_object *to_etnaviv_bo(struct drm_gem_object *obj)
60{
61 return container_of(obj, struct etnaviv_gem_object, base);
62}
63
64struct etnaviv_gem_ops {
65 int (*get_pages)(struct etnaviv_gem_object *);
66 void (*release)(struct etnaviv_gem_object *);
67 void *(*vmap)(struct etnaviv_gem_object *);
68 int (*mmap)(struct etnaviv_gem_object *, struct vm_area_struct *);
69};
70
71static inline bool is_active(struct etnaviv_gem_object *etnaviv_obj)
72{
73 return atomic_read(&etnaviv_obj->gpu_active) != 0;
74}
75
76#define MAX_CMDS 4
77
78struct etnaviv_gem_submit_bo {
79 u32 flags;
80 u64 va;
81 struct etnaviv_gem_object *obj;
82 struct etnaviv_vram_mapping *mapping;
83};
84
85/* Created per submit-ioctl, to track bo's and cmdstream bufs, etc,
86 * associated with the cmdstream submission for synchronization (and
87 * make it easier to unwind when things go wrong, etc).
88 */
89struct etnaviv_gem_submit {
90 struct drm_sched_job sched_job;
91 struct kref refcount;
92 struct etnaviv_file_private *ctx;
93 struct etnaviv_gpu *gpu;
94 struct etnaviv_iommu_context *mmu_context, *prev_mmu_context;
95 struct dma_fence *out_fence;
96 int out_fence_id;
97 struct list_head node; /* GPU active submit list */
98 struct etnaviv_cmdbuf cmdbuf;
99 struct pid *pid; /* submitting process */
100 u32 exec_state;
101 u32 flags;
102 unsigned int nr_pmrs;
103 struct etnaviv_perfmon_request *pmrs;
104 unsigned int nr_bos;
105 struct etnaviv_gem_submit_bo bos[];
106 /* No new members here, the previous one is variable-length! */
107};
108
109void etnaviv_submit_put(struct etnaviv_gem_submit * submit);
110
111int etnaviv_gem_wait_bo(struct etnaviv_gpu *gpu, struct drm_gem_object *obj,
112 struct drm_etnaviv_timespec *timeout);
113int etnaviv_gem_new_private(struct drm_device *dev, size_t size, u32 flags,
114 const struct etnaviv_gem_ops *ops, struct etnaviv_gem_object **res);
115void etnaviv_gem_obj_add(struct drm_device *dev, struct drm_gem_object *obj);
116struct page **etnaviv_gem_get_pages(struct etnaviv_gem_object *obj);
117void etnaviv_gem_put_pages(struct etnaviv_gem_object *obj);
118
119struct etnaviv_vram_mapping *etnaviv_gem_mapping_get(
120 struct drm_gem_object *obj, struct etnaviv_iommu_context *mmu_context,
121 u64 va);
122void etnaviv_gem_mapping_unreference(struct etnaviv_vram_mapping *mapping);
123
124#endif /* __ETNAVIV_GEM_H__ */
1/*
2 * Copyright (C) 2015 Etnaviv Project
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef __ETNAVIV_GEM_H__
18#define __ETNAVIV_GEM_H__
19
20#include <linux/reservation.h>
21#include "etnaviv_drv.h"
22
23struct etnaviv_gem_ops;
24struct etnaviv_gem_object;
25
26struct etnaviv_gem_userptr {
27 uintptr_t ptr;
28 struct task_struct *task;
29 struct work_struct *work;
30 bool ro;
31};
32
33struct etnaviv_vram_mapping {
34 struct list_head obj_node;
35 struct list_head scan_node;
36 struct list_head mmu_node;
37 struct etnaviv_gem_object *object;
38 struct etnaviv_iommu *mmu;
39 struct drm_mm_node vram_node;
40 unsigned int use;
41 u32 iova;
42};
43
44struct etnaviv_gem_object {
45 struct drm_gem_object base;
46 const struct etnaviv_gem_ops *ops;
47 struct mutex lock;
48
49 u32 flags;
50
51 struct list_head gem_node;
52 struct etnaviv_gpu *gpu; /* non-null if active */
53 atomic_t gpu_active;
54 u32 access;
55
56 struct page **pages;
57 struct sg_table *sgt;
58 void *vaddr;
59
60 /* normally (resv == &_resv) except for imported bo's */
61 struct reservation_object *resv;
62 struct reservation_object _resv;
63
64 struct list_head vram_list;
65
66 /* cache maintenance */
67 u32 last_cpu_prep_op;
68
69 struct etnaviv_gem_userptr userptr;
70};
71
72static inline
73struct etnaviv_gem_object *to_etnaviv_bo(struct drm_gem_object *obj)
74{
75 return container_of(obj, struct etnaviv_gem_object, base);
76}
77
78struct etnaviv_gem_ops {
79 int (*get_pages)(struct etnaviv_gem_object *);
80 void (*release)(struct etnaviv_gem_object *);
81 void *(*vmap)(struct etnaviv_gem_object *);
82};
83
84static inline bool is_active(struct etnaviv_gem_object *etnaviv_obj)
85{
86 return atomic_read(&etnaviv_obj->gpu_active) != 0;
87}
88
89#define MAX_CMDS 4
90
91struct etnaviv_gem_submit_bo {
92 u32 flags;
93 struct etnaviv_gem_object *obj;
94 struct etnaviv_vram_mapping *mapping;
95};
96
97/* Created per submit-ioctl, to track bo's and cmdstream bufs, etc,
98 * associated with the cmdstream submission for synchronization (and
99 * make it easier to unwind when things go wrong, etc). This only
100 * lasts for the duration of the submit-ioctl.
101 */
102struct etnaviv_gem_submit {
103 struct drm_device *dev;
104 struct etnaviv_gpu *gpu;
105 struct ww_acquire_ctx ticket;
106 u32 fence;
107 unsigned int nr_bos;
108 struct etnaviv_gem_submit_bo bos[0];
109};
110
111int etnaviv_gem_wait_bo(struct etnaviv_gpu *gpu, struct drm_gem_object *obj,
112 struct timespec *timeout);
113int etnaviv_gem_new_private(struct drm_device *dev, size_t size, u32 flags,
114 struct reservation_object *robj, const struct etnaviv_gem_ops *ops,
115 struct etnaviv_gem_object **res);
116int etnaviv_gem_obj_add(struct drm_device *dev, struct drm_gem_object *obj);
117struct page **etnaviv_gem_get_pages(struct etnaviv_gem_object *obj);
118void etnaviv_gem_put_pages(struct etnaviv_gem_object *obj);
119
120struct etnaviv_vram_mapping *etnaviv_gem_mapping_get(
121 struct drm_gem_object *obj, struct etnaviv_gpu *gpu);
122void etnaviv_gem_mapping_reference(struct etnaviv_vram_mapping *mapping);
123void etnaviv_gem_mapping_unreference(struct etnaviv_vram_mapping *mapping);
124
125#endif /* __ETNAVIV_GEM_H__ */