Skip to content

Commit d208988

Browse files
lifeixwenlingz
authored andcommitted
hv: pci: minor fix of coding style about pci_read_cap
There's no need to check which capability we care at the very beginning. We could do it later step by step. Tracked-On: #3475 Signed-off-by: Li Fei1 <fei1.li@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent cdf9d6b commit d208988

File tree

1 file changed

+32
-36
lines changed

1 file changed

+32
-36
lines changed

hypervisor/hw/pci.c

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -414,57 +414,53 @@ static inline uint32_t pci_pdev_get_nr_bars(uint8_t hdr_type)
414414
*/
415415
static void pci_read_cap(struct pci_pdev *pdev)
416416
{
417-
uint8_t ptr, cap;
417+
uint8_t pos, cap;
418418
uint32_t msgctrl;
419-
uint32_t len, offset, idx;
419+
uint32_t len, idx;
420420
uint32_t table_info;
421421
uint32_t pcie_devcap, val;
422422

423-
ptr = (uint8_t)pci_pdev_read_cfg(pdev->bdf, PCIR_CAP_PTR, 1U);
423+
pos = (uint8_t)pci_pdev_read_cfg(pdev->bdf, PCIR_CAP_PTR, 1U);
424424

425-
while ((ptr != 0U) && (ptr != 0xFFU)) {
426-
cap = (uint8_t)pci_pdev_read_cfg(pdev->bdf, ptr + PCICAP_ID, 1U);
425+
while ((pos != 0U) && (pos != 0xFFU)) {
426+
cap = (uint8_t)pci_pdev_read_cfg(pdev->bdf, pos + PCICAP_ID, 1U);
427427

428-
/* Ignore all other Capability IDs for now */
429-
if ((cap == PCIY_MSI) || (cap == PCIY_MSIX) || (cap == PCIY_PCIE) || (cap == PCIY_AF)) {
430-
offset = ptr;
431-
if (cap == PCIY_MSI) {
432-
pdev->msi_capoff = offset;
433-
} else if (cap == PCIY_MSIX) {
434-
pdev->msix.capoff = offset;
435-
pdev->msix.caplen = MSIX_CAPLEN;
436-
len = pdev->msix.caplen;
428+
if (cap == PCIY_MSI) {
429+
pdev->msi_capoff = pos;
430+
} else if (cap == PCIY_MSIX) {
431+
pdev->msix.capoff = pos;
432+
pdev->msix.caplen = MSIX_CAPLEN;
433+
len = pdev->msix.caplen;
437434

438-
msgctrl = pci_pdev_read_cfg(pdev->bdf, pdev->msix.capoff + PCIR_MSIX_CTRL, 2U);
435+
msgctrl = pci_pdev_read_cfg(pdev->bdf, pdev->msix.capoff + PCIR_MSIX_CTRL, 2U);
439436

440-
/* Read Table Offset and Table BIR */
441-
table_info = pci_pdev_read_cfg(pdev->bdf, pdev->msix.capoff + PCIR_MSIX_TABLE, 4U);
437+
/* Read Table Offset and Table BIR */
438+
table_info = pci_pdev_read_cfg(pdev->bdf, pdev->msix.capoff + PCIR_MSIX_TABLE, 4U);
442439

443-
pdev->msix.table_bar = (uint8_t)(table_info & PCIM_MSIX_BIR_MASK);
440+
pdev->msix.table_bar = (uint8_t)(table_info & PCIM_MSIX_BIR_MASK);
444441

445-
pdev->msix.table_offset = table_info & ~PCIM_MSIX_BIR_MASK;
446-
pdev->msix.table_count = (msgctrl & PCIM_MSIXCTRL_TABLE_SIZE) + 1U;
442+
pdev->msix.table_offset = table_info & ~PCIM_MSIX_BIR_MASK;
443+
pdev->msix.table_count = (msgctrl & PCIM_MSIXCTRL_TABLE_SIZE) + 1U;
447444

448-
ASSERT(pdev->msix.table_count <= CONFIG_MAX_MSIX_TABLE_NUM);
445+
ASSERT(pdev->msix.table_count <= CONFIG_MAX_MSIX_TABLE_NUM);
449446

450-
/* Copy MSIX capability struct into buffer */
451-
for (idx = 0U; idx < len; idx++) {
452-
pdev->msix.cap[idx] = (uint8_t)pci_pdev_read_cfg(pdev->bdf, offset + idx, 1U);
453-
}
454-
} else if (cap == PCIY_PCIE) {
455-
/* PCI Express Capability */
456-
pdev->pcie_capoff = offset;
457-
pcie_devcap = pci_pdev_read_cfg(pdev->bdf, offset + PCIR_PCIE_DEVCAP, 4U);
458-
pdev->has_flr = ((pcie_devcap & PCIM_PCIE_FLRCAP) != 0U) ? true : false;
459-
} else {
460-
/* Conventional PCI Advanced Features Capability */
461-
pdev->af_capoff = offset;
462-
val = pci_pdev_read_cfg(pdev->bdf, offset, 4U);
463-
pdev->has_af_flr = ((val & PCIM_AF_FLR_CAP) != 0U) ? true : false;
447+
/* Copy MSIX capability struct into buffer */
448+
for (idx = 0U; idx < len; idx++) {
449+
pdev->msix.cap[idx] = (uint8_t)pci_pdev_read_cfg(pdev->bdf, (uint32_t)pos + idx, 1U);
464450
}
451+
} else if (cap == PCIY_PCIE) {
452+
pdev->pcie_capoff = pos;
453+
pcie_devcap = pci_pdev_read_cfg(pdev->bdf, pos + PCIR_PCIE_DEVCAP, 4U);
454+
pdev->has_flr = ((pcie_devcap & PCIM_PCIE_FLRCAP) != 0U) ? true : false;
455+
} else if (cap == PCIY_AF) {
456+
pdev->af_capoff = pos;
457+
val = pci_pdev_read_cfg(pdev->bdf, pos, 4U);
458+
pdev->has_af_flr = ((val & PCIM_AF_FLR_CAP) != 0U) ? true : false;
459+
} else {
460+
/* Ignore all other Capability IDs for now */
465461
}
466462

467-
ptr = (uint8_t)pci_pdev_read_cfg(pdev->bdf, ptr + PCICAP_NEXTPTR, 1U);
463+
pos = (uint8_t)pci_pdev_read_cfg(pdev->bdf, pos + PCICAP_NEXTPTR, 1U);
468464
}
469465
}
470466

0 commit comments

Comments
 (0)