public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Michael Brown" <mcb30@ipxe.org>
To: "Kinney, Michael D" <michael.d.kinney@intel.com>,
	 "devel@edk2.groups.io" <devel@edk2.groups.io>,
	 "lersek@redhat.com" <lersek@redhat.com>,
	 "jlotwo@gmail.com" <jlotwo@gmail.com>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>,
	 Ard Biesheuvel <ardb+tianocore@kernel.org>,
	 Sami Mujawar <sami.mujawar@arm.com>,
	 "Wang, Jian J" <jian.j.wang@intel.com>,
	 "Gao, Liming" <gaoliming@byosoft.com.cn>,
	 "Wu, Hao A" <hao.a.wu@intel.com>, "Ni, Ray" <ray.ni@intel.com>,
	 Pedro Falcato <pedro.falcato@gmail.com>
Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/PciHostBridgeDxe: Add readback after final Cfg-Write
Date: Fri, 3 Nov 2023 16:57:05 +0000	[thread overview]
Message-ID: <0102018b961decc1-e615fc66-39cb-4826-9f61-bdabeb43e73e-000000@eu-west-1.amazonses.com> (raw)
In-Reply-To: <CO1PR11MB4929B59E63624A481B622859D2A5A@CO1PR11MB4929.namprd11.prod.outlook.com>

On 03/11/2023 16:03, Kinney, Michael D wrote:
> PCI Configuration read/write operations are non-posted, so the PCI
> Configuration write operation should complete without the need for
> an additional transaction.  If you are seeing an issue, then it may
> be in the implementation of the PciLib/PciSegmentLib that is not
> guaranteeing this non-posted behavior.

 From the PCIe spec:

   "The ECAM converts memory transactions from the host CPU into
    Configuration Requests on the PCI Express fabric. This conversion
    potentially creates ordering problems for the software, because
    writes to memory addresses are typically posted transactions but
    writes to Configuration Space are not posted on the PCI Express
    fabric."

My understanding from the above is that the posted write occurs at the 
level of the CPU performing a memory write to the ECAM window.  By the 
time this write reaches the ECAM and becomes a non-posted write 
transaction within the downstream PCIe fabric, the CPU has already moved 
on and is not waiting for completion of the ECAM memory write.

Reading back from the PCI configuration register will cause the CPU to 
wait until the read from the ECAM window has completed, which cannot 
happen until the corresponding downstream PCI configuration read has 
completed.  Since the CPU will (with appropriate barrier operations) not 
reorder the memory read ahead of the preceding memory write, the overall 
effect is to guarantee that the memory write has reached the ECAM, and 
that the memory write reached the ECAM before the subsequent memory read 
from the same location.

There is an implicit assumption in the above that the ECAM and PCIe 
fabric will themselves not reorder the PCI configuration read ahead of 
the PCI configuration write.  Unfortunately, on a closer reading of the 
spec, this may not be a valid assumption: other parts of the PCIe spec 
state that non-posted transactions (e.g. configuration reads and writes) 
may be freely reordered.

It seems slightly insane that PCIe bridges would be allowed to 
arbitrarily reorder configuration cycles to downstream devices, but 
that's what the spec seems to state.  The upshot seems to be that:

a) software is entirely responsible for ensuring that PCI configuration 
writes via ECAM have completed, and

b) software has no available mechanism for ensuring that PCI 
configuration writes via ECAM have completed.

Ard: any alternative suggestions on ways we can wait for completion, 
given that even reading back from the PCI configuration register is 
apparently not guaranteed?

Thanks,

Michael



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



  reply	other threads:[~2023-11-03 16:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-03  0:03 [edk2-devel] [PATCH] MdeModulePkg/PciHostBridgeDxe: Add readback after final Cfg-Write Joe L
2023-11-03  7:19 ` Laszlo Ersek
2023-11-03 16:03   ` Michael D Kinney
2023-11-03 16:57     ` Michael Brown [this message]
2023-11-06  6:55       ` Joe L
2023-11-08 19:30         ` Laszlo Ersek

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=0102018b961decc1-e615fc66-39cb-4826-9f61-bdabeb43e73e-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