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 21ee546cd3SJordan Crouse #include <linux/kref.h> 227198e6b0SRob Clark #include <linux/reservation.h> 23c8afe684SRob Clark #include "msm_drv.h" 24c8afe684SRob Clark 25072f1f91SRob Clark /* Additional internal-use only BO flags: */ 26072f1f91SRob Clark #define MSM_BO_STOLEN 0x10000000 /* try to use stolen/splash memory */ 27072f1f91SRob Clark 28667ce33eSRob Clark struct msm_gem_address_space { 29667ce33eSRob Clark const char *name; 30667ce33eSRob Clark /* NOTE: mm managed at the page level, size is in # of pages 31667ce33eSRob Clark * and position mm_node->start is in # of pages: 32667ce33eSRob Clark */ 33667ce33eSRob Clark struct drm_mm mm; 34667ce33eSRob Clark struct msm_mmu *mmu; 35ee546cd3SJordan Crouse struct kref kref; 368bdcd949SRob Clark int id; /* temporary */ 37667ce33eSRob Clark }; 38667ce33eSRob Clark 39667ce33eSRob Clark struct msm_gem_vma { 40667ce33eSRob Clark struct drm_mm_node node; 41667ce33eSRob Clark uint64_t iova; 42667ce33eSRob Clark }; 43667ce33eSRob Clark 44c8afe684SRob Clark struct msm_gem_object { 45c8afe684SRob Clark struct drm_gem_object base; 46c8afe684SRob Clark 47c8afe684SRob Clark uint32_t flags; 48c8afe684SRob Clark 494cd33c48SRob Clark /** 504cd33c48SRob Clark * Advice: are the backing pages purgeable? 514cd33c48SRob Clark */ 524cd33c48SRob Clark uint8_t madv; 534cd33c48SRob Clark 54e1e9db2cSRob Clark /** 55e1e9db2cSRob Clark * count of active vmap'ing 56e1e9db2cSRob Clark */ 57e1e9db2cSRob Clark uint8_t vmap_count; 58e1e9db2cSRob Clark 597198e6b0SRob Clark /* And object is either: 607198e6b0SRob Clark * inactive - on priv->inactive_list 617198e6b0SRob Clark * active - on one one of the gpu's active_list.. well, at 627198e6b0SRob Clark * least for now we don't have (I don't think) hw sync between 637198e6b0SRob Clark * 2d and 3d one devices which have both, meaning we need to 647198e6b0SRob Clark * block on submit if a bo is already on other ring 657198e6b0SRob Clark * 667198e6b0SRob Clark */ 67c8afe684SRob Clark struct list_head mm_list; 687198e6b0SRob Clark struct msm_gpu *gpu; /* non-null if active */ 697198e6b0SRob Clark 707198e6b0SRob Clark /* Transiently in the process of submit ioctl, objects associated 717198e6b0SRob Clark * with the submit are on submit->bo_list.. this only lasts for 727198e6b0SRob Clark * the duration of the ioctl, so one bo can never be on multiple 737198e6b0SRob Clark * submit lists. 747198e6b0SRob Clark */ 757198e6b0SRob Clark struct list_head submit_entry; 767198e6b0SRob Clark 77c8afe684SRob Clark struct page **pages; 78c8afe684SRob Clark struct sg_table *sgt; 79c8afe684SRob Clark void *vaddr; 80c8afe684SRob Clark 81667ce33eSRob Clark struct msm_gem_vma domain[NUM_DOMAINS]; 827198e6b0SRob Clark 837198e6b0SRob Clark /* normally (resv == &_resv) except for imported bo's */ 847198e6b0SRob Clark struct reservation_object *resv; 857198e6b0SRob Clark struct reservation_object _resv; 86871d812aSRob Clark 87871d812aSRob Clark /* For physically contiguous buffers. Used when we don't have 88072f1f91SRob Clark * an IOMMU. Also used for stolen/splashscreen buffer. 89871d812aSRob Clark */ 90871d812aSRob Clark struct drm_mm_node *vram_node; 91c8afe684SRob Clark }; 92c8afe684SRob Clark #define to_msm_bo(x) container_of(x, struct msm_gem_object, base) 93c8afe684SRob Clark 947198e6b0SRob Clark static inline bool is_active(struct msm_gem_object *msm_obj) 957198e6b0SRob Clark { 967198e6b0SRob Clark return msm_obj->gpu != NULL; 977198e6b0SRob Clark } 987198e6b0SRob Clark 9968209390SRob Clark static inline bool is_purgeable(struct msm_gem_object *msm_obj) 10068209390SRob Clark { 10168209390SRob Clark return (msm_obj->madv == MSM_MADV_DONTNEED) && msm_obj->sgt && 10268209390SRob Clark !msm_obj->base.dma_buf && !msm_obj->base.import_attach; 10368209390SRob Clark } 10468209390SRob Clark 105e1e9db2cSRob Clark static inline bool is_vunmapable(struct msm_gem_object *msm_obj) 106e1e9db2cSRob Clark { 107e1e9db2cSRob Clark return (msm_obj->vmap_count == 0) && msm_obj->vaddr; 108e1e9db2cSRob Clark } 109e1e9db2cSRob Clark 1107198e6b0SRob Clark /* Created per submit-ioctl, to track bo's and cmdstream bufs, etc, 1117198e6b0SRob Clark * associated with the cmdstream submission for synchronization (and 1127198e6b0SRob Clark * make it easier to unwind when things go wrong, etc). This only 1137198e6b0SRob Clark * lasts for the duration of the submit-ioctl. 1147198e6b0SRob Clark */ 1157198e6b0SRob Clark struct msm_gem_submit { 1167198e6b0SRob Clark struct drm_device *dev; 1177198e6b0SRob Clark struct msm_gpu *gpu; 1181a370be9SRob Clark struct list_head node; /* node in gpu submit_list */ 1197198e6b0SRob Clark struct list_head bo_list; 1207198e6b0SRob Clark struct ww_acquire_ctx ticket; 121f54d1867SChris Wilson struct dma_fence *fence; 1224816b626SRob Clark struct pid *pid; /* submitting process */ 123340faef2SRob Clark bool valid; /* true if no cmdstream patching needed */ 1247198e6b0SRob Clark unsigned int nr_cmds; 1257198e6b0SRob Clark unsigned int nr_bos; 1267198e6b0SRob Clark struct { 1277198e6b0SRob Clark uint32_t type; 1287198e6b0SRob Clark uint32_t size; /* in dwords */ 12978babc16SRob Clark uint64_t iova; 130a7d3c950SRob Clark uint32_t idx; /* cmdstream buffer idx in bos[] */ 1316b597ce2SRob Clark } *cmd; /* array of size nr_cmds */ 1327198e6b0SRob Clark struct { 1337198e6b0SRob Clark uint32_t flags; 1347198e6b0SRob Clark struct msm_gem_object *obj; 13578babc16SRob Clark uint64_t iova; 1367198e6b0SRob Clark } bos[0]; 1377198e6b0SRob Clark }; 1387198e6b0SRob Clark 139c8afe684SRob Clark #endif /* __MSM_GEM_H__ */ 140