linux/drivers/tty/serial/8250/8250_port.c

// SPDX-License-Identifier: GPL-2.0+
/*
 *  Base port operations for 8250/16550-type serial ports
 *
 *  Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
 *  Split from 8250_core.c, Copyright (C) 2001 Russell King.
 *
 * A note about mapbase / membase
 *
 *  mapbase is the physical address of the IO port.
 *  membase is an 'ioremapped' cookie.
 */

#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/ioport.h>
#include <linux/init.h>
#include <linux/irq.h>
#include <linux/console.h>
#include <linux/gpio/consumer.h>
#include <linux/sysrq.h>
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <linux/tty.h>
#include <linux/ratelimit.h>
#include <linux/tty_flip.h>
#include <linux/serial.h>
#include <linux/serial_8250.h>
#include <linux/nmi.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/pm_runtime.h>
#include <linux/ktime.h>

#include <asm/io.h>
#include <asm/irq.h>

#include "8250.h"

/*
 * Debugging.
 */
#if 0
#define DEBUG_AUTOCONF
#else
#define DEBUG_AUTOCONF(fmt...)
#endif

/*
 * Here we define the default xmit fifo size used for each type of UART.
 */
static const struct serial8250_config uart_config[] =;

/* Uart divisor latch read */
static u32 default_serial_dl_read(struct uart_8250_port *up)
{}

/* Uart divisor latch write */
static void default_serial_dl_write(struct uart_8250_port *up, u32 value)
{}

static unsigned int hub6_serial_in(struct uart_port *p, int offset)
{}

static void hub6_serial_out(struct uart_port *p, int offset, int value)
{}

static unsigned int mem_serial_in(struct uart_port *p, int offset)
{}

static void mem_serial_out(struct uart_port *p, int offset, int value)
{}

static void mem16_serial_out(struct uart_port *p, int offset, int value)
{}

static unsigned int mem16_serial_in(struct uart_port *p, int offset)
{}

static void mem32_serial_out(struct uart_port *p, int offset, int value)
{}

static unsigned int mem32_serial_in(struct uart_port *p, int offset)
{}

static void mem32be_serial_out(struct uart_port *p, int offset, int value)
{}

static unsigned int mem32be_serial_in(struct uart_port *p, int offset)
{}

static unsigned int io_serial_in(struct uart_port *p, int offset)
{}

static void io_serial_out(struct uart_port *p, int offset, int value)
{}

static int serial8250_default_handle_irq(struct uart_port *port);

static void set_io_from_upio(struct uart_port *p)
{}

static void
serial_port_out_sync(struct uart_port *p, int offset, int value)
{}

/*
 * FIFO support.
 */
static void serial8250_clear_fifos(struct uart_8250_port *p)
{}

static enum hrtimer_restart serial8250_em485_handle_start_tx(struct hrtimer *t);
static enum hrtimer_restart serial8250_em485_handle_stop_tx(struct hrtimer *t);

void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p)
{}
EXPORT_SYMBOL_GPL();

void serial8250_rpm_get(struct uart_8250_port *p)
{}
EXPORT_SYMBOL_GPL();

void serial8250_rpm_put(struct uart_8250_port *p)
{}
EXPORT_SYMBOL_GPL();

/**
 *	serial8250_em485_init() - put uart_8250_port into rs485 emulating
 *	@p:	uart_8250_port port instance
 *
 *	The function is used to start rs485 software emulating on the
 *	&struct uart_8250_port* @p. Namely, RTS is switched before/after
 *	transmission. The function is idempotent, so it is safe to call it
 *	multiple times.
 *
 *	The caller MUST enable interrupt on empty shift register before
 *	calling serial8250_em485_init(). This interrupt is not a part of
 *	8250 standard, but implementation defined.
 *
 *	The function is supposed to be called from .rs485_config callback
 *	or from any other callback protected with p->port.lock spinlock.
 *
 *	See also serial8250_em485_destroy()
 *
 *	Return 0 - success, -errno - otherwise
 */
static int serial8250_em485_init(struct uart_8250_port *p)
{}

/**
 *	serial8250_em485_destroy() - put uart_8250_port into normal state
 *	@p:	uart_8250_port port instance
 *
 *	The function is used to stop rs485 software emulating on the
 *	&struct uart_8250_port* @p. The function is idempotent, so it is safe to
 *	call it multiple times.
 *
 *	The function is supposed to be called from .rs485_config callback
 *	or from any other callback protected with p->port.lock spinlock.
 *
 *	See also serial8250_em485_init()
 */
void serial8250_em485_destroy(struct uart_8250_port *p)
{}
EXPORT_SYMBOL_GPL();

