uart_cpu.h (f8100ce2a70db5c60672578fee913d986ac1cf01) | uart_cpu.h (27d5dc189c8e2eaf1cbe7e47078bf065854ba210) |
---|---|
1/*- 2 * Copyright (c) 2003, 2004 Marcel Moolenaar | 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. --- 13 unchanged lines hidden (view full) --- 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * 26 * $FreeBSD$ 27 */ 28 29#ifndef _DEV_UART_CPU_H_ 30#define _DEV_UART_CPU_H_ 31 | 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. --- 13 unchanged lines hidden (view full) --- 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * 26 * $FreeBSD$ 27 */ 28 29#ifndef _DEV_UART_CPU_H_ 30#define _DEV_UART_CPU_H_ 31 |
32#include <sys/kdb.h> 33#include <sys/lock.h> 34#include <sys/mutex.h> 35 | |
36/* 37 * Low-level operations for use by console and/or debug port support. 38 */ 39struct uart_ops { 40 int (*probe)(struct uart_bas *); 41 void (*init)(struct uart_bas *, int, int, int, int); 42 void (*term)(struct uart_bas *); 43 void (*putc)(struct uart_bas *, int); | 32/* 33 * Low-level operations for use by console and/or debug port support. 34 */ 35struct uart_ops { 36 int (*probe)(struct uart_bas *); 37 void (*init)(struct uart_bas *, int, int, int, int); 38 void (*term)(struct uart_bas *); 39 void (*putc)(struct uart_bas *, int); |
44 int (*rxready)(struct uart_bas *); 45 int (*getc)(struct uart_bas *, struct mtx *); | 40 int (*poll)(struct uart_bas *); 41 int (*getc)(struct uart_bas *); |
46}; 47 | 42}; 43 |
48extern bus_space_tag_t uart_bus_space_io; 49extern bus_space_tag_t uart_bus_space_mem; | 44extern struct uart_ops uart_ns8250_ops; 45extern struct uart_ops uart_sab82532_ops; 46extern struct uart_ops uart_z8530_ops; |
50 51/* 52 * Console and debug port device info. 53 */ 54struct uart_softc; 55struct uart_devinfo { 56 SLIST_ENTRY(uart_devinfo) next; | 47 48/* 49 * Console and debug port device info. 50 */ 51struct uart_softc; 52struct uart_devinfo { 53 SLIST_ENTRY(uart_devinfo) next; |
57 struct uart_ops *ops; | 54 struct uart_ops ops; |
58 struct uart_bas bas; 59 int baudrate; 60 int databits; 61 int stopbits; 62 int parity; 63 int type; 64#define UART_DEV_CONSOLE 0 65#define UART_DEV_DBGPORT 1 66#define UART_DEV_KEYBOARD 2 67 int (*attach)(struct uart_softc*); 68 int (*detach)(struct uart_softc*); 69 void *cookie; /* Type dependent use. */ | 55 struct uart_bas bas; 56 int baudrate; 57 int databits; 58 int stopbits; 59 int parity; 60 int type; 61#define UART_DEV_CONSOLE 0 62#define UART_DEV_DBGPORT 1 63#define UART_DEV_KEYBOARD 2 64 int (*attach)(struct uart_softc*); 65 int (*detach)(struct uart_softc*); 66 void *cookie; /* Type dependent use. */ |
70 struct mtx *hwmtx; | |
71}; 72 | 67}; 68 |
73int uart_cpu_eqres(struct uart_bas *, struct uart_bas *); 74int uart_cpu_getdev(int, struct uart_devinfo *); | 69int uart_cpu_getdev(int devtype, struct uart_devinfo *di); 70int uart_cpu_eqres(struct uart_bas *b1, struct uart_bas *b2); |
75 | 71 |
76int uart_getenv(int, struct uart_devinfo *, struct uart_class *); 77const char *uart_getname(struct uart_class *); 78struct uart_ops *uart_getops(struct uart_class *); 79int uart_getrange(struct uart_class *); | 72void uart_add_sysdev(struct uart_devinfo*); |
80 | 73 |
81void uart_add_sysdev(struct uart_devinfo *); 82 | |
83/* 84 * Operations for low-level access to the UART. Primarily for use 85 * by console and debug port logic. 86 */ | 74/* 75 * Operations for low-level access to the UART. Primarily for use 76 * by console and debug port logic. 77 */ |
87 88static __inline void 89uart_lock(struct mtx *hwmtx) 90{ 91 if (!kdb_active && hwmtx != NULL) 92 mtx_lock_spin(hwmtx); 93} 94 95static __inline void 96uart_unlock(struct mtx *hwmtx) 97{ 98 if (!kdb_active && hwmtx != NULL) 99 mtx_unlock_spin(hwmtx); 100} 101 | |
102static __inline int 103uart_probe(struct uart_devinfo *di) 104{ | 78static __inline int 79uart_probe(struct uart_devinfo *di) 80{ |
105 int res; 106 107 uart_lock(di->hwmtx); 108 res = di->ops->probe(&di->bas); 109 uart_unlock(di->hwmtx); 110 return (res); | 81 return (di->ops.probe(&di->bas)); |
111} 112 113static __inline void 114uart_init(struct uart_devinfo *di) 115{ | 82} 83 84static __inline void 85uart_init(struct uart_devinfo *di) 86{ |
116 uart_lock(di->hwmtx); 117 di->ops->init(&di->bas, di->baudrate, di->databits, di->stopbits, | 87 di->ops.init(&di->bas, di->baudrate, di->databits, di->stopbits, |
118 di->parity); | 88 di->parity); |
119 uart_unlock(di->hwmtx); | |
120} 121 122static __inline void 123uart_term(struct uart_devinfo *di) 124{ | 89} 90 91static __inline void 92uart_term(struct uart_devinfo *di) 93{ |
125 uart_lock(di->hwmtx); 126 di->ops->term(&di->bas); 127 uart_unlock(di->hwmtx); | 94 di->ops.term(&di->bas); |
128} 129 130static __inline void 131uart_putc(struct uart_devinfo *di, int c) 132{ | 95} 96 97static __inline void 98uart_putc(struct uart_devinfo *di, int c) 99{ |
133 uart_lock(di->hwmtx); 134 di->ops->putc(&di->bas, c); 135 uart_unlock(di->hwmtx); | 100 di->ops.putc(&di->bas, c); |
136} 137 138static __inline int | 101} 102 103static __inline int |
139uart_rxready(struct uart_devinfo *di) 140{ 141 int res; 142 143 uart_lock(di->hwmtx); 144 res = di->ops->rxready(&di->bas); 145 uart_unlock(di->hwmtx); 146 return (res); 147} 148 149static __inline int | |
150uart_poll(struct uart_devinfo *di) 151{ | 104uart_poll(struct uart_devinfo *di) 105{ |
152 int res; 153 154 uart_lock(di->hwmtx); 155 if (di->ops->rxready(&di->bas)) 156 res = di->ops->getc(&di->bas, NULL); 157 else 158 res = -1; 159 uart_unlock(di->hwmtx); 160 return (res); | 106 return (di->ops.poll(&di->bas)); |
161} 162 163static __inline int 164uart_getc(struct uart_devinfo *di) 165{ | 107} 108 109static __inline int 110uart_getc(struct uart_devinfo *di) 111{ |
166 167 return (di->ops->getc(&di->bas, di->hwmtx)); | 112 return (di->ops.getc(&di->bas)); |
168} 169 170#endif /* _DEV_UART_CPU_H_ */ | 113} 114 115#endif /* _DEV_UART_CPU_H_ */ |