Skip to contentSkip to conversation

dm: pci: Support selected device/driver binding before relocation

PATCH Superseded Bin Meng 2 participants 27 messages Aug 15, 2015 – Aug 18, 2015

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH 1/8 dm: pci: Support selected device/driver binding before relocation

On some platforms pci devices behind bridge need to be probed (eg:
a pci uart on recent x86 chipset) before relocation. But we won't bind all devices found during the enumeration. Only devices whose driver with DM_FLAG_PRE_RELOC set will be bound. Any other generic devices except bridges won't be bound.

---

 drivers/pci/pci-uclass.c | 41 ++++++++++++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 11 deletions(-)
drivers/pci/pci-uclass.c +30 -11
index 7d41d56..4160274 100644
@@ -461,6 +461,7 @@ static int pci_find_and_bind_driver(struct udevice *parent,
 	int n_ents;
 	int ret;
 	char name[30], *str;
+	bool bridge;
 
 	*devp = NULL;
 
@@ -480,6 +481,17 @@ static int pci_find_and_bind_driver(struct udevice *parent,
 				continue;
 
 			drv = entry->driver;
+
+			/*
+			 * In the pre-relocation phase, we only bind devices
+			 * whose driver has the DM_FLAG_PRE_RELOC set, to save
+			 * precious memory space as on some platforms as that
+			 * space is pretty limited (ie: using Cache As RAM).
+			 */
+			if (!(gd->flags & GD_FLG_RELOC) &&
+			    !(drv->flags & DM_FLAG_PRE_RELOC))
+				return 0;
+
 			/*
 			 * We could pass the descriptor to the driver as
 			 * platdata (instead of NULL) and allow its bind()
@@ -499,14 +511,23 @@ static int pci_find_and_bind_driver(struct udevice *parent,
 		}
 	}
 
+	bridge = (find_id->class >> 8) == PCI_CLASS_BRIDGE_PCI;
+	/*
+	 * In the pre-relocation phase, we only bind bridge devices to save
+	 * precious memory space as on some platforms as that space is pretty
+	 * limited (ie: using Cache As RAM).
+	 */
+	if (!(gd->flags & GD_FLG_RELOC) && !bridge)
+		return 0;
+
 	/* Bind a generic driver so that the device can be used */
 	sprintf(name, "pci_%x:%x.%x", parent->seq, PCI_DEV(bdf),
 		PCI_FUNC(bdf));
 	str = strdup(name);
 	if (!str)
 		return -ENOMEM;
-	drv = (find_id->class >> 8) == PCI_CLASS_BRIDGE_PCI ? "pci_bridge_drv" :
-			"pci_generic_drv";
+	drv = bridge ? "pci_bridge_drv" : "pci_generic_drv";
+
 	ret = device_bind_driver(parent, drv, str, devp);
 	if (ret) {
 		debug("%s: Failed to bind generic driver: %d", __func__, ret);
@@ -589,11 +610,13 @@ int pci_bind_bus_devices(struct udevice *bus)
 			return ret;
 
 		/* Update the platform data */
-		pplat = dev_get_parent_platdata(dev);
-		pplat->devfn = PCI_MASK_BUS(bdf);
-		pplat->vendor = vendor;
-		pplat->device = device;
-		pplat->class = class;
+		if (dev) {
+			pplat = dev_get_parent_platdata(dev);
+			pplat->devfn = PCI_MASK_BUS(bdf);
+			pplat->vendor = vendor;
+			pplat->device = device;
+			pplat->class = class;
+		}
 	}
 
 	return 0;
@@ -717,10 +740,6 @@ static int pci_uclass_post_probe(struct udevice *bus)
 {
 	int ret;
 
-	/* Don't scan buses before relocation */
-	if (!(gd->flags & GD_FLG_RELOC))
-		return 0;
-
 	debug("%s: probing bus %d\n", __func__, bus->seq);
 	ret = pci_bind_bus_devices(bus);
 	if (ret)
Signature · 1 line
1.8.2.1
author
#1 lore raw

PATCH 2/8 dm: pci: Only allow serial device to be bound before relocation

To further limit the memory space, we only allow serial device to be bound before relocation.

---

 drivers/pci/pci-uclass.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pci/pci-uclass.c +5 -1
index 4160274..b7dca0f 100644
@@ -487,9 +487,13 @@ static int pci_find_and_bind_driver(struct udevice *parent,
 			 * whose driver has the DM_FLAG_PRE_RELOC set, to save
 			 * precious memory space as on some platforms as that
 			 * space is pretty limited (ie: using Cache As RAM).
+			 *
+			 * To further limit the memory space, we only allow
+			 * serial device to be bound.
 			 */
 			if (!(gd->flags & GD_FLG_RELOC) &&
-			    !(drv->flags & DM_FLAG_PRE_RELOC))
+			    !(drv->flags & DM_FLAG_PRE_RELOC) &&
+			    (drv->id != UCLASS_SERIAL))
 				return 0;
 
 			/*
Signature · 1 line
1.8.2.1
author
#6 lore raw

PATCH 3/8 x86: fsp: Delay x86_fsp_init() call a little bit

In reply to Bin Meng

Move x86_fsp_init() call after initf_malloc() so that we can fix up the gd->malloc_limit later.

---

 common/board_f.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
common/board_f.c +3 -3
index c959774..5155013 100644
@@ -765,9 +765,6 @@ static init_fnc_t init_sequence_f[] = {
 #ifdef CONFIG_OF_CONTROL
 	fdtdec_setup,
 #endif
-#if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP)
-	x86_fsp_init,
-#endif
 #ifdef CONFIG_TRACE
 	trace_early_init,
 #endif
@@ -776,6 +773,9 @@ static init_fnc_t init_sequence_f[] = {
 	/* TODO: can this go into arch_cpu_init()? */
 	probecpu,
 #endif
+#if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP)
+	x86_fsp_init,
+#endif
 	arch_cpu_init,		/* basic arch cpu dependent setup */
 	mark_bootstage,
 	initf_dm,
Signature · 1 line
1.8.2.1
author
#8 lore raw

PATCH 4/8 x86: fsp: Enlarge the size of malloc() pool before relocation

In reply to Bin Meng

After fsp_init() returns, the stack has already been switched to a place within system memory as defined by CONFIG_FSP_TEMP_RAM_ADDR. Enlarge the size of malloc() pool before relocation since we have plenty of memory now.

---

 arch/x86/Kconfig              | 7 +++++++
 arch/x86/cpu/start.S          | 8 ++++++++
 arch/x86/lib/fsp/fsp_common.c | 6 +++++-
 3 files changed, 20 insertions(+), 1 deletion(-)
arch/x86/Kconfig +7 -0
index 065bbe4..687208f 100644
@@ -232,6 +232,13 @@ config FSP_TEMP_RAM_ADDR
 	  Stack top address which is used in FspInit after DRAM is ready and
 	  CAR is disabled.
 
+config FSP_SYS_MALLOC_F_LEN
+	hex
+	depends on HAVE_FSP
+	default 0x100000
+	help
+	  Additional size of malloc() pool before relocation.
+
 config SMP
 	bool "Enable Symmetric Multiprocessing"
 	default n
arch/x86/cpu/start.S +8 -0
index e94ddc4..e2b5ef4 100644
@@ -141,6 +141,14 @@ car_init_ret:
 	jz	skip_hob
 	movl	%esi, GD_HOB_LIST(%edx)
 
+	/*
+	 * After fsp_init() returns, the stack has already been switched to a
+	 * place within system memory as defined by CONFIG_FSP_TEMP_RAM_ADDR.
+	 * Enlarge the size of malloc() pool before relocation since we have
+	 * plenty of memory now.
+	 */
+	subl	$CONFIG_FSP_SYS_MALLOC_F_LEN, %esp
+	movl	%esp, GD_MALLOC_BASE(%edx)
 skip_hob:
 #else
 	/* Store table pointer */
arch/x86/lib/fsp/fsp_common.c +5 -1
index 6f72c6d..9c316d4 100644
@@ -56,8 +56,12 @@ void board_final_cleanup(void)
 
 int x86_fsp_init(void)
 {
-	if (!gd->arch.hob_list)
+	if (!gd->arch.hob_list) {
 		fsp_init(CONFIG_FSP_TEMP_RAM_ADDR, BOOT_FULL_CONFIG, NULL);
+	} else {
+		/* We should adjust gd->malloc_limit here */
+		gd->malloc_limit += CONFIG_FSP_SYS_MALLOC_F_LEN;
+	}
 
 	return 0;
 }
Signature · 1 line
1.8.2.1
author
#13 lore raw

PATCH 5/8 drivers: serial: Add ns16550 compatible pci uart driver

In reply to Bin Meng

This adds a new driver to support National Semiconductor 16550 compatible UART device with PCI interface. The initial support only adds device IDs for Intel Topcliff chipset UART devices.

---

 drivers/serial/Kconfig      |  9 ++++++
 drivers/serial/Makefile     |  1 +
 drivers/serial/serial_pci.c | 75 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+)
 create mode 100644 drivers/serial/serial_pci.c
drivers/serial/Kconfig +9 -0
index fd126a8..f2eccdd 100644
@@ -128,3 +128,12 @@ config X86_SERIAL
 	  enabled in the device tree with the correct input clock frequency
 	  provided (default 1843200). Enable this to obtain serial console
 	  output.
+
+config PCI_SERIAL
+	bool "Support for 16550 serial port on PCI bus"
+	depends on DM_PCI
+	default n
+	help
+	  This is the UART driver for ns16550 compatible chipset with PCI
+	  interface. This can be enabled in the device tree with the correct
+	  properties provided. If unsure, say N.
drivers/serial/Makefile +1 -0
index 1d1f036..a7e2cd2 100644
@@ -45,6 +45,7 @@ obj-$(CONFIG_TEGRA_SERIAL) += serial_tegra.o
 obj-$(CONFIG_UNIPHIER_SERIAL) += serial_uniphier.o
 obj-$(CONFIG_OMAP_SERIAL) += serial_omap.o
 obj-$(CONFIG_X86_SERIAL) += serial_x86.o
+obj-$(CONFIG_PCI_SERIAL) += serial_pci.o
 obj-$(CONFIG_STM32_SERIAL) += serial_stm32.o
 
 ifndef CONFIG_SPL_BUILD
drivers/serial/serial_pci.c new file +75 -0

75 lines not on this page · raw message

Signature · 1 line
1.8.2.1
author
#20 lore raw

PATCH 6/8 drivers: serial: Remove special handling for pci uart in the ns16550 driver

In reply to Bin Meng

Now we have a dedicated PCI UART driver, remove previous special handling for PCI UART in the ns16550 driver.

---

 drivers/serial/ns16550.c | 31 -------------------------------
 1 file changed, 31 deletions(-)
drivers/serial/ns16550.c +0 -31
index c8a77e2..8a5db49 100644
@@ -363,38 +363,7 @@ int ns16550_serial_ofdata_to_platdata(struct udevice *dev)
 	struct ns16550_platdata *plat = dev->platdata;
 	fdt_addr_t addr;
 
-	/* try Processor Local Bus device first */
 	addr = fdtdec_get_addr(gd->fdt_blob, dev->of_offset, "reg");
-#ifdef CONFIG_PCI
-	if (addr == FDT_ADDR_T_NONE) {
-		/* then try pci device */
-		struct fdt_pci_addr pci_addr;
-		u32 bar;
-		int ret;
-
-		/* we prefer to use a memory-mapped register */
-		ret = fdtdec_get_pci_addr(gd->fdt_blob, dev->of_offset,
-					  FDT_PCI_SPACE_MEM32, "reg",
-					  &pci_addr);
-		if (ret) {
-			/* try if there is any i/o-mapped register */
-			ret = fdtdec_get_pci_addr(gd->fdt_blob,
-						  dev->of_offset,
-						  FDT_PCI_SPACE_IO,
-						  "reg", &pci_addr);
-			if (ret)
-				return ret;
-		}
-
-		ret = fdtdec_get_pci_bar32(gd->fdt_blob, dev->of_offset,
-					   &pci_addr, &bar);
-		if (ret)
-			return ret;
-
-		addr = bar;
-	}
-#endif
-
 	if (addr == FDT_ADDR_T_NONE)
 		return -EINVAL;
 
Signature · 1 line
1.8.2.1
author
#21 lore raw

PATCH 7/8 x86: crownbay: Support Topcliff integrated pci uart devices

In reply to Bin Meng

Use new PCI_SERIAL driver to support Topcliff integrated pci uart devices on Intel Crown Bay board.

---

 arch/x86/dts/crownbay.dts  | 8 ++++----
 configs/crownbay_defconfig | 1 +
 2 files changed, 5 insertions(+), 4 deletions(-)
arch/x86/dts/crownbay.dts +4 -4
index 3af9cc3..841f47e 100644
@@ -114,7 +114,7 @@
 							"pci8086,8811",
 							"pciclass,070002",
 							"pciclass,0700",
-							"x86-uart";
+							"pci-uart";
 					reg = <0x00025100 0x0 0x0 0x0 0x0
 					       0x01025110 0x0 0x0 0x0 0x0>;
 					reg-shift = <0>;
@@ -127,7 +127,7 @@
 							"pci8086,8812",
 							"pciclass,070002",
 							"pciclass,0700",
-							"x86-uart";
+							"pci-uart";
 					reg = <0x00025200 0x0 0x0 0x0 0x0
 					       0x01025210 0x0 0x0 0x0 0x0>;
 					reg-shift = <0>;
@@ -140,7 +140,7 @@
 							"pci8086,8813",
 							"pciclass,070002",
 							"pciclass,0700",
-							"x86-uart";
+							"pci-uart";
 					reg = <0x00025300 0x0 0x0 0x0 0x0
 					       0x01025310 0x0 0x0 0x0 0x0>;
 					reg-shift = <0>;
@@ -153,7 +153,7 @@
 							"pci8086,8814",
 							"pciclass,070002",
 							"pciclass,0700",
-							"x86-uart";
+							"pci-uart";
 					reg = <0x00025400 0x0 0x0 0x0 0x0
 					       0x01025410 0x0 0x0 0x0 0x0>;
 					reg-shift = <0>;
configs/crownbay_defconfig +1 -0
index aa1232d..9113eb7 100644
@@ -19,6 +19,7 @@ CONFIG_OF_CONTROL=y
 CONFIG_CPU=y
 CONFIG_DM_PCI=y
 CONFIG_SPI_FLASH=y
+CONFIG_PCI_SERIAL=y
 CONFIG_VIDEO_VESA=y
 CONFIG_FRAMEBUFFER_SET_VESA_MODE=y
 CONFIG_DM_RTC=y
Signature · 1 line
1.8.2.1
author
#22 lore raw

PATCH 8/8 x86: queensbay: Call fsp_init_phase_pci() again

In reply to Bin Meng

With driver model pci conversion, the call to FspNotify was dropped. Now add this call back as this is required by the FSP spec.

---

 arch/x86/cpu/queensbay/tnc.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
arch/x86/cpu/queensbay/tnc.c +7 -1
index c465642..11f65ad 100644
@@ -80,5 +80,11 @@ void cpu_irq_init(void)
 
 int arch_misc_init(void)
 {
-	return pirq_init();
+	int ret;
+
+	ret =  pirq_init();
+	if (ret)
+		return ret;
+
+	return fsp_init_phase_pci();
 }
Signature · 1 line
1.8.2.1
author
#14 lore raw

PATCH 5/8 drivers: serial: Add ns16550 compatible pci uart driver

In reply to Bin Meng

Hi Simon,

Quoted 114 lines · Bin Meng

This adds a new driver to support National Semiconductor 16550 compatible UART device with PCI interface. The initial support only adds device IDs for Intel Topcliff chipset UART devices.

---

 drivers/serial/Kconfig      |  9 ++++++
 drivers/serial/Makefile     |  1 +
 drivers/serial/serial_pci.c | 75 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+)
 create mode 100644 drivers/serial/serial_pci.c
drivers/serial/Kconfig +9 -0
index fd126a8..f2eccdd 100644
@@ -128,3 +128,12 @@ config X86_SERIAL
          enabled in the device tree with the correct input clock frequency
          provided (default 1843200). Enable this to obtain serial console
          output.
+
+config PCI_SERIAL
+       bool "Support for 16550 serial port on PCI bus"
+       depends on DM_PCI
+       default n
+       help
+         This is the UART driver for ns16550 compatible chipset with PCI
+         interface. This can be enabled in the device tree with the correct
+         properties provided. If unsure, say N.
drivers/serial/Makefile +1 -0
index 1d1f036..a7e2cd2 100644
@@ -45,6 +45,7 @@ obj-$(CONFIG_TEGRA_SERIAL) += serial_tegra.o
 obj-$(CONFIG_UNIPHIER_SERIAL) += serial_uniphier.o
 obj-$(CONFIG_OMAP_SERIAL) += serial_omap.o
 obj-$(CONFIG_X86_SERIAL) += serial_x86.o
+obj-$(CONFIG_PCI_SERIAL) += serial_pci.o
 obj-$(CONFIG_STM32_SERIAL) += serial_stm32.o
 
 ifndef CONFIG_SPL_BUILD
drivers/serial/serial_pci.c new file +66 -0
new file mode 100644
index 0000000..bc87c9a
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2015, Bin Meng <[email protected]>
+ *
+ * This driver aims to support National Semiconductor 16550 compatible
+ * UART device with PCI interface.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <fdtdec.h>
+#include <ns16550.h>
+#include <serial.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static struct pci_device_id supported[] = {
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_0) },
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_1) },
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_2) },
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_3) },
+       {}
+};
+
+static const struct udevice_id pci_serial_ids[] = {
+       { .compatible = "pci-uart" },
+       { }
+};
+
+static int pci_serial_ofdata_to_platdata(struct udevice *dev)
+{
+       struct ns16550_platdata *plat = dev_get_platdata(dev);
+       struct fdt_pci_addr pci_addr;
+       u32 bar;
+       int ret;
+
+       /* we prefer to use a memory-mapped register */
+       ret = fdtdec_get_pci_addr(gd->fdt_blob, dev->of_offset,
+                                 FDT_PCI_SPACE_MEM32, "reg", &pci_addr);
+       if (ret) {
+               /* try if there is any i/o-mapped register */
+               ret = fdtdec_get_pci_addr(gd->fdt_blob, dev->of_offset,
+                                         FDT_PCI_SPACE_IO, "reg", &pci_addr);
+               if (ret)
+                       return ret;
+       }
+
+       ret = fdtdec_get_pci_bar32(gd->fdt_blob, dev->of_offset,
+                                  &pci_addr, &bar);
+       if (ret)
+               return ret;
+
+       plat->base = bar;
+       plat->reg_shift = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+                                        "reg-shift", 1);
+       plat->clock = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+                                    "clock-frequency", 1843200);
+
+       return 0;
+}
+
+U_BOOT_DRIVER(serial_pci) = {
+       .name = "serial_pci",
+       .id = UCLASS_SERIAL,
+       .of_match = pci_serial_ids,

drivers/serial/serial_pci.c

Quoted 10 lines
drivers/serial/serial_pci.c new file +9 -1
+       .ofdata_to_platdata = pci_serial_ofdata_to_platdata,
+       .platdata_auto_alloc_size = sizeof(struct ns16550_platdata),
+       .priv_auto_alloc_size = sizeof(struct NS16550),
+       .probe = ns16550_serial_probe,
+       .ops = &ns16550_serial_ops,
+       .flags = DM_FLAG_PRE_RELOC,
+};
+
+U_BOOT_PCI_DEVICE(serial_pci, supported);
--

