blob: 977f1a5e11a52c90fb9f044a5b8a7e9266f642f4 [file] [log] [blame]
Jerome Glisse771fe6b2009-06-05 14:42:42 +02001/*
2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
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 shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Dave Airlie
25 * Alex Deucher
26 * Jerome Glisse
27 */
David Howells760285e2012-10-02 18:01:07 +010028#include <drm/drmP.h>
Jerome Glisse771fe6b2009-06-05 14:42:42 +020029#include "radeon.h"
David Howells760285e2012-10-02 18:01:07 +010030#include <drm/radeon_drm.h>
Marek Olšák6759a0a2012-08-09 16:34:17 +020031#include "radeon_asic.h"
Jerome Glisse771fe6b2009-06-05 14:42:42 +020032
Dave Airlie6a9ee8a2010-02-01 15:38:10 +100033#include <linux/vga_switcheroo.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090034#include <linux/slab.h>
Dave Airlie10ebc0b2012-09-17 14:40:31 +100035#include <linux/pm_runtime.h>
Alex Deucher78488652014-03-11 15:02:30 -040036
Oded Gabbaye28740e2014-07-15 13:53:32 +030037#include "radeon_kfd.h"
38
Alex Deucher78488652014-03-11 15:02:30 -040039#if defined(CONFIG_VGA_SWITCHEROO)
Alex Deucher90c4cde2014-04-10 22:29:01 -040040bool radeon_has_atpx(void);
Alex Deucher78488652014-03-11 15:02:30 -040041#else
Alex Deucher90c4cde2014-04-10 22:29:01 -040042static inline bool radeon_has_atpx(void) { return false; }
Alex Deucher78488652014-03-11 15:02:30 -040043#endif
44
Alex Deucherf482a142012-07-17 14:02:34 -040045/**
46 * radeon_driver_unload_kms - Main unload function for KMS.
47 *
48 * @dev: drm dev pointer
49 *
50 * This is the main unload function for KMS (all asics).
51 * It calls radeon_modeset_fini() to tear down the
52 * displays, and radeon_device_fini() to tear down
53 * the rest of the device (CP, writeback, etc.).
54 * Returns 0 on success.
55 */
Jerome Glissecf0fe452009-12-09 18:21:55 +010056int radeon_driver_unload_kms(struct drm_device *dev)
57{
58 struct radeon_device *rdev = dev->dev_private;
Jerome Glisse771fe6b2009-06-05 14:42:42 +020059
Jerome Glissecf0fe452009-12-09 18:21:55 +010060 if (rdev == NULL)
61 return 0;
Dave Airlie10ebc0b2012-09-17 14:40:31 +100062
Alex Deucher0cd9cb72013-04-12 19:15:52 -040063 if (rdev->rmmio == NULL)
64 goto done_free;
Dave Airlie10ebc0b2012-09-17 14:40:31 +100065
66 pm_runtime_get_sync(dev->dev);
67
Oded Gabbaye28740e2014-07-15 13:53:32 +030068 radeon_kfd_device_fini(rdev);
69
Alex Deucherc4917072012-07-31 17:14:35 -040070 radeon_acpi_fini(rdev);
Dave Airlie10ebc0b2012-09-17 14:40:31 +100071
Jerome Glissecf0fe452009-12-09 18:21:55 +010072 radeon_modeset_fini(rdev);
73 radeon_device_fini(rdev);
Alex Deucher0cd9cb72013-04-12 19:15:52 -040074
75done_free:
Jerome Glissecf0fe452009-12-09 18:21:55 +010076 kfree(rdev);
77 dev->dev_private = NULL;
78 return 0;
79}
80
Alex Deucherf482a142012-07-17 14:02:34 -040081/**
82 * radeon_driver_load_kms - Main load function for KMS.
83 *
84 * @dev: drm dev pointer
85 * @flags: device flags
86 *
87 * This is the main load function for KMS (all asics).
88 * It calls radeon_device_init() to set up the non-display
89 * parts of the chip (asic init, CP, writeback, etc.), and
90 * radeon_modeset_init() to set up the display parts
91 * (crtcs, encoders, hotplug detect, etc.).
92 * Returns 0 on success, error on failure.
93 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +020094int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags)
95{
96 struct radeon_device *rdev;
Alberto Miloned7a29522010-07-06 11:40:24 -040097 int r, acpi_status;
Jerome Glisse771fe6b2009-06-05 14:42:42 +020098
99 rdev = kzalloc(sizeof(struct radeon_device), GFP_KERNEL);
100 if (rdev == NULL) {
101 return -ENOMEM;
102 }
103 dev->dev_private = (void *)rdev;
104
105 /* update BUS flag */
Dave Airlie8410ea32010-12-15 03:16:38 +1000106 if (drm_pci_device_is_agp(dev)) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200107 flags |= RADEON_IS_AGP;
Jon Mason58b65422011-06-27 16:07:50 +0000108 } else if (pci_is_pcie(dev->pdev)) {
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200109 flags |= RADEON_IS_PCIE;
110 } else {
111 flags |= RADEON_IS_PCI;
112 }
113
Alex Deucher73acacc2014-04-15 12:44:35 -0400114 if ((radeon_runtime_pm != 0) &&
115 radeon_has_atpx() &&
116 ((flags & RADEON_IS_IGP) == 0))
Alex Deucher90c4cde2014-04-10 22:29:01 -0400117 flags |= RADEON_IS_PX;
118
Jerome Glisse6cf8a3f2009-09-10 21:46:48 +0200119 /* radeon_device_init should report only fatal error
120 * like memory allocation failure or iomapping failure,
121 * or memory manager initialization failure, it must
122 * properly initialize the GPU MC controller and permit
123 * VRAM allocation
124 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200125 r = radeon_device_init(rdev, dev, dev->pdev, flags);
126 if (r) {
Jerome Glissecf0fe452009-12-09 18:21:55 +0100127 dev_err(&dev->pdev->dev, "Fatal error during GPU init\n");
128 goto out;
Jerome Glisse6cf8a3f2009-09-10 21:46:48 +0200129 }
Alberto Miloned7a29522010-07-06 11:40:24 -0400130
Jerome Glisse6cf8a3f2009-09-10 21:46:48 +0200131 /* Again modeset_init should fail only on fatal error
132 * otherwise it should provide enough functionalities
133 * for shadowfb to run
134 */
135 r = radeon_modeset_init(rdev);
Jerome Glissecf0fe452009-12-09 18:21:55 +0100136 if (r)
137 dev_err(&dev->pdev->dev, "Fatal error during modeset init\n");
Luca Tettamantifda4b252012-07-30 21:20:35 +0200138
139 /* Call ACPI methods: require modeset init
140 * but failure is not fatal
141 */
142 if (!r) {
143 acpi_status = radeon_acpi_init(rdev);
144 if (acpi_status)
145 dev_dbg(&dev->pdev->dev,
146 "Error during ACPI methods call\n");
147 }
148
Oded Gabbaye28740e2014-07-15 13:53:32 +0300149 radeon_kfd_device_probe(rdev);
150 radeon_kfd_device_init(rdev);
151
Alex Deucher90c4cde2014-04-10 22:29:01 -0400152 if (radeon_is_px(dev)) {
Dave Airlie10ebc0b2012-09-17 14:40:31 +1000153 pm_runtime_use_autosuspend(dev->dev);
154 pm_runtime_set_autosuspend_delay(dev->dev, 5000);
155 pm_runtime_set_active(dev->dev);
156 pm_runtime_allow(dev->dev);
157 pm_runtime_mark_last_busy(dev->dev);
158 pm_runtime_put_autosuspend(dev->dev);
159 }
160
Jerome Glissecf0fe452009-12-09 18:21:55 +0100161out:
162 if (r)
163 radeon_driver_unload_kms(dev);
Dave Airlie10ebc0b2012-09-17 14:40:31 +1000164
165
Jerome Glissecf0fe452009-12-09 18:21:55 +0100166 return r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200167}
168
Alex Deucherf482a142012-07-17 14:02:34 -0400169/**
170 * radeon_set_filp_rights - Set filp right.
171 *
172 * @dev: drm dev pointer
173 * @owner: drm file
174 * @applier: drm file
175 * @value: value
176 *
177 * Sets the filp rights for the device (all asics).
178 */
Marek Olšák9eba4a92011-01-05 05:46:48 +0100179static void radeon_set_filp_rights(struct drm_device *dev,
180 struct drm_file **owner,
181 struct drm_file *applier,
182 uint32_t *value)
183{
184 mutex_lock(&dev->struct_mutex);
185 if (*value == 1) {
186 /* wants rights */
187 if (!*owner)
188 *owner = applier;
189 } else if (*value == 0) {
190 /* revokes rights */
191 if (*owner == applier)
192 *owner = NULL;
193 }
194 *value = *owner == applier ? 1 : 0;
195 mutex_unlock(&dev->struct_mutex);
196}
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200197
198/*
Marek Olšák9eba4a92011-01-05 05:46:48 +0100199 * Userspace get information ioctl
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200200 */
Alex Deucherf482a142012-07-17 14:02:34 -0400201/**
202 * radeon_info_ioctl - answer a device specific request.
203 *
204 * @rdev: radeon device pointer
205 * @data: request object
206 * @filp: drm filp
207 *
208 * This function is used to pass device specific parameters to the userspace
209 * drivers. Examples include: pci device id, pipeline parms, tiling params,
210 * etc. (all asics).
211 * Returns 0 on success, -EINVAL on failure.
212 */
Rashika Kheria55203452014-01-06 20:53:07 +0530213static int radeon_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200214{
215 struct radeon_device *rdev = dev->dev_private;
Marek Olšák6759a0a2012-08-09 16:34:17 +0200216 struct drm_radeon_info *info = data;
Jerome Glissebc35afd2010-05-12 18:01:13 +0200217 struct radeon_mode_info *minfo = &rdev->mode_info;
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400218 uint32_t *value, value_tmp, *value_ptr, value_size;
219 uint64_t value64;
Jerome Glissebc35afd2010-05-12 18:01:13 +0200220 struct drm_crtc *crtc;
221 int i, found;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200222
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200223 value_ptr = (uint32_t *)((unsigned long)info->value);
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400224 value = &value_tmp;
225 value_size = sizeof(uint32_t);
Dr. David Alan Gilbertd8ab3552010-08-02 09:43:52 +1000226
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200227 switch (info->request) {
228 case RADEON_INFO_DEVICE_ID:
Ville Syrjäläffbab09b2013-10-04 14:53:40 +0300229 *value = dev->pdev->device;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200230 break;
231 case RADEON_INFO_NUM_GB_PIPES:
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400232 *value = rdev->num_gb_pipes;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200233 break;
Alex Deucherf779b3e2009-08-19 19:11:39 -0400234 case RADEON_INFO_NUM_Z_PIPES:
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400235 *value = rdev->num_z_pipes;
Alex Deucherf779b3e2009-08-19 19:11:39 -0400236 break;
Jerome Glisse733289c2009-09-16 15:24:21 +0200237 case RADEON_INFO_ACCEL_WORKING:
Alex Deucher148a03b2010-06-03 19:00:03 -0400238 /* xf86-video-ati 6.13.0 relies on this being false for evergreen */
239 if ((rdev->family >= CHIP_CEDAR) && (rdev->family <= CHIP_HEMLOCK))
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400240 *value = false;
Alex Deucher148a03b2010-06-03 19:00:03 -0400241 else
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400242 *value = rdev->accel_working;
Jerome Glisse733289c2009-09-16 15:24:21 +0200243 break;
Jerome Glissebc35afd2010-05-12 18:01:13 +0200244 case RADEON_INFO_CRTC_FROM_ID:
Daniel Vetter1d6ac182013-12-11 11:34:44 +0100245 if (copy_from_user(value, value_ptr, sizeof(uint32_t))) {
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400246 DRM_ERROR("copy_from_user %s:%u\n", __func__, __LINE__);
247 return -EFAULT;
248 }
Jerome Glissebc35afd2010-05-12 18:01:13 +0200249 for (i = 0, found = 0; i < rdev->num_crtc; i++) {
250 crtc = (struct drm_crtc *)minfo->crtcs[i];
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400251 if (crtc && crtc->base.id == *value) {
Alex Deucher0baf2d82010-07-21 14:05:35 -0400252 struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400253 *value = radeon_crtc->crtc_id;
Jerome Glissebc35afd2010-05-12 18:01:13 +0200254 found = 1;
255 break;
256 }
257 }
258 if (!found) {
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400259 DRM_DEBUG_KMS("unknown crtc id %d\n", *value);
Jerome Glissebc35afd2010-05-12 18:01:13 +0200260 return -EINVAL;
261 }
262 break;
Alex Deucher148a03b2010-06-03 19:00:03 -0400263 case RADEON_INFO_ACCEL_WORKING2:
Alex Deucher3c64bd22014-08-01 20:05:30 +0200264 if (rdev->family == CHIP_HAWAII) {
Andreas Boll9eb401a2014-08-01 20:05:32 +0200265 if (rdev->accel_working) {
266 if (rdev->new_fw)
267 *value = 3;
268 else
269 *value = 2;
270 } else {
Alex Deucher3c64bd22014-08-01 20:05:30 +0200271 *value = 0;
Andreas Boll9eb401a2014-08-01 20:05:32 +0200272 }
Alex Deucher3c64bd22014-08-01 20:05:30 +0200273 } else {
274 *value = rdev->accel_working;
275 }
Alex Deucher148a03b2010-06-03 19:00:03 -0400276 break;
Alex Deuchere7aeeba2010-06-04 13:10:12 -0400277 case RADEON_INFO_TILING_CONFIG:
Alex Deucher64f759c2012-07-06 17:40:32 -0400278 if (rdev->family >= CHIP_BONAIRE)
279 *value = rdev->config.cik.tile_config;
280 else if (rdev->family >= CHIP_TAHITI)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400281 *value = rdev->config.si.tile_config;
Michel Dänzerc1b2f692012-03-20 17:18:26 -0400282 else if (rdev->family >= CHIP_CAYMAN)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400283 *value = rdev->config.cayman.tile_config;
Alex Deucherfecf1d02011-03-02 20:07:29 -0500284 else if (rdev->family >= CHIP_CEDAR)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400285 *value = rdev->config.evergreen.tile_config;
Alex Deuchere7aeeba2010-06-04 13:10:12 -0400286 else if (rdev->family >= CHIP_RV770)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400287 *value = rdev->config.rv770.tile_config;
Alex Deuchere7aeeba2010-06-04 13:10:12 -0400288 else if (rdev->family >= CHIP_R600)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400289 *value = rdev->config.r600.tile_config;
Alex Deuchere7aeeba2010-06-04 13:10:12 -0400290 else {
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000291 DRM_DEBUG_KMS("tiling config is r6xx+ only!\n");
Alex Deuchere7aeeba2010-06-04 13:10:12 -0400292 return -EINVAL;
293 }
Alex Deucherb824b362010-08-12 08:25:47 -0400294 break;
Dave Airlieab9e1f52010-07-13 11:11:11 +1000295 case RADEON_INFO_WANT_HYPERZ:
Marek Olšák43861f72010-08-07 03:36:34 +0200296 /* The "value" here is both an input and output parameter.
297 * If the input value is 1, filp requests hyper-z access.
298 * If the input value is 0, filp revokes its hyper-z access.
299 *
300 * When returning, the value is 1 if filp owns hyper-z access,
301 * 0 otherwise. */
Daniel Vetter1d6ac182013-12-11 11:34:44 +0100302 if (copy_from_user(value, value_ptr, sizeof(uint32_t))) {
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400303 DRM_ERROR("copy_from_user %s:%u\n", __func__, __LINE__);
304 return -EFAULT;
305 }
306 if (*value >= 2) {
307 DRM_DEBUG_KMS("WANT_HYPERZ: invalid value %d\n", *value);
Marek Olšák43861f72010-08-07 03:36:34 +0200308 return -EINVAL;
Dave Airlieab9e1f52010-07-13 11:11:11 +1000309 }
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400310 radeon_set_filp_rights(dev, &rdev->hyperz_filp, filp, value);
Marek Olšák9eba4a92011-01-05 05:46:48 +0100311 break;
312 case RADEON_INFO_WANT_CMASK:
313 /* The same logic as Hyper-Z. */
Daniel Vetter1d6ac182013-12-11 11:34:44 +0100314 if (copy_from_user(value, value_ptr, sizeof(uint32_t))) {
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400315 DRM_ERROR("copy_from_user %s:%u\n", __func__, __LINE__);
316 return -EFAULT;
317 }
318 if (*value >= 2) {
319 DRM_DEBUG_KMS("WANT_CMASK: invalid value %d\n", *value);
Marek Olšák9eba4a92011-01-05 05:46:48 +0100320 return -EINVAL;
Marek Olšák43861f72010-08-07 03:36:34 +0200321 }
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400322 radeon_set_filp_rights(dev, &rdev->cmask_filp, filp, value);
Alex Deuchere7aeeba2010-06-04 13:10:12 -0400323 break;
Alex Deucher58bbf012011-01-24 17:14:26 -0500324 case RADEON_INFO_CLOCK_CRYSTAL_FREQ:
325 /* return clock value in KHz */
Alex Deucher454d2e22013-02-14 10:04:02 -0500326 if (rdev->asic->get_xclk)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400327 *value = radeon_get_xclk(rdev) * 10;
Alex Deucher454d2e22013-02-14 10:04:02 -0500328 else
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400329 *value = rdev->clock.spll.reference_freq * 10;
Alex Deucher58bbf012011-01-24 17:14:26 -0500330 break;
Dave Airlie486af182011-03-01 14:32:27 +1000331 case RADEON_INFO_NUM_BACKENDS:
Alex Deucher64f759c2012-07-06 17:40:32 -0400332 if (rdev->family >= CHIP_BONAIRE)
333 *value = rdev->config.cik.max_backends_per_se *
334 rdev->config.cik.max_shader_engines;
335 else if (rdev->family >= CHIP_TAHITI)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400336 *value = rdev->config.si.max_backends_per_se *
Michel Dänzerc1b2f692012-03-20 17:18:26 -0400337 rdev->config.si.max_shader_engines;
338 else if (rdev->family >= CHIP_CAYMAN)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400339 *value = rdev->config.cayman.max_backends_per_se *
Alex Deucherfecf1d02011-03-02 20:07:29 -0500340 rdev->config.cayman.max_shader_engines;
341 else if (rdev->family >= CHIP_CEDAR)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400342 *value = rdev->config.evergreen.max_backends;
Dave Airlie486af182011-03-01 14:32:27 +1000343 else if (rdev->family >= CHIP_RV770)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400344 *value = rdev->config.rv770.max_backends;
Dave Airlie486af182011-03-01 14:32:27 +1000345 else if (rdev->family >= CHIP_R600)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400346 *value = rdev->config.r600.max_backends;
Dave Airlie486af182011-03-01 14:32:27 +1000347 else {
348 return -EINVAL;
349 }
350 break;
Alex Deucher65659452011-04-26 13:27:43 -0400351 case RADEON_INFO_NUM_TILE_PIPES:
Alex Deucher64f759c2012-07-06 17:40:32 -0400352 if (rdev->family >= CHIP_BONAIRE)
353 *value = rdev->config.cik.max_tile_pipes;
354 else if (rdev->family >= CHIP_TAHITI)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400355 *value = rdev->config.si.max_tile_pipes;
Michel Dänzerc1b2f692012-03-20 17:18:26 -0400356 else if (rdev->family >= CHIP_CAYMAN)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400357 *value = rdev->config.cayman.max_tile_pipes;
Alex Deucher65659452011-04-26 13:27:43 -0400358 else if (rdev->family >= CHIP_CEDAR)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400359 *value = rdev->config.evergreen.max_tile_pipes;
Alex Deucher65659452011-04-26 13:27:43 -0400360 else if (rdev->family >= CHIP_RV770)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400361 *value = rdev->config.rv770.max_tile_pipes;
Alex Deucher65659452011-04-26 13:27:43 -0400362 else if (rdev->family >= CHIP_R600)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400363 *value = rdev->config.r600.max_tile_pipes;
Alex Deucher65659452011-04-26 13:27:43 -0400364 else {
365 return -EINVAL;
366 }
367 break;
Alex Deucher8aeb96f2011-05-03 19:28:02 -0400368 case RADEON_INFO_FUSION_GART_WORKING:
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400369 *value = 1;
Alex Deucher8aeb96f2011-05-03 19:28:02 -0400370 break;
Alex Deuchere55b9422011-07-15 19:53:52 +0000371 case RADEON_INFO_BACKEND_MAP:
Alex Deucher64f759c2012-07-06 17:40:32 -0400372 if (rdev->family >= CHIP_BONAIRE)
Michel Dänzer1ddce272013-11-18 18:25:59 +0900373 *value = rdev->config.cik.backend_map;
Alex Deucher64f759c2012-07-06 17:40:32 -0400374 else if (rdev->family >= CHIP_TAHITI)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400375 *value = rdev->config.si.backend_map;
Michel Dänzerc1b2f692012-03-20 17:18:26 -0400376 else if (rdev->family >= CHIP_CAYMAN)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400377 *value = rdev->config.cayman.backend_map;
Alex Deuchere55b9422011-07-15 19:53:52 +0000378 else if (rdev->family >= CHIP_CEDAR)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400379 *value = rdev->config.evergreen.backend_map;
Alex Deuchere55b9422011-07-15 19:53:52 +0000380 else if (rdev->family >= CHIP_RV770)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400381 *value = rdev->config.rv770.backend_map;
Alex Deuchere55b9422011-07-15 19:53:52 +0000382 else if (rdev->family >= CHIP_R600)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400383 *value = rdev->config.r600.backend_map;
Alex Deuchere55b9422011-07-15 19:53:52 +0000384 else {
385 return -EINVAL;
386 }
387 break;
Jerome Glisse721604a2012-01-05 22:11:05 -0500388 case RADEON_INFO_VA_START:
389 /* this is where we report if vm is supported or not */
390 if (rdev->family < CHIP_CAYMAN)
391 return -EINVAL;
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400392 *value = RADEON_VA_RESERVED_SIZE;
Jerome Glisse721604a2012-01-05 22:11:05 -0500393 break;
394 case RADEON_INFO_IB_VM_MAX_SIZE:
395 /* this is where we report if vm is supported or not */
396 if (rdev->family < CHIP_CAYMAN)
397 return -EINVAL;
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400398 *value = RADEON_IB_VM_MAX_SIZE;
Jerome Glisse721604a2012-01-05 22:11:05 -0500399 break;
Tom Stellard609c1e12012-03-20 17:17:55 -0400400 case RADEON_INFO_MAX_PIPES:
Alex Deucher64f759c2012-07-06 17:40:32 -0400401 if (rdev->family >= CHIP_BONAIRE)
402 *value = rdev->config.cik.max_cu_per_sh;
403 else if (rdev->family >= CHIP_TAHITI)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400404 *value = rdev->config.si.max_cu_per_sh;
Michel Dänzerc1b2f692012-03-20 17:18:26 -0400405 else if (rdev->family >= CHIP_CAYMAN)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400406 *value = rdev->config.cayman.max_pipes_per_simd;
Tom Stellard609c1e12012-03-20 17:17:55 -0400407 else if (rdev->family >= CHIP_CEDAR)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400408 *value = rdev->config.evergreen.max_pipes;
Tom Stellard609c1e12012-03-20 17:17:55 -0400409 else if (rdev->family >= CHIP_RV770)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400410 *value = rdev->config.rv770.max_pipes;
Tom Stellard609c1e12012-03-20 17:17:55 -0400411 else if (rdev->family >= CHIP_R600)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400412 *value = rdev->config.r600.max_pipes;
Tom Stellard609c1e12012-03-20 17:17:55 -0400413 else {
414 return -EINVAL;
415 }
416 break;
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400417 case RADEON_INFO_TIMESTAMP:
418 if (rdev->family < CHIP_R600) {
419 DRM_DEBUG_KMS("timestamp is r6xx+ only!\n");
420 return -EINVAL;
421 }
422 value = (uint32_t*)&value64;
423 value_size = sizeof(uint64_t);
424 value64 = radeon_get_gpu_clock_counter(rdev);
425 break;
Alex Deucher2e1a7672012-12-04 12:55:37 -0500426 case RADEON_INFO_MAX_SE:
Alex Deucher64f759c2012-07-06 17:40:32 -0400427 if (rdev->family >= CHIP_BONAIRE)
428 *value = rdev->config.cik.max_shader_engines;
429 else if (rdev->family >= CHIP_TAHITI)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400430 *value = rdev->config.si.max_shader_engines;
Alex Deucher2e1a7672012-12-04 12:55:37 -0500431 else if (rdev->family >= CHIP_CAYMAN)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400432 *value = rdev->config.cayman.max_shader_engines;
Alex Deucher2e1a7672012-12-04 12:55:37 -0500433 else if (rdev->family >= CHIP_CEDAR)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400434 *value = rdev->config.evergreen.num_ses;
Alex Deucher2e1a7672012-12-04 12:55:37 -0500435 else
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400436 *value = 1;
Alex Deucher2e1a7672012-12-04 12:55:37 -0500437 break;
438 case RADEON_INFO_MAX_SH_PER_SE:
Alex Deucher64f759c2012-07-06 17:40:32 -0400439 if (rdev->family >= CHIP_BONAIRE)
440 *value = rdev->config.cik.max_sh_per_se;
441 else if (rdev->family >= CHIP_TAHITI)
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400442 *value = rdev->config.si.max_sh_per_se;
Alex Deucher2e1a7672012-12-04 12:55:37 -0500443 else
444 return -EINVAL;
445 break;
Samuel Lia0a53aa2013-04-08 17:25:47 -0400446 case RADEON_INFO_FASTFB_WORKING:
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400447 *value = rdev->fastfb_working;
Samuel Lia0a53aa2013-04-08 17:25:47 -0400448 break;
Christian König902aaef2013-04-09 10:35:42 -0400449 case RADEON_INFO_RING_WORKING:
Daniel Vetter1d6ac182013-12-11 11:34:44 +0100450 if (copy_from_user(value, value_ptr, sizeof(uint32_t))) {
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400451 DRM_ERROR("copy_from_user %s:%u\n", __func__, __LINE__);
452 return -EFAULT;
453 }
454 switch (*value) {
Christian König902aaef2013-04-09 10:35:42 -0400455 case RADEON_CS_RING_GFX:
456 case RADEON_CS_RING_COMPUTE:
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400457 *value = rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready;
Christian König902aaef2013-04-09 10:35:42 -0400458 break;
459 case RADEON_CS_RING_DMA:
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400460 *value = rdev->ring[R600_RING_TYPE_DMA_INDEX].ready;
461 *value |= rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX].ready;
Christian König902aaef2013-04-09 10:35:42 -0400462 break;
463 case RADEON_CS_RING_UVD:
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400464 *value = rdev->ring[R600_RING_TYPE_UVD_INDEX].ready;
Christian König902aaef2013-04-09 10:35:42 -0400465 break;
Christian Königf7ba8b02014-01-27 10:16:06 -0700466 case RADEON_CS_RING_VCE:
467 *value = rdev->ring[TN_RING_TYPE_VCE1_INDEX].ready;
468 break;
Christian König902aaef2013-04-09 10:35:42 -0400469 default:
470 return -EINVAL;
471 }
472 break;
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400473 case RADEON_INFO_SI_TILE_MODE_ARRAY:
Alex Deucher64f759c2012-07-06 17:40:32 -0400474 if (rdev->family >= CHIP_BONAIRE) {
Alex Deucher39aee492013-04-10 13:41:25 -0400475 value = rdev->config.cik.tile_mode_array;
476 value_size = sizeof(uint32_t)*32;
477 } else if (rdev->family >= CHIP_TAHITI) {
478 value = rdev->config.si.tile_mode_array;
479 value_size = sizeof(uint32_t)*32;
480 } else {
481 DRM_DEBUG_KMS("tile mode array is si+ only!\n");
Alex Deucher64f759c2012-07-06 17:40:32 -0400482 return -EINVAL;
483 }
Jerome Glisse64d7b8b2013-04-09 11:17:08 -0400484 break;
Michel Dänzer32f79a82013-11-18 18:26:00 +0900485 case RADEON_INFO_CIK_MACROTILE_MODE_ARRAY:
486 if (rdev->family >= CHIP_BONAIRE) {
487 value = rdev->config.cik.macrotile_mode_array;
488 value_size = sizeof(uint32_t)*16;
489 } else {
490 DRM_DEBUG_KMS("macrotile mode array is cik+ only!\n");
491 return -EINVAL;
492 }
493 break;
Tom Stellarde5b9e752013-08-16 17:47:39 -0400494 case RADEON_INFO_SI_CP_DMA_COMPUTE:
495 *value = 1;
496 break;
Marek Olšák439a1cf2013-12-22 02:18:01 +0100497 case RADEON_INFO_SI_BACKEND_ENABLED_MASK:
498 if (rdev->family >= CHIP_BONAIRE) {
499 *value = rdev->config.cik.backend_enable_mask;
500 } else if (rdev->family >= CHIP_TAHITI) {
501 *value = rdev->config.si.backend_enable_mask;
502 } else {
503 DRM_DEBUG_KMS("BACKEND_ENABLED_MASK is si+ only!\n");
504 }
505 break;
Alex Deucherf5f1f892014-01-20 18:20:29 -0500506 case RADEON_INFO_MAX_SCLK:
507 if ((rdev->pm.pm_method == PM_METHOD_DPM) &&
508 rdev->pm.dpm_enabled)
509 *value = rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.sclk * 10;
510 else
511 *value = rdev->pm.default_sclk * 10;
512 break;
Christian König98ccc292014-01-23 09:50:49 -0700513 case RADEON_INFO_VCE_FW_VERSION:
514 *value = rdev->vce.fw_version;
515 break;
516 case RADEON_INFO_VCE_FB_VERSION:
517 *value = rdev->vce.fb_version;
518 break;
Marek Olšák67e8e3f2014-03-02 00:56:18 +0100519 case RADEON_INFO_NUM_BYTES_MOVED:
520 value = (uint32_t*)&value64;
521 value_size = sizeof(uint64_t);
522 value64 = atomic64_read(&rdev->num_bytes_moved);
523 break;
524 case RADEON_INFO_VRAM_USAGE:
525 value = (uint32_t*)&value64;
526 value_size = sizeof(uint64_t);
527 value64 = atomic64_read(&rdev->vram_usage);
528 break;
529 case RADEON_INFO_GTT_USAGE:
530 value = (uint32_t*)&value64;
531 value_size = sizeof(uint64_t);
532 value64 = atomic64_read(&rdev->gtt_usage);
533 break;
Alex Deucher65fcf662014-06-02 16:13:21 -0400534 case RADEON_INFO_ACTIVE_CU_COUNT:
535 if (rdev->family >= CHIP_BONAIRE)
536 *value = rdev->config.cik.active_cus;
537 else if (rdev->family >= CHIP_TAHITI)
538 *value = rdev->config.si.active_cus;
539 else if (rdev->family >= CHIP_CAYMAN)
540 *value = rdev->config.cayman.active_simds;
541 else if (rdev->family >= CHIP_CEDAR)
542 *value = rdev->config.evergreen.active_simds;
543 else if (rdev->family >= CHIP_RV770)
544 *value = rdev->config.rv770.active_simds;
545 else if (rdev->family >= CHIP_R600)
546 *value = rdev->config.r600.active_simds;
547 else
548 *value = 1;
549 break;
Alex Deucherd6d2a182014-09-30 10:04:40 -0400550 case RADEON_INFO_CURRENT_GPU_TEMP:
551 /* get temperature in millidegrees C */
552 if (rdev->asic->pm.get_temperature)
553 *value = radeon_get_temperature(rdev);
554 else
555 *value = 0;
556 break;
Alex Deucher5c363a82014-09-30 11:33:30 -0400557 case RADEON_INFO_CURRENT_GPU_SCLK:
558 /* get sclk in Mhz */
559 if (rdev->pm.dpm_enabled)
560 *value = radeon_dpm_get_current_sclk(rdev) / 100;
561 else
562 *value = rdev->pm.current_sclk / 100;
563 break;
564 case RADEON_INFO_CURRENT_GPU_MCLK:
565 /* get mclk in Mhz */
566 if (rdev->pm.dpm_enabled)
567 *value = radeon_dpm_get_current_mclk(rdev) / 100;
568 else
569 *value = rdev->pm.current_mclk / 100;
570 break;
Alex Deucher4535cb92014-10-01 11:26:50 -0400571 case RADEON_INFO_READ_REG:
572 if (copy_from_user(value, value_ptr, sizeof(uint32_t))) {
573 DRM_ERROR("copy_from_user %s:%u\n", __func__, __LINE__);
574 return -EFAULT;
575 }
576 if (radeon_get_allowed_info_register(rdev, *value, value))
577 return -EINVAL;
578 break;
Michel Dänzer3bc980b2015-06-16 17:28:16 +0900579 case RADEON_INFO_VA_UNMAP_WORKING:
580 *value = true;
581 break;
Marek Olšák72b90762015-04-29 19:40:33 +0200582 case RADEON_INFO_GPU_RESET_COUNTER:
583 *value = atomic_read(&rdev->gpu_reset_counter);
584 break;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200585 default:
Dave Airlied9fdaaf2010-08-02 10:42:55 +1000586 DRM_DEBUG_KMS("Invalid request %d\n", info->request);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200587 return -EINVAL;
588 }
Daniel Vetter1d6ac182013-12-11 11:34:44 +0100589 if (copy_to_user(value_ptr, (char*)value, value_size)) {
Marek Olšák6759a0a2012-08-09 16:34:17 +0200590 DRM_ERROR("copy_to_user %s:%u\n", __func__, __LINE__);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200591 return -EFAULT;
592 }
593 return 0;
594}
595
596
597/*
598 * Outdated mess for old drm with Xorg being in charge (void function now).
599 */
Alex Deucherf482a142012-07-17 14:02:34 -0400600/**
Alex Deucherf482a142012-07-17 14:02:34 -0400601 * radeon_driver_firstopen_kms - drm callback for last close
602 *
603 * @dev: drm dev pointer
604 *
Lukas Wunner8e5de1d2015-09-05 11:14:43 +0200605 * Switch vga_switcheroo state after last close (all asics).
Alex Deucherf482a142012-07-17 14:02:34 -0400606 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200607void radeon_driver_lastclose_kms(struct drm_device *dev)
608{
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000609 vga_switcheroo_process_delayed_switch();
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200610}
611
Alex Deucherf482a142012-07-17 14:02:34 -0400612/**
613 * radeon_driver_open_kms - drm callback for open
614 *
615 * @dev: drm dev pointer
616 * @file_priv: drm file
617 *
618 * On device open, init vm on cayman+ (all asics).
619 * Returns 0 on success, error on failure.
620 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200621int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
622{
Jerome Glisse721604a2012-01-05 22:11:05 -0500623 struct radeon_device *rdev = dev->dev_private;
Dave Airlie10ebc0b2012-09-17 14:40:31 +1000624 int r;
Jerome Glisse721604a2012-01-05 22:11:05 -0500625
626 file_priv->driver_priv = NULL;
627
Dave Airlie10ebc0b2012-09-17 14:40:31 +1000628 r = pm_runtime_get_sync(dev->dev);
629 if (r < 0)
630 return r;
631
Jerome Glisse721604a2012-01-05 22:11:05 -0500632 /* new gpu have virtual address space support */
633 if (rdev->family >= CHIP_CAYMAN) {
634 struct radeon_fpriv *fpriv;
Christian Königcc9e67e2014-07-18 13:48:10 +0200635 struct radeon_vm *vm;
Jerome Glisse721604a2012-01-05 22:11:05 -0500636 int r;
637
638 fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL);
639 if (unlikely(!fpriv)) {
640 return -ENOMEM;
641 }
642
Jérôme Glisse24f47ac2014-05-07 16:35:24 -0400643 if (rdev->accel_working) {
Alex Deucher544143f2015-01-28 14:36:26 -0500644 vm = &fpriv->vm;
645 r = radeon_vm_init(rdev, vm);
646 if (r) {
647 kfree(fpriv);
648 return r;
649 }
650
Jérôme Glisse24f47ac2014-05-07 16:35:24 -0400651 r = radeon_bo_reserve(rdev->ring_tmp_bo.bo, false);
652 if (r) {
Christian Königcc9e67e2014-07-18 13:48:10 +0200653 radeon_vm_fini(rdev, vm);
Jérôme Glisse24f47ac2014-05-07 16:35:24 -0400654 kfree(fpriv);
655 return r;
656 }
657
658 /* map the ib pool buffer read only into
659 * virtual address space */
Christian Königcc9e67e2014-07-18 13:48:10 +0200660 vm->ib_bo_va = radeon_vm_bo_add(rdev, vm,
661 rdev->ring_tmp_bo.bo);
662 r = radeon_vm_bo_set_addr(rdev, vm->ib_bo_va,
663 RADEON_VA_IB_OFFSET,
Jérôme Glisse24f47ac2014-05-07 16:35:24 -0400664 RADEON_VM_PAGE_READABLE |
665 RADEON_VM_PAGE_SNOOPED);
Jérôme Glisse24f47ac2014-05-07 16:35:24 -0400666 if (r) {
Christian Königcc9e67e2014-07-18 13:48:10 +0200667 radeon_vm_fini(rdev, vm);
Jérôme Glisse24f47ac2014-05-07 16:35:24 -0400668 kfree(fpriv);
669 return r;
670 }
Quentin Casasnovas74073c92014-03-18 17:16:52 +0100671 }
Jerome Glisse721604a2012-01-05 22:11:05 -0500672 file_priv->driver_priv = fpriv;
673 }
Dave Airlie10ebc0b2012-09-17 14:40:31 +1000674
675 pm_runtime_mark_last_busy(dev->dev);
676 pm_runtime_put_autosuspend(dev->dev);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200677 return 0;
678}
679
Alex Deucherf482a142012-07-17 14:02:34 -0400680/**
681 * radeon_driver_postclose_kms - drm callback for post close
682 *
683 * @dev: drm dev pointer
684 * @file_priv: drm file
685 *
686 * On device post close, tear down vm on cayman+ (all asics).
687 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200688void radeon_driver_postclose_kms(struct drm_device *dev,
689 struct drm_file *file_priv)
690{
Jerome Glisse721604a2012-01-05 22:11:05 -0500691 struct radeon_device *rdev = dev->dev_private;
692
693 /* new gpu have virtual address space support */
694 if (rdev->family >= CHIP_CAYMAN && file_priv->driver_priv) {
695 struct radeon_fpriv *fpriv = file_priv->driver_priv;
Christian Königcc9e67e2014-07-18 13:48:10 +0200696 struct radeon_vm *vm = &fpriv->vm;
Christian Königd72d43c2012-10-09 13:31:18 +0200697 int r;
698
Jérôme Glisse24f47ac2014-05-07 16:35:24 -0400699 if (rdev->accel_working) {
700 r = radeon_bo_reserve(rdev->ring_tmp_bo.bo, false);
701 if (!r) {
Christian Königcc9e67e2014-07-18 13:48:10 +0200702 if (vm->ib_bo_va)
703 radeon_vm_bo_rmv(rdev, vm->ib_bo_va);
Jérôme Glisse24f47ac2014-05-07 16:35:24 -0400704 radeon_bo_unreserve(rdev->ring_tmp_bo.bo);
705 }
Alex Deucher544143f2015-01-28 14:36:26 -0500706 radeon_vm_fini(rdev, vm);
Christian Königd72d43c2012-10-09 13:31:18 +0200707 }
Jerome Glisse721604a2012-01-05 22:11:05 -0500708
Jerome Glisse721604a2012-01-05 22:11:05 -0500709 kfree(fpriv);
710 file_priv->driver_priv = NULL;
711 }
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200712}
713
Alex Deucherf482a142012-07-17 14:02:34 -0400714/**
715 * radeon_driver_preclose_kms - drm callback for pre close
716 *
717 * @dev: drm dev pointer
718 * @file_priv: drm file
719 *
720 * On device pre close, tear down hyperz and cmask filps on r1xx-r5xx
721 * (all asics).
722 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200723void radeon_driver_preclose_kms(struct drm_device *dev,
724 struct drm_file *file_priv)
725{
Dave Airlieab9e1f52010-07-13 11:11:11 +1000726 struct radeon_device *rdev = dev->dev_private;
727 if (rdev->hyperz_filp == file_priv)
728 rdev->hyperz_filp = NULL;
Marek Olšákdca0d612011-01-27 22:46:15 +0100729 if (rdev->cmask_filp == file_priv)
730 rdev->cmask_filp = NULL;
Christian Königf2ba57b2013-04-08 12:41:29 +0200731 radeon_uvd_free_handles(rdev, file_priv);
Christian Königd93f7932013-05-23 12:10:04 +0200732 radeon_vce_free_handles(rdev, file_priv);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200733}
734
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200735/*
736 * VBlank related functions.
737 */
Alex Deucherf482a142012-07-17 14:02:34 -0400738/**
739 * radeon_get_vblank_counter_kms - get frame count
740 *
741 * @dev: drm dev pointer
742 * @crtc: crtc to get the frame count from
743 *
744 * Gets the frame count on the requested crtc (all asics).
745 * Returns frame count on success, -EINVAL on failure.
746 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200747u32 radeon_get_vblank_counter_kms(struct drm_device *dev, int crtc)
748{
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200749 struct radeon_device *rdev = dev->dev_private;
750
Dave Airlie9c950a42010-04-23 13:21:58 +1000751 if (crtc < 0 || crtc >= rdev->num_crtc) {
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200752 DRM_ERROR("Invalid crtc %d\n", crtc);
753 return -EINVAL;
754 }
755
756 return radeon_get_vblank_counter(rdev, crtc);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200757}
758
Alex Deucherf482a142012-07-17 14:02:34 -0400759/**
760 * radeon_enable_vblank_kms - enable vblank interrupt
761 *
762 * @dev: drm dev pointer
763 * @crtc: crtc to enable vblank interrupt for
764 *
765 * Enable the interrupt on the requested crtc (all asics).
766 * Returns 0 on success, -EINVAL on failure.
767 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200768int radeon_enable_vblank_kms(struct drm_device *dev, int crtc)
769{
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200770 struct radeon_device *rdev = dev->dev_private;
Christian Koenigfb982572012-05-17 01:33:30 +0200771 unsigned long irqflags;
772 int r;
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200773
Dave Airlie9c950a42010-04-23 13:21:58 +1000774 if (crtc < 0 || crtc >= rdev->num_crtc) {
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200775 DRM_ERROR("Invalid crtc %d\n", crtc);
776 return -EINVAL;
777 }
778
Christian Koenigfb982572012-05-17 01:33:30 +0200779 spin_lock_irqsave(&rdev->irq.lock, irqflags);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200780 rdev->irq.crtc_vblank_int[crtc] = true;
Christian Koenigfb982572012-05-17 01:33:30 +0200781 r = radeon_irq_set(rdev);
782 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
783 return r;
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200784}
785
Alex Deucherf482a142012-07-17 14:02:34 -0400786/**
787 * radeon_disable_vblank_kms - disable vblank interrupt
788 *
789 * @dev: drm dev pointer
790 * @crtc: crtc to disable vblank interrupt for
791 *
792 * Disable the interrupt on the requested crtc (all asics).
793 */
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200794void radeon_disable_vblank_kms(struct drm_device *dev, int crtc)
795{
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200796 struct radeon_device *rdev = dev->dev_private;
Christian Koenigfb982572012-05-17 01:33:30 +0200797 unsigned long irqflags;
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200798
Dave Airlie9c950a42010-04-23 13:21:58 +1000799 if (crtc < 0 || crtc >= rdev->num_crtc) {
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200800 DRM_ERROR("Invalid crtc %d\n", crtc);
801 return;
802 }
803
Christian Koenigfb982572012-05-17 01:33:30 +0200804 spin_lock_irqsave(&rdev->irq.lock, irqflags);
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200805 rdev->irq.crtc_vblank_int[crtc] = false;
Michel Dänzer7ed220d2009-08-13 11:10:51 +0200806 radeon_irq_set(rdev);
Christian Koenigfb982572012-05-17 01:33:30 +0200807 spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200808}
809
Alex Deucherf482a142012-07-17 14:02:34 -0400810/**
811 * radeon_get_vblank_timestamp_kms - get vblank timestamp
812 *
813 * @dev: drm dev pointer
814 * @crtc: crtc to get the timestamp for
815 * @max_error: max error
816 * @vblank_time: time value
817 * @flags: flags passed to the driver
818 *
819 * Gets the timestamp on the requested crtc based on the
820 * scanout position. (all asics).
821 * Returns postive status flags on success, negative error on failure.
822 */
Mario Kleinerf5a80202010-10-23 04:42:17 +0200823int radeon_get_vblank_timestamp_kms(struct drm_device *dev, int crtc,
824 int *max_error,
825 struct timeval *vblank_time,
826 unsigned flags)
827{
828 struct drm_crtc *drmcrtc;
829 struct radeon_device *rdev = dev->dev_private;
830
831 if (crtc < 0 || crtc >= dev->num_crtcs) {
832 DRM_ERROR("Invalid crtc %d\n", crtc);
833 return -EINVAL;
834 }
835
836 /* Get associated drm_crtc: */
837 drmcrtc = &rdev->mode_info.crtcs[crtc]->base;
Petr Mladekf5475cc2014-11-27 16:57:21 +0100838 if (!drmcrtc)
839 return -EINVAL;
Mario Kleinerf5a80202010-10-23 04:42:17 +0200840
841 /* Helper routine in DRM core does all the work: */
842 return drm_calc_vbltimestamp_from_scanoutpos(dev, crtc, max_error,
843 vblank_time, flags,
Ville Syrjäläeba1f352015-09-14 22:43:43 +0300844 &drmcrtc->hwmode);
Mario Kleinerf5a80202010-10-23 04:42:17 +0200845}
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200846
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200847#define KMS_INVALID_IOCTL(name) \
Rashika Kheriaf6e2e402014-01-06 21:06:44 +0530848static int name(struct drm_device *dev, void *data, struct drm_file \
849 *file_priv) \
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200850{ \
851 DRM_ERROR("invalid ioctl with kms %s\n", __func__); \
852 return -EINVAL; \
853}
854
855/*
856 * All these ioctls are invalid in kms world.
857 */
858KMS_INVALID_IOCTL(radeon_cp_init_kms)
859KMS_INVALID_IOCTL(radeon_cp_start_kms)
860KMS_INVALID_IOCTL(radeon_cp_stop_kms)
861KMS_INVALID_IOCTL(radeon_cp_reset_kms)
862KMS_INVALID_IOCTL(radeon_cp_idle_kms)
863KMS_INVALID_IOCTL(radeon_cp_resume_kms)
864KMS_INVALID_IOCTL(radeon_engine_reset_kms)
865KMS_INVALID_IOCTL(radeon_fullscreen_kms)
866KMS_INVALID_IOCTL(radeon_cp_swap_kms)
867KMS_INVALID_IOCTL(radeon_cp_clear_kms)
868KMS_INVALID_IOCTL(radeon_cp_vertex_kms)
869KMS_INVALID_IOCTL(radeon_cp_indices_kms)
870KMS_INVALID_IOCTL(radeon_cp_texture_kms)
871KMS_INVALID_IOCTL(radeon_cp_stipple_kms)
872KMS_INVALID_IOCTL(radeon_cp_indirect_kms)
873KMS_INVALID_IOCTL(radeon_cp_vertex2_kms)
874KMS_INVALID_IOCTL(radeon_cp_cmdbuf_kms)
875KMS_INVALID_IOCTL(radeon_cp_getparam_kms)
876KMS_INVALID_IOCTL(radeon_cp_flip_kms)
877KMS_INVALID_IOCTL(radeon_mem_alloc_kms)
878KMS_INVALID_IOCTL(radeon_mem_free_kms)
879KMS_INVALID_IOCTL(radeon_mem_init_heap_kms)
880KMS_INVALID_IOCTL(radeon_irq_emit_kms)
881KMS_INVALID_IOCTL(radeon_irq_wait_kms)
882KMS_INVALID_IOCTL(radeon_cp_setparam_kms)
883KMS_INVALID_IOCTL(radeon_surface_alloc_kms)
884KMS_INVALID_IOCTL(radeon_surface_free_kms)
885
886
Rob Clarkbaa70942013-08-02 13:27:49 -0400887const struct drm_ioctl_desc radeon_ioctls_kms[] = {
Dave Airlie1b2f1482010-08-14 20:20:34 +1000888 DRM_IOCTL_DEF_DRV(RADEON_CP_INIT, radeon_cp_init_kms, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
889 DRM_IOCTL_DEF_DRV(RADEON_CP_START, radeon_cp_start_kms, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
890 DRM_IOCTL_DEF_DRV(RADEON_CP_STOP, radeon_cp_stop_kms, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
891 DRM_IOCTL_DEF_DRV(RADEON_CP_RESET, radeon_cp_reset_kms, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
892 DRM_IOCTL_DEF_DRV(RADEON_CP_IDLE, radeon_cp_idle_kms, DRM_AUTH),
893 DRM_IOCTL_DEF_DRV(RADEON_CP_RESUME, radeon_cp_resume_kms, DRM_AUTH),
894 DRM_IOCTL_DEF_DRV(RADEON_RESET, radeon_engine_reset_kms, DRM_AUTH),
895 DRM_IOCTL_DEF_DRV(RADEON_FULLSCREEN, radeon_fullscreen_kms, DRM_AUTH),
896 DRM_IOCTL_DEF_DRV(RADEON_SWAP, radeon_cp_swap_kms, DRM_AUTH),
897 DRM_IOCTL_DEF_DRV(RADEON_CLEAR, radeon_cp_clear_kms, DRM_AUTH),
898 DRM_IOCTL_DEF_DRV(RADEON_VERTEX, radeon_cp_vertex_kms, DRM_AUTH),
899 DRM_IOCTL_DEF_DRV(RADEON_INDICES, radeon_cp_indices_kms, DRM_AUTH),
900 DRM_IOCTL_DEF_DRV(RADEON_TEXTURE, radeon_cp_texture_kms, DRM_AUTH),
901 DRM_IOCTL_DEF_DRV(RADEON_STIPPLE, radeon_cp_stipple_kms, DRM_AUTH),
902 DRM_IOCTL_DEF_DRV(RADEON_INDIRECT, radeon_cp_indirect_kms, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
903 DRM_IOCTL_DEF_DRV(RADEON_VERTEX2, radeon_cp_vertex2_kms, DRM_AUTH),
904 DRM_IOCTL_DEF_DRV(RADEON_CMDBUF, radeon_cp_cmdbuf_kms, DRM_AUTH),
905 DRM_IOCTL_DEF_DRV(RADEON_GETPARAM, radeon_cp_getparam_kms, DRM_AUTH),
906 DRM_IOCTL_DEF_DRV(RADEON_FLIP, radeon_cp_flip_kms, DRM_AUTH),
907 DRM_IOCTL_DEF_DRV(RADEON_ALLOC, radeon_mem_alloc_kms, DRM_AUTH),
908 DRM_IOCTL_DEF_DRV(RADEON_FREE, radeon_mem_free_kms, DRM_AUTH),
909 DRM_IOCTL_DEF_DRV(RADEON_INIT_HEAP, radeon_mem_init_heap_kms, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
910 DRM_IOCTL_DEF_DRV(RADEON_IRQ_EMIT, radeon_irq_emit_kms, DRM_AUTH),
911 DRM_IOCTL_DEF_DRV(RADEON_IRQ_WAIT, radeon_irq_wait_kms, DRM_AUTH),
912 DRM_IOCTL_DEF_DRV(RADEON_SETPARAM, radeon_cp_setparam_kms, DRM_AUTH),
913 DRM_IOCTL_DEF_DRV(RADEON_SURF_ALLOC, radeon_surface_alloc_kms, DRM_AUTH),
914 DRM_IOCTL_DEF_DRV(RADEON_SURF_FREE, radeon_surface_free_kms, DRM_AUTH),
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200915 /* KMS */
Christian Königf33bcab2013-08-25 18:29:03 +0200916 DRM_IOCTL_DEF_DRV(RADEON_GEM_INFO, radeon_gem_info_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
917 DRM_IOCTL_DEF_DRV(RADEON_GEM_CREATE, radeon_gem_create_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
918 DRM_IOCTL_DEF_DRV(RADEON_GEM_MMAP, radeon_gem_mmap_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
919 DRM_IOCTL_DEF_DRV(RADEON_GEM_SET_DOMAIN, radeon_gem_set_domain_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
Dave Airlie1b2f1482010-08-14 20:20:34 +1000920 DRM_IOCTL_DEF_DRV(RADEON_GEM_PREAD, radeon_gem_pread_ioctl, DRM_AUTH|DRM_UNLOCKED),
921 DRM_IOCTL_DEF_DRV(RADEON_GEM_PWRITE, radeon_gem_pwrite_ioctl, DRM_AUTH|DRM_UNLOCKED),
Christian Königf33bcab2013-08-25 18:29:03 +0200922 DRM_IOCTL_DEF_DRV(RADEON_GEM_WAIT_IDLE, radeon_gem_wait_idle_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
923 DRM_IOCTL_DEF_DRV(RADEON_CS, radeon_cs_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
924 DRM_IOCTL_DEF_DRV(RADEON_INFO, radeon_info_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
925 DRM_IOCTL_DEF_DRV(RADEON_GEM_SET_TILING, radeon_gem_set_tiling_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
926 DRM_IOCTL_DEF_DRV(RADEON_GEM_GET_TILING, radeon_gem_get_tiling_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
927 DRM_IOCTL_DEF_DRV(RADEON_GEM_BUSY, radeon_gem_busy_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
928 DRM_IOCTL_DEF_DRV(RADEON_GEM_VA, radeon_gem_va_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
Marek Olšákbda72d52014-03-02 00:56:17 +0100929 DRM_IOCTL_DEF_DRV(RADEON_GEM_OP, radeon_gem_op_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
Christian Königf72a113a2014-08-07 09:36:00 +0200930 DRM_IOCTL_DEF_DRV(RADEON_GEM_USERPTR, radeon_gem_userptr_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
Jerome Glisse771fe6b2009-06-05 14:42:42 +0200931};
Damien Lespiauf95aeb12014-06-09 14:39:49 +0100932int radeon_max_kms_ioctl = ARRAY_SIZE(radeon_ioctls_kms);