From patchwork Tue Mar 12 03:10:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunming Zhou X-Patchwork-Id: 10848561 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 376971515 for ; Tue, 12 Mar 2019 03:12:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 249A8291A9 for ; Tue, 12 Mar 2019 03:12:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 18B60294BD; Tue, 12 Mar 2019 03:12:05 +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=-5.2 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 9A808291A9 for ; Tue, 12 Mar 2019 03:12:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 01ED889DA4; Tue, 12 Mar 2019 03:12:01 +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-co1nam03on0618.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe48::618]) by gabe.freedesktop.org (Postfix) with ESMTPS id A72C689C63; Tue, 12 Mar 2019 03:11:59 +0000 (UTC) Received: from BN4PR12CA0006.namprd12.prod.outlook.com (2603:10b6:403:2::16) by BN8PR12MB2961.namprd12.prod.outlook.com (2603:10b6:408:61::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1686.18; Tue, 12 Mar 2019 03:11:57 +0000 Received: from DM3NAM03FT055.eop-NAM03.prod.protection.outlook.com (2a01:111:f400:7e49::208) by BN4PR12CA0006.outlook.office365.com (2603:10b6:403:2::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1686.16 via Frontend Transport; Tue, 12 Mar 2019 03:11:57 +0000 Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) Received: from SATLEXCHOV01.amd.com (165.204.84.17) by DM3NAM03FT055.mail.protection.outlook.com (10.152.83.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1686.19 via Frontend Transport; Tue, 12 Mar 2019 03:11:57 +0000 Received: from zhoucm1.amd.com (10.34.1.3) by SATLEXCHOV01.amd.com (10.181.40.71) with Microsoft SMTP Server id 14.3.389.1; Mon, 11 Mar 2019 22:11:56 -0500 From: Chunming Zhou To: , , , , Subject: [PATCH 8/9] drm/syncobj: add timeline signal ioctl for syncobj v3 Date: Tue, 12 Mar 2019 11:10:48 +0800 Message-ID: <20190312031049.23647-8-david1.zhou@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190312031049.23647-1-david1.zhou@amd.com> References: <20190312031049.23647-1-david1.zhou@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:165.204.84.17; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(136003)(39860400002)(346002)(376002)(396003)(2980300002)(428003)(3190300001)(189003)(199004)(104016004)(36756003)(316002)(305945005)(8936002)(97736004)(53936002)(50226002)(68736007)(6636002)(51416003)(7696005)(2906002)(8676002)(76176011)(126002)(105586002)(336012)(476003)(16586007)(81156014)(2616005)(426003)(486006)(81166006)(4326008)(2201001)(86362001)(48376002)(478600001)(6666004)(50466002)(186003)(356004)(53416004)(14444005)(110136005)(77096007)(26005)(106466001)(11346002)(446003)(1076003)(47776003)(5660300002)(72206003); DIR:OUT; SFP:1101; SCL:1; SRVR:BN8PR12MB2961; H:SATLEXCHOV01.amd.com; FPR:; SPF:None; LANG:en; PTR:InfoDomainNonexistent; MX:1; A:1; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 23ca7430-ea55-4925-52b1-08d6a6987c7c X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(2017052603328)(7153060); SRVR:BN8PR12MB2961; X-MS-TrafficTypeDiagnostic: BN8PR12MB2961: X-Microsoft-Exchange-Diagnostics: 1; BN8PR12MB2961; 20:BInFhoyVMr6G0OucYagZSLMmzGUHzScQVq8xjI56l2LhC2HHjnl0+HANV+wGNyNvpupPtwIG8iO9fCKVOlb0oSeXHfZZ2t44OL1TFTx5QWFJHM/739fLcDTZXKlXkP92Wp3vJvPe4lAfXNlsG8HUsLYK0t6GaZda4HhiT90gbjSNam3RuIIHjq5kTUVEVx/sXsNF0O0Fkqbm9TyAZYZ1cxzBQaYOjGTefgE1OXTlnkTuNwPGtWWkrPEaQkSlh0WoKhszUGVYS6jJPlKwPKBnLgKd3AzokSKaiyNO/ndQyuXsTUSsDCTg400hl3io5UUkpeuIbW/JbnLPn74VLA82OYcdcSEP8BF9Mc9O+PsbXlrO4rR4RKcBZzjBPzwm5ls55G1QE7A21UxKd9ZQqOaqzOVphyArMpMQpPo97NzQ14boHAOaReOoIhVP5E+QHRqw4kIjKA7NkzawoT2FT57reK3+ge3tgSFiw68sZuPPYAbYLvndf7/qszcZLW42eaw5 X-Microsoft-Antispam-P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txGu3od55n5QE7VltF0toGj3fH0lZYBee3U4V514BnRK068VMJZ7yXa6IqXdlq+9LMf8x8RQcMmPTeba1BZVGY7wqgJmFUQHvndefSQ7V2+jlRph1POzruDZ7PlDKpJHu8l0k0LNvIQCFlowopVzT7smpA+8SBA0yiagTMH3lutnf8oyMCagJXJQX6EbErcfxbicYdfmwekNqsN9KFE35TcDZv0YrEho/XCQEdVbbPJCQ== X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: zz7VAOQRahP0Hb1JjdB5QY+T30R0+ZwchEBllkONRU8v/hmO+jTurpuUvoSa3q82oOzZ2P/JJbFb3U/OGifULIaL7vumICx6PHTAVv+yKTib9MTFg/M16gGuVNN0feTCkaICM4o9F7v6qn7jAmAIXik9C5WQK5p2rynx9rhJ1F/uMYCXKfHk30PeOKGX5mXoABkWPOOCF8MD/s8WN1bDnRhW6H2cO0Ph9lcYMh7H1OKTTbNimv0iQ3pIPs14LsAcg/YNWiQ200iB/5aDCvaqZdwCtP639eR22oTViGOeu2kwAp9twD/D+Sv6AH+F+G95qL8OzU4V5CuMQCCqACsDfEItzy/P/Kt/kHfLIOM9IMbFt+a4tDQ0dhBZGL04z9TrVMQ8QfmDQl0BkAn/vAyMifT0l/c/39cBv68fch5CYlU= X-Microsoft-Exchange-Diagnostics: 1; BN8PR12MB2961; 20:1pd8LnpEIexQvUHJaP3IprXQt7wbQ+dNyPgE98wxVGLcz5jC/tQ30+K/Q8M7nwg1O/Wiq4p0/8Cmvtl29xrd19hjupwr8yu5PI8AmKwjK08Vz6W6PJY9eviNDnP8IUrqyYoRZfkq9ySwG3J9P3J0Dct9j4VAjfb02XNmcUnc4prkavAvEslnysOm/E6Q8bBjrQlz1XzkviJ8v6zBLeBQIMeAG26XEzqAfO5kygsqFEc8VSPVYV42iyneLVVssvqN X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Mar 2019 03:11:57.0999 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 23ca7430-ea55-4925-52b1-08d6a6987c7c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXCHOV01.amd.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB2961 X-Mailman-Original-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:X-MS-Exchange-SenderADCheck; bh=1cd0iJB9Yzvt6glQ7+6gs3XzVHiquIZhD2GQoeH3SYg=; b=xpLmoioBWPbB6ITdSuqmSkIL/97M5sDmrEo0Uu2v8h3Ta5XitGn2ifgg3pmmqfAlrhPifK4oca6m/yZ/09vQJvrNEpV9r/sbxEdeJX59SemXAdXfF42C2aqvpb2OUj3GHS123uKD50xoSLSr7/NnyPj5ROFbkGS/4pdLHNLZPwY= X-Mailman-Original-Authentication-Results: spf=none (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=permerror action=none header.from=amd.com; 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 v2: individually allocate chain array, since chain node is free independently. v3: all existing points must be already signaled before cpu perform signal operation, so add check condition for that. Signed-off-by: Chunming Zhou --- drivers/gpu/drm/drm_internal.h | 2 + drivers/gpu/drm/drm_ioctl.c | 2 + drivers/gpu/drm/drm_syncobj.c | 103 +++++++++++++++++++++++++++++++++ include/uapi/drm/drm.h | 1 + 4 files changed, 108 insertions(+) diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h index dd11ae5f1eef..d9a483a5fce0 100644 --- a/drivers/gpu/drm/drm_internal.h +++ b/drivers/gpu/drm/drm_internal.h @@ -190,6 +190,8 @@ int drm_syncobj_reset_ioctl(struct drm_device *dev, void *data, struct drm_file *file_private); int drm_syncobj_signal_ioctl(struct drm_device *dev, void *data, struct drm_file *file_private); +int drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_private); int drm_syncobj_query_ioctl(struct drm_device *dev, void *data, struct drm_file *file_private); diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c index 92b3b7b2fd81..d337f161909c 100644 --- a/drivers/gpu/drm/drm_ioctl.c +++ b/drivers/gpu/drm/drm_ioctl.c @@ -696,6 +696,8 @@ static const struct drm_ioctl_desc drm_ioctls[] = { DRM_UNLOCKED|DRM_RENDER_ALLOW), DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SIGNAL, drm_syncobj_signal_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW), + DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL, drm_syncobj_timeline_signal_ioctl, + DRM_UNLOCKED|DRM_RENDER_ALLOW), DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_QUERY, drm_syncobj_query_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW), DRM_IOCTL_DEF(DRM_IOCTL_CRTC_GET_SEQUENCE, drm_crtc_get_sequence_ioctl, DRM_UNLOCKED), diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c index f1d18d10d1f2..78fc1c029339 100644 --- a/drivers/gpu/drm/drm_syncobj.c +++ b/drivers/gpu/drm/drm_syncobj.c @@ -1174,6 +1174,109 @@ drm_syncobj_signal_ioctl(struct drm_device *dev, void *data, return ret; } +int +drm_syncobj_timeline_signal_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_private) +{ + struct drm_syncobj_timeline_array *args = data; + struct drm_syncobj **syncobjs; + struct dma_fence_chain **chains; + uint64_t *points; + uint32_t i, j, timeline_count = 0; + int ret; + + if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ)) + return -EOPNOTSUPP; + + if (args->pad != 0) + return -EINVAL; + + if (args->count_handles == 0) + return -EINVAL; + + ret = drm_syncobj_array_find(file_private, + u64_to_user_ptr(args->handles), + args->count_handles, + &syncobjs); + if (ret < 0) + return ret; + + for (i = 0; i < args->count_handles; i++) { + struct dma_fence_chain *chain; + struct dma_fence *fence; + + fence = drm_syncobj_fence_get(syncobjs[i]); + chain = to_dma_fence_chain(fence); + if (chain) { + struct dma_fence *iter; + + dma_fence_chain_for_each(iter, fence) { + if (!iter) + break; + if (!dma_fence_is_signaled(iter)) { + dma_fence_put(iter); + DRM_ERROR("Client must guarantee all existing timeline points signaled before performing host signal operation!"); + ret = -EPERM; + goto out; + } + } + } + } + + points = kmalloc_array(args->count_handles, sizeof(*points), + GFP_KERNEL); + if (!points) { + ret = -ENOMEM; + goto out; + } + if (!u64_to_user_ptr(args->points)) { + memset(points, 0, args->count_handles * sizeof(uint64_t)); + } else if (copy_from_user(points, u64_to_user_ptr(args->points), + sizeof(uint64_t) * args->count_handles)) { + ret = -EFAULT; + goto err_points; + } + + + for (i = 0; i < args->count_handles; i++) { + if (points[i]) + timeline_count++; + } + chains = kmalloc_array(timeline_count, sizeof(void *), GFP_KERNEL); + if (!chains) { + ret = -ENOMEM; + goto err_points; + } + for (i = 0; i < timeline_count; i++) { + chains[i] = kzalloc(sizeof(struct dma_fence_chain), GFP_KERNEL); + if (!chains[i]) { + for (j = 0; j < i; j++) + kfree(chains[j]); + ret = -ENOMEM; + goto err_chains; + } + } + + for (i = 0, j = 0; i < args->count_handles; i++) { + if (points[i]) { + struct dma_fence *fence = dma_fence_get_stub(); + + drm_syncobj_add_point(syncobjs[i], chains[j++], + fence, points[i]); + dma_fence_put(fence); + } else + drm_syncobj_assign_null_handle(syncobjs[i]); + } +err_chains: + kfree(chains); +err_points: + kfree(points); +out: + drm_syncobj_array_free(syncobjs, args->count_handles); + + return ret; +} + int drm_syncobj_query_ioctl(struct drm_device *dev, void *data, struct drm_file *file_private) { diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h index 4c1e2e6579fa..fe00b74268eb 100644 --- a/include/uapi/drm/drm.h +++ b/include/uapi/drm/drm.h @@ -943,6 +943,7 @@ extern "C" { #define DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT DRM_IOWR(0xCA, struct drm_syncobj_timeline_wait) #define DRM_IOCTL_SYNCOBJ_QUERY DRM_IOWR(0xCB, struct drm_syncobj_timeline_array) #define DRM_IOCTL_SYNCOBJ_TRANSFER DRM_IOWR(0xCC, struct drm_syncobj_transfer) +#define DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL DRM_IOWR(0xCD, struct drm_syncobj_timeline_array) /** * Device specific ioctls should only be in their respective headers