drm: etnaviv: extract command ring reservation
authorRussell King <rmk+kernel@arm.linux.org.uk>
Thu, 21 Jan 2016 15:20:04 +0000 (15:20 +0000)
committerLucas Stach <l.stach@pengutronix.de>
Mon, 7 Mar 2016 14:36:52 +0000 (15:36 +0100)
Provide a helper etnaviv_buffer_reserve() to ensure that we can fit a
set of commands into the ring buffer without wrapping by moving code
out of etnaviv_buffer_queue().

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
drivers/gpu/drm/etnaviv/etnaviv_buffer.c

index 332c55ebba6d3d839e595c377d4b4a6f838dd8ad..7f935e58e4b3796f43aec70edc43ea12fd25e0d3 100644 (file)
@@ -131,6 +131,19 @@ static void etnaviv_buffer_dump(struct etnaviv_gpu *gpu,
                        ptr, len * 4, 0);
 }
 
+/*
+ * Ensure that there is space in the command buffer to contiguously write
+ * 'cmd_dwords' 64-bit words into the buffer, wrapping if necessary.
+ */
+static u32 etnaviv_buffer_reserve(struct etnaviv_gpu *gpu,
+       struct etnaviv_cmdbuf *buffer, unsigned int cmd_dwords)
+{
+       if (buffer->user_size + cmd_dwords * sizeof(u64) > buffer->size)
+               buffer->user_size = 0;
+
+       return gpu_va(gpu, buffer) + buffer->user_size;
+}
+
 u16 etnaviv_buffer_init(struct etnaviv_gpu *gpu)
 {
        struct etnaviv_cmdbuf *buffer = gpu->buffer;
@@ -183,15 +196,10 @@ void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, unsigned int event,
 
        reserve_size = (6 + extra_size) * 4;
 
-       /*
-        * if we are going to completely overflow the buffer, we need to wrap.
-        */
-       if (buffer->user_size + reserve_size > buffer->size)
-               buffer->user_size = 0;
+       link_target = etnaviv_buffer_reserve(gpu, buffer, reserve_size / 8);
 
        /* save offset back into main buffer */
        back = buffer->user_size + reserve_size - 6 * 4;
-       link_target = gpu_va(gpu, buffer) + buffer->user_size;
        link_size = 6;
 
        /* Skip over any extra instructions */
@@ -207,8 +215,6 @@ void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, unsigned int event,
        link_target = gpu_va(gpu, cmdbuf);
        link_size = cmdbuf->size / 8;
 
-
-
        if (drm_debug & DRM_UT_DRIVER) {
                print_hex_dump(KERN_INFO, "cmd ", DUMP_PREFIX_OFFSET, 16, 4,
                               cmdbuf->vaddr, cmdbuf->size, 0);