Ok here's what I've got done with DSCAPS_AGPONLY surface support. Not
exactly cvs ready (TM) yet.
Currently allocates one large chunk of AGP memory. Size is the minimum of
aperture size, actually available AGP memory or value supplied with
'agpmem-limit' option.
I had to add dfb_gfxcard_get_alignment_limits() (horrible name, I know)
function to get the hw limits for the surface manager.
The matrox driver gained some more ugliness and two new fields to the
device struct. CheckState{G100,Old} reject AGP surfaces as they can't use
them.
Some TODOs that come to mind:
- Some way to gracefully fail if AGP init fails. I don't think it's a
good idea to abort the whole process if AGP has trouble.
- User should be able to disable AGP. agpmem-limit=0? Could use the
same stuff as the previous item.
- Better policies than CSP_AGPONLY.
- Test single-app core (didn't do that yet) and test if multi-app
actually works with more than one app.
- Non Matrox cards??
--
Ville Syrj�l�
[EMAIL PROTECTED]
http://www.sci.fi/~syrjala/
diff -urN DirectFB/configure.in DirectFB/configure.in
--- DirectFB/configure.in Fri Dec 6 02:00:32 2002
+++ DirectFB/configure.in Wed Dec 11 00:26:49 2002
@@ -87,6 +87,25 @@
AM_CONDITIONAL(FBDEV_CORE, test x$enable_fbdev = xyes)
+dnl Test for Linux agpgart support
+AC_ARG_ENABLE(agp,
+ [ --enable-agp build with linux agpgart support [default=auto]],,
+ enable_agp=yes)
+
+if test x$enable_agp = xyes; then
+ AC_CHECK_HEADER(linux/agpgart.h, agp_found=yes, agp_found=no)
+ if test "agp_found" = no; then
+ enable_agp=no
+ AC_MSG_WARN([
+*** no linux/agpgart.h found -- building without linux agpgart support.])
+ else
+ AC_DEFINE(SUPPORT_AGP,1,
+ [Define to 1 to enable support for AGP surfaces.])
+ fi
+fi
+
+AM_CONDITIONAL(ENABLE_AGP, test x$enable_agp = xyes)
+
if test "x$GCC" = xyes; then
DFB_CFLAGS="$DFB_CFLAGS -ffast-math -Wall"
@@ -768,6 +787,7 @@
src/gfx/Makefile
src/gfx/generic/Makefile
src/core/Makefile
+src/core/agp/Makefile
src/core/fbdev/Makefile
src/core/fusion/Makefile
src/core/fusion/shmalloc/Makefile
@@ -820,6 +840,7 @@
Debug mode $enable_debug
RGB332 support $enable_rgb332
Multi App support $enable_multi
+ AGP support $enable_agp
Core Systems:
Linux FBDev support $enable_fbdev
diff -urN DirectFB/gfxdrivers/matrox/matrox.c DirectFB/gfxdrivers/matrox/matrox.c
--- DirectFB/gfxdrivers/matrox/matrox.c Wed Dec 11 00:08:55 2002
+++ DirectFB/gfxdrivers/matrox/matrox.c Wed Dec 11 00:35:46 2002
@@ -42,6 +42,7 @@
#include <core/state.h>
#include <core/gfxcard.h>
#include <core/surfaces.h>
+#include <core/agp/agp.h>
#include <gfx/util.h>
#include <misc/util.h>
@@ -152,6 +153,12 @@
static void matroxOldCheckState( void *drv, void *dev,
CardState *state, DFBAccelerationMask accel )
{
+ if (state->destination->back_buffer->policy == CSP_AGPONLY)
+ return;
+ if (DFB_BLITTING_FUNCTION( accel ) &&
+ state->source->front_buffer->policy == CSP_AGPONLY)
+ return;
+
/* FIXME: 24bit support */
switch (state->destination->format) {
case DSPF_I420:
@@ -199,6 +206,12 @@
static void matroxG100CheckState( void *drv, void *dev,
CardState *state, DFBAccelerationMask accel )
{
+ if (state->destination->back_buffer->policy == CSP_AGPONLY)
+ return;
+ if (DFB_BLITTING_FUNCTION( accel ) &&
+ state->source->front_buffer->policy == CSP_AGPONLY)
+ return;
+
/* FIXME: 24bit support */
switch (state->destination->format) {
case DSPF_I420:
@@ -843,7 +856,10 @@
int src_cb_offset, src_cr_offset, dst_offset;
mga_waitfifo( mdrv, mdev, 1 );
- mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, mdev->src_byteoffset ) &
0x1FFFFFF, SRCORG );
+ if (mdev->src_agp)
+ mga_out32( mmio, dfb_agp_memory_physical( mdev->src_byteoffset ) | 0x3,
+SRCORG );
+ else
+ mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, mdev->src_byteoffset )
+& 0x1FFFFFF, SRCORG );
matroxDoBlit2D( mdrv, mdev,
rect->x, rect->y,
@@ -875,8 +891,14 @@
mga_out32( mmio, (mdev->dst_pixelpitch * mdev->clip.y2 / 4) & 0xFFFFFF, YBOT );
mga_out32( mmio, ((mdev->clip.x2/2 & 0x0FFF) << 16) | (mdev->clip.x1/2 &
0x0FFF), CXBNDRY );
- mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, dst_offset ) & 0x1FFFFFF,
DSTORG );
- mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, src_cb_offset ) & 0x1FFFFFF,
SRCORG );
+ if (mdev->dst_agp)
+ mga_out32( mmio, dfb_agp_memory_physical( dst_offset ) | 0x3, DSTORG );
+ else
+ mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, dst_offset ) &
+0x1FFFFFF, DSTORG );
+ if (mdev->src_agp)
+ mga_out32( mmio, dfb_agp_memory_physical( src_cb_offset ) | 0x3, SRCORG );
+ else
+ mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, src_cb_offset ) &
+0x1FFFFFF, SRCORG );
matroxDoBlit2D( mdrv, mdev,
rect->x, rect->y,
@@ -887,8 +909,15 @@
/* Cr plane */
dst_offset += mdev->dst_bytepitch * mdev->dst_height / 4;
mga_waitfifo( mdrv, mdev, 2 );
- mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, dst_offset ) & 0x1FFFFFF,
DSTORG );
- mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, src_cr_offset ) & 0x1FFFFFF,
SRCORG );
+ if (mdev->dst_agp)
+ mga_out32( mmio, dfb_agp_memory_physical( dst_offset ) | 0x3, DSTORG );
+ else
+ mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, dst_offset ) &
+0x1FFFFFF, DSTORG );
+
+ if (mdev->src_agp)
+ mga_out32( mmio, dfb_agp_memory_physical( src_cr_offset ) | 0x3, SRCORG );
+ else
+ mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, src_cr_offset ) &
+0x1FFFFFF, SRCORG );
matroxDoBlit2D( mdrv, mdev,
rect->x, rect->y,
@@ -902,7 +931,10 @@
mga_out32( mmio, (mdev->dst_pixelpitch * mdev->clip.y2) & 0xFFFFFF, YBOT );
mga_out32( mmio, ((mdev->clip.x2 & 0x0FFF) << 16) | (mdev->clip.x1 & 0x0FFF),
CXBNDRY );
- mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, mdev->dst_byteoffset ) &
0x1FFFFFF, DSTORG );
+ if (mdev->dst_agp)
+ mga_out32( mmio, dfb_agp_memory_physical( mdev->dst_byteoffset ) | 0x3,
+DSTORG );
+ else
+ mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, mdev->dst_byteoffset )
+& 0x1FFFFFF, DSTORG );
mga_out32( mmio, mdev->dst_pixelpitch, PITCH );
}
@@ -980,7 +1012,10 @@
mga_out32( mmio, mdev->texctl2, TEXCTL2 );
mga_out32( mmio, (w-1)<<18 | ((8-w2)&63)<<9 | w2, TEXWIDTH );
mga_out32( mmio, (h-1)<<18 | ((8-h2)&63)<<9 | h2, TEXHEIGHT );
- mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, src_offset ) & 0x1FFFFFF,
TEXORG );
+ if (mdev->src_agp)
+ mga_out32( mmio, dfb_agp_memory_physical( src_offset ) | 0x3, TEXORG );
+ else
+ mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, src_offset ) &
+0x1FFFFFF, TEXORG );
matroxDoBlitTMU( mdrv, mdev,
srect->x, srect->y,
@@ -1033,9 +1068,15 @@
mga_out32( mmio, mdev->texctl2, TEXCTL2 );
mga_out32( mmio, (w-1)<<18 | ((8-w2)&63)<<9 | w2, TEXWIDTH );
mga_out32( mmio, (h-1)<<18 | ((8-h2)&63)<<9 | h2, TEXHEIGHT );
- mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, src_cb_offset ) & 0x1FFFFFF,
TEXORG );
+ if (mdev->src_agp)
+ mga_out32( mmio, dfb_agp_memory_physical( src_cb_offset ) | 0x3, TEXORG );
+ else
+ mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, src_cb_offset ) &
+0x1FFFFFF, TEXORG );
- mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, dst_offset ) & 0x1FFFFFF,
DSTORG );
+ if (mdev->dst_agp)
+ mga_out32( mmio, dfb_agp_memory_physical( dst_offset ) | 0x3, DSTORG );
+ else
+ mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, dst_offset ) &
+0x1FFFFFF, DSTORG );
mga_out32( mmio, mdev->dst_pixelpitch/2, PITCH );
if (mdev->old_matrox) {
@@ -1059,8 +1100,14 @@
dst_pixeloffset += mdev->dst_pixelpitch * mdev->dst_height / 4;
mga_waitfifo( mdrv, mdev, 2 );
- mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, src_cr_offset ) & 0x1FFFFFF,
TEXORG );
- mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, dst_offset ) & 0x1FFFFFF,
DSTORG );
+ if (mdev->src_agp)
+ mga_out32( mmio, dfb_agp_memory_physical( src_cr_offset ) | 0x3, TEXORG );
+ else
+ mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, src_cr_offset ) &
+0x1FFFFFF, TEXORG );
+ if (mdev->dst_agp)
+ mga_out32( mmio, dfb_agp_memory_physical( dst_offset ) | 0x3, DSTORG );
+ else
+ mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, dst_offset ) &
+0x1FFFFFF, DSTORG );
if (mdev->old_matrox) {
mga_waitfifo( mdrv, mdev, 2 );
@@ -1086,7 +1133,10 @@
}
mga_out32( mmio, ((mdev->clip.x2 & 0x0FFF) << 16) | (mdev->clip.x1 & 0x0FFF),
CXBNDRY );
- mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, mdev->dst_byteoffset ) &
0x1FFFFFF, DSTORG );
+ if (mdev->dst_agp)
+ mga_out32( mmio, dfb_agp_memory_physical( mdev->dst_byteoffset ) | 0x3,
+DSTORG );
+ else
+ mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, mdev->dst_byteoffset )
+& 0x1FFFFFF, DSTORG );
mga_out32( mmio, mdev->dst_pixelpitch, PITCH );
}
diff -urN DirectFB/gfxdrivers/matrox/matrox.h DirectFB/gfxdrivers/matrox/matrox.h
--- DirectFB/gfxdrivers/matrox/matrox.h Wed Dec 11 00:08:55 2002
+++ DirectFB/gfxdrivers/matrox/matrox.h Wed Dec 11 00:35:46 2002
@@ -74,6 +74,7 @@
MatroxStateBits valid;
/* Stored values */
+ int dst_agp;
int dst_pixelpitch;
int dst_pixeloffset;
int dst_bytepitch;
@@ -81,6 +82,7 @@
int dst_height;
DFBSurfacePixelFormat dst_format;
+ int src_agp;
int src_pixelpitch;
int src_pixeloffset;
int src_bytepitch;
diff -urN DirectFB/gfxdrivers/matrox/matrox_state.c
DirectFB/gfxdrivers/matrox/matrox_state.c
--- DirectFB/gfxdrivers/matrox/matrox_state.c Wed Dec 11 00:08:56 2002
+++ DirectFB/gfxdrivers/matrox/matrox_state.c Wed Dec 11 00:35:46 2002
@@ -32,6 +32,7 @@
#include <core/state.h>
#include <core/gfxcard.h>
#include <core/surfaces.h>
+#include <core/agp/agp.h>
#include <gfx/convert.h>
#include <misc/util.h>
@@ -60,13 +61,20 @@
mdev->dst_byteoffset = buffer->video.offset;
mdev->dst_bytepitch = buffer->video.pitch;
+ mdev->dst_agp = buffer->policy == CSP_AGPONLY ? 1 : 0;
+
mga_waitfifo( mdrv, mdev, 3 );
if (mdev->old_matrox)
mga_out32( mmio, mdev->dst_pixeloffset, YDSTORG );
- else
- mga_out32( mmio, dfb_gfxcard_memory_physical( NULL, buffer->video.offset) &
- 0x1FFFFFF, DSTORG );
+ else {
+ if (mdev->dst_agp)
+ mga_out32( mmio, dfb_agp_memory_physical( buffer->video.offset) | 0x3,
+ DSTORG );
+ else
+ mga_out32( mmio, dfb_gfxcard_memory_physical( NULL,
+buffer->video.offset) & 0x1FFFFFF,
+ DSTORG );
+ }
mga_out32( mmio, mdev->dst_pixelpitch, PITCH );
@@ -335,11 +343,14 @@
mdev->src_byteoffset = buffer->video.offset;
mdev->src_bytepitch = buffer->video.pitch;
+ mdev->src_agp = buffer->policy == CSP_AGPONLY ? 1 : 0;
+
mdev->src_width = surface->width;
mdev->src_height = surface->height;
mdev->src_format = surface->format;
mdev->field = surface->field;
+
if (state->blittingflags & DSBLIT_BLEND_ALPHACHANNEL)
texctl = TAMASK;
else
@@ -408,6 +419,8 @@
mdev->src_pixelpitch = buffer->video.pitch / bytes_per_pixel;
mdev->src_byteoffset = buffer->video.offset;
mdev->src_bytepitch = buffer->video.pitch;
+
+ mdev->src_agp = buffer->policy == CSP_AGPONLY ? 1 : 0;
mdev->src_height = surface->height;
mdev->src_format = surface->format;
diff -urN DirectFB/include/directfb.h DirectFB/include/directfb.h
--- DirectFB/include/directfb.h Sun Dec 8 11:28:05 2002
+++ DirectFB/include/directfb.h Wed Dec 11 00:35:46 2002
@@ -449,6 +449,8 @@
DSCAPS_VIDEOONLY = 0x00000004, /* Surface data is permanently stored
in video memory. <br>There's no
system memory allocation/storage. */
+ DSCAPS_AGPONLY = 0x00000008, /* Surface data is permanently stored
+ in AGP memory. */
DSCAPS_FLIPPING = 0x00000010, /* Surface is double buffered or needs
Flip() calls to make updates/changes
visible/usable. */
diff -urN DirectFB/src/core/Makefile.am DirectFB/src/core/Makefile.am
--- DirectFB/src/core/Makefile.am Mon Oct 28 17:11:21 2002
+++ DirectFB/src/core/Makefile.am Wed Dec 11 00:35:46 2002
@@ -16,7 +16,15 @@
FBDEV_LIB =
endif
-SUBDIRS = fusion $(FBDEV_DIR) $(SDL_DIR)
+if ENABLE_AGP
+AGP_DIR = agp
+AGP_LIB = agp/libdirectfb_agp.la
+else
+AGP_DIR =
+AGP_LIB =
+endif
+
+SUBDIRS = fusion $(FBDEV_DIR) $(SDL_DIR) $(AGP_DIR)
INCLUDES = \
-I$(top_srcdir)/include \
@@ -62,7 +70,8 @@
libdirectfb_core_la_LIBADD = \
fusion/libdirectfb_core_fusion.la \
$(FBDEV_LIB) \
- $(SDL_LIB)
+ $(SDL_LIB) \
+ $(AGP_LIB)
libdirectfb_core_la_SOURCES = \
core.c \
diff -urN DirectFB/src/core/agp/Makefile.am DirectFB/src/core/agp/Makefile.am
--- DirectFB/src/core/agp/Makefile.am Thu Jan 1 02:00:00 1970
+++ DirectFB/src/core/agp/Makefile.am Wed Dec 11 00:27:20 2002
@@ -0,0 +1,25 @@
+## Makefile.am for DirectFB/src/core/agp
+
+INCLUDES = \
+ -I$(top_srcdir)/include \
+ -I$(top_builddir)/include \
+ -I$(top_srcdir)/src
+
+AM_CFLAGS = $(DFB_CFLAGS)
+
+AM_CPPFLAGS = \
+ -DDATADIR=\"@DATADIR@\" \
+ -DSOPATH=\"@SOPATH@\" \
+ -DMODULEDIR=\"@MODULEDIR@\" \
+ "-DBUILDTIME=\"`date -u "+%Y-%m-%d %H:%M"`\""
+
+
+internalincludedir = $(INTERNALINCLUDEDIR)/core/agp
+
+internalinclude_HEADERS = \
+ agp.h
+
+noinst_LTLIBRARIES = libdirectfb_agp.la
+
+libdirectfb_agp_la_SOURCES = \
+ agp.c
diff -urN DirectFB/src/core/agp/agp.c DirectFB/src/core/agp/agp.c
--- DirectFB/src/core/agp/agp.c Thu Jan 1 02:00:00 1970
+++ DirectFB/src/core/agp/agp.c Wed Dec 11 00:38:54 2002
@@ -0,0 +1,451 @@
+#include "config.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+
+#include <linux/agpgart.h>
+
+#include <pthread.h>
+
+#include <core/fusion/shmalloc.h>
+#include <core/fusion/arena.h>
+#include <core/fusion/list.h>
+
+#include <directfb.h>
+
+#include <core/core.h>
+#include <core/coredefs.h>
+#include <core/coretypes.h>
+
+#include <core/agp/agp.h>
+#include <core/gfxcard.h>
+#include <core/surfacemanager.h>
+
+#include <misc/mem.h>
+#include <misc/util.h>
+
+typedef struct _AGPShared AGPShared;
+struct _AGPShared {
+ unsigned int agp_mem;
+ int agp_key;
+ agp_info info;
+ SurfaceManager *surface_manager;
+};
+
+typedef struct _AGP AGP;
+struct _AGP {
+ AGPShared *shared;
+ int fd;
+ void *agp_base;
+};
+
+static AGP *agp = NULL;
+#define Sagp (agp->shared)
+
+static DFBResult dfb_agp_open()
+{
+ agp->fd = open( "/dev/agpgart", O_RDWR, 0 );
+ if (agp->fd < 0) {
+ PERRORMSG( "DirectFB/core/agp: Error opening `/dev/agpgart'!\n" );
+ return errno2dfb( errno );
+ }
+
+ return DFB_OK;
+}
+
+static DFBResult dfb_agp_info( agp_info *info )
+{
+ if (ioctl( agp->fd, AGPIOC_INFO, info ) != 0) {
+ PERRORMSG( "DirectFB/core/agp: Could not get AGP info!\n" );
+ return errno2dfb( errno );
+ }
+
+ return DFB_OK;
+}
+
+static DFBResult dfb_agp_setup( __u32 mode )
+{
+ agp_setup setup;
+ setup.agp_mode = mode;
+
+ if (ioctl( agp->fd, AGPIOC_SETUP, &setup ) != 0) {
+ PERRORMSG( "DirectFB/core/agp: AGP setup failed!\n" );
+ return errno2dfb( errno );
+ }
+
+ return DFB_OK;
+}
+
+static DFBResult dfb_agp_acquire()
+{
+ if (ioctl( agp->fd, AGPIOC_ACQUIRE, 0 ) != 0) {
+ PERRORMSG( "DirectFB/core/agp: Acquire failed!\n" );
+ return errno2dfb( errno );
+ }
+
+ return DFB_OK;
+}
+
+static DFBResult dfb_agp_release()
+{
+ if (ioctl( agp->fd, AGPIOC_RELEASE, 0 ) != 0) {
+ PERRORMSG( "DirectFB/core/agp: Release failed!\n" );
+ return errno2dfb( errno );
+ }
+
+ return DFB_OK;
+}
+
+static DFBResult dfb_agp_allocate( unsigned long size, int *key )
+{
+ agp_allocate alloc;
+ int pages;
+
+ if (!key)
+ return DFB_INVARG;
+
+ pages = (size / PAGE_SIZE);
+ if (size % PAGE_SIZE)
+ pages++;
+
+ if (pages == 0) {
+ BUG( "DirectFB/core/agp: Attempted to allocate 0 pages!\n");
+ return DFB_BUG;
+ }
+
+ alloc.pg_count = pages;
+ alloc.type = 0;
+
+ if (ioctl( agp->fd, AGPIOC_ALLOCATE, &alloc ) != 0) {
+ PERRORMSG( "DirectFB/core/agp: "
+ "Allocate failed (%d pages)!\n",
+ pages );
+ return errno2dfb( errno );
+ }
+
+ *key = alloc.key;
+ return DFB_OK;
+}
+
+static DFBResult dfb_agp_deallocate( int key )
+{
+ if (ioctl( agp->fd, AGPIOC_DEALLOCATE, key ) != 0) {
+ PERRORMSG( "DirectFB/core/agp: "
+ "Deallocate failed (key = %d)!\n",
+ key );
+ return errno2dfb( errno );
+ }
+
+ return DFB_OK;
+}
+
+static DFBResult dfb_agp_bind( int key, unsigned int offset )
+{
+ agp_bind bind;
+ int page_offset;
+
+ if (offset % PAGE_SIZE) {
+ BUG( "DirectFB/core/agp: Offset is not page-aligned!\n" );
+ return DFB_BUG;
+ }
+ page_offset = offset / PAGE_SIZE;
+
+ bind.pg_start = page_offset;
+ bind.key = key;
+
+ if (ioctl( agp->fd, AGPIOC_BIND, &bind ) != 0) {
+ PERRORMSG( "DirectFB/core/agp: "
+ "Bind failed (key = %d, offset = 0x%x)!\n",
+ key, offset );
+ return errno2dfb( errno );
+ }
+
+ return DFB_OK;
+}
+
+static DFBResult dfb_agp_unbind( int key )
+{
+ agp_unbind unbind;
+
+ unbind.priority = 0;
+ unbind.key = key;
+
+ if (ioctl( agp->fd, AGPIOC_UNBIND, &unbind ) != 0) {
+ PERRORMSG( "DirectFB/core/agp: "
+ "Unbind failed (key = %d)!\n",
+ key );
+ return errno2dfb( errno );
+ }
+
+ return DFB_OK;
+}
+
+/* public */
+
+DFBResult dfb_agp_initialize()
+{
+ unsigned int byteoffset_alignment, pixelpitch_alignment;
+ unsigned int agp_avail;
+ DFBResult ret;
+
+ if (agp) {
+ BUG( "dfb_agp_init() already called!" );
+ return DFB_BUG;
+ }
+
+ agp = (AGP*) DFBCALLOC( 1, sizeof(AGP) );
+ Sagp = (AGPShared*) shcalloc( 1, sizeof(AGPShared) );
+
+ ret = dfb_agp_open();
+ if (ret) {
+ shfree( Sagp );
+ DFBFREE( agp );
+ agp = NULL;
+
+ return ret;
+ }
+
+ ret = dfb_agp_acquire();
+ if (ret) {
+ shfree( Sagp );
+ close( agp->fd );
+ DFBFREE( agp );
+ agp = NULL;
+
+ return ret;
+ }
+
+ ret = dfb_agp_info( &Sagp->info );
+ if (ret) {
+ shfree( Sagp );
+ dfb_agp_release();
+ close( agp->fd );
+ DFBFREE( agp );
+ agp = NULL;
+
+ return ret;
+ }
+
+ DEBUGMSG( "DirectFB/core/agp: "
+ "Bridge supports: AGP%s%s%s%s%s\n",
+ Sagp->info.agp_mode & 0x1 ? " 1X" : "",
+ Sagp->info.agp_mode & 0x2 ? " 2X" : "",
+ Sagp->info.agp_mode & 0x4 ? " 4X" : "",
+ Sagp->info.agp_mode & 0x200 ? ", SBA" : "",
+ Sagp->info.agp_mode & 0x10 ? ", FW" : "" );
+
+ ret = dfb_agp_setup( Sagp->info.agp_mode );
+ if (ret != DFB_OK) {
+ shfree( Sagp );
+ dfb_agp_release();
+ close( agp->fd );
+ DFBFREE( agp );
+ agp = NULL;
+
+ return ret;
+ }
+
+ INITMSG( "DirectFB/core/agp: "
+ "AGP aperture at 0x%x (%d MB)\n",
+ (unsigned int) Sagp->info.aper_base, Sagp->info.aper_size );
+
+ agp_avail = (Sagp->info.pg_total - Sagp->info.pg_used) * PAGE_SIZE;
+ if (agp_avail == 0) {
+ ERRORMSG( "DirectFB/core/agp: No AGP memory available!\n" );
+ shfree( Sagp );
+ dfb_agp_release();
+ close( agp->fd );
+ DFBFREE( agp );
+ agp = NULL;
+
+ return DFB_INIT;
+ }
+
+ Sagp->agp_mem = Sagp->info.aper_size << 20;
+ if (Sagp->agp_mem > agp_avail)
+ Sagp->agp_mem = agp_avail;
+ if (Sagp->agp_mem > dfb_config->agpmem_limit)
+ Sagp->agp_mem = dfb_config->agpmem_limit;
+
+ ret = dfb_agp_allocate( Sagp->agp_mem, &Sagp->agp_key );
+ if (ret != DFB_OK) {
+ shfree( Sagp );
+ dfb_agp_release();
+ close( agp->fd );
+ DFBFREE( agp );
+ agp = NULL;
+
+ return ret;
+ }
+ ret = dfb_agp_bind( Sagp->agp_key, 0 );
+ if (ret != DFB_OK) {
+ dfb_agp_deallocate( Sagp->agp_key );
+
+ shfree( Sagp );
+ dfb_agp_release();
+ close( agp->fd );
+ DFBFREE( agp );
+ agp = NULL;
+
+ return ret;
+ }
+
+ INITMSG( "DirectFB/core/agp: Using %d MB of AGP memory (%d MB available)\n",
+ Sagp->agp_mem >> 20, agp_avail >> 20 );
+
+ /* Map the AGP aperture */
+ agp->agp_base = mmap( NULL, Sagp->info.aper_size << 20,
+ PROT_READ | PROT_WRITE, MAP_SHARED,
+ agp->fd, 0 );
+ if (agp->agp_base == MAP_FAILED) {
+ PERRORMSG( "DirectFB/core/agp: "
+ "Could not mmap the AGP aperture!\n" );
+ dfb_agp_deallocate( Sagp->agp_key );
+
+ shfree( Sagp );
+ dfb_agp_release();
+ close( agp->fd );
+ DFBFREE( agp );
+ agp = NULL;
+
+ return DFB_INIT;
+ }
+ DEBUGMSG( "DirectFB/core/agp: AGP aperture mapped at 0x%x\n",
+ (unsigned int) agp->agp_base );
+
+ dfb_agp_release();
+
+ dfb_gfxcard_get_alignment_limits( &byteoffset_alignment, &pixelpitch_alignment );
+ Sagp->surface_manager = dfb_surfacemanager_create( Sagp->agp_mem,
+byteoffset_alignment, pixelpitch_alignment );
+
+#ifndef FUSION_FAKE
+ arena_add_shared_field( dfb_core->arena, "Sagp", Sagp );
+#endif
+
+ return DFB_OK;
+}
+
+#ifndef FUSION_FAKE
+DFBResult dfb_agp_join()
+{
+ DFBResult ret;
+
+ agp = (AGP*) DFBCALLOC( 1, sizeof(AGP) );
+
+ arena_get_shared_field( dfb_core->arena, "Sagp", (void**) &Sagp );
+
+ ret = dfb_agp_open();
+ if (ret) {
+ DFBFREE( agp );
+ agp = NULL;
+
+ return ret;
+ }
+
+ ret = dfb_agp_acquire();
+ if (ret) {
+ close( agp->fd );
+ DFBFREE( agp );
+ agp = NULL;
+
+ return ret;
+ }
+
+ /* Map the AGP aperture */
+ agp->agp_base = mmap( NULL, Sagp->info.aper_size * 0x100000,
+ PROT_READ | PROT_WRITE, MAP_SHARED,
+ agp->fd, 0 );
+ if (agp->agp_base == MAP_FAILED) {
+ PERRORMSG( "DirectFB/core/agp: "
+ "Could not mmap the AGP aperture!\n" );
+ dfb_agp_release();
+ close( agp->fd );
+ DFBFREE( agp );
+ agp = NULL;
+
+ return DFB_INIT;
+ }
+ DEBUGMSG( "DirectFB/core/agp: AGP aperture mapped at 0x%x\n",
+ (unsigned int) agp->agp_base );
+
+ dfb_agp_release();
+
+ return DFB_OK;
+}
+#endif
+
+DFBResult dfb_agp_shutdown( bool emergency )
+{
+ if (!agp)
+ return DFB_OK;
+
+ dfb_agp_acquire();
+
+ munmap( agp->agp_base, Sagp->info.aper_size * 0x100000 );
+
+ dfb_agp_unbind( Sagp->agp_key );
+ dfb_agp_deallocate( Sagp->agp_key );
+
+ dfb_agp_release();
+ close( agp->fd );
+
+ dfb_surfacemanager_destroy( Sagp->surface_manager );
+
+ shfree( Sagp );
+
+ DFBFREE( agp );
+ agp = NULL;
+
+ return DFB_OK;
+}
+
+#ifndef FUSION_FAKE
+DFBResult dfb_agp_leave( bool emergency )
+{
+ if (!agp)
+ return DFB_OK;
+
+ dfb_agp_acquire();
+
+ munmap( agp->agp_base, Sagp->info.aper_size * 0x100000 );
+
+ dfb_agp_release();
+ close( agp->fd );
+
+ DFBFREE( agp );
+ agp = NULL;
+
+ return DFB_OK;
+}
+#endif
+
+#ifdef FUSION_FAKE
+DFBResult dfb_agp_suspend()
+{
+ return dfb_surfacemanager_suspend( Sagp->surface_manager );
+}
+
+DFBResult dfb_agp_resume()
+{
+ return dfb_surfacemanager_resume( Sagp->surface_manager );
+}
+#endif
+
+SurfaceManager *dfb_agp_surface_manager()
+{
+ return Sagp->surface_manager;
+}
+
+unsigned long dfb_agp_memory_physical( unsigned int offset )
+{
+ return Sagp->info.aper_base + offset;
+}
+
+void *dfb_agp_memory_virtual( unsigned int offset )
+{
+ return (void*)((__u8*)(agp->agp_base) + offset);
+}
diff -urN DirectFB/src/core/agp/agp.h DirectFB/src/core/agp/agp.h
--- DirectFB/src/core/agp/agp.h Thu Jan 1 02:00:00 1970
+++ DirectFB/src/core/agp/agp.h Wed Dec 11 00:27:15 2002
@@ -0,0 +1,23 @@
+#ifndef __CORE__AGP_H__
+#define __CORE__AGP_H__
+
+#include <directfb.h>
+#include <core/surfacemanager.h>
+
+DFBResult dfb_agp_initialize();
+DFBResult dfb_agp_join();
+
+DFBResult dfb_agp_shutdown( bool emergency );
+DFBResult dfb_agp_leave( bool emergency );
+
+#ifdef FUSION_FAKE
+DFBResult dfb_agp_suspend();
+DFBResult dfb_agp_resume();
+#endif
+
+SurfaceManager *dfb_agp_surface_manager();
+
+unsigned long dfb_agp_memory_physical( unsigned int offset );
+void *dfb_agp_memory_virtual( unsigned int offset );
+
+#endif
diff -urN DirectFB/src/core/core.c DirectFB/src/core/core.c
--- DirectFB/src/core/core.c Wed Dec 4 02:15:17 2002
+++ DirectFB/src/core/core.c Wed Dec 11 00:35:46 2002
@@ -49,6 +49,7 @@
#include <core/layers.h>
#include <core/surfaces.h>
#include <core/surfacemanager.h>
+#include <core/agp/agp.h>
#include <misc/mem.h>
#include <misc/memcpy.h>
@@ -280,6 +281,12 @@
if (ret)
return ret;
+#ifdef SUPPORT_AGP
+ ret = dfb_agp_suspend();
+ if (ret)
+ return ret;
+#endif
+
return DFB_OK;
#endif
}
@@ -296,6 +303,12 @@
if (ret)
return ret;
+#ifdef SUPPORT_AGP
+ ret = dfb_agp_resume();
+ if (ret)
+ return ret;
+#endif
+
ret = dfb_layers_resume();
if (ret)
return ret;
@@ -383,7 +396,13 @@
ret = dfb_gfxcard_initialize();
if (ret)
return ret;
-
+
+#ifdef SUPPORT_AGP
+ ret = dfb_agp_initialize();
+ if (ret)
+ return ret;
+#endif
+
ret = dfb_layers_initialize();
if (ret)
return ret;
@@ -426,7 +445,13 @@
ret = dfb_gfxcard_join();
if (ret)
return ret;
-
+
+#ifdef SUPPORT_AGP
+ ret = dfb_agp_join();
+ if (ret)
+ return ret;
+#endif
+
ret = dfb_layers_join();
if (ret)
return ret;
@@ -458,6 +483,9 @@
dfb_layers_shutdown( emergency );
dfb_gfxcard_shutdown( emergency );
+#ifdef SUPPORT_AGP
+ dfb_agp_shutdown( emergency );
+#endif
dfb_input_shutdown( emergency );
dfb_system_shutdown( emergency );
@@ -487,7 +515,10 @@
dfb_input_leave( emergency );
dfb_layers_leave( emergency );
dfb_gfxcard_leave( emergency );
-
+#ifdef SUPPORT_AGP
+ dfb_agp_leave( emergency );
+#endif
+
dfb_system_leave( emergency );
dfb_colorhash_leave( emergency );
diff -urN DirectFB/src/core/gfxcard.c DirectFB/src/core/gfxcard.c
--- DirectFB/src/core/gfxcard.c Thu Nov 14 17:57:44 2002
+++ DirectFB/src/core/gfxcard.c Wed Dec 11 00:35:46 2002
@@ -1181,6 +1181,19 @@
return Scard->videoram_length;
}
+DFBResult
+dfb_gfxcard_get_alignment_limits( unsigned int *byteoffset_alignment,
+ unsigned int *pixelpitch_alignment )
+{
+ if (!byteoffset_alignment || !pixelpitch_alignment)
+ return DFB_INVARG;
+
+ *byteoffset_alignment = Scard->device_info.limits.surface_byteoffset_alignment;
+ *pixelpitch_alignment = Scard->device_info.limits.surface_pixelpitch_alignment;
+
+ return DFB_OK;
+}
+
volatile void *
dfb_gfxcard_map_mmio( GraphicsDevice *device,
unsigned int offset,
diff -urN DirectFB/src/core/gfxcard.h DirectFB/src/core/gfxcard.h
--- DirectFB/src/core/gfxcard.h Tue Oct 22 21:01:55 2002
+++ DirectFB/src/core/gfxcard.h Wed Dec 11 00:35:46 2002
@@ -262,6 +262,9 @@
unsigned int dfb_gfxcard_memory_length();
+DFBResult dfb_gfxcard_get_alignment_limits( unsigned int *byteoffset_alignment,
+ unsigned int *pixelpitch_alignment );
+
/*
* Graphics drivers call this function to get access to MMIO regions.
*
diff -urN DirectFB/src/core/surfacemanager.c DirectFB/src/core/surfacemanager.c
--- DirectFB/src/core/surfacemanager.c Wed Dec 4 02:15:17 2002
+++ DirectFB/src/core/surfacemanager.c Wed Dec 11 00:35:46 2002
@@ -159,6 +159,7 @@
while (c) {
if (c->buffer &&
c->buffer->policy != CSP_VIDEOONLY &&
+ c->buffer->policy != CSP_AGPONLY &&
c->buffer->video.health == CSH_STORED)
{
dfb_surfacemanager_assure_system( manager, c->buffer );
@@ -293,8 +294,10 @@
if (c->buffer &&
!c->buffer->video.locked &&
c->buffer->policy != CSP_VIDEOONLY &&
+ c->buffer->policy != CSP_AGPONLY &&
((c->tolerations > min_toleration/8) ||
- buffer->policy == CSP_VIDEOONLY))
+ buffer->policy == CSP_VIDEOONLY ||
+ buffer->policy == CSP_AGPONLY))
{
/* found a nice place to chill */
if (!best_occupied ||
@@ -457,8 +460,9 @@
{
CoreSurface *surface = buffer->surface;
- if (buffer->policy == CSP_VIDEOONLY) {
- BUG( "surface_manager_assure_system() called on video only surface" );
+ if (buffer->policy == CSP_VIDEOONLY ||
+ buffer->policy == CSP_AGPONLY) {
+ BUG( "surface_manager_assure_system() called on video/AGP only surface" );
return DFB_BUG;
}
diff -urN DirectFB/src/core/surfaces.c DirectFB/src/core/surfaces.c
--- DirectFB/src/core/surfaces.c Fri Nov 22 23:46:42 2002
+++ DirectFB/src/core/surfaces.c Wed Dec 11 00:35:46 2002
@@ -40,6 +40,7 @@
#include <core/coredefs.h>
#include <core/coretypes.h>
+#include <core/agp/agp.h>
#include <core/gfxcard.h>
#include <core/layers.h>
#include <core/palette.h>
@@ -121,6 +122,9 @@
case CSP_VIDEOONLY:
s->caps |= DSCAPS_VIDEOONLY;
break;
+ case CSP_AGPONLY:
+ s->caps |= DSCAPS_AGPONLY;
+ break;
default:
;
}
@@ -161,7 +165,7 @@
DFBResult ret;
CoreSurface *s;
- if (policy == CSP_VIDEOONLY)
+ if (policy == CSP_VIDEOONLY || policy == CSP_AGPONLY)
return DFB_UNSUPPORTED;
s = (CoreSurface*) fusion_object_create( dfb_gfxcard_surface_pool() );
@@ -516,6 +520,12 @@
*pitch = buffer->video.pitch;
video_access_by_software( buffer, flags );
break;
+ case CSP_AGPONLY:
+ buffer->video.locked++;
+ *data = dfb_agp_memory_virtual( buffer->video.offset );
+ *pitch = buffer->video.pitch;
+ video_access_by_software( buffer, flags );
+ break;
default:
BUG( "invalid surface policy" );
@@ -567,6 +577,7 @@
/* fall through */
case CSP_VIDEOONLY:
+ case CSP_AGPONLY:
buffer->video.locked++;
video_access_by_hardware( buffer, flags );
return DFB_OK;
@@ -726,8 +737,11 @@
dfb_palette_unref( palette );
}
- surface->manager = dfb_gfxcard_surface_manager();
-
+ if (caps & DSCAPS_AGPONLY)
+ surface->manager = dfb_agp_surface_manager();
+ else
+ surface->manager = dfb_gfxcard_surface_manager();
+
return DFB_OK;
}
@@ -784,7 +798,8 @@
break;
}
- case CSP_VIDEOONLY: {
+ case CSP_VIDEOONLY:
+ case CSP_AGPONLY: {
DFBResult ret;
/* Lock surface manager. */
diff -urN DirectFB/src/core/surfaces.h DirectFB/src/core/surfaces.h
--- DirectFB/src/core/surfaces.h Fri Nov 22 23:46:42 2002
+++ DirectFB/src/core/surfaces.h Wed Dec 11 00:35:46 2002
@@ -70,8 +70,9 @@
store in video memory */
CSP_VIDEOLOW = 0x00000002, /* try to store in video memory,
low priority */
- CSP_VIDEOHIGH = 0x00000003 /* try to store in video memory,
+ CSP_VIDEOHIGH = 0x00000003, /* try to store in video memory,
high priority */
+ CSP_AGPONLY = 0x00000004 /* store in AGP memory only */
} CoreSurfacePolicy;
typedef enum {
diff -urN DirectFB/src/idirectfb.c DirectFB/src/idirectfb.c
--- DirectFB/src/idirectfb.c Thu Nov 14 17:57:44 2002
+++ DirectFB/src/idirectfb.c Wed Dec 11 00:35:46 2002
@@ -523,11 +523,14 @@
policy = CSP_VIDEOONLY;
else if (caps & DSCAPS_SYSTEMONLY)
policy = CSP_SYSTEMONLY;
+ else if (caps & DSCAPS_AGPONLY)
+ policy = CSP_AGPONLY;
if (desc->flags & DSDESC_PREALLOCATED) {
int min_pitch;
- if (policy == CSP_VIDEOONLY)
+ if (policy == CSP_VIDEOONLY ||
+ policy == CSP_AGPONLY)
return DFB_INVARG;
min_pitch = DFB_BYTES_PER_LINE(format, width);
diff -urN DirectFB/src/misc/conf.c DirectFB/src/misc/conf.c
--- DirectFB/src/misc/conf.c Wed Dec 11 00:08:04 2002
+++ DirectFB/src/misc/conf.c Wed Dec 11 00:35:46 2002
@@ -117,6 +117,8 @@
"Allow translucent windows\n"
" videoram-limit=<amount> "
"Limit amount of Video RAM in kb\n"
+ " agpmem-limit=<amount> "
+ "Limit amount of AGP memory in kb\n"
" matrox-tv-standard=[pal|ntsc] "
"Matrox TV standard (default=pal)\n"
" [no-]matrox-sgram "
@@ -381,6 +383,25 @@
}
else {
ERRORMSG("DirectFB/Config 'videoram-limit': No value specified!\n");
+ return DFB_INVARG;
+ }
+ } else
+ if (strcmp (name, "agpmem-limit" ) == 0) {
+ if (value) {
+ int limit;
+
+ if (sscanf( value, "%d", &limit ) < 1) {
+ ERRORMSG("DirectFB/Config 'agpmem-limit': Could not parse
+value!\n");
+ return DFB_INVARG;
+ }
+
+ if (limit < 0)
+ limit = 0;
+
+ dfb_config->agpmem_limit = PAGE_ALIGN(limit<<10);
+ }
+ else {
+ ERRORMSG("DirectFB/Config 'agpmem-limit': No value specified!\n");
return DFB_INVARG;
}
} else
diff -urN DirectFB/src/misc/conf.h DirectFB/src/misc/conf.h
--- DirectFB/src/misc/conf.h Wed Dec 4 02:15:18 2002
+++ DirectFB/src/misc/conf.h Wed Dec 11 00:35:46 2002
@@ -100,6 +100,8 @@
int videoram_limit; /* limit amount of video
memory used by DirectFB */
+ int agpmem_limit; /* limit amount of AGP
+ memory used by DirectFB */
sigset_t dont_catch; /* don't catch these signals */