Josh Boyer 35ceed
Path: news.gmane.org!not-for-mail
Josh Boyer 35ceed
From: Adam Jackson <ajax@redhat.com>
Josh Boyer 35ceed
Newsgroups: gmane.linux.kernel
Josh Boyer 35ceed
Subject: [PATCH] vt: Drop K_OFF for VC_MUTE
Josh Boyer 35ceed
Date: Fri, 16 Nov 2012 13:32:34 -0500
Josh Boyer 35ceed
Lines: 205
Josh Boyer 35ceed
Approved: news@gmane.org
Josh Boyer 35ceed
Message-ID: <1353090754-30233-1-git-send-email-ajax@redhat.com>
Josh Boyer 35ceed
NNTP-Posting-Host: plane.gmane.org
Josh Boyer 35ceed
X-Trace: ger.gmane.org 1353090772 20663 80.91.229.3 (16 Nov 2012 18:32:52 GMT)
Josh Boyer 35ceed
X-Complaints-To: usenet@ger.gmane.org
Josh Boyer 35ceed
NNTP-Posting-Date: Fri, 16 Nov 2012 18:32:52 +0000 (UTC)
Josh Boyer 35ceed
Cc: Arthur Taylor <art@ified.ca>,
Josh Boyer 35ceed
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Josh Boyer 35ceed
To: linux-kernel@vger.kernel.org
Josh Boyer 35ceed
Original-X-From: linux-kernel-owner@vger.kernel.org Fri Nov 16 19:33:03 2012
Josh Boyer 35ceed
Return-path: <linux-kernel-owner@vger.kernel.org>
Josh Boyer 35ceed
Envelope-to: glk-linux-kernel-3@plane.gmane.org
Josh Boyer 35ceed
Original-Received: from vger.kernel.org ([209.132.180.67])
Josh Boyer 35ceed
	by plane.gmane.org with esmtp (Exim 4.69)
Josh Boyer 35ceed
	(envelope-from <linux-kernel-owner@vger.kernel.org>)
Josh Boyer 35ceed
	id 1TZQim-0000aG-BI
Josh Boyer 35ceed
	for glk-linux-kernel-3@plane.gmane.org; Fri, 16 Nov 2012 19:32:56 +0100
Josh Boyer 35ceed
Original-Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
Josh Boyer 35ceed
	id S1753232Ab2KPSck (ORCPT <rfc822;glk-linux-kernel-3@m.gmane.org>);
Josh Boyer 35ceed
	Fri, 16 Nov 2012 13:32:40 -0500
Josh Boyer 35ceed
Original-Received: from mx1.redhat.com ([209.132.183.28]:32172 "EHLO mx1.redhat.com"
Josh Boyer 35ceed
	rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
Josh Boyer 35ceed
	id S1752810Ab2KPSci (ORCPT <rfc822;linux-kernel@vger.kernel.org>);
Josh Boyer 35ceed
	Fri, 16 Nov 2012 13:32:38 -0500
Josh Boyer 35ceed
Original-Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])
Josh Boyer 35ceed
	by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qAGIWaM7020116
Josh Boyer 35ceed
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);
Josh Boyer 35ceed
	Fri, 16 Nov 2012 13:32:36 -0500
Josh Boyer 35ceed
Original-Received: from ihatethathostname.lab.bos.redhat.com (ihatethathostname.lab.bos.redhat.com [10.16.43.238])
Josh Boyer 35ceed
	by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qAGIWZD7010099;
Josh Boyer 35ceed
	Fri, 16 Nov 2012 13:32:35 -0500
