forked from Mirrors/opensbi
lib: sbi: Improve get_feature_str() implementation and usage
We do following improvements for get_feature_str(): 1. We should return "none" from get_feature_str() no features available instead of sbi_boot_prints() explicitly handling failure. 2. We don't need to return failure (just like misa_xlen()) because we are returning "none" for no features and we are truncating output when space is not available. 3. Based on 1 and 2, the sbi_boot_prints() can be further simplified. 4. No need for two char[] in sbi_boot_prints() Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
This commit is contained in:
@@ -43,7 +43,7 @@ int sbi_hart_pmp_check_addr(struct sbi_scratch *scratch, unsigned long daddr,
|
|||||||
unsigned long attr);
|
unsigned long attr);
|
||||||
bool sbi_hart_has_feature(u32 hartid, unsigned long feature);
|
bool sbi_hart_has_feature(u32 hartid, unsigned long feature);
|
||||||
unsigned long sbi_hart_get_features(u32 hartid);
|
unsigned long sbi_hart_get_features(u32 hartid);
|
||||||
int sbi_hart_get_features_str(u32 hartid, char *features_str, int nfstr);
|
void sbi_hart_get_features_str(u32 hartid, char *features_str, int nfstr);
|
||||||
|
|
||||||
void __attribute__((noreturn)) sbi_hart_hang(void);
|
void __attribute__((noreturn)) sbi_hart_hang(void);
|
||||||
|
|
||||||
|
@@ -244,10 +244,9 @@ u32 sbi_platform_hart_index(const struct sbi_platform *plat, u32 hartid);
|
|||||||
* updated
|
* updated
|
||||||
* @param nfstr length of the features_str. The feature string will be truncated
|
* @param nfstr length of the features_str. The feature string will be truncated
|
||||||
* if nfstr is not long enough.
|
* if nfstr is not long enough.
|
||||||
* @return the features value currently set for the given platform
|
|
||||||
*/
|
*/
|
||||||
int sbi_platform_get_features_str(const struct sbi_platform *plat,
|
void sbi_platform_get_features_str(const struct sbi_platform *plat,
|
||||||
char *features_str, int nfstr);
|
char *features_str, int nfstr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get name of the platform
|
* Get name of the platform
|
||||||
|
@@ -270,18 +270,20 @@ static inline char *sbi_hart_feature_id2string(unsigned long feature)
|
|||||||
* updated
|
* updated
|
||||||
* @param nfstr length of the features_str. The feature string will be truncated
|
* @param nfstr length of the features_str. The feature string will be truncated
|
||||||
* if nfstr is not long enough.
|
* if nfstr is not long enough.
|
||||||
* @return the features value currently set for the given platform
|
|
||||||
*/
|
*/
|
||||||
int sbi_hart_get_features_str(u32 hartid, char *features_str, int nfstr)
|
void sbi_hart_get_features_str(u32 hartid, char *features_str, int nfstr)
|
||||||
{
|
{
|
||||||
unsigned long features, feat = 1UL;
|
unsigned long features, feat = 1UL;
|
||||||
char *temp;
|
char *temp;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
if (!features_str || !nfstr)
|
if (!features_str || nfstr <= 0)
|
||||||
return SBI_EINVAL;
|
return;
|
||||||
|
sbi_memset(features_str, 0, nfstr);
|
||||||
|
|
||||||
features = sbi_hart_get_features(hartid);
|
features = sbi_hart_get_features(hartid);
|
||||||
|
if (!features)
|
||||||
|
goto done;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (features & feat) {
|
if (features & feat) {
|
||||||
@@ -295,9 +297,11 @@ int sbi_hart_get_features_str(u32 hartid, char *features_str, int nfstr)
|
|||||||
feat = feat << 1;
|
feat = feat << 1;
|
||||||
} while (feat <= SBI_HART_HAS_LAST_FEATURE);
|
} while (feat <= SBI_HART_HAS_LAST_FEATURE);
|
||||||
|
|
||||||
features_str[offset - 1] = '\0';
|
done:
|
||||||
|
if (offset)
|
||||||
return 0;
|
features_str[offset - 1] = '\0';
|
||||||
|
else
|
||||||
|
sbi_strncpy(features_str, "none", nfstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sbi_hart_set_feature(u32 hartid, unsigned long feature)
|
static void sbi_hart_set_feature(u32 hartid, unsigned long feature)
|
||||||
|
@@ -35,10 +35,8 @@
|
|||||||
|
|
||||||
static void sbi_boot_prints(struct sbi_scratch *scratch, u32 hartid)
|
static void sbi_boot_prints(struct sbi_scratch *scratch, u32 hartid)
|
||||||
{
|
{
|
||||||
int xlen, ret;
|
int xlen;
|
||||||
char str[64];
|
char str[128];
|
||||||
int max_fstr_len = 128;
|
|
||||||
char features[128];
|
|
||||||
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
|
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
|
||||||
|
|
||||||
#ifdef OPENSBI_VERSION_GIT
|
#ifdef OPENSBI_VERSION_GIT
|
||||||
@@ -56,35 +54,26 @@ static void sbi_boot_prints(struct sbi_scratch *scratch, u32 hartid)
|
|||||||
sbi_printf("Error %d getting MISA XLEN\n", xlen);
|
sbi_printf("Error %d getting MISA XLEN\n", xlen);
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
}
|
}
|
||||||
misa_string(xlen, str, sizeof(str));
|
|
||||||
|
|
||||||
/* Platform details */
|
/* Platform details */
|
||||||
sbi_printf("Platform Name : %s\n", sbi_platform_name(plat));
|
sbi_printf("Platform Name : %s\n", sbi_platform_name(plat));
|
||||||
sbi_printf("Platform HART Count : %u\n",
|
sbi_printf("Platform HART Count : %u\n",
|
||||||
sbi_platform_hart_count(plat));
|
sbi_platform_hart_count(plat));
|
||||||
|
sbi_platform_get_features_str(plat, str, sizeof(str));
|
||||||
sbi_memset(features, 0, max_fstr_len);
|
sbi_printf("Platform Features : %s\n", str);
|
||||||
ret = sbi_platform_get_features_str(plat, features, max_fstr_len);
|
|
||||||
if (!ret)
|
|
||||||
sbi_printf("Platform Features : %s\n", features);
|
|
||||||
else
|
|
||||||
sbi_printf("Platform Features : %s\n", "none");
|
|
||||||
|
|
||||||
/* Boot HART details */
|
/* Boot HART details */
|
||||||
sbi_printf("Boot HART ID : %u\n", hartid);
|
sbi_printf("Boot HART ID : %u\n", hartid);
|
||||||
|
misa_string(xlen, str, sizeof(str));
|
||||||
sbi_printf("Boot HART ISA : %s\n", str);
|
sbi_printf("Boot HART ISA : %s\n", str);
|
||||||
|
sbi_hart_get_features_str(hartid, str, sizeof(str));
|
||||||
sbi_memset(features, 0, max_fstr_len);
|
sbi_printf("BOOT HART Features : %s\n", str);
|
||||||
ret = sbi_hart_get_features_str(hartid, features, max_fstr_len);
|
|
||||||
if (!ret)
|
|
||||||
sbi_printf("BOOT HART Features : %s\n", features);
|
|
||||||
else
|
|
||||||
sbi_printf("BOOT HART Features : %s\n", "none");
|
|
||||||
|
|
||||||
/* Firmware details */
|
/* Firmware details */
|
||||||
sbi_printf("Firmware Base : 0x%lx\n", scratch->fw_start);
|
sbi_printf("Firmware Base : 0x%lx\n", scratch->fw_start);
|
||||||
sbi_printf("Firmware Size : %d KB\n",
|
sbi_printf("Firmware Size : %d KB\n",
|
||||||
(u32)(scratch->fw_size / 1024));
|
(u32)(scratch->fw_size / 1024));
|
||||||
|
|
||||||
/* Generic details */
|
/* Generic details */
|
||||||
sbi_printf("Runtime SBI Version : %d.%d\n",
|
sbi_printf("Runtime SBI Version : %d.%d\n",
|
||||||
sbi_ecall_version_major(), sbi_ecall_version_minor());
|
sbi_ecall_version_major(), sbi_ecall_version_minor());
|
||||||
|
@@ -38,27 +38,20 @@ static inline char *sbi_platform_feature_id2string(unsigned long feature)
|
|||||||
return fstr;
|
return fstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void sbi_platform_get_features_str(const struct sbi_platform *plat,
|
||||||
* Get the platform features in string format
|
char *features_str, int nfstr)
|
||||||
*
|
|
||||||
* @param plat pointer to struct sbi_platform
|
|
||||||
* @param features_str pointer to a char array where the features string will be
|
|
||||||
* updated
|
|
||||||
* @param nfstr length of the features_str. The feature string will be truncated
|
|
||||||
* if nfstr is not long enough.
|
|
||||||
* @return the features value currently set for the given platform
|
|
||||||
*/
|
|
||||||
int sbi_platform_get_features_str(const struct sbi_platform *plat,
|
|
||||||
char *features_str, int nfstr)
|
|
||||||
{
|
{
|
||||||
unsigned long features, feat = 1UL;
|
unsigned long features, feat = 1UL;
|
||||||
char *temp;
|
char *temp;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
if (!plat || !features_str || !nfstr)
|
if (!plat || !features_str || !nfstr)
|
||||||
return SBI_EINVAL;
|
return;
|
||||||
|
sbi_memset(features_str, 0, nfstr);
|
||||||
|
|
||||||
features = sbi_platform_get_features(plat);
|
features = sbi_platform_get_features(plat);
|
||||||
|
if (!features)
|
||||||
|
goto done;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (features & feat) {
|
if (features & feat) {
|
||||||
@@ -72,21 +65,14 @@ int sbi_platform_get_features_str(const struct sbi_platform *plat,
|
|||||||
feat = feat << 1;
|
feat = feat << 1;
|
||||||
} while (feat <= SBI_PLATFORM_HAS_LAST_FEATURE);
|
} while (feat <= SBI_PLATFORM_HAS_LAST_FEATURE);
|
||||||
|
|
||||||
features_str[offset - 1] = '\0';
|
done:
|
||||||
|
if (offset)
|
||||||
return 0;
|
features_str[offset - 1] = '\0';
|
||||||
|
else
|
||||||
|
sbi_strncpy(features_str, "none", nfstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
u32 sbi_platform_hart_index(const struct sbi_platform *plat, u32 hartid)
|
||||||
* Get HART index for the given HART
|
|
||||||
*
|
|
||||||
* @param plat pointer to struct sbi_platform
|
|
||||||
* @param hartid HART ID
|
|
||||||
*
|
|
||||||
* @return 0 <= value < hart_count for valid HART otherwise -1U
|
|
||||||
*/
|
|
||||||
u32 sbi_platform_hart_index(const struct sbi_platform *plat,
|
|
||||||
u32 hartid)
|
|
||||||
{
|
{
|
||||||
u32 i;
|
u32 i;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user