Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:22:42

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSBSPsAArch64XilinxZynqMP
0007  *
0008  * @brief This source file contains this BSP's console configuration.
0009  */
0010 
0011 /*
0012  * Copyright (C) 2022 On-Line Applications Research Corporation (OAR)
0013  * Written by Kinsey Moore <kinsey.moore@oarcorp.com>
0014  *
0015  * Redistribution and use in source and binary forms, with or without
0016  * modification, are permitted provided that the following conditions
0017  * are met:
0018  * 1. Redistributions of source code must retain the above copyright
0019  *    notice, this list of conditions and the following disclaimer.
0020  * 2. Redistributions in binary form must reproduce the above copyright
0021  *    notice, this list of conditions and the following disclaimer in the
0022  *    documentation and/or other materials provided with the distribution.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #include <rtems/console.h>
0038 #include <rtems/endian.h>
0039 #include <rtems/sysinit.h>
0040 #include <rtems/termiostypes.h>
0041 
0042 #include <bsp/aarch64-mmu.h>
0043 #include <bsp/fdt.h>
0044 #include <bsp/irq.h>
0045 
0046 #include <dev/serial/zynq-uart.h>
0047 #include <dev/serial/zynq-uart-regs.h>
0048 
0049 #include <bspopts.h>
0050 #include <libfdt.h>
0051 
0052 #include <libchip/ns16550.h>
0053 
0054 static zynq_uart_context zynqmp_uart_instances[2] = {
0055   {
0056     .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER( "Zynq UART 0" ),
0057     .regs = (volatile zynq_uart *) ZYNQ_UART_0_BASE_ADDR,
0058     .irq = ZYNQMP_IRQ_UART_0
0059   }, {
0060     .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER( "Zynq UART 1" ),
0061     .regs = (volatile zynq_uart *) ZYNQ_UART_1_BASE_ADDR,
0062     .irq = ZYNQMP_IRQ_UART_1
0063   }
0064 };
0065 
0066 rtems_status_code console_initialize(
0067   rtems_device_major_number major,
0068   rtems_device_minor_number minor,
0069   void *arg
0070 )
0071 {
0072   size_t i;
0073 
0074   rtems_termios_initialize();
0075 
0076   for (i = 0; i < RTEMS_ARRAY_SIZE(zynqmp_uart_instances); ++i) {
0077     zynq_uart_context *ctx = &zynqmp_uart_instances[i];
0078     char uart[] = "/dev/ttySX";
0079 
0080     uart[sizeof(uart) - 2] = (char) ('0' + i);
0081     rtems_termios_device_install(
0082       &uart[0],
0083       &zynq_uart_handler,
0084       NULL,
0085       &ctx->base
0086     );
0087 
0088     if (ctx->regs == (zynq_uart *) ZYNQ_UART_KERNEL_IO_BASE_ADDR) {
0089       link(&uart[0], CONSOLE_DEVICE_NAME);
0090     }
0091   }
0092 
0093   zynqmp_management_console_termios_init();
0094 
0095   return RTEMS_SUCCESSFUL;
0096 }
0097 
0098 void zynqmp_debug_console_flush(void)
0099 {
0100   zynq_uart_reset_tx_flush((zynq_uart *) ZYNQ_UART_KERNEL_IO_BASE_ADDR);
0101 }