A simulated serial peripheral is generally attached to an external interface, that will act as source for receiving data and sink for trasmitted data. This article describes the internal design of Qemu, that helps to simplify the work for people writing simulations for serial peripherals.
Qemu allows simulated serial ports to be connected to several different external interfaces, including
Physical serial port /dev/ttySX
Unix/UDP/TCP socket server/client
Qemu has an internal abstraction layer called the qemu-char abstraction. Each of the various external interfaces mentioned above are accessed within Qemu through a common qemu-char API. Some functions in the qemu-char API are given below.
qemu_chr_read() - to read data from the external interface
qemu_chr_write() - to write data to the external interface
qemu_chr_ioctl() - to perform control operations on the external interface
All the simulated serial peripherals use these API to send and receive data. This greatly simplifies the implementation of the peripherals, since the code for accessing the external interfaces does not have to be repeated in each of the serial peripherals.
The qemu-char abstraction layer, its relation with the external interfaces and the simulated serial devices is shown in the following block diagram.