Skip to contentSkip to conversation

ns16550: Add support for UART parameters to be specifed with name-value pairs

PATCH Superseded Swapnil Paratey 2 participants 2 messages Apr 27, 2017 – May 9, 2017

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 ns16550: Add support for UART parameters to be specifed with name-value pairs

Add name=value parsing options for com1 and com2 to add flexibility in setting register values for MMIO UART devices.

Maintain backward compatibility with previous positional parameter specfications.

eg. com1=115200,8n1,0x3f8,4
eg. com1=115200,8n1,0x3f8,4,reg_width=4,reg_shift=2 eg. com1=baud=115200,parity=n,reg_width=4,reg_shift=2,irq=4

---
Changed since v5:
* Extended changelist for PATCH v4 and v5
* Removed const for name[12] in serial_param_var
* Changed "ext_value" pointer to "value" double pointer in get_token()
* Removed parenthesis in clock_hz case statement

Changed since v4:
* Changed max_serial_params to num_serial_params in enum e_serial_param_type
* Changed *sp_name in struct serial_param_var to a 12 byte buffer
* Removed sp_ prefix in sp_name in struct serial_param_var
* Removed if( name_val_pos ) check before while() loop in parse_positional()
* Added blank lines for non-fall-through case blocks in switch statement inside parse_namevalue_pairs
* Changed comparison of a bool with "true" for dev_set in io_base case.
* Changed cmdline to com_console_options in ns16550_parse_port_config()
* Changed io_base setting after pci device specification to give an error message instead of PARSE_ERR_RET
* Removed config_parsed goto statements outside of error cleanup
* Removed the full-stop (.) in sanity checks for reg_width at the end of ns16550_parse_port_config

Changed since v3:
* Changed subject/title of the patch
Previous name: ns16550-Add-command-line-parsing-adjustments
* Increased length of opt_com1 and opt_com2 buffers to 128 bytes.
* Changed wrongly used bus:device:function to bus:device.function in xen-command-line.markdown
* Using '-' instead of '_' for name-value pairs
eg. reg-width instead of reg_width, stop-bits instead of stop_bits
* Used __initconst for serial_param_var struct
* Changed get_token_value function name to get_token
* Values for name-value pairs in get_token are extracted only when a match is found in the table for valid name-value pairs
* Removed intermediate return variable for get_token function and used it directly in the switch statement for setting UART configs in parse_namevalue_pairs

Changed since v2:
* Added name=value specification for com1 and com2 command line parameter input for UART devices
Syntax: "com1=(positional parameters),(name-value parameters)"
* Maintained previous positional specification for UART parameters
* All parameters should be comma-separated

Changed since v1:
* Changed opt_com1 and opt_com2 array size to 64 (power of 2).
* Added descriptions for reg_width and reg_shift in docs/misc/xen-command-line.markdown
* Changed subject to ns16550 from 16550 for better tracking.

---
 docs/misc/xen-command-line.markdown |  38 ++++++
 xen/common/kernel.c                 |   2 +-
 xen/drivers/char/ns16550.c          | 245 +++++++++++++++++++++++++++++++++---
 3 files changed, 268 insertions(+), 17 deletions(-)
docs/misc/xen-command-line.markdown +38 -0
index 450b222..53052b2 100644
@@ -324,6 +324,44 @@ Both option `com1` and `com2` follow the same format.
 
 A typical setup for most situations might be `com1=115200,8n1`
 
+In addition to the above positional specification for UART parameters,
+name=value pair specfications are also supported. This is used to add
+flexibility for UART devices which require additional UART parameter
+configurations.
+
+The comma separation still delineates positional parameters. Hence,
+unless the parameter is explicitly specified with name=value option, it
+will be considered a positional parameter.
+
+The syntax consists of
+com1=(comma-separated positional parameters),(comma separated name-value pairs)
+
+The accepted name keywords for name=value pairs are
+ * `baud` - accepts integer baud rate (eg. 115200) or `auto`
+ * `bridge`- Similar to bridge-bdf in positional parameters.
+             Used to determine the PCI bridge to access the UART device.
+             Notation is xx:xx.xx <bus>:<device>.<function>
+ * `clock-hz`- accepts large integers to setup UART clock frequencies.
+               Do note - these values are multiplied by 16.
+ * `data-bits` - integer between 5 and 8
+ * `dev` - accepted values are `pci` OR `amt`. If this option
+           is used to specify if the serial device is pci-based. The io_base
+           cannot be specified when `dev=pci` or `dev=amt` is used.
+ * `io-base` - accepts integer which specified IO base port for UART registers
+ * `irq` - IRQ number to use
+ * `parity` - accepted values are same as positional parameters
+ * `port` - Used to specify which port the PCI serial device is located on
+            Notation is xx:xx.xx <bus>:<device>.<function>
+ * `reg-shift` - register shifts required to set UART registers
+ * `reg-width` - register width required to set UART registers
+                 (only accepts 1 and 4)
+ * `stop-bits` - only accepts 1 or 2 for the number of stop bits
+
+The following are examples of correct specifications:
+`com1=115200,8n1,0x3f8,4`
+`com1=115200,8n1,0x3f8,4,reg_width=4,reg_shift=2`
+`com1=baud=115200,parity=n,stop_bits=1,io_base=0x3f8,reg_width=4`
+
 ### conring\_size
 > `= <size>`
 
