From patchwork Wed Mar 13 12:36:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Terje Bergstrom X-Patchwork-Id: 227272 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 773052C007C for ; Wed, 13 Mar 2013 23:38:56 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933094Ab3CMMf5 (ORCPT ); Wed, 13 Mar 2013 08:35:57 -0400 Received: from hqemgate04.nvidia.com ([216.228.121.35]:4280 "EHLO hqemgate04.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933007Ab3CMMfz (ORCPT ); Wed, 13 Mar 2013 08:35:55 -0400 Received: from hqnvupgp08.nvidia.com (Not Verified[216.228.121.13]) by hqemgate04.nvidia.com id ; Wed, 13 Mar 2013 05:35:46 -0700 Received: from hqemhub01.nvidia.com ([172.17.108.22]) by hqnvupgp08.nvidia.com (PGP Universal service); Wed, 13 Mar 2013 05:29:13 -0700 X-PGP-Universal: processed; by hqnvupgp08.nvidia.com on Wed, 13 Mar 2013 05:29:13 -0700 Received: from deemhub02.nvidia.com (10.21.69.138) by hqemhub01.nvidia.com (172.20.150.30) with Microsoft SMTP Server (TLS) id 8.3.298.1; Wed, 13 Mar 2013 05:35:50 -0700 Received: from tbergstrom-desktop.Nvidia.com (10.21.65.27) by deemhub02.nvidia.com (10.21.69.138) with Microsoft SMTP Server id 8.3.298.1; Wed, 13 Mar 2013 13:35:47 +0100 From: Terje Bergstrom To: , , , CC: , , Terje Bergstrom Subject: [PATCHv7 09/10] gpu: host1x: drm: Add CMA ops for host1x driver Date: Wed, 13 Mar 2013 14:36:25 +0200 Message-ID: <1363178186-2017-10-git-send-email-tbergstrom@nvidia.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1363178186-2017-1-git-send-email-tbergstrom@nvidia.com> References: <1363178186-2017-1-git-send-email-tbergstrom@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org From: Arto Merilainen This patch implements a CMA memory handler for the host1x driver. Signed-off-by: Arto Merilainen Signed-off-by: Terje Bergstrom --- drivers/gpu/host1x/Makefile | 1 + drivers/gpu/host1x/drm/cma.c | 93 ++++++++++++++++++++++++++++++++++++++++++ drivers/gpu/host1x/drm/cma.h | 35 ++++++++++++++++ 3 files changed, 129 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 9a6fc76..e85db5a 100644 --- a/drivers/gpu/host1x/Makefile +++ b/drivers/gpu/host1x/Makefile @@ -15,4 +15,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..cf86fce --- /dev/null +++ b/drivers/gpu/host1x/drm/cma.c @@ -0,0 +1,93 @@ +/* + * 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 "cma.h" +#include "host1x_bo.h" + +static void cma_put(struct host1x_bo *bo) +{ + struct tegra_drm_bo *cma_bo = + container_of(bo, struct tegra_drm_bo, base); + struct drm_device *drm = cma_bo->cma_obj.base.dev; + + mutex_lock(&drm->struct_mutex); + drm_gem_object_unreference(&cma_bo->cma_obj.base); + mutex_unlock(&drm->struct_mutex); +} + +static dma_addr_t cma_pin(struct host1x_bo *bo, struct sg_table **sgt) +{ + struct tegra_drm_bo *cma_bo = + container_of(bo, struct tegra_drm_bo, base); + return cma_bo->cma_obj.paddr; +} + +static void cma_unpin(struct host1x_bo *bo, struct sg_table *sgt) +{ +} + +static void *cma_mmap(struct host1x_bo *bo) +{ + struct tegra_drm_bo *cma_bo = + container_of(bo, struct tegra_drm_bo, base); + return cma_bo->cma_obj.vaddr; +} + +static void cma_munmap(struct host1x_bo *bo, void *addr) +{ +} + +static void *cma_kmap(struct host1x_bo *bo, unsigned int pagenum) +{ + struct tegra_drm_bo *cma_bo = + container_of(bo, struct tegra_drm_bo, base); + return cma_bo->cma_obj.vaddr + pagenum * PAGE_SIZE; +} + +static void cma_kunmap(struct host1x_bo *bo, unsigned int pagenum, void *addr) +{ +} + +static struct host1x_bo *cma_get(struct host1x_bo *bo) +{ + struct tegra_drm_bo *cma_bo = + container_of(bo, struct tegra_drm_bo, base); + struct drm_device *drm = cma_bo->cma_obj.base.dev; + + mutex_lock(&drm->struct_mutex); + drm_gem_object_reference(&cma_bo->cma_obj.base); + mutex_unlock(&drm->struct_mutex); + + return bo; +} + +const struct host1x_bo_ops tegra_drm_bo_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..f35cebd --- /dev/null +++ b/drivers/gpu/host1x/drm/cma.h @@ -0,0 +1,35 @@ +/* + * 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 +#include +#include + +#include "host1x_bo.h" + +struct tegra_drm_bo { + struct host1x_bo base; + struct drm_gem_cma_object cma_obj; +}; + +extern const struct host1x_bo_ops tegra_drm_bo_ops; + +#endif