public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: Guo Heyi <heyi.guo@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>,
	Leif Lindholm <leif.lindholm@linaro.org>
Subject: Re: [PATCH edk2-platforms 1/2] Platform, Silicon: use DxeRuntimeDebugLibSerialPort for runtime DXE drivers
Date: Tue, 27 Feb 2018 16:59:28 +0100	[thread overview]
Message-ID: <706092d9-679d-d1e7-2253-946eda2b1b87@redhat.com> (raw)
In-Reply-To: <20180227113042.GF3918@SZX1000114654>

On 02/27/18 12:30, Guo Heyi wrote:
> On Tue, Feb 27, 2018 at 11:43:35AM +0100, Laszlo Ersek wrote:
>> On 02/27/18 10:23, Ard Biesheuvel wrote:
>>> On 27 February 2018 at 01:50, Guo Heyi <heyi.guo@linaro.org> wrote:
>>>> Hi Ard,
>>>>
>>>> Sorry for the late of seeing this patch. I have one question: why don't we
>>>> implement a runtime serial port lib, which will switch UART base address in
>>>> virtual address map change? I think this will be useful when we want to debug
>>>> runtime driver in OS stage. And if we have a runtime version of SerialPortLib,
>>>> then we don't need a runtime version of DebugLib which just disable touching
>>>> serial port.
>>>>
>>>
>>> Well, only if the serial port is not exposed to the OS as well. The
>>> Linux PL011 driver is especially easy to confuse, and having both the
>>> firmware and the OS control it at the same time is likely to cause
>>> problems.
>>>
>>> However, I do agree that having the ability to assign a UART to DEBUG
>>> at runtime is useful, and so I do intend to create a runtime version
>>> of the PL011 library, in which case DxeRuntimeDebugLibSerialPort can
>>> be replaced with BaseDebugLibSerialPort for DXE_RUNTIME_DRIVER
>>> modules.
>>>
>>
>> Converting the PL011 base address from phys to virt can be done in the
>> library instance, yes (and then every runtime driver module linked
>> against this library instance will individually convert the address for
>> its own use). The messier aspect is getting the PL011 base address into
>> the UEFI memmap, marked as MMIO / RUNTIME, so that the OS assign a
>> virtual mapping to it in the first place.
>>
>> The flash drivers generally do this with AddMemorySpace /
>> SetMemorySpaceAttributes.
>>
>> (Side point: while I agree that those are good APIs to invoke, I think
>> they should also call AllocateMemorySpace right after; otherwise a
>> "stray" AllocateMemorySpace elsewhere could allocate a chunk out of the
>> middle of what the flash driver *thinks* it owns.)
>>
>> The question is where this pair (or triplet) of GCD APIs should be called:
>>
>> - In a platform DXE driver? Perhaps.
>>
>> - In the DebugLib instance constructor / destructor? That could result
>> in some ugly reference counting -- you might want to keep the PL011 area
>> registered in GCD as long as *at least one* such runtime driver is loaded.
>>
>> This is different from the flash driver because the flash driver is the
>> sole runtime DXE (or SMM) driver that accesses & owns the flash MMIO
>> range. With the PL011 register block, that's not the case; all runtime
>> drivers that produce debug messages own it co-operatively.
> 
> On our platforms, we actually use
> IntelFrameworkModulePkg/PeiDxeDebugLibReportStatusCode,
> MdeModulePkg/RuntimeDxeReportStatusCodeLib and
> IntelFrameworkModulePkg/StatusCodeRuntimeDxe as the whole DebugLib call chain
> for runtime drivers. Is StatusCodeRuntimeDxe a good place for GCD manipulation?

Sure; if DebugLib (and the library instances below it) don't directly
access hardware, but make calls to some shared code -- i.e. into another
runtime DXE driver via a protocol interface originally looked up /
stashed at boot time, and then converted to a virtual address --, then
only that runtime DXE driver needs to manage the GCD map.

> But I've no idea on how to distinguish the code between ARM and X86, for X86
> uses port IO for serial port access.

If you can ascertain that the lib instance linked into
StatusCodeRuntimeDxe (a) is not used by any other module, and (b)
performs the hardware access, then you could push the GCD management
into that lib instance. Or else, you could write a plug-in lib instance
and hook that with NULL resolution into the driver.

But, I guess, at this point it's simplest to modify PlatformPei or
PlatformDxe to add that entry to GCD in advance, regardless of the
actual number of runtime DXE drivers that will rely on the mapping.

Laszlo


  reply	other threads:[~2018-02-27 15:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-24 14:25 [PATCH edk2-platforms 1/2] Platform, Silicon: use DxeRuntimeDebugLibSerialPort for runtime DXE drivers Ard Biesheuvel
2018-02-24 14:25 ` [PATCH edk2-platforms 2/2] Silicon/SynQuacerI2cDxe: remove special runtime treatment of DEBUG()s Ard Biesheuvel
2018-02-26 14:50 ` [PATCH edk2-platforms 1/2] Platform, Silicon: use DxeRuntimeDebugLibSerialPort for runtime DXE drivers Laszlo Ersek
2018-02-27  1:50 ` Guo Heyi
2018-02-27  9:23   ` Ard Biesheuvel
2018-02-27 10:43     ` Laszlo Ersek
2018-02-27 11:30       ` Guo Heyi
2018-02-27 15:59         ` Laszlo Ersek [this message]
2018-02-27 14:21       ` Ard Biesheuvel
2018-02-27 16:09         ` Laszlo Ersek
2018-02-27 16:10           ` Ard Biesheuvel
2018-02-27 17:33             ` Ard Biesheuvel
2018-02-27 17:47               ` Laszlo Ersek
2018-02-27 17:55                 ` Ard Biesheuvel
2018-02-27 10:39 ` Leif Lindholm
2018-02-27 10:45   ` Ard Biesheuvel

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=706092d9-679d-d1e7-2253-946eda2b1b87@redhat.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