Martin Roth merged this change.

View Change

Approvals: build bot (Jenkins): Verified Nico Huber: Looks good to me, approved Tim Wawrzynczak: Looks good to me, approved Paul Fagerburg: Looks good to me, but someone else must approve
soc/intel/common/block/uart: Update the UART PCI device reference

This implementation revises the UART PCI device reference in common
UART driver. The SOC functions have been aligned to provide the UART
PCI device reference using pcidev_path_on_root.

The uart_get_device() return type is changed, and files in which
it gets used are updated.

Change-Id: Ie0fe5991f3b0b9c596c3de9472e98e4091d7dd87
Signed-off-by: Aamir Bohra <aamir.bohra@intel.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/34582
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
---
M src/soc/intel/apollolake/uart.c
M src/soc/intel/cannonlake/uart.c
M src/soc/intel/common/block/include/intelblocks/uart.h
M src/soc/intel/common/block/uart/uart.c
M src/soc/intel/icelake/uart.c
M src/soc/intel/skylake/uart.c
6 files changed, 38 insertions(+), 31 deletions(-)

diff --git a/src/soc/intel/apollolake/uart.c b/src/soc/intel/apollolake/uart.c
index 27be4e6..f8c4aaf 100644
--- a/src/soc/intel/apollolake/uart.c
+++ b/src/soc/intel/apollolake/uart.c
@@ -74,7 +74,7 @@

const int uart_max_index = ARRAY_SIZE(uart_gpio_pads);

-struct device *soc_uart_console_to_device(int uart_console)
+DEVTREE_CONST struct device *soc_uart_console_to_device(int uart_console)
{
/*
* if index is valid, this function will return corresponding structure
@@ -82,13 +82,13 @@
*/
switch (uart_console) {
case 0:
- return (struct device *)PCH_DEV_UART0;
+ return pcidev_path_on_root(PCH_DEVFN_UART0);
case 1:
- return (struct device *)PCH_DEV_UART1;
+ return pcidev_path_on_root(PCH_DEVFN_UART1);
case 2:
- return (struct device *)PCH_DEV_UART2;
+ return pcidev_path_on_root(PCH_DEVFN_UART2);
case 3:
- return (struct device *)PCH_DEV_UART3;
+ return pcidev_path_on_root(PCH_DEVFN_UART3);
default:
printk(BIOS_ERR, "Invalid UART console index\n");
return NULL;
diff --git a/src/soc/intel/cannonlake/uart.c b/src/soc/intel/cannonlake/uart.c
index 7174a9a..ae19acc 100644
--- a/src/soc/intel/cannonlake/uart.c
+++ b/src/soc/intel/cannonlake/uart.c
@@ -50,7 +50,7 @@

const int uart_max_index = ARRAY_SIZE(uart_gpio_pads);

-struct device *soc_uart_console_to_device(int uart_console)
+DEVTREE_CONST struct device *soc_uart_console_to_device(int uart_console)
{
/*
* if index is valid, this function will return corresponding structure
@@ -58,11 +58,11 @@
*/
switch (uart_console) {
case 0:
- return (struct device *)PCH_DEV_UART0;
+ return pcidev_path_on_root(PCH_DEVFN_UART0);
case 1:
- return (struct device *)PCH_DEV_UART1;
+ return pcidev_path_on_root(PCH_DEVFN_UART1);
case 2:
- return (struct device *)PCH_DEV_UART2;
+ return pcidev_path_on_root(PCH_DEVFN_UART2);
default:
printk(BIOS_ERR, "Invalid UART console index\n");
return NULL;
diff --git a/src/soc/intel/common/block/include/intelblocks/uart.h b/src/soc/intel/common/block/include/intelblocks/uart.h
index 55f259d..1b62421 100644
--- a/src/soc/intel/common/block/include/intelblocks/uart.h
+++ b/src/soc/intel/common/block/include/intelblocks/uart.h
@@ -40,7 +40,7 @@
* Common routine to initialize UART controller PCI config space, take it out of
* reset and configure M/N dividers.
*/
-void uart_common_init(struct device *dev, uintptr_t baseaddr);
+void uart_common_init(const struct device *dev, uintptr_t baseaddr);

/*
* Check if UART debug controller is initialized
@@ -72,7 +72,7 @@
* Pointer to device structure = If device has a UART debug controller.
* NULL = otherwise
*/
-struct device *uart_get_device(void);
+const struct device *uart_get_device(void);

/**************************** SoC callbacks ***********************************/

@@ -89,6 +89,6 @@
* Pointer to device structure = If device has a UART debug controller.
* NULL = otherwise
*/
-struct device *soc_uart_console_to_device(int uart_console);
+DEVTREE_CONST struct device *soc_uart_console_to_device(int uart_console);

#endif /* SOC_INTEL_COMMON_BLOCK_UART_H */
diff --git a/src/soc/intel/common/block/uart/uart.c b/src/soc/intel/common/block/uart/uart.c
index 9d820ff..f556aed 100644
--- a/src/soc/intel/common/block/uart/uart.c
+++ b/src/soc/intel/common/block/uart/uart.c
@@ -65,15 +65,13 @@
return UART_CONSOLE_INVALID_INDEX;
}

-void uart_common_init(struct device *device, uintptr_t baseaddr)
+void uart_common_init(const struct device *device, uintptr_t baseaddr)
{
#if defined(__SIMPLE_DEVICE__)
- pci_devfn_t dev = (pci_devfn_t)(uintptr_t)device;
+ pci_devfn_t dev = PCI_BDF(device);
#else
- struct device *dev = device;
+ const struct device *dev = device;
#endif
- if (!dev)
- return;

/* Set UART base address */
pci_write_config32(dev, PCI_BASE_ADDRESS_0, baseaddr);
@@ -84,7 +82,7 @@
uart_lpss_init(baseaddr);
}

-struct device *uart_get_device(void)
+const struct device *uart_get_device(void)
{
/*
* This function will get called even if INTEL_LPSS_UART_FOR_CONSOLE
@@ -105,14 +103,16 @@
bool uart_is_controller_initialized(void)
{
uintptr_t base;
+ const struct device *dev_uart = uart_get_device();
+
+ if (!dev_uart)
+ return false;

#if defined(__SIMPLE_DEVICE__)
- pci_devfn_t dev = (pci_devfn_t)(uintptr_t)uart_get_device();
+ pci_devfn_t dev = PCI_BDF(dev_uart);
#else
- struct device *dev = uart_get_device();
+ const struct device *dev = dev_uart;
#endif
- if (!dev)
- return false;

base = pci_read_config32(dev, PCI_BASE_ADDRESS_0) & ~0xFFF;
if (!base)
@@ -136,8 +136,15 @@

void uart_bootblock_init(void)
{
+ const struct device *dev_uart;
+
+ dev_uart = uart_get_device();
+
+ if (!dev_uart)
+ return;
+
/* Program UART BAR0, command, reset and clock register */
- uart_common_init(uart_get_device(), CONFIG_CONSOLE_UART_BASE_ADDRESS);
+ uart_common_init(dev_uart, CONFIG_CONSOLE_UART_BASE_ADDRESS);

/* Configure the 2 pads per UART. */
uart_configure_gpio_pads();
diff --git a/src/soc/intel/icelake/uart.c b/src/soc/intel/icelake/uart.c
index 7174a9a..ae19acc 100644
--- a/src/soc/intel/icelake/uart.c
+++ b/src/soc/intel/icelake/uart.c
@@ -50,7 +50,7 @@

const int uart_max_index = ARRAY_SIZE(uart_gpio_pads);

-struct device *soc_uart_console_to_device(int uart_console)
+DEVTREE_CONST struct device *soc_uart_console_to_device(int uart_console)
{
/*
* if index is valid, this function will return corresponding structure
@@ -58,11 +58,11 @@
*/
switch (uart_console) {
case 0:
- return (struct device *)PCH_DEV_UART0;
+ return pcidev_path_on_root(PCH_DEVFN_UART0);
case 1:
- return (struct device *)PCH_DEV_UART1;
+ return pcidev_path_on_root(PCH_DEVFN_UART1);
case 2:
- return (struct device *)PCH_DEV_UART2;
+ return pcidev_path_on_root(PCH_DEVFN_UART2);
default:
printk(BIOS_ERR, "Invalid UART console index\n");
return NULL;
diff --git a/src/soc/intel/skylake/uart.c b/src/soc/intel/skylake/uart.c
index 8b7c99e..18fcf1b 100644
--- a/src/soc/intel/skylake/uart.c
+++ b/src/soc/intel/skylake/uart.c
@@ -51,7 +51,7 @@

const int uart_max_index = ARRAY_SIZE(uart_gpio_pads);

-struct device *soc_uart_console_to_device(int uart_console)
+DEVTREE_CONST struct device *soc_uart_console_to_device(int uart_console)
{
/*
* if index is valid, this function will return corresponding structure
@@ -59,11 +59,11 @@
*/
switch (uart_console) {
case 0:
- return (struct device *)PCH_DEV_UART0;
+ return pcidev_path_on_root(PCH_DEVFN_UART0);
case 1:
- return (struct device *)PCH_DEV_UART1;
+ return pcidev_path_on_root(PCH_DEVFN_UART1);
case 2:
- return (struct device *)PCH_DEV_UART2;
+ return pcidev_path_on_root(PCH_DEVFN_UART2);
default:
printk(BIOS_ERR, "Invalid UART console index\n");
return NULL;

To view, visit change 34582. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Ie0fe5991f3b0b9c596c3de9472e98e4091d7dd87
Gerrit-Change-Number: 34582
Gerrit-PatchSet: 7
Gerrit-Owner: Aamir Bohra <aamir.bohra@intel.com>
Gerrit-Reviewer: Aamir Bohra <aamir.bohra@intel.com>
Gerrit-Reviewer: Furquan Shaikh <furquan@google.com>
Gerrit-Reviewer: Karthik Ramasubramanian <kramasub@google.com>
Gerrit-Reviewer: Martin Roth <martinroth@google.com>
Gerrit-Reviewer: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: Patrick Rudolph <siro@das-labor.org>
Gerrit-Reviewer: Paul Fagerburg <pfagerburg@chromium.org>
Gerrit-Reviewer: Subrata Banik <subrata.banik@intel.com>
Gerrit-Reviewer: Tim Wawrzynczak <twawrzynczak@chromium.org>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-CC: Kyösti Mälkki <kyosti.malkki@gmail.com>
Gerrit-CC: Patrick Rudolph <patrick.rudolph@9elements.com>
Gerrit-CC: Paul Menzel <paulepanter@users.sourceforge.net>
Gerrit-MessageType: merged