From: Joshua Wise Date: Thu, 4 Dec 2008 20:32:01 +0000 (-0500) Subject: paging for fb X-Git-Url: http://git.joshuawise.com/netwatch.git/commitdiff_plain/e8f20fe7be6203b50e049bbaa057acc7f0b0d593?ds=sidebyside paging for fb --- diff --git a/aseg-paging/pagingstub.c b/aseg-paging/pagingstub.c index 7d430b9..678f2ea 100644 --- a/aseg-paging/pagingstub.c +++ b/aseg-paging/pagingstub.c @@ -23,14 +23,26 @@ void ps_switch_stack (void (*call)(), int stack); asm volatile("mov %%cr0, %0" : "=r" (_temp__)); \ _temp__; \ }) - - #define set_cr3(value) \ { \ register unsigned int _temp__ = (value); \ asm volatile("mov %0, %%cr3" : : "r" (_temp__)); \ } + +#define get_cr4() \ + ({ \ + register unsigned int _temp__; \ + asm volatile("mov %%cr4, %0" : "=r" (_temp__)); \ + _temp__; \ + }) +#define set_cr4(value) \ + { \ + register unsigned int _temp__ = (value); \ + asm volatile("mov %0, %%cr4" : : "r" (_temp__)); \ + } + #define CR0_PG 0x80000000 +#define CR4_PSE 0x00000010 #define MAP_FLAGS (PTE_PRESENT | PTE_READ_WRITE) @@ -97,6 +109,15 @@ int addmap(unsigned long vaddr, unsigned long paddr) return 0; } +int addmap_4m(unsigned long vaddr, unsigned long paddr) +{ + /* PDE_PAGE_SIZE = (1 << 7) */ + ((unsigned long *)p2v((unsigned long)pd))[PDE_FOR(vaddr)] = + paddr | PDE_PRESENT | PDE_READ_WRITE | PDE_PAGE_SIZE; + + return 0; +} + void *demap(unsigned long client_pd, unsigned long vaddr) { unsigned long pde = ((unsigned long *)p2v(client_pd))[PDE_FOR(vaddr)]; @@ -158,6 +179,7 @@ void c_entry(void) /* Enable paging. */ set_cr3((unsigned long)pd); + set_cr4(get_cr4() | CR4_PSE); /* ITT, we 4MByte page. */ set_cr0(get_cr0() | CR0_PG); outb(0x80, 0x03); paging_enb = 1; diff --git a/aseg-paging/smi.c b/aseg-paging/smi.c index e1304f3..f2b574f 100644 --- a/aseg-paging/smi.c +++ b/aseg-paging/smi.c @@ -46,20 +46,13 @@ void smi_entry(void) for (p = 0; ass[p][0] != -1; p++) { int x, y; - unsigned long lasta = 0; - unsigned long *lastmap; for (y = 0; y < 8; y++) for (x = 0; x < 8; x++) { - unsigned long a = - (unsigned long) fb->fbaddr + - ((y+ass[p][1]*8) * fb->curmode.xres + ass[p][0]*8 + x) * 4; - if ((a & ~4095) != (lasta & ~4095)) - { - lastmap = (unsigned long *)((unsigned long)p2v(a) & ~4095); - lasta = a; - } - lastmap[(a & 4095) / 4] = 0xFF0000FF; + unsigned long *a = + (unsigned long*) fb->fbaddr + + ((y+ass[p][1]*8) * fb->curmode.xres + ass[p][0]*8 + x); + *a = 0xFF0000FF; } } } diff --git a/include/paging.h b/include/paging.h index 90c44e9..0f864d8 100644 --- a/include/paging.h +++ b/include/paging.h @@ -4,6 +4,7 @@ extern unsigned long v2p(void *virt); extern void *p2v(unsigned long phys); extern int addmap(unsigned long vaddr, unsigned long paddr); +extern int addmap_4m(unsigned long vaddr, unsigned long paddr); extern void *demap(unsigned long _pd, unsigned long vaddr); #endif diff --git a/video/tnt2.c b/video/tnt2.c index 5ab5f02..32e646a 100644 --- a/video/tnt2.c +++ b/video/tnt2.c @@ -3,6 +3,7 @@ #include #include #include +#include static void tnt2_getvmode(void *priv); @@ -39,14 +40,21 @@ static void tnt2_getvmode(void *priv) static int tnt2_probe(struct pci_dev *pci, void *data) { + unsigned int p; + if (pci->bars[1].type != PCI_BAR_MEMORY32) { output("TNT2 BAR1 is not memory32?"); return 0; } - tnt2_fb.fbaddr = (void *)pci->bars[1].addr; + + /* Map 32M of memory. */ + for (p = 0; p < 32; p += 4) + addmap_4m(0x40000000 + p*1024*1024, pci->bars[1].addr + p*1024*1024); + tnt2_fb.fbaddr = (void *)0x40000000; + fb = &tnt2_fb; - outputf("Found TNT2 with FB at %08x", tnt2_fb.fbaddr); + outputf("Found TNT2 with FB at %08x, mapped to %08x", pci->bars[1].addr, tnt2_fb.fbaddr); return 1; }