[ltp] Some IR progress

linux-thinkpad@www.bm-soft.com linux-thinkpad@www.bm-soft.com
Thu, 01 Mar 2001 04:07:39 -0800 (PST)


On 26-Feb-01 Tom Grydeland wrote:
>
>=20
> I have another question on the serial devices:
>=20
> Is the mapping
>     [physical device] <-> /dev/ttySx=20
> 1) hardwired somewhere, or=20
> 2) is it determined by whatever COMx settings I choose for the
>    [physical device], or
> 3) the [physical device] appears as the device node which has
> matching
>    ioport/irq settings?
>=20

Both, 2 and 3 are true. When an application, let's say=20
opens /dev/ttyS0, the kernel finds the right driver using
the device special file's (/dev/ttyS0) major number.
There's really no magic about these special files - they are
only used to map a name to a driver, in this case the
`serial' driver. Now, the driver has to know how to talk
to the hardware, i.e. know what I/O-port and IRQ to use. Since
the /dev/ttyS0 provides _no_ means for storing this information,
the driver has its own lookup table for ports and irqs.
(this table is indexed by the _minor_ device number).

That's how it works:=20

 -  you open /dev/ttyS0=20
 -  the kernel realizes that /dev/ttyS0 is a `special' file
    and uses the type (char device) and major number to=20
    locate the correct driver. It passes the minor number
    down to the driver - in this case, the `serial' driver.

 -  the serial driver looks the minor number up in its table of
    ports and irqs and uses the resources found there to=20
    address the hardware - if the values are incorrect, the
    driver may well talk to a big black hole.

Note that none of these mappings are fixed:

 -  when creating the /dev/ttyS0 special file, the administrator
    creates an association of a 'name' in the file system with
    a driver type and number:

     mknod /dev/ttyS0 c 4 64

    creates a 'char' device with major number 4 and minor number
    64 which is named /dev/ttyS0. Nothing prevents you from using
    a different name / number combination, i.e. you may well
    create a device

      mknod /dev/ttyS0 b 3 0

   However, when you write to /dev/ttyS0 you will end up
   overwriting the first IDE disk (normally named /dev/hda).


 - The `setserial' program allows you to change the serial
   driver's internal table of ports/irqs, hence

     setserial /dev/ttyS0 irq 5

   tells the serial driver to use irq 5 for the serial
   device with minor number 64 (the driver knows nothing
   about the filesystem name space)

Hence:
   - the special file associates a name with a driver
     (major number) and a device instance (minor number)
   - the file type and major number identify a driver=20
   - the minor number allows the driver to identify
     a specific device (among others, i.e. DB9 port
     vs IR port)
 =20

Hope this is not too confusing...

--Till

----- The Linux ThinkPad mailing list -----
The linux-thinkpad mailing list home page is at:
http://www.bm-soft.com/~bm/tp_mailing.html