1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
/*
* Copyright 2007 Jérôme Glisse
* Copyright 2007 Alex Deucher
* Copyright 2007 Dave Airlie
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/*
* Authors:
* Jerome Glisse <glisse@freedesktop.org>
*/
#include "drm_pciids.h"
#include "radeon_ms.h"
#include "amd_legacy_fence.h"
static uint32_t radeon_ms_mem_prios[] = {
DRM_BO_MEM_VRAM,
DRM_BO_MEM_TT,
DRM_BO_MEM_LOCAL,
};
static uint32_t radeon_ms_busy_prios[] = {
DRM_BO_MEM_TT,
DRM_BO_MEM_VRAM,
DRM_BO_MEM_LOCAL,
};
struct drm_bo_driver radeon_ms_bo_driver = {
.mem_type_prio = radeon_ms_mem_prios,
.mem_busy_prio = radeon_ms_busy_prios,
.num_mem_type_prio = sizeof(radeon_ms_mem_prios)/sizeof(uint32_t),
.num_mem_busy_prio = sizeof(radeon_ms_busy_prios)/sizeof(uint32_t),
.create_ttm_backend_entry = radeon_ms_create_ttm_backend,
.fence_type = r3xx_fence_types,
.invalidate_caches = radeon_ms_invalidate_caches,
.init_mem_type = radeon_ms_init_mem_type,
.evict_flags = radeon_ms_evict_flags,
.move = radeon_ms_bo_move,
.ttm_cache_flush = radeon_ms_ttm_flush,
};
struct drm_ioctl_desc radeon_ms_ioctls[] = {
DRM_IOCTL_DEF(DRM_RADEON_EXECBUFFER, radeon_ms_execbuffer, DRM_AUTH),
};
int radeon_ms_num_ioctls = DRM_ARRAY_SIZE(radeon_ms_ioctls);
int radeon_ms_driver_dma_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
struct drm_device_dma *dma = dev->dma;
struct drm_dma *d = data;
LOCK_TEST_WITH_RETURN(dev, file_priv);
/* Please don't send us buffers.
*/
if (d->send_count != 0) {
DRM_ERROR("Process %d trying to send %d buffers via drmDMA\n",
DRM_CURRENTPID, d->send_count);
return -EINVAL;
}
/* Don't ask us buffer neither :)
*/
DRM_ERROR("Process %d trying to get %d buffers (of %d max)\n",
DRM_CURRENTPID, d->request_count, dma->buf_count);
return -EINVAL;
}
void radeon_ms_driver_lastclose(struct drm_device * dev)
{
}
int radeon_ms_driver_load(struct drm_device *dev, unsigned long flags)
{
struct drm_radeon_private *dev_priv;
int ret = 0;
DRM_INFO("[radeon_ms] loading\n");
/* allocate and clear device private structure */
dev_priv = drm_alloc(sizeof(struct drm_radeon_private), DRM_MEM_DRIVER);
if (dev_priv == NULL)
return -ENOMEM;
memset(dev_priv, 0, sizeof(struct drm_radeon_private));
dev->dev_private = (void *)dev_priv;
/* initialize modesetting structure (must be done here) */
drm_mode_config_init(dev);
/* flags correspond to chipset family */
dev_priv->usec_timeout = 100;
dev_priv->family = flags & 0xffffU;
dev_priv->bus_type = flags & 0xff0000U;
/* initialize family functions */
ret = radeon_ms_family_init(dev);
if (ret != 0) {
radeon_ms_driver_unload(dev);
return ret;
}
dev_priv->fence = drm_alloc(sizeof(struct legacy_fence), DRM_MEM_DRIVER);
if (dev_priv->fence == NULL) {
radeon_ms_driver_unload(dev);
return -ENOMEM;
}
memset(dev_priv->fence, 0, sizeof(struct legacy_fence));
/* we don't want userspace to be able to map this so don't use
* drm_addmap */
dev_priv->mmio.offset = drm_get_resource_start(dev, 2);
dev_priv->mmio.size = drm_get_resource_len(dev, 2);
dev_priv->mmio.type = _DRM_REGISTERS;
dev_priv->mmio.flags = _DRM_RESTRICTED;
drm_core_ioremap(&dev_priv->mmio, dev);
/* map vram FIXME: IGP likely don't have any of this */
dev_priv->vram.offset = drm_get_resource_start(dev, 0);
dev_priv->vram.size = drm_get_resource_len(dev, 0);
dev_priv->vram.type = _DRM_FRAME_BUFFER;
dev_priv->vram.flags = _DRM_RESTRICTED;
drm_core_ioremap(&dev_priv->vram, dev);
/* save radeon initial state which will be restored upon module
* exit */
radeon_ms_state_save(dev, &dev_priv->load_state);
dev_priv->restore_state = 1;
memcpy(&dev_priv->driver_state, &dev_priv->load_state,
sizeof(struct radeon_state));
/* initialize irq */
ret = radeon_ms_irq_init(dev);
if (ret != 0) {
radeon_ms_driver_unload(dev);
return ret;
}
/* init bo driver */
dev_priv->fence_id_last = 1;
dev_priv->fence_reg = SCRATCH_REG2;
drm_bo_driver_init(dev);
/* initialize vram */
ret = drm_bo_init_mm(dev, DRM_BO_MEM_VRAM, 0, dev_priv->vram.size, 1);
if (ret != 0) {
radeon_ms_driver_unload(dev);
return ret;
}
/* initialize gpu address space (only after) VRAM initialization */
ret = radeon_ms_gpu_initialize(dev);
if (ret != 0) {
radeon_ms_driver_unload(dev);
return ret;
}
radeon_ms_gpu_restore(dev, &dev_priv->driver_state);
/* initialize ttm */
ret = drm_bo_init_mm(dev, DRM_BO_MEM_TT, 0,
dev_priv->gpu_gart_size / RADEON_PAGE_SIZE, 1);
if (ret != 0) {
radeon_ms_driver_unload(dev);
return ret;
}
/* initialize ring buffer */
/* set ring size to 4Mo FIXME: should make a parameter for this */
dev_priv->write_back_area_size = 4 * 1024;
dev_priv->ring_buffer_size = 4 * 1024 * 1024;
ret = radeon_ms_cp_init(dev);
if (ret != 0) {
radeon_ms_driver_unload(dev);
return ret;
}
/* initialize modesetting */
dev->mode_config.min_width = 0;
dev->mode_config.min_height = 0;
dev->mode_config.max_width = 4096;
dev->mode_config.max_height = 4096;
dev->mode_config.fb_base = dev_priv->vram.offset;
ret = radeon_ms_crtc_create(dev, 1);
if (ret != 0) {
radeon_ms_driver_unload(dev);
return ret;
}
ret = radeon_ms_outputs_from_rom(dev);
if (ret < 0) {
radeon_ms_driver_unload(dev);
return ret;
} else if (!ret) {
ret = radeon_ms_outputs_from_properties(dev);
if (ret < 0) {
radeon_ms_driver_unload(dev);
return ret;
} else if (ret == 0) {
DRM_INFO("[radeon_ms] no outputs !\n");
}
} else {
DRM_INFO("[radeon_ms] added %d outputs from rom.\n", ret);
}
ret = radeon_ms_connectors_from_rom(dev);
if (ret < 0) {
radeon_ms_driver_unload(dev);
return ret;
} else if (!ret) {
ret = radeon_ms_connectors_from_properties(dev);
if (ret < 0) {
radeon_ms_driver_unload(dev);
return ret;
} else if (!ret) {
DRM_INFO("[radeon_ms] no connectors !\n");
}
} else {
DRM_INFO("[radeon_ms] added %d connectors from rom.\n", ret);
}
radeon_ms_outputs_save(dev, &dev_priv->load_state);
drm_initial_config(dev, false);
ret = drm_irq_install(dev);
if (ret != 0) {
radeon_ms_driver_unload(dev);
return ret;
}
DRM_INFO("[radeon_ms] successfull initialization\n");
return 0;
}
int radeon_ms_driver_open(struct drm_device * dev, struct drm_file *file_priv)
{
return 0;
}
int radeon_ms_driver_unload(struct drm_device *dev)
{
struct drm_radeon_private *dev_priv = dev->dev_private;
if (dev_priv == NULL) {
return 0;
}
/* cleanup modesetting */
drm_mode_config_cleanup(dev);
DRM_INFO("[radeon_ms] modesetting clean\n");
radeon_ms_outputs_restore(dev, &dev_priv->load_state);
radeon_ms_connectors_destroy(dev);
radeon_ms_outputs_destroy(dev);
/* shutdown cp engine */
radeon_ms_cp_finish(dev);
DRM_INFO("[radeon_ms] cp clean\n");
drm_irq_uninstall(dev);
DRM_INFO("[radeon_ms] irq uninstalled\n");
DRM_INFO("[radeon_ms] unloading\n");
/* clean ttm memory manager */
mutex_lock(&dev->struct_mutex);
if (drm_bo_clean_mm(dev, DRM_BO_MEM_TT, 1)) {
DRM_ERROR("TT memory manager not clean. Delaying takedown\n");
}
mutex_unlock(&dev->struct_mutex);
DRM_INFO("[radeon_ms] TT memory clean\n");
/* finish */
if (dev_priv->bus_finish) {
dev_priv->bus_finish(dev);
}
DRM_INFO("[radeon_ms] bus down\n");
/* clean vram memory manager */
mutex_lock(&dev->struct_mutex);
if (drm_bo_clean_mm(dev, DRM_BO_MEM_VRAM, 1)) {
DRM_ERROR("VRAM memory manager not clean. Delaying takedown\n");
}
mutex_unlock(&dev->struct_mutex);
DRM_INFO("[radeon_ms] VRAM memory clean\n");
/* clean memory manager */
drm_bo_driver_finish(dev);
DRM_INFO("[radeon_ms] memory manager clean\n");
/* restore card state */
if (dev_priv->restore_state) {
radeon_ms_state_restore(dev, &dev_priv->load_state);
}
DRM_INFO("[radeon_ms] state restored\n");
if (dev_priv->mmio.handle) {
drm_core_ioremapfree(&dev_priv->mmio, dev);
}
if (dev_priv->vram.handle) {
drm_core_ioremapfree(&dev_priv->vram, dev);
}
DRM_INFO("[radeon_ms] map released\n");
drm_free(dev_priv->fence, sizeof(struct legacy_fence), DRM_MEM_DRIVER);
drm_free(dev_priv, sizeof(*dev_priv), DRM_MEM_DRIVER);
dev->dev_private = NULL;
DRM_INFO("[radeon_ms] that's all the folks\n");
return 0;
}
|