From patchwork Tue Jan 16 13:56:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Hellstrom X-Patchwork-Id: 10167077 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 60DC260567 for ; Tue, 16 Jan 2018 13:57:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52AD12823D for ; Tue, 16 Jan 2018 13:57:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D44828433; Tue, 16 Jan 2018 13:57:20 +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_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 DC09F2823D for ; Tue, 16 Jan 2018 13:57:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 15F766E235; Tue, 16 Jan 2018 13:57:14 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0626.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe48::626]) by gabe.freedesktop.org (Postfix) with ESMTPS id 53E0D6E22A for ; Tue, 16 Jan 2018 13:57:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=onevmw.onmicrosoft.com; s=selector1-vmware-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Q/ymqyNTWhp9tFGfEP7m6Ei3jnWzQ1SG381SKGYLW74=; b=XSRkmKr/kBwszBfA9E7niu7x/1st+uQCzCWoHu3YX2nt721jMHvlISPHtSRGvnZ318XDfcgS+My7FX9qxts42FhgdZaHp+OG23G12Y1KjOJhTRGDXwcaWbpeTandCWxdzYcgLDwITsZ98ElfzC/le1pwlV5upD6s6tiG8b9VJnM= Received: from ubuntu.localdomain (155.4.205.56) by BLUPR05MB754.namprd05.prod.outlook.com (10.141.208.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.428.9; Tue, 16 Jan 2018 13:57:07 +0000 From: Thomas Hellstrom To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/5] drm/ttm: Clean up kmap_atomic_prot selection code Date: Tue, 16 Jan 2018 14:56:40 +0100 Message-Id: <1516111004-10247-2-git-send-email-thellstrom@vmware.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516111004-10247-1-git-send-email-thellstrom@vmware.com> References: <1516111004-10247-1-git-send-email-thellstrom@vmware.com> MIME-Version: 1.0 X-Originating-IP: [155.4.205.56] X-ClientProxiedBy: HE1PR0802CA0014.eurprd08.prod.outlook.com (10.172.123.152) To BLUPR05MB754.namprd05.prod.outlook.com (10.141.208.142) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4513bb20-f6bf-43fe-1594-08d55ce90893 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(4534125)(4602075)(4627221)(201703031133081)(201702281549075)(2017052603307)(7153060)(7193020); SRVR:BLUPR05MB754; X-Microsoft-Exchange-Diagnostics: 1; BLUPR05MB754; 3:G7di3zoJ5n7iW5m/fheEqw2N0i9HKGD/9fD9S8SOpleRX/lBYCIB7jf3N7KYqR4We6nRRMpcrpeHKp37COWyP6vaeAnmzvJrvlYeBduyUQcSgp+3EFg7YiV5oN/uB2an0rpBeAbwJCUvX7r3WM5xZ/BDG4mly85UrIxn1roCi7PGievgUf8xG1FN2iyV8SDkvLLChyJh0xk+F47xYiLej2fQbycQs79IQU4w6V71efMtfu/MfWmiZVz/9kzxCEPL; 25:x4Y25X8Ngx1ePLOOCHNtJJSSRJiRE6aawzhnxpk4WFq18QdUO8yHmkONC5SLqN4YG1FDMRqxRi1VtcNlOf+j7od59zGNnxbfn5RXJgsfRryTMX+TBqTbMKa6rITKvtWxi4WYtf1mT2FWbnwwV4g44m4CYGA02z7aKSh8nb3qH6FAmHFc6gRMBOUHFsqhH3oWW8p+eLHdI9qiyIoqjxRLw09/PQKH+2wMoQW3JMkEbbJpKFm2bu9h5cbKqjYYG5JayubhtN1VC5HlZ+eE7WyS231Ickq4gypVDWayMcIqLNO6FAkGJqqsQL3gwbt6h4sseerbG82aaSMoztCNtSXaHA==; 31:rsG33yIhwzkqPXDm4YHVwLtFbELBu440FiGXB93+kIbEMJzKmP0fzjr2H0FOaPcfVIpUhW0N6fFh0/aGbYh+ZkE2+BXSHS0azNfDCx/4F1KlbGc3bxqG2AqgJvFpn4i88wX7okVtlxZn7VlUZMO6ZyFozI+BfgObIZMmNXh70IL7OwmhqP1n2/ZrphC3XgttWXgORqxVT7IyNVggnm4BJRtzwqeyYQMA3CvWWhzl1uM= X-MS-TrafficTypeDiagnostic: BLUPR05MB754: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=thellstrom@vmware.com; X-Microsoft-Exchange-Diagnostics: 1; BLUPR05MB754; 20:Ym++OLrXjeyJfgv7nnc+tJbVdli5YCeO3yj/3xKXYbk1mWxK+l9C4+ta5WRnLmMJRVwL6xrl42xT7Vzg4HYPwHp7kauUdNx+IP96Rxnmpgix6RaAPHn/ZJcPs2fYmhpxmfYhCJF0YvqFxHcFHxSSeXNibxz3PbkJutd8vrDyi+DT/aEYNnHgjfzieGTLu1SYSdTLvjA5BlhI9AcQpJmqjdirJEiwJ1wNLxM/XV4qSW0Kb59xJs2jzby0vtz8v/Y0RZvNuCt16cthQlfhmdkWm1tyvnjFXeNkXAPU/c3gnZUaNJrALfFoSzlyiK/ZzrBlgi4FM4y6BOw5LXo9q+HpdMiYE4i082Fiy9GWTeKZ91PIw+INm8T3Nl2orio5VgHehAV762pP7yO9ducRfj4pMRRARReQi1DdJ5PsqtcvIon0GcbOuafwSvrykAmDFk9L0DIZJAVRFPercEyC6hTGlxQeG5R/unok3mBAeSGD73qN5eas58CS7lkSJxxbuhTm; 4:mtvlrrAv2DaowKGYjgqu2kFIRYwII5LPZdZHnk0/CWhUiN/uVF2VePopgHR8phTe0t8SKcE+x1To4Yt1yu65X34PVeTnwp1pUQ1/n+YZL2ouD7V7OecLBhlZEFCeK63EpHJ8LD5NLPhGEWCgOnBNoRafnuFZ8u7Vp+Z/VYdYQ2IebwkZTBo0HJCsN3TA3+NC+6lSeNiN6lmjn8EUs7ZhyxzS6zKcHP8T5fkDwq+OjzgzNJh4hyWpGNdADtd1ZAwDaue1PQIOERcAS1tlZqHr+sXPfG+Zn9A2KQhC6gGGkErE/JRGfhYXn68A/RQs3QdYQt97VZJqjvKfSLY6fPE4EA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(61668805478150)(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(5005006)(8121501046)(3231023)(2400035)(944501161)(10201501046)(3002001)(93006095)(93001095)(6041268)(20161123562045)(20161123564045)(20161123560045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:BLUPR05MB754; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:BLUPR05MB754; X-Forefront-PRVS: 0554B1F54F X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(39380400002)(39860400002)(346002)(376002)(366004)(189003)(199004)(6116002)(2351001)(6506007)(386003)(5660300001)(2870700001)(3846002)(4326008)(305945005)(8676002)(68736007)(54906003)(16526018)(86362001)(59450400001)(2361001)(97736004)(81156014)(7736002)(50226002)(81166006)(8936002)(2906002)(36756003)(6916009)(52116002)(6512007)(6486002)(50466002)(76176011)(66066001)(53936002)(47776003)(2950100002)(23676004)(105586002)(106356001)(478600001)(8666007)(6666003)(316002)(25786009)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR05MB754; H:ubuntu.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: vmware.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTFVQUjA1TUI3NTQ7MjM6WUh1M2dnbkQ0T3ExWFVaYnJ0M0xSam5DbnVj?= =?utf-8?B?T2lhQlpLTzRyc1UycC91SW1MM2VLcWVrWkRqcUMxaFZGS3E4ZllEc0NKUThL?= =?utf-8?B?YXA3WWlTT085RVlWY3hvQ0N3MkNKWnc0THUvZGFDd2dPRTdKc1lpTXZHU0lX?= =?utf-8?B?QjNDZFhMeDdlN2JSL2ZObElEY2h6VmpXL1dWU0NuQ3ErcXBUV29aRkdIZW5O?= =?utf-8?B?OGFqeS9sbW1MbVVEYmpmSXM4dHpLS0NXelJnZTNBM25UUDBrNVFlY2tlZG1j?= =?utf-8?B?U2JVTitXWGwyUjZsU1ZPY3JqZCtuNG5lbkFobG5oWDhHbFlhTVFGM2F2ZWMx?= =?utf-8?B?Mm83ZHpzY3YwbnI4NXBrUEswOWFxZ2tMS2MrdlVzWlF4anhXRCtvNHJsVXJx?= =?utf-8?B?MEtldVdsUEFDQnRTdjRRTXRqeThxUUNXeG94bUFOdWNRbm1CUUhmN3NOK25I?= =?utf-8?B?RTA5VUV0WGpDbkF6OWFpN3VtSDRPTnRUd2MyTU9UZUh4S2pvNkZnMHNVSC9r?= =?utf-8?B?dWxFY29FdlVXREdnS0J0c25YSk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gOWwNpCxeVLrWGy7a+ZFNd4Cgd4rBas5PdOOWRqaRxxiZ1BJVELAWwQQg3 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BLUPR05MB754; 20:aQMvOzIpDxnlLq9/4RFsMiKLwrKTs4z0c5wWRV8Th7M3Dar2lwHmcI7SVfzugN6W3Y/O3ArGuzNoUcL8jbBBnnquOR68e3koU+1WCefG2kdcjSOn2rfc0rBjd3vjHsZUvTzxZmlcW17mNq92uAkbylziIAaxgQsovrET0YxEZH0= X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2018 13:57:07.6910 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4513bb20-f6bf-43fe-1594-08d55ce90893 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR05MB754 Cc: Thomas Hellstrom , =?UTF-8?q?Christian=20K=C3=B6nig?= 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 Use helpers to perform the kmap_atomic_prot() functionality to a) Avoid in-function ifdefs that violate the kernel coding policy, b) Facilitate exporting the functionality. This commit should not change any functionality. Cc: Christian König Signed-off-by: Thomas Hellstrom Reviewed-by: Christian König --- drivers/gpu/drm/ttm/ttm_bo_util.c | 64 +++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c index 153de1b..6d6d939 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_util.c +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c @@ -255,6 +255,33 @@ static int ttm_copy_io_page(void *dst, void *src, unsigned long page) return 0; } +#ifdef CONFIG_X86 +#define __ttm_kmap_atomic_prot(__page, __prot) kmap_atomic_prot(__page, __prot) +#define __ttm_kunmap_atomic(__addr) kunmap_atomic(__addr) +#else +#define __ttm_kmap_atomic_prot(__page, __prot) vmap(&__page, 1, 0, __prot) +#define __ttm_kunmap_atomic(__addr) vunmap(__addr) +#endif + +static void *ttm_kmap_atomic_prot(struct page *page, + pgprot_t prot) +{ + if (pgprot_val(prot) == pgprot_val(PAGE_KERNEL)) + return kmap_atomic(page); + else + return __ttm_kmap_atomic_prot(page, prot); +} + + +static void ttm_kunmap_atomic_prot(void *addr, + pgprot_t prot) +{ + if (pgprot_val(prot) == pgprot_val(PAGE_KERNEL)) + kunmap_atomic(addr); + else + __ttm_kunmap_atomic(addr); +} + static int ttm_copy_io_ttm_page(struct ttm_tt *ttm, void *src, unsigned long page, pgprot_t prot) @@ -266,28 +293,13 @@ static int ttm_copy_io_ttm_page(struct ttm_tt *ttm, void *src, return -ENOMEM; src = (void *)((unsigned long)src + (page << PAGE_SHIFT)); - -#ifdef CONFIG_X86 - dst = kmap_atomic_prot(d, prot); -#else - if (pgprot_val(prot) != pgprot_val(PAGE_KERNEL)) - dst = vmap(&d, 1, 0, prot); - else - dst = kmap(d); -#endif + dst = ttm_kmap_atomic_prot(d, prot); if (!dst) return -ENOMEM; memcpy_fromio(dst, src, PAGE_SIZE); -#ifdef CONFIG_X86 - kunmap_atomic(dst); -#else - if (pgprot_val(prot) != pgprot_val(PAGE_KERNEL)) - vunmap(dst); - else - kunmap(d); -#endif + ttm_kunmap_atomic_prot(dst, prot); return 0; } @@ -303,27 +315,13 @@ static int ttm_copy_ttm_io_page(struct ttm_tt *ttm, void *dst, return -ENOMEM; dst = (void *)((unsigned long)dst + (page << PAGE_SHIFT)); -#ifdef CONFIG_X86 - src = kmap_atomic_prot(s, prot); -#else - if (pgprot_val(prot) != pgprot_val(PAGE_KERNEL)) - src = vmap(&s, 1, 0, prot); - else - src = kmap(s); -#endif + src = ttm_kmap_atomic_prot(s, prot); if (!src) return -ENOMEM; memcpy_toio(dst, src, PAGE_SIZE); -#ifdef CONFIG_X86 - kunmap_atomic(src); -#else - if (pgprot_val(prot) != pgprot_val(PAGE_KERNEL)) - vunmap(src); - else - kunmap(s); -#endif + ttm_kunmap_atomic_prot(src, prot); return 0; }