#define VG_DEFINED(ptr, size) VG(VALGRIND_MAKE_MEM_DEFINED(ptr, size))
#define VG_NOACCESS(ptr, size) VG(VALGRIND_MAKE_MEM_NOACCESS(ptr, size))
-#define memclear(s) memset(&s, 0, sizeof(s))
-
#define PAGE_SIZE 4096
#define FILE_DEBUG_FLAG DEBUG_BUFMGR
brw_bo_busy(struct brw_bo *bo)
{
struct brw_bufmgr *bufmgr = bo->bufmgr;
- struct drm_i915_gem_busy busy;
- int ret;
+ struct drm_i915_gem_busy busy = { .handle = bo->gem_handle };
- memclear(busy);
- busy.handle = bo->gem_handle;
-
- ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_BUSY, &busy);
+ int ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_BUSY, &busy);
if (ret == 0) {
bo->idle = !busy.busy;
return busy.busy;
int
brw_bo_madvise(struct brw_bo *bo, int state)
{
- struct drm_i915_gem_madvise madv;
+ struct drm_i915_gem_madvise madv = {
+ .handle = bo->gem_handle,
+ .madv = state,
+ .retained = 1,
+ };
- memclear(madv);
- madv.handle = bo->gem_handle;
- madv.madv = state;
- madv.retained = 1;
drmIoctl(bo->bufmgr->fd, DRM_IOCTL_I915_GEM_MADVISE, &madv);
return madv.retained;
}
if (!alloc_from_cache) {
- struct drm_i915_gem_create create;
-
bo = calloc(1, sizeof(*bo));
if (!bo)
goto err;
bo->size = bo_size;
bo->idle = true;
- memclear(create);
- create.size = bo_size;
+ struct drm_i915_gem_create create = { .size = bo_size };
/* All new BOs we get from the kernel are zeroed, so we don't need to
* worry about that here.
const char *name, unsigned int handle)
{
struct brw_bo *bo;
- int ret;
- struct drm_gem_open open_arg;
- struct drm_i915_gem_get_tiling get_tiling;
/* At the moment most applications only have a few named bo.
* For instance, in a DRI client only the render buffers passed
goto out;
}
- memclear(open_arg);
- open_arg.name = handle;
- ret = drmIoctl(bufmgr->fd, DRM_IOCTL_GEM_OPEN, &open_arg);
+ struct drm_gem_open open_arg = { .name = handle };
+ int ret = drmIoctl(bufmgr->fd, DRM_IOCTL_GEM_OPEN, &open_arg);
if (ret != 0) {
DBG("Couldn't reference %s handle 0x%08x: %s\n",
name, handle, strerror(errno));
_mesa_hash_table_insert(bufmgr->handle_table, &bo->gem_handle, bo);
_mesa_hash_table_insert(bufmgr->name_table, &bo->global_name, bo);
- memclear(get_tiling);
- get_tiling.handle = bo->gem_handle;
+ struct drm_i915_gem_get_tiling get_tiling = { .handle = bo->gem_handle };
ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_GET_TILING, &get_tiling);
if (ret != 0)
goto err_unref;
bo_free(struct brw_bo *bo)
{
struct brw_bufmgr *bufmgr = bo->bufmgr;
- struct drm_gem_close close;
- int ret;
if (bo->map_cpu) {
VG_NOACCESS(bo->map_cpu, bo->size);
}
/* Close this object */
- memclear(close);
- close.handle = bo->gem_handle;
- ret = drmIoctl(bufmgr->fd, DRM_IOCTL_GEM_CLOSE, &close);
+ struct drm_gem_close close = { .handle = bo->gem_handle };
+ int ret = drmIoctl(bufmgr->fd, DRM_IOCTL_GEM_CLOSE, &close);
if (ret != 0) {
DBG("DRM_IOCTL_GEM_CLOSE %d failed (%s): %s\n",
bo->gem_handle, bo->name, strerror(errno));
assert(bo->cache_coherent || !(flags & MAP_WRITE));
if (!bo->map_cpu) {
- struct drm_i915_gem_mmap mmap_arg;
- void *map;
-
DBG("brw_bo_map_cpu: %d (%s)\n", bo->gem_handle, bo->name);
- memclear(mmap_arg);
- mmap_arg.handle = bo->gem_handle;
- mmap_arg.size = bo->size;
+ struct drm_i915_gem_mmap mmap_arg = {
+ .handle = bo->gem_handle,
+ .size = bo->size,
+ };
int ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg);
if (ret != 0) {
ret = -errno;
__FILE__, __LINE__, bo->gem_handle, bo->name, strerror(errno));
return NULL;
}
- map = (void *) (uintptr_t) mmap_arg.addr_ptr;
+ void *map = (void *) (uintptr_t) mmap_arg.addr_ptr;
VG_DEFINED(map, bo->size);
if (p_atomic_cmpxchg(&bo->map_cpu, NULL, map)) {
return NULL;
if (!bo->map_wc) {
- struct drm_i915_gem_mmap mmap_arg;
- void *map;
-
DBG("brw_bo_map_wc: %d (%s)\n", bo->gem_handle, bo->name);
- memclear(mmap_arg);
- mmap_arg.handle = bo->gem_handle;
- mmap_arg.size = bo->size;
- mmap_arg.flags = I915_MMAP_WC;
+ struct drm_i915_gem_mmap mmap_arg = {
+ .handle = bo->gem_handle,
+ .size = bo->size,
+ .flags = I915_MMAP_WC,
+ };
int ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg);
if (ret != 0) {
ret = -errno;
return NULL;
}
- map = (void *) (uintptr_t) mmap_arg.addr_ptr;
+ void *map = (void *) (uintptr_t) mmap_arg.addr_ptr;
VG_DEFINED(map, bo->size);
if (p_atomic_cmpxchg(&bo->map_wc, NULL, map)) {
/* Get a mapping of the buffer if we haven't before. */
if (bo->map_gtt == NULL) {
- struct drm_i915_gem_mmap_gtt mmap_arg;
- void *map;
-
DBG("bo_map_gtt: mmap %d (%s)\n", bo->gem_handle, bo->name);
- memclear(mmap_arg);
- mmap_arg.handle = bo->gem_handle;
+ struct drm_i915_gem_mmap_gtt mmap_arg = { .handle = bo->gem_handle };
/* Get the fake offset back... */
int ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg);
}
/* and mmap it. */
- map = drm_mmap(0, bo->size, PROT_READ | PROT_WRITE,
- MAP_SHARED, bufmgr->fd, mmap_arg.offset);
+ void *map = drm_mmap(0, bo->size, PROT_READ | PROT_WRITE,
+ MAP_SHARED, bufmgr->fd, mmap_arg.offset);
if (map == MAP_FAILED) {
DBG("%s:%d: Error mapping buffer %d (%s): %s .\n",
__FILE__, __LINE__, bo->gem_handle, bo->name, strerror(errno));
uint64_t size, const void *data)
{
struct brw_bufmgr *bufmgr = bo->bufmgr;
- struct drm_i915_gem_pwrite pwrite;
- int ret;
- memclear(pwrite);
- pwrite.handle = bo->gem_handle;
- pwrite.offset = offset;
- pwrite.size = size;
- pwrite.data_ptr = (uint64_t) (uintptr_t) data;
- ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_PWRITE, &pwrite);
+ struct drm_i915_gem_pwrite pwrite = {
+ .handle = bo->gem_handle,
+ .offset = offset,
+ .size = size,
+ .data_ptr = (uint64_t) (uintptr_t) data,
+ };
+
+ int ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_PWRITE, &pwrite);
if (ret != 0) {
ret = -errno;
DBG("%s:%d: Error writing data to buffer %d: "
brw_bo_wait(struct brw_bo *bo, int64_t timeout_ns)
{
struct brw_bufmgr *bufmgr = bo->bufmgr;
- struct drm_i915_gem_wait wait;
- int ret;
/* If we know it's idle, don't bother with the kernel round trip */
if (bo->idle && !bo->external)
return 0;
- memclear(wait);
- wait.bo_handle = bo->gem_handle;
- wait.timeout_ns = timeout_ns;
- ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_WAIT, &wait);
+ struct drm_i915_gem_wait wait = {
+ .bo_handle = bo->gem_handle,
+ .timeout_ns = timeout_ns,
+ };
+ int ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_WAIT, &wait);
if (ret == -1)
return -errno;
struct brw_bo *
brw_bo_gem_create_from_prime(struct brw_bufmgr *bufmgr, int prime_fd)
{
- int ret;
uint32_t handle;
struct brw_bo *bo;
- struct drm_i915_gem_get_tiling get_tiling;
mtx_lock(&bufmgr->lock);
- ret = drmPrimeFDToHandle(bufmgr->fd, prime_fd, &handle);
+ int ret = drmPrimeFDToHandle(bufmgr->fd, prime_fd, &handle);
if (ret) {
DBG("create_from_prime: failed to obtain handle from fd: %s\n",
strerror(errno));
bo->reusable = false;
bo->external = true;
- memclear(get_tiling);
- get_tiling.handle = bo->gem_handle;
+ struct drm_i915_gem_get_tiling get_tiling = { .handle = bo->gem_handle };
if (drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_GET_TILING, &get_tiling))
goto err;
struct brw_bufmgr *bufmgr = bo->bufmgr;
if (!bo->global_name) {
- struct drm_gem_flink flink;
+ struct drm_gem_flink flink = { .handle = bo->gem_handle };
- memclear(flink);
- flink.handle = bo->gem_handle;
if (drmIoctl(bufmgr->fd, DRM_IOCTL_GEM_FLINK, &flink))
return -errno;
uint32_t
brw_create_hw_context(struct brw_bufmgr *bufmgr)
{
- struct drm_i915_gem_context_create create;
- int ret;
-
- memclear(create);
- ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create);
+ struct drm_i915_gem_context_create create = { };
+ int ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create);
if (ret != 0) {
DBG("DRM_IOCTL_I915_GEM_CONTEXT_CREATE failed: %s\n", strerror(errno));
return 0;
void
brw_destroy_hw_context(struct brw_bufmgr *bufmgr, uint32_t ctx_id)
{
- struct drm_i915_gem_context_destroy d = {.ctx_id = ctx_id };
+ struct drm_i915_gem_context_destroy d = { .ctx_id = ctx_id };
if (ctx_id != 0 &&
drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_DESTROY, &d) != 0) {
int
brw_reg_read(struct brw_bufmgr *bufmgr, uint32_t offset, uint64_t *result)
{
- struct drm_i915_reg_read reg_read;
- int ret;
-
- memclear(reg_read);
- reg_read.offset = offset;
-
- ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_REG_READ, ®_read);
+ struct drm_i915_reg_read reg_read = { .offset = offset };
+ int ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_REG_READ, ®_read);
*result = reg_read.val;
return ret;
static int
gem_param(int fd, int name)
{
- drm_i915_getparam_t gp;
int v = -1; /* No param uses (yet) the sign bit, reserve it for errors */
- memset(&gp, 0, sizeof(gp));
- gp.param = name;
- gp.value = &v;
+ struct drm_i915_getparam gp = { .param = name, .value = &v };
if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp))
return -1;