Skip to content

Commit f592cc5

Browse files
maulik-k-shahandersson
authored andcommitted
soc: qcom: rpmh-rsc: Enhance check for VRM in-flight request
Each RPMh VRM accelerator resource has 3 or 4 contiguous 4-byte aligned addresses associated with it. These control voltage, enable state, mode, and in legacy targets, voltage headroom. The current in-flight request checking logic looks for exact address matches. Requests for different addresses of the same RPMh resource as thus not detected as in-flight. Add new cmd-db API cmd_db_match_resource_addr() to enhance the in-flight request check for VRM requests by ignoring the address offset. This ensures that only one request is allowed to be in-flight for a given VRM resource. This is needed to avoid scenarios where request commands are carried out by RPMh hardware out-of-order leading to LDO regulator over-current protection triggering. Fixes: 658628e ("drivers: qcom: rpmh-rsc: add RPMH controller for QCOM SoCs") Cc: [email protected] Reviewed-by: Konrad Dybcio <[email protected]> Tested-by: Elliot Berman <[email protected]> # sm8650-qrd Signed-off-by: Maulik Shah <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bjorn Andersson <[email protected]>
1 parent b971829 commit f592cc5

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

drivers/soc/qcom/cmd-db.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
2-
/* Copyright (c) 2016-2018, 2020, The Linux Foundation. All rights reserved. */
2+
/*
3+
* Copyright (c) 2016-2018, 2020, The Linux Foundation. All rights reserved.
4+
* Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved.
5+
*/
36

7+
#include <linux/bitfield.h>
48
#include <linux/debugfs.h>
59
#include <linux/kernel.h>
610
#include <linux/module.h>
@@ -17,6 +21,8 @@
1721
#define MAX_SLV_ID 8
1822
#define SLAVE_ID_MASK 0x7
1923
#define SLAVE_ID_SHIFT 16
24+
#define SLAVE_ID(addr) FIELD_GET(GENMASK(19, 16), addr)
25+
#define VRM_ADDR(addr) FIELD_GET(GENMASK(19, 4), addr)
2026

2127
/**
2228
* struct entry_header: header for each entry in cmddb
@@ -220,6 +226,30 @@ const void *cmd_db_read_aux_data(const char *id, size_t *len)
220226
}
221227
EXPORT_SYMBOL_GPL(cmd_db_read_aux_data);
222228

229+
/**
230+
* cmd_db_match_resource_addr() - Compare if both Resource addresses are same
231+
*
232+
* @addr1: Resource address to compare
233+
* @addr2: Resource address to compare
234+
*
235+
* Return: true if two addresses refer to the same resource, false otherwise
236+
*/
237+
bool cmd_db_match_resource_addr(u32 addr1, u32 addr2)
238+
{
239+
/*
240+
* Each RPMh VRM accelerator resource has 3 or 4 contiguous 4-byte
241+
* aligned addresses associated with it. Ignore the offset to check
242+
* for VRM requests.
243+
*/
244+
if (addr1 == addr2)
245+
return true;
246+
else if (SLAVE_ID(addr1) == CMD_DB_HW_VRM && VRM_ADDR(addr1) == VRM_ADDR(addr2))
247+
return true;
248+
249+
return false;
250+
}
251+
EXPORT_SYMBOL_GPL(cmd_db_match_resource_addr);
252+
223253
/**
224254
* cmd_db_read_slave_id - Get the slave ID for a given resource address
225255
*

drivers/soc/qcom/rpmh-rsc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22
/*
33
* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
4+
* Copyright (c) 2023-2024, Qualcomm Innovation Center, Inc. All rights reserved.
45
*/
56

67
#define pr_fmt(fmt) "%s " fmt, KBUILD_MODNAME
@@ -557,7 +558,7 @@ static int check_for_req_inflight(struct rsc_drv *drv, struct tcs_group *tcs,
557558
for_each_set_bit(j, &curr_enabled, MAX_CMDS_PER_TCS) {
558559
addr = read_tcs_cmd(drv, drv->regs[RSC_DRV_CMD_ADDR], i, j);
559560
for (k = 0; k < msg->num_cmds; k++) {
560-
if (addr == msg->cmds[k].addr)
561+
if (cmd_db_match_resource_addr(msg->cmds[k].addr, addr))
561562
return -EBUSY;
562563
}
563564
}

include/soc/qcom/cmd-db.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
2-
/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved. */
2+
/*
3+
* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
4+
* Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved.
5+
*/
36

47
#ifndef __QCOM_COMMAND_DB_H__
58
#define __QCOM_COMMAND_DB_H__
@@ -21,6 +24,8 @@ u32 cmd_db_read_addr(const char *resource_id);
2124

2225
const void *cmd_db_read_aux_data(const char *resource_id, size_t *len);
2326

27+
bool cmd_db_match_resource_addr(u32 addr1, u32 addr2);
28+
2429
enum cmd_db_hw_type cmd_db_read_slave_id(const char *resource_id);
2530

2631
int cmd_db_ready(void);
@@ -31,6 +36,9 @@ static inline u32 cmd_db_read_addr(const char *resource_id)
3136
static inline const void *cmd_db_read_aux_data(const char *resource_id, size_t *len)
3237
{ return ERR_PTR(-ENODEV); }
3338

39+
static inline bool cmd_db_match_resource_addr(u32 addr1, u32 addr2)
40+
{ return false; }
41+
3442
static inline enum cmd_db_hw_type cmd_db_read_slave_id(const char *resource_id)
3543
{ return -ENODEV; }
3644

0 commit comments

Comments
 (0)