struct serial_rs485 serial8250_em485_supported =;
EXPORT_SYMBOL_GPL();

/**
 * serial8250_em485_config() - generic ->rs485_config() callback
 * @port: uart port
 * @termios: termios structure
 * @rs485: rs485 settings
 *
 * Generic callback usable by 8250 uart drivers to activate rs485 settings
 * if the uart is incapable of driving RTS as a Transmit Enable signal in
 * hardware, relying on software emulation instead.
 */
int serial8250_em485_config(struct uart_port *port, struct ktermios *termios,
			    struct serial_rs485 *rs485)
{}
EXPORT_SYMBOL_GPL();

/*
 * These two wrappers ensure that enable_runtime_pm_tx() can be called more than
 * once and disable_runtime_pm_tx() will still disable RPM because the fifo is
 * empty and the HW can idle again.
 */
void serial8250_rpm_get_tx(struct uart_8250_port *p)
{}
EXPORT_SYMBOL_GPL();

void serial8250_rpm_put_tx(struct uart_8250_port *p)
{}
EXPORT_SYMBOL_GPL();

/*
 * IER sleep support.  UARTs which have EFRs need the "extended
 * capability" bit enabled.  Note that on XR16C850s, we need to
 * reset LCR to write to IER.
 */
static void serial8250_set_sleep(struct uart_8250_port *p, int sleep)
{}

static void serial8250_clear_IER(struct uart_8250_port *up)
{}

#ifdef CONFIG_SERIAL_8250_RSA
/*
 * Attempts to turn on the RSA FIFO.  Returns zero on failure.
 * We set the port uart clock rate if we succeed.
 */
static int __enable_rsa(struct uart_8250_port *up)
{}

static void enable_rsa(struct uart_8250_port *up)
{}

/*
 * Attempts to turn off the RSA FIFO.  Returns zero on failure.
 * It is unknown why interrupts were disabled in here.  However,
 * the caller is expected to preserve this behaviour by grabbing
 * the spinlock before calling this function.
 */
static void disable_rsa(struct uart_8250_port *up)
{}
#endif /* CONFIG_SERIAL_8250_RSA */

/*
 * This is a quickie test to see how big the FIFO is.
 * It doesn't work at all the time, more's the pity.
 */
static int size_fifo(struct uart_8250_port *up)
{}

/*
 * Read UART ID using the divisor method - set DLL and DLM to zero
 * and the revision will be in DLL and device type in DLM.  We
 * preserve the device state across this.
 */
static unsigned int autoconfig_read_divisor_id(struct uart_8250_port *p)
{}

/*
 * This is a helper routine to autodetect StarTech/Exar/Oxsemi UART's.
 * When this function is called we know it is at least a StarTech
 * 16650 V2, but it might be one of several StarTech UARTs, or one of
 * its clones.  (We treat the broken original StarTech 16650 V1 as a
 * 16550, and why not?  Startech doesn't seem to even acknowledge its
 * existence.)
 *
 * What evil have men's minds wrought...
 */
static void autoconfig_has_efr(struct uart_8250_port *up)
{}

/*
 * We detected a chip without a FIFO.  Only two fall into
 * this category - the original 8250 and the 16450.  The
 * 16450 has a scratch register (accessible with LCR=0)
 */
static void autoconfig_8250(struct uart_8250_port *up)
{}

static int broken_efr(struct uart_8250_port *up)
{}

/*
 * We know that the chip has FIFOs.  Does it have an EFR?  The
 * EFR is located in the same register position as the IIR and
 * we know the top two bits of the IIR are currently set.  The
 * EFR should contain zero.  Try to read the EFR.
 */
static void autoconfig_16550a(struct uart_8250_port *up)
{}

/*
 * This routine is called by rs_init() to initialize a specific serial
 * port.  It determines what type of UART chip this serial port is
 * using: 8250, 16450, 16550, 16550A.  The important question is
 * whether or not this UART is a 16550A or not, since this will
 * determine whether or not we can use its FIFO features or not.
 */
static void autoconfig(struct uart_8250_port *up)
{}

static void autoconfig_irq(struct uart_8250_port *up)
{}

static void serial8250_stop_rx(struct uart_port *port)
{}

/**
 * serial8250_em485_stop_tx() - generic ->rs485_stop_tx() callback
 * @p: uart 8250 port
 *
 * Generic callback usable by 8250 uart drivers to stop rs485 transmission.
 */
void serial8250_em485_stop_tx(struct uart_8250_port *p)
{}
EXPORT_SYMBOL_GPL();

static enum hrtimer_restart serial8250_em485_handle_stop_tx(struct hrtimer *t)
{}

static void start_hrtimer_ms(struct hrtimer *hrt, unsigned long msec)
{}

