freedreno: small cleanup

Make cheezy growable array thing less open-coded before adding more.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
main
Rob Clark 2018-07-23 09:42:22 -04:00
parent fcbf206aa2
commit 2932a03180
2 changed files with 31 additions and 27 deletions

View File

@ -101,4 +101,30 @@ static inline void get_abs_timeout(struct drm_msm_timespec *tv, uint64_t ns)
tv->tv_nsec = t.tv_nsec + ns - (s * 1000000000); tv->tv_nsec = t.tv_nsec + ns - (s * 1000000000);
} }
/*
* Stupid/simple growable array implementation:
*/
static inline void *
grow(void *ptr, uint32_t nr, uint32_t *max, uint32_t sz)
{
if ((nr + 1) > *max) {
if ((*max * 2) < (nr + 1))
*max = nr + 5;
else
*max = *max * 2;
ptr = realloc(ptr, *max * sz);
}
return ptr;
}
#define DECLARE_ARRAY(type, name) \
unsigned nr_ ## name, max_ ## name; \
type * name;
#define APPEND(x, name) ({ \
(x)->name = grow((x)->name, (x)->nr_ ## name, &(x)->max_ ## name, sizeof((x)->name[0])); \
(x)->nr_ ## name ++; \
})
#endif /* MSM_PRIV_H_ */ #endif /* MSM_PRIV_H_ */

View File

@ -42,8 +42,7 @@ struct msm_cmd {
struct fd_bo *ring_bo; struct fd_bo *ring_bo;
/* reloc's table: */ /* reloc's table: */
struct drm_msm_gem_submit_reloc *relocs; DECLARE_ARRAY(struct drm_msm_gem_submit_reloc, relocs);
uint32_t nr_relocs, max_relocs;
uint32_t size; uint32_t size;
}; };
@ -58,22 +57,18 @@ struct msm_ringbuffer {
*/ */
struct { struct {
/* bo's table: */ /* bo's table: */
struct drm_msm_gem_submit_bo *bos; DECLARE_ARRAY(struct drm_msm_gem_submit_bo, bos);
uint32_t nr_bos, max_bos;
/* cmd's table: */ /* cmd's table: */
struct drm_msm_gem_submit_cmd *cmds; DECLARE_ARRAY(struct drm_msm_gem_submit_cmd, cmds);
uint32_t nr_cmds, max_cmds;
} submit; } submit;
/* should have matching entries in submit.bos: */ /* should have matching entries in submit.bos: */
/* Note, only in parent ringbuffer */ /* Note, only in parent ringbuffer */
struct fd_bo **bos; DECLARE_ARRAY(struct fd_bo *, bos);
uint32_t nr_bos, max_bos;
/* should have matching entries in submit.cmds: */ /* should have matching entries in submit.cmds: */
struct msm_cmd **cmds; DECLARE_ARRAY(struct msm_cmd *, cmds);
uint32_t nr_cmds, max_cmds;
/* List of physical cmdstream buffers (msm_cmd) assocated with this /* List of physical cmdstream buffers (msm_cmd) assocated with this
* logical fd_ringbuffer. * logical fd_ringbuffer.
@ -170,23 +165,6 @@ fail:
return NULL; return NULL;
} }
static void *grow(void *ptr, uint32_t nr, uint32_t *max, uint32_t sz)
{
if ((nr + 1) > *max) {
if ((*max * 2) < (nr + 1))
*max = nr + 5;
else
*max = *max * 2;
ptr = realloc(ptr, *max * sz);
}
return ptr;
}
#define APPEND(x, name) ({ \
(x)->name = grow((x)->name, (x)->nr_ ## name, &(x)->max_ ## name, sizeof((x)->name[0])); \
(x)->nr_ ## name ++; \
})
static struct msm_cmd *current_cmd(struct fd_ringbuffer *ring) static struct msm_cmd *current_cmd(struct fd_ringbuffer *ring)
{ {
struct msm_ringbuffer *msm_ring = to_msm_ringbuffer(ring); struct msm_ringbuffer *msm_ring = to_msm_ringbuffer(ring);