Blame freedreno/freedreno_ringbuffer.h

Packit Service 103f6b
/* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
Packit Service 103f6b
Packit Service 103f6b
/*
Packit Service 103f6b
 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
Packit Service 103f6b
 *
Packit Service 103f6b
 * Permission is hereby granted, free of charge, to any person obtaining a
Packit Service 103f6b
 * copy of this software and associated documentation files (the "Software"),
Packit Service 103f6b
 * to deal in the Software without restriction, including without limitation
Packit Service 103f6b
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
Packit Service 103f6b
 * and/or sell copies of the Software, and to permit persons to whom the
Packit Service 103f6b
 * Software is furnished to do so, subject to the following conditions:
Packit Service 103f6b
 *
Packit Service 103f6b
 * The above copyright notice and this permission notice (including the next
Packit Service 103f6b
 * paragraph) shall be included in all copies or substantial portions of the
Packit Service 103f6b
 * Software.
Packit Service 103f6b
 *
Packit Service 103f6b
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit Service 103f6b
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit Service 103f6b
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
Packit Service 103f6b
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Packit Service 103f6b
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Packit Service 103f6b
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Packit Service 103f6b
 * SOFTWARE.
Packit Service 103f6b
 *
Packit Service 103f6b
 * Authors:
Packit Service 103f6b
 *    Rob Clark <robclark@freedesktop.org>
Packit Service 103f6b
 */
Packit Service 103f6b
Packit Service 103f6b
#ifndef FREEDRENO_RINGBUFFER_H_
Packit Service 103f6b
#define FREEDRENO_RINGBUFFER_H_
Packit Service 103f6b
Packit Service 103f6b
#include <freedreno_drmif.h>
Packit Service 103f6b
Packit Service 103f6b
/* the ringbuffer object is not opaque so that OUT_RING() type stuff
Packit Service 103f6b
 * can be inlined.  Note that users should not make assumptions about
Packit Service 103f6b
 * the size of this struct.
Packit Service 103f6b
 */
Packit Service 103f6b
Packit Service 103f6b
struct fd_ringbuffer_funcs;
Packit Service 103f6b
Packit Service 103f6b
enum fd_ringbuffer_flags {
Packit Service 103f6b
Packit Service 103f6b
	/* Ringbuffer is a "state object", which is potentially reused
Packit Service 103f6b
	 * many times, rather than being used in one-shot mode linked
Packit Service 103f6b
	 * to a parent ringbuffer.
Packit Service 103f6b
	 */
Packit Service 103f6b
	FD_RINGBUFFER_OBJECT = 0x1,
Packit Service 103f6b
Packit Service 103f6b
	/* Hint that the stateobj will be used for streaming state
Packit Service 103f6b
	 * that is used once or a few times and then discarded.
Packit Service 103f6b
	 *
Packit Service 103f6b
	 * For sub-allocation, non streaming stateobj's should be
Packit Service 103f6b
	 * sub-allocated from a page size buffer, so one long lived
Packit Service 103f6b
	 * state obj doesn't prevent other pages from being freed.
Packit Service 103f6b
	 * (Ie. it would be no worse than allocating a page sized
Packit Service 103f6b
	 * bo for each small non-streaming stateobj).
Packit Service 103f6b
	 *
Packit Service 103f6b
	 * But streaming stateobj's could be sub-allocated from a
Packit Service 103f6b
	 * larger buffer to reduce the alloc/del overhead.
Packit Service 103f6b
	 */
Packit Service 103f6b
	FD_RINGBUFFER_STREAMING = 0x2,
Packit Service 103f6b
};
Packit Service 103f6b
Packit Service 103f6b
struct fd_ringbuffer {
Packit Service 103f6b
	int size;
Packit Service 103f6b
	uint32_t *cur, *end, *start, *last_start;
Packit Service 103f6b
	struct fd_pipe *pipe;
Packit Service 103f6b
	const struct fd_ringbuffer_funcs *funcs;
Packit Service 103f6b
	uint32_t last_timestamp;
Packit Service 103f6b
	struct fd_ringbuffer *parent;
Packit Service 103f6b
Packit Service 103f6b
	/* for users of fd_ringbuffer to store their own private per-
Packit Service 103f6b
	 * ringbuffer data
Packit Service 103f6b
	 */
Packit Service 103f6b
	void *user;
Packit Service 103f6b
Packit Service 103f6b
	enum fd_ringbuffer_flags flags;
Packit Service 103f6b
Packit Service 103f6b
	/* This is a bit gross, but we can't use atomic_t in exported
Packit Service 103f6b
	 * headers.  OTOH, we don't need the refcnt to be publicly
Packit Service 103f6b
	 * visible.  The only reason that this struct is exported is
Packit Service 103f6b
	 * because fd_ringbuffer_emit needs to be something that can
Packit Service 103f6b
	 * be inlined for performance reasons.
Packit Service 103f6b
	 */
Packit Service 103f6b
	union {
Packit Service 103f6b
#ifdef HAS_ATOMIC_OPS
Packit Service 103f6b
		atomic_t refcnt;
Packit Service 103f6b
#endif
Packit Service 103f6b
		uint64_t __pad;
Packit Service 103f6b
	};
Packit Service 103f6b
};
Packit Service 103f6b
Packit Service 103f6b
struct fd_ringbuffer * fd_ringbuffer_new(struct fd_pipe *pipe,
Packit Service 103f6b
		uint32_t size);
Packit Service 103f6b
will_be_deprecated
Packit Service 103f6b
struct fd_ringbuffer * fd_ringbuffer_new_object(struct fd_pipe *pipe,
Packit Service 103f6b
		uint32_t size);
Packit Service 103f6b
struct fd_ringbuffer * fd_ringbuffer_new_flags(struct fd_pipe *pipe,
Packit Service 103f6b
		uint32_t size, enum fd_ringbuffer_flags flags);
Packit Service 103f6b
Packit Service 103f6b
struct fd_ringbuffer *fd_ringbuffer_ref(struct fd_ringbuffer *ring);
Packit Service 103f6b
void fd_ringbuffer_del(struct fd_ringbuffer *ring);
Packit Service 103f6b
void fd_ringbuffer_set_parent(struct fd_ringbuffer *ring,
Packit Service 103f6b
		struct fd_ringbuffer *parent);
Packit Service 103f6b
will_be_deprecated
Packit Service 103f6b
void fd_ringbuffer_reset(struct fd_ringbuffer *ring);
Packit Service 103f6b
int fd_ringbuffer_flush(struct fd_ringbuffer *ring);
Packit Service 103f6b
/* in_fence_fd: -1 for no in-fence, else fence fd
Packit Service 103f6b
 * out_fence_fd: NULL for no output-fence requested, else ptr to return out-fence
Packit Service 103f6b
 */
Packit Service 103f6b
int fd_ringbuffer_flush2(struct fd_ringbuffer *ring, int in_fence_fd,
Packit Service 103f6b
		int *out_fence_fd);
Packit Service 103f6b
void fd_ringbuffer_grow(struct fd_ringbuffer *ring, uint32_t ndwords);
Packit Service 103f6b
uint32_t fd_ringbuffer_timestamp(struct fd_ringbuffer *ring);
Packit Service 103f6b
Packit Service 103f6b
static inline void fd_ringbuffer_emit(struct fd_ringbuffer *ring,
Packit Service 103f6b
		uint32_t data)
Packit Service 103f6b
{
Packit Service 103f6b
	(*ring->cur++) = data;
Packit Service 103f6b
}
Packit Service 103f6b
Packit Service 103f6b
struct fd_reloc {
Packit Service 103f6b
	struct fd_bo *bo;
Packit Service 103f6b
#define FD_RELOC_READ             0x0001
Packit Service 103f6b
#define FD_RELOC_WRITE            0x0002
Packit Service 103f6b
	uint32_t flags;
Packit Service 103f6b
	uint32_t offset;
Packit Service 103f6b
	uint32_t or;
Packit Service 103f6b
	int32_t  shift;
Packit Service 103f6b
	uint32_t orhi;      /* used for a5xx+ */
Packit Service 103f6b
};
Packit Service 103f6b
Packit Service 103f6b
/* NOTE: relocs are 2 dwords on a5xx+ */
Packit Service 103f6b
Packit Service 103f6b
void fd_ringbuffer_reloc2(struct fd_ringbuffer *ring, const struct fd_reloc *reloc);
Packit Service 103f6b
will_be_deprecated void fd_ringbuffer_reloc(struct fd_ringbuffer *ring, const struct fd_reloc *reloc);
Packit Service 103f6b
uint32_t fd_ringbuffer_cmd_count(struct fd_ringbuffer *ring);
Packit Service 103f6b
uint32_t fd_ringbuffer_emit_reloc_ring_full(struct fd_ringbuffer *ring,
Packit Service 103f6b
		struct fd_ringbuffer *target, uint32_t cmd_idx);
Packit Service 103f6b
uint32_t fd_ringbuffer_size(struct fd_ringbuffer *ring);
Packit Service 103f6b
Packit Service 103f6b
#endif /* FREEDRENO_RINGBUFFER_H_ */