From patchwork Fri Feb 2 19:09:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 10198031 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 4B1FA60388 for ; Fri, 2 Feb 2018 19:10:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B73728F55 for ; Fri, 2 Feb 2018 19:10:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 303AB28F59; Fri, 2 Feb 2018 19:10:06 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 AF1C228F55 for ; Fri, 2 Feb 2018 19:10:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A6EE26F0DB; Fri, 2 Feb 2018 19:09:56 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6E37A6F00D; Fri, 2 Feb 2018 19:09:54 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id f3so14466778wmc.1; Fri, 02 Feb 2018 11:09:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=K4mUdCwmAtzRwm7u+kCETBgAEE11lQr4mH6vRmjSPyg=; b=hXRoX2Bu1Bpkkt2+9MQ54gWEaJJ3MbvFSNpwBzhpBftUAR/3g+JxR1wQoT96cF5vvI 1p7/lXnnrdT2FlHSm6I+1RT0z88gI08TjHAQLEO4h142mae51GCsfxgN4PIt2sbG93xk q8ct1Vmp/9f9Vri1IYv2MWKVtkoK6sFa1vuuzHTcXeBk4/xvfnAVUyu1zPEkLG5l3Cu0 tbr/Rh5InbOhPAubtp5ID1tJudi85MBWxnQ+x2W1yp5kGebc5idYDBiL6XHfMlLqfAuG ElVbJQh3ht+bdSqCz85d46Tk0qnGNoCyQOzUSJClmdeLG+ov4RWQfXW1Q5M45usM9a2Q uW/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K4mUdCwmAtzRwm7u+kCETBgAEE11lQr4mH6vRmjSPyg=; b=ObMk6cnp9UU9SYST18KkJhpxXX1bGukO9jhLa8m9qNZ7qeyu5ymMcJcbEph9d9jHNF 3hysae8q/CKoPFK7rm2nW62xva5CaRzF0/ORrY6gOU+zIy5XDdWfCeerohfm/+z5SAvf pAHrlM4O5jOo19CK/a32ZNfE0r1QmuQywJ6BnCdANnRZRiVDx1EhriZsb0M0ex8mdBTx Il5ef6mIhC2mpeSfpZf36ulqswPqjbaz9U8zDIuK3nKlzOKpTgX4okGe0LeV7i3d/tYb bG4MgWz2k7BxzI0H9rKttvaLRZv1MUqaod1+hVN3uJc0lrCnbCloxoDCyFgB8yqEaKUb Z9Yw== X-Gm-Message-State: APf1xPBPQniTtQf1ns0OIXyTzH1WKleJjA1HR+0+o1G4UDpSSDo432fQ lETwiXuOnQgnQRWu00E0gETS9g== X-Google-Smtp-Source: AH8x2243nvh/zdGJpGbigrf7NsIJ7uIP33hcSRFsJgkWXopMMcU26IBhigvci7uVKqpcHA0J2Zev8A== X-Received: by 10.28.239.3 with SMTP id n3mr2909327wmh.88.1517598592870; Fri, 02 Feb 2018 11:09:52 -0800 (PST) Received: from baker.fritz.box ([2a02:908:1251:8fc0:ad10:3711:be7c:8502]) by smtp.gmail.com with ESMTPSA id j132sm3917316wmd.38.2018.02.02.11.09.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Feb 2018 11:09:52 -0800 (PST) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem Date: Fri, 2 Feb 2018 20:09:48 +0100 Message-Id: <20180202190948.2654-5-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180202190948.2654-1-christian.koenig@amd.com> References: <20180202190948.2654-1-christian.koenig@amd.com> MIME-Version: 1.0 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This allows access to pages allocated through the driver with optional IOMMU mapping. Signed-off-by: Christian König --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 57 ++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index 648c449aaa79..795ceaeb82d5 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -1929,38 +1929,51 @@ static const struct file_operations amdgpu_ttm_gtt_fops = { #endif -static ssize_t amdgpu_iova_to_phys_read(struct file *f, char __user *buf, - size_t size, loff_t *pos) +static ssize_t amdgpu_iomem_read(struct file *f, char __user *buf, + size_t size, loff_t *pos) { struct amdgpu_device *adev = file_inode(f)->i_private; - int r; - uint64_t phys; struct iommu_domain *dom; + ssize_t result = 0; + int r; - // always return 8 bytes - if (size != 8) - return -EINVAL; + dom = iommu_get_domain_for_dev(adev->dev); - // only accept page addresses - if (*pos & 0xFFF) - return -EINVAL; + while (size) { + phys_addr_t addr = *pos & PAGE_MASK; + loff_t off = *pos & ~PAGE_MASK; + size_t bytes = PAGE_SIZE - off; + unsigned long pfn; + struct page *p; + void *ptr; - dom = iommu_get_domain_for_dev(adev->dev); - if (dom) - phys = iommu_iova_to_phys(dom, *pos); - else - phys = *pos; + addr = dom ? iommu_iova_to_phys(dom, addr) : addr; - r = copy_to_user(buf, &phys, 8); - if (r) - return -EFAULT; + pfn = addr >> PAGE_SHIFT; + if (!pfn_valid(pfn)) + return -EPERM; + + p = pfn_to_page(pfn); + if (p->mapping != adev->mman.bdev.dev_mapping) + return -EPERM; + + ptr = kmap(p); + r = copy_to_user(buf, ptr, bytes); + kunmap(p); + if (r) + return -EFAULT; - return 8; + size -= bytes; + *pos += bytes; + result += bytes; + } + + return result; } -static const struct file_operations amdgpu_ttm_iova_fops = { +static const struct file_operations amdgpu_ttm_iomem_fops = { .owner = THIS_MODULE, - .read = amdgpu_iova_to_phys_read, + .read = amdgpu_iomem_read, .llseek = default_llseek }; @@ -1973,7 +1986,7 @@ static const struct { #ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS { "amdgpu_gtt", &amdgpu_ttm_gtt_fops, TTM_PL_TT }, #endif - { "amdgpu_iova", &amdgpu_ttm_iova_fops, TTM_PL_SYSTEM }, + { "amdgpu_iomem", &amdgpu_ttm_iomem_fops, TTM_PL_SYSTEM }, }; #endif