In memory mapped io for the raspberry pi, does the cpu write to ram and doe the io device then read that section of ram the cpu wrote to using dma? I'm getting this impression by looking at the diagram from the BCM2835 ARM Peripherals guide. Can someone please clear up any misconceptions I have.
Asked
Active
Viewed 102 times
2
-
1_"does the cpu write to ram"_ - Not quite: A computer's memory-address-space does not get mapped directly to physical RAM: address ranges can be mapped to physical devices and IO ports and other non-RAM _things_, which is how memory-mapped IO works: because for complex-hardware (e.g. an OHCI/XHCI USB Controller) there's often hundreds or thousands of hardware registers that software needs to read/write from, and so using old-style IO-port-numbers just adds complexity compared to just mapping those registers directly into computer memory-address-space. – Dai Feb 20 '23 at 00:56
-
Thanks for the response. But now I'm wondering how it is possible for the same address bus to be used for accessing ram and i/o device. How does the computer redirect the bus to i/o devices when it is accessing memory mapped to an i/o device? – EskimoJones Feb 20 '23 at 01:33
-
I can't speak for Raspberrry Pi's hardware specifically, but _in principle_ the same address bus **is** used: except instead of hooking up the address-lines to only the SRAM/DRAM's CS ([_Chip Select_](https://en.wikipedia.org/wiki/Chip_select)) pins, the address-lines corresponding to the memory-address region for memory-mapped IO is hooked-up to the CS-equivalent pin for some non-RAM device, such as some IO chip. (Of course, in practice in modern hardware there's an MMU which handles the actual address space mapping to RAM chips vs. IO chips, but in the 1980s hard-wiring was common. – Dai Feb 20 '23 at 01:37
-
Thanks. And to be sure because I'm a noob in hardware architecture, the physical addresses are translated into peripheral addresses that map to read/write operations for the i/o device's registers, right? – EskimoJones Feb 20 '23 at 01:56
-
The concept of separate "peripheral addresses" does not apply in the scenario I described - and read/write operations are a separate concept: all memory-mapping does is expose hardware registers to a computer's main address-space, so the triggers of actual read/write _operations_ (e.g. in a HDD controller, for example) have to be done via register read/writes (and interrupts for completion notifications), usually triggered simply by writing a particular value to a hardware register in that controller (which is why IO is inherently asynchronous). – Dai Feb 20 '23 at 02:00
-
Sorry. What I meant to say is that does memory mapping allow the cpu to read and write to the device's hardware registers? – EskimoJones Feb 20 '23 at 02:13
-
...that's basically the entire point of memory-mapping, yes. – Dai Feb 20 '23 at 02:33
-
You're fine - your questions are reasonable and the _dumb thing here_ really isn't you, it's that CS schools just don't teach students how software _really_ interfaces with hardware: I had to take entirely optional electives at my uni's EE school to learn things like that. So learning how Raspberry Pi works is also a great way to learn this stuff. Kudos to you. – Dai Feb 20 '23 at 02:55
-
Also, I really, really recommend _Retro Game Mechanics Explained_ on YouTube because he explains how things like memory-mapping and hardware/IO interfaces with game software in the NES/SNES which is all very relevant to programming today (they're timeless principles, after-all), such as with Ardunio and Pi: I especially recommend this video as it relates to your questions: https://www.youtube.com/watch?v=-U76YvWdnZM – Dai Feb 20 '23 at 02:58
-
Thanks a lot. You really helped. Also, I'm not in a CS school. I'm still in high school. – EskimoJones Feb 20 '23 at 05:34