Just found that this patch needs to be rebased on latest u-boot-x86/master in order to apply cleanly. Will send v2 after the review.

Regards,
Bin

author
#23 lore raw

PATCH 8/8 x86: queensbay: Call fsp_init_phase_pci() again

In reply to Bin Meng

Hi Simon,

Quoted 17 lines · Bin Meng

With driver model pci conversion, the call to FspNotify was dropped. Now add this call back as this is required by the FSP spec.

---

 arch/x86/cpu/queensbay/tnc.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
arch/x86/cpu/queensbay/tnc.c +0 -0
index c465642..11f65ad 100644
@@ -80,5 +80,11 @@ void cpu_irq_init(void)
 
 int arch_misc_init(void)
 {

arch/x86/cpu/queensbay/tnc.c void cpu_irq_init(void)

Quoted 10 lines
arch/x86/cpu/queensbay/tnc.c +7 -2
-       return pirq_init();
+       int ret;
+
+       ret =  pirq_init();
+       if (ret)
+               return ret;
+
+       return fsp_init_phase_pci();
 }
--

Unfortunately, this change breaks video graphics console on Intel Crown Bay. I was not testing graphics (leave the LVDS interface open) when I submitted this series. But when I got my LVDS panel connected (during my attempt to support the PS/2 keyboard), the screen is just a mess with funny colors. I've git bisected and confirmed this very last commit breaks the video.

