Commit 5972354
tools: fall back to PAGE_SIZE mmap when /dev/mem rejects 64 KiB window (#172)
mem_reg() always mmap()s a 64 KiB window so consecutive register reads
in the same SoC block hit a cache. On kernels built with
CONFIG_IO_STRICT_DEVMEM=y (the kernel default since v4.6, and what the
OpenIPC hi3516cv6xx defconfig currently ships) any /dev/mem mapping
whose range overlaps a page already claimed by a driver via
request_mem_region() is rejected with EPERM, even for root.
On Hi3516CV608 the very first probe touches SCSYSID at 0x11020EE0.
The 64 KiB window [0x11020000..0x1102FFFF] covers 0x11029000, claimed
by the PWM driver, so mmap fails and ipctool aborts before printing
the chip name -- even though the SYSCTRL page itself is unclaimed and
readable.
When EPERM is observed, retry the mmap with a single PAGE_SIZE window
aligned to the requested address. That unblocks chip-ID, HPM, DDR PHY
and any other register block whose own page isn't kernel-claimed.
Pages that *are* claimed (CRG/clocks, I2C, SPI, GPIO, UART) still need
the kernel-side companion fix in the OpenIPC firmware defconfig.
Cache invalidation is rewritten to track the actual loaded window
range instead of comparing against a fixed 64 KiB offset, so the
fallback path's smaller window still benefits from the read-side
cache for adjacent registers in the same page.
Verified on OpenIPC hi3516cv6xx (kernel 5.10.221, CONFIG_STRICT_DEVMEM
and CONFIG_IO_STRICT_DEVMEM both =y): before the patch ipctool exited
with "read_mem_reg mmap error: Operation not permitted (1)"; after,
it correctly identifies model 3516CV608 and emits NOR/RAM/firmware
sections of the YAML report.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 56a3696 commit 5972354
1 file changed
Lines changed: 24 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | | - | |
46 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| 57 | + | |
56 | 58 | | |
57 | 59 | | |
58 | 60 | | |
| |||
65 | 67 | | |
66 | 68 | | |
67 | 69 | | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
78 | 87 | | |
79 | 88 | | |
80 | 89 | | |
| |||
87 | 96 | | |
88 | 97 | | |
89 | 98 | | |
90 | | - | |
| 99 | + | |
91 | 100 | | |
92 | | - | |
| 101 | + | |
93 | 102 | | |
94 | 103 | | |
95 | 104 | | |
| |||
0 commit comments