Carl van Schaik | 438aa18 | 2018-07-06 22:22:42 +1000 | [diff] [blame] | 1 | /* |
| 2 | * drivers/char/vs_serial_common.h |
| 3 | * |
| 4 | * Copyright (c) 2012-2018 General Dynamics |
| 5 | * Copyright (c) 2014 Open Kernel Labs, Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #ifndef _VS_SERIAL_COMMON_H |
| 14 | #define _VS_SERIAL_COMMON_H |
| 15 | |
| 16 | #include <linux/version.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/tty.h> |
| 19 | #include <linux/tty_driver.h> |
| 20 | #include <linux/mutex.h> |
| 21 | #include <linux/completion.h> |
| 22 | #include <linux/console.h> |
| 23 | |
| 24 | #include <vservices/protocol/serial/common.h> |
| 25 | #include <vservices/protocol/serial/types.h> |
| 26 | #include <vservices/protocol/serial/server.h> |
| 27 | #include <vservices/protocol/serial/client.h> |
| 28 | |
| 29 | #define OUTBUFFER_SIZE 1024 |
| 30 | #define vtty_list_last_entry(ptr, type, member) \ |
| 31 | list_entry((ptr)->prev, type, member) |
| 32 | |
| 33 | struct vtty_port; |
| 34 | struct vs_service_device; |
| 35 | |
| 36 | struct vtty_port_ops { |
| 37 | struct vs_mbuf *(*alloc_msg_buf)(struct vtty_port *port, |
| 38 | struct vs_pbuf *pbuf, gfp_t gfp_flags); |
| 39 | void (*free_msg_buf)(struct vtty_port *port, |
| 40 | struct vs_mbuf *mbuf, struct vs_pbuf *pbuf); |
| 41 | int (*send_msg_buf)(struct vtty_port *port, |
| 42 | struct vs_mbuf *mbuf, struct vs_pbuf *pbuf); |
| 43 | bool (*is_running)(struct vtty_port *port); |
| 44 | }; |
| 45 | |
| 46 | struct vtty_port { |
| 47 | union { |
| 48 | struct vs_client_serial_state vs_client; |
| 49 | struct vs_server_serial_state vs_server; |
| 50 | } u; |
| 51 | |
| 52 | struct vs_service_device *service; |
| 53 | int port_num; |
| 54 | |
| 55 | struct tty_driver *vtty_driver; |
| 56 | |
| 57 | struct vtty_port_ops ops; |
| 58 | |
| 59 | /* output data */ |
| 60 | bool doing_release; |
| 61 | |
| 62 | int max_transfer_size; |
| 63 | |
| 64 | /* Tracks if tty layer can receive data from driver */ |
| 65 | bool tty_canrecv; |
| 66 | |
| 67 | /* |
| 68 | * List of pending incoming buffers from the vServices stack. If we |
| 69 | * receive a buffer, but cannot write it to the tty layer then we |
| 70 | * queue it on this list to handle later. in_lock protects access to |
| 71 | * the pending_in_packets list and the tty_canrecv field. |
| 72 | */ |
| 73 | struct list_head pending_in_packets; |
| 74 | spinlock_t in_lock; |
| 75 | |
| 76 | #ifdef CONFIG_OKL4_VTTY_CONSOLE |
| 77 | struct console console; |
| 78 | #endif |
| 79 | |
| 80 | struct tty_port port; |
| 81 | }; |
| 82 | |
| 83 | extern struct vtty_port * |
| 84 | vs_serial_alloc_port(struct vs_service_device *service, |
| 85 | struct vtty_port_ops *port_ops); |
| 86 | extern void vs_serial_release(struct vtty_port *port); |
| 87 | extern void vs_serial_reset(struct vtty_port *port); |
| 88 | extern int vs_serial_handle_message(struct vtty_port *port, |
| 89 | struct vs_mbuf *mbuf, struct vs_pbuf *pbuf); |
| 90 | |
| 91 | #endif /* _VS_SERIAL_COMMON_H */ |