xref: /freebsd/usr.sbin/bhyve/uart_emul.h (revision f3003a0dfb91ce887587ff73ce758f31a921e5a3)
1ea7f1c8cSNeel Natu /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
31de7b4b8SPedro F. Giffuni  *
4ea7f1c8cSNeel Natu  * Copyright (c) 2013 Neel Natu <neel@freebsd.org>
5ea7f1c8cSNeel Natu  * All rights reserved.
6ea7f1c8cSNeel Natu  *
7ea7f1c8cSNeel Natu  * Redistribution and use in source and binary forms, with or without
8ea7f1c8cSNeel Natu  * modification, are permitted provided that the following conditions
9ea7f1c8cSNeel Natu  * are met:
10ea7f1c8cSNeel Natu  * 1. Redistributions of source code must retain the above copyright
11ea7f1c8cSNeel Natu  *    notice, this list of conditions and the following disclaimer.
12ea7f1c8cSNeel Natu  * 2. Redistributions in binary form must reproduce the above copyright
13ea7f1c8cSNeel Natu  *    notice, this list of conditions and the following disclaimer in the
14ea7f1c8cSNeel Natu  *    documentation and/or other materials provided with the distribution.
15ea7f1c8cSNeel Natu  *
16ea7f1c8cSNeel Natu  * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
17ea7f1c8cSNeel Natu  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18ea7f1c8cSNeel Natu  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19ea7f1c8cSNeel Natu  * ARE DISCLAIMED.  IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
20ea7f1c8cSNeel Natu  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21ea7f1c8cSNeel Natu  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22ea7f1c8cSNeel Natu  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23ea7f1c8cSNeel Natu  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24ea7f1c8cSNeel Natu  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25ea7f1c8cSNeel Natu  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26ea7f1c8cSNeel Natu  * SUCH DAMAGE.
27ea7f1c8cSNeel Natu  */
28ea7f1c8cSNeel Natu 
29ea7f1c8cSNeel Natu #ifndef _UART_EMUL_H_
30ea7f1c8cSNeel Natu #define	_UART_EMUL_H_
31ea7f1c8cSNeel Natu 
32d1c5d0cfSMark Johnston #define	UART_NS16550_IO_BAR_SIZE	8
33ea7f1c8cSNeel Natu 
34d1c5d0cfSMark Johnston struct uart_ns16550_softc;
35*f3003a0dSAndrew Turner struct uart_pl011_softc;
36483d953aSJohn Baldwin struct vm_snapshot_meta;
37ea7f1c8cSNeel Natu 
38ea7f1c8cSNeel Natu typedef void (*uart_intr_func_t)(void *arg);
39ea7f1c8cSNeel Natu 
40ea7f1c8cSNeel Natu int	uart_legacy_alloc(int unit, int *ioaddr, int *irq);
41d1c5d0cfSMark Johnston 
42d1c5d0cfSMark Johnston struct uart_ns16550_softc *uart_ns16550_init(uart_intr_func_t intr_assert,
43d1c5d0cfSMark Johnston 	    uart_intr_func_t intr_deassert, void *arg);
44d1c5d0cfSMark Johnston uint8_t	uart_ns16550_read(struct uart_ns16550_softc *sc, int offset);
45d1c5d0cfSMark Johnston void	uart_ns16550_write(struct uart_ns16550_softc *sc, int offset,
46d1c5d0cfSMark Johnston 	    uint8_t value);
47d1c5d0cfSMark Johnston int	uart_ns16550_tty_open(struct uart_ns16550_softc *sc,
48d1c5d0cfSMark Johnston 	    const char *device);
49483d953aSJohn Baldwin #ifdef BHYVE_SNAPSHOT
50d1c5d0cfSMark Johnston int	uart_ns16550_snapshot(struct uart_ns16550_softc *sc,
51d1c5d0cfSMark Johnston 	    struct vm_snapshot_meta *meta);
52483d953aSJohn Baldwin #endif
53*f3003a0dSAndrew Turner 
54*f3003a0dSAndrew Turner uint32_t uart_pl011_read(struct uart_pl011_softc *sc, int offset);
55*f3003a0dSAndrew Turner void	uart_pl011_write(struct uart_pl011_softc *sc, int offset,
56*f3003a0dSAndrew Turner 	    uint32_t value);
57*f3003a0dSAndrew Turner struct uart_pl011_softc *uart_pl011_init(uart_intr_func_t intr_assert,
58*f3003a0dSAndrew Turner 	    uart_intr_func_t intr_deassert, void *arg);
59*f3003a0dSAndrew Turner int	uart_pl011_tty_open(struct uart_pl011_softc *sc, const char *device);
60*f3003a0dSAndrew Turner 
61*f3003a0dSAndrew Turner #endif /* _UART_EMUL_H_ */
62