aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/serial/8250.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/serial/8250.c')
-rw-r--r--drivers/serial/8250.c69
1 files changed, 56 insertions, 13 deletions
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index 1528de23a65..303272af386 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -156,11 +156,15 @@ struct uart_8250_port {
156}; 156};
157 157
158struct irq_info { 158struct irq_info {
159 spinlock_t lock; 159 struct hlist_node node;
160 int irq;
161 spinlock_t lock; /* Protects list not the hash */
160 struct list_head *head; 162 struct list_head *head;
161}; 163};
162 164
163static struct irq_info irq_lists[NR_IRQS]; 165#define NR_IRQ_HASH 32 /* Can be adjusted later */
166static struct hlist_head irq_lists[NR_IRQ_HASH];
167static DEFINE_MUTEX(hash_mutex); /* Used to walk the hash */
164 168
165/* 169/*
166 * Here we define the default xmit fifo size used for each type of UART. 170 * Here we define the default xmit fifo size used for each type of UART.
@@ -1545,15 +1549,43 @@ static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up)
1545 BUG_ON(i->head != &up->list); 1549 BUG_ON(i->head != &up->list);
1546 i->head = NULL; 1550 i->head = NULL;
1547 } 1551 }
1548
1549 spin_unlock_irq(&i->lock); 1552 spin_unlock_irq(&i->lock);
1553 /* List empty so throw away the hash node */
1554 if (i->head == NULL) {
1555 hlist_del(&i->node);
1556 kfree(i);
1557 }
1550} 1558}
1551 1559
1552static int serial_link_irq_chain(struct uart_8250_port *up) 1560static int serial_link_irq_chain(struct uart_8250_port *up)
1553{ 1561{
1554 struct irq_info *i = irq_lists + up->port.irq; 1562 struct hlist_head *h;
1563 struct hlist_node *n;
1564 struct irq_info *i;
1555 int ret, irq_flags = up->port.flags & UPF_SHARE_IRQ ? IRQF_SHARED : 0; 1565 int ret, irq_flags = up->port.flags & UPF_SHARE_IRQ ? IRQF_SHARED : 0;
1556 1566
1567 mutex_lock(&hash_mutex);
1568
1569 h = &irq_lists[up->port.irq % NR_IRQ_HASH];
1570
1571 hlist_for_each(n, h) {
1572 i = hlist_entry(n, struct irq_info, node);
1573 if (i->irq == up->port.irq)
1574 break;
1575 }
1576
1577 if (n == NULL) {
1578 i = kzalloc(sizeof(struct irq_info), GFP_KERNEL);
1579 if (i == NULL) {
1580 mutex_unlock(&hash_mutex);
1581 return -ENOMEM;
1582 }
1583 spin_lock_init(&i->lock);
1584 i->irq = up->port.irq;
1585 hlist_add_head(&i->node, h);
1586 }
1587 mutex_unlock(&hash_mutex);
1588
1557 spin_lock_irq(&i->lock); 1589 spin_lock_irq(&i->lock);
1558 1590
1559 if (i->head) { 1591 if (i->head) {
@@ -1577,14 +1609,28 @@ static int serial_link_irq_chain(struct uart_8250_port *up)
1577 1609
1578static void serial_unlink_irq_chain(struct uart_8250_port *up) 1610static void serial_unlink_irq_chain(struct uart_8250_port *up)
1579{ 1611{
1580 struct irq_info *i = irq_lists + up->port.irq; 1612 struct irq_info *i;
1613 struct hlist_node *n;
1614 struct hlist_head *h;
1581 1615
1616 mutex_lock(&hash_mutex);
1617
1618 h = &irq_lists[up->port.irq % NR_IRQ_HASH];
1619
1620 hlist_for_each(n, h) {
1621 i = hlist_entry(n, struct irq_info, node);
1622 if (i->irq == up->port.irq)
1623 break;
1624 }
1625
1626 BUG_ON(n == NULL);
1582 BUG_ON(i->head == NULL); 1627 BUG_ON(i->head == NULL);
1583 1628
1584 if (list_empty(i->head)) 1629 if (list_empty(i->head))
1585 free_irq(up->port.irq, i); 1630 free_irq(up->port.irq, i);
1586 1631
1587 serial_do_unlink(i, up); 1632 serial_do_unlink(i, up);
1633 mutex_unlock(&hash_mutex);
1588} 1634}
1589 1635
1590/* Base timer interval for polling */ 1636/* Base timer interval for polling */
@@ -2447,7 +2493,7 @@ static void serial8250_config_port(struct uart_port *port, int flags)
2447static int 2493static int
2448serial8250_verify_port(struct uart_port *port, struct serial_struct *ser) 2494serial8250_verify_port(struct uart_port *port, struct serial_struct *ser)
2449{ 2495{
2450 if (ser->irq >= NR_IRQS || ser->irq < 0 || 2496 if (ser->irq >= nr_irqs || ser->irq < 0 ||
2451 ser->baud_base < 9600 || ser->type < PORT_UNKNOWN || 2497 ser->baud_base < 9600 || ser->type < PORT_UNKNOWN ||
2452 ser->type >= ARRAY_SIZE(uart_config) || ser->type == PORT_CIRRUS || 2498 ser->type >= ARRAY_SIZE(uart_config) || ser->type == PORT_CIRRUS ||
2453 ser->type == PORT_STARTECH) 2499 ser->type == PORT_STARTECH)
@@ -2967,7 +3013,7 @@ EXPORT_SYMBOL(serial8250_unregister_port);
2967 3013
2968static int __init serial8250_init(void) 3014static int __init serial8250_init(void)
2969{ 3015{
2970 int ret, i; 3016 int ret;
2971 3017
2972 if (nr_uarts > UART_NR) 3018 if (nr_uarts > UART_NR)
2973 nr_uarts = UART_NR; 3019 nr_uarts = UART_NR;
@@ -2976,9 +3022,6 @@ static int __init serial8250_init(void)
2976 "%d ports, IRQ sharing %sabled\n", nr_uarts, 3022 "%d ports, IRQ sharing %sabled\n", nr_uarts,
2977 share_irqs ? "en" : "dis"); 3023 share_irqs ? "en" : "dis");
2978 3024
2979 for (i = 0; i < NR_IRQS; i++)
2980 spin_lock_init(&irq_lists[i].lock);
2981
2982#ifdef CONFIG_SPARC 3025#ifdef CONFIG_SPARC
2983 ret = sunserial_register_minors(&serial8250_reg, UART_NR); 3026 ret = sunserial_register_minors(&serial8250_reg, UART_NR);
2984#else 3027#else
@@ -3006,15 +3049,15 @@ static int __init serial8250_init(void)
3006 goto out; 3049 goto out;
3007 3050
3008 platform_device_del(serial8250_isa_devs); 3051 platform_device_del(serial8250_isa_devs);
3009 put_dev: 3052put_dev:
3010 platform_device_put(serial8250_isa_devs); 3053 platform_device_put(serial8250_isa_devs);
3011 unreg_uart_drv: 3054unreg_uart_drv:
3012#ifdef CONFIG_SPARC 3055#ifdef CONFIG_SPARC
3013 sunserial_unregister_minors(&serial8250_reg, UART_NR); 3056 sunserial_unregister_minors(&serial8250_reg, UART_NR);
3014#else 3057#else
3015 uart_unregister_driver(&serial8250_reg); 3058 uart_unregister_driver(&serial8250_reg);
3016#endif 3059#endif
3017 out: 3060out:
3018 return ret; 3061 return ret;
3019} 3062}
3020 3063