Parcourir la source

include: Add version info to struct sbi_platform

Add version control of sbi_platform structure
- Add opensbi_version, this gives information of opensbi revision on
which the sbi_platform table was created.
- Add platform_version field in sbi_platform structure for platform
level version control.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Acked-by: Anup Patel <anup.patel@wdc.com>
Abner Chang il y a 5 ans
Parent
commit
08b196956d

+ 2 - 2
Makefile

@@ -63,8 +63,8 @@ export libsbiutils_dir=$(CURDIR)/lib/utils
 export firmware_dir=$(CURDIR)/firmware
 
 # Find library version
-OPENSBI_VERSION_MAJOR=`grep MAJOR $(include_dir)/sbi/sbi_version.h | sed 's/.*MAJOR.*\([0-9][0-9]*\)/\1/'`
-OPENSBI_VERSION_MINOR=`grep MINOR $(include_dir)/sbi/sbi_version.h | sed 's/.*MINOR.*\([0-9][0-9]*\)/\1/'`
+OPENSBI_VERSION_MAJOR=`grep "define OPENSBI_VERSION_MAJOR" $(include_dir)/sbi/sbi_version.h | sed 's/.*MAJOR.*\([0-9][0-9]*\)/\1/'`
+OPENSBI_VERSION_MINOR=`grep "define OPENSBI_VERSION_MINOR" $(include_dir)/sbi/sbi_version.h | sed 's/.*MINOR.*\([0-9][0-9]*\)/\1/'`
 
 # Setup compilation commands
 ifdef CROSS_COMPILE

+ 31 - 9
include/sbi/sbi_platform.h

@@ -10,21 +10,32 @@
 #ifndef __SBI_PLATFORM_H__
 #define __SBI_PLATFORM_H__
 
+/** OpenSBI 32-bit platform version with:
+ *  1. upper 16-bits as major number
+ *  2. lower 16-bits as minor number
+ */
+#define SBI_PLATFORM_VERSION(Major, Minor) ((Major << 16) | Minor)
+
+/** Offset of opensbi_version in struct sbi_platform */
+#define SBI_PLATFORM_OPENSBI_VERSION_OFFSET (0x00)
+/** Offset of platform_version in struct sbi_platform */
+#define SBI_PLATFORM_VERSION_OFFSET (0x04)
 /** Offset of name in struct sbi_platform */
-#define SBI_PLATFORM_NAME_OFFSET (0x0)
+#define SBI_PLATFORM_NAME_OFFSET (0x08)
 /** Offset of features in struct sbi_platform */
-#define SBI_PLATFORM_FEATURES_OFFSET (0x40)
+#define SBI_PLATFORM_FEATURES_OFFSET (0x48)
 /** Offset of hart_count in struct sbi_platform */
-#define SBI_PLATFORM_HART_COUNT_OFFSET (0x48)
+#define SBI_PLATFORM_HART_COUNT_OFFSET (0x50)
 /** Offset of hart_stack_size in struct sbi_platform */
-#define SBI_PLATFORM_HART_STACK_SIZE_OFFSET (0x4c)
+#define SBI_PLATFORM_HART_STACK_SIZE_OFFSET (0x54)
 /** Offset of disabled_hart_mask in struct sbi_platform */
-#define SBI_PLATFORM_DISABLED_HART_OFFSET (0x50)
+#define SBI_PLATFORM_DISABLED_HART_OFFSET (0x58)
 /** Offset of platform_ops_addr in struct sbi_platform */
-#define SBI_PLATFORM_OPS_OFFSET (0x58)
+#define SBI_PLATFORM_OPS_OFFSET (0x60)
 
 #ifndef __ASSEMBLY__
 
+#include <sbi/sbi_version.h>
 #include <sbi/sbi_scratch.h>
 
 /** Possible feature flags of a platform */
