2016-12-24 71 views
0

我嘗試使用UIO而不是直接映射/dev/mem後,無法在Xilinx Zynq上映射物理內存。雖然計劃是以普通用戶身份運行應用程序,而不是root,但仍以root運行該應用程序。mmap在UIO設備上出現EINVAL錯誤

顯然,第一次映射是成功的,而其餘完成到相同的文件描述符12/dev/uio/ps2pl)失敗。雖然明顯的差異是偏移量,但它在範圍之內(請參閱設備樹),並且頁面對齊正確。此應用程序與/dev/mem配合良好。

通過用strace運行中觀察到的錯誤是:

open("/dev/uio/ps2pl", O_RDWR|O_SYNC) = 12 
open("/sys/bus/i2c/devices/0-0050/eeprom", O_RDONLY) = 13 
fstat64(13, {st_mode=S_IFREG|0600, st_size=8192, ...}) = 0 
_llseek(13, 0, [0], SEEK_SET)   = 0 
read(13, "\1\1\0\0\0\0\0\0", 8)   = 8 
read(13, "(\\\217\2(\\\217\00233333333\0\0\0\0\0\0\0\0(\\\217\2(\\\217\2"..., 4096) = 4096 
close(13)        = 0 
mmap2(NULL, 48, PROT_READ|PROT_WRITE, MAP_SHARED, 12, 0) = 0xb6f93000 
mmap2(NULL, 48, PROT_READ|PROT_WRITE, MAP_SHARED, 12, 0x400000) = -1 EINVAL (Invalid argument) 
mmap2(NULL, 196608, PROT_READ|PROT_WRITE, MAP_SHARED, 12, 0x200000) = -1 EINVAL (Invalid argument) 
mmap2(NULL, 196608, PROT_READ|PROT_WRITE, MAP_SHARED, 12, 0x100000) = -1 EINVAL (Invalid argument) 
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x1f} --- 
+++ killed by SIGSEGV +++ 
Segmentation fault 

作爲裝入內核的設備樹:

# /root/dtc/dtc -f -I fs /sys/firmware/devicetree/base/amba_pl/ps2pl\@40000000/ 
ERROR (name_properties): "name" property in/is incorrect ("ps2pl" instead of base node name) 
Warning: Input tree has errors, output forced 
/dts-v1/; 

/{ 
    reg = <0x40000000 0x40000000>; 
    name = "ps2pl"; 
    interrupts = <0x0 0x44 0x4>; 
    compatible = "generic-uio"; 
    interrupt-parent = <0x3>; 
}; 

的UIO映射的尺寸足夠大,以容納上述mmap尺寸和補償:

# cat /sys/devices/soc0/amba_pl/40000000.ps2pl/uio/uio0/maps/map0/size 
0x40000000 

回答

0

對於UIO設備,對於/dev/mem,偏移的處理方式不同。 不可能使用任意偏移量,而只能映射每個區域的開始。僅具有一個區域在設備樹中定義的上面的例子,但也可以定義多個區域:

reg = <0x40000000 0x10000>, 
     <0x40010000 0x10000>, 
     <0x40020000 0x10000>, 
     <0x40030000 0x10000>; 
reg-names = "region0", "id", "region2", "gpio"; 

訪問每個區域/映射不是顯而易見的,因爲這裏描述: https://lwn.net/Articles/232575/

偏移用於訪問n個區域應該是:

n * sysconf(_SC_PAGESIZE) 

ARM的頁面大小爲12位的窗口0x1000

一些更通用的文檔。 http://elinux.org/images/b/b0/Uio080417celfelc08.pdf

相關問題