Skip to contentSkip to conversation

hvc_dcc: don't ignore errors during initialization

PATCH Superseded Timur Tabi 3 participants 6 messages Aug 19, 2015 – Aug 20, 2015

Subsystems (4)
lore
Share & tools
lore

Timur Tabi

author
#0 lore raw

PATCH v3 1/3 hvc_dcc: don't ignore errors during initialization

hvc_instantiate() and hvc_alloc() return errors if they fail, so don't ignore them.

---
 drivers/tty/hvc/hvc_dcc.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/tty/hvc/hvc_dcc.c +11 -4
index 809920d..82f240f 100644
@@ -70,20 +70,27 @@ static const struct hv_ops hvc_dcc_get_put_ops = {
 
 static int __init hvc_dcc_console_init(void)
 {
+	int ret;
+
 	if (!hvc_dcc_check())
 		return -ENODEV;
 
-	hvc_instantiate(0, 0, &hvc_dcc_get_put_ops);
-	return 0;
+	/* Returns -1 if error */
+	ret = hvc_instantiate(0, 0, &hvc_dcc_get_put_ops);
+
+	return ret < 0 ? -ENODEV : 0;
 }
 console_initcall(hvc_dcc_console_init);
 
 static int __init hvc_dcc_init(void)
 {
+	struct hvc_struct *p;
+
 	if (!hvc_dcc_check())
 		return -ENODEV;
 
-	hvc_alloc(0, 0, &hvc_dcc_get_put_ops, 128);
-	return 0;
+	p = hvc_alloc(0, 0, &hvc_dcc_get_put_ops, 128);
+
+	return PTR_ERR_OR_ZERO(p);
 }
 device_initcall(hvc_dcc_init);
Signature · 3 lines
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.
author
#1 lore raw

PATCH v5 2/3 ARM64: TTY: hvc_dcc: Add support for ARM64 dcc

From: Abhimanyu Kapur <[email protected]>

Add support for debug communications channel based hvc console for arm64 cpus.

---
 arch/arm64/include/asm/dcc.h | 55 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/tty/hvc/Kconfig      |  2 +-
 2 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm64/include/asm/dcc.h
arch/arm64/include/asm/dcc.h new file +55 -0
new file mode 100644
index 0000000..65e0190
@@ -0,0 +1,55 @@
+/* Copyright (c) 2014-2015 The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * A call to __dcc_getchar() or __dcc_putchar() is typically followed by
+ * a call to __dcc_getstatus().  We want to make sure that the CPU does
+ * not speculative read the DCC status before executing the read or write
+ * instruction.  That's what the ISBs are for.
+ *
+ * The 'volatile' ensures that the compiler does not cache the status bits,
+ * and instead reads the DCC register every time.
+ */
+#ifndef __ASM_DCC_H
+#define __ASM_DCC_H
+
+#include <asm/barrier.h>
+
+static inline u32 __dcc_getstatus(void)
+{
+	u32 ret;
+
+	asm volatile("mrs %0, mdccsr_el0" : "=r" (ret));
+
+	return ret;
+}
+
+static inline char __dcc_getchar(void)
+{
+	char c;
+
+	asm volatile("mrs %0, dbgdtrrx_el0" : "=r" (c));
+	isb();
+
+	return c;
+}
+
+static inline void __dcc_putchar(char c)
+{
+	/*
+	 * The typecast is to make absolutely certain that 'c' is
+	 * zero-extended.
+	 */
+	asm volatile("msr dbgdtrtx_el0, %0"
+			: : "r" ((unsigned long)(unsigned char)c));
+	isb();
+}
+
+#endif
drivers/tty/hvc/Kconfig +1 -1
index 2509d05..574da15 100644
@@ -81,7 +81,7 @@ config HVC_UDBG
 
 config HVC_DCC
        bool "ARM JTAG DCC console"
-       depends on ARM
+       depends on ARM || ARM64
        select HVC_DRIVER
        help
          This console uses the JTAG DCC on ARM to create a console under the HVC
Signature · 3 lines
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.
author
#2 lore raw

PATCH v2 3/3 hvc_dcc: disable user-space access to DCC

In reply to Timur Tabi

If the DCC driver loads, then disable user-space access to the DCC so that we don't have two entities trying to access the DCC at the same time.

---
 arch/arm/include/asm/dcc.h   | 15 +++++++++++++++
 arch/arm64/include/asm/dcc.h | 11 +++++++++++
 drivers/tty/hvc/hvc_dcc.c    |  2 ++
 3 files changed, 28 insertions(+)
arch/arm/include/asm/dcc.h +15 -0
index b74899d..c50056b 100644
@@ -9,8 +9,11 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  */
+#ifndef __ASM_DCC_H
+#define __ASM_DCC_H
 
 #include <asm/barrier.h>
+#include <asm/hardware/cp14.h>
 
 static inline u32 __dcc_getstatus(void)
 {
@@ -39,3 +42,15 @@ static inline void __dcc_putchar(char c)
 		: "r" (c));
 	isb();
 }
