While going through computer Architecture, I learnt different method of controlling I/O device which are,
I learnt all three methods.
But I come across another term Memory Mapped I/O.
Is there any relation between Programmed I/O and Memory Mapped I/O?
I am confused with these two. Are they similar?
Those terms are mostly independent and not mutually exclusive.
Below I'll use a pseudo-assembly code to make the examples clearer, it is a demonstrative code, not real code.
If the device is accessible in a dedicated address space, separate from the address space or memory, then the type of IO is called port-mapped IO or isolated IO.
If the device is accessible as part of an unique address space, where memory is also located, then the type of IO is called memory-mapped IO.
For example some embedded controller and some mainstream architecture have special instructions to access the IO address space.
in r0, 0x34 #Read address 0x34 from IO address space
ld r0, 0x34 #Read address 0x34 from memory address space
In the example above the two addresses 0x34 generate two different bus addresses that are then handled differently.
Note that the ld
type of instruction is the same used to access memory, so for example ld r1, 0x1000
could access memory instead of a device.
This also applies to writing data into a device.
If the software is forced to read each byte/word of data explicitly then the type of IO is programmed IO.
If the device can be told to initiate an operation and transfer the data to memory autonomously then the type of IO is Direct Memory Access IO.
For example to read a sector, say 512 bytes, from a disk the software could
#Setup read parameters omitted
movi r0, $0x20 #r0 = 0x20 (say it's READ_SECTORS command)
out 0x102, r0 #Tell the device to start reading
movi r1, 512 / 4 #r1 = number of words in a sector
_read:
in r0, 0x103 #Read a word (32-bit)
...
decbnz r1, _read #Decrement r1 and branch back if not zero
With DMA the same read could be performed as
#Setup read parameters omitted
movi r0, $0x21 #r0 = 0x21 (say it's READ_DMA_SECTORS command)
out 0x102, r0 #Tell the device to start reading
#Done, the software can do something else
The completion of an operation and the arrival of new data are two example of event that the software may want to be notified about.
If the device use an interrupt to notify the CPU of an event, the type of IO is said interrupt driven IO.
If the device has just a status register that the software must periodically check, the type of IO is said polling IO.
For example to check if an UART has new data a software can use an interrupt
#Setup isr
la r0, myISR
call setup_isr
#Example of device configuration
in r0, 0x100
or r0, 0x80
out 0x100, r0 #Set bit7 to enable generation of interrupt
#Done, myISR is called whenever new data arrives
If instead the IO is polling then the software must check periodically
_check_data:
in r0, 0x102 #Say 102 is a status resister
btbz r0, 7, _check_data #Test if bit7 of r0 is set, if not jump back
#New data is available
So for example an IO can be memory-mapped DMA interrupt driven IO.
This is actually what PCI(e) devices usually uses on the x86 architecture.
For a real example of port-mapped DMA interrupt driven IO (when reading samples) and port-mapped programmed polling IO (when issuing commands to the DSP), you can check my answer about programming the sound-card to playback a wave file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With