public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: miaoyubo <miaoyubo@huawei.com>,
	"ard.biesheuvel@linaro.org" <ard.biesheuvel@linaro.org>,
	"leif@nuviainc.com" <leif@nuviainc.com>
Cc: "devel@edk2.groups.io" <devel@edk2.groups.io>,
	Xiexiangyou <xiexiangyou@huawei.com>
Subject: Re: [PATCH] ArmVirtPkg/FdtPciHostBridgeLib: add extra roots for Arm.
Date: Wed, 8 Apr 2020 12:15:39 +0200	[thread overview]
Message-ID: <57fd0043-d63a-55b0-9c55-4ca079331885@redhat.com> (raw)
In-Reply-To: <62080872605a4a36a9df99313350b1f2@huawei.com>

On 04/08/20 05:58, miaoyubo wrote:

>>> (2) This code is way too large for my taste to duplicate between
>>> ArmVirtPkg and OvmfPkg. I would strongly prefer if we could factor the
>>> logic in OvmfPkg out to a separate library, and use that from both
>> consumer sites.
>>>
> 
> Where should I put the extracted logic?(Still put in OvmfPkg and direct use it in ArmVirtPkg  or
> put them in MdeModulePkg/Include/Library/PciHostBridgeLib.h? If in PciHostBridgeLib.h, 
> should I create a new .c file as a common implementation?) 
> There are some other codes duplicated between FdtPciHostBridgeLib.c and PciHostBridgeLib.c,
> should I extract them?

Good questions, I've kind of expected them. Thanks for asking them.

There are at least two ways to approach this.

* One would be to move the ArmVirtPkg/Library/FdtPciHostBridgeLib/ stuff
under OvmfPkg/Library/PciHostBridgeLib/, have two INF files in the same
directory, and separate out exactly those bits of functionality that are
shared, using module-internal header files.

This is usually a good thing if much of the logic is shared. In this
case, I don't like it however, as the ArmVirtPkg lib instance INF file
itself lists some dependencies that come from "ArmPkg.dec" and
"ArmVirtPkg.dec":

- PciPcdProducerLib class
- PcdPciMmio32Translation, PcdPciMmio64Translation, PcdPciIoTranslation
- gFdtClientProtocolGuid

So we'd either have to move those into OvmfPkg, or else make OvmfPkg
content depend on ArmVirtPkg.dec / ArmPkg.dec. None of those are good ideas.

* Therefore, please go the more winding route, and introduce a new lib
class, and lib instance, under OvmfPkg. For the lib class name, I
suggest "PciHostBridgeUtilityLib". Files:

OvmfPkg/OvmfPkg.dec
OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c

Then both OvmfPkg's and ArmVirtPkg's PciHostBridgeLib instances can
consume this.

I'd prefer four patches:

- #1: OvmfPkg patch. Introduce the new lib class and lib instance, with
functionality that the ArmVirtPkg and OvmfPkg PciHostBridgeLib instances
already share.

Regarding the OvmfPkg/Library/PciHostBridgeLib instace, you can at once
move code from that lib instance to the new
OvmfPkg/Library/PciHostBridgeUtilityLib, in this patch.

- #2: ArmVirtPkg patch. Elminate the currently duplicated code, and put
the newly extracted code to use, through consuming the new lib class.

- #3: OvmfPkg patch. Move more code from PciHostBridgeLib to
PciHostBridgeUtilityLib: code that you will need to use in the next
patch, for enabling multiple root bridges in ArmVirtPkg.

-#4: ArmVirtPkg patch. Consume the code exposed in patch#3 for enabling
the feature.


In theory, the code extraction / movement described in patches #1 and #3
could be done in a single unified step, at the start of the series.
However, we certainly want to keep #2 and #4 separate (#2 is
refactoring, #4 is feature enablement). And then I prefer keeping #1 and
#3 separate too -- while both move code from the same old lib instance
to the same new lib instance, their motivations are different. The
ultimate goal is of course just the one "share as much code as possible
between ArmVirtPkg and OvmfPkg", but, when I run "git-blame" on the new
lib class header, I'd like to understand why exactly any given function
prototype was declared there.

Thanks!
Laszlo


      reply	other threads:[~2020-04-08 10:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-02 12:08 [PATCH] ArmVirtPkg/FdtPciHostBridgeLib: add extra roots for Arm Yubo Miao
2020-04-02 13:52 ` Laszlo Ersek
2020-04-03  8:55   ` miaoyubo
2020-04-08  3:58   ` miaoyubo
2020-04-08 10:15     ` Laszlo Ersek [this message]

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=57fd0043-d63a-55b0-9c55-4ca079331885@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