return size;
/* 965+ just need multiples of page size for tiling */
- if (IS_I965G(bufmgr_gem))
+ if (!IS_GEN2(bufmgr_gem) && !IS_GEN3(bufmgr_gem))
return ROUND_UP_TO(size, 4096);
/* Older chips need powers of two, of at least 512k or 1M */
- if (IS_I9XX(bufmgr_gem)) {
+ if (!IS_GEN2(bufmgr_gem)) {
min_size = 1024*1024;
max_size = 128*1024*1024;
} else {
return ROUND_UP_TO(pitch, tile_width);
/* 965 is flexible */
- if (IS_I965G(bufmgr_gem))
+ if (!IS_GEN2(bufmgr_gem) && !IS_GEN3(bufmgr_gem))
return ROUND_UP_TO(pitch, tile_width);
/* Pre-965 needs power of two tile width */
* aperture. Optimal packing is for wimps.
*/
size = bo_gem->bo.size;
- if (!IS_I965G(bufmgr_gem) && bo_gem->tiling_mode != I915_TILING_NONE)
+ if ((IS_GEN2(bufmgr_gem) || IS_GEN3(bufmgr_gem))
+ && bo_gem->tiling_mode != I915_TILING_NONE)
size *= 2;
bo_gem->reloc_tree_size = size;
MAP_SHARED, bufmgr_gem->fd,
mmap_arg.offset);
if (bo_gem->gtt_virtual == MAP_FAILED) {
+ bo_gem->gtt_virtual = NULL;
ret = -errno;
fprintf(stderr,
"%s:%d: Error mapping buffer %d (%s): %s .\n",
drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo;
drm_intel_bo_gem *target_bo_gem = (drm_intel_bo_gem *) target_bo;
- pthread_mutex_lock(&bufmgr_gem->lock);
- if (bo_gem->has_error) {
- pthread_mutex_unlock(&bufmgr_gem->lock);
+ if (bo_gem->has_error)
return -ENOMEM;
- }
if (target_bo_gem->has_error) {
bo_gem->has_error = 1;
- pthread_mutex_unlock(&bufmgr_gem->lock);
return -ENOMEM;
}
/* Create a new relocation list if needed */
- if (bo_gem->relocs == NULL && drm_intel_setup_reloc_list(bo)) {
- pthread_mutex_unlock(&bufmgr_gem->lock);
+ if (bo_gem->relocs == NULL && drm_intel_setup_reloc_list(bo))
return -ENOMEM;
- }
/* Check overflow */
assert(bo_gem->reloc_count < bufmgr_gem->max_relocs);
bo_gem->reloc_count++;
- pthread_mutex_unlock(&bufmgr_gem->lock);
-
return 0;
}
memset(&set_tiling, 0, sizeof(set_tiling));
set_tiling.handle = bo_gem->gem_handle;
- set_tiling.tiling_mode = *tiling_mode;
- set_tiling.stride = stride;
do {
+ set_tiling.tiling_mode = *tiling_mode;
+ set_tiling.stride = stride;
+
ret = ioctl(bufmgr_gem->fd,
DRM_IOCTL_I915_GEM_SET_TILING,
&set_tiling);
} while (ret == -1 && errno == EINTR);
- if (ret != 0) {
- *tiling_mode = bo_gem->tiling_mode;
- return -errno;
- }
bo_gem->tiling_mode = set_tiling.tiling_mode;
bo_gem->swizzle_mode = set_tiling.swizzle_mode;
drm_intel_bo_gem_set_in_aperture_size(bufmgr_gem, bo_gem);
*tiling_mode = bo_gem->tiling_mode;
- return 0;
+ return ret == 0 ? 0 : -errno;
}
static int
unsigned long size;
bufmgr_gem = calloc(1, sizeof(*bufmgr_gem));
+ if (bufmgr_gem == NULL)
+ return NULL;
+
bufmgr_gem->fd = fd;
if (pthread_mutex_init(&bufmgr_gem->lock, NULL) != 0) {
fprintf(stderr, "param: %d, val: %d\n", gp.param, *gp.value);
}
- if (!IS_I965G(bufmgr_gem)) {
+ if (IS_GEN2(bufmgr_gem) || IS_GEN3(bufmgr_gem)) {
gp.param = I915_PARAM_NUM_FENCES_AVAIL;
gp.value = &bufmgr_gem->available_fences;
ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GETPARAM, &gp);
fprintf(stderr, "param: %d, val: %d\n", gp.param,
*gp.value);
bufmgr_gem->available_fences = 0;
+ } else {
+ /* XXX The kernel reports the total number of fences,
+ * including any that may be pinned.
+ *
+ * We presume that there will be at least one pinned
+ * fence for the scanout buffer, but there may be more
+ * than one scanout and the user may be manually
+ * pinning buffers. Let's move to execbuffer2 and
+ * thereby forget the insanity of using fences...
+ */
+ bufmgr_gem->available_fences -= 2;
+ if (bufmgr_gem->available_fences < 0)
+ bufmgr_gem->available_fences = 0;
}
}