public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Console events and accessibility
@ 2007-08-21 21:29 Samuel Thibault
  2007-08-22  5:48 ` Greg KH
  0 siblings, 1 reply; 9+ messages in thread
From: Samuel Thibault @ 2007-08-21 21:29 UTC (permalink / raw)
  To: linux-kernel, akpm

Some external modules like Speakup need to monitor console output.

This adds a VT notifier that such modules can use to get console output events:
allocation, deallocation, writes, other updates (cursor position, switch, etc.)

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

---

This is the second hook for Speakup.  I've already set symbols exported
to GPL only.

diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index c20773a..8b87263 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -99,6 +99,7 @@
 #include <linux/pm.h>
 #include <linux/font.h>
 #include <linux/bitops.h>
+#include <linux/notifier.h>
 
 #include <asm/io.h>
 #include <asm/system.h>
@@ -223,6 +224,35 @@ enum {
 };
 
 /*
+ * Notifier list for console events.
+ */
+static ATOMIC_NOTIFIER_HEAD(vt_notifier_list);
+
+int register_vt_notifier(struct notifier_block *nb)
+{
+	return atomic_notifier_chain_register(&vt_notifier_list, nb);
+}
+EXPORT_SYMBOL_GPL(register_vt_notifier);
+
+int unregister_vt_notifier(struct notifier_block *nb)
+{
+	return atomic_notifier_chain_unregister(&vt_notifier_list, nb);
+}
+EXPORT_SYMBOL_GPL(unregister_vt_notifier);
+
+static void notify_write(struct vc_data *vc, unsigned int unicode)
+{
+	struct vt_notifier_param param = { .vc = vc, unicode = unicode };
+	atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param);
+}
+
+static void notify_update(struct vc_data *vc)
+{
+	struct vt_notifier_param param = { .vc = vc };
+	atomic_notifier_call_chain(&vt_notifier_list, VT_UPDATE, &param);
+}
+
+/*
  *	Low-Level Functions
  */
 
@@ -718,6 +748,7 @@ int vc_allocate(unsigned int currcons)	/* return 0 on success */
 		return -ENXIO;
 	if (!vc_cons[currcons].d) {
 	    struct vc_data *vc;
+	    struct vt_notifier_param param;
 
 	    /* prevent users from taking too much memory */
 	    if (currcons >= MAX_NR_USER_CONSOLES && !capable(CAP_SYS_RESOURCE))
@@ -729,7 +760,7 @@ int vc_allocate(unsigned int currcons)	/* return 0 on success */
 	    /* although the numbers above are not valid since long ago, the
 	       point is still up-to-date and the comment still has its value
 	       even if only as a historical artifact.  --mj, July 1998 */
-	    vc = kzalloc(sizeof(struct vc_data), GFP_KERNEL);
+	    param.vc = vc = kzalloc(sizeof(struct vc_data), GFP_KERNEL);
 	    if (!vc)
 		return -ENOMEM;
 	    vc_cons[currcons].d = vc;
@@ -746,6 +777,7 @@ int vc_allocate(unsigned int currcons)	/* return 0 on success */
 	    }
 	    vc->vc_kmalloced = 1;
 	    vc_init(vc, vc->vc_rows, vc->vc_cols, 1);
+	    atomic_notifier_call_chain(&vt_notifier_list, VT_ALLOCATE, &param);
 	}
 	return 0;
 }
@@ -902,6 +934,8 @@ void vc_deallocate(unsigned int currcons)
 
 	if (vc_cons_allocated(currcons)) {
 		struct vc_data *vc = vc_cons[currcons].d;
+		struct vt_notifier_param param = { .vc = vc };
+		atomic_notifier_call_chain(&vt_notifier_list, VT_DEALLOCATE, &param);
 		vc->vc_sw->con_deinit(vc);
 		put_pid(vc->vt_pid);
 		module_put(vc->vc_sw->owner);
@@ -1014,6 +1048,7 @@ static void lf(struct vc_data *vc)
 		vc->vc_pos += vc->vc_size_row;
 	}
 	vc->vc_need_wrap = 0;
+	notify_write(vc, '\n');
 }
 
 static void ri(struct vc_data *vc)
@@ -1034,6 +1069,7 @@ static inline void cr(struct vc_data *vc)
 {
 	vc->vc_pos -= vc->vc_x << 1;
 	vc->vc_need_wrap = vc->vc_x = 0;
+	notify_write(vc, '\r');
 }
 
 static inline void bs(struct vc_data *vc)
@@ -1042,6 +1078,7 @@ static inline void bs(struct vc_data *vc)
 		vc->vc_pos -= 2;
 		vc->vc_x--;
 		vc->vc_need_wrap = 0;
+		notify_write(vc, '\b');
 	}
 }
 
@@ -1588,6 +1625,7 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c)
 				break;
 		}
 		vc->vc_pos += (vc->vc_x << 1);
+		notify_write(vc, '\t');
 		return;
 	case 10: case 11: case 12:
 		lf(vc);
@@ -2247,6 +2285,7 @@ rescan_last_byte:
 				tc = conv_uni_to_pc(vc, ' '); /* A space is printed in the second column */
 				if (tc < 0) tc = ' ';
 			}
+			notify_write(vc, c);
 
 			if (inverse) {
 				FLUSH
@@ -2269,6 +2308,7 @@ rescan_last_byte:
 	release_console_sem();
 
 out:
+	notify_update(vc);
 	return n;
 #undef FLUSH
 }
@@ -2312,6 +2352,7 @@ static void console_callback(struct work_struct *ignored)
 		do_blank_screen(0);
 		blank_timer_expired = 0;
 	}
+	notify_update(vc_cons[fg_console].d);
 
 	release_console_sem();
 }
@@ -2413,6 +2454,7 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
 				continue;
 		}
 		scr_writew((vc->vc_attr << 8) + c, (unsigned short *)vc->vc_pos);
+		notify_write(vc, c);
 		cnt++;
 		if (myx == vc->vc_cols - 1) {
 			vc->vc_need_wrap = 1;
@@ -2431,6 +2473,7 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
 		}
 	}
 	set_cursor(vc);
+	notify_update(vc);
 
 quit:
 	clear_bit(0, &printing);
diff --git a/include/linux/notifier.h b/include/linux/notifier.h
index bd37880..fb88436 100644
--- a/include/linux/notifier.h
+++ b/include/linux/notifier.h
@@ -240,5 +240,11 @@ static inline int notifier_to_errno(int ret)
 #define KBD_KEYSYM		0x0004 /* Keyboard keysym */
 #define KBD_POST_KEYSYM		0x0005 /* Called after keyboard keysym interpretation */
 
+/* Virtual Terminal events. */
+#define VT_ALLOCATE		0x0001 /* Console got allocated */
+#define VT_DEALLOCATE		0x0002 /* Console will be deallocated */
+#define VT_WRITE		0x0003 /* A char got output */
+#define VT_UPDATE		0x0004 /* A bigger update occurred */
+
 #endif /* __KERNEL__ */
 #endif /* _LINUX_NOTIFIER_H */
diff --git a/include/linux/vt.h b/include/linux/vt.h
index ba806e8..40216b0 100644
--- a/include/linux/vt.h
+++ b/include/linux/vt.h
@@ -1,6 +1,18 @@
 #ifndef _LINUX_VT_H
 #define _LINUX_VT_H
 
+#ifdef __KERNEL__
+#include <linux/notifier.h>
+
+struct vt_notifier_param {
+	struct vc_data *vc;	/* VC on which the update happened */
+	unsigned int c;		/* Printed char */
+};
+
+extern int register_vt_notifier(struct notifier_block *nb);
+extern int unregister_vt_notifier(struct notifier_block *nb);
+#endif
+
 /*
  * These constants are also useful for user-level apps (e.g., VC
  * resizing).

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] Console events and accessibility
  2007-08-21 21:29 [PATCH] Console events and accessibility Samuel Thibault
@ 2007-08-22  5:48 ` Greg KH
  2007-08-22  8:53   ` Samuel Thibault
  0 siblings, 1 reply; 9+ messages in thread
From: Greg KH @ 2007-08-22  5:48 UTC (permalink / raw)
  To: Samuel Thibault, linux-kernel, akpm

On Tue, Aug 21, 2007 at 11:29:39PM +0200, Samuel Thibault wrote:
> Some external modules like Speakup need to monitor console output.
> 
> This adds a VT notifier that such modules can use to get console output events:
> allocation, deallocation, writes, other updates (cursor position, switch, etc.)
> 
> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

Will speakup work with this kind of change?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Console events and accessibility
  2007-08-22  5:48 ` Greg KH
