From patchwork Fri Mar 8 13:47:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Terje Bergstrom X-Patchwork-Id: 2238141 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 42D8D4006E for ; Fri, 8 Mar 2013 13:57:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 04C54E6D4B for ; Fri, 8 Mar 2013 05:57:20 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from hqemgate03.nvidia.com (hqemgate03.nvidia.com [216.228.121.140]) by gabe.freedesktop.org (Postfix) with ESMTP id E3CC0E6D3A for ; Fri, 8 Mar 2013 05:48:35 -0800 (PST) Received: from hqnvupgp08.nvidia.com (Not Verified[216.228.121.13]) by hqemgate03.nvidia.com id ; Fri, 08 Mar 2013 05:53:32 -0800 Received: from hqemhub03.nvidia.com ([172.17.108.22]) by hqnvupgp08.nvidia.com (PGP Universal service); Fri, 08 Mar 2013 05:42:13 -0800 X-PGP-Universal: processed; by hqnvupgp08.nvidia.com on Fri, 08 Mar 2013 05:42:13 -0800 Received: from deemhub01.nvidia.com (10.21.69.137) by hqemhub03.nvidia.com (172.20.150.15) with Microsoft SMTP Server (TLS) id 8.3.298.1; Fri, 8 Mar 2013 05:48:24 -0800 Received: from tbergstrom-desktop.Nvidia.com (10.21.65.27) by deemhub01.nvidia.com (10.21.69.137) with Microsoft SMTP Server id 8.3.298.1; Fri, 8 Mar 2013 14:48:19 +0100 From: Terje Bergstrom To: , , , Subject: [PATCHv6 8/9] gpu: host1x: drm: Add CMA ops for host1x driver Date: Fri, 8 Mar 2013 15:47:00 +0200 Message-ID: <1362750421-18080-9-git-send-email-tbergstrom@nvidia.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1362750421-18080-1-git-send-email-tbergstrom@nvidia.com> References: <1362750421-18080-1-git-send-email-tbergstrom@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 Cc: Terje Bergstrom , linux-kernel@vger.kernel.org, amerilainen@nvidia.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org From: Arto Merilainen This patch adds CMA memory operations for host1x driver. This allows usage of CMA buffers inside host1x driver. Signed-off-by: Arto Merilainen Signed-off-by: Terje Bergstrom --- drivers/gpu/host1x/Makefile | 1 + drivers/gpu/host1x/drm/cma.c | 87 ++++++++++++++++++++++++++++++++++++++++++ drivers/gpu/host1x/drm/cma.h | 26 +++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 drivers/gpu/host1x/drm/cma.c create mode 100644 drivers/gpu/host1x/drm/cma.h diff --git a/drivers/gpu/host1x/Makefile b/drivers/gpu/host1x/Makefile index ad39fef..d1d7e35 100644 --- a/drivers/gpu/host1x/Makefile +++ b/drivers/gpu/host1x/Makefile @@ -16,4 +16,5 @@ ccflags-$(CONFIG_DRM_TEGRA_DEBUG) += -DDEBUG host1x-$(CONFIG_DRM_TEGRA) += drm/drm.o drm/fb.o drm/dc.o host1x-$(CONFIG_DRM_TEGRA) += drm/output.o drm/rgb.o drm/hdmi.o +host1x-$(CONFIG_DRM_TEGRA) += drm/cma.o obj-$(CONFIG_TEGRA_HOST1X) += host1x.o diff --git a/drivers/gpu/host1x/drm/cma.c b/drivers/gpu/host1x/drm/cma.c new file mode 100644 index 0000000..1c5d000 --- /dev/null +++ b/drivers/gpu/host1x/drm/cma.c @@ -0,0 +1,87 @@ +/* + * Tegra host1x CMA support + * + * Copyright (c) 2012-2013, NVIDIA Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include + +#include "memmgr.h" + +static void cma_put(void *handle_data) +{ + struct drm_gem_cma_object *obj = handle_data; + struct drm_device *drm = obj->base.dev; + + mutex_lock(&drm->struct_mutex); + drm_gem_object_unreference(&obj->base); + mutex_unlock(&drm->struct_mutex); +} + +static dma_addr_t cma_pin(void *handle_data, struct sg_table **sgt) +{ + struct drm_gem_cma_object *obj = handle_data; + return obj->paddr; +} + +static void cma_unpin(void *handle_data, struct sg_table *sgt) +{ +} + +static void *cma_mmap(void *handle_data) +{ + struct drm_gem_cma_object *obj = handle_data; + return obj->vaddr; +} + +static void cma_munmap(void *handle_data, void *addr) +{ +} + +static void *cma_kmap(void *handle_data, unsigned int pagenum) +{ + struct drm_gem_cma_object *obj = handle_data; + return obj->vaddr + pagenum * PAGE_SIZE; +} + +static void cma_kunmap(void *handle_data, unsigned int pagenum, void *addr) +{ +} + +static struct host1x_mem_handle *cma_get(void *handle_data) +{ + struct drm_gem_cma_object *obj = handle_data; + struct drm_device *drm = obj->base.dev; + + mutex_lock(&drm->struct_mutex); + drm_gem_object_reference(&obj->base); + mutex_unlock(&drm->struct_mutex); + + return obj->base.driver_private; +} + +const struct host1x_mem_op host1x_cma_ops = { + .get = cma_get, + .put = cma_put, + .pin = cma_pin, + .unpin = cma_unpin, + .mmap = cma_mmap, + .munmap = cma_munmap, + .kmap = cma_kmap, + .kunmap = cma_kunmap, +}; diff --git a/drivers/gpu/host1x/drm/cma.h b/drivers/gpu/host1x/drm/cma.h new file mode 100644 index 0000000..06aa0ba --- /dev/null +++ b/drivers/gpu/host1x/drm/cma.h @@ -0,0 +1,26 @@ +/* + * Tegra host1x cma memory manager + * + * Copyright (c) 2012-2013, NVIDIA Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __HOST1X_CMA_H +#define __HOST1X_CMA_H + +#include "memmgr.h" + +extern const struct host1x_mem_op host1x_cma_ops; + +#endif