Re: [PATCH 01/18] powerpc/pci: Add ppc_md.discover_phbs()

2021-02-10 Thread Michael Ellerman
On Tue, 3 Nov 2020 15:35:06 +1100, Oliver O'Halloran wrote:
> On many powerpc platforms the discovery and initalisation of
> pci_controllers (PHBs) happens inside of setup_arch(). This is very early
> in boot (pre-initcalls) and means that we're initialising the PHB long
> before many basic kernel services (slab allocator, debugfs, a real ioremap)
> are available.
> 
> On PowerNV this causes an additional problem since we map the PHB registers
> with ioremap(). As of commit d538aadc2718 ("powerpc/ioremap: warn on early
> use of ioremap()") a warning is printed because we're using the "incorrect"
> API to setup and MMIO mapping in searly boot. The kernel does provide
> early_ioremap(), but that is not intended to create long-lived MMIO
> mappings and a seperate warning is printed by generic code if
> early_ioremap() mappings are "leaked."
> 
> [...]

Applied to powerpc/next.

[01/18] powerpc/pci: Add ppc_md.discover_phbs()

https://git.kernel.org/powerpc/c/5537fcb319d016ce387f818dd774179bc03217f5
[02/18] powerpc/pci: Move PHB discovery for PCI_DN using platforms

https://git.kernel.org/powerpc/c/fbbefb320214db14c3e740fce98e2c95c9d0669b
[03/18] powerpc/maple: Move PHB discovery
(squashed into 2)
[04/18] powerpc/512x: Move PHB discovery

https://git.kernel.org/powerpc/c/893586ec949d3e48573a585c26bf04998fea6e1f
[05/18] powerpc/52xx/efika: Move PHB discovery

https://git.kernel.org/powerpc/c/eab3166f4eac384b48ebd2ed7b61dc465c1912cf
[06/18] powerpc/52xx/lite5200: Move PHB discovery

https://git.kernel.org/powerpc/c/e0bf9de2242a31a8f79015376ed08c4efe74774a
[07/18] powerpc/52xx/media5200: Move PHB discovery

https://git.kernel.org/powerpc/c/ba5087622a0f11c8d3c6587392ebc70f96503e51
[08/18] powerpc/52xx/mpc5200_simple: Move PHB discovery

https://git.kernel.org/powerpc/c/a760cfd9cfa2193961d7e599f46fbfe2498c400a
[09/18] powerpc/82xx/*: Move PHB discovery

https://git.kernel.org/powerpc/c/3c82a6aecd367bbbe7876c406cd3e12b5b0e4204
[10/18] powerpc/83xx: Move PHB discovery

https://git.kernel.org/powerpc/c/83f84041ff1cf6c23fc38861218af2d4ca2d9b38
[11/18] powerpc/amigaone: Move PHB discovery

https://git.kernel.org/powerpc/c/053d58c870298d62b9c5154672ef2f1684c4ea43
[12/18] powerpc/chrp: Move PHB discovery

https://git.kernel.org/powerpc/c/407d418f2fd4c20aa8ca1cf4168a414d77766852
[13/18] powerpc/embedded6xx/holly: Move PHB discovery

https://git.kernel.org/powerpc/c/08c4738254b87117c69816d8033dd25f38185f92
[14/18] powerpc/embedded6xx/linkstation: Move PHB discovery

https://git.kernel.org/powerpc/c/daa6c24780c15f4abcb76a9d426142beff9f62c6
[15/18] powerpc/embedded6xx/mpc7448: Move PHB discovery

https://git.kernel.org/powerpc/c/748770aeb44108ecb4e09d273e7718611cd60a98
[16/18] powerpc/embedded6xx/mve5100: Move PHB discovery

https://git.kernel.org/powerpc/c/d20a864f434b277b245ac6508920d90a48f6155d
[17/18] powerpc/pasemi: Move PHB discovery

https://git.kernel.org/powerpc/c/c144bc719234500e292c0545de99822bd8a78a6b
[18/18] powerpc/powermac: Move PHB discovery
(squashed into 2)

cheers


Re: [PATCH 01/18] powerpc/pci: Add ppc_md.discover_phbs()

2020-11-03 Thread kernel test robot
Hi Oliver,

I love your patch! Perhaps something to improve:

[auto build test WARNING on powerpc/next]
[also build test WARNING on v5.10-rc2 next-20201103]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:
https://github.com/0day-ci/linux/commits/Oliver-O-Halloran/powerpc-pci-Add-ppc_md-discover_phbs/20201103-130935
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc64-randconfig-r024-20201103 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 
1fcd5d5655e29f85e12b402e32974f207cfedf32)
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# install powerpc64 cross compiling tool for clang build
# apt-get install binutils-powerpc64-linux-gnu
# 
https://github.com/0day-ci/linux/commit/76dcfc8e7ec9ceaee251e156ffe07140bf1f1a5d
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Oliver-O-Halloran/powerpc-pci-Add-ppc_md-discover_phbs/20201103-130935
git checkout 76dcfc8e7ec9ceaee251e156ffe07140bf1f1a5d
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross 
ARCH=powerpc64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All warnings (new ones prefixed by >>):

>> arch/powerpc/kernel/pci-common.c:1630:12: warning: no previous prototype for 
>> function 'discover_phbs' [-Wmissing-prototypes]
   int __init discover_phbs(void)
  ^
   arch/powerpc/kernel/pci-common.c:1630:1: note: declare 'static' if the 
function is not intended to be used outside of this translation unit
   int __init discover_phbs(void)
   ^
   static 
   1 warning generated.

vim +/discover_phbs +1630 arch/powerpc/kernel/pci-common.c

  1628  
  1629  
> 1630  int __init discover_phbs(void)

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip


[PATCH 01/18] powerpc/pci: Add ppc_md.discover_phbs()

2020-11-02 Thread Oliver O'Halloran
On many powerpc platforms the discovery and initalisation of
pci_controllers (PHBs) happens inside of setup_arch(). This is very early
in boot (pre-initcalls) and means that we're initialising the PHB long
before many basic kernel services (slab allocator, debugfs, a real ioremap)
are available.

On PowerNV this causes an additional problem since we map the PHB registers
with ioremap(). As of commit d538aadc2718 ("powerpc/ioremap: warn on early
use of ioremap()") a warning is printed because we're using the "incorrect"
API to setup and MMIO mapping in searly boot. The kernel does provide
early_ioremap(), but that is not intended to create long-lived MMIO
mappings and a seperate warning is printed by generic code if
early_ioremap() mappings are "leaked."

This is all fixable with dumb hacks like using early_ioremap() to setup
the initial mapping then replacing it with a real ioremap later on in
boot, but it does raise the question: Why the hell are we setting up the
PHB's this early in boot?

The old and wise claim it's due to "hysterical rasins." Aside from amused
grapes there doesn't appear to be any real reason to maintain the current
behaviour. Already most of the newer embedded platforms perform PHB
discovery in an arch_initcall and between the end of setup_arch() and the
start of initcalls none of the generic kernel code does anything PCI
related. On powerpc scanning PHBs occurs in a subsys_initcall so it should
be possible to move the PHB discovery to a core, postcore or arch initcall.

This patch adds the ppc_md.discover_phbs hook and a core_initcall stub that
calls it. The core_initcalls are the earliest to be called so this will
any possibly issues with dependency between initcalls. This isn't just an
academic issue either since on pseries and PowerNV EEH init occurs in an
arch_initcall and depends on the pci_controllers being available, similarly
the creation of pci_dns occurs at core_initcall_sync (i.e. between core and
postcore initcalls). These problems need to be addressed seperately.

Cc: Paul Mackerras 
Cc: Christophe Leroy 
Signed-off-by: Oliver O'Halloran 
---
 arch/powerpc/include/asm/machdep.h |  3 +++
 arch/powerpc/kernel/pci-common.c   | 10 ++
 2 files changed, 13 insertions(+)

diff --git a/arch/powerpc/include/asm/machdep.h 
b/arch/powerpc/include/asm/machdep.h
index 475687f24f4a..d319160d790c 100644
--- a/arch/powerpc/include/asm/machdep.h
+++ b/arch/powerpc/include/asm/machdep.h
@@ -59,6 +59,9 @@ struct machdep_calls {
int (*pcibios_root_bridge_prepare)(struct pci_host_bridge
*bridge);
 
+   /* finds all the pci_controllers present at boot */
+   void(*discover_phbs)(void);
+
/* To setup PHBs when using automatic OF platform driver for PCI */
int (*pci_setup_phb)(struct pci_controller *host);
 
diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
index be108616a721..6265e7d1c697 100644
--- a/arch/powerpc/kernel/pci-common.c
+++ b/arch/powerpc/kernel/pci-common.c
@@ -1625,3 +1625,13 @@ static void fixup_hide_host_resource_fsl(struct pci_dev 
*dev)
 }
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MOTOROLA, PCI_ANY_ID, 
fixup_hide_host_resource_fsl);
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_FREESCALE, PCI_ANY_ID, 
fixup_hide_host_resource_fsl);
+
+
+int __init discover_phbs(void)
+{
+   if (ppc_md.discover_phbs)
+   ppc_md.discover_phbs();
+
+   return 0;
+}
+core_initcall(discover_phbs);
-- 
2.26.2