Josh Boyer 35ceed
X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11
Josh Boyer 35ceed
Original-Sender: linux-kernel-owner@vger.kernel.org
Josh Boyer 35ceed
Precedence: bulk
Josh Boyer 35ceed
List-ID: <linux-kernel.vger.kernel.org>
Josh Boyer 35ceed
X-Mailing-List: linux-kernel@vger.kernel.org
Josh Boyer 35ceed
Xref: news.gmane.org gmane.linux.kernel:1395620
Josh Boyer 35ceed
Archived-At: <http://permalink.gmane.org/gmane.linux.kernel/1395620>
Josh Boyer 35ceed
Josh Boyer 35ceed
The "don't enqueue stuff" semantics of K_OFF shouldn't be a function of
Josh Boyer 35ceed
the keyboard map state; we should be able to switch among cooked/raw/
Josh Boyer 35ceed
unicode without changing whether events are delivered.  Otherwise - if
Josh Boyer 35ceed
changing to K_UNICODE undoes K_OFF - then suddenly Alt-F2 under
Josh Boyer 35ceed
Gnome will switch VT instead of summoning the "run command" dialog.
Josh Boyer 35ceed
Josh Boyer 35ceed
Drop the K_OFF handling and replace it with a new "mute" ioctl pair.
Josh Boyer 35ceed
Anybody using K_OFF would already need to be prepared to handle it
Josh Boyer 35ceed
throwing -EINVAL for old kernel compatibility, so userspace will degrade
Josh Boyer 35ceed
gracefully.
Josh Boyer 35ceed
Josh Boyer 35ceed
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=859485
Josh Boyer 35ceed
Cc: Arthur Taylor <art@ified.ca>
Josh Boyer 35ceed
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Josh Boyer 35ceed
Tested-by: Josh Boyer <jwboyer@redhat.com>
Josh Boyer 35ceed
Signed-off-by: Adam Jackson <ajax@redhat.com>
Josh Boyer 35ceed
---
Josh Boyer 35ceed
 drivers/tty/vt/keyboard.c | 40 +++++++++++++++++++++++++++++++++-------
Josh Boyer 35ceed
 drivers/tty/vt/vt_ioctl.c | 13 +++++++++++++
Josh Boyer 35ceed
 include/linux/kbd_kern.h  |  6 +++---
Josh Boyer 35ceed
 include/linux/vt_kern.h   |  2 ++
Josh Boyer 35ceed
 include/uapi/linux/kd.h   |  5 +++++
Josh Boyer 35ceed
 5 files changed, 56 insertions(+), 10 deletions(-)
Josh Boyer 35ceed
Josh Boyer 35ceed
diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
Josh Boyer 35ceed
index 681765b..08d1d57 100644
Josh Boyer 35ceed
--- a/drivers/tty/vt/keyboard.c
Josh Boyer 35ceed
+++ b/drivers/tty/vt/keyboard.c
Josh Boyer 35ceed
@@ -657,7 +657,7 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
Josh Boyer 35ceed
 		return;
Josh Boyer 35ceed
 	if ((kbd->kbdmode == VC_RAW ||
Josh Boyer 35ceed
 	     kbd->kbdmode == VC_MEDIUMRAW ||
Josh Boyer 35ceed
-	     kbd->kbdmode == VC_OFF) &&
Josh Boyer 35ceed
+	     vc_kbd_mode(kbd, VC_MUTE)) &&
Josh Boyer 35ceed
 	     value != KVAL(K_SAK))
Josh Boyer 35ceed
 		return;		/* SAK is allowed even in raw mode */
Josh Boyer 35ceed
 	fn_handler[value](vc);
Josh Boyer 35ceed
@@ -1381,7 +1381,7 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw)
Josh Boyer 35ceed
 	if (rc == NOTIFY_STOP)
Josh Boyer 35ceed
 		return;
Josh Boyer 35ceed
 
Josh Boyer 35ceed
-	if ((raw_mode || kbd->kbdmode == VC_OFF) && type != KT_SPEC && type != KT_SHIFT)
Josh Boyer 35ceed
+	if ((raw_mode || vc_kbd_mode(kbd, VC_MUTE)) && type != KT_SPEC && type != KT_SHIFT)
Josh Boyer 35ceed
 		return;
Josh Boyer 35ceed
 
Josh Boyer 35ceed
 	(*k_handler[type])(vc, keysym & 0xff, !down);
