xf86-video-intel: 2 commits - src/i830_driver.c src/i830.h src/i830_memory.c
Eric Anholt
anholt at kemper.freedesktop.org
Fri Oct 12 16:15:04 PDT 2007
src/i830.h | 5 +++++
src/i830_driver.c | 10 ++++++++++
src/i830_memory.c | 22 +++++++++++++++++++++-
3 files changed, 36 insertions(+), 1 deletion(-)
New commits:
diff-tree e04333a6352040bc883655d606923c912d005981 (from a1612b7728d4153499fe86b6713a13c8702cc7d9)
Author: Eric Anholt <eric at anholt.net>
Date: Fri Oct 12 12:42:45 2007 -0700
Fix failure in tiling setup on non-power-of-two allocations on pre-965.
diff --git a/src/i830.h b/src/i830.h
index 031781e..57f0544 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -145,6 +145,11 @@ struct _i830_memory {
*/
unsigned long size;
/**
+ * Allocated aperture size, taking into account padding to allow for
+ * tiling.
+ */
+ unsigned long allocated_size;
+ /**
* Physical (or more properly, bus) address of the allocation.
* Only set if requested during allocation.
*/
diff --git a/src/i830_memory.c b/src/i830_memory.c
index 35e19f9..2ddc454 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -190,7 +190,7 @@ i830_bind_memory(ScrnInfoPtr pScrn, i830
if (mem->tiling != TILE_NONE) {
mem->fence_nr = i830_set_tiling(pScrn, mem->offset, mem->pitch,
- mem->size, mem->tiling);
+ mem->allocated_size, mem->tiling);
}
/* Mark the pages accessible now that they're bound. */
@@ -617,6 +617,7 @@ i830_allocate_aperture(ScrnInfoPtr pScrn
/* Only allocate page-sized increments. */
size = ALIGN(size, GTT_PAGE_SIZE);
mem->size = size;
+ mem->allocated_size = size;
if (alignment < GTT_PAGE_SIZE)
alignment = GTT_PAGE_SIZE;
@@ -754,6 +755,7 @@ i830_allocate_memory_bo(ScrnInfoPtr pScr
mem->offset = -1;
mem->end = -1;
mem->size = size;
+ mem->allocated_size = size;
if (flags & NEED_LIFETIME_FIXED)
mem->lifetime_fixed_offset = TRUE;
diff-tree a1612b7728d4153499fe86b6713a13c8702cc7d9 (from 3af442ba52550a9d183e215d49cc12dac0cb9e4b)
Author: Eric Anholt <eric at anholt.net>
Date: Fri Oct 12 12:42:06 2007 -0700
Use mprotect on unbound AGP memory to attempt to catch use while unbound.
This doesn't help with the most common use-while-unbound cases, which are
from the hardware side.
diff --git a/src/i830_driver.c b/src/i830_driver.c
index 9ca1222..0eb6e2d 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -171,6 +171,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
+#include <sys/mman.h>
#include "xf86.h"
#include "xf86_OSproc.h"
@@ -667,6 +668,15 @@ I830MapMem(ScrnInfoPtr pScrn)
pI830->FbBase + pI830->LpRing->mem->offset;
}
+ /* Mark the pages we haven't yet bound into AGP as inaccessible. */
+ if (pI830->FbMapSize > pI830->stolen_size) {
+ if (mprotect(pI830->FbBase + pI830->stolen_size,
+ pI830->FbMapSize - pI830->stolen_size, PROT_NONE) != 0) {
+ xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+ "Failed to mprotect unbound AGP: %s\n", strerror(errno));
+ }
+ }
+
return TRUE;
}
diff --git a/src/i830_memory.c b/src/i830_memory.c
index 9dfe43e..35e19f9 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -98,6 +98,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN
#include <assert.h>
#include <string.h>
+#include <errno.h>
+#include <sys/mman.h>
#include "xf86.h"
#include "xf86_OSproc.h"
@@ -191,15 +193,31 @@ i830_bind_memory(ScrnInfoPtr pScrn, i830
mem->size, mem->tiling);
}
+ /* Mark the pages accessible now that they're bound. */
+ if (mprotect(pI830->FbBase + mem->offset, ALIGN(mem->size, GTT_PAGE_SIZE),
+ PROT_READ | PROT_WRITE) != 0) {
+ xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+ "Failed to mprotect %s: %s\n", mem->name, strerror(errno));
+ }
+
return TRUE;
}
static Bool
i830_unbind_memory(ScrnInfoPtr pScrn, i830_memory *mem)
{
+ I830Ptr pI830 = I830PTR(pScrn);
+
if (mem == NULL || !mem->bound)
return TRUE;
+ /* Mark the pages accessible now that they're bound. */
+ if (mprotect(pI830->FbBase + mem->offset, ALIGN(mem->size, GTT_PAGE_SIZE),
+ PROT_NONE) != 0) {
+ xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+ "Failed to mprotect %s: %s\n", mem->name, strerror(errno));
+ }
+
if (mem->tiling != TILE_NONE)
i830_clear_tiling(pScrn, mem->fence_nr);
More information about the xorg-commit
mailing list