Changes to UART ns8250

Zbigniew Bodek zbb at freebsd.org
Mon Oct 7 21:20:45 UTC 2013


Hello Ian.

Well you can't really perform wake event basing on busy interrupt because
we are busy waiting/sleeping i.a. to avoid that interrupt to occur. I tried
to use pause() that should switch to another task for the declared amount
of time and I got:
"panic: mi_switch: switch in a critical section"

Best regards
Zbigniew Bodek


2013/10/7 Ian Lepore <ian at freebsd.org>

> On Mon, 2013-10-07 at 14:56 -0600, Ian Lepore wrote:
> > On Mon, 2013-10-07 at 22:36 +0200, Zbigniew Bodek wrote:
> > > Hello Adrian,
> > >
> > > Thank you for your remarks.
> > > Please check my answers in-line.
> > >
> > > Best regards
> > > Zbigniew Bodek
> > >
> > >
> > > 2013/10/7 Adrian Chadd <adrian at freebsd.org>
> > >
> > > > Hi,
> > > >
> > > > You should add:
> > > >
> > > > * a loop counter, to break out after a while;
> > > >
> > > [ZBB] In general as long as UART is busy we cannot proceed but if the
> > > timeout occurs we could return an error. Do you agree?
> > >
> > > > * a DELAY(1) or something.
> > > >
> > > [ZBB] DELAY is also a busy wait after all. The reasonable solution
> might be
> > > to use ns8250_delay() to get the transmission time and use it for
> timeout
> > > from the first point. I would DELAY(1) in each loop and decrement value
> > > acquired from ns8250_delay(). The loop should break during that time
> or we
> > > return an error. What do you think?
> > >
> >
> > Is it possible to not busy-wait at all?  Something like the attached?
> >
> > -- Ian
> >
> > differences between files attachment (temp.diff)
> > Index: sys/dev/uart/uart_dev_ns8250.c
> > ===================================================================
> > --- sys/dev/uart/uart_dev_ns8250.c    (revision 255916)
> > +++ sys/dev/uart/uart_dev_ns8250.c    (working copy)
> > @@ -614,6 +614,7 @@ ns8250_bus_ipend(struct uart_softc *sc)
> >
> >       if (ns8250->busy_detect && (iir & IIR_BUSY) == IIR_BUSY) {
> >               (void)uart_getreg(bas, DW_REG_USR);
> > +             wakeup(&ns8250->busy_detect);
> >               uart_unlock(sc->sc_hwmtx);
> >               return (0);
> >       }
> > @@ -652,6 +653,16 @@ ns8250_bus_param(struct uart_softc *sc, int baudra
> >
> >       bas = &sc->sc_bas;
> >       uart_lock(sc->sc_hwmtx);
> > +       /*
> > +     * When using DW UART with BUSY detection it is necessary to wait
> > +     * until all serial transfers are finished before manipulating the
> > +     * line control. LCR will not be affected when UART is busy.
> > +     */
> > +     while (ns8250->busy_detect &&
> > +         (uart_getreg(bas, DW_REG_USR) & USR_BUSY) == 0) {
> > +             msleep(&ns8250->busy_detect, sc->sc_hwmtx, "dwbusy", 10);
> > +     }
> > +
> >       error = ns8250_param(bas, baudrate, databits, stopbits, parity);
> >       uart_unlock(sc->sc_hwmtx);
> >       return (error);
>
> Ooops, that should be != 0 in that USR_BUSY test.  Also, I haven't
> tested this at all because I don't I have any boards that use DW uarts.
>
> -- Ian
>
>
>


More information about the freebsd-current mailing list