Skip to contentSkip to conversation

x86: Support pci based uart as the U-Boot serial console

PATCH Superseded Bin Meng 2 participants 14 messages Dec 30, 2014 – Dec 31, 2014

Subsystems (4)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

v3 cover x86: Support pci based uart as the U-Boot serial console

This series add support to the ns16550 compatible pci devices.

Newer x86 Platform Controller Hub chipset (like Topcliff, BayTrail) starts to integrate ns16550 compatible pci uart devices. In order to use them, we have to scan the pci bus and allocate memory/io address in the early phase. A gd->hose is added to save the pci bus controller hose in the early phase so that pci apis can be used.

On Intel Crown Bay board, there are 4 DB9 connectors, one of which is from the superio legacy serial port and the other 3 are connected to the Topcliff PCH UART devices. In order to use them as the U-Boot serial console, we need describe those devices in the board's dts file per Open Firmware PCI bus bindings and specify it as the console via the 'stdout-path' in the chosen node. Several APIs are added in fdtdec.c to provide help for decoding the pci device nodes.

Changes in v3:
- Fixed a typo: parant -> parent
- Return better error code in fdtdec_get_pci_addr()
- Add some debug output in fdtdec_get_pci_addr()
- Reuse variable 'len' instead of creating a new one 'l'
- Check compatible string length and existence of '.'
- Using simple_strtol() directly on the compatible sub-string
- Change variable 'bn' to 'barnum' which is self-documenting
- Update to use 'memory-mapped' and 'i/o-mapped' in several places
- Use 'Processor Local Bus' instead of 'plb'
- Change the logic in ns16550_serial_ofdata_to_platdata() to avoid goto

Changes in v2:
- Add a commit message
- New patch to make pci apis usable before relocation
- New patch to add several apis to decode pci device node
- New patch to support ns16550 compatible pci uart devices
- New patch to use ePAPR defined properties for x86-uart
- New patch to add pci devices in crownbay.dts
- Drop v1 patch: Add an API for finding pci devices in the early phase
- Drop v1 patch: Support PCI UART in the x86_serial driver
- Drop v1 patch: Add PCI UART related defines in crownbay.h

Bin Meng (7):
x86: Add missing DECLARE_GLOBAL_DATA_PTR for pci.c
x86: Support pci bus scan in the early phase
pci: Make pci apis usable before relocation
fdt: Add several apis to decode pci device node
serial: ns16550: Support ns16550 compatible pci uart devices
x86: Use ePAPR defined properties for x86-uart
x86: crownbay: Add pci devices in the dts file

 arch/x86/cpu/pci.c                 |  11 ++-
 arch/x86/dts/crownbay.dts          |  81 ++++++++++++++++++
 arch/x86/dts/serial.dtsi           |   5 +-
 arch/x86/include/asm/global_data.h |   1 -
 arch/x86/include/asm/pci.h         |   2 +-
 drivers/pci/pci.c                  |  25 ++++--
 drivers/serial/ns16550.c           |  31 +++++++
 drivers/serial/serial_x86.c        |   8 +-
 include/asm-generic/global_data.h  |   6 ++
 include/fdtdec.h                   | 108 +++++++++++++++++++++---
 lib/fdtdec.c                       | 166 +++++++++++++++++++++++++++++++++----
 11 files changed, 401 insertions(+), 43 deletions(-)
Signature · 1 line
1.8.2.1
author
#1 lore raw

PATCH v3 1/7 x86: Add missing DECLARE_GLOBAL_DATA_PTR for pci.c

arch/x86/cpu/pci.c has access to the U-Boot global data thus DECLARE_GLOBAL_DATA_PTR is needed.

---

Changes in v3: None
Changes in v2:
- Add a commit message

 arch/x86/cpu/pci.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/cpu/pci.c +2 -0
index f3492c3..404fbb6 100644
@@ -15,6 +15,8 @@
 #include <pci.h>
 #include <asm/pci.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 static struct pci_controller x86_hose;
 
 int pci_early_init_hose(struct pci_controller **hosep)
Signature · 1 line
1.8.2.1
#2 lore raw

PATCH v3 1/7 x86: Add missing DECLARE_GLOBAL_DATA_PTR for pci.c

Quoted 6 lines · Bin Meng

arch/x86/cpu/pci.c has access to the U-Boot global data thus DECLARE_GLOBAL_DATA_PTR is needed.

Quoted 9 lines

---

Changes in v3: None
Changes in v2:
- Add a commit message

 arch/x86/cpu/pci.c | 2 ++
 1 file changed, 2 insertions(+)

Applied to u-boot-x86/next, thanks!

author
#3 lore raw

PATCH v3 2/7 x86: Support pci bus scan in the early phase

In reply to Bin Meng

On x86, some peripherals on pci buses need to be accessed in the early phase (eg: pci uart) with a valid pci memory/io address, thus scan the pci bus and do the corresponding resource allocation.

---

Changes in v3: None
Changes in v2: None

 arch/x86/cpu/pci.c | 1 +
 1 file changed, 1 insertion(+)
arch/x86/cpu/pci.c +1 -0
index 404fbb6..1eee08b 100644
@@ -29,6 +29,7 @@ int pci_early_init_hose(struct pci_controller **hosep)
 
 	board_pci_setup_hose(hose);
 	pci_setup_type1(hose);
+	hose->last_busno = pci_hose_scan(hose);
 	gd->arch.hose = hose;
 	*hosep = hose;
 
Signature · 1 line
1.8.2.1
#4 lore raw

PATCH v3 2/7 x86: Support pci bus scan in the early phase

Quoted 6 lines · Bin Meng

On x86, some peripherals on pci buses need to be accessed in the early phase (eg: pci uart) with a valid pci memory/io address, thus scan the pci bus and do the corresponding resource allocation.

Quoted 7 lines

---

Changes in v3: None
Changes in v2: None

 arch/x86/cpu/pci.c | 1 +
 1 file changed, 1 insertion(+)

Applied to u-boot-x86/next, thanks!

author
#5 lore raw

PATCH v3 3/7 pci: Make pci apis usable before relocation

In reply to Bin Meng

Introduce a gd->hose to save the pci hose in the early phase so that apis in drivers/pci/pci.c can be used before relocation. Architecture codes need assign a valid gd->hose in the early phase.

Some variables are declared as static so change them to be either stack variable or global data member so that they can be used before relocation, except the 'indent' used by CONFIG_PCI_SCAN_SHOW which just affects some print format.

---

