Date: Mon, 24 Nov 2025 10:38:21 -0600 From: Friedrich Doku <friedrichdoku2030@u.northwestern.edu> To: freebsd-hackers@freebsd.org Subject: mmap of PCI BAR0 returns 0s in userspace Message-ID: <CAD2_vGpvubqMCX3Oh-9ddTc2r3T=_SH%2B5Y8i0g%2BfcHWiHDUy6A@mail.gmail.com>
index | next in thread | raw e-mail
[-- Attachment #1 --] Hello, I'm working on a custom e1000 driver, and I want to map the MMIO addresses into userspace, so I wrote an e1000 driver using .d_mmap to do this, but for some reason I can only access the register values in the kernel and not in user space. I'm just getting all 0s in userspace. When I mmap this character device in userspace, the mapping succeeds, but reading from the pointer returns all zeros (0x00000000). I'm on aarch64. I'm even mapping the memory as VM_MEMATTR_UNCACHEABLE. Any suggestions? driver code <https://pastebin.com/25NKcH6U> user space program code <https://pastebin.com/kMNcFC8m> *DUMPING IN KERNEL* e1000_map module loaded. Device: /dev/e1000_map Mapping BAR0 Base: 0x70100000, Size: 0x20000 DEBUG: Kernel read of BAR0[0] (CTRL): 0x18100209 DEBUG: Kernel read of MAC: 98:b7:85:01:93:b5 *IN USER SPACE* === Intel E1000 Register Dump (Userspace) === e1000_map_mmap: offset=0x0, paddr=0x70100000 Device Control and Status: CTRL (0x00000): 0x00000000 STATUS (0x00008): 0x00000000 (Link: DOWN, Speed: 10Mbps) e1000_map_mmap: offset=0x5000, paddr=0x70105000 MAC Address: RAL (0x05400): 0x00000000 RAH (0x05404): 0x00000000 MAC: 00:00:00:00:00:00 === End of Register Dump === Best, Friedrich [-- Attachment #2 --] <div dir="ltr"><div><div><div>Hello,<br></div><br></div>I'm working on a custom e1000 driver, and I want to map the MMIO addresses into userspace, so I wrote an e1000 driver using .d_mmap to do this, but for some reason I can only access the register values in the kernel and not in user space. I'm just getting all 0s in userspace. <br><br>When I mmap this character device in userspace, the mapping succeeds, but reading from the pointer returns all zeros (0x00000000). I'm on aarch64. I'm even mapping the memory as <span style="font-family:Monaco,Menlo,Consolas,"Courier New",monospace;font-size:12px;font-style:normal;font-variant-ligatures:none;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:left;text-indent:0px;text-transform:none;word-spacing:0px;white-space:pre-wrap;background-color:rgba(232,232,232,0.04);text-decoration-style:initial;text-decoration-color:initial;display:inline;float:none;color:rgb(0,0,0)">VM_MEMATTR_UNCACHEABLE.</span><br></div><div><br></div><div>Any suggestions?<br><br></div><div><a href="https://pastebin.com/25NKcH6U">driver code</a><br></div><div><a href="https://pastebin.com/kMNcFC8m">user space program code</a></div><div><br><b>DUMPING IN KERNEL</b><br>e1000_map module loaded. Device: /dev/e1000_map<br>Mapping BAR0 Base: 0x70100000, Size: 0x20000<br>DEBUG: Kernel read of BAR0[0] (CTRL): 0x18100209<br>DEBUG: Kernel read of MAC: 98:b7:85:01:93:b5<br><br><b>IN USER SPACE</b><br>=== Intel E1000 Register Dump (Userspace) ===<br>e1000_map_mmap: offset=0x0, paddr=0x70100000<br>Device Control and Status:<br> CTRL (0x00000): 0x00000000<br> STATUS (0x00008): 0x00000000 (Link: DOWN, Speed: 10Mbps)<br>e1000_map_mmap: offset=0x5000, paddr=0x70105000<br><br>MAC Address:<br> RAL (0x05400): 0x00000000<br> RAH (0x05404): 0x00000000<br> MAC: 00:00:00:00:00:00<br>=== End of Register Dump ===<br><br></div><div>Best,<br></div><div>Friedrich</div></div>home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAD2_vGpvubqMCX3Oh-9ddTc2r3T=_SH%2B5Y8i0g%2BfcHWiHDUy6A>
