]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/cdrom/yaird-0.0.5/doc/input.xml
362d9674debfbd17c3dcc84bff42fb5ce2b90b39
[bacula/rescue] / rescue / linux / cdrom / yaird-0.0.5 / doc / input.xml
1 <section id="input">
2   <title>Supporting Input Devices</title>
3
4   <para>
5     A working console and keyboard during the initial boot image execution
6     is needed to enter a password for encrypted file systems; it also
7     helps while debugging.  This section discusses the kernel input
8     layer and how it can be supported during image generation.
9   </para>
10
11   <para>
12     The console is a designated terminal, where kernel output goes, and that
13     is the initial I/O device for <filename>/sbin/init</filename>.  Like all
14     terminal devices, it provides a number of functions: you can read
15     and write to it, plus it has a number of <code>ioctl()</code>
16     functions to manage line buffering, interrupt characters and
17     baudrate or parity where applicable.
18   </para>
19
20   <para>
21     Terminals come in different types: it can be a VT100 or terminal
22     emulator connected via an RS232 cable, or it can be a combination
23     of a CRT and a keyboard.  The keyboard can be connected via
24     USB or it can talk a byte oriented protocol via a legacy UART
25     chip.
26   </para>
27     
28   <para>
29     The CRT is managed in two layers.  The top layer, "virtual
30     terminal", manages a two dimensional array describing which letter
31     should go in which position of the screen.  In fact, there are a
32     number of different arrays, and which one is actually visible on
33     the screen is selected by a keyboard combination.
34     Below the virtual terminals is a layer that actually places the
35     letters on the screen.  This can be done a letter at a time,
36     using a VGA interface, or the letters can be painted pixel by
37     pixel, using a frame buffer.
38   </para>
39
40   <para>
41     Below the terminal concept we find the input layer.  This provides a
42     unified interface to the various user input devices: mouse, keyboard,
43     PC speaker, joystick, tablet.  These input devices not only
44     generate data, they can also receive input from the computer.  As
45     an example, the keyboard needs computer input to operate the NUM
46     LOCK indicator.  Hardware devices such as keyboards register
47     themselves with the input layer, describing their capabilities
48     (I can send relative position, have two buttons and no LEDs),
49     and the input layer assigns a handler to the hardware device.
50     The handler presents the device to upper layers, either as a char
51     special file or as the input part of a terminal device.
52     This is not a one-to-one mapping: every mouse gets its own
53     handler, but keyboard and PC speaker share a handler, so it looks
54     to userland like you have a keyboard that can do "beep".
55   </para>
56
57   <para>
58     In addition to handlers for specific type of upper layers (mouse,
59     joystick, touch screen) there is a generic handler that provides a
60     character device file such as <filename>/dev/input/event0</filename>
61     for every input device detected; input events are presented through
62     these devices in a unified format.  The input layer generates
63     hotplug events for these generic event handlers; hotplug uses
64     <filename>modules.inputmap</filename> to load a module containing a
65     suitable upper layer event handler.  The keyboard handler is a special
66     case that does not occur in this map, so for image generation there
67     is little to be learned from hotplug input support.
68   </para>
69
70   <para>
71     To guarantee a working console, <application>yaird</application>
72     should examine <filename>/dev/console</filename>, determine
73     whether it's RS232 or hardware directly connected to the computer,
74     and then load modules for either serial port, or for virtual
75     terminals, the input layer and any hardware underlying it.
76     Unfortunately, <filename>/dev/console</filename> does not give
77     a hint what is below the terminal interface, and unfortunately,
78     lots of input devices are legacy hardware that is hard to probe
79     and only sketchily described by sysfs in kernel 2.6.10.
80   </para>
81
82   <para>
83     This means that a guarantee for a working console cannot be made,
84     which is why distribution kernels come with components such as the
85     keyboard and serial port driver compiled into the kernel.  We can
86     do something else though: provide modules for keyboard devices
87     provided the kernel provides correct information.  That covers the
88     case of USB keyboards, and that's something that's not compiled
89     into distribution kernels, so that the administrator has to add
90     modules explictly in order to get the keyboard working in
91     the initial boot image.
92   </para>
93
94   <para>
95     Lets examine the sources of information we have to find which input
96     hardware we have to support.
97     <itemizedlist>
98
99       <listitem>
100         <para>
101           In <filename>/sys/class/input</filename>, all input devices
102           are enumerated.  Mostly, these only contain a
103           <filename>dev</filename> file containing major/minor number,
104           but USB devices also have a <filename>device</filename>
105           symlink into <filename>/sys/devices</filename> identifying
106           the underlying hardware.
107         </para>
108       </listitem>
109
110       <listitem>
111         <para>
112           In <filename>/boot/menu/grub.lst</filename>, kernel options
113           can be defined that determine whether to use a serial line as
114           console and whether to use a frame buffer.  The consequence
115           is that it is fundamentally impossible to determine by looking
116           at the hardware alone what's needed to get an image that will
117           boot without problems.  This probably means we'll have to consider
118           supplying some modules in the image that will only get loaded
119           depending on kernel options.
120         </para>
121       </listitem>
122
123       <listitem>
124         <para>
125           The file <filename>/proc/bus/input/devices</filename> gives
126           a formatted overview of all known input devices; entries look
127           like this:
128           <programlisting>
129             I: Bus=0003 Vendor=413c Product=2003 Version=0100
130             N: Name="DELL DELL USB Keyboard"
131             P: Phys=usb-0000:00:1d.7-4.1/input1
132             H: Handlers=kbd event2
133             B: EV=100003
134             B: KEY=7f f0000 0 3878 d801d101 1e0000 0 0 0
135           </programlisting>
136           Here the "I" line shows identification information passed to
137           the input layer by the hardware driver that is used to look
138           up the appropiate handler.  "N" is a printable name provided
139           by the hardware driver.  "P" is a hint at location in a bus
140           of the device; note how this line is completely unrelated to
141           the location of the hardware in
142           <filename>/sys/devices</filename>.
143           The H (Handlers) line is obvious; The B lines specify
144           capabilities of the device, plus extra information for each
145           capability.  Known capabilities include:
146           <informaltable frame='topbot'>
147             <tgroup cols='2' align='left'>
148               <thead>
149                 <row>
150                   <entry>Capability</entry>
151                   <entry>Description</entry>
152                 </row>
153               </thead>
154               <tbody>
155                 <row>
156                   <entry>SYN</entry>
157                   <entry>Input event is completed</entry>
158                 </row>
159                 <row>
160                   <entry>KEY</entry>
161                   <entry>Key press/release event</entry>
162                 </row>
163                 <row>
164                   <entry>REL</entry>
165                   <entry>Relative measure, as in mouse movement</entry>
166                 </row>
167                 <row>
168                   <entry>ABS</entry>
169                   <entry>Absolute position, as in graphics
170                   tablet</entry>
171                 </row>
172                 <row>
173                   <entry>MSC</entry>
174                   <entry>Miscelanious</entry>
175                 </row>
176                 <row>
177                   <entry>SND</entry>
178                   <entry>Beep</entry>
179                 </row>
180                 <row>
181                   <entry>REP</entry>
182                   <entry>Set hardware repeat</entry>
183                 </row>
184                 <row>
185                   <entry>FF</entry>
186                   <entry>Don't know</entry>
187                 </row>
188                 <row>
189                   <entry>PWR</entry>
190                   <entry>Power event: on/off switch pressed.</entry>
191                 </row>
192                 <row>
193                   <entry>FF_STATUS</entry>
194                   <entry>Don't know.</entry>
195                 </row>
196               </tbody>
197             </tgroup>
198           </informaltable>
199         </para>
200       </listitem>
201     </itemizedlist>
202   </para>
203
204   <para>
205     Finally, let's consider some kernel configuration defines, the
206     corresponding modules and their function.  This could be used as a
207     start to check whether all components required to make an
208     operational console are available on the generated image:
209     <informaltable frame='topbot'>
210       <tgroup cols='3' align='left'>
211         <thead>
212           <row>
213             <entry>Define</entry>
214             <entry>Module</entry>
215             <entry>Description</entry>
216           </row>
217         </thead>
218         <tbody valign='top'>
219
220           <row>
221             <entry>VT</entry>
222             <entry>(bool)</entry>
223             <entry>
224               Support multiple virtual terminals, irrespective of what
225               hardware is used to display letters from the virtual
226               terminal on the CRT.
227             </entry>
228           </row>
229
230           <row>
231             <entry>VT_CONSOLE</entry>
232             <entry>(bool)</entry>
233             <entry>
234               Make the VT a candidate for console output.  The alternative
235               is a serial line to a VT100 or terminal emulator
236             </entry>
237           </row>
238
239           <row>
240             <entry>VGA_CONSOLE</entry>
241             <entry>(bool)</entry>
242             <entry>
243               Display a terminal on CRT using the VGA interface.
244             </entry>
245           </row>
246
247           <row>
248             <entry>FRAMEBUFFER_CONSOLE</entry>
249             <entry>fbcon</entry>
250             <entry>
251               Display a terminal on a framebuffer, painting letters a
252               pixel at a time.  This has to know about fonts.
253             </entry>
254           </row>
255
256           <row>
257             <entry>FB_VESA</entry>
258             <entry>vesafb</entry>
259             <entry>
260               Implement a framebuffer based on VESA (a common standard
261               for PC graphic cards), a place where an X server or
262               the framebuffer console can write pixels to be displayed
263               on CRT.
264               There are many different framebuffer modules that
265               optimise for different graphics cards.
266               Note that while vesafb and other drivers such as intelfb
267               can be built as a module, they only function correctly
268               when built into the kernel.  Most framebuffer modules
269               depend on three other modules to function correctly:
270               cfbfillrect, cfbcopyarea, cfbimgblt.
271             </entry>
272           </row>
273
274           <row>
275             <entry>ATKBD</entry>
276             <entry>atkbd</entry>
277             <entry>
278               Interpret input from a standard AT or PS/2 keyboard.
279               Other keyboards use other byte codes, see for example
280               the Acorn keyboard (rpckbd).
281             </entry>
282           </row>
283
284           <row>
285             <entry>SERIO</entry>
286             <entry>serio</entry>
287             <entry>
288               Module that manages a stream of bytes from and to an IO port.
289               It includes a kernel thread (kseriod) that handles the queue
290               needed to talk to slow ports.  It is normally used for
291               dedicated IO ports talking to PS/2 mouse and keyboard,
292               but can also be interfaced to serial ports (COM1, COM2).
293               The atkbd driver uses a serio driver to communicate with
294               the keyboard.
295             </entry>
296           </row>
297
298           <row>
299             <entry>SERIO_I8042</entry>
300             <entry>i8042</entry>
301             <entry>
302               Implement a serio stream on top of the i8042 chip, the chip
303               that connects the standard AT keyboard and PS/2 mouse to
304               the computer.
305               This is legacy hardware: it's not connected via PCI but
306               directly to the 'platform bus'.
307               When a chip such as i8042 that implements
308               serio is detected, it registers itself with the input
309               layer.  The input layer then lets drivers that use serio
310               (such as atkbd and psmouse) probe whether a known device
311               is connected via the chip; if such a device is found,
312               it is registered as a new input device.
313             </entry>
314           </row>
315
316           <row>
317             <entry>SERIAL_8250</entry>
318             <entry>serial</entry>
319             <entry>
320               Support for serial ports (COM1, COM2) on PC hardware.
321               Lots of other configuration options exist to support
322               multiple cards and fiddle with interrupts.
323               If compiled in rather than modular, a further option,
324               SERIAL_8250_CONSOLE, allows using the serial port as a
325               console.
326             </entry>
327           </row>
328
329           <row>
330             <entry>USB_HID</entry>
331             <entry>usbhid</entry>
332             <entry>
333               Driver for USB keyboards and mice.
334               Another define, USB_HIDINPUT, needs to be true for
335               these devices to actually work.
336             </entry>
337           </row>
338
339           <row>
340             <entry>USB_KBD</entry>
341             <entry>usbkbd</entry>
342             <entry>
343               Severely limited form of USB keyboard; uses the "boot
344               protocol".  This conflicts with the complete driver.
345             </entry>
346           </row>
347
348         </tbody>
349       </tgroup>
350       
351     </informaltable>
352   </para>
353
354   <para>
355     The following figure gives an example of how the various modules 
356     can fit together.
357   </para>
358
359   <figure id="console-module-flow">
360     <title>
361       Module relation for common console setup
362     </title>
363     <mediaobject>
364       <imageobject>
365         <imagedata fileref="figures/console.png" format="PNG"/>
366       </imageobject>
367     </mediaobject>
368   </figure>
369
370   <para>
371     In practical terms, a first step toward a more robust boot image
372     is to support new keyboard types, such as USB keyboards.
373     The following algorithm should do that.
374
375     <orderedlist>
376       
377       <listitem>
378         <para>
379           Interpret <filename>/proc/bus/input/devices</filename>.
380         </para>
381       </listitem>
382       
383       <listitem>
384         <para>
385           Look for devices that have handler kbd <emphasis>and</emphasis>
386           that have buttons.  Mice and the PC speaker don't match that
387           criterium, keyboards do.
388         </para>
389       </listitem>
390
391       <listitem>
392         <para>
393           You could interpret the name field of such devices if you're
394           interested in supporting legacy keyboards.
395         </para>
396       </listitem>
397
398       <listitem>
399         <para>
400           The devices that have handler 'kbd' also have a handler 'event\d',
401           where input is presented in a generalised event format;
402           look up this device in /sys/class/input/event\d/.
403         </para>
404       </listitem>
405
406       <listitem>
407         <para>
408           If it's got a device symlink, load the hardware drivers for that
409           hardware device (most likely it's usbhid plus a usb core driver).
410         </para>
411       </listitem>
412
413       <listitem>
414         <para>
415           Don't bother with a mknod, the input is handled via
416           <filename>/dev/console</filename>.
417         </para>
418       </listitem>
419
420       <listitem>
421         <para>
422           Otherwise it's presumable a legacy device; you could check for
423           the existence of
424           <filename>/sys/devices/platform/i8042/serio\d/</filename>,
425           or you could just assume the appropriate driver to be compiled in.
426         </para>
427       </listitem>
428
429       <listitem>
430         <para>
431           Implement support for
432           <filename>/etc/hotplug/blacklist</filename>,
433           since some USB keyboards publish two interfaces (full HID
434           and the limited boot protocol), the input layer makes both
435           visible in <filename>/proc/bus/input/devices</filename> and
436           the corresponding modules are mutually conflicting.
437           The blacklist is used to filter out one of these modules.
438         </para>
439       </listitem>
440
441     </orderedlist>
442   </para>
443 </section>