forked from Mirrors/opensbi
		
	lib: Add platform features in boot time print
We have now clear distinction between platform and hart features. Modify the boot print messages to print platform features in a string format. In the process, this patch moved relatively larger functions to its own file from platform.h header file. Signed-off-by: Atish Patra <atish.patra@wdc.com> Tested-by: Jonathan Balkind <jbalkind@cs.princeton.edu> Reviewed-by: Anup Patel <anup.patel@wdc.com>
This commit is contained in:
		@@ -56,6 +56,9 @@ enum sbi_platform_features {
 | 
			
		||||
	SBI_PLATFORM_HAS_MFAULTS_DELEGATION = (1 << 2),
 | 
			
		||||
	/** Platform has custom secondary hart booting support */
 | 
			
		||||
	SBI_PLATFORM_HAS_HART_SECONDARY_BOOT = (1 << 3),
 | 
			
		||||
 | 
			
		||||
	/** Last index of Platform features*/
 | 
			
		||||
	SBI_PLATFORM_HAS_LAST_FEATURE = SBI_PLATFORM_HAS_HART_SECONDARY_BOOT,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/** Default feature set for a platform */
 | 
			
		||||
@@ -223,6 +226,29 @@ struct sbi_platform {
 | 
			
		||||
#define sbi_platform_has_hart_secondary_boot(__p) \
 | 
			
		||||
	((__p)->features & SBI_PLATFORM_HAS_HART_SECONDARY_BOOT)
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 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);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Get the platform features in string format
 | 
			
		||||
 *
 | 
			
		||||
 * @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);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Get name of the platform
 | 
			
		||||
 *
 | 
			
		||||
@@ -237,6 +263,21 @@ static inline const char *sbi_platform_name(const struct sbi_platform *plat)
 | 
			
		||||
	return "Unknown";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Get the platform features
 | 
			
		||||
 *
 | 
			
		||||
 * @param plat pointer to struct sbi_platform
 | 
			
		||||
 *
 | 
			
		||||
 * @return the features value currently set for the given platform
 | 
			
		||||
 */
 | 
			
		||||