Josh Boyer 35ceed
@@ -1731,9 +1731,6 @@ int vt_do_kdskbmode(int console, unsigned int arg)
Josh Boyer 35ceed
 		kbd->kbdmode = VC_UNICODE;
Josh Boyer 35ceed
 		do_compute_shiftstate();
Josh Boyer 35ceed
 		break;
Josh Boyer 35ceed
-	case K_OFF:
Josh Boyer 35ceed
-		kbd->kbdmode = VC_OFF;
Josh Boyer 35ceed
-		break;
Josh Boyer 35ceed
 	default:
Josh Boyer 35ceed
 		ret = -EINVAL;
Josh Boyer 35ceed
 	}
Josh Boyer 35ceed
@@ -1742,6 +1739,30 @@ int vt_do_kdskbmode(int console, unsigned int arg)
Josh Boyer 35ceed
 }
Josh Boyer 35ceed
 
Josh Boyer 35ceed
 /**
Josh Boyer 35ceed
+ *	vt_do_kdskbmute		-	set keyboard event mute
Josh Boyer 35ceed
+ *	@console: the console to use
Josh Boyer 35ceed
+ *	@arg: the requested mode
Josh Boyer 35ceed
+ *
Josh Boyer 35ceed
+ *	Update the keyboard mute state while holding the correct locks.
Josh Boyer 35ceed
+ *	Return 0 for success or an error code.
Josh Boyer 35ceed
+ */
Josh Boyer 35ceed
+int vt_do_kdskbmute(int console, unsigned int arg)
Josh Boyer 35ceed
+{
Josh Boyer 35ceed
+	struct kbd_struct * kbd = kbd_table + console;
Josh Boyer 35ceed
+	int ret = 0;
Josh Boyer 35ceed
+	unsigned long flags;
Josh Boyer 35ceed
+
Josh Boyer 35ceed
+	spin_lock_irqsave(&kbd_event_lock, flags);
Josh Boyer 35ceed
+	if (arg)
Josh Boyer 35ceed
+		set_vc_kbd_mode(kbd, VC_MUTE);
Josh Boyer 35ceed
+	else
Josh Boyer 35ceed
+		clr_vc_kbd_mode(kbd, VC_MUTE);
Josh Boyer 35ceed
+	spin_unlock_irqrestore(&kbd_event_lock, flags);
Josh Boyer 35ceed
+	return ret;
Josh Boyer 35ceed
+}
Josh Boyer 35ceed
+
Josh Boyer 35ceed
+
Josh Boyer 35ceed
+/**
Josh Boyer 35ceed
  *	vt_do_kdskbmeta		-	set keyboard meta state
Josh Boyer 35ceed
  *	@console: the console to use
Josh Boyer 35ceed
  *	@arg: the requested meta state
Josh Boyer 35ceed
@@ -2068,13 +2089,18 @@ int vt_do_kdgkbmode(int console)
Josh Boyer 35ceed
 		return K_MEDIUMRAW;
Josh Boyer 35ceed
 	case VC_UNICODE:
Josh Boyer 35ceed
 		return K_UNICODE;
Josh Boyer 35ceed
-	case VC_OFF:
Josh Boyer 35ceed
-		return K_OFF;
Josh Boyer 35ceed
 	default:
Josh Boyer 35ceed
 		return K_XLATE;
Josh Boyer 35ceed
 	}
Josh Boyer 35ceed
 }
Josh Boyer 35ceed
 
Josh Boyer 35ceed
+int vt_do_kdgkbmute(int console)
Josh Boyer 35ceed
+{
Josh Boyer 35ceed
+	struct kbd_struct * kbd = kbd_table + console;
Josh Boyer 35ceed
+	/* This is a spot read so needs no locking */
Josh Boyer 35ceed
+	return vc_kbd_mode(kbd, VC_MUTE);
Josh Boyer 35ceed
+}
Josh Boyer 35ceed
+
Josh Boyer 35ceed
 /**
Josh Boyer 35ceed
  *	vt_do_kdgkbmeta		-	report meta status
Josh Boyer 35ceed
  *	@console: console to report
Josh Boyer 35ceed
diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
Josh Boyer 35ceed
index b841f56..f0951e2 100644
Josh Boyer 35ceed
--- a/drivers/tty/vt/vt_ioctl.c
Josh Boyer 35ceed
+++ b/drivers/tty/vt/vt_ioctl.c
Josh Boyer 35ceed
@@ -477,6 +477,19 @@ int vt_ioctl(struct tty_struct *tty,
Josh Boyer 35ceed
 		ret = put_user(uival, (int __user *)arg);
Josh Boyer 35ceed
 		break;
Josh Boyer 35ceed
 
Josh Boyer 35ceed
+	case KDSKBMUTE:
Josh Boyer 35ceed
+		if (!perm)
Josh Boyer 35ceed
+			return -EPERM;
Josh Boyer 35ceed
+		ret = vt_do_kdskbmute(console, arg);
Josh Boyer 35ceed
+		if (ret == 0)
Josh Boyer 35ceed
+			tty_ldisc_flush(tty);
Josh Boyer 35ceed
+		break;
Josh Boyer 35ceed
+
Josh Boyer 35ceed
+	case KDGKBMUTE:
Josh Boyer 35ceed
+		uival = vt_do_kdgkbmute(console);
Josh Boyer 35ceed
+		ret = put_user(uival, (int __user *)arg);
Josh Boyer 35ceed
+		break;
Josh Boyer 35ceed
+
Josh Boyer 35ceed
 	/* this could be folded into KDSKBMODE, but for compatibility
Josh Boyer 35ceed
 	   reasons it is not so easy to fold KDGKBMETA into KDGKBMODE */