@@ -101,6 +112,18 @@ struct sbi_platform_operations {
 
 /** Representation of a platform */
 struct sbi_platform {
+	/**
+	 * OpenSBI version this sbi_platform is based on.
+	 * It's a 32-bit value where upper 16-bits are major number
+	 * and lower 16-bits are minor number
+	 */
+	u32 opensbi_version;
+	/**
+	 * OpenSBI platform version released by vendor.
+	 * It's a 32-bit value where upper 16-bits are major number
+	 * and lower 16-bits are minor number
+	 */
+	u32 platform_version;
 	/** Name of the platform */
 	char name[64];
 	/** Supported features */
@@ -119,9 +142,8 @@ struct sbi_platform {
 #define sbi_platform_ptr(__s) \
 	((const struct sbi_platform *)((__s)->platform_addr))
 /** Get pointer to sbi_platform for current HART */
-#define sbi_platform_thishart_ptr()                               \
-	((const struct sbi_platform *)(sbi_scratch_thishart_ptr() \
-						>platform_addr))
+#define sbi_platform_thishart_ptr() ((const struct sbi_platform *) \
+	(sbi_scratch_thishart_ptr()->platform_addr))
 /** Get pointer to platform_ops_addr from platform pointer **/
 #define sbi_platform_ops(__p) \
 	((const struct sbi_platform_operations *)(__p)->platform_ops_addr)

+ 8 - 0
include/sbi/sbi_version.h

@@ -13,4 +13,12 @@
 #define OPENSBI_VERSION_MAJOR 0
 #define OPENSBI_VERSION_MINOR 3
 
+/**
+ *  OpenSBI 32-bit version with:
+ *  1. upper 16-bits as major number
+ *  2. lower 16-bits as minor number
+ */
+#define OPENSBI_VERSION ((OPENSBI_VERSION_MAJOR << 16) | \
+			 (OPENSBI_VERSION_MINOR))
+
 #endif

+ 2 - 0
platform/ariane-fpga/platform.c

@@ -196,6 +196,8 @@ const struct sbi_platform_operations platform_ops = {
 };
 
 const struct sbi_platform platform = {
+	.opensbi_version = OPENSBI_VERSION,
+	.platform_version = SBI_PLATFORM_VERSION(0x0, 0x01),
 	.name = "ARIANE RISC-V",
 	.features = SBI_ARIANE_FEATURES,
 	.hart_count = ARIANE_HART_COUNT,

+ 2 - 0
platform/kendryte/k210/platform.c

@@ -115,6 +115,8 @@ const struct sbi_platform_operations platform_ops = {
 };
 
 const struct sbi_platform platform = {
+	.opensbi_version	= OPENSBI_VERSION,
+	.platform_version   	= SBI_PLATFORM_VERSION(0x0, 0x01),
 	.name			= "Kendryte K210",
 	.features		= SBI_PLATFORM_HAS_TIMER_VALUE,
 	.hart_count		= K210_HART_COUNT,

+ 2 - 0
platform/qemu/sifive_u/platform.c

@@ -148,6 +148,8 @@ const struct sbi_platform_operations platform_ops = {
 };
 
 const struct sbi_platform platform = {
+	.opensbi_version	= OPENSBI_VERSION,
+	.platform_version	= SBI_PLATFORM_VERSION(0x0, 0x01),
 	.name			= "QEMU SiFive Unleashed",
 	.features		= SBI_PLATFORM_DEFAULT_FEATURES,
 	.hart_count		= SIFIVE_U_HART_COUNT,

+ 2 - 0
platform/qemu/virt/platform.c

@@ -153,6 +153,8 @@ const struct sbi_platform_operations platform_ops = {
 };
 
 const struct sbi_platform platform = {
+	.opensbi_version	= OPENSBI_VERSION,
+	.platform_version	= SBI_PLATFORM_VERSION(0x0, 0x01),
 	.name			= "QEMU Virt Machine",
 	.features		= SBI_PLATFORM_DEFAULT_FEATURES,
 	.hart_count		= VIRT_HART_COUNT,

+ 2 - 0
platform/sifive/fu540/platform.c

@@ -209,6 +209,8 @@ const struct sbi_platform_operations platform_ops = {
 };
 
 const struct sbi_platform platform = {
+	.opensbi_version	= OPENSBI_VERSION,
+	.platform_version	= SBI_PLATFORM_VERSION(0x0, 0x01),
 	.name			= "SiFive Freedom U540",
 	.features		= SBI_PLATFORM_DEFAULT_FEATURES,
 	.hart_count		= FU540_HART_COUNT,

+ 2 - 0
platform/template/platform.c

@@ -227,6 +227,8 @@ const struct sbi_platform_operations platform_ops = {
 	.system_shutdown	= platform_system_down
 };
 const struct sbi_platform platform = {
+	.opensbi_version	= OPENSBI_VERSION,
+	.platform_version	= SBI_PLATFORM_VERSION(0x0, 0x00),
 	.name			= "platform-name",
 	.features		= SBI_PLATFORM_DEFAULT_FEATURES,
 	.hart_count		= 1,

+ 2 - 2
scripts/create-binary-archive.sh

@@ -74,8 +74,8 @@ if [ -z "${BUILD_ARCHIVE_SUFFIX}" ]; then
 fi
 
 # Get version of OpenSBI
-BUILD_VERSION_MAJOR=$(grep MAJOR "${BUILD_OPENSBI_SOURCE_PATH}/include/sbi/sbi_version.h" | sed 's/.*MAJOR.*\([0-9][0-9]*\)/\1/')
-BUILD_VERSION_MINOR=$(grep MINOR "${BUILD_OPENSBI_SOURCE_PATH}/include/sbi/sbi_version.h" | sed 's/.*MINOR.*\([0-9][0-9]*\)/\1/')
+BUILD_VERSION_MAJOR=$(grep "define OPENSBI_VERSION_MAJOR" "${BUILD_OPENSBI_SOURCE_PATH}/include/sbi/sbi_version.h" | sed 's/.*MAJOR.*\([0-9][0-9]*\)/\1/')
+BUILD_VERSION_MINOR=$(grep "define OPENSBI_VERSION_MINOR" "${BUILD_OPENSBI_SOURCE_PATH}/include/sbi/sbi_version.h" | sed 's/.*MINOR.*\([0-9][0-9]*\)/\1/')
 
 # Setup archive name
 BUILD_ARCHIVE_NAME="opensbi-${BUILD_VERSION_MAJOR}.${BUILD_VERSION_MINOR}-rv${BUILD_RISCV_XLEN}-${BUILD_ARCHIVE_SUFFIX}"