fix invisibility of PCI Option ROM
PATCH 1/1 fix invisibility of PCI Option ROM
If 'lspci -v' command on Dom0 shows '[virtual]' as follows, the option ROM can't be read by the guest.
$ lspci -v -s 0:1
...
[virtual] Expansion ROM at fdb00000 [disabled] [size=256K]hw/pass-through.c +14 -0
@@ -1088,6 +1088,13 @@ static void pt_pci_write_config(PCIDevice *d, uint32_t address, uint32_t val,break ;case 4 : read_val =pci_read_long (pci_dev, address); + +/* use the address reported by OS but not by the device */ +if ((address ==PCI_ROM_ADDRESS ) && + (read_val &PCI_ROM_ADDRESS_MASK ) ==0 && + (pci_dev->rom_base_addr &PCI_ROM_ADDRESS_MASK ) !=0 ) + read_val = (pci_dev->rom_base_addr &PCI_ROM_ADDRESS_MASK ) | + (read_val & (~PCI_ROM_ADDRESS_MASK ));break ; }
@@ -1265,6 +1272,13 @@ static uint32_t pt_pci_read_config(PCIDevice *d, uint32_t address, int len)break ;case 4 : val =pci_read_long (pci_dev, address); + +/* use the address reported by OS but not by the device */ +if ((address ==PCI_ROM_ADDRESS ) && + (val &PCI_ROM_ADDRESS_MASK ) ==0 && + (pci_dev->rom_base_addr &PCI_ROM_ADDRESS_MASK ) !=0 ) + val = (pci_dev->rom_base_addr &PCI_ROM_ADDRESS_MASK ) | + (val & (~PCI_ROM_ADDRESS_MASK ));break ; }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Hi, Shimura-san,
It is better to write OS reporting value to device in "pt_bar_reg_init" function, I think.
The reasons are followings.
- "pt_pci_write_config" and "pt_pci_read_config" are generic function. It is not good to put register-specific code to them.
- We need to set rom base address to device, because we'd like device to respond to the access from guest software.
Thanks,
--
Yuji Shimada
Hi Shimada-san,
Thanks for your comment.
I agree it's not good to modify the generic function. Let me think for a while since I'm newbie in passthrough.
Thanks,
Kouya
Quoted 18 lines · Yuji Shimada
Hi, Shimura-san,
It is better to write OS reporting value to device in "
pt_bar_reg_init" function, I think.The reasons are followings.
- "
pt_pci_write_config" and "pt_pci_read_config" are generic function. It is not good to put register-specific code to them.- We need to set rom base address to device, because we'd like device to respond to the access from guest software.
Thanks,
--
Yuji Shimada
Quoted 4 lines
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
hw/pass-through.c +33 -1
@@ -93,6 +93,9 @@ static int pt_long_reg_read(struct pt_dev *ptdev,static int pt_bar_reg_read (struct pt_dev *ptdev,struct pt_reg_tbl *cfg_entry,uint32_t *value,uint32_t valid_mask); +static int pt_exp_rom_bar_reg_read (struct pt_dev *ptdev, +struct pt_reg_tbl *cfg_entry, +uint32_t *value,uint32_t valid_mask);static int pt_byte_reg_write (struct pt_dev *ptdev,struct pt_reg_tbl *cfg_entry,uint8_t *value,uint8_t dev_value,uint8_t valid_mask);
@@ -305,7 +308,7 @@ static struct pt_reg_info_tbl pt_emu_reg_header0_tbl[] = { .ro_mask = 0x000007FE, .emu_mask = 0xFFFFF800, .init = pt_bar_reg_init, - .u.dw.read = pt_long_reg_read, + .u.dw.read = pt_exp_rom_bar_reg_read, .u.dw.write = pt_exp_rom_bar_reg_write, }, {
@@ -2262,6 +2265,29 @@ static int pt_bar_reg_read(struct pt_dev *ptdev,return 0 ; } +/* read Exp ROM BAR */ +static int pt_exp_rom_bar_reg_read (struct pt_dev *ptdev, +struct pt_reg_tbl *cfg_entry, +uint32_t *value,uint32_t valid_mask) +{ +struct pt_reg_info_tbl *reg = cfg_entry->reg; +uint32_t valid_emu_mask =0 ; +uint32_t val = *value; + +/* use the address reported by OS but not by the device */ +if ((val &PCI_ROM_ADDRESS_MASK ) ==0 && + (ptdev->pci_dev->rom_base_addr &PCI_ROM_ADDRESS_MASK ) !=0 ) + val = (ptdev->pci_dev->rom_base_addr &PCI_ROM_ADDRESS_MASK ) | + (val & (~PCI_ROM_ADDRESS_MASK )); + +/* emulate long register */ + valid_emu_mask = reg->emu_mask & valid_mask; + *value = ((val & ~valid_emu_mask) | + (cfg_entry->data & valid_emu_mask)); + +return 0 ; +} +/* write byte size emulate register */ static int pt_byte_reg_write(struct pt_dev *ptdev, struct pt_reg_tbl *cfg_entry,
@@ -2510,6 +2536,12 @@ static int pt_exp_rom_bar_reg_write(struct pt_dev *ptdev,uint32_t bar_emu_mask =0 ;uint32_t bar_ro_mask =0 ; +/* use the address reported by OS but not by the device */ +if ((dev_value &PCI_ROM_ADDRESS_MASK ) ==0 && + (ptdev->pci_dev->rom_base_addr &PCI_ROM_ADDRESS_MASK ) !=0 ) + dev_value = (ptdev->pci_dev->rom_base_addr &PCI_ROM_ADDRESS_MASK ) | + (dev_value & (~PCI_ROM_ADDRESS_MASK )); + r = &d->io_regions[PCI_ROM_SLOT ]; r_size = r->size; base = &ptdev->bases[PCI_ROM_SLOT ];
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 fix invisibility of PCI Option ROM
In reply to Yuji ShimadaHi,
This is the revised patch with Shimada-san's suggestions.
If 'lspci -v' command on Dom0 shows '[virtual]' as follows, the option ROM can't be read by the guest.
$ lspci -v -s 0:1
...
[virtual] Expansion ROM at fdb00000 [disabled] [size=256K]Thanks,
Kouya
hw/pass-through.c +9 -0
@@ -1403,6 +1403,15 @@ static int pt_register_regions(struct pt_dev *assigned_device)/* Register expansion ROM address */ if ( pci_dev->rom_base_addr && pci_dev->rom_size ) { + +/* Re-set BAR reported by OS, otherwise ROM can't be read. */ + bar_data =pci_read_long (pci_dev,PCI_ROM_ADDRESS ); +if ( (bar_data &PCI_ROM_ADDRESS_MASK ) ==0 ) + { + bar_data |= (pci_dev->rom_base_addr &PCI_ROM_ADDRESS_MASK ); +pci_write_long (pci_dev,PCI_ROM_ADDRESS , bar_data); + } + assigned_device->bases[PCI_ROM_SLOT ].e_physbase = pci_dev->rom_base_addr; assigned_device->bases[PCI_ROM_SLOT].access.maddr =
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Hi Ian,
I hope his patch is applied into qemu.
With his patch, option ROM can be read by the guest.
Thanks,
--
Yuji Shimada
Quoted 16 lines · On Mon, 1 Dec 2008 16:59:13 +0900 Kouya Shimura <[email protected]> wrote:
Hi,
This is the revised patch with Shimada-san's suggestions.
If 'lspci -v' command on Dom0 shows '[virtual]' as follows, the option ROM can't be read by the guest.
$ lspci -v -s 0:1 ... [virtual] Expansion ROM at fdb00000 [disabled] [size=256K]Thanks,
KouyaSigned-off-by Kouya Shimura <[email protected]>