xref: /openbmc/linux/drivers/gpu/drm/msm/msm_gem.h (revision e1e9db2c)
1c8afe684SRob Clark /*
2c8afe684SRob Clark  * Copyright (C) 2013 Red Hat
3c8afe684SRob Clark  * Author: Rob Clark <robdclark@gmail.com>
4c8afe684SRob Clark  *
5c8afe684SRob Clark  * This program is free software; you can redistribute it and/or modify it
6c8afe684SRob Clark  * under the terms of the GNU General Public License version 2 as published by
7c8afe684SRob Clark  * the Free Software Foundation.
8c8afe684SRob Clark  *
9c8afe684SRob Clark  * This program is distributed in the hope that it will be useful, but WITHOUT
10c8afe684SRob Clark  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11c8afe684SRob Clark  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12c8afe684SRob Clark  * more details.
13c8afe684SRob Clark  *
14c8afe684SRob Clark  * You should have received a copy of the GNU General Public License along with
15c8afe684SRob Clark  * this program.  If not, see <http://www.gnu.org/licenses/>.
16c8afe684SRob Clark  */
17c8afe684SRob Clark 
18c8afe684SRob Clark #ifndef __MSM_GEM_H__
19c8afe684SRob Clark #define __MSM_GEM_H__
20c8afe684SRob Clark 
217198e6b0SRob Clark #include <linux/reservation.h>
22c8afe684SRob Clark #include "msm_drv.h"
23c8afe684SRob Clark 
24072f1f91SRob Clark /* Additional internal-use only BO flags: */
25072f1f91SRob Clark #define MSM_BO_STOLEN        0x10000000    /* try to use stolen/splash memory */
26072f1f91SRob Clark 
27c8afe684SRob Clark struct msm_gem_object {
28c8afe684SRob Clark 	struct drm_gem_object base;
29c8afe684SRob Clark 
30c8afe684SRob Clark 	uint32_t flags;
31c8afe684SRob Clark 
324cd33c48SRob Clark 	/**
334cd33c48SRob Clark 	 * Advice: are the backing pages purgeable?
344cd33c48SRob Clark 	 */
354cd33c48SRob Clark 	uint8_t madv;
364cd33c48SRob Clark 
37e1e9db2cSRob Clark 	/**
38e1e9db2cSRob Clark 	 * count of active vmap'ing
39e1e9db2cSRob Clark 	 */
40e1e9db2cSRob Clark 	uint8_t vmap_count;
41e1e9db2cSRob Clark 
427198e6b0SRob Clark 	/* And object is either:
437198e6b0SRob Clark 	 *  inactive - on priv->inactive_list
447198e6b0SRob Clark 	 *  active   - on one one of the gpu's active_list..  well, at
457198e6b0SRob Clark 	 *     least for now we don't have (I don't think) hw sync between
467198e6b0SRob Clark 	 *     2d and 3d one devices which have both, meaning we need to
477198e6b0SRob Clark 	 *     block on submit if a bo is already on other ring
487198e6b0SRob Clark 	 *
497198e6b0SRob Clark 	 */
50c8afe684SRob Clark 	struct list_head mm_list;
517198e6b0SRob Clark 	struct msm_gpu *gpu;     /* non-null if active */
527198e6b0SRob Clark 
537198e6b0SRob Clark 	/* Transiently in the process of submit ioctl, objects associated
547198e6b0SRob Clark 	 * with the submit are on submit->bo_list.. this only lasts for
557198e6b0SRob Clark 	 * the duration of the ioctl, so one bo can never be on multiple
567198e6b0SRob Clark 	 * submit lists.
577198e6b0SRob Clark 	 */
587198e6b0SRob Clark 	struct list_head submit_entry;
597198e6b0SRob Clark 
60c8afe684SRob Clark 	struct page **pages;
61c8afe684SRob Clark 	struct sg_table *sgt;
62c8afe684SRob Clark 	void *vaddr;
63c8afe684SRob Clark 
64c8afe684SRob Clark 	struct {
65c8afe684SRob Clark 		// XXX
66c8afe684SRob Clark 		uint32_t iova;
67c8afe684SRob Clark 	} domain[NUM_DOMAINS];
687198e6b0SRob Clark 
697198e6b0SRob Clark 	/* normally (resv == &_resv) except for imported bo's */
707198e6b0SRob Clark 	struct reservation_object *resv;
717198e6b0SRob Clark 	struct reservation_object _resv;
72871d812aSRob Clark 
73871d812aSRob Clark 	/* For physically contiguous buffers.  Used when we don't have
74072f1f91SRob Clark 	 * an IOMMU.  Also used for stolen/splashscreen buffer.
75871d812aSRob Clark 	 */
76871d812aSRob Clark 	struct drm_mm_node *vram_node;
77c8afe684SRob Clark };
78c8afe684SRob Clark #define to_msm_bo(x) container_of(x, struct msm_gem_object, base)
79c8afe684SRob Clark 
807198e6b0SRob Clark static inline bool is_active(struct msm_gem_object *msm_obj)
817198e6b0SRob Clark {
827198e6b0SRob Clark 	return msm_obj->gpu != NULL;
837198e6b0SRob Clark }
847198e6b0SRob Clark 
8568209390SRob Clark static inline bool is_purgeable(struct msm_gem_object *msm_obj)
8668209390SRob Clark {
8768209390SRob Clark 	return (msm_obj->madv == MSM_MADV_DONTNEED) && msm_obj->sgt &&
8868209390SRob Clark 			!msm_obj->base.dma_buf && !msm_obj->base.import_attach;
8968209390SRob Clark }
9068209390SRob Clark 
91e1e9db2cSRob Clark static inline bool is_vunmapable(struct msm_gem_object *msm_obj)
92e1e9db2cSRob Clark {
93e1e9db2cSRob Clark 	return (msm_obj->vmap_count == 0) && msm_obj->vaddr;
94e1e9db2cSRob Clark }
95e1e9db2cSRob Clark 
967198e6b0SRob Clark #define MAX_CMDS 4
977198e6b0SRob Clark 
987198e6b0SRob Clark /* Created per submit-ioctl, to track bo's and cmdstream bufs, etc,
997198e6b0SRob Clark  * associated with the cmdstream submission for synchronization (and
1007198e6b0SRob Clark  * make it easier to unwind when things go wrong, etc).  This only
1017198e6b0SRob Clark  * lasts for the duration of the submit-ioctl.
1027198e6b0SRob Clark  */
1037198e6b0SRob Clark struct msm_gem_submit {
1047198e6b0SRob Clark 	struct drm_device *dev;
1057198e6b0SRob Clark 	struct msm_gpu *gpu;
1061a370be9SRob Clark 	struct list_head node;   /* node in gpu submit_list */
1077198e6b0SRob Clark 	struct list_head bo_list;
1087198e6b0SRob Clark 	struct ww_acquire_ctx ticket;
109b6295f9aSRob Clark 	struct fence *fence;
1104816b626SRob Clark 	struct pid *pid;    /* submitting process */
111340faef2SRob Clark 	bool valid;         /* true if no cmdstream patching needed */
1127198e6b0SRob Clark 	unsigned int nr_cmds;
1137198e6b0SRob Clark 	unsigned int nr_bos;
1147198e6b0SRob Clark 	struct {
1157198e6b0SRob Clark 		uint32_t type;
1167198e6b0SRob Clark 		uint32_t size;  /* in dwords */
1177198e6b0SRob Clark 		uint32_t iova;
118a7d3c950SRob Clark 		uint32_t idx;   /* cmdstream buffer idx in bos[] */
1197198e6b0SRob Clark 	} cmd[MAX_CMDS];
1207198e6b0SRob Clark 	struct {
1217198e6b0SRob Clark 		uint32_t flags;
1227198e6b0SRob Clark 		struct msm_gem_object *obj;
1237198e6b0SRob Clark 		uint32_t iova;
1247198e6b0SRob Clark 	} bos[0];
1257198e6b0SRob Clark };
1267198e6b0SRob Clark 
127c8afe684SRob Clark #endif /* __MSM_GEM_H__ */
128