Changes in v3: None
Changes in v2:
- New patch to make pci apis usable before relocation

 arch/x86/cpu/pci.c                 |  8 ++++----
 arch/x86/include/asm/global_data.h |  1 -
 arch/x86/include/asm/pci.h         |  2 +-
 drivers/pci/pci.c                  | 25 +++++++++++++++++--------
 include/asm-generic/global_data.h  |  6 ++++++
 5 files changed, 28 insertions(+), 14 deletions(-)
arch/x86/cpu/pci.c +4 -4
index 1eee08b..ab1aaaa 100644
@@ -30,7 +30,7 @@ int pci_early_init_hose(struct pci_controller **hosep)
 	board_pci_setup_hose(hose);
 	pci_setup_type1(hose);
 	hose->last_busno = pci_hose_scan(hose);
-	gd->arch.hose = hose;
+	gd->hose = hose;
 	*hosep = hose;
 
 	return 0;
@@ -51,7 +51,7 @@ void pci_init_board(void)
 	struct pci_controller *hose = &x86_hose;
 
 	/* Stop using the early hose */
-	gd->arch.hose = NULL;
+	gd->hose = NULL;
 
 	board_pci_setup_hose(hose);
 	pci_setup_type1(hose);
@@ -64,8 +64,8 @@ void pci_init_board(void)
 
 static struct pci_controller *get_hose(void)
 {
-	if (gd->arch.hose)
-		return gd->arch.hose;
+	if (gd->hose)
+		return gd->hose;
 
 	return pci_bus_to_hose(0);
 }
arch/x86/include/asm/global_data.h +0 -1
index 03d491a..aeab3e5 100644
@@ -43,7 +43,6 @@ struct arch_global_data {
 	uint32_t tsc_mhz;		/* TSC frequency in MHz */
 	void *new_fdt;			/* Relocated FDT */
 	uint32_t bist;			/* Built-in self test value */
-	struct pci_controller *hose;	/* PCI hose for early use */
 	enum pei_boot_mode_t pei_boot_mode;
 	const struct pch_gpio_map *gpio_map;	/* board GPIO map */
 	struct memory_info meminfo;	/* Memory information */
arch/x86/include/asm/pci.h +1 -1
index ac1a808..c30dd4c 100644
@@ -29,7 +29,7 @@ void board_pci_setup_hose(struct pci_controller *hose);
  * pci_early_init_hose() - Set up PCI host before relocation
  *
  * This allocates memory for, sets up and returns the PCI hose. It can be
- * called before relocation. The hose will be stored in gd->arch.hose for
+ * called before relocation. The hose will be stored in gd->hose for
  * later use, but will become invalid one DRAM is available.
  */
 int pci_early_init_hose(struct pci_controller **hosep);
drivers/pci/pci.c +17 -8
index 3daf73c..83fd9a0 100644
@@ -19,6 +19,8 @@
 #include <asm/io.h>
 #include <pci.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 #define PCI_HOSE_OP(rw, size, type)					\
 int pci_hose_##rw##_config_##size(struct pci_controller *hose,		\
 				  pci_dev_t dev,			\
@@ -123,6 +125,14 @@ void *pci_map_bar(pci_dev_t pdev, int bar, int flags)
 
 static struct pci_controller* hose_head;
 
+struct pci_controller *pci_get_hose_head(void)
+{
+	if (gd->hose)
+		return gd->hose;
+
+	return hose_head;
+}
+
 void pci_register_hose(struct pci_controller* hose)
 {
 	struct pci_controller **phose = &hose_head;
@@ -139,7 +149,7 @@ struct pci_controller *pci_bus_to_hose(int bus)
 {
 	struct pci_controller *hose;
 
-	for (hose = hose_head; hose; hose = hose->next) {
+	for (hose = pci_get_hose_head(); hose; hose = hose->next) {
 		if (bus >= hose->first_busno && bus <= hose->last_busno)
 			return hose;
 	}
@@ -152,7 +162,7 @@ struct pci_controller *find_hose_by_cfg_addr(void *cfg_addr)
 {
 	struct pci_controller *hose;
 
-	for (hose = hose_head; hose; hose = hose->next) {
+	for (hose = pci_get_hose_head(); hose; hose = hose->next) {
 		if (hose->cfg_addr == cfg_addr)
 			return hose;
 	}
@@ -162,7 +172,7 @@ struct pci_controller *find_hose_by_cfg_addr(void *cfg_addr)
 
 int pci_last_busno(void)
 {
-	struct pci_controller *hose = hose_head;
+	struct pci_controller *hose = pci_get_hose_head();
 
 	if (!hose)
 		return -1;
@@ -181,7 +191,7 @@ pci_dev_t pci_find_devices(struct pci_device_id *ids, int index)
 	pci_dev_t bdf;
 	int i, bus, found_multi = 0;
 
-	for (hose = hose_head; hose; hose = hose->next) {
+	for (hose = pci_get_hose_head(); hose; hose = hose->next) {
 #ifdef CONFIG_SYS_SCSI_SCAN_BUS_REVERSE
 		for (bus = hose->last_busno; bus >= hose->first_busno; bus--)
 #else
@@ -233,7 +243,7 @@ pci_dev_t pci_find_devices(struct pci_device_id *ids, int index)
 
 pci_dev_t pci_find_device(unsigned int vendor, unsigned int device, int index)
 {
-	static struct pci_device_id ids[2] = {{}, {0, 0}};
+	struct pci_device_id ids[2] = { {}, {0, 0} };
 
 	ids[0].vendor = vendor;
 	ids[0].device = device;
@@ -709,11 +719,10 @@ int pci_hose_scan_bus(struct pci_controller *hose, int bus)
 int pci_hose_scan(struct pci_controller *hose)
 {
 #if defined(CONFIG_PCI_BOOTDELAY)
-	static int pcidelay_done;
 	char *s;
 	int i;
 
-	if (!pcidelay_done) {
+	if (!gd->pcidelay_done) {
 		/* wait "pcidelay" ms (if defined)... */
 		s = getenv("pcidelay");
 		if (s) {
@@ -721,7 +730,7 @@ int pci_hose_scan(struct pci_controller *hose)
 			for (i = 0; i < val; i++)
 				udelay(1000);
 		}
-		pcidelay_done = 1;
+		gd->pcidelay_done = 1;
 	}
 #endif /* CONFIG_PCI_BOOTDELAY */
 
include/asm-generic/global_data.h +6 -0
index 9c5a1e1..3d14d5f 100644
@@ -91,6 +91,12 @@ typedef struct global_data {
 	unsigned long malloc_limit;	/* limit address */
 	unsigned long malloc_ptr;	/* current address */
 #endif
+#ifdef CONFIG_PCI
+	struct pci_controller *hose;	/* PCI hose for early use */
+#endif
+#ifdef CONFIG_PCI_BOOTDELAY
+	int pcidelay_done;
+#endif
 	struct udevice *cur_serial_dev;	/* current serial device */
 	struct arch_global_data arch;	/* architecture-specific data */
 } gd_t;
Signature · 1 line
1.8.2.1
#6 lore raw

PATCH v3 3/7 pci: Make pci apis usable before relocation

Quoted 18 lines · Bin Meng

Introduce a gd->hose to save the pci hose in the early phase so that apis in drivers/pci/pci.c can be used before relocation. Architecture codes need assign a valid gd->hose in the early phase.

Some variables are declared as static so change them to be either stack variable or global data member so that they can be used before relocation, except the 'indent' used by CONFIG_PCI_SCAN_SHOW which just affects some print format.

---

Changes in v3: None
Changes in v2:
- New patch to make pci apis usable before relocation

Quoted 6 lines
 arch/x86/cpu/pci.c                 |  8 ++++----
 arch/x86/include/asm/global_data.h |  1 -
 arch/x86/include/asm/pci.h         |  2 +-
 drivers/pci/pci.c                  | 25 +++++++++++++++++--------
 include/asm-generic/global_data.h  |  6 ++++++
 5 files changed, 28 insertions(+), 14 deletions(-)

Applied to u-boot-x86/next, thanks!

author
#7 lore raw

PATCH v3 4/7 fdt: Add several apis to decode pci device node

In reply to Bin Meng

This commit adds several APIs to decode PCI device node according to the Open Firmware PCI bus bindings, including:
- fdtdec_get_pci_addr() for encoded pci address
- fdtdec_get_pci_vendev() for vendor id and device id
- fdtdec_get_pci_bdf() for pci device bdf triplet
- fdtdec_get_pci_bar32() for pci device register bar

---

Changes in v3:
- Fixed a typo: parant -> parent
- Return better error code in fdtdec_get_pci_addr()
- Add some debug output in fdtdec_get_pci_addr()
- Reuse variable 'len' instead of creating a new one 'l'
- Check compatible string length and existence of '.'
- Using simple_strtol() directly on the compatible sub-string
- Change variable 'bn' to 'barnum' which is self-documenting

Changes in v2:
- New patch to add several apis to decode pci device node

 include/fdtdec.h | 108 ++++++++++++++++++++++++++++++++----
 lib/fdtdec.c     | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 249 insertions(+), 25 deletions(-)
include/fdtdec.h +97 -11
index d2b665c..2b2652f 100644
@@ -50,6 +50,49 @@ struct fdt_resource {
 	fdt_addr_t end;
 };
 
+enum fdt_pci_space {
+	FDT_PCI_SPACE_CONFIG = 0,
+	FDT_PCI_SPACE_IO = 0x01000000,
+	FDT_PCI_SPACE_MEM32 = 0x02000000,
+	FDT_PCI_SPACE_MEM64 = 0x03000000,
+	FDT_PCI_SPACE_MEM32_PREF = 0x42000000,
+	FDT_PCI_SPACE_MEM64_PREF = 0x43000000,
+};
+
+#define FDT_PCI_ADDR_CELLS	3
+#define FDT_PCI_SIZE_CELLS	2
+#define FDT_PCI_REG_SIZE	\
+	((FDT_PCI_ADDR_CELLS + FDT_PCI_SIZE_CELLS) * sizeof(u32))
+
+/*
+ * The Open Firmware spec defines PCI physical address as follows:
+ *
+ *          bits# 31 .... 24 23 .... 16 15 .... 08 07 .... 00
+ *
+ * phys.hi  cell:  npt000ss   bbbbbbbb   dddddfff   rrrrrrrr
+ * phys.mid cell:  hhhhhhhh   hhhhhhhh   hhhhhhhh   hhhhhhhh
+ * phys.lo  cell:  llllllll   llllllll   llllllll   llllllll
+ *
+ * where:
+ *
+ * n:        is 0 if the address is relocatable, 1 otherwise
+ * p:        is 1 if addressable region is prefetchable, 0 otherwise
+ * t:        is 1 if the address is aliased (for non-relocatable I/O) below 1MB
+ *           (for Memory), or below 64KB (for relocatable I/O)
+ * ss:       is the space code, denoting the address space
+ * bbbbbbbb: is the 8-bit Bus Number
+ * ddddd:    is the 5-bit Device Number
+ * fff:      is the 3-bit Function Number
+ * rrrrrrrr: is the 8-bit Register Number
+ * hhhhhhhh: is a 32-bit unsigned number
+ * llllllll: is a 32-bit unsigned number
+ */
+struct fdt_pci_addr {
+	u32	phys_hi;
+	u32	phys_mid;
+	u32	phys_lo;
+};
+
 /**
  * Compute the size of a resource.
  *
@@ -252,6 +295,60 @@ fdt_addr_t fdtdec_get_addr_size(const void *blob, int node,
 		const char *prop_name, fdt_size_t *sizep);
 
 /**
+ * Look at an address property in a node and return the pci address which
+ * corresponds to the given type in the form of fdt_pci_addr.
+ * The property must hold one fdt_pci_addr with a lengh.
+ *
+ * @param blob		FDT blob
+ * @param node		node to examine
+ * @param type		pci address type (FDT_PCI_SPACE_xxx)
+ * @param prop_name	name of property to find
+ * @param addr		returns pci address in the form of fdt_pci_addr
+ * @return 0 if ok, negative on error
+ */
+int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type,
+		const char *prop_name, struct fdt_pci_addr *addr);
+
+/**
+ * Look at the compatible property of a device node that represents a PCI
+ * device and extract pci vendor id and device id from it.
+ *
+ * @param blob		FDT blob
+ * @param node		node to examine
+ * @param vendor	vendor id of the pci device
+ * @param device	device id of the pci device
+ * @return 0 if ok, negative on error
+ */
+int fdtdec_get_pci_vendev(const void *blob, int node,
+		u16 *vendor, u16 *device);
+
+/**
+ * Look at the pci address of a device node that represents a PCI device
+ * and parse the bus, device and function number from it.
+ *
+ * @param blob		FDT blob
+ * @param node		node to examine
+ * @param addr		pci address in the form of fdt_pci_addr
+ * @param bdf		returns bus, device, function triplet
+ * @return 0 if ok, negative on error
+ */
+int fdtdec_get_pci_bdf(const void *blob, int node,
+		struct fdt_pci_addr *addr, pci_dev_t *bdf);
+
+/**
+ * Look at the pci address of a device node that represents a PCI device
+ * and return base address of the pci device's registers.
+ *
+ * @param blob		FDT blob
+ * @param node		node to examine
+ * @param addr		pci address in the form of fdt_pci_addr
+ * @param bar		returns base address of the pci device's registers
+ * @return 0 if ok, negative on error
+ */
+int fdtdec_get_pci_bar32(const void *blob, int node,
+		struct fdt_pci_addr *addr, u32 *bar);
+
+/**
  * Look up a 32-bit integer property in a node and return it. The property
  * must have at least 4 bytes of data. The value of the first cell is
  * returned.
@@ -677,17 +774,6 @@ int fdt_get_named_resource(const void *fdt, int node, const char *property,
 			   struct fdt_resource *res);
 
 /**
- * Look at the reg property of a device node that represents a PCI device
- * and parse the bus, device and function number from it.
- *
- * @param fdt		FDT blob
- * @param node		node to examine
- * @param bdf		returns bus, device, function triplet
- * @return 0 if ok, negative on error
- */
-int fdtdec_pci_get_bdf(const void *fdt, int node, int *bdf);
-
-/**
  * Decode a named region within a memory bank of a given type.
  *
  * This function handles selection of a memory region. The region is
lib/fdtdec.c +152 -14

178 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#8 lore raw

PATCH v3 4/7 fdt: Add several apis to decode pci device node

Hi Bin,

Quoted 20 lines · Bin Meng

This commit adds several APIs to decode PCI device node according to the Open Firmware PCI bus bindings, including:
- fdtdec_get_pci_addr() for encoded pci address
- fdtdec_get_pci_vendev() for vendor id and device id
- fdtdec_get_pci_bdf() for pci device bdf triplet
- fdtdec_get_pci_bar32() for pci device register bar

---

Changes in v3:
- Fixed a typo: parant -> parent
- Return better error code in fdtdec_get_pci_addr()
- Add some debug output in fdtdec_get_pci_addr()
- Reuse variable 'len' instead of creating a new one 'l'
- Check compatible string length and existence of '.'
- Using simple_strtol() directly on the compatible sub-string
- Change variable 'bn' to 'barnum' which is self-documenting

Quoted 6 lines

Changes in v2:
- New patch to add several apis to decode pci device node

 include/fdtdec.h | 108 ++++++++++++++++++++++++++++++++----
 lib/fdtdec.c     | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 249 insertions(+), 25 deletions(-)

See question below...

Quoted 202 lines
include/fdtdec.h +97 -11
index d2b665c..2b2652f 100644
@@ -50,6 +50,49 @@ struct fdt_resource {
        fdt_addr_t end;
 };
 
+enum fdt_pci_space {
+       FDT_PCI_SPACE_CONFIG = 0,
+       FDT_PCI_SPACE_IO = 0x01000000,
+       FDT_PCI_SPACE_MEM32 = 0x02000000,
+       FDT_PCI_SPACE_MEM64 = 0x03000000,
+       FDT_PCI_SPACE_MEM32_PREF = 0x42000000,
+       FDT_PCI_SPACE_MEM64_PREF = 0x43000000,
+};
+
+#define FDT_PCI_ADDR_CELLS     3
+#define FDT_PCI_SIZE_CELLS     2
+#define FDT_PCI_REG_SIZE       \
+       ((FDT_PCI_ADDR_CELLS + FDT_PCI_SIZE_CELLS) * sizeof(u32))
+
+/*
+ * The Open Firmware spec defines PCI physical address as follows:
+ *
+ *          bits# 31 .... 24 23 .... 16 15 .... 08 07 .... 00
+ *
+ * phys.hi  cell:  npt000ss   bbbbbbbb   dddddfff   rrrrrrrr
+ * phys.mid cell:  hhhhhhhh   hhhhhhhh   hhhhhhhh   hhhhhhhh
+ * phys.lo  cell:  llllllll   llllllll   llllllll   llllllll
+ *
+ * where:
+ *
+ * n:        is 0 if the address is relocatable, 1 otherwise
+ * p:        is 1 if addressable region is prefetchable, 0 otherwise
+ * t:        is 1 if the address is aliased (for non-relocatable I/O) below 1MB
+ *           (for Memory), or below 64KB (for relocatable I/O)
+ * ss:       is the space code, denoting the address space
+ * bbbbbbbb: is the 8-bit Bus Number
+ * ddddd:    is the 5-bit Device Number
+ * fff:      is the 3-bit Function Number
+ * rrrrrrrr: is the 8-bit Register Number
+ * hhhhhhhh: is a 32-bit unsigned number
+ * llllllll: is a 32-bit unsigned number
+ */
+struct fdt_pci_addr {
+       u32     phys_hi;
+       u32     phys_mid;
+       u32     phys_lo;
+};
+
 /**
  * Compute the size of a resource.
  *
@@ -252,6 +295,60 @@ fdt_addr_t fdtdec_get_addr_size(const void *blob, int node,
                const char *prop_name, fdt_size_t *sizep);
 
 /**
+ * Look at an address property in a node and return the pci address which
+ * corresponds to the given type in the form of fdt_pci_addr.
+ * The property must hold one fdt_pci_addr with a lengh.
+ *
+ * @param blob         FDT blob
+ * @param node         node to examine
+ * @param type         pci address type (FDT_PCI_SPACE_xxx)
+ * @param prop_name    name of property to find
+ * @param addr         returns pci address in the form of fdt_pci_addr
+ * @return 0 if ok, negative on error
+ */
+int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type,
+               const char *prop_name, struct fdt_pci_addr *addr);
+
+/**
+ * Look at the compatible property of a device node that represents a PCI
+ * device and extract pci vendor id and device id from it.
+ *
+ * @param blob         FDT blob
+ * @param node         node to examine
+ * @param vendor       vendor id of the pci device
+ * @param device       device id of the pci device
+ * @return 0 if ok, negative on error
+ */
+int fdtdec_get_pci_vendev(const void *blob, int node,
+               u16 *vendor, u16 *device);
+
+/**
+ * Look at the pci address of a device node that represents a PCI device
+ * and parse the bus, device and function number from it.
+ *
+ * @param blob         FDT blob
+ * @param node         node to examine
+ * @param addr         pci address in the form of fdt_pci_addr
+ * @param bdf          returns bus, device, function triplet
+ * @return 0 if ok, negative on error
+ */
+int fdtdec_get_pci_bdf(const void *blob, int node,
+               struct fdt_pci_addr *addr, pci_dev_t *bdf);
+
+/**
+ * Look at the pci address of a device node that represents a PCI device
+ * and return base address of the pci device's registers.
+ *
+ * @param blob         FDT blob
+ * @param node         node to examine
+ * @param addr         pci address in the form of fdt_pci_addr
+ * @param bar          returns base address of the pci device's registers
+ * @return 0 if ok, negative on error
+ */
+int fdtdec_get_pci_bar32(const void *blob, int node,
+               struct fdt_pci_addr *addr, u32 *bar);
+
+/**
  * Look up a 32-bit integer property in a node and return it. The property
  * must have at least 4 bytes of data. The value of the first cell is
  * returned.
@@ -677,17 +774,6 @@ int fdt_get_named_resource(const void *fdt, int node, const char *property,
                           struct fdt_resource *res);
 
 /**
- * Look at the reg property of a device node that represents a PCI device
- * and parse the bus, device and function number from it.
- *
- * @param fdt          FDT blob
- * @param node         node to examine
- * @param bdf          returns bus, device, function triplet
- * @return 0 if ok, negative on error
- */
-int fdtdec_pci_get_bdf(const void *fdt, int node, int *bdf);
-
-/**
  * Decode a named region within a memory bank of a given type.
  *
  * This function handles selection of a memory region. The region is
lib/fdtdec.c +60 -0
index 9d86dba..a703f57 100644
@@ -121,6 +121,158 @@ fdt_addr_t fdtdec_get_addr(const void *blob, int node,
        return fdtdec_get_addr_size(blob, node, prop_name, NULL);
 }
 
+#ifdef CONFIG_PCI
+int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type,
+               const char *prop_name, struct fdt_pci_addr *addr)
+{
+       const u32 *cell;
+       int len;
+       int ret = -ENOENT;
+
+       debug("%s: %s: ", __func__, prop_name);
+
+       /*
+        * If we follow the pci bus bindings strictly, we should check
+        * the value of the node's parent node's #address-cells and
+        * #size-cells. They need to be 3 and 2 accordingly. However,
+        * for simplicity we skip the check here.
+        */
+       cell = fdt_getprop(blob, node, prop_name, &len);
+       if (!cell)
+               goto fail;
+
+       if ((len % FDT_PCI_REG_SIZE) == 0) {
+               int num = len / FDT_PCI_REG_SIZE;
+               int i;
+
+               for (i = 0; i < num; i++) {
+                       debug("pci address #%d: %08lx %08lx %08lx\n", i,
+                             (ulong)fdt_addr_to_cpu(cell[0]),
+                             (ulong)fdt_addr_to_cpu(cell[1]),
+                             (ulong)fdt_addr_to_cpu(cell[2]));
+                       if ((fdt_addr_to_cpu(*cell) & type) == type) {
+                               addr->phys_hi = fdt_addr_to_cpu(cell[0]);
+                               addr->phys_mid = fdt_addr_to_cpu(cell[1]);
+                               addr->phys_lo = fdt_addr_to_cpu(cell[2]);
+                               break;
+                       } else {
+                               cell += (FDT_PCI_ADDR_CELLS +
+                                        FDT_PCI_SIZE_CELLS);
+                       }
+               }
+
+               if (i == num)
+                       goto fail;
+
+               return 0;
+       } else {
+               ret = -EINVAL;
+       }
+
+fail:
+       debug("(not found)\n");
+       return ret;
+}
+
+int fdtdec_get_pci_vendev(const void *blob, int node, u16 *vendor, u16 *device)
+{
+       const char *list, *end;
+       int len;
+
+       list = fdt_getprop(blob, node, "compatible", &len);
+       if (!list)

lib/fdtdec.c fdt_addr_t fdtdec_get_addr(const void *blob, int node, · line 193

Quoted 10 lines
lib/fdtdec.c +10 -0
+               return -ENOENT;
+
+       end = list + len;
+       while (list < end) {
+               char *s;
+
+               len = strlen(list);
+               if (len > strlen("pciVVVV,DDDD")) {
+                       s = strstr(list, "pci");
+                       /* check if the string is something like pciVVVV,DDDD */

You are also requiring a revision ID here, but that doesn't seem to be absolutely required by the spec. This is fine if that's what you want, but should probably add a '.R'R at the end of of the comment. Another option would be to allow s[12] to be either '.' or \0. The subsystem ID is not supported which is fine.

Please let me know which way you'd like to go - and either I can fix it up before applying, or you can send a new patch.

Quoted 107 lines
lib/fdtdec.c +82 -15
+                       if (s && s[7] == ',' && s[12] == '.') {
+                               s += 3;
+                               *vendor = simple_strtol(s, NULL, 16);
+
+                               s += 5;
+                               *device = simple_strtol(s, NULL, 16);
+
+                               return 0;
+                       }
+               } else {
+                       list += (len + 1);
+               }
+       }
+
+       return -ENOENT;
+}
+
+int fdtdec_get_pci_bdf(const void *blob, int node,
+               struct fdt_pci_addr *addr, pci_dev_t *bdf)
+{
+       u16 dt_vendor, dt_device, vendor, device;
+       int ret;
+
+       /* get vendor id & device id from the compatible string */
+       ret = fdtdec_get_pci_vendev(blob, node, &dt_vendor, &dt_device);
+       if (ret)
+               return ret;
+
+       /* extract the bdf from fdt_pci_addr */
+       *bdf = addr->phys_hi & 0xffff00;
+
+       /* read vendor id & device id based on bdf */
+       pci_read_config_word(*bdf, PCI_VENDOR_ID, &vendor);
+       pci_read_config_word(*bdf, PCI_DEVICE_ID, &device);
+
+       /*
+        * Note there are two places in the device tree to fully describe
+        * a pci device: one is via compatible string with a format of
+        * "pciVVVV,DDDD" and the other one is the bdf numbers encoded in
+        * the device node's reg address property. We read the vendor id
+        * and device id based on bdf and compare the values with the
+        * "VVVV,DDDD". If they are the same, then we are good to use bdf
+        * to read device's bar. But if they are different, we have to rely
+        * on the vendor id and device id extracted from the compatible
+        * string and locate the real bdf by pci_find_device(). This is
+        * because normally we may only know device's device number and
+        * function number when writing device tree. The bus number is
+        * dynamically assigned during the pci enumeration process.
+        */
+       if ((dt_vendor != vendor) || (dt_device != device)) {
+               *bdf = pci_find_device(dt_vendor, dt_device, 0);
+               if (*bdf == -1)
+                       return -ENODEV;
+       }
+
+       return 0;
+}
+
+int fdtdec_get_pci_bar32(const void *blob, int node,
+               struct fdt_pci_addr *addr, u32 *bar)
+{
+       pci_dev_t bdf;
+       int barnum;
+       int ret;
+
+       /* get pci devices's bdf */
+       ret = fdtdec_get_pci_bdf(blob, node, addr, &bdf);
+       if (ret)
+               return ret;
+
+       /* extract the bar number from fdt_pci_addr */
+       barnum = addr->phys_hi & 0xff;
+       if ((barnum < PCI_BASE_ADDRESS_0) || (barnum > PCI_CARDBUS_CIS))
+               return -EINVAL;
+
+       barnum = (barnum - PCI_BASE_ADDRESS_0) / 4;
+       *bar = pci_read_bar32(pci_bus_to_hose(PCI_BUS(bdf)), bdf, barnum);
+
+       return 0;
+}
+#endif
+
 uint64_t fdtdec_get_uint64(const void *blob, int node, const char *prop_name,
                uint64_t default_val)
 {
@@ -790,20 +942,6 @@ int fdt_get_named_resource(const void *fdt, int node, const char *property,
        return fdt_get_resource(fdt, node, property, index, res);
 }
 
-int fdtdec_pci_get_bdf(const void *fdt, int node, int *bdf)
-{
-       const fdt32_t *prop;
-       int len;
-
-       prop = fdt_getprop(fdt, node, "reg", &len);
-       if (!prop)
-               return len;
-
-       *bdf = fdt32_to_cpu(*prop) & 0xffffff;
-
-       return 0;
-}
-
 int fdtdec_decode_memory_region(const void *blob, int config_node,
                                const char *mem_type, const char *suffix,
                                fdt_addr_t *basep, fdt_size_t *sizep)
--
Quoted 2 lines

1.8.2.1

Regards,
Simon

author
#9 lore raw

PATCH v3 4/7 fdt: Add several apis to decode pci device node

Hi Simon,

Quoted 244 lines · Simon Glass

Hi Bin,

Quoted 20 lines · Bin Meng

This commit adds several APIs to decode PCI device node according to the Open Firmware PCI bus bindings, including:
- fdtdec_get_pci_addr() for encoded pci address
- fdtdec_get_pci_vendev() for vendor id and device id
- fdtdec_get_pci_bdf() for pci device bdf triplet
- fdtdec_get_pci_bar32() for pci device register bar

---

Changes in v3:
- Fixed a typo: parant -> parent
- Return better error code in fdtdec_get_pci_addr()
- Add some debug output in fdtdec_get_pci_addr()
- Reuse variable 'len' instead of creating a new one 'l'
- Check compatible string length and existence of '.'
- Using simple_strtol() directly on the compatible sub-string
- Change variable 'bn' to 'barnum' which is self-documenting

Quoted 6 lines

Changes in v2:
- New patch to add several apis to decode pci device node

 include/fdtdec.h | 108 ++++++++++++++++++++++++++++++++----
 lib/fdtdec.c     | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 249 insertions(+), 25 deletions(-)

See question below...

Quoted 210 lines
include/fdtdec.h +97 -11
index d2b665c..2b2652f 100644
@@ -50,6 +50,49 @@ struct fdt_resource {
        fdt_addr_t end;
 };
 
+enum fdt_pci_space {
+       FDT_PCI_SPACE_CONFIG = 0,
+       FDT_PCI_SPACE_IO = 0x01000000,
+       FDT_PCI_SPACE_MEM32 = 0x02000000,
+       FDT_PCI_SPACE_MEM64 = 0x03000000,
+       FDT_PCI_SPACE_MEM32_PREF = 0x42000000,
+       FDT_PCI_SPACE_MEM64_PREF = 0x43000000,
+};
+
+#define FDT_PCI_ADDR_CELLS     3
+#define FDT_PCI_SIZE_CELLS     2
+#define FDT_PCI_REG_SIZE       \
+       ((FDT_PCI_ADDR_CELLS + FDT_PCI_SIZE_CELLS) * sizeof(u32))
+
+/*
+ * The Open Firmware spec defines PCI physical address as follows:
+ *
+ *          bits# 31 .... 24 23 .... 16 15 .... 08 07 .... 00
+ *
+ * phys.hi  cell:  npt000ss   bbbbbbbb   dddddfff   rrrrrrrr
+ * phys.mid cell:  hhhhhhhh   hhhhhhhh   hhhhhhhh   hhhhhhhh
+ * phys.lo  cell:  llllllll   llllllll   llllllll   llllllll
+ *
+ * where:
+ *
+ * n:        is 0 if the address is relocatable, 1 otherwise
+ * p:        is 1 if addressable region is prefetchable, 0 otherwise
+ * t:        is 1 if the address is aliased (for non-relocatable I/O) below 1MB
+ *           (for Memory), or below 64KB (for relocatable I/O)
+ * ss:       is the space code, denoting the address space
+ * bbbbbbbb: is the 8-bit Bus Number
+ * ddddd:    is the 5-bit Device Number
+ * fff:      is the 3-bit Function Number
+ * rrrrrrrr: is the 8-bit Register Number
+ * hhhhhhhh: is a 32-bit unsigned number
+ * llllllll: is a 32-bit unsigned number
+ */
+struct fdt_pci_addr {
+       u32     phys_hi;
+       u32     phys_mid;
+       u32     phys_lo;
+};
+
 /**
  * Compute the size of a resource.
  *
@@ -252,6 +295,60 @@ fdt_addr_t fdtdec_get_addr_size(const void *blob, int node,
                const char *prop_name, fdt_size_t *sizep);
 
 /**
+ * Look at an address property in a node and return the pci address which
+ * corresponds to the given type in the form of fdt_pci_addr.
+ * The property must hold one fdt_pci_addr with a lengh.
+ *
+ * @param blob         FDT blob
+ * @param node         node to examine
+ * @param type         pci address type (FDT_PCI_SPACE_xxx)
+ * @param prop_name    name of property to find
+ * @param addr         returns pci address in the form of fdt_pci_addr
+ * @return 0 if ok, negative on error
+ */
+int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type,
+               const char *prop_name, struct fdt_pci_addr *addr);
+
+/**
+ * Look at the compatible property of a device node that represents a PCI
+ * device and extract pci vendor id and device id from it.
+ *
+ * @param blob         FDT blob
+ * @param node         node to examine
+ * @param vendor       vendor id of the pci device
+ * @param device       device id of the pci device
+ * @return 0 if ok, negative on error
+ */
+int fdtdec_get_pci_vendev(const void *blob, int node,
+               u16 *vendor, u16 *device);
+
+/**
+ * Look at the pci address of a device node that represents a PCI device
+ * and parse the bus, device and function number from it.
+ *
+ * @param blob         FDT blob
+ * @param node         node to examine
+ * @param addr         pci address in the form of fdt_pci_addr
+ * @param bdf          returns bus, device, function triplet
+ * @return 0 if ok, negative on error
+ */
+int fdtdec_get_pci_bdf(const void *blob, int node,
+               struct fdt_pci_addr *addr, pci_dev_t *bdf);
+
+/**
+ * Look at the pci address of a device node that represents a PCI device
+ * and return base address of the pci device's registers.
+ *
+ * @param blob         FDT blob
+ * @param node         node to examine
+ * @param addr         pci address in the form of fdt_pci_addr
+ * @param bar          returns base address of the pci device's registers
+ * @return 0 if ok, negative on error
+ */
+int fdtdec_get_pci_bar32(const void *blob, int node,
+               struct fdt_pci_addr *addr, u32 *bar);
+
+/**
  * Look up a 32-bit integer property in a node and return it. The property
  * must have at least 4 bytes of data. The value of the first cell is
  * returned.
@@ -677,17 +774,6 @@ int fdt_get_named_resource(const void *fdt, int node, const char *property,
                           struct fdt_resource *res);
 
 /**
- * Look at the reg property of a device node that represents a PCI device
- * and parse the bus, device and function number from it.
- *
- * @param fdt          FDT blob
- * @param node         node to examine
- * @param bdf          returns bus, device, function triplet
- * @return 0 if ok, negative on error
- */
-int fdtdec_pci_get_bdf(const void *fdt, int node, int *bdf);
-
-/**
  * Decode a named region within a memory bank of a given type.
  *
  * This function handles selection of a memory region. The region is
lib/fdtdec.c +68 -0
index 9d86dba..a703f57 100644
@@ -121,6 +121,158 @@ fdt_addr_t fdtdec_get_addr(const void *blob, int node,
        return fdtdec_get_addr_size(blob, node, prop_name, NULL);
 }
 
+#ifdef CONFIG_PCI
+int fdtdec_get_pci_addr(const void *blob, int node, enum fdt_pci_space type,
+               const char *prop_name, struct fdt_pci_addr *addr)
+{
+       const u32 *cell;
+       int len;
+       int ret = -ENOENT;
+
+       debug("%s: %s: ", __func__, prop_name);
+
+       /*
+        * If we follow the pci bus bindings strictly, we should check
+        * the value of the node's parent node's #address-cells and
+        * #size-cells. They need to be 3 and 2 accordingly. However,
+        * for simplicity we skip the check here.
+        */
+       cell = fdt_getprop(blob, node, prop_name, &len);
+       if (!cell)
+               goto fail;
+
+       if ((len % FDT_PCI_REG_SIZE) == 0) {
+               int num = len / FDT_PCI_REG_SIZE;
+               int i;
+
+               for (i = 0; i < num; i++) {
+                       debug("pci address #%d: %08lx %08lx %08lx\n", i,
+                             (ulong)fdt_addr_to_cpu(cell[0]),
+                             (ulong)fdt_addr_to_cpu(cell[1]),
+                             (ulong)fdt_addr_to_cpu(cell[2]));
+                       if ((fdt_addr_to_cpu(*cell) & type) == type) {
+                               addr->phys_hi = fdt_addr_to_cpu(cell[0]);
+                               addr->phys_mid = fdt_addr_to_cpu(cell[1]);
+                               addr->phys_lo = fdt_addr_to_cpu(cell[2]);
+                               break;
+                       } else {
+                               cell += (FDT_PCI_ADDR_CELLS +
+                                        FDT_PCI_SIZE_CELLS);
+                       }
+               }
+
+               if (i == num)
+                       goto fail;
+
+               return 0;
+       } else {
+               ret = -EINVAL;
+       }
+
+fail:
+       debug("(not found)\n");
+       return ret;
+}
+
+int fdtdec_get_pci_vendev(const void *blob, int node, u16 *vendor, u16 *device)
+{
+       const char *list, *end;
+       int len;
+
+       list = fdt_getprop(blob, node, "compatible", &len);
+       if (!list)
+               return -ENOENT;
+
+       end = list + len;
+       while (list < end) {
+               char *s;
+
+               len = strlen(list);
+               if (len > strlen("pciVVVV,DDDD")) {
Quoted 8 lines

lib/fdtdec.c fdt_addr_t fdtdec_get_addr(const void *blob, int node, · line 193

Quoted 2 lines
lib/fdtdec.c +2 -0
+                       s = strstr(list, "pci");
+                       /* check if the string is something like pciVVVV,DDDD */

You are also requiring a revision ID here, but that doesn't seem to be absolutely required by the spec. This is fine if that's what you want, but should probably add a '.R'R at the end of of the comment. Another option would be to allow s[12] to be either '.' or \0. The subsystem ID is not supported which is fine.

I originally thought the pciVVVV,DDDD.RR should always be there in the device tree, but I think checking s[12] against \0 is not bad.

Quoted 2 lines

Please let me know which way you'd like to go - and either I can fix it up before applying, or you can send a new patch.

I will send a new patch to check s[12] against \0.

[snip]

Regards,
Bin

author
#10 lore raw

PATCH v3 5/7 serial: ns16550: Support ns16550 compatible pci uart devices

In reply to Bin Meng

There are many pci uart devices which are ns16550 compatible. We can describe them in the board dts file and use it as the U-Boot serial console as specified in the chosen node 'stdout-path' property.

Those pci uart devices can have their register be memory-mapped, or i/o-mapped. The driver will try to use the memory-mapped register if the reg property in the node has an entry to describe the memory-mapped register, otherwise i/o-mapped register will be used.

---

Changes in v3:
- Update to use 'memory-mapped' and 'i/o-mapped' in several places
- Use 'Processor Local Bus' instead of 'plb'
- Change the logic in ns16550_serial_ofdata_to_platdata() to avoid goto

Changes in v2:
- New patch to support ns16550 compatible pci uart devices

 drivers/serial/ns16550.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
drivers/serial/ns16550.c +31 -0
index af5beba..70c9462 100644
@@ -289,7 +289,38 @@ 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
#11 lore raw

PATCH v3 5/7 serial: ns16550: Support ns16550 compatible pci uart devices

Quoted 18 lines · Bin Meng

There are many pci uart devices which are ns16550 compatible. We can describe them in the board dts file and use it as the U-Boot serial console as specified in the chosen node 'stdout-path' property.

Those pci uart devices can have their register be memory-mapped, or i/o-mapped. The driver will try to use the memory-mapped register if the reg property in the node has an entry to describe the memory-mapped register, otherwise i/o-mapped register will be used.

---

Changes in v3:
- Update to use 'memory-mapped' and 'i/o-mapped' in several places
- Use 'Processor Local Bus' instead of 'plb'
- Change the logic in ns16550_serial_ofdata_to_platdata() to avoid goto

Quoted 5 lines

Changes in v2:
- New patch to support ns16550 compatible pci uart devices

 drivers/serial/ns16550.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
author
#12 lore raw

PATCH v3 6/7 x86: Use ePAPR defined properties for x86-uart

In reply to Bin Meng

Use ePAPR defined properties for x86-uart: clock-frequency and current-speed. Assign the value of clock-frequency in device tree to plat->clock of x86-uart instead of using hardcoded number.

---

Changes in v3: None
Changes in v2:
- New patch to use ePAPR defined properties for x86-uart

 arch/x86/dts/serial.dtsi    | 5 ++---
 drivers/serial/serial_x86.c | 8 +++++++-
 2 files changed, 9 insertions(+), 4 deletions(-)
arch/x86/dts/serial.dtsi +2 -3
index ebdda76..9b097f4 100644
@@ -3,8 +3,7 @@
 		compatible = "x86-uart";
 		reg = <0x3f8 8>;
 		reg-shift = <0>;
-		io-mapped = <1>;
-		multiplier = <1>;
-		baudrate = <115200>;
+		clock-frequency = <1843200>;
+		current-speed = <115200>;
 	};
 };
drivers/serial/serial_x86.c +7 -1
index e81e035..4bf6062 100644
@@ -6,9 +6,12 @@
 
 #include <common.h>
 #include <dm.h>
+#include <fdtdec.h>
 #include <ns16550.h>
 #include <serial.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 static const struct udevice_id x86_serial_ids[] = {
 	{ .compatible = "x86-uart" },
 	{ }
@@ -22,10 +25,13 @@ static int x86_serial_ofdata_to_platdata(struct udevice *dev)
 	ret = ns16550_serial_ofdata_to_platdata(dev);
 	if (ret)
 		return ret;
-	plat->clock = 1843200;
+
+	plat->clock = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
+				     "clock-frequency", 1843200);
 
 	return 0;
 }
+
 U_BOOT_DRIVER(serial_ns16550) = {
 	.name	= "serial_x86",
 	.id	= UCLASS_SERIAL,
Signature · 1 line
1.8.2.1
author
#13 lore raw

PATCH v3 7/7 x86: crownbay: Add pci devices in the dts file

In reply to Bin Meng

The Topcliff PCH has 4 UART devices integrated (Device 10, Funciton 1/2/3/4). Add the corresponding device nodes in the crownbay.dts per Open Firmware PCI bus bindings.

Also a comment block is added for the 'stdout-path' property in the chosen node, mentioning that by default the legacy superio serial port (io addr 0x3f8) is still used on Crown Bay as the console port.

---

Changes in v3: None
Changes in v2:
- New patch to add pci devices in crownbay.dts
- Drop v1 patch: Add an API for finding pci devices in the early phase
- Drop v1 patch: Support PCI UART in the x86_serial driver
- Drop v1 patch: Add PCI UART related defines in crownbay.h

 arch/x86/dts/crownbay.dts | 81 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)
arch/x86/dts/crownbay.dts +81 -0
index 97f7a52..a42e0e4 100644
@@ -32,6 +32,14 @@
 	};
 
 	chosen {
+		/*
+		 * By default the legacy superio serial port is used as the
+		 * U-Boot serial console. If we want to use UART from Topcliff
+		 * PCH as the console, change this property to &pciuart#.
+		 *
+		 * For example, stdout-path = &pciuart0 will use the first
+		 * UART on Topcliff PCH.
+		 */
 		stdout-path = "/serial";
 	};
 
@@ -52,4 +60,77 @@
 		};
 	};
 
+	pci {
+		#address-cells = <3>;
+		#size-cells = <2>;
+		compatible = "intel,pci";
+		device_type = "pci";
+
+		pcie at 17,0 {
+			#address-cells = <3>;
+			#size-cells = <2>;
+			compatible = "intel,pci";
+			device_type = "pci";
+
+			topcliff at 0,0 {
+				#address-cells = <3>;
+				#size-cells = <2>;
+				compatible = "intel,pci";
+				device_type = "pci";
+
+				pciuart0: uart at a,1 {
+					compatible = "pci8086,8811.0",
+							"pci8086,8811",
+							"pciclass070002",
+							"pciclass0700",
+							"x86-uart";
+					reg = <0x00025100 0x0 0x0 0x0 0x0
+					       0x01025110 0x0 0x0 0x0 0x0>;
+					reg-shift = <0>;
+					clock-frequency = <1843200>;
+					current-speed = <115200>;
+				};
+
+				pciuart1: uart at a,2 {
+					compatible = "pci8086,8812.0",
+							"pci8086,8812",
+							"pciclass070002",
+							"pciclass0700",
+							"x86-uart";
+					reg = <0x00025200 0x0 0x0 0x0 0x0
+					       0x01025210 0x0 0x0 0x0 0x0>;
+					reg-shift = <0>;
+					clock-frequency = <1843200>;
+					current-speed = <115200>;
+				};
+
+				pciuart2: uart at a,3 {
+					compatible = "pci8086,8813.0",
+							"pci8086,8813",
+							"pciclass070002",
+							"pciclass0700",
+							"x86-uart";
+					reg = <0x00025300 0x0 0x0 0x0 0x0
+					       0x01025310 0x0 0x0 0x0 0x0>;
+					reg-shift = <0>;
+					clock-frequency = <1843200>;
+					current-speed = <115200>;
+				};
+
+				pciuart3: uart at a,4 {
+					compatible = "pci8086,8814.0",
+							"pci8086,8814",
+							"pciclass070002",
+							"pciclass0700",
+							"x86-uart";
+					reg = <0x00025400 0x0 0x0 0x0 0x0
+					       0x01025410 0x0 0x0 0x0 0x0>;
+					reg-shift = <0>;
+					clock-frequency = <1843200>;
+					current-speed = <115200>;
+				};
+			};
+		};
+	};
+
 };
Signature · 1 line
1.8.2.1