The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/uart/uart_bus.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2003 Marcel Moolenaar
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  *
    9  * 1. Redistributions of source code must retain the above copyright
   10  *    notice, this list of conditions and the following disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  *
   15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   25  *
   26  * $FreeBSD$
   27  */
   28 
   29 #ifndef _DEV_UART_BUS_H_
   30 #define _DEV_UART_BUS_H_
   31 
   32 #ifndef KLD_MODULE
   33 #include "opt_uart.h"
   34 #endif
   35 
   36 #include <sys/serial.h>
   37 #include <sys/timepps.h>
   38 
   39 /* Drain and flush targets. */
   40 #define UART_DRAIN_RECEIVER     0x0001
   41 #define UART_DRAIN_TRANSMITTER  0x0002
   42 #define UART_FLUSH_RECEIVER     UART_DRAIN_RECEIVER
   43 #define UART_FLUSH_TRANSMITTER  UART_DRAIN_TRANSMITTER
   44 
   45 /*
   46  * Interrupt sources (in priority order). See also uart_core.c
   47  * Note that the low order 16 bits are used to pass modem signals
   48  * from the hardware interrupt handler to the software interrupt
   49  * handler.
   50  */
   51 #define UART_IPEND_OVERRUN      0x010000
   52 #define UART_IPEND_BREAK        0x020000
   53 #define UART_IPEND_RXREADY      0x040000
   54 #define UART_IPEND_SIGCHG       0x080000
   55 #define UART_IPEND_TXIDLE       0x100000
   56 
   57 #define UART_IPEND_MASK         0x1f0000
   58 #define UART_IPEND_SIGMASK      0x00ffff
   59 
   60 /* Received character status bits. */
   61 #define UART_STAT_BREAK         0x0100
   62 #define UART_STAT_FRAMERR       0x0200
   63 #define UART_STAT_OVERRUN       0x0400
   64 #define UART_STAT_PARERR        0x0800
   65 
   66 #define UART_SIGMASK_DTE        (SER_DTR | SER_RTS)
   67 #define UART_SIGMASK_DCE        (SER_DSR | SER_CTS | SER_DCD | SER_RI)
   68 #define UART_SIGMASK_STATE      (UART_SIGMASK_DTE | UART_SIGMASK_DCE)
   69 #define UART_SIGMASK_DELTA      (UART_SIGMASK_STATE << 8)
   70 
   71 #ifdef UART_PPS_ON_CTS
   72 #define UART_SIG_DPPS           SER_DCTS
   73 #define UART_SIG_PPS            SER_CTS
   74 #else
   75 #define UART_SIG_DPPS           SER_DDCD
   76 #define UART_SIG_PPS            SER_DCD
   77 #endif
   78 
   79 /* UART_IOCTL() requests */
   80 #define UART_IOCTL_BREAK        1
   81 #define UART_IOCTL_IFLOW        2
   82 #define UART_IOCTL_OFLOW        3
   83 #define UART_IOCTL_BAUD         4
   84 
   85 /*
   86  * UART class & instance (=softc)
   87  */
   88 struct uart_class {
   89         KOBJ_CLASS_FIELDS;
   90         u_int   uc_range;               /* Bus space address range. */
   91         u_int   uc_rclk;                /* Default rclk for this device. */
   92 };
   93 
   94 extern struct uart_class uart_ns8250_class;
   95 extern struct uart_class uart_sab82532_class;
   96 extern struct uart_class uart_z8530_class;
   97 
   98 struct uart_softc {
   99         KOBJ_FIELDS;
  100         struct uart_class *sc_class;
  101         struct uart_bas sc_bas;
  102         device_t        sc_dev;
  103 
  104         struct mtx      sc_hwmtx;       /* Spinlock protecting hardware. */
  105 
  106         struct resource *sc_rres;       /* Register resource. */
  107         int             sc_rrid;
  108         int             sc_rtype;       /* SYS_RES_{IOPORT|MEMORY}. */
  109         struct resource *sc_ires;       /* Interrupt resource. */
  110         void            *sc_icookie;
  111         int             sc_irid;
  112 
  113         int             sc_callout:1;   /* This UART is opened for callout. */
  114         int             sc_fastintr:1;  /* This UART uses fast interrupts. */
  115         int             sc_hasfifo:1;   /* This UART has FIFOs. */
  116         int             sc_hwiflow:1;   /* This UART has HW input flow ctl. */
  117         int             sc_hwoflow:1;   /* This UART has HW output flow ctl. */
  118         int             sc_leaving:1;   /* This UART is going away. */
  119         int             sc_opened:1;    /* This UART is open for business. */
  120         int             sc_polled:1;    /* This UART has no interrupts. */
  121         int             sc_txbusy:1;    /* This UART is transmitting. */
  122 
  123         struct uart_devinfo *sc_sysdev; /* System device (or NULL). */
  124 
  125         int             sc_altbrk;      /* State for alt break sequence. */
  126         uint32_t        sc_hwsig;       /* Signal state. Used by HW driver. */
  127 
  128         /* Receiver data. */
  129         uint16_t        *sc_rxbuf;
  130         int             sc_rxbufsz;
  131         int             sc_rxput;
  132         int             sc_rxget;
  133         int             sc_rxfifosz;    /* Size of RX FIFO. */
  134 
  135         /* Transmitter data. */
  136         uint8_t         *sc_txbuf;
  137         int             sc_txdatasz;
  138         int             sc_txfifosz;    /* Size of TX FIFO and buffer. */
  139 
  140         /* Pulse capturing support (PPS). */
  141         struct pps_state sc_pps;
  142 
  143         /* Upper layer data. */
  144         void            *sc_softih;
  145         uint32_t        sc_ttypend;
  146         union {
  147                 /* TTY specific data. */
  148                 struct {
  149                         struct cdev *si[2];     /* We have 2 device special files. */
  150                         struct tty *tp;
  151                 } u_tty;
  152                 /* Keyboard specific data. */
  153                 struct {
  154                 } u_kbd;
  155         } sc_u;
  156 };
  157 
  158 extern devclass_t uart_devclass;
  159 extern char uart_driver_name[];
  160 
  161 int uart_bus_attach(device_t dev);
  162 int uart_bus_detach(device_t dev);
  163 int uart_bus_probe(device_t dev, int regshft, int rclk, int rid, int chan);
  164 
  165 int uart_tty_attach(struct uart_softc *);
  166 int uart_tty_detach(struct uart_softc *);
  167 void uart_tty_intr(void *arg);
  168 
  169 /*
  170  * Receive buffer operations.
  171  */
  172 static __inline int
  173 uart_rx_empty(struct uart_softc *sc)
  174 {
  175         return ((sc->sc_rxget == sc->sc_rxput) ? 1 : 0);
  176 }
  177 
  178 static __inline int
  179 uart_rx_full(struct uart_softc *sc)
  180 {
  181         return ((sc->sc_rxput + 1 < sc->sc_rxbufsz)
  182             ? (sc->sc_rxput + 1 == sc->sc_rxget) : (sc->sc_rxget == 0));
  183 }
  184 
  185 static __inline int
  186 uart_rx_get(struct uart_softc *sc)
  187 {
  188         int ptr, xc;
  189 
  190         ptr = sc->sc_rxget;
  191         if (ptr == sc->sc_rxput)
  192                 return (-1);
  193         xc = sc->sc_rxbuf[ptr++];
  194         sc->sc_rxget = (ptr < sc->sc_rxbufsz) ? ptr : 0;
  195         return (xc);
  196 }
  197 
  198 static __inline int
  199 uart_rx_put(struct uart_softc *sc, int xc)
  200 {
  201         int ptr;
  202 
  203         ptr = (sc->sc_rxput + 1 < sc->sc_rxbufsz) ? sc->sc_rxput + 1 : 0;
  204         if (ptr == sc->sc_rxget)
  205                 return (ENOSPC);
  206         sc->sc_rxbuf[sc->sc_rxput] = xc;
  207         sc->sc_rxput = ptr;
  208         return (0);
  209 }
  210 
  211 #endif /* _DEV_UART_BUS_H_ */

Cache object: e29619d1b2d1ddbf40fe2920e308a04c


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.