Skip to content

Commit ceb197c

Browse files
Junming Liuwenlingz
authored andcommitted
dm:keep pci bar property unchanged when updating pci bar address
When update pci bar addr, DM may change the bar property by func pci_cfgrw. PCI spec chapter 'Base Addresses' shows bits 0~3 are readonly of memeory space BAR, so this change won't happen. This patch ensures pci bar property unchanged when update pci bar addr. Tracked-On: #4282 Signed-off-by: Junming Liu <junming.liu@intel.com> Reviewed-by: Zhao Yakui <yakui.zhao@intel.com> Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
1 parent b59e5a8 commit ceb197c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

devicemodel/hw/pci/core.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,6 +2236,7 @@ pci_cfgrw(struct vmctx *ctx, int vcpu, int in, int bus, int slot, int func,
22362236
int idx, needcfg;
22372237
uint64_t addr, bar, mask;
22382238
bool decode, ignore_reg_unreg = false;
2239+
uint8_t mmio_bar_prop;
22392240

22402241
bi = pci_businfo[bus];
22412242
if (bi != NULL) {
@@ -2342,6 +2343,11 @@ pci_cfgrw(struct vmctx *ctx, int vcpu, int in, int bus, int slot, int func,
23422343
}
23432344
}
23442345

2346+
/* save the bar property for MMIO pci bar. */
2347+
mmio_bar_prop = pci_get_cfgdata32(dev, PCIR_BAR(idx)) &
2348+
(PCIM_BAR_SPACE | PCIM_BAR_MEM_TYPE |
2349+
PCIM_BAR_MEM_PREFETCH);
2350+
23452351
switch (dev->bar[idx].type) {
23462352
case PCIBAR_NONE:
23472353
dev->bar[idx].addr = bar = 0;
@@ -2361,7 +2367,8 @@ pci_cfgrw(struct vmctx *ctx, int vcpu, int in, int bus, int slot, int func,
23612367
break;
23622368
case PCIBAR_MEM32:
23632369
addr = bar = *eax & mask;
2364-
bar |= PCIM_BAR_MEM_SPACE | PCIM_BAR_MEM_32;
2370+
/* Restore the readonly fields for mmio bar */
2371+
bar |= mmio_bar_prop;
23652372
if (addr != dev->bar[idx].addr) {
23662373
update_bar_address(ctx, dev, addr, idx,
23672374
PCIBAR_MEM32,
@@ -2370,8 +2377,8 @@ pci_cfgrw(struct vmctx *ctx, int vcpu, int in, int bus, int slot, int func,
23702377
break;
23712378
case PCIBAR_MEM64:
23722379
addr = bar = *eax & mask;
2373-
bar |= PCIM_BAR_MEM_SPACE | PCIM_BAR_MEM_64 |
2374-
PCIM_BAR_MEM_PREFETCH;
2380+
/* Restore the readonly fields for mmio bar */
2381+
bar |= mmio_bar_prop;
23752382
if (addr != (uint32_t)dev->bar[idx].addr) {
23762383
update_bar_address(ctx, dev, addr, idx,
23772384
PCIBAR_MEM64,

0 commit comments

Comments
 (0)