1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
2 
3 /*
4  * Copyright (C) 2013 Rob Clark <robclark@freedesktop.org>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the next
14  * paragraph) shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  *
25  * Authors:
26  *    Rob Clark <robclark@freedesktop.org>
27  */
28 
29 #ifndef KGSL_PRIV_H_
30 #define KGSL_PRIV_H_
31 
32 #include "freedreno_priv.h"
33 #include "msm_kgsl.h"
34 #include "kgsl_drm.h"
35 
36 struct kgsl_device {
37 	struct fd_device base;
38 };
39 
to_kgsl_device(struct fd_device * x)40 static inline struct kgsl_device * to_kgsl_device(struct fd_device *x)
41 {
42 	return (struct kgsl_device *)x;
43 }
44 
45 struct kgsl_pipe {
46 	struct fd_pipe base;
47 
48 	int fd;
49 	uint32_t drawctxt_id;
50 
51 	/* device properties: */
52 	struct kgsl_version version;
53 	struct kgsl_devinfo devinfo;
54 
55 	/* list of bo's that are referenced in ringbuffer but not
56 	 * submitted yet:
57 	 */
58 	struct list_head submit_list;
59 
60 	/* list of bo's that have been submitted but timestamp has
61 	 * not passed yet (so still ref'd in active cmdstream)
62 	 */
63 	struct list_head pending_list;
64 
65 	/* if we are the 2d pipe, and want to wait on a timestamp
66 	 * from 3d, we need to also internally open the 3d pipe:
67 	 */
68 	struct fd_pipe *p3d;
69 };
70 
to_kgsl_pipe(struct fd_pipe * x)71 static inline struct kgsl_pipe * to_kgsl_pipe(struct fd_pipe *x)
72 {
73 	return (struct kgsl_pipe *)x;
74 }
75 
76 int is_kgsl_pipe(struct fd_pipe *pipe);
77 
78 struct kgsl_bo {
79 	struct fd_bo base;
80 	uint64_t offset;
81 	uint32_t gpuaddr;
82 	/* timestamp (per pipe) for bo's in a pipe's pending_list: */
83 	uint32_t timestamp[FD_PIPE_MAX];
84 	/* list-node for pipe's submit_list or pending_list */
85 	struct list_head list[FD_PIPE_MAX];
86 };
87 
to_kgsl_bo(struct fd_bo * x)88 static inline struct kgsl_bo * to_kgsl_bo(struct fd_bo *x)
89 {
90 	return (struct kgsl_bo *)x;
91 }
92 
93 
94 struct fd_device * kgsl_device_new(int fd);
95 
96 int kgsl_pipe_timestamp(struct kgsl_pipe *kgsl_pipe, uint32_t *timestamp);
97 void kgsl_pipe_add_submit(struct kgsl_pipe *pipe, struct kgsl_bo *bo);
98 void kgsl_pipe_pre_submit(struct kgsl_pipe *pipe);
99 void kgsl_pipe_post_submit(struct kgsl_pipe *pipe, uint32_t timestamp);
100 void kgsl_pipe_process_pending(struct kgsl_pipe *pipe, uint32_t timestamp);
101 struct fd_pipe * kgsl_pipe_new(struct fd_device *dev, enum fd_pipe_id id);
102 
103 struct fd_ringbuffer * kgsl_ringbuffer_new(struct fd_pipe *pipe,
104 		uint32_t size);
105 
106 int kgsl_bo_new_handle(struct fd_device *dev,
107 		uint32_t size, uint32_t flags, uint32_t *handle);
108 struct fd_bo * kgsl_bo_from_handle(struct fd_device *dev,
109 		uint32_t size, uint32_t handle);
110 
111 uint32_t kgsl_bo_gpuaddr(struct kgsl_bo *bo, uint32_t offset);
112 void kgsl_bo_set_timestamp(struct kgsl_bo *bo, uint32_t timestamp);
113 uint32_t kgsl_bo_get_timestamp(struct kgsl_bo *bo);
114 
115 #endif /* KGSL_PRIV_H_ */
116