iPXE
uart.h File Reference

Generic UART. More...

#include <stdint.h>
#include <ipxe/refcnt.h>
#include <ipxe/list.h>

Go to the source code of this file.

Data Structures

struct  uart
 A generic UART. More...
struct  uart_operations
 UART operations. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static __attribute__ ((always_inline)) void uart_transmit(struct uart *uart
 Transmit byte.
struct uartalloc_uart (size_t priv_len)
 Allocate UART.
int uart_register (struct uart *uart)
 Register UART.
int uart_register_fixed (void)
 Register fixed UARTs (when not provided by platform)
void uart_unregister (struct uart *uart)
 Unregister UART.
struct uartuart_find (const char *name)
 Find named UART.

Variables

static uint8_t byte
struct list_head uarts
struct uart_operations null_uart_operations
 Null UART operations.

Detailed Description

Generic UART.

Definition in file uart.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ __attribute__()

__attribute__ ( (always_inline) )
inlinestatic

Transmit byte.

Nullify UART.

Drop reference to UART.

Get reference to UART.

Flush transmitted data.

Initialise UART.

Receive byte.

Check if data is ready.

Parameters
uartUART
byteByte to transmit
Return values
rcReturn status code
Parameters
uartUART
Return values
readyData is ready
Parameters
uartUART
Return values
byteReceived byte
Parameters
uartUART
Return values
rcReturn status code
Parameters
uartUART
uartUART
Return values
uartUART

Definition at line 92 of file uart.h.

93 {
94
95 return uart->op->data_ready ( uart );
96}
int(* data_ready)(struct uart *uart)
Check if data is ready.
Definition uart.h:50
A generic UART.
Definition uart.h:17
struct uart_operations * op
UART operations.
Definition uart.h:29

References uart_operations::data_ready, and uart::op.

◆ alloc_uart()

struct uart * alloc_uart ( size_t priv_len)
extern

Allocate UART.

Parameters
priv_lenLength of private data
Return values
uartUART, or NULL on error

Definition at line 74 of file uart.c.

74 {
75 struct uart *uart;
76
77 /* Allocate and initialise UART */
78 uart = zalloc ( sizeof ( *uart ) + priv_len );
79 if ( ! uart )
80 return NULL;
81 uart->priv = ( ( ( void * ) uart ) + sizeof ( *uart ) );
82
83 return uart;
84}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:662
void * priv
Driver-private data.
Definition uart.h:31

References NULL, uart::priv, and zalloc().

Referenced by dwuart_probe().

◆ uart_register()

int uart_register ( struct uart * uart)
extern

Register UART.

Parameters
uartUART
Return values
rcReturn status code

Definition at line 102 of file uart.c.

102 {
103
104 /* Add to list of registered UARTs */
105 uart_get ( uart );
107 DBGC ( uart, "UART %s registered\n", uart->name );
108
109 return 0;
110}
#define DBGC(...)
Definition compiler.h:505
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition list.h:94
const char * name
Name.
Definition uart.h:21
struct list_head list
List of registered UARTs.
Definition uart.h:23
struct list_head uarts

References DBGC, uart::list, list_add_tail, uart::name, and uarts.

Referenced by dwuart_probe(), and uart_register_fixed().

◆ uart_register_fixed()

int uart_register_fixed ( void )
extern

Register fixed UARTs (when not provided by platform)

Return values
rcReturn status code

Register fixed UARTs (when not provided by platform)

Return values
rcReturn status code

Definition at line 91 of file uart.c.

91 {
92
93 return 0;
94}

References __weak, COM1, COM2, COM3, COM4, DBGC, name, rc, strerror(), and uart_register().

Referenced by uart_find().

◆ uart_unregister()

void uart_unregister ( struct uart * uart)
extern

Unregister UART.

Parameters
uartUART

Definition at line 117 of file uart.c.

117 {
118
119 /* Remove from list of registered UARTs */
120 list_del ( &uart->list );
121 uart_put ( uart );
122}
#define list_del(list)
Delete an entry from a list.
Definition list.h:120

References uart::list, and list_del.

Referenced by dwuart_probe(), and dwuart_remove().

◆ uart_find()

struct uart * uart_find ( const char * name)
extern

Find named UART.

Parameters
nameUART name
Return values
uartUART, or NULL if not found

Definition at line 130 of file uart.c.

130 {
131 struct uart *uart;
132 unsigned int index;
133 char *endp;
134 int rc;
135
136 /* Register fixed platform UARTs if not already registered */
137 if ( list_empty ( &uarts ) ) {
138 if ( ( rc = uart_register_fixed() ) != 0 ) {
139 DBGC ( &uarts, "UART could not register fixed UARTs: "
140 "%s\n", strerror ( rc ) );
141 /* Continue anyway */
142 }
143 }
144
145 /* Try parsing name as a numeric index */
146 index = strtoul ( name, &endp, 10 );
147
148 /* Find matching UART, if any */
150
151 /* Check for a matching name */
152 if ( strcasecmp ( name, uart->name ) == 0 )
153 return uart;
154
155 /* Check for a matching numeric index */
156 if ( ( *endp == '\0' ) && ( index-- == 0 ) )
157 return uart;
158 }
159
160 DBGC ( &uarts, "UART %s not found\n", name );
161 return NULL;
162}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
long index
Definition bigint.h:65
const char * name
Definition ath9k_hw.c:1986
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition list.h:432
#define list_empty(list)
Test whether a list is empty.
Definition list.h:137
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition string.c:485
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
Definition string.c:209
__weak int uart_register_fixed(void)
Register fixed UARTs (when not provided by platform)
Definition uart.c:91

References DBGC, index, uart::list, list_empty, list_for_each_entry, name, uart::name, NULL, rc, strcasecmp(), strerror(), strtoul(), uart_register_fixed(), and uarts.

Referenced by gdbserial_configure().

Variable Documentation

◆ byte

Initial value:
{
uart->op->transmit ( uart, byte )
void(* transmit)(struct uart *uart, uint8_t byte)
Transmit byte.
Definition uart.h:43

Definition at line 81 of file uart.h.

◆ uarts

struct list_head uarts
extern

◆ null_uart_operations

struct uart_operations null_uart_operations
extern

Null UART operations.

Definition at line 60 of file uart.c.

60 {
61 .transmit = null_uart_transmit,
62 .data_ready = null_uart_data_ready,
63 .receive = null_uart_receive,
64 .init = null_uart_init,
65 .flush = null_uart_flush,
66};
static void null_uart_transmit(struct uart *uart __unused, uint8_t byte __unused)
Definition uart.c:40
static uint8_t null_uart_receive(struct uart *uart __unused)
Definition uart.c:48
static int null_uart_init(struct uart *uart __unused)
Definition uart.c:52
static void null_uart_flush(struct uart *uart __unused)
Definition uart.c:56
static int null_uart_data_ready(struct uart *uart __unused)
Definition uart.c:44