So, this test result is now supporting my previous worry, that we should call FspNotify() immediately after PCI enumeration, before any device driver touch PCI devices. This is what the FSP spec tells us and we used to do this correctly before dm pci conversion. This issue is unfortunately exposed by driver model PCI. With driver model, when PCI bus gets enumerated is unknown to us. On Crown Bay, this happens in initr_mmc() in board_r.c where MMC driver gets initialized. Then vesa video driver runs the vbios and finally followed by arch_misc_init() which calls FspNotify() and messes up the screen.

I moved the call to fsp_init_phase_pci() from arch_misc_init() to the place in initr_mmc() that immediately follows mmc_initialize(), which means call the FspNotify() as soon as PCI bus is enumerated. With this change, video (graphics console) is working again. So during the FspNotify() phase, FSP must have done something (eg: programming some graphics hardware registers) and that unfortunately breaks the things.

I cannot find a good place in the generic dm pci driver to insert such a call. So maybe we should just explicitly trigger the PCI bus enumeration at least when CONFIG_HAVE_FSP. What do you think?

Regards,
Bin

#15 lore raw

PATCH 5/8 drivers: serial: Add ns16550 compatible pci uart driver

In reply to Bin Meng

Hi Bin,

Quoted 60 lines · Bin Meng

This adds a new driver to support National Semiconductor 16550 compatible UART device with PCI interface. The initial support only adds device IDs for Intel Topcliff chipset UART devices.

---

 drivers/serial/Kconfig      |  9 ++++++
 drivers/serial/Makefile     |  1 +
 drivers/serial/serial_pci.c | 75 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+)
 create mode 100644 drivers/serial/serial_pci.c
drivers/serial/Kconfig +9 -0
index fd126a8..f2eccdd 100644
@@ -128,3 +128,12 @@ config X86_SERIAL
          enabled in the device tree with the correct input clock frequency
          provided (default 1843200). Enable this to obtain serial console
          output.
+
+config PCI_SERIAL
+       bool "Support for 16550 serial port on PCI bus"
+       depends on DM_PCI
+       default n
+       help
+         This is the UART driver for ns16550 compatible chipset with PCI
+         interface. This can be enabled in the device tree with the correct
+         properties provided. If unsure, say N.
drivers/serial/Makefile +1 -0
index 1d1f036..a7e2cd2 100644
@@ -45,6 +45,7 @@ obj-$(CONFIG_TEGRA_SERIAL) += serial_tegra.o
 obj-$(CONFIG_UNIPHIER_SERIAL) += serial_uniphier.o
 obj-$(CONFIG_OMAP_SERIAL) += serial_omap.o
 obj-$(CONFIG_X86_SERIAL) += serial_x86.o
+obj-$(CONFIG_PCI_SERIAL) += serial_pci.o
 obj-$(CONFIG_STM32_SERIAL) += serial_stm32.o
 
 ifndef CONFIG_SPL_BUILD
drivers/serial/serial_pci.c new file +12 -0
new file mode 100644
index 0000000..bc87c9a
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2015, Bin Meng <[email protected]>
+ *
+ * This driver aims to support National Semiconductor 16550 compatible
+ * UART device with PCI interface.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <fdtdec.h>

drivers/serial/serial_pci.c line 22

Quoted 10 lines
drivers/serial/serial_pci.c new file +10 -0
+#include <ns16550.h>
+#include <serial.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static struct pci_device_id supported[] = {
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_0) },
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_1) },
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_2) },
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_3) },

Ick, did I miss the discussion on this? I really want us to keep this stuff in the device tree.

Quoted 54 lines
drivers/serial/serial_pci.c new file +53 -1
+       {}
+};
+
+static const struct udevice_id pci_serial_ids[] = {
+       { .compatible = "pci-uart" },
+       { }
+};
+
+static int pci_serial_ofdata_to_platdata(struct udevice *dev)
+{
+       struct ns16550_platdata *plat = dev_get_platdata(dev);
+       struct fdt_pci_addr pci_addr;
+       u32 bar;
+       int ret;
+
+       /* we prefer to use a memory-mapped register */
+       ret = fdtdec_get_pci_addr(gd->fdt_blob, dev->of_offset,
+                                 FDT_PCI_SPACE_MEM32, "reg", &pci_addr);
+       if (ret) {
+               /* try if there is any i/o-mapped register */
+               ret = fdtdec_get_pci_addr(gd->fdt_blob, dev->of_offset,
+                                         FDT_PCI_SPACE_IO, "reg", &pci_addr);
+               if (ret)
+                       return ret;
+       }
+
+       ret = fdtdec_get_pci_bar32(gd->fdt_blob, dev->of_offset,
+                                  &pci_addr, &bar);
+       if (ret)
+               return ret;
+
+       plat->base = bar;
+       plat->reg_shift = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+                                        "reg-shift", 1);
+       plat->clock = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+                                    "clock-frequency", 1843200);
+
+       return 0;
+}
+
+U_BOOT_DRIVER(serial_pci) = {
+       .name = "serial_pci",
+       .id = UCLASS_SERIAL,
+       .of_match = pci_serial_ids,
+       .ofdata_to_platdata = pci_serial_ofdata_to_platdata,
+       .platdata_auto_alloc_size = sizeof(struct ns16550_platdata),
+       .priv_auto_alloc_size = sizeof(struct NS16550),
+       .probe = ns16550_serial_probe,
+       .ops = &ns16550_serial_ops,
+       .flags = DM_FLAG_PRE_RELOC,
+};
+
+U_BOOT_PCI_DEVICE(serial_pci, supported);
--
Quoted 2 lines

