From patchwork Tue Aug 21 18:30:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru-Cosmin Gheorghe X-Patchwork-Id: 10572293 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 98EFA17E0 for ; Tue, 21 Aug 2018 18:31:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 849702AB8A for ; Tue, 21 Aug 2018 18:31:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 827082AC33; Tue, 21 Aug 2018 18:31:19 +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 B631E2AB8A for ; Tue, 21 Aug 2018 18:31:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A77936E360; Tue, 21 Aug 2018 18:31:17 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70041.outbound.protection.outlook.com [40.107.7.41]) by gabe.freedesktop.org (Postfix) with ESMTPS id C15E26E360 for ; Tue, 21 Aug 2018 18:31:15 +0000 (UTC) Received: from e114479-lin.cambridge.arm.com (217.140.106.49) by AM5PR0802MB2548.eurprd08.prod.outlook.com (2603:10a6:203:a1::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1059.23; Tue, 21 Aug 2018 18:31:08 +0000 From: Alexandru Gheorghe To: seanpaul@chromium.org, airlied@linux.ie, dri-devel@lists.freedesktop.org, liviu.dudau@arm.com, brian.starkey@arm.com, malidp@foss.arm.com, gustavo@padovan.org, maarten.lankhorst@linux.intel.com, ayan.halder@arm.com, daniel.vetter@ffwll.ch Subject: [PATCH v2 4/5] drm: Add support for handling linear tile formats Date: Tue, 21 Aug 2018 19:30:03 +0100 Message-Id: <20180821183004.6775-5-alexandru-cosmin.gheorghe@arm.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180821183004.6775-1-alexandru-cosmin.gheorghe@arm.com> References: <20180821183004.6775-1-alexandru-cosmin.gheorghe@arm.com> MIME-Version: 1.0 X-Originating-IP: [217.140.106.49] X-ClientProxiedBy: MWHPR2001CA0020.namprd20.prod.outlook.com (2603:10b6:301:15::30) To AM5PR0802MB2548.eurprd08.prod.outlook.com (2603:10a6:203:a1::21) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 372df687-4a5b-4c0a-83e1-08d607944603 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:AM5PR0802MB2548; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2548; 3:spXIycoJeOyeKahzFGaSDQ74JeJlpiFqZFIoQKEW7xB1zFbs4hDCSoW65UdjMd5h1qDia6hxjntCK6zdTk3Kgr+zJkYXZC12prU30KQqb+sViwWpnECQzskjA5KUK9lxuPoVTB/Gw84xBx9mVCabarD6nKkWHycxEEUMIWTxI7c84VobD1aDgQ7NFzrerASSvJLTWweemEU9Ee/kLBTigG+P8XwBcMTjSnqa3LUQdB3xCm/Gw0w43YGJY3glDmDL; 25:Q8BNGciJkkGEJXubEPNEyGjBH9iSQMwcTG0UVLQh/F1Fe7vC87eLJpk1WCraEp+G6Oh7APL9FVxFYUxqTVkfFvqff9562mjfP5ZhR8p7VmiDJ1NG00dEnvPoYa/rDWQazCGSeDj+n9Oxud7vPinpBEuF2POvxH17POdwD9TRCyQMQRXjfNlElTQrEjnhJhyb3i+E/j76qAJcdH2BReqcFX+iULz0XmBMUkiwbneMKQv3wi0vTJN0C98P+acK7ZjjFYoB22Kyjf/vDTpiGMgAB8LPyXij8Mzby4EKL3q0yZ/bw+nZToaHa7oiqGPOKl9tM6nZL9zWwBBVcYCkBaqqcg==; 31:aZzhm48VwPZ8upwYgSBwlCxIQDx3F3b7aTZ+z6gBQsix6k3x+lw4l2XhaemdPZqZJTMp2dYLY6YZPZqchdnkU9CdXI9y4AXPFhgrMS7NK4Y51xmQdlhg8pB4PQuer7SnIjdRjcQNckXrCts3RUmMGiQg/cnonq6d63rfgxUrLZQqQxigkKWbt41fC6BCUIXRplUVhw6xj1vhxylF4aOlA/FZKNeXacPx9Srt9DNPdEs= X-MS-TrafficTypeDiagnostic: AM5PR0802MB2548: NoDisclaimer: True X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2548; 20:MYPhOlnEacf8gNvZV2GzdWtNzP2Y3+UQot4fp/afi1HXRN16tUWBB+SjP7jJ8OvS+/MVuN+EwoIoWs591yKjl2tzs9yfo4ZI+1lq7M2Fv6rvQ1spcynUGWLvluQ9dEfY0drbvjg3o30gWztLg2EOW87PLELYj+A4QzJtYJx81+csel0np50K/Pl1pkFfysiIp6FRGEaF/pnV/5Vs9QpHGm056YzUn1nklkqTYmBCFj9l3hfXF8eXbswdPTT53BfxOPO+CcYBls0Iz7bX5r14V9aHq5NL2plphnfDAWGWwWpBe59IxRSbx39H71vLZ/2vS4VzfBEdIOL20+3xzZtE4Q==; 4:GjbIrCmZcx00qaY8XgykkxdCvnJSthptQ2ALbxfHFn27uSRDWHKFp2xE7EYnPXu8lZH+tlJRAFGKsc8w+dFvs0q+fxlffm2LNh7d288n7LWQmWQY1oJavy5U/sQtG08iuEagpc3qgof0alvV/DVIUTGk1hkVZC7yKD50F+I7CvbOykEix7TMWSgK3pPKoDEdxZwB81kfEadSbg/27MVk8VYEejIzyDmioleNO4he+wb/2nFdIs8wu4Ok7Xr7whYaHGFyyJ7AgMa5abqfTt37npCC6PwtKUWkVKGXX5A4VB4a/ii4zpLsSef8FsPJM5WY X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(823301075)(3002001)(10201501046)(3231311)(944501410)(52105095)(93006095)(93001095)(6055026)(149027)(150027)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123564045)(201708071742011)(7699016); SRVR:AM5PR0802MB2548; BCL:0; PCL:0; RULEID:; SRVR:AM5PR0802MB2548; X-Forefront-PRVS: 0771670921 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(39860400002)(136003)(396003)(376002)(366004)(189003)(199004)(52314003)(8676002)(68736007)(72206003)(97736004)(50226002)(36756003)(106356001)(53936002)(6666003)(105586002)(47776003)(16586007)(316002)(6116002)(575784001)(66066001)(2906002)(86362001)(8936002)(3846002)(478600001)(4326008)(1076002)(25786009)(6486002)(7736002)(81156014)(81166006)(476003)(76176011)(50466002)(26005)(186003)(11346002)(2616005)(48376002)(51416003)(486006)(7696005)(956004)(52116002)(446003)(386003)(16526019)(5660300001)(14444005)(305945005)(921003)(1121003); DIR:OUT; SFP:1101; SCL:1; SRVR:AM5PR0802MB2548; H:e114479-lin.cambridge.arm.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM5PR0802MB2548; 23:BpIfE5gI7prTbObMT7C7SJegwiDJqCsFDDo+iAA?= vKqyxmj2OXDMk/xQsQl6ijw5UQHiIA7rdXzrpYO70cBOiRE0zf0uFTJMYCeI7NxhEvT+i93s2IjAldR4Q2EJEWrJ0671jHB+mMaJe4HsOi9NDLlcu1RijPzdazB1jkx4h9UxXX81SgQB9lEhBe0BdUqUKPeDbMt7xFODPYCOQu1gN/kTQMrcwvBCTXDepsCTDS3v1RHNps/IUS6ldNgk1mm7csyN+M/c1yn88kzIqniT2+eRdH3+Gr9MpQi2fg6+OxXY5Po1ksCDjG4YM3GYIhzCZVNCDpOmpA/3DCwQ/sDknV5UJmXqULgKw7wAbtzfYiahquXyze5PoqYYcNJvzn++DZ78meZAwAIyhlWjtVBEX0fzK4ACuC2N6vQUC/zV1aEhu8P3J6A/esRH6Xw27dpmJe6ZRJ9uiv7x0rT1RUvXx5shD8tiLRJ0VrURj7URRxBe26Rea5RzBSqVp4IstZtBi+mro95Tg9lHRQqFYYoRhrIF2pFCL7cOiG4WYQjGR2dSf6ke/iEXgD6yGRWRHwgU+RyuJCnwSisXRnCsftVUk/clQktTqZ/wljY80VeLjAiSc5YYdkZHBBXdbM/rVgt6jrm2dMMfTl7oOxL7edU38q0lj0Tyz6w1ht1vMkhpwMxHLBSjwYEWmwVnyXYld7Aj0tFEH8oqQ0o5n90HcaLSMGvOB4v9u61vOfrN7fah/FOFtxCvXKjsoDgA4R8qkyoQjS6o56g9XavBxNyWQkDlAGvTjD6qSL1Pe3sHj+qrsTrv5Ir2HNnIWMVj8bDh/8iOx/9MUYRZj5NKDul5Kg8WLuk2QvEEGKEcxWrCnUvwR5PSpPnEpVoyjSKoxXzMAvXZJ0t2PSyYS146c6CjRQjwidSo4riQp66AB4PTTNa5+6rD7psqanbN55lIbASQUmJ6mUNZ0Z661cCtNAF977ZrY2yTShpmfLryRLbpn63msC6IIQP2H8G5eC93SoupvJPX54xZFYBAWppEanferplNdyJot9edRuSis4iXhKPyGeys14klacqDax/IiZHWNnqtftuVhnO3j97b1VcgZQpOu4c9TzTVQp5LLU4B8QoOqlc16Vj7ZtsJp4DXN3N8qNGHWKz4zV9GqPfIo91E6HC7x99oF4WUZQjmL8pLBvhI6CAkY4xYlww9vDPN0H4zK+wV0pMuKqVIRNKZnXCPzFnNtHJ+9mMFSkmeItx/T5nOMfQO8RfVJHXnpF1FbhNwWfBd0 X-Microsoft-Antispam-Message-Info: twZPIyNlD8K2n4lZXwfIGavTIAzy6wFsnpeb8feQFHmeE5O04rdf0wzsOlYuWH717y1FwsVzPO0t4wAIoe/wKnezLg5menmJnpR1KqvvP24fHZORDgS0ztTLhk7Xo/9yHkJOwkswVlpB4hloznaGZc9Cn9oTa2MdkVAgUGOI6UzE9srkzjvulPMXLB5VmU6L3UyApp2bmFJ0fRdMQD+T9lVvN4GzrqzFayWzfoHIHpely47IS0TBHDWISK45Rei4alghKe04cSJ3QvQE5COoM5L2GeoLawisrTrZ19V2UTxN2mpQr60m+qYd0aSn3Gf8BSqx+bgwROzze39BsvHhB2M/+VubwyGowto91cy9+0U= X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2548; 6:eEznwvOBxEqV6vGUDVzcIW3q2Hyffawfjnb4J2cg9JV1iU0ngTrXsuafBX4hAMwG+CThEZI+1KH+orXp28f2EYSZ620+lCA+Wjajsde7/YrBIEyGPGcPC7x5UarErq7UFMecc9dwaUF6qs4gDXFVarnuHploBkRu26uv0lPb8tddmqhcLBxWlYQghQxR9qNHN2ODhmGu/fM7mb4s/aLCY0lZyeJJV1Jr4G2qYf8/zCralbzm94GfNQXgOg12aBC4swFFfATITvJY21q+vMkUuTNLbtxC5dUeBt4AwEzE9pB0d2q/6VzPP8rDynNBetWNZL3/mttCFAXPEdbxpeE2Lkcp5C/X1j4M+VWVy8+JITMvGXb6aLP3Jv/3qgZjbB2c+aSKamtcu82wLSXfhgIY0fUhQp4I05+vc7+3x35ZYZqU2Q3/AXLEb2Gat0Fz0Em+lLO83k36VNHIeJZKwFRrKA==; 5:oj21ab3OQcdd3O50ajQrecMGzFv8CLkzRrIfCR9+5lQ26TgTS2UKPrhzjs+pHnGQCQMdgkf+cQmozmDgv/JHv19bSCfntJgHt236OY3bzdkCznHyJm6VAH05igWxernAr8vTpIvpX8D8yuoJo+TSfiN0wt4GPaxwyQnjxTcl+kk=; 7:1tm7BJwszpI9QCpVk3/YW6Nshsf28E62lmog4RDlhqxQqpwY6IXnLH4PsjazmuYCWvpJqbQfR2BRj6vZ7THh1b+QfreB7DR7ZxV5FWJoyAApZqteOBK0dfZRQ2CBvfb4JZqEsDjDKRgxfv8rYsNVCm3jBXkdCE813Ts1Fo5DN5+TSc9dYViIB9I6Hw9nl9DnIFUbb+kAp4SmRjBC3wtlYO8VlESqTIeuz70LWGruv9bYtuEH7N4gepCMeSXJAnTR SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Aug 2018 18:31:08.8988 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 372df687-4a5b-4c0a-83e1-08d607944603 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2548 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: , Cc: nd@arm.com, Alexandru Gheorghe Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The previous patch added tile_w and tile_h, which represent the horizontal and vertical sizes of a tile. This one uses that to plumb through drm core in order to be able to handle linear tile formats without the need for drivers to roll up their own implementation. This patch had been written with Mali-dp X0L2 and X0L0 in mind which is a 1 plane YCbCr 420 format with a 2x2 tile, that uses in average 2 bytes per pixel and where tiles are laid out in a linear manner. Now what are the restrictions: 1. Pitch in bytes is expected to cover at least tile_h * width in pixels. Due to this the places where the pitch is checked/used need to be updated to take into consideration the tile_w, tile_h and tile_size. tile_size = cpp * tile_w * tile_h 2. When doing source cropping plane_src_x/y need to be a multiple of tile_w/tile_h and we need to take into consideration the tile_w/tile_h when computing the start address. For all non-tiled formats the tile_w and tile_h will be 1, so if I didn't miss anything nothing should change. Regarding multi-planar linear tile formats, I'm not sure how those should be handle I kind of assumed that tile_h/tile_w will have to be divided by horizontal/subsampling. Anyway, I think it's best to just put an warning in there and handle it when someone tries to add support for them. Signed-off-by: Alexandru Gheorghe Reviewed-by: Liviu Dudau --- drivers/gpu/drm/drm_atomic.c | 8 +++ drivers/gpu/drm/drm_fb_cma_helper.c | 11 ++++- drivers/gpu/drm/drm_fourcc.c | 52 ++++++++++++++++++++ drivers/gpu/drm/drm_framebuffer.c | 19 +++++-- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 10 ++-- include/drm/drm_fourcc.h | 2 + 6 files changed, 94 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index 3eb061e11e2e..7a3e893a4cd1 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -1087,6 +1087,14 @@ static int drm_atomic_plane_check(struct drm_plane *plane, return -ENOSPC; } + /* Make sure source coordinates are a multiple of tile sizes */ + if ((state->src_x >> 16) % state->fb->format->tile_w || + (state->src_y >> 16) % state->fb->format->tile_h) { + DRM_DEBUG_ATOMIC("[PLANE:%d:%s] Source coordinates do not meet tile restrictions", + plane->base.id, plane->name); + return -EINVAL; + } + if (plane_switching_crtc(state->state, plane, state)) { DRM_DEBUG_ATOMIC("[PLANE:%d:%s] switching CRTC directly\n", plane->base.id, plane->name); diff --git a/drivers/gpu/drm/drm_fb_cma_helper.c b/drivers/gpu/drm/drm_fb_cma_helper.c index 47e0e2f6642d..4d8052adce67 100644 --- a/drivers/gpu/drm/drm_fb_cma_helper.c +++ b/drivers/gpu/drm/drm_fb_cma_helper.c @@ -87,6 +87,8 @@ dma_addr_t drm_fb_cma_get_gem_addr(struct drm_framebuffer *fb, struct drm_gem_cma_object *obj; dma_addr_t paddr; u8 h_div = 1, v_div = 1; + u32 tile_w = drm_format_tile_width(fb->format, plane); + u32 tile_h = drm_format_tile_height(fb->format, plane); obj = drm_fb_cma_get_gem_obj(fb, plane); if (!obj) @@ -99,8 +101,13 @@ dma_addr_t drm_fb_cma_get_gem_addr(struct drm_framebuffer *fb, v_div = fb->format->vsub; } - paddr += (fb->format->cpp[plane] * (state->src_x >> 16)) / h_div; - paddr += (fb->pitches[plane] * (state->src_y >> 16)) / v_div; + paddr += (fb->format->cpp[plane] * tile_w * (state->src_x >> 16)) + / h_div; + /* + * For tile formats pitches are expected to cover at least + * width * tile_h pixels + */ + paddr += ((fb->pitches[plane] / tile_h) * (state->src_y >> 16)) / v_div; return paddr; } diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c index f55cd93ba2d0..d6c9c5aa4036 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -557,3 +557,55 @@ int drm_format_plane_height(int height, uint32_t format, int plane) return height / info->vsub; } EXPORT_SYMBOL(drm_format_plane_height); + +/** + * drm_format_tile_width - width of a tile for tile formats, should be 1 for all + * non-tiled formats. + * @format: pixel format + * @plane: plane index + * + * Returns: + * The width of a tile, depending on the plane index and horizontal sub-sampling + */ +uint32_t drm_format_tile_width(const struct drm_format_info *info, int plane) +{ + WARN_ON(!info->tile_w); + if (plane == 0 || info->tile_w == 1) + return info->tile_w; + + /* + * Multi planar tiled formats have never been tested, check that + * buffer restrictions and source cropping meet the format layout + * expectations. + */ + WARN_ON("Multi-planar tiled formats unsupported"); + WARN_ON(info->tile_w % info->hsub); + return info->tile_w / info->hsub; +} +EXPORT_SYMBOL(drm_format_tile_width); + +/** + * drm_format_tile_height - height of a tile for tile formats, should be 1 for + * all non-tiled formats. + * @format: pixel format + * @plane: plane index + * + * Returns: + * The height of a tile, depending on the plane index and vertical sub-sampling + */ +uint32_t drm_format_tile_height(const struct drm_format_info *info, int plane) +{ + WARN_ON(!info->tile_h); + if (plane == 0 || info->tile_h == 1) + return info->tile_h; + + /* + * Multi planar tiled formats have never been tested, check that + * buffer restrictions and source cropping meet the format layout + * expectations. + */ + WARN_ON("Multi-planar tiled formats unsupported"); + WARN_ON(info->tile_h % info->vsub); + return info->tile_h / info->vsub; +} +EXPORT_SYMBOL(drm_format_tile_height); diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c index 781af1d42d76..57509e51cb80 100644 --- a/drivers/gpu/drm/drm_framebuffer.c +++ b/drivers/gpu/drm/drm_framebuffer.c @@ -191,19 +191,32 @@ static int framebuffer_check(struct drm_device *dev, unsigned int width = fb_plane_width(r->width, info, i); unsigned int height = fb_plane_height(r->height, info, i); unsigned int cpp = info->cpp[i]; + unsigned int tile_w = drm_format_tile_width(info, i); + unsigned int tile_h = drm_format_tile_height(info, i); + unsigned int tile_size = cpp * tile_w * tile_h; + unsigned int num_htiles; + unsigned int num_vtiles; if (!r->handles[i]) { DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i); return -EINVAL; } - if ((uint64_t) width * cpp > UINT_MAX) + if ((width % tile_w) || (height % tile_h)) { + DRM_DEBUG_KMS("buffer width/height need to be a multiple of tile dimensions\n"); + return -EINVAL; + } + + num_htiles = width / tile_w; + num_vtiles = height / tile_h; + + if ((uint64_t)num_htiles * tile_size > UINT_MAX) return -ERANGE; - if ((uint64_t) height * r->pitches[i] + r->offsets[i] > UINT_MAX) + if ((uint64_t)num_vtiles * r->pitches[i] + r->offsets[i] > UINT_MAX) return -ERANGE; - if (r->pitches[i] < width * cpp) { + if (r->pitches[i] < num_htiles * tile_size) { DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r->pitches[i], i); return -EINVAL; } diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c index 2810d4131411..3d01a1a9d5d2 100644 --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c @@ -161,6 +161,11 @@ drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file, unsigned int width = mode_cmd->width / (i ? info->hsub : 1); unsigned int height = mode_cmd->height / (i ? info->vsub : 1); unsigned int min_size; + unsigned int tile_w = drm_format_tile_width(info, i); + unsigned int tile_h = drm_format_tile_height(info, i); + unsigned int tile_size = info->cpp[i] * tile_w * tile_h; + unsigned int num_htiles = width / tile_w; + unsigned int num_vtiles = height / tile_h; objs[i] = drm_gem_object_lookup(file, mode_cmd->handles[i]); if (!objs[i]) { @@ -169,9 +174,8 @@ drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file, goto err_gem_object_put; } - min_size = (height - 1) * mode_cmd->pitches[i] - + width * info->cpp[i] - + mode_cmd->offsets[i]; + min_size = (num_vtiles - 1) * mode_cmd->pitches[i] + + num_htiles * tile_size + mode_cmd->offsets[i]; if (objs[i]->size < min_size) { drm_gem_object_put_unlocked(objs[i]); diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h index 41681cf2b140..001afca9bcff 100644 --- a/include/drm/drm_fourcc.h +++ b/include/drm/drm_fourcc.h @@ -76,6 +76,8 @@ int drm_format_horz_chroma_subsampling(uint32_t format); int drm_format_vert_chroma_subsampling(uint32_t format); int drm_format_plane_width(int width, uint32_t format, int plane); int drm_format_plane_height(int height, uint32_t format, int plane); +uint32_t drm_format_tile_width(const struct drm_format_info *info, int plane); +uint32_t drm_format_tile_height(const struct drm_format_info *info, int plane); const char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf); #endif /* __DRM_FOURCC_H__ */