All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0 of 5] Patches for PCI serial cards (v2).
@ 2011-07-12 17:53 Konrad Rzeszutek Wilk
  2011-07-12 17:53 ` [PATCH 1 of 5] xen: Automatically find serial port on PCI/PCIe and AMT devices Konrad Rzeszutek Wilk
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Konrad Rzeszutek Wilk @ 2011-07-12 17:53 UTC (permalink / raw)
  To: xen-devel, keir, stefano.stabellini, Ian.Campbell, andrew.cooper3,
	JBeulich, George.Dunlap, ro
  Cc: konrad.wilk

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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1 of 5] xen: Automatically find serial port on PCI/PCIe and AMT devices
  2011-07-12 17:53 [PATCH 0 of 5] Patches for PCI serial cards (v2) Konrad Rzeszutek Wilk
@ 2011-07-12 17:53 ` Konrad Rzeszutek Wilk
  2011-07-12 17:53 ` [PATCH 2 of 5] xen: Support suspend in ns16550 code Konrad Rzeszutek Wilk
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Konrad Rzeszutek Wilk @ 2011-07-12 17:53 UTC (permalink / raw)
  To: xen-devel, keir, stefano.stabellini, Ian.Campbell, andrew.cooper3,
	JBeulich, George.Dunlap, ro
  Cc: konrad.wilk

# HG changeset patch
# User James Mckenzie <jamesmck@bob.uk.xensource.com>
# 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

Signed-off-by: James Mckenzie <jamesmck@bob.uk.xensource.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Tom Goetz <tom.goetz@virtualcomputer.com>

diff -r 2f63562df1c4 -r 50ce3b9afcd7 xen/drivers/char/ns16550.c
--- a/xen/drivers/char/ns16550.c	Mon Jun 27 17:37:12 2011 +0100
+++ b/xen/drivers/char/ns16550.c	Tue Jul 12 13:06:05 2011 -0400
@@ -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(struct
     return (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_co
     if ( *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 == ',' )
         {

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2 of 5] xen: Support suspend in ns16550 code
  2011-07-12 17:53 [PATCH 0 of 5] Patches for PCI serial cards (v2) Konrad Rzeszutek Wilk
  2011-07-12 17:53 ` [PATCH 1 of 5] xen: Automatically find serial port on PCI/PCIe and AMT devices Konrad Rzeszutek Wilk
@ 2011-07-12 17:53 ` Konrad Rzeszutek Wilk
  2011-07-12 17:53 ` [PATCH 3 of 5] xen: Restore the BAR and PCI command after resume Konrad Rzeszutek Wilk
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Konrad Rzeszutek Wilk @ 2011-07-12 17:53 UTC (permalink / raw)
  To: xen-devel, keir, stefano.stabellini, Ian.Campbell, andrew.cooper3,
	JBeulich, George.Dunlap, ro
  Cc: konrad.wilk

# HG changeset patch
# User Tom Goetz <tom.goetz@virtualcomputer.com>
# 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.

Signed-off-by: Roger Cruz <roger.cruz@virtualcomputer.com>
Signed-off-by: Tom Goetz <tom.goetz@virtualcomputer.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

diff -r 50ce3b9afcd7 -r 4c94bcf4b4af xen/drivers/char/ns16550.c
--- a/xen/drivers/char/ns16550.c	Tue Jul 12 13:06:05 2011 -0400
+++ b/xen/drivers/char/ns16550.c	Tue Jul 12 13:06:05 2011 -0400
@@ -353,6 +353,13 @@ static int ns16550_irq(struct serial_por
     return ((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)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3 of 5] xen: Restore the BAR and PCI command after resume
  2011-07-12 17:53 [PATCH 0 of 5] Patches for PCI serial cards (v2) Konrad Rzeszutek Wilk
  2011-07-12 17:53 ` [PATCH 1 of 5] xen: Automatically find serial port on PCI/PCIe and AMT devices Konrad Rzeszutek Wilk
  2011-07-12 17:53 ` [PATCH 2 of 5] xen: Support suspend in ns16550 code Konrad Rzeszutek Wilk
@ 2011-07-12 17:53 ` Konrad Rzeszutek Wilk
  2011-07-12 17:53 ` [PATCH 4 of 5] xen: Update pci_uart_config to save the BAR1 contents if com2 is used Konrad Rzeszutek Wilk
  2011-07-12 17:53 ` [PATCH 5 of 5] doc: Update the com1, com2 section with pci and amt options Konrad Rzeszutek Wilk
  4 siblings, 0 replies; 8+ messages in thread
From: Konrad Rzeszutek Wilk @ 2011-07-12 17:53 UTC (permalink / raw)
  To: xen-devel, keir, stefano.stabellini, Ian.Campbell, andrew.cooper3,
	JBeulich, George.Dunlap, ro
  Cc: konrad.wilk

# HG changeset patch
# User Roger Cruz <roger.cruz@virtualcomputer.com>
# 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.

Signed-off-by: Roger Cruz <roger.cruz@virtualcomputer.com>
Signed-off-by: Tom Goetz <tom.goetz@virtualcomputer.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

diff -r 4c94bcf4b4af -r ded47a2ba411 xen/drivers/char/ns16550.c
--- a/xen/drivers/char/ns16550.c	Tue Jul 12 13:06:05 2011 -0400
+++ b/xen/drivers/char/ns16550.c	Tue Jul 12 13:06:05 2011 -0400
@@ -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 seria
     struct 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;

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 4 of 5] xen: Update pci_uart_config to save the BAR1 contents if com2 is used
  2011-07-12 17:53 [PATCH 0 of 5] Patches for PCI serial cards (v2) Konrad Rzeszutek Wilk
                   ` (2 preceding siblings ...)
  2011-07-12 17:53 ` [PATCH 3 of 5] xen: Restore the BAR and PCI command after resume Konrad Rzeszutek Wilk
@ 2011-07-12 17:53 ` Konrad Rzeszutek Wilk
  2011-07-13 10:07   ` George Dunlap
  2011-07-12 17:53 ` [PATCH 5 of 5] doc: Update the com1, com2 section with pci and amt options Konrad Rzeszutek Wilk
  4 siblings, 1 reply; 8+ messages in thread
From: Konrad Rzeszutek Wilk @ 2011-07-12 17:53 UTC (permalink / raw)
  To: xen-devel, keir, stefano.stabellini, Ian.Campbell, andrew.cooper3,
	JBeulich, George.Dunlap, ro
  Cc: konrad.wilk

# HG changeset patch
# User Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
# 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'.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

diff -r ded47a2ba411 -r 841e8a1304e7 xen/drivers/char/ns16550.c
--- a/xen/drivers/char/ns16550.c	Tue Jul 12 13:06:05 2011 -0400
+++ b/xen/drivers/char/ns16550.c	Tue Jul 12 13:52:55 2011 -0400
@@ -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 serial
     ns16550_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 seria
     struct 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_co
     if ( *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);
         }

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 5 of 5] doc: Update the com1, com2 section with pci and amt options
  2011-07-12 17:53 [PATCH 0 of 5] Patches for PCI serial cards (v2) Konrad Rzeszutek Wilk
                   ` (3 preceding siblings ...)
  2011-07-12 17:53 ` [PATCH 4 of 5] xen: Update pci_uart_config to save the BAR1 contents if com2 is used Konrad Rzeszutek Wilk
