aa71b5649dc0e5e472fcd7fae2a7e414195da711
[platform/upstream/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
41 #include "xf86drm.h"
42 #include "xf86atomic.h"
43
44 #include "list.h"
45
46 #include "freedreno_drmif.h"
47 #include "msm_kgsl.h"
48 #include "kgsl_drm.h"
49
50 struct fd_device {
51         int fd;
52 };
53
54 struct fd_pipe {
55         struct fd_device *dev;
56         enum fd_pipe_id id;
57         int fd;
58         uint32_t drawctxt_id;
59
60         /* device properties: */
61         struct kgsl_version version;
62         struct kgsl_devinfo devinfo;
63
64         /* list of bo's that are referenced in ringbuffer but not
65          * submitted yet:
66          */
67         struct list_head submit_list;
68
69         /* list of bo's that have been submitted but timestamp has
70          * not passed yet (so still ref'd in active cmdstream)
71          */
72         struct list_head pending_list;
73 };
74
75 void fd_pipe_add_submit(struct fd_pipe *pipe, struct fd_bo *bo);
76 void fd_pipe_process_submit(struct fd_pipe *pipe, uint32_t timestamp);
77 void fd_pipe_process_pending(struct fd_pipe *pipe, uint32_t timestamp);
78
79 struct fd_bo {
80         struct fd_device *dev;
81         uint32_t size;
82         uint32_t handle;
83         uint32_t name;
84         uint32_t gpuaddr;
85         void *map;
86         uint64_t offset;
87         /* timestamp (per pipe) for bo's in a pipe's pending_list: */
88         uint32_t timestamp[FD_PIPE_MAX];
89         /* list-node for pipe's submit_list or pending_list */
90         struct list_head list[FD_PIPE_MAX];
91         atomic_t refcnt;
92 };
93
94 /* not exposed publicly, because won't be needed when we have
95  * a proper kernel driver
96  */
97 uint32_t fd_bo_gpuaddr(struct fd_bo *bo, uint32_t offset);
98
99 #define ALIGN(v,a) (((v) + (a) - 1) & ~((a) - 1))
100 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
101
102 #define enable_debug 1  /* TODO make dynamic */
103
104 #define INFO_MSG(fmt, ...) \
105                 do { drmMsg("[I] "fmt " (%s:%d)\n", \
106                                 ##__VA_ARGS__, __FUNCTION__, __LINE__); } while (0)
107 #define DEBUG_MSG(fmt, ...) \
108                 do if (enable_debug) { drmMsg("[D] "fmt " (%s:%d)\n", \
109                                 ##__VA_ARGS__, __FUNCTION__, __LINE__); } while (0)
110 #define WARN_MSG(fmt, ...) \
111                 do { drmMsg("[W] "fmt " (%s:%d)\n", \
112                                 ##__VA_ARGS__, __FUNCTION__, __LINE__); } while (0)
113 #define ERROR_MSG(fmt, ...) \
114                 do { drmMsg("[E] " fmt " (%s:%d)\n", \
115                                 ##__VA_ARGS__, __FUNCTION__, __LINE__); } while (0)
116
117 #endif /* FREEDRENO_PRIV_H_ */