Assorted Project 4 Notes
Joshua Wise
Quick overview
P4 this semester
How it all fits together
P4 and the real world
Project 4
"What's Project 4 this semester?"
A small extension to your Project 3 kernel...
Sound Blaster 16 driver
Kernel components
Driver and syscall interface
Shouldn't be too difficult concurrencywise...
...but the hardware...
Why SB16?
Hugely
popular card
About 2347845923854 clones
Everybody
advertised being "Sound Blaster Compatible"
Emulated by everybody, too
...but Simics...
ISA
Saves you the hassle of learning about PCI
Easily programmable
Designed to be programmed in assembly
Overview of the SB16
Command interface distinct from data interface
DMA interface off-chip
Cannot talk directly to memory!
You get to program each of the bits
The SB16
Where is it?
You get to go looking for it
Has 'command queues'
Playback
"Wake me up after
n
samples"
Reads samples from the DMA controller, who knows nothing about this number
n
n
carefully chosen so that you can refill the buffer
The DMA Talk
Who here knows what DMA stands for?
Mechanism for a device to get data from the host
Without
intervention on each byte, word, qword, ...
Basic idea
Kernel says "Here's how to get to some memory, have at"
Some time later, device comes back
A Device's Worth
DMA engine usually tightly coupled to each device
How about 'on the same chip'?
Bus-master
DMA
Mechanism:
Device asks for a word
DMA engine says either "OK!", or "Uh-oh"
Host sets up DMA engine, then tells DMA engine and device to go ahead.
DMA buffer strategies
Simplest?
Buffer, length, done.
A little better?
List of buffers and lengths
What's better than a list?
Especially if the hardware guys are stuck with implementing it?
Linked list
of buffers and lengths!
Used on many network cards
Some buffers can have flags associated with them
Typical scatter-gather setup
ISA DMA
Like everything else on the PC, DMA is sad
Logic very expensive in the late 1980s
DMA controller goes with the
bus
, not the card
What you will implement is a crazy part of PC history, and
not
"how DMA works" in the real world.
Your buffer
Back to the SB16!
DMA controller will be programmed
You tell it:
Location of buffer (over the course of many writes)
Size of buffer
It feeds samples
and loops
Buffer strategy, part 1
Naive strategy?
Fill it all up, then tell the sound card to interrupt you after reading the whole thing
When woken up, you go fill it up again
Buffer strategy, part 1.5
What went wrong?
Well, the interrupt didn't really get there in time, maybe
Or even if it did, by the time you started copying data...
Old data got played, and it sounds
pretty bad.
Buffer strategy, part 2
We really need
two
buffers
While we're filling one, the card is playing from the other
We're
guaranteed
not to intersect the card's play pointer!
Buffer strategy, part 2.5
...except our DMA controller sucks.
We only get one buffer. :(
So let's split the buffer in the middle.
Tell the card the buffer is half as big as it is
Not just 2
Since the buffer loops, it might as well be one long buffer
Let's consider a different strategy:
Interrupt every N
For N <<<< the buffer size, we can see it like this:
Pick a N, any N
If we get some interrupt, what can we tell?
We know where the card just played from... ...so we know what's not in use... ...so we know what we can fill.
This is another possible strategy.
Which you choose is a
design decision.
(Sorry.)
In Summary
Sound is fun
Buffers are a pain
DMA controllers are weird
You're lucky you're not using PCI
Have fun with this!