@ 2007-08-22  8:53   ` Samuel Thibault
  2007-08-22 13:05     ` Samuel Thibault
  0 siblings, 1 reply; 9+ messages in thread
From: Samuel Thibault @ 2007-08-22  8:53 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel, akpm

Greg KH, le Tue 21 Aug 2007 22:48:55 -0700, a écrit :
> On Tue, Aug 21, 2007 at 11:29:39PM +0200, Samuel Thibault wrote:
> > Some external modules like Speakup need to monitor console output.
> > 
> > This adds a VT notifier that such modules can use to get console output events:
> > allocation, deallocation, writes, other updates (cursor position, switch, etc.)
> > 
> > Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> 
> Will speakup work with this kind of change?

Here are the last needed bits.

Samuel

Export inverse_translate, kd_mksound and screen_glyph for speakup. Also
reserve KT_SPKUP.

diff --git a/drivers/char/consolemap.c b/drivers/char/consolemap.c
index 4b3916f..37c7980 100644
--- a/drivers/char/consolemap.c
+++ b/drivers/char/consolemap.c
@@ -277,6 +277,7 @@
 			return p->inverse_translations[m][glyph];
 	}
 }
+EXPORT_SYMBOL_GPL(inverse_translate);
 
 static void update_user_maps(void)
 {
--- a/drivers/char/keyboard.c
+++ b/drivers/char/keyboard.c
@@ -101,7 +101,7 @@
 const int max_vals[] = {
 	255, ARRAY_SIZE(func_table) - 1, ARRAY_SIZE(fn_handler) - 1, NR_PAD - 1,
 	NR_DEAD - 1, 255, 3, NR_SHIFT - 1, 255, NR_ASCII - 1, NR_LOCK - 1,
-	255, NR_LOCK - 1, 255, NR_BRL - 1
+	255, NR_LOCK - 1, 255, NR_BRL - 1, NR_SPKUP - 1
 };
 
 const int NR_TYPES = ARRAY_SIZE(max_vals);
@@ -240,6 +240,7 @@
 	} else
 		kd_nosound(0);
 }
