Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1 | /* |
| 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 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 28 | |
Thomas Zimmermann | 2ef7941 | 2019-12-03 11:04:02 +0100 | [diff] [blame] | 29 | #include <linux/pci.h> |
Dave Airlie | 10ebc0b | 2012-09-17 14:40:31 +1000 | [diff] [blame] | 30 | #include <linux/pm_runtime.h> |
Sam Ravnborg | f918312 | 2019-06-08 10:02:40 +0200 | [diff] [blame] | 31 | #include <linux/slab.h> |
| 32 | #include <linux/uaccess.h> |
| 33 | #include <linux/vga_switcheroo.h> |
| 34 | |
| 35 | #include <drm/drm_fb_helper.h> |
| 36 | #include <drm/drm_file.h> |
| 37 | #include <drm/drm_ioctl.h> |
Sam Ravnborg | f918312 | 2019-06-08 10:02:40 +0200 | [diff] [blame] | 38 | #include <drm/radeon_drm.h> |
| 39 | |
| 40 | #include "radeon.h" |
| 41 | #include "radeon_asic.h" |
Lee Jones | 9c69e42 | 2020-11-06 21:49:37 +0000 | [diff] [blame] | 42 | #include "radeon_drv.h" |
Lee Jones | 59718db | 2020-11-16 17:29:25 +0000 | [diff] [blame] | 43 | #include "radeon_kms.h" |
Alex Deucher | 7848865 | 2014-03-11 15:02:30 -0400 | [diff] [blame] | 44 | |
| 45 | #if defined(CONFIG_VGA_SWITCHEROO) |
Alex Deucher | 90c4cde | 2014-04-10 22:29:01 -0400 | [diff] [blame] | 46 | bool radeon_has_atpx(void); |
Alex Deucher | 7848865 | 2014-03-11 15:02:30 -0400 | [diff] [blame] | 47 | #else |
Alex Deucher | 90c4cde | 2014-04-10 22:29:01 -0400 | [diff] [blame] | 48 | static inline bool radeon_has_atpx(void) { return false; } |
Alex Deucher | 7848865 | 2014-03-11 15:02:30 -0400 | [diff] [blame] | 49 | #endif |
| 50 | |
Alex Deucher | f482a14 | 2012-07-17 14:02:34 -0400 | [diff] [blame] | 51 | /** |
| 52 | * radeon_driver_unload_kms - Main unload function for KMS. |
| 53 | * |
| 54 | * @dev: drm dev pointer |
| 55 | * |
| 56 | * This is the main unload function for KMS (all asics). |
| 57 | * It calls radeon_modeset_fini() to tear down the |
| 58 | * displays, and radeon_device_fini() to tear down |
| 59 | * the rest of the device (CP, writeback, etc.). |
| 60 | * Returns 0 on success. |
| 61 | */ |
Gabriel Krisman Bertazi | 11b3c20 | 2017-01-06 15:57:31 -0200 | [diff] [blame] | 62 | void radeon_driver_unload_kms(struct drm_device *dev) |
Jerome Glisse | cf0fe45 | 2009-12-09 18:21:55 +0100 | [diff] [blame] | 63 | { |
| 64 | struct radeon_device *rdev = dev->dev_private; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 65 | |
Jerome Glisse | cf0fe45 | 2009-12-09 18:21:55 +0100 | [diff] [blame] | 66 | if (rdev == NULL) |
Gabriel Krisman Bertazi | 11b3c20 | 2017-01-06 15:57:31 -0200 | [diff] [blame] | 67 | return; |
Dave Airlie | 10ebc0b | 2012-09-17 14:40:31 +1000 | [diff] [blame] | 68 | |
Alex Deucher | 0cd9cb7 | 2013-04-12 19:15:52 -0400 | [diff] [blame] | 69 | if (rdev->rmmio == NULL) |
| 70 | goto done_free; |
Dave Airlie | 10ebc0b | 2012-09-17 14:40:31 +1000 | [diff] [blame] | 71 | |
Lukas Wunner | 19de659 | 2016-06-08 18:47:27 +0200 | [diff] [blame] | 72 | if (radeon_is_px(dev)) { |
| 73 | pm_runtime_get_sync(dev->dev); |
Lukas Wunner | 8fecb6a | 2016-06-08 18:47:27 +0200 | [diff] [blame] | 74 | pm_runtime_forbid(dev->dev); |
Lukas Wunner | 19de659 | 2016-06-08 18:47:27 +0200 | [diff] [blame] | 75 | } |
Dave Airlie | 10ebc0b | 2012-09-17 14:40:31 +1000 | [diff] [blame] | 76 | |
Alex Deucher | c491707 | 2012-07-31 17:14:35 -0400 | [diff] [blame] | 77 | radeon_acpi_fini(rdev); |
Thomas Zimmermann | abe3910 | 2020-12-01 11:35:37 +0100 | [diff] [blame] | 78 | |
Jerome Glisse | cf0fe45 | 2009-12-09 18:21:55 +0100 | [diff] [blame] | 79 | radeon_modeset_fini(rdev); |
| 80 | radeon_device_fini(rdev); |
Alex Deucher | 0cd9cb7 | 2013-04-12 19:15:52 -0400 | [diff] [blame] | 81 | |
Thomas Zimmermann | 4335978 | 2021-05-07 20:57:07 +0200 | [diff] [blame] | 82 | if (rdev->agp) |
| 83 | arch_phys_wc_del(rdev->agp->agp_mtrr); |
| 84 | kfree(rdev->agp); |
| 85 | rdev->agp = NULL; |
Daniel Vetter | b8076b5 | 2020-02-22 18:54:32 +0100 | [diff] [blame] | 86 | |
Alex Deucher | 0cd9cb7 | 2013-04-12 19:15:52 -0400 | [diff] [blame] | 87 | done_free: |
Jerome Glisse | cf0fe45 | 2009-12-09 18:21:55 +0100 | [diff] [blame] | 88 | kfree(rdev); |
| 89 | dev->dev_private = NULL; |
Jerome Glisse | cf0fe45 | 2009-12-09 18:21:55 +0100 | [diff] [blame] | 90 | } |
| 91 | |
Alex Deucher | f482a14 | 2012-07-17 14:02:34 -0400 | [diff] [blame] | 92 | /** |
| 93 | * radeon_driver_load_kms - Main load function for KMS. |
| 94 | * |
| 95 | * @dev: drm dev pointer |
| 96 | * @flags: device flags |
| 97 | * |
| 98 | * This is the main load function for KMS (all asics). |
| 99 | * It calls radeon_device_init() to set up the non-display |
| 100 | * parts of the chip (asic init, CP, writeback, etc.), and |
| 101 | * radeon_modeset_init() to set up the display parts |
| 102 | * (crtcs, encoders, hotplug detect, etc.). |
| 103 | * Returns 0 on success, error on failure. |
| 104 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 105 | int radeon_driver_load_kms(struct drm_device *dev, unsigned long flags) |
| 106 | { |
Thomas Zimmermann | d86a412 | 2020-12-01 11:35:38 +0100 | [diff] [blame] | 107 | struct pci_dev *pdev = to_pci_dev(dev->dev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 108 | struct radeon_device *rdev; |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 109 | int r, acpi_status; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 110 | |
| 111 | rdev = kzalloc(sizeof(struct radeon_device), GFP_KERNEL); |
| 112 | if (rdev == NULL) { |
| 113 | return -ENOMEM; |
| 114 | } |
| 115 | dev->dev_private = (void *)rdev; |
| 116 | |
Thomas Zimmermann | 5c1736c | 2021-01-12 09:10:34 +0100 | [diff] [blame] | 117 | #ifdef __alpha__ |
| 118 | rdev->hose = pdev->sysdata; |
| 119 | #endif |
| 120 | |
Thomas Zimmermann | 4335978 | 2021-05-07 20:57:07 +0200 | [diff] [blame] | 121 | if (pci_find_capability(pdev, PCI_CAP_ID_AGP)) |
Nirmoy Das | 93def70 | 2021-09-13 10:08:23 +0200 | [diff] [blame] | 122 | rdev->agp = radeon_agp_head_init(dev); |
Thomas Zimmermann | 4335978 | 2021-05-07 20:57:07 +0200 | [diff] [blame] | 123 | if (rdev->agp) { |
| 124 | rdev->agp->agp_mtrr = arch_phys_wc_add( |
| 125 | rdev->agp->agp_info.aper_base, |
| 126 | rdev->agp->agp_info.aper_size * |
| 127 | 1024 * 1024); |
| 128 | } |
| 129 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 130 | /* update BUS flag */ |
Thomas Zimmermann | d86a412 | 2020-12-01 11:35:38 +0100 | [diff] [blame] | 131 | if (pci_find_capability(pdev, PCI_CAP_ID_AGP)) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 132 | flags |= RADEON_IS_AGP; |
Thomas Zimmermann | d86a412 | 2020-12-01 11:35:38 +0100 | [diff] [blame] | 133 | } else if (pci_is_pcie(pdev)) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 134 | flags |= RADEON_IS_PCIE; |
| 135 | } else { |
| 136 | flags |= RADEON_IS_PCI; |
| 137 | } |
| 138 | |
Alex Deucher | 73acacc | 2014-04-15 12:44:35 -0400 | [diff] [blame] | 139 | if ((radeon_runtime_pm != 0) && |
| 140 | radeon_has_atpx() && |
Lukas Wunner | 7ffb0ce3 | 2017-03-10 21:23:45 +0100 | [diff] [blame] | 141 | ((flags & RADEON_IS_IGP) == 0) && |
Thomas Zimmermann | d86a412 | 2020-12-01 11:35:38 +0100 | [diff] [blame] | 142 | !pci_is_thunderbolt_attached(pdev)) |
Alex Deucher | 90c4cde | 2014-04-10 22:29:01 -0400 | [diff] [blame] | 143 | flags |= RADEON_IS_PX; |
| 144 | |
Jerome Glisse | 6cf8a3f5 | 2009-09-10 21:46:48 +0200 | [diff] [blame] | 145 | /* radeon_device_init should report only fatal error |
| 146 | * like memory allocation failure or iomapping failure, |
| 147 | * or memory manager initialization failure, it must |
| 148 | * properly initialize the GPU MC controller and permit |
| 149 | * VRAM allocation |
| 150 | */ |
Thomas Zimmermann | d86a412 | 2020-12-01 11:35:38 +0100 | [diff] [blame] | 151 | r = radeon_device_init(rdev, dev, pdev, flags); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 152 | if (r) { |
Thomas Zimmermann | d86a412 | 2020-12-01 11:35:38 +0100 | [diff] [blame] | 153 | dev_err(dev->dev, "Fatal error during GPU init\n"); |
Jerome Glisse | cf0fe45 | 2009-12-09 18:21:55 +0100 | [diff] [blame] | 154 | goto out; |
Jerome Glisse | 6cf8a3f5 | 2009-09-10 21:46:48 +0200 | [diff] [blame] | 155 | } |
Alberto Milone | d7a2952 | 2010-07-06 11:40:24 -0400 | [diff] [blame] | 156 | |
Jerome Glisse | 6cf8a3f5 | 2009-09-10 21:46:48 +0200 | [diff] [blame] | 157 | /* Again modeset_init should fail only on fatal error |
| 158 | * otherwise it should provide enough functionalities |
| 159 | * for shadowfb to run |
| 160 | */ |
| 161 | r = radeon_modeset_init(rdev); |
Jerome Glisse | cf0fe45 | 2009-12-09 18:21:55 +0100 | [diff] [blame] | 162 | if (r) |
Thomas Zimmermann | d86a412 | 2020-12-01 11:35:38 +0100 | [diff] [blame] | 163 | dev_err(dev->dev, "Fatal error during modeset init\n"); |
Luca Tettamanti | fda4b25 | 2012-07-30 21:20:35 +0200 | [diff] [blame] | 164 | |
| 165 | /* Call ACPI methods: require modeset init |
| 166 | * but failure is not fatal |
| 167 | */ |
| 168 | if (!r) { |
| 169 | acpi_status = radeon_acpi_init(rdev); |
| 170 | if (acpi_status) |
Xu Wang | a6506cd8 | 2021-11-10 09:42:42 +0000 | [diff] [blame] | 171 | dev_dbg(dev->dev, "Error during ACPI methods call\n"); |
Luca Tettamanti | fda4b25 | 2012-07-30 21:20:35 +0200 | [diff] [blame] | 172 | } |
| 173 | |
Alex Deucher | 90c4cde | 2014-04-10 22:29:01 -0400 | [diff] [blame] | 174 | if (radeon_is_px(dev)) { |
Rafael J. Wysocki | e075155 | 2020-04-18 18:53:01 +0200 | [diff] [blame] | 175 | dev_pm_set_driver_flags(dev->dev, DPM_FLAG_NO_DIRECT_COMPLETE); |
Dave Airlie | 10ebc0b | 2012-09-17 14:40:31 +1000 | [diff] [blame] | 176 | pm_runtime_use_autosuspend(dev->dev); |
| 177 | pm_runtime_set_autosuspend_delay(dev->dev, 5000); |
| 178 | pm_runtime_set_active(dev->dev); |
| 179 | pm_runtime_allow(dev->dev); |
| 180 | pm_runtime_mark_last_busy(dev->dev); |
| 181 | pm_runtime_put_autosuspend(dev->dev); |
| 182 | } |
| 183 | |
Jerome Glisse | cf0fe45 | 2009-12-09 18:21:55 +0100 | [diff] [blame] | 184 | out: |
| 185 | if (r) |
| 186 | radeon_driver_unload_kms(dev); |
Dave Airlie | 10ebc0b | 2012-09-17 14:40:31 +1000 | [diff] [blame] | 187 | |
| 188 | |
Jerome Glisse | cf0fe45 | 2009-12-09 18:21:55 +0100 | [diff] [blame] | 189 | return r; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 190 | } |
| 191 | |
Alex Deucher | f482a14 | 2012-07-17 14:02:34 -0400 | [diff] [blame] | 192 | /** |
| 193 | * radeon_set_filp_rights - Set filp right. |
| 194 | * |
| 195 | * @dev: drm dev pointer |
| 196 | * @owner: drm file |
| 197 | * @applier: drm file |
| 198 | * @value: value |
| 199 | * |
| 200 | * Sets the filp rights for the device (all asics). |
| 201 | */ |
Marek Olšák | 9eba4a9 | 2011-01-05 05:46:48 +0100 | [diff] [blame] | 202 | static void radeon_set_filp_rights(struct drm_device *dev, |
| 203 | struct drm_file **owner, |
| 204 | struct drm_file *applier, |
| 205 | uint32_t *value) |
| 206 | { |
Daniel Vetter | 45c1da5 | 2015-10-15 09:36:34 +0200 | [diff] [blame] | 207 | struct radeon_device *rdev = dev->dev_private; |
| 208 | |
| 209 | mutex_lock(&rdev->gem.mutex); |
Marek Olšák | 9eba4a9 | 2011-01-05 05:46:48 +0100 | [diff] [blame] | 210 | if (*value == 1) { |
| 211 | /* wants rights */ |
| 212 | if (!*owner) |
| 213 | *owner = applier; |
| 214 | } else if (*value == 0) { |
| 215 | /* revokes rights */ |
| 216 | if (*owner == applier) |
| 217 | *owner = NULL; |
| 218 | } |
| 219 | *value = *owner == applier ? 1 : 0; |
Daniel Vetter | 45c1da5 | 2015-10-15 09:36:34 +0200 | [diff] [blame] | 220 | mutex_unlock(&rdev->gem.mutex); |
Marek Olšák | 9eba4a9 | 2011-01-05 05:46:48 +0100 | [diff] [blame] | 221 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 222 | |
| 223 | /* |
Marek Olšák | 9eba4a9 | 2011-01-05 05:46:48 +0100 | [diff] [blame] | 224 | * Userspace get information ioctl |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 225 | */ |
Alex Deucher | f482a14 | 2012-07-17 14:02:34 -0400 | [diff] [blame] | 226 | /** |
| 227 | * radeon_info_ioctl - answer a device specific request. |
| 228 | * |
Lee Jones | f5194f7 | 2020-11-16 17:29:26 +0000 | [diff] [blame] | 229 | * @dev: drm device pointer |
Alex Deucher | f482a14 | 2012-07-17 14:02:34 -0400 | [diff] [blame] | 230 | * @data: request object |
| 231 | * @filp: drm filp |
| 232 | * |
| 233 | * This function is used to pass device specific parameters to the userspace |
| 234 | * drivers. Examples include: pci device id, pipeline parms, tiling params, |
| 235 | * etc. (all asics). |
| 236 | * Returns 0 on success, -EINVAL on failure. |
| 237 | */ |
Daniel Vetter | 384bc5e | 2020-11-04 11:04:20 +0100 | [diff] [blame] | 238 | int radeon_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 239 | { |
| 240 | struct radeon_device *rdev = dev->dev_private; |
Marek Olšák | 6759a0a | 2012-08-09 16:34:17 +0200 | [diff] [blame] | 241 | struct drm_radeon_info *info = data; |
Jerome Glisse | bc35afd | 2010-05-12 18:01:13 +0200 | [diff] [blame] | 242 | struct radeon_mode_info *minfo = &rdev->mode_info; |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 243 | uint32_t *value, value_tmp, *value_ptr, value_size; |
| 244 | uint64_t value64; |
Jerome Glisse | bc35afd | 2010-05-12 18:01:13 +0200 | [diff] [blame] | 245 | struct drm_crtc *crtc; |
| 246 | int i, found; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 247 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 248 | value_ptr = (uint32_t *)((unsigned long)info->value); |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 249 | value = &value_tmp; |
| 250 | value_size = sizeof(uint32_t); |
Dr. David Alan Gilbert | d8ab355 | 2010-08-02 09:43:52 +1000 | [diff] [blame] | 251 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 252 | switch (info->request) { |
| 253 | case RADEON_INFO_DEVICE_ID: |
Thomas Zimmermann | d86a412 | 2020-12-01 11:35:38 +0100 | [diff] [blame] | 254 | *value = to_pci_dev(dev->dev)->device; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 255 | break; |
| 256 | case RADEON_INFO_NUM_GB_PIPES: |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 257 | *value = rdev->num_gb_pipes; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 258 | break; |
Alex Deucher | f779b3e | 2009-08-19 19:11:39 -0400 | [diff] [blame] | 259 | case RADEON_INFO_NUM_Z_PIPES: |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 260 | *value = rdev->num_z_pipes; |
Alex Deucher | f779b3e | 2009-08-19 19:11:39 -0400 | [diff] [blame] | 261 | break; |
Jerome Glisse | 733289c | 2009-09-16 15:24:21 +0200 | [diff] [blame] | 262 | case RADEON_INFO_ACCEL_WORKING: |
Alex Deucher | 148a03b | 2010-06-03 19:00:03 -0400 | [diff] [blame] | 263 | /* xf86-video-ati 6.13.0 relies on this being false for evergreen */ |
| 264 | if ((rdev->family >= CHIP_CEDAR) && (rdev->family <= CHIP_HEMLOCK)) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 265 | *value = false; |
Alex Deucher | 148a03b | 2010-06-03 19:00:03 -0400 | [diff] [blame] | 266 | else |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 267 | *value = rdev->accel_working; |
Jerome Glisse | 733289c | 2009-09-16 15:24:21 +0200 | [diff] [blame] | 268 | break; |
Jerome Glisse | bc35afd | 2010-05-12 18:01:13 +0200 | [diff] [blame] | 269 | case RADEON_INFO_CRTC_FROM_ID: |
Daniel Vetter | 1d6ac18 | 2013-12-11 11:34:44 +0100 | [diff] [blame] | 270 | if (copy_from_user(value, value_ptr, sizeof(uint32_t))) { |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 271 | DRM_ERROR("copy_from_user %s:%u\n", __func__, __LINE__); |
| 272 | return -EFAULT; |
| 273 | } |
Jerome Glisse | bc35afd | 2010-05-12 18:01:13 +0200 | [diff] [blame] | 274 | for (i = 0, found = 0; i < rdev->num_crtc; i++) { |
| 275 | crtc = (struct drm_crtc *)minfo->crtcs[i]; |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 276 | if (crtc && crtc->base.id == *value) { |
Alex Deucher | 0baf2d8 | 2010-07-21 14:05:35 -0400 | [diff] [blame] | 277 | struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 278 | *value = radeon_crtc->crtc_id; |
Jerome Glisse | bc35afd | 2010-05-12 18:01:13 +0200 | [diff] [blame] | 279 | found = 1; |
| 280 | break; |
| 281 | } |
| 282 | } |
| 283 | if (!found) { |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 284 | DRM_DEBUG_KMS("unknown crtc id %d\n", *value); |
Jerome Glisse | bc35afd | 2010-05-12 18:01:13 +0200 | [diff] [blame] | 285 | return -EINVAL; |
| 286 | } |
| 287 | break; |
Alex Deucher | 148a03b | 2010-06-03 19:00:03 -0400 | [diff] [blame] | 288 | case RADEON_INFO_ACCEL_WORKING2: |
Alex Deucher | 3c64bd2 | 2014-08-01 20:05:30 +0200 | [diff] [blame] | 289 | if (rdev->family == CHIP_HAWAII) { |
Andreas Boll | 9eb401a | 2014-08-01 20:05:32 +0200 | [diff] [blame] | 290 | if (rdev->accel_working) { |
| 291 | if (rdev->new_fw) |
| 292 | *value = 3; |
| 293 | else |
| 294 | *value = 2; |
| 295 | } else { |
Alex Deucher | 3c64bd2 | 2014-08-01 20:05:30 +0200 | [diff] [blame] | 296 | *value = 0; |
Andreas Boll | 9eb401a | 2014-08-01 20:05:32 +0200 | [diff] [blame] | 297 | } |
Alex Deucher | 3c64bd2 | 2014-08-01 20:05:30 +0200 | [diff] [blame] | 298 | } else { |
| 299 | *value = rdev->accel_working; |
| 300 | } |
Alex Deucher | 148a03b | 2010-06-03 19:00:03 -0400 | [diff] [blame] | 301 | break; |
Alex Deucher | e7aeeba6 | 2010-06-04 13:10:12 -0400 | [diff] [blame] | 302 | case RADEON_INFO_TILING_CONFIG: |
Alex Deucher | 64f759c | 2012-07-06 17:40:32 -0400 | [diff] [blame] | 303 | if (rdev->family >= CHIP_BONAIRE) |
| 304 | *value = rdev->config.cik.tile_config; |
| 305 | else if (rdev->family >= CHIP_TAHITI) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 306 | *value = rdev->config.si.tile_config; |
Michel Dänzer | c1b2f69 | 2012-03-20 17:18:26 -0400 | [diff] [blame] | 307 | else if (rdev->family >= CHIP_CAYMAN) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 308 | *value = rdev->config.cayman.tile_config; |
Alex Deucher | fecf1d0 | 2011-03-02 20:07:29 -0500 | [diff] [blame] | 309 | else if (rdev->family >= CHIP_CEDAR) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 310 | *value = rdev->config.evergreen.tile_config; |
Alex Deucher | e7aeeba6 | 2010-06-04 13:10:12 -0400 | [diff] [blame] | 311 | else if (rdev->family >= CHIP_RV770) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 312 | *value = rdev->config.rv770.tile_config; |
Alex Deucher | e7aeeba6 | 2010-06-04 13:10:12 -0400 | [diff] [blame] | 313 | else if (rdev->family >= CHIP_R600) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 314 | *value = rdev->config.r600.tile_config; |
Alex Deucher | e7aeeba6 | 2010-06-04 13:10:12 -0400 | [diff] [blame] | 315 | else { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 316 | DRM_DEBUG_KMS("tiling config is r6xx+ only!\n"); |
Alex Deucher | e7aeeba6 | 2010-06-04 13:10:12 -0400 | [diff] [blame] | 317 | return -EINVAL; |
| 318 | } |
Alex Deucher | b824b36 | 2010-08-12 08:25:47 -0400 | [diff] [blame] | 319 | break; |
Dave Airlie | ab9e1f5 | 2010-07-13 11:11:11 +1000 | [diff] [blame] | 320 | case RADEON_INFO_WANT_HYPERZ: |
Marek Olšák | 43861f7 | 2010-08-07 03:36:34 +0200 | [diff] [blame] | 321 | /* The "value" here is both an input and output parameter. |
| 322 | * If the input value is 1, filp requests hyper-z access. |
| 323 | * If the input value is 0, filp revokes its hyper-z access. |
| 324 | * |
| 325 | * When returning, the value is 1 if filp owns hyper-z access, |
| 326 | * 0 otherwise. */ |
Daniel Vetter | 1d6ac18 | 2013-12-11 11:34:44 +0100 | [diff] [blame] | 327 | if (copy_from_user(value, value_ptr, sizeof(uint32_t))) { |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 328 | DRM_ERROR("copy_from_user %s:%u\n", __func__, __LINE__); |
| 329 | return -EFAULT; |
| 330 | } |
| 331 | if (*value >= 2) { |
| 332 | DRM_DEBUG_KMS("WANT_HYPERZ: invalid value %d\n", *value); |
Marek Olšák | 43861f7 | 2010-08-07 03:36:34 +0200 | [diff] [blame] | 333 | return -EINVAL; |
Dave Airlie | ab9e1f5 | 2010-07-13 11:11:11 +1000 | [diff] [blame] | 334 | } |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 335 | radeon_set_filp_rights(dev, &rdev->hyperz_filp, filp, value); |
Marek Olšák | 9eba4a9 | 2011-01-05 05:46:48 +0100 | [diff] [blame] | 336 | break; |
| 337 | case RADEON_INFO_WANT_CMASK: |
| 338 | /* The same logic as Hyper-Z. */ |
Daniel Vetter | 1d6ac18 | 2013-12-11 11:34:44 +0100 | [diff] [blame] | 339 | if (copy_from_user(value, value_ptr, sizeof(uint32_t))) { |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 340 | DRM_ERROR("copy_from_user %s:%u\n", __func__, __LINE__); |
| 341 | return -EFAULT; |
| 342 | } |
| 343 | if (*value >= 2) { |
| 344 | DRM_DEBUG_KMS("WANT_CMASK: invalid value %d\n", *value); |
Marek Olšák | 9eba4a9 | 2011-01-05 05:46:48 +0100 | [diff] [blame] | 345 | return -EINVAL; |
Marek Olšák | 43861f7 | 2010-08-07 03:36:34 +0200 | [diff] [blame] | 346 | } |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 347 | radeon_set_filp_rights(dev, &rdev->cmask_filp, filp, value); |
Alex Deucher | e7aeeba6 | 2010-06-04 13:10:12 -0400 | [diff] [blame] | 348 | break; |
Alex Deucher | 58bbf01 | 2011-01-24 17:14:26 -0500 | [diff] [blame] | 349 | case RADEON_INFO_CLOCK_CRYSTAL_FREQ: |
| 350 | /* return clock value in KHz */ |
Alex Deucher | 454d2e2 | 2013-02-14 10:04:02 -0500 | [diff] [blame] | 351 | if (rdev->asic->get_xclk) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 352 | *value = radeon_get_xclk(rdev) * 10; |
Alex Deucher | 454d2e2 | 2013-02-14 10:04:02 -0500 | [diff] [blame] | 353 | else |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 354 | *value = rdev->clock.spll.reference_freq * 10; |
Alex Deucher | 58bbf01 | 2011-01-24 17:14:26 -0500 | [diff] [blame] | 355 | break; |
Dave Airlie | 486af18 | 2011-03-01 14:32:27 +1000 | [diff] [blame] | 356 | case RADEON_INFO_NUM_BACKENDS: |
Alex Deucher | 64f759c | 2012-07-06 17:40:32 -0400 | [diff] [blame] | 357 | if (rdev->family >= CHIP_BONAIRE) |
| 358 | *value = rdev->config.cik.max_backends_per_se * |
| 359 | rdev->config.cik.max_shader_engines; |
| 360 | else if (rdev->family >= CHIP_TAHITI) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 361 | *value = rdev->config.si.max_backends_per_se * |
Michel Dänzer | c1b2f69 | 2012-03-20 17:18:26 -0400 | [diff] [blame] | 362 | rdev->config.si.max_shader_engines; |
| 363 | else if (rdev->family >= CHIP_CAYMAN) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 364 | *value = rdev->config.cayman.max_backends_per_se * |
Alex Deucher | fecf1d0 | 2011-03-02 20:07:29 -0500 | [diff] [blame] | 365 | rdev->config.cayman.max_shader_engines; |
| 366 | else if (rdev->family >= CHIP_CEDAR) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 367 | *value = rdev->config.evergreen.max_backends; |
Dave Airlie | 486af18 | 2011-03-01 14:32:27 +1000 | [diff] [blame] | 368 | else if (rdev->family >= CHIP_RV770) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 369 | *value = rdev->config.rv770.max_backends; |
Dave Airlie | 486af18 | 2011-03-01 14:32:27 +1000 | [diff] [blame] | 370 | else if (rdev->family >= CHIP_R600) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 371 | *value = rdev->config.r600.max_backends; |
Dave Airlie | 486af18 | 2011-03-01 14:32:27 +1000 | [diff] [blame] | 372 | else { |
| 373 | return -EINVAL; |
| 374 | } |
| 375 | break; |
Alex Deucher | 6565945 | 2011-04-26 13:27:43 -0400 | [diff] [blame] | 376 | case RADEON_INFO_NUM_TILE_PIPES: |
Alex Deucher | 64f759c | 2012-07-06 17:40:32 -0400 | [diff] [blame] | 377 | if (rdev->family >= CHIP_BONAIRE) |
| 378 | *value = rdev->config.cik.max_tile_pipes; |
| 379 | else if (rdev->family >= CHIP_TAHITI) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 380 | *value = rdev->config.si.max_tile_pipes; |
Michel Dänzer | c1b2f69 | 2012-03-20 17:18:26 -0400 | [diff] [blame] | 381 | else if (rdev->family >= CHIP_CAYMAN) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 382 | *value = rdev->config.cayman.max_tile_pipes; |
Alex Deucher | 6565945 | 2011-04-26 13:27:43 -0400 | [diff] [blame] | 383 | else if (rdev->family >= CHIP_CEDAR) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 384 | *value = rdev->config.evergreen.max_tile_pipes; |
Alex Deucher | 6565945 | 2011-04-26 13:27:43 -0400 | [diff] [blame] | 385 | else if (rdev->family >= CHIP_RV770) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 386 | *value = rdev->config.rv770.max_tile_pipes; |
Alex Deucher | 6565945 | 2011-04-26 13:27:43 -0400 | [diff] [blame] | 387 | else if (rdev->family >= CHIP_R600) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 388 | *value = rdev->config.r600.max_tile_pipes; |
Alex Deucher | 6565945 | 2011-04-26 13:27:43 -0400 | [diff] [blame] | 389 | else { |
| 390 | return -EINVAL; |
| 391 | } |
| 392 | break; |
Alex Deucher | 8aeb96f8 | 2011-05-03 19:28:02 -0400 | [diff] [blame] | 393 | case RADEON_INFO_FUSION_GART_WORKING: |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 394 | *value = 1; |
Alex Deucher | 8aeb96f8 | 2011-05-03 19:28:02 -0400 | [diff] [blame] | 395 | break; |
Alex Deucher | e55b942 | 2011-07-15 19:53:52 +0000 | [diff] [blame] | 396 | case RADEON_INFO_BACKEND_MAP: |
Alex Deucher | 64f759c | 2012-07-06 17:40:32 -0400 | [diff] [blame] | 397 | if (rdev->family >= CHIP_BONAIRE) |
Michel Dänzer | 1ddce27 | 2013-11-18 18:25:59 +0900 | [diff] [blame] | 398 | *value = rdev->config.cik.backend_map; |
Alex Deucher | 64f759c | 2012-07-06 17:40:32 -0400 | [diff] [blame] | 399 | else if (rdev->family >= CHIP_TAHITI) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 400 | *value = rdev->config.si.backend_map; |
Michel Dänzer | c1b2f69 | 2012-03-20 17:18:26 -0400 | [diff] [blame] | 401 | else if (rdev->family >= CHIP_CAYMAN) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 402 | *value = rdev->config.cayman.backend_map; |
Alex Deucher | e55b942 | 2011-07-15 19:53:52 +0000 | [diff] [blame] | 403 | else if (rdev->family >= CHIP_CEDAR) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 404 | *value = rdev->config.evergreen.backend_map; |
Alex Deucher | e55b942 | 2011-07-15 19:53:52 +0000 | [diff] [blame] | 405 | else if (rdev->family >= CHIP_RV770) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 406 | *value = rdev->config.rv770.backend_map; |
Alex Deucher | e55b942 | 2011-07-15 19:53:52 +0000 | [diff] [blame] | 407 | else if (rdev->family >= CHIP_R600) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 408 | *value = rdev->config.r600.backend_map; |
Alex Deucher | e55b942 | 2011-07-15 19:53:52 +0000 | [diff] [blame] | 409 | else { |
| 410 | return -EINVAL; |
| 411 | } |
| 412 | break; |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 413 | case RADEON_INFO_VA_START: |
| 414 | /* this is where we report if vm is supported or not */ |
| 415 | if (rdev->family < CHIP_CAYMAN) |
| 416 | return -EINVAL; |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 417 | *value = RADEON_VA_RESERVED_SIZE; |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 418 | break; |
| 419 | case RADEON_INFO_IB_VM_MAX_SIZE: |
| 420 | /* this is where we report if vm is supported or not */ |
| 421 | if (rdev->family < CHIP_CAYMAN) |
| 422 | return -EINVAL; |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 423 | *value = RADEON_IB_VM_MAX_SIZE; |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 424 | break; |
Tom Stellard | 609c1e1 | 2012-03-20 17:17:55 -0400 | [diff] [blame] | 425 | case RADEON_INFO_MAX_PIPES: |
Alex Deucher | 64f759c | 2012-07-06 17:40:32 -0400 | [diff] [blame] | 426 | if (rdev->family >= CHIP_BONAIRE) |
| 427 | *value = rdev->config.cik.max_cu_per_sh; |
| 428 | else if (rdev->family >= CHIP_TAHITI) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 429 | *value = rdev->config.si.max_cu_per_sh; |
Michel Dänzer | c1b2f69 | 2012-03-20 17:18:26 -0400 | [diff] [blame] | 430 | else if (rdev->family >= CHIP_CAYMAN) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 431 | *value = rdev->config.cayman.max_pipes_per_simd; |
Tom Stellard | 609c1e1 | 2012-03-20 17:17:55 -0400 | [diff] [blame] | 432 | else if (rdev->family >= CHIP_CEDAR) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 433 | *value = rdev->config.evergreen.max_pipes; |
Tom Stellard | 609c1e1 | 2012-03-20 17:17:55 -0400 | [diff] [blame] | 434 | else if (rdev->family >= CHIP_RV770) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 435 | *value = rdev->config.rv770.max_pipes; |
Tom Stellard | 609c1e1 | 2012-03-20 17:17:55 -0400 | [diff] [blame] | 436 | else if (rdev->family >= CHIP_R600) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 437 | *value = rdev->config.r600.max_pipes; |
Tom Stellard | 609c1e1 | 2012-03-20 17:17:55 -0400 | [diff] [blame] | 438 | else { |
| 439 | return -EINVAL; |
| 440 | } |
| 441 | break; |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 442 | case RADEON_INFO_TIMESTAMP: |
| 443 | if (rdev->family < CHIP_R600) { |
| 444 | DRM_DEBUG_KMS("timestamp is r6xx+ only!\n"); |
| 445 | return -EINVAL; |
| 446 | } |
| 447 | value = (uint32_t*)&value64; |
| 448 | value_size = sizeof(uint64_t); |
| 449 | value64 = radeon_get_gpu_clock_counter(rdev); |
| 450 | break; |
Alex Deucher | 2e1a767 | 2012-12-04 12:55:37 -0500 | [diff] [blame] | 451 | case RADEON_INFO_MAX_SE: |
Alex Deucher | 64f759c | 2012-07-06 17:40:32 -0400 | [diff] [blame] | 452 | if (rdev->family >= CHIP_BONAIRE) |
| 453 | *value = rdev->config.cik.max_shader_engines; |
| 454 | else if (rdev->family >= CHIP_TAHITI) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 455 | *value = rdev->config.si.max_shader_engines; |
Alex Deucher | 2e1a767 | 2012-12-04 12:55:37 -0500 | [diff] [blame] | 456 | else if (rdev->family >= CHIP_CAYMAN) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 457 | *value = rdev->config.cayman.max_shader_engines; |
Alex Deucher | 2e1a767 | 2012-12-04 12:55:37 -0500 | [diff] [blame] | 458 | else if (rdev->family >= CHIP_CEDAR) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 459 | *value = rdev->config.evergreen.num_ses; |
Alex Deucher | 2e1a767 | 2012-12-04 12:55:37 -0500 | [diff] [blame] | 460 | else |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 461 | *value = 1; |
Alex Deucher | 2e1a767 | 2012-12-04 12:55:37 -0500 | [diff] [blame] | 462 | break; |
| 463 | case RADEON_INFO_MAX_SH_PER_SE: |
Alex Deucher | 64f759c | 2012-07-06 17:40:32 -0400 | [diff] [blame] | 464 | if (rdev->family >= CHIP_BONAIRE) |
| 465 | *value = rdev->config.cik.max_sh_per_se; |
| 466 | else if (rdev->family >= CHIP_TAHITI) |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 467 | *value = rdev->config.si.max_sh_per_se; |
Alex Deucher | 2e1a767 | 2012-12-04 12:55:37 -0500 | [diff] [blame] | 468 | else |
| 469 | return -EINVAL; |
| 470 | break; |
Samuel Li | a0a53aa | 2013-04-08 17:25:47 -0400 | [diff] [blame] | 471 | case RADEON_INFO_FASTFB_WORKING: |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 472 | *value = rdev->fastfb_working; |
Samuel Li | a0a53aa | 2013-04-08 17:25:47 -0400 | [diff] [blame] | 473 | break; |
Christian König | 902aaef | 2013-04-09 10:35:42 -0400 | [diff] [blame] | 474 | case RADEON_INFO_RING_WORKING: |
Daniel Vetter | 1d6ac18 | 2013-12-11 11:34:44 +0100 | [diff] [blame] | 475 | if (copy_from_user(value, value_ptr, sizeof(uint32_t))) { |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 476 | DRM_ERROR("copy_from_user %s:%u\n", __func__, __LINE__); |
| 477 | return -EFAULT; |
| 478 | } |
| 479 | switch (*value) { |
Christian König | 902aaef | 2013-04-09 10:35:42 -0400 | [diff] [blame] | 480 | case RADEON_CS_RING_GFX: |
| 481 | case RADEON_CS_RING_COMPUTE: |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 482 | *value = rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready; |
Christian König | 902aaef | 2013-04-09 10:35:42 -0400 | [diff] [blame] | 483 | break; |
| 484 | case RADEON_CS_RING_DMA: |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 485 | *value = rdev->ring[R600_RING_TYPE_DMA_INDEX].ready; |
| 486 | *value |= rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX].ready; |
Christian König | 902aaef | 2013-04-09 10:35:42 -0400 | [diff] [blame] | 487 | break; |
| 488 | case RADEON_CS_RING_UVD: |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 489 | *value = rdev->ring[R600_RING_TYPE_UVD_INDEX].ready; |
Christian König | 902aaef | 2013-04-09 10:35:42 -0400 | [diff] [blame] | 490 | break; |
Christian König | f7ba8b0 | 2014-01-27 10:16:06 -0700 | [diff] [blame] | 491 | case RADEON_CS_RING_VCE: |
| 492 | *value = rdev->ring[TN_RING_TYPE_VCE1_INDEX].ready; |
| 493 | break; |
Christian König | 902aaef | 2013-04-09 10:35:42 -0400 | [diff] [blame] | 494 | default: |
| 495 | return -EINVAL; |
| 496 | } |
| 497 | break; |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 498 | case RADEON_INFO_SI_TILE_MODE_ARRAY: |
Alex Deucher | 64f759c | 2012-07-06 17:40:32 -0400 | [diff] [blame] | 499 | if (rdev->family >= CHIP_BONAIRE) { |
Alex Deucher | 39aee49 | 2013-04-10 13:41:25 -0400 | [diff] [blame] | 500 | value = rdev->config.cik.tile_mode_array; |
| 501 | value_size = sizeof(uint32_t)*32; |
| 502 | } else if (rdev->family >= CHIP_TAHITI) { |
| 503 | value = rdev->config.si.tile_mode_array; |
| 504 | value_size = sizeof(uint32_t)*32; |
| 505 | } else { |
| 506 | DRM_DEBUG_KMS("tile mode array is si+ only!\n"); |
Alex Deucher | 64f759c | 2012-07-06 17:40:32 -0400 | [diff] [blame] | 507 | return -EINVAL; |
| 508 | } |
Jerome Glisse | 64d7b8b | 2013-04-09 11:17:08 -0400 | [diff] [blame] | 509 | break; |
Michel Dänzer | 32f79a8 | 2013-11-18 18:26:00 +0900 | [diff] [blame] | 510 | case RADEON_INFO_CIK_MACROTILE_MODE_ARRAY: |
| 511 | if (rdev->family >= CHIP_BONAIRE) { |
| 512 | value = rdev->config.cik.macrotile_mode_array; |
| 513 | value_size = sizeof(uint32_t)*16; |
| 514 | } else { |
| 515 | DRM_DEBUG_KMS("macrotile mode array is cik+ only!\n"); |
| 516 | return -EINVAL; |
| 517 | } |
| 518 | break; |
Tom Stellard | e5b9e75 | 2013-08-16 17:47:39 -0400 | [diff] [blame] | 519 | case RADEON_INFO_SI_CP_DMA_COMPUTE: |
| 520 | *value = 1; |
| 521 | break; |
Marek Olšák | 439a1cf | 2013-12-22 02:18:01 +0100 | [diff] [blame] | 522 | case RADEON_INFO_SI_BACKEND_ENABLED_MASK: |
| 523 | if (rdev->family >= CHIP_BONAIRE) { |
| 524 | *value = rdev->config.cik.backend_enable_mask; |
| 525 | } else if (rdev->family >= CHIP_TAHITI) { |
| 526 | *value = rdev->config.si.backend_enable_mask; |
| 527 | } else { |
| 528 | DRM_DEBUG_KMS("BACKEND_ENABLED_MASK is si+ only!\n"); |
Colin Ian King | 8dbc2cc | 2021-03-03 00:27:59 +0000 | [diff] [blame] | 529 | return -EINVAL; |
Marek Olšák | 439a1cf | 2013-12-22 02:18:01 +0100 | [diff] [blame] | 530 | } |
| 531 | break; |
Alex Deucher | f5f1f89 | 2014-01-20 18:20:29 -0500 | [diff] [blame] | 532 | case RADEON_INFO_MAX_SCLK: |
| 533 | if ((rdev->pm.pm_method == PM_METHOD_DPM) && |
| 534 | rdev->pm.dpm_enabled) |
| 535 | *value = rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.sclk * 10; |
| 536 | else |
| 537 | *value = rdev->pm.default_sclk * 10; |
| 538 | break; |
Christian König | 98ccc29 | 2014-01-23 09:50:49 -0700 | [diff] [blame] | 539 | case RADEON_INFO_VCE_FW_VERSION: |
| 540 | *value = rdev->vce.fw_version; |
| 541 | break; |
| 542 | case RADEON_INFO_VCE_FB_VERSION: |
| 543 | *value = rdev->vce.fb_version; |
| 544 | break; |
Marek Olšák | 67e8e3f | 2014-03-02 00:56:18 +0100 | [diff] [blame] | 545 | case RADEON_INFO_NUM_BYTES_MOVED: |
| 546 | value = (uint32_t*)&value64; |
| 547 | value_size = sizeof(uint64_t); |
| 548 | value64 = atomic64_read(&rdev->num_bytes_moved); |
| 549 | break; |
| 550 | case RADEON_INFO_VRAM_USAGE: |
| 551 | value = (uint32_t*)&value64; |
| 552 | value_size = sizeof(uint64_t); |
| 553 | value64 = atomic64_read(&rdev->vram_usage); |
| 554 | break; |
| 555 | case RADEON_INFO_GTT_USAGE: |
| 556 | value = (uint32_t*)&value64; |
| 557 | value_size = sizeof(uint64_t); |
| 558 | value64 = atomic64_read(&rdev->gtt_usage); |
| 559 | break; |
Alex Deucher | 65fcf66 | 2014-06-02 16:13:21 -0400 | [diff] [blame] | 560 | case RADEON_INFO_ACTIVE_CU_COUNT: |
| 561 | if (rdev->family >= CHIP_BONAIRE) |
| 562 | *value = rdev->config.cik.active_cus; |
| 563 | else if (rdev->family >= CHIP_TAHITI) |
| 564 | *value = rdev->config.si.active_cus; |
| 565 | else if (rdev->family >= CHIP_CAYMAN) |
| 566 | *value = rdev->config.cayman.active_simds; |
| 567 | else if (rdev->family >= CHIP_CEDAR) |
| 568 | *value = rdev->config.evergreen.active_simds; |
| 569 | else if (rdev->family >= CHIP_RV770) |
| 570 | *value = rdev->config.rv770.active_simds; |
| 571 | else if (rdev->family >= CHIP_R600) |
| 572 | *value = rdev->config.r600.active_simds; |
| 573 | else |
| 574 | *value = 1; |
| 575 | break; |
Alex Deucher | d6d2a18 | 2014-09-30 10:04:40 -0400 | [diff] [blame] | 576 | case RADEON_INFO_CURRENT_GPU_TEMP: |
| 577 | /* get temperature in millidegrees C */ |
| 578 | if (rdev->asic->pm.get_temperature) |
| 579 | *value = radeon_get_temperature(rdev); |
| 580 | else |
| 581 | *value = 0; |
| 582 | break; |
Alex Deucher | 5c363a8 | 2014-09-30 11:33:30 -0400 | [diff] [blame] | 583 | case RADEON_INFO_CURRENT_GPU_SCLK: |
| 584 | /* get sclk in Mhz */ |
| 585 | if (rdev->pm.dpm_enabled) |
| 586 | *value = radeon_dpm_get_current_sclk(rdev) / 100; |
| 587 | else |
| 588 | *value = rdev->pm.current_sclk / 100; |
| 589 | break; |
| 590 | case RADEON_INFO_CURRENT_GPU_MCLK: |
| 591 | /* get mclk in Mhz */ |
| 592 | if (rdev->pm.dpm_enabled) |
| 593 | *value = radeon_dpm_get_current_mclk(rdev) / 100; |
| 594 | else |
| 595 | *value = rdev->pm.current_mclk / 100; |
| 596 | break; |
Alex Deucher | 4535cb9 | 2014-10-01 11:26:50 -0400 | [diff] [blame] | 597 | case RADEON_INFO_READ_REG: |
| 598 | if (copy_from_user(value, value_ptr, sizeof(uint32_t))) { |
| 599 | DRM_ERROR("copy_from_user %s:%u\n", __func__, __LINE__); |
| 600 | return -EFAULT; |
| 601 | } |
| 602 | if (radeon_get_allowed_info_register(rdev, *value, value)) |
| 603 | return -EINVAL; |
| 604 | break; |
Michel Dänzer | 3bc980b | 2015-06-16 17:28:16 +0900 | [diff] [blame] | 605 | case RADEON_INFO_VA_UNMAP_WORKING: |
| 606 | *value = true; |
| 607 | break; |
Marek Olšák | 72b9076 | 2015-04-29 19:40:33 +0200 | [diff] [blame] | 608 | case RADEON_INFO_GPU_RESET_COUNTER: |
| 609 | *value = atomic_read(&rdev->gpu_reset_counter); |
| 610 | break; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 611 | default: |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 612 | DRM_DEBUG_KMS("Invalid request %d\n", info->request); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 613 | return -EINVAL; |
| 614 | } |
Daniel Vetter | 1d6ac18 | 2013-12-11 11:34:44 +0100 | [diff] [blame] | 615 | if (copy_to_user(value_ptr, (char*)value, value_size)) { |
Marek Olšák | 6759a0a | 2012-08-09 16:34:17 +0200 | [diff] [blame] | 616 | DRM_ERROR("copy_to_user %s:%u\n", __func__, __LINE__); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 617 | return -EFAULT; |
| 618 | } |
| 619 | return 0; |
| 620 | } |
| 621 | |
| 622 | |
| 623 | /* |
| 624 | * Outdated mess for old drm with Xorg being in charge (void function now). |
| 625 | */ |
Alex Deucher | f482a14 | 2012-07-17 14:02:34 -0400 | [diff] [blame] | 626 | /** |
Alex Deucher | 8c70e1c | 2015-10-02 16:52:58 -0400 | [diff] [blame] | 627 | * radeon_driver_lastclose_kms - drm callback for last close |
Alex Deucher | f482a14 | 2012-07-17 14:02:34 -0400 | [diff] [blame] | 628 | * |
| 629 | * @dev: drm dev pointer |
| 630 | * |
Lukas Wunner | 8e5de1d | 2015-09-05 11:14:43 +0200 | [diff] [blame] | 631 | * Switch vga_switcheroo state after last close (all asics). |
Alex Deucher | f482a14 | 2012-07-17 14:02:34 -0400 | [diff] [blame] | 632 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 633 | void radeon_driver_lastclose_kms(struct drm_device *dev) |
| 634 | { |
Noralf Trønnes | 3997eea | 2017-12-05 19:25:02 +0100 | [diff] [blame] | 635 | drm_fb_helper_lastclose(dev); |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 636 | vga_switcheroo_process_delayed_switch(); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 637 | } |
| 638 | |
Alex Deucher | f482a14 | 2012-07-17 14:02:34 -0400 | [diff] [blame] | 639 | /** |
| 640 | * radeon_driver_open_kms - drm callback for open |
| 641 | * |
| 642 | * @dev: drm dev pointer |
| 643 | * @file_priv: drm file |
| 644 | * |
| 645 | * On device open, init vm on cayman+ (all asics). |
| 646 | * Returns 0 on success, error on failure. |
| 647 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 648 | int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) |
| 649 | { |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 650 | struct radeon_device *rdev = dev->dev_private; |
Zhou Qingyang | ab50cb9 | 2021-12-01 23:13:10 +0800 | [diff] [blame] | 651 | struct radeon_fpriv *fpriv; |
| 652 | struct radeon_vm *vm; |
Dave Airlie | 10ebc0b | 2012-09-17 14:40:31 +1000 | [diff] [blame] | 653 | int r; |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 654 | |
| 655 | file_priv->driver_priv = NULL; |
| 656 | |
Dave Airlie | 10ebc0b | 2012-09-17 14:40:31 +1000 | [diff] [blame] | 657 | r = pm_runtime_get_sync(dev->dev); |
Aditya Pakki | 9fb1067 | 2020-06-13 21:21:22 -0500 | [diff] [blame] | 658 | if (r < 0) { |
| 659 | pm_runtime_put_autosuspend(dev->dev); |
Dave Airlie | 10ebc0b | 2012-09-17 14:40:31 +1000 | [diff] [blame] | 660 | return r; |
Aditya Pakki | 9fb1067 | 2020-06-13 21:21:22 -0500 | [diff] [blame] | 661 | } |
Dave Airlie | 10ebc0b | 2012-09-17 14:40:31 +1000 | [diff] [blame] | 662 | |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 663 | /* new gpu have virtual address space support */ |
| 664 | if (rdev->family >= CHIP_CAYMAN) { |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 665 | |
| 666 | fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL); |
| 667 | if (unlikely(!fpriv)) { |
Alex Deucher | 32c59dc | 2016-08-31 17:27:03 -0400 | [diff] [blame] | 668 | r = -ENOMEM; |
| 669 | goto out_suspend; |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 670 | } |
| 671 | |
Jérôme Glisse | 24f47ac | 2014-05-07 16:35:24 -0400 | [diff] [blame] | 672 | if (rdev->accel_working) { |
Alex Deucher | 544143f | 2015-01-28 14:36:26 -0500 | [diff] [blame] | 673 | vm = &fpriv->vm; |
| 674 | r = radeon_vm_init(rdev, vm); |
Zhou Qingyang | ab50cb9 | 2021-12-01 23:13:10 +0800 | [diff] [blame] | 675 | if (r) |
| 676 | goto out_fpriv; |
Alex Deucher | 544143f | 2015-01-28 14:36:26 -0500 | [diff] [blame] | 677 | |
Jérôme Glisse | 24f47ac | 2014-05-07 16:35:24 -0400 | [diff] [blame] | 678 | r = radeon_bo_reserve(rdev->ring_tmp_bo.bo, false); |
Zhou Qingyang | ab50cb9 | 2021-12-01 23:13:10 +0800 | [diff] [blame] | 679 | if (r) |
| 680 | goto out_vm_fini; |
Jérôme Glisse | 24f47ac | 2014-05-07 16:35:24 -0400 | [diff] [blame] | 681 | |
| 682 | /* map the ib pool buffer read only into |
| 683 | * virtual address space */ |
Christian König | cc9e67e | 2014-07-18 13:48:10 +0200 | [diff] [blame] | 684 | vm->ib_bo_va = radeon_vm_bo_add(rdev, vm, |
| 685 | rdev->ring_tmp_bo.bo); |
Zhou Qingyang | ab50cb9 | 2021-12-01 23:13:10 +0800 | [diff] [blame] | 686 | if (!vm->ib_bo_va) { |
| 687 | r = -ENOMEM; |
| 688 | goto out_vm_fini; |
| 689 | } |
| 690 | |
Christian König | cc9e67e | 2014-07-18 13:48:10 +0200 | [diff] [blame] | 691 | r = radeon_vm_bo_set_addr(rdev, vm->ib_bo_va, |
| 692 | RADEON_VA_IB_OFFSET, |
Jérôme Glisse | 24f47ac | 2014-05-07 16:35:24 -0400 | [diff] [blame] | 693 | RADEON_VM_PAGE_READABLE | |
| 694 | RADEON_VM_PAGE_SNOOPED); |
Zhou Qingyang | ab50cb9 | 2021-12-01 23:13:10 +0800 | [diff] [blame] | 695 | if (r) |
| 696 | goto out_vm_fini; |
Quentin Casasnovas | 74073c9 | 2014-03-18 17:16:52 +0100 | [diff] [blame] | 697 | } |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 698 | file_priv->driver_priv = fpriv; |
| 699 | } |
Dave Airlie | 10ebc0b | 2012-09-17 14:40:31 +1000 | [diff] [blame] | 700 | |
Zhou Qingyang | ab50cb9 | 2021-12-01 23:13:10 +0800 | [diff] [blame] | 701 | if (!r) |
| 702 | goto out_suspend; |
| 703 | |
| 704 | out_vm_fini: |
| 705 | radeon_vm_fini(rdev, vm); |
| 706 | out_fpriv: |
| 707 | kfree(fpriv); |
Alex Deucher | 32c59dc | 2016-08-31 17:27:03 -0400 | [diff] [blame] | 708 | out_suspend: |
Dave Airlie | 10ebc0b | 2012-09-17 14:40:31 +1000 | [diff] [blame] | 709 | pm_runtime_mark_last_busy(dev->dev); |
| 710 | pm_runtime_put_autosuspend(dev->dev); |
Alex Deucher | 32c59dc | 2016-08-31 17:27:03 -0400 | [diff] [blame] | 711 | return r; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 712 | } |
| 713 | |
Alex Deucher | f482a14 | 2012-07-17 14:02:34 -0400 | [diff] [blame] | 714 | /** |
| 715 | * radeon_driver_postclose_kms - drm callback for post close |
| 716 | * |
| 717 | * @dev: drm dev pointer |
| 718 | * @file_priv: drm file |
| 719 | * |
Daniel Vetter | 7891024 | 2017-03-08 15:12:48 +0100 | [diff] [blame] | 720 | * On device close, tear down hyperz and cmask filps on r1xx-r5xx |
| 721 | * (all asics). And tear down vm on cayman+ (all asics). |
Alex Deucher | f482a14 | 2012-07-17 14:02:34 -0400 | [diff] [blame] | 722 | */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 723 | void radeon_driver_postclose_kms(struct drm_device *dev, |
| 724 | struct drm_file *file_priv) |
| 725 | { |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 726 | struct radeon_device *rdev = dev->dev_private; |
| 727 | |
Daniel Vetter | 7891024 | 2017-03-08 15:12:48 +0100 | [diff] [blame] | 728 | pm_runtime_get_sync(dev->dev); |
| 729 | |
| 730 | mutex_lock(&rdev->gem.mutex); |
| 731 | if (rdev->hyperz_filp == file_priv) |
| 732 | rdev->hyperz_filp = NULL; |
| 733 | if (rdev->cmask_filp == file_priv) |
| 734 | rdev->cmask_filp = NULL; |
| 735 | mutex_unlock(&rdev->gem.mutex); |
| 736 | |
| 737 | radeon_uvd_free_handles(rdev, file_priv); |
| 738 | radeon_vce_free_handles(rdev, file_priv); |
| 739 | |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 740 | /* new gpu have virtual address space support */ |
| 741 | if (rdev->family >= CHIP_CAYMAN && file_priv->driver_priv) { |
| 742 | struct radeon_fpriv *fpriv = file_priv->driver_priv; |
Christian König | cc9e67e | 2014-07-18 13:48:10 +0200 | [diff] [blame] | 743 | struct radeon_vm *vm = &fpriv->vm; |
Christian König | d72d43c | 2012-10-09 13:31:18 +0200 | [diff] [blame] | 744 | int r; |
| 745 | |
Jérôme Glisse | 24f47ac | 2014-05-07 16:35:24 -0400 | [diff] [blame] | 746 | if (rdev->accel_working) { |
| 747 | r = radeon_bo_reserve(rdev->ring_tmp_bo.bo, false); |
| 748 | if (!r) { |
Christian König | cc9e67e | 2014-07-18 13:48:10 +0200 | [diff] [blame] | 749 | if (vm->ib_bo_va) |
| 750 | radeon_vm_bo_rmv(rdev, vm->ib_bo_va); |
Jérôme Glisse | 24f47ac | 2014-05-07 16:35:24 -0400 | [diff] [blame] | 751 | radeon_bo_unreserve(rdev->ring_tmp_bo.bo); |
| 752 | } |
Alex Deucher | 544143f | 2015-01-28 14:36:26 -0500 | [diff] [blame] | 753 | radeon_vm_fini(rdev, vm); |
Christian König | d72d43c | 2012-10-09 13:31:18 +0200 | [diff] [blame] | 754 | } |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 755 | |
Jerome Glisse | 721604a | 2012-01-05 22:11:05 -0500 | [diff] [blame] | 756 | kfree(fpriv); |
| 757 | file_priv->driver_priv = NULL; |
| 758 | } |
Alex Deucher | 9b96b63 | 2016-08-31 17:23:31 -0400 | [diff] [blame] | 759 | pm_runtime_mark_last_busy(dev->dev); |
| 760 | pm_runtime_put_autosuspend(dev->dev); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 761 | } |
| 762 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 763 | /* |
| 764 | * VBlank related functions. |
| 765 | */ |
Alex Deucher | f482a14 | 2012-07-17 14:02:34 -0400 | [diff] [blame] | 766 | /** |
| 767 | * radeon_get_vblank_counter_kms - get frame count |
| 768 | * |
Thomas Zimmermann | d7757ba | 2020-01-23 14:59:32 +0100 | [diff] [blame] | 769 | * @crtc: crtc to get the frame count from |
Alex Deucher | f482a14 | 2012-07-17 14:02:34 -0400 | [diff] [blame] | 770 | * |
| 771 | * Gets the frame count on the requested crtc (all asics). |
| 772 | * Returns frame count on success, -EINVAL on failure. |
| 773 | */ |
Thomas Zimmermann | d7757ba | 2020-01-23 14:59:32 +0100 | [diff] [blame] | 774 | u32 radeon_get_vblank_counter_kms(struct drm_crtc *crtc) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 775 | { |
Thomas Zimmermann | d7757ba | 2020-01-23 14:59:32 +0100 | [diff] [blame] | 776 | struct drm_device *dev = crtc->dev; |
| 777 | unsigned int pipe = crtc->index; |
Mario Kleiner | c55d21e | 2015-11-25 20:14:31 +0100 | [diff] [blame] | 778 | int vpos, hpos, stat; |
| 779 | u32 count; |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 780 | struct radeon_device *rdev = dev->dev_private; |
| 781 | |
Thierry Reding | 85a21ea | 2016-01-04 18:19:12 +0100 | [diff] [blame] | 782 | if (pipe >= rdev->num_crtc) { |
Thierry Reding | 4e926d2 | 2015-12-16 15:31:47 +0100 | [diff] [blame] | 783 | DRM_ERROR("Invalid crtc %u\n", pipe); |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 784 | return -EINVAL; |
| 785 | } |
| 786 | |
Mario Kleiner | c55d21e | 2015-11-25 20:14:31 +0100 | [diff] [blame] | 787 | /* The hw increments its frame counter at start of vsync, not at start |
| 788 | * of vblank, as is required by DRM core vblank counter handling. |
| 789 | * Cook the hw count here to make it appear to the caller as if it |
| 790 | * incremented at start of vblank. We measure distance to start of |
| 791 | * vblank in vpos. vpos therefore will be >= 0 between start of vblank |
| 792 | * and start of vsync, so vpos >= 0 means to bump the hw frame counter |
| 793 | * result by 1 to give the proper appearance to caller. |
| 794 | */ |
Thierry Reding | 4e926d2 | 2015-12-16 15:31:47 +0100 | [diff] [blame] | 795 | if (rdev->mode_info.crtcs[pipe]) { |
Mario Kleiner | c55d21e | 2015-11-25 20:14:31 +0100 | [diff] [blame] | 796 | /* Repeat readout if needed to provide stable result if |
| 797 | * we cross start of vsync during the queries. |
| 798 | */ |
| 799 | do { |
Thierry Reding | 4e926d2 | 2015-12-16 15:31:47 +0100 | [diff] [blame] | 800 | count = radeon_get_vblank_counter(rdev, pipe); |
Mario Kleiner | c55d21e | 2015-11-25 20:14:31 +0100 | [diff] [blame] | 801 | /* Ask radeon_get_crtc_scanoutpos to return vpos as |
| 802 | * distance to start of vblank, instead of regular |
| 803 | * vertical scanout pos. |
| 804 | */ |
| 805 | stat = radeon_get_crtc_scanoutpos( |
Thierry Reding | 4e926d2 | 2015-12-16 15:31:47 +0100 | [diff] [blame] | 806 | dev, pipe, GET_DISTANCE_TO_VBLANKSTART, |
Mario Kleiner | c55d21e | 2015-11-25 20:14:31 +0100 | [diff] [blame] | 807 | &vpos, &hpos, NULL, NULL, |
Thierry Reding | 4e926d2 | 2015-12-16 15:31:47 +0100 | [diff] [blame] | 808 | &rdev->mode_info.crtcs[pipe]->base.hwmode); |
| 809 | } while (count != radeon_get_vblank_counter(rdev, pipe)); |
Mario Kleiner | c55d21e | 2015-11-25 20:14:31 +0100 | [diff] [blame] | 810 | |
| 811 | if (((stat & (DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE)) != |
| 812 | (DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE))) { |
| 813 | DRM_DEBUG_VBL("Query failed! stat %d\n", stat); |
| 814 | } |
| 815 | else { |
Thierry Reding | 4e926d2 | 2015-12-16 15:31:47 +0100 | [diff] [blame] | 816 | DRM_DEBUG_VBL("crtc %u: dist from vblank start %d\n", |
| 817 | pipe, vpos); |
Mario Kleiner | c55d21e | 2015-11-25 20:14:31 +0100 | [diff] [blame] | 818 | |
| 819 | /* Bump counter if we are at >= leading edge of vblank, |
| 820 | * but before vsync where vpos would turn negative and |
| 821 | * the hw counter really increments. |
| 822 | */ |
| 823 | if (vpos >= 0) |
| 824 | count++; |
| 825 | } |
| 826 | } |
| 827 | else { |
| 828 | /* Fallback to use value as is. */ |
Thierry Reding | 4e926d2 | 2015-12-16 15:31:47 +0100 | [diff] [blame] | 829 | count = radeon_get_vblank_counter(rdev, pipe); |
Mario Kleiner | c55d21e | 2015-11-25 20:14:31 +0100 | [diff] [blame] | 830 | DRM_DEBUG_VBL("NULL mode info! Returned count may be wrong.\n"); |
| 831 | } |
| 832 | |
| 833 | return count; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 834 | } |
| 835 | |
Alex Deucher | f482a14 | 2012-07-17 14:02:34 -0400 | [diff] [blame] | 836 | /** |
| 837 | * radeon_enable_vblank_kms - enable vblank interrupt |
| 838 | * |
Alex Deucher | f482a14 | 2012-07-17 14:02:34 -0400 | [diff] [blame] | 839 | * @crtc: crtc to enable vblank interrupt for |
| 840 | * |
| 841 | * Enable the interrupt on the requested crtc (all asics). |
| 842 | * Returns 0 on success, -EINVAL on failure. |
| 843 | */ |
Thomas Zimmermann | d7757ba | 2020-01-23 14:59:32 +0100 | [diff] [blame] | 844 | int radeon_enable_vblank_kms(struct drm_crtc *crtc) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 845 | { |
Thomas Zimmermann | d7757ba | 2020-01-23 14:59:32 +0100 | [diff] [blame] | 846 | struct drm_device *dev = crtc->dev; |
| 847 | unsigned int pipe = crtc->index; |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 848 | struct radeon_device *rdev = dev->dev_private; |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 849 | unsigned long irqflags; |
| 850 | int r; |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 851 | |
ChenTao | a2eb03a | 2020-05-05 12:57:37 +0800 | [diff] [blame] | 852 | if (pipe >= rdev->num_crtc) { |
Thomas Zimmermann | d7757ba | 2020-01-23 14:59:32 +0100 | [diff] [blame] | 853 | DRM_ERROR("Invalid crtc %d\n", pipe); |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 854 | return -EINVAL; |
| 855 | } |
| 856 | |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 857 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
Thomas Zimmermann | d7757ba | 2020-01-23 14:59:32 +0100 | [diff] [blame] | 858 | rdev->irq.crtc_vblank_int[pipe] = true; |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 859 | r = radeon_irq_set(rdev); |
| 860 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
| 861 | return r; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 862 | } |
| 863 | |
Alex Deucher | f482a14 | 2012-07-17 14:02:34 -0400 | [diff] [blame] | 864 | /** |
| 865 | * radeon_disable_vblank_kms - disable vblank interrupt |
| 866 | * |
Alex Deucher | f482a14 | 2012-07-17 14:02:34 -0400 | [diff] [blame] | 867 | * @crtc: crtc to disable vblank interrupt for |
| 868 | * |
| 869 | * Disable the interrupt on the requested crtc (all asics). |
| 870 | */ |
Thomas Zimmermann | d7757ba | 2020-01-23 14:59:32 +0100 | [diff] [blame] | 871 | void radeon_disable_vblank_kms(struct drm_crtc *crtc) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 872 | { |
Thomas Zimmermann | d7757ba | 2020-01-23 14:59:32 +0100 | [diff] [blame] | 873 | struct drm_device *dev = crtc->dev; |
| 874 | unsigned int pipe = crtc->index; |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 875 | struct radeon_device *rdev = dev->dev_private; |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 876 | unsigned long irqflags; |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 877 | |
ChenTao | a2eb03a | 2020-05-05 12:57:37 +0800 | [diff] [blame] | 878 | if (pipe >= rdev->num_crtc) { |
Thomas Zimmermann | d7757ba | 2020-01-23 14:59:32 +0100 | [diff] [blame] | 879 | DRM_ERROR("Invalid crtc %d\n", pipe); |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 880 | return; |
| 881 | } |
| 882 | |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 883 | spin_lock_irqsave(&rdev->irq.lock, irqflags); |
Thomas Zimmermann | d7757ba | 2020-01-23 14:59:32 +0100 | [diff] [blame] | 884 | rdev->irq.crtc_vblank_int[pipe] = false; |
Michel Dänzer | 7ed220d | 2009-08-13 11:10:51 +0200 | [diff] [blame] | 885 | radeon_irq_set(rdev); |
Christian Koenig | fb98257 | 2012-05-17 01:33:30 +0200 | [diff] [blame] | 886 | spin_unlock_irqrestore(&rdev->irq.lock, irqflags); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 887 | } |