source: rtems/bsps/powerpc/qoriq/console/console-config.c @ e560ee85

Last change on this file since e560ee85 was e560ee85, checked in by Joel Sherrill <joel@…>, on 03/01/22 at 21:38:55

bsps/powerpc/: Scripted embedded brains header file clean up

Updates #4625.

  • Property mode set to 100644
File size: 7.7 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup RTEMSBSPsPowerPCQorIQ
5 *
6 * @brief Console configuration.
7 */
8
9/*
10 * Copyright (c) 2010, 2017 embedded brains GmbH.  All rights reserved.
11 *
12 * The license and distribution terms for this file may be
13 * found in the file LICENSE in this distribution or at
14 * http://www.rtems.org/license/LICENSE.
15 */
16
17#include <string.h>
18
19#include <libfdt.h>
20
21#include <rtems/bspIo.h>
22
23#include <libchip/ns16550.h>
24
25#include <asm/epapr_hcalls.h>
26
27#include <bsp.h>
28#include <bsp/fdt.h>
29#include <bsp/irq.h>
30#include <bsp/qoriq.h>
31#include <bsp/intercom.h>
32#include <bsp/uart-bridge.h>
33#include <bsp/console-termios.h>
34
35static void output_char(char c);
36
37#ifdef QORIQ_IS_HYPERVISOR_GUEST
38typedef struct {
39  rtems_termios_device_context base;
40  uint32_t handle;
41} qoriq_bc_context;
42
43static bool qoriq_bc_probe(rtems_termios_device_context *base)
44{
45  qoriq_bc_context *ctx;
46  const void *fdt;
47  int node;
48  const uint32_t *handle;
49  int len;
50
51  fdt = bsp_fdt_get();
52
53  node = fdt_node_offset_by_compatible(fdt, -1, "epapr,hv-byte-channel");
54  if (node < 0) {
55    return false;
56  }
57
58  handle = fdt_getprop(fdt, node, "hv-handle", &len);
59  if (handle == NULL || len != 4) {
60    return false;
61  }
62
63  ctx = (qoriq_bc_context *) base;
64  ctx->handle = fdt32_to_cpu(*handle);
65
66  BSP_output_char = output_char;
67  return true;
68}
69
70static int qoriq_bc_read_polled(rtems_termios_device_context *base)
71{
72  qoriq_bc_context *ctx;
73  char buf[EV_BYTE_CHANNEL_MAX_BYTES];
74  unsigned int count;
75  unsigned int status;
76
77  ctx = (qoriq_bc_context *) base;
78  count = 1;
79  status = ev_byte_channel_receive(ctx->handle, &count, buf);
80
81  if (status != EV_SUCCESS || count == 0) {
82    return -1;
83  }
84
85  return (unsigned char) buf[0];
86}
87
88static void qoriq_bc_write_polled(
89  rtems_termios_device_context *base,
90  const char *buf,
91  size_t len
92)
93{
94  qoriq_bc_context *ctx;
95  uint32_t handle;
96
97  ctx = (qoriq_bc_context *) base;
98  handle = ctx->handle;
99
100  while (len > 0) {
101    unsigned int count;
102    unsigned int status;
103    char buf2[EV_BYTE_CHANNEL_MAX_BYTES];
104    const char *out;
105
106    if (len < EV_BYTE_CHANNEL_MAX_BYTES) {
107      count = len;
108      out = memcpy(buf2, buf, len);
109    } else {
110      count = EV_BYTE_CHANNEL_MAX_BYTES;
111      out = buf;
112    }
113
114    status = ev_byte_channel_send(handle, &count, out);
115
116    if (status == EV_SUCCESS) {
117      len -= count;
118      buf += count;
119    }
120  }
121}
122
123static const rtems_termios_device_handler qoriq_bc_handler_polled = {
124  .poll_read = qoriq_bc_read_polled,
125  .write = qoriq_bc_write_polled,
126  .mode = TERMIOS_POLLED
127};
128
129static qoriq_bc_context qoriq_bc_context_0 = {
130  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("BC 0"),
131};
132#endif /* QORIQ_IS_HYPERVISOR_GUEST */
133
134#if (QORIQ_UART_0_ENABLE + QORIQ_UART_BRIDGE_0_ENABLE == 2) \
135  || (QORIQ_UART_1_ENABLE + QORIQ_UART_BRIDGE_1_ENABLE == 2)
136  #define BRIDGE_MASTER
137#elif QORIQ_UART_BRIDGE_0_ENABLE || QORIQ_UART_BRIDGE_1_ENABLE
138  #define BRIDGE_SLAVE
139#endif
140
141#ifdef BSP_USE_UART_INTERRUPTS
142  #define DEVICE_FNS &ns16550_handler_interrupt
143#else
144  #define DEVICE_FNS &ns16550_handler_polled
145#endif
146
147#if QORIQ_UART_0_ENABLE || QORIQ_UART_1_ENABLE
148  static bool uart_probe(rtems_termios_device_context *base)
149  {
150    ns16550_context *ctx = (ns16550_context *) base;
151
152    ctx->clock = BSP_bus_frequency;
153
154    return ns16550_probe(base);
155  }
156
157  static uint8_t get_register(uintptr_t addr, uint8_t i)
158  {
159    volatile uint8_t *reg = (uint8_t *) addr;
160
161    return reg [i];
162  }
163
164  static void set_register(uintptr_t addr, uint8_t i, uint8_t val)
165  {
166    volatile uint8_t *reg = (uint8_t *) addr;
167
168    reg [i] = val;
169  }
170#endif
171
172#if QORIQ_UART_0_ENABLE
173static ns16550_context qoriq_uart_context_0 = {
174  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 0"),
175  .get_reg = get_register,
176  .set_reg = set_register,
177  .port = (uintptr_t) &qoriq.uart_0,
178  .irq = QORIQ_IRQ_DUART_1,
179  .initial_baud = BSP_CONSOLE_BAUD
180};
181#endif
182
183#if QORIQ_UART_1_ENABLE
184static ns16550_context qoriq_uart_context_1 = {
185  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 1"),
186  .get_reg = get_register,
187  .set_reg = set_register,
188  .port = (uintptr_t) &qoriq.uart_1,
189  .irq = QORIQ_IRQ_DUART_1,
190  .initial_baud = BSP_CONSOLE_BAUD
191};
192#endif
193
194#ifdef BRIDGE_MASTER
195  #define BRIDGE_PROBE qoriq_uart_bridge_master_probe
196  #define BRIDGE_FNS &qoriq_uart_bridge_master
197  #if QORIQ_UART_BRIDGE_0_ENABLE
198    static uart_bridge_master_context bridge_0_context = {
199      .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART Bridge 0"),
200      .device_path = "/dev/ttyS0",
201      .type = INTERCOM_TYPE_UART_0,
202      .transmit_fifo = RTEMS_CHAIN_INITIALIZER_EMPTY(
203        bridge_0_context.transmit_fifo
204      )
205    };
206    #define BRIDGE_0_CONTEXT &bridge_0_context.base
207  #endif
208  #if QORIQ_UART_BRIDGE_1_ENABLE
209    static uart_bridge_master_context bridge_1_context = {
210      .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART Bridge 1"),
211      .device_path = "/dev/ttyS1",
212      .type = INTERCOM_TYPE_UART_1,
213      .transmit_fifo = RTEMS_CHAIN_INITIALIZER_EMPTY(
214        bridge_1_context.transmit_fifo
215      )
216    };
217    #define BRIDGE_1_CONTEXT &bridge_1_context.base
218  #endif
219#endif
220
221#ifdef BRIDGE_SLAVE
222  #define BRIDGE_PROBE console_device_probe_default
223  #define BRIDGE_FNS &qoriq_uart_bridge_slave
224  #if QORIQ_UART_BRIDGE_0_ENABLE
225    static uart_bridge_slave_context bridge_0_context = {
226      .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART Bridge 0"),
227      .type = INTERCOM_TYPE_UART_0,
228      .transmit_fifo = RTEMS_CHAIN_INITIALIZER_EMPTY(
229        bridge_0_context.transmit_fifo
230      )
231    };
232    #define BRIDGE_0_CONTEXT &bridge_0_context.base
233  #endif
234  #if QORIQ_UART_BRIDGE_1_ENABLE
235    static uart_bridge_slave_context bridge_1_context = {
236      .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART Bridge 1"),
237      .type = INTERCOM_TYPE_UART_1,
238      .transmit_fifo = RTEMS_CHAIN_INITIALIZER_EMPTY(
239        bridge_1_context.transmit_fifo
240      )
241    };
242    #define BRIDGE_1_CONTEXT &bridge_1_context.base
243  #endif
244#endif
245
246const console_device console_device_table[] = {
247  #ifdef QORIQ_IS_HYPERVISOR_GUEST
248    {
249      .device_file = "/dev/ttyBC0",
250      .probe = qoriq_bc_probe,
251      .handler = &qoriq_bc_handler_polled,
252      .context = &qoriq_bc_context_0.base
253    },
254  #endif
255  #if QORIQ_UART_0_ENABLE
256    {
257      .device_file = "/dev/ttyS0",
258      .probe = uart_probe,
259      .handler = DEVICE_FNS,
260      .context = &qoriq_uart_context_0.base
261    },
262  #endif
263  #if QORIQ_UART_1_ENABLE
264    {
265      .device_file = "/dev/ttyS1",
266      .probe = uart_probe,
267      .handler = DEVICE_FNS,
268      .context = &qoriq_uart_context_1.base
269    },
270  #endif
271  #if QORIQ_UART_BRIDGE_0_ENABLE
272    {
273      #if QORIQ_UART_1_ENABLE
274        .device_file = "/dev/ttyB0",
275      #else
276        .device_file = "/dev/ttyS0",
277      #endif
278      .probe = BRIDGE_PROBE,
279      .handler = BRIDGE_FNS,
280      .context = BRIDGE_0_CONTEXT
281    },
282  #endif
283  #if QORIQ_UART_BRIDGE_1_ENABLE
284    {
285      #if QORIQ_UART_1_ENABLE
286        .device_file = "/dev/ttyB1",
287      #else
288        .device_file = "/dev/ttyS1",
289      #endif
290      .probe = BRIDGE_PROBE,
291      .handler = BRIDGE_FNS,
292      .context = BRIDGE_1_CONTEXT
293    }
294  #endif
295};
296
297const size_t console_device_count = RTEMS_ARRAY_SIZE(console_device_table);
298
299static void output_char(char c)
300{
301  rtems_termios_device_context *base = console_device_table[0].context;
302
303#ifdef QORIQ_IS_HYPERVISOR_GUEST
304  qoriq_bc_write_polled(base, &c, 1);
305#else
306  ns16550_polled_putchar(base, c);
307#endif
308}
309
310#ifdef QORIQ_IS_HYPERVISOR_GUEST
311static void qoriq_bc_output_char_init(char c)
312{
313  rtems_termios_device_context *base = console_device_table[0].context;
314
315  qoriq_bc_probe(base);
316  output_char(c);
317}
318
319BSP_output_char_function_type BSP_output_char = qoriq_bc_output_char_init;
320#else
321BSP_output_char_function_type BSP_output_char = output_char;
322#endif
323
324BSP_polling_getchar_function_type BSP_poll_char = NULL;
Note: See TracBrowser for help on using the repository browser.