Page MenuHomeFreeBSD

riscv: smarter DMAP construction (again)
AcceptedPublic

Authored by mhorne on Wed, Jan 14, 5:18 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Jan 18, 9:28 AM
Unknown Object (File)
Thu, Jan 15, 8:54 AM
Unknown Object (File)
Thu, Jan 15, 1:53 AM
Unknown Object (File)
Wed, Jan 14, 11:55 PM
Unknown Object (File)
Wed, Jan 14, 10:55 PM
Unknown Object (File)
Wed, Jan 14, 5:27 PM

Details

Summary

Extend pmap_bootstrap_dmap() to build the DMAP with 4K-page granularity.

Recently we have been approximating it with 2MB mappings. The motivation
again is the problematic FU540 hardware, which seems to require more
accurate mappings still to avoid triggering its PMP errata.

Although this hardware alone is of little consequence, constructing the
DMAP accurately/correctly may help avoid future surprises.

The implementation contains some repetitive code. This could be
expressed differently, but my guiding principle for these early routines
is that being simple and explicit about what we are doing makes them
easier to comprehend.

See also 762a3224cde6 ("riscv: smarter DMAP construction).

Test Plan

Booted in QEMU, and on Allwinner D1. Testing on the unleashed board to be performed by @maciphone2_googlemail.com.

With some prints added to pmap_bootstrap_dmap(), the ranges are shown to be constructed more accurately:

map_bootstrap 275c00000 e9e000
physmap_idx 14
min_pa 80080000
max_pa 280000000
loop 0; pa=0x80080000, endpa=0x27dc00000, va=0xffffffd000080000
        384 L3; 511 L2; 6 L1; 494 L2; 0 L3
loop 2; pa=0x27dc01000, endpa=0x27de59000, va=0xffffffd1fdc01000
        600 L3
loop 4; pa=0x27de61000, endpa=0x27de69000, va=0xffffffd1fde61000
        8 L3
loop 6; pa=0x27de6a000, endpa=0x27de6b000, va=0xffffffd1fde6a000
        1 L3
loop 8; pa=0x27de8d000, endpa=0x27eed2000, va=0xffffffd1fde8d000
        371 L3; 7 L2; 210 L3
loop 10; pa=0x27eed3000, endpa=0x27f6bd000, va=0xffffffd1feed3000
        301 L3; 3 L2; 189 L3
loop 12; pa=0x27f6bf000, endpa=0x280000000, va=0xffffffd1ff6bf000
        321 L3; 4 L2; 0 L3
---<<BOOT>>---

...

Physical memory chunk(s):
  0x80080000 - 0x27fffffff,  8191 MB (2097024 pages)
Excluded memory regions:
  0x275c00000 - 0x276c1afff,    16 MB (   4123 pages) NoAlloc 
  0x27dc00000 - 0x27dc00fff,     0 MB (      1 pages) NoAlloc 
  0x27de59000 - 0x27de60fff,     0 MB (      8 pages) NoAlloc 
  0x27de69000 - 0x27de69fff,     0 MB (      1 pages) NoAlloc 
  0x27de6b000 - 0x27de8cfff,     0 MB (     34 pages) NoAlloc 
  0x27eed2000 - 0x27eed2fff,     0 MB (      1 pages) NoAlloc 
  0x27f6bd000 - 0x27f6befff,     0 MB (      2 pages) NoAlloc 

...

Physical memory chunk(s):
0x0000000080080000 - 0x000000026acc7fff, 8233713664 bytes (2010184 pages)
0x0000000276c1b000 - 0x000000027dbfffff, 117329920 bytes (28645 pages)
0x000000027dc01000 - 0x000000027de58fff, 2457600 bytes (600 pages)
0x000000027de61000 - 0x000000027de68fff, 32768 bytes (8 pages)
0x000000027de6a000 - 0x000000027de6afff, 4096 bytes (1 pages)
0x000000027de8d000 - 0x000000027eed1fff, 17059840 bytes (4165 pages)
0x000000027eed3000 - 0x000000027f6bcfff, 8298496 bytes (2026 pages)
0x000000027f6bf000 - 0x000000027fffffff, 9703424 bytes (2369 pages)
avail memory = 8341520384 (7955 MB)

Demonstrate further with read of excluded memory range starting at 0x27de6b000, via /dev/mem.

Before:

# dd if=/dev/mem bs=1 count=128 of=./outputbytes iseek=0x27de6b000
128+0 records in
128+0 records out
128 bytes transferred in 0.004856 secs (26358 bytes/sec)

After:

# dd if=/dev/mem bs=1 count=128 of=./outputbytes iseek=0x27de6b000
dd: /dev/mem: Bad address
0+0 records in
0+0 records out
0 bytes transferred in 0.002467 secs (0 bytes/sec)

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 69882
Build 66765: arc lint + arc unit