iPXE
x86_uart.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2025 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 /** @file
27  *
28  * 16550-compatible UART
29  *
30  */
31 
32 #include <string.h>
33 #include <ipxe/serial.h>
34 #include <ipxe/ns16550.h>
35 
36 /** Define a fixed ISA UART */
37 #define ISA_UART( NAME, BASE ) \
38  static struct ns16550_uart ns16550_ ## NAME = { \
39  .base = ( ( void * ) (BASE) ), \
40  .clock = NS16550_CLK_DEFAULT, \
41  }; \
42  struct uart NAME = { \
43  .refcnt = REF_INIT ( ref_no_free ), \
44  .name = #NAME, \
45  .op = &ns16550_operations, \
46  .priv = &ns16550_ ## NAME, \
47  }
48 
49 /* Fixed ISA UARTs */
54 
55 /**
56  * Register fixed ISA UARTs
57  *
58  * @ret rc Return status code
59  */
60 int uart_register_fixed ( void ) {
61  static struct uart *ports[] = { COM1, COM2, COM3, COM4 };
62  unsigned int i;
63  int rc;
64 
65  /* Register all fixed ISA UARTs */
66  for ( i = 0 ; i < ( sizeof ( ports ) / sizeof ( ports[0] ) ) ; i++ ) {
67  if ( ( rc = uart_register ( ports[i] ) ) != 0 ) {
68  DBGC ( ports[i], "UART could not register %s: %s\n",
69  ports[i]->name, strerror ( rc ) );
70  return rc;
71  }
72  }
73 
74  return 0;
75 }
#define COM2
Definition: ns16550.h:56
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
A generic UART.
Definition: uart.h:17
#define COM4
Definition: ns16550.h:58
#define DBGC(...)
Definition: compiler.h:505
#define COM1_BASE
Definition: ns16550.h:43
Serial console.
int uart_register(struct uart *uart)
Register UART.
Definition: uart.c:102
16550-compatible UART
struct uart com3
#define ISA_UART(NAME, BASE)
Define a fixed ISA UART.
Definition: x86_uart.c:37
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define COM2_BASE
Definition: ns16550.h:44
#define COM3_BASE
Definition: ns16550.h:45
struct uart com4
struct uart com2
#define COM1
Definition: ns16550.h:55
#define COM4_BASE
Definition: ns16550.h:46
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define COM3
Definition: ns16550.h:57
int uart_register_fixed(void)
Register fixed ISA UARTs.
Definition: x86_uart.c:60
struct uart com1
String functions.