ref: 6184a4ef2eba1d49f0386e9ce94f4877d3d9edb2
parent: 182e18ecffa579b06d88b4d9bdd1b87f257b5936
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Jun 6 11:23:50 EDT 2020
devvga: use 64-bit physical addresses for framebuffer
--- a/sys/src/9/pc/devvga.c
+++ b/sys/src/9/pc/devvga.c
@@ -188,7 +188,7 @@
p = seprint(p, e, "hwaccel %s\n", hwaccel ? "on" : "off");
p = seprint(p, e, "hwblank %s\n", hwblank ? "on" : "off");
p = seprint(p, e, "panning %s\n", panning ? "on" : "off");
- p = seprint(p, e, "addr p %#p v %#p size %#ux\n",
+ p = seprint(p, e, "addr p 0x%.8llux v %#p size %#ux\n",
scr->paddr, scr->vaddr, scr->apsize);
p = seprint(p, e, "softscreen %s\n", scr->softscreen ? "on" : "off");
USED(p);
--- a/sys/src/9/pc/screen.c
+++ b/sys/src/9/pc/screen.c
@@ -95,7 +95,7 @@
screenaperture(int size, int align)
{
VGAscr *scr;
- ulong pa;
+ uvlong pa;
scr = &vgascreen[0];
@@ -115,7 +115,7 @@
* The driver will tell the card to use it.
*/
size = PGROUND(size);
- pa = upaalloc(-1, size, align);
+ pa = upaalloc(-1ULL, size, align);
if(pa == -1)
return -1;
scr->paddr = pa;
@@ -405,10 +405,10 @@
}
static char*
-vgalinearaddr0(VGAscr *scr, ulong paddr, int size)
+vgalinearaddr0(VGAscr *scr, uvlong paddr, int size)
{
int x, nsize;
- ulong npaddr;
+ uvlong npaddr;
/*
* new approach. instead of trying to resize this
@@ -455,8 +455,8 @@
static char*
vgalinearpci0(VGAscr *scr)
{
- ulong paddr;
int i, size, best;
+ uvlong paddr;
Pcidev *p;
p = scr->pci;
@@ -505,7 +505,7 @@
}
void
-vgalinearaddr(VGAscr *scr, ulong paddr, int size)
+vgalinearaddr(VGAscr *scr, uvlong paddr, int size)
{
char *err;
@@ -514,15 +514,15 @@
}
static char*
-bootmapfb(VGAscr *scr, ulong pa, ulong sz)
+bootmapfb(VGAscr *scr, uvlong pa, ulong sz)
{
- ulong start, end;
+ uvlong start, end;
Pcidev *p;
int i;
for(p = pcimatch(nil, 0, 0); p != nil; p = pcimatch(p, 0, 0)){
for(i=0; i<nelem(p->mem); i++){
- if(p->mem[i].bar & 1)
+ if(p->mem[i].size == 0 || (p->mem[i].bar & 1) != 0)
continue;
start = p->mem[i].bar & ~0xF;
end = start + p->mem[i].size;
@@ -575,7 +575,8 @@
{
VGAscr *scr;
int x, y, z;
- ulong chan, pa, sz;
+ uvlong pa;
+ ulong chan, sz;
char *s, *p, *err;
/* *bootscreen=WIDTHxHEIGHTxDEPTH CHAN PA [SZ] */
@@ -603,7 +604,7 @@
return;
sz = 0;
- pa = strtoul(p+1, &s, 0);
+ pa = strtoull(p+1, &s, 0);
if(pa == 0)
return;
if(*s++ == ' ')
@@ -658,7 +659,7 @@
conf[0] = '\0';
if(scr != nil && scr->paddr != 0 && scr->gscreen != nil)
- snprint(conf, sizeof(conf), "%dx%dx%d %s %#p %d\n",
+ snprint(conf, sizeof(conf), "%dx%dx%d %s 0x%.8llux %d\n",
scr->gscreen->r.max.x, scr->gscreen->r.max.y,
scr->gscreen->depth, chantostr(chan, scr->gscreen->chan),
scr->paddr, scr->apsize);
--- a/sys/src/9/pc/screen.h
+++ b/sys/src/9/pc/screen.h
@@ -92,7 +92,7 @@
int useflush;
- uintptr paddr; /* frame buffer */
+ uvlong paddr; /* frame buffer */
void* vaddr;
int apsize;
@@ -129,7 +129,7 @@
extern int hwaccel; /* use hw acceleration */
extern int hwblank; /* use hw blanking */
extern int panning; /* use virtual screen panning */
-extern void addvgaseg(char*, ulong, ulong);
+extern void addvgaseg(char*, uvlong, ulong);
extern Memdata* attachscreen(Rectangle*, ulong*, int*, int*, int*);
extern void flushmemscreen(Rectangle);
extern void cursoron(void);
@@ -154,7 +154,7 @@
extern void vgascreenwin(VGAscr*);
extern void vgaimageinit(ulong);
extern void vgalinearpci(VGAscr*);
-extern void vgalinearaddr(VGAscr*, ulong, int);
+extern void vgalinearaddr(VGAscr*, uvlong, int);
extern void vgablank(VGAscr*, int);
extern Lock vgascreenlock;
--- a/sys/src/9/pc/vga.c
+++ b/sys/src/9/pc/vga.c
@@ -252,14 +252,19 @@
}
void
-addvgaseg(char *name, ulong pa, ulong size)
+addvgaseg(char *name, uvlong pa, ulong size)
{
Physseg seg;
+ if((uintptr)pa != pa || size == 0 || -(uintptr)pa < size){
+ print("addvgaseg %s: bad address %llux-%llux pc %#p\n",
+ name, pa, pa+size, getcallerpc(&name));
+ return;
+ }
memset(&seg, 0, sizeof seg);
seg.attr = SG_PHYSICAL | SG_DEVICE | SG_NOEXEC;
seg.name = name;
- seg.pa = pa;
+ seg.pa = (uintptr)pa;
seg.size = size;
addphysseg(&seg);
}