[RFC PATCH 01/18] powerpc/pci: Add ppc_md.discover_phbs()

2020-09-23 Thread Oliver O'Halloran
On many powerpc platforms the discovery and initalisation of
pci_controllers (PHBs) happens inside of setup_arch(). This is very early
in boot (pre-initcalls) and means that we're initialising the PHB long
before many basic kernel services (slab allocator, debugfs, a real ioremap)
are available.

On PowerNV this causes an additional problem since we map the PHB registers
with ioremap(). As of commit d538aadc2718 ("powerpc/ioremap: warn on early
use of ioremap()") a warning is printed because we're using the "incorrect"
API to setup and MMIO mapping in searly boot. The kernel does provide
early_ioremap(), but that is not intended to create long-lived MMIO
mappings and a seperate warning is printed by generic code if
early_ioremap() mappings are "leaked."

This is all fixable with dumb hacks like using early_ioremap() to setup
the initial mapping then replacing it with a real ioremap later on in
boot, but it does raise the question: Why the hell are we setting up the
PHB's this early in boot?

The old and wise claim it's due to "hysterical rasins." Aside from amused
grapes there doesn't appear to be any real reason to maintain the current
behaviour. Already most of the newer embedded platforms perform PHB
discovery in an arch_initcall and between the end of setup_arch() and the
start of initcalls none of the generic kernel code does anything PCI
related. On powerpc scanning PHBs occurs in a subsys_initcall so it should
be possible to move the PHB discovery to a core, postcore or arch initcall.

This patch adds the ppc_md.discover_phbs hook and a core_initcall stub that
calls it. The core_initcalls are the earliest to be called so this will
any possibly issues with dependency between initcalls. This isn't just an
academic issue either since on pseries and PowerNV EEH init occurs in an
arch_initcall and depends on the pci_controllers being available, similarly
the creation of pci_dns occurs at core_initcall_sync (i.e. between core and
postcore initcalls). These problems need to be addressed seperately.

Cc: Paul Mackerras 
Cc: Christophe Leroy 
Signed-off-by: Oliver O'Halloran 
---
 arch/powerpc/include/asm/machdep.h |  3 +++
 arch/powerpc/kernel/pci-common.c   | 10 ++
 2 files changed, 13 insertions(+)

diff --git a/arch/powerpc/include/asm/machdep.h 
b/arch/powerpc/include/asm/machdep.h
index a90b892f0bfe..b732dd5722aa 100644
--- a/arch/powerpc/include/asm/machdep.h
+++ b/arch/powerpc/include/asm/machdep.h
@@ -59,6 +59,9 @@ struct machdep_calls {
int (*pcibios_root_bridge_prepare)(struct pci_host_bridge
*bridge);
 
+   /* finds all the pci_controllers present at boot */
+   void(*discover_phbs)(void);
+
/* To setup PHBs when using automatic OF platform driver for PCI */
int (*pci_setup_phb)(struct pci_controller *host);
 
diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
index be108616a721..6265e7d1c697 100644
--- a/arch/powerpc/kernel/pci-common.c
+++ b/arch/powerpc/kernel/pci-common.c
@@ -1625,3 +1625,13 @@ static void fixup_hide_host_resource_fsl(struct pci_dev 
*dev)
 }
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MOTOROLA, PCI_ANY_ID, 
fixup_hide_host_resource_fsl);
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_FREESCALE, PCI_ANY_ID, 
fixup_hide_host_resource_fsl);
+
+
+int __init discover_phbs(void)
+{
+   if (ppc_md.discover_phbs)
+   ppc_md.discover_phbs();
+
+   return 0;
+}
+core_initcall(discover_phbs);
-- 
2.26.2