Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /*
0003  * hvc_console.h
0004  * Copyright (C) 2005 IBM Corporation
0005  *
0006  * Author(s):
0007  *  Ryan S. Arnold <rsa@us.ibm.com>
0008  *
0009  * hvc_console header information:
0010  *      moved here from arch/powerpc/include/asm/hvconsole.h
0011  *      and drivers/char/hvc_console.c
0012  */
0013 
0014 #ifndef HVC_CONSOLE_H
0015 #define HVC_CONSOLE_H
0016 #include <linux/kref.h>
0017 #include <linux/tty.h>
0018 #include <linux/spinlock.h>
0019 
0020 /*
0021  * This is the max number of console adapters that can/will be found as
0022  * console devices on first stage console init.  Any number beyond this range
0023  * can't be used as a console device but is still a valid tty device.
0024  */
0025 #define MAX_NR_HVC_CONSOLES 16
0026 
0027 /*
0028  * The Linux TTY code does not support dynamic addition of tty derived devices
0029  * so we need to know how many tty devices we might need when space is allocated
0030  * for the tty device.  Since this driver supports hotplug of vty adapters we
0031  * need to make sure we have enough allocated.
0032  */
0033 #define HVC_ALLOC_TTY_ADAPTERS  8
0034 
0035 struct hvc_struct {
0036     struct tty_port port;
0037     spinlock_t lock;
0038     int index;
0039     int do_wakeup;
0040     char *outbuf;
0041     int outbuf_size;
0042     int n_outbuf;
0043     uint32_t vtermno;
0044     const struct hv_ops *ops;
0045     int irq_requested;
0046     int data;
0047     struct winsize ws;
0048     struct work_struct tty_resize;
0049     struct list_head next;
0050     unsigned long flags;
0051 };
0052 
0053 /* implemented by a low level driver */
0054 struct hv_ops {
0055     int (*get_chars)(uint32_t vtermno, char *buf, int count);
0056     int (*put_chars)(uint32_t vtermno, const char *buf, int count);
0057     int (*flush)(uint32_t vtermno, bool wait);
0058 
0059     /* Callbacks for notification. Called in open, close and hangup */
0060     int (*notifier_add)(struct hvc_struct *hp, int irq);
0061     void (*notifier_del)(struct hvc_struct *hp, int irq);
0062     void (*notifier_hangup)(struct hvc_struct *hp, int irq);
0063 
0064     /* tiocmget/set implementation */
0065     int (*tiocmget)(struct hvc_struct *hp);
0066     int (*tiocmset)(struct hvc_struct *hp, unsigned int set, unsigned int clear);
0067 
0068     /* Callbacks to handle tty ports */
0069     void (*dtr_rts)(struct hvc_struct *hp, int raise);
0070 };
0071 
0072 /* Register a vterm and a slot index for use as a console (console_init) */
0073 extern int hvc_instantiate(uint32_t vtermno, int index,
0074                const struct hv_ops *ops);
0075 
0076 /* register a vterm for hvc tty operation (module_init or hotplug add) */
0077 extern struct hvc_struct * hvc_alloc(uint32_t vtermno, int data,
0078                      const struct hv_ops *ops, int outbuf_size);
0079 /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
0080 extern int hvc_remove(struct hvc_struct *hp);
0081 
0082 /* data available */
0083 int hvc_poll(struct hvc_struct *hp);
0084 void hvc_kick(void);
0085 
0086 /* Resize hvc tty terminal window */
0087 extern void __hvc_resize(struct hvc_struct *hp, struct winsize ws);
0088 
0089 static inline void hvc_resize(struct hvc_struct *hp, struct winsize ws)
0090 {
0091     unsigned long flags;
0092 
0093     spin_lock_irqsave(&hp->lock, flags);
0094     __hvc_resize(hp, ws);
0095     spin_unlock_irqrestore(&hp->lock, flags);
0096 }
0097 
0098 /* default notifier for irq based notification */
0099 extern int notifier_add_irq(struct hvc_struct *hp, int data);
0100 extern void notifier_del_irq(struct hvc_struct *hp, int data);
0101 extern void notifier_hangup_irq(struct hvc_struct *hp, int data);
0102 
0103 
0104 #if defined(CONFIG_XMON) && defined(CONFIG_SMP)
0105 #include <asm/xmon.h>
0106 #else
0107 static inline int cpus_are_in_xmon(void)
0108 {
0109     return 0;
0110 }
0111 #endif
0112 
0113 #endif // HVC_CONSOLE_H