1.8.2.1

Regards,
Simon

author
#16 lore raw

PATCH 5/8 drivers: serial: Add ns16550 compatible pci uart driver

Hi Simon,

Quoted 68 lines · Simon Glass

Hi Bin,

Quoted 65 lines · Bin Meng

This adds a new driver to support National Semiconductor 16550 compatible UART device with PCI interface. The initial support only adds device IDs for Intel Topcliff chipset UART devices.

---

 drivers/serial/Kconfig      |  9 ++++++
 drivers/serial/Makefile     |  1 +
 drivers/serial/serial_pci.c | 75 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+)
 create mode 100644 drivers/serial/serial_pci.c
drivers/serial/Kconfig +9 -0
index fd126a8..f2eccdd 100644
@@ -128,3 +128,12 @@ config X86_SERIAL
          enabled in the device tree with the correct input clock frequency
          provided (default 1843200). Enable this to obtain serial console
          output.
+
+config PCI_SERIAL
+       bool "Support for 16550 serial port on PCI bus"
+       depends on DM_PCI
+       default n
+       help
+         This is the UART driver for ns16550 compatible chipset with PCI
+         interface. This can be enabled in the device tree with the correct
+         properties provided. If unsure, say N.
drivers/serial/Makefile +1 -0
index 1d1f036..a7e2cd2 100644
@@ -45,6 +45,7 @@ obj-$(CONFIG_TEGRA_SERIAL) += serial_tegra.o
 obj-$(CONFIG_UNIPHIER_SERIAL) += serial_uniphier.o
 obj-$(CONFIG_OMAP_SERIAL) += serial_omap.o
 obj-$(CONFIG_X86_SERIAL) += serial_x86.o
+obj-$(CONFIG_PCI_SERIAL) += serial_pci.o
 obj-$(CONFIG_STM32_SERIAL) += serial_stm32.o
 
 ifndef CONFIG_SPL_BUILD
drivers/serial/serial_pci.c new file +17 -0
new file mode 100644
index 0000000..bc87c9a
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2015, Bin Meng <[email protected]>
+ *
+ * This driver aims to support National Semiconductor 16550 compatible
+ * UART device with PCI interface.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <fdtdec.h>
+#include <ns16550.h>
+#include <serial.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
Quoted 9 lines

drivers/serial/serial_pci.c line 22

Quoted 5 lines
drivers/serial/serial_pci.c new file +5 -0
+static struct pci_device_id supported[] = {
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_0) },
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_1) },
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_2) },
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_3) },

Ick, did I miss the discussion on this? I really want us to keep this stuff in the device tree.

I don't think you missed any discussion. But I think you might misread this code? Do you mean there is no need to declare what devices are supported by this driver using U_BOOT_PCI_DEVICE?

Quoted 46 lines
Quoted 46 lines
drivers/serial/serial_pci.c new file +46 -0
+       {}
+};
+
+static const struct udevice_id pci_serial_ids[] = {
+       { .compatible = "pci-uart" },
+       { }
+};
+
+static int pci_serial_ofdata_to_platdata(struct udevice *dev)
+{
+       struct ns16550_platdata *plat = dev_get_platdata(dev);
+       struct fdt_pci_addr pci_addr;
+       u32 bar;
+       int ret;
+
+       /* we prefer to use a memory-mapped register */
+       ret = fdtdec_get_pci_addr(gd->fdt_blob, dev->of_offset,
+                                 FDT_PCI_SPACE_MEM32, "reg", &pci_addr);
+       if (ret) {
+               /* try if there is any i/o-mapped register */
+               ret = fdtdec_get_pci_addr(gd->fdt_blob, dev->of_offset,
+                                         FDT_PCI_SPACE_IO, "reg", &pci_addr);
+               if (ret)
+                       return ret;
+       }
+
+       ret = fdtdec_get_pci_bar32(gd->fdt_blob, dev->of_offset,
+                                  &pci_addr, &bar);
+       if (ret)
+               return ret;
+
+       plat->base = bar;
+       plat->reg_shift = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+                                        "reg-shift", 1);
+       plat->clock = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+                                    "clock-frequency", 1843200);
+
+       return 0;
+}
+
+U_BOOT_DRIVER(serial_pci) = {
+       .name = "serial_pci",
+       .id = UCLASS_SERIAL,
+       .of_match = pci_serial_ids,
+       .ofdata_to_platdata = pci_serial_ofdata_to_platdata,
+       .platdata_auto_alloc_size = sizeof(struct ns16550_platdata),
Quoted 8 lines

drivers/serial/serial_pci.c

Quoted 8 lines
drivers/serial/serial_pci.c new file +7 -1
+       .priv_auto_alloc_size = sizeof(struct NS16550),
+       .probe = ns16550_serial_probe,
+       .ops = &ns16550_serial_ops,
+       .flags = DM_FLAG_PRE_RELOC,
+};
+
+U_BOOT_PCI_DEVICE(serial_pci, supported);
--

Regards,
Bin

#24 lore raw

PATCH 8/8 x86: queensbay: Call fsp_init_phase_pci() again

In reply to Bin Meng

Hi Bin,

Quoted 55 lines · Bin Meng

Hi Simon,

Quoted 17 lines · Bin Meng

With driver model pci conversion, the call to FspNotify was dropped. Now add this call back as this is required by the FSP spec.

---

 arch/x86/cpu/queensbay/tnc.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
arch/x86/cpu/queensbay/tnc.c +0 -0
index c465642..11f65ad 100644
@@ -80,5 +80,11 @@ void cpu_irq_init(void)
 
 int arch_misc_init(void)
 {

arch/x86/cpu/queensbay/tnc.c void cpu_irq_init(void)

Quoted 10 lines
arch/x86/cpu/queensbay/tnc.c +7 -2
-       return pirq_init();
+       int ret;
+
+       ret =  pirq_init();
+       if (ret)
+               return ret;
+
+       return fsp_init_phase_pci();
 }
--

Unfortunately, this change breaks video graphics console on Intel Crown Bay. I was not testing graphics (leave the LVDS interface open) when I submitted this series. But when I got my LVDS panel connected (during my attempt to support the PS/2 keyboard), the screen is just a mess with funny colors. I've git bisected and confirmed this very last commit breaks the video.

So, this test result is now supporting my previous worry, that we should call FspNotify() immediately after PCI enumeration, before any device driver touch PCI devices. This is what the FSP spec tells us and we used to do this correctly before dm pci conversion. This issue is unfortunately exposed by driver model PCI. With driver model, when PCI bus gets enumerated is unknown to us. On Crown Bay, this happens in initr_mmc() in board_r.c where MMC driver gets initialized. Then vesa video driver runs the vbios and finally followed by arch_misc_init() which calls FspNotify() and messes up the screen.

I moved the call to fsp_init_phase_pci() from arch_misc_init() to the place in initr_mmc() that immediately follows mmc_initialize(), which means call the FspNotify() as soon as PCI bus is enumerated. With this change, video (graphics console) is working again. So during the FspNotify() phase, FSP must have done something (eg: programming some graphics hardware registers) and that unfortunately breaks the things.

Quoted 3 lines

I cannot find a good place in the generic dm pci driver to insert such a call. So maybe we should just explicitly trigger the PCI bus enumeration at least when CONFIG_HAVE_FSP. What do you think?

An ugly option would be to add the call to pci_uclass_post_probe().

No I don't think we should force enumeration.

Regards,
Simon

#26 lore raw

PATCH 1/8 dm: pci: Support selected device/driver binding before relocation

In reply to Bin Meng
Quoted 11 lines · Bin Meng

On some platforms pci devices behind bridge need to be probed (eg:
a pci uart on recent x86 chipset) before relocation. But we won't bind all devices found during the enumeration. Only devices whose driver with DM_FLAG_PRE_RELOC set will be bound. Any other generic devices except bridges won't be bound.

