tty: add SPDX identifiers to all remaining files in drivers/tty/
[linux-block.git] / drivers / tty / serial / earlycon-arm-semihost.c
CommitLineData
e3b3d0f5 1// SPDX-License-Identifier: GPL-2.0
d50d7269
RH
2/*
3 * Copyright (C) 2012 ARM Ltd.
4 * Author: Marc Zyngier <marc.zyngier@arm.com>
5 *
6 * Adapted for ARM and earlycon:
7 * Copyright (C) 2014 Linaro Ltd.
8 * Author: Rob Herring <robh@kernel.org>
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22#include <linux/kernel.h>
23#include <linux/console.h>
24#include <linux/init.h>
25#include <linux/serial_core.h>
26
27#ifdef CONFIG_THUMB2_KERNEL
28#define SEMIHOST_SWI "0xab"
29#else
30#define SEMIHOST_SWI "0x123456"
31#endif
32
33/*
34 * Semihosting-based debug console
35 */
36static void smh_putc(struct uart_port *port, int c)
37{
38#ifdef CONFIG_ARM64
39 asm volatile("mov x1, %0\n"
40 "mov x0, #3\n"
41 "hlt 0xf000\n"
42 : : "r" (&c) : "x0", "x1", "memory");
43#else
44 asm volatile("mov r1, %0\n"
45 "mov r0, #3\n"
46 "svc " SEMIHOST_SWI "\n"
47 : : "r" (&c) : "r0", "r1", "memory");
48#endif
49}
50
51static void smh_write(struct console *con, const char *s, unsigned n)
52{
53 struct earlycon_device *dev = con->data;
54 uart_console_write(&dev->port, s, n, smh_putc);
55}
56
8f975fe4
BX
57static int
58__init early_smh_setup(struct earlycon_device *device, const char *opt)
d50d7269
RH
59{
60 device->con->write = smh_write;
61 return 0;
62}
63EARLYCON_DECLARE(smh, early_smh_setup);