OSDN Git Service

freedreno: use local drm.h over the system one
[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 #include <stdio.h>
42 #include <assert.h>
43
44 #include "xf86drm.h"
45 #include "xf86atomic.h"
46
47 #include "list.h"
48
49 #include "freedreno_drmif.h"
50 #include "freedreno_ringbuffer.h"
51 #include "drm.h"
52
53 struct fd_device_funcs {
54         int (*bo_new_handle)(struct fd_device *dev, uint32_t size,
55                         uint32_t flags, uint32_t *handle);
56         struct fd_bo * (*bo_from_handle)(struct fd_device *dev,
57                         uint32_t size, uint32_t handle);
58         struct fd_pipe * (*pipe_new)(struct fd_device *dev, enum fd_pipe_id id);
59         void (*destroy)(struct fd_device *dev);
60 };
61
62 struct fd_device {
63         int fd;
64         atomic_t refcnt;
65
66         /* tables to keep track of bo's, to avoid "evil-twin" fd_bo objects:
67          *
68          *   handle_table: maps handle to fd_bo
69          *   name_table: maps flink name to fd_bo
70          *
71          * We end up needing two tables, because DRM_IOCTL_GEM_OPEN always
72          * returns a new handle.  So we need to figure out if the bo is already
73          * open in the process first, before calling gem-open.
74          */
75         void *handle_table, *name_table;
76
77         struct fd_device_funcs *funcs;
78 };
79
80 struct fd_pipe_funcs {
81         struct fd_ringbuffer * (*ringbuffer_new)(struct fd_pipe *pipe, uint32_t size);
82         int (*get_param)(struct fd_pipe *pipe, enum fd_param_id param, uint64_t *value);
83         int (*wait)(struct fd_pipe *pipe, uint32_t timestamp);
84         void (*destroy)(struct fd_pipe *pipe);
85 };
86
87 struct fd_pipe {
88         struct fd_device *dev;
89         enum fd_pipe_id id;
90         struct fd_pipe_funcs *funcs;
91 };
92
93 struct fd_ringmarker {
94         struct fd_ringbuffer *ring;
95         uint32_t *cur;
96 };
97
98 struct fd_ringbuffer_funcs {
99         void * (*hostptr)(struct fd_ringbuffer *ring);
100         int (*flush)(struct fd_ringbuffer *ring, uint32_t *last_start);
101         void (*emit_reloc)(struct fd_ringbuffer *ring,
102                         const struct fd_reloc *reloc);
103         void (*emit_reloc_ring)(struct fd_ringbuffer *ring,
104                         struct fd_ringmarker *target, struct fd_ringmarker *end);
105         void (*destroy)(struct fd_ringbuffer *ring);
106 };
107
108 struct fd_bo_funcs {
109         int (*offset)(struct fd_bo *bo, uint64_t *offset);
110         int (*cpu_prep)(struct fd_bo *bo, struct fd_pipe *pipe, uint32_t op);
111         void (*cpu_fini)(struct fd_bo *bo);
112         void (*destroy)(struct fd_bo *bo);
113 };
114
115 struct fd_bo {
116         struct fd_device *dev;
117         uint32_t size;
118         uint32_t handle;
119         uint32_t name;
120         void *map;
121         atomic_t refcnt;
122         struct fd_bo_funcs *funcs;
123 };
124
125 struct fd_bo *fd_bo_from_handle(struct fd_device *dev,
126                 uint32_t handle, uint32_t size);
127
128 #define ALIGN(v,a) (((v) + (a) - 1) & ~((a) - 1))
129 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
130
131 #define enable_debug 0  /* TODO make dynamic */
132
133 #define INFO_MSG(fmt, ...) \
134                 do { drmMsg("[I] "fmt " (%s:%d)\n", \
135                                 ##__VA_ARGS__, __FUNCTION__, __LINE__); } while (0)
136 #define DEBUG_MSG(fmt, ...) \
137                 do if (enable_debug) { drmMsg("[D] "fmt " (%s:%d)\n", \
138                                 ##__VA_ARGS__, __FUNCTION__, __LINE__); } while (0)
139 #define WARN_MSG(fmt, ...) \
140                 do { drmMsg("[W] "fmt " (%s:%d)\n", \
141                                 ##__VA_ARGS__, __FUNCTION__, __LINE__); } while (0)
142 #define ERROR_MSG(fmt, ...) \
143                 do { drmMsg("[E] " fmt " (%s:%d)\n", \
144                                 ##__VA_ARGS__, __FUNCTION__, __LINE__); } while (0)
145
146 #define U642VOID(x) ((void *)(unsigned long)(x))
147 #define VOID2U64(x) ((uint64_t)(unsigned long)(x))
148
149 #endif /* FREEDRENO_PRIV_H_ */