summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2008-05-02 10:06:13 -0700
committerEric Anholt <eric@anholt.net>2008-05-02 10:06:13 -0700
commit271abfd0ec29851273d8ca5241d963be5c64e43c (patch)
treee3512e53caad486787667e792e052d3f9a74ff56
parent152a50703aa5e9ebaa9abbe448518742734a5eb7 (diff)
Add initial GEM hacks to bring the server up.
-rw-r--r--src/i830.h2
-rw-r--r--src/i830_dri.c2
-rw-r--r--src/i830_driver.c13
-rw-r--r--src/i830_memory.c75
4 files changed, 42 insertions, 50 deletions
diff --git a/src/i830.h b/src/i830.h
index 4e82036b..8bc0af4f 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -195,7 +195,7 @@ struct _i830_memory {
/** @} */
#ifdef XF86DRI_MM
- drmBO bo;
+ uint32_t gem_handle;
Bool lifetime_fixed_offset;
#endif
};
diff --git a/src/i830_dri.c b/src/i830_dri.c
index 4361ad0b..1c5de8f4 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -1542,6 +1542,7 @@ i830_update_sarea(ScrnInfoPtr pScrn, drmI830Sarea *sarea)
sarea->third_bo_handle = -1;
sarea->depth_bo_handle = -1;
#ifdef XF86DRI_MM
+ /* XXX
if (pI830->front_buffer->bo.size)
sarea->front_bo_handle = pI830->front_buffer->bo.handle;
if (pI830->back_buffer->bo.size)
@@ -1550,6 +1551,7 @@ i830_update_sarea(ScrnInfoPtr pScrn, drmI830Sarea *sarea)
sarea->third_bo_handle = pI830->third_buffer->bo.handle;
if (pI830->depth_buffer->bo.size)
sarea->depth_bo_handle = pI830->depth_buffer->bo.handle;
+ */
#endif
/* The rotation is now handled entirely by the X Server, so just leave the
diff --git a/src/i830_driver.c b/src/i830_driver.c
index ea37e6d6..63fc8cb9 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -3184,9 +3184,10 @@ I830LeaveVT(int scrnIndex, int flags)
*/
#ifdef XF86DRI_MM
if (pI830->directRenderingOpen) {
+ /* XXX:
if (pI830->memory_manager != NULL && pScrn->vtSema) {
drmMMLock(pI830->drmSubFD, DRM_BO_MEM_TT, 1, 0);
- }
+ }*/
}
#endif /* XF86DRI_MM */
@@ -3224,9 +3225,11 @@ I830EnterVT(int scrnIndex, int flags)
/* Unlock the memory manager first of all so that we can pin our
* buffer objects
*/
+ /*
if (pI830->memory_manager != NULL && pScrn->vtSema) {
drmMMUnlock(pI830->drmSubFD, DRM_BO_MEM_TT, 1);
}
+ */
}
#endif /* XF86DRI_MM */
@@ -3353,14 +3356,6 @@ I830CloseScreen(int scrnIndex, ScreenPtr pScreen)
if (pScrn->vtSema == TRUE) {
I830LeaveVT(scrnIndex, 0);
-#ifdef XF86DRI_MM
- if (pI830->directRenderingEnabled) {
- if (pI830->memory_manager != NULL) {
- drmMMUnlock(pI830->drmSubFD, DRM_BO_MEM_TT, 1);
- }
- }
-#endif /* XF86DRI_MM */
-
}
if (pI830->devicesTimer)
diff --git a/src/i830_memory.c b/src/i830_memory.c
index 84db0ef1..cee46a87 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -101,12 +101,16 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <string.h>
#include <errno.h>
#include <sys/types.h>
+#include <sys/ioctl.h>
#include "xf86.h"
#include "xf86_OSproc.h"
#include "i830.h"
#include "i810_reg.h"
+#ifdef XF86DRI_MM
+#include "i915_drm.h"
+#endif
#define ALIGN(i,m) (((i) + (m) - 1) & ~((m) - 1))
@@ -161,27 +165,19 @@ i830_bind_memory(ScrnInfoPtr pScrn, i830_memory *mem)
return TRUE;
#ifdef XF86DRI_MM
- if (mem->bo.size != 0) {
+ if (mem->gem_handle != 0) {
I830Ptr pI830 = I830PTR(pScrn);
+ struct drm_i915_gem_pin pin;
int ret;
- ret = drmBOSetStatus(pI830->drmSubFD, &mem->bo,
- DRM_BO_FLAG_MEM_VRAM |
- DRM_BO_FLAG_MEM_TT |
- DRM_BO_FLAG_READ |
- DRM_BO_FLAG_WRITE |
- DRM_BO_FLAG_NO_EVICT,
- DRM_BO_MASK_MEM |
- DRM_BO_FLAG_READ |
- DRM_BO_FLAG_WRITE |
- DRM_BO_FLAG_NO_EVICT,
- 0, 0, 0);
+ pin.handle = mem->gem_handle;
+ ret = ioctl(pI830->drmSubFD, DRM_IOCTL_I915_GEM_PIN, &pin);
if (ret != 0)
return FALSE;
mem->bound = TRUE;
- mem->offset = mem->bo.offset;
- mem->end = mem->bo.offset + mem->size;
+ mem->offset = pin.offset;
+ mem->end = mem->offset + mem->size;
}
#endif
@@ -216,13 +212,13 @@ i830_unbind_memory(ScrnInfoPtr pScrn, i830_memory *mem)
i830_clear_tiling(pScrn, mem->fence_nr);
#ifdef XF86DRI_MM
- if (mem->bo.size != 0) {
+ if (mem->gem_handle != 0) {
I830Ptr pI830 = I830PTR(pScrn);
+ struct drm_i915_gem_unpin unpin;
int ret;
- ret = drmBOSetStatus(pI830->drmSubFD, &mem->bo,
- 0, DRM_BO_FLAG_NO_EVICT,
- 0, 0, 0);
+ unpin.handle = mem->gem_handle;
+ ret = ioctl(pI830->drmSubFD, DRM_IOCTL_I915_GEM_UNPIN, &unpin);
if (ret == 0) {
mem->bound = FALSE;
@@ -254,10 +250,12 @@ i830_free_memory(ScrnInfoPtr pScrn, i830_memory *mem)
i830_unbind_memory(pScrn, mem);
#ifdef XF86DRI_MM
- if (mem->bo.size != 0) {
+ if (mem->gem_handle != 0) {
I830Ptr pI830 = I830PTR(pScrn);
+ struct drm_gem_unreference unref;
- drmBOUnreference(pI830->drmSubFD, &mem->bo);
+ unref.handle = mem->gem_handle;
+ ioctl(pI830->drmSubFD, DRM_IOCTL_GEM_UNREFERENCE, &unref);
if (pI830->bo_list == mem) {
pI830->bo_list = mem->next;
if (mem->next)
@@ -467,13 +465,15 @@ i830_allocator_init(ScrnInfoPtr pScrn, unsigned long offset, unsigned long size)
ALIGN_BOTH_ENDS | NEED_NON_STOLEN);
if (pI830->memory_manager != NULL) {
+ struct drm_i915_gem_init init;
int ret;
+ init.gtt_start = pI830->memory_manager->offset;
+ init.gtt_end = pI830->memory_manager->offset +
+ pI830->memory_manager->size;
+
/* Tell the kernel to manage it */
- ret = drmMMInit(pI830->drmSubFD,
- pI830->memory_manager->offset / GTT_PAGE_SIZE,
- pI830->memory_manager->size / GTT_PAGE_SIZE,
- DRM_BO_MEM_TT);
+ ret = ioctl(pI830->drmSubFD, DRM_IOCTL_I915_GEM_INIT, &init);
if (ret != 0) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"Failed to initialize kernel memory manager\n");
@@ -503,7 +503,7 @@ i830_allocator_fini(ScrnInfoPtr pScrn)
#ifdef XF86DRI_MM
/* The memory manager is more special */
if (pI830->memory_manager) {
- drmMMTakedown(pI830->drmSubFD, DRM_BO_MEM_TT);
+ /* XXX drmMMTakedown(pI830->drmSubFD, DRM_BO_MEM_TT);*/
i830_free_memory(pScrn, pI830->memory_manager);
pI830->memory_manager = NULL;
}
@@ -723,8 +723,8 @@ i830_allocate_memory_bo(ScrnInfoPtr pScrn, const char *name,
{
I830Ptr pI830 = I830PTR(pScrn);
i830_memory *mem;
- unsigned long mask;
int ret;
+ struct drm_gem_alloc alloc;
assert((flags & NEED_PHYSICAL_ADDR) == 0);
@@ -742,25 +742,17 @@ i830_allocate_memory_bo(ScrnInfoPtr pScrn, const char *name,
return NULL;
}
- /*
- * Create buffers in local memory to avoid having the creation order
- * determine the TT offset. Driver acceleration
- * cannot handle changed front buffer TT offsets yet ,
- * so let's keep our fingers crossed.
- */
-
- mask = DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_MAPPABLE |
- DRM_BO_FLAG_MEM_LOCAL;
- if (flags & ALLOW_SHARING)
- mask |= DRM_BO_FLAG_SHAREABLE;
+ memset(&alloc, 0, sizeof(alloc));
+ alloc.size = size;
- ret = drmBOCreate(pI830->drmSubFD, size, align / GTT_PAGE_SIZE, NULL,
- mask, 0, &mem->bo);
+ ret = ioctl(pI830->drmSubFD, DRM_IOCTL_GEM_ALLOC, &alloc);
if (ret) {
xfree(mem->name);
xfree(mem);
return NULL;
}
+ mem->gem_handle = alloc.handle;
+
/* Give buffer obviously wrong offset/end until it's pinned. */
mem->offset = -1;
mem->end = -1;
@@ -772,7 +764,10 @@ i830_allocate_memory_bo(ScrnInfoPtr pScrn, const char *name,
/* Bind it if we currently control the VT */
if (pScrn->vtSema) {
if (!i830_bind_memory(pScrn, mem)) {
- drmBOUnreference(pI830->drmSubFD, &mem->bo);
+ struct drm_gem_unreference unref;
+
+ unref.handle = mem->gem_handle;
+ ioctl(pI830->drmSubFD, DRM_IOCTL_GEM_UNREFERENCE, &unref);
xfree(mem->name);
xfree(mem);
return NULL;