*/
#include <assert.h>
+#include <stdlib.h>
#include "etnaviv_drmif.h"
#include "etnaviv_priv.h"
(x)->nr_ ## name ++; \
})
+void etna_cmd_stream_realloc(struct etna_cmd_stream *stream, size_t n)
+{
+ size_t size;
+ void *buffer;
+
+ /*
+ * Increase the command buffer size by 1 kiB. Here we pick 1 kiB
+ * increment to prevent it from growing too much too quickly.
+ */
+ size = ALIGN(stream->size + n, 1024);
+
+ /* Command buffer is too big for older kernel versions */
+ if (size >= 32768)
+ goto error;
+
+ buffer = realloc(stream->buffer, size * 4);
+ if (!buffer)
+ goto error;
+
+ stream->buffer = buffer;
+ stream->size = size;
+
+ return;
+
+error:
+ WARN_MSG("command buffer too long, forcing flush.");
+ etna_cmd_stream_force_flush(stream);
+}
+
static inline struct etna_cmd_stream_priv *
etna_cmd_stream_priv(struct etna_cmd_stream *stream)
{
return stream->size - stream->offset - END_CLEARANCE;
}
+void etna_cmd_stream_realloc(struct etna_cmd_stream *stream, size_t n);
+
static inline void etna_cmd_stream_reserve(struct etna_cmd_stream *stream, size_t n)
{
if (etna_cmd_stream_avail(stream) < n)
- etna_cmd_stream_force_flush(stream);
+ etna_cmd_stream_realloc(stream, n);
}
static inline void etna_cmd_stream_emit(struct etna_cmd_stream *stream, uint32_t data)