iPXE
Data Structures | Functions | Variables
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. More...
 
struct uartalloc_uart (size_t priv_len)
 Allocate UART. More...
 
int uart_register (struct uart *uart)
 Register UART. More...
 
int uart_register_fixed (void)
 Register fixed UARTs (when not provided by platform) More...
 
void uart_unregister (struct uart *uart)
 Unregister UART. More...
 
struct uartuart_find (const char *name)
 Find named UART. More...
 

Variables

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

Detailed Description

Generic UART.

Definition in file uart.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ __attribute__()

static __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 }
A generic UART.
Definition: uart.h:17
int(* data_ready)(struct uart *uart)
Check if data is ready.
Definition: uart.h:50
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)

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()

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_register_fixed()

int uart_register_fixed ( void  )

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 COM1, COM2, COM3, COM4, DBGC, name, rc, strerror(), and uart_register().

Referenced by uart_find().

◆ 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

◆ byte

Initial value:
{
uart->op->transmit ( uart, byte )
A generic UART.
Definition: uart.h:17
void(* transmit)(struct uart *uart, uint8_t byte)
Transmit byte.
Definition: uart.h:43
struct uart_operations * op
UART operations.
Definition: uart.h:29

Definition at line 81 of file uart.h.

◆ uarts

struct list_head uarts

◆ null_uart_operations

struct uart_operations null_uart_operations

Null UART operations.

Definition at line 60 of file uart.c.