This source file includes following definitions.
- radeon_has_atpx
- radeon_driver_unload_kms
- radeon_driver_load_kms
- radeon_set_filp_rights
- radeon_info_ioctl
- radeon_driver_lastclose_kms
- radeon_driver_open_kms
- radeon_driver_postclose_kms
- radeon_get_vblank_counter_kms
- radeon_enable_vblank_kms
- radeon_disable_vblank_kms
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 #include <linux/pm_runtime.h>
30 #include <linux/slab.h>
31 #include <linux/uaccess.h>
32 #include <linux/vga_switcheroo.h>
33
34 #include <drm/drm_agpsupport.h>
35 #include <drm/drm_fb_helper.h>
36 #include <drm/drm_file.h>
37 #include <drm/drm_ioctl.h>
38 #include <drm/drm_pci.h>
39 #include <drm/radeon_drm.h>
40
41 #include "radeon.h"
42 #include "radeon_asic.h"
43
44 #if defined(CONFIG_VGA_SWITCHEROO)
45 bool radeon_has_atpx(void);
46 #else
47 static inline bool radeon_has_atpx(void) { return false; }
48 #endif
49
50
51
52
53
54
55
56
57
58
59
60
61 void radeon_driver_unload_kms(struct drm_device *dev)
62 {
63 struct radeon_device *rdev = dev->dev_private;
64
65 if (rdev == NULL)
66 return;
67
68 if (rdev->rmmio == NULL)
69 goto done_free;
70
71 if (radeon_is_px(dev)) {
72 pm_runtime_get_sync(dev->dev);
73 pm_runtime_forbid(dev->dev);
74 }
75
76 radeon_acpi_fini(rdev);
77
78 radeon_modeset_fini(rdev);
79 radeon_device_fini(rdev);
80
81 if (dev->agp)
82 arch_phys_wc_del(dev->agp->agp_mtrr);
83 kfree(dev->agp);
84 dev->agp = NULL;
85
86 done_free:
87 kfree(rdev);
88 dev->dev_private = NULL;
89 }
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104 int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags)
105 {
106 struct radeon_device *rdev;
107 int r, acpi_status;
108
109 rdev = kzalloc(sizeof(struct radeon_device), GFP_KERNEL);
110 if (rdev == NULL) {
111 return -ENOMEM;
112 }
113 dev->dev_private = (void *)rdev;
114
115
116 if (pci_find_capability(dev->pdev, PCI_CAP_ID_AGP)) {
117 flags |= RADEON_IS_AGP;
118 } else if (pci_is_pcie(dev->pdev)) {
119 flags |= RADEON_IS_PCIE;
120 } else {
121 flags |= RADEON_IS_PCI;
122 }
123
124 if ((radeon_runtime_pm != 0) &&
125 radeon_has_atpx() &&
126 ((flags & RADEON_IS_IGP) == 0) &&
127 !pci_is_thunderbolt_attached(dev->pdev))
128 flags |= RADEON_IS_PX;
129
130
131
132
133
134
135
136 r = radeon_device_init(rdev, dev, dev->pdev, flags);
137 if (r) {
138 dev_err(&dev->pdev->dev, "Fatal error during GPU init\n");
139 goto out;
140 }
141
142
143
144
145
146 r = radeon_modeset_init(rdev);
147 if (r)
148 dev_err(&dev->pdev->dev, "Fatal error during modeset init\n");
149
150
151
152
153 if (!r) {
154 acpi_status = radeon_acpi_init(rdev);
155 if (acpi_status)
156 dev_dbg(&dev->pdev->dev,
157 "Error during ACPI methods call\n");
158 }
159
160 if (radeon_is_px(dev)) {
161 dev_pm_set_driver_flags(dev->dev, DPM_FLAG_NEVER_SKIP);
162 pm_runtime_use_autosuspend(dev->dev);
163 pm_runtime_set_autosuspend_delay(dev->dev, 5000);
164 pm_runtime_set_active(dev->dev);
165 pm_runtime_allow(dev->dev);
166 pm_runtime_mark_last_busy(dev->dev);
167 pm_runtime_put_autosuspend(dev->dev);
168 }
169
170 out:
171 if (r)
172 radeon_driver_unload_kms(dev);
173
174
175 return r;
176 }
177
178
179
180
181
182
183
184
185
186
187
188 static void radeon_set_filp_rights(struct drm_device *dev,
189 struct drm_file **owner,
190 struct drm_file *applier,
191 uint32_t *value)
192 {
193 struct radeon_device *rdev = dev->dev_private;
194
195 mutex_lock(&rdev->gem.mutex);
196 if (*value == 1) {
197
198 if (!*owner)
199 *owner = applier;
200 } else if (*value == 0) {
201
202 if (*owner == applier)
203 *owner = NULL;
204 }
205 *value = *owner == applier ? 1 : 0;
206 mutex_unlock(&rdev->gem.mutex);
207 }
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224 static int radeon_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
225 {
226 struct radeon_device *rdev = dev->dev_private;
227 struct drm_radeon_info *info = data;
228 struct radeon_mode_info *minfo = &rdev->mode_info;
229 uint32_t *value, value_tmp, *value_ptr, value_size;
230 uint64_t value64;
231 struct drm_crtc *crtc;
232 int i, found;
233
234 value_ptr = (uint32_t *)((unsigned long)info->value);
235 value = &value_tmp;
236 value_size = sizeof(uint32_t);
237
238 switch (info->request) {
239 case RADEON_INFO_DEVICE_ID:
240 *value = dev->pdev->device;
241 break;
242 case RADEON_INFO_NUM_GB_PIPES:
243 *value = rdev->num_gb_pipes;
244 break;
245 case RADEON_INFO_NUM_Z_PIPES:
246 *value = rdev->num_z_pipes;
247 break;
248 case RADEON_INFO_ACCEL_WORKING:
249
250 if ((rdev->family >= CHIP_CEDAR) && (rdev->family <= CHIP_HEMLOCK))
251 *value = false;
252 else
253 *value = rdev->accel_working;
254 break;
255 case RADEON_INFO_CRTC_FROM_ID:
256 if (copy_from_user(value, value_ptr, sizeof(uint32_t))) {
257 DRM_ERROR("copy_from_user %s:%u\n", __func__, __LINE__);
258 return -EFAULT;
259 }
260 for (i = 0, found = 0; i < rdev->num_crtc; i++) {
261 crtc = (struct drm_crtc *)minfo->crtcs[i];
262 if (crtc && crtc->base.id == *value) {
263 struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
264 *value = radeon_crtc->crtc_id;
265 found = 1;
266 break;
267 }
268 }
269 if (!found) {
270 DRM_DEBUG_KMS("unknown crtc id %d\n", *value);
271 return -EINVAL;
272 }
273 break;
274 case RADEON_INFO_ACCEL_WORKING2:
275 if (rdev->family == CHIP_HAWAII) {
276 if (rdev->accel_working) {
277 if (rdev->new_fw)
278 *value = 3;
279 else
280 *value = 2;
281 } else {
282 *value = 0;
283 }
284 } else {
285 *value = rdev->accel_working;
286 }
287 break;
288 case RADEON_INFO_TILING_CONFIG:
289 if (rdev->family >= CHIP_BONAIRE)
290 *value = rdev->config.cik.tile_config;
291 else if (rdev->family >= CHIP_TAHITI)
292 *value = rdev->config.si.tile_config;
293 else if (rdev->family >= CHIP_CAYMAN)
294 *value = rdev->config.cayman.tile_config;
295 else if (rdev->family >= CHIP_CEDAR)
296 *value = rdev->config.evergreen.tile_config;
297 else if (rdev->family >= CHIP_RV770)
298 *value = rdev->config.rv770.tile_config;
299 else if (rdev->family >= CHIP_R600)
300 *value = rdev->config.r600.tile_config;
301 else {
302 DRM_DEBUG_KMS("tiling config is r6xx+ only!\n");
303 return -EINVAL;
304 }
305 break;
306 case RADEON_INFO_WANT_HYPERZ:
307
308
309
310
311
312
313 if (copy_from_user(value, value_ptr, sizeof(uint32_t))) {
314 DRM_ERROR("copy_from_user %s:%u\n", __func__, __LINE__);
315 return -EFAULT;
316 }
317 if (*value >= 2) {
318 DRM_DEBUG_KMS("WANT_HYPERZ: invalid value %d\n", *value);
319 return -EINVAL;
320 }
321 radeon_set_filp_rights(dev, &rdev->hyperz_filp, filp, value);
322 break;
323 case RADEON_INFO_WANT_CMASK:
324
325 if (copy_from_user(value, value_ptr, sizeof(uint32_t))) {
326 DRM_ERROR("copy_from_user %s:%u\n", __func__, __LINE__);
327 return -EFAULT;
328 }
329 if (*value >= 2) {
330 DRM_DEBUG_KMS("WANT_CMASK: invalid value %d\n", *value);
331 return -EINVAL;
332 }
333 radeon_set_filp_rights(dev, &rdev->cmask_filp, filp, value);
334 break;
335 case RADEON_INFO_CLOCK_CRYSTAL_FREQ:
336
337 if (rdev->asic->get_xclk)
338 *value = radeon_get_xclk(rdev) * 10;
339 else
340 *value = rdev->clock.spll.reference_freq * 10;
341 break;
342 case RADEON_INFO_NUM_BACKENDS:
343 if (rdev->family >= CHIP_BONAIRE)
344 *value = rdev->config.cik.max_backends_per_se *
345 rdev->config.cik.max_shader_engines;
346 else if (rdev->family >= CHIP_TAHITI)
347 *value = rdev->config.si.max_backends_per_se *
348 rdev->config.si.max_shader_engines;
349 else if (rdev->family >= CHIP_CAYMAN)
350 *value = rdev->config.cayman.max_backends_per_se *
351 rdev->config.cayman.max_shader_engines;
352 else if (rdev->family >= CHIP_CEDAR)
353 *value = rdev->config.evergreen.max_backends;
354 else if (rdev->family >= CHIP_RV770)
355 *value = rdev->config.rv770.max_backends;
356 else if (rdev->family >= CHIP_R600)
357 *value = rdev->config.r600.max_backends;
358 else {
359 return -EINVAL;
360 }
361 break;
362 case RADEON_INFO_NUM_TILE_PIPES:
363 if (rdev->family >= CHIP_BONAIRE)
364 *value = rdev->config.cik.max_tile_pipes;
365 else if (rdev->family >= CHIP_TAHITI)
366 *value = rdev->config.si.max_tile_pipes;
367 else if (rdev->family >= CHIP_CAYMAN)
368 *value = rdev->config.cayman.max_tile_pipes;
369 else if (rdev->family >= CHIP_CEDAR)
370 *value = rdev->config.evergreen.max_tile_pipes;
371 else if (rdev->family >= CHIP_RV770)
372 *value = rdev->config.rv770.max_tile_pipes;
373 else if (rdev->family >= CHIP_R600)
374 *value = rdev->config.r600.max_tile_pipes;
375 else {
376 return -EINVAL;
377 }
378 break;
379 case RADEON_INFO_FUSION_GART_WORKING:
380 *value = 1;
381 break;
382 case RADEON_INFO_BACKEND_MAP:
383 if (rdev->family >= CHIP_BONAIRE)
384 *value = rdev->config.cik.backend_map;
385 else if (rdev->family >= CHIP_TAHITI)
386 *value = rdev->config.si.backend_map;
387 else if (rdev->family >= CHIP_CAYMAN)
388 *value = rdev->config.cayman.backend_map;
389 else if (rdev->family >= CHIP_CEDAR)
390 *value = rdev->config.evergreen.backend_map;
391 else if (rdev->family >= CHIP_RV770)
392 *value = rdev->config.rv770.backend_map;
393 else if (rdev->family >= CHIP_R600)
394 *value = rdev->config.r600.backend_map;
395 else {
396 return -EINVAL;
397 }
398 break;
399 case RADEON_INFO_VA_START:
400
401 if (rdev->family < CHIP_CAYMAN)
402 return -EINVAL;
403 *value = RADEON_VA_RESERVED_SIZE;
404 break;
405 case RADEON_INFO_IB_VM_MAX_SIZE:
406
407 if (rdev->family < CHIP_CAYMAN)
408 return -EINVAL;
409 *value = RADEON_IB_VM_MAX_SIZE;
410 break;
411 case RADEON_INFO_MAX_PIPES:
412 if (rdev->family >= CHIP_BONAIRE)
413 *value = rdev->config.cik.max_cu_per_sh;
414 else if (rdev->family >= CHIP_TAHITI)
415 *value = rdev->config.si.max_cu_per_sh;
416 else if (rdev->family >= CHIP_CAYMAN)
417 *value = rdev->config.cayman.max_pipes_per_simd;
418 else if (rdev->family >= CHIP_CEDAR)
419 *value = rdev->config.evergreen.max_pipes;
420 else if (rdev->family >= CHIP_RV770)
421 *value = rdev->config.rv770.max_pipes;
422 else if (rdev->family >= CHIP_R600)
423 *value = rdev->config.r600.max_pipes;
424 else {
425 return -EINVAL;
426 }
427 break;
428 case RADEON_INFO_TIMESTAMP:
429 if (rdev->family < CHIP_R600) {
430 DRM_DEBUG_KMS("timestamp is r6xx+ only!\n");
431 return -EINVAL;
432 }
433 value = (uint32_t*)&value64;
434 value_size = sizeof(uint64_t);
435 value64 = radeon_get_gpu_clock_counter(rdev);
436 break;
437 case RADEON_INFO_MAX_SE:
438 if (rdev->family >= CHIP_BONAIRE)
439 *value = rdev->config.cik.max_shader_engines;
440 else if (rdev->family >= CHIP_TAHITI)
441 *value = rdev->config.si.max_shader_engines;
442 else if (rdev->family >= CHIP_CAYMAN)
443 *value = rdev->config.cayman.max_shader_engines;
444 else if (rdev->family >= CHIP_CEDAR)
445 *value = rdev->config.evergreen.num_ses;
446 else
447 *value = 1;
448 break;
449 case RADEON_INFO_MAX_SH_PER_SE:
450 if (rdev->family >= CHIP_BONAIRE)
451 *value = rdev->config.cik.max_sh_per_se;
452 else if (rdev->family >= CHIP_TAHITI)
453 *value = rdev->config.si.max_sh_per_se;
454 else
455 return -EINVAL;
456 break;
457 case RADEON_INFO_FASTFB_WORKING:
458 *value = rdev->fastfb_working;
459 break;
460 case RADEON_INFO_RING_WORKING:
461 if (copy_from_user(value, value_ptr, sizeof(uint32_t))) {
462 DRM_ERROR("copy_from_user %s:%u\n", __func__, __LINE__);
463 return -EFAULT;
464 }
465 switch (*value) {
466 case RADEON_CS_RING_GFX:
467 case RADEON_CS_RING_COMPUTE:
468 *value = rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready;
469 break;
470 case RADEON_CS_RING_DMA:
471 *value = rdev->ring[R600_RING_TYPE_DMA_INDEX].ready;
472 *value |= rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX].ready;
473 break;
474 case RADEON_CS_RING_UVD:
475 *value = rdev->ring[R600_RING_TYPE_UVD_INDEX].ready;
476 break;
477 case RADEON_CS_RING_VCE:
478 *value = rdev->ring[TN_RING_TYPE_VCE1_INDEX].ready;
479 break;
480 default:
481 return -EINVAL;
482 }
483 break;
484 case RADEON_INFO_SI_TILE_MODE_ARRAY:
485 if (rdev->family >= CHIP_BONAIRE) {
486 value = rdev->config.cik.tile_mode_array;
487 value_size = sizeof(uint32_t)*32;
488 } else if (rdev->family >= CHIP_TAHITI) {
489 value = rdev->config.si.tile_mode_array;
490 value_size = sizeof(uint32_t)*32;
491 } else {
492 DRM_DEBUG_KMS("tile mode array is si+ only!\n");
493 return -EINVAL;
494 }
495 break;
496 case RADEON_INFO_CIK_MACROTILE_MODE_ARRAY:
497 if (rdev->family >= CHIP_BONAIRE) {
498 value = rdev->config.cik.macrotile_mode_array;
499 value_size = sizeof(uint32_t)*16;
500 } else {
501 DRM_DEBUG_KMS("macrotile mode array is cik+ only!\n");
502 return -EINVAL;
503 }
504 break;
505 case RADEON_INFO_SI_CP_DMA_COMPUTE:
506 *value = 1;
507 break;
508 case RADEON_INFO_SI_BACKEND_ENABLED_MASK:
509 if (rdev->family >= CHIP_BONAIRE) {
510 *value = rdev->config.cik.backend_enable_mask;
511 } else if (rdev->family >= CHIP_TAHITI) {
512 *value = rdev->config.si.backend_enable_mask;
513 } else {
514 DRM_DEBUG_KMS("BACKEND_ENABLED_MASK is si+ only!\n");
515 }
516 break;
517 case RADEON_INFO_MAX_SCLK:
518 if ((rdev->pm.pm_method == PM_METHOD_DPM) &&
519 rdev->pm.dpm_enabled)
520 *value = rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.sclk * 10;
521 else
522 *value = rdev->pm.default_sclk * 10;
523 break;
524 case RADEON_INFO_VCE_FW_VERSION:
525 *value = rdev->vce.fw_version;
526 break;
527 case RADEON_INFO_VCE_FB_VERSION:
528 *value = rdev->vce.fb_version;
529 break;
530 case RADEON_INFO_NUM_BYTES_MOVED:
531 value = (uint32_t*)&value64;
532 value_size = sizeof(uint64_t);
533 value64 = atomic64_read(&rdev->num_bytes_moved);
534 break;
535 case RADEON_INFO_VRAM_USAGE:
536 value = (uint32_t*)&value64;
537 value_size = sizeof(uint64_t);
538 value64 = atomic64_read(&rdev->vram_usage);
539 break;
540 case RADEON_INFO_GTT_USAGE:
541 value = (uint32_t*)&value64;
542 value_size = sizeof(uint64_t);
543 value64 = atomic64_read(&rdev->gtt_usage);
544 break;
545 case RADEON_INFO_ACTIVE_CU_COUNT:
546 if (rdev->family >= CHIP_BONAIRE)
547 *value = rdev->config.cik.active_cus;
548 else if (rdev->family >= CHIP_TAHITI)
549 *value = rdev->config.si.active_cus;
550 else if (rdev->family >= CHIP_CAYMAN)
551 *value = rdev->config.cayman.active_simds;
552 else if (rdev->family >= CHIP_CEDAR)
553 *value = rdev->config.evergreen.active_simds;
554 else if (rdev->family >= CHIP_RV770)
555 *value = rdev->config.rv770.active_simds;
556 else if (rdev->family >= CHIP_R600)
557 *value = rdev->config.r600.active_simds;
558 else
559 *value = 1;
560 break;
561 case RADEON_INFO_CURRENT_GPU_TEMP:
562
563 if (rdev->asic->pm.get_temperature)
564 *value = radeon_get_temperature(rdev);
565 else
566 *value = 0;
567 break;
568 case RADEON_INFO_CURRENT_GPU_SCLK:
569
570 if (rdev->pm.dpm_enabled)
571 *value = radeon_dpm_get_current_sclk(rdev) / 100;
572 else
573 *value = rdev->pm.current_sclk / 100;
574 break;
575 case RADEON_INFO_CURRENT_GPU_MCLK:
576
577 if (rdev->pm.dpm_enabled)
578 *value = radeon_dpm_get_current_mclk(rdev) / 100;
579 else
580 *value = rdev->pm.current_mclk / 100;
581 break;
582 case RADEON_INFO_READ_REG:
583 if (copy_from_user(value, value_ptr, sizeof(uint32_t))) {
584 DRM_ERROR("copy_from_user %s:%u\n", __func__, __LINE__);
585 return -EFAULT;
586 }
587 if (radeon_get_allowed_info_register(rdev, *value, value))
588 return -EINVAL;
589 break;
590 case RADEON_INFO_VA_UNMAP_WORKING:
591 *value = true;
592 break;
593 case RADEON_INFO_GPU_RESET_COUNTER:
594 *value = atomic_read(&rdev->gpu_reset_counter);
595 break;
596 default:
597 DRM_DEBUG_KMS("Invalid request %d\n", info->request);
598 return -EINVAL;
599 }
600 if (copy_to_user(value_ptr, (char*)value, value_size)) {
601 DRM_ERROR("copy_to_user %s:%u\n", __func__, __LINE__);
602 return -EFAULT;
603 }
604 return 0;
605 }
606
607
608
609
610
611
612
613
614
615
616
617
618 void radeon_driver_lastclose_kms(struct drm_device *dev)
619 {
620 drm_fb_helper_lastclose(dev);
621 vga_switcheroo_process_delayed_switch();
622 }
623
624
625
626
627
628
629
630
631
632
633 int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
634 {
635 struct radeon_device *rdev = dev->dev_private;
636 int r;
637
638 file_priv->driver_priv = NULL;
639
640 r = pm_runtime_get_sync(dev->dev);
641 if (r < 0)
642 return r;
643
644
645 if (rdev->family >= CHIP_CAYMAN) {
646 struct radeon_fpriv *fpriv;
647 struct radeon_vm *vm;
648
649 fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL);
650 if (unlikely(!fpriv)) {
651 r = -ENOMEM;
652 goto out_suspend;
653 }
654
655 if (rdev->accel_working) {
656 vm = &fpriv->vm;
657 r = radeon_vm_init(rdev, vm);
658 if (r) {
659 kfree(fpriv);
660 goto out_suspend;
661 }
662
663 r = radeon_bo_reserve(rdev->ring_tmp_bo.bo, false);
664 if (r) {
665 radeon_vm_fini(rdev, vm);
666 kfree(fpriv);
667 goto out_suspend;
668 }
669
670
671
672 vm->ib_bo_va = radeon_vm_bo_add(rdev, vm,
673 rdev->ring_tmp_bo.bo);
674 r = radeon_vm_bo_set_addr(rdev, vm->ib_bo_va,
675 RADEON_VA_IB_OFFSET,
676 RADEON_VM_PAGE_READABLE |
677 RADEON_VM_PAGE_SNOOPED);
678 if (r) {
679 radeon_vm_fini(rdev, vm);
680 kfree(fpriv);
681 goto out_suspend;
682 }
683 }
684 file_priv->driver_priv = fpriv;
685 }
686
687 out_suspend:
688 pm_runtime_mark_last_busy(dev->dev);
689 pm_runtime_put_autosuspend(dev->dev);
690 return r;
691 }
692
693
694
695
696
697
698
699
700
701
702 void radeon_driver_postclose_kms(struct drm_device *dev,
703 struct drm_file *file_priv)
704 {
705 struct radeon_device *rdev = dev->dev_private;
706
707 pm_runtime_get_sync(dev->dev);
708
709 mutex_lock(&rdev->gem.mutex);
710 if (rdev->hyperz_filp == file_priv)
711 rdev->hyperz_filp = NULL;
712 if (rdev->cmask_filp == file_priv)
713 rdev->cmask_filp = NULL;
714 mutex_unlock(&rdev->gem.mutex);
715
716 radeon_uvd_free_handles(rdev, file_priv);
717 radeon_vce_free_handles(rdev, file_priv);
718
719
720 if (rdev->family >= CHIP_CAYMAN && file_priv->driver_priv) {
721 struct radeon_fpriv *fpriv = file_priv->driver_priv;
722 struct radeon_vm *vm = &fpriv->vm;
723 int r;
724
725 if (rdev->accel_working) {
726 r = radeon_bo_reserve(rdev->ring_tmp_bo.bo, false);
727 if (!r) {
728 if (vm->ib_bo_va)
729 radeon_vm_bo_rmv(rdev, vm->ib_bo_va);
730 radeon_bo_unreserve(rdev->ring_tmp_bo.bo);
731 }
732 radeon_vm_fini(rdev, vm);
733 }
734
735 kfree(fpriv);
736 file_priv->driver_priv = NULL;
737 }
738 pm_runtime_mark_last_busy(dev->dev);
739 pm_runtime_put_autosuspend(dev->dev);
740 }
741
742
743
744
745
746
747
748
749
750
751
752
753
754 u32 radeon_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe)
755 {
756 int vpos, hpos, stat;
757 u32 count;
758 struct radeon_device *rdev = dev->dev_private;
759
760 if (pipe >= rdev->num_crtc) {
761 DRM_ERROR("Invalid crtc %u\n", pipe);
762 return -EINVAL;
763 }
764
765
766
767
768
769
770
771
772
773 if (rdev->mode_info.crtcs[pipe]) {
774
775
776
777 do {
778 count = radeon_get_vblank_counter(rdev, pipe);
779
780
781
782
783 stat = radeon_get_crtc_scanoutpos(
784 dev, pipe, GET_DISTANCE_TO_VBLANKSTART,
785 &vpos, &hpos, NULL, NULL,
786 &rdev->mode_info.crtcs[pipe]->base.hwmode);
787 } while (count != radeon_get_vblank_counter(rdev, pipe));
788
789 if (((stat & (DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE)) !=
790 (DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE))) {
791 DRM_DEBUG_VBL("Query failed! stat %d\n", stat);
792 }
793 else {
794 DRM_DEBUG_VBL("crtc %u: dist from vblank start %d\n",
795 pipe, vpos);
796
797
798
799
800
801 if (vpos >= 0)
802 count++;
803 }
804 }
805 else {
806
807 count = radeon_get_vblank_counter(rdev, pipe);
808 DRM_DEBUG_VBL("NULL mode info! Returned count may be wrong.\n");
809 }
810
811 return count;
812 }
813
814
815
816
817
818
819
820
821
822
823 int radeon_enable_vblank_kms(struct drm_device *dev, int crtc)
824 {
825 struct radeon_device *rdev = dev->dev_private;
826 unsigned long irqflags;
827 int r;
828
829 if (crtc < 0 || crtc >= rdev->num_crtc) {
830 DRM_ERROR("Invalid crtc %d\n", crtc);
831 return -EINVAL;
832 }
833
834 spin_lock_irqsave(&rdev->irq.lock, irqflags);
835 rdev->irq.crtc_vblank_int[crtc] = true;
836 r = radeon_irq_set(rdev);
837 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
838 return r;
839 }
840
841
842
843
844
845
846
847
848
849 void radeon_disable_vblank_kms(struct drm_device *dev, int crtc)
850 {
851 struct radeon_device *rdev = dev->dev_private;
852 unsigned long irqflags;
853
854 if (crtc < 0 || crtc >= rdev->num_crtc) {
855 DRM_ERROR("Invalid crtc %d\n", crtc);
856 return;
857 }
858
859 spin_lock_irqsave(&rdev->irq.lock, irqflags);
860 rdev->irq.crtc_vblank_int[crtc] = false;
861 radeon_irq_set(rdev);
862 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
863 }
864
865 const struct drm_ioctl_desc radeon_ioctls_kms[] = {
866 DRM_IOCTL_DEF_DRV(RADEON_CP_INIT, drm_invalid_op, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
867 DRM_IOCTL_DEF_DRV(RADEON_CP_START, drm_invalid_op, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
868 DRM_IOCTL_DEF_DRV(RADEON_CP_STOP, drm_invalid_op, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
869 DRM_IOCTL_DEF_DRV(RADEON_CP_RESET, drm_invalid_op, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
870 DRM_IOCTL_DEF_DRV(RADEON_CP_IDLE, drm_invalid_op, DRM_AUTH),
871 DRM_IOCTL_DEF_DRV(RADEON_CP_RESUME, drm_invalid_op, DRM_AUTH),
872 DRM_IOCTL_DEF_DRV(RADEON_RESET, drm_invalid_op, DRM_AUTH),
873 DRM_IOCTL_DEF_DRV(RADEON_FULLSCREEN, drm_invalid_op, DRM_AUTH),
874 DRM_IOCTL_DEF_DRV(RADEON_SWAP, drm_invalid_op, DRM_AUTH),
875 DRM_IOCTL_DEF_DRV(RADEON_CLEAR, drm_invalid_op, DRM_AUTH),
876 DRM_IOCTL_DEF_DRV(RADEON_VERTEX, drm_invalid_op, DRM_AUTH),
877 DRM_IOCTL_DEF_DRV(RADEON_INDICES, drm_invalid_op, DRM_AUTH),
878 DRM_IOCTL_DEF_DRV(RADEON_TEXTURE, drm_invalid_op, DRM_AUTH),
879 DRM_IOCTL_DEF_DRV(RADEON_STIPPLE, drm_invalid_op, DRM_AUTH),
880 DRM_IOCTL_DEF_DRV(RADEON_INDIRECT, drm_invalid_op, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
881 DRM_IOCTL_DEF_DRV(RADEON_VERTEX2, drm_invalid_op, DRM_AUTH),
882 DRM_IOCTL_DEF_DRV(RADEON_CMDBUF, drm_invalid_op, DRM_AUTH),
883 DRM_IOCTL_DEF_DRV(RADEON_GETPARAM, drm_invalid_op, DRM_AUTH),
884 DRM_IOCTL_DEF_DRV(RADEON_FLIP, drm_invalid_op, DRM_AUTH),
885 DRM_IOCTL_DEF_DRV(RADEON_ALLOC, drm_invalid_op, DRM_AUTH),
886 DRM_IOCTL_DEF_DRV(RADEON_FREE, drm_invalid_op, DRM_AUTH),
887 DRM_IOCTL_DEF_DRV(RADEON_INIT_HEAP, drm_invalid_op, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
888 DRM_IOCTL_DEF_DRV(RADEON_IRQ_EMIT, drm_invalid_op, DRM_AUTH),
889 DRM_IOCTL_DEF_DRV(RADEON_IRQ_WAIT, drm_invalid_op, DRM_AUTH),
890 DRM_IOCTL_DEF_DRV(RADEON_SETPARAM, drm_invalid_op, DRM_AUTH),
891 DRM_IOCTL_DEF_DRV(RADEON_SURF_ALLOC, drm_invalid_op, DRM_AUTH),
892 DRM_IOCTL_DEF_DRV(RADEON_SURF_FREE, drm_invalid_op, DRM_AUTH),
893
894 DRM_IOCTL_DEF_DRV(RADEON_GEM_INFO, radeon_gem_info_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
895 DRM_IOCTL_DEF_DRV(RADEON_GEM_CREATE, radeon_gem_create_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
896 DRM_IOCTL_DEF_DRV(RADEON_GEM_MMAP, radeon_gem_mmap_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
897 DRM_IOCTL_DEF_DRV(RADEON_GEM_SET_DOMAIN, radeon_gem_set_domain_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
898 DRM_IOCTL_DEF_DRV(RADEON_GEM_PREAD, radeon_gem_pread_ioctl, DRM_AUTH),
899 DRM_IOCTL_DEF_DRV(RADEON_GEM_PWRITE, radeon_gem_pwrite_ioctl, DRM_AUTH),
900 DRM_IOCTL_DEF_DRV(RADEON_GEM_WAIT_IDLE, radeon_gem_wait_idle_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
901 DRM_IOCTL_DEF_DRV(RADEON_CS, radeon_cs_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
902 DRM_IOCTL_DEF_DRV(RADEON_INFO, radeon_info_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
903 DRM_IOCTL_DEF_DRV(RADEON_GEM_SET_TILING, radeon_gem_set_tiling_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
904 DRM_IOCTL_DEF_DRV(RADEON_GEM_GET_TILING, radeon_gem_get_tiling_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
905 DRM_IOCTL_DEF_DRV(RADEON_GEM_BUSY, radeon_gem_busy_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
906 DRM_IOCTL_DEF_DRV(RADEON_GEM_VA, radeon_gem_va_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
907 DRM_IOCTL_DEF_DRV(RADEON_GEM_OP, radeon_gem_op_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
908 DRM_IOCTL_DEF_DRV(RADEON_GEM_USERPTR, radeon_gem_userptr_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
909 };
910 int radeon_max_kms_ioctl = ARRAY_SIZE(radeon_ioctls_kms);