xref: /third_party/libdrm/freedreno/msm/msm_priv.h (revision d722e3fb)
1d722e3fbSopenharmony_ci/* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
2d722e3fbSopenharmony_ci
3d722e3fbSopenharmony_ci/*
4d722e3fbSopenharmony_ci * Copyright (C) 2013 Rob Clark <robclark@freedesktop.org>
5d722e3fbSopenharmony_ci *
6d722e3fbSopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7d722e3fbSopenharmony_ci * copy of this software and associated documentation files (the "Software"),
8d722e3fbSopenharmony_ci * to deal in the Software without restriction, including without limitation
9d722e3fbSopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10d722e3fbSopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
11d722e3fbSopenharmony_ci * Software is furnished to do so, subject to the following conditions:
12d722e3fbSopenharmony_ci *
13d722e3fbSopenharmony_ci * The above copyright notice and this permission notice (including the next
14d722e3fbSopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
15d722e3fbSopenharmony_ci * Software.
16d722e3fbSopenharmony_ci *
17d722e3fbSopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18d722e3fbSopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19d722e3fbSopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20d722e3fbSopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21d722e3fbSopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22d722e3fbSopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23d722e3fbSopenharmony_ci * SOFTWARE.
24d722e3fbSopenharmony_ci *
25d722e3fbSopenharmony_ci * Authors:
26d722e3fbSopenharmony_ci *    Rob Clark <robclark@freedesktop.org>
27d722e3fbSopenharmony_ci */
28d722e3fbSopenharmony_ci
29d722e3fbSopenharmony_ci#ifndef MSM_PRIV_H_
30d722e3fbSopenharmony_ci#define MSM_PRIV_H_
31d722e3fbSopenharmony_ci
32d722e3fbSopenharmony_ci#include "freedreno_priv.h"
33d722e3fbSopenharmony_ci
34d722e3fbSopenharmony_ci#ifndef __user
35d722e3fbSopenharmony_ci#  define __user
36d722e3fbSopenharmony_ci#endif
37d722e3fbSopenharmony_ci
38d722e3fbSopenharmony_ci#include "msm_drm.h"
39d722e3fbSopenharmony_ci
40d722e3fbSopenharmony_cistruct msm_device {
41d722e3fbSopenharmony_ci	struct fd_device base;
42d722e3fbSopenharmony_ci	struct fd_bo_cache ring_cache;
43d722e3fbSopenharmony_ci	unsigned ring_cnt;
44d722e3fbSopenharmony_ci};
45d722e3fbSopenharmony_ci
46d722e3fbSopenharmony_cistatic inline struct msm_device * to_msm_device(struct fd_device *x)
47d722e3fbSopenharmony_ci{
48d722e3fbSopenharmony_ci	return (struct msm_device *)x;
49d722e3fbSopenharmony_ci}
50d722e3fbSopenharmony_ci
51d722e3fbSopenharmony_cidrm_private struct fd_device * msm_device_new(int fd);
52d722e3fbSopenharmony_ci
53d722e3fbSopenharmony_cistruct msm_pipe {
54d722e3fbSopenharmony_ci	struct fd_pipe base;
55d722e3fbSopenharmony_ci	uint32_t pipe;
56d722e3fbSopenharmony_ci	uint32_t gpu_id;
57d722e3fbSopenharmony_ci	uint32_t gmem;
58d722e3fbSopenharmony_ci	uint32_t chip_id;
59d722e3fbSopenharmony_ci	uint32_t queue_id;
60d722e3fbSopenharmony_ci
61d722e3fbSopenharmony_ci	/* Allow for sub-allocation of stateobj ring buffers (ie. sharing
62d722e3fbSopenharmony_ci	 * the same underlying bo)..
63d722e3fbSopenharmony_ci	 *
64d722e3fbSopenharmony_ci	 * This takes advantage of each context having it's own fd_pipe,
65d722e3fbSopenharmony_ci	 * so we don't have to worry about access from multiple threads.
66d722e3fbSopenharmony_ci	 *
67d722e3fbSopenharmony_ci	 * We also rely on previous stateobj having been fully constructed
68d722e3fbSopenharmony_ci	 * so we can reclaim extra space at it's end.
69d722e3fbSopenharmony_ci	 */
70d722e3fbSopenharmony_ci	struct fd_ringbuffer *suballoc_ring;
71d722e3fbSopenharmony_ci};
72d722e3fbSopenharmony_ci
73d722e3fbSopenharmony_cistatic inline struct msm_pipe * to_msm_pipe(struct fd_pipe *x)
74d722e3fbSopenharmony_ci{
75d722e3fbSopenharmony_ci	return (struct msm_pipe *)x;
76d722e3fbSopenharmony_ci}
77d722e3fbSopenharmony_ci
78d722e3fbSopenharmony_cidrm_private struct fd_pipe * msm_pipe_new(struct fd_device *dev,
79d722e3fbSopenharmony_ci		enum fd_pipe_id id, uint32_t prio);
80d722e3fbSopenharmony_ci
81d722e3fbSopenharmony_cidrm_private struct fd_ringbuffer * msm_ringbuffer_new(struct fd_pipe *pipe,
82d722e3fbSopenharmony_ci		uint32_t size, enum fd_ringbuffer_flags flags);
83d722e3fbSopenharmony_ci
84d722e3fbSopenharmony_cistruct msm_bo {
85d722e3fbSopenharmony_ci	struct fd_bo base;
86d722e3fbSopenharmony_ci	uint64_t offset;
87d722e3fbSopenharmony_ci	uint64_t presumed;
88d722e3fbSopenharmony_ci	/* to avoid excess hashtable lookups, cache the ring this bo was
89d722e3fbSopenharmony_ci	 * last emitted on (since that will probably also be the next ring
90d722e3fbSopenharmony_ci	 * it is emitted on)
91d722e3fbSopenharmony_ci	 */
92d722e3fbSopenharmony_ci	unsigned current_ring_seqno;
93d722e3fbSopenharmony_ci	uint32_t idx;
94d722e3fbSopenharmony_ci};
95d722e3fbSopenharmony_ci
96d722e3fbSopenharmony_cistatic inline struct msm_bo * to_msm_bo(struct fd_bo *x)
97d722e3fbSopenharmony_ci{
98d722e3fbSopenharmony_ci	return (struct msm_bo *)x;
99d722e3fbSopenharmony_ci}
100d722e3fbSopenharmony_ci
101d722e3fbSopenharmony_cidrm_private int msm_bo_new_handle(struct fd_device *dev,
102d722e3fbSopenharmony_ci		uint32_t size, uint32_t flags, uint32_t *handle);
103d722e3fbSopenharmony_cidrm_private struct fd_bo * msm_bo_from_handle(struct fd_device *dev,
104d722e3fbSopenharmony_ci		uint32_t size, uint32_t handle);
105d722e3fbSopenharmony_ci
106d722e3fbSopenharmony_cistatic inline void get_abs_timeout(struct drm_msm_timespec *tv, uint64_t ns)
107d722e3fbSopenharmony_ci{
108d722e3fbSopenharmony_ci	struct timespec t;
109d722e3fbSopenharmony_ci	uint32_t s = ns / 1000000000;
110d722e3fbSopenharmony_ci	clock_gettime(CLOCK_MONOTONIC, &t);
111d722e3fbSopenharmony_ci	tv->tv_sec = t.tv_sec + s;
112d722e3fbSopenharmony_ci	tv->tv_nsec = t.tv_nsec + ns - (s * 1000000000);
113d722e3fbSopenharmony_ci}
114d722e3fbSopenharmony_ci
115d722e3fbSopenharmony_ci/*
116d722e3fbSopenharmony_ci * Stupid/simple growable array implementation:
117d722e3fbSopenharmony_ci */
118d722e3fbSopenharmony_ci
119d722e3fbSopenharmony_cistatic inline void *
120d722e3fbSopenharmony_cigrow(void *ptr, uint32_t nr, uint32_t *max, uint32_t sz)
121d722e3fbSopenharmony_ci{
122d722e3fbSopenharmony_ci	if ((nr + 1) > *max) {
123d722e3fbSopenharmony_ci		if ((*max * 2) < (nr + 1))
124d722e3fbSopenharmony_ci			*max = nr + 5;
125d722e3fbSopenharmony_ci		else
126d722e3fbSopenharmony_ci			*max = *max * 2;
127d722e3fbSopenharmony_ci		ptr = realloc(ptr, *max * sz);
128d722e3fbSopenharmony_ci	}
129d722e3fbSopenharmony_ci	return ptr;
130d722e3fbSopenharmony_ci}
131d722e3fbSopenharmony_ci
132d722e3fbSopenharmony_ci#define DECLARE_ARRAY(type, name) \
133d722e3fbSopenharmony_ci	unsigned nr_ ## name, max_ ## name; \
134d722e3fbSopenharmony_ci	type * name;
135d722e3fbSopenharmony_ci
136d722e3fbSopenharmony_ci#define APPEND(x, name) ({ \
137d722e3fbSopenharmony_ci	(x)->name = grow((x)->name, (x)->nr_ ## name, &(x)->max_ ## name, sizeof((x)->name[0])); \
138d722e3fbSopenharmony_ci	(x)->nr_ ## name ++; \
139d722e3fbSopenharmony_ci})
140d722e3fbSopenharmony_ci
141d722e3fbSopenharmony_ci#endif /* MSM_PRIV_H_ */
142