mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-03-20 07:58:55 +00:00
vmm: Add tpm device to mmio bus
Add tpm device to mmio bus if appropriate cmdline arguments were passed. Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
This commit is contained in:
parent
af261f231c
commit
09e79a5e9b
@ -172,6 +172,9 @@ pub enum DeviceManagerError {
|
||||
/// Cannot create virtio-vsock device
|
||||
CreateVirtioVsock(io::Error),
|
||||
|
||||
/// Cannot create tpm device
|
||||
CreateTpmDevice(anyhow::Error),
|
||||
|
||||
/// Failed to convert Path to &str for the vDPA device.
|
||||
CreateVdpaConvertPath,
|
||||
|
||||
@ -1187,6 +1190,11 @@ impl DeviceManager {
|
||||
console_resize_pipe,
|
||||
)?;
|
||||
|
||||
if let Some(tpm) = self.config.clone().lock().unwrap().tpm.as_ref() {
|
||||
let tpm_dev = self.add_tpm_device(tpm.socket.clone())?;
|
||||
self.bus_devices
|
||||
.push(Arc::clone(&tpm_dev) as Arc<Mutex<dyn BusDevice>>)
|
||||
}
|
||||
self.legacy_interrupt_manager = Some(legacy_interrupt_manager);
|
||||
|
||||
virtio_devices.append(&mut self.make_virtio_devices()?);
|
||||
@ -1986,6 +1994,29 @@ impl DeviceManager {
|
||||
Ok(Arc::new(Console { console_resizer }))
|
||||
}
|
||||
|
||||
fn add_tpm_device(
|
||||
&mut self,
|
||||
tpm_path: PathBuf,
|
||||
) -> DeviceManagerResult<Arc<Mutex<devices::tpm::Tpm>>> {
|
||||
// Create TPM Device
|
||||
let tpm = devices::tpm::Tpm::new(tpm_path.to_str().unwrap().to_string()).map_err(|e| {
|
||||
DeviceManagerError::CreateTpmDevice(anyhow!("Failed to create TPM Device : {:?}", e))
|
||||
})?;
|
||||
let tpm = Arc::new(Mutex::new(tpm));
|
||||
|
||||
// Add TPM Device to mmio
|
||||
self.address_manager
|
||||
.mmio_bus
|
||||
.insert(
|
||||
tpm.clone(),
|
||||
arch::layout::TPM_START.0,
|
||||
arch::layout::TPM_SIZE,
|
||||
)
|
||||
.map_err(DeviceManagerError::BusError)?;
|
||||
|
||||
Ok(tpm)
|
||||
}
|
||||
|
||||
fn make_virtio_devices(&mut self) -> DeviceManagerResult<Vec<MetaVirtioDevice>> {
|
||||
let mut devices: Vec<MetaVirtioDevice> = Vec::new();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user