MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / write

Method write

devices/src/tpm.rs:388–539  ·  view source on GitHub ↗
(&mut self, _base: u64, offset: u64, data: &[u8])

Source from the content-addressed store, hash-verified

386 }
387
388 fn write(&mut self, _base: u64, offset: u64, data: &[u8]) -> Option<Arc<Barrier>> {
389 debug!(
390 "MMIO Write: offset {:#X} len {:?} input data {:02X?}",
391 offset,
392 data.len(),
393 data
394 );
395 let mut offset: u32 = offset as u32;
396 if offset < CRB_DATA_BUFFER {
397 offset &= 0xff;
398 }
399 let locality = locality_from_addr(offset) as u32;
400 let write_len = data.len();
401
402 if offset >= CRB_DATA_BUFFER
403 && (offset + write_len as u32) < (CRB_DATA_BUFFER + self.data_buff.len() as u32)
404 {
405 let start: usize = (offset as usize) - (CRB_DATA_BUFFER as usize);
406 if start == 0 {
407 // If filling data_buff at index 0, reset length to 0
408 self.data_buff_len = 0;
409 self.data_buff.fill(0);
410 }
411 let end: usize = start + data.len();
412 self.data_buff[start..end].clone_from_slice(data);
413 self.data_buff_len += data.len();
414 } else {
415 // Ctrl Commands that take more than 4 bytes as input are not yet supported
416 // CTRL_RSP_ADDR usually gets 8 byte write request. Last 4 bytes are zeros.
417 if write_len > 4 && offset != CRB_CTRL_RSP_ADDR {
418 error!(
419 "Invalid tpm write: offset {:#X}, data length {}",
420 offset,
421 data.len()
422 );
423 return None;
424 }
425
426 let mut input: [u8; 4] = [0; 4];
427 input.copy_from_slice(&data[0..4]);
428 let v = u32::from_le_bytes(input);
429
430 match offset {
431 CRB_CTRL_CMD_SIZE_REG => {
432 self.regs[CRB_CTRL_CMD_SIZE_REG as usize] = v;
433 }
434 CRB_CTRL_CMD_LADDR => {
435 self.regs[CRB_CTRL_CMD_LADDR as usize] = v;
436 }
437 CRB_CTRL_CMD_HADDR => {
438 self.regs[CRB_CTRL_CMD_HADDR as usize] = v;
439 }
440 CRB_CTRL_RSP_SIZE => {
441 self.regs[CRB_CTRL_RSP_SIZE as usize] = v;
442 }
443 CRB_CTRL_RSP_ADDR => {
444 self.regs[CRB_CTRL_RSP_ADDR as usize] = v;
445 }

Callers

nothing calls this directly

Calls 7

locality_from_addrFunction · 0.85
set_reg_fieldFunction · 0.85
cancel_cmdMethod · 0.80
get_active_localityMethod · 0.80
deliver_requestMethod · 0.80
request_completedMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected