Tidy EnterVT, and don't call it from ScreenInit
[nouveau] / src / nouveau_drmif.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_DRMIF_H__
24 #define __NOUVEAU_DRMIF_H__
25
26 #include <stdint.h>
27 #include <xf86drm.h>
28 #include <nouveau_drm.h>
29
30 #include "nouveau_device.h"
31 #include "nouveau_channel.h"
32 #include "nouveau_grobj.h"
33 #include "nouveau_notifier.h"
34 #include "nouveau_bo.h"
35 #include "nouveau_local.h"
36
37 struct nouveau_device_priv {
38         struct nouveau_device base;
39
40         int fd;
41         drm_context_t ctx;
42         drmLock *lock;
43         int needs_close;
44 };
45 #define nouveau_device(n) ((struct nouveau_device_priv *)(n))
46
47 NOUVEAU_PRIVATE int
48 nouveau_device_open_existing(struct nouveau_device **, int close,
49                              int fd, drm_context_t ctx);
50
51 NOUVEAU_PRIVATE int
52 nouveau_device_open(struct nouveau_device **, const char *busid);
53
54 NOUVEAU_PRIVATE void
55 nouveau_device_close(struct nouveau_device **);
56
57 NOUVEAU_PRIVATE int
58 nouveau_device_get_param(struct nouveau_device *, uint64_t param, uint64_t *v);
59
60 NOUVEAU_PRIVATE int
61 nouveau_device_set_param(struct nouveau_device *, uint64_t param, uint64_t val);
62
63 struct nouveau_channel_priv {
64         struct nouveau_channel base;
65
66         struct drm_nouveau_channel_alloc drm;
67
68         struct {
69                 struct nouveau_grobj *grobj;
70                 uint32_t seq;
71         } subchannel[8];
72         uint32_t subc_sequence;
73
74         uint32_t *pushbuf;
75         void     *notifier_block;
76
77         volatile uint32_t *user;
78         volatile uint32_t *put;
79         volatile uint32_t *get;
80         volatile uint32_t *ref_cnt;
81
82         struct {
83                 uint32_t base, max;
84                 uint32_t cur, put;
85                 uint32_t free;
86
87                 int push_free;
88         } dma;
89
90         struct nouveau_bo_reloc *relocs;
91         int num_relocs;
92         int max_relocs;
93 };
94 #define nouveau_channel(n) ((struct nouveau_channel_priv *)(n))
95
96 NOUVEAU_PRIVATE int
97 nouveau_channel_alloc(struct nouveau_device *, uint32_t fb, uint32_t tt,
98                       struct nouveau_channel **);
99
100 NOUVEAU_PRIVATE void
101 nouveau_channel_free(struct nouveau_channel **);
102
103 struct nouveau_grobj_priv {
104         struct nouveau_grobj base;
105 };
106 #define nouveau_grobj(n) ((struct nouveau_grobj_priv *)(n))
107
108 NOUVEAU_PRIVATE int nouveau_grobj_alloc(struct nouveau_channel *, uint32_t handle,
109                                int class, struct nouveau_grobj **);
110 NOUVEAU_PRIVATE int nouveau_grobj_ref(struct nouveau_channel *, uint32_t handle,
111                              struct nouveau_grobj **);
112 NOUVEAU_PRIVATE void nouveau_grobj_free(struct nouveau_grobj **);
113
114
115 struct nouveau_notifier_priv {
116         struct nouveau_notifier base;
117
118         struct drm_nouveau_notifierobj_alloc drm;
119         volatile void *map;
120 };
121 #define nouveau_notifier(n) ((struct nouveau_notifier_priv *)(n))
122
123 NOUVEAU_PRIVATE int
124 nouveau_notifier_alloc(struct nouveau_channel *, uint32_t handle, int count,
125                        struct nouveau_notifier **);
126
127 NOUVEAU_PRIVATE void
128 nouveau_notifier_free(struct nouveau_notifier **);
129
130 NOUVEAU_PRIVATE void
131 nouveau_notifier_reset(struct nouveau_notifier *, int id);
132
133 NOUVEAU_PRIVATE uint32_t
134 nouveau_notifier_status(struct nouveau_notifier *, int id);
135
136 NOUVEAU_PRIVATE uint32_t
137 nouveau_notifier_return_val(struct nouveau_notifier *, int id);
138
139 NOUVEAU_PRIVATE int
140 nouveau_notifier_wait_status(struct nouveau_notifier *, int id, int status,
141                              int timeout);
142
143 struct nouveau_bo_priv {
144         struct nouveau_bo base;
145
146         struct drm_nouveau_mem_alloc drm;
147         void *map;
148
149         int refcount;
150 };
151
152 struct nouveau_bo_reloc {
153         struct nouveau_bo_priv *bo;
154         uint32_t *ptr;
155         uint32_t flags;
156         uint32_t data, vor, tor;
157 };
158
159 #define nouveau_bo(n) ((struct nouveau_bo_priv *)(n))
160
161 NOUVEAU_PRIVATE int
162 nouveau_bo_new(struct nouveau_device *, uint32_t flags, int align, int size,
163                struct nouveau_bo **);
164
165 NOUVEAU_PRIVATE int
166 nouveau_bo_ref(struct nouveau_device *, uint64_t handle, struct nouveau_bo **);
167
168 NOUVEAU_PRIVATE void
169 nouveau_bo_del(struct nouveau_bo **);
170
171 NOUVEAU_PRIVATE int
172 nouveau_bo_map(struct nouveau_bo *, uint32_t flags);
173
174 NOUVEAU_PRIVATE void
175 nouveau_bo_unmap(struct nouveau_bo *);
176
177 NOUVEAU_PRIVATE void
178 nouveau_bo_emit_reloc(struct nouveau_channel *chan, void *ptr,
179                       struct nouveau_bo *, uint32_t data, uint32_t flags,
180                       uint32_t vor, uint32_t tor);
181
182 NOUVEAU_PRIVATE void
183 nouveau_bo_validate(struct nouveau_channel *);
184
185 #endif