Skip to contentSkip to conversation

pci: improve w1c mask handling

PATCH In review Michael S. Tsirkin 2 participants 3 messages Oct 27, 2010 – Oct 28, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci: improve w1c mask handling

- save/restore must not check w1c bits
since they are in fact guest controlled
- clear w1c bits on reset

Note: for express there are different kinds of reset, some leave part of config space alone. We will likely need a sticky bit mask to implement this.

---

Isaku, does the below make sense?

 hw/pci.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
hw/pci.c +4 -2
index e50de14..1a14a0e 100644
@@ -141,7 +141,8 @@ static void pci_device_reset(PCIDevice *dev)
     pci_update_irq_status(dev);
     /* Clear all writeable bits */
     pci_word_test_and_clear_mask(dev->config + PCI_COMMAND,
-                                 pci_get_word(dev->wmask + PCI_COMMAND));
+                                 pci_get_word(dev->wmask + PCI_COMMAND) |
+                                 pci_get_word(dev->w1cmask + PCI_COMMAND));
     dev->config[PCI_CACHE_LINE_SIZE] = 0x0;
     dev->config[PCI_INTERRUPT_LINE] = 0x0;
     for (r = 0; r < PCI_NUM_REGIONS; ++r) {
@@ -293,7 +294,8 @@ static int get_pci_config_device(QEMUFile *f, void *pv, size_t size)
 
     qemu_get_buffer(f, config, size);
     for (i = 0; i < size; ++i) {
-        if ((config[i] ^ s->config[i]) & s->cmask[i] & ~s->wmask[i]) {
+        if ((config[i] ^ s->config[i]) &
+            s->cmask[i] & ~s->wmask[i] & ~s->w1cmask) {
             qemu_free(config);
             return -EINVAL;
         }
Signature · 1 line
1.7.3.2.91.g446ac
#1 lore raw
Quoted 31 lines · Michael S. Tsirkin

- save/restore must not check w1c bits
since they are in fact guest controlled
- clear w1c bits on reset

Note: for express there are different kinds of reset, some leave part of config space alone. We will likely need a sticky bit mask to implement this.

---

Isaku, does the below make sense?

 hw/pci.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
hw/pci.c +2 -1
index e50de14..1a14a0e 100644
@@ -141,7 +141,8 @@ static void pci_device_reset(PCIDevice *dev)
     pci_update_irq_status(dev);
     /* Clear all writeable bits */
     pci_word_test_and_clear_mask(dev->config + PCI_COMMAND,
-                                 pci_get_word(dev->wmask + PCI_COMMAND));
+                                 pci_get_word(dev->wmask + PCI_COMMAND) |
+                                 pci_get_word(dev->w1cmask + PCI_COMMAND));
     dev->config[PCI_CACHE_LINE_SIZE] = 0x0;
     dev->config[PCI_INTERRUPT_LINE] = 0x0;
     for (r = 0; r < PCI_NUM_REGIONS; ++r) {

hw/pci.c static int get_pci_config_device(QEMUFile *f, void *pv, size_t size) · line 298

Quoted 6 lines
hw/pci.c +2 -1
@@ -293,7 +294,8 @@ static int get_pci_config_device(QEMUFile *f, void *pv, size_t size)
 
     qemu_get_buffer(f, config, size);
     for (i = 0; i < size; ++i) {
-        if ((config[i] ^ s->config[i]) & s->cmask[i] & ~s->wmask[i]) {
+        if ((config[i] ^ s->config[i]) &
+            s->cmask[i] & ~s->wmask[i] & ~s->w1cmask) {

[i] is needed for w1cmask.
~s->w1cmask[i]

           ^^^
Quoted 6 lines
hw/pci.c +0 -0
             qemu_free(config);
             return -EINVAL;
         }
Signature · 1 line
1.7.3.2.91.g446ac
Signature · 1 line
yamahata
#2 lore raw
Quoted 41 lines · Isaku Yamahata
Quoted 31 lines · Michael S. Tsirkin

- save/restore must not check w1c bits
since they are in fact guest controlled
- clear w1c bits on reset

Note: for express there are different kinds of reset, some leave part of config space alone. We will likely need a sticky bit mask to implement this.

---

Isaku, does the below make sense?

 hw/pci.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
hw/pci.c +2 -1
index e50de14..1a14a0e 100644
@@ -141,7 +141,8 @@ static void pci_device_reset(PCIDevice *dev)
     pci_update_irq_status(dev);
     /* Clear all writeable bits */
     pci_word_test_and_clear_mask(dev->config + PCI_COMMAND,
-                                 pci_get_word(dev->wmask + PCI_COMMAND));
+                                 pci_get_word(dev->wmask + PCI_COMMAND) |
+                                 pci_get_word(dev->w1cmask + PCI_COMMAND));
     dev->config[PCI_CACHE_LINE_SIZE] = 0x0;
     dev->config[PCI_INTERRUPT_LINE] = 0x0;
     for (r = 0; r < PCI_NUM_REGIONS; ++r) {

hw/pci.c static int get_pci_config_device(QEMUFile *f, void *pv, size_t size) · line 298

Quoted 6 lines
hw/pci.c +2 -1
@@ -293,7 +294,8 @@ static int get_pci_config_device(QEMUFile *f, void *pv, size_t size)
 
     qemu_get_buffer(f, config, size);
     for (i = 0; i < size; ++i) {
-        if ((config[i] ^ s->config[i]) & s->cmask[i] & ~s->wmask[i]) {
+        if ((config[i] ^ s->config[i]) &
+            s->cmask[i] & ~s->wmask[i] & ~s->w1cmask) {

[i] is needed for w1cmask.
~s->w1cmask[i]

Quoted 1 line
           ^^^

Yes, I sent out a borken patch but it's correct on my branch.

Quoted 11 lines
Quoted 8 lines
hw/pci.c +0 -0
             qemu_free(config);
             return -EINVAL;
         }
Signature · 1 line
1.7.3.2.91.g446ac
Signature · 1 line
yamahata