From patchwork Thu Mar 22 10:23:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Hellstrom X-Patchwork-Id: 10301189 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 BC70860385 for ; Thu, 22 Mar 2018 10:24:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEA6C29AA1 for ; Thu, 22 Mar 2018 10:24:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A307D29AA4; Thu, 22 Mar 2018 10:24:48 +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=BAD_ENC_HEADER,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 8998529AA3 for ; Thu, 22 Mar 2018 10:24:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1BAB26EBD0; Thu, 22 Mar 2018 10:24:43 +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-co1nam03on0085.outbound.protection.outlook.com [104.47.40.85]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6F3396EBCA for ; Thu, 22 Mar 2018 10:24:41 +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=SuWqBPSSWyC1i8a+93fc+qPCxKUjPI79asgE5KhEQdM=; b=pt9LYur1/Cj+4xDh9QjjHDx4KkTz4UaT1s7tbb+fFoIVk0GwJ0X33c0wDUIXo7CA4GGUYHxf2vZ0KKUFTrGzVJYKc+gwldZSr0yKg6F3dv7Lnu7yy3uH+Wtk8kxBWrmGXYO9JeO/EXk7SEHAxU5TyD4BbFLg3VlU+bhBB2xJhhk= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=thellstrom@vmware.com; Received: from localhost.localdomain (155.4.205.56) by DM2PR05MB767.namprd05.prod.outlook.com (2a01:111:e400:244d::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.609.6; Thu, 22 Mar 2018 10:24:38 +0000 From: Thomas Hellstrom To: dri-devel@lists.freedesktop.org, linux-graphics-maintainer@vmware.com Subject: [PATCH -next 04/11] drm/vmwgfx: Avoid pinning fbdev framebuffers Date: Thu, 22 Mar 2018 11:23:45 +0100 Message-Id: <20180322102352.2881-4-thellstrom@vmware.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180322102352.2881-1-thellstrom@vmware.com> References: <20180322102352.2881-1-thellstrom@vmware.com> MIME-Version: 1.0 X-Originating-IP: [155.4.205.56] X-ClientProxiedBy: HE1PR0502CA0021.eurprd05.prod.outlook.com (2603:10a6:3:e3::31) To DM2PR05MB767.namprd05.prod.outlook.com (2a01:111:e400:244d::22) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8ee1a936-0b40-4f1d-2c3c-08d58fdf1e8b X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:DM2PR05MB767; X-Microsoft-Exchange-Diagnostics: 1; DM2PR05MB767; 3:MWotd8Sn2JKAD4VUPpK4jI20r1nhHzhYoRzKGcWnIoE7vhjkqv/hQnB3WyDDS2mdE5EneLhpXLYTrZ9WMX278hrQCCJxsB1+To9NhqcFwmEiokR9cBKEWfHryTtmMgoNI8lMqxWL0rAPU7Ht9rh8pNXysu155cFUlDPy3Y2FfDULNl9lRQWBBwJwMn+j1kteTD0sSdsUbQNGoXBNBqqVmCExcQEhtRibCbus+5wXYTsujAwCdCFG9+4uwo0n+vql; 25:GULhxV03rdfTbw/BSWT7qLffFuMtTmppHw4b3tlvo4JUb6SK7ZVhHHvK45+GPqg5ndlWwFI4eySZE2NY7EuO5SF7s37RMSXI6V7MzplbOGIXeICUrOdl9S4FKe3fxgrCqme5ubPokVBajNcjbrEVetPAiBOrzduFGayZMcJZjtNh7l4EhceubYrLz3MFhpRF+pngloH9XLOG7OoqMHNxPooxC+jNiekkCddma0mX/G0I0oT2hZWyRH1PHPwnqL9xVV33Mi53axTA9ghioXtUcT2VwN84XcZAncBp2mSCAi900cmvR7P/aK7cRJQbKumPXKv3hO5chEJ2xrsNd/Ehz+mz4GisjVHctlKlmihsEeo=; 31:0Hi/+cuxGrj/N/d9Gvxs/rdw5736LQV4sxlvCGK1UUFk+SlEYyNVMXe4OzLGPyH/XTEYYnY1Uj+4LDfhfseEu8c68T01cNM1gIuUcCHS3wTR7yy4fz8PcNoPmzB9BfYzhoMXVvH/XtUz6NdrjhLZDUJodRzDP+dXfFzi+iZTHRN3Gjr0zT5mcoJKv3x8G/n6s/roIEVywZD0zQtfg3p8Xnwyww4QebeDC4bkHAZoRIQ= X-MS-TrafficTypeDiagnostic: DM2PR05MB767: X-LD-Processed: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; DM2PR05MB767; 20:RvjXqMkyNIZmDjjzsPk4SkdfWwVMyWh01e7VlWXBNVamGtoH9EptAxeoxjBzrcPwbttugp72dVjNrKv8JZ2enYl/SJSOYxIEP17ODc3kwm1tpt9GgUptyloq/kkX9fGijq/OsBD0cr3aLRYubXKED9AL0pHsqpu6UaskyOQOyFasFkmjHpUpkW5TEpvILIlhj6f/8V6Paxu/uG08JdiXng+ZnB1qjtpRBAcVIbRRvCOKC7gKbNDootf6nOhpiNfCC488w73fEZcHPzp34ls5Ho9htdBgRX4yrG8LKpQQv6HCFcUoI7DSivelDVrLGpC72+Xz/NO7QYdEn3EHke0cxJKFz6o0tsV7GxjC8wLZPSlgcj/Fg8EOE1R0Z3mEnfB/lShs8L8EOE3BbWygri3VibS+6BUEvVtTUkOab3PeWOUkjEPZ9vFwYELfuuj/8y9qH8amSmOUNbpI7JtYeRUqYkx1mLXtxR36AT4plm+FYV/ii673PPdkP9sRytjlpAmd; 4:lq92pRxdgJSgazGlbBBuqBH5mSO3G7DLP1nPAdVAcSVA25OBbXk9LyM6s+XaDjjjXQWfkg2BIi2FKH0yU99qHLS6VN204fnTd9yZBQNMyJf0fjSMMtbsR4senpZFAcM9rpX7kcXigxCXVaIXm3X6yI6LeSZCyLshfFpa2EyZV4wCtfrFv9xpIXpHs/OmKP8muQ/MRouMCFt4FrTGxZ9r/1ny7lENqHW53wm9LPvgJrlOunRF45Jv1VsVf5pQ5gQjbG6Rx6tdVJHTIiJNhRbcZcJp2II2kQbl6H2SRDJws4x0bM2jxK78/XfYLkN1Qkqn X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(61668805478150); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3231221)(944501327)(52105095)(10201501046)(3002001)(93006095)(93001095)(6041310)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(6072148)(201708071742011); SRVR:DM2PR05MB767; BCL:0; PCL:0; RULEID:; SRVR:DM2PR05MB767; X-Forefront-PRVS: 0619D53754 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(346002)(39380400002)(376002)(396003)(39860400002)(366004)(199004)(189003)(76176011)(59450400001)(8676002)(81156014)(316002)(68736007)(5660300001)(305945005)(8936002)(50226002)(16586007)(36756003)(81166006)(86362001)(50466002)(6486002)(48376002)(186003)(16526019)(6512007)(53936002)(6666003)(6636002)(6506007)(386003)(2950100002)(25786009)(6116002)(52116002)(106356001)(105586002)(51416003)(47776003)(3846002)(26005)(1076002)(2906002)(97736004)(7736002)(66066001)(478600001)(446003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR05MB767; H:localhost.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: vmware.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR05MB767; 23:x5vlWU3MXfKhlnVA4BFnct3Rsux9F4DGVDThbnBtE+?= =?us-ascii?Q?97sGnRW18GBwYCdrKLAbZWllLlKCjqoFPUMLPW6th2xUyIAEjjjOFoHThBS8?= =?us-ascii?Q?dCwwchjpTQTlOBfQyKUnxj+MnidpNbgTyP4LiHyiBiYp/IUmwjYpLDCnZEK5?= =?us-ascii?Q?k0B2mVrA3uXuRAYcH9pVT0z60GySj5PurLCU6IWNKrvRNIaI02702UyIG9dg?= =?us-ascii?Q?hf7j0gyucwU91PgRHGB0w5CBYsOIB4ozTVWcdcUpRjUFOlpd0ICXr7gLdjJ0?= =?us-ascii?Q?pqzLE0fkV10pKpW5aujEsWss17FNyYmykfp/66Pzdt1I/ENY4BG/lBqrqT5c?= =?us-ascii?Q?RXu5TaXrhlTpr0Ynug9yHOkUlatsRas39HqwbrssBjHrwJTm80evuvJf63jx?= =?us-ascii?Q?eYQl1S6GhyP2qJTf01+9PASQkoAH9JxemfWukyjEZrGWHNWcD7gE0XUYzqJP?= =?us-ascii?Q?fUD+WLIDkOO+oVI6/aCXwHG7tD0P1AiZFXRSwuUCqEjs6mGFy8Mbg7ETkW+R?= =?us-ascii?Q?G2AAImce6XkLczsaZNW1Moh1vcmFbBM5zo/B+gzg6wHAWTFRqMrestdIYvMV?= =?us-ascii?Q?CIgc44SljyfeStVWd0jYTU4c4dPdn1thOXT0f1Gdhd5HP0LTlTNM2iBw7J8x?= =?us-ascii?Q?WFLrK3/hRp8lG7YbT4HmaQoEUBKBOcuFhb7OrxnLMIywJjzaLkOdPvwWBpxA?= =?us-ascii?Q?7U5VFn2ms/3qxkuol42MXLalRGCFCiBHVy5r1CV8jYdcXiwO3ryJmJo/PFJG?= =?us-ascii?Q?2DhAaRau4/XVSOdre2L4UGiPEzr4oxJ08ReupDhRuGkYNjQZ54I6lKfm9FGB?= =?us-ascii?Q?qzUPmBTVqvo9IiLJGU/7uzvksV/uMSJFx12FWvhXKdQIDJ9djD4TtdNjyhrp?= =?us-ascii?Q?Sfr6scxW8mPwM3vj2tJ4X/gll0FvRTmGcFuyR1KDs9gKxbTirKTtbIwVy5Xe?= =?us-ascii?Q?VQI0tQ4KL5w6bmf2lv/BKUePVjPco8ylZCo5PDB03PWK0vBEZQkiHTjL946v?= =?us-ascii?Q?KK2Lnnaglmwfy0RPYeAwv22cj2iOMCioyC+C4lZNNGi5H7njPf5jpCKalief?= =?us-ascii?Q?5QkfafV/HzeyvM1JvAaAe9lLSHkr+Su4WX0tBEH1/BSWFUM4bzAHJxfGQiMk?= =?us-ascii?Q?H2BXfMKqt4HKiOkCpBeCw1FUXpyO5fZ58hGfVXIDP1EevhvuvR2g=3D=3D?= X-Microsoft-Antispam-Message-Info: cOwYQ8CTrtn5sc17MuLL063NVnTzWN3gqysbKCBj+AudZhtEZpqiyvdu5gqB25ymi0BNLNZfX+cNac7VBvzl4Wi0JUre4i7qlsLya9o4zLg6YHA3LNlbHgWrvYqcfla9EAMc4x/JnzdGo8p2FaujPGmQ93PnyoMbht3lhrulPmqKTWqDT8ngbwfJgvaQtqWn X-Microsoft-Exchange-Diagnostics: 1; DM2PR05MB767; 6:ZXe8jwmEBXB3UkNCAl50htVmxVLmSwEkefflDuAQRmlll7Wqm+qj6/hHHBVs6yX6+7Zq8fQsmWRbGVuFihMrnw0Kx0dO26wgx086ZQR+6Q0Pi+IXzGKep1GivNLyRguuc4n1B9n98zfPuSJbkKO5GKAA8b45Z6s9mgFruXjCnBxfHvrWgziSL3z5hOBDD30HNl91w8IWdehVyOydQ3PJ1yB7fdUHaSbNQZkjdNvPCw8c0o9MlWjmiK9uQDgGWL5h9Nj8lm+XTH8ruO6XErQ1b7Ev5rdrJZDwAtv4UTxZtJHiKUW4CcM1yoFJBXfr0Sm9bqChEFUyXC2J/djH3Av7PHimPYUoEmvSIlLPqeYqHAhoXg3YbRq0u1/2ZuS7+is+GsYoAPJTl72XIuzbBzjqud+Gdf4eRVZ8z6X8kVcbinlLSE1TYp/4EBcsfHi19+woNct5ufC04gqb0/9GXu20/w==; 5:Qo8n+EzFs40VopzNOjfvMz+DkwPdeFfyaxrE+x2I8vFYVUrV2VhwV4FwXz2aymp2h5cBMGywFMV2AOztG20Tny1gZ+j4DksGcm3aB78VwYh0jiWS45IdKQz3b4Vz2YCMEcutx2dMJqqorXgcBX3jyvxs8afekjBognrl6rA/YCE=; 24:820xOiSeqjkOeEGZrnuTOZpn8LGSr8gASGWD8E55B0fZwxMVt+OyfYTool4j2ZkoFsIcvThaASRnFwd45XM6M6+o5i7cUhVXOyD8nXNixf8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR05MB767; 7:mfjk5ddFS+wlv+SG4EzlJm9AnRajR5Ybk3DrDRkNoMt7BHVxnpumhQTpGBxas6Un+/h1/ZIiBl48VqMezgYfU1pweS++R+oG4+G+yB5lTuqydYhY4kpUkcxOn+H5V1MlkUVr/+qvUDyGjtg7Fi7Pvxx14B2bvQKEzpmvjWNR/iBhU8wsqeMru4PLIEDyKcWlycKuxOZ4tEUG9/wMeGUxPm1Iihc/L/2JhrQx5V7nzyEWELRrx7s0RrnL2G7ULULr; 20:9pQbk+u7k6KTbXO6b3jrL8b42ftUHP+KDvJa/JSkRmN9nRijm2+ZZCBOdIisTiDPljzRDZnwuzgFkfXy/9iixElOetEvTVySvD1LrcVxBz73Ed4xHsEm+GPwp3JqGRuzHMSsy/tiGEAoZKit+JqXl9AbbVnfFSS+5VYDguCFjmg= X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Mar 2018 10:24:38.8974 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8ee1a936-0b40-4f1d-2c3c-08d58fdf1e8b X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR05MB767 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 fbdev framebuffers were previously pinned to be able to keep them mapped across updates. This commit introduces a mechanism that instead revalidates the map on each update, keeping the map cached across updates. The cached map is torn down if the underlying pages change. Typically on buffer object moves and swapouts. This should be nicer to the system when we have resource contention. Testing done: Basic fbdev functionality under Fedora 27. Signed-off-by: Thomas Hellstrom Signed-off-by: Sinclair Yeh Reviewed-by: Brian Paul Reviewed-by: Deepak Rawat --- drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c | 1 + drivers/gpu/drm/vmwgfx/vmwgfx_dmabuf.c | 51 ++++++++++++++++++++++++ drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 5 +++ drivers/gpu/drm/vmwgfx/vmwgfx_fb.c | 67 +++++++++----------------------- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 23 +++++++++++ 5 files changed, 98 insertions(+), 49 deletions(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c index ddf71bef5359..21111fd091f9 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c @@ -864,6 +864,7 @@ static void vmw_move_notify(struct ttm_buffer_object *bo, */ static void vmw_swap_notify(struct ttm_buffer_object *bo) { + vmw_resource_swap_notify(bo); (void) ttm_bo_wait(bo, false, false); } diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_dmabuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_dmabuf.c index d45d2caffa5a..d59d9dd16ebc 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_dmabuf.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_dmabuf.c @@ -323,3 +323,54 @@ void vmw_bo_pin_reserved(struct vmw_dma_buffer *vbo, bool pin) BUG_ON(ret != 0 || bo->mem.mem_type != old_mem_type); } + + +/* + * vmw_dma_buffer_unmap - Tear down a cached buffer object map. + * + * @vbo: The buffer object whose map we are tearing down. + * + * This function tears down a cached map set up using + * vmw_dma_buffer_map_and_cache(). + */ +void vmw_dma_buffer_unmap(struct vmw_dma_buffer *vbo) +{ + if (vbo->map.bo == NULL) + return; + + ttm_bo_kunmap(&vbo->map); +} + + +/* + * vmw_dma_buffer_map_and_cache - Map a buffer object and cache the map + * + * @vbo: The buffer object to map + * Return: A kernel virtual address or NULL if mapping failed. + * + * This function maps a buffer object into the kernel address space, or + * returns the virtual kernel address of an already existing map. The virtual + * address remains valid as long as the buffer object is pinned or reserved. + * The cached map is torn down on either + * 1) Buffer object move + * 2) Buffer object swapout + * 3) Buffer object destruction + * + */ +void *vmw_dma_buffer_map_and_cache(struct vmw_dma_buffer *vbo) +{ + struct ttm_buffer_object *bo = &vbo->base; + bool not_used; + void *virtual; + int ret; + + virtual = ttm_kmap_obj_virtual(&vbo->map, ¬_used); + if (virtual) + return virtual; + + ret = ttm_bo_kmap(bo, 0, bo->num_pages, &vbo->map); + if (ret) + DRM_ERROR("Buffer object map failed: %d.\n", ret); + + return ttm_kmap_obj_virtual(&vbo->map, ¬_used); +} diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h index 9368bcb492aa..3a5476df7d84 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h @@ -92,6 +92,8 @@ struct vmw_dma_buffer { s32 pin_count; /* Not ref-counted. Protected by binding_mutex */ struct vmw_resource *dx_query_ctx; + /* Protected by reservation */ + struct ttm_bo_kmap_obj map; }; /** @@ -673,6 +675,7 @@ extern void vmw_resource_move_notify(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem); extern void vmw_query_move_notify(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem); +extern void vmw_resource_swap_notify(struct ttm_buffer_object *bo); extern int vmw_query_readback_all(struct vmw_dma_buffer *dx_query_mob); extern void vmw_fence_single_bo(struct ttm_buffer_object *bo, struct vmw_fence_obj *fence); @@ -701,6 +704,8 @@ extern int vmw_dmabuf_unpin(struct vmw_private *vmw_priv, extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf, SVGAGuestPtr *ptr); extern void vmw_bo_pin_reserved(struct vmw_dma_buffer *bo, bool pin); +extern void *vmw_dma_buffer_map_and_cache(struct vmw_dma_buffer *vbo); +extern void vmw_dma_buffer_unmap(struct vmw_dma_buffer *vbo); /** * Misc Ioctl functionality - vmwgfx_ioctl.c diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c index d23a18aae476..fb4e59ee26c7 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c @@ -43,8 +43,6 @@ struct vmw_fb_par { struct mutex bo_mutex; struct vmw_dma_buffer *vmw_bo; - struct ttm_bo_kmap_obj map; - void *bo_ptr; unsigned bo_size; struct drm_framebuffer *set_fb; struct drm_display_mode *set_mode; @@ -174,11 +172,13 @@ static void vmw_fb_dirty_flush(struct work_struct *work) struct vmw_private *vmw_priv = par->vmw_priv; struct fb_info *info = vmw_priv->fb_info; unsigned long irq_flags; - s32 dst_x1, dst_x2, dst_y1, dst_y2, w, h; + s32 dst_x1, dst_x2, dst_y1, dst_y2, w = 0, h = 0; u32 cpp, max_x, max_y; struct drm_clip_rect clip; struct drm_framebuffer *cur_fb; u8 *src_ptr, *dst_ptr; + struct vmw_dma_buffer *vbo = par->vmw_bo; + void *virtual; if (vmw_priv->suspended) return; @@ -188,10 +188,16 @@ static void vmw_fb_dirty_flush(struct work_struct *work) if (!cur_fb) goto out_unlock; + (void) ttm_read_lock(&vmw_priv->reservation_sem, false); + (void) ttm_bo_reserve(&vbo->base, false, false, NULL); + virtual = vmw_dma_buffer_map_and_cache(vbo); + if (!virtual) + goto out_unreserve; + spin_lock_irqsave(&par->dirty.lock, irq_flags); if (!par->dirty.active) { spin_unlock_irqrestore(&par->dirty.lock, irq_flags); - goto out_unlock; + goto out_unreserve; } /* @@ -221,7 +227,7 @@ static void vmw_fb_dirty_flush(struct work_struct *work) spin_unlock_irqrestore(&par->dirty.lock, irq_flags); if (w && h) { - dst_ptr = (u8 *)par->bo_ptr + + dst_ptr = (u8 *)virtual + (dst_y1 * par->set_fb->pitches[0] + dst_x1 * cpp); src_ptr = (u8 *)par->vmalloc + ((dst_y1 + par->fb_y) * info->fix.line_length + @@ -237,7 +243,12 @@ static void vmw_fb_dirty_flush(struct work_struct *work) clip.x2 = dst_x2; clip.y1 = dst_y1; clip.y2 = dst_y2; + } +out_unreserve: + ttm_bo_unreserve(&vbo->base); + ttm_read_unlock(&vmw_priv->reservation_sem); + if (w && h) { WARN_ON_ONCE(par->set_fb->funcs->dirty(cur_fb, NULL, 0, 0, &clip, 1)); vmw_fifo_flush(vmw_priv, false); @@ -504,18 +515,8 @@ static int vmw_fb_kms_detach(struct vmw_fb_par *par, par->set_fb = NULL; } - if (par->vmw_bo && detach_bo) { - struct vmw_private *vmw_priv = par->vmw_priv; - - if (par->bo_ptr) { - ttm_bo_kunmap(&par->map); - par->bo_ptr = NULL; - } - if (unref_bo) - vmw_dmabuf_unreference(&par->vmw_bo); - else if (vmw_priv->active_display_unit != vmw_du_legacy) - vmw_dmabuf_unpin(par->vmw_priv, par->vmw_bo, false); - } + if (par->vmw_bo && detach_bo && unref_bo) + vmw_dmabuf_unreference(&par->vmw_bo); return 0; } @@ -636,38 +637,6 @@ static int vmw_fb_set_par(struct fb_info *info) if (ret) goto out_unlock; - if (!par->bo_ptr) { - struct vmw_framebuffer *vfb = vmw_framebuffer_to_vfb(set.fb); - - /* - * Pin before mapping. Since we don't know in what placement - * to pin, call into KMS to do it for us. LDU doesn't require - * additional pinning because set_config() would've pinned - * it already - */ - if (vmw_priv->active_display_unit != vmw_du_legacy) { - ret = vfb->pin(vfb); - if (ret) { - DRM_ERROR("Could not pin the fbdev " - "framebuffer.\n"); - goto out_unlock; - } - } - - ret = ttm_bo_kmap(&par->vmw_bo->base, 0, - par->vmw_bo->base.num_pages, &par->map); - if (ret) { - if (vmw_priv->active_display_unit != vmw_du_legacy) - vfb->unpin(vfb); - - DRM_ERROR("Could not map the fbdev framebuffer.\n"); - goto out_unlock; - } - - par->bo_ptr = ttm_kmap_obj_virtual(&par->map, &par->bo_iowrite); - } - - vmw_fb_dirty_mark(par, par->fb_x, par->fb_y, par->set_fb->width, par->set_fb->height); diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c index 9e101450cc4d..6b3a942b18df 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c @@ -354,6 +354,7 @@ void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo) { struct vmw_dma_buffer *vmw_bo = vmw_dma_buffer(bo); + vmw_dma_buffer_unmap(vmw_bo); kfree(vmw_bo); } @@ -361,6 +362,7 @@ static void vmw_user_dmabuf_destroy(struct ttm_buffer_object *bo) { struct vmw_user_dma_buffer *vmw_user_bo = vmw_user_dma_buffer(bo); + vmw_dma_buffer_unmap(&vmw_user_bo->dma); ttm_prime_object_kfree(vmw_user_bo, prime); } @@ -1239,6 +1241,12 @@ void vmw_resource_move_notify(struct ttm_buffer_object *bo, dma_buf = container_of(bo, struct vmw_dma_buffer, base); + /* + * Kill any cached kernel maps before move. An optimization could + * be to do this iff source or destination memory type is VRAM. + */ + vmw_dma_buffer_unmap(dma_buf); + if (mem->mem_type != VMW_PL_MOB) { struct vmw_resource *res, *n; struct ttm_validate_buffer val_buf; @@ -1262,6 +1270,21 @@ void vmw_resource_move_notify(struct ttm_buffer_object *bo, } +/** + * vmw_resource_swap_notify - swapout notify callback. + * + * @bo: The buffer object to be swapped out. + */ +void vmw_resource_swap_notify(struct ttm_buffer_object *bo) +{ + if (bo->destroy != vmw_dmabuf_bo_free && + bo->destroy != vmw_user_dmabuf_destroy) + return; + + /* Kill any cached kernel maps before swapout */ + vmw_dma_buffer_unmap(vmw_dma_buffer(bo)); +} + /** * vmw_query_readback_all - Read back cached query states