Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp64701pxb; Mon, 2 Nov 2020 14:09:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJyZdmDHiBoh1OEu5Q52ctx5AxuY7QvLcSiTGgSb7xFHVp5iSmly8ffV5uHVqJ54bUrOotxC X-Received: by 2002:a17:906:1a11:: with SMTP id i17mr16913678ejf.381.1604354951171; Mon, 02 Nov 2020 14:09:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604354951; cv=none; d=google.com; s=arc-20160816; b=BpgTP+b0y+7dLU9K7mo1gjh8fOESicrh5HYGb2syLyBJ5S4Dtr2C4pXdzH+2axDRoI nHg2hL14ffJH5Dd2NYB2zu42E4bL257Gwa5PebV21O8qy5IuEx6yBOjbM5RBKqetf5zk DzbnQH7ashvRzaFO8XJCo4P0nkSAhmwCHWrAPU+brxk5V0kZsH6flZC+CvAQ9VsJ4Qfs CktmBtSuam4AKTBljGBR3wVuUchttEBc9zy9OTcvHIX/0hwZAGqYoIpIMfquARb2jSqI RExcB99uIzKpjNnLBzPfuGbhWTWpE0v3TibfWqN/RIp+LCqocfOLiQtCpT7FXbK+7eFn LlRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Do14nDGORjH5ENxwar43x4Lf+doxaheMWErGcBcnV+s=; b=MouBPIg8rV/A7dvhwxbj/pVHMshgtkJy78SE+Kf7DMQQJO8bxngnDWazfWWI+d6RT1 uAxBuQ5XplKK803FVFvk2/Bgvx7USJZ2fYIurKCKmawaU/QcLIWQCvJyXcUiouknamvu KXtQjmgBBC/XgELO59LtGahOK22vZ+b3agP4lbE1uCN3Dw7/WmOBhKRLUgpzBWqnTwBU IvlGWsm4OQ5VaymeuY/aBI8ZT3k2u2XvNAVU9CbEwhNWAQqLrnnLh2akgwAzKPq/EQS+ 3ZSPKk1B/IkWsiZjHUDyO6UZiZvHGUu0SRwDXs4Lib19SEmCrAoUWuEADYhhxJGdPgs8 OSSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v8si7101651edf.28.2020.11.02.14.08.48; Mon, 02 Nov 2020 14:09:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725997AbgKBWHW (ORCPT + 99 others); Mon, 2 Nov 2020 17:07:22 -0500 Received: from aposti.net ([89.234.176.197]:44698 "EHLO aposti.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725933AbgKBWHV (ORCPT ); Mon, 2 Nov 2020 17:07:21 -0500 From: Paul Cercueil To: David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann Cc: od@zcrc.me, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Paul Cercueil Subject: [PATCH 1/5] drm: Add and export function drm_gem_cma_create_noncoherent Date: Mon, 2 Nov 2020 22:06:47 +0000 Message-Id: <20201102220651.22069-2-paul@crapouillou.net> In-Reply-To: <20201102220651.22069-1-paul@crapouillou.net> References: <20201102220651.22069-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This function can be used by drivers that need to create a GEM object with non-coherent backing memory. Signed-off-by: Paul Cercueil --- drivers/gpu/drm/drm_gem_cma_helper.c | 71 +++++++++++++++++++++------- include/drm/drm_gem_cma_helper.h | 2 + 2 files changed, 56 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c index 2165633c9b9e..717871d741fb 100644 --- a/drivers/gpu/drm/drm_gem_cma_helper.c +++ b/drivers/gpu/drm/drm_gem_cma_helper.c @@ -77,21 +77,10 @@ __drm_gem_cma_create(struct drm_device *drm, size_t size) return ERR_PTR(ret); } -/** - * drm_gem_cma_create - allocate an object with the given size - * @drm: DRM device - * @size: size of the object to allocate - * - * This function creates a CMA GEM object and allocates a contiguous chunk of - * memory as backing store. The backing memory has the writecombine attribute - * set. - * - * Returns: - * A struct drm_gem_cma_object * on success or an ERR_PTR()-encoded negative - * error code on failure. - */ -struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm, - size_t size) +static struct drm_gem_cma_object * +drm_gem_cma_create_with_cache_param(struct drm_device *drm, + size_t size, + bool noncoherent) { struct drm_gem_cma_object *cma_obj; int ret; @@ -102,8 +91,16 @@ struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm, if (IS_ERR(cma_obj)) return cma_obj; - cma_obj->vaddr = dma_alloc_wc(drm->dev, size, &cma_obj->paddr, - GFP_KERNEL | __GFP_NOWARN); + if (noncoherent) { + cma_obj->vaddr = dma_alloc_noncoherent(drm->dev, size, + &cma_obj->paddr, + DMA_TO_DEVICE, + GFP_KERNEL | __GFP_NOWARN); + + } else { + cma_obj->vaddr = dma_alloc_wc(drm->dev, size, &cma_obj->paddr, + GFP_KERNEL | __GFP_NOWARN); + } if (!cma_obj->vaddr) { drm_dbg(drm, "failed to allocate buffer with size %zu\n", size); @@ -117,8 +114,48 @@ struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm, drm_gem_object_put(&cma_obj->base); return ERR_PTR(ret); } + +/** + * drm_gem_cma_create - allocate an object with the given size + * @drm: DRM device + * @size: size of the object to allocate + * + * This function creates a CMA GEM object and allocates a contiguous chunk of + * memory as backing store. The backing memory has the writecombine attribute + * set. + * + * Returns: + * A struct drm_gem_cma_object * on success or an ERR_PTR()-encoded negative + * error code on failure. + */ +struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm, + size_t size) +{ + return drm_gem_cma_create_with_cache_param(drm, size, false); +} EXPORT_SYMBOL_GPL(drm_gem_cma_create); +/** + * drm_gem_cma_create_noncoherent - allocate an object with the given size + * and non-coherent cache attribute + * @drm: DRM device + * @size: size of the object to allocate + * + * This function creates a CMA GEM object and allocates a contiguous chunk of + * memory as backing store. The backing memory has the noncoherent attribute + * set. + * + * Returns: + * A struct drm_gem_cma_object * on success or an ERR_PTR()-encoded negative + * error code on failure. + */ +struct drm_gem_cma_object * +drm_gem_cma_create_noncoherent(struct drm_device *drm, size_t size) +{ + return drm_gem_cma_create_with_cache_param(drm, size, true); +} +EXPORT_SYMBOL_GPL(drm_gem_cma_create_noncoherent); + /** * drm_gem_cma_create_with_handle - allocate an object with the given size and * return a GEM handle to it diff --git a/include/drm/drm_gem_cma_helper.h b/include/drm/drm_gem_cma_helper.h index 2bfa2502607a..071c73ad7177 100644 --- a/include/drm/drm_gem_cma_helper.h +++ b/include/drm/drm_gem_cma_helper.h @@ -82,6 +82,8 @@ int drm_gem_cma_mmap(struct file *filp, struct vm_area_struct *vma); /* allocate physical memory */ struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm, size_t size); +struct drm_gem_cma_object * +drm_gem_cma_create_noncoherent(struct drm_device *drm, size_t size); extern const struct vm_operations_struct drm_gem_cma_vm_ops; -- 2.28.0