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)
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)];
/* 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;
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;
}
}
}
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
#include <pci.h>
#include <output.h>
#include <fb.h>
+#include <paging.h>
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;
}