From patchwork Mon Feb 5 13:55:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "StDenis, Tom" X-Patchwork-Id: 10200415 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 C4C8D601A1 for ; Mon, 5 Feb 2018 13:55:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD9F7286B7 for ; Mon, 5 Feb 2018 13:55:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A25B22874E; Mon, 5 Feb 2018 13:55:34 +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=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, 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 C801A286B7 for ; Mon, 5 Feb 2018 13:55:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5CB416E2A0; Mon, 5 Feb 2018 13:55:29 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM02-CY1-obe.outbound.protection.outlook.com (mail-cys01nam02on062c.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe45::62c]) by gabe.freedesktop.org (Postfix) with ESMTPS id 113196E224; Mon, 5 Feb 2018 13:55:26 +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=Eh9CIfvkfMXOLtULrc6A6MKMNdOxeNXKl0RUH1w3beE=; b=SgKisBKl/m4x/6xYMe5kvYL2CH/OPZ7A8TcFbNLZVrrN6C5xrvAcwvRO70EduS7mJ4czjIGSS+gmuLxdtkc1sk3Kc0tVI5b5yVl17ywQ45LuqFj0xjuZy/odEBJSCKJ8NyZrrb1kiGSR8h5nsk1bsID4Lw8JYpWUs06Zo3GxeAw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Tom.StDenis@amd.com; Received: from [0.0.0.0] (65.95.38.236) 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.464.11; Mon, 5 Feb 2018 13:55:23 +0000 Subject: Re: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem To: christian.koenig@amd.com, "He, Roger" , "amd-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" References: <20180202190948.2654-1-christian.koenig@amd.com> <20180202190948.2654-5-christian.koenig@amd.com> <8c826b1d-1a3c-e36f-c978-48b286b10f0f@amd.com> <0db6d2d5-8cd1-31e3-8443-4be9394fd8ff@gmail.com> From: Tom St Denis Message-ID: <5177b275-635f-a5b1-6c93-71627d115996@amd.com> Date: Mon, 5 Feb 2018 08:55:19 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <0db6d2d5-8cd1-31e3-8443-4be9394fd8ff@gmail.com> Content-Language: en-US X-Originating-IP: [65.95.38.236] X-ClientProxiedBy: MWHPR1401CA0023.namprd14.prod.outlook.com (10.174.253.161) To MWHPR1201MB0079.namprd12.prod.outlook.com (10.174.98.18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: ca167436-7452-4ff3-106c-08d56ca01ab1 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(49563074)(7193020); SRVR:MWHPR1201MB0079; X-Microsoft-Exchange-Diagnostics: 1; MWHPR1201MB0079; 3:/vtZXlcKiqPxvcqFPQbYv6VPr6Ta6oegrlWV9WC/CpfRhsoyejysVpRuGTGwaAvXImWjo9JF0kA8Qx+7ompRUmQIR7wT05G1xQ0kUUBhmp3noYAx2OyKgdMzQVY92+YtwvoDBgCT8HxiwWnpTWp/6OA5mNoKpA1bgqyv2msl78DkM1865MNgesmyVGYdtpKO9mjEJHWQ24zX3qwB84leR/P5Du0Oydx/pj5zwHA4swil5yagmnJlff3YZX84F172; 25:PHr1eSdS94H1Vt58b7vdAHuvc9Uzuial1XyKeTf77+0/MAg7k4mvCYoAXXjSycw0rmz+gUrncrFs/Y7OWkzqLycv6yJqcgnyNlyeAQPxeeyBIFZ+/yNWl/+voLKHIe5sbi3WB7nUALc6OixWWAjup870ShAM0G5EC18SWjUrTyzHYA69uKc4E+YRx1PZoPnecisT8K4nP1L55kbrJBYJzocG0K3HnF20HyOwFwO78r0J031irrdzsT3BVm7WyAw2O7GDZIw6n/tp1in1kBgaWLbs75b70n5DjVxi7FGUkybnkO4Lsq6AcxIkrdrpu/hCeRzEqI20Gr/ryXCe+hGt+g==; 31:qjojwUkg6cdsHOS9pUGUfT6K06xmm3Ys2lcZdrpbtqe3tXk4ZioCJZotJsA7bURiYraK1YRDCnn+31MFYNxS5sjBXWXTgzzOE3y8cGkNBPzUk9i7pQeH3p1DTitJlkxEzfM8xaDxMER8CWgDQLULD8pwBKwGmyhdmyH/kp8X4l5U5WkuYtYmaZiJC/RXbueIy13d4Fz2i8VaUK8KmcGSuX+GnE23LTCJE1Rl2J64vTc= X-MS-TrafficTypeDiagnostic: MWHPR1201MB0079: X-Microsoft-Exchange-Diagnostics: 1; MWHPR1201MB0079; 20:YZjjywOsocsVsdg3mNmVFExa89k9hfO/tvwuGIycVyEDRGy/3G+saEq9WjlLec7cktYngl3oFDOa9lco4Eme4F3weOV8BG49o8aMfH07JiT9VO0slz2RXiRE4IrclBoCJXUVZOXafpwbicTDMHYkk3jW6bt4+2GhTt6Pz5jg6pMigynpzGyku5v+TsZ380KNIU3ZpUop+nY81GGtOqB3k94lIuT3ON6+3yRo7qjQYjkSKatodwkLpB67pjeDjcyDhLRG3fTQNV4Ztt3N5/jmw9iLTGvmNFVfTkzUqPb0zPmQRsHOVfEE77qinnbtIWh/jWvrmg8RNA26Bn5SryKgtuWIL4nwwVjWXp8XsCt64WVTGPjPAwcx3jB4NnzlDQR4/5FkGUGpULO6vFpWdiKmdoPa0YxhDsjoteBIICQ9myjbEOBbVN3gr/LXIbpi6a0QMRZlMgfxO+Y4eNGzJrZ70jARU92+iRa2uG8RHAvHbTfNSAb9zntMAjrhrNV0GosQ; 4:17r9mzL63xFn3edUj02PCXUEORRvTjB7gW1sSfH+1apg8J4ckrztbYiVi2CVp55wSstntdiYUBswIaWV9dK4IFJEQ2TBPGZY5Ohd23YZRo9JiPjfO3Hl+a1Mw8WRIJuLouinmWW/SfuFSxDeafuEJsmMX5AWKuVUVjtU5FvENsBROTQUkCRIVS+13SUldihHoH9AHMIefajYekHFPiynUy7S+FRjo55k3SID7PSy9IRWycmzl8x2xr26jaFnUo7vZBLaSZLVPcoNM3fTDICWQvhHIx+GulljEhsgp3G14Xg7KBULxzXi8U7bcBsWUQZq+IaeILnOXeRx/duWYI5xYHrhm8Xe3xwS8rAsHdBlH68S20wW++NvaOTxuc6+3us8 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110)(788757137089)(217544274631240); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(102415395)(6040501)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(3231101)(2400082)(944501161)(6055026)(6041288)(20161123562045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011); SRVR:MWHPR1201MB0079; BCL:0; PCL:0; RULEID:; SRVR:MWHPR1201MB0079; X-Forefront-PRVS: 0574D4712B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6049001)(376002)(346002)(366004)(39380400002)(396003)(39860400002)(13464003)(43234003)(189003)(52314003)(199004)(5660300001)(76176011)(28096004)(33964004)(2501003)(64126003)(6246003)(2906002)(4610100001)(68736007)(52116002)(25786009)(53936002)(31686004)(84326002)(65826007)(966005)(72206003)(49976009)(2201001)(8676002)(26005)(81166006)(3846002)(81156014)(86362001)(6116002)(58126008)(16576012)(36756003)(97736004)(305945005)(316002)(2476003)(16586007)(93886005)(66066001)(83506002)(65806001)(65956001)(31696002)(106356001)(105586002)(186003)(37036004)(7736002)(110136005)(6306002)(8936002)(90366009)(16526019)(6666003)(229853002)(450100002)(59450400001)(53546011)(386003)(2950100002)(5890100001)(568964002)(270700001)(478600001)(6486002)(78286006); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR1201MB0079; H:[0.0.0.0]; 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:NEkGonsneaV91N8rcIO+aNSZOKhjxlaUKURUZTJ?= =?us-ascii?Q?npMsE802B2GidFvJm/cA3hDPLQQorKOcxpR1jnV/B5h7Z2GHUv53QEw9E5FV?= =?us-ascii?Q?abL1wwRtruZDENheYae3VJvAqDkHK6K/s0XU7mSNA80ckAY7LXdojpWPoSqn?= =?us-ascii?Q?9g+DVVY8fapgsTdrewcWUJQfuo4eBhHr+lpis/z1IFv5KEaH7JY3juIM7v1M?= =?us-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2ZcUqHXCITATQg3Hxo9Yb2lKc982XRf7Q4OAmAVxlJjnjKjH/sNvcQUGIimTlgGcgpXsQuzBUa3vWvQ/bDBwY+9FDQ96VZUdDEsTk=; 5:pH4Z+ZSGCWbGM7BWXULmY7DuqcH3xr44FIhd7sJHXkEBjp1O+US2B849KmnFXyf5J0CDubZAU2CttXpbfk9E81bZkq4ebbnVvCxDq2pRZnBzZhvGlz74mBs9w7zd2DO2oT90tsfS2Ke7nSNjo/hpwDwbzAzbexsjoPGzodIkrck=; 24:yoFy4sUZ5t9ouxjKovfmF+HwLJhkJP2RfnA+MOd7nQGVAcNOjVivCxfmOXkezxAPgJjEDLogPtv6PWAlUuVVyJhuH+8XdxZSuwPHWcL37oo=; 7:9IeB5sz59fhfnbFaL25PwsYqHnPkdCMkugX4CNLXzEWKf1lTnfgprlB8khyqXrCiyzuqk8hAZl8W/nc4+EwtT/ojuPfxcwjqstntrr8DS/4FhEVT+t8OSDhZZOVtZKa9PMwlBs6CVXkNtD5JOHsKLv8UEremlJgrnQGUM9r5woUG25VokDbpddnlXAsTxGYRnfxcD4gj+mPpEbKr01/PjeNo0TcPPlfWSDtirH5LKykqU8uUlrlMvtVBCkC02PSI SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR1201MB0079; 20:q9SYQKqVeURl9/pOwi5JlMctG3kzUZs0dASPOfTuQG3hFwLxT3SnwtLAgQlkttnvAO7P5xYJ2PWomWRlMtgUs+gTISw/Fut+E6Dcj85f7kmY8zhhRHXl3m7qOf9Q0y+oeU4GxXqifowKfcyJ3FbOSb+QDBVzRFBy5tucXzlVkjvAs8EcOVosn/tKsbfPvvmiqCxTuOybKqApeE4R1mkkTF5AVnTX1gaz5ExJk0wfTS5l+0+BFoMGipKNEK7FDBcb X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Feb 2018 13:55:23.5859 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ca167436-7452-4ff3-106c-08d56ca01ab1 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1201MB0079 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 Attached is a patch for umr{master} which should in theory support both iova and iomem. I can add the write method if you want since ya it should be fairly simple to copy/pasta that up. Cheers, Tom On 05/02/18 07:07 AM, Christian König wrote: > Well adding write support is trivial. > > What I'm more concerned about is if setting page->mapping during > allocation of the page could have any negative effect? > > I of hand don't see any since the page isn't reclaimable directly > anyway, but I'm not 100% sure of that. > > Christian. > > Am 05.02.2018 um 12:49 schrieb Tom St Denis: >> Another thing that occurred to me is this will break write access to >> GPU bound memory.  Previously we relied on iova to translate the >> address and then /dev/mem or /dev/fmem to read/write it.  But since >> this is literally a read only method obviously there's no write support. >> >> Tom >> >> >> On 04/02/18 09:56 PM, He, Roger wrote: >>> Patch1 & 2 & 4,   Reviewed-by: Roger He >>> Patch 5:  Acked-by: Roger He >>> >>> -----Original Message----- >>> From: dri-devel [mailto:dri-devel-bounces@lists.freedesktop.org] On >>> Behalf Of Christian K?nig >>> Sent: Saturday, February 03, 2018 3:10 AM >>> To: amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org >>> Subject: [PATCH 5/5] drm/amdgpu: replace iova debugfs file with iomem >>> >>> 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 >>> -- >>> 2.14.1 >>> >>> _______________________________________________ >>> dri-devel mailing list >>> dri-devel@lists.freedesktop.org >>> https://lists.freedesktop.org/mailman/listinfo/dri-devel >>> _______________________________________________ >>> amd-gfx mailing list >>> amd-gfx@lists.freedesktop.org >>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx >>> >> > From 67703a62763dfb2107bd503c5ae76414a50c50a4 Mon Sep 17 00:00:00 2001 From: Tom St Denis Date: Mon, 5 Feb 2018 08:53:40 -0500 Subject: [PATCH umr] add support for new iomem debugfs entry Signed-off-by: Tom St Denis --- src/lib/close_asic.c | 1 + src/lib/discover.c | 3 +++ src/lib/read_vram.c | 29 +++++++++++++++++++---------- src/umr.h | 3 ++- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/lib/close_asic.c b/src/lib/close_asic.c index 782b1a0d029b..6b220cd578e9 100644 --- a/src/lib/close_asic.c +++ b/src/lib/close_asic.c @@ -57,6 +57,7 @@ void umr_close_asic(struct umr_asic *asic) cond_close(asic->fd.gpr); cond_close(asic->fd.drm); cond_close(asic->fd.iova); + cond_close(asic->fd.iomem); umr_free_asic(asic); } } diff --git a/src/lib/discover.c b/src/lib/discover.c index 4af3733c8af8..dedcedc776ab 100644 --- a/src/lib/discover.c +++ b/src/lib/discover.c @@ -232,6 +232,8 @@ struct umr_asic *umr_discover_asic(struct umr_options *options) asic->fd.gpr = open(fname, O_RDWR); snprintf(fname, sizeof(fname)-1, "/sys/kernel/debug/dri/%d/amdgpu_iova", asic->instance); asic->fd.iova = open(fname, O_RDWR); + snprintf(fname, sizeof(fname)-1, "/sys/kernel/debug/dri/%d/amdgpu_iomem", asic->instance); + asic->fd.iomem = open(fname, O_RDWR); asic->fd.drm = -1; // default to closed // if appending to the fd list remember to update close_asic() and discover_by_did()... } else { @@ -246,6 +248,7 @@ struct umr_asic *umr_discover_asic(struct umr_options *options) asic->fd.gpr = -1; asic->fd.drm = -1; asic->fd.iova = -1; + asic->fd.iomem = -1; } if (options->use_pci) { diff --git a/src/lib/read_vram.c b/src/lib/read_vram.c index 25ffec93f54d..c685955e5050 100644 --- a/src/lib/read_vram.c +++ b/src/lib/read_vram.c @@ -73,30 +73,39 @@ static void access_vram_via_mmio(struct umr_asic *asic, uint64_t address, uint32 #define DEBUG(...) #endif -static int umr_access_sram(uint64_t address, uint32_t size, void *dst, int write_en) +static int umr_access_sram(struct umr_asic *asic, uint64_t address, uint32_t size, void *dst, int write_en) { - int fd; + int fd, need_close=0; DEBUG("Reading physical sys addr: 0x%llx\n", (unsigned long long)address); - fd = open("/dev/fmem", O_RDWR); - if (fd < 0) - fd = open("/dev/mem", O_RDWR | O_DSYNC); + if (asic->fd.iomem >= 0) { + fd = asic->fd.iomem; + } else { + need_close = 1; + + fd = open("/dev/fmem", O_RDWR); + if (fd < 0) + fd = open("/dev/mem", O_RDWR | O_DSYNC); + } if (fd >= 0) { lseek(fd, address, SEEK_SET); if (write_en == 0) { memset(dst, 0xFF, size); if (read(fd, dst, size) != size) { - close(fd); + if (need_close) + close(fd); return -1; } } else { if (write(fd, dst, size) != size) { - close(fd); + if (need_close) + close(fd); return -1; } } - close(fd); + if (need_close) + close(fd); return 0; } return -1; @@ -292,7 +301,7 @@ next_page: // allow destination to be NULL to simply use decoder if (pdst) { if (pte_fields.system) { - if (umr_access_sram(start_addr, chunk_size, pdst, write_en) < 0) { + if (umr_access_sram(asic, start_addr, chunk_size, pdst, write_en) < 0) { fprintf(stderr, "[ERROR]: Cannot access system ram, perhaps CONFIG_STRICT_DEVMEM is set in your kernel config?\n"); fprintf(stderr, "[ERROR]: Alternatively download and install /dev/fmem\n"); return -1; @@ -663,7 +672,7 @@ next_page: if (pte_fields.valid) { if (pdst) { if (pte_fields.system) { - if (umr_access_sram(start_addr, chunk_size, pdst, write_en) < 0) { + if (umr_access_sram(asic, start_addr, chunk_size, pdst, write_en) < 0) { fprintf(stderr, "[ERROR]: Cannot access system ram, perhaps CONFIG_STRICT_DEVMEM is set in your kernel config?\n"); fprintf(stderr, "[ERROR]: Alternatively download and install /dev/fmem\n"); return -1; diff --git a/src/umr.h b/src/umr.h index 9c006f00cf45..da67abf6dc2b 100644 --- a/src/umr.h +++ b/src/umr.h @@ -233,7 +233,8 @@ struct umr_asic { wave, vram, gpr, - iova; + iova, + iomem; } fd; struct { struct pci_device *pdevice; -- 2.14.3