xen/common/kernel.c +1 -1
index 8461871..e1ebb0b 100644
@@ -49,7 +49,7 @@ static void __init assign_integer_param(
 
 static void __init _cmdline_parse(const char *cmdline)
 {
-    char opt[100], *optval, *optkey, *q;
+    char opt[128], *optval, *optkey, *q;
     const char *p = cmdline;
     const struct kernel_param *param;
     int bool_assert;
xen/drivers/char/ns16550.c +229 -16

310 lines not on this page · raw message

Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v6 1/1
#1 lore raw
Quoted 63 lines
Quoted 1 line
Quoted 1 line · On 28.04.17 at 01:01, <[email protected]> wrote:
xen/drivers/char/ns16550.c +62 -0
+static bool __init parse_namevalue_pairs(char *str, struct ns16550 *uart)
+{
+    char *token, *start = str;
+    char *param_value = NULL;
+    bool dev_set = false;
+
+    if ( (str == NULL) || (*str == '\0') )
+        return true;
+
+    do
+    {
+        /* When no tokens are found, start will be NULL */
+        token = strsep(&start, ",");
+
+        switch ( get_token(token, &param_value) )
+        {
+        case baud:
+            uart->baud = simple_strtoul(param_value, NULL, 0);
+            break;
+
+        case bridge_bdf:
+            if ( !parse_pci(param_value, NULL, &uart->ps_bdf[0],
+                            &uart->ps_bdf[1], &uart->ps_bdf[2]) )
+                PARSE_ERR_RET("Bad port PCI coordinates\n");
+            uart->ps_bdf_enable = 1;
+            break;
+
+        case clock_hz:
+            uart->clock_hz = simple_strtoul(param_value, NULL, 0) << 4;
+            break;
+
+        case device:
+            if ( strncmp(param_value, "pci", 3) == 0 )
+            {
+                pci_uart_config(uart, 1/* skip AMT */, uart - ns16550_com);
+                dev_set = true;
+            }
+            else if ( strncmp(param_value, "amt", 3) == 0 )
+            {
+                pci_uart_config(uart, 0, uart - ns16550_com);
+                dev_set = true;
+            }
+            break;
+
+        case io_base:
+            if ( dev_set )
+            {
+                printk(XENLOG_WARNING
+                       "Can't use io_base with dev=pci or dev=amt options\n");
+                break;
+            }
+            uart->io_base = simple_strtoul(param_value, NULL, 0);
+            break;
+
+        case irq:
+            uart->irq = simple_strtoul(param_value, NULL, 0);
+            break;
+
+        case data_bits:
+            uart->data_bits = simple_strtoul(param_value, NULL, 0);
+            break;
+

xen/drivers/char/ns16550.c static void __init ns16550_parse_port_config( · line 1335

Quoted 10 lines
xen/drivers/char/ns16550.c +10 -0
+        case parity:
+            uart->parity = parse_parity_char(*param_value);
+            break;
+
+        case port_bdf:
+            if ( !parse_pci(param_value, NULL, &uart->pb_bdf[0],
+                            &uart->pb_bdf[1], &uart->pb_bdf[2]) )
+                PARSE_ERR_RET("Bad port PCI coordinates\n");
+            uart->pb_bdf_enable = true;
+            break;

Considering you imply no fall through from the "if()" body to what follows the "if()" here, I think ...

Quoted 5 lines
xen/drivers/char/ns16550.c +5 -0
+        case stop_bits:
+            uart->stop_bits = simple_strtoul(param_value, NULL, 0);
+            break;
+
+        case reg_shift:

xen/drivers/char/ns16550.c static void __init ns16550_parse_port_config( · line 1351

Quoted 10 lines
xen/drivers/char/ns16550.c +10 -0
+            uart->reg_shift = simple_strtoul(param_value, NULL, 0);
+            break;
+
+        case reg_width:
+            uart->reg_width = simple_strtoul(param_value, NULL, 0);
+            break;
+
+        default:
+            PARSE_ERR_RET("Invalid parameter: %s\n", token);
+            break;

... the "break" here should be removed. Or alternatively the "if()" above (and also the bridge_bdf one) should gain an "else". I'd be fine with doing the former while committing, but if you prefer the latter, please submit v7. With either adjustment

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel