Skip to contentSkip to conversation

TTY: hvc_dcc: probe for a JTAG connection before registering

PATCH Superseded Rob Herring 3 participants 7 messages Sep 23, 2013 – Oct 17, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 TTY: hvc_dcc: probe for a JTAG connection before registering

From: Rob Herring <[email protected]>

Enabling the ARM DCC console and using without a JTAG connection will simply hang the system. Since distros like to turn on all options, this is a reoccurring problem to debug. We can do better by checking if anything is attached and handling characters. There is no way to probe this, so send a newline and check that it is handled.

Cc Paolo Pisati <[email protected]>
Cc Tim Gardner <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
---
 drivers/tty/hvc/hvc_dcc.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/tty/hvc/hvc_dcc.c +21 -0
index 44fbeba..44c8aff 100644
@@ -86,6 +86,21 @@ static int hvc_dcc_get_chars(uint32_t vt, char *buf, int count)
 	return i;
 }
 
+static bool hvc_dcc_check(void)
+{
+	unsigned long time = jiffies;
+
+	/* Write a test character to check if it is handled */
+	__dcc_putchar('\n');
+
+	while (jiffies < time + (HZ / 10)) {
+		if (!(__dcc_getstatus() & DCC_STATUS_TX))
+			return true;
+	}
+
+	return false;
+}
+
 static const struct hv_ops hvc_dcc_get_put_ops = {
 	.get_chars = hvc_dcc_get_chars,
 	.put_chars = hvc_dcc_put_chars,
@@ -93,6 +108,9 @@ static const struct hv_ops hvc_dcc_get_put_ops = {
 
 static int __init hvc_dcc_console_init(void)
 {
+	if (!hvc_dcc_check())
+		return -ENODEV;
+
 	hvc_instantiate(0, 0, &hvc_dcc_get_put_ops);
 	return 0;
 }
@@ -100,6 +118,9 @@ console_initcall(hvc_dcc_console_init);
 
 static int __init hvc_dcc_init(void)
 {
+	if (!hvc_dcc_check())
+		return -ENODEV;
+
 	hvc_alloc(0, 0, &hvc_dcc_get_put_ops, 128);
 	return 0;
 }
Signature · 1 line
1.8.1.2
#1 lore raw
Quoted 26 lines · Rob Herring

From: Rob Herring <[email protected]>

Enabling the ARM DCC console and using without a JTAG connection will simply hang the system. Since distros like to turn on all options, this is a reoccurring problem to debug. We can do better by checking if anything is attached and handling characters. There is no way to probe this, so send a newline and check that it is handled.

Cc Paolo Pisati <[email protected]>
Cc Tim Gardner <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
---
 drivers/tty/hvc/hvc_dcc.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/tty/hvc/hvc_dcc.c +1 -0
index 44fbeba..44c8aff 100644
@@ -86,6 +86,21 @@ static int hvc_dcc_get_chars(uint32_t vt, char *buf, int count)
 	return i;
 }
 
+static bool hvc_dcc_check(void)

drivers/tty/hvc/hvc_dcc.c static int hvc_dcc_get_chars(uint32_t vt, char *buf, int count) · line 99

Quoted 10 lines
drivers/tty/hvc/hvc_dcc.c +10 -0
+{
+	unsigned long time = jiffies;
+
+	/* Write a test character to check if it is handled */
+	__dcc_putchar('\n');
+
+	while (jiffies < time + (HZ / 10)) {
+		if (!(__dcc_getstatus() & DCC_STATUS_TX))
+			return true;
+	}

I think you should use one of the jiffies time comparison functions, e.g.,

	time = jiffies + (HZ / 10);
	while (time_before(jiffies,time) {
		...
	}

What is the possibility that __dcc_getstatus() will return garbage if no JTAG is connected ? In that event you're likely to get a false positive on DCC_STATUS_TX.

rtg

Signature · 1 line
Tim Gardner tim.gardner at canonical.com
#2 lore raw
Quoted 40 lines · Tim Gardner
Quoted 26 lines · Rob Herring

From: Rob Herring <[email protected]>

Enabling the ARM DCC console and using without a JTAG connection will simply hang the system. Since distros like to turn on all options, this is a reoccurring problem to debug. We can do better by checking if anything is attached and handling characters. There is no way to probe this, so send a newline and check that it is handled.

Cc Paolo Pisati <[email protected]>
Cc Tim Gardner <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
---
 drivers/tty/hvc/hvc_dcc.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/tty/hvc/hvc_dcc.c +1 -0
index 44fbeba..44c8aff 100644
@@ -86,6 +86,21 @@ static int hvc_dcc_get_chars(uint32_t vt, char *buf, int count)
 	return i;
 }
 
+static bool hvc_dcc_check(void)

drivers/tty/hvc/hvc_dcc.c static int hvc_dcc_get_chars(uint32_t vt, char *buf, int count) · line 99

Quoted 10 lines
drivers/tty/hvc/hvc_dcc.c +10 -0
+{
+	unsigned long time = jiffies;
+
+	/* Write a test character to check if it is handled */
+	__dcc_putchar('\n');
+
+	while (jiffies < time + (HZ / 10)) {
+		if (!(__dcc_getstatus() & DCC_STATUS_TX))
+			return true;
+	}

I think you should use one of the jiffies time comparison functions, e.g.,

Quoted 4 lines
	time = jiffies + (HZ / 10);
	while (time_before(jiffies,time) {
		...
	}

Yes.

Quoted 4 lines

What is the possibility that __dcc_getstatus() will return garbage if no JTAG is connected ? In that event you're likely to get a false positive on DCC_STATUS_TX.

That probably would not be architecturally compliant. The status bits are cleared by JTAG reading the read side of the register. If the bit stays set, we'll return false. If the bit is always clear, then we wouldn't hang in the first place and should be fine. If you get random values, then I'm sorry and good luck. You are still no worse off than before this patch.

Rob

#3 lore raw

PATCH v2 1/1 TTY: hvc_dcc: probe for a JTAG connection before registering

In reply to Rob Herring

From: Rob Herring <[email protected]>

Enabling the ARM DCC console and using without a JTAG connection will simply hang the system. Since distros like to turn on all options, this is a reoccurring problem to debug. We can do better by checking if anything is attached and handling characters. There is no way to probe this, so send a newline and check that it is handled.

Cc Paolo Pisati <[email protected]>
Cc Tim Gardner <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>

---
v2: use time_is_after_jiffies

 drivers/tty/hvc/hvc_dcc.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/tty/hvc/hvc_dcc.c +21 -0
index 44fbeba..3502a7b 100644
@@ -86,6 +86,21 @@ static int hvc_dcc_get_chars(uint32_t vt, char *buf, int count)
 	return i;
 }
 
+static bool hvc_dcc_check(void)
+{
+	unsigned long time = jiffies + (HZ / 10);
+
+	/* Write a test character to check if it is handled */
+	__dcc_putchar('\n');
+
+	while (time_is_after_jiffies(time)) {
+		if (!(__dcc_getstatus() & DCC_STATUS_TX))
+			return true;
+	}
+
+	return false;
+}
+
 static const struct hv_ops hvc_dcc_get_put_ops = {
 	.get_chars = hvc_dcc_get_chars,
 	.put_chars = hvc_dcc_put_chars,
@@ -93,6 +108,9 @@ static const struct hv_ops hvc_dcc_get_put_ops = {
 
 static int __init hvc_dcc_console_init(void)
 {
+	if (!hvc_dcc_check())
+		return -ENODEV;
+
 	hvc_instantiate(0, 0, &hvc_dcc_get_put_ops);
 	return 0;
 }
@@ -100,6 +118,9 @@ console_initcall(hvc_dcc_console_init);
 
 static int __init hvc_dcc_init(void)
 {
+	if (!hvc_dcc_check())
+		return -ENODEV;
+
 	hvc_alloc(0, 0, &hvc_dcc_get_put_ops, 128);
 	return 0;
 }
Signature · 1 line
1.8.1.2
#4 lore raw
Quoted 13 lines · Rob Herring

From: Rob Herring <[email protected]>

Enabling the ARM DCC console and using without a JTAG connection will simply hang the system. Since distros like to turn on all options, this is a reoccurring problem to debug. We can do better by checking if anything is attached and handling characters. There is no way to probe this, so send a newline and check that it is handled.

Cc Paolo Pisati <[email protected]>
Cc Tim Gardner <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>
Quoted 5 lines

---
v2: use time_is_after_jiffies

 drivers/tty/hvc/hvc_dcc.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Greg, Jiri,

Can you please apply.

Rob

Quoted 50 lines
drivers/tty/hvc/hvc_dcc.c +21 -1
index 44fbeba..3502a7b 100644
@@ -86,6 +86,21 @@ static int hvc_dcc_get_chars(uint32_t vt, char *buf, int count)
        return i;
 }
 
+static bool hvc_dcc_check(void)
+{
+       unsigned long time = jiffies + (HZ / 10);
+
+       /* Write a test character to check if it is handled */
+       __dcc_putchar('\n');
+
+       while (time_is_after_jiffies(time)) {
+               if (!(__dcc_getstatus() & DCC_STATUS_TX))
+                       return true;
+       }
+
+       return false;
+}
+
 static const struct hv_ops hvc_dcc_get_put_ops = {
        .get_chars = hvc_dcc_get_chars,
        .put_chars = hvc_dcc_put_chars,
@@ -93,6 +108,9 @@ static const struct hv_ops hvc_dcc_get_put_ops = {
 
 static int __init hvc_dcc_console_init(void)
 {
+       if (!hvc_dcc_check())
+               return -ENODEV;
+
        hvc_instantiate(0, 0, &hvc_dcc_get_put_ops);
        return 0;
 }
@@ -100,6 +118,9 @@ console_initcall(hvc_dcc_console_init);
 
 static int __init hvc_dcc_init(void)
 {
+       if (!hvc_dcc_check())
+               return -ENODEV;
+
        hvc_alloc(0, 0, &hvc_dcc_get_put_ops, 128);
        return 0;
 }
--

1.8.1.2

#5 lore raw
Quoted 17 lines · Rob Herring
Quoted 16 lines · Rob Herring

From: Rob Herring <[email protected]>

Enabling the ARM DCC console and using without a JTAG connection will simply hang the system. Since distros like to turn on all options, this is a reoccurring problem to debug. We can do better by checking if anything is attached and handling characters. There is no way to probe this, so send a newline and check that it is handled.

Cc Paolo Pisati <[email protected]>
Cc Tim Gardner <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>

---
v2: use time_is_after_jiffies

Quoted 6 lines
Quoted 2 lines
 drivers/tty/hvc/hvc_dcc.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Greg, Jiri,

Can you please apply.

I already did, didn't you get an email saying it was applied to my tree?

#6 lore raw
Quoted 18 lines · Greg Kroah-Hartman
Quoted 17 lines · Rob Herring
Quoted 16 lines · Rob Herring

From: Rob Herring <[email protected]>

Enabling the ARM DCC console and using without a JTAG connection will simply hang the system. Since distros like to turn on all options, this is a reoccurring problem to debug. We can do better by checking if anything is attached and handling characters. There is no way to probe this, so send a newline and check that it is handled.

Cc Paolo Pisati <[email protected]>
Cc Tim Gardner <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Jiri Slaby <[email protected]>

---
v2: use time_is_after_jiffies

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
 drivers/tty/hvc/hvc_dcc.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Greg, Jiri,

Can you please apply.

I already did, didn't you get an email saying it was applied to my tree?

Ah, yes. Found it buried in my work email. Sorry about that.

Rob