qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: BALATON Zoltan <balaton@eik.bme.hu>,
	"Michael S. Tsirkin" <mst@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [PATCH] hw/acpi: Set memory regions to native endian as a work around
Date: Tue, 21 Feb 2023 09:30:34 +0100	[thread overview]
Message-ID: <e3a19d91-b9ef-9352-8f60-35432fdf5d1e@redhat.com> (raw)
In-Reply-To: <f4e755b6-051e-103f-b8bc-2765d277633f@eik.bme.hu>

On 2/21/23 00:25, BALATON Zoltan wrote:
>> I think fundamentally you need to check for the condition
>> Size < mr->ops->impl.min_access_size in memory_region_dispatch_write
>> and then make a read, combine the result with
>> the value and make a write.
> 
> I neither know that part nor feel confident enough breaking such low 
> level stuff so I think setting the affected regions NATIVE_ENDIAN for 
> now until somebody takes care of this is safer and not likely to break 
> anyting (or if it does, much less widely and I'm more likely to be able 
> to fix that than your proposed changes). So I'd rather let you do that 
> but I'd like this fixed one way or another at last.

Sorry about not replying.

The case of impl.min_access_size < valid.min_access_size is not
supported in the memory core.  Until that is done, the correct fix is to
fix acpi_pm_evt_ops to have impl.min_access_size == 1, something like
this:

diff --git a/hw/acpi/core.c b/hw/acpi/core.c
index 6da275c599c6..96eb88fa7e27 100644
--- a/hw/acpi/core.c
+++ b/hw/acpi/core.c
@@ -429,20 +429,35 @@ void acpi_pm1_evt_reset(ACPIREGS *ar)
  static uint64_t acpi_pm_evt_read(void *opaque, hwaddr addr, unsigned width)
  {
      ACPIREGS *ar = opaque;
+    uint16_t val;
      switch (addr) {
      case 0:
-        return acpi_pm1_evt_get_sts(ar);
+        val = acpi_pm1_evt_get_sts(ar);
      case 2:
-        return ar->pm1.evt.en;
+        val = ar->pm1.evt.en;
      default:
          return 0;
      }
+
+    if (width == 1) {
+        int bitofs = (addr & 1) * 8;
+        val >>= bitofs;
+    }
+    return val;
  }
  
  static void acpi_pm_evt_write(void *opaque, hwaddr addr, uint64_t val,
                                unsigned width)
  {
      ACPIREGS *ar = opaque;
+    if (width == 1) {
+        int bitofs = (addr & 1) * 8;
+        uint16_t old_val = acpi_pm_evt_read(ar, addr, val & ~1);
+        uint16_t mask = 0xFF << bitofs;
+        val = (old_val & ~mask) | (val << bitofs);
+        addr &= ~1;
+    }
+
      switch (addr) {
      case 0:
          acpi_pm1_evt_write_sts(ar, val);
@@ -458,7 +473,7 @@ static void acpi_pm_evt_write(void *opaque, hwaddr addr, uint64_t val,
  static const MemoryRegionOps acpi_pm_evt_ops = {
      .read = acpi_pm_evt_read,
      .write = acpi_pm_evt_write,
-    .impl.min_access_size = 2,
+    .impl.min_access_size = 1,
      .valid.min_access_size = 1,
      .valid.max_access_size = 2,
      .endianness = DEVICE_LITTLE_ENDIAN,


This assumes that the bus is little-endian, i.e. reading the byte at PM_EVT returns
bits 0..7 and reading the byte at PM_EVT+1 returns bits 8..15.

If this is incorrect, endianness needs to be changed as well.

Paolo



  reply	other threads:[~2023-02-21  8:31 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-08 13:05 [PATCH] hw/acpi: Set memory regions to native endian as a work around BALATON Zoltan
2021-11-08 13:32 ` Michael S. Tsirkin
2021-11-08 15:22   ` BALATON Zoltan
2021-12-16 10:27   ` Michael S. Tsirkin
2021-11-08 14:30 ` Paolo Bonzini
2021-11-08 15:04   ` Paolo Bonzini
2021-11-08 15:16     ` BALATON Zoltan
2021-11-13 18:47       ` BALATON Zoltan
2022-01-19  9:19         ` Michael S. Tsirkin
2022-02-22 14:40           ` Michael S. Tsirkin
2023-02-20 18:24             ` BALATON Zoltan
2023-02-20 22:33               ` Michael S. Tsirkin
2023-02-20 23:25                 ` BALATON Zoltan
2023-02-21  8:30                   ` Paolo Bonzini [this message]
2023-02-21 12:48                     ` BALATON Zoltan
2023-02-21 12:55                       ` BALATON Zoltan
2023-03-06 22:56                         ` Paolo Bonzini
2023-03-06 23:11                           ` BALATON Zoltan
2023-03-06 23:36                           ` Paolo Bonzini
2023-03-07  0:06                             ` BALATON Zoltan
2023-03-07  5:58                               ` Paolo Bonzini
2023-03-07 10:01                                 ` BALATON Zoltan
2023-03-07 11:26                                   ` Paolo Bonzini
2023-03-07 12:54                                     ` BALATON Zoltan
2023-03-07 15:14                                       ` Paolo Bonzini
2023-03-07 15:21                                         ` BALATON Zoltan
2023-03-07 16:48                                           ` Paolo Bonzini
2023-04-30 23:10                                     ` BALATON Zoltan
2023-04-30 23:26                                       ` BALATON Zoltan
2023-02-21 14:02                       ` Paolo Bonzini
2023-03-02 13:42                         ` BALATON Zoltan
2023-03-06 18:34                           ` Michael S. Tsirkin
2023-03-03  8:22                         ` Michael S. Tsirkin
2023-03-11 20:59                     ` Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e3a19d91-b9ef-9352-8f60-35432fdf5d1e@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=balaton@eik.bme.hu \
    --cc=imammedo@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).