From nobody Mon Jun 8 06:36:23 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE8D139E19C for ; Mon, 1 Jun 2026 11:26:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780313212; cv=none; b=h2tHmg+jUjJV1NbFIXjS++b/ewZytdUin5ikKLi1s+RgX5aX769Vp7lgj14tXRUlYYaOAQ7lBfdnyDUJ0zqEUG/xIG0Nq4ouiePhjtJUcw5Ad2TGc52dTBQjrIHZ3sla8mnvWpAJwWjFH9LK2m0kW0qq4EgcGX2gCXN3B8oloqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780313212; c=relaxed/simple; bh=aclxZiyUV7QTw5zDhEdyjD1PaHM5hj3PBELTQWqMvuI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=nHkAKVodfHOrE2AX7GDWDtEBG0dzbFl35N584EdZf8O8EXfOLv2w9tg/5Y/n6GUNXVPrsyLkre4hQ4ShhoRVcgA3odBNdsByi2PkyQxFHVHHy2YPYeTxZUvoSzqnhoEAlGF+DI30weVIWyPPJOrxnLEh/oEkdy3K6psWF2I9734= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=XctIx1+N; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="XctIx1+N" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6514APAU3708091; Mon, 1 Jun 2026 11:26:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=pp1; bh=EHtJczlzPsaw96sfgjdcb7909B2TunaiprAsMSFmr XA=; b=XctIx1+NexJmGxqwmgdYHLMq26TR905dr9iVjd1OU4pzBWmg9SZegX0Tf LCUwhAvynbIDtBXkaLEOCnRIdJZJKPisljYK3gv3EpTz0mX8a780JrNfxK2ftzN3 vruv1JG9DaLvgGwHLjBRYfkLjFzbPp9ZupKxy+lPx9qmw9MFg8UXvKp+r3EnKm53 pDbFxFfRYjuxZIFBEqTmriDAP/vOkEnJD21zdqxO6XF/sofRTUma6Wmz3P1uICSm xbeO/nKkyABleVeRjka8/s+bTBNnn19yvbMFvs1z85wjAYaMRrq5peoncj89TqDy qo5w3bGrRlQVTc+VYysXC0kWya1Yw== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4efpae05br-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 01 Jun 2026 11:26:25 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 651BO8Tp023788; Mon, 1 Jun 2026 11:26:24 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4egbqh5qw9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 01 Jun 2026 11:26:24 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 651BQLPw57016760 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 1 Jun 2026 11:26:21 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E39CA2004F; Mon, 1 Jun 2026 11:26:20 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8D47720040; Mon, 1 Jun 2026 11:26:18 +0000 (GMT) Received: from shivang.bl1-in.ibm.com (unknown [9.123.12.247]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 1 Jun 2026 11:26:18 +0000 (GMT) From: Shivang Upadhyay To: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Cc: maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com, chleroy@kernel.org, thuth@redhat.com, Shivang Upadhyay , Aditya Gupta , Sourabh Jain , Mahesh J Salgaonkar Subject: [PATCH] powerpc/powernv: Cache OPAL check_token() results Date: Mon, 1 Jun 2026 16:55:20 +0530 Message-ID: <20260601112520.161605-1-shivangu@linux.ibm.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=Zt3d7d7G c=1 sm=1 tr=0 ts=6a1d6c62 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=FelO9ux0wxsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=pGLkceISAAAA:8 a=VwQbUJbxAAAA:8 a=cfGK7pAvqkcwuHOd0NgA:9 X-Proofpoint-GUID: 3J9yil8-VSsPEZOV2Ho9WB5emZ1dweoP X-Proofpoint-ORIG-GUID: 3cIZLfS7NjxrkyUVIx_G-P9my0RWHDrA X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNjAxMDExMSBTYWx0ZWRfX46jnKkNyDhzq emNSi1XE6BUD3PpY5BOE87ZDehswbgvXmqypZ7rJVhz14nPMnn6jKQqp+2aVSKKBz6IJFUF23ui R3u74NCpr/XtDU98M4O1uSKMGXapK+Ymco7K+WyefH/tmv/6c1vbc598vLH+wlzLcp7LMVpNSMO 6/I4O/gv62bzVzezTZL2y8VAtfOCixGxO4daRBVkqTX9nVJ0+HBbF4ykfGS6ruM2t2mNc5u7a0P 7ntF08Zrmkd+jIqetE7T99aZGweoMuyK7TAswubD0WPSSmkAa547cTQxwa3My2dDlkeoRT2ashL GPwzqMWzd+awMYwBLOqChxF3AlqFyI2UxvzZ8IlamEYhRWXivEXq3H+qjdfE/7Lyjbk4zu23/IV jD821y7IbTOd1PTCTlHq2PILwI5PD3+53e9/dF5dw1W2ezWxOxgG43GhV3eCk/Ne5qkeyRi5R+x cxl1hX31G9TwFE8rOCg== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-06-01_03,2026-05-28_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 priorityscore=1501 bulkscore=0 clxscore=1015 phishscore=0 spamscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2605210000 definitions=main-2606010111 Content-Type: text/plain; charset="utf-8" Add a caching layer for the opal_check_token() OPAL call to avoid repeated firmware calls for token availability checks. The opal_check_token() function is used to determine if a specific OPAL firmware call is supported on the current platform. This check is performed frequently during boot and runtime, resulting in unnecessary firmware calls for the same token values. This reduces firmware call overhead during boot and runtime token checks while maintaining compatibility with existing code. Testing with buildroot images shows OPAL calls reduced from 35578 to 28983, before console bring-up. Cc: Madhavan Srinivasan Cc: Nicholas Piggin Cc: Christophe Leroy Cc: Aditya Gupta Cc: Sourabh Jain Cc: Mahesh J Salgaonkar Signed-off-by: Shivang Upadhyay --- arch/powerpc/include/asm/opal.h | 1 + arch/powerpc/platforms/powernv/opal-call.c | 2 +- arch/powerpc/platforms/powernv/opal.c | 55 ++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opa= l.h index 0a398265ba04..e7e11479122b 100644 --- a/arch/powerpc/include/asm/opal.h +++ b/arch/powerpc/include/asm/opal.h @@ -156,6 +156,7 @@ int64_t opal_pci_next_error(uint64_t phb_id, __be64 *fi= rst_frozen_pe, int64_t opal_pci_poll(uint64_t id); int64_t opal_return_cpu(void); int64_t opal_check_token(uint64_t token); +int64_t opal_check_token_call(uint64_t token); int64_t opal_reinit_cpus(uint64_t flags); =20 int64_t opal_xscom_read(uint32_t gcid, uint64_t pcb_addr, __be64 *val); diff --git a/arch/powerpc/platforms/powernv/opal-call.c b/arch/powerpc/plat= forms/powernv/opal-call.c index 021b0ec29e24..00325c189e69 100644 --- a/arch/powerpc/platforms/powernv/opal-call.c +++ b/arch/powerpc/platforms/powernv/opal-call.c @@ -207,7 +207,7 @@ OPAL_CALL(opal_validate_flash, OPAL_FLASH_VALIDATE); OPAL_CALL(opal_manage_flash, OPAL_FLASH_MANAGE); OPAL_CALL(opal_update_flash, OPAL_FLASH_UPDATE); OPAL_CALL(opal_resync_timebase, OPAL_RESYNC_TIMEBASE); -OPAL_CALL(opal_check_token, OPAL_CHECK_TOKEN); +OPAL_CALL(opal_check_token_call, OPAL_CHECK_TOKEN); OPAL_CALL(opal_dump_init, OPAL_DUMP_INIT); OPAL_CALL(opal_dump_info, OPAL_DUMP_INFO); OPAL_CALL(opal_dump_info2, OPAL_DUMP_INFO2); diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms= /powernv/opal.c index 1946dbdc9fa1..c32035136efa 100644 --- a/arch/powerpc/platforms/powernv/opal.c +++ b/arch/powerpc/platforms/powernv/opal.c @@ -73,6 +73,12 @@ static struct task_struct *kopald_tsk; static struct opal_msg *opal_msg; static u32 opal_msg_size __ro_after_init; =20 +/* Token cache for opal_check_token() */ +#define OPAL_TOKEN_CACHE_SIZE 256 /* Covers tokens 0-255, including OPAL_= LAST (178) */ +static unsigned long opal_token_cache[BITS_TO_LONGS(OPAL_TOKEN_CACHE_SIZE)= ] __ro_after_init; +static bool opal_token_cache_initialized __ro_after_init; +static void opal_token_cache_init(void); + void __init opal_configure_cores(void) { u64 reinit_flags =3D 0; @@ -1125,8 +1131,57 @@ EXPORT_SYMBOL_GPL(opal_flash_read); EXPORT_SYMBOL_GPL(opal_flash_write); EXPORT_SYMBOL_GPL(opal_flash_erase); EXPORT_SYMBOL_GPL(opal_prd_msg); + +/** + * opal_check_token - Check if an OPAL call token is supported + * @token: OPAL token number to check + * + * Returns 1 if supported, 0 if not. + * Uses a cached bitmap for fast lookups after initialization. + */ +int64_t opal_check_token(uint64_t token) +{ + /* Initialize if not done before */ + if (!opal_token_cache_initialized) { + opal_token_cache_init(); + } + + /* Use cached result */ + if (token < OPAL_TOKEN_CACHE_SIZE) { + return test_bit(token, opal_token_cache); + } + + /* Fall back to direct OPAL call for out-of-range tokens */ + return opal_check_token_call(token); +} EXPORT_SYMBOL_GPL(opal_check_token); =20 +/** + * opal_token_cache_init - Initialize the OPAL token cache + * + * Called during opal_init() to populate the token cache by querying + * OPAL firmware for all tokens in the supported range. + */ +static void opal_token_cache_init(void) +{ + uint64_t token; + int64_t result; + + pr_debug("Initializing OPAL token cache\n"); + + /* Query OPAL for each token and cache the result */ + for (token =3D 0; token < OPAL_TOKEN_CACHE_SIZE; token++) { + result =3D opal_check_token_call(token); + if (result =3D=3D 1) + set_bit(token, opal_token_cache); + } + + /* Mark cache as initialized - enables fast path */ + opal_token_cache_initialized =3D true; + + pr_info("OPAL token cache initialized\n"); +} + /* Convert a region of vmalloc memory to an opal sg list */ struct opal_sg_list *opal_vmalloc_to_sg_list(void *vmalloc_addr, unsigned long vmalloc_size) --=20 2.53.0