Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp2796950rwe; Sun, 28 Aug 2022 23:30:06 -0700 (PDT) X-Google-Smtp-Source: AA6agR4VQPKC7iVLhBxpU2DHRUtVJgReGi9y0OrT4HeBnmakVGEWZQ/qyXn7wGP4lmtHP42+ZtPR X-Received: by 2002:a17:907:720f:b0:731:8a9d:5ade with SMTP id dr15-20020a170907720f00b007318a9d5ademr12308955ejc.768.1661754606341; Sun, 28 Aug 2022 23:30:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1661754606; cv=pass; d=google.com; s=arc-20160816; b=jBtvEBknHwTsJAAj9fCIT6YgWnbJLQgGKXYksoRshO7q1NcJVdjc88XriP8TFQ65Kx LFmcttiImn2dqsWnR6YByccuRyhY6k3WGxfJt7npNHjIh79iTapReYOEfDEs9+OXgSUh BmS0c0hQ+sOC3UjAG5bJaVJbZQ6/n72UF1MqDBzWA2ZN4LJfeBXrR6JesLmhJcrfkHlj +UYsjp9VVIlOaQp+3riLpXgOdNVEsdyRDVaWMb3zNHsV5HUNWYTxcxwDLCVi870eCnPr pMr5QNhKzKaKb33QI0ZKjmvlZhidETAJGWv5YTbsBYLq04WszgpfLD+dxDSJG9NWTkGv e1aA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=cTGHZkuwUO1QTa4W1T3PxT1vwiZmcn+6Hc5XWzlXrGA=; b=CU6ekdIlKEhfbbSLrxEvsDLqD5lzwPgWDWsYuLxqc8yz108zMT1hUrjz4FXDJm3Lyn 9sshG6/13nxe4xYC0fDsQcB1uJfoyepsih/DTbo3qF1F7/NkLPeFF6lLy5KuTfWdp7i3 Mai6HH1G4Xm6LKrBxEDpnhA5gkGpLvgpEpneE5w+mTgDkZ1lhvou3UrZs3LyD6MoJVm9 RzlVPXXQzx+OWoGoCyCJ0vWyjvZC35/7CF3e7axK47A2ZOPe+xp5qzmPOOThAEnRTzMk kj+xVLt4tSuyA+/rVyiJhoYU2RowvhqFWGDo1Tev8vMwqaZ3l8ftsAARBHiLtNxT/i1W T6yw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=x5Yp6rQi; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o16-20020a170906975000b007304fac484fsi6494898ejy.466.2022.08.28.23.29.39; Sun, 28 Aug 2022 23:30:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=x5Yp6rQi; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229679AbiH2F60 (ORCPT + 99 others); Mon, 29 Aug 2022 01:58:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229455AbiH2F6Y (ORCPT ); Mon, 29 Aug 2022 01:58:24 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2052.outbound.protection.outlook.com [40.107.100.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22B0CBFC; Sun, 28 Aug 2022 22:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oN0weiwhJhKdSwicYc+WvUkn2JhOCVfRZPypa4zdYaFK8nUsGcCU0Lnoy1MY+/j8gOmnpIZvUlxcXC5nRHGME054l+5OPbRCPenPrhDgZ1yY7O3Sqita9y7kX/xHJPpq0ETbNn07tf00DkN6pb18NXlg15sDhLoo/X+r67Z5mYUz6fXzNtqkSWvDv5ADhfd0Wf1IsyH3bDwn5y1yQU4wTD6/YGP71JrPceHuev57F2Tn3gGpCZGGraUyzYnmur2zx2EEfIlFJWGr5aba+a+8t1cfJFYcLNucRr114NlOpTWbWaR1Up4zXPolXWdu9QyAeR+8uDgbHfpS/hhCM5oRMw== 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=cTGHZkuwUO1QTa4W1T3PxT1vwiZmcn+6Hc5XWzlXrGA=; b=Rxg2Hs5DK8KkjANgntpfv/ctwkwgG8ekg4c4amcHKEaS8fCkqnafVqdCQJClgxZ762RRvrr6cj/LHU/oh80xO7xD4yGSnqCcW1y244Xtnaa1h8zrgGSKpIfuAHANmFkhm7q/fwx5JPngqReHQ62tSr1WZCRSusn/ivnT9xwdF6OcvHHfUsV+G60m7AFcHAGxJ+yLdW7R62CjFnF0Dq+edjekE78LsI+JIDDBGrnSUPWLgJQ4vKTG3BRQ6FFr5m7HqqzOZ3S5jHFzodw1pJT01K15G/KTd78H2f2dDYeWw0pzse3Ufp/xQ8gSQ5ukDe6x9Gd1owAPLOjeMhT72HaFCw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cTGHZkuwUO1QTa4W1T3PxT1vwiZmcn+6Hc5XWzlXrGA=; b=x5Yp6rQiDIP0ivrQRydAnkKUNZyB0xXN7h+p4PQWiAtkZ8ibW8aW+iYM3NEK3EHk6Pq7T9q2BSCjpJfCo7U7tt628pVf6p/ruGeSH1WrqH8XbIUg6GfKI/CwcJHPQQwFm7+NchUwho60+4zIzJk2X6ezzw0Z6N4xaAkqNxlnHr4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) by BL1PR12MB5301.namprd12.prod.outlook.com (2603:10b6:208:31f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.15; Mon, 29 Aug 2022 05:58:20 +0000 Received: from BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::4524:eda6:873a:8f94]) by BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::4524:eda6:873a:8f94%7]) with mapi id 15.20.5566.021; Mon, 29 Aug 2022 05:58:17 +0000 Message-ID: <732919ef-c8b8-159b-6f69-e95eea710680@amd.com> Date: Mon, 29 Aug 2022 07:58:10 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PTACH v3] drm/ast: add dmabuf/prime buffer sharing support Content-Language: en-US To: oushixiong , Dave Airlie Cc: Thomas Zimmermann , David Airlie , Daniel Vetter , Sumit Semwal , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org References: <20220827091030.496671-1-oushixiong@kylinos.cn> From: =?UTF-8?Q?Christian_K=c3=b6nig?= In-Reply-To: <20220827091030.496671-1-oushixiong@kylinos.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: AS8PR04CA0190.eurprd04.prod.outlook.com (2603:10a6:20b:2f3::15) To BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fe909fb5-68ae-4e35-7210-08da898377f4 X-MS-TrafficTypeDiagnostic: BL1PR12MB5301:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XIdoh75OqVIHX4FCit/2u3kMKC3UOAHTVjE6MjzPrqsFQSzgVBM79VqNHuKowmz3RPHsbqLz1NTnVibMp3HlgFlbCdabcmHh/J4lVXZosybghqzYU5JDePJK6WXHcNIqNelwKNRXN6nMhX2ZlMYaJrexjcQISML3sZQnXOgr9NNWAdnnblOXBSXJOxGsCjesz3sfT+p/eNLDXVI63zNyKvzhBrWVj8xaoTFkMTubmqY9362rVDMZ8QUm2zlyAhYB8G9RWXOBg3Z7qN0tI7TKgnm64TwrxTulVR/vbvN5IoQtN7sAMJ+pDuqZx/4T5TNwU7xxXaARs0HjBADHZDrqgSwg1gaP2RU+Wm3cmuhcGjyV7MIDsCVXjWAGlLNUv8aR5rK+P7AfiVY8o0cRJCa9elYbwgCa417N6dv2y8W9/a3C7Qh7URXj/9mni57bw6RiVXs6aPhDmIbONPn/zjwgPLG8s1fdOgwPs9+PgfyTkrDEoiaTVRf+2P0r1jzJ3wnU3RFMYUZt9zBBJwp2reSpAmoMg/eRio8LITJz5omkmsOP0bf+ROP5Qp5Y+rY+f08gV1aQd3Oz3I4epDjCjpTPMikbwu0n+78BgEGXW5vrC4cw0MpzNBvVZZ33y8tMmD9ll7lrKT7UZ+InKJWkjFyZF44Ehf6FX8F/tYwoJ45dUUyzqr/PXEl/yxnQYRvdGvLyKacYzpvpy4igSpYIVeVMACHyn6YDkAKtoXw+a0UktWnM0sj0yRFAJyVxgSpbpL2iDzwCcyeTA5TyktWZjfNTArJZJfABgTEDg83ovOWUqBI= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR12MB3587.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(396003)(376002)(39860400002)(366004)(346002)(136003)(38100700002)(2906002)(6512007)(26005)(6666004)(6506007)(2616005)(66574015)(186003)(83380400001)(316002)(110136005)(8676002)(4326008)(66476007)(66556008)(66946007)(31696002)(6486002)(54906003)(31686004)(7416002)(41300700001)(86362001)(8936002)(5660300002)(36756003)(478600001)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?R1RCNlBvVGcydGRMNFRrdW1wV2RpLzZoZmMzRzc1VzN3YW9YRGVJMWlFVWVk?= =?utf-8?B?YkhJN1hNNUo5UW1JSmF1cnB3bXAyaVFTNmhUc004QlhUUHpqbmVIamdGOTBL?= =?utf-8?B?c3BldUNGZGFLT3RjNEN5ZmVvNUVnMVN5ZDZpeTR3ZUpmMFhjRmlPQ1BtOERk?= =?utf-8?B?ZWQyWTQ3UGthRHJwZUFBTUl4SER0NHNLMW02d2E3a25JVVV0d2YrRUhYdWhM?= =?utf-8?B?UEJFY2svbjZOZHVGRm5ackdzN2xkWGI4OXBkMjFiMWhRRHBzYnF6dVhjR2ZG?= =?utf-8?B?bEwra0MyR0tDRUVFSko0RE5NZ2xwcUlmV0oxQThFMWs0b0ZHdmE4S3hSZ0hz?= =?utf-8?B?TDIvcHFLQndQaTJLMzhac3JmQi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OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe909fb5-68ae-4e35-7210-08da898377f4 X-MS-Exchange-CrossTenant-AuthSource: BN8PR12MB3587.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2022 05:58:17.4919 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5HOF9GQB182lDeD7736crp7rMkHnxQAnLuqEFXrcBoLTvZoIVdichDhkPRB5t6Fd X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5301 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 27.08.22 um 11:10 schrieb oushixiong: > This patch adds ast specific codes for DRM prime feature, this is to > allow for offloading of rending in one direction and outputs in other. > > This patch is designed to solve the problem that the AST is not displayed > when the server plug in a discrete graphics graphics card at the same time. > We call the dirty callback function to copy the rendering results of the > discrete graphics card to the ast side by dma-buf. > > v1->v2: > - Fix the comment. > v2->v3: > - we remove the gem_prime_import_sg_table callback and use the gem_prime_import > callback, becuase it just map and access the buffer with the CPU. and do not > to pin the buffer. > > Signed-off-by: oushixiong Thomas should probably comment as well, I think at least the memcpy_toio usage can still be made cleaner. But from the DMA-buf side I think that looks good now, feel free to add an Acked-by: Christian König Regards, Christian. > --- > drivers/gpu/drm/ast/ast_drv.c | 27 +++++++ > drivers/gpu/drm/ast/ast_mode.c | 125 ++++++++++++++++++++++++++++++++- > 2 files changed, 151 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/ast/ast_drv.c b/drivers/gpu/drm/ast/ast_drv.c > index 7465c4f0156a..107383a56ca7 100644 > --- a/drivers/gpu/drm/ast/ast_drv.c > +++ b/drivers/gpu/drm/ast/ast_drv.c > @@ -28,6 +28,7 @@ > > #include > #include > +#include > > #include > #include > @@ -50,6 +51,29 @@ module_param_named(modeset, ast_modeset, int, 0400); > > DEFINE_DRM_GEM_FOPS(ast_fops); > > +struct drm_gem_object *ast_gem_prime_import(struct drm_device *dev, > + struct dma_buf *dma_buf) > +{ > + struct drm_gem_vram_object *gbo; > + > + gbo = drm_gem_vram_of_gem(dma_buf->priv); > + if (gbo->bo.base.dev == dev) { > + /* > + * Importing dmabuf exported from out own gem increases > + * refcount on gem itself instead of f_count of dmabuf. > + */ > + drm_gem_object_get(&gbo->bo.base); > + return &gbo->bo.base; > + } > + > + gbo = drm_gem_vram_create(dev, dma_buf->size, 0); > + if (IS_ERR(gbo)) > + return NULL; > + > + get_dma_buf(dma_buf); > + return &gbo->bo.base; > +} > + > static const struct drm_driver ast_driver = { > .driver_features = DRIVER_ATOMIC | > DRIVER_GEM | > @@ -63,6 +87,9 @@ static const struct drm_driver ast_driver = { > .minor = DRIVER_MINOR, > .patchlevel = DRIVER_PATCHLEVEL, > > + .prime_fd_to_handle = drm_gem_prime_fd_to_handle, > + .gem_prime_import = ast_gem_prime_import, > + > DRM_GEM_VRAM_DRIVER > }; > > diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c > index 45b56b39ad47..65a4342c5622 100644 > --- a/drivers/gpu/drm/ast/ast_mode.c > +++ b/drivers/gpu/drm/ast/ast_mode.c > @@ -48,6 +48,8 @@ > #include "ast_drv.h" > #include "ast_tables.h" > > +MODULE_IMPORT_NS(DMA_BUF); > + > static inline void ast_load_palette_index(struct ast_private *ast, > u8 index, u8 red, u8 green, > u8 blue) > @@ -1535,8 +1537,129 @@ static const struct drm_mode_config_helper_funcs ast_mode_config_helper_funcs = > .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm, > }; > > +static int ast_handle_damage(struct drm_framebuffer *fb, int x, int y, > + int width, int height) > +{ > + struct drm_gem_vram_object *dst_bo = NULL; > + void *dst = NULL; > + int ret = 0, i; > + unsigned long offset = 0; > + bool unmap = false; > + unsigned int bytesPerPixel; > + struct iosys_map map; > + struct iosys_map dmabuf_map; > + > + bytesPerPixel = fb->format->cpp[0]; > + > + if (!fb->obj[0]->dma_buf) > + return -EINVAL; > + > + if (!fb->obj[0]->dma_buf->vmap_ptr.vaddr) { > + ret = dma_buf_vmap(fb->obj[0]->dma_buf, &dmabuf_map); > + if (ret) > + return ret; > + } else > + dmabuf_map.vaddr = fb->obj[0]->dma_buf->vmap_ptr.vaddr; > + > + dst_bo = drm_gem_vram_of_gem(fb->obj[0]); > + > + ret = drm_gem_vram_pin(dst_bo, 0); > + if (ret) { > + DRM_ERROR("ast_bo_pin failed\n"); > + return ret; > + } > + > + if (!dst_bo->map.vaddr) { > + ret = drm_gem_vram_vmap(dst_bo, &map); > + if (ret) { > + drm_gem_vram_unpin(dst_bo); > + DRM_ERROR("failed to vmap fbcon\n"); > + return ret; > + } > + unmap = true; > + } > + dst = dst_bo->map.vaddr; > + > + for (i = y; i < y + height; i++) { > + offset = i * fb->pitches[0] + (x * bytesPerPixel); > + memcpy_toio(dst + offset, dmabuf_map.vaddr + offset, > + width * bytesPerPixel); > + } > + > + if (unmap) > + drm_gem_vram_vunmap(dst_bo, &map); > + > + drm_gem_vram_unpin(dst_bo); > + > + return 0; > +} > + > + > +static int ast_user_framebuffer_dirty(struct drm_framebuffer *fb, > + struct drm_file *file, > + unsigned int flags, > + unsigned int color, > + struct drm_clip_rect *clips, > + unsigned int num_clips) > +{ > + int i, ret = 0; > + > + drm_modeset_lock_all(fb->dev); > + if (fb->obj[0]->dma_buf) { > + ret = dma_buf_begin_cpu_access(fb->obj[0]->dma_buf, > + DMA_FROM_DEVICE); > + if (ret) > + goto unlock; > + } > + > + for (i = 0; i < num_clips; i++) { > + ret = ast_handle_damage(fb, clips[i].x1, clips[i].y1, > + clips[i].x2 - clips[i].x1, clips[i].y2 - clips[i].y1); > + if (ret) > + break; > + } > + > + if (fb->obj[0]->dma_buf) { > + dma_buf_end_cpu_access(fb->obj[0]->dma_buf, > + DMA_FROM_DEVICE); > + } > + > +unlock: > + drm_modeset_unlock_all(fb->dev); > + > + return ret; > +} > + > +static void ast_user_framebuffer_destroy(struct drm_framebuffer *fb) > +{ > + struct iosys_map dmabuf_map; > + > + if (fb->obj[0]->dma_buf) { > + dmabuf_map.is_iomem = fb->obj[0]->dma_buf->vmap_ptr.is_iomem; > + dmabuf_map.vaddr = fb->obj[0]->dma_buf->vmap_ptr.vaddr; > + if (dmabuf_map.vaddr) > + dma_buf_vunmap(fb->obj[0]->dma_buf, &dmabuf_map); > + } > + > + drm_gem_fb_destroy(fb); > +} > + > +static const struct drm_framebuffer_funcs ast_gem_fb_funcs_dirtyfb = { > + .destroy = ast_user_framebuffer_destroy, > + .create_handle = drm_gem_fb_create_handle, > + .dirty = ast_user_framebuffer_dirty, > +}; > + > +static struct drm_framebuffer * > +ast_gem_fb_create_with_dirty(struct drm_device *dev, struct drm_file *file, > + const struct drm_mode_fb_cmd2 *mode_cmd) > +{ > + return drm_gem_fb_create_with_funcs(dev, file, mode_cmd, > + &ast_gem_fb_funcs_dirtyfb); > +} > + > static const struct drm_mode_config_funcs ast_mode_config_funcs = { > - .fb_create = drm_gem_fb_create, > + .fb_create = ast_gem_fb_create_with_dirty, > .mode_valid = drm_vram_helper_mode_valid, > .atomic_check = drm_atomic_helper_check, > .atomic_commit = drm_atomic_helper_commit,