diff --git a/hypervisor/dm/vpci/vdev.c b/hypervisor/dm/vpci/vdev.c index 9333884be..6214fdb00 100644 --- a/hypervisor/dm/vpci/vdev.c +++ b/hypervisor/dm/vpci/vdev.c @@ -30,6 +30,9 @@ #include #include "vpci_priv.h" +/** + * @pre vdev != NULL + */ uint32_t pci_vdev_read_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes) { uint32_t val; @@ -49,6 +52,9 @@ uint32_t pci_vdev_read_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_ return val; } +/** + * @pre vdev != NULL + */ void pci_vdev_write_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val) { switch (bytes) { diff --git a/hypervisor/dm/vpci/vmsi.c b/hypervisor/dm/vpci/vmsi.c index eb95bf743..12f7e5bff 100644 --- a/hypervisor/dm/vpci/vmsi.c +++ b/hypervisor/dm/vpci/vmsi.c @@ -57,6 +57,12 @@ static inline bool msicap_access(const struct pci_vdev *vdev, uint32_t offset) return ret; } +/** + * @pre vdev != NULL + * @pre vdev->vpci != NULL + * @pre vdev->vpci->vm != NULL + * @pre vdev->pdev != NULL + */ static int32_t vmsi_remap(const struct pci_vdev *vdev, bool enable) { struct ptirq_msi_info info; @@ -172,6 +178,11 @@ int32_t vmsi_write_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, u return ret; } +/** + * @pre vdev != NULL + * @pre vdev->vpci != NULL + * @pre vdev->vpci->vm != NULL + */ void deinit_vmsi(const struct pci_vdev *vdev) { if (has_msi_cap(vdev)) { @@ -194,6 +205,10 @@ static void buf_write32(uint8_t buf[], uint32_t val) buf[3] = (uint8_t)((val >> 24U) & 0xFFU); } +/** + * @pre vdev != NULL + * @pre vdev->pdev != NULL + */ void init_vmsi(struct pci_vdev *vdev) { struct pci_pdev *pdev = vdev->pdev; diff --git a/hypervisor/dm/vpci/vmsix.c b/hypervisor/dm/vpci/vmsix.c index 58f8e6cce..3ee345bb0 100644 --- a/hypervisor/dm/vpci/vmsix.c +++ b/hypervisor/dm/vpci/vmsix.c @@ -53,11 +53,20 @@ static inline bool msixcap_access(const struct pci_vdev *vdev, uint32_t offset) return ret; } +/** + * @pre vdev != NULL + */ static inline bool msixtable_access(const struct pci_vdev *vdev, uint32_t offset) { return in_range(offset, vdev->msix.table_offset, vdev->msix.table_count * MSIX_TABLE_ENTRY_SIZE); } +/** + * @pre vdev != NULL + * @pre vdev->vpci != NULL + * @pre vdev->vpci->vm != NULL + * @pre vdev->pdev != NULL + */ static int32_t vmsix_remap_entry(const struct pci_vdev *vdev, uint32_t index, bool enable) { struct msix_table_entry *pentry; @@ -92,6 +101,10 @@ static int32_t vmsix_remap_entry(const struct pci_vdev *vdev, uint32_t index, bo return ret; } +/** + * @pre vdev != NULL + * @pre vdev->pdev != NULL + */ static inline void enable_disable_msix(const struct pci_vdev *vdev, bool enable) { uint32_t msgctrl; @@ -105,7 +118,11 @@ static inline void enable_disable_msix(const struct pci_vdev *vdev, bool enable) pci_pdev_write_cfg(vdev->pdev->bdf, vdev->msix.capoff + PCIR_MSIX_CTRL, 2U, msgctrl); } -/* Do MSI-X remap for all MSI-X table entries in the target device */ +/** + * Do MSI-X remap for all MSI-X table entries in the target device + * @pre vdev != NULL + * @pre vdev->pdev != NULL + */ static int32_t vmsix_remap(const struct pci_vdev *vdev, bool enable) { uint32_t index; @@ -132,7 +149,11 @@ static int32_t vmsix_remap(const struct pci_vdev *vdev, bool enable) return ret; } -/* Do MSI-X remap for one MSI-X table entry only */ +/** + * Do MSI-X remap for one MSI-X table entry only + * @pre vdev != NULL + * @pre vdev->pdev != NULL + */ static int32_t vmsix_remap_one_entry(const struct pci_vdev *vdev, uint32_t index, bool enable) { uint32_t msgctrl; @@ -336,6 +357,7 @@ int32_t vmsix_table_mmio_access_handler(struct io_request *io_req, void *handler /** * @pre vdev != NULL + * @pre vdev->pdev != NULL */ void init_vmsix(struct pci_vdev *vdev) { diff --git a/hypervisor/dm/vpci/vpci.c b/hypervisor/dm/vpci/vpci.c index 229fd48fe..6273ca12d 100644 --- a/hypervisor/dm/vpci/vpci.c +++ b/hypervisor/dm/vpci/vpci.c @@ -51,7 +51,8 @@ static void pci_cfg_clear_cache(struct pci_addr_info *pi) } /** - * @pre vm != NULL && vcpu != NULL + * @pre vm != NULL + * @pre vcpu != NULL */ static bool pci_cfgaddr_io_read(struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint16_t addr, size_t bytes) { @@ -147,7 +148,7 @@ static bool pci_cfgdata_io_read(struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint /** * @pre vm != NULL * @pre vm->vm_id < CONFIG_MAX_VM_NUM - * @pre (get_vm_config(vm->vm_id)->type == PRE_LAUNCHED_VM) || (get_vm_config(vm->vm_id)->type == SOS_VM) + * @pre (get_vm_config(vm->vm_id)->load_order == PRE_LAUNCHED_VM) || (get_vm_config(vm->vm_id)->load_order == SOS_VM) */ static bool pci_cfgdata_io_write(struct acrn_vm *vm, uint16_t addr, size_t bytes, uint32_t val) { diff --git a/hypervisor/dm/vpci/vpci_priv.h b/hypervisor/dm/vpci/vpci_priv.h index 7a0ce14cc..8ecfe394d 100644 --- a/hypervisor/dm/vpci/vpci_priv.h +++ b/hypervisor/dm/vpci/vpci_priv.h @@ -37,31 +37,49 @@ static inline bool in_range(uint32_t value, uint32_t lower, uint32_t len) return ((value >= lower) && (value < (lower + len))); } +/** + * @pre vdev != NULL + */ static inline uint8_t pci_vdev_read_cfg_u8(const struct pci_vdev *vdev, uint32_t offset) { return vdev->cfgdata.data_8[offset]; } +/** + * @pre vdev != NULL + */ static inline uint16_t pci_vdev_read_cfg_u16(const struct pci_vdev *vdev, uint32_t offset) { return vdev->cfgdata.data_16[offset >> 1U]; } +/** + * @pre vdev != NULL + */ static inline uint32_t pci_vdev_read_cfg_u32(const struct pci_vdev *vdev, uint32_t offset) { return vdev->cfgdata.data_32[offset >> 2U]; } +/** + * @pre vdev != NULL + */ static inline void pci_vdev_write_cfg_u8(struct pci_vdev *vdev, uint32_t offset, uint8_t val) { vdev->cfgdata.data_8[offset] = val; } +/** + * @pre vdev != NULL + */ static inline void pci_vdev_write_cfg_u16(struct pci_vdev *vdev, uint32_t offset, uint16_t val) { vdev->cfgdata.data_16[offset >> 1U] = val; } +/** + * @pre vdev != NULL + */ static inline void pci_vdev_write_cfg_u32(struct pci_vdev *vdev, uint32_t offset, uint32_t val) { vdev->cfgdata.data_32[offset >> 2U] = val;