Revisão | 6f506c90c3e1814a4a7df5be8d08782c06226820 (tree) |
---|---|
Hora | 2022-01-18 20:56:31 |
Autor | Daniel Henrique Barboza <danielhb413@gmai...> |
Commiter | Cédric Le Goater |
ppc/pnv: reduce stack->stack_no usage
'stack->stack_no' represents the order that a stack appears in its PEC.
Its primary use is in XSCOM address space calculation in
pnv_phb4_xscom_realize() when calculating the memory region offset.
This attribute is redundant with phb->phb_id, which is calculated via
pnv_phb4_pec_get_phb_id() using stack->stack_no information. It'll also
be awkward to assign it when dealing with PECs and PHBs only in a future
patch.
A new pnv_phb4_get_phb_stack_no() helper is introduced to eliminate most
of the stack->stack_no uses we have. The only use left after this patch
is during pnv_pec_stk_default_phb_realize() when calculating phb_id,
which will also handled in the next patches.
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Message-Id: <20220114180719.52117-3-danielhb413@gmail.com>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
@@ -868,6 +868,28 @@ static uint64_t pnv_pec_stk_nest_xscom_read(void *opaque, hwaddr addr, | ||
868 | 868 | return phb->nest_regs[reg]; |
869 | 869 | } |
870 | 870 | |
871 | +/* | |
872 | + * Return the 'stack_no' of a PHB4. 'stack_no' is the order | |
873 | + * the PHB4 occupies in the PEC. This is the reverse of what | |
874 | + * pnv_phb4_pec_get_phb_id() does. | |
875 | + * | |
876 | + * E.g. a phb with phb_id = 4 and pec->index = 1 (PEC1) will | |
877 | + * be the second phb (stack_no = 1) of the PEC. | |
878 | + */ | |
879 | +static int pnv_phb4_get_phb_stack_no(PnvPHB4 *phb) | |
880 | +{ | |
881 | + PnvPhb4PecState *pec = phb->pec; | |
882 | + PnvPhb4PecClass *pecc = PNV_PHB4_PEC_GET_CLASS(pec); | |
883 | + int index = pec->index; | |
884 | + int stack_no = phb->phb_id; | |
885 | + | |
886 | + while (index--) { | |
887 | + stack_no -= pecc->num_stacks[index]; | |
888 | + } | |
889 | + | |
890 | + return stack_no; | |
891 | +} | |
892 | + | |
871 | 893 | static void pnv_phb4_update_regions(PnvPHB4 *phb) |
872 | 894 | { |
873 | 895 | /* Unmap first always */ |
@@ -894,10 +916,10 @@ static void pnv_phb4_update_regions(PnvPHB4 *phb) | ||
894 | 916 | |
895 | 917 | static void pnv_pec_stk_update_map(PnvPHB4 *phb) |
896 | 918 | { |
897 | - PnvPhb4PecStack *stack = phb->stack; | |
898 | 919 | PnvPhb4PecState *pec = phb->pec; |
899 | 920 | MemoryRegion *sysmem = get_system_memory(); |
900 | 921 | uint64_t bar_en = phb->nest_regs[PEC_NEST_STK_BAR_EN]; |
922 | + int stack_no = pnv_phb4_get_phb_stack_no(phb); | |
901 | 923 | uint64_t bar, mask, size; |
902 | 924 | char name[64]; |
903 | 925 |
@@ -937,7 +959,7 @@ static void pnv_pec_stk_update_map(PnvPHB4 *phb) | ||
937 | 959 | mask = phb->nest_regs[PEC_NEST_STK_MMIO_BAR0_MASK]; |
938 | 960 | size = ((~mask) >> 8) + 1; |
939 | 961 | snprintf(name, sizeof(name), "pec-%d.%d-phb-%d-mmio0", |
940 | - pec->chip_id, pec->index, stack->stack_no); | |
962 | + pec->chip_id, pec->index, stack_no); | |
941 | 963 | memory_region_init(&phb->mmbar0, OBJECT(phb), name, size); |
942 | 964 | memory_region_add_subregion(sysmem, bar, &phb->mmbar0); |
943 | 965 | phb->mmio0_base = bar; |
@@ -949,7 +971,7 @@ static void pnv_pec_stk_update_map(PnvPHB4 *phb) | ||
949 | 971 | mask = phb->nest_regs[PEC_NEST_STK_MMIO_BAR1_MASK]; |
950 | 972 | size = ((~mask) >> 8) + 1; |
951 | 973 | snprintf(name, sizeof(name), "pec-%d.%d-phb-%d-mmio1", |
952 | - pec->chip_id, pec->index, stack->stack_no); | |
974 | + pec->chip_id, pec->index, stack_no); | |
953 | 975 | memory_region_init(&phb->mmbar1, OBJECT(phb), name, size); |
954 | 976 | memory_region_add_subregion(sysmem, bar, &phb->mmbar1); |
955 | 977 | phb->mmio1_base = bar; |
@@ -960,7 +982,7 @@ static void pnv_pec_stk_update_map(PnvPHB4 *phb) | ||
960 | 982 | bar = phb->nest_regs[PEC_NEST_STK_PHB_REGS_BAR] >> 8; |
961 | 983 | size = PNV_PHB4_NUM_REGS << 3; |
962 | 984 | snprintf(name, sizeof(name), "pec-%d.%d-phb-%d", |
963 | - pec->chip_id, pec->index, stack->stack_no); | |
985 | + pec->chip_id, pec->index, stack_no); | |
964 | 986 | memory_region_init(&phb->phbbar, OBJECT(phb), name, size); |
965 | 987 | memory_region_add_subregion(sysmem, bar, &phb->phbbar); |
966 | 988 | } |
@@ -969,7 +991,7 @@ static void pnv_pec_stk_update_map(PnvPHB4 *phb) | ||
969 | 991 | bar = phb->nest_regs[PEC_NEST_STK_INT_BAR] >> 8; |
970 | 992 | size = PNV_PHB4_MAX_INTs << 16; |
971 | 993 | snprintf(name, sizeof(name), "pec-%d.%d-phb-%d-int", |
972 | - phb->pec->chip_id, phb->pec->index, stack->stack_no); | |
994 | + phb->pec->chip_id, phb->pec->index, stack_no); | |
973 | 995 | memory_region_init(&phb->intbar, OBJECT(phb), name, size); |
974 | 996 | memory_region_add_subregion(sysmem, bar, &phb->intbar); |
975 | 997 | } |
@@ -1458,9 +1480,9 @@ static AddressSpace *pnv_phb4_dma_iommu(PCIBus *bus, void *opaque, int devfn) | ||
1458 | 1480 | |
1459 | 1481 | static void pnv_phb4_xscom_realize(PnvPHB4 *phb) |
1460 | 1482 | { |
1461 | - PnvPhb4PecStack *stack = phb->stack; | |
1462 | 1483 | PnvPhb4PecState *pec = phb->pec; |
1463 | 1484 | PnvPhb4PecClass *pecc = PNV_PHB4_PEC_GET_CLASS(pec); |
1485 | + int stack_no = pnv_phb4_get_phb_stack_no(phb); | |
1464 | 1486 | uint32_t pec_nest_base; |
1465 | 1487 | uint32_t pec_pci_base; |
1466 | 1488 | char name[64]; |
@@ -1469,20 +1491,20 @@ static void pnv_phb4_xscom_realize(PnvPHB4 *phb) | ||
1469 | 1491 | |
1470 | 1492 | /* Initialize the XSCOM regions for the stack registers */ |
1471 | 1493 | snprintf(name, sizeof(name), "xscom-pec-%d.%d-nest-phb-%d", |
1472 | - pec->chip_id, pec->index, stack->stack_no); | |
1494 | + pec->chip_id, pec->index, stack_no); | |
1473 | 1495 | pnv_xscom_region_init(&phb->nest_regs_mr, OBJECT(phb), |
1474 | 1496 | &pnv_pec_stk_nest_xscom_ops, phb, name, |
1475 | 1497 | PHB4_PEC_NEST_STK_REGS_COUNT); |
1476 | 1498 | |
1477 | 1499 | snprintf(name, sizeof(name), "xscom-pec-%d.%d-pci-phb-%d", |
1478 | - pec->chip_id, pec->index, stack->stack_no); | |
1500 | + pec->chip_id, pec->index, stack_no); | |
1479 | 1501 | pnv_xscom_region_init(&phb->pci_regs_mr, OBJECT(phb), |
1480 | 1502 | &pnv_pec_stk_pci_xscom_ops, phb, name, |
1481 | 1503 | PHB4_PEC_PCI_STK_REGS_COUNT); |
1482 | 1504 | |
1483 | 1505 | /* PHB pass-through */ |
1484 | 1506 | snprintf(name, sizeof(name), "xscom-pec-%d.%d-pci-phb-%d", |
1485 | - pec->chip_id, pec->index, stack->stack_no); | |
1507 | + pec->chip_id, pec->index, stack_no); | |
1486 | 1508 | pnv_xscom_region_init(&phb->phb_regs_mr, OBJECT(phb), |
1487 | 1509 | &pnv_phb4_xscom_ops, phb, name, 0x40); |
1488 | 1510 |
@@ -1491,14 +1513,14 @@ static void pnv_phb4_xscom_realize(PnvPHB4 *phb) | ||
1491 | 1513 | |
1492 | 1514 | /* Populate the XSCOM address space. */ |
1493 | 1515 | pnv_xscom_add_subregion(pec->chip, |
1494 | - pec_nest_base + 0x40 * (stack->stack_no + 1), | |
1516 | + pec_nest_base + 0x40 * (stack_no + 1), | |
1495 | 1517 | &phb->nest_regs_mr); |
1496 | 1518 | pnv_xscom_add_subregion(pec->chip, |
1497 | - pec_pci_base + 0x40 * (stack->stack_no + 1), | |
1519 | + pec_pci_base + 0x40 * (stack_no + 1), | |
1498 | 1520 | &phb->pci_regs_mr); |
1499 | 1521 | pnv_xscom_add_subregion(pec->chip, |
1500 | 1522 | pec_pci_base + PNV9_XSCOM_PEC_PCI_STK0 + |
1501 | - 0x40 * stack->stack_no, | |
1523 | + 0x40 * stack_no, | |
1502 | 1524 | &phb->phb_regs_mr); |
1503 | 1525 | } |
1504 | 1526 |