linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiang Liu <jiang.liu@huawei.com>
To: Yinghai Lu <yinghai@kernel.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	Taku Izumi <izumi.taku@jp.fujitsu.com>,
	Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>,
	Don Dutile <ddutile@redhat.com>,
	Yijing Wang <wangyijing@huawei.com>,
	Keping Chen <chenkeping@huawei.com>, <linux-pci@vger.kernel.org>,
	Jiang Liu <liuj97@gmail.com>
Subject: Re: [PATCH v7 08/10] PCI, x86: add MMCFG information on demand
Date: Sat, 16 Jun 2012 16:58:20 +0800	[thread overview]
Message-ID: <4FDC4AAC.8010601@huawei.com> (raw)
In-Reply-To: <CAE9FiQUOtdB3PMgmX8aSRYrinhJGWoUBZGii1aowDBLKTH_LJQ@mail.gmail.com>

Hi Yinghai,
	How about following patch to solve the "probe/free then install" issue?
For pci_mmcfg_early_init(), we still need the "probe/free then install" dance
because MMCONFIG may be need for hardware quirks at early stage.
For pci_mmcfg_late_init(), the patch get rid of the redundant "probe/free"
steps. It also generates better readable code.
	Thanks!
	Gerry

---
The logic of __pci_mmcfg_init() is a little complex, so simplify it a little.

Signed-off-by: Jiang Liu <liuj97@gmail.com>
---
 arch/x86/pci/mmconfig-shared.c |   72 ++++++++++++++++++++++------------------
 1 files changed, 40 insertions(+), 32 deletions(-)

diff --git a/arch/x86/pci/mmconfig-shared.c b/arch/x86/pci/mmconfig-shared.c
index 06da933..e9a791c 100644
--- a/arch/x86/pci/mmconfig-shared.c
+++ b/arch/x86/pci/mmconfig-shared.c
@@ -566,8 +566,6 @@ static void __init pci_mmcfg_reject_broken(int early)
        }
 }

-static int __initdata known_bridge;
-
 static int __init acpi_mcfg_check_entry(struct acpi_table_mcfg *mcfg,
                                        struct acpi_mcfg_allocation *cfg)
 {
@@ -647,25 +645,10 @@ static int __init pci_parse_mcfg(struct acpi_table_header *header)
        return 0;
 }

-static void __init __pci_mmcfg_init(int early)
-{
-       /* MMCONFIG disabled */
-       if ((pci_probe & PCI_PROBE_MMCONF) == 0)
-               return;
-
-       /* for late to exit */
-       if (known_bridge)
-               return;
-
-       /* MMCONFIG already enabled */
-       if (!early && !(pci_probe & PCI_PROBE_MASK & ~PCI_PROBE_MMCONF))
-               goto out;
-
-       if (early) {
-               if (pci_mmcfg_check_hostbridge())
-                       known_bridge = 1;
-       }
+static int __initdata known_bridge;

+static void __init __pci_mmcfg_init(int early, bool create_on_demand)
+{
        if (!known_bridge)
                acpi_sfi_table_parse(ACPI_SIG_MCFG, pci_parse_mcfg);

@@ -684,6 +667,13 @@ static void __init __pci_mmcfg_init(int early)
                }
        }

+       /*
+        * Avoid redundant pci_mmcfg_arch_map()/pci_mmcfg_arch_unmap() calls
+        * for each MMCONFIG entry if they will be created on demand.
+        */
+       if (create_on_demand)
+               free_all_mmcfg();
+
        if (pci_mmcfg_arch_init())
                pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF;
        else {
@@ -694,26 +684,44 @@ static void __init __pci_mmcfg_init(int early)
                pci_mmcfg_resources_inserted = 1;
                pci_mmcfg_arch_init_failed = true;
        }
-
-out:
-       /*
-        * Free all MCFG entries if ACPI is enabled. MCFG information will
-        * be added back on demand by the pci_root driver later.
-        */
-       if (!early && !acpi_disabled && !known_bridge &&
-           !pci_mmcfg_arch_init_failed)
-               if (!acpi_pci_cache_mcfg())
-                       free_all_mmcfg();
 }

 void __init pci_mmcfg_early_init(void)
 {
-       __pci_mmcfg_init(1);
+       if (pci_probe & PCI_PROBE_MMCONF) {
+               if (pci_mmcfg_check_hostbridge())
+                       known_bridge = 1;
+               __pci_mmcfg_init(1, false);
+       }
 }

 void __init pci_mmcfg_late_init(void)
 {
-       __pci_mmcfg_init(0);
+       bool create_on_demand;
+
+       /* MMCONFIG disabled */
+       if ((pci_probe & PCI_PROBE_MMCONF) == 0)
+               return;
+
+       /* Don't touch hardcoded MMCONFIG information */
+       if (known_bridge)
+               return;
+
+       /*
+        * MMCONFIG information will be created on demand by pci_root driver
+        * when binding to ACPI host bridge deivces.
+        */
+       create_on_demand = (!acpi_disabled && !acpi_pci_cache_mcfg());
+
+       /* pci_mmcfg_early_init() fails to setup MMCONFIG, try again. */
+       if (pci_probe & PCI_PROBE_MASK & ~PCI_PROBE_MMCONF)
+               __pci_mmcfg_init(0, create_on_demand);
+       /*
+        * Free MMCONFIG information created by pci_mmcfg_early_init()
+        * if MMCONFIG information will be created on demand.
+        */
+       else if (create_on_demand)
+               free_all_mmcfg();
 }

 static int __init pci_mmcfg_late_insert_resources(void)