@ 2011-07-12 17:53 ` Konrad Rzeszutek Wilk
  4 siblings, 0 replies; 8+ messages in thread
From: Konrad Rzeszutek Wilk @ 2011-07-12 17:53 UTC (permalink / raw)
  To: xen-devel, keir, stefano.stabellini, Ian.Campbell, andrew.cooper3,
	JBeulich, George.Dunlap, ro
  Cc: konrad.wilk

# HG changeset patch
# User Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
# 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.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

diff -r 841e8a1304e7 -r d42a0c7903e6 docs/src/user.tex
--- a/docs/src/user.tex	Tue Jul 12 13:52:55 2011 -0400
+++ b/docs/src/user.tex	Tue Jul 12 13:52:57 2011 -0400
@@ -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}

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 4 of 5] xen: Update pci_uart_config to save the BAR1 contents if com2 is used
  2011-07-12 17:53 ` [PATCH 4 of 5] xen: Update pci_uart_config to save the BAR1 contents if com2 is used Konrad Rzeszutek Wilk
@ 2011-07-13 10:07   ` George Dunlap
  2011-07-13 13:23     ` Konrad Rzeszutek Wilk
  0 siblings, 1 reply; 8+ messages in thread
From: George Dunlap @ 2011-07-13 10:07 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: xen-devel@lists.xensource.com, keir@xen.org, Stefano Stabellini,
	George Dunlap, Andrew Cooper, JBeulich@novell.com, Ian Campbell,
	roger.cruz@virtualcomputer.com, tom.goetz@virtualcomputer.com

On Tue, 2011-07-12 at 18:53 +0100, Konrad Rzeszutek Wilk wrote:
> # HG changeset patch
> # User Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> # 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'.
> 
> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> 
> diff -r ded47a2ba411 -r 841e8a1304e7 xen/drivers/char/ns16550.c
> --- a/xen/drivers/char/ns16550.c	Tue Jul 12 13:06:05 2011 -0400
> +++ b/xen/drivers/char/ns16550.c	Tue Jul 12 13:52:55 2011 -0400
> @@ -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 serial
>      ns16550_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 seria
>      struct 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_co
>      if ( *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;

Isn't fixing issues found in earlier patches in later patches a bit
skanky? :-)

 -George

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 4 of 5] xen: Update pci_uart_config to save the BAR1 contents if com2 is used
  2011-07-13 10:07   ` George Dunlap
@ 2011-07-13 13:23     ` Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 8+ messages in thread
From: Konrad Rzeszutek Wilk @ 2011-07-13 13:23 UTC (permalink / raw)
  To: George Dunlap
  Cc: xen-devel@lists.xensource.com, keir@xen.org, Stefano Stabellini,
	George Dunlap, Andrew Cooper, JBeulich@novell.com, Ian Campbell,
	roger.cruz@virtualcomputer.com, tom.goetz@virtualcomputer.com

> 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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-07-13 13:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-12 17:53 [PATCH 0 of 5] Patches for PCI serial cards (v2) Konrad Rzeszutek Wilk
2011-07-12 17:53 ` [PATCH 1 of 5] xen: Automatically find serial port on PCI/PCIe and AMT devices Konrad Rzeszutek Wilk
2011-07-12 17:53 ` [PATCH 2 of 5] xen: Support suspend in ns16550 code Konrad Rzeszutek Wilk
2011-07-12 17:53 ` [PATCH 3 of 5] xen: Restore the BAR and PCI command after resume Konrad Rzeszutek Wilk
2011-07-12 17:53 ` [PATCH 4 of 5] xen: Update pci_uart_config to save the BAR1 contents if com2 is used Konrad Rzeszutek Wilk
2011-07-13 10:07   ` George Dunlap
2011-07-13 13:23     ` Konrad Rzeszutek Wilk
2011-07-12 17:53 ` [PATCH 5 of 5] doc: Update the com1, com2 section with pci and amt options Konrad Rzeszutek Wilk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.