Changeset 134fe56 in rtems


Ignore:
Timestamp:
Sep 8, 2017, 8:11:32 AM (2 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
df62e51
Parents:
356b1b85
git-author:
Sebastian Huber <sebastian.huber@…> (09/08/17 08:11:32)
git-committer:
Sebastian Huber <sebastian.huber@…> (09/12/17 08:00:33)
Message:

bsp/qoriq: Add byte channel console driver

Update #3085.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/powerpc/qoriq/console/console-config.c

    r356b1b85 r134fe56  
    88
    99/*
    10  * Copyright (c) 2010-2015 embedded brains GmbH.  All rights reserved.
     10 * Copyright (c) 2010, 2017 embedded brains GmbH.  All rights reserved.
    1111 *
    1212 *  embedded brains GmbH
     
    2121 */
    2222
     23#include <string.h>
     24
     25#include <libfdt.h>
     26
    2327#include <rtems/bspIo.h>
    2428
    2529#include <libchip/ns16550.h>
    2630
     31#include <asm/epapr_hcalls.h>
     32
    2733#include <bsp.h>
     34#include <bsp/fdt.h>
    2835#include <bsp/irq.h>
    2936#include <bsp/qoriq.h>
     
    3138#include <bsp/uart-bridge.h>
    3239#include <bsp/console-termios.h>
     40
     41#ifdef QORIQ_IS_HYPERVISOR_GUEST
     42typedef struct {
     43  rtems_termios_device_context base;
     44  uint32_t handle;
     45} qoriq_bc_context;
     46
     47static bool qoriq_bc_probe(rtems_termios_device_context *base)
     48{
     49  qoriq_bc_context *ctx;
     50  const void *fdt;
     51  int node;
     52  const uint32_t *handle;
     53  int len;
     54
     55  fdt = bsp_fdt_get();
     56
     57  node = fdt_node_offset_by_compatible(fdt, -1, "epapr,hv-byte-channel");
     58  if (node < 0) {
     59    return false;
     60  }
     61
     62  handle = fdt_getprop(fdt, node, "hv-handle", &len);
     63  if (handle == NULL || len != 4) {
     64    return false;
     65  }
     66
     67  ctx = (qoriq_bc_context *) base;
     68  ctx->handle = fdt32_to_cpu(*handle);
     69
     70  return true;
     71}
     72
     73static int qoriq_bc_read_polled(rtems_termios_device_context *base)
     74{
     75  qoriq_bc_context *ctx;
     76  char buf[EV_BYTE_CHANNEL_MAX_BYTES];
     77  unsigned int count;
     78  unsigned int status;
     79
     80  ctx = (qoriq_bc_context *) base;
     81  count = 1;
     82  status = ev_byte_channel_receive(ctx->handle, &count, buf);
     83
     84  if (status != EV_SUCCESS) {
     85    return -1;
     86  }
     87
     88  return (unsigned char) buf[0];
     89}
     90
     91static void qoriq_bc_write_polled(
     92  rtems_termios_device_context *base,
     93  const char *buf,
     94  size_t len
     95)
     96{
     97  qoriq_bc_context *ctx;
     98  uint32_t handle;
     99
     100  ctx = (qoriq_bc_context *) base;
     101  handle = ctx->handle;
     102
     103  while (len > 0) {
     104    unsigned int count;
     105    unsigned int status;
     106    char buf2[EV_BYTE_CHANNEL_MAX_BYTES];
     107    const char *out;
     108
     109    if (len < EV_BYTE_CHANNEL_MAX_BYTES) {
     110      count = len;
     111      out = memcpy(buf2, buf, len);
     112    } else {
     113      count = EV_BYTE_CHANNEL_MAX_BYTES;
     114      out = buf;
     115    }
     116
     117    status = ev_byte_channel_send(handle, &count, out);
     118
     119    if (status == EV_SUCCESS) {
     120      len -= count;
     121      buf += count;
     122    }
     123  }
     124}
     125
     126static const rtems_termios_device_handler qoriq_bc_handler_polled = {
     127  .poll_read = qoriq_bc_read_polled,
     128  .write = qoriq_bc_write_polled,
     129  .mode = TERMIOS_POLLED
     130};
     131
     132static qoriq_bc_context qoriq_bc_context_0 = {
     133  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("BC 0"),
     134};
     135#endif /* QORIQ_IS_HYPERVISOR_GUEST */
    33136
    34137#if (QORIQ_UART_0_ENABLE + QORIQ_UART_BRIDGE_0_ENABLE == 2) \
     
    145248
    146249const console_device console_device_table[] = {
     250  #ifdef QORIQ_IS_HYPERVISOR_GUEST
     251    {
     252      .device_file = "/dev/ttyBC0",
     253      .probe = qoriq_bc_probe,
     254      .handler = &qoriq_bc_handler_polled,
     255      .context = &qoriq_bc_context_0.base
     256    },
     257  #endif
    147258  #if QORIQ_UART_0_ENABLE
    148259    {
     
    193304  rtems_termios_device_context *ctx = console_device_table[0].context;
    194305
     306#ifdef QORIQ_IS_HYPERVISOR_GUEST
     307  qoriq_bc_write_polled(ctx, &c, 1);
     308#else
    195309  ns16550_polled_putchar(ctx, c);
     310#endif
    196311}
    197312
Note: See TracChangeset for help on using the changeset viewer.