public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: Heyi Guo <guoheyi@huawei.com>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Hao Wu <hao.a.wu@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>,
	Julien Grall <julien.grall@arm.com>,
	wanghaibin 00208455 <wanghaibin.wang@huawei.com>
Subject: Re: [RFC 0/3] Enable runtime serial debug for ArmVirtQemu
Date: Wed, 20 Mar 2019 10:55:35 +0100	[thread overview]
Message-ID: <8b2a9fcd-fb0d-6432-4481-e05d08816332@redhat.com> (raw)
In-Reply-To: <69336094-c1c0-b978-7fe7-6a585faedda6@huawei.com>

On 03/16/19 10:41, Heyi Guo wrote:
> On 2019/3/13 1:05, Laszlo Ersek wrote:

>> Given that you'd have to implement a "special" SerialPortLib instance
>> just for StatusCodeHandlerRuntimeDxe anyway, can we perhaps:
>>
>> (1) Undo -- dependent on a build flag? -- commit ebfca258f5d7; i.e.,
>> stick universally with BaseDebugLibSerialPort, for DebugLib,
>>
>> (2) add a new implementation of "FdtPL011SerialPortLib.inf" with both
>> (a) runtime behavior and (b) handling of a special serial port?
>>
>> In other words, push down the "runtime?" distinction from DebugLib (see
>> commit 7f029e1b31ee) to SerialPortLib. The new SerialPortLib instance
>> would be used only with DXE_RUNTIME_DRIVERs.
>>
>> The lib instance would prepare everything in advance for accessing the
>> "special" serial port at runtime (which could require allocating runtime
>> memory in advance). Once ExitBootServices() is called, a callback should
>> switch over the behavior of the lib instance, without allocating further
>> memory. (The switched-over behavior would not have to be functional
>> until the virtual address map is set.)
> My first idea was also simply implement a runtime serial port instance,
> but the problem is for the initialization.
> 
> Since serial port lib is only a library, it seems we can only initialize
> everything in SerialPortInitialize() or library constructor, but either
> of which could no work in current EDK2 code framework. Please see my
> explanation in earlier mail as below:
> 
> "The long story is: at first I proposed to still use
> BaseSerialPortDebugLib, so I added RuntimePrepare() function into the
> constructor directly, but the builder complained about looped
> constructors, for RuntimePrepare() invokes gBS and some RunTime
> libraries. Then I tried disabling the constructor and moved
> RuntimePrepare() into SerialPortInitialize() which could complete the
> build, but still couldn't guarantee the calling order of these
> constructors, for BaseSerialPortDebugLib has a constructor to call
> SerialPortInitialize()."

(Sorry about the late response (I've been away for a few days), and also
for missing that construction loop that you apparently mentioned earlier.)

You mention that "RuntimePrepare() invokes gBS and some RunTime
libraries". How important is it to rely on those libraries?

For example, "gBS" is simply a convenience; you can get at the same
thing from the parameter list of the constructor function too (assuming
you use a MODULE_TYPE of (minimally) DXE_DRIVER, in the lib instance's
INF file).

If we don't have to flatten a ridiculous amount of other library code
into the RuntimePrepare() function, I think such flattening would be a
viable approach. We've run into this constructor loop several times
before, and -- if I remember correctly anyway! -- one approach has been
to declare SerialPortLib the "lowest level abstraction", and make the
affected lib instance self-contained.

> Can we use event notify or protocol notify to do the runtime
> intialization? Like EndOfDxe event group. Any other advice?

I guess this could work too. I'm not really a fan of callbacks as long
as we can manage otherwise (for example, we can't propagate errors out
of callbacks), but if the lib flattening thing gets too complex, we
could do this as well.

Regarding EndOfDxe -- I think EndOfDxe is considered a trust barrier
(namely between platform fw modules and 3rd party modules), so I
wouldn't tie our initialization to that, for clarity's sake. ReadyToBoot
seems a tiny bit less "forced" -- it is sufficiently late, you can still
allocate resources, and we can claim it is "on the path towards OS
runtime". Just be aware that ReadyToBoot can be signaled multiple times,
e.g. if some boot options fail (so uninstall the handler / close the
event when serving the first callback I guess).

Thanks
Laszlo


  reply	other threads:[~2019-03-20  9:55 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-28  8:05 [RFC 0/3] Enable runtime serial debug for ArmVirtQemu Heyi Guo
2019-02-28  8:05 ` [RFC 1/3] MdeModulePkg/StatusCode: Add PCD to enable runtime serial debug Heyi Guo
2019-02-28  8:05 ` [RFC 2/3] ArmVirtPkg: add runtime instance of FdtPL011SerialPortLib Heyi Guo
2019-02-28  8:05 ` [RFC 3/3] ArmVirtQemu: enable runtime debug by build flag Heyi Guo
2019-02-28 12:10 ` [RFC 0/3] Enable runtime serial debug for ArmVirtQemu Ard Biesheuvel
2019-03-01 15:27   ` Laszlo Ersek
2019-03-04 13:52     ` Heyi Guo
2019-03-12  6:56     ` Heyi Guo
2019-03-12 17:05       ` Laszlo Ersek
2019-03-12 17:28         ` Andrew Fish
2019-03-12 19:42           ` Laszlo Ersek
2019-03-13 20:16           ` Brian J. Johnson
2019-03-14  3:52             ` Andrew Fish
2019-03-16  9:41         ` Heyi Guo
2019-03-20  9:55           ` Laszlo Ersek [this message]
2019-03-20 12:16             ` Heyi Guo
2019-03-20 17:47               ` Laszlo Ersek
2019-03-21  3:23                 ` Heyi Guo
2019-02-28 13:39 ` Laszlo Ersek
2019-03-01 12:24   ` Heyi Guo
2019-03-01 14:59     ` Laszlo Ersek
2019-03-01 15:14       ` Ard Biesheuvel
     [not found]       ` <CAFEAcA8AQjMJytpbXbBPH_YyuVW-PawhSgGeXaZGhVzRUPh9+A@mail.gmail.com>
2019-03-01 16:14         ` 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=8b2a9fcd-fb0d-6432-4481-e05d08816332@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