soc: qcom: socinfo: Add APIs for part count and subpart information

Add kernel APIs to provide part count and subpart information.

Change-Id: Ie0f67555ec3561efa4832c1e0a6863f5842ccb53
Signed-off-by: Naina Mehta <quic_nainmeht@quicinc.com>
Signed-off-by: Tengfei Fan <quic_tengfan@quicinc.com>
Signed-off-by: jianzhou <quic_jianzhou@quicinc.com>
This commit is contained in:
Tengfei Fan 2023-05-18 16:29:41 +08:00 committed by Gerrit - the friendly Code Review server
parent a206f247de
commit 12d73dd3fd
2 changed files with 67 additions and 13 deletions

View File

@ -783,25 +783,70 @@ msm_get_subset_parts(struct device *dev,
}
ATTR_DEFINE(subset_parts);
int32_t
socinfo_get_subpart_info(enum subset_part_type part, uint32_t *nIdx, uint32_t *part_info)
/*
* socinfo_get_part_count - Get part count
* @part: The subset_part_type to be checked
*
* Return the number of instance supported by the
* firmware for the part on success and a negative
* errno will be returned in error cases.
*/
int
socinfo_get_part_count(enum subset_part_type part)
{
uint32_t num_parts = 0, offset = 0;
void *info = socinfo;
int part_count = 1;
if (part >= NUM_PARTS_MAX) {
/* TODO: part_count to be read from SMEM after firmware adds support */
if ((part <= PART_UNKNOWN) || (part >= NUM_PARTS_MAX)) {
pr_err("Bad part number\n");
return -EINVAL;
}
num_parts = socinfo_get_num_subset_parts();
offset = socinfo_get_nsubset_parts_array_offset();
if (!num_parts || !offset)
return part_count;
}
EXPORT_SYMBOL(socinfo_get_part_count);
/*
* socinfo_get_subpart_info - Get subpart information
* @part: The subset_part_type to be checked
* @part_info: Pointer to the subpart information.
* Used to store the subpart information
* for num_parts instances of the part.
* @num_parts: Number of instances of the part for
* which the subpart information is required.
*
* On success subpart information will be stored in the part_info
* array for minimum of the number of instances requested and
* the number of instances supported by the firmware.
*
* A value of zero will be returned on success and a negative
* errno will be returned in error cases.
*/
int
socinfo_get_subpart_info(enum subset_part_type part,
u32 *part_info,
u32 num_parts)
{
uint32_t num_subset_parts = 0, offset = 0;
void *info = socinfo;
u32 i = 0, count = 0;
int part_count = 0;
part_count = socinfo_get_part_count(part);
if (part_count <= 0)
return -EINVAL;
info += (offset + (part * sizeof(uint32_t)));
*part_info = get_unaligned_le32(info);
*nIdx = 0;
num_subset_parts = socinfo_get_num_subset_parts();
offset = socinfo_get_nsubset_parts_array_offset();
if (!num_subset_parts || !offset)
return -EINVAL;
info += (offset + (part * sizeof(u32)));
count = min_t(u32, num_parts, part_count);
for (i = 0; i < count; i++) {
part_info[i] = get_unaligned_le32(info);
info += sizeof(u32);
}
return 0;
}

View File

@ -39,7 +39,10 @@ uint32_t socinfo_get_serial_number(void);
const char *socinfo_get_id_string(void);
uint32_t socinfo_get_cluster_info(enum subset_cluster_type cluster);
bool socinfo_get_part_info(enum subset_part_type part);
int32_t socinfo_get_subpart_info(enum subset_part_type part, uint32_t *nIdx, uint32_t *part_info);
int socinfo_get_part_count(enum subset_part_type part);
int socinfo_get_subpart_info(enum subset_part_type part,
u32 *part_info,
u32 num_parts);
int socinfo_get_oem_variant_id(void);
#else
static inline uint32_t socinfo_get_id(void)
@ -65,7 +68,13 @@ bool socinfo_get_part_info(enum subset_part_type part)
{
return false;
}
int32_t socinfo_get_subpart_info(enum subset_part_type part, uint32_t *nIdx, uint32_t *part_info)
int socinfo_get_part_count(enum subset_part_type part)
{
return -EINVAL;
}
int socinfo_get_subpart_info(enum subset_part_type part,
u32 *part_info,
u32 num_parts)
{
return -EINVAL;
}