Confusion about memory mapped I/O
Luis R. Rodriguez
lrodriguez at atheros.com
Thu Oct 15 10:17:52 PDT 2009
On Thu, Oct 15, 2009 at 02:04:38AM -0700, Amit Uttamchandani wrote:
> On Thu, Oct 15, 2009 at 01:49:46AM -0700, Benoit Donnette wrote:
> > > Hi,
> > >
> > > I am trying to understand the magic behind memory mapped I/O in linux
> > > device drivers. I understand the concepts behind setting up memory
> > > mapped I/O but I am confused about how the data (once written into
> > > memory) gets transferred onto the bus and onto the peripheral.
> > "Memory mapped I/O" means taht through the specified address, mapped in
> > the address space, you actually send data to the device.
> > It means you map I/O buffers on the device into addressable memory. After
> > that, everything you write at these addresses will go to the device as set
> > up, not to memory.
> Ok that definitely makes more sense, everything is written directly
> to the registers on the device not main memory.
> > >
> > > E.g. many network drivers use memory mapped I/O and this makes it quite
> > > generic but how do you specify the bus in all this?
> > All the memory mapped I/O setup does the job.
> I guess this is the part I am getting confused. For example ethoc.c sets
> up everything as memory mapped IO. I need to hookup the actual ethoc
> device to the processor. This will be done using SPI. So how does the
> 'memory mapped I/O setup' know to use SPI to read/write the data.
The read/write calls are bus agnostic -- but that also doesn't mean
you'd use MMIO for all types of buses. For instance USB devices do
not use it.
The non-bus agnostic part is the actual MMIO setup. For instance,
look at ioremap_nocache()  which makes bus memory CPU accessible
via the readb/readw/readl/writeb/writew/writel functions. Your PCI
driver would use this when using the pci_iomap() for example for
MMIO devices, the bus part being done right before the call .
I take it SPI has similar wrappers.
More information about the devel