ref: 21e4d88a51303bc41cc28aba77d8f65d7776e39e
parent: 5f3e72eb844582693e1b0bd4f73be59ab822531e
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Jun 6 10:43:24 EDT 2020
pc, pc64: use 64-bit physical addresses for vmap() and upaalloc()
--- a/sys/src/9/pc/fns.h
+++ b/sys/src/9/pc/fns.h
@@ -192,10 +192,10 @@
uvlong tscticks(uvlong*);
ulong umballoc(ulong, ulong, ulong);
void umbfree(ulong, ulong);
-ulong upaalloc(ulong, ulong, ulong);
-void upafree(ulong, ulong);
+uvlong upaalloc(uvlong, ulong, ulong);
+void upafree(uvlong, ulong);
void vectortable(void);
-void* vmap(ulong, int);
+void* vmap(uvlong, int);
int vmapsync(ulong);
void vmxprocrestore(Proc *);
void vmxshutdown(void);
--- a/sys/src/9/pc/memory.c
+++ b/sys/src/9/pc/memory.c
@@ -244,14 +244,14 @@
* does not map the physical address into virtual memory.
* Call vmap to do that.
*/
-ulong
-upaalloc(ulong pa, ulong size, ulong align)
+uvlong
+upaalloc(uvlong pa, ulong size, ulong align)
{
- return (ulong)memmapalloc(pa == -1UL ? -1ULL : (uvlong)pa, size, align, MemUPA);
+ return memmapalloc(pa, size, align, MemUPA);
}
void
-upafree(ulong pa, ulong size)
+upafree(uvlong pa, ulong size)
{
memmapfree(pa, size, MemUPA);
}
--- a/sys/src/9/pc/mmu.c
+++ b/sys/src/9/pc/mmu.c
@@ -71,7 +71,6 @@
{
ulong x, *p;
ushort ptr[3];
- vlong v;
if(0) print("vpt=%#.8ux vpd=%#p kmap=%#.8ux\n",
VPT, vpd, KMAP);
@@ -537,11 +536,16 @@
* Add a device mapping to the vmap range.
*/
void*
-vmap(ulong pa, int size)
+vmap(uvlong pa, int size)
{
int osize;
ulong o, va;
+ if(pa < BY2PG || size <= 0 || ((pa+size) >> 32) != 0 || size > VMAPSIZE){
+ print("vmap pa=%llux size=%d pc=%#p\n", pa, size, getcallerpc(&pa));
+ return nil;
+ }
+
/*
* might be asking for less than a page.
*/
@@ -549,17 +553,12 @@
o = pa & (BY2PG-1);
pa -= o;
size += o;
-
size = ROUND(size, BY2PG);
- if(pa == 0){
- print("vmap pa=0 pc=%#p\n", getcallerpc(&pa));
- return nil;
- }
ilock(&vmaplock);
if((va = vmapalloc(size)) == 0
|| pdbmap(MACHP(0)->pdb, pa|PTEUNCACHED|PTEWRITE, va, size) < 0){
iunlock(&vmaplock);
- return 0;
+ return nil;
}
iunlock(&vmaplock);
/* avoid trap on local processor
--- a/sys/src/9/pc64/fns.h
+++ b/sys/src/9/pc64/fns.h
@@ -191,12 +191,12 @@
uvlong tscticks(uvlong*);
ulong umballoc(ulong, ulong, ulong);
void umbfree(ulong, ulong);
-ulong upaalloc(ulong, ulong, ulong);
-void upafree(ulong, ulong);
+uvlong upaalloc(uvlong, ulong, ulong);
+void upafree(uvlong, ulong);
void vectortable(void);
void vmxprocrestore(Proc *);
void vmxshutdown(void);
-void* vmap(uintptr, int);
+void* vmap(uvlong, int);
void vunmap(void*, int);
void wbinvd(void);
void writeconf(void);
--- a/sys/src/9/pc64/mmu.c
+++ b/sys/src/9/pc64/mmu.c
@@ -579,14 +579,17 @@
* synchronization is being done.
*/
void*
-vmap(uintptr pa, int size)
+vmap(uvlong pa, int size)
{
uintptr va;
int o;
- if(pa+size > VMAPSIZE)
- return 0;
+ if(pa < BY2PG || size <= 0 || -pa < size || pa+size > VMAPSIZE){
+ print("vmap pa=%llux size=%d pc=%#p\n", pa, size, getcallerpc(&pa));
+ return nil;
+ }
va = pa+VMAP;
+
/*
* might be asking for less than a page.
*/