Hi Aaron Here is some background informations about how the hid driver handle the stream. When a keyboard is physically opened, the internal stream is unplugged from conskbd automatically(just as you said) and then a default stream head will be plugged as the top head of the stream. When the keyboard is physically closed, the stream is unplugged from the default stream head automatically, and the conskbd will be replugged as the stream head again. All these actions only happen when physically opening or closing a keyboard.
Your problem is caused by that the hid driver doesn't support the virtual opening(switch to console) while the keyboard is being physically opened (by Xorg). For your first question, the existing hid driver doesn't do anything helpful for the problem. For the second question, perhaps I think your proposal is good enough. So according to your proposal, a new set of ioctls can be added in hid driver to do the following two actions: -1. Switch from Xorg to console: hid kill the old stream(default stream head---usbkbd---hid), change the opening status to virtual opened, and then build a new stream for console(conskbd---usbkbd---hid); -2. Switch from console to Xorg: hid kill the old stream(conskbd---usbkbd---hid), change the opening status to physically opened, and then build a new stream for Xorg(default stream head---usbkbd---hid). And accordingly, in user space: -1. When switching from X to VT, kbd driver should call the first ioctl to activate keyboard in VT; -2. When switching from VT to X, the second ioctl should be called by console? to re-activate keyboard in X. We also need conskbd to pass this ioctl down to hid. ----- ??? ----- ?: Aaron Zang <Aaron.Zang at Sun.COM> ??: ???, 2008 ? 11? 7?, ??5:48 ??: New ioctl to route IO between the two streams of one USB keyboard ???: Edward Pilatowicz <Edward.Pilatowicz at Sun.COM>, Alan Coopersmith <Alan.Coopersmith at Sun.COM>, vconsole-discuss at opensolaris.org, usb-tech at sun.com, console-core at sun.com > Hi all, > > During the implementation of Xorg VT (virtual console) support, > a problem has been discovered when Xorg physically opens a USB > keyboard (/dev/usb/hid*). > > By default Xorg on Solaris opens the virtual keyboard device > (/dev/kbd). The virtual keyboard (conskbd) creates two minor nodes > thus has two streams. One is the internal minor node which is linked > under console stream, the other is /dev/kbd which is for the use > of applications. > Say Xorg is running on /dev/vt/7, when /dev/vt/7 is made active, > Xorg uses KIOCSDIRECT to route conskbd IO to /dev/kbd stream. > And it will route the IO back when switching away to consoles. > > HID driver creates two minor nodes for a USB keyboard too. > One minor node is internal used and the stream is plumbed under > conskbd, the other is /dev/usb/hidx. > When Xorg is configured to open /dev/usb/hidx as keyboard device, > the internal stream is unplugged from conskbd automatically. > So when switching from Xorg session back to console session, the > console will not get any input from this keyboard. > And Xorg can not close /dev/usb/hidx, since it has already dropped > the privilege and running as a normal user at this moment. If Xorg > closes /dev/usb/hidx when switching away, it loses the privilege > to reopen the keyboard device when switching back. > > So the proposal here is to add a new ioctl to the hid driver for > keyboard devices which has the similar routing functionality as > KIOCSDIRECT does to conskbd driver. > > Before I am preparing any official documents, I would like to > discuss it with the following purposes: > > 1) Is there any existing way to resolve this? > 2) Is there any better solution? > > Edward and Alan, your comments are more than welcomed. > > Thanks a lot. > Aaron > > -- > You know some birds are not meant to be caged, their feathers are > just too bright. >