public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Michael Brown" <mcb30@ipxe.org>
To: devel@edk2.groups.io, ardb@kernel.org
Cc: pedro.falcato@gmail.com, jlotwo@gmail.com,
	 Leif Lindholm <quic_llindhol@quicinc.com>,
	 Sami Mujawar <sami.mujawar@arm.com>, Ray Ni <ray.ni@intel.com>
Subject: Re: [edk2-devel] [RFC] Ordering of Arm PCI ECAM and MMIO operations
Date: Wed, 1 Nov 2023 13:23:59 +0000	[thread overview]
Message-ID: <0102018b8b0e1ca8-ce15d29c-2c0c-4982-9c45-be42ae53a1d6-000000@eu-west-1.amazonses.com> (raw)
In-Reply-To: <CAMj1kXFr85Phcs77i173fwx7qkUVGq0ss33=ecf8PcgAfO9kNg@mail.gmail.com>

On 01/11/2023 12:51, Ard Biesheuvel wrote:
> On Wed, 1 Nov 2023 at 13:25, Michael Brown <mcb30@ipxe.org> wrote:
>> By my reading, the PCIe specification seems to therefore require
>> something stronger than an ordering guarantee: it requires the ability
>> for software to make a standalone determination that the write has
>> *completed*, independent of the existence of any subsequent I/O operations.
> 
> indeed, thanks for bringing this up.
> 
>> The PCIe specification does not mandate that any particular mechanism be
>> used, but it does require that the processor and/or host bridge provides
>> *some* mechanism for software to determine that the ECAM write has
>> completed.
>>
>> What mechanism does ARM (or the host bridge) provide to determine
>> completion of an ECAM write?
> 
> A MMIO read of the same location should ensure that the MMIO write has
> completed by the time the read returns. Not sure whether or not there
> are any other requirements (e.g., wrt.the size of the read vs the size
> of the write).

That seems to suggest that a logical PCIe configuration space write 
operation using ECAM should probably always comprise:

1. ECAM write
2. ECAM read from the same location (using the same size)

If reads are not allowed to have side effects (e.g. read-clear 
registers) then this seems safe.  The PCIe specification "Configuration 
Register Types" list comprises (in version 3.0, at least):

   HwInit - read-only, no read side effects

   RO - read-only, no read side effects

   RW - read-write, no read side effects

   RW1C - write 1 to clear bits, no read side effects

   ROS - read-only, no read side effects

   RWS - read-write, no read side effects

   RW1CS - write 1 to clear bits, no read side effects

   RsvdP - read-write, no read side effects

   RsvdZ - read-write, no read side effects

So, unless newer versions of the PCIe specification have allowed for the 
existence of configuration register types with read side effects, then 
the approach of always reading back from ECAM seems to be safe for any 
conforming PCIe device.

I would therefore suggest that all ECAM driver implementation functions 
in EDK2 (e.g. PciExpressWrite32(), PciExpressOr32(), 
PciSegmentWrite32(), etc) be updated to add the relevant ECAM read 
following the write operation.

PCI configuration space writes are never fast-path operations (in any 
sane hardware), and so the delay introduced by the read should not be 
significant.

Does this seem like a sensible solution?

Thanks,

Michael



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#110480): https://edk2.groups.io/g/devel/message/110480
Mute This Topic: https://groups.io/mt/102310377/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  reply	other threads:[~2023-11-01 13:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-31 23:24 [edk2-devel] [RFC] Ordering of Arm PCI ECAM and MMIO operations Joe L
2023-11-01  2:09 ` Pedro Falcato
2023-11-01  9:56   ` Ard Biesheuvel
2023-11-01 12:25     ` Michael Brown
2023-11-01 12:51       ` Ard Biesheuvel
2023-11-01 13:23         ` Michael Brown [this message]
2023-11-01 16:41           ` Ard Biesheuvel
2023-11-01 20:17             ` Joe L
2023-11-01 21:51               ` Michael Brown
2023-11-01 23:07                 ` Pedro Falcato

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-list 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=0102018b8b0e1ca8-ce15d29c-2c0c-4982-9c45-be42ae53a1d6-000000@eu-west-1.amazonses.com \
    --to=devel@edk2.groups.io \
    /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