Skip to contentSkip to conversation

ACPI: Generate SPCR table

PATCH New Andy Shevchenko 3 participants 26 messages Nov 20, 2018 – Dec 5, 2018 x86

lore
Share & tools
lore
#0 lore raw

v3 cover 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

#1 lore raw

PATCH v3 1/7 dm: serial: Add ->getconfig() callback

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.

---
 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(-)
drivers/serial/sandbox.c +13 -0
index 4a05ea44ce..76d26d3c59 100644
@@ -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,
 };
 
drivers/serial/serial-uclass.c +16 -0
index 665cca85cb..d5a3b1255f 100644
@@ -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
include/common.h +1 -0
index 8b9f859c07..675495bde5 100644
@@ -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 */
include/serial.h +23 -3
index 020cd392e8..bc6d28ea86 100644
@@ -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)
test/dm/serial.c +7 -0
index 5c603e1f42..7a1a1526a4 100644
@@ -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
Signature · 1 line
2.19.1
#2 lore raw

PATCH v3 1/7 dm: serial: Add ->getconfig() callback

Hi Andy,

Quoted 5 lines · Andy Shevchenko

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.

Quoted 9 lines
---
 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

#3 lore raw

PATCH v3 1/7 dm: serial: Add ->getconfig() callback

Quoted 19 lines · Simon Glass

Hi Andy,

Quoted 5 lines · Andy Shevchenko

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.

Quoted 9 lines
---
 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(-)
Quoted 1 line

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.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

PATCH v3 1/7 dm: serial: Add ->getconfig() callback

Quoted 20 lines · Andy Shevchenko
Quoted 17 lines · Simon Glass
Quoted 5 lines · Andy Shevchenko

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.

Quoted 9 lines
---
 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(-)
Quoted 1 line

My only concern is that serial_get_config() should have a device parameter.

Quoted 7 lines

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.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

PATCH v3 1/7 dm: serial: Add ->getconfig() callback

In reply to Andy Shevchenko

HI Andy,

Quoted 23 lines · Andy Shevchenko
Quoted 19 lines · Simon Glass

Hi Andy,

Quoted 5 lines · Andy Shevchenko

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.

Quoted 9 lines
---
 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(-)
Quoted 1 line

My only concern is that serial_get_config() should have a device parameter.

Quoted 7 lines

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.

Regards,
Simon

#6 lore raw

PATCH v3 1/7 dm: serial: Add ->getconfig() callback

Quoted 7 lines · Simon Glass
Quoted 5 lines · Andy Shevchenko

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.

Quoted 7 lines
Quoted 2 lines

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.

Quoted 4 lines

I'm going to pick this up, absent any other issues, and see if I can do a patch for it afterwards.

Thank you for review, and sorry for being persuader, I have several big tasks to be accomplished before my vacation starts.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw

PATCH v3 1/7 dm: serial: Add ->getconfig() callback

Hi Andy,

Quoted 12 lines · Andy Shevchenko
Quoted 10 lines · Simon Glass
Quoted 7 lines · Andy Shevchenko

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.

Quoted 8 lines
Quoted 4 lines

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.

Quoted 8 lines
Quoted 5 lines

I'm going to pick this up, absent any other issues, and see if I can do a patch for it afterwards.

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

#8 lore raw

PATCH v3 1/7 dm: serial: Add ->getconfig() callback

Hi Andy,

Quoted 12 lines · Andy Shevchenko
Quoted 10 lines · Simon Glass
Quoted 7 lines · Andy Shevchenko

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.

Quoted 8 lines
Quoted 4 lines

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.

Quoted 8 lines
Quoted 5 lines

I'm going to pick this up, absent any other issues, and see if I can do a patch for it afterwards.

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!

#9 lore raw

PATCH v3 2/7 dm: serial: Introduce ->getinfo() callback

In reply to Andy Shevchenko

New callback will give a necessary information to fill up ACPI SPCR table, for example. Maybe used later for other purposes.

---
 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(+)
drivers/serial/sandbox.c +21 -0
index 76d26d3c59..c510a6ed36 100644
@@ -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[] = {
drivers/serial/serial-uclass.c +21 -0
index d5a3b1255f..8dc8a6788d 100644
@@ -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) {
include/common.h +3 -0
index 675495bde5..ea1fef0b24 100644
@@ -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);
include/serial.h +40 -0
index bc6d28ea86..ca549d45aa 100644
@@ -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);
 };
 
 /**
test/dm/serial.c +5 -0
index 7a1a1526a4..19a15d5d95 100644
@@ -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
Signature · 1 line
2.19.1
#10 lore raw

PATCH v3 2/7 dm: serial: Introduce ->getinfo() callback

Quoted 4 lines · Andy Shevchenko

New callback will give a necessary information to fill up ACPI SPCR table, for example. Maybe used later for other purposes.

Quoted 8 lines
---
 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(+)
#11 lore raw

PATCH v3 2/7 dm: serial: Introduce ->getinfo() callback

Quoted 4 lines · Andy Shevchenko

New callback will give a necessary information to fill up ACPI SPCR table, for example. Maybe used later for other purposes.

Quoted 8 lines
---
 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(+)

Applied to u-boot-dm/master, thanks!

#12 lore raw

PATCH v3 3/7 serial: ns16550: Group reg_* members of ns16550_platdata

In reply to Andy Shevchenko

Group reg_* members of struct ns16550_platdata together for better maintenance.

No functional change intended.

---
 include/ns16550.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/ns16550.h +1 -1
index 5fcbcd2e74..f565645d65 100644
@@ -55,8 +55,8 @@
 struct ns16550_platdata {
 	unsigned long base;
 	int reg_shift;
-	int clock;
 	int reg_offset;
+	int clock;
 	u32 fcr;
 };
 
Signature · 1 line
2.19.1
#15 lore raw

PATCH v3 4/7 serial: ns16550: Read reg-io-width from device tree

In reply to Andy Shevchenko

Cache the value of the reg-io-width property for the future use.

---
 drivers/serial/ns16550.c | 1 +
 include/ns16550.h        | 2 ++
 2 files changed, 3 insertions(+)
drivers/serial/ns16550.c +1 -0
index f9041aa626..b51b56de9f 100644
@@ -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) {
include/ns16550.h +2 -0
index f565645d65..22b89e4d6d 100644
@@ -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;
Signature · 1 line
2.19.1
#18 lore raw

PATCH v3 5/7 serial: ns16550: Provide ->getinfo() implementation

In reply to Andy Shevchenko

New callback will supply necessary information, for example, to ACPI SPCR table.

---
 drivers/serial/ns16550.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/serial/ns16550.c +20 -0
index b51b56de9f..226c5daf50 100644
@@ -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)
Signature · 1 line
2.19.1
#21 lore raw

PATCH v3 6/7 x86: acpi: Add SPCR table description

In reply to Andy Shevchenko

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.

---
 arch/x86/include/asm/acpi_table.h | 49 +++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
arch/x86/include/asm/acpi_table.h +49 -0
index 95fae036f6..51cc806673 100644
@@ -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);
Signature · 1 line
2.19.1
#22 lore raw

PATCH v3 6/7 x86: acpi: Add SPCR table description

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.

---
 arch/x86/include/asm/acpi_table.h | 49 +++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

Applied to u-boot-dm/master, thanks!

#23 lore raw

PATCH v3 7/7 x86: acpi: Generate SPCR table

In reply to Andy Shevchenko

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-port-console-redirection-table

---
 arch/x86/include/asm/acpi_table.h |   2 +
 arch/x86/lib/acpi_table.c         | 118 ++++++++++++++++++++++++++++++
 2 files changed, 120 insertions(+)
arch/x86/include/asm/acpi_table.h +2 -0
index 51cc806673..e3b65cff66 100644
@@ -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;
arch/x86/lib/acpi_table.c +118 -0

142 lines not on this page · raw message

Signature · 1 line
2.19.1
#24 lore raw

PATCH v3 7/7 x86: acpi: Generate SPCR table

Quoted 11 lines · Andy Shevchenko

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-port-console-redirection-table

---
 arch/x86/include/asm/acpi_table.h |   2 +
 arch/x86/lib/acpi_table.c         | 118 ++++++++++++++++++++++++++++++
 2 files changed, 120 insertions(+)
#25 lore raw

PATCH v3 7/7 x86: acpi: Generate SPCR table

Quoted 11 lines · Andy Shevchenko

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-port-console-redirection-table

---
 arch/x86/include/asm/acpi_table.h |   2 +
 arch/x86/lib/acpi_table.c         | 118 ++++++++++++++++++++++++++++++
 2 files changed, 120 insertions(+)

Applied to u-boot-dm/master, thanks!