---

 drivers/pci/pci-uclass.c | 41 ++++++++++++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 11 deletions(-)
#2 lore raw

PATCH 2/8 dm: pci: Only allow serial device to be bound before relocation

In reply to Bin Meng

Hi Bin,

Quoted 29 lines · Bin Meng

To further limit the memory space, we only allow serial device to be bound before relocation.

---

 drivers/pci/pci-uclass.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pci/pci-uclass.c +5 -2
index 4160274..b7dca0f 100644
@@ -487,9 +487,13 @@ static int pci_find_and_bind_driver(struct udevice *parent,
                         * whose driver has the DM_FLAG_PRE_RELOC set, to save
                         * precious memory space as on some platforms as that
                         * space is pretty limited (ie: using Cache As RAM).
+                        *
+                        * To further limit the memory space, we only allow
+                        * serial device to be bound.
                         */
                        if (!(gd->flags & GD_FLG_RELOC) &&
-                           !(drv->flags & DM_FLAG_PRE_RELOC))
+                           !(drv->flags & DM_FLAG_PRE_RELOC) &&
+                           (drv->id != UCLASS_SERIAL))
                                return 0;
 
                        /*
--
Quoted 2 lines

1.8.2.1

This seems to go too far. We may have other drivers that need to do pre-reloc init. Why not just rely on DM_FLAG_PRE_RELOC?

Regards,
Simon

#9 lore raw

PATCH 4/8 x86: fsp: Enlarge the size of malloc() pool before relocation

In reply to Bin Meng

Hi Bin,

Quoted 5 lines · Bin Meng

After fsp_init() returns, the stack has already been switched to a place within system memory as defined by CONFIG_FSP_TEMP_RAM_ADDR. Enlarge the size of malloc() pool before relocation since we have plenty of memory now.

Quoted 7 lines

---

 arch/x86/Kconfig              | 7 +++++++
 arch/x86/cpu/start.S          | 8 ++++++++
 arch/x86/lib/fsp/fsp_common.c | 6 +++++-
 3 files changed, 20 insertions(+), 1 deletion(-)

Can you please explain a bit why this patch is needed? Wouldn't it be better to avoid needing so much memory?

Regards,
Simon

#17 lore raw

PATCH 5/8 drivers: serial: Add ns16550 compatible pci uart driver

In reply to Bin Meng

Hi Bin,

Quoted 81 lines · Bin Meng

Hi Simon,

Quoted 68 lines · Simon Glass

Hi Bin,

Quoted 65 lines · Bin Meng

This adds a new driver to support National Semiconductor 16550 compatible UART device with PCI interface. The initial support only adds device IDs for Intel Topcliff chipset UART devices.

---

 drivers/serial/Kconfig      |  9 ++++++
 drivers/serial/Makefile     |  1 +
 drivers/serial/serial_pci.c | 75 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+)
 create mode 100644 drivers/serial/serial_pci.c
drivers/serial/Kconfig +9 -0
index fd126a8..f2eccdd 100644
@@ -128,3 +128,12 @@ config X86_SERIAL
          enabled in the device tree with the correct input clock frequency
          provided (default 1843200). Enable this to obtain serial console
          output.
+
+config PCI_SERIAL
+       bool "Support for 16550 serial port on PCI bus"
+       depends on DM_PCI
+       default n
+       help
+         This is the UART driver for ns16550 compatible chipset with PCI
+         interface. This can be enabled in the device tree with the correct
+         properties provided. If unsure, say N.
drivers/serial/Makefile +1 -0
index 1d1f036..a7e2cd2 100644
@@ -45,6 +45,7 @@ obj-$(CONFIG_TEGRA_SERIAL) += serial_tegra.o
 obj-$(CONFIG_UNIPHIER_SERIAL) += serial_uniphier.o
 obj-$(CONFIG_OMAP_SERIAL) += serial_omap.o
 obj-$(CONFIG_X86_SERIAL) += serial_x86.o
+obj-$(CONFIG_PCI_SERIAL) += serial_pci.o
 obj-$(CONFIG_STM32_SERIAL) += serial_stm32.o
 
 ifndef CONFIG_SPL_BUILD
drivers/serial/serial_pci.c new file +17 -0
new file mode 100644
index 0000000..bc87c9a
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2015, Bin Meng <[email protected]>
+ *
+ * This driver aims to support National Semiconductor 16550 compatible
+ * UART device with PCI interface.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <fdtdec.h>
+#include <ns16550.h>
+#include <serial.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
Quoted 9 lines

drivers/serial/serial_pci.c line 22

Quoted 5 lines
drivers/serial/serial_pci.c new file +5 -0
+static struct pci_device_id supported[] = {
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_0) },
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_1) },
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_2) },
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_3) },

Ick, did I miss the discussion on this? I really want us to keep this stuff in the device tree.

Quoted 3 lines

I don't think you missed any discussion. But I think you might misread this code? Do you mean there is no need to declare what devices are supported by this driver using U_BOOT_PCI_DEVICE?

OK but we have gone from a generic driver that worked with anything to one where you have to enable it for every ID on every board. How is that an improvement?

Quoted 15 lines
Quoted 15 lines
Quoted 5 lines
drivers/serial/serial_pci.c new file +4 -0
+       {}
+};
+
+static const struct udevice_id pci_serial_ids[] = {

drivers/serial/serial_pci.c line 36

Quoted 10 lines
drivers/serial/serial_pci.c new file +10 -0
+       { .compatible = "pci-uart" },
+       { }
+};
+
+static int pci_serial_ofdata_to_platdata(struct udevice *dev)
+{
+       struct ns16550_platdata *plat = dev_get_platdata(dev);
+       struct fdt_pci_addr pci_addr;
+       u32 bar;
+       int ret;

If we have a device tree node, why do we need the U_BOOT_PCI_DEVICE() stuff?

Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
drivers/serial/serial_pci.c new file +35 -0
+
+       /* we prefer to use a memory-mapped register */
+       ret = fdtdec_get_pci_addr(gd->fdt_blob, dev->of_offset,
+                                 FDT_PCI_SPACE_MEM32, "reg", &pci_addr);
+       if (ret) {
+               /* try if there is any i/o-mapped register */
+               ret = fdtdec_get_pci_addr(gd->fdt_blob, dev->of_offset,
+                                         FDT_PCI_SPACE_IO, "reg", &pci_addr);
+               if (ret)
+                       return ret;
+       }
+
+       ret = fdtdec_get_pci_bar32(gd->fdt_blob, dev->of_offset,
+                                  &pci_addr, &bar);
+       if (ret)
+               return ret;
+
+       plat->base = bar;
+       plat->reg_shift = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+                                        "reg-shift", 1);
+       plat->clock = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+                                    "clock-frequency", 1843200);
+
+       return 0;
+}
+
+U_BOOT_DRIVER(serial_pci) = {
+       .name = "serial_pci",
+       .id = UCLASS_SERIAL,
+       .of_match = pci_serial_ids,
+       .ofdata_to_platdata = pci_serial_ofdata_to_platdata,
+       .platdata_auto_alloc_size = sizeof(struct ns16550_platdata),
+       .priv_auto_alloc_size = sizeof(struct NS16550),
+       .probe = ns16550_serial_probe,
+       .ops = &ns16550_serial_ops,
Quoted 8 lines
Quoted 5 lines

drivers/serial/serial_pci.c

Quoted 5 lines
drivers/serial/serial_pci.c new file +4 -1
+       .flags = DM_FLAG_PRE_RELOC,
+};
+
+U_BOOT_PCI_DEVICE(serial_pci, supported);
--

Regards,
Bin

Regards,
Simon

author
#3 lore raw

PATCH 2/8 dm: pci: Only allow serial device to be bound before relocation

In reply to Simon Glass

Hi Simon,

Quoted 30 lines · Simon Glass

Hi Bin,

Quoted 27 lines · Bin Meng

To further limit the memory space, we only allow serial device to be bound before relocation.

---

 drivers/pci/pci-uclass.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pci/pci-uclass.c +5 -1
index 4160274..b7dca0f 100644
@@ -487,9 +487,13 @@ static int pci_find_and_bind_driver(struct udevice *parent,
                         * whose driver has the DM_FLAG_PRE_RELOC set, to save
                         * precious memory space as on some platforms as that
                         * space is pretty limited (ie: using Cache As RAM).
+                        *
+                        * To further limit the memory space, we only allow
+                        * serial device to be bound.
                         */
                        if (!(gd->flags & GD_FLG_RELOC) &&
-                           !(drv->flags & DM_FLAG_PRE_RELOC))
+                           !(drv->flags & DM_FLAG_PRE_RELOC) &&
+                           (drv->id != UCLASS_SERIAL))
                                return 0;
 