+EXPORT_SYMBOL_GPL(kd_mksound);
 
 /*
  * Setting the keyboard rate.
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -3934,6 +3934,7 @@
 		c |= 0x100;
 	return c;
 }
+EXPORT_SYMBOL_GPL(screen_glyph);
 
 /* used by vcs - note the word offset */
 unsigned short *screen_pos(struct vc_data *vc, int w_offset, int viewed)
--- a/include/linux/keyboard.h
+++ b/include/linux/keyboard.h
@@ -45,6 +45,7 @@
 #define KT_LOCK		10
 #define KT_SLOCK	12
 #define KT_BRL		14
+#define KT_SPKUP	15
 
 #define K(t,v)		(((t)<<8)|(v))
 #define KTYP(x)		((x) >> 8)
@@ -442,5 +443,7 @@
 
 #define NR_BRL		11
 
+#define NR_SPKUP	0x56
+
 #define MAX_DIACR	256
 #endif

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] Console events and accessibility
  2007-08-22  8:53   ` Samuel Thibault
@ 2007-08-22 13:05     ` Samuel Thibault
  2007-08-23 10:04       ` Greg KH
  0 siblings, 1 reply; 9+ messages in thread
From: Samuel Thibault @ 2007-08-22 13:05 UTC (permalink / raw)
  To: Greg KH, linux-kernel, akpm

Samuel Thibault, le Wed 22 Aug 2007 10:53:55 +0200, a écrit :
> Greg KH, le Tue 21 Aug 2007 22:48:55 -0700, a écrit :
> > On Tue, Aug 21, 2007 at 11:29:39PM +0200, Samuel Thibault wrote:
> > > Some external modules like Speakup need to monitor console output.
> > > 
> > > This adds a VT notifier that such modules can use to get console output events:
> > > allocation, deallocation, writes, other updates (cursor position, switch, etc.)
> > > 
> > > Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> > 
> > Will speakup work with this kind of change?
> 
> Here are the last needed bits.

I mean: yes, with these three patches, speakup will work fine.

The biggest change we'll have to do in speakup is the way it accesses
the serial port, which is really dirty for now, but that's an internal
matter.

Samuel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Console events and accessibility
  2007-08-22 13:05     ` Samuel Thibault
@ 2007-08-23 10:04       ` Greg KH
  2007-08-23 11:30         ` Samuel Thibault
  0 siblings, 1 reply; 9+ messages in thread
From: Greg KH @ 2007-08-23 10:04 UTC (permalink / raw)
  To: Samuel Thibault, linux-kernel, akpm

