All of lore.kernel.org
 help / color / mirror / Atom feed
From: BALATON Zoltan <balaton@eik.bme.hu>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	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 13:48:38 +0100 (CET)	[thread overview]
Message-ID: <c2bdd618-5077-3b3f-12d0-974cf9757692@eik.bme.hu> (raw)
In-Reply-To: <e3a19d91-b9ef-9352-8f60-35432fdf5d1e@redhat.com>

On Tue, 21 Feb 2023, Paolo Bonzini wrote:
> 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;

Some break; statements are missing here and above. This patch does not 
apply, I had to apply it by hand to test it but it does not work. I don't 
have time now to debug this. My patch works and don't see what else could 
it break. We already have some devices set to native endian because of 
this so that could be a usable workaround for now until you can fix it in 
memory layer.

You can reproduce this with the MorphOS demo iso on pegasos2 with the 
original board firmware thath isn't free but availeble in an updater here:
http://web.archive.org/web/20071021223056/http://www.bplan-gmbh.de/up050404/up050404
and the script to get the rom image from it is here:
https://osdn.net/projects/qmiga/wiki/SubprojectPegasos2/attach/extract_rom_from_updater
the MorphOS iso is here:
https://www.morphos-team.net/morphos-3.17.iso

Then you can run it as:

qemu-system-ppc -M pegasos2 -bios pegasos2.rom -device ati-vga,romfile=""
   -serial stdio -cdrom morphos-3.17.iso

at the firmware ok prompt type 'boot cd boot.img' then click OK button for 
keyboard/language and once it booted press right mouse button on the top 
menu bar and select Shutdown from the Ambient (first) menu. Click twice on 
Shutwon button which should exit QEMU but does reboot instead without a 
fix. Can you please come up with a working fix if my patch is not 
acceptable.

Thank you,
BALATON Zoltan

>     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 12:49 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
2023-02-21 12:48                     ` BALATON Zoltan [this message]
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=c2bdd618-5077-3b3f-12d0-974cf9757692@eik.bme.hu \
    --to=balaton@eik.bme.hu \
    --cc=imammedo@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.