All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Simek <michal.simek@amd.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>
Cc: qemu-devel@nongnu.org, "Anton Johansson" <anjo@rev.ng>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Alistair Francis" <alistair@alistair23.me>,
	"Thomas Huth" <thuth@redhat.com>,
	qemu-arm@nongnu.org, devel@lists.libvirt.org,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Luc Michel" <luc@lmichel.fr>
Subject: Re: [PATCH 09/19] hw/intc/xilinx_intc: Only expect big-endian accesses
Date: Fri, 15 Nov 2024 16:00:19 +0100	[thread overview]
Message-ID: <d3346a55-584b-427b-8c87-32f7411a9290@amd.com> (raw)
In-Reply-To: <1625bc6b-8951-414c-88c0-62061289fdb5@linaro.org>



On 11/14/24 23:43, Philippe Mathieu-Daudé wrote:
> +Michal for Linux driver
> 
> On 5/11/24 23:08, Edgar E. Iglesias wrote:
>> On Tue, Nov 05, 2024 at 02:04:21PM +0100, Philippe Mathieu-Daudé wrote:
>>> Per the datasheet (reference added in file header, p.9)
>>> 'Programming Model' -> 'Register Data Types and Organization':
>>>
>>>      "The XPS INTC registers are read as big-endian data"
>>
>> Hi Phil,
>>
>> Some of these devices exist in both big and little endian versions.
>> So far we've reused the same model by using DEVICE_NATIVE_ENDIAN.
>>
>> Here's the little endian version:
>> https://docs.amd.com/v/u/en-US/ds747_axi_intc
> 
> This model is specified as:
> 
> - https://docs.amd.com/v/u/en-US/xps_intc
>    LogiCORE IP XPS Interrupt Controller (v2.01a)
>    DS572 April 19, 2010
> 
> Spec is from 2010, you added it in 2009:
> 
>    commit 17628bc642260df3a07b9df8b8a9ca7da2e7e87c
>    Author: Edgar E. Iglesias <edgar.iglesias@gmail.com>
>    Date:   Wed May 20 20:11:30 2009 +0200
> 
>        xilinx: Add interrupt controller.
> 
> The spec is explicit:
> 
>    "The XPS INTC registers are read as big-endian data"
> 
> 
> The other model you mention is:
> 
> - https://docs.amd.com/v/u/en-US/ds747_axi_intc
>    LogiCORE IP AXI INTC (v1.04a)
>    DS747 June 19, 2013
> 
> The spec is more recent than your addition, and contains
> the Interrupt Vector Address Register (IVAR) which is not
> present in our model.
> 
> 
> Indeed the latter seems to extend the former, but they are
> not the same and we need some work to model the latter.
> 
> The endianness explicit for each model (and is not listed
> in the "IP Configurable Design Parameters" tables).
> 
> 
> That said, let's look at Linux use. Driver was added in:
> 
>    commit eedbdab99fffb8ed71cac75a722088b8ace2583c
>    Author: Michal Simek <monstr@monstr.eu>
>    Date:   Fri Mar 27 14:25:49 2009 +0100
> 
>        microblaze_v8: Interrupt handling and timer support
> 
> Using explicit big-endian API:
> 
>    +void __init init_IRQ(void)
>    +{
>    ...
>    +       /*
>    +        * Disable all external interrupts until they are
>    +        * explicity requested.
>    +        */
>    +       out_be32(intc_baseaddr + IER, 0);
>    +
>    +       /* Acknowledge any pending interrupts just in case. */
>    +       out_be32(intc_baseaddr + IAR, 0xffffffff);
>    +
>    +       /* Turn on the Master Enable. */
>    +       out_be32(intc_baseaddr + MER, MER_HIE | MER_ME);
> 
> Then the driver became clever in:
> 
>    commit 1aa1243c339d4c902c0f9c1ced45742729a86e6a
>    Author: Michal Simek <michal.simek@amd.com>
>    Date:   Mon Feb 24 14:56:32 2014 +0100
> 
>        microblaze: Make intc driver endian aware
> 
>        Detect endianess directly on the hardware and use
>        ioread/iowrite functions.
> 
>    +static void intc_write32(u32 val, void __iomem *addr)
>    +{
>    +       iowrite32(val, addr);
>    +}
>    +
>    +static void intc_write32_be(u32 val, void __iomem *addr)
>    +{
>    +       iowrite32be(val, addr);
>    +}
> 
> @@ -140,17 +163,25 @@ static int __init xilinx_intc_of_init(struct device_node 
> *intc,
> 
>    +       write_fn = intc_write32;
>    +       read_fn = intc_read32;
>    +
>            /*
>             * Disable all external interrupts until they are
>             * explicity requested.
>             */
>    -       out_be32(intc_baseaddr + IER, 0);
>    +       write_fn(0, intc_baseaddr + IER);
> 
>            /* Acknowledge any pending interrupts just in case. */
>    -       out_be32(intc_baseaddr + IAR, 0xffffffff);
>    +       write_fn(0xffffffff, intc_baseaddr + IAR);
> 
>            /* Turn on the Master Enable. */
>    -       out_be32(intc_baseaddr + MER, MER_HIE | MER_ME);
>    +       write_fn(MER_HIE | MER_ME, intc_baseaddr + MER);
>    +       if (!(read_fn(intc_baseaddr + MER) & (MER_HIE | MER_ME))) {
>    +               write_fn = intc_write32_be;
>    +               read_fn = intc_read32_be;
>    +               write_fn(MER_HIE | MER_ME, intc_baseaddr + MER);
>    +       }
> 
> Interestingly little endianness became the default, although
> the driver detect it on init.
> 
> This is from 2014, maybe to work with the "LogiCORE IP AXI INTC"
> you mentioned, which spec date is 2013.
> 
> Indeed when forcing different endianness [*], the Linux kernel used
> in our tests (tests/functional/test_microblaze*) does the check
> and ends up using the correct INTC endianness:
> 
> LE CPU, LE INTC model
> pic_write addr=8 val=0
> pic_write addr=c val=ffffffff
> pic_write addr=1c val=3           <- LE
> pic_read 1c=3
> pic_write addr=c val=1
> pic_write addr=10 val=1
> pic_read 18=0
> 
> LE CPU, BE INTC model
> pic_write addr=8 val=0
> pic_write addr=c val=ffffffff
> pic_write addr=1c val=3000000     <- LE test
> pic_read 1c=0
> pic_write addr=1c val=3           <- BE
> pic_write addr=c val=1
> pic_write addr=10 val=1
> pic_read 18=0
> 
> BE CPU, BE INTC model
> pic_write addr=8 val=0
> pic_write addr=c val=ffffffff
> pic_write addr=1c val=3000000     <- LE test
> pic_read 1c=0
> pic_write addr=1c val=3           <- BE
> pic_write addr=c val=1
> pic_write addr=10 val=1
> pic_read 18=0
> 
> BE CPU, LE INTC model
> pic_write addr=8 val=0
> pic_write addr=c val=ffffffff
> pic_write addr=1c val=3           <- LE
> pic_read 1c=3
> pic_write addr=c val=1
> pic_write addr=10 val=1
> pic_read 18=0
> 
> 
> IMHO this patch behavior is correct. Besides, I don't expect
> firmwares to be as clever as Linux.
> 
>> Can we have add property to select the endianess?
>> For the Xilinx use-cases I think it may be a good idea to default it
>> to little endian and have the big-endian machines explicitly set it.
> 
> What you suggested is implemented in v3:
> https://lore.kernel.org/qemu-devel/20241108154317.12129-4-philmd@linaro.org/
> but after the analysis, I wonder if it isn't safer to not
> make the endianness configurable, but expose as 2 models:
> - xlnx,xps_intc (2010) in BE
> - xlnx,axi_intc (2013) in LE

It is a little bit more complicated.
In past everything started as big endian on OPB bus. Then PLB bus still big 
endian and then AXI came and things have been moved to little endian.
That's from bus perspective.

 From CPU perspective itself till AXI microblaze was big endian only. With AXI 
cpu started to be by default little endian but still today you can still 
configured cpu to be big endian (C_ENDIANNESS config) with using AXI bus.

Truth is that I am not aware about anybody configuring MB to big endian and we 
are on AXI for quite a long time. There is still code in Linux kernel for it but 
I can't see any reason to keep it around. I don't think that make sense to keep 
big endian configurations alive at all.

Thanks,
Michal








  reply	other threads:[~2024-11-15 15:01 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-05 13:04 [PATCH 00/19] hw/microblaze: Allow running cross-endian vCPUs Philippe Mathieu-Daudé
2024-11-05 13:04 ` [PATCH 01/19] target/microblaze: Rename CPU endianness property as 'little-endian' Philippe Mathieu-Daudé
2024-11-05 14:16   ` Anton Johansson via
2024-11-05 14:16     ` Anton Johansson via
2024-11-05 22:29   ` Alistair Francis
2024-11-05 22:54   ` Edgar E. Iglesias
2024-11-05 23:01     ` Philippe Mathieu-Daudé
2024-11-05 23:18       ` Philippe Mathieu-Daudé
2024-11-05 23:20         ` Edgar E. Iglesias
2024-11-05 13:04 ` [PATCH 02/19] hw/microblaze: Deprecate big-endian petalogix-ml605 & xlnx-zynqmp-pmu Philippe Mathieu-Daudé
2024-11-05 14:22   ` Anton Johansson via
2024-11-05 14:22     ` Anton Johansson via
2024-11-05 22:34   ` Alistair Francis
2024-11-05 22:56   ` Edgar E. Iglesias
2024-11-05 13:04 ` [PATCH 03/19] hw/microblaze/s3adsp1800: Explicit CPU endianness Philippe Mathieu-Daudé
2024-11-05 13:22   ` Richard Henderson
2024-11-05 22:34   ` Alistair Francis
2024-11-05 22:59   ` Edgar E. Iglesias
2024-11-05 13:04 ` [PATCH 04/19] hw/microblaze/s3adsp1800: Rename unimplemented MMIO region as xps_gpio Philippe Mathieu-Daudé
2024-11-05 14:26   ` Anton Johansson via
2024-11-05 22:37   ` Alistair Francis
2024-11-05 22:59   ` Edgar E. Iglesias
2024-11-05 13:04 ` [PATCH 05/19] hw/microblaze/s3adsp1800: Declare machine type using DEFINE_TYPES macro Philippe Mathieu-Daudé
2024-11-05 14:33   ` Anton Johansson via
2024-11-05 14:33     ` Anton Johansson via
2024-11-05 22:40   ` Alistair Francis
2024-11-05 22:59   ` Edgar E. Iglesias
2024-11-05 13:04 ` [PATCH 06/19] hw/microblaze: Fix MemoryRegionOps coding style Philippe Mathieu-Daudé
2024-11-05 13:23   ` Richard Henderson
2024-11-05 22:38   ` Alistair Francis
2024-11-05 23:00   ` Edgar E. Iglesias
2024-11-05 13:04 ` [PATCH 07/19] hw/microblaze: Restrict MemoryRegionOps are implemented as 32-bit Philippe Mathieu-Daudé
2024-11-05 14:50   ` Anton Johansson via
2024-11-05 14:50     ` Anton Johansson via
2024-11-05 22:24   ` Philippe Mathieu-Daudé
2024-11-05 22:27     ` Philippe Mathieu-Daudé
2025-01-02 12:20       ` Philippe Mathieu-Daudé
2024-11-05 13:04 ` [PATCH 08/19] hw/microblaze: Propagate CPU endianness to microblaze_load_kernel() Philippe Mathieu-Daudé
2024-11-05 16:56   ` Anton Johansson via
2024-11-05 16:56     ` Anton Johansson via
2024-11-05 22:13   ` Alistair Francis
2024-11-05 23:02   ` Edgar E. Iglesias
2024-11-05 13:04 ` [PATCH 09/19] hw/intc/xilinx_intc: Only expect big-endian accesses Philippe Mathieu-Daudé
2024-11-05 16:58   ` Anton Johansson via
2024-11-05 16:58     ` Anton Johansson via
2024-11-05 22:24   ` Alistair Francis
2024-11-05 23:08   ` Edgar E. Iglesias
2024-11-14 22:43     ` Philippe Mathieu-Daudé
2024-11-15 15:00       ` Michal Simek [this message]
2024-11-05 13:04 ` [PATCH 10/19] hw/timer/xilinx_timer: " Philippe Mathieu-Daudé
2024-11-05 16:58   ` Anton Johansson via
2024-11-05 23:09   ` Edgar E. Iglesias
2024-11-05 13:04 ` [PATCH 11/19] hw/timer/xilinx_timer: Allow down to 8-bit memory access Philippe Mathieu-Daudé
2024-11-05 17:00   ` Anton Johansson via
2024-11-05 22:25   ` Alistair Francis
2024-11-05 23:09   ` Edgar E. Iglesias
2024-11-05 13:04 ` [PATCH 12/19] hw/net/xilinx_ethlite: Only expect big-endian accesses Philippe Mathieu-Daudé
2024-11-05 13:30   ` Richard Henderson
2024-11-06  9:53     ` Philippe Mathieu-Daudé
2024-11-05 14:18   ` Paolo Bonzini
2024-11-05 23:29     ` Philippe Mathieu-Daudé
2024-11-06  6:45       ` Paolo Bonzini
2024-11-05 23:16   ` Edgar E. Iglesias
2024-11-05 13:04 ` [PATCH 13/19] target/microblaze: Explode MO_TExx -> MO_TE | MO_xx Philippe Mathieu-Daudé
2024-11-05 13:31   ` Richard Henderson
2024-11-05 22:57   ` Alistair Francis
2024-11-05 13:04 ` [PATCH 14/19] target/microblaze: Set MO_TE once in do_load() / do_store() Philippe Mathieu-Daudé
2024-11-05 13:32   ` Richard Henderson
2024-11-05 13:04 ` [PATCH 15/19] target/microblaze: Introduce mo_endian() helper Philippe Mathieu-Daudé
2024-11-05 13:32   ` Richard Henderson
2024-11-05 13:04 ` [PATCH 16/19] target/microblaze: Consider endianness while translating code Philippe Mathieu-Daudé
2024-11-05 13:33   ` Richard Henderson
2024-11-05 13:04 ` [PATCH 17/19] hw/microblaze: Support various endianness for s3adsp1800 machines Philippe Mathieu-Daudé
2024-11-05 13:43   ` Richard Henderson
2024-11-05 13:04 ` [PATCH 18/19] tests/functional: Explicit endianness of microblaze assets Philippe Mathieu-Daudé
2024-11-05 13:44   ` Richard Henderson
2024-11-05 13:04 ` [PATCH 19/19] tests/functional: Add microblaze cross-endianness tests Philippe Mathieu-Daudé
2024-11-05 13:46   ` Richard Henderson

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=d3346a55-584b-427b-8c87-32f7411a9290@amd.com \
    --to=michal.simek@amd.com \
    --cc=alistair@alistair23.me \
    --cc=anjo@rev.ng \
    --cc=devel@lists.libvirt.org \
    --cc=edgar.iglesias@gmail.com \
    --cc=jasowang@redhat.com \
    --cc=luc@lmichel.fr \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=thuth@redhat.com \
    /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.