From patchwork Fri Aug 18 14:07:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "StDenis, Tom" X-Patchwork-Id: 9909279 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 6F67B60382 for ; Fri, 18 Aug 2017 14:39:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C2AE283ED for ; Fri, 18 Aug 2017 14:39:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50A5D2852A; Fri, 18 Aug 2017 14:39:24 +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 22CC9283ED for ; Fri, 18 Aug 2017 14:39:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A0B5F6E091; Fri, 18 Aug 2017 14:39:22 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0077.outbound.protection.outlook.com [104.47.38.77]) by gabe.freedesktop.org (Postfix) with ESMTPS id 95D526E091 for ; Fri, 18 Aug 2017 14:39:21 +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=tohufamMzC1Qg7Ry9PIMIES4O2qJ7R0luvqNOoKN2kk=; b=rYx1vE8TJti5aLfVnhZxSGv+1cK1ilisUiXLomBYGC8WaioNoVgLT/J7zU/qbn01gaD9ERfK2W56b2Mv1C1z/sCo7oU6i1XYKKIL+BzmcVZqqlzdWMdFg0VKV/Kpac5SrpRxMgdMim3m4+XdHZtlLqOQ2I+EBUW7h8wcr6M8utw= 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_128_CBC_SHA256_P256) id 15.1.1362.18; Fri, 18 Aug 2017 14:07:36 +0000 From: Tom St Denis To: amd-gfx@lists.freedesktop.org Subject: [PATCH] drm/ttm: Add helper functions to populate/map in one call Date: Fri, 18 Aug 2017 10:07:27 -0400 Message-Id: <20170818140727.8342-1-tom.stdenis@amd.com> X-Mailer: git-send-email 2.12.0 MIME-Version: 1.0 X-Originating-IP: [165.204.55.251] X-ClientProxiedBy: BN6PR06CA0002.namprd06.prod.outlook.com (10.175.123.140) To MWHPR1201MB0079.namprd12.prod.outlook.com (10.174.98.18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b2c0248f-1aaf-4007-0668-08d4e6427b25 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(48565401081)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:MWHPR1201MB0079; X-Microsoft-Exchange-Diagnostics: 1; MWHPR1201MB0079; 3:1Iz+c5KU603WpbuSG/fNE2G9GhyjsHk22ti64gqz33vI3CC8G347HUgiitleE2Q0XdIoERwkGLvdT5h05ZkkDsrGfbw7p0cDZHeIRsDqihPstuArPNcKWxYW3sn+BsKujAGo+OnRGpDXsF9jsmoVWdhotCPDjCS1X4A1yCvROaOuoeYkl6ZmSPx4i9VaW7REv8THviEvLSfsqIakCnvjjyPb6V2463/8TewvotFxGeRm+OufVe0c97JcMEcHL65M; 25:U5f6aC1xnGU+98fLB6M8QZgXkYmT8aIlLlo3UdBjX7pLyF8GEKFg7NRBihZBqbb3hEwnmvAPHZrl98brC/+hJAbez6cTmVA3B15Heu17vf2Q8/WShvsF0YCK7wkQ5VXKhmFPXVTkXC29j8RtW/Pd7AzhiV5dg59YiWzueQxnPL91PyUJw3S+p9bErekGJDI+TfeoHUaPUO3rbJqwaJotxdKxh51CDyVpL2lJ5sJusEtk0KIsgXr3M2xcaM1/FXlhP7t3za+ZHvFsUyHXppIWEttCdMcdc3ZBjg8hn+n1dslIHv1V5zQEPhhJFIDod3o14XGTI53CUcBWG1uK83cdow==; 31:5oU45pedTWNWNpcdYFODeF/TG1sjMsMaLKvfqpJFEh3HqM+0LFmlROWOA1n1Q/QgMSJF2GtnuFDpV1Cm6WaNj7aiie/1sn5EMbHJtsvU8S/rKWAQG+4DwaDc6iD71dc7xIe23wOsGk1gYuGfxyyFXCxQ+SZeNgI4tC0J7dBTk5eWkcEy1FycagzMyoAUZYcp656TmiQzoJsVcC1AuAssZDsMv8F6YZDrBtdAyZEnh1g= X-MS-TrafficTypeDiagnostic: MWHPR1201MB0079: X-Microsoft-Exchange-Diagnostics: 1; MWHPR1201MB0079; 20:RsRzEGpXzaAWkVjA7Zb+8seEL8OOgAIgKYy9d3Vdl0oydvIbwDcSPT+DxvqoF9HOFKrYD/hZK/7UsuslfyhRQg2mnMFtgfl/bN2P2XCAs/trqeznEdtekffsE2YvXv1EytUTLP2CnzzXXPLyRypHDH8obfPmwNRkawihhlRdLJmiGmCd6Q6b3jleYX8dWWdmjFEV/HZn5+G/96f7oYY3QEtzyYrFNCpg1A2K8oBlYB5JNGUZT6gvjmz3anp9ZS8zgyg+sd5PeEwOCiBAB1SF+y2sdXmQGxYbLY8g2cba+FQtI+scSsocz5bPERhtRNrhkIzNEWvgmjPzvZC8DQU+OgGS7RCE4FB1oBH9ZAt9mgEHphXo1Q8vY902DhIgJC0FV0lW9m0qBZ3E4Xo3sKbS4BxySJONQR7phcFpzJ5vSz30jnR2pchWIU8TP3dr/dltrwZKR7JmaF4g5Ljju2Otbn+hvbQieGqQN225OdhjH72HiY/8JvxR3b2k1inBKWgz; 4:ZLBg3D7LJYkeywSDkdwvPfjcq/ZSuF1Oe9j7e+umlCkQ4Y30fDUqkNIAd1M63jzgXroAcR3PNHxcqGcEjOCuUxZ8ol9sXG9rxpZlkRHivdT3gPpgF0xB0bRdgTiQD8AAbHcQk9wOm4jSc7ylqHEdVzT6GTxIOf+JC2xjKGAq72RgxTnCt6OcU8zXh6ldwbXrbDeO0lROAeaKh+8XNXJyB2dc0WCVDypYnOQ4Giywv+N5VMz12c1VtjSm7DQVX34hy517uEQKpwln70glUyECo8VnfC4+6Hek3yuUyN1xgPwhZ+q8fBO5VwMGnLD2ASNP 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)(601004)(2401047)(5005006)(8121501046)(3002001)(100000703101)(100105400095)(10201501046)(93006095)(93001095)(6055026)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123560025)(20161123558100)(20161123564025)(20161123555025)(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: 040359335D X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(7370300001)(4630300001)(6009001)(39860400002)(189002)(199003)(5003940100001)(25786009)(50466002)(97736004)(48376002)(72206003)(189998001)(81166006)(81156014)(36756003)(478600001)(50986999)(101416001)(8676002)(53936002)(6486002)(450100002)(106356001)(105586002)(6116002)(6916009)(6666003)(3846002)(2906002)(33646002)(2361001)(2351001)(86362001)(7350300001)(1076002)(50226002)(305945005)(42186005)(66066001)(68736007)(4326008)(5660300001)(53416004)(110136004)(7736002)(47776003); 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:u5VOMxXm4ZIgWwdx6q3780dLPgROAbnLoEksp4d?= =?us-ascii?Q?7st3F/AazwPR4LWMMwE3W8DuC2qGCuGrjoAp31DJvdhHrCTD43GYnStgM0iw?= =?us-ascii?Q?42kxdXF+JApHzSkX5ERJMQrlqQR5Q9Mi/5/6A0fYp9+pGmHpZ6SyUpTgPmmB?= =?us-ascii?Q?hs1lr3hhlTVayiApcbMM0xeQ3vILjKmAshSq7Cdz+0cUZ/o5XBDZ3jtVyEXp?= =?us-ascii?Q?MmLkUJkbbGl8qwLmeBZ5JudFVDOcs+C5RBKIMSgTCejxzK9jx/uZ1rzZa3lo?= =?us-ascii?Q?ZvAzUDj13TElcGe5KRTuGTsZ8KOmhk6+2SjtICpDX2V195ouYOyLjdedQaji?= =?us-ascii?Q?HUs9WsgDsqmoqxvBaBlmbp9Nnk4WPSW2uK1TiMmoY8zHq22crUHNJh9xl8xT?= =?us-ascii?Q?j9NbQy2cQvpjLsfZ2F6o4G54G+QY0rU7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IXqUZXTjwb1hLCPLlYUkvraedEFu90Q5yd0p1WhRneayCu/lRWrIr/srJn+uZPOyy60GnXi+KXgXZi74CTuCgApokBHqgF9a1ilxBqhTvkdfDaqI7GZncvelBxrnP1jByF388KS7Io5IXxlk47t2aVnP9M6kjCcT/C+uKWaPnnVDhmjD2XjezB+fWXPnmPQ==; 5:2fM+1EzLRGBf0a8s3oFAQlPB+Gw/ovfMZU5UfM7Byh2YbKDWic8ixj+55PaZpwf896TAnHodrT7fmbd7VLX+vQxDAhIBrsG5Gt2I3fVu1WFPhMinyr27I7xUJU9vd+e8VP8LoT5KBsWE6yzYftyEJQ==; 24:FDkjCpbb6aH8U/M2YjpjYGPo66uL4DfDZBcPHLKu1cjll5e+K0xhEbPRChIvEjyF7CAqbckxgHhsMWZOCMeGkzpQn02r6P0NyjLYWJmvvEA=; 7:KlCaDCm5VtS16xJxA4eEoZqkbRJbegARWibqbSFmP/Az8+SWgibhPIxjMlcTZIilIowlmV4VP/JVtm9YdZnwz1EwvGqsUdqdJYaT+efXmZ/iO69u15EX24UnxS4vMF4yo36OH68kJAHfVnDWI14IpoTU9zEeNWO2WbJopSDd5W0hYEM8JUb25r9S22690kaO3ih+azTI1urEUElxYP6LfUu7z80tWvEGbm92xLBo9+c= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR1201MB0079; 20:961pqf0AnHsgll62P0wvSMm2NYZf4RsLHTEVkIUysqis3HfYf8spja/+gi2++Slb2lhlanihBLAUQcwYv8uQausu61eh4nLURRiByeGfq7fdXqZhE0/Wdwz95eohxjss6WF8XPaH/Cwytm2oEb8/CEAPpE8Vpv137R5iTiRaPASBVip6WTnZdYinz7klC4LShAKf1tmQECb5Qc7e0fRYJS4N5IsRb1KIBY5txz9dEA9itZY7bK/l0M38euwVApL+ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Aug 2017 14:07:36.7617 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted 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 These functions replace a section of common code found in radeon/amdgpu drivers (and possibly others) as part of the ttm_tt_*populate() callbacks. Signed-off-by: Tom St Denis Reviewed-by: Christian König for this one as --- drivers/gpu/drm/ttm/ttm_page_alloc.c | 41 ++++++++++++++++++++++++++++++++++++ include/drm/ttm/ttm_page_alloc.h | 11 ++++++++++ 2 files changed, 52 insertions(+) diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c index 871599826773..6a660d196d87 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c @@ -920,6 +920,47 @@ void ttm_pool_unpopulate(struct ttm_tt *ttm) } EXPORT_SYMBOL(ttm_pool_unpopulate); +int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt) +{ + unsigned i; + int r; + + r = ttm_pool_populate(&tt->ttm); + if (r) + return r; + + for (i = 0; i < tt->ttm.num_pages; i++) { + tt->dma_address[i] = dma_map_page(dev, tt->ttm.pages[i], + 0, PAGE_SIZE, + DMA_BIDIRECTIONAL); + if (dma_mapping_error(dev, tt->dma_address[i])) { + while (i--) { + dma_unmap_page(dev, tt->dma_address[i], + PAGE_SIZE, DMA_BIDIRECTIONAL); + tt->dma_address[i] = 0; + } + ttm_pool_unpopulate(&tt->ttm); + return -EFAULT; + } + } + return 0; +} +EXPORT_SYMBOL(ttm_populate_and_map_pages); + +void ttm_unmap_and_unpopulate_pages(struct device *dev, struct ttm_dma_tt *tt) +{ + unsigned i; + + for (i = 0; i < tt->ttm.num_pages; i++) { + if (tt->dma_address[i]) { + dma_unmap_page(dev, tt->dma_address[i], + PAGE_SIZE, DMA_BIDIRECTIONAL); + } + } + ttm_pool_unpopulate(&tt->ttm); +} +EXPORT_SYMBOL(ttm_unmap_and_unpopulate_pages); + int ttm_page_alloc_debugfs(struct seq_file *m, void *data) { struct ttm_page_pool *p; diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h index 49a828425fa2..8695918ea629 100644 --- a/include/drm/ttm/ttm_page_alloc.h +++ b/include/drm/ttm/ttm_page_alloc.h @@ -83,6 +83,17 @@ extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data); extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev); extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev); + +/** + * Populates and DMA maps pages to fullfil a ttm_dma_populate() request + */ +int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt); + +/** + * Unpopulates and DMA unmaps pages as part of a + * ttm_dma_unpopulate() request */ +void ttm_unmap_and_unpopulate_pages(struct device *dev, struct ttm_dma_tt *tt); + #else static inline int ttm_dma_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages)