lock pixmaps

git-svn-id: svn://kolibrios.org@817 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2008-07-04 09:14:15 +00:00
parent e3f6e939d2
commit 947f48e392
8 changed files with 162 additions and 83 deletions

View File

@ -6,20 +6,26 @@
#define COMPIZ 5 #define COMPIZ 5
#define PIXMAP 6 #define PIXMAP 6
#define PIXBLIT 7 #define PIXBLIT 7
#define PIXLOCK 8
typedef unsigned int color_t; typedef unsigned int color_t;
typedef struct typedef struct
{ {
pixmap_t *dstpix;
int x; int x;
int y; int y;
int w; u32_t w;
int h; u32_t h;
u32 color; color_t color;
}draw_t; }draw_t;
typedef struct typedef struct
{ {
pixmap_t *dstpix;
int x; int x;
int y; int y;
int w; int w;
@ -53,12 +59,14 @@ typedef struct
typedef struct typedef struct
{ {
u32_t pixmap; pixmap_t *pixmap;
void *usermap;
u32_t format; u32_t format;
u32_t pitch;
u32_t width; u32_t width;
u32_t height; u32_t height;
u32_t pitch; }userpixmap_t;
}new_pixmap_t;
typedef struct typedef struct
{ {
@ -86,10 +94,12 @@ int Blit(blit_t *blit);
int RadeonComposite( blit_t *blit); int RadeonComposite( blit_t *blit);
int CreatePixmap(new_pixmap_t *io); int CreatePixmap(userpixmap_t *io);
int PixBlit(pixblit_t* blit); int PixBlit(pixblit_t* blit);
int LockPixmap(userpixmap_t *io);
# define RADEON_GMC_SRC_PITCH_OFFSET_CNTL (1 << 0) # define RADEON_GMC_SRC_PITCH_OFFSET_CNTL (1 << 0)
# define RADEON_GMC_DST_PITCH_OFFSET_CNTL (1 << 1) # define RADEON_GMC_DST_PITCH_OFFSET_CNTL (1 << 1)
# define RADEON_GMC_BRUSH_SOLID_COLOR (13 << 4) # define RADEON_GMC_BRUSH_SOLID_COLOR (13 << 4)

View File

@ -6,6 +6,10 @@ int DrawRect(draw_t* draw)
{ {
int x0, y0, x1, y1; int x0, y0, x1, y1;
pixmap_t *dstpixmap;
dstpixmap = (draw->dstpix == (void*)-1) ? &scr_pixmap : draw->dstpix ;
x0 = draw->x; x0 = draw->x;
y0 = draw->y; y0 = draw->y;
@ -38,7 +42,7 @@ int DrawRect(draw_t* draw)
OUTREG(R5XX_DP_BRUSH_FRGD_CLR, draw->color); OUTREG(R5XX_DP_BRUSH_FRGD_CLR, draw->color);
OUTREG(R5XX_DP_WRITE_MASK, 0xFFFFFFFF); OUTREG(R5XX_DP_WRITE_MASK, 0xFFFFFFFF);
OUTREG(R5XX_DP_CNTL, R5XX_DST_X_LEFT_TO_RIGHT | R5XX_DST_Y_TOP_TO_BOTTOM); OUTREG(R5XX_DP_CNTL, R5XX_DST_X_LEFT_TO_RIGHT | R5XX_DST_Y_TOP_TO_BOTTOM);
OUTREG(R5XX_DST_PITCH_OFFSET, rhd.dst_pitch_offset); OUTREG(R5XX_DST_PITCH_OFFSET, dstpixmap->pitch_offset);
OUTREG(R5XX_DST_Y_X,(y0<<16)|x0); OUTREG(R5XX_DST_Y_X,(y0<<16)|x0);
OUTREG(R5XX_DST_WIDTH_HEIGHT,(w<<16)|h); OUTREG(R5XX_DST_WIDTH_HEIGHT,(w<<16)|h);
@ -47,16 +51,15 @@ int DrawRect(draw_t* draw)
BEGIN_RING(); BEGIN_RING();
OUT_RING(CP_PACKET3(RADEON_CNTL_PAINT_MULTI, 4)); OUT_RING(CP_PACKET3(RADEON_CNTL_PAINT_MULTI, 4));
OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL | OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL |
RADEON_GMC_BRUSH_SOLID_COLOR | RADEON_GMC_BRUSH_SOLID_COLOR |
RADEON_GMC_DST_32BPP | RADEON_GMC_DST_32BPP |
RADEON_GMC_SRC_DATATYPE_COLOR | RADEON_GMC_SRC_DATATYPE_COLOR |
(1 << 28)+(1 << 30) | R5XX_ROP3_P); (1 << 28)+(1 << 30) | R5XX_ROP3_P);
OUT_RING(rhd.dst_pitch_offset); OUT_RING(dstpixmap->pitch_offset);
OUT_RING(draw->color); OUT_RING(draw->color);
OUT_RING((y0<<16)|x0); OUT_RING((x0<<16)|y0);
OUT_RING((w<<16)|h); OUT_RING((w<<16)|h);
COMMIT_RING(); COMMIT_RING();
@ -64,13 +67,16 @@ int DrawRect(draw_t* draw)
safe_sti(ifl); safe_sti(ifl);
} ; } ;
return 0; return ERR_OK;
} }
int FillRect(fill_t *fill) int FillRect(fill_t *fill)
{ {
pixmap_t *dstpixmap;
int x0, y0, x1, y1; int x0, y0, x1, y1;
dstpixmap = (fill->dstpix == (void*)-1) ? &scr_pixmap : fill->dstpix ;
x0 = fill->x; x0 = fill->x;
y0 = fill->y; y0 = fill->y;
@ -99,7 +105,7 @@ int FillRect(fill_t *fill)
RADEON_GMC_SRC_DATATYPE_COLOR | RADEON_GMC_SRC_DATATYPE_COLOR |
(1 << 28)+(1 << 30) | R5XX_ROP3_P); (1 << 28)+(1 << 30) | R5XX_ROP3_P);
OUT_RING(rhd.dst_pitch_offset); OUT_RING(dstpixmap->pitch_offset);
OUT_RING(fill->bkcolor); OUT_RING(fill->bkcolor);
OUT_RING(fill->fcolor); OUT_RING(fill->fcolor);
@ -114,7 +120,7 @@ int FillRect(fill_t *fill)
safe_sti(ifl); safe_sti(ifl);
}; };
return 0; return ERR_OK;
} }
int Blit(blit_t *blit) int Blit(blit_t *blit)
@ -167,7 +173,7 @@ int Blit(blit_t *blit)
safe_sti(ifl); safe_sti(ifl);
} ; } ;
return 0; return ERR_OK;
} }
int Line2P(line2p_t *draw) int Line2P(line2p_t *draw)
@ -225,11 +231,11 @@ int Line2P(line2p_t *draw)
safe_sti(ifl); safe_sti(ifl);
}; };
return 0; return ERR_OK;
} }
int CreatePixmap(new_pixmap_t *io) int CreatePixmap(userpixmap_t *io)
{ {
pixmap_t *pixmap; pixmap_t *pixmap;
@ -241,7 +247,7 @@ int CreatePixmap(new_pixmap_t *io)
(io->height == 0)|| (io->height > 2048)) (io->height == 0)|| (io->height > 2048))
{ {
dbgprintf("Invalid pixmap size w:%d h:%d\n", io->width,io->height); dbgprintf("Invalid pixmap size w:%d h:%d\n", io->width,io->height);
return 0; return ERR_PARAM;
}; };
@ -252,37 +258,71 @@ int CreatePixmap(new_pixmap_t *io)
if (! raw) if (! raw)
{ {
dbgprintf("Not enough memory for pixmap\n"); dbgprintf("Not enough memory for pixmap\n");
return 0; return ERR_PARAM;
}; };
pixmap = malloc(sizeof(pixmap_t)); pixmap = malloc(sizeof(pixmap_t));
if(!pixmap) if(!pixmap)
{ {
rhd_mem_free(&rhd, RHD_MEM_FB,raw); rhd_mem_free(&rhd, RHD_MEM_FB,raw);
return 0; return ERR_PARAM;
} }
else else
{ {
io->pixmap = (u32_t)pixmap; io->pixmap = pixmap;
io->usermap = NULL;
io->format = PICT_a8r8g8b8; io->format = PICT_a8r8g8b8;
io->pitch = pitch; io->pitch = 0;
pixmap->width = io->width; pixmap->width = io->width;
pixmap->height = io->height; pixmap->height = io->height;
pixmap->format = PICT_a8r8g8b8; pixmap->format = PICT_a8r8g8b8;
pixmap->flags = 0;
pixmap->pitch = pitch; pixmap->pitch = pitch;
pixmap->offset = (u32_t)raw-rhd.FbBase+rhd.FbIntAddress; pixmap->offset = (u32_t)raw+rhd.FbIntAddress;
pixmap->pitch_offset = ((pitch/64)<<22)| (pixmap->offset>>10); pixmap->pitch_offset = ((pitch/64)<<22)| (pixmap->offset>>10);
pixmap->raw = raw; pixmap->raw = raw;
pixmap->usermap = NULL;
dbgprintf("pixmap.pitch_offset: %x\n", pixmap->pitch_offset); dbgprintf("pixmap.pitch_offset: %x\n", pixmap->pitch_offset);
dbgprintf("width: %d height: %d\n",pixmap->width,pixmap->height ); dbgprintf("width: %d height: %d\n",pixmap->width,pixmap->height );
dbgprintf("pixmap.offset: %x\n", pixmap->offset); dbgprintf("pixmap.offset: %x\n", pixmap->offset);
} }
return 1; return ERR_OK;
} }
int LockPixmap(userpixmap_t *io)
{
pixmap_t *pixmap;
size_t size;
void *usermap;
dbgprintf("Lock pixmap %x\n", io->pixmap);
if(io->pixmap == (pixmap_t*)-1)
return ERR_PARAM;
else
pixmap = io->pixmap;
if(pixmap->flags & 1 == 1 )
return ERR_PARAM;
size = pixmap->pitch*pixmap->width;
if (usermap = UserAlloc(size))
{
CommitPages(usermap, ((u32_t)pixmap->raw+rhd.PhisBase)|7|(1<<9), size);
pixmap->flags |= 1;
pixmap->usermap = usermap;
io->usermap = usermap;
io->pitch = pixmap->pitch;
dbgprintf("map at %x\n", io->usermap);
return ERR_OK;
}
else
return ERR_PARAM;
};
int PixBlit(pixblit_t *blit) int PixBlit(pixblit_t *blit)
@ -296,17 +336,17 @@ int PixBlit(pixblit_t *blit)
pixmap_t *srcpixmap; pixmap_t *srcpixmap;
pixmap_t *dstpixmap; pixmap_t *dstpixmap;
dbgprintf("Pixblit src: %x dst: %x\n",blit->srcpix, blit->dstpix); //dbgprintf("Pixblit src: %x dst: %x\n",blit->srcpix, blit->dstpix);
dstpixmap = (blit->dstpix == (void*)-1) ? &scr_pixmap : blit->dstpix ; dstpixmap = (blit->dstpix == (void*)-1) ? &scr_pixmap : blit->dstpix ;
srcpixmap = (blit->srcpix == (void*)-1) ? &scr_pixmap : blit->srcpix ; srcpixmap = (blit->srcpix == (void*)-1) ? &scr_pixmap : blit->srcpix ;
dbgprintf("srcpixmap: %x dstpixmap: %x\n",srcpixmap, dstpixmap); //dbgprintf("srcpixmap: %x dstpixmap: %x\n",srcpixmap, dstpixmap);
dbgprintf("dst.width: %d dst.height: %d\n", dstpixmap->width,dstpixmap->height); //dbgprintf("dst.width: %d dst.height: %d\n", dstpixmap->width,dstpixmap->height);
dbgprintf("src.width: %d src.height: %d\n", srcpixmap->width,srcpixmap->height); //dbgprintf("src.width: %d src.height: %d\n", srcpixmap->width,srcpixmap->height);
dbgprintf("srcpitch: %x dstpitch: %x\n", //dbgprintf("srcpitch: %x dstpitch: %x\n",
srcpixmap->pitch_offset,dstpixmap->pitch_offset); // srcpixmap->pitch_offset,dstpixmap->pitch_offset);
ifl = safe_cli(); ifl = safe_cli();
@ -325,16 +365,11 @@ int PixBlit(pixblit_t *blit)
OUT_RING(srcpixmap->pitch_offset); OUT_RING(srcpixmap->pitch_offset);
OUT_RING(dstpixmap->pitch_offset); OUT_RING(dstpixmap->pitch_offset);
// x0 = blit->src_x;
// y0 = blit->src_y;
// w = blit->w;
// h = blit->h;
OUT_RING((blit->src_x<<16)|blit->src_y); OUT_RING((blit->src_x<<16)|blit->src_y);
OUT_RING((blit->dst_x<<16)|blit->dst_y); OUT_RING((blit->dst_x<<16)|blit->dst_y);
OUT_RING((blit->w<<16)|blit->h); OUT_RING((blit->w<<16)|blit->h);
COMMIT_RING(); COMMIT_RING();
safe_sti(ifl); safe_sti(ifl);
return 0; return ERR_OK;
} }

View File

@ -86,8 +86,6 @@ u32 __stdcall drvEntry(int action)
}; };
#define ERR_PARAM -1
#pragma pack (push,1) #pragma pack (push,1)
#pragma pack (pop) #pragma pack (pop)
@ -140,12 +138,12 @@ int _stdcall srv_2d(ioctl_t *io)
break; break;
case DRAW_RECT: case DRAW_RECT:
if(io->inp_size==5) if(io->inp_size==6)
return DrawRect((draw_t*)inp); return DrawRect((draw_t*)inp);
break; break;
case FILL_RECT: case FILL_RECT:
if(io->inp_size==8) if(io->inp_size==9)
return FillRect((fill_t*)inp); return FillRect((fill_t*)inp);
break; break;
@ -165,8 +163,8 @@ int _stdcall srv_2d(ioctl_t *io)
break; break;
case PIXMAP: case PIXMAP:
if(io->inp_size==5) if(io->inp_size==6)
return CreatePixmap((new_pixmap_t*)inp); return CreatePixmap((userpixmap_t*)inp);
break; break;
case PIXBLIT: case PIXBLIT:
@ -174,6 +172,11 @@ int _stdcall srv_2d(ioctl_t *io)
return PixBlit((pixblit_t*)inp); return PixBlit((pixblit_t*)inp);
break; break;
case PIXLOCK:
if(io->inp_size==6)
return LockPixmap((userpixmap_t*)inp);
break;
default: default:
return ERR_PARAM; return ERR_PARAM;
}; };
@ -184,7 +187,7 @@ int _stdcall srv_2d(ioctl_t *io)
#include "init.c" #include "init.c"
#include "pci.c" #include "pci.c"
#include "ati_mem.c" #include "ati_mem.c"
#include "cursor.inc" //#include "cursor.inc"
#include "r500.inc" #include "r500.inc"
#include "accel_2d.inc" #include "accel_2d.inc"

View File

@ -109,7 +109,7 @@ typedef struct RHDRec
CARD32 MMIOMapSize; CARD32 MMIOMapSize;
CARD32 videoRam; CARD32 videoRam;
CARD32 FbBase; /* map base of fb */ // CARD32 FbBase; /* map base of fb */
CARD32 PhisBase; CARD32 PhisBase;
CARD32 FbIntAddress; /* card internal address of FB */ CARD32 FbIntAddress; /* card internal address of FB */
CARD32 FbMapSize; CARD32 FbMapSize;
@ -181,10 +181,12 @@ typedef struct
u32_t width; u32_t width;
u32_t height; u32_t height;
u32_t format; u32_t format;
u32_t flags;
u32_t pitch_offset;
u32_t pitch; u32_t pitch;
u32_t offset; u32_t offset;
u32_t pitch_offset; void* raw;
u32_t *raw; void* usermap;
}pixmap_t; }pixmap_t;

View File

@ -162,7 +162,7 @@ static void free_block(struct mem_block *p)
int rhdInitHeap(RHDPtr rhdPtr) int rhdInitHeap(RHDPtr rhdPtr)
{ {
int base = rhdPtr->FbBase + rhdPtr->FbFreeStart; int base = rhdPtr->FbFreeStart;
return init_heap(&rhdPtr->fb_heap, base, rhdPtr->FbFreeSize); return init_heap(&rhdPtr->fb_heap, base, rhdPtr->FbFreeSize);
}; };

