From patchwork Tue Feb 22 14:52:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Vivekanandan, Balasubramani" X-Patchwork-Id: 12755257 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1F7F9C433EF for ; Tue, 22 Feb 2022 14:51:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 052D110E818; Tue, 22 Feb 2022 14:51:26 +0000 (UTC) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id D0AC810E818; Tue, 22 Feb 2022 14:51:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645541484; x=1677077484; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=r19qf66yrOMC2QK5I+WIFk5Cujmy4szIiBaFKOkhYSI=; b=R53Vy325xnMXd3j9akyodnl5WZ+lM6rhE4Yxeq9cqZOHWLNWustJRE31 Ik8Uf/hQhS4gQBq25TTl6Yv/zj/dyh1wbXZpDxnEvImqns8XhbBhqeagH dwDFCD3io0jgDHEzZNZMaHPH9w+vsGi70ItvR40fpj3SPAbcVasdpORsi fPP0Q3NBvPSvaRgqaTp0cpMIPEZXAPyNqVTQJ5Hrr2J0gaSFO0o5bZkaq aKc9WHcr92B+WGBlluxf6Nn9Zd87gFafVAdcY917cejJPTZ0Wl9Xs754Y noKjqLTOyYKxEKojACI96gvQ8foOLubbsxzoDUeHwNPIsEsfeiaUB3iDo w==; X-IronPort-AV: E=McAfee;i="6200,9189,10265"; a="276320813" X-IronPort-AV: E=Sophos;i="5.88,387,1635231600"; d="scan'208";a="276320813" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2022 06:51:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,387,1635231600"; d="scan'208";a="573453808" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga001.jf.intel.com with ESMTP; 22 Feb 2022 06:51:24 -0800 Received: from orsmsx601.amr.corp.intel.com (10.22.229.14) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Tue, 22 Feb 2022 06:51:23 -0800 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Frontend Transport; Tue, 22 Feb 2022 06:51:23 -0800 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.108) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Tue, 22 Feb 2022 06:51:23 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OOs73EEnBLth2qwWeo+K6wkYg+Gi9Aj+TssbQvBDlLUxS/EOMZ9fHopl+Iihmx+9qKERKNKikTmFypDV72X3L5hSk0oeCqbUBY/uKX7mNZ7aIvBp/uXRzDWuhyn+70lF5hVaENw4ya39rNebXNVxqenPJKMh1I0NuydaWN4P4rRVJfRVGps2CjiYkPVqrrO/B4hiDUGB/OSxe5wGbCtKqMX7ojv5ois9nVj1OznKz1SJ/89Q4cHuwZdxhv4b2m1Qc/esCeLqH8u37BYY9+FLeq8G2g1/NvKLLGfPFB12Xb13zADCWBzAK1mlhSAHNkCK1yyVJ1ey7ufbpS4YtkLyOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=RbxQnpLY+ob0lV8KZGxdbwuc9uApJSCTLIC9IcsxaHk=; b=X4KIyW1K2k73x5OUxwJuqjun+xqishvSn+6DQ1cg+5Q5CiIwA9eDvkIXcknfdht1rb4JUA4+xjnnXnG/ZWPVVuSamkomHXg8HsOR54CTbJiby7t56iVFe08H9KjqOqaHwLA+lrDGi0/jxVUg48IJQKED0GtXVaiH1oygKlfmxLNFELLiO+5NozE1DP2nufafLSEZVl12m0PBTJMyYFIj4s2Zju0FkgrQbJco9EPBNa4YkaX1rggdc5XgV4oaktGXOydLMHYg+EoZVRTCPhZJa9WDikm4hg++XYkX2vxkYbN436KrtpuMlF+M7FBqLXq4Mdy9dds8wriJIc+mNVUjxg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from SJ0PR11MB4894.namprd11.prod.outlook.com (2603:10b6:a03:2d4::5) by PH0PR11MB5627.namprd11.prod.outlook.com (2603:10b6:510:e4::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22; Tue, 22 Feb 2022 14:51:21 +0000 Received: from SJ0PR11MB4894.namprd11.prod.outlook.com ([fe80::d67:8a16:f4cd:b475]) by SJ0PR11MB4894.namprd11.prod.outlook.com ([fe80::d67:8a16:f4cd:b475%9]) with mapi id 15.20.4995.027; Tue, 22 Feb 2022 14:51:21 +0000 From: Balasubramani Vivekanandan To: , Subject: [PATCH 2/7] drm: Add drm_memcpy_from_wc() variant which accepts destination address Date: Tue, 22 Feb 2022 20:22:01 +0530 Message-ID: <20220222145206.76118-3-balasubramani.vivekanandan@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220222145206.76118-1-balasubramani.vivekanandan@intel.com> References: <20220222145206.76118-1-balasubramani.vivekanandan@intel.com> X-ClientProxiedBy: BMXPR01CA0092.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:54::32) To SJ0PR11MB4894.namprd11.prod.outlook.com (2603:10b6:a03:2d4::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1c43e96f-61ec-4e57-63d4-08d9f612ca51 X-MS-TrafficTypeDiagnostic: PH0PR11MB5627:EE_ X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HC++DqaV4pU8xzKZ2iSNZtAtahhBmrYAtlPlTiyK2Q2rE5hmm3vkLARJMNYQnwVnpeBcFxuDeAgSetjq2nT0tQoqCeNfrV+rc5xX2gAwGujWMYx2avuBbZaBIHIm4E0369n5iKGgz9AgtSoP7rla2ID4/VlAh0395eIWJV5Gg/RA5IX2dkKyYzJC4GGZXmb9+hVPBxAH9/zcNQDjHqervDanAHU6Ijso7Ts6EbIdX+3DFolNC88m7s9t9oJJK4zya1FpFmFU8IQTP648hzmig9vOdiGlAjAIBPo130yfwbR6Dlxqyis213ypnggTYz/AkNP4Wq7EoI+dYadebfPLqpxQ0Rv/qEU0W0IVdfW55nFlqC8tW5IgUxWcSYS3Dhhhyd8rqgybexgFZGg9Xd5zElJP095XvHmYqQxoRyuBUyjltloBtcSUf7yPwru+0gSnyLGbh28O9jl0+SI1MCxotjjvgAR1HLIS32Hsh/onnrr4BDjRIMogUXH+dzH9CEGhzPDOws8nujFomqqStD0xYx9Xsn2icLy4ARtgaXXbRvKpBT372owqZ4k4FdN0MJvNudJIy7WrXD+Z9FVeL2oUw+VwWMGftN1AaoHNqIyB6yXeXiJ/KMf5q74rlzG7r4KOkJ+6R8f6gf62qxCWkBIQlQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SJ0PR11MB4894.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(86362001)(82960400001)(38100700002)(316002)(66946007)(66556008)(66476007)(4326008)(8676002)(54906003)(8936002)(44832011)(5660300002)(2906002)(2616005)(36756003)(186003)(26005)(1076003)(6666004)(6486002)(508600001)(6512007)(6506007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qom4qSpdxmbsQs1g5962LLUYzo/qy0/AUjxKnzhMJY6yB5eTTM1AMmo9itlydBFf67oN9ZGedpY24+qi4Sm2g7ugNATyVcURCJYzb2DJ3OSqEXcSlXPXLnFvKTa+OiBlSdPWRto0Y+eXtc7om67M3YQmjpKFycjt3A6oyWmxYIwk9VIMdOQdDorS76p1V/I9HJN0stYTj4m2bPIllLyG0J1ZVBvQxxhAt5l+GaWbO0NKRtHl5APMmIhIDoQhjMC4MY5z8N1qir/k5d7vSMie9dG6OuNUZ/OvMZ/OPdZ44tGA0Mf8IpirbAtL0TLB8ahO0122CLx0ZVg65wjDygecl0GPsICgu076KimmVDNgVOrNqt6ao5ZpEMMQwI+v+uB7N0ArfnsCdp9UmbRQqDqJvbgmTRNsxxVL/yO9onzhw3UGT6qX9coo3Vvg21XtOWnP5hViDcpHyRiR/OHTyQI5W9778KMneIHPy4CMyHEUv/gBV47uZ3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hbbaxGZXV9uM/g1Ms/wHnyV2AfeV2P9Q6DDm6ncfrpIRLTtIuHPIL+lJRRfXz4U4dE7qZPgibZT19/Sp6/Dv9pWF7dst/NQcJKdjKHuvph6Dra2n+5yD/+t6pRr8C+M1nMvN3vZ0oAGUTc4phsqComSshi21ZmsAgl6wJdzT9Tlp/QFNfw== X-MS-Exchange-CrossTenant-Network-Message-Id: 1c43e96f-61ec-4e57-63d4-08d9f612ca51 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR11MB4894.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Feb 2022 14:51:21.4905 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bBzoAekQVjncggmVcaymA989Ay+TCDEToKu/7Daljl2RhXVVBhRfEQwoXKz7BwecZ3NiZGN52O7FDhIqIik01+rX7YZngo5finMy0KJQDpfCxVXk9fGqz08/CCIqu8OM X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5627 X-OriginatorOrg: intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Hellstr_m , michael.cheng@intel.com, Balasubramani Vivekanandan , wayne.boyer@intel.com, David Airlie , casey.g.bowman@intel.com, lucas.demarchi@intel.com, siva.mullati@intel.com, Thomas Zimmermann Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Fast copy using non-temporal instructions for x86 currently exists at two locations. One is implemented in i915 driver at i915/i915_memcpy.c and another copy at drm_cache.c. The plan is to remove the duplicate implementation in i915 driver and use the functions from drm_cache.c. A variant of drm_memcpy_from_wc() is added in drm_cache.c which accepts address as argument instead of iosys_map for destination. It is a very common scenario in i915 to copy from a WC memory type, which may be an io memory or a system memory to a destination address pointing to system memory. To avoid the overhead of creating iosys_map type for the destination, new variant is created to accept the address directly. Also a new function is exported in drm_cache.c to find if the fast copy is supported by the platform or not. It is required for i915. Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Thomas Zimmermann Cc: David Airlie Cc: Daniel Vetter Cc: Thomas Hellstr_m Signed-off-by: Balasubramani Vivekanandan --- drivers/gpu/drm/drm_cache.c | 54 +++++++++++++++++++++++++++++++++++++ include/drm/drm_cache.h | 3 +++ 2 files changed, 57 insertions(+) diff --git a/drivers/gpu/drm/drm_cache.c b/drivers/gpu/drm/drm_cache.c index a21c1350eb09..eb0bcd33665e 100644 --- a/drivers/gpu/drm/drm_cache.c +++ b/drivers/gpu/drm/drm_cache.c @@ -358,6 +358,54 @@ void drm_memcpy_from_wc(struct iosys_map *dst, } EXPORT_SYMBOL(drm_memcpy_from_wc); +/** + * drm_memcpy_from_wc_vaddr - Perform the fastest available memcpy from a source + * that may be WC. + * @dst: The destination pointer + * @src: The source pointer + * @len: The size of the area to transfer in bytes + * + * Same as drm_memcpy_from_wc except destination is accepted as system memory + * address. Useful in situations where passing destination address as iosys_map + * is simply an overhead and can be avoided. + */ +void drm_memcpy_from_wc_vaddr(void *dst, const struct iosys_map *src, + unsigned long len) +{ + if (WARN_ON(in_interrupt())) { + iosys_map_memcpy_from(dst, src, 0, len); + return; + } + + if (static_branch_likely(&has_movntdqa)) { + __drm_memcpy_from_wc(dst, + src->is_iomem ? + (void const __force *)src->vaddr_iomem : + src->vaddr, + len); + return; + } + + iosys_map_memcpy_from(dst, src, 0, len); +} +EXPORT_SYMBOL(drm_memcpy_from_wc_vaddr); + +/* + * drm_memcpy_fastcopy_supported - Returns if fast copy using non-temporal + * instructions is supported + * + * Returns true if platform has support for fast copying from wc memory type + * using non-temporal instructions. Else false. + */ +bool drm_memcpy_fastcopy_supported(void) +{ + if (static_branch_likely(&has_movntdqa)) + return true; + + return false; +} +EXPORT_SYMBOL(drm_memcpy_fastcopy_supported); + /* * drm_memcpy_init_early - One time initialization of the WC memcpy code */ @@ -382,6 +430,12 @@ void drm_memcpy_from_wc(struct iosys_map *dst, } EXPORT_SYMBOL(drm_memcpy_from_wc); +bool drm_memcpy_fastcopy_supported(void) +{ + return false; +} +EXPORT_SYMBOL(drm_memcpy_fastcopy_supported); + void drm_memcpy_init_early(void) { } diff --git a/include/drm/drm_cache.h b/include/drm/drm_cache.h index 22deb216b59c..8f48e4dcd7dc 100644 --- a/include/drm/drm_cache.h +++ b/include/drm/drm_cache.h @@ -77,4 +77,7 @@ void drm_memcpy_init_early(void); void drm_memcpy_from_wc(struct iosys_map *dst, const struct iosys_map *src, unsigned long len); +bool drm_memcpy_fastcopy_supported(void); +void drm_memcpy_from_wc_vaddr(void *dst, const struct iosys_map *src, + unsigned long len); #endif