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>
This commit is contained in:
Abner Chang
2019-06-29 16:18:05 +08:00
committed by Anup Patel
parent fa6fd6bf86
commit 08b196956d
10 changed files with 55 additions and 13 deletions

View File

@@ -63,8 +63,8 @@ export libsbiutils_dir=$(CURDIR)/lib/utils
export firmware_dir=$(CURDIR)/firmware export firmware_dir=$(CURDIR)/firmware
# Find library version # Find library version
OPENSBI_VERSION_MAJOR=`grep MAJOR $(include_dir)/sbi/sbi_version.h | sed 's/.*MAJOR.*\([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 MINOR $(include_dir)/sbi/sbi_version.h | sed 's/.*MINOR.*\([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 # Setup compilation commands
ifdef CROSS_COMPILE ifdef CROSS_COMPILE

View File

@@ -10,21 +10,32 @@
#ifndef __SBI_PLATFORM_H__ #ifndef __SBI_PLATFORM_H__
#define __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 */ /** 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 */ /** 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 */ /** 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 */ /** 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 */ /** 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 */ /** Offset of platform_ops_addr in struct sbi_platform */
#define SBI_PLATFORM_OPS_OFFSET (0x58) #define SBI_PLATFORM_OPS_OFFSET (0x60)
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
#include <sbi/sbi_version.h>
#include <sbi/sbi_scratch.h> #include <sbi/sbi_scratch.h>
/** Possible feature flags of a platform */ /** Possible feature flags of a platform */
@@ -101,6 +112,18 @@ struct sbi_platform_operations {
/** Representation of a platform */ /** Representation of a platform */
struct sbi_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 */ /** Name of the platform */
char name[64]; char name[64];
/** Supported features */ /** Supported features */
@@ -119,9 +142,8 @@ struct sbi_platform {
#define sbi_platform_ptr(__s) \ #define sbi_platform_ptr(__s) \
((const struct sbi_platform *)((__s)->platform_addr)) ((const struct sbi_platform *)((__s)->platform_addr))
/** Get pointer to sbi_platform for current HART */ /** Get pointer to sbi_platform for current HART */
#define sbi_platform_thishart_ptr() \ #define sbi_platform_thishart_ptr() ((const struct sbi_platform *) \
((const struct sbi_platform *)(sbi_scratch_thishart_ptr() \ (sbi_scratch_thishart_ptr()->platform_addr))
>platform_addr))
/** Get pointer to platform_ops_addr from platform pointer **/ /** Get pointer to platform_ops_addr from platform pointer **/
#define sbi_platform_ops(__p) \ #define sbi_platform_ops(__p) \
((const struct sbi_platform_operations *)(__p)->platform_ops_addr) ((const struct sbi_platform_operations *)(__p)->platform_ops_addr)

View File

@@ -13,4 +13,12 @@
#define OPENSBI_VERSION_MAJOR 0 #define OPENSBI_VERSION_MAJOR 0
#define OPENSBI_VERSION_MINOR 3 #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 #endif

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -74,8 +74,8 @@ if [ -z "${BUILD_ARCHIVE_SUFFIX}" ]; then
fi fi
# Get version of OpenSBI # 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_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 MINOR "${BUILD_OPENSBI_SOURCE_PATH}/include/sbi/sbi_version.h" | sed 's/.*MINOR.*\([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 # Setup archive name
BUILD_ARCHIVE_NAME="opensbi-${BUILD_VERSION_MAJOR}.${BUILD_VERSION_MINOR}-rv${BUILD_RISCV_XLEN}-${BUILD_ARCHIVE_SUFFIX}" BUILD_ARCHIVE_NAME="opensbi-${BUILD_VERSION_MAJOR}.${BUILD_VERSION_MINOR}-rv${BUILD_RISCV_XLEN}-${BUILD_ARCHIVE_SUFFIX}"