Understanding Direct Memory Access (DMA)
Understanding Direct Memory Access (DMA)
PROF.
DR. KAMALIKA DATTA
[Link]
KAMALIKASENGUPTA
DATTA
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, NIT
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, IIT MEGHALAYA
KHARAGPUR
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING, NIT MEGHALAYA
1 2
Introduc)on
• In the data transfer methods discussed under programmed I/O, it is
assumed that machine instruc;ons are used to transfer the data between
I/O device and memory.
– Not very suitable when large blocks of data are required to be transferred at
high speed (e.g. transfer of a disk block).
• An alternate approach is Direct Memory Access (DMA).
– Allows transfer of a block of data directly between an I/O device and memory,
without con;nuous CPU interven;on.
2 2
1
15/09/17
3 2
b) Many high speed peripheral devices like disk have a synchronous mode of
opera;on, where data are transferred at a fixed rate.
• Consider a disk rota;ng at 7200 rpm, with average rota;onal delay of 4.15 msec.
• Suppose there are 64 Kbytes of data recorded in every track.
• Once the disk head reaches the desired track, there will be a sustained data transfer at
rate 64 Kbytes / 4.15 msec = 15.4 MBps.
• This sustained data transfer rate is comparable to the memory bandwidth, and cannot
be handled by programmed I/O.
4 2
2
15/09/17
DMA Controller
• A hardwired controller called the DMA controller can enable direct data
transfer between I/O device (e.g. disk) and memory without CPU
interven;on.
– No need to execute instruc;ons to carry out data transfer.
– Maximum data transfer speed will be determined by the rate with which
memory read and write opera;ons can be carried out.
– Much faster than programmed I/O.
5 2
MEMORY
Address Bus
CPU Data Bus
Control Bus
DMA-ACK
DMA-RQ
6 2
3
15/09/17
Steps Involved
a) When the CPU wants to transfer data, it ini;alizes the DMA controller.
– How many bytes to transfer, address in memory for the transfer.
b) When the I/O device is ready for the transfer, the DMA controller sends DMA-RQ
signal to the CPU.
c) CPU waits ;ll the next DMA breakpoint, relinquishes control of the bus (i.e. puts
them in high impedance state), and sends DMA-ACK to DMA controller.
d) Now DMA controller enables its bus interface, and transfers data directly to/from
memory.
e) When done, it deac;vates the DMA-RQ signal.
f) The CPU again begins to use the bus to access memory.
7 2
Instruc;on Cycle
8 2
4
15/09/17
• For every DMA channel, the DMA controller will have three registers:
a) Memory address
b) Word count
c) Address of data on disk
• CPU ini;alizes these registers before each DMA transfer opera;on.
• Before the data transfer, DMA controller requests the memory bus from
the CPU.
• When the data transfer is complete, the DMA controller sends an
interrupt signal to the CPU.
9 2
DMA-RQ DMA-RQ1
DMA-ACK1
DMA-ACK
CPU
DMA ..
Controller .
INTR
DMA-RQ4
DMA-ACK4
10 2
5
15/09/17
11 2
Cycle Block
DMA controller Stealing DMA controller
Transfer
takes over bus Mode takes over bus
Mode
12 2
6
15/09/17
13 2
END OF LECTURE 48
14 2
7
15/09/17
15 2
Introduc)on
• Here we consider two simple examples to illustrate the I/O device interfacing
techniques discussed earlier.
a) Keyboard interfacing
b) Printer interfacing
16 2
8
15/09/17
Keyboard Interfacing
• What is a keyboard?
– A set of pushbufon switches (keys) interfaced to a computer.
– Typically arranged in the form of a two-dimensional matrix.
• A key is connected to a row line and a column line at every junc;on.
• Results in minimiza;on of the number of port lines required.
17 2
Interfacing VCC
Switches R
ON
• How to check status for P1.0
asynchronous transfer? P1.1
P1.2
P1.3
P1.4
Read from port P1.5
P1.6
P1.7
= FF? PORT
Yes 8051
DIP
No SWITCH
18 2
9
15/09/17
Interfacing a +5V
Keyboard
P1.0
• One key per port line. P1.1
PORT
8051
19 2
Interfacing a
Keyboard
3 2 1 0
PULL-UP
P1.0 REGISTERS
• Keys organized in matrix X1
7 6 5 4 10KΩ
form. P1.1
X2
• For N keys, number of port B A 9 8
P1.2
lines required will be 2 √N. X3
F E D C
• Possible to interface P1.3
large keyboards. X4 Y4 Y3 Y2 Y1
2-D
8051 P2.3 P2.2 P2.1 P2.0
20 2
10
15/09/17
• How to detect the status of the device (i.e. whether any key has been
pressed)?
– Output all-0’s to the rows.
– Read the column port, and check whether all the bits are 1.
– If any of the bits is 0, it means a key has been pressed.
• Allows asynchronous mode of transfer.
21 2
22 2
11
15/09/17
23 2
Printer Interfacing
• Older printers has serial and parallel ports for interfacing to computer
systems.
– RS-232C serial data interface.
– LPT parallel data interface (8 data lines).
• Modern-day printers support the much higher speed Universal Serial Bus
(USB) interface.
– Almost all devices today have USB interfaces.
24 2
12
15/09/17
25 2
26 2
13
15/09/17
END OF LECTURE 49
27 2
28 2
14
15/09/17
Example 1
29 2
Example 2
30 2
15
15/09/17
Example 3
31 2
Example 4
32 2
16
15/09/17
Example 5
• Consider a disk drive with 16 surfaces, 512 tracks per surface, and 512
sectors per track, 1024 bytes per sector, and a rota;on speed of 3600 rpm.
The disk is operated in cycle stealing mode whereby whenever one 4-byte
word is ready, it is sent to memory. Similarly for wri;ng, the disk interface
reads a 4-byte word from memory in each DMA cycle. The memory cycle
;me is 40 nsec. Find the maximum percentage of ;me that the CPU gets
blocked during DMA opera;on.
33 2
Example 6
34 2
17
15/09/17
Example 7
35 2
END OF LECTURE 50
36 2
18
15/09/17
37 2
Introduc)on
• A bus is a collec;on of wires and connectors through which the data is
transmifed.
19
15/09/17
• Bus Protocol:
– Rules determining the format and transmission of data through bus.
• Parallel Bus:
– Data transmifed in parallel.
– Advantage: It is fast.
– Disadvantage: High cost for long distance communica;on, inter-line interference
at high frequency.
• Serial Bus:
– Data transmifed serially.
– Advantage: low cost for long distance communica;on, no interference.
– Disadvantage: Slow.
39 2
40 2
20
15/09/17
• AGP Bus:
– Connects NorthBridge chipset to the GPU.
• ISA, PCI, Firewire, USB, PCI-Express Bus:
– Connects motherboard to peripherals.
41 2
42 2
21
15/09/17
• Bus width:
– Number of wires available in the bus for transferring data.
• Bus bandwidth:
– Total amount of data that can be transferred over the bus per unit
;me.
43 2
44 2
22
15/09/17
45 2
46 2
23
15/09/17
2. Aler the voltages on the address line have become stable, CPU
asserts MREQ and RD lines
47 2
48 2
24
15/09/17
4. CPU reads data from the data lines, and then de-asserts MREQ
and RD to release the bus
49 2
1. CPU puts the address of the memory loca;on on the address lines
50 2
25
15/09/17
2. Aler the voltages on the address line have become stable, CPU
asserts MREQ and RD lines
51 2
52 2
26
15/09/17
4. Memory controller loads data from memory to data lines, and asserts SSYN.
53 2
5. CPU takes data from the data lines, and then de-asserts MREQ, RD and MSYN.
54 2
27
15/09/17
55 2
56 2
28
15/09/17
57 2
END OF LECTURE 51
58 2
29
15/09/17
59 2
60 2
30
15/09/17
History of USB
• A group of 7 companies (Compaq, DEC, IBM, Intel, Microsol, NEC, Nortel)
ini;ated the development of the USB standard in 1994.
• Main Goal:
– Simplify the problem of connec;ng external devices by replacing the variety of
connectors that were available earlier.
– Simplify solware configura;on of the connected devices.
• The first USB version 1.0 appeared in 1996, which was followed by many
other genera;ons, with USB 3.1 being the latest.
61 2
62 2
31
15/09/17
USB Connectors
• There are two pre-defined connectors in any USB system.
– The Type-A plug has an elongated cross-sec;on, inserts into a Type-A
receptacle on a downstream port on a USB host or hub, and carries both
power and data.
– The Type-B plug has a near square cross-sec;on with the top exterior corners
beveled. As part of a removable cable, it inserts into an upstream port on a
device (e.g. printer).
• For connec;ng smaller devices like mobile phones and digital cameras,
mini and micro USB connectors have also been developed.
63 2
Mini
Type-A
Type-B Micro
64 2
32
15/09/17
System Bus
USB Internal Bus and i/f
Host Computer
USB Host
Hub
65 2
Bus Topology
66 2
33
15/09/17
Host Root
Hub D
FuncJonal USB
Device
D Hub D D
D D
67 2
• USB Host:
– It is a device that controls the en;re system (usually a computer).
– It processes data arriving to and from the USB port.
– It contains a sophis;cated set of solware drivers.
• Drivers schedule and compose USB transac;ons.
• Access individual devices to obtain configura;on informa;on.
– Solware dependence of USB systems make it difficult to use on stand-
alone systems (with no OS support).
– The physical interface to USB Root Hub is called the USB Host Controller.
68 2
34
15/09/17
• USB Hub:
– It checks for new devices and maintains status informa;on of child
devices.
– It serves as repeater, boos;ng strength of upstream and downstream
signals.
– It electrically isolates devices from one another, thus allowing an
expanded number of devices.
• Allows malfunc;oning devices to be removed.
• Allows slower devices to be placed on a faster branch.
– Can be purchased as stand-alone devices.
69 2
• USB Devices:
– All func;onal USB devices are slaves; only responding to data reads or
writes, never ini;a;ng any.
– May indicate a need to transmit or receive data through polling.
– Contain registers that iden;fy relevant configura;on informa;on.
– Exist in conjunc;on with corresponding set of solware drivers inside
the host system.
70 2
35
15/09/17
71 2
72 2
36
15/09/17
Future of USB
• USB Type-C Plug:
– They are about the same size as micro USB connectors.
– Can deliver power output of 20 volts and 5 amps (100 wafs).
• Can be used for charging laptops and phones.
• Thunderbolt 3 port uses the same port type as USB-C.
– Peak speed up to 40 Gbps.
– Available on Apple machines.
73 2
END OF LECTURE 52
74 2
37