From patchwork Fri May 18 23:52:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 10414123 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A228260365 for ; Mon, 21 May 2018 08:21:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93D80287A7 for ; Mon, 21 May 2018 08:21:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 889CE287B1; Mon, 21 May 2018 08:21:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2FAB8287A7 for ; Mon, 21 May 2018 08:21:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AD6866E343; Mon, 21 May 2018 08:19:14 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0A8816EF6C for ; Fri, 18 May 2018 23:54:09 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id j4-v6so16690768wme.1 for ; Fri, 18 May 2018 16:54:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=gRkeKGFRNzNFlmrXdcgGRSPEUUIHMDG8Bm2lKLnVqDQ=; b=jaJ5vJoRMLx/u2aK+yT2Dikf7wMI81J3xx2RAHHrepNRNR/2xBPpBVhADCvi5c3nOq tlJj+2GAvVmM7xCHGNoZFT/oed0z1PAI6ayjTYEZOfgejquK3vP2mB1rzcvSullTAkFF 4r4g0p8XhNuzbyB9VsL74OuT0sW/Ud7efvOfQyNFOTUSLzahcUAV7cOHO0MdxjR/KgWM XM4/9vrQLq0rTK8LRncnIzmWV2U+rT6phcaAiVTGjn/DbEBR/ripZwNpEJE0Bibo8Ey7 mgjRT+IQDC/2hg/ZAPY6jGT9Df67dVnkCfotTsA4Mlu/N5DRcHgmHRacbLdp5tOMN7wG so0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=gRkeKGFRNzNFlmrXdcgGRSPEUUIHMDG8Bm2lKLnVqDQ=; b=jyEluwyVuJHm9POEKMyfVd/EqcNDeGCT6CuEXIHzqI8dMGEviVqVgK18/ZN+5vDbvV 4/eXQ61U9tp6QEdoIw2RmCgq8uJRIv9NZ0vnxnxT2zsdSEBgHFyPLpQKU08PRLeICBgL QiTNsYUcaLt6A8T/lDzSlWgW20X98YckqwoTuL++dfqjzsh3+8Z4eiQ7buo1acfuulF3 Vk6PvT9GSJFR8zoNY3T8lPVlAl04X3oVMiVero9atHciALVMAq+XbPFTc5ck+69OzHGv jwHwnyNL091k+FDBBqewv7G7f4fBDRylXWZbsGhGdsMOAbXVInRRH9vqYbVema8VS6qn fuCA== X-Gm-Message-State: ALKqPwdaU98kDfM6cXDOYVbfpDhaZkRVNzFy0GqYyuGXMChCs5Ldtfw/ tEOEkqYj1o25H8RszzQ2uHc= X-Google-Smtp-Source: AB8JxZos294+e2kuDkmMoRDEk4FYGzlJOOmB1RAHegHzSgnje+wHVkGC92TLx92l4rjhelMzUSPR1w== X-Received: by 2002:a1c:c405:: with SMTP id u5-v6mr6278886wmf.46.1526687648570; Fri, 18 May 2018 16:54:08 -0700 (PDT) Received: from localhost.localdomain (109-252-91-60.nat.spd-mgts.ru. [109.252.91.60]) by smtp.gmail.com with ESMTPSA id 76-v6sm5237202wmj.0.2018.05.18.16.54.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 May 2018 16:54:07 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Mikko Perttunen Subject: [PATCH v1] gpu: host1x: Utilize IOMMU mapping for firewall-copied buffers Date: Sat, 19 May 2018 02:52:31 +0300 Message-Id: <20180518235231.9274-1-digetx@gmail.com> X-Mailer: git-send-email 2.17.0 X-Mailman-Approved-At: Mon, 21 May 2018 08:18:08 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Map firewall-copied buffers into Host1x's IOVA space, otherwise Host1x CDMA can't access the command buffers and all submitted jobs fail if IOMMU and Host1x firewall are enabled in the kernels config. Signed-off-by: Dmitry Osipenko --- drivers/gpu/host1x/job.c | 58 +++++++++++++++++++++++++++++++++++----- include/linux/host1x.h | 4 ++- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/host1x/job.c b/drivers/gpu/host1x/job.c index e2f4a4d93d20..57384a5b5059 100644 --- a/drivers/gpu/host1x/job.c +++ b/drivers/gpu/host1x/job.c @@ -449,10 +449,13 @@ static int validate(struct host1x_firewall *fw, struct host1x_job_gather *g) static inline int copy_gathers(struct host1x_job *job, struct device *dev) { + struct host1x *host = dev_get_drvdata(job->channel->dev->parent); struct host1x_firewall fw; + dma_addr_t dma_addr; size_t size = 0; size_t offset = 0; unsigned int i; + int err; fw.job = job; fw.dev = dev; @@ -466,23 +469,55 @@ static inline int copy_gathers(struct host1x_job *job, struct device *dev) size += g->words * sizeof(u32); } + if (host->domain) + size = iova_align(&host->iova, size); + /* * Try a non-blocking allocation from a higher priority pools first, * as awaiting for the allocation here is a major performance hit. */ - job->gather_copy_mapped = dma_alloc_wc(dev, size, &job->gather_copy, - GFP_NOWAIT); + job->gather_copy_mapped = dma_alloc_wc(dev, size, + &job->gather_copy_phys, + GFP_NOWAIT); /* the higher priority allocation failed, try the generic-blocking */ if (!job->gather_copy_mapped) job->gather_copy_mapped = dma_alloc_wc(dev, size, - &job->gather_copy, + &job->gather_copy_phys, GFP_KERNEL); if (!job->gather_copy_mapped) return -ENOMEM; job->gather_copy_size = size; + if (host->domain) { + unsigned long shift; + + shift = iova_shift(&host->iova); + job->gather_copy_iova_alloc = alloc_iova( + &host->iova, size >> shift, + host->iova_end >> shift, true); + if (!job->gather_copy_iova_alloc) + return -ENOMEM; + + job->gather_copy_iova = iova_dma_addr( + &host->iova, job->gather_copy_iova_alloc); + + err = iommu_map(host->domain, + job->gather_copy_iova, + job->gather_copy_phys, + size, IOMMU_READ); + if (err) { + __free_iova(&host->iova, job->gather_copy_iova_alloc); + job->gather_copy_iova_alloc = NULL; + return err; + } + + dma_addr = job->gather_copy_iova; + } else { + dma_addr = job->gather_copy_phys; + } + for (i = 0; i < job->num_gathers; i++) { struct host1x_job_gather *g = &job->gathers[i]; void *gather; @@ -494,7 +529,7 @@ static inline int copy_gathers(struct host1x_job *job, struct device *dev) host1x_bo_munmap(g->bo, gather); /* Store the location in the buffer */ - g->base = job->gather_copy; + g->base = dma_addr; g->offset = offset; /* Validate the job */ @@ -582,9 +617,20 @@ void host1x_job_unpin(struct host1x_job *job) job->num_unpins = 0; - if (job->gather_copy_size) + if (job->gather_copy_size) { dma_free_wc(job->channel->dev, job->gather_copy_size, - job->gather_copy_mapped, job->gather_copy); + job->gather_copy_mapped, job->gather_copy_phys); + + if (job->gather_copy_iova_alloc) { + iommu_unmap(host->domain, + job->gather_copy_iova, + job->gather_copy_size); + + __free_iova(&host->iova, job->gather_copy_iova_alloc); + + job->gather_copy_iova_alloc = NULL; + } + } } EXPORT_SYMBOL(host1x_job_unpin); diff --git a/include/linux/host1x.h b/include/linux/host1x.h index 57d26406bdfd..536a678f81d4 100644 --- a/include/linux/host1x.h +++ b/include/linux/host1x.h @@ -235,8 +235,10 @@ struct host1x_job { unsigned int num_slots; /* Copy of gathers */ + struct iova *gather_copy_iova_alloc; size_t gather_copy_size; - dma_addr_t gather_copy; + dma_addr_t gather_copy_iova; + dma_addr_t gather_copy_phys; u8 *gather_copy_mapped; /* Check if register is marked as an address reg */