static void __stop_tx_rs485(struct uart_8250_port *p, u64 stop_delay)
{}

static inline void __stop_tx(struct uart_8250_port *p)
{}

static void serial8250_stop_tx(struct uart_port *port)
{}

static inline void __start_tx(struct uart_port *port)
{}

/**
 * serial8250_em485_start_tx() - generic ->rs485_start_tx() callback
 * @up: uart 8250 port
 *
 * Generic callback usable by 8250 uart drivers to start rs485 transmission.
 * Assumes that setting the RTS bit in the MCR register means RTS is high.
 * (Some chips use inverse semantics.)  Further assumes that reception is
 * stoppable by disabling the UART_IER_RDI interrupt.  (Some chips set the
 * UART_LSR_DR bit even when UART_IER_RDI is disabled, foiling this approach.)
 */
void serial8250_em485_start_tx(struct uart_8250_port *up)
{}
EXPORT_SYMBOL_GPL();

/* Returns false, if start_tx_timer was setup to defer TX start */
static bool start_tx_rs485(struct uart_port *port)
{}

static enum hrtimer_restart serial8250_em485_handle_start_tx(struct hrtimer *t)
{}

static void serial8250_start_tx(struct uart_port *port)
{}

static void serial8250_throttle(struct uart_port *port)
{}

static void serial8250_unthrottle(struct uart_port *port)
{}

static void serial8250_disable_ms(struct uart_port *port)
{}

static void serial8250_enable_ms(struct uart_port *port)
{}

void serial8250_read_char(struct uart_8250_port *up, u16 lsr)
{}
EXPORT_SYMBOL_GPL();

/*
 * serial8250_rx_chars - Read characters. The first LSR value must be passed in.
 *
 * Returns LSR bits. The caller should rely only on non-Rx related LSR bits
 * (such as THRE) because the LSR value might come from an already consumed
 * character.
 */
u16 serial8250_rx_chars(struct uart_8250_port *up, u16 lsr)
{}
EXPORT_SYMBOL_GPL();

void serial8250_tx_chars(struct uart_8250_port *up)
{}
EXPORT_SYMBOL_GPL();

/* Caller holds uart port lock */
unsigned int serial8250_modem_status(struct uart_8250_port *up)
{}
EXPORT_SYMBOL_GPL();

static bool handle_rx_dma(struct uart_8250_port *up, unsigned int iir)
{}

/*
 * This handles the interrupt from one port.
 */
int serial8250_handle_irq(struct uart_port *port, unsigned int iir)
{}
EXPORT_SYMBOL_GPL();

static int serial8250_default_handle_irq(struct uart_port *port)
{}

/*
 * Newer 16550 compatible parts such as the SC16C650 & Altera 16550 Soft IP
 * have a programmable TX threshold that triggers the THRE interrupt in
 * the IIR register. In this case, the THRE interrupt indicates the FIFO
 * has space available. Load it up with tx_loadsz bytes.
 */
static int serial8250_tx_threshold_handle_irq(struct uart_port *port)
{}

static unsigned int serial8250_tx_empty(struct uart_port *port)
{}

unsigned int serial8250_do_get_mctrl(struct uart_port *port)
{}
EXPORT_SYMBOL_GPL();

static unsigned int serial8250_get_mctrl(struct uart_port *port)
{}

void serial8250_do_set_mctrl(struct uart_port *port, unsigned int mctrl)
{}
EXPORT_SYMBOL_GPL();

static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl)
{}

static void serial8250_break_ctl(struct uart_port *port, int break_state)
{}

static void wait_for_lsr(struct uart_8250_port *up, int bits)
{}

/*
 *	Wait for transmitter & holding register to empty
 */
static void wait_for_xmitr(struct uart_8250_port *up, int bits)
{}

#ifdef CONFIG_CONSOLE_POLL
/*
 * Console polling routines for writing and reading from the uart while
 * in an interrupt or debug context.
 */

static int serial8250_get_poll_char(struct uart_port *port)
{}


static void serial8250_put_poll_char(struct uart_port *port,
			 unsigned char c)
{}

#endif /* CONFIG_CONSOLE_POLL */

int serial8250_do_startup(struct uart_port *port)
{}
EXPORT_SYMBOL_GPL();

static int serial8250_startup(struct uart_port *port)
{}

void serial8250_do_shutdown(struct uart_port *port)
{}
EXPORT_SYMBOL_GPL();

static void serial8250_shutdown(struct uart_port *port)
{}

static unsigned int serial8250_do_get_divisor(struct uart_port *port,
					      unsigned int baud,
					      unsigned int *frac)
{}

static unsigned int serial8250_get_divisor(struct uart_port *port,
					   unsigned int baud,
					   unsigned int *frac)
{}

