OSDN Git Service

freedreno: add handle and name tracking
[android-x86/external-libdrm.git] / freedreno / freedreno_priv.h
1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
2
3 /*
4  * Copyright (C) 2012 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 FREEDRENO_PRIV_H_
30 #define FREEDRENO_PRIV_H_
31
32 #include <stdlib.h>
33 #include <errno.h>
34 #include <string.h>
35 #include <unistd.h>
36 #include <errno.h>
37 #include <fcntl.h>
38 #include <sys/ioctl.h>
39 #include <sys/mman.h>
40 #include <pthread.h>
41
42 #include "xf86drm.h"
43 #include "xf86atomic.h"
44
45 #include "list.h"
46
47 #include "freedreno_drmif.h"
48 #include "msm_kgsl.h"
49 #include "kgsl_drm.h"
50
51 struct fd_device {
52         int fd;
53         atomic_t refcnt;
54
55         /* tables to keep track of bo's, to avoid "evil-twin" fd_bo objects:
56          *
57          *   handle_table: maps handle to fd_bo
58          *   name_table: maps flink name to fd_bo
59          *
60          * We end up needing two tables, because DRM_IOCTL_GEM_OPEN always
61          * returns a new handle.  So we need to figure out if the bo is already
62          * open in the process first, before calling gem-open.
63          */
64         void *handle_table, *name_table;
65 };
66
67 struct fd_pipe {
68         struct fd_device *dev;
69         enum fd_pipe_id id;
70         int fd;
71         uint32_t drawctxt_id;
72
73         /* device properties: */
74         struct kgsl_version version;
75         struct kgsl_devinfo devinfo;
76
77         /* list of bo's that are referenced in ringbuffer but not
78          * submitted yet:
79          */
80         struct list_head submit_list;
81
82         /* list of bo's that have been submitted but timestamp has
83          * not passed yet (so still ref'd in active cmdstream)
84          */
85         struct list_head pending_list;
86
87         /* if we are the 2d pipe, and want to wait on a timestamp
88          * from 3d, we need to also internally open the 3d pipe:
89          */
90         struct fd_pipe *p3d;
91 };
92
93 void fd_pipe_add_submit(struct fd_pipe *pipe, struct fd_bo *bo);
94 void fd_pipe_pre_submit(struct fd_pipe *pipe);
95 void fd_pipe_post_submit(struct fd_pipe *pipe, uint32_t timestamp);
96 void fd_pipe_process_pending(struct fd_pipe *pipe, uint32_t timestamp);
97
98 struct fd_bo {
99         struct fd_device *dev;
100         uint32_t size;
101         uint32_t handle;
102         uint32_t name;
103         uint32_t gpuaddr;
104         void *map;
105         uint64_t offset;
106         /* timestamp (per pipe) for bo's in a pipe's pending_list: */
107         uint32_t timestamp[FD_PIPE_MAX];
108         /* list-node for pipe's submit_list or pending_list */
109         struct list_head list[FD_PIPE_MAX];
110         atomic_t refcnt;
111 };
112
113 /* not exposed publicly, because won't be needed when we have
114  * a proper kernel driver
115  */
116 uint32_t fd_bo_gpuaddr(struct fd_bo *bo, uint32_t offset);
117 void fb_bo_set_timestamp(struct fd_bo *bo, uint32_t timestamp);
118 uint32_t fd_bo_get_timestamp(struct fd_bo *bo);
119
120 #define ALIGN(v,a) (((v) + (a) - 1) & ~((a) - 1))
121 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
122
123 #define enable_debug 1  /* TODO make dynamic */
124
125 #define INFO_MSG(fmt, ...) \
126                 do { drmMsg("[I] "fmt " (%s:%d)\n", \
127                                 ##__VA_ARGS__, __FUNCTION__, __LINE__); } while (0)
128 #define DEBUG_MSG(fmt, ...) \
129                 do if (enable_debug) { drmMsg("[D] "fmt " (%s:%d)\n", \
130                                 ##__VA_ARGS__, __FUNCTION__, __LINE__); } while (0)
131 #define WARN_MSG(fmt, ...) \
132                 do { drmMsg("[W] "fmt " (%s:%d)\n", \
133                                 ##__VA_ARGS__, __FUNCTION__, __LINE__); } while (0)
134 #define ERROR_MSG(fmt, ...) \
135                 do { drmMsg("[E] " fmt " (%s:%d)\n", \
136                                 ##__VA_ARGS__, __FUNCTION__, __LINE__); } while (0)
137
138 #endif /* FREEDRENO_PRIV_H_ */