From patchwork Mon Sep 18 17:33:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "StDenis, Tom" X-Patchwork-Id: 9957223 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 25A2C601E9 for ; Mon, 18 Sep 2017 17:34:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10B9228D6F for ; Mon, 18 Sep 2017 17:34:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 058AB28D78; Mon, 18 Sep 2017 17:34:13 +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=-2.6 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_WEB, 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 A37E828D6F for ; Mon, 18 Sep 2017 17:34:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 070976E3CF; Mon, 18 Sep 2017 17:34:08 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0086.outbound.protection.outlook.com [104.47.33.86]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3E3566E3C8; Mon, 18 Sep 2017 17:34:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=S72BmDkhbYLHUN+oo5HfQBAWnRZyCh+/AMoHLOjQhTc=; b=sHDDO8oRT4pqH0RSWJ/iauVZ+JK4m4Ehx9L2Ugwx83DA9n5G7XYxbP54palqzuzdIeTx6kCh4nsswb9o46nfOrK1TkRV8CMJ4JAS12qz//xzZ1btV7HphTKDO1VsluyMBv05N9CH4VVP4BGFCClz59uuhoqQMo0dX8R7wTPz3yQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Tom.StDenis@amd.com; Received: from fx8.amd.com (165.204.55.251) by MWHPR1201MB0079.namprd12.prod.outlook.com (10.174.98.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.56.11; Mon, 18 Sep 2017 17:34:00 +0000 From: Tom St Denis To: amd-gfx@lists.freedesktop.org Subject: [PATCH 2/4] drm/amd/amdgpu: add support for iova_to_phys to replace TTM trace (v3) Date: Mon, 18 Sep 2017 13:33:48 -0400 Message-Id: <20170918173350.9543-3-tom.stdenis@amd.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170918173350.9543-1-tom.stdenis@amd.com> References: <20170918173350.9543-1-tom.stdenis@amd.com> MIME-Version: 1.0 X-Originating-IP: [165.204.55.251] X-ClientProxiedBy: BN6PR06CA0031.namprd06.prod.outlook.com (10.174.93.20) To MWHPR1201MB0079.namprd12.prod.outlook.com (10.174.98.18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c4735288-ef54-45a7-afeb-08d4febb7340 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(48565401081)(300000503095)(300135400095)(2017052603199)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:MWHPR1201MB0079; X-Microsoft-Exchange-Diagnostics: 1; MWHPR1201MB0079; 3:fsGEcpZxmhY3WRJTxSaPY6s/xYAqYgrfBFMkNIGKJxfV7s/sZxy5N7zyA+TkNPaYeX3WxxbcFETLtpehesP/aOQHIXbT7PqEgKkCdh0dm6UJgNL57k0GZGiPtnLq19K2j03sIJKXHnjVrYYa7s/J0UrBRElQ6bteGPKLDWzbr3Dtw7ATNyX62ss0/ymmBQ0CuDFKJHLvDPnkx4sTb61IfnfAPtiwMx8qTL58v+HfJlxT/HMGXiYCNUeaLNTCCKJV; 25:Ac0fbKvILgXRZIU6S73j4qE5/6SGyqOODVpkgiMoorVQ1f89MDvtGZ0QqAnSqFVUDOLlh+Ntx303s40+9oQOMCyO8t2fKmV7wFdOJKQZbR4KRE7JI8Z/fbGowOd2QCHPLulsWFwAjbfcOvORHnpl6bxXXS1KJE88jAUG0k46MQWgeGveH6kgj4ps7TnXjeQWvi8xsgXbQhjWBQb8ttn7tJVa7x9HlSkYyniwii/SOdSHik3/joZrQH2Fsyz9a02DgBOF1sliaR8LT1a3oTThFSMnAfeRYHOqRebFXcg1vMJuGtmHEvWH57Z8DKN3IEETLIwelG9qDyrI45Gkh5m24g==; 31:gPTlXGIkobNZsBU25soIY360RLvaAnZFc72vebxD/CYmm5UVTcV+d65BoycHFxk+WZCQP8PUtb4ZSHyprw19muo+VbH6afgNG9UX0PnDXtjmmS/AfPy6ZPX2TcRM45Lo5c9YeHdRet1sc7/uI9KQjGShXkE5C5a/ggLtM45ZCWAbZuW6qr+Sddl+6/RdxA0j7yKH0Uib7oUaCjtnS+09qPPZ8ohnTvhj1YJCZXTg8EI= X-MS-TrafficTypeDiagnostic: MWHPR1201MB0079: X-Microsoft-Exchange-Diagnostics: 1; MWHPR1201MB0079; 20:dGahdoNt3I/ex4WmkWnde4c13QeVkgZww43pXSFF7IdSok+lc0SJOGmBLXVMoIGRoE5ECULCOFLXn5xTU2FYhgl60fBYVaySpk/KaJ6ugu6ZUiMrpCGXIMCZ1pD9dFdvnpqJqDe8rRn2LIDfXdKMK8y681DB4VicYWKLfXQ89e3a75xG2YvWQ9JlYriMaIjLRRXJHEA5s5vHCwpt0EjF8zEfwUFxzm3Wl8CloJ/oK6La8+2/Sc2YlzgWoBRO1Y1x+JN5alKs/5Th767qhtneRBCZ8A0YvCDCr8GEJp9mCWGjA/F+EwSwUGYdYIaayLS+4yW7uld0BP71LCOUBS2BFh8nQQxn2cGkbXz0sTSl8+7D0otpnEJlyU2PrBZv8anyL8A1idRmduCT7FAfcyCe1knFWbp6TrCkzo4q/Y4Tt+5SSfolZv+WDcWhoSPPyATX2BBomASQZOHUyoofRjRVjZKtFGIGPIXXdVifQZwie7QowJcMkVZkOhEuyDGi5gFu; 4:7M9j16BFJOU7Rq37HZXL83YxxFwqwO919GKS0ru9E5pZwksmDmr8tA5K5Cl7ncXpboaYNigULjeYl1LzN4/chgqKSJQ+TzRwPcpsoWxmtj665/XV9iGxuEeYEUY/KMRWoQa2fPnHccazq1CQFmT6/tVtRQ/2XGdIVLV+MvhvWFKH8g3NNGjW7VPNECqauFluMS9Wcpv6et2kHnD+xBYtL8s+iNGLUkcgr3be1QVyVNLSfC1yUGlfNvxbuChROwqKaezBmXPZFznVuuITR/+fnRsQtbvFZQzM4bTwHU91a8LMt9RI4appdGbCKo9VmilS X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(788757137089); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(100000703101)(100105400095)(3002001)(6055026)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123562025)(20161123564025)(20161123558100)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:MWHPR1201MB0079; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:MWHPR1201MB0079; X-Forefront-PRVS: 04347F8039 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(346002)(376002)(39860400002)(189002)(199003)(25786009)(105586002)(72206003)(68736007)(53936002)(2361001)(33646002)(76176999)(48376002)(50466002)(5660300001)(36756003)(6486002)(450100002)(110136004)(478600001)(6116002)(16526017)(66066001)(3846002)(1076002)(47776003)(16586007)(86362001)(2906002)(6666003)(50986999)(5003940100001)(305945005)(8676002)(81166006)(81156014)(106356001)(7736002)(2950100002)(316002)(6916009)(2351001)(50226002)(97736004)(4326008)(101416001)(8936002)(189998001)(53416004); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR1201MB0079; H:fx8.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR1201MB0079; 23:qBNhDzczWljhuZM569n11omWnPYSoQ3+WdE/ZzP?= =?us-ascii?Q?/Mv/1Wycsmmq+lvVmlYMe3jO9yaNH13lSefTaBjx2L+ktoMscnrP2MtUe0cG?= =?us-ascii?Q?4zSFUpnsy5Q4/DN2ZFO6UmanYJG/aIBYjLsk1DJiJbEuQ5XFpoc88p9XKT6s?= =?us-ascii?Q?fPacwK+LrbS3eM2LetaHYF4XDfmhcu5eyduHqaVUfZNoTLskbHUhEUv6SBTF?= =?us-ascii?Q?FmjMggAHRj8fIkBBVNDEDlJy9T0yVSN1r+gfWzolZxquWqvgo4Y0jtSDmtA3?= =?us-ascii?Q?bNFeKgR4keIrKh+vm8vSYbs/zYU3wUaZcnG8oKuU0zAe4a2OVaF5rNu79VY3?= =?us-ascii?Q?QKRVHOu751fZpWve+ZXE13ksAM3qbcxImSMaGz4CbXUROAfwzqpeBg4MoMIo?= =?us-ascii?Q?lhfIeoRaWO90lq7T1lRD0K7OVyNKVxXOj+p41FOvh081lxxG/TcWGJ8ATOvR?= =?us-ascii?Q?NMDiScVZwPagdn7sHOvN1RN2MIIlzA5zVia8QHaunyMrHfm0iBw/xTslNiT9?= =?us-ascii?Q?bLptxTHpX2vIPkDE8tdOAqmk7gfunfv42Gm0ABVxSAH6xbY2DgwY0udohpIC?= =?us-ascii?Q?m1b4yHqY3JVB6U4WTrw6h3dmaXAYbL899maW0LooYDOF/u4lkXUAs/s7KK78?= =?us-ascii?Q?33RUgbmJF/odLLyJy7fWNyv9n/MufbdHj8/wxEw7QecmQDl9hLPL7jOeAcDe?= =?us-ascii?Q?Rg291YBclk0WMwQtRRicPhjbITLjceQxxyEivixVx97cvzbveGlmCnkU6sCP?= =?us-ascii?Q?SdJE00rOcXpmDy2r8Y2EBbDQ4nxLsmU8T2Pc/a8yLzZZ24JY3NyhiZAydue5?= =?us-ascii?Q?iaQlGYg++wsLuqoE4lqoHGTulV5HaJALcjZOihoU+KT8+5S2KEeIpZu2+ENO?= =?us-ascii?Q?qXjKPNdQeEeTn/hvCq/Ik8NhQE+UWKfBXiLtwemRZdgNIkpn2RLZVsxfa6h+?= =?us-ascii?Q?7GFRTwyJ4Mhb+96yyL3e+ufTguRtG9c9FuVs2sBd3uKIm8bxts8bfybUKG1V?= =?us-ascii?Q?m/h4/B+kACrtfgZLtqs/41913JKjGgjMjYNvcYjtKXh19CFGQW5nI+o/KWfn?= =?us-ascii?Q?olXnKuWFiGjelQDHfSxLr7/+LLKm5NOOhVQiIE2Ron9ylJiRqZaNg6bvM7yy?= =?us-ascii?Q?YrCBFS/e7Rv7cLLthI2aQ4u3vnC5DKD7EajI0ezYKqRyHCR3W2VL8ohMut4f?= =?us-ascii?Q?fxY4C0L7EiMn0noHx07n8RzljQ7y5Z3KCg6j0?= X-Microsoft-Exchange-Diagnostics: 1; MWHPR1201MB0079; 6:bH3WosgUTg0xiyMHEPLuZMG9ht7mSjQcOW2RMctuMwmuVcbEvgU7WgasxhFEQwWZ5WGyLRne3hb88FuIAHofQNpUCw+PzsAh0yoOhZFV1mP7ohhdO9j8l/TYTmTtP1KJHQcrPGrCI53FP9TxLfVJrETg5723MHA7WydxX4k71MaylWefvwFUNE9Z4t5gW0sV7Lnj1w1xTu+HN2GUpAFyfpXs/CHwzxocPwqt27TTnZSJtnRrkLDb5v8LMuY347LqFRajcx0PHjsRO7RZE04AmlmZxT3lIN0B/+LqN5xOgAF5/oDl34L40kiPvF++bXJocS5nF9bHRk2jY7GRhHJ56w==; 5:+vlQmnHmCuXmJOWgTxVd5/kDhfGONqSwliRDRTzFT6FT1U3SyDmND0njkeyd+n+ISvVx+HglKtkccfTlP2ziVn1xSyyrp1V32LDrfG6UgBBwsQ/561YR7zm8Udlvj4k3Sj6YRHALBmfykva+6rCk2Q==; 24:uEXlmUIK1KZEYMQbCtx7QvmEjxaMxoAgNmWXhVSMn/G2/34iwu5BPLvcnPNnge/7pswJui5IqxeE37/YVUL805OeD7dYUjE6d1LBkJTWK9s=; 7:fYXnS0sQK/TcVENj823RpBTQgrT5iCPxjOtiSc6rgAD2u3vzjny6bcUfGLoPIgARo2/yBTg6OyhDt2//HEKYHW8oUN/n9WYXWk7niSCrwkx3/8TkA7dttSaRhcRROqxBUtCeoq/9k44/Szh4ytR2Kk6HZ3JluDaWUyMsVL923cQ007QFg/bL33jYbiHy4JrX8+VwKMteQbODbv6b4V+qJ53CFSR/2cO521SHizh06CA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR1201MB0079; 20:cOATjH5dLOQaCjNLVJ/g+PUp2ZcofmgSpqB2HpRmx9h9lnxCsxh2BPNszIK5/ydz46fB6nFWXXROSBmivzb6MEEX+TgIw28sohrV0v4HW1mh5Lo2MB9dGwPMS88nVPBXqzufTk3JQOEVf4sX35RwIlG3agG7Gs8UKl9yiLOgwcjmM5rAKYRGfuW5kK7isF4oZf8oH6mAmPvM9KZ5M4rk6m+qOPSjw9zGZi/CIzApIdL+EmeNA880DKOvSrjg5EyX X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2017 17:34:00.5791 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1201MB0079 Cc: Tom St Denis , dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 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 Signed-off-by: Tom St Denis (v2): Add domain to iova debugfs (v3): Add true read/write methods to access system memory of pages mapped to the device --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 104 ++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index 50d20903de4f..02ae32378e1c 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -43,6 +43,7 @@ #include #include #include +#include #include "amdgpu.h" #include "amdgpu_trace.h" #include "bif/bif_4_1_d.h" @@ -1810,6 +1811,108 @@ static const struct file_operations amdgpu_ttm_gtt_fops = { #endif +static void *transform_page(uint64_t phys) +{ + if (PageHighMem(pfn_to_page(PFN_DOWN(phys)))) + return kmap(pfn_to_page(PFN_DOWN(phys))); + else + return __va(phys); +} + +static void untransform_page(uint64_t phys) +{ + if (PageHighMem(pfn_to_page(PFN_DOWN(phys)))) + return kunmap(pfn_to_page(PFN_DOWN(phys))); +} + +static ssize_t amdgpu_iova_to_phys_read(struct file *f, char __user *buf, + size_t size, loff_t *pos) +{ + struct amdgpu_device *adev = file_inode(f)->i_private; + ssize_t result, n; + int r; + uint64_t phys; + void *ptr; + + result = 0; + while (size) { + // get physical address and map + phys = iommu_iova_to_phys(iommu_get_domain_for_dev(adev->dev), *pos); + + // copy upto one page + if (size > PAGE_SIZE) + n = PAGE_SIZE; + else + n = size; + + // to end of the page + if (((*pos & (PAGE_SIZE - 1)) + n) >= PAGE_SIZE) + n = PAGE_SIZE - (*pos & (PAGE_SIZE - 1)); + + ptr = transform_page(phys); + if (!ptr) + return -EFAULT; + + r = copy_to_user(buf, ptr, n); + untransform_page(phys); + if (r) + return -EFAULT; + + *pos += n; + size -= n; + result += n; + } + + return result; +} + +static ssize_t amdgpu_iova_to_phys_write(struct file *f, const char __user *buf, + size_t size, loff_t *pos) +{ + struct amdgpu_device *adev = file_inode(f)->i_private; + ssize_t result, n; + int r; + uint64_t phys; + void *ptr; + + result = 0; + while (size) { + // get physical address and map + phys = iommu_iova_to_phys(iommu_get_domain_for_dev(adev->dev), *pos); + + // copy upto one page + if (size > PAGE_SIZE) + n = PAGE_SIZE; + else + n = size; + + // to end of the page + if (((*pos & (PAGE_SIZE - 1)) + n) >= PAGE_SIZE) + n = PAGE_SIZE - (*pos & (PAGE_SIZE - 1)); + + ptr = transform_page(phys); + if (!ptr) + return -EFAULT; + + r = copy_from_user(ptr, buf, n); + untransform_page(phys); + if (r) + return -EFAULT; + + *pos += n; + size -= n; + result += n; + } + + return result; +} + +static const struct file_operations amdgpu_ttm_iova_fops = { + .owner = THIS_MODULE, + .read = amdgpu_iova_to_phys_read, + .write = amdgpu_iova_to_phys_write, + .llseek = default_llseek +}; static const struct { char *name; @@ -1820,6 +1923,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 }, }; #endif