mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-24 15:31:22 +01:00
Compare commits
128 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
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 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -9,3 +9,5 @@ install/
|
||||
|
||||
# Development friendly files
|
||||
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"
|
142
Makefile
142
Makefile
@@ -47,11 +47,14 @@ ifdef PLATFORM_DIR
|
||||
platform_parent_dir=$(platform_dir_path)
|
||||
else
|
||||
PLATFORM=$(shell basename $(platform_dir_path))
|
||||
platform_parent_dir=$(subst $(PLATFORM),,$(platform_dir_path))
|
||||
platform_parent_dir=$(shell realpath ${platform_dir_path}/..)
|
||||
endif
|
||||
else
|
||||
platform_parent_dir=$(src_dir)/platform
|
||||
endif
|
||||
ifndef PLATFORM_DEFCONFIG
|
||||
PLATFORM_DEFCONFIG=defconfig
|
||||
endif
|
||||
|
||||
# Check if verbosity is ON for build process
|
||||
CMD_PREFIX_DEFAULT := @
|
||||
@@ -70,6 +73,20 @@ export libsbi_dir=$(CURDIR)/lib/sbi
|
||||
export libsbiutils_dir=$(CURDIR)/lib/utils
|
||||
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
|
||||
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/'`
|
||||
@@ -183,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)
|
||||
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
|
||||
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
|
||||
|
||||
# Include all object.mk files
|
||||
# Include all objects.mk files
|
||||
ifdef PLATFORM
|
||||
include $(platform-object-mks)
|
||||
endif
|
||||
@@ -198,8 +241,8 @@ include $(firmware-object-mks)
|
||||
|
||||
# Setup list of objects
|
||||
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
|
||||
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))
|
||||
firmware-bins-path-y=$(foreach bin,$(firmware-bins-y),$(platform_build_dir)/firmware/$(bin))
|
||||
endif
|
||||
@@ -280,6 +323,9 @@ ifeq ($(BUILD_INFO),y)
|
||||
GENFLAGS += -DOPENSBI_BUILD_TIME_STAMP="\"$(OPENSBI_BUILD_TIME_STAMP)\""
|
||||
GENFLAGS += -DOPENSBI_BUILD_COMPILER_VERSION="\"$(OPENSBI_BUILD_COMPILER_VERSION)\""
|
||||
endif
|
||||
ifdef PLATFORM
|
||||
GENFLAGS += -include $(KCONFIG_AUTOHEADER)
|
||||
endif
|
||||
GENFLAGS += $(libsbiutils-genflags-y)
|
||||
GENFLAGS += $(platform-genflags-y)
|
||||
GENFLAGS += $(firmware-genflags-y)
|
||||
@@ -413,29 +459,33 @@ compile_gen_dep = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
|
||||
echo "$(1:.dep=$(2)): $(3)" >> $(1)
|
||||
|
||||
targets-y = $(build_dir)/lib/libsbi.a
|
||||
targets-y += $(build_dir)/lib/libsbiutils.a
|
||||
ifdef PLATFORM
|
||||
targets-y += $(platform_build_dir)/lib/libplatsbi.a
|
||||
endif
|
||||
targets-y += $(firmware-bins-path-y)
|
||||
|
||||
# Default rule "make" should always be first rule
|
||||
# The default "make all" rule
|
||||
.PHONY: all
|
||||
all: $(targets-y)
|
||||
|
||||
# Preserve all intermediate files
|
||||
.SECONDARY:
|
||||
|
||||
# Rules for lib/sbi sources
|
||||
$(build_dir)/lib/libsbi.a: $(libsbi-objs-path-y)
|
||||
$(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)
|
||||
$(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,$@,$<)
|
||||
|
||||
$(build_dir)/%.o: $(src_dir)/%.c
|
||||
@@ -449,32 +499,24 @@ $(build_dir)/lib/sbi/sbi_init.o: $(libsbi_dir)/sbi_init.c FORCE
|
||||
$(call compile_cc,$@,$<)
|
||||
endif
|
||||
|
||||
$(build_dir)/%.dep: $(src_dir)/%.S
|
||||
$(build_dir)/%.dep: $(src_dir)/%.S $(KCONFIG_CONFIG)
|
||||
$(call compile_as_dep,$@,$<)
|
||||
|
||||
$(build_dir)/%.o: $(src_dir)/%.S
|
||||
$(call compile_as,$@,$<)
|
||||
|
||||
$(build_dir)/%.dep: $(src_dir)/%.carray
|
||||
$(call compile_gen_dep,$@,.c,$<)
|
||||
# Rules for platform sources
|
||||
$(platform_build_dir)/%.dep: $(platform_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
|
||||
$(platform_build_dir)/%.c: $(platform_src_dir)/%.carray
|
||||
$(call compile_carray,$@,$<)
|
||||
|
||||
$(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)/%.ld: $(src_dir)/%.ldS
|
||||
$(call compile_cpp,$@,$<)
|
||||
|
||||
$(platform_build_dir)/%.dep: $(platform_src_dir)/%.c
|
||||
$(platform_build_dir)/%.dep: $(platform_src_dir)/%.c $(KCONFIG_CONFIG)
|
||||
$(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)/%.dep: $(platform_src_dir)/%.S
|
||||
@@ -483,8 +525,8 @@ $(platform_build_dir)/%.dep: $(platform_src_dir)/%.S
|
||||
$(platform_build_dir)/%.o: $(platform_src_dir)/%.S
|
||||
$(call compile_as,$@,$<)
|
||||
|
||||
$(platform_build_dir)/%.dep: $(platform_src_dir)/%.dts
|
||||
$(call compile_gen_dep,$@,.dtb,$<)
|
||||
$(platform_build_dir)/%.dep: $(platform_src_dir)/%.dts $(KCONFIG_CONFIG)
|
||||
$(call compile_gen_dep,$@,.dtb,$< $(KCONFIG_CONFIG))
|
||||
$(call compile_gen_dep,$@,.c,$(@:.dep=.dtb))
|
||||
$(call compile_gen_dep,$@,.o,$(@:.dep=.c))
|
||||
|
||||
@@ -494,13 +536,30 @@ $(platform_build_dir)/%.c: $(platform_build_dir)/%.dtb
|
||||
$(platform_build_dir)/%.dtb: $(platform_src_dir)/%.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)/%.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,$@,$<)
|
||||
|
||||
$(platform_build_dir)/%.o: $(src_dir)/%.c
|
||||
$(call compile_cc,$@,$<)
|
||||
|
||||
$(platform_build_dir)/%.dep: $(src_dir)/%.S
|
||||
$(platform_build_dir)/%.dep: $(src_dir)/%.S $(KCONFIG_CONFIG)
|
||||
$(call compile_as_dep,$@,$<)
|
||||
|
||||
$(platform_build_dir)/%.o: $(src_dir)/%.S
|
||||
@@ -544,7 +603,6 @@ endif
|
||||
endif
|
||||
|
||||
install_targets-y = install_libsbi
|
||||
install_targets-y += install_libsbiutils
|
||||
ifdef PLATFORM
|
||||
install_targets-y += install_libplatsbi
|
||||
install_targets-y += install_firmwares
|
||||
@@ -559,17 +617,12 @@ install_libsbi: $(build_dir)/lib/libsbi.a
|
||||
$(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)
|
||||
|
||||
.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
|
||||
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)
|
||||
|
||||
.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-bins-path-y))
|
||||
|
||||
@@ -577,6 +630,17 @@ install_firmwares: $(platform_build_dir)/lib/libplatsbi.a $(build_dir)/lib/libsb
|
||||
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)
|
||||
|
||||
.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"
|
||||
.PHONY: clean
|
||||
clean:
|
||||
@@ -606,6 +670,8 @@ ifeq ($(install_root_dir),$(install_root_dir_default)/usr)
|
||||
$(if $(V), @echo " RM $(install_root_dir_default)")
|
||||
$(CMD_PREFIX)rm -rf $(install_root_dir_default)
|
||||
endif
|
||||
$(if $(V), @echo " RM $(src_dir)/cscope*")
|
||||
$(CMD_PREFIX)rm -f $(src_dir)/cscope*
|
||||
|
||||
.PHONY: FORCE
|
||||
FORCE:
|
||||
|
25
README.md
25
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
|
||||
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
|
||||
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
|
||||
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
|
||||
----------------------------------------------------------------
|
||||
|
||||
@@ -196,6 +204,19 @@ top-level make command line. These options, such as *PLATFORM_<xyz>* or
|
||||
*docs/platform/<platform_name>.md* files and
|
||||
*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
|
||||
---------------------------------------
|
||||
By default, building OpenSBI generates 32-bit or 64-bit images based on the
|
||||
|
@@ -29,7 +29,7 @@ and "top:".
|
||||
5. Maintainers should use "Rebase and Merge" when using GitHub to merge pull
|
||||
requests to avoid creating unnecessary merge commits.
|
||||
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.
|
||||
7. A maintainer cannot merge his own pull requests in the riscv/opensbi main
|
||||
repository.
|
||||
|
@@ -2,7 +2,7 @@ OpenSBI Domain Support
|
||||
======================
|
||||
|
||||
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
|
||||
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.
|
||||
The OpenSBI platform support is responsible for populating domains and
|
||||
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.
|
||||
|
||||
Domain Memory Region
|
||||
@@ -29,7 +29,7 @@ OpenSBI and has following details:
|
||||
* **base** - The base address of a memory region is **2 ^ order**
|
||||
aligned start address
|
||||
* **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
|
||||
---------------
|
||||
|
@@ -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
|
||||
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
|
||||
.text section of the final firmware.
|
||||
.rodata section of the final firmware.
|
||||
|
||||
Firmware Configuration and Compilation
|
||||
--------------------------------------
|
||||
|
@@ -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.
|
||||
|
||||
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.
|
||||
|
||||
The compiled *FW_DYNAMIC* firmware ELF file is named *fw_dynamic.elf*. It's
|
||||
@@ -31,6 +31,6 @@ directory.
|
||||
*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
|
||||
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:
|
||||
|
||||
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
|
||||
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
|
||||
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:
|
||||
|
||||
* **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
|
||||
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
|
||||
-----------------
|
||||
|
||||
|
@@ -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
|
||||
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
|
||||
in the .text section of the final firmware.
|
||||
in the .rodata section of the final firmware.
|
||||
|
||||
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:
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
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:
|
||||
|
||||
* **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
|
||||
bootloader linking with this library. This library is installed as
|
||||
*<install_directory>/lib/libsbi.a*
|
||||
2. *libsbiutils.a* - A static library that will contain all common code required
|
||||
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
|
||||
2. *libplatsbi.a* - An example platform-specific static library integrating
|
||||
*libsbi.a* with platform-specific hooks. This library is available only for
|
||||
the platforms supported by OpenSBI. This library is installed as
|
||||
*<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
|
||||
external header file during the build preprocess in order to define OpensSBI data types
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
----------------
|
||||
@@ -18,13 +18,190 @@ The Andes AE350 platform does not have any platform-specific options.
|
||||
Building Andes AE350 Platform
|
||||
-----------------------------
|
||||
|
||||
To use Linux v5.2 should be used to build Andes AE350 OpenSBI binaries by using
|
||||
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
|
||||
AE350's dts is included in https://github.com/andestech/linux/tree/RISCV-Linux-5.4-ast-v5_1_0-branch
|
||||
|
||||
**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:
|
||||
- DDR3 memory controller
|
||||
- SPI controller to conncet to an SDCard
|
||||
- SPI controller to connect to an SDCard
|
||||
- Ethernet controller
|
||||
- JTAG port (see debugging section below)
|
||||
- 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
|
||||
---------------------------------------
|
||||
|
||||
* **Andes AE350 Platform** (*[andes-ae350.md]*)
|
||||
* **QEMU RISC-V Virt Machine** (*[qemu_virt.md]*)
|
||||
* **Renesas RZ/Five SoC** (*[renesas-rzfive.md]*)
|
||||
* **Shakti C-class SoC Platform** (*[shakti_cclass.md]*)
|
||||
* **SiFive HiFive Unleashed** (*[sifive_fu540.md]*)
|
||||
* **Spike** (*[spike.md]*)
|
||||
* **T-HEAD C9xx series Processors** (*[thead-c9xx.md]*)
|
||||
|
||||
[andes-ae350.md]: andse-ae350.md
|
||||
[qemu_virt.md]: qemu_virt.md
|
||||
[renesas-rzfive.md]: renesas-rzfive.md
|
||||
[shakti_cclass.md]: shakti_cclass.md
|
||||
[sifive_fu540.md]: sifive_fu540.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
|
||||
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
|
||||
support for other platforms. The *platform/template* directory also provides
|
||||
template files for implementing support for a new platform. The *object.mk*,
|
||||
*config.mk* and *platform.c* template files provides enough comments to
|
||||
facilitate the implementation.
|
||||
template files for implementing support for a new platform. The *objects.mk*,
|
||||
*Kconfig*, *configs/defconfig* and *platform.c* template files provides enough
|
||||
comments to facilitate the implementation.
|
||||
|
||||
[generic.md]: generic.md
|
||||
[qemu_virt.md]: qemu_virt.md
|
||||
@@ -54,3 +58,4 @@ facilitate the implementation.
|
||||
[spike.md]: spike.md
|
||||
[fpga-openpiton.md]: fpga-openpiton.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.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
because it use generic platform.
|
||||
because it uses generic platform.
|
||||
|
||||
```
|
||||
CROSS_COMPILE=riscv64-linux-gnu- PLATFORM=generic /usr/bin/make
|
||||
|
@@ -28,11 +28,12 @@ Adding support for a new platform
|
||||
Support for a new platform named *<xyz>* can be added as follows:
|
||||
|
||||
1. Create a directory named *<xyz>* under the *platform/* directory.
|
||||
2. Create a platform configuration file named *config.mk* under the
|
||||
*platform/<xyz>/* directory. This configuration file will provide
|
||||
2. Create platform configuration files named *Kconfig* and *configs/defconfig*
|
||||
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.
|
||||
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
|
||||
*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
|
||||
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.
|
||||
|
||||
Base Platform Requirements
|
||||
|
@@ -1,14 +1,11 @@
|
||||
OpenSBI SBI PMU extension support
|
||||
==================================
|
||||
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
|
||||
enabled. The OpenSBI implementation makes the following assumptions about the
|
||||
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
|
||||
via device tree or platform specific hooks. Otherwise, SBI PMU extension will
|
||||
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
|
||||
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.
|
||||
|
||||
* **compatible** (Mandatory) - The compatible string of SBI PMU device tree node.
|
||||
@@ -42,21 +39,21 @@ This property shouldn't encode any raw hardware event.
|
||||
* **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
|
||||
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
|
||||
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
|
||||
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.
|
||||
|
||||
* **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
|
||||
a bitmap format that can be used to monitor that raw event. The encoding of the
|
||||
raw events are platform specific. The information is encoded in a table format
|
||||
where each row represent the specific raw event(s). The first column is a 64bit
|
||||
where each row represents the specific raw event(s). The first column is a 64bit
|
||||
match value where the invariant bits of range of events are set. The second
|
||||
column is a 64 bit mask that will have all the variant bits of the range of
|
||||
events cleared. Every other bits should be set in the mask.
|
||||
events cleared. All other bits should be set in the mask.
|
||||
The third column is a 32bit value to represent bitmap of all MHPMCOUNTERx that
|
||||
can monitor these set of event(s).
|
||||
If a platform directly encodes each raw PMU event as a unique ID, the value of
|
||||
@@ -70,17 +67,17 @@ via platform hooks rather than the device tree.
|
||||
```
|
||||
pmu {
|
||||
compatible = "riscv,pmu";
|
||||
riscv,event-to-mhpmevent = <0x0000B 0x0000 0x0001>,
|
||||
riscv,event-to-mhpmevent = <0x0000B 0x0000 0x0001>;
|
||||
riscv,event-to-mhpmcounters = <0x00001 0x00001 0x00000001>,
|
||||
<0x00002 0x00002 0x00000004>,
|
||||
<0x00003 0x0000A 0x00000ff8>,
|
||||
<0x10000 0x10033 0x000ff000>,
|
||||
<0x10000 0x10033 0x000ff000>;
|
||||
/* For event ID 0x0002 */
|
||||
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>,
|
||||
<0xffffffff 0x0 0xffffffff 0xffffff0f 0x00000ff0>;
|
||||
};
|
||||
```
|
||||
|
||||
@@ -90,11 +87,41 @@ pmu {
|
||||
/*
|
||||
* 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,raw-event-to-mhpmcounters = <0x0 0x0 0xffffffff 0xfc0000ff 0xc>,
|
||||
<0x0 0x1 0xffffffff 0xfff800ff 0xc>,
|
||||
<0x0 0x2 0xffffffff 0xffffe0ff 0xc>;
|
||||
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)
|
||||
lla t2, _load_start
|
||||
REG_L t2, 0(t2)
|
||||
beq t0, t2, _relocate_done
|
||||
sub t3, t1, t0
|
||||
add t3, t3, t2
|
||||
beq t0, t2, _relocate_done
|
||||
lla t4, _relocate_done
|
||||
sub t4, t4, t2
|
||||
add t4, t4, t0
|
||||
|
@@ -24,14 +24,12 @@
|
||||
PROVIDE(_text_end = .);
|
||||
}
|
||||
|
||||
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
||||
|
||||
/* End of the code sections */
|
||||
|
||||
/* Beginning of the read-only data sections */
|
||||
|
||||
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
||||
|
||||
/* Beginning of the read-only data sections */
|
||||
|
||||
.rodata :
|
||||
{
|
||||
PROVIDE(_rodata_start = .);
|
||||
@@ -42,10 +40,10 @@
|
||||
|
||||
/* End of the read-only data sections */
|
||||
|
||||
/* Beginning of the read-write data sections */
|
||||
|
||||
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
||||
|
||||
/* Beginning of the read-write data sections */
|
||||
|
||||
.data :
|
||||
{
|
||||
PROVIDE(_data_start = .);
|
||||
|
@@ -33,14 +33,12 @@ SECTIONS
|
||||
PROVIDE(_text_end = .);
|
||||
}
|
||||
|
||||
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
||||
|
||||
/* End of the code sections */
|
||||
|
||||
/* Beginning of the read-only data sections */
|
||||
|
||||
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
||||
|
||||
/* Beginning of the read-only data sections */
|
||||
|
||||
.rodata :
|
||||
{
|
||||
PROVIDE(_rodata_start = .);
|
||||
@@ -51,10 +49,10 @@ SECTIONS
|
||||
|
||||
/* End of the read-only data sections */
|
||||
|
||||
/* Beginning of the read-write data sections */
|
||||
|
||||
. = ALIGN(0x1000); /* Ensure next section is page aligned */
|
||||
|
||||
/* Beginning of the read-write data sections */
|
||||
|
||||
.data :
|
||||
{
|
||||
PROVIDE(_data_start = .);
|
||||
|
@@ -38,10 +38,14 @@
|
||||
#define MSTATUS_SXL _ULL(0x0000000C00000000)
|
||||
#define MSTATUS_SBE _ULL(0x0000001000000000)
|
||||
#define MSTATUS_MBE _ULL(0x0000002000000000)
|
||||
#define MSTATUS_GVA _ULL(0x0000004000000000)
|
||||
#define MSTATUS_GVA_SHIFT 38
|
||||
#define MSTATUS_MPV _ULL(0x0000008000000000)
|
||||
#else
|
||||
#define MSTATUSH_SBE _UL(0x00000010)
|
||||
#define MSTATUSH_MBE _UL(0x00000020)
|
||||
#define MSTATUSH_GVA _UL(0x00000040)
|
||||
#define MSTATUSH_GVA_SHIFT 6
|
||||
#define MSTATUSH_MPV _UL(0x00000080)
|
||||
#endif
|
||||
#define MSTATUS32_SD _UL(0x80000000)
|
||||
@@ -308,8 +312,6 @@
|
||||
|
||||
/* Supervisor Trap Setup */
|
||||
#define CSR_SSTATUS 0x100
|
||||
#define CSR_SEDELEG 0x102
|
||||
#define CSR_SIDELEG 0x103
|
||||
#define CSR_SIE 0x104
|
||||
#define CSR_STVEC 0x105
|
||||
#define CSR_SCOUNTEREN 0x106
|
||||
|
@@ -175,11 +175,25 @@ int sbi_domain_register(struct sbi_domain *dom,
|
||||
* @param reg pointer to the memory region to be added
|
||||
*
|
||||
* @return 0 on success
|
||||
* @return SBI_EALREADY if memory region conflicts with existing
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* 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 */
|
||||
int sbi_domain_finalize(struct sbi_scratch *scratch, u32 cold_hartid);
|
||||
|
||||
|
@@ -31,16 +31,6 @@ struct sbi_ecall_extension {
|
||||
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_minor(void);
|
||||
|
@@ -208,6 +208,12 @@ enum sbi_pmu_ctr_type {
|
||||
|
||||
#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 */
|
||||
#define SBI_PMU_CFG_FLAG_SKIP_MATCH (1 << 0)
|
||||
#define SBI_PMU_CFG_FLAG_CLEAR_VALUE (1 << 1)
|
||||
|
@@ -30,8 +30,8 @@ enum sbi_hart_extensions {
|
||||
SBI_HART_EXT_SSCOFPMF = 0,
|
||||
/** HART has HW time CSR (extension name not available) */
|
||||
SBI_HART_EXT_TIME,
|
||||
/** HART has AIA CSRs (extension name not available) */
|
||||
SBI_HART_EXT_AIA,
|
||||
/** HART has AIA M-mode CSRs */
|
||||
SBI_HART_EXT_SMAIA,
|
||||
/** HART has Smstateen CSR **/
|
||||
SBI_HART_EXT_SMSTATEEN,
|
||||
/** HART has Sstc extension */
|
||||
@@ -41,6 +41,17 @@ enum sbi_hart_extensions {
|
||||
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;
|
||||
|
||||
int sbi_hart_reinit(struct sbi_scratch *scratch);
|
||||
|
@@ -75,7 +75,7 @@ int sbi_ipi_send_halt(ulong hmask, ulong hbase);
|
||||
|
||||
void sbi_ipi_process(void);
|
||||
|
||||
void sbi_ipi_raw_send(u32 target_hart);
|
||||
int sbi_ipi_raw_send(u32 target_hart);
|
||||
|
||||
const struct sbi_ipi_device *sbi_ipi_get_device(void);
|
||||
|
||||
|
@@ -48,6 +48,7 @@
|
||||
struct sbi_domain_memregion;
|
||||
struct sbi_trap_info;
|
||||
struct sbi_trap_regs;
|
||||
struct sbi_hart_features;
|
||||
|
||||
/** Possible feature flags of a platform */
|
||||
enum sbi_platform_features {
|
||||
@@ -90,7 +91,7 @@ struct sbi_platform_operations {
|
||||
int (*misa_get_xlen)(void);
|
||||
|
||||
/** Initialize (or populate) HART extensions for the platform */
|
||||
int (*extensions_init)(void);
|
||||
int (*extensions_init)(struct sbi_hart_features *hfeatures);
|
||||
|
||||
/** Initialize (or populate) domains for the platform */
|
||||
int (*domains_init)(void);
|
||||
@@ -464,10 +465,11 @@ static inline int sbi_platform_misa_xlen(const struct sbi_platform *plat)
|
||||
* @return 0 on success and negative error code on failure
|
||||
*/
|
||||
static inline int sbi_platform_extensions_init(
|
||||
const struct sbi_platform *plat)
|
||||
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();
|
||||
return sbi_platform_ops(plat)->extensions_init(hfeatures);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -11,29 +11,90 @@
|
||||
#define __SBI_PMU_H__
|
||||
|
||||
#include <sbi/sbi_types.h>
|
||||
#include <sbi/sbi_hartmask.h>
|
||||
#include <sbi/sbi_scratch.h>
|
||||
#include <sbi/sbi_ecall_interface.h>
|
||||
|
||||
struct sbi_scratch;
|
||||
|
||||
/* Event related macros */
|
||||
/* Maximum number of hardware events that can mapped by OpenSBI */
|
||||
#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 */
|
||||
#define SBI_PMU_FW_CTR_MAX 16
|
||||
#define SBI_PMU_HW_CTR_MAX 32
|
||||
#define SBI_PMU_CTR_MAX (SBI_PMU_HW_CTR_MAX + SBI_PMU_FW_CTR_MAX)
|
||||
#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
|
||||
* Note: SBI_PMU_FW_MAX <= event_idx_code
|
||||
*/
|
||||
int (*fw_event_validate_code)(uint32_t event_idx_code);
|
||||
|
||||
/**
|
||||
* Match custom firmware counter with custom firmware event
|
||||
* Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX
|
||||
*/
|
||||
bool (*fw_counter_match_code)(uint32_t counter_index,
|
||||
uint32_t event_idx_code);
|
||||
|
||||
/**
|
||||
* Read value of custom firmware counter
|
||||
* Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX
|
||||
*/
|
||||
uint64_t (*fw_counter_read_value)(uint32_t counter_index);
|
||||
|
||||
/**
|
||||
* Start custom firmware counter
|
||||
* Note: SBI_PMU_FW_MAX <= event_idx_code
|
||||
* Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX
|
||||
*/
|
||||
int (*fw_counter_start)(uint32_t counter_index,
|
||||
uint32_t event_idx_code,
|
||||
uint64_t init_val, bool init_val_update);
|
||||
|
||||
/**
|
||||
* Stop custom firmware counter
|
||||
* Note: 0 <= counter_index < SBI_PMU_FW_CTR_MAX
|
||||
*/
|
||||
int (*fw_counter_stop)(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 */
|
||||
int sbi_pmu_init(struct sbi_scratch *scratch, bool cold_boot);
|
||||
|
||||
/** Reset PMU during hart exit */
|
||||
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
|
||||
* from the platform code to update the mapping table.
|
||||
@@ -53,7 +114,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_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,
|
||||
unsigned long flag);
|
||||
|
@@ -57,7 +57,7 @@ struct sbi_scratch {
|
||||
unsigned long next_arg1;
|
||||
/** Address of next booting stage for this HART */
|
||||
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;
|
||||
/** Warm boot entry point address for this HART */
|
||||
unsigned long warmboot_addr;
|
||||
|
@@ -48,6 +48,24 @@ static inline void sbi_timer_udelay(ulong usecs)
|
||||
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 */
|
||||
u64 sbi_timer_value(void);
|
||||
|
||||
|
@@ -10,6 +10,8 @@
|
||||
#ifndef __SBI_TRAP_H__
|
||||
#define __SBI_TRAP_H__
|
||||
|
||||
#include <sbi/riscv_encoding.h>
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
/** Index of zero member in sbi_trap_regs */
|
||||
@@ -95,8 +97,10 @@
|
||||
#define SBI_TRAP_INFO_tval2 3
|
||||
/** Index of tinst member in sbi_trap_info */
|
||||
#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 */
|
||||
#define SBI_TRAP_INFO_last 5
|
||||
#define SBI_TRAP_INFO_last 6
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
@@ -200,8 +204,26 @@ struct sbi_trap_info {
|
||||
unsigned long tval2;
|
||||
/** tinst Trap instruction */
|
||||
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,
|
||||
struct sbi_trap_info *trap);
|
||||
|
||||
|
@@ -11,7 +11,7 @@
|
||||
#define __SBI_VERSION_H__
|
||||
|
||||
#define OPENSBI_VERSION_MAJOR 1
|
||||
#define OPENSBI_VERSION_MINOR 1
|
||||
#define OPENSBI_VERSION_MINOR 2
|
||||
|
||||
/**
|
||||
* OpenSBI 32-bit version with:
|
||||
|
@@ -13,6 +13,8 @@
|
||||
|
||||
#include <sbi/sbi_types.h>
|
||||
|
||||
#ifdef CONFIG_FDT_DOMAIN
|
||||
|
||||
struct sbi_domain;
|
||||
|
||||
/**
|
||||
@@ -70,4 +72,11 @@ void fdt_domain_fixup(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__ */
|
||||
|
@@ -59,14 +59,17 @@ int fdt_parse_timebase_frequency(void *fdt, unsigned long *freq);
|
||||
int fdt_parse_gaisler_uart_node(void *fdt, int nodeoffset,
|
||||
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,
|
||||
struct platform_uart_data *uart);
|
||||
|
||||
int fdt_parse_sifive_uart_node(void *fdt, int nodeoffset,
|
||||
struct platform_uart_data *uart);
|
||||
|
||||
int fdt_parse_uart8250_node(void *fdt, int nodeoffset,
|
||||
struct platform_uart_data *uart);
|
||||
int fdt_parse_uart_node(void *fdt, int nodeoffset,
|
||||
struct platform_uart_data *uart);
|
||||
|
||||
int fdt_parse_uart8250(void *fdt, struct platform_uart_data *uart,
|
||||
const char *compatible);
|
||||
@@ -95,6 +98,12 @@ int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer,
|
||||
unsigned long *out_addr2, unsigned long *out_size2,
|
||||
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,
|
||||
const char *compatible);
|
||||
|
||||
|
@@ -13,6 +13,8 @@
|
||||
|
||||
#include <sbi/sbi_types.h>
|
||||
|
||||
#ifdef CONFIG_FDT_PMU
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
#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
|
||||
|
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>
|
||||
|
||||
#ifdef CONFIG_FDT_IPI
|
||||
|
||||
struct fdt_ipi {
|
||||
const struct fdt_match *match_table;
|
||||
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);
|
||||
|
||||
#else
|
||||
|
||||
static inline void fdt_ipi_exit(void) { }
|
||||
static inline int fdt_ipi_init(bool cold_boot) { return 0; }
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@@ -12,6 +12,8 @@
|
||||
|
||||
#include <sbi/sbi_types.h>
|
||||
|
||||
#ifdef CONFIG_FDT_IRQCHIP
|
||||
|
||||
struct fdt_irqchip {
|
||||
const struct fdt_match *match_table;
|
||||
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);
|
||||
|
||||
#else
|
||||
|
||||
static inline void fdt_irqchip_exit(void) { }
|
||||
|
||||
static inline int fdt_irqchip_init(bool cold_boot) { return 0; }
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@@ -9,13 +9,24 @@
|
||||
|
||||
#include <sbi/sbi_types.h>
|
||||
|
||||
void fdt_plic_priority_save(u8 *priority);
|
||||
/**
|
||||
* 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);
|
||||
|
||||
void fdt_plic_priority_restore(const u8 *priority);
|
||||
/**
|
||||
* 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);
|
||||
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);
|
||||
void fdt_plic_context_restore(bool smode, const u32 *enable, u32 threshold,
|
||||
u32 num);
|
||||
|
||||
void thead_plic_restore(void);
|
||||
|
||||
|
@@ -33,6 +33,8 @@ struct imsic_data {
|
||||
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);
|
||||
@@ -47,4 +49,12 @@ 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
|
||||
|
@@ -18,15 +18,16 @@ struct plic_data {
|
||||
};
|
||||
|
||||
/* So far, priorities on all consumers of these functions fit in 8 bits. */
|
||||
void plic_priority_save(const struct plic_data *plic, u8 *priority);
|
||||
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);
|
||||
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 *enable, u32 *threshold, u32 num);
|
||||
|
||||
void plic_context_restore(const struct plic_data *plic, int context_id,
|
||||
const u32 *enable, u32 threshold);
|
||||
const u32 *enable, u32 threshold, u32 num);
|
||||
|
||||
int plic_context_init(const struct plic_data *plic, int context_id,
|
||||
bool enable, u32 threshold);
|
||||
|
@@ -17,6 +17,8 @@ struct fdt_reset {
|
||||
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
|
||||
*/
|
||||
@@ -29,4 +31,14 @@ int fdt_reset_driver_init(void *fdt, struct fdt_reset *drv);
|
||||
*/
|
||||
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
|
||||
|
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>
|
||||
|
||||
#ifdef CONFIG_FDT_SERIAL
|
||||
|
||||
struct fdt_serial {
|
||||
const struct fdt_match *match_table;
|
||||
int (*init)(void *fdt, int nodeoff, const struct fdt_match *match);
|
||||
@@ -19,4 +21,10 @@ struct fdt_serial {
|
||||
|
||||
int fdt_serial_init(void);
|
||||
|
||||
#else
|
||||
|
||||
static inline int fdt_serial_init(void) { return 0; }
|
||||
|
||||
#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);
|
||||
int semihosting_enabled(void);
|
||||
#else
|
||||
static inline int semihosting_init(void) { return SBI_ENODEV; }
|
||||
static inline int semihosting_enabled(void) { return 0; }
|
||||
#endif
|
||||
|
||||
#endif
|
@@ -22,6 +22,8 @@
|
||||
|
||||
#define CLINT_MTIMER_OFFSET 0x4000
|
||||
|
||||
#define MTIMER_REGION_ALIGN 0x1000
|
||||
|
||||
struct aclint_mtimer_data {
|
||||
/* Public details */
|
||||
unsigned long mtime_freq;
|
||||
|
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>
|
||||
|
||||
#ifdef CONFIG_FDT_TIMER
|
||||
|
||||
struct fdt_timer {
|
||||
const struct fdt_match *match_table;
|
||||
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);
|
||||
|
||||
#else
|
||||
|
||||
static inline void fdt_timer_exit(void) { }
|
||||
static inline int fdt_timer_init(bool cold_boot) { return 0; }
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
37
lib/sbi/Kconfig
Normal file
37
lib/sbi/Kconfig
Normal file
@@ -0,0 +1,37 @@
|
||||
# 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_PMU
|
||||
bool "Performance Monitoring Unit 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,41 @@ libsbi-objs-y += riscv_atomic.o
|
||||
libsbi-objs-y += riscv_hardfp.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_PMU) += ecall_pmu
|
||||
libsbi-objs-$(CONFIG_SBI_ECALL_PMU) += sbi_ecall_pmu.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_bitops.o
|
||||
libsbi-objs-y += sbi_console.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_fifo.o
|
||||
libsbi-objs-y += sbi_hart.o
|
||||
|
@@ -76,20 +76,22 @@ typedef __builtin_va_list va_list;
|
||||
|
||||
static void printc(char **out, u32 *out_len, char ch)
|
||||
{
|
||||
if (out) {
|
||||
if (*out) {
|
||||
if (out_len && (0 < *out_len)) {
|
||||
**out = ch;
|
||||
++(*out);
|
||||
(*out_len)--;
|
||||
} else {
|
||||
**out = ch;
|
||||
++(*out);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!out) {
|
||||
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,
|
||||
@@ -181,7 +183,7 @@ 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)
|
||||
{
|
||||
int width, flags, acnt = 0;
|
||||
int width, flags;
|
||||
int pc = 0;
|
||||
char scr[2];
|
||||
unsigned long long tmp;
|
||||
@@ -193,7 +195,7 @@ static int print(char **out, u32 *out_len, const char *format, va_list args)
|
||||
if (*format == '\0')
|
||||
break;
|
||||
if (*format == '%')
|
||||
goto out;
|
||||
goto literal;
|
||||
/* Get flags */
|
||||
if (*format == '-') {
|
||||
++format;
|
||||
@@ -214,7 +216,6 @@ static int print(char **out, u32 *out_len, const char *format, va_list args)
|
||||
}
|
||||
if (*format == 's') {
|
||||
char *s = va_arg(args, char *);
|
||||
acnt += sizeof(char *);
|
||||
pc += prints(out, out_len, s ? s : "(null)",
|
||||
width, flags);
|
||||
continue;
|
||||
@@ -222,61 +223,40 @@ static int print(char **out, u32 *out_len, const char *format, va_list args)
|
||||
if ((*format == 'd') || (*format == 'i')) {
|
||||
pc += printi(out, out_len, va_arg(args, int),
|
||||
10, 1, width, flags, '0');
|
||||
acnt += sizeof(int);
|
||||
continue;
|
||||
}
|
||||
if (*format == 'x') {
|
||||
pc += printi(out, out_len,
|
||||
va_arg(args, unsigned int), 16, 0,
|
||||
width, flags, 'a');
|
||||
acnt += sizeof(unsigned int);
|
||||
continue;
|
||||
}
|
||||
if (*format == 'X') {
|
||||
pc += printi(out, out_len,
|
||||
va_arg(args, unsigned int), 16, 0,
|
||||
width, flags, 'A');
|
||||
acnt += sizeof(unsigned int);
|
||||
continue;
|
||||
}
|
||||
if (*format == 'u') {
|
||||
pc += printi(out, out_len,
|
||||
va_arg(args, unsigned int), 10, 0,
|
||||
width, flags, 'a');
|
||||
acnt += sizeof(unsigned int);
|
||||
continue;
|
||||
}
|
||||
if (*format == 'p') {
|
||||
pc += printi(out, out_len,
|
||||
va_arg(args, unsigned long), 16, 0,
|
||||
width, flags, 'a');
|
||||
acnt += sizeof(unsigned long);
|
||||
continue;
|
||||
}
|
||||
if (*format == 'P') {
|
||||
pc += printi(out, out_len,
|
||||
va_arg(args, unsigned long), 16, 0,
|
||||
width, flags, 'A');
|
||||
acnt += sizeof(unsigned long);
|
||||
continue;
|
||||
}
|
||||
if (*format == 'l' && *(format + 1) == 'l') {
|
||||
while (acnt &
|
||||
(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);
|
||||
}
|
||||
tmp = va_arg(args, unsigned long long);
|
||||
if (*(format + 2) == 'u') {
|
||||
format += 2;
|
||||
pc += printi(out, out_len, tmp, 10, 0,
|
||||
@@ -308,19 +288,16 @@ static int print(char **out, u32 *out_len, const char *format, va_list args)
|
||||
out, out_len,
|
||||
va_arg(args, unsigned long), 16,
|
||||
0, width, flags, 'a');
|
||||
acnt += sizeof(unsigned long);
|
||||
} else if (*(format + 1) == 'X') {
|
||||
format += 1;
|
||||
pc += printi(
|
||||
out, out_len,
|
||||
va_arg(args, unsigned long), 16,
|
||||
0, width, flags, 'A');
|
||||
acnt += sizeof(unsigned long);
|
||||
} else {
|
||||
pc += printi(out, out_len,
|
||||
va_arg(args, long), 10, 1,
|
||||
width, flags, '0');
|
||||
acnt += sizeof(long);
|
||||
}
|
||||
}
|
||||
if (*format == 'c') {
|
||||
@@ -328,17 +305,14 @@ static int print(char **out, u32 *out_len, const char *format, va_list args)
|
||||
scr[0] = va_arg(args, int);
|
||||
scr[1] = '\0';
|
||||
pc += prints(out, out_len, scr, width, flags);
|
||||
acnt += sizeof(int);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
out:
|
||||
literal:
|
||||
printc(out, out_len, *format);
|
||||
++pc;
|
||||
}
|
||||
}
|
||||
if (out)
|
||||
**out = '\0';
|
||||
|
||||
return pc;
|
||||
}
|
||||
@@ -348,6 +322,9 @@ int sbi_sprintf(char *out, const char *format, ...)
|
||||
va_list args;
|
||||
int retval;
|
||||
|
||||
if (unlikely(!out))
|
||||
sbi_panic("sbi_sprintf called with NULL output string\n");
|
||||
|
||||
va_start(args, format);
|
||||
retval = print(&out, NULL, format, args);
|
||||
va_end(args);
|
||||
@@ -360,6 +337,10 @@ int sbi_snprintf(char *out, u32 out_sz, const char *format, ...)
|
||||
va_list args;
|
||||
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);
|
||||
retval = print(&out, &out_sz, format, args);
|
||||
va_end(args);
|
||||
|
@@ -105,7 +105,7 @@ bool sbi_domain_check_addr(const struct sbi_domain *dom,
|
||||
unsigned long addr, unsigned long mode,
|
||||
unsigned long access_flags)
|
||||
{
|
||||
bool mmio = FALSE;
|
||||
bool rmmio, mmio = FALSE;
|
||||
struct sbi_domain_memregion *reg;
|
||||
unsigned long rstart, rend, rflags, rwx = 0;
|
||||
|
||||
@@ -130,8 +130,8 @@ bool sbi_domain_check_addr(const struct sbi_domain *dom,
|
||||
rend = (reg->order < __riscv_xlen) ?
|
||||
rstart + ((1UL << reg->order) - 1) : -1UL;
|
||||
if (rstart <= addr && addr <= rend) {
|
||||
if ((mmio && !(rflags & SBI_DOMAIN_MEMREGION_MMIO)) ||
|
||||
(!mmio && (rflags & SBI_DOMAIN_MEMREGION_MMIO)))
|
||||
rmmio = (rflags & SBI_DOMAIN_MEMREGION_MMIO) ? TRUE : FALSE;
|
||||
if (mmio != rmmio)
|
||||
return FALSE;
|
||||
return ((rflags & rwx) == rwx) ? TRUE : FALSE;
|
||||
}
|
||||
@@ -146,7 +146,10 @@ static bool is_region_valid(const struct sbi_domain_memregion *reg)
|
||||
if (reg->order < 3 || __riscv_xlen < reg->order)
|
||||
return FALSE;
|
||||
|
||||
if (reg->base & (BIT(reg->order) - 1))
|
||||
if (reg->order == __riscv_xlen && reg->base != 0)
|
||||
return FALSE;
|
||||
|
||||
if (reg->order < __riscv_xlen && (reg->base & (BIT(reg->order) - 1)))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
@@ -522,6 +525,33 @@ int sbi_domain_root_add_memregion(const struct sbi_domain_memregion *reg)
|
||||
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 rc;
|
||||
|
@@ -13,6 +13,9 @@
|
||||
#include <sbi/sbi_error.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)
|
||||
{
|
||||
return SBI_ECALL_VERSION_MAJOR;
|
||||
@@ -144,35 +147,15 @@ int sbi_ecall_handler(struct sbi_trap_regs *regs)
|
||||
int sbi_ecall_init(void)
|
||||
{
|
||||
int ret;
|
||||
struct sbi_ecall_extension *ext;
|
||||
unsigned long i;
|
||||
|
||||
/* The order of below registrations is performance optimized */
|
||||
ret = sbi_ecall_register_extension(&ecall_time);
|
||||
if (ret)
|
||||
return ret;
|
||||
ret = sbi_ecall_register_extension(&ecall_rfence);
|
||||
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;
|
||||
for (i = 0; i < sbi_ecall_exts_size; i++) {
|
||||
ext = sbi_ecall_exts[i];
|
||||
ret = sbi_ecall_register_extension(ext);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
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
|
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,8 @@ static int sbi_ecall_pmu_handler(unsigned long extid, unsigned long funcid,
|
||||
|
||||
break;
|
||||
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_START:
|
||||
|
||||
|
@@ -9,40 +9,11 @@
|
||||
*/
|
||||
|
||||
#include <sbi/riscv_asm.h>
|
||||
#include <sbi/sbi_error.h>
|
||||
#include <sbi/sbi_ecall.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>
|
||||
|
||||
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,
|
||||
};
|
||||
#include <sbi/sbi_tlb.h>
|
||||
|
||||
static int sbi_ecall_rfence_handler(unsigned long extid, unsigned long funcid,
|
||||
const struct sbi_trap_regs *regs,
|
||||
@@ -113,84 +84,3 @@ struct sbi_ecall_extension ecall_rfence = {
|
||||
.extid_end = SBI_EXT_RFENCE,
|
||||
.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,
|
||||
};
|
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,
|
||||
};
|
@@ -11,7 +11,7 @@
|
||||
#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.
|
||||
*
|
||||
* The trap info will be saved as follows:
|
||||
@@ -22,7 +22,7 @@
|
||||
.align 3
|
||||
.global __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
|
||||
REG_S a4, SBI_TRAP_INFO_OFFSET(epc)(a3)
|
||||
csrr a4, CSR_MCAUSE
|
||||
@@ -31,6 +31,7 @@ __sbi_expected_trap:
|
||||
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(tinst)(a3)
|
||||
REG_S zero, SBI_TRAP_INFO_OFFSET(gva)(a3)
|
||||
csrr a4, CSR_MEPC
|
||||
addi a4, a4, 4
|
||||
csrw CSR_MEPC, a4
|
||||
@@ -39,7 +40,7 @@ __sbi_expected_trap:
|
||||
.align 3
|
||||
.global __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
|
||||
REG_S a4, SBI_TRAP_INFO_OFFSET(epc)(a3)
|
||||
csrr a4, CSR_MCAUSE
|
||||
@@ -50,6 +51,18 @@ __sbi_expected_trap_hext:
|
||||
REG_S a4, SBI_TRAP_INFO_OFFSET(tval2)(a3)
|
||||
csrr a4, CSR_MTINST
|
||||
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
|
||||
addi a4, a4, 4
|
||||
csrw CSR_MEPC, a4
|
||||
|
@@ -19,24 +19,16 @@
|
||||
#include <sbi/sbi_hart.h>
|
||||
#include <sbi/sbi_math.h>
|
||||
#include <sbi/sbi_platform.h>
|
||||
#include <sbi/sbi_pmu.h>
|
||||
#include <sbi/sbi_string.h>
|
||||
#include <sbi/sbi_trap.h>
|
||||
#include <sbi/sbi_hfence.h>
|
||||
|
||||
extern void __sbi_expected_trap(void);
|
||||
extern void __sbi_expected_trap_hext(void);
|
||||
|
||||
void (*sbi_hart_expected_trap)(void) = &__sbi_expected_trap;
|
||||
|
||||
struct 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;
|
||||
};
|
||||
static unsigned long hart_features_offset;
|
||||
|
||||
static void mstatus_init(struct sbi_scratch *scratch)
|
||||
@@ -100,7 +92,7 @@ static void mstatus_init(struct sbi_scratch *scratch)
|
||||
mstateen_val |= SMSTATEEN_STATEN;
|
||||
mstateen_val |= SMSTATEEN0_HSENVCFG;
|
||||
|
||||
if (sbi_hart_has_extension(scratch, SBI_HART_EXT_AIA))
|
||||
if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SMAIA))
|
||||
mstateen_val |= (SMSTATEEN0_AIA | SMSTATEEN0_SVSLCT |
|
||||
SMSTATEEN0_IMSIC);
|
||||
else
|
||||
@@ -208,8 +200,7 @@ static int delegate_traps(struct sbi_scratch *scratch)
|
||||
|
||||
/* Send M-mode interrupts and most exceptions to S-mode */
|
||||
interrupts = MIP_SSIP | MIP_STIP | MIP_SEIP;
|
||||
if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCOFPMF))
|
||||
interrupts |= MIP_LCOFIP;
|
||||
interrupts |= sbi_pmu_irq_bit();
|
||||
|
||||
exceptions = (1U << CAUSE_MISALIGNED_FETCH) | (1U << CAUSE_BREAKPOINT) |
|
||||
(1U << CAUSE_USER_ECALL);
|
||||
@@ -254,7 +245,7 @@ void sbi_hart_delegation_dump(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);
|
||||
|
||||
return hfeatures->mhpm_count;
|
||||
@@ -262,7 +253,7 @@ unsigned int sbi_hart_mhpm_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);
|
||||
|
||||
return hfeatures->pmp_count;
|
||||
@@ -270,7 +261,7 @@ unsigned int sbi_hart_pmp_count(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);
|
||||
|
||||
return hfeatures->pmp_gran;
|
||||
@@ -278,7 +269,7 @@ unsigned long sbi_hart_pmp_granularity(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);
|
||||
|
||||
return hfeatures->pmp_addr_bits;
|
||||
@@ -286,7 +277,7 @@ unsigned int sbi_hart_pmp_addrbits(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);
|
||||
|
||||
return hfeatures->mhpm_bits;
|
||||
@@ -331,12 +322,33 @@ 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;
|
||||
}
|
||||
|
||||
int sbi_hart_priv_version(struct sbi_scratch *scratch)
|
||||
{
|
||||
struct hart_features *hfeatures =
|
||||
struct sbi_hart_features *hfeatures =
|
||||
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
||||
|
||||
return hfeatures->priv_version;
|
||||
@@ -346,7 +358,7 @@ void sbi_hart_get_priv_version_str(struct sbi_scratch *scratch,
|
||||
char *version_str, int nvstr)
|
||||
{
|
||||
char *temp;
|
||||
struct hart_features *hfeatures =
|
||||
struct sbi_hart_features *hfeatures =
|
||||
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
||||
|
||||
switch (hfeatures->priv_version) {
|
||||
@@ -368,7 +380,7 @@ void sbi_hart_get_priv_version_str(struct sbi_scratch *scratch,
|
||||
}
|
||||
|
||||
static inline void __sbi_hart_update_extension(
|
||||
struct hart_features *hfeatures,
|
||||
struct sbi_hart_features *hfeatures,
|
||||
enum sbi_hart_extensions ext,
|
||||
bool enable)
|
||||
{
|
||||
@@ -389,7 +401,7 @@ void sbi_hart_update_extension(struct sbi_scratch *scratch,
|
||||
enum sbi_hart_extensions ext,
|
||||
bool enable)
|
||||
{
|
||||
struct hart_features *hfeatures =
|
||||
struct sbi_hart_features *hfeatures =
|
||||
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
||||
|
||||
__sbi_hart_update_extension(hfeatures, ext, enable);
|
||||
@@ -405,7 +417,7 @@ void sbi_hart_update_extension(struct sbi_scratch *scratch,
|
||||
bool sbi_hart_has_extension(struct sbi_scratch *scratch,
|
||||
enum sbi_hart_extensions ext)
|
||||
{
|
||||
struct hart_features *hfeatures =
|
||||
struct sbi_hart_features *hfeatures =
|
||||
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
||||
|
||||
if (hfeatures->extensions & BIT(ext))
|
||||
@@ -425,8 +437,8 @@ static inline char *sbi_hart_extension_id2string(int ext)
|
||||
case SBI_HART_EXT_TIME:
|
||||
estr = "time";
|
||||
break;
|
||||
case SBI_HART_EXT_AIA:
|
||||
estr = "aia";
|
||||
case SBI_HART_EXT_SMAIA:
|
||||
estr = "smaia";
|
||||
break;
|
||||
case SBI_HART_EXT_SSTC:
|
||||
estr = "sstc";
|
||||
@@ -453,7 +465,7 @@ static inline char *sbi_hart_extension_id2string(int ext)
|
||||
void sbi_hart_get_extensions_str(struct sbi_scratch *scratch,
|
||||
char *extensions_str, int nestr)
|
||||
{
|
||||
struct hart_features *hfeatures =
|
||||
struct sbi_hart_features *hfeatures =
|
||||
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
||||
int offset = 0, ext = 0;
|
||||
char *temp;
|
||||
@@ -539,7 +551,7 @@ static int hart_pmu_get_allowed_bits(void)
|
||||
static int hart_detect_features(struct sbi_scratch *scratch)
|
||||
{
|
||||
struct sbi_trap_info trap = {0};
|
||||
struct hart_features *hfeatures =
|
||||
struct sbi_hart_features *hfeatures =
|
||||
sbi_scratch_offset_ptr(scratch, hart_features_offset);
|
||||
unsigned long val, oldval;
|
||||
int rc;
|
||||
@@ -663,7 +675,7 @@ __mhpm_skip:
|
||||
csr_read_allowed(CSR_MTOPI, (unsigned long)&trap);
|
||||
if (!trap.cause)
|
||||
__sbi_hart_update_extension(hfeatures,
|
||||
SBI_HART_EXT_AIA, true);
|
||||
SBI_HART_EXT_SMAIA, true);
|
||||
|
||||
/* Detect if hart supports stimecmp CSR(Sstc extension) */
|
||||
if (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) {
|
||||
@@ -682,7 +694,8 @@ __mhpm_skip:
|
||||
}
|
||||
|
||||
/* Let platform populate extensions */
|
||||
rc = sbi_platform_extensions_init(sbi_platform_thishart_ptr());
|
||||
rc = sbi_platform_extensions_init(sbi_platform_thishart_ptr(),
|
||||
hfeatures);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
@@ -718,7 +731,7 @@ int sbi_hart_init(struct sbi_scratch *scratch, bool cold_boot)
|
||||
sbi_hart_expected_trap = &__sbi_expected_trap_hext;
|
||||
|
||||
hart_features_offset = sbi_scratch_alloc_offset(
|
||||
sizeof(struct hart_features));
|
||||
sizeof(struct sbi_hart_features));
|
||||
if (!hart_features_offset)
|
||||
return SBI_ENOMEM;
|
||||
}
|
||||
@@ -769,19 +782,12 @@ sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,
|
||||
#if __riscv_xlen == 32
|
||||
if (misa_extension('H')) {
|
||||
valH = csr_read(CSR_MSTATUSH);
|
||||
if (next_virt)
|
||||
valH = INSERT_FIELD(valH, MSTATUSH_MPV, 1);
|
||||
else
|
||||
valH = INSERT_FIELD(valH, MSTATUSH_MPV, 0);
|
||||
valH = INSERT_FIELD(valH, MSTATUSH_MPV, next_virt);
|
||||
csr_write(CSR_MSTATUSH, valH);
|
||||
}
|
||||
#else
|
||||
if (misa_extension('H')) {
|
||||
if (next_virt)
|
||||
val = INSERT_FIELD(val, MSTATUS_MPV, 1);
|
||||
else
|
||||
val = INSERT_FIELD(val, MSTATUS_MPV, 0);
|
||||
}
|
||||
if (misa_extension('H'))
|
||||
val = INSERT_FIELD(val, MSTATUS_MPV, next_virt);
|
||||
#endif
|
||||
csr_write(CSR_MSTATUS, val);
|
||||
csr_write(CSR_MEPC, next_addr);
|
||||
|
@@ -289,7 +289,9 @@ int sbi_hsm_hart_start(struct sbi_scratch *scratch,
|
||||
(hsm_device_has_hart_secondary_boot() && !init_count)) {
|
||||
return hsm_device_hart_start(hartid, scratch->warmboot_addr);
|
||||
} else {
|
||||
sbi_ipi_raw_send(hartid);
|
||||
int rc = sbi_ipi_raw_send(hartid);
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@@ -30,6 +30,7 @@ static int truly_illegal_insn(ulong insn, struct sbi_trap_regs *regs)
|
||||
trap.tval = insn;
|
||||
trap.tval2 = 0;
|
||||
trap.tinst = 0;
|
||||
trap.gva = 0;
|
||||
|
||||
return sbi_trap_redirect(regs, &trap);
|
||||
}
|
||||
@@ -39,6 +40,7 @@ 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;
|
||||
}
|
||||
|
||||
|
@@ -63,6 +63,7 @@ static void sbi_boot_print_banner(struct sbi_scratch *scratch)
|
||||
static void sbi_boot_print_general(struct sbi_scratch *scratch)
|
||||
{
|
||||
char str[128];
|
||||
const struct sbi_pmu_device *pdev;
|
||||
const struct sbi_hsm_device *hdev;
|
||||
const struct sbi_ipi_device *idev;
|
||||
const struct sbi_timer_device *tdev;
|
||||
@@ -93,6 +94,9 @@ static void sbi_boot_print_general(struct sbi_scratch *scratch)
|
||||
hdev = sbi_hsm_get_device();
|
||||
sbi_printf("Platform HSM Device : %s\n",
|
||||
(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);
|
||||
sbi_printf("Platform Reboot Device : %s\n",
|
||||
(srdev) ? srdev->name : "---");
|
||||
|
@@ -208,10 +208,13 @@ skip:
|
||||
};
|
||||
}
|
||||
|
||||
void sbi_ipi_raw_send(u32 target_hart)
|
||||
int sbi_ipi_raw_send(u32 target_hart)
|
||||
{
|
||||
if (ipi_dev && ipi_dev->ipi_send)
|
||||
ipi_dev->ipi_send(target_hart);
|
||||
if (!ipi_dev || !ipi_dev->ipi_send)
|
||||
return SBI_EINVAL;
|
||||
|
||||
ipi_dev->ipi_send(target_hart);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct sbi_ipi_device *sbi_ipi_get_device(void)
|
||||
|
@@ -129,6 +129,7 @@ int sbi_misaligned_load_handler(ulong addr, ulong tval2, ulong tinst,
|
||||
uptrap.tval = addr;
|
||||
uptrap.tval2 = tval2;
|
||||
uptrap.tinst = tinst;
|
||||
uptrap.gva = sbi_regs_gva(regs);
|
||||
return sbi_trap_redirect(regs, &uptrap);
|
||||
}
|
||||
|
||||
@@ -244,6 +245,7 @@ int sbi_misaligned_store_handler(ulong addr, ulong tval2, ulong tinst,
|
||||
uptrap.tval = addr;
|
||||
uptrap.tval2 = tval2;
|
||||
uptrap.tinst = tinst;
|
||||
uptrap.gva = sbi_regs_gva(regs);
|
||||
return sbi_trap_redirect(regs, &uptrap);
|
||||
}
|
||||
|
||||
|
@@ -10,7 +10,9 @@
|
||||
#include <sbi/riscv_asm.h>
|
||||
#include <sbi/sbi_bitops.h>
|
||||
#include <sbi/sbi_console.h>
|
||||
#include <sbi/sbi_ecall_interface.h>
|
||||
#include <sbi/sbi_hart.h>
|
||||
#include <sbi/sbi_hartmask.h>
|
||||
#include <sbi/sbi_platform.h>
|
||||
#include <sbi/sbi_pmu.h>
|
||||
#include <sbi/sbi_scratch.h>
|
||||
@@ -33,18 +35,6 @@ struct sbi_pmu_hw_event {
|
||||
uint64_t select_mask;
|
||||
};
|
||||
|
||||
/** Representation of a firmware event */
|
||||
struct sbi_pmu_fw_event {
|
||||
/* Event associated with the particular counter */
|
||||
uint32_t event_idx;
|
||||
|
||||
/* Current value of the counter */
|
||||
unsigned long curr_count;
|
||||
|
||||
/* A flag indicating pmu event monitoring is started */
|
||||
bool bStarted;
|
||||
};
|
||||
|
||||
/* Information about PMU counters as per SBI specification */
|
||||
union sbi_pmu_ctr_info {
|
||||
unsigned long value;
|
||||
@@ -60,14 +50,23 @@ union sbi_pmu_ctr_info {
|
||||
};
|
||||
};
|
||||
|
||||
/* Platform specific PMU device */
|
||||
static const struct sbi_pmu_device *pmu_dev = NULL;
|
||||
|
||||
/* Mapping between event range and possible counters */
|
||||
static struct sbi_pmu_hw_event hw_event_map[SBI_PMU_HW_EVENT_MAX] = {0};
|
||||
|
||||
/* counter to enabled event mapping */
|
||||
static uint32_t active_events[SBI_HARTMASK_MAX_BITS][SBI_PMU_HW_CTR_MAX + SBI_PMU_FW_CTR_MAX];
|
||||
|
||||
/* Contains all the information about firmwares events */
|
||||
static struct sbi_pmu_fw_event fw_event_map[SBI_HARTMASK_MAX_BITS][SBI_PMU_FW_EVENT_MAX] = {0};
|
||||
/* Bitmap of firmware counters started on each HART */
|
||||
#if SBI_PMU_FW_CTR_MAX >= BITS_PER_LONG
|
||||
#error "Can't handle firmware counters beyond BITS_PER_LONG"
|
||||
#endif
|
||||
static unsigned long fw_counters_started[SBI_HARTMASK_MAX_BITS];
|
||||
|
||||
/* Values of firmwares counters on each HART */
|
||||
static uint64_t fw_counters_value[SBI_HARTMASK_MAX_BITS][SBI_PMU_FW_CTR_MAX] = {0};
|
||||
|
||||
/* Maximum number of hardware events available */
|
||||
static uint32_t num_hw_events;
|
||||
@@ -107,19 +106,66 @@ static bool pmu_event_select_overlap(struct sbi_pmu_hw_event *evt,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static int pmu_event_validate(unsigned long event_idx)
|
||||
{
|
||||
uint32_t event_idx_type = get_cidx_type(event_idx);
|
||||
uint32_t event_idx_code = get_cidx_code(event_idx);
|
||||
uint32_t event_idx_code_max = -1;
|
||||
uint32_t cache_ops_result, cache_ops_id, cache_id;
|
||||
|
||||
switch(event_idx_type) {
|
||||
case SBI_PMU_EVENT_TYPE_HW:
|
||||
event_idx_code_max = SBI_PMU_HW_GENERAL_MAX;
|
||||
break;
|
||||
case SBI_PMU_EVENT_TYPE_FW:
|
||||
if (SBI_PMU_FW_MAX <= event_idx_code &&
|
||||
pmu_dev && pmu_dev->fw_event_validate_code)
|
||||
return pmu_dev->fw_event_validate_code(event_idx_code);
|
||||
else
|
||||
event_idx_code_max = SBI_PMU_FW_MAX;
|
||||
break;
|
||||
case SBI_PMU_EVENT_TYPE_HW_CACHE:
|
||||
cache_ops_result = event_idx_code &
|
||||
SBI_PMU_EVENT_HW_CACHE_OPS_RESULT;
|
||||
cache_ops_id = (event_idx_code &
|
||||
SBI_PMU_EVENT_HW_CACHE_OPS_ID_MASK) >>
|
||||
SBI_PMU_EVENT_HW_CACHE_OPS_ID_OFFSET;
|
||||
cache_id = (event_idx_code &
|
||||
SBI_PMU_EVENT_HW_CACHE_ID_MASK) >>
|
||||
SBI_PMU_EVENT_HW_CACHE_ID_OFFSET;
|
||||
if ((cache_ops_result < SBI_PMU_HW_CACHE_RESULT_MAX) &&
|
||||
(cache_ops_id < SBI_PMU_HW_CACHE_OP_MAX) &&
|
||||
(cache_id < SBI_PMU_HW_CACHE_MAX))
|
||||
return event_idx_type;
|
||||
else
|
||||
return SBI_EINVAL;
|
||||
break;
|
||||
case SBI_PMU_EVENT_TYPE_HW_RAW:
|
||||
event_idx_code_max = 1; // event_idx.code should be zero
|
||||
break;
|
||||
default:
|
||||
return SBI_EINVAL;
|
||||
}
|
||||
|
||||
if (event_idx_code < event_idx_code_max)
|
||||
return event_idx_type;
|
||||
|
||||
return SBI_EINVAL;
|
||||
}
|
||||
|
||||
static int pmu_ctr_validate(uint32_t cidx, uint32_t *event_idx_code)
|
||||
{
|
||||
uint32_t event_idx_val;
|
||||
uint32_t event_idx_type;
|
||||
u32 hartid = current_hartid();
|
||||
|
||||
event_idx_val = active_events[hartid][cidx];
|
||||
|
||||
if (cidx >= total_ctrs || (event_idx_val == SBI_PMU_EVENT_IDX_INVALID))
|
||||
if (cidx >= total_ctrs)
|
||||
return SBI_EINVAL;
|
||||
|
||||
event_idx_val = active_events[hartid][cidx];
|
||||
event_idx_type = get_cidx_type(event_idx_val);
|
||||
if (event_idx_type >= SBI_PMU_EVENT_TYPE_MAX)
|
||||
if (event_idx_val == SBI_PMU_EVENT_IDX_INVALID ||
|
||||
event_idx_type >= SBI_PMU_EVENT_TYPE_MAX)
|
||||
return SBI_EINVAL;
|
||||
|
||||
*event_idx_code = get_cidx_code(event_idx_val);
|
||||
@@ -127,50 +173,22 @@ static int pmu_ctr_validate(uint32_t cidx, uint32_t *event_idx_code)
|
||||
return event_idx_type;
|
||||
}
|
||||
|
||||
static int pmu_ctr_read_fw(uint32_t cidx, unsigned long *cval,
|
||||
uint32_t fw_evt_code)
|
||||
{
|
||||
u32 hartid = current_hartid();
|
||||
struct sbi_pmu_fw_event fevent;
|
||||
|
||||
fevent = fw_event_map[hartid][fw_evt_code];
|
||||
*cval = fevent.curr_count;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Add a hardware counter read for completeness for future purpose */
|
||||
static int pmu_ctr_read_hw(uint32_t cidx, uint64_t *cval)
|
||||
{
|
||||
/* Check for invalid hw counter read requests */
|
||||
if (unlikely(cidx == 1))
|
||||
return SBI_EINVAL;
|
||||
#if __riscv_xlen == 32
|
||||
uint32_t temp, temph = 0;
|
||||
|
||||
temp = csr_read_num(CSR_MCYCLE + cidx);
|
||||
temph = csr_read_num(CSR_MCYCLEH + cidx);
|
||||
*cval = ((uint64_t)temph << 32) | temp;
|
||||
#else
|
||||
*cval = csr_read_num(CSR_MCYCLE + cidx);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sbi_pmu_ctr_read(uint32_t cidx, unsigned long *cval)
|
||||
int sbi_pmu_ctr_fw_read(uint32_t cidx, uint64_t *cval)
|
||||
{
|
||||
int event_idx_type;
|
||||
uint32_t event_code;
|
||||
uint64_t cval64;
|
||||
u32 hartid = current_hartid();
|
||||
|
||||
event_idx_type = pmu_ctr_validate(cidx, &event_code);
|
||||
if (event_idx_type < 0)
|
||||
if (event_idx_type != SBI_PMU_EVENT_TYPE_FW)
|
||||
return SBI_EINVAL;
|
||||
else if (event_idx_type == SBI_PMU_EVENT_TYPE_FW)
|
||||
pmu_ctr_read_fw(cidx, cval, event_code);
|
||||
else
|
||||
pmu_ctr_read_hw(cidx, &cval64);
|
||||
|
||||
if (SBI_PMU_FW_MAX <= event_code &&
|
||||
pmu_dev && pmu_dev->fw_counter_read_value)
|
||||
fw_counters_value[hartid][cidx - num_hw_ctrs] =
|
||||
pmu_dev->fw_counter_read_value(cidx - num_hw_ctrs);
|
||||
|
||||
*cval = fw_counters_value[hartid][cidx - num_hw_ctrs];
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -315,6 +333,8 @@ static int pmu_ctr_start_hw(uint32_t cidx, uint64_t ival, bool ival_update)
|
||||
|
||||
if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCOFPMF))
|
||||
pmu_ctr_enable_irq_hw(cidx);
|
||||
if (pmu_dev && pmu_dev->hw_counter_enable_irq)
|
||||
pmu_dev->hw_counter_enable_irq(cidx);
|
||||
csr_write(CSR_MCOUNTINHIBIT, mctr_inhbt);
|
||||
|
||||
skip_inhibit_update:
|
||||
@@ -324,16 +344,36 @@ skip_inhibit_update:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pmu_ctr_start_fw(uint32_t cidx, uint32_t fw_evt_code,
|
||||
int sbi_pmu_irq_bit(void)
|
||||
{
|
||||
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
||||
|
||||
if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCOFPMF))
|
||||
return MIP_LCOFIP;
|
||||
if (pmu_dev && pmu_dev->hw_counter_irq_bit)
|
||||
return pmu_dev->hw_counter_irq_bit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pmu_ctr_start_fw(uint32_t cidx, uint32_t event_code,
|
||||
uint64_t ival, bool ival_update)
|
||||
{
|
||||
int ret;
|
||||
u32 hartid = current_hartid();
|
||||
struct sbi_pmu_fw_event *fevent;
|
||||
|
||||
fevent = &fw_event_map[hartid][fw_evt_code];
|
||||
if (SBI_PMU_FW_MAX <= event_code &&
|
||||
pmu_dev && pmu_dev->fw_counter_start) {
|
||||
ret = pmu_dev->fw_counter_start(cidx - num_hw_ctrs,
|
||||
event_code,
|
||||
ival, ival_update);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (ival_update)
|
||||
fevent->curr_count = ival;
|
||||
fevent->bStarted = TRUE;
|
||||
fw_counters_value[hartid][cidx - num_hw_ctrs] = ival;
|
||||
fw_counters_started[hartid] |= BIT(cidx - num_hw_ctrs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -343,25 +383,26 @@ int sbi_pmu_ctr_start(unsigned long cbase, unsigned long cmask,
|
||||
{
|
||||
int event_idx_type;
|
||||
uint32_t event_code;
|
||||
unsigned long ctr_mask = cmask << cbase;
|
||||
int ret = SBI_EINVAL;
|
||||
bool bUpdate = FALSE;
|
||||
int i, cidx;
|
||||
|
||||
if (sbi_fls(ctr_mask) >= total_ctrs)
|
||||
if ((cbase + sbi_fls(cmask)) >= total_ctrs)
|
||||
return ret;
|
||||
|
||||
if (flags & SBI_PMU_START_FLAG_SET_INIT_VALUE)
|
||||
bUpdate = TRUE;
|
||||
|
||||
for_each_set_bit_from(cbase, &ctr_mask, total_ctrs) {
|
||||
event_idx_type = pmu_ctr_validate(cbase, &event_code);
|
||||
for_each_set_bit(i, &cmask, total_ctrs) {
|
||||
cidx = i + cbase;
|
||||
event_idx_type = pmu_ctr_validate(cidx, &event_code);
|
||||
if (event_idx_type < 0)
|
||||
/* Continue the start operation for other counters */
|
||||
continue;
|
||||
else if (event_idx_type == SBI_PMU_EVENT_TYPE_FW)
|
||||
ret = pmu_ctr_start_fw(cbase, event_code, ival, bUpdate);
|
||||
ret = pmu_ctr_start_fw(cidx, event_code, ival, bUpdate);
|
||||
else
|
||||
ret = pmu_ctr_start_hw(cbase, ival, bUpdate);
|
||||
ret = pmu_ctr_start_hw(cidx, ival, bUpdate);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -389,11 +430,18 @@ static int pmu_ctr_stop_hw(uint32_t cidx)
|
||||
return SBI_EALREADY_STOPPED;
|
||||
}
|
||||
|
||||
static int pmu_ctr_stop_fw(uint32_t cidx, uint32_t fw_evt_code)
|
||||
static int pmu_ctr_stop_fw(uint32_t cidx, uint32_t event_code)
|
||||
{
|
||||
u32 hartid = current_hartid();
|
||||
int ret;
|
||||
|
||||
fw_event_map[hartid][fw_evt_code].bStarted = FALSE;
|
||||
if (SBI_PMU_FW_MAX <= event_code &&
|
||||
pmu_dev && pmu_dev->fw_counter_stop) {
|
||||
ret = pmu_dev->fw_counter_stop(cidx - num_hw_ctrs);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
fw_counters_started[current_hartid()] &= ~BIT(cidx - num_hw_ctrs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -421,25 +469,26 @@ int sbi_pmu_ctr_stop(unsigned long cbase, unsigned long cmask,
|
||||
int ret = SBI_EINVAL;
|
||||
int event_idx_type;
|
||||
uint32_t event_code;
|
||||
unsigned long ctr_mask = cmask << cbase;
|
||||
int i, cidx;
|
||||
|
||||
if (sbi_fls(ctr_mask) >= total_ctrs)
|
||||
if ((cbase + sbi_fls(cmask)) >= total_ctrs)
|
||||
return SBI_EINVAL;
|
||||
|
||||
for_each_set_bit_from(cbase, &ctr_mask, total_ctrs) {
|
||||
event_idx_type = pmu_ctr_validate(cbase, &event_code);
|
||||
for_each_set_bit(i, &cmask, total_ctrs) {
|
||||
cidx = i + cbase;
|
||||
event_idx_type = pmu_ctr_validate(cidx, &event_code);
|
||||
if (event_idx_type < 0)
|
||||
/* Continue the stop operation for other counters */
|
||||
continue;
|
||||
|
||||
else if (event_idx_type == SBI_PMU_EVENT_TYPE_FW)
|
||||
ret = pmu_ctr_stop_fw(cbase, event_code);
|
||||
ret = pmu_ctr_stop_fw(cidx, event_code);
|
||||
else
|
||||
ret = pmu_ctr_stop_hw(cbase);
|
||||
ret = pmu_ctr_stop_hw(cidx);
|
||||
|
||||
if (flag & SBI_PMU_STOP_FLAG_RESET) {
|
||||
active_events[hartid][cbase] = SBI_PMU_EVENT_IDX_INVALID;
|
||||
pmu_reset_hw_mhpmevent(cbase);
|
||||
active_events[hartid][cidx] = SBI_PMU_EVENT_IDX_INVALID;
|
||||
pmu_reset_hw_mhpmevent(cidx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -480,6 +529,9 @@ static int pmu_update_hw_mhpmevent(struct sbi_pmu_hw_event *hw_evt, int ctr_idx,
|
||||
mhpmevent_val = (mhpmevent_val & ~MHPMEVENT_SSCOF_MASK) |
|
||||
MHPMEVENT_MINH | MHPMEVENT_OF;
|
||||
|
||||
if (pmu_dev && pmu_dev->hw_counter_disable_irq)
|
||||
pmu_dev->hw_counter_disable_irq(ctr_idx);
|
||||
|
||||
/* Update the inhibit flags based on inhibit flags received from supervisor */
|
||||
pmu_update_inhibit_flags(flags, &mhpmevent_val);
|
||||
|
||||
@@ -587,21 +639,26 @@ static int pmu_ctr_find_hw(unsigned long cbase, unsigned long cmask, unsigned lo
|
||||
* Thus, select the first available fw counter after sanity
|
||||
* check.
|
||||
*/
|
||||
static int pmu_ctr_find_fw(unsigned long cbase, unsigned long cmask, u32 hartid)
|
||||
static int pmu_ctr_find_fw(unsigned long cbase, unsigned long cmask,
|
||||
uint32_t event_code, u32 hartid)
|
||||
{
|
||||
int i = 0;
|
||||
int fw_base;
|
||||
unsigned long ctr_mask = cmask << cbase;
|
||||
int i, cidx;
|
||||
|
||||
if (cbase < num_hw_ctrs)
|
||||
fw_base = num_hw_ctrs;
|
||||
else
|
||||
fw_base = cbase;
|
||||
for_each_set_bit(i, &cmask, BITS_PER_LONG) {
|
||||
cidx = i + cbase;
|
||||
if (cidx < num_hw_ctrs || total_ctrs <= cidx)
|
||||
continue;
|
||||
if (active_events[hartid][i] != SBI_PMU_EVENT_IDX_INVALID)
|
||||
continue;
|
||||
if (SBI_PMU_FW_MAX <= event_code &&
|
||||
pmu_dev && pmu_dev->fw_counter_match_code) {
|
||||
if (!pmu_dev->fw_counter_match_code(cidx - num_hw_ctrs,
|
||||
event_code))
|
||||
continue;
|
||||
}
|
||||
|
||||
for (i = fw_base; i < total_ctrs; i++)
|
||||
if ((active_events[hartid][i] == SBI_PMU_EVENT_IDX_INVALID) &&
|
||||
((1UL << i) & ctr_mask))
|
||||
return i;
|
||||
return i;
|
||||
}
|
||||
|
||||
return SBI_ENOTSUPP;
|
||||
}
|
||||
@@ -610,17 +667,19 @@ int sbi_pmu_ctr_cfg_match(unsigned long cidx_base, unsigned long cidx_mask,
|
||||
unsigned long flags, unsigned long event_idx,
|
||||
uint64_t event_data)
|
||||
{
|
||||
int ctr_idx = SBI_ENOTSUPP;
|
||||
u32 hartid = current_hartid();
|
||||
int event_type = get_cidx_type(event_idx);
|
||||
struct sbi_pmu_fw_event *fevent;
|
||||
uint32_t fw_evt_code;
|
||||
unsigned long tmp = cidx_mask << cidx_base;
|
||||
int ret, ctr_idx = SBI_ENOTSUPP;
|
||||
u32 event_code, hartid = current_hartid();
|
||||
int event_type;
|
||||
|
||||
/* Do a basic sanity check of counter base & mask */
|
||||
if (sbi_fls(tmp) >= total_ctrs || event_type >= SBI_PMU_EVENT_TYPE_MAX)
|
||||
if ((cidx_base + sbi_fls(cidx_mask)) >= total_ctrs)
|
||||
return SBI_EINVAL;
|
||||
|
||||
event_type = pmu_event_validate(event_idx);
|
||||
if (event_type < 0)
|
||||
return SBI_EINVAL;
|
||||
event_code = get_cidx_code(event_idx);
|
||||
|
||||
if (flags & SBI_PMU_CFG_FLAG_SKIP_MATCH) {
|
||||
/* The caller wants to skip the match because it already knows the
|
||||
* counter idx for the given event. Verify that the counter idx
|
||||
@@ -634,7 +693,7 @@ int sbi_pmu_ctr_cfg_match(unsigned long cidx_base, unsigned long cidx_mask,
|
||||
|
||||
if (event_type == SBI_PMU_EVENT_TYPE_FW) {
|
||||
/* Any firmware counter can be used track any firmware event */
|
||||
ctr_idx = pmu_ctr_find_fw(cidx_base, cidx_mask, hartid);
|
||||
ctr_idx = pmu_ctr_find_fw(cidx_base, cidx_mask, event_code, hartid);
|
||||
} else {
|
||||
ctr_idx = pmu_ctr_find_hw(cidx_base, cidx_mask, flags, event_idx,
|
||||
event_data);
|
||||
@@ -651,30 +710,46 @@ skip_match:
|
||||
if (flags & SBI_PMU_CFG_FLAG_AUTO_START)
|
||||
pmu_ctr_start_hw(ctr_idx, 0, false);
|
||||
} else if (event_type == SBI_PMU_EVENT_TYPE_FW) {
|
||||
fw_evt_code = get_cidx_code(event_idx);
|
||||
fevent = &fw_event_map[hartid][fw_evt_code];
|
||||
if (flags & SBI_PMU_CFG_FLAG_CLEAR_VALUE)
|
||||
fevent->curr_count = 0;
|
||||
if (flags & SBI_PMU_CFG_FLAG_AUTO_START)
|
||||
fevent->bStarted = TRUE;
|
||||
fw_counters_value[hartid][ctr_idx - num_hw_ctrs] = 0;
|
||||
if (flags & SBI_PMU_CFG_FLAG_AUTO_START) {
|
||||
if (SBI_PMU_FW_MAX <= event_code &&
|
||||
pmu_dev && pmu_dev->fw_counter_start) {
|
||||
ret = pmu_dev->fw_counter_start(
|
||||
ctr_idx - num_hw_ctrs, event_code,
|
||||
fw_counters_value[hartid][ctr_idx - num_hw_ctrs],
|
||||
true);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
fw_counters_started[hartid] |= BIT(ctr_idx - num_hw_ctrs);
|
||||
}
|
||||
}
|
||||
|
||||
return ctr_idx;
|
||||
}
|
||||
|
||||
inline int sbi_pmu_ctr_incr_fw(enum sbi_pmu_fw_event_code_id fw_id)
|
||||
int sbi_pmu_ctr_incr_fw(enum sbi_pmu_fw_event_code_id fw_id)
|
||||
{
|
||||
u32 hartid = current_hartid();
|
||||
struct sbi_pmu_fw_event *fevent;
|
||||
u32 cidx, hartid = current_hartid();
|
||||
uint64_t *fcounter = NULL;
|
||||
|
||||
if (likely(!fw_counters_started[hartid]))
|
||||
return 0;
|
||||
|
||||
if (unlikely(fw_id >= SBI_PMU_FW_MAX))
|
||||
return SBI_EINVAL;
|
||||
|
||||
fevent = &fw_event_map[hartid][fw_id];
|
||||
for (cidx = num_hw_ctrs; cidx < total_ctrs; cidx++) {
|
||||
if (get_cidx_code(active_events[hartid][cidx]) == fw_id &&
|
||||
(fw_counters_started[hartid] & BIT(cidx - num_hw_ctrs))) {
|
||||
fcounter = &fw_counters_value[hartid][cidx - num_hw_ctrs];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* PMU counters will be only enabled during performance debugging */
|
||||
if (unlikely(fevent->bStarted))
|
||||
fevent->curr_count++;
|
||||
if (fcounter)
|
||||
(*fcounter)++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -705,8 +780,8 @@ int sbi_pmu_ctr_get_info(uint32_t cidx, unsigned long *ctr_info)
|
||||
} else {
|
||||
/* it's a firmware counter */
|
||||
cinfo.type = SBI_PMU_CTR_TYPE_FW;
|
||||
/* Firmware counters are XLEN bits wide */
|
||||
cinfo.width = BITS_PER_LONG - 1;
|
||||
/* Firmware counters are always 64 bits wide */
|
||||
cinfo.width = 63;
|
||||
}
|
||||
|
||||
*ctr_info = cinfo.value;
|
||||
@@ -722,8 +797,21 @@ static void pmu_reset_event_map(u32 hartid)
|
||||
for (j = 3; j < total_ctrs; j++)
|
||||
active_events[hartid][j] = SBI_PMU_EVENT_IDX_INVALID;
|
||||
for (j = 0; j < SBI_PMU_FW_CTR_MAX; j++)
|
||||
sbi_memset(&fw_event_map[hartid][j], 0,
|
||||
sizeof(struct sbi_pmu_fw_event));
|
||||
fw_counters_value[hartid][j] = 0;
|
||||
fw_counters_started[hartid] = 0;
|
||||
}
|
||||
|
||||
const struct sbi_pmu_device *sbi_pmu_get_device(void)
|
||||
{
|
||||
return pmu_dev;
|
||||
}
|
||||
|
||||
void sbi_pmu_set_device(const struct sbi_pmu_device *dev)
|
||||
{
|
||||
if (!dev || pmu_dev)
|
||||
return;
|
||||
|
||||
pmu_dev = dev;
|
||||
}
|
||||
|
||||
void sbi_pmu_exit(struct sbi_scratch *scratch)
|
||||
|
@@ -59,7 +59,6 @@ size_t sbi_strnlen(const char *str, size_t count)
|
||||
while (*str != '\0' && ret < count) {
|
||||
ret++;
|
||||
str++;
|
||||
count--;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@@ -76,6 +76,19 @@ void sbi_timer_delay_loop(ulong units, u64 unit_freq,
|
||||
delay_fn(opaque);
|
||||
}
|
||||
|
||||
bool sbi_timer_waitms_until(bool (*predicate)(void *), void *arg,
|
||||
uint64_t timeout_ms)
|
||||
{
|
||||
uint64_t start_time = sbi_timer_value();
|
||||
uint64_t ticks =
|
||||
(sbi_timer_get_device()->timer_freq / 1000) *
|
||||
timeout_ms;
|
||||
while(!predicate(arg))
|
||||
if (sbi_timer_value() - start_time >= ticks)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
u64 sbi_timer_value(void)
|
||||
{
|
||||
if (get_time_val)
|
||||
|
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <sbi/riscv_asm.h>
|
||||
#include <sbi/riscv_encoding.h>
|
||||
#include <sbi/sbi_bitops.h>
|
||||
#include <sbi/sbi_console.h>
|
||||
#include <sbi/sbi_ecall.h>
|
||||
#include <sbi/sbi_error.h>
|
||||
@@ -118,14 +119,18 @@ int sbi_trap_redirect(struct sbi_trap_regs *regs,
|
||||
regs->mstatus |= (next_virt) ? MSTATUS_MPV : 0UL;
|
||||
#endif
|
||||
|
||||
/* Update HSTATUS for VS/VU-mode to HS-mode transition */
|
||||
if (misa_extension('H') && prev_virt && !next_virt) {
|
||||
/* Update HSTATUS SPVP and SPV bits */
|
||||
/* Update hypervisor CSRs if going to HS-mode */
|
||||
if (misa_extension('H') && !next_virt) {
|
||||
hstatus = csr_read(CSR_HSTATUS);
|
||||
hstatus &= ~HSTATUS_SPVP;
|
||||
hstatus |= (prev_mode == PRV_S) ? HSTATUS_SPVP : 0;
|
||||
if (prev_virt) {
|
||||
/* hstatus.SPVP is only updated if coming from VS/VU-mode */
|
||||
hstatus &= ~HSTATUS_SPVP;
|
||||
hstatus |= (prev_mode == PRV_S) ? HSTATUS_SPVP : 0;
|
||||
}
|
||||
hstatus &= ~HSTATUS_SPV;
|
||||
hstatus |= (prev_virt) ? HSTATUS_SPV : 0;
|
||||
hstatus &= ~HSTATUS_GVA;
|
||||
hstatus |= (trap->gva) ? HSTATUS_GVA : 0;
|
||||
csr_write(CSR_HSTATUS, hstatus);
|
||||
csr_write(CSR_HTVAL, trap->tval2);
|
||||
csr_write(CSR_HTINST, trap->tinst);
|
||||
@@ -270,7 +275,7 @@ struct sbi_trap_regs *sbi_trap_handler(struct sbi_trap_regs *regs)
|
||||
|
||||
if (mcause & (1UL << (__riscv_xlen - 1))) {
|
||||
if (sbi_hart_has_extension(sbi_scratch_thishart_ptr(),
|
||||
SBI_HART_EXT_AIA))
|
||||
SBI_HART_EXT_SMAIA))
|
||||
rc = sbi_trap_aia_irq(regs, mcause);
|
||||
else
|
||||
rc = sbi_trap_nonaia_irq(regs, mcause);
|
||||
@@ -311,6 +316,8 @@ struct sbi_trap_regs *sbi_trap_handler(struct sbi_trap_regs *regs)
|
||||
trap.tval = mtval;
|
||||
trap.tval2 = mtval2;
|
||||
trap.tinst = mtinst;
|
||||
trap.gva = sbi_regs_gva(regs);
|
||||
|
||||
rc = sbi_trap_redirect(regs, &trap);
|
||||
break;
|
||||
};
|
||||
|
25
lib/utils/Kconfig
Normal file
25
lib/utils/Kconfig
Normal file
@@ -0,0 +1,25 @@
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
menu "Utils and Drivers Support"
|
||||
|
||||
source "$(OPENSBI_SRC_DIR)/lib/utils/fdt/Kconfig"
|
||||
|
||||
source "$(OPENSBI_SRC_DIR)/lib/utils/gpio/Kconfig"
|
||||
|
||||
source "$(OPENSBI_SRC_DIR)/lib/utils/i2c/Kconfig"
|
||||
|
||||
source "$(OPENSBI_SRC_DIR)/lib/utils/ipi/Kconfig"
|
||||
|
||||
source "$(OPENSBI_SRC_DIR)/lib/utils/irqchip/Kconfig"
|
||||
|
||||
source "$(OPENSBI_SRC_DIR)/lib/utils/libfdt/Kconfig"
|
||||
|
||||
source "$(OPENSBI_SRC_DIR)/lib/utils/reset/Kconfig"
|
||||
|
||||
source "$(OPENSBI_SRC_DIR)/lib/utils/serial/Kconfig"
|
||||
|
||||
source "$(OPENSBI_SRC_DIR)/lib/utils/sys/Kconfig"
|
||||
|
||||
source "$(OPENSBI_SRC_DIR)/lib/utils/timer/Kconfig"
|
||||
|
||||
endmenu
|
18
lib/utils/fdt/Kconfig
Normal file
18
lib/utils/fdt/Kconfig
Normal file
@@ -0,0 +1,18 @@
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
menuconfig FDT
|
||||
bool "Flattened Device Tree (FDT) support"
|
||||
select LIBFDT
|
||||
default n
|
||||
|
||||
if FDT
|
||||
|
||||
config FDT_DOMAIN
|
||||
bool "FDT domain support"
|
||||
default n
|
||||
|
||||
config FDT_PMU
|
||||
bool "FDT performance monitoring unit (PMU) support"
|
||||
default n
|
||||
|
||||
endif
|
@@ -246,7 +246,7 @@ static int __fdt_parse_region(void *fdt, int domain_offset,
|
||||
|
||||
/* Read "base" DT property */
|
||||
val = fdt_getprop(fdt, region_offset, "base", &len);
|
||||
if (!val && len >= 8)
|
||||
if (!val || len != 8)
|
||||
return SBI_EINVAL;
|
||||
val64 = fdt32_to_cpu(val[0]);
|
||||
val64 = (val64 << 32) | fdt32_to_cpu(val[1]);
|
||||
@@ -254,7 +254,7 @@ static int __fdt_parse_region(void *fdt, int domain_offset,
|
||||
|
||||
/* Read "order" DT property */
|
||||
val = fdt_getprop(fdt, region_offset, "order", &len);
|
||||
if (!val && len >= 4)
|
||||
if (!val || len != 4)
|
||||
return SBI_EINVAL;
|
||||
val32 = fdt32_to_cpu(*val);
|
||||
if (val32 < 3 || __riscv_xlen < val32)
|
||||
|
@@ -74,22 +74,23 @@ static void fdt_domain_based_fixup_one(void *fdt, int nodeoff)
|
||||
}
|
||||
}
|
||||
|
||||
void fdt_aplic_fixup(void *fdt)
|
||||
static void fdt_fixup_node(void *fdt, const char *compatible)
|
||||
{
|
||||
int noff = 0;
|
||||
|
||||
while ((noff = fdt_node_offset_by_compatible(fdt, noff,
|
||||
"riscv,aplic")) >= 0)
|
||||
compatible)) >= 0)
|
||||
fdt_domain_based_fixup_one(fdt, noff);
|
||||
}
|
||||
|
||||
void fdt_aplic_fixup(void *fdt)
|
||||
{
|
||||
fdt_fixup_node(fdt, "riscv,aplic");
|
||||
}
|
||||
|
||||
void fdt_imsic_fixup(void *fdt)
|
||||
{
|
||||
int noff = 0;
|
||||
|
||||
while ((noff = fdt_node_offset_by_compatible(fdt, noff,
|
||||
"riscv,imsics")) >= 0)
|
||||
fdt_domain_based_fixup_one(fdt, noff);
|
||||
fdt_fixup_node(fdt, "riscv,imsics");
|
||||
}
|
||||
|
||||
void fdt_plic_fixup(void *fdt)
|
||||
|
@@ -23,12 +23,11 @@
|
||||
#define DEFAULT_UART_REG_IO_WIDTH 1
|
||||
#define DEFAULT_UART_REG_OFFSET 0
|
||||
|
||||
#define DEFAULT_RENESAS_SCIF_FREQ 100000000
|
||||
#define DEFAULT_RENESAS_SCIF_BAUD 115200
|
||||
|
||||
#define DEFAULT_SIFIVE_UART_FREQ 0
|
||||
#define DEFAULT_SIFIVE_UART_BAUD 115200
|
||||
#define DEFAULT_SIFIVE_UART_REG_SHIFT 0
|
||||
#define DEFAULT_SIFIVE_UART_REG_IO_WIDTH 4
|
||||
|
||||
#define DEFAULT_GAISLER_UART_REG_IO_WIDTH 4
|
||||
|
||||
#define DEFAULT_SHAKTI_UART_FREQ 50000000
|
||||
#define DEFAULT_SHAKTI_UART_BAUD 115200
|
||||
@@ -128,7 +127,7 @@ static int fdt_translate_address(void *fdt, uint64_t reg, int parent,
|
||||
int i, rlen;
|
||||
int cell_addr, cell_size;
|
||||
const fdt32_t *ranges;
|
||||
uint64_t offset = 0, caddr = 0, paddr = 0, rsize = 0;
|
||||
uint64_t offset, caddr = 0, paddr = 0, rsize = 0;
|
||||
|
||||
cell_addr = fdt_address_cells(fdt, parent);
|
||||
if (cell_addr < 1)
|
||||
@@ -314,8 +313,10 @@ int fdt_parse_timebase_frequency(void *fdt, unsigned long *freq)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fdt_parse_gaisler_uart_node(void *fdt, int nodeoffset,
|
||||
struct platform_uart_data *uart)
|
||||
static int fdt_parse_uart_node_common(void *fdt, int nodeoffset,
|
||||
struct platform_uart_data *uart,
|
||||
unsigned long default_freq,
|
||||
unsigned long default_baud)
|
||||
{
|
||||
int len, rc;
|
||||
const fdt32_t *val;
|
||||
@@ -338,126 +339,60 @@ int fdt_parse_gaisler_uart_node(void *fdt, int nodeoffset,
|
||||
if (len > 0 && val)
|
||||
uart->freq = fdt32_to_cpu(*val);
|
||||
else
|
||||
uart->freq = DEFAULT_UART_FREQ;
|
||||
uart->freq = default_freq;
|
||||
|
||||
val = (fdt32_t *)fdt_getprop(fdt, nodeoffset, "current-speed", &len);
|
||||
if (len > 0 && val)
|
||||
uart->baud = fdt32_to_cpu(*val);
|
||||
else
|
||||
uart->baud = DEFAULT_UART_BAUD;
|
||||
|
||||
/* For Gaisler APBUART, the reg-shift and reg-io-width are fixed .*/
|
||||
uart->reg_shift = DEFAULT_UART_REG_SHIFT;
|
||||
uart->reg_io_width = DEFAULT_GAISLER_UART_REG_IO_WIDTH;
|
||||
uart->baud = default_baud;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fdt_parse_gaisler_uart_node(void *fdt, int nodeoffset,
|
||||
struct platform_uart_data *uart)
|
||||
{
|
||||
return fdt_parse_uart_node_common(fdt, nodeoffset, uart,
|
||||
DEFAULT_UART_FREQ,
|
||||
DEFAULT_UART_BAUD);
|
||||
}
|
||||
|
||||
int fdt_parse_renesas_scif_node(void *fdt, int nodeoffset,
|
||||
struct platform_uart_data *uart)
|
||||
{
|
||||
return fdt_parse_uart_node_common(fdt, nodeoffset, uart,
|
||||
DEFAULT_RENESAS_SCIF_FREQ,
|
||||
DEFAULT_RENESAS_SCIF_BAUD);
|
||||
}
|
||||
|
||||
int fdt_parse_shakti_uart_node(void *fdt, int nodeoffset,
|
||||
struct platform_uart_data *uart)
|
||||
{
|
||||
int len, rc;
|
||||
const fdt32_t *val;
|
||||
uint64_t reg_addr, reg_size;
|
||||
|
||||
if (nodeoffset < 0 || !uart || !fdt)
|
||||
return SBI_ENODEV;
|
||||
|
||||
rc = fdt_get_node_addr_size(fdt, nodeoffset, 0,
|
||||
®_addr, ®_size);
|
||||
if (rc < 0 || !reg_addr || !reg_size)
|
||||
return SBI_ENODEV;
|
||||
uart->addr = reg_addr;
|
||||
|
||||
/**
|
||||
* UART address is mandaotry. clock-frequency and current-speed
|
||||
* may not be present. Don't return error.
|
||||
*/
|
||||
val = (fdt32_t *)fdt_getprop(fdt, nodeoffset, "clock-frequency", &len);
|
||||
if (len > 0 && val)
|
||||
uart->freq = fdt32_to_cpu(*val);
|
||||
else
|
||||
uart->freq = DEFAULT_SHAKTI_UART_FREQ;
|
||||
|
||||
val = (fdt32_t *)fdt_getprop(fdt, nodeoffset, "current-speed", &len);
|
||||
if (len > 0 && val)
|
||||
uart->baud = fdt32_to_cpu(*val);
|
||||
else
|
||||
uart->baud = DEFAULT_SHAKTI_UART_BAUD;
|
||||
|
||||
return 0;
|
||||
return fdt_parse_uart_node_common(fdt, nodeoffset, uart,
|
||||
DEFAULT_SHAKTI_UART_FREQ,
|
||||
DEFAULT_SHAKTI_UART_BAUD);
|
||||
}
|
||||
|
||||
int fdt_parse_sifive_uart_node(void *fdt, int nodeoffset,
|
||||
struct platform_uart_data *uart)
|
||||
{
|
||||
int len, rc;
|
||||
const fdt32_t *val;
|
||||
uint64_t reg_addr, reg_size;
|
||||
|
||||
if (nodeoffset < 0 || !uart || !fdt)
|
||||
return SBI_ENODEV;
|
||||
|
||||
rc = fdt_get_node_addr_size(fdt, nodeoffset, 0,
|
||||
®_addr, ®_size);
|
||||
if (rc < 0 || !reg_addr || !reg_size)
|
||||
return SBI_ENODEV;
|
||||
uart->addr = reg_addr;
|
||||
|
||||
/**
|
||||
* UART address is mandaotry. clock-frequency and current-speed
|
||||
* may not be present. Don't return error.
|
||||
*/
|
||||
val = (fdt32_t *)fdt_getprop(fdt, nodeoffset, "clock-frequency", &len);
|
||||
if (len > 0 && val)
|
||||
uart->freq = fdt32_to_cpu(*val);
|
||||
else
|
||||
uart->freq = DEFAULT_SIFIVE_UART_FREQ;
|
||||
|
||||
val = (fdt32_t *)fdt_getprop(fdt, nodeoffset, "current-speed", &len);
|
||||
if (len > 0 && val)
|
||||
uart->baud = fdt32_to_cpu(*val);
|
||||
else
|
||||
uart->baud = DEFAULT_SIFIVE_UART_BAUD;
|
||||
|
||||
/* For SiFive UART, the reg-shift and reg-io-width are fixed .*/
|
||||
uart->reg_shift = DEFAULT_SIFIVE_UART_REG_SHIFT;
|
||||
uart->reg_io_width = DEFAULT_SIFIVE_UART_REG_IO_WIDTH;
|
||||
|
||||
return 0;
|
||||
return fdt_parse_uart_node_common(fdt, nodeoffset, uart,
|
||||
DEFAULT_SIFIVE_UART_FREQ,
|
||||
DEFAULT_SIFIVE_UART_BAUD);
|
||||
}
|
||||
|
||||
int fdt_parse_uart8250_node(void *fdt, int nodeoffset,
|
||||
struct platform_uart_data *uart)
|
||||
int fdt_parse_uart_node(void *fdt, int nodeoffset,
|
||||
struct platform_uart_data *uart)
|
||||
{
|
||||
int len, rc;
|
||||
const fdt32_t *val;
|
||||
uint64_t reg_addr, reg_size;
|
||||
|
||||
if (nodeoffset < 0 || !uart || !fdt)
|
||||
return SBI_ENODEV;
|
||||
|
||||
rc = fdt_get_node_addr_size(fdt, nodeoffset, 0,
|
||||
®_addr, ®_size);
|
||||
if (rc < 0 || !reg_addr || !reg_size)
|
||||
return SBI_ENODEV;
|
||||
uart->addr = reg_addr;
|
||||
|
||||
/**
|
||||
* UART address is mandaotry. clock-frequency and current-speed
|
||||
* may not be present. Don't return error.
|
||||
*/
|
||||
val = (fdt32_t *)fdt_getprop(fdt, nodeoffset, "clock-frequency", &len);
|
||||
if (len > 0 && val)
|
||||
uart->freq = fdt32_to_cpu(*val);
|
||||
else
|
||||
uart->freq = DEFAULT_UART_FREQ;
|
||||
|
||||
val = (fdt32_t *)fdt_getprop(fdt, nodeoffset, "current-speed", &len);
|
||||
if (len > 0 && val)
|
||||
uart->baud = fdt32_to_cpu(*val);
|
||||
else
|
||||
uart->baud = DEFAULT_UART_BAUD;
|
||||
rc = fdt_parse_uart_node_common(fdt, nodeoffset, uart,
|
||||
DEFAULT_UART_FREQ,
|
||||
DEFAULT_UART_BAUD);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
val = (fdt32_t *)fdt_getprop(fdt, nodeoffset, "reg-shift", &len);
|
||||
if (len > 0 && val)
|
||||
@@ -492,25 +427,13 @@ int fdt_parse_uart8250(void *fdt, struct platform_uart_data *uart,
|
||||
if (nodeoffset < 0)
|
||||
return nodeoffset;
|
||||
|
||||
return fdt_parse_uart8250_node(fdt, nodeoffset, uart);
|
||||
return fdt_parse_uart_node(fdt, nodeoffset, uart);
|
||||
}
|
||||
|
||||
int fdt_parse_xlnx_uartlite_node(void *fdt, int nodeoffset,
|
||||
struct platform_uart_data *uart)
|
||||
{
|
||||
int rc;
|
||||
uint64_t reg_addr, reg_size;
|
||||
|
||||
if (nodeoffset < 0 || !uart || !fdt)
|
||||
return SBI_ENODEV;
|
||||
|
||||
rc = fdt_get_node_addr_size(fdt, nodeoffset, 0,
|
||||
®_addr, ®_size);
|
||||
if (rc < 0 || !reg_addr || !reg_size)
|
||||
return SBI_ENODEV;
|
||||
uart->addr = reg_addr;
|
||||
|
||||
return 0;
|
||||
return fdt_parse_uart_node_common(fdt, nodeoffset, uart, 0, 0);
|
||||
}
|
||||
|
||||
int fdt_parse_aplic_node(void *fdt, int nodeoff, struct aplic_data *aplic)
|
||||
@@ -860,7 +783,7 @@ int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer,
|
||||
continue;
|
||||
|
||||
cpu_offset = fdt_parent_offset(fdt, cpu_intc_offset);
|
||||
if (cpu_intc_offset < 0)
|
||||
if (cpu_offset < 0)
|
||||
continue;
|
||||
|
||||
rc = fdt_parse_hart_id(fdt, cpu_offset, &hartid);
|
||||
@@ -888,6 +811,118 @@ int fdt_parse_aclint_node(void *fdt, int nodeoffset, bool for_timer,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fdt_parse_plmt_node(void *fdt, int nodeoffset, unsigned long *plmt_base,
|
||||
unsigned long *plmt_size, u32 *hart_count)
|
||||
{
|
||||
const fdt32_t *val;
|
||||
int rc, i, count;
|
||||
uint64_t reg_addr, reg_size;
|
||||
u32 phandle, hwirq, hartid, hcount;
|
||||
|
||||
if (nodeoffset < 0 || !fdt || !plmt_base ||
|
||||
!hart_count || !plmt_size)
|
||||
return SBI_EINVAL;
|
||||
|
||||
rc = fdt_get_node_addr_size(fdt, nodeoffset, 0,
|
||||
®_addr, ®_size);
|
||||
if (rc < 0)
|
||||
return SBI_ENODEV;
|
||||
*plmt_base = reg_addr;
|
||||
*plmt_size = reg_size;
|
||||
|
||||
val = fdt_getprop(fdt, nodeoffset, "interrupts-extended", &count);
|
||||
if (!val || count < sizeof(fdt32_t))
|
||||
return 0;
|
||||
count = count / sizeof(fdt32_t);
|
||||
|
||||
hcount = 0;
|
||||
for (i = 0; i < (count / 2); i++) {
|
||||
int cpu_offset, cpu_intc_offset;
|
||||
|
||||
phandle = fdt32_to_cpu(val[2 * i]);
|
||||
hwirq = fdt32_to_cpu(val[2 * i + 1]);
|
||||
|
||||
cpu_intc_offset = fdt_node_offset_by_phandle(fdt, phandle);
|
||||
if (cpu_intc_offset < 0)
|
||||
continue;
|
||||
|
||||
cpu_offset = fdt_parent_offset(fdt, cpu_intc_offset);
|
||||
if (cpu_offset < 0)
|
||||
continue;
|
||||
|
||||
rc = fdt_parse_hart_id(fdt, cpu_offset, &hartid);
|
||||
|
||||
if (rc)
|
||||
continue;
|
||||
|
||||
if (SBI_HARTMASK_MAX_BITS <= hartid)
|
||||
continue;
|
||||
|
||||
if (hwirq == IRQ_M_TIMER)
|
||||
hcount++;
|
||||
}
|
||||
|
||||
*hart_count = hcount;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fdt_parse_plicsw_node(void *fdt, int nodeoffset, unsigned long *plicsw_base,
|
||||
unsigned long *size, u32 *hart_count)
|
||||
{
|
||||
const fdt32_t *val;
|
||||
int rc, i, count;
|
||||
uint64_t reg_addr, reg_size;
|
||||
u32 phandle, hwirq, hartid, hcount;
|
||||
|
||||
if (nodeoffset < 0 || !fdt || !plicsw_base ||
|
||||
!hart_count || !size)
|
||||
return SBI_EINVAL;
|
||||
|
||||
rc = fdt_get_node_addr_size(fdt, nodeoffset, 0,
|
||||
®_addr, ®_size);
|
||||
if (rc < 0)
|
||||
return SBI_ENODEV;
|
||||
*plicsw_base = reg_addr;
|
||||
*size = reg_size;
|
||||
|
||||
val = fdt_getprop(fdt, nodeoffset, "interrupts-extended", &count);
|
||||
if (!val || count < sizeof(fdt32_t))
|
||||
return 0;
|
||||
count = count / sizeof(fdt32_t);
|
||||
|
||||
hcount = 0;
|
||||
for (i = 0; i < (count / 2); i++) {
|
||||
int cpu_offset, cpu_intc_offset;
|
||||
|
||||
phandle = fdt32_to_cpu(val[2 * i]);
|
||||
hwirq = fdt32_to_cpu(val[2 * i + 1]);
|
||||
|
||||
cpu_intc_offset = fdt_node_offset_by_phandle(fdt, phandle);
|
||||
if (cpu_intc_offset < 0)
|
||||
continue;
|
||||
|
||||
cpu_offset = fdt_parent_offset(fdt, cpu_intc_offset);
|
||||
if (cpu_offset < 0)
|
||||
continue;
|
||||
|
||||
rc = fdt_parse_hart_id(fdt, cpu_offset, &hartid);
|
||||
|
||||
if (rc)
|
||||
continue;
|
||||
|
||||
if (SBI_HARTMASK_MAX_BITS <= hartid)
|
||||
continue;
|
||||
|
||||
if (hwirq == IRQ_M_SOFT)
|
||||
hcount++;
|
||||
}
|
||||
|
||||
*hart_count = hcount;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fdt_parse_compat_addr(void *fdt, uint64_t *addr,
|
||||
const char *compatible)
|
||||
{
|
||||
|
@@ -75,42 +75,52 @@ int fdt_pmu_setup(void *fdt)
|
||||
if (pmu_offset < 0)
|
||||
return SBI_EFAIL;
|
||||
|
||||
event_ctr_map = fdt_getprop(fdt, pmu_offset, "riscv,event-to-mhpmcounters", &len);
|
||||
if (!event_ctr_map || len < 8)
|
||||
return SBI_EFAIL;
|
||||
len = len / (sizeof(u32) * 3);
|
||||
for (i = 0; i < len; i++) {
|
||||
event_idx_start = fdt32_to_cpu(event_ctr_map[3 * i]);
|
||||
event_idx_end = fdt32_to_cpu(event_ctr_map[3 * i + 1]);
|
||||
ctr_map = fdt32_to_cpu(event_ctr_map[3 * i + 2]);
|
||||
sbi_pmu_add_hw_event_counter_map(event_idx_start, event_idx_end, ctr_map);
|
||||
event_ctr_map = fdt_getprop(fdt, pmu_offset,
|
||||
"riscv,event-to-mhpmcounters", &len);
|
||||
if (event_ctr_map && len >= 8) {
|
||||
len = len / (sizeof(u32) * 3);
|
||||
for (i = 0; i < len; i++) {
|
||||
event_idx_start = fdt32_to_cpu(event_ctr_map[3 * i]);
|
||||
event_idx_end = fdt32_to_cpu(event_ctr_map[3 * i + 1]);
|
||||
ctr_map = fdt32_to_cpu(event_ctr_map[3 * i + 2]);
|
||||
result = sbi_pmu_add_hw_event_counter_map(
|
||||
event_idx_start, event_idx_end, ctr_map);
|
||||
if (result)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
event_val = fdt_getprop(fdt, pmu_offset, "riscv,event-to-mhpmevent", &len);
|
||||
if (!event_val || len < 8)
|
||||
return SBI_EFAIL;
|
||||
len = len / (sizeof(u32) * 3);
|
||||
for (i = 0; i < len; i++) {
|
||||
event = &fdt_pmu_evt_select[hw_event_count];
|
||||
event->eidx = fdt32_to_cpu(event_val[3 * i]);
|
||||
event->select = fdt32_to_cpu(event_val[3 * i + 1]);
|
||||
event->select = (event->select << 32) | fdt32_to_cpu(event_val[3 * i + 2]);
|
||||
hw_event_count++;
|
||||
}
|
||||
|
||||
event_val = fdt_getprop(fdt, pmu_offset, "riscv,raw-event-to-mhpmcounters", &len);
|
||||
if (!event_val || len < 20)
|
||||
return SBI_EFAIL;
|
||||
len = len / (sizeof(u32) * 5);
|
||||
for (i = 0; i < len; i++) {
|
||||
raw_selector = fdt32_to_cpu(event_val[5 * i]);
|
||||
raw_selector = (raw_selector << 32) | fdt32_to_cpu(event_val[5 * i + 1]);
|
||||
select_mask = fdt32_to_cpu(event_val[5 * i + 2]);
|
||||
select_mask = (select_mask << 32) | fdt32_to_cpu(event_val[5 * i + 3]);
|
||||
ctr_map = fdt32_to_cpu(event_val[5 * i + 4]);
|
||||
result = sbi_pmu_add_raw_event_counter_map(raw_selector, select_mask, ctr_map);
|
||||
if (!result)
|
||||
event_val = fdt_getprop(fdt, pmu_offset,
|
||||
"riscv,event-to-mhpmevent", &len);
|
||||
if (event_val && len >= 8) {
|
||||
len = len / (sizeof(u32) * 3);
|
||||
for (i = 0; i < len; i++) {
|
||||
event = &fdt_pmu_evt_select[hw_event_count];
|
||||
event->eidx = fdt32_to_cpu(event_val[3 * i]);
|
||||
event->select = fdt32_to_cpu(event_val[3 * i + 1]);
|
||||
event->select = (event->select << 32) |
|
||||
fdt32_to_cpu(event_val[3 * i + 2]);
|
||||
hw_event_count++;
|
||||
}
|
||||
}
|
||||
|
||||
event_val = fdt_getprop(fdt, pmu_offset,
|
||||
"riscv,raw-event-to-mhpmcounters", &len);
|
||||
if (event_val && len >= 20) {
|
||||
len = len / (sizeof(u32) * 5);
|
||||
for (i = 0; i < len; i++) {
|
||||
raw_selector = fdt32_to_cpu(event_val[5 * i]);
|
||||
raw_selector = (raw_selector << 32) |
|
||||
fdt32_to_cpu(event_val[5 * i + 1]);
|
||||
select_mask = fdt32_to_cpu(event_val[5 * i + 2]);
|
||||
select_mask = (select_mask << 32) |
|
||||
fdt32_to_cpu(event_val[5 * i + 3]);
|
||||
ctr_map = fdt32_to_cpu(event_val[5 * i + 4]);
|
||||
result = sbi_pmu_add_raw_event_counter_map(
|
||||
raw_selector, select_mask, ctr_map);
|
||||
if (result)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@@ -4,7 +4,7 @@
|
||||
# Copyright (C) 2020 Bin Meng <bmeng.cn@gmail.com>
|
||||
#
|
||||
|
||||
libsbiutils-objs-y += fdt/fdt_domain.o
|
||||
libsbiutils-objs-y += fdt/fdt_pmu.o
|
||||
libsbiutils-objs-y += fdt/fdt_helper.o
|
||||
libsbiutils-objs-y += fdt/fdt_fixup.o
|
||||
libsbiutils-objs-$(CONFIG_FDT_DOMAIN) += fdt/fdt_domain.o
|
||||
libsbiutils-objs-$(CONFIG_FDT_PMU) += fdt/fdt_pmu.o
|
||||
libsbiutils-objs-$(CONFIG_FDT) += fdt/fdt_helper.o
|
||||
libsbiutils-objs-$(CONFIG_FDT) += fdt/fdt_fixup.o
|
||||
|
23
lib/utils/gpio/Kconfig
Normal file
23
lib/utils/gpio/Kconfig
Normal file
@@ -0,0 +1,23 @@
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
menu "GPIO Support"
|
||||
|
||||
config FDT_GPIO
|
||||
bool "FDT based GPIO drivers"
|
||||
depends on FDT
|
||||
select GPIO
|
||||
default n
|
||||
|
||||
if FDT_GPIO
|
||||
|
||||
config FDT_GPIO_SIFIVE
|
||||
bool "SiFive GPIO FDT driver"
|
||||
default n
|
||||
|
||||
endif
|
||||
|
||||
config GPIO
|
||||
bool "GPIO support"
|
||||
default n
|
||||
|
||||
endmenu
|
@@ -7,10 +7,10 @@
|
||||
# Anup Patel <anup.patel@wdc.com>
|
||||
#
|
||||
|
||||
libsbiutils-objs-y += gpio/fdt_gpio.o
|
||||
libsbiutils-objs-y += gpio/fdt_gpio_drivers.o
|
||||
libsbiutils-objs-$(CONFIG_FDT_GPIO) += gpio/fdt_gpio.o
|
||||
libsbiutils-objs-$(CONFIG_FDT_GPIO) += gpio/fdt_gpio_drivers.o
|
||||
|
||||
carray-fdt_gpio_drivers-y += fdt_gpio_sifive
|
||||
libsbiutils-objs-y += gpio/fdt_gpio_sifive.o
|
||||
carray-fdt_gpio_drivers-$(CONFIG_FDT_GPIO_SIFIVE) += fdt_gpio_sifive
|
||||
libsbiutils-objs-$(CONFIG_FDT_GPIO_SIFIVE) += gpio/fdt_gpio_sifive.o
|
||||
|
||||
libsbiutils-objs-y += gpio/gpio.o
|
||||
libsbiutils-objs-$(CONFIG_GPIO) += gpio/gpio.o
|
||||
|
23
lib/utils/i2c/Kconfig
Normal file
23
lib/utils/i2c/Kconfig
Normal file
@@ -0,0 +1,23 @@
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
menu "I2C Support"
|
||||
|
||||
config FDT_I2C
|
||||
bool "FDT based I2C drivers"
|
||||
depends on FDT
|
||||
select I2C
|
||||
default n
|
||||
|
||||
if FDT_I2C
|
||||
|
||||
config FDT_I2C_SIFIVE
|
||||
bool "SiFive I2C FDT driver"
|
||||
default n
|
||||
|
||||
endif
|
||||
|
||||
config I2C
|
||||
bool "I2C support"
|
||||
default n
|
||||
|
||||
endmenu
|
@@ -7,10 +7,10 @@
|
||||
# Nikita Shubin <n.shubin@yadro.com>
|
||||
#
|
||||
|
||||
libsbiutils-objs-y += i2c/i2c.o
|
||||
libsbiutils-objs-$(CONFIG_I2C) += i2c/i2c.o
|
||||
|
||||
libsbiutils-objs-y += i2c/fdt_i2c.o
|
||||
libsbiutils-objs-y += i2c/fdt_i2c_adapter_drivers.o
|
||||
libsbiutils-objs-$(CONFIG_FDT_I2C) += i2c/fdt_i2c.o
|
||||
libsbiutils-objs-$(CONFIG_FDT_I2C) += i2c/fdt_i2c_adapter_drivers.o
|
||||
|
||||
carray-fdt_i2c_adapter_drivers-y += fdt_i2c_adapter_sifive
|
||||
libsbiutils-objs-y += i2c/fdt_i2c_sifive.o
|
||||
carray-fdt_i2c_adapter_drivers-$(CONFIG_FDT_I2C_SIFIVE) += fdt_i2c_adapter_sifive
|
||||
libsbiutils-objs-$(CONFIG_FDT_I2C_SIFIVE) += i2c/fdt_i2c_sifive.o
|
||||
|
32
lib/utils/ipi/Kconfig
Normal file
32
lib/utils/ipi/Kconfig
Normal file
@@ -0,0 +1,32 @@
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
menu "IPI Device Support"
|
||||
|
||||
config FDT_IPI
|
||||
bool "FDT based ipi drivers"
|
||||
depends on FDT
|
||||
default n
|
||||
|
||||
if FDT_IPI
|
||||
|
||||
config FDT_IPI_MSWI
|
||||
bool "ACLINT MSWI FDT driver"
|
||||
select IPI_MSWI
|
||||
default n
|
||||
|
||||
config FDT_IPI_PLICSW
|
||||
bool "Andes PLICSW FDT driver"
|
||||
select IPI_PLICSW
|
||||
default n
|
||||
|
||||
endif
|
||||
|
||||
config IPI_MSWI
|
||||
bool "ACLINT MSWI support"
|
||||
default n
|
||||
|
||||
config IPI_PLICSW
|
||||
bool "Andes PLICSW support"
|
||||
default n
|
||||
|
||||
endmenu
|
137
lib/utils/ipi/andes_plicsw.c
Normal file
137
lib/utils/ipi/andes_plicsw.c
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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>
|
||||
*/
|
||||
|
||||
#include <sbi/riscv_asm.h>
|
||||
#include <sbi/riscv_io.h>
|
||||
#include <sbi/sbi_domain.h>
|
||||
#include <sbi/sbi_ipi.h>
|
||||
#include <sbi_utils/ipi/andes_plicsw.h>
|
||||
|
||||
struct plicsw_data plicsw;
|
||||
|
||||
static inline void plicsw_claim(void)
|
||||
{
|
||||
u32 hartid = current_hartid();
|
||||
|
||||
if (plicsw.hart_count <= hartid)
|
||||
ebreak();
|
||||
|
||||
plicsw.source_id[hartid] =
|
||||
readl((void *)plicsw.addr + PLICSW_CONTEXT_BASE +
|
||||
PLICSW_CONTEXT_CLAIM + PLICSW_CONTEXT_STRIDE * hartid);
|
||||
}
|
||||
|
||||
static inline void plicsw_complete(void)
|
||||
{
|
||||
u32 hartid = current_hartid();
|
||||
u32 source = plicsw.source_id[hartid];
|
||||
|
||||
writel(source, (void *)plicsw.addr + PLICSW_CONTEXT_BASE +
|
||||
PLICSW_CONTEXT_CLAIM +
|
||||
PLICSW_CONTEXT_STRIDE * hartid);
|
||||
}
|
||||
|
||||
static inline void plic_sw_pending(u32 target_hart)
|
||||
{
|
||||
/*
|
||||
* The pending array registers are w1s type.
|
||||
* IPI pending array mapping as following:
|
||||
*
|
||||
* Pending array start address: base + 0x1000
|
||||
* ---------------------------------
|
||||
* | hart3 | hart2 | hart1 | hart0 |
|
||||
* ---------------------------------
|
||||
* Each hartX can send IPI to another hart by setting the
|
||||
* bitY to its own region (see the below).
|
||||
*
|
||||
* In each hartX region:
|
||||
* <---------- PICSW_PENDING_STRIDE -------->
|
||||
* | bit7 | ... | bit3 | bit2 | bit1 | bit0 |
|
||||
* ------------------------------------------
|
||||
* The bitY of hartX region indicates that hartX sends an
|
||||
* IPI to hartY.
|
||||
*/
|
||||
u32 hartid = current_hartid();
|
||||
u32 word_index = hartid / 4;
|
||||
u32 per_hart_offset = PLICSW_PENDING_STRIDE * hartid;
|
||||
u32 val = 1 << target_hart << per_hart_offset;
|
||||
|
||||
writel(val, (void *)plicsw.addr + PLICSW_PENDING_BASE + word_index * 4);
|
||||
}
|
||||
|
||||
static void plicsw_ipi_send(u32 target_hart)
|
||||
{
|
||||
if (plicsw.hart_count <= target_hart)
|
||||
ebreak();
|
||||
|
||||
/* Set PLICSW IPI */
|
||||
plic_sw_pending(target_hart);
|
||||
}
|
||||
|
||||
static void plicsw_ipi_clear(u32 target_hart)
|
||||
{
|
||||
if (plicsw.hart_count <= target_hart)
|
||||
ebreak();
|
||||
|
||||
/* Clear PLICSW IPI */
|
||||
plicsw_claim();
|
||||
plicsw_complete();
|
||||
}
|
||||
|
||||
static struct sbi_ipi_device plicsw_ipi = {
|
||||
.name = "andes_plicsw",
|
||||
.ipi_send = plicsw_ipi_send,
|
||||
.ipi_clear = plicsw_ipi_clear
|
||||
};
|
||||
|
||||
int plicsw_warm_ipi_init(void)
|
||||
{
|
||||
u32 hartid = current_hartid();
|
||||
|
||||
/* Clear PLICSW IPI */
|
||||
plicsw_ipi_clear(hartid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int plicsw_cold_ipi_init(struct plicsw_data *plicsw)
|
||||
{
|
||||
int rc;
|
||||
|
||||
/* Setup source priority */
|
||||
uint32_t *priority = (void *)plicsw->addr + PLICSW_PRIORITY_BASE;
|
||||
|
||||
for (int i = 0; i < plicsw->hart_count; i++)
|
||||
writel(1, &priority[i]);
|
||||
|
||||
/* Setup target enable */
|
||||
uint32_t enable_mask = PLICSW_HART_MASK;
|
||||
|
||||
for (int i = 0; i < plicsw->hart_count; i++) {
|
||||
uint32_t *enable = (void *)plicsw->addr + PLICSW_ENABLE_BASE +
|
||||
PLICSW_ENABLE_STRIDE * i;
|
||||
writel(enable_mask, enable);
|
||||
writel(enable_mask, enable + 1);
|
||||
enable_mask <<= 1;
|
||||
}
|
||||
|
||||
/* Add PLICSW region to the root domain */
|
||||
rc = sbi_domain_root_add_memrange(plicsw->addr, plicsw->size,
|
||||
PLICSW_REGION_ALIGN,
|
||||
SBI_DOMAIN_MEMREGION_MMIO);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
sbi_ipi_set_device(&plicsw_ipi);
|
||||
|
||||
return 0;
|
||||
}
|
@@ -56,6 +56,7 @@ static const unsigned long clint_offset = CLINT_MSWI_OFFSET;
|
||||
static const struct fdt_match ipi_mswi_match[] = {
|
||||
{ .compatible = "riscv,clint0", .data = &clint_offset },
|
||||
{ .compatible = "sifive,clint0", .data = &clint_offset },
|
||||
{ .compatible = "thead,c900-clint", .data = &clint_offset },
|
||||
{ .compatible = "riscv,aclint-mswi" },
|
||||
{ },
|
||||
};
|
||||
|
47
lib/utils/ipi/fdt_ipi_plicsw.c
Normal file
47
lib/utils/ipi/fdt_ipi_plicsw.c
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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>
|
||||
*/
|
||||
|
||||
#include <sbi/riscv_io.h>
|
||||
#include <sbi_utils/fdt/fdt_helper.h>
|
||||
#include <sbi_utils/ipi/fdt_ipi.h>
|
||||
#include <sbi_utils/ipi/andes_plicsw.h>
|
||||
|
||||
extern struct plicsw_data plicsw;
|
||||
|
||||
int fdt_plicsw_cold_ipi_init(void *fdt, int nodeoff,
|
||||
const struct fdt_match *match)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = fdt_parse_plicsw_node(fdt, nodeoff, &plicsw.addr, &plicsw.size,
|
||||
&plicsw.hart_count);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
rc = plicsw_cold_ipi_init(&plicsw);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct fdt_match ipi_plicsw_match[] = {
|
||||
{ .compatible = "andestech,plicsw" },
|
||||
{},
|
||||
};
|
||||
|
||||
struct fdt_ipi fdt_ipi_plicsw = {
|
||||
.match_table = ipi_plicsw_match,
|
||||
.cold_init = fdt_plicsw_cold_ipi_init,
|
||||
.warm_init = plicsw_warm_ipi_init,
|
||||
.exit = NULL,
|
||||
};
|
@@ -7,10 +7,14 @@
|
||||
# Anup Patel <anup.patel@wdc.com>
|
||||
#
|
||||
|
||||
libsbiutils-objs-y += ipi/aclint_mswi.o
|
||||
libsbiutils-objs-$(CONFIG_IPI_MSWI) += ipi/aclint_mswi.o
|
||||
libsbiutils-objs-$(CONFIG_IPI_PLICSW) += ipi/andes_plicsw.o
|
||||
|
||||
libsbiutils-objs-y += ipi/fdt_ipi.o
|
||||
libsbiutils-objs-y += ipi/fdt_ipi_drivers.o
|
||||
libsbiutils-objs-$(CONFIG_FDT_IPI) += ipi/fdt_ipi.o
|
||||
libsbiutils-objs-$(CONFIG_FDT_IPI) += ipi/fdt_ipi_drivers.o
|
||||
|
||||
carray-fdt_ipi_drivers-y += fdt_ipi_mswi
|
||||
libsbiutils-objs-y += ipi/fdt_ipi_mswi.o
|
||||
carray-fdt_ipi_drivers-$(CONFIG_FDT_IPI_MSWI) += fdt_ipi_mswi
|
||||
libsbiutils-objs-$(CONFIG_FDT_IPI_MSWI) += ipi/fdt_ipi_mswi.o
|
||||
|
||||
carray-fdt_ipi_drivers-$(CONFIG_FDT_IPI_PLICSW) += fdt_ipi_plicsw
|
||||
libsbiutils-objs-$(CONFIG_FDT_IPI_PLICSW) += ipi/fdt_ipi_plicsw.o
|
||||
|
41
lib/utils/irqchip/Kconfig
Normal file
41
lib/utils/irqchip/Kconfig
Normal file
@@ -0,0 +1,41 @@
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
menu "Interrupt Controller Support"
|
||||
|
||||
config FDT_IRQCHIP
|
||||
bool "FDT based interrupt controller drivers"
|
||||
depends on FDT
|
||||
default n
|
||||
|
||||
if FDT_IRQCHIP
|
||||
|
||||
config FDT_IRQCHIP_APLIC
|
||||
bool "Advanced Platform Level Interrupt Controller (APLIC) FDT driver"
|
||||
select IRQCHIP_APLIC
|
||||
default n
|
||||
|
||||
config FDT_IRQCHIP_IMSIC
|
||||
bool "Incoming Message Signalled Interrupt Controller (IMSIC) FDT driver"
|
||||
select IRQCHIP_IMSIC
|
||||
default n
|
||||
|
||||
config FDT_IRQCHIP_PLIC
|
||||
bool "Platform Level Interrupt Controller (PLIC) FDT driver"
|
||||
select IRQCHIP_PLIC
|
||||
default n
|
||||
|
||||
endif
|
||||
|
||||
config IRQCHIP_APLIC
|
||||
bool "Advanced Platform Level Interrupt Controller (APLIC) support"
|
||||
default n
|
||||
|
||||
config IRQCHIP_IMSIC
|
||||
bool "Incoming Message Signalled Interrupt Controller (IMSIC) support"
|
||||
default n
|
||||
|
||||
config IRQCHIP_PLIC
|
||||
bool "Platform Level Interrupt Controller (PLIC) support"
|
||||
default n
|
||||
|
||||
endmenu
|
@@ -24,36 +24,37 @@ static struct plic_data plic[PLIC_MAX_NR];
|
||||
static struct plic_data *plic_hartid2data[SBI_HARTMASK_MAX_BITS];
|
||||
static int plic_hartid2context[SBI_HARTMASK_MAX_BITS][2];
|
||||
|
||||
void fdt_plic_priority_save(u8 *priority)
|
||||
void fdt_plic_priority_save(u8 *priority, u32 num)
|
||||
{
|
||||
struct plic_data *plic = plic_hartid2data[current_hartid()];
|
||||
|
||||
plic_priority_save(plic, priority);
|
||||
plic_priority_save(plic, priority, num);
|
||||
}
|
||||
|
||||
void fdt_plic_priority_restore(const u8 *priority)
|
||||
void fdt_plic_priority_restore(const u8 *priority, u32 num)
|
||||
{
|
||||
struct plic_data *plic = plic_hartid2data[current_hartid()];
|
||||
|
||||
plic_priority_restore(plic, priority);
|
||||
plic_priority_restore(plic, priority, num);
|
||||
}
|
||||
|
||||
void fdt_plic_context_save(bool smode, u32 *enable, u32 *threshold)
|
||||
void fdt_plic_context_save(bool smode, u32 *enable, u32 *threshold, u32 num)
|
||||
{
|
||||
u32 hartid = current_hartid();
|
||||
|
||||
plic_context_save(plic_hartid2data[hartid],
|
||||
plic_hartid2context[hartid][smode],
|
||||
enable, threshold);
|
||||
enable, threshold, num);
|
||||
}
|
||||
|
||||
void fdt_plic_context_restore(bool smode, const u32 *enable, u32 threshold)
|
||||
void fdt_plic_context_restore(bool smode, const u32 *enable, u32 threshold,
|
||||
u32 num)
|
||||
{
|
||||
u32 hartid = current_hartid();
|
||||
|
||||
plic_context_restore(plic_hartid2data[hartid],
|
||||
plic_hartid2context[hartid][smode],
|
||||
enable, threshold);
|
||||
enable, threshold, num);
|
||||
}
|
||||
|
||||
static int irqchip_plic_warm_init(void)
|
||||
@@ -86,7 +87,7 @@ static int irqchip_plic_update_hartid_table(void *fdt, int nodeoff,
|
||||
continue;
|
||||
|
||||
cpu_offset = fdt_parent_offset(fdt, cpu_intc_offset);
|
||||
if (cpu_intc_offset < 0)
|
||||
if (cpu_offset < 0)
|
||||
continue;
|
||||
|
||||
err = fdt_parse_hart_id(fdt, cpu_offset, &hartid);
|
||||
@@ -159,11 +160,12 @@ void thead_plic_restore(void)
|
||||
}
|
||||
|
||||
static const struct fdt_match irqchip_plic_match[] = {
|
||||
{ .compatible = "andestech,nceplic100" },
|
||||
{ .compatible = "riscv,plic0" },
|
||||
{ .compatible = "sifive,plic-1.0.0" },
|
||||
{ .compatible = "thead,c900-plic",
|
||||
.data = thead_plic_plat_init },
|
||||
{ },
|
||||
{ /* sentinel */ }
|
||||
};
|
||||
|
||||
struct fdt_irqchip fdt_irqchip_plic = {
|
||||
|
@@ -7,18 +7,18 @@
|
||||
# Anup Patel <anup.patel@wdc.com>
|
||||
#
|
||||
|
||||
libsbiutils-objs-y += irqchip/fdt_irqchip.o
|
||||
libsbiutils-objs-y += irqchip/fdt_irqchip_drivers.o
|
||||
libsbiutils-objs-$(CONFIG_FDT_IRQCHIP) += irqchip/fdt_irqchip.o
|
||||
libsbiutils-objs-$(CONFIG_FDT_IRQCHIP) += irqchip/fdt_irqchip_drivers.o
|
||||
|
||||
carray-fdt_irqchip_drivers-y += fdt_irqchip_aplic
|
||||
libsbiutils-objs-y += irqchip/fdt_irqchip_aplic.o
|
||||
carray-fdt_irqchip_drivers-$(CONFIG_FDT_IRQCHIP_APLIC) += fdt_irqchip_aplic
|
||||
libsbiutils-objs-$(CONFIG_FDT_IRQCHIP_APLIC) += irqchip/fdt_irqchip_aplic.o
|
||||
|
||||
carray-fdt_irqchip_drivers-y += fdt_irqchip_imsic
|
||||
libsbiutils-objs-y += irqchip/fdt_irqchip_imsic.o
|
||||
carray-fdt_irqchip_drivers-$(CONFIG_FDT_IRQCHIP_IMSIC) += fdt_irqchip_imsic
|
||||
libsbiutils-objs-$(CONFIG_FDT_IRQCHIP_IMSIC) += irqchip/fdt_irqchip_imsic.o
|
||||
|
||||
carray-fdt_irqchip_drivers-y += fdt_irqchip_plic
|
||||
libsbiutils-objs-y += irqchip/fdt_irqchip_plic.o
|
||||
carray-fdt_irqchip_drivers-$(CONFIG_FDT_IRQCHIP_PLIC) += fdt_irqchip_plic
|
||||
libsbiutils-objs-$(CONFIG_FDT_IRQCHIP_PLIC) += irqchip/fdt_irqchip_plic.o
|
||||
|
||||
libsbiutils-objs-y += irqchip/aplic.o
|
||||
libsbiutils-objs-y += irqchip/imsic.o
|
||||
libsbiutils-objs-y += irqchip/plic.o
|
||||
libsbiutils-objs-$(CONFIG_IRQCHIP_APLIC) += irqchip/aplic.o
|
||||
libsbiutils-objs-$(CONFIG_IRQCHIP_IMSIC) += irqchip/imsic.o
|
||||
libsbiutils-objs-$(CONFIG_IRQCHIP_PLIC) += irqchip/plic.o
|
||||
|
@@ -36,15 +36,16 @@ static void plic_set_priority(const struct plic_data *plic, u32 source, u32 val)
|
||||
writel(val, plic_priority);
|
||||
}
|
||||
|
||||
void plic_priority_save(const struct plic_data *plic, u8 *priority)
|
||||
void plic_priority_save(const struct plic_data *plic, u8 *priority, u32 num)
|
||||
{
|
||||
for (u32 i = 0; i < plic->num_src; i++)
|
||||
for (u32 i = 1; i <= num; i++)
|
||||
priority[i] = plic_get_priority(plic, i);
|
||||
}
|
||||
|
||||
void plic_priority_restore(const struct plic_data *plic, const u8 *priority)
|
||||
void plic_priority_restore(const struct plic_data *plic, const u8 *priority,
|
||||
u32 num)
|
||||
{
|
||||
for (u32 i = 0; i < plic->num_src; i++)
|
||||
for (u32 i = 1; i <= num; i++)
|
||||
plic_set_priority(plic, i, priority[i]);
|
||||
}
|
||||
|
||||
@@ -91,22 +92,28 @@ static void plic_set_ie(const struct plic_data *plic, u32 cntxid,
|
||||
}
|
||||
|
||||
void plic_context_save(const struct plic_data *plic, int context_id,
|
||||
u32 *enable, u32 *threshold)
|
||||
u32 *enable, u32 *threshold, u32 num)
|
||||
{
|
||||
u32 ie_words = (plic->num_src + 31) / 32;
|
||||
u32 ie_words = plic->num_src / 32 + 1;
|
||||
|
||||
for (u32 i = 0; i < ie_words; i++)
|
||||
if (num > ie_words)
|
||||
num = ie_words;
|
||||
|
||||
for (u32 i = 0; i < num; i++)
|
||||
enable[i] = plic_get_ie(plic, context_id, i);
|
||||
|
||||
*threshold = plic_get_thresh(plic, context_id);
|
||||
}
|
||||
|
||||
void plic_context_restore(const struct plic_data *plic, int context_id,
|
||||
const u32 *enable, u32 threshold)
|
||||
const u32 *enable, u32 threshold, u32 num)
|
||||
{
|
||||
u32 ie_words = (plic->num_src + 31) / 32;
|
||||
u32 ie_words = plic->num_src / 32 + 1;
|
||||
|
||||
for (u32 i = 0; i < ie_words; i++)
|
||||
if (num > ie_words)
|
||||
num = ie_words;
|
||||
|
||||
for (u32 i = 0; i < num; i++)
|
||||
plic_set_ie(plic, context_id, i, enable[i]);
|
||||
|
||||
plic_set_thresh(plic, context_id, threshold);
|
||||
@@ -120,7 +127,7 @@ int plic_context_init(const struct plic_data *plic, int context_id,
|
||||
if (!plic || context_id < 0)
|
||||
return SBI_EINVAL;
|
||||
|
||||
ie_words = (plic->num_src + 31) / 32;
|
||||
ie_words = plic->num_src / 32 + 1;
|
||||
ie_value = enable ? 0xffffffffU : 0U;
|
||||
|
||||
for (u32 i = 0; i < ie_words; i++)
|
||||
|
5
lib/utils/libfdt/Kconfig
Normal file
5
lib/utils/libfdt/Kconfig
Normal file
@@ -0,0 +1,5 @@
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
config LIBFDT
|
||||
bool
|
||||
default n
|
@@ -12,5 +12,5 @@ libfdt_files = fdt.o fdt_addresses.o fdt_check.o fdt_empty_tree.o fdt_ro.o fdt_r
|
||||
$(foreach file, $(libfdt_files), \
|
||||
$(eval CFLAGS_$(file) = -I$(src)/../../utils/libfdt))
|
||||
|
||||
libsbiutils-objs-y += $(addprefix libfdt/,$(libfdt_files))
|
||||
libsbiutils-objs-$(CONFIG_LIBFDT) += $(addprefix libfdt/,$(libfdt_files))
|
||||
libsbiutils-genflags-y += -I$(libsbiutils_dir)/libfdt/
|
||||
|
41
lib/utils/reset/Kconfig
Normal file
41
lib/utils/reset/Kconfig
Normal file
@@ -0,0 +1,41 @@
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
menu "System Reset Support"
|
||||
|
||||
config FDT_RESET
|
||||
bool "FDT based reset drivers"
|
||||
depends on FDT
|
||||
default n
|
||||
|
||||
if FDT_RESET
|
||||
|
||||
config FDT_RESET_ATCWDT200
|
||||
bool "Andes WDT FDT reset driver"
|
||||
default n
|
||||
|
||||
config FDT_RESET_GPIO
|
||||
bool "GPIO FDT reset driver"
|
||||
depends on FDT_GPIO
|
||||
default n
|
||||
|
||||
config FDT_RESET_HTIF
|
||||
bool "Host transfer interface (HTIF) FDT reset driver"
|
||||
select SYS_HTIF
|
||||
default n
|
||||
|
||||
config FDT_RESET_SIFIVE_TEST
|
||||
bool "SiFive Test FDT reset driver"
|
||||
select SYS_SIFIVE_TEST
|
||||
default n
|
||||
|
||||
config FDT_RESET_SUNXI_WDT
|
||||
bool "Sunxi WDT FDT reset driver"
|
||||
default n
|
||||
|
||||
config FDT_RESET_THEAD
|
||||
bool "T-HEAD FDT reset driver"
|
||||
default n
|
||||
|
||||
endif
|
||||
|
||||
endmenu
|
122
lib/utils/reset/fdt_reset_atcwdt200.c
Normal file
122
lib/utils/reset/fdt_reset_atcwdt200.c
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2022 Andes Technology Corporation
|
||||
*
|
||||
* Authors:
|
||||
* Yu Chien Peter Lin <peterlin@andestech.com>
|
||||
*/
|
||||
|
||||
#include <libfdt.h>
|
||||
#include <sbi/riscv_io.h>
|
||||
#include <sbi/sbi_ecall_interface.h>
|
||||
#include <sbi/sbi_error.h>
|
||||
#include <sbi/sbi_hart.h>
|
||||
#include <sbi/sbi_platform.h>
|
||||
#include <sbi/sbi_system.h>
|
||||
#include <sbi_utils/fdt/fdt_helper.h>
|
||||
#include <sbi_utils/reset/fdt_reset.h>
|
||||
|
||||
#define ATCWDT200_WP_NUM 0x5aa5
|
||||
#define WREN_REG 0x18
|
||||
#define CTRL_REG 0x10
|
||||
#define RST_TIME_OFF 8
|
||||
#define RST_TIME_MSK (0x3 << RST_TIME_OFF)
|
||||
#define RST_CLK_128 (0 << RST_TIME_OFF)
|
||||
#define RST_CLK_256 (1 << RST_TIME_OFF)
|
||||
#define RST_CLK_512 (2 << RST_TIME_OFF)
|
||||
#define RST_CLK_1024 (3 << RST_TIME_OFF)
|
||||
#define INT_TIME_OFF 4
|
||||
#define INT_TIME_MSK (0xf << INT_TIME_OFF)
|
||||
#define INT_CLK_64 (0 << INT_TIME_OFF)
|
||||
#define INT_CLK_256 (1 << INT_TIME_OFF)
|
||||
#define INT_CLK_1024 (2 << INT_TIME_OFF)
|
||||
#define INT_CLK_2048 (3 << INT_TIME_OFF)
|
||||
#define INT_CLK_4096 (4 << INT_TIME_OFF)
|
||||
#define INT_CLK_8192 (5 << INT_TIME_OFF)
|
||||
#define INT_CLK_16384 (6 << INT_TIME_OFF)
|
||||
#define INT_CLK_32768 (7 << INT_TIME_OFF)
|
||||
#define RST_EN (1 << 3)
|
||||
#define INT_EN (1 << 2)
|
||||
#define CLK_PCLK (1 << 1)
|
||||
#define WDT_EN (1 << 0)
|
||||
|
||||
#define FLASH_BASE 0x80000000ULL
|
||||
#define SMU_RESET_VEC_LO_OFF 0x50
|
||||
#define SMU_RESET_VEC_HI_OFF 0x60
|
||||
#define SMU_HARTn_RESET_VEC_LO(n) (SMU_RESET_VEC_LO_OFF + (n * 0x4))
|
||||
#define SMU_HARTn_RESET_VEC_HI(n) (SMU_RESET_VEC_HI_OFF + (n * 0x4))
|
||||
|
||||
static volatile char *wdt_addr;
|
||||
static volatile char *smu_addr;
|
||||
|
||||
static int ae350_system_reset_check(u32 type, u32 reason)
|
||||
{
|
||||
switch (type) {
|
||||
case SBI_SRST_RESET_TYPE_COLD_REBOOT:
|
||||
return 1;
|
||||
case SBI_SRST_RESET_TYPE_SHUTDOWN:
|
||||
case SBI_SRST_RESET_TYPE_WARM_REBOOT:
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void ae350_system_reset(u32 type, u32 reason)
|
||||
{
|
||||
const struct sbi_platform *plat = sbi_platform_thishart_ptr();
|
||||
|
||||
for (int i = 0; i < sbi_platform_hart_count(plat); i++) {
|
||||
writel(FLASH_BASE, smu_addr + SMU_HARTn_RESET_VEC_LO(i));
|
||||
writel(FLASH_BASE >> 32, smu_addr + SMU_HARTn_RESET_VEC_HI(i));
|
||||
}
|
||||
|
||||
/* Program WDT control register */
|
||||
writew(ATCWDT200_WP_NUM, wdt_addr + WREN_REG);
|
||||
writel(INT_CLK_32768 | INT_EN | RST_CLK_128 | RST_EN | WDT_EN,
|
||||
wdt_addr + CTRL_REG);
|
||||
|
||||
sbi_hart_hang();
|
||||
}
|
||||
|
||||
static struct sbi_system_reset_device atcwdt200_reset = {
|
||||
.name = "atcwdt200",
|
||||
.system_reset_check = ae350_system_reset_check,
|
||||
.system_reset = ae350_system_reset,
|
||||
};
|
||||
|
||||
static int atcwdt200_reset_init(void *fdt, int nodeoff,
|
||||
const struct fdt_match *match)
|
||||
{
|
||||
uint64_t reg_addr;
|
||||
int rc;
|
||||
|
||||
rc = fdt_get_node_addr_size(fdt, nodeoff, 0, ®_addr, NULL);
|
||||
if (rc < 0 || !reg_addr)
|
||||
return SBI_ENODEV;
|
||||
|
||||
wdt_addr = (volatile char *)(unsigned long)reg_addr;
|
||||
|
||||
/*
|
||||
* The reset device requires smu to program the reset
|
||||
* vector for each hart.
|
||||
*/
|
||||
if (fdt_parse_compat_addr(fdt, ®_addr, "andestech,atcsmu"))
|
||||
return SBI_ENODEV;
|
||||
|
||||
smu_addr = (volatile char *)(unsigned long)reg_addr;
|
||||
|
||||
sbi_system_reset_add_device(&atcwdt200_reset);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct fdt_match atcwdt200_reset_match[] = {
|
||||
{ .compatible = "andestech,atcwdt200" },
|
||||
{},
|
||||
};
|
||||
|
||||
struct fdt_reset fdt_reset_atcwdt200 = {
|
||||
.match_table = atcwdt200_reset_match,
|
||||
.init = atcwdt200_reset_init,
|
||||
};
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user