From patchwork Tue Sep 23 13:46:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 4956581 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8A334BEEA5 for ; Tue, 23 Sep 2014 13:47:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5901520254 for ; Tue, 23 Sep 2014 13:47:23 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id D2EE320103 for ; Tue, 23 Sep 2014 13:47:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E43B86E579; Tue, 23 Sep 2014 06:47:19 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f176.google.com (mail-wi0-f176.google.com [209.85.212.176]) by gabe.freedesktop.org (Postfix) with ESMTP id 98BA46E575 for ; Tue, 23 Sep 2014 06:47:13 -0700 (PDT) Received: by mail-wi0-f176.google.com with SMTP id fb4so4888909wid.9 for ; Tue, 23 Sep 2014 06:47:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=Fd9sw3ja/QfoJQ7K2UmTLb6GjBlawAYILaYxJURU4Ak=; b=J6rADLNcnF46Ify9WrzMOHnKnhuZMLvwNUwlU1ZomP+GNzx5T8AjK0wUeMXzeP9hJ/ mJ1p56Gq7fOP0si2hrChtSOL04tjcwqQpcF9hVdSiv7bpP0NBCADxqXZ7loK43WfmFM8 AMZAfB1C07ZXPOw7YryFJh4GsZSmCmzZc+XdI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=Fd9sw3ja/QfoJQ7K2UmTLb6GjBlawAYILaYxJURU4Ak=; b=FOM9Du2BBjKYNpDjdUAtIZR8Gc/Vocbj9uKmhDmAotdNT0yQSmM6WgOM5kY6+Sk8lW GPbz3Vvs9WhPjGMLdZbqaBLzM7MXPHKJ7aBC3k0hU8M/Z7pQZDZEAeDLTrfFj3bOzc8H 4BBvTC63ueZx5ibgEx3DNw8tqe3drukrmHd1J0w6SziWlwlZ5yjmYVOJF5zpH5WVL6Cf QX5w/zUVoO/Ui7KsMnmvkFO/WFUiW+84mRC5BD0dxUCqJ598G3eYjAFefC2MnhGVSmLS IrFOtt7mF6ZFahb7encoQl/Zd0siGrJmvdwQVPZ5X+TxNySiPDlI1aTabSlyNoZ0vFkY X1rw== X-Gm-Message-State: ALoCoQm7y2PrgUy6wZTY43toIbGKPFRsWPdKBVB9C7MD/ux8x8JO6uUOeduqEhz8T0DK16gtpomQ X-Received: by 10.194.48.44 with SMTP id i12mr11855648wjn.83.1411480032665; Tue, 23 Sep 2014 06:47:12 -0700 (PDT) Received: from phenom.ffwll.local (84-73-67-144.dclient.hispeed.ch. [84.73.67.144]) by mx.google.com with ESMTPSA id wx3sm15982504wjc.19.2014.09.23.06.47.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 23 Sep 2014 06:47:11 -0700 (PDT) From: Daniel Vetter To: DRI Development Subject: [PATCH 7/8] drm: Extract Date: Tue, 23 Sep 2014 15:46:53 +0200 Message-Id: <1411480014-10138-8-git-send-email-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1411480014-10138-1-git-send-email-daniel.vetter@ffwll.ch> References: <1411480014-10138-1-git-send-email-daniel.vetter@ffwll.ch> MIME-Version: 1.0 Cc: Daniel Vetter , Daniel Vetter X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP v2: Don't forget git add, noticed by David. Cc: David Herrmann Signed-off-by: Daniel Vetter Acked-by: David Herrmann --- drivers/gpu/drm/armada/armada_gem.h | 2 + drivers/gpu/drm/ast/ast_drv.h | 2 + drivers/gpu/drm/bochs/bochs.h | 2 + drivers/gpu/drm/cirrus/cirrus_drv.h | 2 + drivers/gpu/drm/drm_gem.c | 1 + drivers/gpu/drm/drm_info.c | 2 + drivers/gpu/drm/drm_prime.c | 2 + drivers/gpu/drm/exynos/exynos_drm_gem.h | 2 + drivers/gpu/drm/gma500/gtt.h | 1 + drivers/gpu/drm/i915/i915_drv.h | 1 + drivers/gpu/drm/mgag200/mgag200_drv.h | 2 + drivers/gpu/drm/msm/msm_drv.h | 1 + drivers/gpu/drm/nouveau/nouveau_bo.h | 2 + drivers/gpu/drm/omapdrm/omap_drv.h | 1 + drivers/gpu/drm/qxl/qxl_drv.h | 2 + drivers/gpu/drm/radeon/radeon.h | 2 + drivers/gpu/drm/radeon/radeon_drv.c | 2 + drivers/gpu/drm/tegra/gem.h | 1 + drivers/gpu/drm/udl/udl_drv.h | 1 + include/drm/drmP.h | 148 +------------------------- include/drm/drm_gem.h | 183 ++++++++++++++++++++++++++++++++ include/drm/drm_gem_cma_helper.h | 1 + 22 files changed, 216 insertions(+), 147 deletions(-) create mode 100644 include/drm/drm_gem.h diff --git a/drivers/gpu/drm/armada/armada_gem.h b/drivers/gpu/drm/armada/armada_gem.h index 00b6cd461a03..b000ea3a829a 100644 --- a/drivers/gpu/drm/armada/armada_gem.h +++ b/drivers/gpu/drm/armada/armada_gem.h @@ -8,6 +8,8 @@ #ifndef ARMADA_GEM_H #define ARMADA_GEM_H +#include + /* GEM */ struct armada_gem_object { struct drm_gem_object obj; diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h index 7485ff945ca9..86205a28e56b 100644 --- a/drivers/gpu/drm/ast/ast_drv.h +++ b/drivers/gpu/drm/ast/ast_drv.h @@ -36,6 +36,8 @@ #include #include +#include + #include #include diff --git a/drivers/gpu/drm/bochs/bochs.h b/drivers/gpu/drm/bochs/bochs.h index 4f6e7b3a3635..71f2687fc3cc 100644 --- a/drivers/gpu/drm/bochs/bochs.h +++ b/drivers/gpu/drm/bochs/bochs.h @@ -7,6 +7,8 @@ #include #include +#include + #include #include diff --git a/drivers/gpu/drm/cirrus/cirrus_drv.h b/drivers/gpu/drm/cirrus/cirrus_drv.h index dd2cfc9024aa..d44e69daa239 100644 --- a/drivers/gpu/drm/cirrus/cirrus_drv.h +++ b/drivers/gpu/drm/cirrus/cirrus_drv.h @@ -21,6 +21,8 @@ #include #include +#include + #define DRIVER_AUTHOR "Matthew Garrett" #define DRIVER_NAME "cirrus" diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index f9af78541505..cd45e45e2cce 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -38,6 +38,7 @@ #include #include #include +#include #include "drm_internal.h" /** @file drm_gem.c diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c index 0780541f7935..51efebd434f3 100644 --- a/drivers/gpu/drm/drm_info.c +++ b/drivers/gpu/drm/drm_info.c @@ -35,6 +35,8 @@ #include #include +#include + #include "drm_legacy.h" /** diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index 2807a771f505..7826de9da276 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -29,6 +29,8 @@ #include #include #include +#include + #include "drm_internal.h" /* diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.h b/drivers/gpu/drm/exynos/exynos_drm_gem.h index 1592c0ba7de8..74818b15e853 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_gem.h +++ b/drivers/gpu/drm/exynos/exynos_drm_gem.h @@ -12,6 +12,8 @@ #ifndef _EXYNOS_DRM_GEM_H_ #define _EXYNOS_DRM_GEM_H_ +#include + #define to_exynos_gem_obj(x) container_of(x,\ struct exynos_drm_gem_obj, base) diff --git a/drivers/gpu/drm/gma500/gtt.h b/drivers/gpu/drm/gma500/gtt.h index f5860a739bd8..cdbb350c9d5d 100644 --- a/drivers/gpu/drm/gma500/gtt.h +++ b/drivers/gpu/drm/gma500/gtt.h @@ -21,6 +21,7 @@ #define _PSB_GTT_H_ #include +#include /* This wants cleaning up with respect to the psb_dev and un-needed stuff */ struct psb_gtt { diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 07dafa2c2d8c..e9f5765699b4 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -43,6 +43,7 @@ #include #include #include /* for struct drm_dma_handle */ +#include #include #include #include diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.h b/drivers/gpu/drm/mgag200/mgag200_drv.h index c03e347f3ffd..e9eea1d4e7c3 100644 --- a/drivers/gpu/drm/mgag200/mgag200_drv.h +++ b/drivers/gpu/drm/mgag200/mgag200_drv.h @@ -22,6 +22,8 @@ #include #include +#include + #include #include diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h index 8a2c5fd0893e..afaafd42dee7 100644 --- a/drivers/gpu/drm/msm/msm_drv.h +++ b/drivers/gpu/drm/msm/msm_drv.h @@ -51,6 +51,7 @@ static inline struct device *msm_iommu_get_ctx(const char *ctx_name) #include #include #include +#include struct msm_kms; struct msm_gpu; diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.h b/drivers/gpu/drm/nouveau/nouveau_bo.h index ae95b2d43b36..f238def41a92 100644 --- a/drivers/gpu/drm/nouveau/nouveau_bo.h +++ b/drivers/gpu/drm/nouveau/nouveau_bo.h @@ -1,6 +1,8 @@ #ifndef __NOUVEAU_BO_H__ #define __NOUVEAU_BO_H__ +#include + struct nouveau_channel; struct nouveau_fence; struct nouveau_vma; diff --git a/drivers/gpu/drm/omapdrm/omap_drv.h b/drivers/gpu/drm/omapdrm/omap_drv.h index 84d73a61b34b..60e47b33c801 100644 --- a/drivers/gpu/drm/omapdrm/omap_drv.h +++ b/drivers/gpu/drm/omapdrm/omap_drv.h @@ -26,6 +26,7 @@ #include #include #include +#include #include diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h index d75c0a9f674f..ff0772728eb0 100644 --- a/drivers/gpu/drm/qxl/qxl_drv.h +++ b/drivers/gpu/drm/qxl/qxl_drv.h @@ -43,6 +43,8 @@ #include #include +#include + /* just for ttm_validate_buffer */ #include diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h index 82b0e11ade89..ef91ebb7c671 100644 --- a/drivers/gpu/drm/radeon/radeon.h +++ b/drivers/gpu/drm/radeon/radeon.h @@ -74,6 +74,8 @@ #include #include +#include + #include "radeon_family.h" #include "radeon_mode.h" #include "radeon_reg.h" diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c index dd082049fd5b..de108427a197 100644 --- a/drivers/gpu/drm/radeon/radeon_drv.c +++ b/drivers/gpu/drm/radeon/radeon_drv.c @@ -38,6 +38,8 @@ #include #include #include +#include + #include "drm_crtc_helper.h" /* * KMS wrapper. diff --git a/drivers/gpu/drm/tegra/gem.h b/drivers/gpu/drm/tegra/gem.h index 43a25c853357..6538b56780c2 100644 --- a/drivers/gpu/drm/tegra/gem.h +++ b/drivers/gpu/drm/tegra/gem.h @@ -15,6 +15,7 @@ #include #include +#include #define TEGRA_BO_BOTTOM_UP (1 << 0) diff --git a/drivers/gpu/drm/udl/udl_drv.h b/drivers/gpu/drm/udl/udl_drv.h index 51e10ee77f39..c7490a2489a7 100644 --- a/drivers/gpu/drm/udl/udl_drv.h +++ b/drivers/gpu/drm/udl/udl_drv.h @@ -15,6 +15,7 @@ #define UDL_DRV_H #include +#include #define DRIVER_NAME "udl" #define DRIVER_DESC "DisplayLink" diff --git a/include/drm/drmP.h b/include/drm/drmP.h index 9130c8bd9e09..d46efbc255ed 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -82,6 +82,7 @@ struct drm_agp_head; struct drm_local_map; struct drm_device_dma; struct drm_dma_handle; +struct drm_gem_object; struct device_node; struct videomode; @@ -331,93 +332,6 @@ struct drm_lock_data { }; /** - * This structure defines the drm_mm memory object, which will be used by the - * DRM for its buffer objects. - */ -struct drm_gem_object { - /** Reference count of this object */ - struct kref refcount; - - /** - * handle_count - gem file_priv handle count of this object - * - * Each handle also holds a reference. Note that when the handle_count - * drops to 0 any global names (e.g. the id in the flink namespace) will - * be cleared. - * - * Protected by dev->object_name_lock. - * */ - unsigned handle_count; - - /** Related drm device */ - struct drm_device *dev; - - /** File representing the shmem storage */ - struct file *filp; - - /* Mapping info for this object */ - struct drm_vma_offset_node vma_node; - - /** - * Size of the object, in bytes. Immutable over the object's - * lifetime. - */ - size_t size; - - /** - * Global name for this object, starts at 1. 0 means unnamed. - * Access is covered by the object_name_lock in the related drm_device - */ - int name; - - /** - * Memory domains. These monitor which caches contain read/write data - * related to the object. When transitioning from one set of domains - * to another, the driver is called to ensure that caches are suitably - * flushed and invalidated - */ - uint32_t read_domains; - uint32_t write_domain; - - /** - * While validating an exec operation, the - * new read/write domain values are computed here. - * They will be transferred to the above values - * at the point that any cache flushing occurs - */ - uint32_t pending_read_domains; - uint32_t pending_write_domain; - - /** - * dma_buf - dma buf associated with this GEM object - * - * Pointer to the dma-buf associated with this gem object (either - * through importing or exporting). We break the resulting reference - * loop when the last gem handle for this object is released. - * - * Protected by obj->object_name_lock - */ - struct dma_buf *dma_buf; - - /** - * import_attach - dma buf attachment backing this object - * - * Any foreign dma_buf imported as a gem object has this set to the - * attachment point for the device. This is invariant over the lifetime - * of a gem object. - * - * The driver's ->gem_free_object callback is responsible for cleaning - * up the dma_buf attachment and references acquired at import time. - * - * Note that the drm gem/prime core does not depend upon drivers setting - * this field any more. So for drivers where this doesn't make sense - * (e.g. virtual devices or a displaylink behind an usb bus) they can - * simply leave it as NULL. - */ - struct dma_buf_attachment *import_attach; -}; - -/** * struct drm_master - drm master structure * * @refcount: Refcount for this master object. @@ -1073,10 +987,6 @@ extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page ** extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, int nr_pages); extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg); -int drm_gem_dumb_destroy(struct drm_file *file, - struct drm_device *dev, - uint32_t handle); - extern struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev, size_t size, size_t align); @@ -1085,62 +995,6 @@ extern void drm_pci_free(struct drm_device *dev, struct drm_dma_handle * dmah); /* sysfs support (drm_sysfs.c) */ extern void drm_sysfs_hotplug_event(struct drm_device *dev); -/* Graphics Execution Manager library functions (drm_gem.c) */ -void drm_gem_object_release(struct drm_gem_object *obj); -void drm_gem_object_free(struct kref *kref); -int drm_gem_object_init(struct drm_device *dev, - struct drm_gem_object *obj, size_t size); -void drm_gem_private_object_init(struct drm_device *dev, - struct drm_gem_object *obj, size_t size); -void drm_gem_vm_open(struct vm_area_struct *vma); -void drm_gem_vm_close(struct vm_area_struct *vma); -int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size, - struct vm_area_struct *vma); -int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma); - -static inline void -drm_gem_object_reference(struct drm_gem_object *obj) -{ - kref_get(&obj->refcount); -} - -static inline void -drm_gem_object_unreference(struct drm_gem_object *obj) -{ - if (obj != NULL) - kref_put(&obj->refcount, drm_gem_object_free); -} - -static inline void -drm_gem_object_unreference_unlocked(struct drm_gem_object *obj) -{ - if (obj && !atomic_add_unless(&obj->refcount.refcount, -1, 1)) { - struct drm_device *dev = obj->dev; - - mutex_lock(&dev->struct_mutex); - if (likely(atomic_dec_and_test(&obj->refcount.refcount))) - drm_gem_object_free(&obj->refcount); - mutex_unlock(&dev->struct_mutex); - } -} - -int drm_gem_handle_create(struct drm_file *file_priv, - struct drm_gem_object *obj, - u32 *handlep); -int drm_gem_handle_delete(struct drm_file *filp, u32 handle); - - -void drm_gem_free_mmap_offset(struct drm_gem_object *obj); -int drm_gem_create_mmap_offset(struct drm_gem_object *obj); -int drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size); - -struct page **drm_gem_get_pages(struct drm_gem_object *obj); -void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages, - bool dirty, bool accessed); - -struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev, - struct drm_file *filp, - u32 handle); struct drm_device *drm_dev_alloc(struct drm_driver *driver, struct device *parent); diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h new file mode 100644 index 000000000000..1e6ae1458f7a --- /dev/null +++ b/include/drm/drm_gem.h @@ -0,0 +1,183 @@ +#ifndef __DRM_GEM_H__ +#define __DRM_GEM_H__ + +/* + * GEM Graphics Execution Manager Driver Interfaces + * + * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. + * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. + * Copyright (c) 2009-2010, Code Aurora Forum. + * All rights reserved. + * Copyright © 2014 Intel Corporation + * Daniel Vetter + * + * Author: Rickard E. (Rik) Faith + * Author: Gareth Hughes + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * This structure defines the drm_mm memory object, which will be used by the + * DRM for its buffer objects. + */ +struct drm_gem_object { + /** Reference count of this object */ + struct kref refcount; + + /** + * handle_count - gem file_priv handle count of this object + * + * Each handle also holds a reference. Note that when the handle_count + * drops to 0 any global names (e.g. the id in the flink namespace) will + * be cleared. + * + * Protected by dev->object_name_lock. + * */ + unsigned handle_count; + + /** Related drm device */ + struct drm_device *dev; + + /** File representing the shmem storage */ + struct file *filp; + + /* Mapping info for this object */ + struct drm_vma_offset_node vma_node; + + /** + * Size of the object, in bytes. Immutable over the object's + * lifetime. + */ + size_t size; + + /** + * Global name for this object, starts at 1. 0 means unnamed. + * Access is covered by the object_name_lock in the related drm_device + */ + int name; + + /** + * Memory domains. These monitor which caches contain read/write data + * related to the object. When transitioning from one set of domains + * to another, the driver is called to ensure that caches are suitably + * flushed and invalidated + */ + uint32_t read_domains; + uint32_t write_domain; + + /** + * While validating an exec operation, the + * new read/write domain values are computed here. + * They will be transferred to the above values + * at the point that any cache flushing occurs + */ + uint32_t pending_read_domains; + uint32_t pending_write_domain; + + /** + * dma_buf - dma buf associated with this GEM object + * + * Pointer to the dma-buf associated with this gem object (either + * through importing or exporting). We break the resulting reference + * loop when the last gem handle for this object is released. + * + * Protected by obj->object_name_lock + */ + struct dma_buf *dma_buf; + + /** + * import_attach - dma buf attachment backing this object + * + * Any foreign dma_buf imported as a gem object has this set to the + * attachment point for the device. This is invariant over the lifetime + * of a gem object. + * + * The driver's ->gem_free_object callback is responsible for cleaning + * up the dma_buf attachment and references acquired at import time. + * + * Note that the drm gem/prime core does not depend upon drivers setting + * this field any more. So for drivers where this doesn't make sense + * (e.g. virtual devices or a displaylink behind an usb bus) they can + * simply leave it as NULL. + */ + struct dma_buf_attachment *import_attach; +}; + +void drm_gem_object_release(struct drm_gem_object *obj); +void drm_gem_object_free(struct kref *kref); +int drm_gem_object_init(struct drm_device *dev, + struct drm_gem_object *obj, size_t size); +void drm_gem_private_object_init(struct drm_device *dev, + struct drm_gem_object *obj, size_t size); +void drm_gem_vm_open(struct vm_area_struct *vma); +void drm_gem_vm_close(struct vm_area_struct *vma); +int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size, + struct vm_area_struct *vma); +int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma); + +static inline void +drm_gem_object_reference(struct drm_gem_object *obj) +{ + kref_get(&obj->refcount); +} + +static inline void +drm_gem_object_unreference(struct drm_gem_object *obj) +{ + if (obj != NULL) + kref_put(&obj->refcount, drm_gem_object_free); +} + +static inline void +drm_gem_object_unreference_unlocked(struct drm_gem_object *obj) +{ + if (obj && !atomic_add_unless(&obj->refcount.refcount, -1, 1)) { + struct drm_device *dev = obj->dev; + + mutex_lock(&dev->struct_mutex); + if (likely(atomic_dec_and_test(&obj->refcount.refcount))) + drm_gem_object_free(&obj->refcount); + mutex_unlock(&dev->struct_mutex); + } +} + +int drm_gem_handle_create(struct drm_file *file_priv, + struct drm_gem_object *obj, + u32 *handlep); +int drm_gem_handle_delete(struct drm_file *filp, u32 handle); + + +void drm_gem_free_mmap_offset(struct drm_gem_object *obj); +int drm_gem_create_mmap_offset(struct drm_gem_object *obj); +int drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size); + +struct page **drm_gem_get_pages(struct drm_gem_object *obj); +void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages, + bool dirty, bool accessed); + +struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev, + struct drm_file *filp, + u32 handle); +int drm_gem_dumb_destroy(struct drm_file *file, + struct drm_device *dev, + uint32_t handle); + +#endif /* __DRM_GEM_H__ */ diff --git a/include/drm/drm_gem_cma_helper.h b/include/drm/drm_gem_cma_helper.h index 2a3cea91606d..42f11f3a8d39 100644 --- a/include/drm/drm_gem_cma_helper.h +++ b/include/drm/drm_gem_cma_helper.h @@ -2,6 +2,7 @@ #define __DRM_GEM_CMA_HELPER_H__ #include +#include struct drm_gem_cma_object { struct drm_gem_object base;