Josh Boyer 35ceed
 	case KDSKBMETA:
Josh Boyer 35ceed
diff --git a/include/linux/kbd_kern.h b/include/linux/kbd_kern.h
Josh Boyer 35ceed
index b7c8cdc..9386143 100644
Josh Boyer 35ceed
--- a/include/linux/kbd_kern.h
Josh Boyer 35ceed
+++ b/include/linux/kbd_kern.h
Josh Boyer 35ceed
@@ -48,19 +48,19 @@ struct kbd_struct {
Josh Boyer 35ceed
 #define VC_CAPSLOCK	2	/* capslock mode */
Josh Boyer 35ceed
 #define VC_KANALOCK	3	/* kanalock mode */
Josh Boyer 35ceed
 
Josh Boyer 35ceed
-	unsigned char kbdmode:3;	/* one 3-bit value */
Josh Boyer 35ceed
+	unsigned char kbdmode:2;	/* one 2-bit value */
Josh Boyer 35ceed
 #define VC_XLATE	0	/* translate keycodes using keymap */
Josh Boyer 35ceed
 #define VC_MEDIUMRAW	1	/* medium raw (keycode) mode */
Josh Boyer 35ceed
 #define VC_RAW		2	/* raw (scancode) mode */
Josh Boyer 35ceed
 #define VC_UNICODE	3	/* Unicode mode */
Josh Boyer 35ceed
-#define VC_OFF		4	/* disabled mode */
Josh Boyer 35ceed
 
Josh Boyer 35ceed
-	unsigned char modeflags:5;
Josh Boyer 35ceed
+	unsigned char modeflags:6;
Josh Boyer 35ceed
 #define VC_APPLIC	0	/* application key mode */
Josh Boyer 35ceed
 #define VC_CKMODE	1	/* cursor key mode */
Josh Boyer 35ceed
 #define VC_REPEAT	2	/* keyboard repeat */
Josh Boyer 35ceed
 #define VC_CRLF		3	/* 0 - enter sends CR, 1 - enter sends CRLF */
Josh Boyer 35ceed
 #define VC_META		4	/* 0 - meta, 1 - meta=prefix with ESC */
Josh Boyer 35ceed
+#define VC_MUTE		5	/* don't generate events */
Josh Boyer 35ceed
 };