--
1.7.1


On 2012-6-16 0:55, Yinghai Lu wrote:
> On Fri, Jun 15, 2012 at 8:46 AM, Bjorn Helgaas <bhelgaas@google.com> wrote:
>>
>>> But the code in the init path is ridiculously, embarrassingly complicated ...
>>
>> I rest my case.  The current init path is unmaintainable.
>>
>> I'll wait for a v8 (or later) with fixes for the build issues
>> Fengguang found and Yinghai's ack.  It will make things somewhat
>> easier for me if you start with my topic/jiang-mmconfig-v7 branch.
> 
> yes. probe/free then install is not good.
> 
> should make __pci_mmcfg_init() to cache needed stuff for all path, and
> then consume stored
> entry just before scan root bus.
> 
> Thanks
> 
> Yinghai
> 
> 



  reply	other threads:[~2012-06-16  8:58 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-26  9:53 [PATCH v7 00/10] PCI, x86: update MMCFG information when hot-plugging PCI host bridges Jiang Liu
2012-05-26  9:53 ` [PATCH v7 01/10] PCI, x86: split out pci_mmcfg_check_reserved() for code reuse Jiang Liu
2012-05-26  9:53 ` [PATCH v7 02/10] PCI, x86: split out pci_mmconfig_alloc() " Jiang Liu
2012-05-26  9:53 ` [PATCH v7 03/10] PCI, x86: use RCU list to protect mmconfig list Jiang Liu
2012-05-26  9:53 ` [PATCH v7 04/10] PCI, x86: introduce pci_mmcfg_arch_map()/pci_mmcfg_arch_unmap() Jiang Liu
2012-05-26  9:53 ` [PATCH v7 05/10] PCI, x86: introduce pci_mmconfig_insert()/delete() for PCI root bridge hotplug Jiang Liu
2012-05-26  9:53 ` [PATCH v7 06/10] PCI, ACPI: provide MCFG address for PCI host bridges Jiang Liu
2012-05-26  9:54 ` [PATCH v7 07/10] PCI, x86: update MMCFG information when hot-plugging " Jiang Liu
2012-05-26  9:54 ` [PATCH v7 08/10] PCI, x86: add MMCFG information on demand Jiang Liu
2012-06-15  7:15   ` Yinghai Lu
2012-06-15  8:13     ` Jiang Liu
2012-06-15 11:50     ` Jiang Liu
2012-06-15 16:51       ` Yinghai Lu
2012-06-16  9:23         ` Jiang Liu
2012-06-16 20:08           ` Yinghai Lu
2012-06-16 21:48             ` Bjorn Helgaas
2012-06-16 22:44               ` Yinghai Lu
2012-06-16 22:48                 ` Yinghai Lu
2012-06-17  1:55                 ` Bjorn Helgaas
2012-06-18  1:21                   ` Jiang Liu
2012-06-18 18:24                     ` Bjorn Helgaas
2012-06-15 15:46     ` Bjorn Helgaas
2012-06-15 16:34       ` Jiang Liu
2012-06-15 16:55       ` Yinghai Lu
2012-06-16  8:58         ` Jiang Liu [this message]
2012-05-26  9:54 ` [PATCH v7 09/10] PCI, x86: simplify pci_mmcfg_late_insert_resources() Jiang Liu
2012-05-26  9:54 ` [PATCH v7 10/10] PCI, x86: get rid of redundant log messages Jiang Liu
2012-06-05  2:59 ` [PATCH v7 00/10] PCI, x86: update MMCFG information when hot-plugging PCI host bridges Taku Izumi
2012-06-15  3:06 ` Bjorn Helgaas
2012-06-15  7:16   ` Yinghai Lu
2012-06-15 11:42   ` Jiang Liu

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-all 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=4FDC4AAC.8010601@huawei.com \
    --to=jiang.liu@huawei.com \
    --cc=bhelgaas@google.com \
    --cc=chenkeping@huawei.com \
    --cc=ddutile@redhat.com \
    --cc=izumi.taku@jp.fujitsu.com \
    --cc=kaneshige.kenji@jp.fujitsu.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=liuj97@gmail.com \
    --cc=wangyijing@huawei.com \
    --cc=yinghai@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).