Compare commits
350 Commits
v1.0
...
sg2042-dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
adc7ba17f3 | ||
|
|
6eef399cfc | ||
|
|
506f47f9fa | ||
|
|
3745939ceb | ||
|
|
44fdaafcb4 | ||
|
|
a82a033c74 | ||
|
|
270f27b81b | ||
|
|
f89d688f60 | ||
|
|
4826e4f743 | ||
|
|
d06c0a7858 | ||
|
|
d21bf89240 | ||
|
|
9af30e56df | ||
|
|
d0b705e19c | ||
|
|
546bc50f9a | ||
|
|
4aab6f3263 | ||
|
|
e1d3b68eeb | ||
|
|
19622b6c93 | ||
|
|
60142dc80c | ||
|
|
31087f36d7 | ||
|
|
58f9b858c5 | ||
|
|
be6e558f66 | ||
|
|
0e87f899c3 | ||
|
|
0b5c942ee9 | ||
|
|
64fb41e927 | ||
|
|
b210bc000c | ||
|
|
35fb234d39 | ||
|
|
c6a092cd80 | ||
|
|
e8e9ed3790 | ||
|
|
d56049e299 | ||
|
|
c631a7da27 | ||
|
|
57d3aa3b0d | ||
|
|
641d2e9f38 | ||
|
|
b51ddffcc0 | ||
|
|
548e4b4b28 | ||
|
|
60c358e677 | ||
|
|
51951d9e9a | ||
|
|
1fe8dc9955 | ||
|
|
506144f398 | ||
|
|
568ea49490 | ||
|
|
e9d08bd99c | ||
|
|
4b28afc98b | ||
|
|
908be1b85c | ||
|
|
5ccebf0a7e | ||
|
|
37558dccbe | ||
|
|
7c964e279c | ||
|
|
c9917b6108 | ||
|
|
73623a0aca | ||
|
|
8a40306371 | ||
|
|
07673fc063 | ||
|
|
b1ae6ef33b | ||
|
|
c88e039ec2 | ||
|
|
40f16a81d3 | ||
|
|
1364d5adb2 | ||
|
|
17b3776c81 | ||
|
|
bc06ff65bf | ||
|
|
5a75f5309c | ||
|
|
67b2a40892 | ||
|
|
2491242282 | ||
|
|
c10095132a | ||
|
|
31b82e0d50 | ||
|
|
81adc62f45 | ||
|
|
30ea8069f4 | ||
|
|
4f2be40102 | ||
|
|
6861ee996c | ||
|
|
99d09b601e | ||
|
|
745aaecc64 | ||
|
|
aafcc90a87 | ||
|
|
321293c644 | ||
|
|
65c2190b47 | ||
|
|
29285aead0 | ||
|
|
c43903c4ea | ||
|
|
5a41a3884f | ||
|
|
eab48c33a1 | ||
|
|
4e0572f57b | ||
|
|
0ee3a86fed | ||
|
|
e3bf1afcc5 | ||
|
|
aa5dafcb5b | ||
|
|
b224ddb41f | ||
|
|
680bea02bf | ||
|
|
09b34d8cca | ||
|
|
642f3de9b9 | ||
|
|
66b0e23a0c | ||
|
|
199189bd1c | ||
|
|
84d15f4f52 | ||
|
|
8050081f68 | ||
|
|
c8ea836ee3 | ||
|
|
c45992cc2b | ||
|
|
33bf917460 | ||
|
|
dea0922f86 | ||
|
|
230278dcf1 | ||
|
|
b666760bfa | ||
|
|
c10e3fe5f9 | ||
|
|
2f40a99c9e | ||
|
|
fefa548803 | ||
|
|
a990309fa3 | ||
|
|
7aaeeab9e7 | ||
|
|
787296ae92 | ||
|
|
9c4eb3521e | ||
|
|
b1818ee244 | ||
|
|
8ecbe6d3fb | ||
|
|
ce2a834c98 | ||
|
|
da5594bf85 | ||
|
|
001106d19b | ||
|
|
59a08cd7d6 | ||
|
|
3e2f573e70 | ||
|
|
20646e0184 | ||
|
|
44f736c96e | ||
|
|
1ac14f10f6 | ||
|
|
22dbdb3d60 | ||
|
|
aace1e145d | ||
|
|
9e0ba09076 | ||
|
|
9e397e3960 | ||
|
|
6997552ea2 | ||
|
|
8020df8733 | ||
|
|
cb7e7c3325 | ||
|
|
6957ae0e91 | ||
|
|
f14595a7cf | ||
|
|
65638f8d6b | ||
|
|
6509127ad6 | ||
|
|
440fa818fb | ||
|
|
6b5188ca14 | ||
|
|
d5d12a91d1 | ||
|
|
0412460baf | ||
|
|
391ec85875 | ||
|
|
b848d8763a | ||
|
|
ca7810aecd | ||
|
|
a8ee82cd8c | ||
|
|
9a2eeb4aae | ||
|
|
fabbc00668 | ||
|
|
91c8a7d5ce | ||
|
|
8509e46ca6 | ||
|
|
34da6638ad | ||
|
|
7a3354ac15 | ||
|
|
8b1617d13a | ||
|
|
684090272a | ||
|
|
0021b43737 | ||
|
|
64e8b9f72e | ||
|
|
506928a1be | ||
|
|
cb568b9b29 | ||
|
|
7b087781c2 | ||
|
|
c2be21432c | ||
|
|
8b00be6927 | ||
|
|
ed8b8f5254 | ||
|
|
e1a0cb062a | ||
|
|
e9775120f5 | ||
|
|
4640d041d3 | ||
|
|
d3fcff77a1 | ||
|
|
6cd4b9b223 | ||
|
|
a36d455182 | ||
|
|
cfbabb9ec6 | ||
|
|
ad2ac29263 | ||
|
|
1f6866e015 | ||
|
|
5daa0ef087 | ||
|
|
e9bc7f1757 | ||
|
|
cc54184619 | ||
|
|
f8eec91de8 | ||
|
|
fc82e84329 | ||
|
|
74e20293c4 | ||
|
|
49b0e355e6 | ||
|
|
ba32021683 | ||
|
|
9a740f5c46 | ||
|
|
1b0d71bb9f | ||
|
|
8e63716c1c | ||
|
|
14f5c4cb4d | ||
|
|
7b29264f11 | ||
|
|
8e9966c1a7 | ||
|
|
21ba418f1a | ||
|
|
85cf56c159 | ||
|
|
22f38ee6c6 | ||
|
|
56bed1a0fe | ||
|
|
9d54f431e8 | ||
|
|
51acd4956a | ||
|
|
0fee0bf826 | ||
|
|
d682a0afa1 | ||
|
|
c8683c57f6 | ||
|
|
ce7c490719 | ||
|
|
6f3258e671 | ||
|
|
127a3f2ab4 | ||
|
|
8234fc1bdf | ||
|
|
ef9f02e7fb | ||
|
|
88f58a3694 | ||
|
|
9899b59beb | ||
|
|
bd7ef41398 | ||
|
|
dcdaf30274 | ||
|
|
60b78fee92 | ||
|
|
11d14ae7f2 | ||
|
|
98aa12738d | ||
|
|
b6e520b2a8 | ||
|
|
2f63f2465c | ||
|
|
4f2acb53e2 | ||
|
|
c316fa38c2 | ||
|
|
e54cb3298b | ||
|
|
3f3d401d2d | ||
|
|
7105c189f6 | ||
|
|
7f09fba86e | ||
|
|
49372f2691 | ||
|
|
8ce486a781 | ||
|
|
46e744ab67 | ||
|
|
37a0d83b6d | ||
|
|
19664f6757 | ||
|
|
d32b0a92db | ||
|
|
5019fd124b | ||
|
|
ee69f8eeb3 | ||
|
|
d10c1f4acd | ||
|
|
c9b388d578 | ||
|
|
e238459fab | ||
|
|
1664d0efce | ||
|
|
a90cf6b186 | ||
|
|
622cc5f014 | ||
|
|
cbaa9b0333 | ||
|
|
adf44b51ba | ||
|
|
111afc1230 | ||
|
|
a69eb6cc65 | ||
|
|
5a0ca098f1 | ||
|
|
1c4ce74f51 | ||
|
|
1fbe7778c9 | ||
|
|
9529e360df | ||
|
|
a6a85579b6 | ||
|
|
0723bab8fe | ||
|
|
eccb9df5cf | ||
|
|
bc317a378f | ||
|
|
d514a8f0dc | ||
|
|
68d7b85ec7 | ||
|
|
5616aa4f4a | ||
|
|
b126ce4a8f | ||
|
|
0b1cf2f645 | ||
|
|
76af9d40da | ||
|
|
013dbb3a60 | ||
|
|
3e76a607b5 | ||
|
|
2adc94b466 | ||
|
|
26bbff5f76 | ||
|
|
de80e9337d | ||
|
|
662e631cce | ||
|
|
422f0e0486 | ||
|
|
b9edf49b67 | ||
|
|
f27203525a | ||
|
|
7198e1d06f | ||
|
|
7d28d3be50 | ||
|
|
8e86b23db9 | ||
|
|
11c0008862 | ||
|
|
860a376817 | ||
|
|
83db3af5f9 | ||
|
|
1545afd342 | ||
|
|
88b790f129 | ||
|
|
4e21ccacd1 | ||
|
|
0374ccf3f1 | ||
|
|
caa5eeacac | ||
|
|
994c8cfb29 | ||
|
|
4489876e93 | ||
|
|
3f66465fb6 | ||
|
|
c6fdbcf83f | ||
|
|
6f1fe98c2f | ||
|
|
d76a196bfc | ||
|
|
7738345396 | ||
|
|
c6530012d4 | ||
|
|
a07402ac9c | ||
|
|
187127fb89 | ||
|
|
551c70c040 | ||
|
|
9dc5ec5c51 | ||
|
|
5e5675874c | ||
|
|
69be3dff9d | ||
|
|
2b79b694a8 | ||
|
|
415ecf28f7 | ||
|
|
8c362e7d06 | ||
|
|
2ea7799d56 | ||
|
|
79e42eb2d6 | ||
|
|
b20ed9febe | ||
|
|
ce1d6188a2 | ||
|
|
adc3388d76 | ||
|
|
cb8271c8e4 | ||
|
|
ff65bfec4e | ||
|
|
295e5f3c69 | ||
|
|
fab0379bb6 | ||
|
|
f067bb84cf | ||
|
|
1bc67db80c | ||
|
|
575bb4e8ca | ||
|
|
616da52e18 | ||
|
|
90a9dd2b22 | ||
|
|
851c14d455 | ||
|
|
9a7a677d5f | ||
|
|
a3a3c60b66 | ||
|
|
4eacd8229b | ||
|
|
998ed43fde | ||
|
|
4ee0c57969 | ||
|
|
3a69d12fc3 | ||
|
|
bfeb305e0f | ||
|
|
1e62705adc | ||
|
|
73cf511914 | ||
|
|
7fb474b9dd | ||
|
|
f726f2dc01 | ||
|
|
023f0ad2d9 | ||
|
|
994ace30f7 | ||
|
|
be4903ae00 | ||
|
|
cad6c91045 | ||
|
|
a6ab94fdbf | ||
|
|
97a17c2e5c | ||
|
|
dbc3d8f0ef | ||
|
|
d4b563c881 | ||
|
|
5b8b377178 | ||
|
|
5a6be99cc5 | ||
|
|
1a754bb365 | ||
|
|
b0c9df514b | ||
|
|
e576b3e620 | ||
|
|
474a9d4555 | ||
|
|
d62f6da062 | ||
|
|
4035ae94be | ||
|
|
9cd95e13bb | ||
|
|
c1e47d0c3f | ||
|
|
5c5cbb53a4 | ||
|
|
3383d6a4d1 | ||
|
|
d44568a0f2 | ||
|
|
499601a4ff | ||
|
|
794986f87f | ||
|
|
47d676570d | ||
|
|
31fecad46d | ||
|
|
722f80d8e9 | ||
|
|
7924a0b220 | ||
|
|
1b42d3ace3 | ||
|
|
555bdb1cf3 | ||
|
|
d552fc8d36 | ||
|
|
b6b7220a47 | ||
|
|
2dfbd3c0e2 | ||
|
|
4998a712b2 | ||
|
|
f3f4604c19 | ||
|
|
f2ccf2f783 | ||
|
|
3a69cc1487 | ||
|
|
8e2ef4f7af | ||
|
|
34612193af | ||
|
|
99792653de | ||
|
|
7127aaaaf7 | ||
|
|
811da5c541 | ||
|
|
9f73669959 | ||
|
|
55e79f823d | ||
|
|
10509405b2 | ||
|
|
5f56314618 | ||
|
|
222132f48c | ||
|
|
65b4c7c01e | ||
|
|
8f96070067 | ||
|
|
01250d0044 | ||
|
|
ce4c0188d9 | ||
|
|
6ad8917b7e | ||
|
|
5d53b55aa7 | ||
|
|
a26dc609df | ||
|
|
3b7c204dca | ||
|
|
632f59392b | ||
|
|
5d025eb235 | ||
|
|
fb688d9e9d | ||
|
|
8257262dbf | ||
|
|
6dde43584f | ||
|
|
5b9960379f |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -9,3 +9,5 @@ install/
|
|||||||
|
|
||||||
# Development friendly files
|
# Development friendly files
|
||||||
tags
|
tags
|
||||||
|
cscope*
|
||||||
|
*.swp
|
||||||
|
|||||||
25
Kconfig
Normal file
25
Kconfig
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
|
||||||
|
mainmenu "OpenSBI $(OPENSBI_PLATFORM) Configuration"
|
||||||
|
|
||||||
|
config OPENSBI_SRC_DIR
|
||||||
|
string
|
||||||
|
option env="OPENSBI_SRC_DIR"
|
||||||
|
|
||||||
|
config OPENSBI_PLATFORM
|
||||||
|
string
|
||||||
|
option env="OPENSBI_PLATFORM"
|
||||||
|
|
||||||
|
config OPENSBI_PLATFORM_SRC_DIR
|
||||||
|
string
|
||||||
|
option env="OPENSBI_PLATFORM_SRC_DIR"
|
||||||
|
|
||||||
|
menu "Platform Options"
|
||||||
|
source "$(OPENSBI_PLATFORM_SRC_DIR)/Kconfig"
|
||||||
|
endmenu
|
||||||
|
|
||||||
|
source "$(OPENSBI_SRC_DIR)/lib/sbi/Kconfig"
|
||||||
|
|
||||||
|
source "$(OPENSBI_SRC_DIR)/lib/utils/Kconfig"
|
||||||
|
|
||||||
|
source "$(OPENSBI_SRC_DIR)/firmware/Kconfig"
|
||||||
176
Makefile
176
Makefile
@@ -47,11 +47,14 @@ ifdef PLATFORM_DIR
|
|||||||
platform_parent_dir=$(platform_dir_path)
|
platform_parent_dir=$(platform_dir_path)
|
||||||
else
|
else
|
||||||
PLATFORM=$(shell basename $(platform_dir_path))
|
PLATFORM=$(shell basename $(platform_dir_path))
|
||||||
platform_parent_dir=$(subst $(PLATFORM),,$(platform_dir_path))
|
platform_parent_dir=$(shell realpath ${platform_dir_path}/..)
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
platform_parent_dir=$(src_dir)/platform
|
platform_parent_dir=$(src_dir)/platform
|
||||||
endif
|
endif
|
||||||
|
ifndef PLATFORM_DEFCONFIG
|
||||||
|
PLATFORM_DEFCONFIG=defconfig
|
||||||
|
endif
|
||||||
|
|
||||||
# Check if verbosity is ON for build process
|
# Check if verbosity is ON for build process
|
||||||
CMD_PREFIX_DEFAULT := @
|
CMD_PREFIX_DEFAULT := @
|
||||||
@@ -70,6 +73,20 @@ export libsbi_dir=$(CURDIR)/lib/sbi
|
|||||||
export libsbiutils_dir=$(CURDIR)/lib/utils
|
export libsbiutils_dir=$(CURDIR)/lib/utils
|
||||||
export firmware_dir=$(CURDIR)/firmware
|
export firmware_dir=$(CURDIR)/firmware
|
||||||
|
|
||||||
|
# Setup variables for kconfig
|
||||||
|
ifdef PLATFORM
|
||||||
|
export PYTHONDONTWRITEBYTECODE=1
|
||||||
|
export KCONFIG_DIR=$(platform_build_dir)/kconfig
|
||||||
|
export KCONFIG_AUTOLIST=$(KCONFIG_DIR)/auto.list
|
||||||
|
export KCONFIG_AUTOHEADER=$(KCONFIG_DIR)/autoconf.h
|
||||||
|
export KCONFIG_AUTOCMD=$(KCONFIG_DIR)/auto.conf.cmd
|
||||||
|
export KCONFIG_CONFIG=$(KCONFIG_DIR)/.config
|
||||||
|
# Additional exports for include paths in Kconfig files
|
||||||
|
export OPENSBI_SRC_DIR=$(src_dir)
|
||||||
|
export OPENSBI_PLATFORM=$(PLATFORM)
|
||||||
|
export OPENSBI_PLATFORM_SRC_DIR=$(platform_src_dir)
|
||||||
|
endif
|
||||||
|
|
||||||
# Find library version
|
# Find library version
|
||||||
OPENSBI_VERSION_MAJOR=`grep "define OPENSBI_VERSION_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 "define OPENSBI_VERSION_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/'`
|
||||||
@@ -153,6 +170,9 @@ OPENSBI_LD_PIE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) $(USE_LD_FLAG) -fP
|
|||||||
# Check whether the compiler supports -m(no-)save-restore
|
# Check whether the compiler supports -m(no-)save-restore
|
||||||
CC_SUPPORT_SAVE_RESTORE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -mno-save-restore -x c /dev/null -o /dev/null 2>&1 | grep "\-save\-restore" >/dev/null && echo n || echo y)
|
CC_SUPPORT_SAVE_RESTORE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -mno-save-restore -x c /dev/null -o /dev/null 2>&1 | grep "\-save\-restore" >/dev/null && echo n || echo y)
|
||||||
|
|
||||||
|
# Check whether the assembler and the compiler support the Zicsr and Zifencei extensions
|
||||||
|
CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep "zicsr\|zifencei" > /dev/null && echo n || echo y)
|
||||||
|
|
||||||
# Build Info:
|
# Build Info:
|
||||||
# OPENSBI_BUILD_TIME_STAMP -- the compilation time stamp
|
# OPENSBI_BUILD_TIME_STAMP -- the compilation time stamp
|
||||||
# OPENSBI_BUILD_COMPILER_VERSION -- the compiler version info
|
# OPENSBI_BUILD_COMPILER_VERSION -- the compiler version info
|
||||||
@@ -180,12 +200,38 @@ libsbi-object-mks=$(shell if [ -d $(libsbi_dir) ]; then find $(libsbi_dir) -inam
|
|||||||
libsbiutils-object-mks=$(shell if [ -d $(libsbiutils_dir) ]; then find $(libsbiutils_dir) -iname "objects.mk" | sort -r; fi)
|
libsbiutils-object-mks=$(shell if [ -d $(libsbiutils_dir) ]; then find $(libsbiutils_dir) -iname "objects.mk" | sort -r; fi)
|
||||||
firmware-object-mks=$(shell if [ -d $(firmware_dir) ]; then find $(firmware_dir) -iname "objects.mk" | sort -r; fi)
|
firmware-object-mks=$(shell if [ -d $(firmware_dir) ]; then find $(firmware_dir) -iname "objects.mk" | sort -r; fi)
|
||||||
|
|
||||||
# Include platform specifig config.mk
|
# The "make all" rule should always be first rule
|
||||||
|
.PHONY: all
|
||||||
|
all:
|
||||||
|
|
||||||
|
# Include platform specific .config
|
||||||
ifdef PLATFORM
|
ifdef PLATFORM
|
||||||
include $(platform_src_dir)/config.mk
|
.PHONY: menuconfig
|
||||||
|
menuconfig: $(platform_src_dir)/Kconfig $(src_dir)/Kconfig
|
||||||
|
$(CMD_PREFIX)mkdir -p $(KCONFIG_DIR)
|
||||||
|
$(CMD_PREFIX)$(src_dir)/scripts/Kconfiglib/menuconfig.py $(src_dir)/Kconfig
|
||||||
|
$(CMD_PREFIX)$(src_dir)/scripts/Kconfiglib/genconfig.py --header-path $(KCONFIG_AUTOHEADER) --sync-deps $(KCONFIG_DIR) --file-list $(KCONFIG_AUTOLIST) $(src_dir)/Kconfig
|
||||||
|
|
||||||
|
.PHONY: savedefconfig
|
||||||
|
savedefconfig: $(platform_src_dir)/Kconfig $(src_dir)/Kconfig
|
||||||
|
$(CMD_PREFIX)mkdir -p $(KCONFIG_DIR)
|
||||||
|
$(CMD_PREFIX)$(src_dir)/scripts/Kconfiglib/savedefconfig.py --kconfig $(src_dir)/Kconfig --out $(KCONFIG_DIR)/defconfig
|
||||||
|
|
||||||
|
$(KCONFIG_CONFIG): $(platform_src_dir)/configs/$(PLATFORM_DEFCONFIG) $(platform_src_dir)/Kconfig $(src_dir)/Kconfig
|
||||||
|
$(CMD_PREFIX)mkdir -p $(KCONFIG_DIR)
|
||||||
|
$(CMD_PREFIX)$(src_dir)/scripts/Kconfiglib/defconfig.py --kconfig $(src_dir)/Kconfig $(platform_src_dir)/configs/$(PLATFORM_DEFCONFIG)
|
||||||
|
$(CMD_PREFIX)$(src_dir)/scripts/Kconfiglib/genconfig.py --header-path $(KCONFIG_AUTOHEADER) --sync-deps $(KCONFIG_DIR) --file-list $(KCONFIG_AUTOLIST) $(src_dir)/Kconfig
|
||||||
|
|
||||||
|
$(KCONFIG_AUTOCMD): $(KCONFIG_CONFIG)
|
||||||
|
$(CMD_PREFIX)mkdir -p $(KCONFIG_DIR)
|
||||||
|
$(CMD_PREFIX)printf "%s: " $(KCONFIG_CONFIG) > $(KCONFIG_AUTOCMD)
|
||||||
|
$(CMD_PREFIX)cat $(KCONFIG_AUTOLIST) | tr '\n' ' ' >> $(KCONFIG_AUTOCMD)
|
||||||
|
|
||||||
|
include $(KCONFIG_CONFIG)
|
||||||
|
include $(KCONFIG_AUTOCMD)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Include all object.mk files
|
# Include all objects.mk files
|
||||||
ifdef PLATFORM
|
ifdef PLATFORM
|
||||||
include $(platform-object-mks)
|
include $(platform-object-mks)
|
||||||
endif
|
endif
|
||||||
@@ -195,8 +241,8 @@ include $(firmware-object-mks)
|
|||||||
|
|
||||||
# Setup list of objects
|
# Setup list of objects
|
||||||
libsbi-objs-path-y=$(foreach obj,$(libsbi-objs-y),$(build_dir)/lib/sbi/$(obj))
|
libsbi-objs-path-y=$(foreach obj,$(libsbi-objs-y),$(build_dir)/lib/sbi/$(obj))
|
||||||
libsbiutils-objs-path-y=$(foreach obj,$(libsbiutils-objs-y),$(build_dir)/lib/utils/$(obj))
|
|
||||||
ifdef PLATFORM
|
ifdef PLATFORM
|
||||||
|
libsbiutils-objs-path-y=$(foreach obj,$(libsbiutils-objs-y),$(platform_build_dir)/lib/utils/$(obj))
|
||||||
platform-objs-path-y=$(foreach obj,$(platform-objs-y),$(platform_build_dir)/$(obj))
|
platform-objs-path-y=$(foreach obj,$(platform-objs-y),$(platform_build_dir)/$(obj))
|
||||||
firmware-bins-path-y=$(foreach bin,$(firmware-bins-y),$(platform_build_dir)/firmware/$(bin))
|
firmware-bins-path-y=$(foreach bin,$(firmware-bins-y),$(platform_build_dir)/firmware/$(bin))
|
||||||
endif
|
endif
|
||||||
@@ -208,6 +254,7 @@ deps-y=$(platform-objs-path-y:.o=.dep)
|
|||||||
deps-y+=$(libsbi-objs-path-y:.o=.dep)
|
deps-y+=$(libsbi-objs-path-y:.o=.dep)
|
||||||
deps-y+=$(libsbiutils-objs-path-y:.o=.dep)
|
deps-y+=$(libsbiutils-objs-path-y:.o=.dep)
|
||||||
deps-y+=$(firmware-objs-path-y:.o=.dep)
|
deps-y+=$(firmware-objs-path-y:.o=.dep)
|
||||||
|
deps-y+=$(firmware-elfs-path-y:=.dep)
|
||||||
|
|
||||||
# Setup platform ABI, ISA and Code Model
|
# Setup platform ABI, ISA and Code Model
|
||||||
ifndef PLATFORM_RISCV_ABI
|
ifndef PLATFORM_RISCV_ABI
|
||||||
@@ -223,7 +270,11 @@ ifndef PLATFORM_RISCV_ABI
|
|||||||
endif
|
endif
|
||||||
ifndef PLATFORM_RISCV_ISA
|
ifndef PLATFORM_RISCV_ISA
|
||||||
ifneq ($(PLATFORM_RISCV_TOOLCHAIN_DEFAULT), 1)
|
ifneq ($(PLATFORM_RISCV_TOOLCHAIN_DEFAULT), 1)
|
||||||
PLATFORM_RISCV_ISA = rv$(PLATFORM_RISCV_XLEN)imafdc
|
ifeq ($(CC_SUPPORT_ZICSR_ZIFENCEI), y)
|
||||||
|
PLATFORM_RISCV_ISA = rv$(PLATFORM_RISCV_XLEN)imafdc_zicsr_zifencei
|
||||||
|
else
|
||||||
|
PLATFORM_RISCV_ISA = rv$(PLATFORM_RISCV_XLEN)imafdc
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
PLATFORM_RISCV_ISA = $(OPENSBI_CC_ISA)
|
PLATFORM_RISCV_ISA = $(OPENSBI_CC_ISA)
|
||||||
endif
|
endif
|
||||||
@@ -273,11 +324,19 @@ ifeq ($(BUILD_INFO),y)
|
|||||||
GENFLAGS += -DOPENSBI_BUILD_TIME_STAMP="\"$(OPENSBI_BUILD_TIME_STAMP)\""
|
GENFLAGS += -DOPENSBI_BUILD_TIME_STAMP="\"$(OPENSBI_BUILD_TIME_STAMP)\""
|
||||||
GENFLAGS += -DOPENSBI_BUILD_COMPILER_VERSION="\"$(OPENSBI_BUILD_COMPILER_VERSION)\""
|
GENFLAGS += -DOPENSBI_BUILD_COMPILER_VERSION="\"$(OPENSBI_BUILD_COMPILER_VERSION)\""
|
||||||
endif
|
endif
|
||||||
|
ifdef PLATFORM
|
||||||
|
GENFLAGS += -include $(KCONFIG_AUTOHEADER)
|
||||||
|
endif
|
||||||
GENFLAGS += $(libsbiutils-genflags-y)
|
GENFLAGS += $(libsbiutils-genflags-y)
|
||||||
GENFLAGS += $(platform-genflags-y)
|
GENFLAGS += $(platform-genflags-y)
|
||||||
GENFLAGS += $(firmware-genflags-y)
|
GENFLAGS += $(firmware-genflags-y)
|
||||||
|
|
||||||
CFLAGS = -g -Wall -Werror -ffreestanding -nostdlib -fno-stack-protector -fno-strict-aliasing -O2
|
CFLAGS = -g -Wall -Werror -ffreestanding -nostdlib -fno-stack-protector -fno-strict-aliasing
|
||||||
|
ifneq ($(DEBUG),)
|
||||||
|
CFLAGS += -O0
|
||||||
|
else
|
||||||
|
CFLAGS += -O2
|
||||||
|
endif
|
||||||
CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls -mstrict-align
|
CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls -mstrict-align
|
||||||
# enable -m(no-)save-restore option by CC_SUPPORT_SAVE_RESTORE
|
# enable -m(no-)save-restore option by CC_SUPPORT_SAVE_RESTORE
|
||||||
ifeq ($(CC_SUPPORT_SAVE_RESTORE),y)
|
ifeq ($(CC_SUPPORT_SAVE_RESTORE),y)
|
||||||
@@ -316,7 +375,7 @@ ASFLAGS += $(firmware-asflags-y)
|
|||||||
ARFLAGS = rcs
|
ARFLAGS = rcs
|
||||||
|
|
||||||
ELFFLAGS += $(USE_LD_FLAG)
|
ELFFLAGS += $(USE_LD_FLAG)
|
||||||
ELFFLAGS += -Wl,--build-id=none -Wl,-N
|
ELFFLAGS += -Wl,--build-id=none
|
||||||
ELFFLAGS += $(platform-ldflags-y)
|
ELFFLAGS += $(platform-ldflags-y)
|
||||||
ELFFLAGS += $(firmware-ldflags-y)
|
ELFFLAGS += $(firmware-ldflags-y)
|
||||||
|
|
||||||
@@ -360,6 +419,11 @@ inst_file_list = $(CMD_PREFIX)if [ ! -z "$(4)" ]; then \
|
|||||||
inst_header_dir = $(CMD_PREFIX)mkdir -p $(1); \
|
inst_header_dir = $(CMD_PREFIX)mkdir -p $(1); \
|
||||||
echo " INSTALL $(subst $(install_root_dir)/,,$(1))"; \
|
echo " INSTALL $(subst $(install_root_dir)/,,$(1))"; \
|
||||||
cp -rf $(2) $(1)
|
cp -rf $(2) $(1)
|
||||||
|
compile_cpp_dep = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
|
||||||
|
echo " CPP-DEP $(subst $(build_dir)/,,$(1))"; \
|
||||||
|
printf %s `dirname $(1)`/ > $(1) && \
|
||||||
|
$(CC) $(CPPFLAGS) -x c -MM $(3) \
|
||||||
|
-MT `basename $(1:.dep=$(2))` >> $(1) || rm -f $(1)
|
||||||
compile_cpp = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
|
compile_cpp = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
|
||||||
echo " CPP $(subst $(build_dir)/,,$(1))"; \
|
echo " CPP $(subst $(build_dir)/,,$(1))"; \
|
||||||
$(CPP) $(CPPFLAGS) -x c $(2) | grep -v "\#" > $(1)
|
$(CPP) $(CPPFLAGS) -x c $(2) | grep -v "\#" > $(1)
|
||||||
@@ -397,66 +461,73 @@ compile_d2c = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
|
|||||||
$(if $($(2)-varprefix-$(3)),$(eval D2C_NAME_PREFIX := $($(2)-varprefix-$(3))),$(eval D2C_NAME_PREFIX := $(5))) \
|
$(if $($(2)-varprefix-$(3)),$(eval D2C_NAME_PREFIX := $($(2)-varprefix-$(3))),$(eval D2C_NAME_PREFIX := $(5))) \
|
||||||
$(if $($(2)-padding-$(3)),$(eval D2C_PADDING_BYTES := $($(2)-padding-$(3))),$(eval D2C_PADDING_BYTES := 0)) \
|
$(if $($(2)-padding-$(3)),$(eval D2C_PADDING_BYTES := $($(2)-padding-$(3))),$(eval D2C_PADDING_BYTES := 0)) \
|
||||||
$(src_dir)/scripts/d2c.sh -i $(6) -a $(D2C_ALIGN_BYTES) -p $(D2C_NAME_PREFIX) -t $(D2C_PADDING_BYTES) > $(1)
|
$(src_dir)/scripts/d2c.sh -i $(6) -a $(D2C_ALIGN_BYTES) -p $(D2C_NAME_PREFIX) -t $(D2C_PADDING_BYTES) > $(1)
|
||||||
|
compile_carray = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
|
||||||
|
echo " CARRAY $(subst $(build_dir)/,,$(1))"; \
|
||||||
|
$(eval CARRAY_VAR_LIST := $(carray-$(subst .c,,$(shell basename $(1)))-y)) \
|
||||||
|
$(src_dir)/scripts/carray.sh -i $(2) -l "$(CARRAY_VAR_LIST)" > $(1)
|
||||||
compile_gen_dep = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
|
compile_gen_dep = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
|
||||||
echo " GEN-DEP $(subst $(build_dir)/,,$(1))"; \
|
echo " GEN-DEP $(subst $(build_dir)/,,$(1))"; \
|
||||||
echo "$(1:.dep=$(2)): $(3)" >> $(1)
|
echo "$(1:.dep=$(2)): $(3)" >> $(1)
|
||||||
|
|
||||||
targets-y = $(build_dir)/lib/libsbi.a
|
targets-y = $(build_dir)/lib/libsbi.a
|
||||||
targets-y += $(build_dir)/lib/libsbiutils.a
|
|
||||||
ifdef PLATFORM
|
ifdef PLATFORM
|
||||||
targets-y += $(platform_build_dir)/lib/libplatsbi.a
|
targets-y += $(platform_build_dir)/lib/libplatsbi.a
|
||||||
endif
|
endif
|
||||||
targets-y += $(firmware-bins-path-y)
|
targets-y += $(firmware-bins-path-y)
|
||||||
|
|
||||||
# Default rule "make" should always be first rule
|
# The default "make all" rule
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: $(targets-y)
|
all: $(targets-y)
|
||||||
|
|
||||||
# Preserve all intermediate files
|
# Preserve all intermediate files
|
||||||
.SECONDARY:
|
.SECONDARY:
|
||||||
|
|
||||||
|
# Rules for lib/sbi sources
|
||||||
$(build_dir)/lib/libsbi.a: $(libsbi-objs-path-y)
|
$(build_dir)/lib/libsbi.a: $(libsbi-objs-path-y)
|
||||||
$(call compile_ar,$@,$^)
|
$(call compile_ar,$@,$^)
|
||||||
|
|
||||||
$(build_dir)/lib/libsbiutils.a: $(libsbi-objs-path-y) $(libsbiutils-objs-path-y)
|
|
||||||
$(call compile_ar,$@,$^)
|
|
||||||
|
|
||||||
$(platform_build_dir)/lib/libplatsbi.a: $(libsbi-objs-path-y) $(libsbiutils-objs-path-y) $(platform-objs-path-y)
|
$(platform_build_dir)/lib/libplatsbi.a: $(libsbi-objs-path-y) $(libsbiutils-objs-path-y) $(platform-objs-path-y)
|
||||||
$(call compile_ar,$@,$^)
|
$(call compile_ar,$@,$^)
|
||||||
|
|
||||||
$(build_dir)/%.dep: $(src_dir)/%.c
|
$(build_dir)/%.dep: $(src_dir)/%.carray $(KCONFIG_CONFIG)
|
||||||
|
$(call compile_gen_dep,$@,.c,$< $(KCONFIG_CONFIG))
|
||||||
|
$(call compile_gen_dep,$@,.o,$(@:.dep=.c))
|
||||||
|
|
||||||
|
$(build_dir)/%.c: $(src_dir)/%.carray
|
||||||
|
$(call compile_carray,$@,$<)
|
||||||
|
|
||||||
|
$(build_dir)/%.dep: $(src_dir)/%.c $(KCONFIG_CONFIG)
|
||||||
$(call compile_cc_dep,$@,$<)
|
$(call compile_cc_dep,$@,$<)
|
||||||
|
|
||||||
$(build_dir)/%.o: $(src_dir)/%.c
|
$(build_dir)/%.o: $(src_dir)/%.c
|
||||||
$(call compile_cc,$@,$<)
|
$(call compile_cc,$@,$<)
|
||||||
|
|
||||||
|
$(build_dir)/%.o: $(build_dir)/%.c
|
||||||
|
$(call compile_cc,$@,$<)
|
||||||
|
|
||||||
ifeq ($(BUILD_INFO),y)
|
ifeq ($(BUILD_INFO),y)
|
||||||
$(build_dir)/lib/sbi/sbi_init.o: $(libsbi_dir)/sbi_init.c FORCE
|
$(build_dir)/lib/sbi/sbi_init.o: $(libsbi_dir)/sbi_init.c FORCE
|
||||||
$(call compile_cc,$@,$<)
|
$(call compile_cc,$@,$<)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(build_dir)/%.dep: $(src_dir)/%.S
|
$(build_dir)/%.dep: $(src_dir)/%.S $(KCONFIG_CONFIG)
|
||||||
$(call compile_as_dep,$@,$<)
|
$(call compile_as_dep,$@,$<)
|
||||||
|
|
||||||
$(build_dir)/%.o: $(src_dir)/%.S
|
$(build_dir)/%.o: $(src_dir)/%.S
|
||||||
$(call compile_as,$@,$<)
|
$(call compile_as,$@,$<)
|
||||||
|
|
||||||
$(platform_build_dir)/%.bin: $(platform_build_dir)/%.elf
|
# Rules for platform sources
|
||||||
$(call compile_objcopy,$@,$<)
|
$(platform_build_dir)/%.dep: $(platform_src_dir)/%.carray $(KCONFIG_CONFIG)
|
||||||
|
$(call compile_gen_dep,$@,.c,$< $(KCONFIG_CONFIG))
|
||||||
|
$(call compile_gen_dep,$@,.o,$(@:.dep=.c))
|
||||||
|
|
||||||
$(platform_build_dir)/%.elf: $(platform_build_dir)/%.o $(platform_build_dir)/%.elf.ld $(platform_build_dir)/lib/libplatsbi.a
|
$(platform_build_dir)/%.c: $(platform_src_dir)/%.carray
|
||||||
$(call compile_elf,$@,$@.ld,$< $(platform_build_dir)/lib/libplatsbi.a)
|
$(call compile_carray,$@,$<)
|
||||||
|
|
||||||
$(platform_build_dir)/%.ld: $(src_dir)/%.ldS
|
$(platform_build_dir)/%.dep: $(platform_src_dir)/%.c $(KCONFIG_CONFIG)
|
||||||
$(call compile_cpp,$@,$<)
|
|
||||||
|
|
||||||
$(platform_build_dir)/%.dep: $(platform_src_dir)/%.c
|
|
||||||
$(call compile_cc_dep,$@,$<)
|
$(call compile_cc_dep,$@,$<)
|
||||||
|
|
||||||
$(platform_build_dir)/%.o: $(platform_src_dir)/%.c
|
$(platform_build_dir)/%.o: $(platform_src_dir)/%.c $(KCONFIG_CONFIG)
|
||||||
$(call compile_cc,$@,$<)
|
|
||||||
|
|
||||||
$(platform_build_dir)/%.o: $(platform_build_dir)/%.c
|
|
||||||
$(call compile_cc,$@,$<)
|
$(call compile_cc,$@,$<)
|
||||||
|
|
||||||
$(platform_build_dir)/%.dep: $(platform_src_dir)/%.S
|
$(platform_build_dir)/%.dep: $(platform_src_dir)/%.S
|
||||||
@@ -465,8 +536,8 @@ $(platform_build_dir)/%.dep: $(platform_src_dir)/%.S
|
|||||||
$(platform_build_dir)/%.o: $(platform_src_dir)/%.S
|
$(platform_build_dir)/%.o: $(platform_src_dir)/%.S
|
||||||
$(call compile_as,$@,$<)
|
$(call compile_as,$@,$<)
|
||||||
|
|
||||||
$(platform_build_dir)/%.dep: $(platform_src_dir)/%.dts
|
$(platform_build_dir)/%.dep: $(platform_src_dir)/%.dts $(KCONFIG_CONFIG)
|
||||||
$(call compile_gen_dep,$@,.dtb,$<)
|
$(call compile_gen_dep,$@,.dtb,$< $(KCONFIG_CONFIG))
|
||||||
$(call compile_gen_dep,$@,.c,$(@:.dep=.dtb))
|
$(call compile_gen_dep,$@,.c,$(@:.dep=.dtb))
|
||||||
$(call compile_gen_dep,$@,.o,$(@:.dep=.c))
|
$(call compile_gen_dep,$@,.o,$(@:.dep=.c))
|
||||||
|
|
||||||
@@ -476,13 +547,33 @@ $(platform_build_dir)/%.c: $(platform_build_dir)/%.dtb
|
|||||||
$(platform_build_dir)/%.dtb: $(platform_src_dir)/%.dts
|
$(platform_build_dir)/%.dtb: $(platform_src_dir)/%.dts
|
||||||
$(call compile_dts,$@,$<)
|
$(call compile_dts,$@,$<)
|
||||||
|
|
||||||
$(platform_build_dir)/%.dep: $(src_dir)/%.c
|
# Rules for lib/utils and firmware sources
|
||||||
|
$(platform_build_dir)/%.bin: $(platform_build_dir)/%.elf
|
||||||
|
$(call compile_objcopy,$@,$<)
|
||||||
|
|
||||||
|
$(platform_build_dir)/%.elf: $(platform_build_dir)/%.o $(platform_build_dir)/%.elf.ld $(platform_build_dir)/lib/libplatsbi.a
|
||||||
|
$(call compile_elf,$@,$@.ld,$< $(platform_build_dir)/lib/libplatsbi.a)
|
||||||
|
|
||||||
|
$(platform_build_dir)/%.dep: $(src_dir)/%.ldS $(KCONFIG_CONFIG)
|
||||||
|
$(call compile_cpp_dep,$@,.ld,$<)
|
||||||
|
|
||||||
|
$(platform_build_dir)/%.ld: $(src_dir)/%.ldS
|
||||||
|
$(call compile_cpp,$@,$<)
|
||||||
|
|
||||||
|
$(platform_build_dir)/%.dep: $(src_dir)/%.carray $(KCONFIG_CONFIG)
|
||||||
|
$(call compile_gen_dep,$@,.c,$< $(KCONFIG_CONFIG))
|
||||||
|
$(call compile_gen_dep,$@,.o,$(@:.dep=.c))
|
||||||
|
|
||||||
|
$(platform_build_dir)/%.c: $(src_dir)/%.carray
|
||||||
|
$(call compile_carray,$@,$<)
|
||||||
|
|
||||||
|
$(platform_build_dir)/%.dep: $(src_dir)/%.c $(KCONFIG_CONFIG)
|
||||||
$(call compile_cc_dep,$@,$<)
|
$(call compile_cc_dep,$@,$<)
|
||||||
|
|
||||||
$(platform_build_dir)/%.o: $(src_dir)/%.c
|
$(platform_build_dir)/%.o: $(src_dir)/%.c
|
||||||
$(call compile_cc,$@,$<)
|
$(call compile_cc,$@,$<)
|
||||||
|
|
||||||
$(platform_build_dir)/%.dep: $(src_dir)/%.S
|
$(platform_build_dir)/%.dep: $(src_dir)/%.S $(KCONFIG_CONFIG)
|
||||||
$(call compile_as_dep,$@,$<)
|
$(call compile_as_dep,$@,$<)
|
||||||
|
|
||||||
$(platform_build_dir)/%.o: $(src_dir)/%.S
|
$(platform_build_dir)/%.o: $(src_dir)/%.S
|
||||||
@@ -526,7 +617,6 @@ endif
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
install_targets-y = install_libsbi
|
install_targets-y = install_libsbi
|
||||||
install_targets-y += install_libsbiutils
|
|
||||||
ifdef PLATFORM
|
ifdef PLATFORM
|
||||||
install_targets-y += install_libplatsbi
|
install_targets-y += install_libplatsbi
|
||||||
install_targets-y += install_firmwares
|
install_targets-y += install_firmwares
|
||||||
@@ -541,17 +631,12 @@ install_libsbi: $(build_dir)/lib/libsbi.a
|
|||||||
$(call inst_header_dir,$(install_root_dir)/$(install_include_path),$(include_dir)/sbi)
|
$(call inst_header_dir,$(install_root_dir)/$(install_include_path),$(include_dir)/sbi)
|
||||||
$(call inst_file,$(install_root_dir)/$(install_lib_path)/libsbi.a,$(build_dir)/lib/libsbi.a)
|
$(call inst_file,$(install_root_dir)/$(install_lib_path)/libsbi.a,$(build_dir)/lib/libsbi.a)
|
||||||
|
|
||||||
.PHONY: install_libsbiutils
|
|
||||||
install_libsbiutils: $(build_dir)/lib/libsbiutils.a
|
|
||||||
$(call inst_header_dir,$(install_root_dir)/$(install_include_path),$(include_dir)/sbi_utils)
|
|
||||||
$(call inst_file,$(install_root_dir)/$(install_lib_path)/libsbiutils.a,$(build_dir)/lib/libsbiutils.a)
|
|
||||||
|
|
||||||
.PHONY: install_libplatsbi
|
.PHONY: install_libplatsbi
|
||||||
install_libplatsbi: $(platform_build_dir)/lib/libplatsbi.a $(build_dir)/lib/libsbi.a $(build_dir)/lib/libsbiutils.a
|
install_libplatsbi: $(platform_build_dir)/lib/libplatsbi.a $(build_dir)/lib/libsbi.a
|
||||||
$(call inst_file,$(install_root_dir)/$(install_lib_path)/opensbi/$(platform_subdir)/lib/libplatsbi.a,$(platform_build_dir)/lib/libplatsbi.a)
|
$(call inst_file,$(install_root_dir)/$(install_lib_path)/opensbi/$(platform_subdir)/lib/libplatsbi.a,$(platform_build_dir)/lib/libplatsbi.a)
|
||||||
|
|
||||||
.PHONY: install_firmwares
|
.PHONY: install_firmwares
|
||||||
install_firmwares: $(platform_build_dir)/lib/libplatsbi.a $(build_dir)/lib/libsbi.a $(build_dir)/lib/libsbiutils.a $(firmware-bins-path-y)
|
install_firmwares: $(platform_build_dir)/lib/libplatsbi.a $(build_dir)/lib/libsbi.a $(firmware-bins-path-y)
|
||||||
$(call inst_file_list,$(install_root_dir),$(build_dir),$(install_firmware_path)/$(platform_subdir)/firmware,$(firmware-elfs-path-y))
|
$(call inst_file_list,$(install_root_dir),$(build_dir),$(install_firmware_path)/$(platform_subdir)/firmware,$(firmware-elfs-path-y))
|
||||||
$(call inst_file_list,$(install_root_dir),$(build_dir),$(install_firmware_path)/$(platform_subdir)/firmware,$(firmware-bins-path-y))
|
$(call inst_file_list,$(install_root_dir),$(build_dir),$(install_firmware_path)/$(platform_subdir)/firmware,$(firmware-bins-path-y))
|
||||||
|
|
||||||
@@ -559,6 +644,17 @@ install_firmwares: $(platform_build_dir)/lib/libplatsbi.a $(build_dir)/lib/libsb
|
|||||||
install_docs: $(build_dir)/docs/latex/refman.pdf
|
install_docs: $(build_dir)/docs/latex/refman.pdf
|
||||||
$(call inst_file,$(install_root_dir)/$(install_docs_path)/refman.pdf,$(build_dir)/docs/latex/refman.pdf)
|
$(call inst_file,$(install_root_dir)/$(install_docs_path)/refman.pdf,$(build_dir)/docs/latex/refman.pdf)
|
||||||
|
|
||||||
|
.PHONY: cscope
|
||||||
|
cscope:
|
||||||
|
$(CMD_PREFIX)find \
|
||||||
|
"$(src_dir)/firmware" \
|
||||||
|
"$(src_dir)/include" \
|
||||||
|
"$(src_dir)/lib" \
|
||||||
|
"$(platform_src_dir)" \
|
||||||
|
-name "*.[chS]" -print > cscope.files
|
||||||
|
$(CMD_PREFIX)echo "$(KCONFIG_AUTOHEADER)" >> cscope.files
|
||||||
|
$(CMD_PREFIX)cscope -bkq -i cscope.files -f cscope.out
|
||||||
|
|
||||||
# Rule for "make clean"
|
# Rule for "make clean"
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
@@ -588,6 +684,8 @@ ifeq ($(install_root_dir),$(install_root_dir_default)/usr)
|
|||||||
$(if $(V), @echo " RM $(install_root_dir_default)")
|
$(if $(V), @echo " RM $(install_root_dir_default)")
|
||||||
$(CMD_PREFIX)rm -rf $(install_root_dir_default)
|
$(CMD_PREFIX)rm -rf $(install_root_dir_default)
|
||||||
endif
|
endif
|
||||||
|
$(if $(V), @echo " RM $(src_dir)/cscope*")
|
||||||
|
$(CMD_PREFIX)rm -f $(src_dir)/cscope*
|
||||||
|
|
||||||
.PHONY: FORCE
|
.PHONY: FORCE
|
||||||
FORCE:
|
FORCE:
|
||||||
|
|||||||
38
README.md
38
README.md
@@ -92,8 +92,8 @@ N.B. Any S-mode boot loader (i.e. U-Boot) doesn't need to support HSM extension,
|
|||||||
as it doesn't need to boot all the harts. The operating system should be
|
as it doesn't need to boot all the harts. The operating system should be
|
||||||
capable enough to bring up all other non-booting harts using HSM extension.
|
capable enough to bring up all other non-booting harts using HSM extension.
|
||||||
|
|
||||||
Required Toolchain
|
Required Toolchain and Packages
|
||||||
------------------
|
-------------------------------
|
||||||
|
|
||||||
OpenSBI can be compiled natively or cross-compiled on a x86 host. For
|
OpenSBI can be compiled natively or cross-compiled on a x86 host. For
|
||||||
cross-compilation, you can build your own toolchain, download a prebuilt one
|
cross-compilation, you can build your own toolchain, download a prebuilt one
|
||||||
@@ -115,6 +115,14 @@ triple is used (e.g. *-target riscv64-unknown-elf*).
|
|||||||
Please note that only a 64-bit version of the toolchain is available in
|
Please note that only a 64-bit version of the toolchain is available in
|
||||||
the Bootlin toolchain repository for now.
|
the Bootlin toolchain repository for now.
|
||||||
|
|
||||||
|
In addition to a toolchain, OpenSBI also requires the following packages on
|
||||||
|
the host:
|
||||||
|
|
||||||
|
1. device-tree-compiler: The device tree compiler for compiling device
|
||||||
|
tree sources (DTS files).
|
||||||
|
2. python3: The python 3.0 (or compatible) language support for various
|
||||||
|
scripts.
|
||||||
|
|
||||||
Building and Installing the OpenSBI Platform-Independent Library
|
Building and Installing the OpenSBI Platform-Independent Library
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
|
||||||
@@ -196,6 +204,19 @@ top-level make command line. These options, such as *PLATFORM_<xyz>* or
|
|||||||
*docs/platform/<platform_name>.md* files and
|
*docs/platform/<platform_name>.md* files and
|
||||||
*docs/firmware/<firmware_name>.md* files.
|
*docs/firmware/<firmware_name>.md* files.
|
||||||
|
|
||||||
|
All OpenSBI platforms support Kconfig style build-time configuration. Users
|
||||||
|
can change the build-time configuration of a platform using a graphical
|
||||||
|
interface as follows:
|
||||||
|
```
|
||||||
|
make PLATFORM=<platform_subdir> menuconfig
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternately, an OpenSBI platform can have multiple default configurations
|
||||||
|
and users can select a custom default configuration as follows:
|
||||||
|
```
|
||||||
|
make PLATFORM=<platform_subdir> PLATFORM_DEFCONFIG=<platform_custom_defconfig>
|
||||||
|
```
|
||||||
|
|
||||||
Building 32-bit / 64-bit OpenSBI Images
|
Building 32-bit / 64-bit OpenSBI Images
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
By default, building OpenSBI generates 32-bit or 64-bit images based on the
|
By default, building OpenSBI generates 32-bit or 64-bit images based on the
|
||||||
@@ -277,6 +298,19 @@ NOTE: Using `BUILD_INFO=y` without specifying SOURCE_DATE_EPOCH will violate
|
|||||||
purpose, and should NOT be used in a product which follows "reproducible
|
purpose, and should NOT be used in a product which follows "reproducible
|
||||||
builds".
|
builds".
|
||||||
|
|
||||||
|
Building with optimization off for debugging
|
||||||
|
--------------------------------------------
|
||||||
|
|
||||||
|
When debugging OpenSBI, we may want to turn off the compiler optimization and
|
||||||
|
make debugging produce the expected results for a better debugging experience.
|
||||||
|
To build with optimization off we can just simply add `DEBUG=1`, like:
|
||||||
|
```
|
||||||
|
make DEBUG=1
|
||||||
|
```
|
||||||
|
|
||||||
|
This definition is ONLY for development and debug purpose, and should NOT be
|
||||||
|
used in a product build.
|
||||||
|
|
||||||
Contributing to OpenSBI
|
Contributing to OpenSBI
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ and "top:".
|
|||||||
5. Maintainers should use "Rebase and Merge" when using GitHub to merge pull
|
5. Maintainers should use "Rebase and Merge" when using GitHub to merge pull
|
||||||
requests to avoid creating unnecessary merge commits.
|
requests to avoid creating unnecessary merge commits.
|
||||||
6. Maintainers should avoid creating branches directly in the main
|
6. Maintainers should avoid creating branches directly in the main
|
||||||
riscv/opensbi repository. Instead prefer using a fork of the riscv/opensbi main
|
riscv/opensbi repository. Instead, prefer using a fork of the riscv/opensbi main
|
||||||
repository and branches within that fork to create pull requests.
|
repository and branches within that fork to create pull requests.
|
||||||
7. A maintainer cannot merge his own pull requests in the riscv/opensbi main
|
7. A maintainer cannot merge his own pull requests in the riscv/opensbi main
|
||||||
repository.
|
repository.
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ OpenSBI Domain Support
|
|||||||
======================
|
======================
|
||||||
|
|
||||||
An OpenSBI domain is a system-level partition (subset) of underlying hardware
|
An OpenSBI domain is a system-level partition (subset) of underlying hardware
|
||||||
having it's own memory regions (RAM and MMIO devices) and HARTs. The OpenSBI
|
having its own memory regions (RAM and MMIO devices) and HARTs. The OpenSBI
|
||||||
will try to achieve secure isolation between domains using RISC-V platform
|
will try to achieve secure isolation between domains using RISC-V platform
|
||||||
features such as PMP, ePMP, IOPMP, SiFive Shield, etc.
|
features such as PMP, ePMP, IOPMP, SiFive Shield, etc.
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ Important entities which help implement OpenSBI domain support are:
|
|||||||
Each HART of a RISC-V platform must have an OpenSBI domain assigned to it.
|
Each HART of a RISC-V platform must have an OpenSBI domain assigned to it.
|
||||||
The OpenSBI platform support is responsible for populating domains and
|
The OpenSBI platform support is responsible for populating domains and
|
||||||
providing HART id to domain mapping. The OpenSBI domain support will by
|
providing HART id to domain mapping. The OpenSBI domain support will by
|
||||||
default assign **the ROOT domain** to all HARTs of a RISC-V platform so
|
default assign **the ROOT domain** to all HARTs of a RISC-V platform, so
|
||||||
it is not mandatory for the OpenSBI platform support to populate domains.
|
it is not mandatory for the OpenSBI platform support to populate domains.
|
||||||
|
|
||||||
Domain Memory Region
|
Domain Memory Region
|
||||||
@@ -29,7 +29,7 @@ OpenSBI and has following details:
|
|||||||
* **base** - The base address of a memory region is **2 ^ order**
|
* **base** - The base address of a memory region is **2 ^ order**
|
||||||
aligned start address
|
aligned start address
|
||||||
* **flags** - The flags of a memory region represent memory type (i.e.
|
* **flags** - The flags of a memory region represent memory type (i.e.
|
||||||
RAM or MMIO) and allowed accesses (i.e. READ, WRITE, EXECUTE, etc)
|
RAM or MMIO) and allowed accesses (i.e. READ, WRITE, EXECUTE, etc.)
|
||||||
|
|
||||||
Domain Instance
|
Domain Instance
|
||||||
---------------
|
---------------
|
||||||
@@ -52,6 +52,7 @@ has following details:
|
|||||||
* **next_mode** - Privilege mode of the next booting stage for this
|
* **next_mode** - Privilege mode of the next booting stage for this
|
||||||
domain. This can be either S-mode or U-mode.
|
domain. This can be either S-mode or U-mode.
|
||||||
* **system_reset_allowed** - Is domain allowed to reset the system?
|
* **system_reset_allowed** - Is domain allowed to reset the system?
|
||||||
|
* **system_suspend_allowed** - Is domain allowed to suspend the system?
|
||||||
|
|
||||||
The memory regions represented by **regions** in **struct sbi_domain** have
|
The memory regions represented by **regions** in **struct sbi_domain** have
|
||||||
following additional constraints to align with RISC-V PMP requirements:
|
following additional constraints to align with RISC-V PMP requirements:
|
||||||
@@ -91,6 +92,7 @@ following manner:
|
|||||||
* **next_mode** - Next booting stage mode in coldboot HART scratch space
|
* **next_mode** - Next booting stage mode in coldboot HART scratch space
|
||||||
is the next mode for the ROOT domain
|
is the next mode for the ROOT domain
|
||||||
* **system_reset_allowed** - The ROOT domain is allowed to reset the system
|
* **system_reset_allowed** - The ROOT domain is allowed to reset the system
|
||||||
|
* **system_suspend_allowed** - The ROOT domain is allowed to suspend the system
|
||||||
|
|
||||||
Domain Effects
|
Domain Effects
|
||||||
--------------
|
--------------
|
||||||
@@ -124,6 +126,9 @@ The DT properties of a domain configuration DT node are as follows:
|
|||||||
* **compatible** (Mandatory) - The compatible string of the domain
|
* **compatible** (Mandatory) - The compatible string of the domain
|
||||||
configuration. This DT property should have value *"opensbi,domain,config"*
|
configuration. This DT property should have value *"opensbi,domain,config"*
|
||||||
|
|
||||||
|
* **system-suspend-test** (Optional) - When present, enable a system
|
||||||
|
suspend test implementation which simply waits five seconds and issues a WFI.
|
||||||
|
|
||||||
### Domain Memory Region Node
|
### Domain Memory Region Node
|
||||||
|
|
||||||
The domain memory region DT node describes details of a memory region and
|
The domain memory region DT node describes details of a memory region and
|
||||||
@@ -160,8 +165,16 @@ The DT properties of a domain instance DT node are as follows:
|
|||||||
* **regions** (Optional) - The list of domain memory region DT node phandle
|
* **regions** (Optional) - The list of domain memory region DT node phandle
|
||||||
and access permissions for the domain instance. Each list entry is a pair
|
and access permissions for the domain instance. Each list entry is a pair
|
||||||
of DT node phandle and access permissions. The access permissions are
|
of DT node phandle and access permissions. The access permissions are
|
||||||
represented as a 32bit bitmask having bits: **readable** (BIT[0]),
|
represented as a 32bit bitmask having bits: **M readable** (BIT[0]),
|
||||||
**writeable** (BIT[1]), **executable** (BIT[2]), and **m-mode** (BIT[3]).
|
**M writeable** (BIT[1]), **M executable** (BIT[2]), **SU readable**
|
||||||
|
(BIT[3]), **SU writable** (BIT[4]), and **SU executable** (BIT[5]).
|
||||||
|
The enforce permission bit (BIT[6]), if set, will lock the permissions
|
||||||
|
in the PMP. This will enforce the permissions on M-mode as well which
|
||||||
|
otherwise will have unrestricted access. This bit must be used with
|
||||||
|
caution because no changes can be made to a PMP entry once its locked
|
||||||
|
until the hart is reset.
|
||||||
|
Any region of a domain defined in DT node cannot have only M-bits set
|
||||||
|
in access permissions i.e. it cannot be an m-mode only accessible region.
|
||||||
* **boot-hart** (Optional) - The DT node phandle of the HART booting the
|
* **boot-hart** (Optional) - The DT node phandle of the HART booting the
|
||||||
domain instance. If coldboot HART is assigned to the domain instance then
|
domain instance. If coldboot HART is assigned to the domain instance then
|
||||||
this DT property is ignored and the coldboot HART is assumed to be the
|
this DT property is ignored and the coldboot HART is assumed to be the
|
||||||
@@ -180,13 +193,15 @@ The DT properties of a domain instance DT node are as follows:
|
|||||||
is used as default value.
|
is used as default value.
|
||||||
* **next-mode** (Optional) - The 32 bit next booting stage mode for the
|
* **next-mode** (Optional) - The 32 bit next booting stage mode for the
|
||||||
domain instance. The possible values of this DT property are: **0x1**
|
domain instance. The possible values of this DT property are: **0x1**
|
||||||
(s-mode), and **0x0** (u-mode). If this DT property is not available
|
(S-mode), and **0x0** (U-mode). If this DT property is not available
|
||||||
and coldboot HART is not assigned to the domain instance then **0x1**
|
and coldboot HART is not assigned to the domain instance then **0x1**
|
||||||
is used as default value. If this DT property is not available and
|
is used as default value. If this DT property is not available and
|
||||||
coldboot HART is assigned to the domain instance then **next booting
|
coldboot HART is assigned to the domain instance then **next booting
|
||||||
stage mode of coldboot HART** is used as default value.
|
stage mode of coldboot HART** is used as default value.
|
||||||
* **system-reset-allowed** (Optional) - A boolean flag representing
|
* **system-reset-allowed** (Optional) - A boolean flag representing
|
||||||
whether the domain instance is allowed to do system reset.
|
whether the domain instance is allowed to do system reset.
|
||||||
|
* **system-suspend-allowed** (Optional) - A boolean flag representing
|
||||||
|
whether the domain instance is allowed to do system suspend.
|
||||||
|
|
||||||
### Assigning HART To Domain Instance
|
### Assigning HART To Domain Instance
|
||||||
|
|
||||||
@@ -195,9 +210,9 @@ platform support can provide the HART to domain instance assignment using
|
|||||||
platform specific callback.
|
platform specific callback.
|
||||||
|
|
||||||
The HART to domain instance assignment can be parsed from the device tree
|
The HART to domain instance assignment can be parsed from the device tree
|
||||||
using optional DT property **opensbi,domain** in each CPU DT node. The
|
using optional DT property **opensbi-domain** in each CPU DT node. The
|
||||||
value of DT property **opensbi,domain** is the DT phandle of the domain
|
value of DT property **opensbi-domain** is the DT phandle of the domain
|
||||||
instance DT node. If **opensbi,domain** DT property is not specified then
|
instance DT node. If **opensbi-domain** DT property is not specified then
|
||||||
corresponding HART is assigned to **the ROOT domain**.
|
corresponding HART is assigned to **the ROOT domain**.
|
||||||
|
|
||||||
### Domain Configuration Only Accessible to OpenSBI
|
### Domain Configuration Only Accessible to OpenSBI
|
||||||
@@ -222,6 +237,7 @@ be done:
|
|||||||
chosen {
|
chosen {
|
||||||
opensbi-domains {
|
opensbi-domains {
|
||||||
compatible = "opensbi,domain,config";
|
compatible = "opensbi,domain,config";
|
||||||
|
system-suspend-test;
|
||||||
|
|
||||||
tmem: tmem {
|
tmem: tmem {
|
||||||
compatible = "opensbi,domain,memregion";
|
compatible = "opensbi,domain,memregion";
|
||||||
@@ -246,18 +262,19 @@ be done:
|
|||||||
tdomain: trusted-domain {
|
tdomain: trusted-domain {
|
||||||
compatible = "opensbi,domain,instance";
|
compatible = "opensbi,domain,instance";
|
||||||
possible-harts = <&cpu0>;
|
possible-harts = <&cpu0>;
|
||||||
regions = <&tmem 0x7>, <&tuart 0x7>;
|
regions = <&tmem 0x3f>, <&tuart 0x3f>;
|
||||||
boot-hart = <&cpu0>;
|
boot-hart = <&cpu0>;
|
||||||
next-arg1 = <0x0 0x0>;
|
next-arg1 = <0x0 0x0>;
|
||||||
next-addr = <0x0 0x80100000>;
|
next-addr = <0x0 0x80100000>;
|
||||||
next-mode = <0x0>;
|
next-mode = <0x0>;
|
||||||
system-reset-allowed;
|
system-reset-allowed;
|
||||||
|
system-suspend-allowed;
|
||||||
};
|
};
|
||||||
|
|
||||||
udomain: untrusted-domain {
|
udomain: untrusted-domain {
|
||||||
compatible = "opensbi,domain,instance";
|
compatible = "opensbi,domain,instance";
|
||||||
possible-harts = <&cpu1 &cpu2 &cpu3 &cpu4>;
|
possible-harts = <&cpu1 &cpu2 &cpu3 &cpu4>;
|
||||||
regions = <&tmem 0x0>, <&tuart 0x0>, <&allmem 0x7>;
|
regions = <&tmem 0x0>, <&tuart 0x0>, <&allmem 0x3f>;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ the booting stage to follow OpenSBI firmware.
|
|||||||
A *FW_PAYLOAD* firmware is also useful for cases where the booting stage prior
|
A *FW_PAYLOAD* firmware is also useful for cases where the booting stage prior
|
||||||
to OpenSBI firmware does not pass a *flattened device tree (FDT file)*. In such
|
to OpenSBI firmware does not pass a *flattened device tree (FDT file)*. In such
|
||||||
case, a *FW_PAYLOAD* firmware allows embedding a flattened device tree in the
|
case, a *FW_PAYLOAD* firmware allows embedding a flattened device tree in the
|
||||||
.text section of the final firmware.
|
.rodata section of the final firmware.
|
||||||
|
|
||||||
Firmware Configuration and Compilation
|
Firmware Configuration and Compilation
|
||||||
--------------------------------------
|
--------------------------------------
|
||||||
@@ -61,7 +61,7 @@ Firmware Configuration and Compilation
|
|||||||
All firmware types support the following common compile time configuration
|
All firmware types support the following common compile time configuration
|
||||||
parameters:
|
parameters:
|
||||||
|
|
||||||
* **FW_TEXT_ADDR** - Defines the execution address of the OpenSBI firmware.
|
* **FW_TEXT_START** - Defines the execution address of the OpenSBI firmware.
|
||||||
This configuration parameter is mandatory.
|
This configuration parameter is mandatory.
|
||||||
* **FW_FDT_PATH** - Path to an external flattened device tree binary file to
|
* **FW_FDT_PATH** - Path to an external flattened device tree binary file to
|
||||||
be embedded in the *.rodata* section of the final firmware. If this option
|
be embedded in the *.rodata* section of the final firmware. If this option
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ the booting stage binary to follow OpenSBI firmware.
|
|||||||
A platform can enable *FW_DYNAMIC* firmware using any of the following methods.
|
A platform can enable *FW_DYNAMIC* firmware using any of the following methods.
|
||||||
|
|
||||||
1. Specifying `FW_DYNAMIC=y` on the top level `make` command line.
|
1. Specifying `FW_DYNAMIC=y` on the top level `make` command line.
|
||||||
2. Specifying `FW_DYNAMIC=y` in the target platform *config.mk* configuration
|
2. Specifying `FW_DYNAMIC=y` in the target platform *objects.mk* configuration
|
||||||
file.
|
file.
|
||||||
|
|
||||||
The compiled *FW_DYNAMIC* firmware ELF file is named *fw_dynamic.elf*. It's
|
The compiled *FW_DYNAMIC* firmware ELF file is named *fw_dynamic.elf*. It's
|
||||||
@@ -31,6 +31,6 @@ directory.
|
|||||||
*FW_DYNAMIC* Firmware Configuration Options
|
*FW_DYNAMIC* Firmware Configuration Options
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
|
|
||||||
The *FW_DYNAMIC* firmware does not requires any platform specific configuration
|
The *FW_DYNAMIC* firmware does not require any platform specific configuration
|
||||||
parameters because all required information is passed by previous booting stage
|
parameters because all required information is passed by previous booting stage
|
||||||
at runtime via *struct fw_dynamic_info*.
|
at runtime via *struct fw_dynamic_info*.
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ and the booting stage binary to follow the OpenSBI firmware.
|
|||||||
A platform *FW_JUMP* firmware can be enabled by any of the following methods:
|
A platform *FW_JUMP* firmware can be enabled by any of the following methods:
|
||||||
|
|
||||||
1. Specifying `FW_JUMP=y` on the top level `make` command line.
|
1. Specifying `FW_JUMP=y` on the top level `make` command line.
|
||||||
2. Specifying `FW_JUMP=y` in the target platform *config.mk* configuration file.
|
2. Specifying `FW_JUMP=y` in the target platform *objects.mk* configuration file.
|
||||||
|
|
||||||
The compiled *FW_JUMP* firmware ELF file is named *fw_jump.elf*. Its expanded
|
The compiled *FW_JUMP* firmware ELF file is named *fw_jump.elf*. Its expanded
|
||||||
image file is *fw_jump.bin*. Both files are created in the platform-specific
|
image file is *fw_jump.bin*. Both files are created in the platform-specific
|
||||||
@@ -26,7 +26,7 @@ build directory under the *build/platform/<platform_subdir>/firmware* directory.
|
|||||||
|
|
||||||
To operate correctly, a *FW_JUMP* firmware requires some configuration
|
To operate correctly, a *FW_JUMP* firmware requires some configuration
|
||||||
parameters to be defined using either the top level `make` command line or the
|
parameters to be defined using either the top level `make` command line or the
|
||||||
target platform *config.mk* configuration file. The possible parameters are as
|
target platform *objects.mk* configuration file. The possible parameters are as
|
||||||
follows:
|
follows:
|
||||||
|
|
||||||
* **FW_JUMP_ADDR** - Address of the entry point of the booting stage to be
|
* **FW_JUMP_ADDR** - Address of the entry point of the booting stage to be
|
||||||
@@ -41,6 +41,22 @@ follows:
|
|||||||
provided, then the OpenSBI firmware will pass the FDT address passed by the
|
provided, then the OpenSBI firmware will pass the FDT address passed by the
|
||||||
previous booting stage to the next booting stage.
|
previous booting stage to the next booting stage.
|
||||||
|
|
||||||
|
When using the default *FW_JUMP_FDT_ADDR* with *PLATFORM=generic*, you must
|
||||||
|
ensure *FW_JUMP_FDT_ADDR* is set high enough to avoid overwriting the kernel.
|
||||||
|
You can use the following method.
|
||||||
|
|
||||||
|
```
|
||||||
|
${CROSS_COMPILE}objdump -h $KERNEL_ELF | sort -k 5,5 | awk -n '/^ +[0-9]+ /\
|
||||||
|
{addr="0x"$3; size="0x"$5; printf "0x""%x\n",addr+size}' \
|
||||||
|
| (( `tail -1` > 0x2200000 )) && echo fdt overlaps kernel,\
|
||||||
|
increase FW_JUMP_FDT_ADDR
|
||||||
|
|
||||||
|
${LLVM}objdump -h --show-lma $KERNEL_ELF | sort -k 5,5 | \
|
||||||
|
awk -n '/^ +[0-9]+ / {addr="0x"$3; size="0x"$5; printf "0x""%x\n",addr+size}'\
|
||||||
|
| (( `tail -1` > 0x2200000 )) && echo fdt overlaps kernel,\
|
||||||
|
increase FW_JUMP_FDT_ADDR
|
||||||
|
```
|
||||||
|
|
||||||
*FW_JUMP* Example
|
*FW_JUMP* Example
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ firmware and the booting stage to follow OpenSBI firmware.
|
|||||||
A *FW_PAYLOAD* firmware is also useful for cases where the booting stage prior
|
A *FW_PAYLOAD* firmware is also useful for cases where the booting stage prior
|
||||||
to the OpenSBI firmware does not pass a *flattened device tree (FDT file)*. In
|
to the OpenSBI firmware does not pass a *flattened device tree (FDT file)*. In
|
||||||
such a case, a *FW_PAYLOAD* firmware allows embedding a flattened device tree
|
such a case, a *FW_PAYLOAD* firmware allows embedding a flattened device tree
|
||||||
in the .text section of the final firmware.
|
in the .rodata section of the final firmware.
|
||||||
|
|
||||||
Enabling *FW_PAYLOAD* compilation
|
Enabling *FW_PAYLOAD* compilation
|
||||||
---------------------------------
|
---------------------------------
|
||||||
@@ -20,7 +20,7 @@ Enabling *FW_PAYLOAD* compilation
|
|||||||
The *FW_PAYLOAD* firmware can be enabled by any of the following methods:
|
The *FW_PAYLOAD* firmware can be enabled by any of the following methods:
|
||||||
|
|
||||||
1. Specifying `FW_PAYLOAD=y` on the top level `make` command line.
|
1. Specifying `FW_PAYLOAD=y` on the top level `make` command line.
|
||||||
2. Specifying `FW_PAYLOAD=y` in the target platform *config.mk* configuration
|
2. Specifying `FW_PAYLOAD=y` in the target platform *objects.mk* configuration
|
||||||
file.
|
file.
|
||||||
|
|
||||||
The compiled *FW_PAYLOAD* firmware ELF file is named *fw_jump.elf*. Its
|
The compiled *FW_PAYLOAD* firmware ELF file is named *fw_jump.elf*. Its
|
||||||
@@ -33,7 +33,7 @@ Configuration Options
|
|||||||
|
|
||||||
A *FW_PAYLOAD* firmware is built according to configuration parameters and
|
A *FW_PAYLOAD* firmware is built according to configuration parameters and
|
||||||
options. These configuration parameters can be defined using either the top
|
options. These configuration parameters can be defined using either the top
|
||||||
level `make` command line or the target platform *config.mk* configuration
|
level `make` command line or the target platform *objects.mk* configuration
|
||||||
file. The parameters currently defined are as follows:
|
file. The parameters currently defined are as follows:
|
||||||
|
|
||||||
* **FW_PAYLOAD_OFFSET** - Offset from *FW_TEXT_BASE* where the payload binary
|
* **FW_PAYLOAD_OFFSET** - Offset from *FW_TEXT_BASE* where the payload binary
|
||||||
|
|||||||
@@ -8,11 +8,7 @@ OpenSBI provides two types of static libraries:
|
|||||||
hooks for the execution of this interface must be provided by the firmware or
|
hooks for the execution of this interface must be provided by the firmware or
|
||||||
bootloader linking with this library. This library is installed as
|
bootloader linking with this library. This library is installed as
|
||||||
*<install_directory>/lib/libsbi.a*
|
*<install_directory>/lib/libsbi.a*
|
||||||
2. *libsbiutils.a* - A static library that will contain all common code required
|
2. *libplatsbi.a* - An example platform-specific static library integrating
|
||||||
by any platform supported in OpenSBI. It will be built by default and included
|
|
||||||
in libplatsbi.a. This library is installed as
|
|
||||||
*<install_directory>/lib/libsbiutils.a*.
|
|
||||||
3. *libplatsbi.a* - An example platform-specific static library integrating
|
|
||||||
*libsbi.a* with platform-specific hooks. This library is available only for
|
*libsbi.a* with platform-specific hooks. This library is available only for
|
||||||
the platforms supported by OpenSBI. This library is installed as
|
the platforms supported by OpenSBI. This library is installed as
|
||||||
*<install_directory>/platform/<platform_subdir>/lib/libplatsbi.a*
|
*<install_directory>/platform/<platform_subdir>/lib/libplatsbi.a*
|
||||||
@@ -77,7 +73,7 @@ firmware drivers based on the external firmware architecture.
|
|||||||
**OPENSBI_EXTERNAL_SBI_TYPES** identifier is introduced to *sbi_types.h* for selecting
|
**OPENSBI_EXTERNAL_SBI_TYPES** identifier is introduced to *sbi_types.h* for selecting
|
||||||
external header file during the build preprocess in order to define OpensSBI data types
|
external header file during the build preprocess in order to define OpensSBI data types
|
||||||
based on external firmware data type binding.
|
based on external firmware data type binding.
|
||||||
For example, *bool* is declared as *int* in sbi_types.h. However in EDK2 build system,
|
For example, *bool* is declared as *int* in sbi_types.h. However, in EDK2 build system,
|
||||||
*bool* is declared as *BOOLEAN* which is defined as *unsigned char* data type.
|
*bool* is declared as *BOOLEAN* which is defined as *unsigned char* data type.
|
||||||
|
|
||||||
External firmware can define **OPENSBI_EXTERNAL_SBI_TYPES** in CFLAGS and specify it to the
|
External firmware can define **OPENSBI_EXTERNAL_SBI_TYPES** in CFLAGS and specify it to the
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ AHB/APB IPs suites a majority embedded systems, and the verified platform serves
|
|||||||
as a starting point to jump start SoC designs.
|
as a starting point to jump start SoC designs.
|
||||||
|
|
||||||
To build platform specific library and firmwares, provide the
|
To build platform specific library and firmwares, provide the
|
||||||
*PLATFORM=andes/ae350* parameter to the top level make command.
|
*PLATFORM=generic* parameter to the top level `make` command.
|
||||||
|
|
||||||
Platform Options
|
Platform Options
|
||||||
----------------
|
----------------
|
||||||
@@ -18,13 +18,190 @@ The Andes AE350 platform does not have any platform-specific options.
|
|||||||
Building Andes AE350 Platform
|
Building Andes AE350 Platform
|
||||||
-----------------------------
|
-----------------------------
|
||||||
|
|
||||||
To use Linux v5.2 should be used to build Andes AE350 OpenSBI binaries by using
|
AE350's dts is included in https://github.com/andestech/linux/tree/RISCV-Linux-5.4-ast-v5_1_0-branch
|
||||||
the compile time option FW_FDT_PATH.
|
|
||||||
|
|
||||||
AE350's dts is included in https://github.com/andestech/linux/tree/ast-v3_2_0-release-public
|
|
||||||
|
|
||||||
**Linux Kernel Payload**
|
**Linux Kernel Payload**
|
||||||
|
|
||||||
```
|
```
|
||||||
make PLATFORM=andes/ae350 FW_PAYLOAD_PATH=<linux_build_directory>/arch/riscv/boot/Image FW_FDT_PATH=<ae350.dtb path>
|
make PLATFORM=generic FW_PAYLOAD_PATH=<linux_build_directory>/arch/riscv/boot/Image FW_FDT_PATH=<ae350.dtb path>
|
||||||
|
```
|
||||||
|
|
||||||
|
DTS Example: (Quad-core AX45MP)
|
||||||
|
-------------------------------
|
||||||
|
|
||||||
|
```
|
||||||
|
compatible = "andestech,ae350";
|
||||||
|
cpus {
|
||||||
|
#address-cells = <1>;
|
||||||
|
#size-cells = <0>;
|
||||||
|
timebase-frequency = <60000000>;
|
||||||
|
|
||||||
|
CPU0: cpu@0 {
|
||||||
|
device_type = "cpu";
|
||||||
|
reg = <0>;
|
||||||
|
status = "okay";
|
||||||
|
compatible = "riscv";
|
||||||
|
riscv,isa = "rv64imafdc";
|
||||||
|
riscv,priv-major = <1>;
|
||||||
|
riscv,priv-minor = <10>;
|
||||||
|
mmu-type = "riscv,sv48";
|
||||||
|
clock-frequency = <60000000>;
|
||||||
|
i-cache-size = <0x8000>;
|
||||||
|
i-cache-sets = <256>;
|
||||||
|
i-cache-line-size = <64>;
|
||||||
|
i-cache-block-size = <64>;
|
||||||
|
d-cache-size = <0x8000>;
|
||||||
|
d-cache-sets = <128>;
|
||||||
|
d-cache-line-size = <64>;
|
||||||
|
d-cache-block-size = <64>;
|
||||||
|
next-level-cache = <&L2>;
|
||||||
|
CPU0_intc: interrupt-controller {
|
||||||
|
#interrupt-cells = <1>;
|
||||||
|
interrupt-controller;
|
||||||
|
compatible = "riscv,cpu-intc";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
CPU1: cpu@1 {
|
||||||
|
device_type = "cpu";
|
||||||
|
reg = <1>;
|
||||||
|
status = "okay";
|
||||||
|
compatible = "riscv";
|
||||||
|
riscv,isa = "rv64imafdc";
|
||||||
|
riscv,priv-major = <1>;
|
||||||
|
riscv,priv-minor = <10>;
|
||||||
|
mmu-type = "riscv,sv48";
|
||||||
|
clock-frequency = <60000000>;
|
||||||
|
i-cache-size = <0x8000>;
|
||||||
|
i-cache-sets = <256>;
|
||||||
|
i-cache-line-size = <64>;
|
||||||
|
i-cache-block-size = <64>;
|
||||||
|
d-cache-size = <0x8000>;
|
||||||
|
d-cache-sets = <128>;
|
||||||
|
d-cache-line-size = <64>;
|
||||||
|
d-cache-block-size = <64>;
|
||||||
|
next-level-cache = <&L2>;
|
||||||
|
CPU1_intc: interrupt-controller {
|
||||||
|
#interrupt-cells = <1>;
|
||||||
|
interrupt-controller;
|
||||||
|
compatible = "riscv,cpu-intc";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
CPU2: cpu@2 {
|
||||||
|
device_type = "cpu";
|
||||||
|
reg = <2>;
|
||||||
|
status = "okay";
|
||||||
|
compatible = "riscv";
|
||||||
|
riscv,isa = "rv64imafdc";
|
||||||
|
riscv,priv-major = <1>;
|
||||||
|
riscv,priv-minor = <10>;
|
||||||
|
mmu-type = "riscv,sv48";
|
||||||
|
clock-frequency = <60000000>;
|
||||||
|
i-cache-size = <0x8000>;
|
||||||
|
i-cache-sets = <256>;
|
||||||
|
i-cache-line-size = <64>;
|
||||||
|
i-cache-block-size = <64>;
|
||||||
|
d-cache-size = <0x8000>;
|
||||||
|
d-cache-sets = <128>;
|
||||||
|
d-cache-line-size = <64>;
|
||||||
|
d-cache-block-size = <64>;
|
||||||
|
next-level-cache = <&L2>;
|
||||||
|
CPU2_intc: interrupt-controller {
|
||||||
|
#interrupt-cells = <1>;
|
||||||
|
interrupt-controller;
|
||||||
|
compatible = "riscv,cpu-intc";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
CPU3: cpu@3 {
|
||||||
|
device_type = "cpu";
|
||||||
|
reg = <3>;
|
||||||
|
status = "okay";
|
||||||
|
compatible = "riscv";
|
||||||
|
riscv,isa = "rv64imafdc";
|
||||||
|
riscv,priv-major = <1>;
|
||||||
|
riscv,priv-minor = <10>;
|
||||||
|
mmu-type = "riscv,sv48";
|
||||||
|
clock-frequency = <60000000>;
|
||||||
|
i-cache-size = <0x8000>;
|
||||||
|
i-cache-sets = <256>;
|
||||||
|
i-cache-line-size = <64>;
|
||||||
|
i-cache-block-size = <64>;
|
||||||
|
d-cache-size = <0x8000>;
|
||||||
|
d-cache-sets = <128>;
|
||||||
|
d-cache-line-size = <64>;
|
||||||
|
d-cache-block-size = <64>;
|
||||||
|
next-level-cache = <&L2>;
|
||||||
|
CPU3_intc: interrupt-controller {
|
||||||
|
#interrupt-cells = <1>;
|
||||||
|
interrupt-controller;
|
||||||
|
compatible = "riscv,cpu-intc";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
soc {
|
||||||
|
#address-cells = <2>;
|
||||||
|
#size-cells = <2>;
|
||||||
|
compatible = "andestech,riscv-ae350-soc", "simple-bus";
|
||||||
|
ranges;
|
||||||
|
|
||||||
|
plic0: interrupt-controller@e4000000 {
|
||||||
|
compatible = "riscv,plic0";
|
||||||
|
reg = <0x00000000 0xe4000000 0x00000000 0x02000000>;
|
||||||
|
interrupts-extended = < &CPU0_intc 11 &CPU0_intc 9
|
||||||
|
&CPU1_intc 11 &CPU1_intc 9
|
||||||
|
&CPU2_intc 11 &CPU2_intc 9
|
||||||
|
&CPU3_intc 11 &CPU3_intc 9 >;
|
||||||
|
interrupt-controller;
|
||||||
|
#address-cells = <2>;
|
||||||
|
#interrupt-cells = <2>;
|
||||||
|
riscv,ndev = <71>;
|
||||||
|
};
|
||||||
|
|
||||||
|
plicsw: interrupt-controller@e6400000 {
|
||||||
|
compatible = "andestech,plicsw";
|
||||||
|
reg = <0x00000000 0xe6400000 0x00000000 0x00400000>;
|
||||||
|
interrupts-extended = < &CPU0_intc 3
|
||||||
|
&CPU1_intc 3
|
||||||
|
&CPU2_intc 3
|
||||||
|
&CPU3_intc 3 >;
|
||||||
|
interrupt-controller;
|
||||||
|
#address-cells = <2>;
|
||||||
|
#interrupt-cells = <2>;
|
||||||
|
};
|
||||||
|
|
||||||
|
plmt0: plmt0@e6000000 {
|
||||||
|
compatible = "andestech,plmt0";
|
||||||
|
reg = <0x00000000 0xe6000000 0x00000000 0x00100000>;
|
||||||
|
interrupts-extended = < &CPU0_intc 7
|
||||||
|
&CPU1_intc 7
|
||||||
|
&CPU2_intc 7
|
||||||
|
&CPU3_intc 7 >;
|
||||||
|
};
|
||||||
|
|
||||||
|
wdt: watchdog@f0500000 {
|
||||||
|
compatible = "andestech,atcwdt200";
|
||||||
|
reg = <0x00000000 0xf0500000 0x00000000 0x00001000>;
|
||||||
|
interrupts = <3 4>;
|
||||||
|
interrupt-parent = <&plic0>;
|
||||||
|
clock-frequency = <15000000>;
|
||||||
|
};
|
||||||
|
|
||||||
|
serial0: serial@f0300000 {
|
||||||
|
compatible = "andestech,uart16550", "ns16550a";
|
||||||
|
reg = <0x00000000 0xf0300000 0x00000000 0x00001000>;
|
||||||
|
interrupts = <9 4>;
|
||||||
|
interrupt-parent = <&plic0>;
|
||||||
|
clock-frequency = <19660800>;
|
||||||
|
current-speed = <38400>;
|
||||||
|
reg-shift = <2>;
|
||||||
|
reg-offset = <32>;
|
||||||
|
reg-io-width = <4>;
|
||||||
|
no-loopback-test = <1>;
|
||||||
|
};
|
||||||
|
|
||||||
|
smu: smu@f0100000 {
|
||||||
|
compatible = "andestech,atcsmu";
|
||||||
|
reg = <0x00000000 0xf0100000 0x00000000 0x00001000>;
|
||||||
|
};
|
||||||
|
};
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Linux.
|
|||||||
|
|
||||||
The FPGA SoC currently contains the following peripherals:
|
The FPGA SoC currently contains the following peripherals:
|
||||||
- DDR3 memory controller
|
- DDR3 memory controller
|
||||||
- SPI controller to conncet to an SDCard
|
- SPI controller to connect to an SDCard
|
||||||
- Ethernet controller
|
- Ethernet controller
|
||||||
- JTAG port (see debugging section below)
|
- JTAG port (see debugging section below)
|
||||||
- Bootrom containing zero stage bootloader and device tree.
|
- Bootrom containing zero stage bootloader and device tree.
|
||||||
|
|||||||
@@ -45,13 +45,17 @@ The *Generic* platform does not have any platform-specific options.
|
|||||||
RISC-V Platforms Using Generic Platform
|
RISC-V Platforms Using Generic Platform
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
|
* **Andes AE350 Platform** (*[andes-ae350.md]*)
|
||||||
* **QEMU RISC-V Virt Machine** (*[qemu_virt.md]*)
|
* **QEMU RISC-V Virt Machine** (*[qemu_virt.md]*)
|
||||||
|
* **Renesas RZ/Five SoC** (*[renesas-rzfive.md]*)
|
||||||
* **Shakti C-class SoC Platform** (*[shakti_cclass.md]*)
|
* **Shakti C-class SoC Platform** (*[shakti_cclass.md]*)
|
||||||
* **SiFive HiFive Unleashed** (*[sifive_fu540.md]*)
|
* **SiFive HiFive Unleashed** (*[sifive_fu540.md]*)
|
||||||
* **Spike** (*[spike.md]*)
|
* **Spike** (*[spike.md]*)
|
||||||
* **T-HEAD C9xx series Processors** (*[thead-c9xx.md]*)
|
* **T-HEAD C9xx series Processors** (*[thead-c9xx.md]*)
|
||||||
|
|
||||||
|
[andes-ae350.md]: andes-ae350.md
|
||||||
[qemu_virt.md]: qemu_virt.md
|
[qemu_virt.md]: qemu_virt.md
|
||||||
|
[renesas-rzfive.md]: renesas-rzfive.md
|
||||||
[shakti_cclass.md]: shakti_cclass.md
|
[shakti_cclass.md]: shakti_cclass.md
|
||||||
[sifive_fu540.md]: sifive_fu540.md
|
[sifive_fu540.md]: sifive_fu540.md
|
||||||
[spike.md]: spike.md
|
[spike.md]: spike.md
|
||||||
|
|||||||
@@ -39,11 +39,15 @@ OpenSBI currently supports the following virtual and hardware platforms:
|
|||||||
processor based SOCs. More details on this platform can be found in the
|
processor based SOCs. More details on this platform can be found in the
|
||||||
file *[shakti_cclass.md]*.
|
file *[shakti_cclass.md]*.
|
||||||
|
|
||||||
|
* **Renesas RZ/Five SoC**: Platform support for Renesas RZ/Five (R9A07G043F) SoC
|
||||||
|
used on the Renesas RZ/Five SMARC EVK board. More details on this platform can
|
||||||
|
be found in the file *[renesas-rzfive.md]*.
|
||||||
|
|
||||||
The code for these supported platforms can be used as example to implement
|
The code for these supported platforms can be used as example to implement
|
||||||
support for other platforms. The *platform/template* directory also provides
|
support for other platforms. The *platform/template* directory also provides
|
||||||
template files for implementing support for a new platform. The *object.mk*,
|
template files for implementing support for a new platform. The *objects.mk*,
|
||||||
*config.mk* and *platform.c* template files provides enough comments to
|
*Kconfig*, *configs/defconfig* and *platform.c* template files provides enough
|
||||||
facilitate the implementation.
|
comments to facilitate the implementation.
|
||||||
|
|
||||||
[generic.md]: generic.md
|
[generic.md]: generic.md
|
||||||
[qemu_virt.md]: qemu_virt.md
|
[qemu_virt.md]: qemu_virt.md
|
||||||
@@ -54,3 +58,4 @@ facilitate the implementation.
|
|||||||
[spike.md]: spike.md
|
[spike.md]: spike.md
|
||||||
[fpga-openpiton.md]: fpga-openpiton.md
|
[fpga-openpiton.md]: fpga-openpiton.md
|
||||||
[shakti_cclass.md]: shakti_cclass.md
|
[shakti_cclass.md]: shakti_cclass.md
|
||||||
|
[renesas-rzfive.md]: renesas-rzfive.md
|
||||||
|
|||||||
160
docs/platform/renesas-rzfive.md
Normal file
160
docs/platform/renesas-rzfive.md
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
Renesas RZ/Five SoC (R9A07G043F) Platform
|
||||||
|
=========================================
|
||||||
|
The RZ/Five microprocessor includes a single RISC-V CPU Core (Andes AX45MP)
|
||||||
|
1.0 GHz, 16-bit DDR3L/DDR4 interface. Supported interfaces include:
|
||||||
|
- Memory controller for DDR4-1600 / DDR3L-1333 with 16 bits
|
||||||
|
- System RAM (RAM of 128 Kbytes (ECC))
|
||||||
|
- SPI Multi I/O Bus Controller 1ch
|
||||||
|
- SD Card Host Interface/Multimedia Card Interface (SD/MMC) 2ch
|
||||||
|
- Serial Sound Interface (SSI) 4ch
|
||||||
|
- Sampling Rate Converter (SRC) 1ch
|
||||||
|
- USB2.0 host/function interface 2ch (ch0: Host-Function ch1: Host only)
|
||||||
|
- Gigabit Ethernet Interface (GbE) 2ch
|
||||||
|
- Controller Area Network Interface (CAN) 2ch (CAN-FD ISO 11898-1 (CD2014) compliant)
|
||||||
|
- Multi-function Timer Pulse Unit 3 (MTU3a) 9 ch (16 bits × 8 channels, 32 bits × 1 channel)
|
||||||
|
- Port Output Enable 3 (POE3)
|
||||||
|
- Watchdog Timer (WDT) 1ch
|
||||||
|
- General Timer (GTM) 3ch (32bits)
|
||||||
|
- I2C Bus Interface (I2C) 4ch
|
||||||
|
- Serial Communication Interface with FIFO (SCIFA) 5ch
|
||||||
|
- Serial Communication Interface (SCI) 2ch
|
||||||
|
- Renesas Serial Peripheral Interface (RSPI) 3ch
|
||||||
|
- A/D Converter (ADC) 2ch
|
||||||
|
making it ideal for applications such as entry-class social infrastructure
|
||||||
|
gateway control and industrial gateway control. More details can be found at
|
||||||
|
below link [0].
|
||||||
|
|
||||||
|
[0] https://www.renesas.com/us/en/products/microcontrollers-microprocessors/rz-mpus/rzfive-general-purpose-microprocessors-risc-v-cpu-core-andes-ax45mp-single-10-ghz-2ch-gigabit-ethernet
|
||||||
|
|
||||||
|
To build platform specific library and firmwares, provide the
|
||||||
|
*PLATFORM=generic* parameter to the top level make command.
|
||||||
|
|
||||||
|
Platform Options
|
||||||
|
----------------
|
||||||
|
|
||||||
|
The Renesas RZ/Five platform does not have any platform-specific options.
|
||||||
|
|
||||||
|
Building Renesas RZ/Five Platform
|
||||||
|
---------------------------------
|
||||||
|
|
||||||
|
```
|
||||||
|
make PLATFORM=generic
|
||||||
|
```
|
||||||
|
|
||||||
|
DTS Example: (RZ/Five AX45MP)
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
```
|
||||||
|
compatible = "renesas,r9a07g043f01", "renesas,r9a07g043";
|
||||||
|
|
||||||
|
cpus {
|
||||||
|
#address-cells = <1>;
|
||||||
|
#size-cells = <0>;
|
||||||
|
timebase-frequency = <12000000>;
|
||||||
|
|
||||||
|
cpu0: cpu@0 {
|
||||||
|
compatible = "andestech,ax45mp", "riscv";
|
||||||
|
device_type = "cpu";
|
||||||
|
reg = <0x0>;
|
||||||
|
status = "okay";
|
||||||
|
riscv,isa = "rv64imafdc";
|
||||||
|
mmu-type = "riscv,sv39";
|
||||||
|
i-cache-size = <0x8000>;
|
||||||
|
i-cache-line-size = <0x40>;
|
||||||
|
d-cache-size = <0x8000>;
|
||||||
|
d-cache-line-size = <0x40>;
|
||||||
|
clocks = <&cpg CPG_CORE R9A07G043_CLK_I>;
|
||||||
|
|
||||||
|
cpu0_intc: interrupt-controller {
|
||||||
|
#interrupt-cells = <1>;
|
||||||
|
compatible = "riscv,cpu-intc";
|
||||||
|
interrupt-controller;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
soc {
|
||||||
|
compatible = "simple-bus";
|
||||||
|
#address-cells = <1>;
|
||||||
|
#size-cells = <0>;
|
||||||
|
ranges;
|
||||||
|
|
||||||
|
scif0: serial@1004b800 {
|
||||||
|
compatible = "renesas,scif-r9a07g043",
|
||||||
|
"renesas,scif-r9a07g044";
|
||||||
|
reg = <0 0x1004b800 0 0x400>;
|
||||||
|
interrupts = <412 IRQ_TYPE_LEVEL_HIGH>,
|
||||||
|
<414 IRQ_TYPE_LEVEL_HIGH>,
|
||||||
|
<415 IRQ_TYPE_LEVEL_HIGH>,
|
||||||
|
<413 IRQ_TYPE_LEVEL_HIGH>,
|
||||||
|
<416 IRQ_TYPE_LEVEL_HIGH>,
|
||||||
|
<416 IRQ_TYPE_LEVEL_HIGH>;
|
||||||
|
interrupt-names = "eri", "rxi", "txi",
|
||||||
|
"bri", "dri", "tei";
|
||||||
|
clocks = <&cpg CPG_MOD R9A07G043_SCIF0_CLK_PCK>;
|
||||||
|
clock-names = "fck";
|
||||||
|
power-domains = <&cpg>;
|
||||||
|
resets = <&cpg R9A07G043_SCIF0_RST_SYSTEM_N>;
|
||||||
|
status = "disabled";
|
||||||
|
};
|
||||||
|
|
||||||
|
cpg: clock-controller@11010000 {
|
||||||
|
compatible = "renesas,r9a07g043-cpg";
|
||||||
|
reg = <0 0x11010000 0 0x10000>;
|
||||||
|
clocks = <&extal_clk>;
|
||||||
|
clock-names = "extal";
|
||||||
|
#clock-cells = <2>;
|
||||||
|
#reset-cells = <1>;
|
||||||
|
#power-domain-cells = <0>;
|
||||||
|
};
|
||||||
|
|
||||||
|
sysc: system-controller@11020000 {
|
||||||
|
compatible = "renesas,r9a07g043-sysc";
|
||||||
|
reg = <0 0x11020000 0 0x10000>;
|
||||||
|
status = "disabled";
|
||||||
|
};
|
||||||
|
|
||||||
|
pinctrl: pinctrl@11030000 {
|
||||||
|
compatible = "renesas,r9a07g043-pinctrl";
|
||||||
|
reg = <0 0x11030000 0 0x10000>;
|
||||||
|
gpio-controller;
|
||||||
|
#gpio-cells = <2>;
|
||||||
|
#interrupt-cells = <2>;
|
||||||
|
interrupt-controller;
|
||||||
|
gpio-ranges = <&pinctrl 0 0 152>;
|
||||||
|
clocks = <&cpg CPG_MOD R9A07G043_GPIO_HCLK>;
|
||||||
|
power-domains = <&cpg>;
|
||||||
|
resets = <&cpg R9A07G043_GPIO_RSTN>,
|
||||||
|
<&cpg R9A07G043_GPIO_PORT_RESETN>,
|
||||||
|
<&cpg R9A07G043_GPIO_SPARE_RESETN>;
|
||||||
|
};
|
||||||
|
|
||||||
|
plmt0: plmt0@110c0000 {
|
||||||
|
compatible = "andestech,plmt0", "riscv,plmt0";
|
||||||
|
reg = <0x0 0x110c0000 0x0 0x10000>;
|
||||||
|
interrupts-extended = <&cpu0_intc 7>;
|
||||||
|
};
|
||||||
|
|
||||||
|
plic: interrupt-controller@12c00000 {
|
||||||
|
compatible = "renesas,r9a07g043-plic", "andestech,nceplic100";
|
||||||
|
#interrupt-cells = <2>;
|
||||||
|
#address-cells = <0>;
|
||||||
|
riscv,ndev = <511>;
|
||||||
|
interrupt-controller;
|
||||||
|
reg = <0x0 0x12c00000 0x0 0x400000>;
|
||||||
|
clocks = <&cpg CPG_MOD R9A07G043_NCEPLIC_ACLK>;
|
||||||
|
power-domains = <&cpg>;
|
||||||
|
resets = <&cpg R9A07G043_NCEPLIC_ARESETN>;
|
||||||
|
interrupts-extended = <&cpu0_intc 11 &cpu0_intc 9>;
|
||||||
|
};
|
||||||
|
|
||||||
|
plicsw: interrupt-controller@13000000 {
|
||||||
|
compatible = "andestech,plicsw";
|
||||||
|
reg = <0x0 0x13000000 0x0 0x400000>;
|
||||||
|
interrupts-extended = <&cpu0_intc 3>;
|
||||||
|
interrupt-controller;
|
||||||
|
#address-cells = <2>;
|
||||||
|
#interrupt-cells = <2>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
```
|
||||||
@@ -150,7 +150,7 @@ If you want to test OpenSBI with QEMU 'sifive_u' machine, please follow the
|
|||||||
same instructions above, with the exception of not passing FW_FDT_PATH.
|
same instructions above, with the exception of not passing FW_FDT_PATH.
|
||||||
|
|
||||||
This is because QEMU generates a device tree blob on the fly based on the
|
This is because QEMU generates a device tree blob on the fly based on the
|
||||||
command line parameters and it's compatible with the one used in the upstream
|
command line parameters, and it's compatible with the one used in the upstream
|
||||||
Linux kernel.
|
Linux kernel.
|
||||||
|
|
||||||
When U-Boot v2021.07 (or higher) is used as the payload, as the SiFive FU540
|
When U-Boot v2021.07 (or higher) is used as the payload, as the SiFive FU540
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ Platform Options
|
|||||||
----------------
|
----------------
|
||||||
|
|
||||||
The *T-HEAD C9xx* does not have any platform-specific compile options
|
The *T-HEAD C9xx* does not have any platform-specific compile options
|
||||||
because it use generic platform.
|
because it uses generic platform.
|
||||||
|
|
||||||
```
|
```
|
||||||
CROSS_COMPILE=riscv64-linux-gnu- PLATFORM=generic /usr/bin/make
|
CROSS_COMPILE=riscv64-linux-gnu- PLATFORM=generic /usr/bin/make
|
||||||
@@ -52,12 +52,11 @@ DTS Example1: (Single core, eg: Allwinner D1 - c906)
|
|||||||
ranges;
|
ranges;
|
||||||
|
|
||||||
clint0: clint@14000000 {
|
clint0: clint@14000000 {
|
||||||
compatible = "riscv,clint0";
|
compatible = "allwinner,sun20i-d1-clint";
|
||||||
interrupts-extended = <
|
interrupts-extended = <
|
||||||
&cpu0_intc 3 &cpu0_intc 7
|
&cpu0_intc 3 &cpu0_intc 7
|
||||||
>;
|
>;
|
||||||
reg = <0x0 0x14000000 0x0 0x04000000>;
|
reg = <0x0 0x14000000 0x0 0x04000000>;
|
||||||
clint,has-no-64bit-mmio;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
intc: interrupt-controller@10000000 {
|
intc: interrupt-controller@10000000 {
|
||||||
@@ -163,7 +162,6 @@ DTS Example2: (Multi cores with soc reset-regs)
|
|||||||
&cpu4_intc 3 &cpu4_intc 7
|
&cpu4_intc 3 &cpu4_intc 7
|
||||||
>;
|
>;
|
||||||
reg = <0xff 0xdc000000 0x0 0x04000000>;
|
reg = <0xff 0xdc000000 0x0 0x04000000>;
|
||||||
clint,has-no-64bit-mmio;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
intc: interrupt-controller@ffd8000000 {
|
intc: interrupt-controller@ffd8000000 {
|
||||||
|
|||||||
@@ -28,11 +28,12 @@ Adding support for a new platform
|
|||||||
Support for a new platform named *<xyz>* can be added as follows:
|
Support for a new platform named *<xyz>* can be added as follows:
|
||||||
|
|
||||||
1. Create a directory named *<xyz>* under the *platform/* directory.
|
1. Create a directory named *<xyz>* under the *platform/* directory.
|
||||||
2. Create a platform configuration file named *config.mk* under the
|
2. Create platform configuration files named *Kconfig* and *configs/defconfig*
|
||||||
*platform/<xyz>/* directory. This configuration file will provide
|
under the *platform/<xyz>/* directory. These configuration files will
|
||||||
|
provide the build time configuration for the sources to be compiled.
|
||||||
|
3. Create a *platform/<xyz>/objects.mk* file for listing the platform
|
||||||
|
object files to be compiled. This file also provides platform-specific
|
||||||
compiler flags, and select firmware options.
|
compiler flags, and select firmware options.
|
||||||
3. Create a *platform/<xyz>/objects.mk* file for listing the
|
|
||||||
platform-specific object files to be compiled.
|
|
||||||
4. Create a *platform/<xyz>/platform.c* file providing a
|
4. Create a *platform/<xyz>/platform.c* file providing a
|
||||||
*struct sbi_platform* instance.
|
*struct sbi_platform* instance.
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ To handle this, we have two types of RISC-V platform requirements:
|
|||||||
2. **Release specific platform requirements** which apply to a OpenSBI
|
2. **Release specific platform requirements** which apply to a OpenSBI
|
||||||
release and later releases
|
release and later releases
|
||||||
|
|
||||||
Currently, we don't have any **Release specific platform requirements**
|
Currently, we don't have any **Release specific platform requirements**,
|
||||||
but such platform requirements will be added in future.
|
but such platform requirements will be added in future.
|
||||||
|
|
||||||
Base Platform Requirements
|
Base Platform Requirements
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
OpenSBI SBI PMU extension support
|
OpenSBI SBI PMU extension support
|
||||||
==================================
|
==================================
|
||||||
SBI PMU extension supports allow supervisor software to configure/start/stop
|
SBI PMU extension supports allow supervisor software to configure/start/stop
|
||||||
any performance counter at anytime. Thus, an user can leverage full
|
any performance counter at anytime. Thus, a user can leverage full
|
||||||
capability of performance analysis tools such as perf if SBI PMU extension is
|
capability of performance analysis tools such as perf if SBI PMU extension is
|
||||||
enabled. The OpenSBI implementation makes the following assumptions about the
|
enabled. The OpenSBI implementation makes the following assumptions about the
|
||||||
hardware platform.
|
hardware platform.
|
||||||
|
|
||||||
* MCOUNTINHIBIT CSR must be implemented in the hardware. Otherwise, SBI PMU
|
|
||||||
extension will not be enabled.
|
|
||||||
|
|
||||||
* The platform must provide information about PMU event to counter mapping
|
* The platform must provide information about PMU event to counter mapping
|
||||||
via device tree or platform specific hooks. Otherwise, SBI PMU extension will
|
via device tree or platform specific hooks. Otherwise, SBI PMU extension will
|
||||||
not be enabled.
|
not be enabled.
|
||||||
@@ -25,7 +22,7 @@ SBI PMU Device Tree Bindings
|
|||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
Platforms may choose to describe PMU event selector and event to counter mapping
|
Platforms may choose to describe PMU event selector and event to counter mapping
|
||||||
values via device tree. The following sections describes the PMU DT node
|
values via device tree. The following sections describe the PMU DT node
|
||||||
bindings in details.
|
bindings in details.
|
||||||
|
|
||||||
* **compatible** (Mandatory) - The compatible string of SBI PMU device tree node.
|
* **compatible** (Mandatory) - The compatible string of SBI PMU device tree node.
|
||||||
@@ -42,46 +39,89 @@ This property shouldn't encode any raw hardware event.
|
|||||||
* **riscv,event-to-mhpmcounters**(Optional) - It represents a MANY-to-MANY
|
* **riscv,event-to-mhpmcounters**(Optional) - It represents a MANY-to-MANY
|
||||||
mapping between a range of events and all the MHPMCOUNTERx in a bitmap format
|
mapping between a range of events and all the MHPMCOUNTERx in a bitmap format
|
||||||
that can be used to monitor these range of events. The information is encoded in
|
that can be used to monitor these range of events. The information is encoded in
|
||||||
a table format where each row represent a certain range of events and
|
a table format where each row represents a certain range of events and
|
||||||
corresponding counters. The first column represents starting of the pmu event id
|
corresponding counters. The first column represents starting of the pmu event id
|
||||||
and 2nd column represents the end of the pmu event id. The third column
|
and 2nd column represents the end of the pmu event id. The third column
|
||||||
represent a bitmap of all the MHPMCOUNTERx. This property is mandatory if
|
represent a bitmap of all the MHPMCOUNTERx. This property is mandatory if
|
||||||
event-to-mhpmevent is present. Otherwise, it can be omitted. This property
|
riscv,event-to-mhpmevent is present. Otherwise, it can be omitted. This property
|
||||||
shouldn't encode any raw event.
|
shouldn't encode any raw event.
|
||||||
|
|
||||||
* **riscv,raw-event-to-mhpmcounters**(Optional) - It represents an ONE-to-MANY
|
* **riscv,raw-event-to-mhpmcounters**(Optional) - It represents an ONE-to-MANY
|
||||||
or MANY-to-MANY mapping between the raw event(s) and all the MHPMCOUNTERx in
|
or MANY-to-MANY mapping between the raw event(s) and all the MHPMCOUNTERx in
|
||||||
a bitmap format that can be used to monitor that raw event, which depends on
|
a bitmap format that can be used to monitor that raw event. The encoding of the
|
||||||
how the platform encodes the monitor events. Currently, only the following three
|
raw events are platform specific. The information is encoded in a table format
|
||||||
encoding methods are supported, encoding each event as a number, using a bitmap
|
where each row represents the specific raw event(s). The first column is a 64bit
|
||||||
to encode monitor events, and mixing the previous two methods. The information
|
match value where the invariant bits of range of events are set. The second
|
||||||
is encoded in a table format where each row represent the specific raw event(s).
|
column is a 64 bit mask that will have all the variant bits of the range of
|
||||||
The first column represents a 64-bit selector value which can indicate an
|
events cleared. All other bits should be set in the mask.
|
||||||
monitor event ID (encoded by a number) or an event set (encoded by a bitmap).
|
The third column is a 32bit value to represent bitmap of all MHPMCOUNTERx that
|
||||||
In case of the latter, the lower bits used to encode a set of events should be
|
can monitor these set of event(s).
|
||||||
set to zero. The second column is a 64-bit selector mask where any bits used
|
If a platform directly encodes each raw PMU event as a unique ID, the value of
|
||||||
for event encoding will be cleared. If a platform directly encodes each raw PMU
|
select_mask must be 0xffffffff_ffffffff.
|
||||||
event as a unique ID, the value of select_mask will be 0xffffffff_ffffffff.
|
|
||||||
The third column represent a bitmap of all the MHPMCOUNTERx that can be used for
|
|
||||||
monitoring the specified event(s).
|
|
||||||
|
|
||||||
*Note:* A platform may choose to provide the mapping between event & counters
|
*Note:* A platform may choose to provide the mapping between event & counters
|
||||||
via platform hooks rather than the device tree.
|
via platform hooks rather than the device tree.
|
||||||
|
|
||||||
### Example
|
### Example 1
|
||||||
|
|
||||||
```
|
```
|
||||||
pmu {
|
pmu {
|
||||||
compatible = "riscv,pmu";
|
compatible = "riscv,pmu";
|
||||||
interrupts = <0x100>;
|
riscv,event-to-mhpmevent = <0x0000B 0x0000 0x0001>;
|
||||||
interrupt-parent = <&plic>
|
|
||||||
riscv,event-to-mhpmevent = <0x0000B 0x0000 0x0001>,
|
|
||||||
riscv,event-to-mhpmcounters = <0x00001 0x00001 0x00000001>,
|
riscv,event-to-mhpmcounters = <0x00001 0x00001 0x00000001>,
|
||||||
<0x00002 0x00002 0x00000004>,
|
<0x00002 0x00002 0x00000004>,
|
||||||
<0x00003 0x0000A 0x00000ff8>,
|
<0x00003 0x0000A 0x00000ff8>,
|
||||||
<0x10000 0x10033 0x000ff000>,
|
<0x10000 0x10033 0x000ff000>;
|
||||||
riscv,raw-event-to-mhpmcounters = <0x0000 0x0002 0xffffffff 0xffffffff 0x00000f8>,
|
/* For event ID 0x0002 */
|
||||||
<0xffffffff 0xfffffff0 0xffffffff 0xfffffff0 0x00000ff0>,
|
riscv,raw-event-to-mhpmcounters = <0x0000 0x0002 0xffffffff 0xffffffff 0x00000f8>,
|
||||||
|
/* For event ID 0-4 */
|
||||||
|
<0x0 0x0 0xffffffff 0xfffffff0 0x00000ff0>,
|
||||||
|
/* For event ID 0xffffffff0000000f - 0xffffffff000000ff */
|
||||||
|
<0xffffffff 0x0 0xffffffff 0xffffff0f 0x00000ff0>;
|
||||||
};
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example 2
|
||||||
|
|
||||||
```
|
```
|
||||||
|
/*
|
||||||
|
* For HiFive Unmatched board. The encodings can be found here
|
||||||
|
* https://sifive.cdn.prismic.io/sifive/1a82e600-1f93-4f41-b2d8-86ed8b16acba_fu740-c000-manual-v1p6.pdf
|
||||||
|
* This example also binds standard SBI PMU hardware id's to U74 PMU event codes, U74 uses bitfield for
|
||||||
|
* events encoding, so several U74 events can be bound to single perf id.
|
||||||
|
* See SBI PMU hardware id's in include/sbi/sbi_ecall_interface.h
|
||||||
|
*/
|
||||||
|
pmu {
|
||||||
|
compatible = "riscv,pmu";
|
||||||
|
riscv,event-to-mhpmevent =
|
||||||
|
/* SBI_PMU_HW_CACHE_REFERENCES -> Instruction cache/ITIM busy | Data cache/DTIM busy */
|
||||||
|
<0x00003 0x00000000 0x1801>,
|
||||||
|
/* SBI_PMU_HW_CACHE_MISSES -> Instruction cache miss | Data cache miss or memory-mapped I/O access */
|
||||||
|
<0x00004 0x00000000 0x0302>,
|
||||||
|
/* SBI_PMU_HW_BRANCH_INSTRUCTIONS -> Conditional branch retired */
|
||||||
|
<0x00005 0x00000000 0x4000>,
|
||||||
|
/* SBI_PMU_HW_BRANCH_MISSES -> Branch direction misprediction | Branch/jump target misprediction */
|
||||||
|
<0x00006 0x00000000 0x6001>,
|
||||||
|
/* L1D_READ_MISS -> Data cache miss or memory-mapped I/O access */
|
||||||
|
<0x10001 0x00000000 0x0202>,
|
||||||
|
/* L1D_WRITE_ACCESS -> Data cache write-back */
|
||||||
|
<0x10002 0x00000000 0x0402>,
|
||||||
|
/* L1I_READ_ACCESS -> Instruction cache miss */
|
||||||
|
<0x10009 0x00000000 0x0102>,
|
||||||
|
/* LL_READ_MISS -> UTLB miss */
|
||||||
|
<0x10011 0x00000000 0x2002>,
|
||||||
|
/* DTLB_READ_MISS -> Data TLB miss */
|
||||||
|
<0x10019 0x00000000 0x1002>,
|
||||||
|
/* ITLB_READ_MISS-> Instruction TLB miss */
|
||||||
|
<0x10021 0x00000000 0x0802>;
|
||||||
|
riscv,event-to-mhpmcounters = <0x00003 0x00006 0x18>,
|
||||||
|
<0x10001 0x10002 0x18>,
|
||||||
|
<0x10009 0x10009 0x18>,
|
||||||
|
<0x10011 0x10011 0x18>,
|
||||||
|
<0x10019 0x10019 0x18>,
|
||||||
|
<0x10021 0x10021 0x18>;
|
||||||
|
riscv,raw-event-to-mhpmcounters = <0x0 0x0 0xffffffff 0xfc0000ff 0x18>,
|
||||||
|
<0x0 0x1 0xffffffff 0xfff800ff 0x18>,
|
||||||
|
<0x0 0x2 0xffffffff 0xffffe0ff 0x18>;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|||||||
1
firmware/Kconfig
Normal file
1
firmware/Kconfig
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# SPDX-License-Identifier: BSD-2-Clause
|
||||||
@@ -128,9 +128,9 @@ _relocate:
|
|||||||
REG_L t1, 0(t1)
|
REG_L t1, 0(t1)
|
||||||
lla t2, _load_start
|
lla t2, _load_start
|
||||||
REG_L t2, 0(t2)
|
REG_L t2, 0(t2)
|
||||||
|
beq t0, t2, _relocate_done
|
||||||
sub t3, t1, t0
|
sub t3, t1, t0
|
||||||
add t3, t3, t2
|
add t3, t3, t2
|
||||||
beq t0, t2, _relocate_done
|
|
||||||
lla t4, _relocate_done
|
lla t4, _relocate_done
|
||||||
sub t4, t4, t2
|
sub t4, t4, t2
|
||||||
add t4, t4, t0
|
add t4, t4, t0
|
||||||
@@ -259,7 +259,7 @@ _bss_zero:
|
|||||||
* s8 -> HART Stack Size
|
* s8 -> HART Stack Size
|
||||||
*/
|
*/
|
||||||
lla a4, platform
|
lla a4, platform
|
||||||
#if __riscv_xlen == 64
|
#if __riscv_xlen > 32
|
||||||
lwu s7, SBI_PLATFORM_HART_COUNT_OFFSET(a4)
|
lwu s7, SBI_PLATFORM_HART_COUNT_OFFSET(a4)
|
||||||
lwu s8, SBI_PLATFORM_HART_STACK_SIZE_OFFSET(a4)
|
lwu s8, SBI_PLATFORM_HART_STACK_SIZE_OFFSET(a4)
|
||||||
#else
|
#else
|
||||||
@@ -298,6 +298,12 @@ _scratch_init:
|
|||||||
sub a5, t3, a4
|
sub a5, t3, a4
|
||||||
REG_S a4, SBI_SCRATCH_FW_START_OFFSET(tp)
|
REG_S a4, SBI_SCRATCH_FW_START_OFFSET(tp)
|
||||||
REG_S a5, SBI_SCRATCH_FW_SIZE_OFFSET(tp)
|
REG_S a5, SBI_SCRATCH_FW_SIZE_OFFSET(tp)
|
||||||
|
|
||||||
|
/* Store R/W section's offset in scratch space */
|
||||||
|
lla a4, __fw_rw_offset
|
||||||
|
REG_L a5, 0(a4)
|
||||||
|
REG_S a5, SBI_SCRATCH_FW_RW_OFFSET(tp)
|
||||||
|
|
||||||
/* Store next arg1 in scratch space */
|
/* Store next arg1 in scratch space */
|
||||||
MOV_3R s0, a0, s1, a1, s2, a2
|
MOV_3R s0, a0, s1, a1, s2, a2
|
||||||
call fw_next_arg1
|
call fw_next_arg1
|
||||||
@@ -422,9 +428,15 @@ _start_warm:
|
|||||||
li ra, 0
|
li ra, 0
|
||||||
call _reset_regs
|
call _reset_regs
|
||||||
|
|
||||||
/* Disable and clear all interrupts */
|
/* Disable all interrupts */
|
||||||
csrw CSR_MIE, zero
|
csrw CSR_MIE, zero
|
||||||
csrw CSR_MIP, zero
|
/*
|
||||||
|
* Only clear the MIP_SSIP and MIP_STIP. For the platform like QEMU,
|
||||||
|
* If we clear other interrupts like MIP_SEIP and the pendings of
|
||||||
|
* PLIC still exist, the QEMU may not set it back immediately.
|
||||||
|
*/
|
||||||
|
li t0, (MIP_SSIP | MIP_STIP)
|
||||||
|
csrc CSR_MIP, t0
|
||||||
|
|
||||||
/* Find HART count and HART stack size */
|
/* Find HART count and HART stack size */
|
||||||
lla a4, platform
|
lla a4, platform
|
||||||
@@ -455,7 +467,7 @@ _start_warm:
|
|||||||
blt a4, s7, 1b
|
blt a4, s7, 1b
|
||||||
li a4, -1
|
li a4, -1
|
||||||
2: add s6, a4, zero
|
2: add s6, a4, zero
|
||||||
3: bge s6, s7, _start_hang
|
3: bgeu s6, s7, _start_hang
|
||||||
|
|
||||||
/* Find the scratch space based on HART index */
|
/* Find the scratch space based on HART index */
|
||||||
lla tp, _fw_end
|
lla tp, _fw_end
|
||||||
@@ -519,6 +531,8 @@ _link_start:
|
|||||||
RISCV_PTR FW_TEXT_START
|
RISCV_PTR FW_TEXT_START
|
||||||
_link_end:
|
_link_end:
|
||||||
RISCV_PTR _fw_reloc_end
|
RISCV_PTR _fw_reloc_end
|
||||||
|
__fw_rw_offset:
|
||||||
|
RISCV_PTR _fw_rw_start - _fw_start
|
||||||
|
|
||||||
.section .entry, "ax", %progbits
|
.section .entry, "ax", %progbits
|
||||||
.align 3
|
.align 3
|
||||||
@@ -743,6 +757,8 @@ memcmp:
|
|||||||
.globl _trap_handler
|
.globl _trap_handler
|
||||||
.globl _trap_exit
|
.globl _trap_exit
|
||||||
_trap_handler:
|
_trap_handler:
|
||||||
|
sfence.vma zero, t0
|
||||||
|
|
||||||
TRAP_SAVE_AND_SETUP_SP_T0
|
TRAP_SAVE_AND_SETUP_SP_T0
|
||||||
|
|
||||||
TRAP_SAVE_MEPC_MSTATUS 0
|
TRAP_SAVE_MEPC_MSTATUS 0
|
||||||
|
|||||||
@@ -24,27 +24,49 @@
|
|||||||
PROVIDE(_text_end = .);
|
PROVIDE(_text_end = .);
|
||||||
}
|
}
|
||||||
|
|
||||||
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
|
||||||
|
|
||||||
/* End of the code sections */
|
/* End of the code sections */
|
||||||
|
|
||||||
|
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
||||||
|
|
||||||
/* Beginning of the read-only data sections */
|
/* Beginning of the read-only data sections */
|
||||||
|
|
||||||
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
PROVIDE(_rodata_start = .);
|
||||||
|
|
||||||
.rodata :
|
.rodata :
|
||||||
{
|
{
|
||||||
PROVIDE(_rodata_start = .);
|
|
||||||
*(.rodata .rodata.*)
|
*(.rodata .rodata.*)
|
||||||
. = ALIGN(8);
|
. = ALIGN(8);
|
||||||
PROVIDE(_rodata_end = .);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
||||||
|
|
||||||
|
.dynsym : {
|
||||||
|
PROVIDE(__dyn_sym_start = .);
|
||||||
|
*(.dynsym)
|
||||||
|
PROVIDE(__dyn_sym_end = .);
|
||||||
|
}
|
||||||
|
|
||||||
|
.rela.dyn : {
|
||||||
|
PROVIDE(__rel_dyn_start = .);
|
||||||
|
*(.rela*)
|
||||||
|
. = ALIGN(8);
|
||||||
|
PROVIDE(__rel_dyn_end = .);
|
||||||
|
}
|
||||||
|
|
||||||
|
PROVIDE(_rodata_end = .);
|
||||||
|
|
||||||
/* End of the read-only data sections */
|
/* End of the read-only data sections */
|
||||||
|
|
||||||
/* Beginning of the read-write data sections */
|
/*
|
||||||
|
* PMP regions must be to be power-of-2. RX/RW will have separate
|
||||||
|
* regions, so ensure that the split is power-of-2.
|
||||||
|
*/
|
||||||
|
. = ALIGN(1 << LOG2CEIL((SIZEOF(.rodata) + SIZEOF(.text)
|
||||||
|
+ SIZEOF(.dynsym) + SIZEOF(.rela.dyn))));
|
||||||
|
|
||||||
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
PROVIDE(_fw_rw_start = .);
|
||||||
|
|
||||||
|
/* Beginning of the read-write data sections */
|
||||||
|
|
||||||
.data :
|
.data :
|
||||||
{
|
{
|
||||||
@@ -61,19 +83,6 @@
|
|||||||
PROVIDE(_data_end = .);
|
PROVIDE(_data_end = .);
|
||||||
}
|
}
|
||||||
|
|
||||||
.dynsym : {
|
|
||||||
PROVIDE(__dyn_sym_start = .);
|
|
||||||
*(.dynsym)
|
|
||||||
PROVIDE(__dyn_sym_end = .);
|
|
||||||
}
|
|
||||||
|
|
||||||
.rela.dyn : {
|
|
||||||
PROVIDE(__rel_dyn_start = .);
|
|
||||||
*(.rela*)
|
|
||||||
. = ALIGN(8);
|
|
||||||
PROVIDE(__rel_dyn_end = .);
|
|
||||||
}
|
|
||||||
|
|
||||||
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
||||||
|
|
||||||
.bss :
|
.bss :
|
||||||
|
|||||||
@@ -33,14 +33,12 @@ SECTIONS
|
|||||||
PROVIDE(_text_end = .);
|
PROVIDE(_text_end = .);
|
||||||
}
|
}
|
||||||
|
|
||||||
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
|
||||||
|
|
||||||
/* End of the code sections */
|
/* End of the code sections */
|
||||||
|
|
||||||
/* Beginning of the read-only data sections */
|
|
||||||
|
|
||||||
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
||||||
|
|
||||||
|
/* Beginning of the read-only data sections */
|
||||||
|
|
||||||
.rodata :
|
.rodata :
|
||||||
{
|
{
|
||||||
PROVIDE(_rodata_start = .);
|
PROVIDE(_rodata_start = .);
|
||||||
@@ -51,10 +49,10 @@ SECTIONS
|
|||||||
|
|
||||||
/* End of the read-only data sections */
|
/* End of the read-only data sections */
|
||||||
|
|
||||||
/* Beginning of the read-write data sections */
|
|
||||||
|
|
||||||
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
||||||
|
|
||||||
|
/* Beginning of the read-write data sections */
|
||||||
|
|
||||||
.data :
|
.data :
|
||||||
{
|
{
|
||||||
PROVIDE(_data_start = .);
|
PROVIDE(_data_start = .);
|
||||||
|
|||||||
@@ -75,6 +75,41 @@ struct fw_dynamic_info {
|
|||||||
unsigned long boot_hart;
|
unsigned long boot_hart;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prevent modification of struct fw_dynamic_info from affecting
|
||||||
|
* FW_DYNAMIC_INFO_xxx_OFFSET
|
||||||
|
*/
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct fw_dynamic_info, magic)
|
||||||
|
== FW_DYNAMIC_INFO_MAGIC_OFFSET,
|
||||||
|
"struct fw_dynamic_info definition has changed, please redefine "
|
||||||
|
"FW_DYNAMIC_INFO_MAGIC_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct fw_dynamic_info, version)
|
||||||
|
== FW_DYNAMIC_INFO_VERSION_OFFSET,
|
||||||
|
"struct fw_dynamic_info definition has changed, please redefine "
|
||||||
|
"FW_DYNAMIC_INFO_VERSION_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct fw_dynamic_info, next_addr)
|
||||||
|
== FW_DYNAMIC_INFO_NEXT_ADDR_OFFSET,
|
||||||
|
"struct fw_dynamic_info definition has changed, please redefine "
|
||||||
|
"FW_DYNAMIC_INFO_NEXT_ADDR_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct fw_dynamic_info, next_mode)
|
||||||
|
== FW_DYNAMIC_INFO_NEXT_MODE_OFFSET,
|
||||||
|
"struct fw_dynamic_info definition has changed, please redefine "
|
||||||
|
"FW_DYNAMIC_INFO_NEXT_MODE_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct fw_dynamic_info, options)
|
||||||
|
== FW_DYNAMIC_INFO_OPTIONS_OFFSET,
|
||||||
|
"struct fw_dynamic_info definition has changed, please redefine "
|
||||||
|
"FW_DYNAMIC_INFO_OPTIONS_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct fw_dynamic_info, boot_hart)
|
||||||
|
== FW_DYNAMIC_INFO_BOOT_HART_OFFSET,
|
||||||
|
"struct fw_dynamic_info definition has changed, please redefine "
|
||||||
|
"FW_DYNAMIC_INFO_BOOT_HART_OFFSET");
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -25,30 +25,39 @@
|
|||||||
#define mb() RISCV_FENCE(iorw,iorw)
|
#define mb() RISCV_FENCE(iorw,iorw)
|
||||||
|
|
||||||
/* Read Memory barrier */
|
/* Read Memory barrier */
|
||||||
#define rmb() RISCV_FENCE(ir,ir)
|
#define rmb() RISCV_FENCE(ir,iorw)
|
||||||
|
|
||||||
/* Write Memory barrier */
|
/* Write Memory barrier */
|
||||||
#define wmb() RISCV_FENCE(ow,ow)
|
#define wmb() RISCV_FENCE(iorw,ow)
|
||||||
|
|
||||||
/* SMP Read & Write Memory barrier */
|
/* SMP Read & Write Memory barrier */
|
||||||
#define smp_mb() RISCV_FENCE(rw,rw)
|
#define smp_mb() RISCV_FENCE(rw,rw)
|
||||||
|
|
||||||
/* SMP Read Memory barrier */
|
/* SMP Read Memory barrier */
|
||||||
#define smp_rmb() RISCV_FENCE(r,r)
|
#define smp_rmb() RISCV_FENCE(r,rw)
|
||||||
|
|
||||||
/* SMP Write Memory barrier */
|
/* SMP Write Memory barrier */
|
||||||
#define smp_wmb() RISCV_FENCE(w,w)
|
#define smp_wmb() RISCV_FENCE(rw,w)
|
||||||
|
|
||||||
/* CPU relax for busy loop */
|
/* CPU relax for busy loop */
|
||||||
#define cpu_relax() asm volatile ("" : : : "memory")
|
#define cpu_relax() asm volatile ("" : : : "memory")
|
||||||
|
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
|
||||||
|
#ifdef CONFIG_PLATFORM_SOPHGO_MANGO
|
||||||
|
#define __smp_store_release(p, v) \
|
||||||
|
do { \
|
||||||
|
RISCV_FENCE(rw, w); \
|
||||||
|
*(p) = (v); \
|
||||||
|
RISCV_FENCE(w, rw); \
|
||||||
|
} while (0)
|
||||||
|
#else
|
||||||
#define __smp_store_release(p, v) \
|
#define __smp_store_release(p, v) \
|
||||||
do { \
|
do { \
|
||||||
RISCV_FENCE(rw, w); \
|
RISCV_FENCE(rw, w); \
|
||||||
*(p) = (v); \
|
*(p) = (v); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define __smp_load_acquire(p) \
|
#define __smp_load_acquire(p) \
|
||||||
({ \
|
({ \
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
#define MSTATUS_MPP (_UL(3) << MSTATUS_MPP_SHIFT)
|
#define MSTATUS_MPP (_UL(3) << MSTATUS_MPP_SHIFT)
|
||||||
#define MSTATUS_FS _UL(0x00006000)
|
#define MSTATUS_FS _UL(0x00006000)
|
||||||
#define MSTATUS_XS _UL(0x00018000)
|
#define MSTATUS_XS _UL(0x00018000)
|
||||||
#define MSTATUS_VS _UL(0x01800000)
|
#define MSTATUS_VS _UL(0x00000600)
|
||||||
#define MSTATUS_MPRV _UL(0x00020000)
|
#define MSTATUS_MPRV _UL(0x00020000)
|
||||||
#define MSTATUS_SUM _UL(0x00040000)
|
#define MSTATUS_SUM _UL(0x00040000)
|
||||||
#define MSTATUS_MXR _UL(0x00080000)
|
#define MSTATUS_MXR _UL(0x00080000)
|
||||||
@@ -38,10 +38,14 @@
|
|||||||
#define MSTATUS_SXL _ULL(0x0000000C00000000)
|
#define MSTATUS_SXL _ULL(0x0000000C00000000)
|
||||||
#define MSTATUS_SBE _ULL(0x0000001000000000)
|
#define MSTATUS_SBE _ULL(0x0000001000000000)
|
||||||
#define MSTATUS_MBE _ULL(0x0000002000000000)
|
#define MSTATUS_MBE _ULL(0x0000002000000000)
|
||||||
|
#define MSTATUS_GVA _ULL(0x0000004000000000)
|
||||||
|
#define MSTATUS_GVA_SHIFT 38
|
||||||
#define MSTATUS_MPV _ULL(0x0000008000000000)
|
#define MSTATUS_MPV _ULL(0x0000008000000000)
|
||||||
#else
|
#else
|
||||||
#define MSTATUSH_SBE _UL(0x00000010)
|
#define MSTATUSH_SBE _UL(0x00000010)
|
||||||
#define MSTATUSH_MBE _UL(0x00000020)
|
#define MSTATUSH_MBE _UL(0x00000020)
|
||||||
|
#define MSTATUSH_GVA _UL(0x00000040)
|
||||||
|
#define MSTATUSH_GVA_SHIFT 6
|
||||||
#define MSTATUSH_MPV _UL(0x00000080)
|
#define MSTATUSH_MPV _UL(0x00000080)
|
||||||
#endif
|
#endif
|
||||||
#define MSTATUS32_SD _UL(0x80000000)
|
#define MSTATUS32_SD _UL(0x80000000)
|
||||||
@@ -173,6 +177,10 @@
|
|||||||
#define HGATP_MODE_SHIFT HGATP32_MODE_SHIFT
|
#define HGATP_MODE_SHIFT HGATP32_MODE_SHIFT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define TOPI_IID_SHIFT 16
|
||||||
|
#define TOPI_IID_MASK 0xfff
|
||||||
|
#define TOPI_IPRIO_MASK 0xff
|
||||||
|
|
||||||
#if __riscv_xlen == 64
|
#if __riscv_xlen == 64
|
||||||
#define MHPMEVENT_OF (_UL(1) << 63)
|
#define MHPMEVENT_OF (_UL(1) << 63)
|
||||||
#define MHPMEVENT_MINH (_UL(1) << 62)
|
#define MHPMEVENT_MINH (_UL(1) << 62)
|
||||||
@@ -181,13 +189,14 @@
|
|||||||
#define MHPMEVENT_VSINH (_UL(1) << 59)
|
#define MHPMEVENT_VSINH (_UL(1) << 59)
|
||||||
#define MHPMEVENT_VUINH (_UL(1) << 58)
|
#define MHPMEVENT_VUINH (_UL(1) << 58)
|
||||||
#else
|
#else
|
||||||
#define MHPMEVENTH_OF (_UL(1) << 31)
|
#define MHPMEVENTH_OF (_ULL(1) << 31)
|
||||||
#define MHPMEVENTH_MINH (_ULL(1) << 30)
|
#define MHPMEVENTH_MINH (_ULL(1) << 30)
|
||||||
#define MHPMEVENTH_SINH (_ULL(1) << 29)
|
#define MHPMEVENTH_SINH (_ULL(1) << 29)
|
||||||
#define MHPMEVENTH_UINH (_ULL(1) << 28)
|
#define MHPMEVENTH_UINH (_ULL(1) << 28)
|
||||||
#define MHPMEVENTH_VSINH (_ULL(1) << 27)
|
#define MHPMEVENTH_VSINH (_ULL(1) << 27)
|
||||||
#define MHPMEVENTH_VUINH (_ULL(1) << 26)
|
#define MHPMEVENTH_VUINH (_ULL(1) << 26)
|
||||||
|
|
||||||
|
#define MHPMEVENT_OF (MHPMEVENTH_OF << 32)
|
||||||
#define MHPMEVENT_MINH (MHPMEVENTH_MINH << 32)
|
#define MHPMEVENT_MINH (MHPMEVENTH_MINH << 32)
|
||||||
#define MHPMEVENT_SINH (MHPMEVENTH_SINH << 32)
|
#define MHPMEVENT_SINH (MHPMEVENTH_SINH << 32)
|
||||||
#define MHPMEVENT_UINH (MHPMEVENTH_UINH << 32)
|
#define MHPMEVENT_UINH (MHPMEVENTH_UINH << 32)
|
||||||
@@ -198,6 +207,24 @@
|
|||||||
|
|
||||||
#define MHPMEVENT_SSCOF_MASK _ULL(0xFFFF000000000000)
|
#define MHPMEVENT_SSCOF_MASK _ULL(0xFFFF000000000000)
|
||||||
|
|
||||||
|
#if __riscv_xlen > 32
|
||||||
|
#define ENVCFG_STCE (_ULL(1) << 63)
|
||||||
|
#define ENVCFG_PBMTE (_ULL(1) << 62)
|
||||||
|
#else
|
||||||
|
#define ENVCFGH_STCE (_UL(1) << 31)
|
||||||
|
#define ENVCFGH_PBMTE (_UL(1) << 30)
|
||||||
|
#endif
|
||||||
|
#define ENVCFG_CBZE (_UL(1) << 7)
|
||||||
|
#define ENVCFG_CBCFE (_UL(1) << 6)
|
||||||
|
#define ENVCFG_CBIE_SHIFT 4
|
||||||
|
#define ENVCFG_CBIE (_UL(0x3) << ENVCFG_CBIE_SHIFT)
|
||||||
|
#define ENVCFG_CBIE_ILL _UL(0x0)
|
||||||
|
#define ENVCFG_CBIE_FLUSH _UL(0x1)
|
||||||
|
#define ENVCFG_CBIE_INV _UL(0x3)
|
||||||
|
#define ENVCFG_FIOM _UL(0x1)
|
||||||
|
|
||||||
|
#define MCOUNTEREN_TM (_UL(1) << 1)
|
||||||
|
|
||||||
/* ===== User-level CSRs ===== */
|
/* ===== User-level CSRs ===== */
|
||||||
|
|
||||||
/* User Trap Setup (N-extension) */
|
/* User Trap Setup (N-extension) */
|
||||||
@@ -287,12 +314,13 @@
|
|||||||
|
|
||||||
/* Supervisor Trap Setup */
|
/* Supervisor Trap Setup */
|
||||||
#define CSR_SSTATUS 0x100
|
#define CSR_SSTATUS 0x100
|
||||||
#define CSR_SEDELEG 0x102
|
|
||||||
#define CSR_SIDELEG 0x103
|
|
||||||
#define CSR_SIE 0x104
|
#define CSR_SIE 0x104
|
||||||
#define CSR_STVEC 0x105
|
#define CSR_STVEC 0x105
|
||||||
#define CSR_SCOUNTEREN 0x106
|
#define CSR_SCOUNTEREN 0x106
|
||||||
|
|
||||||
|
/* Supervisor Configuration */
|
||||||
|
#define CSR_SENVCFG 0x10a
|
||||||
|
|
||||||
/* Supervisor Trap Handling */
|
/* Supervisor Trap Handling */
|
||||||
#define CSR_SSCRATCH 0x140
|
#define CSR_SSCRATCH 0x140
|
||||||
#define CSR_SEPC 0x141
|
#define CSR_SEPC 0x141
|
||||||
@@ -300,9 +328,31 @@
|
|||||||
#define CSR_STVAL 0x143
|
#define CSR_STVAL 0x143
|
||||||
#define CSR_SIP 0x144
|
#define CSR_SIP 0x144
|
||||||
|
|
||||||
|
/* Sstc extension */
|
||||||
|
#define CSR_STIMECMP 0x14D
|
||||||
|
#define CSR_STIMECMPH 0x15D
|
||||||
|
|
||||||
/* Supervisor Protection and Translation */
|
/* Supervisor Protection and Translation */
|
||||||
#define CSR_SATP 0x180
|
#define CSR_SATP 0x180
|
||||||
|
|
||||||
|
/* Supervisor-Level Window to Indirectly Accessed Registers (AIA) */
|
||||||
|
#define CSR_SISELECT 0x150
|
||||||
|
#define CSR_SIREG 0x151
|
||||||
|
|
||||||
|
/* Supervisor-Level Interrupts (AIA) */
|
||||||
|
#define CSR_STOPEI 0x15c
|
||||||
|
#define CSR_STOPI 0xdb0
|
||||||
|
|
||||||
|
/* Supervisor-Level High-Half CSRs (AIA) */
|
||||||
|
#define CSR_SIEH 0x114
|
||||||
|
#define CSR_SIPH 0x154
|
||||||
|
|
||||||
|
/* Supervisor stateen CSRs */
|
||||||
|
#define CSR_SSTATEEN0 0x10C
|
||||||
|
#define CSR_SSTATEEN1 0x10D
|
||||||
|
#define CSR_SSTATEEN2 0x10E
|
||||||
|
#define CSR_SSTATEEN3 0x10F
|
||||||
|
|
||||||
/* ===== Hypervisor-level CSRs ===== */
|
/* ===== Hypervisor-level CSRs ===== */
|
||||||
|
|
||||||
/* Hypervisor Trap Setup (H-extension) */
|
/* Hypervisor Trap Setup (H-extension) */
|
||||||
@@ -313,6 +363,10 @@
|
|||||||
#define CSR_HCOUNTEREN 0x606
|
#define CSR_HCOUNTEREN 0x606
|
||||||
#define CSR_HGEIE 0x607
|
#define CSR_HGEIE 0x607
|
||||||
|
|
||||||
|
/* Hypervisor Configuration */
|
||||||
|
#define CSR_HENVCFG 0x60a
|
||||||
|
#define CSR_HENVCFGH 0x61a
|
||||||
|
|
||||||
/* Hypervisor Trap Handling (H-extension) */
|
/* Hypervisor Trap Handling (H-extension) */
|
||||||
#define CSR_HTVAL 0x643
|
#define CSR_HTVAL 0x643
|
||||||
#define CSR_HIP 0x644
|
#define CSR_HIP 0x644
|
||||||
@@ -338,6 +392,39 @@
|
|||||||
#define CSR_VSIP 0x244
|
#define CSR_VSIP 0x244
|
||||||
#define CSR_VSATP 0x280
|
#define CSR_VSATP 0x280
|
||||||
|
|
||||||
|
/* Virtual Interrupts and Interrupt Priorities (H-extension with AIA) */
|
||||||
|
#define CSR_HVIEN 0x608
|
||||||
|
#define CSR_HVICTL 0x609
|
||||||
|
#define CSR_HVIPRIO1 0x646
|
||||||
|
#define CSR_HVIPRIO2 0x647
|
||||||
|
|
||||||
|
/* VS-Level Window to Indirectly Accessed Registers (H-extension with AIA) */
|
||||||
|
#define CSR_VSISELECT 0x250
|
||||||
|
#define CSR_VSIREG 0x251
|
||||||
|
|
||||||
|
/* VS-Level Interrupts (H-extension with AIA) */
|
||||||
|
#define CSR_VSTOPEI 0x25c
|
||||||
|
#define CSR_VSTOPI 0xeb0
|
||||||
|
|
||||||
|
/* Hypervisor and VS-Level High-Half CSRs (H-extension with AIA) */
|
||||||
|
#define CSR_HIDELEGH 0x613
|
||||||
|
#define CSR_HVIENH 0x618
|
||||||
|
#define CSR_HVIPH 0x655
|
||||||
|
#define CSR_HVIPRIO1H 0x656
|
||||||
|
#define CSR_HVIPRIO2H 0x657
|
||||||
|
#define CSR_VSIEH 0x214
|
||||||
|
#define CSR_VSIPH 0x254
|
||||||
|
|
||||||
|
/* Hypervisor stateen CSRs */
|
||||||
|
#define CSR_HSTATEEN0 0x60C
|
||||||
|
#define CSR_HSTATEEN0H 0x61C
|
||||||
|
#define CSR_HSTATEEN1 0x60D
|
||||||
|
#define CSR_HSTATEEN1H 0x61D
|
||||||
|
#define CSR_HSTATEEN2 0x60E
|
||||||
|
#define CSR_HSTATEEN2H 0x61E
|
||||||
|
#define CSR_HSTATEEN3 0x60F
|
||||||
|
#define CSR_HSTATEEN3H 0x61F
|
||||||
|
|
||||||
/* ===== Machine-level CSRs ===== */
|
/* ===== Machine-level CSRs ===== */
|
||||||
|
|
||||||
/* Machine Information Registers */
|
/* Machine Information Registers */
|
||||||
@@ -356,6 +443,10 @@
|
|||||||
#define CSR_MCOUNTEREN 0x306
|
#define CSR_MCOUNTEREN 0x306
|
||||||
#define CSR_MSTATUSH 0x310
|
#define CSR_MSTATUSH 0x310
|
||||||
|
|
||||||
|
/* Machine Configuration */
|
||||||
|
#define CSR_MENVCFG 0x30a
|
||||||
|
#define CSR_MENVCFGH 0x31a
|
||||||
|
|
||||||
/* Machine Trap Handling */
|
/* Machine Trap Handling */
|
||||||
#define CSR_MSCRATCH 0x340
|
#define CSR_MSCRATCH 0x340
|
||||||
#define CSR_MEPC 0x341
|
#define CSR_MEPC 0x341
|
||||||
@@ -589,6 +680,36 @@
|
|||||||
#define CSR_DSCRATCH0 0x7b2
|
#define CSR_DSCRATCH0 0x7b2
|
||||||
#define CSR_DSCRATCH1 0x7b3
|
#define CSR_DSCRATCH1 0x7b3
|
||||||
|
|
||||||
|
/* Machine-Level Window to Indirectly Accessed Registers (AIA) */
|
||||||
|
#define CSR_MISELECT 0x350
|
||||||
|
#define CSR_MIREG 0x351
|
||||||
|
|
||||||
|
/* Machine-Level Interrupts (AIA) */
|
||||||
|
#define CSR_MTOPEI 0x35c
|
||||||
|
#define CSR_MTOPI 0xfb0
|
||||||
|
|
||||||
|
/* Virtual Interrupts for Supervisor Level (AIA) */
|
||||||
|
#define CSR_MVIEN 0x308
|
||||||
|
#define CSR_MVIP 0x309
|
||||||
|
|
||||||
|
/* Smstateen extension registers */
|
||||||
|
/* Machine stateen CSRs */
|
||||||
|
#define CSR_MSTATEEN0 0x30C
|
||||||
|
#define CSR_MSTATEEN0H 0x31C
|
||||||
|
#define CSR_MSTATEEN1 0x30D
|
||||||
|
#define CSR_MSTATEEN1H 0x31D
|
||||||
|
#define CSR_MSTATEEN2 0x30E
|
||||||
|
#define CSR_MSTATEEN2H 0x31E
|
||||||
|
#define CSR_MSTATEEN3 0x30F
|
||||||
|
#define CSR_MSTATEEN3H 0x31F
|
||||||
|
|
||||||
|
/* Machine-Level High-Half CSRs (AIA) */
|
||||||
|
#define CSR_MIDELEGH 0x313
|
||||||
|
#define CSR_MIEH 0x314
|
||||||
|
#define CSR_MVIENH 0x318
|
||||||
|
#define CSR_MVIPH 0x319
|
||||||
|
#define CSR_MIPH 0x354
|
||||||
|
|
||||||
/* ===== Trap/Exception Causes ===== */
|
/* ===== Trap/Exception Causes ===== */
|
||||||
|
|
||||||
#define CAUSE_MISALIGNED_FETCH 0x0
|
#define CAUSE_MISALIGNED_FETCH 0x0
|
||||||
@@ -611,6 +732,25 @@
|
|||||||
#define CAUSE_VIRTUAL_INST_FAULT 0x16
|
#define CAUSE_VIRTUAL_INST_FAULT 0x16
|
||||||
#define CAUSE_STORE_GUEST_PAGE_FAULT 0x17
|
#define CAUSE_STORE_GUEST_PAGE_FAULT 0x17
|
||||||
|
|
||||||
|
/* Common defines for all smstateen */
|
||||||
|
#define SMSTATEEN_MAX_COUNT 4
|
||||||
|
#define SMSTATEEN0_CS_SHIFT 0
|
||||||
|
#define SMSTATEEN0_CS (_ULL(1) << SMSTATEEN0_CS_SHIFT)
|
||||||
|
#define SMSTATEEN0_FCSR_SHIFT 1
|
||||||
|
#define SMSTATEEN0_FCSR (_ULL(1) << SMSTATEEN0_FCSR_SHIFT)
|
||||||
|
#define SMSTATEEN0_CONTEXT_SHIFT 57
|
||||||
|
#define SMSTATEEN0_CONTEXT (_ULL(1) << SMSTATEEN0_CONTEXT_SHIFT)
|
||||||
|
#define SMSTATEEN0_IMSIC_SHIFT 58
|
||||||
|
#define SMSTATEEN0_IMSIC (_ULL(1) << SMSTATEEN0_IMSIC_SHIFT)
|
||||||
|
#define SMSTATEEN0_AIA_SHIFT 59
|
||||||
|
#define SMSTATEEN0_AIA (_ULL(1) << SMSTATEEN0_AIA_SHIFT)
|
||||||
|
#define SMSTATEEN0_SVSLCT_SHIFT 60
|
||||||
|
#define SMSTATEEN0_SVSLCT (_ULL(1) << SMSTATEEN0_SVSLCT_SHIFT)
|
||||||
|
#define SMSTATEEN0_HSENVCFG_SHIFT 62
|
||||||
|
#define SMSTATEEN0_HSENVCFG (_ULL(1) << SMSTATEEN0_HSENVCFG_SHIFT)
|
||||||
|
#define SMSTATEEN_STATEN_SHIFT 63
|
||||||
|
#define SMSTATEEN_STATEN (_ULL(1) << SMSTATEEN_STATEN_SHIFT)
|
||||||
|
|
||||||
/* ===== Instruction Encodings ===== */
|
/* ===== Instruction Encodings ===== */
|
||||||
|
|
||||||
#define INSN_MATCH_LB 0x3
|
#define INSN_MATCH_LB 0x3
|
||||||
@@ -686,6 +826,29 @@
|
|||||||
#define INSN_MASK_WFI 0xffffff00
|
#define INSN_MASK_WFI 0xffffff00
|
||||||
#define INSN_MATCH_WFI 0x10500000
|
#define INSN_MATCH_WFI 0x10500000
|
||||||
|
|
||||||
|
#define INSN_MASK_FENCE_TSO 0xffffffff
|
||||||
|
#define INSN_MATCH_FENCE_TSO 0x8330000f
|
||||||
|
|
||||||
|
#if __riscv_xlen == 64
|
||||||
|
|
||||||
|
/* 64-bit read for VS-stage address translation (RV64) */
|
||||||
|
#define INSN_PSEUDO_VS_LOAD 0x00003000
|
||||||
|
|
||||||
|
/* 64-bit write for VS-stage address translation (RV64) */
|
||||||
|
#define INSN_PSEUDO_VS_STORE 0x00003020
|
||||||
|
|
||||||
|
#elif __riscv_xlen == 32
|
||||||
|
|
||||||
|
/* 32-bit read for VS-stage address translation (RV32) */
|
||||||
|
#define INSN_PSEUDO_VS_LOAD 0x00002000
|
||||||
|
|
||||||
|
/* 32-bit write for VS-stage address translation (RV32) */
|
||||||
|
#define INSN_PSEUDO_VS_STORE 0x00002020
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error "Unexpected __riscv_xlen"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define INSN_16BIT_MASK 0x3
|
#define INSN_16BIT_MASK 0x3
|
||||||
#define INSN_32BIT_MASK 0x1c
|
#define INSN_32BIT_MASK 0x1c
|
||||||
|
|
||||||
|
|||||||
@@ -37,47 +37,12 @@
|
|||||||
(((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
|
(((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ffs - Find first bit set
|
* sbi_ffs - find first (less-significant) set bit in a long word.
|
||||||
* @x: the word to search
|
|
||||||
*
|
|
||||||
* This is defined the same way as
|
|
||||||
* the libc and compiler builtin ffs routines, therefore
|
|
||||||
* differs in spirit from the above ffz (man ffs).
|
|
||||||
*/
|
|
||||||
static inline int ffs(int x)
|
|
||||||
{
|
|
||||||
int r = 1;
|
|
||||||
|
|
||||||
if (!x)
|
|
||||||
return 0;
|
|
||||||
if (!(x & 0xffff)) {
|
|
||||||
x >>= 16;
|
|
||||||
r += 16;
|
|
||||||
}
|
|
||||||
if (!(x & 0xff)) {
|
|
||||||
x >>= 8;
|
|
||||||
r += 8;
|
|
||||||
}
|
|
||||||
if (!(x & 0xf)) {
|
|
||||||
x >>= 4;
|
|
||||||
r += 4;
|
|
||||||
}
|
|
||||||
if (!(x & 3)) {
|
|
||||||
x >>= 2;
|
|
||||||
r += 2;
|
|
||||||
}
|
|
||||||
if (!(x & 1))
|
|
||||||
r += 1;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* __ffs - find first bit in word.
|
|
||||||
* @word: The word to search
|
* @word: The word to search
|
||||||
*
|
*
|
||||||
* Undefined if no bit exists, so code should check against 0 first.
|
* Undefined if no bit exists, so code should check against 0 first.
|
||||||
*/
|
*/
|
||||||
static inline int __ffs(unsigned long word)
|
static inline int sbi_ffs(unsigned long word)
|
||||||
{
|
{
|
||||||
int num = 0;
|
int num = 0;
|
||||||
|
|
||||||
@@ -109,55 +74,20 @@ static inline int __ffs(unsigned long word)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ffz - find first zero in word.
|
* sbi_ffz - find first zero in word.
|
||||||
* @word: The word to search
|
* @word: The word to search
|
||||||
*
|
*
|
||||||
* Undefined if no zero exists, so code should check against ~0UL first.
|
* Undefined if no zero exists, so code should check against ~0UL first.
|
||||||
*/
|
*/
|
||||||
#define ffz(x) __ffs(~(x))
|
#define sbi_ffz(x) sbi_ffs(~(x))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fls - find last (most-significant) bit set
|
* sbi_fls - find last (most-significant) set bit in a long word
|
||||||
* @x: the word to search
|
|
||||||
*
|
|
||||||
* This is defined the same way as ffs.
|
|
||||||
* Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static inline int fls(int x)
|
|
||||||
{
|
|
||||||
int r = 32;
|
|
||||||
|
|
||||||
if (!x)
|
|
||||||
return 0;
|
|
||||||
if (!(x & 0xffff0000u)) {
|
|
||||||
x <<= 16;
|
|
||||||
r -= 16;
|
|
||||||
}
|
|
||||||
if (!(x & 0xff000000u)) {
|
|
||||||
x <<= 8;
|
|
||||||
r -= 8;
|
|
||||||
}
|
|
||||||
if (!(x & 0xf0000000u)) {
|
|
||||||
x <<= 4;
|
|
||||||
r -= 4;
|
|
||||||
}
|
|
||||||
if (!(x & 0xc0000000u)) {
|
|
||||||
x <<= 2;
|
|
||||||
r -= 2;
|
|
||||||
}
|
|
||||||
if (!(x & 0x80000000u))
|
|
||||||
r -= 1;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* __fls - find last (most-significant) set bit in a long word
|
|
||||||
* @word: the word to search
|
* @word: the word to search
|
||||||
*
|
*
|
||||||
* Undefined if no set bit exists, so code should check against 0 first.
|
* Undefined if no set bit exists, so code should check against 0 first.
|
||||||
*/
|
*/
|
||||||
static inline unsigned long __fls(unsigned long word)
|
static inline unsigned long sbi_fls(unsigned long word)
|
||||||
{
|
{
|
||||||
int num = BITS_PER_LONG - 1;
|
int num = BITS_PER_LONG - 1;
|
||||||
|
|
||||||
|
|||||||
61
include/sbi/sbi_byteorder.h
Normal file
61
include/sbi/sbi_byteorder.h
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Ventana Micro Systems Inc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SBI_BYTEORDER_H__
|
||||||
|
#define __SBI_BYTEORDER_H__
|
||||||
|
|
||||||
|
#include <sbi/sbi_types.h>
|
||||||
|
|
||||||
|
#define BSWAP16(x) ((((x) & 0x00ff) << 8) | \
|
||||||
|
(((x) & 0xff00) >> 8))
|
||||||
|
#define BSWAP32(x) ((((x) & 0x000000ff) << 24) | \
|
||||||
|
(((x) & 0x0000ff00) << 8) | \
|
||||||
|
(((x) & 0x00ff0000) >> 8) | \
|
||||||
|
(((x) & 0xff000000) >> 24))
|
||||||
|
#define BSWAP64(x) ((((x) & 0x00000000000000ffULL) << 56) | \
|
||||||
|
(((x) & 0x000000000000ff00ULL) << 40) | \
|
||||||
|
(((x) & 0x0000000000ff0000ULL) << 24) | \
|
||||||
|
(((x) & 0x00000000ff000000ULL) << 8) | \
|
||||||
|
(((x) & 0x000000ff00000000ULL) >> 8) | \
|
||||||
|
(((x) & 0x0000ff0000000000ULL) >> 24) | \
|
||||||
|
(((x) & 0x00ff000000000000ULL) >> 40) | \
|
||||||
|
(((x) & 0xff00000000000000ULL) >> 56))
|
||||||
|
|
||||||
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ /* CPU(little-endian) */
|
||||||
|
#define cpu_to_be16(x) ((uint16_t)BSWAP16(x))
|
||||||
|
#define cpu_to_be32(x) ((uint32_t)BSWAP32(x))
|
||||||
|
#define cpu_to_be64(x) ((uint64_t)BSWAP64(x))
|
||||||
|
|
||||||
|
#define be16_to_cpu(x) ((uint16_t)BSWAP16(x))
|
||||||
|
#define be32_to_cpu(x) ((uint32_t)BSWAP32(x))
|
||||||
|
#define be64_to_cpu(x) ((uint64_t)BSWAP64(x))
|
||||||
|
|
||||||
|
#define cpu_to_le16(x) ((uint16_t)(x))
|
||||||
|
#define cpu_to_le32(x) ((uint32_t)(x))
|
||||||
|
#define cpu_to_le64(x) ((uint64_t)(x))
|
||||||
|
|
||||||
|
#define le16_to_cpu(x) ((uint16_t)(x))
|
||||||
|
#define le32_to_cpu(x) ((uint32_t)(x))
|
||||||
|
#define le64_to_cpu(x) ((uint64_t)(x))
|
||||||
|
#else /* CPU(big-endian) */
|
||||||
|
#define cpu_to_be16(x) ((uint16_t)(x))
|
||||||
|
#define cpu_to_be32(x) ((uint32_t)(x))
|
||||||
|
#define cpu_to_be64(x) ((uint64_t)(x))
|
||||||
|
|
||||||
|
#define be16_to_cpu(x) ((uint16_t)(x))
|
||||||
|
#define be32_to_cpu(x) ((uint32_t)(x))
|
||||||
|
#define be64_to_cpu(x) ((uint64_t)(x))
|
||||||
|
|
||||||
|
#define cpu_to_le16(x) ((uint16_t)BSWAP16(x))
|
||||||
|
#define cpu_to_le32(x) ((uint32_t)BSWAP32(x))
|
||||||
|
#define cpu_to_le64(x) ((uint64_t)BSWAP64(x))
|
||||||
|
|
||||||
|
#define le16_to_cpu(x) ((uint16_t)BSWAP16(x))
|
||||||
|
#define le32_to_cpu(x) ((uint32_t)BSWAP32(x))
|
||||||
|
#define le64_to_cpu(x) ((uint64_t)BSWAP64(x))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __SBI_BYTEORDER_H__ */
|
||||||
@@ -19,6 +19,9 @@ struct sbi_console_device {
|
|||||||
/** Write a character to the console output */
|
/** Write a character to the console output */
|
||||||
void (*console_putc)(char ch);
|
void (*console_putc)(char ch);
|
||||||
|
|
||||||
|
/** Write a character string to the console output */
|
||||||
|
unsigned long (*console_puts)(const char *str, unsigned long len);
|
||||||
|
|
||||||
/** Read a character from the console input */
|
/** Read a character from the console input */
|
||||||
int (*console_getc)(void);
|
int (*console_getc)(void);
|
||||||
};
|
};
|
||||||
@@ -33,8 +36,12 @@ void sbi_putc(char ch);
|
|||||||
|
|
||||||
void sbi_puts(const char *str);
|
void sbi_puts(const char *str);
|
||||||
|
|
||||||
|
unsigned long sbi_nputs(const char *str, unsigned long len);
|
||||||
|
|
||||||
void sbi_gets(char *s, int maxwidth, char endchar);
|
void sbi_gets(char *s, int maxwidth, char endchar);
|
||||||
|
|
||||||
|
unsigned long sbi_ngets(char *str, unsigned long len);
|
||||||
|
|
||||||
int __printf(2, 3) sbi_sprintf(char *out, const char *format, ...);
|
int __printf(2, 3) sbi_sprintf(char *out, const char *format, ...);
|
||||||
|
|
||||||
int __printf(3, 4) sbi_snprintf(char *out, u32 out_sz, const char *format, ...);
|
int __printf(3, 4) sbi_snprintf(char *out, u32 out_sz, const char *format, ...);
|
||||||
|
|||||||
@@ -36,11 +36,53 @@ struct sbi_domain_memregion {
|
|||||||
*/
|
*/
|
||||||
unsigned long base;
|
unsigned long base;
|
||||||
/** Flags representing memory region attributes */
|
/** Flags representing memory region attributes */
|
||||||
#define SBI_DOMAIN_MEMREGION_READABLE (1UL << 0)
|
#define SBI_DOMAIN_MEMREGION_M_READABLE (1UL << 0)
|
||||||
#define SBI_DOMAIN_MEMREGION_WRITEABLE (1UL << 1)
|
#define SBI_DOMAIN_MEMREGION_M_WRITABLE (1UL << 1)
|
||||||
#define SBI_DOMAIN_MEMREGION_EXECUTABLE (1UL << 2)
|
#define SBI_DOMAIN_MEMREGION_M_EXECUTABLE (1UL << 2)
|
||||||
#define SBI_DOMAIN_MEMREGION_MMODE (1UL << 3)
|
#define SBI_DOMAIN_MEMREGION_SU_READABLE (1UL << 3)
|
||||||
#define SBI_DOMAIN_MEMREGION_ACCESS_MASK (0xfUL)
|
#define SBI_DOMAIN_MEMREGION_SU_WRITABLE (1UL << 4)
|
||||||
|
#define SBI_DOMAIN_MEMREGION_SU_EXECUTABLE (1UL << 5)
|
||||||
|
|
||||||
|
/** Bit to control if permissions are enforced on all modes */
|
||||||
|
#define SBI_DOMAIN_MEMREGION_ENF_PERMISSIONS (1UL << 6)
|
||||||
|
|
||||||
|
#define SBI_DOMAIN_MEMREGION_M_RWX \
|
||||||
|
(SBI_DOMAIN_MEMREGION_M_READABLE | \
|
||||||
|
SBI_DOMAIN_MEMREGION_M_WRITABLE | \
|
||||||
|
SBI_DOMAIN_MEMREGION_M_EXECUTABLE)
|
||||||
|
|
||||||
|
#define SBI_DOMAIN_MEMREGION_SU_RWX \
|
||||||
|
(SBI_DOMAIN_MEMREGION_SU_READABLE | \
|
||||||
|
SBI_DOMAIN_MEMREGION_SU_WRITABLE | \
|
||||||
|
SBI_DOMAIN_MEMREGION_SU_EXECUTABLE)
|
||||||
|
|
||||||
|
/* Unrestricted M-mode accesses but enfoced on SU-mode */
|
||||||
|
#define SBI_DOMAIN_MEMREGION_READABLE \
|
||||||
|
(SBI_DOMAIN_MEMREGION_SU_READABLE | \
|
||||||
|
SBI_DOMAIN_MEMREGION_M_RWX)
|
||||||
|
#define SBI_DOMAIN_MEMREGION_WRITEABLE \
|
||||||
|
(SBI_DOMAIN_MEMREGION_SU_WRITABLE | \
|
||||||
|
SBI_DOMAIN_MEMREGION_M_RWX)
|
||||||
|
#define SBI_DOMAIN_MEMREGION_EXECUTABLE \
|
||||||
|
(SBI_DOMAIN_MEMREGION_SU_EXECUTABLE | \
|
||||||
|
SBI_DOMAIN_MEMREGION_M_RWX)
|
||||||
|
|
||||||
|
/* Enforced accesses across all modes */
|
||||||
|
#define SBI_DOMAIN_MEMREGION_ENF_READABLE \
|
||||||
|
(SBI_DOMAIN_MEMREGION_SU_READABLE | \
|
||||||
|
SBI_DOMAIN_MEMREGION_M_READABLE)
|
||||||
|
#define SBI_DOMAIN_MEMREGION_ENF_WRITABLE \
|
||||||
|
(SBI_DOMAIN_MEMREGION_SU_WRITABLE | \
|
||||||
|
SBI_DOMAIN_MEMREGION_M_WRITABLE)
|
||||||
|
#define SBI_DOMAIN_MEMREGION_ENF_EXECUTABLE \
|
||||||
|
(SBI_DOMAIN_MEMREGION_SU_EXECUTABLE | \
|
||||||
|
SBI_DOMAIN_MEMREGION_M_EXECUTABLE)
|
||||||
|
|
||||||
|
#define SBI_DOMAIN_MEMREGION_ACCESS_MASK (0x3fUL)
|
||||||
|
#define SBI_DOMAIN_MEMREGION_M_ACCESS_MASK (0x7UL)
|
||||||
|
#define SBI_DOMAIN_MEMREGION_SU_ACCESS_MASK (0x38UL)
|
||||||
|
|
||||||
|
#define SBI_DOMAIN_MEMREGION_SU_ACCESS_SHIFT (3)
|
||||||
|
|
||||||
#define SBI_DOMAIN_MEMREGION_MMIO (1UL << 31)
|
#define SBI_DOMAIN_MEMREGION_MMIO (1UL << 31)
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
@@ -78,6 +120,8 @@ struct sbi_domain {
|
|||||||
unsigned long next_mode;
|
unsigned long next_mode;
|
||||||
/** Is domain allowed to reset the system */
|
/** Is domain allowed to reset the system */
|
||||||
bool system_reset_allowed;
|
bool system_reset_allowed;
|
||||||
|
/** Is domain allowed to suspend the system */
|
||||||
|
bool system_suspend_allowed;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** The root domain instance */
|
/** The root domain instance */
|
||||||
@@ -113,7 +157,7 @@ extern struct sbi_domain *domidx_to_domain_table[];
|
|||||||
* Check whether given HART is assigned to specified domain
|
* Check whether given HART is assigned to specified domain
|
||||||
* @param dom pointer to domain
|
* @param dom pointer to domain
|
||||||
* @param hartid the HART ID
|
* @param hartid the HART ID
|
||||||
* @return TRUE if HART is assigned to domain otherwise FALSE
|
* @return true if HART is assigned to domain otherwise false
|
||||||
*/
|
*/
|
||||||
bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartid);
|
bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartid);
|
||||||
|
|
||||||
@@ -148,12 +192,27 @@ void sbi_domain_memregion_init(unsigned long addr,
|
|||||||
* @param addr the address to be checked
|
* @param addr the address to be checked
|
||||||
* @param mode the privilege mode of access
|
* @param mode the privilege mode of access
|
||||||
* @param access_flags bitmask of domain access types (enum sbi_domain_access)
|
* @param access_flags bitmask of domain access types (enum sbi_domain_access)
|
||||||
* @return TRUE if access allowed otherwise FALSE
|
* @return true if access allowed otherwise false
|
||||||
*/
|
*/
|
||||||
bool sbi_domain_check_addr(const struct sbi_domain *dom,
|
bool sbi_domain_check_addr(const struct sbi_domain *dom,
|
||||||
unsigned long addr, unsigned long mode,
|
unsigned long addr, unsigned long mode,
|
||||||
unsigned long access_flags);
|
unsigned long access_flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether we can access specified address range for given mode and
|
||||||
|
* memory region flags under a domain
|
||||||
|
* @param dom pointer to domain
|
||||||
|
* @param addr the start of the address range to be checked
|
||||||
|
* @param size the size of the address range to be checked
|
||||||
|
* @param mode the privilege mode of access
|
||||||
|
* @param access_flags bitmask of domain access types (enum sbi_domain_access)
|
||||||
|
* @return TRUE if access allowed otherwise FALSE
|
||||||
|
*/
|
||||||
|
bool sbi_domain_check_addr_range(const struct sbi_domain *dom,
|
||||||
|
unsigned long addr, unsigned long size,
|
||||||
|
unsigned long mode,
|
||||||
|
unsigned long access_flags);
|
||||||
|
|
||||||
/** Dump domain details on the console */
|
/** Dump domain details on the console */
|
||||||
void sbi_domain_dump(const struct sbi_domain *dom, const char *suffix);
|
void sbi_domain_dump(const struct sbi_domain *dom, const char *suffix);
|
||||||
|
|
||||||
@@ -174,10 +233,26 @@ int sbi_domain_register(struct sbi_domain *dom,
|
|||||||
* Add a memory region to the root domain
|
* Add a memory region to the root domain
|
||||||
* @param reg pointer to the memory region to be added
|
* @param reg pointer to the memory region to be added
|
||||||
*
|
*
|
||||||
* @return 0 on success and negative error code on failure
|
* @return 0 on success
|
||||||
|
* @return SBI_EALREADY if memory region conflicts with the existing one
|
||||||
|
* @return SBI_EINVAL otherwise
|
||||||
*/
|
*/
|
||||||
int sbi_domain_root_add_memregion(const struct sbi_domain_memregion *reg);
|
int sbi_domain_root_add_memregion(const struct sbi_domain_memregion *reg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a memory range with its flags to the root domain
|
||||||
|
* @param addr start physical address of memory range
|
||||||
|
* @param size physical size of memory range
|
||||||
|
* @param align alignment of memory region
|
||||||
|
* @param region_flags memory range flags
|
||||||
|
*
|
||||||
|
* @return 0 on success
|
||||||
|
* @return SBI_EALREADY if memory region conflicts with the existing one
|
||||||
|
* @return SBI_EINVAL otherwise
|
||||||
|
*/
|
||||||
|
int sbi_domain_root_add_memrange(unsigned long addr, unsigned long size,
|
||||||
|
unsigned long align, unsigned long region_flags);
|
||||||
|
|
||||||
/** Finalize domain tables and startup non-root domains */
|
/** Finalize domain tables and startup non-root domains */
|
||||||
int sbi_domain_finalize(struct sbi_scratch *scratch, u32 cold_hartid);
|
int sbi_domain_finalize(struct sbi_scratch *scratch, u32 cold_hartid);
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,8 @@
|
|||||||
#include <sbi/sbi_types.h>
|
#include <sbi/sbi_types.h>
|
||||||
#include <sbi/sbi_list.h>
|
#include <sbi/sbi_list.h>
|
||||||
|
|
||||||
#define SBI_ECALL_VERSION_MAJOR 0
|
#define SBI_ECALL_VERSION_MAJOR 1
|
||||||
#define SBI_ECALL_VERSION_MINOR 3
|
#define SBI_ECALL_VERSION_MINOR 0
|
||||||
#define SBI_OPENSBI_IMPID 1
|
#define SBI_OPENSBI_IMPID 1
|
||||||
|
|
||||||
struct sbi_trap_regs;
|
struct sbi_trap_regs;
|
||||||
@@ -31,16 +31,6 @@ struct sbi_ecall_extension {
|
|||||||
struct sbi_trap_info *out_trap);
|
struct sbi_trap_info *out_trap);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct sbi_ecall_extension ecall_base;
|
|
||||||
extern struct sbi_ecall_extension ecall_legacy;
|
|
||||||
extern struct sbi_ecall_extension ecall_time;
|
|
||||||
extern struct sbi_ecall_extension ecall_rfence;
|
|
||||||
extern struct sbi_ecall_extension ecall_ipi;
|
|
||||||
extern struct sbi_ecall_extension ecall_vendor;
|
|
||||||
extern struct sbi_ecall_extension ecall_hsm;
|
|
||||||
extern struct sbi_ecall_extension ecall_srst;
|
|
||||||
extern struct sbi_ecall_extension ecall_pmu;
|
|
||||||
|
|
||||||
u16 sbi_ecall_version_major(void);
|
u16 sbi_ecall_version_major(void);
|
||||||
|
|
||||||
u16 sbi_ecall_version_minor(void);
|
u16 sbi_ecall_version_minor(void);
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
#define SBI_EXT_HSM 0x48534D
|
#define SBI_EXT_HSM 0x48534D
|
||||||
#define SBI_EXT_SRST 0x53525354
|
#define SBI_EXT_SRST 0x53525354
|
||||||
#define SBI_EXT_PMU 0x504D55
|
#define SBI_EXT_PMU 0x504D55
|
||||||
|
#define SBI_EXT_DBCN 0x4442434E
|
||||||
|
#define SBI_EXT_SUSP 0x53555350
|
||||||
|
|
||||||
/* SBI function IDs for BASE extension*/
|
/* SBI function IDs for BASE extension*/
|
||||||
#define SBI_EXT_BASE_GET_SPEC_VERSION 0x0
|
#define SBI_EXT_BASE_GET_SPEC_VERSION 0x0
|
||||||
@@ -99,6 +101,7 @@
|
|||||||
#define SBI_EXT_PMU_COUNTER_START 0x3
|
#define SBI_EXT_PMU_COUNTER_START 0x3
|
||||||
#define SBI_EXT_PMU_COUNTER_STOP 0x4
|
#define SBI_EXT_PMU_COUNTER_STOP 0x4
|
||||||
#define SBI_EXT_PMU_COUNTER_FW_READ 0x5
|
#define SBI_EXT_PMU_COUNTER_FW_READ 0x5
|
||||||
|
#define SBI_EXT_PMU_COUNTER_FW_READ_HI 0x6
|
||||||
|
|
||||||
/** General pmu event codes specified in SBI PMU extension */
|
/** General pmu event codes specified in SBI PMU extension */
|
||||||
enum sbi_pmu_hw_generic_events_t {
|
enum sbi_pmu_hw_generic_events_t {
|
||||||
@@ -182,6 +185,17 @@ enum sbi_pmu_fw_event_code_id {
|
|||||||
SBI_PMU_FW_HFENCE_VVMA_ASID_SENT = 20,
|
SBI_PMU_FW_HFENCE_VVMA_ASID_SENT = 20,
|
||||||
SBI_PMU_FW_HFENCE_VVMA_ASID_RCVD = 21,
|
SBI_PMU_FW_HFENCE_VVMA_ASID_RCVD = 21,
|
||||||
SBI_PMU_FW_MAX,
|
SBI_PMU_FW_MAX,
|
||||||
|
/*
|
||||||
|
* Event codes 22 to 255 are reserved for future use.
|
||||||
|
* Event codes 256 to 65534 are reserved for SBI implementation
|
||||||
|
* specific custom firmware events.
|
||||||
|
*/
|
||||||
|
SBI_PMU_FW_RESERVED_MAX = 0xFFFE,
|
||||||
|
/*
|
||||||
|
* Event code 0xFFFF is used for platform specific firmware
|
||||||
|
* events where the event data contains any event specific information.
|
||||||
|
*/
|
||||||
|
SBI_PMU_FW_PLATFORM = 0xFFFF,
|
||||||
};
|
};
|
||||||
|
|
||||||
/** SBI PMU event idx type */
|
/** SBI PMU event idx type */
|
||||||
@@ -208,6 +222,12 @@ enum sbi_pmu_ctr_type {
|
|||||||
|
|
||||||
#define SBI_PMU_EVENT_IDX_INVALID 0xFFFFFFFF
|
#define SBI_PMU_EVENT_IDX_INVALID 0xFFFFFFFF
|
||||||
|
|
||||||
|
#define SBI_PMU_EVENT_HW_CACHE_OPS_RESULT 0x1
|
||||||
|
#define SBI_PMU_EVENT_HW_CACHE_OPS_ID_MASK 0x6
|
||||||
|
#define SBI_PMU_EVENT_HW_CACHE_OPS_ID_OFFSET 1
|
||||||
|
#define SBI_PMU_EVENT_HW_CACHE_ID_MASK 0xfff8
|
||||||
|
#define SBI_PMU_EVENT_HW_CACHE_ID_OFFSET 3
|
||||||
|
|
||||||
/* Flags defined for config matching function */
|
/* Flags defined for config matching function */
|
||||||
#define SBI_PMU_CFG_FLAG_SKIP_MATCH (1 << 0)
|
#define SBI_PMU_CFG_FLAG_SKIP_MATCH (1 << 0)
|
||||||
#define SBI_PMU_CFG_FLAG_CLEAR_VALUE (1 << 1)
|
#define SBI_PMU_CFG_FLAG_CLEAR_VALUE (1 << 1)
|
||||||
@@ -224,6 +244,18 @@ enum sbi_pmu_ctr_type {
|
|||||||
/* Flags defined for counter stop function */
|
/* Flags defined for counter stop function */
|
||||||
#define SBI_PMU_STOP_FLAG_RESET (1 << 0)
|
#define SBI_PMU_STOP_FLAG_RESET (1 << 0)
|
||||||
|
|
||||||
|
/* SBI function IDs for DBCN extension */
|
||||||
|
#define SBI_EXT_DBCN_CONSOLE_WRITE 0x0
|
||||||
|
#define SBI_EXT_DBCN_CONSOLE_READ 0x1
|
||||||
|
#define SBI_EXT_DBCN_CONSOLE_WRITE_BYTE 0x2
|
||||||
|
|
||||||
|
/* SBI function IDs for SUSP extension */
|
||||||
|
#define SBI_EXT_SUSP_SUSPEND 0x0
|
||||||
|
|
||||||
|
#define SBI_SUSP_SLEEP_TYPE_SUSPEND 0x0
|
||||||
|
#define SBI_SUSP_SLEEP_TYPE_LAST SBI_SUSP_SLEEP_TYPE_SUSPEND
|
||||||
|
#define SBI_SUSP_PLATFORM_SLEEP_START 0x80000000
|
||||||
|
|
||||||
/* SBI base specification related macros */
|
/* SBI base specification related macros */
|
||||||
#define SBI_SPEC_VERSION_MAJOR_OFFSET 24
|
#define SBI_SPEC_VERSION_MAJOR_OFFSET 24
|
||||||
#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f
|
#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f
|
||||||
|
|||||||
@@ -12,21 +12,44 @@
|
|||||||
|
|
||||||
#include <sbi/sbi_types.h>
|
#include <sbi/sbi_types.h>
|
||||||
|
|
||||||
/** Possible feature flags of a hart */
|
/** Possible privileged specification versions of a hart */
|
||||||
enum sbi_hart_features {
|
enum sbi_hart_priv_versions {
|
||||||
/** Hart has S-mode counter enable */
|
/** Unknown privileged specification */
|
||||||
SBI_HART_HAS_SCOUNTEREN = (1 << 0),
|
SBI_HART_PRIV_VER_UNKNOWN = 0,
|
||||||
/** Hart has M-mode counter enable */
|
/** Privileged specification v1.10 */
|
||||||
SBI_HART_HAS_MCOUNTEREN = (1 << 1),
|
SBI_HART_PRIV_VER_1_10 = 1,
|
||||||
/** Hart has counter inhibit CSR */
|
/** Privileged specification v1.11 */
|
||||||
SBI_HART_HAS_MCOUNTINHIBIT = (1 << 2),
|
SBI_HART_PRIV_VER_1_11 = 2,
|
||||||
/** Hart has sscofpmf extension */
|
/** Privileged specification v1.12 */
|
||||||
SBI_HART_HAS_SSCOFPMF = (1 << 3),
|
SBI_HART_PRIV_VER_1_12 = 3,
|
||||||
/** HART has timer csr implementation in hardware */
|
};
|
||||||
SBI_HART_HAS_TIME = (1 << 4),
|
|
||||||
|
|
||||||
/** Last index of Hart features*/
|
/** Possible ISA extensions of a hart */
|
||||||
SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_TIME,
|
enum sbi_hart_extensions {
|
||||||
|
/** Hart has Sscofpmt extension */
|
||||||
|
SBI_HART_EXT_SSCOFPMF = 0,
|
||||||
|
/** HART has HW time CSR (extension name not available) */
|
||||||
|
SBI_HART_EXT_TIME,
|
||||||
|
/** HART has AIA M-mode CSRs */
|
||||||
|
SBI_HART_EXT_SMAIA,
|
||||||
|
/** HART has Smstateen CSR **/
|
||||||
|
SBI_HART_EXT_SMSTATEEN,
|
||||||
|
/** HART has Sstc extension */
|
||||||
|
SBI_HART_EXT_SSTC,
|
||||||
|
|
||||||
|
/** Maximum index of Hart extension */
|
||||||
|
SBI_HART_EXT_MAX,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sbi_hart_features {
|
||||||
|
bool detected;
|
||||||
|
int priv_version;
|
||||||
|
unsigned long extensions;
|
||||||
|
unsigned int pmp_count;
|
||||||
|
unsigned int pmp_addr_bits;
|
||||||
|
unsigned long pmp_gran;
|
||||||
|
unsigned int mhpm_count;
|
||||||
|
unsigned int mhpm_bits;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sbi_scratch;
|
struct sbi_scratch;
|
||||||
@@ -48,9 +71,16 @@ unsigned long sbi_hart_pmp_granularity(struct sbi_scratch *scratch);
|
|||||||
unsigned int sbi_hart_pmp_addrbits(struct sbi_scratch *scratch);
|
unsigned int sbi_hart_pmp_addrbits(struct sbi_scratch *scratch);
|
||||||
unsigned int sbi_hart_mhpm_bits(struct sbi_scratch *scratch);
|
unsigned int sbi_hart_mhpm_bits(struct sbi_scratch *scratch);
|
||||||
int sbi_hart_pmp_configure(struct sbi_scratch *scratch);
|
int sbi_hart_pmp_configure(struct sbi_scratch *scratch);
|
||||||
bool sbi_hart_has_feature(struct sbi_scratch *scratch, unsigned long feature);
|
int sbi_hart_priv_version(struct sbi_scratch *scratch);
|
||||||
void sbi_hart_get_features_str(struct sbi_scratch *scratch,
|
void sbi_hart_get_priv_version_str(struct sbi_scratch *scratch,
|
||||||
char *features_str, int nfstr);
|
char *version_str, int nvstr);
|
||||||
|
void sbi_hart_update_extension(struct sbi_scratch *scratch,
|
||||||
|
enum sbi_hart_extensions ext,
|
||||||
|
bool enable);
|
||||||
|
bool sbi_hart_has_extension(struct sbi_scratch *scratch,
|
||||||
|
enum sbi_hart_extensions ext);
|
||||||
|
void sbi_hart_get_extensions_str(struct sbi_scratch *scratch,
|
||||||
|
char *extension_str, int nestr);
|
||||||
|
|
||||||
void __attribute__((noreturn)) sbi_hart_hang(void);
|
void __attribute__((noreturn)) sbi_hart_hang(void);
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,12 @@ struct sbi_hsm_device {
|
|||||||
int (*hart_start)(u32 hartid, ulong saddr);
|
int (*hart_start)(u32 hartid, ulong saddr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop (or power-down) the current hart from running. This call
|
* Stop (or power-down) the current hart from running.
|
||||||
* doesn't expect to return if success.
|
*
|
||||||
|
* Return SBI_ENOTSUPP if the hart does not support platform-specific
|
||||||
|
* stop actions.
|
||||||
|
*
|
||||||
|
* For successful stop, the call won't return.
|
||||||
*/
|
*/
|
||||||
int (*hart_stop)(void);
|
int (*hart_stop)(void);
|
||||||
|
|
||||||
@@ -34,9 +38,17 @@ struct sbi_hsm_device {
|
|||||||
* the hart resumes normal execution.
|
* the hart resumes normal execution.
|
||||||
*
|
*
|
||||||
* For successful non-retentive suspend, the hart will resume from
|
* For successful non-retentive suspend, the hart will resume from
|
||||||
* specified resume address
|
* the warm boot entry point.
|
||||||
*/
|
*/
|
||||||
int (*hart_suspend)(u32 suspend_type, ulong raddr);
|
int (*hart_suspend)(u32 suspend_type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform platform-specific actions to resume from a suspended state.
|
||||||
|
*
|
||||||
|
* This includes restoring any platform state that was lost during
|
||||||
|
* non-retentive suspend.
|
||||||
|
*/
|
||||||
|
void (*hart_resume)(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sbi_domain;
|
struct sbi_domain;
|
||||||
@@ -51,15 +63,21 @@ void __noreturn sbi_hsm_exit(struct sbi_scratch *scratch);
|
|||||||
|
|
||||||
int sbi_hsm_hart_start(struct sbi_scratch *scratch,
|
int sbi_hsm_hart_start(struct sbi_scratch *scratch,
|
||||||
const struct sbi_domain *dom,
|
const struct sbi_domain *dom,
|
||||||
u32 hartid, ulong saddr, ulong smode, ulong priv);
|
u32 hartid, ulong saddr, ulong smode, ulong arg1);
|
||||||
int sbi_hsm_hart_stop(struct sbi_scratch *scratch, bool exitnow);
|
int sbi_hsm_hart_stop(struct sbi_scratch *scratch, bool exitnow);
|
||||||
void sbi_hsm_hart_resume_start(struct sbi_scratch *scratch);
|
void sbi_hsm_hart_resume_start(struct sbi_scratch *scratch);
|
||||||
void sbi_hsm_hart_resume_finish(struct sbi_scratch *scratch);
|
void __noreturn sbi_hsm_hart_resume_finish(struct sbi_scratch *scratch,
|
||||||
|
u32 hartid);
|
||||||
int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type,
|
int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type,
|
||||||
ulong raddr, ulong rmode, ulong priv);
|
ulong raddr, ulong rmode, ulong arg1);
|
||||||
|
bool sbi_hsm_hart_change_state(struct sbi_scratch *scratch, long oldstate,
|
||||||
|
long newstate);
|
||||||
|
int __sbi_hsm_hart_get_state(u32 hartid);
|
||||||
int sbi_hsm_hart_get_state(const struct sbi_domain *dom, u32 hartid);
|
int sbi_hsm_hart_get_state(const struct sbi_domain *dom, u32 hartid);
|
||||||
int sbi_hsm_hart_interruptible_mask(const struct sbi_domain *dom,
|
int sbi_hsm_hart_interruptible_mask(const struct sbi_domain *dom,
|
||||||
ulong hbase, ulong *out_hmask);
|
ulong hbase, ulong *out_hmask);
|
||||||
void sbi_hsm_prepare_next_jump(struct sbi_scratch *scratch, u32 hartid);
|
void __sbi_hsm_suspend_non_ret_save(struct sbi_scratch *scratch);
|
||||||
|
void __noreturn sbi_hsm_hart_start_finish(struct sbi_scratch *scratch,
|
||||||
|
u32 hartid);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -41,6 +41,10 @@ struct sbi_ipi_event_ops {
|
|||||||
* Update callback to save/enqueue data for remote HART
|
* Update callback to save/enqueue data for remote HART
|
||||||
* Note: This is an optional callback and it is called just before
|
* Note: This is an optional callback and it is called just before
|
||||||
* triggering IPI to remote HART.
|
* triggering IPI to remote HART.
|
||||||
|
* @return 0 success
|
||||||
|
* @return -1 break IPI, done on local hart
|
||||||
|
* @return -2 need retry
|
||||||
|
|
||||||
*/
|
*/
|
||||||
int (* update)(struct sbi_scratch *scratch,
|
int (* update)(struct sbi_scratch *scratch,
|
||||||
struct sbi_scratch *remote_scratch,
|
struct sbi_scratch *remote_scratch,
|
||||||
@@ -75,7 +79,9 @@ int sbi_ipi_send_halt(ulong hmask, ulong hbase);
|
|||||||
|
|
||||||
void sbi_ipi_process(void);
|
void sbi_ipi_process(void);
|
||||||
|
|
||||||
void sbi_ipi_raw_send(u32 target_hart);
|
int sbi_ipi_raw_send(u32 target_hart);
|
||||||
|
|
||||||
|
void sbi_ipi_raw_clear(u32 target_hart);
|
||||||
|
|
||||||
const struct sbi_ipi_device *sbi_ipi_get_device(void);
|
const struct sbi_ipi_device *sbi_ipi_get_device(void);
|
||||||
|
|
||||||
|
|||||||
44
include/sbi/sbi_irqchip.h
Normal file
44
include/sbi/sbi_irqchip.h
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Ventana Micro Systems Inc.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Anup Patel <apatel@ventanamicro.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SBI_IRQCHIP_H__
|
||||||
|
#define __SBI_IRQCHIP_H__
|
||||||
|
|
||||||
|
#include <sbi/sbi_types.h>
|
||||||
|
|
||||||
|
struct sbi_scratch;
|
||||||
|
struct sbi_trap_regs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set external interrupt handling function
|
||||||
|
*
|
||||||
|
* This function is called by OpenSBI platform code to set a handler for
|
||||||
|
* external interrupts
|
||||||
|
*
|
||||||
|
* @param fn function pointer for handling external irqs
|
||||||
|
*/
|
||||||
|
void sbi_irqchip_set_irqfn(int (*fn)(struct sbi_trap_regs *regs));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process external interrupts
|
||||||
|
*
|
||||||
|
* This function is called by sbi_trap_handler() to handle external
|
||||||
|
* interrupts.
|
||||||
|
*
|
||||||
|
* @param regs pointer for trap registers
|
||||||
|
*/
|
||||||
|
int sbi_irqchip_process(struct sbi_trap_regs *regs);
|
||||||
|
|
||||||
|
/** Initialize interrupt controllers */
|
||||||
|
int sbi_irqchip_init(struct sbi_scratch *scratch, bool cold_boot);
|
||||||
|
|
||||||
|
/** Exit interrupt controllers */
|
||||||
|
void sbi_irqchip_exit(struct sbi_scratch *scratch);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -47,7 +47,7 @@ static inline void __sbi_list_add(struct sbi_dlist *new,
|
|||||||
* Checks if the list is empty or not.
|
* Checks if the list is empty or not.
|
||||||
* @param head List head
|
* @param head List head
|
||||||
*
|
*
|
||||||
* Retruns TRUE if list is empty, FALSE otherwise.
|
* Returns true if list is empty, false otherwise.
|
||||||
*/
|
*/
|
||||||
static inline bool sbi_list_empty(struct sbi_dlist *head)
|
static inline bool sbi_list_empty(struct sbi_dlist *head)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
struct sbi_domain_memregion;
|
struct sbi_domain_memregion;
|
||||||
struct sbi_trap_info;
|
struct sbi_trap_info;
|
||||||
struct sbi_trap_regs;
|
struct sbi_trap_regs;
|
||||||
|
struct sbi_hart_features;
|
||||||
|
|
||||||
/** Possible feature flags of a platform */
|
/** Possible feature flags of a platform */
|
||||||
enum sbi_platform_features {
|
enum sbi_platform_features {
|
||||||
@@ -64,6 +65,15 @@ enum sbi_platform_features {
|
|||||||
|
|
||||||
/** Platform functions */
|
/** Platform functions */
|
||||||
struct sbi_platform_operations {
|
struct sbi_platform_operations {
|
||||||
|
/* Check if specified HART is allowed to do cold boot */
|
||||||
|
bool (*cold_boot_allowed)(u32 hartid);
|
||||||
|
|
||||||
|
/* Check if platform force emulate time csr, instead of using csr directly */
|
||||||
|
bool (*force_emulate_time_csr)(void);
|
||||||
|
|
||||||
|
/* Platform nascent initialization */
|
||||||
|
int (*nascent_init)(void);
|
||||||
|
|
||||||
/** Platform early initialization */
|
/** Platform early initialization */
|
||||||
int (*early_init)(bool cold_boot);
|
int (*early_init)(bool cold_boot);
|
||||||
/** Platform final initialization */
|
/** Platform final initialization */
|
||||||
@@ -86,6 +96,9 @@ struct sbi_platform_operations {
|
|||||||
*/
|
*/
|
||||||
int (*misa_get_xlen)(void);
|
int (*misa_get_xlen)(void);
|
||||||
|
|
||||||
|
/** Initialize (or populate) HART extensions for the platform */
|
||||||
|
int (*extensions_init)(struct sbi_hart_features *hfeatures);
|
||||||
|
|
||||||
/** Initialize (or populate) domains for the platform */
|
/** Initialize (or populate) domains for the platform */
|
||||||
int (*domains_init)(void);
|
int (*domains_init)(void);
|
||||||
|
|
||||||
@@ -116,10 +129,10 @@ struct sbi_platform_operations {
|
|||||||
/** Exit platform timer for current HART */
|
/** Exit platform timer for current HART */
|
||||||
void (*timer_exit)(void);
|
void (*timer_exit)(void);
|
||||||
|
|
||||||
/** platform specific SBI extension implementation probe function */
|
/** Check if SBI vendor extension is implemented or not */
|
||||||
int (*vendor_ext_check)(long extid);
|
bool (*vendor_ext_check)(void);
|
||||||
/** platform specific SBI extension implementation provider */
|
/** platform specific SBI extension implementation provider */
|
||||||
int (*vendor_ext_provider)(long extid, long funcid,
|
int (*vendor_ext_provider)(long funcid,
|
||||||
const struct sbi_trap_regs *regs,
|
const struct sbi_trap_regs *regs,
|
||||||
unsigned long *out_value,
|
unsigned long *out_value,
|
||||||
struct sbi_trap_info *out_trap);
|
struct sbi_trap_info *out_trap);
|
||||||
@@ -172,6 +185,56 @@ struct sbi_platform {
|
|||||||
const u32 *hart_index2id;
|
const u32 *hart_index2id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prevent modification of struct sbi_platform from affecting
|
||||||
|
* SBI_PLATFORM_xxx_OFFSET
|
||||||
|
*/
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct sbi_platform, opensbi_version)
|
||||||
|
== SBI_PLATFORM_OPENSBI_VERSION_OFFSET,
|
||||||
|
"struct sbi_platform definition has changed, please redefine "
|
||||||
|
"SBI_PLATFORM_OPENSBI_VERSION_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct sbi_platform, platform_version)
|
||||||
|
== SBI_PLATFORM_VERSION_OFFSET,
|
||||||
|
"struct sbi_platform definition has changed, please redefine "
|
||||||
|
"SBI_PLATFORM_VERSION_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct sbi_platform, name)
|
||||||
|
== SBI_PLATFORM_NAME_OFFSET,
|
||||||
|
"struct sbi_platform definition has changed, please redefine "
|
||||||
|
"SBI_PLATFORM_NAME_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct sbi_platform, features)
|
||||||
|
== SBI_PLATFORM_FEATURES_OFFSET,
|
||||||
|
"struct sbi_platform definition has changed, please redefine "
|
||||||
|
"SBI_PLATFORM_FEATURES_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct sbi_platform, hart_count)
|
||||||
|
== SBI_PLATFORM_HART_COUNT_OFFSET,
|
||||||
|
"struct sbi_platform definition has changed, please redefine "
|
||||||
|
"SBI_PLATFORM_HART_COUNT_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct sbi_platform, hart_stack_size)
|
||||||
|
== SBI_PLATFORM_HART_STACK_SIZE_OFFSET,
|
||||||
|
"struct sbi_platform definition has changed, please redefine "
|
||||||
|
"SBI_PLATFORM_HART_STACK_SIZE_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct sbi_platform, platform_ops_addr)
|
||||||
|
== SBI_PLATFORM_OPS_OFFSET,
|
||||||
|
"struct sbi_platform definition has changed, please redefine "
|
||||||
|
"SBI_PLATFORM_OPS_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct sbi_platform, firmware_context)
|
||||||
|
== SBI_PLATFORM_FIRMWARE_CONTEXT_OFFSET,
|
||||||
|
"struct sbi_platform definition has changed, please redefine "
|
||||||
|
"SBI_PLATFORM_FIRMWARE_CONTEXT_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct sbi_platform, hart_index2id)
|
||||||
|
== SBI_PLATFORM_HART_INDEX2ID_OFFSET,
|
||||||
|
"struct sbi_platform definition has changed, please redefine "
|
||||||
|
"SBI_PLATFORM_HART_INDEX2ID_OFFSET");
|
||||||
|
|
||||||
/** Get pointer to sbi_platform for sbi_scratch pointer */
|
/** Get pointer to sbi_platform for sbi_scratch pointer */
|
||||||
#define sbi_platform_ptr(__s) \
|
#define sbi_platform_ptr(__s) \
|
||||||
((const struct sbi_platform *)((__s)->platform_addr))
|
((const struct sbi_platform *)((__s)->platform_addr))
|
||||||
@@ -287,23 +350,71 @@ static inline u32 sbi_platform_hart_stack_size(const struct sbi_platform *plat)
|
|||||||
* @param plat pointer to struct sbi_platform
|
* @param plat pointer to struct sbi_platform
|
||||||
* @param hartid HART ID
|
* @param hartid HART ID
|
||||||
*
|
*
|
||||||
* @return TRUE if HART is invalid and FALSE otherwise
|
* @return true if HART is invalid and false otherwise
|
||||||
*/
|
*/
|
||||||
static inline bool sbi_platform_hart_invalid(const struct sbi_platform *plat,
|
static inline bool sbi_platform_hart_invalid(const struct sbi_platform *plat,
|
||||||
u32 hartid)
|
u32 hartid)
|
||||||
{
|
{
|
||||||
if (!plat)
|
if (!plat)
|
||||||
return TRUE;
|
return true;
|
||||||
if (plat->hart_count <= sbi_platform_hart_index(plat, hartid))
|
if (plat->hart_count <= sbi_platform_hart_index(plat, hartid))
|
||||||
return TRUE;
|
return true;
|
||||||
return FALSE;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether given HART is allowed to do cold boot
|
||||||
|
*
|
||||||
|
* @param plat pointer to struct sbi_platform
|
||||||
|
* @param hartid HART ID
|
||||||
|
*
|
||||||
|
* @return true if HART is allowed to do cold boot and false otherwise
|
||||||
|
*/
|
||||||
|
static inline bool sbi_platform_cold_boot_allowed(
|
||||||
|
const struct sbi_platform *plat,
|
||||||
|
u32 hartid)
|
||||||
|
{
|
||||||
|
if (plat && sbi_platform_ops(plat)->cold_boot_allowed)
|
||||||
|
return sbi_platform_ops(plat)->cold_boot_allowed(hartid);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether given platform should force emulate time CSR
|
||||||
|
*
|
||||||
|
* @param plat pointer to struct sbi_platform
|
||||||
|
*
|
||||||
|
* @return true such platform force emulate time CSR, false otherwise
|
||||||
|
*/
|
||||||
|
static inline bool sbi_platform_force_emulate_time_csr(const struct sbi_platform *plat)
|
||||||
|
{
|
||||||
|
if (plat && sbi_platform_ops(plat)->force_emulate_time_csr)
|
||||||
|
return sbi_platform_ops(plat)->force_emulate_time_csr();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nascent (very early) initialization for current HART
|
||||||
|
*
|
||||||
|
* NOTE: This function can be used to do very early initialization of
|
||||||
|
* platform specific per-HART CSRs and devices.
|
||||||
|
*
|
||||||
|
* @param plat pointer to struct sbi_platform
|
||||||
|
*
|
||||||
|
* @return 0 on success and negative error code on failure
|
||||||
|
*/
|
||||||
|
static inline int sbi_platform_nascent_init(const struct sbi_platform *plat)
|
||||||
|
{
|
||||||
|
if (plat && sbi_platform_ops(plat)->nascent_init)
|
||||||
|
return sbi_platform_ops(plat)->nascent_init();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Early initialization for current HART
|
* Early initialization for current HART
|
||||||
*
|
*
|
||||||
* @param plat pointer to struct sbi_platform
|
* @param plat pointer to struct sbi_platform
|
||||||
* @param cold_boot whether cold boot (TRUE) or warm_boot (FALSE)
|
* @param cold_boot whether cold boot (true) or warm_boot (false)
|
||||||
*
|
*
|
||||||
* @return 0 on success and negative error code on failure
|
* @return 0 on success and negative error code on failure
|
||||||
*/
|
*/
|
||||||
@@ -319,7 +430,7 @@ static inline int sbi_platform_early_init(const struct sbi_platform *plat,
|
|||||||
* Final initialization for current HART
|
* Final initialization for current HART
|
||||||
*
|
*
|
||||||
* @param plat pointer to struct sbi_platform
|
* @param plat pointer to struct sbi_platform
|
||||||
* @param cold_boot whether cold boot (TRUE) or warm_boot (FALSE)
|
* @param cold_boot whether cold boot (true) or warm_boot (false)
|
||||||
*
|
*
|
||||||
* @return 0 on success and negative error code on failure
|
* @return 0 on success and negative error code on failure
|
||||||
*/
|
*/
|
||||||
@@ -383,6 +494,22 @@ static inline int sbi_platform_misa_xlen(const struct sbi_platform *plat)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize (or populate) HART extensions for the platform
|
||||||
|
*
|
||||||
|
* @param plat pointer to struct sbi_platform
|
||||||
|
*
|
||||||
|
* @return 0 on success and negative error code on failure
|
||||||
|
*/
|
||||||
|
static inline int sbi_platform_extensions_init(
|
||||||
|
const struct sbi_platform *plat,
|
||||||
|
struct sbi_hart_features *hfeatures)
|
||||||
|
{
|
||||||
|
if (plat && sbi_platform_ops(plat)->extensions_init)
|
||||||
|
return sbi_platform_ops(plat)->extensions_init(hfeatures);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize (or populate) domains for the platform
|
* Initialize (or populate) domains for the platform
|
||||||
*
|
*
|
||||||
@@ -448,7 +575,7 @@ static inline int sbi_platform_console_init(const struct sbi_platform *plat)
|
|||||||
* Initialize the platform interrupt controller for current HART
|
* Initialize the platform interrupt controller for current HART
|
||||||
*
|
*
|
||||||
* @param plat pointer to struct sbi_platform
|
* @param plat pointer to struct sbi_platform
|
||||||
* @param cold_boot whether cold boot (TRUE) or warm_boot (FALSE)
|
* @param cold_boot whether cold boot (true) or warm_boot (false)
|
||||||
*
|
*
|
||||||
* @return 0 on success and negative error code on failure
|
* @return 0 on success and negative error code on failure
|
||||||
*/
|
*/
|
||||||
@@ -475,7 +602,7 @@ static inline void sbi_platform_irqchip_exit(const struct sbi_platform *plat)
|
|||||||
* Initialize the platform IPI support for current HART
|
* Initialize the platform IPI support for current HART
|
||||||
*
|
*
|
||||||
* @param plat pointer to struct sbi_platform
|
* @param plat pointer to struct sbi_platform
|
||||||
* @param cold_boot whether cold boot (TRUE) or warm_boot (FALSE)
|
* @param cold_boot whether cold boot (true) or warm_boot (false)
|
||||||
*
|
*
|
||||||
* @return 0 on success and negative error code on failure
|
* @return 0 on success and negative error code on failure
|
||||||
*/
|
*/
|
||||||
@@ -502,7 +629,7 @@ static inline void sbi_platform_ipi_exit(const struct sbi_platform *plat)
|
|||||||
* Initialize the platform timer for current HART
|
* Initialize the platform timer for current HART
|
||||||
*
|
*
|
||||||
* @param plat pointer to struct sbi_platform
|
* @param plat pointer to struct sbi_platform
|
||||||
* @param cold_boot whether cold boot (TRUE) or warm_boot (FALSE)
|
* @param cold_boot whether cold boot (true) or warm_boot (false)
|
||||||
*
|
*
|
||||||
* @return 0 on success and negative error code on failure
|
* @return 0 on success and negative error code on failure
|
||||||
*/
|
*/
|
||||||
@@ -526,27 +653,25 @@ static inline void sbi_platform_timer_exit(const struct sbi_platform *plat)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a vendor extension is implemented or not.
|
* Check if SBI vendor extension is implemented or not.
|
||||||
*
|
*
|
||||||
* @param plat pointer to struct sbi_platform
|
* @param plat pointer to struct sbi_platform
|
||||||
* @param extid vendor SBI extension id
|
|
||||||
*
|
*
|
||||||
* @return 0 if extid is not implemented and 1 if implemented
|
* @return false if not implemented and true if implemented
|
||||||
*/
|
*/
|
||||||
static inline int sbi_platform_vendor_ext_check(const struct sbi_platform *plat,
|
static inline bool sbi_platform_vendor_ext_check(
|
||||||
long extid)
|
const struct sbi_platform *plat)
|
||||||
{
|
{
|
||||||
if (plat && sbi_platform_ops(plat)->vendor_ext_check)
|
if (plat && sbi_platform_ops(plat)->vendor_ext_check)
|
||||||
return sbi_platform_ops(plat)->vendor_ext_check(extid);
|
return sbi_platform_ops(plat)->vendor_ext_check();
|
||||||
|
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoke platform specific vendor SBI extension implementation.
|
* Invoke platform specific vendor SBI extension implementation.
|
||||||
*
|
*
|
||||||
* @param plat pointer to struct sbi_platform
|
* @param plat pointer to struct sbi_platform
|
||||||
* @param extid vendor SBI extension id
|
|
||||||
* @param funcid SBI function id within the extension id
|
* @param funcid SBI function id within the extension id
|
||||||
* @param regs pointer to trap registers passed by the caller
|
* @param regs pointer to trap registers passed by the caller
|
||||||
* @param out_value output value that can be filled by the callee
|
* @param out_value output value that can be filled by the callee
|
||||||
@@ -556,14 +681,14 @@ static inline int sbi_platform_vendor_ext_check(const struct sbi_platform *plat,
|
|||||||
*/
|
*/
|
||||||
static inline int sbi_platform_vendor_ext_provider(
|
static inline int sbi_platform_vendor_ext_provider(
|
||||||
const struct sbi_platform *plat,
|
const struct sbi_platform *plat,
|
||||||
long extid, long funcid,
|
long funcid,
|
||||||
const struct sbi_trap_regs *regs,
|
const struct sbi_trap_regs *regs,
|
||||||
unsigned long *out_value,
|
unsigned long *out_value,
|
||||||
struct sbi_trap_info *out_trap)
|
struct sbi_trap_info *out_trap)
|
||||||
{
|
{
|
||||||
if (plat && sbi_platform_ops(plat)->vendor_ext_provider) {
|
if (plat && sbi_platform_ops(plat)->vendor_ext_provider) {
|
||||||
return sbi_platform_ops(plat)->vendor_ext_provider(extid,
|
return sbi_platform_ops(plat)->vendor_ext_provider(funcid,
|
||||||
funcid, regs,
|
regs,
|
||||||
out_value,
|
out_value,
|
||||||
out_trap);
|
out_trap);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,16 +11,12 @@
|
|||||||
#define __SBI_PMU_H__
|
#define __SBI_PMU_H__
|
||||||
|
|
||||||
#include <sbi/sbi_types.h>
|
#include <sbi/sbi_types.h>
|
||||||
#include <sbi/sbi_hartmask.h>
|
|
||||||
#include <sbi/sbi_scratch.h>
|
struct sbi_scratch;
|
||||||
#include <sbi/sbi_ecall_interface.h>
|
|
||||||
|
|
||||||
/* Event related macros */
|
/* Event related macros */
|
||||||
/* Maximum number of hardware events that can mapped by OpenSBI */
|
/* Maximum number of hardware events that can mapped by OpenSBI */
|
||||||
#define SBI_PMU_HW_EVENT_MAX 64
|
#define SBI_PMU_HW_EVENT_MAX 256
|
||||||
|
|
||||||
/* Maximum number of firmware events that can mapped by OpenSBI */
|
|
||||||
#define SBI_PMU_FW_EVENT_MAX 32
|
|
||||||
|
|
||||||
/* Counter related macros */
|
/* Counter related macros */
|
||||||
#define SBI_PMU_FW_CTR_MAX 16
|
#define SBI_PMU_FW_CTR_MAX 16
|
||||||
@@ -28,12 +24,88 @@
|
|||||||
#define SBI_PMU_CTR_MAX (SBI_PMU_HW_CTR_MAX + SBI_PMU_FW_CTR_MAX)
|
#define SBI_PMU_CTR_MAX (SBI_PMU_HW_CTR_MAX + SBI_PMU_FW_CTR_MAX)
|
||||||
#define SBI_PMU_FIXED_CTR_MASK 0x07
|
#define SBI_PMU_FIXED_CTR_MASK 0x07
|
||||||
|
|
||||||
|
struct sbi_pmu_device {
|
||||||
|
/** Name of the PMU platform device */
|
||||||
|
char name[32];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate event code of custom firmware event
|
||||||
|
*/
|
||||||
|
int (*fw_event_validate_encoding)(uint32_t hartid, uint64_t event_data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Match custom firmware counter with custom firmware event
|
||||||
|
* Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX
|
||||||
|
*/
|
||||||
|
bool (*fw_counter_match_encoding)(uint32_t hartid,
|
||||||
|
uint32_t counter_index,
|
||||||
|
uint64_t event_data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch the max width of this counter in number of bits.
|
||||||
|
*/
|
||||||
|
int (*fw_counter_width)(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read value of custom firmware counter
|
||||||
|
* Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX
|
||||||
|
*/
|
||||||
|
uint64_t (*fw_counter_read_value)(uint32_t hartid,
|
||||||
|
uint32_t counter_index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write value to custom firmware counter
|
||||||
|
* Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX
|
||||||
|
*/
|
||||||
|
void (*fw_counter_write_value)(uint32_t hartid, uint32_t counter_index,
|
||||||
|
uint64_t value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start custom firmware counter
|
||||||
|
* Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX
|
||||||
|
*/
|
||||||
|
int (*fw_counter_start)(uint32_t hartid, uint32_t counter_index,
|
||||||
|
uint64_t event_data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop custom firmware counter
|
||||||
|
* Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX
|
||||||
|
*/
|
||||||
|
int (*fw_counter_stop)(uint32_t hartid, uint32_t counter_index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom enable irq for hardware counter
|
||||||
|
* Note: 0 <= counter_index < SBI_PMU_HW_CTR_MAX
|
||||||
|
*/
|
||||||
|
void (*hw_counter_enable_irq)(uint32_t counter_index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom disable irq for hardware counter
|
||||||
|
* Note: 0 <= counter_index < SBI_PMU_HW_CTR_MAX
|
||||||
|
*/
|
||||||
|
void (*hw_counter_disable_irq)(uint32_t counter_index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom function returning the machine-specific irq-bit.
|
||||||
|
*/
|
||||||
|
int (*hw_counter_irq_bit)(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Get the PMU platform device */
|
||||||
|
const struct sbi_pmu_device *sbi_pmu_get_device(void);
|
||||||
|
|
||||||
|
/** Set the PMU platform device */
|
||||||
|
void sbi_pmu_set_device(const struct sbi_pmu_device *dev);
|
||||||
|
|
||||||
/** Initialize PMU */
|
/** Initialize PMU */
|
||||||
int sbi_pmu_init(struct sbi_scratch *scratch, bool cold_boot);
|
int sbi_pmu_init(struct sbi_scratch *scratch, bool cold_boot);
|
||||||
|
|
||||||
/** Reset PMU during hart exit */
|
/** Reset PMU during hart exit */
|
||||||
void sbi_pmu_exit(struct sbi_scratch *scratch);
|
void sbi_pmu_exit(struct sbi_scratch *scratch);
|
||||||
|
|
||||||
|
/** Return the pmu irq bit depending on extension existence */
|
||||||
|
int sbi_pmu_irq_bit(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the hardware event to counter mapping information. This should be called
|
* Add the hardware event to counter mapping information. This should be called
|
||||||
* from the platform code to update the mapping table.
|
* from the platform code to update the mapping table.
|
||||||
@@ -53,7 +125,7 @@ int sbi_pmu_add_hw_event_counter_map(u32 eidx_start, u32 eidx_end, u32 cmap);
|
|||||||
|
|
||||||
int sbi_pmu_add_raw_event_counter_map(uint64_t select, uint64_t select_mask, u32 cmap);
|
int sbi_pmu_add_raw_event_counter_map(uint64_t select, uint64_t select_mask, u32 cmap);
|
||||||
|
|
||||||
int sbi_pmu_ctr_read(uint32_t cidx, unsigned long *cval);
|
int sbi_pmu_ctr_fw_read(uint32_t cidx, uint64_t *cval);
|
||||||
|
|
||||||
int sbi_pmu_ctr_stop(unsigned long cidx_base, unsigned long cidx_mask,
|
int sbi_pmu_ctr_stop(unsigned long cidx_base, unsigned long cidx_mask,
|
||||||
unsigned long flag);
|
unsigned long flag);
|
||||||
|
|||||||
@@ -18,28 +18,30 @@
|
|||||||
#define SBI_SCRATCH_FW_START_OFFSET (0 * __SIZEOF_POINTER__)
|
#define SBI_SCRATCH_FW_START_OFFSET (0 * __SIZEOF_POINTER__)
|
||||||
/** Offset of fw_size member in sbi_scratch */
|
/** Offset of fw_size member in sbi_scratch */
|
||||||
#define SBI_SCRATCH_FW_SIZE_OFFSET (1 * __SIZEOF_POINTER__)
|
#define SBI_SCRATCH_FW_SIZE_OFFSET (1 * __SIZEOF_POINTER__)
|
||||||
|
/** Offset (in sbi_scratch) of the R/W Offset */
|
||||||
|
#define SBI_SCRATCH_FW_RW_OFFSET (2 * __SIZEOF_POINTER__)
|
||||||
/** Offset of next_arg1 member in sbi_scratch */
|
/** Offset of next_arg1 member in sbi_scratch */
|
||||||
#define SBI_SCRATCH_NEXT_ARG1_OFFSET (2 * __SIZEOF_POINTER__)
|
#define SBI_SCRATCH_NEXT_ARG1_OFFSET (3 * __SIZEOF_POINTER__)
|
||||||
/** Offset of next_addr member in sbi_scratch */
|
/** Offset of next_addr member in sbi_scratch */
|
||||||
#define SBI_SCRATCH_NEXT_ADDR_OFFSET (3 * __SIZEOF_POINTER__)
|
#define SBI_SCRATCH_NEXT_ADDR_OFFSET (4 * __SIZEOF_POINTER__)
|
||||||
/** Offset of next_mode member in sbi_scratch */
|
/** Offset of next_mode member in sbi_scratch */
|
||||||
#define SBI_SCRATCH_NEXT_MODE_OFFSET (4 * __SIZEOF_POINTER__)
|
#define SBI_SCRATCH_NEXT_MODE_OFFSET (5 * __SIZEOF_POINTER__)
|
||||||
/** Offset of warmboot_addr member in sbi_scratch */
|
/** Offset of warmboot_addr member in sbi_scratch */
|
||||||
#define SBI_SCRATCH_WARMBOOT_ADDR_OFFSET (5 * __SIZEOF_POINTER__)
|
#define SBI_SCRATCH_WARMBOOT_ADDR_OFFSET (6 * __SIZEOF_POINTER__)
|
||||||
/** Offset of platform_addr member in sbi_scratch */
|
/** Offset of platform_addr member in sbi_scratch */
|
||||||
#define SBI_SCRATCH_PLATFORM_ADDR_OFFSET (6 * __SIZEOF_POINTER__)
|
#define SBI_SCRATCH_PLATFORM_ADDR_OFFSET (7 * __SIZEOF_POINTER__)
|
||||||
/** Offset of hartid_to_scratch member in sbi_scratch */
|
/** Offset of hartid_to_scratch member in sbi_scratch */
|
||||||
#define SBI_SCRATCH_HARTID_TO_SCRATCH_OFFSET (7 * __SIZEOF_POINTER__)
|
#define SBI_SCRATCH_HARTID_TO_SCRATCH_OFFSET (8 * __SIZEOF_POINTER__)
|
||||||
/** Offset of trap_exit member in sbi_scratch */
|
/** Offset of trap_exit member in sbi_scratch */
|
||||||
#define SBI_SCRATCH_TRAP_EXIT_OFFSET (8 * __SIZEOF_POINTER__)
|
#define SBI_SCRATCH_TRAP_EXIT_OFFSET (9 * __SIZEOF_POINTER__)
|
||||||
/** Offset of tmp0 member in sbi_scratch */
|
/** Offset of tmp0 member in sbi_scratch */
|
||||||
#define SBI_SCRATCH_TMP0_OFFSET (9 * __SIZEOF_POINTER__)
|
#define SBI_SCRATCH_TMP0_OFFSET (10 * __SIZEOF_POINTER__)
|
||||||
/** Offset of options member in sbi_scratch */
|
/** Offset of options member in sbi_scratch */
|
||||||
#define SBI_SCRATCH_OPTIONS_OFFSET (10 * __SIZEOF_POINTER__)
|
#define SBI_SCRATCH_OPTIONS_OFFSET (11 * __SIZEOF_POINTER__)
|
||||||
/** Offset of extra space in sbi_scratch */
|
/** Offset of extra space in sbi_scratch */
|
||||||
#define SBI_SCRATCH_EXTRA_SPACE_OFFSET (11 * __SIZEOF_POINTER__)
|
#define SBI_SCRATCH_EXTRA_SPACE_OFFSET (12 * __SIZEOF_POINTER__)
|
||||||
/** Maximum size of sbi_scratch (4KB) */
|
/** Maximum size of sbi_scratch (4KB) */
|
||||||
#define SBI_SCRATCH_SIZE (0x1000)
|
#define SBI_SCRATCH_SIZE (0x2000)
|
||||||
|
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
|
||||||
@@ -53,11 +55,13 @@ struct sbi_scratch {
|
|||||||
unsigned long fw_start;
|
unsigned long fw_start;
|
||||||
/** Size (in bytes) of firmware linked to OpenSBI library */
|
/** Size (in bytes) of firmware linked to OpenSBI library */
|
||||||
unsigned long fw_size;
|
unsigned long fw_size;
|
||||||
|
/** Offset (in bytes) of the R/W section */
|
||||||
|
unsigned long fw_rw_offset;
|
||||||
/** Arg1 (or 'a1' register) of next booting stage for this HART */
|
/** Arg1 (or 'a1' register) of next booting stage for this HART */
|
||||||
unsigned long next_arg1;
|
unsigned long next_arg1;
|
||||||
/** Address of next booting stage for this HART */
|
/** Address of next booting stage for this HART */
|
||||||
unsigned long next_addr;
|
unsigned long next_addr;
|
||||||
/** Priviledge mode of next booting stage for this HART */
|
/** Privilege mode of next booting stage for this HART */
|
||||||
unsigned long next_mode;
|
unsigned long next_mode;
|
||||||
/** Warm boot entry point address for this HART */
|
/** Warm boot entry point address for this HART */
|
||||||
unsigned long warmboot_addr;
|
unsigned long warmboot_addr;
|
||||||
@@ -73,6 +77,66 @@ struct sbi_scratch {
|
|||||||
unsigned long options;
|
unsigned long options;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prevent modification of struct sbi_scratch from affecting
|
||||||
|
* SBI_SCRATCH_xxx_OFFSET
|
||||||
|
*/
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct sbi_scratch, fw_start)
|
||||||
|
== SBI_SCRATCH_FW_START_OFFSET,
|
||||||
|
"struct sbi_scratch definition has changed, please redefine "
|
||||||
|
"SBI_SCRATCH_FW_START_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct sbi_scratch, fw_size)
|
||||||
|
== SBI_SCRATCH_FW_SIZE_OFFSET,
|
||||||
|
"struct sbi_scratch definition has changed, please redefine "
|
||||||
|
"SBI_SCRATCH_FW_SIZE_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct sbi_scratch, next_arg1)
|
||||||
|
== SBI_SCRATCH_NEXT_ARG1_OFFSET,
|
||||||
|
"struct sbi_scratch definition has changed, please redefine "
|
||||||
|
"SBI_SCRATCH_NEXT_ARG1_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct sbi_scratch, next_addr)
|
||||||
|
== SBI_SCRATCH_NEXT_ADDR_OFFSET,
|
||||||
|
"struct sbi_scratch definition has changed, please redefine "
|
||||||
|
"SBI_SCRATCH_NEXT_ADDR_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct sbi_scratch, next_mode)
|
||||||
|
== SBI_SCRATCH_NEXT_MODE_OFFSET,
|
||||||
|
"struct sbi_scratch definition has changed, please redefine "
|
||||||
|
"SBI_SCRATCH_NEXT_MODE_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct sbi_scratch, warmboot_addr)
|
||||||
|
== SBI_SCRATCH_WARMBOOT_ADDR_OFFSET,
|
||||||
|
"struct sbi_scratch definition has changed, please redefine "
|
||||||
|
"SBI_SCRATCH_WARMBOOT_ADDR_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct sbi_scratch, platform_addr)
|
||||||
|
== SBI_SCRATCH_PLATFORM_ADDR_OFFSET,
|
||||||
|
"struct sbi_scratch definition has changed, please redefine "
|
||||||
|
"SBI_SCRATCH_PLATFORM_ADDR_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct sbi_scratch, hartid_to_scratch)
|
||||||
|
== SBI_SCRATCH_HARTID_TO_SCRATCH_OFFSET,
|
||||||
|
"struct sbi_scratch definition has changed, please redefine "
|
||||||
|
"SBI_SCRATCH_HARTID_TO_SCRATCH_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct sbi_scratch, trap_exit)
|
||||||
|
== SBI_SCRATCH_TRAP_EXIT_OFFSET,
|
||||||
|
"struct sbi_scratch definition has changed, please redefine "
|
||||||
|
"SBI_SCRATCH_TRAP_EXIT_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct sbi_scratch, tmp0)
|
||||||
|
== SBI_SCRATCH_TMP0_OFFSET,
|
||||||
|
"struct sbi_scratch definition has changed, please redefine "
|
||||||
|
"SBI_SCRATCH_TMP0_OFFSET");
|
||||||
|
_Static_assert(
|
||||||
|
offsetof(struct sbi_scratch, options)
|
||||||
|
== SBI_SCRATCH_OPTIONS_OFFSET,
|
||||||
|
"struct sbi_scratch definition has changed, please redefine "
|
||||||
|
"SBI_SCRATCH_OPTIONS_OFFSET");
|
||||||
|
|
||||||
/** Possible options for OpenSBI library */
|
/** Possible options for OpenSBI library */
|
||||||
enum sbi_scratch_options {
|
enum sbi_scratch_options {
|
||||||
/** Disable prints during boot */
|
/** Disable prints during boot */
|
||||||
@@ -104,11 +168,11 @@ unsigned long sbi_scratch_alloc_offset(unsigned long size);
|
|||||||
void sbi_scratch_free_offset(unsigned long offset);
|
void sbi_scratch_free_offset(unsigned long offset);
|
||||||
|
|
||||||
/** Get pointer from offset in sbi_scratch */
|
/** Get pointer from offset in sbi_scratch */
|
||||||
#define sbi_scratch_offset_ptr(scratch, offset) ((void *)scratch + (offset))
|
#define sbi_scratch_offset_ptr(scratch, offset) (void *)((char *)(scratch) + (offset))
|
||||||
|
|
||||||
/** Get pointer from offset in sbi_scratch for current HART */
|
/** Get pointer from offset in sbi_scratch for current HART */
|
||||||
#define sbi_scratch_thishart_offset_ptr(offset) \
|
#define sbi_scratch_thishart_offset_ptr(offset) \
|
||||||
((void *)sbi_scratch_thishart_ptr() + (offset))
|
(void *)((char *)sbi_scratch_thishart_ptr() + (offset))
|
||||||
|
|
||||||
/** HART id to scratch table */
|
/** HART id to scratch table */
|
||||||
extern struct sbi_scratch *hartid_to_scratch_table[];
|
extern struct sbi_scratch *hartid_to_scratch_table[];
|
||||||
|
|||||||
@@ -43,4 +43,31 @@ bool sbi_system_reset_supported(u32 reset_type, u32 reset_reason);
|
|||||||
|
|
||||||
void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason);
|
void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason);
|
||||||
|
|
||||||
|
/** System suspend device */
|
||||||
|
struct sbi_system_suspend_device {
|
||||||
|
/** Name of the system suspend device */
|
||||||
|
char name[32];
|
||||||
|
|
||||||
|
/* Check whether sleep type is supported by the device */
|
||||||
|
int (*system_suspend_check)(u32 sleep_type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Suspend the system
|
||||||
|
*
|
||||||
|
* @sleep_type: The sleep type identifier passed to the SBI call.
|
||||||
|
* @mmode_resume_addr:
|
||||||
|
* This is the same as sbi_scratch.warmboot_addr. Some platforms
|
||||||
|
* may not be able to return from system_suspend(), so they will
|
||||||
|
* jump directly to this address instead. Platforms which can
|
||||||
|
* return from system_suspend() may ignore this parameter.
|
||||||
|
*/
|
||||||
|
int (*system_suspend)(u32 sleep_type, unsigned long mmode_resume_addr);
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct sbi_system_suspend_device *sbi_system_suspend_get_device(void);
|
||||||
|
void sbi_system_suspend_set_device(struct sbi_system_suspend_device *dev);
|
||||||
|
void sbi_system_suspend_test_enable(void);
|
||||||
|
bool sbi_system_suspend_supported(u32 sleep_type);
|
||||||
|
int sbi_system_suspend(u32 sleep_type, ulong resume_addr, ulong opaque);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -48,6 +48,24 @@ static inline void sbi_timer_udelay(ulong usecs)
|
|||||||
sbi_timer_delay_loop(usecs, 1000000, NULL, NULL);
|
sbi_timer_delay_loop(usecs, 1000000, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A blocking function that will wait until @p predicate returns true or
|
||||||
|
* @p timeout_ms milliseconds elapsed. @p arg will be passed as argument to
|
||||||
|
* @p predicate function.
|
||||||
|
*
|
||||||
|
* @param predicate Pointer to a function that returns true if certain
|
||||||
|
* condition is met. It shouldn't block the code execution.
|
||||||
|
* @param arg Argument to pass to @p predicate.
|
||||||
|
* @param timeout_ms Timeout value in milliseconds. The function will return
|
||||||
|
* false if @p timeout_ms time period elapsed but still @p predicate doesn't
|
||||||
|
* return true.
|
||||||
|
*
|
||||||
|
* @return true if @p predicate returns true within @p timeout_ms, false
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
|
bool sbi_timer_waitms_until(bool (*predicate)(void *), void *arg,
|
||||||
|
uint64_t timeout_ms);
|
||||||
|
|
||||||
/** Get timer value for current HART */
|
/** Get timer value for current HART */
|
||||||
u64 sbi_timer_value(void);
|
u64 sbi_timer_value(void);
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
|
||||||
#define SBI_TLB_FIFO_NUM_ENTRIES 8
|
#define SBI_TLB_FIFO_NUM_ENTRIES 128
|
||||||
|
|
||||||
struct sbi_scratch;
|
struct sbi_scratch;
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
#ifndef __SBI_TRAP_H__
|
#ifndef __SBI_TRAP_H__
|
||||||
#define __SBI_TRAP_H__
|
#define __SBI_TRAP_H__
|
||||||
|
|
||||||
|
#include <sbi/riscv_encoding.h>
|
||||||
|
|
||||||
/* clang-format off */
|
/* clang-format off */
|
||||||
|
|
||||||
/** Index of zero member in sbi_trap_regs */
|
/** Index of zero member in sbi_trap_regs */
|
||||||
@@ -95,8 +97,10 @@
|
|||||||
#define SBI_TRAP_INFO_tval2 3
|
#define SBI_TRAP_INFO_tval2 3
|
||||||
/** Index of tinst member in sbi_trap_info */
|
/** Index of tinst member in sbi_trap_info */
|
||||||
#define SBI_TRAP_INFO_tinst 4
|
#define SBI_TRAP_INFO_tinst 4
|
||||||
|
/** Index of gva member in sbi_trap_info */
|
||||||
|
#define SBI_TRAP_INFO_gva 5
|
||||||
/** Last member index in sbi_trap_info */
|
/** Last member index in sbi_trap_info */
|
||||||
#define SBI_TRAP_INFO_last 5
|
#define SBI_TRAP_INFO_last 6
|
||||||
|
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
|
||||||
@@ -200,8 +204,26 @@ struct sbi_trap_info {
|
|||||||
unsigned long tval2;
|
unsigned long tval2;
|
||||||
/** tinst Trap instruction */
|
/** tinst Trap instruction */
|
||||||
unsigned long tinst;
|
unsigned long tinst;
|
||||||
|
/** gva Guest virtual address in tval flag */
|
||||||
|
unsigned long gva;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static inline unsigned long sbi_regs_gva(const struct sbi_trap_regs *regs)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* If the hypervisor extension is not implemented, mstatus[h].GVA is a
|
||||||
|
* WPRI field, which is guaranteed to read as zero. In addition, in this
|
||||||
|
* case we don't read mstatush and instead pretend it is zero, which
|
||||||
|
* handles privileged spec version < 1.12.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if __riscv_xlen == 32
|
||||||
|
return (regs->mstatusH & MSTATUSH_GVA) ? 1 : 0;
|
||||||
|
#else
|
||||||
|
return (regs->mstatus & MSTATUS_GVA) ? 1 : 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int sbi_trap_redirect(struct sbi_trap_regs *regs,
|
int sbi_trap_redirect(struct sbi_trap_regs *regs,
|
||||||
struct sbi_trap_info *trap);
|
struct sbi_trap_info *trap);
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,11 @@ typedef unsigned long long uint64_t;
|
|||||||
#error "Unexpected __riscv_xlen"
|
#error "Unexpected __riscv_xlen"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __STDC_VERSION__ < 202000L
|
||||||
typedef int bool;
|
typedef int bool;
|
||||||
|
#define true 1
|
||||||
|
#define false 0
|
||||||
|
#endif
|
||||||
typedef unsigned long ulong;
|
typedef unsigned long ulong;
|
||||||
typedef unsigned long uintptr_t;
|
typedef unsigned long uintptr_t;
|
||||||
typedef unsigned long size_t;
|
typedef unsigned long size_t;
|
||||||
@@ -54,16 +58,19 @@ typedef unsigned long virtual_size_t;
|
|||||||
typedef unsigned long physical_addr_t;
|
typedef unsigned long physical_addr_t;
|
||||||
typedef unsigned long physical_size_t;
|
typedef unsigned long physical_size_t;
|
||||||
|
|
||||||
#define TRUE 1
|
typedef uint16_t le16_t;
|
||||||
#define FALSE 0
|
typedef uint16_t be16_t;
|
||||||
#define true TRUE
|
typedef uint32_t le32_t;
|
||||||
#define false FALSE
|
typedef uint32_t be32_t;
|
||||||
|
typedef uint64_t le64_t;
|
||||||
|
typedef uint64_t be64_t;
|
||||||
|
|
||||||
#define NULL ((void *)0)
|
#define NULL ((void *)0)
|
||||||
|
|
||||||
#define __packed __attribute__((packed))
|
#define __packed __attribute__((packed))
|
||||||
#define __noreturn __attribute__((noreturn))
|
#define __noreturn __attribute__((noreturn))
|
||||||
#define __aligned(x) __attribute__((aligned(x)))
|
#define __aligned(x) __attribute__((aligned(x)))
|
||||||
|
#define __always_inline inline __attribute__((always_inline))
|
||||||
|
|
||||||
#define likely(x) __builtin_expect((x), 1)
|
#define likely(x) __builtin_expect((x), 1)
|
||||||
#define unlikely(x) __builtin_expect((x), 0)
|
#define unlikely(x) __builtin_expect((x), 0)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#define __SBI_VERSION_H__
|
#define __SBI_VERSION_H__
|
||||||
|
|
||||||
#define OPENSBI_VERSION_MAJOR 1
|
#define OPENSBI_VERSION_MAJOR 1
|
||||||
#define OPENSBI_VERSION_MINOR 0
|
#define OPENSBI_VERSION_MINOR 2
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OpenSBI 32-bit version with:
|
* OpenSBI 32-bit version with:
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
#include <sbi/sbi_types.h>
|
#include <sbi/sbi_types.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_FDT_DOMAIN
|
||||||
|
|
||||||
struct sbi_domain;
|
struct sbi_domain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,4 +72,11 @@ void fdt_domain_fixup(void *fdt);
|
|||||||
*/
|
*/
|
||||||
int fdt_domains_populate(void *fdt);
|
int fdt_domains_populate(void *fdt);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
static inline void fdt_domain_fixup(void *fdt) { }
|
||||||
|
static inline int fdt_domains_populate(void *fdt) { return 0; }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __FDT_DOMAIN_H__ */
|
#endif /* __FDT_DOMAIN_H__ */
|
||||||
|
|||||||
@@ -9,6 +9,29 @@
|
|||||||
#ifndef __FDT_FIXUP_H__
|
#ifndef __FDT_FIXUP_H__
|
||||||
#define __FDT_FIXUP_H__
|
#define __FDT_FIXUP_H__
|
||||||
|
|
||||||
|
struct sbi_cpu_idle_state {
|
||||||
|
const char *name;
|
||||||
|
uint32_t suspend_param;
|
||||||
|
bool local_timer_stop;
|
||||||
|
uint32_t entry_latency_us;
|
||||||
|
uint32_t exit_latency_us;
|
||||||
|
uint32_t min_residency_us;
|
||||||
|
uint32_t wakeup_latency_us;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add CPU idle states to cpu nodes in the DT
|
||||||
|
*
|
||||||
|
* Add information about CPU idle states to the devicetree. This function
|
||||||
|
* assumes that CPU idle states are not already present in the devicetree, and
|
||||||
|
* that all CPU states are equally applicable to all CPUs.
|
||||||
|
*
|
||||||
|
* @param fdt: device tree blob
|
||||||
|
* @param states: array of idle state descriptions, ending with empty element
|
||||||
|
* @return zero on success and -ve on failure
|
||||||
|
*/
|
||||||
|
int fdt_add_cpu_idle_states(void *dtb, const struct sbi_cpu_idle_state *state);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fix up the CPU node in the device tree
|
* Fix up the CPU node in the device tree
|
||||||
*
|
*
|
||||||
@@ -21,6 +44,30 @@
|
|||||||
*/
|
*/
|
||||||
void fdt_cpu_fixup(void *fdt);
|
void fdt_cpu_fixup(void *fdt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fix up the APLIC nodes in the device tree
|
||||||
|
*
|
||||||
|
* This routine disables APLIC nodes which are not accessible to the next
|
||||||
|
* booting stage based on currently assigned domain.
|
||||||
|
*
|
||||||
|
* It is recommended that platform codes call this helper in their final_init()
|
||||||
|
*
|
||||||
|
* @param fdt: device tree blob
|
||||||
|
*/
|
||||||
|
void fdt_aplic_fixup(void *fdt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fix up the IMSIC nodes in the device tree
|
||||||
|
*
|
||||||
|
* This routine disables IMSIC nodes which are not accessible to the next
|
||||||
|
* booting stage based on currently assigned domain.
|
||||||
|
*
|
||||||
|
* It is recommended that platform codes call this helper in their final_init()
|
||||||
|
*
|
||||||
|
* @param fdt: device tree blob
|
||||||
|
*/
|
||||||
|
void fdt_imsic_fixup(void *fdt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fix up the PLIC node in the device tree
|
* Fix up the PLIC node in the device tree
|
||||||
*
|
*
|
||||||
@@ -64,8 +111,9 @@ int fdt_reserved_memory_nomap_fixup(void *fdt);
|
|||||||
* General device tree fix-up
|
* General device tree fix-up
|
||||||
*
|
*
|
||||||
* This routine do all required device tree fix-ups for a typical platform.
|
* This routine do all required device tree fix-ups for a typical platform.
|
||||||
* It fixes up the PLIC node and the reserved memory node in the device tree
|
* It fixes up the PLIC node, IMSIC nodes, APLIC nodes, and the reserved
|
||||||
* by calling the corresponding helper routines to accomplish the task.
|
* memory node in the device tree by calling the corresponding helper
|
||||||
|
* routines to accomplish the task.
|
||||||
*
|
*
|
||||||
* It is recommended that platform codes call this helper in their final_init()
|
* It is recommended that platform codes call this helper in their final_init()
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -11,11 +11,11 @@
|
|||||||
#define __FDT_HELPER_H__
|
#define __FDT_HELPER_H__
|
||||||
|
|
||||||
#include <sbi/sbi_types.h>
|
#include <sbi/sbi_types.h>
|
||||||
#include <sbi/sbi_scratch.h>
|
#include <sbi/sbi_domain.h>
|
||||||
|
|
||||||
struct fdt_match {
|
struct fdt_match {
|
||||||
const char *compatible;
|
const char *compatible;
|
||||||
void *data;
|
const void *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define FDT_MAX_PHANDLE_ARGS 16
|
#define FDT_MAX_PHANDLE_ARGS 16
|
||||||
@@ -31,6 +31,7 @@ struct platform_uart_data {
|
|||||||
unsigned long baud;
|
unsigned long baud;
|
||||||
unsigned long reg_shift;
|
unsigned long reg_shift;
|
||||||
unsigned long reg_io_width;
|
unsigned long reg_io_width;
|
||||||
|
unsigned long reg_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct fdt_match *fdt_match_node(void *fdt, int nodeoff,
|
const struct fdt_match *fdt_match_node(void *fdt, int nodeoff,
|
||||||
@@ -47,27 +48,45 @@ int fdt_parse_phandle_with_args(void *fdt, int nodeoff,
|
|||||||
int fdt_get_node_addr_size(void *fdt, int node, int index,
|
int fdt_get_node_addr_size(void *fdt, int node, int index,
|
||||||
uint64_t *addr, uint64_t *size);
|
uint64_t *addr, uint64_t *size);
|
||||||
|
|
||||||
|
bool fdt_node_is_enabled(void *fdt, int nodeoff);
|
||||||
|
|
||||||
int fdt_parse_hart_id(void *fdt, int cpu_offset, u32 *hartid);
|
int fdt_parse_hart_id(void *fdt, int cpu_offset, u32 *hartid);
|
||||||
|
|
||||||
int fdt_parse_max_hart_id(void *fdt, u32 *max_hartid);
|
int fdt_parse_max_enabled_hart_id(void *fdt, u32 *max_hartid);
|
||||||
|
|
||||||
int fdt_parse_timebase_frequency(void *fdt, unsigned long *freq);
|
int fdt_parse_timebase_frequency(void *fdt, unsigned long *freq);
|
||||||
|
|
||||||
int fdt_parse_gaisler_uart_node(void *fdt, int nodeoffset,
|
int fdt_parse_gaisler_uart_node(void *fdt, int nodeoffset,
|
||||||
struct platform_uart_data *uart);
|
struct platform_uart_data *uart);
|
||||||
|
|
||||||
|
int fdt_parse_renesas_scif_node(void *fdt, int nodeoffset,
|
||||||
|
struct platform_uart_data *uart);
|
||||||
|
|
||||||
int fdt_parse_shakti_uart_node(void *fdt, int nodeoffset,
|
int fdt_parse_shakti_uart_node(void *fdt, int nodeoffset,
|
||||||
struct platform_uart_data *uart);
|
struct platform_uart_data *uart);
|
||||||
|
|
||||||
int fdt_parse_sifive_uart_node(void *fdt, int nodeoffset,
|
int fdt_parse_sifive_uart_node(void *fdt, int nodeoffset,
|
||||||
struct platform_uart_data *uart);
|
struct platform_uart_data *uart);
|
||||||
|
|
||||||
int fdt_parse_uart8250_node(void *fdt, int nodeoffset,
|
int fdt_parse_uart_node(void *fdt, int nodeoffset,
|
||||||
struct platform_uart_data *uart);
|
struct platform_uart_data *uart);
|
||||||
|
|
||||||
int fdt_parse_uart8250(void *fdt, struct platform_uart_data *uart,
|
int fdt_parse_uart8250(void *fdt, struct platform_uart_data *uart,
|
||||||
const char *compatible);
|
const char *compatible);
|
||||||
|
|
||||||
|
int fdt_parse_xlnx_uartlite_node(void *fdt, int nodeoffset,
|
||||||
|
struct platform_uart_data *uart);
|
||||||
|
|
||||||
|
struct aplic_data;
|
||||||
|
|
||||||
|
int fdt_parse_aplic_node(void *fdt, int nodeoff, struct aplic_data *aplic);
|
||||||
|
|
||||||
|
struct imsic_data;
|
||||||
|
|
||||||
|
bool fdt_check_imsic_mlevel(void *fdt);
|
||||||
|
|
||||||
|
int fdt_parse_imsic_node(void *fdt, int nodeoff, struct imsic_data *imsic);
|
||||||
|
|
||||||
struct plic_data;
|
struct plic_data;
|
||||||
|
|
||||||
int fdt_parse_plic_node(void *fdt, int nodeoffset, struct plic_data *plic);
|
int fdt_parse_plic_node(void *fdt, int nodeoffset, struct plic_data *plic);
|
||||||
@@ -79,12 +98,18 @@ int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer,
|
|||||||
unsigned long *out_addr2, unsigned long *out_size2,
|
unsigned long *out_addr2, unsigned long *out_size2,
|
||||||
u32 *out_first_hartid, u32 *out_hart_count);
|
u32 *out_first_hartid, u32 *out_hart_count);
|
||||||
|
|
||||||
|
int fdt_parse_plmt_node(void *fdt, int nodeoffset, unsigned long *plmt_base,
|
||||||
|
unsigned long *plmt_size, u32 *hart_count);
|
||||||
|
|
||||||
|
int fdt_parse_plicsw_node(void *fdt, int nodeoffset, unsigned long *plicsw_base,
|
||||||
|
unsigned long *size, u32 *hart_count);
|
||||||
|
|
||||||
int fdt_parse_compat_addr(void *fdt, uint64_t *addr,
|
int fdt_parse_compat_addr(void *fdt, uint64_t *addr,
|
||||||
const char *compatible);
|
const char *compatible);
|
||||||
|
|
||||||
static inline void *fdt_get_address(void)
|
static inline void *fdt_get_address(void)
|
||||||
{
|
{
|
||||||
return sbi_scratch_thishart_arg1_ptr();
|
return (void *)root.next_arg1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* __FDT_HELPER_H__ */
|
#endif /* __FDT_HELPER_H__ */
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
#include <sbi/sbi_types.h>
|
#include <sbi/sbi_types.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_FDT_PMU
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fix up the PMU node in the device tree
|
* Fix up the PMU node in the device tree
|
||||||
*
|
*
|
||||||
@@ -43,4 +45,12 @@ int fdt_pmu_setup(void *fdt);
|
|||||||
*/
|
*/
|
||||||
uint64_t fdt_pmu_get_select_value(uint32_t event_idx);
|
uint64_t fdt_pmu_get_select_value(uint32_t event_idx);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
static inline void fdt_pmu_fixup(void *fdt) { }
|
||||||
|
static inline int fdt_pmu_setup(void *fdt) { return 0; }
|
||||||
|
static inline uint64_t fdt_pmu_get_select_value(uint32_t event_idx) { return 0; }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#include <sbi_utils/gpio/gpio.h>
|
#include <sbi_utils/gpio/gpio.h>
|
||||||
|
|
||||||
|
struct fdt_phandle_args;
|
||||||
|
|
||||||
/** FDT based GPIO driver */
|
/** FDT based GPIO driver */
|
||||||
struct fdt_gpio {
|
struct fdt_gpio {
|
||||||
const struct fdt_match *match_table;
|
const struct fdt_match *match_table;
|
||||||
|
|||||||
21
include/sbi_utils/i2c/dw_i2c.h
Normal file
21
include/sbi_utils/i2c/dw_i2c.h
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 StarFive Technology Co., Ltd.
|
||||||
|
*
|
||||||
|
* Author: Minda Chen <minda.chen@starfivetech.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __DW_I2C_H__
|
||||||
|
#define __DW_I2C_H__
|
||||||
|
|
||||||
|
#include <sbi_utils/i2c/i2c.h>
|
||||||
|
|
||||||
|
int dw_i2c_init(struct i2c_adapter *, int nodeoff);
|
||||||
|
|
||||||
|
struct dw_i2c_adapter {
|
||||||
|
unsigned long addr;
|
||||||
|
struct i2c_adapter adapter;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
46
include/sbi_utils/ipi/andes_plicsw.h
Normal file
46
include/sbi_utils/ipi/andes_plicsw.h
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Andes Technology Corporation
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Zong Li <zong@andestech.com>
|
||||||
|
* Nylon Chen <nylon7@andestech.com>
|
||||||
|
* Leo Yu-Chi Liang <ycliang@andestech.com>
|
||||||
|
* Yu Chien Peter Lin <peterlin@andestech.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _IPI_ANDES_PLICSW_H_
|
||||||
|
#define _IPI_ANDES_PLICSW_H_
|
||||||
|
|
||||||
|
#define PLICSW_PRIORITY_BASE 0x4
|
||||||
|
|
||||||
|
#define PLICSW_PENDING_BASE 0x1000
|
||||||
|
#define PLICSW_PENDING_STRIDE 0x8
|
||||||
|
|
||||||
|
#define PLICSW_ENABLE_BASE 0x2000
|
||||||
|
#define PLICSW_ENABLE_STRIDE 0x80
|
||||||
|
|
||||||
|
#define PLICSW_CONTEXT_BASE 0x200000
|
||||||
|
#define PLICSW_CONTEXT_STRIDE 0x1000
|
||||||
|
#define PLICSW_CONTEXT_CLAIM 0x4
|
||||||
|
|
||||||
|
#define PLICSW_HART_MASK 0x01010101
|
||||||
|
|
||||||
|
#define PLICSW_HART_MAX_NR 8
|
||||||
|
|
||||||
|
#define PLICSW_REGION_ALIGN 0x1000
|
||||||
|
|
||||||
|
struct plicsw_data {
|
||||||
|
unsigned long addr;
|
||||||
|
unsigned long size;
|
||||||
|
uint32_t hart_count;
|
||||||
|
/* hart id to source id table */
|
||||||
|
uint32_t source_id[PLICSW_HART_MAX_NR];
|
||||||
|
};
|
||||||
|
|
||||||
|
int plicsw_warm_ipi_init(void);
|
||||||
|
|
||||||
|
int plicsw_cold_ipi_init(struct plicsw_data *plicsw);
|
||||||
|
|
||||||
|
#endif /* _IPI_ANDES_PLICSW_H_ */
|
||||||
@@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#include <sbi/sbi_types.h>
|
#include <sbi/sbi_types.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_FDT_IPI
|
||||||
|
|
||||||
struct fdt_ipi {
|
struct fdt_ipi {
|
||||||
const struct fdt_match *match_table;
|
const struct fdt_match *match_table;
|
||||||
int (*cold_init)(void *fdt, int nodeoff, const struct fdt_match *match);
|
int (*cold_init)(void *fdt, int nodeoff, const struct fdt_match *match);
|
||||||
@@ -23,4 +25,11 @@ void fdt_ipi_exit(void);
|
|||||||
|
|
||||||
int fdt_ipi_init(bool cold_boot);
|
int fdt_ipi_init(bool cold_boot);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
static inline void fdt_ipi_exit(void) { }
|
||||||
|
static inline int fdt_ipi_init(bool cold_boot) { return 0; }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
47
include/sbi_utils/irqchip/aplic.h
Normal file
47
include/sbi_utils/irqchip/aplic.h
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Western Digital Corporation or its affiliates.
|
||||||
|
* Copyright (c) 2022 Ventana Micro Systems Inc.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Anup Patel <anup.patel@wdc.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __IRQCHIP_APLIC_H__
|
||||||
|
#define __IRQCHIP_APLIC_H__
|
||||||
|
|
||||||
|
#include <sbi/sbi_types.h>
|
||||||
|
|
||||||
|
#define APLIC_MAX_DELEGATE 16
|
||||||
|
|
||||||
|
struct aplic_msicfg_data {
|
||||||
|
unsigned long lhxs;
|
||||||
|
unsigned long lhxw;
|
||||||
|
unsigned long hhxs;
|
||||||
|
unsigned long hhxw;
|
||||||
|
unsigned long base_addr;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct aplic_delegate_data {
|
||||||
|
u32 first_irq;
|
||||||
|
u32 last_irq;
|
||||||
|
u32 child_index;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct aplic_data {
|
||||||
|
unsigned long addr;
|
||||||
|
unsigned long size;
|
||||||
|
unsigned long num_idc;
|
||||||
|
unsigned long num_source;
|
||||||
|
bool targets_mmode;
|
||||||
|
bool has_msicfg_mmode;
|
||||||
|
struct aplic_msicfg_data msicfg_mmode;
|
||||||
|
bool has_msicfg_smode;
|
||||||
|
struct aplic_msicfg_data msicfg_smode;
|
||||||
|
struct aplic_delegate_data delegate[APLIC_MAX_DELEGATE];
|
||||||
|
};
|
||||||
|
|
||||||
|
int aplic_cold_irqchip_init(struct aplic_data *aplic);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#include <sbi/sbi_types.h>
|
#include <sbi/sbi_types.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_FDT_IRQCHIP
|
||||||
|
|
||||||
struct fdt_irqchip {
|
struct fdt_irqchip {
|
||||||
const struct fdt_match *match_table;
|
const struct fdt_match *match_table;
|
||||||
int (*cold_init)(void *fdt, int nodeoff, const struct fdt_match *match);
|
int (*cold_init)(void *fdt, int nodeoff, const struct fdt_match *match);
|
||||||
@@ -23,4 +25,12 @@ void fdt_irqchip_exit(void);
|
|||||||
|
|
||||||
int fdt_irqchip_init(bool cold_boot);
|
int fdt_irqchip_init(bool cold_boot);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
static inline void fdt_irqchip_exit(void) { }
|
||||||
|
|
||||||
|
static inline int fdt_irqchip_init(bool cold_boot) { return 0; }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
33
include/sbi_utils/irqchip/fdt_irqchip_plic.h
Normal file
33
include/sbi_utils/irqchip/fdt_irqchip_plic.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Samuel Holland <samuel@sholland.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __IRQCHIP_FDT_IRQCHIP_PLIC_H__
|
||||||
|
#define __IRQCHIP_FDT_IRQCHIP_PLIC_H__
|
||||||
|
|
||||||
|
#include <sbi/sbi_types.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the PLIC priority state
|
||||||
|
* @param priority pointer to the memory region for the saved priority
|
||||||
|
* @param num size of the memory region including interrupt source 0
|
||||||
|
*/
|
||||||
|
void fdt_plic_priority_save(u8 *priority, u32 num);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore the PLIC priority state
|
||||||
|
* @param priority pointer to the memory region for the saved priority
|
||||||
|
* @param num size of the memory region including interrupt source 0
|
||||||
|
*/
|
||||||
|
void fdt_plic_priority_restore(const u8 *priority, u32 num);
|
||||||
|
|
||||||
|
void fdt_plic_context_save(bool smode, u32 *enable, u32 *threshold, u32 num);
|
||||||
|
|
||||||
|
void fdt_plic_context_restore(bool smode, const u32 *enable, u32 threshold,
|
||||||
|
u32 num);
|
||||||
|
|
||||||
|
void thead_plic_restore(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
60
include/sbi_utils/irqchip/imsic.h
Normal file
60
include/sbi_utils/irqchip/imsic.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021 Western Digital Corporation or its affiliates.
|
||||||
|
* Copyright (c) 2022 Ventana Micro Systems Inc.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Anup Patel <anup.patel@wdc.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __IRQCHIP_IMSIC_H__
|
||||||
|
#define __IRQCHIP_IMSIC_H__
|
||||||
|
|
||||||
|
#include <sbi/sbi_types.h>
|
||||||
|
|
||||||
|
#define IMSIC_MMIO_PAGE_SHIFT 12
|
||||||
|
#define IMSIC_MMIO_PAGE_SZ (1UL << IMSIC_MMIO_PAGE_SHIFT)
|
||||||
|
|
||||||
|
#define IMSIC_MAX_REGS 16
|
||||||
|
|
||||||
|
struct imsic_regs {
|
||||||
|
unsigned long addr;
|
||||||
|
unsigned long size;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct imsic_data {
|
||||||
|
bool targets_mmode;
|
||||||
|
u32 guest_index_bits;
|
||||||
|
u32 hart_index_bits;
|
||||||
|
u32 group_index_bits;
|
||||||
|
u32 group_index_shift;
|
||||||
|
unsigned long num_ids;
|
||||||
|
struct imsic_regs regs[IMSIC_MAX_REGS];
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef CONFIG_IRQCHIP_IMSIC
|
||||||
|
|
||||||
|
int imsic_map_hartid_to_data(u32 hartid, struct imsic_data *imsic, int file);
|
||||||
|
|
||||||
|
struct imsic_data *imsic_get_data(u32 hartid);
|
||||||
|
|
||||||
|
int imsic_get_target_file(u32 hartid);
|
||||||
|
|
||||||
|
void imsic_local_irqchip_init(void);
|
||||||
|
|
||||||
|
int imsic_warm_irqchip_init(void);
|
||||||
|
|
||||||
|
int imsic_data_check(struct imsic_data *imsic);
|
||||||
|
|
||||||
|
int imsic_cold_irqchip_init(struct imsic_data *imsic);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
static inline void imsic_local_irqchip_init(void) { }
|
||||||
|
|
||||||
|
static inline int imsic_data_check(struct imsic_data *imsic) { return 0; }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -17,13 +17,24 @@ struct plic_data {
|
|||||||
unsigned long num_src;
|
unsigned long num_src;
|
||||||
};
|
};
|
||||||
|
|
||||||
int plic_warm_irqchip_init(struct plic_data *plic,
|
/* So far, priorities on all consumers of these functions fit in 8 bits. */
|
||||||
|
void plic_priority_save(const struct plic_data *plic, u8 *priority, u32 num);
|
||||||
|
|
||||||
|
void plic_priority_restore(const struct plic_data *plic, const u8 *priority,
|
||||||
|
u32 num);
|
||||||
|
|
||||||
|
void plic_context_save(const struct plic_data *plic, int context_id,
|
||||||
|
u32 *enable, u32 *threshold, u32 num);
|
||||||
|
|
||||||
|
void plic_context_restore(const struct plic_data *plic, int context_id,
|
||||||
|
const u32 *enable, u32 threshold, u32 num);
|
||||||
|
|
||||||
|
int plic_context_init(const struct plic_data *plic, int context_id,
|
||||||
|
bool enable, u32 threshold);
|
||||||
|
|
||||||
|
int plic_warm_irqchip_init(const struct plic_data *plic,
|
||||||
int m_cntx_id, int s_cntx_id);
|
int m_cntx_id, int s_cntx_id);
|
||||||
|
|
||||||
int plic_cold_irqchip_init(struct plic_data *plic);
|
int plic_cold_irqchip_init(const struct plic_data *plic);
|
||||||
|
|
||||||
void plic_set_thresh(struct plic_data *plic, u32 cntxid, u32 val);
|
|
||||||
|
|
||||||
void plic_set_ie(struct plic_data *plic, u32 cntxid, u32 word_index, u32 val);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ struct fdt_reset {
|
|||||||
int (*init)(void *fdt, int nodeoff, const struct fdt_match *match);
|
int (*init)(void *fdt, int nodeoff, const struct fdt_match *match);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef CONFIG_FDT_RESET
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fdt_reset_driver_init() - initialize reset driver based on the device-tree
|
* fdt_reset_driver_init() - initialize reset driver based on the device-tree
|
||||||
*/
|
*/
|
||||||
@@ -29,4 +31,14 @@ int fdt_reset_driver_init(void *fdt, struct fdt_reset *drv);
|
|||||||
*/
|
*/
|
||||||
void fdt_reset_init(void);
|
void fdt_reset_init(void);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
static inline int fdt_reset_driver_init(void *fdt, struct fdt_reset *drv)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static inline void fdt_reset_init(void) { }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
16
include/sbi_utils/serial/cadence-uart.h
Normal file
16
include/sbi_utils/serial/cadence-uart.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 StarFive Technology Co., Ltd.
|
||||||
|
*
|
||||||
|
* Author: Jun Liang Tan <junliang.tan@linux.starfivetech.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SERIAL_CADENCE_UART_H__
|
||||||
|
#define __SERIAL_CADENCE_UART_H__
|
||||||
|
|
||||||
|
#include <sbi/sbi_types.h>
|
||||||
|
|
||||||
|
int cadence_uart_init(unsigned long base, u32 in_freq, u32 baudrate);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#include <sbi/sbi_types.h>
|
#include <sbi/sbi_types.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_FDT_SERIAL
|
||||||
|
|
||||||
struct fdt_serial {
|
struct fdt_serial {
|
||||||
const struct fdt_match *match_table;
|
const struct fdt_match *match_table;
|
||||||
int (*init)(void *fdt, int nodeoff, const struct fdt_match *match);
|
int (*init)(void *fdt, int nodeoff, const struct fdt_match *match);
|
||||||
@@ -19,4 +21,10 @@ struct fdt_serial {
|
|||||||
|
|
||||||
int fdt_serial_init(void);
|
int fdt_serial_init(void);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
static inline int fdt_serial_init(void) { return 0; }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
11
include/sbi_utils/serial/renesas-scif.h
Normal file
11
include/sbi_utils/serial/renesas-scif.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2022 Renesas Electronics Corporation
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SERIAL_RENESAS_SCIF_H__
|
||||||
|
#define __SERIAL_RENESAS_SCIF_H__
|
||||||
|
|
||||||
|
int renesas_scif_init(unsigned long base, u32 in_freq, u32 baudrate);
|
||||||
|
|
||||||
|
#endif /* __SERIAL_RENESAS_SCIF_H__ */
|
||||||
47
include/sbi_utils/serial/semihosting.h
Normal file
47
include/sbi_utils/serial/semihosting.h
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Ventana Micro Systems Inc.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Anup Patel <apatel@ventanamicro.com>
|
||||||
|
* Kautuk Consul <kconsul@ventanamicro.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SERIAL_SEMIHOSTING_H__
|
||||||
|
#define __SERIAL_SEMIHOSTING_H__
|
||||||
|
|
||||||
|
#include <sbi/sbi_types.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* enum semihosting_open_mode - Numeric file modes for use with semihosting_open()
|
||||||
|
* MODE_READ: 'r'
|
||||||
|
* MODE_BINARY: 'b'
|
||||||
|
* MODE_PLUS: '+'
|
||||||
|
* MODE_WRITE: 'w'
|
||||||
|
* MODE_APPEND: 'a'
|
||||||
|
*
|
||||||
|
* These modes represent the mode string used by fopen(3) in a form which can
|
||||||
|
* be passed to semihosting_open(). These do NOT correspond directly to %O_RDONLY,
|
||||||
|
* %O_CREAT, etc; see fopen(3) for details. In particular, @MODE_PLUS
|
||||||
|
* effectively results in adding %O_RDWR, and @MODE_WRITE will add %O_TRUNC.
|
||||||
|
* For compatibility, @MODE_BINARY should be added when opening non-text files
|
||||||
|
* (such as images).
|
||||||
|
*/
|
||||||
|
enum semihosting_open_mode {
|
||||||
|
MODE_READ = 0x0,
|
||||||
|
MODE_BINARY = 0x1,
|
||||||
|
MODE_PLUS = 0x2,
|
||||||
|
MODE_WRITE = 0x4,
|
||||||
|
MODE_APPEND = 0x8,
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef CONFIG_SERIAL_SEMIHOSTING
|
||||||
|
int semihosting_init(void);
|
||||||
|
bool semihosting_enabled(void);
|
||||||
|
#else
|
||||||
|
static inline int semihosting_init(void) { return SBI_ENODEV; }
|
||||||
|
static inline int semihosting_enabled(void) { return 0; }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -13,6 +13,6 @@
|
|||||||
#include <sbi/sbi_types.h>
|
#include <sbi/sbi_types.h>
|
||||||
|
|
||||||
int uart8250_init(unsigned long base, u32 in_freq, u32 baudrate, u32 reg_shift,
|
int uart8250_init(unsigned long base, u32 in_freq, u32 baudrate, u32 reg_shift,
|
||||||
u32 reg_width);
|
u32 reg_width, u32 reg_offset);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
16
include/sbi_utils/serial/xlnx_uartlite.h
Normal file
16
include/sbi_utils/serial/xlnx_uartlite.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Western Digital Corporation or its affiliates.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Alistair Francis <alistair.francis@wdc.com>
|
||||||
|
*/
|
||||||
|
#ifndef __SERIAL_XLNX_UARTLITE_H__
|
||||||
|
#define __SERIAL_XLNX_UARTLITE_H__
|
||||||
|
|
||||||
|
#include <sbi/sbi_types.h>
|
||||||
|
|
||||||
|
int xlnx_uartlite_init(unsigned long base);
|
||||||
|
|
||||||
|
#endif
|
||||||
59
include/sbi_utils/sys/atcsmu.h
Normal file
59
include/sbi_utils/sys/atcsmu.h
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*
|
||||||
|
* Copyright (c) 2023 Andes Technology Corporation
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SYS_ATCSMU_H
|
||||||
|
#define _SYS_ATCSMU_H
|
||||||
|
|
||||||
|
#include <sbi/sbi_types.h>
|
||||||
|
|
||||||
|
/* clang-format off */
|
||||||
|
|
||||||
|
#define PCS0_WE_OFFSET 0x90
|
||||||
|
#define PCSm_WE_OFFSET(i) ((i + 3) * 0x20 + PCS0_WE_OFFSET)
|
||||||
|
|
||||||
|
#define PCS0_CTL_OFFSET 0x94
|
||||||
|
#define PCSm_CTL_OFFSET(i) ((i + 3) * 0x20 + PCS0_CTL_OFFSET)
|
||||||
|
#define PCS_CTL_CMD_SHIFT 0
|
||||||
|
#define PCS_CTL_PARAM_SHIFT 3
|
||||||
|
#define SLEEP_CMD 0x3
|
||||||
|
#define WAKEUP_CMD (0x0 | (1 << PCS_CTL_PARAM_SHIFT))
|
||||||
|
#define LIGHTSLEEP_MODE 0
|
||||||
|
#define DEEPSLEEP_MODE 1
|
||||||
|
#define LIGHT_SLEEP_CMD (SLEEP_CMD | (LIGHTSLEEP_MODE << PCS_CTL_PARAM_SHIFT))
|
||||||
|
#define DEEP_SLEEP_CMD (SLEEP_CMD | (DEEPSLEEP_MODE << PCS_CTL_PARAM_SHIFT))
|
||||||
|
|
||||||
|
#define PCS0_CFG_OFFSET 0x80
|
||||||
|
#define PCSm_CFG_OFFSET(i) ((i + 3) * 0x20 + PCS0_CFG_OFFSET)
|
||||||
|
#define PCS_CFG_LIGHT_SLEEP_SHIFT 2
|
||||||
|
#define PCS_CFG_LIGHT_SLEEP (1 << PCS_CFG_LIGHT_SLEEP_SHIFT)
|
||||||
|
#define PCS_CFG_DEEP_SLEEP_SHIFT 3
|
||||||
|
#define PCS_CFG_DEEP_SLEEP (1 << PCS_CFG_DEEP_SLEEP_SHIFT)
|
||||||
|
|
||||||
|
#define RESET_VEC_LO_OFFSET 0x50
|
||||||
|
#define RESET_VEC_HI_OFFSET 0x60
|
||||||
|
#define RESET_VEC_8CORE_OFFSET 0x1a0
|
||||||
|
#define HARTn_RESET_VEC_LO(n) (RESET_VEC_LO_OFFSET + \
|
||||||
|
((n) < 4 ? 0 : RESET_VEC_8CORE_OFFSET) + \
|
||||||
|
((n) * 0x4))
|
||||||
|
#define HARTn_RESET_VEC_HI(n) (RESET_VEC_HI_OFFSET + \
|
||||||
|
((n) < 4 ? 0 : RESET_VEC_8CORE_OFFSET) + \
|
||||||
|
((n) * 0x4))
|
||||||
|
|
||||||
|
#define PCS_MAX_NR 8
|
||||||
|
#define FLASH_BASE 0x80000000ULL
|
||||||
|
|
||||||
|
/* clang-format on */
|
||||||
|
|
||||||
|
struct smu_data {
|
||||||
|
unsigned long addr;
|
||||||
|
};
|
||||||
|
|
||||||
|
int smu_set_wakeup_events(struct smu_data *smu, u32 events, u32 hartid);
|
||||||
|
bool smu_support_sleep_mode(struct smu_data *smu, u32 sleep_mode, u32 hartid);
|
||||||
|
int smu_set_command(struct smu_data *smu, u32 pcs_ctl, u32 hartid);
|
||||||
|
int smu_set_reset_vector(struct smu_data *smu, ulong wakeup_addr, u32 hartid);
|
||||||
|
|
||||||
|
#endif /* _SYS_ATCSMU_H */
|
||||||
@@ -10,8 +10,12 @@
|
|||||||
|
|
||||||
#include <sbi/sbi_types.h>
|
#include <sbi/sbi_types.h>
|
||||||
|
|
||||||
int htif_serial_init(void);
|
int htif_serial_init(bool custom_addr,
|
||||||
|
unsigned long custom_fromhost_addr,
|
||||||
|
unsigned long custom_tohost_addr);
|
||||||
|
|
||||||
int htif_system_reset_init(void);
|
int htif_system_reset_init(bool custom_addr,
|
||||||
|
unsigned long custom_fromhost_addr,
|
||||||
|
unsigned long custom_tohost_addr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#define CLINT_MTIMER_OFFSET 0x4000
|
#define CLINT_MTIMER_OFFSET 0x4000
|
||||||
|
|
||||||
|
#define MTIMER_REGION_ALIGN 0x1000
|
||||||
|
|
||||||
struct aclint_mtimer_data {
|
struct aclint_mtimer_data {
|
||||||
/* Public details */
|
/* Public details */
|
||||||
unsigned long mtime_freq;
|
unsigned long mtime_freq;
|
||||||
@@ -33,6 +35,7 @@ struct aclint_mtimer_data {
|
|||||||
u32 hart_count;
|
u32 hart_count;
|
||||||
bool has_64bit_mmio;
|
bool has_64bit_mmio;
|
||||||
bool has_shared_mtime;
|
bool has_shared_mtime;
|
||||||
|
bool use_extern_domain;
|
||||||
/* Private details (initialized and used by ACLINT MTIMER library) */
|
/* Private details (initialized and used by ACLINT MTIMER library) */
|
||||||
struct aclint_mtimer_data *time_delta_reference;
|
struct aclint_mtimer_data *time_delta_reference;
|
||||||
unsigned long time_delta_computed;
|
unsigned long time_delta_computed;
|
||||||
|
|||||||
29
include/sbi_utils/timer/andes_plmt.h
Normal file
29
include/sbi_utils/timer/andes_plmt.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Andes Technology Corporation
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Zong Li <zong@andestech.com>
|
||||||
|
* Nylon Chen <nylon7@andestech.com>
|
||||||
|
* Yu Chien Peter Lin <peterlin@andestech.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __TIMER_ANDES_PLMT_H__
|
||||||
|
#define __TIMER_ANDES_PLMT_H__
|
||||||
|
|
||||||
|
#define DEFAULT_AE350_PLMT_FREQ 60000000
|
||||||
|
#define PLMT_REGION_ALIGN 0x1000
|
||||||
|
|
||||||
|
struct plmt_data {
|
||||||
|
u32 hart_count;
|
||||||
|
unsigned long size;
|
||||||
|
unsigned long timer_freq;
|
||||||
|
volatile u64 *time_val;
|
||||||
|
volatile u64 *time_cmp;
|
||||||
|
};
|
||||||
|
|
||||||
|
int plmt_cold_timer_init(struct plmt_data *plmt);
|
||||||
|
int plmt_warm_timer_init(void);
|
||||||
|
|
||||||
|
#endif /* __TIMER_ANDES_PLMT_H__ */
|
||||||
@@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#include <sbi/sbi_types.h>
|
#include <sbi/sbi_types.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_FDT_TIMER
|
||||||
|
|
||||||
struct fdt_timer {
|
struct fdt_timer {
|
||||||
const struct fdt_match *match_table;
|
const struct fdt_match *match_table;
|
||||||
int (*cold_init)(void *fdt, int nodeoff, const struct fdt_match *match);
|
int (*cold_init)(void *fdt, int nodeoff, const struct fdt_match *match);
|
||||||
@@ -23,4 +25,11 @@ void fdt_timer_exit(void);
|
|||||||
|
|
||||||
int fdt_timer_init(bool cold_boot);
|
int fdt_timer_init(bool cold_boot);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
static inline void fdt_timer_exit(void) { }
|
||||||
|
static inline int fdt_timer_init(bool cold_boot) { return 0; }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
21
include/sbi_utils/timer/sg2042_gmt.h
Normal file
21
include/sbi_utils/timer/sg2042_gmt.h
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025 SOPHGO Corporation
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Chao Wei <chao.wei@sophgo.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SG2042_GMT_H__
|
||||||
|
#define __SG2042_GMT_H__
|
||||||
|
|
||||||
|
int sg2042gmt_cold_timer_init(unsigned long mtimer_base,
|
||||||
|
unsigned long mtimecmp_base,
|
||||||
|
unsigned long mtimecmp_size,
|
||||||
|
unsigned long delcared_freq,
|
||||||
|
unsigned long actual_freq,
|
||||||
|
unsigned long timecmp_freq);
|
||||||
|
int sg2042gmt_warm_timer_init(void);
|
||||||
|
|
||||||
|
#endif /* __SG2042_GMT_H__ */
|
||||||
45
lib/sbi/Kconfig
Normal file
45
lib/sbi/Kconfig
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
# SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
|
||||||
|
menu "SBI Extension Support"
|
||||||
|
|
||||||
|
config SBI_ECALL_TIME
|
||||||
|
bool "Timer extension"
|
||||||
|
default y
|
||||||
|
|
||||||
|
config SBI_ECALL_RFENCE
|
||||||
|
bool "RFENCE extension"
|
||||||
|
default y
|
||||||
|
|
||||||
|
config SBI_ECALL_IPI
|
||||||
|
bool "IPI extension"
|
||||||
|
default y
|
||||||
|
|
||||||
|
config SBI_ECALL_HSM
|
||||||
|
bool "Hart State Management extension"
|
||||||
|
default y
|
||||||
|
|
||||||
|
config SBI_ECALL_SRST
|
||||||
|
bool "System Reset extension"
|
||||||
|
default y
|
||||||
|
|
||||||
|
config SBI_ECALL_SUSP
|
||||||
|
bool "System Suspend extension"
|
||||||
|
default y
|
||||||
|
|
||||||
|
config SBI_ECALL_PMU
|
||||||
|
bool "Performance Monitoring Unit extension"
|
||||||
|
default y
|
||||||
|
|
||||||
|
config SBI_ECALL_DBCN
|
||||||
|
bool "Debug Console extension"
|
||||||
|
default y
|
||||||
|
|
||||||
|
config SBI_ECALL_LEGACY
|
||||||
|
bool "SBI v0.1 legacy extensions"
|
||||||
|
default y
|
||||||
|
|
||||||
|
config SBI_ECALL_VENDOR
|
||||||
|
bool "Platform-defined vendor extensions"
|
||||||
|
default y
|
||||||
|
|
||||||
|
endmenu
|
||||||
@@ -12,17 +12,47 @@ libsbi-objs-y += riscv_atomic.o
|
|||||||
libsbi-objs-y += riscv_hardfp.o
|
libsbi-objs-y += riscv_hardfp.o
|
||||||
libsbi-objs-y += riscv_locks.o
|
libsbi-objs-y += riscv_locks.o
|
||||||
|
|
||||||
|
libsbi-objs-y += sbi_ecall.o
|
||||||
|
libsbi-objs-y += sbi_ecall_exts.o
|
||||||
|
|
||||||
|
# The order of below extensions is performance optimized
|
||||||
|
carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_TIME) += ecall_time
|
||||||
|
libsbi-objs-$(CONFIG_SBI_ECALL_TIME) += sbi_ecall_time.o
|
||||||
|
|
||||||
|
carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_RFENCE) += ecall_rfence
|
||||||
|
libsbi-objs-$(CONFIG_SBI_ECALL_RFENCE) += sbi_ecall_rfence.o
|
||||||
|
|
||||||
|
carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_IPI) += ecall_ipi
|
||||||
|
libsbi-objs-$(CONFIG_SBI_ECALL_IPI) += sbi_ecall_ipi.o
|
||||||
|
|
||||||
|
carray-sbi_ecall_exts-y += ecall_base
|
||||||
|
libsbi-objs-y += sbi_ecall_base.o
|
||||||
|
|
||||||
|
carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_HSM) += ecall_hsm
|
||||||
|
libsbi-objs-$(CONFIG_SBI_ECALL_HSM) += sbi_ecall_hsm.o
|
||||||
|
|
||||||
|
carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_SRST) += ecall_srst
|
||||||
|
libsbi-objs-$(CONFIG_SBI_ECALL_SRST) += sbi_ecall_srst.o
|
||||||
|
|
||||||
|
carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_SUSP) += ecall_susp
|
||||||
|
libsbi-objs-$(CONFIG_SBI_ECALL_SUSP) += sbi_ecall_susp.o
|
||||||
|
|
||||||
|
carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_PMU) += ecall_pmu
|
||||||
|
libsbi-objs-$(CONFIG_SBI_ECALL_PMU) += sbi_ecall_pmu.o
|
||||||
|
|
||||||
|
carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_DBCN) += ecall_dbcn
|
||||||
|
libsbi-objs-$(CONFIG_SBI_ECALL_DBCN) += sbi_ecall_dbcn.o
|
||||||
|
|
||||||
|
carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_LEGACY) += ecall_legacy
|
||||||
|
libsbi-objs-$(CONFIG_SBI_ECALL_LEGACY) += sbi_ecall_legacy.o
|
||||||
|
|
||||||
|
carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_VENDOR) += ecall_vendor
|
||||||
|
libsbi-objs-$(CONFIG_SBI_ECALL_VENDOR) += sbi_ecall_vendor.o
|
||||||
|
|
||||||
libsbi-objs-y += sbi_bitmap.o
|
libsbi-objs-y += sbi_bitmap.o
|
||||||
libsbi-objs-y += sbi_bitops.o
|
libsbi-objs-y += sbi_bitops.o
|
||||||
libsbi-objs-y += sbi_console.o
|
libsbi-objs-y += sbi_console.o
|
||||||
libsbi-objs-y += sbi_domain.o
|
libsbi-objs-y += sbi_domain.o
|
||||||
libsbi-objs-y += sbi_ecall.o
|
|
||||||
libsbi-objs-y += sbi_ecall_base.o
|
|
||||||
libsbi-objs-y += sbi_ecall_hsm.o
|
|
||||||
libsbi-objs-y += sbi_ecall_legacy.o
|
|
||||||
libsbi-objs-y += sbi_ecall_pmu.o
|
|
||||||
libsbi-objs-y += sbi_ecall_replace.o
|
|
||||||
libsbi-objs-y += sbi_ecall_vendor.o
|
|
||||||
libsbi-objs-y += sbi_emulate_csr.o
|
libsbi-objs-y += sbi_emulate_csr.o
|
||||||
libsbi-objs-y += sbi_fifo.o
|
libsbi-objs-y += sbi_fifo.o
|
||||||
libsbi-objs-y += sbi_hart.o
|
libsbi-objs-y += sbi_hart.o
|
||||||
@@ -32,6 +62,7 @@ libsbi-objs-y += sbi_hsm.o
|
|||||||
libsbi-objs-y += sbi_illegal_insn.o
|
libsbi-objs-y += sbi_illegal_insn.o
|
||||||
libsbi-objs-y += sbi_init.o
|
libsbi-objs-y += sbi_init.o
|
||||||
libsbi-objs-y += sbi_ipi.o
|
libsbi-objs-y += sbi_ipi.o
|
||||||
|
libsbi-objs-y += sbi_irqchip.o
|
||||||
libsbi-objs-y += sbi_misaligned_ldst.o
|
libsbi-objs-y += sbi_misaligned_ldst.o
|
||||||
libsbi-objs-y += sbi_platform.o
|
libsbi-objs-y += sbi_platform.o
|
||||||
libsbi-objs-y += sbi_pmu.o
|
libsbi-objs-y += sbi_pmu.o
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ int misa_xlen(void)
|
|||||||
void misa_string(int xlen, char *out, unsigned int out_sz)
|
void misa_string(int xlen, char *out, unsigned int out_sz)
|
||||||
{
|
{
|
||||||
unsigned int i, pos = 0;
|
unsigned int i, pos = 0;
|
||||||
const char valid_isa_order[] = "iemafdqclbjtpvnsuhkorwxyzg";
|
const char valid_isa_order[] = "iemafdqclbjtpvnhkorwxyzg";
|
||||||
|
|
||||||
if (!out)
|
if (!out)
|
||||||
return;
|
return;
|
||||||
@@ -139,6 +139,10 @@ unsigned long csr_read_num(int csr_num)
|
|||||||
switchcase_csr_read_4(CSR_MHPMCOUNTER4H, ret)
|
switchcase_csr_read_4(CSR_MHPMCOUNTER4H, ret)
|
||||||
switchcase_csr_read_8(CSR_MHPMCOUNTER8H, ret)
|
switchcase_csr_read_8(CSR_MHPMCOUNTER8H, ret)
|
||||||
switchcase_csr_read_16(CSR_MHPMCOUNTER16H, ret)
|
switchcase_csr_read_16(CSR_MHPMCOUNTER16H, ret)
|
||||||
|
/**
|
||||||
|
* The CSR range MHPMEVENT[3-16]H are available only if sscofpmf
|
||||||
|
* extension is present. The caller must ensure that.
|
||||||
|
*/
|
||||||
switchcase_csr_read(CSR_MHPMEVENT3H, ret)
|
switchcase_csr_read(CSR_MHPMEVENT3H, ret)
|
||||||
switchcase_csr_read_4(CSR_MHPMEVENT4H, ret)
|
switchcase_csr_read_4(CSR_MHPMEVENT4H, ret)
|
||||||
switchcase_csr_read_8(CSR_MHPMEVENT8H, ret)
|
switchcase_csr_read_8(CSR_MHPMEVENT8H, ret)
|
||||||
@@ -261,7 +265,7 @@ int pmp_set(unsigned int n, unsigned long prot, unsigned long addr,
|
|||||||
pmpcfg_csr = (CSR_PMPCFG0 + (n >> 2)) & ~1;
|
pmpcfg_csr = (CSR_PMPCFG0 + (n >> 2)) & ~1;
|
||||||
pmpcfg_shift = (n & 7) << 3;
|
pmpcfg_shift = (n & 7) << 3;
|
||||||
#else
|
#else
|
||||||
return SBI_ENOTSUPP;
|
# error "Unexpected __riscv_xlen"
|
||||||
#endif
|
#endif
|
||||||
pmpaddr_csr = CSR_PMPADDR0 + n;
|
pmpaddr_csr = CSR_PMPADDR0 + n;
|
||||||
|
|
||||||
@@ -312,7 +316,7 @@ int pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out,
|
|||||||
pmpcfg_csr = (CSR_PMPCFG0 + (n >> 2)) & ~1;
|
pmpcfg_csr = (CSR_PMPCFG0 + (n >> 2)) & ~1;
|
||||||
pmpcfg_shift = (n & 7) << 3;
|
pmpcfg_shift = (n & 7) << 3;
|
||||||
#else
|
#else
|
||||||
return SBI_ENOTSUPP;
|
# error "Unexpected __riscv_xlen"
|
||||||
#endif
|
#endif
|
||||||
pmpaddr_csr = CSR_PMPADDR0 + n;
|
pmpaddr_csr = CSR_PMPADDR0 + n;
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ unsigned long find_first_bit(const unsigned long *addr,
|
|||||||
if (tmp == 0UL) /* Are any bits set? */
|
if (tmp == 0UL) /* Are any bits set? */
|
||||||
return result + size; /* Nope. */
|
return result + size; /* Nope. */
|
||||||
found:
|
found:
|
||||||
return result + __ffs(tmp);
|
return result + sbi_ffs(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,7 +69,7 @@ unsigned long find_first_zero_bit(const unsigned long *addr,
|
|||||||
if (tmp == ~0UL) /* Are any bits zero? */
|
if (tmp == ~0UL) /* Are any bits zero? */
|
||||||
return result + size; /* Nope. */
|
return result + size; /* Nope. */
|
||||||
found:
|
found:
|
||||||
return result + ffz(tmp);
|
return result + sbi_ffz(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -100,7 +100,7 @@ unsigned long find_last_bit(const unsigned long *addr,
|
|||||||
tmp = addr[--words];
|
tmp = addr[--words];
|
||||||
if (tmp) {
|
if (tmp) {
|
||||||
found:
|
found:
|
||||||
return words * BITS_PER_LONG + __fls(tmp);
|
return words * BITS_PER_LONG + sbi_fls(tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ found_first:
|
|||||||
if (tmp == 0UL) /* Are any bits set? */
|
if (tmp == 0UL) /* Are any bits set? */
|
||||||
return result + size; /* Nope. */
|
return result + size; /* Nope. */
|
||||||
found_middle:
|
found_middle:
|
||||||
return result + __ffs(tmp);
|
return result + sbi_ffs(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -196,5 +196,5 @@ found_first:
|
|||||||
if (tmp == ~0UL) /* Are any bits zero? */
|
if (tmp == ~0UL) /* Are any bits zero? */
|
||||||
return result + size; /* Nope. */
|
return result + size; /* Nope. */
|
||||||
found_middle:
|
found_middle:
|
||||||
return result + ffz(tmp);
|
return result + sbi_ffz(tmp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,17 +12,22 @@
|
|||||||
#include <sbi/sbi_hart.h>
|
#include <sbi/sbi_hart.h>
|
||||||
#include <sbi/sbi_platform.h>
|
#include <sbi/sbi_platform.h>
|
||||||
#include <sbi/sbi_scratch.h>
|
#include <sbi/sbi_scratch.h>
|
||||||
|
#include <sbi/sbi_string.h>
|
||||||
|
|
||||||
|
#define CONSOLE_TBUF_MAX 256
|
||||||
|
|
||||||
static const struct sbi_console_device *console_dev = NULL;
|
static const struct sbi_console_device *console_dev = NULL;
|
||||||
|
static char console_tbuf[CONSOLE_TBUF_MAX];
|
||||||
|
static u32 console_tbuf_len;
|
||||||
static spinlock_t console_out_lock = SPIN_LOCK_INITIALIZER;
|
static spinlock_t console_out_lock = SPIN_LOCK_INITIALIZER;
|
||||||
|
|
||||||
bool sbi_isprintable(char c)
|
bool sbi_isprintable(char c)
|
||||||
{
|
{
|
||||||
if (((31 < c) && (c < 127)) || (c == '\f') || (c == '\r') ||
|
if (((31 < c) && (c < 127)) || (c == '\f') || (c == '\r') ||
|
||||||
(c == '\n') || (c == '\t')) {
|
(c == '\n') || (c == '\t')) {
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sbi_getc(void)
|
int sbi_getc(void)
|
||||||
@@ -41,16 +46,49 @@ void sbi_putc(char ch)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unsigned long nputs(const char *str, unsigned long len)
|
||||||
|
{
|
||||||
|
unsigned long i, ret;
|
||||||
|
|
||||||
|
if (console_dev && console_dev->console_puts) {
|
||||||
|
ret = console_dev->console_puts(str, len);
|
||||||
|
} else {
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
sbi_putc(str[i]);
|
||||||
|
ret = len;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void nputs_all(const char *str, unsigned long len)
|
||||||
|
{
|
||||||
|
unsigned long p = 0;
|
||||||
|
|
||||||
|
while (p < len)
|
||||||
|
p += nputs(&str[p], len - p);
|
||||||
|
}
|
||||||
|
|
||||||
void sbi_puts(const char *str)
|
void sbi_puts(const char *str)
|
||||||
{
|
{
|
||||||
|
unsigned long len = sbi_strlen(str);
|
||||||
|
|
||||||
spin_lock(&console_out_lock);
|
spin_lock(&console_out_lock);
|
||||||
while (*str) {
|
nputs_all(str, len);
|
||||||
sbi_putc(*str);
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
spin_unlock(&console_out_lock);
|
spin_unlock(&console_out_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long sbi_nputs(const char *str, unsigned long len)
|
||||||
|
{
|
||||||
|
unsigned long ret;
|
||||||
|
|
||||||
|
spin_lock(&console_out_lock);
|
||||||
|
ret = nputs(str, len);
|
||||||
|
spin_unlock(&console_out_lock);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void sbi_gets(char *s, int maxwidth, char endchar)
|
void sbi_gets(char *s, int maxwidth, char endchar)
|
||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
@@ -64,6 +102,21 @@ void sbi_gets(char *s, int maxwidth, char endchar)
|
|||||||
*retval = '\0';
|
*retval = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long sbi_ngets(char *str, unsigned long len)
|
||||||
|
{
|
||||||
|
int ch;
|
||||||
|
unsigned long i;
|
||||||
|
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
ch = sbi_getc();
|
||||||
|
if (ch < 0)
|
||||||
|
break;
|
||||||
|
str[i] = ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
#define PAD_RIGHT 1
|
#define PAD_RIGHT 1
|
||||||
#define PAD_ZERO 2
|
#define PAD_ZERO 2
|
||||||
#define PAD_ALTERNATE 4
|
#define PAD_ALTERNATE 4
|
||||||
@@ -76,20 +129,22 @@ typedef __builtin_va_list va_list;
|
|||||||
|
|
||||||
static void printc(char **out, u32 *out_len, char ch)
|
static void printc(char **out, u32 *out_len, char ch)
|
||||||
{
|
{
|
||||||
if (out) {
|
if (!out) {
|
||||||
if (*out) {
|
|
||||||
if (out_len && (0 < *out_len)) {
|
|
||||||
**out = ch;
|
|
||||||
++(*out);
|
|
||||||
(*out_len)--;
|
|
||||||
} else {
|
|
||||||
**out = ch;
|
|
||||||
++(*out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sbi_putc(ch);
|
sbi_putc(ch);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The *printf entry point functions have enforced that (*out) can
|
||||||
|
* only be null when out_len is non-null and its value is zero.
|
||||||
|
*/
|
||||||
|
if (!out_len || *out_len > 1) {
|
||||||
|
*(*out)++ = ch;
|
||||||
|
**out = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (out_len && *out_len > 0)
|
||||||
|
--(*out_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int prints(char **out, u32 *out_len, const char *string, int width,
|
static int prints(char **out, u32 *out_len, const char *string, int width,
|
||||||
@@ -181,19 +236,37 @@ static int printi(char **out, u32 *out_len, long long i, int b, int sg,
|
|||||||
|
|
||||||
static int print(char **out, u32 *out_len, const char *format, va_list args)
|
static int print(char **out, u32 *out_len, const char *format, va_list args)
|
||||||
{
|
{
|
||||||
int width, flags, acnt = 0;
|
int width, flags, pc = 0;
|
||||||
int pc = 0;
|
char scr[2], *tout;
|
||||||
char scr[2];
|
bool use_tbuf = (!out) ? true : false;
|
||||||
unsigned long long tmp;
|
unsigned long long tmp;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The console_tbuf is protected by console_out_lock and
|
||||||
|
* print() is always called with console_out_lock held
|
||||||
|
* when out == NULL.
|
||||||
|
*/
|
||||||
|
if (use_tbuf) {
|
||||||
|
console_tbuf_len = CONSOLE_TBUF_MAX;
|
||||||
|
tout = console_tbuf;
|
||||||
|
out = &tout;
|
||||||
|
out_len = &console_tbuf_len;
|
||||||
|
}
|
||||||
|
|
||||||
for (; *format != 0; ++format) {
|
for (; *format != 0; ++format) {
|
||||||
|
if (use_tbuf && !console_tbuf_len) {
|
||||||
|
nputs_all(console_tbuf, CONSOLE_TBUF_MAX);
|
||||||
|
console_tbuf_len = CONSOLE_TBUF_MAX;
|
||||||
|
tout = console_tbuf;
|
||||||
|
}
|
||||||
|
|
||||||
if (*format == '%') {
|
if (*format == '%') {
|
||||||
++format;
|
++format;
|
||||||
width = flags = 0;
|
width = flags = 0;
|
||||||
if (*format == '\0')
|
if (*format == '\0')
|
||||||
break;
|
break;
|
||||||
if (*format == '%')
|
if (*format == '%')
|
||||||
goto out;
|
goto literal;
|
||||||
/* Get flags */
|
/* Get flags */
|
||||||
if (*format == '-') {
|
if (*format == '-') {
|
||||||
++format;
|
++format;
|
||||||
@@ -214,7 +287,6 @@ static int print(char **out, u32 *out_len, const char *format, va_list args)
|
|||||||
}
|
}
|
||||||
if (*format == 's') {
|
if (*format == 's') {
|
||||||
char *s = va_arg(args, char *);
|
char *s = va_arg(args, char *);
|
||||||
acnt += sizeof(char *);
|
|
||||||
pc += prints(out, out_len, s ? s : "(null)",
|
pc += prints(out, out_len, s ? s : "(null)",
|
||||||
width, flags);
|
width, flags);
|
||||||
continue;
|
continue;
|
||||||
@@ -222,61 +294,40 @@ static int print(char **out, u32 *out_len, const char *format, va_list args)
|
|||||||
if ((*format == 'd') || (*format == 'i')) {
|
if ((*format == 'd') || (*format == 'i')) {
|
||||||
pc += printi(out, out_len, va_arg(args, int),
|
pc += printi(out, out_len, va_arg(args, int),
|
||||||
10, 1, width, flags, '0');
|
10, 1, width, flags, '0');
|
||||||
acnt += sizeof(int);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (*format == 'x') {
|
if (*format == 'x') {
|
||||||
pc += printi(out, out_len,
|
pc += printi(out, out_len,
|
||||||
va_arg(args, unsigned int), 16, 0,
|
va_arg(args, unsigned int), 16, 0,
|
||||||
width, flags, 'a');
|
width, flags, 'a');
|
||||||
acnt += sizeof(unsigned int);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (*format == 'X') {
|
if (*format == 'X') {
|
||||||
pc += printi(out, out_len,
|
pc += printi(out, out_len,
|
||||||
va_arg(args, unsigned int), 16, 0,
|
va_arg(args, unsigned int), 16, 0,
|
||||||
width, flags, 'A');
|
width, flags, 'A');
|
||||||
acnt += sizeof(unsigned int);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (*format == 'u') {
|
if (*format == 'u') {
|
||||||
pc += printi(out, out_len,
|
pc += printi(out, out_len,
|
||||||
va_arg(args, unsigned int), 10, 0,
|
va_arg(args, unsigned int), 10, 0,
|
||||||
width, flags, 'a');
|
width, flags, 'a');
|
||||||
acnt += sizeof(unsigned int);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (*format == 'p') {
|
if (*format == 'p') {
|
||||||
pc += printi(out, out_len,
|
pc += printi(out, out_len,
|
||||||
va_arg(args, unsigned long), 16, 0,
|
va_arg(args, unsigned long), 16, 0,
|
||||||
width, flags, 'a');
|
width, flags, 'a');
|
||||||
acnt += sizeof(unsigned long);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (*format == 'P') {
|
if (*format == 'P') {
|
||||||
pc += printi(out, out_len,
|
pc += printi(out, out_len,
|
||||||
va_arg(args, unsigned long), 16, 0,
|
va_arg(args, unsigned long), 16, 0,
|
||||||
width, flags, 'A');
|
width, flags, 'A');
|
||||||
acnt += sizeof(unsigned long);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (*format == 'l' && *(format + 1) == 'l') {
|
if (*format == 'l' && *(format + 1) == 'l') {
|
||||||
while (acnt &
|
tmp = va_arg(args, unsigned long long);
|
||||||
(sizeof(unsigned long long) - 1)) {
|
|
||||||
va_arg(args, int);
|
|
||||||
acnt += sizeof(int);
|
|
||||||
}
|
|
||||||
if (sizeof(unsigned long long) ==
|
|
||||||
sizeof(unsigned long)) {
|
|
||||||
tmp = va_arg(args, unsigned long long);
|
|
||||||
acnt += sizeof(unsigned long long);
|
|
||||||
} else {
|
|
||||||
((unsigned long *)&tmp)[0] =
|
|
||||||
va_arg(args, unsigned long);
|
|
||||||
((unsigned long *)&tmp)[1] =
|
|
||||||
va_arg(args, unsigned long);
|
|
||||||
acnt += 2 * sizeof(unsigned long);
|
|
||||||
}
|
|
||||||
if (*(format + 2) == 'u') {
|
if (*(format + 2) == 'u') {
|
||||||
format += 2;
|
format += 2;
|
||||||
pc += printi(out, out_len, tmp, 10, 0,
|
pc += printi(out, out_len, tmp, 10, 0,
|
||||||
@@ -308,19 +359,16 @@ static int print(char **out, u32 *out_len, const char *format, va_list args)
|
|||||||
out, out_len,
|
out, out_len,
|
||||||
va_arg(args, unsigned long), 16,
|
va_arg(args, unsigned long), 16,
|
||||||
0, width, flags, 'a');
|
0, width, flags, 'a');
|
||||||
acnt += sizeof(unsigned long);
|
|
||||||
} else if (*(format + 1) == 'X') {
|
} else if (*(format + 1) == 'X') {
|
||||||
format += 1;
|
format += 1;
|
||||||
pc += printi(
|
pc += printi(
|
||||||
out, out_len,
|
out, out_len,
|
||||||
va_arg(args, unsigned long), 16,
|
va_arg(args, unsigned long), 16,
|
||||||
0, width, flags, 'A');
|
0, width, flags, 'A');
|
||||||
acnt += sizeof(unsigned long);
|
|
||||||
} else {
|
} else {
|
||||||
pc += printi(out, out_len,
|
pc += printi(out, out_len,
|
||||||
va_arg(args, long), 10, 1,
|
va_arg(args, long), 10, 1,
|
||||||
width, flags, '0');
|
width, flags, '0');
|
||||||
acnt += sizeof(long);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*format == 'c') {
|
if (*format == 'c') {
|
||||||
@@ -328,17 +376,17 @@ static int print(char **out, u32 *out_len, const char *format, va_list args)
|
|||||||
scr[0] = va_arg(args, int);
|
scr[0] = va_arg(args, int);
|
||||||
scr[1] = '\0';
|
scr[1] = '\0';
|
||||||
pc += prints(out, out_len, scr, width, flags);
|
pc += prints(out, out_len, scr, width, flags);
|
||||||
acnt += sizeof(int);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
out:
|
literal:
|
||||||
printc(out, out_len, *format);
|
printc(out, out_len, *format);
|
||||||
++pc;
|
++pc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (out)
|
|
||||||
**out = '\0';
|
if (use_tbuf && console_tbuf_len < CONSOLE_TBUF_MAX)
|
||||||
|
nputs_all(console_tbuf, CONSOLE_TBUF_MAX - console_tbuf_len);
|
||||||
|
|
||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
@@ -348,6 +396,9 @@ int sbi_sprintf(char *out, const char *format, ...)
|
|||||||
va_list args;
|
va_list args;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
|
if (unlikely(!out))
|
||||||
|
sbi_panic("sbi_sprintf called with NULL output string\n");
|
||||||
|
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
retval = print(&out, NULL, format, args);
|
retval = print(&out, NULL, format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
@@ -360,6 +411,10 @@ int sbi_snprintf(char *out, u32 out_sz, const char *format, ...)
|
|||||||
va_list args;
|
va_list args;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
|
if (unlikely(!out && out_sz != 0))
|
||||||
|
sbi_panic("sbi_snprintf called with NULL output string and "
|
||||||
|
"output size is not zero\n");
|
||||||
|
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
retval = print(&out, &out_sz, format, args);
|
retval = print(&out, &out_sz, format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|||||||
@@ -17,8 +17,12 @@
|
|||||||
#include <sbi/sbi_scratch.h>
|
#include <sbi/sbi_scratch.h>
|
||||||
#include <sbi/sbi_string.h>
|
#include <sbi/sbi_string.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We allocate an extra element because sbi_domain_for_each() expects
|
||||||
|
* the array to be null-terminated.
|
||||||
|
*/
|
||||||
|
struct sbi_domain *domidx_to_domain_table[SBI_DOMAIN_MAX_INDEX + 1] = { 0 };
|
||||||
struct sbi_domain *hartid_to_domain_table[SBI_HARTMASK_MAX_BITS] = { 0 };
|
struct sbi_domain *hartid_to_domain_table[SBI_HARTMASK_MAX_BITS] = { 0 };
|
||||||
struct sbi_domain *domidx_to_domain_table[SBI_DOMAIN_MAX_INDEX] = { 0 };
|
|
||||||
static u32 domain_count = 0;
|
static u32 domain_count = 0;
|
||||||
static bool domain_finalized = false;
|
static bool domain_finalized = false;
|
||||||
|
|
||||||
@@ -33,7 +37,8 @@ struct sbi_domain root = {
|
|||||||
.name = "root",
|
.name = "root",
|
||||||
.possible_harts = &root_hmask,
|
.possible_harts = &root_hmask,
|
||||||
.regions = root_memregs,
|
.regions = root_memregs,
|
||||||
.system_reset_allowed = TRUE,
|
.system_reset_allowed = true,
|
||||||
|
.system_suspend_allowed = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartid)
|
bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartid)
|
||||||
@@ -41,7 +46,7 @@ bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartid)
|
|||||||
if (dom)
|
if (dom)
|
||||||
return sbi_hartmask_test_hart(hartid, &dom->assigned_harts);
|
return sbi_hartmask_test_hart(hartid, &dom->assigned_harts);
|
||||||
|
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ulong sbi_domain_get_assigned_hartmask(const struct sbi_domain *dom,
|
ulong sbi_domain_get_assigned_hartmask(const struct sbi_domain *dom,
|
||||||
@@ -105,51 +110,64 @@ bool sbi_domain_check_addr(const struct sbi_domain *dom,
|
|||||||
unsigned long addr, unsigned long mode,
|
unsigned long addr, unsigned long mode,
|
||||||
unsigned long access_flags)
|
unsigned long access_flags)
|
||||||
{
|
{
|
||||||
bool mmio = FALSE;
|
bool rmmio, mmio = false;
|
||||||
struct sbi_domain_memregion *reg;
|
struct sbi_domain_memregion *reg;
|
||||||
unsigned long rstart, rend, rflags, rwx = 0;
|
unsigned long rstart, rend, rflags, rwx = 0, rrwx = 0;
|
||||||
|
|
||||||
if (!dom)
|
if (!dom)
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Use M_{R/W/X} bits because the SU-bits are at the
|
||||||
|
* same relative offsets. If the mode is not M, the SU
|
||||||
|
* bits will fall at same offsets after the shift.
|
||||||
|
*/
|
||||||
if (access_flags & SBI_DOMAIN_READ)
|
if (access_flags & SBI_DOMAIN_READ)
|
||||||
rwx |= SBI_DOMAIN_MEMREGION_READABLE;
|
rwx |= SBI_DOMAIN_MEMREGION_M_READABLE;
|
||||||
|
|
||||||
if (access_flags & SBI_DOMAIN_WRITE)
|
if (access_flags & SBI_DOMAIN_WRITE)
|
||||||
rwx |= SBI_DOMAIN_MEMREGION_WRITEABLE;
|
rwx |= SBI_DOMAIN_MEMREGION_M_WRITABLE;
|
||||||
|
|
||||||
if (access_flags & SBI_DOMAIN_EXECUTE)
|
if (access_flags & SBI_DOMAIN_EXECUTE)
|
||||||
rwx |= SBI_DOMAIN_MEMREGION_EXECUTABLE;
|
rwx |= SBI_DOMAIN_MEMREGION_M_EXECUTABLE;
|
||||||
|
|
||||||
if (access_flags & SBI_DOMAIN_MMIO)
|
if (access_flags & SBI_DOMAIN_MMIO)
|
||||||
mmio = TRUE;
|
mmio = true;
|
||||||
|
|
||||||
sbi_domain_for_each_memregion(dom, reg) {
|
sbi_domain_for_each_memregion(dom, reg) {
|
||||||
rflags = reg->flags;
|
rflags = reg->flags;
|
||||||
if (mode == PRV_M && !(rflags & SBI_DOMAIN_MEMREGION_MMODE))
|
rrwx = (mode == PRV_M ?
|
||||||
continue;
|
(rflags & SBI_DOMAIN_MEMREGION_M_ACCESS_MASK) :
|
||||||
|
(rflags & SBI_DOMAIN_MEMREGION_SU_ACCESS_MASK)
|
||||||
|
>> SBI_DOMAIN_MEMREGION_SU_ACCESS_SHIFT);
|
||||||
|
|
||||||
rstart = reg->base;
|
rstart = reg->base;
|
||||||
rend = (reg->order < __riscv_xlen) ?
|
rend = (reg->order < __riscv_xlen) ?
|
||||||
rstart + ((1UL << reg->order) - 1) : -1UL;
|
rstart + ((1UL << reg->order) - 1) : -1UL;
|
||||||
if (rstart <= addr && addr <= rend) {
|
if (rstart <= addr && addr <= rend) {
|
||||||
if ((mmio && !(rflags & SBI_DOMAIN_MEMREGION_MMIO)) ||
|
rmmio = (rflags & SBI_DOMAIN_MEMREGION_MMIO) ? true : false;
|
||||||
(!mmio && (rflags & SBI_DOMAIN_MEMREGION_MMIO)))
|
if (mmio != rmmio)
|
||||||
return FALSE;
|
return false;
|
||||||
return ((rflags & rwx) == rwx) ? TRUE : FALSE;
|
return ((rrwx & rwx) == rwx) ? true : false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (mode == PRV_M) ? TRUE : FALSE;
|
return (mode == PRV_M) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if region complies with constraints */
|
/* Check if region complies with constraints */
|
||||||
static bool is_region_valid(const struct sbi_domain_memregion *reg)
|
static bool is_region_valid(const struct sbi_domain_memregion *reg)
|
||||||
{
|
{
|
||||||
if (reg->order < 3 || __riscv_xlen < reg->order)
|
if (reg->order < 3 || __riscv_xlen < reg->order)
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
if (reg->base & (BIT(reg->order) - 1))
|
if (reg->order == __riscv_xlen && reg->base != 0)
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
return TRUE;
|
if (reg->order < __riscv_xlen && (reg->base & (BIT(reg->order) - 1)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if regionA is sub-region of regionB */
|
/** Check if regionA is sub-region of regionB */
|
||||||
@@ -159,15 +177,15 @@ static bool is_region_subset(const struct sbi_domain_memregion *regA,
|
|||||||
ulong regA_start = regA->base;
|
ulong regA_start = regA->base;
|
||||||
ulong regA_end = regA->base + (BIT(regA->order) - 1);
|
ulong regA_end = regA->base + (BIT(regA->order) - 1);
|
||||||
ulong regB_start = regB->base;
|
ulong regB_start = regB->base;
|
||||||
ulong regB_end = regB->base + (BIT(regA->order) - 1);
|
ulong regB_end = regB->base + (BIT(regB->order) - 1);
|
||||||
|
|
||||||
if ((regB_start <= regA_start) &&
|
if ((regB_start <= regA_start) &&
|
||||||
(regA_start < regB_end) &&
|
(regA_start < regB_end) &&
|
||||||
(regB_start < regA_end) &&
|
(regB_start < regA_end) &&
|
||||||
(regA_end <= regB_end))
|
(regA_end <= regB_end))
|
||||||
return TRUE;
|
return true;
|
||||||
|
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if regionA conflicts regionB */
|
/** Check if regionA conflicts regionB */
|
||||||
@@ -176,9 +194,9 @@ static bool is_region_conflict(const struct sbi_domain_memregion *regA,
|
|||||||
{
|
{
|
||||||
if ((is_region_subset(regA, regB) || is_region_subset(regB, regA)) &&
|
if ((is_region_subset(regA, regB) || is_region_subset(regB, regA)) &&
|
||||||
regA->flags == regB->flags)
|
regA->flags == regB->flags)
|
||||||
return TRUE;
|
return true;
|
||||||
|
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if regionA should be placed before regionB */
|
/** Check if regionA should be placed before regionB */
|
||||||
@@ -186,13 +204,51 @@ static bool is_region_before(const struct sbi_domain_memregion *regA,
|
|||||||
const struct sbi_domain_memregion *regB)
|
const struct sbi_domain_memregion *regB)
|
||||||
{
|
{
|
||||||
if (regA->order < regB->order)
|
if (regA->order < regB->order)
|
||||||
return TRUE;
|
return true;
|
||||||
|
|
||||||
if ((regA->order == regB->order) &&
|
if ((regA->order == regB->order) &&
|
||||||
(regA->base < regB->base))
|
(regA->base < regB->base))
|
||||||
return TRUE;
|
return true;
|
||||||
|
|
||||||
return FALSE;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct sbi_domain_memregion *find_region(
|
||||||
|
const struct sbi_domain *dom,
|
||||||
|
unsigned long addr)
|
||||||
|
{
|
||||||
|
unsigned long rstart, rend;
|
||||||
|
struct sbi_domain_memregion *reg;
|
||||||
|
|
||||||
|
sbi_domain_for_each_memregion(dom, reg) {
|
||||||
|
rstart = reg->base;
|
||||||
|
rend = (reg->order < __riscv_xlen) ?
|
||||||
|
rstart + ((1UL << reg->order) - 1) : -1UL;
|
||||||
|
if (rstart <= addr && addr <= rend)
|
||||||
|
return reg;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct sbi_domain_memregion *find_next_subset_region(
|
||||||
|
const struct sbi_domain *dom,
|
||||||
|
const struct sbi_domain_memregion *reg,
|
||||||
|
unsigned long addr)
|
||||||
|
{
|
||||||
|
struct sbi_domain_memregion *sreg, *ret = NULL;
|
||||||
|
|
||||||
|
sbi_domain_for_each_memregion(dom, sreg) {
|
||||||
|
if (sreg == reg || (sreg->base <= addr) ||
|
||||||
|
!is_region_subset(sreg, reg))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!ret || (sreg->base < ret->base) ||
|
||||||
|
((sreg->base == ret->base) && (sreg->order < ret->order)))
|
||||||
|
ret = sreg;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sanitize_domain(const struct sbi_platform *plat,
|
static int sanitize_domain(const struct sbi_platform *plat,
|
||||||
@@ -234,12 +290,12 @@ static int sanitize_domain(const struct sbi_platform *plat,
|
|||||||
|
|
||||||
/* Count memory regions and check presence of firmware region */
|
/* Count memory regions and check presence of firmware region */
|
||||||
count = 0;
|
count = 0;
|
||||||
have_fw_reg = FALSE;
|
have_fw_reg = false;
|
||||||
sbi_domain_for_each_memregion(dom, reg) {
|
sbi_domain_for_each_memregion(dom, reg) {
|
||||||
if (reg->order == root_fw_region.order &&
|
if (reg->order == root_fw_region.order &&
|
||||||
reg->base == root_fw_region.base &&
|
reg->base == root_fw_region.base &&
|
||||||
reg->flags == root_fw_region.flags)
|
reg->flags == root_fw_region.flags)
|
||||||
have_fw_reg = TRUE;
|
have_fw_reg = true;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
if (!have_fw_reg) {
|
if (!have_fw_reg) {
|
||||||
@@ -282,7 +338,7 @@ static int sanitize_domain(const struct sbi_platform *plat,
|
|||||||
/*
|
/*
|
||||||
* Check next mode
|
* Check next mode
|
||||||
*
|
*
|
||||||
* We only allow next mode to be S-mode or U-mode.so that we can
|
* We only allow next mode to be S-mode or U-mode, so that we can
|
||||||
* protect M-mode context and enforce checks on memory accesses.
|
* protect M-mode context and enforce checks on memory accesses.
|
||||||
*/
|
*/
|
||||||
if (dom->next_mode != PRV_S &&
|
if (dom->next_mode != PRV_S &&
|
||||||
@@ -292,7 +348,7 @@ static int sanitize_domain(const struct sbi_platform *plat,
|
|||||||
return SBI_EINVAL;
|
return SBI_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check next address and next mode*/
|
/* Check next address and next mode */
|
||||||
if (!sbi_domain_check_addr(dom, dom->next_addr, dom->next_mode,
|
if (!sbi_domain_check_addr(dom, dom->next_addr, dom->next_mode,
|
||||||
SBI_DOMAIN_EXECUTE)) {
|
SBI_DOMAIN_EXECUTE)) {
|
||||||
sbi_printf("%s: %s next booting stage address 0x%lx can't "
|
sbi_printf("%s: %s next booting stage address 0x%lx can't "
|
||||||
@@ -303,6 +359,37 @@ static int sanitize_domain(const struct sbi_platform *plat,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool sbi_domain_check_addr_range(const struct sbi_domain *dom,
|
||||||
|
unsigned long addr, unsigned long size,
|
||||||
|
unsigned long mode,
|
||||||
|
unsigned long access_flags)
|
||||||
|
{
|
||||||
|
unsigned long max = addr + size;
|
||||||
|
const struct sbi_domain_memregion *reg, *sreg;
|
||||||
|
|
||||||
|
if (!dom)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
while (addr < max) {
|
||||||
|
reg = find_region(dom, addr);
|
||||||
|
if (!reg)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!sbi_domain_check_addr(dom, addr, mode, access_flags))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
sreg = find_next_subset_region(dom, reg, addr);
|
||||||
|
if (sreg)
|
||||||
|
addr = sreg->base;
|
||||||
|
else if (reg->order < __riscv_xlen)
|
||||||
|
addr = reg->base + (1UL << reg->order);
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void sbi_domain_dump(const struct sbi_domain *dom, const char *suffix)
|
void sbi_domain_dump(const struct sbi_domain *dom, const char *suffix)
|
||||||
{
|
{
|
||||||
u32 i, k;
|
u32 i, k;
|
||||||
@@ -332,15 +419,25 @@ void sbi_domain_dump(const struct sbi_domain *dom, const char *suffix)
|
|||||||
dom->index, i, suffix, rstart, rend);
|
dom->index, i, suffix, rstart, rend);
|
||||||
|
|
||||||
k = 0;
|
k = 0;
|
||||||
if (reg->flags & SBI_DOMAIN_MEMREGION_MMODE)
|
|
||||||
sbi_printf("%cM", (k++) ? ',' : '(');
|
sbi_printf("M: ");
|
||||||
if (reg->flags & SBI_DOMAIN_MEMREGION_MMIO)
|
if (reg->flags & SBI_DOMAIN_MEMREGION_MMIO)
|
||||||
sbi_printf("%cI", (k++) ? ',' : '(');
|
sbi_printf("%cI", (k++) ? ',' : '(');
|
||||||
if (reg->flags & SBI_DOMAIN_MEMREGION_READABLE)
|
if (reg->flags & SBI_DOMAIN_MEMREGION_M_READABLE)
|
||||||
sbi_printf("%cR", (k++) ? ',' : '(');
|
sbi_printf("%cR", (k++) ? ',' : '(');
|
||||||
if (reg->flags & SBI_DOMAIN_MEMREGION_WRITEABLE)
|
if (reg->flags & SBI_DOMAIN_MEMREGION_M_WRITABLE)
|
||||||
sbi_printf("%cW", (k++) ? ',' : '(');
|
sbi_printf("%cW", (k++) ? ',' : '(');
|
||||||
if (reg->flags & SBI_DOMAIN_MEMREGION_EXECUTABLE)
|
if (reg->flags & SBI_DOMAIN_MEMREGION_M_EXECUTABLE)
|
||||||
|
sbi_printf("%cX", (k++) ? ',' : '(');
|
||||||
|
sbi_printf("%s ", (k++) ? ")" : "()");
|
||||||
|
|
||||||
|
k = 0;
|
||||||
|
sbi_printf("S/U: ");
|
||||||
|
if (reg->flags & SBI_DOMAIN_MEMREGION_SU_READABLE)
|
||||||
|
sbi_printf("%cR", (k++) ? ',' : '(');
|
||||||
|
if (reg->flags & SBI_DOMAIN_MEMREGION_SU_WRITABLE)
|
||||||
|
sbi_printf("%cW", (k++) ? ',' : '(');
|
||||||
|
if (reg->flags & SBI_DOMAIN_MEMREGION_SU_EXECUTABLE)
|
||||||
sbi_printf("%cX", (k++) ? ',' : '(');
|
sbi_printf("%cX", (k++) ? ',' : '(');
|
||||||
sbi_printf("%s\n", (k++) ? ")" : "()");
|
sbi_printf("%s\n", (k++) ? ")" : "()");
|
||||||
|
|
||||||
@@ -371,6 +468,9 @@ void sbi_domain_dump(const struct sbi_domain *dom, const char *suffix)
|
|||||||
|
|
||||||
sbi_printf("Domain%d SysReset %s: %s\n",
|
sbi_printf("Domain%d SysReset %s: %s\n",
|
||||||
dom->index, suffix, (dom->system_reset_allowed) ? "yes" : "no");
|
dom->index, suffix, (dom->system_reset_allowed) ? "yes" : "no");
|
||||||
|
|
||||||
|
sbi_printf("Domain%d SysSuspend %s: %s\n",
|
||||||
|
dom->index, suffix, (dom->system_suspend_allowed) ? "yes" : "no");
|
||||||
}
|
}
|
||||||
|
|
||||||
void sbi_domain_dump_all(const char *suffix)
|
void sbi_domain_dump_all(const char *suffix)
|
||||||
@@ -471,8 +571,12 @@ int sbi_domain_root_add_memregion(const struct sbi_domain_memregion *reg)
|
|||||||
|
|
||||||
/* Check for conflicts */
|
/* Check for conflicts */
|
||||||
sbi_domain_for_each_memregion(&root, nreg) {
|
sbi_domain_for_each_memregion(&root, nreg) {
|
||||||
if (is_region_conflict(reg, nreg))
|
if (is_region_conflict(reg, nreg)) {
|
||||||
return SBI_EINVAL;
|
sbi_printf("%s: is_region_conflict check failed"
|
||||||
|
" 0x%lx conflicts existing 0x%lx\n", __func__,
|
||||||
|
reg->base, nreg->base);
|
||||||
|
return SBI_EALREADY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Append the memregion to root memregions */
|
/* Append the memregion to root memregions */
|
||||||
@@ -518,6 +622,33 @@ int sbi_domain_root_add_memregion(const struct sbi_domain_memregion *reg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sbi_domain_root_add_memrange(unsigned long addr, unsigned long size,
|
||||||
|
unsigned long align, unsigned long region_flags)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
unsigned long pos, end, rsize;
|
||||||
|
struct sbi_domain_memregion reg;
|
||||||
|
|
||||||
|
pos = addr;
|
||||||
|
end = addr + size;
|
||||||
|
while (pos < end) {
|
||||||
|
rsize = pos & (align - 1);
|
||||||
|
if (rsize)
|
||||||
|
rsize = 1UL << sbi_ffs(pos);
|
||||||
|
else
|
||||||
|
rsize = ((end - pos) < align) ?
|
||||||
|
(end - pos) : align;
|
||||||
|
|
||||||
|
sbi_domain_memregion_init(pos, rsize, region_flags, ®);
|
||||||
|
rc = sbi_domain_root_add_memregion(®);
|
||||||
|
if (rc)
|
||||||
|
return rc;
|
||||||
|
pos += rsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int sbi_domain_finalize(struct sbi_scratch *scratch, u32 cold_hartid)
|
int sbi_domain_finalize(struct sbi_scratch *scratch, u32 cold_hartid)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
@@ -584,11 +715,32 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid)
|
|||||||
u32 i;
|
u32 i;
|
||||||
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
|
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
|
||||||
|
|
||||||
|
if (scratch->fw_rw_offset == 0 ||
|
||||||
|
(scratch->fw_rw_offset & (scratch->fw_rw_offset - 1)) != 0) {
|
||||||
|
sbi_printf("%s: fw_rw_offset is not a power of 2 (0x%lx)\n",
|
||||||
|
__func__, scratch->fw_rw_offset);
|
||||||
|
return SBI_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((scratch->fw_start & (scratch->fw_rw_offset - 1)) != 0) {
|
||||||
|
sbi_printf("%s: fw_start and fw_rw_offset not aligned\n",
|
||||||
|
__func__);
|
||||||
|
return SBI_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Root domain firmware memory region */
|
/* Root domain firmware memory region */
|
||||||
sbi_domain_memregion_init(scratch->fw_start, scratch->fw_size, 0,
|
sbi_domain_memregion_init(scratch->fw_start, scratch->fw_rw_offset,
|
||||||
|
(SBI_DOMAIN_MEMREGION_M_READABLE |
|
||||||
|
SBI_DOMAIN_MEMREGION_M_EXECUTABLE),
|
||||||
&root_fw_region);
|
&root_fw_region);
|
||||||
domain_memregion_initfw(&root_memregs[root_memregs_count++]);
|
domain_memregion_initfw(&root_memregs[root_memregs_count++]);
|
||||||
|
|
||||||
|
sbi_domain_memregion_init((scratch->fw_start + scratch->fw_rw_offset),
|
||||||
|
(scratch->fw_size - scratch->fw_rw_offset),
|
||||||
|
(SBI_DOMAIN_MEMREGION_M_READABLE |
|
||||||
|
SBI_DOMAIN_MEMREGION_M_WRITABLE),
|
||||||
|
&root_memregs[root_memregs_count++]);
|
||||||
|
|
||||||
/* Root domain allow everything memory region */
|
/* Root domain allow everything memory region */
|
||||||
sbi_domain_memregion_init(0, ~0UL,
|
sbi_domain_memregion_init(0, ~0UL,
|
||||||
(SBI_DOMAIN_MEMREGION_READABLE |
|
(SBI_DOMAIN_MEMREGION_READABLE |
|
||||||
|
|||||||
@@ -13,6 +13,9 @@
|
|||||||
#include <sbi/sbi_error.h>
|
#include <sbi/sbi_error.h>
|
||||||
#include <sbi/sbi_trap.h>
|
#include <sbi/sbi_trap.h>
|
||||||
|
|
||||||
|
extern struct sbi_ecall_extension *sbi_ecall_exts[];
|
||||||
|
extern unsigned long sbi_ecall_exts_size;
|
||||||
|
|
||||||
u16 sbi_ecall_version_major(void)
|
u16 sbi_ecall_version_major(void)
|
||||||
{
|
{
|
||||||
return SBI_ECALL_VERSION_MAJOR;
|
return SBI_ECALL_VERSION_MAJOR;
|
||||||
@@ -75,7 +78,7 @@ int sbi_ecall_register_extension(struct sbi_ecall_extension *ext)
|
|||||||
|
|
||||||
void sbi_ecall_unregister_extension(struct sbi_ecall_extension *ext)
|
void sbi_ecall_unregister_extension(struct sbi_ecall_extension *ext)
|
||||||
{
|
{
|
||||||
bool found = FALSE;
|
bool found = false;
|
||||||
struct sbi_ecall_extension *t;
|
struct sbi_ecall_extension *t;
|
||||||
|
|
||||||
if (!ext)
|
if (!ext)
|
||||||
@@ -83,7 +86,7 @@ void sbi_ecall_unregister_extension(struct sbi_ecall_extension *ext)
|
|||||||
|
|
||||||
sbi_list_for_each_entry(t, &ecall_exts_list, head) {
|
sbi_list_for_each_entry(t, &ecall_exts_list, head) {
|
||||||
if (t == ext) {
|
if (t == ext) {
|
||||||
found = TRUE;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,7 +120,7 @@ int sbi_ecall_handler(struct sbi_trap_regs *regs)
|
|||||||
trap.epc = regs->mepc;
|
trap.epc = regs->mepc;
|
||||||
sbi_trap_redirect(regs, &trap);
|
sbi_trap_redirect(regs, &trap);
|
||||||
} else {
|
} else {
|
||||||
if (ret < SBI_LAST_ERR) {
|
if (ret < SBI_LAST_ERR || SBI_SUCCESS < ret) {
|
||||||
sbi_printf("%s: Invalid error %d for ext=0x%lx "
|
sbi_printf("%s: Invalid error %d for ext=0x%lx "
|
||||||
"func=0x%lx\n", __func__, ret,
|
"func=0x%lx\n", __func__, ret,
|
||||||
extension_id, func_id);
|
extension_id, func_id);
|
||||||
@@ -144,35 +147,15 @@ int sbi_ecall_handler(struct sbi_trap_regs *regs)
|
|||||||
int sbi_ecall_init(void)
|
int sbi_ecall_init(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
struct sbi_ecall_extension *ext;
|
||||||
|
unsigned long i;
|
||||||
|
|
||||||
/* The order of below registrations is performance optimized */
|
for (i = 0; i < sbi_ecall_exts_size; i++) {
|
||||||
ret = sbi_ecall_register_extension(&ecall_time);
|
ext = sbi_ecall_exts[i];
|
||||||
if (ret)
|
ret = sbi_ecall_register_extension(ext);
|
||||||
return ret;
|
if (ret)
|
||||||
ret = sbi_ecall_register_extension(&ecall_rfence);
|
return ret;
|
||||||
if (ret)
|
}
|
||||||
return ret;
|
|
||||||
ret = sbi_ecall_register_extension(&ecall_ipi);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
ret = sbi_ecall_register_extension(&ecall_base);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
ret = sbi_ecall_register_extension(&ecall_hsm);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
ret = sbi_ecall_register_extension(&ecall_srst);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
ret = sbi_ecall_register_extension(&ecall_pmu);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
ret = sbi_ecall_register_extension(&ecall_legacy);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
ret = sbi_ecall_register_extension(&ecall_vendor);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
72
lib/sbi/sbi_ecall_dbcn.c
Normal file
72
lib/sbi/sbi_ecall_dbcn.c
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Ventana Micro Systems Inc.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Anup Patel <apatel@ventanamicro.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sbi/sbi_console.h>
|
||||||
|
#include <sbi/sbi_domain.h>
|
||||||
|
#include <sbi/sbi_error.h>
|
||||||
|
#include <sbi/sbi_ecall.h>
|
||||||
|
#include <sbi/sbi_ecall_interface.h>
|
||||||
|
#include <sbi/sbi_trap.h>
|
||||||
|
#include <sbi/riscv_asm.h>
|
||||||
|
|
||||||
|
static int sbi_ecall_dbcn_handler(unsigned long extid, unsigned long funcid,
|
||||||
|
const struct sbi_trap_regs *regs,
|
||||||
|
unsigned long *out_val,
|
||||||
|
struct sbi_trap_info *out_trap)
|
||||||
|
{
|
||||||
|
ulong smode = (csr_read(CSR_MSTATUS) & MSTATUS_MPP) >>
|
||||||
|
MSTATUS_MPP_SHIFT;
|
||||||
|
|
||||||
|
switch (funcid) {
|
||||||
|
case SBI_EXT_DBCN_CONSOLE_WRITE:
|
||||||
|
case SBI_EXT_DBCN_CONSOLE_READ:
|
||||||
|
/*
|
||||||
|
* On RV32, the M-mode can only access the first 4GB of
|
||||||
|
* the physical address space because M-mode does not have
|
||||||
|
* MMU to access full 34-bit physical address space.
|
||||||
|
*
|
||||||
|
* Based on above, we simply fail if the upper 32bits of
|
||||||
|
* the physical address (i.e. a2 register) is non-zero on
|
||||||
|
* RV32.
|
||||||
|
*/
|
||||||
|
#if __riscv_xlen == 32
|
||||||
|
if (regs->a2)
|
||||||
|
return SBI_ERR_FAILED;
|
||||||
|
#endif
|
||||||
|
if (!sbi_domain_check_addr_range(sbi_domain_thishart_ptr(),
|
||||||
|
regs->a1, regs->a0, smode,
|
||||||
|
SBI_DOMAIN_READ|SBI_DOMAIN_WRITE))
|
||||||
|
return SBI_ERR_INVALID_PARAM;
|
||||||
|
if (funcid == SBI_EXT_DBCN_CONSOLE_WRITE)
|
||||||
|
*out_val = sbi_nputs((const char *)regs->a1, regs->a0);
|
||||||
|
else
|
||||||
|
*out_val = sbi_ngets((char *)regs->a1, regs->a0);
|
||||||
|
return 0;
|
||||||
|
case SBI_EXT_DBCN_CONSOLE_WRITE_BYTE:
|
||||||
|
sbi_putc(regs->a0);
|
||||||
|
return 0;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SBI_ENOTSUPP;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int sbi_ecall_dbcn_probe(unsigned long extid, unsigned long *out_val)
|
||||||
|
{
|
||||||
|
*out_val = sbi_console_get_device() ? 1 : 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sbi_ecall_extension ecall_dbcn = {
|
||||||
|
.extid_start = SBI_EXT_DBCN,
|
||||||
|
.extid_end = SBI_EXT_DBCN,
|
||||||
|
.handle = sbi_ecall_dbcn_handler,
|
||||||
|
.probe = sbi_ecall_dbcn_probe,
|
||||||
|
};
|
||||||
3
lib/sbi/sbi_ecall_exts.carray
Normal file
3
lib/sbi/sbi_ecall_exts.carray
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
HEADER: sbi/sbi_ecall.h
|
||||||
|
TYPE: struct sbi_ecall_extension
|
||||||
|
NAME: sbi_ecall_exts
|
||||||
@@ -12,7 +12,6 @@
|
|||||||
#include <sbi/sbi_ecall_interface.h>
|
#include <sbi/sbi_ecall_interface.h>
|
||||||
#include <sbi/sbi_error.h>
|
#include <sbi/sbi_error.h>
|
||||||
#include <sbi/sbi_trap.h>
|
#include <sbi/sbi_trap.h>
|
||||||
#include <sbi/sbi_version.h>
|
|
||||||
#include <sbi/sbi_hsm.h>
|
#include <sbi/sbi_hsm.h>
|
||||||
#include <sbi/sbi_scratch.h>
|
#include <sbi/sbi_scratch.h>
|
||||||
#include <sbi/riscv_asm.h>
|
#include <sbi/riscv_asm.h>
|
||||||
@@ -33,7 +32,7 @@ static int sbi_ecall_hsm_handler(unsigned long extid, unsigned long funcid,
|
|||||||
regs->a0, regs->a1, smode, regs->a2);
|
regs->a0, regs->a1, smode, regs->a2);
|
||||||
break;
|
break;
|
||||||
case SBI_EXT_HSM_HART_STOP:
|
case SBI_EXT_HSM_HART_STOP:
|
||||||
ret = sbi_hsm_hart_stop(scratch, TRUE);
|
ret = sbi_hsm_hart_stop(scratch, true);
|
||||||
break;
|
break;
|
||||||
case SBI_EXT_HSM_HART_GET_STATUS:
|
case SBI_EXT_HSM_HART_GET_STATUS:
|
||||||
ret = sbi_hsm_hart_get_state(sbi_domain_thishart_ptr(),
|
ret = sbi_hsm_hart_get_state(sbi_domain_thishart_ptr(),
|
||||||
@@ -45,7 +44,8 @@ static int sbi_ecall_hsm_handler(unsigned long extid, unsigned long funcid,
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ret = SBI_ENOTSUPP;
|
ret = SBI_ENOTSUPP;
|
||||||
};
|
}
|
||||||
|
|
||||||
if (ret >= 0) {
|
if (ret >= 0) {
|
||||||
*out_val = ret;
|
*out_val = ret;
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|||||||
36
lib/sbi/sbi_ecall_ipi.c
Normal file
36
lib/sbi/sbi_ecall_ipi.c
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Western Digital Corporation or its affiliates.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Anup Patel <anup.patel@wdc.com>
|
||||||
|
* Atish Patra <atish.patra@wdc.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sbi/sbi_error.h>
|
||||||
|
#include <sbi/sbi_ecall.h>
|
||||||
|
#include <sbi/sbi_ecall_interface.h>
|
||||||
|
#include <sbi/sbi_trap.h>
|
||||||
|
#include <sbi/sbi_ipi.h>
|
||||||
|
|
||||||
|
static int sbi_ecall_ipi_handler(unsigned long extid, unsigned long funcid,
|
||||||
|
const struct sbi_trap_regs *regs,
|
||||||
|
unsigned long *out_val,
|
||||||
|
struct sbi_trap_info *out_trap)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
if (funcid == SBI_EXT_IPI_SEND_IPI)
|
||||||
|
ret = sbi_ipi_send_smode(regs->a0, regs->a1);
|
||||||
|
else
|
||||||
|
ret = SBI_ENOTSUPP;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sbi_ecall_extension ecall_ipi = {
|
||||||
|
.extid_start = SBI_EXT_IPI,
|
||||||
|
.extid_end = SBI_EXT_IPI,
|
||||||
|
.handle = sbi_ecall_ipi_handler,
|
||||||
|
};
|
||||||
@@ -51,7 +51,16 @@ static int sbi_ecall_pmu_handler(unsigned long extid, unsigned long funcid,
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case SBI_EXT_PMU_COUNTER_FW_READ:
|
case SBI_EXT_PMU_COUNTER_FW_READ:
|
||||||
ret = sbi_pmu_ctr_read(regs->a0, out_val);
|
ret = sbi_pmu_ctr_fw_read(regs->a0, &temp);
|
||||||
|
*out_val = temp;
|
||||||
|
break;
|
||||||
|
case SBI_EXT_PMU_COUNTER_FW_READ_HI:
|
||||||
|
#if __riscv_xlen == 32
|
||||||
|
ret = sbi_pmu_ctr_fw_read(regs->a0, &temp);
|
||||||
|
*out_val = temp >> 32;
|
||||||
|
#else
|
||||||
|
*out_val = 0;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case SBI_EXT_PMU_COUNTER_START:
|
case SBI_EXT_PMU_COUNTER_START:
|
||||||
|
|
||||||
|
|||||||
@@ -9,40 +9,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sbi/riscv_asm.h>
|
#include <sbi/riscv_asm.h>
|
||||||
|
#include <sbi/sbi_error.h>
|
||||||
#include <sbi/sbi_ecall.h>
|
#include <sbi/sbi_ecall.h>
|
||||||
#include <sbi/sbi_ecall_interface.h>
|
#include <sbi/sbi_ecall_interface.h>
|
||||||
#include <sbi/sbi_error.h>
|
|
||||||
#include <sbi/sbi_hart.h>
|
|
||||||
#include <sbi/sbi_ipi.h>
|
|
||||||
#include <sbi/sbi_system.h>
|
|
||||||
#include <sbi/sbi_timer.h>
|
|
||||||
#include <sbi/sbi_tlb.h>
|
|
||||||
#include <sbi/sbi_trap.h>
|
#include <sbi/sbi_trap.h>
|
||||||
|
#include <sbi/sbi_tlb.h>
|
||||||
static int sbi_ecall_time_handler(unsigned long extid, unsigned long funcid,
|
|
||||||
const struct sbi_trap_regs *regs,
|
|
||||||
unsigned long *out_val,
|
|
||||||
struct sbi_trap_info *out_trap)
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
if (funcid == SBI_EXT_TIME_SET_TIMER) {
|
|
||||||
#if __riscv_xlen == 32
|
|
||||||
sbi_timer_event_start((((u64)regs->a1 << 32) | (u64)regs->a0));
|
|
||||||
#else
|
|
||||||
sbi_timer_event_start((u64)regs->a0);
|
|
||||||
#endif
|
|
||||||
} else
|
|
||||||
ret = SBI_ENOTSUPP;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sbi_ecall_extension ecall_time = {
|
|
||||||
.extid_start = SBI_EXT_TIME,
|
|
||||||
.extid_end = SBI_EXT_TIME,
|
|
||||||
.handle = sbi_ecall_time_handler,
|
|
||||||
};
|
|
||||||
|
|
||||||
static int sbi_ecall_rfence_handler(unsigned long extid, unsigned long funcid,
|
static int sbi_ecall_rfence_handler(unsigned long extid, unsigned long funcid,
|
||||||
const struct sbi_trap_regs *regs,
|
const struct sbi_trap_regs *regs,
|
||||||
@@ -113,84 +84,3 @@ struct sbi_ecall_extension ecall_rfence = {
|
|||||||
.extid_end = SBI_EXT_RFENCE,
|
.extid_end = SBI_EXT_RFENCE,
|
||||||
.handle = sbi_ecall_rfence_handler,
|
.handle = sbi_ecall_rfence_handler,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int sbi_ecall_ipi_handler(unsigned long extid, unsigned long funcid,
|
|
||||||
const struct sbi_trap_regs *regs,
|
|
||||||
unsigned long *out_val,
|
|
||||||
struct sbi_trap_info *out_trap)
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
if (funcid == SBI_EXT_IPI_SEND_IPI)
|
|
||||||
ret = sbi_ipi_send_smode(regs->a0, regs->a1);
|
|
||||||
else
|
|
||||||
ret = SBI_ENOTSUPP;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sbi_ecall_extension ecall_ipi = {
|
|
||||||
.extid_start = SBI_EXT_IPI,
|
|
||||||
.extid_end = SBI_EXT_IPI,
|
|
||||||
.handle = sbi_ecall_ipi_handler,
|
|
||||||
};
|
|
||||||
|
|
||||||
static int sbi_ecall_srst_handler(unsigned long extid, unsigned long funcid,
|
|
||||||
const struct sbi_trap_regs *regs,
|
|
||||||
unsigned long *out_val,
|
|
||||||
struct sbi_trap_info *out_trap)
|
|
||||||
{
|
|
||||||
if (funcid == SBI_EXT_SRST_RESET) {
|
|
||||||
if ((((u32)-1U) <= ((u64)regs->a0)) ||
|
|
||||||
(((u32)-1U) <= ((u64)regs->a1)))
|
|
||||||
return SBI_EINVAL;
|
|
||||||
|
|
||||||
switch (regs->a0) {
|
|
||||||
case SBI_SRST_RESET_TYPE_SHUTDOWN:
|
|
||||||
case SBI_SRST_RESET_TYPE_COLD_REBOOT:
|
|
||||||
case SBI_SRST_RESET_TYPE_WARM_REBOOT:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return SBI_EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (regs->a1) {
|
|
||||||
case SBI_SRST_RESET_REASON_NONE:
|
|
||||||
case SBI_SRST_RESET_REASON_SYSFAIL:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return SBI_EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sbi_system_reset_supported(regs->a0, regs->a1))
|
|
||||||
sbi_system_reset(regs->a0, regs->a1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return SBI_ENOTSUPP;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val)
|
|
||||||
{
|
|
||||||
u32 type, count = 0;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* At least one standard reset types should be supported by
|
|
||||||
* the platform for SBI SRST extension to be usable.
|
|
||||||
*/
|
|
||||||
|
|
||||||
for (type = 0; type <= SBI_SRST_RESET_TYPE_LAST; type++) {
|
|
||||||
if (sbi_system_reset_supported(type,
|
|
||||||
SBI_SRST_RESET_REASON_NONE))
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
*out_val = (count) ? 1 : 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sbi_ecall_extension ecall_srst = {
|
|
||||||
.extid_start = SBI_EXT_SRST,
|
|
||||||
.extid_end = SBI_EXT_SRST,
|
|
||||||
.handle = sbi_ecall_srst_handler,
|
|
||||||
.probe = sbi_ecall_srst_probe,
|
|
||||||
};
|
|
||||||
75
lib/sbi/sbi_ecall_srst.c
Normal file
75
lib/sbi/sbi_ecall_srst.c
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Western Digital Corporation or its affiliates.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Anup Patel <anup.patel@wdc.com>
|
||||||
|
* Atish Patra <atish.patra@wdc.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sbi/sbi_error.h>
|
||||||
|
#include <sbi/sbi_ecall.h>
|
||||||
|
#include <sbi/sbi_ecall_interface.h>
|
||||||
|
#include <sbi/sbi_trap.h>
|
||||||
|
#include <sbi/sbi_system.h>
|
||||||
|
|
||||||
|
static int sbi_ecall_srst_handler(unsigned long extid, unsigned long funcid,
|
||||||
|
const struct sbi_trap_regs *regs,
|
||||||
|
unsigned long *out_val,
|
||||||
|
struct sbi_trap_info *out_trap)
|
||||||
|
{
|
||||||
|
if (funcid == SBI_EXT_SRST_RESET) {
|
||||||
|
if ((((u32)-1U) <= ((u64)regs->a0)) ||
|
||||||
|
(((u32)-1U) <= ((u64)regs->a1)))
|
||||||
|
return SBI_EINVAL;
|
||||||
|
|
||||||
|
switch (regs->a0) {
|
||||||
|
case SBI_SRST_RESET_TYPE_SHUTDOWN:
|
||||||
|
case SBI_SRST_RESET_TYPE_COLD_REBOOT:
|
||||||
|
case SBI_SRST_RESET_TYPE_WARM_REBOOT:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return SBI_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (regs->a1) {
|
||||||
|
case SBI_SRST_RESET_REASON_NONE:
|
||||||
|
case SBI_SRST_RESET_REASON_SYSFAIL:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return SBI_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sbi_system_reset_supported(regs->a0, regs->a1))
|
||||||
|
sbi_system_reset(regs->a0, regs->a1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return SBI_ENOTSUPP;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val)
|
||||||
|
{
|
||||||
|
u32 type, count = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* At least one standard reset types should be supported by
|
||||||
|
* the platform for SBI SRST extension to be usable.
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (type = 0; type <= SBI_SRST_RESET_TYPE_LAST; type++) {
|
||||||
|
if (sbi_system_reset_supported(type,
|
||||||
|
SBI_SRST_RESET_REASON_NONE))
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out_val = (count) ? 1 : 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sbi_ecall_extension ecall_srst = {
|
||||||
|
.extid_start = SBI_EXT_SRST,
|
||||||
|
.extid_end = SBI_EXT_SRST,
|
||||||
|
.handle = sbi_ecall_srst_handler,
|
||||||
|
.probe = sbi_ecall_srst_probe,
|
||||||
|
};
|
||||||
48
lib/sbi/sbi_ecall_susp.c
Normal file
48
lib/sbi/sbi_ecall_susp.c
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
// SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
#include <sbi/sbi_ecall.h>
|
||||||
|
#include <sbi/sbi_ecall_interface.h>
|
||||||
|
#include <sbi/sbi_error.h>
|
||||||
|
#include <sbi/sbi_trap.h>
|
||||||
|
#include <sbi/sbi_system.h>
|
||||||
|
|
||||||
|
static int sbi_ecall_susp_handler(unsigned long extid, unsigned long funcid,
|
||||||
|
const struct sbi_trap_regs *regs,
|
||||||
|
unsigned long *out_val,
|
||||||
|
struct sbi_trap_info *out_trap)
|
||||||
|
{
|
||||||
|
int ret = SBI_ENOTSUPP;
|
||||||
|
|
||||||
|
if (funcid == SBI_EXT_SUSP_SUSPEND)
|
||||||
|
ret = sbi_system_suspend(regs->a0, regs->a1, regs->a2);
|
||||||
|
|
||||||
|
if (ret >= 0) {
|
||||||
|
*out_val = ret;
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int sbi_ecall_susp_probe(unsigned long extid, unsigned long *out_val)
|
||||||
|
{
|
||||||
|
u32 type, count = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* At least one suspend type should be supported by the
|
||||||
|
* platform for the SBI SUSP extension to be usable.
|
||||||
|
*/
|
||||||
|
for (type = 0; type <= SBI_SUSP_SLEEP_TYPE_LAST; type++) {
|
||||||
|
if (sbi_system_suspend_supported(type))
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out_val = count ? 1 : 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sbi_ecall_extension ecall_susp = {
|
||||||
|
.extid_start = SBI_EXT_SUSP,
|
||||||
|
.extid_end = SBI_EXT_SUSP,
|
||||||
|
.handle = sbi_ecall_susp_handler,
|
||||||
|
.probe = sbi_ecall_susp_probe,
|
||||||
|
};
|
||||||
40
lib/sbi/sbi_ecall_time.c
Normal file
40
lib/sbi/sbi_ecall_time.c
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 Western Digital Corporation or its affiliates.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Anup Patel <anup.patel@wdc.com>
|
||||||
|
* Atish Patra <atish.patra@wdc.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sbi/sbi_error.h>
|
||||||
|
#include <sbi/sbi_ecall.h>
|
||||||
|
#include <sbi/sbi_ecall_interface.h>
|
||||||
|
#include <sbi/sbi_trap.h>
|
||||||
|
#include <sbi/sbi_timer.h>
|
||||||
|
|
||||||
|
static int sbi_ecall_time_handler(unsigned long extid, unsigned long funcid,
|
||||||
|
const struct sbi_trap_regs *regs,
|
||||||
|
unsigned long *out_val,
|
||||||
|
struct sbi_trap_info *out_trap)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
if (funcid == SBI_EXT_TIME_SET_TIMER) {
|
||||||
|
#if __riscv_xlen == 32
|
||||||
|
sbi_timer_event_start((((u64)regs->a1 << 32) | (u64)regs->a0));
|
||||||
|
#else
|
||||||
|
sbi_timer_event_start((u64)regs->a0);
|
||||||
|
#endif
|
||||||
|
} else
|
||||||
|
ret = SBI_ENOTSUPP;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sbi_ecall_extension ecall_time = {
|
||||||
|
.extid_start = SBI_EXT_TIME,
|
||||||
|
.extid_end = SBI_EXT_TIME,
|
||||||
|
.handle = sbi_ecall_time_handler,
|
||||||
|
};
|
||||||
@@ -13,12 +13,23 @@
|
|||||||
#include <sbi/sbi_error.h>
|
#include <sbi/sbi_error.h>
|
||||||
#include <sbi/sbi_platform.h>
|
#include <sbi/sbi_platform.h>
|
||||||
#include <sbi/sbi_trap.h>
|
#include <sbi/sbi_trap.h>
|
||||||
|
#include <sbi/riscv_asm.h>
|
||||||
|
|
||||||
|
static inline unsigned long sbi_ecall_vendor_id(void)
|
||||||
|
{
|
||||||
|
return SBI_EXT_VENDOR_START +
|
||||||
|
(csr_read(CSR_MVENDORID) &
|
||||||
|
(SBI_EXT_VENDOR_END - SBI_EXT_VENDOR_START));
|
||||||
|
}
|
||||||
|
|
||||||
static int sbi_ecall_vendor_probe(unsigned long extid,
|
static int sbi_ecall_vendor_probe(unsigned long extid,
|
||||||
unsigned long *out_val)
|
unsigned long *out_val)
|
||||||
{
|
{
|
||||||
*out_val = sbi_platform_vendor_ext_check(sbi_platform_thishart_ptr(),
|
if (!sbi_platform_vendor_ext_check(sbi_platform_thishart_ptr()) ||
|
||||||
extid);
|
extid != sbi_ecall_vendor_id())
|
||||||
|
*out_val = 0;
|
||||||
|
else
|
||||||
|
*out_val = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,8 +38,12 @@ static int sbi_ecall_vendor_handler(unsigned long extid, unsigned long funcid,
|
|||||||
unsigned long *out_val,
|
unsigned long *out_val,
|
||||||
struct sbi_trap_info *out_trap)
|
struct sbi_trap_info *out_trap)
|
||||||
{
|
{
|
||||||
|
if (!sbi_platform_vendor_ext_check(sbi_platform_thishart_ptr()) ||
|
||||||
|
extid != sbi_ecall_vendor_id())
|
||||||
|
return SBI_ERR_NOT_SUPPORTED;
|
||||||
|
|
||||||
return sbi_platform_vendor_ext_provider(sbi_platform_thishart_ptr(),
|
return sbi_platform_vendor_ext_provider(sbi_platform_thishart_ptr(),
|
||||||
extid, funcid, regs,
|
funcid, regs,
|
||||||
out_val, out_trap);
|
out_val, out_trap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ static bool hpm_allowed(int hpm_num, ulong prev_mode, bool virt)
|
|||||||
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
||||||
|
|
||||||
if (prev_mode <= PRV_S) {
|
if (prev_mode <= PRV_S) {
|
||||||
if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTEREN)) {
|
if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10) {
|
||||||
cen &= csr_read(CSR_MCOUNTEREN);
|
cen &= csr_read(CSR_MCOUNTEREN);
|
||||||
if (virt)
|
if (virt)
|
||||||
cen &= csr_read(CSR_HCOUNTEREN);
|
cen &= csr_read(CSR_HCOUNTEREN);
|
||||||
@@ -33,13 +33,13 @@ static bool hpm_allowed(int hpm_num, ulong prev_mode, bool virt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (prev_mode == PRV_U) {
|
if (prev_mode == PRV_U) {
|
||||||
if (sbi_hart_has_feature(scratch, SBI_HART_HAS_SCOUNTEREN))
|
if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
|
||||||
cen &= csr_read(CSR_SCOUNTEREN);
|
cen &= csr_read(CSR_SCOUNTEREN);
|
||||||
else
|
else
|
||||||
cen = 0;
|
cen = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((cen >> hpm_num) & 1) ? TRUE : FALSE;
|
return ((cen >> hpm_num) & 1) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sbi_emulate_csr_read(int csr_num, struct sbi_trap_regs *regs,
|
int sbi_emulate_csr_read(int csr_num, struct sbi_trap_regs *regs,
|
||||||
@@ -49,9 +49,9 @@ int sbi_emulate_csr_read(int csr_num, struct sbi_trap_regs *regs,
|
|||||||
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
||||||
ulong prev_mode = (regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT;
|
ulong prev_mode = (regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT;
|
||||||
#if __riscv_xlen == 32
|
#if __riscv_xlen == 32
|
||||||
bool virt = (regs->mstatusH & MSTATUSH_MPV) ? TRUE : FALSE;
|
bool virt = (regs->mstatusH & MSTATUSH_MPV) ? true : false;
|
||||||
#else
|
#else
|
||||||
bool virt = (regs->mstatus & MSTATUS_MPV) ? TRUE : FALSE;
|
bool virt = (regs->mstatus & MSTATUS_MPV) ? true : false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch (csr_num) {
|
switch (csr_num) {
|
||||||
@@ -164,9 +164,9 @@ int sbi_emulate_csr_write(int csr_num, struct sbi_trap_regs *regs,
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
ulong prev_mode = (regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT;
|
ulong prev_mode = (regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT;
|
||||||
#if __riscv_xlen == 32
|
#if __riscv_xlen == 32
|
||||||
bool virt = (regs->mstatusH & MSTATUSH_MPV) ? TRUE : FALSE;
|
bool virt = (regs->mstatusH & MSTATUSH_MPV) ? true : false;
|
||||||
#else
|
#else
|
||||||
bool virt = (regs->mstatus & MSTATUS_MPV) ? TRUE : FALSE;
|
bool virt = (regs->mstatus & MSTATUS_MPV) ? true : false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch (csr_num) {
|
switch (csr_num) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#include <sbi/sbi_trap.h>
|
#include <sbi/sbi_trap.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We assume that faulting instruction is is 4-byte long and blindly
|
* We assume that faulting instruction is 4-byte long and blindly
|
||||||
* increment SEPC by 4.
|
* increment SEPC by 4.
|
||||||
*
|
*
|
||||||
* The trap info will be saved as follows:
|
* The trap info will be saved as follows:
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
.align 3
|
.align 3
|
||||||
.global __sbi_expected_trap
|
.global __sbi_expected_trap
|
||||||
__sbi_expected_trap:
|
__sbi_expected_trap:
|
||||||
/* Without H-extension so, MTVAL2 and MTINST CSRs not available */
|
/* Without H-extension so, MTVAL2 and MTINST CSRs and GVA not available */
|
||||||
csrr a4, CSR_MEPC
|
csrr a4, CSR_MEPC
|
||||||
REG_S a4, SBI_TRAP_INFO_OFFSET(epc)(a3)
|
REG_S a4, SBI_TRAP_INFO_OFFSET(epc)(a3)
|
||||||
csrr a4, CSR_MCAUSE
|
csrr a4, CSR_MCAUSE
|
||||||
@@ -31,6 +31,7 @@ __sbi_expected_trap:
|
|||||||
REG_S a4, SBI_TRAP_INFO_OFFSET(tval)(a3)
|
REG_S a4, SBI_TRAP_INFO_OFFSET(tval)(a3)
|
||||||
REG_S zero, SBI_TRAP_INFO_OFFSET(tval2)(a3)
|
REG_S zero, SBI_TRAP_INFO_OFFSET(tval2)(a3)
|
||||||
REG_S zero, SBI_TRAP_INFO_OFFSET(tinst)(a3)
|
REG_S zero, SBI_TRAP_INFO_OFFSET(tinst)(a3)
|
||||||
|
REG_S zero, SBI_TRAP_INFO_OFFSET(gva)(a3)
|
||||||
csrr a4, CSR_MEPC
|
csrr a4, CSR_MEPC
|
||||||
addi a4, a4, 4
|
addi a4, a4, 4
|
||||||
csrw CSR_MEPC, a4
|
csrw CSR_MEPC, a4
|
||||||
@@ -39,7 +40,7 @@ __sbi_expected_trap:
|
|||||||
.align 3
|
.align 3
|
||||||
.global __sbi_expected_trap_hext
|
.global __sbi_expected_trap_hext
|
||||||
__sbi_expected_trap_hext:
|
__sbi_expected_trap_hext:
|
||||||
/* With H-extension so, MTVAL2 and MTINST CSRs available */
|
/* With H-extension so, MTVAL2 and MTINST CSRs and GVA available */
|
||||||
csrr a4, CSR_MEPC
|
csrr a4, CSR_MEPC
|
||||||
REG_S a4, SBI_TRAP_INFO_OFFSET(epc)(a3)
|
REG_S a4, SBI_TRAP_INFO_OFFSET(epc)(a3)
|
||||||
csrr a4, CSR_MCAUSE
|
csrr a4, CSR_MCAUSE
|
||||||
@@ -50,6 +51,18 @@ __sbi_expected_trap_hext:
|
|||||||
REG_S a4, SBI_TRAP_INFO_OFFSET(tval2)(a3)
|
REG_S a4, SBI_TRAP_INFO_OFFSET(tval2)(a3)
|
||||||
csrr a4, CSR_MTINST
|
csrr a4, CSR_MTINST
|
||||||
REG_S a4, SBI_TRAP_INFO_OFFSET(tinst)(a3)
|
REG_S a4, SBI_TRAP_INFO_OFFSET(tinst)(a3)
|
||||||
|
|
||||||
|
/* Extract GVA bit from MSTATUS or MSTATUSH */
|
||||||
|
#if __riscv_xlen == 32
|
||||||
|
csrr a4, CSR_MSTATUSH
|
||||||
|
srli a4, a4, MSTATUSH_GVA_SHIFT
|
||||||
|
#else
|
||||||
|
csrr a4, CSR_MSTATUS
|
||||||
|
srli a4, a4, MSTATUS_GVA_SHIFT
|
||||||
|
#endif
|
||||||
|
andi a4, a4, 1
|
||||||
|
REG_S a4, SBI_TRAP_INFO_OFFSET(gva)(a3)
|
||||||
|
|
||||||
csrr a4, CSR_MEPC
|
csrr a4, CSR_MEPC
|
||||||
addi a4, a4, 4
|
addi a4, a4, 4
|
||||||
csrw CSR_MEPC, a4
|
csrw CSR_MEPC, a4
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ void sbi_fifo_init(struct sbi_fifo *fifo, void *queue_mem, u16 entries,
|
|||||||
/* Note: must be called with fifo->qlock held */
|
/* Note: must be called with fifo->qlock held */
|
||||||
static inline bool __sbi_fifo_is_full(struct sbi_fifo *fifo)
|
static inline bool __sbi_fifo_is_full(struct sbi_fifo *fifo)
|
||||||
{
|
{
|
||||||
return (fifo->avail == fifo->num_entries) ? TRUE : FALSE;
|
return (fifo->avail == fifo->num_entries) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 sbi_fifo_avail(struct sbi_fifo *fifo)
|
u16 sbi_fifo_avail(struct sbi_fifo *fifo)
|
||||||
@@ -66,7 +66,7 @@ static inline void __sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data)
|
|||||||
if (head >= fifo->num_entries)
|
if (head >= fifo->num_entries)
|
||||||
head = head - fifo->num_entries;
|
head = head - fifo->num_entries;
|
||||||
|
|
||||||
sbi_memcpy(fifo->queue + head * fifo->entry_size, data, fifo->entry_size);
|
sbi_memcpy((char *)fifo->queue + head * fifo->entry_size, data, fifo->entry_size);
|
||||||
|
|
||||||
fifo->avail++;
|
fifo->avail++;
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ static inline void __sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data)
|
|||||||
/* Note: must be called with fifo->qlock held */
|
/* Note: must be called with fifo->qlock held */
|
||||||
static inline bool __sbi_fifo_is_empty(struct sbi_fifo *fifo)
|
static inline bool __sbi_fifo_is_empty(struct sbi_fifo *fifo)
|
||||||
{
|
{
|
||||||
return (fifo->avail == 0) ? TRUE : FALSE;
|
return (fifo->avail == 0) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sbi_fifo_is_empty(struct sbi_fifo *fifo)
|
int sbi_fifo_is_empty(struct sbi_fifo *fifo)
|
||||||
@@ -105,13 +105,13 @@ static inline void __sbi_fifo_reset(struct sbi_fifo *fifo)
|
|||||||
bool sbi_fifo_reset(struct sbi_fifo *fifo)
|
bool sbi_fifo_reset(struct sbi_fifo *fifo)
|
||||||
{
|
{
|
||||||
if (!fifo)
|
if (!fifo)
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
spin_lock(&fifo->qlock);
|
spin_lock(&fifo->qlock);
|
||||||
__sbi_fifo_reset(fifo);
|
__sbi_fifo_reset(fifo);
|
||||||
spin_unlock(&fifo->qlock);
|
spin_unlock(&fifo->qlock);
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,7 +142,7 @@ int sbi_fifo_inplace_update(struct sbi_fifo *fifo, void *in,
|
|||||||
index = fifo->tail + i;
|
index = fifo->tail + i;
|
||||||
if (index >= fifo->num_entries)
|
if (index >= fifo->num_entries)
|
||||||
index -= fifo->num_entries;
|
index -= fifo->num_entries;
|
||||||
entry = (void *)fifo->queue + (u32)index * fifo->entry_size;
|
entry = (char *)fifo->queue + (u32)index * fifo->entry_size;
|
||||||
ret = fptr(in, entry);
|
ret = fptr(in, entry);
|
||||||
|
|
||||||
if (ret == SBI_FIFO_SKIP || ret == SBI_FIFO_UPDATED) {
|
if (ret == SBI_FIFO_SKIP || ret == SBI_FIFO_UPDATED) {
|
||||||
@@ -184,7 +184,7 @@ int sbi_fifo_dequeue(struct sbi_fifo *fifo, void *data)
|
|||||||
return SBI_ENOENT;
|
return SBI_ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
sbi_memcpy(data, fifo->queue + (u32)fifo->tail * fifo->entry_size,
|
sbi_memcpy(data, (char *)fifo->queue + (u32)fifo->tail * fifo->entry_size,
|
||||||
fifo->entry_size);
|
fifo->entry_size);
|
||||||
|
|
||||||
fifo->avail--;
|
fifo->avail--;
|
||||||
|
|||||||
@@ -19,27 +19,26 @@
|
|||||||
#include <sbi/sbi_hart.h>
|
#include <sbi/sbi_hart.h>
|
||||||
#include <sbi/sbi_math.h>
|
#include <sbi/sbi_math.h>
|
||||||
#include <sbi/sbi_platform.h>
|
#include <sbi/sbi_platform.h>
|
||||||
|
#include <sbi/sbi_pmu.h>
|
||||||
#include <sbi/sbi_string.h>
|
#include <sbi/sbi_string.h>
|
||||||
#include <sbi/sbi_trap.h>
|
#include <sbi/sbi_trap.h>
|
||||||
|
#include <sbi/sbi_hfence.h>
|
||||||
|
|
||||||
extern void __sbi_expected_trap(void);
|
extern void __sbi_expected_trap(void);
|
||||||
extern void __sbi_expected_trap_hext(void);
|
extern void __sbi_expected_trap_hext(void);
|
||||||
|
|
||||||
void (*sbi_hart_expected_trap)(void) = &__sbi_expected_trap;
|
void (*sbi_hart_expected_trap)(void) = &__sbi_expected_trap;
|
||||||
|
|
||||||
struct hart_features {
|
|
||||||
unsigned long features;
|
|
||||||
unsigned int pmp_count;
|
|
||||||
unsigned int pmp_addr_bits;
|
|
||||||
unsigned long pmp_gran;
|
|
||||||
unsigned int mhpm_count;
|
|
||||||
unsigned int mhpm_bits;
|
|
||||||
};
|
|
||||||
static unsigned long hart_features_offset;
|
static unsigned long hart_features_offset;
|
||||||
|
|
||||||
static void mstatus_init(struct sbi_scratch *scratch)
|
static void mstatus_init(struct sbi_scratch *scratch)
|
||||||
{
|
{
|
||||||
unsigned long mstatus_val = 0;
|
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
|
||||||
|
unsigned long menvcfg_val, mstatus_val = 0;
|
||||||
|
int cidx;
|
||||||
|
unsigned int num_mhpm = sbi_hart_mhpm_count(scratch);
|
||||||
|
uint64_t mhpmevent_init_val = 0;
|
||||||
|
uint64_t mstateen_val;
|
||||||
|
|
||||||
/* Enable FPU */
|
/* Enable FPU */
|
||||||
if (misa_extension('D') || misa_extension('F'))
|
if (misa_extension('D') || misa_extension('F'))
|
||||||
@@ -53,7 +52,7 @@ static void mstatus_init(struct sbi_scratch *scratch)
|
|||||||
|
|
||||||
/* Disable user mode usage of all perf counters except default ones (CY, TM, IR) */
|
/* Disable user mode usage of all perf counters except default ones (CY, TM, IR) */
|
||||||
if (misa_extension('S') &&
|
if (misa_extension('S') &&
|
||||||
sbi_hart_has_feature(scratch, SBI_HART_HAS_SCOUNTEREN))
|
sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
|
||||||
csr_write(CSR_SCOUNTEREN, 7);
|
csr_write(CSR_SCOUNTEREN, 7);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,13 +60,113 @@ static void mstatus_init(struct sbi_scratch *scratch)
|
|||||||
* Supervisor mode usage for all counters are enabled by default
|
* Supervisor mode usage for all counters are enabled by default
|
||||||
* But counters will not run until mcountinhibit is set.
|
* But counters will not run until mcountinhibit is set.
|
||||||
*/
|
*/
|
||||||
if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTEREN))
|
if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
|
||||||
csr_write(CSR_MCOUNTEREN, -1);
|
csr_write(CSR_MCOUNTEREN, -1);
|
||||||
|
|
||||||
|
if (sbi_platform_force_emulate_time_csr(plat)) {
|
||||||
|
csr_clear(CSR_MCOUNTEREN, MCOUNTEREN_TM);
|
||||||
|
csr_clear(CSR_SCOUNTEREN, MCOUNTEREN_TM);
|
||||||
|
}
|
||||||
|
|
||||||
/* All programmable counters will start running at runtime after S-mode request */
|
/* All programmable counters will start running at runtime after S-mode request */
|
||||||
if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT))
|
if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_11)
|
||||||
csr_write(CSR_MCOUNTINHIBIT, 0xFFFFFFF8);
|
csr_write(CSR_MCOUNTINHIBIT, 0xFFFFFFF8);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The mhpmeventn[h] CSR should be initialized with interrupt disabled
|
||||||
|
* and inhibited running in M-mode during init.
|
||||||
|
* To keep it simple, only contiguous mhpmcounters are supported as a
|
||||||
|
* platform with discontiguous mhpmcounters may not make much sense.
|
||||||
|
*/
|
||||||
|
mhpmevent_init_val |= (MHPMEVENT_OF | MHPMEVENT_MINH);
|
||||||
|
for (cidx = 0; cidx < num_mhpm; cidx++) {
|
||||||
|
#if __riscv_xlen == 32
|
||||||
|
csr_write_num(CSR_MHPMEVENT3 + cidx, mhpmevent_init_val & 0xFFFFFFFF);
|
||||||
|
if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCOFPMF))
|
||||||
|
csr_write_num(CSR_MHPMEVENT3H + cidx,
|
||||||
|
mhpmevent_init_val >> BITS_PER_LONG);
|
||||||
|
#else
|
||||||
|
csr_write_num(CSR_MHPMEVENT3 + cidx, mhpmevent_init_val);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SMSTATEEN)) {
|
||||||
|
mstateen_val = csr_read(CSR_MSTATEEN0);
|
||||||
|
#if __riscv_xlen == 32
|
||||||
|
mstateen_val |= ((uint64_t)csr_read(CSR_MSTATEEN0H)) << 32;
|
||||||
|
#endif
|
||||||
|
mstateen_val |= SMSTATEEN_STATEN;
|
||||||
|
mstateen_val |= SMSTATEEN0_CONTEXT;
|
||||||
|
mstateen_val |= SMSTATEEN0_HSENVCFG;
|
||||||
|
|
||||||
|
if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SMAIA))
|
||||||
|
mstateen_val |= (SMSTATEEN0_AIA | SMSTATEEN0_SVSLCT |
|
||||||
|
SMSTATEEN0_IMSIC);
|
||||||
|
else
|
||||||
|
mstateen_val &= ~(SMSTATEEN0_AIA | SMSTATEEN0_SVSLCT |
|
||||||
|
SMSTATEEN0_IMSIC);
|
||||||
|
csr_write(CSR_MSTATEEN0, mstateen_val);
|
||||||
|
#if __riscv_xlen == 32
|
||||||
|
csr_write(CSR_MSTATEEN0H, mstateen_val >> 32);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12) {
|
||||||
|
menvcfg_val = csr_read(CSR_MENVCFG);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set menvcfg.CBZE == 1
|
||||||
|
*
|
||||||
|
* If Zicboz extension is not available then writes to
|
||||||
|
* menvcfg.CBZE will be ignored because it is a WARL field.
|
||||||
|
*/
|
||||||
|
menvcfg_val |= ENVCFG_CBZE;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set menvcfg.CBCFE == 1
|
||||||
|
*
|
||||||
|
* If Zicbom extension is not available then writes to
|
||||||
|
* menvcfg.CBCFE will be ignored because it is a WARL field.
|
||||||
|
*/
|
||||||
|
menvcfg_val |= ENVCFG_CBCFE;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set menvcfg.CBIE == 3
|
||||||
|
*
|
||||||
|
* If Zicbom extension is not available then writes to
|
||||||
|
* menvcfg.CBIE will be ignored because it is a WARL field.
|
||||||
|
*/
|
||||||
|
menvcfg_val |= ENVCFG_CBIE_INV << ENVCFG_CBIE_SHIFT;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set menvcfg.PBMTE == 1 for RV64 or RV128
|
||||||
|
*
|
||||||
|
* If Svpbmt extension is not available then menvcfg.PBMTE
|
||||||
|
* will be read-only zero.
|
||||||
|
*/
|
||||||
|
#if __riscv_xlen > 32
|
||||||
|
menvcfg_val |= ENVCFG_PBMTE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The spec doesn't explicitly describe the reset value of menvcfg.
|
||||||
|
* Enable access to stimecmp if sstc extension is present in the
|
||||||
|
* hardware.
|
||||||
|
*/
|
||||||
|
if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSTC)) {
|
||||||
|
#if __riscv_xlen == 32
|
||||||
|
unsigned long menvcfgh_val;
|
||||||
|
menvcfgh_val = csr_read(CSR_MENVCFGH);
|
||||||
|
menvcfgh_val |= ENVCFGH_STCE;
|
||||||
|
csr_write(CSR_MENVCFGH, menvcfgh_val);
|
||||||
|
#else
|
||||||
|
menvcfg_val |= ENVCFG_STCE;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
csr_write(CSR_MENVCFG, menvcfg_val);
|
||||||
|
}
|
||||||
|
|
||||||
/* Disable all interrupts */
|
/* Disable all interrupts */
|
||||||
csr_write(CSR_MIE, 0);
|
csr_write(CSR_MIE, 0);
|
||||||
|
|
||||||
@@ -108,8 +207,7 @@ static int delegate_traps(struct sbi_scratch *scratch)
|
|||||||
|
|
||||||
/* Send M-mode interrupts and most exceptions to S-mode */
|
/* Send M-mode interrupts and most exceptions to S-mode */
|
||||||
interrupts = MIP_SSIP | MIP_STIP | MIP_SEIP;
|
interrupts = MIP_SSIP | MIP_STIP | MIP_SEIP;
|
||||||
if (sbi_hart_has_feature(scratch, SBI_HART_HAS_SSCOFPMF))
|
interrupts |= sbi_pmu_irq_bit();
|
||||||
interrupts |= MIP_LCOFIP;
|
|
||||||
|
|
||||||
exceptions = (1U << CAUSE_MISALIGNED_FETCH) | (1U << CAUSE_BREAKPOINT) |
|
exceptions = (1U << CAUSE_MISALIGNED_FETCH) | (1U << CAUSE_BREAKPOINT) |
|
||||||
(1U << CAUSE_USER_ECALL);
|
(1U << CAUSE_USER_ECALL);
|
||||||
@@ -154,7 +252,7 @@ void sbi_hart_delegation_dump(struct sbi_scratch *scratch,
|
|||||||
|
|
||||||
unsigned int sbi_hart_mhpm_count(struct sbi_scratch *scratch)
|
unsigned int sbi_hart_mhpm_count(struct sbi_scratch *scratch)
|
||||||
{
|
{
|
||||||
struct hart_features *hfeatures =
|
struct sbi_hart_features *hfeatures =
|
||||||
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
||||||
|
|
||||||
return hfeatures->mhpm_count;
|
return hfeatures->mhpm_count;
|
||||||
@@ -162,7 +260,7 @@ unsigned int sbi_hart_mhpm_count(struct sbi_scratch *scratch)
|
|||||||
|
|
||||||
unsigned int sbi_hart_pmp_count(struct sbi_scratch *scratch)
|
unsigned int sbi_hart_pmp_count(struct sbi_scratch *scratch)
|
||||||
{
|
{
|
||||||
struct hart_features *hfeatures =
|
struct sbi_hart_features *hfeatures =
|
||||||
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
||||||
|
|
||||||
return hfeatures->pmp_count;
|
return hfeatures->pmp_count;
|
||||||
@@ -170,7 +268,7 @@ unsigned int sbi_hart_pmp_count(struct sbi_scratch *scratch)
|
|||||||
|
|
||||||
unsigned long sbi_hart_pmp_granularity(struct sbi_scratch *scratch)
|
unsigned long sbi_hart_pmp_granularity(struct sbi_scratch *scratch)
|
||||||
{
|
{
|
||||||
struct hart_features *hfeatures =
|
struct sbi_hart_features *hfeatures =
|
||||||
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
||||||
|
|
||||||
return hfeatures->pmp_gran;
|
return hfeatures->pmp_gran;
|
||||||
@@ -178,7 +276,7 @@ unsigned long sbi_hart_pmp_granularity(struct sbi_scratch *scratch)
|
|||||||
|
|
||||||
unsigned int sbi_hart_pmp_addrbits(struct sbi_scratch *scratch)
|
unsigned int sbi_hart_pmp_addrbits(struct sbi_scratch *scratch)
|
||||||
{
|
{
|
||||||
struct hart_features *hfeatures =
|
struct sbi_hart_features *hfeatures =
|
||||||
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
||||||
|
|
||||||
return hfeatures->pmp_addr_bits;
|
return hfeatures->pmp_addr_bits;
|
||||||
@@ -186,7 +284,7 @@ unsigned int sbi_hart_pmp_addrbits(struct sbi_scratch *scratch)
|
|||||||
|
|
||||||
unsigned int sbi_hart_mhpm_bits(struct sbi_scratch *scratch)
|
unsigned int sbi_hart_mhpm_bits(struct sbi_scratch *scratch)
|
||||||
{
|
{
|
||||||
struct hart_features *hfeatures =
|
struct sbi_hart_features *hfeatures =
|
||||||
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
||||||
|
|
||||||
return hfeatures->mhpm_bits;
|
return hfeatures->mhpm_bits;
|
||||||
@@ -212,15 +310,21 @@ int sbi_hart_pmp_configure(struct sbi_scratch *scratch)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
pmp_flags = 0;
|
pmp_flags = 0;
|
||||||
if (reg->flags & SBI_DOMAIN_MEMREGION_READABLE)
|
|
||||||
pmp_flags |= PMP_R;
|
/*
|
||||||
if (reg->flags & SBI_DOMAIN_MEMREGION_WRITEABLE)
|
* If permissions are to be enforced for all modes on this
|
||||||
pmp_flags |= PMP_W;
|
* region, the lock bit should be set.
|
||||||
if (reg->flags & SBI_DOMAIN_MEMREGION_EXECUTABLE)
|
*/
|
||||||
pmp_flags |= PMP_X;
|
if (reg->flags & SBI_DOMAIN_MEMREGION_ENF_PERMISSIONS)
|
||||||
if (reg->flags & SBI_DOMAIN_MEMREGION_MMODE)
|
|
||||||
pmp_flags |= PMP_L;
|
pmp_flags |= PMP_L;
|
||||||
|
|
||||||
|
if (reg->flags & SBI_DOMAIN_MEMREGION_SU_READABLE)
|
||||||
|
pmp_flags |= PMP_R;
|
||||||
|
if (reg->flags & SBI_DOMAIN_MEMREGION_SU_WRITABLE)
|
||||||
|
pmp_flags |= PMP_W;
|
||||||
|
if (reg->flags & SBI_DOMAIN_MEMREGION_SU_EXECUTABLE)
|
||||||
|
pmp_flags |= PMP_X;
|
||||||
|
|
||||||
pmp_addr = reg->base >> PMP_SHIFT;
|
pmp_addr = reg->base >> PMP_SHIFT;
|
||||||
if (pmp_gran_log2 <= reg->order && pmp_addr < pmp_addr_max)
|
if (pmp_gran_log2 <= reg->order && pmp_addr < pmp_addr_max)
|
||||||
pmp_set(pmp_idx++, pmp_flags, reg->base, reg->order);
|
pmp_set(pmp_idx++, pmp_flags, reg->base, reg->order);
|
||||||
@@ -231,106 +335,180 @@ int sbi_hart_pmp_configure(struct sbi_scratch *scratch)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* As per section 3.7.2 of privileged specification v1.12,
|
||||||
|
* virtual address translations can be speculatively performed
|
||||||
|
* (even before actual access). These, along with PMP traslations,
|
||||||
|
* can be cached. This can pose a problem with CPU hotplug
|
||||||
|
* and non-retentive suspend scenario because PMP states are
|
||||||
|
* not preserved.
|
||||||
|
* It is advisable to flush the caching structures under such
|
||||||
|
* conditions.
|
||||||
|
*/
|
||||||
|
if (misa_extension('S')) {
|
||||||
|
__asm__ __volatile__("sfence.vma");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If hypervisor mode is supported, flush caching
|
||||||
|
* structures in guest mode too.
|
||||||
|
*/
|
||||||
|
if (misa_extension('H'))
|
||||||
|
__sbi_hfence_gvma_all();
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
int sbi_hart_priv_version(struct sbi_scratch *scratch)
|
||||||
* Check whether a particular hart feature is available
|
|
||||||
*
|
|
||||||
* @param scratch pointer to the HART scratch space
|
|
||||||
* @param feature the feature to check
|
|
||||||
* @returns true (feature available) or false (feature not available)
|
|
||||||
*/
|
|
||||||
bool sbi_hart_has_feature(struct sbi_scratch *scratch, unsigned long feature)
|
|
||||||
{
|
{
|
||||||
struct hart_features *hfeatures =
|
struct sbi_hart_features *hfeatures =
|
||||||
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
||||||
|
|
||||||
if (hfeatures->features & feature)
|
return hfeatures->priv_version;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sbi_hart_get_priv_version_str(struct sbi_scratch *scratch,
|
||||||
|
char *version_str, int nvstr)
|
||||||
|
{
|
||||||
|
char *temp;
|
||||||
|
struct sbi_hart_features *hfeatures =
|
||||||
|
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
||||||
|
|
||||||
|
switch (hfeatures->priv_version) {
|
||||||
|
case SBI_HART_PRIV_VER_1_10:
|
||||||
|
temp = "v1.10";
|
||||||
|
break;
|
||||||
|
case SBI_HART_PRIV_VER_1_11:
|
||||||
|
temp = "v1.11";
|
||||||
|
break;
|
||||||
|
case SBI_HART_PRIV_VER_1_12:
|
||||||
|
temp = "v1.12";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
temp = "unknown";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
sbi_snprintf(version_str, nvstr, "%s", temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void __sbi_hart_update_extension(
|
||||||
|
struct sbi_hart_features *hfeatures,
|
||||||
|
enum sbi_hart_extensions ext,
|
||||||
|
bool enable)
|
||||||
|
{
|
||||||
|
if (enable)
|
||||||
|
hfeatures->extensions |= BIT(ext);
|
||||||
|
else
|
||||||
|
hfeatures->extensions &= ~BIT(ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable/Disable a particular hart extension
|
||||||
|
*
|
||||||
|
* @param scratch pointer to the HART scratch space
|
||||||
|
* @param ext the extension number to check
|
||||||
|
* @param enable new state of hart extension
|
||||||
|
*/
|
||||||
|
void sbi_hart_update_extension(struct sbi_scratch *scratch,
|
||||||
|
enum sbi_hart_extensions ext,
|
||||||
|
bool enable)
|
||||||
|
{
|
||||||
|
struct sbi_hart_features *hfeatures =
|
||||||
|
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
||||||
|
|
||||||
|
__sbi_hart_update_extension(hfeatures, ext, enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether a particular hart extension is available
|
||||||
|
*
|
||||||
|
* @param scratch pointer to the HART scratch space
|
||||||
|
* @param ext the extension number to check
|
||||||
|
* @returns true (available) or false (not available)
|
||||||
|
*/
|
||||||
|
bool sbi_hart_has_extension(struct sbi_scratch *scratch,
|
||||||
|
enum sbi_hart_extensions ext)
|
||||||
|
{
|
||||||
|
struct sbi_hart_features *hfeatures =
|
||||||
|
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
||||||
|
|
||||||
|
if (hfeatures->extensions & BIT(ext))
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned long hart_get_features(struct sbi_scratch *scratch)
|
static inline char *sbi_hart_extension_id2string(int ext)
|
||||||
{
|
{
|
||||||
struct hart_features *hfeatures =
|
char *estr = NULL;
|
||||||
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
|
||||||
|
|
||||||
return hfeatures->features;
|
switch (ext) {
|
||||||
}
|
case SBI_HART_EXT_SSCOFPMF:
|
||||||
|
estr = "sscofpmf";
|
||||||
static inline char *sbi_hart_feature_id2string(unsigned long feature)
|
|
||||||
{
|
|
||||||
char *fstr = NULL;
|
|
||||||
|
|
||||||
if (!feature)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
switch (feature) {
|
|
||||||
case SBI_HART_HAS_SCOUNTEREN:
|
|
||||||
fstr = "scounteren";
|
|
||||||
break;
|
break;
|
||||||
case SBI_HART_HAS_MCOUNTEREN:
|
case SBI_HART_EXT_TIME:
|
||||||
fstr = "mcounteren";
|
estr = "time";
|
||||||
break;
|
break;
|
||||||
case SBI_HART_HAS_MCOUNTINHIBIT:
|
case SBI_HART_EXT_SMAIA:
|
||||||
fstr = "mcountinhibit";
|
estr = "smaia";
|
||||||
break;
|
break;
|
||||||
case SBI_HART_HAS_SSCOFPMF:
|
case SBI_HART_EXT_SSTC:
|
||||||
fstr = "sscofpmf";
|
estr = "sstc";
|
||||||
break;
|
break;
|
||||||
case SBI_HART_HAS_TIME:
|
case SBI_HART_EXT_SMSTATEEN:
|
||||||
fstr = "time";
|
estr = "smstateen";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fstr;
|
return estr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the hart features in string format
|
* Get the hart extensions in string format
|
||||||
*
|
*
|
||||||
* @param scratch pointer to the HART scratch space
|
* @param scratch pointer to the HART scratch space
|
||||||
* @param features_str pointer to a char array where the features string will be
|
* @param extensions_str pointer to a char array where the extensions string
|
||||||
* updated
|
* will be updated
|
||||||
* @param nfstr length of the features_str. The feature string will be truncated
|
* @param nestr length of the features_str. The feature string will be
|
||||||
* if nfstr is not long enough.
|
* truncated if nestr is not long enough.
|
||||||
*/
|
*/
|
||||||
void sbi_hart_get_features_str(struct sbi_scratch *scratch,
|
void sbi_hart_get_extensions_str(struct sbi_scratch *scratch,
|
||||||
char *features_str, int nfstr)
|
char *extensions_str, int nestr)
|
||||||
{
|
{
|
||||||
unsigned long features, feat = 1UL;
|
struct sbi_hart_features *hfeatures =
|
||||||
|
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
||||||
|
int offset = 0, ext = 0;
|
||||||
char *temp;
|
char *temp;
|
||||||
int offset = 0;
|
|
||||||
|
|
||||||
if (!features_str || nfstr <= 0)
|
if (!extensions_str || nestr <= 0)
|
||||||
return;
|
return;
|
||||||
sbi_memset(features_str, 0, nfstr);
|
sbi_memset(extensions_str, 0, nestr);
|
||||||
|
|
||||||
features = hart_get_features(scratch);
|
if (!hfeatures->extensions)
|
||||||
if (!features)
|
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (features & feat) {
|
if (hfeatures->extensions & BIT(ext)) {
|
||||||
temp = sbi_hart_feature_id2string(feat);
|
temp = sbi_hart_extension_id2string(ext);
|
||||||
if (temp) {
|
if (temp) {
|
||||||
sbi_snprintf(features_str + offset, nfstr,
|
sbi_snprintf(extensions_str + offset,
|
||||||
|
nestr - offset,
|
||||||
"%s,", temp);
|
"%s,", temp);
|
||||||
offset = offset + sbi_strlen(temp) + 1;
|
offset = offset + sbi_strlen(temp) + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
feat = feat << 1;
|
|
||||||
} while (feat <= SBI_HART_HAS_LAST_FEATURE);
|
ext++;
|
||||||
|
} while (ext < SBI_HART_EXT_MAX);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (offset)
|
if (offset)
|
||||||
features_str[offset - 1] = '\0';
|
extensions_str[offset - 1] = '\0';
|
||||||
else
|
else
|
||||||
sbi_strncpy(features_str, "none", nfstr);
|
sbi_strncpy(extensions_str, "none", nestr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned long hart_pmp_get_allowed_addr(void)
|
static unsigned long hart_pmp_get_allowed_addr(void)
|
||||||
@@ -368,7 +546,7 @@ static int hart_pmu_get_allowed_bits(void)
|
|||||||
if (trap.cause)
|
if (trap.cause)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
num_bits = __fls(val) + 1;
|
num_bits = sbi_fls(val) + 1;
|
||||||
#if __riscv_xlen == 32
|
#if __riscv_xlen == 32
|
||||||
csr_write_allowed(CSR_MHPMCOUNTER3H, (ulong)&trap, val);
|
csr_write_allowed(CSR_MHPMCOUNTER3H, (ulong)&trap, val);
|
||||||
if (!trap.cause) {
|
if (!trap.cause) {
|
||||||
@@ -376,34 +554,40 @@ static int hart_pmu_get_allowed_bits(void)
|
|||||||
if (trap.cause)
|
if (trap.cause)
|
||||||
return num_bits;
|
return num_bits;
|
||||||
}
|
}
|
||||||
num_bits += __fls(val) + 1;
|
num_bits += sbi_fls(val) + 1;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return num_bits;
|
return num_bits;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hart_detect_features(struct sbi_scratch *scratch)
|
static int hart_detect_features(struct sbi_scratch *scratch)
|
||||||
{
|
{
|
||||||
struct sbi_trap_info trap = {0};
|
struct sbi_trap_info trap = {0};
|
||||||
struct hart_features *hfeatures;
|
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
|
||||||
unsigned long val;
|
struct sbi_hart_features *hfeatures =
|
||||||
|
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
||||||
|
unsigned long val, oldval;
|
||||||
|
int rc;
|
||||||
|
|
||||||
/* Reset hart features */
|
/* If hart features already detected then do nothing */
|
||||||
hfeatures = sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
if (hfeatures->detected)
|
||||||
hfeatures->features = 0;
|
return 0;
|
||||||
|
|
||||||
|
/* Clear hart features */
|
||||||
|
hfeatures->extensions = 0;
|
||||||
hfeatures->pmp_count = 0;
|
hfeatures->pmp_count = 0;
|
||||||
hfeatures->mhpm_count = 0;
|
hfeatures->mhpm_count = 0;
|
||||||
|
|
||||||
#define __check_csr(__csr, __rdonly, __wrval, __field, __skip) \
|
#define __check_csr(__csr, __rdonly, __wrval, __field, __skip) \
|
||||||
val = csr_read_allowed(__csr, (ulong)&trap); \
|
oldval = csr_read_allowed(__csr, (ulong)&trap); \
|
||||||
if (!trap.cause) { \
|
if (!trap.cause) { \
|
||||||
if (__rdonly) { \
|
if (__rdonly) { \
|
||||||
(hfeatures->__field)++; \
|
(hfeatures->__field)++; \
|
||||||
} else { \
|
} else { \
|
||||||
csr_write_allowed(__csr, (ulong)&trap, __wrval);\
|
csr_write_allowed(__csr, (ulong)&trap, __wrval);\
|
||||||
if (!trap.cause) { \
|
if (!trap.cause) { \
|
||||||
if (csr_swap(__csr, val) == __wrval) \
|
if (csr_swap(__csr, oldval) == __wrval) \
|
||||||
(hfeatures->__field)++; \
|
(hfeatures->__field)++; \
|
||||||
else \
|
else \
|
||||||
goto __skip; \
|
goto __skip; \
|
||||||
@@ -439,8 +623,8 @@ static void hart_detect_features(struct sbi_scratch *scratch)
|
|||||||
*/
|
*/
|
||||||
val = hart_pmp_get_allowed_addr();
|
val = hart_pmp_get_allowed_addr();
|
||||||
if (val) {
|
if (val) {
|
||||||
hfeatures->pmp_gran = 1 << (__ffs(val) + 2);
|
hfeatures->pmp_gran = 1 << (sbi_ffs(val) + 2);
|
||||||
hfeatures->pmp_addr_bits = __fls(val) + 1;
|
hfeatures->pmp_addr_bits = sbi_fls(val) + 1;
|
||||||
/* Detect number of PMP regions. At least PMPADDR0 should be implemented*/
|
/* Detect number of PMP regions. At least PMPADDR0 should be implemented*/
|
||||||
__check_csr_64(CSR_PMPADDR0, 0, val, pmp_count, __pmp_skip);
|
__check_csr_64(CSR_PMPADDR0, 0, val, pmp_count, __pmp_skip);
|
||||||
}
|
}
|
||||||
@@ -469,43 +653,72 @@ __mhpm_skip:
|
|||||||
#undef __check_csr_2
|
#undef __check_csr_2
|
||||||
#undef __check_csr
|
#undef __check_csr
|
||||||
|
|
||||||
/* Detect if hart supports SCOUNTEREN feature */
|
/* Detect if hart supports Priv v1.10 */
|
||||||
val = csr_read_allowed(CSR_SCOUNTEREN, (unsigned long)&trap);
|
|
||||||
if (!trap.cause) {
|
|
||||||
csr_write_allowed(CSR_SCOUNTEREN, (unsigned long)&trap, val);
|
|
||||||
if (!trap.cause)
|
|
||||||
hfeatures->features |= SBI_HART_HAS_SCOUNTEREN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Detect if hart supports MCOUNTEREN feature */
|
|
||||||
val = csr_read_allowed(CSR_MCOUNTEREN, (unsigned long)&trap);
|
val = csr_read_allowed(CSR_MCOUNTEREN, (unsigned long)&trap);
|
||||||
if (!trap.cause) {
|
if (!trap.cause)
|
||||||
csr_write_allowed(CSR_MCOUNTEREN, (unsigned long)&trap, val);
|
hfeatures->priv_version = SBI_HART_PRIV_VER_1_10;
|
||||||
if (!trap.cause)
|
|
||||||
hfeatures->features |= SBI_HART_HAS_MCOUNTEREN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Detect if hart supports MCOUNTINHIBIT feature */
|
/* Detect if hart supports Priv v1.11 */
|
||||||
val = csr_read_allowed(CSR_MCOUNTINHIBIT, (unsigned long)&trap);
|
val = csr_read_allowed(CSR_MCOUNTINHIBIT, (unsigned long)&trap);
|
||||||
if (!trap.cause) {
|
if (!trap.cause &&
|
||||||
csr_write_allowed(CSR_MCOUNTINHIBIT, (unsigned long)&trap, val);
|
(hfeatures->priv_version >= SBI_HART_PRIV_VER_1_10))
|
||||||
if (!trap.cause)
|
hfeatures->priv_version = SBI_HART_PRIV_VER_1_11;
|
||||||
hfeatures->features |= SBI_HART_HAS_MCOUNTINHIBIT;
|
|
||||||
}
|
/* Detect if hart supports Priv v1.12 */
|
||||||
|
csr_read_allowed(CSR_MENVCFG, (unsigned long)&trap);
|
||||||
|
if (!trap.cause &&
|
||||||
|
(hfeatures->priv_version >= SBI_HART_PRIV_VER_1_11))
|
||||||
|
hfeatures->priv_version = SBI_HART_PRIV_VER_1_12;
|
||||||
|
|
||||||
/* Counter overflow/filtering is not useful without mcounter/inhibit */
|
/* Counter overflow/filtering is not useful without mcounter/inhibit */
|
||||||
if (hfeatures->features & SBI_HART_HAS_MCOUNTINHIBIT &&
|
if (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) {
|
||||||
hfeatures->features & SBI_HART_HAS_MCOUNTEREN) {
|
|
||||||
/* Detect if hart supports sscofpmf */
|
/* Detect if hart supports sscofpmf */
|
||||||
csr_read_allowed(CSR_SCOUNTOVF, (unsigned long)&trap);
|
csr_read_allowed(CSR_SCOUNTOVF, (unsigned long)&trap);
|
||||||
if (!trap.cause)
|
if (!trap.cause)
|
||||||
hfeatures->features |= SBI_HART_HAS_SSCOFPMF;
|
__sbi_hart_update_extension(hfeatures,
|
||||||
|
SBI_HART_EXT_SSCOFPMF, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Detect if hart supports time CSR */
|
/* Detect if hart supports time CSR */
|
||||||
csr_read_allowed(CSR_TIME, (unsigned long)&trap);
|
if (!sbi_platform_force_emulate_time_csr(plat)) {
|
||||||
|
csr_read_allowed(CSR_TIME, (unsigned long)&trap);
|
||||||
|
if (!trap.cause)
|
||||||
|
__sbi_hart_update_extension(hfeatures,
|
||||||
|
SBI_HART_EXT_TIME, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Detect if hart has AIA local interrupt CSRs */
|
||||||
|
csr_read_allowed(CSR_MTOPI, (unsigned long)&trap);
|
||||||
if (!trap.cause)
|
if (!trap.cause)
|
||||||
hfeatures->features |= SBI_HART_HAS_TIME;
|
__sbi_hart_update_extension(hfeatures,
|
||||||
|
SBI_HART_EXT_SMAIA, true);
|
||||||
|
|
||||||
|
/* Detect if hart supports stimecmp CSR(Sstc extension) */
|
||||||
|
if (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) {
|
||||||
|
csr_read_allowed(CSR_STIMECMP, (unsigned long)&trap);
|
||||||
|
if (!trap.cause)
|
||||||
|
__sbi_hart_update_extension(hfeatures,
|
||||||
|
SBI_HART_EXT_SSTC, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Detect if hart supports mstateen CSRs */
|
||||||
|
if (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) {
|
||||||
|
val = csr_read_allowed(CSR_MSTATEEN0, (unsigned long)&trap);
|
||||||
|
if (!trap.cause)
|
||||||
|
__sbi_hart_update_extension(hfeatures,
|
||||||
|
SBI_HART_EXT_SMSTATEEN, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Let platform populate extensions */
|
||||||
|
rc = sbi_platform_extensions_init(sbi_platform_thishart_ptr(),
|
||||||
|
hfeatures);
|
||||||
|
if (rc)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
/* Mark hart feature detection done */
|
||||||
|
hfeatures->detected = true;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sbi_hart_reinit(struct sbi_scratch *scratch)
|
int sbi_hart_reinit(struct sbi_scratch *scratch)
|
||||||
@@ -527,17 +740,21 @@ int sbi_hart_reinit(struct sbi_scratch *scratch)
|
|||||||
|
|
||||||
int sbi_hart_init(struct sbi_scratch *scratch, bool cold_boot)
|
int sbi_hart_init(struct sbi_scratch *scratch, bool cold_boot)
|
||||||
{
|
{
|
||||||
|
int rc;
|
||||||
|
|
||||||
if (cold_boot) {
|
if (cold_boot) {
|
||||||
if (misa_extension('H'))
|
if (misa_extension('H'))
|
||||||
sbi_hart_expected_trap = &__sbi_expected_trap_hext;
|
sbi_hart_expected_trap = &__sbi_expected_trap_hext;
|
||||||
|
|
||||||
hart_features_offset = sbi_scratch_alloc_offset(
|
hart_features_offset = sbi_scratch_alloc_offset(
|
||||||
sizeof(struct hart_features));
|
sizeof(struct sbi_hart_features));
|
||||||
if (!hart_features_offset)
|
if (!hart_features_offset)
|
||||||
return SBI_ENOMEM;
|
return SBI_ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
hart_detect_features(scratch);
|
rc = hart_detect_features(scratch);
|
||||||
|
if (rc)
|
||||||
|
return rc;
|
||||||
|
|
||||||
return sbi_hart_reinit(scratch);
|
return sbi_hart_reinit(scratch);
|
||||||
}
|
}
|
||||||
@@ -581,19 +798,12 @@ sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,
|
|||||||
#if __riscv_xlen == 32
|
#if __riscv_xlen == 32
|
||||||
if (misa_extension('H')) {
|
if (misa_extension('H')) {
|
||||||
valH = csr_read(CSR_MSTATUSH);
|
valH = csr_read(CSR_MSTATUSH);
|
||||||
if (next_virt)
|
valH = INSERT_FIELD(valH, MSTATUSH_MPV, next_virt);
|
||||||
valH = INSERT_FIELD(valH, MSTATUSH_MPV, 1);
|
|
||||||
else
|
|
||||||
valH = INSERT_FIELD(valH, MSTATUSH_MPV, 0);
|
|
||||||
csr_write(CSR_MSTATUSH, valH);
|
csr_write(CSR_MSTATUSH, valH);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (misa_extension('H')) {
|
if (misa_extension('H'))
|
||||||
if (next_virt)
|
val = INSERT_FIELD(val, MSTATUS_MPV, next_virt);
|
||||||
val = INSERT_FIELD(val, MSTATUS_MPV, 1);
|
|
||||||
else
|
|
||||||
val = INSERT_FIELD(val, MSTATUS_MPV, 0);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
csr_write(CSR_MSTATUS, val);
|
csr_write(CSR_MSTATUS, val);
|
||||||
csr_write(CSR_MEPC, next_addr);
|
csr_write(CSR_MEPC, next_addr);
|
||||||
|
|||||||
@@ -26,6 +26,15 @@
|
|||||||
#include <sbi/sbi_timer.h>
|
#include <sbi/sbi_timer.h>
|
||||||
#include <sbi/sbi_console.h>
|
#include <sbi/sbi_console.h>
|
||||||
|
|
||||||
|
#define __sbi_hsm_hart_change_state(hdata, oldstate, newstate) \
|
||||||
|
({ \
|
||||||
|
long state = atomic_cmpxchg(&(hdata)->state, oldstate, newstate); \
|
||||||
|
if (state != (oldstate)) \
|
||||||
|
sbi_printf("%s: ERR: The hart is in invalid state [%lu]\n", \
|
||||||
|
__func__, state); \
|
||||||
|
state == (oldstate); \
|
||||||
|
})
|
||||||
|
|
||||||
static const struct sbi_hsm_device *hsm_dev = NULL;
|
static const struct sbi_hsm_device *hsm_dev = NULL;
|
||||||
static unsigned long hart_data_offset;
|
static unsigned long hart_data_offset;
|
||||||
|
|
||||||
@@ -35,9 +44,18 @@ struct sbi_hsm_data {
|
|||||||
unsigned long suspend_type;
|
unsigned long suspend_type;
|
||||||
unsigned long saved_mie;
|
unsigned long saved_mie;
|
||||||
unsigned long saved_mip;
|
unsigned long saved_mip;
|
||||||
|
atomic_t start_ticket;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline int __sbi_hsm_hart_get_state(u32 hartid)
|
bool sbi_hsm_hart_change_state(struct sbi_scratch *scratch, long oldstate,
|
||||||
|
long newstate)
|
||||||
|
{
|
||||||
|
struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
|
||||||
|
hart_data_offset);
|
||||||
|
return __sbi_hsm_hart_change_state(hdata, oldstate, newstate);
|
||||||
|
}
|
||||||
|
|
||||||
|
int __sbi_hsm_hart_get_state(u32 hartid)
|
||||||
{
|
{
|
||||||
struct sbi_hsm_data *hdata;
|
struct sbi_hsm_data *hdata;
|
||||||
struct sbi_scratch *scratch;
|
struct sbi_scratch *scratch;
|
||||||
@@ -58,6 +76,32 @@ int sbi_hsm_hart_get_state(const struct sbi_domain *dom, u32 hartid)
|
|||||||
return __sbi_hsm_hart_get_state(hartid);
|
return __sbi_hsm_hart_get_state(hartid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Try to acquire the ticket for the given target hart to make sure only
|
||||||
|
* one hart prepares the start of the target hart.
|
||||||
|
* Returns true if the ticket has been acquired, false otherwise.
|
||||||
|
*
|
||||||
|
* The function has "acquire" semantics: no memory operations following it
|
||||||
|
* in the current hart can be seen before it by other harts.
|
||||||
|
* atomic_cmpxchg() provides the memory barriers needed for that.
|
||||||
|
*/
|
||||||
|
static bool hsm_start_ticket_acquire(struct sbi_hsm_data *hdata)
|
||||||
|
{
|
||||||
|
return (atomic_cmpxchg(&hdata->start_ticket, 0, 1) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Release the ticket for the given target hart.
|
||||||
|
*
|
||||||
|
* The function has "release" semantics: no memory operations preceding it
|
||||||
|
* in the current hart can be seen after it by other harts.
|
||||||
|
*/
|
||||||
|
static void hsm_start_ticket_release(struct sbi_hsm_data *hdata)
|
||||||
|
{
|
||||||
|
RISCV_FENCE(rw, w);
|
||||||
|
atomic_write(&hdata->start_ticket, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get ulong HART mask for given HART base ID
|
* Get ulong HART mask for given HART base ID
|
||||||
* @param dom the domain to be used for output HART mask
|
* @param dom the domain to be used for output HART mask
|
||||||
@@ -93,16 +137,25 @@ int sbi_hsm_hart_interruptible_mask(const struct sbi_domain *dom,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sbi_hsm_prepare_next_jump(struct sbi_scratch *scratch, u32 hartid)
|
void __noreturn sbi_hsm_hart_start_finish(struct sbi_scratch *scratch,
|
||||||
|
u32 hartid)
|
||||||
{
|
{
|
||||||
u32 oldstate;
|
unsigned long next_arg1;
|
||||||
|
unsigned long next_addr;
|
||||||
|
unsigned long next_mode;
|
||||||
struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
|
struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
|
||||||
hart_data_offset);
|
hart_data_offset);
|
||||||
|
|
||||||
oldstate = atomic_cmpxchg(&hdata->state, SBI_HSM_STATE_START_PENDING,
|
if (!__sbi_hsm_hart_change_state(hdata, SBI_HSM_STATE_START_PENDING,
|
||||||
SBI_HSM_STATE_STARTED);
|
SBI_HSM_STATE_STARTED))
|
||||||
if (oldstate != SBI_HSM_STATE_START_PENDING)
|
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
|
|
||||||
|
next_arg1 = scratch->next_arg1;
|
||||||
|
next_addr = scratch->next_addr;
|
||||||
|
next_mode = scratch->next_mode;
|
||||||
|
hsm_start_ticket_release(hdata);
|
||||||
|
|
||||||
|
sbi_hart_switch_mode(hartid, next_arg1, next_addr, next_mode, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sbi_hsm_hart_wait(struct sbi_scratch *scratch, u32 hartid)
|
static void sbi_hsm_hart_wait(struct sbi_scratch *scratch, u32 hartid)
|
||||||
@@ -113,10 +166,10 @@ static void sbi_hsm_hart_wait(struct sbi_scratch *scratch, u32 hartid)
|
|||||||
/* Save MIE CSR */
|
/* Save MIE CSR */
|
||||||
saved_mie = csr_read(CSR_MIE);
|
saved_mie = csr_read(CSR_MIE);
|
||||||
|
|
||||||
/* Set MSIE bit to receive IPI */
|
/* Set MSIE and MEIE bits to receive IPI */
|
||||||
csr_set(CSR_MIE, MIP_MSIP);
|
csr_set(CSR_MIE, MIP_MSIP | MIP_MEIP);
|
||||||
|
|
||||||
/* Wait for hart_add call*/
|
/* Wait for state transition requested by sbi_hsm_hart_start() */
|
||||||
while (atomic_read(&hdata->state) != SBI_HSM_STATE_START_PENDING) {
|
while (atomic_read(&hdata->state) != SBI_HSM_STATE_START_PENDING) {
|
||||||
wfi();
|
wfi();
|
||||||
};
|
};
|
||||||
@@ -171,13 +224,19 @@ static int hsm_device_hart_stop(void)
|
|||||||
return SBI_ENOTSUPP;
|
return SBI_ENOTSUPP;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int hsm_device_hart_suspend(u32 suspend_type, ulong raddr)
|
static int hsm_device_hart_suspend(u32 suspend_type)
|
||||||
{
|
{
|
||||||
if (hsm_dev && hsm_dev->hart_suspend)
|
if (hsm_dev && hsm_dev->hart_suspend)
|
||||||
return hsm_dev->hart_suspend(suspend_type, raddr);
|
return hsm_dev->hart_suspend(suspend_type);
|
||||||
return SBI_ENOTSUPP;
|
return SBI_ENOTSUPP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void hsm_device_hart_resume(void)
|
||||||
|
{
|
||||||
|
if (hsm_dev && hsm_dev->hart_resume)
|
||||||
|
hsm_dev->hart_resume();
|
||||||
|
}
|
||||||
|
|
||||||
int sbi_hsm_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot)
|
int sbi_hsm_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot)
|
||||||
{
|
{
|
||||||
u32 i;
|
u32 i;
|
||||||
@@ -201,6 +260,7 @@ int sbi_hsm_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot)
|
|||||||
(i == hartid) ?
|
(i == hartid) ?
|
||||||
SBI_HSM_STATE_START_PENDING :
|
SBI_HSM_STATE_START_PENDING :
|
||||||
SBI_HSM_STATE_STOPPED);
|
SBI_HSM_STATE_STOPPED);
|
||||||
|
ATOMIC_INIT(&hdata->start_ticket, 0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sbi_hsm_hart_wait(scratch, hartid);
|
sbi_hsm_hart_wait(scratch, hartid);
|
||||||
@@ -211,20 +271,17 @@ int sbi_hsm_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot)
|
|||||||
|
|
||||||
void __noreturn sbi_hsm_exit(struct sbi_scratch *scratch)
|
void __noreturn sbi_hsm_exit(struct sbi_scratch *scratch)
|
||||||
{
|
{
|
||||||
u32 hstate;
|
|
||||||
struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
|
struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
|
||||||
hart_data_offset);
|
hart_data_offset);
|
||||||
void (*jump_warmboot)(void) = (void (*)(void))scratch->warmboot_addr;
|
void (*jump_warmboot)(void) = (void (*)(void))scratch->warmboot_addr;
|
||||||
|
|
||||||
hstate = atomic_cmpxchg(&hdata->state, SBI_HSM_STATE_STOP_PENDING,
|
if (!__sbi_hsm_hart_change_state(hdata, SBI_HSM_STATE_STOP_PENDING,
|
||||||
SBI_HSM_STATE_STOPPED);
|
SBI_HSM_STATE_STOPPED))
|
||||||
if (hstate != SBI_HSM_STATE_STOP_PENDING)
|
|
||||||
goto fail_exit;
|
goto fail_exit;
|
||||||
|
|
||||||
if (hsm_device_has_hart_hotplug()) {
|
if (hsm_device_has_hart_hotplug()) {
|
||||||
hsm_device_hart_stop();
|
if (hsm_device_hart_stop() != SBI_ENOTSUPP)
|
||||||
/* It should never reach here */
|
goto fail_exit;
|
||||||
goto fail_exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -242,12 +299,13 @@ fail_exit:
|
|||||||
|
|
||||||
int sbi_hsm_hart_start(struct sbi_scratch *scratch,
|
int sbi_hsm_hart_start(struct sbi_scratch *scratch,
|
||||||
const struct sbi_domain *dom,
|
const struct sbi_domain *dom,
|
||||||
u32 hartid, ulong saddr, ulong smode, ulong priv)
|
u32 hartid, ulong saddr, ulong smode, ulong arg1)
|
||||||
{
|
{
|
||||||
unsigned long init_count;
|
unsigned long init_count;
|
||||||
unsigned int hstate;
|
unsigned int hstate;
|
||||||
struct sbi_scratch *rscratch;
|
struct sbi_scratch *rscratch;
|
||||||
struct sbi_hsm_data *hdata;
|
struct sbi_hsm_data *hdata;
|
||||||
|
int rc;
|
||||||
|
|
||||||
/* For now, we only allow start mode to be S-mode or U-mode. */
|
/* For now, we only allow start mode to be S-mode or U-mode. */
|
||||||
if (smode != PRV_S && smode != PRV_U)
|
if (smode != PRV_S && smode != PRV_U)
|
||||||
@@ -261,37 +319,53 @@ int sbi_hsm_hart_start(struct sbi_scratch *scratch,
|
|||||||
rscratch = sbi_hartid_to_scratch(hartid);
|
rscratch = sbi_hartid_to_scratch(hartid);
|
||||||
if (!rscratch)
|
if (!rscratch)
|
||||||
return SBI_EINVAL;
|
return SBI_EINVAL;
|
||||||
|
|
||||||
hdata = sbi_scratch_offset_ptr(rscratch, hart_data_offset);
|
hdata = sbi_scratch_offset_ptr(rscratch, hart_data_offset);
|
||||||
|
if (!hsm_start_ticket_acquire(hdata))
|
||||||
|
return SBI_EINVAL;
|
||||||
|
|
||||||
|
init_count = sbi_init_count(hartid);
|
||||||
|
rscratch->next_arg1 = arg1;
|
||||||
|
rscratch->next_addr = saddr;
|
||||||
|
rscratch->next_mode = smode;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* atomic_cmpxchg() is an implicit barrier. It makes sure that
|
||||||
|
* other harts see reading of init_count and writing to *rscratch
|
||||||
|
* before hdata->state is set to SBI_HSM_STATE_START_PENDING.
|
||||||
|
*/
|
||||||
hstate = atomic_cmpxchg(&hdata->state, SBI_HSM_STATE_STOPPED,
|
hstate = atomic_cmpxchg(&hdata->state, SBI_HSM_STATE_STOPPED,
|
||||||
SBI_HSM_STATE_START_PENDING);
|
SBI_HSM_STATE_START_PENDING);
|
||||||
if (hstate == SBI_HSM_STATE_STARTED)
|
if (hstate == SBI_HSM_STATE_STARTED) {
|
||||||
return SBI_EALREADY;
|
rc = SBI_EALREADY;
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* if a hart is already transition to start or stop, another start call
|
* if a hart is already transition to start or stop, another start call
|
||||||
* is considered as invalid request.
|
* is considered as invalid request.
|
||||||
*/
|
*/
|
||||||
if (hstate != SBI_HSM_STATE_STOPPED)
|
if (hstate != SBI_HSM_STATE_STOPPED) {
|
||||||
return SBI_EINVAL;
|
rc = SBI_EINVAL;
|
||||||
|
goto err;
|
||||||
init_count = sbi_init_count(hartid);
|
}
|
||||||
rscratch->next_arg1 = priv;
|
|
||||||
rscratch->next_addr = saddr;
|
|
||||||
rscratch->next_mode = smode;
|
|
||||||
|
|
||||||
if (hsm_device_has_hart_hotplug() ||
|
if (hsm_device_has_hart_hotplug() ||
|
||||||
(hsm_device_has_hart_secondary_boot() && !init_count)) {
|
(hsm_device_has_hart_secondary_boot() && !init_count)) {
|
||||||
return hsm_device_hart_start(hartid, scratch->warmboot_addr);
|
rc = hsm_device_hart_start(hartid, scratch->warmboot_addr);
|
||||||
} else {
|
} else {
|
||||||
sbi_ipi_raw_send(hartid);
|
rc = sbi_ipi_raw_send(hartid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
if (!rc)
|
||||||
|
return 0;
|
||||||
|
err:
|
||||||
|
hsm_start_ticket_release(hdata);
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sbi_hsm_hart_stop(struct sbi_scratch *scratch, bool exitnow)
|
int sbi_hsm_hart_stop(struct sbi_scratch *scratch, bool exitnow)
|
||||||
{
|
{
|
||||||
int oldstate;
|
|
||||||
const struct sbi_domain *dom = sbi_domain_thishart_ptr();
|
const struct sbi_domain *dom = sbi_domain_thishart_ptr();
|
||||||
struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
|
struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
|
||||||
hart_data_offset);
|
hart_data_offset);
|
||||||
@@ -299,13 +373,9 @@ int sbi_hsm_hart_stop(struct sbi_scratch *scratch, bool exitnow)
|
|||||||
if (!dom)
|
if (!dom)
|
||||||
return SBI_EFAIL;
|
return SBI_EFAIL;
|
||||||
|
|
||||||
oldstate = atomic_cmpxchg(&hdata->state, SBI_HSM_STATE_STARTED,
|
if (!__sbi_hsm_hart_change_state(hdata, SBI_HSM_STATE_STARTED,
|
||||||
SBI_HSM_STATE_STOP_PENDING);
|
SBI_HSM_STATE_STOP_PENDING))
|
||||||
if (oldstate != SBI_HSM_STATE_STARTED) {
|
|
||||||
sbi_printf("%s: ERR: The hart is in invalid state [%u]\n",
|
|
||||||
__func__, oldstate);
|
|
||||||
return SBI_EFAIL;
|
return SBI_EFAIL;
|
||||||
}
|
|
||||||
|
|
||||||
if (exitnow)
|
if (exitnow)
|
||||||
sbi_exit(scratch);
|
sbi_exit(scratch);
|
||||||
@@ -313,7 +383,7 @@ int sbi_hsm_hart_stop(struct sbi_scratch *scratch, bool exitnow)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __sbi_hsm_suspend_ret_default(struct sbi_scratch *scratch)
|
static int __sbi_hsm_suspend_default(struct sbi_scratch *scratch)
|
||||||
{
|
{
|
||||||
/* Wait for interrupt */
|
/* Wait for interrupt */
|
||||||
wfi();
|
wfi();
|
||||||
@@ -321,7 +391,7 @@ static int __sbi_hsm_suspend_ret_default(struct sbi_scratch *scratch)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __sbi_hsm_suspend_non_ret_save(struct sbi_scratch *scratch)
|
void __sbi_hsm_suspend_non_ret_save(struct sbi_scratch *scratch)
|
||||||
{
|
{
|
||||||
struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
|
struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
|
||||||
hart_data_offset);
|
hart_data_offset);
|
||||||
@@ -350,77 +420,55 @@ static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch)
|
|||||||
hart_data_offset);
|
hart_data_offset);
|
||||||
|
|
||||||
csr_write(CSR_MIE, hdata->saved_mie);
|
csr_write(CSR_MIE, hdata->saved_mie);
|
||||||
csr_write(CSR_MIP, (hdata->saved_mip & (MIP_SSIP | MIP_STIP)));
|
csr_set(CSR_MIP, (hdata->saved_mip & (MIP_SSIP | MIP_STIP)));
|
||||||
}
|
|
||||||
|
|
||||||
static int __sbi_hsm_suspend_non_ret_default(struct sbi_scratch *scratch,
|
|
||||||
ulong raddr)
|
|
||||||
{
|
|
||||||
void (*jump_warmboot)(void) = (void (*)(void))scratch->warmboot_addr;
|
|
||||||
|
|
||||||
/* Wait for interrupt */
|
|
||||||
wfi();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Directly jump to warm reboot to simulate resume from a
|
|
||||||
* non-retentive suspend.
|
|
||||||
*/
|
|
||||||
jump_warmboot();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sbi_hsm_hart_resume_start(struct sbi_scratch *scratch)
|
void sbi_hsm_hart_resume_start(struct sbi_scratch *scratch)
|
||||||
{
|
{
|
||||||
int oldstate;
|
|
||||||
struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
|
struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
|
||||||
hart_data_offset);
|
hart_data_offset);
|
||||||
|
|
||||||
/* If current HART was SUSPENDED then set RESUME_PENDING state */
|
/* If current HART was SUSPENDED then set RESUME_PENDING state */
|
||||||
oldstate = atomic_cmpxchg(&hdata->state, SBI_HSM_STATE_SUSPENDED,
|
if (!__sbi_hsm_hart_change_state(hdata, SBI_HSM_STATE_SUSPENDED,
|
||||||
SBI_HSM_STATE_RESUME_PENDING);
|
SBI_HSM_STATE_RESUME_PENDING))
|
||||||
if (oldstate != SBI_HSM_STATE_SUSPENDED) {
|
|
||||||
sbi_printf("%s: ERR: The hart is in invalid state [%u]\n",
|
|
||||||
__func__, oldstate);
|
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
}
|
|
||||||
|
hsm_device_hart_resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sbi_hsm_hart_resume_finish(struct sbi_scratch *scratch)
|
void __noreturn sbi_hsm_hart_resume_finish(struct sbi_scratch *scratch,
|
||||||
|
u32 hartid)
|
||||||
{
|
{
|
||||||
u32 oldstate;
|
|
||||||
struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
|
struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
|
||||||
hart_data_offset);
|
hart_data_offset);
|
||||||
|
|
||||||
/* If current HART was RESUME_PENDING then set STARTED state */
|
/* If current HART was RESUME_PENDING then set STARTED state */
|
||||||
oldstate = atomic_cmpxchg(&hdata->state, SBI_HSM_STATE_RESUME_PENDING,
|
if (!__sbi_hsm_hart_change_state(hdata, SBI_HSM_STATE_RESUME_PENDING,
|
||||||
SBI_HSM_STATE_STARTED);
|
SBI_HSM_STATE_STARTED))
|
||||||
if (oldstate != SBI_HSM_STATE_RESUME_PENDING) {
|
|
||||||
sbi_printf("%s: ERR: The hart is in invalid state [%u]\n",
|
|
||||||
__func__, oldstate);
|
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Restore some of the M-mode CSRs which we are re-configured by
|
* Restore some of the M-mode CSRs which we are re-configured by
|
||||||
* the warm-boot sequence.
|
* the warm-boot sequence.
|
||||||
*/
|
*/
|
||||||
__sbi_hsm_suspend_non_ret_restore(scratch);
|
__sbi_hsm_suspend_non_ret_restore(scratch);
|
||||||
|
|
||||||
|
sbi_hart_switch_mode(hartid, scratch->next_arg1,
|
||||||
|
scratch->next_addr,
|
||||||
|
scratch->next_mode, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type,
|
int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type,
|
||||||
ulong raddr, ulong rmode, ulong priv)
|
ulong raddr, ulong rmode, ulong arg1)
|
||||||
{
|
{
|
||||||
int oldstate, ret;
|
int ret;
|
||||||
const struct sbi_domain *dom = sbi_domain_thishart_ptr();
|
const struct sbi_domain *dom = sbi_domain_thishart_ptr();
|
||||||
struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
|
struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch,
|
||||||
hart_data_offset);
|
hart_data_offset);
|
||||||
|
|
||||||
/* For now, we only allow suspend from S-mode or U-mode. */
|
|
||||||
|
|
||||||
/* Sanity check on domain assigned to current HART */
|
/* Sanity check on domain assigned to current HART */
|
||||||
if (!dom)
|
if (!dom)
|
||||||
return SBI_EINVAL;
|
return SBI_EFAIL;
|
||||||
|
|
||||||
/* Sanity check on suspend type */
|
/* Sanity check on suspend type */
|
||||||
if (SBI_HSM_SUSPEND_RET_DEFAULT < suspend_type &&
|
if (SBI_HSM_SUSPEND_RET_DEFAULT < suspend_type &&
|
||||||
@@ -432,27 +480,26 @@ int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type,
|
|||||||
|
|
||||||
/* Additional sanity check for non-retentive suspend */
|
/* Additional sanity check for non-retentive suspend */
|
||||||
if (suspend_type & SBI_HSM_SUSP_NON_RET_BIT) {
|
if (suspend_type & SBI_HSM_SUSP_NON_RET_BIT) {
|
||||||
|
/*
|
||||||
|
* For now, we only allow non-retentive suspend from
|
||||||
|
* S-mode or U-mode.
|
||||||
|
*/
|
||||||
if (rmode != PRV_S && rmode != PRV_U)
|
if (rmode != PRV_S && rmode != PRV_U)
|
||||||
return SBI_EINVAL;
|
return SBI_EFAIL;
|
||||||
if (dom && !sbi_domain_check_addr(dom, raddr, rmode,
|
if (dom && !sbi_domain_check_addr(dom, raddr, rmode,
|
||||||
SBI_DOMAIN_EXECUTE))
|
SBI_DOMAIN_EXECUTE))
|
||||||
return SBI_EINVALID_ADDR;
|
return SBI_EINVALID_ADDR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save the resume address and resume mode */
|
/* Save the resume address and resume mode */
|
||||||
scratch->next_arg1 = priv;
|
scratch->next_arg1 = arg1;
|
||||||
scratch->next_addr = raddr;
|
scratch->next_addr = raddr;
|
||||||
scratch->next_mode = rmode;
|
scratch->next_mode = rmode;
|
||||||
|
|
||||||
/* Directly move from STARTED to SUSPENDED state */
|
/* Directly move from STARTED to SUSPENDED state */
|
||||||
oldstate = atomic_cmpxchg(&hdata->state, SBI_HSM_STATE_STARTED,
|
if (!__sbi_hsm_hart_change_state(hdata, SBI_HSM_STATE_STARTED,
|
||||||
SBI_HSM_STATE_SUSPENDED);
|
SBI_HSM_STATE_SUSPENDED))
|
||||||
if (oldstate != SBI_HSM_STATE_STARTED) {
|
return SBI_EFAIL;
|
||||||
sbi_printf("%s: ERR: The hart is in invalid state [%u]\n",
|
|
||||||
__func__, oldstate);
|
|
||||||
ret = SBI_EDENIED;
|
|
||||||
goto fail_restore_state;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Save the suspend type */
|
/* Save the suspend type */
|
||||||
hdata->suspend_type = suspend_type;
|
hdata->suspend_type = suspend_type;
|
||||||
@@ -465,29 +512,35 @@ int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type,
|
|||||||
__sbi_hsm_suspend_non_ret_save(scratch);
|
__sbi_hsm_suspend_non_ret_save(scratch);
|
||||||
|
|
||||||
/* Try platform specific suspend */
|
/* Try platform specific suspend */
|
||||||
ret = hsm_device_hart_suspend(suspend_type, scratch->warmboot_addr);
|
ret = hsm_device_hart_suspend(suspend_type);
|
||||||
if (ret == SBI_ENOTSUPP) {
|
if (ret == SBI_ENOTSUPP) {
|
||||||
/* Try generic implementation of default suspend types */
|
/* Try generic implementation of default suspend types */
|
||||||
if (suspend_type == SBI_HSM_SUSPEND_RET_DEFAULT) {
|
if (suspend_type == SBI_HSM_SUSPEND_RET_DEFAULT ||
|
||||||
ret = __sbi_hsm_suspend_ret_default(scratch);
|
suspend_type == SBI_HSM_SUSPEND_NON_RET_DEFAULT) {
|
||||||
} else if (suspend_type == SBI_HSM_SUSPEND_NON_RET_DEFAULT) {
|
ret = __sbi_hsm_suspend_default(scratch);
|
||||||
ret = __sbi_hsm_suspend_non_ret_default(scratch,
|
|
||||||
scratch->warmboot_addr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fail_restore_state:
|
/*
|
||||||
|
* The platform may have coordinated a retentive suspend, or it may
|
||||||
|
* have exited early from a non-retentive suspend. Either way, the
|
||||||
|
* caller is not expecting a successful return, so jump to the warm
|
||||||
|
* boot entry point to simulate resume from a non-retentive suspend.
|
||||||
|
*/
|
||||||
|
if (ret == 0 && (suspend_type & SBI_HSM_SUSP_NON_RET_BIT)) {
|
||||||
|
void (*jump_warmboot)(void) =
|
||||||
|
(void (*)(void))scratch->warmboot_addr;
|
||||||
|
|
||||||
|
jump_warmboot();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We might have successfully resumed from retentive suspend
|
* We might have successfully resumed from retentive suspend
|
||||||
* or suspend failed. In both cases, we restore state of hart.
|
* or suspend failed. In both cases, we restore state of hart.
|
||||||
*/
|
*/
|
||||||
oldstate = atomic_cmpxchg(&hdata->state, SBI_HSM_STATE_SUSPENDED,
|
if (!__sbi_hsm_hart_change_state(hdata, SBI_HSM_STATE_SUSPENDED,
|
||||||
SBI_HSM_STATE_STARTED);
|
SBI_HSM_STATE_STARTED))
|
||||||
if (oldstate != SBI_HSM_STATE_SUSPENDED) {
|
|
||||||
sbi_printf("%s: ERR: The hart is in invalid state [%u]\n",
|
|
||||||
__func__, oldstate);
|
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sbi/riscv_asm.h>
|
#include <sbi/riscv_asm.h>
|
||||||
|
#include <sbi/riscv_barrier.h>
|
||||||
#include <sbi/riscv_encoding.h>
|
#include <sbi/riscv_encoding.h>
|
||||||
#include <sbi/sbi_bitops.h>
|
#include <sbi/sbi_bitops.h>
|
||||||
#include <sbi/sbi_emulate_csr.h>
|
#include <sbi/sbi_emulate_csr.h>
|
||||||
@@ -16,6 +17,7 @@
|
|||||||
#include <sbi/sbi_pmu.h>
|
#include <sbi/sbi_pmu.h>
|
||||||
#include <sbi/sbi_trap.h>
|
#include <sbi/sbi_trap.h>
|
||||||
#include <sbi/sbi_unpriv.h>
|
#include <sbi/sbi_unpriv.h>
|
||||||
|
#include <sbi/sbi_console.h>
|
||||||
|
|
||||||
typedef int (*illegal_insn_func)(ulong insn, struct sbi_trap_regs *regs);
|
typedef int (*illegal_insn_func)(ulong insn, struct sbi_trap_regs *regs);
|
||||||
|
|
||||||
@@ -28,17 +30,37 @@ static int truly_illegal_insn(ulong insn, struct sbi_trap_regs *regs)
|
|||||||
trap.tval = insn;
|
trap.tval = insn;
|
||||||
trap.tval2 = 0;
|
trap.tval2 = 0;
|
||||||
trap.tinst = 0;
|
trap.tinst = 0;
|
||||||
|
trap.gva = 0;
|
||||||
|
|
||||||
return sbi_trap_redirect(regs, &trap);
|
return sbi_trap_redirect(regs, &trap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int misc_mem_opcode_insn(ulong insn, struct sbi_trap_regs *regs)
|
||||||
|
{
|
||||||
|
/* Errata workaround: emulate `fence.tso` as `fence rw, rw`. */
|
||||||
|
if ((insn & INSN_MASK_FENCE_TSO) == INSN_MATCH_FENCE_TSO) {
|
||||||
|
smp_mb();
|
||||||
|
regs->mepc += 4;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return truly_illegal_insn(insn, regs);
|
||||||
|
}
|
||||||
|
|
||||||
static int system_opcode_insn(ulong insn, struct sbi_trap_regs *regs)
|
static int system_opcode_insn(ulong insn, struct sbi_trap_regs *regs)
|
||||||
{
|
{
|
||||||
int do_write, rs1_num = (insn >> 15) & 0x1f;
|
int do_write, rs1_num = (insn >> 15) & 0x1f;
|
||||||
ulong rs1_val = GET_RS1(insn, regs);
|
ulong rs1_val = GET_RS1(insn, regs);
|
||||||
int csr_num = (u32)insn >> 20;
|
int csr_num = (u32)insn >> 20;
|
||||||
|
ulong prev_mode = (regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT;
|
||||||
ulong csr_val, new_csr_val;
|
ulong csr_val, new_csr_val;
|
||||||
|
|
||||||
|
if (prev_mode == PRV_M) {
|
||||||
|
sbi_printf("%s: Failed to access CSR %#x from M-mode",
|
||||||
|
__func__, csr_num);
|
||||||
|
return SBI_EFAIL;
|
||||||
|
}
|
||||||
|
|
||||||
/* TODO: Ensure that we got CSR read/write instruction */
|
/* TODO: Ensure that we got CSR read/write instruction */
|
||||||
|
|
||||||
if (sbi_emulate_csr_read(csr_num, regs, &csr_val))
|
if (sbi_emulate_csr_read(csr_num, regs, &csr_val))
|
||||||
@@ -80,11 +102,11 @@ static int system_opcode_insn(ulong insn, struct sbi_trap_regs *regs)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static illegal_insn_func illegal_insn_table[32] = {
|
static const illegal_insn_func illegal_insn_table[32] = {
|
||||||
truly_illegal_insn, /* 0 */
|
truly_illegal_insn, /* 0 */
|
||||||
truly_illegal_insn, /* 1 */
|
truly_illegal_insn, /* 1 */
|
||||||
truly_illegal_insn, /* 2 */
|
truly_illegal_insn, /* 2 */
|
||||||
truly_illegal_insn, /* 3 */
|
misc_mem_opcode_insn, /* 3 */
|
||||||
truly_illegal_insn, /* 4 */
|
truly_illegal_insn, /* 4 */
|
||||||
truly_illegal_insn, /* 5 */
|
truly_illegal_insn, /* 5 */
|
||||||
truly_illegal_insn, /* 6 */
|
truly_illegal_insn, /* 6 */
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <sbi/sbi_hartmask.h>
|
#include <sbi/sbi_hartmask.h>
|
||||||
#include <sbi/sbi_hsm.h>
|
#include <sbi/sbi_hsm.h>
|
||||||
#include <sbi/sbi_ipi.h>
|
#include <sbi/sbi_ipi.h>
|
||||||
|
#include <sbi/sbi_irqchip.h>
|
||||||
#include <sbi/sbi_platform.h>
|
#include <sbi/sbi_platform.h>
|
||||||
#include <sbi/sbi_pmu.h>
|
#include <sbi/sbi_pmu.h>
|
||||||
#include <sbi/sbi_system.h>
|
#include <sbi/sbi_system.h>
|
||||||
@@ -62,11 +63,13 @@ static void sbi_boot_print_banner(struct sbi_scratch *scratch)
|
|||||||
static void sbi_boot_print_general(struct sbi_scratch *scratch)
|
static void sbi_boot_print_general(struct sbi_scratch *scratch)
|
||||||
{
|
{
|
||||||
char str[128];
|
char str[128];
|
||||||
|
const struct sbi_pmu_device *pdev;
|
||||||
const struct sbi_hsm_device *hdev;
|
const struct sbi_hsm_device *hdev;
|
||||||
const struct sbi_ipi_device *idev;
|
const struct sbi_ipi_device *idev;
|
||||||
const struct sbi_timer_device *tdev;
|
const struct sbi_timer_device *tdev;
|
||||||
const struct sbi_console_device *cdev;
|
const struct sbi_console_device *cdev;
|
||||||
const struct sbi_system_reset_device *srdev;
|
const struct sbi_system_reset_device *srdev;
|
||||||
|
const struct sbi_system_suspend_device *susp_dev;
|
||||||
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
|
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
|
||||||
|
|
||||||
if (scratch->options & SBI_SCRATCH_NO_BOOT_PRINTS)
|
if (scratch->options & SBI_SCRATCH_NO_BOOT_PRINTS)
|
||||||
@@ -92,17 +95,24 @@ static void sbi_boot_print_general(struct sbi_scratch *scratch)
|
|||||||
hdev = sbi_hsm_get_device();
|
hdev = sbi_hsm_get_device();
|
||||||
sbi_printf("Platform HSM Device : %s\n",
|
sbi_printf("Platform HSM Device : %s\n",
|
||||||
(hdev) ? hdev->name : "---");
|
(hdev) ? hdev->name : "---");
|
||||||
|
pdev = sbi_pmu_get_device();
|
||||||
|
sbi_printf("Platform PMU Device : %s\n",
|
||||||
|
(pdev) ? pdev->name : "---");
|
||||||
srdev = sbi_system_reset_get_device(SBI_SRST_RESET_TYPE_COLD_REBOOT, 0);
|
srdev = sbi_system_reset_get_device(SBI_SRST_RESET_TYPE_COLD_REBOOT, 0);
|
||||||
sbi_printf("Platform Reboot Device : %s\n",
|
sbi_printf("Platform Reboot Device : %s\n",
|
||||||
(srdev) ? srdev->name : "---");
|
(srdev) ? srdev->name : "---");
|
||||||
srdev = sbi_system_reset_get_device(SBI_SRST_RESET_TYPE_SHUTDOWN, 0);
|
srdev = sbi_system_reset_get_device(SBI_SRST_RESET_TYPE_SHUTDOWN, 0);
|
||||||
sbi_printf("Platform Shutdown Device : %s\n",
|
sbi_printf("Platform Shutdown Device : %s\n",
|
||||||
(srdev) ? srdev->name : "---");
|
(srdev) ? srdev->name : "---");
|
||||||
|
susp_dev = sbi_system_suspend_get_device();
|
||||||
|
sbi_printf("Platform Suspend Device : %s\n",
|
||||||
|
(susp_dev) ? susp_dev->name : "---");
|
||||||
|
|
||||||
/* 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));
|
||||||
|
sbi_printf("Firmware RW Offset : 0x%lx\n", scratch->fw_rw_offset);
|
||||||
|
|
||||||
/* SBI details */
|
/* SBI details */
|
||||||
sbi_printf("Runtime SBI Version : %d.%d\n",
|
sbi_printf("Runtime SBI Version : %d.%d\n",
|
||||||
@@ -138,10 +148,12 @@ static void sbi_boot_print_hart(struct sbi_scratch *scratch, u32 hartid)
|
|||||||
/* Boot HART details */
|
/* Boot HART details */
|
||||||
sbi_printf("Boot HART ID : %u\n", hartid);
|
sbi_printf("Boot HART ID : %u\n", hartid);
|
||||||
sbi_printf("Boot HART Domain : %s\n", dom->name);
|
sbi_printf("Boot HART Domain : %s\n", dom->name);
|
||||||
|
sbi_hart_get_priv_version_str(scratch, str, sizeof(str));
|
||||||
|
sbi_printf("Boot HART Priv Version : %s\n", str);
|
||||||
misa_string(xlen, str, sizeof(str));
|
misa_string(xlen, str, sizeof(str));
|
||||||
sbi_printf("Boot HART ISA : %s\n", str);
|
sbi_printf("Boot HART Base ISA : %s\n", str);
|
||||||
sbi_hart_get_features_str(scratch, str, sizeof(str));
|
sbi_hart_get_extensions_str(scratch, str, sizeof(str));
|
||||||
sbi_printf("Boot HART Features : %s\n", str);
|
sbi_printf("Boot HART ISA Extensions : %s\n", str);
|
||||||
sbi_printf("Boot HART PMP Count : %d\n",
|
sbi_printf("Boot HART PMP Count : %d\n",
|
||||||
sbi_hart_pmp_count(scratch));
|
sbi_hart_pmp_count(scratch));
|
||||||
sbi_printf("Boot HART PMP Granularity : %lu\n",
|
sbi_printf("Boot HART PMP Granularity : %lu\n",
|
||||||
@@ -165,8 +177,8 @@ static void wait_for_coldboot(struct sbi_scratch *scratch, u32 hartid)
|
|||||||
/* Save MIE CSR */
|
/* Save MIE CSR */
|
||||||
saved_mie = csr_read(CSR_MIE);
|
saved_mie = csr_read(CSR_MIE);
|
||||||
|
|
||||||
/* Set MSIE bit to receive IPI */
|
/* Set MSIE and MEIE bits to receive IPI */
|
||||||
csr_set(CSR_MIE, MIP_MSIP);
|
csr_set(CSR_MIE, MIP_MSIP | MIP_MEIP);
|
||||||
|
|
||||||
/* Acquire coldboot lock */
|
/* Acquire coldboot lock */
|
||||||
spin_lock(&coldboot_lock);
|
spin_lock(&coldboot_lock);
|
||||||
@@ -182,7 +194,7 @@ static void wait_for_coldboot(struct sbi_scratch *scratch, u32 hartid)
|
|||||||
do {
|
do {
|
||||||
wfi();
|
wfi();
|
||||||
cmip = csr_read(CSR_MIP);
|
cmip = csr_read(CSR_MIP);
|
||||||
} while (!(cmip & MIP_MSIP));
|
} while (!(cmip & (MIP_MSIP | MIP_MEIP)));
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Acquire coldboot lock */
|
/* Acquire coldboot lock */
|
||||||
@@ -248,15 +260,15 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
|
|||||||
if (!init_count_offset)
|
if (!init_count_offset)
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
|
|
||||||
rc = sbi_hsm_init(scratch, hartid, TRUE);
|
rc = sbi_hsm_init(scratch, hartid, true);
|
||||||
if (rc)
|
if (rc)
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
|
|
||||||
rc = sbi_platform_early_init(plat, TRUE);
|
rc = sbi_platform_early_init(plat, true);
|
||||||
if (rc)
|
if (rc)
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
|
|
||||||
rc = sbi_hart_init(scratch, TRUE);
|
rc = sbi_hart_init(scratch, true);
|
||||||
if (rc)
|
if (rc)
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
|
|
||||||
@@ -264,32 +276,32 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
|
|||||||
if (rc)
|
if (rc)
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
|
|
||||||
rc = sbi_pmu_init(scratch, TRUE);
|
rc = sbi_pmu_init(scratch, true);
|
||||||
if (rc)
|
if (rc)
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
|
|
||||||
sbi_boot_print_banner(scratch);
|
sbi_boot_print_banner(scratch);
|
||||||
|
|
||||||
rc = sbi_platform_irqchip_init(plat, TRUE);
|
rc = sbi_irqchip_init(scratch, true);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
sbi_printf("%s: platform irqchip init failed (error %d)\n",
|
sbi_printf("%s: irqchip init failed (error %d)\n",
|
||||||
__func__, rc);
|
__func__, rc);
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = sbi_ipi_init(scratch, TRUE);
|
rc = sbi_ipi_init(scratch, true);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
sbi_printf("%s: ipi init failed (error %d)\n", __func__, rc);
|
sbi_printf("%s: ipi init failed (error %d)\n", __func__, rc);
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = sbi_tlb_init(scratch, TRUE);
|
rc = sbi_tlb_init(scratch, true);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
sbi_printf("%s: tlb init failed (error %d)\n", __func__, rc);
|
sbi_printf("%s: tlb init failed (error %d)\n", __func__, rc);
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = sbi_timer_init(scratch, TRUE);
|
rc = sbi_timer_init(scratch, true);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
sbi_printf("%s: timer init failed (error %d)\n", __func__, rc);
|
sbi_printf("%s: timer init failed (error %d)\n", __func__, rc);
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
@@ -325,7 +337,7 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
|
|||||||
* Note: Platform final initialization should be last so that
|
* Note: Platform final initialization should be last so that
|
||||||
* it sees correct domain assignment and PMP configuration.
|
* it sees correct domain assignment and PMP configuration.
|
||||||
*/
|
*/
|
||||||
rc = sbi_platform_final_init(plat, TRUE);
|
rc = sbi_platform_final_init(plat, true);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
sbi_printf("%s: platform final init failed (error %d)\n",
|
sbi_printf("%s: platform final init failed (error %d)\n",
|
||||||
__func__, rc);
|
__func__, rc);
|
||||||
@@ -343,12 +355,11 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
|
|||||||
init_count = sbi_scratch_offset_ptr(scratch, init_count_offset);
|
init_count = sbi_scratch_offset_ptr(scratch, init_count_offset);
|
||||||
(*init_count)++;
|
(*init_count)++;
|
||||||
|
|
||||||
sbi_hsm_prepare_next_jump(scratch, hartid);
|
sbi_hsm_hart_start_finish(scratch, hartid);
|
||||||
sbi_hart_switch_mode(hartid, scratch->next_arg1, scratch->next_addr,
|
|
||||||
scratch->next_mode, FALSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_warm_startup(struct sbi_scratch *scratch, u32 hartid)
|
static void __noreturn init_warm_startup(struct sbi_scratch *scratch,
|
||||||
|
u32 hartid)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
unsigned long *init_count;
|
unsigned long *init_count;
|
||||||
@@ -357,35 +368,35 @@ static void init_warm_startup(struct sbi_scratch *scratch, u32 hartid)
|
|||||||
if (!init_count_offset)
|
if (!init_count_offset)
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
|
|
||||||
rc = sbi_hsm_init(scratch, hartid, FALSE);
|
rc = sbi_hsm_init(scratch, hartid, false);
|
||||||
if (rc)
|
if (rc)
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
|
|
||||||
rc = sbi_platform_early_init(plat, FALSE);
|
rc = sbi_platform_early_init(plat, false);
|
||||||
if (rc)
|
if (rc)
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
|
|
||||||
rc = sbi_hart_init(scratch, FALSE);
|
rc = sbi_hart_init(scratch, false);
|
||||||
if (rc)
|
if (rc)
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
|
|
||||||
rc = sbi_pmu_init(scratch, FALSE);
|
rc = sbi_pmu_init(scratch, false);
|
||||||
if (rc)
|
if (rc)
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
|
|
||||||
rc = sbi_platform_irqchip_init(plat, FALSE);
|
rc = sbi_irqchip_init(scratch, false);
|
||||||
if (rc)
|
if (rc)
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
|
|
||||||
rc = sbi_ipi_init(scratch, FALSE);
|
rc = sbi_ipi_init(scratch, false);
|
||||||
if (rc)
|
if (rc)
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
|
|
||||||
rc = sbi_tlb_init(scratch, FALSE);
|
rc = sbi_tlb_init(scratch, false);
|
||||||
if (rc)
|
if (rc)
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
|
|
||||||
rc = sbi_timer_init(scratch, FALSE);
|
rc = sbi_timer_init(scratch, false);
|
||||||
if (rc)
|
if (rc)
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
|
|
||||||
@@ -393,17 +404,18 @@ static void init_warm_startup(struct sbi_scratch *scratch, u32 hartid)
|
|||||||
if (rc)
|
if (rc)
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
|
|
||||||
rc = sbi_platform_final_init(plat, FALSE);
|
rc = sbi_platform_final_init(plat, false);
|
||||||
if (rc)
|
if (rc)
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
|
|
||||||
init_count = sbi_scratch_offset_ptr(scratch, init_count_offset);
|
init_count = sbi_scratch_offset_ptr(scratch, init_count_offset);
|
||||||
(*init_count)++;
|
(*init_count)++;
|
||||||
|
|
||||||
sbi_hsm_prepare_next_jump(scratch, hartid);
|
sbi_hsm_hart_start_finish(scratch, hartid);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_warm_resume(struct sbi_scratch *scratch)
|
static void __noreturn init_warm_resume(struct sbi_scratch *scratch,
|
||||||
|
u32 hartid)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
@@ -417,7 +429,7 @@ static void init_warm_resume(struct sbi_scratch *scratch)
|
|||||||
if (rc)
|
if (rc)
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
|
|
||||||
sbi_hsm_hart_resume_finish(scratch);
|
sbi_hsm_hart_resume_finish(scratch, hartid);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __noreturn init_warmboot(struct sbi_scratch *scratch, u32 hartid)
|
static void __noreturn init_warmboot(struct sbi_scratch *scratch, u32 hartid)
|
||||||
@@ -430,14 +442,12 @@ static void __noreturn init_warmboot(struct sbi_scratch *scratch, u32 hartid)
|
|||||||
if (hstate < 0)
|
if (hstate < 0)
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
|
|
||||||
if (hstate == SBI_HSM_STATE_SUSPENDED)
|
if (hstate == SBI_HSM_STATE_SUSPENDED) {
|
||||||
init_warm_resume(scratch);
|
init_warm_resume(scratch, hartid);
|
||||||
else
|
} else {
|
||||||
|
sbi_ipi_raw_clear(hartid);
|
||||||
init_warm_startup(scratch, hartid);
|
init_warm_startup(scratch, hartid);
|
||||||
|
}
|
||||||
sbi_hart_switch_mode(hartid, scratch->next_arg1,
|
|
||||||
scratch->next_addr,
|
|
||||||
scratch->next_mode, FALSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static atomic_t coldboot_lottery = ATOMIC_INITIALIZER(0);
|
static atomic_t coldboot_lottery = ATOMIC_INITIALIZER(0);
|
||||||
@@ -456,8 +466,8 @@ static atomic_t coldboot_lottery = ATOMIC_INITIALIZER(0);
|
|||||||
*/
|
*/
|
||||||
void __noreturn sbi_init(struct sbi_scratch *scratch)
|
void __noreturn sbi_init(struct sbi_scratch *scratch)
|
||||||
{
|
{
|
||||||
bool next_mode_supported = FALSE;
|
bool next_mode_supported = false;
|
||||||
bool coldboot = FALSE;
|
bool coldboot = false;
|
||||||
u32 hartid = current_hartid();
|
u32 hartid = current_hartid();
|
||||||
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
|
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
|
||||||
|
|
||||||
@@ -467,15 +477,15 @@ void __noreturn sbi_init(struct sbi_scratch *scratch)
|
|||||||
|
|
||||||
switch (scratch->next_mode) {
|
switch (scratch->next_mode) {
|
||||||
case PRV_M:
|
case PRV_M:
|
||||||
next_mode_supported = TRUE;
|
next_mode_supported = true;
|
||||||
break;
|
break;
|
||||||
case PRV_S:
|
case PRV_S:
|
||||||
if (misa_extension('S'))
|
if (misa_extension('S'))
|
||||||
next_mode_supported = TRUE;
|
next_mode_supported = true;
|
||||||
break;
|
break;
|
||||||
case PRV_U:
|
case PRV_U:
|
||||||
if (misa_extension('U'))
|
if (misa_extension('U'))
|
||||||
next_mode_supported = TRUE;
|
next_mode_supported = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sbi_hart_hang();
|
sbi_hart_hang();
|
||||||
@@ -491,8 +501,19 @@ void __noreturn sbi_init(struct sbi_scratch *scratch)
|
|||||||
* HARTs which satisfy above condition.
|
* HARTs which satisfy above condition.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (next_mode_supported && atomic_xchg(&coldboot_lottery, 1) == 0)
|
if (sbi_platform_cold_boot_allowed(plat, hartid)) {
|
||||||
coldboot = TRUE;
|
if (next_mode_supported &&
|
||||||
|
atomic_xchg(&coldboot_lottery, 1) == 0)
|
||||||
|
coldboot = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Do platform specific nascent (very early) initialization so
|
||||||
|
* that platform can initialize platform specific per-HART CSRs
|
||||||
|
* or per-HART devices.
|
||||||
|
*/
|
||||||
|
if (sbi_platform_nascent_init(plat))
|
||||||
|
sbi_hart_hang();
|
||||||
|
|
||||||
if (coldboot)
|
if (coldboot)
|
||||||
init_coldboot(scratch, hartid);
|
init_coldboot(scratch, hartid);
|
||||||
@@ -542,7 +563,7 @@ void __noreturn sbi_exit(struct sbi_scratch *scratch)
|
|||||||
|
|
||||||
sbi_ipi_exit(scratch);
|
sbi_ipi_exit(scratch);
|
||||||
|
|
||||||
sbi_platform_irqchip_exit(plat);
|
sbi_irqchip_exit(scratch);
|
||||||
|
|
||||||
sbi_platform_final_exit(plat);
|
sbi_platform_final_exit(plat);
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include <sbi/sbi_domain.h>
|
#include <sbi/sbi_domain.h>
|
||||||
#include <sbi/sbi_error.h>
|
#include <sbi/sbi_error.h>
|
||||||
#include <sbi/sbi_hart.h>
|
#include <sbi/sbi_hart.h>
|
||||||
|
#include <sbi/sbi_hartmask.h>
|
||||||
#include <sbi/sbi_hsm.h>
|
#include <sbi/sbi_hsm.h>
|
||||||
#include <sbi/sbi_init.h>
|
#include <sbi/sbi_init.h>
|
||||||
#include <sbi/sbi_ipi.h>
|
#include <sbi/sbi_ipi.h>
|
||||||
@@ -31,7 +32,7 @@ static unsigned long ipi_data_off;
|
|||||||
static const struct sbi_ipi_device *ipi_dev = NULL;
|
static const struct sbi_ipi_device *ipi_dev = NULL;
|
||||||
static const struct sbi_ipi_event_ops *ipi_ops_array[SBI_IPI_EVENT_MAX];
|
static const struct sbi_ipi_event_ops *ipi_ops_array[SBI_IPI_EVENT_MAX];
|
||||||
|
|
||||||
static int sbi_ipi_send(struct sbi_scratch *scratch, u32 remote_hartid,
|
static int sbi_ipi_update(struct sbi_scratch *scratch, u32 remote_hartid,
|
||||||
u32 event, void *data)
|
u32 event, void *data)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
@@ -69,6 +70,18 @@ static int sbi_ipi_send(struct sbi_scratch *scratch, u32 remote_hartid,
|
|||||||
|
|
||||||
sbi_pmu_ctr_incr_fw(SBI_PMU_FW_IPI_SENT);
|
sbi_pmu_ctr_incr_fw(SBI_PMU_FW_IPI_SENT);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int sbi_ipi_sync(struct sbi_scratch *scratch, u32 event)
|
||||||
|
{
|
||||||
|
const struct sbi_ipi_event_ops *ipi_ops;
|
||||||
|
|
||||||
|
if ((SBI_IPI_EVENT_MAX <= event) ||
|
||||||
|
!ipi_ops_array[event])
|
||||||
|
return SBI_EINVAL;
|
||||||
|
ipi_ops = ipi_ops_array[event];
|
||||||
|
|
||||||
if (ipi_ops->sync)
|
if (ipi_ops->sync)
|
||||||
ipi_ops->sync(scratch);
|
ipi_ops->sync(scratch);
|
||||||
|
|
||||||
@@ -82,8 +95,10 @@ static int sbi_ipi_send(struct sbi_scratch *scratch, u32 remote_hartid,
|
|||||||
*/
|
*/
|
||||||
int sbi_ipi_send_many(ulong hmask, ulong hbase, u32 event, void *data)
|
int sbi_ipi_send_many(ulong hmask, ulong hbase, u32 event, void *data)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc, done;
|
||||||
ulong i, m;
|
ulong i, m;
|
||||||
|
struct sbi_hartmask target_mask = {0};
|
||||||
|
struct sbi_hartmask retry_mask = {0};
|
||||||
struct sbi_domain *dom = sbi_domain_thishart_ptr();
|
struct sbi_domain *dom = sbi_domain_thishart_ptr();
|
||||||
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
||||||
|
|
||||||
@@ -93,23 +108,36 @@ int sbi_ipi_send_many(ulong hmask, ulong hbase, u32 event, void *data)
|
|||||||
return rc;
|
return rc;
|
||||||
m &= hmask;
|
m &= hmask;
|
||||||
|
|
||||||
/* Send IPIs */
|
|
||||||
for (i = hbase; m; i++, m >>= 1) {
|
for (i = hbase; m; i++, m >>= 1) {
|
||||||
if (m & 1UL)
|
if (m & 1UL)
|
||||||
sbi_ipi_send(scratch, i, event, data);
|
sbi_hartmask_set_hart(i, &target_mask);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
hbase = 0;
|
hbase = 0;
|
||||||
while (!sbi_hsm_hart_interruptible_mask(dom, hbase, &m)) {
|
while (!sbi_hsm_hart_interruptible_mask(dom, hbase, &m)) {
|
||||||
/* Send IPIs */
|
|
||||||
for (i = hbase; m; i++, m >>= 1) {
|
for (i = hbase; m; i++, m >>= 1) {
|
||||||
if (m & 1UL)
|
if (m & 1UL)
|
||||||
sbi_ipi_send(scratch, i, event, data);
|
sbi_hartmask_set_hart(i, &target_mask);
|
||||||
}
|
}
|
||||||
hbase += BITS_PER_LONG;
|
hbase += BITS_PER_LONG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retry_mask = target_mask;
|
||||||
|
do {
|
||||||
|
done = true;
|
||||||
|
sbi_hartmask_for_each_hart(i, &retry_mask) {
|
||||||
|
rc = sbi_ipi_update(scratch, i, event, data);
|
||||||
|
if (rc == -2)
|
||||||
|
done = false;
|
||||||
|
else
|
||||||
|
sbi_hartmask_clear_hart(i, &retry_mask);
|
||||||
|
}
|
||||||
|
} while (!done);
|
||||||
|
|
||||||
|
/* sync IPIs */
|
||||||
|
sbi_ipi_sync(scratch, event);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +191,7 @@ void sbi_ipi_clear_smode(void)
|
|||||||
|
|
||||||
static void sbi_ipi_process_halt(struct sbi_scratch *scratch)
|
static void sbi_ipi_process_halt(struct sbi_scratch *scratch)
|
||||||
{
|
{
|
||||||
sbi_hsm_hart_stop(scratch, TRUE);
|
sbi_hsm_hart_stop(scratch, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct sbi_ipi_event_ops ipi_halt_ops = {
|
static struct sbi_ipi_event_ops ipi_halt_ops = {
|
||||||
@@ -208,10 +236,19 @@ skip:
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void sbi_ipi_raw_send(u32 target_hart)
|
int sbi_ipi_raw_send(u32 target_hart)
|
||||||
{
|
{
|
||||||
if (ipi_dev && ipi_dev->ipi_send)
|
if (!ipi_dev || !ipi_dev->ipi_send)
|
||||||
ipi_dev->ipi_send(target_hart);
|
return SBI_EINVAL;
|
||||||
|
|
||||||
|
ipi_dev->ipi_send(target_hart);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sbi_ipi_raw_clear(u32 target_hart)
|
||||||
|
{
|
||||||
|
if (ipi_dev && ipi_dev->ipi_clear)
|
||||||
|
ipi_dev->ipi_clear(target_hart);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct sbi_ipi_device *sbi_ipi_get_device(void)
|
const struct sbi_ipi_device *sbi_ipi_get_device(void)
|
||||||
|
|||||||
54
lib/sbi/sbi_irqchip.c
Normal file
54
lib/sbi/sbi_irqchip.c
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022 Ventana Micro Systems Inc.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Anup Patel <apatel@ventanamicro.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sbi/sbi_irqchip.h>
|
||||||
|
#include <sbi/sbi_platform.h>
|
||||||
|
|
||||||
|
static int default_irqfn(struct sbi_trap_regs *regs)
|
||||||
|
{
|
||||||
|
return SBI_ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int (*ext_irqfn)(struct sbi_trap_regs *regs) = default_irqfn;
|
||||||
|
|
||||||
|
void sbi_irqchip_set_irqfn(int (*fn)(struct sbi_trap_regs *regs))
|
||||||
|
{
|
||||||
|
if (fn)
|
||||||
|
ext_irqfn = fn;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sbi_irqchip_process(struct sbi_trap_regs *regs)
|
||||||
|
{
|
||||||
|
return ext_irqfn(regs);
|
||||||
|
}
|
||||||
|
|
||||||
|
int sbi_irqchip_init(struct sbi_scratch *scratch, bool cold_boot)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
|
||||||
|
|
||||||
|
rc = sbi_platform_irqchip_init(plat, cold_boot);
|
||||||
|
if (rc)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
if (ext_irqfn != default_irqfn)
|
||||||
|
csr_set(CSR_MIE, MIP_MEIP);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sbi_irqchip_exit(struct sbi_scratch *scratch)
|
||||||
|
{
|
||||||
|
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
|
||||||
|
|
||||||
|
if (ext_irqfn != default_irqfn)
|
||||||
|
csr_clear(CSR_MIE, MIP_MEIP);
|
||||||
|
|
||||||
|
sbi_platform_irqchip_exit(plat);
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user