On Wed, Aug 22, 2007 at 03:05:20PM +0200, Samuel Thibault wrote:
> Samuel Thibault, le Wed 22 Aug 2007 10:53:55 +0200, a ?crit :
> > Greg KH, le Tue 21 Aug 2007 22:48:55 -0700, a ?crit :
> > > On Tue, Aug 21, 2007 at 11:29:39PM +0200, Samuel Thibault wrote:
> > > > Some external modules like Speakup need to monitor console output.
> > > > 
> > > > This adds a VT notifier that such modules can use to get console output events:
> > > > allocation, deallocation, writes, other updates (cursor position, switch, etc.)
> > > > 
> > > > Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> > > 
> > > Will speakup work with this kind of change?
> > 
> > Here are the last needed bits.
> 
> I mean: yes, with these three patches, speakup will work fine.

3 patches?  I only saw 2.  Or do you mean the modifications of the 3
files?

The patches look sane but you should change the global symbols to play
nicer in the namespace.  Care to respin them together with this change?

> The biggest change we'll have to do in speakup is the way it accesses
> the serial port, which is really dirty for now, but that's an internal
> matter.

Yeah, that shouldn't be that tough to do.

It doesn't look like these changes handle scrolling of the console, do
they?  If so, don't you need to do more?  I had some old patches around
here that had devices that wanted to know cursor positioning, which I
don't think this hook can handle :(

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Console events and accessibility
  2007-08-23 10:04       ` Greg KH
@ 2007-08-23 11:30         ` Samuel Thibault
  2007-08-23 16:33           ` Greg KH
  0 siblings, 1 reply; 9+ messages in thread
From: Samuel Thibault @ 2007-08-23 11:30 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel, akpm

Greg KH, le Thu 23 Aug 2007 03:04:02 -0700, a écrit :
> > I mean: yes, with these three patches, speakup will work fine.
> 
> 3 patches?  I only saw 2.  Or do you mean the modifications of the 3
> files?

Maybe you missed the keyboard notification patch which is already in
-mm.

> The patches look sane but you should change the global symbols to play
> nicer in the namespace.  Care to respin them together with this change?

You mean inverse_translate and screen_glyph?

> > The biggest change we'll have to do in speakup is the way it accesses
> > the serial port, which is really dirty for now, but that's an internal
> > matter.
> 
> Yeah, that shouldn't be that tough to do.

Well, the biggest problem is that we'd like to output on serial _before_
/dev gets mounted.

> It doesn't look like these changes handle scrolling of the console, do
> they?

Ah, indeed, speakup doesn't seem to handle it, that's why I forgot it in
the patch.  I'll see what needs to be done.

Thanks,
Samuel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Console events and accessibility
  2007-08-23 11:30         ` Samuel Thibault
@ 2007-08-23 16:33           ` Greg KH
  2007-08-23 17:08             ` Samuel Thibault
  0 siblings, 1 reply; 9+ messages in thread
From: Greg KH @ 2007-08-23 16:33 UTC (permalink / raw)
  To: Samuel Thibault, linux-kernel, akpm

On Thu, Aug 23, 2007 at 01:30:35PM +0200, Samuel Thibault wrote:
> Greg KH, le Thu 23 Aug 2007 03:04:02 -0700, a ?crit :
> > > I mean: yes, with these three patches, speakup will work fine.
> > 
> > 3 patches?  I only saw 2.  Or do you mean the modifications of the 3
> > files?
> 
> Maybe you missed the keyboard notification patch which is already in
> -mm.

Yes I did, sorry.  Do you have a pointer for it, all I see is these
patches in -mm:
	console-keyboard-events-and-accessibility.patch
	console-keyboard-events-and-accessibility-fix.patch
	console-keyboard-events-and-accessibility-fix-2.patch

> > The patches look sane but you should change the global symbols to play
> > nicer in the namespace.  Care to respin them together with this change?
> 
> You mean inverse_translate and screen_glyph?

Yes.  Also, things like "register_keyboard_notifier" should be
"keyboard_register_notifer", trying to keep everything in the
"keyboard*" namespace to make things a bit easier overall[1].

> > > The biggest change we'll have to do in speakup is the way it accesses
> > > the serial port, which is really dirty for now, but that's an internal
> > > matter.
> > 
> > Yeah, that shouldn't be that tough to do.
> 
> Well, the biggest problem is that we'd like to output on serial _before_
> /dev gets mounted.

As we can do this today with the console layer (think boot consoles over
serial and network and even USB), it should not be that tough.  Just be
an early console yourself also.

> > It doesn't look like these changes handle scrolling of the console, do
> > they?
> 
> Ah, indeed, speakup doesn't seem to handle it, that's why I forgot it in
> the patch.  I'll see what needs to be done.

Does speakup need to handle it?  I know it's the most popular reader
package out there, but other people seem to have other screen readers
too, but I am in no position to evaluate if their hacks/patches are
really something that is needed here.

