Skip to content

Commit d25298a

Browse files
committed
lib: rename MachineInfo to EnvInfo to shorten trait name
Signed-off-by: Zhouqi Jiang <luojia@hust.edu.cn>
1 parent acf4007 commit d25298a

File tree

7 files changed

+58
-56
lines changed

7 files changed

+58
-56
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1818

1919
### Modified
2020

21-
- run on provided `MachineInfo` by default; bare metal M-mode environment should gate `machine`
21+
- run on provided `EnvInfo` by default; bare metal M-mode environment should gate `machine`
2222
- doc: grammar tweaks in hsm module
2323
- update dependency `sbi-spec` to v0.0.6, use `Physical` struct from `sbi-spec` crate.
2424

examples/derive/commons.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Mock implementaion module. Actual SBI implementaion should implement
22
// those SBI extensions with machine environment specific hardware features.
33

4-
use rustsbi::{HartMask, MachineInfo};
4+
use rustsbi::{HartMask, EnvInfo};
55
use sbi_spec::binary::SbiRet;
66

77
pub struct MyFence;
@@ -21,9 +21,9 @@ impl rustsbi::Fence for MyFence {
2121
}
2222
}
2323

24-
pub struct MyMachineInfo;
24+
pub struct MyEnvInfo;
2525

26-
impl MachineInfo for MyMachineInfo {
26+
impl EnvInfo for MyEnvInfo {
2727
fn mvendorid(&self) -> usize {
2828
0x100
2929
}

examples/derive/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct MySBI {
2424
// CSR accesses; developers should enable RustSBI feature `machine` in this case.
2525
// The name `info` is also special, like the name `fence` we have mentioned;
2626
// RustSBI identifies machine information from the field name `info`.
27-
info: MyMachineInfo,
27+
info: MyEnvInfo,
2828
}
2929

3030
// We have a properly defined RustSBI implementation called `MySBI`. Now `MySBI`
@@ -38,7 +38,7 @@ fn main() {
3838
// as a stack variable for now.
3939
let sbi = MySBI {
4040
fence: MyFence,
41-
info: MyMachineInfo,
41+
info: MyEnvInfo,
4242
};
4343

4444
// In S-mode environment call handler, call the `handle_ecall` of the SBI instance.

macros/src/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct RustSBIImp<'a> {
1515
cppc: Option<&'a Ident>,
1616
nacl: Option<&'a Ident>,
1717
sta: Option<&'a Ident>,
18-
machine_info: Option<&'a Ident>,
18+
env_info: Option<&'a Ident>,
1919
}
2020

2121
/// This macro should be used in `rustsbi` crate as `rustsbi::RustSBI`.
@@ -56,7 +56,7 @@ pub fn derive_rustsbi(input: TokenStream) -> TokenStream {
5656
"cppc" => imp.cppc = Some(name),
5757
"nacl" => imp.nacl = Some(name),
5858
"sta" => imp.sta = Some(name),
59-
"info" | "machine_info" => imp.machine_info = Some(name),
59+
"info" | "env_info" => imp.env_info = Some(name),
6060
_ => {}
6161
}
6262
}
@@ -96,17 +96,18 @@ fn impl_derive_rustsbi(name: &Ident, imp: RustSBIImp) -> TokenStream {
9696
sta: #sta_probe,
9797
}
9898
};
99-
let base_procedure = if let Some(machine_info) = imp.machine_info {
99+
let base_procedure = if let Some(env_info) = imp.env_info {
100100
quote! {
101-
::rustsbi::spec::base::EID_BASE => ::rustsbi::_rustsbi_base_machine_info(param, function, &self.#machine_info, #probe),
101+
::rustsbi::spec::base::EID_BASE => ::rustsbi::_rustsbi_base_env_info(param, function, &self.#env_info, #probe),
102102
}
103103
} else {
104104
match () {
105105
#[cfg(not(feature = "machine"))]
106106
() => quote! {
107107
::rustsbi::spec::base::EID_BASE => compile_error!(
108-
"can't derive RustSBI: #[cfg(feature = \"machine\")] is needed to derive RustSBI with no extra MachineInfo provided; \
109-
consider adding an `info` parameter to provide machine information if RustSBI is not run on machine mode."
108+
"can't derive RustSBI: #[cfg(feature = \"machine\")] is needed to derive RustSBI with no extra `EnvInfo` provided; \
109+
consider adding an `info` parameter to provide machine information implementing `rustsbi::EnvInfo`\
110+
if RustSBI is not run on machine mode."
110111
),
111112
},
112113
#[cfg(feature = "machine")]

src/lib.rs

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,12 @@
362362
//! or provide another set of information to override the current environment. Notably,
363363
//! RISC-V hypervisors do not have direct access to machine mode (M-mode) registers.
364364
//!
365-
//! RustSBI supports both by providing a `MachineInfo` structure in instance based interface.
365+
//! RustSBI supports both by providing a `EnvInfo` structure in instance based interface.
366366
//! If RISC-V hypervisors choose to use existing information on current machine, it may require
367-
//! to call underlying M-mode environment using SBI calls and fill in information into `MachineInfo`.
367+
//! to call underlying M-mode environment using SBI calls and fill in information into `EnvInfo`.
368368
//! If hypervisors use customized information other than taking the same one from the
369-
//! environment they reside in, they may fill in custom one into `MachineInfo` structures.
370-
//! When creating RustSBI instance, `MachineInfo` structure is required as an input of constructor.
369+
//! environment they reside in, they may fill in custom one into `EnvInfo` structures.
370+
//! When creating RustSBI instance, `EnvInfo` structure is required as an input of constructor.
371371
//!
372372
//! To begin with, include RustSBI library in file `Cargo.toml`:
373373
//!
@@ -550,7 +550,7 @@ pub extern crate sbi_spec as spec;
550550
///
551551
/// # Usage
552552
///
553-
/// The `#[derive(RustSBI)]` macro provides a convenient way of building `RustSBI` trait implementation.
553+
/// The `#[derive(RustSBI)]` macro provides a convenient way of building `RustSBI` trait implementations.
554554
/// To use this macro, say that we have a struct `MyFence` with RISC-V SBI Remote Fence extension
555555
/// implemented using `rustsbi::Fence` trait. Then, we build a struct around it, representing a
556556
/// whole SBI implementation including one `Fence` extension only; we can name it `MySBI`:
@@ -572,10 +572,10 @@ pub extern crate sbi_spec as spec;
572572
/// }
573573
/// ```
574574
///
575-
/// Here, we declared the field named `fence` with type `MyFence`. The name `fence` is special, it tells
576-
/// RustSBI derive macro that this field implements SBI Remote Fence instead of other SBI extensions.
575+
/// Here, we declared the field named `fence` with type `MyFence`. The variable name `fence` is special,
576+
/// it tells RustSBI derive macro that this field implements SBI Remote Fence instead of other SBI extensions.
577577
/// We can continue to adding more fields into `MySBI`. For example, if we have RISC-V SBI Time extension
578-
/// implementation `MyTimer`, we can add it to `MySBI`:
578+
/// implementation with type `MyTimer`, we can add it to `MySBI`:
579579
///
580580
/// ```rust
581581
/// struct MySBI {
@@ -615,7 +615,7 @@ pub extern crate sbi_spec as spec;
615615
/// Oops! Compile failed. We'd check what happened here:
616616
///
617617
/// ```text
618-
/// error: can't derive RustSBI: #[cfg(feature = "machine")] is needed to derive RustSBI with no extra MachineInfo provided; consider adding an `info` parameter to provide machine information if RustSBI is not run on machine mode.
618+
/// error: can't derive RustSBI: #[cfg(feature = "machine")] is needed to derive RustSBI with no extra `EnvInfo` provided; consider adding an `info` parameter to provide machine information implementing `rustsbi::EnvInfo` if RustSBI is not run on machine mode.
619619
/// --> example.rs:LL:10
620620
/// |
621621
/// LL | #[derive(RustSBI)]
@@ -626,12 +626,12 @@ pub extern crate sbi_spec as spec;
626626
/// error: aborting due to previous error
627627
/// ```
628628
///
629-
/// The error message hints that we don't have machine information implementing trait `MachineInfo`
630-
/// provided. By default, RustSBI is targeted to provide RISC-V supervisor environment on any hardware,
629+
/// The error message hints that we didn't provide any SBI environment information implementing trait
630+
/// `EnvInfo`. By default, RustSBI is targeted to provide RISC-V supervisor environment on any hardware,
631631
/// targeting hypervisor, emulator and binary translation applications. In this case, the virtualized
632-
/// environment should provide the supervisor with machine information like `mvendorid`, `marchid` and
633-
/// `mimpid` values. RustSBI could also be used on bare-metal RISC-V machines where such values would
634-
/// be directly accessible through CSR read operations.
632+
/// environment should provide the supervisor with machine environment information like `mvendorid`,
633+
/// `marchid` and `mimpid` values. RustSBI could also be used on bare-metal RISC-V machines where such
634+
/// values would be directly accessible through CSR read operations.
635635
///
636636
/// If we are targeting bare-metal, we can use the RustSBI library with `#[cfg(feature = "machine")]`
637637
/// enabled by changing `dependencies` section in `Cargo.toml` file (if we are using Cargo):
@@ -642,7 +642,7 @@ pub extern crate sbi_spec as spec;
642642
/// ```
643643
///
644644
/// If that's not the case and we are writing a virtualization targeted application, we should add a
645-
/// `MachineInfo` implementation into the structure like `MySBI` mentioned above, with a special field
645+
/// `EnvInfo` implementation into the structure like `MySBI` mentioned above, with a special field
646646
/// name `info`. We can do it like:
647647
///
648648
/// ```rust
@@ -651,12 +651,12 @@ pub extern crate sbi_spec as spec;
651651
/// fence: MyFence,
652652
/// timer: MyTimer,
653653
/// # #[cfg(not(feature = "machine"))]
654-
/// info: MyMachineInfo,
654+
/// info: MyEnvInfo,
655655
/// }
656656
///
657-
/// struct MyMachineInfo;
657+
/// struct MyEnvInfo;
658658
///
659-
/// impl rustsbi::MachineInfo for MyMachineInfo {
659+
/// impl rustsbi::EnvInfo for MyEnvInfo {
660660
/// #[inline]
661661
/// fn mvendorid(&self) -> usize { todo!("add real value here") }
662662
/// #[inline]
@@ -690,14 +690,14 @@ pub extern crate sbi_spec as spec;
690690
/// #[derive(RustSBI)]
691691
/// struct MySBI {
692692
/// /* we omit the extension fields by now */
693-
/// # info: MyMachineInfo,
693+
/// # info: MyEnvInfo,
694694
/// }
695695
///
696696
/// fn main() {
697697
/// // Create a MySBI instance.
698698
/// let sbi = MySBI {
699699
/// /* include initial values for fields */
700-
/// # info: MyMachineInfo
700+
/// # info: MyEnvInfo
701701
/// };
702702
/// // Make the call. Read SBI implementation ID resides in extension Base (0x10),
703703
/// // with function id 1, and it doesn't have any parameters.
@@ -706,8 +706,8 @@ pub extern crate sbi_spec as spec;
706706
/// println!("SBI implementation ID for MySBI: {}", ret.value);
707707
/// assert_eq!(ret.value, 4);
708708
/// }
709-
/// # struct MyMachineInfo;
710-
/// # impl rustsbi::MachineInfo for MyMachineInfo {
709+
/// # struct MyEnvInfo;
710+
/// # impl rustsbi::EnvInfo for MyEnvInfo {
711711
/// # fn mvendorid(&self) -> usize { unimplemented!() }
712712
/// # fn marchid(&self) -> usize { unimplemented!() }
713713
/// # fn mimpid(&self) -> usize { unimplemented!() }
@@ -720,8 +720,9 @@ pub extern crate sbi_spec as spec;
720720
/// SBI implementation ID for MySBI: 4
721721
/// ```
722722
///
723-
/// The SBI call returns the number 4 as SBI call result. By looking up the RISC-V SBI Specification,
724-
/// we acknowledge that RustSBI have the implementation ID of 4. You have successfully made your first
723+
/// The SBI call returns the number 4 as SBI call result. By looking up
724+
/// [the RISC-V SBI Specification](https://github.com/riscv-non-isa/riscv-sbi-doc/blob/cf86bda6f57afb8e0e7011b61504d4e8664b9b1d/src/ext-base.adoc#sbi-implementation-ids),
725+
/// we can know that RustSBI have the implementation ID of 4. You have successfully made your first
725726
/// SBI call from a derived `RustSBI` implementation!
726727
///
727728
/// If we learn further from the RISC-V privileged software architecture, we may know more about how
@@ -757,17 +758,17 @@ pub extern crate sbi_spec as spec;
757758
/// | `nacl` | [`Nacl`](trait.Nacl.html) | Nested Acceleration extension |
758759
/// | `sta` | [`Sta`](trait.Sta.html) | Steal Time Accounting extension |
759760
///
760-
/// The `MachineInfo` parameter is used by RISC-V SBI Base extension which is always supported on all
761-
/// RISC-V SBI implementations. RustSBI provides Base extension with additional `MachineInfo` by default.
761+
/// The `EnvInfo` parameter is used by RISC-V SBI Base extension which is always supported on all
762+
/// RISC-V SBI implementations. RustSBI provides Base extension with additional `EnvInfo` by default.
762763
///
763764
/// | Field names | RustSBI trait | Description |
764765
/// |:------------|:----------|:--------------|
765-
/// | `info` or `machine_info` | [`MachineInfo`](trait.MachineInfo.html) | Machine information used by Base extension |
766+
/// | `info` or `env_info` | [`EnvInfo`](trait.EnvInfo.html) | Machine environment information used by Base extension |
766767
///
767768
/// Or, if `#[cfg(feature = "machine")]` is enabled, RustSBI derive macro does not require additional
768-
/// machine information but reads them by RISC-V CSR operation when we don't have any `MachineInfo`
769+
/// machine environment information but reads them by RISC-V CSR operation when we don't have any `EnvInfo`s
769770
/// in the structure. This feature would only work if RustSBI runs directly on machine mode hardware.
770-
/// If we are targeting other environments (virtualization etc.) we should provide `MachineInfo` instead
771+
/// If we are targeting other environments (virtualization etc.) we should provide `EnvInfo` instead
771772
/// of using the machine feature.
772773
///
773774
/// # Examples
@@ -779,11 +780,11 @@ pub extern crate sbi_spec as spec;
779780
/// #[derive(RustSBI)]
780781
/// struct MySBI {
781782
/// fence: MyFence,
782-
/// info: MyMachineInfo,
783+
/// info: MyEnvInfo,
783784
/// }
784785
///
785786
/// // we assume that `MyFence` implements `rustsbi::Fence`
786-
/// // and `MyMachineInfo` implements `rustsbi::MachineInfo`.
787+
/// // and `MyEnvInfo` implements `rustsbi::EnvInfo`.
787788
/// # use rustsbi::{RustSBI, HartMask};
788789
/// # use sbi_spec::binary::SbiRet;
789790
/// # struct MyFence;
@@ -792,8 +793,8 @@ pub extern crate sbi_spec as spec;
792793
/// # fn remote_sfence_vma(&self, _: HartMask, _: usize, _: usize) -> SbiRet { unimplemented!() }
793794
/// # fn remote_sfence_vma_asid(&self, _: HartMask, _: usize, _: usize, _: usize) -> SbiRet { unimplemented!() }
794795
/// # }
795-
/// # struct MyMachineInfo;
796-
/// # impl rustsbi::MachineInfo for MyMachineInfo {
796+
/// # struct MyEnvInfo;
797+
/// # impl rustsbi::EnvInfo for MyEnvInfo {
797798
/// # fn mvendorid(&self) -> usize { 1 }
798799
/// # fn marchid(&self) -> usize { 2 }
799800
/// # fn mimpid(&self) -> usize { 3 }
@@ -817,7 +818,7 @@ pub use rfence::Rfence as Fence;
817818
pub use sta::Sta;
818819
pub use susp::Susp;
819820
pub use timer::Timer;
820-
pub use traits::{MachineInfo, RustSBI};
821+
pub use traits::{EnvInfo, RustSBI};
821822

822823
// Macro internal functions and structures
823824

@@ -826,7 +827,7 @@ pub use traits::{MachineInfo, RustSBI};
826827
pub use traits::_rustsbi_base_bare;
827828
#[doc(hidden)]
828829
pub use traits::{
829-
_StandardExtensionProbe, _rustsbi_base_machine_info, _rustsbi_console, _rustsbi_cppc,
830+
_StandardExtensionProbe, _rustsbi_base_env_info, _rustsbi_console, _rustsbi_cppc,
830831
_rustsbi_fence, _rustsbi_hsm, _rustsbi_ipi, _rustsbi_nacl, _rustsbi_pmu, _rustsbi_reset,
831832
_rustsbi_sta, _rustsbi_susp, _rustsbi_timer,
832833
};

src/traits.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ pub trait RustSBI {
99
fn handle_ecall(&self, extension: usize, function: usize, param: [usize; 6]) -> SbiRet;
1010
}
1111

12-
/// Machine information for SBI environment.
12+
/// Machine environment information for an SBI environment.
1313
///
1414
/// This trait is useful to build an SBI environment when RustSBI is not run directly on RISC-V machine mode.
15-
pub trait MachineInfo {
15+
pub trait EnvInfo {
1616
/// Vendor ID for the supervisor environment.
1717
///
1818
/// Provides JEDEC manufacturer ID of the provider of the core.
@@ -74,7 +74,7 @@ pub fn _rustsbi_base_bare(
7474

7575
#[doc(hidden)]
7676
#[inline(always)]
77-
pub fn _rustsbi_base_machine_info<T: MachineInfo>(
77+
pub fn _rustsbi_base_env_info<T: EnvInfo>(
7878
param: [usize; 6],
7979
function: usize,
8080
machine_info: &T,

tests/build-full.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct FullyImplemented {
1919
sta: DummySta,
2020
susp: DummySusp,
2121
timer: DummyTimer,
22-
info: DummyMachineInfo,
22+
info: DummyEnvInfo,
2323
}
2424

2525
#[derive(RustSBI)]
@@ -35,7 +35,7 @@ struct AlternateName {
3535
sta: DummySta,
3636
susp: DummySusp,
3737
time: DummyTimer,
38-
info: DummyMachineInfo,
38+
info: DummyEnvInfo,
3939
}
4040

4141
struct DummyConsole;
@@ -197,9 +197,9 @@ impl rustsbi::Timer for DummyTimer {
197197
}
198198
}
199199

200-
struct DummyMachineInfo;
200+
struct DummyEnvInfo;
201201

202-
impl rustsbi::MachineInfo for DummyMachineInfo {
202+
impl rustsbi::EnvInfo for DummyEnvInfo {
203203
fn mvendorid(&self) -> usize {
204204
unimplemented!()
205205
}
@@ -227,7 +227,7 @@ fn rustsbi_impl_id() {
227227
sta: DummySta,
228228
susp: DummySusp,
229229
timer: DummyTimer,
230-
info: DummyMachineInfo,
230+
info: DummyEnvInfo,
231231
};
232232
assert_eq!(sbi.handle_ecall(0x10, 0x1, [0; 6]).value, 4);
233233
let sbi = AlternateName {
@@ -242,7 +242,7 @@ fn rustsbi_impl_id() {
242242
sta: DummySta,
243243
susp: DummySusp,
244244
time: DummyTimer,
245-
info: DummyMachineInfo,
245+
info: DummyEnvInfo,
246246
};
247247
assert_eq!(sbi.handle_ecall(0x10, 0x1, [0; 6]).value, 4);
248248
}

0 commit comments

Comments
 (0)