qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] first batch of hpet fixes
@ 2024-07-16  9:34 Paolo Bonzini
  2024-07-16  9:34 ` [PATCH 1/2] hpet: fix clamping of period Paolo Bonzini
  2024-07-16  9:34 ` [PATCH 2/2] hpet: fix HPET_TN_SETVAL for high 32-bits of the comparator Paolo Bonzini
  0 siblings, 2 replies; 3+ messages in thread
From: Paolo Bonzini @ 2024-07-16  9:34 UTC (permalink / raw)
  To: qemu-devel; +Cc: taisei1212

Extracted from the patch that TaiseiIto <taisei1212@outlook.jp> tested.
While not sufficient to fix their problems, this is a step in the
right direction.

Paolo Bonzini (2):
  hpet: fix clamping of period
  hpet: fix HPET_TN_SETVAL for high 32-bits of the comparator

 hw/timer/hpet.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

-- 
2.45.2



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] hpet: fix clamping of period
  2024-07-16  9:34 [PATCH 0/2] first batch of hpet fixes Paolo Bonzini
@ 2024-07-16  9:34 ` Paolo Bonzini
  2024-07-16  9:34 ` [PATCH 2/2] hpet: fix HPET_TN_SETVAL for high 32-bits of the comparator Paolo Bonzini
  1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2024-07-16  9:34 UTC (permalink / raw)
  To: qemu-devel; +Cc: taisei1212

When writing a new period, the clamping should use a maximum value
rather than a bit mask.  Also, when writing the high bits new_val
is shifted right by 32, so the maximum allowed period should also
be shifted right.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/timer/hpet.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c
index 01efe4885db..16be1278d09 100644
--- a/hw/timer/hpet.c
+++ b/hw/timer/hpet.c
@@ -548,7 +548,9 @@ static void hpet_ram_write(void *opaque, hwaddr addr,
                  * FIXME: Clamp period to reasonable min value?
                  * Clamp period to reasonable max value
                  */
-                new_val &= (timer->config & HPET_TN_32BIT ? ~0u : ~0ull) >> 1;
+                if (timer->config & HPET_TN_32_BIT) {
+                    new_val = MIN(new_val, ~0u >> 1);
+                }
                 timer->period =
                     (timer->period & 0xffffffff00000000ULL) | new_val;
             }
@@ -567,7 +569,7 @@ static void hpet_ram_write(void *opaque, hwaddr addr,
                  * FIXME: Clamp period to reasonable min value?
                  * Clamp period to reasonable max value
                  */
-                new_val &= (timer->config & HPET_TN_32BIT ? ~0u : ~0ull) >> 1;
+                new_val = MIN(new_val, ~0u >> 1);
                 timer->period =
                     (timer->period & 0xffffffffULL) | new_val << 32;
                 }
-- 
2.45.2



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] hpet: fix HPET_TN_SETVAL for high 32-bits of the comparator
  2024-07-16  9:34 [PATCH 0/2] first batch of hpet fixes Paolo Bonzini
  2024-07-16  9:34 ` [PATCH 1/2] hpet: fix clamping of period Paolo Bonzini
@ 2024-07-16  9:34 ` Paolo Bonzini
  1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2024-07-16  9:34 UTC (permalink / raw)
  To: qemu-devel; +Cc: taisei1212

Commit 3787324101b ("hpet: Fix emulation of HPET_TN_SETVAL (Jan Kiszka)",
2009-04-17) applied the fix only to the low 32-bits of the comparator, but
it should be done for the high bits as well.  Otherwise, the high 32-bits
of the comparator cannot be written and they remain fixed to 0xffffffff.

Co-developed-by: TaiseiIto <taisei1212@outlook.jp>
Signed-off-by: TaiseiIto <taisei1212@outlook.jp>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/timer/hpet.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c
index 16be1278d09..85fb2c07ae3 100644
--- a/hw/timer/hpet.c
+++ b/hw/timer/hpet.c
@@ -554,6 +554,10 @@ static void hpet_ram_write(void *opaque, hwaddr addr,
                 timer->period =
                     (timer->period & 0xffffffff00000000ULL) | new_val;
             }
+            /*
+             * FIXME: on a 64-bit write, HPET_TN_SETVAL should apply to the
+             * high bits part as well.
+             */
             timer->config &= ~HPET_TN_SETVAL;
             if (hpet_enabled(s)) {
                 hpet_set_timer(timer);
@@ -564,7 +568,8 @@ static void hpet_ram_write(void *opaque, hwaddr addr,
             if (!timer_is_periodic(timer)
                 || (timer->config & HPET_TN_SETVAL)) {
                 timer->cmp = (timer->cmp & 0xffffffffULL) | new_val << 32;
-            } else {
+            }
+            if (timer_is_periodic(timer)) {
                 /*
                  * FIXME: Clamp period to reasonable min value?
                  * Clamp period to reasonable max value
@@ -572,12 +577,12 @@ static void hpet_ram_write(void *opaque, hwaddr addr,
                 new_val = MIN(new_val, ~0u >> 1);
                 timer->period =
                     (timer->period & 0xffffffffULL) | new_val << 32;
-                }
-                timer->config &= ~HPET_TN_SETVAL;
-                if (hpet_enabled(s)) {
-                    hpet_set_timer(timer);
-                }
-                break;
+            }
+            timer->config &= ~HPET_TN_SETVAL;
+            if (hpet_enabled(s)) {
+                hpet_set_timer(timer);
+            }
+            break;
         case HPET_TN_ROUTE:
             timer->fsb = (timer->fsb & 0xffffffff00000000ULL) | new_val;
             break;
-- 
2.45.2



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-07-16  9:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-16  9:34 [PATCH 0/2] first batch of hpet fixes Paolo Bonzini
2024-07-16  9:34 ` [PATCH 1/2] hpet: fix clamping of period Paolo Bonzini
2024-07-16  9:34 ` [PATCH 2/2] hpet: fix HPET_TN_SETVAL for high 32-bits of the comparator Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).