Josh Boyer 35ceed
 
Josh Boyer 35ceed
 extern int kbd_init(void);
Josh Boyer 35ceed
diff --git a/include/linux/vt_kern.h b/include/linux/vt_kern.h
Josh Boyer 35ceed
index 50ae7d0..a886915 100644
Josh Boyer 35ceed
--- a/include/linux/vt_kern.h
Josh Boyer 35ceed
+++ b/include/linux/vt_kern.h
Josh Boyer 35ceed
@@ -168,6 +168,7 @@ extern void hide_boot_cursor(bool hide);
Josh Boyer 35ceed
 
Josh Boyer 35ceed
 /* keyboard  provided interfaces */
Josh Boyer 35ceed
 extern int vt_do_diacrit(unsigned int cmd, void __user *up, int eperm);
Josh Boyer 35ceed
+extern int vt_do_kdskbmute(int console, unsigned int arg);
Josh Boyer 35ceed
 extern int vt_do_kdskbmode(int console, unsigned int arg);
Josh Boyer 35ceed
 extern int vt_do_kdskbmeta(int console, unsigned int arg);
Josh Boyer 35ceed
 extern int vt_do_kbkeycode_ioctl(int cmd, struct kbkeycode __user *user_kbkc,
Josh Boyer 35ceed
@@ -177,6 +178,7 @@ extern int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe,
Josh Boyer 35ceed
 extern int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb,
Josh Boyer 35ceed
                                         int perm);
Josh Boyer 35ceed
 extern int vt_do_kdskled(int console, int cmd, unsigned long arg, int perm);
Josh Boyer 35ceed
+extern int vt_do_kdgkbmute(int console);
Josh Boyer 35ceed
 extern int vt_do_kdgkbmode(int console);
Josh Boyer 35ceed
 extern int vt_do_kdgkbmeta(int console);
Josh Boyer 35ceed
 extern void vt_reset_unicode(int console);
Josh Boyer 35ceed
diff --git a/include/uapi/linux/kd.h b/include/uapi/linux/kd.h
Josh Boyer 35ceed
index 87b7cc4..c3de63c 100644
Josh Boyer 35ceed
--- a/include/uapi/linux/kd.h
Josh Boyer 35ceed
+++ b/include/uapi/linux/kd.h
Josh Boyer 35ceed
@@ -81,6 +81,7 @@ struct unimapinit {
Josh Boyer 35ceed
 #define		K_XLATE		0x01
Josh Boyer 35ceed
 #define		K_MEDIUMRAW	0x02
Josh Boyer 35ceed
 #define		K_UNICODE	0x03
Josh Boyer 35ceed
+/* K_OFF is no longer implemented, but preserved for source compatibility */
Josh Boyer 35ceed
 #define		K_OFF		0x04
Josh Boyer 35ceed
 #define KDGKBMODE	0x4B44	/* gets current keyboard mode */
Josh Boyer 35ceed
 #define KDSKBMODE	0x4B45	/* sets current keyboard mode */
Josh Boyer 35ceed
@@ -150,6 +151,10 @@ struct kbd_repeat {
Josh Boyer 35ceed
 			/* earlier this field was misnamed "rate" */
Josh Boyer 35ceed
 };
Josh Boyer 35ceed
 
Josh Boyer 35ceed
+/* get/set event mute */
Josh Boyer 35ceed
+#define KDGKBMUTE	0x4B50
Josh Boyer 35ceed
+#define KDSKBMUTE	0x4B51
Josh Boyer 35ceed
+
Josh Boyer 35ceed
 #define KDKBDREP        0x4B52  /* set keyboard delay/repeat rate;
Josh Boyer 35ceed
 				 * actually used values are returned */
Josh Boyer 35ceed
 
Josh Boyer 35ceed
-- 
Josh Boyer 35ceed
1.7.11.7
Josh Boyer 35ceed