dm: identical mapping of pass-thru dev PIO bar

For pass-thru dev PIO bar,keep identical mapping

Tracked-On: #6508

Signed-off-by: Fei Li <fei1.li@intel.com>
This commit is contained in:
Fei Li 2021-08-31 16:32:26 +08:00 committed by wenlingz
parent a075129534
commit cf345269d9
3 changed files with 85 additions and 54 deletions

View File

@ -131,11 +131,6 @@ int create_mmio_rsvd_rgn(uint64_t start,
{ {
int i; int i;
if(bar_type == PCIBAR_IO){
pr_err("fail to create PCIBAR_IO bar_type\n");
return -1;
}
for(i = 0; i < REGION_NUMS; i++){ for(i = 0; i < REGION_NUMS; i++){
if(reserved_bar_regions[i].vdev == NULL){ if(reserved_bar_regions[i].vdev == NULL){
reserved_bar_regions[i].start = start; reserved_bar_regions[i].start = start;
@ -574,13 +569,7 @@ pci_emul_alloc_resource(uint64_t *baseptr, uint64_t limit, uint64_t size,
size = PAGE_SIZE; size = PAGE_SIZE;
base = roundup2(*baseptr, size); base = roundup2(*baseptr, size);
/* TODO:Currently, we only reserve gvt mmio regions, adjust_bar_region(&base, size, bar_type);
* so ignore PCIBAR_IO when adjust_bar_region.
* If other devices also use reserved bar regions later,
* need remove pcibar_type != PCIBAR_IO condition
*/
if(bar_type != PCIBAR_IO)
adjust_bar_region(&base, size, bar_type);
if (base + size <= limit) { if (base + size <= limit) {
*addr = base; *addr = base;
@ -1381,8 +1370,8 @@ init_pci(struct vmctx *ctx)
struct businfo *bi; struct businfo *bi;
struct slotinfo *si; struct slotinfo *si;
struct funcinfo *fi; struct funcinfo *fi;
int bus, slot, func, i; int bus, slot, func, i,j;
int success_cnt = 0; int success_cnt[2] = {0}; /* 0 for passthru and 1 for others */
int error; int error;
uint64_t bus0_memlimit; uint64_t bus0_memlimit;
@ -1404,25 +1393,34 @@ init_pci(struct vmctx *ctx)
bi->membase32 = pci_emul_membase32; bi->membase32 = pci_emul_membase32;
bi->membase64 = pci_emul_membase64; bi->membase64 = pci_emul_membase64;
for (slot = 0; slot < MAXSLOTS; slot++) { for (j = 0; j < 2; j++) {
si = &bi->slotinfo[slot]; for (slot = 0; slot < MAXSLOTS; slot++) {
for (func = 0; func < MAXFUNCS; func++) { si = &bi->slotinfo[slot];
fi = &si->si_funcs[func]; for (func = 0; func < MAXFUNCS; func++) {
if (fi->fi_name == NULL) fi = &si->si_funcs[func];
continue; if (fi->fi_name == NULL)
ops = pci_emul_finddev(fi->fi_name); continue;
if (!ops) { ops = pci_emul_finddev(fi->fi_name);
pr_warn("No driver for device [%s]\n", fi->fi_name); if (!ops) {
continue; pr_warn("No driver for device [%s]\n", fi->fi_name);
continue;
}
if ((j == 0) && strcmp(ops->class_name, "passthru")) {
pr_warn("init passthru first to reserve PIO BAR\n");
continue;
} else if ((j == 1) && !strcmp(ops->class_name, "passthru")) {
continue;
}
pr_notice("pci init %s\r\n", fi->fi_name);
error = pci_emul_init(ctx, ops, bus, slot, func, fi);
if (error) {
pr_err("pci %s init failed\n", fi->fi_name);
goto pci_emul_init_fail;
}
success_cnt[j]++;
} }
pr_notice("pci init %s\r\n", fi->fi_name);
error = pci_emul_init(ctx, ops, bus, slot,
func, fi);
if (error) {
pr_err("pci %s init failed\n", fi->fi_name);
goto pci_emul_init_fail;
}
success_cnt++;
} }
} }
@ -1463,6 +1461,24 @@ init_pci(struct vmctx *ctx)
} }
bi->memlimit32 = bus0_memlimit; bi->memlimit32 = bus0_memlimit;
for (i = 0; i < REGION_NUMS; i++) {
if(reserved_bar_regions[i].vdev &&
reserved_bar_regions[i].bar_type == PCIBAR_IO) {
if (reserved_bar_regions[i].start < bi->iobase)
bi->iobase = reserved_bar_regions[i].start;
break;
}
}
for (i = REGION_NUMS - 1; i >= 0; i--) {
if(reserved_bar_regions[i].vdev &&
reserved_bar_regions[i].bar_type == PCIBAR_IO) {
if (reserved_bar_regions[i].end + 1 > bi->iolimit)
bi->iolimit = reserved_bar_regions[i].end + 1;
break;
}
}
error = check_gsi_sharing_violation(); error = check_gsi_sharing_violation();
if (error < 0) if (error < 0)
goto pci_emul_init_fail; goto pci_emul_init_fail;
@ -1543,25 +1559,35 @@ init_pci(struct vmctx *ctx)
return 0; return 0;
pci_emul_init_fail: pci_emul_init_fail:
for (bus = 0; bus < MAXBUSES && success_cnt > 0; bus++) { for (j = 0; j < 2; j++) {
bi = pci_businfo[bus]; for (bus = 0; bus < MAXBUSES && success_cnt[j] > 0; bus++) {
if (bi == NULL) bi = pci_businfo[bus];
continue; if (bi == NULL)
for (slot = 0; slot < MAXSLOTS && success_cnt > 0; slot++) { continue;
si = &bi->slotinfo[slot]; for (slot = 0; slot < MAXSLOTS && success_cnt[j] > 0; slot++) {
for (func = 0; func < MAXFUNCS; func++) { si = &bi->slotinfo[slot];
fi = &si->si_funcs[func]; for (func = 0; func < MAXFUNCS; func++) {
if (fi->fi_name == NULL) fi = &si->si_funcs[func];
continue; if (fi->fi_name == NULL)
if (success_cnt-- <= 0) continue;
break; if (success_cnt[j]-- <= 0)
ops = pci_emul_finddev(fi->fi_name); break;
if (!ops) { ops = pci_emul_finddev(fi->fi_name);
pr_warn("No driver for device [%s]\n", fi->fi_name); if (!ops) {
continue; pr_warn("No driver for device [%s]\n", fi->fi_name);
continue;
}
if ((j == 0) && strcmp(ops->class_name, "passthru")) {
pr_warn("init passthru first to reserve PIO BAR\n");
continue;
} else if ((j == 1) && !strcmp(ops->class_name, "passthru")) {
continue;
}
pci_emul_deinit(ctx, ops, bus, slot,
func, fi);
} }
pci_emul_deinit(ctx, ops, bus, slot,
func, fi);
} }
} }
} }

View File

@ -243,7 +243,12 @@ cfginitbar(struct vmctx *ctx, struct passthru_dev *ptdev)
if (size == 0) if (size == 0)
continue; continue;
/* Allocate the BAR in the guest I/O or MMIO space */ if (bartype == PCIBAR_IO)
error = create_mmio_rsvd_rgn(base, base + size - 1, i, PCIBAR_IO, dev);
if (error)
return -1;
/* Allocate the BAR in the guest MMIO space */
error = pci_emul_alloc_pbar(dev, i, base, bartype, size); error = pci_emul_alloc_pbar(dev, i, base, bartype, size);
if (error) if (error)
return -1; return -1;

View File

@ -51,10 +51,10 @@
#define SOFTWARE_SRAM_MAX_SIZE 0x00800000UL #define SOFTWARE_SRAM_MAX_SIZE 0x00800000UL
#define SOFTWARE_SRAM_BASE_GPA (PCI_EMUL_MEMBASE32 - SOFTWARE_SRAM_MAX_SIZE) #define SOFTWARE_SRAM_BASE_GPA (PCI_EMUL_MEMBASE32 - SOFTWARE_SRAM_MAX_SIZE)
/* Currently,only gvt need reserved bar regions, /*
* so just hardcode REGION_NUMS=5 here * GVT BARs + PTDEV IO BARs
*/ */
#define REGION_NUMS 5 #define REGION_NUMS 32
struct vmctx; struct vmctx;
struct pci_vdev; struct pci_vdev;