Input/Output Organization: S. Dandamudi
Input/Output Organization: S. Dandamudi
Chapter 19
S. Dandamudi
Outline
• Introduction • External interface
• Accessing I/O devices ∗ Serial transmission
• An example I/O device ∗ Parallel interface
∗ Keyboard • USB
• I/O data transfer ∗ Motivation
∗ Programmed I/O ∗ USB architecture
∗ DMA ∗ USB transactions
• Error detection and • IEEE 1394
correction
∗ Advantages
∗ Parity encoding
∗ Transactions
∗ Error correction
∗ CRC ∗ Bus arbitration
∗ Configuration
2003 S. Dandamudi Chapter 19: Page 2
To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer, 2003.
1
Introduction
• I/O devices serve two main purposes
∗ To communicate with outside world
∗ To store data
• I/O controller acts as an interface between the
systems bus and I/O device
∗ Relieves the processor of low-level details
∗ Takes care of electrical interface
• I/O controllers have three types of registers
∗ Data
∗ Command
∗ Status
2003 S. Dandamudi Chapter 19: Page 3
To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer, 2003.
Introduction (cont’d)
2
Introduction (cont’d)
• To communicate with an I/O device, we need
∗ Access to various registers (data, status,…)
» This access depends on I/O mapping
– Two basic ways
4Memory-mapped I/O
4Isolated I/O
∗ A protocol to communicate (to send data, …)
» Three types
– Programmed I/O
– Direct memory access (DMA)
– Interrupt-driven I/O
3
Accessing I/O Devices (cont’d)
• Accessing I/O ports in Pentium
∗ Register I/O instructions
in accumulator, port8 ; direct format
– Useful to access first 256 ports
in accumulator,DX ; indirect format
– DX gives the port address
∗ Block I/O instructions
» ins and outs
– Both take no operands---as in string instructions
» ins: port address in DX, memory address in ES:(E)DI
» outs: port address in DX, memory address in ES:(E)SI
» We can use rep prefix for block transfer of data
4
An Example I/O Device (cont’d)
• 8255 PPI has three 8-bit registers
» Port A (PA)
» Port B (PB)
» Port C (PC)
∗ These ports are mapped as follows
8255 register Port address
PA (input port) 60H
PB (output port) 61H
PC (input port) 62H
Command register 63H
5
An Example I/O Device (cont’d)
• Mapping I/O ports is similar to mapping memory
∗ Partial mapping
∗ Full mapping
» See our discussion in Chapter 16
• Keyboard scan code and status can be read from
port 60H
∗ 7-bit scan code is available from
» PA0 – PA6
∗ Key status is available from PA7
» PA7 = 0 – key depressed
» PA0 = 1 – key released
6
I/O Data Transfer (cont’d)
• Programmed I/O
∗ Done by busy-waiting
» This process is called polling
• Example
∗ Reading a key from the keyboard involves
» Waiting for PA7 bit to go low
– Indicates that a key is pressed
» Reading the key scan code
» Translating it to the ASCII value
» Waiting until the key is released
∗ Program 19.1 uses this process to read input from the
keyboard
7
I/O Data Transfer (cont’d)
8
I/O Data Transfer (cont’d)
• Steps in a DMA operation
∗ Processor initiates the DMA controller
» Gives device number, memory buffer pointer, …
– Called channel initialization
» Once initialized, it is ready for data transfer
∗ When ready, I/O device informs the DMA controller
» DMA controller starts the data transfer process
– Obtains bus by going through bus arbitration
– Places memory address and appropriate control signals
– Completes transfer and releases the bus
– Updates memory address and count value
– If more to read, loops back to repeat the process
∗ Notify the processor when done
» Typically uses an interrupt
9
I/O Data Transfer (cont’d)
DMA transfer timing
10
I/O Data Transfer (cont’d)
• 8237 supports four DMA channels
• It has the following internal registers
∗ Current address register
» One 16-bit register for each channel
» Holds address for the current DMA transfer
∗ Current word register
» Keeps the byte count
» Generates terminal count (TC) signal when the count goes
from zero to FFFFH
∗ Command register
» Used to program 8257 (type of priority, …)
11
I/O Data Transfer (cont’d)
• 8237 supports four types of data transfer
∗ Single cycle transfer
» Only single transfer takes place
» Useful for slow devices
∗ Block transfer mode
» Transfers data until TC is generated or external EOP signal is
received
∗ Demand transfer mode
» Similar to the block transfer mode
» In addition to TC and EOP, transfer can be terminated by
deactivating DREQ signal
∗ Cascade mode
» Useful to expand the number channels beyond four
2003 S. Dandamudi Chapter 19: Page 23
To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer, 2003.
12
Error Detection and Correction (cont’d)
• Error correction
∗ Need to know the error bit position
» To correct, simply flip the bit
∗ To correct single-bit errors in d data bits
» Add p parity bits
» Codeword C = d + p bits
∗ How many parity bits do we need?
» Depends on d
» Hamming distance between codewords
– Number of bit positions in which the two codewords differ
» Hamming distance of code
– Smallest Hamming distance between any pair of
codewords in the code
2003 S. Dandamudi Chapter 19: Page 25
To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer, 2003.
13
Error Detection and Correction (cont’d)
• Check bits are derived as in the parity scheme
» Uses even parity
∗ Each check bit is responsible for checking certain bits
» P1: checks bits 1, 3, 5, 7, 9, and 11
» P2: checks bits 2, 3, 6,7, 10, and 11
» P4: checks bits 4,5,6,7, and 12
» P8: checks bits 8,9,10,11, and 12
∗ Example
14
Error Detection and Correction (cont’d)
Circuit to identify
error bit position
15
Error Detection and Correction (cont’d)
• CRC
∗ Cyclic redundancy check
» Computed for a block of data
» Widely used to detect burst errors
» Uses fixed number of bits
– Mostly 16 or 32 bits depending on the block size
∗ Basic idea: If
D =Q+R
G
D−R = Q
G
» Based on integer division
x16 + x15 + x2 + 1
» USB polynomial for token packets
x5 + x2 + 1
» Polynomial identifies the 1 bit positions
– USB data polynomial: 11000000000000101
– USB token polynomial: 100101
» Such polynomials are called polynomial generators
16
Error Detection and Correction (cont’d)
• A bit of theory behind CRC
C = (d + n)-bit codeword
D = d-bit data
R = n-bit remainder (i.e., CRC code)
G = degree n polynomial generator
∗ Goal: To generate C such that
» Remainder of (C/G) = 0
∗ Since we append n bits to the right
C = D × 2n ⊕ R
⊕ = XOR operation
17
Error Detection and Correction (cont’d)
CRC calculation
for 10100101
Codeword is
1010010101110
18
Error Detection and Correction (cont’d)
• A serial CRC generator circuit
∗ Uses polynomial generator
x16 + x15 + x2 + 1
19
Error Detection and Correction (cont’d)
External Interface
• Two ways of interfacing I/O devices
∗ Serial
» Cheaper
» Slower
∗ Parallel
» Faster
» Data skew
» Limited to small distances
20
External Interface (cont’d)
Two basic modes of data transmission
21
External Interface (cont’d)
22
External Interface (cont’d)
• EIA-232 serial interface
∗ Low-speed serial transmission
∗ Adopted by Electronics
Industry Association (EIA)
» Popularly known by its
predecessor RS-232
∗ It uses a 9-pin connector DB-9
» Uses 8 signals
∗ Typically used to connect a
modem to a computer
23
External Interface (cont’d)
• Parallel printer interface
∗ A simple parallel interface
∗ Uses 25-pin DB-25
» 8 data signals
– Latched by strobe (pin 1)
» Data transfer uses simple handshaking
– Uses acknowledge (CK) signal
4After each byte, computer waits for ACK
» 5 lines for printer status
– Busy, out-of-paper, online/offline, autofeed, and fault
» Can be initialized with INIT
– Clears the printer buffer and resets the printer
2003 S. Dandamudi Chapter 19: Page 47
To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer, 2003.
24
External Interface (cont’d)
• SCSI
∗ Pronounced “scuzzy”
∗ Small Computer System Interface
» Supports both internal and external connection
∗ Comes in two bus widths
» 8 bits
– Known as narrow SCSI
– Uses a 50-pin connector
– Device id can range from 0 to 7
» 16 bits
– Known as wide SCSI
– Uses a 68-pin connector
– Device id can range from 0 to 15
2003 S. Dandamudi Chapter 19: Page 49
To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer, 2003.
25
External Interface (cont’d)
cont’d
2003 S. Dandamudi Chapter 19: Page 51
To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer, 2003.
26
External Interface (cont’d)
• SCSI uses client-server model
∗ Uses terms initiator and target for client and server
» Initiator issues commands to targets to perform a task
– Initiators are typically SCSI host adaptors
» Targets receive the command and perform the task
– Targets are SCSI devices like disk drives
• SCSI transfer proceeds in phases
∗ Command
∗ Message in IN and OUT from
∗ Message out
the initiator point
∗ Data in
of view
∗ Data out
∗ Status
27
USB
• Universal Serial Bus
∗ Originally developed in 1995 by a consortium including
» Compaq, HP, Intel, Lucent, Microsoft, and Philips
∗ USB 1.1 supports
» Low-speed devices (1.5 Mbps)
» Full-speed devices (12 Mbps)
∗ USB 2.0 supports
» High-speed devices
– Up to 480 Mbps (a factor of 40 over USB 1.1)
» Uses the same connectors
– Transmission speed is negotiated on device-by-device
basis
USB (cont’d)
• Motivation for USB
∗ Avoid device-specific interfaces
» Eliminates multitude of interfaces
– PS/2, serial, parallel, monitor, microphone, keyboard,…
∗ Avoid non-shareable interfaces
» Standard interfaces support only one device
∗ Avoid I/O address space and IRQ problems
» USB does not require memory or address space
∗ Avoid installation and configuration problems
» Don’t have to open the box to install and configure jumpers
∗ Allow hot attachment of devices
2003 S. Dandamudi Chapter 19: Page 56
To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer, 2003.
28
USB (cont’d)
• Additional advantages of USB
∗ Power distribution
» Simple devices can be bus-powered
– Examples: mouse, keyboards, floppy disk drives, wireless
LANs, …
∗ Control peripherals
» Possible because USB allows data to flow in both directions
∗ Expandable through hubs
∗ Power conservation
» Enters suspend state if there is no activity for 3 ms
∗ Error detection and recovery
» Uses CRC
USB (cont’d)
USB cables
29
USB (cont’d)
• USB encoding
∗ Uses NRZI encoding
» Non-Return to Zero-Inverted
USB (cont’d)
• NRZI encoding
∗ A signal transition occurs if the next bit is zero
» It is called differential encoding
∗ Two desirable properties
» Signal transitions, not levels, need to be detected
» Long string of zeros causes signal changes
∗ Still a problem
» Long strings of 1s do not causes signal change
∗ To solve this problem
» Uses bit stuffing
– A zero is inserted after every six consecutive 1s
30
USB (cont’d)
Bit stuffing
USB (cont’d)
• Transfer types
» Four types of transfer
∗ Interrupt transfer
» Uses polling
– Polling interval can range from 1 ms to 255 ms
∗ Isochronous transfer
» Used in real-time applications that require constant data
transfer rate
– Example: Reading audio from CD-ROM
» These transfers are scheduled regularly
» Do not use error detection and recovery
31
USB (cont’d)
∗ Control transfer
» Used to configure and set up USB devices
» Three phases
– Setup stage
4Conveys type of request made to target device
– Data stage
4Optional stage
4Control transfers that require data use this stage
– Status stage
4Checks the status of the operation
» Allocates a guaranteed bandwidth of 10%
» Error detection and recovery are used
– Recovery is by means of retries
USB (cont’d)
∗ Bulk transfer
» For devices with no specific data transfer rate
requirements
– Example: sending data to a printer
» Lowest priority bandwidth allocation
» If the other three types of transfers take 100% of the
bandwidth
– Bulk transfers are deferred until load decreases
» Error detection and recovery are used
– Recovery is by means of retries
32
USB (cont’d)
• USB architecture
∗ USB host controller
» Initiates transactions over USB
∗ Root hub
» Provides connection points
∗ Two types of host controllers
» Open host controller (OHC)
– Defined by Intel
» Universal host controller (UHC)
– Specified by National Semiconductor, Microsoft, Compaq
» Difference between the two
– How they schedule the four types of transfers
USB (cont’d)
• UHC scheduling
∗ Schedules periodic transfers first
» Periodic transfers: isochronous and interrupts
» Can take up to 90% of bandwidth
∗ These transfers are followed by control and bulk
transfers
» Control transfers are guaranteed 10% of bandwidth
∗ Bulk transfers are scheduled only if there is bandwidth
available
33
USB (cont’d)
USB (cont’d)
• OHC scheduling
∗ Different from UHC scheduling
∗ Reserves space for non-periodic transfers first
» Non-periodic transfers: control and bulk
» 10% bandwidth reserved
∗ Next periodic transfers are scheduled
» Guarantees 90% bandwidth
∗ Left over bandwidth is allocated to non-periodic
transfers
34
USB (cont’d)
• Bus powered devices
∗ Low-power
» Less than 100 mA
» Can be bus-powered
∗ High-powered
» Between 100 mA and 500 mA
– Full-powered ports can power these devices
» Can be designed to have their own power
» Operate in three modes
– Configured (500 mA)
– Unconfigured (100 mA)
– Suspended ( about 2.5 mA)
USB (cont’d)
• USB hubs
∗ Bus-powered
» No extra power supply required
» Must be connected to an upstream port that can supply 500 mA
» Downstream ports can only supply 100 mA
– Number of ports is limited to four
– Support only low-powered devices
∗ Self-powered
» Support 4 high-powered devices
» Support 4 bus-powered USB hubs
∗ Most 4-port hubs are dual-powered
35
USB (cont’d)
Upstream port
Downstream ports
USB (cont’d)
• USB transactions
∗ Transfers are done in one or more transactions
» Each transaction consists of several packets
∗ Transactions may have between 1 and 3 phases
» Token packet phase
– Specifies transaction type and target device address
» Data packet phase (optional)
– Maximum of 1023 bytes are transferred
» Handshake packet phase
– Except for isochronous transfers, others use error detection
for guaranteed delivery
– Provides feedback on whether data has been received
without error
2003 S. Dandamudi Chapter 19: Page 72
To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer, 2003.
36
USB (cont’d)
USB IRP frame
USB (cont’d)
Hardware encoded
special pattern
37
USB (cont’d)
USB (cont’d)
• USB 2.0
∗ USB 1.1 uses 1 ms frames
∗ USB 2.0 uses 125 µs frames
» 1/8 of USB 1.1
∗ Supports 40X data rates
» Up to 480 Mbps
∗ Competitive with
» SCSI
» IEEE 1394 (FireWire)
∗ Widely available now
38
IEEE 1394
• Apple originally developed this standard for high-
speed peripherals
∗ Known by a variety of names
» Apple: FireWire
» Sony: i.ILINK
∗ IEEE standardized it as IEEE 1394
» First released in 1995 as IEEE 1394-1995
» A slightly revised version as 1394a
» Next version 1394b
∗ Shares many of the features of USB
39
IEEE 1394 (cont’d)
∗ Expandable bus
» Devices can be connected in daisy-chain fashion
» Hubs can used to expand
∗ Power distribution
» Like the USB, cables distribute power
– Much higher power than USB
4Voltage between 8 and 33 V
4Current an be up to 1.5 Amps
∗ Error detection and recovery
» As in USB, uses CRC
» Uses retransmission in case of error
∗ Long cables
» Like the USB
2003 S. Dandamudi Chapter 19: Page 79
To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer, 2003.
40
IEEE 1394 (cont’d)
• Encoding
∗ Uses a simple NRZ encoding
∗ Strobe signal is encoded
» Changes the signal even if successive bits are the same
41
IEEE 1394 (cont’d)
42
IEEE 1394 (cont’d)
• Isochronous transactions
∗ Similar to asynchronous transactions
∗ Main difference:
» No acknowledgement packets
43
IEEE 1394 (cont’d)
• Configuration
∗ Does not require the host system
∗ Consists of two main phases
» Tree identification
– Used to find the network topology
– Uses two special signals
4Parent_notify and Child_Notify
» Self-identification
– Done after the tree identification
– Assigns unique ids to nodes
44
IEEE 1394 (cont’d)
Tree identification
45
IEEE 1394 (cont’d)
Tree identification
46
IEEE 1394 (cont’d)
Self-identification
47
IEEE 1394 (cont’d)
Self-identification
Bus Wars
• SCSI is dominant in disk and storage device
interfaces
∗ Parallel interface
∗ Its bandwidth could go up to 640 MB/s
• IEEE 1394
∗ Serial interface
∗ Supports peer-to-peer applications
∗ Dominant in video applications
• USB
∗ Useful in low-cost, host-to-peripheral applications
∗ USB 2.0 provides high-speed support
Last slide
48