QEMU: Mask writes to RO bits in the status reg of PCI config space
PATCH 1/1 QEMU: Mask writes to RO bits in the status reg of PCI config space
The Status register in the PCI config space has some read-only bits. Any writes to those bits should be masked out.
Signed-off-by Amit Shah <[email protected]>
--- qemu/hw/pci.c | 11 +++++++++++ qemu/hw/pci.h | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 0 deletions(-)
qemu/hw/pci.c +11 -0
@@ -416,6 +416,7 @@ void pci_default_write_config(PCIDevice *d,case 0x0b :case 0x0e : case 0x10 ... 0x27: /* base */ + case 0x2c ... 0x2f: /* read-only subsystem ID & vendor ID */ case 0x30 ... 0x33: /* rom */case 0x3d : can_write =0 ;
@@ -437,6 +438,7 @@ void pci_default_write_config(PCIDevice *d,case 0x0a :case 0x0b :case 0x0e : + case 0x2c ... 0x2f: /* read-only subsystem ID & vendor ID */ case 0x38 ... 0x3b: /* rom */case 0x3d : can_write =0 ;
@@ -448,6 +450,15 @@ void pci_default_write_config(PCIDevice *d,break ; }if (can_write) { +/* Mask out writes to reserved bits in registers */ +switch (addr) { +case 0x06 : + val &= ~PCI_STATUS_RESERVED_MASK_LO ; +break ; +case 0x07 : + val &= ~PCI_STATUS_RESERVED_MASK_HI ; +break ; + } d->config[addr] = val; }if (++addr >0xff )
qemu/hw/pci.h +15 -0
@@ -46,6 +46,21 @@ typedef struct PCIIORegion {#define PCI_MIN_GNT 0x3e/* 8 bits */ #define PCI_MAX_LAT 0x3f/* 8 bits */ +/* Bits in the PCI Status Register (PCI 2.3 spec) */ +#define PCI_STATUS_RESERVED1 0x007 +#define PCI_STATUS_INT_STATUS 0x008 +#define PCI_STATUS_CAPABILITIES 0x010 +#define PCI_STATUS_66MHZ 0x020 +#define PCI_STATUS_RESERVED2 0x040 +#define PCI_STATUS_FAST_BACK 0x080 +#define PCI_STATUS_DEVSEL 0x600 + +#define PCI_STATUS_RESERVED_MASK_LO (PCI_STATUS_RESERVED1 | \ + PCI_STATUS_INT_STATUS | PCI_STATUS_CAPABILITIES | \ + PCI_STATUS_66MHZ | PCI_STATUS_RESERVED2 | PCI_STATUS_FAST_BACK) + +#define PCI_STATUS_RESERVED_MASK_HI (PCI_STATUS_DEVSEL >> 8) +struct PCIDevice {/* PCI config space */ uint8_t config[256 ];
Signature · 1 line
1.5.6.3
PATCH 1/1 QEMU: Mask writes to RO bits in the command reg of PCI config space
The Command register in the PCI config space has some read-only bits. Any writes to those bits should be masked out.
Signed-off-by Amit Shah <[email protected]>
--- qemu/hw/pci.c | 3 +++ qemu/hw/pci.h | 5 +++++ 2 files changed, 8 insertions(+), 0 deletions(-)
qemu/hw/pci.c +3 -0
@@ -452,6 +452,9 @@ void pci_default_write_config(PCIDevice *d,if (can_write) {/* Mask out writes to reserved bits in registers */ switch (addr) { +case 0x05 : + val &= ~PCI_COMMAND_RESERVED_MASK_HI ; +break ;case 0x06 : val &= ~PCI_STATUS_RESERVED_MASK_LO ;break ;
qemu/hw/pci.h +5 -0
@@ -61,6 +61,11 @@ typedef struct PCIIORegion {#define PCI_STATUS_RESERVED_MASK_HI (PCI_STATUS_DEVSEL >> 8) +/* Bits in the PCI Command Register (PCI 2.3 spec) */ +#define PCI_COMMAND_RESERVED 0xf800 + +#define PCI_COMMAND_RESERVED_MASK_HI (PCI_COMMAND_RESERVED >> 8) +struct PCIDevice {/* PCI config space */ uint8_t config[256 ];
Signature · 1 line
1.5.6.3
Aurelien Jarno
AppliedRe: [Qemu-devel] [PATCH] QEMU: Mask writes to RO bits in the command reg of PCI config space
Quoted 4 lines · Amit Shah
The Command register in the PCI config space has some read-only bits. Any writes to those bits should be masked out.
Signed-off-by Amit Shah <[email protected]>
Thanks applied.
Quoted 41 lines
--- qemu/hw/pci.c | 3 +++ qemu/hw/pci.h | 5 +++++ 2 files changed, 8 insertions(+), 0 deletions(-)qemu/hw/pci.c +3
-0@@ -452,6 +452,9 @@ void pci_default_write_config(PCIDevice *d,if (can_write) {/* Mask out writes to reserved bits in registers */ switch (addr) { +case 0x05 : + val &= ~PCI_COMMAND_RESERVED_MASK_HI ; +break ;case 0x06 : val &= ~PCI_STATUS_RESERVED_MASK_LO ;break ;qemu/hw/pci.h +5
-0@@ -61,6 +61,11 @@ typedef struct PCIIORegion {#define PCI_STATUS_RESERVED_MASK_HI (PCI_STATUS_DEVSEL >> 8) +/* Bits in the PCI Command Register (PCI 2.3 spec) */ +#define PCI_COMMAND_RESERVED 0xf800 + +#define PCI_COMMAND_RESERVED_MASK_HI (PCI_COMMAND_RESERVED >> 8) +struct PCIDevice {/* PCI config space */ uint8_t config[256 ];Signature · 1 line
1.5.6.3
Signature · 4 lines
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' [email protected] | [email protected] `- people.debian.org/~aurel32 | www.aurel32.net
Aurelien Jarno
AppliedQuoted 4 lines · Amit Shah
The Status register in the PCI config space has some read-only bits. Any writes to those bits should be masked out.
Signed-off-by Amit Shah <[email protected]>
Thanks applied.
Quoted 73 lines
--- qemu/hw/pci.c | 11 +++++++++++ qemu/hw/pci.h | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 0 deletions(-)qemu/hw/pci.c +11
-0@@ -416,6 +416,7 @@ void pci_default_write_config(PCIDevice *d,case 0x0b :case 0x0e : case 0x10 ... 0x27: /* base */ + case 0x2c ... 0x2f: /* read-only subsystem ID & vendor ID */ case 0x30 ... 0x33: /* rom */case 0x3d : can_write =0 ;@@ -437,6 +438,7 @@ void pci_default_write_config(PCIDevice *d,case 0x0a :case 0x0b :case 0x0e : + case 0x2c ... 0x2f: /* read-only subsystem ID & vendor ID */ case 0x38 ... 0x3b: /* rom */case 0x3d : can_write =0 ;@@ -448,6 +450,15 @@ void pci_default_write_config(PCIDevice *d,break ; }if (can_write) { +/* Mask out writes to reserved bits in registers */ +switch (addr) { +case 0x06 : + val &= ~PCI_STATUS_RESERVED_MASK_LO ; +break ; +case 0x07 : + val &= ~PCI_STATUS_RESERVED_MASK_HI ; +break ; + } d->config[addr] = val; }if (++addr >0xff )qemu/hw/pci.h +15
-0@@ -46,6 +46,21 @@ typedef struct PCIIORegion {#define PCI_MIN_GNT 0x3e/* 8 bits */ #define PCI_MAX_LAT 0x3f/* 8 bits */ +/* Bits in the PCI Status Register (PCI 2.3 spec) */ +#define PCI_STATUS_RESERVED1 0x007 +#define PCI_STATUS_INT_STATUS 0x008 +#define PCI_STATUS_CAPABILITIES 0x010 +#define PCI_STATUS_66MHZ 0x020 +#define PCI_STATUS_RESERVED2 0x040 +#define PCI_STATUS_FAST_BACK 0x080 +#define PCI_STATUS_DEVSEL 0x600 + +#define PCI_STATUS_RESERVED_MASK_LO (PCI_STATUS_RESERVED1 | \ + PCI_STATUS_INT_STATUS | PCI_STATUS_CAPABILITIES | \ + PCI_STATUS_66MHZ | PCI_STATUS_RESERVED2 | PCI_STATUS_FAST_BACK) + +#define PCI_STATUS_RESERVED_MASK_HI (PCI_STATUS_DEVSEL >> 8) +struct PCIDevice {/* PCI config space */ uint8_t config[256 ];Signature · 1 line
1.5.6.3
Signature · 4 lines
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' [email protected] | [email protected] `- people.debian.org/~aurel32 | www.aurel32.net