1239676Srwatson/*- 2239676Srwatson * Copyright (c) 2011-2012 Robert N. M. Watson 3239676Srwatson * All rights reserved. 4239676Srwatson * 5239676Srwatson * This software was developed by SRI International and the University of 6239676Srwatson * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) 7239676Srwatson * ("CTSRD"), as part of the DARPA CRASH research programme. 8239676Srwatson * 9239676Srwatson * Redistribution and use in source and binary forms, with or without 10239676Srwatson * modification, are permitted provided that the following conditions 11239676Srwatson * are met: 12239676Srwatson * 1. Redistributions of source code must retain the above copyright 13239676Srwatson * notice, this list of conditions and the following disclaimer. 14239676Srwatson * 2. Redistributions in binary form must reproduce the above copyright 15239676Srwatson * notice, this list of conditions and the following disclaimer in the 16239676Srwatson * documentation and/or other materials provided with the distribution. 17239676Srwatson * 18239676Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19239676Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20239676Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21239676Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22239676Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23239676Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24239676Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25239676Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26239676Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27239676Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28239676Srwatson * SUCH DAMAGE. 29239676Srwatson * 30239676Srwatson * $FreeBSD: releng/10.2/sys/dev/altera/jtag_uart/altera_jtag_uart.h 250113 2013-04-30 18:29:05Z brooks $ 31239676Srwatson */ 32239676Srwatson 33239676Srwatson#ifndef _DEV_ALTERA_JTAG_UART_H_ 34239676Srwatson#define _DEV_ALTERA_JTAG_UART_H_ 35239676Srwatson 36239676Srwatsonstruct altera_jtag_uart_softc { 37239676Srwatson device_t ajus_dev; 38239676Srwatson int ajus_unit; 39239676Srwatson 40239676Srwatson /* 41239676Srwatson * Hardware resources. 42239676Srwatson */ 43239676Srwatson struct resource *ajus_irq_res; 44239676Srwatson int ajus_irq_rid; 45239676Srwatson void *ajus_irq_cookie; 46239676Srwatson struct resource *ajus_mem_res; 47239676Srwatson int ajus_mem_rid; 48239676Srwatson 49239676Srwatson /* 50239676Srwatson * TTY resources. 51239676Srwatson */ 52239676Srwatson struct tty *ajus_ttyp; 53239676Srwatson int ajus_alt_break_state; 54239676Srwatson 55239676Srwatson /* 56239676Srwatson * Driver resources. 57239676Srwatson */ 58239676Srwatson u_int ajus_flags; 59239676Srwatson struct mtx *ajus_lockp; 60239676Srwatson struct mtx ajus_lock; 61239676Srwatson struct callout ajus_io_callout; 62239676Srwatson struct callout ajus_ac_callout; 63239676Srwatson 64239676Srwatson /* 65239676Srwatson * One-character buffer required because it's not possible to peek at 66239676Srwatson * the input FIFO without reading it. 67239676Srwatson */ 68239676Srwatson int ajus_buffer_valid; 69239676Srwatson int *ajus_buffer_validp; 70239676Srwatson uint8_t ajus_buffer_data; 71239676Srwatson uint8_t *ajus_buffer_datap; 72239676Srwatson int ajus_jtag_present; 73239676Srwatson int *ajus_jtag_presentp; 74239676Srwatson u_int ajus_jtag_missed; 75239676Srwatson u_int *ajus_jtag_missedp; 76239676Srwatson}; 77239676Srwatson 78250113Sbrooks#define AJU_TTYNAME "ttyj" 79239676Srwatson 80239676Srwatson/* 81239676Srwatson * Flag values for ajus_flags. 82239676Srwatson */ 83239676Srwatson#define ALTERA_JTAG_UART_FLAG_CONSOLE 0x00000001 /* Is console. */ 84239676Srwatson 85239676Srwatson/* 86239676Srwatson * Because tty-level use of the I/O ports completes with low-level console 87239676Srwatson * use, spinlocks must be employed here. 88239676Srwatson */ 89239676Srwatson#define AJU_CONSOLE_LOCK_INIT() do { \ 90239676Srwatson mtx_init(&aju_cons_lock, "aju_cons_lock", NULL, MTX_SPIN); \ 91239676Srwatson} while (0) 92239676Srwatson 93239676Srwatson#define AJU_CONSOLE_LOCK() do { \ 94239676Srwatson if (!kdb_active) \ 95239676Srwatson mtx_lock_spin(&aju_cons_lock); \ 96239676Srwatson} while (0) 97239676Srwatson 98239676Srwatson#define AJU_CONSOLE_LOCK_ASSERT() { \ 99239676Srwatson if (!kdb_active) \ 100239676Srwatson mtx_assert(&aju_cons_lock, MA_OWNED); \ 101239676Srwatson} while (0) 102239676Srwatson 103239676Srwatson#define AJU_CONSOLE_UNLOCK() do { \ 104239676Srwatson if (!kdb_active) \ 105239676Srwatson mtx_unlock_spin(&aju_cons_lock); \ 106239676Srwatson} while (0) 107239676Srwatson 108239676Srwatson#define AJU_LOCK_INIT(sc) do { \ 109239676Srwatson mtx_init(&(sc)->ajus_lock, "aju_lock", NULL, MTX_SPIN); \ 110239676Srwatson} while (0) 111239676Srwatson 112239676Srwatson#define AJU_LOCK_DESTROY(sc) do { \ 113239676Srwatson mtx_destroy(&(sc)->ajus_lock); \ 114239676Srwatson} while (0) 115239676Srwatson 116239676Srwatson#define AJU_LOCK(sc) do { \ 117239676Srwatson mtx_lock_spin((sc)->ajus_lockp); \ 118239676Srwatson} while (0) 119239676Srwatson 120239676Srwatson#define AJU_LOCK_ASSERT(sc) do { \ 121239676Srwatson mtx_assert((sc)->ajus_lockp, MA_OWNED); \ 122239676Srwatson} while (0) 123239676Srwatson 124239676Srwatson#define AJU_UNLOCK(sc) do { \ 125239676Srwatson mtx_unlock_spin((sc)->ajus_lockp); \ 126239676Srwatson} while (0) 127239676Srwatson 128239676Srwatson/* 129239676Srwatson * When a TTY-level Altera JTAG UART instance is also the low-level console, 130239676Srwatson * the TTY layer borrows the console-layer lock and buffer rather than using 131239676Srwatson * its own. 132239676Srwatson */ 133239676Srwatsonextern struct mtx aju_cons_lock; 134239676Srwatsonextern char aju_cons_buffer_data; 135239676Srwatsonextern int aju_cons_buffer_valid; 136239676Srwatsonextern int aju_cons_jtag_present; 137239676Srwatsonextern u_int aju_cons_jtag_missed; 138239676Srwatson 139239676Srwatson/* 140239676Srwatson * Base physical address of the JTAG UART in BERI. 141239676Srwatson */ 142239676Srwatson#define BERI_UART_BASE 0x7f000000 /* JTAG UART */ 143239676Srwatson 144239676Srwatson/*- 145239676Srwatson * Routines for interacting with the BERI console JTAG UART. Programming 146239676Srwatson * details from the June 2011 "Embedded Peripherals User Guide" by Altera 147239676Srwatson * Corporation, tables 6-2 (JTAG UART Core Register Map), 6-3 (Data Register 148239676Srwatson * Bits), and 6-4 (Control Register Bits). 149239676Srwatson * 150239676Srwatson * Offsets of data and control registers relative to the base. Altera 151239676Srwatson * conventions are maintained in BERI. 152239676Srwatson */ 153239676Srwatson#define ALTERA_JTAG_UART_DATA_OFF 0x00000000 154239676Srwatson#define ALTERA_JTAG_UART_CONTROL_OFF 0x00000004 155239676Srwatson 156239676Srwatson/* 157239676Srwatson * Offset 0: 'data' register -- bits 31-16 (RAVAIL), 15 (RVALID), 158239676Srwatson * 14-8 (Reserved), 7-0 (DATA). 159239676Srwatson * 160239676Srwatson * DATA - One byte read or written. 161239676Srwatson * RAVAIL - Bytes available to read (excluding the current byte). 162239676Srwatson * RVALID - Whether the byte in DATA is valid. 163239676Srwatson */ 164239676Srwatson#define ALTERA_JTAG_UART_DATA_DATA 0x000000ff 165239676Srwatson#define ALTERA_JTAG_UART_DATA_RESERVED 0x00007f00 166239676Srwatson#define ALTERA_JTAG_UART_DATA_RVALID 0x00008000 167239676Srwatson#define ALTERA_JTAG_UART_DATA_RAVAIL 0xffff0000 168239676Srwatson#define ALTERA_JTAG_UART_DATA_RAVAIL_SHIFT 16 169239676Srwatson 170239676Srwatson/*- 171239676Srwatson * Offset 1: 'control' register -- bits 31-16 (WSPACE), 15-11 (Reserved), 172239676Srwatson * 10 (AC), 9 (WI), 8 (RI), 7..2 (Reserved), 1 (WE), 0 (RE). 173239676Srwatson * 174239676Srwatson * RE - Enable read interrupts. 175239676Srwatson * WE - Enable write interrupts. 176239676Srwatson * RI - Read interrupt pending. 177239676Srwatson * WI - Write interrupt pending. 178239676Srwatson * AC - Activity bit; set to '1' to clear to '0'. 179239676Srwatson * WSPACE - Space available in the write FIFO. 180239676Srwatson */ 181239676Srwatson#define ALTERA_JTAG_UART_CONTROL_RE 0x00000001 182239676Srwatson#define ALTERA_JTAG_UART_CONTROL_WE 0x00000002 183239676Srwatson#define ALTERA_JTAG_UART_CONTROL_RESERVED0 0x000000fc 184239676Srwatson#define ALTERA_JTAG_UART_CONTROL_RI 0x00000100 185239676Srwatson#define ALTERA_JTAG_UART_CONTROL_WI 0x00000200 186239676Srwatson#define ALTERA_JTAG_UART_CONTROL_AC 0x00000400 187239676Srwatson#define ALTERA_JTAG_UART_CONTROL_RESERVED1 0x0000f800 188239676Srwatson#define ALTERA_JTAG_UART_CONTROL_WSPACE 0xffff0000 189239676Srwatson#define ALTERA_JTAG_UART_CONTROL_WSPACE_SHIFT 16 190239676Srwatson 191239676Srwatson/* 192239676Srwatson * Driver attachment functions for Nexus. 193239676Srwatson */ 194239676Srwatsonint altera_jtag_uart_attach(struct altera_jtag_uart_softc *sc); 195239676Srwatsonvoid altera_jtag_uart_detach(struct altera_jtag_uart_softc *sc); 196239676Srwatson 197245380Srwatsonextern devclass_t altera_jtag_uart_devclass; 198245380Srwatson 199239676Srwatson#endif /* _DEV_ALTERA_JTAG_UART_H_ */ 200