+
+static inline void __dcc_initialize(void)
+{
+	u32 val;
+
+	/* Disable user-space access to DCC */
+	val = MRC14(0, c0, c1, 0);
+	val |= 1 << 12; /* DSCR[Comms] */
+	MCR14(val, 0, c0, c1, 0);
+}
+
+#endif
arch/arm64/include/asm/dcc.h +11 -0
index 65e0190..cff9512 100644
@@ -52,4 +52,15 @@ static inline void __dcc_putchar(char c)
 	isb();
 }
 
+static inline void __dcc_initialize(void)
+{
+	u32 val;
+
+	/* Disable user-space access to DCC */
+	asm volatile ("mrs %0, mdscr_el1\n"
+		"	orr %0, %0, #4096\n" /* Set the TDCC bit */
+		"	msr mdscr_el1, %0\n"
+		: "=r" (val));
+}
+
 #endif
drivers/tty/hvc/hvc_dcc.c +2 -0
index 82f240f..14d4a473 100644
@@ -75,6 +75,8 @@ static int __init hvc_dcc_console_init(void)
 	if (!hvc_dcc_check())
 		return -ENODEV;
 
+	__dcc_initialize();
+
 	/* Returns -1 if error */
 	ret = hvc_instantiate(0, 0, &hvc_dcc_get_put_ops);
 
Signature · 3 lines
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.
#3 lore raw

PATCH v2 3/3 hvc_dcc: disable user-space access to DCC

Quoted 2 lines · Timur Tabi

If the DCC driver loads, then disable user-space access to the DCC so that we don't have two entities trying to access the DCC at the same time.

In the interests of making some headway with this, just drop this patch and I'll queue the diff below via the arm64 tree.

Will

--->8

arch/arm64/mm/proc.S +1 -1
index 39139a3aa16d..4c922ecce600 100644
@@ -156,7 +156,7 @@ ENTRY(__cpu_setup)
 
 	mov	x0, #3 << 20
 	msr	cpacr_el1, x0			// Enable FP/ASIMD
-	msr	mdscr_el1, xzr			// Reset mdscr_el1
+	msr	mdscr_el1, #1 << 12		// Reset mdscr_el1
 	/*
 	 * Memory region attributes for LPAE:
 	 *
maintainer
#4 lore raw

PATCH v2 3/3 hvc_dcc: disable user-space access to DCC

Quoted 16 lines · Will Deacon
Quoted 2 lines · Timur Tabi

If the DCC driver loads, then disable user-space access to the DCC so that we don't have two entities trying to access the DCC at the same time.

In the interests of making some headway with this, just drop this patch and I'll queue the diff below via the arm64 tree.

Will

--->8

arch/arm64/mm/proc.S +0 -0
index 39139a3aa16d..4c922ecce600 100644

arch/arm64/mm/proc.S ENTRY(__cpu_setup) · line 159

Quoted 5 lines
arch/arm64/mm/proc.S +1 -1
@@ -156,7 +156,7 @@ ENTRY(__cpu_setup)
 
 	mov	x0, #3 << 20
 	msr	cpacr_el1, x0			// Enable FP/ASIMD
-	msr	mdscr_el1, xzr			// Reset mdscr_el1
+	msr	mdscr_el1, #1 << 12		// Reset mdscr_el1

Nitpick: expand the "Reset..." comment to include some text about this bit.

Signature · 1 line
Catalin
author
#5 lore raw

PATCH v2 3/3 hvc_dcc: disable user-space access to DCC

In reply to Will Deacon
Quoted 5 lines · Will Deacon
Quoted 2 lines

If the DCC driver loads, then disable user-space access to the DCC so that

Quoted 1 line

we don't have two entities trying to access the DCC at the same time.

In the interests of making some headway with this, just drop this patch and I'll queue the diff below via the arm64 tree.

Yes, that would be great. Thank you.

Signature · 3 lines
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.