diff options
author | Chia-I Wu <[email protected]> | 2013-06-12 16:56:49 +0800 |
---|---|---|
committer | Chia-I Wu <[email protected]> | 2013-06-12 17:46:52 +0800 |
commit | e7a14eea1616e597215f037708a56f8ad5850815 (patch) | |
tree | bcc2fc72b42c661716e44c4fba1b5a2ff9314625 /src/gallium/winsys | |
parent | 39226705b7ee79504b5b09669e5420cd7c374713 (diff) |
winsys/intel: reorganize functions
Move functions around to match the order of the declarations in the header.
Diffstat (limited to 'src/gallium/winsys')
-rw-r--r-- | src/gallium/winsys/intel/drm/intel_drm_winsys.c | 498 |
1 files changed, 249 insertions, 249 deletions
diff --git a/src/gallium/winsys/intel/drm/intel_drm_winsys.c b/src/gallium/winsys/intel/drm/intel_drm_winsys.c index d44113873cb..f4e8bd4e080 100644 --- a/src/gallium/winsys/intel/drm/intel_drm_winsys.c +++ b/src/gallium/winsys/intel/drm/intel_drm_winsys.c @@ -61,177 +61,144 @@ struct intel_bo { drm_intel_bo *bo; }; -int -intel_winsys_export_handle(struct intel_winsys *winsys, - struct intel_bo *bo, - enum intel_tiling_mode tiling, - unsigned long pitch, - struct winsys_handle *handle) +static bool +get_param(struct intel_winsys *winsys, int param, int *value) { - int err = 0; + struct drm_i915_getparam gp; + int err; - switch (handle->type) { - case DRM_API_HANDLE_TYPE_SHARED: - { - uint32_t name; + *value = 0; - err = drm_intel_bo_flink(bo->bo, &name); - if (!err) - handle->handle = name; - } - break; - case DRM_API_HANDLE_TYPE_KMS: - handle->handle = bo->bo->handle; - break; -#if 0 - case DRM_API_HANDLE_TYPE_PRIME: - { - int fd; + memset(&gp, 0, sizeof(gp)); + gp.param = param; + gp.value = value; - err = drm_intel_bo_gem_export_to_prime(bo->bo, &fd); - if (!err) - handle->handle = fd; - } -#endif - break; - default: - err = -EINVAL; - break; + err = drmCommandWriteRead(winsys->fd, DRM_I915_GETPARAM, &gp, sizeof(gp)); + if (err) { + *value = 0; + return false; } - if (err) - return err; - - handle->stride = pitch; - - return 0; + return true; } -int -intel_bo_exec(struct intel_bo *bo, int used, - struct intel_context *ctx, unsigned long flags) +static bool +test_address_swizzling(struct intel_winsys *winsys) { - if (ctx) { - return drm_intel_gem_bo_context_exec(bo->bo, - (drm_intel_context *) ctx, used, flags); + drm_intel_bo *bo; + uint32_t tiling = I915_TILING_X, swizzle; + unsigned long pitch; + + bo = drm_intel_bo_alloc_tiled(winsys->bufmgr, + "address swizzling test", 64, 64, 4, &tiling, &pitch, 0); + if (bo) { + drm_intel_bo_get_tiling(bo, &tiling, &swizzle); + drm_intel_bo_unreference(bo); } else { - return drm_intel_bo_mrb_exec(bo->bo, used, NULL, 0, 0, flags); + swizzle = I915_BIT_6_SWIZZLE_NONE; } + + return (swizzle != I915_BIT_6_SWIZZLE_NONE); } -int -intel_bo_wait(struct intel_bo *bo, int64_t timeout) +static bool +init_info(struct intel_winsys *winsys) { - int err; + struct intel_winsys_info *info = &winsys->info; + int val; - err = drm_intel_gem_bo_wait(bo->bo, timeout); - /* consider the bo idle on errors */ - if (err && err != -ETIME) - err = 0; + /* follow the classic driver here */ + get_param(winsys, I915_PARAM_HAS_RELAXED_DELTA, &val); + if (!val) { + debug_error("kernel 2.6.39 required"); + return false; + } - return err; -} + info->devid = drm_intel_bufmgr_gem_get_devid(winsys->bufmgr); -int -intel_bo_emit_reloc(struct intel_bo *bo, uint32_t offset, - struct intel_bo *target_bo, uint32_t target_offset, - uint32_t read_domains, uint32_t write_domain) -{ - return drm_intel_bo_emit_reloc(bo->bo, offset, - target_bo->bo, target_offset, read_domains, write_domain); -} + get_param(winsys, I915_PARAM_HAS_LLC, &val); + info->has_llc = val; -int -intel_bo_get_reloc_count(struct intel_bo *bo) -{ - return drm_intel_gem_bo_get_reloc_count(bo->bo); -} + get_param(winsys, I915_PARAM_HAS_GEN7_SOL_RESET, &val); + info->has_gen7_sol_reset = val; -void -intel_bo_clear_relocs(struct intel_bo *bo, int start) -{ - return drm_intel_gem_bo_clear_relocs(bo->bo, start); -} + info->has_address_swizzling = test_address_swizzling(winsys); -bool -intel_bo_references(struct intel_bo *bo, struct intel_bo *target_bo) -{ - return drm_intel_bo_references(bo->bo, target_bo->bo); + return true; } -int -intel_bo_map(struct intel_bo *bo, bool write_enable) +struct intel_winsys * +intel_winsys_create_for_fd(int fd) { - return drm_intel_bo_map(bo->bo, write_enable); -} + struct intel_winsys *winsys; -int -intel_bo_map_gtt(struct intel_bo *bo) -{ - return drm_intel_gem_bo_map_gtt(bo->bo); -} + winsys = CALLOC_STRUCT(intel_winsys); + if (!winsys) + return NULL; -int -intel_bo_map_unsynchronized(struct intel_bo *bo) -{ - return drm_intel_gem_bo_map_unsynchronized(bo->bo); -} + winsys->fd = fd; -void -intel_bo_unmap(struct intel_bo *bo) -{ - int err; + winsys->bufmgr = drm_intel_bufmgr_gem_init(winsys->fd, BATCH_SZ); + if (!winsys->bufmgr) { + debug_error("failed to create GEM buffer manager"); + FREE(winsys); + return NULL; + } - err = drm_intel_bo_unmap(bo->bo); - assert(!err); -} + if (!init_info(winsys)) { + drm_intel_bufmgr_destroy(winsys->bufmgr); + FREE(winsys); + return NULL; + } -int -intel_bo_pwrite(struct intel_bo *bo, unsigned long offset, - unsigned long size, const void *data) -{ - return drm_intel_bo_subdata(bo->bo, offset, size, data); + drm_intel_bufmgr_gem_enable_fenced_relocs(winsys->bufmgr); + + return winsys; } -int -intel_bo_pread(struct intel_bo *bo, unsigned long offset, - unsigned long size, void *data) +void +intel_winsys_destroy(struct intel_winsys *winsys) { - return drm_intel_bo_get_subdata(bo->bo, offset, size, data); + if (winsys->decode) + drm_intel_decode_context_free(winsys->decode); + + drm_intel_bufmgr_destroy(winsys->bufmgr); + FREE(winsys->drm_bo_array); + FREE(winsys); } -unsigned long -intel_bo_get_size(const struct intel_bo *bo) +const struct intel_winsys_info * +intel_winsys_get_info(const struct intel_winsys *winsys) { - return bo->bo->size; + return &winsys->info; } -unsigned long -intel_bo_get_offset(const struct intel_bo *bo) +void +intel_winsys_enable_reuse(struct intel_winsys *winsys) { - return bo->bo->offset; + drm_intel_bufmgr_gem_enable_reuse(winsys->bufmgr); } -void * -intel_bo_get_virtual(const struct intel_bo *bo) +struct intel_context * +intel_winsys_create_context(struct intel_winsys *winsys) { - return bo->bo->virtual; + return (struct intel_context *) + drm_intel_gem_context_create(winsys->bufmgr); } void -intel_bo_reference(struct intel_bo *bo) +intel_winsys_destroy_context(struct intel_winsys *winsys, + struct intel_context *ctx) { - pipe_reference(NULL, &bo->reference); + drm_intel_gem_context_destroy((drm_intel_context *) ctx); } -void -intel_bo_unreference(struct intel_bo *bo) +int +intel_winsys_read_reg(struct intel_winsys *winsys, + uint32_t reg, uint64_t *val) { - if (pipe_reference(&bo->reference, NULL)) { - drm_intel_bo_unreference(bo->bo); - FREE(bo); - } + return drm_intel_reg_read(winsys->bufmgr, reg, val); } static struct intel_bo * @@ -249,30 +216,28 @@ create_bo(void) } struct intel_bo * -intel_winsys_alloc_texture(struct intel_winsys *winsys, - const char *name, - int width, int height, int cpp, - enum intel_tiling_mode tiling, - unsigned long flags, - unsigned long *pitch) +intel_winsys_alloc_buffer(struct intel_winsys *winsys, + const char *name, + unsigned long size, + unsigned long flags) { + const int alignment = 4096; /* always page-aligned */ struct intel_bo *bo; - uint32_t real_tiling = tiling; bo = create_bo(); if (!bo) return NULL; - bo->bo = drm_intel_bo_alloc_tiled(winsys->bufmgr, name, - width, height, cpp, &real_tiling, pitch, flags); - if (!bo->bo) { - FREE(bo); - return NULL; + if (flags == INTEL_ALLOC_FOR_RENDER) { + bo->bo = drm_intel_bo_alloc_for_render(winsys->bufmgr, + name, size, alignment); + } + else { + assert(!flags); + bo->bo = drm_intel_bo_alloc(winsys->bufmgr, name, size, alignment); } - if (tiling != real_tiling) { - assert(!"tiling mis-match"); - drm_intel_bo_unreference(bo->bo); + if (!bo->bo) { FREE(bo); return NULL; } @@ -281,28 +246,30 @@ intel_winsys_alloc_texture(struct intel_winsys *winsys, } struct intel_bo * -intel_winsys_alloc_buffer(struct intel_winsys *winsys, - const char *name, - unsigned long size, - unsigned long flags) +intel_winsys_alloc_texture(struct intel_winsys *winsys, + const char *name, + int width, int height, int cpp, + enum intel_tiling_mode tiling, + unsigned long flags, + unsigned long *pitch) { - const int alignment = 4096; /* always page-aligned */ + uint32_t real_tiling = tiling; struct intel_bo *bo; bo = create_bo(); if (!bo) return NULL; - if (flags == INTEL_ALLOC_FOR_RENDER) { - bo->bo = drm_intel_bo_alloc_for_render(winsys->bufmgr, - name, size, alignment); - } - else { - assert(!flags); - bo->bo = drm_intel_bo_alloc(winsys->bufmgr, name, size, alignment); + bo->bo = drm_intel_bo_alloc_tiled(winsys->bufmgr, name, + width, height, cpp, &real_tiling, pitch, flags); + if (!bo->bo) { + FREE(bo); + return NULL; } - if (!bo->bo) { + if (real_tiling != tiling) { + assert(!"tiling mismatch"); + drm_intel_bo_unreference(bo->bo); FREE(bo); return NULL; } @@ -366,6 +333,52 @@ intel_winsys_import_handle(struct intel_winsys *winsys, } int +intel_winsys_export_handle(struct intel_winsys *winsys, + struct intel_bo *bo, + enum intel_tiling_mode tiling, + unsigned long pitch, + struct winsys_handle *handle) +{ + int err = 0; + + switch (handle->type) { + case DRM_API_HANDLE_TYPE_SHARED: + { + uint32_t name; + + err = drm_intel_bo_flink(bo->bo, &name); + if (!err) + handle->handle = name; + } + break; + case DRM_API_HANDLE_TYPE_KMS: + handle->handle = bo->bo->handle; + break; +#if 0 + case DRM_API_HANDLE_TYPE_PRIME: + { + int fd; + + err = drm_intel_bo_gem_export_to_prime(bo->bo, &fd); + if (!err) + handle->handle = fd; + } + break; +#endif + default: + err = -EINVAL; + break; + } + + if (err) + return err; + + handle->stride = pitch; + + return 0; +} + +int intel_winsys_check_aperture_space(struct intel_winsys *winsys, struct intel_bo **bo_array, int count) @@ -432,142 +445,129 @@ intel_winsys_decode_commands(struct intel_winsys *winsys, drm_intel_bo_unmap(bo->bo); } -int -intel_winsys_read_reg(struct intel_winsys *winsys, - uint32_t reg, uint64_t *val) +void +intel_bo_reference(struct intel_bo *bo) { - return drm_intel_reg_read(winsys->bufmgr, reg, val); + pipe_reference(NULL, &bo->reference); } void -intel_winsys_enable_reuse(struct intel_winsys *winsys) +intel_bo_unreference(struct intel_bo *bo) { - drm_intel_bufmgr_gem_enable_reuse(winsys->bufmgr); + if (pipe_reference(&bo->reference, NULL)) { + drm_intel_bo_unreference(bo->bo); + FREE(bo); + } } -void -intel_winsys_destroy_context(struct intel_winsys *winsys, - struct intel_context *ctx) +unsigned long +intel_bo_get_size(const struct intel_bo *bo) { - drm_intel_gem_context_destroy((drm_intel_context *) ctx); + return bo->bo->size; } -struct intel_context * -intel_winsys_create_context(struct intel_winsys *winsys) +unsigned long +intel_bo_get_offset(const struct intel_bo *bo) { - return (struct intel_context *) - drm_intel_gem_context_create(winsys->bufmgr); + return bo->bo->offset; } -const struct intel_winsys_info * -intel_winsys_get_info(const struct intel_winsys *winsys) +void * +intel_bo_get_virtual(const struct intel_bo *bo) { - return &winsys->info; + return bo->bo->virtual; } -void -intel_winsys_destroy(struct intel_winsys *winsys) +int +intel_bo_map(struct intel_bo *bo, bool write_enable) { - if (winsys->decode) - drm_intel_decode_context_free(winsys->decode); - - drm_intel_bufmgr_destroy(winsys->bufmgr); - FREE(winsys->drm_bo_array); - FREE(winsys); + return drm_intel_bo_map(bo->bo, write_enable); } -static bool -get_param(struct intel_winsys *winsys, int param, int *value) +int +intel_bo_map_gtt(struct intel_bo *bo) { - struct drm_i915_getparam gp; - int err; - - *value = 0; - - memset(&gp, 0, sizeof(gp)); - gp.param = param; - gp.value = value; - - err = drmCommandWriteRead(winsys->fd, DRM_I915_GETPARAM, &gp, sizeof(gp)); - if (err) { - *value = 0; - return false; - } - - return true; + return drm_intel_gem_bo_map_gtt(bo->bo); } -static bool -test_address_swizzling(struct intel_winsys *winsys) +int +intel_bo_map_unsynchronized(struct intel_bo *bo) { - drm_intel_bo *bo; - uint32_t tiling = I915_TILING_X, swizzle; - unsigned long pitch; - - bo = drm_intel_bo_alloc_tiled(winsys->bufmgr, - "address swizzling test", 64, 64, 4, &tiling, &pitch, 0); - if (bo) { - drm_intel_bo_get_tiling(bo, &tiling, &swizzle); - drm_intel_bo_unreference(bo); - } - else { - swizzle = I915_BIT_6_SWIZZLE_NONE; - } - - return (swizzle != I915_BIT_6_SWIZZLE_NONE); + return drm_intel_gem_bo_map_unsynchronized(bo->bo); } -static bool -init_info(struct intel_winsys *winsys) +void +intel_bo_unmap(struct intel_bo *bo) { - struct intel_winsys_info *info = &winsys->info; - int val; - - /* follow the classic driver here */ - get_param(winsys, I915_PARAM_HAS_RELAXED_DELTA, &val); - if (!val) { - debug_error("kernel 2.6.39 required"); - return false; - } - - info->devid = drm_intel_bufmgr_gem_get_devid(winsys->bufmgr); + int err; - get_param(winsys, I915_PARAM_HAS_LLC, &val); - info->has_llc = val; + err = drm_intel_bo_unmap(bo->bo); + assert(!err); +} - get_param(winsys, I915_PARAM_HAS_GEN7_SOL_RESET, &val); - info->has_gen7_sol_reset = val; +int +intel_bo_pwrite(struct intel_bo *bo, unsigned long offset, + unsigned long size, const void *data) +{ + return drm_intel_bo_subdata(bo->bo, offset, size, data); +} - info->has_address_swizzling = test_address_swizzling(winsys); +int +intel_bo_pread(struct intel_bo *bo, unsigned long offset, + unsigned long size, void *data) +{ + return drm_intel_bo_get_subdata(bo->bo, offset, size, data); +} - return true; +int +intel_bo_emit_reloc(struct intel_bo *bo, uint32_t offset, + struct intel_bo *target_bo, uint32_t target_offset, + uint32_t read_domains, uint32_t write_domain) +{ + return drm_intel_bo_emit_reloc(bo->bo, offset, + target_bo->bo, target_offset, read_domains, write_domain); } -struct intel_winsys * -intel_winsys_create_for_fd(int fd) +int +intel_bo_get_reloc_count(struct intel_bo *bo) { - struct intel_winsys *winsys; + return drm_intel_gem_bo_get_reloc_count(bo->bo); +} - winsys = CALLOC_STRUCT(intel_winsys); - if (!winsys) - return NULL; +void +intel_bo_clear_relocs(struct intel_bo *bo, int start) +{ + return drm_intel_gem_bo_clear_relocs(bo->bo, start); +} - winsys->fd = fd; +bool +intel_bo_references(struct intel_bo *bo, struct intel_bo *target_bo) +{ + return drm_intel_bo_references(bo->bo, target_bo->bo); +} - winsys->bufmgr = drm_intel_bufmgr_gem_init(winsys->fd, BATCH_SZ); - if (!winsys->bufmgr) { - debug_error("failed to create GEM buffer manager"); - FREE(winsys); - return NULL; +int +intel_bo_exec(struct intel_bo *bo, int used, + struct intel_context *ctx, unsigned long flags) +{ + if (ctx) { + return drm_intel_gem_bo_context_exec(bo->bo, + (drm_intel_context *) ctx, used, flags); } - - if (!init_info(winsys)) { - drm_intel_bufmgr_destroy(winsys->bufmgr); - FREE(winsys); - return NULL; + else { + return drm_intel_bo_mrb_exec(bo->bo, used, NULL, 0, 0, flags); } +} - drm_intel_bufmgr_gem_enable_fenced_relocs(winsys->bufmgr); +int +intel_bo_wait(struct intel_bo *bo, int64_t timeout) +{ + int err; - return winsys; + err = drm_intel_gem_bo_wait(bo->bo, timeout); + /* consider the bo idle on errors */ + if (err && err != -ETIME) + err = 0; + + return err; } |