1 /* $NetBSD: comvar.h,v 1.78 2013/10/03 13:23:03 kiyohara Exp $ */ 2 3 /* 4 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 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 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Christopher G. Demetriou 17 * for the NetBSD Project. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #include "rnd.h" 34 #include "opt_multiprocessor.h" 35 #include "opt_lockdebug.h" 36 #include "opt_com.h" 37 #include "opt_kgdb.h" 38 39 #ifdef RND_COM 40 #include <sys/rnd.h> 41 #endif 42 43 #include <sys/callout.h> 44 #include <sys/timepps.h> 45 #include <sys/mutex.h> 46 #include <sys/device.h> 47 48 #include <dev/ic/comreg.h> /* for COM_NPORTS */ 49 50 struct com_regs; 51 52 int comcnattach(bus_space_tag_t, bus_addr_t, int, int, int, tcflag_t); 53 int comcnattach1(struct com_regs *, int, int, int, tcflag_t); 54 55 #ifdef KGDB 56 int com_kgdb_attach(bus_space_tag_t, bus_addr_t, int, int, int, tcflag_t); 57 int com_kgdb_attach1(struct com_regs *, int, int, int, tcflag_t); 58 #endif 59 60 int com_is_console(bus_space_tag_t, bus_addr_t, bus_space_handle_t *); 61 62 /* Hardware flag masks */ 63 #define COM_HW_NOIEN 0x01 64 #define COM_HW_FIFO 0x02 65 /* 0x04 free for use */ 66 #define COM_HW_FLOW 0x08 67 #define COM_HW_DEV_OK 0x20 68 #define COM_HW_CONSOLE 0x40 69 #define COM_HW_KGDB 0x80 70 #define COM_HW_TXFIFO_DISABLE 0x100 71 #define COM_HW_NO_TXPRELOAD 0x200 72 #define COM_HW_AFE 0x400 73 74 /* Buffer size for character buffer */ 75 #ifndef COM_RING_SIZE 76 #define COM_RING_SIZE 2048 77 #endif 78 79 #ifdef COM_REGMAP 80 #define COM_REG_RXDATA 0 81 #define COM_REG_TXDATA 1 82 #define COM_REG_DLBL 2 83 #define COM_REG_DLBH 3 84 #define COM_REG_IER 4 85 #define COM_REG_IIR 5 86 #define COM_REG_FIFO 6 87 #define COM_REG_TCR 6 88 #define COM_REG_EFR 7 89 #define COM_REG_TLR 7 90 #define COM_REG_LCR 8 91 #define COM_REG_MDR1 8 92 #define COM_REG_MCR 9 93 #define COM_REG_LSR 10 94 #define COM_REG_MSR 11 95 #ifdef COM_16750 96 #define COM_REG_USR 31 97 #endif 98 99 struct com_regs { 100 bus_space_tag_t cr_iot; 101 bus_space_handle_t cr_ioh; 102 bus_addr_t cr_iobase; 103 bus_size_t cr_nports; 104 #ifdef COM_16750 105 bus_size_t cr_map[32]; 106 #else 107 bus_size_t cr_map[16]; 108 #endif 109 }; 110 111 #ifdef COM_16750 112 extern const bus_size_t com_std_map[32]; 113 #else 114 extern const bus_size_t com_std_map[16]; 115 #endif 116 117 #define COM_INIT_REGS(regs, tag, hdl, addr) \ 118 do { \ 119 regs.cr_iot = tag; \ 120 regs.cr_ioh = hdl; \ 121 regs.cr_iobase = addr; \ 122 regs.cr_nports = COM_NPORTS; \ 123 memcpy(regs.cr_map, com_std_map, sizeof (regs.cr_map)); \ 124 } while (0) 125 126 #else 127 #define COM_REG_RXDATA com_data 128 #define COM_REG_TXDATA com_data 129 #define COM_REG_DLBL com_dlbl 130 #define COM_REG_DLBH com_dlbh 131 #define COM_REG_IER com_ier 132 #define COM_REG_IIR com_iir 133 #define COM_REG_FIFO com_fifo 134 #define COM_REG_EFR com_efr 135 #define COM_REG_LCR com_lctl 136 #define COM_REG_MCR com_mcr 137 #define COM_REG_LSR com_lsr 138 #define COM_REG_MSR com_msr 139 #define COM_REG_TCR com_msr 140 #define COM_REG_TLR com_scratch 141 #define COM_REG_MDR1 8 142 #ifdef COM_16750 143 #define COM_REG_USR com_usr 144 #endif 145 146 struct com_regs { 147 bus_space_tag_t cr_iot; 148 bus_space_handle_t cr_ioh; 149 bus_addr_t cr_iobase; 150 bus_size_t cr_nports; 151 }; 152 153 #define COM_INIT_REGS(regs, tag, hdl, addr) \ 154 do { \ 155 regs.cr_iot = tag; \ 156 regs.cr_ioh = hdl; \ 157 regs.cr_iobase = addr; \ 158 regs.cr_nports = COM_NPORTS; \ 159 } while (0) 160 161 #endif 162 163 struct comcons_info { 164 struct com_regs regs; 165 int rate; 166 int frequency; 167 int type; 168 tcflag_t cflag; 169 }; 170 171 struct com_softc { 172 device_t sc_dev; 173 void *sc_si; 174 struct tty *sc_tty; 175 176 struct callout sc_diag_callout; 177 178 int sc_frequency; 179 180 struct com_regs sc_regs; 181 bus_space_handle_t sc_hayespioh; 182 183 184 u_int sc_overflows, 185 sc_floods, 186 sc_errors; 187 188 int sc_hwflags, 189 sc_swflags; 190 u_int sc_fifolen; 191 192 u_int sc_r_hiwat, 193 sc_r_lowat; 194 u_char *volatile sc_rbget, 195 *volatile sc_rbput; 196 volatile u_int sc_rbavail; 197 u_char *sc_rbuf, 198 *sc_ebuf; 199 200 u_char *sc_tba; 201 u_int sc_tbc, 202 sc_heldtbc; 203 204 volatile u_char sc_rx_flags, 205 #define RX_TTY_BLOCKED 0x01 206 #define RX_TTY_OVERFLOWED 0x02 207 #define RX_IBUF_BLOCKED 0x04 208 #define RX_IBUF_OVERFLOWED 0x08 209 #define RX_ANY_BLOCK 0x0f 210 sc_tx_busy, 211 sc_tx_done, 212 sc_tx_stopped, 213 sc_st_check, 214 sc_rx_ready; 215 216 volatile u_char sc_heldchange; 217 volatile u_char sc_msr, sc_msr_delta, sc_msr_mask, sc_mcr, 218 sc_mcr_active, sc_lcr, sc_ier, sc_fifo, sc_dlbl, sc_dlbh, sc_efr; 219 u_char sc_mcr_dtr, sc_mcr_rts, sc_msr_cts, sc_msr_dcd; 220 221 #ifdef COM_HAYESP 222 u_char sc_prescaler; 223 #endif 224 225 /* 226 * There are a great many almost-ns16550-compatible UARTs out 227 * there, which have minor differences. The type field here 228 * lets us distinguish between them. 229 */ 230 int sc_type; 231 #define COM_TYPE_NORMAL 0 /* normal 16x50 */ 232 #define COM_TYPE_HAYESP 1 /* Hayes ESP modem */ 233 #define COM_TYPE_PXA2x0 2 /* Intel PXA2x0 processor built-in */ 234 #define COM_TYPE_AU1x00 3 /* AMD/Alchemy Au1x000 proc. built-in */ 235 #define COM_TYPE_OMAP 4 /* TI OMAP processor built-in */ 236 #define COM_TYPE_16550_NOERS 5 /* like a 16550, no ERS */ 237 238 /* power management hooks */ 239 int (*enable)(struct com_softc *); 240 void (*disable)(struct com_softc *); 241 int enabled; 242 243 /* XXXX: vendor workaround functions */ 244 int (*sc_vendor_workaround)(struct com_softc *); 245 246 struct pps_state sc_pps_state; /* pps state */ 247 248 #ifdef RND_COM 249 krndsource_t rnd_source; 250 #endif 251 kmutex_t sc_lock; 252 }; 253 254 int comprobe1(bus_space_tag_t, bus_space_handle_t); 255 int comintr(void *); 256 void com_attach_subr(struct com_softc *); 257 int com_probe_subr(struct com_regs *); 258 int com_detach(device_t, int); 259 bool com_resume(device_t, const pmf_qual_t *); 260 bool com_cleanup(device_t, int); 261 bool com_suspend(device_t, const pmf_qual_t *); 262 263 #ifndef IPL_SERIAL 264 #define IPL_SERIAL IPL_TTY 265 #define splserial() spltty() 266 #endif 267