View File

@ -25,6 +25,7 @@ typedef unsigned int size_t;
typedef struct { float hi, lo; } range; typedef struct { float hi, lo; } range;
typedef struct typedef struct
{ {
unsigned handle; unsigned handle;
@ -37,7 +38,11 @@ typedef struct
typedef int (_stdcall *srv_proc_t)(ioctl_t *); typedef int (_stdcall *srv_proc_t)(ioctl_t *);
u32 __stdcall drvEntry(int)__asm__("_drvEntry"); #define ERR_OK 0
#define ERR_PARAM -1
u32_t __stdcall drvEntry(int)__asm__("_drvEntry");
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -49,8 +54,10 @@ u32 __stdcall drvEntry(int)__asm__("_drvEntry");
#define PG_SW 0x003 #define PG_SW 0x003
#define PG_NOCACHE 0x018 #define PG_NOCACHE 0x018
CARD32 STDCALL AllocKernelSpace(unsigned size)__asm__("AllocKernelSpace"); void* STDCALL AllocKernelSpace(size_t size)__asm__("AllocKernelSpace");
void* STDCALL KernelAlloc(unsigned size)__asm__("KernelAlloc"); void* STDCALL KernelAlloc(size_t size)__asm__("KernelAlloc");
void* STDCALL UserAlloc(size_t size)__asm__("UserAlloc");
int KernelFree(void *); int KernelFree(void *);
void* STDCALL CreateRingBuffer(size_t size, u32 map)__asm__("CreateRingBuffer"); void* STDCALL CreateRingBuffer(size_t size, u32 map)__asm__("CreateRingBuffer");
@ -62,9 +69,9 @@ u32 STDCALL RegService(char *name, srv_proc_t proc)__asm__("RegService");
CARD32 STDCALL MapIoMem(CARD32 Base,CARD32 size,CARD32 flags)__asm__("MapIoMem"); CARD32 STDCALL MapIoMem(CARD32 Base,CARD32 size,CARD32 flags)__asm__("MapIoMem");
static inline u32 GetPgAddr(void *mem) static inline u32_t GetPgAddr(void *mem)
{ {
u32 retval; u32_t retval;
asm volatile ( asm volatile (
"call *__imp__GetPgAddr \n\t" "call *__imp__GetPgAddr \n\t"
@ -74,6 +81,28 @@ static inline u32 GetPgAddr(void *mem)
return retval; return retval;
} }
static inline void CommitPages(void *mem, u32_t page, u32_t size)
{
size = (size+4095) & ~4095;
asm volatile (
"call *__imp__CommitPages"
:
:"a" (page), "b"(mem),"c"(size>>12)
:"edx"
);
}
static inline void UnmapPages(void *mem, size_t size)
{
size = (size+4095) & ~4095;
asm volatile (
"call *__imp__UnmapPages"
:
:"a" (mem), "c"(size>>12)
:"eax","ecx", "edx"
);
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
u32 PciApi(int cmd); u32 PciApi(int cmd);

View File

@ -60,10 +60,10 @@ rhdMapFB(RHDPtr rhdPtr)
rhdPtr->FbMapSize = 1 << rhdPtr->memsize[RHD_FB_BAR]; rhdPtr->FbMapSize = 1 << rhdPtr->memsize[RHD_FB_BAR];
rhdPtr->PhisBase = rhdPtr->memBase[RHD_FB_BAR]; rhdPtr->PhisBase = rhdPtr->memBase[RHD_FB_BAR];
rhdPtr->FbBase = MapIoMem(rhdPtr->PhisBase, rhdPtr->FbMapSize,PG_SW+PG_NOCACHE); // rhdPtr->FbBase = MapIoMem(rhdPtr->PhisBase, rhdPtr->FbMapSize,PG_SW+PG_NOCACHE);
if (!rhdPtr->FbBase) // if (!rhdPtr->FbBase)
return FALSE; // return FALSE;
/* These devices have an internal address reference, which some other /* These devices have an internal address reference, which some other
* address registers in there also use. This can be different from the * address registers in there also use. This can be different from the
@ -80,7 +80,7 @@ rhdMapFB(RHDPtr rhdPtr)
dbgprintf("PCI FB Address (BAR) is at " dbgprintf("PCI FB Address (BAR) is at "
"0x%08X while card Internal Address is 0x%08X\n", "0x%08X while card Internal Address is 0x%08X\n",
(unsigned int) rhdPtr->PhisBase,rhdPtr->FbIntAddress); (unsigned int) rhdPtr->PhisBase,rhdPtr->FbIntAddress);
dbgprintf("Mapped FB at %p (size 0x%08X)\n",rhdPtr->FbBase, rhdPtr->FbMapSize); // dbgprintf("Mapped FB at %p (size 0x%08X)\n",rhdPtr->FbBase, rhdPtr->FbMapSize);
return TRUE; return TRUE;
} }
@ -108,8 +108,8 @@ Bool RHDPreInit()
rhd.FbScanoutStart = 0; rhd.FbScanoutStart = 0;
rhd.FbScanoutSize = 8*1024*1024; rhd.FbScanoutSize = 8*1024*1024;
rhd.FbFreeStart = 8*1024*1024; rhd.FbFreeStart = 10*1024*1024;
rhd.FbFreeSize = rhd.FbMapSize - 8*1024*1024; rhd.FbFreeSize = rhd.FbMapSize - 10*1024*1024;
rhdInitHeap(&rhd); rhdInitHeap(&rhd);
return TRUE; return TRUE;

View File

@ -391,7 +391,7 @@ void R5xx2DInit()
scr_pixmap.pitch = rhd.displayWidth * 4; scr_pixmap.pitch = rhd.displayWidth * 4;
scr_pixmap.offset = rhd.FbIntAddress; scr_pixmap.offset = rhd.FbIntAddress;
scr_pixmap.pitch_offset = rhd.dst_pitch_offset; scr_pixmap.pitch_offset = rhd.dst_pitch_offset;
scr_pixmap.raw = (void*)rhd.FbBase; scr_pixmap.raw = (void*)0;
MASKREG(R5XX_GB_TILE_CONFIG, 0, R5XX_ENABLE_TILING); MASKREG(R5XX_GB_TILE_CONFIG, 0, R5XX_ENABLE_TILING);