Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp280979rwb; Thu, 11 Aug 2022 01:04:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR7DWt9dvM596vXzamXofOUjM3OrH5BGTRoGbU92ARJbIqNRj09FgOuu65e3wLAlZMROScWY X-Received: by 2002:a05:6402:3550:b0:43d:e475:7d2f with SMTP id f16-20020a056402355000b0043de4757d2fmr29680732edd.166.1660205088846; Thu, 11 Aug 2022 01:04:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660205088; cv=none; d=google.com; s=arc-20160816; b=jLaphKbUvSKeXnaq8mIf27aX6GA1R+Haz0pgMh7fmRneUHjrn3O7MlqpM7b8etOav0 gfsGTdZMkB+EXLhAwymQDcrj1NBP5foqEyfmlEW0knhKumAS1va9G/sRXWKAMGuki+TZ B6+unOKsj/BUv0tN5lDhJ6DKBCDfS7YyNz388RadyFwsnWgmhs14CEaBsELLaF1JhcbN ELfVInNWBZOvd1RWoA6zLlyInBUnTU9l6DBogVVfnBBr2ofH+EsFJYztyh3JFCVZ6hYY NtsL38K0Wh9yPW32geoN1fOD1GatafDWcj37B4mtjj2GrozIBuqGgfY4EeeJ4F16+po4 g5fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=Mzt9xiZn2UZTlTKHVMvt4CFBZHRE5sVzzM2CBT3iHn0=; b=0IjrD4CjT1MftpyQrZyEX6ugeXwmxvXTLJ9YIiINjpr6doxCZhwz2OADpz0muIE2ok eXSP4MQU8IWGzEIAIbA2nYaThrXcQJcgjLgFlpWSnHrj7XiQE9Wz/l0Z3oW5XjmeJKXv K/5qtn5VmikddwJdMnrqJy36XPskWkTyPOMYbk7sctK+qlyy+n6d1bH3g3HJt3JvbNCH 16FkD+Zz5D82HeDaWFzlyUyOlLNAxKWRh1jLe1Lii1/xcfn/l0uSXO2J3uzZVGhpJo46 3f3eYWy3cvmO6xrGApN+tSK3CXjU2BiH9LtzCrX5vlDq6U8SGTF5F9BGUVqW+JAji2iF reXA== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t24-20020a056402241800b004424ff25f21si4441437eda.407.2022.08.11.01.04.19; Thu, 11 Aug 2022 01:04:48 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234022AbiHKH76 (ORCPT + 99 others); Thu, 11 Aug 2022 03:59:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233028AbiHKH7z (ORCPT ); Thu, 11 Aug 2022 03:59:55 -0400 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AB1B8E9AE; Thu, 11 Aug 2022 00:59:54 -0700 (PDT) Received: by mail-qt1-f171.google.com with SMTP id a4so8261608qto.10; Thu, 11 Aug 2022 00:59:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=Mzt9xiZn2UZTlTKHVMvt4CFBZHRE5sVzzM2CBT3iHn0=; b=pTdmlRWEUv7hnG7gNZeG7U0LqUmOkF4SQ9JswnJhOhMEm1T8IpKQteS2+VdGooCB/5 CMCFjpRXZzCyJu271gz/UIE2E2cq5wcmOpoduz0NyXPnzQb9zU9Dfe+kPqBb4saHKU+h WQZyy30fy4qw8IDv4JQ3o2RtJARmjn7QboGz3oB7vEZNwq0RxqrVM97fAU55Fxfnvc3G vPpgbFi7E80SYdk5hhmKifHvcjXKCe9KKJkkWtYhoubg4y6UQbzeL/eB0/wr/120naDe +iuwvTkW9SOpdegqExBwm8F8eP9LnGbUNlp4ORkUJSgpGou9hz71WstDnzXFCRg+eska FH6w== X-Gm-Message-State: ACgBeo1PBRar37v4bLgukPzYXW51ElUotzSqLuQELkfV5N/8fGN/bnOr aUVnjzIDpnMWq3SnuNnBNwlKo+1gYnePQEQQ X-Received: by 2002:a05:622a:3d2:b0:31f:1e36:4782 with SMTP id k18-20020a05622a03d200b0031f1e364782mr26837995qtx.190.1660204792844; Thu, 11 Aug 2022 00:59:52 -0700 (PDT) Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com. [209.85.128.172]) by smtp.gmail.com with ESMTPSA id f4-20020a05620a408400b006b46a78bc0fsm1479308qko.118.2022.08.11.00.59.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Aug 2022 00:59:51 -0700 (PDT) Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-31f661b3f89so165054187b3.11; Thu, 11 Aug 2022 00:59:51 -0700 (PDT) X-Received: by 2002:a81:b049:0:b0:324:7408:94b with SMTP id x9-20020a81b049000000b003247408094bmr31043465ywk.283.1660204791329; Thu, 11 Aug 2022 00:59:51 -0700 (PDT) MIME-Version: 1.0 References: <1cae5ebc28513ec1c91c66b00647ce3ca23bfba7.1657294931.git.geert@linux-m68k.org> In-Reply-To: From: Geert Uytterhoeven Date: Thu, 11 Aug 2022 09:59:39 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 01/10] drm/fourcc: Add drm_format_info_bpp() helper To: Daniel Vetter Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , DRI Development , Linux Fbdev development list , "Linux/m68k" , Linux Kernel Mailing List , Javier Martinez Canillas Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 Hi Daniel, On Wed, Aug 10, 2022 at 5:59 PM Daniel Vetter wrote: > On Fri, Jul 08, 2022 at 08:20:46PM +0200, Geert Uytterhoeven wrote: > > Add a helper to retrieve the actual number of bits per pixel for a > > plane, taking into account the number of characters and pixels per > > block for tiled formats. > > > > Signed-off-by: Geert Uytterhoeven > > Reviewed-by: Javier Martinez Canillas > > --- a/drivers/gpu/drm/drm_fourcc.c > > +++ b/drivers/gpu/drm/drm_fourcc.c > > @@ -370,6 +370,25 @@ unsigned int drm_format_info_block_height(const struct drm_format_info *info, > > } > > EXPORT_SYMBOL(drm_format_info_block_height); > > > > +/** > > + * drm_format_info_bpp - number of bits per pixel > > + * @info: pixel format info > > + * @plane: plane index > > + * > > + * Returns: > > + * The actual number of bits per pixel, depending on the plane index. > > + */ > > +unsigned int drm_format_info_bpp(const struct drm_format_info *info, int plane) > > +{ > > + if (!info || plane < 0 || plane >= info->num_planes) > > + return 0; > > + > > + return info->char_per_block[plane] * 8 / > > + (drm_format_info_block_width(info, plane) * > > + drm_format_info_block_height(info, plane)); > > Do we really needs this for blocky formats where this is potentially > ill-defined? I think if there's no need then this should also return 0 > when block_width/height != 1, it doesn't make much sense to compute bpp > when it's not really bits per _pixel_. Yes, we do need this. For low-color formats, the number of bits per pixel is less than eight, and block_width is larger than one. That is actually the point of this patch. > Minimally this needs to check whether the division actually makes sense or > whether there's a reminder, and if there's reminder, then fail. But that > feels like a bad hack and I think we should avoid it if it's not > absolutely necessary. Looking at drivers/gpu/drm/drm_fourcc.c, the only supported format where there can be a remainder is P030, which has 2 spare bits per 32-bit word, and thus is special anyway. Still, 4 * 8 / 3 = 10, so you get the correct numbers of bits for the first plane. For the second plane, you get 8 * 8 / 3 = 21, but as .is_yuv = true, you have to divide that result by two again, so you get 10 again. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds