Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk> --- lib/drmtest.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/drmtest.h | 3 +++ 2 files changed, 55 insertions(+) diff --git a/lib/drmtest.c b/lib/drmtest.c index 871c1d0..66f2887 100644 --- a/lib/drmtest.c +++ b/lib/drmtest.c @@ -252,6 +252,58 @@ void gem_set_tiling(int fd, uint32_t handle, int tiling, int stride) assert(st.tiling_mode == tiling); } +struct local_drm_i915_gem_cacheing { + uint32_t handle; + uint32_t cacheing; +}; + +#define LOCAL_DRM_I915_GEM_SET_CACHEING 0x2f +#define LOCAL_DRM_I915_GEM_GET_CACHEING 0x30 +#define LOCAL_DRM_IOCTL_I915_GEM_SET_CACHEING \ + DRM_IOW(DRM_COMMAND_BASE + LOCAL_DRM_I915_GEM_SET_CACHEING, struct local_drm_i915_gem_cacheing) +#define LOCAL_DRM_IOCTL_I915_GEM_GET_CACHEING \ + DRM_IOWR(DRM_COMMAND_BASE + LOCAL_DRM_I915_GEM_GET_CACHEING, struct local_drm_i915_gem_cacheing) + +int gem_has_cacheing(int fd) +{ + struct local_drm_i915_gem_cacheing arg; + int ret; + + arg.handle = gem_create(fd, 4096); + if (arg.handle == 0) + return 0; + + arg.cacheing = 0; + ret = ioctl(fd, LOCAL_DRM_IOCTL_I915_GEM_SET_CACHEING, &arg); + gem_close(fd, arg.handle); + + return ret == 0; +} + +void gem_set_cacheing(int fd, uint32_t handle, int cacheing) +{ + struct local_drm_i915_gem_cacheing arg; + int ret; + + arg.handle = handle; + arg.cacheing = cacheing; + ret = ioctl(fd, LOCAL_DRM_IOCTL_I915_GEM_SET_CACHEING, &arg); + assert(ret == 0); +} + +int gem_get_cacheing(int fd, uint32_t handle) +{ + struct local_drm_i915_gem_cacheing arg; + int ret; + + arg.handle = handle; + arg.cacheing = 0; + ret = ioctl(fd, LOCAL_DRM_IOCTL_I915_GEM_GET_CACHEING, &arg); + assert(ret == 0); + + return arg.cacheing; +} + void gem_close(int fd, uint32_t handle) { struct drm_gem_close close_bo; diff --git a/lib/drmtest.h b/lib/drmtest.h index 4021104..0208559 100644 --- a/lib/drmtest.h +++ b/lib/drmtest.h @@ -45,6 +45,9 @@ void gem_quiescent_gpu(int fd); /* ioctl wrappers and similar stuff for bare metal testing */ void gem_set_tiling(int fd, uint32_t handle, int tiling, int stride); +int gem_has_cacheing(int fd); +void gem_set_cacheing(int fd, uint32_t handle, int cacheing); +int gem_get_cacheing(int fd, uint32_t handle); void gem_close(int fd, uint32_t handle); void gem_write(int fd, uint32_t handle, uint32_t offset, const void *buf, uint32_t size); void gem_read(int fd, uint32_t handle, uint32_t offset, void *buf, uint32_t size); -- 1.7.10.4