Also, we really would like to see the users of these hooks (meaning the
speakup drivers) go into the tree at the same time the hooks do, as we
don't like hooks with no users in the kernel.

I know the speakup code needs a lot of work to bring it up to
kernel-acceptance level.  Has this work been done, or is it happening?
If you need help in this area, I can see about doing a bit as I did a
lot of cleanup of this codebase a few years ago.  I also know of a few
users who are willing to help test this stuff out.

Anyway, thanks a lot for working to get this code into the main tree,
it's very useful to an important group of users.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Console events and accessibility
  2007-08-23 16:33           ` Greg KH
@ 2007-08-23 17:08             ` Samuel Thibault
  2007-08-23 17:51               ` Samuel Thibault
  0 siblings, 1 reply; 9+ messages in thread
From: Samuel Thibault @ 2007-08-23 17:08 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-kernel, akpm

Hi,

Greg KH, le Thu 23 Aug 2007 09:33:18 -0700, a écrit :
> Yes I did, sorry.  Do you have a pointer for it, all I see is these
> patches in -mm:
> 	console-keyboard-events-and-accessibility.patch

Here is the patch

> 	console-keyboard-events-and-accessibility-fix.patch
> 	console-keyboard-events-and-accessibility-fix-2.patch

These are just EXPORT_SYMBOL -> EXPORT_SYMBOL_GPL and #include fixes.

> > > The patches look sane but you should change the global symbols to play
> > > nicer in the namespace.  Care to respin them together with this change?
> > 
> > You mean inverse_translate and screen_glyph?
> 
> Yes.  Also, things like "register_keyboard_notifier" should be
> "keyboard_register_notifer", trying to keep everything in the
> "keyboard*" namespace to make things a bit easier overall[1].

Ok.

> > Well, the biggest problem is that we'd like to output on serial _before_
> > /dev gets mounted.
> 
> As we can do this today with the console layer (think boot consoles over
> serial and network and even USB), it should not be that tough.  Just be
> an early console yourself also.

Yes, that's on the plan too, but in some cases (like braille devices),
the driver needs to read from the port too, which is not provided by
early consoles.

> > > It doesn't look like these changes handle scrolling of the console, do
> > > they?
> > 
> > Ah, indeed, speakup doesn't seem to handle it, that's why I forgot it in
> > the patch.  I'll see what needs to be done.
> 
> Does speakup need to handle it?

I don't know exactly, but most probably yes, because else the cursor
position gets wrong.

> Also, we really would like to see the users of these hooks (meaning the
> speakup drivers) go into the tree at the same time the hooks do, as we
> don't like hooks with no users in the kernel.

OK.  Having my patches in the -mm tree for just some review time is
fine: at least we know that the way they're done is ok for people (or
else we're told how to fix them).

> I know the speakup code needs a lot of work to bring it up to
> kernel-acceptance level.  Has this work been done, or is it happening?

It is happening.

> If you need help in this area, I can see about doing a bit as I did a
> lot of cleanup of this codebase a few years ago.  I also know of a few
> users who are willing to help test this stuff out.

Oh, great!  Maybe Kirk should be contacted so he gives access to the git
tree of speakup.

Samuel

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Console events and accessibility
  2007-08-23 17:08             ` Samuel Thibault
@ 2007-08-23 17:51               ` Samuel Thibault
  0 siblings, 0 replies; 9+ messages in thread
From: Samuel Thibault @ 2007-08-23 17:51 UTC (permalink / raw)
  To: Greg KH, linux-kernel, akpm

Samuel Thibault, le Thu 23 Aug 2007 19:08:45 +0200, a écrit :
> > If you need help in this area, I can see about doing a bit as I did a
> > lot of cleanup of this codebase a few years ago.  I also know of a few
> > users who are willing to help test this stuff out.
> 
> Oh, great!  Maybe Kirk should be contacted so he gives access to the git
> tree of speakup.

There's a public repos on 
http://linux-speakup.org/speakup.git

Samuel

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-08-23 17:51 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-21 21:29 [PATCH] Console events and accessibility Samuel Thibault
2007-08-22  5:48 ` Greg KH
2007-08-22  8:53   ` Samuel Thibault
2007-08-22 13:05     ` Samuel Thibault
2007-08-23 10:04       ` Greg KH
2007-08-23 11:30         ` Samuel Thibault
2007-08-23 16:33           ` Greg KH
2007-08-23 17:08             ` Samuel Thibault
2007-08-23 17:51               ` Samuel Thibault

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox