[U-Boot] [PATCH v3 0/7] ACPI: Generate SPCR table

This is a series to enable SPCR table generation in U-Boot.
This table is useful to get early console in Linux for debugging purposes. The benefit of using it is not only for x86, but also for arm64 community (actually they introduced support in Linux kernel).
This implementation has been tested on Intel Edison with enabled ACPI support.
Known issue(s): - if the serial parameters are changed at run time, SPCR is not regenerated, thus, might not produce what user excepts (this is more likely design issue of U-Boot itself)
Changelog v3: - addressed Simon's and Alexander's comments - fix most known issues
Changelog v2: - drop WIP state - test on most recent U-Boot and Linux kernel
Andy Shevchenko (7): dm: serial: Add ->getconfig() callback dm: serial: Introduce ->getinfo() callback serial: ns16550: Group reg_* members of ns16550_platdata serial: ns16550: Read reg-io-width from device tree serial: ns16550: Provide ->getinfo() implementation x86: acpi: Add SPCR table description x86: acpi: Generate SPCR table
arch/x86/include/asm/acpi_table.h | 51 +++++++++++++ arch/x86/lib/acpi_table.c | 118 ++++++++++++++++++++++++++++++ drivers/serial/ns16550.c | 21 ++++++ drivers/serial/sandbox.c | 34 +++++++++ drivers/serial/serial-uclass.c | 37 ++++++++++ include/common.h | 4 + include/ns16550.h | 4 +- include/serial.h | 66 ++++++++++++++++- test/dm/serial.c | 12 +++ 9 files changed, 343 insertions(+), 4 deletions(-)
-- 2.19.1

