diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ce91f8d2..7972f545 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,15 +5,15 @@ name: CI on: - push: - branches: - - main - - dev - pull_request: - branches: - - main - - dev - workflow_dispatch: + # push: + # branches: + # - main + # - dev + # pull_request: + # branches: + # - main + # - dev + # workflow_dispatch: env: MODE: debug jobs: @@ -31,7 +31,7 @@ jobs: - name: Install Dependencies run: | sudo apt-get update - sudo apt-get install -y qemu-system-aarch64 qemu-system-riscv64 gdb-multiarch llvm-dev libclang-dev wget + sudo apt-get install -y qemu-system-aarch64 qemu-system-riscv64 gdb-multiarch llvm-dev libclang-dev wget python3-venv cargo install --version 0.3.0 --locked cargo-binutils - name: Format Check run: make fmt-test diff --git a/.gitignore b/.gitignore index d2f81579..087d952d 100644 --- a/.gitignore +++ b/.gitignore @@ -32,10 +32,13 @@ flash.img* .vscode/settings.json compile.sh src/platform/__board.rs -.config +.config* .cursorrules .vscode/extensions.json # systemtest rootfs1.zip* jenkins/__pycache__ -jenkins-cli.jar \ No newline at end of file +jenkins-cli.jar +tools/kconfig/.venv/ +tools/kconfig/__pycache__/ +kernel_build/ \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index c3b5d3a9..66abbcf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,7 +53,7 @@ - [platform] **aarch64**: Improve QEMU GICv2/GICv3 configurations and add zone1-linux support. ([agicy](https://github.com/agicy)) - [platform] **loongarch64**: Add support for Loongson 3A5 / 3A6 platforms and improve clock and trap handling. ([wheatfox](https://github.com/enkerewpo)) - [feature] Add **aarch32** support. ([Guowei Li](https://github.com/KouweiLee)) -- [feature] **riscv64** enhancements: g-stage dynamic detection, eic770x_soc, and syscrg emulation. ([Jingyu Liu](https://github.com/liulog)) +- [feature] **riscv64** enhancements: g-stage dynamic detection, hypervisor_v0_6 (EIC770x SoC), and syscrg emulation. ([Jingyu Liu](https://github.com/liulog)) - [infra] Unify UART / MPIDR mapping, centralize IOMMU configuration, remove redundant arch feature flags, and tidy Cargo/zone/hypercall code. ([Nehckl](https://github.com/Inquisitor-201), [Ren HangQi](https://github.com/ForeverYolo)) - [infra/tool] **aarch64**: Optimized the structure of GIC parameters ([Ren HangQi](https://github.com/ForeverYolo)) - [ci/misc] Update dependencies, add ccache support, and improve build/tooling workflows. ([Jingyu Liu](https://github.com/liulog)) diff --git a/Cargo.toml b/Cargo.toml index ae96cce1..e26316e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,64 +47,6 @@ acpi = "=5.2.0" uguid = "=2.2.0" uefi-raw = "=0.9.0" -[features] -############# general ############## -iommu = [] # supported by: aarch64, riscv64 -pci = [] # supported by: aarch64, riscv64,loongarch64 -print_timestamp = [] # print timestamp when logging - -############# IOMMU ############## -riscv_iommu = ["iommu"] -arm_smmu = ["iommu"] -intel_vtd = ["iommu"] -share_s2pt = ["iommu"] -viommu = ["iommu"] # supported by: riscv64 - -############# PCIe access mechanism ############## -ecam_pcie = [] # Standard ECAM mechanism (default for most platforms) -dwc_pcie = [] # DesignWare PCIe Core mechanism (CFG0/CFG1, used by RK3568) -loongarch64_pcie = [] # LoongArch PCIe mechanism (used by LoongArch platforms) -no_pcie_bar_realloc = [] -virtio_pci = [] # Virtual virtio pci support - -############# aarch64 ############## -# irqchip driver -gicv2 = [] -gicv3 = [] - -# uart driver -pl011 = [] -xuartps = [] -imx_uart = [] -uart_16550 = [] -sifive_ccache = [] -eic7700_sysreg = [] -uart16550a = [] - -############## riscv64 ############# -# irqchip driver -plic = [] -dp1000_plic = [] -aia = [] -aclint = [] -# extensions -sstc = [] -# platform specific -eic770x_soc = [] - -########### loongarch64 ############ -# irqchip driver -loongson_7a2000 = [] -# uart driver -loongson_uart = [] -# cpu (not used for now) -loongson_3a5000 = [] -loongson_3a6000 = [] - -############# x86_64 ############### -graphics = [] -split_screen = [] - [profile.dev] # panic = "abort" # avoid cargo test failure, this is a bug of cargo debug = 2 diff --git a/Jenkinsfile b/Jenkinsfile index 1d95e4d4..38af869d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,3 +1,12 @@ +/** ARCH/BOARD come from matrix BID (arch/board); ci.yaml must not duplicate them. */ +def parseBid(String bid) { + def parts = (bid ?: '').split('/', 2) + if (parts.size() != 2 || !parts[0] || !parts[1]) { + error("invalid BID: ${bid}") + } + return [arch: parts[0], board: parts[1]] +} + def parseCiBuildArgs(cfg) { def buildArgs = [:] if (!cfg?.build_args) { @@ -23,6 +32,23 @@ def matrixCellDir() { return "${env.WORKSPACE}/.matrix/${bid.replace('/', '__')}" } +/** Isolated workspace for top-level CI jobs (linter, license-checker, …). */ +def jenkinsJobDir(String name) { + return "${env.WORKSPACE}/.jenkins/${name}" +} + +/** Copy repo into an isolated dir; excludes other Jenkins sandboxes from the source tree. */ +def syncWorkspaceTo(String destDir) { + sh """ + mkdir -p '${destDir}' + rsync -a --delete \\ + --exclude '.jenkins/' \\ + --exclude '.matrix/' \\ + --exclude '.jenkins-matrix/' \\ + '${env.WORKSPACE}/' '${destDir}/' + """ +} + def loadCiYaml() { def data = readYaml file: 'jenkins/ci.yaml' def bids = data?.bids @@ -51,6 +77,86 @@ def normalizeToolArch(String arch) { return mapping.get(raw, raw) } +/** GitHub Check name for this matrix cell */ +def matrixCheckName() { + return (env.BID ?: '').toString() +} + +def publishGithubCheckInProgress(String checkName) { + publishChecks( + name: checkName, + title: checkName, + summary: 'In progress', + status: 'IN_PROGRESS', + conclusion: 'NONE', + detailsURL: "${env.RUN_DISPLAY_URL ?: env.BUILD_URL}", + ) +} + +def publishGithubCheckCompleted(String checkName, String conclusion) { + def summaries = [ + 'SUCCESS' : 'Passed', + 'FAILURE' : 'Failed', + 'CANCELLED': 'Cancelled', + ] + publishChecks( + name: checkName, + title: checkName, + summary: summaries.get(conclusion, conclusion), + status: 'COMPLETED', + conclusion: conclusion, + detailsURL: "${env.RUN_DISPLAY_URL ?: env.BUILD_URL}", + ) +} + +def publishMatrixCheckInProgress() { + publishGithubCheckInProgress(matrixCheckName()) +} + +def publishMatrixCheckCompleted(String conclusion) { + publishGithubCheckCompleted(matrixCheckName(), conclusion) +} + +def finishGithubCheck(String checkName, String buildResult) { + def conclusion = [ + 'SUCCESS' : 'SUCCESS', + 'FAILURE' : 'FAILURE', + 'UNSTABLE': 'FAILURE', + 'ABORTED' : 'CANCELLED', + 'NOT_BUILT': 'CANCELLED', + ].get(buildResult ?: '', 'FAILURE') + publishGithubCheckCompleted(checkName, conclusion) +} + +def hasCiTests() { + return getBidConfig(loadCiYaml(), env.BID) != null +} + +def toolchainPathShell() { + return "export PATH=${env.CARGO_HOME}/bin:${env.TOOLCHAIN_PATHS}:\$PATH" +} + +def qemuPathShell() { + return "export PATH=${env.QEMU_PATH}:\$PATH" +} + +/** Kconfig: symlink agent venv + make defconfig. Keep in sync with Makefile kconfig_python path. */ +def kconfigSetupShell(String arch, String board) { + return """ + ${toolchainPathShell()} + chmod +x tools/kconfig/host_config.sh tools/kconfig/save_defconfig.sh 2>/dev/null || true + if [ ! -x tools/kconfig/.venv/bin/python ]; then + if [ ! -x ${env.KCONFIG_VENV}/bin/python ]; then + echo "ERROR: CI kconfig venv missing: ${env.KCONFIG_VENV}/bin/python" >&2 + exit 1 + fi + mkdir -p tools/kconfig + ln -sfn ${env.KCONFIG_VENV} tools/kconfig/.venv + fi + make defconfig ARCH=${arch} BOARD=${board} + """ +} + pipeline { agent any @@ -62,6 +168,7 @@ pipeline { always { echo "=== DEBUG: Branch ${env.BRANCH_NAME} ===" echo "=== DEBUG: Commit ${env.GIT_COMMIT} ===" + deleteDir() } } @@ -72,6 +179,7 @@ pipeline { CARGO_HOME = '/usr/local/cargo' QEMU_PATH = '/home/light/DEMO/qemu-9.2.3/build' TEST_IMG_BASE = '/home/light/DEMO/syswonder/test_img' + KCONFIG_VENV = "/home/light/DEMO/syswonder/test_img/venv" RISCV_TOOLCHAIN_PATH = '/home/light/DEMO/toolchain/riscv64-glibc-ubuntu-24.04-gcc' AARCH64_TOOLCHAIN_PATH = '/home/light/DEMO/toolchain/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu' LOONGARCH64_TOOLCHAIN_PATH = '/home/light/DEMO/toolchain/loongarch_cross_tools' @@ -80,214 +188,228 @@ pipeline { } stages { - stage('CI') { - when { - anyOf { - branch 'main' - branch 'dev' - allOf { - changeRequest() - anyOf { - expression { return (env.CHANGE_TARGET ?: '') == 'main' } - expression { return (env.CHANGE_TARGET ?: '') == 'dev' } - } + stage('Linter') { + steps { + script { + publishGithubCheckInProgress('linter') + def cellWs = jenkinsJobDir('linter') + syncWorkspaceTo(cellWs) + dir(cellWs) { + sh kconfigSetupShell('aarch64', 'qemu-gicv3') + ''' + cargo fmt --all -- --check + ''' + } + } + } + post { + always { + script { finishGithubCheck('linter', currentBuild.currentResult) } + } + } + } + + stage('License checker') { + steps { + script { + publishGithubCheckInProgress('license-checker') + def cellWs = jenkinsJobDir('license-checker') + syncWorkspaceTo(cellWs) + dir(cellWs) { + sh """ + chmod +x tools/license_checker.sh + ./tools/license_checker.sh + """ } } } - stages { - stage('Checkout') { - steps { - // Ensure no stale files from previous builds. - deleteDir() - checkout scm + post { + always { + script { finishGithubCheck('license-checker', currentBuild.currentResult) } + } + } + } + + stage('Multi-Platform Matrix') { + matrix { + axes { + axis { + name 'BID' + values( + 'aarch64/imx8mp', + 'aarch64/ok6254-c', + 'aarch64/phytium-pi', + 'aarch64/qemu-gicv2', + 'aarch64/qemu-gicv3', + 'aarch64/rk3568', + 'aarch64/rk3588', + 'aarch64/sysoul_x3300', + 'aarch64/zcu102', + 'loongarch64/ls3a5000', + 'loongarch64/ls3a6000', + 'riscv64/hifive-premier-p550', + 'riscv64/megrez', + 'riscv64/qemu-aia', + 'riscv64/qemu-plic', + 'riscv64/ur-dp1000', + 'x86_64/ecx-2300f-peg', + 'x86_64/nuc14mnk', + 'x86_64/qemu', + ) } } - stage('Multi-Platform Matrix') { - matrix { - axes { - axis { - name 'BID' - values( - 'aarch64/imx8mp', - 'aarch64/ok6254-c', - 'aarch64/phytium-pi', - 'aarch64/qemu-gicv2', - 'aarch64/qemu-gicv3', - 'aarch64/rk3568', - 'aarch64/rk3588', - 'aarch64/sysoul_x3300', - 'aarch64/zcu102', - 'loongarch64/ls3a5000', - 'loongarch64/ls3a6000', - 'riscv64/hifive-premier-p550', - 'riscv64/megrez', - 'riscv64/qemu-aia', - 'riscv64/qemu-plic', - 'riscv64/ur-dp1000', - 'x86_64/ecx-2300f-peg', - 'x86_64/nuc14mnk', - 'x86_64/qemu', - ) + stages { + stage('Prepare cell') { + steps { + script { + publishMatrixCheckInProgress() + syncWorkspaceTo(matrixCellDir()) } } + } - stages { - stage('Prepare cell workspace') { - steps { - script { - def cellWs = matrixCellDir() + stage('Compile') { + steps { + dir(matrixCellDir()) { + script { + def bid = parseBid(env.BID) + def arch = bid.arch + def board = bid.board + echo "Compile hvisor [BID=${env.BID}, ARCH=${arch}, BOARD=${board}]" + sh kconfigSetupShell(arch, board) + if (arch != 'x86_64') { sh """ - mkdir -p '${cellWs}' - rsync -a --delete \\ - --exclude '.matrix/' \\ - --exclude '.jenkins-matrix/' \\ - '${env.WORKSPACE}/' '${cellWs}/' + ${toolchainPathShell()} + make dtb ARCH=${arch} BOARD=${board} """ } + sh """ + ${toolchainPathShell()} + make all ARCH=${arch} BOARD=${board} MODE=release + """ } } - - stage('Compile') { - steps { - dir(matrixCellDir()) { - script { - def parts = (env.BID ?: '').split('/', 2) - if (parts.size() != 2) { - error("invalid BID: ${env.BID}") - } - def arch = parts[0] - def board = parts[1] - echo "Compile hvisor [BID=${env.BID}, ARCH=${arch}, BOARD=${board}]" - if (arch != 'x86_64') { - sh """ - export PATH=${env.CARGO_HOME}/bin:${env.TOOLCHAIN_PATHS}:\$PATH - make dtb ARCH=${arch} BOARD=${board} - """ - } - sh """ - export PATH=${env.CARGO_HOME}/bin:${env.TOOLCHAIN_PATHS}:\$PATH - make all ARCH=${arch} BOARD=${board} MODE=release - """ - } + } + } + + stage('Build hvisor-tool') { + when { + expression { return hasCiTests() } + } + steps { + dir(matrixCellDir()) { + script { + def bidCfg = getBidConfig(loadCiYaml(), env.BID) + def buildArgs = parseCiBuildArgs(bidCfg) + def bidTool = parseBid(env.BID) + def tarch = normalizeToolArch(buildArgs.TARCH ?: bidTool.arch) + def kdir = buildArgs.KDIR + if (!kdir) { + error("jenkins/ci.yaml BID=${env.BID}: build_args must include KDIR") } - } - } - - stage('Build hvisor-tool') { - when { - expression { - return getBidConfig(loadCiYaml(), env.BID) != null + + echo "Build hvisor-tool [BID=${env.BID}, TARCH=${tarch}, KDIR=${kdir}]" + if (!fileExists(env.HVISOR_TOOL_PATH)) { + sh "mkdir -p ${env.HVISOR_TOOL_PATH}" } - } - steps { - dir(matrixCellDir()) { - script { - def ci = loadCiYaml() - def bidCfg = getBidConfig(ci, env.BID) - def buildArgs = parseCiBuildArgs(bidCfg) - def tarch = normalizeToolArch(buildArgs.TARCH ?: buildArgs.ARCH) - def kdir = buildArgs.KDIR - if (!tarch || !kdir) { - error("jenkins/ci.yaml BID=${env.BID}: build_args must include ARCH/TARCH and KDIR") - } - - echo "Build hvisor-tool [BID=${env.BID}, TARCH=${tarch}, KDIR=${kdir}]" - if (!fileExists(env.HVISOR_TOOL_PATH)) { - sh "mkdir -p ${env.HVISOR_TOOL_PATH}" - } - dir(env.HVISOR_TOOL_PATH) { - checkout([ - $class: 'GitSCM', - branches: [[name: '*/main']], - extensions: [[$class: 'CloneOption', depth: 1, noTags: true]], - userRemoteConfigs: [[url: env.HVISOR_TOOL_URL]] - ]) - } - sh """ - export PATH=${env.TOOLCHAIN_PATHS}:\$PATH - cd ${env.HVISOR_TOOL_PATH} - make all ARCH=${tarch} KDIR=${kdir} - """ - } + dir(env.HVISOR_TOOL_PATH) { + checkout([ + $class: 'GitSCM', + branches: [[name: '*/main']], + extensions: [[$class: 'CloneOption', depth: 1, noTags: true]], + userRemoteConfigs: [[url: env.HVISOR_TOOL_URL]] + ]) } + sh """ + export PATH=${env.TOOLCHAIN_PATHS}:\$PATH + make -C ${env.HVISOR_TOOL_PATH} all ARCH=${tarch} KDIR=${kdir} + """ } } - - stage('Prepare test') { - when { - expression { - return getBidConfig(loadCiYaml(), env.BID) != null + } + } + + stage('Prepare test') { + when { + expression { return hasCiTests() } + } + steps { + dir(matrixCellDir()) { + script { + def bidCfg = getBidConfig(loadCiYaml(), env.BID) + def buildArgs = parseCiBuildArgs(bidCfg) + def bidParsed = parseBid(env.BID) + def arch = bidParsed.arch + def board = bidParsed.board + def kdir = (buildArgs.KDIR ?: '').toString() + def testsCfg = bidCfg.tests ?: [:] + def mode = (testsCfg.mode ?: '').toString().trim() + if (!kdir || !mode) { + error("jenkins/ci.yaml BID=${env.BID}: tests.mode and build_args KDIR are required") } - } - steps { - dir(matrixCellDir()) { - script { - def ci = loadCiYaml() - def bidCfg = getBidConfig(ci, env.BID) - def buildArgs = parseCiBuildArgs(bidCfg) - def arch = (buildArgs.ARCH ?: '').toString() - def board = (buildArgs.BOARD ?: '').toString() - def kdir = (buildArgs.KDIR ?: '').toString() - def testsCfg = bidCfg.tests ?: [:] - def mode = (testsCfg.mode ?: '').toString().trim() - if (!arch || !board || !kdir || !mode) { - error("jenkins/ci.yaml BID=${env.BID}: tests.mode and build_args ARCH/BOARD/KDIR are required") - } - - if (mode == 'qemu') { - def prepareScript = "jenkins/prepare.sh" - def externalFile = "${env.TEST_IMG_BASE}/${arch}/${board}" - def configure = "./platform/${arch}/${board}/" - echo "Prepare rootfs [BID=${env.BID}]" - sh """ - cp -r ${externalFile}/* ${configure} - chmod +x "${prepareScript}" - sudo -E env \\ - ARCH="${arch}" \\ - BOARD="${board}" \\ - KDIR="${kdir}" \\ - WORKSPACE_ROOT="\$(pwd)" \\ - HVISOR_TOOL_PATH="${env.HVISOR_TOOL_PATH}" \\ - "${prepareScript}" - """ - } else if (mode == 'board') { - // Placeholder for future board artifact distribution by network. - echo "Board prepare placeholder [BID=${env.BID}]" - } else { - error("jenkins/ci.yaml BID=${env.BID}: unsupported tests.mode='${mode}'") - } - } + + if (mode == 'qemu') { + def prepareScript = "jenkins/prepare.sh" + def externalFile = "${env.TEST_IMG_BASE}/${arch}/${board}" + def configure = "./platform/${arch}/${board}/" + echo "Prepare rootfs [BID=${env.BID}]" + sh """ + cp -r ${externalFile}/* ${configure} + chmod +x "${prepareScript}" + sudo -E env \\ + ARCH="${arch}" \\ + BOARD="${board}" \\ + KDIR="${kdir}" \\ + WORKSPACE_ROOT="\$(pwd)" \\ + HVISOR_TOOL_PATH="${env.HVISOR_TOOL_PATH}" \\ + "${prepareScript}" + """ + } else if (mode == 'board') { + // Placeholder for future board artifact distribution by network. + echo "Board prepare placeholder [BID=${env.BID}]" + } else { + error("jenkins/ci.yaml BID=${env.BID}: unsupported tests.mode='${mode}'") } } } - - stage('Run test cases') { - when { - expression { - return getBidConfig(loadCiYaml(), env.BID) != null - } - } - steps { - dir(matrixCellDir()) { - script { - def ci = loadCiYaml() - def bidCfg = getBidConfig(ci, env.BID) - echo "Run tests via ci_runner [BID=${env.BID}]" - sh """ - export TERM=\${TERM:-xterm} - export PATH=${env.CARGO_HOME}/bin:${env.TOOLCHAIN_PATHS}:\$PATH - export PATH=${env.QEMU_PATH}:\$PATH - python3 jenkins/ci_runner.py \ - --bid "${env.BID}" - """ - } - } + } + } + + stage('Run test cases') { + when { + expression { return hasCiTests() } + } + steps { + dir(matrixCellDir()) { + script { + echo "Run tests via ci_runner [BID=${env.BID}]" + sh """ + export TERM=\${TERM:-xterm} + ${toolchainPathShell()} + ${qemuPathShell()} + python3 jenkins/ci_runner.py \ + --bid "${env.BID}" + """ } } } } } + + post { + success { + script { finishGithubCheck(matrixCheckName(), 'SUCCESS') } + } + failure { + script { finishGithubCheck(matrixCheckName(), 'FAILURE') } + } + unstable { + script { finishGithubCheck(matrixCheckName(), 'UNSTABLE') } + } + aborted { + script { finishGithubCheck(matrixCheckName(), 'ABORTED') } + } + } } } } diff --git a/Makefile b/Makefile index 55497c84..36d79820 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,6 @@ STATS ?= off PORT ?= 2333 MODE ?= release BOARD ?= qemu-gicv3 -FEATURES= BID ?= ptest ?= @@ -23,15 +22,6 @@ else BOARD := $(shell echo $(BID) | cut -d'/' -f2) endif -# if user add FEATURES in environment, we use it -# else we use the default FEATURES in platform/$(ARCH)/$(BOARD)/cargo/features -ifeq ($(FEATURES),) - FEATURES := $(shell ./tools/read_features.sh $(ARCH) $(BOARD) || echo ERROR) - ifeq ($(FEATURES),ERROR) - $(error ERROR: Read FEATURES failed. Please check if ARCH="$(ARCH)" and BOARD="$(BOARD)" are correct.) - endif -endif - ifeq ($(ARCH),aarch64) RUSTC_TARGET := aarch64-unknown-none GDB_ARCH := aarch64 @@ -56,7 +46,6 @@ export ARCH export BOARD export BID export RUSTC_TARGET -export FEATURES # Build paths build_path := target/$(RUSTC_TARGET)/$(MODE) @@ -69,7 +58,6 @@ systemtest_tdownload := $(test_dir)/systemtest/tdownload_all.sh # Build arguments build_args := -build_args += --features "$(FEATURES)" build_args += --target $(RUSTC_TARGET) build_args += -Z build-std=core,alloc build_args += -Z build-std-features=compiler-builtins-mem @@ -86,16 +74,53 @@ COLOR_BLUE := $(shell tput setaf 4) COLOR_BOLD := $(shell tput bold) COLOR_RESET := $(shell tput sgr0) +# Defconfig / menuconfig: see tools/kconfig/kconfig_cli.py +kconfig_python := tools/kconfig/.venv/bin/python + # Targets -.PHONY: all elf disa run gdb monitor clean tools rootfs vscode ci-run check-hv-mem-overlap -all: clean_check gen_cargo_config vscode $(hvisor_bin) check-hv-mem-overlap +.PHONY: all elf disa run gdb monitor clean tools rootfs vscode ci-run defconfig menuconfig savedefconfig ensure_config clean_check kconfig_venv check-hv-mem-overlap +kconfig_venv: + @if [ ! -x $(kconfig_python) ]; then \ + echo "$(COLOR_YELLOW)Creating tools/kconfig/.venv (kconfiglib)...$(COLOR_RESET)"; \ + ./tools/kconfig/bootstrap_venv.sh; \ + fi + +ensure_config: + @CONFIG_ARCH=; CONFIG_BOARD=; \ + if [ -f .config ]; then \ + CONFIG_ARCH=$$(grep '^# ARCH=' .config 2>/dev/null | head -1 | sed 's/^# ARCH=//'); \ + [ -n "$$CONFIG_ARCH" ] || CONFIG_ARCH=$$(grep '^ARCH=' .config | head -1 | cut -d'=' -f2); \ + CONFIG_BOARD=$$(grep '^# BOARD=' .config 2>/dev/null | head -1 | sed 's/^# BOARD=//'); \ + [ -n "$$CONFIG_BOARD" ] || CONFIG_BOARD=$$(grep '^BOARD=' .config | head -1 | cut -d'=' -f2); \ + fi; \ + if [ ! -f .config ]; then \ + echo "$(COLOR_YELLOW)No .config; running defconfig for $(ARCH)/$(BOARD)$(COLOR_RESET)"; \ + $(MAKE) --no-print-directory defconfig; \ + elif [ "$$CONFIG_ARCH" != "$(ARCH)" ] || [ "$$CONFIG_BOARD" != "$(BOARD)" ]; then \ + echo "$(COLOR_YELLOW)$(COLOR_BOLD)ARCH or BOARD changed (OLD: $$CONFIG_ARCH/$$CONFIG_BOARD, NEW: $(ARCH)/$(BOARD)), cleaning and reloading defconfig...$(COLOR_RESET)"; \ + ./tools/clean.sh; \ + $(MAKE) --no-print-directory defconfig; \ + fi + +clean_check: ensure_config + +defconfig: kconfig_venv + @$(kconfig_python) tools/kconfig/kconfig_cli.py defconfig + +menuconfig: kconfig_venv + @$(kconfig_python) tools/kconfig/kconfig_cli.py menuconfig + +savedefconfig: + @./tools/kconfig/save_defconfig.sh "$(ARCH)" "$(BOARD)" + +all: ensure_config gen_cargo_config vscode $(hvisor_bin) check-hv-mem-overlap @printf "\n" @printf "$(COLOR_GREEN)$(COLOR_BOLD)hvisor build summary:$(COLOR_RESET)\n" @printf "%-10s %s\n" "ARCH =" "$(COLOR_BOLD)$(ARCH)$(COLOR_RESET)" @printf "%-10s %s\n" "BOARD =" "$(COLOR_BOLD)$(BOARD)$(COLOR_RESET)" @printf "%-10s %s\n" "BID =" "$(COLOR_BOLD)$(BID)$(COLOR_RESET)" @printf "%-10s %s\n" "LOG =" "$(COLOR_BOLD)$(LOG)$(COLOR_RESET)" - @printf "%-10s %s\n" "FEATURES =" "$(COLOR_BOLD)$(FEATURES)$(COLOR_RESET)" + @printf "%-10s %s\n" "DEFCONFIG =" "$(COLOR_BOLD)platform/$(ARCH)/$(BOARD)/kconfig/defconfig$(COLOR_RESET)" @printf "%-10s %s\n" "RUSTC_TARGET =" "$(COLOR_BOLD)$(RUSTC_TARGET)$(COLOR_RESET)" @printf "%-10s %s\n" "BUILD_PATH =" "$(COLOR_BOLD)$(build_path)$(COLOR_RESET)" @printf "%-10s %s\n" "HVISON_BIN_SIZE =" "$(COLOR_BOLD)$(shell du -h $(hvisor_bin) | cut -f1)$(COLOR_RESET)" @@ -109,21 +134,10 @@ all: clean_check gen_cargo_config vscode $(hvisor_bin) check-hv-mem-overlap @printf "\n" @printf "$(COLOR_GREEN)$(COLOR_BOLD)hvisor build success!$(COLOR_RESET)\n" -clean_check: -# if .config not exist, then everything is fine -# else we read .config and parse ARCH and BOARD, if they are different, we clean the build - @if [ -f ".config" ]; then \ - CONFIG_ARCH=$$(cat .config | grep "ARCH" | cut -d'=' -f2); \ - CONFIG_BOARD=$$(cat .config | grep "BOARD" | cut -d'=' -f2); \ - if [ "$$CONFIG_ARCH" != "$(ARCH)" ] || [ "$$CONFIG_BOARD" != "$(BOARD)" ]; then \ - echo "$(COLOR_YELLOW)$(COLOR_BOLD)ARCH or BOARD changed(OLD: $$CONFIG_ARCH/$$CONFIG_BOARD, NEW: $(ARCH)/$(BOARD)), cleaning...$(COLOR_RESET)"; \ - ./tools/clean.sh; \ - fi; \ - fi - gen_cargo_config: @printf "$(COLOR_GREEN)$(COLOR_BOLD)generating .cargo/config.toml...$(COLOR_RESET)\n" - ./tools/gen_cargo_config.sh + @chmod +x tools/kconfig/host_config.sh 2>/dev/null || true + ./tools/kconfig/host_config.sh cargo @printf "$(COLOR_GREEN)$(COLOR_BOLD)generating .cargo/config.toml success!$(COLOR_RESET)\n" check-hv-mem-overlap: $(hvisor_bin) platform/$(ARCH)/$(BOARD)/board.rs @@ -135,10 +149,11 @@ check-hv-mem-overlap: $(hvisor_bin) platform/$(ARCH)/$(BOARD)/board.rs vscode: @printf "$(COLOR_GREEN)$(COLOR_BOLD)generating .vscode/settings.json...$(COLOR_RESET)\n" - ./tools/gen_vscode_settings.sh + @chmod +x tools/kconfig/host_config.sh 2>/dev/null || true + ./tools/kconfig/host_config.sh vscode @printf "$(COLOR_GREEN)$(COLOR_BOLD)generating .vscode/settings.json success!$(COLOR_RESET)\n" -elf: +elf: ensure_config gen_cargo_config cargo build $(build_args) disa: @@ -174,15 +189,11 @@ test-pre: download-test-img chmod +x platform/$(ARCH)/$(BOARD)/test/runner.sh @echo "added execute permission to test runner.sh for board $(BOARD)" -fmt-test: all - cargo fmt --all -- --check - @echo "cargo fmt check passed!" - fmt: all cargo fmt --all @echo "your code has been formatted" -clippy: +clippy: ensure_config gen_cargo_config cargo clippy $(build_args) flash-img: @@ -198,10 +209,10 @@ download-test-img: else echo "\nflash.img found\n"; \ fi -test: clean test-pre gen_cargo_config +test: clean test-pre ensure_config gen_cargo_config cargo test $(build_args) -vv -stest: clean test-pre gen_cargo_config +stest: clean test-pre ensure_config gen_cargo_config ./platform/$(ARCH)/$(BOARD)/test/systemtest/tcompiledtb.sh ./platform/$(ARCH)/$(BOARD)/test/systemtest/tdownload_all.sh ./platform/$(ARCH)/$(BOARD)/test/systemtest/trootfs_deploy.sh @@ -210,7 +221,7 @@ stest: clean test-pre gen_cargo_config # Performance benchmark: data collection only, does not affect pass/fail. # Calls systemtest scripts for DTS, then perftest/tdownload_all.sh when present # (fallback to systemtest/tdownload_all.sh), and perftest/trootfs_deploy.sh. -perf: clean test-pre gen_cargo_config +perf: clean test-pre ensure_config gen_cargo_config ./platform/$(ARCH)/$(BOARD)/test/systemtest/tcompiledtb.sh @if [ -x "$(perftest_tdownload)" ]; then \ $(perftest_tdownload); \ @@ -222,7 +233,7 @@ perf: clean test-pre gen_cargo_config # Prepare perf image only: reuse existing rootfs img when present, download # missing assets, deploy benchmark scripts/tools into image, and print path. -perf-prepare-img: clean test-pre gen_cargo_config +perf-prepare-img: clean test-pre ensure_config gen_cargo_config ./platform/$(ARCH)/$(BOARD)/test/systemtest/tcompiledtb.sh @if [ -x "$(perftest_tdownload)" ]; then \ $(perftest_tdownload); \ diff --git a/build.rs b/build.rs index 9fdedbbf..9de7058d 100644 --- a/build.rs +++ b/build.rs @@ -14,6 +14,7 @@ // Authors: // Yulong Han // +use std::collections::{HashMap, HashSet}; use std::io::Write; use std::{env, fs, path::Path}; @@ -29,58 +30,116 @@ fn log(output: &str) { writeln!(file, "{}", output).expect("Failed to write to log file"); } -// .config -// ARCH=... -// BOARD=... struct BuildEnv { arch: String, board: String, bid: String, - features: String, } +// parse ARCH, BOARD and BID from .config fn parse_build_env(file_path: &str) -> BuildEnv { let file = fs::read_to_string(file_path).expect("Failed to read .config file"); let mut arch = String::new(); let mut board = String::new(); let mut bid = String::new(); - let mut features = String::new(); for line in file.lines() { - let parts: Vec<&str> = line.split('=').collect(); - if parts.len() != 2 { + let t = line.trim(); + if let Some(v) = t.strip_prefix("# ARCH=") { + arch = v.to_string(); + continue; + } + if let Some(v) = t.strip_prefix("# BOARD=") { + board = v.to_string(); + continue; + } + if let Some(v) = t.strip_prefix("# BID=") { + bid = v.to_string(); + continue; + } + if t.starts_with('#') { continue; } - match parts[0] { - "ARCH" => arch = parts[1].to_string(), - "BOARD" => board = parts[1].to_string(), - "BID" => bid = parts[1].to_string(), - "FEATURES" => features = parts[1].to_string(), + let Some((k, v)) = t.split_once('=') else { + continue; + }; + match k { + "ARCH" if arch.is_empty() => arch = v.to_string(), + "BOARD" if board.is_empty() => board = v.to_string(), + "BID" if bid.is_empty() => bid = v.to_string(), _ => {} } } - BuildEnv { - arch, - board, - bid, - features, + BuildEnv { arch, board, bid } +} + +fn load_cfg_map(root: &Path) -> HashMap { + let path = root.join("kconfig/cfg_map.toml"); + let raw = fs::read_to_string(&path).unwrap_or_else(|_| panic!("missing {}", path.display())); + let mut m = HashMap::new(); + let mut in_symbols = false; + for line in raw.lines() { + let t = line.trim(); + if t.is_empty() || t.starts_with('#') { + continue; + } + if t == "[symbols]" { + in_symbols = true; + continue; + } + if t.starts_with('[') { + in_symbols = false; + continue; + } + if !in_symbols { + continue; + } + let Some((k, v)) = t.split_once('=') else { + continue; + }; + let k = k.trim().trim_matches('"'); + let v = v.trim().trim_matches('"'); + m.insert(k.to_string(), v.to_string()); + } + if m.is_empty() { + panic!("cfg_map.toml: no entries under [symbols]"); } + m +} + +// parse enabled config keys from .config +fn parse_enabled_config_keys(config_text: &str) -> HashSet { + let mut out = HashSet::new(); + for line in config_text.lines() { + let line = line.trim(); + if line.is_empty() || line.starts_with('#') { + continue; + } + let Some((key, val)) = line.split_once('=') else { + continue; + }; + let val = val.trim(); + if val != "y" && val != "m" { + continue; + } + if key.starts_with("CONFIG_") { + out.insert(key.to_string()); + } + } + out } fn main() { - // cleanup the log file let log_path = Path::new(BUILD_LOG_FILE); if log_path.exists() { fs::remove_file(log_path).expect("Failed to remove log file"); } let project_toml_root = env::var("CARGO_MANIFEST_DIR").unwrap(); - // read the .config file at the project root - let config_path = format!("{}/.config", project_toml_root); - let mut build_env = parse_build_env(&config_path); + let root = Path::new(&project_toml_root); + let config_path = root.join(".config"); + let mut build_env = parse_build_env(config_path.to_str().unwrap()); if !build_env.bid.is_empty() { - // BID=$ARCH/$BOARD, parse it - // update the build_env with the parsed values let parts: Vec<&str> = build_env.bid.split('/').collect(); if parts.len() != 2 { log(&format!("Invalid BID format: {}", build_env.bid)); @@ -91,35 +150,45 @@ fn main() { } build_env.arch = parts[0].to_string(); build_env.board = parts[1].to_string(); - } else { - log(&format!( - "BID environment variable not found, using ARCH and BOARD" - )); - if build_env.arch.is_empty() || build_env.board.is_empty() { - log(&format!("ARCH or BOARD environment variable not found")); - panic!( - "ARCH or BOARD environment variable not found, please check the log file({}) for more details", - BUILD_LOG_FILE - ); - } + } else if build_env.arch.is_empty() || build_env.board.is_empty() { + log("ARCH or BOARD missing in .config"); + panic!( + "ARCH or BOARD missing in .config (run: make defconfig), see {}", + BUILD_LOG_FILE + ); } let arch = build_env.arch; let board = build_env.board; let bid = build_env.bid; - let features = build_env.features; let pwd = env::current_dir().unwrap(); log(&format!("Current directory: {}", pwd.display())); + let cfg_map = load_cfg_map(root); + let config_text = fs::read_to_string(&config_path).expect("read .config"); + let enabled = parse_enabled_config_keys(&config_text); + + for rust_cfg in cfg_map.values().collect::>() { + println!("cargo:rustc-check-cfg=cfg({rust_cfg})"); + } + + for k in &enabled { + if let Some(rust_cfg) = cfg_map.get(k) { + println!("cargo:rustc-cfg={rust_cfg}"); + } else if k.starts_with("CONFIG_") { + log(&format!("warning: unknown config key in .config: {k}")); + } + } + let target_path_str = format!("{}/src/platform/__board.rs", pwd.display()); let target_path = Path::new(&target_path_str); let source_path_str = format!("{}/platform/{}/{}/board.rs", pwd.display(), arch, board); let source_path = Path::new(&source_path_str); log(&format!( - "Building for ARCH={} BOARD={}, BID={}, FEATURES={}", - arch, board, bid, features + "Building for ARCH={arch} BOARD={board}, BID={bid}, enabled_cfgs={}", + enabled.len() )); log(&format!( @@ -129,24 +198,40 @@ fn main() { )); if !source_path.exists() { - log(&format!("Invalid board.rs path: {}, make sure the ARCH and BOARD environment variables are set correctly", source_path_str)); - panic!( - "Invalid board.rs, please check the log file({}) for more details", - BUILD_LOG_FILE - ); + log(&format!("Invalid board.rs path: {source_path_str}")); + panic!("Invalid board.rs, please check the log file({BUILD_LOG_FILE}) for more details"); } - // soft link the board.rs to __board.rs if target_path.exists() { fs::remove_file(target_path).expect("Failed to remove existing __board.rs"); } std::os::unix::fs::symlink(source_path, target_path).expect("Failed to create symlink"); - log(&format!("Linking successful")); + log("Linking successful"); println!("cargo:rerun-if-env-changed=ARCH"); println!("cargo:rerun-if-env-changed=BOARD"); println!("cargo:rerun-if-env-changed=BID"); - println!("cargo:rerun-if-env-changed=FEATURES"); - println!("cargo:rerun-if-changed={}", source_path_str); - println!("cargo:rerun-if-changed={}", target_path_str); + println!("cargo:rerun-if-changed={}", config_path.display()); + println!( + "cargo:rerun-if-changed={}", + root.join("kconfig/cfg_map.toml").display() + ); + println!( + "cargo:rerun-if-changed={}", + root.join("kconfig/Kconfig").display() + ); + println!( + "cargo:rerun-if-changed={}", + root.join("tools/kconfig/kconfig_cli.py").display() + ); + println!( + "cargo:rerun-if-changed={}", + root.join("platform") + .join(&arch) + .join(&board) + .join("kconfig/defconfig") + .display() + ); + println!("cargo:rerun-if-changed={source_path_str}"); + println!("cargo:rerun-if-changed={target_path_str}"); } diff --git a/jenkins/ci.yaml b/jenkins/ci.yaml index de3b79ba..b23c396e 100644 --- a/jenkins/ci.yaml +++ b/jenkins/ci.yaml @@ -1,8 +1,6 @@ bids: - bid: riscv64/qemu-plic build_args: - - ARCH=riscv64 - - BOARD=qemu-plic - KDIR=/home/light/DEMO/linux/linux-6.10 tests: mode: qemu @@ -12,8 +10,6 @@ bids: - bid: aarch64/qemu-gicv3 build_args: - - ARCH=aarch64 - - BOARD=qemu-gicv3 - KDIR=/home/light/DEMO/linux/linux-5.4 tests: mode: qemu @@ -24,8 +20,6 @@ bids: # - bid: aarch64/rk3568 # build_args: - # - ARCH=aarch64 - # - BOARD=rk3568 # - KDIR=/home/light/DEMO/sdk/rk356x-up4-2c/kernel # tests: # mode: board @@ -39,8 +33,6 @@ bids: - bid: x86_64/qemu build_args: - - ARCH=x86_64 - - BOARD=qemu - KDIR=/home/light/DEMO/linux/linux-5.19 tests: mode: qemu diff --git a/jenkins/ci_config.py b/jenkins/ci_config.py index b7452124..f47c5f3c 100755 --- a/jenkins/ci_config.py +++ b/jenkins/ci_config.py @@ -15,6 +15,13 @@ CI_YAML = ROOT / "jenkins" / "ci.yaml" +def parse_bid(bid: str) -> tuple[str, str]: + parts = bid.strip().split("/", 1) + if len(parts) != 2 or not parts[0].strip() or not parts[1].strip(): + raise ValueError(f"invalid BID: {bid!r}") + return parts[0].strip(), parts[1].strip() + + def normalize_build_args(raw: list[Any] | None) -> dict[str, str]: result: dict[str, str] = {} for item in raw or []: diff --git a/jenkins/ci_runner.py b/jenkins/ci_runner.py index d7d64584..6036ff9c 100755 --- a/jenkins/ci_runner.py +++ b/jenkins/ci_runner.py @@ -11,7 +11,7 @@ from pathlib import Path from typing import Any, Callable -from ci_config import get_bid_entry, load_ci +from ci_config import get_bid_entry, load_ci, parse_bid from terminal import Terminal, TerminalCommandError, TerminalTimeoutError @@ -180,7 +180,7 @@ def zone1_start(cfg: dict[str, Any], term: Terminal | None) -> int: if not pts_numbers: raise TerminalCommandError("failed to find numeric pts from 'ls -1 /dev/pts/[0-9]*'") max_pts = pts_numbers[-1] - _ = run_and_print_send_only(term, f"screen /dev/pts/{max_pts}", read_duration=5.0) + _ = run_and_print_send_only(term, f"screen /dev/pts/{max_pts}", read_duration=20.0) _ = run_and_print_send_only(term, "\n", read_duration=2.0) _, _ = run_and_print_quiet(term, "ls", quiet_seconds=1.0, max_duration=15.0) if boot_rc != 0: @@ -205,15 +205,16 @@ def parse_args() -> argparse.Namespace: def load_runtime_config(args: argparse.Namespace) -> dict[str, Any]: ci = load_ci() bid_entry = get_bid_entry(ci, args.bid) - build_args = bid_entry["build_args"] tests = bid_entry["tests"] - arch = build_args.get("ARCH", "").strip() - board = build_args.get("BOARD", "").strip() + try: + arch, board = parse_bid(args.bid) + except ValueError as exc: + raise SystemExit(str(exc)) from exc mode = bid_entry.get("mode", "").strip() cases = bid_entry.get("cases", []) - if not arch or not board or not mode: - raise SystemExit(f"incomplete config for bid '{args.bid}': ARCH/BOARD/mode are required") + if not mode: + raise SystemExit(f"incomplete config for bid '{args.bid}': tests.mode is required") if not cases: raise SystemExit(f"no test cases configured for bid '{args.bid}'") diff --git a/kconfig/Kconfig b/kconfig/Kconfig new file mode 100644 index 00000000..a8ae8acd --- /dev/null +++ b/kconfig/Kconfig @@ -0,0 +1,227 @@ +mainmenu "hvisor platform options" + +menu "Target architecture" +choice + prompt "CPU architecture" + default ARCH_AARCH64 + +config ARCH_AARCH64 + bool "aarch64" + +config ARCH_RISCV64 + bool "riscv64" + +config ARCH_LOONGARCH64 + bool "loongarch64" + +config ARCH_X86_64 + bool "x86_64" + +endchoice +endmenu + +menu "Interrupt controller" + depends on ARCH_AARCH64 || ARCH_RISCV64 || ARCH_LOONGARCH64 + +choice + prompt "GIC version" + optional + default IRQ_GICV3 + depends on ARCH_AARCH64 + +config IRQ_GICV2 + bool "GICv2" + +config IRQ_GICV3 + bool "GICv3" + +endchoice + +config PLIC + bool "PLIC" + depends on ARCH_RISCV64 + default n + +config DP1000_PLIC + bool "DP1000 PLIC variant" + depends on ARCH_RISCV64 && PLIC + default n + +config AIA + bool "AIA (APLIC/IMSIC)" + depends on ARCH_RISCV64 + default n + +config ACLINT + bool "ACLINT (MTI/MSI)" + depends on ARCH_RISCV64 + default n + +config LOONGSON_7A2000 + bool "Loongson 7A2000" + depends on ARCH_LOONGARCH64 + default n + +endmenu + +menu "RISC-V options" + depends on ARCH_RISCV64 + +config SSTC + bool "Sstc" + default n + +config HYPERVISOR_V0_6 + bool "Hypervisor v0.6" + default n + +config EIC7700_SYSREG + bool "EIC7700 system registers" + depends on HYPERVISOR_V0_6 + default n + +config SIFIVE_CCACHE + bool "SiFive ccache" + depends on HYPERVISOR_V0_6 + default n + +endmenu + +menu "LoongArch platform" + depends on ARCH_LOONGARCH64 + +config LOONGSON_3A5000 + bool "Loongson 3A5000 CPU profile" + default n + +config LOONGSON_3A6000 + bool "Loongson 3A6000 CPU profile" + default n +endmenu + +menu "UART" + +config PL011 + bool "PL011" + depends on ARCH_AARCH64 + default n + +config IMX_UART + bool "iMX UART" + depends on ARCH_AARCH64 + default n + +config XUARTPS + bool "XUARTPS" + depends on ARCH_AARCH64 + default n + +config UART_16550 + bool "UART_16550" + depends on ARCH_AARCH64 + default n + +config UART16550A + bool "UART16550A" + depends on ARCH_X86_64 + default n + +config LOONGSON_UART + bool "Loongson UART" + depends on ARCH_LOONGARCH64 + default n +endmenu + +menu "PCIe" + +config PCI + bool "PCI/PCIe support" + default n + +choice + prompt "PCIe Architecture" + depends on PCI + default PCIE_ECAM + +config PCIE_ECAM + bool "ECAM PCIe" + +config PCIE_DWC + bool "DesignWare Core PCIe" + +config PCIE_LOONGARCH64 + bool "LoongArch PCIe" + depends on ARCH_LOONGARCH64 + +endchoice + +config NO_PCIE_BAR_REALLOC + bool "Do not reallocate PCIe BARs (board-specific)" + depends on PCI + default n + +config VIRTIO_PCI + bool "Virtio over PCI" + depends on PCI && IRQ_GICV3 + default n +endmenu + +menu "IOMMU" + +config IOMMU + bool + default n + +config ARM_SMMU + bool "ARM SMMU" + depends on ARCH_AARCH64 + select IOMMU + default n + +config INTEL_VTD + bool "Intel VT-d" + depends on ARCH_X86_64 + select IOMMU + default n + +config RISCV_IOMMU + bool "RISC-V IOMMU" + depends on ARCH_RISCV64 + select IOMMU + default n + +config SHARE_S2PT + bool "Share stage-2 page tables with IOMMU (RISC-V IOMMU only)" + depends on RISCV_IOMMU + default n + +config VIOMMU + bool "Virtual RISC-V IOMMU" + depends on RISCV_IOMMU + default n +endmenu + +menu "x86-specific options" + depends on ARCH_X86_64 + +config GRAPHICS + bool "Framebuffer / graphics" + default n + +config SPLIT_SCREEN + bool "Split screen layout" + depends on GRAPHICS + default n + +config PRINT_TIMESTAMP + bool "Print timestamp in logs" + default n +endmenu + +menu "Debug" + +config EXTIOI_DEBUG + bool "EXTIOI debug (LoongArch LS7A2000)" + depends on ARCH_LOONGARCH64 + default n +endmenu diff --git a/kconfig/cfg_map.toml b/kconfig/cfg_map.toml new file mode 100644 index 00000000..5540b5cd --- /dev/null +++ b/kconfig/cfg_map.toml @@ -0,0 +1,38 @@ +# Kconfig / .config symbol -> rustc cfg name (must match #[cfg(...)] in source). +# Keys are exactly as in .config (CONFIG_*). +[symbols] +CONFIG_IRQ_GICV2 = "irq_gicv2" +CONFIG_IRQ_GICV3 = "irq_gicv3" +CONFIG_PL011 = "pl011" +CONFIG_IMX_UART = "imx_uart" +CONFIG_XUARTPS = "xuartps" +CONFIG_UART_16550 = "uart_16550" +CONFIG_UART16550A = "uart16550a" +CONFIG_LOONGSON_UART = "loongson_uart" +CONFIG_PCI = "pci" +CONFIG_PCIE_ECAM = "ecam_pcie" +CONFIG_PCIE_DWC = "dwc_pcie" +CONFIG_PCIE_LOONGARCH64 = "loongarch64_pcie" +CONFIG_NO_PCIE_BAR_REALLOC = "no_pcie_bar_realloc" +CONFIG_VIRTIO_PCI = "virtio_pci" +CONFIG_IOMMU = "iommu" +CONFIG_SHARE_S2PT = "share_s2pt" +CONFIG_ARM_SMMU = "arm_smmu" +CONFIG_INTEL_VTD = "intel_vtd" +CONFIG_RISCV_IOMMU = "riscv_iommu" +CONFIG_VIOMMU = "viommu" +CONFIG_PLIC = "plic" +CONFIG_DP1000_PLIC = "dp1000_plic" +CONFIG_AIA = "aia" +CONFIG_ACLINT = "aclint" +CONFIG_SSTC = "sstc" +CONFIG_HYPERVISOR_V0_6 = "hypervisor_v0_6" +CONFIG_EIC7700_SYSREG = "eic7700_sysreg" +CONFIG_SIFIVE_CCACHE = "sifive_ccache" +CONFIG_LOONGSON_7A2000 = "loongson_7a2000" +CONFIG_LOONGSON_3A5000 = "loongson_3a5000" +CONFIG_LOONGSON_3A6000 = "loongson_3a6000" +CONFIG_GRAPHICS = "graphics" +CONFIG_SPLIT_SCREEN = "split_screen" +CONFIG_PRINT_TIMESTAMP = "print_timestamp" +CONFIG_EXTIOI_DEBUG = "extioi_debug" diff --git a/platform/aarch64/imx8mp/cargo/features b/platform/aarch64/imx8mp/cargo/features deleted file mode 100644 index 7acf44c6..00000000 --- a/platform/aarch64/imx8mp/cargo/features +++ /dev/null @@ -1,2 +0,0 @@ -gicv3 -imx_uart diff --git a/platform/aarch64/imx8mp/kconfig/defconfig b/platform/aarch64/imx8mp/kconfig/defconfig new file mode 100644 index 00000000..d9c75b09 --- /dev/null +++ b/platform/aarch64/imx8mp/kconfig/defconfig @@ -0,0 +1,3 @@ +CONFIG_ARCH_AARCH64=y +CONFIG_IMX_UART=y +CONFIG_IRQ_GICV3=y diff --git a/platform/aarch64/imx8mp/platform.mk b/platform/aarch64/imx8mp/platform.mk index 5e5809f0..d4014f9a 100644 --- a/platform/aarch64/imx8mp/platform.mk +++ b/platform/aarch64/imx8mp/platform.mk @@ -1,6 +1,6 @@ QEMU := qemu-system-aarch64 -ifeq ($(findstring gicv3, $(FEATURES)),gicv3) +ifneq ($(shell grep -Fx CONFIG_IRQ_GICV3=y platform/$(ARCH)/$(BOARD)/kconfig/defconfig 2>/dev/null),) UBOOT := $(image_dir)/bootloader/u-boot-atf.bin zone0_dtb := $(image_dir)/devicetree/linux1.dtb QEMU_ARGS := -machine virt,secure=on,gic-version=3,virtualization=on,iommu=smmuv3 diff --git a/platform/aarch64/ok6254-c/cargo/features b/platform/aarch64/ok6254-c/cargo/features deleted file mode 100644 index afa59489..00000000 --- a/platform/aarch64/ok6254-c/cargo/features +++ /dev/null @@ -1,2 +0,0 @@ -gicv3 -uart_16550 diff --git a/platform/aarch64/ok6254-c/kconfig/defconfig b/platform/aarch64/ok6254-c/kconfig/defconfig new file mode 100644 index 00000000..242faa32 --- /dev/null +++ b/platform/aarch64/ok6254-c/kconfig/defconfig @@ -0,0 +1,3 @@ +CONFIG_ARCH_AARCH64=y +CONFIG_IRQ_GICV3=y +CONFIG_UART_16550=y diff --git a/platform/aarch64/phytium-pi/cargo/features b/platform/aarch64/phytium-pi/cargo/features deleted file mode 100644 index 416c6913..00000000 --- a/platform/aarch64/phytium-pi/cargo/features +++ /dev/null @@ -1,2 +0,0 @@ -gicv3 -pl011 \ No newline at end of file diff --git a/platform/aarch64/phytium-pi/kconfig/defconfig b/platform/aarch64/phytium-pi/kconfig/defconfig new file mode 100644 index 00000000..f24edf75 --- /dev/null +++ b/platform/aarch64/phytium-pi/kconfig/defconfig @@ -0,0 +1,3 @@ +CONFIG_ARCH_AARCH64=y +CONFIG_IRQ_GICV3=y +CONFIG_PL011=y diff --git a/platform/aarch64/phytium-pi/platform.mk b/platform/aarch64/phytium-pi/platform.mk index 061516bc..46c77377 100644 --- a/platform/aarch64/phytium-pi/platform.mk +++ b/platform/aarch64/phytium-pi/platform.mk @@ -1,6 +1,6 @@ QEMU := qemu-system-aarch64 -ifeq ($(findstring gicv3, $(FEATURES)),gicv3) +ifneq ($(shell grep -Fx CONFIG_IRQ_GICV3=y platform/$(ARCH)/$(BOARD)/kconfig/defconfig 2>/dev/null),) UBOOT := $(image_dir)/bootloader/u-boot-atf.bin zone0_dtb := $(image_dir)/devicetree/linux1.dtb QEMU_ARGS := -machine virt,secure=on,gic-version=3,virtualization=on,iommu=smmuv3 diff --git a/platform/aarch64/qemu-gicv2/cargo/features b/platform/aarch64/qemu-gicv2/cargo/features deleted file mode 100644 index e0ed82fd..00000000 --- a/platform/aarch64/qemu-gicv2/cargo/features +++ /dev/null @@ -1,4 +0,0 @@ -gicv2 -pl011 -arm_smmu -pci diff --git a/platform/aarch64/qemu-gicv2/kconfig/defconfig b/platform/aarch64/qemu-gicv2/kconfig/defconfig new file mode 100644 index 00000000..fb8f4ff3 --- /dev/null +++ b/platform/aarch64/qemu-gicv2/kconfig/defconfig @@ -0,0 +1,7 @@ +CONFIG_ARCH_AARCH64=y +CONFIG_ARM_SMMU=y +CONFIG_IOMMU=y +CONFIG_IRQ_GICV2=y +CONFIG_PCI=y +CONFIG_PCIE_ECAM=y +CONFIG_PL011=y diff --git a/platform/aarch64/qemu-gicv3/cargo/features b/platform/aarch64/qemu-gicv3/cargo/features deleted file mode 100644 index cf034a83..00000000 --- a/platform/aarch64/qemu-gicv3/cargo/features +++ /dev/null @@ -1,6 +0,0 @@ -gicv3 -pl011 -arm_smmu -pci -ecam_pcie -virtio_pci \ No newline at end of file diff --git a/platform/aarch64/qemu-gicv3/kconfig/defconfig b/platform/aarch64/qemu-gicv3/kconfig/defconfig new file mode 100644 index 00000000..674eecc5 --- /dev/null +++ b/platform/aarch64/qemu-gicv3/kconfig/defconfig @@ -0,0 +1,8 @@ +CONFIG_ARCH_AARCH64=y +CONFIG_ARM_SMMU=y +CONFIG_IOMMU=y +CONFIG_IRQ_GICV3=y +CONFIG_PCI=y +CONFIG_PCIE_ECAM=y +CONFIG_PL011=y +CONFIG_VIRTIO_PCI=y diff --git a/platform/aarch64/rk3568/cargo/features b/platform/aarch64/rk3568/cargo/features deleted file mode 100644 index 0b11e0fa..00000000 --- a/platform/aarch64/rk3568/cargo/features +++ /dev/null @@ -1,5 +0,0 @@ -gicv3 -uart_16550 -pci -dwc_pcie -no_pcie_bar_realloc \ No newline at end of file diff --git a/platform/aarch64/rk3568/kconfig/defconfig b/platform/aarch64/rk3568/kconfig/defconfig new file mode 100644 index 00000000..212ee3ba --- /dev/null +++ b/platform/aarch64/rk3568/kconfig/defconfig @@ -0,0 +1,6 @@ +CONFIG_ARCH_AARCH64=y +CONFIG_IRQ_GICV3=y +CONFIG_NO_PCIE_BAR_REALLOC=y +CONFIG_PCI=y +CONFIG_PCIE_DWC=y +CONFIG_UART_16550=y diff --git a/platform/aarch64/rk3588/cargo/features b/platform/aarch64/rk3588/cargo/features deleted file mode 100644 index afa59489..00000000 --- a/platform/aarch64/rk3588/cargo/features +++ /dev/null @@ -1,2 +0,0 @@ -gicv3 -uart_16550 diff --git a/platform/aarch64/rk3588/kconfig/defconfig b/platform/aarch64/rk3588/kconfig/defconfig new file mode 100644 index 00000000..242faa32 --- /dev/null +++ b/platform/aarch64/rk3588/kconfig/defconfig @@ -0,0 +1,3 @@ +CONFIG_ARCH_AARCH64=y +CONFIG_IRQ_GICV3=y +CONFIG_UART_16550=y diff --git a/platform/aarch64/sysoul_x3300/cargo/features b/platform/aarch64/sysoul_x3300/cargo/features deleted file mode 100644 index afa59489..00000000 --- a/platform/aarch64/sysoul_x3300/cargo/features +++ /dev/null @@ -1,2 +0,0 @@ -gicv3 -uart_16550 diff --git a/platform/aarch64/sysoul_x3300/kconfig/defconfig b/platform/aarch64/sysoul_x3300/kconfig/defconfig new file mode 100644 index 00000000..242faa32 --- /dev/null +++ b/platform/aarch64/sysoul_x3300/kconfig/defconfig @@ -0,0 +1,3 @@ +CONFIG_ARCH_AARCH64=y +CONFIG_IRQ_GICV3=y +CONFIG_UART_16550=y diff --git a/platform/aarch64/zcu102/cargo/features b/platform/aarch64/zcu102/cargo/features deleted file mode 100644 index 4189d149..00000000 --- a/platform/aarch64/zcu102/cargo/features +++ /dev/null @@ -1,2 +0,0 @@ -gicv2 -xuartps diff --git a/platform/aarch64/zcu102/kconfig/defconfig b/platform/aarch64/zcu102/kconfig/defconfig new file mode 100644 index 00000000..b3563178 --- /dev/null +++ b/platform/aarch64/zcu102/kconfig/defconfig @@ -0,0 +1,3 @@ +CONFIG_ARCH_AARCH64=y +CONFIG_IRQ_GICV2=y +CONFIG_XUARTPS=y diff --git a/platform/loongarch64/ls3a5000/cargo/features b/platform/loongarch64/ls3a5000/cargo/features deleted file mode 100644 index 442505f4..00000000 --- a/platform/loongarch64/ls3a5000/cargo/features +++ /dev/null @@ -1,7 +0,0 @@ -loongson_3a5000 -loongson_7a2000 -loongson_uart - -pci -loongarch64_pcie -no_pcie_bar_realloc \ No newline at end of file diff --git a/platform/loongarch64/ls3a5000/kconfig/defconfig b/platform/loongarch64/ls3a5000/kconfig/defconfig new file mode 100644 index 00000000..c061a0fd --- /dev/null +++ b/platform/loongarch64/ls3a5000/kconfig/defconfig @@ -0,0 +1,7 @@ +CONFIG_ARCH_LOONGARCH64=y +CONFIG_LOONGSON_3A5000=y +CONFIG_LOONGSON_7A2000=y +CONFIG_LOONGSON_UART=y +CONFIG_NO_PCIE_BAR_REALLOC=y +CONFIG_PCI=y +CONFIG_PCIE_LOONGARCH64=y diff --git a/platform/loongarch64/ls3a6000/cargo/features b/platform/loongarch64/ls3a6000/cargo/features deleted file mode 100644 index 86cd7a5c..00000000 --- a/platform/loongarch64/ls3a6000/cargo/features +++ /dev/null @@ -1,7 +0,0 @@ -loongson_3a6000 -loongson_7a2000 -loongson_uart - -pci -loongarch64_pcie -no_pcie_bar_realloc \ No newline at end of file diff --git a/platform/loongarch64/ls3a6000/kconfig/defconfig b/platform/loongarch64/ls3a6000/kconfig/defconfig new file mode 100644 index 00000000..ef0a73e9 --- /dev/null +++ b/platform/loongarch64/ls3a6000/kconfig/defconfig @@ -0,0 +1,7 @@ +CONFIG_ARCH_LOONGARCH64=y +CONFIG_LOONGSON_3A6000=y +CONFIG_LOONGSON_7A2000=y +CONFIG_LOONGSON_UART=y +CONFIG_NO_PCIE_BAR_REALLOC=y +CONFIG_PCI=y +CONFIG_PCIE_LOONGARCH64=y diff --git a/platform/riscv64/hifive-premier-p550/cargo/features b/platform/riscv64/hifive-premier-p550/cargo/features deleted file mode 100644 index d72ea9ac..00000000 --- a/platform/riscv64/hifive-premier-p550/cargo/features +++ /dev/null @@ -1,4 +0,0 @@ -eic770x_soc -plic -eic7700_sysreg -sifive_ccache diff --git a/platform/riscv64/hifive-premier-p550/kconfig/defconfig b/platform/riscv64/hifive-premier-p550/kconfig/defconfig new file mode 100644 index 00000000..769ea39d --- /dev/null +++ b/platform/riscv64/hifive-premier-p550/kconfig/defconfig @@ -0,0 +1,5 @@ +CONFIG_ARCH_RISCV64=y +CONFIG_EIC7700_SYSREG=y +CONFIG_HYPERVISOR_V0_6=y +CONFIG_PLIC=y +CONFIG_SIFIVE_CCACHE=y diff --git a/platform/riscv64/megrez/cargo/features b/platform/riscv64/megrez/cargo/features deleted file mode 100644 index d1314d86..00000000 --- a/platform/riscv64/megrez/cargo/features +++ /dev/null @@ -1,2 +0,0 @@ -eic770x_soc -plic diff --git a/platform/riscv64/megrez/kconfig/defconfig b/platform/riscv64/megrez/kconfig/defconfig new file mode 100644 index 00000000..54604c28 --- /dev/null +++ b/platform/riscv64/megrez/kconfig/defconfig @@ -0,0 +1,3 @@ +CONFIG_ARCH_RISCV64=y +CONFIG_HYPERVISOR_V0_6=y +CONFIG_PLIC=y diff --git a/platform/riscv64/qemu-aia/cargo/features b/platform/riscv64/qemu-aia/cargo/features deleted file mode 100644 index b0b27b6d..00000000 --- a/platform/riscv64/qemu-aia/cargo/features +++ /dev/null @@ -1,7 +0,0 @@ -aia -sstc -pci -ecam_pcie -riscv_iommu -share_s2pt -viommu diff --git a/platform/riscv64/qemu-aia/kconfig/defconfig b/platform/riscv64/qemu-aia/kconfig/defconfig new file mode 100644 index 00000000..70c7639e --- /dev/null +++ b/platform/riscv64/qemu-aia/kconfig/defconfig @@ -0,0 +1,9 @@ +CONFIG_AIA=y +CONFIG_ARCH_RISCV64=y +CONFIG_IOMMU=y +CONFIG_PCI=y +CONFIG_PCIE_ECAM=y +CONFIG_RISCV_IOMMU=y +CONFIG_SHARE_S2PT=y +CONFIG_VIOMMU=y +CONFIG_SSTC=y diff --git a/platform/riscv64/qemu-plic/README.md b/platform/riscv64/qemu-plic/README.md index b6884c55..898babb3 100644 --- a/platform/riscv64/qemu-plic/README.md +++ b/platform/riscv64/qemu-plic/README.md @@ -73,5 +73,5 @@ Both the root zone and zone1 are assigned one virtio-pci-blk device(using wired- Please confirm qemu-system-riscv64 version >= 10.0.0, add iommu-sys=on for machine param and iommu_platform=on for devices linked behind iommu. (refer to platform.mk) -Add `iommu` and `share_s2pt` features for hvisor. +Enable IOMMU in **`kconfig/defconfig`** (`CONFIG_IOMMU`, `CONFIG_RISCV_IOMMU`, `CONFIG_SHARE_S2PT`, etc.) for hvisor. diff --git a/platform/riscv64/qemu-plic/cargo/features b/platform/riscv64/qemu-plic/cargo/features deleted file mode 100644 index 6be000e7..00000000 --- a/platform/riscv64/qemu-plic/cargo/features +++ /dev/null @@ -1,5 +0,0 @@ -aclint -plic -sstc -pci -ecam_pcie diff --git a/platform/riscv64/qemu-plic/kconfig/defconfig b/platform/riscv64/qemu-plic/kconfig/defconfig new file mode 100644 index 00000000..e3556c4f --- /dev/null +++ b/platform/riscv64/qemu-plic/kconfig/defconfig @@ -0,0 +1,6 @@ +CONFIG_ACLINT=y +CONFIG_ARCH_RISCV64=y +CONFIG_PCI=y +CONFIG_PCIE_ECAM=y +CONFIG_PLIC=y +CONFIG_SSTC=y diff --git a/platform/riscv64/ur-dp1000/cargo/features b/platform/riscv64/ur-dp1000/cargo/features deleted file mode 100644 index cac3e049..00000000 --- a/platform/riscv64/ur-dp1000/cargo/features +++ /dev/null @@ -1,2 +0,0 @@ -plic -dp1000_plic diff --git a/platform/riscv64/ur-dp1000/kconfig/defconfig b/platform/riscv64/ur-dp1000/kconfig/defconfig new file mode 100644 index 00000000..58f138b2 --- /dev/null +++ b/platform/riscv64/ur-dp1000/kconfig/defconfig @@ -0,0 +1,3 @@ +CONFIG_ARCH_RISCV64=y +CONFIG_DP1000_PLIC=y +CONFIG_PLIC=y diff --git a/platform/x86_64/ecx-2300f-peg/board.rs b/platform/x86_64/ecx-2300f-peg/board.rs index 1b295342..e628dd84 100644 --- a/platform/x86_64/ecx-2300f-peg/board.rs +++ b/platform/x86_64/ecx-2300f-peg/board.rs @@ -180,6 +180,6 @@ pub const ROOT_PCI_DEVS: [HvPciDevConfig; 19] = [ pci_dev!(0x0, 0x3, 0x0, 0x0, VpciDevType::Physical), // ethernet controller ]; -#[cfg(all(feature = "graphics"))] +#[cfg(all(graphics))] pub const GRAPHICS_FONT: &[u8] = include_bytes!("../../platform/x86_64/qemu/image/font/spleen-6x12.psf"); diff --git a/platform/x86_64/ecx-2300f-peg/cargo/features b/platform/x86_64/ecx-2300f-peg/cargo/features deleted file mode 100644 index e4ad1c13..00000000 --- a/platform/x86_64/ecx-2300f-peg/cargo/features +++ /dev/null @@ -1,2 +0,0 @@ -pci -uart16550a diff --git a/platform/x86_64/ecx-2300f-peg/kconfig/defconfig b/platform/x86_64/ecx-2300f-peg/kconfig/defconfig new file mode 100644 index 00000000..770397db --- /dev/null +++ b/platform/x86_64/ecx-2300f-peg/kconfig/defconfig @@ -0,0 +1,4 @@ +CONFIG_ARCH_X86_64=y +CONFIG_PCI=y +CONFIG_PCIE_ECAM=y +CONFIG_UART16550A=y diff --git a/platform/x86_64/nuc14mnk/board.rs b/platform/x86_64/nuc14mnk/board.rs index bceb2bfe..b59520f4 100644 --- a/platform/x86_64/nuc14mnk/board.rs +++ b/platform/x86_64/nuc14mnk/board.rs @@ -200,6 +200,6 @@ pub const ROOT_PCI_DEVS: [HvPciDevConfig; 18] = [ pci_dev!(0x0, 0x2, 0x0, 0x0, VpciDevType::Physical), // memory controller ]; -#[cfg(all(feature = "graphics"))] +#[cfg(all(graphics))] pub const GRAPHICS_FONT: &[u8] = include_bytes!("../../platform/x86_64/qemu/image/font/spleen-6x12.psf"); diff --git a/platform/x86_64/nuc14mnk/cargo/features b/platform/x86_64/nuc14mnk/cargo/features deleted file mode 100644 index 69fb95c9..00000000 --- a/platform/x86_64/nuc14mnk/cargo/features +++ /dev/null @@ -1,6 +0,0 @@ -pci -ecam_pcie -no_pcie_bar_realloc -uart16550a -graphics -split_screen \ No newline at end of file diff --git a/platform/x86_64/nuc14mnk/kconfig/defconfig b/platform/x86_64/nuc14mnk/kconfig/defconfig new file mode 100644 index 00000000..fb35c8fc --- /dev/null +++ b/platform/x86_64/nuc14mnk/kconfig/defconfig @@ -0,0 +1,7 @@ +CONFIG_ARCH_X86_64=y +CONFIG_GRAPHICS=y +CONFIG_NO_PCIE_BAR_REALLOC=y +CONFIG_PCI=y +CONFIG_PCIE_ECAM=y +CONFIG_SPLIT_SCREEN=y +CONFIG_UART16550A=y diff --git a/platform/x86_64/qemu/board.rs b/platform/x86_64/qemu/board.rs index a0a420b5..c3dc8669 100644 --- a/platform/x86_64/qemu/board.rs +++ b/platform/x86_64/qemu/board.rs @@ -160,6 +160,6 @@ pub const ROOT_PCI_DEVS: [HvPciDevConfig; 7] = [ pci_dev!(0x0, 0x1, 0x0, 0x0, VpciDevType::Physical), // SCSI controller ]; -#[cfg(all(feature = "graphics"))] +#[cfg(all(graphics))] pub const GRAPHICS_FONT: &[u8] = include_bytes!("../../platform/x86_64/qemu/image/font/spleen-6x12.psf"); diff --git a/platform/x86_64/qemu/cargo/features b/platform/x86_64/qemu/cargo/features deleted file mode 100644 index fc6ef1e6..00000000 --- a/platform/x86_64/qemu/cargo/features +++ /dev/null @@ -1,5 +0,0 @@ -pci -ecam_pcie -no_pcie_bar_realloc -uart16550a -intel_vtd \ No newline at end of file diff --git a/platform/x86_64/qemu/kconfig/defconfig b/platform/x86_64/qemu/kconfig/defconfig new file mode 100644 index 00000000..007ce348 --- /dev/null +++ b/platform/x86_64/qemu/kconfig/defconfig @@ -0,0 +1,7 @@ +CONFIG_ARCH_X86_64=y +CONFIG_INTEL_VTD=y +CONFIG_IOMMU=y +CONFIG_NO_PCIE_BAR_REALLOC=y +CONFIG_PCI=y +CONFIG_PCIE_ECAM=y +CONFIG_UART16550A=y diff --git a/src/arch/riscv64/cpu.rs b/src/arch/riscv64/cpu.rs index a9c54238..bc6997db 100644 --- a/src/arch/riscv64/cpu.rs +++ b/src/arch/riscv64/cpu.rs @@ -52,7 +52,7 @@ impl ArchCpu { stack_top: 0, cpuid, // first_cpu: 0, - sstc: cfg!(feature = "sstc"), + sstc: cfg!(sstc), }; ret } @@ -68,7 +68,7 @@ impl ArchCpu { write_csr!(CSR_SSCRATCH, self as *const _ as usize); //arch cpu pointer self.sepc = entry; self.hstatus = 1 << 7 | 2 << 32; // HSTATUS_SPV | HSTATUS_VSXL_64 - #[cfg(feature = "aia")] + #[cfg(aia)] { self.hstatus |= 1 << 12; // HSTATUS_VGEIN } @@ -87,7 +87,7 @@ impl ArchCpu { set_csr!(CSR_VSTIMECMP, usize::MAX); } else { // In megrez board, this instruction is not supported. (illegal instruction) - #[cfg(not(feature = "eic770x_soc"))] + #[cfg(not(hypervisor_v0_6))] set_csr!(CSR_HENVCFG, 0); } set_csr!(CSR_HCOUNTEREN, 1 << 1); // HCOUNTEREN_TM diff --git a/src/arch/riscv64/ipi.rs b/src/arch/riscv64/ipi.rs index d4ad55d2..242023ca 100644 --- a/src/arch/riscv64/ipi.rs +++ b/src/arch/riscv64/ipi.rs @@ -15,7 +15,7 @@ // Jingyu Liu // use crate::consts::IPI_EVENT_SEND_IPI; -#[cfg(feature = "plic")] +#[cfg(plic)] use crate::consts::IPI_EVENT_UPDATE_HART_LINE; use crate::platform::BOARD_HARTID_MAP; @@ -23,9 +23,9 @@ use crate::platform::BOARD_HARTID_MAP; pub fn arch_send_event(cpu_id: u64, _sgi_num: u64) { let hart_id = BOARD_HARTID_MAP[cpu_id as usize]; debug!("arch_send_event: cpu_id: {}", hart_id); - #[cfg(feature = "aclint")] + #[cfg(aclint)] crate::device::irqchip::aclint::aclint_send_ipi(hart_id as usize); - #[cfg(not(feature = "aclint"))] + #[cfg(not(aclint))] { let sbi_ret: sbi_rt::SbiRet = sbi_rt::send_ipi(sbi_rt::HartMask::from_mask_base(1 << hart_id, 0)); @@ -44,7 +44,7 @@ pub fn arch_ipi_handler() { pub fn arch_check_events(event: Option) { match event { - #[cfg(feature = "plic")] + #[cfg(plic)] Some(IPI_EVENT_UPDATE_HART_LINE) => { use crate::device::irqchip::plic::update_hart_line; update_hart_line(); diff --git a/src/arch/riscv64/trap.rs b/src/arch/riscv64/trap.rs index 99277f72..4c8de184 100644 --- a/src/arch/riscv64/trap.rs +++ b/src/arch/riscv64/trap.rs @@ -15,7 +15,7 @@ // use super::cpu::ArchCpu; use crate::arch::sbi::sbi_vs_handler; -#[cfg(feature = "plic")] +#[cfg(plic)] use crate::device::irqchip::plic::{inject_irq, plic_get_hwirq}; use crate::event::check_events; use crate::memory::GuestPhysAddr; @@ -417,7 +417,7 @@ pub fn handle_software_interrupt(_current_cpu: &mut ArchCpu) { /// Handle supervisor external interrupt. pub fn handle_external_interrupt(_current_cpu: &mut ArchCpu) { - #[cfg(feature = "plic")] + #[cfg(plic)] { // Note: in hvisor, all external interrupts are assigned to VS. // 1. claim hw irq. @@ -431,7 +431,7 @@ pub fn handle_external_interrupt(_current_cpu: &mut ArchCpu) { // 2. inject hw irq to zone. inject_irq(irq_id as usize, true); } - #[cfg(feature = "aia")] + #[cfg(aia)] { // Note: no irq belongs to hvisor, so hvisor won't handle external interrupt. panic!("HS extensional interrupt") diff --git a/src/arch/x86_64/boot.rs b/src/arch/x86_64/boot.rs index b3191ef1..c3ec4636 100644 --- a/src/arch/x86_64/boot.rs +++ b/src/arch/x86_64/boot.rs @@ -394,9 +394,9 @@ impl BootParams { let bytes_per_pixel = (fb_info.bpp as usize) / 8; let width = fb_info.width as usize; - #[cfg(not(feature = "split_screen"))] + #[cfg(not(split_screen))] let height = fb_info.height as usize; - #[cfg(all(feature = "split_screen"))] + #[cfg(all(split_screen))] let height = (fb_info.height / 2) as usize; self.screen_info.lfb_base = config.arch_config.screen_base as _; diff --git a/src/arch/x86_64/cpu.rs b/src/arch/x86_64/cpu.rs index fd56d747..97d69ccd 100644 --- a/src/arch/x86_64/cpu.rs +++ b/src/arch/x86_64/cpu.rs @@ -296,7 +296,7 @@ impl ArchCpu { if per_cpu.boot_cpu { // must be called after activate_gpm() - #[cfg(feature = "intel_vtd")] + #[cfg(intel_vtd)] iommu::activate(); self.guest_regs = self.vm_launch_guest_regs.clone(); } diff --git a/src/arch/x86_64/entry.rs b/src/arch/x86_64/entry.rs index 2a6db8bd..9b7a883b 100644 --- a/src/arch/x86_64/entry.rs +++ b/src/arch/x86_64/entry.rs @@ -80,7 +80,7 @@ extern "C" fn rust_entry(magic: u32, info_addr: usize) { crate::clear_bss(); unsafe { PHYS_VIRT_OFFSET = X86_PHYS_VIRT_OFFSET }; boot::multiboot_init(info_addr); - #[cfg(all(feature = "graphics"))] + #[cfg(all(graphics))] font_init(__board::GRAPHICS_FONT); boot::print_memory_map(); rust_main(this_apic_id(), info_addr); diff --git a/src/arch/x86_64/graphics.rs b/src/arch/x86_64/graphics.rs index 2097e401..34367850 100644 --- a/src/arch/x86_64/graphics.rs +++ b/src/arch/x86_64/graphics.rs @@ -94,18 +94,18 @@ pub fn font_init(psf: &'static [u8]) { cursor_x: 0, cursor_y: 0, max_char_nr_x: (framebuffer.width / font_width) as _, - #[cfg(not(feature = "split_screen"))] + #[cfg(not(split_screen))] max_char_nr_y: (framebuffer.height / psf_header.height) as _, - #[cfg(all(feature = "split_screen"))] + #[cfg(all(split_screen))] max_char_nr_y: (framebuffer.height / 2 / psf_header.height) as _, - #[cfg(not(feature = "split_screen"))] + #[cfg(not(split_screen))] addr: framebuffer.addr as _, - #[cfg(all(feature = "split_screen"))] + #[cfg(all(split_screen))] addr: mid_addr as _, width: framebuffer.width as _, - #[cfg(not(feature = "split_screen"))] + #[cfg(not(split_screen))] height: framebuffer.height as _, - #[cfg(all(feature = "split_screen"))] + #[cfg(all(split_screen))] height: (framebuffer.height / 2) as _, }) }); diff --git a/src/arch/x86_64/pio.rs b/src/arch/x86_64/pio.rs index f89a5564..255e76dd 100644 --- a/src/arch/x86_64/pio.rs +++ b/src/arch/x86_64/pio.rs @@ -89,7 +89,7 @@ impl PortIoBitmap { bitmap.set_range_intercept(PCI_CONFIG_DATA_PORT, true); // if zone_id == 0 { - #[cfg(feature = "graphics")] + #[cfg(graphics)] bitmap.set_range_intercept(UART_COM1_PORT, true); // } diff --git a/src/arch/x86_64/s2pt.rs b/src/arch/x86_64/s2pt.rs index db9bed50..7d62106c 100644 --- a/src/arch/x86_64/s2pt.rs +++ b/src/arch/x86_64/s2pt.rs @@ -263,7 +263,7 @@ impl PagingInstr for S2PTInstr { // if this cpu is boot cpu and it is running if this_cpu_data().vcpu_state.is_running() && this_cpu_data().boot_cpu { - #[cfg(feature = "intel_vtd")] + #[cfg(intel_vtd)] iommu::fill_dma_translation_tables(this_zone_id(), root_paddr); } } diff --git a/src/device/iommu/arm_smmu/smmu_hw.rs b/src/device/iommu/arm_smmu/smmu_hw.rs index fe7b3244..ad34d08a 100644 --- a/src/device/iommu/arm_smmu/smmu_hw.rs +++ b/src/device/iommu/arm_smmu/smmu_hw.rs @@ -529,13 +529,13 @@ impl Smmuv3 { static SMMUV3: spin::Once> = spin::Once::new(); /// iommu feature is disabled. -#[cfg(not(feature = "iommu"))] +#[cfg(not(iommu))] pub fn iommu_init() { info!("aarch64: iommu_init: do nothing now"); } /// smmuv3 init (enabled) -#[cfg(feature = "iommu")] +#[cfg(iommu)] pub fn iommu_init() { info!("Smmuv3 init..."); SMMUV3.call_once(|| Mutex::new(Smmuv3::new())); diff --git a/src/device/iommu/iommu_impl.rs b/src/device/iommu/iommu_impl.rs index eac9ea16..49e0d369 100644 --- a/src/device/iommu/iommu_impl.rs +++ b/src/device/iommu/iommu_impl.rs @@ -24,17 +24,17 @@ static IOMMU_IMPL: Once> = Once::new(); // Dispatch to the appropriate IOMMU implementation based on hardware support fn iommu_impl_init() -> Box { - #[cfg(feature = "arm_smmu")] + #[cfg(arm_smmu)] return Box::new(super::arm_smmu::ArmSmmu); - #[cfg(feature = "intel_vtd")] + #[cfg(intel_vtd)] return Box::new(super::intel_vtd::IntelVtd); - #[cfg(feature = "riscv_iommu")] + #[cfg(riscv_iommu)] return Box::new(super::riscv_iommu::RiscvIommu); // Default return DummyIommu if no IOMMU support - #[cfg(not(any(feature = "arm_smmu", feature = "intel_vtd", feature = "riscv_iommu",)))] + #[cfg(not(any(arm_smmu, intel_vtd, riscv_iommu)))] return Box::new(super::dummy_iommu::DummyIommu); } diff --git a/src/device/iommu/mod.rs b/src/device/iommu/mod.rs index 37cd69d0..0bb46391 100644 --- a/src/device/iommu/mod.rs +++ b/src/device/iommu/mod.rs @@ -26,13 +26,13 @@ use crate::zone::Zone; use iommu_impl::iommu_impl; use iommu_trait::Iommu; -#[cfg(feature = "arm_smmu")] +#[cfg(arm_smmu)] mod arm_smmu; -#[cfg(not(any(feature = "arm_smmu", feature = "intel_vtd", feature = "riscv_iommu")))] +#[cfg(not(any(arm_smmu, intel_vtd, riscv_iommu)))] mod dummy_iommu; -#[cfg(feature = "intel_vtd")] +#[cfg(intel_vtd)] mod intel_vtd; -#[cfg(feature = "riscv_iommu")] +#[cfg(riscv_iommu)] mod riscv_iommu; fn check_zone_id(zone_id: usize) -> Result<(), &'static str> { @@ -93,28 +93,28 @@ pub(crate) fn viommu_mmio_handler_register(zone: &Zone, viommu_base: usize, viom // Below pub apis are used for compatibility for old code(for x86_64) // // These apis will be replaced by IOMMU trait later. // //////////////////////////////////////////////////////////////////////// -#[cfg(feature = "intel_vtd")] +#[cfg(intel_vtd)] pub fn clear_dma_translation_tables(zone_id: usize) { intel_vtd::clear_dma_translation_tables(zone_id); } -#[cfg(feature = "intel_vtd")] +#[cfg(intel_vtd)] pub fn fill_dma_translation_tables(zone_id: usize, zone_s2pt_hpa: crate::memory::HostPhysAddr) { intel_vtd::fill_dma_translation_tables(zone_id, zone_s2pt_hpa); } /// should be called after gpm is activated -#[cfg(feature = "intel_vtd")] +#[cfg(intel_vtd)] pub fn activate() { intel_vtd::activate(); } -#[cfg(feature = "intel_vtd")] +#[cfg(intel_vtd)] pub fn flush(zone_id: usize, bus: u8, dev_func: u8) { intel_vtd::flush(zone_id, bus, dev_func); } -#[cfg(feature = "riscv_iommu")] +#[cfg(riscv_iommu)] pub fn iommu_msi_pt_tlb_invalid(zone_id: u16, msi_gpa: usize) { riscv_iommu::iommu_msi_pt_tlb_invalid(zone_id, msi_gpa); } diff --git a/src/device/iommu/riscv_iommu/iommu_hw.rs b/src/device/iommu/riscv_iommu/iommu_hw.rs index c79faa8d..97262ac8 100644 --- a/src/device/iommu/riscv_iommu/iommu_hw.rs +++ b/src/device/iommu/riscv_iommu/iommu_hw.rs @@ -113,15 +113,15 @@ fn get_iommu<'a>() -> &'a Mutex { /// Initialize IOMMU with default mode pub fn iommu_init() { - #[cfg(feature = "iommu")] + #[cfg(iommu)] riscv_iommu_init(); - #[cfg(not(feature = "iommu"))] + #[cfg(not(iommu))] info!("RISC-V IOMMU: do nothing now"); } /// Add a device to IOMMU pub fn iommu_add_device(vm_id: usize, device_id: usize, root_pt: usize) { - #[cfg(feature = "iommu")] + #[cfg(iommu)] { info!( "RV IOMMU: Add device, root_pt {:#x}, vm_id {}, device_id {}", @@ -130,13 +130,13 @@ pub fn iommu_add_device(vm_id: usize, device_id: usize, root_pt: usize) { let iommu = get_iommu(); iommu.lock().rv_iommu_add_device(device_id, vm_id, root_pt); } - #[cfg(not(feature = "iommu"))] + #[cfg(not(iommu))] info!("RISC-V: iommu_add_device do nothing now"); } /// Remove a device from IOMMU (reserved for future hot-unplug paths). pub fn iommu_remove_device(vm_id: usize, device_id: usize) { - #[cfg(feature = "iommu")] + #[cfg(iommu)] { info!( "RV IOMMU: Remove device, vm_id {}, device_id {}", @@ -145,12 +145,12 @@ pub fn iommu_remove_device(vm_id: usize, device_id: usize) { let iommu = get_iommu(); iommu.lock().rv_iommu_remove_device(device_id); } - #[cfg(not(feature = "iommu"))] + #[cfg(not(iommu))] info!("RISC-V: iommu_remove_device do nothing now"); } pub fn iommu_msi_pt_tlb_invalid(gscid: u16, msi_gpa: usize) { - #[cfg(feature = "iommu")] + #[cfg(iommu)] { // If software changes a MSI page-table entry identified by interrupt file number I that corresponds to an // untranslated MSI address A then the following invalidations must be performed: @@ -170,7 +170,7 @@ pub fn iommu_msi_pt_tlb_invalid(gscid: u16, msi_gpa: usize) { let iommu = get_iommu(); iommu.lock().rv_iommu_msi_pt_tlb_invalid(gscid, msi_gpa); } - #[cfg(not(feature = "iommu"))] + #[cfg(not(iommu))] info!("RISC-V: iommu_msi_pt_tlb_invalid do nothing now"); } diff --git a/src/device/iommu/riscv_iommu/mod.rs b/src/device/iommu/riscv_iommu/mod.rs index 2284341f..dd823204 100644 --- a/src/device/iommu/riscv_iommu/mod.rs +++ b/src/device/iommu/riscv_iommu/mod.rs @@ -30,7 +30,7 @@ mod cmd; mod iommu_hw; mod reg_bits; -#[cfg(feature = "viommu")] +#[cfg(viommu)] mod viommu; use super::Iommu; @@ -38,7 +38,7 @@ use crate::zone::Zone; use cmd::*; use iommu_hw::*; pub use iommu_hw::{iommu_msi_pt_tlb_invalid, iommu_remove_device}; -#[cfg(feature = "viommu")] +#[cfg(viommu)] use viommu::{viommu_init, viommu_mmio_handler_register, viommu_remove}; pub(super) struct RiscvIommu; @@ -85,27 +85,27 @@ impl Iommu for RiscvIommu { ); } fn viommu_init(&self, zone_id: usize) { - #[cfg(feature = "viommu")] + #[cfg(viommu)] viommu_init(zone_id); - #[cfg(not(feature = "viommu"))] + #[cfg(not(viommu))] warn!( "Virtual IOMMU is not enabled, skipping viommu init for zone {}", zone_id ); } fn viommu_remove(&self, zone_id: usize) { - #[cfg(feature = "viommu")] + #[cfg(viommu)] viommu_remove(zone_id); - #[cfg(not(feature = "viommu"))] + #[cfg(not(viommu))] warn!( "Virtual IOMMU is not enabled, skipping viommu remove for zone {}", zone_id ); } fn viommu_mmio_handler_register(&self, zone: &Zone, viommu_base: usize, viommu_size: usize) { - #[cfg(feature = "viommu")] + #[cfg(viommu)] viommu_mmio_handler_register(zone, viommu_base, viommu_size); - #[cfg(not(feature = "viommu"))] + #[cfg(not(viommu))] warn!("Virtual IOMMU is not enabled, skipping viommu mmio handler for zone {}, viommu_base {}, viommu_size {}.", zone.id(), viommu_base, viommu_size); } } diff --git a/src/device/irqchip/aia/vimsic.rs b/src/device/irqchip/aia/vimsic.rs index c4974766..b7a1296a 100644 --- a/src/device/irqchip/aia/vimsic.rs +++ b/src/device/irqchip/aia/vimsic.rs @@ -17,7 +17,7 @@ use alloc::vec::Vec; use crate::consts::PAGE_SIZE; -#[cfg(feature = "iommu")] +#[cfg(iommu)] use crate::device::iommu::iommu_msi_pt_tlb_invalid; use crate::memory::Frame; use crate::memory::GuestPhysAddr; @@ -78,7 +78,7 @@ fn msi_pt_fill( // Fill MSI PTE to MSI PT. frame.as_slice_mut()[off..off + MSI_PTE_BYTES].copy_from_slice(&pte); // After change the MSI PTE, invalidate the related TLBs in IOMMU. - #[cfg(feature = "iommu")] + #[cfg(iommu)] iommu_msi_pt_tlb_invalid(zone_id as u16, imsic_gpa as usize); } } diff --git a/src/device/irqchip/ls7a2000/chip.rs b/src/device/irqchip/ls7a2000/chip.rs index 0b09350b..d7c56751 100644 --- a/src/device/irqchip/ls7a2000/chip.rs +++ b/src/device/irqchip/ls7a2000/chip.rs @@ -663,7 +663,7 @@ pub fn extioi_int_enable_all() { CHIP_EXTIOI_ENABLE.extioi_en1.set(0xffff_ffff_ffff_ffff); CHIP_EXTIOI_ENABLE.extioi_en2.set(0xffff_ffff_ffff_ffff); CHIP_EXTIOI_ENABLE.extioi_en3.set(0xffff_ffff_ffff_ffff); - #[cfg(feature = "extioi_debug")] + #[cfg(extioi_debug)] { // dump ht int vector and enable /* diff --git a/src/device/irqchip/mod.rs b/src/device/irqchip/mod.rs index 345c4d20..c32b0e3c 100644 --- a/src/device/irqchip/mod.rs +++ b/src/device/irqchip/mod.rs @@ -17,32 +17,32 @@ use crate::arch::zone::HvArchZoneConfig; use crate::config::HvZoneConfig; use crate::zone::Zone; -#[cfg(all(feature = "gicv2", target_arch = "aarch64"))] +#[cfg(all(irq_gicv2, target_arch = "aarch64"))] pub mod gicv2; -#[cfg(all(feature = "gicv2", target_arch = "aarch64"))] +#[cfg(all(irq_gicv2, target_arch = "aarch64"))] pub use gicv2::{ gic::inject_irq, gicd::set_ispender, percpu_init, primary_init_early, primary_init_late, vgic::set_sgi_irq, }; -#[cfg(all(feature = "gicv3", target_arch = "aarch64"))] +#[cfg(all(irq_gicv3, target_arch = "aarch64"))] pub mod gicv3; -#[cfg(all(feature = "gicv3", target_arch = "aarch64"))] +#[cfg(all(irq_gicv3, target_arch = "aarch64"))] pub use gicv3::{ gicd::set_ispender, inject_irq, percpu_init, primary_init_early, primary_init_late, }; #[cfg(target_arch = "aarch64")] pub fn gic_handle_irq() { - #[cfg(feature = "gicv2")] + #[cfg(irq_gicv2)] gicv2::gic::gicv2_handle_irq(); - #[cfg(feature = "gicv3")] + #[cfg(irq_gicv3)] gicv3::gicv3_handle_irq_el1(); } #[cfg(target_arch = "aarch64")] pub fn gic_send_event(cpu_id: u64, sgi_num: u64) { - #[cfg(feature = "gicv3")] + #[cfg(irq_gicv3)] { /*Actually, the value passed to ICC_SGI1R_EL1 should be derived from the MPIDR of the target CPU. However, since we cannot access this @@ -63,7 +63,7 @@ pub fn gic_send_event(cpu_id: u64, sgi_num: u64) { write_sysreg!(icc_sgi1r_el1, val); debug!("write sgi sys value = {:#x}", val); } - #[cfg(feature = "gicv2")] + #[cfg(irq_gicv2)] { let sgi_id: u64 = sgi_num; let target_list: u64 = 1 << cpu_id; @@ -73,11 +73,11 @@ pub fn gic_send_event(cpu_id: u64, sgi_num: u64) { impl Zone { pub fn virqc_init(&mut self, _config: &HvZoneConfig) { - #[cfg(all(feature = "plic", target_arch = "riscv64"))] + #[cfg(all(plic, target_arch = "riscv64"))] { self.vplic_init(_config); } - #[cfg(all(feature = "aia", target_arch = "riscv64"))] + #[cfg(all(aia, target_arch = "riscv64"))] { self.vaplic_init(_config); self.vimsic_init(_config); @@ -85,28 +85,28 @@ impl Zone { } pub fn mmio_init(&mut self, hv_config: &HvArchZoneConfig) { - #[cfg(all(feature = "gicv2", target_arch = "aarch64"))] + #[cfg(all(irq_gicv2, target_arch = "aarch64"))] { self.vgicv2_mmio_init(hv_config); self.vgicv2_remap_init(hv_config); } - #[cfg(all(feature = "gicv3", target_arch = "aarch64"))] + #[cfg(all(irq_gicv3, target_arch = "aarch64"))] { self.vgicv3_mmio_init(hv_config); } - #[cfg(all(feature = "plic", target_arch = "riscv64"))] + #[cfg(all(plic, target_arch = "riscv64"))] { self.vplic_mmio_init(hv_config); } - #[cfg(all(feature = "aia", target_arch = "riscv64"))] + #[cfg(all(aia, target_arch = "riscv64"))] { self.vaplic_mmio_init(hv_config); } - #[cfg(all(feature = "eic770x_soc", target_arch = "riscv64"))] + #[cfg(all(hypervisor_v0_6, target_arch = "riscv64"))] { - #[cfg(feature = "sifive_ccache")] + #[cfg(sifive_ccache)] self.virtual_sifive_ccache_mmio_init(); - #[cfg(feature = "eic7700_sysreg")] + #[cfg(eic7700_sysreg)] self.virtual_syscon_mmio_init(); } #[cfg(target_arch = "x86_64")] @@ -117,30 +117,30 @@ impl Zone { } } -#[cfg(all(feature = "aclint", target_arch = "riscv64"))] +#[cfg(all(aclint, target_arch = "riscv64"))] pub mod aclint; -#[cfg(all(feature = "plic", target_arch = "riscv64"))] +#[cfg(all(plic, target_arch = "riscv64"))] pub mod plic; -#[cfg(all(feature = "plic", target_arch = "riscv64"))] +#[cfg(all(plic, target_arch = "riscv64"))] pub use plic::{inject_irq, percpu_init, primary_init_late}; -#[cfg(all(feature = "aia", target_arch = "riscv64"))] +#[cfg(all(aia, target_arch = "riscv64"))] pub mod aia; -#[cfg(all(feature = "aia", target_arch = "riscv64"))] +#[cfg(all(aia, target_arch = "riscv64"))] pub use aia::{host_aplic, inject_irq, percpu_init, primary_init_late}; #[cfg(target_arch = "riscv64")] pub fn primary_init_early() { // aclint is local interrupt controller // plic & aia is global interrupt controller - #[cfg(feature = "plic")] + #[cfg(plic)] plic::primary_init_early(); - #[cfg(feature = "aia")] + #[cfg(aia)] aia::primary_init_early(); - #[cfg(feature = "aclint")] + #[cfg(aclint)] aclint::aclint_init(crate::platform::ACLINT_SSWI_BASE); } diff --git a/src/device/irqchip/pic/mod.rs b/src/device/irqchip/pic/mod.rs index 5ad49ef5..17778576 100644 --- a/src/device/irqchip/pic/mod.rs +++ b/src/device/irqchip/pic/mod.rs @@ -145,7 +145,7 @@ pub fn primary_init_late() {} impl Zone { pub fn arch_irqchip_reset(&self) { - #[cfg(feature = "intel_vtd")] + #[cfg(intel_vtd)] iommu::clear_dma_translation_tables(self.id()); } } diff --git a/src/device/irqchip/plic/plic.rs b/src/device/irqchip/plic/plic.rs index a7f069bc..af009b38 100644 --- a/src/device/irqchip/plic/plic.rs +++ b/src/device/irqchip/plic/plic.rs @@ -235,7 +235,7 @@ impl Plic { */ let mut hwirq = 0; - if cfg!(feature = "dp1000_plic") { + if cfg!(dp1000_plic) { let mut ie: [u32; 32] = [0; 32]; // max 1024 irqs hwirq = if self.plic_check_enable_first_pending(context, &mut ie) { self.claim(context) diff --git a/src/device/mod.rs b/src/device/mod.rs index fa5aab22..7fab9db4 100644 --- a/src/device/mod.rs +++ b/src/device/mod.rs @@ -19,8 +19,8 @@ pub mod irqchip; pub mod uart; pub mod virtio_trampoline; -#[cfg(feature = "eic7700_sysreg")] +#[cfg(eic7700_sysreg)] pub mod eic7700_syscrg; -#[cfg(feature = "sifive_ccache")] +#[cfg(sifive_ccache)] pub mod sifive_ccache; diff --git a/src/device/uart/mod.rs b/src/device/uart/mod.rs index f30f036d..16026b7f 100644 --- a/src/device/uart/mod.rs +++ b/src/device/uart/mod.rs @@ -13,23 +13,23 @@ // // Authors: // -// we specified the driver for each platform in the FEATURES environment variable. +// UART driver is selected per board via kconfig/defconfig (see kconfig/cfg_map.toml). #![allow(unused)] -#[cfg(all(feature = "pl011", target_arch = "aarch64"))] +#[cfg(all(pl011, target_arch = "aarch64"))] mod pl011; -#[cfg(all(feature = "pl011", target_arch = "aarch64"))] +#[cfg(all(pl011, target_arch = "aarch64"))] pub use pl011::{console_getchar, console_putchar}; -#[cfg(all(feature = "imx_uart", target_arch = "aarch64"))] +#[cfg(all(imx_uart, target_arch = "aarch64"))] mod imx_uart; -#[cfg(all(feature = "imx_uart", target_arch = "aarch64"))] +#[cfg(all(imx_uart, target_arch = "aarch64"))] pub use imx_uart::{console_getchar, console_putchar}; -#[cfg(all(feature = "xuartps", target_arch = "aarch64"))] +#[cfg(all(xuartps, target_arch = "aarch64"))] mod xuartps; -#[cfg(all(feature = "xuartps", target_arch = "aarch64"))] +#[cfg(all(xuartps, target_arch = "aarch64"))] pub use xuartps::{console_getchar, console_putchar}; #[cfg(target_arch = "riscv64")] @@ -37,19 +37,19 @@ pub use crate::arch::riscv64::sbi::{ sbi_console_getchar as console_getchar, sbi_console_putchar as console_putchar, }; -#[cfg(all(feature = "loongson_uart", target_arch = "loongarch64"))] +#[cfg(all(loongson_uart, target_arch = "loongarch64"))] pub mod loongson_uart; -#[cfg(all(feature = "loongson_uart", target_arch = "loongarch64"))] +#[cfg(all(loongson_uart, target_arch = "loongarch64"))] pub use loongson_uart::{console_getchar, console_putchar}; -#[cfg(all(feature = "uart_16550", target_arch = "aarch64"))] +#[cfg(all(uart_16550, target_arch = "aarch64"))] mod uart_16550; -#[cfg(all(feature = "uart_16550", target_arch = "aarch64"))] +#[cfg(all(uart_16550, target_arch = "aarch64"))] pub use uart_16550::{console_getchar, console_putchar}; -#[cfg(all(feature = "uart16550a", target_arch = "x86_64"))] +#[cfg(all(uart16550a, target_arch = "x86_64"))] mod uart16550a; -#[cfg(all(feature = "uart16550a", target_arch = "x86_64"))] +#[cfg(all(uart16550a, target_arch = "x86_64"))] pub use uart16550a::{ console_getchar, console_putchar, virt_console_io_read, virt_console_io_write, UartReg, }; diff --git a/src/device/uart/uart16550a.rs b/src/device/uart/uart16550a.rs index 144b788b..e180c0d6 100644 --- a/src/device/uart/uart16550a.rs +++ b/src/device/uart/uart16550a.rs @@ -348,7 +348,7 @@ impl VirtUart16550a { pub fn console_putchar(c: u8) { COM1.lock().putchar(c); - #[cfg(all(feature = "graphics"))] + #[cfg(all(graphics))] fb_putchar(c, 0xffffffff, 0); } diff --git a/src/event.rs b/src/event.rs index cadbff2b..5ac74490 100644 --- a/src/event.rs +++ b/src/event.rs @@ -25,7 +25,7 @@ use crate::{ device::{irqchip::inject_irq, virtio_trampoline::handle_virtio_irq}, platform::IRQ_WAKEUP_VIRTIO_DEVICE, }; -#[cfg(feature = "virtio_pci")] +#[cfg(virtio_pci)] use crate::{ pci::msix::activate_msix, platform::{IRQ_WAKEUP_VIRTIO_PCI_CONFIG, IRQ_WAKEUP_VIRTIO_PCI_DATA}, @@ -113,17 +113,17 @@ pub fn check_events() -> bool { inject_irq(IRQ_WAKEUP_VIRTIO_DEVICE, false); true } - #[cfg(feature = "virtio_pci")] + #[cfg(virtio_pci)] Some(IPI_EVENT_VIRTIO_PCI_CONFIG) => { inject_irq(IRQ_WAKEUP_VIRTIO_PCI_CONFIG, false); true } - #[cfg(feature = "virtio_pci")] + #[cfg(virtio_pci)] Some(IPI_EVENT_VIRTIO_PCI_DATA) => { inject_irq(IRQ_WAKEUP_VIRTIO_PCI_DATA, false); true } - #[cfg(feature = "virtio_pci")] + #[cfg(virtio_pci)] Some(IPI_EVENT_VIRTIO_PCI_DONE) => { // Virtio PCI notice // unsafe { @@ -148,7 +148,7 @@ pub fn check_events() -> bool { // irqchip::ls7a2000::clear_hwi_injected_irq(); // true // } - // #[cfg(all(target_arch = "riscv64", feature = "plic"))] + // #[cfg(all(target_arch = "riscv64", plic))] // Some(IPI_EVENT_UPDATE_HART_LINE) => { // use crate::device::irqchip; // info!("cpu {} update hart line", cpu_data.id); diff --git a/src/hypercall/mod.rs b/src/hypercall/mod.rs index 40834f68..ca4f3389 100644 --- a/src/hypercall/mod.rs +++ b/src/hypercall/mod.rs @@ -282,7 +282,7 @@ impl<'a> HyperCall<'a> { zone.arch_irqchip_reset(); // Remove viommu instance related to this zone. - #[cfg(feature = "viommu")] + #[cfg(viommu)] crate::device::iommu::viommu_remove(zone_id as usize); drop(zone); diff --git a/src/logging.rs b/src/logging.rs index 6f8320c0..21316a98 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -133,7 +133,7 @@ pub fn init() { struct SimpleLogger; impl SimpleLogger { - #[cfg(feature = "graphics")] + #[cfg(graphics)] fn print( &self, level: Level, @@ -154,7 +154,7 @@ impl SimpleLogger { ); } - #[cfg(not(feature = "graphics"))] + #[cfg(not(graphics))] fn print( &self, level: Level, @@ -165,7 +165,7 @@ impl SimpleLogger { args_color: ColorCode, record: &Record, ) { - #[cfg(feature = "print_timestamp")] + #[cfg(print_timestamp)] { let time_us: u64 = crate::arch::time::get_time_us(); let sec = time_us / 1_000_000; @@ -180,7 +180,7 @@ impl SimpleLogger { with_color!(args_color, "{}", record.args()), )); } - #[cfg(not(feature = "print_timestamp"))] + #[cfg(not(print_timestamp))] print(with_color!( ColorCode::White, "[{} {}] {} {}\n", diff --git a/src/main.rs b/src/main.rs index 736d209b..4379ad48 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,7 +73,7 @@ use arch::{cpu::cpu_start, entry::arch_entry}; use config::root_zone_config; use core::sync::atomic::{AtomicI32, AtomicU32, Ordering}; use cpu_data::PerCpu; -#[cfg(feature = "pci")] +#[cfg(pci)] use pci::pci_config::hvisor_pci_init; static INITED_CPUS: AtomicU32 = AtomicU32::new(0); @@ -132,12 +132,12 @@ fn primary_init_early() { device::irqchip::primary_init_early(); - #[cfg(feature = "iommu")] + #[cfg(iommu)] iommu_init(); let root_config = root_zone_config(); - #[cfg(feature = "pci")] + #[cfg(pci)] if root_config.num_pci_bus > 0 { let num_pci_bus = root_config.num_pci_bus as usize; let _ = hvisor_pci_init(&root_config.pci_config[..num_pci_bus]); diff --git a/src/pci/config_accessors/mod.rs b/src/pci/config_accessors/mod.rs index 544505a6..1a974546 100644 --- a/src/pci/config_accessors/mod.rs +++ b/src/pci/config_accessors/mod.rs @@ -65,11 +65,7 @@ impl PciRegionMmio { } } -#[cfg(all( - not(feature = "ecam_pcie"), - not(feature = "dwc_pcie"), - not(feature = "loongarch64_pcie") -))] +#[cfg(not(pci))] impl PciConfigMmio { pub fn access(&self, offset: PciConfigAddress) -> *mut T { (self.base + offset) as *mut T @@ -147,13 +143,13 @@ pub enum PciAccessorType { } // Export accessor implementations -#[cfg(feature = "ecam_pcie")] +#[cfg(ecam_pcie)] pub mod ecam; -#[cfg(feature = "dwc_pcie")] +#[cfg(dwc_pcie)] pub mod dwc; -#[cfg(feature = "dwc_pcie")] +#[cfg(dwc_pcie)] pub mod dwc_atu; -#[cfg(feature = "loongarch64_pcie")] +#[cfg(loongarch64_pcie)] pub mod loongarch64; diff --git a/src/pci/msix.rs b/src/pci/msix.rs index 365cb400..03adbd1f 100644 --- a/src/pci/msix.rs +++ b/src/pci/msix.rs @@ -51,7 +51,7 @@ pub fn activate_msix() { #[allow(unreachable_code)] pub fn get_arch_msix_backend() -> Option>> { - #[cfg(all(target_arch = "aarch64", feature = "gicv3"))] + #[cfg(all(target_arch = "aarch64", irq_gicv3))] { use crate::device::irqchip::gicv3::msix_backend::get_gicv3_backend; return Some(get_gicv3_backend()); diff --git a/src/pci/pci_config.rs b/src/pci/pci_config.rs index f2235dc8..99df487e 100644 --- a/src/pci/pci_config.rs +++ b/src/pci/pci_config.rs @@ -27,30 +27,25 @@ use crate::{ zone::Zone, }; -#[cfg(feature = "loongarch64_pcie")] +#[cfg(loongarch64_pcie)] use alloc::vec::Vec; -#[cfg(any( - all(feature = "iommu", target_arch = "aarch64"), - all(feature = "iommu", target_arch = "riscv64"), - target_arch = "x86_64" -))] +#[cfg(iommu)] use crate::device::iommu::iommu_add_device_with_root_pt_addr; -#[cfg(feature = "ecam_pcie")] -use crate::pci::vpci_dev::{get_handler, VpciDevType}; +#[cfg(ecam_pcie)] +use crate::pci::{ + pci_struct::VirtualPciConfigSpace, + vpci_dev::{get_handler, VpciDevType}, +}; -#[cfg(any( - feature = "ecam_pcie", - feature = "dwc_pcie", - feature = "loongarch64_pcie" -))] +#[cfg(pci)] use crate::pci::{mem_alloc::BaseAllocator, pci_struct::RootComplex}; -#[cfg(feature = "ecam_pcie")] +#[cfg(ecam_pcie)] use crate::pci::{config_accessors::ecam::EcamConfigAccessor, pci_handler::mmio_vpci_handler}; -#[cfg(feature = "dwc_pcie")] +#[cfg(dwc_pcie)] use crate::{ memory::mmio_generic_handler, pci::{ @@ -63,7 +58,7 @@ use crate::{ platform, }; -#[cfg(feature = "loongarch64_pcie")] +#[cfg(loongarch64_pcie)] use crate::pci::{ config_accessors::loongarch64::LoongArchConfigAccessor, pci_handler::mmio_vpci_direct_handler, }; @@ -77,11 +72,7 @@ pub static GLOBAL_PCIE_LIST: Lazy HvResult { warn!("begin {:#x?}", pci_config); - #[cfg(any( - feature = "ecam_pcie", - feature = "dwc_pcie", - feature = "loongarch64_pcie" - ))] + #[cfg(pci)] for (_index, rootcomplex_config) in pci_config.iter().enumerate() { /* empty config */ if rootcomplex_config.ecam_base == 0 { @@ -99,12 +90,12 @@ pub fn hvisor_pci_init(pci_config: &[HvPciConfig]) -> HvResult { // TODO: refactor // in x86, we do not take the initiative to reallocate BAR space - #[cfg(feature = "no_pcie_bar_realloc")] + #[cfg(no_pcie_bar_realloc)] let allocator_opt: Option = None; - #[cfg(not(feature = "no_pcie_bar_realloc"))] + #[cfg(not(no_pcie_bar_realloc))] let allocator_opt: Option = Some(allocator); - // #[cfg(feature = "loongarch64_pcie")] + // #[cfg(loongarch64_pcie)] // let allocator_opt: Option = { // let mut allocator = LoongArchAllocator::default(); // allocator.set_mem( @@ -119,7 +110,7 @@ pub fn hvisor_pci_init(pci_config: &[HvPciConfig]) -> HvResult { // }; let mut rootcomplex = { - #[cfg(feature = "dwc_pcie")] + #[cfg(dwc_pcie)] { // warn!("dwc pcie"); let ecam_base = rootcomplex_config.ecam_base; @@ -140,7 +131,7 @@ pub fn hvisor_pci_init(pci_config: &[HvPciConfig]) -> HvResult { RootComplex::new_dwc(rootcomplex_config.ecam_base, atu_config, root_bus) } - #[cfg(feature = "loongarch64_pcie")] + #[cfg(loongarch64_pcie)] { let root_bus = rootcomplex_config.bus_range_begin as u8; RootComplex::new_loongarch( @@ -150,7 +141,7 @@ pub fn hvisor_pci_init(pci_config: &[HvPciConfig]) -> HvResult { ) } - #[cfg(feature = "ecam_pcie")] + #[cfg(ecam_pcie)] { RootComplex::new_ecam(rootcomplex_config.ecam_base) } @@ -195,7 +186,7 @@ impl Zone { let bus_range_begin = target_pci_config.bus_range_begin as u8; // Create accessor for VirtualRootComplex, similar to RootComplex - #[cfg(feature = "dwc_pcie")] + #[cfg(dwc_pcie)] { use alloc::sync::Arc; let atu_config = platform::ROOT_DWC_ATU_CONFIG @@ -215,7 +206,7 @@ impl Zone { } } - #[cfg(feature = "loongarch64_pcie")] + #[cfg(loongarch64_pcie)] { use alloc::sync::Arc; let root_bus = bus_range_begin; @@ -227,7 +218,7 @@ impl Zone { inner.vpci_bus_mut().set_accessor(accessor); } - #[cfg(feature = "ecam_pcie")] + #[cfg(ecam_pcie)] { use alloc::sync::Arc; let accessor = Arc::new(EcamConfigAccessor::new(ecam_base)); @@ -326,11 +317,7 @@ impl Zone { info!("set bdf {:#?} to vbdf {:#?}", bdf, vbdf); - #[cfg(any( - all(feature = "iommu", target_arch = "aarch64"), - all(feature = "iommu", target_arch = "riscv64"), - target_arch = "x86_64" - ))] + #[cfg(iommu)] { let iommu_pt_addr = if inner.iommu_pt().is_some() { inner.iommu_pt().unwrap().root_paddr() @@ -340,13 +327,13 @@ impl Zone { let device_id = (dev_config.bus as usize) << 8 | (dev_config.device as usize) << 3 | dev_config.function as usize; - #[cfg(feature = "share_s2pt")] + #[cfg(share_s2pt)] iommu_add_device_with_root_pt_addr( _zone_id, device_id as _, inner.gpm().root_paddr(), ); - #[cfg(not(feature = "share_s2pt"))] + #[cfg(not(share_s2pt))] iommu_add_device_with_root_pt_addr(_zone_id, device_id as _, iommu_pt_addr); } @@ -377,7 +364,7 @@ impl Zone { } } else { warn!("can not find dev {:#?} in GLOBAL_PCIE_LIST (not detected during enumeration)", bdf); - #[cfg(feature = "ecam_pcie")] + #[cfg(ecam_pcie)] { let dev_type = dev_config.dev_type; warn!("dev_type:{:?}", dev_config); @@ -414,7 +401,7 @@ impl Zone { pci_rootcomplex_config: &[HvPciConfig; CONFIG_PCI_BUS_MAXNUM], _num_pci_config: usize, ) { - #[cfg(feature = "loongarch64_pcie")] + #[cfg(loongarch64_pcie)] let mut emergency_map_regions: Vec<(usize, usize)> = Vec::new(); let mut inner = self.write(); @@ -424,7 +411,7 @@ impl Zone { if rootcomplex_config.ecam_base == 0 { continue; } - #[cfg(feature = "ecam_pcie")] + #[cfg(ecam_pcie)] { // use crate::pci::pci_handler::mmio_vpci_direct_handler; inner.mmio_region_register( @@ -435,7 +422,7 @@ impl Zone { rootcomplex_config.ecam_base as usize, ); } - #[cfg(feature = "dwc_pcie")] + #[cfg(dwc_pcie)] { inner.mmio_region_register( rootcomplex_config.ecam_base as usize, @@ -511,7 +498,7 @@ impl Zone { ); } } - #[cfg(feature = "loongarch64_pcie")] + #[cfg(loongarch64_pcie)] { inner.mmio_region_register( rootcomplex_config.ecam_base as usize, @@ -524,11 +511,7 @@ impl Zone { rootcomplex_config.ecam_size as usize, )); } - #[cfg(not(any( - feature = "ecam_pcie", - feature = "dwc_pcie", - feature = "loongarch64_pcie" - )))] + #[cfg(not(pci))] { warn!( "No extend config found for base 0x{:x}", @@ -537,7 +520,7 @@ impl Zone { } } - #[cfg(feature = "loongarch64_pcie")] + #[cfg(loongarch64_pcie)] { drop(inner); for (base, size) in emergency_map_regions { diff --git a/src/pci/pci_handler.rs b/src/pci/pci_handler.rs index e118a966..ca42746a 100644 --- a/src/pci/pci_handler.rs +++ b/src/pci/pci_handler.rs @@ -31,7 +31,7 @@ use super::PciConfigAddress; #[cfg(target_arch = "x86_64")] use crate::zone::this_zone_id; -#[cfg(feature = "dwc_pcie")] +#[cfg(dwc_pcie)] use crate::{ memory::mmio_perform_access, pci::config_accessors::{ @@ -407,7 +407,7 @@ fn handle_endpoint_access( /* after update gpm, need to flush iommu table * in x86_64 */ - #[cfg(all(target_arch = "x86_64", feature = "intel_vtd"))] + #[cfg(all(target_arch = "x86_64", intel_vtd))] { let vbdf = dev.get_vbdf(); crate::device::iommu::flush( @@ -537,7 +537,7 @@ fn handle_endpoint_access( /* after update gpm, need to flush iommu table * in x86_64 */ - #[cfg(all(target_arch = "x86_64", feature = "intel_vtd"))] + #[cfg(all(target_arch = "x86_64", intel_vtd))] { let vbdf = dev.get_vbdf(); crate::device::iommu::flush( @@ -753,7 +753,7 @@ pub fn mmio_vpci_handler(mmio: &mut MMIOAccess, _base: usize) -> HvResult { Ok(()) } -#[cfg(feature = "dwc_pcie")] +#[cfg(dwc_pcie)] pub fn mmio_dwc_io_handler(mmio: &mut MMIOAccess, _base: usize) -> HvResult { { let zone = this_zone(); @@ -794,7 +794,7 @@ pub fn mmio_dwc_io_handler(mmio: &mut MMIOAccess, _base: usize) -> HvResult { Ok(()) } -#[cfg(feature = "dwc_pcie")] +#[cfg(dwc_pcie)] pub fn mmio_dwc_cfg_handler(mmio: &mut MMIOAccess, _base: usize) -> HvResult { // info!("mmio_dwc_cfg_handler {:#x}", mmio.address + _base); let zone = this_zone(); @@ -879,7 +879,7 @@ pub fn mmio_dwc_cfg_handler(mmio: &mut MMIOAccess, _base: usize) -> HvResult { Ok(()) } -#[cfg(feature = "dwc_pcie")] +#[cfg(dwc_pcie)] pub fn mmio_vpci_handler_dbi(mmio: &mut MMIOAccess, _base: usize) -> HvResult { // info!("mmio_vpci_handler_dbi {:#x}", mmio.address); diff --git a/src/pci/pci_struct.rs b/src/pci/pci_struct.rs index ad243d1f..d2789cc7 100644 --- a/src/pci/pci_struct.rs +++ b/src/pci/pci_struct.rs @@ -1424,7 +1424,7 @@ impl Iterator for PciIterator { // (UEFI/BIOS) may skip bus numbers for subordinate bus reservation, // causing calculated bus numbers to diverge from actual hardware // bus assignments — making devices behind bridges invisible. - #[cfg(feature = "no_pcie_bar_realloc")] + #[cfg(no_pcie_bar_realloc)] let next_bus = { let bridge_base = node.get_base(); let bus_reg = unsafe { @@ -1459,7 +1459,7 @@ impl Iterator for PciIterator { parent.subordinate_bus + 1 } }; - #[cfg(not(feature = "no_pcie_bar_realloc"))] + #[cfg(not(no_pcie_bar_realloc))] let next_bus = parent.subordinate_bus + 1; let bdf = Bdf::new(domain, next_bus, 0, 0); @@ -1566,10 +1566,10 @@ impl Bridge { } // When no_pcie_bar_realloc is enabled, firmware already assigned correct bus // numbers — don't overwrite them. - #[cfg(feature = "no_pcie_bar_realloc")] + #[cfg(no_pcie_bar_realloc)] return; - #[cfg(not(feature = "no_pcie_bar_realloc"))] + #[cfg(not(no_pcie_bar_realloc))] { // we need to update the bridge bus number if we want linux not to update bus number unsafe { @@ -2233,9 +2233,9 @@ impl VirtualPciConfigSpace { // } // } // false - // #[cfg(feature = "dwc_pcie")] + // #[cfg(dwc_pcie)] // return true; - // #[cfg(not(feature = "dwc_pcie"))] + // #[cfg(not(dwc_pcie))] return false; } _ => false, diff --git a/src/pci/pci_test.rs b/src/pci/pci_test.rs index 182a614d..c6d7b22d 100644 --- a/src/pci/pci_test.rs +++ b/src/pci/pci_test.rs @@ -25,7 +25,7 @@ use super::{ pci_struct::{Bdf, VirtualPciConfigSpace, CONFIG_LENTH}, }; -#[cfg(feature = "ecam_pcie")] +#[cfg(ecam_pcie)] use super::{mem_alloc::BaseAllocator, pci_struct::RootComplex}; use crate::{ @@ -40,7 +40,7 @@ pub static GLOBAL_PCIE_LIST_TEST: Lazy Option { - #[cfg(feature = "virtio_pci")] + #[cfg(virtio_pci)] { // Create initial VirtualPciConfigSpace with default values @@ -139,7 +139,7 @@ pub(super) fn virt_dev_init( } } } - #[cfg(not(feature = "virtio_pci"))] + #[cfg(not(virtio_pci))] { warn!( "Try to initialize a virtual virtio pci device when feature virtio-pci is not enabled" diff --git a/src/platform/mod.rs b/src/platform/mod.rs index d9dd18a6..64605c31 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -72,7 +72,7 @@ pub fn platform_root_zone_config() -> HvZoneConfig { let mut _num_pci_devs: u64 = 0; let mut _num_pci_bus: u64 = 0; - #[cfg(feature = "pci")] + #[cfg(pci)] { check!(ROOT_PCI_DEVS.len(), CONFIG_MAX_PCI_DEV, "ROOT_PCI_DEVS"); pci_devs[..ROOT_PCI_DEVS.len()].copy_from_slice(&ROOT_PCI_DEVS); diff --git a/src/zone.rs b/src/zone.rs index 3052a4f6..817c694a 100644 --- a/src/zone.rs +++ b/src/zone.rs @@ -20,9 +20,9 @@ use crate::consts::{INVALID_ADDRESS, MAX_CPU_NUM}; use crate::pci::pci_struct::VirtualRootComplex; use spin::{RwLock, RwLockReadGuard, RwLockWriteGuard}; -#[cfg(feature = "dwc_pcie")] +#[cfg(dwc_pcie)] use crate::pci::{config_accessors::dwc_atu::AtuConfig, PciConfigAddress}; -#[cfg(feature = "dwc_pcie")] +#[cfg(dwc_pcie)] use alloc::collections::btree_map::BTreeMap; use crate::arch::mm::new_s2_memory_set; @@ -36,7 +36,7 @@ use crate::memory::{MMIOConfig, MMIOHandler, MMIORegion, MemorySet}; use core::panic; use core::sync::atomic::{AtomicBool, Ordering}; -#[cfg(feature = "dwc_pcie")] +#[cfg(dwc_pcie)] #[derive(Debug)] pub struct VirtualAtuConfigs { ecam_to_atu: BTreeMap, @@ -44,7 +44,7 @@ pub struct VirtualAtuConfigs { cfg_base_to_ecam: BTreeMap, } -#[cfg(feature = "dwc_pcie")] +#[cfg(dwc_pcie)] impl VirtualAtuConfigs { pub fn new() -> Self { Self { @@ -123,7 +123,7 @@ pub struct ZoneInner { gpm: MemorySet, iommu_pt: Option>, vpci_bus: VirtualRootComplex, - #[cfg(feature = "dwc_pcie")] + #[cfg(dwc_pcie)] atu_configs: VirtualAtuConfigs, } @@ -175,13 +175,13 @@ impl ZoneInner { cpu_num: 0, cpu_set: CpuSet::new(MAX_CPU_NUM as usize, 0), irq_bitmap: [0; 1024 / 32], - iommu_pt: if cfg!(feature = "iommu") { + iommu_pt: if cfg!(iommu) { Some(new_s2_memory_set()) } else { None }, vpci_bus: VirtualRootComplex::new(), - #[cfg(feature = "dwc_pcie")] + #[cfg(dwc_pcie)] atu_configs: VirtualAtuConfigs::new(), } } @@ -308,12 +308,12 @@ impl ZoneInner { &mut self.vpci_bus } - #[cfg(feature = "dwc_pcie")] + #[cfg(dwc_pcie)] pub fn atu_configs(&self) -> &VirtualAtuConfigs { &self.atu_configs } - #[cfg(feature = "dwc_pcie")] + #[cfg(dwc_pcie)] pub fn atu_configs_mut(&mut self) -> &mut VirtualAtuConfigs { &mut self.atu_configs } @@ -388,7 +388,7 @@ pub fn zone_create(config: &HvZoneConfig) -> HvResult> { zone.pt_init(config.memory_regions())?; zone.mmio_init(&config.arch_config); - #[cfg(feature = "pci")] + #[cfg(pci)] { let _ = zone.virtual_pci_mmio_init(&config.pci_config, config.num_pci_bus as usize); let _ = zone.guest_pci_init( @@ -400,7 +400,7 @@ pub fn zone_create(config: &HvZoneConfig) -> HvResult> { ); } - #[cfg(feature = "viommu")] + #[cfg(viommu)] { use crate::platform::{IOMMU_SYS_BASE, IOMMU_SYS_SIZE}; // Create viommu instance and register mmio handler for target zone. @@ -442,7 +442,7 @@ pub fn zone_create(config: &HvZoneConfig) -> HvResult> { // #[cfg(target_arch = "aarch64")] // zone.ivc_init(config.ivc_config()); - #[cfg(all(feature = "iommu", target_arch = "aarch64"))] + #[cfg(all(iommu, target_arch = "aarch64"))] zone.iommu_pt_init(config.memory_regions(), &config.arch_config)?; /* loongarch page table emergency */ diff --git a/tools/gen_cargo_config.sh b/tools/gen_cargo_config.sh deleted file mode 100755 index 3bb6832a..00000000 --- a/tools/gen_cargo_config.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash - -set -e - -CONFIG_TOML=".cargo/config.toml" -echo "" > $CONFIG_TOML - -function find_hvisor_src { - # find in ./CHANGELOG.md ../CHANGELOG.md - ret=$(find . -name CHANGELOG.md -exec grep -l "hvisor" {} \;) - if [ -z "$ret" ]; then - ret=$(find .. -name CHANGELOG.md -exec grep -l "hvisor" {} \;) - fi - if [ -z "$ret" ]; then - echo "." - fi - echo $(dirname $ret) -} - -CONFIG_TOML_TEMPLATE="platform/$ARCH/$BOARD/cargo/config.template.toml" -CONFIG_TOML_TEMPLATE=$(realpath $CONFIG_TOML_TEMPLATE) -TEMPLATE=$(cat $CONFIG_TOML_TEMPLATE) -LD_SCRIPT="platform/$ARCH/$BOARD/linker.ld" -LD_SCRIPT=$(realpath $LD_SCRIPT) -HVISOR_SRC=$(realpath $(find_hvisor_src)) -HOST_ARCH=$(uname -m) -OS=$(uname -s) -OS_VERSION=$(uname -r) -DISTRO=unknown -if [ -f /etc/os-release ]; then - DISTRO=$(grep '^ID=' /etc/os-release | cut -d= -f2) -fi - -echo "# Generated by gen_cargo_config.sh at $(date) ($(whoami)@$(hostname))" >> $CONFIG_TOML -echo "# BASH_VERSION = $BASH_VERSION" >> $CONFIG_TOML -echo "# HOST_ARCH = $HOST_ARCH" >> $CONFIG_TOML -echo "# OS_INFO = $OS $OS_VERSION $DISTRO" >> $CONFIG_TOML -echo "# ARCH = $ARCH" >> $CONFIG_TOML -echo "# BOARD = $BOARD" >> $CONFIG_TOML -echo "# FEATURES = $FEATURES" >> $CONFIG_TOML -echo "# HVISOR_SRC = $HVISOR_SRC" >> $CONFIG_TOML -echo "# LD_SCRIPT = $LD_SCRIPT" >> $CONFIG_TOML -echo "# TEMPLATE = $CONFIG_TOML_TEMPLATE" >> $CONFIG_TOML -echo "" >> $CONFIG_TOML - -# place holders: __XXX__ -> XXX -TEMPLATE=$(echo "$TEMPLATE" | sed -e 's/__ARCH__/'"$ARCH"'/g') -TEMPLATE=$(echo "$TEMPLATE" | sed -e 's/__BOARD__/'"$BOARD"'/g') - -echo "$TEMPLATE" >> $CONFIG_TOML - -# also generate a .config file in the HVISOR_SRC directory -CONFIG_FILE="$HVISOR_SRC/.config" -echo "ARCH=$ARCH" > $CONFIG_FILE -echo "BOARD=$BOARD" >> $CONFIG_FILE -echo "BID=$ARCH/$BOARD" >> $CONFIG_FILE -echo "FEATURES=$FEATURES" >> $CONFIG_FILE -echo "HVISOR_SRC=$HVISOR_SRC" >> $CONFIG_FILE -echo "LD_SCRIPT=$LD_SCRIPT" >> $CONFIG_FILE -echo "TEMPLATE=$CONFIG_TOML_TEMPLATE" >> $CONFIG_FILE \ No newline at end of file diff --git a/tools/gen_vscode_settings.sh b/tools/gen_vscode_settings.sh deleted file mode 100755 index 2d911faa..00000000 --- a/tools/gen_vscode_settings.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash -set -e - -function find_hvisor_src { - ret=$(find . -name CHANGELOG.md -exec grep -l "hvisor" {} \;) - if [ -z "$ret" ]; then - ret=$(find .. -name CHANGELOG.md -exec grep -l "hvisor" {} \;) - fi - if [ -z "$ret" ]; then - echo "ERROR: Could not locate hvisor source root (CHANGELOG.md with 'hvisor')" >&2 - exit 1 - fi - echo "$(dirname "$ret")" -} - -HVISOR_SRC=$(realpath $(find_hvisor_src)) -cd "$HVISOR_SRC" - -if [ -n "$BID" ]; then - ARCH=$(echo "$BID" | cut -d'/' -f1) - BOARD=$(echo "$BID" | cut -d'/' -f2) -fi - -if [ -z "$ARCH" ] || [ -z "$BOARD" ]; then - echo "ERROR: ARCH/BOARD not set, please use BID=arch/board or ARCH=... BOARD=..." - exit 1 -fi - -if [ -z "$FEATURES" ]; then - FEATURES=$(./tools/read_features.sh "$ARCH" "$BOARD") -fi - -FEATURES=$(echo "$FEATURES" | tr '\n' ' ' | tr -s ' ' | sed 's/^ *//;s/ *$//') - -case "$ARCH" in - aarch64) TARGET="aarch64-unknown-none" ;; - riscv64) TARGET="riscv64gc-unknown-none-elf" ;; - loongarch64) TARGET="loongarch64-unknown-none" ;; - x86_64) TARGET="x86_64-unknown-none" ;; - *) - echo "ERROR: Unsupported ARCH value: $ARCH" - exit 1 - ;; -esac - -mkdir -p .vscode - -cat > .vscode/settings.json <&2 + exit 1 +fi + +if [[ -x "${VENV}/bin/python" ]] && "${VENV}/bin/python" -c "import kconfiglib" 2>/dev/null; then + exit 0 +fi + +python3 -m venv "${VENV}" +"${VENV}/bin/pip" install -q -r "${REQ}" diff --git a/tools/kconfig/host_config.sh b/tools/kconfig/host_config.sh new file mode 100755 index 00000000..fa40c950 --- /dev/null +++ b/tools/kconfig/host_config.sh @@ -0,0 +1,121 @@ +#!/usr/bin/env bash +# Host-side helpers that consume repo-root .config (Kconfig + metadata from kconfig_cli.py). +# Usage (from repo root, or any cwd — script cds to root): +# ./tools/kconfig/host_config.sh cargo # write .cargo/config.toml +# ./tools/kconfig/host_config.sh vscode # refresh .config + write .vscode/settings.json +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" +cd "$ROOT" + +KPY="$ROOT/tools/kconfig/.venv/bin/python" +CLI="$ROOT/tools/kconfig/kconfig_cli.py" + +cmd_gen_cargo() { + local CONFIG_TOML=".cargo/config.toml" + echo "" >"$CONFIG_TOML" + + if [ ! -f .config ]; then + echo "error: missing .config (run: make defconfig)" >&2 + exit 1 + fi + local ARCH BOARD HVISOR_SRC LD_SCRIPT CONFIG_TOML_TEMPLATE + ARCH=$(grep '^# ARCH=' .config 2>/dev/null | head -1 | sed 's/^# ARCH=//') + [ -n "$ARCH" ] || ARCH=$(grep '^ARCH=' .config | head -1 | cut -d= -f2-) + BOARD=$(grep '^# BOARD=' .config 2>/dev/null | head -1 | sed 's/^# BOARD=//') + [ -n "$BOARD" ] || BOARD=$(grep '^BOARD=' .config | head -1 | cut -d= -f2-) + HVISOR_SRC=$(grep '^# HVISOR_SRC=' .config 2>/dev/null | head -1 | sed 's/^# HVISOR_SRC=//') + [ -n "$HVISOR_SRC" ] || HVISOR_SRC=$(grep '^HVISOR_SRC=' .config | head -1 | cut -d= -f2-) + LD_SCRIPT=$(grep '^# LD_SCRIPT=' .config 2>/dev/null | head -1 | sed 's/^# LD_SCRIPT=//') + [ -n "$LD_SCRIPT" ] || LD_SCRIPT=$(grep '^LD_SCRIPT=' .config | head -1 | cut -d= -f2-) + CONFIG_TOML_TEMPLATE=$(grep '^# TEMPLATE=' .config 2>/dev/null | head -1 | sed 's/^# TEMPLATE=//') + [ -n "$CONFIG_TOML_TEMPLATE" ] || CONFIG_TOML_TEMPLATE=$(grep '^TEMPLATE=' .config | head -1 | cut -d= -f2-) + if [ -z "$ARCH" ] || [ -z "$BOARD" ] || [ -z "$HVISOR_SRC" ] || [ -z "$LD_SCRIPT" ] || [ -z "$CONFIG_TOML_TEMPLATE" ]; then + echo "error: .config missing ARCH/BOARD/HVISOR_SRC/LD_SCRIPT/TEMPLATE lines (run: make defconfig)" >&2 + exit 1 + fi + local TEMPLATE + TEMPLATE=$(cat "$CONFIG_TOML_TEMPLATE") + local HOST_ARCH OS OS_VERSION DISTRO + HOST_ARCH=$(uname -m) + OS=$(uname -s) + OS_VERSION=$(uname -r) + DISTRO=unknown + if [ -f /etc/os-release ]; then + DISTRO=$(grep '^ID=' /etc/os-release | cut -d= -f2) + fi + + { + echo "# Generated by tools/kconfig/host_config.sh cargo at $(date) ($(whoami)@$(hostname))" + echo "# BASH_VERSION = $BASH_VERSION" + echo "# HOST_ARCH = $HOST_ARCH" + echo "# OS_INFO = $OS $OS_VERSION $DISTRO" + echo "# ARCH = $ARCH" + echo "# BOARD = $BOARD" + echo "# (platform toggles come from .config CONFIG_* via build.rs)" + echo "# HVISOR_SRC = $HVISOR_SRC" + echo "# LD_SCRIPT = $LD_SCRIPT" + echo "# TEMPLATE = $CONFIG_TOML_TEMPLATE" + echo "" + } >>"$CONFIG_TOML" + + TEMPLATE=$(echo "$TEMPLATE" | sed -e 's/__ARCH__/'"$ARCH"'/g') + TEMPLATE=$(echo "$TEMPLATE" | sed -e 's/__BOARD__/'"$BOARD"'/g') + echo "$TEMPLATE" >>"$CONFIG_TOML" +} + +cmd_vscode() { + local ARCH="${ARCH:-}" BOARD="${BOARD:-}" + if [ -n "${BID:-}" ]; then + ARCH=$(echo "$BID" | cut -d'/' -f1) + BOARD=$(echo "$BID" | cut -d'/' -f2) + fi + if [ -z "$ARCH" ] || [ -z "$BOARD" ]; then + echo "ERROR: ARCH/BOARD not set, use BID=arch/board or ARCH=... BOARD=..." >&2 + exit 1 + fi + if [ ! -x "$KPY" ]; then + echo "ERROR: tools/kconfig/.venv missing. Run: ./tools/kconfig/bootstrap_venv.sh" >&2 + exit 1 + fi + ARCH="$ARCH" BOARD="$BOARD" "$KPY" "$CLI" defconfig + + local CFG_JSON + CFG_JSON=$("$KPY" "$CLI" vscode-cfgs .config kconfig/cfg_map.toml) + + local TARGET + case "$ARCH" in + aarch64) TARGET="aarch64-unknown-none" ;; + riscv64) TARGET="riscv64gc-unknown-none-elf" ;; + loongarch64) TARGET="loongarch64-unknown-none" ;; + x86_64) TARGET="x86_64-unknown-none" ;; + *) + echo "ERROR: Unsupported ARCH value: $ARCH" >&2 + exit 1 + ;; + esac + + mkdir -p .vscode + cat >.vscode/settings.json <&2 + exit 2 + ;; +esac diff --git a/tools/kconfig/kconfig_cli.py b/tools/kconfig/kconfig_cli.py new file mode 100644 index 00000000..ffef3f69 --- /dev/null +++ b/tools/kconfig/kconfig_cli.py @@ -0,0 +1,164 @@ +#!/usr/bin/env python3 +"""Kconfig entrypoints: defconfig, menuconfig, vscode-cfgs.""" +from __future__ import annotations + +import argparse +import json +import os +import re +import sys +import tomllib +from pathlib import Path + +_KCONF_ARCH_TO_DIR: dict[str, str] = { + "ARCH_AARCH64": "aarch64", + "ARCH_RISCV64": "riscv64", + "ARCH_LOONGARCH64": "loongarch64", + "ARCH_X86_64": "x86_64", +} + + +def arch_from_kconf(kconf) -> str | None: + for sym_name, arch in _KCONF_ARCH_TO_DIR.items(): + sym = kconf.syms.get(sym_name) + if sym is not None and sym.str_value == "y": + return arch + return None + + +def write_root_dot_config(root: Path, arch: str, board: str, kconf) -> None: + """Write repo-root `.config`: comment metadata (Kconfig-safe) then kconfiglib body.""" + cfg = root / ".config" + derived = arch_from_kconf(kconf) + if derived is None: + raise SystemExit( + "Kconfig: no architecture selected; enable exactly one of " + "ARCH_AARCH64 / ARCH_RISCV64 / ARCH_LOONGARCH64 / ARCH_X86_64 in defconfig." + ) + if derived != arch: + raise SystemExit( + f"Kconfig architecture ({derived}) does not match " + f"platform path arch ({arch}) for board {board!r}. " + "Fix kconfig/defconfig or pick the correct ARCH/BOARD." + ) + arch_out = derived + ld = (root / "platform" / arch_out / board / "linker.ld").resolve() + tmpl = (root / "platform" / arch_out / board / "cargo" / "config.template.toml").resolve() + hvisor_src = str(root.resolve()) + bid = f"{arch_out}/{board}" + kconf.write_config(str(cfg)) + body = cfg.read_text() + meta = ( + f"# ARCH={arch_out}\n" + f"# BOARD={board}\n" + f"# BID={bid}\n" + f"# HVISOR_SRC={hvisor_src}\n" + f"# LD_SCRIPT={ld}\n" + f"# TEMPLATE={tmpl}\n" + "\n" + ) + cfg.write_text(meta + body) + + +def _repo_root() -> Path: + return Path(__file__).resolve().parents[2] + + +def cmd_defconfig() -> None: + arch = os.environ.get("ARCH", "") + board = os.environ.get("BOARD", "") + if not arch or not board: + print("error: set ARCH and BOARD", file=sys.stderr) + sys.exit(2) + root = _repo_root() + os.chdir(root) + try: + from kconfiglib import Kconfig + except ImportError: + print("error: pip install kconfiglib (see tools/kconfig/requirements.txt)", file=sys.stderr) + sys.exit(1) + kconf = Kconfig(str(root / "kconfig" / "Kconfig")) + defcfg = root / "platform" / arch / board / "kconfig" / "defconfig" + if not defcfg.is_file(): + print(f"error: missing {defcfg}", file=sys.stderr) + sys.exit(1) + kconf.load_config(str(defcfg)) + write_root_dot_config(root, arch, board, kconf) + print(f"wrote .config for {arch}/{board}") + + +def cmd_menuconfig() -> None: + arch = os.environ.get("ARCH", "") + board = os.environ.get("BOARD", "") + if not arch or not board: + print("error: set ARCH and BOARD", file=sys.stderr) + sys.exit(2) + root = _repo_root() + os.chdir(root) + try: + from kconfiglib import Kconfig + except ImportError as e: + print(f"error: kconfiglib is not installed: {e}", file=sys.stderr) + print("hint: tools/kconfig/.venv/bin/pip install -r tools/kconfig/requirements.txt", file=sys.stderr) + sys.exit(1) + try: + import menuconfig as kc_menu + except ImportError as e: + print(f"error: kconfiglib TUI (menuconfig) could not load: {e}", file=sys.stderr) + print( + "hint: the UI needs Python stdlib curses. " + "Debian/Ubuntu: apt install python3-curses; Fedora: dnf install python3-curses; " + "Windows: pip install windows-curses", + file=sys.stderr, + ) + sys.exit(1) + kconf = Kconfig(str(root / "kconfig" / "Kconfig")) + cfg = root / ".config" + defcfg = root / "platform" / arch / board / "kconfig" / "defconfig" + if cfg.is_file(): + kconf.load_config(str(cfg)) + elif defcfg.is_file(): + kconf.load_config(str(defcfg)) + kc_menu.menuconfig(kconf) + write_root_dot_config(root, arch, board, kconf) + + +def cmd_vscode_cfgs(cfg_path: Path, map_path: Path) -> None: + sym = tomllib.loads(map_path.read_text(encoding="utf-8"))["symbols"] + enabled: set[str] = set() + for line in cfg_path.read_text().splitlines(): + line = line.strip() + m = re.match(r"^(CONFIG_[A-Z0-9_]+)=(y|m)$", line) + if not m: + continue + k = m.group(1) + if k in sym: + enabled.add(sym[k]) + print(json.dumps(sorted(enabled))) + + +def main() -> int: + p = argparse.ArgumentParser(description="hvisor Kconfig helpers") + sub = p.add_subparsers(dest="cmd", required=True) + + sub.add_parser("defconfig", help="merge board defconfig + Kconfig into repo-root .config (env ARCH, BOARD)") + sub.add_parser( + "menuconfig", + help="interactive Kconfig UI (env ARCH, BOARD); do not name this file menuconfig.py", + ) + p_vc = sub.add_parser("vscode-cfgs", help="emit JSON array of rustc cfg names for rust-analyzer") + p_vc.add_argument("config", type=Path, help="path to repo-root .config") + p_vc.add_argument("map", type=Path, help="path to kconfig/cfg_map.toml") + + args = p.parse_args() + if args.cmd == "defconfig": + cmd_defconfig() + elif args.cmd == "menuconfig": + cmd_menuconfig() + elif args.cmd == "vscode-cfgs": + cmd_vscode_cfgs(args.config, args.map) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tools/kconfig/requirements.txt b/tools/kconfig/requirements.txt new file mode 100644 index 00000000..3c91d891 --- /dev/null +++ b/tools/kconfig/requirements.txt @@ -0,0 +1,2 @@ +PySocks>=1.7.1 +kconfiglib>=14.1.0 diff --git a/tools/kconfig/save_defconfig.sh b/tools/kconfig/save_defconfig.sh new file mode 100755 index 00000000..f474d5d3 --- /dev/null +++ b/tools/kconfig/save_defconfig.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Write CONFIG_* lines from repo-root .config to the board defconfig (sorted). +set -euo pipefail +ARCH="${1:?arch}" +BOARD="${2:?board}" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" +cd "$ROOT" + +OUT="platform/${ARCH}/${BOARD}/kconfig/defconfig" +mkdir -p "$(dirname "$OUT")" +if [[ ! -f .config ]]; then + echo "error: no .config in repo root" >&2 + exit 1 +fi +grep '^CONFIG_' .config | LC_ALL=C sort >"$OUT" +echo "wrote $OUT" diff --git a/tools/read_features.sh b/tools/read_features.sh deleted file mode 100755 index 81b0b484..00000000 --- a/tools/read_features.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -set -e - -ARCH=$1 -BOARD=$2 - -FEATURES="platform/$ARCH/$BOARD/cargo/features" -FEATURES=$(cat $FEATURES) -FEATURES=$(echo $FEATURES | tr '\n' ' ') -FEATURES=$(echo $FEATURES | tr -d '\r') -echo $FEATURES