From 5968e061db90451b19c3948bbd91c6d5ac9af941 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 7 Aug 2008 15:26:30 -0700 Subject: Make flink save the kernel-assigned name and return it instead of creating another name --- libdrm/intel/intel_bufmgr_gem.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/libdrm/intel/intel_bufmgr_gem.c b/libdrm/intel/intel_bufmgr_gem.c index 22f8695d..f5732226 100644 --- a/libdrm/intel/intel_bufmgr_gem.c +++ b/libdrm/intel/intel_bufmgr_gem.c @@ -102,6 +102,11 @@ struct _dri_bo_gem { uint32_t gem_handle; const char *name; + /** + * Kenel-assigned global name for this object + */ + unsigned int global_name; + /** * Index of the buffer within the validation list while preparing a * batchbuffer execution. @@ -833,13 +838,16 @@ dri_gem_flink(dri_bo *bo, uint32_t *name) struct drm_gem_flink flink; int ret; - flink.handle = bo_gem->gem_handle; - - ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_GEM_FLINK, &flink); - if (ret != 0) - return -errno; - - *name = flink.name; + if (!bo_gem->global_name) { + flink.handle = bo_gem->gem_handle; + + ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_GEM_FLINK, &flink); + if (ret != 0) + return -errno; + bo_gem->gem_handle = flink.name; + } + + *name = bo_gem->gem_handle; return 0; } -- cgit v1.2.3 From 0c47151a571827905c34649208e22f8ec0175d62 Mon Sep 17 00:00:00 2001 From: Stuart Bennett Date: Fri, 8 Aug 2008 16:20:52 +0100 Subject: nouveau: wait for pgraph idle after loading or saving a context the nvidia driver does this, and it stops the error message appearing on nv40 --- shared-core/nv40_graph.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/shared-core/nv40_graph.c b/shared-core/nv40_graph.c index 2540fc5f..de178f57 100644 --- a/shared-core/nv40_graph.c +++ b/shared-core/nv40_graph.c @@ -1544,6 +1544,8 @@ nv40_graph_transfer_context(struct drm_device *dev, uint32_t inst, int save) tmp |= NV40_PGRAPH_CTXCTL_0304_XFER_CTX; NV_WRITE(NV40_PGRAPH_CTXCTL_0304, tmp); + nouveau_wait_for_idle(dev); + for (i = 0; i < tv; i++) { if (NV_READ(NV40_PGRAPH_CTXCTL_030C) == 0) break; @@ -1565,9 +1567,7 @@ nv40_graph_transfer_context(struct drm_device *dev, uint32_t inst, int save) return 0; } -/* Save current context (from PGRAPH) into the channel's context - *XXX: fails sometimes, not sure why.. - */ +/* Save current context (from PGRAPH) into the channel's context */ int nv40_graph_save_context(struct nouveau_channel *chan) { @@ -1581,9 +1581,7 @@ nv40_graph_save_context(struct nouveau_channel *chan) return nv40_graph_transfer_context(dev, inst, 1); } -/* Restore the context for a specific channel into PGRAPH - * XXX: fails sometimes.. not sure why - */ +/* Restore the context for a specific channel into PGRAPH */ int nv40_graph_load_context(struct nouveau_channel *chan) { -- cgit v1.2.3 From 46e9274e8538e5b0517f611dca99dde611f4e95d Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Fri, 8 Aug 2008 13:13:46 -0700 Subject: Replace the check_aperture API with one we can make thread-safe. While the bufmgr isn't thread-safe at the moment, we need it to be for shared objects between contexts. --- libdrm/dri_bufmgr.c | 4 +-- libdrm/dri_bufmgr.h | 4 +-- libdrm/intel/intel_bufmgr_fake.c | 63 ++++++++++++++++++++++++---------------- libdrm/intel/intel_bufmgr_gem.c | 2 +- 4 files changed, 43 insertions(+), 30 deletions(-) diff --git a/libdrm/dri_bufmgr.c b/libdrm/dri_bufmgr.c index 7657df61..a6eda3bd 100644 --- a/libdrm/dri_bufmgr.c +++ b/libdrm/dri_bufmgr.c @@ -135,7 +135,7 @@ dri_bufmgr_set_debug(dri_bufmgr *bufmgr, int enable_debug) } int -dri_bufmgr_check_aperture_space(dri_bo *bo) +dri_bufmgr_check_aperture_space(dri_bo **bo_array, int count) { - return bo->bufmgr->check_aperture_space(bo); + return bo_array[0]->bufmgr->check_aperture_space(bo_array, count); } diff --git a/libdrm/dri_bufmgr.h b/libdrm/dri_bufmgr.h index a5ae6c0f..e67756bb 100644 --- a/libdrm/dri_bufmgr.h +++ b/libdrm/dri_bufmgr.h @@ -146,7 +146,7 @@ struct _dri_bufmgr { void (*post_submit)(dri_bo *batch_buf); - int (*check_aperture_space)(dri_bo *bo); + int (*check_aperture_space)(dri_bo **bo_array, int count); int debug; /**< Enables verbose debugging printouts */ }; @@ -169,6 +169,6 @@ void dri_bufmgr_destroy(dri_bufmgr *bufmgr); void *dri_process_relocs(dri_bo *batch_buf); void dri_post_process_relocs(dri_bo *batch_buf); void dri_post_submit(dri_bo *batch_buf); -int dri_bufmgr_check_aperture_space(dri_bo *bo); +int dri_bufmgr_check_aperture_space(dri_bo **bo_array, int count); #endif diff --git a/libdrm/intel/intel_bufmgr_fake.c b/libdrm/intel/intel_bufmgr_fake.c index e988eb58..63dd9bef 100644 --- a/libdrm/intel/intel_bufmgr_fake.c +++ b/libdrm/intel/intel_bufmgr_fake.c @@ -43,6 +43,8 @@ #include "i915_drm.h" #include "mm.h" +#define ALIGN(value, alignment) ((value + alignment - 1) & ~(alignment - 1)) + #define DBG(...) do { \ if (bufmgr_fake->bufmgr.debug) \ drmMsg(__VA_ARGS__); \ @@ -147,9 +149,6 @@ typedef struct _bufmgr_fake { int debug; int performed_rendering; - - /* keep track of the current total size of objects we have relocs for */ - unsigned long current_total_size; } dri_bufmgr_fake; typedef struct _dri_bo_fake { @@ -159,8 +158,8 @@ typedef struct _dri_bo_fake { const char *name; unsigned dirty:1; - unsigned size_accounted:1; /*this buffers size has been accounted against the aperture */ - unsigned card_dirty:1; /* has the card written to this buffer - we make need to copy it back */ + /** has the card written to this buffer - we make need to copy it back */ + unsigned card_dirty:1; unsigned int refcount; /* Flags may consist of any of the DRM_BO flags, plus * DRM_BO_NO_BACKING_STORE and BM_NO_FENCE_SUBDATA, which are the first two @@ -179,6 +178,12 @@ typedef struct _dri_bo_fake { /** relocation list */ struct fake_buffer_reloc *relocs; int nr_relocs; + /** + * Total size of the target_bos of this buffer. + * + * Used for estimation in check_aperture. + */ + unsigned int child_size; struct block *block; void *backing_store; @@ -189,8 +194,6 @@ typedef struct _dri_bo_fake { static int clear_fenced(dri_bufmgr_fake *bufmgr_fake, unsigned int fence_cookie); -static int dri_fake_check_aperture_space(dri_bo *bo); - #define MAXFENCE 0x7fffffff static int FENCE_LTE( unsigned a, unsigned b ) @@ -855,9 +858,6 @@ dri_fake_bo_validate(dri_bo *bo) return 0; } - /* reset size accounted */ - bo_fake->size_accounted = 0; - /* Allocate the card memory */ if (!bo_fake->block && !evict_and_alloc_block(bo)) { bufmgr_fake->fail = 1; @@ -941,8 +941,6 @@ dri_fake_emit_reloc(dri_bo *reloc_buf, assert(reloc_buf); assert(target_buf); - assert(target_fake->is_static || target_fake->size_accounted); - if (reloc_fake->relocs == NULL) { reloc_fake->relocs = malloc(sizeof(struct fake_buffer_reloc) * MAX_RELOCS); @@ -954,6 +952,9 @@ dri_fake_emit_reloc(dri_bo *reloc_buf, dri_bo_reference(target_buf); + if (!target_fake->is_static) + reloc_fake->child_size += ALIGN(target_buf->size, target_fake->alignment); + r->target_buf = target_buf; r->offset = offset; r->last_target_offset = target_buf->offset; @@ -1079,7 +1080,6 @@ dri_fake_process_relocs(dri_bo *batch_buf) assert(ret == 0); - bufmgr_fake->current_total_size = 0; return NULL; } @@ -1117,26 +1117,39 @@ dri_fake_post_submit(dri_bo *batch_buf) dri_bo_fake_post_submit(batch_buf); } +/** + * Return an error if the list of BOs will exceed the aperture size. + * + * This is a rough guess and likely to fail, as during the validate sequence we + * may place a buffer in an inopportune spot early on and then fail to fit + * a set smaller than the aperture. + */ static int -dri_fake_check_aperture_space(dri_bo *bo) +dri_fake_check_aperture_space(dri_bo **bo_array, int count) { - dri_bufmgr_fake *bufmgr_fake = (dri_bufmgr_fake *)bo->bufmgr; - dri_bo_fake *bo_fake = (dri_bo_fake *)bo; - unsigned int sz; + dri_bufmgr_fake *bufmgr_fake = (dri_bufmgr_fake *)bo_array[0]->bufmgr; + unsigned int sz = 0; + int i; - sz = (bo->size + bo_fake->alignment - 1) & ~(bo_fake->alignment - 1); + for (i = 0; i < count; i++) { + dri_bo_fake *bo_fake = (dri_bo_fake *)bo_array[i]; - if (bo_fake->size_accounted || bo_fake->is_static) - return 0; + if (bo_fake == NULL) + continue; + + if (!bo_fake->is_static) + sz += ALIGN(bo_array[i]->size, bo_fake->alignment); + sz += bo_fake->child_size; + } - if (bufmgr_fake->current_total_size + sz > bufmgr_fake->size) { - DBG("check_space: %s bo %d %d overflowed bufmgr size %d\n", bo_fake->name, bo_fake->id, sz, bufmgr_fake->size); + if (sz > bufmgr_fake->size) { + DBG("check_space: overflowed bufmgr size, %dkb vs %dkb\n", + sz / 1024, bufmgr_fake->size / 1024); return -1; } - bufmgr_fake->current_total_size += sz; - bo_fake->size_accounted = 1; - DBG("drm_check_space: buf %d, %s %d %d\n", bo_fake->id, bo_fake->name, bo->size, bufmgr_fake->current_total_size); + DBG("drm_check_space: sz %dkb vs bufgr %dkb\n", sz / 1024 , + bufmgr_fake->size / 1024); return 0; } diff --git a/libdrm/intel/intel_bufmgr_gem.c b/libdrm/intel/intel_bufmgr_gem.c index f5732226..48752f2f 100644 --- a/libdrm/intel/intel_bufmgr_gem.c +++ b/libdrm/intel/intel_bufmgr_gem.c @@ -873,7 +873,7 @@ intel_bufmgr_gem_enable_reuse(dri_bufmgr *bufmgr) * */ static int -dri_gem_check_aperture_space(dri_bo *bo) +dri_gem_check_aperture_space(dri_bo *bo_array, int count) { return 0; } -- cgit v1.2.3 From 9e9d9b1741965f6529153bc2bcbe2dd8ba96ef3f Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Fri, 8 Aug 2008 14:08:43 -0700 Subject: Fix compile warning from check_aperture change. --- libdrm/intel/intel_bufmgr_gem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdrm/intel/intel_bufmgr_gem.c b/libdrm/intel/intel_bufmgr_gem.c index 48752f2f..54c800aa 100644 --- a/libdrm/intel/intel_bufmgr_gem.c +++ b/libdrm/intel/intel_bufmgr_gem.c @@ -873,7 +873,7 @@ intel_bufmgr_gem_enable_reuse(dri_bufmgr *bufmgr) * */ static int -dri_gem_check_aperture_space(dri_bo *bo_array, int count) +dri_gem_check_aperture_space(dri_bo **bo_array, int count) { return 0; } -- cgit v1.2.3 From f7a99407153eaba5724b6f1f2cadab62c6a50a26 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Fri, 8 Aug 2008 15:55:34 -0700 Subject: Drop TTM interfaces from the userland library. --- libdrm/Makefile.am | 4 +- libdrm/intel/intel_bufmgr_fake.c | 1 + libdrm/libdrm_lists.h | 87 ++++++ libdrm/xf86drm.c | 573 --------------------------------------- libdrm/xf86drm.h | 2 - 5 files changed, 90 insertions(+), 577 deletions(-) create mode 100644 libdrm/libdrm_lists.h diff --git a/libdrm/Makefile.am b/libdrm/Makefile.am index 1187517a..b73cb673 100644 --- a/libdrm/Makefile.am +++ b/libdrm/Makefile.am @@ -26,10 +26,10 @@ libdrm_la_LDFLAGS = -version-number 2:3:0 -no-undefined AM_CFLAGS = -I$(top_srcdir)/shared-core libdrm_la_SOURCES = xf86drm.c xf86drmHash.c xf86drmRandom.c xf86drmSL.c \ - dri_bufmgr.c + dri_bufmgr.c libdrm_lists.h libdrm_la_LIBADD = intel/libdrm_intel.la libdrmincludedir = ${includedir} -libdrminclude_HEADERS = xf86drm.h xf86mm.h dri_bufmgr.h +libdrminclude_HEADERS = xf86drm.h dri_bufmgr.h EXTRA_DIST = ChangeLog TODO diff --git a/libdrm/intel/intel_bufmgr_fake.c b/libdrm/intel/intel_bufmgr_fake.c index 63dd9bef..e2dd9dc7 100644 --- a/libdrm/intel/intel_bufmgr_fake.c +++ b/libdrm/intel/intel_bufmgr_fake.c @@ -42,6 +42,7 @@ #include "drm.h" #include "i915_drm.h" #include "mm.h" +#include "libdrm_lists.h" #define ALIGN(value, alignment) ((value + alignment - 1) & ~(alignment - 1)) diff --git a/libdrm/libdrm_lists.h b/libdrm/libdrm_lists.h new file mode 100644 index 00000000..8e23991f --- /dev/null +++ b/libdrm/libdrm_lists.h @@ -0,0 +1,87 @@ +/************************************************************************** + * + * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND. USA. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ + +/* + * List macros heavily inspired by the Linux kernel + * list handling. No list looping yet. + */ + +typedef struct _drmMMListHead +{ + struct _drmMMListHead *prev; + struct _drmMMListHead *next; +} drmMMListHead; + +#define DRMINITLISTHEAD(__item) \ + do{ \ + (__item)->prev = (__item); \ + (__item)->next = (__item); \ + } while (0) + +#define DRMLISTADD(__item, __list) \ + do { \ + (__item)->prev = (__list); \ + (__item)->next = (__list)->next; \ + (__list)->next->prev = (__item); \ + (__list)->next = (__item); \ + } while (0) + +#define DRMLISTADDTAIL(__item, __list) \ + do { \ + (__item)->next = (__list); \ + (__item)->prev = (__list)->prev; \ + (__list)->prev->next = (__item); \ + (__list)->prev = (__item); \ + } while(0) + +#define DRMLISTDEL(__item) \ + do { \ + (__item)->prev->next = (__item)->next; \ + (__item)->next->prev = (__item)->prev; \ + } while(0) + +#define DRMLISTDELINIT(__item) \ + do { \ + (__item)->prev->next = (__item)->next; \ + (__item)->next->prev = (__item)->prev; \ + (__item)->next = (__item); \ + (__item)->prev = (__item); \ + } while(0) + +#define DRMLISTENTRY(__type, __item, __field) \ + ((__type *)(((char *) (__item)) - offsetof(__type, __field))) + +#define DRMLISTEMPTY(__item) ((__item)->next == (__item)) + +#define DRMLISTFOREACHSAFE(__item, __temp, __list) \ + for ((__item) = (__list)->next, (__temp) = (__item)->next; \ + (__item) != (__list); \ + (__item) = (__temp), (__temp) = (__item)->next) + +#define DRMLISTFOREACHSAFEREVERSE(__item, __temp, __list) \ + for ((__item) = (__list)->prev, (__temp) = (__item)->prev; \ + (__item) != (__list); \ + (__item) = (__temp), (__temp) = (__item)->prev) diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c index edb0c90b..150dd5f8 100644 --- a/libdrm/xf86drm.c +++ b/libdrm/xf86drm.c @@ -2349,579 +2349,6 @@ int drmCommandWriteRead(int fd, unsigned long drmCommandIndex, void *data, return 0; } - -/* - * Valid flags are - * DRM_FENCE_FLAG_EMIT - * DRM_FENCE_FLAG_SHAREABLE - * DRM_FENCE_MASK_DRIVER - */ - -int drmFenceCreate(int fd, unsigned flags, int fence_class, unsigned type, - drmFence *fence) -{ - drm_fence_arg_t arg; - - memset(&arg, 0, sizeof(arg)); - arg.flags = flags; - arg.type = type; - arg.fence_class = fence_class; - - if (drmIoctl(fd, DRM_IOCTL_FENCE_CREATE, &arg)) - return -errno; - fence->handle = arg.handle; - fence->fence_class = arg.fence_class; - fence->type = arg.type; - fence->flags = arg.flags; - fence->signaled = 0; - return 0; -} - -/* - * Valid flags are - * DRM_FENCE_FLAG_SHAREABLE - * DRM_FENCE_MASK_DRIVER - */ - -int drmFenceBuffers(int fd, unsigned flags, uint32_t fence_class, drmFence *fence) -{ - drm_fence_arg_t arg; - - memset(&arg, 0, sizeof(arg)); - arg.flags = flags; - arg.fence_class = fence_class; - - if (drmIoctl(fd, DRM_IOCTL_FENCE_BUFFERS, &arg)) - return -errno; - fence->handle = arg.handle; - fence->fence_class = arg.fence_class; - fence->type = arg.type; - fence->flags = arg.flags; - fence->sequence = arg.sequence; - fence->signaled = 0; - return 0; -} - -int drmFenceReference(int fd, unsigned handle, drmFence *fence) -{ - drm_fence_arg_t arg; - - memset(&arg, 0, sizeof(arg)); - arg.handle = handle; - - if (drmIoctl(fd, DRM_IOCTL_FENCE_REFERENCE, &arg)) - return -errno; - fence->handle = arg.handle; - fence->fence_class = arg.fence_class; - fence->type = arg.type; - fence->flags = arg.flags; - fence->signaled = arg.signaled; - return 0; -} - -int drmFenceUnreference(int fd, const drmFence *fence) -{ - drm_fence_arg_t arg; - - memset(&arg, 0, sizeof(arg)); - arg.handle = fence->handle; - - if (drmIoctl(fd, DRM_IOCTL_FENCE_UNREFERENCE, &arg)) - return -errno; - return 0; -} - -int drmFenceFlush(int fd, drmFence *fence, unsigned flush_type) -{ - drm_fence_arg_t arg; - - memset(&arg, 0, sizeof(arg)); - arg.handle = fence->handle; - arg.type = flush_type; - - if (drmIoctl(fd, DRM_IOCTL_FENCE_FLUSH, &arg)) - return -errno; - fence->fence_class = arg.fence_class; - fence->type = arg.type; - fence->signaled = arg.signaled; - return arg.error; -} - -int drmFenceUpdate(int fd, drmFence *fence) -{ - drm_fence_arg_t arg; - - memset(&arg, 0, sizeof(arg)); - arg.handle = fence->handle; - - if (drmIoctl(fd, DRM_IOCTL_FENCE_SIGNALED, &arg)) - return -errno; - fence->fence_class = arg.fence_class; - fence->type = arg.type; - fence->signaled = arg.signaled; - return 0; -} - -int drmFenceSignaled(int fd, drmFence *fence, unsigned fenceType, - int *signaled) -{ - if ((fence->flags & DRM_FENCE_FLAG_SHAREABLE) || - ((fenceType & fence->signaled) != fenceType)) { - int ret = drmFenceFlush(fd, fence, fenceType); - if (ret) - return ret; - } - - *signaled = ((fenceType & fence->signaled) == fenceType); - - return 0; -} - -/* - * Valid flags are - * DRM_FENCE_FLAG_SHAREABLE - * DRM_FENCE_MASK_DRIVER - */ - - -int drmFenceEmit(int fd, unsigned flags, drmFence *fence, unsigned emit_type) -{ - drm_fence_arg_t arg; - - memset(&arg, 0, sizeof(arg)); - arg.fence_class = fence->fence_class; - arg.flags = flags; - arg.handle = fence->handle; - arg.type = emit_type; - - if (drmIoctl(fd, DRM_IOCTL_FENCE_EMIT, &arg)) - return -errno; - fence->fence_class = arg.fence_class; - fence->type = arg.type; - fence->signaled = arg.signaled; - fence->sequence = arg.sequence; - return 0; -} - -/* - * Valid flags are - * DRM_FENCE_FLAG_WAIT_LAZY - * DRM_FENCE_FLAG_WAIT_IGNORE_SIGNALS - */ - -#define DRM_IOCTL_TIMEOUT_USEC 3000000UL - -static unsigned long -drmTimeDiff(struct timeval *now, struct timeval *then) -{ - uint64_t val; - - val = now->tv_sec - then->tv_sec; - val *= 1000000LL; - val += now->tv_usec; - val -= then->tv_usec; - - return (unsigned long) val; -} - -static int -drmIoctlTimeout(int fd, unsigned long request, void *argp) -{ - int haveThen = 0; - struct timeval then, now; - int ret; - - do { - ret = drmIoctl(fd, request, argp); - if (ret != 0 && errno == EAGAIN) { - if (!haveThen) { - gettimeofday(&then, NULL); - haveThen = 1; - } - gettimeofday(&now, NULL); - } - } while (ret != 0 && errno == EAGAIN && - drmTimeDiff(&now, &then) < DRM_IOCTL_TIMEOUT_USEC); - - if (ret != 0) - return ((errno == EAGAIN) ? -EBUSY : -errno); - - return 0; -} - - - - -int drmFenceWait(int fd, unsigned flags, drmFence *fence, unsigned flush_type) -{ - drm_fence_arg_t arg; - int ret; - - if (flush_type == 0) { - flush_type = fence->type; - } - - if (!(fence->flags & DRM_FENCE_FLAG_SHAREABLE)) { - if ((flush_type & fence->signaled) == flush_type) { - return 0; - } - } - - memset(&arg, 0, sizeof(arg)); - arg.handle = fence->handle; - arg.type = flush_type; - arg.flags = flags; - - - ret = drmIoctlTimeout(fd, DRM_IOCTL_FENCE_WAIT, &arg); - if (ret) - return ret; - - fence->fence_class = arg.fence_class; - fence->type = arg.type; - fence->signaled = arg.signaled; - return arg.error; -} - -static void drmBOCopyReply(const struct drm_bo_info_rep *rep, drmBO *buf) -{ - buf->handle = rep->handle; - buf->flags = rep->flags; - buf->size = rep->size; - buf->offset = rep->offset; - buf->mapHandle = rep->arg_handle; - buf->proposedFlags = rep->proposed_flags; - buf->start = rep->buffer_start; - buf->fenceFlags = rep->fence_flags; - buf->replyFlags = rep->rep_flags; - buf->pageAlignment = rep->page_alignment; - buf->tileInfo = rep->tile_info; - buf->hwTileStride = rep->hw_tile_stride; - buf->desiredTileStride = rep->desired_tile_stride; -} - - - -int drmBOCreate(int fd, unsigned long size, - unsigned pageAlignment, void *user_buffer, - uint64_t flags, - unsigned hint, drmBO *buf) -{ - struct drm_bo_create_arg arg; - struct drm_bo_create_req *req = &arg.d.req; - struct drm_bo_info_rep *rep = &arg.d.rep; - int ret; - - memset(buf, 0, sizeof(*buf)); - memset(&arg, 0, sizeof(arg)); - req->flags = flags; - req->hint = hint; - req->size = size; - req->page_alignment = pageAlignment; - req->buffer_start = (unsigned long) user_buffer; - - buf->virtual = NULL; - - ret = drmIoctlTimeout(fd, DRM_IOCTL_BO_CREATE, &arg); - if (ret) - return ret; - - drmBOCopyReply(rep, buf); - buf->virtual = user_buffer; - buf->mapCount = 0; - - return 0; -} - -int drmBOReference(int fd, unsigned handle, drmBO *buf) -{ - struct drm_bo_reference_info_arg arg; - struct drm_bo_handle_arg *req = &arg.d.req; - struct drm_bo_info_rep *rep = &arg.d.rep; - - memset(&arg, 0, sizeof(arg)); - req->handle = handle; - - if (drmIoctl(fd, DRM_IOCTL_BO_REFERENCE, &arg)) - return -errno; - - drmBOCopyReply(rep, buf); - buf->mapVirtual = NULL; - buf->mapCount = 0; - buf->virtual = NULL; - - return 0; -} - -int drmBOUnreference(int fd, drmBO *buf) -{ - struct drm_bo_handle_arg arg; - - if (buf->mapVirtual && buf->mapHandle) { - (void) munmap(buf->mapVirtual, buf->start + buf->size); - buf->mapVirtual = NULL; - buf->virtual = NULL; - } - - memset(&arg, 0, sizeof(arg)); - arg.handle = buf->handle; - - if (drmIoctl(fd, DRM_IOCTL_BO_UNREFERENCE, &arg)) - return -errno; - - buf->handle = 0; - return 0; -} - - -/* - * Flags can be DRM_BO_FLAG_READ, DRM_BO_FLAG_WRITE or'ed together - * Hint currently be DRM_BO_HINT_DONT_BLOCK, which makes the - * call return an -EBUSY if it can' immediately honor the mapping request. - */ - -int drmBOMap(int fd, drmBO *buf, unsigned mapFlags, unsigned mapHint, - void **address) -{ - struct drm_bo_map_wait_idle_arg arg; - struct drm_bo_info_req *req = &arg.d.req; - struct drm_bo_info_rep *rep = &arg.d.rep; - int ret = 0; - - /* - * Make sure we have a virtual address of the buffer. - */ - - if (!buf->virtual) { - drmAddress virtual; - virtual = mmap(0, buf->size + buf->start, - PROT_READ | PROT_WRITE, MAP_SHARED, - fd, buf->mapHandle); - if (virtual == MAP_FAILED) { - ret = -errno; - } - if (ret) - return ret; - buf->mapVirtual = virtual; - buf->virtual = ((char *) virtual) + buf->start; - } - - memset(&arg, 0, sizeof(arg)); - req->handle = buf->handle; - req->mask = mapFlags; - req->hint = mapHint; - - /* - * May hang if the buffer object is busy. - * This IOCTL synchronizes the buffer. - */ - - ret = drmIoctlTimeout(fd, DRM_IOCTL_BO_MAP, &arg); - if (ret) - return ret; - - drmBOCopyReply(rep, buf); - buf->mapFlags = mapFlags; - ++buf->mapCount; - *address = buf->virtual; - - return 0; -} - - -int drmBOUnmap(int fd, drmBO *buf) -{ - struct drm_bo_handle_arg arg; - - memset(&arg, 0, sizeof(arg)); - arg.handle = buf->handle; - - if (drmIoctl(fd, DRM_IOCTL_BO_UNMAP, &arg)) { - return -errno; - } - buf->mapCount--; - return 0; -} - -int drmBOSetStatus(int fd, drmBO *buf, - uint64_t flags, uint64_t mask, - unsigned int hint, - unsigned int desired_tile_stride, - unsigned int tile_info) -{ - - struct drm_bo_map_wait_idle_arg arg; - struct drm_bo_info_req *req = &arg.d.req; - struct drm_bo_info_rep *rep = &arg.d.rep; - int ret = 0; - - memset(&arg, 0, sizeof(arg)); - req->mask = mask; - req->flags = flags; - req->handle = buf->handle; - req->hint = hint; - req->desired_tile_stride = desired_tile_stride; - req->tile_info = tile_info; - - ret = drmIoctlTimeout(fd, DRM_IOCTL_BO_SETSTATUS, &arg); - if (ret) - return ret; - - drmBOCopyReply(rep, buf); - return 0; -} - - -int drmBOInfo(int fd, drmBO *buf) -{ - struct drm_bo_reference_info_arg arg; - struct drm_bo_handle_arg *req = &arg.d.req; - struct drm_bo_info_rep *rep = &arg.d.rep; - int ret = 0; - - memset(&arg, 0, sizeof(arg)); - req->handle = buf->handle; - - ret = drmIoctl(fd, DRM_IOCTL_BO_INFO, &arg); - if (ret) - return -errno; - - drmBOCopyReply(rep, buf); - return 0; -} - -int drmBOWaitIdle(int fd, drmBO *buf, unsigned hint) -{ - struct drm_bo_map_wait_idle_arg arg; - struct drm_bo_info_req *req = &arg.d.req; - struct drm_bo_info_rep *rep = &arg.d.rep; - int ret = 0; - - if ((buf->flags & DRM_BO_FLAG_SHAREABLE) || - (buf->replyFlags & DRM_BO_REP_BUSY)) { - memset(&arg, 0, sizeof(arg)); - req->handle = buf->handle; - req->hint = hint; - - ret = drmIoctlTimeout(fd, DRM_IOCTL_BO_WAIT_IDLE, &arg); - if (ret) - return ret; - - drmBOCopyReply(rep, buf); - } - return 0; -} - -int drmBOBusy(int fd, drmBO *buf, int *busy) -{ - int ret = drmBOInfo(fd, buf); - - if (ret) - return ret; - - *busy = (buf->replyFlags & DRM_BO_REP_BUSY); - return 0; -} - -int drmMMInit(int fd, unsigned long pOffset, unsigned long pSize, - unsigned memType) -{ - struct drm_mm_init_arg arg; - - memset(&arg, 0, sizeof(arg)); - - arg.magic = DRM_BO_INIT_MAGIC; - arg.major = DRM_BO_INIT_MAJOR; - arg.minor = DRM_BO_INIT_MINOR; - arg.p_offset = pOffset; - arg.p_size = pSize; - arg.mem_type = memType; - - if (drmIoctl(fd, DRM_IOCTL_MM_INIT, &arg)) - return -errno; - return 0; -} - -int drmMMTakedown(int fd, unsigned memType) -{ - struct drm_mm_type_arg arg; - - memset(&arg, 0, sizeof(arg)); - arg.mem_type = memType; - - if (drmIoctl(fd, DRM_IOCTL_MM_TAKEDOWN, &arg)) - return -errno; - return 0; -} - -/* - * If this function returns an error, and lockBM was set to 1, - * the buffer manager is NOT locked. - */ - -int drmMMLock(int fd, unsigned memType, int lockBM, int ignoreNoEvict) -{ - struct drm_mm_type_arg arg; - - memset(&arg, 0, sizeof(arg)); - arg.mem_type = memType; - arg.lock_flags |= (lockBM) ? DRM_BO_LOCK_UNLOCK_BM : 0; - arg.lock_flags |= (ignoreNoEvict) ? DRM_BO_LOCK_IGNORE_NO_EVICT : 0; - - return drmIoctlTimeout(fd, DRM_IOCTL_MM_LOCK, &arg); -} - -int drmMMUnlock(int fd, unsigned memType, int unlockBM) -{ - struct drm_mm_type_arg arg; - - memset(&arg, 0, sizeof(arg)); - - arg.mem_type = memType; - arg.lock_flags |= (unlockBM) ? DRM_BO_LOCK_UNLOCK_BM : 0; - - return drmIoctlTimeout(fd, DRM_IOCTL_MM_UNLOCK, &arg); -} - -int drmMMInfo(int fd, unsigned memType, uint64_t *size) -{ - struct drm_mm_info_arg arg; - - memset(&arg, 0, sizeof(arg)); - - arg.mem_type = memType; - - if (drmIoctl(fd, DRM_IOCTL_MM_INFO, &arg)) - return -errno; - - *size = arg.p_size; - return 0; -} - -int drmBOVersion(int fd, unsigned int *major, - unsigned int *minor, - unsigned int *patchlevel) -{ - struct drm_bo_version_arg arg; - int ret; - - memset(&arg, 0, sizeof(arg)); - ret = drmIoctl(fd, DRM_IOCTL_BO_VERSION, &arg); - if (ret) - return -errno; - - if (major) - *major = arg.major; - if (minor) - *minor = arg.minor; - if (patchlevel) - *patchlevel = arg.patchlevel; - - return 0; -} - - - #define DRM_MAX_FDS 16 static struct { char *BusID; diff --git a/libdrm/xf86drm.h b/libdrm/xf86drm.h index 6ced284a..f4fa71b0 100644 --- a/libdrm/xf86drm.h +++ b/libdrm/xf86drm.h @@ -659,6 +659,4 @@ extern int drmOpenOnce(void *unused, const char *BusID, int *newlyopened); extern void drmCloseOnce(int fd); extern void drmMsg(const char *format, ...); -#include "xf86mm.h" - #endif -- cgit v1.2.3 From 12e6a114cf9ebd0e1d8ccdbf9a7aef7c67e24b58 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Sat, 9 Aug 2008 17:19:16 +1000 Subject: drm: TRUE/true --- linux-core/drm_agpsupport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-core/drm_agpsupport.c b/linux-core/drm_agpsupport.c index 6ccb4b6d..3cc94ff7 100644 --- a/linux-core/drm_agpsupport.c +++ b/linux-core/drm_agpsupport.c @@ -517,7 +517,7 @@ drm_agp_bind_pages(struct drm_device *dev, mem->memory[i] = phys_to_gart(page_to_phys(pages[i])); mem->page_count = num_pages; - mem->is_flushed = TRUE; + mem->is_flushed = true; ret = drm_agp_bind_memory(mem, gtt_offset / PAGE_SIZE); if (ret != 0) { DRM_ERROR("Failed to bind AGP memory: %d\n", ret); -- cgit v1.2.3 From 280d415957c0af099c44aaecb69a06c68c86aebb Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 11 Aug 2008 10:47:00 +1000 Subject: drm: add OS_HAS_GEM option. To build i915 driver pass OS_HAS_GEM=1 to make for now --- linux-core/Makefile | 6 ++++++ linux-core/drm_compat.h | 8 ++++++++ linux-core/drm_drv.c | 2 ++ linux-core/drm_gem.c | 26 +++++++++++++++++++++++++- 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/linux-core/Makefile b/linux-core/Makefile index 55dfb77c..4edec312 100644 --- a/linux-core/Makefile +++ b/linux-core/Makefile @@ -270,6 +270,10 @@ ifneq ($(PAGE_AGP),0) EXTRA_CFLAGS += -DHAVE_PAGE_AGP endif +ifeq ($(OS_HAS_GEM), 1) +EXTRA_CFLAGS += -DOS_HAS_GEM=1 +endif + # Start with all modules turned off. CONFIG_DRM_GAMMA := n CONFIG_DRM_TDFX := n @@ -332,8 +336,10 @@ ifneq (,$(findstring i810,$(DRM_MODULES))) CONFIG_DRM_I810 := m endif ifneq (,$(findstring i915,$(DRM_MODULES))) +ifeq ($(OS_HAS_GEM), 1) CONFIG_DRM_I915 := m endif +endif GIT_REVISION := $(shell cd "$(DRMSRCDIR)" && git-describe --abbrev=17) ifneq ($(GIT_REVISION),) diff --git a/linux-core/drm_compat.h b/linux-core/drm_compat.h index 7ddc2c97..c7f72e33 100644 --- a/linux-core/drm_compat.h +++ b/linux-core/drm_compat.h @@ -369,4 +369,12 @@ extern struct page *drm_vm_sg_nopage(struct vm_area_struct *vma, #define drm_core_ioremap_wc drm_core_ioremap #endif +#ifndef OS_HAS_GEM +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)) +#define OS_HAS_GEM 1 +#else +#define OS_HAS_GEM 0 +#endif +#endif + #endif diff --git a/linux-core/drm_drv.c b/linux-core/drm_drv.c index efd6416f..31a98fe8 100644 --- a/linux-core/drm_drv.c +++ b/linux-core/drm_drv.c @@ -151,9 +151,11 @@ static struct drm_ioctl_desc drm_ioctls[] = { DRM_IOCTL_DEF(DRM_IOCTL_MM_INFO, drm_mm_info_ioctl, 0), +#if OS_HAS_GEM DRM_IOCTL_DEF(DRM_IOCTL_GEM_CLOSE, drm_gem_close_ioctl, 0), DRM_IOCTL_DEF(DRM_IOCTL_GEM_FLINK, drm_gem_flink_ioctl, DRM_AUTH), DRM_IOCTL_DEF(DRM_IOCTL_GEM_OPEN, drm_gem_open_ioctl, DRM_AUTH), +#endif }; #define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls ) diff --git a/linux-core/drm_gem.c b/linux-core/drm_gem.c index 434155b3..ce930265 100644 --- a/linux-core/drm_gem.c +++ b/linux-core/drm_gem.c @@ -25,6 +25,12 @@ * */ +#include + +#include "drmP.h" + +#if OS_HAS_GEM + #include #include #include @@ -34,7 +40,6 @@ #include #include #include -#include "drmP.h" /** @file drm_gem.c * @@ -418,3 +423,22 @@ drm_gem_object_handle_free(struct kref *kref) } EXPORT_SYMBOL(drm_gem_object_handle_free); +#else + +int drm_gem_init(struct drm_device *dev) +{ + return 0; +} + +void drm_gem_open(struct drm_device *dev, struct drm_file *file_private) +{ + +} + +void +drm_gem_release(struct drm_device *dev, struct drm_file *file_private) +{ + +} + +#endif -- cgit v1.2.3 From 08faab27e5fbf12e53dc9d4bf38eda8da1a55007 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 11 Aug 2008 10:58:41 +1000 Subject: drm_vm: fix for build on 2.6.22 thanks to malc0 for pointing it out --- linux-core/drm_vm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-core/drm_vm.c b/linux-core/drm_vm.c index 0d5242d3..d4d97a4d 100644 --- a/linux-core/drm_vm.c +++ b/linux-core/drm_vm.c @@ -698,7 +698,7 @@ EXPORT_SYMBOL(drm_mmap); * protected by the bo->mutex lock. */ -#ifdef DRM_FULL_MM_COMPAT +#if defined(DRM_FULL_MM_COMPAT) && !defined(DRM_NO_FAULT) static int drm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf) { -- cgit v1.2.3 From 966c783e96b3f8ae0271db3dd6862177c659ab13 Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Mon, 11 Aug 2008 10:44:39 -0700 Subject: libdrm: Allow build outside of source tree. --- libdrm/intel/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/libdrm/intel/Makefile.am b/libdrm/intel/Makefile.am index 111204b1..31a8512a 100644 --- a/libdrm/intel/Makefile.am +++ b/libdrm/intel/Makefile.am @@ -24,6 +24,7 @@ AM_CFLAGS = \ $(WARN_CFLAGS) \ + -I$(top_srcdir)/libdrm \ -I$(top_srcdir)/shared-core noinst_LTLIBRARIES = libdrm_intel.la -- cgit v1.2.3 From b0e68829462aad00ce68be998da6313bca754e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Tue, 12 Aug 2008 22:22:15 -0400 Subject: [intel_bufmgr_gem] Fix flink buffer name caching (#17085, #17092). Store the global name in global_name, don't overwrite the gem_handle. --- libdrm/intel/intel_bufmgr_gem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libdrm/intel/intel_bufmgr_gem.c b/libdrm/intel/intel_bufmgr_gem.c index 54c800aa..48a47701 100644 --- a/libdrm/intel/intel_bufmgr_gem.c +++ b/libdrm/intel/intel_bufmgr_gem.c @@ -844,10 +844,10 @@ dri_gem_flink(dri_bo *bo, uint32_t *name) ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_GEM_FLINK, &flink); if (ret != 0) return -errno; - bo_gem->gem_handle = flink.name; + bo_gem->global_name = flink.name; } - *name = bo_gem->gem_handle; + *name = bo_gem->global_name; return 0; } -- cgit v1.2.3