summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Deucher <alexdeucher@gmail.com>2008-07-11 02:02:38 -0400
committerAlex Deucher <alexdeucher@gmail.com>2008-08-25 09:49:28 -0400
commit7daba77ded1c718e93ae8c372a39a6e85228d513 (patch)
tree45ae247155398deb0f3faf1e1a1443852bee283b
parent610fe1a937da78f4ac813ac919c158dde8f42442 (diff)
Convert randr, Xv to a common allocator
-rw-r--r--src/Makefile.am3
-rw-r--r--src/radeon.h10
-rw-r--r--src/radeon_crtc.c101
-rw-r--r--src/radeon_memory.c118
-rw-r--r--src/radeon_probe.h7
-rw-r--r--src/radeon_textured_video.c8
-rw-r--r--src/radeon_video.c147
-rw-r--r--src/radeon_video.h8
8 files changed, 154 insertions, 248 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 97c686bc..c79b635c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -88,7 +88,7 @@ radeon_drv_la_LTLIBRARIES = radeon_drv.la
radeon_drv_la_LDFLAGS = -module -avoid-version
radeon_drv_ladir = @moduledir@/drivers
radeon_drv_la_SOURCES = \
- radeon_accel.c radeon_cursor.c radeon_dga.c \
+ radeon_accel.c radeon_cursor.c radeon_dga.c radeon_memory.c \
radeon_driver.c radeon_video.c radeon_bios.c radeon_mm_i2c.c \
radeon_vip.c radeon_misc.c radeon_probe.c \
legacy_crtc.c legacy_output.c \
@@ -128,7 +128,6 @@ EXTRA_DIST = \
radeon_render.c \
radeon_accelfuncs.c \
radeon_textured_videofuncs.c \
- \
ati.h \
ativersion.h \
generic_bus.h \
diff --git a/src/radeon.h b/src/radeon.h
index 7ed39f89..6cce7365 100644
--- a/src/radeon.h
+++ b/src/radeon.h
@@ -1068,6 +1068,16 @@ extern void RADEONUpdateHVPosition(xf86OutputPtr output, DisplayModePtr mode);
extern void RADEONInitVideo(ScreenPtr pScreen);
extern void RADEONResetVideo(ScrnInfoPtr pScrn);
+/* radeon_memory.c */
+extern uint32_t
+radeon_allocate_memory(ScrnInfoPtr pScrn,
+ void **mem_struct,
+ int size,
+ int align);
+extern void
+radeon_free_memory(ScrnInfoPtr pScrn,
+ void *mem_struct);
+
#ifdef XF86DRI
# ifdef USE_XAA
/* radeon_accelfuncs.c */
diff --git a/src/radeon_crtc.c b/src/radeon_crtc.c
index dce450ca..69a87a42 100644
--- a/src/radeon_crtc.c
+++ b/src/radeon_crtc.c
@@ -394,44 +394,6 @@ radeon_crtc_unlock(xf86CrtcPtr crtc)
RADEON_SYNC(info, pScrn);
}
-#ifdef USE_XAA
-/**
- * Allocates memory from the XF86 linear allocator, but also purges
- * memory if possible to cause the allocation to succeed.
- */
-static FBLinearPtr
-radeon_xf86AllocateOffscreenLinear(ScreenPtr pScreen, int length,
- int granularity,
- MoveLinearCallbackProcPtr moveCB,
- RemoveLinearCallbackProcPtr removeCB,
- pointer privData)
-{
- FBLinearPtr linear;
- int max_size;
-
- linear = xf86AllocateOffscreenLinear(pScreen, length, granularity, moveCB,
- removeCB, privData);
- if (linear != NULL)
- return linear;
-
- /* The above allocation didn't succeed, so purge unlocked stuff and try
- * again.
- */
- xf86QueryLargestOffscreenLinear(pScreen, &max_size, granularity,
- PRIORITY_EXTREME);
-
- if (max_size < length)
- return NULL;
-
- xf86PurgeUnlockedOffscreenAreas(pScreen);
-
- linear = xf86AllocateOffscreenLinear(pScreen, length, granularity, moveCB,
- removeCB, privData);
-
- return linear;
-}
-#endif
-
/**
* Allocates memory for a locked-in-framebuffer shadow of the given
* width and height for this CRTC's rotated shadow framebuffer.
@@ -441,8 +403,6 @@ static void *
radeon_crtc_shadow_allocate (xf86CrtcPtr crtc, int width, int height)
{
ScrnInfoPtr pScrn = crtc->scrn;
- /* if this is called during ScreenInit() we don't have pScrn->pScreen yet */
- ScreenPtr pScreen = screenInfo.screens[pScrn->scrnIndex];
RADEONInfoPtr info = RADEONPTR(pScrn);
RADEONCrtcPrivatePtr radeon_crtc = crtc->driver_private;
unsigned long rotate_pitch;
@@ -453,49 +413,14 @@ radeon_crtc_shadow_allocate (xf86CrtcPtr crtc, int width, int height)
rotate_pitch = pScrn->displayWidth * cpp;
size = rotate_pitch * height;
-#ifdef USE_EXA
/* We could get close to what we want here by just creating a pixmap like
* normal, but we have to lock it down in framebuffer, and there is no
* setter for offscreen area locking in EXA currently. So, we just
* allocate offscreen memory and fake up a pixmap header for it.
*/
- if (info->useEXA) {
- assert(radeon_crtc->rotate_mem_exa == NULL);
-
- radeon_crtc->rotate_mem_exa = exaOffscreenAlloc(pScreen, size, align,
- TRUE, NULL, NULL);
- if (radeon_crtc->rotate_mem_exa == NULL) {
- xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
- "Couldn't allocate shadow memory for rotated CRTC\n");
- return NULL;
- }
- rotate_offset = radeon_crtc->rotate_mem_exa->offset;
- }
-#endif /* USE_EXA */
-#ifdef USE_XAA
- if (!info->useEXA) {
- /* The XFree86 linear allocator operates in units of screen pixels,
- * sadly.
- */
- size = (size + cpp - 1) / cpp;
- align = (align + cpp - 1) / cpp;
-
- assert(radeon_crtc->rotate_mem_xaa == NULL);
-
- radeon_crtc->rotate_mem_xaa =
- radeon_xf86AllocateOffscreenLinear(pScreen, size, align,
- NULL, NULL, NULL);
- if (radeon_crtc->rotate_mem_xaa == NULL) {
- xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
- "Couldn't allocate shadow memory for rotated CRTC\n");
- return NULL;
- }
-#ifdef XF86DRI
- rotate_offset = info->dri->frontOffset +
- radeon_crtc->rotate_mem_xaa->offset * cpp;
-#endif
- }
-#endif /* USE_XAA */
+ rotate_offset = radeon_allocate_memory(pScrn, &radeon_crtc->crtc_rotate_mem, size, align);
+ if (rotate_offset == 0)
+ return NULL;
return info->FB + rotate_offset;
}
@@ -535,26 +460,14 @@ static void
radeon_crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
{
ScrnInfoPtr pScrn = crtc->scrn;
- RADEONInfoPtr info = RADEONPTR(pScrn);
RADEONCrtcPrivatePtr radeon_crtc = crtc->driver_private;
if (rotate_pixmap)
FreeScratchPixmapHeader(rotate_pixmap);
-
- if (data) {
-#ifdef USE_EXA
- if (info->useEXA && radeon_crtc->rotate_mem_exa != NULL) {
- exaOffscreenFree(pScrn->pScreen, radeon_crtc->rotate_mem_exa);
- radeon_crtc->rotate_mem_exa = NULL;
- }
-#endif /* USE_EXA */
-#ifdef USE_XAA
- if (!info->useEXA) {
- xf86FreeOffscreenLinear(radeon_crtc->rotate_mem_xaa);
- radeon_crtc->rotate_mem_xaa = NULL;
- }
-#endif /* USE_XAA */
- }
+
+ if (data)
+ radeon_free_memory(pScrn, radeon_crtc->crtc_rotate_mem);
+
}
static const xf86CrtcFuncsRec radeon_crtc_funcs = {
diff --git a/src/radeon_memory.c b/src/radeon_memory.c
new file mode 100644
index 00000000..d9e6403e
--- /dev/null
+++ b/src/radeon_memory.c
@@ -0,0 +1,118 @@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* Driver data structures */
+#include "radeon.h"
+
+
+/* Allocates memory, either by resizing the allocation pointed to by mem_struct,
+ * or by freeing mem_struct (if non-NULL) and allocating a new space. The size
+ * is measured in bytes, and the offset from the beginning of card space is
+ * returned.
+ */
+uint32_t
+radeon_allocate_memory(ScrnInfoPtr pScrn,
+ void **mem_struct,
+ int size,
+ int align)
+{
+ ScreenPtr pScreen;
+ RADEONInfoPtr info = RADEONPTR(pScrn);
+ int offset = 0;
+
+ pScreen = screenInfo.screens[pScrn->scrnIndex];
+#ifdef USE_EXA
+ if (info->useEXA) {
+ ExaOffscreenArea *area = *mem_struct;
+
+ if (area != NULL) {
+ if (area->size >= size)
+ return area->offset;
+
+ exaOffscreenFree(pScrn->pScreen, area);
+ }
+
+ area = exaOffscreenAlloc(pScrn->pScreen, size, align, TRUE,
+ NULL, NULL);
+
+ *mem_struct = area;
+ if (area == NULL)
+ return 0;
+ offset = area->offset;
+ }
+#endif /* USE_EXA */
+#ifdef USE_XAA
+ if (!info->useEXA) {
+ FBLinearPtr linear = *mem_struct;
+ int cpp = info->CurrentLayout.bitsPerPixel / 8;
+
+ /* XAA allocates in units of pixels at the screen bpp, so adjust size
+ * appropriately.
+ */
+ size = (size + cpp - 1) / cpp;
+ align = (align + cpp - 1) / cpp;
+
+ if (linear) {
+ if(linear->size >= size)
+ return linear->offset * cpp;
+
+ if(xf86ResizeOffscreenLinear(linear, size))
+ return linear->offset * cpp;
+
+ xf86FreeOffscreenLinear(linear);
+ }
+
+ linear = xf86AllocateOffscreenLinear(pScreen, size, align,
+ NULL, NULL, NULL);
+ *mem_struct = linear;
+
+ if (!linear) {
+ int max_size;
+
+ xf86QueryLargestOffscreenLinear(pScreen, &max_size, align,
+ PRIORITY_EXTREME);
+
+ if (max_size < size)
+ return 0;
+
+ xf86PurgeUnlockedOffscreenAreas(pScreen);
+ linear = xf86AllocateOffscreenLinear(pScreen, size, align,
+ NULL, NULL, NULL);
+ *mem_struct = linear;
+ if (!linear)
+ return 0;
+ }
+ offset = linear->offset * cpp;
+ }
+#endif /* USE_XAA */
+
+ return offset;
+}
+
+void
+radeon_free_memory(ScrnInfoPtr pScrn,
+ void *mem_struct)
+{
+ RADEONInfoPtr info = RADEONPTR(pScrn);
+
+#ifdef USE_EXA
+ if (info->useEXA) {
+ ExaOffscreenArea *area = mem_struct;
+
+ if (area != NULL)
+ exaOffscreenFree(pScrn->pScreen, area);
+ area = NULL;
+ }
+#endif /* USE_EXA */
+#ifdef USE_XAA
+ if (!info->useEXA) {
+ FBLinearPtr linear = mem_struct;
+
+ if (linear != NULL)
+ xf86FreeOffscreenLinear(linear);
+ linear = NULL;
+ }
+#endif /* USE_XAA */
+}
diff --git a/src/radeon_probe.h b/src/radeon_probe.h
index 3770abfd..8e01b0f8 100644
--- a/src/radeon_probe.h
+++ b/src/radeon_probe.h
@@ -183,12 +183,7 @@ typedef struct
} RADEONI2CBusRec, *RADEONI2CBusPtr;
typedef struct _RADEONCrtcPrivateRec {
-#ifdef USE_XAA
- FBLinearPtr rotate_mem_xaa;
-#endif
-#ifdef USE_EXA
- ExaOffscreenArea *rotate_mem_exa;
-#endif
+ void *crtc_rotate_mem;
int crtc_id;
int binding;
uint32_t cursor_offset;
diff --git a/src/radeon_textured_video.c b/src/radeon_textured_video.c
index 9e6b37a8..d210a2d5 100644
--- a/src/radeon_textured_video.c
+++ b/src/radeon_textured_video.c
@@ -197,14 +197,14 @@ RADEONPutImageTextured(ScrnInfoPtr pScrn,
dstPitch = (dstPitch + 15) & ~15;
if (pPriv->video_memory != NULL && size != pPriv->size) {
- RADEONFreeMemory(pScrn, pPriv->video_memory);
+ radeon_free_memory(pScrn, pPriv->video_memory);
pPriv->video_memory = NULL;
}
if (pPriv->video_memory == NULL) {
- pPriv->video_offset = RADEONAllocateMemory(pScrn,
- &pPriv->video_memory,
- size * 2);
+ pPriv->video_offset = radeon_allocate_memory(pScrn,
+ &pPriv->video_memory,
+ size * 2, 64);
if (pPriv->video_offset == 0)
return BadAlloc;
}
diff --git a/src/radeon_video.c b/src/radeon_video.c
index e71f0f85..e86a7d4c 100644
--- a/src/radeon_video.c
+++ b/src/radeon_video.c
@@ -240,19 +240,6 @@ radeon_crtc_clip_video(ScrnInfoPtr pScrn,
#endif
}
-#ifdef USE_EXA
-static void
-ATIVideoSave(ScreenPtr pScreen, ExaOffscreenArea *area)
-{
- ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
- RADEONInfoPtr info = RADEONPTR(pScrn);
- RADEONPortPrivPtr pPriv = info->adaptor->pPortPrivates[0].ptr;
-
- if (pPriv->video_memory == area)
- pPriv->video_memory = NULL;
-}
-#endif /* USE_EXA */
-
void RADEONInitVideo(ScreenPtr pScreen)
{
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
@@ -1670,7 +1657,7 @@ RADEONStopVideo(ScrnInfoPtr pScrn, pointer data, Bool cleanup)
if(pPriv->i2c != NULL) RADEON_board_setmisc(pPriv);
}
if (pPriv->video_memory != NULL) {
- RADEONFreeMemory(pScrn, pPriv->video_memory);
+ radeon_free_memory(pScrn, pPriv->video_memory);
pPriv->video_memory = NULL;
}
if (pPriv->bicubic_memory != NULL) {
@@ -2426,114 +2413,6 @@ RADEONCopyMungedData(
}
}
-
-/* Allocates memory, either by resizing the allocation pointed to by mem_struct,
- * or by freeing mem_struct (if non-NULL) and allocating a new space. The size
- * is measured in bytes, and the offset from the beginning of card space is
- * returned.
- */
-uint32_t
-RADEONAllocateMemory(
- ScrnInfoPtr pScrn,
- void **mem_struct,
- int size
-){
- ScreenPtr pScreen;
- RADEONInfoPtr info = RADEONPTR(pScrn);
- int offset = 0;
-
- pScreen = screenInfo.screens[pScrn->scrnIndex];
-#ifdef USE_EXA
- if (info->useEXA) {
- ExaOffscreenArea *area = *mem_struct;
-
- if (area != NULL) {
- if (area->size >= size)
- return area->offset;
-
- exaOffscreenFree(pScrn->pScreen, area);
- }
-
- area = exaOffscreenAlloc(pScrn->pScreen, size, 64, TRUE, ATIVideoSave,
- NULL);
- *mem_struct = area;
- if (area == NULL)
- return 0;
- offset = area->offset;
- }
-#endif /* USE_EXA */
-#ifdef USE_XAA
- if (!info->useEXA) {
- FBLinearPtr linear = *mem_struct;
- int cpp = info->CurrentLayout.bitsPerPixel / 8;
-
- /* XAA allocates in units of pixels at the screen bpp, so adjust size
- * appropriately.
- */
- size = (size + cpp - 1) / cpp;
-
- if (linear) {
- if(linear->size >= size)
- return linear->offset * cpp;
-
- if(xf86ResizeOffscreenLinear(linear, size))
- return linear->offset * cpp;
-
- xf86FreeOffscreenLinear(linear);
- }
-
- linear = xf86AllocateOffscreenLinear(pScreen, size, 16,
- NULL, NULL, NULL);
- *mem_struct = linear;
-
- if (!linear) {
- int max_size;
-
- xf86QueryLargestOffscreenLinear(pScreen, &max_size, 16,
- PRIORITY_EXTREME);
-
- if(max_size < size)
- return 0;
-
- xf86PurgeUnlockedOffscreenAreas(pScreen);
- linear = xf86AllocateOffscreenLinear(pScreen, size, 16,
- NULL, NULL, NULL);
- *mem_struct = linear;
- if (!linear)
- return 0;
- }
- offset = linear->offset * cpp;
- }
-#endif /* USE_XAA */
-
- return offset;
-}
-
-void
-RADEONFreeMemory(
- ScrnInfoPtr pScrn,
- void *mem_struct
-){
- RADEONInfoPtr info = RADEONPTR(pScrn);
-
-#ifdef USE_EXA
- if (info->useEXA) {
- ExaOffscreenArea *area = mem_struct;
-
- if (area != NULL)
- exaOffscreenFree(pScrn->pScreen, area);
- }
-#endif /* USE_EXA */
-#ifdef USE_XAA
- if (!info->useEXA) {
- FBLinearPtr linear = mem_struct;
-
- if (linear != NULL)
- xf86FreeOffscreenLinear(linear);
- }
-#endif /* USE_XAA */
-}
-
static void
RADEONDisplayVideo(
ScrnInfoPtr pScrn,
@@ -3052,9 +2931,9 @@ RADEONPutImage(
if (idconv == FOURCC_YV12 || id == FOURCC_I420) {
new_size += (dstPitch >> 1) * ((height + 1) & ~1);
}
- pPriv->video_offset = RADEONAllocateMemory(pScrn, &pPriv->video_memory,
- (pPriv->doubleBuffer ?
- (new_size * 2) : new_size));
+ pPriv->video_offset = radeon_allocate_memory(pScrn, &pPriv->video_memory,
+ (pPriv->doubleBuffer ?
+ (new_size * 2) : new_size), 64);
if (pPriv->video_offset == 0)
return BadAlloc;
@@ -3247,7 +3126,7 @@ RADEONVideoTimerCallback(ScrnInfoPtr pScrn, Time now)
} else { /* FREE_TIMER */
if(pPriv->freeTime < now) {
if (pPriv->video_memory != NULL) {
- RADEONFreeMemory(pScrn, pPriv->video_memory);
+ radeon_free_memory(pScrn, pPriv->video_memory);
pPriv->video_memory = NULL;
}
if (pPriv->bicubic_memory != NULL) {
@@ -3286,7 +3165,7 @@ RADEONAllocateSurface(
pitch = ((w << 1) + 15) & ~15;
size = pitch * h;
- offset = RADEONAllocateMemory(pScrn, &surface_memory, size);
+ offset = radeon_allocate_memory(pScrn, &surface_memory, size, 64);
if (offset == 0)
return BadAlloc;
@@ -3294,18 +3173,18 @@ RADEONAllocateSurface(
surface->height = h;
if(!(surface->pitches = xalloc(sizeof(int)))) {
- RADEONFreeMemory(pScrn, surface_memory);
+ radeon_free_memory(pScrn, surface_memory);
return BadAlloc;
}
if(!(surface->offsets = xalloc(sizeof(int)))) {
xfree(surface->pitches);
- RADEONFreeMemory(pScrn, surface_memory);
+ radeon_free_memory(pScrn, surface_memory);
return BadAlloc;
}
if(!(pPriv = xalloc(sizeof(OffscreenPrivRec)))) {
xfree(surface->pitches);
xfree(surface->offsets);
- RADEONFreeMemory(pScrn, surface_memory);
+ radeon_free_memory(pScrn, surface_memory);
return BadAlloc;
}
@@ -3346,7 +3225,7 @@ RADEONFreeSurface(
if(pPriv->isOn)
RADEONStopSurface(surface);
- RADEONFreeMemory(pScrn, pPriv->surface_memory);
+ radeon_free_memory(pScrn, pPriv->surface_memory);
xfree(surface->pitches);
xfree(surface->offsets);
xfree(surface->devPrivate.ptr);
@@ -3620,9 +3499,9 @@ RADEONPutVideo(
if (pPriv->capture_vbi_data)
alloc_size += 2 * 2 * vbi_line_width * 21;
- pPriv->video_offset = RADEONAllocateMemory(pScrn, &pPriv->video_memory,
- (pPriv->doubleBuffer ?
- (new_size * 2) : new_size));
+ pPriv->video_offset = radeon_allocate_memory(pScrn, &pPriv->video_memory,
+ (pPriv->doubleBuffer ?
+ (new_size * 2) : new_size), 64);
if (pPriv->video_offset == 0)
return BadAlloc;
diff --git a/src/radeon_video.h b/src/radeon_video.h
index b9d900dc..11b80291 100644
--- a/src/radeon_video.h
+++ b/src/radeon_video.h
@@ -86,9 +86,6 @@ typedef struct {
xf86CrtcPtr desired_crtc;
int size;
-#ifdef USE_EXA
- ExaOffscreenArea *off_screen;
-#endif
void *video_memory;
int video_offset;
@@ -122,11 +119,6 @@ void RADEONResetI2C(ScrnInfoPtr pScrn, RADEONPortPrivPtr pPriv);
void RADEONVIP_init(ScrnInfoPtr pScrn, RADEONPortPrivPtr pPriv);
void RADEONVIP_reset(ScrnInfoPtr pScrn, RADEONPortPrivPtr pPriv);
-uint32_t
-RADEONAllocateMemory(ScrnInfoPtr pScrn, void **mem_struct, int size);
-void
-RADEONFreeMemory(ScrnInfoPtr pScrn, void *mem_struct);
-
int RADEONSetPortAttribute(ScrnInfoPtr, Atom, INT32, pointer);
int RADEONGetPortAttribute(ScrnInfoPtr, Atom ,INT32 *, pointer);
void RADEONStopVideo(ScrnInfoPtr, pointer, Bool);