Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4932866rdb; Tue, 12 Dec 2023 13:38:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVWAbpGrruyDdmb8/VbuujJ1FsXIlX20w0cdgBVfYbpmM9LNRqSQUcWXARl4QIJgCmv8xm X-Received: by 2002:a05:6358:99a0:b0:16b:fe18:27fc with SMTP id j32-20020a05635899a000b0016bfe1827fcmr8617432rwb.31.1702417092304; Tue, 12 Dec 2023 13:38:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702417092; cv=none; d=google.com; s=arc-20160816; b=v7np2MtKPqSS07x4j1vbJGpyc9jucUMVrwSkCiX942nxkdxKEXgWsYIi9dIADXzitk x++lHh0yiEcFFXo8eNsnnVkdCq9VFfzZ6x7rsp3SjX/q6AyrXmlbh9GZRa/UMOkbl7rS Jf6DS92CSNwlvSf+/LmHYmVB3Eb0Ki2xS1XyZMEvVWbeIZVPDID/aQJB7l91R/1gmJAM SuFdOuwIiAIO92kuyzm9Cq9DdQ/+MUx2P55cWSzr9XvbTWMdNUdCH5e91B30PrgS1a4A pUj1n0+PmGAXn18ef5NEvtdXAnrfrqPvgdC4R1I9ZiuZtSNscv3R9MZLoiINs/jVShzf 1riA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=hhsGxU/qWWOqfefKWpO0M9yGwPlrA51ZAFdB+LK78Og=; fh=WdvorNt9W2LCUPiGPsn75/bW5381IkpXRxF82JgZV7c=; b=AG51YMrzuxiaAJ9SQnFzufArO1ssn0hhJnt+SmlZerVtzP0IHYMyoLKc85nZUH1vFm MDOlvJStPSZup3S7c/BDSz1lStHt54++1/X4Bxis1YmeSsH0nc8rqooh8CwG6zwO7GD3 6Fs+BCsseEaidqjuIulc+OsxtChT2JTBD+jxNsmTGBehGn1PWNki5U4JgwIa3UDn8SB1 0ykdgb1A95MG2of18eYGXRRnXpPEILaKOoBrU9SK87MuNGdDfXP149fBxPLkoKVPGhSf xgg4FIwYJPpPEHAMBJsoY7o7AoSpKs/jll5pjde17ylqrQniU4WbekOg6MOfHHML1cAp xDjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=UisptYPt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id l5-20020a056a00140500b006cdf584699fsi8472611pfu.336.2023.12.12.13.38.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 13:38:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=UisptYPt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id DEC61802373C; Tue, 12 Dec 2023 13:38:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377314AbjLLVhy (ORCPT + 99 others); Tue, 12 Dec 2023 16:37:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231345AbjLLVhx (ORCPT ); Tue, 12 Dec 2023 16:37:53 -0500 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F922AF; Tue, 12 Dec 2023 13:37:58 -0800 (PST) Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 3BCKPSWg015264; Tue, 12 Dec 2023 21:37:49 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:mime-version:content-type; s= qcppdkim1; bh=hhsGxU/qWWOqfefKWpO0M9yGwPlrA51ZAFdB+LK78Og=; b=Ui sptYPt716hImd/Wpp8ZWpfvgsnD+3GnGRifTszBvOao18y+UlZW07FGYTa+Wcg/T w/6NC98YgN6p+ojt1c8hNhO3tQLjfK+fnRf80O1fUPzG56/csQFeGfNysy8sGAdD dwm10eYc0S8iSsWkyru7MfLbtHLf1FkmOmVKYQZY8tVXIz5XTao/3fEP4mtA6gpB khWBTk2BULdnGDp5hBuIakmUIZQysgrcyN26cITQpcApjWIylSqHSAeO0vedYKyV sOkF6N9GNCeN5gRFQGgQByaRyeN1EEjOs/FK2HJR/GbnhR3TP/u9Y6NuhlwGp+b4 7dtfr+7j9XAMA5nko6Mw== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ux6533k1j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 12 Dec 2023 21:37:49 +0000 (GMT) Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3BCLblA7020621 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 12 Dec 2023 21:37:47 GMT Received: from khsieh-linux1.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 12 Dec 2023 13:37:47 -0800 From: Kuogee Hsieh To: , , , , , , , , , , CC: Kuogee Hsieh , , , , , , , Subject: [PATCH v4] drm/msm/dpu: improve DSC allocation Date: Tue, 12 Dec 2023 13:37:38 -0800 Message-ID: <1702417058-24257-1-git-send-email-quic_khsieh@quicinc.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: hgp7sv2OQkzQ8rgJsZBH2vaoEjJNLrBL X-Proofpoint-GUID: hgp7sv2OQkzQ8rgJsZBH2vaoEjJNLrBL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_02,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 mlxscore=0 mlxlogscore=684 clxscore=1015 adultscore=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 suspectscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2312120167 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 12 Dec 2023 13:38:09 -0800 (PST) At DSC V1.1 DCE (Display Compression Engine) contains a DSC encoder. However, at DSC V1.2 DCE consists of two DSC encoders, one has an odd index and another one has an even index. Each encoder can work independently. But only two DSC encoders from same DCE can be paired to work together to support DSC merge mode at DSC V1.2. For DSC V1.1 two consecutive DSC encoders (start with even index) have to be paired to support DSC merge mode. In addition, the DSC with even index have to be mapped to even PINGPONG index and DSC with odd index have to be mapped to odd PINGPONG index at its data path in regardless of DSC V1.1 or V1.2. This patch improves DSC allocation mechanism with consideration of those factors. Changes in V4: -- rework commit message -- use reserved_by_other() -- add _dpu_rm_pingpong_next_index() -- revise _dpu_rm_pingpong_dsc_check() Changes in V3: -- add dpu_rm_pingpong_dsc_check() -- for pair allocation use i += 2 at for loop Changes in V2: -- split _dpu_rm_reserve_dsc() into _dpu_rm_reserve_dsc_single() and _dpu_rm_reserve_dsc_pair() Fixes: f2803ee91a41 ("drm/msm/disp/dpu1: Add DSC support in RM") Signed-off-by: Kuogee Hsieh --- drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c | 178 ++++++++++++++++++++++++++++++--- 1 file changed, 163 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c index f9215643..15317b6 100644 --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c @@ -461,29 +461,177 @@ static int _dpu_rm_reserve_ctls( return 0; } -static int _dpu_rm_reserve_dsc(struct dpu_rm *rm, +static int _dpu_rm_pingpong_next_index(int start, + uint32_t enc_id, + uint32_t *pp_to_enc_id, + int pp_max) +{ + int pp_ndx; + + for (pp_ndx = start; pp_ndx < pp_max; pp_ndx++) { + if (pp_to_enc_id[pp_ndx] == enc_id) + return pp_ndx; + } + + return -ENAVAIL; +} + +static int _dpu_rm_pingpong_dsc_check(int dsc_ndx, int pp_ndx) +{ + + /* + * dsc even index must be mapped to pingpong even index + * dsc odd index must be mapped to pingpong odd index + */ + if ((dsc_ndx & 0x01) != (pp_ndx & 0x01)) + return -ENAVAIL; + + return 0; +} + +static int _dpu_rm_reserve_dsc_single(struct dpu_rm *rm, struct dpu_global_state *global_state, - struct drm_encoder *enc, + uint32_t enc_id, + int *dsc_id, const struct msm_display_topology *top) { - int num_dsc = top->num_dsc; - int i; + int num_dsc = 0; + uint32_t *pp_to_enc_id = global_state->pingpong_to_enc_id; + uint32_t *dsc_enc_id = global_state->dsc_to_enc_id; + int pp_max = PINGPONG_MAX - PINGPONG_0; + int pp_ndx; + int dsc_ndx; + int ret; - /* check if DSC required are allocated or not */ - for (i = 0; i < num_dsc; i++) { - if (!rm->dsc_blks[i]) { - DPU_ERROR("DSC %d does not exist\n", i); - return -EIO; - } + for (dsc_ndx = 0; dsc_ndx < ARRAY_SIZE(rm->dsc_blks); dsc_ndx++) { + if (!rm->dsc_blks[dsc_ndx]) + continue; + + if (reserved_by_other(dsc_enc_id, dsc_ndx, enc_id)) + continue; + + pp_ndx = _dpu_rm_pingpong_next_index(0, enc_id, pp_to_enc_id, pp_max); + if (pp_ndx < 0) + return -ENAVAIL; + + ret = _dpu_rm_pingpong_dsc_check(dsc_ndx, pp_ndx); + if (ret) + return -ENAVAIL; + + dsc_id[num_dsc++] = DSC_0 + dsc_ndx; /* found */ + + if (num_dsc >= top->num_dsc) + break; + } - if (global_state->dsc_to_enc_id[i]) { - DPU_ERROR("DSC %d is already allocated\n", i); - return -EIO; + if (num_dsc < top->num_dsc) { + DPU_ERROR("DSC allocation failed num_dsc=%d required=%d\n", + num_dsc, top->num_dsc); + return -ENAVAIL; + } + + return 0; +} + +static int _dpu_rm_reserve_dsc_pair(struct dpu_rm *rm, + struct dpu_global_state *global_state, + uint32_t enc_id, + int *dsc_id, + const struct msm_display_topology *top) +{ + int num_dsc = 0; + uint32_t *pp_to_enc_id = global_state->pingpong_to_enc_id; + uint32_t *dsc_enc_id = global_state->dsc_to_enc_id; + int pp_max = PINGPONG_MAX - PINGPONG_0; + int start_pp_ndx = 0; + int dsc_ndx, pp_ndx; + int ret; + + /* only start from even dsc index */ + for (dsc_ndx = 0; dsc_ndx < ARRAY_SIZE(rm->dsc_blks); dsc_ndx += 2) { + if (!rm->dsc_blks[dsc_ndx] || !rm->dsc_blks[dsc_ndx + 1]) + continue; + + /* consective dsc index to be paired */ + if (reserved_by_other(dsc_enc_id, dsc_ndx, enc_id) || + reserved_by_other(dsc_enc_id, dsc_ndx + 1, enc_id)) + continue; + + pp_ndx = _dpu_rm_pingpong_next_index(start_pp_ndx, enc_id, pp_to_enc_id, pp_max); + if (pp_ndx < 0) + return -ENAVAIL; + + ret = _dpu_rm_pingpong_dsc_check(dsc_ndx, pp_ndx); + if (ret) { + pp_ndx = 0; + continue; } + + pp_ndx = _dpu_rm_pingpong_next_index(pp_ndx + 1, enc_id, pp_to_enc_id, pp_max); + if (pp_ndx < 0) + return -ENAVAIL; + + /* pair found */ + dsc_id[num_dsc++] = DSC_0 + dsc_ndx; + dsc_id[num_dsc++] = DSC_0 + dsc_ndx + 1; + + start_pp_ndx = pp_ndx + 1; /* start for next pair */ + + if (num_dsc >= top->num_dsc) + break; + } + + if (num_dsc < top->num_dsc) { + DPU_ERROR("DSC allocation failed num_dsc=%d required=%d\n", + num_dsc, top->num_dsc); + return -ENAVAIL; } - for (i = 0; i < num_dsc; i++) - global_state->dsc_to_enc_id[i] = enc->base.id; + return 0; +} + +static int _dpu_rm_reserve_dsc(struct dpu_rm *rm, + struct dpu_global_state *global_state, + struct drm_encoder *enc, + const struct msm_display_topology *top) +{ + uint32_t enc_id = enc->base.id; + int dsc_id[DSC_MAX - DSC_0]; + int i, ret; + + if (!top->num_dsc || !top->num_intf) + return 0; + + memset(dsc_id, 0, sizeof(dsc_id)); + + /* + * Truth: + * 1) every layer mixer only connects to one interface + * 2) no pingpong split -- which is two layer mixers shared one pingpong + * 3) DSC pair start from even index, such as index(0,1), index (2,3), etc + * 4) odd pingpong connect to odd dsc + * 5) even pingpong connect to even dsc + * 6) pair: encoder +--> pp_idx_0 --> dsc_idx_0 + +--> pp_idx_1 --> dsc_idx_1 + */ + + /* num_dsc should be either 1, 2 or 4 */ + if (top->num_dsc > top->num_intf) /* merge mode */ + ret = _dpu_rm_reserve_dsc_pair(rm, global_state, enc_id, dsc_id, top); + else + ret = _dpu_rm_reserve_dsc_single(rm, global_state, enc_id, dsc_id, top); + + if (ret) + return ret; + + /* everything is good proceed to allocate dsc */ + for (i = 0; i < top->num_dsc; i++) { + int id; + + id = dsc_id[i]; + if (id >= DSC_0) + global_state->dsc_to_enc_id[id - DSC_0] = enc_id; + } return 0; } -- 2.7.4