OSDN Git Service

intel: Fix up math errors when allocating very large BOs.
[android-x86/external-libdrm.git] / libdrm / nouveau / nouveau_private.h
1 /*
2  * Copyright 2007 Nouveau Project
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22
23 #ifndef __NOUVEAU_PRIVATE_H__
24 #define __NOUVEAU_PRIVATE_H__
25
26 #include <stdint.h>
27 #include <xf86drm.h>
28 #include <nouveau_drm.h>
29
30 #include "nouveau_drmif.h"
31 #include "nouveau_device.h"
32 #include "nouveau_channel.h"
33 #include "nouveau_grobj.h"
34 #include "nouveau_notifier.h"
35 #include "nouveau_bo.h"
36 #include "nouveau_resource.h"
37 #include "nouveau_pushbuf.h"
38
39 #define NOUVEAU_PUSHBUF_MAX_BUFFERS 1024
40 #define NOUVEAU_PUSHBUF_MAX_RELOCS 1024
41 struct nouveau_pushbuf_priv {
42         struct nouveau_pushbuf base;
43
44         int use_cal;
45         struct nouveau_bo *buffer;
46
47         unsigned *pushbuf;
48         unsigned  size;
49
50         struct drm_nouveau_gem_pushbuf_bo *buffers;
51         unsigned nr_buffers;
52         struct drm_nouveau_gem_pushbuf_reloc *relocs;
53         unsigned nr_relocs;
54
55         /*XXX: nomm */
56         struct nouveau_fence *fence;
57 };
58 #define nouveau_pushbuf(n) ((struct nouveau_pushbuf_priv *)(n))
59
60 #define pbbo_to_ptr(o) ((uint64_t)(unsigned long)(o))
61 #define ptr_to_pbbo(h) ((struct nouveau_pushbuf_bo *)(unsigned long)(h))
62 #define pbrel_to_ptr(o) ((uint64_t)(unsigned long)(o))
63 #define ptr_to_pbrel(h) ((struct nouveau_pushbuf_reloc *)(unsigned long)(h))
64 #define bo_to_ptr(o) ((uint64_t)(unsigned long)(o))
65 #define ptr_to_bo(h) ((struct nouveau_bo_priv *)(unsigned long)(h))
66
67 int
68 nouveau_pushbuf_init(struct nouveau_channel *);
69
70 struct nouveau_dma_priv {
71         uint32_t base;
72         uint32_t max;
73         uint32_t cur;
74         uint32_t put;
75         uint32_t free;
76
77         int push_free;
78 } dma;
79
80 struct nouveau_channel_priv {
81         struct nouveau_channel base;
82
83         struct drm_nouveau_channel_alloc drm;
84
85         void     *notifier_block;
86
87         struct nouveau_pushbuf_priv pb;
88
89         /*XXX: nomm */
90         volatile uint32_t *user, *put, *get, *ref_cnt;
91         uint32_t *pushbuf;
92         struct nouveau_dma_priv struct_dma;
93         struct nouveau_dma_priv *dma;
94         struct nouveau_fence *fence_head;
95         struct nouveau_fence *fence_tail;
96         uint32_t fence_sequence;
97         struct nouveau_grobj *fence_grobj;
98         struct nouveau_notifier *fence_ntfy;
99 };
100 #define nouveau_channel(n) ((struct nouveau_channel_priv *)(n))
101
102 struct nouveau_fence {
103         struct nouveau_channel *channel;
104 };
105
106 struct nouveau_fence_cb {
107         struct nouveau_fence_cb *next;
108         void (*func)(void *);
109         void *priv;
110 };
111
112 struct nouveau_fence_priv {
113         struct nouveau_fence base;
114         int refcount;
115
116         struct nouveau_fence *next;
117         struct nouveau_fence_cb *signal_cb;
118
119         uint32_t sequence;
120         int emitted;
121         int signalled;
122 };
123 #define nouveau_fence(n) ((struct nouveau_fence_priv *)(n))
124
125 int
126 nouveau_fence_new(struct nouveau_channel *, struct nouveau_fence **);
127
128 int
129 nouveau_fence_ref(struct nouveau_fence *, struct nouveau_fence **);
130
131 int
132 nouveau_fence_signal_cb(struct nouveau_fence *, void (*)(void *), void *);
133
134 void
135 nouveau_fence_emit(struct nouveau_fence *);
136
137 int
138 nouveau_fence_wait(struct nouveau_fence **);
139
140 void
141 nouveau_fence_flush(struct nouveau_channel *);
142
143 struct nouveau_grobj_priv {
144         struct nouveau_grobj base;
145 };
146 #define nouveau_grobj(n) ((struct nouveau_grobj_priv *)(n))
147
148 struct nouveau_notifier_priv {
149         struct nouveau_notifier base;
150
151         struct drm_nouveau_notifierobj_alloc drm;
152         volatile void *map;
153 };
154 #define nouveau_notifier(n) ((struct nouveau_notifier_priv *)(n))
155
156 struct nouveau_bo_priv {
157         struct nouveau_bo base;
158         int refcount;
159
160         /* Buffer configuration + usage hints */
161         unsigned flags;
162         unsigned size;
163         unsigned align;
164         int user;
165
166         /* Tracking */
167         struct drm_nouveau_gem_pushbuf_bo *pending;
168         struct nouveau_channel *pending_channel;
169         int write_marker;
170
171         /* Userspace object */
172         void *sysmem;
173
174         /* Kernel object */
175         uint32_t global_handle;
176         drm_handle_t handle;
177         uint64_t map_handle;
178         void *map;
179
180         /* Last known information from kernel on buffer status */
181         int pinned;
182         uint64_t offset;
183         uint32_t domain;
184
185         /*XXX: nomm stuff */
186         struct nouveau_fence *fence;
187         struct nouveau_fence *wr_fence;
188 };
189 #define nouveau_bo(n) ((struct nouveau_bo_priv *)(n))
190
191 int
192 nouveau_bo_init(struct nouveau_device *);
193
194 void
195 nouveau_bo_takedown(struct nouveau_device *);
196
197 struct drm_nouveau_gem_pushbuf_bo *
198 nouveau_bo_emit_buffer(struct nouveau_channel *, struct nouveau_bo *);
199
200 int
201 nouveau_bo_validate_nomm(struct nouveau_bo_priv *, uint32_t);
202
203 #include "nouveau_dma.h"
204 #endif