lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1273142684.3477.22.camel@gentoo-ija64.mev.local>
Date:	Thu, 6 May 2010 11:44:44 +0100
From:	Ian Abbott <abbotti@....co.uk>
To:	"nios2-dev@...c.et.ntust.edu.tw" <nios2-dev@...c.et.ntust.edu.tw>
CC:	"linux-serial@...r.kernel.org" <linux-serial@...r.kernel.org>,
	"gregkh@...e.de" <gregkh@...e.de>,
	"akpm@...ux-foundation.org" <akpm@...ux-foundation.org>,
	"sfr@...b.auug.org.au" <sfr@...b.auug.org.au>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
	"alan@...rguk.ukuu.org.uk" <alan@...rguk.ukuu.org.uk>
Subject: Re: [Nios2-dev] [PATCH 2/2] serial: Add driver for the Altera UART

On Wed, 2010-05-05 at 09:35 +0100, Tobias Klauser wrote:
> Add an UART driver for the UART component available as a SOPC (System on
> Programmable Chip) component for Altera FPGAs.
[...]

> +static void altera_uart_start_tx(struct uart_port *port)
> +{
> +       struct altera_uart *pp = container_of(port, struct altera_uart, port);
> +       unsigned long flags;
> +
> +       spin_lock_irqsave(&port->lock, flags);
> +       pp->imr |= ALTERA_UART_CONTROL_TRDY_MSK;
> +       writel(pp->imr, port->membase + ALTERA_UART_CONTROL_REG);
> +       spin_unlock_irqrestore(&port->lock, flags);
> +}
> +
> +static void altera_uart_stop_tx(struct uart_port *port)
> +{
> +       struct altera_uart *pp = container_of(port, struct altera_uart, port);
> +       unsigned long flags;
> +
> +       spin_lock_irqsave(&port->lock, flags);
> +       pp->imr &= ~ALTERA_UART_CONTROL_TRDY_MSK;
> +       writel(pp->imr, port->membase + ALTERA_UART_CONTROL_REG);
> +       spin_unlock_irqrestore(&port->lock, flags);
> +}
> +
> +static void altera_uart_stop_rx(struct uart_port *port)
> +{
> +       struct altera_uart *pp = container_of(port, struct altera_uart, port);
> +       unsigned long flags;
> +
> +       spin_lock_irqsave(&port->lock, flags);
> +       pp->imr &= ~ALTERA_UART_CONTROL_RRDY_MSK;
> +       writel(pp->imr, port->membase + ALTERA_UART_CONTROL_REG);
> +       spin_unlock_irqrestore(&port->lock, flags);
> +}

Those four functions shouldn't grab port->lock because the caller in
serial_core.c grabs it before calling them.

> +static irqreturn_t altera_uart_interrupt(int irq, void *data)
> +{
> +       struct uart_port *port = data;
> +       struct altera_uart *pp = container_of(port, struct altera_uart, port);
> +       unsigned int isr;
> +
> +       isr = readl(port->membase + ALTERA_UART_STATUS_REG) & pp->imr;
> +       if (isr & ALTERA_UART_STATUS_RRDY_MSK)
> +               altera_uart_rx_chars(pp);
> +       if (isr & ALTERA_UART_STATUS_TRDY_MSK)
> +               altera_uart_tx_chars(pp);
> +       return IRQ_RETVAL(isr);
> +}

Either the interrupt routine should grab port->lock (see equivalent
function in altera_jtaguart.c for an example), or this could be done
lower down in altera_uart_rx_chars() and altera_uart_tx_chars(). (It's
less messing about to do it here in the interrupt routine though.)

> +static void altera_uart_console_putc(struct console *co, const char c)
> +{
> +       struct uart_port *port = &(altera_uart_ports + co->index)->port;
> +       int i;
> +
> +       for (i = 0; i < 0x10000; i++) {
> +               if (readl(port->membase + ALTERA_UART_STATUS_REG) &
> +                   ALTERA_UART_STATUS_TRDY_MSK)
> +                       break;
> +       }
> +       writel(c, port->membase + ALTERA_UART_TXDATA_REG);
> +       for (i = 0; i < 0x10000; i++) {
> +               if (readl(port->membase + ALTERA_UART_STATUS_REG) &
> +                   ALTERA_UART_STATUS_TRDY_MSK)
> +                       break;
> +       }
> +}

I'd suggest calling udelay(1) in each iteration of the loop.  Perhaps
the second loop is overkill.

I was also going to suggest using the port->lock spin lock, but I'm not
sure about the policy regarding that for console output (the 8250 driver
console output doesn't use the spin lock for example).

-- 
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@....co.uk>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