Quoted 8 lines
Quoted 4 lines
drivers/pci/pci-uclass.c +0 -1
                        /*
--

1.8.2.1

This seems to go too far. We may have other drivers that need to do pre-reloc init. Why not just rely on DM_FLAG_PRE_RELOC?

I was thinking the only usable pci driver before relocation is serial?

Regards,
Bin

author
#10 lore raw

PATCH 4/8 x86: fsp: Enlarge the size of malloc() pool before relocation

In reply to Simon Glass

Hi Simon,

Quoted 11 lines · Simon Glass

Hi Bin,

Quoted 8 lines · Bin Meng

After fsp_init() returns, the stack has already been switched to a place within system memory as defined by CONFIG_FSP_TEMP_RAM_ADDR. Enlarge the size of malloc() pool before relocation since we have plenty of memory now.

---

Quoted 8 lines
Quoted 4 lines
 arch/x86/Kconfig              | 7 +++++++
 arch/x86/cpu/start.S          | 8 ++++++++
 arch/x86/lib/fsp/fsp_common.c | 6 +++++-
 3 files changed, 20 insertions(+), 1 deletion(-)

Can you please explain a bit why this patch is needed? Wouldn't it be better to avoid needing so much memory?

This is because even with pci-uclass change, the memory is still not enough on Crown Bay to support PCI UART as the UART is behind two bridges (at best), or five bridges (at worst).

Anyway I change this not only for Crown Bay. It's a "feature" that FSP provides since it already switches to a new stack which is using system memory where the size is not a problem.

Regards,
Bin

#4 lore raw

PATCH 2/8 dm: pci: Only allow serial device to be bound before relocation

In reply to Bin Meng

Hi Bin,

Quoted 42 lines · Bin Meng

Hi Simon,

Quoted 30 lines · Simon Glass

Hi Bin,

Quoted 27 lines · Bin Meng

To further limit the memory space, we only allow serial device to be bound before relocation.

---

 drivers/pci/pci-uclass.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pci/pci-uclass.c +5 -1
index 4160274..b7dca0f 100644
@@ -487,9 +487,13 @@ static int pci_find_and_bind_driver(struct udevice *parent,
                         * whose driver has the DM_FLAG_PRE_RELOC set, to save
                         * precious memory space as on some platforms as that
                         * space is pretty limited (ie: using Cache As RAM).
+                        *
+                        * To further limit the memory space, we only allow
+                        * serial device to be bound.
                         */
                        if (!(gd->flags & GD_FLG_RELOC) &&
-                           !(drv->flags & DM_FLAG_PRE_RELOC))
+                           !(drv->flags & DM_FLAG_PRE_RELOC) &&
+                           (drv->id != UCLASS_SERIAL))
                                return 0;
 
Quoted 8 lines
Quoted 4 lines
drivers/pci/pci-uclass.c +0 -1
                        /*
--

1.8.2.1

This seems to go too far. We may have other drivers that need to do pre-reloc init. Why not just rely on DM_FLAG_PRE_RELOC?

Quoted 1 line

I was thinking the only usable pci driver before relocation is serial?

I suspect there will be others. We have pre-relocation CPU init that might go in a driver one day. In any case this seems a bit hacky so I think we should drop this patch unless we need it.

Regards,
Simon

#11 lore raw

PATCH 4/8 x86: fsp: Enlarge the size of malloc() pool before relocation

In reply to Bin Meng

Hi Bin,

Quoted 5 lines · Bin Meng

After fsp_init() returns, the stack has already been switched to a place within system memory as defined by CONFIG_FSP_TEMP_RAM_ADDR. Enlarge the size of malloc() pool before relocation since we have plenty of memory now.

Quoted 7 lines

---

 arch/x86/Kconfig              | 7 +++++++
 arch/x86/cpu/start.S          | 8 ++++++++
 arch/x86/lib/fsp/fsp_common.c | 6 +++++-
 3 files changed, 20 insertions(+), 1 deletion(-)

Thanks for explaining the patch.

arch/x86/Kconfig config FSP_TEMP_RAM_ADDR · line 232

Quoted 7 lines
arch/x86/Kconfig +0 -0
index 065bbe4..687208f 100644
@@ -232,6 +232,13 @@ config FSP_TEMP_RAM_ADDR
          Stack top address which is used in FspInit after DRAM is ready and

(separate point for a possible future patch: FspInit should probably change to fsp_init globally)

Quoted 17 lines
arch/x86/Kconfig +7 -0
          CAR is disabled.
 
+config FSP_SYS_MALLOC_F_LEN
+       hex
+       depends on HAVE_FSP
+       default 0x100000
+       help
+         Additional size of malloc() pool before relocation.
+
 config SMP
        bool "Enable Symmetric Multiprocessing"
        default n
arch/x86/cpu/start.S +0 -0
index e94ddc4..e2b5ef4 100644

arch/x86/cpu/start.S car_init_ret: · line 142

Quoted 2 lines
arch/x86/cpu/start.S +0 -0
@@ -141,6 +141,14 @@ car_init_ret:
        jz      skip_hob
        movl    %esi, GD_HOB_LIST(%edx)

At some point could you please add a comment here about the fact that we enter this code twice on boot?

Quoted 17 lines
arch/x86/cpu/start.S +8 -0
+       /*
+        * After fsp_init() returns, the stack has already been switched to a
+        * place within system memory as defined by CONFIG_FSP_TEMP_RAM_ADDR.
+        * Enlarge the size of malloc() pool before relocation since we have
+        * plenty of memory now.
+        */
+       subl    $CONFIG_FSP_SYS_MALLOC_F_LEN, %esp
+       movl    %esp, GD_MALLOC_BASE(%edx)
 skip_hob:
 #else
        /* Store table pointer */
arch/x86/lib/fsp/fsp_common.c +0 -0
index 6f72c6d..9c316d4 100644

arch/x86/lib/fsp/fsp_common.c void board_final_cleanup(void) · line 63

Quoted 9 lines
arch/x86/lib/fsp/fsp_common.c +4 -1
@@ -56,8 +56,12 @@ void board_final_cleanup(void)
 
 int x86_fsp_init(void)
 {
-       if (!gd->arch.hob_list)
+       if (!gd->arch.hob_list) {
                fsp_init(CONFIG_FSP_TEMP_RAM_ADDR, BOOT_FULL_CONFIG, NULL);
+       } else {
+               /* We should adjust gd->malloc_limit here */
+               gd->malloc_limit += CONFIG_FSP_SYS_MALLOC_F_LEN;

Should this increase the limit by this much, or CONFIG_FSP_SYS_MALLOC_F_LEN - CONFIG_SYS_MALLOC_F_LEN?

Quoted 7 lines
arch/x86/lib/fsp/fsp_common.c +1 -1
+       }
 
        return 0;
 }
--

1.8.2.1

Regards,
Simon

author
#5 lore raw

PATCH 2/8 dm: pci: Only allow serial device to be bound before relocation

In reply to Simon Glass

Hi Simon,

Quoted 45 lines · Simon Glass

Hi Bin,

Quoted 42 lines · Bin Meng

Hi Simon,

Quoted 38 lines · Simon Glass

Hi Bin,

Quoted 29 lines · Bin Meng

To further limit the memory space, we only allow serial device to be bound before relocation.

---

 drivers/pci/pci-uclass.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pci/pci-uclass.c +5 -2
index 4160274..b7dca0f 100644
@@ -487,9 +487,13 @@ static int pci_find_and_bind_driver(struct udevice *parent,
                         * whose driver has the DM_FLAG_PRE_RELOC set, to save
                         * precious memory space as on some platforms as that
                         * space is pretty limited (ie: using Cache As RAM).
+                        *
+                        * To further limit the memory space, we only allow
+                        * serial device to be bound.
                         */
                        if (!(gd->flags & GD_FLG_RELOC) &&
-                           !(drv->flags & DM_FLAG_PRE_RELOC))
+                           !(drv->flags & DM_FLAG_PRE_RELOC) &&
+                           (drv->id != UCLASS_SERIAL))
                                return 0;
 
                        /*
--
Quoted 2 lines

1.8.2.1

This seems to go too far. We may have other drivers that need to do pre-reloc init. Why not just rely on DM_FLAG_PRE_RELOC?

Quoted 5 lines
Quoted 1 line

I was thinking the only usable pci driver before relocation is serial?

I suspect there will be others. We have pre-relocation CPU init that might go in a driver one day. In any case this seems a bit hacky so I think we should drop this patch unless we need it.

But that is not on PCI bus, right? I can only think of a PCI serial device so far. But as you said, we can drop this patch and revisit this in the future.

Regards,
Bin

author
#18 lore raw

PATCH 5/8 drivers: serial: Add ns16550 compatible pci uart driver

In reply to Simon Glass

Hi Simon,

Quoted 84 lines · Simon Glass

Hi Bin,

Quoted 81 lines · Bin Meng

Hi Simon,

Quoted 77 lines · Simon Glass

Hi Bin,

Quoted 60 lines · Bin Meng

This adds a new driver to support National Semiconductor 16550 compatible UART device with PCI interface. The initial support only adds device IDs for Intel Topcliff chipset UART devices.

---

 drivers/serial/Kconfig      |  9 ++++++
 drivers/serial/Makefile     |  1 +
 drivers/serial/serial_pci.c | 75 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+)
 create mode 100644 drivers/serial/serial_pci.c
drivers/serial/Kconfig +9 -0
index fd126a8..f2eccdd 100644
@@ -128,3 +128,12 @@ config X86_SERIAL
          enabled in the device tree with the correct input clock frequency
          provided (default 1843200). Enable this to obtain serial console
          output.
+
+config PCI_SERIAL
+       bool "Support for 16550 serial port on PCI bus"
+       depends on DM_PCI
+       default n
+       help
+         This is the UART driver for ns16550 compatible chipset with PCI
+         interface. This can be enabled in the device tree with the correct
+         properties provided. If unsure, say N.
drivers/serial/Makefile +1 -0
index 1d1f036..a7e2cd2 100644
@@ -45,6 +45,7 @@ obj-$(CONFIG_TEGRA_SERIAL) += serial_tegra.o
 obj-$(CONFIG_UNIPHIER_SERIAL) += serial_uniphier.o
 obj-$(CONFIG_OMAP_SERIAL) += serial_omap.o
 obj-$(CONFIG_X86_SERIAL) += serial_x86.o
+obj-$(CONFIG_PCI_SERIAL) += serial_pci.o
 obj-$(CONFIG_STM32_SERIAL) += serial_stm32.o
 
 ifndef CONFIG_SPL_BUILD
drivers/serial/serial_pci.c new file +12 -0
new file mode 100644
index 0000000..bc87c9a
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2015, Bin Meng <[email protected]>
+ *
+ * This driver aims to support National Semiconductor 16550 compatible
+ * UART device with PCI interface.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <fdtdec.h>

drivers/serial/serial_pci.c line 22

Quoted 10 lines
drivers/serial/serial_pci.c new file +10 -0
+#include <ns16550.h>
+#include <serial.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static struct pci_device_id supported[] = {
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_0) },
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_1) },
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_2) },
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_3) },

Ick, did I miss the discussion on this? I really want us to keep this stuff in the device tree.

Quoted 8 lines
Quoted 3 lines

I don't think you missed any discussion. But I think you might misread this code? Do you mean there is no need to declare what devices are supported by this driver using U_BOOT_PCI_DEVICE?

OK but we have gone from a generic driver that worked with anything to one where you have to enable it for every ID on every board. How is that an improvement?

Agreed, but given fdtdec_get_addr() is broken (see previous discussion), I decided to split that from the generic 16550 driver. Although I see you revert that commit, I am not sure how fdtdec_get_addr() will be changed in the future.

Quoted 18 lines
Quoted 15 lines
Quoted 15 lines
Quoted 5 lines
drivers/serial/serial_pci.c new file +4 -0
+       {}
+};
+
+static const struct udevice_id pci_serial_ids[] = {

drivers/serial/serial_pci.c line 36

Quoted 10 lines
drivers/serial/serial_pci.c new file +10 -0
+       { .compatible = "pci-uart" },
+       { }
+};
+
+static int pci_serial_ofdata_to_platdata(struct udevice *dev)
+{
+       struct ns16550_platdata *plat = dev_get_platdata(dev);
+       struct fdt_pci_addr pci_addr;
+       u32 bar;
+       int ret;

If we have a device tree node, why do we need the U_BOOT_PCI_DEVICE() stuff?

This is to have pci bus to filter the device creation. I see if I define U_BOOT_PCI_DEVICE() and with a device node at the same time, it will show twice in the 'dm tree' output. One with a driver name 'pci_serial' and the other one with 'serial'. Maybe I am using it wrong?

Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
drivers/serial/serial_pci.c new file +33 -0
+
+       /* we prefer to use a memory-mapped register */
+       ret = fdtdec_get_pci_addr(gd->fdt_blob, dev->of_offset,
+                                 FDT_PCI_SPACE_MEM32, "reg", &pci_addr);
+       if (ret) {
+               /* try if there is any i/o-mapped register */
+               ret = fdtdec_get_pci_addr(gd->fdt_blob, dev->of_offset,
+                                         FDT_PCI_SPACE_IO, "reg", &pci_addr);
+               if (ret)
+                       return ret;
+       }
+
+       ret = fdtdec_get_pci_bar32(gd->fdt_blob, dev->of_offset,
+                                  &pci_addr, &bar);
+       if (ret)
+               return ret;
+
+       plat->base = bar;
+       plat->reg_shift = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+                                        "reg-shift", 1);
+       plat->clock = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+                                    "clock-frequency", 1843200);
+
+       return 0;
+}
+
+U_BOOT_DRIVER(serial_pci) = {
+       .name = "serial_pci",
+       .id = UCLASS_SERIAL,
+       .of_match = pci_serial_ids,
+       .ofdata_to_platdata = pci_serial_ofdata_to_platdata,
+       .platdata_auto_alloc_size = sizeof(struct ns16550_platdata),
+       .priv_auto_alloc_size = sizeof(struct NS16550),
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

drivers/serial/serial_pci.c

Quoted 7 lines
drivers/serial/serial_pci.c new file +6 -1
+       .probe = ns16550_serial_probe,
+       .ops = &ns16550_serial_ops,
+       .flags = DM_FLAG_PRE_RELOC,
+};
+
+U_BOOT_PCI_DEVICE(serial_pci, supported);
--

Regards,
Bin

author
#25 lore raw

PATCH 8/8 x86: queensbay: Call fsp_init_phase_pci() again

In reply to Simon Glass

Hi Simon,

Quoted 58 lines · Simon Glass

Hi Bin,

Quoted 55 lines · Bin Meng

Hi Simon,

Quoted 17 lines · Bin Meng

With driver model pci conversion, the call to FspNotify was dropped. Now add this call back as this is required by the FSP spec.

---

 arch/x86/cpu/queensbay/tnc.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
arch/x86/cpu/queensbay/tnc.c +0 -0
index c465642..11f65ad 100644
@@ -80,5 +80,11 @@ void cpu_irq_init(void)
 
 int arch_misc_init(void)
 {

arch/x86/cpu/queensbay/tnc.c void cpu_irq_init(void)

Quoted 10 lines
arch/x86/cpu/queensbay/tnc.c +7 -2
-       return pirq_init();
+       int ret;
+
+       ret =  pirq_init();
+       if (ret)
+               return ret;
+
+       return fsp_init_phase_pci();
 }
--

Unfortunately, this change breaks video graphics console on Intel Crown Bay. I was not testing graphics (leave the LVDS interface open) when I submitted this series. But when I got my LVDS panel connected (during my attempt to support the PS/2 keyboard), the screen is just a mess with funny colors. I've git bisected and confirmed this very last commit breaks the video.

So, this test result is now supporting my previous worry, that we should call FspNotify() immediately after PCI enumeration, before any device driver touch PCI devices. This is what the FSP spec tells us and we used to do this correctly before dm pci conversion. This issue is unfortunately exposed by driver model PCI. With driver model, when PCI bus gets enumerated is unknown to us. On Crown Bay, this happens in initr_mmc() in board_r.c where MMC driver gets initialized. Then vesa video driver runs the vbios and finally followed by arch_misc_init() which calls FspNotify() and messes up the screen.

I moved the call to fsp_init_phase_pci() from arch_misc_init() to the place in initr_mmc() that immediately follows mmc_initialize(), which means call the FspNotify() as soon as PCI bus is enumerated. With this change, video (graphics console) is working again. So during the FspNotify() phase, FSP must have done something (eg: programming some graphics hardware registers) and that unfortunately breaks the things.

Quoted 8 lines
Quoted 3 lines

I cannot find a good place in the generic dm pci driver to insert such a call. So maybe we should just explicitly trigger the PCI bus enumeration at least when CONFIG_HAVE_FSP. What do you think?

An ugly option would be to add the call to pci_uclass_post_probe().

No I don't think we should force enumeration.

That's really ugly. But I don't see a good place too..

Regards,
Bin

author
#12 lore raw

PATCH 4/8 x86: fsp: Enlarge the size of malloc() pool before relocation

