From ef1f669cb7db5e3aebc390f5bd228cd88ed31a66 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Thu, 20 Dec 2018 18:23:52 +0530 Subject: [PATCH 0001/1765] top: More detailed top-level README.md This patch adds more details to top-level README.md based on current state of OpenSBI. Signed-off-by: Anup Patel --- README.md | 86 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 38922731b7c..82084c3d8c9 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,81 @@ RISC-V Open Source Supervisor Binary Interface (OpenSBI) ======================================================== -The RISC-V Supervisor Binary Interface (SBI) is a recommended +The **RISC-V Supervisor Binary Interface (SBI)** is a recommended interface between: -1. platform specific firmware running in M-mode and bootloader - running in S-mode -2. platform specific firmware running in M-mode and general - purpose operating system running in S-mode -3. hypervisor runnng in HS-mode and general purpose operating - system running in VS-mode. -The RISC-V SBI spec is maintained as independent project by -RISC-V Foundation at https://github.com/riscv/riscv-sbi-doc +1. Platform specific firmware running in M-mode and + general-purpose-os/hypervisor/bootloader running in S-mode/HS-mode +2. Hypervisor runnng in HS-mode and general-purpose-os/bootloader + running in VS-mode -The RISC-V OpenSBI project aims to provides an open-source and -extensible implementation of the SBI spec. This project can be -easily extended by RISC-V platform or RISC-V System-on-Chip vendors. +The **RISC-V SBI specification** is maintained as independent project +by RISC-V Foundation on [Github](https://github.com/riscv/riscv-sbi-doc) +The **RISC-V OpenSBI project** aims to provides an open-source and +extensible implementation of the **RISC-V SBI specification** for +point 1) mentioned above. It can be easily extended by RISC-V platform +or RISC-V System-on-Chip vendors. + +We can create three things using the RISC-V OpenSBI project: + +1. **libsbi.a** - Generic OpenSBI static library +2. **libplatsbi.a** - Platform specific OpenSBI static library + (It is libsbi.a plus platform specific hooks represented + by "platform" symbol) +3. **blobs** - Platform specific firware blobs How to Build? ------------- -Below are the steps to cross-compile and install RISC-V OpenSBI: +For cross-compiling, please ensure that CROSS_COMPILE environment +variable is set before starting build system. + +The libplatsbi.a and blobs are optional and only built when +`PLAT=` parameter is specified to top-level make. +(**NOTE**: `` is sub-directory under plat/ directory) -1. Setup build environment -$ CROSS_COMPILE=riscv64-unknown-linux-gnu- +To build and install Generic OpenSBI library do the following: -2. Build sources -$ make PLAT= +1. Build **libsbi.a**: +`make` OR -$ make PLAT= O= +`make O=` +2. Install **libsbi.a and headers**: +`make install` +OR +`make I= install` + +To build and install platform specific OpenSBI library and blobs +do the following: -3. Install blobs -$ make PLAT= install +1. Build **libsbi, libplatsbi, and blobs**: +`make PLAT=` +OR +`make PLAT= O=` +2. Install **libsbi, headers, libplatsbi, and blobs**: +`make PLAT= install` OR -$ make PLAT= I= install +`make PLAT= I= install` + +In addition, we can also specify platform specific command-line +options to top-level make (such as `PLAT_` or `FW_`) +which are described under `docs/plat/.md` OR +`docs/blob/.md`. + +Documentation +------------- + +All our documenation is under `docs` directory organized in following +manner: + +* `docs/platform_guide.md` - Guidelines for adding new platform support +* `docs/library_usage.md` - Guidelines for using static library +* `docs/plat/.md` - Documentation for `` platform +* `docs/blob/.md` - Documentation for firmware blob `` + +We also prefer source level documentation, so wherever possible we describe +stuff directly in the source code. This helps us maintain source and its +documentation at the same place. For source level documentation we strictly +follow Doxygen style. Please refer [Doxygen manual] +(http://www.stack.nl/~dimitri/doxygen/manual.html) for details. \ No newline at end of file From 33ec85c9ab234f546b5814a8bd1dad9ab698a6b0 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Thu, 20 Dec 2018 21:04:38 +0530 Subject: [PATCH 0002/1765] docs: Add documentation for firmware blobs This patch adds documentation for fw_jump and fw_payload firmware blobs. Signed-off-by: Anup Patel --- docs/blob/fw_jump.md | 37 ++++++++++++++++++++++++++++++ docs/blob/fw_payload.md | 51 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 docs/blob/fw_jump.md create mode 100644 docs/blob/fw_payload.md diff --git a/docs/blob/fw_jump.md b/docs/blob/fw_jump.md new file mode 100644 index 00000000000..ee6ad0d8780 --- /dev/null +++ b/docs/blob/fw_jump.md @@ -0,0 +1,37 @@ +OpenSBI Firmware with Jump Address(FW_JUMP) +=========================================== + +The **OpenSBI firmware with Jump Address (FW_JUMP)** is a +firmware which only know the address of next booting stage +(i.e. bootloader/kernel). + +This **FW_JUMP** firmware is particularly useful when booting +stage prior to OpenSBI firmware is capable of loading OpenSBI +firmware and booting stage after OpenSBI firmware separately. + +How to Enable? +-------------- + +The **FW_JUMP** firmware can be enabled by any of the following +methods: + +1. Passing `FW_JUMP=y` command-line parameter to +top-level `make` +2. Setting `FW_JUMP=y` in platform `config.mk` + +Config Options +-------------- + +We need more config details for **FW_JUMP** firmware to work +correctly. These config details can be passed as paramter to +top-level `make` or can be set in platform `config.mk`. + +Following are the config options for **FW_JUMP** firmware: + +* **FW_JUMP_ADDR** - Address where next booting stage is +located. This is a mandatory config option and will result +in compile error if not provided. +* **FW_JUMP_FDT_ADDR** - Address where FDT passed by prior +booting stage will be placed before passing to next booting +stage. If this option is not provided then firmware will pass +zero as FDT address to next booting stage. \ No newline at end of file diff --git a/docs/blob/fw_payload.md b/docs/blob/fw_payload.md new file mode 100644 index 00000000000..2fab092cc68 --- /dev/null +++ b/docs/blob/fw_payload.md @@ -0,0 +1,51 @@ +OpenSBI Firmware with Payload (FW_PAYLOAD) +========================================== + +The **OpenSBI firmware with Payload (FW_PAYLOAD)** is a +firmware which includes next booting stage binary (i.e. +bootloader/kernel) as payload in the OpenSBI firmware binary. + +This **FW_PAYLOAD** firmware is particularly useful when +booting stage prior to OpenSBI firmware is not capable of +loading OpenSBI firmware and booting stage after OpenSBI +firmware separately. + +It is also possible that booting stage prior to OpenSBI +firmware does not pass **flattened device tree (FDT)**. In +this case, we have provision to embed FDT in .text section +of **FW_PAYLOAD** firmware. + +How to Enable? +-------------- + +The **FW_PAYLOAD** firmware can be enabled by any of the +following methods: + +1. Passing `FW_PAYLOAD=y` command-line parameter to +top-level `make` +2. Setting `FW_PAYLOAD=y` in platform `config.mk` + +Config Options +-------------- + +We need more config details for **FW_PAYLOAD** firmware to +work correctly. These config details can be passed as paramter +to top-level `make` or can be set in platform `config.mk`. + +Following are the config options for **FW_PAYLOAD** firmware: + +* **FW_PAYLOAD_OFFSET** - Offset from FW_TEXT_BASE where next +booting stage binary will be linked to **FW_PAYLOAD** firmware. +This is a mandatory config option and will result in compile +error if not provided. +* **FW_PAYLOAD_PATH** - Path to the next booting stage binary. +If this option is not provided then **`while (1)`** is taken as +payload. +* **FW_PAYLOAD_FDT_PATH** - Path to the FDT binary to be embedded +in .text section of **FW_PAYLOAD** firmware. If this option is +not provided then firmware will expect FDT to be passed by prior +booting stage. +* **FW_PAYLOAD_FDT_ADDR** - Address where FDT passed by prior +booting stage (or embedded FDT) will be placed before passing +to next booting stage. If this option is not provided then +firmware will pass zero as FDT address to next booting stage. \ No newline at end of file From ab5b228ff596657dffce4a2ed96cd73a95e1864b Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 21 Dec 2018 07:51:59 +0530 Subject: [PATCH 0003/1765] lib: sbi_hart: Remove unwanted sbi_printf() This patch removes unwanted sbi_printf() from sbi_hart_wait_for_coldboot(). Signed-off-by: Anup Patel --- lib/sbi_hart.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/sbi_hart.c b/lib/sbi_hart.c index 30f4f03f014..fd6d4d40695 100644 --- a/lib/sbi_hart.c +++ b/lib/sbi_hart.c @@ -270,7 +270,6 @@ void sbi_hart_wait_for_coldboot(struct sbi_scratch *scratch, u32 hartid) unsigned long mipval; struct sbi_platform *plat = sbi_platform_ptr(scratch); - sbi_printf("%s: In hartid = [%d]\n", __func__, hartid); if ((sbi_platform_hart_count(plat) <= hartid) || (NO_HOTPLUG_BITMAP_SIZE <= hartid)) sbi_hart_hang(); @@ -287,11 +286,10 @@ void sbi_hart_wake_coldboot_harts(struct sbi_scratch *scratch, u32 hartid) { struct sbi_platform *plat = sbi_platform_ptr(scratch); int max_hart = sbi_platform_hart_count(plat); - + for(int i = 0; i < max_hart ; i++) { /* send an IPI to every other hart */ if (i != hartid) - sbi_platform_ipi_inject(plat, i, hartid); - } - + sbi_platform_ipi_inject(plat, i, hartid); + } } From b023176c17e655f9371df65f6fddc0c1bcbb1fc7 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 21 Dec 2018 09:52:27 +0530 Subject: [PATCH 0004/1765] top: Rename "blob" to "firmware" everywhere This patch renames "blob" to "firmware" everywhere for better and intutive naming. Signed-off-by: Anup Patel --- Makefile | 34 +++++++++++------------ README.md | 14 +++++----- blob/objects.mk | 39 --------------------------- docs/{blob => firmware}/fw_jump.md | 0 docs/{blob => firmware}/fw_payload.md | 0 {blob => firmware}/fw_common.S | 0 {blob => firmware}/fw_common.ldS | 0 {blob => firmware}/fw_jump.S | 0 {blob => firmware}/fw_jump.elf.ldS | 0 {blob => firmware}/fw_payload.S | 0 {blob => firmware}/fw_payload.elf.ldS | 0 firmware/objects.mk | 39 +++++++++++++++++++++++++++ 12 files changed, 63 insertions(+), 63 deletions(-) delete mode 100644 blob/objects.mk rename docs/{blob => firmware}/fw_jump.md (100%) rename docs/{blob => firmware}/fw_payload.md (100%) rename {blob => firmware}/fw_common.S (100%) rename {blob => firmware}/fw_common.ldS (100%) rename {blob => firmware}/fw_jump.S (100%) rename {blob => firmware}/fw_jump.elf.ldS (100%) rename {blob => firmware}/fw_payload.S (100%) rename {blob => firmware}/fw_payload.elf.ldS (100%) create mode 100644 firmware/objects.mk diff --git a/Makefile b/Makefile index ff416744e2d..112d3722b65 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,7 @@ export plat_dir=$(CURDIR)/$(plat_subdir) export plat_common_dir=$(CURDIR)/plat/common export include_dir=$(CURDIR)/include export lib_dir=$(CURDIR)/lib -export blob_dir=$(CURDIR)/blob +export firmware_dir=$(CURDIR)/firmware # Setup list of objects.mk files ifdef PLAT @@ -70,7 +70,7 @@ plat-object-mks=$(shell if [ -d $(plat_dir) ]; then find $(plat_dir) -iname "obj plat-common-object-mks=$(shell if [ -d $(plat_common_dir) ]; then find $(plat_common_dir) -iname "objects.mk" | sort -r; fi) endif lib-object-mks=$(shell if [ -d $(lib_dir) ]; then find $(lib_dir) -iname "objects.mk" | sort -r; fi) -blob-object-mks=$(shell if [ -d $(blob_dir) ]; then find $(blob_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 ifdef PLAT @@ -83,23 +83,23 @@ include $(plat-object-mks) include $(plat-common-object-mks) endif include $(lib-object-mks) -include $(blob-object-mks) +include $(firmware-object-mks) # Setup list of objects lib-objs-path-y=$(foreach obj,$(lib-objs-y),$(build_dir)/lib/$(obj)) ifdef PLAT plat-objs-path-y=$(foreach obj,$(plat-objs-y),$(build_dir)/$(plat_subdir)/$(obj)) plat-common-objs-path-y=$(foreach obj,$(plat-common-objs-y),$(build_dir)/plat/common/$(obj)) -blob-bins-path-y=$(foreach bin,$(blob-bins-y),$(build_dir)/$(plat_subdir)/blob/$(bin)) +firmware-bins-path-y=$(foreach bin,$(firmware-bins-y),$(build_dir)/$(plat_subdir)/firmware/$(bin)) endif -blob-elfs-path-y=$(blob-bins-path-y:.bin=.elf) -blob-objs-path-y=$(blob-bins-path-y:.bin=.o) +firmware-elfs-path-y=$(firmware-bins-path-y:.bin=.elf) +firmware-objs-path-y=$(firmware-bins-path-y:.bin=.o) # Setup list of deps files for objects deps-y=$(plat-objs-path-y:.o=.dep) deps-y+=$(plat-common-objs-path-y:.o=.dep) deps-y+=$(lib-objs-path-y:.o=.dep) -deps-y+=$(blob-objs-path-y:.o=.dep) +deps-y+=$(firmware-objs-path-y:.o=.dep) # Setup compilation environment cpp=$(CROSS_COMPILE)cpp @@ -109,14 +109,14 @@ cppflags+=-I$(plat_dir)/include cppflags+=-I$(plat_common_dir)/include cppflags+=-I$(include_dir) cppflags+=$(plat-cppflags-y) -cppflags+=$(blob-cppflags-y) +cppflags+=$(firmware-cppflags-y) cc=$(CROSS_COMPILE)gcc cflags=-g -Wall -Werror -nostdlib -fno-strict-aliasing -O2 cflags+=-fno-omit-frame-pointer -fno-optimize-sibling-calls cflags+=-mno-save-restore -mstrict-align cflags+=$(cppflags) cflags+=$(plat-cflags-y) -cflags+=$(blob-cflags-y) +cflags+=$(firmware-cflags-y) cflags+=$(EXTRA_CFLAGS) as=$(CROSS_COMPILE)gcc asflags=-g -Wall -nostdlib -D__ASSEMBLY__ @@ -124,14 +124,14 @@ asflags+=-fno-omit-frame-pointer -fno-optimize-sibling-calls asflags+=-mno-save-restore -mstrict-align asflags+=$(cppflags) asflags+=$(plat-asflags-y) -asflags+=$(blob-asflags-y) +asflags+=$(firmware-asflags-y) asflags+=$(EXTRA_ASFLAGS) ar=$(CROSS_COMPILE)ar arflags=rcs ld=$(CROSS_COMPILE)gcc ldflags=-g -Wall -nostdlib -Wl,--build-id=none ldflags+=$(plat-ldflags-y) -ldflags+=$(blob-ldflags-y) +ldflags+=$(firmware-ldflags-y) merge=$(CROSS_COMPILE)ld mergeflags=-r objcopy=$(CROSS_COMPILE)objcopy @@ -195,7 +195,7 @@ targets-y = $(build_dir)/lib/libsbi.a ifdef PLAT targets-y += $(build_dir)/$(plat_subdir)/lib/libplatsbi.a endif -targets-y += $(blob-bins-path-y) +targets-y += $(firmware-bins-path-y) # Default rule "make" should always be first rule .PHONY: all @@ -252,7 +252,7 @@ all-deps-2 = $(if $(findstring clean,$(MAKECMDGOALS)),,$(all-deps-1)) install_targets-y = install_libsbi ifdef PLAT install_targets-y += install_libplatsbi -install_targets-y += install_blobs +install_targets-y += install_firmwares endif # Rule for "make install" @@ -269,10 +269,10 @@ install_libplatsbi: $(build_dir)/$(plat_subdir)/lib/libplatsbi.a $(build_dir)/li $(call inst_header_dir,$(install_dir)/$(plat_subdir)/include,$(include_dir)/sbi) $(call inst_file,$(install_dir)/$(plat_subdir)/lib/libplatsbi.a,$(build_dir)/$(plat_subdir)/lib/libplatsbi.a) -.PHONY: install_blobs -install_blobs: $(build_dir)/$(plat_subdir)/lib/libplatsbi.a $(build_dir)/lib/libsbi.a $(blob-bins-path-y) - $(call inst_file_list,$(install_dir)/$(plat_subdir)/blob,$(plat_subdir)/blob,$(blob-elfs-path-y)) - $(call inst_file_list,$(install_dir)/$(plat_subdir)/blob,$(plat_subdir)/blob,$(blob-bins-path-y)) +.PHONY: install_firmwares +install_firmwares: $(build_dir)/$(plat_subdir)/lib/libplatsbi.a $(build_dir)/lib/libsbi.a $(firmware-bins-path-y) + $(call inst_file_list,$(install_dir)/$(plat_subdir)/firmware,$(plat_subdir)/firmware,$(firmware-elfs-path-y)) + $(call inst_file_list,$(install_dir)/$(plat_subdir)/firmware,$(plat_subdir)/firmware,$(firmware-bins-path-y)) # Rule for "make clean" .PHONY: clean diff --git a/README.md b/README.md index 82084c3d8c9..ca70e0eff46 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ We can create three things using the RISC-V OpenSBI project: 2. **libplatsbi.a** - Platform specific OpenSBI static library (It is libsbi.a plus platform specific hooks represented by "platform" symbol) -3. **blobs** - Platform specific firware blobs +3. **firmwares** - Platform specific firmware binaries How to Build? ------------- @@ -31,7 +31,7 @@ How to Build? For cross-compiling, please ensure that CROSS_COMPILE environment variable is set before starting build system. -The libplatsbi.a and blobs are optional and only built when +The libplatsbi.a and firmwares are optional and only built when `PLAT=` parameter is specified to top-level make. (**NOTE**: `` is sub-directory under plat/ directory) @@ -46,14 +46,14 @@ OR OR `make I= install` -To build and install platform specific OpenSBI library and blobs +To build and install platform specific OpenSBI library and firmwares do the following: -1. Build **libsbi, libplatsbi, and blobs**: +1. Build **libsbi, libplatsbi, and firmwares**: `make PLAT=` OR `make PLAT= O=` -2. Install **libsbi, headers, libplatsbi, and blobs**: +2. Install **libsbi, headers, libplatsbi, and firmwares**: `make PLAT= install` OR `make PLAT= I= install` @@ -61,7 +61,7 @@ OR In addition, we can also specify platform specific command-line options to top-level make (such as `PLAT_` or `FW_`) which are described under `docs/plat/.md` OR -`docs/blob/.md`. +`docs/firmware/.md`. Documentation ------------- @@ -72,7 +72,7 @@ manner: * `docs/platform_guide.md` - Guidelines for adding new platform support * `docs/library_usage.md` - Guidelines for using static library * `docs/plat/.md` - Documentation for `` platform -* `docs/blob/.md` - Documentation for firmware blob `` +* `docs/firmware/.md` - Documentation for firmware `` We also prefer source level documentation, so wherever possible we describe stuff directly in the source code. This helps us maintain source and its diff --git a/blob/objects.mk b/blob/objects.mk deleted file mode 100644 index 717f4550552..00000000000 --- a/blob/objects.mk +++ /dev/null @@ -1,39 +0,0 @@ -# -# Copyright (c) 2018 Western Digital Corporation or its affiliates. -# -# Authors: -# Anup Patel -# -# SPDX-License-Identifier: BSD-2-Clause -# - -blob-cppflags-y = -blob-cflags-y = -blob-asflags-y = -blob-ldflags-y = - -ifdef FW_TEXT_START -blob-cppflags-y += -DFW_TEXT_START=$(FW_TEXT_START) -endif - -blob-bins-$(FW_JUMP) += fw_jump.bin -ifdef FW_JUMP_ADDR -blob-cppflags-$(FW_JUMP) += -DFW_JUMP_ADDR=$(FW_JUMP_ADDR) -endif -ifdef FW_JUMP_FDT_ADDR -blob-cppflags-$(FW_JUMP) += -DFW_JUMP_FDT_ADDR=$(FW_JUMP_FDT_ADDR) -endif - -blob-bins-$(FW_PAYLOAD) += fw_payload.bin -ifdef FW_PAYLOAD_PATH -blob-cppflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_PATH=$(FW_PAYLOAD_PATH) -endif -ifdef FW_PAYLOAD_OFFSET -blob-cppflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_OFFSET=$(FW_PAYLOAD_OFFSET) -endif -ifdef FW_PAYLOAD_FDT_PATH -blob-cppflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_FDT_PATH=$(FW_PAYLOAD_FDT_PATH) -endif -ifdef FW_PAYLOAD_FDT_ADDR -blob-cppflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_FDT_ADDR=$(FW_PAYLOAD_FDT_ADDR) -endif diff --git a/docs/blob/fw_jump.md b/docs/firmware/fw_jump.md similarity index 100% rename from docs/blob/fw_jump.md rename to docs/firmware/fw_jump.md diff --git a/docs/blob/fw_payload.md b/docs/firmware/fw_payload.md similarity index 100% rename from docs/blob/fw_payload.md rename to docs/firmware/fw_payload.md diff --git a/blob/fw_common.S b/firmware/fw_common.S similarity index 100% rename from blob/fw_common.S rename to firmware/fw_common.S diff --git a/blob/fw_common.ldS b/firmware/fw_common.ldS similarity index 100% rename from blob/fw_common.ldS rename to firmware/fw_common.ldS diff --git a/blob/fw_jump.S b/firmware/fw_jump.S similarity index 100% rename from blob/fw_jump.S rename to firmware/fw_jump.S diff --git a/blob/fw_jump.elf.ldS b/firmware/fw_jump.elf.ldS similarity index 100% rename from blob/fw_jump.elf.ldS rename to firmware/fw_jump.elf.ldS diff --git a/blob/fw_payload.S b/firmware/fw_payload.S similarity index 100% rename from blob/fw_payload.S rename to firmware/fw_payload.S diff --git a/blob/fw_payload.elf.ldS b/firmware/fw_payload.elf.ldS similarity index 100% rename from blob/fw_payload.elf.ldS rename to firmware/fw_payload.elf.ldS diff --git a/firmware/objects.mk b/firmware/objects.mk new file mode 100644 index 00000000000..9bed733de64 --- /dev/null +++ b/firmware/objects.mk @@ -0,0 +1,39 @@ +# +# Copyright (c) 2018 Western Digital Corporation or its affiliates. +# +# Authors: +# Anup Patel +# +# SPDX-License-Identifier: BSD-2-Clause +# + +firmware-cppflags-y = +firmware-cflags-y = +firmware-asflags-y = +firmware-ldflags-y = + +ifdef FW_TEXT_START +firmware-cppflags-y += -DFW_TEXT_START=$(FW_TEXT_START) +endif + +firmware-bins-$(FW_JUMP) += fw_jump.bin +ifdef FW_JUMP_ADDR +firmware-cppflags-$(FW_JUMP) += -DFW_JUMP_ADDR=$(FW_JUMP_ADDR) +endif +ifdef FW_JUMP_FDT_ADDR +firmware-cppflags-$(FW_JUMP) += -DFW_JUMP_FDT_ADDR=$(FW_JUMP_FDT_ADDR) +endif + +firmware-bins-$(FW_PAYLOAD) += fw_payload.bin +ifdef FW_PAYLOAD_PATH +firmware-cppflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_PATH=$(FW_PAYLOAD_PATH) +endif +ifdef FW_PAYLOAD_OFFSET +firmware-cppflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_OFFSET=$(FW_PAYLOAD_OFFSET) +endif +ifdef FW_PAYLOAD_FDT_PATH +firmware-cppflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_FDT_PATH=$(FW_PAYLOAD_FDT_PATH) +endif +ifdef FW_PAYLOAD_FDT_ADDR +firmware-cppflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_FDT_ADDR=$(FW_PAYLOAD_FDT_ADDR) +endif From 6f02b6938f8e607d38ee8de5a59581d554af0d3f Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 21 Dec 2018 10:09:33 +0530 Subject: [PATCH 0005/1765] lib: Introduce bitmap to track HARTs waiting for coldboot On QEMU Virt, max supported HARTs are 8 but number of HARTs actually depend on "-smp" command-line parameter passed to QEMU. This creates problems in sbi_hart_wake_coldboot_harts() because when number of HARTs are less than 8. To tackle this, we introduce a bitmap to track HARTs waiting for coldboot to finish. We wake only those HARTs who have set their bit in coldboot bitmap. Signed-off-by: Anup Patel --- lib/sbi_hart.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/sbi_hart.c b/lib/sbi_hart.c index fd6d4d40695..5b26aead51b 100644 --- a/lib/sbi_hart.c +++ b/lib/sbi_hart.c @@ -263,7 +263,9 @@ struct sbi_scratch *sbi_hart_id_to_scratch(struct sbi_scratch *scratch, return ((h2s)scratch->hartid_to_scratch)(hartid); } -#define NO_HOTPLUG_BITMAP_SIZE __riscv_xlen +#define COLDBOOT_WAIT_BITMAP_SIZE __riscv_xlen +static spinlock_t coldboot_wait_bitmap_lock = SPIN_LOCK_INITIALIZER; +static unsigned long coldboot_wait_bitmap = 0; void sbi_hart_wait_for_coldboot(struct sbi_scratch *scratch, u32 hartid) { @@ -271,13 +273,20 @@ void sbi_hart_wait_for_coldboot(struct sbi_scratch *scratch, u32 hartid) struct sbi_platform *plat = sbi_platform_ptr(scratch); if ((sbi_platform_hart_count(plat) <= hartid) || - (NO_HOTPLUG_BITMAP_SIZE <= hartid)) + (COLDBOOT_WAIT_BITMAP_SIZE <= hartid)) sbi_hart_hang(); do { + spin_lock(&coldboot_wait_bitmap_lock); + coldboot_wait_bitmap |= (1UL << hartid); + spin_unlock(&coldboot_wait_bitmap_lock); + wfi(); mipval = csr_read(mip); - /* Make sure the hart woke because of ipi */ - } while (!(mipval && MIP_MSIP) ); + + spin_lock(&coldboot_wait_bitmap_lock); + coldboot_wait_bitmap &= ~(1UL << hartid); + spin_unlock(&coldboot_wait_bitmap_lock); + } while (!(mipval && MIP_MSIP)); csr_clear(mip, MIP_MSIP); } @@ -289,7 +298,9 @@ void sbi_hart_wake_coldboot_harts(struct sbi_scratch *scratch, u32 hartid) for(int i = 0; i < max_hart ; i++) { /* send an IPI to every other hart */ - if (i != hartid) + spin_lock(&coldboot_wait_bitmap_lock); + if ((i != hartid) && (coldboot_wait_bitmap & (1UL << i))) sbi_platform_ipi_inject(plat, i, hartid); + spin_unlock(&coldboot_wait_bitmap_lock); } } From 089f70a1798b5c631e87eeb26b7eb2593571c63d Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 21 Dec 2018 10:35:04 +0530 Subject: [PATCH 0006/1765] top: Rename "plat" to "platform" everywhere This patch renames "plat" to "platform" everywhere for better readablility. Signed-off-by: Anup Patel --- Makefile | 80 +++++++++---------- README.md | 16 ++-- {plat => platform}/common/fdt.c | 0 {plat => platform}/common/include/plat/fdt.h | 0 .../common/include/plat/irqchip/plic.h | 0 .../common/include/plat/serial/sifive-uart.h | 0 .../common/include/plat/serial/uart8250.h | 0 .../common/include/plat/sys/clint.h | 0 .../common/irqchip}/objects.mk | 2 +- {plat => platform}/common/irqchip/plic.c | 0 .../qemu/virt => platform/common}/objects.mk | 2 +- {plat => platform}/common/serial/objects.mk | 4 +- .../common/serial/sifive-uart.c | 0 {plat => platform}/common/serial/uart8250.c | 0 {plat => platform}/common/sys/clint.c | 0 .../common/sys}/objects.mk | 2 +- {plat => platform}/kendryte/k210/config.mk | 16 ++-- {plat => platform}/kendryte/k210/objects.mk | 2 +- {plat => platform}/kendryte/k210/platform.c | 0 {plat => platform}/kendryte/k210/platform.h | 0 {plat => platform}/kendryte/k210/sysctl.c | 0 {plat => platform}/kendryte/k210/sysctl.h | 0 {plat => platform}/kendryte/k210/uarths.c | 0 {plat => platform}/kendryte/k210/uarths.h | 0 .../qemu/sifive_u}/config.mk | 18 ++--- {plat => platform}/qemu/sifive_u/objects.mk | 2 +- {plat => platform}/qemu/sifive_u/platform.c | 0 .../sifive_u => platform/qemu/virt}/config.mk | 18 ++--- .../common => platform/qemu/virt}/objects.mk | 2 +- {plat => platform}/qemu/virt/platform.c | 0 .../sifive/hifive_u540}/config.mk | 18 ++--- .../sifive/hifive_u540/objects.mk | 2 +- .../sifive/hifive_u540/platform.c | 0 33 files changed, 92 insertions(+), 92 deletions(-) rename {plat => platform}/common/fdt.c (100%) rename {plat => platform}/common/include/plat/fdt.h (100%) rename {plat => platform}/common/include/plat/irqchip/plic.h (100%) rename {plat => platform}/common/include/plat/serial/sifive-uart.h (100%) rename {plat => platform}/common/include/plat/serial/uart8250.h (100%) rename {plat => platform}/common/include/plat/sys/clint.h (100%) rename {plat/common/sys => platform/common/irqchip}/objects.mk (71%) rename {plat => platform}/common/irqchip/plic.c (100%) rename {plat/qemu/virt => platform/common}/objects.mk (83%) rename {plat => platform}/common/serial/objects.mk (52%) rename {plat => platform}/common/serial/sifive-uart.c (100%) rename {plat => platform}/common/serial/uart8250.c (100%) rename {plat => platform}/common/sys/clint.c (100%) rename {plat/common/irqchip => platform/common/sys}/objects.mk (73%) rename {plat => platform}/kendryte/k210/config.mk (52%) rename {plat => platform}/kendryte/k210/objects.mk (77%) rename {plat => platform}/kendryte/k210/platform.c (100%) rename {plat => platform}/kendryte/k210/platform.h (100%) rename {plat => platform}/kendryte/k210/sysctl.c (100%) rename {plat => platform}/kendryte/k210/sysctl.h (100%) rename {plat => platform}/kendryte/k210/uarths.c (100%) rename {plat => platform}/kendryte/k210/uarths.h (100%) rename {plat/sifive/hifive_u540 => platform/qemu/sifive_u}/config.mk (53%) rename {plat => platform}/qemu/sifive_u/objects.mk (84%) rename {plat => platform}/qemu/sifive_u/platform.c (100%) rename {plat/qemu/sifive_u => platform/qemu/virt}/config.mk (53%) rename {plat/common => platform/qemu/virt}/objects.mk (84%) rename {plat => platform}/qemu/virt/platform.c (100%) rename {plat/qemu/virt => platform/sifive/hifive_u540}/config.mk (53%) rename {plat => platform}/sifive/hifive_u540/objects.mk (84%) rename {plat => platform}/sifive/hifive_u540/platform.c (100%) diff --git a/Makefile b/Makefile index 112d3722b65..f544a6488be 100644 --- a/Makefile +++ b/Makefile @@ -57,47 +57,47 @@ else endif # Setup path of directories -export plat_subdir=plat/$(PLAT) -export plat_dir=$(CURDIR)/$(plat_subdir) -export plat_common_dir=$(CURDIR)/plat/common +export platform_subdir=platform/$(PLATFORM) +export platform_dir=$(CURDIR)/$(platform_subdir) +export platform_common_dir=$(CURDIR)/platform/common export include_dir=$(CURDIR)/include export lib_dir=$(CURDIR)/lib export firmware_dir=$(CURDIR)/firmware # Setup list of objects.mk files -ifdef PLAT -plat-object-mks=$(shell if [ -d $(plat_dir) ]; then find $(plat_dir) -iname "objects.mk" | sort -r; fi) -plat-common-object-mks=$(shell if [ -d $(plat_common_dir) ]; then find $(plat_common_dir) -iname "objects.mk" | sort -r; fi) +ifdef PLATFORM +platform-object-mks=$(shell if [ -d $(platform_dir) ]; then find $(platform_dir) -iname "objects.mk" | sort -r; fi) +platform-common-object-mks=$(shell if [ -d $(platform_common_dir) ]; then find $(platform_common_dir) -iname "objects.mk" | sort -r; fi) endif lib-object-mks=$(shell if [ -d $(lib_dir) ]; then find $(lib_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 -ifdef PLAT -include $(plat_dir)/config.mk +ifdef PLATFORM +include $(platform_dir)/config.mk endif # Include all object.mk files -ifdef PLAT -include $(plat-object-mks) -include $(plat-common-object-mks) +ifdef PLATFORM +include $(platform-object-mks) +include $(platform-common-object-mks) endif include $(lib-object-mks) include $(firmware-object-mks) # Setup list of objects lib-objs-path-y=$(foreach obj,$(lib-objs-y),$(build_dir)/lib/$(obj)) -ifdef PLAT -plat-objs-path-y=$(foreach obj,$(plat-objs-y),$(build_dir)/$(plat_subdir)/$(obj)) -plat-common-objs-path-y=$(foreach obj,$(plat-common-objs-y),$(build_dir)/plat/common/$(obj)) -firmware-bins-path-y=$(foreach bin,$(firmware-bins-y),$(build_dir)/$(plat_subdir)/firmware/$(bin)) +ifdef PLATFORM +platform-objs-path-y=$(foreach obj,$(platform-objs-y),$(build_dir)/$(platform_subdir)/$(obj)) +platform-common-objs-path-y=$(foreach obj,$(platform-common-objs-y),$(build_dir)/platform/common/$(obj)) +firmware-bins-path-y=$(foreach bin,$(firmware-bins-y),$(build_dir)/$(platform_subdir)/firmware/$(bin)) endif firmware-elfs-path-y=$(firmware-bins-path-y:.bin=.elf) firmware-objs-path-y=$(firmware-bins-path-y:.bin=.o) # Setup list of deps files for objects -deps-y=$(plat-objs-path-y:.o=.dep) -deps-y+=$(plat-common-objs-path-y:.o=.dep) +deps-y=$(platform-objs-path-y:.o=.dep) +deps-y+=$(platform-common-objs-path-y:.o=.dep) deps-y+=$(lib-objs-path-y:.o=.dep) deps-y+=$(firmware-objs-path-y:.o=.dep) @@ -105,17 +105,17 @@ deps-y+=$(firmware-objs-path-y:.o=.dep) cpp=$(CROSS_COMPILE)cpp cppflags+=-DOPENSBI_MAJOR=$(MAJOR) cppflags+=-DOPENSBI_MINOR=$(MINOR) -cppflags+=-I$(plat_dir)/include -cppflags+=-I$(plat_common_dir)/include +cppflags+=-I$(platform_dir)/include +cppflags+=-I$(platform_common_dir)/include cppflags+=-I$(include_dir) -cppflags+=$(plat-cppflags-y) +cppflags+=$(platform-cppflags-y) cppflags+=$(firmware-cppflags-y) cc=$(CROSS_COMPILE)gcc cflags=-g -Wall -Werror -nostdlib -fno-strict-aliasing -O2 cflags+=-fno-omit-frame-pointer -fno-optimize-sibling-calls cflags+=-mno-save-restore -mstrict-align cflags+=$(cppflags) -cflags+=$(plat-cflags-y) +cflags+=$(platform-cflags-y) cflags+=$(firmware-cflags-y) cflags+=$(EXTRA_CFLAGS) as=$(CROSS_COMPILE)gcc @@ -123,14 +123,14 @@ asflags=-g -Wall -nostdlib -D__ASSEMBLY__ asflags+=-fno-omit-frame-pointer -fno-optimize-sibling-calls asflags+=-mno-save-restore -mstrict-align asflags+=$(cppflags) -asflags+=$(plat-asflags-y) +asflags+=$(platform-asflags-y) asflags+=$(firmware-asflags-y) asflags+=$(EXTRA_ASFLAGS) ar=$(CROSS_COMPILE)ar arflags=rcs ld=$(CROSS_COMPILE)gcc ldflags=-g -Wall -nostdlib -Wl,--build-id=none -ldflags+=$(plat-ldflags-y) +ldflags+=$(platform-ldflags-y) ldflags+=$(firmware-ldflags-y) merge=$(CROSS_COMPILE)ld mergeflags=-r @@ -192,8 +192,8 @@ compile_objcopy = $(V)mkdir -p `dirname $(1)`; \ $(objcopy) -S -O binary $(2) $(1) targets-y = $(build_dir)/lib/libsbi.a -ifdef PLAT -targets-y += $(build_dir)/$(plat_subdir)/lib/libplatsbi.a +ifdef PLATFORM +targets-y += $(build_dir)/$(platform_subdir)/lib/libplatsbi.a endif targets-y += $(firmware-bins-path-y) @@ -207,16 +207,16 @@ all: $(targets-y) $(build_dir)/%.bin: $(build_dir)/%.elf $(call compile_objcopy,$@,$<) -$(build_dir)/%.elf: $(build_dir)/%.o $(build_dir)/%.elf.ld $(build_dir)/$(plat_subdir)/lib/libplatsbi.a - $(call compile_ld,$@,$@.ld,$< $(build_dir)/$(plat_subdir)/lib/libplatsbi.a) +$(build_dir)/%.elf: $(build_dir)/%.o $(build_dir)/%.elf.ld $(build_dir)/$(platform_subdir)/lib/libplatsbi.a + $(call compile_ld,$@,$@.ld,$< $(build_dir)/$(platform_subdir)/lib/libplatsbi.a) -$(build_dir)/$(plat_subdir)/%.ld: $(src_dir)/%.ldS +$(build_dir)/$(platform_subdir)/%.ld: $(src_dir)/%.ldS $(call compile_cpp,$@,$<) $(build_dir)/lib/libsbi.a: $(lib-objs-path-y) $(call compile_ar,$@,$^) -$(build_dir)/$(plat_subdir)/lib/libplatsbi.a: $(lib-objs-path-y) $(plat-common-objs-path-y) $(plat-objs-path-y) +$(build_dir)/$(platform_subdir)/lib/libplatsbi.a: $(lib-objs-path-y) $(platform-common-objs-path-y) $(platform-objs-path-y) $(call compile_ar,$@,$^) $(build_dir)/%.dep: $(src_dir)/%.c @@ -231,16 +231,16 @@ $(build_dir)/%.dep: $(src_dir)/%.S $(build_dir)/%.o: $(src_dir)/%.S $(call compile_as,$@,$<) -$(build_dir)/$(plat_subdir)/%.dep: $(src_dir)/%.c +$(build_dir)/$(platform_subdir)/%.dep: $(src_dir)/%.c $(call compile_cc_dep,$@,$<) -$(build_dir)/$(plat_subdir)/%.o: $(src_dir)/%.c +$(build_dir)/$(platform_subdir)/%.o: $(src_dir)/%.c $(call compile_cc,$@,$<) -$(build_dir)/$(plat_subdir)/%.dep: $(src_dir)/%.S +$(build_dir)/$(platform_subdir)/%.dep: $(src_dir)/%.S $(call compile_as_dep,$@,$<) -$(build_dir)/$(plat_subdir)/%.o: $(src_dir)/%.S +$(build_dir)/$(platform_subdir)/%.o: $(src_dir)/%.S $(call compile_as,$@,$<) # Dependency files should only be included after default Makefile rule @@ -250,7 +250,7 @@ all-deps-2 = $(if $(findstring clean,$(MAKECMDGOALS)),,$(all-deps-1)) -include $(all-deps-2) install_targets-y = install_libsbi -ifdef PLAT +ifdef PLATFORM install_targets-y += install_libplatsbi install_targets-y += install_firmwares endif @@ -265,14 +265,14 @@ install_libsbi: $(build_dir)/lib/libsbi.a $(call inst_file,$(install_dir)/lib/libsbi.a,$(build_dir)/lib/libsbi.a) .PHONY: install_libplatsbi -install_libplatsbi: $(build_dir)/$(plat_subdir)/lib/libplatsbi.a $(build_dir)/lib/libsbi.a - $(call inst_header_dir,$(install_dir)/$(plat_subdir)/include,$(include_dir)/sbi) - $(call inst_file,$(install_dir)/$(plat_subdir)/lib/libplatsbi.a,$(build_dir)/$(plat_subdir)/lib/libplatsbi.a) +install_libplatsbi: $(build_dir)/$(platform_subdir)/lib/libplatsbi.a $(build_dir)/lib/libsbi.a + $(call inst_header_dir,$(install_dir)/$(platform_subdir)/include,$(include_dir)/sbi) + $(call inst_file,$(install_dir)/$(platform_subdir)/lib/libplatsbi.a,$(build_dir)/$(platform_subdir)/lib/libplatsbi.a) .PHONY: install_firmwares -install_firmwares: $(build_dir)/$(plat_subdir)/lib/libplatsbi.a $(build_dir)/lib/libsbi.a $(firmware-bins-path-y) - $(call inst_file_list,$(install_dir)/$(plat_subdir)/firmware,$(plat_subdir)/firmware,$(firmware-elfs-path-y)) - $(call inst_file_list,$(install_dir)/$(plat_subdir)/firmware,$(plat_subdir)/firmware,$(firmware-bins-path-y)) +install_firmwares: $(build_dir)/$(platform_subdir)/lib/libplatsbi.a $(build_dir)/lib/libsbi.a $(firmware-bins-path-y) + $(call inst_file_list,$(install_dir)/$(platform_subdir)/firmware,$(platform_subdir)/firmware,$(firmware-elfs-path-y)) + $(call inst_file_list,$(install_dir)/$(platform_subdir)/firmware,$(platform_subdir)/firmware,$(firmware-bins-path-y)) # Rule for "make clean" .PHONY: clean diff --git a/README.md b/README.md index ca70e0eff46..db6c77b1946 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ For cross-compiling, please ensure that CROSS_COMPILE environment variable is set before starting build system. The libplatsbi.a and firmwares are optional and only built when -`PLAT=` parameter is specified to top-level make. -(**NOTE**: `` is sub-directory under plat/ directory) +`PLATFORM=` parameter is specified to top-level make. +(**NOTE**: `` is sub-directory under platform/ directory) To build and install Generic OpenSBI library do the following: @@ -50,17 +50,17 @@ To build and install platform specific OpenSBI library and firmwares do the following: 1. Build **libsbi, libplatsbi, and firmwares**: -`make PLAT=` +`make PLATFORM=` OR -`make PLAT= O=` +`make PLATFORM= O=` 2. Install **libsbi, headers, libplatsbi, and firmwares**: -`make PLAT= install` +`make PLATFORM= install` OR -`make PLAT= I= install` +`make PLATFORM= I= install` In addition, we can also specify platform specific command-line options to top-level make (such as `PLAT_` or `FW_`) -which are described under `docs/plat/.md` OR +which are described under `docs/platform/.md` OR `docs/firmware/.md`. Documentation @@ -71,7 +71,7 @@ manner: * `docs/platform_guide.md` - Guidelines for adding new platform support * `docs/library_usage.md` - Guidelines for using static library -* `docs/plat/.md` - Documentation for `` platform +* `docs/platform/.md` - Documentation for `` platform * `docs/firmware/.md` - Documentation for firmware `` We also prefer source level documentation, so wherever possible we describe diff --git a/plat/common/fdt.c b/platform/common/fdt.c similarity index 100% rename from plat/common/fdt.c rename to platform/common/fdt.c diff --git a/plat/common/include/plat/fdt.h b/platform/common/include/plat/fdt.h similarity index 100% rename from plat/common/include/plat/fdt.h rename to platform/common/include/plat/fdt.h diff --git a/plat/common/include/plat/irqchip/plic.h b/platform/common/include/plat/irqchip/plic.h similarity index 100% rename from plat/common/include/plat/irqchip/plic.h rename to platform/common/include/plat/irqchip/plic.h diff --git a/plat/common/include/plat/serial/sifive-uart.h b/platform/common/include/plat/serial/sifive-uart.h similarity index 100% rename from plat/common/include/plat/serial/sifive-uart.h rename to platform/common/include/plat/serial/sifive-uart.h diff --git a/plat/common/include/plat/serial/uart8250.h b/platform/common/include/plat/serial/uart8250.h similarity index 100% rename from plat/common/include/plat/serial/uart8250.h rename to platform/common/include/plat/serial/uart8250.h diff --git a/plat/common/include/plat/sys/clint.h b/platform/common/include/plat/sys/clint.h similarity index 100% rename from plat/common/include/plat/sys/clint.h rename to platform/common/include/plat/sys/clint.h diff --git a/plat/common/sys/objects.mk b/platform/common/irqchip/objects.mk similarity index 71% rename from plat/common/sys/objects.mk rename to platform/common/irqchip/objects.mk index 451adbb722d..84fffa604cb 100644 --- a/plat/common/sys/objects.mk +++ b/platform/common/irqchip/objects.mk @@ -7,4 +7,4 @@ # SPDX-License-Identifier: BSD-2-Clause # -plat-common-objs-$(PLAT_SYS_CLINT) += sys/clint.o +platform-common-objs-$(PLATFORM_IRQCHIP_PLIC) += irqchip/plic.o diff --git a/plat/common/irqchip/plic.c b/platform/common/irqchip/plic.c similarity index 100% rename from plat/common/irqchip/plic.c rename to platform/common/irqchip/plic.c diff --git a/plat/qemu/virt/objects.mk b/platform/common/objects.mk similarity index 83% rename from plat/qemu/virt/objects.mk rename to platform/common/objects.mk index 03ee2fe5f07..712e9508338 100644 --- a/plat/qemu/virt/objects.mk +++ b/platform/common/objects.mk @@ -7,4 +7,4 @@ # SPDX-License-Identifier: BSD-2-Clause # -plat-objs-y += platform.o +platform-common-objs-y += fdt.o diff --git a/plat/common/serial/objects.mk b/platform/common/serial/objects.mk similarity index 52% rename from plat/common/serial/objects.mk rename to platform/common/serial/objects.mk index 61d5d377e66..cb6062db906 100644 --- a/plat/common/serial/objects.mk +++ b/platform/common/serial/objects.mk @@ -7,5 +7,5 @@ # SPDX-License-Identifier: BSD-2-Clause # -plat-common-objs-$(PLAT_SERIAL_UART8250) += serial/uart8250.o -plat-common-objs-$(PLAT_SERIAL_SIFIVE_UART) += serial/sifive-uart.o +platform-common-objs-$(PLATFORM_SERIAL_UART8250) += serial/uart8250.o +platform-common-objs-$(PLATFORM_SERIAL_SIFIVE_UART) += serial/sifive-uart.o diff --git a/plat/common/serial/sifive-uart.c b/platform/common/serial/sifive-uart.c similarity index 100% rename from plat/common/serial/sifive-uart.c rename to platform/common/serial/sifive-uart.c diff --git a/plat/common/serial/uart8250.c b/platform/common/serial/uart8250.c similarity index 100% rename from plat/common/serial/uart8250.c rename to platform/common/serial/uart8250.c diff --git a/plat/common/sys/clint.c b/platform/common/sys/clint.c similarity index 100% rename from plat/common/sys/clint.c rename to platform/common/sys/clint.c diff --git a/plat/common/irqchip/objects.mk b/platform/common/sys/objects.mk similarity index 73% rename from plat/common/irqchip/objects.mk rename to platform/common/sys/objects.mk index 3950734f25b..183d8db6541 100644 --- a/plat/common/irqchip/objects.mk +++ b/platform/common/sys/objects.mk @@ -7,4 +7,4 @@ # SPDX-License-Identifier: BSD-2-Clause # -plat-common-objs-$(PLAT_IRQCHIP_PLIC) += irqchip/plic.o +platform-common-objs-$(PLATFORM_SYS_CLINT) += sys/clint.o diff --git a/plat/kendryte/k210/config.mk b/platform/kendryte/k210/config.mk similarity index 52% rename from plat/kendryte/k210/config.mk rename to platform/kendryte/k210/config.mk index 07cbf84f937..e0e0247bd79 100644 --- a/plat/kendryte/k210/config.mk +++ b/platform/kendryte/k210/config.mk @@ -8,18 +8,18 @@ # # Essential defines required by SBI platform -plat-cppflags-y = -DPLAT_NAME="Kendryte K210" -plat-cppflags-y+= -DPLAT_HART_COUNT=2 -plat-cppflags-y+= -DPLAT_HART_STACK_SIZE=8192 +platform-cppflags-y = -DPLAT_NAME="Kendryte K210" +platform-cppflags-y+= -DPLAT_HART_COUNT=2 +platform-cppflags-y+= -DPLAT_HART_STACK_SIZE=8192 # Compiler flags -plat-cflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany -plat-asflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany -plat-ldflags-y = +platform-cflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany +platform-asflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany +platform-ldflags-y = # Common drivers to enable -PLAT_IRQCHIP_PLIC=y -PLAT_SYS_CLINT=y +PLATFORM_IRQCHIP_PLIC=y +PLATFORM_SYS_CLINT=y # Blobs to build FW_TEXT_START=0x80000000 diff --git a/plat/kendryte/k210/objects.mk b/platform/kendryte/k210/objects.mk similarity index 77% rename from plat/kendryte/k210/objects.mk rename to platform/kendryte/k210/objects.mk index c2103f05059..3e16abe63a8 100644 --- a/plat/kendryte/k210/objects.mk +++ b/platform/kendryte/k210/objects.mk @@ -7,4 +7,4 @@ # SPDX-License-Identifier: BSD-2-Clause # -plat-objs-y += uarths.o sysctl.o platform.o +platform-objs-y += uarths.o sysctl.o platform.o diff --git a/plat/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c similarity index 100% rename from plat/kendryte/k210/platform.c rename to platform/kendryte/k210/platform.c diff --git a/plat/kendryte/k210/platform.h b/platform/kendryte/k210/platform.h similarity index 100% rename from plat/kendryte/k210/platform.h rename to platform/kendryte/k210/platform.h diff --git a/plat/kendryte/k210/sysctl.c b/platform/kendryte/k210/sysctl.c similarity index 100% rename from plat/kendryte/k210/sysctl.c rename to platform/kendryte/k210/sysctl.c diff --git a/plat/kendryte/k210/sysctl.h b/platform/kendryte/k210/sysctl.h similarity index 100% rename from plat/kendryte/k210/sysctl.h rename to platform/kendryte/k210/sysctl.h diff --git a/plat/kendryte/k210/uarths.c b/platform/kendryte/k210/uarths.c similarity index 100% rename from plat/kendryte/k210/uarths.c rename to platform/kendryte/k210/uarths.c diff --git a/plat/kendryte/k210/uarths.h b/platform/kendryte/k210/uarths.h similarity index 100% rename from plat/kendryte/k210/uarths.h rename to platform/kendryte/k210/uarths.h diff --git a/plat/sifive/hifive_u540/config.mk b/platform/qemu/sifive_u/config.mk similarity index 53% rename from plat/sifive/hifive_u540/config.mk rename to platform/qemu/sifive_u/config.mk index 165c80a4e61..d4470cd0ad5 100644 --- a/plat/sifive/hifive_u540/config.mk +++ b/platform/qemu/sifive_u/config.mk @@ -8,19 +8,19 @@ # # Essential defines required by SBI platform -plat-cppflags-y = -DPLAT_NAME="SiFive HiFive U540" -plat-cppflags-y+= -DPLAT_HART_COUNT=5 -plat-cppflags-y+= -DPLAT_HART_STACK_SIZE=8192 +platform-cppflags-y = -DPLAT_NAME="QEMU SiFive Unleashed" +platform-cppflags-y+= -DPLAT_HART_COUNT=1 +platform-cppflags-y+= -DPLAT_HART_STACK_SIZE=8192 # Compiler flags -plat-cflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany -plat-asflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany -plat-ldflags-y = +platform-cflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany +platform-asflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany +platform-ldflags-y = # Common drivers to enable -PLAT_IRQCHIP_PLIC=y -PLAT_SERIAL_SIFIVE_UART=y -PLAT_SYS_CLINT=y +PLATFORM_IRQCHIP_PLIC=y +PLATFORM_SERIAL_SIFIVE_UART=y +PLATFORM_SYS_CLINT=y # Blobs to build FW_TEXT_START=0x80000000 diff --git a/plat/qemu/sifive_u/objects.mk b/platform/qemu/sifive_u/objects.mk similarity index 84% rename from plat/qemu/sifive_u/objects.mk rename to platform/qemu/sifive_u/objects.mk index 03ee2fe5f07..7e96bad0cef 100644 --- a/plat/qemu/sifive_u/objects.mk +++ b/platform/qemu/sifive_u/objects.mk @@ -7,4 +7,4 @@ # SPDX-License-Identifier: BSD-2-Clause # -plat-objs-y += platform.o +platform-objs-y += platform.o diff --git a/plat/qemu/sifive_u/platform.c b/platform/qemu/sifive_u/platform.c similarity index 100% rename from plat/qemu/sifive_u/platform.c rename to platform/qemu/sifive_u/platform.c diff --git a/plat/qemu/sifive_u/config.mk b/platform/qemu/virt/config.mk similarity index 53% rename from plat/qemu/sifive_u/config.mk rename to platform/qemu/virt/config.mk index 97a08f511d4..8496e2d4804 100644 --- a/plat/qemu/sifive_u/config.mk +++ b/platform/qemu/virt/config.mk @@ -8,19 +8,19 @@ # # Essential defines required by SBI platform -plat-cppflags-y = -DPLAT_NAME="QEMU SiFive Unleashed" -plat-cppflags-y+= -DPLAT_HART_COUNT=1 -plat-cppflags-y+= -DPLAT_HART_STACK_SIZE=8192 +platform-cppflags-y = -DPLAT_NAME="QEMU Virt Machine" +platform-cppflags-y+= -DPLAT_HART_COUNT=8 +platform-cppflags-y+= -DPLAT_HART_STACK_SIZE=8192 # Compiler flags -plat-cflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany -plat-asflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany -plat-ldflags-y = +platform-cflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany +platform-asflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany +platform-ldflags-y = # Common drivers to enable -PLAT_IRQCHIP_PLIC=y -PLAT_SERIAL_SIFIVE_UART=y -PLAT_SYS_CLINT=y +PLATFORM_IRQCHIP_PLIC=y +PLATFORM_SERIAL_UART8250=y +PLATFORM_SYS_CLINT=y # Blobs to build FW_TEXT_START=0x80000000 diff --git a/plat/common/objects.mk b/platform/qemu/virt/objects.mk similarity index 84% rename from plat/common/objects.mk rename to platform/qemu/virt/objects.mk index 18fcd0c4718..7e96bad0cef 100644 --- a/plat/common/objects.mk +++ b/platform/qemu/virt/objects.mk @@ -7,4 +7,4 @@ # SPDX-License-Identifier: BSD-2-Clause # -plat-common-objs-y += fdt.o +platform-objs-y += platform.o diff --git a/plat/qemu/virt/platform.c b/platform/qemu/virt/platform.c similarity index 100% rename from plat/qemu/virt/platform.c rename to platform/qemu/virt/platform.c diff --git a/plat/qemu/virt/config.mk b/platform/sifive/hifive_u540/config.mk similarity index 53% rename from plat/qemu/virt/config.mk rename to platform/sifive/hifive_u540/config.mk index 0b10613006c..f411fa9a180 100644 --- a/plat/qemu/virt/config.mk +++ b/platform/sifive/hifive_u540/config.mk @@ -8,19 +8,19 @@ # # Essential defines required by SBI platform -plat-cppflags-y = -DPLAT_NAME="QEMU Virt Machine" -plat-cppflags-y+= -DPLAT_HART_COUNT=8 -plat-cppflags-y+= -DPLAT_HART_STACK_SIZE=8192 +platform-cppflags-y = -DPLAT_NAME="SiFive HiFive U540" +platform-cppflags-y+= -DPLAT_HART_COUNT=5 +platform-cppflags-y+= -DPLAT_HART_STACK_SIZE=8192 # Compiler flags -plat-cflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany -plat-asflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany -plat-ldflags-y = +platform-cflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany +platform-asflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany +platform-ldflags-y = # Common drivers to enable -PLAT_IRQCHIP_PLIC=y -PLAT_SERIAL_UART8250=y -PLAT_SYS_CLINT=y +PLATFORM_IRQCHIP_PLIC=y +PLATFORM_SERIAL_SIFIVE_UART=y +PLATFORM_SYS_CLINT=y # Blobs to build FW_TEXT_START=0x80000000 diff --git a/plat/sifive/hifive_u540/objects.mk b/platform/sifive/hifive_u540/objects.mk similarity index 84% rename from plat/sifive/hifive_u540/objects.mk rename to platform/sifive/hifive_u540/objects.mk index 03ee2fe5f07..7e96bad0cef 100644 --- a/plat/sifive/hifive_u540/objects.mk +++ b/platform/sifive/hifive_u540/objects.mk @@ -7,4 +7,4 @@ # SPDX-License-Identifier: BSD-2-Clause # -plat-objs-y += platform.o +platform-objs-y += platform.o diff --git a/plat/sifive/hifive_u540/platform.c b/platform/sifive/hifive_u540/platform.c similarity index 100% rename from plat/sifive/hifive_u540/platform.c rename to platform/sifive/hifive_u540/platform.c From f003787455709a1a6c69c1b6ab6a02d4d767c325 Mon Sep 17 00:00:00 2001 From: Atish Patra Date: Fri, 21 Dec 2018 11:06:20 +0530 Subject: [PATCH 0007/1765] lib: Hang in sbi_hart_boot_next() if next mode is not supported We should not jump to next stage if next mode (S-mode or U-mode) is not supported by HART. Signed-off-by: Atish Patra Signed-off-by: Anup Patel --- lib/sbi_hart.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/sbi_hart.c b/lib/sbi_hart.c index 5b26aead51b..a375ecf663a 100644 --- a/lib/sbi_hart.c +++ b/lib/sbi_hart.c @@ -203,6 +203,10 @@ void __attribute__((noreturn)) sbi_hart_boot_next(unsigned long arg0, if (next_mode != PRV_S && next_mode != PRV_M && next_mode != PRV_U) sbi_hart_hang(); + if (next_mode == PRV_S && !misa_extension('S')) + sbi_hart_hang(); + if (next_mode == PRV_U && !misa_extension('U')) + sbi_hart_hang(); val = csr_read(mstatus); val = INSERT_FIELD(val, MSTATUS_MPP, next_mode); From aa68f0252f2a0749dee35bda309c397f79ae26a0 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Fri, 21 Dec 2018 09:13:37 +0900 Subject: [PATCH 0008/1765] Refine platform features control Allow a platform to report its supported features in more details. The new features defined are: * SBI_PLATFORM_HAS_PMP * SBI_PLATFORM_HAS_SCOUNTEREN * SBI_PLATFORM_HAS_MCOUNTEREN In addition, define the macro SBI_PLATFORM_DEFAULT_FEATURES as the set of features that are generally expected to be supported by a Linux capable platform. Operations touching the features controlled with these falgs are not executed if the platform does not set the corresponding feature flags. Signed-off-by: Damien Le Moal --- include/sbi/sbi_hart.h | 2 +- include/sbi/sbi_platform.h | 34 +++++++++++++++++--------- lib/sbi_hart.c | 27 ++++++++++++-------- lib/sbi_init.c | 2 +- platform/qemu/sifive_u/platform.c | 2 +- platform/qemu/virt/platform.c | 2 +- platform/sifive/hifive_u540/platform.c | 2 +- 7 files changed, 45 insertions(+), 26 deletions(-) diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index c77ffd23231..90161f0be69 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -16,7 +16,7 @@ struct sbi_scratch; int sbi_hart_init(struct sbi_scratch *scratch, u32 hartid); -void sbi_hart_pmp_dump(void); +void sbi_hart_pmp_dump(struct sbi_scratch *scratch); void __attribute__((noreturn)) sbi_hart_hang(void); diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 57b8e6be919..39dfb499d9a 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -13,10 +13,19 @@ #include enum sbi_platform_features { - SBI_PLATFORM_HAS_MMIO_TIMER_VALUE = (1 << 0), - SBI_PLATFORM_HAS_HART_HOTPLUG = (1 << 1), + SBI_PLATFORM_HAS_MMIO_TIMER_VALUE = (1 << 0), + SBI_PLATFORM_HAS_HART_HOTPLUG = (1 << 1), + SBI_PLATFORM_HAS_PMP = (1 << 2), + SBI_PLATFORM_HAS_SCOUNTEREN = (1 << 3), + SBI_PLATFORM_HAS_MCOUNTEREN = (1 << 4), }; +#define SBI_PLATFORM_DEFAULT_FEATURES \ + (SBI_PLATFORM_HAS_MMIO_TIMER_VALUE | \ + SBI_PLATFORM_HAS_PMP | \ + SBI_PLATFORM_HAS_SCOUNTEREN | \ + SBI_PLATFORM_HAS_MCOUNTEREN) + struct sbi_platform { char name[64]; u64 features; @@ -48,17 +57,20 @@ struct sbi_platform { int (*system_shutdown)(u32 type); } __attribute__((packed)); -#define sbi_platform_ptr(__s) \ -((struct sbi_platform *)((__s)->platform_addr)) - -#define sbi_platform_thishart_ptr() \ -((struct sbi_platform *)(sbi_scratch_thishart_ptr()->platform_addr)) - +#define sbi_platform_ptr(__s) \ + ((struct sbi_platform *)((__s)->platform_addr)) +#define sbi_platform_thishart_ptr() \ + ((struct sbi_platform *)(sbi_scratch_thishart_ptr()->platform_addr)) #define sbi_platform_has_mmio_timer_value(__p) \ -((__p)->features & SBI_PLATFORM_HAS_MMIO_TIMER_VALUE) - + ((__p)->features & SBI_PLATFORM_HAS_MMIO_TIMER_VALUE) #define sbi_platform_has_hart_hotplug(__p) \ -((__p)->features & SBI_PLATFORM_HAS_HART_HOTPLUG) + ((__p)->features & SBI_PLATFORM_HAS_HART_HOTPLUG) +#define sbi_platform_has_pmp(__p) \ + ((__p)->features & SBI_PLATFORM_HAS_PMP) +#define sbi_platform_has_scounteren(__p) \ + ((__p)->features & SBI_PLATFORM_HAS_SCOUNTEREN) +#define sbi_platform_has_mcounteren(__p) \ + ((__p)->features & SBI_PLATFORM_HAS_MCOUNTEREN) static inline const char *sbi_platform_name(struct sbi_platform *plat) { diff --git a/lib/sbi_hart.c b/lib/sbi_hart.c index a375ecf663a..26d435bdf97 100644 --- a/lib/sbi_hart.c +++ b/lib/sbi_hart.c @@ -17,16 +17,20 @@ #include #include -static int mstatus_init(u32 hartid) +static void mstatus_init(struct sbi_scratch *scratch, u32 hartid) { + struct sbi_platform *plat = sbi_platform_ptr(scratch); + /* Enable FPU */ if (misa_extension('D') || misa_extension('F')) csr_write(mstatus, MSTATUS_FS); /* Enable user/supervisor use of perf counters */ - if (misa_extension('S')) + if (misa_extension('S') && + sbi_platform_has_scounteren(plat)) csr_write(scounteren, -1); - csr_write(mcounteren, -1); + if (sbi_platform_has_mcounteren(plat)) + csr_write(mcounteren, -1); /* Disable all interrupts */ csr_write(mie, 0); @@ -34,8 +38,6 @@ static int mstatus_init(u32 hartid) /* Disable S-mode paging */ if (misa_extension('S')) csr_write(sptbr, 0); - - return 0; } #ifdef __riscv_flen @@ -111,10 +113,14 @@ unsigned long log2roundup(unsigned long x) return ret; } -void sbi_hart_pmp_dump(void) +void sbi_hart_pmp_dump(struct sbi_scratch *scratch) { - unsigned int i; + struct sbi_platform *plat = sbi_platform_ptr(scratch); unsigned long prot, addr, size, l2l; + unsigned int i; + + if (!sbi_platform_has_pmp(plat)) + return; for (i = 0; i < PMP_COUNT; i++) { pmp_get(i, &prot, &addr, &l2l); @@ -149,6 +155,9 @@ static int pmp_init(struct sbi_scratch *scratch, u32 hartid) ulong prot, addr, log2size; struct sbi_platform *plat = sbi_platform_ptr(scratch); + if (!sbi_platform_has_pmp(plat)) + return 0; + fw_size_log2 = log2roundup(scratch->fw_size); fw_start = scratch->fw_start & ~((1UL << fw_size_log2) - 1UL); @@ -172,9 +181,7 @@ int sbi_hart_init(struct sbi_scratch *scratch, u32 hartid) { int rc; - rc = mstatus_init(hartid); - if (rc) - return rc; + mstatus_init(scratch, hartid); rc = fp_init(hartid); if (rc) diff --git a/lib/sbi_init.c b/lib/sbi_init.c index 82384b39873..3e7bda35e6e 100644 --- a/lib/sbi_init.c +++ b/lib/sbi_init.c @@ -91,7 +91,7 @@ static void __attribute__((noreturn)) init_coldboot(struct sbi_scratch *scratch, sbi_ecall_version_major(), sbi_ecall_version_minor()); sbi_printf("\n"); - sbi_hart_pmp_dump(); + sbi_hart_pmp_dump(scratch); sbi_hart_mark_available(hartid); diff --git a/platform/qemu/sifive_u/platform.c b/platform/qemu/sifive_u/platform.c index a4a401ecba8..d9168255ec6 100644 --- a/platform/qemu/sifive_u/platform.c +++ b/platform/qemu/sifive_u/platform.c @@ -88,7 +88,7 @@ static int sifive_u_system_down(u32 type) struct sbi_platform platform = { .name = STRINGIFY(PLAT_NAME), - .features = SBI_PLATFORM_HAS_MMIO_TIMER_VALUE, + .features = SBI_PLATFORM_DEFAULT_FEATURES, .hart_count = PLAT_HART_COUNT, .hart_stack_size = PLAT_HART_STACK_SIZE, .pmp_region_count = sifive_u_pmp_region_count, diff --git a/platform/qemu/virt/platform.c b/platform/qemu/virt/platform.c index e59cdfd1360..fe91fc8f664 100644 --- a/platform/qemu/virt/platform.c +++ b/platform/qemu/virt/platform.c @@ -86,7 +86,7 @@ static int virt_system_down(u32 type) struct sbi_platform platform = { .name = STRINGIFY(PLAT_NAME), - .features = SBI_PLATFORM_HAS_MMIO_TIMER_VALUE, + .features = SBI_PLATFORM_DEFAULT_FEATURES, .hart_count = PLAT_HART_COUNT, .hart_stack_size = PLAT_HART_STACK_SIZE, .pmp_region_count = virt_pmp_region_count, diff --git a/platform/sifive/hifive_u540/platform.c b/platform/sifive/hifive_u540/platform.c index 5b1c989ffa0..46613e60073 100644 --- a/platform/sifive/hifive_u540/platform.c +++ b/platform/sifive/hifive_u540/platform.c @@ -105,7 +105,7 @@ static int sifive_u_system_down(u32 type) struct sbi_platform platform = { .name = STRINGIFY(PLAT_NAME), - .features = SBI_PLATFORM_HAS_MMIO_TIMER_VALUE, + .features = SBI_PLATFORM_DEFAULT_FEATURES; .hart_count = PLAT_HART_COUNT, .hart_stack_size = PLAT_HART_STACK_SIZE, .pmp_region_count = sifive_u_pmp_region_count, From 513474cd1b6f3481ee72ec71df916880d7bc0232 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Fri, 21 Dec 2018 10:03:56 +0900 Subject: [PATCH 0009/1765] Fix FDT relocation Or rather, disable it if FW_PAYLOAD_FDT_ADDR is not defined. This correspond to cases where the underlying FW that loaded and started opensbi did not provide any FDT. In such case, the platform code will need to prepare one. Signed-off-by: Damien Le Moal --- firmware/fw_common.S | 2 ++ 1 file changed, 2 insertions(+) diff --git a/firmware/fw_common.S b/firmware/fw_common.S index a2685cf21b2..9963fdd9539 100644 --- a/firmware/fw_common.S +++ b/firmware/fw_common.S @@ -41,6 +41,7 @@ _bss_zero: add a1, t1, zero _prev_arg1_override_done: +#ifdef FW_PAYLOAD_FDT_ADDR /* * Relocate Flatened Device Tree (FDT) * source FDT address = previous arg1 @@ -99,6 +100,7 @@ _fdt_reloc_again: add t1, t1, __SIZEOF_POINTER__ blt t1, t2, _fdt_reloc_again _fdt_reloc_done: +#endif /* Update boot hart flag */ la a4, _boot_hart_done From 8f91d1142e241d3319cdafd9810928870bc71970 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Fri, 21 Dec 2018 14:48:42 +0900 Subject: [PATCH 0010/1765] fw: Disable delegation Also disable interrupts and exceptions delegation when clearing mie and mip. Signed-off-by: Damien Le Moal --- firmware/fw_common.S | 2 ++ 1 file changed, 2 insertions(+) diff --git a/firmware/fw_common.S b/firmware/fw_common.S index 9963fdd9539..afe14a1bc81 100644 --- a/firmware/fw_common.S +++ b/firmware/fw_common.S @@ -121,6 +121,8 @@ _wait_for_boot_hart: _start_warm: /* Disable and clear all interrupts */ + csrw mideleg, zero + csrw medeleg, zero csrw mie, zero csrw mip, zero From 84df181c84921c4411eac7debce94316eb4a1132 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Fri, 21 Dec 2018 14:58:23 +0900 Subject: [PATCH 0011/1765] Add a banner Signed-off-by: Damien Le Moal --- lib/sbi_init.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/sbi_init.c b/lib/sbi_init.c index 3e7bda35e6e..72f2c19b233 100644 --- a/lib/sbi_init.c +++ b/lib/sbi_init.c @@ -17,6 +17,16 @@ #include #include +static const char *logo = + " ____ _____ ____ _____\n" + " / __ \\ / ____| _ \\_ _|\n" + " | | | |_ __ ___ _ __ | (___ | |_) || |\n" + " | | | | '_ \\ / _ \\ '_ \\ \\___ \\| _ < | |\n" + " | |__| | |_) | __/ | | |____) | |_) || |_\n" + " \\____/| .__/ \\___|_| |_|_____/|____/_____|\n" + " | |\n" + " |_|\n"; + static void __attribute__((noreturn)) init_coldboot(struct sbi_scratch *scratch, u32 hartid) { @@ -76,7 +86,10 @@ static void __attribute__((noreturn)) init_coldboot(struct sbi_scratch *scratch, sbi_printf("OpenSBI v%d.%d (%s %s)\n", OPENSBI_MAJOR, OPENSBI_MINOR, __DATE__, __TIME__); - sbi_printf("\n"); + sbi_printf("Running on Hart %u\n", hartid); + + sbi_printf("%s\n", logo); + /* Platform details */ sbi_printf("Platform Name : %s\n", sbi_platform_name(plat)); sbi_printf("Platform HART Features : RV%d%s\n", misa_xlen(), str); From 9c183df632ee91560e160d6011c7ece56ee1f9b0 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Fri, 21 Dec 2018 15:04:16 +0900 Subject: [PATCH 0012/1765] Add a hang message Make it clear that the end of the FW execution was reached without the hand being passed to any payload. Signed-off-by: Damien Le Moal --- lib/sbi_hart.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/sbi_hart.c b/lib/sbi_hart.c index 26d435bdf97..b30250b3268 100644 --- a/lib/sbi_hart.c +++ b/lib/sbi_hart.c @@ -196,6 +196,8 @@ int sbi_hart_init(struct sbi_scratch *scratch, u32 hartid) void __attribute__((noreturn)) sbi_hart_hang(void) { + sbi_printf("\nHang !!\n"); + while (1) wfi(); __builtin_unreachable(); From d403c70fb11fb55042ca3cef0dbe399ed87cc79b Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Fri, 21 Dec 2018 15:05:33 +0900 Subject: [PATCH 0013/1765] Fix interrupt and exception delegation When S mode is not supported, simply clear mideleg and medeleg. Otherwise, set delegation from M-mode to S-mode, removing the page fault exceptions as those would not happen in M-mode. Signed-off-by: Damien Le Moal --- lib/sbi_hart.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/sbi_hart.c b/lib/sbi_hart.c index b30250b3268..12c5c55ba2e 100644 --- a/lib/sbi_hart.c +++ b/lib/sbi_hart.c @@ -77,17 +77,19 @@ static int fp_init(u32 hartid) static int delegate_traps(u32 hartid) { - /* send S-mode interrupts and most exceptions straight to S-mode */ - unsigned long interrupts = MIP_SSIP | MIP_STIP | MIP_SEIP; - unsigned long exceptions = (1U << CAUSE_MISALIGNED_FETCH) | - (1U << CAUSE_FETCH_PAGE_FAULT) | - (1U << CAUSE_BREAKPOINT) | - (1U << CAUSE_LOAD_PAGE_FAULT) | - (1U << CAUSE_STORE_PAGE_FAULT) | - (1U << CAUSE_USER_ECALL); - - if (!misa_extension('S')) - return 0; + unsigned long interrupts, exceptions; + + if (!misa_extension('S')) { + /* No delegation possible */ + interrupts = 0; + exceptions = 0; + } else { + /* Send M-mode interrupts and most exceptions to S-mode */ + interrupts = MIP_SSIP | MIP_STIP | MIP_SEIP; + exceptions = (1U << CAUSE_MISALIGNED_FETCH) | + (1U << CAUSE_BREAKPOINT) | + (1U << CAUSE_USER_ECALL); + } csr_write(mideleg, interrupts); csr_write(medeleg, exceptions); From 745ae45e6570985682e8072c852e56e73219d182 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Fri, 21 Dec 2018 09:14:44 +0900 Subject: [PATCH 0014/1765] Update Kendryte k210 support Booting now. Signed-off-by: Damien Le Moal --- platform/kendryte/k210/config.mk | 6 +- platform/kendryte/k210/platform.c | 78 +- platform/kendryte/k210/platform.h | 1493 +++-------------------------- platform/kendryte/k210/sysctl.c | 7 +- platform/kendryte/k210/sysctl.h | 6 +- platform/kendryte/k210/uarths.c | 4 +- platform/kendryte/k210/uarths.h | 16 +- 7 files changed, 169 insertions(+), 1441 deletions(-) diff --git a/platform/kendryte/k210/config.mk b/platform/kendryte/k210/config.mk index e0e0247bd79..c0c36ea054b 100644 --- a/platform/kendryte/k210/config.mk +++ b/platform/kendryte/k210/config.mk @@ -10,7 +10,7 @@ # Essential defines required by SBI platform platform-cppflags-y = -DPLAT_NAME="Kendryte K210" platform-cppflags-y+= -DPLAT_HART_COUNT=2 -platform-cppflags-y+= -DPLAT_HART_STACK_SIZE=8192 +platform-cppflags-y+= -DPLAT_HART_STACK_SIZE=4096 # Compiler flags platform-cflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany @@ -25,6 +25,6 @@ PLATFORM_SYS_CLINT=y FW_TEXT_START=0x80000000 FW_JUMP=n FW_PAYLOAD=y -FW_PAYLOAD_OFFSET=0x200000 -FW_PAYLOAD_FDT_ADDR=0x80040000 +FW_PAYLOAD_OFFSET=0x10000 +#FW_PAYLOAD_FDT_ADDR=0x80040000 diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c index 6f9297ef640..03c2c2d7693 100644 --- a/platform/kendryte/k210/platform.c +++ b/platform/kendryte/k210/platform.c @@ -10,25 +10,20 @@ #include #include #include +#include #include #include #include "platform.h" #include "uarths.h" -#define K210_U_SYS_CLK 1000000000 -#define K210_U_PERIPH_CLK (K210_U_SYS_CLK / 2) - -#define K210_U_PLIC_NUM_SOURCES 0x35 -#define K210_U_PLIC_NUM_PRIORITIES 7 - -static int k210_console_init(void) +int k210_console_init(void) { uarths_init(115200, UARTHS_STOP_1); return 0; } -static void k210_console_putc(char c) +void k210_console_putc(char c) { uarths_putc(c); } @@ -38,57 +33,40 @@ static char k210_console_getc(void) return uarths_getc(); } -static u32 k210_pmp_region_count(u32 target_hart) -{ - return 1; -} - -static int k210_pmp_region_info(u32 target_hart, u32 index, - ulong *prot, ulong *addr, ulong *log2size) +static int k210_cold_irqchip_init(void) { - int ret = 0; - - switch (index) { - case 0: - *prot = PMP_R | PMP_W | PMP_X; - *addr = 0; - *log2size = __riscv_xlen; - break; - default: - ret = -1; - break; - }; - - return ret; + return plic_cold_irqchip_init(PLIC_BASE_ADDR, PLIC_NUM_SOURCES, + PLAT_HART_COUNT); } -static int k210_cold_irqchip_init(void) +static int k210_warm_irqchip_init(u32 core_id) { - return plic_cold_irqchip_init(PLIC_BASE_ADDR, - K210_U_PLIC_NUM_SOURCES, - PLAT_HART_COUNT); + return plic_warm_irqchip_init(core_id); } static int k210_cold_ipi_init(void) { - return clint_cold_ipi_init(CLINT_BASE_ADDR, - PLAT_HART_COUNT); + return clint_cold_ipi_init(CLINT_BASE_ADDR, PLAT_HART_COUNT); } static int k210_cold_timer_init(void) { - return clint_cold_timer_init(CLINT_BASE_ADDR, - PLAT_HART_COUNT); + return clint_cold_timer_init(CLINT_BASE_ADDR, PLAT_HART_COUNT); } -static int k210_cold_final_init(void) +static int k210_system_reboot(u32 type) { - return plic_fdt_fixup(sbi_scratch_thishart_arg1_ptr(), "riscv,plic0"); + /* For now nothing to do. */ + sbi_printf("System reboot\n"); + + return 0; } -static int k210_system_down(u32 type) +static int k210_system_shutdown(u32 type) { /* For now nothing to do. */ + sbi_printf("System shutdown\n"); + return 0; } @@ -100,29 +78,27 @@ struct sbi_platform platform = { .hart_count = PLAT_HART_COUNT, .hart_stack_size = PLAT_HART_STACK_SIZE, - .pmp_region_count = k210_pmp_region_count, - .pmp_region_info = k210_pmp_region_info, - - .console_init = k210_console_init, .console_putc = k210_console_putc, .console_getc = k210_console_getc, .cold_irqchip_init = k210_cold_irqchip_init, - .warm_irqchip_init = plic_warm_irqchip_init, + .warm_irqchip_init = k210_warm_irqchip_init, + + .cold_ipi_init = k210_cold_ipi_init, + .warm_ipi_init = clint_warm_ipi_init, .ipi_inject = clint_ipi_inject, .ipi_sync = clint_ipi_sync, .ipi_clear = clint_ipi_clear, - .warm_ipi_init = clint_warm_ipi_init, - .cold_ipi_init = k210_cold_ipi_init, - .cold_final_init = k210_cold_final_init, + .cold_timer_init = k210_cold_timer_init, .timer_value = clint_timer_value, .timer_event_stop = clint_timer_event_stop, .timer_event_start = clint_timer_event_start, .warm_timer_init = clint_warm_timer_init, - .cold_timer_init = k210_cold_timer_init, - .system_reboot = k210_system_down, - .system_shutdown = k210_system_down + .cold_final_init = NULL, + + .system_reboot = k210_system_reboot, + .system_shutdown = k210_system_shutdown }; diff --git a/platform/kendryte/k210/platform.h b/platform/kendryte/k210/platform.h index 4aa15d76b10..14a4bbdfba4 100644 --- a/platform/kendryte/k210/platform.h +++ b/platform/kendryte/k210/platform.h @@ -19,69 +19,69 @@ /* Register base address */ /* Under Coreplex */ -#define CLINT_BASE_ADDR (0x02000000U) -#define PLIC_BASE_ADDR (0x0C000000U) +#define CLINT_BASE_ADDR (0x02000000U) +#define PLIC_BASE_ADDR (0x0C000000U) +#define PLIC_NUM_CORES (PLAT_HART_COUNT) /* Under TileLink */ -#define UARTHS_BASE_ADDR (0x38000000U) -#define GPIOHS_BASE_ADDR (0x38001000U) +#define GPIOHS_BASE_ADDR (0x38001000U) /* Under AXI 64 bit */ -#define RAM_BASE_ADDR (0x80000000U) -#define RAM_SIZE (6 * 1024 * 1024U) +#define RAM_BASE_ADDR (0x80000000U) +#define RAM_SIZE (6 * 1024 * 1024U) -#define IO_BASE_ADDR (0x40000000U) -#define IO_SIZE (6 * 1024 * 1024U) +#define IO_BASE_ADDR (0x40000000U) +#define IO_SIZE (6 * 1024 * 1024U) -#define AI_RAM_BASE_ADDR (0x80600000U) -#define AI_RAM_SIZE (2 * 1024 * 1024U) +#define AI_RAM_BASE_ADDR (0x80600000U) +#define AI_RAM_SIZE (2 * 1024 * 1024U) -#define AI_IO_BASE_ADDR (0x40600000U) -#define AI_IO_SIZE (2 * 1024 * 1024U) +#define AI_IO_BASE_ADDR (0x40600000U) +#define AI_IO_SIZE (2 * 1024 * 1024U) -#define AI_BASE_ADDR (0x40800000U) -#define AI_SIZE (12 * 1024 * 1024U) +#define AI_BASE_ADDR (0x40800000U) +#define AI_SIZE (12 * 1024 * 1024U) -#define FFT_BASE_ADDR (0x42000000U) -#define FFT_SIZE (4 * 1024 * 1024U) +#define FFT_BASE_ADDR (0x42000000U) +#define FFT_SIZE (4 * 1024 * 1024U) -#define ROM_BASE_ADDR (0x88000000U) -#define ROM_SIZE (128 * 1024U) +#define ROM_BASE_ADDR (0x88000000U) +#define ROM_SIZE (128 * 1024U) /* Under AHB 32 bit */ -#define DMAC_BASE_ADDR (0x50000000U) +#define DMAC_BASE_ADDR (0x50000000U) /* Under APB1 32 bit */ -#define GPIO_BASE_ADDR (0x50200000U) -#define UART1_BASE_ADDR (0x50210000U) -#define UART2_BASE_ADDR (0x50220000U) -#define UART3_BASE_ADDR (0x50230000U) -#define SPI_SLAVE_BASE_ADDR (0x50240000U) -#define I2S0_BASE_ADDR (0x50250000U) -#define I2S1_BASE_ADDR (0x50260000U) -#define I2S2_BASE_ADDR (0x50270000U) -#define I2C0_BASE_ADDR (0x50280000U) -#define I2C1_BASE_ADDR (0x50290000U) -#define I2C2_BASE_ADDR (0x502A0000U) -#define FPIOA_BASE_ADDR (0x502B0000U) -#define SHA256_BASE_ADDR (0x502C0000U) -#define TIMER0_BASE_ADDR (0x502D0000U) -#define TIMER1_BASE_ADDR (0x502E0000U) -#define TIMER2_BASE_ADDR (0x502F0000U) +#define GPIO_BASE_ADDR (0x50200000U) +#define UART1_BASE_ADDR (0x50210000U) +#define UART2_BASE_ADDR (0x50220000U) +#define UART3_BASE_ADDR (0x50230000U) +#define SPI_SLAVE_BASE_ADDR (0x50240000U) +#define I2S0_BASE_ADDR (0x50250000U) +#define I2S1_BASE_ADDR (0x50260000U) +#define I2S2_BASE_ADDR (0x50270000U) +#define I2C0_BASE_ADDR (0x50280000U) +#define I2C1_BASE_ADDR (0x50290000U) +#define I2C2_BASE_ADDR (0x502A0000U) +#define FPIOA_BASE_ADDR (0x502B0000U) +#define SHA256_BASE_ADDR (0x502C0000U) +#define TIMER0_BASE_ADDR (0x502D0000U) +#define TIMER1_BASE_ADDR (0x502E0000U) +#define TIMER2_BASE_ADDR (0x502F0000U) /* Under APB2 32 bit */ -#define WDT0_BASE_ADDR (0x50400000U) -#define WDT1_BASE_ADDR (0x50410000U) -#define OTP_BASE_ADDR (0x50420000U) -#define DVP_BASE_ADDR (0x50430000U) -#define SYSCTL_BASE_ADDR (0x50440000U) -#define AES_BASE_ADDR (0x50450000U) -#define RTC_BASE_ADDR (0x50460000U) +#define WDT0_BASE_ADDR (0x50400000U) +#define WDT1_BASE_ADDR (0x50410000U) +#define OTP_BASE_ADDR (0x50420000U) +#define DVP_BASE_ADDR (0x50430000U) +#define SYSCTL_BASE_ADDR (0x50440000U) +#define AES_BASE_ADDR (0x50450000U) +#define RTC_BASE_ADDR (0x50460000U) /* Under APB3 32 bit */ -#define SPI0_BASE_ADDR (0x52000000U) -#define SPI1_BASE_ADDR (0x53000000U) -#define SPI3_BASE_ADDR (0x54000000U) +#define SPI0_BASE_ADDR (0x52000000U) +#define SPI1_BASE_ADDR (0x53000000U) +#define SPI3_BASE_ADDR (0x54000000U) #define read_csr(reg) ({ unsigned long __tmp; \ asm volatile ("csrr %0, " #reg : "=r"(__tmp)); \ @@ -118,1331 +118,82 @@ #define read_cycle() read_csr(mcycle) #define current_coreid() read_csr(mhartid) -#endif /* _PLATFORM_H_ */ - - - - - - - - -#if 0 - -/* From Kendryte SDK encoding.h file */ - -#ifndef RISCV_CSR_ENCODING_H -#define RISCV_CSR_ENCODING_H - -#define MSTATUS_UIE 0x00000001U -#define MSTATUS_SIE 0x00000002U -#define MSTATUS_HIE 0x00000004U -#define MSTATUS_MIE 0x00000008U -#define MSTATUS_UPIE 0x00000010U -#define MSTATUS_SPIE 0x00000020U -#define MSTATUS_HPIE 0x00000040U -#define MSTATUS_MPIE 0x00000080U -#define MSTATUS_SPP 0x00000100U -#define MSTATUS_HPP 0x00000600U -#define MSTATUS_MPP 0x00001800U -#define MSTATUS_FS 0x00006000U -#define MSTATUS_XS 0x00018000U -#define MSTATUS_MPRV 0x00020000U -#define MSTATUS_PUM 0x00040000U -#define MSTATUS_MXR 0x00080000U -#define MSTATUS_VM 0x1F000000U -#define MSTATUS32_SD 0x80000000U -#define MSTATUS64_SD 0x8000000000000000U - -#define SSTATUS_UIE 0x00000001U -#define SSTATUS_SIE 0x00000002U -#define SSTATUS_UPIE 0x00000010U -#define SSTATUS_SPIE 0x00000020U -#define SSTATUS_SPP 0x00000100U -#define SSTATUS_FS 0x00006000U -#define SSTATUS_XS 0x00018000U -#define SSTATUS_PUM 0x00040000U -#define SSTATUS32_SD 0x80000000U -#define SSTATUS64_SD 0x8000000000000000U - -#define DCSR_XDEBUGVER (3U<<30) -#define DCSR_NDRESET (1U<<29) -#define DCSR_FULLRESET (1U<<28) -#define DCSR_EBREAKM (1U<<15) -#define DCSR_EBREAKH (1U<<14) -#define DCSR_EBREAKS (1U<<13) -#define DCSR_EBREAKU (1U<<12) -#define DCSR_STOPCYCLE (1U<<10) -#define DCSR_STOPTIME (1U<<9) -#define DCSR_CAUSE (7U<<6) -#define DCSR_DEBUGINT (1U<<5) -#define DCSR_HALT (1U<<3) -#define DCSR_STEP (1U<<2) -#define DCSR_PRV (3U<<0) - -#define DCSR_CAUSE_NONE 0 -#define DCSR_CAUSE_SWBP 1 -#define DCSR_CAUSE_HWBP 2 -#define DCSR_CAUSE_DEBUGINT 3 -#define DCSR_CAUSE_STEP 4 -#define DCSR_CAUSE_HALT 5 - -#define MCONTROL_SELECT (1U<<19) -#define MCONTROL_TIMING (1U<<18) -#define MCONTROL_ACTION (0x3fU<<12) -#define MCONTROL_CHAIN (1U<<11) -#define MCONTROL_MATCH (0xfU<<7) -#define MCONTROL_M (1U<<6) -#define MCONTROL_H (1U<<5) -#define MCONTROL_S (1U<<4) -#define MCONTROL_U (1U<<3) -#define MCONTROL_EXECUTE (1U<<2) -#define MCONTROL_STORE (1U<<1) -#define MCONTROL_LOAD (1U<<0) - -#define MCONTROL_TYPE_NONE 0 -#define MCONTROL_TYPE_MATCH 2 - -#define MCONTROL_ACTION_DEBUG_EXCEPTION 0 -#define MCONTROL_ACTION_DEBUG_MODE 1 -#define MCONTROL_ACTION_TRACE_START 2 -#define MCONTROL_ACTION_TRACE_STOP 3 -#define MCONTROL_ACTION_TRACE_EMIT 4 - -#define MCONTROL_MATCH_EQUAL 0 -#define MCONTROL_MATCH_NAPOT 1 -#define MCONTROL_MATCH_GE 2 -#define MCONTROL_MATCH_LT 3 -#define MCONTROL_MATCH_MASK_LOW 4 -#define MCONTROL_MATCH_MASK_HIGH 5 - -#define MIP_SSIP (1U << IRQ_S_SOFT) -#define MIP_HSIP (1U << IRQ_H_SOFT) -#define MIP_MSIP (1U << IRQ_M_SOFT) -#define MIP_STIP (1U << IRQ_S_TIMER) -#define MIP_HTIP (1U << IRQ_H_TIMER) -#define MIP_MTIP (1U << IRQ_M_TIMER) -#define MIP_SEIP (1U << IRQ_S_EXT) -#define MIP_HEIP (1U << IRQ_H_EXT) -#define MIP_MEIP (1U << IRQ_M_EXT) - -#define SIP_SSIP MIP_SSIP -#define SIP_STIP MIP_STIP - -#define PRV_U 0 -#define PRV_S 1 -#define PRV_H 2 -#define PRV_M 3 - -#define VM_MBARE 0 -#define VM_MBB 1 -#define VM_MBBID 2 -#define VM_SV32 8 -#define VM_SV39 9 -#define VM_SV48 10 - -#define IRQ_S_SOFT 1 -#define IRQ_H_SOFT 2 -#define IRQ_M_SOFT 3 -#define IRQ_S_TIMER 5 -#define IRQ_H_TIMER 6 -#define IRQ_M_TIMER 7 -#define IRQ_S_EXT 9 -#define IRQ_H_EXT 10 -#define IRQ_M_EXT 11 -#define IRQ_COP 12 -#define IRQ_HOST 13 - -#define DEFAULT_RSTVEC 0x00001000U -#define DEFAULT_NMIVEC 0x00001004U -#define DEFAULT_MTVEC 0x00001010U -#define CONFIG_STRING_ADDR 0x0000100CU -#define EXT_IO_BASE 0x40000000U -#define DRAM_BASE 0x80000000U - -/* page table entry (PTE) fields */ -#define PTE_V 0x001U /* Valid */ -#define PTE_R 0x002U /* Read */ -#define PTE_W 0x004U /* Write */ -#define PTE_X 0x008U /* Execute */ -#define PTE_U 0x010U /* User */ -#define PTE_G 0x020U /* Global */ -#define PTE_A 0x040U /* Accessed */ -#define PTE_D 0x080U /* Dirty */ -#define PTE_SOFT 0x300U /* Reserved for Software */ - -#define PTE_PPN_SHIFT 10 - -#define MCONTROL_TYPE(xlen) (0xfULL<<((xlen)-4)) -#define MCONTROL_DMODE(xlen) (1ULL<<((xlen)-5)) -#define MCONTROL_MASKMAX(xlen) (0x3fULL<<((xlen)-11)) - -#define PTE_TABLE(PTE) (((PTE) & (PTE_V | PTE_R | PTE_W | PTE_X)) == PTE_V) - -#if defined(__riscv) - -#if defined(__riscv64) -# define MSTATUS_SD MSTATUS64_SD -# define SSTATUS_SD SSTATUS64_SD -# define RISCV_PGLEVEL_BITS 9 -#else -# define MSTATUS_SD MSTATUS32_SD -# define SSTATUS_SD SSTATUS32_SD -# define RISCV_PGLEVEL_BITS 10 -#endif - -#define RISCV_PGSHIFT 12 -#define RISCV_PGSIZE (1 << RISCV_PGSHIFT) - -#ifndef __ASSEMBLER__ - -#if defined(__GNUC__) - -#define read_csr(reg) ({ unsigned long __tmp; \ - asm volatile ("csrr %0, " #reg : "=r"(__tmp)); \ - __tmp; }) - -#define write_csr(reg, val) ({ \ - if (__builtin_constant_p(val) && (unsigned long)(val) < 32) \ - asm volatile ("csrw " #reg ", %0" :: "i"(val)); \ - else \ - asm volatile ("csrw " #reg ", %0" :: "r"(val)); }) - -#define swap_csr(reg, val) ({ unsigned long __tmp; \ - if (__builtin_constant_p(val) && (unsigned long)(val) < 32) \ - asm volatile ("csrrw %0, " #reg ", %1" : "=r"(__tmp) : "i"(val)); \ - else \ - asm volatile ("csrrw %0, " #reg ", %1" : "=r"(__tmp) : "r"(val)); \ - __tmp; }) - -#define set_csr(reg, bit) ({ unsigned long __tmp; \ - if (__builtin_constant_p(bit) && (unsigned long)(bit) < 32) \ - asm volatile ("csrrs %0, " #reg ", %1" : "=r"(__tmp) : "i"(bit)); \ - else \ - asm volatile ("csrrs %0, " #reg ", %1" : "=r"(__tmp) : "r"(bit)); \ - __tmp; }) - -#define clear_csr(reg, bit) ({ unsigned long __tmp; \ - if (__builtin_constant_p(bit) && (unsigned long)(bit) < 32) \ - asm volatile ("csrrc %0, " #reg ", %1" : "=r"(__tmp) : "i"(bit)); \ - else \ - asm volatile ("csrrc %0, " #reg ", %1" : "=r"(__tmp) : "r"(bit)); \ - __tmp; }) - -#define read_time() read_csr(mtime) -#define read_cycle() read_csr(mcycle) -#define current_coreid() read_csr(mhartid) - -#endif - -#endif - -#endif - -#endif - -#ifndef RISCV_ENCODING_H -#define RISCV_ENCODING_H -#define MATCH_BEQ 0x63U -#define MASK_BEQ 0x707fU -#define MATCH_BNE 0x1063U -#define MASK_BNE 0x707fU -#define MATCH_BLT 0x4063U -#define MASK_BLT 0x707fU -#define MATCH_BGE 0x5063U -#define MASK_BGE 0x707fU -#define MATCH_BLTU 0x6063U -#define MASK_BLTU 0x707fU -#define MATCH_BGEU 0x7063U -#define MASK_BGEU 0x707fU -#define MATCH_JALR 0x67U -#define MASK_JALR 0x707fU -#define MATCH_JAL 0x6fU -#define MASK_JAL 0x7fU -#define MATCH_LUI 0x37U -#define MASK_LUI 0x7fU -#define MATCH_AUIPC 0x17U -#define MASK_AUIPC 0x7fU -#define MATCH_ADDI 0x13U -#define MASK_ADDI 0x707fU -#define MATCH_SLLI 0x1013U -#define MASK_SLLI 0xfc00707fU -#define MATCH_SLTI 0x2013U -#define MASK_SLTI 0x707fU -#define MATCH_SLTIU 0x3013U -#define MASK_SLTIU 0x707fU -#define MATCH_XORI 0x4013U -#define MASK_XORI 0x707fU -#define MATCH_SRLI 0x5013U -#define MASK_SRLI 0xfc00707fU -#define MATCH_SRAI 0x40005013U -#define MASK_SRAI 0xfc00707fU -#define MATCH_ORI 0x6013U -#define MASK_ORI 0x707fU -#define MATCH_ANDI 0x7013U -#define MASK_ANDI 0x707fU -#define MATCH_ADD 0x33U -#define MASK_ADD 0xfe00707fU -#define MATCH_SUB 0x40000033U -#define MASK_SUB 0xfe00707fU -#define MATCH_SLL 0x1033U -#define MASK_SLL 0xfe00707fU -#define MATCH_SLT 0x2033U -#define MASK_SLT 0xfe00707fU -#define MATCH_SLTU 0x3033U -#define MASK_SLTU 0xfe00707fU -#define MATCH_XOR 0x4033U -#define MASK_XOR 0xfe00707fU -#define MATCH_SRL 0x5033U -#define MASK_SRL 0xfe00707fU -#define MATCH_SRA 0x40005033U -#define MASK_SRA 0xfe00707fU -#define MATCH_OR 0x6033U -#define MASK_OR 0xfe00707fU -#define MATCH_AND 0x7033U -#define MASK_AND 0xfe00707fU -#define MATCH_ADDIW 0x1bU -#define MASK_ADDIW 0x707fU -#define MATCH_SLLIW 0x101bU -#define MASK_SLLIW 0xfe00707fU -#define MATCH_SRLIW 0x501bU -#define MASK_SRLIW 0xfe00707fU -#define MATCH_SRAIW 0x4000501bU -#define MASK_SRAIW 0xfe00707fU -#define MATCH_ADDW 0x3bU -#define MASK_ADDW 0xfe00707fU -#define MATCH_SUBW 0x4000003bU -#define MASK_SUBW 0xfe00707fU -#define MATCH_SLLW 0x103bU -#define MASK_SLLW 0xfe00707fU -#define MATCH_SRLW 0x503bU -#define MASK_SRLW 0xfe00707fU -#define MATCH_SRAW 0x4000503bU -#define MASK_SRAW 0xfe00707fU -#define MATCH_LB 0x3U -#define MASK_LB 0x707fU -#define MATCH_LH 0x1003U -#define MASK_LH 0x707fU -#define MATCH_LW 0x2003U -#define MASK_LW 0x707fU -#define MATCH_LD 0x3003U -#define MASK_LD 0x707fU -#define MATCH_LBU 0x4003U -#define MASK_LBU 0x707fU -#define MATCH_LHU 0x5003U -#define MASK_LHU 0x707fU -#define MATCH_LWU 0x6003U -#define MASK_LWU 0x707fU -#define MATCH_SB 0x23U -#define MASK_SB 0x707fU -#define MATCH_SH 0x1023U -#define MASK_SH 0x707fU -#define MATCH_SW 0x2023U -#define MASK_SW 0x707fU -#define MATCH_SD 0x3023U -#define MASK_SD 0x707fU -#define MATCH_FENCE 0xfU -#define MASK_FENCE 0x707fU -#define MATCH_FENCE_I 0x100fU -#define MASK_FENCE_I 0x707fU -#define MATCH_MUL 0x2000033U -#define MASK_MUL 0xfe00707fU -#define MATCH_MULH 0x2001033U -#define MASK_MULH 0xfe00707fU -#define MATCH_MULHSU 0x2002033U -#define MASK_MULHSU 0xfe00707fU -#define MATCH_MULHU 0x2003033U -#define MASK_MULHU 0xfe00707fU -#define MATCH_DIV 0x2004033U -#define MASK_DIV 0xfe00707fU -#define MATCH_DIVU 0x2005033U -#define MASK_DIVU 0xfe00707fU -#define MATCH_REM 0x2006033U -#define MASK_REM 0xfe00707fU -#define MATCH_REMU 0x2007033U -#define MASK_REMU 0xfe00707fU -#define MATCH_MULW 0x200003bU -#define MASK_MULW 0xfe00707fU -#define MATCH_DIVW 0x200403bU -#define MASK_DIVW 0xfe00707fU -#define MATCH_DIVUW 0x200503bU -#define MASK_DIVUW 0xfe00707fU -#define MATCH_REMW 0x200603bU -#define MASK_REMW 0xfe00707fU -#define MATCH_REMUW 0x200703bU -#define MASK_REMUW 0xfe00707fU -#define MATCH_AMOADD_W 0x202fU -#define MASK_AMOADD_W 0xf800707fU -#define MATCH_AMOXOR_W 0x2000202fU -#define MASK_AMOXOR_W 0xf800707fU -#define MATCH_AMOOR_W 0x4000202fU -#define MASK_AMOOR_W 0xf800707fU -#define MATCH_AMOAND_W 0x6000202fU -#define MASK_AMOAND_W 0xf800707fU -#define MATCH_AMOMIN_W 0x8000202fU -#define MASK_AMOMIN_W 0xf800707fU -#define MATCH_AMOMAX_W 0xa000202fU -#define MASK_AMOMAX_W 0xf800707fU -#define MATCH_AMOMINU_W 0xc000202fU -#define MASK_AMOMINU_W 0xf800707fU -#define MATCH_AMOMAXU_W 0xe000202fU -#define MASK_AMOMAXU_W 0xf800707fU -#define MATCH_AMOSWAP_W 0x800202fU -#define MASK_AMOSWAP_W 0xf800707fU -#define MATCH_LR_W 0x1000202fU -#define MASK_LR_W 0xf9f0707fU -#define MATCH_SC_W 0x1800202fU -#define MASK_SC_W 0xf800707fU -#define MATCH_AMOADD_D 0x302fU -#define MASK_AMOADD_D 0xf800707fU -#define MATCH_AMOXOR_D 0x2000302fU -#define MASK_AMOXOR_D 0xf800707fU -#define MATCH_AMOOR_D 0x4000302fU -#define MASK_AMOOR_D 0xf800707fU -#define MATCH_AMOAND_D 0x6000302fU -#define MASK_AMOAND_D 0xf800707fU -#define MATCH_AMOMIN_D 0x8000302fU -#define MASK_AMOMIN_D 0xf800707fU -#define MATCH_AMOMAX_D 0xa000302fU -#define MASK_AMOMAX_D 0xf800707fU -#define MATCH_AMOMINU_D 0xc000302fU -#define MASK_AMOMINU_D 0xf800707fU -#define MATCH_AMOMAXU_D 0xe000302fU -#define MASK_AMOMAXU_D 0xf800707fU -#define MATCH_AMOSWAP_D 0x800302fU -#define MASK_AMOSWAP_D 0xf800707fU -#define MATCH_LR_D 0x1000302fU -#define MASK_LR_D 0xf9f0707fU -#define MATCH_SC_D 0x1800302fU -#define MASK_SC_D 0xf800707fU -#define MATCH_ECALL 0x73U -#define MASK_ECALL 0xffffffffU -#define MATCH_EBREAK 0x100073U -#define MASK_EBREAK 0xffffffffU -#define MATCH_URET 0x200073U -#define MASK_URET 0xffffffffU -#define MATCH_SRET 0x10200073U -#define MASK_SRET 0xffffffffU -#define MATCH_HRET 0x20200073U -#define MASK_HRET 0xffffffffU -#define MATCH_MRET 0x30200073U -#define MASK_MRET 0xffffffffU -#define MATCH_DRET 0x7b200073U -#define MASK_DRET 0xffffffffU -#define MATCH_SFENCE_VM 0x10400073U -#define MASK_SFENCE_VM 0xfff07fffU -#define MATCH_WFI 0x10500073U -#define MASK_WFI 0xffffffffU -#define MATCH_CSRRW 0x1073U -#define MASK_CSRRW 0x707fU -#define MATCH_CSRRS 0x2073U -#define MASK_CSRRS 0x707fU -#define MATCH_CSRRC 0x3073U -#define MASK_CSRRC 0x707fU -#define MATCH_CSRRWI 0x5073U -#define MASK_CSRRWI 0x707fU -#define MATCH_CSRRSI 0x6073U -#define MASK_CSRRSI 0x707fU -#define MATCH_CSRRCI 0x7073U -#define MASK_CSRRCI 0x707fU -#define MATCH_FADD_S 0x53U -#define MASK_FADD_S 0xfe00007fU -#define MATCH_FSUB_S 0x8000053U -#define MASK_FSUB_S 0xfe00007fU -#define MATCH_FMUL_S 0x10000053U -#define MASK_FMUL_S 0xfe00007fU -#define MATCH_FDIV_S 0x18000053U -#define MASK_FDIV_S 0xfe00007fU -#define MATCH_FSGNJ_S 0x20000053U -#define MASK_FSGNJ_S 0xfe00707fU -#define MATCH_FSGNJN_S 0x20001053U -#define MASK_FSGNJN_S 0xfe00707fU -#define MATCH_FSGNJX_S 0x20002053U -#define MASK_FSGNJX_S 0xfe00707fU -#define MATCH_FMIN_S 0x28000053U -#define MASK_FMIN_S 0xfe00707fU -#define MATCH_FMAX_S 0x28001053U -#define MASK_FMAX_S 0xfe00707fU -#define MATCH_FSQRT_S 0x58000053U -#define MASK_FSQRT_S 0xfff0007fU -#define MATCH_FADD_D 0x2000053U -#define MASK_FADD_D 0xfe00007fU -#define MATCH_FSUB_D 0xa000053U -#define MASK_FSUB_D 0xfe00007fU -#define MATCH_FMUL_D 0x12000053U -#define MASK_FMUL_D 0xfe00007fU -#define MATCH_FDIV_D 0x1a000053U -#define MASK_FDIV_D 0xfe00007fU -#define MATCH_FSGNJ_D 0x22000053U -#define MASK_FSGNJ_D 0xfe00707fU -#define MATCH_FSGNJN_D 0x22001053U -#define MASK_FSGNJN_D 0xfe00707fU -#define MATCH_FSGNJX_D 0x22002053U -#define MASK_FSGNJX_D 0xfe00707fU -#define MATCH_FMIN_D 0x2a000053U -#define MASK_FMIN_D 0xfe00707fU -#define MATCH_FMAX_D 0x2a001053U -#define MASK_FMAX_D 0xfe00707fU -#define MATCH_FCVT_S_D 0x40100053U -#define MASK_FCVT_S_D 0xfff0007fU -#define MATCH_FCVT_D_S 0x42000053U -#define MASK_FCVT_D_S 0xfff0007fU -#define MATCH_FSQRT_D 0x5a000053U -#define MASK_FSQRT_D 0xfff0007fU -#define MATCH_FLE_S 0xa0000053U -#define MASK_FLE_S 0xfe00707fU -#define MATCH_FLT_S 0xa0001053U -#define MASK_FLT_S 0xfe00707fU -#define MATCH_FEQ_S 0xa0002053U -#define MASK_FEQ_S 0xfe00707fU -#define MATCH_FLE_D 0xa2000053U -#define MASK_FLE_D 0xfe00707fU -#define MATCH_FLT_D 0xa2001053U -#define MASK_FLT_D 0xfe00707fU -#define MATCH_FEQ_D 0xa2002053U -#define MASK_FEQ_D 0xfe00707fU -#define MATCH_FCVT_W_S 0xc0000053U -#define MASK_FCVT_W_S 0xfff0007fU -#define MATCH_FCVT_WU_S 0xc0100053U -#define MASK_FCVT_WU_S 0xfff0007fU -#define MATCH_FCVT_L_S 0xc0200053U -#define MASK_FCVT_L_S 0xfff0007fU -#define MATCH_FCVT_LU_S 0xc0300053U -#define MASK_FCVT_LU_S 0xfff0007fU -#define MATCH_FMV_X_S 0xe0000053U -#define MASK_FMV_X_S 0xfff0707fU -#define MATCH_FCLASS_S 0xe0001053U -#define MASK_FCLASS_S 0xfff0707fU -#define MATCH_FCVT_W_D 0xc2000053U -#define MASK_FCVT_W_D 0xfff0007fU -#define MATCH_FCVT_WU_D 0xc2100053U -#define MASK_FCVT_WU_D 0xfff0007fU -#define MATCH_FCVT_L_D 0xc2200053U -#define MASK_FCVT_L_D 0xfff0007fU -#define MATCH_FCVT_LU_D 0xc2300053U -#define MASK_FCVT_LU_D 0xfff0007fU -#define MATCH_FMV_X_D 0xe2000053U -#define MASK_FMV_X_D 0xfff0707fU -#define MATCH_FCLASS_D 0xe2001053U -#define MASK_FCLASS_D 0xfff0707fU -#define MATCH_FCVT_S_W 0xd0000053U -#define MASK_FCVT_S_W 0xfff0007fU -#define MATCH_FCVT_S_WU 0xd0100053U -#define MASK_FCVT_S_WU 0xfff0007fU -#define MATCH_FCVT_S_L 0xd0200053U -#define MASK_FCVT_S_L 0xfff0007fU -#define MATCH_FCVT_S_LU 0xd0300053U -#define MASK_FCVT_S_LU 0xfff0007fU -#define MATCH_FMV_S_X 0xf0000053U -#define MASK_FMV_S_X 0xfff0707fU -#define MATCH_FCVT_D_W 0xd2000053U -#define MASK_FCVT_D_W 0xfff0007fU -#define MATCH_FCVT_D_WU 0xd2100053U -#define MASK_FCVT_D_WU 0xfff0007fU -#define MATCH_FCVT_D_L 0xd2200053U -#define MASK_FCVT_D_L 0xfff0007fU -#define MATCH_FCVT_D_LU 0xd2300053U -#define MASK_FCVT_D_LU 0xfff0007fU -#define MATCH_FMV_D_X 0xf2000053U -#define MASK_FMV_D_X 0xfff0707fU -#define MATCH_FLW 0x2007U -#define MASK_FLW 0x707fU -#define MATCH_FLD 0x3007U -#define MASK_FLD 0x707fU -#define MATCH_FSW 0x2027U -#define MASK_FSW 0x707fU -#define MATCH_FSD 0x3027U -#define MASK_FSD 0x707fU -#define MATCH_FMADD_S 0x43U -#define MASK_FMADD_S 0x600007fU -#define MATCH_FMSUB_S 0x47U -#define MASK_FMSUB_S 0x600007fU -#define MATCH_FNMSUB_S 0x4bU -#define MASK_FNMSUB_S 0x600007fU -#define MATCH_FNMADD_S 0x4fU -#define MASK_FNMADD_S 0x600007fU -#define MATCH_FMADD_D 0x2000043U -#define MASK_FMADD_D 0x600007fU -#define MATCH_FMSUB_D 0x2000047U -#define MASK_FMSUB_D 0x600007fU -#define MATCH_FNMSUB_D 0x200004bU -#define MASK_FNMSUB_D 0x600007fU -#define MATCH_FNMADD_D 0x200004fU -#define MASK_FNMADD_D 0x600007fU -#define MATCH_C_NOP 0x1U -#define MASK_C_NOP 0xffffU -#define MATCH_C_ADDI16SP 0x6101U -#define MASK_C_ADDI16SP 0xef83U -#define MATCH_C_JR 0x8002U -#define MASK_C_JR 0xf07fU -#define MATCH_C_JALR 0x9002U -#define MASK_C_JALR 0xf07fU -#define MATCH_C_EBREAK 0x9002U -#define MASK_C_EBREAK 0xffffU -#define MATCH_C_LD 0x6000U -#define MASK_C_LD 0xe003U -#define MATCH_C_SD 0xe000U -#define MASK_C_SD 0xe003U -#define MATCH_C_ADDIW 0x2001U -#define MASK_C_ADDIW 0xe003U -#define MATCH_C_LDSP 0x6002U -#define MASK_C_LDSP 0xe003U -#define MATCH_C_SDSP 0xe002U -#define MASK_C_SDSP 0xe003U -#define MATCH_C_ADDI4SPN 0x0U -#define MASK_C_ADDI4SPN 0xe003U -#define MATCH_C_FLD 0x2000U -#define MASK_C_FLD 0xe003U -#define MATCH_C_LW 0x4000U -#define MASK_C_LW 0xe003U -#define MATCH_C_FLW 0x6000U -#define MASK_C_FLW 0xe003U -#define MATCH_C_FSD 0xa000U -#define MASK_C_FSD 0xe003U -#define MATCH_C_SW 0xc000U -#define MASK_C_SW 0xe003U -#define MATCH_C_FSW 0xe000U -#define MASK_C_FSW 0xe003U -#define MATCH_C_ADDI 0x1U -#define MASK_C_ADDI 0xe003U -#define MATCH_C_JAL 0x2001U -#define MASK_C_JAL 0xe003U -#define MATCH_C_LI 0x4001U -#define MASK_C_LI 0xe003U -#define MATCH_C_LUI 0x6001U -#define MASK_C_LUI 0xe003U -#define MATCH_C_SRLI 0x8001U -#define MASK_C_SRLI 0xec03U -#define MATCH_C_SRAI 0x8401U -#define MASK_C_SRAI 0xec03U -#define MATCH_C_ANDI 0x8801U -#define MASK_C_ANDI 0xec03U -#define MATCH_C_SUB 0x8c01U -#define MASK_C_SUB 0xfc63U -#define MATCH_C_XOR 0x8c21U -#define MASK_C_XOR 0xfc63U -#define MATCH_C_OR 0x8c41U -#define MASK_C_OR 0xfc63U -#define MATCH_C_AND 0x8c61U -#define MASK_C_AND 0xfc63U -#define MATCH_C_SUBW 0x9c01U -#define MASK_C_SUBW 0xfc63U -#define MATCH_C_ADDW 0x9c21U -#define MASK_C_ADDW 0xfc63U -#define MATCH_C_J 0xa001U -#define MASK_C_J 0xe003U -#define MATCH_C_BEQZ 0xc001U -#define MASK_C_BEQZ 0xe003U -#define MATCH_C_BNEZ 0xe001U -#define MASK_C_BNEZ 0xe003U -#define MATCH_C_SLLI 0x2U -#define MASK_C_SLLI 0xe003U -#define MATCH_C_FLDSP 0x2002U -#define MASK_C_FLDSP 0xe003U -#define MATCH_C_LWSP 0x4002U -#define MASK_C_LWSP 0xe003U -#define MATCH_C_FLWSP 0x6002U -#define MASK_C_FLWSP 0xe003U -#define MATCH_C_MV 0x8002U -#define MASK_C_MV 0xf003U -#define MATCH_C_ADD 0x9002U -#define MASK_C_ADD 0xf003U -#define MATCH_C_FSDSP 0xa002U -#define MASK_C_FSDSP 0xe003U -#define MATCH_C_SWSP 0xc002U -#define MASK_C_SWSP 0xe003U -#define MATCH_C_FSWSP 0xe002U -#define MASK_C_FSWSP 0xe003U -#define MATCH_CUSTOM0 0xbU -#define MASK_CUSTOM0 0x707fU -#define MATCH_CUSTOM0_RS1 0x200bU -#define MASK_CUSTOM0_RS1 0x707fU -#define MATCH_CUSTOM0_RS1_RS2 0x300bU -#define MASK_CUSTOM0_RS1_RS2 0x707fU -#define MATCH_CUSTOM0_RD 0x400bU -#define MASK_CUSTOM0_RD 0x707fU -#define MATCH_CUSTOM0_RD_RS1 0x600bU -#define MASK_CUSTOM0_RD_RS1 0x707fU -#define MATCH_CUSTOM0_RD_RS1_RS2 0x700bU -#define MASK_CUSTOM0_RD_RS1_RS2 0x707fU -#define MATCH_CUSTOM1 0x2bU -#define MASK_CUSTOM1 0x707fU -#define MATCH_CUSTOM1_RS1 0x202bU -#define MASK_CUSTOM1_RS1 0x707fU -#define MATCH_CUSTOM1_RS1_RS2 0x302bU -#define MASK_CUSTOM1_RS1_RS2 0x707fU -#define MATCH_CUSTOM1_RD 0x402bU -#define MASK_CUSTOM1_RD 0x707fU -#define MATCH_CUSTOM1_RD_RS1 0x602bU -#define MASK_CUSTOM1_RD_RS1 0x707fU -#define MATCH_CUSTOM1_RD_RS1_RS2 0x702bU -#define MASK_CUSTOM1_RD_RS1_RS2 0x707fU -#define MATCH_CUSTOM2 0x5bU -#define MASK_CUSTOM2 0x707fU -#define MATCH_CUSTOM2_RS1 0x205bU -#define MASK_CUSTOM2_RS1 0x707fU -#define MATCH_CUSTOM2_RS1_RS2 0x305bU -#define MASK_CUSTOM2_RS1_RS2 0x707fU -#define MATCH_CUSTOM2_RD 0x405bU -#define MASK_CUSTOM2_RD 0x707fU -#define MATCH_CUSTOM2_RD_RS1 0x605bU -#define MASK_CUSTOM2_RD_RS1 0x707fU -#define MATCH_CUSTOM2_RD_RS1_RS2 0x705bU -#define MASK_CUSTOM2_RD_RS1_RS2 0x707fU -#define MATCH_CUSTOM3 0x7bU -#define MASK_CUSTOM3 0x707fU -#define MATCH_CUSTOM3_RS1 0x207bU -#define MASK_CUSTOM3_RS1 0x707fU -#define MATCH_CUSTOM3_RS1_RS2 0x307bU -#define MASK_CUSTOM3_RS1_RS2 0x707fU -#define MATCH_CUSTOM3_RD 0x407bU -#define MASK_CUSTOM3_RD 0x707fU -#define MATCH_CUSTOM3_RD_RS1 0x607bU -#define MASK_CUSTOM3_RD_RS1 0x707fU -#define MATCH_CUSTOM3_RD_RS1_RS2 0x707bU -#define MASK_CUSTOM3_RD_RS1_RS2 0x707fU -#define CSR_FFLAGS 0x1U -#define CSR_FRM 0x2U -#define CSR_FCSR 0x3U -#define CSR_CYCLE 0xc00U -#define CSR_TIME 0xc01U -#define CSR_INSTRET 0xc02U -#define CSR_HPMCOUNTER3 0xc03U -#define CSR_HPMCOUNTER4 0xc04U -#define CSR_HPMCOUNTER5 0xc05U -#define CSR_HPMCOUNTER6 0xc06U -#define CSR_HPMCOUNTER7 0xc07U -#define CSR_HPMCOUNTER8 0xc08U -#define CSR_HPMCOUNTER9 0xc09U -#define CSR_HPMCOUNTER10 0xc0aU -#define CSR_HPMCOUNTER11 0xc0bU -#define CSR_HPMCOUNTER12 0xc0cU -#define CSR_HPMCOUNTER13 0xc0dU -#define CSR_HPMCOUNTER14 0xc0eU -#define CSR_HPMCOUNTER15 0xc0fU -#define CSR_HPMCOUNTER16 0xc10U -#define CSR_HPMCOUNTER17 0xc11U -#define CSR_HPMCOUNTER18 0xc12U -#define CSR_HPMCOUNTER19 0xc13U -#define CSR_HPMCOUNTER20 0xc14U -#define CSR_HPMCOUNTER21 0xc15U -#define CSR_HPMCOUNTER22 0xc16U -#define CSR_HPMCOUNTER23 0xc17U -#define CSR_HPMCOUNTER24 0xc18U -#define CSR_HPMCOUNTER25 0xc19U -#define CSR_HPMCOUNTER26 0xc1aU -#define CSR_HPMCOUNTER27 0xc1bU -#define CSR_HPMCOUNTER28 0xc1cU -#define CSR_HPMCOUNTER29 0xc1dU -#define CSR_HPMCOUNTER30 0xc1eU -#define CSR_HPMCOUNTER31 0xc1fU -#define CSR_SSTATUS 0x100U -#define CSR_SIE 0x104U -#define CSR_STVEC 0x105U -#define CSR_SSCRATCH 0x140U -#define CSR_SEPC 0x141U -#define CSR_SCAUSE 0x142U -#define CSR_SBADADDR 0x143U -#define CSR_SIP 0x144U -#define CSR_SPTBR 0x180U -#define CSR_MSTATUS 0x300U -#define CSR_MISA 0x301U -#define CSR_MEDELEG 0x302U -#define CSR_MIDELEG 0x303U -#define CSR_MIE 0x304U -#define CSR_MTVEC 0x305U -#define CSR_MSCRATCH 0x340U -#define CSR_MEPC 0x341U -#define CSR_MCAUSE 0x342U -#define CSR_MBADADDR 0x343U -#define CSR_MIP 0x344U -#define CSR_TSELECT 0x7a0U -#define CSR_TDATA1 0x7a1U -#define CSR_TDATA2 0x7a2U -#define CSR_TDATA3 0x7a3U -#define CSR_DCSR 0x7b0U -#define CSR_DPC 0x7b1U -#define CSR_DSCRATCH 0x7b2U -#define CSR_MCYCLE 0xb00U -#define CSR_MINSTRET 0xb02U -#define CSR_MHPMCOUNTER3 0xb03U -#define CSR_MHPMCOUNTER4 0xb04U -#define CSR_MHPMCOUNTER5 0xb05U -#define CSR_MHPMCOUNTER6 0xb06U -#define CSR_MHPMCOUNTER7 0xb07U -#define CSR_MHPMCOUNTER8 0xb08U -#define CSR_MHPMCOUNTER9 0xb09U -#define CSR_MHPMCOUNTER10 0xb0aU -#define CSR_MHPMCOUNTER11 0xb0bU -#define CSR_MHPMCOUNTER12 0xb0cU -#define CSR_MHPMCOUNTER13 0xb0dU -#define CSR_MHPMCOUNTER14 0xb0eU -#define CSR_MHPMCOUNTER15 0xb0fU -#define CSR_MHPMCOUNTER16 0xb10U -#define CSR_MHPMCOUNTER17 0xb11U -#define CSR_MHPMCOUNTER18 0xb12U -#define CSR_MHPMCOUNTER19 0xb13U -#define CSR_MHPMCOUNTER20 0xb14U -#define CSR_MHPMCOUNTER21 0xb15U -#define CSR_MHPMCOUNTER22 0xb16U -#define CSR_MHPMCOUNTER23 0xb17U -#define CSR_MHPMCOUNTER24 0xb18U -#define CSR_MHPMCOUNTER25 0xb19U -#define CSR_MHPMCOUNTER26 0xb1aU -#define CSR_MHPMCOUNTER27 0xb1bU -#define CSR_MHPMCOUNTER28 0xb1cU -#define CSR_MHPMCOUNTER29 0xb1dU -#define CSR_MHPMCOUNTER30 0xb1eU -#define CSR_MHPMCOUNTER31 0xb1fU -#define CSR_MUCOUNTEREN 0x320U -#define CSR_MSCOUNTEREN 0x321U -#define CSR_MHPMEVENT3 0x323U -#define CSR_MHPMEVENT4 0x324U -#define CSR_MHPMEVENT5 0x325U -#define CSR_MHPMEVENT6 0x326U -#define CSR_MHPMEVENT7 0x327U -#define CSR_MHPMEVENT8 0x328U -#define CSR_MHPMEVENT9 0x329U -#define CSR_MHPMEVENT10 0x32aU -#define CSR_MHPMEVENT11 0x32bU -#define CSR_MHPMEVENT12 0x32cU -#define CSR_MHPMEVENT13 0x32dU -#define CSR_MHPMEVENT14 0x32eU -#define CSR_MHPMEVENT15 0x32fU -#define CSR_MHPMEVENT16 0x330U -#define CSR_MHPMEVENT17 0x331U -#define CSR_MHPMEVENT18 0x332U -#define CSR_MHPMEVENT19 0x333U -#define CSR_MHPMEVENT20 0x334U -#define CSR_MHPMEVENT21 0x335U -#define CSR_MHPMEVENT22 0x336U -#define CSR_MHPMEVENT23 0x337U -#define CSR_MHPMEVENT24 0x338U -#define CSR_MHPMEVENT25 0x339U -#define CSR_MHPMEVENT26 0x33aU -#define CSR_MHPMEVENT27 0x33bU -#define CSR_MHPMEVENT28 0x33cU -#define CSR_MHPMEVENT29 0x33dU -#define CSR_MHPMEVENT30 0x33eU -#define CSR_MHPMEVENT31 0x33fU -#define CSR_MVENDORID 0xf11U -#define CSR_MARCHID 0xf12U -#define CSR_MIMPID 0xf13U -#define CSR_MHARTID 0xf14U -#define CSR_CYCLEH 0xc80U -#define CSR_TIMEH 0xc81U -#define CSR_INSTRETH 0xc82U -#define CSR_HPMCOUNTER3H 0xc83U -#define CSR_HPMCOUNTER4H 0xc84U -#define CSR_HPMCOUNTER5H 0xc85U -#define CSR_HPMCOUNTER6H 0xc86U -#define CSR_HPMCOUNTER7H 0xc87U -#define CSR_HPMCOUNTER8H 0xc88U -#define CSR_HPMCOUNTER9H 0xc89U -#define CSR_HPMCOUNTER10H 0xc8aU -#define CSR_HPMCOUNTER11H 0xc8bU -#define CSR_HPMCOUNTER12H 0xc8cU -#define CSR_HPMCOUNTER13H 0xc8dU -#define CSR_HPMCOUNTER14H 0xc8eU -#define CSR_HPMCOUNTER15H 0xc8fU -#define CSR_HPMCOUNTER16H 0xc90U -#define CSR_HPMCOUNTER17H 0xc91U -#define CSR_HPMCOUNTER18H 0xc92U -#define CSR_HPMCOUNTER19H 0xc93U -#define CSR_HPMCOUNTER20H 0xc94U -#define CSR_HPMCOUNTER21H 0xc95U -#define CSR_HPMCOUNTER22H 0xc96U -#define CSR_HPMCOUNTER23H 0xc97U -#define CSR_HPMCOUNTER24H 0xc98U -#define CSR_HPMCOUNTER25H 0xc99U -#define CSR_HPMCOUNTER26H 0xc9aU -#define CSR_HPMCOUNTER27H 0xc9bU -#define CSR_HPMCOUNTER28H 0xc9cU -#define CSR_HPMCOUNTER29H 0xc9dU -#define CSR_HPMCOUNTER30H 0xc9eU -#define CSR_HPMCOUNTER31H 0xc9fU -#define CSR_MCYCLEH 0xb80U -#define CSR_MINSTRETH 0xb82U -#define CSR_MHPMCOUNTER3H 0xb83U -#define CSR_MHPMCOUNTER4H 0xb84U -#define CSR_MHPMCOUNTER5H 0xb85U -#define CSR_MHPMCOUNTER6H 0xb86U -#define CSR_MHPMCOUNTER7H 0xb87U -#define CSR_MHPMCOUNTER8H 0xb88U -#define CSR_MHPMCOUNTER9H 0xb89U -#define CSR_MHPMCOUNTER10H 0xb8aU -#define CSR_MHPMCOUNTER11H 0xb8bU -#define CSR_MHPMCOUNTER12H 0xb8cU -#define CSR_MHPMCOUNTER13H 0xb8dU -#define CSR_MHPMCOUNTER14H 0xb8eU -#define CSR_MHPMCOUNTER15H 0xb8fU -#define CSR_MHPMCOUNTER16H 0xb90U -#define CSR_MHPMCOUNTER17H 0xb91U -#define CSR_MHPMCOUNTER18H 0xb92U -#define CSR_MHPMCOUNTER19H 0xb93U -#define CSR_MHPMCOUNTER20H 0xb94U -#define CSR_MHPMCOUNTER21H 0xb95U -#define CSR_MHPMCOUNTER22H 0xb96U -#define CSR_MHPMCOUNTER23H 0xb97U -#define CSR_MHPMCOUNTER24H 0xb98U -#define CSR_MHPMCOUNTER25H 0xb99U -#define CSR_MHPMCOUNTER26H 0xb9aU -#define CSR_MHPMCOUNTER27H 0xb9bU -#define CSR_MHPMCOUNTER28H 0xb9cU -#define CSR_MHPMCOUNTER29H 0xb9dU -#define CSR_MHPMCOUNTER30H 0xb9eU -#define CSR_MHPMCOUNTER31H 0xb9fU -#define CAUSE_MISALIGNED_FETCH 0x0 -#define CAUSE_FAULT_FETCH 0x1 -#define CAUSE_ILLEGAL_INSTRUCTION 0x2 -#define CAUSE_BREAKPOINT 0x3 -#define CAUSE_MISALIGNED_LOAD 0x4 -#define CAUSE_FAULT_LOAD 0x5 -#define CAUSE_MISALIGNED_STORE 0x6 -#define CAUSE_FAULT_STORE 0x7 -#define CAUSE_USER_ECALL 0x8 -#define CAUSE_SUPERVISOR_ECALL 0x9 -#define CAUSE_HYPERVISOR_ECALL 0xa -#define CAUSE_MACHINE_ECALL 0xb -#endif -#if defined(DECLARE_INSN) -DECLARE_INSN(beq, MATCH_BEQ, MASK_BEQ) -DECLARE_INSN(bne, MATCH_BNE, MASK_BNE) -DECLARE_INSN(blt, MATCH_BLT, MASK_BLT) -DECLARE_INSN(bge, MATCH_BGE, MASK_BGE) -DECLARE_INSN(bltu, MATCH_BLTU, MASK_BLTU) -DECLARE_INSN(bgeu, MATCH_BGEU, MASK_BGEU) -DECLARE_INSN(jalr, MATCH_JALR, MASK_JALR) -DECLARE_INSN(jal, MATCH_JAL, MASK_JAL) -DECLARE_INSN(lui, MATCH_LUI, MASK_LUI) -DECLARE_INSN(auipc, MATCH_AUIPC, MASK_AUIPC) -DECLARE_INSN(addi, MATCH_ADDI, MASK_ADDI) -DECLARE_INSN(slli, MATCH_SLLI, MASK_SLLI) -DECLARE_INSN(slti, MATCH_SLTI, MASK_SLTI) -DECLARE_INSN(sltiu, MATCH_SLTIU, MASK_SLTIU) -DECLARE_INSN(xori, MATCH_XORI, MASK_XORI) -DECLARE_INSN(srli, MATCH_SRLI, MASK_SRLI) -DECLARE_INSN(srai, MATCH_SRAI, MASK_SRAI) -DECLARE_INSN(ori, MATCH_ORI, MASK_ORI) -DECLARE_INSN(andi, MATCH_ANDI, MASK_ANDI) -DECLARE_INSN(add, MATCH_ADD, MASK_ADD) -DECLARE_INSN(sub, MATCH_SUB, MASK_SUB) -DECLARE_INSN(sll, MATCH_SLL, MASK_SLL) -DECLARE_INSN(slt, MATCH_SLT, MASK_SLT) -DECLARE_INSN(sltu, MATCH_SLTU, MASK_SLTU) -DECLARE_INSN(xor, MATCH_XOR, MASK_XOR) -DECLARE_INSN(srl, MATCH_SRL, MASK_SRL) -DECLARE_INSN(sra, MATCH_SRA, MASK_SRA) -DECLARE_INSN(or, MATCH_OR, MASK_OR) -DECLARE_INSN(and, MATCH_AND, MASK_AND) -DECLARE_INSN(addiw, MATCH_ADDIW, MASK_ADDIW) -DECLARE_INSN(slliw, MATCH_SLLIW, MASK_SLLIW) -DECLARE_INSN(srliw, MATCH_SRLIW, MASK_SRLIW) -DECLARE_INSN(sraiw, MATCH_SRAIW, MASK_SRAIW) -DECLARE_INSN(addw, MATCH_ADDW, MASK_ADDW) -DECLARE_INSN(subw, MATCH_SUBW, MASK_SUBW) -DECLARE_INSN(sllw, MATCH_SLLW, MASK_SLLW) -DECLARE_INSN(srlw, MATCH_SRLW, MASK_SRLW) -DECLARE_INSN(sraw, MATCH_SRAW, MASK_SRAW) -DECLARE_INSN(lb, MATCH_LB, MASK_LB) -DECLARE_INSN(lh, MATCH_LH, MASK_LH) -DECLARE_INSN(lw, MATCH_LW, MASK_LW) -DECLARE_INSN(ld, MATCH_LD, MASK_LD) -DECLARE_INSN(lbu, MATCH_LBU, MASK_LBU) -DECLARE_INSN(lhu, MATCH_LHU, MASK_LHU) -DECLARE_INSN(lwu, MATCH_LWU, MASK_LWU) -DECLARE_INSN(sb, MATCH_SB, MASK_SB) -DECLARE_INSN(sh, MATCH_SH, MASK_SH) -DECLARE_INSN(sw, MATCH_SW, MASK_SW) -DECLARE_INSN(sd, MATCH_SD, MASK_SD) -DECLARE_INSN(fence, MATCH_FENCE, MASK_FENCE) -DECLARE_INSN(fence_i, MATCH_FENCE_I, MASK_FENCE_I) -DECLARE_INSN(mul, MATCH_MUL, MASK_MUL) -DECLARE_INSN(mulh, MATCH_MULH, MASK_MULH) -DECLARE_INSN(mulhsu, MATCH_MULHSU, MASK_MULHSU) -DECLARE_INSN(mulhu, MATCH_MULHU, MASK_MULHU) -DECLARE_INSN(div, MATCH_DIV, MASK_DIV) -DECLARE_INSN(divu, MATCH_DIVU, MASK_DIVU) -DECLARE_INSN(rem, MATCH_REM, MASK_REM) -DECLARE_INSN(remu, MATCH_REMU, MASK_REMU) -DECLARE_INSN(mulw, MATCH_MULW, MASK_MULW) -DECLARE_INSN(divw, MATCH_DIVW, MASK_DIVW) -DECLARE_INSN(divuw, MATCH_DIVUW, MASK_DIVUW) -DECLARE_INSN(remw, MATCH_REMW, MASK_REMW) -DECLARE_INSN(remuw, MATCH_REMUW, MASK_REMUW) -DECLARE_INSN(amoadd_w, MATCH_AMOADD_W, MASK_AMOADD_W) -DECLARE_INSN(amoxor_w, MATCH_AMOXOR_W, MASK_AMOXOR_W) -DECLARE_INSN(amoor_w, MATCH_AMOOR_W, MASK_AMOOR_W) -DECLARE_INSN(amoand_w, MATCH_AMOAND_W, MASK_AMOAND_W) -DECLARE_INSN(amomin_w, MATCH_AMOMIN_W, MASK_AMOMIN_W) -DECLARE_INSN(amomax_w, MATCH_AMOMAX_W, MASK_AMOMAX_W) -DECLARE_INSN(amominu_w, MATCH_AMOMINU_W, MASK_AMOMINU_W) -DECLARE_INSN(amomaxu_w, MATCH_AMOMAXU_W, MASK_AMOMAXU_W) -DECLARE_INSN(amoswap_w, MATCH_AMOSWAP_W, MASK_AMOSWAP_W) -DECLARE_INSN(lr_w, MATCH_LR_W, MASK_LR_W) -DECLARE_INSN(sc_w, MATCH_SC_W, MASK_SC_W) -DECLARE_INSN(amoadd_d, MATCH_AMOADD_D, MASK_AMOADD_D) -DECLARE_INSN(amoxor_d, MATCH_AMOXOR_D, MASK_AMOXOR_D) -DECLARE_INSN(amoor_d, MATCH_AMOOR_D, MASK_AMOOR_D) -DECLARE_INSN(amoand_d, MATCH_AMOAND_D, MASK_AMOAND_D) -DECLARE_INSN(amomin_d, MATCH_AMOMIN_D, MASK_AMOMIN_D) -DECLARE_INSN(amomax_d, MATCH_AMOMAX_D, MASK_AMOMAX_D) -DECLARE_INSN(amominu_d, MATCH_AMOMINU_D, MASK_AMOMINU_D) -DECLARE_INSN(amomaxu_d, MATCH_AMOMAXU_D, MASK_AMOMAXU_D) -DECLARE_INSN(amoswap_d, MATCH_AMOSWAP_D, MASK_AMOSWAP_D) -DECLARE_INSN(lr_d, MATCH_LR_D, MASK_LR_D) -DECLARE_INSN(sc_d, MATCH_SC_D, MASK_SC_D) -DECLARE_INSN(ecall, MATCH_ECALL, MASK_ECALL) -DECLARE_INSN(ebreak, MATCH_EBREAK, MASK_EBREAK) -DECLARE_INSN(uret, MATCH_URET, MASK_URET) -DECLARE_INSN(sret, MATCH_SRET, MASK_SRET) -DECLARE_INSN(hret, MATCH_HRET, MASK_HRET) -DECLARE_INSN(mret, MATCH_MRET, MASK_MRET) -DECLARE_INSN(dret, MATCH_DRET, MASK_DRET) -DECLARE_INSN(sfence_vm, MATCH_SFENCE_VM, MASK_SFENCE_VM) -DECLARE_INSN(wfi, MATCH_WFI, MASK_WFI) -DECLARE_INSN(csrrw, MATCH_CSRRW, MASK_CSRRW) -DECLARE_INSN(csrrs, MATCH_CSRRS, MASK_CSRRS) -DECLARE_INSN(csrrc, MATCH_CSRRC, MASK_CSRRC) -DECLARE_INSN(csrrwi, MATCH_CSRRWI, MASK_CSRRWI) -DECLARE_INSN(csrrsi, MATCH_CSRRSI, MASK_CSRRSI) -DECLARE_INSN(csrrci, MATCH_CSRRCI, MASK_CSRRCI) -DECLARE_INSN(fadd_s, MATCH_FADD_S, MASK_FADD_S) -DECLARE_INSN(fsub_s, MATCH_FSUB_S, MASK_FSUB_S) -DECLARE_INSN(fmul_s, MATCH_FMUL_S, MASK_FMUL_S) -DECLARE_INSN(fdiv_s, MATCH_FDIV_S, MASK_FDIV_S) -DECLARE_INSN(fsgnj_s, MATCH_FSGNJ_S, MASK_FSGNJ_S) -DECLARE_INSN(fsgnjn_s, MATCH_FSGNJN_S, MASK_FSGNJN_S) -DECLARE_INSN(fsgnjx_s, MATCH_FSGNJX_S, MASK_FSGNJX_S) -DECLARE_INSN(fmin_s, MATCH_FMIN_S, MASK_FMIN_S) -DECLARE_INSN(fmax_s, MATCH_FMAX_S, MASK_FMAX_S) -DECLARE_INSN(fsqrt_s, MATCH_FSQRT_S, MASK_FSQRT_S) -DECLARE_INSN(fadd_d, MATCH_FADD_D, MASK_FADD_D) -DECLARE_INSN(fsub_d, MATCH_FSUB_D, MASK_FSUB_D) -DECLARE_INSN(fmul_d, MATCH_FMUL_D, MASK_FMUL_D) -DECLARE_INSN(fdiv_d, MATCH_FDIV_D, MASK_FDIV_D) -DECLARE_INSN(fsgnj_d, MATCH_FSGNJ_D, MASK_FSGNJ_D) -DECLARE_INSN(fsgnjn_d, MATCH_FSGNJN_D, MASK_FSGNJN_D) -DECLARE_INSN(fsgnjx_d, MATCH_FSGNJX_D, MASK_FSGNJX_D) -DECLARE_INSN(fmin_d, MATCH_FMIN_D, MASK_FMIN_D) -DECLARE_INSN(fmax_d, MATCH_FMAX_D, MASK_FMAX_D) -DECLARE_INSN(fcvt_s_d, MATCH_FCVT_S_D, MASK_FCVT_S_D) -DECLARE_INSN(fcvt_d_s, MATCH_FCVT_D_S, MASK_FCVT_D_S) -DECLARE_INSN(fsqrt_d, MATCH_FSQRT_D, MASK_FSQRT_D) -DECLARE_INSN(fle_s, MATCH_FLE_S, MASK_FLE_S) -DECLARE_INSN(flt_s, MATCH_FLT_S, MASK_FLT_S) -DECLARE_INSN(feq_s, MATCH_FEQ_S, MASK_FEQ_S) -DECLARE_INSN(fle_d, MATCH_FLE_D, MASK_FLE_D) -DECLARE_INSN(flt_d, MATCH_FLT_D, MASK_FLT_D) -DECLARE_INSN(feq_d, MATCH_FEQ_D, MASK_FEQ_D) -DECLARE_INSN(fcvt_w_s, MATCH_FCVT_W_S, MASK_FCVT_W_S) -DECLARE_INSN(fcvt_wu_s, MATCH_FCVT_WU_S, MASK_FCVT_WU_S) -DECLARE_INSN(fcvt_l_s, MATCH_FCVT_L_S, MASK_FCVT_L_S) -DECLARE_INSN(fcvt_lu_s, MATCH_FCVT_LU_S, MASK_FCVT_LU_S) -DECLARE_INSN(fmv_x_s, MATCH_FMV_X_S, MASK_FMV_X_S) -DECLARE_INSN(fclass_s, MATCH_FCLASS_S, MASK_FCLASS_S) -DECLARE_INSN(fcvt_w_d, MATCH_FCVT_W_D, MASK_FCVT_W_D) -DECLARE_INSN(fcvt_wu_d, MATCH_FCVT_WU_D, MASK_FCVT_WU_D) -DECLARE_INSN(fcvt_l_d, MATCH_FCVT_L_D, MASK_FCVT_L_D) -DECLARE_INSN(fcvt_lu_d, MATCH_FCVT_LU_D, MASK_FCVT_LU_D) -DECLARE_INSN(fmv_x_d, MATCH_FMV_X_D, MASK_FMV_X_D) -DECLARE_INSN(fclass_d, MATCH_FCLASS_D, MASK_FCLASS_D) -DECLARE_INSN(fcvt_s_w, MATCH_FCVT_S_W, MASK_FCVT_S_W) -DECLARE_INSN(fcvt_s_wu, MATCH_FCVT_S_WU, MASK_FCVT_S_WU) -DECLARE_INSN(fcvt_s_l, MATCH_FCVT_S_L, MASK_FCVT_S_L) -DECLARE_INSN(fcvt_s_lu, MATCH_FCVT_S_LU, MASK_FCVT_S_LU) -DECLARE_INSN(fmv_s_x, MATCH_FMV_S_X, MASK_FMV_S_X) -DECLARE_INSN(fcvt_d_w, MATCH_FCVT_D_W, MASK_FCVT_D_W) -DECLARE_INSN(fcvt_d_wu, MATCH_FCVT_D_WU, MASK_FCVT_D_WU) -DECLARE_INSN(fcvt_d_l, MATCH_FCVT_D_L, MASK_FCVT_D_L) -DECLARE_INSN(fcvt_d_lu, MATCH_FCVT_D_LU, MASK_FCVT_D_LU) -DECLARE_INSN(fmv_d_x, MATCH_FMV_D_X, MASK_FMV_D_X) -DECLARE_INSN(flw, MATCH_FLW, MASK_FLW) -DECLARE_INSN(fld, MATCH_FLD, MASK_FLD) -DECLARE_INSN(fsw, MATCH_FSW, MASK_FSW) -DECLARE_INSN(fsd, MATCH_FSD, MASK_FSD) -DECLARE_INSN(fmadd_s, MATCH_FMADD_S, MASK_FMADD_S) -DECLARE_INSN(fmsub_s, MATCH_FMSUB_S, MASK_FMSUB_S) -DECLARE_INSN(fnmsub_s, MATCH_FNMSUB_S, MASK_FNMSUB_S) -DECLARE_INSN(fnmadd_s, MATCH_FNMADD_S, MASK_FNMADD_S) -DECLARE_INSN(fmadd_d, MATCH_FMADD_D, MASK_FMADD_D) -DECLARE_INSN(fmsub_d, MATCH_FMSUB_D, MASK_FMSUB_D) -DECLARE_INSN(fnmsub_d, MATCH_FNMSUB_D, MASK_FNMSUB_D) -DECLARE_INSN(fnmadd_d, MATCH_FNMADD_D, MASK_FNMADD_D) -DECLARE_INSN(c_nop, MATCH_C_NOP, MASK_C_NOP) -DECLARE_INSN(c_addi16sp, MATCH_C_ADDI16SP, MASK_C_ADDI16SP) -DECLARE_INSN(c_jr, MATCH_C_JR, MASK_C_JR) -DECLARE_INSN(c_jalr, MATCH_C_JALR, MASK_C_JALR) -DECLARE_INSN(c_ebreak, MATCH_C_EBREAK, MASK_C_EBREAK) -DECLARE_INSN(c_ld, MATCH_C_LD, MASK_C_LD) -DECLARE_INSN(c_sd, MATCH_C_SD, MASK_C_SD) -DECLARE_INSN(c_addiw, MATCH_C_ADDIW, MASK_C_ADDIW) -DECLARE_INSN(c_ldsp, MATCH_C_LDSP, MASK_C_LDSP) -DECLARE_INSN(c_sdsp, MATCH_C_SDSP, MASK_C_SDSP) -DECLARE_INSN(c_addi4spn, MATCH_C_ADDI4SPN, MASK_C_ADDI4SPN) -DECLARE_INSN(c_fld, MATCH_C_FLD, MASK_C_FLD) -DECLARE_INSN(c_lw, MATCH_C_LW, MASK_C_LW) -DECLARE_INSN(c_flw, MATCH_C_FLW, MASK_C_FLW) -DECLARE_INSN(c_fsd, MATCH_C_FSD, MASK_C_FSD) -DECLARE_INSN(c_sw, MATCH_C_SW, MASK_C_SW) -DECLARE_INSN(c_fsw, MATCH_C_FSW, MASK_C_FSW) -DECLARE_INSN(c_addi, MATCH_C_ADDI, MASK_C_ADDI) -DECLARE_INSN(c_jal, MATCH_C_JAL, MASK_C_JAL) -DECLARE_INSN(c_li, MATCH_C_LI, MASK_C_LI) -DECLARE_INSN(c_lui, MATCH_C_LUI, MASK_C_LUI) -DECLARE_INSN(c_srli, MATCH_C_SRLI, MASK_C_SRLI) -DECLARE_INSN(c_srai, MATCH_C_SRAI, MASK_C_SRAI) -DECLARE_INSN(c_andi, MATCH_C_ANDI, MASK_C_ANDI) -DECLARE_INSN(c_sub, MATCH_C_SUB, MASK_C_SUB) -DECLARE_INSN(c_xor, MATCH_C_XOR, MASK_C_XOR) -DECLARE_INSN(c_or, MATCH_C_OR, MASK_C_OR) -DECLARE_INSN(c_and, MATCH_C_AND, MASK_C_AND) -DECLARE_INSN(c_subw, MATCH_C_SUBW, MASK_C_SUBW) -DECLARE_INSN(c_addw, MATCH_C_ADDW, MASK_C_ADDW) -DECLARE_INSN(c_j, MATCH_C_J, MASK_C_J) -DECLARE_INSN(c_beqz, MATCH_C_BEQZ, MASK_C_BEQZ) -DECLARE_INSN(c_bnez, MATCH_C_BNEZ, MASK_C_BNEZ) -DECLARE_INSN(c_slli, MATCH_C_SLLI, MASK_C_SLLI) -DECLARE_INSN(c_fldsp, MATCH_C_FLDSP, MASK_C_FLDSP) -DECLARE_INSN(c_lwsp, MATCH_C_LWSP, MASK_C_LWSP) -DECLARE_INSN(c_flwsp, MATCH_C_FLWSP, MASK_C_FLWSP) -DECLARE_INSN(c_mv, MATCH_C_MV, MASK_C_MV) -DECLARE_INSN(c_add, MATCH_C_ADD, MASK_C_ADD) -DECLARE_INSN(c_fsdsp, MATCH_C_FSDSP, MASK_C_FSDSP) -DECLARE_INSN(c_swsp, MATCH_C_SWSP, MASK_C_SWSP) -DECLARE_INSN(c_fswsp, MATCH_C_FSWSP, MASK_C_FSWSP) -DECLARE_INSN(custom0, MATCH_CUSTOM0, MASK_CUSTOM0) -DECLARE_INSN(custom0_rs1, MATCH_CUSTOM0_RS1, MASK_CUSTOM0_RS1) -DECLARE_INSN(custom0_rs1_rs2, MATCH_CUSTOM0_RS1_RS2, MASK_CUSTOM0_RS1_RS2) -DECLARE_INSN(custom0_rd, MATCH_CUSTOM0_RD, MASK_CUSTOM0_RD) -DECLARE_INSN(custom0_rd_rs1, MATCH_CUSTOM0_RD_RS1, MASK_CUSTOM0_RD_RS1) -DECLARE_INSN(custom0_rd_rs1_rs2, MATCH_CUSTOM0_RD_RS1_RS2, MASK_CUSTOM0_RD_RS1_RS2) -DECLARE_INSN(custom1, MATCH_CUSTOM1, MASK_CUSTOM1) -DECLARE_INSN(custom1_rs1, MATCH_CUSTOM1_RS1, MASK_CUSTOM1_RS1) -DECLARE_INSN(custom1_rs1_rs2, MATCH_CUSTOM1_RS1_RS2, MASK_CUSTOM1_RS1_RS2) -DECLARE_INSN(custom1_rd, MATCH_CUSTOM1_RD, MASK_CUSTOM1_RD) -DECLARE_INSN(custom1_rd_rs1, MATCH_CUSTOM1_RD_RS1, MASK_CUSTOM1_RD_RS1) -DECLARE_INSN(custom1_rd_rs1_rs2, MATCH_CUSTOM1_RD_RS1_RS2, MASK_CUSTOM1_RD_RS1_RS2) -DECLARE_INSN(custom2, MATCH_CUSTOM2, MASK_CUSTOM2) -DECLARE_INSN(custom2_rs1, MATCH_CUSTOM2_RS1, MASK_CUSTOM2_RS1) -DECLARE_INSN(custom2_rs1_rs2, MATCH_CUSTOM2_RS1_RS2, MASK_CUSTOM2_RS1_RS2) -DECLARE_INSN(custom2_rd, MATCH_CUSTOM2_RD, MASK_CUSTOM2_RD) -DECLARE_INSN(custom2_rd_rs1, MATCH_CUSTOM2_RD_RS1, MASK_CUSTOM2_RD_RS1) -DECLARE_INSN(custom2_rd_rs1_rs2, MATCH_CUSTOM2_RD_RS1_RS2, MASK_CUSTOM2_RD_RS1_RS2) -DECLARE_INSN(custom3, MATCH_CUSTOM3, MASK_CUSTOM3) -DECLARE_INSN(custom3_rs1, MATCH_CUSTOM3_RS1, MASK_CUSTOM3_RS1) -DECLARE_INSN(custom3_rs1_rs2, MATCH_CUSTOM3_RS1_RS2, MASK_CUSTOM3_RS1_RS2) -DECLARE_INSN(custom3_rd, MATCH_CUSTOM3_RD, MASK_CUSTOM3_RD) -DECLARE_INSN(custom3_rd_rs1, MATCH_CUSTOM3_RD_RS1, MASK_CUSTOM3_RD_RS1) -DECLARE_INSN(custom3_rd_rs1_rs2, MATCH_CUSTOM3_RD_RS1_RS2, MASK_CUSTOM3_RD_RS1_RS2) -#endif -#if defined(DECLARE_CSR) -DECLARE_CSR(fflags, CSR_FFLAGS) -DECLARE_CSR(frm, CSR_FRM) -DECLARE_CSR(fcsr, CSR_FCSR) -DECLARE_CSR(cycle, CSR_CYCLE) -DECLARE_CSR(time, CSR_TIME) -DECLARE_CSR(instret, CSR_INSTRET) -DECLARE_CSR(hpmcounter3, CSR_HPMCOUNTER3) -DECLARE_CSR(hpmcounter4, CSR_HPMCOUNTER4) -DECLARE_CSR(hpmcounter5, CSR_HPMCOUNTER5) -DECLARE_CSR(hpmcounter6, CSR_HPMCOUNTER6) -DECLARE_CSR(hpmcounter7, CSR_HPMCOUNTER7) -DECLARE_CSR(hpmcounter8, CSR_HPMCOUNTER8) -DECLARE_CSR(hpmcounter9, CSR_HPMCOUNTER9) -DECLARE_CSR(hpmcounter10, CSR_HPMCOUNTER10) -DECLARE_CSR(hpmcounter11, CSR_HPMCOUNTER11) -DECLARE_CSR(hpmcounter12, CSR_HPMCOUNTER12) -DECLARE_CSR(hpmcounter13, CSR_HPMCOUNTER13) -DECLARE_CSR(hpmcounter14, CSR_HPMCOUNTER14) -DECLARE_CSR(hpmcounter15, CSR_HPMCOUNTER15) -DECLARE_CSR(hpmcounter16, CSR_HPMCOUNTER16) -DECLARE_CSR(hpmcounter17, CSR_HPMCOUNTER17) -DECLARE_CSR(hpmcounter18, CSR_HPMCOUNTER18) -DECLARE_CSR(hpmcounter19, CSR_HPMCOUNTER19) -DECLARE_CSR(hpmcounter20, CSR_HPMCOUNTER20) -DECLARE_CSR(hpmcounter21, CSR_HPMCOUNTER21) -DECLARE_CSR(hpmcounter22, CSR_HPMCOUNTER22) -DECLARE_CSR(hpmcounter23, CSR_HPMCOUNTER23) -DECLARE_CSR(hpmcounter24, CSR_HPMCOUNTER24) -DECLARE_CSR(hpmcounter25, CSR_HPMCOUNTER25) -DECLARE_CSR(hpmcounter26, CSR_HPMCOUNTER26) -DECLARE_CSR(hpmcounter27, CSR_HPMCOUNTER27) -DECLARE_CSR(hpmcounter28, CSR_HPMCOUNTER28) -DECLARE_CSR(hpmcounter29, CSR_HPMCOUNTER29) -DECLARE_CSR(hpmcounter30, CSR_HPMCOUNTER30) -DECLARE_CSR(hpmcounter31, CSR_HPMCOUNTER31) -DECLARE_CSR(sstatus, CSR_SSTATUS) -DECLARE_CSR(sie, CSR_SIE) -DECLARE_CSR(stvec, CSR_STVEC) -DECLARE_CSR(sscratch, CSR_SSCRATCH) -DECLARE_CSR(sepc, CSR_SEPC) -DECLARE_CSR(scause, CSR_SCAUSE) -DECLARE_CSR(sbadaddr, CSR_SBADADDR) -DECLARE_CSR(sip, CSR_SIP) -DECLARE_CSR(sptbr, CSR_SPTBR) -DECLARE_CSR(mstatus, CSR_MSTATUS) -DECLARE_CSR(misa, CSR_MISA) -DECLARE_CSR(medeleg, CSR_MEDELEG) -DECLARE_CSR(mideleg, CSR_MIDELEG) -DECLARE_CSR(mie, CSR_MIE) -DECLARE_CSR(mtvec, CSR_MTVEC) -DECLARE_CSR(mscratch, CSR_MSCRATCH) -DECLARE_CSR(mepc, CSR_MEPC) -DECLARE_CSR(mcause, CSR_MCAUSE) -DECLARE_CSR(mbadaddr, CSR_MBADADDR) -DECLARE_CSR(mip, CSR_MIP) -DECLARE_CSR(tselect, CSR_TSELECT) -DECLARE_CSR(tdata1, CSR_TDATA1) -DECLARE_CSR(tdata2, CSR_TDATA2) -DECLARE_CSR(tdata3, CSR_TDATA3) -DECLARE_CSR(dcsr, CSR_DCSR) -DECLARE_CSR(dpc, CSR_DPC) -DECLARE_CSR(dscratch, CSR_DSCRATCH) -DECLARE_CSR(mcycle, CSR_MCYCLE) -DECLARE_CSR(minstret, CSR_MINSTRET) -DECLARE_CSR(mhpmcounter3, CSR_MHPMCOUNTER3) -DECLARE_CSR(mhpmcounter4, CSR_MHPMCOUNTER4) -DECLARE_CSR(mhpmcounter5, CSR_MHPMCOUNTER5) -DECLARE_CSR(mhpmcounter6, CSR_MHPMCOUNTER6) -DECLARE_CSR(mhpmcounter7, CSR_MHPMCOUNTER7) -DECLARE_CSR(mhpmcounter8, CSR_MHPMCOUNTER8) -DECLARE_CSR(mhpmcounter9, CSR_MHPMCOUNTER9) -DECLARE_CSR(mhpmcounter10, CSR_MHPMCOUNTER10) -DECLARE_CSR(mhpmcounter11, CSR_MHPMCOUNTER11) -DECLARE_CSR(mhpmcounter12, CSR_MHPMCOUNTER12) -DECLARE_CSR(mhpmcounter13, CSR_MHPMCOUNTER13) -DECLARE_CSR(mhpmcounter14, CSR_MHPMCOUNTER14) -DECLARE_CSR(mhpmcounter15, CSR_MHPMCOUNTER15) -DECLARE_CSR(mhpmcounter16, CSR_MHPMCOUNTER16) -DECLARE_CSR(mhpmcounter17, CSR_MHPMCOUNTER17) -DECLARE_CSR(mhpmcounter18, CSR_MHPMCOUNTER18) -DECLARE_CSR(mhpmcounter19, CSR_MHPMCOUNTER19) -DECLARE_CSR(mhpmcounter20, CSR_MHPMCOUNTER20) -DECLARE_CSR(mhpmcounter21, CSR_MHPMCOUNTER21) -DECLARE_CSR(mhpmcounter22, CSR_MHPMCOUNTER22) -DECLARE_CSR(mhpmcounter23, CSR_MHPMCOUNTER23) -DECLARE_CSR(mhpmcounter24, CSR_MHPMCOUNTER24) -DECLARE_CSR(mhpmcounter25, CSR_MHPMCOUNTER25) -DECLARE_CSR(mhpmcounter26, CSR_MHPMCOUNTER26) -DECLARE_CSR(mhpmcounter27, CSR_MHPMCOUNTER27) -DECLARE_CSR(mhpmcounter28, CSR_MHPMCOUNTER28) -DECLARE_CSR(mhpmcounter29, CSR_MHPMCOUNTER29) -DECLARE_CSR(mhpmcounter30, CSR_MHPMCOUNTER30) -DECLARE_CSR(mhpmcounter31, CSR_MHPMCOUNTER31) -DECLARE_CSR(mucounteren, CSR_MUCOUNTEREN) -DECLARE_CSR(mscounteren, CSR_MSCOUNTEREN) -DECLARE_CSR(mhpmevent3, CSR_MHPMEVENT3) -DECLARE_CSR(mhpmevent4, CSR_MHPMEVENT4) -DECLARE_CSR(mhpmevent5, CSR_MHPMEVENT5) -DECLARE_CSR(mhpmevent6, CSR_MHPMEVENT6) -DECLARE_CSR(mhpmevent7, CSR_MHPMEVENT7) -DECLARE_CSR(mhpmevent8, CSR_MHPMEVENT8) -DECLARE_CSR(mhpmevent9, CSR_MHPMEVENT9) -DECLARE_CSR(mhpmevent10, CSR_MHPMEVENT10) -DECLARE_CSR(mhpmevent11, CSR_MHPMEVENT11) -DECLARE_CSR(mhpmevent12, CSR_MHPMEVENT12) -DECLARE_CSR(mhpmevent13, CSR_MHPMEVENT13) -DECLARE_CSR(mhpmevent14, CSR_MHPMEVENT14) -DECLARE_CSR(mhpmevent15, CSR_MHPMEVENT15) -DECLARE_CSR(mhpmevent16, CSR_MHPMEVENT16) -DECLARE_CSR(mhpmevent17, CSR_MHPMEVENT17) -DECLARE_CSR(mhpmevent18, CSR_MHPMEVENT18) -DECLARE_CSR(mhpmevent19, CSR_MHPMEVENT19) -DECLARE_CSR(mhpmevent20, CSR_MHPMEVENT20) -DECLARE_CSR(mhpmevent21, CSR_MHPMEVENT21) -DECLARE_CSR(mhpmevent22, CSR_MHPMEVENT22) -DECLARE_CSR(mhpmevent23, CSR_MHPMEVENT23) -DECLARE_CSR(mhpmevent24, CSR_MHPMEVENT24) -DECLARE_CSR(mhpmevent25, CSR_MHPMEVENT25) -DECLARE_CSR(mhpmevent26, CSR_MHPMEVENT26) -DECLARE_CSR(mhpmevent27, CSR_MHPMEVENT27) -DECLARE_CSR(mhpmevent28, CSR_MHPMEVENT28) -DECLARE_CSR(mhpmevent29, CSR_MHPMEVENT29) -DECLARE_CSR(mhpmevent30, CSR_MHPMEVENT30) -DECLARE_CSR(mhpmevent31, CSR_MHPMEVENT31) -DECLARE_CSR(mvendorid, CSR_MVENDORID) -DECLARE_CSR(marchid, CSR_MARCHID) -DECLARE_CSR(mimpid, CSR_MIMPID) -DECLARE_CSR(mhartid, CSR_MHARTID) -DECLARE_CSR(cycleh, CSR_CYCLEH) -DECLARE_CSR(timeh, CSR_TIMEH) -DECLARE_CSR(instreth, CSR_INSTRETH) -DECLARE_CSR(hpmcounter3h, CSR_HPMCOUNTER3H) -DECLARE_CSR(hpmcounter4h, CSR_HPMCOUNTER4H) -DECLARE_CSR(hpmcounter5h, CSR_HPMCOUNTER5H) -DECLARE_CSR(hpmcounter6h, CSR_HPMCOUNTER6H) -DECLARE_CSR(hpmcounter7h, CSR_HPMCOUNTER7H) -DECLARE_CSR(hpmcounter8h, CSR_HPMCOUNTER8H) -DECLARE_CSR(hpmcounter9h, CSR_HPMCOUNTER9H) -DECLARE_CSR(hpmcounter10h, CSR_HPMCOUNTER10H) -DECLARE_CSR(hpmcounter11h, CSR_HPMCOUNTER11H) -DECLARE_CSR(hpmcounter12h, CSR_HPMCOUNTER12H) -DECLARE_CSR(hpmcounter13h, CSR_HPMCOUNTER13H) -DECLARE_CSR(hpmcounter14h, CSR_HPMCOUNTER14H) -DECLARE_CSR(hpmcounter15h, CSR_HPMCOUNTER15H) -DECLARE_CSR(hpmcounter16h, CSR_HPMCOUNTER16H) -DECLARE_CSR(hpmcounter17h, CSR_HPMCOUNTER17H) -DECLARE_CSR(hpmcounter18h, CSR_HPMCOUNTER18H) -DECLARE_CSR(hpmcounter19h, CSR_HPMCOUNTER19H) -DECLARE_CSR(hpmcounter20h, CSR_HPMCOUNTER20H) -DECLARE_CSR(hpmcounter21h, CSR_HPMCOUNTER21H) -DECLARE_CSR(hpmcounter22h, CSR_HPMCOUNTER22H) -DECLARE_CSR(hpmcounter23h, CSR_HPMCOUNTER23H) -DECLARE_CSR(hpmcounter24h, CSR_HPMCOUNTER24H) -DECLARE_CSR(hpmcounter25h, CSR_HPMCOUNTER25H) -DECLARE_CSR(hpmcounter26h, CSR_HPMCOUNTER26H) -DECLARE_CSR(hpmcounter27h, CSR_HPMCOUNTER27H) -DECLARE_CSR(hpmcounter28h, CSR_HPMCOUNTER28H) -DECLARE_CSR(hpmcounter29h, CSR_HPMCOUNTER29H) -DECLARE_CSR(hpmcounter30h, CSR_HPMCOUNTER30H) -DECLARE_CSR(hpmcounter31h, CSR_HPMCOUNTER31H) -DECLARE_CSR(mcycleh, CSR_MCYCLEH) -DECLARE_CSR(minstreth, CSR_MINSTRETH) -DECLARE_CSR(mhpmcounter3h, CSR_MHPMCOUNTER3H) -DECLARE_CSR(mhpmcounter4h, CSR_MHPMCOUNTER4H) -DECLARE_CSR(mhpmcounter5h, CSR_MHPMCOUNTER5H) -DECLARE_CSR(mhpmcounter6h, CSR_MHPMCOUNTER6H) -DECLARE_CSR(mhpmcounter7h, CSR_MHPMCOUNTER7H) -DECLARE_CSR(mhpmcounter8h, CSR_MHPMCOUNTER8H) -DECLARE_CSR(mhpmcounter9h, CSR_MHPMCOUNTER9H) -DECLARE_CSR(mhpmcounter10h, CSR_MHPMCOUNTER10H) -DECLARE_CSR(mhpmcounter11h, CSR_MHPMCOUNTER11H) -DECLARE_CSR(mhpmcounter12h, CSR_MHPMCOUNTER12H) -DECLARE_CSR(mhpmcounter13h, CSR_MHPMCOUNTER13H) -DECLARE_CSR(mhpmcounter14h, CSR_MHPMCOUNTER14H) -DECLARE_CSR(mhpmcounter15h, CSR_MHPMCOUNTER15H) -DECLARE_CSR(mhpmcounter16h, CSR_MHPMCOUNTER16H) -DECLARE_CSR(mhpmcounter17h, CSR_MHPMCOUNTER17H) -DECLARE_CSR(mhpmcounter18h, CSR_MHPMCOUNTER18H) -DECLARE_CSR(mhpmcounter19h, CSR_MHPMCOUNTER19H) -DECLARE_CSR(mhpmcounter20h, CSR_MHPMCOUNTER20H) -DECLARE_CSR(mhpmcounter21h, CSR_MHPMCOUNTER21H) -DECLARE_CSR(mhpmcounter22h, CSR_MHPMCOUNTER22H) -DECLARE_CSR(mhpmcounter23h, CSR_MHPMCOUNTER23H) -DECLARE_CSR(mhpmcounter24h, CSR_MHPMCOUNTER24H) -DECLARE_CSR(mhpmcounter25h, CSR_MHPMCOUNTER25H) -DECLARE_CSR(mhpmcounter26h, CSR_MHPMCOUNTER26H) -DECLARE_CSR(mhpmcounter27h, CSR_MHPMCOUNTER27H) -DECLARE_CSR(mhpmcounter28h, CSR_MHPMCOUNTER28H) -DECLARE_CSR(mhpmcounter29h, CSR_MHPMCOUNTER29H) -DECLARE_CSR(mhpmcounter30h, CSR_MHPMCOUNTER30H) -DECLARE_CSR(mhpmcounter31h, CSR_MHPMCOUNTER31H) -#endif -#if defined(DECLARE_CAUSE) -DECLARE_CAUSE("misaligned fetch", CAUSE_MISALIGNED_FETCH) -DECLARE_CAUSE("fault fetch", CAUSE_FAULT_FETCH) -DECLARE_CAUSE("illegal instruction", CAUSE_ILLEGAL_INSTRUCTION) -DECLARE_CAUSE("breakpoint", CAUSE_BREAKPOINT) -DECLARE_CAUSE("misaligned load", CAUSE_MISALIGNED_LOAD) -DECLARE_CAUSE("fault load", CAUSE_FAULT_LOAD) -DECLARE_CAUSE("misaligned store", CAUSE_MISALIGNED_STORE) -DECLARE_CAUSE("fault store", CAUSE_FAULT_STORE) -DECLARE_CAUSE("user_ecall", CAUSE_USER_ECALL) -DECLARE_CAUSE("supervisor_ecall", CAUSE_SUPERVISOR_ECALL) -DECLARE_CAUSE("hypervisor_ecall", CAUSE_HYPERVISOR_ECALL) -DECLARE_CAUSE("machine_ecall", CAUSE_MACHINE_ECALL) -#endif +/* + * PLIC External Interrupt Numbers + */ +enum plic_irq { + IRQN_NO_INTERRUPT = 0, /*!< The non-existent interrupt */ + IRQN_SPI0_INTERRUPT = 1, /*!< SPI0 interrupt */ + IRQN_SPI1_INTERRUPT = 2, /*!< SPI1 interrupt */ + IRQN_SPI_SLAVE_INTERRUPT = 3, /*!< SPI_SLAVE interrupt */ + IRQN_SPI3_INTERRUPT = 4, /*!< SPI3 interrupt */ + IRQN_I2S0_INTERRUPT = 5, /*!< I2S0 interrupt */ + IRQN_I2S1_INTERRUPT = 6, /*!< I2S1 interrupt */ + IRQN_I2S2_INTERRUPT = 7, /*!< I2S2 interrupt */ + IRQN_I2C0_INTERRUPT = 8, /*!< I2C0 interrupt */ + IRQN_I2C1_INTERRUPT = 9, /*!< I2C1 interrupt */ + IRQN_I2C2_INTERRUPT = 10, /*!< I2C2 interrupt */ + IRQN_UART1_INTERRUPT = 11, /*!< UART1 interrupt */ + IRQN_UART2_INTERRUPT = 12, /*!< UART2 interrupt */ + IRQN_UART3_INTERRUPT = 13, /*!< UART3 interrupt */ + IRQN_TIMER0A_INTERRUPT = 14, /*!< TIMER0 channel 0 or 1 interrupt */ + IRQN_TIMER0B_INTERRUPT = 15, /*!< TIMER0 channel 2 or 3 interrupt */ + IRQN_TIMER1A_INTERRUPT = 16, /*!< TIMER1 channel 0 or 1 interrupt */ + IRQN_TIMER1B_INTERRUPT = 17, /*!< TIMER1 channel 2 or 3 interrupt */ + IRQN_TIMER2A_INTERRUPT = 18, /*!< TIMER2 channel 0 or 1 interrupt */ + IRQN_TIMER2B_INTERRUPT = 19, /*!< TIMER2 channel 2 or 3 interrupt */ + IRQN_RTC_INTERRUPT = 20, /*!< RTC tick and alarm interrupt */ + IRQN_WDT0_INTERRUPT = 21, /*!< Watching dog timer0 interrupt */ + IRQN_WDT1_INTERRUPT = 22, /*!< Watching dog timer1 interrupt */ + IRQN_APB_GPIO_INTERRUPT = 23, /*!< APB GPIO interrupt */ + IRQN_DVP_INTERRUPT = 24, /*!< Digital video port interrupt */ + IRQN_AI_INTERRUPT = 25, /*!< AI accelerator interrupt */ + IRQN_FFT_INTERRUPT = 26, /*!< FFT accelerator interrupt */ + IRQN_DMA0_INTERRUPT = 27, /*!< DMA channel0 interrupt */ + IRQN_DMA1_INTERRUPT = 28, /*!< DMA channel1 interrupt */ + IRQN_DMA2_INTERRUPT = 29, /*!< DMA channel2 interrupt */ + IRQN_DMA3_INTERRUPT = 30, /*!< DMA channel3 interrupt */ + IRQN_DMA4_INTERRUPT = 31, /*!< DMA channel4 interrupt */ + IRQN_DMA5_INTERRUPT = 32, /*!< DMA channel5 interrupt */ + IRQN_UARTHS_INTERRUPT = 33, /*!< Hi-speed UART0 interrupt */ + IRQN_GPIOHS0_INTERRUPT = 34, /*!< Hi-speed GPIO0 interrupt */ + IRQN_GPIOHS1_INTERRUPT = 35, /*!< Hi-speed GPIO1 interrupt */ + IRQN_GPIOHS2_INTERRUPT = 36, /*!< Hi-speed GPIO2 interrupt */ + IRQN_GPIOHS3_INTERRUPT = 37, /*!< Hi-speed GPIO3 interrupt */ + IRQN_GPIOHS4_INTERRUPT = 38, /*!< Hi-speed GPIO4 interrupt */ + IRQN_GPIOHS5_INTERRUPT = 39, /*!< Hi-speed GPIO5 interrupt */ + IRQN_GPIOHS6_INTERRUPT = 40, /*!< Hi-speed GPIO6 interrupt */ + IRQN_GPIOHS7_INTERRUPT = 41, /*!< Hi-speed GPIO7 interrupt */ + IRQN_GPIOHS8_INTERRUPT = 42, /*!< Hi-speed GPIO8 interrupt */ + IRQN_GPIOHS9_INTERRUPT = 43, /*!< Hi-speed GPIO9 interrupt */ + IRQN_GPIOHS10_INTERRUPT = 44, /*!< Hi-speed GPIO10 interrupt */ + IRQN_GPIOHS11_INTERRUPT = 45, /*!< Hi-speed GPIO11 interrupt */ + IRQN_GPIOHS12_INTERRUPT = 46, /*!< Hi-speed GPIO12 interrupt */ + IRQN_GPIOHS13_INTERRUPT = 47, /*!< Hi-speed GPIO13 interrupt */ + IRQN_GPIOHS14_INTERRUPT = 48, /*!< Hi-speed GPIO14 interrupt */ + IRQN_GPIOHS15_INTERRUPT = 49, /*!< Hi-speed GPIO15 interrupt */ + IRQN_GPIOHS16_INTERRUPT = 50, /*!< Hi-speed GPIO16 interrupt */ + IRQN_GPIOHS17_INTERRUPT = 51, /*!< Hi-speed GPIO17 interrupt */ + IRQN_GPIOHS18_INTERRUPT = 52, /*!< Hi-speed GPIO18 interrupt */ + IRQN_GPIOHS19_INTERRUPT = 53, /*!< Hi-speed GPIO19 interrupt */ + IRQN_GPIOHS20_INTERRUPT = 54, /*!< Hi-speed GPIO20 interrupt */ + IRQN_GPIOHS21_INTERRUPT = 55, /*!< Hi-speed GPIO21 interrupt */ + IRQN_GPIOHS22_INTERRUPT = 56, /*!< Hi-speed GPIO22 interrupt */ + IRQN_GPIOHS23_INTERRUPT = 57, /*!< Hi-speed GPIO23 interrupt */ + IRQN_GPIOHS24_INTERRUPT = 58, /*!< Hi-speed GPIO24 interrupt */ + IRQN_GPIOHS25_INTERRUPT = 59, /*!< Hi-speed GPIO25 interrupt */ + IRQN_GPIOHS26_INTERRUPT = 60, /*!< Hi-speed GPIO26 interrupt */ + IRQN_GPIOHS27_INTERRUPT = 61, /*!< Hi-speed GPIO27 interrupt */ + IRQN_GPIOHS28_INTERRUPT = 62, /*!< Hi-speed GPIO28 interrupt */ + IRQN_GPIOHS29_INTERRUPT = 63, /*!< Hi-speed GPIO29 interrupt */ + IRQN_GPIOHS30_INTERRUPT = 64, /*!< Hi-speed GPIO30 interrupt */ + IRQN_GPIOHS31_INTERRUPT = 65, /*!< Hi-speed GPIO31 interrupt */ + IRQN_MAX +}; + +/* IRQ number settings */ +#define PLIC_NUM_SOURCES (IRQN_MAX - 1) +#define PLIC_NUM_PRIORITIES (7) -#endif /* if 0 */ +#endif /* _PLATFORM_H_ */ diff --git a/platform/kendryte/k210/sysctl.c b/platform/kendryte/k210/sysctl.c index c19859d3ec2..3e855a58833 100644 --- a/platform/kendryte/k210/sysctl.c +++ b/platform/kendryte/k210/sysctl.c @@ -973,10 +973,12 @@ u32 sysctl_pll_get_freq(sysctl_pll_t pll) /* * Get final PLL output freq * FOUT = FIN / NR * NF / OD + * = (FIN * NF) / (NR * OD) */ - return (double)freq_in / (double)nr * (double)nf / (double)od; + return ((u64)freq_in * (u64)nf) / ((u64)nr * (u64)od); } +#if 0 static u32 sysctl_pll_source_set_freq(sysctl_pll_t pll, sysctl_clock_source_t source, u32 freq) { @@ -1229,6 +1231,7 @@ static u32 sysctl_pll_source_set_freq(sysctl_pll_t pll, return sysctl_pll_get_freq(pll); } +#endif u32 sysctl_clock_get_freq(sysctl_clock_t clock) { @@ -1683,6 +1686,7 @@ void sysctl_set_power_mode(sysctl_power_bank_t power_bank, sysctl_io_power_mode_ *((u32 *)(&sysctl->power_sel)) &= ~(1 << power_bank); } +#if 0 u32 sysctl_pll_set_freq(sysctl_pll_t pll, u32 pll_freq) { u32 result; @@ -1755,6 +1759,7 @@ u32 sysctl_cpu_set_freq(u32 freq) return sysctl_pll_set_freq(SYSCTL_PLL0, (sysctl->clk_sel0.aclk_divider_sel + 1) * 2 * freq); } +#endif void sysctl_enable_irq(void) { diff --git a/platform/kendryte/k210/sysctl.h b/platform/kendryte/k210/sysctl.h index 1fba1c5b318..09d81aeca8d 100644 --- a/platform/kendryte/k210/sysctl.h +++ b/platform/kendryte/k210/sysctl.h @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef _SYSCTL_H_ -#define _SYSCTL_H_ +#ifndef _K210_SYSCTL_H_ +#define _K210_SYSCTL_H_ #include #include "platform.h" @@ -942,4 +942,4 @@ u64 sysctl_get_time_us(void); void sysctl_usleep(u64 usec); -#endif /* _SYSCTL_H_ */ +#endif /* _K210_SYSCTL_H_ */ diff --git a/platform/kendryte/k210/uarths.c b/platform/kendryte/k210/uarths.c index 1d07ad07f95..6551de76e37 100644 --- a/platform/kendryte/k210/uarths.c +++ b/platform/kendryte/k210/uarths.c @@ -31,9 +31,9 @@ void uarths_init(u32 baud_rate, enum uarths_stopbit stopbit) uarths->rxctrl.rxen = 1; uarths->txctrl.txcnt = 0; uarths->rxctrl.rxcnt = 0; - uarths->ip.txwm = 0; + uarths->ip.txwm = 1; uarths->ip.rxwm = 0; - uarths->ie.txwm = 0; + uarths->ie.txwm = 1; uarths->ie.rxwm = 0; } diff --git a/platform/kendryte/k210/uarths.h b/platform/kendryte/k210/uarths.h index ab539cdf874..dd0433cf7cc 100644 --- a/platform/kendryte/k210/uarths.h +++ b/platform/kendryte/k210/uarths.h @@ -41,11 +41,13 @@ * | 0x018 | div | Baud rate divisor | */ -#ifndef _UARTHS_H_ -#define _UARTHS_H_ +#ifndef _K210_UARTHS_H_ +#define _K210_UARTHS_H_ #include -#include "platform.h" + +/* Base register address */ +#define UARTHS_BASE_ADDR (0x38000000U) /* Register address offsets */ #define UARTHS_REG_TXFIFO 0x00 @@ -152,12 +154,6 @@ struct uarths { struct uarths_div div; } __attribute__((packed, aligned(4))); -enum uarths_interrupt_mode { - UARTHS_SEND = 1, - UARTHS_RECEIVE = 2, - UARTHS_SEND_RECEIVE = 3, -}; - enum uarths_stopbit { UARTHS_STOP_1, UARTHS_STOP_2 @@ -167,4 +163,4 @@ void uarths_init(u32 baud_rate, enum uarths_stopbit stopbit); void uarths_putc(char c); char uarths_getc(void); -#endif /* _UARTHS_H_ */ +#endif /* _K210_UARTHS_H_ */ From 4fb23c49ebbb012955ba7128d1dc742adb8d85b5 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Fri, 21 Dec 2018 16:35:33 +0900 Subject: [PATCH 0015/1765] Fiw comment typo Signed-off-by: Damien Le Moal --- firmware/fw_common.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/fw_common.S b/firmware/fw_common.S index afe14a1bc81..d7074f8bc77 100644 --- a/firmware/fw_common.S +++ b/firmware/fw_common.S @@ -129,7 +129,7 @@ _start_warm: /* set MSIE bit to receive IPI */ li a2, MIP_MSIP csrw mie, a2 - /* HART ID should be withing expected limit */ + /* HART ID should be within expected limit */ csrr a6, mhartid li a5, PLAT_HART_COUNT bge a6, a5, _start_hang From 426adf9f6025fe70470476166db63ea7c0c1514b Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Fri, 21 Dec 2018 16:44:53 +0900 Subject: [PATCH 0016/1765] Cleanup and rename sbi_hart_boot_next() Cleanup sbi_hart_boot_nexti() code, adding messages for clarity and rename the function to sbi_hart_switch_mode() to reflect what the function actually does. Signed-off-by: Damien Le Moal --- include/sbi/sbi_hart.h | 8 ++++---- lib/sbi_hart.c | 35 +++++++++++++++++++++++++---------- lib/sbi_init.c | 8 ++++---- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index 90161f0be69..e369779d869 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -20,10 +20,10 @@ void sbi_hart_pmp_dump(struct sbi_scratch *scratch); void __attribute__((noreturn)) sbi_hart_hang(void); -void __attribute__((noreturn)) sbi_hart_boot_next(unsigned long arg0, - unsigned long arg1, - unsigned long next_addr, - unsigned long next_mode); +void __attribute__((noreturn)) sbi_hart_switch_mode(unsigned long arg0, + unsigned long arg1, + unsigned long next_addr, + unsigned long next_mode); void sbi_hart_mark_available(u32 hartid); diff --git a/lib/sbi_hart.c b/lib/sbi_hart.c index 12c5c55ba2e..32dcfe41d1c 100644 --- a/lib/sbi_hart.c +++ b/lib/sbi_hart.c @@ -205,37 +205,52 @@ void __attribute__((noreturn)) sbi_hart_hang(void) __builtin_unreachable(); } -void __attribute__((noreturn)) sbi_hart_boot_next(unsigned long arg0, - unsigned long arg1, - unsigned long next_addr, - unsigned long next_mode) +void __attribute__((noreturn)) sbi_hart_switch_mode(unsigned long arg0, + unsigned long arg1, + unsigned long next_addr, + unsigned long next_mode) { unsigned long val; - - if (next_mode != PRV_S && next_mode != PRV_M && next_mode != PRV_U) - sbi_hart_hang(); - if (next_mode == PRV_S && !misa_extension('S')) - sbi_hart_hang(); - if (next_mode == PRV_U && !misa_extension('U')) + char mode = 'M'; + + switch (next_mode) { + case PRV_M: + break; + case PRV_S: + if (!misa_extension('S')) + sbi_hart_hang(); + break; + case PRV_U: + if (!misa_extension('U')) + sbi_hart_hang(); + break; + default: + sbi_printf("\nTrying to switch to unsupported mode\n"); sbi_hart_hang(); + } val = csr_read(mstatus); val = INSERT_FIELD(val, MSTATUS_MPP, next_mode); val = INSERT_FIELD(val, MSTATUS_MPIE, 0); + csr_write(mstatus, val); csr_write(mepc, next_addr); if (next_mode == PRV_S) { + mode = 'S'; csr_write(stvec, next_addr); csr_write(sscratch, 0); csr_write(sie, 0); csr_write(satp, 0); } else if (next_mode == PRV_U) { + mode = 'U'; csr_write(utvec, next_addr); csr_write(uscratch, 0); csr_write(uie, 0); } + sbi_printf("\nSwitching to %c-mode...\n\n", mode); + register unsigned long a0 asm ("a0") = arg0; register unsigned long a1 asm ("a1") = arg1; __asm__ __volatile__ ("mret" : : "r" (a0), "r" (a1)); diff --git a/lib/sbi_init.c b/lib/sbi_init.c index 72f2c19b233..f8451d18a63 100644 --- a/lib/sbi_init.c +++ b/lib/sbi_init.c @@ -111,8 +111,8 @@ static void __attribute__((noreturn)) init_coldboot(struct sbi_scratch *scratch, if (!sbi_platform_has_hart_hotplug(plat)) sbi_hart_wake_coldboot_harts(scratch, hartid); - sbi_hart_boot_next(hartid, scratch->next_arg1, - scratch->next_addr, scratch->next_mode); + sbi_hart_switch_mode(hartid, scratch->next_arg1, + scratch->next_addr, scratch->next_mode); } static void __attribute__((noreturn)) init_warmboot(struct sbi_scratch *scratch, @@ -154,8 +154,8 @@ static void __attribute__((noreturn)) init_warmboot(struct sbi_scratch *scratch, /* TODO: To be implemented in-future. */ sbi_hart_hang(); else - sbi_hart_boot_next(hartid, scratch->next_arg1, - scratch->next_addr, scratch->next_mode); + sbi_hart_switch_mode(hartid, scratch->next_arg1, + scratch->next_addr, scratch->next_mode); } static atomic_t coldboot_lottery = ATOMIC_INITIALIZER(0); From 5563a0335421c3e1d69dc62a1b58675ddf3d1e5b Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Fri, 21 Dec 2018 17:06:59 +0900 Subject: [PATCH 0017/1765] Introduce sbi_current_hartid() Use this helper instead of hardcoding csr_read(mhartid). Signed-off-by: Damien Le Moal --- include/sbi/sbi_hart.h | 2 ++ lib/sbi_hart.c | 13 +++++++++++-- lib/sbi_init.c | 2 +- lib/sbi_trap.c | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index e369779d869..70416430da9 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -38,4 +38,6 @@ void sbi_hart_wait_for_coldboot(struct sbi_scratch *scratch, u32 hartid); void sbi_hart_wake_coldboot_harts(struct sbi_scratch *scratch, u32 hartid); +u32 sbi_current_hartid(void); + #endif diff --git a/lib/sbi_hart.c b/lib/sbi_hart.c index 32dcfe41d1c..09739b922a6 100644 --- a/lib/sbi_hart.c +++ b/lib/sbi_hart.c @@ -17,6 +17,14 @@ #include #include +/** + * Return HART ID of the caller. + */ +unsigned int sbi_current_hartid() +{ + return (u32)csr_read(mhartid); +} + static void mstatus_init(struct sbi_scratch *scratch, u32 hartid) { struct sbi_platform *plat = sbi_platform_ptr(scratch); @@ -198,7 +206,7 @@ int sbi_hart_init(struct sbi_scratch *scratch, u32 hartid) void __attribute__((noreturn)) sbi_hart_hang(void) { - sbi_printf("\nHang !!\n"); + sbi_printf("\nHART %u Hang !!\n\n", sbi_current_hartid()); while (1) wfi(); @@ -249,7 +257,8 @@ void __attribute__((noreturn)) sbi_hart_switch_mode(unsigned long arg0, csr_write(uie, 0); } - sbi_printf("\nSwitching to %c-mode...\n\n", mode); + sbi_printf("HART %u switching to %c-mode...\n\n", + sbi_current_hartid(), mode); register unsigned long a0 asm ("a0") = arg0; register unsigned long a1 asm ("a1") = arg1; diff --git a/lib/sbi_init.c b/lib/sbi_init.c index f8451d18a63..da78a7efe7a 100644 --- a/lib/sbi_init.c +++ b/lib/sbi_init.c @@ -163,7 +163,7 @@ static atomic_t coldboot_lottery = ATOMIC_INITIALIZER(0); void __attribute__((noreturn)) sbi_init(struct sbi_scratch *scratch) { bool coldboot = FALSE; - u32 hartid = csr_read(mhartid); + u32 hartid = sbi_current_hartid(); if (atomic_add_return(&coldboot_lottery, 1) == 1) coldboot = TRUE; diff --git a/lib/sbi_trap.c b/lib/sbi_trap.c index f9c70a63fe9..284bb74f009 100644 --- a/lib/sbi_trap.c +++ b/lib/sbi_trap.c @@ -68,7 +68,7 @@ void sbi_trap_handler(struct sbi_trap_regs *regs, { int rc; const char *msg; - u32 hartid = csr_read(mhartid); + u32 hartid = sbi_current_hartid(); ulong mcause = csr_read(mcause); if (mcause & (1UL << (__riscv_xlen - 1))) { From 07ee5f2e328b7ee3ed57b51f98f2765ae1701a99 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Fri, 21 Dec 2018 17:20:56 +0900 Subject: [PATCH 0018/1765] Kendryte-k210: Remove unnecessary asm functions Use functions defined in sbi/riscv_asm.h. Signed-off-by: Damien Le Moal --- platform/kendryte/k210/platform.h | 37 +++---------------------------- platform/kendryte/k210/sysctl.c | 14 ++++++------ 2 files changed, 10 insertions(+), 41 deletions(-) diff --git a/platform/kendryte/k210/platform.h b/platform/kendryte/k210/platform.h index 14a4bbdfba4..6b520cf7b15 100644 --- a/platform/kendryte/k210/platform.h +++ b/platform/kendryte/k210/platform.h @@ -16,6 +16,8 @@ #ifndef _PLATFORM_H_ #define _PLATFORM_H_ +#include + /* Register base address */ /* Under Coreplex */ @@ -83,40 +85,7 @@ #define SPI1_BASE_ADDR (0x53000000U) #define SPI3_BASE_ADDR (0x54000000U) -#define read_csr(reg) ({ unsigned long __tmp; \ - asm volatile ("csrr %0, " #reg : "=r"(__tmp)); \ - __tmp; }) - -#define write_csr(reg, val) ({ \ - if (__builtin_constant_p(val) && (unsigned long)(val) < 32) \ - asm volatile ("csrw " #reg ", %0" :: "i"(val)); \ - else \ - asm volatile ("csrw " #reg ", %0" :: "r"(val)); }) - -#define swap_csr(reg, val) ({ unsigned long __tmp; \ - if (__builtin_constant_p(val) && (unsigned long)(val) < 32) \ - asm volatile ("csrrw %0, " #reg ", %1" : "=r"(__tmp) : "i"(val)); \ - else \ - asm volatile ("csrrw %0, " #reg ", %1" : "=r"(__tmp) : "r"(val)); \ - __tmp; }) - -#define set_csr(reg, bit) ({ unsigned long __tmp; \ - if (__builtin_constant_p(bit) && (unsigned long)(bit) < 32) \ - asm volatile ("csrrs %0, " #reg ", %1" : "=r"(__tmp) : "i"(bit)); \ - else \ - asm volatile ("csrrs %0, " #reg ", %1" : "=r"(__tmp) : "r"(bit)); \ - __tmp; }) - -#define clear_csr(reg, bit) ({ unsigned long __tmp; \ - if (__builtin_constant_p(bit) && (unsigned long)(bit) < 32) \ - asm volatile ("csrrc %0, " #reg ", %1" : "=r"(__tmp) : "i"(bit)); \ - else \ - asm volatile ("csrrc %0, " #reg ", %1" : "=r"(__tmp) : "r"(bit)); \ - __tmp; }) - -#define read_time() read_csr(mtime) -#define read_cycle() read_csr(mcycle) -#define current_coreid() read_csr(mhartid) +#define read_cycle() csr_read(mcycle) /* * PLIC External Interrupt Numbers diff --git a/platform/kendryte/k210/sysctl.c b/platform/kendryte/k210/sysctl.c index 3e855a58833..8039f6e7d06 100644 --- a/platform/kendryte/k210/sysctl.c +++ b/platform/kendryte/k210/sysctl.c @@ -1763,14 +1763,14 @@ u32 sysctl_cpu_set_freq(u32 freq) void sysctl_enable_irq(void) { - set_csr(mie, MIP_MEIP); - set_csr(mstatus, MSTATUS_MIE); + csr_read_set(mie, MIP_MEIP); + csr_read_set(mstatus, MSTATUS_MIE); } void sysctl_disable_irq(void) { - clear_csr(mie, MIP_MEIP); - clear_csr(mstatus, MSTATUS_MIE); + csr_read_clear(mie, MIP_MEIP); + csr_read_clear(mstatus, MSTATUS_MIE); } u64 sysctl_get_time_us(void) @@ -1782,8 +1782,8 @@ u64 sysctl_get_time_us(void) void sysctl_usleep(u64 usec) { - u64 nop_all = usec * sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 1000000UL; - u64 cycle = read_cycle(); + u64 nop_all = usec * sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 1000000UL; + u64 cycle = read_cycle(); - while (read_cycle() - cycle < nop_all); + while (read_cycle() - cycle < nop_all); } From e1e8f1813080958ed3547e0cd03f940859f20a60 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Fri, 21 Dec 2018 18:12:58 +0900 Subject: [PATCH 0019/1765] console: protect output with a spinlock Avoid getting messages from multiple harts mingled into garbage text with a spinlock serializing calls to sbi_puts() and sbi_printf(). Signed-off-by: Damien Le Moal --- lib/sbi_console.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/sbi_console.c b/lib/sbi_console.c index 3d17340a6f1..6923b9a7247 100644 --- a/lib/sbi_console.c +++ b/lib/sbi_console.c @@ -9,8 +9,10 @@ #include #include +#include static struct sbi_platform *console_plat = NULL; +static spinlock_t console_out_lock = SPIN_LOCK_INITIALIZER; bool sbi_isprintable(char c) { @@ -38,28 +40,24 @@ void sbi_putc(char ch) void sbi_puts(const char *str) { + spin_lock(&console_out_lock); while (*str) { sbi_putc(*str); str++; } + spin_unlock(&console_out_lock); } void sbi_gets(char *s, int maxwidth, char endchar) { - char *retval; - char ch; - retval = s; - ch = sbi_getc(); - while (ch != endchar && maxwidth > 0) { + char ch, *retval = s; + + while ((ch = sbi_getc()) != endchar && maxwidth > 1) { *retval = ch; retval++; maxwidth--; - if (maxwidth == 0) - break; - ch = sbi_getc(); } *retval = '\0'; - return; } #define PAD_RIGHT 1 @@ -360,9 +358,13 @@ int sbi_printf(const char *format, ...) { va_list args; int retval; + + spin_lock(&console_out_lock); va_start(args, format); retval = print(NULL, NULL, format, args); va_end(args); + spin_unlock(&console_out_lock); + return retval; } From 1bfa2445059a4248f82f097a94e4746b5adf2137 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 21 Dec 2018 14:06:17 +0530 Subject: [PATCH 0020/1765] lib: Fix delegate_traps() for Linux boot commit d403c70fb11fb55042ca3cef0dbe399ed87cc79b breaks Linux booting because of fewer exceptions delegated to S-mode. This patch fixes Linux booting by having all required exceptions delegated to S-mode. Signed-off-by: Anup Patel --- lib/sbi_hart.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/sbi_hart.c b/lib/sbi_hart.c index 09739b922a6..fae82c9f46c 100644 --- a/lib/sbi_hart.c +++ b/lib/sbi_hart.c @@ -95,7 +95,10 @@ static int delegate_traps(u32 hartid) /* Send M-mode interrupts and most exceptions to S-mode */ interrupts = MIP_SSIP | MIP_STIP | MIP_SEIP; exceptions = (1U << CAUSE_MISALIGNED_FETCH) | + (1U << CAUSE_FETCH_PAGE_FAULT) | (1U << CAUSE_BREAKPOINT) | + (1U << CAUSE_LOAD_PAGE_FAULT) | + (1U << CAUSE_STORE_PAGE_FAULT) | (1U << CAUSE_USER_ECALL); } From a18913200a34c6da44c634578214db7830cdd036 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 21 Dec 2018 14:12:10 +0530 Subject: [PATCH 0021/1765] lib: Remove prints from sbi_hart_switch_mode() The sbi_hart_switch_mode() will be used by CPU hotplug. This means if we have prints in sbi_hart_switch_mode() then these prints will mix with Linux prints. Being a runtime firmware, we should be verbose only at coldboot time and error situations. Signed-off-by: Anup Patel --- lib/sbi_hart.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/sbi_hart.c b/lib/sbi_hart.c index fae82c9f46c..01362dd73f3 100644 --- a/lib/sbi_hart.c +++ b/lib/sbi_hart.c @@ -209,7 +209,7 @@ int sbi_hart_init(struct sbi_scratch *scratch, u32 hartid) void __attribute__((noreturn)) sbi_hart_hang(void) { - sbi_printf("\nHART %u Hang !!\n\n", sbi_current_hartid()); + sbi_printf("\nHART%u Hang !!\n\n", sbi_current_hartid()); while (1) wfi(); @@ -222,7 +222,6 @@ void __attribute__((noreturn)) sbi_hart_switch_mode(unsigned long arg0, unsigned long next_mode) { unsigned long val; - char mode = 'M'; switch (next_mode) { case PRV_M: @@ -236,7 +235,6 @@ void __attribute__((noreturn)) sbi_hart_switch_mode(unsigned long arg0, sbi_hart_hang(); break; default: - sbi_printf("\nTrying to switch to unsupported mode\n"); sbi_hart_hang(); } @@ -248,21 +246,16 @@ void __attribute__((noreturn)) sbi_hart_switch_mode(unsigned long arg0, csr_write(mepc, next_addr); if (next_mode == PRV_S) { - mode = 'S'; csr_write(stvec, next_addr); csr_write(sscratch, 0); csr_write(sie, 0); csr_write(satp, 0); } else if (next_mode == PRV_U) { - mode = 'U'; csr_write(utvec, next_addr); csr_write(uscratch, 0); csr_write(uie, 0); } - sbi_printf("HART %u switching to %c-mode...\n\n", - sbi_current_hartid(), mode); - register unsigned long a0 asm ("a0") = arg0; register unsigned long a1 asm ("a1") = arg1; __asm__ __volatile__ ("mret" : : "r" (a0), "r" (a1)); From 4e15d79419a63c8bd08045fab8f15d2daa3bb353 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 21 Dec 2018 14:45:14 +0530 Subject: [PATCH 0022/1765] Revert "Fix FDT relocation" This patch reverts "Fix FDT relocation" because it breaks fw_jump firmware. Signed-off-by: Anup Patel --- firmware/fw_common.S | 2 -- 1 file changed, 2 deletions(-) diff --git a/firmware/fw_common.S b/firmware/fw_common.S index d7074f8bc77..b5e1f904558 100644 --- a/firmware/fw_common.S +++ b/firmware/fw_common.S @@ -41,7 +41,6 @@ _bss_zero: add a1, t1, zero _prev_arg1_override_done: -#ifdef FW_PAYLOAD_FDT_ADDR /* * Relocate Flatened Device Tree (FDT) * source FDT address = previous arg1 @@ -100,7 +99,6 @@ _fdt_reloc_again: add t1, t1, __SIZEOF_POINTER__ blt t1, t2, _fdt_reloc_again _fdt_reloc_done: -#endif /* Update boot hart flag */ la a4, _boot_hart_done From ef5f4e149c9f6f354d48463f30f7bf0f759d8028 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 21 Dec 2018 15:05:59 +0530 Subject: [PATCH 0023/1765] firmware: Remove redundant write to mideleg and medeleg The mideleg and medeleg are already programmed in delegate_traps() so no need to set it here. Any CSR setup in our reference firmware becomes a requirement for bootloader linking to libsbi.a so we should have minimum possible CSR setup in our reference firmware. Signed-off-by: Anup Patel --- firmware/fw_common.S | 2 -- 1 file changed, 2 deletions(-) diff --git a/firmware/fw_common.S b/firmware/fw_common.S index b5e1f904558..198aa0b9925 100644 --- a/firmware/fw_common.S +++ b/firmware/fw_common.S @@ -119,8 +119,6 @@ _wait_for_boot_hart: _start_warm: /* Disable and clear all interrupts */ - csrw mideleg, zero - csrw medeleg, zero csrw mie, zero csrw mip, zero From db6c1fe78bebc103670becba39e1c34bcdc48185 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 21 Dec 2018 15:32:28 +0530 Subject: [PATCH 0024/1765] platform: kendryte/k210: Don't include math.h The math.h is not required anymore and it also gives compile error for certain toolchains hence thsi patch removes math.h include from kendryte/k210/sysctl.c. Signed-off-by: Anup Patel --- platform/kendryte/k210/sysctl.c | 1 - 1 file changed, 1 deletion(-) diff --git a/platform/kendryte/k210/sysctl.c b/platform/kendryte/k210/sysctl.c index 8039f6e7d06..90aa0e2355e 100644 --- a/platform/kendryte/k210/sysctl.c +++ b/platform/kendryte/k210/sysctl.c @@ -13,7 +13,6 @@ * limitations under the License. */ #include -#include #include "sysctl.h" #define SYSCTRL_CLOCK_FREQ_IN0 (26000000UL) From 27332e63faaf6d3220a9d56bcfb280921114f012 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Fri, 21 Dec 2018 19:19:54 +0900 Subject: [PATCH 0025/1765] Introduce HAS_MFAULTS_DELEGATION feature Conditionnally delegate page fault exceptions from M mode to S mode based on the platform features. Signed-off-by: Damien Le Moal --- include/sbi/sbi_platform.h | 6 +++++- lib/sbi_hart.c | 12 +++++++----- platform/sifive/hifive_u540/platform.c | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 39dfb499d9a..6de52f63a6f 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -18,13 +18,15 @@ enum sbi_platform_features { SBI_PLATFORM_HAS_PMP = (1 << 2), SBI_PLATFORM_HAS_SCOUNTEREN = (1 << 3), SBI_PLATFORM_HAS_MCOUNTEREN = (1 << 4), + SBI_PLATFORM_HAS_MFAULTS_DELEGATION = (1 << 5), }; #define SBI_PLATFORM_DEFAULT_FEATURES \ (SBI_PLATFORM_HAS_MMIO_TIMER_VALUE | \ SBI_PLATFORM_HAS_PMP | \ SBI_PLATFORM_HAS_SCOUNTEREN | \ - SBI_PLATFORM_HAS_MCOUNTEREN) + SBI_PLATFORM_HAS_MCOUNTEREN | \ + SBI_PLATFORM_HAS_MFAULTS_DELEGATION) struct sbi_platform { char name[64]; @@ -71,6 +73,8 @@ struct sbi_platform { ((__p)->features & SBI_PLATFORM_HAS_SCOUNTEREN) #define sbi_platform_has_mcounteren(__p) \ ((__p)->features & SBI_PLATFORM_HAS_MCOUNTEREN) +#define sbi_platform_has_mfaults_delegation(__p) \ + ((__p)->features & SBI_PLATFORM_HAS_MFAULTS_DELEGATION) static inline const char *sbi_platform_name(struct sbi_platform *plat) { diff --git a/lib/sbi_hart.c b/lib/sbi_hart.c index 01362dd73f3..be114d693ff 100644 --- a/lib/sbi_hart.c +++ b/lib/sbi_hart.c @@ -83,8 +83,9 @@ static int fp_init(u32 hartid) return 0; } -static int delegate_traps(u32 hartid) +static int delegate_traps(struct sbi_scratch *scratch, u32 hartid) { + struct sbi_platform *plat = sbi_platform_ptr(scratch); unsigned long interrupts, exceptions; if (!misa_extension('S')) { @@ -95,11 +96,12 @@ static int delegate_traps(u32 hartid) /* Send M-mode interrupts and most exceptions to S-mode */ interrupts = MIP_SSIP | MIP_STIP | MIP_SEIP; exceptions = (1U << CAUSE_MISALIGNED_FETCH) | - (1U << CAUSE_FETCH_PAGE_FAULT) | (1U << CAUSE_BREAKPOINT) | - (1U << CAUSE_LOAD_PAGE_FAULT) | - (1U << CAUSE_STORE_PAGE_FAULT) | (1U << CAUSE_USER_ECALL); + if (sbi_platform_has_mfaults_delegation(plat)) + exceptions |= (1U << CAUSE_FETCH_PAGE_FAULT) | + (1U << CAUSE_LOAD_PAGE_FAULT) | + (1U << CAUSE_STORE_PAGE_FAULT); } csr_write(mideleg, interrupts); @@ -200,7 +202,7 @@ int sbi_hart_init(struct sbi_scratch *scratch, u32 hartid) if (rc) return rc; - rc = delegate_traps(hartid); + rc = delegate_traps(scratch, hartid); if (rc) return rc; diff --git a/platform/sifive/hifive_u540/platform.c b/platform/sifive/hifive_u540/platform.c index 46613e60073..338cc2cc286 100644 --- a/platform/sifive/hifive_u540/platform.c +++ b/platform/sifive/hifive_u540/platform.c @@ -105,7 +105,7 @@ static int sifive_u_system_down(u32 type) struct sbi_platform platform = { .name = STRINGIFY(PLAT_NAME), - .features = SBI_PLATFORM_DEFAULT_FEATURES; + .features = SBI_PLATFORM_DEFAULT_FEATURES, .hart_count = PLAT_HART_COUNT, .hart_stack_size = PLAT_HART_STACK_SIZE, .pmp_region_count = sifive_u_pmp_region_count, From 95fbe7d49587beb4f92b6e5e7b8adb5e54b81366 Mon Sep 17 00:00:00 2001 From: Atish Patra Date: Fri, 21 Dec 2018 15:16:59 -0800 Subject: [PATCH 0026/1765] Move hardcoded uart constant to macros. Signed-off-by: Atish Patra --- platform/kendryte/k210/platform.c | 4 +++- platform/qemu/virt/platform.c | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c index 03c2c2d7693..487b7cc935f 100644 --- a/platform/kendryte/k210/platform.c +++ b/platform/kendryte/k210/platform.c @@ -16,9 +16,11 @@ #include "platform.h" #include "uarths.h" +#define K210_UART_BAUDRATE 115200 + int k210_console_init(void) { - uarths_init(115200, UARTHS_STOP_1); + uarths_init(K210_UART_BAUDRATE, UARTHS_STOP_1); return 0; } diff --git a/platform/qemu/virt/platform.c b/platform/qemu/virt/platform.c index fe91fc8f664..84ea58f1a2a 100644 --- a/platform/qemu/virt/platform.c +++ b/platform/qemu/virt/platform.c @@ -23,6 +23,8 @@ #define VIRT_PLIC_NUM_PRIORITIES 7 #define VIRT_UART16550_ADDR 0x10000000 +#define VIRT_UART_BAUDRATE 115200 +#define VIRT_UART_SHIFTREG_ADDR 1843200 static int virt_cold_final_init(void) { @@ -56,7 +58,8 @@ static int virt_pmp_region_info(u32 target_hart, u32 index, static int virt_console_init(void) { return uart8250_init(VIRT_UART16550_ADDR, - 1843200, 115200, 0, 1); + VIRT_UART_SHIFTREG_ADDR, + VIRT_UART_BAUDRATE, 0, 1); } static int virt_cold_irqchip_init(void) From 5148499e0393737609baa5ada55284ad91c8be86 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 21 Dec 2018 15:45:14 -0800 Subject: [PATCH 0027/1765] Fix plic warm init in common code. Unleashed doesn't have S mode for hart 0. PLIC register base calculation is current wrong because of that. Signed-off-by: Atish Patra Signed-off-by: Anup Patel --- platform/common/include/plat/irqchip/plic.h | 5 ++- platform/common/irqchip/plic.c | 47 ++++++++++----------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/platform/common/include/plat/irqchip/plic.h b/platform/common/include/plat/irqchip/plic.h index 7c062aa53de..d3094acc6af 100644 --- a/platform/common/include/plat/irqchip/plic.h +++ b/platform/common/include/plat/irqchip/plic.h @@ -12,9 +12,10 @@ #include -int plic_fdt_fixup(void *fdt, const char *compat); +void plic_fdt_fixup(void *fdt, const char *compat, u32 cntx_id); -int plic_warm_irqchip_init(u32 target_hart); +int plic_warm_irqchip_init(u32 target_hart, + int m_cntx_id, int s_cntx_id); int plic_cold_irqchip_init(unsigned long base, u32 num_sources, u32 hart_count); diff --git a/platform/common/irqchip/plic.c b/platform/common/irqchip/plic.c index 404d1b7e6cb..ece86a7ef01 100644 --- a/platform/common/irqchip/plic.c +++ b/platform/common/irqchip/plic.c @@ -27,28 +27,20 @@ static void plic_set_priority(u32 source, u32 val) writel(val, plic_base); } -static void plic_set_m_thresh(u32 hartid, u32 val) +static void plic_set_thresh(u32 cntxid, u32 val) { - volatile void *plic_m_thresh = plic_base + + volatile void *plic_thresh = plic_base + PLIC_CONTEXT_BASE + - PLIC_CONTEXT_STRIDE * (2 * hartid); - writel(val, plic_m_thresh); + PLIC_CONTEXT_STRIDE * cntxid; + writel(val, plic_thresh); } -static void plic_set_s_thresh(u32 hartid, u32 val) +static void plic_set_ie(u32 cntxid, u32 word_index, u32 val) { - volatile void *plic_s_thresh = plic_base + - PLIC_CONTEXT_BASE + - PLIC_CONTEXT_STRIDE * (2 * hartid + 1); - writel(val, plic_s_thresh); -} - -static void plic_set_s_ie(u32 hartid, u32 word_index, u32 val) -{ - volatile void *plic_s_ie = plic_base + + volatile void *plic_ie = plic_base + PLIC_ENABLE_BASE + - PLIC_ENABLE_STRIDE * (2 * hartid + 1); - writel(val, plic_s_ie + word_index * 4); + PLIC_ENABLE_STRIDE * cntxid; + writel(val, plic_ie + word_index * 4); } static void plic_fdt_fixup_prop(const struct fdt_node *node, @@ -57,6 +49,7 @@ static void plic_fdt_fixup_prop(const struct fdt_node *node, { u32 *cells; u32 i, cells_count; + u32 *cntx_id = priv; if (!prop) return; @@ -70,18 +63,18 @@ static void plic_fdt_fixup_prop(const struct fdt_node *node, return; for (i = 0; i < cells_count; i++) { - if (i % 4 == 1) + if (((i % 2) == 1) && ((i / 2) == *cntx_id)) cells[i] = fdt_rev32(0xffffffff); } } -int plic_fdt_fixup(void *fdt, const char *compat) +void plic_fdt_fixup(void *fdt, const char *compat, u32 cntx_id) { - fdt_compat_node_prop(fdt, compat, plic_fdt_fixup_prop, NULL); - return 0; + fdt_compat_node_prop(fdt, compat, plic_fdt_fixup_prop, &cntx_id); } -int plic_warm_irqchip_init(u32 target_hart) +int plic_warm_irqchip_init(u32 target_hart, + int m_cntx_id, int s_cntx_id) { size_t i, ie_words = plic_num_sources / 32 + 1; @@ -89,14 +82,18 @@ int plic_warm_irqchip_init(u32 target_hart) return -1; /* By default, enable all IRQs for S-mode of target HART */ - for (i = 0; i < ie_words; i++) - plic_set_s_ie(target_hart, i, -1); + if (s_cntx_id > -1) { + for (i = 0; i < ie_words; i++) + plic_set_ie(s_cntx_id, i, -1); + } /* By default, enable M-mode threshold */ - plic_set_m_thresh(target_hart, 1); + if (m_cntx_id > -1) + plic_set_thresh(m_cntx_id, 1); /* By default, disable S-mode threshold */ - plic_set_s_thresh(target_hart, 0); + if (s_cntx_id > -1) + plic_set_thresh(s_cntx_id, 0); return 0; } From a6a5bb22a8c97f6191a0271f3dfe529038161675 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 21 Dec 2018 15:46:37 -0800 Subject: [PATCH 0028/1765] Fix plic warm init in platform code. Pass S-Mode and M-mode context id separately to common warm init. Signed-off-by: Atish Patra Signed-off-by: Anup Patel --- platform/kendryte/k210/platform.c | 4 +++- platform/qemu/sifive_u/platform.c | 17 +++++++++++++++-- platform/qemu/virt/platform.c | 17 +++++++++++++++-- platform/sifive/hifive_u540/platform.c | 18 ++++++++++++++++-- 4 files changed, 49 insertions(+), 7 deletions(-) diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c index 487b7cc935f..8e565dd85e4 100644 --- a/platform/kendryte/k210/platform.c +++ b/platform/kendryte/k210/platform.c @@ -43,7 +43,9 @@ static int k210_cold_irqchip_init(void) static int k210_warm_irqchip_init(u32 core_id) { - return plic_warm_irqchip_init(core_id); + return plic_warm_irqchip_init(core_id, + (2 * core_id), + (2 * core_id + 1)); } static int k210_cold_ipi_init(void) diff --git a/platform/qemu/sifive_u/platform.c b/platform/qemu/sifive_u/platform.c index d9168255ec6..10db5db12b3 100644 --- a/platform/qemu/sifive_u/platform.c +++ b/platform/qemu/sifive_u/platform.c @@ -28,7 +28,13 @@ static int sifive_u_cold_final_init(void) { - return plic_fdt_fixup(sbi_scratch_thishart_arg1_ptr(), "riscv,plic0"); + u32 i; + void *fdt = sbi_scratch_thishart_arg1_ptr(); + + for (i = 0; i < PLAT_HART_COUNT; i++) + plic_fdt_fixup(fdt, "riscv,plic0", 2 * i); + + return 0; } static u32 sifive_u_pmp_region_count(u32 target_hart) @@ -68,6 +74,13 @@ static int sifive_u_cold_irqchip_init(void) PLAT_HART_COUNT); } +static int sifive_u_warm_irqchip_init(u32 target_hart) +{ + return plic_warm_irqchip_init(target_hart, + (2 * target_hart), + (2 * target_hart + 1)); +} + static int sifive_u_cold_ipi_init(void) { return clint_cold_ipi_init(SIFIVE_U_CLINT_ADDR, @@ -98,7 +111,7 @@ struct sbi_platform platform = { .console_getc = sifive_uart_getc, .console_init = sifive_u_console_init, .cold_irqchip_init = sifive_u_cold_irqchip_init, - .warm_irqchip_init = plic_warm_irqchip_init, + .warm_irqchip_init = sifive_u_warm_irqchip_init, .ipi_inject = clint_ipi_inject, .ipi_sync = clint_ipi_sync, .ipi_clear = clint_ipi_clear, diff --git a/platform/qemu/virt/platform.c b/platform/qemu/virt/platform.c index 84ea58f1a2a..de407732a68 100644 --- a/platform/qemu/virt/platform.c +++ b/platform/qemu/virt/platform.c @@ -28,7 +28,13 @@ static int virt_cold_final_init(void) { - return plic_fdt_fixup(sbi_scratch_thishart_arg1_ptr(), "riscv,plic0"); + u32 i; + void *fdt = sbi_scratch_thishart_arg1_ptr(); + + for (i = 0; i < PLAT_HART_COUNT; i++) + plic_fdt_fixup(fdt, "riscv,plic0", 2 * i); + + return 0; } static u32 virt_pmp_region_count(u32 target_hart) @@ -69,6 +75,13 @@ static int virt_cold_irqchip_init(void) PLAT_HART_COUNT); } +static int virt_warm_irqchip_init(u32 target_hart) +{ + return plic_warm_irqchip_init(target_hart, + (2 * target_hart), + (2 * target_hart + 1)); +} + static int virt_cold_ipi_init(void) { return clint_cold_ipi_init(VIRT_CLINT_ADDR, @@ -99,7 +112,7 @@ struct sbi_platform platform = { .console_getc = uart8250_getc, .console_init = virt_console_init, .cold_irqchip_init = virt_cold_irqchip_init, - .warm_irqchip_init = plic_warm_irqchip_init, + .warm_irqchip_init = virt_warm_irqchip_init, .ipi_inject = clint_ipi_inject, .ipi_sync = clint_ipi_sync, .ipi_clear = clint_ipi_clear, diff --git a/platform/sifive/hifive_u540/platform.c b/platform/sifive/hifive_u540/platform.c index 338cc2cc286..d3ed8042dc0 100644 --- a/platform/sifive/hifive_u540/platform.c +++ b/platform/sifive/hifive_u540/platform.c @@ -35,7 +35,14 @@ static int sifive_u_cold_final_init(void) { - return plic_fdt_fixup(sbi_scratch_thishart_arg1_ptr(), "riscv,plic0"); + u32 i; + void *fdt = sbi_scratch_thishart_arg1_ptr(); + + plic_fdt_fixup(fdt, "riscv,plic0", 0); + for (i = 1; i < PLAT_HART_COUNT; i++) + plic_fdt_fixup(fdt, "riscv,plic0", 2 * i - 1); + + return 0; } static u32 sifive_u_pmp_region_count(u32 target_hart) @@ -85,6 +92,13 @@ static int sifive_u_cold_irqchip_init(void) PLAT_HART_COUNT); } +static int sifive_u_warm_irqchip_init(u32 target_hart) +{ + return plic_warm_irqchip_init(target_hart, + (target_hart) ? (2 * target_hart - 1) : 0, + (target_hart) ? (2 * target_hart) : -1); +} + static int sifive_u_cold_ipi_init(void) { return clint_cold_ipi_init(SIFIVE_U_CLINT_ADDR, @@ -115,7 +129,7 @@ struct sbi_platform platform = { .console_getc = sifive_uart_getc, .console_init = sifive_u_console_init, .cold_irqchip_init = sifive_u_cold_irqchip_init, - .warm_irqchip_init = plic_warm_irqchip_init, + .warm_irqchip_init = sifive_u_warm_irqchip_init, .ipi_inject = clint_ipi_inject, .ipi_sync = clint_ipi_sync, .ipi_clear = clint_ipi_clear, From 88b173b33b0810fbeff91ee589073efb9099a904 Mon Sep 17 00:00:00 2001 From: Atish Patra Date: Fri, 21 Dec 2018 11:29:28 -0800 Subject: [PATCH 0029/1765] Introduce hart disabled parameter in platform. As of now, uboot doesn't have support for SMP. Moreover, unleashed board has a E51 hart which doesn't not support S mode. We should only boot only 1 non-zero hart. Signed-off-by: Atish Patra --- include/sbi/sbi_platform.h | 8 ++++++++ lib/sbi_hart.c | 2 -- lib/sbi_init.c | 13 +++++++++---- lib/sbi_ipi.c | 2 +- platform/kendryte/k210/platform.c | 1 + platform/qemu/sifive_u/platform.c | 1 + platform/qemu/virt/platform.c | 1 + platform/sifive/hifive_u540/platform.c | 3 +++ 8 files changed, 24 insertions(+), 7 deletions(-) diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 6de52f63a6f..00fadde912e 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -33,6 +33,7 @@ struct sbi_platform { u64 features; u32 hart_count; u32 hart_stack_size; + u64 disabled_hart_mask; int (*cold_early_init)(void); int (*cold_final_init)(void); int (*warm_early_init)(u32 target_hart); @@ -83,6 +84,13 @@ static inline const char *sbi_platform_name(struct sbi_platform *plat) return NULL; } +static inline bool sbi_platform_hart_disabled(struct sbi_platform *plat, u32 hartid) +{ + if (plat && (plat->disabled_hart_mask & (1 << hartid))) + return 1; + else + return 0; +} static inline u32 sbi_platform_hart_count(struct sbi_platform *plat) { if (plat) diff --git a/lib/sbi_hart.c b/lib/sbi_hart.c index be114d693ff..1e5465f5d31 100644 --- a/lib/sbi_hart.c +++ b/lib/sbi_hart.c @@ -211,8 +211,6 @@ int sbi_hart_init(struct sbi_scratch *scratch, u32 hartid) void __attribute__((noreturn)) sbi_hart_hang(void) { - sbi_printf("\nHART%u Hang !!\n\n", sbi_current_hartid()); - while (1) wfi(); __builtin_unreachable(); diff --git a/lib/sbi_init.c b/lib/sbi_init.c index da78a7efe7a..68113b4913f 100644 --- a/lib/sbi_init.c +++ b/lib/sbi_init.c @@ -86,7 +86,6 @@ static void __attribute__((noreturn)) init_coldboot(struct sbi_scratch *scratch, sbi_printf("OpenSBI v%d.%d (%s %s)\n", OPENSBI_MAJOR, OPENSBI_MINOR, __DATE__, __TIME__); - sbi_printf("Running on Hart %u\n", hartid); sbi_printf("%s\n", logo); @@ -95,6 +94,7 @@ static void __attribute__((noreturn)) init_coldboot(struct sbi_scratch *scratch, sbi_printf("Platform HART Features : RV%d%s\n", misa_xlen(), str); sbi_printf("Platform Max HARTs : %d\n", sbi_platform_hart_count(plat)); + sbi_printf("Current Hart : %u\n", hartid); /* Firmware details */ sbi_printf("Firmware Base : 0x%lx\n", scratch->fw_start); sbi_printf("Firmware Size : %d KB\n", @@ -106,11 +106,9 @@ static void __attribute__((noreturn)) init_coldboot(struct sbi_scratch *scratch, sbi_hart_pmp_dump(scratch); - sbi_hart_mark_available(hartid); - if (!sbi_platform_has_hart_hotplug(plat)) sbi_hart_wake_coldboot_harts(scratch, hartid); - + sbi_hart_mark_available(hartid); sbi_hart_switch_mode(hartid, scratch->next_arg1, scratch->next_addr, scratch->next_mode); } @@ -124,6 +122,9 @@ static void __attribute__((noreturn)) init_warmboot(struct sbi_scratch *scratch, if (!sbi_platform_has_hart_hotplug(plat)) sbi_hart_wait_for_coldboot(scratch, hartid); + if (sbi_platform_hart_disabled(plat, hartid)) + sbi_hart_hang(); + rc = sbi_system_warm_early_init(scratch, hartid); if (rc) sbi_hart_hang(); @@ -164,7 +165,11 @@ void __attribute__((noreturn)) sbi_init(struct sbi_scratch *scratch) { bool coldboot = FALSE; u32 hartid = sbi_current_hartid(); + struct sbi_platform *plat = sbi_platform_ptr(scratch); + if (sbi_platform_hart_disabled(plat, hartid)) + sbi_hart_hang(); + if (atomic_add_return(&coldboot_lottery, 1) == 1) coldboot = TRUE; diff --git a/lib/sbi_ipi.c b/lib/sbi_ipi.c index f3e68de1d99..d21ea4a2f05 100644 --- a/lib/sbi_ipi.c +++ b/lib/sbi_ipi.c @@ -28,7 +28,7 @@ int sbi_ipi_send_many(struct sbi_scratch *scratch, /* send IPIs to everyone */ for (i = 0, m = mask; m; i++, m >>= 1) { - if ((m & 1) && (i != hartid)) { + if ((m & 1) && (i != hartid) && !sbi_platform_hart_disabled(plat, hartid)) { oth = sbi_hart_id_to_scratch(scratch, i); oth->ipi_type = event; mb(); diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c index 8e565dd85e4..d3765d0e96c 100644 --- a/platform/kendryte/k210/platform.c +++ b/platform/kendryte/k210/platform.c @@ -81,6 +81,7 @@ struct sbi_platform platform = { .hart_count = PLAT_HART_COUNT, .hart_stack_size = PLAT_HART_STACK_SIZE, + .disabled_hart_mask = 0, .console_init = k210_console_init, .console_putc = k210_console_putc, diff --git a/platform/qemu/sifive_u/platform.c b/platform/qemu/sifive_u/platform.c index 10db5db12b3..f01df1efaf2 100644 --- a/platform/qemu/sifive_u/platform.c +++ b/platform/qemu/sifive_u/platform.c @@ -104,6 +104,7 @@ struct sbi_platform platform = { .features = SBI_PLATFORM_DEFAULT_FEATURES, .hart_count = PLAT_HART_COUNT, .hart_stack_size = PLAT_HART_STACK_SIZE, + .disabled_hart_mask = 0, .pmp_region_count = sifive_u_pmp_region_count, .pmp_region_info = sifive_u_pmp_region_info, .cold_final_init = sifive_u_cold_final_init, diff --git a/platform/qemu/virt/platform.c b/platform/qemu/virt/platform.c index de407732a68..9e006744bf0 100644 --- a/platform/qemu/virt/platform.c +++ b/platform/qemu/virt/platform.c @@ -105,6 +105,7 @@ struct sbi_platform platform = { .features = SBI_PLATFORM_DEFAULT_FEATURES, .hart_count = PLAT_HART_COUNT, .hart_stack_size = PLAT_HART_STACK_SIZE, + .disabled_hart_mask = 0, .pmp_region_count = virt_pmp_region_count, .pmp_region_info = virt_pmp_region_info, .cold_final_init = virt_cold_final_init, diff --git a/platform/sifive/hifive_u540/platform.c b/platform/sifive/hifive_u540/platform.c index d3ed8042dc0..646ce27341d 100644 --- a/platform/sifive/hifive_u540/platform.c +++ b/platform/sifive/hifive_u540/platform.c @@ -27,6 +27,8 @@ #define SIFIVE_U_UART1_ADDR 0x10011000 #define SIFIVE_UART_BAUDRATE 115200 +#define SIFIVE_U_HARITD_ENABLED 1 + /* PRCI clock related macros */ //TODO: Do we need a separate driver for this ? #define SIFIVE_PRCI_BASE_ADDR 0x10000000 @@ -122,6 +124,7 @@ struct sbi_platform platform = { .features = SBI_PLATFORM_DEFAULT_FEATURES, .hart_count = PLAT_HART_COUNT, .hart_stack_size = PLAT_HART_STACK_SIZE, + .disabled_hart_mask = ~(1 << SIFIVE_U_HARITD_ENABLED), .pmp_region_count = sifive_u_pmp_region_count, .pmp_region_info = sifive_u_pmp_region_info, .cold_final_init = sifive_u_cold_final_init, From 8304ee9424cc7700f2b08ba17553c2e48e0bafa8 Mon Sep 17 00:00:00 2001 From: Atish Patra Date: Fri, 21 Dec 2018 21:31:12 -0800 Subject: [PATCH 0030/1765] Disable all interrupts during warm irqchip init. M mode is not expected to recieve any interrupts. S mode interrupts shouldn't be enabled in M mode. Signed-off-by: Atish Patra --- platform/common/irqchip/plic.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/platform/common/irqchip/plic.c b/platform/common/irqchip/plic.c index ece86a7ef01..61a6bd01fd7 100644 --- a/platform/common/irqchip/plic.c +++ b/platform/common/irqchip/plic.c @@ -80,11 +80,16 @@ int plic_warm_irqchip_init(u32 target_hart, if (plic_hart_count <= target_hart) return -1; + + if (m_cntx_id > -1) { + for (i = 0; i < ie_words; i++) + plic_set_ie(m_cntx_id, i, 0); + } /* By default, enable all IRQs for S-mode of target HART */ if (s_cntx_id > -1) { for (i = 0; i < ie_words; i++) - plic_set_ie(s_cntx_id, i, -1); + plic_set_ie(s_cntx_id, i, 0); } /* By default, enable M-mode threshold */ From 24b4d48674ad2dc088949cdf852231ab1e81f56b Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Sat, 22 Dec 2018 11:15:37 +0530 Subject: [PATCH 0031/1765] platform: Remove PLAT_NAME from all platforms The PLAT_NAME is used only in platform.c for all platforms hence remove it. Signed-off-by: Anup Patel --- platform/kendryte/k210/config.mk | 1 - platform/kendryte/k210/platform.c | 2 +- platform/qemu/sifive_u/config.mk | 1 - platform/qemu/sifive_u/platform.c | 2 +- platform/qemu/virt/config.mk | 1 - platform/qemu/virt/platform.c | 2 +- platform/sifive/hifive_u540/config.mk | 1 - platform/sifive/hifive_u540/platform.c | 2 +- 8 files changed, 4 insertions(+), 8 deletions(-) diff --git a/platform/kendryte/k210/config.mk b/platform/kendryte/k210/config.mk index c0c36ea054b..f800a41fa57 100644 --- a/platform/kendryte/k210/config.mk +++ b/platform/kendryte/k210/config.mk @@ -8,7 +8,6 @@ # # Essential defines required by SBI platform -platform-cppflags-y = -DPLAT_NAME="Kendryte K210" platform-cppflags-y+= -DPLAT_HART_COUNT=2 platform-cppflags-y+= -DPLAT_HART_STACK_SIZE=4096 diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c index d3765d0e96c..4ef1a249552 100644 --- a/platform/kendryte/k210/platform.c +++ b/platform/kendryte/k210/platform.c @@ -76,7 +76,7 @@ static int k210_system_shutdown(u32 type) struct sbi_platform platform = { - .name = STRINGIFY(PLAT_NAME), + .name = "Kendryte K210", .features = SBI_PLATFORM_HAS_MMIO_TIMER_VALUE, .hart_count = PLAT_HART_COUNT, diff --git a/platform/qemu/sifive_u/config.mk b/platform/qemu/sifive_u/config.mk index d4470cd0ad5..c2668a8f774 100644 --- a/platform/qemu/sifive_u/config.mk +++ b/platform/qemu/sifive_u/config.mk @@ -8,7 +8,6 @@ # # Essential defines required by SBI platform -platform-cppflags-y = -DPLAT_NAME="QEMU SiFive Unleashed" platform-cppflags-y+= -DPLAT_HART_COUNT=1 platform-cppflags-y+= -DPLAT_HART_STACK_SIZE=8192 diff --git a/platform/qemu/sifive_u/platform.c b/platform/qemu/sifive_u/platform.c index f01df1efaf2..c2dcafc8dab 100644 --- a/platform/qemu/sifive_u/platform.c +++ b/platform/qemu/sifive_u/platform.c @@ -100,7 +100,7 @@ static int sifive_u_system_down(u32 type) } struct sbi_platform platform = { - .name = STRINGIFY(PLAT_NAME), + .name = "QEMU SiFive Unleashed", .features = SBI_PLATFORM_DEFAULT_FEATURES, .hart_count = PLAT_HART_COUNT, .hart_stack_size = PLAT_HART_STACK_SIZE, diff --git a/platform/qemu/virt/config.mk b/platform/qemu/virt/config.mk index 8496e2d4804..467b0576126 100644 --- a/platform/qemu/virt/config.mk +++ b/platform/qemu/virt/config.mk @@ -8,7 +8,6 @@ # # Essential defines required by SBI platform -platform-cppflags-y = -DPLAT_NAME="QEMU Virt Machine" platform-cppflags-y+= -DPLAT_HART_COUNT=8 platform-cppflags-y+= -DPLAT_HART_STACK_SIZE=8192 diff --git a/platform/qemu/virt/platform.c b/platform/qemu/virt/platform.c index 9e006744bf0..7b82e4e2d18 100644 --- a/platform/qemu/virt/platform.c +++ b/platform/qemu/virt/platform.c @@ -101,7 +101,7 @@ static int virt_system_down(u32 type) } struct sbi_platform platform = { - .name = STRINGIFY(PLAT_NAME), + .name = "QEMU Virt Machine", .features = SBI_PLATFORM_DEFAULT_FEATURES, .hart_count = PLAT_HART_COUNT, .hart_stack_size = PLAT_HART_STACK_SIZE, diff --git a/platform/sifive/hifive_u540/config.mk b/platform/sifive/hifive_u540/config.mk index f411fa9a180..ecbf88c39ac 100644 --- a/platform/sifive/hifive_u540/config.mk +++ b/platform/sifive/hifive_u540/config.mk @@ -8,7 +8,6 @@ # # Essential defines required by SBI platform -platform-cppflags-y = -DPLAT_NAME="SiFive HiFive U540" platform-cppflags-y+= -DPLAT_HART_COUNT=5 platform-cppflags-y+= -DPLAT_HART_STACK_SIZE=8192 diff --git a/platform/sifive/hifive_u540/platform.c b/platform/sifive/hifive_u540/platform.c index 646ce27341d..395ad4ed1ae 100644 --- a/platform/sifive/hifive_u540/platform.c +++ b/platform/sifive/hifive_u540/platform.c @@ -120,7 +120,7 @@ static int sifive_u_system_down(u32 type) } struct sbi_platform platform = { - .name = STRINGIFY(PLAT_NAME), + .name = "SiFive HiFive U540", .features = SBI_PLATFORM_DEFAULT_FEATURES, .hart_count = PLAT_HART_COUNT, .hart_stack_size = PLAT_HART_STACK_SIZE, From 1cf7ec9e3bbf287fc9d601d2346b9e73fda40a84 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Sat, 22 Dec 2018 12:02:31 +0530 Subject: [PATCH 0032/1765] firmware: Remove stack section from common linker script We don't need a separate stack section for per-HART stack instead we create per-HART stack at the end of firmware (i.e. after _fw_end symbol). Signed-off-by: Anup Patel --- firmware/fw_common.S | 61 +++++++++++++++++++++++++++++------------- firmware/fw_common.ldS | 12 --------- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/firmware/fw_common.S b/firmware/fw_common.S index 198aa0b9925..4c11e852c73 100644 --- a/firmware/fw_common.S +++ b/firmware/fw_common.S @@ -122,18 +122,28 @@ _start_warm: csrw mie, zero csrw mip, zero - /* set MSIE bit to receive IPI */ + /* Set MSIE bit to receive IPI */ li a2, MIP_MSIP csrw mie, a2 + + /* Preload per-HART details + * s6 -> HART ID + * s7 -> HART Count + * s8 -> HART Stack Size + */ + csrr s6, mhartid + li s7, PLAT_HART_COUNT + li s8, PLAT_HART_STACK_SIZE + /* HART ID should be within expected limit */ - csrr a6, mhartid - li a5, PLAT_HART_COUNT - bge a6, a5, _start_hang + csrr s6, mhartid + bge s6, s7, _start_hang /* Setup scratch space */ - li a5, PLAT_HART_STACK_SIZE - la tp, _stack_end - mul a5, a5, a6 + la tp, _fw_end + mul a5, s7, s8 + add tp, tp, a5 + mul a5, s8, s6 sub tp, tp, a5 li a5, RISCV_SCRATCH_SIZE sub tp, tp, a5 @@ -143,6 +153,8 @@ _start_warm: REG_S zero, RISCV_SCRATCH_TMP0_OFFSET(tp) la a4, _fw_start la a5, _fw_end + mul t0, s7, s8 + add a5, a5, t0 sub a5, a5, a4 REG_S a4, RISCV_SCRATCH_FW_START_OFFSET(tp) REG_S a5, RISCV_SCRATCH_FW_SIZE_OFFSET(tp) @@ -180,18 +192,29 @@ _start_warm: .section .entry, "ax", %progbits .globl _hartid_to_scratch _hartid_to_scratch: - add sp, sp, -(2 * __SIZEOF_POINTER__) - REG_S a1, (sp) - REG_S a2, (__SIZEOF_POINTER__)(sp) - li a1, PLAT_HART_STACK_SIZE - la a2, _stack_end - mul a1, a1, a0 - sub a2, a2, a1 - li a1, RISCV_SCRATCH_SIZE - sub a0, a2, a1 - REG_L a1, (sp) - REG_L a2, (__SIZEOF_POINTER__)(sp) - add sp, sp, (2 * __SIZEOF_POINTER__) + add sp, sp, -(3 * __SIZEOF_POINTER__) + REG_S s0, (sp) + REG_S s1, (__SIZEOF_POINTER__)(sp) + REG_S s2, (__SIZEOF_POINTER__ * 2)(sp) + /* + * a0 -> HART ID (passed by caller) + * s0 -> HART Stack Size + * s1 -> HART Stack End + * s2 -> Temporary + */ + li s0, PLAT_HART_STACK_SIZE + li s2, PLAT_HART_COUNT + mul s2, s2, s0 + la s1, _fw_end + add s1, s1, s2 + mul s2, s0, a0 + sub s1, s1, s2 + li s2, RISCV_SCRATCH_SIZE + sub a0, s1, s2 + REG_L s0, (sp) + REG_L s1, (__SIZEOF_POINTER__)(sp) + REG_L s2, (__SIZEOF_POINTER__ * 2)(sp) + add sp, sp, (3 * __SIZEOF_POINTER__) ret .align 3 diff --git a/firmware/fw_common.ldS b/firmware/fw_common.ldS index 3761d62fa7d..52771f8bdda 100644 --- a/firmware/fw_common.ldS +++ b/firmware/fw_common.ldS @@ -61,18 +61,6 @@ . = ALIGN(0x1000); /* Ensure next section is page aligned */ - .stack : - { - PROVIDE(_stack_start = .); - *(.stack) - *(.stack.*) - . = . + (PLAT_HART_STACK_SIZE * PLAT_HART_COUNT); - . = ALIGN(8); - PROVIDE(_stack_end = .); - } - - . = ALIGN(0x1000); /* Ensure next section is page aligned */ - .bss : { PROVIDE(_bss_start = .); From 58ca525a7d35b2d4cd7045fd343fb6d85567f01d Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Sat, 22 Dec 2018 12:40:54 +0530 Subject: [PATCH 0033/1765] firmware: Don't depend on PLAT_HART_COUNT and PLAT_HART_STACK_SIZE The hart_count and hart_stack_size information is already available in "struct sbi_platform" so we use that instead of depending on PLAT_HART_COUNT and PLAT_HART_STACK_SIZE. Signed-off-by: Anup Patel --- firmware/fw_common.S | 10 ++++++---- include/sbi/riscv_asm.h | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/firmware/fw_common.S b/firmware/fw_common.S index 4c11e852c73..d426f15f753 100644 --- a/firmware/fw_common.S +++ b/firmware/fw_common.S @@ -132,8 +132,9 @@ _start_warm: * s8 -> HART Stack Size */ csrr s6, mhartid - li s7, PLAT_HART_COUNT - li s8, PLAT_HART_STACK_SIZE + la a4, platform + lwu s7, RISCV_PLATFORM_HART_COUNT_OFFSET(a4) + lwu s8, RISCV_PLATFORM_HART_STACK_SIZE_OFFSET(a4) /* HART ID should be within expected limit */ csrr s6, mhartid @@ -202,8 +203,9 @@ _hartid_to_scratch: * s1 -> HART Stack End * s2 -> Temporary */ - li s0, PLAT_HART_STACK_SIZE - li s2, PLAT_HART_COUNT + la s2, platform + lwu s0, RISCV_PLATFORM_HART_STACK_SIZE_OFFSET(s2) + lwu s2, RISCV_PLATFORM_HART_COUNT_OFFSET(s2) mul s2, s2, s0 la s1, _fw_end add s1, s1, s2 diff --git a/include/sbi/riscv_asm.h b/include/sbi/riscv_asm.h index 516bf6f9a94..045310b5d5a 100644 --- a/include/sbi/riscv_asm.h +++ b/include/sbi/riscv_asm.h @@ -81,6 +81,11 @@ #define RISCV_SCRATCH_IPI_TYPE_OFFSET (9 * __SIZEOF_POINTER__) #define RISCV_SCRATCH_SIZE 256 +#define RISCV_PLATFORM_NAME_OFFSET (0x0) +#define RISCV_PLATFORM_FEATURES_OFFSET (0x40) +#define RISCV_PLATFORM_HART_COUNT_OFFSET (0x48) +#define RISCV_PLATFORM_HART_STACK_SIZE_OFFSET (0x4c) + #define RISCV_TRAP_REGS_zero 0 #define RISCV_TRAP_REGS_ra 1 #define RISCV_TRAP_REGS_sp 2 From 472d3f4e170814a2eda663a97b84728557a71757 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Sat, 22 Dec 2018 21:01:40 +0530 Subject: [PATCH 0034/1765] platform: Remove PLAT_HART_COUNT and PLAT_HART_STACK_SIZE The PLAT_HART_COUNT and PLAT_HART_STACK_SIZE are only used by platform code so no need of exposing these to everyone by adding it to platform-cppflags-y. Signed-off-by: Anup Patel --- platform/kendryte/k210/config.mk | 5 +---- platform/kendryte/k210/platform.c | 10 +++++----- platform/kendryte/k210/platform.h | 5 ++++- platform/qemu/sifive_u/config.mk | 5 +---- platform/qemu/sifive_u/platform.c | 15 +++++++++------ platform/qemu/virt/config.mk | 5 +---- platform/qemu/virt/platform.c | 15 +++++++++------ platform/sifive/hifive_u540/config.mk | 5 +---- platform/sifive/hifive_u540/platform.c | 15 +++++++++------ 9 files changed, 40 insertions(+), 40 deletions(-) diff --git a/platform/kendryte/k210/config.mk b/platform/kendryte/k210/config.mk index f800a41fa57..512fc2abe86 100644 --- a/platform/kendryte/k210/config.mk +++ b/platform/kendryte/k210/config.mk @@ -7,11 +7,8 @@ # SPDX-License-Identifier: BSD-2-Clause # -# Essential defines required by SBI platform -platform-cppflags-y+= -DPLAT_HART_COUNT=2 -platform-cppflags-y+= -DPLAT_HART_STACK_SIZE=4096 - # Compiler flags +platform-cppflags-y = platform-cflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany platform-asflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany platform-ldflags-y = diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c index 4ef1a249552..226cb775ca2 100644 --- a/platform/kendryte/k210/platform.c +++ b/platform/kendryte/k210/platform.c @@ -38,7 +38,7 @@ static char k210_console_getc(void) static int k210_cold_irqchip_init(void) { return plic_cold_irqchip_init(PLIC_BASE_ADDR, PLIC_NUM_SOURCES, - PLAT_HART_COUNT); + K210_HART_COUNT); } static int k210_warm_irqchip_init(u32 core_id) @@ -50,12 +50,12 @@ static int k210_warm_irqchip_init(u32 core_id) static int k210_cold_ipi_init(void) { - return clint_cold_ipi_init(CLINT_BASE_ADDR, PLAT_HART_COUNT); + return clint_cold_ipi_init(CLINT_BASE_ADDR, K210_HART_COUNT); } static int k210_cold_timer_init(void) { - return clint_cold_timer_init(CLINT_BASE_ADDR, PLAT_HART_COUNT); + return clint_cold_timer_init(CLINT_BASE_ADDR, K210_HART_COUNT); } static int k210_system_reboot(u32 type) @@ -79,8 +79,8 @@ struct sbi_platform platform = { .name = "Kendryte K210", .features = SBI_PLATFORM_HAS_MMIO_TIMER_VALUE, - .hart_count = PLAT_HART_COUNT, - .hart_stack_size = PLAT_HART_STACK_SIZE, + .hart_count = K210_HART_COUNT, + .hart_stack_size = K210_HART_STACK_SIZE, .disabled_hart_mask = 0, .console_init = k210_console_init, diff --git a/platform/kendryte/k210/platform.h b/platform/kendryte/k210/platform.h index 6b520cf7b15..ddfdf15ba15 100644 --- a/platform/kendryte/k210/platform.h +++ b/platform/kendryte/k210/platform.h @@ -18,12 +18,15 @@ #include +#define K210_HART_COUNT 2 +#define K210_HART_STACK_SIZE 4096 + /* Register base address */ /* Under Coreplex */ #define CLINT_BASE_ADDR (0x02000000U) #define PLIC_BASE_ADDR (0x0C000000U) -#define PLIC_NUM_CORES (PLAT_HART_COUNT) +#define PLIC_NUM_CORES (K210_HART_COUNT) /* Under TileLink */ #define GPIOHS_BASE_ADDR (0x38001000U) diff --git a/platform/qemu/sifive_u/config.mk b/platform/qemu/sifive_u/config.mk index c2668a8f774..630098e54b7 100644 --- a/platform/qemu/sifive_u/config.mk +++ b/platform/qemu/sifive_u/config.mk @@ -7,11 +7,8 @@ # SPDX-License-Identifier: BSD-2-Clause # -# Essential defines required by SBI platform -platform-cppflags-y+= -DPLAT_HART_COUNT=1 -platform-cppflags-y+= -DPLAT_HART_STACK_SIZE=8192 - # Compiler flags +platform-cppflags-y = platform-cflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany platform-asflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany platform-ldflags-y = diff --git a/platform/qemu/sifive_u/platform.c b/platform/qemu/sifive_u/platform.c index c2dcafc8dab..f593323a8fc 100644 --- a/platform/qemu/sifive_u/platform.c +++ b/platform/qemu/sifive_u/platform.c @@ -14,6 +14,9 @@ #include #include +#define SIFIVE_U_HART_COUNT 1 +#define SIFIVE_U_HART_STACK_SIZE 8192 + #define SIFIVE_U_SYS_CLK 1000000000 #define SIFIVE_U_PERIPH_CLK (SIFIVE_U_SYS_CLK / 2) @@ -31,7 +34,7 @@ static int sifive_u_cold_final_init(void) u32 i; void *fdt = sbi_scratch_thishart_arg1_ptr(); - for (i = 0; i < PLAT_HART_COUNT; i++) + for (i = 0; i < SIFIVE_U_HART_COUNT; i++) plic_fdt_fixup(fdt, "riscv,plic0", 2 * i); return 0; @@ -71,7 +74,7 @@ static int sifive_u_cold_irqchip_init(void) { return plic_cold_irqchip_init(SIFIVE_U_PLIC_ADDR, SIFIVE_U_PLIC_NUM_SOURCES, - PLAT_HART_COUNT); + SIFIVE_U_HART_COUNT); } static int sifive_u_warm_irqchip_init(u32 target_hart) @@ -84,13 +87,13 @@ static int sifive_u_warm_irqchip_init(u32 target_hart) static int sifive_u_cold_ipi_init(void) { return clint_cold_ipi_init(SIFIVE_U_CLINT_ADDR, - PLAT_HART_COUNT); + SIFIVE_U_HART_COUNT); } static int sifive_u_cold_timer_init(void) { return clint_cold_timer_init(SIFIVE_U_CLINT_ADDR, - PLAT_HART_COUNT); + SIFIVE_U_HART_COUNT); } static int sifive_u_system_down(u32 type) @@ -102,8 +105,8 @@ static int sifive_u_system_down(u32 type) struct sbi_platform platform = { .name = "QEMU SiFive Unleashed", .features = SBI_PLATFORM_DEFAULT_FEATURES, - .hart_count = PLAT_HART_COUNT, - .hart_stack_size = PLAT_HART_STACK_SIZE, + .hart_count = SIFIVE_U_HART_COUNT, + .hart_stack_size = SIFIVE_U_HART_STACK_SIZE, .disabled_hart_mask = 0, .pmp_region_count = sifive_u_pmp_region_count, .pmp_region_info = sifive_u_pmp_region_info, diff --git a/platform/qemu/virt/config.mk b/platform/qemu/virt/config.mk index 467b0576126..927422c16d1 100644 --- a/platform/qemu/virt/config.mk +++ b/platform/qemu/virt/config.mk @@ -7,11 +7,8 @@ # SPDX-License-Identifier: BSD-2-Clause # -# Essential defines required by SBI platform -platform-cppflags-y+= -DPLAT_HART_COUNT=8 -platform-cppflags-y+= -DPLAT_HART_STACK_SIZE=8192 - # Compiler flags +platform-cppflags-y = platform-cflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany platform-asflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany platform-ldflags-y = diff --git a/platform/qemu/virt/platform.c b/platform/qemu/virt/platform.c index 7b82e4e2d18..98357cfc680 100644 --- a/platform/qemu/virt/platform.c +++ b/platform/qemu/virt/platform.c @@ -14,6 +14,9 @@ #include #include +#define VIRT_HART_COUNT 8 +#define VIRT_HART_STACK_SIZE 8192 + #define VIRT_TEST_ADDR 0x100000 #define VIRT_CLINT_ADDR 0x2000000 @@ -31,7 +34,7 @@ static int virt_cold_final_init(void) u32 i; void *fdt = sbi_scratch_thishart_arg1_ptr(); - for (i = 0; i < PLAT_HART_COUNT; i++) + for (i = 0; i < VIRT_HART_COUNT; i++) plic_fdt_fixup(fdt, "riscv,plic0", 2 * i); return 0; @@ -72,7 +75,7 @@ static int virt_cold_irqchip_init(void) { return plic_cold_irqchip_init(VIRT_PLIC_ADDR, VIRT_PLIC_NUM_SOURCES, - PLAT_HART_COUNT); + VIRT_HART_COUNT); } static int virt_warm_irqchip_init(u32 target_hart) @@ -85,13 +88,13 @@ static int virt_warm_irqchip_init(u32 target_hart) static int virt_cold_ipi_init(void) { return clint_cold_ipi_init(VIRT_CLINT_ADDR, - PLAT_HART_COUNT); + VIRT_HART_COUNT); } static int virt_cold_timer_init(void) { return clint_cold_timer_init(VIRT_CLINT_ADDR, - PLAT_HART_COUNT); + VIRT_HART_COUNT); } static int virt_system_down(u32 type) @@ -103,8 +106,8 @@ static int virt_system_down(u32 type) struct sbi_platform platform = { .name = "QEMU Virt Machine", .features = SBI_PLATFORM_DEFAULT_FEATURES, - .hart_count = PLAT_HART_COUNT, - .hart_stack_size = PLAT_HART_STACK_SIZE, + .hart_count = VIRT_HART_COUNT, + .hart_stack_size = VIRT_HART_STACK_SIZE, .disabled_hart_mask = 0, .pmp_region_count = virt_pmp_region_count, .pmp_region_info = virt_pmp_region_info, diff --git a/platform/sifive/hifive_u540/config.mk b/platform/sifive/hifive_u540/config.mk index ecbf88c39ac..630098e54b7 100644 --- a/platform/sifive/hifive_u540/config.mk +++ b/platform/sifive/hifive_u540/config.mk @@ -7,11 +7,8 @@ # SPDX-License-Identifier: BSD-2-Clause # -# Essential defines required by SBI platform -platform-cppflags-y+= -DPLAT_HART_COUNT=5 -platform-cppflags-y+= -DPLAT_HART_STACK_SIZE=8192 - # Compiler flags +platform-cppflags-y = platform-cflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany platform-asflags-y =-mabi=lp64 -march=rv64imafdc -mcmodel=medany platform-ldflags-y = diff --git a/platform/sifive/hifive_u540/platform.c b/platform/sifive/hifive_u540/platform.c index 395ad4ed1ae..1e600a3e34d 100644 --- a/platform/sifive/hifive_u540/platform.c +++ b/platform/sifive/hifive_u540/platform.c @@ -15,6 +15,9 @@ #include #include +#define SIFIVE_U_HART_COUNT 5 +#define SIFIVE_U_HART_STACK_SIZE 8192 + #define SIFIVE_U_SYS_CLK 1000000000 #define SIFIVE_U_CLINT_ADDR 0x2000000 @@ -41,7 +44,7 @@ static int sifive_u_cold_final_init(void) void *fdt = sbi_scratch_thishart_arg1_ptr(); plic_fdt_fixup(fdt, "riscv,plic0", 0); - for (i = 1; i < PLAT_HART_COUNT; i++) + for (i = 1; i < SIFIVE_U_HART_COUNT; i++) plic_fdt_fixup(fdt, "riscv,plic0", 2 * i - 1); return 0; @@ -91,7 +94,7 @@ static int sifive_u_cold_irqchip_init(void) { return plic_cold_irqchip_init(SIFIVE_U_PLIC_ADDR, SIFIVE_U_PLIC_NUM_SOURCES, - PLAT_HART_COUNT); + SIFIVE_U_HART_COUNT); } static int sifive_u_warm_irqchip_init(u32 target_hart) @@ -104,13 +107,13 @@ static int sifive_u_warm_irqchip_init(u32 target_hart) static int sifive_u_cold_ipi_init(void) { return clint_cold_ipi_init(SIFIVE_U_CLINT_ADDR, - PLAT_HART_COUNT); + SIFIVE_U_HART_COUNT); } static int sifive_u_cold_timer_init(void) { return clint_cold_timer_init(SIFIVE_U_CLINT_ADDR, - PLAT_HART_COUNT); + SIFIVE_U_HART_COUNT); } static int sifive_u_system_down(u32 type) @@ -122,8 +125,8 @@ static int sifive_u_system_down(u32 type) struct sbi_platform platform = { .name = "SiFive HiFive U540", .features = SBI_PLATFORM_DEFAULT_FEATURES, - .hart_count = PLAT_HART_COUNT, - .hart_stack_size = PLAT_HART_STACK_SIZE, + .hart_count = SIFIVE_U_HART_COUNT, + .hart_stack_size = SIFIVE_U_HART_STACK_SIZE, .disabled_hart_mask = ~(1 << SIFIVE_U_HARITD_ENABLED), .pmp_region_count = sifive_u_pmp_region_count, .pmp_region_info = sifive_u_pmp_region_info, From 4e8d078613ee670a8577ec76d7b0a05944e07f1b Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Sat, 22 Dec 2018 21:14:23 +0530 Subject: [PATCH 0035/1765] top: Typo fix in top-level README.md The platform specific options will be PLATFORM_ and not PLAT_ hence this patch fixes typo in top-level README.md. Signed-off-by: Anup Patel --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index db6c77b1946..8d5b7233ee1 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ OR `make PLATFORM= I= install` In addition, we can also specify platform specific command-line -options to top-level make (such as `PLAT_` or `FW_`) +options to top-level make (such as `PLATFORM_` or `FW_`) which are described under `docs/platform/.md` OR `docs/firmware/.md`. From d06dca9bcc470472337571c8ecc2742832713693 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Tue, 25 Dec 2018 15:37:48 +0900 Subject: [PATCH 0036/1765] Makefile: Rename CROSS_COMPILE to CROSS_COMPILE_PREFIX Make it clear what this environment variable defines and update the README.md file to explain that. Signed-off-by: Damien Le Moal --- Makefile | 14 +++++++------- README.md | 7 ++++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index f544a6488be..ee00d65e760 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +102,7 @@ deps-y+=$(lib-objs-path-y:.o=.dep) deps-y+=$(firmware-objs-path-y:.o=.dep) # Setup compilation environment -cpp=$(CROSS_COMPILE)cpp +cpp=$(CROSS_COMPILE_PREFIX)cpp cppflags+=-DOPENSBI_MAJOR=$(MAJOR) cppflags+=-DOPENSBI_MINOR=$(MINOR) cppflags+=-I$(platform_dir)/include @@ -110,7 +110,7 @@ cppflags+=-I$(platform_common_dir)/include cppflags+=-I$(include_dir) cppflags+=$(platform-cppflags-y) cppflags+=$(firmware-cppflags-y) -cc=$(CROSS_COMPILE)gcc +cc=$(CROSS_COMPILE_PREFIX)gcc cflags=-g -Wall -Werror -nostdlib -fno-strict-aliasing -O2 cflags+=-fno-omit-frame-pointer -fno-optimize-sibling-calls cflags+=-mno-save-restore -mstrict-align @@ -118,7 +118,7 @@ cflags+=$(cppflags) cflags+=$(platform-cflags-y) cflags+=$(firmware-cflags-y) cflags+=$(EXTRA_CFLAGS) -as=$(CROSS_COMPILE)gcc +as=$(CROSS_COMPILE_PREFIX)gcc asflags=-g -Wall -nostdlib -D__ASSEMBLY__ asflags+=-fno-omit-frame-pointer -fno-optimize-sibling-calls asflags+=-mno-save-restore -mstrict-align @@ -126,15 +126,15 @@ asflags+=$(cppflags) asflags+=$(platform-asflags-y) asflags+=$(firmware-asflags-y) asflags+=$(EXTRA_ASFLAGS) -ar=$(CROSS_COMPILE)ar +ar=$(CROSS_COMPILE_PREFIX)ar arflags=rcs -ld=$(CROSS_COMPILE)gcc +ld=$(CROSS_COMPILE_PREFIX)gcc ldflags=-g -Wall -nostdlib -Wl,--build-id=none ldflags+=$(platform-ldflags-y) ldflags+=$(firmware-ldflags-y) -merge=$(CROSS_COMPILE)ld +merge=$(CROSS_COMPILE_PREFIX)ld mergeflags=-r -objcopy=$(CROSS_COMPILE)objcopy +objcopy=$(CROSS_COMPILE_PREFIX)objcopy # Setup functions for compilation define dynamic_flags diff --git a/README.md b/README.md index 8d5b7233ee1..0588aa8d639 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,9 @@ We can create three things using the RISC-V OpenSBI project: How to Build? ------------- -For cross-compiling, please ensure that CROSS_COMPILE environment -variable is set before starting build system. +For cross-compiling, the environment variable CROSS_COMPILE_PREFIX must be +defined to specify the toolchain executable name prefix, e.g. +"riscv64-unknown-elf-" for riscv64-unknown-elf-gcc. The libplatsbi.a and firmwares are optional and only built when `PLATFORM=` parameter is specified to top-level make. @@ -78,4 +79,4 @@ We also prefer source level documentation, so wherever possible we describe stuff directly in the source code. This helps us maintain source and its documentation at the same place. For source level documentation we strictly follow Doxygen style. Please refer [Doxygen manual] -(http://www.stack.nl/~dimitri/doxygen/manual.html) for details. \ No newline at end of file +(http://www.stack.nl/~dimitri/doxygen/manual.html) for details. From fb3cbe6481e1a9dff80857ab2aa4812d4211c188 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Tue, 25 Dec 2018 15:50:29 +0900 Subject: [PATCH 0037/1765] Makefile: Fix clean Clean was doing nothing. Fix it to remove all compiled files, leaving only dependency files. Signed-off-by: Damien Le Moal --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ee00d65e760..bbd18f64291 100644 --- a/Makefile +++ b/Makefile @@ -280,7 +280,7 @@ clean: ifeq ($(build_dir),$(CURDIR)/build) $(V)mkdir -p $(build_dir) $(if $(V), @echo " CLEAN $(build_dir)") - $(V)find $(build_dir) -maxdepth 1 -type f -exec rm -rf {} + + $(V)find $(build_dir) -regex ".*\.\(o\|a\|elf\|bin\)" -type f -exec rm -rf {} + endif # Rule for "make distclean" From 23e2c594cc9ef3a51655252871ff3016f534cfe3 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Tue, 25 Dec 2018 15:37:04 +0900 Subject: [PATCH 0038/1765] README: Update Some rewrite with a more formal style. Signed-off-by: Damien Le Moal --- README.md | 170 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 100 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index 0588aa8d639..69a65c16773 100644 --- a/README.md +++ b/README.md @@ -4,79 +4,109 @@ RISC-V Open Source Supervisor Binary Interface (OpenSBI) The **RISC-V Supervisor Binary Interface (SBI)** is a recommended interface between: -1. Platform specific firmware running in M-mode and - general-purpose-os/hypervisor/bootloader running in S-mode/HS-mode -2. Hypervisor runnng in HS-mode and general-purpose-os/bootloader - running in VS-mode - -The **RISC-V SBI specification** is maintained as independent project -by RISC-V Foundation on [Github](https://github.com/riscv/riscv-sbi-doc) - -The **RISC-V OpenSBI project** aims to provides an open-source and -extensible implementation of the **RISC-V SBI specification** for -point 1) mentioned above. It can be easily extended by RISC-V platform -or RISC-V System-on-Chip vendors. - -We can create three things using the RISC-V OpenSBI project: - -1. **libsbi.a** - Generic OpenSBI static library -2. **libplatsbi.a** - Platform specific OpenSBI static library - (It is libsbi.a plus platform specific hooks represented - by "platform" symbol) -3. **firmwares** - Platform specific firmware binaries - -How to Build? -------------- - -For cross-compiling, the environment variable CROSS_COMPILE_PREFIX must be -defined to specify the toolchain executable name prefix, e.g. -"riscv64-unknown-elf-" for riscv64-unknown-elf-gcc. - -The libplatsbi.a and firmwares are optional and only built when -`PLATFORM=` parameter is specified to top-level make. -(**NOTE**: `` is sub-directory under platform/ directory) - -To build and install Generic OpenSBI library do the following: - -1. Build **libsbi.a**: -`make` -OR -`make O=` -2. Install **libsbi.a and headers**: -`make install` -OR -`make I= install` - -To build and install platform specific OpenSBI library and firmwares -do the following: - -1. Build **libsbi, libplatsbi, and firmwares**: -`make PLATFORM=` -OR -`make PLATFORM= O=` -2. Install **libsbi, headers, libplatsbi, and firmwares**: -`make PLATFORM= install` -OR -`make PLATFORM= I= install` - -In addition, we can also specify platform specific command-line -options to top-level make (such as `PLATFORM_` or `FW_`) -which are described under `docs/platform/.md` OR -`docs/firmware/.md`. +1. A pplatform specific firmware executed in M-mode and a general purpose + OS hypervisor or bootloader executed in S-mode or HS-mode. +2. A hypervisor executed in HS-mode and a general purpose OS or bootloader + executed in VS-mode + +The *RISC-V SBI specification* is maintained as an independent project +by the RISC-V Foundation in [Github](https://github.com/riscv/riscv-sbi-doc) + +OpenSBI aims to provides an open-source and extensible implementation of +the RISC-V SBI specification for case 1 mentioned above. OpenSBI +implementation can be easily extended by RISC-V platform or System-on-Chip +vendors to fit a particular hadware configuration. + +OpenSBI provides three components: + +1. *libsbi.a* - A generic OpenSBI static library +2. *libplatsbi.a* - Platform specific OpenSBI static library, that is, + libsbi.a plus platform specific hooks +3. *firmwares* - Platform specific bootable firmware binaries + +Building and Installing generic *libsbi.a* +------------------------------------------ + +For cross-compiling, the environment variable *CROSS_COMPILE_PREFIX* must +be defined to specify the toolchain executable name prefix, e.g. +*riscv64-unknown-elf-* if the gcc executable used is +*riscv64-unknown-elf-gcc*. + +To build the generic OpenSBI library *libsbi.a*, simply execute: +``` +make +``` + +All compiled binaries will be placed in the *build* directory. +To specify an alternate build directory target, run: +``` +make O= +``` + +To generate files to be installed for using *libsbi.a* in other projects, +run: +``` +make install +``` +This will create the *install* directory with all necessary include files +and binary files under it. To specify an alternate installation directory, +run: +``` +make I= install +``` + +Building and Installing platform specific *libsbi.a* and firmwares +------------------------------------------------------------------ + +The libplatsbi.a and firmware files are only built if the +*PLATFORM=* argument is specified on make command lines. +** must specify the path to one of the leaf directories +under the *platform* directory. For example, to compile the library and +firmware for QEMU generic RISC-V *virt* machine, ** +should be *qemu/virt*. + +To build *libsbi, libplatsbi, and firmwares* for a specific platform, run: +``` +make PLATFORM= +``` + +or + +``` +make PLATFORM= O= +``` + +To install *libsbi, headers, libplatsbi, and firmwares*, run: +``` +make PLATFORM= install +``` + +or + +``` +make PLATFORM= I= install` +``` + +In addition, platform specific make command-line options to top-level make +,such as *PLATFORM_* or *FW_* can also be specified. These +options are described under *docs/platform/.md* and +*docs/firmware/.md*. Documentation ------------- -All our documenation is under `docs` directory organized in following -manner: +A more detailed documenation is under the *docs* directory and organized +as follows. + +* *docs/platform_guide.md* - Guidelines for adding new platform support +* *docs/library_usage.md* - Guidelines for using the static library +* *docs/platform/.md* - Platform specific documentation for + the platform ** +* *docs/firmware/.md* - Platform specific documentation for + the firmware ** -* `docs/platform_guide.md` - Guidelines for adding new platform support -* `docs/library_usage.md` - Guidelines for using static library -* `docs/platform/.md` - Documentation for `` platform -* `docs/firmware/.md` - Documentation for firmware `` +The source code is also well documented. For source level documentation, +doxygen style is used. Please refer to [Doxygen manual] +(http://www.stack.nl/~dimitri/doxygen/manual.html) for details on this +format. -We also prefer source level documentation, so wherever possible we describe -stuff directly in the source code. This helps us maintain source and its -documentation at the same place. For source level documentation we strictly -follow Doxygen style. Please refer [Doxygen manual] -(http://www.stack.nl/~dimitri/doxygen/manual.html) for details. From fd7199920ed9cee84b07234db85b8fb3943664c2 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Wed, 26 Dec 2018 10:57:15 +0530 Subject: [PATCH 0039/1765] top: Rename back CROSS_COMPILE_PREFIX to CROSS_COMPILE The name CROSS_COMPILE is an industry standard used across open-source project to specify cross-compiler prefix. In fact, distro build systems such as buildroot and yocto assume CROSS_COMPILE to be supported by projects added as packages to these build systems. This patch rename back CROSS_COMPILE_PREFIX to CROSS_COMPILE. Signed-off-by: Anup Patel --- Makefile | 14 +++++++------- README.md | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index bbd18f64291..9c55559aa3d 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +102,7 @@ deps-y+=$(lib-objs-path-y:.o=.dep) deps-y+=$(firmware-objs-path-y:.o=.dep) # Setup compilation environment -cpp=$(CROSS_COMPILE_PREFIX)cpp +cpp=$(CROSS_COMPILE)cpp cppflags+=-DOPENSBI_MAJOR=$(MAJOR) cppflags+=-DOPENSBI_MINOR=$(MINOR) cppflags+=-I$(platform_dir)/include @@ -110,7 +110,7 @@ cppflags+=-I$(platform_common_dir)/include cppflags+=-I$(include_dir) cppflags+=$(platform-cppflags-y) cppflags+=$(firmware-cppflags-y) -cc=$(CROSS_COMPILE_PREFIX)gcc +cc=$(CROSS_COMPILE)gcc cflags=-g -Wall -Werror -nostdlib -fno-strict-aliasing -O2 cflags+=-fno-omit-frame-pointer -fno-optimize-sibling-calls cflags+=-mno-save-restore -mstrict-align @@ -118,7 +118,7 @@ cflags+=$(cppflags) cflags+=$(platform-cflags-y) cflags+=$(firmware-cflags-y) cflags+=$(EXTRA_CFLAGS) -as=$(CROSS_COMPILE_PREFIX)gcc +as=$(CROSS_COMPILE)gcc asflags=-g -Wall -nostdlib -D__ASSEMBLY__ asflags+=-fno-omit-frame-pointer -fno-optimize-sibling-calls asflags+=-mno-save-restore -mstrict-align @@ -126,15 +126,15 @@ asflags+=$(cppflags) asflags+=$(platform-asflags-y) asflags+=$(firmware-asflags-y) asflags+=$(EXTRA_ASFLAGS) -ar=$(CROSS_COMPILE_PREFIX)ar +ar=$(CROSS_COMPILE)ar arflags=rcs -ld=$(CROSS_COMPILE_PREFIX)gcc +ld=$(CROSS_COMPILE)gcc ldflags=-g -Wall -nostdlib -Wl,--build-id=none ldflags+=$(platform-ldflags-y) ldflags+=$(firmware-ldflags-y) -merge=$(CROSS_COMPILE_PREFIX)ld +merge=$(CROSS_COMPILE)ld mergeflags=-r -objcopy=$(CROSS_COMPILE_PREFIX)objcopy +objcopy=$(CROSS_COMPILE)objcopy # Setup functions for compilation define dynamic_flags diff --git a/README.md b/README.md index 69a65c16773..7b142d56e98 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ OpenSBI provides three components: Building and Installing generic *libsbi.a* ------------------------------------------ -For cross-compiling, the environment variable *CROSS_COMPILE_PREFIX* must +For cross-compiling, the environment variable *CROSS_COMPILE* must be defined to specify the toolchain executable name prefix, e.g. *riscv64-unknown-elf-* if the gcc executable used is *riscv64-unknown-elf-gcc*. From 96f66f79ca022eb4b591d319675b5ee0854ca45f Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Mon, 24 Dec 2018 16:45:00 +0530 Subject: [PATCH 0040/1765] lib: Move instruction encoding macros to riscv_encoding.h This patch moves all instruction encoding macros to riscv_encoding.h. Signed-off-by: Anup Patel --- include/sbi/riscv_encoding.h | 117 +++++++++++++++++++++++++++++++++++ include/sbi/sbi_bits.h | 15 ----- lib/sbi_illegal_insn.c | 50 --------------- 3 files changed, 117 insertions(+), 65 deletions(-) diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h index a4407d2c002..1adc0c55b1a 100644 --- a/include/sbi/riscv_encoding.h +++ b/include/sbi/riscv_encoding.h @@ -420,4 +420,121 @@ #define CAUSE_LOAD_PAGE_FAULT 0xd #define CAUSE_STORE_PAGE_FAULT 0xf +#define INSN_MATCH_LB 0x3 +#define INSN_MASK_LB 0x707f +#define INSN_MATCH_LH 0x1003 +#define INSN_MASK_LH 0x707f +#define INSN_MATCH_LW 0x2003 +#define INSN_MASK_LW 0x707f +#define INSN_MATCH_LD 0x3003 +#define INSN_MASK_LD 0x707f +#define INSN_MATCH_LBU 0x4003 +#define INSN_MASK_LBU 0x707f +#define INSN_MATCH_LHU 0x5003 +#define INSN_MASK_LHU 0x707f +#define INSN_MATCH_LWU 0x6003 +#define INSN_MASK_LWU 0x707f +#define INSN_MATCH_SB 0x23 +#define INSN_MASK_SB 0x707f +#define INSN_MATCH_SH 0x1023 +#define INSN_MASK_SH 0x707f +#define INSN_MATCH_SW 0x2023 +#define INSN_MASK_SW 0x707f +#define INSN_MATCH_SD 0x3023 +#define INSN_MASK_SD 0x707f + +#define INSN_MATCH_C_LD 0x6000 +#define INSN_MASK_C_LD 0xe003 +#define INSN_MATCH_C_SD 0xe000 +#define INSN_MASK_C_SD 0xe003 +#define INSN_MATCH_C_LW 0x4000 +#define INSN_MASK_C_LW 0xe003 +#define INSN_MATCH_C_SW 0xc000 +#define INSN_MASK_C_SW 0xe003 +#define INSN_MATCH_C_LDSP 0x6002 +#define INSN_MASK_C_LDSP 0xe003 +#define INSN_MATCH_C_SDSP 0xe002 +#define INSN_MASK_C_SDSP 0xe003 +#define INSN_MATCH_C_LWSP 0x4002 +#define INSN_MASK_C_LWSP 0xe003 +#define INSN_MATCH_C_SWSP 0xc002 +#define INSN_MASK_C_SWSP 0xe003 + +#define INSN_MATCH_C_FLD 0x2000 +#define INSN_MASK_C_FLD 0xe003 +#define INSN_MATCH_C_FLW 0x6000 +#define INSN_MASK_C_FLW 0xe003 +#define INSN_MATCH_C_FSD 0xa000 +#define INSN_MASK_C_FSD 0xe003 +#define INSN_MATCH_C_FSW 0xe000 +#define INSN_MASK_C_FSW 0xe003 +#define INSN_MATCH_C_FLDSP 0x2002 +#define INSN_MASK_C_FLDSP 0xe003 +#define INSN_MATCH_C_FSDSP 0xa002 +#define INSN_MASK_C_FSDSP 0xe003 +#define INSN_MATCH_C_FLWSP 0x6002 +#define INSN_MASK_C_FLWSP 0xe003 +#define INSN_MATCH_C_FSWSP 0xe002 +#define INSN_MASK_C_FSWSP 0xe003 + +#define INSN_LEN(insn) ((((insn) & 0x3) < 0x3) ? 2 : 4) + +#if __riscv_xlen == 64 +#define LOG_REGBYTES 3 +#else +#define LOG_REGBYTES 2 +#endif +#define REGBYTES (1 << LOG_REGBYTES) + +#define SH_RD 7 +#define SH_RS1 15 +#define SH_RS2 20 +#define SH_RS2C 2 + +#define RV_X(x, s, n) (((x) >> (s)) & ((1 << (n)) - 1)) +#define RVC_LW_IMM(x) ((RV_X(x, 6, 1) << 2) | \ + (RV_X(x, 10, 3) << 3) | \ + (RV_X(x, 5, 1) << 6)) +#define RVC_LD_IMM(x) ((RV_X(x, 10, 3) << 3) | \ + (RV_X(x, 5, 2) << 6)) +#define RVC_LWSP_IMM(x) ((RV_X(x, 4, 3) << 2) | \ + (RV_X(x, 12, 1) << 5) | \ + (RV_X(x, 2, 2) << 6)) +#define RVC_LDSP_IMM(x) ((RV_X(x, 5, 2) << 3) | \ + (RV_X(x, 12, 1) << 5) | \ + (RV_X(x, 2, 3) << 6)) +#define RVC_SWSP_IMM(x) ((RV_X(x, 9, 4) << 2) | \ + (RV_X(x, 7, 2) << 6)) +#define RVC_SDSP_IMM(x) ((RV_X(x, 10, 3) << 3) | \ + (RV_X(x, 7, 3) << 6)) +#define RVC_RS1S(insn) (8 + RV_X(insn, SH_RD, 3)) +#define RVC_RS2S(insn) (8 + RV_X(insn, SH_RS2C, 3)) +#define RVC_RS2(insn) RV_X(insn, SH_RS2C, 5) + +#define SHIFT_RIGHT(x, y) \ + ((y) < 0 ? ((x) << -(y)) : ((x) >> (y))) + +#define REG_MASK \ + ((1 << (5 + LOG_REGBYTES)) - (1 << LOG_REGBYTES)) + +#define REG_OFFSET(insn, pos) \ + (SHIFT_RIGHT((insn), (pos) - LOG_REGBYTES) & REG_MASK) + +#define REG_PTR(insn, pos, regs) \ + (ulong *)((ulong)(regs) + REG_OFFSET(insn, pos)) + +#define GET_RM(insn) (((insn) >> 12) & 7) + +#define GET_RS1(insn, regs) (*REG_PTR(insn, SH_RS1, regs)) +#define GET_RS2(insn, regs) (*REG_PTR(insn, SH_RS2, regs)) +#define GET_RS1S(insn, regs) (*REG_PTR(RVC_RS1S(insn), 0, regs)) +#define GET_RS2S(insn, regs) (*REG_PTR(RVC_RS2S(insn), 0, regs)) +#define GET_RS2C(insn, regs) (*REG_PTR(insn, SH_RS2C, regs)) +#define GET_SP(regs) (*REG_PTR(2, 0, regs)) +#define SET_RD(insn, regs, val) (*REG_PTR(insn, SH_RD, regs) = (val)) +#define IMM_I(insn) ((s32)(insn) >> 20) +#define IMM_S(insn) (((s32)(insn) >> 25 << 5) | \ + (s32)(((insn) >> 7) & 0x1f)) +#define MASK_FUNCT3 0x7000 + #endif diff --git a/include/sbi/sbi_bits.h b/include/sbi/sbi_bits.h index 118fab23c9f..2a2f2a5c63b 100644 --- a/include/sbi/sbi_bits.h +++ b/include/sbi/sbi_bits.h @@ -26,19 +26,4 @@ #define STR(x) XSTR(x) #define XSTR(x) #x -#if __riscv_xlen == 64 -#define SLL32 sllw -#define STORE sd -#define LOAD ld -#define LWU lwu -#define LOG_REGBYTES 3 -#else -#define SLL32 sll -#define STORE sw -#define LOAD lw -#define LWU lw -#define LOG_REGBYTES 2 -#endif -#define REGBYTES (1 << LOG_REGBYTES) - #endif diff --git a/lib/sbi_illegal_insn.c b/lib/sbi_illegal_insn.c index e8edd0e4bc2..9383df47e4c 100644 --- a/lib/sbi_illegal_insn.c +++ b/lib/sbi_illegal_insn.c @@ -16,56 +16,6 @@ #include #include -#define SH_RD 7 -#define SH_RS1 15 -#define SH_RS2 20 -#define SH_RS2C 2 - -#define RV_X(x, s, n) (((x) >> (s)) & ((1 << (n)) - 1)) -#define RVC_LW_IMM(x) ((RV_X(x, 6, 1) << 2) | \ - (RV_X(x, 10, 3) << 3) | \ - (RV_X(x, 5, 1) << 6)) -#define RVC_LD_IMM(x) ((RV_X(x, 10, 3) << 3) | \ - (RV_X(x, 5, 2) << 6)) -#define RVC_LWSP_IMM(x) ((RV_X(x, 4, 3) << 2) | \ - (RV_X(x, 12, 1) << 5) | \ - (RV_X(x, 2, 2) << 6)) -#define RVC_LDSP_IMM(x) ((RV_X(x, 5, 2) << 3) | \ - (RV_X(x, 12, 1) << 5) | \ - (RV_X(x, 2, 3) << 6)) -#define RVC_SWSP_IMM(x) ((RV_X(x, 9, 4) << 2) | \ - (RV_X(x, 7, 2) << 6)) -#define RVC_SDSP_IMM(x) ((RV_X(x, 10, 3) << 3) | \ - (RV_X(x, 7, 3) << 6)) -#define RVC_RS1S(insn) (8 + RV_X(insn, SH_RD, 3)) -#define RVC_RS2S(insn) (8 + RV_X(insn, SH_RS2C, 3)) -#define RVC_RS2(insn) RV_X(insn, SH_RS2C, 5) - -#define SHIFT_RIGHT(x, y) ((y) < 0 ? ((x) << -(y)) : ((x) >> (y))) - -#define REG_MASK \ -((1 << (5 + LOG_REGBYTES)) - (1 << LOG_REGBYTES)) - -#define REG_OFFSET(insn, pos) \ -(SHIFT_RIGHT((insn), (pos) - LOG_REGBYTES) & REG_MASK) - -#define REG_PTR(insn, pos, regs)\ -(ulong *)((ulong)(regs) + REG_OFFSET(insn, pos)) - -#define GET_RM(insn) (((insn) >> 12) & 7) - -#define GET_RS1(insn, regs) (*REG_PTR(insn, SH_RS1, regs)) -#define GET_RS2(insn, regs) (*REG_PTR(insn, SH_RS2, regs)) -#define GET_RS1S(insn, regs) (*REG_PTR(RVC_RS1S(insn), 0, regs)) -#define GET_RS2S(insn, regs) (*REG_PTR(RVC_RS2S(insn), 0, regs)) -#define GET_RS2C(insn, regs) (*REG_PTR(insn, SH_RS2C, regs)) -#define GET_SP(regs) (*REG_PTR(2, 0, regs)) -#define SET_RD(insn, regs, val) (*REG_PTR(insn, SH_RD, regs) = (val)) -#define IMM_I(insn) ((s32)(insn) >> 20) -#define IMM_S(insn) (((s32)(insn) >> 25 << 5) | \ - (s32)(((insn) >> 7) & 0x1f)) -#define MASK_FUNCT3 0x7000 - typedef int (*illegal_insn_func)(ulong insn, u32 hartid, ulong mcause, struct sbi_trap_regs *regs, From b5ae8e8a650d8cb0134f03f53472fb026d2ee6e6 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Mon, 24 Dec 2018 16:49:01 +0530 Subject: [PATCH 0041/1765] lib: Add misaligned load/store trap handling We generally don't get misaligned load/store traps from Linux/U-Boot compiled using GCC 8.2 or higher but this is not true with older GCC toolchains. To tackle this we add misaligned load/store trap handling adopted from BBL sources but much more simpler. (Note: BBL sources can be found at https://github.com/riscv/riscv-pk.git) Signed-off-by: Anup Patel --- include/sbi/sbi_misaligned_ldst.h | 26 ++++++ lib/objects.mk | 1 + lib/sbi_misaligned_ldst.c | 129 ++++++++++++++++++++++++++++++ lib/sbi_trap.c | 11 ++- 4 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 include/sbi/sbi_misaligned_ldst.h create mode 100644 lib/sbi_misaligned_ldst.c diff --git a/include/sbi/sbi_misaligned_ldst.h b/include/sbi/sbi_misaligned_ldst.h new file mode 100644 index 00000000000..16419586368 --- /dev/null +++ b/include/sbi/sbi_misaligned_ldst.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2018 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#ifndef __SBI_MISALIGNED_LDST_H__ +#define __SBI_MISALIGNED_LDST_H__ + +#include + +struct sbi_trap_regs; +struct sbi_scratch; + +int sbi_misaligned_load_handler(u32 hartid, ulong mcause, + struct sbi_trap_regs *regs, + struct sbi_scratch *scratch); + +int sbi_misaligned_store_handler(u32 hartid, ulong mcause, + struct sbi_trap_regs *regs, + struct sbi_scratch *scratch); + +#endif diff --git a/lib/objects.mk b/lib/objects.mk index ed14677f2a9..b70557ddad7 100644 --- a/lib/objects.mk +++ b/lib/objects.mk @@ -18,6 +18,7 @@ lib-objs-y += sbi_hart.o lib-objs-y += sbi_illegal_insn.o lib-objs-y += sbi_init.o lib-objs-y += sbi_ipi.o +lib-objs-y += sbi_misaligned_ldst.o lib-objs-y += sbi_system.o lib-objs-y += sbi_timer.o lib-objs-y += sbi_trap.o diff --git a/lib/sbi_misaligned_ldst.c b/lib/sbi_misaligned_ldst.c new file mode 100644 index 00000000000..b35e919ac70 --- /dev/null +++ b/lib/sbi_misaligned_ldst.c @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2018 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include +#include +#include + +union reg_data { + u8 data_bytes[8]; + ulong data_ulong; + u64 data_u64; +}; + +int sbi_misaligned_load_handler(u32 hartid, ulong mcause, + struct sbi_trap_regs *regs, + struct sbi_scratch *scratch) +{ + union reg_data val; + ulong mstatus = csr_read(mstatus); + ulong insn = get_insn(regs->mepc, &mstatus); + ulong addr = csr_read(mtval); + int i, shift = 0, len = 0; + + if ((insn & INSN_MASK_LW) == INSN_MATCH_LW) { + len = 4; + shift = 8 * (sizeof(ulong) - len); +#if __riscv_xlen == 64 + } else if ((insn & INSN_MASK_LD) == INSN_MATCH_LD) { + len = 8; + shift = 8 * (sizeof(ulong) - len); + } else if ((insn & INSN_MASK_LWU) == INSN_MATCH_LWU) { + len = 4; +#endif + } else if ((insn & INSN_MASK_LH) == INSN_MATCH_LH) { + len = 2; + shift = 8 * (sizeof(ulong) - len); + } else if ((insn & INSN_MASK_LHU) == INSN_MATCH_LHU) { + len = 2; +#ifdef __riscv_compressed +# if __riscv_xlen >= 64 + } else if ((insn & INSN_MASK_C_LD) == INSN_MATCH_C_LD) { + len = 8; + shift = 8 * (sizeof(ulong) - len); + insn = RVC_RS2S(insn) << SH_RD; + } else if ((insn & INSN_MASK_C_LDSP) == INSN_MATCH_C_LDSP && + ((insn >> SH_RD) & 0x1f)) { + len = 8; + shift = 8 * (sizeof(ulong) - len); +# endif + } else if ((insn & INSN_MASK_C_LW) ==INSN_MATCH_C_LW) { + len = 4; + shift = 8 * (sizeof(ulong) - len); + insn = RVC_RS2S(insn) << SH_RD; + } else if ((insn & INSN_MASK_C_LWSP) == INSN_MATCH_C_LWSP && + ((insn >> SH_RD) & 0x1f)) { + len = 4; + shift = 8 * (sizeof(ulong) - len); +#endif + } else + return SBI_EILL; + + val.data_u64 = 0; + for (i = 0; i < len; i++) + val.data_bytes[i] = load_u8((void *)(addr + i), regs->mepc); + + SET_RD(insn, regs, val.data_ulong << shift >> shift); + + regs->mepc += INSN_LEN(insn); + + return 0; +} + +int sbi_misaligned_store_handler(u32 hartid, ulong mcause, + struct sbi_trap_regs *regs, + struct sbi_scratch *scratch) +{ + union reg_data val; + ulong mstatus = csr_read(mstatus); + ulong insn = get_insn(regs->mepc, &mstatus); + ulong addr = csr_read(mtval); + int i, len = 0; + + val.data_ulong = GET_RS2(insn, regs); + + if ((insn & INSN_MASK_SW) == INSN_MATCH_SW) { + len = 4; +#if __riscv_xlen == 64 + } else if ((insn & INSN_MASK_SD) == INSN_MATCH_SD) { + len = 8; +#endif + } else if ((insn & INSN_MASK_SH) == INSN_MATCH_SH) { + len = 2; +#ifdef __riscv_compressed +# if __riscv_xlen >= 64 + } else if ((insn & INSN_MASK_C_SD) == INSN_MATCH_C_SD) { + len = 8; + val.data_ulong = GET_RS2S(insn, regs); + } else if ((insn & INSN_MASK_C_SDSP) == INSN_MATCH_C_SDSP && + ((insn >> SH_RD) & 0x1f)) { + len = 8; + val.data_ulong = GET_RS2C(insn, regs); +# endif + } else if ((insn & INSN_MASK_C_SW) == INSN_MATCH_C_SW) { + len = 4; + val.data_ulong = GET_RS2S(insn, regs); + } else if ((insn & INSN_MASK_C_SWSP) == INSN_MATCH_C_SWSP && + ((insn >> SH_RD) & 0x1f)) { + len = 4; + val.data_ulong = GET_RS2C(insn, regs); +#endif + } else + return SBI_EILL; + + for (i = 0; i < len; i++) + store_u8((void *)(addr + i), val.data_bytes[i], regs->mepc); + + regs->mepc += INSN_LEN(insn); + + return 0; +} diff --git a/lib/sbi_trap.c b/lib/sbi_trap.c index 284bb74f009..012a9a001a2 100644 --- a/lib/sbi_trap.c +++ b/lib/sbi_trap.c @@ -12,9 +12,10 @@ #include #include #include -#include #include +#include #include +#include #include #include @@ -95,6 +96,14 @@ void sbi_trap_handler(struct sbi_trap_regs *regs, rc = sbi_illegal_insn_handler(hartid, mcause, regs, scratch); msg = "illegal instruction handler failed"; break; + case CAUSE_MISALIGNED_LOAD: + rc = sbi_misaligned_load_handler(hartid, mcause, regs, scratch); + msg = "misaligned load handler failed"; + break; + case CAUSE_MISALIGNED_STORE: + rc = sbi_misaligned_store_handler(hartid, mcause, regs, scratch); + msg = "misaligned store handler failed"; + break; case CAUSE_SUPERVISOR_ECALL: case CAUSE_HYPERVISOR_ECALL: rc = sbi_ecall_handler(hartid, mcause, regs, scratch); From b46970b47e63dce030ef6d4196f7c395a9ea23c1 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Wed, 26 Dec 2018 09:42:26 +0530 Subject: [PATCH 0042/1765] lib: Move ECALL defines to sbi_ecall_interface.h This patch moves all ECALL defines to sbi_ecall_interface.h so that it can be shared with firmware payloads. Signed-off-by: Anup Patel --- include/sbi/sbi_ecall_interface.h | 39 +++++++++++++++++++++++++++++++ lib/sbi_ecall.c | 11 +-------- 2 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 include/sbi/sbi_ecall_interface.h diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h new file mode 100644 index 00000000000..53de6a4de8c --- /dev/null +++ b/include/sbi/sbi_ecall_interface.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2018 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#ifndef __SBI_ECALL_INTERFACE_H__ +#define __SBI_ECALL_INTERFACE_H__ + +#define SBI_ECALL_SET_TIMER 0 +#define SBI_ECALL_CONSOLE_PUTCHAR 1 +#define SBI_ECALL_CONSOLE_GETCHAR 2 +#define SBI_ECALL_CLEAR_IPI 3 +#define SBI_ECALL_SEND_IPI 4 +#define SBI_ECALL_REMOTE_FENCE_I 5 +#define SBI_ECALL_REMOTE_SFENCE_VMA 6 +#define SBI_ECALL_REMOTE_SFENCE_VMA_ASID 7 +#define SBI_ECALL_SHUTDOWN 8 + +#define SBI_ECALL(__num, __a0, __a1, __a2) ({ \ + register unsigned long a0 asm ("a0") = (unsigned long)(__a0); \ + register unsigned long a1 asm ("a1") = (unsigned long)(__a1); \ + register unsigned long a2 asm ("a2") = (unsigned long)(__a2); \ + register unsigned long a7 asm ("a7") = (unsigned long)(__num);\ + asm volatile ("ecall" \ + : "+r" (a0) \ + : "r" (a1), "r" (a2), "r" (a7) \ + : "memory"); \ + a0; \ +}) + +#define SBI_ECALL_0(__num) SBI_ECALL(__num, 0, 0, 0) +#define SBI_ECALL_1(__num, __a0) SBI_ECALL(__num, __a0, 0, 0) +#define SBI_ECALL_2(__num, __a0, __a1) SBI_ECALL(__num, __a0, __a1, 0) + +#endif diff --git a/lib/sbi_ecall.c b/lib/sbi_ecall.c index 928a8b757be..731a6652a7b 100644 --- a/lib/sbi_ecall.c +++ b/lib/sbi_ecall.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -18,16 +19,6 @@ #define SBI_ECALL_VERSION_MAJOR 0 #define SBI_ECALL_VERSION_MINOR 1 -#define SBI_ECALL_SET_TIMER 0 -#define SBI_ECALL_CONSOLE_PUTCHAR 1 -#define SBI_ECALL_CONSOLE_GETCHAR 2 -#define SBI_ECALL_CLEAR_IPI 3 -#define SBI_ECALL_SEND_IPI 4 -#define SBI_ECALL_REMOTE_FENCE_I 5 -#define SBI_ECALL_REMOTE_SFENCE_VMA 6 -#define SBI_ECALL_REMOTE_SFENCE_VMA_ASID 7 -#define SBI_ECALL_SHUTDOWN 8 - u16 sbi_ecall_version_major(void) { return SBI_ECALL_VERSION_MAJOR; From bb3665d0f097745f5f081e687b7487f3bbed3500 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Wed, 26 Dec 2018 09:44:49 +0530 Subject: [PATCH 0043/1765] firmware: Add separate dummy payload for FW_PAYLOAD Currently, the default payload for FW_PAYLOAD is embedded fw_payload.S itself. This means people have to hack fw_payload.S if they want to have some temporary S-mode test code. This patch adds a separate dummy payload for FW_PAYLOAD which can be easily hacked for some S-mode testing. Signed-off-by: Anup Patel --- firmware/payloads/dummy.elf.ldS | 83 +++++++++++++++++++++++++++++++ firmware/payloads/dummy_head.S | 87 +++++++++++++++++++++++++++++++++ firmware/payloads/dummy_main.c | 31 ++++++++++++ firmware/payloads/objects.mk | 19 +++++++ 4 files changed, 220 insertions(+) create mode 100644 firmware/payloads/dummy.elf.ldS create mode 100644 firmware/payloads/dummy_head.S create mode 100644 firmware/payloads/dummy_main.c create mode 100644 firmware/payloads/objects.mk diff --git a/firmware/payloads/dummy.elf.ldS b/firmware/payloads/dummy.elf.ldS new file mode 100644 index 00000000000..b4d9f757841 --- /dev/null +++ b/firmware/payloads/dummy.elf.ldS @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2018 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +OUTPUT_ARCH(riscv) +ENTRY(_start) + +SECTIONS +{ + . = FW_TEXT_START + FW_PAYLOAD_OFFSET; + + PROVIDE(_payload_start = .); + + . = ALIGN(0x1000); /* Need this to create proper sections */ + + /* Beginning of the code section */ + + .text : + { + PROVIDE(_text_start = .); + *(.entry) + *(.text) + . = ALIGN(8); + 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 */ + + .rodata : + { + PROVIDE(_rodata_start = .); + *(.rodata .rodata.*) + . = ALIGN(8); + PROVIDE(_rodata_end = .); + } + + /* End of the read-only data sections */ + + /* Beginning of the read-write data sections */ + + . = ALIGN(0x1000); /* Ensure next section is page aligned */ + + .data : + { + PROVIDE(_data_start = .); + + *(.data) + *(.data.*) + *(.readmostly.data) + *(*.data) + . = ALIGN(8); + + PROVIDE(_data_end = .); + } + + . = ALIGN(0x1000); /* Ensure next section is page aligned */ + + .bss : + { + PROVIDE(_bss_start = .); + *(.bss) + *(.bss.*) + . = ALIGN(8); + PROVIDE(_bss_end = .); + } + + /* End of the read-write data sections */ + + . = ALIGN(0x1000); /* Need this to create proper sections */ + + PROVIDE(_payload_end = .); +} diff --git a/firmware/payloads/dummy_head.S b/firmware/payloads/dummy_head.S new file mode 100644 index 00000000000..1b36319e84b --- /dev/null +++ b/firmware/payloads/dummy_head.S @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2018 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#define __ASM_STR(x) x + +#if __riscv_xlen == 64 +#define __REG_SEL(a, b) __ASM_STR(a) +#define RISCV_PTR .dword +#elif __riscv_xlen == 32 +#define __REG_SEL(a, b) __ASM_STR(b) +#define RISCV_PTR .word +#else +#error "Unexpected __riscv_xlen" +#endif + +#define REG_L __REG_SEL(ld, lw) +#define REG_S __REG_SEL(sd, sw) + + .align 3 + .section .entry, "ax", %progbits + .globl _start +_start: + /* Pick one hart to run the main boot sequence */ + la a3, _hart_lottery + li a2, 1 + amoadd.w a3, a2, (a3) + bnez a3, _start_hang + + /* Save a0 and a1 */ + la a3, _boot_a0 + REG_S a0, 0(a3) + la a3, _boot_a1 + REG_S a1, 0(a3) + + /* Zero-out BSS */ + la a4, _bss_start + la a5, _bss_end +_bss_zero: + REG_S zero, (a4) + add a4, a4, __SIZEOF_POINTER__ + blt a4, a5, _bss_zero + +_start_warm: + /* Disable and clear all interrupts */ + csrw sie, zero + csrw sip, zero + + /* Setup exception vectors */ + la a3, _start_hang + csrw stvec, a3 + + /* Setup stack */ + la a3, _payload_end + li a4, 0x2000 + add sp, a3, a4 + + /* Jump to C main */ + la a3, _boot_a0 + REG_L a0, 0(a3) + la a3, _boot_a1 + REG_L a1, 0(a3) + call dummy_main + + /* We don't expect to reach here hence just hang */ + j _start_hang + + .align 3 + .section .entry, "ax", %progbits + .globl _start_hang +_start_hang: + wfi + j _start_hang + + .align 3 + .section .entry, "ax", %progbits +_hart_lottery: + RISCV_PTR 0 +_boot_a0: + RISCV_PTR 0 +_boot_a1: + RISCV_PTR 0 diff --git a/firmware/payloads/dummy_main.c b/firmware/payloads/dummy_main.c new file mode 100644 index 00000000000..d4bc3603b02 --- /dev/null +++ b/firmware/payloads/dummy_main.c @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +#define wfi() \ +do { \ + __asm__ __volatile__ ("wfi" ::: "memory"); \ +} while (0) + +static void sbi_puts(const char *str) +{ + while (*str) { + SBI_ECALL_1(SBI_ECALL_CONSOLE_PUTCHAR, *str); + str++; + } +} + +void dummy_main(unsigned long a0, unsigned long a1) +{ + sbi_puts("\nDummy Payload\n"); + + while (1) + wfi(); +} diff --git a/firmware/payloads/objects.mk b/firmware/payloads/objects.mk new file mode 100644 index 00000000000..7e82b773055 --- /dev/null +++ b/firmware/payloads/objects.mk @@ -0,0 +1,19 @@ +# +# Copyright (c) 2018 Western Digital Corporation or its affiliates. +# +# Authors: +# Anup Patel +# +# SPDX-License-Identifier: BSD-2-Clause +# + +firmware-bins-$(FW_PAYLOAD) += payloads/dummy.bin + +dummy-y += dummy_head.o +dummy-y += dummy_main.o + +%/dummy.o: $(foreach obj,$(dummy-y),%/$(obj)) + $(call merge_objs,$@,$^) + +%/dummy.dep: $(foreach dep,$(dummy-y:.o=.dep),%/$(dep)) + $(call merge_deps,$@,$^) From 2d90226e04a6b886e9f09e6e1328600134f1a754 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Mon, 24 Dec 2018 10:53:10 +0530 Subject: [PATCH 0044/1765] firmware: Use dummy payload for FW_PAYLOAD We use recently added separate dummy payload for FW_PAYLOAD when FW_PAYLOAD_PATH is not specified. Signed-off-by: Anup Patel --- Makefile | 5 ++++- firmware/external_deps.mk | 10 ++++++++++ firmware/objects.mk | 13 ++++++++----- 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 firmware/external_deps.mk diff --git a/Makefile b/Makefile index 9c55559aa3d..9c19729e24b 100644 --- a/Makefile +++ b/Makefile @@ -243,12 +243,15 @@ $(build_dir)/$(platform_subdir)/%.dep: $(src_dir)/%.S $(build_dir)/$(platform_subdir)/%.o: $(src_dir)/%.S $(call compile_as,$@,$<) -# Dependency files should only be included after default Makefile rule +# Dependency files should only be included after default Makefile rules # They should not be included for any "xxxconfig" or "xxxclean" rule all-deps-1 = $(if $(findstring config,$(MAKECMDGOALS)),,$(deps-y)) all-deps-2 = $(if $(findstring clean,$(MAKECMDGOALS)),,$(all-deps-1)) -include $(all-deps-2) +# Include external dependency of firmwares after default Makefile rules +include $(src_dir)/firmware/external_deps.mk + install_targets-y = install_libsbi ifdef PLATFORM install_targets-y += install_libplatsbi diff --git a/firmware/external_deps.mk b/firmware/external_deps.mk new file mode 100644 index 00000000000..3a0847e9367 --- /dev/null +++ b/firmware/external_deps.mk @@ -0,0 +1,10 @@ +# +# Copyright (c) 2018 Western Digital Corporation or its affiliates. +# +# Authors: +# Anup Patel +# +# SPDX-License-Identifier: BSD-2-Clause +# + +$(build_dir)/$(platform_subdir)/firmware/fw_payload.o: $(FW_PAYLOAD_PATH_FINAL) diff --git a/firmware/objects.mk b/firmware/objects.mk index 9bed733de64..a8275f9f40b 100644 --- a/firmware/objects.mk +++ b/firmware/objects.mk @@ -7,10 +7,10 @@ # SPDX-License-Identifier: BSD-2-Clause # -firmware-cppflags-y = -firmware-cflags-y = -firmware-asflags-y = -firmware-ldflags-y = +firmware-cppflags-y += +firmware-cflags-y += +firmware-asflags-y += +firmware-ldflags-y += ifdef FW_TEXT_START firmware-cppflags-y += -DFW_TEXT_START=$(FW_TEXT_START) @@ -26,8 +26,11 @@ endif firmware-bins-$(FW_PAYLOAD) += fw_payload.bin ifdef FW_PAYLOAD_PATH -firmware-cppflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_PATH=$(FW_PAYLOAD_PATH) +FW_PAYLOAD_PATH_FINAL=$(FW_PAYLOAD_PATH) +else +FW_PAYLOAD_PATH_FINAL=$(build_dir)/$(platform_subdir)/firmware/payloads/dummy.bin endif +firmware-cppflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_PATH=$(FW_PAYLOAD_PATH_FINAL) ifdef FW_PAYLOAD_OFFSET firmware-cppflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_OFFSET=$(FW_PAYLOAD_OFFSET) endif From a4ce7931212dd71af0b1e30379eddfa4adac21f7 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Mon, 24 Dec 2018 12:15:32 +0530 Subject: [PATCH 0045/1765] top: Improve inst_file_list() in Makefile for payloads installation We now have payloads sub-directory under firmware directory which means payload BINs and ELFs should be installed under firmware/payloads. This patch improves inst_file_list() to handle payloads sub-directory under firmware installation directory. Signed-off-by: Anup Patel --- Makefile | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 9c19729e24b..33f4de6ba55 100644 --- a/Makefile +++ b/Makefile @@ -152,11 +152,15 @@ copy_file = $(V)mkdir -p `dirname $(1)`; \ inst_file = $(V)mkdir -p `dirname $(1)`; \ echo " INSTALL $(subst $(install_dir)/,,$(1))"; \ cp -f $(2) $(1) -inst_file_list = $(V)if [ ! -z "$(3)" ]; then \ - mkdir -p $(1); \ - for f in $(3) ; do \ - echo " INSTALL "$(2)"/"`basename $$f`; \ - cp -f $$f $(1); \ +inst_file_list = $(V)if [ ! -z "$(4)" ]; then \ + mkdir -p $(1)/$(3); \ + for file in $(4) ; do \ + rel_file=`echo $$file | sed -e 's@$(2)/$(3)/@@'`; \ + dest_file=$(1)"/"$(3)"/"`echo $$rel_file`; \ + dest_dir=`dirname $$dest_file`; \ + echo " INSTALL "$(3)"/"`echo $$rel_file`; \ + mkdir -p $$dest_dir; \ + cp -f $$file $$dest_file; \ done \ fi inst_header_dir = $(V)mkdir -p $(1); \ @@ -274,8 +278,8 @@ install_libplatsbi: $(build_dir)/$(platform_subdir)/lib/libplatsbi.a $(build_dir .PHONY: install_firmwares install_firmwares: $(build_dir)/$(platform_subdir)/lib/libplatsbi.a $(build_dir)/lib/libsbi.a $(firmware-bins-path-y) - $(call inst_file_list,$(install_dir)/$(platform_subdir)/firmware,$(platform_subdir)/firmware,$(firmware-elfs-path-y)) - $(call inst_file_list,$(install_dir)/$(platform_subdir)/firmware,$(platform_subdir)/firmware,$(firmware-bins-path-y)) + $(call inst_file_list,$(install_dir),$(build_dir),$(platform_subdir)/firmware,$(firmware-elfs-path-y)) + $(call inst_file_list,$(install_dir),$(build_dir),$(platform_subdir)/firmware,$(firmware-bins-path-y)) # Rule for "make clean" .PHONY: clean From 4c1d5a5d2dad51a90d2617cd9f4187e6eb8f4159 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Wed, 26 Dec 2018 11:06:54 +0530 Subject: [PATCH 0046/1765] top: Improve 'clean' and 'distclean' makefile targets This improves 'clean' and 'distclean' makefile target as follows: 1. Remove only .o, .a, .elf, and .bin files for 'clean' 2. Remove .dep in-addition to what 'clean' does for 'distclean' 3. Remove default build and install directory for 'distclean' Signed-off-by: Anup Patel --- Makefile | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 33f4de6ba55..346456548b1 100644 --- a/Makefile +++ b/Makefile @@ -284,20 +284,27 @@ install_firmwares: $(build_dir)/$(platform_subdir)/lib/libplatsbi.a $(build_dir) # Rule for "make clean" .PHONY: clean clean: -ifeq ($(build_dir),$(CURDIR)/build) $(V)mkdir -p $(build_dir) - $(if $(V), @echo " CLEAN $(build_dir)") - $(V)find $(build_dir) -regex ".*\.\(o\|a\|elf\|bin\)" -type f -exec rm -rf {} + -endif + $(if $(V), @echo " RM /*.o") + $(V)find $(build_dir) -type f -name "*.o" -exec rm -rf {} + + $(if $(V), @echo " RM /*.a") + $(V)find $(build_dir) -type f -name "*.a" -exec rm -rf {} + + $(if $(V), @echo " RM /*.elf") + $(V)find $(build_dir) -type f -name "*.elf" -exec rm -rf {} + + $(if $(V), @echo " RM /*.bin") + $(V)find $(build_dir) -type f -name "*.bin" -exec rm -rf {} + # Rule for "make distclean" .PHONY: distclean -distclean: +distclean: clean + $(V)mkdir -p $(build_dir) + $(if $(V), @echo " RM /*.dep") + $(V)find $(build_dir) -type f -name "*.dep" -exec rm -rf {} + ifeq ($(build_dir),$(CURDIR)/build) - $(if $(V), @echo " RM $(build_dir)") + $(if $(V), @echo " RM ") $(V)rm -rf $(build_dir) endif ifeq ($(install_dir),$(CURDIR)/install) - $(if $(V), @echo " RM $(install_dir)") + $(if $(V), @echo " RM ") $(V)rm -rf $(install_dir) endif From cfa3fba14f27f1fabaa8194d1ea1a6a21c2cc83a Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Wed, 26 Dec 2018 10:43:15 +0530 Subject: [PATCH 0047/1765] firmware: Rename fw_common.S to fw_base.S The fw_common.S is the base firmware extendend by fw_jump and fw_payload. This patch renames fw_common.S to fw_base.S to have more clear/intutive name for base firmware. Signed-off-by: Anup Patel --- firmware/{fw_common.S => fw_base.S} | 0 firmware/{fw_common.ldS => fw_base.ldS} | 0 firmware/fw_jump.S | 2 +- firmware/fw_jump.elf.ldS | 2 +- firmware/fw_payload.S | 2 +- firmware/fw_payload.elf.ldS | 2 +- 6 files changed, 4 insertions(+), 4 deletions(-) rename firmware/{fw_common.S => fw_base.S} (100%) rename firmware/{fw_common.ldS => fw_base.ldS} (100%) diff --git a/firmware/fw_common.S b/firmware/fw_base.S similarity index 100% rename from firmware/fw_common.S rename to firmware/fw_base.S diff --git a/firmware/fw_common.ldS b/firmware/fw_base.ldS similarity index 100% rename from firmware/fw_common.ldS rename to firmware/fw_base.ldS diff --git a/firmware/fw_jump.S b/firmware/fw_jump.S index d05d87fe6fb..be9c296704b 100644 --- a/firmware/fw_jump.S +++ b/firmware/fw_jump.S @@ -7,7 +7,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include "fw_common.S" +#include "fw_base.S" .align 3 .section .entry, "ax", %progbits diff --git a/firmware/fw_jump.elf.ldS b/firmware/fw_jump.elf.ldS index dfffbf6013e..8df45ab10a1 100644 --- a/firmware/fw_jump.elf.ldS +++ b/firmware/fw_jump.elf.ldS @@ -12,5 +12,5 @@ ENTRY(_start) SECTIONS { - #include "fw_common.ldS" + #include "fw_base.ldS" } diff --git a/firmware/fw_payload.S b/firmware/fw_payload.S index b6f3cb9642a..7cbd57b421b 100644 --- a/firmware/fw_payload.S +++ b/firmware/fw_payload.S @@ -7,7 +7,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include "fw_common.S" +#include "fw_base.S" .align 3 .section .entry, "ax", %progbits diff --git a/firmware/fw_payload.elf.ldS b/firmware/fw_payload.elf.ldS index 201338b5a12..0713f436606 100644 --- a/firmware/fw_payload.elf.ldS +++ b/firmware/fw_payload.elf.ldS @@ -12,7 +12,7 @@ ENTRY(_start) SECTIONS { - #include "fw_common.ldS" + #include "fw_base.ldS" . = FW_TEXT_START + FW_PAYLOAD_OFFSET; From 7b59571758a5dec75c89928a60d982b29629cee6 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Wed, 26 Dec 2018 18:21:22 +0530 Subject: [PATCH 0048/1765] lib: Simplify sbi_platform early_init() and final_init() hooks Instead of having separate early_init() and final_init() hooks for cold and warm boot, this patch updates struct sbi_platform to have just one early_init() and one final_init() hook. The type of boot (cold or warm) is now a boolean flag parameter for the updated early_init() and final_init() hooks. Signed-off-by: Anup Patel --- include/sbi/sbi_platform.h | 36 +++++++------------------- include/sbi/sbi_system.h | 10 +++---- lib/sbi_init.c | 16 +++--------- lib/sbi_system.c | 22 ++++++---------- platform/kendryte/k210/platform.c | 2 -- platform/qemu/sifive_u/platform.c | 10 ++++--- platform/qemu/virt/platform.c | 10 ++++--- platform/sifive/hifive_u540/platform.c | 10 ++++--- 8 files changed, 47 insertions(+), 69 deletions(-) diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 00fadde912e..e5c1896574c 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -34,10 +34,8 @@ struct sbi_platform { u32 hart_count; u32 hart_stack_size; u64 disabled_hart_mask; - int (*cold_early_init)(void); - int (*cold_final_init)(void); - int (*warm_early_init)(u32 target_hart); - int (*warm_final_init)(u32 target_hart); + int (*early_init)(u32 hartid, bool cold_boot); + int (*final_init)(u32 hartid, bool cold_boot); u32 (*pmp_region_count)(u32 target_hart); int (*pmp_region_info)(u32 target_hart, u32 index, ulong *prot, ulong *addr, ulong *log2size); @@ -105,33 +103,19 @@ static inline u32 sbi_platform_hart_stack_size(struct sbi_platform *plat) return 0; } -static inline int sbi_platform_cold_early_init(struct sbi_platform *plat) +static inline int sbi_platform_early_init(struct sbi_platform *plat, + u32 hartid, bool cold_boot) { - if (plat && plat->cold_early_init) - return plat->cold_early_init(); + if (plat && plat->early_init) + return plat->early_init(hartid, cold_boot); return 0; } -static inline int sbi_platform_cold_final_init(struct sbi_platform *plat) +static inline int sbi_platform_final_init(struct sbi_platform *plat, + u32 hartid, bool cold_boot) { - if (plat && plat->cold_final_init) - return plat->cold_final_init(); - return 0; -} - -static inline int sbi_platform_warm_early_init(struct sbi_platform *plat, - u32 target_hart) -{ - if (plat && plat->warm_early_init) - return plat->warm_early_init(target_hart); - return 0; -} - -static inline int sbi_platform_warm_final_init(struct sbi_platform *plat, - u32 target_hart) -{ - if (plat && plat->warm_final_init) - return plat->warm_final_init(target_hart); + if (plat && plat->final_init) + return plat->final_init(hartid, cold_boot); return 0; } diff --git a/include/sbi/sbi_system.h b/include/sbi/sbi_system.h index ac1fb361617..f37445ee1b3 100644 --- a/include/sbi/sbi_system.h +++ b/include/sbi/sbi_system.h @@ -14,13 +14,11 @@ struct sbi_scratch; -int sbi_system_warm_early_init(struct sbi_scratch *scratch, u32 hartid); +int sbi_system_early_init(struct sbi_scratch *scratch, u32 hartid, + bool cold_boot); -int sbi_system_warm_final_init(struct sbi_scratch *scratch, u32 hartid); - -int sbi_system_cold_early_init(struct sbi_scratch *scratch); - -int sbi_system_cold_final_init(struct sbi_scratch *scratch); +int sbi_system_final_init(struct sbi_scratch *scratch, u32 hartid, + bool cold_boot); void __attribute__((noreturn)) sbi_system_reboot(struct sbi_scratch *scratch, u32 type); diff --git a/lib/sbi_init.c b/lib/sbi_init.c index 68113b4913f..1f5d923ef56 100644 --- a/lib/sbi_init.c +++ b/lib/sbi_init.c @@ -34,11 +34,7 @@ static void __attribute__((noreturn)) init_coldboot(struct sbi_scratch *scratch, char str[64]; struct sbi_platform *plat = sbi_platform_ptr(scratch); - rc = sbi_system_cold_early_init(scratch); - if (rc) - sbi_hart_hang(); - - rc = sbi_system_warm_early_init(scratch, hartid); + rc = sbi_system_early_init(scratch, hartid, TRUE); if (rc) sbi_hart_hang(); @@ -74,11 +70,7 @@ static void __attribute__((noreturn)) init_coldboot(struct sbi_scratch *scratch, if (rc) sbi_hart_hang(); - rc = sbi_system_cold_final_init(scratch); - if (rc) - sbi_hart_hang(); - - rc = sbi_system_warm_final_init(scratch, hartid); + rc = sbi_system_final_init(scratch, hartid, TRUE); if (rc) sbi_hart_hang(); @@ -125,7 +117,7 @@ static void __attribute__((noreturn)) init_warmboot(struct sbi_scratch *scratch, if (sbi_platform_hart_disabled(plat, hartid)) sbi_hart_hang(); - rc = sbi_system_warm_early_init(scratch, hartid); + rc = sbi_system_early_init(scratch, hartid, FALSE); if (rc) sbi_hart_hang(); @@ -145,7 +137,7 @@ static void __attribute__((noreturn)) init_warmboot(struct sbi_scratch *scratch, if (rc) sbi_hart_hang(); - rc = sbi_system_warm_final_init(scratch, hartid); + rc = sbi_system_final_init(scratch, hartid, FALSE); if (rc) sbi_hart_hang(); diff --git a/lib/sbi_system.c b/lib/sbi_system.c index cd250f54df9..f543cef25da 100644 --- a/lib/sbi_system.c +++ b/lib/sbi_system.c @@ -11,24 +11,18 @@ #include #include -int sbi_system_warm_early_init(struct sbi_scratch *scratch, u32 hartid) +int sbi_system_early_init(struct sbi_scratch *scratch, u32 hartid, + bool cold_boot) { - return sbi_platform_warm_early_init(sbi_platform_ptr(scratch), hartid); + return sbi_platform_early_init(sbi_platform_ptr(scratch), + hartid, cold_boot); } -int sbi_system_warm_final_init(struct sbi_scratch *scratch, u32 hartid) +int sbi_system_final_init(struct sbi_scratch *scratch, u32 hartid, + bool cold_boot) { - return sbi_platform_warm_final_init(sbi_platform_ptr(scratch), hartid); -} - -int sbi_system_cold_early_init(struct sbi_scratch *scratch) -{ - return sbi_platform_cold_early_init(sbi_platform_ptr(scratch)); -} - -int sbi_system_cold_final_init(struct sbi_scratch *scratch) -{ - return sbi_platform_cold_final_init(sbi_platform_ptr(scratch)); + return sbi_platform_final_init(sbi_platform_ptr(scratch), + hartid, cold_boot); } void __attribute__((noreturn)) sbi_system_reboot(struct sbi_scratch *scratch, diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c index 226cb775ca2..ccb0ad6692b 100644 --- a/platform/kendryte/k210/platform.c +++ b/platform/kendryte/k210/platform.c @@ -102,8 +102,6 @@ struct sbi_platform platform = { .timer_event_start = clint_timer_event_start, .warm_timer_init = clint_warm_timer_init, - .cold_final_init = NULL, - .system_reboot = k210_system_reboot, .system_shutdown = k210_system_shutdown }; diff --git a/platform/qemu/sifive_u/platform.c b/platform/qemu/sifive_u/platform.c index f593323a8fc..bbbe055a124 100644 --- a/platform/qemu/sifive_u/platform.c +++ b/platform/qemu/sifive_u/platform.c @@ -29,11 +29,15 @@ #define SIFIVE_U_UART0_ADDR 0x10013000 #define SIFIVE_U_UART1_ADDR 0x10023000 -static int sifive_u_cold_final_init(void) +static int sifive_u_final_init(u32 hartid, bool cold_boot) { u32 i; - void *fdt = sbi_scratch_thishart_arg1_ptr(); + void *fdt; + if (!cold_boot) + return 0; + + fdt = sbi_scratch_thishart_arg1_ptr(); for (i = 0; i < SIFIVE_U_HART_COUNT; i++) plic_fdt_fixup(fdt, "riscv,plic0", 2 * i); @@ -110,7 +114,7 @@ struct sbi_platform platform = { .disabled_hart_mask = 0, .pmp_region_count = sifive_u_pmp_region_count, .pmp_region_info = sifive_u_pmp_region_info, - .cold_final_init = sifive_u_cold_final_init, + .final_init = sifive_u_final_init, .console_putc = sifive_uart_putc, .console_getc = sifive_uart_getc, .console_init = sifive_u_console_init, diff --git a/platform/qemu/virt/platform.c b/platform/qemu/virt/platform.c index 98357cfc680..9e0d21a2bf3 100644 --- a/platform/qemu/virt/platform.c +++ b/platform/qemu/virt/platform.c @@ -29,11 +29,15 @@ #define VIRT_UART_BAUDRATE 115200 #define VIRT_UART_SHIFTREG_ADDR 1843200 -static int virt_cold_final_init(void) +static int virt_final_init(u32 hartid, bool cold_boot) { u32 i; - void *fdt = sbi_scratch_thishart_arg1_ptr(); + void *fdt; + if (!cold_boot) + return 0; + + fdt = sbi_scratch_thishart_arg1_ptr(); for (i = 0; i < VIRT_HART_COUNT; i++) plic_fdt_fixup(fdt, "riscv,plic0", 2 * i); @@ -111,7 +115,7 @@ struct sbi_platform platform = { .disabled_hart_mask = 0, .pmp_region_count = virt_pmp_region_count, .pmp_region_info = virt_pmp_region_info, - .cold_final_init = virt_cold_final_init, + .final_init = virt_final_init, .console_putc = uart8250_putc, .console_getc = uart8250_getc, .console_init = virt_console_init, diff --git a/platform/sifive/hifive_u540/platform.c b/platform/sifive/hifive_u540/platform.c index 1e600a3e34d..2db5dae8ef4 100644 --- a/platform/sifive/hifive_u540/platform.c +++ b/platform/sifive/hifive_u540/platform.c @@ -38,11 +38,15 @@ #define SIFIVE_PRCI_CLKMUXSTATUSREG 0x002C #define SIFIVE_PRCI_CLKMUX_STATUS_TLCLKSEL (0x1 << 1) -static int sifive_u_cold_final_init(void) +static int sifive_u_final_init(u32 hartid, bool cold_boot) { u32 i; - void *fdt = sbi_scratch_thishart_arg1_ptr(); + void *fdt; + if (!cold_boot) + return 0; + + fdt = sbi_scratch_thishart_arg1_ptr(); plic_fdt_fixup(fdt, "riscv,plic0", 0); for (i = 1; i < SIFIVE_U_HART_COUNT; i++) plic_fdt_fixup(fdt, "riscv,plic0", 2 * i - 1); @@ -130,7 +134,7 @@ struct sbi_platform platform = { .disabled_hart_mask = ~(1 << SIFIVE_U_HARITD_ENABLED), .pmp_region_count = sifive_u_pmp_region_count, .pmp_region_info = sifive_u_pmp_region_info, - .cold_final_init = sifive_u_cold_final_init, + .final_init = sifive_u_final_init, .console_putc = sifive_uart_putc, .console_getc = sifive_uart_getc, .console_init = sifive_u_console_init, From e34aa8a6719dd6c225e576e0617d05735776af6f Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Wed, 26 Dec 2018 18:27:35 +0530 Subject: [PATCH 0049/1765] lib: Simplify sbi_platform irqchip_init() hooks Instead of having separate irqchip_init() hooks for cold and warm boot, this patch updates struct sbi_platform to have just one irqchip_init() hook. The type of boot (cold or warm) is now a boolean flag parameter for the updated irqchip_init() hook. Signed-off-by: Anup Patel --- include/sbi/sbi_platform.h | 18 +++++------------ lib/sbi_init.c | 8 ++------ platform/kendryte/k210/platform.c | 27 ++++++++++++++----------- platform/qemu/sifive_u/platform.c | 28 ++++++++++++++------------ platform/qemu/virt/platform.c | 28 ++++++++++++++------------ platform/sifive/hifive_u540/platform.c | 26 +++++++++++++----------- 6 files changed, 66 insertions(+), 69 deletions(-) diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index e5c1896574c..503669b3596 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -42,8 +42,7 @@ struct sbi_platform { void (*console_putc)(char ch); char (*console_getc)(void); int (*console_init)(void); - int (*cold_irqchip_init)(void); - int (*warm_irqchip_init)(u32 target_hart); + int (*irqchip_init)(u32 hartid, bool cold_boot); void (*ipi_inject)(u32 target_hart, u32 source_hart); void (*ipi_sync)(u32 target_hart, u32 source_hart); void (*ipi_clear)(u32 target_hart); @@ -159,18 +158,11 @@ static inline int sbi_platform_console_init(struct sbi_platform *plat) return 0; } -static inline int sbi_platform_warm_irqchip_init(struct sbi_platform *plat, - u32 target_hart) -{ - if (plat && plat->warm_irqchip_init) - return plat->warm_irqchip_init(target_hart); - return 0; -} - -static inline int sbi_platform_cold_irqchip_init(struct sbi_platform *plat) +static inline int sbi_platform_irqchip_init(struct sbi_platform *plat, + u32 hartid, bool cold_boot) { - if (plat && plat->cold_irqchip_init) - return plat->cold_irqchip_init(); + if (plat && plat->irqchip_init) + return plat->irqchip_init(hartid, cold_boot); return 0; } diff --git a/lib/sbi_init.c b/lib/sbi_init.c index 1f5d923ef56..448102e504d 100644 --- a/lib/sbi_init.c +++ b/lib/sbi_init.c @@ -46,11 +46,7 @@ static void __attribute__((noreturn)) init_coldboot(struct sbi_scratch *scratch, if (rc) sbi_hart_hang(); - rc = sbi_platform_cold_irqchip_init(plat); - if (rc) - sbi_hart_hang(); - - rc = sbi_platform_warm_irqchip_init(plat, hartid); + rc = sbi_platform_irqchip_init(plat, hartid, TRUE); if (rc) sbi_hart_hang(); @@ -125,7 +121,7 @@ static void __attribute__((noreturn)) init_warmboot(struct sbi_scratch *scratch, if (rc) sbi_hart_hang(); - rc = sbi_platform_warm_irqchip_init(plat, hartid); + rc = sbi_platform_irqchip_init(plat, hartid, FALSE); if (rc) sbi_hart_hang(); diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c index ccb0ad6692b..43c32440bad 100644 --- a/platform/kendryte/k210/platform.c +++ b/platform/kendryte/k210/platform.c @@ -35,17 +35,21 @@ static char k210_console_getc(void) return uarths_getc(); } -static int k210_cold_irqchip_init(void) +static int k210_irqchip_init(u32 hartid, bool cold_boot) { - return plic_cold_irqchip_init(PLIC_BASE_ADDR, PLIC_NUM_SOURCES, - K210_HART_COUNT); -} - -static int k210_warm_irqchip_init(u32 core_id) -{ - return plic_warm_irqchip_init(core_id, - (2 * core_id), - (2 * core_id + 1)); + int rc; + + if (cold_boot) { + rc = plic_cold_irqchip_init(PLIC_BASE_ADDR, + PLIC_NUM_SOURCES, + K210_HART_COUNT); + if (rc) + return rc; + } + + return plic_warm_irqchip_init(hartid, + (2 * hartid), + (2 * hartid + 1)); } static int k210_cold_ipi_init(void) @@ -87,8 +91,7 @@ struct sbi_platform platform = { .console_putc = k210_console_putc, .console_getc = k210_console_getc, - .cold_irqchip_init = k210_cold_irqchip_init, - .warm_irqchip_init = k210_warm_irqchip_init, + .irqchip_init = k210_irqchip_init, .cold_ipi_init = k210_cold_ipi_init, .warm_ipi_init = clint_warm_ipi_init, diff --git a/platform/qemu/sifive_u/platform.c b/platform/qemu/sifive_u/platform.c index bbbe055a124..db6dccd5b98 100644 --- a/platform/qemu/sifive_u/platform.c +++ b/platform/qemu/sifive_u/platform.c @@ -74,18 +74,21 @@ static int sifive_u_console_init(void) SIFIVE_U_PERIPH_CLK, 115200); } -static int sifive_u_cold_irqchip_init(void) +static int sifive_u_irqchip_init(u32 hartid, bool cold_boot) { - return plic_cold_irqchip_init(SIFIVE_U_PLIC_ADDR, - SIFIVE_U_PLIC_NUM_SOURCES, - SIFIVE_U_HART_COUNT); -} - -static int sifive_u_warm_irqchip_init(u32 target_hart) -{ - return plic_warm_irqchip_init(target_hart, - (2 * target_hart), - (2 * target_hart + 1)); + int rc; + + if (cold_boot) { + rc = plic_cold_irqchip_init(SIFIVE_U_PLIC_ADDR, + SIFIVE_U_PLIC_NUM_SOURCES, + SIFIVE_U_HART_COUNT); + if (rc) + return rc; + } + + return plic_warm_irqchip_init(hartid, + (2 * hartid), + (2 * hartid + 1)); } static int sifive_u_cold_ipi_init(void) @@ -118,8 +121,7 @@ struct sbi_platform platform = { .console_putc = sifive_uart_putc, .console_getc = sifive_uart_getc, .console_init = sifive_u_console_init, - .cold_irqchip_init = sifive_u_cold_irqchip_init, - .warm_irqchip_init = sifive_u_warm_irqchip_init, + .irqchip_init = sifive_u_irqchip_init, .ipi_inject = clint_ipi_inject, .ipi_sync = clint_ipi_sync, .ipi_clear = clint_ipi_clear, diff --git a/platform/qemu/virt/platform.c b/platform/qemu/virt/platform.c index 9e0d21a2bf3..986dfc57e57 100644 --- a/platform/qemu/virt/platform.c +++ b/platform/qemu/virt/platform.c @@ -75,18 +75,21 @@ static int virt_console_init(void) VIRT_UART_BAUDRATE, 0, 1); } -static int virt_cold_irqchip_init(void) +static int virt_irqchip_init(u32 hartid, bool cold_boot) { - return plic_cold_irqchip_init(VIRT_PLIC_ADDR, - VIRT_PLIC_NUM_SOURCES, - VIRT_HART_COUNT); -} - -static int virt_warm_irqchip_init(u32 target_hart) -{ - return plic_warm_irqchip_init(target_hart, - (2 * target_hart), - (2 * target_hart + 1)); + int rc; + + if (cold_boot) { + rc = plic_cold_irqchip_init(VIRT_PLIC_ADDR, + VIRT_PLIC_NUM_SOURCES, + VIRT_HART_COUNT); + if (rc) + return rc; + } + + return plic_warm_irqchip_init(hartid, + (2 * hartid), + (2 * hartid + 1)); } static int virt_cold_ipi_init(void) @@ -119,8 +122,7 @@ struct sbi_platform platform = { .console_putc = uart8250_putc, .console_getc = uart8250_getc, .console_init = virt_console_init, - .cold_irqchip_init = virt_cold_irqchip_init, - .warm_irqchip_init = virt_warm_irqchip_init, + .irqchip_init = virt_irqchip_init, .ipi_inject = clint_ipi_inject, .ipi_sync = clint_ipi_sync, .ipi_clear = clint_ipi_clear, diff --git a/platform/sifive/hifive_u540/platform.c b/platform/sifive/hifive_u540/platform.c index 2db5dae8ef4..6d6ac182336 100644 --- a/platform/sifive/hifive_u540/platform.c +++ b/platform/sifive/hifive_u540/platform.c @@ -94,18 +94,21 @@ static int sifive_u_console_init(void) peri_in_freq, SIFIVE_UART_BAUDRATE); } -static int sifive_u_cold_irqchip_init(void) +static int sifive_u_irqchip_init(u32 hartid, bool cold_boot) { - return plic_cold_irqchip_init(SIFIVE_U_PLIC_ADDR, - SIFIVE_U_PLIC_NUM_SOURCES, - SIFIVE_U_HART_COUNT); -} + int rc; + + if (cold_boot) { + rc = plic_cold_irqchip_init(SIFIVE_U_PLIC_ADDR, + SIFIVE_U_PLIC_NUM_SOURCES, + SIFIVE_U_HART_COUNT); + if (rc) + return rc; + } -static int sifive_u_warm_irqchip_init(u32 target_hart) -{ - return plic_warm_irqchip_init(target_hart, - (target_hart) ? (2 * target_hart - 1) : 0, - (target_hart) ? (2 * target_hart) : -1); + return plic_warm_irqchip_init(hartid, + (hartid) ? (2 * hartid - 1) : 0, + (hartid) ? (2 * hartid) : -1); } static int sifive_u_cold_ipi_init(void) @@ -138,8 +141,7 @@ struct sbi_platform platform = { .console_putc = sifive_uart_putc, .console_getc = sifive_uart_getc, .console_init = sifive_u_console_init, - .cold_irqchip_init = sifive_u_cold_irqchip_init, - .warm_irqchip_init = sifive_u_warm_irqchip_init, + .irqchip_init = sifive_u_irqchip_init, .ipi_inject = clint_ipi_inject, .ipi_sync = clint_ipi_sync, .ipi_clear = clint_ipi_clear, From c1b6200653c51642e544c66fab8bb320969b818e Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Wed, 26 Dec 2018 18:36:11 +0530 Subject: [PATCH 0050/1765] lib: Simplify sbi_platform ipi_init() hooks Instead of having separate ipi_init() hooks for cold and warm boot, this patch updates struct sbi_platform to have just one ipi_init() hook. The type of boot (cold or warm) is now a boolean flag parameter for the updated ipi_init() hook. Signed-off-by: Anup Patel --- include/sbi/sbi_ipi.h | 4 +--- include/sbi/sbi_platform.h | 18 +++++------------- lib/sbi_init.c | 8 ++------ lib/sbi_ipi.c | 10 +++------- platform/kendryte/k210/platform.c | 16 ++++++++++++---- platform/qemu/sifive_u/platform.c | 17 ++++++++++++----- platform/qemu/virt/platform.c | 17 ++++++++++++----- platform/sifive/hifive_u540/platform.c | 18 +++++++++++++----- 8 files changed, 60 insertions(+), 48 deletions(-) diff --git a/include/sbi/sbi_ipi.h b/include/sbi/sbi_ipi.h index 40581946af9..d7c05765def 100644 --- a/include/sbi/sbi_ipi.h +++ b/include/sbi/sbi_ipi.h @@ -26,8 +26,6 @@ void sbi_ipi_clear_smode(struct sbi_scratch *scratch, u32 hartid); void sbi_ipi_process(struct sbi_scratch *scratch, u32 hartid); -int sbi_ipi_warm_init(struct sbi_scratch *scratch, u32 hartid); - -int sbi_ipi_cold_init(struct sbi_scratch *scratch); +int sbi_ipi_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot); #endif diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 503669b3596..13c9ffc7484 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -46,8 +46,7 @@ struct sbi_platform { void (*ipi_inject)(u32 target_hart, u32 source_hart); void (*ipi_sync)(u32 target_hart, u32 source_hart); void (*ipi_clear)(u32 target_hart); - int (*cold_ipi_init)(void); - int (*warm_ipi_init)(u32 target_hart); + int (*ipi_init)(u32 hartid, bool cold_boot); u64 (*timer_value)(void); void (*timer_event_stop)(u32 target_hart); void (*timer_event_start)(u32 target_hart, u64 next_event); @@ -187,18 +186,11 @@ static inline void sbi_platform_ipi_clear(struct sbi_platform *plat, plat->ipi_clear(target_hart); } -static inline int sbi_platform_warm_ipi_init(struct sbi_platform *plat, - u32 target_hart) +static inline int sbi_platform_ipi_init(struct sbi_platform *plat, + u32 hartid, bool cold_boot) { - if (plat && plat->warm_ipi_init) - return plat->warm_ipi_init(target_hart); - return 0; -} - -static inline int sbi_platform_cold_ipi_init(struct sbi_platform *plat) -{ - if (plat && plat->cold_ipi_init) - return plat->cold_ipi_init(); + if (plat && plat->ipi_init) + return plat->ipi_init(hartid, cold_boot); return 0; } diff --git a/lib/sbi_init.c b/lib/sbi_init.c index 448102e504d..989cb7d79b3 100644 --- a/lib/sbi_init.c +++ b/lib/sbi_init.c @@ -50,11 +50,7 @@ static void __attribute__((noreturn)) init_coldboot(struct sbi_scratch *scratch, if (rc) sbi_hart_hang(); - rc = sbi_ipi_cold_init(scratch); - if (rc) - sbi_hart_hang(); - - rc = sbi_ipi_warm_init(scratch, hartid); + rc = sbi_ipi_init(scratch, hartid, TRUE); if (rc) sbi_hart_hang(); @@ -125,7 +121,7 @@ static void __attribute__((noreturn)) init_warmboot(struct sbi_scratch *scratch, if (rc) sbi_hart_hang(); - rc = sbi_ipi_warm_init(scratch, hartid); + rc = sbi_ipi_init(scratch, hartid, FALSE); if (rc) sbi_hart_hang(); diff --git a/lib/sbi_ipi.c b/lib/sbi_ipi.c index d21ea4a2f05..423a9a0984d 100644 --- a/lib/sbi_ipi.c +++ b/lib/sbi_ipi.c @@ -68,15 +68,11 @@ void sbi_ipi_process(struct sbi_scratch *scratch, u32 hartid) scratch->ipi_type = 0; } -int sbi_ipi_warm_init(struct sbi_scratch *scratch, u32 hartid) +int sbi_ipi_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot) { /* Enable software interrupts */ csr_set(mie, MIP_MSIP); - return sbi_platform_warm_ipi_init(sbi_platform_ptr(scratch), hartid); -} - -int sbi_ipi_cold_init(struct sbi_scratch *scratch) -{ - return sbi_platform_cold_ipi_init(sbi_platform_ptr(scratch)); + return sbi_platform_ipi_init(sbi_platform_ptr(scratch), + hartid, cold_boot); } diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c index 43c32440bad..d11dd66e4f1 100644 --- a/platform/kendryte/k210/platform.c +++ b/platform/kendryte/k210/platform.c @@ -52,9 +52,18 @@ static int k210_irqchip_init(u32 hartid, bool cold_boot) (2 * hartid + 1)); } -static int k210_cold_ipi_init(void) +static int k210_ipi_init(u32 hartid, bool cold_boot) { - return clint_cold_ipi_init(CLINT_BASE_ADDR, K210_HART_COUNT); + int rc; + + if (cold_boot) { + rc = clint_cold_ipi_init(CLINT_BASE_ADDR, + K210_HART_COUNT); + if (rc) + return rc; + } + + return clint_warm_ipi_init(hartid); } static int k210_cold_timer_init(void) @@ -93,8 +102,7 @@ struct sbi_platform platform = { .irqchip_init = k210_irqchip_init, - .cold_ipi_init = k210_cold_ipi_init, - .warm_ipi_init = clint_warm_ipi_init, + .ipi_init = k210_ipi_init, .ipi_inject = clint_ipi_inject, .ipi_sync = clint_ipi_sync, .ipi_clear = clint_ipi_clear, diff --git a/platform/qemu/sifive_u/platform.c b/platform/qemu/sifive_u/platform.c index db6dccd5b98..4e6ac4832e7 100644 --- a/platform/qemu/sifive_u/platform.c +++ b/platform/qemu/sifive_u/platform.c @@ -91,10 +91,18 @@ static int sifive_u_irqchip_init(u32 hartid, bool cold_boot) (2 * hartid + 1)); } -static int sifive_u_cold_ipi_init(void) +static int sifive_u_ipi_init(u32 hartid, bool cold_boot) { - return clint_cold_ipi_init(SIFIVE_U_CLINT_ADDR, - SIFIVE_U_HART_COUNT); + int rc; + + if (cold_boot) { + rc = clint_cold_ipi_init(SIFIVE_U_CLINT_ADDR, + SIFIVE_U_HART_COUNT); + if (rc) + return rc; + } + + return clint_warm_ipi_init(hartid); } static int sifive_u_cold_timer_init(void) @@ -125,8 +133,7 @@ struct sbi_platform platform = { .ipi_inject = clint_ipi_inject, .ipi_sync = clint_ipi_sync, .ipi_clear = clint_ipi_clear, - .warm_ipi_init = clint_warm_ipi_init, - .cold_ipi_init = sifive_u_cold_ipi_init, + .ipi_init = sifive_u_ipi_init, .timer_value = clint_timer_value, .timer_event_stop = clint_timer_event_stop, .timer_event_start = clint_timer_event_start, diff --git a/platform/qemu/virt/platform.c b/platform/qemu/virt/platform.c index 986dfc57e57..f9dce4a7235 100644 --- a/platform/qemu/virt/platform.c +++ b/platform/qemu/virt/platform.c @@ -92,10 +92,18 @@ static int virt_irqchip_init(u32 hartid, bool cold_boot) (2 * hartid + 1)); } -static int virt_cold_ipi_init(void) +static int virt_ipi_init(u32 hartid, bool cold_boot) { - return clint_cold_ipi_init(VIRT_CLINT_ADDR, - VIRT_HART_COUNT); + int rc; + + if (cold_boot) { + rc = clint_cold_ipi_init(VIRT_CLINT_ADDR, + VIRT_HART_COUNT); + if (rc) + return rc; + } + + return clint_warm_ipi_init(hartid); } static int virt_cold_timer_init(void) @@ -126,8 +134,7 @@ struct sbi_platform platform = { .ipi_inject = clint_ipi_inject, .ipi_sync = clint_ipi_sync, .ipi_clear = clint_ipi_clear, - .warm_ipi_init = clint_warm_ipi_init, - .cold_ipi_init = virt_cold_ipi_init, + .ipi_init = virt_ipi_init, .timer_value = clint_timer_value, .timer_event_stop = clint_timer_event_stop, .timer_event_start = clint_timer_event_start, diff --git a/platform/sifive/hifive_u540/platform.c b/platform/sifive/hifive_u540/platform.c index 6d6ac182336..fabb73e8eb3 100644 --- a/platform/sifive/hifive_u540/platform.c +++ b/platform/sifive/hifive_u540/platform.c @@ -111,10 +111,19 @@ static int sifive_u_irqchip_init(u32 hartid, bool cold_boot) (hartid) ? (2 * hartid) : -1); } -static int sifive_u_cold_ipi_init(void) +static int sifive_u_ipi_init(u32 hartid, bool cold_boot) { - return clint_cold_ipi_init(SIFIVE_U_CLINT_ADDR, - SIFIVE_U_HART_COUNT); + int rc; + + if (cold_boot) { + rc = clint_cold_ipi_init(SIFIVE_U_CLINT_ADDR, + SIFIVE_U_HART_COUNT); + if (rc) + return rc; + + } + + return clint_warm_ipi_init(hartid); } static int sifive_u_cold_timer_init(void) @@ -145,8 +154,7 @@ struct sbi_platform platform = { .ipi_inject = clint_ipi_inject, .ipi_sync = clint_ipi_sync, .ipi_clear = clint_ipi_clear, - .warm_ipi_init = clint_warm_ipi_init, - .cold_ipi_init = sifive_u_cold_ipi_init, + .ipi_init = sifive_u_ipi_init, .timer_value = clint_timer_value, .timer_event_stop = clint_timer_event_stop, .timer_event_start = clint_timer_event_start, From 52ed1d17092bbe93a34802a55ff19cc7cbb7f85d Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Wed, 26 Dec 2018 18:44:54 +0530 Subject: [PATCH 0051/1765] lib: Simplify sbi_platform timer_init() hooks Instead of having separate timer_init() hooks for cold and warm boot, this patch updates struct sbi_platform to have just one timer_init() hook. The type of boot (cold or warm) is now a boolean flag parameter for the updated timer_init() hook. Signed-off-by: Anup Patel --- include/sbi/sbi_platform.h | 18 +++++------------- include/sbi/sbi_timer.h | 5 ++--- lib/sbi_init.c | 8 ++------ lib/sbi_timer.c | 11 ++++------- platform/kendryte/k210/platform.c | 16 ++++++++++++---- platform/qemu/sifive_u/platform.c | 17 ++++++++++++----- platform/qemu/virt/platform.c | 17 ++++++++++++----- platform/sifive/hifive_u540/platform.c | 17 ++++++++++++----- 8 files changed, 61 insertions(+), 48 deletions(-) diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 13c9ffc7484..29e66102c1b 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -50,8 +50,7 @@ struct sbi_platform { u64 (*timer_value)(void); void (*timer_event_stop)(u32 target_hart); void (*timer_event_start)(u32 target_hart, u64 next_event); - int (*cold_timer_init)(void); - int (*warm_timer_init)(u32 target_hart); + int (*timer_init)(u32 hartid, bool cold_boot); int (*system_reboot)(u32 type); int (*system_shutdown)(u32 type); } __attribute__((packed)); @@ -216,18 +215,11 @@ static inline void sbi_platform_timer_event_start(struct sbi_platform *plat, plat->timer_event_start(target_hart, next_event); } -static inline int sbi_platform_warm_timer_init(struct sbi_platform *plat, - u32 target_hart) -{ - if (plat && plat->warm_timer_init) - return plat->warm_timer_init(target_hart); - return 0; -} - -static inline int sbi_platform_cold_timer_init(struct sbi_platform *plat) +static inline int sbi_platform_timer_init(struct sbi_platform *plat, + u32 hartid, bool cold_boot) { - if (plat && plat->cold_timer_init) - return plat->cold_timer_init(); + if (plat && plat->timer_init) + return plat->timer_init(hartid, cold_boot); return 0; } diff --git a/include/sbi/sbi_timer.h b/include/sbi/sbi_timer.h index 914e9c01b7e..601c27c8a71 100644 --- a/include/sbi/sbi_timer.h +++ b/include/sbi/sbi_timer.h @@ -23,8 +23,7 @@ void sbi_timer_event_start(struct sbi_scratch *scratch, u32 hartid, void sbi_timer_process(struct sbi_scratch *scratch, u32 hartid); -int sbi_timer_warm_init(struct sbi_scratch *scratch, u32 hartid); - -int sbi_timer_cold_init(struct sbi_scratch *scratch); +int sbi_timer_init(struct sbi_scratch *scratch, u32 hartid, + bool cold_boot); #endif diff --git a/lib/sbi_init.c b/lib/sbi_init.c index 989cb7d79b3..f9429719fc7 100644 --- a/lib/sbi_init.c +++ b/lib/sbi_init.c @@ -54,11 +54,7 @@ static void __attribute__((noreturn)) init_coldboot(struct sbi_scratch *scratch, if (rc) sbi_hart_hang(); - rc = sbi_timer_cold_init(scratch); - if (rc) - sbi_hart_hang(); - - rc = sbi_timer_warm_init(scratch, hartid); + rc = sbi_timer_init(scratch, hartid, TRUE); if (rc) sbi_hart_hang(); @@ -125,7 +121,7 @@ static void __attribute__((noreturn)) init_warmboot(struct sbi_scratch *scratch, if (rc) sbi_hart_hang(); - rc = sbi_timer_warm_init(scratch, hartid); + rc = sbi_timer_init(scratch, hartid, FALSE); if (rc) sbi_hart_hang(); diff --git a/lib/sbi_timer.c b/lib/sbi_timer.c index 355bc64ea21..8dfc7534491 100644 --- a/lib/sbi_timer.c +++ b/lib/sbi_timer.c @@ -67,12 +67,9 @@ void sbi_timer_process(struct sbi_scratch *scratch, u32 hartid) csr_set(mip, MIP_STIP); } -int sbi_timer_warm_init(struct sbi_scratch *scratch, u32 hartid) +int sbi_timer_init(struct sbi_scratch *scratch, u32 hartid, + bool cold_boot) { - return sbi_platform_warm_timer_init(sbi_platform_ptr(scratch), hartid); -} - -int sbi_timer_cold_init(struct sbi_scratch *scratch) -{ - return sbi_platform_cold_timer_init(sbi_platform_ptr(scratch)); + return sbi_platform_timer_init(sbi_platform_ptr(scratch), + hartid, cold_boot); } diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c index d11dd66e4f1..141c98e30ba 100644 --- a/platform/kendryte/k210/platform.c +++ b/platform/kendryte/k210/platform.c @@ -66,9 +66,18 @@ static int k210_ipi_init(u32 hartid, bool cold_boot) return clint_warm_ipi_init(hartid); } -static int k210_cold_timer_init(void) +static int k210_timer_init(u32 hartid, bool cold_boot) { - return clint_cold_timer_init(CLINT_BASE_ADDR, K210_HART_COUNT); + int rc; + + if (cold_boot) { + rc = clint_cold_timer_init(CLINT_BASE_ADDR, + K210_HART_COUNT); + if (rc) + return rc; + } + + return clint_warm_timer_init(hartid); } static int k210_system_reboot(u32 type) @@ -107,11 +116,10 @@ struct sbi_platform platform = { .ipi_sync = clint_ipi_sync, .ipi_clear = clint_ipi_clear, - .cold_timer_init = k210_cold_timer_init, + .timer_init = k210_timer_init, .timer_value = clint_timer_value, .timer_event_stop = clint_timer_event_stop, .timer_event_start = clint_timer_event_start, - .warm_timer_init = clint_warm_timer_init, .system_reboot = k210_system_reboot, .system_shutdown = k210_system_shutdown diff --git a/platform/qemu/sifive_u/platform.c b/platform/qemu/sifive_u/platform.c index 4e6ac4832e7..7f41fe15cc2 100644 --- a/platform/qemu/sifive_u/platform.c +++ b/platform/qemu/sifive_u/platform.c @@ -105,10 +105,18 @@ static int sifive_u_ipi_init(u32 hartid, bool cold_boot) return clint_warm_ipi_init(hartid); } -static int sifive_u_cold_timer_init(void) +static int sifive_u_timer_init(u32 hartid, bool cold_boot) { - return clint_cold_timer_init(SIFIVE_U_CLINT_ADDR, - SIFIVE_U_HART_COUNT); + int rc; + + if (cold_boot) { + rc = clint_cold_timer_init(SIFIVE_U_CLINT_ADDR, + SIFIVE_U_HART_COUNT); + if (rc) + return rc; + } + + return clint_warm_timer_init(hartid); } static int sifive_u_system_down(u32 type) @@ -137,8 +145,7 @@ struct sbi_platform platform = { .timer_value = clint_timer_value, .timer_event_stop = clint_timer_event_stop, .timer_event_start = clint_timer_event_start, - .warm_timer_init = clint_warm_timer_init, - .cold_timer_init = sifive_u_cold_timer_init, + .timer_init = sifive_u_timer_init, .system_reboot = sifive_u_system_down, .system_shutdown = sifive_u_system_down }; diff --git a/platform/qemu/virt/platform.c b/platform/qemu/virt/platform.c index f9dce4a7235..c83f8f2ba3c 100644 --- a/platform/qemu/virt/platform.c +++ b/platform/qemu/virt/platform.c @@ -106,10 +106,18 @@ static int virt_ipi_init(u32 hartid, bool cold_boot) return clint_warm_ipi_init(hartid); } -static int virt_cold_timer_init(void) +static int virt_timer_init(u32 hartid, bool cold_boot) { - return clint_cold_timer_init(VIRT_CLINT_ADDR, - VIRT_HART_COUNT); + int rc; + + if (cold_boot) { + rc = clint_cold_timer_init(VIRT_CLINT_ADDR, + VIRT_HART_COUNT); + if (rc) + return rc; + } + + return clint_warm_timer_init(hartid); } static int virt_system_down(u32 type) @@ -138,8 +146,7 @@ struct sbi_platform platform = { .timer_value = clint_timer_value, .timer_event_stop = clint_timer_event_stop, .timer_event_start = clint_timer_event_start, - .warm_timer_init = clint_warm_timer_init, - .cold_timer_init = virt_cold_timer_init, + .timer_init = virt_timer_init, .system_reboot = virt_system_down, .system_shutdown = virt_system_down }; diff --git a/platform/sifive/hifive_u540/platform.c b/platform/sifive/hifive_u540/platform.c index fabb73e8eb3..c81697f1825 100644 --- a/platform/sifive/hifive_u540/platform.c +++ b/platform/sifive/hifive_u540/platform.c @@ -126,10 +126,18 @@ static int sifive_u_ipi_init(u32 hartid, bool cold_boot) return clint_warm_ipi_init(hartid); } -static int sifive_u_cold_timer_init(void) +static int sifive_u_timer_init(u32 hartid, bool cold_boot) { - return clint_cold_timer_init(SIFIVE_U_CLINT_ADDR, - SIFIVE_U_HART_COUNT); + int rc; + + if (cold_boot) { + rc = clint_cold_timer_init(SIFIVE_U_CLINT_ADDR, + SIFIVE_U_HART_COUNT); + if (rc) + return rc; + } + + return clint_warm_timer_init(hartid); } static int sifive_u_system_down(u32 type) @@ -158,8 +166,7 @@ struct sbi_platform platform = { .timer_value = clint_timer_value, .timer_event_stop = clint_timer_event_stop, .timer_event_start = clint_timer_event_start, - .warm_timer_init = clint_warm_timer_init, - .cold_timer_init = sifive_u_cold_timer_init, + .timer_init = sifive_u_timer_init, .system_reboot = sifive_u_system_down, .system_shutdown = sifive_u_system_down }; From 45f874da6ccae5294625c9d5b71fafa47299f1d7 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Wed, 26 Dec 2018 18:49:55 +0530 Subject: [PATCH 0052/1765] lib: Rename target_hart parameter to hartid for PMP platform callbacks We rename target_hart parameter of PMP platform callbacks to hartid for clarity because the parameter represents current hartid. Signed-off-by: Anup Patel --- include/sbi/sbi_platform.h | 14 +++++++------- platform/qemu/sifive_u/platform.c | 4 ++-- platform/qemu/virt/platform.c | 4 ++-- platform/sifive/hifive_u540/platform.c | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 29e66102c1b..8532c03bb20 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -36,8 +36,8 @@ struct sbi_platform { u64 disabled_hart_mask; int (*early_init)(u32 hartid, bool cold_boot); int (*final_init)(u32 hartid, bool cold_boot); - u32 (*pmp_region_count)(u32 target_hart); - int (*pmp_region_info)(u32 target_hart, u32 index, + u32 (*pmp_region_count)(u32 hartid); + int (*pmp_region_info)(u32 hartid, u32 index, ulong *prot, ulong *addr, ulong *log2size); void (*console_putc)(char ch); char (*console_getc)(void); @@ -117,21 +117,21 @@ static inline int sbi_platform_final_init(struct sbi_platform *plat, } static inline u32 sbi_platform_pmp_region_count(struct sbi_platform *plat, - u32 target_hart) + u32 hartid) { if (plat && plat->pmp_region_count) - return plat->pmp_region_count(target_hart); + return plat->pmp_region_count(hartid); return 0; } static inline int sbi_platform_pmp_region_info(struct sbi_platform *plat, - u32 target_hart, u32 index, + u32 hartid, u32 index, ulong *prot, ulong *addr, ulong *log2size) { if (plat && plat->pmp_region_info) - return plat->pmp_region_info(target_hart, index, - prot, addr, log2size); + return plat->pmp_region_info(hartid, index, + prot, addr, log2size); return 0; } diff --git a/platform/qemu/sifive_u/platform.c b/platform/qemu/sifive_u/platform.c index 7f41fe15cc2..cf6efbdabdb 100644 --- a/platform/qemu/sifive_u/platform.c +++ b/platform/qemu/sifive_u/platform.c @@ -44,12 +44,12 @@ static int sifive_u_final_init(u32 hartid, bool cold_boot) return 0; } -static u32 sifive_u_pmp_region_count(u32 target_hart) +static u32 sifive_u_pmp_region_count(u32 hartid) { return 1; } -static int sifive_u_pmp_region_info(u32 target_hart, u32 index, +static int sifive_u_pmp_region_info(u32 hartid, u32 index, ulong *prot, ulong *addr, ulong *log2size) { int ret = 0; diff --git a/platform/qemu/virt/platform.c b/platform/qemu/virt/platform.c index c83f8f2ba3c..71ddc759aa7 100644 --- a/platform/qemu/virt/platform.c +++ b/platform/qemu/virt/platform.c @@ -44,12 +44,12 @@ static int virt_final_init(u32 hartid, bool cold_boot) return 0; } -static u32 virt_pmp_region_count(u32 target_hart) +static u32 virt_pmp_region_count(u32 hartid) { return 1; } -static int virt_pmp_region_info(u32 target_hart, u32 index, +static int virt_pmp_region_info(u32 hartid, u32 index, ulong *prot, ulong *addr, ulong *log2size) { int ret = 0; diff --git a/platform/sifive/hifive_u540/platform.c b/platform/sifive/hifive_u540/platform.c index c81697f1825..5528b0c0aa0 100644 --- a/platform/sifive/hifive_u540/platform.c +++ b/platform/sifive/hifive_u540/platform.c @@ -54,12 +54,12 @@ static int sifive_u_final_init(u32 hartid, bool cold_boot) return 0; } -static u32 sifive_u_pmp_region_count(u32 target_hart) +static u32 sifive_u_pmp_region_count(u32 hartid) { return 1; } -static int sifive_u_pmp_region_info(u32 target_hart, u32 index, +static int sifive_u_pmp_region_info(u32 hartid, u32 index, ulong *prot, ulong *addr, ulong *log2size) { int ret = 0; From f2d4c5f2915e805e660a533d30cda6edf97b8bcd Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Thu, 27 Dec 2018 10:06:38 +0530 Subject: [PATCH 0053/1765] lib: Print mtval in sbi_trap_error() The mtval CSR is very useful information when debugging hence print it upon trap error in sbi_trap_error(). Signed-off-by: Anup Patel --- lib/sbi_trap.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/sbi_trap.c b/lib/sbi_trap.c index 012a9a001a2..ab78b576888 100644 --- a/lib/sbi_trap.c +++ b/lib/sbi_trap.c @@ -21,13 +21,15 @@ static void __attribute__((noreturn)) sbi_trap_error(const char *msg, int rc, u32 hartid, - ulong mcause, + ulong mcause, ulong mtval, struct sbi_trap_regs *regs) { sbi_printf("%s: hart%d: %s (error %d)\n", __func__, hartid, msg, rc); - sbi_printf("%s: hart%d: mcause=0x%lx mepc=0x%lx mstatus=0x%lx\n", - __func__, hartid, mcause, regs->mepc, regs->mstatus); + sbi_printf("%s: hart%d: mcause=0x%lx mtval=0x%lx\n", + __func__, hartid, mcause, mtval); + sbi_printf("%s: hart%d: mepc=0x%lx mstatus=0x%lx\n", + __func__, hartid, regs->mepc, regs->mstatus); sbi_printf("%s: hart%d: %s=0x%lx %s=0x%lx\n", __func__, hartid, "ra", regs->ra, "sp", regs->sp); sbi_printf("%s: hart%d: %s=0x%lx %s=0x%lx\n", @@ -67,8 +69,8 @@ static void __attribute__((noreturn)) sbi_trap_error(const char *msg, void sbi_trap_handler(struct sbi_trap_regs *regs, struct sbi_scratch *scratch) { - int rc; - const char *msg; + int rc = SBI_ENOTSUPP; + const char *msg = "trap handler failed"; u32 hartid = sbi_current_hartid(); ulong mcause = csr_read(mcause); @@ -82,15 +84,12 @@ void sbi_trap_handler(struct sbi_trap_regs *regs, sbi_ipi_process(scratch, hartid); break; default: - sbi_trap_error("unhandled external interrupt", - SBI_ENOTSUPP, hartid, mcause, regs); - break; + msg = "unhandled external interrupt"; + goto trap_error; }; return; } - rc = SBI_ENOTSUPP; - msg = "trap handler failed"; switch (mcause) { case CAUSE_ILLEGAL_INSTRUCTION: rc = sbi_illegal_insn_handler(hartid, mcause, regs, scratch); @@ -113,7 +112,8 @@ void sbi_trap_handler(struct sbi_trap_regs *regs, break; }; +trap_error: if (rc) { - sbi_trap_error(msg, rc, hartid, mcause, regs); + sbi_trap_error(msg, rc, hartid, mcause, csr_read(mtval), regs); } } From d461d5b790bba2884dfdd02ab117375e9bfaae4c Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 28 Dec 2018 10:51:15 +0530 Subject: [PATCH 0054/1765] platform: Rename sifive/hifive_u540 to sifive/fu540 We rename sifive/hifive_u540 platform support to sifive/fu540 to match the SoC name which is SiFive FU540 (as-per user manual). In fact, we can expect no (or very minimal) board specific quirks in sifive/fu540 platform support. These board specific quirks can be turned on/off in-future using PLATFORM_ make command-line option. Signed-off-by: Anup Patel Signed-off-by: Atish Patra --- .../sifive/{hifive_u540 => fu540}/config.mk | 2 +- .../sifive/{hifive_u540 => fu540}/objects.mk | 2 +- platform/sifive/fu540/platform.c | 172 ++++++++++++++++++ platform/sifive/hifive_u540/platform.c | 172 ------------------ 4 files changed, 174 insertions(+), 174 deletions(-) rename platform/sifive/{hifive_u540 => fu540}/config.mk (94%) rename platform/sifive/{hifive_u540 => fu540}/objects.mk (80%) create mode 100644 platform/sifive/fu540/platform.c delete mode 100644 platform/sifive/hifive_u540/platform.c diff --git a/platform/sifive/hifive_u540/config.mk b/platform/sifive/fu540/config.mk similarity index 94% rename from platform/sifive/hifive_u540/config.mk rename to platform/sifive/fu540/config.mk index 630098e54b7..07419b64e44 100644 --- a/platform/sifive/hifive_u540/config.mk +++ b/platform/sifive/fu540/config.mk @@ -2,7 +2,7 @@ # Copyright (c) 2018 Western Digital Corporation or its affiliates. # # Authors: -# Anup Patel +# Atish Patra # # SPDX-License-Identifier: BSD-2-Clause # diff --git a/platform/sifive/hifive_u540/objects.mk b/platform/sifive/fu540/objects.mk similarity index 80% rename from platform/sifive/hifive_u540/objects.mk rename to platform/sifive/fu540/objects.mk index 7e96bad0cef..0a4dfa7e83f 100644 --- a/platform/sifive/hifive_u540/objects.mk +++ b/platform/sifive/fu540/objects.mk @@ -2,7 +2,7 @@ # Copyright (c) 2018 Western Digital Corporation or its affiliates. # # Authors: -# Anup Patel +# Atish Patra # # SPDX-License-Identifier: BSD-2-Clause # diff --git a/platform/sifive/fu540/platform.c b/platform/sifive/fu540/platform.c new file mode 100644 index 00000000000..393509b4796 --- /dev/null +++ b/platform/sifive/fu540/platform.c @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2018 Western Digital Corporation or its affiliates. + * + * Authors: + * Atish Patra + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include +#include +#include +#include + +#define FU540_HART_COUNT 5 +#define FU540_HART_STACK_SIZE 8192 + +#define FU540_SYS_CLK 1000000000 + +#define FU540_CLINT_ADDR 0x2000000 + +#define FU540_PLIC_ADDR 0xc000000 +#define FU540_PLIC_NUM_SOURCES 0x35 +#define FU540_PLIC_NUM_PRIORITIES 7 + +#define FU540_UART0_ADDR 0x10010000 +#define FU540_UART1_ADDR 0x10011000 +#define FU540_UART_BAUDRATE 115200 + +#define FU540_HARITD_ENABLED 1 + +/* PRCI clock related macros */ +//TODO: Do we need a separate driver for this ? +#define FU540_PRCI_BASE_ADDR 0x10000000 +#define FU540_PRCI_CLKMUXSTATUSREG 0x002C +#define FU540_PRCI_CLKMUX_STATUS_TLCLKSEL (0x1 << 1) + +static int fu540_final_init(u32 hartid, bool cold_boot) +{ + u32 i; + void *fdt; + + if (!cold_boot) + return 0; + + fdt = sbi_scratch_thishart_arg1_ptr(); + plic_fdt_fixup(fdt, "riscv,plic0", 0); + for (i = 1; i < FU540_HART_COUNT; i++) + plic_fdt_fixup(fdt, "riscv,plic0", 2 * i - 1); + + return 0; +} + +static u32 fu540_pmp_region_count(u32 hartid) +{ + return 1; +} + +static int fu540_pmp_region_info(u32 hartid, u32 index, + ulong *prot, ulong *addr, ulong *log2size) +{ + int ret = 0; + + switch (index) { + case 0: + *prot = PMP_R | PMP_W | PMP_X; + *addr = 0; + *log2size = __riscv_xlen; + break; + default: + ret = -1; + break; + }; + + return ret; +} + +static int fu540_console_init(void) +{ + unsigned long peri_in_freq; + + if (readl((volatile void *)FU540_PRCI_BASE_ADDR + + FU540_PRCI_CLKMUXSTATUSREG) & + FU540_PRCI_CLKMUX_STATUS_TLCLKSEL) { + peri_in_freq = FU540_SYS_CLK; + } else { + peri_in_freq = FU540_SYS_CLK / 2; + } + + return sifive_uart_init(FU540_UART0_ADDR, + peri_in_freq, FU540_UART_BAUDRATE); +} + +static int fu540_irqchip_init(u32 hartid, bool cold_boot) +{ + int rc; + + if (cold_boot) { + rc = plic_cold_irqchip_init(FU540_PLIC_ADDR, + FU540_PLIC_NUM_SOURCES, + FU540_HART_COUNT); + if (rc) + return rc; + } + + return plic_warm_irqchip_init(hartid, + (hartid) ? (2 * hartid - 1) : 0, + (hartid) ? (2 * hartid) : -1); +} + +static int fu540_ipi_init(u32 hartid, bool cold_boot) +{ + int rc; + + if (cold_boot) { + rc = clint_cold_ipi_init(FU540_CLINT_ADDR, + FU540_HART_COUNT); + if (rc) + return rc; + + } + + return clint_warm_ipi_init(hartid); +} + +static int fu540_timer_init(u32 hartid, bool cold_boot) +{ + int rc; + + if (cold_boot) { + rc = clint_cold_timer_init(FU540_CLINT_ADDR, + FU540_HART_COUNT); + if (rc) + return rc; + } + + return clint_warm_timer_init(hartid); +} + +static int fu540_system_down(u32 type) +{ + /* For now nothing to do. */ + return 0; +} + +struct sbi_platform platform = { + .name = "SiFive Freedom U540", + .features = SBI_PLATFORM_DEFAULT_FEATURES, + .hart_count = FU540_HART_COUNT, + .hart_stack_size = FU540_HART_STACK_SIZE, + .disabled_hart_mask = ~(1 << FU540_HARITD_ENABLED), + .pmp_region_count = fu540_pmp_region_count, + .pmp_region_info = fu540_pmp_region_info, + .final_init = fu540_final_init, + .console_putc = sifive_uart_putc, + .console_getc = sifive_uart_getc, + .console_init = fu540_console_init, + .irqchip_init = fu540_irqchip_init, + .ipi_inject = clint_ipi_inject, + .ipi_sync = clint_ipi_sync, + .ipi_clear = clint_ipi_clear, + .ipi_init = fu540_ipi_init, + .timer_value = clint_timer_value, + .timer_event_stop = clint_timer_event_stop, + .timer_event_start = clint_timer_event_start, + .timer_init = fu540_timer_init, + .system_reboot = fu540_system_down, + .system_shutdown = fu540_system_down +}; diff --git a/platform/sifive/hifive_u540/platform.c b/platform/sifive/hifive_u540/platform.c deleted file mode 100644 index 5528b0c0aa0..00000000000 --- a/platform/sifive/hifive_u540/platform.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (c) 2018 Western Digital Corporation or its affiliates. - * - * Authors: - * Anup Patel - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include -#include -#include -#include -#include -#include - -#define SIFIVE_U_HART_COUNT 5 -#define SIFIVE_U_HART_STACK_SIZE 8192 - -#define SIFIVE_U_SYS_CLK 1000000000 - -#define SIFIVE_U_CLINT_ADDR 0x2000000 - -#define SIFIVE_U_PLIC_ADDR 0xc000000 -#define SIFIVE_U_PLIC_NUM_SOURCES 0x35 -#define SIFIVE_U_PLIC_NUM_PRIORITIES 7 - -#define SIFIVE_U_UART0_ADDR 0x10010000 -#define SIFIVE_U_UART1_ADDR 0x10011000 -#define SIFIVE_UART_BAUDRATE 115200 - -#define SIFIVE_U_HARITD_ENABLED 1 - -/* PRCI clock related macros */ -//TODO: Do we need a separate driver for this ? -#define SIFIVE_PRCI_BASE_ADDR 0x10000000 -#define SIFIVE_PRCI_CLKMUXSTATUSREG 0x002C -#define SIFIVE_PRCI_CLKMUX_STATUS_TLCLKSEL (0x1 << 1) - -static int sifive_u_final_init(u32 hartid, bool cold_boot) -{ - u32 i; - void *fdt; - - if (!cold_boot) - return 0; - - fdt = sbi_scratch_thishart_arg1_ptr(); - plic_fdt_fixup(fdt, "riscv,plic0", 0); - for (i = 1; i < SIFIVE_U_HART_COUNT; i++) - plic_fdt_fixup(fdt, "riscv,plic0", 2 * i - 1); - - return 0; -} - -static u32 sifive_u_pmp_region_count(u32 hartid) -{ - return 1; -} - -static int sifive_u_pmp_region_info(u32 hartid, u32 index, - ulong *prot, ulong *addr, ulong *log2size) -{ - int ret = 0; - - switch (index) { - case 0: - *prot = PMP_R | PMP_W | PMP_X; - *addr = 0; - *log2size = __riscv_xlen; - break; - default: - ret = -1; - break; - }; - - return ret; -} - -static int sifive_u_console_init(void) -{ - unsigned long peri_in_freq; - - if (readl((volatile void *)SIFIVE_PRCI_BASE_ADDR + - SIFIVE_PRCI_CLKMUXSTATUSREG) & - SIFIVE_PRCI_CLKMUX_STATUS_TLCLKSEL){ - peri_in_freq = SIFIVE_U_SYS_CLK; - } else { - peri_in_freq = SIFIVE_U_SYS_CLK / 2; - } - - return sifive_uart_init(SIFIVE_U_UART0_ADDR, - peri_in_freq, SIFIVE_UART_BAUDRATE); -} - -static int sifive_u_irqchip_init(u32 hartid, bool cold_boot) -{ - int rc; - - if (cold_boot) { - rc = plic_cold_irqchip_init(SIFIVE_U_PLIC_ADDR, - SIFIVE_U_PLIC_NUM_SOURCES, - SIFIVE_U_HART_COUNT); - if (rc) - return rc; - } - - return plic_warm_irqchip_init(hartid, - (hartid) ? (2 * hartid - 1) : 0, - (hartid) ? (2 * hartid) : -1); -} - -static int sifive_u_ipi_init(u32 hartid, bool cold_boot) -{ - int rc; - - if (cold_boot) { - rc = clint_cold_ipi_init(SIFIVE_U_CLINT_ADDR, - SIFIVE_U_HART_COUNT); - if (rc) - return rc; - - } - - return clint_warm_ipi_init(hartid); -} - -static int sifive_u_timer_init(u32 hartid, bool cold_boot) -{ - int rc; - - if (cold_boot) { - rc = clint_cold_timer_init(SIFIVE_U_CLINT_ADDR, - SIFIVE_U_HART_COUNT); - if (rc) - return rc; - } - - return clint_warm_timer_init(hartid); -} - -static int sifive_u_system_down(u32 type) -{ - /* For now nothing to do. */ - return 0; -} - -struct sbi_platform platform = { - .name = "SiFive HiFive U540", - .features = SBI_PLATFORM_DEFAULT_FEATURES, - .hart_count = SIFIVE_U_HART_COUNT, - .hart_stack_size = SIFIVE_U_HART_STACK_SIZE, - .disabled_hart_mask = ~(1 << SIFIVE_U_HARITD_ENABLED), - .pmp_region_count = sifive_u_pmp_region_count, - .pmp_region_info = sifive_u_pmp_region_info, - .final_init = sifive_u_final_init, - .console_putc = sifive_uart_putc, - .console_getc = sifive_uart_getc, - .console_init = sifive_u_console_init, - .irqchip_init = sifive_u_irqchip_init, - .ipi_inject = clint_ipi_inject, - .ipi_sync = clint_ipi_sync, - .ipi_clear = clint_ipi_clear, - .ipi_init = sifive_u_ipi_init, - .timer_value = clint_timer_value, - .timer_event_stop = clint_timer_event_stop, - .timer_event_start = clint_timer_event_start, - .timer_init = sifive_u_timer_init, - .system_reboot = sifive_u_system_down, - .system_shutdown = sifive_u_system_down -}; From 56e41f7a8db2c9bcfd1116748d496e5d40d2397b Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 28 Dec 2018 11:01:37 +0530 Subject: [PATCH 0055/1765] platform: Fix author name for Kendryte K210 platform The Kendryte K210 platform support was contributed by Damien hence fix author name. Signed-off-by: Anup Patel --- platform/kendryte/k210/config.mk | 2 +- platform/kendryte/k210/objects.mk | 2 +- platform/kendryte/k210/platform.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/kendryte/k210/config.mk b/platform/kendryte/k210/config.mk index 512fc2abe86..4a5b5920df6 100644 --- a/platform/kendryte/k210/config.mk +++ b/platform/kendryte/k210/config.mk @@ -2,7 +2,7 @@ # Copyright (c) 2018 Western Digital Corporation or its affiliates. # # Authors: -# Anup Patel +# Damien Le Moal # # SPDX-License-Identifier: BSD-2-Clause # diff --git a/platform/kendryte/k210/objects.mk b/platform/kendryte/k210/objects.mk index 3e16abe63a8..1f0a20b7f8c 100644 --- a/platform/kendryte/k210/objects.mk +++ b/platform/kendryte/k210/objects.mk @@ -2,7 +2,7 @@ # Copyright (c) 2018 Western Digital Corporation or its affiliates. # # Authors: -# Anup Patel +# Damien Le Moal # # SPDX-License-Identifier: BSD-2-Clause # diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c index 141c98e30ba..35119dbc317 100644 --- a/platform/kendryte/k210/platform.c +++ b/platform/kendryte/k210/platform.c @@ -2,7 +2,7 @@ * Copyright (c) 2018 Western Digital Corporation or its affiliates. * * Authors: - * Anup Patel + * Damien Le Moal * * SPDX-License-Identifier: BSD-2-Clause */ From 5959312a5c26df64ebfdd9b4d926e88cf3d87840 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Thu, 27 Dec 2018 21:39:13 +0530 Subject: [PATCH 0056/1765] lib: Redirect illegal instruction trap to S-mode when not handled Currently, we fail with error SBI_ENOTSUPP when we are not able to handle illegal instruction trap. Instead, we should just redirect illegal instruction trap to S-mode when not handled. This redirection of illegal instruction trap will help lazy save/restore of floating point registers to work correctly in Linux kernel. Signed-off-by: Anup Patel --- include/sbi/riscv_encoding.h | 9 +++++--- include/sbi/sbi_trap.h | 4 ++++ lib/sbi_illegal_insn.c | 6 ++--- lib/sbi_trap.c | 43 ++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 6 deletions(-) diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h index 1adc0c55b1a..381f3058960 100644 --- a/include/sbi/riscv_encoding.h +++ b/include/sbi/riscv_encoding.h @@ -19,12 +19,15 @@ #define MSTATUS_HIE 0x00000004 #define MSTATUS_MIE 0x00000008 #define MSTATUS_UPIE 0x00000010 -#define MSTATUS_SPIE 0x00000020 +#define MSTATUS_SPIE_SHIFT 5 +#define MSTATUS_SPIE (1UL << MSTATUS_SPIE_SHIFT) #define MSTATUS_HPIE 0x00000040 #define MSTATUS_MPIE 0x00000080 -#define MSTATUS_SPP 0x00000100 +#define MSTATUS_SPP_SHIFT 8 +#define MSTATUS_SPP (1UL << MSTATUS_SPP_SHIFT) #define MSTATUS_HPP 0x00000600 -#define MSTATUS_MPP 0x00001800 +#define MSTATUS_MPP_SHIFT 11 +#define MSTATUS_MPP (3UL << MSTATUS_MPP_SHIFT) #define MSTATUS_FS 0x00006000 #define MSTATUS_XS 0x00018000 #define MSTATUS_MPRV 0x00020000 diff --git a/include/sbi/sbi_trap.h b/include/sbi/sbi_trap.h index a6b22e48945..4e5a054c0ef 100644 --- a/include/sbi/sbi_trap.h +++ b/include/sbi/sbi_trap.h @@ -51,6 +51,10 @@ struct sbi_trap_regs { struct sbi_scratch; +int sbi_trap_redirect(struct sbi_trap_regs *regs, + struct sbi_scratch *scratch, + ulong epc, ulong cause, ulong tval); + void sbi_trap_handler(struct sbi_trap_regs *regs, struct sbi_scratch *scratch); diff --git a/lib/sbi_illegal_insn.c b/lib/sbi_illegal_insn.c index 9383df47e4c..1bdc75902a9 100644 --- a/lib/sbi_illegal_insn.c +++ b/lib/sbi_illegal_insn.c @@ -26,8 +26,7 @@ static int truly_illegal_insn(ulong insn, struct sbi_trap_regs *regs, struct sbi_scratch *scratch) { - /* For now, always fails */ - return SBI_ENOTSUPP; + return sbi_trap_redirect(regs, scratch, regs->mepc, mcause, insn); } static int system_opcode_insn(ulong insn, @@ -132,7 +131,8 @@ int sbi_illegal_insn_handler(u32 hartid, ulong mcause, insn = get_insn(regs->mepc, &mstatus); } if ((insn & 3) != 3) - return SBI_ENOTSUPP; + return truly_illegal_insn(insn, hartid, mcause, + regs, scratch); } return illegal_insn_table[(insn & 0x7c) >> 2](insn, hartid, mcause, diff --git a/lib/sbi_trap.c b/lib/sbi_trap.c index ab78b576888..0e731e46f77 100644 --- a/lib/sbi_trap.c +++ b/lib/sbi_trap.c @@ -66,6 +66,49 @@ static void __attribute__((noreturn)) sbi_trap_error(const char *msg, sbi_hart_hang(); } +int sbi_trap_redirect(struct sbi_trap_regs *regs, + struct sbi_scratch *scratch, + ulong epc, ulong cause, ulong tval) +{ + ulong new_mstatus, prev_mode; + + /* Sanity check on previous mode */ + prev_mode = (regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT; + if (prev_mode != PRV_S && prev_mode != PRV_U) + return SBI_ENOTSUPP; + + /* Update S-mode exception info */ + csr_write(stval, tval); + csr_write(sepc, epc); + csr_write(scause, cause); + + /* Set MEPC to S-mode exception vector base */ + regs->mepc = csr_read(stvec); + + /* Initial value of new MSTATUS */ + new_mstatus = regs->mstatus; + + /* Clear MPP, SPP, SPIE, and SIE */ + new_mstatus &= ~(MSTATUS_MPP | + MSTATUS_SPP | MSTATUS_SPIE | MSTATUS_SIE); + + /* Set SPP */ + if (prev_mode == PRV_S) + new_mstatus |= (1UL << MSTATUS_SPP_SHIFT); + + /* Set SPIE */ + if (regs->mstatus & MSTATUS_SIE) + new_mstatus |= (1UL << MSTATUS_SPIE_SHIFT); + + /* Set MPP */ + new_mstatus |= (PRV_S << MSTATUS_MPP_SHIFT); + + /* Set new value in MSTATUS */ + regs->mstatus = new_mstatus; + + return 0; +} + void sbi_trap_handler(struct sbi_trap_regs *regs, struct sbi_scratch *scratch) { From 5688b4d8fcd39eaf504e73279bbe42b9700369da Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 28 Dec 2018 14:20:25 +0530 Subject: [PATCH 0057/1765] top: Minor typo fixes in top-level README.md This patch does minor typo fixes in top-level README.md. Signed-off-by: Anup Patel --- README.md | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 7b142d56e98..c38f54320fe 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,9 @@ RISC-V Open Source Supervisor Binary Interface (OpenSBI) The **RISC-V Supervisor Binary Interface (SBI)** is a recommended interface between: -1. A pplatform specific firmware executed in M-mode and a general purpose - OS hypervisor or bootloader executed in S-mode or HS-mode. -2. A hypervisor executed in HS-mode and a general purpose OS or bootloader - executed in VS-mode +1. A platform specific firmware (M-mode) and a general purpose + OS or hypervisor or bootloader (S-mode or HS-mode). +2. A hypervisor (HS-mode) and a general purpose OS or bootloader (VS-mode) The *RISC-V SBI specification* is maintained as an independent project by the RISC-V Foundation in [Github](https://github.com/riscv/riscv-sbi-doc) @@ -59,17 +58,16 @@ Building and Installing platform specific *libsbi.a* and firmwares ------------------------------------------------------------------ The libplatsbi.a and firmware files are only built if the -*PLATFORM=* argument is specified on make command lines. -** must specify the path to one of the leaf directories -under the *platform* directory. For example, to compile the library and -firmware for QEMU generic RISC-V *virt* machine, ** -should be *qemu/virt*. +*`PLATFORM=`* argument is specified on make command lines. +*``* must specify the path to one of the leaf directories +under the *`platform`* directory. For example, to compile the library and +firmware for QEMU RISC-V *virt* machine, *``* +should be *`qemu/virt`*. To build *libsbi, libplatsbi, and firmwares* for a specific platform, run: ``` make PLATFORM= ``` - or ``` @@ -80,7 +78,6 @@ To install *libsbi, headers, libplatsbi, and firmwares*, run: ``` make PLATFORM= install ``` - or ``` @@ -88,7 +85,7 @@ make PLATFORM= I= install` ``` In addition, platform specific make command-line options to top-level make -,such as *PLATFORM_* or *FW_* can also be specified. These +, such as *PLATFORM_* or *FW_* can also be specified. These options are described under *docs/platform/.md* and *docs/firmware/.md*. From d0bbbbb8fdf059b2e49235af271db0d67ade2fc9 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 28 Dec 2018 14:21:57 +0530 Subject: [PATCH 0058/1765] docs: Add documenation for QEMU platforms This patch adds documentation for qemu/virt and qemu/sifive_u platform supports. Signed-off-by: Anup Patel --- docs/platform/qemu_sifive_u.md | 42 ++++++++++++++++++++++++ docs/platform/qemu_virt.md | 59 ++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 docs/platform/qemu_sifive_u.md create mode 100644 docs/platform/qemu_virt.md diff --git a/docs/platform/qemu_sifive_u.md b/docs/platform/qemu_sifive_u.md new file mode 100644 index 00000000000..da1315bc4cc --- /dev/null +++ b/docs/platform/qemu_sifive_u.md @@ -0,0 +1,42 @@ +QEMU SiFive Unleashed Machine +============================= + +The **QEMU SiFive Unleashed Machine** is an emulation of +SiFive Unleashed platform. + +To build platform specific library and firmwares, provide +`PLATFORM=qemu/sifive_u` parameter to top-level make. + +Platform Options +---------------- + +We don't have any platform specific options for this platform. + +Try on QEMU RISC-V 64bit +------------------------ + +**No Payload** + +*Build*: +``` + make PLATFORM=qemu/virt +``` +*Run*: +``` + qemu-system-riscv64 -M sifive_u -m 256M -display none -serial stdio -kernel build/platform/qemu/sifive_u/firmware/fw_payload.elf +``` + +**U-Boot Payload** + +*Note*: We assume that U-Boot is compiled using `qemu-riscv64_smode_defconfig`. + +*Build*: +``` + make PLATFORM=qemu/virt FW_PAYLOAD_PATH=/u-boot.bin +``` +*Run*: +``` + qemu-system-riscv64 -M sifive_u -m 256M -display none -serial stdio -kernel build/platform/qemu/sifive_u/firmware/fw_payload.elf + or + qemu-system-riscv64 -M sifive_u -m 256M -display none -serial stdio -kernel build/platform/qemu/sifive_u/firmware/fw_jump.elf -device loader,file=/u-boot.bin,addr=0x80200000 +``` \ No newline at end of file diff --git a/docs/platform/qemu_virt.md b/docs/platform/qemu_virt.md new file mode 100644 index 00000000000..c9a4a2c9864 --- /dev/null +++ b/docs/platform/qemu_virt.md @@ -0,0 +1,59 @@ +QEMU RISC-V Virt Machine +======================== + +The **QEMU RISC-V Virt Machine** is virtual platform created +for RISC-V software development. It is also referred to as +QEMU RISC-V VirtIO machine because it uses VirtIO devices +for network, storage, and other types of IO. + +To build platform specific library and firmwares, provide +`PLATFORM=qemu/virt` parameter to top-level make. + +Platform Options +---------------- + +We don't have any platform specific options for this platform. + +Try on QEMU RISC-V 64bit +------------------------ + +**No Payload** + +*Build*: +``` + make PLATFORM=qemu/virt +``` +*Run*: +``` + qemu-system-riscv64 -M virt -m 256M -display none -serial stdio -kernel build/platform/qemu/virt/firmware/fw_payload.elf +``` + +**U-Boot Payload** + +*Note*: We assume that U-Boot is compiled using `qemu-riscv64_smode_defconfig`. + +*Build*: +``` + make PLATFORM=qemu/virt FW_PAYLOAD_PATH=/u-boot.bin +``` +*Run*: +``` + qemu-system-riscv64 -M virt -m 256M -display none -serial stdio -kernel build/platform/qemu/virt/firmware/fw_payload.elf + or + qemu-system-riscv64 -M virt -m 256M -display none -serial stdio -kernel build/platform/qemu/virt/firmware/fw_jump.elf -device loader,file=/u-boot.bin,addr=0x80200000 +``` + +**Linux Payload** + +*Note*: We assume that Linux is compiled using `defconfig`. + +*Build*: +``` + make PLATFORM=qemu/virt FW_PAYLOAD_PATH=/arch/riscv/boot/Image +``` +*Run*: +``` + qemu-system-riscv64 -M virt -m 256M -display none -serial stdio -kernel build/platform/qemu/virt/firmware/fw_payload.elf -drive file=,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -append "root=/dev/vda rw console=ttyS0" + or + qemu-system-riscv64 -M virt -m 256M -display none -serial stdio -kernel build/platform/qemu/virt/firmware/fw_jump.elf -device loader,file=/arch/riscv/boot/Image,addr=0x80200000 -drive file=,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -append "root=/dev/vda rw console=ttyS0" +``` \ No newline at end of file From 81e8950abeb649a0842726fdfc1aa4e60b1008f5 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Mon, 31 Dec 2018 10:25:42 +0530 Subject: [PATCH 0059/1765] include: Remove redundant csr_read_n() and csr_write_n() The patch removes redundant csr_read_n() and csr_write_n() because same thing can be achieved by using __ASM_STR() macro in csr_read() and csr_write() macros. Signed-off-by: Anup Patel --- include/sbi/riscv_asm.h | 21 ++--------- lib/riscv_asm.c | 80 ++++++++++++++++++++--------------------- 2 files changed, 42 insertions(+), 59 deletions(-) diff --git a/include/sbi/riscv_asm.h b/include/sbi/riscv_asm.h index 045310b5d5a..c7a89379c74 100644 --- a/include/sbi/riscv_asm.h +++ b/include/sbi/riscv_asm.h @@ -140,16 +140,7 @@ #define csr_read(csr) \ ({ \ register unsigned long __v; \ - __asm__ __volatile__ ("csrr %0, " #csr \ - : "=r" (__v) : \ - : "memory"); \ - __v; \ -}) - -#define csr_read_n(csr_num) \ -({ \ - register unsigned long __v; \ - __asm__ __volatile__ ("csrr %0, " __ASM_STR(csr_num) \ + __asm__ __volatile__ ("csrr %0, " __ASM_STR(csr) \ : "=r" (__v) : \ : "memory"); \ __v; \ @@ -158,15 +149,7 @@ #define csr_write(csr, val) \ ({ \ unsigned long __v = (unsigned long)(val); \ - __asm__ __volatile__ ("csrw " #csr ", %0" \ - : : "rK" (__v) \ - : "memory"); \ -}) - -#define csr_write_n(csr_num, val) \ -({ \ - unsigned long __v = (unsigned long)(val); \ - __asm__ __volatile__ ("csrw " __ASM_STR(csr_num) ", %0" \ + __asm__ __volatile__ ("csrw " __ASM_STR(csr) ", %0" \ : : "rK" (__v) \ : "memory"); \ }) diff --git a/lib/riscv_asm.c b/lib/riscv_asm.c index 0fbdb315e72..4ffd7547b65 100644 --- a/lib/riscv_asm.c +++ b/lib/riscv_asm.c @@ -17,64 +17,64 @@ unsigned long csr_read_num(int csr_num) switch (csr_num) { case CSR_PMPCFG0: - ret = csr_read_n(CSR_PMPCFG0); + ret = csr_read(CSR_PMPCFG0); break; case CSR_PMPCFG1: - ret = csr_read_n(CSR_PMPCFG1); + ret = csr_read(CSR_PMPCFG1); break; case CSR_PMPCFG2: - ret = csr_read_n(CSR_PMPCFG2); + ret = csr_read(CSR_PMPCFG2); break; case CSR_PMPCFG3: - ret = csr_read_n(CSR_PMPCFG3); + ret = csr_read(CSR_PMPCFG3); break; case CSR_PMPADDR0: - ret = csr_read_n(CSR_PMPADDR0); + ret = csr_read(CSR_PMPADDR0); break; case CSR_PMPADDR1: - ret = csr_read_n(CSR_PMPADDR1); + ret = csr_read(CSR_PMPADDR1); break; case CSR_PMPADDR2: - ret = csr_read_n(CSR_PMPADDR2); + ret = csr_read(CSR_PMPADDR2); break; case CSR_PMPADDR3: - ret = csr_read_n(CSR_PMPADDR3); + ret = csr_read(CSR_PMPADDR3); break; case CSR_PMPADDR4: - ret = csr_read_n(CSR_PMPADDR4); + ret = csr_read(CSR_PMPADDR4); break; case CSR_PMPADDR5: - ret = csr_read_n(CSR_PMPADDR5); + ret = csr_read(CSR_PMPADDR5); break; case CSR_PMPADDR6: - ret = csr_read_n(CSR_PMPADDR6); + ret = csr_read(CSR_PMPADDR6); break; case CSR_PMPADDR7: - ret = csr_read_n(CSR_PMPADDR7); + ret = csr_read(CSR_PMPADDR7); break; case CSR_PMPADDR8: - ret = csr_read_n(CSR_PMPADDR8); + ret = csr_read(CSR_PMPADDR8); break; case CSR_PMPADDR9: - ret = csr_read_n(CSR_PMPADDR9); + ret = csr_read(CSR_PMPADDR9); break; case CSR_PMPADDR10: - ret = csr_read_n(CSR_PMPADDR10); + ret = csr_read(CSR_PMPADDR10); break; case CSR_PMPADDR11: - ret = csr_read_n(CSR_PMPADDR11); + ret = csr_read(CSR_PMPADDR11); break; case CSR_PMPADDR12: - ret = csr_read_n(CSR_PMPADDR12); + ret = csr_read(CSR_PMPADDR12); break; case CSR_PMPADDR13: - ret = csr_read_n(CSR_PMPADDR13); + ret = csr_read(CSR_PMPADDR13); break; case CSR_PMPADDR14: - ret = csr_read_n(CSR_PMPADDR14); + ret = csr_read(CSR_PMPADDR14); break; case CSR_PMPADDR15: - ret = csr_read_n(CSR_PMPADDR15); + ret = csr_read(CSR_PMPADDR15); break; default: break; @@ -87,64 +87,64 @@ void csr_write_num(int csr_num, unsigned long val) { switch (csr_num) { case CSR_PMPCFG0: - csr_write_n(CSR_PMPCFG0, val); + csr_write(CSR_PMPCFG0, val); break; case CSR_PMPCFG1: - csr_write_n(CSR_PMPCFG1, val); + csr_write(CSR_PMPCFG1, val); break; case CSR_PMPCFG2: - csr_write_n(CSR_PMPCFG2, val); + csr_write(CSR_PMPCFG2, val); break; case CSR_PMPCFG3: - csr_write_n(CSR_PMPCFG3, val); + csr_write(CSR_PMPCFG3, val); break; case CSR_PMPADDR0: - csr_write_n(CSR_PMPADDR0, val); + csr_write(CSR_PMPADDR0, val); break; case CSR_PMPADDR1: - csr_write_n(CSR_PMPADDR1, val); + csr_write(CSR_PMPADDR1, val); break; case CSR_PMPADDR2: - csr_write_n(CSR_PMPADDR2, val); + csr_write(CSR_PMPADDR2, val); break; case CSR_PMPADDR3: - csr_write_n(CSR_PMPADDR3, val); + csr_write(CSR_PMPADDR3, val); break; case CSR_PMPADDR4: - csr_write_n(CSR_PMPADDR4, val); + csr_write(CSR_PMPADDR4, val); break; case CSR_PMPADDR5: - csr_write_n(CSR_PMPADDR5, val); + csr_write(CSR_PMPADDR5, val); break; case CSR_PMPADDR6: - csr_write_n(CSR_PMPADDR6, val); + csr_write(CSR_PMPADDR6, val); break; case CSR_PMPADDR7: - csr_write_n(CSR_PMPADDR7, val); + csr_write(CSR_PMPADDR7, val); break; case CSR_PMPADDR8: - csr_write_n(CSR_PMPADDR8, val); + csr_write(CSR_PMPADDR8, val); break; case CSR_PMPADDR9: - csr_write_n(CSR_PMPADDR9, val); + csr_write(CSR_PMPADDR9, val); break; case CSR_PMPADDR10: - csr_write_n(CSR_PMPADDR10, val); + csr_write(CSR_PMPADDR10, val); break; case CSR_PMPADDR11: - csr_write_n(CSR_PMPADDR11, val); + csr_write(CSR_PMPADDR11, val); break; case CSR_PMPADDR12: - csr_write_n(CSR_PMPADDR12, val); + csr_write(CSR_PMPADDR12, val); break; case CSR_PMPADDR13: - csr_write_n(CSR_PMPADDR13, val); + csr_write(CSR_PMPADDR13, val); break; case CSR_PMPADDR14: - csr_write_n(CSR_PMPADDR14, val); + csr_write(CSR_PMPADDR14, val); break; case CSR_PMPADDR15: - csr_write_n(CSR_PMPADDR15, val); + csr_write(CSR_PMPADDR15, val); break; default: break; From 24bfa687fc85f0c8b0b2ed60151e44e9b7c43d3b Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Mon, 31 Dec 2018 10:29:49 +0530 Subject: [PATCH 0060/1765] include: Replace #csr with __ASM_STR(csr) in csr_xyz() macros We replace #csr with __ASM_STR(csr) in all csr_xyz() macros so that we can pass CSR number instead of CSR name when GCC is not aware of CSR name. Signed-off-by: Anup Patel --- include/sbi/riscv_asm.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/sbi/riscv_asm.h b/include/sbi/riscv_asm.h index c7a89379c74..edf35ece6e0 100644 --- a/include/sbi/riscv_asm.h +++ b/include/sbi/riscv_asm.h @@ -131,7 +131,7 @@ #define csr_swap(csr, val) \ ({ \ unsigned long __v = (unsigned long)(val); \ - __asm__ __volatile__ ("csrrw %0, " #csr ", %1" \ + __asm__ __volatile__ ("csrrw %0, " __ASM_STR(csr) ", %1"\ : "=r" (__v) : "rK" (__v) \ : "memory"); \ __v; \ @@ -157,7 +157,7 @@ #define csr_read_set(csr, val) \ ({ \ unsigned long __v = (unsigned long)(val); \ - __asm__ __volatile__ ("csrrs %0, " #csr ", %1" \ + __asm__ __volatile__ ("csrrs %0, " __ASM_STR(csr) ", %1"\ : "=r" (__v) : "rK" (__v) \ : "memory"); \ __v; \ @@ -166,7 +166,7 @@ #define csr_set(csr, val) \ ({ \ unsigned long __v = (unsigned long)(val); \ - __asm__ __volatile__ ("csrs " #csr ", %0" \ + __asm__ __volatile__ ("csrs " __ASM_STR(csr) ", %0" \ : : "rK" (__v) \ : "memory"); \ }) @@ -174,7 +174,7 @@ #define csr_read_clear(csr, val) \ ({ \ unsigned long __v = (unsigned long)(val); \ - __asm__ __volatile__ ("csrrc %0, " #csr ", %1" \ + __asm__ __volatile__ ("csrrc %0, " __ASM_STR(csr) ", %1"\ : "=r" (__v) : "rK" (__v) \ : "memory"); \ __v; \ @@ -183,7 +183,7 @@ #define csr_clear(csr, val) \ ({ \ unsigned long __v = (unsigned long)(val); \ - __asm__ __volatile__ ("csrc " #csr ", %0" \ + __asm__ __volatile__ ("csrc " __ASM_STR(csr) ", %0" \ : : "rK" (__v) \ : "memory"); \ }) From e0d6914b3c40c1609ccf196fa448ea6880ff23d5 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Mon, 31 Dec 2018 11:19:20 +0530 Subject: [PATCH 0061/1765] include: Move RISCV_SCRATCH_xyz defines to sbi_scratch.h The struct sbi_scratch related defines RISCV_SCRATCH_xyz should be in sbi_scratch.h so that we can keep these defines in-sync with changes in struct sbi_scratch. Signed-off-by: Anup Patel --- firmware/fw_base.S | 25 +++++++++++++------------ include/sbi/riscv_asm.h | 12 ------------ include/sbi/sbi_scratch.h | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index d426f15f753..d872061dce6 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -9,6 +9,7 @@ #include #include +#include .align 3 .section .entry, "ax", %progbits @@ -146,34 +147,34 @@ _start_warm: add tp, tp, a5 mul a5, s8, s6 sub tp, tp, a5 - li a5, RISCV_SCRATCH_SIZE + li a5, SBI_SCRATCH_SIZE sub tp, tp, a5 csrw mscratch, tp /* Initialize scratch space */ - REG_S zero, RISCV_SCRATCH_TMP0_OFFSET(tp) + REG_S zero, SBI_SCRATCH_TMP0_OFFSET(tp) la a4, _fw_start la a5, _fw_end mul t0, s7, s8 add a5, a5, t0 sub a5, a5, a4 - REG_S a4, RISCV_SCRATCH_FW_START_OFFSET(tp) - REG_S a5, RISCV_SCRATCH_FW_SIZE_OFFSET(tp) + REG_S a4, SBI_SCRATCH_FW_START_OFFSET(tp) + REG_S a5, SBI_SCRATCH_FW_SIZE_OFFSET(tp) /* Note: fw_next_arg1() uses a0, a1, and ra */ call fw_next_arg1 - REG_S a0, RISCV_SCRATCH_NEXT_ARG1_OFFSET(tp) + REG_S a0, SBI_SCRATCH_NEXT_ARG1_OFFSET(tp) /* Note: fw_next_addr() uses a0, a1, and ra */ call fw_next_addr - REG_S a0, RISCV_SCRATCH_NEXT_ADDR_OFFSET(tp) + REG_S a0, SBI_SCRATCH_NEXT_ADDR_OFFSET(tp) li a4, PRV_S - REG_S a4, RISCV_SCRATCH_NEXT_MODE_OFFSET(tp) + REG_S a4, SBI_SCRATCH_NEXT_MODE_OFFSET(tp) la a4, _start_warm - REG_S a4, RISCV_SCRATCH_WARMBOOT_ADDR_OFFSET(tp) + REG_S a4, SBI_SCRATCH_WARMBOOT_ADDR_OFFSET(tp) la a4, platform - REG_S a4, RISCV_SCRATCH_PLATFORM_ADDR_OFFSET(tp) + REG_S a4, SBI_SCRATCH_PLATFORM_ADDR_OFFSET(tp) la a4, _hartid_to_scratch - REG_S a4, RISCV_SCRATCH_HARTID_TO_SCRATCH_OFFSET(tp) - REG_S zero, RISCV_SCRATCH_IPI_TYPE_OFFSET(tp) + REG_S a4, SBI_SCRATCH_HARTID_TO_SCRATCH_OFFSET(tp) + REG_S zero, SBI_SCRATCH_IPI_TYPE_OFFSET(tp) /* Setup stack */ add sp, tp, zero @@ -211,7 +212,7 @@ _hartid_to_scratch: add s1, s1, s2 mul s2, s0, a0 sub s1, s1, s2 - li s2, RISCV_SCRATCH_SIZE + li s2, SBI_SCRATCH_SIZE sub a0, s1, s2 REG_L s0, (sp) REG_L s1, (__SIZEOF_POINTER__)(sp) diff --git a/include/sbi/riscv_asm.h b/include/sbi/riscv_asm.h index edf35ece6e0..c169d93c49c 100644 --- a/include/sbi/riscv_asm.h +++ b/include/sbi/riscv_asm.h @@ -69,18 +69,6 @@ #error "Unexpected __SIZEOF_SHORT__" #endif -#define RISCV_SCRATCH_TMP0_OFFSET (0 * __SIZEOF_POINTER__) -#define RISCV_SCRATCH_FW_START_OFFSET (1 * __SIZEOF_POINTER__) -#define RISCV_SCRATCH_FW_SIZE_OFFSET (2 * __SIZEOF_POINTER__) -#define RISCV_SCRATCH_NEXT_ARG1_OFFSET (3 * __SIZEOF_POINTER__) -#define RISCV_SCRATCH_NEXT_ADDR_OFFSET (4 * __SIZEOF_POINTER__) -#define RISCV_SCRATCH_NEXT_MODE_OFFSET (5 * __SIZEOF_POINTER__) -#define RISCV_SCRATCH_WARMBOOT_ADDR_OFFSET (6 * __SIZEOF_POINTER__) -#define RISCV_SCRATCH_PLATFORM_ADDR_OFFSET (7 * __SIZEOF_POINTER__) -#define RISCV_SCRATCH_HARTID_TO_SCRATCH_OFFSET (8 * __SIZEOF_POINTER__) -#define RISCV_SCRATCH_IPI_TYPE_OFFSET (9 * __SIZEOF_POINTER__) -#define RISCV_SCRATCH_SIZE 256 - #define RISCV_PLATFORM_NAME_OFFSET (0x0) #define RISCV_PLATFORM_FEATURES_OFFSET (0x40) #define RISCV_PLATFORM_HART_COUNT_OFFSET (0x48) diff --git a/include/sbi/sbi_scratch.h b/include/sbi/sbi_scratch.h index d5c6f353c75..14c72a853dc 100644 --- a/include/sbi/sbi_scratch.h +++ b/include/sbi/sbi_scratch.h @@ -11,6 +11,21 @@ #define __SBI_SCRATCH_H__ #include + +#define SBI_SCRATCH_TMP0_OFFSET (0 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_FW_START_OFFSET (1 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_FW_SIZE_OFFSET (2 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_NEXT_ARG1_OFFSET (3 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_NEXT_ADDR_OFFSET (4 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_NEXT_MODE_OFFSET (5 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_WARMBOOT_ADDR_OFFSET (6 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_PLATFORM_ADDR_OFFSET (7 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_HARTID_TO_SCRATCH_OFFSET (8 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_IPI_TYPE_OFFSET (9 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_SIZE 256 + +#ifndef __ASSEMBLY__ + #include struct sbi_scratch { @@ -33,3 +48,5 @@ struct sbi_scratch { ((void *)(sbi_scratch_thishart_ptr()->next_arg1)) #endif + +#endif From 5ed3cf37073125a38ac839ad11de687f20286b33 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Mon, 31 Dec 2018 11:30:55 +0530 Subject: [PATCH 0062/1765] include: Move RISCV_PLATFORM_xyz defines to sbi_platform.h The struct sbi_platform related defines RISCV_PLATFORM_xyz should be in sbi_platform.h so that we can keep these defines in-sync with changes in struct sbi_platform. Signed-off-by: Anup Patel --- firmware/fw_base.S | 9 +++++---- include/sbi/riscv_asm.h | 5 ----- include/sbi/sbi_platform.h | 9 +++++++++ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index d872061dce6..d927c3e06e1 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -9,6 +9,7 @@ #include #include +#include #include .align 3 @@ -134,8 +135,8 @@ _start_warm: */ csrr s6, mhartid la a4, platform - lwu s7, RISCV_PLATFORM_HART_COUNT_OFFSET(a4) - lwu s8, RISCV_PLATFORM_HART_STACK_SIZE_OFFSET(a4) + lwu s7, SBI_PLATFORM_HART_COUNT_OFFSET(a4) + lwu s8, SBI_PLATFORM_HART_STACK_SIZE_OFFSET(a4) /* HART ID should be within expected limit */ csrr s6, mhartid @@ -205,8 +206,8 @@ _hartid_to_scratch: * s2 -> Temporary */ la s2, platform - lwu s0, RISCV_PLATFORM_HART_STACK_SIZE_OFFSET(s2) - lwu s2, RISCV_PLATFORM_HART_COUNT_OFFSET(s2) + lwu s0, SBI_PLATFORM_HART_STACK_SIZE_OFFSET(s2) + lwu s2, SBI_PLATFORM_HART_COUNT_OFFSET(s2) mul s2, s2, s0 la s1, _fw_end add s1, s1, s2 diff --git a/include/sbi/riscv_asm.h b/include/sbi/riscv_asm.h index c169d93c49c..6fd7d5d75c4 100644 --- a/include/sbi/riscv_asm.h +++ b/include/sbi/riscv_asm.h @@ -69,11 +69,6 @@ #error "Unexpected __SIZEOF_SHORT__" #endif -#define RISCV_PLATFORM_NAME_OFFSET (0x0) -#define RISCV_PLATFORM_FEATURES_OFFSET (0x40) -#define RISCV_PLATFORM_HART_COUNT_OFFSET (0x48) -#define RISCV_PLATFORM_HART_STACK_SIZE_OFFSET (0x4c) - #define RISCV_TRAP_REGS_zero 0 #define RISCV_TRAP_REGS_ra 1 #define RISCV_TRAP_REGS_sp 2 diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 8532c03bb20..43fb4ea8c5f 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -10,6 +10,13 @@ #ifndef __SBI_PLATFORM_H__ #define __SBI_PLATFORM_H__ +#define SBI_PLATFORM_NAME_OFFSET (0x0) +#define SBI_PLATFORM_FEATURES_OFFSET (0x40) +#define SBI_PLATFORM_HART_COUNT_OFFSET (0x48) +#define SBI_PLATFORM_HART_STACK_SIZE_OFFSET (0x4c) + +#ifndef __ASSEMBLY__ + #include enum sbi_platform_features { @@ -240,3 +247,5 @@ static inline int sbi_platform_system_shutdown(struct sbi_platform *plat, } #endif + +#endif From dc7be34d523f93d2834f4aff49d640cdec16a509 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Mon, 31 Dec 2018 12:37:28 +0530 Subject: [PATCH 0063/1765] include: Move RISCV_TRAP_REGS_xyz defines to sbi_trap.h The struct sbi_trap_regs related defines RISCV_TRAP_REGS_xyz should be in sbi_trap.h so that we can keep these defines in-sync with changes in struct sbi_trap_regs. Signed-off-by: Anup Patel --- firmware/fw_base.S | 139 ++++++++++++++++++++-------------------- include/sbi/riscv_asm.h | 40 ------------ include/sbi/sbi_trap.h | 44 +++++++++++++ 3 files changed, 114 insertions(+), 109 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index d927c3e06e1..ab67a705271 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -11,6 +11,7 @@ #include #include #include +#include .align 3 .section .entry, "ax", %progbits @@ -236,18 +237,18 @@ _trap_handler: csrrw sp, mscratch, sp /* Setup exception stack */ - add sp, sp, -(RISCV_TRAP_REGS_SIZE) + add sp, sp, -(SBI_TRAP_REGS_SIZE) /* Save RA, T0, T1, and T2 */ - REG_S ra, RISCV_TRAP_REGS_OFFSET(ra)(sp) - REG_S t0, RISCV_TRAP_REGS_OFFSET(t0)(sp) - REG_S t1, RISCV_TRAP_REGS_OFFSET(t1)(sp) - REG_S t2, RISCV_TRAP_REGS_OFFSET(t2)(sp) + REG_S ra, SBI_TRAP_REGS_OFFSET(ra)(sp) + REG_S t0, SBI_TRAP_REGS_OFFSET(t0)(sp) + REG_S t1, SBI_TRAP_REGS_OFFSET(t1)(sp) + REG_S t2, SBI_TRAP_REGS_OFFSET(t2)(sp) /* Save original SP and restore MSCRATCH */ - add t0, sp, RISCV_TRAP_REGS_SIZE + add t0, sp, SBI_TRAP_REGS_SIZE csrrw t0, mscratch, t0 - REG_S t0, RISCV_TRAP_REGS_OFFSET(sp)(sp) + REG_S t0, SBI_TRAP_REGS_OFFSET(sp)(sp) /* Save MEPC and MSTATUS CSRs */ csrr t0, mepc @@ -261,37 +262,37 @@ _trap_handler: */ /* Save MEPC and MSTATUS CSRs */ - REG_S t0, RISCV_TRAP_REGS_OFFSET(mepc)(sp) - REG_S t1, RISCV_TRAP_REGS_OFFSET(mstatus)(sp) + REG_S t0, SBI_TRAP_REGS_OFFSET(mepc)(sp) + REG_S t1, SBI_TRAP_REGS_OFFSET(mstatus)(sp) /* Save all general regisers except SP, RA, T0, T1, and T2 */ - REG_S zero, RISCV_TRAP_REGS_OFFSET(zero)(sp) - REG_S gp, RISCV_TRAP_REGS_OFFSET(gp)(sp) - REG_S tp, RISCV_TRAP_REGS_OFFSET(tp)(sp) - REG_S s0, RISCV_TRAP_REGS_OFFSET(s0)(sp) - REG_S s1, RISCV_TRAP_REGS_OFFSET(s1)(sp) - REG_S a0, RISCV_TRAP_REGS_OFFSET(a0)(sp) - REG_S a1, RISCV_TRAP_REGS_OFFSET(a1)(sp) - REG_S a2, RISCV_TRAP_REGS_OFFSET(a2)(sp) - REG_S a3, RISCV_TRAP_REGS_OFFSET(a3)(sp) - REG_S a4, RISCV_TRAP_REGS_OFFSET(a4)(sp) - REG_S a5, RISCV_TRAP_REGS_OFFSET(a5)(sp) - REG_S a6, RISCV_TRAP_REGS_OFFSET(a6)(sp) - REG_S a7, RISCV_TRAP_REGS_OFFSET(a7)(sp) - REG_S s2, RISCV_TRAP_REGS_OFFSET(s2)(sp) - REG_S s3, RISCV_TRAP_REGS_OFFSET(s3)(sp) - REG_S s4, RISCV_TRAP_REGS_OFFSET(s4)(sp) - REG_S s5, RISCV_TRAP_REGS_OFFSET(s5)(sp) - REG_S s6, RISCV_TRAP_REGS_OFFSET(s6)(sp) - REG_S s7, RISCV_TRAP_REGS_OFFSET(s7)(sp) - REG_S s8, RISCV_TRAP_REGS_OFFSET(s8)(sp) - REG_S s9, RISCV_TRAP_REGS_OFFSET(s9)(sp) - REG_S s10, RISCV_TRAP_REGS_OFFSET(s10)(sp) - REG_S s11, RISCV_TRAP_REGS_OFFSET(s11)(sp) - REG_S t3, RISCV_TRAP_REGS_OFFSET(t3)(sp) - REG_S t4, RISCV_TRAP_REGS_OFFSET(t4)(sp) - REG_S t5, RISCV_TRAP_REGS_OFFSET(t5)(sp) - REG_S t6, RISCV_TRAP_REGS_OFFSET(t6)(sp) + REG_S zero, SBI_TRAP_REGS_OFFSET(zero)(sp) + REG_S gp, SBI_TRAP_REGS_OFFSET(gp)(sp) + REG_S tp, SBI_TRAP_REGS_OFFSET(tp)(sp) + REG_S s0, SBI_TRAP_REGS_OFFSET(s0)(sp) + REG_S s1, SBI_TRAP_REGS_OFFSET(s1)(sp) + REG_S a0, SBI_TRAP_REGS_OFFSET(a0)(sp) + REG_S a1, SBI_TRAP_REGS_OFFSET(a1)(sp) + REG_S a2, SBI_TRAP_REGS_OFFSET(a2)(sp) + REG_S a3, SBI_TRAP_REGS_OFFSET(a3)(sp) + REG_S a4, SBI_TRAP_REGS_OFFSET(a4)(sp) + REG_S a5, SBI_TRAP_REGS_OFFSET(a5)(sp) + REG_S a6, SBI_TRAP_REGS_OFFSET(a6)(sp) + REG_S a7, SBI_TRAP_REGS_OFFSET(a7)(sp) + REG_S s2, SBI_TRAP_REGS_OFFSET(s2)(sp) + REG_S s3, SBI_TRAP_REGS_OFFSET(s3)(sp) + REG_S s4, SBI_TRAP_REGS_OFFSET(s4)(sp) + REG_S s5, SBI_TRAP_REGS_OFFSET(s5)(sp) + REG_S s6, SBI_TRAP_REGS_OFFSET(s6)(sp) + REG_S s7, SBI_TRAP_REGS_OFFSET(s7)(sp) + REG_S s8, SBI_TRAP_REGS_OFFSET(s8)(sp) + REG_S s9, SBI_TRAP_REGS_OFFSET(s9)(sp) + REG_S s10, SBI_TRAP_REGS_OFFSET(s10)(sp) + REG_S s11, SBI_TRAP_REGS_OFFSET(s11)(sp) + REG_S t3, SBI_TRAP_REGS_OFFSET(t3)(sp) + REG_S t4, SBI_TRAP_REGS_OFFSET(t4)(sp) + REG_S t5, SBI_TRAP_REGS_OFFSET(t5)(sp) + REG_S t6, SBI_TRAP_REGS_OFFSET(t6)(sp) /* Call C routine */ add a0, sp, zero @@ -299,36 +300,36 @@ _trap_handler: call sbi_trap_handler /* Restore all general regisers except SP, RA, T0, T1, T2, and T3 */ - REG_L gp, RISCV_TRAP_REGS_OFFSET(gp)(sp) - REG_L tp, RISCV_TRAP_REGS_OFFSET(tp)(sp) - REG_L s0, RISCV_TRAP_REGS_OFFSET(s0)(sp) - REG_L s1, RISCV_TRAP_REGS_OFFSET(s1)(sp) - REG_L a0, RISCV_TRAP_REGS_OFFSET(a0)(sp) - REG_L a1, RISCV_TRAP_REGS_OFFSET(a1)(sp) - REG_L a2, RISCV_TRAP_REGS_OFFSET(a2)(sp) - REG_L a3, RISCV_TRAP_REGS_OFFSET(a3)(sp) - REG_L a4, RISCV_TRAP_REGS_OFFSET(a4)(sp) - REG_L a5, RISCV_TRAP_REGS_OFFSET(a5)(sp) - REG_L a6, RISCV_TRAP_REGS_OFFSET(a6)(sp) - REG_L a7, RISCV_TRAP_REGS_OFFSET(a7)(sp) - REG_L s2, RISCV_TRAP_REGS_OFFSET(s2)(sp) - REG_L s3, RISCV_TRAP_REGS_OFFSET(s3)(sp) - REG_L s4, RISCV_TRAP_REGS_OFFSET(s4)(sp) - REG_L s5, RISCV_TRAP_REGS_OFFSET(s5)(sp) - REG_L s6, RISCV_TRAP_REGS_OFFSET(s6)(sp) - REG_L s7, RISCV_TRAP_REGS_OFFSET(s7)(sp) - REG_L s8, RISCV_TRAP_REGS_OFFSET(s8)(sp) - REG_L s9, RISCV_TRAP_REGS_OFFSET(s9)(sp) - REG_L s10, RISCV_TRAP_REGS_OFFSET(s10)(sp) - REG_L s11, RISCV_TRAP_REGS_OFFSET(s11)(sp) - REG_L t3, RISCV_TRAP_REGS_OFFSET(t3)(sp) - REG_L t4, RISCV_TRAP_REGS_OFFSET(t4)(sp) - REG_L t5, RISCV_TRAP_REGS_OFFSET(t5)(sp) - REG_L t6, RISCV_TRAP_REGS_OFFSET(t6)(sp) + REG_L gp, SBI_TRAP_REGS_OFFSET(gp)(sp) + REG_L tp, SBI_TRAP_REGS_OFFSET(tp)(sp) + REG_L s0, SBI_TRAP_REGS_OFFSET(s0)(sp) + REG_L s1, SBI_TRAP_REGS_OFFSET(s1)(sp) + REG_L a0, SBI_TRAP_REGS_OFFSET(a0)(sp) + REG_L a1, SBI_TRAP_REGS_OFFSET(a1)(sp) + REG_L a2, SBI_TRAP_REGS_OFFSET(a2)(sp) + REG_L a3, SBI_TRAP_REGS_OFFSET(a3)(sp) + REG_L a4, SBI_TRAP_REGS_OFFSET(a4)(sp) + REG_L a5, SBI_TRAP_REGS_OFFSET(a5)(sp) + REG_L a6, SBI_TRAP_REGS_OFFSET(a6)(sp) + REG_L a7, SBI_TRAP_REGS_OFFSET(a7)(sp) + REG_L s2, SBI_TRAP_REGS_OFFSET(s2)(sp) + REG_L s3, SBI_TRAP_REGS_OFFSET(s3)(sp) + REG_L s4, SBI_TRAP_REGS_OFFSET(s4)(sp) + REG_L s5, SBI_TRAP_REGS_OFFSET(s5)(sp) + REG_L s6, SBI_TRAP_REGS_OFFSET(s6)(sp) + REG_L s7, SBI_TRAP_REGS_OFFSET(s7)(sp) + REG_L s8, SBI_TRAP_REGS_OFFSET(s8)(sp) + REG_L s9, SBI_TRAP_REGS_OFFSET(s9)(sp) + REG_L s10, SBI_TRAP_REGS_OFFSET(s10)(sp) + REG_L s11, SBI_TRAP_REGS_OFFSET(s11)(sp) + REG_L t3, SBI_TRAP_REGS_OFFSET(t3)(sp) + REG_L t4, SBI_TRAP_REGS_OFFSET(t4)(sp) + REG_L t5, SBI_TRAP_REGS_OFFSET(t5)(sp) + REG_L t6, SBI_TRAP_REGS_OFFSET(t6)(sp) /* Load T0 and T1 with MEPC and MSTATUS */ - REG_L t0, RISCV_TRAP_REGS_OFFSET(mepc)(sp) - REG_L t1, RISCV_TRAP_REGS_OFFSET(mstatus)(sp) + REG_L t0, SBI_TRAP_REGS_OFFSET(mepc)(sp) + REG_L t1, SBI_TRAP_REGS_OFFSET(mstatus)(sp) /* * Note: Jump here after fast trap handling @@ -342,12 +343,12 @@ _trap_handler: csrw mstatus, t1 /* Restore RA, T0, T1, and T2 */ - REG_L ra, RISCV_TRAP_REGS_OFFSET(ra)(sp) - REG_L t0, RISCV_TRAP_REGS_OFFSET(t0)(sp) - REG_L t1, RISCV_TRAP_REGS_OFFSET(t1)(sp) - REG_L t2, RISCV_TRAP_REGS_OFFSET(t2)(sp) + REG_L ra, SBI_TRAP_REGS_OFFSET(ra)(sp) + REG_L t0, SBI_TRAP_REGS_OFFSET(t0)(sp) + REG_L t1, SBI_TRAP_REGS_OFFSET(t1)(sp) + REG_L t2, SBI_TRAP_REGS_OFFSET(t2)(sp) /* Restore SP */ - REG_L sp, RISCV_TRAP_REGS_OFFSET(sp)(sp) + REG_L sp, SBI_TRAP_REGS_OFFSET(sp)(sp) mret diff --git a/include/sbi/riscv_asm.h b/include/sbi/riscv_asm.h index 6fd7d5d75c4..6e1bff75fbc 100644 --- a/include/sbi/riscv_asm.h +++ b/include/sbi/riscv_asm.h @@ -69,46 +69,6 @@ #error "Unexpected __SIZEOF_SHORT__" #endif -#define RISCV_TRAP_REGS_zero 0 -#define RISCV_TRAP_REGS_ra 1 -#define RISCV_TRAP_REGS_sp 2 -#define RISCV_TRAP_REGS_gp 3 -#define RISCV_TRAP_REGS_tp 4 -#define RISCV_TRAP_REGS_t0 5 -#define RISCV_TRAP_REGS_t1 6 -#define RISCV_TRAP_REGS_t2 7 -#define RISCV_TRAP_REGS_s0 8 -#define RISCV_TRAP_REGS_s1 9 -#define RISCV_TRAP_REGS_a0 10 -#define RISCV_TRAP_REGS_a1 11 -#define RISCV_TRAP_REGS_a2 12 -#define RISCV_TRAP_REGS_a3 13 -#define RISCV_TRAP_REGS_a4 14 -#define RISCV_TRAP_REGS_a5 15 -#define RISCV_TRAP_REGS_a6 16 -#define RISCV_TRAP_REGS_a7 17 -#define RISCV_TRAP_REGS_s2 18 -#define RISCV_TRAP_REGS_s3 19 -#define RISCV_TRAP_REGS_s4 20 -#define RISCV_TRAP_REGS_s5 21 -#define RISCV_TRAP_REGS_s6 22 -#define RISCV_TRAP_REGS_s7 23 -#define RISCV_TRAP_REGS_s8 24 -#define RISCV_TRAP_REGS_s9 25 -#define RISCV_TRAP_REGS_s10 26 -#define RISCV_TRAP_REGS_s11 27 -#define RISCV_TRAP_REGS_t3 28 -#define RISCV_TRAP_REGS_t4 29 -#define RISCV_TRAP_REGS_t5 30 -#define RISCV_TRAP_REGS_t6 31 -#define RISCV_TRAP_REGS_mepc 32 -#define RISCV_TRAP_REGS_mstatus 33 -#define RISCV_TRAP_REGS_last 34 - -#define RISCV_TRAP_REGS_OFFSET(x) \ - ((RISCV_TRAP_REGS_##x) * __SIZEOF_POINTER__) -#define RISCV_TRAP_REGS_SIZE RISCV_TRAP_REGS_OFFSET(last) - #ifndef __ASSEMBLY__ #define csr_swap(csr, val) \ diff --git a/include/sbi/sbi_trap.h b/include/sbi/sbi_trap.h index 4e5a054c0ef..67f7f38329c 100644 --- a/include/sbi/sbi_trap.h +++ b/include/sbi/sbi_trap.h @@ -10,6 +10,48 @@ #ifndef __SBI_TRAP_H__ #define __SBI_TRAP_H__ +#define SBI_TRAP_REGS_zero 0 +#define SBI_TRAP_REGS_ra 1 +#define SBI_TRAP_REGS_sp 2 +#define SBI_TRAP_REGS_gp 3 +#define SBI_TRAP_REGS_tp 4 +#define SBI_TRAP_REGS_t0 5 +#define SBI_TRAP_REGS_t1 6 +#define SBI_TRAP_REGS_t2 7 +#define SBI_TRAP_REGS_s0 8 +#define SBI_TRAP_REGS_s1 9 +#define SBI_TRAP_REGS_a0 10 +#define SBI_TRAP_REGS_a1 11 +#define SBI_TRAP_REGS_a2 12 +#define SBI_TRAP_REGS_a3 13 +#define SBI_TRAP_REGS_a4 14 +#define SBI_TRAP_REGS_a5 15 +#define SBI_TRAP_REGS_a6 16 +#define SBI_TRAP_REGS_a7 17 +#define SBI_TRAP_REGS_s2 18 +#define SBI_TRAP_REGS_s3 19 +#define SBI_TRAP_REGS_s4 20 +#define SBI_TRAP_REGS_s5 21 +#define SBI_TRAP_REGS_s6 22 +#define SBI_TRAP_REGS_s7 23 +#define SBI_TRAP_REGS_s8 24 +#define SBI_TRAP_REGS_s9 25 +#define SBI_TRAP_REGS_s10 26 +#define SBI_TRAP_REGS_s11 27 +#define SBI_TRAP_REGS_t3 28 +#define SBI_TRAP_REGS_t4 29 +#define SBI_TRAP_REGS_t5 30 +#define SBI_TRAP_REGS_t6 31 +#define SBI_TRAP_REGS_mepc 32 +#define SBI_TRAP_REGS_mstatus 33 +#define SBI_TRAP_REGS_last 34 + +#define SBI_TRAP_REGS_OFFSET(x) \ + ((SBI_TRAP_REGS_##x) * __SIZEOF_POINTER__) +#define SBI_TRAP_REGS_SIZE SBI_TRAP_REGS_OFFSET(last) + +#ifndef __ASSEMBLY__ + #include struct sbi_trap_regs { @@ -59,3 +101,5 @@ void sbi_trap_handler(struct sbi_trap_regs *regs, struct sbi_scratch *scratch); #endif + +#endif From 5797ae203555254c36fd21bc5aaa76a92ac4bd6c Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Wed, 2 Jan 2019 14:51:30 +0530 Subject: [PATCH 0064/1765] include: Remove redundant tmp0 from struct sbi_scratch The tmp0 member was added in struct sbi_scratch to assist register save/restore at time of trap handling. This tmp0 is not unsed any more hence removing it. Signed-off-by: Anup Patel --- firmware/fw_base.S | 1 - include/sbi/sbi_scratch.h | 20 +++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index ab67a705271..ad6371bbb1e 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -154,7 +154,6 @@ _start_warm: csrw mscratch, tp /* Initialize scratch space */ - REG_S zero, SBI_SCRATCH_TMP0_OFFSET(tp) la a4, _fw_start la a5, _fw_end mul t0, s7, s8 diff --git a/include/sbi/sbi_scratch.h b/include/sbi/sbi_scratch.h index 14c72a853dc..25b00c32af3 100644 --- a/include/sbi/sbi_scratch.h +++ b/include/sbi/sbi_scratch.h @@ -12,16 +12,15 @@ #include -#define SBI_SCRATCH_TMP0_OFFSET (0 * __SIZEOF_POINTER__) -#define SBI_SCRATCH_FW_START_OFFSET (1 * __SIZEOF_POINTER__) -#define SBI_SCRATCH_FW_SIZE_OFFSET (2 * __SIZEOF_POINTER__) -#define SBI_SCRATCH_NEXT_ARG1_OFFSET (3 * __SIZEOF_POINTER__) -#define SBI_SCRATCH_NEXT_ADDR_OFFSET (4 * __SIZEOF_POINTER__) -#define SBI_SCRATCH_NEXT_MODE_OFFSET (5 * __SIZEOF_POINTER__) -#define SBI_SCRATCH_WARMBOOT_ADDR_OFFSET (6 * __SIZEOF_POINTER__) -#define SBI_SCRATCH_PLATFORM_ADDR_OFFSET (7 * __SIZEOF_POINTER__) -#define SBI_SCRATCH_HARTID_TO_SCRATCH_OFFSET (8 * __SIZEOF_POINTER__) -#define SBI_SCRATCH_IPI_TYPE_OFFSET (9 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_FW_START_OFFSET (0 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_FW_SIZE_OFFSET (1 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_NEXT_ARG1_OFFSET (2 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_NEXT_ADDR_OFFSET (3 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_NEXT_MODE_OFFSET (4 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_WARMBOOT_ADDR_OFFSET (5 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_PLATFORM_ADDR_OFFSET (6 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_HARTID_TO_SCRATCH_OFFSET (7 * __SIZEOF_POINTER__) +#define SBI_SCRATCH_IPI_TYPE_OFFSET (8 * __SIZEOF_POINTER__) #define SBI_SCRATCH_SIZE 256 #ifndef __ASSEMBLY__ @@ -29,7 +28,6 @@ #include struct sbi_scratch { - unsigned long tmp0; unsigned long fw_start; unsigned long fw_size; unsigned long next_arg1; From da86853a51e3cdddc12cff8c29116c2e87da525c Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Mon, 31 Dec 2018 13:00:39 +0900 Subject: [PATCH 0065/1765] Makefile: Fix messages Instead of printing the generic "" and "" strings, print the actual paths for the build and install directories during "make clean" and "make distclean". Signed-off-by: Damien Le Moal --- Makefile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 346456548b1..0a8accffdaa 100644 --- a/Makefile +++ b/Makefile @@ -285,26 +285,26 @@ install_firmwares: $(build_dir)/$(platform_subdir)/lib/libplatsbi.a $(build_dir) .PHONY: clean clean: $(V)mkdir -p $(build_dir) - $(if $(V), @echo " RM /*.o") + $(if $(V), @echo " RM $(build_dir)/*.o") $(V)find $(build_dir) -type f -name "*.o" -exec rm -rf {} + - $(if $(V), @echo " RM /*.a") + $(if $(V), @echo " RM $(build_dir)/*.a") $(V)find $(build_dir) -type f -name "*.a" -exec rm -rf {} + - $(if $(V), @echo " RM /*.elf") + $(if $(V), @echo " RM $(build_dir)/*.elf") $(V)find $(build_dir) -type f -name "*.elf" -exec rm -rf {} + - $(if $(V), @echo " RM /*.bin") + $(if $(V), @echo " RM $(build_dir)/*.bin") $(V)find $(build_dir) -type f -name "*.bin" -exec rm -rf {} + # Rule for "make distclean" .PHONY: distclean distclean: clean $(V)mkdir -p $(build_dir) - $(if $(V), @echo " RM /*.dep") + $(if $(V), @echo " RM $(build_dir)/*.dep") $(V)find $(build_dir) -type f -name "*.dep" -exec rm -rf {} + ifeq ($(build_dir),$(CURDIR)/build) - $(if $(V), @echo " RM ") + $(if $(V), @echo " RM $(build_dir)") $(V)rm -rf $(build_dir) endif ifeq ($(install_dir),$(CURDIR)/install) - $(if $(V), @echo " RM ") + $(if $(V), @echo " RM $(install_dir)") $(V)rm -rf $(install_dir) endif From 4079df63a7a081c649a350eafd92af51d99df448 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Thu, 3 Jan 2019 13:34:32 +0900 Subject: [PATCH 0066/1765] platform: kendryte/k210: Declare local function static k210_console_putc() and k210_console_init() are local functions. Declare them as static. Signed-off-by: Damien Le Moal --- platform/kendryte/k210/platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c index 35119dbc317..fd0b31adff2 100644 --- a/platform/kendryte/k210/platform.c +++ b/platform/kendryte/k210/platform.c @@ -18,14 +18,14 @@ #define K210_UART_BAUDRATE 115200 -int k210_console_init(void) +static int k210_console_init(void) { uarths_init(K210_UART_BAUDRATE, UARTHS_STOP_1); return 0; } -void k210_console_putc(char c) +static void k210_console_putc(char c) { uarths_putc(c); } From c37a8508d14dae5b0d09c74b5de905bc585abbe3 Mon Sep 17 00:00:00 2001 From: Damien Le Moal Date: Thu, 3 Jan 2019 14:32:25 +0900 Subject: [PATCH 0067/1765] platform: kendryte/k210: Simplify sysctl code Simplify sysctl.c code to only the used CPU freqency function. This reduces the size of the final firmware by 4KB. Signed-off-by: Damien Le Moal --- platform/kendryte/k210/sysctl.c | 1766 +------------------------------ platform/kendryte/k210/sysctl.h | 161 +-- platform/kendryte/k210/uarths.c | 2 +- 3 files changed, 20 insertions(+), 1909 deletions(-) diff --git a/platform/kendryte/k210/sysctl.c b/platform/kendryte/k210/sysctl.c index 90aa0e2355e..5977e33086b 100644 --- a/platform/kendryte/k210/sysctl.c +++ b/platform/kendryte/k210/sysctl.c @@ -15,959 +15,18 @@ #include #include "sysctl.h" -#define SYSCTRL_CLOCK_FREQ_IN0 (26000000UL) - -const u8 get_select_pll2[] = { - [SYSCTL_SOURCE_IN0] = 0, - [SYSCTL_SOURCE_PLL0] = 1, - [SYSCTL_SOURCE_PLL1] = 2, -}; - -const u8 get_source_pll2[] = { - [0] = SYSCTL_SOURCE_IN0, - [1] = SYSCTL_SOURCE_PLL0, - [2] = SYSCTL_SOURCE_PLL1, -}; - -const u8 get_select_aclk[] = { - [SYSCTL_SOURCE_IN0] = 0, - [SYSCTL_SOURCE_PLL0] = 1, -}; - -const u8 get_source_aclk[] = { - [0] = SYSCTL_SOURCE_IN0, - [1] = SYSCTL_SOURCE_PLL0, -}; - volatile sysctl_t *const sysctl = (volatile sysctl_t *)SYSCTL_BASE_ADDR; -u32 sysctl_get_git_id(void) -{ - return sysctl->git_id.git_id; -} - -u32 sysctl_get_freq(void) -{ - return sysctl->clk_freq.clk_freq; -} - -static void sysctl_reset_ctl(sysctl_reset_t reset, u8 rst_value) -{ - switch (reset) { - case SYSCTL_RESET_SOC: - sysctl->soft_reset.soft_reset = rst_value; - break; - case SYSCTL_RESET_ROM: - sysctl->peri_reset.rom_reset = rst_value; - break; - case SYSCTL_RESET_DMA: - sysctl->peri_reset.dma_reset = rst_value; - break; - case SYSCTL_RESET_AI: - sysctl->peri_reset.ai_reset = rst_value; - break; - case SYSCTL_RESET_DVP: - sysctl->peri_reset.dvp_reset = rst_value; - break; - case SYSCTL_RESET_FFT: - sysctl->peri_reset.fft_reset = rst_value; - break; - case SYSCTL_RESET_GPIO: - sysctl->peri_reset.gpio_reset = rst_value; - break; - case SYSCTL_RESET_SPI0: - sysctl->peri_reset.spi0_reset = rst_value; - break; - case SYSCTL_RESET_SPI1: - sysctl->peri_reset.spi1_reset = rst_value; - break; - case SYSCTL_RESET_SPI2: - sysctl->peri_reset.spi2_reset = rst_value; - break; - case SYSCTL_RESET_SPI3: - sysctl->peri_reset.spi3_reset = rst_value; - break; - case SYSCTL_RESET_I2S0: - sysctl->peri_reset.i2s0_reset = rst_value; - break; - case SYSCTL_RESET_I2S1: - sysctl->peri_reset.i2s1_reset = rst_value; - break; - case SYSCTL_RESET_I2S2: - sysctl->peri_reset.i2s2_reset = rst_value; - break; - case SYSCTL_RESET_I2C0: - sysctl->peri_reset.i2c0_reset = rst_value; - break; - case SYSCTL_RESET_I2C1: - sysctl->peri_reset.i2c1_reset = rst_value; - break; - case SYSCTL_RESET_I2C2: - sysctl->peri_reset.i2c2_reset = rst_value; - break; - case SYSCTL_RESET_UART1: - sysctl->peri_reset.uart1_reset = rst_value; - break; - case SYSCTL_RESET_UART2: - sysctl->peri_reset.uart2_reset = rst_value; - break; - case SYSCTL_RESET_UART3: - sysctl->peri_reset.uart3_reset = rst_value; - break; - case SYSCTL_RESET_AES: - sysctl->peri_reset.aes_reset = rst_value; - break; - case SYSCTL_RESET_FPIOA: - sysctl->peri_reset.fpioa_reset = rst_value; - break; - case SYSCTL_RESET_TIMER0: - sysctl->peri_reset.timer0_reset = rst_value; - break; - case SYSCTL_RESET_TIMER1: - sysctl->peri_reset.timer1_reset = rst_value; - break; - case SYSCTL_RESET_TIMER2: - sysctl->peri_reset.timer2_reset = rst_value; - break; - case SYSCTL_RESET_WDT0: - sysctl->peri_reset.wdt0_reset = rst_value; - break; - case SYSCTL_RESET_WDT1: - sysctl->peri_reset.wdt1_reset = rst_value; - break; - case SYSCTL_RESET_SHA: - sysctl->peri_reset.sha_reset = rst_value; - break; - case SYSCTL_RESET_RTC: - sysctl->peri_reset.rtc_reset = rst_value; - break; - - default: - break; - } -} - -void sysctl_reset(sysctl_reset_t reset) -{ - sysctl_reset_ctl(reset, 1); - sysctl_reset_ctl(reset, 0); -} - -static int sysctl_clock_bus_en(sysctl_clock_t clock, u8 en) -{ - /* - * The timer is under APB0, to prevent apb0_clk_en1 and apb0_clk_en0 - * on same register, we split it to peripheral and central two - * registers, to protect CPU close apb0 clock accidentally. - * - * The apb0_clk_en0 and apb0_clk_en1 have same function, - * one of them set, the APB0 clock enable. - */ - - /* The APB clock should carefully disable */ - if (en) { - switch (clock) { - /* - * These peripheral devices are under APB0 - * GPIO, UART1, UART2, UART3, SPI_SLAVE, I2S0, I2S1, - * I2S2, I2C0, I2C1, I2C2, FPIOA, SHA256, TIMER0, - * TIMER1, TIMER2 - */ - case SYSCTL_CLOCK_GPIO: - case SYSCTL_CLOCK_SPI2: - case SYSCTL_CLOCK_I2S0: - case SYSCTL_CLOCK_I2S1: - case SYSCTL_CLOCK_I2S2: - case SYSCTL_CLOCK_I2C0: - case SYSCTL_CLOCK_I2C1: - case SYSCTL_CLOCK_I2C2: - case SYSCTL_CLOCK_UART1: - case SYSCTL_CLOCK_UART2: - case SYSCTL_CLOCK_UART3: - case SYSCTL_CLOCK_FPIOA: - case SYSCTL_CLOCK_TIMER0: - case SYSCTL_CLOCK_TIMER1: - case SYSCTL_CLOCK_TIMER2: - case SYSCTL_CLOCK_SHA: - sysctl->clk_en_cent.apb0_clk_en = en; - break; - - /* - * These peripheral devices are under APB1 - * WDT, AES, OTP, DVP, SYSCTL - */ - case SYSCTL_CLOCK_AES: - case SYSCTL_CLOCK_WDT0: - case SYSCTL_CLOCK_WDT1: - case SYSCTL_CLOCK_OTP: - case SYSCTL_CLOCK_RTC: - sysctl->clk_en_cent.apb1_clk_en = en; - break; - - /* - * These peripheral devices are under APB2 - * SPI0, SPI1 - */ - case SYSCTL_CLOCK_SPI0: - case SYSCTL_CLOCK_SPI1: - sysctl->clk_en_cent.apb2_clk_en = en; - break; - - default: - break; - } - } - - return 0; -} - -static int sysctl_clock_device_en(sysctl_clock_t clock, u8 en) -{ - switch (clock) { - /* - * These devices are PLL - */ - case SYSCTL_CLOCK_PLL0: - sysctl->pll0.pll_out_en0 = en; - break; - case SYSCTL_CLOCK_PLL1: - sysctl->pll1.pll_out_en1 = en; - break; - case SYSCTL_CLOCK_PLL2: - sysctl->pll2.pll_out_en2 = en; - break; - - /* - * These devices are CPU, SRAM, APB bus, ROM, DMA, AI - */ - case SYSCTL_CLOCK_CPU: - sysctl->clk_en_cent.cpu_clk_en = en; - break; - case SYSCTL_CLOCK_SRAM0: - sysctl->clk_en_cent.sram0_clk_en = en; - break; - case SYSCTL_CLOCK_SRAM1: - sysctl->clk_en_cent.sram1_clk_en = en; - break; - case SYSCTL_CLOCK_APB0: - sysctl->clk_en_cent.apb0_clk_en = en; - break; - case SYSCTL_CLOCK_APB1: - sysctl->clk_en_cent.apb1_clk_en = en; - break; - case SYSCTL_CLOCK_APB2: - sysctl->clk_en_cent.apb2_clk_en = en; - break; - case SYSCTL_CLOCK_ROM: - sysctl->clk_en_peri.rom_clk_en = en; - break; - case SYSCTL_CLOCK_DMA: - sysctl->clk_en_peri.dma_clk_en = en; - break; - case SYSCTL_CLOCK_AI: - sysctl->clk_en_peri.ai_clk_en = en; - break; - case SYSCTL_CLOCK_DVP: - sysctl->clk_en_peri.dvp_clk_en = en; - break; - case SYSCTL_CLOCK_FFT: - sysctl->clk_en_peri.fft_clk_en = en; - break; - case SYSCTL_CLOCK_SPI3: - sysctl->clk_en_peri.spi3_clk_en = en; - break; - - /* - * These peripheral devices are under APB0 - * GPIO, UART1, UART2, UART3, SPI_SLAVE, I2S0, I2S1, - * I2S2, I2C0, I2C1, I2C2, FPIOA, SHA256, TIMER0, - * TIMER1, TIMER2 - */ - case SYSCTL_CLOCK_GPIO: - sysctl->clk_en_peri.gpio_clk_en = en; - break; - case SYSCTL_CLOCK_SPI2: - sysctl->clk_en_peri.spi2_clk_en = en; - break; - case SYSCTL_CLOCK_I2S0: - sysctl->clk_en_peri.i2s0_clk_en = en; - break; - case SYSCTL_CLOCK_I2S1: - sysctl->clk_en_peri.i2s1_clk_en = en; - break; - case SYSCTL_CLOCK_I2S2: - sysctl->clk_en_peri.i2s2_clk_en = en; - break; - case SYSCTL_CLOCK_I2C0: - sysctl->clk_en_peri.i2c0_clk_en = en; - break; - case SYSCTL_CLOCK_I2C1: - sysctl->clk_en_peri.i2c1_clk_en = en; - break; - case SYSCTL_CLOCK_I2C2: - sysctl->clk_en_peri.i2c2_clk_en = en; - break; - case SYSCTL_CLOCK_UART1: - sysctl->clk_en_peri.uart1_clk_en = en; - break; - case SYSCTL_CLOCK_UART2: - sysctl->clk_en_peri.uart2_clk_en = en; - break; - case SYSCTL_CLOCK_UART3: - sysctl->clk_en_peri.uart3_clk_en = en; - break; - case SYSCTL_CLOCK_FPIOA: - sysctl->clk_en_peri.fpioa_clk_en = en; - break; - case SYSCTL_CLOCK_TIMER0: - sysctl->clk_en_peri.timer0_clk_en = en; - break; - case SYSCTL_CLOCK_TIMER1: - sysctl->clk_en_peri.timer1_clk_en = en; - break; - case SYSCTL_CLOCK_TIMER2: - sysctl->clk_en_peri.timer2_clk_en = en; - break; - case SYSCTL_CLOCK_SHA: - sysctl->clk_en_peri.sha_clk_en = en; - break; - - /* - * These peripheral devices are under APB1 - * WDT, AES, OTP, DVP, SYSCTL - */ - case SYSCTL_CLOCK_AES: - sysctl->clk_en_peri.aes_clk_en = en; - break; - case SYSCTL_CLOCK_WDT0: - sysctl->clk_en_peri.wdt0_clk_en = en; - break; - case SYSCTL_CLOCK_WDT1: - sysctl->clk_en_peri.wdt1_clk_en = en; - break; - case SYSCTL_CLOCK_OTP: - sysctl->clk_en_peri.otp_clk_en = en; - break; - case SYSCTL_CLOCK_RTC: - sysctl->clk_en_peri.rtc_clk_en = en; - break; - - /* - * These peripheral devices are under APB2 - * SPI0, SPI1 - */ - case SYSCTL_CLOCK_SPI0: - sysctl->clk_en_peri.spi0_clk_en = en; - break; - case SYSCTL_CLOCK_SPI1: - sysctl->clk_en_peri.spi1_clk_en = en; - break; - - default: - break; - } - - return 0; -} - -int sysctl_clock_enable(sysctl_clock_t clock) -{ - if (clock >= SYSCTL_CLOCK_MAX) - return -1; - - sysctl_clock_bus_en(clock, 1); - sysctl_clock_device_en(clock, 1); - - return 0; -} - -int sysctl_clock_disable(sysctl_clock_t clock) -{ - if (clock >= SYSCTL_CLOCK_MAX) - return -1; - - sysctl_clock_bus_en(clock, 0); - sysctl_clock_device_en(clock, 0); - - return 0; -} - -int sysctl_clock_set_threshold(sysctl_threshold_t which, int threshold) -{ - int result = 0; - - switch (which) { - /* - * These threshold is 2 bit width - */ - case SYSCTL_THRESHOLD_ACLK: - sysctl->clk_sel0.aclk_divider_sel = (u8)threshold & 0x03; - break; - - /* - * These threshold is 3 bit width - */ - case SYSCTL_THRESHOLD_APB0: - sysctl->clk_sel0.apb0_clk_sel = (u8)threshold & 0x07; - break; - case SYSCTL_THRESHOLD_APB1: - sysctl->clk_sel0.apb1_clk_sel = (u8)threshold & 0x07; - break; - case SYSCTL_THRESHOLD_APB2: - sysctl->clk_sel0.apb2_clk_sel = (u8)threshold & 0x07; - break; - - /* - * These threshold is 4 bit width - */ - case SYSCTL_THRESHOLD_SRAM0: - sysctl->clk_th0.sram0_gclk_threshold = (u8)threshold & 0x0F; - break; - case SYSCTL_THRESHOLD_SRAM1: - sysctl->clk_th0.sram1_gclk_threshold = (u8)threshold & 0x0F; - break; - case SYSCTL_THRESHOLD_AI: - sysctl->clk_th0.ai_gclk_threshold = (u8)threshold & 0x0F; - break; - case SYSCTL_THRESHOLD_DVP: - sysctl->clk_th0.dvp_gclk_threshold = (u8)threshold & 0x0F; - break; - case SYSCTL_THRESHOLD_ROM: - sysctl->clk_th0.rom_gclk_threshold = (u8)threshold & 0x0F; - break; - - /* - * These threshold is 8 bit width - */ - case SYSCTL_THRESHOLD_SPI0: - sysctl->clk_th1.spi0_clk_threshold = (u8)threshold; - break; - case SYSCTL_THRESHOLD_SPI1: - sysctl->clk_th1.spi1_clk_threshold = (u8)threshold; - break; - case SYSCTL_THRESHOLD_SPI2: - sysctl->clk_th1.spi2_clk_threshold = (u8)threshold; - break; - case SYSCTL_THRESHOLD_SPI3: - sysctl->clk_th1.spi3_clk_threshold = (u8)threshold; - break; - case SYSCTL_THRESHOLD_TIMER0: - sysctl->clk_th2.timer0_clk_threshold = (u8)threshold; - break; - case SYSCTL_THRESHOLD_TIMER1: - sysctl->clk_th2.timer1_clk_threshold = (u8)threshold; - break; - case SYSCTL_THRESHOLD_TIMER2: - sysctl->clk_th2.timer2_clk_threshold = (u8)threshold; - break; - case SYSCTL_THRESHOLD_I2S0_M: - sysctl->clk_th4.i2s0_mclk_threshold = (u8)threshold; - break; - case SYSCTL_THRESHOLD_I2S1_M: - sysctl->clk_th4.i2s1_mclk_threshold = (u8)threshold; - break; - case SYSCTL_THRESHOLD_I2S2_M: - sysctl->clk_th5.i2s2_mclk_threshold = (u8)threshold; - break; - case SYSCTL_THRESHOLD_I2C0: - sysctl->clk_th5.i2c0_clk_threshold = (u8)threshold; - break; - case SYSCTL_THRESHOLD_I2C1: - sysctl->clk_th5.i2c1_clk_threshold = (u8)threshold; - break; - case SYSCTL_THRESHOLD_I2C2: - sysctl->clk_th5.i2c2_clk_threshold = (u8)threshold; - break; - case SYSCTL_THRESHOLD_WDT0: - sysctl->clk_th6.wdt0_clk_threshold = (u8)threshold; - break; - case SYSCTL_THRESHOLD_WDT1: - sysctl->clk_th6.wdt1_clk_threshold = (u8)threshold; - break; - - /* - * These threshold is 16 bit width - */ - case SYSCTL_THRESHOLD_I2S0: - sysctl->clk_th3.i2s0_clk_threshold = (u16)threshold; - break; - case SYSCTL_THRESHOLD_I2S1: - sysctl->clk_th3.i2s1_clk_threshold = (u16)threshold; - break; - case SYSCTL_THRESHOLD_I2S2: - sysctl->clk_th4.i2s2_clk_threshold = (u16)threshold; - break; - - default: - result = -1; - break; - } - - return result; -} - -int sysctl_clock_get_threshold(sysctl_threshold_t which) -{ - int threshold = 0; - - switch (which) { - /* - * Select and get threshold value - */ - case SYSCTL_THRESHOLD_ACLK: - threshold = (int)sysctl->clk_sel0.aclk_divider_sel; - break; - case SYSCTL_THRESHOLD_APB0: - threshold = (int)sysctl->clk_sel0.apb0_clk_sel; - break; - case SYSCTL_THRESHOLD_APB1: - threshold = (int)sysctl->clk_sel0.apb1_clk_sel; - break; - case SYSCTL_THRESHOLD_APB2: - threshold = (int)sysctl->clk_sel0.apb2_clk_sel; - break; - case SYSCTL_THRESHOLD_SRAM0: - threshold = (int)sysctl->clk_th0.sram0_gclk_threshold; - break; - case SYSCTL_THRESHOLD_SRAM1: - threshold = (int)sysctl->clk_th0.sram1_gclk_threshold; - break; - case SYSCTL_THRESHOLD_AI: - threshold = (int)sysctl->clk_th0.ai_gclk_threshold; - break; - case SYSCTL_THRESHOLD_DVP: - threshold = (int)sysctl->clk_th0.dvp_gclk_threshold; - break; - case SYSCTL_THRESHOLD_ROM: - threshold = (int)sysctl->clk_th0.rom_gclk_threshold; - break; - case SYSCTL_THRESHOLD_SPI0: - threshold = (int)sysctl->clk_th1.spi0_clk_threshold; - break; - case SYSCTL_THRESHOLD_SPI1: - threshold = (int)sysctl->clk_th1.spi1_clk_threshold; - break; - case SYSCTL_THRESHOLD_SPI2: - threshold = (int)sysctl->clk_th1.spi2_clk_threshold; - break; - case SYSCTL_THRESHOLD_SPI3: - threshold = (int)sysctl->clk_th1.spi3_clk_threshold; - break; - case SYSCTL_THRESHOLD_TIMER0: - threshold = (int)sysctl->clk_th2.timer0_clk_threshold; - break; - case SYSCTL_THRESHOLD_TIMER1: - threshold = (int)sysctl->clk_th2.timer1_clk_threshold; - break; - case SYSCTL_THRESHOLD_TIMER2: - threshold = (int)sysctl->clk_th2.timer2_clk_threshold; - break; - case SYSCTL_THRESHOLD_I2S0: - threshold = (int)sysctl->clk_th3.i2s0_clk_threshold; - break; - case SYSCTL_THRESHOLD_I2S1: - threshold = (int)sysctl->clk_th3.i2s1_clk_threshold; - break; - case SYSCTL_THRESHOLD_I2S2: - threshold = (int)sysctl->clk_th4.i2s2_clk_threshold; - break; - case SYSCTL_THRESHOLD_I2S0_M: - threshold = (int)sysctl->clk_th4.i2s0_mclk_threshold; - break; - case SYSCTL_THRESHOLD_I2S1_M: - threshold = (int)sysctl->clk_th4.i2s1_mclk_threshold; - break; - case SYSCTL_THRESHOLD_I2S2_M: - threshold = (int)sysctl->clk_th5.i2s2_mclk_threshold; - break; - case SYSCTL_THRESHOLD_I2C0: - threshold = (int)sysctl->clk_th5.i2c0_clk_threshold; - break; - case SYSCTL_THRESHOLD_I2C1: - threshold = (int)sysctl->clk_th5.i2c1_clk_threshold; - break; - case SYSCTL_THRESHOLD_I2C2: - threshold = (int)sysctl->clk_th5.i2c2_clk_threshold; - break; - case SYSCTL_THRESHOLD_WDT0: - threshold = (int)sysctl->clk_th6.wdt0_clk_threshold; - break; - case SYSCTL_THRESHOLD_WDT1: - threshold = (int)sysctl->clk_th6.wdt1_clk_threshold; - break; - - default: - break; - } - - return threshold; -} - -int sysctl_clock_set_clock_select(sysctl_clock_select_t which, int select) -{ - int result = 0; - - switch (which) { - /* - * These clock select is 1 bit width - */ - case SYSCTL_CLOCK_SELECT_PLL0_BYPASS: - sysctl->pll0.pll_bypass0 = select & 0x01; - break; - case SYSCTL_CLOCK_SELECT_PLL1_BYPASS: - sysctl->pll1.pll_bypass1 = select & 0x01; - break; - case SYSCTL_CLOCK_SELECT_PLL2_BYPASS: - sysctl->pll2.pll_bypass2 = select & 0x01; - break; - case SYSCTL_CLOCK_SELECT_ACLK: - sysctl->clk_sel0.aclk_sel = select & 0x01; - break; - case SYSCTL_CLOCK_SELECT_SPI3: - sysctl->clk_sel0.spi3_clk_sel = select & 0x01; - break; - case SYSCTL_CLOCK_SELECT_TIMER0: - sysctl->clk_sel0.timer0_clk_sel = select & 0x01; - break; - case SYSCTL_CLOCK_SELECT_TIMER1: - sysctl->clk_sel0.timer1_clk_sel = select & 0x01; - break; - case SYSCTL_CLOCK_SELECT_TIMER2: - sysctl->clk_sel0.timer2_clk_sel = select & 0x01; - break; - case SYSCTL_CLOCK_SELECT_SPI3_SAMPLE: - sysctl->clk_sel1.spi3_sample_clk_sel = select & 0x01; - break; - - /* - * These clock select is 2 bit width - */ - case SYSCTL_CLOCK_SELECT_PLL2: - sysctl->pll2.pll_ckin_sel2 = select & 0x03; - break; - - default: - result = -1; - break; - } - - return result; -} - -int sysctl_clock_get_clock_select(sysctl_clock_select_t which) -{ - int clock_select = 0; - - switch (which) { - /* - * Select and get clock select value - */ - case SYSCTL_CLOCK_SELECT_PLL0_BYPASS: - clock_select = (int)sysctl->pll0.pll_bypass0; - break; - case SYSCTL_CLOCK_SELECT_PLL1_BYPASS: - clock_select = (int)sysctl->pll1.pll_bypass1; - break; - case SYSCTL_CLOCK_SELECT_PLL2_BYPASS: - clock_select = (int)sysctl->pll2.pll_bypass2; - break; - case SYSCTL_CLOCK_SELECT_PLL2: - clock_select = (int)sysctl->pll2.pll_ckin_sel2; - break; - case SYSCTL_CLOCK_SELECT_ACLK: - clock_select = (int)sysctl->clk_sel0.aclk_sel; - break; - case SYSCTL_CLOCK_SELECT_SPI3: - clock_select = (int)sysctl->clk_sel0.spi3_clk_sel; - break; - case SYSCTL_CLOCK_SELECT_TIMER0: - clock_select = (int)sysctl->clk_sel0.timer0_clk_sel; - break; - case SYSCTL_CLOCK_SELECT_TIMER1: - clock_select = (int)sysctl->clk_sel0.timer1_clk_sel; - break; - case SYSCTL_CLOCK_SELECT_TIMER2: - clock_select = (int)sysctl->clk_sel0.timer2_clk_sel; - break; - case SYSCTL_CLOCK_SELECT_SPI3_SAMPLE: - clock_select = (int)sysctl->clk_sel1.spi3_sample_clk_sel; - break; - - default: - break; - } - - return clock_select; -} - -u32 sysctl_clock_source_get_freq(sysctl_clock_source_t input) -{ - u32 result; - - switch (input) { - case SYSCTL_SOURCE_IN0: - result = SYSCTRL_CLOCK_FREQ_IN0; - break; - case SYSCTL_SOURCE_PLL0: - result = sysctl_pll_get_freq(SYSCTL_PLL0); - break; - case SYSCTL_SOURCE_PLL1: - result = sysctl_pll_get_freq(SYSCTL_PLL1); - break; - case SYSCTL_SOURCE_PLL2: - result = sysctl_pll_get_freq(SYSCTL_PLL2); - break; - case SYSCTL_SOURCE_ACLK: - result = sysctl_clock_get_freq(SYSCTL_CLOCK_ACLK); - break; - default: - result = 0; - break; - } - - return result; -} - -static int sysctl_pll_is_lock(sysctl_pll_t pll) -{ - /* - * All bit enable means PLL lock - * - * struct pll_lock_t - * { - * u8 overflow : 1; - * u8 rfslip : 1; - * u8 fbslip : 1; - * }; - * - */ - - if (pll >= SYSCTL_PLL_MAX) - return 0; - - switch (pll) { - case SYSCTL_PLL0: - return sysctl->pll_lock.pll_lock0 == 3; - - case SYSCTL_PLL1: - return sysctl->pll_lock.pll_lock1 & 1; - - case SYSCTL_PLL2: - return sysctl->pll_lock.pll_lock2 & 1; - - default: - break; - } - - return 0; -} - -static int sysctl_pll_clear_slip(sysctl_pll_t pll) -{ - if (pll >= SYSCTL_PLL_MAX) - return -1; - - switch (pll) { - case SYSCTL_PLL0: - sysctl->pll_lock.pll_slip_clear0 = 1; - break; - - case SYSCTL_PLL1: - sysctl->pll_lock.pll_slip_clear1 = 1; - break; - - case SYSCTL_PLL2: - sysctl->pll_lock.pll_slip_clear2 = 1; - break; - - default: - break; - } - - return sysctl_pll_is_lock(pll) ? 0 : -1; -} - -int sysctl_pll_enable(sysctl_pll_t pll) -{ - /* - * ---+ - * PWRDN | - * +------------------------------------------------------------- - * ^ - * | - * | - * t1 - * +------------------+ - * RESET | | - * ----------+ +----------------------------------- - * ^ ^ ^ - * |<----- t_rst ---->|<---------- t_lock ---------->| - * | | | - * t2 t3 t4 - */ - - if (pll >= SYSCTL_PLL_MAX) - return -1; - - switch (pll) { - case SYSCTL_PLL0: - /* Do not bypass PLL */ - sysctl->pll0.pll_bypass0 = 0; - /* - * Power on the PLL, negtive from PWRDN - * 0 is power off - * 1 is power on - */ - sysctl->pll0.pll_pwrd0 = 1; - /* - * Reset trigger of the PLL, connected RESET - * 0 is free - * 1 is reset - */ - sysctl->pll0.pll_reset0 = 0; - sysctl->pll0.pll_reset0 = 1; - asm volatile ("nop"); - asm volatile ("nop"); - sysctl->pll0.pll_reset0 = 0; - break; - - case SYSCTL_PLL1: - /* Do not bypass PLL */ - sysctl->pll1.pll_bypass1 = 0; - /* - * Power on the PLL, negtive from PWRDN - * 0 is power off - * 1 is power on - */ - sysctl->pll1.pll_pwrd1 = 1; - /* - * Reset trigger of the PLL, connected RESET - * 0 is free - * 1 is reset - */ - sysctl->pll1.pll_reset1 = 0; - sysctl->pll1.pll_reset1 = 1; - asm volatile ("nop"); - asm volatile ("nop"); - sysctl->pll1.pll_reset1 = 0; - break; - - case SYSCTL_PLL2: - /* Do not bypass PLL */ - sysctl->pll2.pll_bypass2 = 0; - /* - * Power on the PLL, negtive from PWRDN - * 0 is power off - * 1 is power on - */ - sysctl->pll2.pll_pwrd2 = 1; - /* - * Reset trigger of the PLL, connected RESET - * 0 is free - * 1 is reset - */ - sysctl->pll2.pll_reset2 = 0; - sysctl->pll2.pll_reset2 = 1; - asm volatile ("nop"); - asm volatile ("nop"); - sysctl->pll2.pll_reset2 = 0; - break; - - default: - break; - } - - return 0; -} - -int sysctl_pll_disable(sysctl_pll_t pll) -{ - if (pll >= SYSCTL_PLL_MAX) - return -1; - - switch (pll) { - case SYSCTL_PLL0: - /* Bypass PLL */ - sysctl->pll0.pll_bypass0 = 1; - /* - * Power on the PLL, negtive from PWRDN - * 0 is power off - * 1 is power on - */ - sysctl->pll0.pll_pwrd0 = 0; - break; - - case SYSCTL_PLL1: - /* Bypass PLL */ - sysctl->pll1.pll_bypass1 = 1; - /* - * Power on the PLL, negtive from PWRDN - * 0 is power off - * 1 is power on - */ - sysctl->pll1.pll_pwrd1 = 0; - break; - - case SYSCTL_PLL2: - /* Bypass PLL */ - sysctl->pll2.pll_bypass2 = 1; - /* - * Power on the PLL, negtive from PWRDN - * 0 is power off - * 1 is power on - */ - sysctl->pll2.pll_pwrd2 = 0; - break; - - default: - break; - } - - return 0; -} +#define SYSCTRL_CLOCK_FREQ_IN0 (26000000UL) -u32 sysctl_pll_get_freq(sysctl_pll_t pll) +static u32 sysctl_pll0_get_freq(void) { - u32 freq_in = 0; - u32 nr = 0, nf = 0, od = 0; - u8 select = 0; - - if (pll >= SYSCTL_PLL_MAX) - return 0; + u32 freq_in, nr, nf, od; - switch (pll) { - case SYSCTL_PLL0: - freq_in = sysctl_clock_source_get_freq(SYSCTL_SOURCE_IN0); - nr = sysctl->pll0.clkr0 + 1; - nf = sysctl->pll0.clkf0 + 1; - od = sysctl->pll0.clkod0 + 1; - break; - - case SYSCTL_PLL1: - freq_in = sysctl_clock_source_get_freq(SYSCTL_SOURCE_IN0); - nr = sysctl->pll1.clkr1 + 1; - nf = sysctl->pll1.clkf1 + 1; - od = sysctl->pll1.clkod1 + 1; - break; - - case SYSCTL_PLL2: - /* - * Get input freq accroding select register - */ - select = sysctl->pll2.pll_ckin_sel2; - if (select < sizeof(get_source_pll2)) - freq_in = sysctl_clock_source_get_freq(get_source_pll2[select]); - else - return 0; - - nr = sysctl->pll2.clkr2 + 1; - nf = sysctl->pll2.clkf2 + 1; - od = sysctl->pll2.clkod2 + 1; - break; - - default: - break; - } + freq_in = SYSCTRL_CLOCK_FREQ_IN0; + nr = sysctl->pll0.clkr0 + 1; + nf = sysctl->pll0.clkf0 + 1; + od = sysctl->pll0.clkod0 + 1; /* * Get final PLL output freq @@ -977,812 +36,19 @@ u32 sysctl_pll_get_freq(sysctl_pll_t pll) return ((u64)freq_in * (u64)nf) / ((u64)nr * (u64)od); } -#if 0 -static u32 sysctl_pll_source_set_freq(sysctl_pll_t pll, - sysctl_clock_source_t source, u32 freq) -{ - - const double vco_min = 3.5e+08; - const double vco_max = 1.75e+09; - const double ref_min = 1.36719e+07; - const double ref_max = 1.75e+09; - const int nr_min = 1; - const int nr_max = 16; - const int nf_min = 1; - const int nf_max = 64; - const int no_min = 1; - const int no_max = 16; - const int nb_min = 1; - const int nb_max = 64; - const int max_vco = 1; - const int ref_rng = 1; - int nr = 0; - int nrx = 0; - int nf = 0; - int nfi = 0; - int no = 0; - int noe = 0; - int not = 0; - int nor = 0; - int nore = 0; - int nb = 0; - int first = 0; - int firstx = 0; - int found = 0; - long long nfx = 0; - double fin = 0, fout = 0, fvco = 0; - double val = 0, nval = 0, err = 0, merr = 0, terr = 0; - int x_nrx = 0, x_no = 0, x_nb = 0; - long long x_nfx = 0; - double x_fvco = 0, x_err = 0; - sysctl_pll0_t pll0; - sysctl_pll1_t pll1; - sysctl_pll2_t pll2; - u32 freq_in = 0; - - if (pll >= SYSCTL_PLL_MAX) - return 0; - - if (source >= SYSCTL_SOURCE_MAX) - return 0; - - switch (pll) { - case SYSCTL_PLL0: - case SYSCTL_PLL1: - /* - * Check input clock source - */ - if (source != SYSCTL_SOURCE_IN0) - return 0; - freq_in = sysctl_clock_source_get_freq(SYSCTL_SOURCE_IN0); - /* - * Check input clock freq - */ - if (freq_in == 0) - return 0; - break; - - case SYSCTL_PLL2: - /* - * Check input clock source - */ - if (source < sizeof(get_select_pll2)) - freq_in = sysctl_clock_source_get_freq(source); - /* - * Check input clock freq - */ - if (freq_in == 0) - return 0; - break; - - default: - return 0; - } - - /* - * Begin calculate PLL registers' value - */ - fin = freq_in; - fout = freq; - val = fout / fin; - terr = 0.5 / ((double)(nf_max / 2)); - first = firstx = 1; - if (terr != -2) { - first = 0; - if (terr == 0) - terr = 1e-16; - merr = fabs(terr); - } - found = 0; - for (nfi = val; nfi < nf_max; ++nfi) { - nr = rint(((double)nfi) / val); - if (nr == 0) - continue; - if ((ref_rng) && (nr < nr_min)) - continue; - if (fin / ((double)nr) > ref_max) - continue; - nrx = nr; - nf = nfx = nfi; - nval = ((double)nfx) / ((double)nr); - if (nf == 0) - nf = 1; - err = 1 - nval / val; - - if ((first) || (fabs(err) < merr * (1 + 1e-6)) || (fabs(err) < 1e-16)) { - not = floor(vco_max / fout); - for (no = (not > no_max) ? no_max : not; no > no_min; --no) { - if ((ref_rng) && ((nr / no) < nr_min)) - continue; - if ((nr % no) == 0) - break; - } - if ((nr % no) != 0) - continue; - nor = ((not > no_max) ? no_max : not) / no; - nore = nf_max / nf; - if (nor > nore) - nor = nore; - noe = ceil(vco_min / fout); - if (!max_vco) { - nore = (noe - 1) / no + 1; - nor = nore; - not = 0; /* force next if to fail */ - } - if ((((no * nor) < (not >> 1)) || ((no * nor) < noe)) && ((no * nor) < (nf_max / nf))) { - no = nf_max / nf; - if (no > no_max) - no = no_max; - if (no > not) - no = not; - nfx *= no; - nf *= no; - if ((no > 1) && (!firstx)) - continue; - /* wait for larger nf in later iterations */ - } else { - nrx /= no; - nfx *= nor; - nf *= nor; - no *= nor; - if (no > no_max) - continue; - if ((nor > 1) && (!firstx)) - continue; - /* wait for larger nf in later iterations */ - } - - nb = nfx; - if (nb < nb_min) - nb = nb_min; - if (nb > nb_max) - continue; - - fvco = fin / ((double)nrx) * ((double)nfx); - if (fvco < vco_min) - continue; - if (fvco > vco_max) - continue; - if (nf < nf_min) - continue; - if ((ref_rng) && (fin / ((double)nrx) < ref_min)) - continue; - if ((ref_rng) && (nrx > nr_max)) - continue; - if (!(((firstx) && (terr < 0)) || (fabs(err) < merr * (1 - 1e-6)) || ((max_vco) && (no > x_no)))) - continue; - if ((!firstx) && (terr >= 0) && (nrx > x_nrx)) - continue; - - found = 1; - x_no = no; - x_nrx = nrx; - x_nfx = nfx; - x_nb = nb; - x_fvco = fvco; - x_err = err; - first = firstx = 0; - merr = fabs(err); - if (terr != -1) - continue; - } - } - - if (!found) - return 0; - - nrx = x_nrx; - nfx = x_nfx; - no = x_no; - nb = x_nb; - fvco = x_fvco; - err = x_err; - if ((terr != -2) && (fabs(err) >= terr * (1 - 1e-6))) - return 0; - - /* - * Begin write PLL registers' value, - * Using atomic write method. - */ - switch (pll) { - case SYSCTL_PLL0: - /* Read register from bus */ - pll0 = sysctl->pll0; - /* Set register temporary value */ - pll0.clkr0 = nrx - 1; - pll0.clkf0 = nfx - 1; - pll0.clkod0 = no - 1; - pll0.bwadj0 = nb - 1; - /* Write register back to bus */ - sysctl->pll0 = pll0; - break; - - case SYSCTL_PLL1: - /* Read register from bus */ - pll1 = sysctl->pll1; - /* Set register temporary value */ - pll1.clkr1 = nrx - 1; - pll1.clkf1 = nfx - 1; - pll1.clkod1 = no - 1; - pll1.bwadj1 = nb - 1; - /* Write register back to bus */ - sysctl->pll1 = pll1; - break; - - case SYSCTL_PLL2: - /* Read register from bus */ - pll2 = sysctl->pll2; - /* Set register temporary value */ - if (source < sizeof(get_select_pll2)) - pll2.pll_ckin_sel2 = get_select_pll2[source]; - - pll2.clkr2 = nrx - 1; - pll2.clkf2 = nfx - 1; - pll2.clkod2 = no - 1; - pll2.bwadj2 = nb - 1; - /* Write register back to bus */ - sysctl->pll2 = pll2; - break; - - default: - return 0; - } - - return sysctl_pll_get_freq(pll); -} -#endif - -u32 sysctl_clock_get_freq(sysctl_clock_t clock) -{ - u32 source = 0; - u32 result = 0; - - switch (clock) { - /* - * The clock IN0 - */ - case SYSCTL_CLOCK_IN0: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_IN0); - result = source; - break; - - /* - * These clock directly under PLL clock domain - * They are using gated divider. - */ - case SYSCTL_CLOCK_PLL0: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL0); - result = source; - break; - case SYSCTL_CLOCK_PLL1: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL1); - result = source; - break; - case SYSCTL_CLOCK_PLL2: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL2); - result = source; - break; - - /* - * These clock directly under ACLK clock domain - */ - case SYSCTL_CLOCK_CPU: - switch (sysctl_clock_get_clock_select(SYSCTL_CLOCK_SELECT_ACLK)) { - case 0: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_IN0); - break; - case 1: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL0) / - (2ULL << sysctl_clock_get_threshold(SYSCTL_THRESHOLD_ACLK)); - break; - default: - break; - } - result = source; - break; - case SYSCTL_CLOCK_DMA: - switch (sysctl_clock_get_clock_select(SYSCTL_CLOCK_SELECT_ACLK)) { - case 0: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_IN0); - break; - case 1: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL0) / - (2ULL << sysctl_clock_get_threshold(SYSCTL_THRESHOLD_ACLK)); - break; - default: - break; - } - result = source; - break; - case SYSCTL_CLOCK_FFT: - switch (sysctl_clock_get_clock_select(SYSCTL_CLOCK_SELECT_ACLK)) { - case 0: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_IN0); - break; - case 1: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL0) / - (2ULL << sysctl_clock_get_threshold(SYSCTL_THRESHOLD_ACLK)); - break; - default: - break; - } - result = source; - break; - case SYSCTL_CLOCK_ACLK: - switch (sysctl_clock_get_clock_select(SYSCTL_CLOCK_SELECT_ACLK)) { - case 0: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_IN0); - break; - case 1: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL0) / - (2ULL << sysctl_clock_get_threshold(SYSCTL_THRESHOLD_ACLK)); - break; - default: - break; - } - result = source; - break; - case SYSCTL_CLOCK_HCLK: - switch (sysctl_clock_get_clock_select(SYSCTL_CLOCK_SELECT_ACLK)) { - case 0: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_IN0); - break; - case 1: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL0) / - (2ULL << sysctl_clock_get_threshold(SYSCTL_THRESHOLD_ACLK)); - break; - default: - break; - } - result = source; - break; - - /* - * These clock under ACLK clock domain. - * They are using gated divider. - */ - case SYSCTL_CLOCK_SRAM0: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_ACLK); - result = source / (sysctl_clock_get_threshold(SYSCTL_THRESHOLD_SRAM0) + 1); - break; - case SYSCTL_CLOCK_SRAM1: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_ACLK); - result = source / (sysctl_clock_get_threshold(SYSCTL_THRESHOLD_SRAM1) + 1); - break; - case SYSCTL_CLOCK_ROM: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_ACLK); - result = source / (sysctl_clock_get_threshold(SYSCTL_THRESHOLD_ROM) + 1); - break; - case SYSCTL_CLOCK_DVP: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_ACLK); - result = source / (sysctl_clock_get_threshold(SYSCTL_THRESHOLD_DVP) + 1); - break; - - /* - * These clock under ACLK clock domain. - * They are using even divider. - */ - case SYSCTL_CLOCK_APB0: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_ACLK); - result = source / (sysctl_clock_get_threshold(SYSCTL_THRESHOLD_APB0) + 1); - break; - case SYSCTL_CLOCK_APB1: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_ACLK); - result = source / (sysctl_clock_get_threshold(SYSCTL_THRESHOLD_APB1) + 1); - break; - case SYSCTL_CLOCK_APB2: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_ACLK); - result = source / (sysctl_clock_get_threshold(SYSCTL_THRESHOLD_APB2) + 1); - break; - - /* - * These clock under AI clock domain. - * They are using gated divider. - */ - case SYSCTL_CLOCK_AI: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL1); - result = source / (sysctl_clock_get_threshold(SYSCTL_THRESHOLD_AI) + 1); - break; - - /* - * These clock under I2S clock domain. - * They are using even divider. - */ - case SYSCTL_CLOCK_I2S0: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL2); - result = source / ((sysctl_clock_get_threshold(SYSCTL_THRESHOLD_I2S0) + 1) * 2); - break; - case SYSCTL_CLOCK_I2S1: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL2); - result = source / ((sysctl_clock_get_threshold(SYSCTL_THRESHOLD_I2S1) + 1) * 2); - break; - case SYSCTL_CLOCK_I2S2: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL2); - result = source / ((sysctl_clock_get_threshold(SYSCTL_THRESHOLD_I2S2) + 1) * 2); - break; - - /* - * These clock under WDT clock domain. - * They are using even divider. - */ - case SYSCTL_CLOCK_WDT0: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_IN0); - result = source / ((sysctl_clock_get_threshold(SYSCTL_THRESHOLD_WDT0) + 1) * 2); - break; - case SYSCTL_CLOCK_WDT1: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_IN0); - result = source / ((sysctl_clock_get_threshold(SYSCTL_THRESHOLD_WDT1) + 1) * 2); - break; - - /* - * These clock under PLL0 clock domain. - * They are using even divider. - */ - case SYSCTL_CLOCK_SPI0: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL0); - result = source / ((sysctl_clock_get_threshold(SYSCTL_THRESHOLD_SPI0) + 1) * 2); - break; - case SYSCTL_CLOCK_SPI1: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL0); - result = source / ((sysctl_clock_get_threshold(SYSCTL_THRESHOLD_SPI1) + 1) * 2); - break; - case SYSCTL_CLOCK_SPI2: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL0); - result = source / ((sysctl_clock_get_threshold(SYSCTL_THRESHOLD_SPI2) + 1) * 2); - break; - case SYSCTL_CLOCK_I2C0: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL0); - result = source / ((sysctl_clock_get_threshold(SYSCTL_THRESHOLD_I2C0) + 1) * 2); - break; - case SYSCTL_CLOCK_I2C1: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL0); - result = source / ((sysctl_clock_get_threshold(SYSCTL_THRESHOLD_I2C1) + 1) * 2); - break; - case SYSCTL_CLOCK_I2C2: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL0); - result = source / ((sysctl_clock_get_threshold(SYSCTL_THRESHOLD_I2C2) + 1) * 2); - break; - - /* - * These clock under PLL0_SEL clock domain. - * They are using even divider. - */ - case SYSCTL_CLOCK_SPI3: - switch (sysctl_clock_get_clock_select(SYSCTL_CLOCK_SELECT_SPI3)) { - case 0: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_IN0); - break; - case 1: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL0); - break; - default: - break; - } - - result = source / ((sysctl_clock_get_threshold(SYSCTL_THRESHOLD_SPI3) + 1) * 2); - break; - case SYSCTL_CLOCK_TIMER0: - switch (sysctl_clock_get_clock_select(SYSCTL_CLOCK_SELECT_TIMER0)) { - case 0: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_IN0); - break; - case 1: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL0); - break; - default: - break; - } - - result = source / ((sysctl_clock_get_threshold(SYSCTL_THRESHOLD_TIMER0) + 1) * 2); - break; - case SYSCTL_CLOCK_TIMER1: - switch (sysctl_clock_get_clock_select(SYSCTL_CLOCK_SELECT_TIMER1)) { - case 0: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_IN0); - break; - case 1: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL0); - break; - default: - break; - } - - result = source / ((sysctl_clock_get_threshold(SYSCTL_THRESHOLD_TIMER1) + 1) * 2); - break; - case SYSCTL_CLOCK_TIMER2: - switch (sysctl_clock_get_clock_select(SYSCTL_CLOCK_SELECT_TIMER2)) { - case 0: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_IN0); - break; - case 1: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL0); - break; - default: - break; - } - - result = source / ((sysctl_clock_get_threshold(SYSCTL_THRESHOLD_TIMER2) + 1) * 2); - break; - - /* - * These clock under MISC clock domain. - * They are using even divider. - */ - - /* - * These clock under APB0 clock domain. - * They are using even divider. - */ - case SYSCTL_CLOCK_GPIO: - source = sysctl_clock_get_freq(SYSCTL_CLOCK_APB0); - result = source; - break; - case SYSCTL_CLOCK_UART1: - source = sysctl_clock_get_freq(SYSCTL_CLOCK_APB0); - result = source; - break; - case SYSCTL_CLOCK_UART2: - source = sysctl_clock_get_freq(SYSCTL_CLOCK_APB0); - result = source; - break; - case SYSCTL_CLOCK_UART3: - source = sysctl_clock_get_freq(SYSCTL_CLOCK_APB0); - result = source; - break; - case SYSCTL_CLOCK_FPIOA: - source = sysctl_clock_get_freq(SYSCTL_CLOCK_APB0); - result = source; - break; - case SYSCTL_CLOCK_SHA: - source = sysctl_clock_get_freq(SYSCTL_CLOCK_APB0); - result = source; - break; - - /* - * These clock under APB1 clock domain. - * They are using even divider. - */ - case SYSCTL_CLOCK_AES: - source = sysctl_clock_get_freq(SYSCTL_CLOCK_APB1); - result = source; - break; - case SYSCTL_CLOCK_OTP: - source = sysctl_clock_get_freq(SYSCTL_CLOCK_APB1); - result = source; - break; - case SYSCTL_CLOCK_RTC: - source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_IN0); - result = source; - break; - - /* - * These clock under APB2 clock domain. - * They are using even divider. - */ - default: - break; - } - - return result; -} - -int sysctl_dma_select(sysctl_dma_channel_t channel, sysctl_dma_select_t select) -{ - sysctl_dma_sel0_t dma_sel0; - sysctl_dma_sel1_t dma_sel1; - - /* Read register from bus */ - dma_sel0 = sysctl->dma_sel0; - dma_sel1 = sysctl->dma_sel1; - switch (channel) { - case SYSCTL_DMA_CHANNEL_0: - dma_sel0.dma_sel0 = select; - break; - - case SYSCTL_DMA_CHANNEL_1: - dma_sel0.dma_sel1 = select; - break; - - case SYSCTL_DMA_CHANNEL_2: - dma_sel0.dma_sel2 = select; - break; - - case SYSCTL_DMA_CHANNEL_3: - dma_sel0.dma_sel3 = select; - break; - - case SYSCTL_DMA_CHANNEL_4: - dma_sel0.dma_sel4 = select; - break; - - case SYSCTL_DMA_CHANNEL_5: - dma_sel1.dma_sel5 = select; - break; - - default: - return -1; - } - - /* Write register back to bus */ - sysctl->dma_sel0 = dma_sel0; - sysctl->dma_sel1 = dma_sel1; - - return 0; -} - -u32 sysctl_pll_fast_enable_pll(void) -{ - sysctl_pll0_t pll0; - sysctl_pll1_t pll1; - sysctl_pll2_t pll2; - - /* Read register from bus */ - pll0 = sysctl->pll0; - pll1 = sysctl->pll1; - pll2 = sysctl->pll2; - - /* - * Begin write PLL registers' value, - * Using atomic write method. - */ - /* PLL VCO MAX freq: 1.8GHz */ - - /* PLL0: 26M reference clk get 793M output clock */ - pll0.clkr0 = 0; - pll0.clkf0 = 60; - pll0.clkod0 = 1; - pll0.bwadj0 = 60; - - /* PLL1: 26M reference clk get 390M output clock */ - pll1.clkr1 = 0; - pll1.clkf1 = 59; - pll1.clkod1 = 3; - pll1.bwadj1 = 59; - - /* PLL2: 26M reference clk get 390M output clock */ - pll2.clkr2 = 0; - pll2.clkf2 = 59; - pll2.clkod2 = 3; - pll2.bwadj2 = 59; - - /* Write register to bus */ - sysctl->pll0 = pll0; - sysctl->pll1 = pll1; - sysctl->pll2 = pll2; - - sysctl_pll_enable(SYSCTL_PLL0); - sysctl_pll_enable(SYSCTL_PLL1); - sysctl_pll_enable(SYSCTL_PLL2); - - while (sysctl_pll_is_lock(SYSCTL_PLL0) == 0) - sysctl_pll_clear_slip(SYSCTL_PLL0); - while (sysctl_pll_is_lock(SYSCTL_PLL1) == 0) - sysctl_pll_clear_slip(SYSCTL_PLL1); - while (sysctl_pll_is_lock(SYSCTL_PLL2) == 0) - sysctl_pll_clear_slip(SYSCTL_PLL2); - - sysctl_clock_enable(SYSCTL_CLOCK_PLL0); - sysctl_clock_enable(SYSCTL_CLOCK_PLL1); - sysctl_clock_enable(SYSCTL_CLOCK_PLL2); - - /* Set ACLK to PLL0 */ - sysctl_clock_set_clock_select(SYSCTL_CLOCK_SELECT_ACLK, SYSCTL_SOURCE_PLL0); - - return 0; -} - -u32 sysctl_set_spi0_dvp_data(u8 en) +u32 sysctl_get_cpu_freq(void) { - sysctl->misc.spi_dvp_data_enable = en; - return 0; -} + int clock_source; -void sysctl_set_power_mode(sysctl_power_bank_t power_bank, sysctl_io_power_mode_t io_power_mode) -{ - if(io_power_mode) - *((u32 *)(&sysctl->power_sel)) |= (1 << power_bank); - else - *((u32 *)(&sysctl->power_sel)) &= ~(1 << power_bank); -} - -#if 0 -u32 sysctl_pll_set_freq(sysctl_pll_t pll, u32 pll_freq) -{ - u32 result; - - if(pll_freq == 0) - return 0; - - volatile sysctl_general_pll_t *v_pll_t; - switch(pll) { - case SYSCTL_PLL0: - v_pll_t = (sysctl_general_pll_t *)(&sysctl->pll0); - break; - case SYSCTL_PLL1: - v_pll_t = (sysctl_general_pll_t *)(&sysctl->pll1); - break; - case SYSCTL_PLL2: - v_pll_t = (sysctl_general_pll_t *)(&sysctl->pll2); - break; + clock_source = (int)sysctl->clk_sel0.aclk_sel; + switch (clock_source) { + case 0: + return SYSCTRL_CLOCK_FREQ_IN0; + case 1: + return sysctl_pll0_get_freq() / + (2ULL << (int)sysctl->clk_sel0.aclk_divider_sel); default: return 0; - break; } - - /* 1. Change CPU CLK to XTAL */ - if (pll == SYSCTL_PLL0) - sysctl_clock_set_clock_select(SYSCTL_CLOCK_SELECT_ACLK, SYSCTL_SOURCE_IN0); - - /* 2. Disable PLL output */ - v_pll_t->pll_out_en = 0; - - /* 3. Turn off PLL */ - v_pll_t->pll_pwrd = 0; - - /* 4. Set PLL new value */ - if (pll == SYSCTL_PLL2) - result = sysctl_pll_source_set_freq(pll, v_pll_t->pll_ckin_sel, pll_freq); - else - result = sysctl_pll_source_set_freq(pll, SYSCTL_SOURCE_IN0, pll_freq); - - /* 5. Power on PLL */ - v_pll_t->pll_pwrd = 1; - /* wait >100ns */ - sysctl_usleep(1); - - /* 6. Reset PLL then Release Reset*/ - v_pll_t->pll_reset = 0; - v_pll_t->pll_reset = 1; - /* wait >100ns */ - sysctl_usleep(1); - v_pll_t->pll_reset = 0; - - /* 7. Get lock status, wait PLL stable */ - while (sysctl_pll_is_lock(pll) == 0) - sysctl_pll_clear_slip(pll); - - /* 8. Enable PLL output */ - v_pll_t->pll_out_en = 1; - - /* 9. Change CPU CLK to PLL */ - if (pll == SYSCTL_PLL0) - sysctl_clock_set_clock_select(SYSCTL_CLOCK_SELECT_ACLK, SYSCTL_SOURCE_PLL0); - - return result; -} - -u32 sysctl_cpu_set_freq(u32 freq) -{ - if (freq == 0) - return 0; - - return sysctl_pll_set_freq(SYSCTL_PLL0, (sysctl->clk_sel0.aclk_divider_sel + 1) * 2 * freq); -} -#endif - -void sysctl_enable_irq(void) -{ - csr_read_set(mie, MIP_MEIP); - csr_read_set(mstatus, MSTATUS_MIE); } -void sysctl_disable_irq(void) -{ - csr_read_clear(mie, MIP_MEIP); - csr_read_clear(mstatus, MSTATUS_MIE); -} - -u64 sysctl_get_time_us(void) -{ - u64 v_cycle = read_cycle(); - - return v_cycle * 1000000 / sysctl_clock_get_freq(SYSCTL_CLOCK_CPU); -} - -void sysctl_usleep(u64 usec) -{ - u64 nop_all = usec * sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 1000000UL; - u64 cycle = read_cycle(); - - while (read_cycle() - cycle < nop_all); -} diff --git a/platform/kendryte/k210/sysctl.h b/platform/kendryte/k210/sysctl.h index 09d81aeca8d..aa95d628e22 100644 --- a/platform/kendryte/k210/sysctl.h +++ b/platform/kendryte/k210/sysctl.h @@ -782,164 +782,9 @@ typedef struct _sysctl_general_pll { } __attribute__((packed, aligned(4))) sysctl_general_pll_t; /** - * System controller object instanse + * Get frequency of CPU + * @return The frequency of the CPU */ -extern volatile sysctl_t *const sysctl; - -/** - * Enable clock for peripheral - * @param[in] clock The clock to be enable - * @return result - * - 0 Success - * - Other Fail - */ -int sysctl_clock_enable(sysctl_clock_t clock); - -/** - * Enable clock for peripheral - * @param[in] clock The clock to be disable - * @return result - * - 0 Success - * - Other Fail - */ -int sysctl_clock_disable(sysctl_clock_t clock); - -/** - * Sysctl clock set threshold - * @param[in] which Which threshold to set - * @param[in] threshold The threshold value - * @return result - * - 0 Success - * - Other Fail - */ -int sysctl_clock_set_threshold(sysctl_threshold_t which, int threshold); - -/** - * Sysctl clock get threshold - * @param[in] which Which threshold to get - * @return The threshold value - * - Other Value of threshold - * - -1 Fail - */ -int sysctl_clock_get_threshold(sysctl_threshold_t which); - -/** - * Sysctl clock set clock select - * @param[in] which Which clock select to set - * @param[in] select The clock select value - * @return result - * - 0 Success - * - Other Fail - */ -int sysctl_clock_set_clock_select(sysctl_clock_select_t which, int select); - -/** - * Sysctl clock get clock select - * @param[in] which Which clock select to get - * @return The clock select value - * - Other Value of clock select - * - -1 Fail - */ -int sysctl_clock_get_clock_select(sysctl_clock_select_t which); - -/** - * Get PLL frequency - * @param[in] pll The PLL id - * @return The frequency of PLL - */ -u32 sysctl_pll_get_freq(sysctl_pll_t pll); - -/** - * Get base clock frequency by clock id - * @param[in] clock The clock id - * @return The clock frequency - */ -u32 sysctl_clock_get_freq(sysctl_clock_t clock); - -/** - * Reset device by reset controller - * @param[in] reset The reset signal - */ -void sysctl_reset(sysctl_reset_t reset); - -/** - * Enable the PLL and power on with reset - * @param[in] pll The pll id - * @return Result - * - 0 Success - * - Other Fail - */ -int sysctl_pll_enable(sysctl_pll_t pll); - -/** - * Disable the PLL and power off - * @param[in] pll The pll id - * @return Result - * - 0 Success - * - Other Fail - */ -int sysctl_pll_disable(sysctl_pll_t pll); - -/** - * Select DMA channel handshake peripheral signal - * @param[in] channel The DMA channel - * @param[in] select The peripheral select - * @return Result - * - 0 Success - * - Other Fail - */ -int sysctl_dma_select(sysctl_dma_channel_t channel, sysctl_dma_select_t select); - -/** - * Set SPI0_D0-D7 DVP_D0-D7 as spi and dvp data pin - * @param[in] en Enable or not - * @return Result - * - 0 Success - * - Other Fail - */ -u32 sysctl_set_spi0_dvp_data(u8 en); - -/** - * Set io power mode - * @param[in] power_bank IO power bank - * @param[in] io_power_mode Set power mode 3.3v or 1.8 - * @return Result - * - 0 Success - * - Other Fail - */ -void sysctl_set_power_mode(sysctl_power_bank_t power_bank, sysctl_io_power_mode_t io_power_mode); - -/** - * Set frequency of CPU - * @param[in] freq The desired frequency in Hz - * @return The actual frequency of CPU after set - */ -u32 sysctl_cpu_set_freq(u32 freq); - -/** - * Init PLL freqency - * @param[in] pll The PLL id - * @param[in] pll_freq The desired frequency in Hz - - */ -u32 sysctl_pll_set_freq(sysctl_pll_t pll, u32 pll_freq); - -/** - * Enable interrupt - */ -void sysctl_enable_irq(void); - -/** - * Disable interrupt - */ -void sysctl_disable_irq(void); - -/** - * Get the time start up to now - * @return The time of microsecond - */ -u64 sysctl_get_time_us(void); - -void sysctl_usleep(u64 usec); +u32 sysctl_get_cpu_freq(void); #endif /* _K210_SYSCTL_H_ */ diff --git a/platform/kendryte/k210/uarths.c b/platform/kendryte/k210/uarths.c index 6551de76e37..2a189aaddd9 100644 --- a/platform/kendryte/k210/uarths.c +++ b/platform/kendryte/k210/uarths.c @@ -21,7 +21,7 @@ static volatile struct uarths *const uarths = void uarths_init(u32 baud_rate, enum uarths_stopbit stopbit) { - u32 freq = sysctl_clock_get_freq(SYSCTL_CLOCK_CPU); + u32 freq = sysctl_get_cpu_freq(); u16 div = freq / baud_rate - 1; /* Set UART registers */ From 4d1eccc41d96413fae25cea5f941f7860429340b Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Thu, 3 Jan 2019 10:37:43 +0530 Subject: [PATCH 0068/1765] include: Add hard FP access macros and defines This patch adds hardware floating-point (hard FP) access macros and defines. Signed-off-by: Anup Patel --- include/sbi/riscv_encoding.h | 13 +++ include/sbi/riscv_fp.h | 73 +++++++++++++++ lib/objects.mk | 1 + lib/riscv_hardfp.S | 171 +++++++++++++++++++++++++++++++++++ lib/sbi_hart.c | 8 +- 5 files changed, 259 insertions(+), 7 deletions(-) create mode 100644 include/sbi/riscv_fp.h create mode 100644 lib/riscv_hardfp.S diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h index 381f3058960..a6651a15107 100644 --- a/include/sbi/riscv_encoding.h +++ b/include/sbi/riscv_encoding.h @@ -446,6 +446,19 @@ #define INSN_MATCH_SD 0x3023 #define INSN_MASK_SD 0x707f +#define INSN_MATCH_FLW 0x2007 +#define INSN_MASK_FLW 0x707f +#define INSN_MATCH_FLD 0x3007 +#define INSN_MASK_FLD 0x707f +#define INSN_MATCH_FLQ 0x4007 +#define INSN_MASK_FLQ 0x707f +#define INSN_MATCH_FSW 0x2027 +#define INSN_MASK_FSW 0x707f +#define INSN_MATCH_FSD 0x3027 +#define INSN_MASK_FSD 0x707f +#define INSN_MATCH_FSQ 0x4027 +#define INSN_MASK_FSQ 0x707f + #define INSN_MATCH_C_LD 0x6000 #define INSN_MASK_C_LD 0xe003 #define INSN_MATCH_C_SD 0xe000 diff --git a/include/sbi/riscv_fp.h b/include/sbi/riscv_fp.h new file mode 100644 index 00000000000..0deb8e4a00c --- /dev/null +++ b/include/sbi/riscv_fp.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2019 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#ifndef __RISCV_FP_H__ +#define __RISCV_FP_H__ + +#include +#include +#include + +#define GET_PRECISION(insn) (((insn) >> 25) & 3) +#define GET_RM(insn) (((insn) >> 12) & 7) +#define PRECISION_S 0 +#define PRECISION_D 1 + +#ifdef __riscv_flen + +#define GET_F32_REG(insn, pos, regs) ({ \ + register s32 value asm("a0") = SHIFT_RIGHT(insn, (pos)-3) & 0xf8; \ + ulong tmp; \ + asm ("1: auipc %0, %%pcrel_hi(get_f32_reg); add %0, %0, %1; jalr t0, %0, %%pcrel_lo(1b)" : "=&r"(tmp), "+&r"(value) :: "t0"); \ + value; }) +#define SET_F32_REG(insn, pos, regs, val) ({ \ + register u32 value asm("a0") = (val); \ + ulong offset = SHIFT_RIGHT(insn, (pos)-3) & 0xf8; \ + ulong tmp; \ + asm volatile ("1: auipc %0, %%pcrel_hi(put_f32_reg); add %0, %0, %2; jalr t0, %0, %%pcrel_lo(1b)" : "=&r"(tmp) : "r"(value), "r"(offset) : "t0"); }) +#define init_fp_reg(i) SET_F32_REG((i) << 3, 3, 0, 0) +#define GET_F64_REG(insn, pos, regs) ({ \ + register ulong value asm("a0") = SHIFT_RIGHT(insn, (pos)-3) & 0xf8; \ + ulong tmp; \ + asm ("1: auipc %0, %%pcrel_hi(get_f64_reg); add %0, %0, %1; jalr t0, %0, %%pcrel_lo(1b)" : "=&r"(tmp), "+&r"(value) :: "t0"); \ + sizeof(ulong) == 4 ? *(int64_t*)value : (int64_t)value; }) +#define SET_F64_REG(insn, pos, regs, val) ({ \ + uint64_t __val = (val); \ + register ulong value asm("a0") = sizeof(ulong) == 4 ? (ulong)&__val : (ulong)__val; \ + ulong offset = SHIFT_RIGHT(insn, (pos)-3) & 0xf8; \ + ulong tmp; \ + asm volatile ("1: auipc %0, %%pcrel_hi(put_f64_reg); add %0, %0, %2; jalr t0, %0, %%pcrel_lo(1b)" : "=&r"(tmp) : "r"(value), "r"(offset) : "t0"); }) +#define GET_FCSR() csr_read(fcsr) +#define SET_FCSR(value) csr_write(fcsr, (value)) +#define GET_FRM() csr_read(frm) +#define SET_FRM(value) csr_write(frm, (value)) +#define GET_FFLAGS() csr_read(fflags) +#define SET_FFLAGS(value) csr_write(fflags, (value)) + +#define SET_FS_DIRTY() ((void) 0) + +#else +#error "Floating point emulation not supported.\n" +#endif + +#define GET_F32_RS1(insn, regs) (GET_F32_REG(insn, 15, regs)) +#define GET_F32_RS2(insn, regs) (GET_F32_REG(insn, 20, regs)) +#define GET_F32_RS3(insn, regs) (GET_F32_REG(insn, 27, regs)) +#define GET_F64_RS1(insn, regs) (GET_F64_REG(insn, 15, regs)) +#define GET_F64_RS2(insn, regs) (GET_F64_REG(insn, 20, regs)) +#define GET_F64_RS3(insn, regs) (GET_F64_REG(insn, 27, regs)) +#define SET_F32_RD(insn, regs, val) (SET_F32_REG(insn, 7, regs, val), SET_FS_DIRTY()) +#define SET_F64_RD(insn, regs, val) (SET_F64_REG(insn, 7, regs, val), SET_FS_DIRTY()) + +#define GET_F32_RS2C(insn, regs) (GET_F32_REG(insn, 2, regs)) +#define GET_F32_RS2S(insn, regs) (GET_F32_REG(RVC_RS2S(insn), 0, regs)) +#define GET_F64_RS2C(insn, regs) (GET_F64_REG(insn, 2, regs)) +#define GET_F64_RS2S(insn, regs) (GET_F64_REG(RVC_RS2S(insn), 0, regs)) + +#endif diff --git a/lib/objects.mk b/lib/objects.mk index b70557ddad7..2ce6328f591 100644 --- a/lib/objects.mk +++ b/lib/objects.mk @@ -9,6 +9,7 @@ lib-objs-y += riscv_asm.o lib-objs-y += riscv_atomic.o +lib-objs-y += riscv_hardfp.o lib-objs-y += riscv_locks.o lib-objs-y += sbi_console.o diff --git a/lib/riscv_hardfp.S b/lib/riscv_hardfp.S new file mode 100644 index 00000000000..11f3e41e613 --- /dev/null +++ b/lib/riscv_hardfp.S @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2019 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#ifdef __riscv_flen + +#if __riscv_flen != 64 +# error single-float only is not supported +#endif + +#define get_f32(which) fmv.x.s a0, which; jr t0 +#define put_f32(which) fmv.s.x which, a0; jr t0 +#if __riscv_xlen == 64 +# define get_f64(which) fmv.x.d a0, which; jr t0 +# define put_f64(which) fmv.d.x which, a0; jr t0 +#else +# define get_f64(which) fsd which, 0(a0); jr t0 +# define put_f64(which) fld which, 0(a0); jr t0 +#endif + + .text + .option norvc + .globl get_f32_reg + get_f32_reg: + get_f32(f0) + get_f32(f1) + get_f32(f2) + get_f32(f3) + get_f32(f4) + get_f32(f5) + get_f32(f6) + get_f32(f7) + get_f32(f8) + get_f32(f9) + get_f32(f10) + get_f32(f11) + get_f32(f12) + get_f32(f13) + get_f32(f14) + get_f32(f15) + get_f32(f16) + get_f32(f17) + get_f32(f18) + get_f32(f19) + get_f32(f20) + get_f32(f21) + get_f32(f22) + get_f32(f23) + get_f32(f24) + get_f32(f25) + get_f32(f26) + get_f32(f27) + get_f32(f28) + get_f32(f29) + get_f32(f30) + get_f32(f31) + + .text + .globl put_f32_reg + put_f32_reg: + put_f32(f0) + put_f32(f1) + put_f32(f2) + put_f32(f3) + put_f32(f4) + put_f32(f5) + put_f32(f6) + put_f32(f7) + put_f32(f8) + put_f32(f9) + put_f32(f10) + put_f32(f11) + put_f32(f12) + put_f32(f13) + put_f32(f14) + put_f32(f15) + put_f32(f16) + put_f32(f17) + put_f32(f18) + put_f32(f19) + put_f32(f20) + put_f32(f21) + put_f32(f22) + put_f32(f23) + put_f32(f24) + put_f32(f25) + put_f32(f26) + put_f32(f27) + put_f32(f28) + put_f32(f29) + put_f32(f30) + put_f32(f31) + + .text + .globl get_f64_reg + get_f64_reg: + get_f64(f0) + get_f64(f1) + get_f64(f2) + get_f64(f3) + get_f64(f4) + get_f64(f5) + get_f64(f6) + get_f64(f7) + get_f64(f8) + get_f64(f9) + get_f64(f10) + get_f64(f11) + get_f64(f12) + get_f64(f13) + get_f64(f14) + get_f64(f15) + get_f64(f16) + get_f64(f17) + get_f64(f18) + get_f64(f19) + get_f64(f20) + get_f64(f21) + get_f64(f22) + get_f64(f23) + get_f64(f24) + get_f64(f25) + get_f64(f26) + get_f64(f27) + get_f64(f28) + get_f64(f29) + get_f64(f30) + get_f64(f31) + + .text + .globl put_f64_reg + put_f64_reg: + put_f64(f0) + put_f64(f1) + put_f64(f2) + put_f64(f3) + put_f64(f4) + put_f64(f5) + put_f64(f6) + put_f64(f7) + put_f64(f8) + put_f64(f9) + put_f64(f10) + put_f64(f11) + put_f64(f12) + put_f64(f13) + put_f64(f14) + put_f64(f15) + put_f64(f16) + put_f64(f17) + put_f64(f18) + put_f64(f19) + put_f64(f20) + put_f64(f21) + put_f64(f22) + put_f64(f23) + put_f64(f24) + put_f64(f25) + put_f64(f26) + put_f64(f27) + put_f64(f28) + put_f64(f29) + put_f64(f30) + put_f64(f31) + +#endif diff --git a/lib/sbi_hart.c b/lib/sbi_hart.c index 1e5465f5d31..e8a689ed282 100644 --- a/lib/sbi_hart.c +++ b/lib/sbi_hart.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -48,13 +49,6 @@ static void mstatus_init(struct sbi_scratch *scratch, u32 hartid) csr_write(sptbr, 0); } -#ifdef __riscv_flen -static void init_fp_reg(int i) -{ - /* TODO: */ -} -#endif - static int fp_init(u32 hartid) { #ifdef __riscv_flen From 48dc50df8f8693f86500f71a4b701b4dd0c841d7 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Thu, 3 Jan 2019 12:18:47 +0530 Subject: [PATCH 0069/1765] lib: Handle misaligned load/store on FP regs This patch extends misaligned load/store trap handling to handle FP regs as well. Signed-off-by: Anup Patel --- lib/sbi_misaligned_ldst.c | 52 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/lib/sbi_misaligned_ldst.c b/lib/sbi_misaligned_ldst.c index b35e919ac70..bde960740f0 100644 --- a/lib/sbi_misaligned_ldst.c +++ b/lib/sbi_misaligned_ldst.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -28,7 +29,7 @@ int sbi_misaligned_load_handler(u32 hartid, ulong mcause, ulong mstatus = csr_read(mstatus); ulong insn = get_insn(regs->mepc, &mstatus); ulong addr = csr_read(mtval); - int i, shift = 0, len = 0; + int i, fp = 0, shift = 0, len = 0; if ((insn & INSN_MASK_LW) == INSN_MATCH_LW) { len = 4; @@ -40,6 +41,12 @@ int sbi_misaligned_load_handler(u32 hartid, ulong mcause, } else if ((insn & INSN_MASK_LWU) == INSN_MATCH_LWU) { len = 4; #endif + } else if ((insn & INSN_MASK_FLD) == INSN_MATCH_FLD) { + fp = 1; + len = 8; + } else if ((insn & INSN_MASK_FLW) == INSN_MATCH_FLW) { + fp = 1; + len = 4; } else if ((insn & INSN_MASK_LH) == INSN_MATCH_LH) { len = 2; shift = 8 * (sizeof(ulong) - len); @@ -64,6 +71,22 @@ int sbi_misaligned_load_handler(u32 hartid, ulong mcause, ((insn >> SH_RD) & 0x1f)) { len = 4; shift = 8 * (sizeof(ulong) - len); + } else if ((insn & INSN_MASK_C_FLD) == INSN_MATCH_C_FLD) { + fp = 1; + len = 8; + insn = RVC_RS2S(insn) << SH_RD; + } else if ((insn & INSN_MASK_C_FLDSP) == INSN_MATCH_C_FLDSP) { + fp = 1; + len = 8; +# if __riscv_xlen == 32 + } else if ((insn & INSN_MASK_C_FLW) == INSN_MATCH_C_FLW) { + fp = 1; + len = 4; + insn = RVC_RS2S(insn) << SH_RD; + } else if ((insn & INSN_MASK_C_FLWSP) == INSN_MATCH_C_FLWSP) { + fp = 1; + len = 4; +# endif #endif } else return SBI_EILL; @@ -72,7 +95,12 @@ int sbi_misaligned_load_handler(u32 hartid, ulong mcause, for (i = 0; i < len; i++) val.data_bytes[i] = load_u8((void *)(addr + i), regs->mepc); - SET_RD(insn, regs, val.data_ulong << shift >> shift); + if (!fp) + SET_RD(insn, regs, val.data_ulong << shift >> shift); + else if (len == 8) + SET_F64_RD(insn, regs, val.data_u64); + else + SET_F32_RD(insn, regs, val.data_ulong); regs->mepc += INSN_LEN(insn); @@ -97,6 +125,12 @@ int sbi_misaligned_store_handler(u32 hartid, ulong mcause, } else if ((insn & INSN_MASK_SD) == INSN_MATCH_SD) { len = 8; #endif + } else if ((insn & INSN_MASK_FSD) == INSN_MATCH_FSD) { + len = 8; + val.data_u64 = GET_F64_RS2(insn, regs); + } else if ((insn & INSN_MASK_FSW) == INSN_MATCH_FSW) { + len = 4; + val.data_ulong = GET_F32_RS2(insn, regs); } else if ((insn & INSN_MASK_SH) == INSN_MATCH_SH) { len = 2; #ifdef __riscv_compressed @@ -116,6 +150,20 @@ int sbi_misaligned_store_handler(u32 hartid, ulong mcause, ((insn >> SH_RD) & 0x1f)) { len = 4; val.data_ulong = GET_RS2C(insn, regs); + } else if ((insn & INSN_MASK_C_FSD) == INSN_MATCH_C_FSD) { + len = 8; + val.data_u64 = GET_F64_RS2S(insn, regs); + } else if ((insn & INSN_MASK_C_FSDSP) == INSN_MATCH_C_FSDSP) { + len = 8; + val.data_u64 = GET_F64_RS2C(insn, regs); +# if __riscv_xlen == 32 + } else if ((insn & INSN_MASK_C_FSW) == INSN_MATCH_C_FSW) { + len = 4; + val.data_ulong = GET_F32_RS2S(insn, regs); + } else if ((insn & INSN_MASK_C_FSWSP) == INSN_MATCH_C_FSWSP) { + len = 4; + val.data_ulong = GET_F32_RS2C(insn, regs); +# endif #endif } else return SBI_EILL; From 6d9e390f5b9e96972aa010b4ef4e0291c14623b5 Mon Sep 17 00:00:00 2001 From: Alistair Francis Date: Wed, 2 Jan 2019 10:14:40 -0800 Subject: [PATCH 0070/1765] Makefile: Support verbosity using standard V=1 Instead of using a confusing and custom option, allow verbose Makefile with the standard V=1. Signed-off-by: Alistair Francis --- Makefile | 62 ++++++++++++++++++++++++-------------------------------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index 0a8accffdaa..2a5285f11bc 100644 --- a/Makefile +++ b/Makefile @@ -39,21 +39,11 @@ $(error Install directory is same as build directory.) endif # Check if verbosity is ON for build process -VERBOSE_DEFAULT := 0 CMD_PREFIX_DEFAULT := @ -ifdef VERBOSE - ifeq ("$(origin VERBOSE)", "command line") - VB := $(VERBOSE) - else - VB := $(VERBOSE_DEFAULT) - endif +ifeq ($(V), 1) + CMD_PREFIX := else - VB := $(VERBOSE_DEFAULT) -endif -ifeq ($(VB), 1) - override V := -else - override V := $(CMD_PREFIX_DEFAULT) + CMD_PREFIX := $(CMD_PREFIX_DEFAULT) endif # Setup path of directories @@ -140,19 +130,19 @@ objcopy=$(CROSS_COMPILE)objcopy define dynamic_flags -I$(shell dirname $(2)) -D__OBJNAME__=$(subst -,_,$(shell basename $(1) .o)) endef -merge_objs = $(V)mkdir -p `dirname $(1)`; \ +merge_objs = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " MERGE $(subst $(build_dir)/,,$(1))"; \ $(merge) $(mergeflags) $(2) -o $(1) -merge_deps = $(V)mkdir -p `dirname $(1)`; \ +merge_deps = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " MERGE-DEP $(subst $(build_dir)/,,$(1))"; \ cat $(2) > $(1) -copy_file = $(V)mkdir -p `dirname $(1)`; \ +copy_file = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " COPY $(subst $(build_dir)/,,$(1))"; \ cp -f $(2) $(1) -inst_file = $(V)mkdir -p `dirname $(1)`; \ +inst_file = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " INSTALL $(subst $(install_dir)/,,$(1))"; \ cp -f $(2) $(1) -inst_file_list = $(V)if [ ! -z "$(4)" ]; then \ +inst_file_list = $(CMD_PREFIX)if [ ! -z "$(4)" ]; then \ mkdir -p $(1)/$(3); \ for file in $(4) ; do \ rel_file=`echo $$file | sed -e 's@$(2)/$(3)/@@'`; \ @@ -163,35 +153,35 @@ inst_file_list = $(V)if [ ! -z "$(4)" ]; then \ cp -f $$file $$dest_file; \ done \ fi -inst_header_dir = $(V)mkdir -p $(1); \ +inst_header_dir = $(CMD_PREFIX)mkdir -p $(1); \ echo " INSTALL $(subst $(install_dir)/,,$(1))"; \ cp -rf $(2) $(1) -compile_cpp = $(V)mkdir -p `dirname $(1)`; \ +compile_cpp = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " CPP $(subst $(build_dir)/,,$(1))"; \ $(cpp) $(cppflags) $(2) | grep -v "\#" > $(1) -compile_cc_dep = $(V)mkdir -p `dirname $(1)`; \ +compile_cc_dep = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " CC-DEP $(subst $(build_dir)/,,$(1))"; \ echo -n `dirname $(1)`/ > $(1) && \ $(cc) $(cflags) $(call dynamic_flags,$(1),$(2)) \ -MM $(2) >> $(1) || rm -f $(1) -compile_cc = $(V)mkdir -p `dirname $(1)`; \ +compile_cc = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " CC $(subst $(build_dir)/,,$(1))"; \ $(cc) $(cflags) $(call dynamic_flags,$(1),$(2)) -c $(2) -o $(1) -compile_as_dep = $(V)mkdir -p `dirname $(1)`; \ +compile_as_dep = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " AS-DEP $(subst $(build_dir)/,,$(1))"; \ echo -n `dirname $(1)`/ > $(1) && \ $(as) $(asflags) $(call dynamic_flags,$(1),$(2)) \ -MM $(2) >> $(1) || rm -f $(1) -compile_as = $(V)mkdir -p `dirname $(1)`; \ +compile_as = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " AS $(subst $(build_dir)/,,$(1))"; \ $(as) $(asflags) $(call dynamic_flags,$(1),$(2)) -c $(2) -o $(1) -compile_ld = $(V)mkdir -p `dirname $(1)`; \ +compile_ld = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " LD $(subst $(build_dir)/,,$(1))"; \ $(ld) $(3) $(ldflags) -Wl,-T$(2) -o $(1) -compile_ar = $(V)mkdir -p `dirname $(1)`; \ +compile_ar = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " AR $(subst $(build_dir)/,,$(1))"; \ $(ar) $(arflags) $(1) $(2) -compile_objcopy = $(V)mkdir -p `dirname $(1)`; \ +compile_objcopy = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " OBJCOPY $(subst $(build_dir)/,,$(1))"; \ $(objcopy) -S -O binary $(2) $(1) @@ -284,27 +274,27 @@ install_firmwares: $(build_dir)/$(platform_subdir)/lib/libplatsbi.a $(build_dir) # Rule for "make clean" .PHONY: clean clean: - $(V)mkdir -p $(build_dir) + $(CMD_PREFIX)mkdir -p $(build_dir) $(if $(V), @echo " RM $(build_dir)/*.o") - $(V)find $(build_dir) -type f -name "*.o" -exec rm -rf {} + + $(CMD_PREFIX)find $(build_dir) -type f -name "*.o" -exec rm -rf {} + $(if $(V), @echo " RM $(build_dir)/*.a") - $(V)find $(build_dir) -type f -name "*.a" -exec rm -rf {} + + $(CMD_PREFIX)find $(build_dir) -type f -name "*.a" -exec rm -rf {} + $(if $(V), @echo " RM $(build_dir)/*.elf") - $(V)find $(build_dir) -type f -name "*.elf" -exec rm -rf {} + + $(CMD_PREFIX)find $(build_dir) -type f -name "*.elf" -exec rm -rf {} + $(if $(V), @echo " RM $(build_dir)/*.bin") - $(V)find $(build_dir) -type f -name "*.bin" -exec rm -rf {} + + $(CMD_PREFIX)find $(build_dir) -type f -name "*.bin" -exec rm -rf {} + # Rule for "make distclean" .PHONY: distclean distclean: clean - $(V)mkdir -p $(build_dir) + $(CMD_PREFIX)mkdir -p $(build_dir) $(if $(V), @echo " RM $(build_dir)/*.dep") - $(V)find $(build_dir) -type f -name "*.dep" -exec rm -rf {} + + $(CMD_PREFIX)find $(build_dir) -type f -name "*.dep" -exec rm -rf {} + ifeq ($(build_dir),$(CURDIR)/build) $(if $(V), @echo " RM $(build_dir)") - $(V)rm -rf $(build_dir) + $(CMD_PREFIX)rm -rf $(build_dir) endif ifeq ($(install_dir),$(CURDIR)/install) $(if $(V), @echo " RM $(install_dir)") - $(V)rm -rf $(install_dir) + $(CMD_PREFIX)rm -rf $(install_dir) endif From 116f10973b539f056be55a24d2855a7a8b985c27 Mon Sep 17 00:00:00 2001 From: Alistair Francis Date: Wed, 2 Jan 2019 10:16:15 -0800 Subject: [PATCH 0071/1765] Makefile: Use generic flags for the platform Signed-off-by: Alistair Francis --- Makefile | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 2a5285f11bc..9c6ea8d34f8 100644 --- a/Makefile +++ b/Makefile @@ -91,20 +91,23 @@ deps-y+=$(platform-common-objs-path-y:.o=.dep) deps-y+=$(lib-objs-path-y:.o=.dep) deps-y+=$(firmware-objs-path-y:.o=.dep) +GENFLAGS = -DOPENSBI_MAJOR=$(MAJOR) +GENFLAGS += -DOPENSBI_MINOR=$(MINOR) +GENFLAGS += -I$(platform_dir)/include +GENFLAGS += -I$(platform_common_dir)/include +GENFLAGS += -I$(include_dir) +GENFLAGS += $(platform-genflags-y) + # Setup compilation environment cpp=$(CROSS_COMPILE)cpp -cppflags+=-DOPENSBI_MAJOR=$(MAJOR) -cppflags+=-DOPENSBI_MINOR=$(MINOR) -cppflags+=-I$(platform_dir)/include -cppflags+=-I$(platform_common_dir)/include -cppflags+=-I$(include_dir) +cppflags+=$(GENFLAGS) cppflags+=$(platform-cppflags-y) cppflags+=$(firmware-cppflags-y) cc=$(CROSS_COMPILE)gcc cflags=-g -Wall -Werror -nostdlib -fno-strict-aliasing -O2 cflags+=-fno-omit-frame-pointer -fno-optimize-sibling-calls cflags+=-mno-save-restore -mstrict-align -cflags+=$(cppflags) +cflags+=$(GENFLAGS) cflags+=$(platform-cflags-y) cflags+=$(firmware-cflags-y) cflags+=$(EXTRA_CFLAGS) @@ -112,7 +115,7 @@ as=$(CROSS_COMPILE)gcc asflags=-g -Wall -nostdlib -D__ASSEMBLY__ asflags+=-fno-omit-frame-pointer -fno-optimize-sibling-calls asflags+=-mno-save-restore -mstrict-align -asflags+=$(cppflags) +asflags+=$(GENFLAGS) asflags+=$(platform-asflags-y) asflags+=$(firmware-asflags-y) asflags+=$(EXTRA_ASFLAGS) From d6ddfdce3975c9484f8b7f9a364b3e75da780b2a Mon Sep 17 00:00:00 2001 From: Alistair Francis Date: Fri, 21 Dec 2018 16:09:03 -0800 Subject: [PATCH 0072/1765] Makefile: Use generic flags for the firmware Signed-off-by: Alistair Francis --- Makefile | 1 + firmware/objects.mk | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 9c6ea8d34f8..cdcb3c46b79 100644 --- a/Makefile +++ b/Makefile @@ -97,6 +97,7 @@ GENFLAGS += -I$(platform_dir)/include GENFLAGS += -I$(platform_common_dir)/include GENFLAGS += -I$(include_dir) GENFLAGS += $(platform-genflags-y) +GENFLAGS += $(firmware-genflags-y) # Setup compilation environment cpp=$(CROSS_COMPILE)cpp diff --git a/firmware/objects.mk b/firmware/objects.mk index a8275f9f40b..18a1fbc967d 100644 --- a/firmware/objects.mk +++ b/firmware/objects.mk @@ -7,21 +7,22 @@ # SPDX-License-Identifier: BSD-2-Clause # +firmware-genflags-y = firmware-cppflags-y += firmware-cflags-y += firmware-asflags-y += firmware-ldflags-y += ifdef FW_TEXT_START -firmware-cppflags-y += -DFW_TEXT_START=$(FW_TEXT_START) +firmware-genflags-y += -DFW_TEXT_START=$(FW_TEXT_START) endif firmware-bins-$(FW_JUMP) += fw_jump.bin ifdef FW_JUMP_ADDR -firmware-cppflags-$(FW_JUMP) += -DFW_JUMP_ADDR=$(FW_JUMP_ADDR) +firmware-genflags-$(FW_JUMP) += -DFW_JUMP_ADDR=$(FW_JUMP_ADDR) endif ifdef FW_JUMP_FDT_ADDR -firmware-cppflags-$(FW_JUMP) += -DFW_JUMP_FDT_ADDR=$(FW_JUMP_FDT_ADDR) +firmware-genflags-$(FW_JUMP) += -DFW_JUMP_FDT_ADDR=$(FW_JUMP_FDT_ADDR) endif firmware-bins-$(FW_PAYLOAD) += fw_payload.bin @@ -30,13 +31,13 @@ FW_PAYLOAD_PATH_FINAL=$(FW_PAYLOAD_PATH) else FW_PAYLOAD_PATH_FINAL=$(build_dir)/$(platform_subdir)/firmware/payloads/dummy.bin endif -firmware-cppflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_PATH=$(FW_PAYLOAD_PATH_FINAL) +firmware-genflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_PATH=$(FW_PAYLOAD_PATH_FINAL) ifdef FW_PAYLOAD_OFFSET -firmware-cppflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_OFFSET=$(FW_PAYLOAD_OFFSET) +firmware-genflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_OFFSET=$(FW_PAYLOAD_OFFSET) endif ifdef FW_PAYLOAD_FDT_PATH -firmware-cppflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_FDT_PATH=$(FW_PAYLOAD_FDT_PATH) +firmware-genflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_FDT_PATH=$(FW_PAYLOAD_FDT_PATH) endif ifdef FW_PAYLOAD_FDT_ADDR -firmware-cppflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_FDT_ADDR=$(FW_PAYLOAD_FDT_ADDR) +firmware-genflags-$(FW_PAYLOAD) += -DFW_PAYLOAD_FDT_ADDR=$(FW_PAYLOAD_FDT_ADDR) endif From eeab92f2423ef907629f784658663baf66b5df78 Mon Sep 17 00:00:00 2001 From: Alistair Francis Date: Fri, 21 Dec 2018 16:44:55 -0800 Subject: [PATCH 0073/1765] Makefile: Convert to a more standard format Convert the Makefile to a more standard format and don't forcefully overwrite a users enviroment. Signed-off-by: Alistair Francis --- Makefile | 79 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/Makefile b/Makefile index cdcb3c46b79..fd3ed44354a 100644 --- a/Makefile +++ b/Makefile @@ -100,35 +100,38 @@ GENFLAGS += $(platform-genflags-y) GENFLAGS += $(firmware-genflags-y) # Setup compilation environment -cpp=$(CROSS_COMPILE)cpp -cppflags+=$(GENFLAGS) -cppflags+=$(platform-cppflags-y) -cppflags+=$(firmware-cppflags-y) -cc=$(CROSS_COMPILE)gcc -cflags=-g -Wall -Werror -nostdlib -fno-strict-aliasing -O2 -cflags+=-fno-omit-frame-pointer -fno-optimize-sibling-calls -cflags+=-mno-save-restore -mstrict-align -cflags+=$(GENFLAGS) -cflags+=$(platform-cflags-y) -cflags+=$(firmware-cflags-y) -cflags+=$(EXTRA_CFLAGS) -as=$(CROSS_COMPILE)gcc -asflags=-g -Wall -nostdlib -D__ASSEMBLY__ -asflags+=-fno-omit-frame-pointer -fno-optimize-sibling-calls -asflags+=-mno-save-restore -mstrict-align -asflags+=$(GENFLAGS) -asflags+=$(platform-asflags-y) -asflags+=$(firmware-asflags-y) -asflags+=$(EXTRA_ASFLAGS) -ar=$(CROSS_COMPILE)ar -arflags=rcs -ld=$(CROSS_COMPILE)gcc -ldflags=-g -Wall -nostdlib -Wl,--build-id=none -ldflags+=$(platform-ldflags-y) -ldflags+=$(firmware-ldflags-y) -merge=$(CROSS_COMPILE)ld -mergeflags=-r -objcopy=$(CROSS_COMPILE)objcopy +CC ?= $(CROSS_COMPILE)gcc +CFLAGS = -g -Wall -Werror -nostdlib -fno-strict-aliasing -O2 +CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls +CFLAGS += -mno-save-restore -mstrict-align +CFLAGS += $(GENFLAGS) +CFLAGS += $(platform-cflags-y) +CFLAGS += $(firmware-cflags-y) + +CPP ?= $(CROSS_COMPILE)cpp +CPPFLAGS += $(GENFLAGS) +CPPFLAGS += $(platform-cppflags-y) +CPPFLAGS += $(firmware-cppflags-y) + +AS = $(CC) +ASFLAGS = -g -Wall -nostdlib -D__ASSEMBLY__ +ASFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls +ASFLAGS += -mno-save-restore -mstrict-align +ASFLAGS += $(GENFLAGS) +ASFLAGS += $(platform-asflags-y) +ASFLAGS += $(firmware-asflags-y) + +AR ?= $(CROSS_COMPILE)ar +ARFLAGS = rcs + +LD ?= $(CROSS_COMPILE)ld +LDFLAGS += -g -Wall -nostdlib -Wl,--build-id=none -N +LDFLAGS += $(platform-ldflags-y) +LDFLAGS += $(firmware-ldflags-y) + +MERGEFLAGS += -r + +OBJCOPY ?= $(CROSS_COMPILE)objcopy # Setup functions for compilation define dynamic_flags @@ -136,7 +139,7 @@ define dynamic_flags endef merge_objs = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " MERGE $(subst $(build_dir)/,,$(1))"; \ - $(merge) $(mergeflags) $(2) -o $(1) + $(LD) $(MERGEFLAGS) $(2) -o $(1) merge_deps = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " MERGE-DEP $(subst $(build_dir)/,,$(1))"; \ cat $(2) > $(1) @@ -162,32 +165,32 @@ inst_header_dir = $(CMD_PREFIX)mkdir -p $(1); \ cp -rf $(2) $(1) compile_cpp = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " CPP $(subst $(build_dir)/,,$(1))"; \ - $(cpp) $(cppflags) $(2) | grep -v "\#" > $(1) + $(CPP) $(CPPFLAGS) $(2) | grep -v "\#" > $(1) compile_cc_dep = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " CC-DEP $(subst $(build_dir)/,,$(1))"; \ echo -n `dirname $(1)`/ > $(1) && \ - $(cc) $(cflags) $(call dynamic_flags,$(1),$(2)) \ + $(CC) $(CFLAGS) $(call dynamic_flags,$(1),$(2)) \ -MM $(2) >> $(1) || rm -f $(1) compile_cc = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " CC $(subst $(build_dir)/,,$(1))"; \ - $(cc) $(cflags) $(call dynamic_flags,$(1),$(2)) -c $(2) -o $(1) + $(CC) $(CFLAGS) $(call dynamic_flags,$(1),$(2)) -c $(2) -o $(1) compile_as_dep = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " AS-DEP $(subst $(build_dir)/,,$(1))"; \ echo -n `dirname $(1)`/ > $(1) && \ - $(as) $(asflags) $(call dynamic_flags,$(1),$(2)) \ + $(AS) $(ASFLAGS) $(call dynamic_flags,$(1),$(2)) \ -MM $(2) >> $(1) || rm -f $(1) compile_as = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " AS $(subst $(build_dir)/,,$(1))"; \ - $(as) $(asflags) $(call dynamic_flags,$(1),$(2)) -c $(2) -o $(1) + $(AS) $(ASFLAGS) $(call dynamic_flags,$(1),$(2)) -c $(2) -o $(1) compile_ld = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " LD $(subst $(build_dir)/,,$(1))"; \ - $(ld) $(3) $(ldflags) -Wl,-T$(2) -o $(1) + $(CC) $(3) $(LDFLAGS) -Wl,-T$(2) -o $(1) compile_ar = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " AR $(subst $(build_dir)/,,$(1))"; \ - $(ar) $(arflags) $(1) $(2) + $(AR) $(ARFLAGS) $(1) $(2) compile_objcopy = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " OBJCOPY $(subst $(build_dir)/,,$(1))"; \ - $(objcopy) -S -O binary $(2) $(1) + $(OBJCOPY) -S -O binary $(2) $(1) targets-y = $(build_dir)/lib/libsbi.a ifdef PLATFORM From 5cbc24b95a541dba3f2b842b54d76435ba4566a7 Mon Sep 17 00:00:00 2001 From: Alistair Francis Date: Wed, 2 Jan 2019 13:59:49 -0800 Subject: [PATCH 0074/1765] Makefile: Force GCC to preprocess the linker file To avoid this message (and subsequent errors): warning: linker input file unused because linking not done force GCC to treat the linker script preprocessing as a C file. Signed-off-by: Alistair Francis --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index fd3ed44354a..139ca460b2c 100644 --- a/Makefile +++ b/Makefile @@ -165,7 +165,7 @@ inst_header_dir = $(CMD_PREFIX)mkdir -p $(1); \ cp -rf $(2) $(1) compile_cpp = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " CPP $(subst $(build_dir)/,,$(1))"; \ - $(CPP) $(CPPFLAGS) $(2) | grep -v "\#" > $(1) + $(CPP) $(CPPFLAGS) -x c $(2) | grep -v "\#" > $(1) compile_cc_dep = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " CC-DEP $(subst $(build_dir)/,,$(1))"; \ echo -n `dirname $(1)`/ > $(1) && \ From 45c9e14a2f329950645fa7eb30306913650642d8 Mon Sep 17 00:00:00 2001 From: Alistair Francis Date: Wed, 2 Jan 2019 14:44:35 -0800 Subject: [PATCH 0075/1765] docs: Add a contributing document Signed-off-by: Alistair Francis --- docs/contributing.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 docs/contributing.md diff --git a/docs/contributing.md b/docs/contributing.md new file mode 100644 index 00000000000..46a0ad9737e --- /dev/null +++ b/docs/contributing.md @@ -0,0 +1,13 @@ +Contrubuting to OpenSBI +======================== + +All contributions to OpenSBI should be sent as GitHub Pull Requests (PRs) to the main repo avaliable at: https://github.com/riscv/opensbi + +As well as that all work must follow the following rules: +1. We follow the [Linux coding style](https://www.kernel.org/doc/html/v4.10/process/coding-style.html). This means that ALL patches must include the Signed-off-by line. +2. Commit subject must have atleast one ":" prefix. Common ones are "lib:", "platform:", "firmware:", "docs:" and "top:". +3. Maintainer should prefer "Rebase and Merge" when using GitHub to merge pull requests. Avoid create extra merge commits. +4. Maintainer should avoid creating branches directly in main riscv/opensbi repo. Instead prefer fork of GitHub riscv/opensbi repo and create branches in your own fork for pull requests. +5. Maintainer cannot merge his own pull requests on GitHub. +6. A pull request must get atleast one review from relevant maintainer. +7. A pull request must spend atleast 24 hours in review so that everyone gets a chance to review. From 2e5ede82796960435fff80b27b21dfb399d2e2fb Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 4 Jan 2019 08:45:36 +0530 Subject: [PATCH 0076/1765] Makefile: Use '=' instead of '?=' for make variables The '?=' will not assign value if the target make variable is overriden via command-line or is set in environment variable. On other hand, '=' will not assign value only if variable is overriden via command-line parameter. It is quite common to have CC, AS, CPP, LD, etc to be set as environment variables pointing to native compiler and binutils. If '-rR' option is not set in MAKEFLAGS then this results in compile error because '?=' will use the native compiler and binutils. If '-rR' option is set in MAKEFLAGS then this again results in compile error because CC, AS, CPP, etc are set to empty strings which causes '?=' to use empty string as compiler and binutils. To handle this, we use '?=' only when CROSS_COMPILE is not defined and we use '=' when CROSS_COMPILE is defined. Signed-off-by: Anup Patel --- Makefile | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 139ca460b2c..5c7d4fb4d8d 100644 --- a/Makefile +++ b/Makefile @@ -100,7 +100,11 @@ GENFLAGS += $(platform-genflags-y) GENFLAGS += $(firmware-genflags-y) # Setup compilation environment -CC ?= $(CROSS_COMPILE)gcc +ifdef CROSS_COMPILE +CC = $(CROSS_COMPILE)gcc +else +CC ?= gcc +endif CFLAGS = -g -Wall -Werror -nostdlib -fno-strict-aliasing -O2 CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls CFLAGS += -mno-save-restore -mstrict-align @@ -108,12 +112,16 @@ CFLAGS += $(GENFLAGS) CFLAGS += $(platform-cflags-y) CFLAGS += $(firmware-cflags-y) -CPP ?= $(CROSS_COMPILE)cpp +ifdef CROSS_COMPILE +CPP = $(CROSS_COMPILE)cpp +else +CPP ?= cpp +endif CPPFLAGS += $(GENFLAGS) CPPFLAGS += $(platform-cppflags-y) CPPFLAGS += $(firmware-cppflags-y) -AS = $(CC) +AS = $(CC) ASFLAGS = -g -Wall -nostdlib -D__ASSEMBLY__ ASFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls ASFLAGS += -mno-save-restore -mstrict-align @@ -121,17 +129,29 @@ ASFLAGS += $(GENFLAGS) ASFLAGS += $(platform-asflags-y) ASFLAGS += $(firmware-asflags-y) -AR ?= $(CROSS_COMPILE)ar +ifdef CROSS_COMPILE +AR = $(CROSS_COMPILE)ar +else +AR ?= ar +endif ARFLAGS = rcs -LD ?= $(CROSS_COMPILE)ld +ifdef CROSS_COMPILE +LD = $(CROSS_COMPILE)ld +else +LD ?= ld +endif LDFLAGS += -g -Wall -nostdlib -Wl,--build-id=none -N LDFLAGS += $(platform-ldflags-y) LDFLAGS += $(firmware-ldflags-y) MERGEFLAGS += -r -OBJCOPY ?= $(CROSS_COMPILE)objcopy +ifdef CROSS_COMPILE +OBJCOPY = $(CROSS_COMPILE)objcopy +else +OBJCOPY ?= objcopy +endif # Setup functions for compilation define dynamic_flags From c2e0b0291475a49f6c923ee7fda864fb2c3c2c6d Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Mon, 14 Jan 2019 12:25:01 +0530 Subject: [PATCH 0077/1765] Makefile: Add make targets to build and install documentation This patch extends top-level makefile to build and install documentation. The 'docs' make target is for building the documentation PDF whereas 'install_docs' make target is for installing the documentation PDF. Signed-off-by: Anup Patel --- Makefile | 17 + docs/doxygen.cfg | 2458 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 2475 insertions(+) create mode 100644 docs/doxygen.cfg diff --git a/Makefile b/Makefile index 5c7d4fb4d8d..f622c812f77 100644 --- a/Makefile +++ b/Makefile @@ -264,6 +264,19 @@ $(build_dir)/$(platform_subdir)/%.dep: $(src_dir)/%.S $(build_dir)/$(platform_subdir)/%.o: $(src_dir)/%.S $(call compile_as,$@,$<) +# Rule for "make docs" +$(build_dir)/docs/latex/refman.pdf: $(build_dir)/docs/latex/refman.tex + $(CMD_PREFIX)mkdir -p $(build_dir)/docs + $(CMD_PREFIX)$(MAKE) -C $(build_dir)/docs/latex +$(build_dir)/docs/latex/refman.tex: $(build_dir)/docs/doxygen.cfg + $(CMD_PREFIX)mkdir -p $(build_dir)/docs + $(CMD_PREFIX)doxygen $(build_dir)/docs/doxygen.cfg +$(build_dir)/docs/doxygen.cfg: $(src_dir)/docs/doxygen.cfg + $(CMD_PREFIX)mkdir -p $(build_dir)/docs + $(CMD_PREFIX)cat docs/doxygen.cfg | sed -e "s#@@SRC_DIR@@#$(src_dir)#" -e "s#@@BUILD_DIR@@#$(build_dir)#" > $(build_dir)/docs/doxygen.cfg +.PHONY: docs +docs: $(build_dir)/docs/latex/refman.pdf + # Dependency files should only be included after default Makefile rules # They should not be included for any "xxxconfig" or "xxxclean" rule all-deps-1 = $(if $(findstring config,$(MAKECMDGOALS)),,$(deps-y)) @@ -298,6 +311,10 @@ install_firmwares: $(build_dir)/$(platform_subdir)/lib/libplatsbi.a $(build_dir) $(call inst_file_list,$(install_dir),$(build_dir),$(platform_subdir)/firmware,$(firmware-elfs-path-y)) $(call inst_file_list,$(install_dir),$(build_dir),$(platform_subdir)/firmware,$(firmware-bins-path-y)) +.PHONY: install_docs +install_docs: $(build_dir)/docs/latex/refman.pdf + $(call inst_file,$(install_dir)/docs/refman.pdf,$(build_dir)/docs/latex/refman.pdf) + # Rule for "make clean" .PHONY: clean clean: diff --git a/docs/doxygen.cfg b/docs/doxygen.cfg new file mode 100644 index 00000000000..344b0851f80 --- /dev/null +++ b/docs/doxygen.cfg @@ -0,0 +1,2458 @@ +# Doxyfile 1.8.13 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project. +# +# All text after a double hash (##) is considered a comment and is placed in +# front of the TAG it is preceding. +# +# All text after a single hash (#) is considered a comment and will be ignored. +# The format is: +# TAG = value [value, ...] +# For lists, items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (\" \"). + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the config file +# that follow. The default is UTF-8 which is also the encoding used for all text +# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv +# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv +# for the list of possible encodings. +# The default value is: UTF-8. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by +# double-quotes, unless you are using Doxywizard) that should identify the +# project for which the documentation is generated. This name is used in the +# title of most generated pages and in a few other places. +# The default value is: My Project. + +PROJECT_NAME = "RISC-V OpenSBI" + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. This +# could be handy for archiving the generated documentation or if some version +# control system is used. + +PROJECT_NUMBER = + +# Using the PROJECT_BRIEF tag one can provide an optional one line description +# for a project that appears at the top of each page and should give viewer a +# quick idea about the purpose of the project. Keep the description short. + +PROJECT_BRIEF = "Open source implemenation of supervisor binary interface" + +# With the PROJECT_LOGO tag one can specify a logo or an icon that is included +# in the documentation. The maximum height of the logo should not exceed 55 +# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy +# the logo to the output directory. + +PROJECT_LOGO = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path +# into which the generated documentation will be written. If a relative path is +# entered, it will be relative to the location where doxygen was started. If +# left blank the current directory will be used. + +OUTPUT_DIRECTORY = @@BUILD_DIR@@/docs + +# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- +# directories (in 2 levels) under the output directory of each output format and +# will distribute the generated files over these directories. Enabling this +# option can be useful when feeding doxygen a huge amount of source files, where +# putting all generated files in the same directory would otherwise causes +# performance problems for the file system. +# The default value is: NO. + +CREATE_SUBDIRS = NO + +# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII +# characters to appear in the names of generated files. If set to NO, non-ASCII +# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode +# U+3044. +# The default value is: NO. + +ALLOW_UNICODE_NAMES = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, +# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), +# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, +# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), +# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, +# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, +# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, +# Ukrainian and Vietnamese. +# The default value is: English. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member +# descriptions after the members that are listed in the file and class +# documentation (similar to Javadoc). Set to NO to disable this. +# The default value is: YES. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief +# description of a member or function before the detailed description +# +# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. +# The default value is: YES. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator that is +# used to form the text in various listings. Each string in this list, if found +# as the leading text of the brief description, will be stripped from the text +# and the result, after processing the whole list, is used as the annotated +# text. Otherwise, the brief description is used as-is. If left blank, the +# following values are used ($name is automatically replaced with the name of +# the entity):The $name class, The $name widget, The $name file, is, provides, +# specifies, contains, represents, a, an and the. + +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# doxygen will generate a detailed section even if there is only a brief +# description. +# The default value is: NO. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. +# The default value is: NO. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path +# before files name in the file list and in the header files. If set to NO the +# shortest path that makes the file name unique will be used +# The default value is: YES. + +FULL_PATH_NAMES = YES + +# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. +# Stripping is only done if one of the specified strings matches the left-hand +# part of the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the path to +# strip. +# +# Note that you can specify absolute paths here, but also relative paths, which +# will be relative from the directory where doxygen is started. +# This tag requires that the tag FULL_PATH_NAMES is set to YES. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the +# path mentioned in the documentation of a class, which tells the reader which +# header file to include in order to use a class. If left blank only the name of +# the header file containing the class definition is used. Otherwise one should +# specify the list of include paths that are normally passed to the compiler +# using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but +# less readable) file names. This can be useful is your file systems doesn't +# support long names like on DOS, Mac, or CD-ROM. +# The default value is: NO. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the +# first line (until the first dot) of a Javadoc-style comment as the brief +# description. If set to NO, the Javadoc-style will behave just like regular Qt- +# style comments (thus requiring an explicit @brief command for a brief +# description.) +# The default value is: NO. + +JAVADOC_AUTOBRIEF = NO + +# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first +# line (until the first dot) of a Qt-style comment as the brief description. If +# set to NO, the Qt-style will behave just like regular Qt-style comments (thus +# requiring an explicit \brief command for a brief description.) +# The default value is: NO. + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a +# multi-line C++ special comment block (i.e. a block of //! or /// comments) as +# a brief description. This used to be the default behavior. The new default is +# to treat a multi-line C++ comment block as a detailed description. Set this +# tag to YES if you prefer the old behavior instead. +# +# Note that setting this tag to YES also means that rational rose comments are +# not recognized any more. +# The default value is: NO. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the +# documentation from any documented member that it re-implements. +# The default value is: YES. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new +# page for each member. If set to NO, the documentation of a member will be part +# of the file/class/namespace that contains it. +# The default value is: NO. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen +# uses this value to replace tabs by spaces in code fragments. +# Minimum value: 1, maximum value: 16, default value: 4. + +TAB_SIZE = 4 + +# This tag can be used to specify a number of aliases that act as commands in +# the documentation. An alias has the form: +# name=value +# For example adding +# "sideeffect=@par Side Effects:\n" +# will allow you to put the command \sideeffect (or @sideeffect) in the +# documentation, which will result in a user-defined paragraph with heading +# "Side Effects:". You can put \n's in the value part of an alias to insert +# newlines. + +ALIASES = + +# This tag can be used to specify a number of word-keyword mappings (TCL only). +# A mapping has the form "name=value". For example adding "class=itcl::class" +# will allow you to use the command class in the itcl::class meaning. + +TCL_SUBST = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources +# only. Doxygen will then generate output that is more tailored for C. For +# instance, some of the names that are used will be different. The list of all +# members will be omitted, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or +# Python sources only. Doxygen will then generate output that is more tailored +# for that language. For instance, namespaces will be presented as packages, +# qualified scopes will look different, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources. Doxygen will then generate output that is tailored for Fortran. +# The default value is: NO. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for VHDL. +# The default value is: NO. + +OPTIMIZE_OUTPUT_VHDL = NO + +# Doxygen selects the parser to use depending on the extension of the files it +# parses. With this tag you can assign which parser to use for a given +# extension. Doxygen has a built-in mapping, but you can override or extend it +# using this tag. The format is ext=language, where ext is a file extension, and +# language is one of the parsers supported by doxygen: IDL, Java, Javascript, +# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran: +# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran: +# Fortran. In the later case the parser tries to guess whether the code is fixed +# or free formatted code, this is the default for Fortran type files), VHDL. For +# instance to make doxygen treat .inc files as Fortran files (default is PHP), +# and .f files as C (default is Fortran), use: inc=Fortran f=C. +# +# Note: For files without extension you can use no_extension as a placeholder. +# +# Note that for custom extensions you also need to set FILE_PATTERNS otherwise +# the files are not read by doxygen. + +EXTENSION_MAPPING = + +# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments +# according to the Markdown format, which allows for more readable +# documentation. See http://daringfireball.net/projects/markdown/ for details. +# The output of markdown processing is further processed by doxygen, so you can +# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in +# case of backward compatibilities issues. +# The default value is: YES. + +MARKDOWN_SUPPORT = YES + +# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up +# to that level are automatically included in the table of contents, even if +# they do not have an id attribute. +# Note: This feature currently applies only to Markdown headings. +# Minimum value: 0, maximum value: 99, default value: 0. +# This tag requires that the tag MARKDOWN_SUPPORT is set to YES. + +TOC_INCLUDE_HEADINGS = 0 + +# When enabled doxygen tries to link words that correspond to documented +# classes, or namespaces to their corresponding documentation. Such a link can +# be prevented in individual cases by putting a % sign in front of the word or +# globally by setting AUTOLINK_SUPPORT to NO. +# The default value is: YES. + +AUTOLINK_SUPPORT = YES + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should set this +# tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); +# versus func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. +# The default value is: NO. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. +# The default value is: NO. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: +# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen +# will parse them like normal C++ but will assume all classes use public instead +# of private inheritance when no explicit protection keyword is present. +# The default value is: NO. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate +# getter and setter methods for a property. Setting this option to YES will make +# doxygen to replace the get and set methods by a property in the documentation. +# This will only work if the methods are indeed getting or setting a simple +# type. If this is not the case, or you want to show the methods anyway, you +# should set this option to NO. +# The default value is: YES. + +IDL_PROPERTY_SUPPORT = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. +# The default value is: NO. + +DISTRIBUTE_GROUP_DOC = NO + +# If one adds a struct or class to a group and this option is enabled, then also +# any nested class or struct is added to the same group. By default this option +# is disabled and one has to add nested compounds explicitly via \ingroup. +# The default value is: NO. + +GROUP_NESTED_COMPOUNDS = NO + +# Set the SUBGROUPING tag to YES to allow class member groups of the same type +# (for instance a group of public functions) to be put as a subgroup of that +# type (e.g. under the Public Functions section). Set it to NO to prevent +# subgrouping. Alternatively, this can be done per class using the +# \nosubgrouping command. +# The default value is: YES. + +SUBGROUPING = YES + +# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions +# are shown inside the group in which they are included (e.g. using \ingroup) +# instead of on a separate page (for HTML and Man pages) or section (for LaTeX +# and RTF). +# +# Note that this feature does not work in combination with +# SEPARATE_MEMBER_PAGES. +# The default value is: NO. + +INLINE_GROUPED_CLASSES = NO + +# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions +# with only public data fields or simple typedef fields will be shown inline in +# the documentation of the scope in which they are defined (i.e. file, +# namespace, or group documentation), provided this scope is documented. If set +# to NO, structs, classes, and unions are shown on a separate page (for HTML and +# Man pages) or section (for LaTeX and RTF). +# The default value is: NO. + +INLINE_SIMPLE_STRUCTS = NO + +# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or +# enum is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically be +# useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. +# The default value is: NO. + +TYPEDEF_HIDES_STRUCT = NO + +# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This +# cache is used to resolve symbols given their name and scope. Since this can be +# an expensive process and often the same symbol appears multiple times in the +# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small +# doxygen will become slower. If the cache is too large, memory is wasted. The +# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range +# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 +# symbols. At the end of a run doxygen will report the cache usage and suggest +# the optimal cache size from a speed point of view. +# Minimum value: 0, maximum value: 9, default value: 0. + +LOOKUP_CACHE_SIZE = 0 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in +# documentation are documented, even if no documentation was available. Private +# class members and static file members will be hidden unless the +# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. +# Note: This will also disable the warnings about undocumented members that are +# normally produced when WARNINGS is set to YES. +# The default value is: NO. + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will +# be included in the documentation. +# The default value is: NO. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal +# scope will be included in the documentation. +# The default value is: NO. + +EXTRACT_PACKAGE = NO + +# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be +# included in the documentation. +# The default value is: NO. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined +# locally in source files will be included in the documentation. If set to NO, +# only classes defined in header files are included. Does not have any effect +# for Java sources. +# The default value is: YES. + +EXTRACT_LOCAL_CLASSES = NO + +# This flag is only useful for Objective-C code. If set to YES, local methods, +# which are defined in the implementation section but not in the interface are +# included in the documentation. If set to NO, only methods in the interface are +# included. +# The default value is: NO. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base name of +# the file that contains the anonymous namespace. By default anonymous namespace +# are hidden. +# The default value is: NO. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all +# undocumented members inside documented classes or files. If set to NO these +# members will be included in the various overviews, but no documentation +# section is generated. This option has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. If set +# to NO, these classes will be included in the various overviews. This option +# has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_CLASSES = YES + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend +# (class|struct|union) declarations. If set to NO, these declarations will be +# included in the documentation. +# The default value is: NO. + +HIDE_FRIEND_COMPOUNDS = YES + +# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any +# documentation blocks found inside the body of a function. If set to NO, these +# blocks will be appended to the function's detailed documentation block. +# The default value is: NO. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation that is typed after a +# \internal command is included. If the tag is set to NO then the documentation +# will be excluded. Set it to YES to include the internal documentation. +# The default value is: NO. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file +# names in lower-case letters. If set to YES, upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. +# The default value is: system dependent. + +CASE_SENSE_NAMES = NO + +# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with +# their full class and namespace scopes in the documentation. If set to YES, the +# scope will be hidden. +# The default value is: NO. + +HIDE_SCOPE_NAMES = NO + +# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will +# append additional text to a page's title, such as Class Reference. If set to +# YES the compound reference will be hidden. +# The default value is: NO. + +HIDE_COMPOUND_REFERENCE= NO + +# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of +# the files that are included by a file in the documentation of that file. +# The default value is: YES. + +SHOW_INCLUDE_FILES = YES + +# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each +# grouped member an include statement to the documentation, telling the reader +# which file to include in order to use the member. +# The default value is: NO. + +SHOW_GROUPED_MEMB_INC = NO + +# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include +# files with double quotes in the documentation rather than with sharp brackets. +# The default value is: NO. + +FORCE_LOCAL_INCLUDES = NO + +# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the +# documentation for inline members. +# The default value is: YES. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the +# (detailed) documentation of file and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. +# The default value is: YES. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief +# descriptions of file, namespace and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. Note that +# this will also influence the order of the classes in the class list. +# The default value is: NO. + +SORT_BRIEF_DOCS = NO + +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the +# (brief and detailed) documentation of class members so that constructors and +# destructors are listed first. If set to NO the constructors will appear in the +# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. +# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief +# member documentation. +# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting +# detailed member documentation. +# The default value is: NO. + +SORT_MEMBERS_CTORS_1ST = NO + +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy +# of group names into alphabetical order. If set to NO the group names will +# appear in their defined order. +# The default value is: NO. + +SORT_GROUP_NAMES = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by +# fully-qualified names, including namespaces. If set to NO, the class list will +# be sorted only by class name, not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the alphabetical +# list. +# The default value is: NO. + +SORT_BY_SCOPE_NAME = NO + +# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper +# type resolution of all parameters of a function it will reject a match between +# the prototype and the implementation of a member function even if there is +# only one candidate or it is obvious which candidate to choose by doing a +# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still +# accept a match between prototype and implementation in such cases. +# The default value is: NO. + +STRICT_PROTO_MATCHING = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo +# list. This list is created by putting \todo commands in the documentation. +# The default value is: YES. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test +# list. This list is created by putting \test commands in the documentation. +# The default value is: YES. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug +# list. This list is created by putting \bug commands in the documentation. +# The default value is: YES. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) +# the deprecated list. This list is created by putting \deprecated commands in +# the documentation. +# The default value is: YES. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional documentation +# sections, marked by \if ... \endif and \cond +# ... \endcond blocks. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the +# initial value of a variable or macro / define can have for it to appear in the +# documentation. If the initializer consists of more lines than specified here +# it will be hidden. Use a value of 0 to hide initializers completely. The +# appearance of the value of individual variables and macros / defines can be +# controlled using \showinitializer or \hideinitializer command in the +# documentation regardless of this setting. +# Minimum value: 0, maximum value: 10000, default value: 30. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at +# the bottom of the documentation of classes and structs. If set to YES, the +# list will mention the files that were used to generate the documentation. +# The default value is: YES. + +SHOW_USED_FILES = YES + +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This +# will remove the Files entry from the Quick Index and from the Folder Tree View +# (if specified). +# The default value is: YES. + +SHOW_FILES = YES + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces +# page. This will remove the Namespaces entry from the Quick Index and from the +# Folder Tree View (if specified). +# The default value is: YES. + +SHOW_NAMESPACES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command command input-file, where command is the value of the +# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided +# by doxygen. Whatever the program writes to standard output is used as the file +# version. For an example see the documentation. + +FILE_VERSION_FILTER = + +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed +# by doxygen. The layout file controls the global structure of the generated +# output files in an output format independent way. To create the layout file +# that represents doxygen's defaults, run doxygen with the -l option. You can +# optionally specify a file name after the option, if omitted DoxygenLayout.xml +# will be used as the name of the layout file. +# +# Note that if you run doxygen from a directory containing a file called +# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE +# tag is left empty. + +LAYOUT_FILE = + +# The CITE_BIB_FILES tag can be used to specify one or more bib files containing +# the reference definitions. This must be a list of .bib files. The .bib +# extension is automatically appended if omitted. This requires the bibtex tool +# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. +# For LaTeX the style of the bibliography can be controlled using +# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the +# search path. See also \cite for info how to create references. + +CITE_BIB_FILES = + +#--------------------------------------------------------------------------- +# Configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated to +# standard output by doxygen. If QUIET is set to YES this implies that the +# messages are off. +# The default value is: NO. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES +# this implies that the warnings are on. +# +# Tip: Turn warnings on while writing the documentation. +# The default value is: YES. + +WARNINGS = YES + +# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate +# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag +# will automatically be disabled. +# The default value is: YES. + +WARN_IF_UNDOCUMENTED = YES + +# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some parameters +# in a documented function, or documenting parameters that don't exist or using +# markup commands wrongly. +# The default value is: YES. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that +# are documented, but have no documentation for their parameters or return +# value. If set to NO, doxygen will only warn about wrong or incomplete +# parameter documentation, but not about the absence of documentation. +# The default value is: NO. + +WARN_NO_PARAMDOC = NO + +# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when +# a warning is encountered. +# The default value is: NO. + +WARN_AS_ERROR = NO + +# The WARN_FORMAT tag determines the format of the warning messages that doxygen +# can produce. The string should contain the $file, $line, and $text tags, which +# will be replaced by the file and line number from which the warning originated +# and the warning text. Optionally the format may contain $version, which will +# be replaced by the version of the file (if it could be obtained via +# FILE_VERSION_FILTER) +# The default value is: $file:$line: $text. + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning and error +# messages should be written. If left blank the output is written to standard +# error (stderr). + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# Configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag is used to specify the files and/or directories that contain +# documented source files. You may enter file names like myfile.cpp or +# directories like /usr/src/myproject. Separate the files or directories with +# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING +# Note: If this tag is empty the current directory is searched. + +INPUT = @@SRC_DIR@@/README.md \ + @@SRC_DIR@@/docs/contributing.md \ + @@SRC_DIR@@/docs/firmware \ + @@SRC_DIR@@/docs/platform \ + @@SRC_DIR@@/include \ + @@SRC_DIR@@/lib + +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses +# libiconv (or the iconv built into libc) for the transcoding. See the libiconv +# documentation (see: http://www.gnu.org/software/libiconv) for the list of +# possible encodings. +# The default value is: UTF-8. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and +# *.h) to filter out the source-files in the directories. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# read by doxygen. +# +# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp, +# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, +# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, +# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, +# *.f, *.for, *.tcl, *.vhd, *.vhdl, *.ucf and *.qsf. + +FILE_PATTERNS = *.c \ + *.h \ + *.md + +# The RECURSIVE tag can be used to specify whether or not subdirectories should +# be searched for input files as well. +# The default value is: NO. + +RECURSIVE = YES + +# The EXCLUDE tag can be used to specify files and/or directories that should be +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. +# +# Note that relative paths are relative to the directory from which doxygen is +# run. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or +# directories that are symbolic links (a Unix file system feature) are excluded +# from the input. +# The default value is: NO. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# AClass::ANamespace, ANamespace::*Test +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories use the pattern */test/* + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or directories +# that contain example code fragments that are included (see the \include +# command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and +# *.h) to filter out the source-files in the directories. If left blank all +# files are included. + +EXAMPLE_PATTERNS = * + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude commands +# irrespective of the value of the RECURSIVE tag. +# The default value is: NO. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or directories +# that contain images that are to be included in the documentation (see the +# \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command: +# +# +# +# where is the value of the INPUT_FILTER tag, and is the +# name of an input file. Doxygen will then use the output that the filter +# program writes to standard output. If FILTER_PATTERNS is specified, this tag +# will be ignored. +# +# Note that the filter must not add or remove lines; it is applied before the +# code is scanned, but not when the output code is generated. If lines are added +# or removed, the anchors will not be placed correctly. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by doxygen. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: pattern=filter +# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how +# filters are used. If the FILTER_PATTERNS tag is empty or if none of the +# patterns match the file name, INPUT_FILTER is applied. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by doxygen. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will also be used to filter the input files that are used for +# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). +# The default value is: NO. + +FILTER_SOURCE_FILES = NO + +# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file +# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and +# it is also possible to disable source filtering for a specific pattern using +# *.ext= (so without naming a filter). +# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. + +FILTER_SOURCE_PATTERNS = + +# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that +# is part of the input, its contents will be placed on the main page +# (index.html). This can be useful if you have a project on for instance GitHub +# and want to reuse the introduction page also for the doxygen output. + +USE_MDFILE_AS_MAINPAGE = + +#--------------------------------------------------------------------------- +# Configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will be +# generated. Documented entities will be cross-referenced with these sources. +# +# Note: To get rid of all source code in the generated output, make sure that +# also VERBATIM_HEADERS is set to NO. +# The default value is: NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body of functions, +# classes and enums directly into the documentation. +# The default value is: NO. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any +# special comment blocks from generated source code fragments. Normal C, C++ and +# Fortran comments will always remain visible. +# The default value is: YES. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES then for each documented +# function all documented functions referencing it will be listed. +# The default value is: NO. + +REFERENCED_BY_RELATION = NO + +# If the REFERENCES_RELATION tag is set to YES then for each documented function +# all documented entities called/used by that function will be listed. +# The default value is: NO. + +REFERENCES_RELATION = NO + +# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set +# to YES then the hyperlinks from functions in REFERENCES_RELATION and +# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will +# link to the documentation. +# The default value is: YES. + +REFERENCES_LINK_SOURCE = YES + +# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the +# source code will show a tooltip with additional information such as prototype, +# brief description and links to the definition and documentation. Since this +# will make the HTML file larger and loading of large files a bit slower, you +# can opt to disable this feature. +# The default value is: YES. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +SOURCE_TOOLTIPS = YES + +# If the USE_HTAGS tag is set to YES then the references to source code will +# point to the HTML generated by the htags(1) tool instead of doxygen built-in +# source browser. The htags tool is part of GNU's global source tagging system +# (see http://www.gnu.org/software/global/global.html). You will need version +# 4.8.6 or higher. +# +# To use it do the following: +# - Install the latest version of global +# - Enable SOURCE_BROWSER and USE_HTAGS in the config file +# - Make sure the INPUT points to the root of the source tree +# - Run doxygen as normal +# +# Doxygen will invoke htags (and that will in turn invoke gtags), so these +# tools must be available from the command line (i.e. in the search path). +# +# The result: instead of the source browser generated by doxygen, the links to +# source code will now point to the output of htags. +# The default value is: NO. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a +# verbatim copy of the header file for each class for which an include is +# specified. Set to NO to disable this. +# See also: Section \class. +# The default value is: YES. + +VERBATIM_HEADERS = YES + +# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the +# clang parser (see: http://clang.llvm.org/) for more accurate parsing at the +# cost of reduced performance. This can be particularly helpful with template +# rich C++ code for which doxygen's built-in parser lacks the necessary type +# information. +# Note: The availability of this option depends on whether or not doxygen was +# generated with the -Duse-libclang=ON option for CMake. +# The default value is: NO. + +CLANG_ASSISTED_PARSING = NO + +# If clang assisted parsing is enabled you can provide the compiler with command +# line options that you would normally use when invoking the compiler. Note that +# the include paths will already be set by doxygen for the files and directories +# specified with INPUT and INCLUDE_PATH. +# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. + +CLANG_OPTIONS = + +#--------------------------------------------------------------------------- +# Configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all +# compounds will be generated. Enable this if the project contains a lot of +# classes, structs, unions or interfaces. +# The default value is: YES. + +ALPHABETICAL_INDEX = YES + +# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in +# which the alphabetical index list will be split. +# Minimum value: 1, maximum value: 20, default value: 5. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all classes will +# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag +# can be used to specify a prefix (or a list of prefixes) that should be ignored +# while generating the index headers. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output +# The default value is: YES. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each +# generated HTML page (for example: .htm, .php, .asp). +# The default value is: .html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a user-defined HTML header file for +# each generated HTML page. If the tag is left blank doxygen will generate a +# standard header. +# +# To get valid HTML the header file that includes any scripts and style sheets +# that doxygen needs, which is dependent on the configuration options used (e.g. +# the setting GENERATE_TREEVIEW). It is highly recommended to start with a +# default header using +# doxygen -w html new_header.html new_footer.html new_stylesheet.css +# YourConfigFile +# and then modify the file new_header.html. See also section "Doxygen usage" +# for information on how to generate the default header that doxygen normally +# uses. +# Note: The header is subject to change so you typically have to regenerate the +# default header when upgrading to a newer version of doxygen. For a description +# of the possible markers and block names see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each +# generated HTML page. If the tag is left blank doxygen will generate a standard +# footer. See HTML_HEADER for more information on how to generate a default +# footer and what special commands can be used inside the footer. See also +# section "Doxygen usage" for information on how to generate the default footer +# that doxygen normally uses. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style +# sheet that is used by each HTML page. It can be used to fine-tune the look of +# the HTML output. If left blank doxygen will generate a default style sheet. +# See also section "Doxygen usage" for information on how to generate the style +# sheet that doxygen normally uses. +# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as +# it is more robust and this tag (HTML_STYLESHEET) will in the future become +# obsolete. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_STYLESHEET = + +# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined +# cascading style sheets that are included after the standard style sheets +# created by doxygen. Using this option one can overrule certain style aspects. +# This is preferred over using HTML_STYLESHEET since it does not replace the +# standard style sheet and is therefore more robust against future updates. +# Doxygen will copy the style sheet files to the output directory. +# Note: The order of the extra style sheet files is of importance (e.g. the last +# style sheet in the list overrules the setting of the previous ones in the +# list). For an example see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_STYLESHEET = + +# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the HTML output directory. Note +# that these files will be copied to the base HTML output directory. Use the +# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that the +# files will be copied as-is; there are no commands or markers available. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_FILES = + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen +# will adjust the colors in the style sheet and background images according to +# this color. Hue is specified as an angle on a colorwheel, see +# http://en.wikipedia.org/wiki/Hue for more information. For instance the value +# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 +# purple, and 360 is red again. +# Minimum value: 0, maximum value: 359, default value: 220. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_HUE = 220 + +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors +# in the HTML output. For a value of 0 the output will use grayscales only. A +# value of 255 will produce the most vivid colors. +# Minimum value: 0, maximum value: 255, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_SAT = 100 + +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the +# luminance component of the colors in the HTML output. Values below 100 +# gradually make the output lighter, whereas values above 100 make the output +# darker. The value divided by 100 is the actual gamma applied, so 80 represents +# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not +# change the gamma. +# Minimum value: 40, maximum value: 240, default value: 80. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_GAMMA = 80 + +# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML +# page will contain the date and time when the page was generated. Setting this +# to YES can help to show when doxygen was last run and thus if the +# documentation is up to date. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_TIMESTAMP = NO + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_DYNAMIC_SECTIONS = NO + +# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries +# shown in the various tree structured indices initially; the user can expand +# and collapse entries dynamically later on. Doxygen will expand the tree to +# such a level that at most the specified number of entries are visible (unless +# a fully collapsed tree already exceeds this amount). So setting the number of +# entries 1 will produce a full collapsed tree by default. 0 is a special value +# representing an infinite number of entries and will result in a full expanded +# tree by default. +# Minimum value: 0, maximum value: 9999, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_INDEX_NUM_ENTRIES = 100 + +# If the GENERATE_DOCSET tag is set to YES, additional index files will be +# generated that can be used as input for Apple's Xcode 3 integrated development +# environment (see: http://developer.apple.com/tools/xcode/), introduced with +# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a +# Makefile in the HTML output directory. Running make will produce the docset in +# that directory and running make install will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at +# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html +# for more information. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_DOCSET = NO + +# This tag determines the name of the docset feed. A documentation feed provides +# an umbrella under which multiple documentation sets from a single provider +# (such as a company or product suite) can be grouped. +# The default value is: Doxygen generated docs. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# This tag specifies a string that should uniquely identify the documentation +# set bundle. This should be a reverse domain-name style string, e.g. +# com.mycompany.MyDocSet. Doxygen will append .docset to the name. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify +# the documentation publisher. This should be a reverse domain-name style +# string, e.g. com.mycompany.MyDocSet.documentation. +# The default value is: org.doxygen.Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_ID = org.doxygen.Publisher + +# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. +# The default value is: Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_NAME = Publisher + +# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three +# additional HTML index files: index.hhp, index.hhc, and index.hhk. The +# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop +# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on +# Windows. +# +# The HTML Help Workshop contains a compiler that can convert all HTML output +# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML +# files are now used as the Windows 98 help format, and will replace the old +# Windows help format (.hlp) on all Windows platforms in the future. Compressed +# HTML files also contain an index, a table of contents, and you can search for +# words in the documentation. The HTML workshop also contains a viewer for +# compressed HTML files. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_HTMLHELP = NO + +# The CHM_FILE tag can be used to specify the file name of the resulting .chm +# file. You can add a path in front of the file if the result should not be +# written to the html output directory. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_FILE = + +# The HHC_LOCATION tag can be used to specify the location (absolute path +# including file name) of the HTML help compiler (hhc.exe). If non-empty, +# doxygen will try to run the HTML help compiler on the generated index.hhp. +# The file has to be specified with full path. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +HHC_LOCATION = + +# The GENERATE_CHI flag controls if a separate .chi index file is generated +# (YES) or that it should be included in the master .chm file (NO). +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +GENERATE_CHI = NO + +# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) +# and project file content. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_INDEX_ENCODING = + +# The BINARY_TOC flag controls whether a binary table of contents is generated +# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it +# enables the Previous and Next buttons. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members to +# the table of contents of the HTML help documentation and to the tree view. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +TOC_EXPAND = NO + +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that +# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help +# (.qch) of the generated HTML documentation. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_QHP = NO + +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify +# the file name of the resulting .qch file. The path specified is relative to +# the HTML output folder. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QCH_FILE = + +# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help +# Project output. For more information please see Qt Help Project / Namespace +# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_NAMESPACE = org.doxygen.Project + +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt +# Help Project output. For more information please see Qt Help Project / Virtual +# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- +# folders). +# The default value is: doc. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_VIRTUAL_FOLDER = doc + +# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom +# filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_NAME = + +# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_ATTRS = + +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this +# project's filter section matches. Qt Help Project / Filter Attributes (see: +# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_SECT_FILTER_ATTRS = + +# The QHG_LOCATION tag can be used to specify the location of Qt's +# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the +# generated .qhp file. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHG_LOCATION = + +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be +# generated, together with the HTML files, they form an Eclipse help plugin. To +# install this plugin and make it available under the help contents menu in +# Eclipse, the contents of the directory containing the HTML and XML files needs +# to be copied into the plugins directory of eclipse. The name of the directory +# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. +# After copying Eclipse needs to be restarted before the help appears. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_ECLIPSEHELP = NO + +# A unique identifier for the Eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have this +# name. Each documentation set should have its own identifier. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. + +ECLIPSE_DOC_ID = org.doxygen.Project + +# If you want full control over the layout of the generated HTML pages it might +# be necessary to disable the index and replace it with your own. The +# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top +# of each HTML page. A value of NO enables the index and the value YES disables +# it. Since the tabs in the index contain the same information as the navigation +# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +DISABLE_INDEX = NO + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. If the tag +# value is set to YES, a side panel will be generated containing a tree-like +# index structure (just like the one that is generated for HTML Help). For this +# to work a browser that supports JavaScript, DHTML, CSS and frames is required +# (i.e. any modern browser). Windows users are probably better off using the +# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can +# further fine-tune the look of the index. As an example, the default style +# sheet generated by doxygen has an example that shows how to put an image at +# the root of the tree instead of the PROJECT_NAME. Since the tree basically has +# the same information as the tab index, you could consider setting +# DISABLE_INDEX to YES when enabling this option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_TREEVIEW = NO + +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that +# doxygen will group on one line in the generated HTML documentation. +# +# Note that a value of 0 will completely suppress the enum values from appearing +# in the overview section. +# Minimum value: 0, maximum value: 20, default value: 4. +# This tag requires that the tag GENERATE_HTML is set to YES. + +ENUM_VALUES_PER_LINE = 4 + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used +# to set the initial width (in pixels) of the frame in which the tree is shown. +# Minimum value: 0, maximum value: 1500, default value: 250. +# This tag requires that the tag GENERATE_HTML is set to YES. + +TREEVIEW_WIDTH = 250 + +# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to +# external symbols imported via tag files in a separate window. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +EXT_LINKS_IN_WINDOW = NO + +# Use this tag to change the font size of LaTeX formulas included as images in +# the HTML documentation. When you change the font size after a successful +# doxygen run you need to manually remove any form_*.png images from the HTML +# output directory to force them to be regenerated. +# Minimum value: 8, maximum value: 50, default value: 10. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_FONTSIZE = 10 + +# Use the FORMULA_TRANPARENT tag to determine whether or not the images +# generated for formulas are transparent PNGs. Transparent PNGs are not +# supported properly for IE 6.0, but are supported on all modern browsers. +# +# Note that when changing this option you need to delete any form_*.png files in +# the HTML output directory before the changes have effect. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_TRANSPARENT = YES + +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see +# http://www.mathjax.org) which uses client side Javascript for the rendering +# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX +# installed or if you want to formulas look prettier in the HTML output. When +# enabled you may also need to install MathJax separately and configure the path +# to it using the MATHJAX_RELPATH option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +USE_MATHJAX = NO + +# When MathJax is enabled you can set the default output format to be used for +# the MathJax output. See the MathJax site (see: +# http://docs.mathjax.org/en/latest/output.html) for more details. +# Possible values are: HTML-CSS (which is slower, but has the best +# compatibility), NativeMML (i.e. MathML) and SVG. +# The default value is: HTML-CSS. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_FORMAT = HTML-CSS + +# When MathJax is enabled you need to specify the location relative to the HTML +# output directory using the MATHJAX_RELPATH option. The destination directory +# should contain the MathJax.js script. For instance, if the mathjax directory +# is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax +# Content Delivery Network so you can quickly see the result without installing +# MathJax. However, it is strongly recommended to install a local copy of +# MathJax from http://www.mathjax.org before deployment. +# The default value is: http://cdn.mathjax.org/mathjax/latest. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest + +# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax +# extension names that should be enabled during MathJax rendering. For example +# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_EXTENSIONS = + +# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces +# of code that will be used on startup of the MathJax code. See the MathJax site +# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an +# example see the documentation. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_CODEFILE = + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box for +# the HTML output. The underlying search engine uses javascript and DHTML and +# should work on any modern browser. Note that when using HTML help +# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) +# there is already a search function so this one should typically be disabled. +# For large projects the javascript based search engine can be slow, then +# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to +# search using the keyboard; to jump to the search box use + S +# (what the is depends on the OS and browser, but it is typically +# , /