static unsigned char serial8250_compute_lcr(struct uart_8250_port *up,
					    tcflag_t c_cflag)
{}

void serial8250_do_set_divisor(struct uart_port *port, unsigned int baud,
			       unsigned int quot)
{}
EXPORT_SYMBOL_GPL();

static void serial8250_set_divisor(struct uart_port *port, unsigned int baud,
				   unsigned int quot, unsigned int quot_frac)
{}

static unsigned int serial8250_get_baud_rate(struct uart_port *port,
					     struct ktermios *termios,
					     const struct ktermios *old)
{}

/*
 * Note in order to avoid the tty port mutex deadlock don't use the next method
 * within the uart port callbacks. Primarily it's supposed to be utilized to
 * handle a sudden reference clock rate change.
 */
void serial8250_update_uartclk(struct uart_port *port, unsigned int uartclk)
{}
EXPORT_SYMBOL_GPL();

void
serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
		          const struct ktermios *old)
{}
EXPORT_SYMBOL();

static void
serial8250_set_termios(struct uart_port *port, struct ktermios *termios,
		       const struct ktermios *old)
{}

void serial8250_do_set_ldisc(struct uart_port *port, struct ktermios *termios)
{}
EXPORT_SYMBOL_GPL();

static void
serial8250_set_ldisc(struct uart_port *port, struct ktermios *termios)
{}

void serial8250_do_pm(struct uart_port *port, unsigned int state,
		      unsigned int oldstate)
{}
EXPORT_SYMBOL();

static void
serial8250_pm(struct uart_port *port, unsigned int state,
	      unsigned int oldstate)
{}

static unsigned int serial8250_port_size(struct uart_8250_port *pt)
{}

/*
 * Resource handling.
 */
static int serial8250_request_std_resource(struct uart_8250_port *up)
{}

static void serial8250_release_std_resource(struct uart_8250_port *up)
{}

static void serial8250_release_port(struct uart_port *port)
{}

static int serial8250_request_port(struct uart_port *port)
{}

static int fcr_get_rxtrig_bytes(struct uart_8250_port *up)
{}

static int bytes_to_fcr_rxtrig(struct uart_8250_port *up, unsigned char bytes)
{}

static int do_get_rxtrig(struct tty_port *port)
{}

static int do_serial8250_get_rxtrig(struct tty_port *port)
{}

static ssize_t rx_trig_bytes_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{}

static int do_set_rxtrig(struct tty_port *port, unsigned char bytes)
{}

static int do_serial8250_set_rxtrig(struct tty_port *port, unsigned char bytes)
{}

static ssize_t rx_trig_bytes_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t count)
{}

static DEVICE_ATTR_RW(rx_trig_bytes);

static struct attribute *serial8250_dev_attrs[] =;

static struct attribute_group serial8250_dev_attr_group =;

static void register_dev_spec_attr_grp(struct uart_8250_port *up)
{}

static void serial8250_config_port(struct uart_port *port, int flags)
{}

static int
serial8250_verify_port(struct uart_port *port, struct serial_struct *ser)
{}

static const char *serial8250_type(struct uart_port *port)
{}

static const struct uart_ops serial8250_pops =;

void serial8250_init_port(struct uart_8250_port *up)
{}
EXPORT_SYMBOL_GPL();

void serial8250_set_defaults(struct uart_8250_port *up)
{}
EXPORT_SYMBOL_GPL();

#ifdef CONFIG_SERIAL_8250_CONSOLE

static void serial8250_console_putchar(struct uart_port *port, unsigned char ch)
{}

/*
 *	Restore serial console when h/w power-off detected
 */
static void serial8250_console_restore(struct uart_8250_port *up)
{}

/*
 * Print a string to the serial port using the device FIFO
 *
 * It sends fifosize bytes and then waits for the fifo
 * to get empty.
 */
static void serial8250_console_fifo_write(struct uart_8250_port *up,
					  const char *s, unsigned int count)
{}

/*
 *	Print a string to the serial port trying not to disturb
 *	any possible real use of the port...
 *
 *	The console_lock must be held when we get here.
 *
 *	Doing runtime PM is really a bad idea for the kernel console.
 *	Thus, we assume the function is called when device is powered up.
 */
void serial8250_console_write(struct uart_8250_port *up, const char *s,
			      unsigned int count)
{}

static unsigned int probe_baud(struct uart_port *port)
{}

int serial8250_console_setup(struct uart_port *port, char *options, bool probe)
{}

int serial8250_console_exit(struct uart_port *port)
{}

#endif /* CONFIG_SERIAL_8250_CONSOLE */

MODULE_DESCRIPTION();
MODULE_LICENSE();