Skip to contentSkip to conversation

eepro100: Fix alignment requirement for statistical counters

PATCH Applied Stefan Weil 4 participants 4 messages Nov 23, 2011 – Nov 28, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eepro100: Fix alignment requirement for statistical counters

According to Intel's Open Source Software Developer Manual, the dump counters address must be Dword aligned.

The new code enforces this alignment, so s->statsaddr may now be used with stw_le_pci_dma() and stl_le_pci_dma().

---
 hw/eepro100.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
hw/eepro100.c +9 -1
index 7d59e71..29ec5b4 100644
@@ -976,7 +976,15 @@ static void eepro100_cu_command(EEPRO100State * s, uint8_t val)
     case CU_STATSADDR:
         /* Load dump counters address. */
         s->statsaddr = e100_read_reg4(s, SCBPointer);
-        TRACE(OTHER, logout("val=0x%02x (status address)\n", val));
+        TRACE(OTHER, logout("val=0x%02x (dump counters address)\n", val));
+        if (s->statsaddr & 3) {
+            /* Memory must be Dword aligned. */
+            logout("unaligned dump counters address\n");
+            /* Handling of misaligned addresses is undefined.
+             * Here we align the address by ignoring the lower bits. */
+            /* TODO: Test unaligned dump counter address on real hardware. */
+            s->statsaddr &= ~3;
+        }
         break;
     case CU_SHOWSTATS:
         /* Dump statistical counters. */
Signature · 1 line
1.7.2.5
#1 lore raw
Quoted 7 lines · Stefan Weil

According to Intel's Open Source Software Developer Manual, the dump counters address must be Dword aligned.

The new code enforces this alignment, so s->statsaddr may now be used with stw_le_pci_dma() and stl_le_pci_dma().

Anthiny, coul you apply pls?

Quoted 27 lines
---
 hw/eepro100.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
hw/eepro100.c +9 -1
index 7d59e71..29ec5b4 100644
@@ -976,7 +976,15 @@ static void eepro100_cu_command(EEPRO100State * s, uint8_t val)
     case CU_STATSADDR:
         /* Load dump counters address. */
         s->statsaddr = e100_read_reg4(s, SCBPointer);
-        TRACE(OTHER, logout("val=0x%02x (status address)\n", val));
+        TRACE(OTHER, logout("val=0x%02x (dump counters address)\n", val));
+        if (s->statsaddr & 3) {
+            /* Memory must be Dword aligned. */
+            logout("unaligned dump counters address\n");
+            /* Handling of misaligned addresses is undefined.
+             * Here we align the address by ignoring the lower bits. */
+            /* TODO: Test unaligned dump counter address on real hardware. */
+            s->statsaddr &= ~3;
+        }
         break;
     case CU_SHOWSTATS:
         /* Dump statistical counters. */
Signature · 1 line
1.7.2.5
#2 lore raw
Quoted 10 lines · Michael S. Tsirkin
Quoted 7 lines · Stefan Weil

According to Intel's Open Source Software Developer Manual, the dump counters address must be Dword aligned.

The new code enforces this alignment, so s->statsaddr may now be used with stw_le_pci_dma() and stl_le_pci_dma().

Anthiny, coul you apply pls?

Yup.

Regards,

Anthony Liguori

Quoted 30 lines
Quoted 28 lines
---
  hw/eepro100.c |   10 +++++++++-
  1 files changed, 9 insertions(+), 1 deletions(-)
hw/eepro100.c +9 -2
index 7d59e71..29ec5b4 100644
@@ -976,7 +976,15 @@ static void eepro100_cu_command(EEPRO100State * s, uint8_t val)
      case CU_STATSADDR:
          /* Load dump counters address. */
          s->statsaddr = e100_read_reg4(s, SCBPointer);
-        TRACE(OTHER, logout("val=0x%02x (status address)\n", val));
+        TRACE(OTHER, logout("val=0x%02x (dump counters address)\n", val));
+        if (s->statsaddr&  3) {
+            /* Memory must be Dword aligned. */
+            logout("unaligned dump counters address\n");
+            /* Handling of misaligned addresses is undefined.
+             * Here we align the address by ignoring the lower bits. */
+            /* TODO: Test unaligned dump counter address on real hardware. */
+            s->statsaddr&= ~3;
+        }
          break;
      case CU_SHOWSTATS:
          /* Dump statistical counters. */
--

1.7.2.5

#3 lore raw
In reply to Stefan Weil
Quoted 7 lines · Stefan Weil

According to Intel's Open Source Software Developer Manual, the dump counters address must be Dword aligned.

The new code enforces this alignment, so s->statsaddr may now be used with stw_le_pci_dma() and stl_le_pci_dma().

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 25 lines
---
  hw/eepro100.c |   10 +++++++++-
  1 files changed, 9 insertions(+), 1 deletions(-)
hw/eepro100.c +9 -1
index 7d59e71..29ec5b4 100644
@@ -976,7 +976,15 @@ static void eepro100_cu_command(EEPRO100State * s, uint8_t val)
      case CU_STATSADDR:
          /* Load dump counters address. */
          s->statsaddr = e100_read_reg4(s, SCBPointer);
-        TRACE(OTHER, logout("val=0x%02x (status address)\n", val));
+        TRACE(OTHER, logout("val=0x%02x (dump counters address)\n", val));
+        if (s->statsaddr&  3) {
+            /* Memory must be Dword aligned. */
+            logout("unaligned dump counters address\n");
+            /* Handling of misaligned addresses is undefined.
+             * Here we align the address by ignoring the lower bits. */
+            /* TODO: Test unaligned dump counter address on real hardware. */
+            s->statsaddr&= ~3;
+        }
          break;
      case CU_SHOWSTATS:
          /* Dump statistical counters. */