Message ID | 20220310155101.294568-4-fbarrat@linux.ibm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Fix user-created PHB devices on POWER10 | expand |
On 3/10/22 16:51, Frederic Barrat wrote: > The PEC array used when looking for the PEC hosting a PHB is stored in > the chip structure. The array is at a different offset in Pnv9Chip and > Pnv10Chip. The lookup function was therefore not working properly on > POWER10. > This patch fixes it by introducing a class method to get the correct > PEC pointer based on the chip object and PEC index. > > Fixes: 623575e16cd5 ("ppc/pnv: Add model for POWER10 PHB5 PCIe Host bridge") > Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com> > --- > hw/pci-host/pnv_phb4.c | 5 ++--- > hw/ppc/pnv.c | 14 ++++++++++++++ > include/hw/ppc/pnv.h | 1 + > 3 files changed, 17 insertions(+), 3 deletions(-) Reviewed-by: Cédric Le Goater <clg@kaod.org> Queued for 7.0. Thanks, C. > diff --git a/hw/pci-host/pnv_phb4.c b/hw/pci-host/pnv_phb4.c > index d1a911f988..4732633833 100644 > --- a/hw/pci-host/pnv_phb4.c > +++ b/hw/pci-host/pnv_phb4.c > @@ -1548,7 +1548,6 @@ static void pnv_phb4_instance_init(Object *obj) > static PnvPhb4PecState *pnv_phb4_get_pec(PnvChip *chip, PnvPHB4 *phb, > Error **errp) > { > - Pnv9Chip *chip9 = PNV9_CHIP(chip); > int chip_id = phb->chip_id; > int index = phb->phb_id; > int i, j; > @@ -1556,9 +1555,9 @@ static PnvPhb4PecState *pnv_phb4_get_pec(PnvChip *chip, PnvPHB4 *phb, > for (i = 0; i < chip->num_pecs; i++) { > /* > * For each PEC, check the amount of phbs it supports > - * and see if the given phb4 index matches an index. > + * and see if the given phb index matches an index. > */ > - PnvPhb4PecState *pec = &chip9->pecs[i]; > + PnvPhb4PecState *pec = PNV_CHIP_GET_CLASS(chip)->get_pec(chip, i); > > for (j = 0; j < pec->num_phbs; j++) { > if (index == pnv_phb4_pec_get_phb_id(pec, j)) { > diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c > index df58403a3a..3a676cd570 100644 > --- a/hw/ppc/pnv.c > +++ b/hw/ppc/pnv.c > @@ -1561,6 +1561,12 @@ static uint32_t pnv_chip_power9_xscom_pcba(PnvChip *chip, uint64_t addr) > return addr >> 3; > } > > +static PnvPhb4PecState *pnv_chip_power9_get_pec(PnvChip *chip, uint32_t index) > +{ > + Pnv9Chip *chip9 = PNV9_CHIP(chip); > + return &chip9->pecs[index]; > +} > + > static void pnv_chip_power9_class_init(ObjectClass *klass, void *data) > { > DeviceClass *dc = DEVICE_CLASS(klass); > @@ -1580,6 +1586,7 @@ static void pnv_chip_power9_class_init(ObjectClass *klass, void *data) > k->xscom_pcba = pnv_chip_power9_xscom_pcba; > dc->desc = "PowerNV Chip POWER9"; > k->num_pecs = PNV9_CHIP_MAX_PEC; > + k->get_pec = pnv_chip_power9_get_pec; > > device_class_set_parent_realize(dc, pnv_chip_power9_realize, > &k->parent_realize); > @@ -1769,6 +1776,12 @@ static uint32_t pnv_chip_power10_xscom_pcba(PnvChip *chip, uint64_t addr) > return addr >> 3; > } > > +static PnvPhb4PecState *pnv_chip_power10_get_pec(PnvChip *chip, uint32_t index) > +{ > + Pnv10Chip *chip10 = PNV10_CHIP(chip); > + return &chip10->pecs[index]; > +} > + > static void pnv_chip_power10_class_init(ObjectClass *klass, void *data) > { > DeviceClass *dc = DEVICE_CLASS(klass); > @@ -1788,6 +1801,7 @@ static void pnv_chip_power10_class_init(ObjectClass *klass, void *data) > k->xscom_pcba = pnv_chip_power10_xscom_pcba; > dc->desc = "PowerNV Chip POWER10"; > k->num_pecs = PNV10_CHIP_MAX_PEC; > + k->get_pec = pnv_chip_power10_get_pec; > > device_class_set_parent_realize(dc, pnv_chip_power10_realize, > &k->parent_realize); > diff --git a/include/hw/ppc/pnv.h b/include/hw/ppc/pnv.h > index 1e34ddd502..282f76ba08 100644 > --- a/include/hw/ppc/pnv.h > +++ b/include/hw/ppc/pnv.h > @@ -163,6 +163,7 @@ struct PnvChipClass { > void (*pic_print_info)(PnvChip *chip, Monitor *mon); > uint64_t (*xscom_core_base)(PnvChip *chip, uint32_t core_id); > uint32_t (*xscom_pcba)(PnvChip *chip, uint64_t addr); > + PnvPhb4PecState *(*get_pec)(PnvChip *chip, uint32_t index); > }; > > #define PNV_CHIP_TYPE_SUFFIX "-" TYPE_PNV_CHIP
diff --git a/hw/pci-host/pnv_phb4.c b/hw/pci-host/pnv_phb4.c index d1a911f988..4732633833 100644 --- a/hw/pci-host/pnv_phb4.c +++ b/hw/pci-host/pnv_phb4.c @@ -1548,7 +1548,6 @@ static void pnv_phb4_instance_init(Object *obj) static PnvPhb4PecState *pnv_phb4_get_pec(PnvChip *chip, PnvPHB4 *phb, Error **errp) { - Pnv9Chip *chip9 = PNV9_CHIP(chip); int chip_id = phb->chip_id; int index = phb->phb_id; int i, j; @@ -1556,9 +1555,9 @@ static PnvPhb4PecState *pnv_phb4_get_pec(PnvChip *chip, PnvPHB4 *phb, for (i = 0; i < chip->num_pecs; i++) { /* * For each PEC, check the amount of phbs it supports - * and see if the given phb4 index matches an index. + * and see if the given phb index matches an index. */ - PnvPhb4PecState *pec = &chip9->pecs[i]; + PnvPhb4PecState *pec = PNV_CHIP_GET_CLASS(chip)->get_pec(chip, i); for (j = 0; j < pec->num_phbs; j++) { if (index == pnv_phb4_pec_get_phb_id(pec, j)) { diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index df58403a3a..3a676cd570 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -1561,6 +1561,12 @@ static uint32_t pnv_chip_power9_xscom_pcba(PnvChip *chip, uint64_t addr) return addr >> 3; } +static PnvPhb4PecState *pnv_chip_power9_get_pec(PnvChip *chip, uint32_t index) +{ + Pnv9Chip *chip9 = PNV9_CHIP(chip); + return &chip9->pecs[index]; +} + static void pnv_chip_power9_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); @@ -1580,6 +1586,7 @@ static void pnv_chip_power9_class_init(ObjectClass *klass, void *data) k->xscom_pcba = pnv_chip_power9_xscom_pcba; dc->desc = "PowerNV Chip POWER9"; k->num_pecs = PNV9_CHIP_MAX_PEC; + k->get_pec = pnv_chip_power9_get_pec; device_class_set_parent_realize(dc, pnv_chip_power9_realize, &k->parent_realize); @@ -1769,6 +1776,12 @@ static uint32_t pnv_chip_power10_xscom_pcba(PnvChip *chip, uint64_t addr) return addr >> 3; } +static PnvPhb4PecState *pnv_chip_power10_get_pec(PnvChip *chip, uint32_t index) +{ + Pnv10Chip *chip10 = PNV10_CHIP(chip); + return &chip10->pecs[index]; +} + static void pnv_chip_power10_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); @@ -1788,6 +1801,7 @@ static void pnv_chip_power10_class_init(ObjectClass *klass, void *data) k->xscom_pcba = pnv_chip_power10_xscom_pcba; dc->desc = "PowerNV Chip POWER10"; k->num_pecs = PNV10_CHIP_MAX_PEC; + k->get_pec = pnv_chip_power10_get_pec; device_class_set_parent_realize(dc, pnv_chip_power10_realize, &k->parent_realize); diff --git a/include/hw/ppc/pnv.h b/include/hw/ppc/pnv.h index 1e34ddd502..282f76ba08 100644 --- a/include/hw/ppc/pnv.h +++ b/include/hw/ppc/pnv.h @@ -163,6 +163,7 @@ struct PnvChipClass { void (*pic_print_info)(PnvChip *chip, Monitor *mon); uint64_t (*xscom_core_base)(PnvChip *chip, uint32_t core_id); uint32_t (*xscom_pcba)(PnvChip *chip, uint64_t addr); + PnvPhb4PecState *(*get_pec)(PnvChip *chip, uint32_t index); }; #define PNV_CHIP_TYPE_SUFFIX "-" TYPE_PNV_CHIP
The PEC array used when looking for the PEC hosting a PHB is stored in the chip structure. The array is at a different offset in Pnv9Chip and Pnv10Chip. The lookup function was therefore not working properly on POWER10. This patch fixes it by introducing a class method to get the correct PEC pointer based on the chip object and PEC index. Fixes: 623575e16cd5 ("ppc/pnv: Add model for POWER10 PHB5 PCIe Host bridge") Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com> --- hw/pci-host/pnv_phb4.c | 5 ++--- hw/ppc/pnv.c | 14 ++++++++++++++ include/hw/ppc/pnv.h | 1 + 3 files changed, 17 insertions(+), 3 deletions(-)