OK - we know when a device needs service, and we know (in general terms) how we communicate commands and status to and from the device. Now there is one more question before we see some examples:
How is data transferred to and from devices?
There are, again, two possibilities:
In looking at these, let's take input from, say, a disk or network controller as an example.
Typically a device will collect input data in the controller. When there is a certain amount of data in the controller the device will generate an interrupt (or set a flag in a status register in the case of polled I/O) to inform the CPU. Now we need to somehow get the data from the device to main memory.
Notice that even though the CPU is freed up to execute another process, there is still additional contention for another critical hardware component - the bus. Here the bus is being used both by the DMA device to transfer the buffer contents to memory, and by the CPU to fetch instructions and manipulate data. This can cause slower process execution during DMA, but is still a big win overall.