Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1112644rwb; Tue, 4 Oct 2022 15:52:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6s/yTdGZ7EAbomJZja1zAR9o2RoJANah/j9fx6kYF8DH7YOroVrMN3UL9nNQa6Hpc5jrtE X-Received: by 2002:a17:90b:3b47:b0:202:a81f:4059 with SMTP id ot7-20020a17090b3b4700b00202a81f4059mr1991671pjb.150.1664923974478; Tue, 04 Oct 2022 15:52:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664923974; cv=none; d=google.com; s=arc-20160816; b=cVvMH4r5/mR6M9sCbmdz6E0AbOwTTqdyreU3IIGBcKEF8CE7fQm4lvIYcIoDtlhAQ2 EFzFDIQrZrBFbVddWSiGgQZ32jRQ+vjwfSmQlsKcCS11+4e87ITgRKRsJnM7xasCG25h sfjFh3AwPWd7W/4pOVP/xUVQNWXz2I/zYG2j6K+pqgt3pBhVSet6jyAHr8tXPdtcrilU QuJOXI8L1dNqvWtbcVOw99NL0RxdLnlhuxmuAvDIq6y1opPzR5G5XymsGMOy6WPnJVg/ 7JrozyEHZmvFCED1W7QCz98f8l4LIHtExZlcLZGb++zfhnHm+IVuAQO8Y6tIbe7oRwt9 eRiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:to:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=0PgM4RE7Ka9gaV1G1xyTNkPxoJ/6pneJjHVAFVAbx5c=; b=HomwpiZbz31IJC5qcxv1dlc0sNZJcu1wJQlhyeobMx63VhCMbPOm2RWxNS3QsKPHxl 6e3yEDJtLjXtoV6OXeAnFEwHzbzYusTi/GK0Ve28mrk+ziXQGVDx5653MVfvDlXga+Qr WAaz/NOHWBDvjSNXsA3cDUz71s9WBeDPhg5HpZw9xlvloBc7O/WoiCBcsFxJJrgmsxJa jSnm9by1gggxXtxRZX4W2EZy5rPFARnr946yu4k+9uYnd0M/ANmeknTetfHHq8zMTOxc NsD+9FSLbdijn59DoA4E1xT3JrX94kHKIy547XNXKm3LcxvTX95VwqQLWSymPKoRi5Nz Jlzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=saJFEvhI; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t23-20020a1709028c9700b001782914b5c3si10394791plo.241.2022.10.04.15.52.42; Tue, 04 Oct 2022 15:52:54 -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=@linaro.org header.s=google header.b=saJFEvhI; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230368AbiJDWkU (ORCPT + 99 others); Tue, 4 Oct 2022 18:40:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230235AbiJDWkR (ORCPT ); Tue, 4 Oct 2022 18:40:17 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5841617A96 for ; Tue, 4 Oct 2022 15:40:15 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id q17so16873264lji.11 for ; Tue, 04 Oct 2022 15:40:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date; bh=0PgM4RE7Ka9gaV1G1xyTNkPxoJ/6pneJjHVAFVAbx5c=; b=saJFEvhIooSAWR2WTc2oGrikRH7OFdCUFFM2pHt//KkWo4qOpGPgF2Q9N16Irz6NyH quI4/MzTFcXZcm4ZrzzDtr3N9rC3wbZf28riKbAC5p+QeFXw83Xak5sAoXzQKY4VttiB LPLRq7j82hYIP0ifgyr2a4E5qjDtIrXIwZfRtc1x5dNSL+3i/oQUt/H28by4gEiSdi19 lOtVtI9sVE/HS/+zCuvbonj42KABDbacKnw2N6QtERs+babJwSN7RWAsdUwr9FvqvlyG 98SivY9SyEhfBYeljqrzySRnM3tU1PO+qzzvOQEh9XBiXTwjkTYyiu8jnGsDnQ7pPGHU An4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=0PgM4RE7Ka9gaV1G1xyTNkPxoJ/6pneJjHVAFVAbx5c=; b=Mk7coO4bMWuRZzUtxEsDTAnRgn166mNCj7uk8asy/l+rOaXp3VEehILNyr3Gl6x0Aq XU1aAlMKrd3k3jFJJi+pdQj63XRbIUGOsqQ6Ul1K96ZyWz4mVSzSMdUED1Zoj1HuUHUK qfKE/FKnPiXGdkKLULSqhpfH5+PWDVuP+RW7Lfe3Z7GzoyZ53GWMyS2cqvX4Jp9XLIYG gLUK5vAzaU99768VLib1moN5cSKlJoJO9BP4w0DUhlkxrw6yprY0+vffYCoLt5G4SD6l Y5+sgyaiYCy+hQCDuOo46+hHMW11gr/ai0zBDnQ8/5UuiftC/FVTnb/FTQiaTu+Lxhqh pliQ== X-Gm-Message-State: ACrzQf2Qo8qR4ocVEHtGsM9x0MJA8v2m6GahycUwt5SZrq1YCgxvSZ4Z AmsGP8hXWlukrF4VB/szGgHRSw== X-Received: by 2002:a05:651c:1795:b0:261:af46:9d12 with SMTP id bn21-20020a05651c179500b00261af469d12mr8908592ljb.122.1664923213617; Tue, 04 Oct 2022 15:40:13 -0700 (PDT) Received: from [192.168.1.211] ([37.153.55.125]) by smtp.gmail.com with ESMTPSA id v12-20020ac258ec000000b004a25bb4494fsm304183lfo.178.2022.10.04.15.40.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Oct 2022 15:40:13 -0700 (PDT) Message-ID: Date: Wed, 5 Oct 2022 01:40:12 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Subject: Re: [PATCH 3/5] drm/msm/dsi: Account for DSC's bits_per_pixel having 4 fractional bits To: Marijn Suijten , phone-devel@vger.kernel.org, Rob Clark , Vinod Koul , ~postmarketos/upstreaming@lists.sr.ht, AngeloGioacchino Del Regno , Konrad Dybcio , Martin Botka , Jami Kettunen , David Airlie , Daniel Vetter , Abhinav Kumar , Sean Paul , Thomas Zimmermann , Javier Martinez Canillas , Alex Deucher , Douglas Anderson , Vladimir Lypak , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, Marek Vasut References: <20221001190807.358691-1-marijn.suijten@somainline.org> <20221001190807.358691-4-marijn.suijten@somainline.org> <20221004223504.vlfmxerdv47tlkdu@SoMainline.org> Content-Language: en-GB From: Dmitry Baryshkov In-Reply-To: <20221004223504.vlfmxerdv47tlkdu@SoMainline.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 On 05/10/2022 01:35, Marijn Suijten wrote: > On 2022-10-04 17:45:50, Dmitry Baryshkov wrote: >> On Sat, 1 Oct 2022 at 22:08, Marijn Suijten >> wrote: >> [..] >>> - bytes_in_slice = DIV_ROUND_UP(dsc->slice_width * dsc->bits_per_pixel, 8); >>> + bytes_in_slice = DIV_ROUND_UP(dsc->slice_width * bpp, 8); >> >> >> bytes_in_slice = DIV_ROUND_UP(dsc->slice_width * dsc->bits_per_pixel, 8 * 16); ? > > Not necessarily a fan of this, it "hides" the fact that we are dealing > with 4 fractional bits (1/16th precision, it is correct though); but > since this is the only use of `bpp` I can change it and document this > fact wiht a comment on top (including referencing the validation pointed > out in dsi_populate_dsc_params()). > > Alternatively we can inline the `>> 4` here? No, I don't think so. If we shift by 4 bits, we'd loose the fractional part. DIV_ROUND_UP( .... , 8 * 16) ensures that we round it up rather than just dropping it. > >>> >>> dsc->slice_chunk_size = bytes_in_slice; >>> >>> @@ -913,6 +918,7 @@ static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi) >>> u32 va_end = va_start + mode->vdisplay; >>> u32 hdisplay = mode->hdisplay; >>> u32 wc; >>> + int ret; >>> >>> DBG(""); >>> >>> @@ -948,7 +954,9 @@ static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi) >>> /* we do the calculations for dsc parameters here so that >>> * panel can use these parameters >>> */ >>> - dsi_populate_dsc_params(dsc); >>> + ret = dsi_populate_dsc_params(dsc); >>> + if (ret) >>> + return; >>> >>> /* Divide the display by 3 but keep back/font porch and >>> * pulse width same >>> @@ -1229,6 +1237,10 @@ static int dsi_cmd_dma_add(struct msm_dsi_host *msm_host, >>> if (packet.size < len) >>> memset(data + packet.size, 0xff, len - packet.size); >>> >>> + if (msg->type == MIPI_DSI_PICTURE_PARAMETER_SET) >>> + print_hex_dump(KERN_DEBUG, "ALL:", DUMP_PREFIX_NONE, >>> + 16, 1, data, len, false); >>> + >>> if (cfg_hnd->ops->tx_buf_put) >>> cfg_hnd->ops->tx_buf_put(msm_host); >>> >>> @@ -1786,6 +1798,12 @@ static int dsi_populate_dsc_params(struct drm_dsc_config *dsc) >>> int data; >>> int final_value, final_scale; >>> int i; >>> + int bpp = dsc->bits_per_pixel >> 4; >>> + >>> + if (dsc->bits_per_pixel & 0xf) { >>> + pr_err("DSI does not support fractional bits_per_pixel\n"); >>> + return -EINVAL; >>> + } >>> >>> dsc->rc_model_size = 8192; >>> dsc->first_line_bpg_offset = 12; >>> @@ -1807,7 +1825,7 @@ static int dsi_populate_dsc_params(struct drm_dsc_config *dsc) >>> } >>> >>> dsc->initial_offset = 6144; /* Not bpp 12 */ >>> - if (dsc->bits_per_pixel != 8) >>> + if (bpp != 8) >>> dsc->initial_offset = 2048; /* bpp = 12 */ >>> >>> mux_words_size = 48; /* bpc == 8/10 */ >>> @@ -1830,16 +1848,16 @@ static int dsi_populate_dsc_params(struct drm_dsc_config *dsc) >>> * params are calculated >>> */ >>> groups_per_line = DIV_ROUND_UP(dsc->slice_width, 3); >>> - dsc->slice_chunk_size = dsc->slice_width * dsc->bits_per_pixel / 8; >>> - if ((dsc->slice_width * dsc->bits_per_pixel) % 8) >>> + dsc->slice_chunk_size = dsc->slice_width * bpp / 8; >>> + if ((dsc->slice_width * bpp) % 8) >> >> One can use fixed point math here too: >> >> dsc->slice_chunk_size = (dsc->slice_width * dsc->bits_per_pixel + 8 * >> 16 - 1)/ (8 * 16); > > Good catch, this is effectively a DIV_ROUND_UP() that we happened to > call bytes_in_slice above... > > Shall I tackle this in the same patch, or insert another cleanup patch? It's up to you. I usually prefer separate patches, even if just to ease bisecting between unrelated changes. > > In fact dsi_populate_dsc_params() is called first (this comment), > followed by dsi_update_dsc_timing(), meaning that slice_chunk_size is > already provided and shouldn't be recomputed. > >>> dsc->slice_chunk_size++; >>> >>> /* rbs-min */ >>> min_rate_buffer_size = dsc->rc_model_size - dsc->initial_offset + >>> - dsc->initial_xmit_delay * dsc->bits_per_pixel + >>> + dsc->initial_xmit_delay * bpp + >>> groups_per_line * dsc->first_line_bpg_offset; >>> >>> - hrd_delay = DIV_ROUND_UP(min_rate_buffer_size, dsc->bits_per_pixel); >>> + hrd_delay = DIV_ROUND_UP(min_rate_buffer_size, bpp); >>> >>> dsc->initial_dec_delay = hrd_delay - dsc->initial_xmit_delay; >>> >>> @@ -1862,7 +1880,7 @@ static int dsi_populate_dsc_params(struct drm_dsc_config *dsc) >>> data = 2048 * (dsc->rc_model_size - dsc->initial_offset + num_extra_mux_bits); >>> dsc->slice_bpg_offset = DIV_ROUND_UP(data, groups_total); >>> >>> - target_bpp_x16 = dsc->bits_per_pixel * 16; >>> + target_bpp_x16 = bpp * 16; >>> >>> data = (dsc->initial_xmit_delay * target_bpp_x16) / 16; >> >> It looks like this can be replaced with the direct multiplication >> instead, maybe with support for overflow/rounding. > > Thanks, Abhinav pointed out the same in patch 1/5 which originally > cleaned up most - but apparently not all! - of the math here. I don't > think this value should ever overlow, nor does this `* 16 / 16` have any > effect on rounding (that'd be `/ 16 * 16`). Ack > >>> final_value = dsc->rc_model_size - data + num_extra_mux_bits; >>> -- >>> 2.37.3 >>> >> >> >> -- >> With best wishes >> Dmitry -- With best wishes Dmitry