#include "xf86.h"
#include "xf86_OSproc.h"
#include "xf86_ansic.h"
#include "xf86fbman.h"
#include "via_compose.h"
#include "via_capture.h"
#include "via.h"
#include "ddmpeg.h"
#include "xf86drm.h"
#include "via_overlay.h"
#include "via_driver.h"
#include "via_regrec.h"
#include "via_priv.h"
#include "via_swov.h"
#include "via_common.h"
void VIAFreeLinear(VIAMemPtr mem)
{
VIAPtr pVia;
DEBUG(ErrorF("Freed %lu (pool %d)\n", mem->base, mem->pool));
switch(mem->pool)
{
case 0:
return;
case 1:
xf86FreeOffscreenLinear(mem->linear);
mem->linear = NULL;
mem->pool = 0;
return;
case 2:
#ifdef XF86DRI
if(drmCommandWrite(mem->drm_fd, DRM_VIA_FREEMEM,
&mem->drm, sizeof(drmViaMem)) < 0)
ErrorF("DRM module failed free.\n");
#endif
mem->pool = 0;
return;
case 3:
mem->pool = 0;
pVia = mem->pVia;
pVia->SWOVUsed[mem->slot] = 0;
return;
}
}
unsigned long VIAAllocLinear(VIAMemPtr mem, ScrnInfoPtr pScrn, unsigned long size)
{
#if defined(XF86DRI) || !defined(XFREE86_44)
VIAPtr pVia = VIAPTR(pScrn);
#endif
#ifdef XF86DRI
if(mem->pool)
ErrorF("VIA Double Alloc.\n");
if(pVia->graphicInfo.DRMEnabled)
{
mem->drm_fd = pVia->drmFD;
mem->drm.context = 1;
mem->drm.size = size;
mem->drm.type = VIDEO;
if(drmCommandWrite(mem->drm_fd, DRM_VIA_ALLOCMEM,
&mem->drm, sizeof(drmViaMem)) < 0)
{
ErrorF("Cannot allocate memory using DRM.\n");
return BadAccess;
}
mem->base = mem->drm.offset;
mem->pool = 2;
DEBUG(ErrorF("Fulfilled via DRI at %lu\n", mem->base));
return 0;
}
#endif
#ifdef XFREE86_44
{
int depth = (pScrn->bitsPerPixel + 7) >> 3;
mem->linear = xf86AllocateOffscreenLinear(pScrn->pScreen,
( size + depth - 1 ) / depth,
32, NULL, NULL, NULL);
if(mem->linear == NULL)
{
ErrorF("Out of memory for surface.\n");
return BadAlloc;
}
mem->base = mem->linear->offset * depth;
mem->pool = 1;
DEBUG(ErrorF("Fulfilled via Linear at %lu\n", mem->base));
return 0;
}
#else
{
int i;
if(size > pVia->SWOVSize)
return BadAccess;
for(i = 0; i < MEM_BLOCKS; i++)
{
if(!pVia->SWOVUsed[i])
{
pVia->SWOVUsed[i] = 1;
mem->pool = 3;
mem->base = pVia->SWOVPool + pVia->SWOVSize * i;
mem->pVia = pVia;
mem->slot = i;
DEBUG(ErrorF("Fulfilled via pool at %lu\n", mem->base));
return 0;
}
}
}
ErrorF("Out of pools.\n");
return BadAlloc;
#endif
}
void VIAInitPool(VIAPtr pVia, unsigned long offset, unsigned long size)
{
DEBUG(ErrorF("VIAInitPool %lu bytes at %lu\n", size, offset));
size /= 4;
DEBUG(ErrorF("VIAInitPool %d pools of %lu bytes\n", MEM_BLOCKS, size));
pVia->SWOVPool = offset;
pVia->SWOVSize = size;
}