-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stage0 HAL: shuffle code that reads/writes MSRs to the HAL.
This is mostly just copying code around as the original implementation was fairly generic to begin with. Bug: 350496083 Change-Id: Ia70d5f10db6aee1cca041482ae081bd0d601b2b8
- Loading branch information
Showing
5 changed files
with
89 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ mod mmio; | |
|
||
pub use cpuid::*; | ||
pub use mmio::*; | ||
pub use x86_64::registers::model_specific::Msr; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
|
||
mod cpuid; | ||
mod mmio; | ||
mod msr; | ||
|
||
pub use cpuid::*; | ||
pub use mmio::*; | ||
pub use msr::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// Copyright 2024 The Project Oak Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
use crate::sev::GHCB_WRAPPER; | ||
|
||
/// Read a MSR. | ||
/// | ||
/// ## Safety | ||
/// | ||
/// The caller must guarantee that the MSR is valid. | ||
pub unsafe fn read_msr(msr: &crate::hal::base::Msr, msr_id: u32) -> u64 { | ||
if let Some(ghcb) = GHCB_WRAPPER.get() { | ||
ghcb.lock().msr_read(msr_id).expect("couldn't read the MSR using the GHCB protocol") | ||
} else { | ||
msr.read() | ||
} | ||
} | ||
|
||
/// Write to a MSR. | ||
/// | ||
/// ## Safety | ||
/// | ||
/// The caller must guarantee that the MSR is valid. | ||
pub unsafe fn write_msr(msr: &mut crate::hal::base::Msr, msr_id: u32, val: u64) { | ||
if let Some(ghcb) = GHCB_WRAPPER.get() { | ||
ghcb.lock().msr_write(msr_id, val).expect("couldn't write the MSR using the GHCB protocol") | ||
} else { | ||
msr.write(val) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters