diff options
Diffstat (limited to 'lib/libdrm')
34 files changed, 738 insertions, 721 deletions
diff --git a/lib/libdrm/Makefile.inc b/lib/libdrm/Makefile.inc index beac84aea..934da1511 100644 --- a/lib/libdrm/Makefile.inc +++ b/lib/libdrm/Makefile.inc @@ -1,6 +1,6 @@ -# $OpenBSD: Makefile.inc,v 1.15 2015/03/26 06:00:06 jsg Exp $ +# $OpenBSD: Makefile.inc,v 1.16 2015/07/15 23:19:17 jsg Exp $ -PACKAGE_VERSION= 2.4.60 +PACKAGE_VERSION= 2.4.62 NOPROFILE= diff --git a/lib/libdrm/intel/intel_bufmgr.c b/lib/libdrm/intel/intel_bufmgr.c index 234cd13e1..14ea9f9fa 100644 --- a/lib/libdrm/intel/intel_bufmgr.c +++ b/lib/libdrm/intel/intel_bufmgr.c @@ -37,7 +37,7 @@ #include <drm.h> #include <i915_drm.h> #include <pciaccess.h> -#include "libdrm.h" +#include "libdrm_macros.h" #include "intel_bufmgr.h" #include "intel_bufmgr_priv.h" #include "xf86drm.h" @@ -47,21 +47,21 @@ * Convenience functions for buffer management methods. */ -drm_public drm_intel_bo * +drm_intel_bo * drm_intel_bo_alloc(drm_intel_bufmgr *bufmgr, const char *name, unsigned long size, unsigned int alignment) { return bufmgr->bo_alloc(bufmgr, name, size, alignment); } -drm_public drm_intel_bo * +drm_intel_bo * drm_intel_bo_alloc_for_render(drm_intel_bufmgr *bufmgr, const char *name, unsigned long size, unsigned int alignment) { return bufmgr->bo_alloc_for_render(bufmgr, name, size, alignment); } -drm_public drm_intel_bo * +drm_intel_bo * drm_intel_bo_alloc_userptr(drm_intel_bufmgr *bufmgr, const char *name, void *addr, uint32_t tiling_mode, @@ -75,7 +75,7 @@ drm_intel_bo_alloc_userptr(drm_intel_bufmgr *bufmgr, return NULL; } -drm_public drm_intel_bo * +drm_intel_bo * drm_intel_bo_alloc_tiled(drm_intel_bufmgr *bufmgr, const char *name, int x, int y, int cpp, uint32_t *tiling_mode, unsigned long *pitch, unsigned long flags) @@ -84,13 +84,13 @@ drm_intel_bo_alloc_tiled(drm_intel_bufmgr *bufmgr, const char *name, tiling_mode, pitch, flags); } -drm_public void +void drm_intel_bo_reference(drm_intel_bo *bo) { bo->bufmgr->bo_reference(bo); } -drm_public void +void drm_intel_bo_unreference(drm_intel_bo *bo) { if (bo == NULL) @@ -99,26 +99,26 @@ drm_intel_bo_unreference(drm_intel_bo *bo) bo->bufmgr->bo_unreference(bo); } -drm_public int +int drm_intel_bo_map(drm_intel_bo *buf, int write_enable) { return buf->bufmgr->bo_map(buf, write_enable); } -drm_public int +int drm_intel_bo_unmap(drm_intel_bo *buf) { return buf->bufmgr->bo_unmap(buf); } -drm_public int +int drm_intel_bo_subdata(drm_intel_bo *bo, unsigned long offset, unsigned long size, const void *data) { return bo->bufmgr->bo_subdata(bo, offset, size, data); } -drm_public int +int drm_intel_bo_get_subdata(drm_intel_bo *bo, unsigned long offset, unsigned long size, void *data) { @@ -137,26 +137,26 @@ drm_intel_bo_get_subdata(drm_intel_bo *bo, unsigned long offset, return 0; } -drm_public void +void drm_intel_bo_wait_rendering(drm_intel_bo *bo) { bo->bufmgr->bo_wait_rendering(bo); } -drm_public void +void drm_intel_bufmgr_destroy(drm_intel_bufmgr *bufmgr) { bufmgr->destroy(bufmgr); } -drm_public int +int drm_intel_bo_exec(drm_intel_bo *bo, int used, drm_clip_rect_t * cliprects, int num_cliprects, int DR4) { return bo->bufmgr->bo_exec(bo, used, cliprects, num_cliprects, DR4); } -drm_public int +int drm_intel_bo_mrb_exec(drm_intel_bo *bo, int used, drm_clip_rect_t *cliprects, int num_cliprects, int DR4, unsigned int rings) @@ -176,19 +176,19 @@ drm_intel_bo_mrb_exec(drm_intel_bo *bo, int used, } } -drm_public void +void drm_intel_bufmgr_set_debug(drm_intel_bufmgr *bufmgr, int enable_debug) { bufmgr->debug = enable_debug; } -drm_public int +int drm_intel_bufmgr_check_aperture_space(drm_intel_bo ** bo_array, int count) { return bo_array[0]->bufmgr->check_aperture_space(bo_array, count); } -drm_public int +int drm_intel_bo_flink(drm_intel_bo *bo, uint32_t * name) { if (bo->bufmgr->bo_flink) @@ -197,7 +197,7 @@ drm_intel_bo_flink(drm_intel_bo *bo, uint32_t * name) return -ENODEV; } -drm_public int +int drm_intel_bo_emit_reloc(drm_intel_bo *bo, uint32_t offset, drm_intel_bo *target_bo, uint32_t target_offset, uint32_t read_domains, uint32_t write_domain) @@ -208,7 +208,7 @@ drm_intel_bo_emit_reloc(drm_intel_bo *bo, uint32_t offset, } /* For fence registers, not GL fences */ -drm_public int +int drm_intel_bo_emit_reloc_fence(drm_intel_bo *bo, uint32_t offset, drm_intel_bo *target_bo, uint32_t target_offset, uint32_t read_domains, uint32_t write_domain) @@ -219,7 +219,7 @@ drm_intel_bo_emit_reloc_fence(drm_intel_bo *bo, uint32_t offset, } -drm_public int +int drm_intel_bo_pin(drm_intel_bo *bo, uint32_t alignment) { if (bo->bufmgr->bo_pin) @@ -228,7 +228,7 @@ drm_intel_bo_pin(drm_intel_bo *bo, uint32_t alignment) return -ENODEV; } -drm_public int +int drm_intel_bo_unpin(drm_intel_bo *bo) { if (bo->bufmgr->bo_unpin) @@ -237,7 +237,7 @@ drm_intel_bo_unpin(drm_intel_bo *bo) return -ENODEV; } -drm_public int +int drm_intel_bo_set_tiling(drm_intel_bo *bo, uint32_t * tiling_mode, uint32_t stride) { @@ -248,7 +248,7 @@ drm_intel_bo_set_tiling(drm_intel_bo *bo, uint32_t * tiling_mode, return 0; } -drm_public int +int drm_intel_bo_get_tiling(drm_intel_bo *bo, uint32_t * tiling_mode, uint32_t * swizzle_mode) { @@ -260,7 +260,7 @@ drm_intel_bo_get_tiling(drm_intel_bo *bo, uint32_t * tiling_mode, return 0; } -drm_public int +int drm_intel_bo_disable_reuse(drm_intel_bo *bo) { if (bo->bufmgr->bo_disable_reuse) @@ -268,7 +268,7 @@ drm_intel_bo_disable_reuse(drm_intel_bo *bo) return 0; } -drm_public int +int drm_intel_bo_is_reusable(drm_intel_bo *bo) { if (bo->bufmgr->bo_is_reusable) @@ -276,7 +276,7 @@ drm_intel_bo_is_reusable(drm_intel_bo *bo) return 0; } -drm_public int +int drm_intel_bo_busy(drm_intel_bo *bo) { if (bo->bufmgr->bo_busy) @@ -284,7 +284,7 @@ drm_intel_bo_busy(drm_intel_bo *bo) return 0; } -drm_public int +int drm_intel_bo_madvise(drm_intel_bo *bo, int madv) { if (bo->bufmgr->bo_madvise) @@ -292,13 +292,13 @@ drm_intel_bo_madvise(drm_intel_bo *bo, int madv) return -1; } -drm_public int +int drm_intel_bo_references(drm_intel_bo *bo, drm_intel_bo *target_bo) { return bo->bufmgr->bo_references(bo, target_bo); } -drm_public int +int drm_intel_get_pipe_from_crtc_id(drm_intel_bufmgr *bufmgr, int crtc_id) { if (bufmgr->get_pipe_from_crtc_id) @@ -332,7 +332,7 @@ err: return size; } -drm_public int +int drm_intel_get_aperture_sizes(int fd, size_t *mappable, size_t *total) { diff --git a/lib/libdrm/intel/intel_bufmgr_fake.c b/lib/libdrm/intel/intel_bufmgr_fake.c index c4828faa2..75387b7cf 100644 --- a/lib/libdrm/intel/intel_bufmgr_fake.c +++ b/lib/libdrm/intel/intel_bufmgr_fake.c @@ -49,14 +49,9 @@ #include "drm.h" #include "i915_drm.h" #include "mm.h" -#include "libdrm.h" +#include "libdrm_macros.h" #include "libdrm_lists.h" -/* Support gcc's __FUNCTION__ for people using other compilers */ -#if !defined(__GNUC__) && !defined(__FUNCTION__) -# define __FUNCTION__ __func__ /* C99 */ -#endif - #define DBG(...) do { \ if (bufmgr_fake->bufmgr.debug) \ drmMsg(__VA_ARGS__); \ @@ -249,7 +244,7 @@ FENCE_LTE(unsigned a, unsigned b) return 0; } -drm_public void +void drm_intel_bufmgr_fake_set_fence_callback(drm_intel_bufmgr *bufmgr, unsigned int (*emit) (void *priv), void (*wait) (unsigned int fence, @@ -278,7 +273,7 @@ _fence_emit_internal(drm_intel_bufmgr_fake *bufmgr_fake) ret = drmCommandWriteRead(bufmgr_fake->fd, DRM_I915_IRQ_EMIT, &ie, sizeof(ie)); if (ret) { - drmMsg("%s: drm_i915_irq_emit: %d\n", __FUNCTION__, ret); + drmMsg("%s: drm_i915_irq_emit: %d\n", __func__, ret); abort(); } @@ -545,7 +540,7 @@ evict_lru(drm_intel_bufmgr_fake *bufmgr_fake, unsigned int max_fence) { struct block *block, *tmp; - DBG("%s\n", __FUNCTION__); + DBG("%s\n", __func__); DRMLISTFOREACHSAFE(block, tmp, &bufmgr_fake->lru) { drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) block->bo; @@ -572,7 +567,7 @@ evict_mru(drm_intel_bufmgr_fake *bufmgr_fake) { struct block *block, *tmp; - DBG("%s\n", __FUNCTION__); + DBG("%s\n", __func__); DRMLISTFOREACHSAFEREVERSE(block, tmp, &bufmgr_fake->lru) { drm_intel_bo_fake *bo_fake = (drm_intel_bo_fake *) block->bo; @@ -632,7 +627,7 @@ clear_fenced(drm_intel_bufmgr_fake *bufmgr_fake, unsigned int fence_cookie) } } - DBG("%s: %d\n", __FUNCTION__, ret); + DBG("%s: %d\n", __func__, ret); return ret; } @@ -717,7 +712,7 @@ evict_and_alloc_block(drm_intel_bo *bo) if (alloc_block(bo)) return 1; - DBG("%s 0x%lx bytes failed\n", __FUNCTION__, bo->size); + DBG("%s 0x%lx bytes failed\n", __func__, bo->size); return 0; } @@ -772,7 +767,7 @@ drm_intel_fake_bo_wait_rendering(drm_intel_bo *bo) * -- just evict everything * -- and wait for idle */ -drm_public void +void drm_intel_bufmgr_fake_contended_lock_take(drm_intel_bufmgr *bufmgr) { drm_intel_bufmgr_fake *bufmgr_fake = (drm_intel_bufmgr_fake *) bufmgr; @@ -868,7 +863,7 @@ drm_intel_fake_bo_alloc_tiled(drm_intel_bufmgr * bufmgr, 4096); } -drm_public drm_intel_bo * +drm_intel_bo * drm_intel_bo_fake_alloc_static(drm_intel_bufmgr *bufmgr, const char *name, unsigned long offset, @@ -963,7 +958,7 @@ drm_intel_fake_bo_unreference(drm_intel_bo *bo) * Set the buffer as not requiring backing store, and instead get the callback * invoked whenever it would be set dirty. */ -drm_public void +void drm_intel_bo_fake_disable_backing_store(drm_intel_bo *bo, void (*invalidate_cb) (drm_intel_bo *bo, void *ptr), @@ -1027,12 +1022,12 @@ static int bo_fake->name, bo_fake->bo.size / 1024); if (bo->virtual != NULL) { - drmMsg("%s: already mapped\n", __FUNCTION__); + drmMsg("%s: already mapped\n", __func__); abort(); } else if (bo_fake->flags & (BM_NO_BACKING_STORE | BM_PINNED)) { if (!bo_fake->block && !evict_and_alloc_block(bo)) { - DBG("%s: alloc failed\n", __FUNCTION__); + DBG("%s: alloc failed\n", __func__); bufmgr_fake->fail = 1; return 1; } else { @@ -1417,7 +1412,7 @@ drm_intel_bo_fake_post_submit(drm_intel_bo *bo) bo_fake->write_domain = 0; } -drm_public void +void drm_intel_bufmgr_fake_set_exec_callback(drm_intel_bufmgr *bufmgr, int (*exec) (drm_intel_bo *bo, unsigned int used, @@ -1540,7 +1535,7 @@ drm_intel_fake_check_aperture_space(drm_intel_bo ** bo_array, int count) * Used by the X Server on LeaveVT, when the card memory is no longer our * own. */ -drm_public void +void drm_intel_bufmgr_fake_evict_all(drm_intel_bufmgr *bufmgr) { drm_intel_bufmgr_fake *bufmgr_fake = (drm_intel_bufmgr_fake *) bufmgr; @@ -1575,7 +1570,7 @@ drm_intel_bufmgr_fake_evict_all(drm_intel_bufmgr *bufmgr) pthread_mutex_unlock(&bufmgr_fake->lock); } -drm_public void +void drm_intel_bufmgr_fake_set_last_dispatch(drm_intel_bufmgr *bufmgr, volatile unsigned int *last_dispatch) @@ -1585,7 +1580,7 @@ drm_intel_bufmgr_fake_set_last_dispatch(drm_intel_bufmgr *bufmgr, bufmgr_fake->last_dispatch = (volatile int *)last_dispatch; } -drm_public drm_intel_bufmgr * +drm_intel_bufmgr * drm_intel_bufmgr_fake_init(int fd, unsigned long low_offset, void *low_virtual, unsigned long size, volatile unsigned int *last_dispatch) diff --git a/lib/libdrm/intel/intel_bufmgr_gem.c b/lib/libdrm/intel/intel_bufmgr_gem.c index 09263044f..ac6186760 100644 --- a/lib/libdrm/intel/intel_bufmgr_gem.c +++ b/lib/libdrm/intel/intel_bufmgr_gem.c @@ -56,7 +56,7 @@ #ifndef ETIME #define ETIME ETIMEDOUT #endif -#include "libdrm.h" +#include "libdrm_macros.h" #include "libdrm_lists.h" #include "intel_bufmgr.h" #include "intel_bufmgr_priv.h" @@ -134,6 +134,11 @@ typedef struct _drm_intel_bufmgr_gem { unsigned int has_vebox : 1; bool fenced_relocs; + struct { + void *ptr; + uint32_t handle; + } userptr_active; + char *aub_filename; FILE *aub_file; uint32_t aub_offset; @@ -940,13 +945,77 @@ drm_intel_gem_bo_alloc_userptr(drm_intel_bufmgr *bufmgr, return &bo_gem->bo; } +static bool +has_userptr(drm_intel_bufmgr_gem *bufmgr_gem) +{ + int ret; + void *ptr; + long pgsz; + struct drm_i915_gem_userptr userptr; + + pgsz = sysconf(_SC_PAGESIZE); + assert(pgsz > 0); + + ret = posix_memalign(&ptr, pgsz, pgsz); + if (ret) { + DBG("Failed to get a page (%ld) for userptr detection!\n", + pgsz); + return false; + } + + memclear(userptr); + userptr.user_ptr = (uint64_t)(unsigned long)ptr; + userptr.user_size = pgsz; + +retry: + ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_USERPTR, &userptr); + if (ret) { + if (errno == ENODEV && userptr.flags == 0) { + userptr.flags = I915_USERPTR_UNSYNCHRONIZED; + goto retry; + } + free(ptr); + return false; + } + + /* We don't release the userptr bo here as we want to keep the + * kernel mm tracking alive for our lifetime. The first time we + * create a userptr object the kernel has to install a mmu_notifer + * which is a heavyweight operation (e.g. it requires taking all + * mm_locks and stop_machine()). + */ + + bufmgr_gem->userptr_active.ptr = ptr; + bufmgr_gem->userptr_active.handle = userptr.handle; + + return true; +} + +static drm_intel_bo * +check_bo_alloc_userptr(drm_intel_bufmgr *bufmgr, + const char *name, + void *addr, + uint32_t tiling_mode, + uint32_t stride, + unsigned long size, + unsigned long flags) +{ + if (has_userptr((drm_intel_bufmgr_gem *)bufmgr)) + bufmgr->bo_alloc_userptr = drm_intel_gem_bo_alloc_userptr; + else + bufmgr->bo_alloc_userptr = NULL; + + return drm_intel_bo_alloc_userptr(bufmgr, name, addr, + tiling_mode, stride, size, flags); +} + /** * Returns a drm_intel_bo wrapping the given buffer object handle. * * This can be used when one application needs to pass a buffer object * to another. */ -drm_public drm_intel_bo * +drm_intel_bo * drm_intel_bo_gem_create_from_name(drm_intel_bufmgr *bufmgr, const char *name, unsigned int handle) @@ -1408,7 +1477,7 @@ map_gtt(drm_intel_bo *bo) return 0; } -drm_public int +int drm_intel_gem_bo_map_gtt(drm_intel_bo *bo) { drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr; @@ -1467,7 +1536,7 @@ drm_intel_gem_bo_map_gtt(drm_intel_bo *bo) * undefined). */ -drm_public int +int drm_intel_gem_bo_map_unsynchronized(drm_intel_bo *bo) { drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr; @@ -1556,7 +1625,7 @@ static int drm_intel_gem_bo_unmap(drm_intel_bo *bo) return ret; } -drm_public int +int drm_intel_gem_bo_unmap_gtt(drm_intel_bo *bo) { return drm_intel_gem_bo_unmap(bo); @@ -1681,7 +1750,7 @@ drm_intel_gem_bo_wait_rendering(drm_intel_bo *bo) * Note that some kernels have broken the inifite wait for negative values * promise, upgrade to latest stable kernels if this is the case. */ -drm_public int +int drm_intel_gem_bo_wait(drm_intel_bo *bo, int64_t timeout_ns) { drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr; @@ -1717,7 +1786,7 @@ drm_intel_gem_bo_wait(drm_intel_bo *bo, int64_t timeout_ns) * In combination with drm_intel_gem_bo_pin() and manual fence management, we * can do tiled pixmaps this way. */ -drm_public void +void drm_intel_gem_bo_start_gtt_access(drm_intel_bo *bo, int write_enable) { drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr; @@ -1744,7 +1813,8 @@ static void drm_intel_bufmgr_gem_destroy(drm_intel_bufmgr *bufmgr) { drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bufmgr; - int i; + struct drm_gem_close close_bo; + int i, ret; free(bufmgr_gem->exec2_objects); #ifndef __OpenBSD__ @@ -1770,6 +1840,18 @@ drm_intel_bufmgr_gem_destroy(drm_intel_bufmgr *bufmgr) } } + /* Release userptr bo kept hanging around for optimisation. */ + if (bufmgr_gem->userptr_active.ptr) { + memclear(close_bo); + close_bo.handle = bufmgr_gem->userptr_active.handle; + ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_GEM_CLOSE, &close_bo); + free(bufmgr_gem->userptr_active.ptr); + if (ret) + fprintf(stderr, + "Failed to release test userptr object! (%d) " + "i915 kernel driver may not be sane!\n", errno); + } + free(bufmgr); } @@ -1882,7 +1964,7 @@ drm_intel_gem_bo_emit_reloc_fence(drm_intel_bo *bo, uint32_t offset, read_domains, write_domain, true); } -drm_public int +int drm_intel_gem_bo_get_reloc_count(drm_intel_bo *bo) { drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *) bo; @@ -1903,7 +1985,7 @@ drm_intel_gem_bo_get_reloc_count(drm_intel_bo *bo) * Any further drm_intel_bufmgr_check_aperture_space() queries * involving this buffer in the tree are undefined after this call. */ -drm_public void +void drm_intel_gem_bo_clear_relocs(drm_intel_bo *bo, int start) { drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr; @@ -2243,7 +2325,7 @@ aub_build_dump_ringbuffer(drm_intel_bufmgr_gem *bufmgr_gem, bufmgr_gem->aub_offset += 4096; } -drm_public void +void drm_intel_gem_bo_aub_dump_bmp(drm_intel_bo *bo, int x1, int y1, int width, int height, enum aub_dump_bmp_format format, @@ -2518,7 +2600,7 @@ drm_intel_gem_bo_mrb_exec2(drm_intel_bo *bo, int used, flags); } -drm_public int +int drm_intel_gem_bo_context_exec(drm_intel_bo *bo, drm_intel_context *ctx, int used, unsigned int flags) { @@ -2643,7 +2725,7 @@ drm_intel_gem_bo_get_tiling(drm_intel_bo *bo, uint32_t * tiling_mode, return 0; } -drm_public drm_intel_bo * +drm_intel_bo * drm_intel_bo_gem_create_from_prime(drm_intel_bufmgr *bufmgr, int prime_fd, int size) { drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bufmgr; @@ -2729,7 +2811,7 @@ drm_intel_bo_gem_create_from_prime(drm_intel_bufmgr *bufmgr, int prime_fd, int s return &bo_gem->bo; } -drm_public int +int drm_intel_bo_gem_export_to_prime(drm_intel_bo *bo, int *prime_fd) { drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bo->bufmgr; @@ -2789,7 +2871,7 @@ drm_intel_gem_bo_flink(drm_intel_bo *bo, uint32_t * name) * size is only bounded by how many buffers of that size we've managed to have * in flight at once. */ -drm_public void +void drm_intel_bufmgr_gem_enable_reuse(drm_intel_bufmgr *bufmgr) { drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *) bufmgr; @@ -2804,7 +2886,7 @@ drm_intel_bufmgr_gem_enable_reuse(drm_intel_bufmgr *bufmgr) * allocation. If this option is not enabled, all relocs will have fence * register allocated. */ -drm_public void +void drm_intel_bufmgr_gem_enable_fenced_relocs(drm_intel_bufmgr *bufmgr) { drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *)bufmgr; @@ -3076,7 +3158,7 @@ init_cache_buckets(drm_intel_bufmgr_gem *bufmgr_gem) } } -drm_public void +void drm_intel_bufmgr_gem_set_vma_cache_size(drm_intel_bufmgr *bufmgr, int limit) { drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *)bufmgr; @@ -3117,7 +3199,7 @@ get_pci_device_id(drm_intel_bufmgr_gem *bufmgr_gem) return devid; } -drm_public int +int drm_intel_bufmgr_gem_get_devid(drm_intel_bufmgr *bufmgr) { drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *)bufmgr; @@ -3131,7 +3213,7 @@ drm_intel_bufmgr_gem_get_devid(drm_intel_bufmgr *bufmgr) * This function has to be called before drm_intel_bufmgr_gem_set_aub_dump() * for it to have any effect. */ -drm_public void +void drm_intel_bufmgr_gem_set_aub_filename(drm_intel_bufmgr *bufmgr, const char *filename) { @@ -3150,7 +3232,7 @@ drm_intel_bufmgr_gem_set_aub_filename(drm_intel_bufmgr *bufmgr, * You can set up a GTT and upload your objects into the referenced * space, then send off batchbuffers and get BMPs out the other end. */ -drm_public void +void drm_intel_bufmgr_gem_set_aub_dump(drm_intel_bufmgr *bufmgr, int enable) { drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *)bufmgr; @@ -3207,7 +3289,7 @@ drm_intel_bufmgr_gem_set_aub_dump(drm_intel_bufmgr *bufmgr, int enable) } } -drm_public drm_intel_context * +drm_intel_context * drm_intel_gem_context_create(drm_intel_bufmgr *bufmgr) { drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *)bufmgr; @@ -3234,7 +3316,7 @@ drm_intel_gem_context_create(drm_intel_bufmgr *bufmgr) return context; } -drm_public void +void drm_intel_gem_context_destroy(drm_intel_context *ctx) { drm_intel_bufmgr_gem *bufmgr_gem; @@ -3257,7 +3339,7 @@ drm_intel_gem_context_destroy(drm_intel_context *ctx) free(ctx); } -drm_public int +int drm_intel_get_reset_stats(drm_intel_context *ctx, uint32_t *reset_count, uint32_t *active, @@ -3291,7 +3373,7 @@ drm_intel_get_reset_stats(drm_intel_context *ctx, return ret; } -drm_public int +int drm_intel_reg_read(drm_intel_bufmgr *bufmgr, uint32_t offset, uint64_t *result) @@ -3309,7 +3391,7 @@ drm_intel_reg_read(drm_intel_bufmgr *bufmgr, return ret; } -drm_public int +int drm_intel_get_subslice_total(int fd, unsigned int *subslice_total) { drm_i915_getparam_t gp; @@ -3325,7 +3407,7 @@ drm_intel_get_subslice_total(int fd, unsigned int *subslice_total) return 0; } -drm_public int +int drm_intel_get_eu_total(int fd, unsigned int *eu_total) { drm_i915_getparam_t gp; @@ -3362,7 +3444,7 @@ drm_intel_get_eu_total(int fd, unsigned int *eu_total) * default state (no annotations), call this function with a \c count * of zero. */ -drm_public void +void drm_intel_bufmgr_gem_set_aub_annotations(drm_intel_bo *bo, drm_intel_aub_annotation *annotations, unsigned count) @@ -3417,60 +3499,13 @@ drm_intel_bufmgr_gem_unref(drm_intel_bufmgr *bufmgr) } } -static bool -has_userptr(drm_intel_bufmgr_gem *bufmgr_gem) -{ - int ret; - void *ptr; - long pgsz; - struct drm_i915_gem_userptr userptr; - struct drm_gem_close close_bo; - - pgsz = sysconf(_SC_PAGESIZE); - assert(pgsz > 0); - - ret = posix_memalign(&ptr, pgsz, pgsz); - if (ret) { - DBG("Failed to get a page (%ld) for userptr detection!\n", - pgsz); - return false; - } - - memclear(userptr); - userptr.user_ptr = (uint64_t)(unsigned long)ptr; - userptr.user_size = pgsz; - -retry: - ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_USERPTR, &userptr); - if (ret) { - if (errno == ENODEV && userptr.flags == 0) { - userptr.flags = I915_USERPTR_UNSYNCHRONIZED; - goto retry; - } - free(ptr); - return false; - } - - memclear(close_bo); - close_bo.handle = userptr.handle; - ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_GEM_CLOSE, &close_bo); - free(ptr); - if (ret) { - fprintf(stderr, "Failed to release test userptr object! (%d) " - "i915 kernel driver may not be sane!\n", errno); - return false; - } - - return true; -} - /** * Initializes the GEM buffer manager, which uses the kernel to allocate, map, * and manage map buffer objections. * * \param fd File descriptor of the opened DRM device. */ -drm_public drm_intel_bufmgr * +drm_intel_bufmgr * drm_intel_bufmgr_gem_init(int fd, int batch_size) { drm_intel_bufmgr_gem *bufmgr_gem; @@ -3572,9 +3607,7 @@ drm_intel_bufmgr_gem_init(int fd, int batch_size) ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GETPARAM, &gp); bufmgr_gem->has_relaxed_fencing = ret == 0; - if (has_userptr(bufmgr_gem)) - bufmgr_gem->bufmgr.bo_alloc_userptr = - drm_intel_gem_bo_alloc_userptr; + bufmgr_gem->bufmgr.bo_alloc_userptr = check_bo_alloc_userptr; gp.param = I915_PARAM_HAS_WAIT_TIMEOUT; ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GETPARAM, &gp); diff --git a/lib/libdrm/intel/intel_chipset.h b/lib/libdrm/intel/intel_chipset.h index e22a86735..253ea7105 100644 --- a/lib/libdrm/intel/intel_chipset.h +++ b/lib/libdrm/intel/intel_chipset.h @@ -181,6 +181,10 @@ #define PCI_CHIP_SKYLAKE_SRV_GT1 0x190A #define PCI_CHIP_SKYLAKE_WKS_GT2 0x191D +#define PCI_CHIP_BROXTON_0 0x0A84 +#define PCI_CHIP_BROXTON_1 0x1A84 +#define PCI_CHIP_BROXTON_2 0x5A84 + #define IS_MOBILE(devid) ((devid) == PCI_CHIP_I855_GM || \ (devid) == PCI_CHIP_I915_GM || \ (devid) == PCI_CHIP_I945_GM || \ @@ -362,7 +366,12 @@ IS_SKL_GT2(devid) || \ IS_SKL_GT3(devid)) -#define IS_GEN9(devid) IS_SKYLAKE(devid) +#define IS_BROXTON(devid) ((devid) == PCI_CHIP_BROXTON_0 || \ + (devid) == PCI_CHIP_BROXTON_1 || \ + (devid) == PCI_CHIP_BROXTON_2) + +#define IS_GEN9(devid) (IS_SKYLAKE(devid) || \ + IS_BROXTON(devid)) #define IS_9XX(dev) (IS_GEN3(dev) || \ IS_GEN4(dev) || \ diff --git a/lib/libdrm/intel/intel_decode.c b/lib/libdrm/intel/intel_decode.c index 7d5cbe5a1..2b902a39f 100644 --- a/lib/libdrm/intel/intel_decode.c +++ b/lib/libdrm/intel/intel_decode.c @@ -33,7 +33,7 @@ #include <stdarg.h> #include <string.h> -#include "libdrm.h" +#include "libdrm_macros.h" #include "xf86drm.h" #include "intel_chipset.h" #include "intel_bufmgr.h" @@ -3817,7 +3817,7 @@ decode_3d_i830(struct drm_intel_decode *ctx) return 1; } -drm_public struct drm_intel_decode * +struct drm_intel_decode * drm_intel_decode_context_alloc(uint32_t devid) { struct drm_intel_decode *ctx; @@ -3851,20 +3851,20 @@ drm_intel_decode_context_alloc(uint32_t devid) return ctx; } -drm_public void +void drm_intel_decode_context_free(struct drm_intel_decode *ctx) { free(ctx); } -drm_public void +void drm_intel_decode_set_dump_past_end(struct drm_intel_decode *ctx, int dump_past_end) { ctx->dump_past_end = !!dump_past_end; } -drm_public void +void drm_intel_decode_set_batch_pointer(struct drm_intel_decode *ctx, void *data, uint32_t hw_offset, int count) { @@ -3873,7 +3873,7 @@ drm_intel_decode_set_batch_pointer(struct drm_intel_decode *ctx, ctx->base_count = count; } -drm_public void +void drm_intel_decode_set_head_tail(struct drm_intel_decode *ctx, uint32_t head, uint32_t tail) { @@ -3881,7 +3881,7 @@ drm_intel_decode_set_head_tail(struct drm_intel_decode *ctx, ctx->tail = tail; } -drm_public void +void drm_intel_decode_set_output_file(struct drm_intel_decode *ctx, FILE *out) { @@ -3895,7 +3895,7 @@ drm_intel_decode_set_output_file(struct drm_intel_decode *ctx, * \param count number of DWORDs to decode in the batch buffer * \param hw_offset hardware address for the buffer */ -drm_public void +void drm_intel_decode(struct drm_intel_decode *ctx) { int ret; diff --git a/lib/libdrm/intel/mm.c b/lib/libdrm/intel/mm.c index 106974525..954e9dcb1 100644 --- a/lib/libdrm/intel/mm.c +++ b/lib/libdrm/intel/mm.c @@ -22,13 +22,18 @@ * */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <stdlib.h> #include <assert.h> #include "xf86drm.h" +#include "libdrm_macros.h" #include "mm.h" -void mmDumpMemInfo(const struct mem_block *heap) +drm_private void mmDumpMemInfo(const struct mem_block *heap) { drmMsg("Memory heap %p:\n", (void *)heap); if (heap == 0) { @@ -54,7 +59,7 @@ void mmDumpMemInfo(const struct mem_block *heap) drmMsg("End of memory blocks\n"); } -struct mem_block *mmInit(int ofs, int size) +drm_private struct mem_block *mmInit(int ofs, int size) { struct mem_block *heap, *block; @@ -159,8 +164,8 @@ static struct mem_block *SliceBlock(struct mem_block *p, return p; } -struct mem_block *mmAllocMem(struct mem_block *heap, int size, int align2, - int startSearch) +drm_private struct mem_block *mmAllocMem(struct mem_block *heap, int size, + int align2, int startSearch) { struct mem_block *p; const int mask = (1 << align2) - 1; @@ -191,18 +196,6 @@ struct mem_block *mmAllocMem(struct mem_block *heap, int size, int align2, return p; } -struct mem_block *mmFindBlock(struct mem_block *heap, int start) -{ - struct mem_block *p; - - for (p = heap->next; p != heap; p = p->next) { - if (p->ofs == start) - return p; - } - - return NULL; -} - static int Join2Blocks(struct mem_block *p) { /* XXX there should be some assertions here */ @@ -227,7 +220,7 @@ static int Join2Blocks(struct mem_block *p) return 0; } -int mmFreeMem(struct mem_block *b) +drm_private int mmFreeMem(struct mem_block *b) { if (!b) return 0; @@ -254,7 +247,7 @@ int mmFreeMem(struct mem_block *b) return 0; } -void mmDestroy(struct mem_block *heap) +drm_private void mmDestroy(struct mem_block *heap) { struct mem_block *p; diff --git a/lib/libdrm/intel/mm.h b/lib/libdrm/intel/mm.h index 8a5235b08..8d83743fd 100644 --- a/lib/libdrm/intel/mm.h +++ b/lib/libdrm/intel/mm.h @@ -29,6 +29,12 @@ #ifndef MM_H #define MM_H +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "libdrm_macros.h" + struct mem_block { struct mem_block *next, *prev; struct mem_block *next_free, *prev_free; @@ -38,21 +44,11 @@ struct mem_block { unsigned int reserved:1; }; -/* Rename the variables in the drm copy of this code so that it doesn't - * conflict with mesa or whoever else has copied it around. - */ -#define mmInit drm_mmInit -#define mmAllocMem drm_mmAllocMem -#define mmFreeMem drm_mmFreeMem -#define mmFindBlock drm_mmFindBlock -#define mmDestroy drm_mmDestroy -#define mmDumpMemInfo drm_mmDumpMemInfo - /** * input: total size in bytes * return: a heap pointer if OK, NULL if error */ -extern struct mem_block *mmInit(int ofs, int size); +drm_private extern struct mem_block *mmInit(int ofs, int size); /** * Allocate 'size' bytes with 2^align2 bytes alignment, @@ -64,31 +60,25 @@ extern struct mem_block *mmInit(int ofs, int size); * startSearch = linear offset from start of heap to begin search * return: pointer to the allocated block, 0 if error */ -extern struct mem_block *mmAllocMem(struct mem_block *heap, int size, - int align2, int startSearch); +drm_private extern struct mem_block *mmAllocMem(struct mem_block *heap, + int size, int align2, + int startSearch); /** * Free block starts at offset * input: pointer to a block * return: 0 if OK, -1 if error */ -extern int mmFreeMem(struct mem_block *b); - -/** - * Free block starts at offset - * input: pointer to a heap, start offset - * return: pointer to a block - */ -extern struct mem_block *mmFindBlock(struct mem_block *heap, int start); +drm_private extern int mmFreeMem(struct mem_block *b); /** * destroy MM */ -extern void mmDestroy(struct mem_block *mmInit); +drm_private extern void mmDestroy(struct mem_block *mmInit); /** * For debuging purpose. */ -extern void mmDumpMemInfo(const struct mem_block *mmInit); +drm_private extern void mmDumpMemInfo(const struct mem_block *mmInit); #endif diff --git a/lib/libdrm/intel/shlib_version b/lib/libdrm/intel/shlib_version index b25072f4e..d9961ea9f 100644 --- a/lib/libdrm/intel/shlib_version +++ b/lib/libdrm/intel/shlib_version @@ -1,2 +1,2 @@ -major=3 -minor=3 +major=4 +minor=0 diff --git a/lib/libdrm/libdrm.h b/lib/libdrm/libdrm_macros.h index 6c3cd594d..639d09047 100644 --- a/lib/libdrm/libdrm.h +++ b/lib/libdrm/libdrm_macros.h @@ -25,10 +25,8 @@ #if defined(HAVE_VISIBILITY) # define drm_private __attribute__((visibility("hidden"))) -# define drm_public __attribute__((visibility("default"))) #else # define drm_private -# define drm_public #endif diff --git a/lib/libdrm/libkms/api.c b/lib/libdrm/libkms/api.c index 41f17705f..be5808932 100644 --- a/lib/libdrm/libkms/api.c +++ b/lib/libdrm/libkms/api.c @@ -29,9 +29,12 @@ #ifdef HAVE_CONFIG_H # include <config.h> #endif + #include <errno.h> #include <stdlib.h> #include <string.h> + +#include "libdrm_macros.h" #include "internal.h" int kms_create(int fd, struct kms_driver **out) diff --git a/lib/libdrm/libkms/dumb.c b/lib/libdrm/libkms/dumb.c index 440efb310..16119ef25 100644 --- a/lib/libdrm/libkms/dumb.c +++ b/lib/libdrm/libkms/dumb.c @@ -191,7 +191,7 @@ dumb_bo_destroy(struct kms_bo *_bo) return 0; } -int +drm_private int dumb_create(int fd, struct kms_driver **out) { struct kms_driver *kms; diff --git a/lib/libdrm/libkms/intel.c b/lib/libdrm/libkms/intel.c index abae45257..52ddcb19e 100644 --- a/lib/libdrm/libkms/intel.c +++ b/lib/libdrm/libkms/intel.c @@ -215,7 +215,7 @@ intel_bo_destroy(struct kms_bo *_bo) return 0; } -int +drm_private int intel_create(int fd, struct kms_driver **out) { struct kms_driver *kms; diff --git a/lib/libdrm/libkms/internal.h b/lib/libdrm/libkms/internal.h index 5e2501e4d..b3bbd8397 100644 --- a/lib/libdrm/libkms/internal.h +++ b/lib/libdrm/libkms/internal.h @@ -29,6 +29,11 @@ #ifndef INTERNAL_H_ #define INTERNAL_H_ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "libdrm_macros.h" #include "libkms.h" struct kms_driver diff --git a/lib/libdrm/libkms/linux.c b/lib/libdrm/libkms/linux.c index 9bae53ca8..321a0b580 100644 --- a/lib/libdrm/libkms/linux.c +++ b/lib/libdrm/libkms/linux.c @@ -39,9 +39,9 @@ #include <xf86drm.h> #include <string.h> #include <unistd.h> - #include <sys/stat.h> +#include "libdrm_macros.h" #include "internal.h" #define PATH_SIZE 512 @@ -215,7 +215,7 @@ linux_from_udev(int fd, struct kms_driver **out) } #endif -int +drm_private int linux_create(int fd, struct kms_driver **out) { if (!dumb_create(fd, out)) diff --git a/lib/libdrm/libkms/nouveau.c b/lib/libdrm/libkms/nouveau.c index 608092f58..8d133108e 100644 --- a/lib/libdrm/libkms/nouveau.c +++ b/lib/libdrm/libkms/nouveau.c @@ -197,7 +197,7 @@ nouveau_bo_destroy(struct kms_bo *_bo) return 0; } -int +drm_private int nouveau_create(int fd, struct kms_driver **out) { struct kms_driver *kms; diff --git a/lib/libdrm/libkms/radeon.c b/lib/libdrm/libkms/radeon.c index f5e382ae4..c775318bf 100644 --- a/lib/libdrm/libkms/radeon.c +++ b/lib/libdrm/libkms/radeon.c @@ -218,7 +218,7 @@ radeon_bo_destroy(struct kms_bo *_bo) return 0; } -int +drm_private int radeon_create(int fd, struct kms_driver **out) { struct kms_driver *kms; diff --git a/lib/libdrm/libkms/vmwgfx.c b/lib/libdrm/libkms/vmwgfx.c index d594b3bd1..047fd30af 100644 --- a/lib/libdrm/libkms/vmwgfx.c +++ b/lib/libdrm/libkms/vmwgfx.c @@ -184,7 +184,7 @@ vmwgfx_bo_destroy(struct kms_bo *_bo) return 0; } -int +drm_private int vmwgfx_create(int fd, struct kms_driver **out) { struct kms_driver *kms; diff --git a/lib/libdrm/radeon/r600_pci_ids.h b/lib/libdrm/radeon/r600_pci_ids.h index 3e1136db2..9d12587b8 100644 --- a/lib/libdrm/radeon/r600_pci_ids.h +++ b/lib/libdrm/radeon/r600_pci_ids.h @@ -413,6 +413,7 @@ CHIPSET(0x6651, BONAIRE_6651, BONAIRE) CHIPSET(0x6658, BONAIRE_6658, BONAIRE) CHIPSET(0x665C, BONAIRE_665C, BONAIRE) CHIPSET(0x665D, BONAIRE_665D, BONAIRE) +CHIPSET(0x665F, BONAIRE_665F, BONAIRE) CHIPSET(0x9830, KABINI_9830, KABINI) CHIPSET(0x9831, KABINI_9831, KABINI) diff --git a/lib/libdrm/radeon/radeon_bo.c b/lib/libdrm/radeon/radeon_bo.c index 865e3f7e0..447f92803 100644 --- a/lib/libdrm/radeon/radeon_bo.c +++ b/lib/libdrm/radeon/radeon_bo.c @@ -32,11 +32,11 @@ #ifdef HAVE_CONFIG_H #include <config.h> #endif -#include <libdrm.h> +#include <libdrm_macros.h> #include <radeon_bo.h> #include <radeon_bo_int.h> -drm_public void radeon_bo_debug(struct radeon_bo *bo, const char *op) +void radeon_bo_debug(struct radeon_bo *bo, const char *op) { struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; @@ -44,7 +44,7 @@ drm_public void radeon_bo_debug(struct radeon_bo *bo, const char *op) op, bo, bo->handle, boi->size, boi->cref); } -drm_public struct radeon_bo * +struct radeon_bo * radeon_bo_open(struct radeon_bo_manager *bom, uint32_t handle, uint32_t size, uint32_t alignment, uint32_t domains, uint32_t flags) { @@ -53,14 +53,14 @@ radeon_bo_open(struct radeon_bo_manager *bom, uint32_t handle, uint32_t size, return bo; } -drm_public void radeon_bo_ref(struct radeon_bo *bo) +void radeon_bo_ref(struct radeon_bo *bo) { struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; boi->cref++; boi->bom->funcs->bo_ref(boi); } -drm_public struct radeon_bo *radeon_bo_unref(struct radeon_bo *bo) +struct radeon_bo *radeon_bo_unref(struct radeon_bo *bo) { struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; if (bo == NULL) @@ -70,19 +70,19 @@ drm_public struct radeon_bo *radeon_bo_unref(struct radeon_bo *bo) return boi->bom->funcs->bo_unref(boi); } -drm_public int radeon_bo_map(struct radeon_bo *bo, int write) +int radeon_bo_map(struct radeon_bo *bo, int write) { struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; return boi->bom->funcs->bo_map(boi, write); } -drm_public int radeon_bo_unmap(struct radeon_bo *bo) +int radeon_bo_unmap(struct radeon_bo *bo) { struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; return boi->bom->funcs->bo_unmap(boi); } -drm_public int radeon_bo_wait(struct radeon_bo *bo) +int radeon_bo_wait(struct radeon_bo *bo) { struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; if (!boi->bom->funcs->bo_wait) @@ -90,13 +90,13 @@ drm_public int radeon_bo_wait(struct radeon_bo *bo) return boi->bom->funcs->bo_wait(boi); } -drm_public int radeon_bo_is_busy(struct radeon_bo *bo, uint32_t *domain) +int radeon_bo_is_busy(struct radeon_bo *bo, uint32_t *domain) { struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; return boi->bom->funcs->bo_is_busy(boi, domain); } -drm_public int +int radeon_bo_set_tiling(struct radeon_bo *bo, uint32_t tiling_flags, uint32_t pitch) { @@ -104,7 +104,7 @@ radeon_bo_set_tiling(struct radeon_bo *bo, return boi->bom->funcs->bo_set_tiling(boi, tiling_flags, pitch); } -drm_public int +int radeon_bo_get_tiling(struct radeon_bo *bo, uint32_t *tiling_flags, uint32_t *pitch) { @@ -112,7 +112,7 @@ radeon_bo_get_tiling(struct radeon_bo *bo, return boi->bom->funcs->bo_get_tiling(boi, tiling_flags, pitch); } -drm_public int radeon_bo_is_static(struct radeon_bo *bo) +int radeon_bo_is_static(struct radeon_bo *bo) { struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; if (boi->bom->funcs->bo_is_static) @@ -120,19 +120,19 @@ drm_public int radeon_bo_is_static(struct radeon_bo *bo) return 0; } -drm_public int +int radeon_bo_is_referenced_by_cs(struct radeon_bo *bo, struct radeon_cs *cs) { struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; return boi->cref > 1; } -drm_public uint32_t radeon_bo_get_handle(struct radeon_bo *bo) +uint32_t radeon_bo_get_handle(struct radeon_bo *bo) { return bo->handle; } -drm_public uint32_t radeon_bo_get_src_domain(struct radeon_bo *bo) +uint32_t radeon_bo_get_src_domain(struct radeon_bo *bo) { struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; uint32_t src_domain; diff --git a/lib/libdrm/radeon/radeon_bo_gem.c b/lib/libdrm/radeon/radeon_bo_gem.c index 3bcbf40ed..7fdd437a1 100644 --- a/lib/libdrm/radeon/radeon_bo_gem.c +++ b/lib/libdrm/radeon/radeon_bo_gem.c @@ -37,7 +37,7 @@ #include <stdlib.h> #include <string.h> #include <errno.h> -#include "libdrm.h" +#include "libdrm_macros.h" #include "xf86drm.h" #include "xf86atomic.h" #include "drm.h" @@ -212,7 +212,7 @@ static int bo_wait(struct radeon_bo_int *boi) args.handle = boi->handle; do { ret = drmCommandWrite(boi->bom->fd, DRM_RADEON_GEM_WAIT_IDLE, - &args, sizeof(args)); + &args, sizeof(args)); } while (ret == -EBUSY); return ret; } @@ -283,7 +283,7 @@ static struct radeon_bo_funcs bo_gem_funcs = { bo_is_busy, }; -drm_public struct radeon_bo_manager *radeon_bo_manager_gem_ctor(int fd) +struct radeon_bo_manager *radeon_bo_manager_gem_ctor(int fd) { struct bo_manager_gem *bomg; @@ -296,7 +296,7 @@ drm_public struct radeon_bo_manager *radeon_bo_manager_gem_ctor(int fd) return (struct radeon_bo_manager*)bomg; } -drm_public void radeon_bo_manager_gem_dtor(struct radeon_bo_manager *bom) +void radeon_bo_manager_gem_dtor(struct radeon_bo_manager *bom) { struct bo_manager_gem *bomg = (struct bo_manager_gem*)bom; @@ -306,21 +306,21 @@ drm_public void radeon_bo_manager_gem_dtor(struct radeon_bo_manager *bom) free(bomg); } -drm_public uint32_t +uint32_t radeon_gem_name_bo(struct radeon_bo *bo) { struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo; return bo_gem->name; } -drm_public void * +void * radeon_gem_get_reloc_in_cs(struct radeon_bo *bo) { struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo; return &bo_gem->reloc_in_cs; } -drm_public int +int radeon_gem_get_kernel_name(struct radeon_bo *bo, uint32_t *name) { struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo; @@ -342,7 +342,7 @@ radeon_gem_get_kernel_name(struct radeon_bo *bo, uint32_t *name) return 0; } -drm_public int +int radeon_gem_set_domain(struct radeon_bo *bo, uint32_t read_domains, uint32_t write_domain) { struct radeon_bo_int *boi = (struct radeon_bo_int *)bo; @@ -360,7 +360,7 @@ radeon_gem_set_domain(struct radeon_bo *bo, uint32_t read_domains, uint32_t writ return r; } -drm_public int radeon_gem_prime_share_bo(struct radeon_bo *bo, int *handle) +int radeon_gem_prime_share_bo(struct radeon_bo *bo, int *handle) { struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo; int ret; @@ -369,7 +369,7 @@ drm_public int radeon_gem_prime_share_bo(struct radeon_bo *bo, int *handle) return ret; } -drm_public struct radeon_bo * +struct radeon_bo * radeon_gem_bo_open_prime(struct radeon_bo_manager *bom, int fd_handle, uint32_t size) { struct radeon_bo_gem *bo; diff --git a/lib/libdrm/radeon/radeon_cs.c b/lib/libdrm/radeon/radeon_cs.c index fe5bbcec4..dffb869fa 100644 --- a/lib/libdrm/radeon/radeon_cs.c +++ b/lib/libdrm/radeon/radeon_cs.c @@ -1,19 +1,19 @@ #ifdef HAVE_CONFIG_H #include <config.h> #endif -#include "libdrm.h" +#include "libdrm_macros.h" #include <stdio.h> #include "radeon_cs.h" #include "radeon_cs_int.h" -drm_public struct radeon_cs * +struct radeon_cs * radeon_cs_create(struct radeon_cs_manager *csm, uint32_t ndw) { struct radeon_cs_int *csi = csm->funcs->cs_create(csm, ndw); return (struct radeon_cs *)csi; } -drm_public int +int radeon_cs_write_reloc(struct radeon_cs *cs, struct radeon_bo *bo, uint32_t read_domain, uint32_t write_domain, uint32_t flags) @@ -27,7 +27,7 @@ radeon_cs_write_reloc(struct radeon_cs *cs, struct radeon_bo *bo, flags); } -drm_public int +int radeon_cs_begin(struct radeon_cs *cs, uint32_t ndw, const char *file, const char *func, int line) { @@ -35,7 +35,7 @@ radeon_cs_begin(struct radeon_cs *cs, uint32_t ndw, return csi->csm->funcs->cs_begin(csi, ndw, file, func, line); } -drm_public int +int radeon_cs_end(struct radeon_cs *cs, const char *file, const char *func, int line) { @@ -43,37 +43,37 @@ radeon_cs_end(struct radeon_cs *cs, return csi->csm->funcs->cs_end(csi, file, func, line); } -drm_public int radeon_cs_emit(struct radeon_cs *cs) +int radeon_cs_emit(struct radeon_cs *cs) { struct radeon_cs_int *csi = (struct radeon_cs_int *)cs; return csi->csm->funcs->cs_emit(csi); } -drm_public int radeon_cs_destroy(struct radeon_cs *cs) +int radeon_cs_destroy(struct radeon_cs *cs) { struct radeon_cs_int *csi = (struct radeon_cs_int *)cs; return csi->csm->funcs->cs_destroy(csi); } -drm_public int radeon_cs_erase(struct radeon_cs *cs) +int radeon_cs_erase(struct radeon_cs *cs) { struct radeon_cs_int *csi = (struct radeon_cs_int *)cs; return csi->csm->funcs->cs_erase(csi); } -drm_public int radeon_cs_need_flush(struct radeon_cs *cs) +int radeon_cs_need_flush(struct radeon_cs *cs) { struct radeon_cs_int *csi = (struct radeon_cs_int *)cs; return csi->csm->funcs->cs_need_flush(csi); } -drm_public void radeon_cs_print(struct radeon_cs *cs, FILE *file) +void radeon_cs_print(struct radeon_cs *cs, FILE *file) { struct radeon_cs_int *csi = (struct radeon_cs_int *)cs; csi->csm->funcs->cs_print(csi, file); } -drm_public void +void radeon_cs_set_limit(struct radeon_cs *cs, uint32_t domain, uint32_t limit) { struct radeon_cs_int *csi = (struct radeon_cs_int *)cs; @@ -83,7 +83,7 @@ radeon_cs_set_limit(struct radeon_cs *cs, uint32_t domain, uint32_t limit) csi->csm->gart_limit = limit; } -drm_public void radeon_cs_space_set_flush(struct radeon_cs *cs, +void radeon_cs_space_set_flush(struct radeon_cs *cs, void (*fn)(void *), void *data) { struct radeon_cs_int *csi = (struct radeon_cs_int *)cs; @@ -91,7 +91,7 @@ drm_public void radeon_cs_space_set_flush(struct radeon_cs *cs, csi->space_flush_data = data; } -drm_public uint32_t radeon_cs_get_id(struct radeon_cs *cs) +uint32_t radeon_cs_get_id(struct radeon_cs *cs) { struct radeon_cs_int *csi = (struct radeon_cs_int *)cs; return csi->id; diff --git a/lib/libdrm/radeon/radeon_cs_gem.c b/lib/libdrm/radeon/radeon_cs_gem.c index 705ee0564..1962e915b 100644 --- a/lib/libdrm/radeon/radeon_cs_gem.c +++ b/lib/libdrm/radeon/radeon_cs_gem.c @@ -44,13 +44,16 @@ #include "radeon_cs_gem.h" #include "radeon_bo_gem.h" #include "drm.h" -#include "libdrm.h" +#include "libdrm_macros.h" #include "xf86drm.h" #include "xf86atomic.h" #include "radeon_drm.h" -#include "bof.h" +/* Add LIBDRM_RADEON_BOF_FILES to libdrm_radeon_la_SOURCES when building with BOF_DUMP */ #define CS_BOF_DUMP 0 +#if CS_BOF_DUMP +#include "bof.h" +#endif struct radeon_cs_manager_gem { struct radeon_cs_manager base; @@ -536,7 +539,7 @@ static int radeon_get_device_id(int fd, uint32_t *device_id) return r; } -drm_public struct radeon_cs_manager *radeon_cs_manager_gem_ctor(int fd) +struct radeon_cs_manager *radeon_cs_manager_gem_ctor(int fd) { struct radeon_cs_manager_gem *csm; @@ -550,7 +553,7 @@ drm_public struct radeon_cs_manager *radeon_cs_manager_gem_ctor(int fd) return &csm->base; } -drm_public void radeon_cs_manager_gem_dtor(struct radeon_cs_manager *csm) +void radeon_cs_manager_gem_dtor(struct radeon_cs_manager *csm) { free(csm); } diff --git a/lib/libdrm/radeon/radeon_cs_space.c b/lib/libdrm/radeon/radeon_cs_space.c index cca650bf5..69287be5b 100644 --- a/lib/libdrm/radeon/radeon_cs_space.c +++ b/lib/libdrm/radeon/radeon_cs_space.c @@ -31,7 +31,7 @@ #include <assert.h> #include <errno.h> #include <stdlib.h> -#include "libdrm.h" +#include "libdrm_macros.h" #include "radeon_cs.h" #include "radeon_bo_int.h" #include "radeon_cs_int.h" @@ -165,7 +165,7 @@ static int radeon_cs_do_space_check(struct radeon_cs_int *cs, struct radeon_cs_s return RADEON_CS_SPACE_OK; } -drm_public void +void radeon_cs_space_add_persistent_bo(struct radeon_cs *cs, struct radeon_bo *bo, uint32_t read_domains, uint32_t write_domain) { @@ -209,7 +209,7 @@ again: return 0; } -drm_public int +int radeon_cs_space_check_with_bo(struct radeon_cs *cs, struct radeon_bo *bo, uint32_t read_domains, uint32_t write_domain) { @@ -230,13 +230,13 @@ radeon_cs_space_check_with_bo(struct radeon_cs *cs, struct radeon_bo *bo, return ret; } -drm_public int radeon_cs_space_check(struct radeon_cs *cs) +int radeon_cs_space_check(struct radeon_cs *cs) { struct radeon_cs_int *csi = (struct radeon_cs_int *)cs; return radeon_cs_check_space_internal(csi, NULL); } -drm_public void radeon_cs_space_reset_bos(struct radeon_cs *cs) +void radeon_cs_space_reset_bos(struct radeon_cs *cs) { struct radeon_cs_int *csi = (struct radeon_cs_int *)cs; int i; diff --git a/lib/libdrm/radeon/radeon_surface.c b/lib/libdrm/radeon/radeon_surface.c index bd9ee6d11..fad4bda31 100644 --- a/lib/libdrm/radeon/radeon_surface.c +++ b/lib/libdrm/radeon/radeon_surface.c @@ -37,7 +37,7 @@ #include <string.h> #include <sys/ioctl.h> #include "drm.h" -#include "libdrm.h" +#include "libdrm_macros.h" #include "xf86drm.h" #include "radeon_drm.h" #include "radeon_surface.h" @@ -785,7 +785,7 @@ static int eg_surface_init_1d_miptrees(struct radeon_surface_manager *surf_man, { unsigned zs_flags = RADEON_SURF_ZBUFFER | RADEON_SURF_SBUFFER; int r, is_depth_stencil = (surf->flags & zs_flags) == zs_flags; - /* Old libdrm headers didn't have stencil_level in it. This prevents crashes. */ + /* Old libdrm_macros.headers didn't have stencil_level in it. This prevents crashes. */ struct radeon_surface_level tmp[RADEON_SURF_MAX_LEVEL]; struct radeon_surface_level *stencil_level = (surf->flags & RADEON_SURF_HAS_SBUFFER_MIPTREE) ? surf->stencil_level : tmp; @@ -807,7 +807,7 @@ static int eg_surface_init_2d_miptrees(struct radeon_surface_manager *surf_man, { unsigned zs_flags = RADEON_SURF_ZBUFFER | RADEON_SURF_SBUFFER; int r, is_depth_stencil = (surf->flags & zs_flags) == zs_flags; - /* Old libdrm headers didn't have stencil_level in it. This prevents crashes. */ + /* Old libdrm_macros.headers didn't have stencil_level in it. This prevents crashes. */ struct radeon_surface_level tmp[RADEON_SURF_MAX_LEVEL]; struct radeon_surface_level *stencil_level = (surf->flags & RADEON_SURF_HAS_SBUFFER_MIPTREE) ? surf->stencil_level : tmp; @@ -2400,7 +2400,7 @@ static int cik_surface_best(struct radeon_surface_manager *surf_man, /* =========================================================================== * public API */ -drm_public struct radeon_surface_manager * +struct radeon_surface_manager * radeon_surface_manager_new(int fd) { struct radeon_surface_manager *surf_man; @@ -2449,7 +2449,7 @@ out_err: return NULL; } -drm_public void +void radeon_surface_manager_free(struct radeon_surface_manager *surf_man) { free(surf_man); @@ -2522,7 +2522,7 @@ static int radeon_surface_sanity(struct radeon_surface_manager *surf_man, return 0; } -drm_public int +int radeon_surface_init(struct radeon_surface_manager *surf_man, struct radeon_surface *surf) { @@ -2539,7 +2539,7 @@ radeon_surface_init(struct radeon_surface_manager *surf_man, return surf_man->surface_init(surf_man, surf); } -drm_public int +int radeon_surface_best(struct radeon_surface_manager *surf_man, struct radeon_surface *surf) { diff --git a/lib/libdrm/shlib_version b/lib/libdrm/shlib_version index 9c1551636..5b844bbf4 100644 --- a/lib/libdrm/shlib_version +++ b/lib/libdrm/shlib_version @@ -1,2 +1,2 @@ -major=6 +major=7 minor=0 diff --git a/lib/libdrm/xf86drm.c b/lib/libdrm/xf86drm.c index 1d24956e1..17e697d15 100644 --- a/lib/libdrm/xf86drm.c +++ b/lib/libdrm/xf86drm.c @@ -62,7 +62,7 @@ #endif #include "xf86drm.h" -#include "libdrm.h" +#include "libdrm_macros.h" #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) #define DRM_MAJOR 145 @@ -110,11 +110,6 @@ drmDebugPrint(const char *format, va_list ap) return vfprintf(stderr, format, ap); } -typedef int DRM_PRINTFLIKE(1, 0) (*debug_msg_func_t)(const char *format, - va_list ap); - -static debug_msg_func_t drm_debug_print = drmDebugPrint; - void drmMsg(const char *format, ...) { @@ -126,18 +121,12 @@ drmMsg(const char *format, ...) if (drm_server_info) { drm_server_info->debug_print(format,ap); } else { - drm_debug_print(format, ap); + drmDebugPrint(format, ap); } va_end(ap); } } -void -drmSetDebugMsgFunction(debug_msg_func_t debug_msg_ptr) -{ - drm_debug_print = debug_msg_ptr; -} - static void *drmHashTable = NULL; /* Context switch callbacks */ void *drmGetHashTable(void) @@ -147,16 +136,12 @@ void *drmGetHashTable(void) void *drmMalloc(int size) { - void *pt; - if ((pt = malloc(size))) - memset(pt, 0, size); - return pt; + return calloc(1, size); } void drmFree(void *pt) { - if (pt) - free(pt); + free(pt); } /** @@ -273,6 +258,7 @@ static int drmMatchBusID(const char *id1, const char *id2, int pci_domain_ok) * If any other failure happened then it will output error mesage using * drmMsg() call. */ +#if !defined(UDEV) static int chown_check_return(const char *path, uid_t owner, gid_t group) { int rv; @@ -288,6 +274,7 @@ static int chown_check_return(const char *path, uid_t owner, gid_t group) path, errno, strerror(errno)); return -1; } +#endif /** * Open the DRM device, creating it if necessary. @@ -358,7 +345,7 @@ static int drmOpenDevice(dev_t dev, int minor, int type) } if (drm_server_info) { - group = (serv_group >= 0) ? serv_group : DRM_DEV_GID; + group = ((int)serv_group >= 0) ? serv_group : DRM_DEV_GID; chown_check_return(buf, user, group); chmod(buf, devmode); } @@ -1735,7 +1722,7 @@ int drmAgpEnable(int fd, unsigned long mode) { drm_agp_mode_t m; - memclear(mode); + memclear(m); m.mode = mode; if (drmIoctl(fd, DRM_IOCTL_AGP_ENABLE, &m)) return -errno; @@ -2758,6 +2745,8 @@ int drmPrimeHandleToFD(int fd, uint32_t handle, uint32_t flags, int *prime_fd) struct drm_prime_handle args; int ret; + memclear(args); + args.fd = -1; args.handle = handle; args.flags = flags; ret = drmIoctl(fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args); @@ -2773,8 +2762,8 @@ int drmPrimeFDToHandle(int fd, int prime_fd, uint32_t *handle) struct drm_prime_handle args; int ret; + memclear(args); args.fd = prime_fd; - args.flags = 0; ret = drmIoctl(fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &args); if (ret) return ret; diff --git a/lib/libdrm/xf86drmHash.c b/lib/libdrm/xf86drmHash.c index 82cbc2a5c..f287e61fb 100644 --- a/lib/libdrm/xf86drmHash.c +++ b/lib/libdrm/xf86drmHash.c @@ -71,60 +71,10 @@ #include <stdio.h> #include <stdlib.h> -#define HASH_MAIN 0 - -#if !HASH_MAIN -# include "xf86drm.h" -#endif +#include "xf86drm.h" +#include "xf86drmHash.h" #define HASH_MAGIC 0xdeadbeef -#define HASH_DEBUG 0 -#define HASH_SIZE 512 /* Good for about 100 entries */ - /* If you change this value, you probably - have to change the HashHash hashing - function! */ - -#if HASH_MAIN -#define HASH_ALLOC malloc -#define HASH_FREE free -#define HASH_RANDOM_DECL -#define HASH_RANDOM_INIT(seed) srandom(seed) -#define HASH_RANDOM random() -#define HASH_RANDOM_DESTROY -#else -#define HASH_ALLOC drmMalloc -#define HASH_FREE drmFree -#define HASH_RANDOM_DECL void *state -#define HASH_RANDOM_INIT(seed) state = drmRandomCreate(seed) -#define HASH_RANDOM drmRandom(state) -#define HASH_RANDOM_DESTROY drmRandomDestroy(state) - -#endif - -typedef struct HashBucket { - unsigned long key; - void *value; - struct HashBucket *next; -} HashBucket, *HashBucketPtr; - -typedef struct HashTable { - unsigned long magic; - unsigned long entries; - unsigned long hits; /* At top of linked list */ - unsigned long partials; /* Not at top of linked list */ - unsigned long misses; /* Not in table */ - HashBucketPtr buckets[HASH_SIZE]; - int p0; - HashBucketPtr p1; -} HashTable, *HashTablePtr; - -#if HASH_MAIN -extern void *drmHashCreate(void); -extern int drmHashDestroy(void *t); -extern int drmHashLookup(void *t, unsigned long key, unsigned long *value); -extern int drmHashInsert(void *t, unsigned long key, unsigned long value); -extern int drmHashDelete(void *t, unsigned long key); -#endif static unsigned long HashHash(unsigned long key) { @@ -135,10 +85,10 @@ static unsigned long HashHash(unsigned long key) int i; if (!init) { - HASH_RANDOM_DECL; - HASH_RANDOM_INIT(37); - for (i = 0; i < 256; i++) scatter[i] = HASH_RANDOM; - HASH_RANDOM_DESTROY; + void *state; + state = drmRandomCreate(37); + for (i = 0; i < 256; i++) scatter[i] = drmRandom(state); + drmRandomDestroy(state); ++init; } @@ -148,8 +98,8 @@ static unsigned long HashHash(unsigned long key) } hash %= HASH_SIZE; -#if HASH_DEBUG - printf( "Hash(%d) = %d\n", key, hash); +#if DEBUG + printf( "Hash(%lu) = %lu\n", key, hash); #endif return hash; } @@ -159,7 +109,7 @@ void *drmHashCreate(void) HashTablePtr table; int i; - table = HASH_ALLOC(sizeof(*table)); + table = drmMalloc(sizeof(*table)); if (!table) return NULL; table->magic = HASH_MAGIC; table->entries = 0; @@ -183,11 +133,11 @@ int drmHashDestroy(void *t) for (i = 0; i < HASH_SIZE; i++) { for (bucket = table->buckets[i]; bucket;) { next = bucket->next; - HASH_FREE(bucket); + drmFree(bucket); bucket = next; } } - HASH_FREE(table); + drmFree(table); return 0; } @@ -245,14 +195,14 @@ int drmHashInsert(void *t, unsigned long key, void *value) if (HashFind(table, key, &hash)) return 1; /* Already in table */ - bucket = HASH_ALLOC(sizeof(*bucket)); + bucket = drmMalloc(sizeof(*bucket)); if (!bucket) return -1; /* Error */ bucket->key = key; bucket->value = value; bucket->next = table->buckets[hash]; table->buckets[hash] = bucket; -#if HASH_DEBUG - printf("Inserted %d at %d/%p\n", key, hash, bucket); +#if DEBUG + printf("Inserted %lu at %lu/%p\n", key, hash, bucket); #endif return 0; /* Added to table */ } @@ -270,7 +220,7 @@ int drmHashDelete(void *t, unsigned long key) if (!bucket) return 1; /* Not found */ table->buckets[hash] = bucket->next; - HASH_FREE(bucket); + drmFree(bucket); return 0; } @@ -301,128 +251,3 @@ int drmHashFirst(void *t, unsigned long *key, void **value) table->p1 = table->buckets[0]; return drmHashNext(table, key, value); } - -#if HASH_MAIN -#define DIST_LIMIT 10 -static int dist[DIST_LIMIT]; - -static void clear_dist(void) { - int i; - - for (i = 0; i < DIST_LIMIT; i++) dist[i] = 0; -} - -static int count_entries(HashBucketPtr bucket) -{ - int count = 0; - - for (; bucket; bucket = bucket->next) ++count; - return count; -} - -static void update_dist(int count) -{ - if (count >= DIST_LIMIT) ++dist[DIST_LIMIT-1]; - else ++dist[count]; -} - -static void compute_dist(HashTablePtr table) -{ - int i; - HashBucketPtr bucket; - - printf("Entries = %ld, hits = %ld, partials = %ld, misses = %ld\n", - table->entries, table->hits, table->partials, table->misses); - clear_dist(); - for (i = 0; i < HASH_SIZE; i++) { - bucket = table->buckets[i]; - update_dist(count_entries(bucket)); - } - for (i = 0; i < DIST_LIMIT; i++) { - if (i != DIST_LIMIT-1) printf("%5d %10d\n", i, dist[i]); - else printf("other %10d\n", dist[i]); - } -} - -static void check_table(HashTablePtr table, - unsigned long key, unsigned long value) -{ - unsigned long retval = 0; - int retcode = drmHashLookup(table, key, &retval); - - switch (retcode) { - case -1: - printf("Bad magic = 0x%08lx:" - " key = %lu, expected = %lu, returned = %lu\n", - table->magic, key, value, retval); - break; - case 1: - printf("Not found: key = %lu, expected = %lu returned = %lu\n", - key, value, retval); - break; - case 0: - if (value != retval) - printf("Bad value: key = %lu, expected = %lu, returned = %lu\n", - key, value, retval); - break; - default: - printf("Bad retcode = %d: key = %lu, expected = %lu, returned = %lu\n", - retcode, key, value, retval); - break; - } -} - -int main(void) -{ - HashTablePtr table; - int i; - - printf("\n***** 256 consecutive integers ****\n"); - table = drmHashCreate(); - for (i = 0; i < 256; i++) drmHashInsert(table, i, i); - for (i = 0; i < 256; i++) check_table(table, i, i); - for (i = 256; i >= 0; i--) check_table(table, i, i); - compute_dist(table); - drmHashDestroy(table); - - printf("\n***** 1024 consecutive integers ****\n"); - table = drmHashCreate(); - for (i = 0; i < 1024; i++) drmHashInsert(table, i, i); - for (i = 0; i < 1024; i++) check_table(table, i, i); - for (i = 1024; i >= 0; i--) check_table(table, i, i); - compute_dist(table); - drmHashDestroy(table); - - printf("\n***** 1024 consecutive page addresses (4k pages) ****\n"); - table = drmHashCreate(); - for (i = 0; i < 1024; i++) drmHashInsert(table, i*4096, i); - for (i = 0; i < 1024; i++) check_table(table, i*4096, i); - for (i = 1024; i >= 0; i--) check_table(table, i*4096, i); - compute_dist(table); - drmHashDestroy(table); - - printf("\n***** 1024 random integers ****\n"); - table = drmHashCreate(); - srandom(0xbeefbeef); - for (i = 0; i < 1024; i++) drmHashInsert(table, random(), i); - srandom(0xbeefbeef); - for (i = 0; i < 1024; i++) check_table(table, random(), i); - srandom(0xbeefbeef); - for (i = 0; i < 1024; i++) check_table(table, random(), i); - compute_dist(table); - drmHashDestroy(table); - - printf("\n***** 5000 random integers ****\n"); - table = drmHashCreate(); - srandom(0xbeefbeef); - for (i = 0; i < 5000; i++) drmHashInsert(table, random(), i); - srandom(0xbeefbeef); - for (i = 0; i < 5000; i++) check_table(table, random(), i); - srandom(0xbeefbeef); - for (i = 0; i < 5000; i++) check_table(table, random(), i); - compute_dist(table); - drmHashDestroy(table); - - return 0; -} -#endif diff --git a/lib/libdrm/xf86drmHash.h b/lib/libdrm/xf86drmHash.h new file mode 100644 index 000000000..38fd84b70 --- /dev/null +++ b/lib/libdrm/xf86drmHash.h @@ -0,0 +1,47 @@ +/* + * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. + * 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, sublicense, + * 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 above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * 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 NONINFRINGEMENT. IN NO EVENT SHALL + * PRECISION INSIGHT 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. + * + * Authors: Rickard E. (Rik) Faith <faith@valinux.com> + */ + +#define HASH_SIZE 512 /* Good for about 100 entries */ + /* If you change this value, you probably + have to change the HashHash hashing + function! */ + +typedef struct HashBucket { + unsigned long key; + void *value; + struct HashBucket *next; +} HashBucket, *HashBucketPtr; + +typedef struct HashTable { + unsigned long magic; + unsigned long entries; + unsigned long hits; /* At top of linked list */ + unsigned long partials; /* Not at top of linked list */ + unsigned long misses; /* Not in table */ + HashBucketPtr buckets[HASH_SIZE]; + int p0; + HashBucketPtr p1; +} HashTable, *HashTablePtr; diff --git a/lib/libdrm/xf86drmMode.c b/lib/libdrm/xf86drmMode.c index 45c6636d6..ae119f542 100644 --- a/lib/libdrm/xf86drmMode.c +++ b/lib/libdrm/xf86drmMode.c @@ -37,14 +37,18 @@ * TODO the types we are after are defined in diffrent headers on diffrent * platforms find which headers to include to get uint32_t */ -#include <stdint.h> -#include <sys/ioctl.h> -#include <stdio.h> #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include <limits.h> +#include <stdint.h> +#include <stdlib.h> +#include <sys/ioctl.h> +#include <stdio.h> +#include <stdbool.h> + #include "xf86drmMode.h" #include "xf86drm.h" #include <drm.h> @@ -53,14 +57,6 @@ #include <unistd.h> #include <errno.h> -#ifdef HAVE_VALGRIND -#include <valgrind.h> -#include <memcheck.h> -#define VG(x) x -#else -#define VG(x) -#endif - #define memclear(s) memset(&s, 0, sizeof(s)) #define U642VOID(x) ((void *)(unsigned long)(x)) @@ -476,19 +472,23 @@ drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id) /* * Connector manipulation */ - -drmModeConnectorPtr drmModeGetConnector(int fd, uint32_t connector_id) +static drmModeConnectorPtr +_drmModeGetConnector(int fd, uint32_t connector_id, int probe) { struct drm_mode_get_connector conn, counts; drmModeConnectorPtr r = NULL; -retry: memclear(conn); conn.connector_id = connector_id; + if (!probe) { + conn.count_modes = 1; + conn.modes_ptr = VOID2U64(drmMalloc(sizeof(struct drm_mode_modeinfo))); + } if (drmIoctl(fd, DRM_IOCTL_MODE_GETCONNECTOR, &conn)) return 0; +retry: counts = conn; if (conn.count_props) { @@ -504,6 +504,9 @@ retry: conn.modes_ptr = VOID2U64(drmMalloc(conn.count_modes*sizeof(struct drm_mode_modeinfo))); if (!conn.modes_ptr) goto err_allocs; + } else { + conn.count_modes = 1; + conn.modes_ptr = VOID2U64(drmMalloc(sizeof(struct drm_mode_modeinfo))); } if (conn.count_encoders) { @@ -572,6 +575,16 @@ err_allocs: return r; } +drmModeConnectorPtr drmModeGetConnector(int fd, uint32_t connector_id) +{ + return _drmModeGetConnector(fd, connector_id, 1); +} + +drmModeConnectorPtr drmModeGetConnectorCurrent(int fd, uint32_t connector_id) +{ + return _drmModeGetConnector(fd, connector_id, 0); +} + int drmModeAttachMode(int fd, uint32_t connector_id, drmModeModeInfoPtr mode_info) { struct drm_mode_mode_cmd res; @@ -1147,3 +1160,274 @@ int drmModeObjectSetProperty(int fd, uint32_t object_id, uint32_t object_type, return DRM_IOCTL(fd, DRM_IOCTL_MODE_OBJ_SETPROPERTY, &prop); } + +typedef struct _drmModeAtomicReqItem drmModeAtomicReqItem, *drmModeAtomicReqItemPtr; + +struct _drmModeAtomicReqItem { + uint32_t object_id; + uint32_t property_id; + uint64_t value; +}; + +struct _drmModeAtomicReq { + uint32_t cursor; + uint32_t size_items; + drmModeAtomicReqItemPtr items; +}; + +drmModeAtomicReqPtr drmModeAtomicAlloc(void) +{ + drmModeAtomicReqPtr req; + + req = drmMalloc(sizeof *req); + if (!req) + return NULL; + + req->items = NULL; + req->cursor = 0; + req->size_items = 0; + + return req; +} + +drmModeAtomicReqPtr drmModeAtomicDuplicate(drmModeAtomicReqPtr old) +{ + drmModeAtomicReqPtr new; + + new = drmMalloc(sizeof *new); + if (!new) + return NULL; + + new->cursor = old->cursor; + new->size_items = old->size_items; + + if (old->size_items) { + new->items = drmMalloc(old->size_items * sizeof(*new->items)); + if (!new->items) { + free(new); + return NULL; + } + memcpy(new->items, old->items, + old->size_items * sizeof(*new->items)); + } else { + new->items = NULL; + } + + return new; +} + +int drmModeAtomicMerge(drmModeAtomicReqPtr base, drmModeAtomicReqPtr augment) +{ + if (!augment || augment->cursor == 0) + return 0; + + if (base->cursor + augment->cursor >= base->size_items) { + drmModeAtomicReqItemPtr new; + int saved_size = base->size_items; + + base->size_items = base->cursor + augment->cursor; + new = realloc(base->items, + base->size_items * sizeof(*base->items)); + if (!new) { + base->size_items = saved_size; + return -ENOMEM; + } + base->items = new; + } + + memcpy(&base->items[base->cursor], augment->items, + augment->cursor * sizeof(*augment->items)); + base->cursor += augment->cursor; + + return 0; +} + +int drmModeAtomicGetCursor(drmModeAtomicReqPtr req) +{ + return req->cursor; +} + +void drmModeAtomicSetCursor(drmModeAtomicReqPtr req, int cursor) +{ + req->cursor = cursor; +} + +int drmModeAtomicAddProperty(drmModeAtomicReqPtr req, + uint32_t object_id, + uint32_t property_id, + uint64_t value) +{ + if (req->cursor >= req->size_items) { + drmModeAtomicReqItemPtr new; + + req->size_items += 16; + new = realloc(req->items, req->size_items * sizeof(*req->items)); + if (!new) { + req->size_items -= 16; + return -ENOMEM; + } + req->items = new; + } + + req->items[req->cursor].object_id = object_id; + req->items[req->cursor].property_id = property_id; + req->items[req->cursor].value = value; + req->cursor++; + + return req->cursor; +} + +void drmModeAtomicFree(drmModeAtomicReqPtr req) +{ + if (!req) + return; + + if (req->items) + drmFree(req->items); + drmFree(req); +} + +static int sort_req_list(const void *misc, const void *other) +{ + const drmModeAtomicReqItem *first = misc; + const drmModeAtomicReqItem *second = other; + + if (first->object_id < second->object_id) + return -1; + else if (first->object_id > second->object_id) + return 1; + else + return second->property_id - first->property_id; +} + +int drmModeAtomicCommit(int fd, drmModeAtomicReqPtr req, uint32_t flags, + void *user_data) +{ + drmModeAtomicReqPtr sorted = drmModeAtomicDuplicate(req); + struct drm_mode_atomic atomic; + uint32_t *objs_ptr = NULL; + uint32_t *count_props_ptr = NULL; + uint32_t *props_ptr = NULL; + uint64_t *prop_values_ptr = NULL; + uint32_t last_obj_id = 0; + uint32_t i; + int obj_idx = -1; + int ret = -1; + + if (!sorted) + return -ENOMEM; + + memclear(atomic); + + /* Sort the list by object ID, then by property ID. */ + qsort(sorted->items, sorted->cursor, sizeof(*sorted->items), + sort_req_list); + + /* Now the list is sorted, eliminate duplicate property sets. */ + for (i = 0; i < sorted->cursor; i++) { + if (sorted->items[i].object_id != last_obj_id) { + atomic.count_objs++; + last_obj_id = sorted->items[i].object_id; + } + + if (i == sorted->cursor - 1) + continue; + + if (sorted->items[i].object_id != sorted->items[i + 1].object_id || + sorted->items[i].property_id != sorted->items[i + 1].property_id) + continue; + + memmove(&sorted->items[i], &sorted->items[i + 1], + (sorted->cursor - i - 1) * sizeof(*sorted->items)); + sorted->cursor--; + } + + objs_ptr = drmMalloc(atomic.count_objs * sizeof objs_ptr[0]); + if (!objs_ptr) { + errno = ENOMEM; + goto out; + } + + count_props_ptr = drmMalloc(atomic.count_objs * sizeof count_props_ptr[0]); + if (!count_props_ptr) { + errno = ENOMEM; + goto out; + } + + props_ptr = drmMalloc(sorted->cursor * sizeof props_ptr[0]); + if (!props_ptr) { + errno = ENOMEM; + goto out; + } + + prop_values_ptr = drmMalloc(sorted->cursor * sizeof prop_values_ptr[0]); + if (!prop_values_ptr) { + errno = ENOMEM; + goto out; + } + + for (i = 0, last_obj_id = 0; i < sorted->cursor; i++) { + if (sorted->items[i].object_id != last_obj_id) { + obj_idx++; + objs_ptr[obj_idx] = sorted->items[i].object_id; + last_obj_id = objs_ptr[obj_idx]; + } + + count_props_ptr[obj_idx]++; + props_ptr[i] = sorted->items[i].property_id; + prop_values_ptr[i] = sorted->items[i].value; + + } + + atomic.flags = flags; + atomic.objs_ptr = VOID2U64(objs_ptr); + atomic.count_props_ptr = VOID2U64(count_props_ptr); + atomic.props_ptr = VOID2U64(props_ptr); + atomic.prop_values_ptr = VOID2U64(prop_values_ptr); + atomic.user_data = VOID2U64(user_data); + + ret = DRM_IOCTL(fd, DRM_IOCTL_MODE_ATOMIC, &atomic); + +out: + drmFree(objs_ptr); + drmFree(count_props_ptr); + drmFree(props_ptr); + drmFree(prop_values_ptr); + drmModeAtomicFree(sorted); + + return ret; +} + +int +drmModeCreatePropertyBlob(int fd, const void *data, size_t length, uint32_t *id) +{ + struct drm_mode_create_blob create; + int ret; + + if (length >= 0xffffffff) + return -ERANGE; + + memclear(create); + + create.length = length; + create.data = (uintptr_t) data; + create.blob_id = 0; + *id = 0; + + ret = DRM_IOCTL(fd, DRM_IOCTL_MODE_CREATEPROPBLOB, &create); + if (ret != 0) + return ret; + + *id = create.blob_id; + return 0; +} + +int +drmModeDestroyPropertyBlob(int fd, uint32_t id) +{ + struct drm_mode_destroy_blob destroy; + + memclear(destroy); + destroy.blob_id = id; + return DRM_IOCTL(fd, DRM_IOCTL_MODE_DESTROYPROPBLOB, &destroy); +} diff --git a/lib/libdrm/xf86drmMode.h b/lib/libdrm/xf86drmMode.h index 856a6bb0f..1c10023c7 100644 --- a/lib/libdrm/xf86drmMode.h +++ b/lib/libdrm/xf86drmMode.h @@ -240,7 +240,7 @@ typedef struct _drmModeProperty { uint32_t *blob_ids; /* store the blob IDs */ } drmModePropertyRes, *drmModePropertyPtr; -static inline int drm_property_type_is(drmModePropertyPtr property, +static __inline int drm_property_type_is(drmModePropertyPtr property, uint32_t type) { /* instanceof for props.. handles extended type vs original types: */ @@ -422,10 +422,23 @@ drmModeEncoderPtr drmModeGetEncoder(int fd, uint32_t encoder_id); */ /** - * Retrive information about the connector connectorId. + * Retrieve all information about the connector connectorId. This will do a + * forced probe on the connector to retrieve remote information such as EDIDs + * from the display device. */ extern drmModeConnectorPtr drmModeGetConnector(int fd, - uint32_t connectorId); + uint32_t connectorId); + +/** + * Retrieve current information, i.e the currently active mode and encoder, + * about the connector connectorId. This will not do any probing on the + * connector or remote device, and only reports what is currently known. + * For the complete set of modes and encoders associated with the connector + * use drmModeGetConnector() which will do a probe to determine any display + * link changes first. + */ +extern drmModeConnectorPtr drmModeGetConnectorCurrent(int fd, + uint32_t connector_id); /** * Attaches the given mode to an connector. @@ -471,6 +484,30 @@ extern int drmModeObjectSetProperty(int fd, uint32_t object_id, uint32_t object_type, uint32_t property_id, uint64_t value); + +typedef struct _drmModeAtomicReq drmModeAtomicReq, *drmModeAtomicReqPtr; + +extern drmModeAtomicReqPtr drmModeAtomicAlloc(void); +extern drmModeAtomicReqPtr drmModeAtomicDuplicate(drmModeAtomicReqPtr req); +extern int drmModeAtomicMerge(drmModeAtomicReqPtr base, + drmModeAtomicReqPtr augment); +extern void drmModeAtomicFree(drmModeAtomicReqPtr req); +extern int drmModeAtomicGetCursor(drmModeAtomicReqPtr req); +extern void drmModeAtomicSetCursor(drmModeAtomicReqPtr req, int cursor); +extern int drmModeAtomicAddProperty(drmModeAtomicReqPtr req, + uint32_t object_id, + uint32_t property_id, + uint64_t value); +extern int drmModeAtomicCommit(int fd, + drmModeAtomicReqPtr req, + uint32_t flags, + void *user_data); + +extern int drmModeCreatePropertyBlob(int fd, const void *data, size_t size, + uint32_t *id); +extern int drmModeDestroyPropertyBlob(int fd, uint32_t id); + + #if defined(__cplusplus) || defined(c_plusplus) } #endif diff --git a/lib/libdrm/xf86drmRandom.c b/lib/libdrm/xf86drmRandom.c index 94922ad7e..81f03014f 100644 --- a/lib/libdrm/xf86drmRandom.c +++ b/lib/libdrm/xf86drmRandom.c @@ -74,45 +74,16 @@ #include <stdio.h> #include <stdlib.h> -#define RANDOM_MAIN 0 - -#if !RANDOM_MAIN -# include "xf86drm.h" -#endif +#include "xf86drm.h" +#include "xf86drmRandom.h" #define RANDOM_MAGIC 0xfeedbeef -#define RANDOM_DEBUG 0 - -#if RANDOM_MAIN -#define RANDOM_ALLOC malloc -#define RANDOM_FREE free -#else -#define RANDOM_ALLOC drmMalloc -#define RANDOM_FREE drmFree -#endif - -typedef struct RandomState { - unsigned long magic; - unsigned long a; - unsigned long m; - unsigned long q; /* m div a */ - unsigned long r; /* m mod a */ - unsigned long check; - unsigned long seed; -} RandomState; - -#if RANDOM_MAIN -extern void *drmRandomCreate(unsigned long seed); -extern int drmRandomDestroy(void *state); -extern unsigned long drmRandom(void *state); -extern double drmRandomDouble(void *state); -#endif void *drmRandomCreate(unsigned long seed) { RandomState *state; - state = RANDOM_ALLOC(sizeof(*state)); + state = drmMalloc(sizeof(*state)); if (!state) return NULL; state->magic = RANDOM_MAGIC; #if 0 @@ -140,7 +111,7 @@ void *drmRandomCreate(unsigned long seed) int drmRandomDestroy(void *state) { - RANDOM_FREE(state); + drmFree(state); return 0; } @@ -164,45 +135,3 @@ double drmRandomDouble(void *state) return (double)drmRandom(state)/(double)s->m; } - -#if RANDOM_MAIN -static void check_period(unsigned long seed) -{ - unsigned long count = 0; - unsigned long initial; - void *state; - - state = drmRandomCreate(seed); - initial = drmRandom(state); - ++count; - while (initial != drmRandom(state)) { - if (!++count) break; - } - printf("With seed of %10lu, period = %10lu (0x%08lx)\n", - seed, count, count); - drmRandomDestroy(state); -} - -int main(void) -{ - RandomState *state; - int i; - unsigned long rand; - - state = drmRandomCreate(1); - for (i = 0; i < 10000; i++) { - rand = drmRandom(state); - } - printf("After 10000 iterations: %lu (%lu expected): %s\n", - rand, state->check, - rand - state->check ? "*INCORRECT*" : "CORRECT"); - drmRandomDestroy(state); - - printf("Checking periods...\n"); - check_period(1); - check_period(2); - check_period(31415926); - - return 0; -} -#endif diff --git a/lib/libdrm/xf86drmRandom.h b/lib/libdrm/xf86drmRandom.h new file mode 100644 index 000000000..43b730ce0 --- /dev/null +++ b/lib/libdrm/xf86drmRandom.h @@ -0,0 +1,35 @@ +/* + * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. + * 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, sublicense, + * 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 above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * 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 NONINFRINGEMENT. IN NO EVENT SHALL + * PRECISION INSIGHT 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. + * + * Authors: Rickard E. (Rik) Faith <faith@valinux.com> + */ + +typedef struct RandomState { + unsigned long magic; + unsigned long a; + unsigned long m; + unsigned long q; /* m div a */ + unsigned long r; /* m mod a */ + unsigned long check; + unsigned long seed; +} RandomState; diff --git a/lib/libdrm/xf86drmSL.c b/lib/libdrm/xf86drmSL.c index acddb5411..a12fa1d00 100644 --- a/lib/libdrm/xf86drmSL.c +++ b/lib/libdrm/xf86drmSL.c @@ -41,36 +41,18 @@ #include <stdio.h> #include <stdlib.h> -#define SL_MAIN 0 - -#if !SL_MAIN -# include "xf86drm.h" -#else -# include <sys/time.h> -#endif +#include "xf86drm.h" #define SL_LIST_MAGIC 0xfacade00LU #define SL_ENTRY_MAGIC 0x00fab1edLU #define SL_FREED_MAGIC 0xdecea5edLU #define SL_MAX_LEVEL 16 -#define SL_DEBUG 0 #define SL_RANDOM_SEED 0xc01055a1LU -#if SL_MAIN -#define SL_ALLOC malloc -#define SL_FREE free -#define SL_RANDOM_DECL static int state = 0; -#define SL_RANDOM_INIT(seed) if (!state) { srandom(seed); ++state; } -#define SL_RANDOM random() -#else -#define SL_ALLOC drmMalloc -#define SL_FREE drmFree #define SL_RANDOM_DECL static void *state = NULL #define SL_RANDOM_INIT(seed) if (!state) state = drmRandomCreate(seed) #define SL_RANDOM drmRandom(state) -#endif - typedef struct SLEntry { unsigned long magic; /* SL_ENTRY_MAGIC */ unsigned long key; @@ -87,27 +69,13 @@ typedef struct SkipList { SLEntryPtr p0; /* Position for iteration */ } SkipList, *SkipListPtr; -#if SL_MAIN -extern void *drmSLCreate(void); -extern int drmSLDestroy(void *l); -extern int drmSLLookup(void *l, unsigned long key, void **value); -extern int drmSLInsert(void *l, unsigned long key, void *value); -extern int drmSLDelete(void *l, unsigned long key); -extern int drmSLNext(void *l, unsigned long *key, void **value); -extern int drmSLFirst(void *l, unsigned long *key, void **value); -extern void drmSLDump(void *l); -extern int drmSLLookupNeighbors(void *l, unsigned long key, - unsigned long *prev_key, void **prev_value, - unsigned long *next_key, void **next_value); -#endif - static SLEntryPtr SLCreateEntry(int max_level, unsigned long key, void *value) { SLEntryPtr entry; if (max_level < 0 || max_level > SL_MAX_LEVEL) max_level = SL_MAX_LEVEL; - entry = SL_ALLOC(sizeof(*entry) + entry = drmMalloc(sizeof(*entry) + (max_level + 1) * sizeof(entry->forward[0])); if (!entry) return NULL; entry->magic = SL_ENTRY_MAGIC; @@ -134,7 +102,7 @@ void *drmSLCreate(void) SkipListPtr list; int i; - list = SL_ALLOC(sizeof(*list)); + list = drmMalloc(sizeof(*list)); if (!list) return NULL; list->magic = SL_LIST_MAGIC; list->level = 0; @@ -158,11 +126,11 @@ int drmSLDestroy(void *l) if (entry->magic != SL_ENTRY_MAGIC) return -1; /* Bad magic */ next = entry->forward[0]; entry->magic = SL_FREED_MAGIC; - SL_FREE(entry); + drmFree(entry); } list->magic = SL_FREED_MAGIC; - SL_FREE(list); + drmFree(list); return 0; } @@ -236,7 +204,7 @@ int drmSLDelete(void *l, unsigned long key) } entry->magic = SL_FREED_MAGIC; - SL_FREE(entry); + drmFree(entry); while (list->level && !list->head->forward[list->level]) --list->level; --list->count; @@ -264,12 +232,14 @@ int drmSLLookupNeighbors(void *l, unsigned long key, unsigned long *next_key, void **next_value) { SkipListPtr list = (SkipListPtr)l; - SLEntryPtr update[SL_MAX_LEVEL + 1]; + SLEntryPtr update[SL_MAX_LEVEL + 1] = {0}; int retcode = 0; + SLLocate(list, key, update); + *prev_key = *next_key = key; *prev_value = *next_value = NULL; - + if (update[0]) { *prev_key = update[0]->key; *prev_value = update[0]->value; @@ -346,132 +316,3 @@ void drmSLDump(void *l) } } } - -#if SL_MAIN -static void print(SkipListPtr list) -{ - unsigned long key; - void *value; - - if (drmSLFirst(list, &key, &value)) { - do { - printf("key = %5lu, value = %p\n", key, value); - } while (drmSLNext(list, &key, &value)); - } -} - -static double do_time(int size, int iter) -{ - SkipListPtr list; - int i, j; - unsigned long keys[1000000]; - unsigned long previous; - unsigned long key; - void *value; - struct timeval start, stop; - double usec; - SL_RANDOM_DECL; - - SL_RANDOM_INIT(12345); - - list = drmSLCreate(); - - for (i = 0; i < size; i++) { - keys[i] = SL_RANDOM; - drmSLInsert(list, keys[i], NULL); - } - - previous = 0; - if (drmSLFirst(list, &key, &value)) { - do { - if (key <= previous) { - printf( "%lu !< %lu\n", previous, key); - } - previous = key; - } while (drmSLNext(list, &key, &value)); - } - - gettimeofday(&start, NULL); - for (j = 0; j < iter; j++) { - for (i = 0; i < size; i++) { - if (drmSLLookup(list, keys[i], &value)) - printf("Error %lu %d\n", keys[i], i); - } - } - gettimeofday(&stop, NULL); - - usec = (double)(stop.tv_sec * 1000000 + stop.tv_usec - - start.tv_sec * 1000000 - start.tv_usec) / (size * iter); - - printf("%0.2f microseconds for list length %d\n", usec, size); - - drmSLDestroy(list); - - return usec; -} - -static void print_neighbors(void *list, unsigned long key) -{ - unsigned long prev_key = 0; - unsigned long next_key = 0; - void *prev_value; - void *next_value; - int retval; - - retval = drmSLLookupNeighbors(list, key, - &prev_key, &prev_value, - &next_key, &next_value); - printf("Neighbors of %5lu: %d %5lu %5lu\n", - key, retval, prev_key, next_key); -} - -int main(void) -{ - SkipListPtr list; - double usec, usec2, usec3, usec4; - - list = drmSLCreate(); - printf( "list at %p\n", list); - - print(list); - printf("\n==============================\n\n"); - - drmSLInsert(list, 123, NULL); - drmSLInsert(list, 213, NULL); - drmSLInsert(list, 50, NULL); - print(list); - printf("\n==============================\n\n"); - - print_neighbors(list, 0); - print_neighbors(list, 50); - print_neighbors(list, 51); - print_neighbors(list, 123); - print_neighbors(list, 200); - print_neighbors(list, 213); - print_neighbors(list, 256); - printf("\n==============================\n\n"); - - drmSLDelete(list, 50); - print(list); - printf("\n==============================\n\n"); - - drmSLDump(list); - drmSLDestroy(list); - printf("\n==============================\n\n"); - - usec = do_time(100, 10000); - usec2 = do_time(1000, 500); - printf("Table size increased by %0.2f, search time increased by %0.2f\n", - 1000.0/100.0, usec2 / usec); - - usec3 = do_time(10000, 50); - printf("Table size increased by %0.2f, search time increased by %0.2f\n", - 10000.0/100.0, usec3 / usec); - - usec4 = do_time(100000, 4); - printf("Table size increased by %0.2f, search time increased by %0.2f\n", - 100000.0/100.0, usec4 / usec); - - return 0; -} -#endif |