iPXE
Functions | Variables
uart.c File Reference

Generic UARTs. More...

#include <stdlib.h>
#include <strings.h>
#include <errno.h>
#include <ipxe/uart.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 LIST_HEAD (uarts)
 List of registered UARTs. More...
 
static void null_uart_transmit (struct uart *uart __unused, uint8_t byte __unused)
 
static int null_uart_data_ready (struct uart *uart __unused)
 
static uint8_t null_uart_receive (struct uart *uart __unused)
 
static int null_uart_init (struct uart *uart __unused)
 
static void null_uart_flush (struct uart *uart __unused)
 
struct uartalloc_uart (size_t priv_len)
 Allocate UART. More...
 
__weak int uart_register_fixed (void)
 Register fixed UARTs (when not provided by platform) More...
 
int uart_register (struct uart *uart)
 Register UART. More...
 
void uart_unregister (struct uart *uart)
 Unregister UART. More...
 
struct uartuart_find (const char *name)
 Find named UART. More...
 

Variables

struct uart_operations null_uart_operations
 Null UART operations. More...
 

Detailed Description

Generic UARTs.

Definition in file uart.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ LIST_HEAD()

LIST_HEAD ( uarts  )

List of registered UARTs.

◆ null_uart_transmit()

static void null_uart_transmit ( struct uart *uart  __unused,
uint8_t byte  __unused 
)
static

Definition at line 40 of file uart.c.

41  {
42 }

◆ null_uart_data_ready()

static int null_uart_data_ready ( struct uart *uart  __unused)
static

Definition at line 44 of file uart.c.

44  {
45  return 0;
46 }

◆ null_uart_receive()

static uint8_t null_uart_receive ( struct uart *uart  __unused)
static

Definition at line 48 of file uart.c.

48  {
49  return 0;
50 }

◆ null_uart_init()

static int null_uart_init ( struct uart *uart  __unused)
static

Definition at line 52 of file uart.c.

52  {
53  return 0;
54 }

◆ null_uart_flush()

static void null_uart_flush ( struct uart *uart  __unused)
static

Definition at line 56 of file uart.c.

56  {
57 }

◆ alloc_uart()

struct uart* alloc_uart ( size_t  priv_len)

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 }
A generic UART.
Definition: uart.h:17
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:661
void * priv
Driver-private data.
Definition: uart.h:31
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

Referenced by dwuart_probe().

◆ uart_register_fixed()

__weak int uart_register_fixed ( void  )

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 }

Referenced by uart_find().

◆ uart_register()

int uart_register ( struct uart uart)

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 );
106  list_add_tail ( &uart->list, &uarts );
107  DBGC ( uart, "UART %s registered\n", uart->name );
108 
109  return 0;
110 }
A generic UART.
Definition: uart.h:17
#define DBGC(...)
Definition: compiler.h:505
const char * name
Name.
Definition: uart.h:21
struct list_head list
List of registered UARTs.
Definition: uart.h:23
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
struct list_head uarts

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

Referenced by dwuart_probe(), and uart_register_fixed().

◆ uart_unregister()

void uart_unregister ( struct uart uart)

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 }
A generic UART.
Definition: uart.h:17
struct list_head list
List of registered UARTs.
Definition: uart.h:23
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119

References uart::list, and list_del.

Referenced by dwuart_probe(), and dwuart_remove().

◆ uart_find()

struct uart* uart_find ( const char *  name)

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:14
const char * name
Definition: ath9k_hw.c:1984
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition: string.c:484
A generic UART.
Definition: uart.h:17
#define DBGC(...)
Definition: compiler.h:505
long index
Definition: bigint.h:62
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
Definition: string.c:208
const char * name
Name.
Definition: uart.h:21
struct list_head list
List of registered UARTs.
Definition: uart.h:23
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
__weak int uart_register_fixed(void)
Register fixed UARTs (when not provided by platform)
Definition: uart.c:91
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct list_head uarts
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

Referenced by gdbserial_configure().

Variable Documentation

◆ null_uart_operations

struct uart_operations null_uart_operations
Initial value:
= {
.transmit = null_uart_transmit,
.data_ready = null_uart_data_ready,
.receive = null_uart_receive,
.init = null_uart_init,
.flush = null_uart_flush,
}
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
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

Null UART operations.

Definition at line 60 of file uart.c.