In reply to Simon Glass

Hi Simon,

Quoted 19 lines · Simon Glass

Hi Bin,

Quoted 5 lines · Bin Meng

After fsp_init() returns, the stack has already been switched to a place within system memory as defined by CONFIG_FSP_TEMP_RAM_ADDR. Enlarge the size of malloc() pool before relocation since we have plenty of memory now.

Quoted 7 lines

---

 arch/x86/Kconfig              | 7 +++++++
 arch/x86/cpu/start.S          | 8 ++++++++
 arch/x86/lib/fsp/fsp_common.c | 6 +++++-
 3 files changed, 20 insertions(+), 1 deletion(-)

Thanks for explaining the patch.

Quoted 1 line
Quoted 9 lines

arch/x86/Kconfig config FSP_TEMP_RAM_ADDR · line 232

Quoted 6 lines
arch/x86/Kconfig +0 -0
index 065bbe4..687208f 100644
@@ -232,6 +232,13 @@ config FSP_TEMP_RAM_ADDR
          Stack top address which is used in FspInit after DRAM is ready and

(separate point for a possible future patch: FspInit should probably change to fsp_init globally)

Will do in v2.

Quoted 15 lines
Quoted 15 lines
arch/x86/Kconfig +7 -0
          CAR is disabled.
 
+config FSP_SYS_MALLOC_F_LEN
+       hex
+       depends on HAVE_FSP
+       default 0x100000
+       help
+         Additional size of malloc() pool before relocation.
+
 config SMP
        bool "Enable Symmetric Multiprocessing"
        default n
arch/x86/cpu/start.S +0 -0
index e94ddc4..e2b5ef4 100644
Quoted 9 lines

arch/x86/cpu/start.S car_init_ret: · line 142

Quoted 5 lines
arch/x86/cpu/start.S +0 -0
@@ -141,6 +141,14 @@ car_init_ret:
        jz      skip_hob
        movl    %esi, GD_HOB_LIST(%edx)

At some point could you please add a comment here about the fact that we enter this code twice on boot?

Will do in v2.

Quoted 18 lines
Quoted 18 lines
arch/x86/cpu/start.S +8 -0
+       /*
+        * After fsp_init() returns, the stack has already been switched to a
+        * place within system memory as defined by CONFIG_FSP_TEMP_RAM_ADDR.
+        * Enlarge the size of malloc() pool before relocation since we have
+        * plenty of memory now.
+        */
+       subl    $CONFIG_FSP_SYS_MALLOC_F_LEN, %esp
+       movl    %esp, GD_MALLOC_BASE(%edx)
 skip_hob:
 #else
        /* Store table pointer */
arch/x86/lib/fsp/fsp_common.c +0 -0
index 6f72c6d..9c316d4 100644
@@ -56,8 +56,12 @@ void board_final_cleanup(void)
 
Quoted 11 lines

arch/x86/lib/fsp/fsp_common.c void board_final_cleanup(void) · line 63

Quoted 8 lines
arch/x86/lib/fsp/fsp_common.c +4 -1
 int x86_fsp_init(void)
 {
-       if (!gd->arch.hob_list)
+       if (!gd->arch.hob_list) {
                fsp_init(CONFIG_FSP_TEMP_RAM_ADDR, BOOT_FULL_CONFIG, NULL);
+       } else {
+               /* We should adjust gd->malloc_limit here */
+               gd->malloc_limit += CONFIG_FSP_SYS_MALLOC_F_LEN;

Should this increase the limit by this much, or CONFIG_FSP_SYS_MALLOC_F_LEN - CONFIG_SYS_MALLOC_F_LEN?

No, as you see in start.S the esp was subtracted by CONFIG_FSP_SYS_MALLOC_F_LEN so the limit should be added by CONFIG_FSP_SYS_MALLOC_F_LEN as well. I will add a more detailed comments for this in v2.

Quoted 6 lines

arch/x86/lib/fsp/fsp_common.c void board_final_cleanup(void)

Quoted 6 lines
arch/x86/lib/fsp/fsp_common.c +1 -1
+       }
 
        return 0;
 }
--

Regards,
Bin

#19 lore raw

PATCH 5/8 drivers: serial: Add ns16550 compatible pci uart driver

In reply to Bin Meng

Hi Bin,

Quoted 96 lines · Bin Meng

Hi Simon,

Quoted 84 lines · Simon Glass

Hi Bin,

Quoted 81 lines · Bin Meng

Hi Simon,

Quoted 77 lines · Simon Glass

Hi Bin,

Quoted 60 lines · Bin Meng

This adds a new driver to support National Semiconductor 16550 compatible UART device with PCI interface. The initial support only adds device IDs for Intel Topcliff chipset UART devices.

---

 drivers/serial/Kconfig      |  9 ++++++
 drivers/serial/Makefile     |  1 +
 drivers/serial/serial_pci.c | 75 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+)
 create mode 100644 drivers/serial/serial_pci.c
drivers/serial/Kconfig +9 -0
index fd126a8..f2eccdd 100644
@@ -128,3 +128,12 @@ config X86_SERIAL
          enabled in the device tree with the correct input clock frequency
          provided (default 1843200). Enable this to obtain serial console
          output.
+
+config PCI_SERIAL
+       bool "Support for 16550 serial port on PCI bus"
+       depends on DM_PCI
+       default n
+       help
+         This is the UART driver for ns16550 compatible chipset with PCI
+         interface. This can be enabled in the device tree with the correct
+         properties provided. If unsure, say N.
drivers/serial/Makefile +1 -0
index 1d1f036..a7e2cd2 100644
@@ -45,6 +45,7 @@ obj-$(CONFIG_TEGRA_SERIAL) += serial_tegra.o
 obj-$(CONFIG_UNIPHIER_SERIAL) += serial_uniphier.o
 obj-$(CONFIG_OMAP_SERIAL) += serial_omap.o
 obj-$(CONFIG_X86_SERIAL) += serial_x86.o
+obj-$(CONFIG_PCI_SERIAL) += serial_pci.o
 obj-$(CONFIG_STM32_SERIAL) += serial_stm32.o
 
 ifndef CONFIG_SPL_BUILD
drivers/serial/serial_pci.c new file +12 -0
new file mode 100644
index 0000000..bc87c9a
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2015, Bin Meng <[email protected]>
+ *
+ * This driver aims to support National Semiconductor 16550 compatible
+ * UART device with PCI interface.
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <fdtdec.h>

drivers/serial/serial_pci.c line 22

Quoted 10 lines
drivers/serial/serial_pci.c new file +10 -0
+#include <ns16550.h>
+#include <serial.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static struct pci_device_id supported[] = {
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_0) },
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_1) },
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_2) },
+       { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_UART_3) },

Ick, did I miss the discussion on this? I really want us to keep this stuff in the device tree.

Quoted 8 lines
Quoted 3 lines

I don't think you missed any discussion. But I think you might misread this code? Do you mean there is no need to declare what devices are supported by this driver using U_BOOT_PCI_DEVICE?

OK but we have gone from a generic driver that worked with anything to one where you have to enable it for every ID on every board. How is that an improvement?

Quoted 4 lines

Agreed, but given fdtdec_get_addr() is broken (see previous discussion), I decided to split that from the generic 16550 driver. Although I see you revert that commit, I am not sure how fdtdec_get_addr() will be changed in the future.

However it gets changed it will need to work correctly so you don't need to worry about that.

Quoted 20 lines
Quoted 19 lines
Quoted 16 lines
Quoted 16 lines
Quoted 6 lines
drivers/serial/serial_pci.c new file +4 -0
+       {}
+};
+
+static const struct udevice_id pci_serial_ids[] = {

drivers/serial/serial_pci.c line 36

Quoted 10 lines
drivers/serial/serial_pci.c new file +10 -0
+       { .compatible = "pci-uart" },
+       { }
+};
+
+static int pci_serial_ofdata_to_platdata(struct udevice *dev)
+{
+       struct ns16550_platdata *plat = dev_get_platdata(dev);
+       struct fdt_pci_addr pci_addr;
+       u32 bar;
+       int ret;

If we have a device tree node, why do we need the U_BOOT_PCI_DEVICE() stuff?

Quoted 5 lines

This is to have pci bus to filter the device creation. I see if I define U_BOOT_PCI_DEVICE() and with a device node at the same time, it will show twice in the 'dm tree' output. One with a driver name 'pci_serial' and the other one with 'serial'. Maybe I am using it wrong?

Well if it is in the device tree you don't need to use U_BOOT_PCI_DEVICE. In pci_bind_bus_devices() it searches the device tree first and only resorts to pci_find_and_bind_driver() if that fails.

[snip]

Regards,
Simon