I/O!Hakim&Weatherspoon&CS&3410,&Spring&2011&Computer)Science)Cornell)University)See:)P&H)Chapter)6.5<6)2)Goals for Today!Computer)System)OrganizaAon))How)to)talk)to)device?))• Programmed)I/O)or)Memory<Mapped)I/O)How)to)get)events?)• Polling)or)Interrupts)How)to)transfer)lots)of)data?)• Direct)Memory)Access)(DMA))3)Computer System Organization!Computer)System)=)Input)+)Output)+)Memory)+)Datapath))+)Control))))CPU)Registers)Network)Video)bus)Memory)bus)Disk)USB)Audio)Keyboard) Mouse)Serial)4)Challenge!How)do)we)interface)to)other)devices)• Keyboard)• Mouse)• Disk)• Network)• Display)• Programmable)Timer)(for)clock)Acks))• Audio)• Printer(s))• Camera)• iPod)• Scanner)• …)5)Interconnects!Bad)Idea)#1:)Put)all)devices)on)one)interconnect)• We)would)have)to)replace)all)devices)as)we)improve/change)the)interconnect)• keyboard)speed)==)main)memory)speed)?!)CPU)Network)Video)Memory)Disk)Audio)Keyboard)Serial)Cache)interconnect)6)I/O Controllers!Decouple)via)I/O)Controllers)and)“Bridges”)• fast/expensive)busses)when)needed;)slow/cheap)elsewhere)• I/O)controllers)to)connect)end)devices))7)I/O Controllers!Decouple)via)I/O)Controllers)and)“Bridges”)• fast/expensive)busses)when)needed;)slow/cheap)elsewhere)• I/O)controllers)to)connect)end)devices))8)Interconnecting Components!Interconnects)are)(were?))busses)• parallel)set)of)wires)for)data)and)control)• shared)channel)– mulAple)senders/receivers)– everyone)can)see)all)bus)transacAons)• bus)protocol:)rules)for)using)the)bus)wires)AlternaAve)(and)increasingly)common):)• dedicated)point<to<point)channels)9)Bus Parameters!Width)=)number)of)wires)Transfer)size)=)data)words)per)bus)transacAon)Synchronous)(with)a)bus)clock))or)asynchronous)(no)bus)clock)/)“self)clocking”)))10)Bus Types!Processor)–)Memory)(“Front)Side)Bus”.)Also)QPI))• Short,)fast,)&)wide)• Mostly)fixed)topology,)designed)as)a)“chipset”)– CPU)+)Caches)+)Interconnect)+)Memory)Controller))I/O)and)Peripheral)busses)(PCI,)SCSI,)USB,)LPC,)…))• Longer,)slower,)&)narrower)• Flexible)topology,)mulAple/varied)connecAons)• Interoperability)standards)for)devices)• Connect)to)processor<memory)bus)through)a)bridge)11)Typical x86 PC I/O System!12)Typical x86 PC I/O System!13)I/O Device API!Typical)I/O)Device)API)• a)set)of)read<only)or)read/write)registers)Command)registers)• wriAng)causes)device)to)do)something)Status)registers)• reading)indicates)what)device)is)doing,)error)codes,)…)Data)registers)• Write:)transfer)data)to)a)device)• Read:)transfer)data)from)a)device))14)Simple)(old))example:)AT)Keyboard)Device)8<bit)Status:)8<bit)Cmd:))0xAA)=)“self)test”)0xAE)=)“enable)kbd”)0xED)=)“set)LEDs”))…)8<bit)Data:))scancode)(when)reading)))LED)state)(when)wriAng))or)…)PE) TO) AUXB)LOCK) AL2) SYSF) IBS) OBS)15)Communication Interface!Q:)How)does))program)))OS))code)talk)to)device?)A:)special)instrucAons)to)talk)over)special)busses)Programmed)I/O)• inb)$a,)0x64)• outb)$a,)0x60)• Specifies:)device,)data,)direcAon)• ProtecAon:)only)allowed)in)kernel)mode)*x86:)$a)implicit;)also)inw,)outw,)inh,)outh,)…)16)Communication Interface!Q:)How)does))program)))OS))code)talk)to)device?)A:)Map)registers)into)virtual)address)space)Memory<mapped)I/O)• Accesses)to)certain)addresses)redirected)to)I/O)devices)• Data)goes)over)the)memory)bus)• ProtecAon:)via)bits)in)pagetable)entries)• OS+MMU+devices)configure)mappings)17)Memory-Mapped I/O!Keyboard)Registers)Video)Registers)&)Memory)Audio)Registers)Physical)Address))Space)RAM)Virtual)Address))Space)18)Device Drivers!Programmed)I/O))!char!read_kbd()!{!do!{!!!sleep();!!!status!=!inb(0x64);!}!while!(!(status!&!1));!return!inb(0x60);!}!Memory)Mapped)I/O)struct!kbd!{!!!char!status,!pad[3];!!!char!data,!pad[3];!};!kbd!*k!=!mmap(...);!!char!read_kbd()!{!do!{!!!sleep();!!!status!=!kH>status;!}!while!(!(status!&!1));!return!kH>data;!})19)Communication Method!Q:)How)does)program)learn)device)is)ready/done?)A:)Polling:)Periodically)check)I/O)status)register)• If)device)ready,)do)operaAon)• If)device)done,)…)• If)error,)take)acAon))Pro?)Con?)• Predictable)Aming)&)inexpensive)• But:)wastes)CPU)cycles)if)nothing)to)do)• Efficient)if)there)is)always)work)to)do)Common)in)small,)cheap,)or)real<Ame)embedded)systems)SomeAmes)for)very)acAve)devices)too…)20)Communication Method!Q:)How)does)program)learn)device)is)ready/done?)A:)Interrupts:)Device)sends)interrupt)to)CPU)• Cause)idenAfies)the)interrupAng)device)• interrupt)handler)examines)device,)decides)what)to)do)Priority)interrupts)• Urgent)events)can)interrupt)lower<priority)interrupt)handling)• OS)can))disable))defer)interrupts)21)Typical x86 PC I/O System!22)I/O Data Transfer!How)to)talk)to)device?))Programmed)I/O)or)Memory<Mapped)I/O)How)to)get)events?)Polling)or)Interrupts)How)to)transfer)lots)of)data?!diskH>cmd!=!READ_4K_SECTOR;!diskH>data!=!12;!while!(!(diskH>status!&!1)!{!}!for!(i!=!0..4k)!!!buf[i]!=!diskH>data;!23)DMA: Direct Memory Access!Programmed)I/O)xfer:))Device)))CPU))RAM)for)(i)=)1)..)n))• CPU)issues)read)request)• Device)puts)data)on)bus)&)CPU)reads)into)registers)• CPU)writes)data)to)memory)CPU) RAM)DISK)24)I/O Data Transfer!Q:)How)to)transfer)lots)of)data)efficiently?!A:)Have)device)access)memory)directly)Direct)memory)access)(DMA))• OS)provides)starAng)address,)length)• controller)(or)device))transfers)data)autonomously)• Interrupt)on)compleAon)/)error)25)DMA: Direct Memory Access!Programmed)I/O)xfer:))Device)))CPU))RAM)for)(i)=)1)..)n))• CPU)issues)read)request)• Device)puts)data)on)bus)&)CPU)reads)into)registers)• CPU)writes)data)to)memory)DMA)xfer:))Device))RAM)• CPU)sets)up)DMA)request)• for)(i)=)1)...)n)))Device)puts)data)on)bus))&)RAM)accepts)it)CPU) RAM)DISK)CPU) RAM)DISK)26)DMA Example!DMA)example:)reading)from)audio)(mic))input)• DMA)engine)on)audio)device…)or)I/O)controller)…)or)…)int!dma_size!=!4*PAGE_SIZE;!int!*buf!=!alloc_dma(dma_size);!...!devH>mic_dma_baseaddr!=!(int)buf;!devH>mic_dma_count!=!dma_len;!devH>cmd!=!DEV_MIC_INPUT!|!DEV_INTERRUPT_ENABLE!|!DEV_DMA_ENABLE;!27)DMA Issues (1):
View Full Document