iPXE
Macros | Functions | Variables
serial.c File Reference

Serial console. More...

#include <stddef.h>
#include <string.h>
#include <ipxe/init.h>
#include <ipxe/uart.h>
#include <ipxe/console.h>
#include <ipxe/serial.h>
#include <config/console.h>
#include <config/serial.h>

Go to the source code of this file.

Macros

#define CONSOLE_SERIAL   ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_LOG )
 
#define CONSOLE_PORT   0
 
#define CONSOLE_BAUD   COMSPEED
 
#define CONSOLE_LCR   UART_LCR_WPS ( COMDATA, COMPARITY, COMSTOP )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void serial_putchar (int character)
 Print a character to serial console. More...
 
static int serial_getchar (void)
 Get character from serial console. More...
 
static int serial_iskey (void)
 Check for character ready to read from serial console. More...
 
static void serial_init (void)
 Initialise serial console. More...
 
static void serial_shutdown (int flags __unused)
 Shut down serial console. More...
 
struct init_fn serial_console_init_fn __init_fn (INIT_CONSOLE)
 Serial console initialisation function. More...
 
struct startup_fn serial_startup_fn __startup_fn (STARTUP_EARLY)
 Serial console startup function. More...
 

Variables

struct uart serial_console
 Serial console UART. More...
 
struct console_driver serial_console_driver __console_driver
 Serial console. More...
 

Detailed Description

Serial console.

Definition in file serial.c.

Macro Definition Documentation

◆ CONSOLE_SERIAL

#define CONSOLE_SERIAL   ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_LOG )

Definition at line 44 of file serial.c.

◆ CONSOLE_PORT

#define CONSOLE_PORT   0

Definition at line 51 of file serial.c.

◆ CONSOLE_BAUD

#define CONSOLE_BAUD   COMSPEED

Definition at line 58 of file serial.c.

◆ CONSOLE_LCR

#define CONSOLE_LCR   UART_LCR_WPS ( COMDATA, COMPARITY, COMSTOP )

Definition at line 65 of file serial.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ serial_putchar()

static void serial_putchar ( int  character)
static

Print a character to serial console.

Parameters
characterCharacter to be printed

Definition at line 76 of file serial.c.

76  {
77 
78  /* Do nothing if we have no UART */
79  if ( ! serial_console.base )
80  return;
81 
82  /* Transmit character */
83  uart_transmit ( &serial_console, character );
84 }
struct uart serial_console
Serial console UART.
Definition: serial.c:69
void uart_transmit(struct uart *uart, uint8_t data)
Transmit data.
Definition: uart.c:48
void * base
I/O port base address.
Definition: uart.h:82

References uart::base, serial_console, and uart_transmit().

◆ serial_getchar()

static int serial_getchar ( void  )
static

Get character from serial console.

Return values
characterCharacter read from console

Definition at line 91 of file serial.c.

91  {
92  uint8_t data;
93 
94  /* Do nothing if we have no UART */
95  if ( ! serial_console.base )
96  return 0;
97 
98  /* Wait for data to be ready */
99  while ( ! uart_data_ready ( &serial_console ) ) {}
100 
101  /* Receive data */
103 
104  /* Strip any high bit and convert DEL to backspace */
105  data &= 0x7f;
106  if ( data == 0x7f )
107  data = 0x08;
108 
109  return data;
110 }
struct uart serial_console
Serial console UART.
Definition: serial.c:69
static int uart_data_ready(struct uart *uart)
Check if received data is ready.
Definition: uart.h:109
void * base
I/O port base address.
Definition: uart.h:82
static uint8_t uart_receive(struct uart *uart)
Receive data.
Definition: uart.h:122
unsigned char uint8_t
Definition: stdint.h:10
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

References uart::base, data, serial_console, uart_data_ready(), and uart_receive().

◆ serial_iskey()

static int serial_iskey ( void  )
static

Check for character ready to read from serial console.

Return values
TrueCharacter available to read
FalseNo character available to read

Definition at line 118 of file serial.c.

118  {
119 
120  /* Do nothing if we have no UART */
121  if ( ! serial_console.base )
122  return 0;
123 
124  /* Check UART */
125  return uart_data_ready ( &serial_console );
126 }
struct uart serial_console
Serial console UART.
Definition: serial.c:69
static int uart_data_ready(struct uart *uart)
Check if received data is ready.
Definition: uart.h:109
void * base
I/O port base address.
Definition: uart.h:82

References uart::base, serial_console, and uart_data_ready().

◆ serial_init()

static void serial_init ( void  )
static

Initialise serial console.

Definition at line 137 of file serial.c.

137  {
138  int rc;
139 
140  /* Do nothing if we have no default port */
141  if ( ! CONSOLE_PORT )
142  return;
143 
144  /* Select UART */
145  if ( ( rc = uart_select ( &serial_console, CONSOLE_PORT ) ) != 0 ) {
146  DBG ( "Could not select UART %d: %s\n",
147  CONSOLE_PORT, strerror ( rc ) );
148  return;
149  }
150 
151  /* Initialise UART */
153  CONSOLE_LCR ) ) != 0 ) {
154  DBG ( "Could not initialise UART %d baud %d LCR %#02x: %s\n",
156  return;
157  }
158 }
struct uart serial_console
Serial console UART.
Definition: serial.c:69
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define CONSOLE_LCR
Definition: serial.c:65
int uart_init(struct uart *uart, unsigned int baud, uint8_t lcr)
Initialise UART.
Definition: uart.c:113
#define CONSOLE_PORT
Definition: serial.c:51
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define CONSOLE_BAUD
Definition: serial.c:58
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
int uart_select(struct uart *uart, unsigned int port)
Select UART port.
Definition: x86_uart.c:50

References CONSOLE_BAUD, CONSOLE_LCR, CONSOLE_PORT, DBG, rc, serial_console, strerror(), uart_init(), and uart_select().

◆ serial_shutdown()

static void serial_shutdown ( int flags  __unused)
static

Shut down serial console.

Parameters
flagsShutdown flags

Definition at line 165 of file serial.c.

165  {
166 
167  /* Do nothing if we have no UART */
168  if ( ! serial_console.base )
169  return;
170 
171  /* Flush any pending output */
173 
174  /* Leave console enabled; it's still usable */
175 }
struct uart serial_console
Serial console UART.
Definition: serial.c:69
void uart_flush(struct uart *uart)
Flush data.
Definition: uart.c:69
void * base
I/O port base address.
Definition: uart.h:82

References uart::base, serial_console, and uart_flush().

◆ __init_fn()

struct init_fn serial_console_init_fn __init_fn ( INIT_CONSOLE  )

Serial console initialisation function.

◆ __startup_fn()

struct startup_fn serial_startup_fn __startup_fn ( STARTUP_EARLY  )

Serial console startup function.

Variable Documentation

◆ serial_console

struct uart serial_console

Serial console UART.

Definition at line 69 of file serial.c.

Referenced by serial_getchar(), serial_init(), serial_iskey(), serial_putchar(), and serial_shutdown().

◆ __console_driver

struct console_driver serial_console_driver __console_driver
Initial value:
= {
.putchar = serial_putchar,
.getchar = serial_getchar,
.iskey = serial_iskey,
.usage = CONSOLE_SERIAL,
}
static int serial_iskey(void)
Check for character ready to read from serial console.
Definition: serial.c:118
static int serial_getchar(void)
Get character from serial console.
Definition: serial.c:91
#define CONSOLE_SERIAL
Definition: serial.c:44
static void serial_putchar(int character)
Print a character to serial console.
Definition: serial.c:76

Serial console.

Definition at line 129 of file serial.c.