1*b843c749SSergey Zigachev /* 2*b843c749SSergey Zigachev * Copyright 2008 Advanced Micro Devices, Inc. 3*b843c749SSergey Zigachev * Copyright 2008 Red Hat Inc. 4*b843c749SSergey Zigachev * Copyright 2009 Jerome Glisse. 5*b843c749SSergey Zigachev * 6*b843c749SSergey Zigachev * Permission is hereby granted, free of charge, to any person obtaining a 7*b843c749SSergey Zigachev * copy of this software and associated documentation files (the "Software"), 8*b843c749SSergey Zigachev * to deal in the Software without restriction, including without limitation 9*b843c749SSergey Zigachev * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10*b843c749SSergey Zigachev * and/or sell copies of the Software, and to permit persons to whom the 11*b843c749SSergey Zigachev * Software is furnished to do so, subject to the following conditions: 12*b843c749SSergey Zigachev * 13*b843c749SSergey Zigachev * The above copyright notice and this permission notice shall be included in 14*b843c749SSergey Zigachev * all copies or substantial portions of the Software. 15*b843c749SSergey Zigachev * 16*b843c749SSergey Zigachev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17*b843c749SSergey Zigachev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18*b843c749SSergey Zigachev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19*b843c749SSergey Zigachev * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20*b843c749SSergey Zigachev * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21*b843c749SSergey Zigachev * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22*b843c749SSergey Zigachev * OTHER DEALINGS IN THE SOFTWARE. 23*b843c749SSergey Zigachev * 24*b843c749SSergey Zigachev * Authors: Dave Airlie 25*b843c749SSergey Zigachev * Alex Deucher 26*b843c749SSergey Zigachev * Jerome Glisse 27*b843c749SSergey Zigachev */ 28*b843c749SSergey Zigachev #include <drm/drmP.h> 29*b843c749SSergey Zigachev #include "amdgpu.h" 30*b843c749SSergey Zigachev #include <drm/amdgpu_drm.h> 31*b843c749SSergey Zigachev #include "amdgpu_sched.h" 32*b843c749SSergey Zigachev #include "amdgpu_uvd.h" 33*b843c749SSergey Zigachev #include "amdgpu_vce.h" 34*b843c749SSergey Zigachev #include "atom.h" 35*b843c749SSergey Zigachev 36*b843c749SSergey Zigachev #include <linux/vga_switcheroo.h> 37*b843c749SSergey Zigachev #include <linux/slab.h> 38*b843c749SSergey Zigachev #include <linux/pm_runtime.h> 39*b843c749SSergey Zigachev #include "amdgpu_amdkfd.h" 40*b843c749SSergey Zigachev 41*b843c749SSergey Zigachev /** 42*b843c749SSergey Zigachev * amdgpu_driver_unload_kms - Main unload function for KMS. 43*b843c749SSergey Zigachev * 44*b843c749SSergey Zigachev * @dev: drm dev pointer 45*b843c749SSergey Zigachev * 46*b843c749SSergey Zigachev * This is the main unload function for KMS (all asics). 47*b843c749SSergey Zigachev * Returns 0 on success. 48*b843c749SSergey Zigachev */ 49*b843c749SSergey Zigachev void amdgpu_driver_unload_kms(struct drm_device *dev) 50*b843c749SSergey Zigachev { 51*b843c749SSergey Zigachev struct amdgpu_device *adev = dev->dev_private; 52*b843c749SSergey Zigachev 53*b843c749SSergey Zigachev if (adev == NULL) 54*b843c749SSergey Zigachev return; 55*b843c749SSergey Zigachev 56*b843c749SSergey Zigachev if (adev->rmmio == NULL) 57*b843c749SSergey Zigachev goto done_free; 58*b843c749SSergey Zigachev 59*b843c749SSergey Zigachev if (amdgpu_sriov_vf(adev)) 60*b843c749SSergey Zigachev amdgpu_virt_request_full_gpu(adev, false); 61*b843c749SSergey Zigachev 62*b843c749SSergey Zigachev if (amdgpu_device_is_px(dev)) { 63*b843c749SSergey Zigachev pm_runtime_get_sync(dev->dev); 64*b843c749SSergey Zigachev pm_runtime_forbid(dev->dev); 65*b843c749SSergey Zigachev } 66*b843c749SSergey Zigachev 67*b843c749SSergey Zigachev amdgpu_acpi_fini(adev); 68*b843c749SSergey Zigachev 69*b843c749SSergey Zigachev amdgpu_device_fini(adev); 70*b843c749SSergey Zigachev 71*b843c749SSergey Zigachev done_free: 72*b843c749SSergey Zigachev kfree(adev); 73*b843c749SSergey Zigachev dev->dev_private = NULL; 74*b843c749SSergey Zigachev } 75*b843c749SSergey Zigachev 76*b843c749SSergey Zigachev /** 77*b843c749SSergey Zigachev * amdgpu_driver_load_kms - Main load function for KMS. 78*b843c749SSergey Zigachev * 79*b843c749SSergey Zigachev * @dev: drm dev pointer 80*b843c749SSergey Zigachev * @flags: device flags 81*b843c749SSergey Zigachev * 82*b843c749SSergey Zigachev * This is the main load function for KMS (all asics). 83*b843c749SSergey Zigachev * Returns 0 on success, error on failure. 84*b843c749SSergey Zigachev */ 85*b843c749SSergey Zigachev int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags) 86*b843c749SSergey Zigachev { 87*b843c749SSergey Zigachev struct amdgpu_device *adev; 88*b843c749SSergey Zigachev int r, acpi_status; 89*b843c749SSergey Zigachev 90*b843c749SSergey Zigachev adev = kzalloc(sizeof(struct amdgpu_device), GFP_KERNEL); 91*b843c749SSergey Zigachev if (adev == NULL) { 92*b843c749SSergey Zigachev return -ENOMEM; 93*b843c749SSergey Zigachev } 94*b843c749SSergey Zigachev dev->dev_private = (void *)adev; 95*b843c749SSergey Zigachev 96*b843c749SSergey Zigachev if ((amdgpu_runtime_pm != 0) && 97*b843c749SSergey Zigachev amdgpu_has_atpx() && 98*b843c749SSergey Zigachev (amdgpu_is_atpx_hybrid() || 99*b843c749SSergey Zigachev amdgpu_has_atpx_dgpu_power_cntl()) && 100*b843c749SSergey Zigachev ((flags & AMD_IS_APU) == 0) && 101*b843c749SSergey Zigachev !pci_is_thunderbolt_attached(dev->pdev)) 102*b843c749SSergey Zigachev flags |= AMD_IS_PX; 103*b843c749SSergey Zigachev 104*b843c749SSergey Zigachev /* amdgpu_device_init should report only fatal error 105*b843c749SSergey Zigachev * like memory allocation failure or iomapping failure, 106*b843c749SSergey Zigachev * or memory manager initialization failure, it must 107*b843c749SSergey Zigachev * properly initialize the GPU MC controller and permit 108*b843c749SSergey Zigachev * VRAM allocation 109*b843c749SSergey Zigachev */ 110*b843c749SSergey Zigachev r = amdgpu_device_init(adev, dev, dev->pdev, flags); 111*b843c749SSergey Zigachev if (r) { 112*b843c749SSergey Zigachev dev_err(&dev->pdev->dev, "Fatal error during GPU init\n"); 113*b843c749SSergey Zigachev goto out; 114*b843c749SSergey Zigachev } 115*b843c749SSergey Zigachev 116*b843c749SSergey Zigachev /* Call ACPI methods: require modeset init 117*b843c749SSergey Zigachev * but failure is not fatal 118*b843c749SSergey Zigachev */ 119*b843c749SSergey Zigachev if (!r) { 120*b843c749SSergey Zigachev acpi_status = amdgpu_acpi_init(adev); 121*b843c749SSergey Zigachev if (acpi_status) 122*b843c749SSergey Zigachev dev_dbg(&dev->pdev->dev, 123*b843c749SSergey Zigachev "Error during ACPI methods call\n"); 124*b843c749SSergey Zigachev } 125*b843c749SSergey Zigachev 126*b843c749SSergey Zigachev if (amdgpu_device_is_px(dev)) { 127*b843c749SSergey Zigachev dev_pm_set_driver_flags(dev->dev, DPM_FLAG_NEVER_SKIP); 128*b843c749SSergey Zigachev pm_runtime_use_autosuspend(dev->dev); 129*b843c749SSergey Zigachev pm_runtime_set_autosuspend_delay(dev->dev, 5000); 130*b843c749SSergey Zigachev pm_runtime_set_active(dev->dev); 131*b843c749SSergey Zigachev pm_runtime_allow(dev->dev); 132*b843c749SSergey Zigachev pm_runtime_mark_last_busy(dev->dev); 133*b843c749SSergey Zigachev pm_runtime_put_autosuspend(dev->dev); 134*b843c749SSergey Zigachev } 135*b843c749SSergey Zigachev 136*b843c749SSergey Zigachev out: 137*b843c749SSergey Zigachev if (r) { 138*b843c749SSergey Zigachev /* balance pm_runtime_get_sync in amdgpu_driver_unload_kms */ 139*b843c749SSergey Zigachev if (adev->rmmio && amdgpu_device_is_px(dev)) 140*b843c749SSergey Zigachev pm_runtime_put_noidle(dev->dev); 141*b843c749SSergey Zigachev amdgpu_driver_unload_kms(dev); 142*b843c749SSergey Zigachev } 143*b843c749SSergey Zigachev 144*b843c749SSergey Zigachev return r; 145*b843c749SSergey Zigachev } 146*b843c749SSergey Zigachev 147*b843c749SSergey Zigachev static int amdgpu_firmware_info(struct drm_amdgpu_info_firmware *fw_info, 148*b843c749SSergey Zigachev struct drm_amdgpu_query_fw *query_fw, 149*b843c749SSergey Zigachev struct amdgpu_device *adev) 150*b843c749SSergey Zigachev { 151*b843c749SSergey Zigachev switch (query_fw->fw_type) { 152*b843c749SSergey Zigachev case AMDGPU_INFO_FW_VCE: 153*b843c749SSergey Zigachev fw_info->ver = adev->vce.fw_version; 154*b843c749SSergey Zigachev fw_info->feature = adev->vce.fb_version; 155*b843c749SSergey Zigachev break; 156*b843c749SSergey Zigachev case AMDGPU_INFO_FW_UVD: 157*b843c749SSergey Zigachev fw_info->ver = adev->uvd.fw_version; 158*b843c749SSergey Zigachev fw_info->feature = 0; 159*b843c749SSergey Zigachev break; 160*b843c749SSergey Zigachev case AMDGPU_INFO_FW_VCN: 161*b843c749SSergey Zigachev fw_info->ver = adev->vcn.fw_version; 162*b843c749SSergey Zigachev fw_info->feature = 0; 163*b843c749SSergey Zigachev break; 164*b843c749SSergey Zigachev case AMDGPU_INFO_FW_GMC: 165*b843c749SSergey Zigachev fw_info->ver = adev->gmc.fw_version; 166*b843c749SSergey Zigachev fw_info->feature = 0; 167*b843c749SSergey Zigachev break; 168*b843c749SSergey Zigachev case AMDGPU_INFO_FW_GFX_ME: 169*b843c749SSergey Zigachev fw_info->ver = adev->gfx.me_fw_version; 170*b843c749SSergey Zigachev fw_info->feature = adev->gfx.me_feature_version; 171*b843c749SSergey Zigachev break; 172*b843c749SSergey Zigachev case AMDGPU_INFO_FW_GFX_PFP: 173*b843c749SSergey Zigachev fw_info->ver = adev->gfx.pfp_fw_version; 174*b843c749SSergey Zigachev fw_info->feature = adev->gfx.pfp_feature_version; 175*b843c749SSergey Zigachev break; 176*b843c749SSergey Zigachev case AMDGPU_INFO_FW_GFX_CE: 177*b843c749SSergey Zigachev fw_info->ver = adev->gfx.ce_fw_version; 178*b843c749SSergey Zigachev fw_info->feature = adev->gfx.ce_feature_version; 179*b843c749SSergey Zigachev break; 180*b843c749SSergey Zigachev case AMDGPU_INFO_FW_GFX_RLC: 181*b843c749SSergey Zigachev fw_info->ver = adev->gfx.rlc_fw_version; 182*b843c749SSergey Zigachev fw_info->feature = adev->gfx.rlc_feature_version; 183*b843c749SSergey Zigachev break; 184*b843c749SSergey Zigachev case AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_CNTL: 185*b843c749SSergey Zigachev fw_info->ver = adev->gfx.rlc_srlc_fw_version; 186*b843c749SSergey Zigachev fw_info->feature = adev->gfx.rlc_srlc_feature_version; 187*b843c749SSergey Zigachev break; 188*b843c749SSergey Zigachev case AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_GPM_MEM: 189*b843c749SSergey Zigachev fw_info->ver = adev->gfx.rlc_srlg_fw_version; 190*b843c749SSergey Zigachev fw_info->feature = adev->gfx.rlc_srlg_feature_version; 191*b843c749SSergey Zigachev break; 192*b843c749SSergey Zigachev case AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_SRM_MEM: 193*b843c749SSergey Zigachev fw_info->ver = adev->gfx.rlc_srls_fw_version; 194*b843c749SSergey Zigachev fw_info->feature = adev->gfx.rlc_srls_feature_version; 195*b843c749SSergey Zigachev break; 196*b843c749SSergey Zigachev case AMDGPU_INFO_FW_GFX_MEC: 197*b843c749SSergey Zigachev if (query_fw->index == 0) { 198*b843c749SSergey Zigachev fw_info->ver = adev->gfx.mec_fw_version; 199*b843c749SSergey Zigachev fw_info->feature = adev->gfx.mec_feature_version; 200*b843c749SSergey Zigachev } else if (query_fw->index == 1) { 201*b843c749SSergey Zigachev fw_info->ver = adev->gfx.mec2_fw_version; 202*b843c749SSergey Zigachev fw_info->feature = adev->gfx.mec2_feature_version; 203*b843c749SSergey Zigachev } else 204*b843c749SSergey Zigachev return -EINVAL; 205*b843c749SSergey Zigachev break; 206*b843c749SSergey Zigachev case AMDGPU_INFO_FW_SMC: 207*b843c749SSergey Zigachev fw_info->ver = adev->pm.fw_version; 208*b843c749SSergey Zigachev fw_info->feature = 0; 209*b843c749SSergey Zigachev break; 210*b843c749SSergey Zigachev case AMDGPU_INFO_FW_SDMA: 211*b843c749SSergey Zigachev if (query_fw->index >= adev->sdma.num_instances) 212*b843c749SSergey Zigachev return -EINVAL; 213*b843c749SSergey Zigachev fw_info->ver = adev->sdma.instance[query_fw->index].fw_version; 214*b843c749SSergey Zigachev fw_info->feature = adev->sdma.instance[query_fw->index].feature_version; 215*b843c749SSergey Zigachev break; 216*b843c749SSergey Zigachev case AMDGPU_INFO_FW_SOS: 217*b843c749SSergey Zigachev fw_info->ver = adev->psp.sos_fw_version; 218*b843c749SSergey Zigachev fw_info->feature = adev->psp.sos_feature_version; 219*b843c749SSergey Zigachev break; 220*b843c749SSergey Zigachev case AMDGPU_INFO_FW_ASD: 221*b843c749SSergey Zigachev fw_info->ver = adev->psp.asd_fw_version; 222*b843c749SSergey Zigachev fw_info->feature = adev->psp.asd_feature_version; 223*b843c749SSergey Zigachev break; 224*b843c749SSergey Zigachev default: 225*b843c749SSergey Zigachev return -EINVAL; 226*b843c749SSergey Zigachev } 227*b843c749SSergey Zigachev return 0; 228*b843c749SSergey Zigachev } 229*b843c749SSergey Zigachev 230*b843c749SSergey Zigachev /* 231*b843c749SSergey Zigachev * Userspace get information ioctl 232*b843c749SSergey Zigachev */ 233*b843c749SSergey Zigachev /** 234*b843c749SSergey Zigachev * amdgpu_info_ioctl - answer a device specific request. 235*b843c749SSergey Zigachev * 236*b843c749SSergey Zigachev * @adev: amdgpu device pointer 237*b843c749SSergey Zigachev * @data: request object 238*b843c749SSergey Zigachev * @filp: drm filp 239*b843c749SSergey Zigachev * 240*b843c749SSergey Zigachev * This function is used to pass device specific parameters to the userspace 241*b843c749SSergey Zigachev * drivers. Examples include: pci device id, pipeline parms, tiling params, 242*b843c749SSergey Zigachev * etc. (all asics). 243*b843c749SSergey Zigachev * Returns 0 on success, -EINVAL on failure. 244*b843c749SSergey Zigachev */ 245*b843c749SSergey Zigachev static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) 246*b843c749SSergey Zigachev { 247*b843c749SSergey Zigachev struct amdgpu_device *adev = dev->dev_private; 248*b843c749SSergey Zigachev struct drm_amdgpu_info *info = data; 249*b843c749SSergey Zigachev struct amdgpu_mode_info *minfo = &adev->mode_info; 250*b843c749SSergey Zigachev void __user *out = (void __user *)(uintptr_t)info->return_pointer; 251*b843c749SSergey Zigachev uint32_t size = info->return_size; 252*b843c749SSergey Zigachev struct drm_crtc *crtc; 253*b843c749SSergey Zigachev uint32_t ui32 = 0; 254*b843c749SSergey Zigachev uint64_t ui64 = 0; 255*b843c749SSergey Zigachev int i, j, found; 256*b843c749SSergey Zigachev int ui32_size = sizeof(ui32); 257*b843c749SSergey Zigachev 258*b843c749SSergey Zigachev if (!info->return_size || !info->return_pointer) 259*b843c749SSergey Zigachev return -EINVAL; 260*b843c749SSergey Zigachev 261*b843c749SSergey Zigachev switch (info->query) { 262*b843c749SSergey Zigachev case AMDGPU_INFO_ACCEL_WORKING: 263*b843c749SSergey Zigachev ui32 = adev->accel_working; 264*b843c749SSergey Zigachev return copy_to_user(out, &ui32, min(size, 4u)) ? -EFAULT : 0; 265*b843c749SSergey Zigachev case AMDGPU_INFO_CRTC_FROM_ID: 266*b843c749SSergey Zigachev for (i = 0, found = 0; i < adev->mode_info.num_crtc; i++) { 267*b843c749SSergey Zigachev crtc = (struct drm_crtc *)minfo->crtcs[i]; 268*b843c749SSergey Zigachev if (crtc && crtc->base.id == info->mode_crtc.id) { 269*b843c749SSergey Zigachev struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); 270*b843c749SSergey Zigachev ui32 = amdgpu_crtc->crtc_id; 271*b843c749SSergey Zigachev found = 1; 272*b843c749SSergey Zigachev break; 273*b843c749SSergey Zigachev } 274*b843c749SSergey Zigachev } 275*b843c749SSergey Zigachev if (!found) { 276*b843c749SSergey Zigachev DRM_DEBUG_KMS("unknown crtc id %d\n", info->mode_crtc.id); 277*b843c749SSergey Zigachev return -EINVAL; 278*b843c749SSergey Zigachev } 279*b843c749SSergey Zigachev return copy_to_user(out, &ui32, min(size, 4u)) ? -EFAULT : 0; 280*b843c749SSergey Zigachev case AMDGPU_INFO_HW_IP_INFO: { 281*b843c749SSergey Zigachev struct drm_amdgpu_info_hw_ip ip = {}; 282*b843c749SSergey Zigachev enum amd_ip_block_type type; 283*b843c749SSergey Zigachev uint32_t ring_mask = 0; 284*b843c749SSergey Zigachev uint32_t ib_start_alignment = 0; 285*b843c749SSergey Zigachev uint32_t ib_size_alignment = 0; 286*b843c749SSergey Zigachev 287*b843c749SSergey Zigachev if (info->query_hw_ip.ip_instance >= AMDGPU_HW_IP_INSTANCE_MAX_COUNT) 288*b843c749SSergey Zigachev return -EINVAL; 289*b843c749SSergey Zigachev 290*b843c749SSergey Zigachev switch (info->query_hw_ip.type) { 291*b843c749SSergey Zigachev case AMDGPU_HW_IP_GFX: 292*b843c749SSergey Zigachev type = AMD_IP_BLOCK_TYPE_GFX; 293*b843c749SSergey Zigachev for (i = 0; i < adev->gfx.num_gfx_rings; i++) 294*b843c749SSergey Zigachev ring_mask |= adev->gfx.gfx_ring[i].ready << i; 295*b843c749SSergey Zigachev ib_start_alignment = 32; 296*b843c749SSergey Zigachev ib_size_alignment = 32; 297*b843c749SSergey Zigachev break; 298*b843c749SSergey Zigachev case AMDGPU_HW_IP_COMPUTE: 299*b843c749SSergey Zigachev type = AMD_IP_BLOCK_TYPE_GFX; 300*b843c749SSergey Zigachev for (i = 0; i < adev->gfx.num_compute_rings; i++) 301*b843c749SSergey Zigachev ring_mask |= adev->gfx.compute_ring[i].ready << i; 302*b843c749SSergey Zigachev ib_start_alignment = 32; 303*b843c749SSergey Zigachev ib_size_alignment = 32; 304*b843c749SSergey Zigachev break; 305*b843c749SSergey Zigachev case AMDGPU_HW_IP_DMA: 306*b843c749SSergey Zigachev type = AMD_IP_BLOCK_TYPE_SDMA; 307*b843c749SSergey Zigachev for (i = 0; i < adev->sdma.num_instances; i++) 308*b843c749SSergey Zigachev ring_mask |= adev->sdma.instance[i].ring.ready << i; 309*b843c749SSergey Zigachev ib_start_alignment = 256; 310*b843c749SSergey Zigachev ib_size_alignment = 4; 311*b843c749SSergey Zigachev break; 312*b843c749SSergey Zigachev case AMDGPU_HW_IP_UVD: 313*b843c749SSergey Zigachev type = AMD_IP_BLOCK_TYPE_UVD; 314*b843c749SSergey Zigachev for (i = 0; i < adev->uvd.num_uvd_inst; i++) { 315*b843c749SSergey Zigachev if (adev->uvd.harvest_config & (1 << i)) 316*b843c749SSergey Zigachev continue; 317*b843c749SSergey Zigachev ring_mask |= adev->uvd.inst[i].ring.ready; 318*b843c749SSergey Zigachev } 319*b843c749SSergey Zigachev ib_start_alignment = 64; 320*b843c749SSergey Zigachev ib_size_alignment = 64; 321*b843c749SSergey Zigachev break; 322*b843c749SSergey Zigachev case AMDGPU_HW_IP_VCE: 323*b843c749SSergey Zigachev type = AMD_IP_BLOCK_TYPE_VCE; 324*b843c749SSergey Zigachev for (i = 0; i < adev->vce.num_rings; i++) 325*b843c749SSergey Zigachev ring_mask |= adev->vce.ring[i].ready << i; 326*b843c749SSergey Zigachev ib_start_alignment = 4; 327*b843c749SSergey Zigachev ib_size_alignment = 1; 328*b843c749SSergey Zigachev break; 329*b843c749SSergey Zigachev case AMDGPU_HW_IP_UVD_ENC: 330*b843c749SSergey Zigachev type = AMD_IP_BLOCK_TYPE_UVD; 331*b843c749SSergey Zigachev for (i = 0; i < adev->uvd.num_uvd_inst; i++) { 332*b843c749SSergey Zigachev if (adev->uvd.harvest_config & (1 << i)) 333*b843c749SSergey Zigachev continue; 334*b843c749SSergey Zigachev for (j = 0; j < adev->uvd.num_enc_rings; j++) 335*b843c749SSergey Zigachev ring_mask |= adev->uvd.inst[i].ring_enc[j].ready << j; 336*b843c749SSergey Zigachev } 337*b843c749SSergey Zigachev ib_start_alignment = 64; 338*b843c749SSergey Zigachev ib_size_alignment = 64; 339*b843c749SSergey Zigachev break; 340*b843c749SSergey Zigachev case AMDGPU_HW_IP_VCN_DEC: 341*b843c749SSergey Zigachev type = AMD_IP_BLOCK_TYPE_VCN; 342*b843c749SSergey Zigachev ring_mask = adev->vcn.ring_dec.ready; 343*b843c749SSergey Zigachev ib_start_alignment = 16; 344*b843c749SSergey Zigachev ib_size_alignment = 16; 345*b843c749SSergey Zigachev break; 346*b843c749SSergey Zigachev case AMDGPU_HW_IP_VCN_ENC: 347*b843c749SSergey Zigachev type = AMD_IP_BLOCK_TYPE_VCN; 348*b843c749SSergey Zigachev for (i = 0; i < adev->vcn.num_enc_rings; i++) 349*b843c749SSergey Zigachev ring_mask |= adev->vcn.ring_enc[i].ready << i; 350*b843c749SSergey Zigachev ib_start_alignment = 64; 351*b843c749SSergey Zigachev ib_size_alignment = 1; 352*b843c749SSergey Zigachev break; 353*b843c749SSergey Zigachev case AMDGPU_HW_IP_VCN_JPEG: 354*b843c749SSergey Zigachev type = AMD_IP_BLOCK_TYPE_VCN; 355*b843c749SSergey Zigachev ring_mask = adev->vcn.ring_jpeg.ready; 356*b843c749SSergey Zigachev ib_start_alignment = 16; 357*b843c749SSergey Zigachev ib_size_alignment = 16; 358*b843c749SSergey Zigachev break; 359*b843c749SSergey Zigachev default: 360*b843c749SSergey Zigachev return -EINVAL; 361*b843c749SSergey Zigachev } 362*b843c749SSergey Zigachev 363*b843c749SSergey Zigachev for (i = 0; i < adev->num_ip_blocks; i++) { 364*b843c749SSergey Zigachev if (adev->ip_blocks[i].version->type == type && 365*b843c749SSergey Zigachev adev->ip_blocks[i].status.valid) { 366*b843c749SSergey Zigachev ip.hw_ip_version_major = adev->ip_blocks[i].version->major; 367*b843c749SSergey Zigachev ip.hw_ip_version_minor = adev->ip_blocks[i].version->minor; 368*b843c749SSergey Zigachev ip.capabilities_flags = 0; 369*b843c749SSergey Zigachev ip.available_rings = ring_mask; 370*b843c749SSergey Zigachev ip.ib_start_alignment = ib_start_alignment; 371*b843c749SSergey Zigachev ip.ib_size_alignment = ib_size_alignment; 372*b843c749SSergey Zigachev break; 373*b843c749SSergey Zigachev } 374*b843c749SSergey Zigachev } 375*b843c749SSergey Zigachev return copy_to_user(out, &ip, 376*b843c749SSergey Zigachev min((size_t)size, sizeof(ip))) ? -EFAULT : 0; 377*b843c749SSergey Zigachev } 378*b843c749SSergey Zigachev case AMDGPU_INFO_HW_IP_COUNT: { 379*b843c749SSergey Zigachev enum amd_ip_block_type type; 380*b843c749SSergey Zigachev uint32_t count = 0; 381*b843c749SSergey Zigachev 382*b843c749SSergey Zigachev switch (info->query_hw_ip.type) { 383*b843c749SSergey Zigachev case AMDGPU_HW_IP_GFX: 384*b843c749SSergey Zigachev type = AMD_IP_BLOCK_TYPE_GFX; 385*b843c749SSergey Zigachev break; 386*b843c749SSergey Zigachev case AMDGPU_HW_IP_COMPUTE: 387*b843c749SSergey Zigachev type = AMD_IP_BLOCK_TYPE_GFX; 388*b843c749SSergey Zigachev break; 389*b843c749SSergey Zigachev case AMDGPU_HW_IP_DMA: 390*b843c749SSergey Zigachev type = AMD_IP_BLOCK_TYPE_SDMA; 391*b843c749SSergey Zigachev break; 392*b843c749SSergey Zigachev case AMDGPU_HW_IP_UVD: 393*b843c749SSergey Zigachev type = AMD_IP_BLOCK_TYPE_UVD; 394*b843c749SSergey Zigachev break; 395*b843c749SSergey Zigachev case AMDGPU_HW_IP_VCE: 396*b843c749SSergey Zigachev type = AMD_IP_BLOCK_TYPE_VCE; 397*b843c749SSergey Zigachev break; 398*b843c749SSergey Zigachev case AMDGPU_HW_IP_UVD_ENC: 399*b843c749SSergey Zigachev type = AMD_IP_BLOCK_TYPE_UVD; 400*b843c749SSergey Zigachev break; 401*b843c749SSergey Zigachev case AMDGPU_HW_IP_VCN_DEC: 402*b843c749SSergey Zigachev case AMDGPU_HW_IP_VCN_ENC: 403*b843c749SSergey Zigachev case AMDGPU_HW_IP_VCN_JPEG: 404*b843c749SSergey Zigachev type = AMD_IP_BLOCK_TYPE_VCN; 405*b843c749SSergey Zigachev break; 406*b843c749SSergey Zigachev default: 407*b843c749SSergey Zigachev return -EINVAL; 408*b843c749SSergey Zigachev } 409*b843c749SSergey Zigachev 410*b843c749SSergey Zigachev for (i = 0; i < adev->num_ip_blocks; i++) 411*b843c749SSergey Zigachev if (adev->ip_blocks[i].version->type == type && 412*b843c749SSergey Zigachev adev->ip_blocks[i].status.valid && 413*b843c749SSergey Zigachev count < AMDGPU_HW_IP_INSTANCE_MAX_COUNT) 414*b843c749SSergey Zigachev count++; 415*b843c749SSergey Zigachev 416*b843c749SSergey Zigachev return copy_to_user(out, &count, min(size, 4u)) ? -EFAULT : 0; 417*b843c749SSergey Zigachev } 418*b843c749SSergey Zigachev case AMDGPU_INFO_TIMESTAMP: 419*b843c749SSergey Zigachev ui64 = amdgpu_gfx_get_gpu_clock_counter(adev); 420*b843c749SSergey Zigachev return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0; 421*b843c749SSergey Zigachev case AMDGPU_INFO_FW_VERSION: { 422*b843c749SSergey Zigachev struct drm_amdgpu_info_firmware fw_info; 423*b843c749SSergey Zigachev int ret; 424*b843c749SSergey Zigachev 425*b843c749SSergey Zigachev /* We only support one instance of each IP block right now. */ 426*b843c749SSergey Zigachev if (info->query_fw.ip_instance != 0) 427*b843c749SSergey Zigachev return -EINVAL; 428*b843c749SSergey Zigachev 429*b843c749SSergey Zigachev ret = amdgpu_firmware_info(&fw_info, &info->query_fw, adev); 430*b843c749SSergey Zigachev if (ret) 431*b843c749SSergey Zigachev return ret; 432*b843c749SSergey Zigachev 433*b843c749SSergey Zigachev return copy_to_user(out, &fw_info, 434*b843c749SSergey Zigachev min((size_t)size, sizeof(fw_info))) ? -EFAULT : 0; 435*b843c749SSergey Zigachev } 436*b843c749SSergey Zigachev case AMDGPU_INFO_NUM_BYTES_MOVED: 437*b843c749SSergey Zigachev ui64 = atomic64_read(&adev->num_bytes_moved); 438*b843c749SSergey Zigachev return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0; 439*b843c749SSergey Zigachev case AMDGPU_INFO_NUM_EVICTIONS: 440*b843c749SSergey Zigachev ui64 = atomic64_read(&adev->num_evictions); 441*b843c749SSergey Zigachev return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0; 442*b843c749SSergey Zigachev case AMDGPU_INFO_NUM_VRAM_CPU_PAGE_FAULTS: 443*b843c749SSergey Zigachev ui64 = atomic64_read(&adev->num_vram_cpu_page_faults); 444*b843c749SSergey Zigachev return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0; 445*b843c749SSergey Zigachev case AMDGPU_INFO_VRAM_USAGE: 446*b843c749SSergey Zigachev ui64 = amdgpu_vram_mgr_usage(&adev->mman.bdev.man[TTM_PL_VRAM]); 447*b843c749SSergey Zigachev return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0; 448*b843c749SSergey Zigachev case AMDGPU_INFO_VIS_VRAM_USAGE: 449*b843c749SSergey Zigachev ui64 = amdgpu_vram_mgr_vis_usage(&adev->mman.bdev.man[TTM_PL_VRAM]); 450*b843c749SSergey Zigachev return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0; 451*b843c749SSergey Zigachev case AMDGPU_INFO_GTT_USAGE: 452*b843c749SSergey Zigachev ui64 = amdgpu_gtt_mgr_usage(&adev->mman.bdev.man[TTM_PL_TT]); 453*b843c749SSergey Zigachev return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0; 454*b843c749SSergey Zigachev case AMDGPU_INFO_GDS_CONFIG: { 455*b843c749SSergey Zigachev struct drm_amdgpu_info_gds gds_info; 456*b843c749SSergey Zigachev 457*b843c749SSergey Zigachev memset(&gds_info, 0, sizeof(gds_info)); 458*b843c749SSergey Zigachev gds_info.gds_gfx_partition_size = adev->gds.mem.gfx_partition_size >> AMDGPU_GDS_SHIFT; 459*b843c749SSergey Zigachev gds_info.compute_partition_size = adev->gds.mem.cs_partition_size >> AMDGPU_GDS_SHIFT; 460*b843c749SSergey Zigachev gds_info.gds_total_size = adev->gds.mem.total_size >> AMDGPU_GDS_SHIFT; 461*b843c749SSergey Zigachev gds_info.gws_per_gfx_partition = adev->gds.gws.gfx_partition_size >> AMDGPU_GWS_SHIFT; 462*b843c749SSergey Zigachev gds_info.gws_per_compute_partition = adev->gds.gws.cs_partition_size >> AMDGPU_GWS_SHIFT; 463*b843c749SSergey Zigachev gds_info.oa_per_gfx_partition = adev->gds.oa.gfx_partition_size >> AMDGPU_OA_SHIFT; 464*b843c749SSergey Zigachev gds_info.oa_per_compute_partition = adev->gds.oa.cs_partition_size >> AMDGPU_OA_SHIFT; 465*b843c749SSergey Zigachev return copy_to_user(out, &gds_info, 466*b843c749SSergey Zigachev min((size_t)size, sizeof(gds_info))) ? -EFAULT : 0; 467*b843c749SSergey Zigachev } 468*b843c749SSergey Zigachev case AMDGPU_INFO_VRAM_GTT: { 469*b843c749SSergey Zigachev struct drm_amdgpu_info_vram_gtt vram_gtt; 470*b843c749SSergey Zigachev 471*b843c749SSergey Zigachev vram_gtt.vram_size = adev->gmc.real_vram_size - 472*b843c749SSergey Zigachev atomic64_read(&adev->vram_pin_size); 473*b843c749SSergey Zigachev vram_gtt.vram_cpu_accessible_size = adev->gmc.visible_vram_size - 474*b843c749SSergey Zigachev atomic64_read(&adev->visible_pin_size); 475*b843c749SSergey Zigachev vram_gtt.gtt_size = adev->mman.bdev.man[TTM_PL_TT].size; 476*b843c749SSergey Zigachev vram_gtt.gtt_size *= PAGE_SIZE; 477*b843c749SSergey Zigachev vram_gtt.gtt_size -= atomic64_read(&adev->gart_pin_size); 478*b843c749SSergey Zigachev return copy_to_user(out, &vram_gtt, 479*b843c749SSergey Zigachev min((size_t)size, sizeof(vram_gtt))) ? -EFAULT : 0; 480*b843c749SSergey Zigachev } 481*b843c749SSergey Zigachev case AMDGPU_INFO_MEMORY: { 482*b843c749SSergey Zigachev struct drm_amdgpu_memory_info mem; 483*b843c749SSergey Zigachev 484*b843c749SSergey Zigachev memset(&mem, 0, sizeof(mem)); 485*b843c749SSergey Zigachev mem.vram.total_heap_size = adev->gmc.real_vram_size; 486*b843c749SSergey Zigachev mem.vram.usable_heap_size = adev->gmc.real_vram_size - 487*b843c749SSergey Zigachev atomic64_read(&adev->vram_pin_size); 488*b843c749SSergey Zigachev mem.vram.heap_usage = 489*b843c749SSergey Zigachev amdgpu_vram_mgr_usage(&adev->mman.bdev.man[TTM_PL_VRAM]); 490*b843c749SSergey Zigachev mem.vram.max_allocation = mem.vram.usable_heap_size * 3 / 4; 491*b843c749SSergey Zigachev 492*b843c749SSergey Zigachev mem.cpu_accessible_vram.total_heap_size = 493*b843c749SSergey Zigachev adev->gmc.visible_vram_size; 494*b843c749SSergey Zigachev mem.cpu_accessible_vram.usable_heap_size = adev->gmc.visible_vram_size - 495*b843c749SSergey Zigachev atomic64_read(&adev->visible_pin_size); 496*b843c749SSergey Zigachev mem.cpu_accessible_vram.heap_usage = 497*b843c749SSergey Zigachev amdgpu_vram_mgr_vis_usage(&adev->mman.bdev.man[TTM_PL_VRAM]); 498*b843c749SSergey Zigachev mem.cpu_accessible_vram.max_allocation = 499*b843c749SSergey Zigachev mem.cpu_accessible_vram.usable_heap_size * 3 / 4; 500*b843c749SSergey Zigachev 501*b843c749SSergey Zigachev mem.gtt.total_heap_size = adev->mman.bdev.man[TTM_PL_TT].size; 502*b843c749SSergey Zigachev mem.gtt.total_heap_size *= PAGE_SIZE; 503*b843c749SSergey Zigachev mem.gtt.usable_heap_size = mem.gtt.total_heap_size - 504*b843c749SSergey Zigachev atomic64_read(&adev->gart_pin_size); 505*b843c749SSergey Zigachev mem.gtt.heap_usage = 506*b843c749SSergey Zigachev amdgpu_gtt_mgr_usage(&adev->mman.bdev.man[TTM_PL_TT]); 507*b843c749SSergey Zigachev mem.gtt.max_allocation = mem.gtt.usable_heap_size * 3 / 4; 508*b843c749SSergey Zigachev 509*b843c749SSergey Zigachev return copy_to_user(out, &mem, 510*b843c749SSergey Zigachev min((size_t)size, sizeof(mem))) 511*b843c749SSergey Zigachev ? -EFAULT : 0; 512*b843c749SSergey Zigachev } 513*b843c749SSergey Zigachev case AMDGPU_INFO_READ_MMR_REG: { 514*b843c749SSergey Zigachev unsigned n, alloc_size; 515*b843c749SSergey Zigachev uint32_t *regs; 516*b843c749SSergey Zigachev unsigned se_num = (info->read_mmr_reg.instance >> 517*b843c749SSergey Zigachev AMDGPU_INFO_MMR_SE_INDEX_SHIFT) & 518*b843c749SSergey Zigachev AMDGPU_INFO_MMR_SE_INDEX_MASK; 519*b843c749SSergey Zigachev unsigned sh_num = (info->read_mmr_reg.instance >> 520*b843c749SSergey Zigachev AMDGPU_INFO_MMR_SH_INDEX_SHIFT) & 521*b843c749SSergey Zigachev AMDGPU_INFO_MMR_SH_INDEX_MASK; 522*b843c749SSergey Zigachev 523*b843c749SSergey Zigachev /* set full masks if the userspace set all bits 524*b843c749SSergey Zigachev * in the bitfields */ 525*b843c749SSergey Zigachev if (se_num == AMDGPU_INFO_MMR_SE_INDEX_MASK) 526*b843c749SSergey Zigachev se_num = 0xffffffff; 527*b843c749SSergey Zigachev else if (se_num >= AMDGPU_GFX_MAX_SE) 528*b843c749SSergey Zigachev return -EINVAL; 529*b843c749SSergey Zigachev if (sh_num == AMDGPU_INFO_MMR_SH_INDEX_MASK) 530*b843c749SSergey Zigachev sh_num = 0xffffffff; 531*b843c749SSergey Zigachev else if (sh_num >= AMDGPU_GFX_MAX_SH_PER_SE) 532*b843c749SSergey Zigachev return -EINVAL; 533*b843c749SSergey Zigachev 534*b843c749SSergey Zigachev if (info->read_mmr_reg.count > 128) 535*b843c749SSergey Zigachev return -EINVAL; 536*b843c749SSergey Zigachev 537*b843c749SSergey Zigachev regs = kmalloc_array(info->read_mmr_reg.count, sizeof(*regs), GFP_KERNEL); 538*b843c749SSergey Zigachev if (!regs) 539*b843c749SSergey Zigachev return -ENOMEM; 540*b843c749SSergey Zigachev alloc_size = info->read_mmr_reg.count * sizeof(*regs); 541*b843c749SSergey Zigachev 542*b843c749SSergey Zigachev for (i = 0; i < info->read_mmr_reg.count; i++) 543*b843c749SSergey Zigachev if (amdgpu_asic_read_register(adev, se_num, sh_num, 544*b843c749SSergey Zigachev info->read_mmr_reg.dword_offset + i, 545*b843c749SSergey Zigachev ®s[i])) { 546*b843c749SSergey Zigachev DRM_DEBUG_KMS("unallowed offset %#x\n", 547*b843c749SSergey Zigachev info->read_mmr_reg.dword_offset + i); 548*b843c749SSergey Zigachev kfree(regs); 549*b843c749SSergey Zigachev return -EFAULT; 550*b843c749SSergey Zigachev } 551*b843c749SSergey Zigachev n = copy_to_user(out, regs, min(size, alloc_size)); 552*b843c749SSergey Zigachev kfree(regs); 553*b843c749SSergey Zigachev return n ? -EFAULT : 0; 554*b843c749SSergey Zigachev } 555*b843c749SSergey Zigachev case AMDGPU_INFO_DEV_INFO: { 556*b843c749SSergey Zigachev struct drm_amdgpu_info_device dev_info; 557*b843c749SSergey Zigachev uint64_t vm_size; 558*b843c749SSergey Zigachev 559*b843c749SSergey Zigachev memset(&dev_info, 0, sizeof(dev_info)); 560*b843c749SSergey Zigachev dev_info.device_id = dev->pdev->device; 561*b843c749SSergey Zigachev dev_info.chip_rev = adev->rev_id; 562*b843c749SSergey Zigachev dev_info.external_rev = adev->external_rev_id; 563*b843c749SSergey Zigachev dev_info.pci_rev = dev->pdev->revision; 564*b843c749SSergey Zigachev dev_info.family = adev->family; 565*b843c749SSergey Zigachev dev_info.num_shader_engines = adev->gfx.config.max_shader_engines; 566*b843c749SSergey Zigachev dev_info.num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se; 567*b843c749SSergey Zigachev /* return all clocks in KHz */ 568*b843c749SSergey Zigachev dev_info.gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10; 569*b843c749SSergey Zigachev if (adev->pm.dpm_enabled) { 570*b843c749SSergey Zigachev dev_info.max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10; 571*b843c749SSergey Zigachev dev_info.max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10; 572*b843c749SSergey Zigachev } else { 573*b843c749SSergey Zigachev dev_info.max_engine_clock = adev->clock.default_sclk * 10; 574*b843c749SSergey Zigachev dev_info.max_memory_clock = adev->clock.default_mclk * 10; 575*b843c749SSergey Zigachev } 576*b843c749SSergey Zigachev dev_info.enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask; 577*b843c749SSergey Zigachev dev_info.num_rb_pipes = adev->gfx.config.max_backends_per_se * 578*b843c749SSergey Zigachev adev->gfx.config.max_shader_engines; 579*b843c749SSergey Zigachev dev_info.num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts; 580*b843c749SSergey Zigachev dev_info._pad = 0; 581*b843c749SSergey Zigachev dev_info.ids_flags = 0; 582*b843c749SSergey Zigachev if (adev->flags & AMD_IS_APU) 583*b843c749SSergey Zigachev dev_info.ids_flags |= AMDGPU_IDS_FLAGS_FUSION; 584*b843c749SSergey Zigachev if (amdgpu_sriov_vf(adev)) 585*b843c749SSergey Zigachev dev_info.ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION; 586*b843c749SSergey Zigachev 587*b843c749SSergey Zigachev vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE; 588*b843c749SSergey Zigachev vm_size -= AMDGPU_VA_RESERVED_SIZE; 589*b843c749SSergey Zigachev 590*b843c749SSergey Zigachev /* Older VCE FW versions are buggy and can handle only 40bits */ 591*b843c749SSergey Zigachev if (adev->vce.fw_version < AMDGPU_VCE_FW_53_45) 592*b843c749SSergey Zigachev vm_size = min(vm_size, 1ULL << 40); 593*b843c749SSergey Zigachev 594*b843c749SSergey Zigachev dev_info.virtual_address_offset = AMDGPU_VA_RESERVED_SIZE; 595*b843c749SSergey Zigachev dev_info.virtual_address_max = 596*b843c749SSergey Zigachev min(vm_size, AMDGPU_VA_HOLE_START); 597*b843c749SSergey Zigachev 598*b843c749SSergey Zigachev if (vm_size > AMDGPU_VA_HOLE_START) { 599*b843c749SSergey Zigachev dev_info.high_va_offset = AMDGPU_VA_HOLE_END; 600*b843c749SSergey Zigachev dev_info.high_va_max = AMDGPU_VA_HOLE_END | vm_size; 601*b843c749SSergey Zigachev } 602*b843c749SSergey Zigachev dev_info.virtual_address_alignment = max((int)PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE); 603*b843c749SSergey Zigachev dev_info.pte_fragment_size = (1 << adev->vm_manager.fragment_size) * AMDGPU_GPU_PAGE_SIZE; 604*b843c749SSergey Zigachev dev_info.gart_page_size = AMDGPU_GPU_PAGE_SIZE; 605*b843c749SSergey Zigachev dev_info.cu_active_number = adev->gfx.cu_info.number; 606*b843c749SSergey Zigachev dev_info.cu_ao_mask = adev->gfx.cu_info.ao_cu_mask; 607*b843c749SSergey Zigachev dev_info.ce_ram_size = adev->gfx.ce_ram_size; 608*b843c749SSergey Zigachev memcpy(&dev_info.cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0], 609*b843c749SSergey Zigachev sizeof(adev->gfx.cu_info.ao_cu_bitmap)); 610*b843c749SSergey Zigachev memcpy(&dev_info.cu_bitmap[0], &adev->gfx.cu_info.bitmap[0], 611*b843c749SSergey Zigachev sizeof(adev->gfx.cu_info.bitmap)); 612*b843c749SSergey Zigachev dev_info.vram_type = adev->gmc.vram_type; 613*b843c749SSergey Zigachev dev_info.vram_bit_width = adev->gmc.vram_width; 614*b843c749SSergey Zigachev dev_info.vce_harvest_config = adev->vce.harvest_config; 615*b843c749SSergey Zigachev dev_info.gc_double_offchip_lds_buf = 616*b843c749SSergey Zigachev adev->gfx.config.double_offchip_lds_buf; 617*b843c749SSergey Zigachev 618*b843c749SSergey Zigachev if (amdgpu_ngg) { 619*b843c749SSergey Zigachev dev_info.prim_buf_gpu_addr = adev->gfx.ngg.buf[NGG_PRIM].gpu_addr; 620*b843c749SSergey Zigachev dev_info.prim_buf_size = adev->gfx.ngg.buf[NGG_PRIM].size; 621*b843c749SSergey Zigachev dev_info.pos_buf_gpu_addr = adev->gfx.ngg.buf[NGG_POS].gpu_addr; 622*b843c749SSergey Zigachev dev_info.pos_buf_size = adev->gfx.ngg.buf[NGG_POS].size; 623*b843c749SSergey Zigachev dev_info.cntl_sb_buf_gpu_addr = adev->gfx.ngg.buf[NGG_CNTL].gpu_addr; 624*b843c749SSergey Zigachev dev_info.cntl_sb_buf_size = adev->gfx.ngg.buf[NGG_CNTL].size; 625*b843c749SSergey Zigachev dev_info.param_buf_gpu_addr = adev->gfx.ngg.buf[NGG_PARAM].gpu_addr; 626*b843c749SSergey Zigachev dev_info.param_buf_size = adev->gfx.ngg.buf[NGG_PARAM].size; 627*b843c749SSergey Zigachev } 628*b843c749SSergey Zigachev dev_info.wave_front_size = adev->gfx.cu_info.wave_front_size; 629*b843c749SSergey Zigachev dev_info.num_shader_visible_vgprs = adev->gfx.config.max_gprs; 630*b843c749SSergey Zigachev dev_info.num_cu_per_sh = adev->gfx.config.max_cu_per_sh; 631*b843c749SSergey Zigachev dev_info.num_tcc_blocks = adev->gfx.config.max_texture_channel_caches; 632*b843c749SSergey Zigachev dev_info.gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth; 633*b843c749SSergey Zigachev dev_info.gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth; 634*b843c749SSergey Zigachev dev_info.max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads; 635*b843c749SSergey Zigachev 636*b843c749SSergey Zigachev return copy_to_user(out, &dev_info, 637*b843c749SSergey Zigachev min((size_t)size, sizeof(dev_info))) ? -EFAULT : 0; 638*b843c749SSergey Zigachev } 639*b843c749SSergey Zigachev case AMDGPU_INFO_VCE_CLOCK_TABLE: { 640*b843c749SSergey Zigachev unsigned i; 641*b843c749SSergey Zigachev struct drm_amdgpu_info_vce_clock_table vce_clk_table = {}; 642*b843c749SSergey Zigachev struct amd_vce_state *vce_state; 643*b843c749SSergey Zigachev 644*b843c749SSergey Zigachev for (i = 0; i < AMDGPU_VCE_CLOCK_TABLE_ENTRIES; i++) { 645*b843c749SSergey Zigachev vce_state = amdgpu_dpm_get_vce_clock_state(adev, i); 646*b843c749SSergey Zigachev if (vce_state) { 647*b843c749SSergey Zigachev vce_clk_table.entries[i].sclk = vce_state->sclk; 648*b843c749SSergey Zigachev vce_clk_table.entries[i].mclk = vce_state->mclk; 649*b843c749SSergey Zigachev vce_clk_table.entries[i].eclk = vce_state->evclk; 650*b843c749SSergey Zigachev vce_clk_table.num_valid_entries++; 651*b843c749SSergey Zigachev } 652*b843c749SSergey Zigachev } 653*b843c749SSergey Zigachev 654*b843c749SSergey Zigachev return copy_to_user(out, &vce_clk_table, 655*b843c749SSergey Zigachev min((size_t)size, sizeof(vce_clk_table))) ? -EFAULT : 0; 656*b843c749SSergey Zigachev } 657*b843c749SSergey Zigachev case AMDGPU_INFO_VBIOS: { 658*b843c749SSergey Zigachev uint32_t bios_size = adev->bios_size; 659*b843c749SSergey Zigachev 660*b843c749SSergey Zigachev switch (info->vbios_info.type) { 661*b843c749SSergey Zigachev case AMDGPU_INFO_VBIOS_SIZE: 662*b843c749SSergey Zigachev return copy_to_user(out, &bios_size, 663*b843c749SSergey Zigachev min((size_t)size, sizeof(bios_size))) 664*b843c749SSergey Zigachev ? -EFAULT : 0; 665*b843c749SSergey Zigachev case AMDGPU_INFO_VBIOS_IMAGE: { 666*b843c749SSergey Zigachev uint8_t *bios; 667*b843c749SSergey Zigachev uint32_t bios_offset = info->vbios_info.offset; 668*b843c749SSergey Zigachev 669*b843c749SSergey Zigachev if (bios_offset >= bios_size) 670*b843c749SSergey Zigachev return -EINVAL; 671*b843c749SSergey Zigachev 672*b843c749SSergey Zigachev bios = adev->bios + bios_offset; 673*b843c749SSergey Zigachev return copy_to_user(out, bios, 674*b843c749SSergey Zigachev min((size_t)size, (size_t)(bios_size - bios_offset))) 675*b843c749SSergey Zigachev ? -EFAULT : 0; 676*b843c749SSergey Zigachev } 677*b843c749SSergey Zigachev default: 678*b843c749SSergey Zigachev DRM_DEBUG_KMS("Invalid request %d\n", 679*b843c749SSergey Zigachev info->vbios_info.type); 680*b843c749SSergey Zigachev return -EINVAL; 681*b843c749SSergey Zigachev } 682*b843c749SSergey Zigachev } 683*b843c749SSergey Zigachev case AMDGPU_INFO_NUM_HANDLES: { 684*b843c749SSergey Zigachev struct drm_amdgpu_info_num_handles handle; 685*b843c749SSergey Zigachev 686*b843c749SSergey Zigachev switch (info->query_hw_ip.type) { 687*b843c749SSergey Zigachev case AMDGPU_HW_IP_UVD: 688*b843c749SSergey Zigachev /* Starting Polaris, we support unlimited UVD handles */ 689*b843c749SSergey Zigachev if (adev->asic_type < CHIP_POLARIS10) { 690*b843c749SSergey Zigachev handle.uvd_max_handles = adev->uvd.max_handles; 691*b843c749SSergey Zigachev handle.uvd_used_handles = amdgpu_uvd_used_handles(adev); 692*b843c749SSergey Zigachev 693*b843c749SSergey Zigachev return copy_to_user(out, &handle, 694*b843c749SSergey Zigachev min((size_t)size, sizeof(handle))) ? -EFAULT : 0; 695*b843c749SSergey Zigachev } else { 696*b843c749SSergey Zigachev return -ENODATA; 697*b843c749SSergey Zigachev } 698*b843c749SSergey Zigachev 699*b843c749SSergey Zigachev break; 700*b843c749SSergey Zigachev default: 701*b843c749SSergey Zigachev return -EINVAL; 702*b843c749SSergey Zigachev } 703*b843c749SSergey Zigachev } 704*b843c749SSergey Zigachev case AMDGPU_INFO_SENSOR: { 705*b843c749SSergey Zigachev if (!adev->pm.dpm_enabled) 706*b843c749SSergey Zigachev return -ENOENT; 707*b843c749SSergey Zigachev 708*b843c749SSergey Zigachev switch (info->sensor_info.type) { 709*b843c749SSergey Zigachev case AMDGPU_INFO_SENSOR_GFX_SCLK: 710*b843c749SSergey Zigachev /* get sclk in Mhz */ 711*b843c749SSergey Zigachev if (amdgpu_dpm_read_sensor(adev, 712*b843c749SSergey Zigachev AMDGPU_PP_SENSOR_GFX_SCLK, 713*b843c749SSergey Zigachev (void *)&ui32, &ui32_size)) { 714*b843c749SSergey Zigachev return -EINVAL; 715*b843c749SSergey Zigachev } 716*b843c749SSergey Zigachev ui32 /= 100; 717*b843c749SSergey Zigachev break; 718*b843c749SSergey Zigachev case AMDGPU_INFO_SENSOR_GFX_MCLK: 719*b843c749SSergey Zigachev /* get mclk in Mhz */ 720*b843c749SSergey Zigachev if (amdgpu_dpm_read_sensor(adev, 721*b843c749SSergey Zigachev AMDGPU_PP_SENSOR_GFX_MCLK, 722*b843c749SSergey Zigachev (void *)&ui32, &ui32_size)) { 723*b843c749SSergey Zigachev return -EINVAL; 724*b843c749SSergey Zigachev } 725*b843c749SSergey Zigachev ui32 /= 100; 726*b843c749SSergey Zigachev break; 727*b843c749SSergey Zigachev case AMDGPU_INFO_SENSOR_GPU_TEMP: 728*b843c749SSergey Zigachev /* get temperature in millidegrees C */ 729*b843c749SSergey Zigachev if (amdgpu_dpm_read_sensor(adev, 730*b843c749SSergey Zigachev AMDGPU_PP_SENSOR_GPU_TEMP, 731*b843c749SSergey Zigachev (void *)&ui32, &ui32_size)) { 732*b843c749SSergey Zigachev return -EINVAL; 733*b843c749SSergey Zigachev } 734*b843c749SSergey Zigachev break; 735*b843c749SSergey Zigachev case AMDGPU_INFO_SENSOR_GPU_LOAD: 736*b843c749SSergey Zigachev /* get GPU load */ 737*b843c749SSergey Zigachev if (amdgpu_dpm_read_sensor(adev, 738*b843c749SSergey Zigachev AMDGPU_PP_SENSOR_GPU_LOAD, 739*b843c749SSergey Zigachev (void *)&ui32, &ui32_size)) { 740*b843c749SSergey Zigachev return -EINVAL; 741*b843c749SSergey Zigachev } 742*b843c749SSergey Zigachev break; 743*b843c749SSergey Zigachev case AMDGPU_INFO_SENSOR_GPU_AVG_POWER: 744*b843c749SSergey Zigachev /* get average GPU power */ 745*b843c749SSergey Zigachev if (amdgpu_dpm_read_sensor(adev, 746*b843c749SSergey Zigachev AMDGPU_PP_SENSOR_GPU_POWER, 747*b843c749SSergey Zigachev (void *)&ui32, &ui32_size)) { 748*b843c749SSergey Zigachev return -EINVAL; 749*b843c749SSergey Zigachev } 750*b843c749SSergey Zigachev ui32 >>= 8; 751*b843c749SSergey Zigachev break; 752*b843c749SSergey Zigachev case AMDGPU_INFO_SENSOR_VDDNB: 753*b843c749SSergey Zigachev /* get VDDNB in millivolts */ 754*b843c749SSergey Zigachev if (amdgpu_dpm_read_sensor(adev, 755*b843c749SSergey Zigachev AMDGPU_PP_SENSOR_VDDNB, 756*b843c749SSergey Zigachev (void *)&ui32, &ui32_size)) { 757*b843c749SSergey Zigachev return -EINVAL; 758*b843c749SSergey Zigachev } 759*b843c749SSergey Zigachev break; 760*b843c749SSergey Zigachev case AMDGPU_INFO_SENSOR_VDDGFX: 761*b843c749SSergey Zigachev /* get VDDGFX in millivolts */ 762*b843c749SSergey Zigachev if (amdgpu_dpm_read_sensor(adev, 763*b843c749SSergey Zigachev AMDGPU_PP_SENSOR_VDDGFX, 764*b843c749SSergey Zigachev (void *)&ui32, &ui32_size)) { 765*b843c749SSergey Zigachev return -EINVAL; 766*b843c749SSergey Zigachev } 767*b843c749SSergey Zigachev break; 768*b843c749SSergey Zigachev case AMDGPU_INFO_SENSOR_STABLE_PSTATE_GFX_SCLK: 769*b843c749SSergey Zigachev /* get stable pstate sclk in Mhz */ 770*b843c749SSergey Zigachev if (amdgpu_dpm_read_sensor(adev, 771*b843c749SSergey Zigachev AMDGPU_PP_SENSOR_STABLE_PSTATE_SCLK, 772*b843c749SSergey Zigachev (void *)&ui32, &ui32_size)) { 773*b843c749SSergey Zigachev return -EINVAL; 774*b843c749SSergey Zigachev } 775*b843c749SSergey Zigachev ui32 /= 100; 776*b843c749SSergey Zigachev break; 777*b843c749SSergey Zigachev case AMDGPU_INFO_SENSOR_STABLE_PSTATE_GFX_MCLK: 778*b843c749SSergey Zigachev /* get stable pstate mclk in Mhz */ 779*b843c749SSergey Zigachev if (amdgpu_dpm_read_sensor(adev, 780*b843c749SSergey Zigachev AMDGPU_PP_SENSOR_STABLE_PSTATE_MCLK, 781*b843c749SSergey Zigachev (void *)&ui32, &ui32_size)) { 782*b843c749SSergey Zigachev return -EINVAL; 783*b843c749SSergey Zigachev } 784*b843c749SSergey Zigachev ui32 /= 100; 785*b843c749SSergey Zigachev break; 786*b843c749SSergey Zigachev default: 787*b843c749SSergey Zigachev DRM_DEBUG_KMS("Invalid request %d\n", 788*b843c749SSergey Zigachev info->sensor_info.type); 789*b843c749SSergey Zigachev return -EINVAL; 790*b843c749SSergey Zigachev } 791*b843c749SSergey Zigachev return copy_to_user(out, &ui32, min(size, 4u)) ? -EFAULT : 0; 792*b843c749SSergey Zigachev } 793*b843c749SSergey Zigachev case AMDGPU_INFO_VRAM_LOST_COUNTER: 794*b843c749SSergey Zigachev ui32 = atomic_read(&adev->vram_lost_counter); 795*b843c749SSergey Zigachev return copy_to_user(out, &ui32, min(size, 4u)) ? -EFAULT : 0; 796*b843c749SSergey Zigachev default: 797*b843c749SSergey Zigachev DRM_DEBUG_KMS("Invalid request %d\n", info->query); 798*b843c749SSergey Zigachev return -EINVAL; 799*b843c749SSergey Zigachev } 800*b843c749SSergey Zigachev return 0; 801*b843c749SSergey Zigachev } 802*b843c749SSergey Zigachev 803*b843c749SSergey Zigachev 804*b843c749SSergey Zigachev /* 805*b843c749SSergey Zigachev * Outdated mess for old drm with Xorg being in charge (void function now). 806*b843c749SSergey Zigachev */ 807*b843c749SSergey Zigachev /** 808*b843c749SSergey Zigachev * amdgpu_driver_lastclose_kms - drm callback for last close 809*b843c749SSergey Zigachev * 810*b843c749SSergey Zigachev * @dev: drm dev pointer 811*b843c749SSergey Zigachev * 812*b843c749SSergey Zigachev * Switch vga_switcheroo state after last close (all asics). 813*b843c749SSergey Zigachev */ 814*b843c749SSergey Zigachev void amdgpu_driver_lastclose_kms(struct drm_device *dev) 815*b843c749SSergey Zigachev { 816*b843c749SSergey Zigachev drm_fb_helper_lastclose(dev); 817*b843c749SSergey Zigachev vga_switcheroo_process_delayed_switch(); 818*b843c749SSergey Zigachev } 819*b843c749SSergey Zigachev 820*b843c749SSergey Zigachev /** 821*b843c749SSergey Zigachev * amdgpu_driver_open_kms - drm callback for open 822*b843c749SSergey Zigachev * 823*b843c749SSergey Zigachev * @dev: drm dev pointer 824*b843c749SSergey Zigachev * @file_priv: drm file 825*b843c749SSergey Zigachev * 826*b843c749SSergey Zigachev * On device open, init vm on cayman+ (all asics). 827*b843c749SSergey Zigachev * Returns 0 on success, error on failure. 828*b843c749SSergey Zigachev */ 829*b843c749SSergey Zigachev int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) 830*b843c749SSergey Zigachev { 831*b843c749SSergey Zigachev struct amdgpu_device *adev = dev->dev_private; 832*b843c749SSergey Zigachev struct amdgpu_fpriv *fpriv; 833*b843c749SSergey Zigachev int r, pasid; 834*b843c749SSergey Zigachev 835*b843c749SSergey Zigachev /* Ensure IB tests are run on ring */ 836*b843c749SSergey Zigachev flush_delayed_work(&adev->late_init_work); 837*b843c749SSergey Zigachev 838*b843c749SSergey Zigachev file_priv->driver_priv = NULL; 839*b843c749SSergey Zigachev 840*b843c749SSergey Zigachev r = pm_runtime_get_sync(dev->dev); 841*b843c749SSergey Zigachev if (r < 0) 842*b843c749SSergey Zigachev goto pm_put; 843*b843c749SSergey Zigachev 844*b843c749SSergey Zigachev fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL); 845*b843c749SSergey Zigachev if (unlikely(!fpriv)) { 846*b843c749SSergey Zigachev r = -ENOMEM; 847*b843c749SSergey Zigachev goto out_suspend; 848*b843c749SSergey Zigachev } 849*b843c749SSergey Zigachev 850*b843c749SSergey Zigachev pasid = amdgpu_pasid_alloc(16); 851*b843c749SSergey Zigachev if (pasid < 0) { 852*b843c749SSergey Zigachev dev_warn(adev->dev, "No more PASIDs available!"); 853*b843c749SSergey Zigachev pasid = 0; 854*b843c749SSergey Zigachev } 855*b843c749SSergey Zigachev r = amdgpu_vm_init(adev, &fpriv->vm, AMDGPU_VM_CONTEXT_GFX, pasid); 856*b843c749SSergey Zigachev if (r) 857*b843c749SSergey Zigachev goto error_pasid; 858*b843c749SSergey Zigachev 859*b843c749SSergey Zigachev fpriv->prt_va = amdgpu_vm_bo_add(adev, &fpriv->vm, NULL); 860*b843c749SSergey Zigachev if (!fpriv->prt_va) { 861*b843c749SSergey Zigachev r = -ENOMEM; 862*b843c749SSergey Zigachev goto error_vm; 863*b843c749SSergey Zigachev } 864*b843c749SSergey Zigachev 865*b843c749SSergey Zigachev if (amdgpu_sriov_vf(adev)) { 866*b843c749SSergey Zigachev r = amdgpu_map_static_csa(adev, &fpriv->vm, &fpriv->csa_va); 867*b843c749SSergey Zigachev if (r) 868*b843c749SSergey Zigachev goto error_vm; 869*b843c749SSergey Zigachev } 870*b843c749SSergey Zigachev 871*b843c749SSergey Zigachev mutex_init(&fpriv->bo_list_lock); 872*b843c749SSergey Zigachev idr_init(&fpriv->bo_list_handles); 873*b843c749SSergey Zigachev 874*b843c749SSergey Zigachev amdgpu_ctx_mgr_init(&fpriv->ctx_mgr); 875*b843c749SSergey Zigachev 876*b843c749SSergey Zigachev file_priv->driver_priv = fpriv; 877*b843c749SSergey Zigachev goto out_suspend; 878*b843c749SSergey Zigachev 879*b843c749SSergey Zigachev error_vm: 880*b843c749SSergey Zigachev amdgpu_vm_fini(adev, &fpriv->vm); 881*b843c749SSergey Zigachev 882*b843c749SSergey Zigachev error_pasid: 883*b843c749SSergey Zigachev if (pasid) 884*b843c749SSergey Zigachev amdgpu_pasid_free(pasid); 885*b843c749SSergey Zigachev 886*b843c749SSergey Zigachev kfree(fpriv); 887*b843c749SSergey Zigachev 888*b843c749SSergey Zigachev out_suspend: 889*b843c749SSergey Zigachev pm_runtime_mark_last_busy(dev->dev); 890*b843c749SSergey Zigachev pm_put: 891*b843c749SSergey Zigachev pm_runtime_put_autosuspend(dev->dev); 892*b843c749SSergey Zigachev 893*b843c749SSergey Zigachev return r; 894*b843c749SSergey Zigachev } 895*b843c749SSergey Zigachev 896*b843c749SSergey Zigachev /** 897*b843c749SSergey Zigachev * amdgpu_driver_postclose_kms - drm callback for post close 898*b843c749SSergey Zigachev * 899*b843c749SSergey Zigachev * @dev: drm dev pointer 900*b843c749SSergey Zigachev * @file_priv: drm file 901*b843c749SSergey Zigachev * 902*b843c749SSergey Zigachev * On device post close, tear down vm on cayman+ (all asics). 903*b843c749SSergey Zigachev */ 904*b843c749SSergey Zigachev void amdgpu_driver_postclose_kms(struct drm_device *dev, 905*b843c749SSergey Zigachev struct drm_file *file_priv) 906*b843c749SSergey Zigachev { 907*b843c749SSergey Zigachev struct amdgpu_device *adev = dev->dev_private; 908*b843c749SSergey Zigachev struct amdgpu_fpriv *fpriv = file_priv->driver_priv; 909*b843c749SSergey Zigachev struct amdgpu_bo_list *list; 910*b843c749SSergey Zigachev struct amdgpu_bo *pd; 911*b843c749SSergey Zigachev unsigned int pasid; 912*b843c749SSergey Zigachev int handle; 913*b843c749SSergey Zigachev 914*b843c749SSergey Zigachev if (!fpriv) 915*b843c749SSergey Zigachev return; 916*b843c749SSergey Zigachev 917*b843c749SSergey Zigachev pm_runtime_get_sync(dev->dev); 918*b843c749SSergey Zigachev 919*b843c749SSergey Zigachev if (adev->asic_type != CHIP_RAVEN) { 920*b843c749SSergey Zigachev amdgpu_uvd_free_handles(adev, file_priv); 921*b843c749SSergey Zigachev amdgpu_vce_free_handles(adev, file_priv); 922*b843c749SSergey Zigachev } 923*b843c749SSergey Zigachev 924*b843c749SSergey Zigachev amdgpu_vm_bo_rmv(adev, fpriv->prt_va); 925*b843c749SSergey Zigachev 926*b843c749SSergey Zigachev if (amdgpu_sriov_vf(adev)) { 927*b843c749SSergey Zigachev /* TODO: how to handle reserve failure */ 928*b843c749SSergey Zigachev BUG_ON(amdgpu_bo_reserve(adev->virt.csa_obj, true)); 929*b843c749SSergey Zigachev amdgpu_vm_bo_rmv(adev, fpriv->csa_va); 930*b843c749SSergey Zigachev fpriv->csa_va = NULL; 931*b843c749SSergey Zigachev amdgpu_bo_unreserve(adev->virt.csa_obj); 932*b843c749SSergey Zigachev } 933*b843c749SSergey Zigachev 934*b843c749SSergey Zigachev pasid = fpriv->vm.pasid; 935*b843c749SSergey Zigachev pd = amdgpu_bo_ref(fpriv->vm.root.base.bo); 936*b843c749SSergey Zigachev 937*b843c749SSergey Zigachev amdgpu_vm_fini(adev, &fpriv->vm); 938*b843c749SSergey Zigachev amdgpu_ctx_mgr_fini(&fpriv->ctx_mgr); 939*b843c749SSergey Zigachev 940*b843c749SSergey Zigachev if (pasid) 941*b843c749SSergey Zigachev amdgpu_pasid_free_delayed(pd->tbo.resv, pasid); 942*b843c749SSergey Zigachev amdgpu_bo_unref(&pd); 943*b843c749SSergey Zigachev 944*b843c749SSergey Zigachev idr_for_each_entry(&fpriv->bo_list_handles, list, handle) 945*b843c749SSergey Zigachev amdgpu_bo_list_put(list); 946*b843c749SSergey Zigachev 947*b843c749SSergey Zigachev idr_destroy(&fpriv->bo_list_handles); 948*b843c749SSergey Zigachev mutex_destroy(&fpriv->bo_list_lock); 949*b843c749SSergey Zigachev 950*b843c749SSergey Zigachev kfree(fpriv); 951*b843c749SSergey Zigachev file_priv->driver_priv = NULL; 952*b843c749SSergey Zigachev 953*b843c749SSergey Zigachev pm_runtime_mark_last_busy(dev->dev); 954*b843c749SSergey Zigachev pm_runtime_put_autosuspend(dev->dev); 955*b843c749SSergey Zigachev } 956*b843c749SSergey Zigachev 957*b843c749SSergey Zigachev /* 958*b843c749SSergey Zigachev * VBlank related functions. 959*b843c749SSergey Zigachev */ 960*b843c749SSergey Zigachev /** 961*b843c749SSergey Zigachev * amdgpu_get_vblank_counter_kms - get frame count 962*b843c749SSergey Zigachev * 963*b843c749SSergey Zigachev * @dev: drm dev pointer 964*b843c749SSergey Zigachev * @pipe: crtc to get the frame count from 965*b843c749SSergey Zigachev * 966*b843c749SSergey Zigachev * Gets the frame count on the requested crtc (all asics). 967*b843c749SSergey Zigachev * Returns frame count on success, -EINVAL on failure. 968*b843c749SSergey Zigachev */ 969*b843c749SSergey Zigachev u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe) 970*b843c749SSergey Zigachev { 971*b843c749SSergey Zigachev struct amdgpu_device *adev = dev->dev_private; 972*b843c749SSergey Zigachev int vpos, hpos, stat; 973*b843c749SSergey Zigachev u32 count; 974*b843c749SSergey Zigachev 975*b843c749SSergey Zigachev if (pipe >= adev->mode_info.num_crtc) { 976*b843c749SSergey Zigachev DRM_ERROR("Invalid crtc %u\n", pipe); 977*b843c749SSergey Zigachev return -EINVAL; 978*b843c749SSergey Zigachev } 979*b843c749SSergey Zigachev 980*b843c749SSergey Zigachev /* The hw increments its frame counter at start of vsync, not at start 981*b843c749SSergey Zigachev * of vblank, as is required by DRM core vblank counter handling. 982*b843c749SSergey Zigachev * Cook the hw count here to make it appear to the caller as if it 983*b843c749SSergey Zigachev * incremented at start of vblank. We measure distance to start of 984*b843c749SSergey Zigachev * vblank in vpos. vpos therefore will be >= 0 between start of vblank 985*b843c749SSergey Zigachev * and start of vsync, so vpos >= 0 means to bump the hw frame counter 986*b843c749SSergey Zigachev * result by 1 to give the proper appearance to caller. 987*b843c749SSergey Zigachev */ 988*b843c749SSergey Zigachev if (adev->mode_info.crtcs[pipe]) { 989*b843c749SSergey Zigachev /* Repeat readout if needed to provide stable result if 990*b843c749SSergey Zigachev * we cross start of vsync during the queries. 991*b843c749SSergey Zigachev */ 992*b843c749SSergey Zigachev do { 993*b843c749SSergey Zigachev count = amdgpu_display_vblank_get_counter(adev, pipe); 994*b843c749SSergey Zigachev /* Ask amdgpu_display_get_crtc_scanoutpos to return 995*b843c749SSergey Zigachev * vpos as distance to start of vblank, instead of 996*b843c749SSergey Zigachev * regular vertical scanout pos. 997*b843c749SSergey Zigachev */ 998*b843c749SSergey Zigachev stat = amdgpu_display_get_crtc_scanoutpos( 999*b843c749SSergey Zigachev dev, pipe, GET_DISTANCE_TO_VBLANKSTART, 1000*b843c749SSergey Zigachev &vpos, &hpos, NULL, NULL, 1001*b843c749SSergey Zigachev &adev->mode_info.crtcs[pipe]->base.hwmode); 1002*b843c749SSergey Zigachev } while (count != amdgpu_display_vblank_get_counter(adev, pipe)); 1003*b843c749SSergey Zigachev 1004*b843c749SSergey Zigachev if (((stat & (DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE)) != 1005*b843c749SSergey Zigachev (DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE))) { 1006*b843c749SSergey Zigachev DRM_DEBUG_VBL("Query failed! stat %d\n", stat); 1007*b843c749SSergey Zigachev } else { 1008*b843c749SSergey Zigachev DRM_DEBUG_VBL("crtc %d: dist from vblank start %d\n", 1009*b843c749SSergey Zigachev pipe, vpos); 1010*b843c749SSergey Zigachev 1011*b843c749SSergey Zigachev /* Bump counter if we are at >= leading edge of vblank, 1012*b843c749SSergey Zigachev * but before vsync where vpos would turn negative and 1013*b843c749SSergey Zigachev * the hw counter really increments. 1014*b843c749SSergey Zigachev */ 1015*b843c749SSergey Zigachev if (vpos >= 0) 1016*b843c749SSergey Zigachev count++; 1017*b843c749SSergey Zigachev } 1018*b843c749SSergey Zigachev } else { 1019*b843c749SSergey Zigachev /* Fallback to use value as is. */ 1020*b843c749SSergey Zigachev count = amdgpu_display_vblank_get_counter(adev, pipe); 1021*b843c749SSergey Zigachev DRM_DEBUG_VBL("NULL mode info! Returned count may be wrong.\n"); 1022*b843c749SSergey Zigachev } 1023*b843c749SSergey Zigachev 1024*b843c749SSergey Zigachev return count; 1025*b843c749SSergey Zigachev } 1026*b843c749SSergey Zigachev 1027*b843c749SSergey Zigachev /** 1028*b843c749SSergey Zigachev * amdgpu_enable_vblank_kms - enable vblank interrupt 1029*b843c749SSergey Zigachev * 1030*b843c749SSergey Zigachev * @dev: drm dev pointer 1031*b843c749SSergey Zigachev * @pipe: crtc to enable vblank interrupt for 1032*b843c749SSergey Zigachev * 1033*b843c749SSergey Zigachev * Enable the interrupt on the requested crtc (all asics). 1034*b843c749SSergey Zigachev * Returns 0 on success, -EINVAL on failure. 1035*b843c749SSergey Zigachev */ 1036*b843c749SSergey Zigachev int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe) 1037*b843c749SSergey Zigachev { 1038*b843c749SSergey Zigachev struct amdgpu_device *adev = dev->dev_private; 1039*b843c749SSergey Zigachev int idx = amdgpu_display_crtc_idx_to_irq_type(adev, pipe); 1040*b843c749SSergey Zigachev 1041*b843c749SSergey Zigachev return amdgpu_irq_get(adev, &adev->crtc_irq, idx); 1042*b843c749SSergey Zigachev } 1043*b843c749SSergey Zigachev 1044*b843c749SSergey Zigachev /** 1045*b843c749SSergey Zigachev * amdgpu_disable_vblank_kms - disable vblank interrupt 1046*b843c749SSergey Zigachev * 1047*b843c749SSergey Zigachev * @dev: drm dev pointer 1048*b843c749SSergey Zigachev * @pipe: crtc to disable vblank interrupt for 1049*b843c749SSergey Zigachev * 1050*b843c749SSergey Zigachev * Disable the interrupt on the requested crtc (all asics). 1051*b843c749SSergey Zigachev */ 1052*b843c749SSergey Zigachev void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe) 1053*b843c749SSergey Zigachev { 1054*b843c749SSergey Zigachev struct amdgpu_device *adev = dev->dev_private; 1055*b843c749SSergey Zigachev int idx = amdgpu_display_crtc_idx_to_irq_type(adev, pipe); 1056*b843c749SSergey Zigachev 1057*b843c749SSergey Zigachev amdgpu_irq_put(adev, &adev->crtc_irq, idx); 1058*b843c749SSergey Zigachev } 1059*b843c749SSergey Zigachev 1060*b843c749SSergey Zigachev const struct drm_ioctl_desc amdgpu_ioctls_kms[] = { 1061*b843c749SSergey Zigachev DRM_IOCTL_DEF_DRV(AMDGPU_GEM_CREATE, amdgpu_gem_create_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), 1062*b843c749SSergey Zigachev DRM_IOCTL_DEF_DRV(AMDGPU_CTX, amdgpu_ctx_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), 1063*b843c749SSergey Zigachev DRM_IOCTL_DEF_DRV(AMDGPU_VM, amdgpu_vm_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), 1064*b843c749SSergey Zigachev DRM_IOCTL_DEF_DRV(AMDGPU_SCHED, amdgpu_sched_ioctl, DRM_MASTER), 1065*b843c749SSergey Zigachev DRM_IOCTL_DEF_DRV(AMDGPU_BO_LIST, amdgpu_bo_list_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), 1066*b843c749SSergey Zigachev DRM_IOCTL_DEF_DRV(AMDGPU_FENCE_TO_HANDLE, amdgpu_cs_fence_to_handle_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), 1067*b843c749SSergey Zigachev /* KMS */ 1068*b843c749SSergey Zigachev DRM_IOCTL_DEF_DRV(AMDGPU_GEM_MMAP, amdgpu_gem_mmap_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), 1069*b843c749SSergey Zigachev DRM_IOCTL_DEF_DRV(AMDGPU_GEM_WAIT_IDLE, amdgpu_gem_wait_idle_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), 1070*b843c749SSergey Zigachev DRM_IOCTL_DEF_DRV(AMDGPU_CS, amdgpu_cs_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), 1071*b843c749SSergey Zigachev DRM_IOCTL_DEF_DRV(AMDGPU_INFO, amdgpu_info_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), 1072*b843c749SSergey Zigachev DRM_IOCTL_DEF_DRV(AMDGPU_WAIT_CS, amdgpu_cs_wait_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), 1073*b843c749SSergey Zigachev DRM_IOCTL_DEF_DRV(AMDGPU_WAIT_FENCES, amdgpu_cs_wait_fences_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), 1074*b843c749SSergey Zigachev DRM_IOCTL_DEF_DRV(AMDGPU_GEM_METADATA, amdgpu_gem_metadata_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), 1075*b843c749SSergey Zigachev DRM_IOCTL_DEF_DRV(AMDGPU_GEM_VA, amdgpu_gem_va_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), 1076*b843c749SSergey Zigachev DRM_IOCTL_DEF_DRV(AMDGPU_GEM_OP, amdgpu_gem_op_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), 1077*b843c749SSergey Zigachev DRM_IOCTL_DEF_DRV(AMDGPU_GEM_USERPTR, amdgpu_gem_userptr_ioctl, DRM_AUTH|DRM_RENDER_ALLOW) 1078*b843c749SSergey Zigachev }; 1079*b843c749SSergey Zigachev const int amdgpu_max_kms_ioctl = ARRAY_SIZE(amdgpu_ioctls_kms); 1080*b843c749SSergey Zigachev 1081*b843c749SSergey Zigachev /* 1082*b843c749SSergey Zigachev * Debugfs info 1083*b843c749SSergey Zigachev */ 1084*b843c749SSergey Zigachev #if defined(CONFIG_DEBUG_FS) 1085*b843c749SSergey Zigachev 1086*b843c749SSergey Zigachev static int amdgpu_debugfs_firmware_info(struct seq_file *m, void *data) 1087*b843c749SSergey Zigachev { 1088*b843c749SSergey Zigachev struct drm_info_node *node = (struct drm_info_node *) m->private; 1089*b843c749SSergey Zigachev struct drm_device *dev = node->minor->dev; 1090*b843c749SSergey Zigachev struct amdgpu_device *adev = dev->dev_private; 1091*b843c749SSergey Zigachev struct drm_amdgpu_info_firmware fw_info; 1092*b843c749SSergey Zigachev struct drm_amdgpu_query_fw query_fw; 1093*b843c749SSergey Zigachev struct atom_context *ctx = adev->mode_info.atom_context; 1094*b843c749SSergey Zigachev int ret, i; 1095*b843c749SSergey Zigachev 1096*b843c749SSergey Zigachev /* VCE */ 1097*b843c749SSergey Zigachev query_fw.fw_type = AMDGPU_INFO_FW_VCE; 1098*b843c749SSergey Zigachev ret = amdgpu_firmware_info(&fw_info, &query_fw, adev); 1099*b843c749SSergey Zigachev if (ret) 1100*b843c749SSergey Zigachev return ret; 1101*b843c749SSergey Zigachev seq_printf(m, "VCE feature version: %u, firmware version: 0x%08x\n", 1102*b843c749SSergey Zigachev fw_info.feature, fw_info.ver); 1103*b843c749SSergey Zigachev 1104*b843c749SSergey Zigachev /* UVD */ 1105*b843c749SSergey Zigachev query_fw.fw_type = AMDGPU_INFO_FW_UVD; 1106*b843c749SSergey Zigachev ret = amdgpu_firmware_info(&fw_info, &query_fw, adev); 1107*b843c749SSergey Zigachev if (ret) 1108*b843c749SSergey Zigachev return ret; 1109*b843c749SSergey Zigachev seq_printf(m, "UVD feature version: %u, firmware version: 0x%08x\n", 1110*b843c749SSergey Zigachev fw_info.feature, fw_info.ver); 1111*b843c749SSergey Zigachev 1112*b843c749SSergey Zigachev /* GMC */ 1113*b843c749SSergey Zigachev query_fw.fw_type = AMDGPU_INFO_FW_GMC; 1114*b843c749SSergey Zigachev ret = amdgpu_firmware_info(&fw_info, &query_fw, adev); 1115*b843c749SSergey Zigachev if (ret) 1116*b843c749SSergey Zigachev return ret; 1117*b843c749SSergey Zigachev seq_printf(m, "MC feature version: %u, firmware version: 0x%08x\n", 1118*b843c749SSergey Zigachev fw_info.feature, fw_info.ver); 1119*b843c749SSergey Zigachev 1120*b843c749SSergey Zigachev /* ME */ 1121*b843c749SSergey Zigachev query_fw.fw_type = AMDGPU_INFO_FW_GFX_ME; 1122*b843c749SSergey Zigachev ret = amdgpu_firmware_info(&fw_info, &query_fw, adev); 1123*b843c749SSergey Zigachev if (ret) 1124*b843c749SSergey Zigachev return ret; 1125*b843c749SSergey Zigachev seq_printf(m, "ME feature version: %u, firmware version: 0x%08x\n", 1126*b843c749SSergey Zigachev fw_info.feature, fw_info.ver); 1127*b843c749SSergey Zigachev 1128*b843c749SSergey Zigachev /* PFP */ 1129*b843c749SSergey Zigachev query_fw.fw_type = AMDGPU_INFO_FW_GFX_PFP; 1130*b843c749SSergey Zigachev ret = amdgpu_firmware_info(&fw_info, &query_fw, adev); 1131*b843c749SSergey Zigachev if (ret) 1132*b843c749SSergey Zigachev return ret; 1133*b843c749SSergey Zigachev seq_printf(m, "PFP feature version: %u, firmware version: 0x%08x\n", 1134*b843c749SSergey Zigachev fw_info.feature, fw_info.ver); 1135*b843c749SSergey Zigachev 1136*b843c749SSergey Zigachev /* CE */ 1137*b843c749SSergey Zigachev query_fw.fw_type = AMDGPU_INFO_FW_GFX_CE; 1138*b843c749SSergey Zigachev ret = amdgpu_firmware_info(&fw_info, &query_fw, adev); 1139*b843c749SSergey Zigachev if (ret) 1140*b843c749SSergey Zigachev return ret; 1141*b843c749SSergey Zigachev seq_printf(m, "CE feature version: %u, firmware version: 0x%08x\n", 1142*b843c749SSergey Zigachev fw_info.feature, fw_info.ver); 1143*b843c749SSergey Zigachev 1144*b843c749SSergey Zigachev /* RLC */ 1145*b843c749SSergey Zigachev query_fw.fw_type = AMDGPU_INFO_FW_GFX_RLC; 1146*b843c749SSergey Zigachev ret = amdgpu_firmware_info(&fw_info, &query_fw, adev); 1147*b843c749SSergey Zigachev if (ret) 1148*b843c749SSergey Zigachev return ret; 1149*b843c749SSergey Zigachev seq_printf(m, "RLC feature version: %u, firmware version: 0x%08x\n", 1150*b843c749SSergey Zigachev fw_info.feature, fw_info.ver); 1151*b843c749SSergey Zigachev 1152*b843c749SSergey Zigachev /* RLC SAVE RESTORE LIST CNTL */ 1153*b843c749SSergey Zigachev query_fw.fw_type = AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_CNTL; 1154*b843c749SSergey Zigachev ret = amdgpu_firmware_info(&fw_info, &query_fw, adev); 1155*b843c749SSergey Zigachev if (ret) 1156*b843c749SSergey Zigachev return ret; 1157*b843c749SSergey Zigachev seq_printf(m, "RLC SRLC feature version: %u, firmware version: 0x%08x\n", 1158*b843c749SSergey Zigachev fw_info.feature, fw_info.ver); 1159*b843c749SSergey Zigachev 1160*b843c749SSergey Zigachev /* RLC SAVE RESTORE LIST GPM MEM */ 1161*b843c749SSergey Zigachev query_fw.fw_type = AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_GPM_MEM; 1162*b843c749SSergey Zigachev ret = amdgpu_firmware_info(&fw_info, &query_fw, adev); 1163*b843c749SSergey Zigachev if (ret) 1164*b843c749SSergey Zigachev return ret; 1165*b843c749SSergey Zigachev seq_printf(m, "RLC SRLG feature version: %u, firmware version: 0x%08x\n", 1166*b843c749SSergey Zigachev fw_info.feature, fw_info.ver); 1167*b843c749SSergey Zigachev 1168*b843c749SSergey Zigachev /* RLC SAVE RESTORE LIST SRM MEM */ 1169*b843c749SSergey Zigachev query_fw.fw_type = AMDGPU_INFO_FW_GFX_RLC_RESTORE_LIST_SRM_MEM; 1170*b843c749SSergey Zigachev ret = amdgpu_firmware_info(&fw_info, &query_fw, adev); 1171*b843c749SSergey Zigachev if (ret) 1172*b843c749SSergey Zigachev return ret; 1173*b843c749SSergey Zigachev seq_printf(m, "RLC SRLS feature version: %u, firmware version: 0x%08x\n", 1174*b843c749SSergey Zigachev fw_info.feature, fw_info.ver); 1175*b843c749SSergey Zigachev 1176*b843c749SSergey Zigachev /* MEC */ 1177*b843c749SSergey Zigachev query_fw.fw_type = AMDGPU_INFO_FW_GFX_MEC; 1178*b843c749SSergey Zigachev query_fw.index = 0; 1179*b843c749SSergey Zigachev ret = amdgpu_firmware_info(&fw_info, &query_fw, adev); 1180*b843c749SSergey Zigachev if (ret) 1181*b843c749SSergey Zigachev return ret; 1182*b843c749SSergey Zigachev seq_printf(m, "MEC feature version: %u, firmware version: 0x%08x\n", 1183*b843c749SSergey Zigachev fw_info.feature, fw_info.ver); 1184*b843c749SSergey Zigachev 1185*b843c749SSergey Zigachev /* MEC2 */ 1186*b843c749SSergey Zigachev if (adev->asic_type == CHIP_KAVERI || 1187*b843c749SSergey Zigachev (adev->asic_type > CHIP_TOPAZ && adev->asic_type != CHIP_STONEY)) { 1188*b843c749SSergey Zigachev query_fw.index = 1; 1189*b843c749SSergey Zigachev ret = amdgpu_firmware_info(&fw_info, &query_fw, adev); 1190*b843c749SSergey Zigachev if (ret) 1191*b843c749SSergey Zigachev return ret; 1192*b843c749SSergey Zigachev seq_printf(m, "MEC2 feature version: %u, firmware version: 0x%08x\n", 1193*b843c749SSergey Zigachev fw_info.feature, fw_info.ver); 1194*b843c749SSergey Zigachev } 1195*b843c749SSergey Zigachev 1196*b843c749SSergey Zigachev /* PSP SOS */ 1197*b843c749SSergey Zigachev query_fw.fw_type = AMDGPU_INFO_FW_SOS; 1198*b843c749SSergey Zigachev ret = amdgpu_firmware_info(&fw_info, &query_fw, adev); 1199*b843c749SSergey Zigachev if (ret) 1200*b843c749SSergey Zigachev return ret; 1201*b843c749SSergey Zigachev seq_printf(m, "SOS feature version: %u, firmware version: 0x%08x\n", 1202*b843c749SSergey Zigachev fw_info.feature, fw_info.ver); 1203*b843c749SSergey Zigachev 1204*b843c749SSergey Zigachev 1205*b843c749SSergey Zigachev /* PSP ASD */ 1206*b843c749SSergey Zigachev query_fw.fw_type = AMDGPU_INFO_FW_ASD; 1207*b843c749SSergey Zigachev ret = amdgpu_firmware_info(&fw_info, &query_fw, adev); 1208*b843c749SSergey Zigachev if (ret) 1209*b843c749SSergey Zigachev return ret; 1210*b843c749SSergey Zigachev seq_printf(m, "ASD feature version: %u, firmware version: 0x%08x\n", 1211*b843c749SSergey Zigachev fw_info.feature, fw_info.ver); 1212*b843c749SSergey Zigachev 1213*b843c749SSergey Zigachev /* SMC */ 1214*b843c749SSergey Zigachev query_fw.fw_type = AMDGPU_INFO_FW_SMC; 1215*b843c749SSergey Zigachev ret = amdgpu_firmware_info(&fw_info, &query_fw, adev); 1216*b843c749SSergey Zigachev if (ret) 1217*b843c749SSergey Zigachev return ret; 1218*b843c749SSergey Zigachev seq_printf(m, "SMC feature version: %u, firmware version: 0x%08x\n", 1219*b843c749SSergey Zigachev fw_info.feature, fw_info.ver); 1220*b843c749SSergey Zigachev 1221*b843c749SSergey Zigachev /* SDMA */ 1222*b843c749SSergey Zigachev query_fw.fw_type = AMDGPU_INFO_FW_SDMA; 1223*b843c749SSergey Zigachev for (i = 0; i < adev->sdma.num_instances; i++) { 1224*b843c749SSergey Zigachev query_fw.index = i; 1225*b843c749SSergey Zigachev ret = amdgpu_firmware_info(&fw_info, &query_fw, adev); 1226*b843c749SSergey Zigachev if (ret) 1227*b843c749SSergey Zigachev return ret; 1228*b843c749SSergey Zigachev seq_printf(m, "SDMA%d feature version: %u, firmware version: 0x%08x\n", 1229*b843c749SSergey Zigachev i, fw_info.feature, fw_info.ver); 1230*b843c749SSergey Zigachev } 1231*b843c749SSergey Zigachev 1232*b843c749SSergey Zigachev /* VCN */ 1233*b843c749SSergey Zigachev query_fw.fw_type = AMDGPU_INFO_FW_VCN; 1234*b843c749SSergey Zigachev ret = amdgpu_firmware_info(&fw_info, &query_fw, adev); 1235*b843c749SSergey Zigachev if (ret) 1236*b843c749SSergey Zigachev return ret; 1237*b843c749SSergey Zigachev seq_printf(m, "VCN feature version: %u, firmware version: 0x%08x\n", 1238*b843c749SSergey Zigachev fw_info.feature, fw_info.ver); 1239*b843c749SSergey Zigachev 1240*b843c749SSergey Zigachev 1241*b843c749SSergey Zigachev seq_printf(m, "VBIOS version: %s\n", ctx->vbios_version); 1242*b843c749SSergey Zigachev 1243*b843c749SSergey Zigachev return 0; 1244*b843c749SSergey Zigachev } 1245*b843c749SSergey Zigachev 1246*b843c749SSergey Zigachev static const struct drm_info_list amdgpu_firmware_info_list[] = { 1247*b843c749SSergey Zigachev {"amdgpu_firmware_info", amdgpu_debugfs_firmware_info, 0, NULL}, 1248*b843c749SSergey Zigachev }; 1249*b843c749SSergey Zigachev #endif 1250*b843c749SSergey Zigachev 1251*b843c749SSergey Zigachev int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev) 1252*b843c749SSergey Zigachev { 1253*b843c749SSergey Zigachev #if defined(CONFIG_DEBUG_FS) 1254*b843c749SSergey Zigachev return amdgpu_debugfs_add_files(adev, amdgpu_firmware_info_list, 1255*b843c749SSergey Zigachev ARRAY_SIZE(amdgpu_firmware_info_list)); 1256*b843c749SSergey Zigachev #else 1257*b843c749SSergey Zigachev return 0; 1258*b843c749SSergey Zigachev #endif 1259*b843c749SSergey Zigachev } 1260