At boot time, hardware is probed. Each device is allocated a set of files in the file system for communication with the device. Serial port 1 for instance will be allocated /dev/ttyS0 and any application wishing to use the serial port will open /dev/ttyS0. The same is true of the mouse, disks, the console, audio devices and so on.
There are two types of files generated a boot time in /dev/, block devices and character devices. Block devices are buffered by the OS, and are used generally for file systems. Character devices are unbuffered and generally refer to raw ports, such as the mouse, a serial port, or the audio devices.
Devices have a major and minor number and actually refer to places in memory. An application reading from this file is actually reading from a memory location (usually 256 * major + minor + device_base_offset), this is mapped in the Kernel.