Patches for PCI serial cards (v2).
PATCH 1/1 Patches for PCI serial cards (v2).
Hey,
The attached patches allow the com1=<> to be expanded to automatically defect the I/O base. It makes it possible to use the PCI serial cards after a S3 suspend/resume and as well to whitelist the BDF for kexec-ing.
Changelog, since v1:
- Added an extra patch to use 'pci' instead of 'magic' as trigger to auto-detect the PCI serial cards.
- Allow to probe BAR1 and BAR0 depending on whether com2 or com1, respectively has been used.
- Updated the doc/user.tex with the new syntax.
- Fixed some formatting issues the patch from XCP had.
History:
The first one is actually from XCP product and I think I got the right author name for it - if not please correct me.
The other three patches are rebased patches that I've received from VirtualComputer (www.virtualcomputer.com). They seem to find lot of issues on laptops/desktops and have been using PCI express serial cards, MiniPCI-e serial cards, etc to get the serial output to troubleshoot. And as such found some issues after a S3 resume which these patches fix.
Please take a look.
PATCH 1/1 xen: Automatically find serial port on PCI/PCIe and AMT devices
# HG changeset patch
# User James Mckenzie <[email protected]> # Date 1310490365 14400
# Node ID 50ce3b9afcd7f43801408f2d1acc686afeb54f00
# Parent 2f63562df1c4230492a81793dce3672f93c93d9a
xen: Automatically find serial port on PCI/PCIe and AMT devices.
Instead of having to manually look the right I/O port on the PCI devices or AMT devices, lets probe the card and find that automatically.
This means that you don't have to have this:
com1=115200,8n1,0xd800,0
But instead can have
com1=115200,8n1,magic
Or if you have AMT:
com1=19200,8n1,amt
xen/drivers/char/ns16550.c +72 -1
@@ -17,6 +17,8 @@#include <xen/timer.h> #include <xen/serial.h> #include <xen/iocap.h> +#include <xen/pci.h> +#include <xen/pci_regs.h> #include <asm/io.h> /*
@@ -433,6 +435,64 @@ static int __init check_existence(structreturn (status ==0x90 ); } +static int +magic_uart_config (struct ns16550 *uart,int skip_amt) +{ +uint16_t class; +uint32_t bar0, len; +int b, d, f; + +/*Skanky hack - start at bus 1 to avoid AMT, a plug in card cannot be on bus 1 */ + +if (skip_amt) b=1 ; +else b=0 ; + +for (; b <0x100 ; ++b) + { +for (d =0 ; d <0x20 ; ++d) + { +for (f =0 ; f <0x8 ; ++f) + { + + class =pci_conf_read16 (b, d, f,PCI_CLASS_DEVICE ); +if (class !=0x700 ) +continue ;; + + bar0 =pci_conf_read32 (b, d, f,PCI_BASE_ADDRESS_0 ); + +/* Not IO */ +if (!(bar0 &1 )) +continue ; + +pci_conf_write32 (b, d, f,PCI_BASE_ADDRESS_0 ,0xffffffff ); + len =pci_conf_read32 (b, d, f,PCI_BASE_ADDRESS_0 ); +pci_conf_write32 (b, d, f,PCI_BASE_ADDRESS_0 , bar0); + +/* Not 8 bytes */ +if ((len &0xffff ) !=0xfff9 ) +continue ; + + uart->io_base = bar0 &0xfffe ; + uart->irq =0 ; + +return 0 ; + + } + + } + } + +if (!skip_amt) +return -1 ; + + uart->io_base =0x3f8 ; + uart->irq =0 ; + uart->clock_hz =UART_CLOCK_HZ ; + +return 0 ; +} + + #define PARSE_ERR(_f, _a...) \ do { \ printk( "ERROR: " _f "\n" , ## _a ); \
@@ -481,7 +541,18 @@ static void __init ns16550_parse_port_coif ( *conf ==',' ) { conf++; - uart->io_base =simple_strtoul (conf, &conf,0 ); + +if (strncmp (conf,"magic" ,5 ) ==0 ) { +if (magic_uart_config (uart,1 )) +return ; + conf+=5 ; + }else if (strncmp (conf,"amt" ,3 ) ==0 ) { +if (magic_uart_config (uart,0 )) +return ; + conf+=3 ; + }else { + uart->io_base =simple_strtoul (conf, &conf,0 ); + }if ( *conf ==',' ) {
PATCH 1/1 xen: Support suspend in ns16550 code
In reply to Konrad Rzeszutek Wilk# HG changeset patch
# User Tom Goetz <[email protected]> # Date 1310490365 14400
# Node ID 4c94bcf4b4afb840bc6a037f0782c63ad573f4eb # Parent 50ce3b9afcd7f43801408f2d1acc686afeb54f00
xen: Support suspend in ns16550 code.
For PCI type cards, you need to disable the timer code during suspend. Otherwise during resume, the timer can be put on the heap as its being resumed and corrupt it resulting in a crash.
xen/drivers/char/ns16550.c +9 -1
@@ -353,6 +353,13 @@ static int ns16550_irq(struct serial_porreturn ((uart->irq >0 ) ? uart->irq :-1 ); } +static void ns16550_suspend (struct serial_port *port) +{ +struct ns16550 *uart = port->uart; + +stop_timer (&uart->timer); +} +static struct uart_driver __read_mostly ns16550_driver = { .init_preirq = ns16550_init_preirq, .init_postirq = ns16550_init_postirq,
@@ -361,7 +368,8 @@ static struct uart_driver __read_mostly .tx_empty = ns16550_tx_empty, .putc = ns16550_putc, .getc = ns16550_getc, - .irq = ns16550_irq + .irq = ns16550_irq, + .suspend = ns16550_suspend, };static int __init parse_parity_char (int c)
PATCH 1/1 xen: Restore the BAR and PCI command after resume
In reply to Konrad Rzeszutek Wilk# HG changeset patch
# User Roger Cruz <[email protected]> # Date 1310490365 14400
# Node ID ded47a2ba411fefc614c773ae78518a162f912f9 # Parent 4c94bcf4b4afb840bc6a037f0782c63ad573f4eb
xen: Restore the BAR and PCI command after resume.
Certain PCI serial cards just don't want to remember what they are when they come out of resume. Save the BAR and the PCI command values before we suspend and write them back in when we resume.
xen/drivers/char/ns16550.c +20 -0
@@ -49,6 +49,7 @@ static struct ns16550 {unsigned int ps_bdf[3 ];/* pci serial port BDF */ bool_t pb_bdf_enable;/* if =1, pb-bdf effective, port behind bridge */ bool_t ps_bdf_enable;/* if =1, ps_bdf effective, port on pci card */ +int bar0, cr; } ns16550_com[2] = { { 0 } };/* Register offsets */
@@ -332,8 +333,17 @@ static void __init ns16550_init_postirq(static void ns16550_resume (struct serial_port *port) { +struct ns16550 *uart = port->uart; +ns16550_setup_preirq (port->uart);ns16550_setup_postirq (port->uart); + +if (uart->bar0) { +pci_conf_write32 (uart->pb_bdf[0 ], uart->pb_bdf[1 ], uart->pb_bdf[2 ], +PCI_BASE_ADDRESS_0 , uart->bar0); +pci_conf_write32 (uart->pb_bdf[0 ], uart->pb_bdf[1 ], uart->pb_bdf[2 ], +PCI_COMMAND , uart->cr); + } }#ifdef CONFIG_X86
@@ -358,6 +368,12 @@ static void ns16550_suspend(struct seriastruct ns16550 *uart = port->uart;stop_timer (&uart->timer); +if (uart->bar0) { + uart->bar0 =pci_conf_read32 (uart->pb_bdf[0 ], uart->pb_bdf[1 ], uart->pb_bdf[2 ], +PCI_BASE_ADDRESS_0 ); + uart->cr =pci_conf_read32 (uart->pb_bdf[0 ], uart->pb_bdf[1 ], uart->pb_bdf[2 ], +PCI_COMMAND ); + } }static struct uart_driver __read_mostly ns16550_driver = {
@@ -480,6 +496,10 @@ magic_uart_config (struct ns16550 *uart,if ((len &0xffff ) !=0xfff9 )continue ; + uart->pb_bdf[0 ] = b; + uart->pb_bdf[1 ] = d; + uart->pb_bdf[2 ] = f; + uart->bar0 = bar0; uart->io_base = bar0 &0xfffe ; uart->irq =0 ;
PATCH 1/1 xen: Update pci_uart_config to save the BAR1 contents if com2 is used
In reply to Konrad Rzeszutek Wilk# HG changeset patch
# User Konrad Rzeszutek Wilk <[email protected]>
# Date 1310493175 14400
# Node ID 841e8a1304e707bb9f077d014fb59d46133fbeae
# Parent ded47a2ba411fefc614c773ae78518a162f912f9
xen: Update pci_uart_config to save the BAR1 contents if com2 is used
Jan Beulich pointed out that the pci_uart_config can be called for com2 and we should probe the second BAR instead of the first one.
This patch will probe the BAR0 if it is com1, and BAR1 if its com2. It also cleans up some of the whitespace problems and changes the name of the parameter and function from 'magic' to 'pci'.
xen/drivers/char/ns16550.c +33 -28
@@ -49,7 +49,7 @@ static struct ns16550 {unsigned int ps_bdf[3 ];/* pci serial port BDF */ bool_t pb_bdf_enable;/* if =1, pb-bdf effective, port behind bridge */ bool_t ps_bdf_enable;/* if =1, ps_bdf effective, port on pci card */ -int bar0, cr; +int bar, cr, bar_idx; } ns16550_com[2] = { { 0 } };/* Register offsets */
@@ -338,9 +338,10 @@ static void ns16550_resume(struct serialns16550_setup_preirq (port->uart);ns16550_setup_postirq (port->uart); -if (uart->bar0) { +if (uart->bar) {pci_conf_write32 (uart->pb_bdf[0 ], uart->pb_bdf[1 ], uart->pb_bdf[2 ], -PCI_BASE_ADDRESS_0 , uart->bar0); +PCI_BASE_ADDRESS_0 +sizeof (uint32_t ) * uart->bar_idx, + uart->bar);pci_conf_write32 (uart->pb_bdf[0 ], uart->pb_bdf[1 ], uart->pb_bdf[2 ],PCI_COMMAND , uart->cr); }
@@ -368,9 +369,10 @@ static void ns16550_suspend(struct seriastruct ns16550 *uart = port->uart;stop_timer (&uart->timer); -if (uart->bar0) { - uart->bar0 =pci_conf_read32 (uart->pb_bdf[0 ], uart->pb_bdf[1 ], uart->pb_bdf[2 ], -PCI_BASE_ADDRESS_0 ); +if (uart->bar) { + uart->bar =pci_conf_read32 (uart->pb_bdf[0 ], uart->pb_bdf[1 ], uart->pb_bdf[2 ], +PCI_BASE_ADDRESS_0 + + (sizeof (uint32_t ) * uart->bar_idx)); uart->cr =pci_conf_read32 (uart->pb_bdf[0 ], uart->pb_bdf[1 ], uart->pb_bdf[2 ],PCI_COMMAND ); }
@@ -460,37 +462,40 @@ static int __init check_existence(struct }static int -magic_uart_config (struct ns16550 *uart,int skip_amt) +pci_uart_config (struct ns16550 *uart,int skip_amt,int bar_idx) {uint16_t class; -uint32_t bar0, len; +uint32_t bar, len;int b, d, f;/*Skanky hack - start at bus 1 to avoid AMT, a plug in card cannot be on bus 1 */ -if (skip_amt) b=1 ; -else b=0 ; +if (skip_amt) + b=1 ; +else + b=0 ;for (; b <0x100 ; ++b) + { +for (d =0 ; d <0x20 ; ++d) { -for (d =0 ; d <0x20 ; ++d) - {for (f =0 ; f <0x8 ; ++f) - { - + { class =pci_conf_read16 (b, d, f,PCI_CLASS_DEVICE );if (class !=0x700 )continue ;; - bar0 =pci_conf_read32 (b, d, f,PCI_BASE_ADDRESS_0 ); + bar =pci_conf_read32 (b, d, f,PCI_BASE_ADDRESS_0 + + (sizeof (uint32_t ) * bar_idx));/* Not IO */ -if (!(bar0 &1 )) +if (!(bar &1 ))continue ;pci_conf_write32 (b, d, f,PCI_BASE_ADDRESS_0 ,0xffffffff ); len =pci_conf_read32 (b, d, f,PCI_BASE_ADDRESS_0 ); -pci_conf_write32 (b, d, f,PCI_BASE_ADDRESS_0 , bar0); +pci_conf_write32 (b, d, f,PCI_BASE_ADDRESS_0 + + (sizeof (uint32_t ) * bar_idx), bar);/* Not 8 bytes */ if ((len &0xffff ) !=0xfff9 )
@@ -499,8 +504,9 @@ magic_uart_config (struct ns16550 *uart, uart->pb_bdf[0 ] = b; uart->pb_bdf[1 ] = d; uart->pb_bdf[2 ] = f; - uart->bar0 = bar0; - uart->io_base = bar0 &0xfffe ; + uart->bar = bar; + uart->bar_idx = bar_idx; + uart->io_base = bar &0xfffe ; uart->irq =0 ;return 0 ;
@@ -569,15 +575,14 @@ static void __init ns16550_parse_port_coif ( *conf ==',' ) { conf++; - -if (strncmp (conf,"magic" ,5 ) ==0 ) { -if (magic_uart_config (uart,1 )) -return ; - conf+=5 ; - }else if (strncmp (conf,"amt" ,3 ) ==0 ) { -if (magic_uart_config (uart,0 )) -return ; - conf+=3 ; +if (strncmp (conf,"pci" ,5 ) ==0 ) { +if (pci_uart_config (uart,1 /* skip AMT */ , uart - ns16550_com)) +return ; + conf +=3 ; + }else if (strncmp (conf,"amt" ,3 ) ==0 ) { +if (pci_uart_config (uart,0 , uart - ns16550_com)) +return ; + conf +=3 ; }else { uart->io_base =simple_strtoul (conf, &conf,0 ); }
Re: [PATCH 4 of 5] xen: Update pci_uart_config to save the BAR1 contents if com2 is used
Quoted 126 lines · Konrad Rzeszutek Wilk
# HG changeset patch
# User Konrad Rzeszutek Wilk <[email protected]>
# Date 1310493175 14400
# Node ID841e8a1304e707bb9f077d014fb59d46133fbeae
# Parentded47a2ba411fefc614c773ae78518a162f912f9
xen: Updatepci_uart_configto save the BAR1 contents if com2 is usedJan Beulich pointed out that the
pci_uart_configcan be called for com2 and we should probe the second BAR instead of the first one.This patch will probe the BAR0 if it is com1, and BAR1 if its com2. It also cleans up some of the whitespace problems and changes the name of the parameter and function from 'magic' to 'pci'.
Signed-off-by Konrad Rzeszutek Wilk <[email protected]>diff -r
ded47a2ba411-r841e8a1304e7xen/drivers/char/ns16550.cxen/drivers/char/ns16550.c +25
-22@@ -49,7 +49,7 @@ static struct ns16550 {unsigned int ps_bdf[3 ];/* pci serial port BDF */ bool_t pb_bdf_enable;/* if =1, pb-bdf effective, port behind bridge */ bool_t ps_bdf_enable;/* if =1, ps_bdf effective, port on pci card */ -int bar0, cr; +int bar, cr, bar_idx; } ns16550_com[2] = { { 0 } };/* Register offsets */ @@ -338,9 +338,10 @@ static void ns16550_resume(struct serialns16550_setup_preirq (port->uart);ns16550_setup_postirq (port->uart); -if (uart->bar0) { +if (uart->bar) {pci_conf_write32 (uart->pb_bdf[0 ], uart->pb_bdf[1 ], uart->pb_bdf[2 ], -PCI_BASE_ADDRESS_0 , uart->bar0); +PCI_BASE_ADDRESS_0 +sizeof (uint32_t ) * uart->bar_idx, + uart->bar);pci_conf_write32 (uart->pb_bdf[0 ], uart->pb_bdf[1 ], uart->pb_bdf[2 ],PCI_COMMAND , uart->cr); }@@ -368,9 +369,10 @@ static void ns16550_suspend(struct seriastruct ns16550 *uart = port->uart;stop_timer (&uart->timer); -if (uart->bar0) { - uart->bar0 =pci_conf_read32 (uart->pb_bdf[0 ], uart->pb_bdf[1 ], uart->pb_bdf[2 ], -PCI_BASE_ADDRESS_0 ); +if (uart->bar) { + uart->bar =pci_conf_read32 (uart->pb_bdf[0 ], uart->pb_bdf[1 ], uart->pb_bdf[2 ], +PCI_BASE_ADDRESS_0 + + (sizeof (uint32_t ) * uart->bar_idx)); uart->cr =pci_conf_read32 (uart->pb_bdf[0 ], uart->pb_bdf[1 ], uart->pb_bdf[2 ],PCI_COMMAND ); }@@ -460,37 +462,40 @@ static int __init check_existence(struct }static int -magic_uart_config (struct ns16550 *uart,int skip_amt) +pci_uart_config (struct ns16550 *uart,int skip_amt,int bar_idx) {uint16_t class; -uint32_t bar0, len; +uint32_t bar, len;int b, d, f;/*Skanky hack - start at bus 1 to avoid AMT, a plug in card cannot be on bus 1 */ -if (skip_amt) b=1 ; -else b=0 ; +if (skip_amt) + b=1 ; +else + b=0 ;for (; b <0x100 ; ++b) + { +for (d =0 ; d <0x20 ; ++d) { -for (d =0 ; d <0x20 ; ++d) - {for (f =0 ; f <0x8 ; ++f) - { - + { class =pci_conf_read16 (b, d, f,PCI_CLASS_DEVICE );if (class !=0x700 )continue ;; - bar0 =pci_conf_read32 (b, d, f,PCI_BASE_ADDRESS_0 ); + bar =pci_conf_read32 (b, d, f,PCI_BASE_ADDRESS_0 + + (sizeof (uint32_t ) * bar_idx));/* Not IO */ -if (!(bar0 &1 )) +if (!(bar &1 ))continue ;pci_conf_write32 (b, d, f,PCI_BASE_ADDRESS_0 ,0xffffffff ); len =pci_conf_read32 (b, d, f,PCI_BASE_ADDRESS_0 ); -pci_conf_write32 (b, d, f,PCI_BASE_ADDRESS_0 , bar0); +pci_conf_write32 (b, d, f,PCI_BASE_ADDRESS_0 + + (sizeof (uint32_t ) * bar_idx), bar);/* Not 8 bytes */ if ((len &0xffff ) !=0xfff9 )@@ -499,8 +504,9 @@ magic_uart_config (struct ns16550 *uart, uart->pb_bdf[0 ] = b; uart->pb_bdf[1 ] = d; uart->pb_bdf[2 ] = f; - uart->bar0 = bar0; - uart->io_base = bar0 &0xfffe ; + uart->bar = bar; + uart->bar_idx = bar_idx; + uart->io_base = bar &0xfffe ; uart->irq =0 ;return 0 ;@@ -569,15 +575,14 @@ static void __init ns16550_parse_port_coif ( *conf ==',' ) { conf++; - -if (strncmp (conf,"magic" ,5 ) ==0 ) { -if (magic_uart_config (uart,1 ))
xen/drivers/char/ns16550.c static void __init ns16550_parse_port_co · line 581
Quoted 10 lines
xen/drivers/char/ns16550.c +4
-6-return ; - conf+=5 ; - }else if (strncmp (conf,"amt" ,3 ) ==0 ) { -if (magic_uart_config (uart,0 )) -return ; - conf+=3 ; +if (strncmp (conf,"pci" ,5 ) ==0 ) { +if (pci_uart_config (uart,1 /* skip AMT */ , uart - ns16550_com)) +return ; + conf +=3 ;
Isn't fixing issues found in earlier patches in later patches a bit skanky? :-)
-George
Re: [PATCH 4 of 5] xen: Update pci_uart_config to save the BAR1 contents if com2 is used
Quoted 2 lines
Isn't fixing issues found in earlier patches in later patches a bit skanky? :-)
Well... The earlier patch is by James McKenzie and I was thinking to preserve the original. But I am OK merging these patches if that is the proper procedure for Xen.
PATCH 1/1 doc: Update the com1, com2 section with pci and amt options
In reply to Konrad Rzeszutek Wilk# HG changeset patch
# User Konrad Rzeszutek Wilk <[email protected]> # Date 1310493177 14400
# Node ID d42a0c7903e6828cccfc8b9fc7d15ba578019674 # Parent 841e8a1304e707bb9f077d014fb59d46133fbeae
doc: Update the com1,com2 section with pci and amt options.
The "xen: Automatically find serial port on PCI/PCIe and AMT devices." provides the functionality to probe for the I/O base using the "pci" and "amt" option. Update the documentation with this fact.
docs/src/user.tex +6 -2
@@ -2154,8 +2154,8 @@ editing \path{grub.conf}. is bad, you would place `badpage=0x12345' on Xen's command line. \item [ serial\_tx\_buffer=$<$size$>$ ] Size of serial transmit buffers. Default is 16kB. -\item [ com1=$<$baud$>$,DPS,$<$io\_base$>$,$<$irq$>$ - com2=$<$baud$>$,DPS,$<$io\_base$>$,$<$irq$>$ ] \mbox{}\\ +\item [ com1=$<$baud$>$,DPS,($<$io\_base$>$$|$pci$|$amt),$<$irq$>$ + com2=$<$baud$>$,DPS,($<$io\_base$>$$|$pci$|$amt),$<$irq$>$] \mbox{}\\ Xen supports up to two 16550-compatible serial ports. For example: `com1=9600, 8n1, 0x408, 5' maps COM1 to a 9600-baud port, 8 data bits, no parity, 1 stop bit, I/O port base 0x408, IRQ 5. If some
@@ -2163,6 +2163,10 @@ editing \path{grub.conf}. only a prefix of the full configuration string need be specified. If the baud rate is pre-configured (e.g., by the bootloader) then you can specify `auto' in place of a numeric baud rate. + For PCI serial devices, such as Intel AMT you can use the {\bf amt} + option to automatically find the I/O base. For PCI serial devices, + such as NetMos, you can use {\bf pci} to probe for the I/O base. + Both options will set the IRQ to zero - meaning they will poll the device. \item [ console=$<$specifier list$>$ ] Specify the destination for Xen console I/O. This is a comma-separated list of, for example: \begin{description}