File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 29
29
*/
30
30
31
31
uintptr_t mmio (Thread * t , uintptr_t addr , off_t count , int flags ) {
32
+ off_t offset = addr & ~(PAGE_SIZE - 1 );
33
+ size_t pageCount = (count + PAGE_SIZE - 1 ) / PAGE_SIZE ;
34
+ if (addr & ~(PAGE_SIZE - 1 )) pageCount ++ ;
32
35
36
+ if (flags & MMIO_ENABLE ) {
37
+ // creating a memory mapping
38
+ int pageFlags = PLATFORM_PAGE_PRESENT | PLATFORM_PAGE_USER ;
39
+ if (flags & MMIO_W ) pageFlags |= PLATFORM_PAGE_WRITE ;
40
+ if (flags & MMIO_X ) pageFlags |= PLATFORM_PAGE_EXEC ;
41
+
42
+ uintptr_t virt = vmmAllocate (USER_MMIO_BASE , USER_LIMIT_ADDRESS , pageCount , VMM_USER );
43
+ if (!virt ) return 0 ;
44
+
45
+ for (int i = 0 ; i < pageCount ; i ++ )
46
+ platformMapPage (virt + (i * PAGE_SIZE ), addr + (i * PAGE_SIZE ), pageFlags );
47
+
48
+ return virt | offset ;
49
+ } else {
50
+ // deleting a memory mapping
51
+ if (addr < USER_MMIO_BASE ) return addr ;
52
+
53
+ for (int i = 0 ; i < pageCount ; i ++ )
54
+ platformMapPage (addr + (i * PAGE_SIZE ), 0 , 0 );
55
+
56
+ return 0 ;
57
+ }
33
58
}
You can’t perform that action at this time.
0 commit comments