From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796129311; b=D1yjbHzjMMLU/1YT77YP4CcImUjXsUvxSrG7nokRQF8UYRWF3pc1K9nDmi+l9EYDGbQL Ws0lvin5VzM9r7YV5cO2yqSW24fg/l5QtXLjPJuTR1VzcPoTJ0SVj65TCmH+wKPFmo77u bsCXrn5ot7j1WBwob0ZCBR5+r5KUOdQ16fmdTwVtz5/8HVbMht7/ssd/+mKWesQEERDt/ g/4LjxLC+g3n0FNiAvldI2GaYO7JExWF6MCQ48sTpfOawu/aLAypw1SNSVzAiuSuJqQw2 z0OHCRriWzS5KJ9Uaoupgq1r57ztM9isGjOnidEwJ9clnS5kiyJvdazOw1H0AtwliTg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796129311; h=DMARC-Filter:Received:DKIM-Signature:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:X-Received:Received:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Proofpoint-Spam-Info: X-Proofpoint-Spam-Details-Enc:X-Authority-Analysis: X-Proofpoint-ORIG-GUID:X-Proofpoint-GUID:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=1BTDfKiKNdlLSL1COSjrQ3wRrY1DC7fptsdAO/Dq+sY=; b=B/KAAkUnQjsR45tvkPsByDHzZY2IB33V5mrpoCoYiSN6agHTae050M8pL2q1mK0TFIAi uOxsO5utSLbvOaVsL+tDIAgqUuiZocdSVi5oSDi9+o1vRpEaougq9S94ZtIx+WxJI2I9Y WH5sRaIm/Vsz8kdCatRN9TwBEc7vfEMEdJemUmXLhDp0uti/l1xX+XvABDt2vShXAxl2v RNeaBjC0lLqVQVTHj6SUaGB3CxX0BNHkFYiomrdKWztlQNgcmxyVlhtCTs+8AIl8ZjjVo aXKFH2TCmKarRycWpMwKVGQ7lszqPZW5U2pXnqgDf3XvFbmK5iSKY/DGXfYgSvG2ysw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=mHc6unEp; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=jPFXZ7HG; arc=none smtp.remote-ip=205.220.168.131 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E71B960A5BE6 for ; Tue, 1 Dec 2026 12:48:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E71B960A5BE6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=mHc6unEp; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=jPFXZ7HG Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B1AQPFW2313384 for ; Tue, 1 Dec 2026 12:48:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=1BTDfKiKNdl LSL1COSjrQ3wRrY1DC7fptsdAO/Dq+sY=; b=mHc6unEpcZDBP3Nl6B75NQUNwUJ xZGY9pYZqs+6P8KgX+wS31Tyyi3b8jDkBo9A2nih92b0NLtMeRAC8ZOfMrnVnoPB 69Cc+ndUlTOMC8Nrjug4FPNNWFoBCiq5pe41s35PMZn75+MpXtb9ogdSAAls9m11 iOhIoL/3tqv4jYxDcqgzcJNq1S0a1vQTz+My+FWs6pTP0nF2E1rp1FK9gRBvgIIx Z0bUNdftsFbJRDncnFoHayvzyvAeKWuLHA7f5ALbpcOtkppCdk+ZDhS6QMlZybQk dPRFqL+lVATB3OIyz6JoO0S2+tZY1QQ2CmbzbFINTy/isDyQq5rpB0B59Vg== Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4j9nb62c7f-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 01 Dec 2026 12:48:30 +0000 (GMT) Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-94a1db3cd3cso629181085a.0 for ; Tue, 01 Dec 2026 04:48:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796129309; x=1796734109; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=1BTDfKiKNdlLSL1COSjrQ3wRrY1DC7fptsdAO/Dq+sY=; b=jPFXZ7HGoKsCgVYKGsGgvvK9CkLjbyV1dZ79J1oGON8Okhpw9m3Yja1ZlefLLSn8VW wLxa0IUOMlfNYChJInThdrmgmm5UAlVp+OCocgvhOoV9Mju6kCQwTnOHoCwy1Fg6InP3 i5YD2utG7eWqG5bdFlNlqF4524mAvMHfsKM0BitpBjkWiu9Y01GHEFRg/PJEpnwhMjqP 3tndNBo0fhGKRC3aCkbrsBulHCgJEUnVO+hpo34CbNJ/pPOiXop85yNlYm5N0Kosz+/t MzQZPyIBCmES2xvyWUGWumFBbzaHJnviHtN3jD7whkmvxW0Bzmx+yG+wUUjsRbfdfVM1 z5BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796129309; x=1796734109; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=1BTDfKiKNdlLSL1COSjrQ3wRrY1DC7fptsdAO/Dq+sY=; b=hP7j+8H3zfTzUPvZrrVdvnc5m6Vr4Aet93idV2KUEhfQjytUXICS/YFBa1k/N4+Dvu nrz132Cfbs03a1AZeOcYabV/Qum7ifc2gwuyJ0SGFQluv8a0yF8PNvLAq80XJhsoIYO0 9iHVJ0qjXqW7Ppq4yDnxIVmJEqw3fNW0B700hN7xWh/5642U+aYpZazx0+8+kiAKExyv aQr2wDNQnDQt3zeTgd1iPTt0G4sP8wPY0keIcA50XZer4KjFGonIegfFMiJ8j+sWeSLp 0c0PH0wKUOPgSC5outXZD99xh/mOvbI+/755hHTvX+rjxRWYrFbeLnCnlhs+eTKdNqIp ibng== X-Forwarded-Encrypted: i=1; AL+hErFaBDGvdMoy+Uvq1ElWrzQKi9pExvtQT9xGAUC6g8IQ39N4csf+BkjUJjn+LI1AHQD8IVBElu1mBilc27I=@vger.kernel.org X-Gm-Message-State: APuU4Z8zFFi4pAZlqzf2UfezHWw5Fn7oteFjxaekjnWUjaKLA7K1WUjH 2KHDBJhZ5CNYzvqpdoyD34v/m6rG88I28LkvmXbyShTvyuDitnRI1vMdQJzfGR10QbpHRyLzTQr 9iGjE8DNfwksirzECioeB/TDkPcQNBjgQZHOIpBWctOswwQhGejScQ75UhbDcbMDKG4M= X-Gm-Gg: AZFdTZfecJDNLJfGJ6oWQiiiM44dlmKd/lGOAR+briMzkTw3YIgRTbssjkqWJEqBB78 SmQ2dcgJ/TTKzQS+Ky+eI5hlvCSpMMmcKwXY4zcW93gB8llCRpY0Fb5lqQnn77Ku5G5hxwTpPiQ 7RKrmMA9kIo3zuZhNo00ULU0MrvxIrVy2ZG3/6vHtbX1GVadL0EjgRgQpa7KnAaJH7kYqH0F5nT oyfSHMiiAjfKQme64GMyKKteMjnsBUeQLT7YB5TzDIg8wkyNbsr5Zshd5ApUSSnKgVEBmIM0NxP JQ5voWneOUjsENwa58Zh5a7p+VUUjFr5MGpbMQDOO2jzAnQkJ15Q67fArP8L5RkphIIdLBLBzx/ wZjiG7poJITKrWywJpS9BXYxka/8FUKvbhr6b+yxKc0ZMSneRnut8s12TG+7Twm8i X-Received: by 2002:a05:620a:2988:b0:93f:57a3:71ab with SMTP id af79cd13be357-949ba9962f2mr6711800185a.32.1796129308800; Tue, 01 Dec 2026 04:48:28 -0800 (PST) X-Received: by 2002:a05:620a:2988:b0:93f:57a3:71ab with SMTP id af79cd13be357-949ba9962f2mr6711796885a.32.1796129308338; Tue, 01 Dec 2026 04:48:28 -0800 (PST) Received: from debian ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb853a9687sm1131892375e9.10.2026.12.01.04.48.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 04:48:27 -0800 (PST) From: Srinivas Kandagatla To: Mark Brown Cc: Liam Girdwood , Jaroslav Kysela , Takashi Iwai , Kuninori Morimoto , Pierre-Louis Bossart , Bjorn Andersson , Konrad Dybcio , Abel Vesa , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , Randy Dunlap , Shuah Khan , linux-sound@vger.kernel.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, alsa-devel@alsa-project.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Ravi Hothi , Srinivas Kandagatla Subject: [PATCH v4 15/24] ASoC: qcom: audioreach: send static cfg blobs to speaker protection modules Date: Tue, 1 Dec 2026 12:47:44 +0000 Message-ID: <20261201124753.196748-16-srinivas.kandagatla@oss.qualcomm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com> References: <20261201124753.196748-1-srinivas.kandagatla@oss.qualcomm.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAxMDA1MCBTYWx0ZWRfX4DwKplDMfa/a A5tWbqXMxqHC+yjGA/4z+sD+IL75qIftXJdp9w0lmtL02jLqXVG9LkLxf+Al6Rt8FSRWl3LQhHA 8sg7DlWLt8qG7E0suAvlAdJFCbMg8uQ= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAxMDA1MCBTYWx0ZWRfX7G6lSIPr+frH Fod5yaI6VnDCQywG2xLDsYjhF1nEKwS89pQEjVnMS4Uel4XcMRHT6Y/7zP4lQSpVXgS9+UOKIC2 miozoX/9N/LKrkW7ffnm6EJzugvHng2MEfdGhUhXaO++5WpPW9FnImKQzrVKuC8b30e/lDKyXgZ g3uAuMzO6WIsFY9Hns2yH9WP6kkhNgK+ozIONyAqeHTg7AiNf2oZ7mP2IDCo5rvyVKgGnvVoaK1 3BStdWczh0zNxwZmGx1rTIzfcMAHBGPXizXSyLw98gkYz+Bgpo+tr/5RSbMKKAMx1bbO3PGXdis SnnblLeYZTBzbwrrTkzi4g+OB3oIXv5B2IbKfgIpZr9oGbHA2bV9EdxXXZ1ldzxE3pSXGiktdZc vROr8JfdUQD07nCorY6bCBdo0CWabSHIRcIe8orIgwgrWjE3Qmm/qBAbiMUUfPtTdbYzThMEVEq YxHrPHQKCDRXSL+pzeA== X-Authority-Analysis: v=2.4 cv=fc44WEQF c=1 sm=1 tr=0 ts=6b0ec21e cx=c_pps a=hnmNkyzTK/kJ09Xio7VxxA==:117 a=ZsC4DHZuhs/kKio7QBcDoQ==:17 a=pUM-KoujPXoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=EUspDBNiAAAA:8 a=OAJap1ZGhMVArrtS6vMA:9 a=PEH46H7Ffwr30OY-TuGO:22 X-Proofpoint-ORIG-GUID: d3VzxjwAwGTZGAH4CBOT8HGsVAHSW8bF X-Proofpoint-GUID: d3VzxjwAwGTZGAH4CBOT8HGsVAHSW8bF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-01_02,2026-11-30_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 adultscore=0 suspectscore=0 clxscore=1015 bulkscore=0 priorityscore=1501 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612010050 From: Ravi Hothi The speaker protection modules need tuning parameters from the topology cfg blob, which is never sent to the DSP. Send it once the module is configured, in small SET_CFG commands split on parameter boundaries, with each payload padded to 8 bytes as the DSP expects. Every record is checked against the end of the blob, and a malformed blob is rejected. A blob not laid out as parameter records is sent whole. Signed-off-by: Ravi Hothi Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/qdsp6/audioreach.c | 139 ++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/sound/soc/qcom/qdsp6/audioreach.c b/sound/soc/qcom/qdsp6/audioreach.c index 19e00563c783..2c1ff8e65b67 100644 --- a/sound/soc/qcom/qdsp6/audioreach.c +++ b/sound/soc/qcom/qdsp6/audioreach.c @@ -1923,6 +1923,141 @@ static int audioreach_speaker_protection_vi(struct q6apm_graph *graph, return rc; } +/* Keep each SET_CFG small; a larger single parameter is sent on its own */ +#define AR_SP_CFG_MAX_CHUNK_BYTES 512 + +static int audioreach_speaker_protection_send_chunk(struct q6apm_graph *graph, + const char *tag, + const void *data, int size, + int chunk_idx) +{ + int rc; + + struct gpr_pkt *pkt __free(kfree) = audioreach_alloc_apm_cmd_pkt(size, APM_CMD_SET_CFG, 0); + if (IS_ERR(pkt)) + return PTR_ERR(pkt); + + memcpy((void *)pkt + GPR_HDR_SIZE + APM_CMD_HDR_SIZE, data, size); + + rc = q6apm_send_cmd_sync(graph->apm, pkt, 0); + if (rc) + dev_err(graph->dev, "%s cfg blob: chunk %d (%d bytes) failed: %d\n", + tag, chunk_idx, size, rc); + else + dev_dbg(graph->dev, "%s cfg blob: chunk %d (%d bytes) sent\n", + tag, chunk_idx, size); + + return rc; +} + +/* + * Walk the parameter records of a cfg blob. Each starts with the module's + * instance id and a param_size, followed by its payload and optional zero + * padding; a parameter smaller than a word may come without a payload word. + * Each record is checked against the end of the blob. With @dst, the records + * are copied there with their payload padded to 8 bytes, as the DSP expects. + * Returns the packed size, or -EINVAL if the blob is malformed. + */ +static int audioreach_sp_cfg_walk(const u32 *word, u32 num_words, u32 iid, + u32 first, u32 *next, u8 *dst, u32 max_bytes) +{ + u32 pos = first, bytes = 0; + + while (pos < num_words) { + u32 param_size, payload_words, avail, rec_bytes; + + if (word[pos] != iid || num_words - pos < 4) + return -EINVAL; + + param_size = word[pos + 2]; + avail = (num_words - pos - 4) * sizeof(u32); + if (param_size < sizeof(u32) && avail && word[pos + 4] == iid) { + payload_words = 0; + } else { + if (param_size > avail) + return -EINVAL; + payload_words = DIV_ROUND_UP(param_size, sizeof(u32)); + } + + rec_bytes = APM_MODULE_PARAM_DATA_SIZE + ALIGN(param_size, 8); + if (bytes && bytes + rec_bytes > max_bytes) + break; + + if (dst) { + memcpy(dst + bytes, &word[pos], APM_MODULE_PARAM_DATA_SIZE); + memset(dst + bytes + APM_MODULE_PARAM_DATA_SIZE, 0, + rec_bytes - APM_MODULE_PARAM_DATA_SIZE); + memcpy(dst + bytes + APM_MODULE_PARAM_DATA_SIZE, &word[pos + 4], + min(param_size, payload_words * (u32)sizeof(u32))); + } + bytes += rec_bytes; + + pos += 4 + payload_words; + while (pos < num_words && !word[pos]) + pos++; + } + + if (next) + *next = pos; + return bytes; +} + +static int audioreach_speaker_protection_send_static_cfg(struct q6apm_graph *graph, + const struct audioreach_module *module, + const char *tag) +{ + u32 size, num_words, pos = 0; + const u32 *word; + int total, rc = 0, chunk = 0; + + if (!module->data || !module->data->size) + return 0; + + size = le32_to_cpu(module->data->size); + word = (const u32 *)module->data->data; + num_words = size / sizeof(u32); + + /* Not laid out as parameter records, so send it as the topology built it */ + if (size % sizeof(u32) || !num_words || word[0] != module->instance_id) + return audioreach_speaker_protection_send_chunk(graph, tag, word, size, 0); + + total = audioreach_sp_cfg_walk(word, num_words, module->instance_id, 0, + NULL, NULL, U32_MAX); + if (total < 0) { + dev_err(graph->dev, "%s cfg blob is malformed\n", tag); + return total; + } + + u8 *packed __free(kfree) = kmalloc(total, GFP_KERNEL); + if (!packed) + return -ENOMEM; + + while (pos < num_words && !rc) { + int bytes = audioreach_sp_cfg_walk(word, num_words, module->instance_id, + pos, &pos, packed, + AR_SP_CFG_MAX_CHUNK_BYTES); + if (bytes <= 0) + return bytes ? bytes : -EINVAL; + + rc = audioreach_speaker_protection_send_chunk(graph, tag, packed, bytes, + chunk++); + } + + return rc; +} + +static int audioreach_speaker_protection_static_cfg(struct q6apm_graph *graph, + const struct audioreach_module *module) +{ + return audioreach_speaker_protection_send_static_cfg(graph, module, "SP"); +} + +static int audioreach_speaker_protection_vi_static_cfg(struct q6apm_graph *graph, + const struct audioreach_module *module) +{ + return audioreach_speaker_protection_send_static_cfg(graph, module, "VI"); +} + int audioreach_set_media_format(struct q6apm_graph *graph, const struct audioreach_module *module, const struct audioreach_module_config *cfg) @@ -1976,12 +2111,16 @@ int audioreach_set_media_format(struct q6apm_graph *graph, break; case MODULE_ID_SPEAKER_PROTECTION: rc = audioreach_speaker_protection(graph, module); + if (!rc) + rc = audioreach_speaker_protection_static_cfg(graph, module); if (!rc) rc = audioreach_module_enable(graph, module, true); break; case MODULE_ID_SPEAKER_PROTECTION_VI: rc = audioreach_speaker_protection_vi(graph, module, cfg); + if (!rc) + rc = audioreach_speaker_protection_vi_static_cfg(graph, module); if (!rc) rc = audioreach_module_enable(graph, module, true); -- 2.53.0