In some cases it would be good to know the settings, such as parity, of current serial console. One example might be an ACPI SPCR table to generate using these parameters.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com --- drivers/serial/sandbox.c | 13 +++++++++++++ drivers/serial/serial-uclass.c | 16 ++++++++++++++++ include/common.h | 1 + include/serial.h | 26 +++++++++++++++++++++++--- test/dm/serial.c | 7 +++++++ 5 files changed, 60 insertions(+), 3 deletions(-)
diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c index 4a05ea44ce..76d26d3c59 100644 --- a/drivers/serial/sandbox.c +++ b/drivers/serial/sandbox.c @@ -163,6 +163,18 @@ DEBUG_UART_FUNCS
#endif /* CONFIG_DEBUG_UART_SANDBOX */
+static int sandbox_serial_getconfig(struct udevice *dev, uint *serial_config) +{ + uint config = SERIAL_DEFAULT_CONFIG; + + if (!serial_config) + return -EINVAL; + + *serial_config = config; + + return 0; +} + static int sandbox_serial_setconfig(struct udevice *dev, uint serial_config) { u8 parity = SERIAL_GET_PARITY(serial_config); @@ -207,6 +219,7 @@ static const struct dm_serial_ops sandbox_serial_ops = { .putc = sandbox_serial_putc, .pending = sandbox_serial_pending, .getc = sandbox_serial_getc, + .getconfig = sandbox_serial_getconfig, .setconfig = sandbox_serial_setconfig, };
diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c index 665cca85cb..d5a3b1255f 100644 --- a/drivers/serial/serial-uclass.c +++ b/drivers/serial/serial-uclass.c @@ -294,6 +294,20 @@ void serial_setbrg(void) ops->setbrg(gd->cur_serial_dev, gd->baudrate); }
+int serial_getconfig(uint *config) +{ + struct dm_serial_ops *ops; + + if (!gd->cur_serial_dev) + return 0; + + ops = serial_get_ops(gd->cur_serial_dev); + if (ops->getconfig) + return ops->getconfig(gd->cur_serial_dev, config); + + return 0; +} + int serial_setconfig(uint config) { struct dm_serial_ops *ops; @@ -419,6 +433,8 @@ static int serial_post_probe(struct udevice *dev) ops->pending += gd->reloc_off; if (ops->clear) ops->clear += gd->reloc_off; + if (ops->getconfig) + ops->getconfig += gd->reloc_off; if (ops->setconfig) ops->setconfig += gd->reloc_off; #if CONFIG_POST & CONFIG_SYS_POST_UART diff --git a/include/common.h b/include/common.h index 8b9f859c07..675495bde5 100644 --- a/include/common.h +++ b/include/common.h @@ -356,6 +356,7 @@ void serial_putc_raw(const char); void serial_puts (const char *); int serial_getc (void); int serial_tstc (void); +int serial_getconfig(uint *config); int serial_setconfig(uint config);
/* $(CPU)/speed.c */ diff --git a/include/serial.h b/include/serial.h index 020cd392e8..bc6d28ea86 100644 --- a/include/serial.h +++ b/include/serial.h @@ -75,6 +75,8 @@ enum serial_par {
#define SERIAL_PAR_SHIFT 0 #define SERIAL_PAR_MASK (0x03 << SERIAL_PAR_SHIFT) +#define SERIAL_SET_PARITY(parity) \ + ((parity << SERIAL_PAR_SHIFT) & SERIAL_PAR_MASK) #define SERIAL_GET_PARITY(config) \ ((config & SERIAL_PAR_MASK) >> SERIAL_PAR_SHIFT)
@@ -87,6 +89,8 @@ enum serial_bits {
#define SERIAL_BITS_SHIFT 2 #define SERIAL_BITS_MASK (0x3 << SERIAL_BITS_SHIFT) +#define SERIAL_SET_BITS(bits) \ + ((bits << SERIAL_BITS_SHIFT) & SERIAL_BITS_MASK) #define SERIAL_GET_BITS(config) \ ((config & SERIAL_BITS_MASK) >> SERIAL_BITS_SHIFT)
@@ -99,6 +103,8 @@ enum serial_stop {
#define SERIAL_STOP_SHIFT 4 #define SERIAL_STOP_MASK (0x3 << SERIAL_STOP_SHIFT) +#define SERIAL_SET_STOP(stop) \ + ((stop << SERIAL_STOP_SHIFT) & SERIAL_STOP_MASK) #define SERIAL_GET_STOP(config) \ ((config & SERIAL_STOP_MASK) >> SERIAL_STOP_SHIFT)
@@ -107,9 +113,10 @@ enum serial_stop { bits << SERIAL_BITS_SHIFT | \ stop << SERIAL_STOP_SHIFT)
-#define SERIAL_DEFAULT_CONFIG SERIAL_PAR_NONE << SERIAL_PAR_SHIFT | \ - SERIAL_8_BITS << SERIAL_BITS_SHIFT | \ - SERIAL_ONE_STOP << SERIAL_STOP_SHIFT +#define SERIAL_DEFAULT_CONFIG \ + (SERIAL_PAR_NONE << SERIAL_PAR_SHIFT | \ + SERIAL_8_BITS << SERIAL_BITS_SHIFT | \ + SERIAL_ONE_STOP << SERIAL_STOP_SHIFT)
/** * struct struct dm_serial_ops - Driver model serial operations @@ -188,6 +195,19 @@ struct dm_serial_ops { int (*loop)(struct udevice *dev, int on); #endif
+ /** + * getconfig() - Get the uart configuration + * (parity, 5/6/7/8 bits word length, stop bits) + * + * Get a current config for this device. + * + * @dev: Device pointer + * @parity: parity to use + * @bits: bits number to use + * @stop: stop bits number to use + * @return 0 if OK, -ve on error + */ + int (*getconfig)(struct udevice *dev, uint *serial_config); /** * setconfig() - Set up the uart configuration * (parity, 5/6/7/8 bits word length, stop bits) diff --git a/test/dm/serial.c b/test/dm/serial.c index 5c603e1f42..7a1a1526a4 100644 --- a/test/dm/serial.c +++ b/test/dm/serial.c @@ -12,6 +12,7 @@ static int dm_test_serial(struct unit_test_state *uts) { struct udevice *dev_serial; + uint value_serial;
ut_assertok(uclass_get_device_by_name(UCLASS_SERIAL, "serial", &dev_serial)); @@ -22,6 +23,12 @@ static int dm_test_serial(struct unit_test_state *uts) * sandbox_serial driver */ ut_assertok(serial_setconfig(SERIAL_DEFAULT_CONFIG)); + ut_assertok(serial_getconfig(&value_serial)); + ut_assert(value_serial == SERIAL_DEFAULT_CONFIG); + /* + * test with a parameter which is NULL pointer + */ + ut_asserteq(-EINVAL, serial_getconfig(NULL)); /* * test with a serial config which is not supported by * sandbox_serial driver: test with wrong parity

Hi Andy,
On Tue, 20 Nov 2018 at 14:52, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
In some cases it would be good to know the settings, such as parity, of current serial console. One example might be an ACPI SPCR table to generate using these parameters.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com
drivers/serial/sandbox.c | 13 +++++++++++++ drivers/serial/serial-uclass.c | 16 ++++++++++++++++ include/common.h | 1 + include/serial.h | 26 +++++++++++++++++++++++--- test/dm/serial.c | 7 +++++++ 5 files changed, 60 insertions(+), 3 deletions(-)
My only concern is that serial_get_config() should have a device parameter.
Regards, Simon

On Mon, Nov 26, 2018 at 06:02:28PM -0700, Simon Glass wrote:
Hi Andy,
On Tue, 20 Nov 2018 at 14:52, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
In some cases it would be good to know the settings, such as parity, of current serial console. One example might be an ACPI SPCR table to generate using these parameters.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com
drivers/serial/sandbox.c | 13 +++++++++++++ drivers/serial/serial-uclass.c | 16 ++++++++++++++++ include/common.h | 1 + include/serial.h | 26 +++++++++++++++++++++++--- test/dm/serial.c | 7 +++++++ 5 files changed, 60 insertions(+), 3 deletions(-)
My only concern is that serial_get_config() should have a device parameter.
It's obviously out of scope of this series.
The rest of similar functions are operate on top of current console device and do not have such parameter, while being DM-based functions.
I would gladly rebase my series on top any work which is done regard above request. For now, I don't see such possibility.

On Tue, Nov 27, 2018 at 06:02:54PM +0200, Andy Shevchenko wrote:
On Mon, Nov 26, 2018 at 06:02:28PM -0700, Simon Glass wrote:
On Tue, 20 Nov 2018 at 14:52, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
In some cases it would be good to know the settings, such as parity, of current serial console. One example might be an ACPI SPCR table to generate using these parameters.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com
drivers/serial/sandbox.c | 13 +++++++++++++ drivers/serial/serial-uclass.c | 16 ++++++++++++++++ include/common.h | 1 + include/serial.h | 26 +++++++++++++++++++++++--- test/dm/serial.c | 7 +++++++ 5 files changed, 60 insertions(+), 3 deletions(-)
My only concern is that serial_get_config() should have a device parameter.
It's obviously out of scope of this series.
The rest of similar functions are operate on top of current console device and do not have such parameter, while being DM-based functions.
I would gladly rebase my series on top any work which is done regard above request. For now, I don't see such possibility.
So, time passed w/o a single action to this.
Is the feature undesirable? I would easily stop doing it, it consumes valuable time.

HI Andy,
On Tue, 27 Nov 2018 at 09:03, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
On Mon, Nov 26, 2018 at 06:02:28PM -0700, Simon Glass wrote:
Hi Andy,
On Tue, 20 Nov 2018 at 14:52, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
In some cases it would be good to know the settings, such as parity, of current serial console. One example might be an ACPI SPCR table to generate using these parameters.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com
drivers/serial/sandbox.c | 13 +++++++++++++ drivers/serial/serial-uclass.c | 16 ++++++++++++++++ include/common.h | 1 + include/serial.h | 26 +++++++++++++++++++++++--- test/dm/serial.c | 7 +++++++ 5 files changed, 60 insertions(+), 3 deletions(-)
My only concern is that serial_get_config() should have a device parameter.
It's obviously out of scope of this series.
The rest of similar functions are operate on top of current console device and do not have such parameter, while being DM-based functions.
I would gladly rebase my series on top any work which is done regard above request. For now, I don't see such possibility.
My point is that you are adding a new function which does not use driver model properly. The serial_getconfig() function should have a device parameter, and it should not support non-DM, since it is a new feature.
I'm going to pick this up, absent any other issues, and see if I can do a patch for it afterwards.
Reviewed-by: Simon Glass sjg@chromium.org
Regards, Simon

On Wed, Dec 05, 2018 at 05:55:37AM -0700, Simon Glass wrote:
On Tue, 27 Nov 2018 at 09:03, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
On Mon, Nov 26, 2018 at 06:02:28PM -0700, Simon Glass wrote:
The rest of similar functions are operate on top of current console device and do not have such parameter, while being DM-based functions.
I would gladly rebase my series on top any work which is done regard above request. For now, I don't see such possibility.
My point is that you are adding a new function which does not use driver model properly. The serial_getconfig() function should have a device parameter, and it should not support non-DM, since it is a new feature.
I understand that, OTOH I can repeat myself that this would be very inconsistent with preexisting set of the functions. In my opinion that must be fixed altogether either before or after, but at once.
I'm going to pick this up, absent any other issues, and see if I can do a patch for it afterwards.
Reviewed-by: Simon Glass sjg@chromium.org
Thank you for review, and sorry for being persuader, I have several big tasks to be accomplished before my vacation starts.

Hi Andy,
On Wed, 5 Dec 2018 at 07:01, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
On Wed, Dec 05, 2018 at 05:55:37AM -0700, Simon Glass wrote:
On Tue, 27 Nov 2018 at 09:03, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
On Mon, Nov 26, 2018 at 06:02:28PM -0700, Simon Glass wrote:
The rest of similar functions are operate on top of current console device and do not have such parameter, while being DM-based functions.
I would gladly rebase my series on top any work which is done regard above request. For now, I don't see such possibility.
My point is that you are adding a new function which does not use driver model properly. The serial_getconfig() function should have a device parameter, and it should not support non-DM, since it is a new feature.
I understand that, OTOH I can repeat myself that this would be very inconsistent with preexisting set of the functions. In my opinion that must be fixed altogether either before or after, but at once.
I don't think we can do that until DM migration is complete. But perhaps I am missing something.
I'm going to pick this up, absent any other issues, and see if I can do a patch for it afterwards.
Reviewed-by: Simon Glass sjg@chromium.org
Thank you for review, and sorry for being persuader, I have several big tasks to be accomplished before my vacation starts.
So, given all my effort here, am I invited? :-)
Regards, Simon

Hi Andy,
On Wed, 5 Dec 2018 at 07:01, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
On Wed, Dec 05, 2018 at 05:55:37AM -0700, Simon Glass wrote:
On Tue, 27 Nov 2018 at 09:03, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
On Mon, Nov 26, 2018 at 06:02:28PM -0700, Simon Glass wrote:
The rest of similar functions are operate on top of current console device and do not have such parameter, while being DM-based functions.
I would gladly rebase my series on top any work which is done regard above request. For now, I don't see such possibility.
My point is that you are adding a new function which does not use driver model properly. The serial_getconfig() function should have a device parameter, and it should not support non-DM, since it is a new feature.
I understand that, OTOH I can repeat myself that this would be very inconsistent with preexisting set of the functions. In my opinion that must be fixed altogether either before or after, but at once.
I don't think we can do that until DM migration is complete. But perhaps I am missing something.
I'm going to pick this up, absent any other issues, and see if I can do a patch for it afterwards.
Reviewed-by: Simon Glass sjg@chromium.org
Thank you for review, and sorry for being persuader, I have several big tasks to be accomplished before my vacation starts.
So, given all my effort here, am I invited? :-)
Regards, Simon
Applied to u-boot-dm/master, thanks!

New callback will give a necessary information to fill up ACPI SPCR table, for example. Maybe used later for other purposes.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com --- drivers/serial/sandbox.c | 21 ++++++++++++++++++ drivers/serial/serial-uclass.c | 21 ++++++++++++++++++ include/common.h | 3 +++ include/serial.h | 40 ++++++++++++++++++++++++++++++++++ test/dm/serial.c | 5 +++++ 5 files changed, 90 insertions(+)
diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c index 76d26d3c59..c510a6ed36 100644 --- a/drivers/serial/sandbox.c +++ b/drivers/serial/sandbox.c @@ -188,6 +188,26 @@ static int sandbox_serial_setconfig(struct udevice *dev, uint serial_config) return 0; }
+static int sandbox_serial_getinfo(struct udevice *dev, + struct serial_device_info *serial_info) +{ + struct serial_device_info info = { + .type = SERIAL_CHIP_UNKNOWN, + .addr_space = ADR_SPACE_SYSTEM_IO, + .addr = SERIAL_DEFAULT_ADDRESS, + .reg_width = 1, + .reg_offset = 0, + .reg_shift = 0, + }; + + if (!serial_info) + return -EINVAL; + + *serial_info = info; + + return 0; +} + #if CONFIG_IS_ENABLED(OF_CONTROL) static const char * const ansi_colour[] = { "black", "red", "green", "yellow", "blue", "megenta", "cyan", @@ -221,6 +241,7 @@ static const struct dm_serial_ops sandbox_serial_ops = { .getc = sandbox_serial_getc, .getconfig = sandbox_serial_getconfig, .setconfig = sandbox_serial_setconfig, + .getinfo = sandbox_serial_getinfo, };
static const struct udevice_id sandbox_serial_ids[] = { diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c index d5a3b1255f..8dc8a6788d 100644 --- a/drivers/serial/serial-uclass.c +++ b/drivers/serial/serial-uclass.c @@ -322,6 +322,25 @@ int serial_setconfig(uint config) return 0; }
+int serial_getinfo(struct serial_device_info *info) +{ + struct dm_serial_ops *ops; + + if (!gd->cur_serial_dev) + return -ENODEV; + + if (!info) + return -EINVAL; + + info->baudrate = gd->baudrate; + + ops = serial_get_ops(gd->cur_serial_dev); + if (ops->getinfo) + return ops->getinfo(gd->cur_serial_dev, info); + + return -EINVAL; +} + void serial_stdio_init(void) { } @@ -441,6 +460,8 @@ static int serial_post_probe(struct udevice *dev) if (ops->loop) ops->loop += gd->reloc_off; #endif + if (ops->getinfo) + ops->getinfo += gd->reloc_off; #endif /* Set the baud rate */ if (ops->setbrg) { diff --git a/include/common.h b/include/common.h index 675495bde5..ea1fef0b24 100644 --- a/include/common.h +++ b/include/common.h @@ -349,6 +349,8 @@ void smp_set_core_boot_addr(unsigned long addr, int corenr); void smp_kick_all_cpus(void);
/* $(CPU)/serial.c */ +struct serial_device_info; + int serial_init (void); void serial_setbrg (void); void serial_putc (const char); @@ -358,6 +360,7 @@ int serial_getc (void); int serial_tstc (void); int serial_getconfig(uint *config); int serial_setconfig(uint config); +int serial_getinfo(struct serial_device_info *info);
/* $(CPU)/speed.c */ int get_clocks (void); diff --git a/include/serial.h b/include/serial.h index bc6d28ea86..ca549d45aa 100644 --- a/include/serial.h +++ b/include/serial.h @@ -118,6 +118,39 @@ enum serial_stop { SERIAL_8_BITS << SERIAL_BITS_SHIFT | \ SERIAL_ONE_STOP << SERIAL_STOP_SHIFT)
+enum serial_chip_type { + SERIAL_CHIP_UNKNOWN = -1, + SERIAL_CHIP_16550_COMPATIBLE, +}; + +enum adr_space_type { + SERIAL_ADDRESS_SPACE_MEMORY = 0, + SERIAL_ADDRESS_SPACE_IO, +}; + +/** + * struct serial_device_info - structure to hold serial device info + * + * @type: type of the UART chip + * @addr_space: address space to access the registers + * @addr: physical address of the registers + * @reg_width: size (in bytes) of the IO accesses to the registers + * @reg_offset: offset to apply to the @addr from the start of the registers + * @reg_shift: quantity to shift the register offsets by + * @baudrate: baud rate + */ +struct serial_device_info { + enum serial_chip_type type; + enum adr_space_type addr_space; + ulong addr; + u8 reg_width; + u8 reg_offset; + u8 reg_shift; + unsigned int baudrate; +}; + +#define SERIAL_DEFAULT_ADDRESS 0xBADACCE5 + /** * struct struct dm_serial_ops - Driver model serial operations * @@ -221,6 +254,13 @@ struct dm_serial_ops { * @return 0 if OK, -ve on error */ int (*setconfig)(struct udevice *dev, uint serial_config); + /** + * getinfo() - Get serial device information + * + * @dev: Device pointer + * @info: struct serial_device_info to fill + */ + int (*getinfo)(struct udevice *dev, struct serial_device_info *info); };
/** diff --git a/test/dm/serial.c b/test/dm/serial.c index 7a1a1526a4..19a15d5d95 100644 --- a/test/dm/serial.c +++ b/test/dm/serial.c @@ -11,6 +11,7 @@
static int dm_test_serial(struct unit_test_state *uts) { + struct serial_device_info info_serial = {0}; struct udevice *dev_serial; uint value_serial;
@@ -25,10 +26,14 @@ static int dm_test_serial(struct unit_test_state *uts) ut_assertok(serial_setconfig(SERIAL_DEFAULT_CONFIG)); ut_assertok(serial_getconfig(&value_serial)); ut_assert(value_serial == SERIAL_DEFAULT_CONFIG); + ut_assertok(serial_getinfo(&info_serial)); + ut_assert(info_serial.type == SERIAL_CHIP_UNKNOWN); + ut_assert(info_serial.addr == SERIAL_DEFAULT_ADDRESS); /* * test with a parameter which is NULL pointer */ ut_asserteq(-EINVAL, serial_getconfig(NULL)); + ut_asserteq(-EINVAL, serial_getinfo(NULL)); /* * test with a serial config which is not supported by * sandbox_serial driver: test with wrong parity

On Tue, 20 Nov 2018 at 14:52, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
New callback will give a necessary information to fill up ACPI SPCR table, for example. Maybe used later for other purposes.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com
drivers/serial/sandbox.c | 21 ++++++++++++++++++ drivers/serial/serial-uclass.c | 21 ++++++++++++++++++ include/common.h | 3 +++ include/serial.h | 40 ++++++++++++++++++++++++++++++++++ test/dm/serial.c | 5 +++++ 5 files changed, 90 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

On Tue, 20 Nov 2018 at 14:52, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
New callback will give a necessary information to fill up ACPI SPCR table, for example. Maybe used later for other purposes.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com
drivers/serial/sandbox.c | 21 ++++++++++++++++++ drivers/serial/serial-uclass.c | 21 ++++++++++++++++++ include/common.h | 3 +++ include/serial.h | 40 ++++++++++++++++++++++++++++++++++ test/dm/serial.c | 5 +++++ 5 files changed, 90 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot-dm/master, thanks!

Group reg_* members of struct ns16550_platdata together for better maintenance.
No functional change intended.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com --- include/ns16550.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/ns16550.h b/include/ns16550.h index 5fcbcd2e74..f565645d65 100644 --- a/include/ns16550.h +++ b/include/ns16550.h @@ -55,8 +55,8 @@ struct ns16550_platdata { unsigned long base; int reg_shift; - int clock; int reg_offset; + int clock; u32 fcr; };

On Tue, 20 Nov 2018 at 14:52, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
Group reg_* members of struct ns16550_platdata together for better maintenance.
No functional change intended.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com
include/ns16550.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Tue, 20 Nov 2018 at 14:52, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
Group reg_* members of struct ns16550_platdata together for better maintenance.
No functional change intended.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com
include/ns16550.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot-dm/master, thanks!

Cache the value of the reg-io-width property for the future use.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com --- drivers/serial/ns16550.c | 1 + include/ns16550.h | 2 ++ 2 files changed, 3 insertions(+)
diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c index f9041aa626..b51b56de9f 100644 --- a/drivers/serial/ns16550.c +++ b/drivers/serial/ns16550.c @@ -408,6 +408,7 @@ int ns16550_serial_ofdata_to_platdata(struct udevice *dev)
plat->reg_offset = dev_read_u32_default(dev, "reg-offset", 0); plat->reg_shift = dev_read_u32_default(dev, "reg-shift", 0); + plat->reg_width = dev_read_u32_default(dev, "reg-io-width", 1);
err = clk_get_by_index(dev, 0, &clk); if (!err) { diff --git a/include/ns16550.h b/include/ns16550.h index f565645d65..22b89e4d6d 100644 --- a/include/ns16550.h +++ b/include/ns16550.h @@ -49,11 +49,13 @@ * struct ns16550_platdata - information about a NS16550 port * * @base: Base register address + * @reg_width: IO accesses size of registers (in bytes) * @reg_shift: Shift size of registers (0=byte, 1=16bit, 2=32bit...) * @clock: UART base clock speed in Hz */ struct ns16550_platdata { unsigned long base; + int reg_width; int reg_shift; int reg_offset; int clock;

On Tue, 20 Nov 2018 at 14:52, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
Cache the value of the reg-io-width property for the future use.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com
drivers/serial/ns16550.c | 1 + include/ns16550.h | 2 ++ 2 files changed, 3 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

On Tue, 20 Nov 2018 at 14:52, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
Cache the value of the reg-io-width property for the future use.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com
drivers/serial/ns16550.c | 1 + include/ns16550.h | 2 ++ 2 files changed, 3 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot-dm/master, thanks!

New callback will supply necessary information, for example, to ACPI SPCR table.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com --- drivers/serial/ns16550.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c index b51b56de9f..226c5daf50 100644 --- a/drivers/serial/ns16550.c +++ b/drivers/serial/ns16550.c @@ -334,6 +334,25 @@ static int ns16550_serial_setbrg(struct udevice *dev, int baudrate) return 0; }
+static int ns16550_serial_getinfo(struct udevice *dev, + struct serial_device_info *info) +{ + struct NS16550 *const com_port = dev_get_priv(dev); + struct ns16550_platdata *plat = com_port->plat; + + info->type = SERIAL_CHIP_16550_COMPATIBLE; +#ifdef CONFIG_SYS_NS16550_PORT_MAPPED + info->addr_space = SERIAL_ADDRESS_SPACE_IO; +#else + info->addr_space = SERIAL_ADDRESS_SPACE_MEMORY; +#endif + info->addr = plat->base; + info->reg_width = plat->reg_width; + info->reg_shift = plat->reg_shift; + info->reg_offset = plat->reg_offset; + return 0; +} + int ns16550_serial_probe(struct udevice *dev) { struct NS16550 *const com_port = dev_get_priv(dev); @@ -441,6 +460,7 @@ const struct dm_serial_ops ns16550_serial_ops = { .pending = ns16550_serial_pending, .getc = ns16550_serial_getc, .setbrg = ns16550_serial_setbrg, + .getinfo = ns16550_serial_getinfo, };
#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)

On Tue, 20 Nov 2018 at 14:52, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
New callback will supply necessary information, for example, to ACPI SPCR table.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com
drivers/serial/ns16550.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

On Tue, 20 Nov 2018 at 14:52, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
New callback will supply necessary information, for example, to ACPI SPCR table.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com
drivers/serial/ns16550.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot-dm/master, thanks!

Add SPCR table description as it provided in Linux kernel.
Port subtype for ACPI_DBG2_SERIAL_PORT is used as an interface type in SPCR. Thus, provide a set of definitions to be utilized later.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com Reviewed-by: Bin Meng bmeng.cn@gmail.com --- arch/x86/include/asm/acpi_table.h | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
diff --git a/arch/x86/include/asm/acpi_table.h b/arch/x86/include/asm/acpi_table.h index 95fae036f6..51cc806673 100644 --- a/arch/x86/include/asm/acpi_table.h +++ b/arch/x86/include/asm/acpi_table.h @@ -303,6 +303,55 @@ struct acpi_mcfg_mmconfig { /* ACPI global NVS structure */ struct acpi_global_nvs;
+/* DBG2 definitions are partially used for SPCR interface_type */ + +/* Types for port_type field */ + +#define ACPI_DBG2_SERIAL_PORT 0x8000 +#define ACPI_DBG2_1394_PORT 0x8001 +#define ACPI_DBG2_USB_PORT 0x8002 +#define ACPI_DBG2_NET_PORT 0x8003 + +/* Subtypes for port_subtype field */ + +#define ACPI_DBG2_16550_COMPATIBLE 0x0000 +#define ACPI_DBG2_16550_SUBSET 0x0001 +#define ACPI_DBG2_ARM_PL011 0x0003 +#define ACPI_DBG2_ARM_SBSA_32BIT 0x000D +#define ACPI_DBG2_ARM_SBSA_GENERIC 0x000E +#define ACPI_DBG2_ARM_DCC 0x000F +#define ACPI_DBG2_BCM2835 0x0010 + +#define ACPI_DBG2_1394_STANDARD 0x0000 + +#define ACPI_DBG2_USB_XHCI 0x0000 +#define ACPI_DBG2_USB_EHCI 0x0001 + +/* SPCR (Serial Port Console Redirection table) */ +struct __packed acpi_spcr { + struct acpi_table_header header; + u8 interface_type; + u8 reserved[3]; + struct acpi_gen_regaddr serial_port; + u8 interrupt_type; + u8 pc_interrupt; + u32 interrupt; /* Global system interrupt */ + u8 baud_rate; + u8 parity; + u8 stop_bits; + u8 flow_control; + u8 terminal_type; + u8 reserved1; + u16 pci_device_id; /* Must be 0xffff if not PCI device */ + u16 pci_vendor_id; /* Must be 0xffff if not PCI device */ + u8 pci_bus; + u8 pci_device; + u8 pci_function; + u32 pci_flags; + u8 pci_segment; + u32 reserved2; +}; + /* These can be used by the target port */
void acpi_fill_header(struct acpi_table_header *header, char *signature);

Add SPCR table description as it provided in Linux kernel.
Port subtype for ACPI_DBG2_SERIAL_PORT is used as an interface type in SPCR. Thus, provide a set of definitions to be utilized later.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com Reviewed-by: Bin Meng bmeng.cn@gmail.com --- arch/x86/include/asm/acpi_table.h | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
Applied to u-boot-dm/master, thanks!

Microsoft specifies a SPCR (Serial Port Console Redirection Table) [1]. Let's provide it in U-Boot.
[1]: https://docs.microsoft.com/en-us/windows-hardware/drivers/serports/serial-po...
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com --- arch/x86/include/asm/acpi_table.h | 2 + arch/x86/lib/acpi_table.c | 118 ++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+)
diff --git a/arch/x86/include/asm/acpi_table.h b/arch/x86/include/asm/acpi_table.h index 51cc806673..e3b65cff66 100644 --- a/arch/x86/include/asm/acpi_table.h +++ b/arch/x86/include/asm/acpi_table.h @@ -327,6 +327,8 @@ struct acpi_global_nvs; #define ACPI_DBG2_USB_XHCI 0x0000 #define ACPI_DBG2_USB_EHCI 0x0001
+#define ACPI_DBG2_UNKNOWN 0x00FF + /* SPCR (Serial Port Console Redirection table) */ struct __packed acpi_spcr { struct acpi_table_header header; diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c index c6b2026613..5a37a22c8c 100644 --- a/arch/x86/lib/acpi_table.c +++ b/arch/x86/lib/acpi_table.c @@ -12,6 +12,7 @@ #include <cpu.h> #include <dm.h> #include <dm/uclass-internal.h> +#include <serial.h> #include <version.h> #include <asm/acpi/global_nvs.h> #include <asm/acpi_table.h> @@ -338,6 +339,115 @@ static void acpi_create_mcfg(struct acpi_mcfg *mcfg) header->checksum = table_compute_checksum((void *)mcfg, header->length); }
+static void acpi_create_spcr(struct acpi_spcr *spcr) +{ + struct acpi_table_header *header = &(spcr->header); + struct serial_device_info serial_info = {0}; + ulong serial_address, serial_offset; + uint serial_config; + uint serial_width; + int access_size; + int space_id; + int ret; + + /* Fill out header fields */ + acpi_fill_header(header, "SPCR"); + header->length = sizeof(struct acpi_spcr); + header->revision = 2; + + ret = serial_getinfo(&serial_info); + if (ret) + serial_info.type = SERIAL_CHIP_UNKNOWN; + + /* Encode chip type */ + switch (serial_info.type) { + case SERIAL_CHIP_16550_COMPATIBLE: + spcr->interface_type = ACPI_DBG2_16550_COMPATIBLE; + break; + case SERIAL_CHIP_UNKNOWN: + default: + spcr->interface_type = ACPI_DBG2_UNKNOWN; + break; + } + + /* Encode address space */ + switch (serial_info.addr_space) { + case SERIAL_ADDRESS_SPACE_MEMORY: + space_id = ACPI_ADDRESS_SPACE_MEMORY; + break; + case SERIAL_ADDRESS_SPACE_IO: + default: + space_id = ACPI_ADDRESS_SPACE_IO; + break; + } + + serial_width = serial_info.reg_width * 8; + serial_offset = serial_info.reg_offset << serial_info.reg_shift; + serial_address = serial_info.addr + serial_offset; + + /* Encode register access size */ + switch (serial_info.reg_shift) { + case 0: + access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; + break; + case 1: + access_size = ACPI_ACCESS_SIZE_WORD_ACCESS; + break; + case 2: + access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; + break; + case 3: + access_size = ACPI_ACCESS_SIZE_QWORD_ACCESS; + break; + default: + access_size = ACPI_ACCESS_SIZE_UNDEFINED; + break; + } + + debug("UART type %u @ %lx\n", spcr->interface_type, serial_address); + + /* Fill GAS */ + spcr->serial_port.space_id = space_id; + spcr->serial_port.bit_width = serial_width; + spcr->serial_port.bit_offset = 0; + spcr->serial_port.access_size = access_size; + spcr->serial_port.addrl = lower_32_bits(serial_address); + spcr->serial_port.addrh = upper_32_bits(serial_address); + + /* Encode baud rate */ + switch (serial_info.baudrate) { + case 9600: + spcr->baud_rate = 3; + break; + case 19200: + spcr->baud_rate = 4; + break; + case 57600: + spcr->baud_rate = 6; + break; + case 115200: + spcr->baud_rate = 7; + break; + default: + spcr->baud_rate = 0; + break; + } + + ret = serial_getconfig(&serial_config); + if (ret) + serial_config = SERIAL_DEFAULT_CONFIG; + + spcr->parity = SERIAL_GET_PARITY(serial_config); + spcr->stop_bits = SERIAL_GET_STOP(serial_config); + + /* No PCI devices for now */ + spcr->pci_device_id = 0xffff; + spcr->pci_vendor_id = 0xffff; + + /* Fix checksum */ + header->checksum = table_compute_checksum((void *)spcr, header->length); +} + /* * QEMU's version of write_acpi_tables is defined in drivers/misc/qfw.c */ @@ -352,6 +462,7 @@ ulong write_acpi_tables(ulong start) struct acpi_fadt *fadt; struct acpi_mcfg *mcfg; struct acpi_madt *madt; + struct acpi_spcr *spcr; int i;
current = start; @@ -440,6 +551,13 @@ ulong write_acpi_tables(ulong start) acpi_add_table(rsdp, mcfg); current = ALIGN(current, 16);
+ debug("ACPI: * SPCR\n"); + spcr = (struct acpi_spcr *)current; + acpi_create_spcr(spcr); + current += spcr->header.length; + acpi_add_table(rsdp, spcr); + current = ALIGN(current, 16); + debug("current = %x\n", current);
acpi_rsdp_addr = (unsigned long)rsdp;

On Tue, 20 Nov 2018 at 14:52, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
Microsoft specifies a SPCR (Serial Port Console Redirection Table) [1]. Let's provide it in U-Boot.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com
arch/x86/include/asm/acpi_table.h | 2 + arch/x86/lib/acpi_table.c | 118 ++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

On Tue, 20 Nov 2018 at 14:52, Andy Shevchenko andriy.shevchenko@linux.intel.com wrote:
Microsoft specifies a SPCR (Serial Port Console Redirection Table) [1]. Let's provide it in U-Boot.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com
arch/x86/include/asm/acpi_table.h | 2 + arch/x86/lib/acpi_table.c | 118 ++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot-dm/master, thanks!
participants (3)
-
Andy Shevchenko
-
Simon Glass
-
sjg@google.com