From c55cdadaad75864e8dbab72651e2156f31d85906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Wed, 27 Nov 2024 01:08:56 +0000 Subject: [PATCH] [feat] add nvme support --- Cargo.lock | 443 ++++++++++++++---------- api/axfeat/Cargo.toml | 1 + examples/shell/README.md | 10 + modules/axdriver/Cargo.toml | 13 +- modules/axdriver/build.rs | 2 +- modules/axdriver/src/bus/pci.rs | 33 ++ modules/axdriver/src/drivers.rs | 28 ++ modules/axdriver/src/lib.rs | 5 +- modules/axdriver/src/macros.rs | 5 + modules/axdriver/src/nvme.rs | 98 ++++++ modules/axhal/Cargo.toml | 1 + modules/axhal/src/arch/aarch64/cache.rs | 49 +++ modules/axhal/src/arch/aarch64/mod.rs | 1 + modules/axhal/src/arch/riscv/cache.rs | 13 + modules/axhal/src/arch/riscv/mod.rs | 1 + modules/axhal/src/arch/x86_64/cache.rs | 13 + modules/axhal/src/arch/x86_64/mod.rs | 1 + modules/axhal/src/dma.rs | 26 ++ modules/axhal/src/lib.rs | 2 + scripts/make/qemu.mk | 11 +- ulib/axstd/Cargo.toml | 1 + 21 files changed, 573 insertions(+), 184 deletions(-) create mode 100644 examples/shell/README.md create mode 100644 modules/axdriver/src/nvme.rs create mode 100644 modules/axhal/src/arch/aarch64/cache.rs create mode 100644 modules/axhal/src/arch/riscv/cache.rs create mode 100644 modules/axhal/src/arch/x86_64/cache.rs create mode 100644 modules/axhal/src/dma.rs diff --git a/Cargo.lock b/Cargo.lock index 2547d9bd92..d255373871 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,14 +8,14 @@ version = "9.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac42a04a61c19fc8196dd728022a784baecc5d63d7e256c01ad1b3fbfab26287" dependencies = [ - "tock-registers", + "tock-registers 0.8.1", ] [[package]] name = "aho-corasick" -version = "1.0.4" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6748e8def348ed4d14996fa801f4122cd763fff530258cdc03f64b25f89d3a5a" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] @@ -128,7 +128,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47d25e73c949c69f75d1b9dba39c5475523403b31eb8c2fdc99da4dc33bc1aca" dependencies = [ - "tock-registers", + "tock-registers 0.8.1", ] [[package]] @@ -137,7 +137,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "efcf6afca4502993a737ba1e00952d1321078689da92bf7aab27d4e5756c0bec" dependencies = [ - "tock-registers", + "tock-registers 0.8.1", ] [[package]] @@ -151,18 +151,18 @@ dependencies = [ [[package]] name = "atomic-polyfill" -version = "0.1.11" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3ff7eb3f316534d83a8a2c3d1674ace8a5a71198eba31e2e2b597833f699b28" +checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4" dependencies = [ "critical-section", ] [[package]] name = "autocfg" -version = "1.1.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "axalloc" @@ -226,6 +226,8 @@ dependencies = [ "axhal", "cfg-if", "log", + "nvme-driver", + "pcie", ] [[package]] @@ -375,6 +377,7 @@ dependencies = [ "axlog", "bitflags 2.6.0", "cfg-if", + "dma-api", "dw_apb_uart", "handler_table", "int_ratio", @@ -387,12 +390,12 @@ dependencies = [ "page_table_entry", "page_table_multiarch", "percpu", - "raw-cpuid 11.1.0", + "raw-cpuid 11.2.0", "riscv", "riscv_goldfish", "sbi-rt", "static_assertions", - "tock-registers", + "tock-registers 0.8.1", "x2apic", "x86", "x86_64 0.15.1", @@ -537,15 +540,15 @@ source = "git+https://github.com/lhw2002426/bcm2835-sdhci.git?rev=e974f16#e974f1 dependencies = [ "aarch64-cpu", "log", - "tock-registers", + "tock-registers 0.8.1", "volatile 0.2.7", ] [[package]] name = "bindgen" -version = "0.69.4" +version = "0.69.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" +checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088" dependencies = [ "bitflags 2.6.0", "cexpr", @@ -560,7 +563,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.70", + "syn 2.0.89", "which", ] @@ -611,15 +614,15 @@ checksum = "a7913f22349ffcfc6ca0ca9a656ec26cfbba538ed49c31a273dff2c5d1ea83d9" [[package]] name = "bumpalo" -version = "3.13.0" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cap_access" @@ -632,11 +635,11 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.83" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47" dependencies = [ - "libc", + "shlex", ] [[package]] @@ -670,9 +673,9 @@ dependencies = [ [[package]] name = "clang-sys" -version = "1.6.1" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" dependencies = [ "glob", "libc", @@ -687,9 +690,9 @@ checksum = "0b396d1f76d455557e1218ec8066ae14bba60b4b36ecd55577ba979f5db7ecaa" [[package]] name = "core-foundation-sys" -version = "0.8.4" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "core_detect" @@ -714,20 +717,20 @@ checksum = "6af24c4862260a825484470f5526a91ad1031e04ab899be62478241231f62b46" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.89", ] [[package]] name = "critical-section" -version = "1.1.2" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" +checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" [[package]] name = "defmt" -version = "0.3.5" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8a2d011b2fee29fb7d659b83c43fce9a2cb4df453e16d441a51448e448f3f98" +checksum = "a99dd22262668b887121d4672af5a64b238f026099f1a2a1b322066c9ecfe9e0" dependencies = [ "bitflags 1.3.2", "defmt-macros", @@ -735,40 +738,46 @@ dependencies = [ [[package]] name = "defmt-macros" -version = "0.3.6" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54f0216f6c5acb5ae1a47050a6645024e6edafc2ee32d421955eccfef12ef92e" +checksum = "e3a9f309eff1f79b3ebdf252954d90ae440599c26c2c553fe87a2d17195f2dcb" dependencies = [ "defmt-parser", "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.89", ] [[package]] name = "defmt-parser" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "269924c02afd7f94bc4cecbfa5c379f6ffcf9766b3408fe63d22c728654eccd0" +checksum = "ff4a5fefe330e8d7f31b16a318f9ce81000d8e35e69b93eae154d16d2278f70f" dependencies = [ "thiserror", ] +[[package]] +name = "dma-api" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f334c8a53134f5d452bf230cf5cf046f8b3f97c402bdd965bfe49fee646fe13b" + [[package]] name = "dw_apb_uart" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f93d496c8faa9dc676ebfa225432e1e3b57645c9268ead889286546f6d39356d" dependencies = [ - "tock-registers", + "tock-registers 0.8.1", ] [[package]] name = "either" -version = "1.9.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "embedded-hal" @@ -782,6 +791,16 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "fatfs" version = "0.4.0" @@ -802,9 +821,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.10" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -834,15 +853,15 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" [[package]] name = "heapless" -version = "0.7.16" +version = "0.7.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db04bc24a18b9ea980628ecf00e6c0264f3c1426dac36c00cb49b6fbad8b0743" +checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f" dependencies = [ "atomic-polyfill", "hash32", @@ -851,11 +870,20 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys", +] + [[package]] name = "iana-time-zone" -version = "0.1.60" +version = "0.1.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -876,9 +904,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", "hashbrown", @@ -892,9 +920,9 @@ checksum = "0640a6c478a68d4899fec305f97afa6e34afce49d4d952d2b9599fd52615b2a7" [[package]] name = "itertools" -version = "0.10.5" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" dependencies = [ "either", ] @@ -913,9 +941,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" dependencies = [ "wasm-bindgen", ] @@ -963,18 +991,18 @@ checksum = "3861aac8febbb038673bf945ee47ac67940ca741b94d1bb3ff6066af2a181338" [[package]] name = "libc" -version = "0.2.147" +version = "0.2.166" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "c2ccc108bbc0b1331bd061864e7cd823c0cab660bbe6970e66e2c0614decde36" [[package]] name = "libloading" -version = "0.7.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", - "winapi", + "windows-targets", ] [[package]] @@ -984,29 +1012,35 @@ source = "git+https://github.com/arceos-org/linked_list.git?tag=v0.1.0#34c8db301 [[package]] name = "linkme" -version = "0.3.27" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccb76662d78edc9f9bf56360d6919bdacc8b7761227727e5082f128eeb90bbf5" +checksum = "566336154b9e58a4f055f6dd4cbab62c7dc0826ce3c0a04e63b2d2ecd784cdae" dependencies = [ "linkme-impl", ] [[package]] name = "linkme-impl" -version = "0.3.27" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dccda732e04fa3baf2e17cf835bfe2601c7c2edafd64417c627dabae3a8cda" +checksum = "edbe595006d355eaf9ae11db92707d4338cd2384d16866131cc1afdbdd35d8d9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.89", ] +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + [[package]] name = "lock_api" -version = "0.4.10" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -1026,9 +1060,9 @@ checksum = "0ca88d725a0a943b096803bd34e73a4437208b6077654cc4ecb2947a5f91618d" [[package]] name = "memchr" -version = "2.5.0" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "memory_addr" @@ -1054,24 +1088,36 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.16" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] +[[package]] +name = "nvme-driver" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "961925b5f122ccdb7ffdda9f563e5efa683d477c31b5e60865668a1324160d1c" +dependencies = [ + "dma-api", + "log", + "sparreal-macros", + "tock-registers 0.9.0", +] + [[package]] name = "once_cell" -version = "1.18.0" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "page_table_entry" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d911cfe86a8529a3fabfafa39a857a57cb8d00046ddca14fa609b289303bc7c" +checksum = "6db6393e4382afb7063e4859f39a7db998c4ba9b842a59b05c138c6a6f524fac" dependencies = [ "aarch64-cpu", "bitflags 2.6.0", @@ -1081,9 +1127,9 @@ dependencies = [ [[package]] name = "page_table_multiarch" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43068c68a7fee18c1749befb515f69f6b1fcc18a4908e0d96e64fc51258d301a" +checksum = "e37ddd25f6c9291ed3d1ba2aacecf1fd8c94ff070242d78dcfe2d4bd47e0bd48" dependencies = [ "log", "memory_addr", @@ -1098,6 +1144,29 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "pci_types" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4325c6aa3cca3373503b1527e75756f9fbfe5fd76be4b4c8a143ee47430b8e0" +dependencies = [ + "bit_field", + "bitflags 2.6.0", +] + +[[package]] +name = "pcie" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b62a36afa396138fc9508886770ed285ee952abff129bd3c614568d359beeff2" +dependencies = [ + "bit_field", + "bitflags 2.6.0", + "log", + "pci_types", + "sparreal-macros", +] + [[package]] name = "percpu" version = "0.1.3" @@ -1119,23 +1188,26 @@ checksum = "37bd51d4112e25524bd18b8a0a4bd2526f35686316ccfe7f6b890bf57b455578" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.89", ] [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] [[package]] name = "prettyplease" -version = "0.2.12" +version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c64d9ba0963cdcea2e1b2230fbae2bab30eb25a174be395c41e764bfb65dd62" +checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" dependencies = [ "proc-macro2", - "syn 2.0.70", + "syn 2.0.89", ] [[package]] @@ -1164,18 +1236,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -1221,18 +1293,18 @@ dependencies = [ [[package]] name = "raw-cpuid" -version = "11.1.0" +version = "11.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb9ee317cfe3fbd54b36a511efc1edd42e216903c9cd575e686dd68a2ba90d8d" +checksum = "1ab240315c661615f2ee9f0f2cd32d5a7343a84d5ebcccb99d46e6637565e7b0" dependencies = [ "bitflags 2.6.0", ] [[package]] name = "regex" -version = "1.9.3" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81bc1d4caf89fac26a70747fe603c130093b53c773888797a6329091246d651a" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", @@ -1242,9 +1314,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.6" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed1ceff11a1dddaee50c9dc8e4938bd106e9d89ae372f192311e7da498e3b69" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -1253,9 +1325,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.7.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "riscv" @@ -1293,18 +1365,31 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustc_version" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.38.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" +dependencies = [ + "bitflags 2.6.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "rustversion" -version = "1.0.14" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" +checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" [[package]] name = "sbi-rt" @@ -1337,35 +1422,35 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "semver" -version = "1.0.18" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.204" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.204" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.89", ] [[package]] name = "shlex" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "slab_allocator" @@ -1389,6 +1474,17 @@ dependencies = [ "managed", ] +[[package]] +name = "sparreal-macros" +version = "0.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f686073b67b2427c9243bddc10ea0a6a5300ab5354a8ee884d9126854b0abab7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.89", +] + [[package]] name = "spin" version = "0.9.8" @@ -1436,9 +1532,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.70" +version = "2.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0209b68b3613b093e0ec905354eccaedcfe83b8cb37cbdeae64026c3064c16" +checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" dependencies = [ "proc-macro2", "quote", @@ -1447,22 +1543,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.47" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97a802ec30afc17eee47b2855fc72e0c4cd62be9b4efe6591edde0ec5bd68d8f" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.47" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bb623b56e39ab7dcd4b1b98bb6c8f8d907ed255b18de254088016b27a8ee19b" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.89", ] [[package]] @@ -1477,6 +1573,12 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "696941a0aee7e276a165a978b37918fd5d22c55c3d6bda197813070ca9c0f21c" +[[package]] +name = "tock-registers" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b9e2fdb3a1e862c0661768b7ed25390811df1947a8acbfbefe09b47078d93c4" + [[package]] name = "toml_datetime" version = "0.6.8" @@ -1485,9 +1587,9 @@ checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" [[package]] name = "toml_edit" -version = "0.22.20" +version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap", "toml_datetime", @@ -1496,21 +1598,21 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.11" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "unicode-width" -version = "0.1.10" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "virtio-drivers" @@ -1549,34 +1651,35 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.89", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1584,70 +1687,58 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.89", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" [[package]] name = "which" -version = "4.4.0" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" dependencies = [ "either", - "libc", + "home", "once_cell", + "rustix", ] [[package]] -name = "winapi" -version = "0.3.9" +name = "windows-core" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "windows-targets", ] [[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-core" +name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -1661,57 +1752,57 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.18" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" dependencies = [ "memchr", ] @@ -1792,5 +1883,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.70", + "syn 2.0.89", ] diff --git a/api/axfeat/Cargo.toml b/api/axfeat/Cargo.toml index 412fdb8027..e8b661b8d3 100644 --- a/api/axfeat/Cargo.toml +++ b/api/axfeat/Cargo.toml @@ -55,6 +55,7 @@ bus-pci = ["axdriver?/bus-pci"] driver-ramdisk = ["axdriver?/ramdisk", "axfs?/use-ramdisk"] driver-ixgbe = ["axdriver?/ixgbe"] driver-bcm2835-sdhci = ["axdriver?/bcm2835-sdhci"] +driver-nvme = ["axdriver?/nvme"] # Logging log-level-off = ["axlog/log-level-off"] diff --git a/examples/shell/README.md b/examples/shell/README.md new file mode 100644 index 0000000000..e55f5ae86f --- /dev/null +++ b/examples/shell/README.md @@ -0,0 +1,10 @@ +# Useage + +## Example + +use nvme as block device. + +```bash +make disk_img +make A=examples/shell ARCH=x86_64 LOG=info SMP=4 ACCEL=N FEATURES=driver-nvme APP_FEATURES=use-ramfs BLK=y run +``` \ No newline at end of file diff --git a/modules/axdriver/Cargo.toml b/modules/axdriver/Cargo.toml index ff38017f48..93be1f5a04 100644 --- a/modules/axdriver/Cargo.toml +++ b/modules/axdriver/Cargo.toml @@ -2,7 +2,10 @@ name = "axdriver" version.workspace = true edition = "2021" -authors = ["Yuekai Jia ", "ChengXiang Qi "] +authors = [ + "Yuekai Jia ", + "ChengXiang Qi ", +] description = "ArceOS device drivers" license.workspace = true homepage.workspace = true @@ -12,7 +15,7 @@ documentation = "https://arceos-org.github.io/arceos/axdriver/index.html" [features] dyn = [] bus-mmio = [] -bus-pci = ["dep:axdriver_pci", "dep:axhal", "dep:axconfig"] +bus-pci = ["dep:axdriver_pci", "dep:axhal", "dep:axconfig", "dep:pcie"] net = ["axdriver_net"] block = ["axdriver_block"] display = ["axdriver_display"] @@ -27,6 +30,7 @@ virtio-gpu = ["display", "virtio", "axdriver_virtio/gpu"] ramdisk = ["block", "axdriver_block/ramdisk"] bcm2835-sdhci = ["block", "axdriver_block/bcm2835-sdhci"] ixgbe = ["net", "axdriver_net/ixgbe", "dep:axalloc", "dep:axhal", "dep:axdma"] +nvme = ["block", "bus-pci", "dep:nvme-driver", "dep:axalloc", "dep:axhal", "axhal/alloc"] # more devices example: e1000 = ["net", "axdriver_net/e1000"] default = ["bus-pci"] @@ -43,4 +47,7 @@ axdriver_virtio = { git = "https://github.com/arceos-org/axdriver_crates.git", t axalloc = { workspace = true, optional = true } axhal = { workspace = true, optional = true } axconfig = { workspace = true, optional = true } -axdma = { workspace = true, optional = true } \ No newline at end of file +axdma = { workspace = true, optional = true } +pcie = { version = "0.2", optional = true } +nvme-driver = { version = "0.2", optional = true } + diff --git a/modules/axdriver/build.rs b/modules/axdriver/build.rs index 8d5fd0710a..abe2599837 100644 --- a/modules/axdriver/build.rs +++ b/modules/axdriver/build.rs @@ -1,5 +1,5 @@ const NET_DEV_FEATURES: &[&str] = &["ixgbe", "virtio-net"]; -const BLOCK_DEV_FEATURES: &[&str] = &["ramdisk", "bcm2835-sdhci", "virtio-blk"]; +const BLOCK_DEV_FEATURES: &[&str] = &["nvme", "ramdisk", "bcm2835-sdhci", "virtio-blk"]; const DISPLAY_DEV_FEATURES: &[&str] = &["virtio-gpu"]; fn make_cfg_values(str_list: &[&str]) -> String { diff --git a/modules/axdriver/src/bus/pci.rs b/modules/axdriver/src/bus/pci.rs index a83ae9af59..be5b2d2ddf 100644 --- a/modules/axdriver/src/bus/pci.rs +++ b/modules/axdriver/src/bus/pci.rs @@ -1,8 +1,12 @@ +use alloc::vec::Vec; +use core::ptr::NonNull; + use crate::{prelude::*, AllDevices}; use axdriver_pci::{ BarInfo, Cam, Command, DeviceFunction, HeaderType, MemoryBarType, PciRangeAllocator, PciRoot, }; use axhal::mem::phys_to_virt; +use pcie::{Header, RootComplexGeneric}; const PCI_BAR_NUM: u8 = 6; @@ -84,6 +88,35 @@ fn config_pci_device( impl AllDevices { pub(crate) fn probe_bus_devices(&mut self) { + self.probe_pci_devices(); + self.probe_pcie_devices(); + } + + fn probe_pcie_devices(&mut self) { + let base_vaddr = phys_to_virt(axconfig::PCI_ECAM_BASE.into()); + let mut root = RootComplexGeneric::new(NonNull::new(base_vaddr.as_mut_ptr()).unwrap()); + + let headers = root.enumerate_no_modify(None).collect::>(); + + for header in headers { + if let Header::Endpoint(ep) = header { + for_each_drivers!(type Driver, { + if let Some(dev) = Driver::probe_pcie(&mut root, ep.clone()) { + info!( + "registered a new {:?} device at {:?}: {:?}", + dev.device_type(), + ep.address, + dev.device_name(), + ); + self.add_device(dev); + continue; // skip to the next device + } + }) + } + } + } + + fn probe_pci_devices(&mut self) { let base_vaddr = phys_to_virt(axconfig::PCI_ECAM_BASE.into()); let mut root = unsafe { PciRoot::new(base_vaddr.as_mut_ptr(), Cam::Ecam) }; diff --git a/modules/axdriver/src/drivers.rs b/modules/axdriver/src/drivers.rs index 4c9d467d5c..ba00df9598 100644 --- a/modules/axdriver/src/drivers.rs +++ b/modules/axdriver/src/drivers.rs @@ -31,6 +31,14 @@ pub trait DriverProbe { ) -> Option { None } + + #[cfg(bus = "pci")] + fn probe_pcie( + _root: &mut pcie::RootComplexGeneric, + _ep: pcie::Endpoint, + ) -> Option { + None + } } #[cfg(net_dev = "virtio-net")] @@ -128,3 +136,23 @@ cfg_if::cfg_if! { } } } + +cfg_if::cfg_if! { + if #[cfg(block_dev="nvme")] { + use crate::nvme::Nvme; + use pcie::{Endpoint, RootComplexGeneric}; + pub struct NvmeDriver; + register_block_driver!(NvmeDriver, Nvme); + + impl DriverProbe for NvmeDriver { + #[cfg(bus = "pci")] + fn probe_pcie(root: &mut RootComplexGeneric, ep: Endpoint) -> Option { + use crate::AxDeviceEnum; + + let dev = Nvme::new(root, ep)?; + + Some(AxDeviceEnum::from_block(dev)) + } + } + } +} diff --git a/modules/axdriver/src/lib.rs b/modules/axdriver/src/lib.rs index 659d95cdef..065d494cdb 100644 --- a/modules/axdriver/src/lib.rs +++ b/modules/axdriver/src/lib.rs @@ -61,7 +61,7 @@ #[macro_use] extern crate log; -#[cfg(feature = "dyn")] +#[cfg(any(feature = "dyn", feature = "bus-pci"))] extern crate alloc; #[macro_use] @@ -78,6 +78,9 @@ mod virtio; #[cfg(feature = "ixgbe")] mod ixgbe; +#[cfg(feature = "nvme")] +mod nvme; + pub mod prelude; #[allow(unused_imports)] diff --git a/modules/axdriver/src/macros.rs b/modules/axdriver/src/macros.rs index b90e813e70..1736ea0869 100644 --- a/modules/axdriver/src/macros.rs +++ b/modules/axdriver/src/macros.rs @@ -64,5 +64,10 @@ macro_rules! for_each_drivers { type $drv_type = crate::drivers::IxgbeDriver; $code } + #[cfg(block_dev = "nvme")] + { + type $drv_type = crate::drivers::NvmeDriver; + $code + } }}; } diff --git a/modules/axdriver/src/nvme.rs b/modules/axdriver/src/nvme.rs new file mode 100644 index 0000000000..89eef44209 --- /dev/null +++ b/modules/axdriver/src/nvme.rs @@ -0,0 +1,98 @@ +use core::ptr::NonNull; + +use axhal::mem::phys_to_virt; +use nvme_driver::{Config, Namespace}; +use pcie::{Chip, CommandRegister, DeviceType, Endpoint, RootComplex}; + +use crate::{BaseDriverOps, BlockDriverOps}; + +pub struct Nvme { + inner: nvme_driver::Nvme, + ns: Namespace, +} + +unsafe impl Send for Nvme {} +unsafe impl Sync for Nvme {} + +impl Nvme { + pub fn new(root: &mut RootComplex, ep: Endpoint) -> Option { + info!("probe: {:?}", ep); + + ep.update_command(root, |cmd| { + cmd | CommandRegister::IO_ENABLE + | CommandRegister::MEMORY_ENABLE + | CommandRegister::BUS_MASTER_ENABLE + }); + + if ep.device_type() == DeviceType::NvmeController { + let bar_addr = match ep.bar { + pcie::BarVec::Memory32(bar_vec_t) => { + let bar0 = bar_vec_t[0].as_ref().unwrap(); + bar0.address as usize + } + pcie::BarVec::Memory64(bar_vec_t) => { + let bar0 = bar_vec_t[0].as_ref().unwrap(); + bar0.address as usize + } + pcie::BarVec::Io(_bar_vec_t) => return None, + }; + + let addr = phys_to_virt(bar_addr.into()); + + let mut nvme = nvme_driver::Nvme::new( + unsafe { NonNull::new_unchecked(addr.as_mut_ptr()) }, + Config { + page_size: 0x1000, + io_queue_pair_count: 1, + }, + ) + .inspect_err(|e| error!("{:?}", e)) + .unwrap(); + let ns_list = nvme.namespace_list().ok()?; + let ns = ns_list.first()?; + + return Some(Self { + inner: nvme, + ns: *ns, + }); + } + + None + } +} + +impl BaseDriverOps for Nvme { + fn device_name(&self) -> &str { + "NVME" + } + + fn device_type(&self) -> crate::DeviceType { + crate::DeviceType::Block + } +} + +impl BlockDriverOps for Nvme { + fn num_blocks(&self) -> u64 { + self.ns.lba_count as _ + } + + fn block_size(&self) -> usize { + self.ns.lba_size + } + + fn read_block(&mut self, block_id: u64, buf: &mut [u8]) -> crate::DevResult { + self.inner + .block_read_sync(&self.ns, block_id as _, buf) + .map_err(|_e| crate::DevError::Io) + } + + fn write_block(&mut self, block_id: u64, buf: &[u8]) -> crate::DevResult { + self.inner + .block_write_sync(&self.ns, block_id, buf) + .map_err(|_e| crate::DevError::Io) + } + + fn flush(&mut self) -> crate::DevResult { + Ok(()) + } +} diff --git a/modules/axhal/Cargo.toml b/modules/axhal/Cargo.toml index 5c48b0153f..e28d0dcb25 100644 --- a/modules/axhal/Cargo.toml +++ b/modules/axhal/Cargo.toml @@ -37,6 +37,7 @@ page_table_multiarch = { version = "0.4", optional = true } axlog = { workspace = true } axconfig = { workspace = true } axalloc = { workspace = true, optional = true } +dma-api = { version = "0.1" } [target.'cfg(target_arch = "x86_64")'.dependencies] x86 = "0.52" diff --git a/modules/axhal/src/arch/aarch64/cache.rs b/modules/axhal/src/arch/aarch64/cache.rs new file mode 100644 index 0000000000..5c76a3c706 --- /dev/null +++ b/modules/axhal/src/arch/aarch64/cache.rs @@ -0,0 +1,49 @@ +#![allow(unused)] + +use core::{arch::asm, ptr::NonNull}; + +fn dcache_line_size() -> usize { + unsafe { + let result; + asm!( + "mrs x8, CTR_EL0", + "ubfm x8, x8, #16, #19", // cache line size encoding + "mov {0}, #4", // bytes per word + "lsl {0}, {0}, x8", // actual cache line size""", + out(reg) result); + + result + } +} + +/// Invalidate data cache +pub fn dcache_invalidate_range(addr: NonNull, size: usize) { + let addr = addr.as_ptr() as usize; + unsafe { + let line_size = dcache_line_size(); + let start = addr & !(line_size - 1); + let end = (addr + size + line_size - 1) & !(line_size - 1); + + for addr in (start..end).step_by(line_size) { + asm!("dc ivac, {0}", in(reg) addr); + } + + asm!("dsb sy"); + } +} + +/// Clean data cache +pub fn dcache_clean_range(addr: NonNull, size: usize) { + let addr = addr.as_ptr() as usize; + unsafe { + let line_size = dcache_line_size(); + let start = addr & !(line_size - 1); + let end = (addr + size + line_size - 1) & !(line_size - 1); + + for addr in (start..end).step_by(line_size) { + asm!("dc cvac, {0}", in(reg) addr); + } + + asm!("dsb sy"); + } +} diff --git a/modules/axhal/src/arch/aarch64/mod.rs b/modules/axhal/src/arch/aarch64/mod.rs index 160dabdd12..d19998020b 100644 --- a/modules/axhal/src/arch/aarch64/mod.rs +++ b/modules/axhal/src/arch/aarch64/mod.rs @@ -1,3 +1,4 @@ +pub(crate) mod cache; mod context; pub(crate) mod trap; diff --git a/modules/axhal/src/arch/riscv/cache.rs b/modules/axhal/src/arch/riscv/cache.rs new file mode 100644 index 0000000000..0f61229952 --- /dev/null +++ b/modules/axhal/src/arch/riscv/cache.rs @@ -0,0 +1,13 @@ +#![allow(unused)] + +use core::ptr::NonNull; + +/// Invalidate data cache +pub fn dcache_invalidate_range(_addr: NonNull, _size: usize) { + //TODO +} + +/// Clean data cache +pub fn dcache_clean_range(_addr: NonNull, _size: usize) { + //TODO +} diff --git a/modules/axhal/src/arch/riscv/mod.rs b/modules/axhal/src/arch/riscv/mod.rs index df6927dddc..36c0c83828 100644 --- a/modules/axhal/src/arch/riscv/mod.rs +++ b/modules/axhal/src/arch/riscv/mod.rs @@ -1,6 +1,7 @@ #[macro_use] mod macros; +pub mod cache; mod context; mod trap; diff --git a/modules/axhal/src/arch/x86_64/cache.rs b/modules/axhal/src/arch/x86_64/cache.rs new file mode 100644 index 0000000000..0f61229952 --- /dev/null +++ b/modules/axhal/src/arch/x86_64/cache.rs @@ -0,0 +1,13 @@ +#![allow(unused)] + +use core::ptr::NonNull; + +/// Invalidate data cache +pub fn dcache_invalidate_range(_addr: NonNull, _size: usize) { + //TODO +} + +/// Clean data cache +pub fn dcache_clean_range(_addr: NonNull, _size: usize) { + //TODO +} diff --git a/modules/axhal/src/arch/x86_64/mod.rs b/modules/axhal/src/arch/x86_64/mod.rs index c9002a58d3..2215c9f2ba 100644 --- a/modules/axhal/src/arch/x86_64/mod.rs +++ b/modules/axhal/src/arch/x86_64/mod.rs @@ -1,3 +1,4 @@ +pub(crate) mod cache; mod context; mod gdt; mod idt; diff --git a/modules/axhal/src/dma.rs b/modules/axhal/src/dma.rs new file mode 100644 index 0000000000..ae65929366 --- /dev/null +++ b/modules/axhal/src/dma.rs @@ -0,0 +1,26 @@ +use dma_api::Impl; + +use crate::{ + arch::cache::{dcache_clean_range, dcache_invalidate_range}, + mem::virt_to_phys, +}; + +struct DmaImpl; + +impl Impl for DmaImpl { + fn map(addr: core::ptr::NonNull, _size: usize, _direction: dma_api::Direction) -> u64 { + virt_to_phys((addr.as_ptr() as usize).into()).as_usize() as _ + } + + fn unmap(_addr: core::ptr::NonNull, _size: usize) {} + + fn flush(addr: core::ptr::NonNull, size: usize) { + dcache_clean_range(addr, size); + } + + fn invalidate(addr: core::ptr::NonNull, size: usize) { + dcache_invalidate_range(addr, size); + } +} + +dma_api::set_impl!(DmaImpl); diff --git a/modules/axhal/src/lib.rs b/modules/axhal/src/lib.rs index 7e2116e640..36df6a3efe 100644 --- a/modules/axhal/src/lib.rs +++ b/modules/axhal/src/lib.rs @@ -57,6 +57,8 @@ pub mod irq; #[cfg(feature = "paging")] pub mod paging; +mod dma; + /// Console input and output. pub mod console { pub use super::platform::console::*; diff --git a/scripts/make/qemu.mk b/scripts/make/qemu.mk index fd2c78b9a6..446499d4e6 100644 --- a/scripts/make/qemu.mk +++ b/scripts/make/qemu.mk @@ -26,9 +26,14 @@ qemu_args-aarch64 := \ qemu_args-y := -m 128M -smp $(SMP) $(qemu_args-$(ARCH)) -qemu_args-$(BLK) += \ - -device virtio-blk-$(vdev-suffix),drive=disk0 \ - -drive id=disk0,if=none,format=raw,file=$(DISK_IMG) +ifeq ($(findstring driver-nvme,$(FEATURES)), driver-nvme) + qemu_args-$(BLK) += \ + -drive file=$(DISK_IMG),if=none,id=nvm -device nvme,serial=deadbeef,drive=nvm +else + qemu_args-$(BLK) += \ + -device virtio-blk-$(vdev-suffix),drive=disk0 \ + -drive id=disk0,if=none,format=raw,file=$(DISK_IMG) +endif qemu_args-$(NET) += \ -device virtio-net-$(vdev-suffix),netdev=net0 diff --git a/ulib/axstd/Cargo.toml b/ulib/axstd/Cargo.toml index b78282f5c0..c5c793f96e 100644 --- a/ulib/axstd/Cargo.toml +++ b/ulib/axstd/Cargo.toml @@ -63,6 +63,7 @@ bus-pci = ["axfeat/bus-pci"] driver-ramdisk = ["axfeat/driver-ramdisk"] driver-ixgbe = ["axfeat/driver-ixgbe"] driver-bcm2835-sdhci = ["axfeat/driver-bcm2835-sdhci"] +driver-nvme = ["axfeat/driver-nvme"] # Logging log-level-off = ["axfeat/log-level-off"]