static inline unsigned long sbi_platform_get_features(
 | 
			
		||||
						const struct sbi_platform *plat)
 | 
			
		||||
{
 | 
			
		||||
	if (plat)
 | 
			
		||||
		return plat->features;
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Get platform specific tlb range flush maximum value. Any request with size
 | 
			
		||||
 * higher than this is upgraded to a full flush.
 | 
			
		||||
@@ -281,32 +322,6 @@ static inline u32 sbi_platform_hart_stack_size(const struct sbi_platform *plat)
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
 */
 | 
			
		||||
static inline u32 sbi_platform_hart_index(const struct sbi_platform *plat,
 | 
			
		||||
					  u32 hartid)
 | 
			
		||||
{
 | 
			
		||||
	u32 i;
 | 
			
		||||
 | 
			
		||||
	if (!plat)
 | 
			
		||||
		return -1U;
 | 
			
		||||
	if (plat->hart_index2id) {
 | 
			
		||||
		for (i = 0; i < plat->hart_count; i++) {
 | 
			
		||||
			if (plat->hart_index2id[i] == hartid)
 | 
			
		||||
				return i;
 | 
			
		||||
		}
 | 
			
		||||
		return -1U;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return hartid;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Check whether given HART is invalid
 | 
			
		||||
 *
 | 
			
		||||
 
 | 
			
		||||
@@ -31,6 +31,7 @@ libsbi-objs-y += sbi_illegal_insn.o
 | 
			
		||||
libsbi-objs-y += sbi_init.o
 | 
			
		||||
libsbi-objs-y += sbi_ipi.o
 | 
			
		||||
libsbi-objs-y += sbi_misaligned_ldst.o
 | 
			
		||||
libsbi-objs-y += sbi_platform.o
 | 
			
		||||
libsbi-objs-y += sbi_scratch.o
 | 
			
		||||
libsbi-objs-y += sbi_string.o
 | 
			
		||||
libsbi-objs-y += sbi_system.o
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,7 @@
 | 
			
		||||
#include <sbi/sbi_ipi.h>
 | 
			
		||||
#include <sbi/sbi_platform.h>
 | 
			
		||||
#include <sbi/sbi_system.h>
 | 
			
		||||
#include <sbi/sbi_string.h>
 | 
			
		||||
#include <sbi/sbi_timer.h>
 | 
			
		||||
#include <sbi/sbi_tlb.h>
 | 
			
		||||
#include <sbi/sbi_version.h>
 | 
			
		||||
@@ -34,8 +35,10 @@
 | 
			
		||||
 | 
			
		||||
static void sbi_boot_prints(struct sbi_scratch *scratch, u32 hartid)
 | 
			
		||||
{
 | 
			
		||||
	int xlen;
 | 
			
		||||
	int xlen, ret;
 | 
			
		||||
	char str[64];
 | 
			
		||||
	int max_fstr_len = 128;
 | 
			
		||||
	char features[128];
 | 
			
		||||
	const struct sbi_platform *plat = sbi_platform_ptr(scratch);
 | 
			
		||||
 | 
			
		||||
#ifdef OPENSBI_VERSION_GIT
 | 
			
		||||
@@ -59,6 +62,14 @@ static void sbi_boot_prints(struct sbi_scratch *scratch, u32 hartid)
 | 
			
		||||
	sbi_printf("Platform Name          : %s\n", sbi_platform_name(plat));
 | 
			
		||||
	sbi_printf("Platform HART Count    : %u\n",
 | 
			
		||||
		   sbi_platform_hart_count(plat));
 | 
			
		||||
 | 
			
		||||
	sbi_memset(features, 0, max_fstr_len);
 | 
			
		||||
	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 */
 | 
			
		||||
	sbi_printf("Boot HART ID           : %u\n", hartid);
 | 
			
		||||
	sbi_printf("Boot HART ISA          : %s\n", str);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										104
									
								
								lib/sbi/sbi_platform.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										104
									
								
								lib/sbi/sbi_platform.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,104 @@
 | 
			
		||||
/*
 | 
			
		||||
 * SPDX-License-Identifier: BSD-2-Clause
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright (c) 2020 Western Digital Corporation or its affiliates.
 | 
			
		||||
 *
 | 
			
		||||
 * Authors:
 | 
			
		||||
 *   Atish Patra <atish.patra@wdc.com>
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <sbi/sbi_console.h>
 | 
			
		||||
#include <sbi/sbi_platform.h>
 | 
			
		||||
#include <sbi/sbi_string.h>
 | 
			
		||||
 | 
			
		||||
static inline char *sbi_platform_feature_id2string(unsigned long feature)
 | 
			
		||||
{
 | 
			
		||||
	char *fstr = NULL;
 | 
			
		||||
 | 
			
		||||
	if (!feature)
 | 
			
		||||
		return NULL;
 | 
			
		||||
 | 
			
		||||
	switch (feature) {
 | 
			
		||||
	case SBI_PLATFORM_HAS_TIMER_VALUE:
 | 
			
		||||
		fstr = "timer";
 | 
			
		||||
		break;
 | 
			
		||||
	case SBI_PLATFORM_HAS_HART_HOTPLUG:
 | 
			
		||||
		fstr = "hotplug";
 | 
			
		||||
		break;
 | 
			
		||||
	case SBI_PLATFORM_HAS_MFAULTS_DELEGATION:
 | 
			
		||||
		fstr = "mfdeleg";
 | 
			
		||||
		break;
 | 
			
		||||
	case SBI_PLATFORM_HAS_HART_SECONDARY_BOOT:
 | 
			
		||||
		fstr = "sec_boot";
 | 
			
		||||
		break;
 | 
			
		||||
	default:
 | 
			
		||||
		break;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return fstr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Get the platform features in string format
 | 
			
		||||
 *
 | 
			
		||||
 * @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;
 | 
			
		||||
	char *temp;
 | 
			
		||||
	int offset = 0;
 | 
			
		||||
 | 
			
		||||
	if (!plat || !features_str || !nfstr)
 | 
			
		||||
		return SBI_EINVAL;
 | 
			
		||||
 | 
			
		||||
	features = sbi_platform_get_features(plat);
 | 
			
		||||
 | 
			
		||||
	do {
 | 
			
		||||
		if (features & feat) {
 | 
			
		||||
			temp = sbi_platform_feature_id2string(feat);
 | 
			
		||||
			if (temp) {
 | 
			
		||||
				sbi_snprintf(features_str + offset, nfstr,
 | 
			
		||||
					     "%s,", temp);
 | 
			
		||||
				offset = offset + sbi_strlen(temp) + 1;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		feat = feat << 1;
 | 
			
		||||
	} while (feat <= SBI_PLATFORM_HAS_LAST_FEATURE);
 | 
			
		||||
 | 
			
		||||
	features_str[offset - 1] = '\0';
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 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;
 | 
			
		||||
 | 
			
		||||
	if (!plat)
 | 
			
		||||
		return -1U;
 | 
			
		||||
	if (plat->hart_index2id) {
 | 
			
		||||
		for (i = 0; i < plat->hart_count; i++) {
 | 
			
		||||
			if (plat->hart_index2id[i] == hartid)
 | 
			
		||||
				return i;
 | 
			
		||||
		}
 | 
			
		||||
		return -1U;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return hartid;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user