162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * hvc_console.h
462306a36Sopenharmony_ci * Copyright (C) 2005 IBM Corporation
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Author(s):
762306a36Sopenharmony_ci * 	Ryan S. Arnold <rsa@us.ibm.com>
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * hvc_console header information:
1062306a36Sopenharmony_ci *      moved here from arch/powerpc/include/asm/hvconsole.h
1162306a36Sopenharmony_ci *      and drivers/char/hvc_console.c
1262306a36Sopenharmony_ci */
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#ifndef HVC_CONSOLE_H
1562306a36Sopenharmony_ci#define HVC_CONSOLE_H
1662306a36Sopenharmony_ci#include <linux/kref.h>
1762306a36Sopenharmony_ci#include <linux/tty.h>
1862306a36Sopenharmony_ci#include <linux/spinlock.h>
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci/*
2162306a36Sopenharmony_ci * This is the max number of console adapters that can/will be found as
2262306a36Sopenharmony_ci * console devices on first stage console init.  Any number beyond this range
2362306a36Sopenharmony_ci * can't be used as a console device but is still a valid tty device.
2462306a36Sopenharmony_ci */
2562306a36Sopenharmony_ci#define MAX_NR_HVC_CONSOLES	16
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci/*
2862306a36Sopenharmony_ci * The Linux TTY code does not support dynamic addition of tty derived devices
2962306a36Sopenharmony_ci * so we need to know how many tty devices we might need when space is allocated
3062306a36Sopenharmony_ci * for the tty device.  Since this driver supports hotplug of vty adapters we
3162306a36Sopenharmony_ci * need to make sure we have enough allocated.
3262306a36Sopenharmony_ci */
3362306a36Sopenharmony_ci#define HVC_ALLOC_TTY_ADAPTERS	8
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_cistruct hvc_struct {
3662306a36Sopenharmony_ci	struct tty_port port;
3762306a36Sopenharmony_ci	spinlock_t lock;
3862306a36Sopenharmony_ci	int index;
3962306a36Sopenharmony_ci	int do_wakeup;
4062306a36Sopenharmony_ci	char *outbuf;
4162306a36Sopenharmony_ci	int outbuf_size;
4262306a36Sopenharmony_ci	int n_outbuf;
4362306a36Sopenharmony_ci	uint32_t vtermno;
4462306a36Sopenharmony_ci	const struct hv_ops *ops;
4562306a36Sopenharmony_ci	int irq_requested;
4662306a36Sopenharmony_ci	int data;
4762306a36Sopenharmony_ci	struct winsize ws;
4862306a36Sopenharmony_ci	struct work_struct tty_resize;
4962306a36Sopenharmony_ci	struct list_head next;
5062306a36Sopenharmony_ci	unsigned long flags;
5162306a36Sopenharmony_ci};
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci/* implemented by a low level driver */
5462306a36Sopenharmony_cistruct hv_ops {
5562306a36Sopenharmony_ci	int (*get_chars)(uint32_t vtermno, char *buf, int count);
5662306a36Sopenharmony_ci	int (*put_chars)(uint32_t vtermno, const char *buf, int count);
5762306a36Sopenharmony_ci	int (*flush)(uint32_t vtermno, bool wait);
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci	/* Callbacks for notification. Called in open, close and hangup */
6062306a36Sopenharmony_ci	int (*notifier_add)(struct hvc_struct *hp, int irq);
6162306a36Sopenharmony_ci	void (*notifier_del)(struct hvc_struct *hp, int irq);
6262306a36Sopenharmony_ci	void (*notifier_hangup)(struct hvc_struct *hp, int irq);
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci	/* tiocmget/set implementation */
6562306a36Sopenharmony_ci	int (*tiocmget)(struct hvc_struct *hp);
6662306a36Sopenharmony_ci	int (*tiocmset)(struct hvc_struct *hp, unsigned int set, unsigned int clear);
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci	/* Callbacks to handle tty ports */
6962306a36Sopenharmony_ci	void (*dtr_rts)(struct hvc_struct *hp, bool active);
7062306a36Sopenharmony_ci};
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci/* Register a vterm and a slot index for use as a console (console_init) */
7362306a36Sopenharmony_ciextern int hvc_instantiate(uint32_t vtermno, int index,
7462306a36Sopenharmony_ci			   const struct hv_ops *ops);
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci/* register a vterm for hvc tty operation (module_init or hotplug add) */
7762306a36Sopenharmony_ciextern struct hvc_struct * hvc_alloc(uint32_t vtermno, int data,
7862306a36Sopenharmony_ci				     const struct hv_ops *ops, int outbuf_size);
7962306a36Sopenharmony_ci/* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
8062306a36Sopenharmony_ciextern int hvc_remove(struct hvc_struct *hp);
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci/* data available */
8362306a36Sopenharmony_ciint hvc_poll(struct hvc_struct *hp);
8462306a36Sopenharmony_civoid hvc_kick(void);
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci/* Resize hvc tty terminal window */
8762306a36Sopenharmony_ciextern void __hvc_resize(struct hvc_struct *hp, struct winsize ws);
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_cistatic inline void hvc_resize(struct hvc_struct *hp, struct winsize ws)
9062306a36Sopenharmony_ci{
9162306a36Sopenharmony_ci	unsigned long flags;
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci	spin_lock_irqsave(&hp->lock, flags);
9462306a36Sopenharmony_ci	__hvc_resize(hp, ws);
9562306a36Sopenharmony_ci	spin_unlock_irqrestore(&hp->lock, flags);
9662306a36Sopenharmony_ci}
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci/* default notifier for irq based notification */
9962306a36Sopenharmony_ciextern int notifier_add_irq(struct hvc_struct *hp, int data);
10062306a36Sopenharmony_ciextern void notifier_del_irq(struct hvc_struct *hp, int data);
10162306a36Sopenharmony_ciextern void notifier_hangup_irq(struct hvc_struct *hp, int data);
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci#if defined(CONFIG_XMON) && defined(CONFIG_SMP)
10562306a36Sopenharmony_ci#include <asm/xmon.h>
10662306a36Sopenharmony_ci#else
10762306a36Sopenharmony_cistatic inline int cpus_are_in_xmon(void)
10862306a36Sopenharmony_ci{
10962306a36Sopenharmony_ci	return 0;
11062306a36Sopenharmony_ci}
11162306a36Sopenharmony_ci#endif
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci#endif // HVC_CONSOLE_H
114