summaryrefslogtreecommitdiff
path: root/xc/programs/Xserver/hw/xfree86/int10/generic.c
diff options
context:
space:
mode:
Diffstat (limited to 'xc/programs/Xserver/hw/xfree86/int10/generic.c')
-rw-r--r--xc/programs/Xserver/hw/xfree86/int10/generic.c294
1 files changed, 117 insertions, 177 deletions
diff --git a/xc/programs/Xserver/hw/xfree86/int10/generic.c b/xc/programs/Xserver/hw/xfree86/int10/generic.c
index 5caf043f7..af12efe23 100644
--- a/xc/programs/Xserver/hw/xfree86/int10/generic.c
+++ b/xc/programs/Xserver/hw/xfree86/int10/generic.c
@@ -1,4 +1,4 @@
-/* $XFree86: xc/programs/Xserver/hw/xfree86/int10/generic.c,v 1.3 2000/02/18 16:23:23 dawes Exp $ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/int10/generic.c,v 1.9 2000/06/07 22:03:10 tsi Exp $ */
/*
* XFree86 int10 module
* execute BIOS int 10h calls in x86 real mode environment
@@ -14,6 +14,8 @@
#include "xf86int10.h"
#include "int10Defines.h"
+#define ALLOC_ENTRIES(x) ((V_RAM / x) - 1)
+
static CARD8 read_b(xf86Int10InfoPtr pInt,int addr);
static CARD16 read_w(xf86Int10InfoPtr pInt,int addr);
static CARD32 read_l(xf86Int10InfoPtr pInt,int addr);
@@ -28,10 +30,11 @@ static void write_l(xf86Int10InfoPtr pInt,int addr, CARD32 val);
typedef struct {
int shift;
- int pagesize_1;
int entries;
+ void* base;
void* vRam;
- memType *alloc_rec;
+ void* sysMem;
+ char* alloc;
} genericInt10Priv;
#define INTPriv(x) ((genericInt10Priv*)x->private)
@@ -47,8 +50,6 @@ int10MemRec genericMem = {
static void MapVRam(xf86Int10InfoPtr pInt);
static void UnmapVRam(xf86Int10InfoPtr pInt);
-static void setupTable(xf86Int10InfoPtr pInt, memType address,
- int loc,int size);
static void *sysMem = NULL;
@@ -57,11 +58,8 @@ xf86InitInt10(int entityIndex)
{
xf86Int10InfoPtr pInt;
int screen;
- void* intMem;
- void* vbiosMem;
- int pagesize;
- int entries;
- int shift;
+ void* base = 0;
+ void* vbiosMem = 0;
legacyVGARec vga;
screen = (xf86FindScreenForEntity(entityIndex))->scrnIndex;
@@ -74,18 +72,11 @@ xf86InitInt10(int entityIndex)
if (!xf86Int10ExecSetup(pInt))
goto error0;
pInt->mem = &genericMem;
- pagesize = xf86getpagesize();
pInt->private = (pointer)xnfcalloc(1,sizeof(genericInt10Priv));
- entries = SYS_SIZE / pagesize;
-
+ INTPriv(pInt)->alloc =
+ (pointer)xnfcalloc(1,sizeof(ALLOC_ENTRIES(getpagesize())));
pInt->scrnIndex = screen;
- INTPriv(pInt)->pagesize_1 = pagesize - 1;
- INTPriv(pInt)->entries = entries;
- INTPriv(pInt)->alloc_rec =
- xnfcalloc(1,sizeof(memType) * entries);
- for (shift = 0 ; (pagesize >> shift) ; shift++) {};
- shift -= 1;
- INTPriv(pInt)->shift = shift;
+ base = INTPriv(pInt)->base = xnfalloc(0xf0000);
/*
* we need to map video RAM MMIO as some chipsets map mmio
@@ -93,54 +84,43 @@ xf86InitInt10(int entityIndex)
*/
MapVRam(pInt);
- intMem = xnfalloc(pagesize);
- setupTable(pInt,(memType)intMem,0,pagesize);
- vbiosMem = xnfalloc(V_BIOS_SIZE);
-
#ifdef _PC
if (!sysMem)
sysMem = xf86MapVidMem(screen,VIDMEM_FRAMEBUFFER,SYS_BIOS,BIOS_SIZE);
- setupTable(pInt,(memType)sysMem,SYS_BIOS,BIOS_SIZE);
- if (xf86ReadBIOS(0,0,(unsigned char *)intMem,LOW_PAGE_SIZE) < 0) {
+ INTPriv(pInt)->sysMem = sysMem;
+
+ if (xf86ReadBIOS(0,0,(unsigned char *)base,LOW_PAGE_SIZE) < 0) {
xf86DrvMsg(screen,X_ERROR,"Cannot read int vect\n");
goto error1;
}
if (xf86IsEntityPrimary(entityIndex)) {
- int size;
int cs = MEM_RW(pInt,((0x10<<2)+2));
- xf86DrvMsg(screen,X_INFO,"Primary V_BIOS segmant is: 0x%x\n",cs);
- if (xf86ReadBIOS(cs << 4,0,(unsigned char *)vbiosMem,
- 0x10) < 0) {
- xf86DrvMsg(screen,X_ERROR,"Cannot read V_BIOS (1)\n");
- goto error1;
- }
- if (!((*(CARD8*)vbiosMem == 0x55)
- && (*((CARD8*)vbiosMem + 1) == 0xAA))) {
- xf86DrvMsg(screen,X_ERROR,"No V_BIOS found\n");
- goto error1;
+
+ vbiosMem = (unsigned char *)base + (cs << 4);
+ if (!int10_read_bios(screen,cs,vbiosMem)) {
+ cs = MEM_RW(pInt,((0x42<<2)+2));
+ vbiosMem = (unsigned char *)base + (cs << 4);
+ if (!int10_read_bios(screen,cs,vbiosMem)) {
+ cs = V_BIOS >> 4;
+ vbiosMem = (unsigned char *)base + (cs << 4);
+ if (!int10_read_bios(screen,cs,vbiosMem)) {
+ xf86DrvMsg(screen,X_ERROR,"No V_BIOS found\n");
+ goto error1;
+ }
+ }
}
+ xf86DrvMsg(screen,X_INFO,"Primary V_BIOS segment is: 0x%x\n",cs);
- size = *((CARD8*)vbiosMem + 2) * 512;
- if (xf86ReadBIOS(cs << 4,0,vbiosMem, size) < 0) {
- xf86DrvMsg(screen,X_ERROR,"Cannot read V_BIOS (2)\n");
- goto error1;
- }
- if (bios_checksum(vbiosMem,size)) {
- xf86DrvMsg(screen,X_ERROR,"Bad checksum of V_BIOS \n");
- goto error1;
- }
-
- setupTable(pInt,(memType)vbiosMem,cs<<4,size);
set_return_trap(pInt);
pInt->BIOSseg = cs;
} else {
reset_int_vect(pInt);
set_return_trap(pInt);
+ vbiosMem = (unsigned char *)base + V_BIOS;
if (!mapPciRom(pInt,(unsigned char *)(vbiosMem))) {
xf86DrvMsg(screen,X_ERROR,"Cannot read V_BIOS (3)\n");
goto error1;
}
- setupTable(pInt,(memType)vbiosMem,V_BIOS,V_BIOS_SIZE);
pInt->BIOSseg = V_BIOS >> 4;
pInt->num = 0xe6;
LockLegacyVGA(screen, &vga);
@@ -152,14 +132,14 @@ xf86InitInt10(int entityIndex)
sysMem = xnfalloc(BIOS_SIZE);
setup_system_bios((memType)sysMem);
}
- setupTable(pInt,(memType)sysMem,SYS_BIOS,BIOS_SIZE);
+ INTPriv(pInt)->sysMem = sysMem;
setup_int_vect(pInt);
set_return_trap(pInt);
+ vbiosMem = (unsigned char *)base + V_BIOS;
if (!mapPciRom(pInt,(unsigned char *)(vbiosMem))) {
xf86DrvMsg(screen,X_ERROR,"Cannot read V_BIOS (4)\n");
goto error1;
}
- setupTable(pInt,(memType)vbiosMem,V_BIOS,V_BIOS_SIZE);
pInt->BIOSseg = V_BIOS >> 4;
pInt->num = 0xe6;
LockLegacyVGA(screen, &vga);
@@ -169,10 +149,9 @@ xf86InitInt10(int entityIndex)
return pInt;
error1:
- xfree(vbiosMem);
- xfree(intMem);
+ xfree(base);
UnmapVRam(pInt);
- xfree(INTPriv(pInt)->alloc_rec);
+ xfree(INTPriv(pInt)->alloc);
xfree(pInt->private);
error0:
xfree(pInt);
@@ -184,7 +163,7 @@ static void
MapVRam(xf86Int10InfoPtr pInt)
{
int screen = pInt->scrnIndex;
- int pagesize = INTPriv(pInt)->pagesize_1 + 1;
+ int pagesize = getpagesize();
int size = ((VRAM_SIZE + pagesize - 1)/pagesize) * pagesize;
INTPriv(pInt)->vRam = xf86MapVidMem(screen,VIDMEM_MMIO,V_RAM,size);
@@ -194,7 +173,7 @@ static void
UnmapVRam(xf86Int10InfoPtr pInt)
{
int screen = pInt->scrnIndex;
- int pagesize = INTPriv(pInt)->pagesize_1 + 1;
+ int pagesize = getpagesize();
int size = ((VRAM_SIZE + pagesize - 1)/pagesize) * pagesize;
xf86UnMapVidMem(screen,INTPriv(pInt)->vRam,size);
@@ -209,17 +188,13 @@ MapCurrentInt10(xf86Int10InfoPtr pInt)
void
xf86FreeInt10(xf86Int10InfoPtr pInt)
{
- int pagesize;
-
if (!pInt)
return;
- pagesize = INTPriv(pInt)->pagesize_1 + 1;
if (Int10Current == pInt)
Int10Current = NULL;
- xfree(INTPriv(pInt)->alloc_rec[V_BIOS/pagesize]);
- xfree(INTPriv(pInt)->alloc_rec[0]);
+ xfree(INTPriv(pInt)->base);
UnmapVRam(pInt);
- xfree(INTPriv(pInt)->alloc_rec);
+ xfree(INTPriv(pInt)->alloc);
xfree(pInt->private);
xfree(pInt);
}
@@ -227,15 +202,14 @@ xf86FreeInt10(xf86Int10InfoPtr pInt)
void *
xf86Int10AllocPages(xf86Int10InfoPtr pInt,int num, int *off)
{
- void* addr;
- int pagesize = INTPriv(pInt)->pagesize_1 + 1;
- int num_pages = INTPriv(pInt)->entries;
+ int pagesize = getpagesize();
+ int num_pages = ALLOC_ENTRIES(pagesize);
int i,j;
-
+
for (i=0;i<num_pages - num;i++) {
- if (INTPriv(pInt)->alloc_rec[i] == 0) {
+ if (INTPriv(pInt)->alloc[i] == 0) {
for (j=i;j < num + i;j++)
- if ((INTPriv(pInt)->alloc_rec[j] != 0))
+ if (INTPriv(pInt)->alloc[j] != 0)
break;
if (j == num + i)
break;
@@ -245,134 +219,103 @@ xf86Int10AllocPages(xf86Int10InfoPtr pInt,int num, int *off)
}
if (i == num_pages - num)
return NULL;
+
+ for (j = i; j < i + num; j++)
+ INTPriv(pInt)->alloc[j] = 1;
- *off = i * pagesize;
- addr = xnfalloc(pagesize * num);
- setupTable(pInt,(memType)addr,*off,pagesize * num);
+ *off = (i + 1) * pagesize;
- return addr;
+ return (void *)
+ ((char*)INTPriv(pInt)->base + (i + 1) * pagesize);
}
void
xf86Int10FreePages(xf86Int10InfoPtr pInt, void *pbase, int num)
{
- int num_pages = INTPriv(pInt)->entries;
- int i,j;
- for (i = 0;i<num_pages - num; i++)
- if (INTPriv(pInt)->alloc_rec[i]==(memType)pbase) {
- for (j = 0; j < num; j++)
- INTPriv(pInt)->alloc_rec[i] = 0;
- break;
- }
- xfree(pbase);
- return;
+ int pagesize = getpagesize();
+ int first = ((unsigned long)pbase
+ - (unsigned long)INTPriv(pInt)->base)
+ / pagesize - 1;
+ int i;
+
+ for (i = first; i < first + num; i++)
+ INTPriv(pInt)->alloc[i] = 0;
}
-static void
-setupTable(xf86Int10InfoPtr pInt, memType address,int loc,int size)
-{
- int pagesize = INTPriv(pInt)->pagesize_1 + 1;
- int i,j,num;
-
- i = loc / pagesize;
- num = (size + pagesize - 1)/ pagesize; /* round up to the nearest page */
- /* boudary if size is not */
- /* multiple of pagesize */
- for (j = 0; j<num; j++) {
- INTPriv(pInt)->alloc_rec[i+j] = address;
- address += pagesize;
- }
-}
-
-#define OFF(addr) \
- ((addr) & (INTPriv(pInt)->pagesize_1))
-#define SHIFT \
- (INTPriv(pInt)->shift)
-#define BASE(addr,shift) \
- (INTPriv(pInt)->alloc_rec[addr >> shift])
-#define V_ADDR(addr,shift,off) \
- (BASE(addr,shift) + (off))
-#define VRAM_ADDR(addr) (addr - 0xA0000)
+#define OFF(addr) ((addr) & 0xffff)
+#define SYS(addr) ((addr) >= SYS_BIOS)
+#define V_ADDR(addr) \
+ (SYS(addr) ? ((char*)INTPriv(pInt)->sysMem) + (addr - SYS_BIOS) \
+ : ((char*)(INTPriv(pInt)->base) + addr))
+#define VRAM_ADDR(addr) (addr - V_RAM)
#define VRAM_BASE (INTPriv(pInt)->vRam)
-#define VRAM(addr) ((addr >= 0xA0000) && (addr <= 0xBFFFF))
-#define V_ADDR_RB(addr,shift,off) \
+#define VRAM(addr) ((addr >= V_RAM) && (addr < (V_RAM + VRAM_SIZE)))
+#define V_ADDR_RB(addr) \
(VRAM(addr)) ? MMIO_IN8((CARD8*)VRAM_BASE,VRAM_ADDR(addr)) \
- : *(CARD8*) V_ADDR(addr,shift,off)
-#define V_ADDR_RW(addr,shift,off) \
+ : *(CARD8*) V_ADDR(addr)
+#define V_ADDR_RW(addr) \
(VRAM(addr)) ? MMIO_IN16((CARD16*)VRAM_BASE,VRAM_ADDR(addr)) \
- : ldw_u((pointer)V_ADDR(addr,shift,off))
-#define V_ADDR_RL(addr,shift,off) \
+ : ldw_u((pointer)V_ADDR(addr))
+#define V_ADDR_RL(addr) \
(VRAM(addr)) ? MMIO_IN32((CARD32*)VRAM_BASE,VRAM_ADDR(addr)) \
- : ldl_u((pointer)V_ADDR(addr,shift,off))
+ : ldl_u((pointer)V_ADDR(addr))
-#define V_ADDR_WB(addr,shift,off,val) \
+#define V_ADDR_WB(addr,val) \
if(VRAM(addr)) \
MMIO_OUT8((CARD8*)VRAM_BASE,VRAM_ADDR(addr),val); \
else \
- *(CARD8*) V_ADDR(addr,shift,off) = val;
-#define V_ADDR_WW(addr,shift,off,val) \
+ *(CARD8*) V_ADDR(addr) = val;
+#define V_ADDR_WW(addr,val) \
if(VRAM(addr)) \
MMIO_OUT16((CARD16*)VRAM_BASE,VRAM_ADDR(addr),val); \
else \
- stw_u((val),(pointer)(V_ADDR(addr,shift,off)));
+ stw_u((val),(pointer)(V_ADDR(addr)));
-#define V_ADDR_WL(addr,shift,off,val) \
+#define V_ADDR_WL(addr,val) \
if (VRAM(addr)) \
MMIO_OUT32((CARD32*)VRAM_BASE,VRAM_ADDR(addr),val); \
else \
- stl_u(val,(pointer)(V_ADDR(addr,shift,off)));
+ stl_u(val,(pointer)(V_ADDR(addr)));
static CARD8
read_b(xf86Int10InfoPtr pInt, int addr)
{
- if (!BASE(addr,SHIFT)) return 0xff;
-
- return V_ADDR_RB(addr,SHIFT,OFF(addr));
+ return V_ADDR_RB(addr);
}
static CARD16
read_w(xf86Int10InfoPtr pInt, int addr)
{
- int shift = SHIFT;
- int off = OFF(addr);
-
- if (!BASE(addr,shift)) return 0xffff;
-
#if X_BYTE_ORDER == X_BIG_ENDIAN
- return ((V_ADDR_RB(addr,shift,off))
- || ((V_ADDR_RB(addr,shift,off + 1)) << 8));
+ return ((V_ADDR_RB(addr))
+ || ((V_ADDR_RB(addr + 1)) << 8));
#else
if (OFF(addr + 1) > 0) {
- return V_ADDR_RW(addr,SHIFT,OFF(addr));
- } else {
- return ((V_ADDR_RB(addr,shift,off + 1))
- || ((V_ADDR_RB(addr,shift,off)) << 8));
- }
+ return V_ADDR_RW(addr);
+ } else
+ return ((V_ADDR_RB(addr + 1))
+ || ((V_ADDR_RB(addr)) << 8));
+
#endif
}
static CARD32
read_l(xf86Int10InfoPtr pInt, int addr)
{
- int shift = SHIFT;
- int off = OFF(addr);
-
- if (!BASE(addr,shift)) return 0xffffffff;
-
#if X_BYTE_ORDER == X_BIG_ENDIAN
- return ((V_ADDR_RB(addr,shift,off))
- || ((V_ADDR_RB(addr,shift,off + 1)) << 8)
- || ((V_ADDR_RB(addr,shift,off + 2)) << 16)
- || ((V_ADDR_RB(addr,shift,off + 3)) << 24));
+ return ((V_ADDR_RB(addr))
+ || ((V_ADDR_RB(addr + 1)) << 8)
+ || ((V_ADDR_RB(addr + 2)) << 16)
+ || ((V_ADDR_RB(addr + 3)) << 24));
#else
- if (OFF(addr + 3) > 2) {
- return V_ADDR_RL(addr,SHIFT,OFF(addr));
+ if (OFF(addr + 3) > 2) {
+ return V_ADDR_RL(addr);
} else {
- return ((V_ADDR_RB(addr,shift,off + 3))
- || ((V_ADDR_RB(addr,shift,off + 2)) << 8)
- || ((V_ADDR_RB(addr,shift,off + 1)) << 16)
- || ((V_ADDR_RB(addr,shift,off)) << 24));
+ return ((V_ADDR_RB(addr + 3))
+ || ((V_ADDR_RB(addr + 2)) << 8)
+ || ((V_ADDR_RB(addr + 1)) << 16)
+ || ((V_ADDR_RB(addr)) << 24));
}
#endif
}
@@ -380,28 +323,21 @@ read_l(xf86Int10InfoPtr pInt, int addr)
static void
write_b(xf86Int10InfoPtr pInt, int addr, CARD8 val)
{
- if (!BASE(addr,SHIFT)) return;
-
- V_ADDR_WB(addr,SHIFT,OFF(addr),val);
+ V_ADDR_WB(addr,val);
}
static void
write_w(xf86Int10InfoPtr pInt, int addr, CARD16 val)
{
- int shift = SHIFT;
- int off = OFF(addr);
-
- if (!BASE(addr,shift)) return;
-
#if X_BYTE_ORDER == X_BIG_ENDIAN
- V_ADDR_WB(addr,shift,off,val);
- V_ADDR_WB(addr,shift,off + 1,val >> 8);
+ V_ADDR_WB(addr,val);
+ V_ADDR_WB(addr + 1,val >> 8);
#else
if (OFF(addr + 1) > 0) {
- V_ADDR_WW(addr,shift,OFF(addr),val);
+ V_ADDR_WW(addr,val);
} else {
- V_ADDR_WB(addr,shift,off + 1,val);
- V_ADDR_WB(addr,shift,off,val >> 8);
+ V_ADDR_WB(addr + 1,val);
+ V_ADDR_WB(addr,val >> 8);
}
#endif
}
@@ -409,23 +345,19 @@ write_w(xf86Int10InfoPtr pInt, int addr, CARD16 val)
static void
write_l(xf86Int10InfoPtr pInt, int addr, CARD32 val)
{
- int shift = SHIFT;
- int off = OFF(addr);
- if (!BASE(addr,shift)) return;
-
#if X_BYTE_ORDER == X_BIG_ENDIAN
- V_ADDR_WB(addr,shift,off,val);
- V_ADDR_WB(addr,shift,off + 1, val >> 8);
- V_ADDR_WB(addr,shift,off + 2, val >> 16);
- V_ADDR_WB(addr,shift,off + 3, val >> 24);
+ V_ADDR_WB(addr,val);
+ V_ADDR_WB(addr + 1, val >> 8);
+ V_ADDR_WB(addr + 2, val >> 16);
+ V_ADDR_WB(addr + 3, val >> 24);
#else
if (OFF(addr + 3) > 2) {
- V_ADDR_WL(addr,shift,OFF(addr),val);
+ V_ADDR_WL(addr,val);
} else {
- V_ADDR_WB(addr,shift,off + 3, val);
- V_ADDR_WB(addr,shift,off + 2, val >> 8);
- V_ADDR_WB(addr,shift,off + 1, val >> 16);
- V_ADDR_WB(addr,shift,off, val >> 24);
+ V_ADDR_WB(addr + 3, val);
+ V_ADDR_WB(addr + 2, val >> 8);
+ V_ADDR_WB(addr + 1, val >> 16);
+ V_ADDR_WB(addr, val >> 24);
}
#endif
}
@@ -433,5 +365,13 @@ write_l(xf86Int10InfoPtr pInt, int addr, CARD32 val)
pointer
xf86int10Addr(xf86Int10InfoPtr pInt, CARD32 addr)
{
- return (pointer) V_ADDR(addr,SHIFT,OFF(addr));
+ return (pointer) V_ADDR(addr);
}
+
+
+
+
+
+
+
+