[igt-dev] [PATCH i-g-t v27 05/30] lib/intel_bufops: extract getting the stride

Zbigniew Kempczyński
2020-08-10T09:47:24Z

Remove redundant code for getting the stride

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Cc: Dominik Grzegorzek <dominik.grzegorzek@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
---
lib/intel_bufops.c | 28 ++++++++++++----------------
1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/lib/intel_bufops.c b/lib/intel_bufops.c
index 35e3c0d2..af42b2ee 100644
--- a/lib/intel_bufops.c
+++ b/lib/intel_bufops.c
@@ -142,6 +142,16 @@ static inline bool is_tiling_supported(struct buf_ops *bops, uint32_t tiling)
return bops->supported_tiles & TILE_DEF(tiling);
}

+static uint32_t get_stride(uint32_t devid, uint32_t tiling)
+{
+ uint32_t stride = 128;
+
+ if (IS_915G(devid) || IS_915GM(devid) || tiling == I915_TILING_X)
+ stride = 512;
+
+ return stride;
+}
+
static int __gem_get_tiling(int fd, struct drm_i915_gem_get_tiling *arg)
{
int err;
@@ -749,14 +759,7 @@ static void __intel_buf_init(struct buf_ops *bops,
} else {
if (buf->tiling) {
devid = intel_get_drm_devid(bops->fd);
-
- if (bops->intel_gen < 3)
- tile_width = 128;
- else if (IS_915G(devid) || buf->tiling == I915_TILING_X)
- tile_width = 512;
- else
- tile_width = 128;
-
+ tile_width = get_stride(devid, buf->tiling);
buf->surface[0].stride = ALIGN(width * (bpp / 8), tile_width);
} else {
buf->surface[0].stride = ALIGN(width * (bpp / 8), alignment ?: 2);
@@ -1041,14 +1044,7 @@ static bool probe_hw_tiling(struct buf_ops *bops, uint32_t tiling,
bool is_set = false;

devid = intel_get_drm_devid(bops->fd);
-
- if (tiling == I915_TILING_X || IS_915G(devid))
- stride = 512;
- else if (tiling == I915_TILING_Y)
- stride = 128;
- else
- return false;
-
+ stride = get_stride(devid, tiling);
handle = gem_create(bops->fd, size);

/* Single shot, if no fences are available we fail immediately */