ns16550: enable support for Pericom controllers
cover ns16550: enable support for Pericom controllers
Patches 1 and 2 are meant to go in. Patch 3 is a prerequisite to patch 4 and may go in as well, but patch 4 is RFC because with the Pericom board I have MSI doesn't appear to function. Since it also does not work in baremetal Linux when doing the trivial adjustments needed in its driver, I suspect the feature doesn't work in general, which is supported by the observation that the device continues to assert INTx despite the MSI enable bit being set (causing unclaimed IRQs until that IRQ gets shut off). While I got some responses back from Pericom support, no actual statement of whether MSI is actually known to work on their boards was ever made by them. I _think_ patch 4 is correct (and hence could go in), but I have no way of proving this by testing.
1: ns16550: store pointer to config parameters for PCI 2: ns16550: enable Pericom controller support 3: console: adjust IRQ initialization
4: ns16550: enable use of PCI MSI
(Konrad, I'd appreciate if you could double check that I didn't accidentally break the Oxford controller support.)
PATCH 1/4 ns16550: store pointer to config parameters for PCI
Subsequent changes will want to use this pointer.
This makes the enable_ro structure member redundant, so it gets dropped at once.
xen/drivers/char/ns16550.c +20 -23
@@ -74,7 +74,7 @@ static struct ns16550 {u32 bar64;u16 cr;u8 bar_idx; -bool_t enable_ro;/* Make MMIO devices read only to Dom0 */ +const struct ns16550_config_param *param;/* Points into .init.*! */ #endif } ns16550_com[2] = { { 0 } };
@@ -624,7 +624,7 @@ static void __init ns16550_init_postirq(#ifdef CONFIG_HAS_PCI if ( uart->bar || uart->ps_bdf_enable ) { -if ( !uart->enable_ro ) +if ( !uart->param )pci_hide_device (uart->ps_bdf[0 ],PCI_DEVFN (uart->ps_bdf[1 ], uart->ps_bdf[2 ]));else
@@ -900,7 +900,7 @@ pci_uart_config(struct ns16550 *uart, bo/* Check for params in uart_config lookup table */ for ( i =0 ; i <ARRAY_SIZE (uart_config); i++) { -unsigned int p; +const struct ns16550_config_param *param;if ( uart_config[i].vendor_id != vendor )continue ;
@@ -908,33 +908,34 @@ pci_uart_config(struct ns16550 *uart, boif ( uart_config[i].dev_id != device )continue ; - p = uart_config[i].param; + param = uart_param + uart_config[i].param; +/* * Force length of mmio region to be at least * 8 bytes times (1 << reg_shift) */ -if ( size < (0x8 * (1 << uart_param[p].reg_shift)) ) +if ( size < (0x8 * (1 << param->reg_shift)) )continue ; -if ( bar_idx >= uart_param[p].max_bars ) +if ( bar_idx >= param->max_bars )continue ; -if ( uart_param[p].fifo_size ) - uart->fifo_size = uart_param[p].fifo_size; + uart->param = param; + +if ( param->fifo_size ) + uart->fifo_size = param->fifo_size; - uart->reg_shift = uart_param[p].reg_shift; - uart->reg_width = uart_param[p].reg_width; - uart->lsr_mask = uart_param[p].lsr_mask; + uart->reg_shift = param->reg_shift; + uart->reg_width = param->reg_width; + uart->lsr_mask = param->lsr_mask; uart->io_base = ((u64 )bar_64 <<32 ) | (bar &PCI_BASE_ADDRESS_MEM_MASK ); - uart->io_base += uart_param[p].first_offset; - uart->io_base += bar_idx * uart_param[p].uart_offset; -if ( uart_param[p].base_baud ) - uart->clock_hz = uart_param[p].base_baud *16 ; - size =max (8U << uart_param[p].reg_shift, - uart_param[p].uart_offset); -/* Set device and MMIO region read only to Dom0 */ - uart->enable_ro =1 ; + uart->io_base += param->first_offset; + uart->io_base += bar_idx * param->uart_offset; +if ( param->base_baud ) + uart->clock_hz = param->base_baud *16 ; + size =max (8U << param->reg_shift, + param->uart_offset);break ; }
@@ -1094,10 +1095,6 @@ static void ns16550_init_common(struct n { uart->clock_hz =UART_CLOCK_HZ ; -#ifdef CONFIG_HAS_PCI - uart->enable_ro =0 ; -#endif -/* Default is no transmit FIFO. */ uart->fifo_size =1 ;
ns16550: store pointer to config parameters for PCI
Subsequent changes will want to use this pointer.
This makes the enable_ro structure member redundant, so it gets dropped at once.
xen/drivers/char/ns16550.c +20 -23
84 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 1/4] ns16550: store pointer to config parameters for PCI
Quoted 6 lines · Jan Beulich
Subsequent changes will want to use this pointer.
This makes the
enable_rostructure member redundant, so it gets dropped at once.Signed-off-by Jan Beulich <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH 2/4 ns16550: enable Pericom controller support
In reply to Jan BeulichOther than the controllers supported so far, multiple port Pericom boards map all of their ports via BAR0, which requires a number of
adjustments: Instead of tracking "max_bars" we now flag whether all ports use BAR0, and whether to expect a port-I/O or MMIO resource. As a result pci_uart_config() now gets handed a port index, which it then maps into a BAR index or an offset into BAR0 depending on the bar0 flag.
xen/drivers/char/ns16550.c +155 -84
@@ -78,10 +78,20 @@ static struct ns16550 {#endif } ns16550_com[2] = { { 0 } }; -struct ns16550_config_mmio { +#ifdef CONFIG_HAS_PCI +struct ns16550_config {u16 vendor_id;u16 dev_id; -unsigned int param; +enum { + param_default,/* Must not be referenced by any table entry. */ + param_trumanage, + param_oxford, + param_oxford_2port, + param_pericom_1port, + param_pericom_2port, + param_pericom_4port, + param_pericom_8port, + } param; };/* Defining uart config options for MMIO devices */
@@ -90,57 +100,91 @@ struct ns16550_config_param {unsigned int reg_width;unsigned int fifo_size;u8 lsr_mask; -unsigned int max_bars; +bool_t mmio; +bool_t bar0; +unsigned int max_ports;unsigned int base_baud;unsigned int uart_offset;unsigned int first_offset; }; - -#ifdef CONFIG_HAS_PCI -enum { - param_default = 0, - param_trumanage, - param_oxford, - param_oxford_2port, -};/* - * Create lookup tables for specific MMIO devices.. - * It is assumed that if the device found is MMIO, - * then you have indexed it here. Else, the driver - * does nothing. +* Create lookup tables for specific devices. It is assumed that if +* the device found is MMIO, then you have indexed it here. Else, the +* driver does nothing for MMIO based devices. */ static const struct ns16550_config_param __initconst uart_param[] = { - [param_default] = { }, /* Ignored. */ + [param_default] = { + .reg_width =1 , + .lsr_mask =UART_LSR_THRE , + .max_ports =1 , + }, [param_trumanage] = { .reg_shift =2 , .reg_width =1 , .fifo_size =16 , .lsr_mask = (UART_LSR_THRE |UART_LSR_TEMT ), - .max_bars = 1, + .mmio =1 , + .max_ports =1 , }, [param_oxford] = { .base_baud =4000000 , .uart_offset =0x200 , .first_offset =0x1000 , .reg_width =1 , - .reg_shift = 0, .fifo_size =16 , .lsr_mask =UART_LSR_THRE , - .max_bars = 1, /* It can do more, but we would need more custom code.*/ + .mmio =1 , + .max_ports =1 ,/* It can do more, but we would need more custom code.*/ }, [param_oxford_2port] = { .base_baud =4000000 , .uart_offset =0x200 , .first_offset =0x1000 , .reg_width =1 , - .reg_shift = 0, .fifo_size =16 , .lsr_mask =UART_LSR_THRE , - .max_bars = 2, + .mmio =1 , + .max_ports =2 , + }, + [param_pericom_1port] = { + .base_baud =921600 , + .uart_offset =8 , + .reg_width =1 , + .fifo_size =16 , + .lsr_mask =UART_LSR_THRE , + .bar0 =1 , + .max_ports =1 , + }, + [param_pericom_2port] = { + .base_baud =921600 , + .uart_offset =8 , + .reg_width =1 , + .fifo_size =16 , + .lsr_mask =UART_LSR_THRE , + .bar0 =1 , + .max_ports =2 , + }, + [param_pericom_4port] = { + .base_baud =921600 , + .uart_offset =8 , + .reg_width =1 , + .fifo_size =16 , + .lsr_mask =UART_LSR_THRE , + .bar0 =1 , + .max_ports =4 , + }, + [param_pericom_8port] = { + .base_baud =921600 , + .uart_offset =8 , + .reg_width =1 , + .fifo_size =16 , + .lsr_mask =UART_LSR_THRE , + .bar0 =1 , + .max_ports =8 , } }; -static const struct ns16550_config_mmio __initconst uart_config[] = +static const struct ns16550_config __initconst uart_config[] = {/* Broadcom TruManage device */ {
@@ -339,6 +383,30 @@ static const struct ns16550_config_mmio .vendor_id = PCI_VENDOR_ID_OXSEMI, .dev_id = 0xc4cf, .param = param_oxford, + }, + /* Pericom PI7C9X7951 Uno UART */ + { + .vendor_id = PCI_VENDOR_ID_PERICOM, + .dev_id = 0x7951, + .param = param_pericom_1port + }, + /* Pericom PI7C9X7952 Duo UART */ + { + .vendor_id = PCI_VENDOR_ID_PERICOM, + .dev_id = 0x7952, + .param = param_pericom_2port + }, + /* Pericom PI7C9X7954 Quad UART */ + { + .vendor_id = PCI_VENDOR_ID_PERICOM, + .dev_id = 0x7954, + .param = param_pericom_4port + }, + /* Pericom PI7C9X7958 Octal UART */ + { + .vendor_id = PCI_VENDOR_ID_PERICOM, + .dev_id = 0x7958, + .param = param_pericom_8port } }; #endif
@@ -629,7 +697,8 @@ static void __init ns16550_init_postirq( uart->ps_bdf[2])); else { -if (rangeset_add_range (mmio_ro_ranges, +if ( uart->param->mmio && +rangeset_add_range (mmio_ro_ranges, uart->io_base, uart->io_base + uart->io_size -1 ) )printk (XENLOG_INFO "Error while adding MMIO range of device to mmio_ro_ranges\n" );
@@ -830,12 +899,11 @@ static int __init check_existence(struct#ifdef CONFIG_HAS_PCI static int __init -pci_uart_config (struct ns16550 *uart,bool_t skip_amt,unsigned int bar_idx) +pci_uart_config (struct ns16550 *uart,bool_t skip_amt,unsigned int idx) {u64 orig_base = uart->io_base;unsigned int b, d, f, nextf, i; - uart->io_base =0 ;/* NB. Start at bus 1 to avoid AMT: a plug-in card cannot be on bus 0. */ for ( b = skip_amt ?1 :0 ; b <0x100 ; b++ ) {
@@ -843,8 +911,10 @@ pci_uart_config(struct ns16550 *uart, bo {for ( f =0 ; f <8 ; f = nextf ) { +unsigned int bar_idx =0 , port_idx = idx;uint32_t bar, bar_64 =0 , len, len_64; -u64 size; +u64 size =0 ; +const struct ns16550_config_param *param = uart_param; nextf = (f || (pci_conf_read16 (0 , b, d, f,PCI_HEADER_TYPE ) &0x80 )) ? f +1 :8 ;
@@ -863,15 +933,38 @@ pci_uart_config(struct ns16550 *uart, bocontinue ; } +/* Check for params in uart_config lookup table */ +for ( i =0 ; i <ARRAY_SIZE (uart_config); i++) + { +u16 vendor =pci_conf_read16 (0 , b, d, f,PCI_VENDOR_ID ); +u16 device =pci_conf_read16 (0 , b, d, f,PCI_DEVICE_ID ); + +if ( uart_config[i].vendor_id == vendor && + uart_config[i].dev_id == device ) + { + param += uart_config[i].param; +if ( !param->bar0 ) + { + bar_idx = idx; + port_idx =0 ; + } +break ; + } + } + +if ( port_idx >= param->max_ports ) + { + idx -= param->max_ports; +continue ; + } + + uart->io_base =0 ; bar =pci_conf_read32 (0 , b, d, f,PCI_BASE_ADDRESS_0 + bar_idx*4 );/* MMIO based */ -if ( !(bar &PCI_BASE_ADDRESS_SPACE_IO ) ) +if ( param->mmio && !(bar &PCI_BASE_ADDRESS_SPACE_IO ) ) { -u16 vendor =pci_conf_read16 (0 , b, d, f,PCI_VENDOR_ID ); -u16 device =pci_conf_read16 (0 , b, d, f,PCI_DEVICE_ID ); -pci_conf_write32 (0 , b, d, f,PCI_BASE_ADDRESS_0 + bar_idx*4 , ~0u ); len =pci_conf_read32 (0 , b, d, f,PCI_BASE_ADDRESS_0 + bar_idx*4 );
@@ -895,56 +988,11 @@ pci_uart_config(struct ns16550 *uart, boelse size = len &PCI_BASE_ADDRESS_MEM_MASK ; - size &= -size; - -/* Check for params in uart_config lookup table */ -for ( i =0 ; i <ARRAY_SIZE (uart_config); i++) - { -const struct ns16550_config_param *param; - -if ( uart_config[i].vendor_id != vendor ) -continue ; - -if ( uart_config[i].dev_id != device ) -continue ; - - param = uart_param + uart_config[i].param; - -/* -* Force length of mmio region to be at least -* 8 bytes times (1 << reg_shift) -*/ -if ( size < (0x8 * (1 << param->reg_shift)) ) -continue ; - -if ( bar_idx >= param->max_bars ) -continue ; - - uart->param = param; - -if ( param->fifo_size ) - uart->fifo_size = param->fifo_size; - - uart->reg_shift = param->reg_shift; - uart->reg_width = param->reg_width; - uart->lsr_mask = param->lsr_mask; - uart->io_base = ((u64 )bar_64 <<32 ) | - (bar &PCI_BASE_ADDRESS_MEM_MASK ); - uart->io_base += param->first_offset; - uart->io_base += bar_idx * param->uart_offset; -if ( param->base_baud ) - uart->clock_hz = param->base_baud *16 ; - size =max (8U << param->reg_shift, - param->uart_offset); -break ; - } - -/* If we have an io_base, then we succeeded in the lookup */ -if ( !uart->io_base ) -continue ; + uart->io_base = ((u64 )bar_64 <<32 ) | + (bar &PCI_BASE_ADDRESS_MEM_MASK ); }/* IO based */ -else +else if ( !param->mmio && (bar &PCI_BASE_ADDRESS_SPACE_IO ) ) {pci_conf_write32 (0 , b, d, f,PCI_BASE_ADDRESS_0 + bar_idx*4 , ~0u );
@@ -952,22 +1000,45 @@ pci_uart_config(struct ns16550 *uart, bopci_conf_write32 (0 , b, d, f,PCI_BASE_ADDRESS_0 + bar_idx*4 , bar); size = len &PCI_BASE_ADDRESS_IO_MASK ; - size &= -size; - -/* Not at least 8 bytes */ -if ( size <8 ) -continue ; uart->io_base = bar & ~PCI_BASE_ADDRESS_SPACE_IO ; } +/* If we have an io_base, then we succeeded in the lookup. */ +if ( !uart->io_base ) +continue ; + + size &= -size; + +/* +* Require length of actually used region to be at least +* 8 bytes times (1 << reg_shift). +*/ +if ( size < param->first_offset + + port_idx * param->uart_offset + + (8 << param->reg_shift) ) +continue ; + + uart->param = param; + + uart->reg_shift = param->reg_shift; + uart->reg_width = param->reg_width; + uart->lsr_mask = param->lsr_mask; + uart->io_base += param->first_offset + + port_idx * param->uart_offset; +if ( param->base_baud ) + uart->clock_hz = param->base_baud *16 ; +if ( param->fifo_size ) + uart->fifo_size = param->fifo_size; + uart->ps_bdf[0 ] = b; uart->ps_bdf[1 ] = d; uart->ps_bdf[2 ] = f; uart->bar_idx = bar_idx; uart->bar = bar; uart->bar64 = bar_64; - uart->io_size = size; + uart->io_size =max (8U << param->reg_shift, + param->uart_offset); uart->irq =pci_conf_read8 (0 , b, d, f,PCI_INTERRUPT_PIN ) ?pci_conf_read8 (0 , b, d, f,PCI_INTERRUPT_LINE ) :0 ;
xen/include/xen/pci_ids.h +2 -0
@@ -2,6 +2,8 @@#define PCI_VENDOR_ID_NVIDIA 0x10de +#define PCI_VENDOR_ID_PERICOM 0x12d8 +#define PCI_VENDOR_ID_OXSEMI 0x1415#define PCI_VENDOR_ID_BROADCOM 0x14e4
ns16550: enable Pericom controller support
Other than the controllers supported so far, multiple port Pericom boards map all of their ports via BAR0, which requires a number of
adjustments: Instead of tracking "max_bars" we now flag whether all ports use BAR0, and whether to expect a port-I/O or MMIO resource. As a result pci_uart_config() now gets handed a port index, which it then maps into a BAR index or an offset into BAR0 depending on the bar0 flag.
xen/drivers/char/ns16550.c +155 -84
348 lines not on this page · raw message
xen/include/xen/pci_ids.h +2 -0
@@ -2,6 +2,8 @@#define PCI_VENDOR_ID_NVIDIA 0x10de +#define PCI_VENDOR_ID_PERICOM 0x12d8 +#define PCI_VENDOR_ID_OXSEMI 0x1415#define PCI_VENDOR_ID_BROADCOM 0x14e4
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 2/4] ns16550: enable Pericom controller support
Quoted 7 lines
xen/drivers/char/ns16550.c +7
-0+ [param_pericom_4port] = { + .base_baud = 921600, + .uart_offset = 8, + .reg_width = 1, + .fifo_size = 16, + .lsr_mask = UART_LSR_THRE, + .bar0 = 1,
xen/drivers/char/ns16550.c struct ns16550_config_param { · line 184
Quoted 10 lines
xen/drivers/char/ns16550.c +10
-0+ .max_ports = 4, + }, + [param_pericom_8port] = { + .base_baud = 921600, + .uart_offset = 8, + .reg_width = 1, + .fifo_size = 16, + .lsr_mask = UART_LSR_THRE, + .bar0 = 1, + .max_ports = 8,
Perhaps document that Xen can only access two of the ports? Unless we expand the ns16550_com array of course.
Quoted 15 lines
xen/drivers/char/ns16550.c +1
-2@@ -830,12 +899,11 @@ static int __init check_existence(struct#ifdef CONFIG_HAS_PCI static int __init -pci_uart_config (struct ns16550 *uart,bool_t skip_amt,unsigned int bar_idx) +pci_uart_config (struct ns16550 *uart,bool_t skip_amt,unsigned int idx) {u64 orig_base = uart->io_base;unsigned int b, d, f, nextf, i; - uart->io_base =0 ;/* NB. Start at bus 1 to avoid AMT: a plug-in card cannot be on bus 0. */ for ( b = skip_amt ?1 :0 ; b <0x100 ; b++ ) {
xen/drivers/char/ns16550.c pci_uart_config(struct ns16550 *uart, bo · line 914
Quoted 4 lines
xen/drivers/char/ns16550.c +1
-0@@ -843,8 +911,10 @@ pci_uart_config(struct ns16550 *uart, bo {for ( f =0 ; f <8 ; f = nextf ) { +unsigned int bar_idx =0 , port_idx = idx;
s/port_idx/port/? or port_nr /?
xen/drivers/char/ns16550.c pci_uart_config(struct ns16550 *uart, bo · line 937
Quoted 13 lines
xen/drivers/char/ns16550.c +4
-1uint32_t bar, bar_64 =0 , len, len_64; -u64 size; +u64 size =0 ; +const struct ns16550_config_param *param = uart_param; nextf = (f || (pci_conf_read16 (0 , b, d, f,PCI_HEADER_TYPE ) &0x80 )) ? f +1 :8 ;@@ -863,15 +933,38 @@ pci_uart_config(struct ns16550 *uart, bocontinue ; } +/* Check for params in uart_config lookup table */ +for ( i =0 ; i <ARRAY_SIZE (uart_config); i++)
I am pretty sure I wrote this piece of code - could you fix the Style on it please? The i++) please?
Quoted 11 lines
xen/drivers/char/ns16550.c +11
-0+ { +u16 vendor =pci_conf_read16 (0 , b, d, f,PCI_VENDOR_ID ); +u16 device =pci_conf_read16 (0 , b, d, f,PCI_DEVICE_ID ); + +if ( uart_config[i].vendor_id == vendor && + uart_config[i].dev_id == device ) + { + param += uart_config[i].param; +if ( !param->bar0 ) + { + bar_idx = idx;
xen/drivers/char/ns16550.c pci_uart_config(struct ns16550 *uart, bo · line 958
Quoted 10 lines
xen/drivers/char/ns16550.c +10
-0+ port_idx =0 ; + } +break ; + } + } + +if ( port_idx >= param->max_ports ) + { + idx -= param->max_ports; +continue ;
Could you add a comment about this? I understand it can detect if we are using an AMT device with the 'com2=115200,8n1,amt' (which would be invalid - AMT devices only have one IO PORT and there is only one of them on the machine) we would skip over the found device and continue on.. Thought I don't understand why we want to decrease the idx value from one to zero?
Hmm, if it was some other PCI based serial card like:
01:05.0 Serial controller: NetMos Technology PCI 9835 Multi-I/O Controller (rev 01) (prog-if 02 [16550])
Subsystem: LSI Logic / Symbios Logic Device 0001
Flags: medium devsel, IRQ 20
I/O ports at e050 [size=8]
I/O ports at e040 [size=8]
I/O ports at e030 [size=8]
I/O ports at e020 [size=8]
I/O ports at e010 [size=8]
I/O ports at e000 [size=16]With 'com1=115200,8n1,pci' and 'com2=115200,8n1,pci' then the first loop would find the device. The second loop would decrement idx (1) by 1 and continue.. which would make it go search for another device.
I hadn't tested this patch on the above device but I believe it used to work with the com1 and com2 going throught it - while with the new code it won't?
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 2/4] ns16550: enable Pericom controller support
Quoted 19 lines
Quoted 8 lines
Quoted 1 line · On 07.03.16 at 23:04, <[email protected]> wrote:
+ [
param_pericom_4port] = {xen/drivers/char/ns16550.c +6
-0+ .base_baud = 921600, + .uart_offset = 8, + .reg_width = 1, + .fifo_size = 16, + .lsr_mask = UART_LSR_THRE, + .bar0 = 1,xen/drivers/char/ns16550.c struct ns16550_config_param { · line 184
Quoted 10 lines
xen/drivers/char/ns16550.c +10
-0+ .max_ports = 4, + }, + [param_pericom_8port] = { + .base_baud = 921600, + .uart_offset = 8, + .reg_width = 1, + .fifo_size = 16, + .lsr_mask = UART_LSR_THRE, + .bar0 = 1, + .max_ports = 8,
Quoted 2 lines
Perhaps document that Xen can only access two of the ports? Unless we expand the
ns16550_comarray of course.
Done.
Quoted 7 lines
xen/drivers/char/ns16550.c pci_uart_config(struct ns16550 *uart, bo · line 914
Quoted 5 lines
xen/drivers/char/ns16550.c +1
-0@@ -843,8 +911,10 @@ pci_uart_config(struct ns16550 *uart, bo {for ( f =0 ; f <8 ; f = nextf ) { +unsigned int bar_idx =0 , port_idx = idx;s/port_idx/port/? or
port_nr/?
"port" would be misleading/ambiguous, and I don't see port_nr being any better than port_idx (or if so, it ought to then also be bar_nr). In fact, "nr" - other than "idx" - is ambiguous too (commonly indicating "number of ...").
Quoted 9 lines
xen/drivers/char/ns16550.c pci_uart_config(struct ns16550 *uart, bo · line 937
Quoted 6 lines
xen/drivers/char/ns16550.c +2
-0@@ -863,15 +933,38 @@ pci_uart_config(struct ns16550 *uart, bocontinue ; } +/* Check for params in uart_config lookup table */ +for ( i =0 ; i <ARRAY_SIZE (uart_config); i++)I am pretty sure I wrote this piece of code - could you fix the Style on it please? The i++) please?
Sure.
Quoted 11 lines
xen/drivers/char/ns16550.c pci_uart_config(struct ns16550 *uart, bo · line 958
Quoted 4 lines
xen/drivers/char/ns16550.c +4
-0+if ( port_idx >= param->max_ports ) + { + idx -= param->max_ports; +continue ;Could you add a comment about this? I understand it can detect if we are using an AMT device with the 'com2=115200,8n1,amt' (which would be invalid - AMT devices only have one IO PORT and there is only one of them on the machine) we would skip over the found device and continue on.. Thought I don't understand why we want to decrease the idx value from one to zero?
If we're looking for COM2 and have found a 1-port card, we want to use the 1st (rather than the 2nd) port on the next card we may find (if any). This seems pretty obvious behavior to me here, so I'm not really convinced a comment is warranted.
Quoted 13 lines
Hmm, if it was some other PCI based serial card like:
01:05.0 Serial controller: NetMos Technology PCI 9835 Multi-I/O Controller (rev 01) (prog-if 02 [16550])
Subsystem: LSI Logic / Symbios Logic Device 0001 Flags: medium devsel, IRQ 20 I/O ports at e050 [size=8] I/O ports at e040 [size=8] I/O ports at e030 [size=8] I/O ports at e020 [size=8] I/O ports at e010 [size=8] I/O ports at e000 [size=16]
Quoted 7 lines
With 'com1=115200,8n1,pci' and 'com2=115200,8n1,pci' then the first loop would find the device. The second loop would decrement idx (1) by 1 and continue.. which would make it go search for another device.
I hadn't tested this patch on the above device but I believe it used to work with the com1 and com2 going throught it - while with the new code it won't?
That's the !bar0 case, and hence the code in the loop over uart_config[] would set port_idx to zero, so the conditional above won't evaluate to true anyway. I.e. no change in behavior over the original code (albeit arguably that behavior is not fully correct, at least if we consider arbitrary bar_idx values - right now it can only be 0 or 1 -, since some skipping logic would then be needed too). The question is whether we shouldn't have all single port cards have their bar0 flag set to true (or extend the conditional inside the loop to "!param->bar0 && param->max_ports > 1"), to enable this skipping in all of those cases.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 2/4] ns16550: enable Pericom controller support
Quoted 83 lines · Jan Beulich
Quoted 19 lines
Quoted 8 lines
Quoted 1 line · On 07.03.16 at 23:04, <[email protected]> wrote:
+ [
param_pericom_4port] = {xen/drivers/char/ns16550.c +6
-0+ .base_baud = 921600, + .uart_offset = 8, + .reg_width = 1, + .fifo_size = 16, + .lsr_mask = UART_LSR_THRE, + .bar0 = 1,xen/drivers/char/ns16550.c struct ns16550_config_param { · line 184
Quoted 10 lines
xen/drivers/char/ns16550.c +10
-0+ .max_ports = 4, + }, + [param_pericom_8port] = { + .base_baud = 921600, + .uart_offset = 8, + .reg_width = 1, + .fifo_size = 16, + .lsr_mask = UART_LSR_THRE, + .bar0 = 1, + .max_ports = 8,Quoted 2 lines
Perhaps document that Xen can only access two of the ports? Unless we expand the
ns16550_comarray of course.Done.
Quoted 7 lines
xen/drivers/char/ns16550.c pci_uart_config(struct ns16550 *uart, bo · line 914
Quoted 5 lines
xen/drivers/char/ns16550.c +1
-0@@ -843,8 +911,10 @@ pci_uart_config(struct ns16550 *uart, bo {for ( f =0 ; f <8 ; f = nextf ) { +unsigned int bar_idx =0 , port_idx = idx;s/port_idx/port/? or
port_nr/?"port" would be misleading/ambiguous, and I don't see
port_nrbeing any better thanport_idx(or if so, it ought to then also bebar_nr). In fact, "nr" - other than "idx" - is ambiguous too (commonly indicating "number of ...").Quoted 9 lines
xen/drivers/char/ns16550.c pci_uart_config(struct ns16550 *uart, bo · line 937
Quoted 6 lines
xen/drivers/char/ns16550.c +2
-0@@ -863,15 +933,38 @@ pci_uart_config(struct ns16550 *uart, bocontinue ; } +/* Check for params in uart_config lookup table */ +for ( i =0 ; i <ARRAY_SIZE (uart_config); i++)I am pretty sure I wrote this piece of code - could you fix the Style on it please? The i++) please?
Sure.
Quoted 11 lines
xen/drivers/char/ns16550.c pci_uart_config(struct ns16550 *uart, bo · line 958
Quoted 4 lines
xen/drivers/char/ns16550.c +4
-0+if ( port_idx >= param->max_ports ) + { + idx -= param->max_ports; +continue ;Could you add a comment about this? I understand it can detect if we are using an AMT device with the 'com2=115200,8n1,amt' (which would be invalid - AMT devices only have one IO PORT and there is only one of them on the machine) we would skip over the found device and continue on.. Thought I don't understand why we want to decrease the idx value from one to zero?
If we're looking for COM2 and have found a 1-port card, we want to use the 1st (rather than the 2nd) port on the next card we may find (if any). This seems pretty obvious behavior to me here, so I'm not really convinced a comment is warranted.
Quoted 17 lines
Hmm, if it was some other PCI based serial card like:
01:05.0 Serial controller: NetMos Technology PCI 9835 Multi-I/O Controller (rev 01) (prog-if 02 [16550])
Subsystem: LSI Logic / Symbios Logic Device 0001 Flags: medium devsel, IRQ 20 I/O ports at e050 [size=8] I/O ports at e040 [size=8] I/O ports at e030 [size=8] I/O ports at e020 [size=8] I/O ports at e010 [size=8] I/O ports at e000 [size=16]With 'com1=115200,8n1,pci' and 'com2=115200,8n1,pci' then the first loop would find the device. The second loop would decrement idx (1) by 1 and continue.. which would make it go search for another device.
Quoted 5 lines
Quoted 3 lines
I hadn't tested this patch on the above device but I believe it used to work with the com1 and com2 going throught it - while with the new code it won't?
That's the !bar0 case, and hence the code in the loop over
You mean:
param += uart_config[i].param;
+ if ( !param->bar0 )
+ {
+ bar_idx = idx;
+ port_idx = 0;
+ }
?
The device in question (NetMos) is not on the uart_config list at all so we won't get inside this loop.
Quoted 10 lines
uart_config[] would set
port_idxto zero, so the conditional above won't evaluate to true anyway. I.e. no change in behavior over the original code (albeit arguably that behavior is not fully correct, at least if we consider arbitrarybar_idxvalues - right now it can only be 0 or 1 -, since some skipping logic would then be needed too). The question is whether we shouldn't have all single port cards have their bar0 flag set to true (or extend the conditional inside the loop to "!param->bar0 &¶m->max_ports> 1"), to enable this skipping in all of those cases.
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 2/4] ns16550: enable Pericom controller support
Quoted 36 lines
Quoted 1 line
Quoted 1 line · On 09.03.16 at 17:52, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 07.03.16 at 23:04, <[email protected]> wrote:
Hmm, if it was some other PCI based serial card like:
01:05.0 Serial controller: NetMos Technology PCI 9835 Multi-I/O Controller (rev 01) (prog-if 02 [16550])
Subsystem: LSI Logic / Symbios Logic Device 0001 Flags: medium devsel, IRQ 20 I/O ports at e050 [size=8] I/O ports at e040 [size=8] I/O ports at e030 [size=8] I/O ports at e020 [size=8] I/O ports at e010 [size=8] I/O ports at e000 [size=16]With 'com1=115200,8n1,pci' and 'com2=115200,8n1,pci' then the first loop would find the device. The second loop would decrement idx (1) by 1 and continue.. which would make it go search for another device.
Quoted 5 lines
Quoted 3 lines
I hadn't tested this patch on the above device but I believe it used to work with the com1 and com2 going throught it - while with the new code it won't?
That's the !bar0 case, and hence the code in the loop over
You mean:
param += uart_config[i].param;xen/drivers/char/ns16550.c +5
-0+if ( !param->bar0 ) + { + bar_idx = idx; + port_idx =0 ; + }?
Quoted 2 lines
The device in question (NetMos) is not on the
uart_configlist at all so we won't get inside this loop.
Well, for devices not on the list it's undetermined anyway whether they would happen to work - we just can't get it right for all possible cases. Someone truly caring about them working should submit a patch adding them to the list.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 2/4] ns16550: enable Pericom controller support
Quoted 36 lines · Jan Beulich
Quoted 36 lines
Quoted 1 line
Quoted 1 line · On 09.03.16 at 17:52, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 07.03.16 at 23:04, <[email protected]> wrote:
Hmm, if it was some other PCI based serial card like:
01:05.0 Serial controller: NetMos Technology PCI 9835 Multi-I/O Controller (rev 01) (prog-if 02 [16550])
Subsystem: LSI Logic / Symbios Logic Device 0001 Flags: medium devsel, IRQ 20 I/O ports at e050 [size=8] I/O ports at e040 [size=8] I/O ports at e030 [size=8] I/O ports at e020 [size=8] I/O ports at e010 [size=8] I/O ports at e000 [size=16]With 'com1=115200,8n1,pci' and 'com2=115200,8n1,pci' then the first loop would find the device. The second loop would decrement idx (1) by 1 and continue.. which would make it go search for another device.
Quoted 5 lines
Quoted 3 lines
I hadn't tested this patch on the above device but I believe it used to work with the com1 and com2 going throught it - while with the new code it won't?
That's the !bar0 case, and hence the code in the loop over
You mean:
param += uart_config[i].param;xen/drivers/char/ns16550.c +5
-0+if ( !param->bar0 ) + { + bar_idx = idx; + port_idx =0 ; + }?
Quoted 6 lines
Quoted 2 lines
The device in question (NetMos) is not on the
uart_configlist at all so we won't get inside this loop.Well, for devices not on the list it's undetermined anyway whether they would happen to work - we just can't get it right for all possible cases. Someone truly caring about them working should submit a
Wouldn't your patch cause a regression compared to how it used to work in earlier version of Xen?
Let me take a peek at the card in question and see if I can hook up an extra RS232 connector.
Quoted 9 lines
patch adding them to the list.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 2/4] ns16550: enable Pericom controller support
Quoted 41 lines
Quoted 1 line
Quoted 1 line · On 11.03.16 at 03:31, <[email protected]> wrote:
Quoted 39 lines · Jan Beulich
Quoted 38 lines
Quoted 1 line
Quoted 1 line · On 09.03.16 at 17:52, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 07.03.16 at 23:04, <[email protected]> wrote:
Hmm, if it was some other PCI based serial card like:
01:05.0 Serial controller: NetMos Technology PCI 9835 Multi-I/O Controller (rev 01) (prog-if 02 [16550])
Subsystem: LSI Logic / Symbios Logic Device 0001 Flags: medium devsel, IRQ 20 I/O ports at e050 [size=8] I/O ports at e040 [size=8] I/O ports at e030 [size=8] I/O ports at e020 [size=8] I/O ports at e010 [size=8] I/O ports at e000 [size=16]With 'com1=115200,8n1,pci' and 'com2=115200,8n1,pci' then the first loop would find the device. The second loop would decrement idx (1) by 1 and continue.. which would make it go search for another device.
Quoted 5 lines
Quoted 3 lines
I hadn't tested this patch on the above device but I believe it used to work with the com1 and com2 going throught it - while with the new code it won't?
That's the !bar0 case, and hence the code in the loop over
You mean:
param += uart_config[i].param;xen/drivers/char/ns16550.c +5
-0+if ( !param->bar0 ) + { + bar_idx = idx; + port_idx =0 ; + }?
The device in question (NetMos) is not on the
uart_configlist at all so we won't get inside this loop.
Quoted 6 lines
Quoted 3 lines
Well, for devices not on the list it's undetermined anyway whether they would happen to work - we just can't get it right for all possible cases. Someone truly caring about them working should submit a
Wouldn't your patch cause a regression compared to how it used to work in earlier version of Xen?
It would, if you want to call such a regression (as I don't think it was determined to behave that way). But okay, I'll simply move the above conditional past the loop, to retain previous behavior.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v2 2/4 ns16550: enable Pericom controller support
In reply to Jan BeulichOther than the controllers supported so far, multiple port Pericom boards map all of their ports via BAR0, which requires a number of
adjustments: Instead of tracking "max_bars" we now flag whether all ports use BAR0, and whether to expect a port-I/O or MMIO resource. As a result pci_uart_config() now gets handed a port index, which it then maps into a BAR index or an offset into BAR0 depending on the bar0 flag.
---
v2: Fix coding style in a piece of code being moved. Add a comment
clarifying that on the 4- and 8-port variants we can't use all the ports for now. Retain previous behavior for PCI devices not explicitly listed, even if that behavior was undefined. (The rest of the series is unchanged, so I won't bother reposting the other patches.)
xen/drivers/char/ns16550.c +160 -84
@@ -78,10 +78,20 @@ static struct ns16550 {#endif } ns16550_com[2] = { { 0 } }; -struct ns16550_config_mmio { +#ifdef CONFIG_HAS_PCI +struct ns16550_config {u16 vendor_id;u16 dev_id; -unsigned int param; +enum { + param_default,/* Must not be referenced by any table entry. */ + param_trumanage, + param_oxford, + param_oxford_2port, + param_pericom_1port, + param_pericom_2port, + param_pericom_4port, + param_pericom_8port, + } param; };/* Defining uart config options for MMIO devices */
@@ -90,57 +100,95 @@ struct ns16550_config_param {unsigned int reg_width;unsigned int fifo_size;u8 lsr_mask; -unsigned int max_bars; +bool_t mmio; +bool_t bar0; +unsigned int max_ports;unsigned int base_baud;unsigned int uart_offset;unsigned int first_offset; }; - -#ifdef CONFIG_HAS_PCI -enum { - param_default = 0, - param_trumanage, - param_oxford, - param_oxford_2port, -};/* - * Create lookup tables for specific MMIO devices.. - * It is assumed that if the device found is MMIO, - * then you have indexed it here. Else, the driver - * does nothing. +* Create lookup tables for specific devices. It is assumed that if +* the device found is MMIO, then you have indexed it here. Else, the +* driver does nothing for MMIO based devices. */ static const struct ns16550_config_param __initconst uart_param[] = { - [param_default] = { }, /* Ignored. */ + [param_default] = { + .reg_width =1 , + .lsr_mask =UART_LSR_THRE , + .max_ports =1 , + }, [param_trumanage] = { .reg_shift =2 , .reg_width =1 , .fifo_size =16 , .lsr_mask = (UART_LSR_THRE |UART_LSR_TEMT ), - .max_bars = 1, + .mmio =1 , + .max_ports =1 , }, [param_oxford] = { .base_baud =4000000 , .uart_offset =0x200 , .first_offset =0x1000 , .reg_width =1 , - .reg_shift = 0, .fifo_size =16 , .lsr_mask =UART_LSR_THRE , - .max_bars = 1, /* It can do more, but we would need more custom code.*/ + .mmio =1 , + .max_ports =1 ,/* It can do more, but we would need more custom code.*/ }, [param_oxford_2port] = { .base_baud =4000000 , .uart_offset =0x200 , .first_offset =0x1000 , .reg_width =1 , - .reg_shift = 0, .fifo_size =16 , .lsr_mask =UART_LSR_THRE , - .max_bars = 2, + .mmio =1 , + .max_ports =2 , + }, + [param_pericom_1port] = { + .base_baud =921600 , + .uart_offset =8 , + .reg_width =1 , + .fifo_size =16 , + .lsr_mask =UART_LSR_THRE , + .bar0 =1 , + .max_ports =1 , + }, + [param_pericom_2port] = { + .base_baud =921600 , + .uart_offset =8 , + .reg_width =1 , + .fifo_size =16 , + .lsr_mask =UART_LSR_THRE , + .bar0 =1 , + .max_ports =2 , + }, +/* +* Of the two following ones, we can't really use all of their ports, +* unless ns16550_com[] would get grown. +*/ + [param_pericom_4port] = { + .base_baud =921600 , + .uart_offset =8 , + .reg_width =1 , + .fifo_size =16 , + .lsr_mask =UART_LSR_THRE , + .bar0 =1 , + .max_ports =4 , + }, + [param_pericom_8port] = { + .base_baud =921600 , + .uart_offset =8 , + .reg_width =1 , + .fifo_size =16 , + .lsr_mask =UART_LSR_THRE , + .bar0 =1 , + .max_ports =8 , } }; -static const struct ns16550_config_mmio __initconst uart_config[] = +static const struct ns16550_config __initconst uart_config[] = {/* Broadcom TruManage device */ {
@@ -339,6 +387,30 @@ static const struct ns16550_config_mmio .vendor_id = PCI_VENDOR_ID_OXSEMI, .dev_id = 0xc4cf, .param = param_oxford, + }, + /* Pericom PI7C9X7951 Uno UART */ + { + .vendor_id = PCI_VENDOR_ID_PERICOM, + .dev_id = 0x7951, + .param = param_pericom_1port + }, + /* Pericom PI7C9X7952 Duo UART */ + { + .vendor_id = PCI_VENDOR_ID_PERICOM, + .dev_id = 0x7952, + .param = param_pericom_2port + }, + /* Pericom PI7C9X7954 Quad UART */ + { + .vendor_id = PCI_VENDOR_ID_PERICOM, + .dev_id = 0x7954, + .param = param_pericom_4port + }, + /* Pericom PI7C9X7958 Octal UART */ + { + .vendor_id = PCI_VENDOR_ID_PERICOM, + .dev_id = 0x7958, + .param = param_pericom_8port } }; #endif
@@ -629,7 +701,8 @@ static void __init ns16550_init_postirq( uart->ps_bdf[2])); else { -if (rangeset_add_range (mmio_ro_ranges, +if ( uart->param->mmio && +rangeset_add_range (mmio_ro_ranges, uart->io_base, uart->io_base + uart->io_size -1 ) )printk (XENLOG_INFO "Error while adding MMIO range of device to mmio_ro_ranges\n" );
@@ -830,12 +903,11 @@ static int __init check_existence(struct#ifdef CONFIG_HAS_PCI static int __init -pci_uart_config (struct ns16550 *uart,bool_t skip_amt,unsigned int bar_idx) +pci_uart_config (struct ns16550 *uart,bool_t skip_amt,unsigned int idx) {u64 orig_base = uart->io_base;unsigned int b, d, f, nextf, i; - uart->io_base =0 ;/* NB. Start at bus 1 to avoid AMT: a plug-in card cannot be on bus 0. */ for ( b = skip_amt ?1 :0 ; b <0x100 ; b++ ) {
@@ -843,8 +915,10 @@ pci_uart_config(struct ns16550 *uart, bo {for ( f =0 ; f <8 ; f = nextf ) { +unsigned int bar_idx =0 , port_idx = idx;uint32_t bar, bar_64 =0 , len, len_64; -u64 size; +u64 size =0 ; +const struct ns16550_config_param *param = uart_param; nextf = (f || (pci_conf_read16 (0 , b, d, f,PCI_HEADER_TYPE ) &0x80 )) ? f +1 :8 ;
@@ -863,15 +937,39 @@ pci_uart_config(struct ns16550 *uart, bocontinue ; } +/* Check for params in uart_config lookup table */ +for ( i =0 ; i <ARRAY_SIZE (uart_config); i++ ) + { +u16 vendor =pci_conf_read16 (0 , b, d, f,PCI_VENDOR_ID ); +u16 device =pci_conf_read16 (0 , b, d, f,PCI_DEVICE_ID ); + +if ( uart_config[i].vendor_id == vendor && + uart_config[i].dev_id == device ) + { + param += uart_config[i].param; +break ; + } + } + +if ( !param->bar0 ) + { + bar_idx = idx; + port_idx =0 ; + } + +if ( port_idx >= param->max_ports ) + { + idx -= param->max_ports; +continue ; + } + + uart->io_base =0 ; bar =pci_conf_read32 (0 , b, d, f,PCI_BASE_ADDRESS_0 + bar_idx*4 );/* MMIO based */ -if ( !(bar &PCI_BASE_ADDRESS_SPACE_IO ) ) +if ( param->mmio && !(bar &PCI_BASE_ADDRESS_SPACE_IO ) ) { -u16 vendor =pci_conf_read16 (0 , b, d, f,PCI_VENDOR_ID ); -u16 device =pci_conf_read16 (0 , b, d, f,PCI_DEVICE_ID ); -pci_conf_write32 (0 , b, d, f,PCI_BASE_ADDRESS_0 + bar_idx*4 , ~0u ); len =pci_conf_read32 (0 , b, d, f,PCI_BASE_ADDRESS_0 + bar_idx*4 );
@@ -895,56 +993,11 @@ pci_uart_config(struct ns16550 *uart, boelse size = len &PCI_BASE_ADDRESS_MEM_MASK ; - size &= -size; - -/* Check for params in uart_config lookup table */ -for ( i =0 ; i <ARRAY_SIZE (uart_config); i++) - { -const struct ns16550_config_param *param; - -if ( uart_config[i].vendor_id != vendor ) -continue ; - -if ( uart_config[i].dev_id != device ) -continue ; - - param = uart_param + uart_config[i].param; - -/* -* Force length of mmio region to be at least -* 8 bytes times (1 << reg_shift) -*/ -if ( size < (0x8 * (1 << param->reg_shift)) ) -continue ; - -if ( bar_idx >= param->max_bars ) -continue ; - - uart->param = param; - -if ( param->fifo_size ) - uart->fifo_size = param->fifo_size; - - uart->reg_shift = param->reg_shift; - uart->reg_width = param->reg_width; - uart->lsr_mask = param->lsr_mask; - uart->io_base = ((u64 )bar_64 <<32 ) | - (bar &PCI_BASE_ADDRESS_MEM_MASK ); - uart->io_base += param->first_offset; - uart->io_base += bar_idx * param->uart_offset; -if ( param->base_baud ) - uart->clock_hz = param->base_baud *16 ; - size =max (8U << param->reg_shift, - param->uart_offset); -break ; - } - -/* If we have an io_base, then we succeeded in the lookup */ -if ( !uart->io_base ) -continue ; + uart->io_base = ((u64 )bar_64 <<32 ) | + (bar &PCI_BASE_ADDRESS_MEM_MASK ); }/* IO based */ -else +else if ( !param->mmio && (bar &PCI_BASE_ADDRESS_SPACE_IO ) ) {pci_conf_write32 (0 , b, d, f,PCI_BASE_ADDRESS_0 + bar_idx*4 , ~0u );
@@ -952,22 +1005,45 @@ pci_uart_config(struct ns16550 *uart, bopci_conf_write32 (0 , b, d, f,PCI_BASE_ADDRESS_0 + bar_idx*4 , bar); size = len &PCI_BASE_ADDRESS_IO_MASK ; - size &= -size; - -/* Not at least 8 bytes */ -if ( size <8 ) -continue ; uart->io_base = bar & ~PCI_BASE_ADDRESS_SPACE_IO ; } +/* If we have an io_base, then we succeeded in the lookup. */ +if ( !uart->io_base ) +continue ; + + size &= -size; + +/* +* Require length of actually used region to be at least +* 8 bytes times (1 << reg_shift). +*/ +if ( size < param->first_offset + + port_idx * param->uart_offset + + (8 << param->reg_shift) ) +continue ; + + uart->param = param; + + uart->reg_shift = param->reg_shift; + uart->reg_width = param->reg_width; + uart->lsr_mask = param->lsr_mask; + uart->io_base += param->first_offset + + port_idx * param->uart_offset; +if ( param->base_baud ) + uart->clock_hz = param->base_baud *16 ; +if ( param->fifo_size ) + uart->fifo_size = param->fifo_size; + uart->ps_bdf[0 ] = b; uart->ps_bdf[1 ] = d; uart->ps_bdf[2 ] = f; uart->bar_idx = bar_idx; uart->bar = bar; uart->bar64 = bar_64; - uart->io_size = size; + uart->io_size =max (8U << param->reg_shift, + param->uart_offset); uart->irq =pci_conf_read8 (0 , b, d, f,PCI_INTERRUPT_PIN ) ?pci_conf_read8 (0 , b, d, f,PCI_INTERRUPT_LINE ) :0 ;
xen/include/xen/pci_ids.h +2 -0
@@ -2,6 +2,8 @@#define PCI_VENDOR_ID_NVIDIA 0x10de +#define PCI_VENDOR_ID_PERICOM 0x12d8 +#define PCI_VENDOR_ID_OXSEMI 0x1415#define PCI_VENDOR_ID_BROADCOM 0x14e4
ns16550: enable Pericom controller support
Other than the controllers supported so far, multiple port Pericom boards map all of their ports via BAR0, which requires a number of
adjustments: Instead of tracking "max_bars" we now flag whether all ports use BAR0, and whether to expect a port-I/O or MMIO resource. As a result pci_uart_config() now gets handed a port index, which it then maps into a BAR index or an offset into BAR0 depending on the bar0 flag.
---
v2: Fix coding style in a piece of code being moved. Add a comment
clarifying that on the 4- and 8-port variants we can't use all the ports for now. Retain previous behavior for PCI devices not explicitly listed, even if that behavior was undefined. (The rest of the series is unchanged, so I won't bother reposting the other patches.)
xen/drivers/char/ns16550.c +160 -84
353 lines not on this page · raw message
xen/include/xen/pci_ids.h +2 -0
@@ -2,6 +2,8 @@#define PCI_VENDOR_ID_NVIDIA 0x10de +#define PCI_VENDOR_ID_PERICOM 0x12d8 +#define PCI_VENDOR_ID_OXSEMI 0x1415#define PCI_VENDOR_ID_BROADCOM 0x14e4
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 2/4] ns16550: enable Pericom controller support
Quoted 10 lines · Jan Beulich
Other than the controllers supported so far, multiple port Pericom boards map all of their ports via BAR0, which requires a number of
adjustments: Instead of tracking "max_bars" we now flag whether all ports use BAR0, and whether to expect a port-I/O or MMIO resource. As a resultpci_uart_config()now gets handed a port index, which it then maps into a BAR index or an offset into BAR0 depending on the bar0 flag.Signed-off-by Jan Beulich <[email protected]>
Quoted 5 lines
---
v2: Fix coding style in a piece of code being moved. Add a comment
clarifying that on the 4- and 8-port variants we can't use all the ports for now. Retain previous behavior for PCI devices not explicitly listed, even if that behavior was undefined. (The rest
Thank you for making that work.
Quoted 2 lines
of the series is unchanged, so I won't bother reposting the other patches.)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH 3/4 console: adjust IRQ initialization
In reply to Jan BeulichIn order for a Xen internal PCI device driver to enable MSI on the device, we need another hook which the driver can use to create the IRQ (doing this in the init_preirq hook is too early, since IRQ code hasn't got initialized at that time yet, and doing it in init_postirq is too late because at least on x86 smp_intr_init() needs to know the IRQ number).
On x86 this additionally requires a slight ordering change to IRQ initialization, to facilitate calling the new hook between basic initialization and the call path leading to smp_intr_init().
xen/arch/x86/i8259.c +0 -2
@@ -342,8 +342,6 @@ void __init init_IRQ(void)init_8259A (0 ); -BUG_ON (init_irq_data () <0 ); -for (irq =0 ;platform_legacy_irq (irq); irq++) {struct irq_desc *desc =irq_to_desc (irq);
xen/arch/x86/setup.c +8 -1
@@ -576,6 +576,7 @@ void __init noreturn __start_xen(unsigneunsigned long nr_pages, raw_max_page, modules_headroom, *module_map;int i, j, e820_warn =0 , bytes =0 ;bool_t acpi_boot_table_init_done =0 ; +int ret;struct domain *dom0;struct ns16550_defaults ns16550 = { .data_bits =8 ,
@@ -1281,6 +1282,12 @@ void __init noreturn __start_xen(unsignex2apic_bsp_setup (); + ret =init_irq_data (); +if ( ret <0 ) +panic ("Error %d setting up IRQ data\n" , ret); + +console_init_irq (); +init_IRQ (); module_map = xmalloc_array(unsigned long, BITS_TO_LONGS(mbi->mods_count));
@@ -1366,7 +1373,7 @@ void __init noreturn __start_xen(unsigneif ( (num_online_cpus () < max_cpus) && !cpu_online (i) ) { -int ret =cpu_up (i); + ret =cpu_up (i);if ( ret !=0 )printk ("Failed to bring up CPU %u (error %d)\n" , i, ret); }
xen/drivers/char/console.c +5 -0
@@ -771,6 +771,11 @@ void __init console_init_ring(void)printk ("Allocated console ring of %u KiB.\n" , opt_conring_size >>10 ); } +void __init console_init_irq (void ) +{ +serial_init_irq (); +} +void __init console_init_postirq (void ) {serial_init_postirq ();
xen/drivers/char/serial.c +9 -0
@@ -504,6 +504,15 @@ void __init serial_init_preirq(void) com[i].driver->init_preirq (&com[i]); } +void __init serial_init_irq (void ) +{ +unsigned int i; + +for ( i =0 ; i <ARRAY_SIZE (com); i++ ) +if ( com[i].driver && com[i].driver->init_irq ) + com[i].driver->init_irq (&com[i]); +} +void __init serial_init_postirq (void ) {int i;
xen/include/xen/console.h +1 -0
@@ -15,6 +15,7 @@ int console_loglvl_op(struct xen_sysctl_void console_init_preirq (void );void console_init_ring (void ); +void console_init_irq (void );void console_init_postirq (void );void console_endboot (void );int console_has (const char *device);
xen/include/xen/serial.h +3 -1
@@ -64,6 +64,7 @@ struct serial_port {struct uart_driver {/* Driver initialisation (pre- and post-IRQ subsystem setup). */ void (*init_preirq)(struct serial_port *); +void (*init_irq)(struct serial_port *);void (*init_postirq)(struct serial_port *);/* Hook to clean up after Xen bootstrap (before domain 0 runs). */ void (*endboot)(struct serial_port *);
@@ -99,8 +100,9 @@ struct uart_driver {#define SERHND_LO (1<<3)/* Ditto, except that the MSB is cleared. */ #define SERHND_COOKED (1<<4)/* Newline/carriage-return translation? */ -/* Two-stage initialisation (before/after IRQ-subsystem initialisation). */ +/* Three-stage initialisation (before/during/after IRQ-subsystem setup). */ void serial_init_preirq (void ); +void serial_init_irq (void );void serial_init_postirq (void );/* Clean-up hook before domain 0 runs. */
console: adjust IRQ initialization
In order for a Xen internal PCI device driver to enable MSI on the device, we need another hook which the driver can use to create the IRQ (doing this in the init_preirq hook is too early, since IRQ code hasn't got initialized at that time yet, and doing it in init_postirq is too late because at least on x86 smp_intr_init() needs to know the IRQ number).
On x86 this additionally requires a slight ordering change to IRQ initialization, to facilitate calling the new hook between basic initialization and the call path leading to smp_intr_init().
xen/arch/x86/i8259.c +0 -2
@@ -342,8 +342,6 @@ void __init init_IRQ(void)init_8259A (0 ); -BUG_ON (init_irq_data () <0 ); -for (irq =0 ;platform_legacy_irq (irq); irq++) {struct irq_desc *desc =irq_to_desc (irq);
xen/arch/x86/setup.c +8 -1
@@ -576,6 +576,7 @@ void __init noreturn __start_xen(unsigneunsigned long nr_pages, raw_max_page, modules_headroom, *module_map;int i, j, e820_warn =0 , bytes =0 ;bool_t acpi_boot_table_init_done =0 ; +int ret;struct domain *dom0;struct ns16550_defaults ns16550 = { .data_bits =8 ,
@@ -1281,6 +1282,12 @@ void __init noreturn __start_xen(unsignex2apic_bsp_setup (); + ret =init_irq_data (); +if ( ret <0 ) +panic ("Error %d setting up IRQ data\n" , ret); + +console_init_irq (); +init_IRQ (); module_map = xmalloc_array(unsigned long, BITS_TO_LONGS(mbi->mods_count));
@@ -1366,7 +1373,7 @@ void __init noreturn __start_xen(unsigneif ( (num_online_cpus () < max_cpus) && !cpu_online (i) ) { -int ret =cpu_up (i); + ret =cpu_up (i);if ( ret !=0 )printk ("Failed to bring up CPU %u (error %d)\n" , i, ret); }
xen/drivers/char/console.c +5 -0
@@ -771,6 +771,11 @@ void __init console_init_ring(void)printk ("Allocated console ring of %u KiB.\n" , opt_conring_size >>10 ); } +void __init console_init_irq (void ) +{ +serial_init_irq (); +} +void __init console_init_postirq (void ) {serial_init_postirq ();
xen/drivers/char/serial.c +9 -0
@@ -504,6 +504,15 @@ void __init serial_init_preirq(void) com[i].driver->init_preirq (&com[i]); } +void __init serial_init_irq (void ) +{ +unsigned int i; + +for ( i =0 ; i <ARRAY_SIZE (com); i++ ) +if ( com[i].driver && com[i].driver->init_irq ) + com[i].driver->init_irq (&com[i]); +} +void __init serial_init_postirq (void ) {int i;
xen/include/xen/console.h +1 -0
@@ -15,6 +15,7 @@ int console_loglvl_op(struct xen_sysctl_void console_init_preirq (void );void console_init_ring (void ); +void console_init_irq (void );void console_init_postirq (void );void console_endboot (void );int console_has (const char *device);
xen/include/xen/serial.h +3 -1
@@ -64,6 +64,7 @@ struct serial_port {struct uart_driver {/* Driver initialisation (pre- and post-IRQ subsystem setup). */ void (*init_preirq)(struct serial_port *); +void (*init_irq)(struct serial_port *);void (*init_postirq)(struct serial_port *);/* Hook to clean up after Xen bootstrap (before domain 0 runs). */ void (*endboot)(struct serial_port *);
@@ -99,8 +100,9 @@ struct uart_driver {#define SERHND_LO (1<<3)/* Ditto, except that the MSB is cleared. */ #define SERHND_COOKED (1<<4)/* Newline/carriage-return translation? */ -/* Two-stage initialisation (before/after IRQ-subsystem initialisation). */ +/* Three-stage initialisation (before/during/after IRQ-subsystem setup). */ void serial_init_preirq (void ); +void serial_init_irq (void );void serial_init_postirq (void );/* Clean-up hook before domain 0 runs. */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 3/4] console: adjust IRQ initialization
Quoted 7 lines · Jan Beulich
In order for a Xen internal PCI device driver to enable MSI on the device, we need another hook which the driver can use to create the IRQ (doing this in the
init_preirqhook is too early, since IRQ code hasn't got initialized at that time yet, and doing it ininit_postirqis too late because at least on x86smp_intr_init()needs to know the IRQ number).
Quoted 5 lines
On x86 this additionally requires a slight ordering change to IRQ initialization, to facilitate calling the new hook between basic initialization and the call path leading to
smp_intr_init().Signed-off-by Jan Beulich <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
RFC PATCH 4/4 ns16550: enable use of PCI MSI
In reply to Jan BeulichWhich, on x86, requires fiddling with the INTx bit in PCI config space, since for internally used MSI we can't delegate this to Dom0.
ns16550_init_postirq() also needs (benign) re-ordering of its operations.
---
RFC reason: No interrupts occur for an unknown reason (presumably
broken hardware/firmware on the device I have).
xen/arch/x86/msi.c +12 -0
@@ -738,6 +738,16 @@ static int msi_capability_init(struct pc *desc = entry;/* Restore the original MSI enabled bits */ +if ( !hardware_domain ) + { +/* +* Except for internal requests (before Dom0 starts), in which case +* we rather need to behave "normally", i.e. not follow the split +* brain model where Dom0 actually enables MSI (and disables INTx). +*/ +pci_intx (dev,0 ); + control |=PCI_MSI_FLAGS_ENABLE ; + }pci_conf_write16 (seg, bus, slot, func,msi_control_reg (pos), control);return 0 ;
@@ -1071,6 +1081,8 @@ static void __pci_disable_msi(struct msi dev = entry->dev;msi_set_enable (dev,0 ); +if ( entry->irq >0 && !(irq_to_desc (entry->irq)->status &IRQ_GUEST ) ) +pci_intx (dev,1 );BUG_ON (list_empty (&dev->msi_list)); }
xen/drivers/char/ns16550.c +81 -12
131 lines not on this page · raw message
xen/drivers/pci/pci.c +15 -0
@@ -115,6 +115,21 @@ int pci_find_next_ext_capability(int segreturn 0 ; } +void pci_intx (const struct pci_dev *pdev,bool_t enable) +{ +uint16_t seg = pdev->seg; +uint8_t bus = pdev->bus; +uint8_t slot =PCI_SLOT (pdev->devfn); +uint8_t func =PCI_FUNC (pdev->devfn); +uint16_t cmd =pci_conf_read16 (seg, bus, slot, func,PCI_COMMAND ); + +if ( enable ) + cmd &= ~PCI_COMMAND_INTX_DISABLE ; +else + cmd |=PCI_COMMAND_INTX_DISABLE ; +pci_conf_write16 (seg, bus, slot, func,PCI_COMMAND , cmd); +} +const char *__init parse_pci (const char *s,unsigned int *seg_p,unsigned int *bus_p,unsigned int *dev_p,unsigned int *func_p)
xen/include/xen/pci.h +1 -0
@@ -152,6 +152,7 @@ int pci_find_next_ext_capability(int segconst char *parse_pci (const char *,unsigned int *seg,unsigned int *bus,unsigned int *dev,unsigned int *func); +void pci_intx (const struct pci_dev *,bool_t enable);bool_t pcie_aer_get_firmware_first (const struct pci_dev *);struct pirq ;
ns16550: enable use of PCI MSI
Which, on x86, requires fiddling with the INTx bit in PCI config space, since for internally used MSI we can't delegate this to Dom0.
ns16550_init_postirq() also needs (benign) re-ordering of its operations.
---
RFC reason: No interrupts occur for an unknown reason (presumably
broken hardware/firmware on the device I have).
xen/arch/x86/msi.c +12 -0
@@ -738,6 +738,16 @@ static int msi_capability_init(struct pc *desc = entry;/* Restore the original MSI enabled bits */ +if ( !hardware_domain ) + { +/* +* Except for internal requests (before Dom0 starts), in which case +* we rather need to behave "normally", i.e. not follow the split +* brain model where Dom0 actually enables MSI (and disables INTx). +*/ +pci_intx (dev,0 ); + control |=PCI_MSI_FLAGS_ENABLE ; + }pci_conf_write16 (seg, bus, slot, func,msi_control_reg (pos), control);return 0 ;
@@ -1071,6 +1081,8 @@ static void __pci_disable_msi(struct msi dev = entry->dev;msi_set_enable (dev,0 ); +if ( entry->irq >0 && !(irq_to_desc (entry->irq)->status &IRQ_GUEST ) ) +pci_intx (dev,1 );BUG_ON (list_empty (&dev->msi_list)); }
xen/drivers/char/ns16550.c +81 -12
131 lines not on this page · raw message
xen/drivers/pci/pci.c +15 -0
@@ -115,6 +115,21 @@ int pci_find_next_ext_capability(int segreturn 0 ; } +void pci_intx (const struct pci_dev *pdev,bool_t enable) +{ +uint16_t seg = pdev->seg; +uint8_t bus = pdev->bus; +uint8_t slot =PCI_SLOT (pdev->devfn); +uint8_t func =PCI_FUNC (pdev->devfn); +uint16_t cmd =pci_conf_read16 (seg, bus, slot, func,PCI_COMMAND ); + +if ( enable ) + cmd &= ~PCI_COMMAND_INTX_DISABLE ; +else + cmd |=PCI_COMMAND_INTX_DISABLE ; +pci_conf_write16 (seg, bus, slot, func,PCI_COMMAND , cmd); +} +const char *__init parse_pci (const char *s,unsigned int *seg_p,unsigned int *bus_p,unsigned int *dev_p,unsigned int *func_p)
xen/include/xen/pci.h +1 -0
@@ -152,6 +152,7 @@ int pci_find_next_ext_capability(int segconst char *parse_pci (const char *,unsigned int *seg,unsigned int *bus,unsigned int *dev,unsigned int *func); +void pci_intx (const struct pci_dev *,bool_t enable);bool_t pcie_aer_get_firmware_first (const struct pci_dev *);struct pirq ;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 18 lines · Jan Beulich
Patches 1 and 2 are meant to go in. Patch 3 is a prerequisite to patch 4 and may go in as well, but patch 4 is RFC because with the Pericom board I have MSI doesn't appear to function. Since it also does not work in baremetal Linux when doing the trivial adjustments needed in its driver, I suspect the feature doesn't work in general, which is supported by the observation that the device continues to assert INTx despite the MSI enable bit being set (causing unclaimed IRQs until that IRQ gets shut off). While I got some responses back from Pericom support, no actual statement of whether MSI is actually known to work on their boards was ever made by them. I _think_ patch 4 is correct (and hence could go in), but I have no way of proving this by testing.
1: ns16550: store pointer to config parameters for PCI 2: ns16550: enable Pericom controller support 3: console: adjust IRQ initialization
4: ns16550: enable use of PCI MSI
Quoted 4 lines
Signed-off-by Jan Beulich <[email protected]>(Konrad, I'd appreciate if you could double check that I didn't accidentally break the Oxford controller support.)
I tested it on my one-port serial card. Let me move the cables + card tomorrow around to use the two port card and see how it behaves.
CC-ing Boris
Boris, I think the two port serial card is tst005 or such - so it may get wonky.
Quoted 1 line
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 29.02.16 at 17:56, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Patches 1 and 2 are meant to go in. Patch 3 is a prerequisite to patch 4 and may go in as well, but patch 4 is RFC because with the Pericom board I have MSI doesn't appear to function. Since it also does not work in baremetal Linux when doing the trivial adjustments needed in its driver, I suspect the feature doesn't work in general, which is supported by the observation that the device continues to assert INTx despite the MSI enable bit being set (causing unclaimed IRQs until that IRQ gets shut off). While I got some responses back from Pericom support, no actual statement of whether MSI is actually known to work on their boards was ever made by them. I _think_ patch 4 is correct (and hence could go in), but I have no way of proving this by testing.
1: ns16550: store pointer to config parameters for PCI 2: ns16550: enable Pericom controller support 3: console: adjust IRQ initialization
4: ns16550: enable use of PCI MSI
Quoted 6 lines
Quoted 4 lines
Signed-off-by Jan Beulich <[email protected]>(Konrad, I'd appreciate if you could double check that I didn't accidentally break the Oxford controller support.)
Thanks!
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Ping: [PATCH 0/4] ns16550: enable support for Pericom controllers
In reply to Jan BeulichQuoted 21 lines
Quoted 1 line
Quoted 1 line · On 23.02.16 at 12:22, <[email protected]> wrote:
Patches 1 and 2 are meant to go in. Patch 3 is a prerequisite to patch 4 and may go in as well, but patch 4 is RFC because with the Pericom board I have MSI doesn't appear to function. Since it also does not work in baremetal Linux when doing the trivial adjustments needed in its driver, I suspect the feature doesn't work in general, which is supported by the observation that the device continues to assert INTx despite the MSI enable bit being set (causing unclaimed IRQs until that IRQ gets shut off). While I got some responses back from Pericom support, no actual statement of whether MSI is actually known to work on their boards was ever made by them. I _think_ patch 4 is correct (and hence could go in), but I have no way of proving this by testing.
1: ns16550: store pointer to config parameters for PCI 2: ns16550: enable Pericom controller support 3: console: adjust IRQ initialization
4: ns16550: enable use of PCI MSISigned-off-by Jan Beulich <[email protected]>
Quoted 8 lines
(Konrad, I'd appreciate if you could double check that I didn't accidentally break the Oxford controller support.)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel