Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu:changes of virtualization cases probe (v3)

1,Changes on virtualization detections
2,Don't load smu & mc firmware if using sr-iov bios
3,skip vPost for sriov & force vPost if dev pass-through

v2: agd: squash in Rays's fix for the missed SI case
v3: agd: squash in additional fixes for CIK, SI, cleanup

Signed-off-by: Monk Liu <Monk.Liu@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Monk Liu and committed by
Alex Deucher
4e99a44e ecab7668

+81 -55
+28 -8
drivers/gpu/drm/amd/amdgpu/amdgpu.h
··· 1827 1827 bool (*read_disabled_bios)(struct amdgpu_device *adev); 1828 1828 bool (*read_bios_from_rom)(struct amdgpu_device *adev, 1829 1829 u8 *bios, u32 length_bytes); 1830 + void (*detect_hw_virtualization) (struct amdgpu_device *adev); 1830 1831 int (*read_register)(struct amdgpu_device *adev, u32 se_num, 1831 1832 u32 sh_num, u32 reg_offset, u32 *value); 1832 1833 void (*set_vga_state)(struct amdgpu_device *adev, bool state); ··· 1837 1836 /* MM block clocks */ 1838 1837 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk); 1839 1838 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk); 1840 - /* query virtual capabilities */ 1841 - u32 (*get_virtual_caps)(struct amdgpu_device *adev); 1842 1839 /* static power management */ 1843 1840 int (*get_pcie_lanes)(struct amdgpu_device *adev); 1844 1841 void (*set_pcie_lanes)(struct amdgpu_device *adev, int lanes); ··· 1933 1934 void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device); 1934 1935 1935 1936 1937 + #define AMDGPU_SRIOV_CAPS_SRIOV_VBIOS (1 << 0) /* vBIOS is sr-iov ready */ 1938 + #define AMDGPU_SRIOV_CAPS_ENABLE_IOV (1 << 1) /* sr-iov is enabled on this GPU */ 1939 + #define AMDGPU_SRIOV_CAPS_IS_VF (1 << 2) /* this GPU is a virtual function */ 1940 + #define AMDGPU_PASSTHROUGH_MODE (1 << 3) /* thw whole GPU is pass through for VM */ 1936 1941 /* GPU virtualization */ 1937 - #define AMDGPU_VIRT_CAPS_SRIOV_EN (1 << 0) 1938 - #define AMDGPU_VIRT_CAPS_IS_VF (1 << 1) 1939 1942 struct amdgpu_virtualization { 1940 - bool supports_sr_iov; 1941 - bool is_virtual; 1942 - u32 caps; 1943 + uint32_t virtual_caps; 1943 1944 }; 1945 + 1946 + #define amdgpu_sriov_enabled(adev) \ 1947 + ((adev)->virtualization.virtual_caps & AMDGPU_SRIOV_CAPS_ENABLE_IOV) 1948 + 1949 + #define amdgpu_sriov_vf(adev) \ 1950 + ((adev)->virtualization.virtual_caps & AMDGPU_SRIOV_CAPS_IS_VF) 1951 + 1952 + #define amdgpu_sriov_bios(adev) \ 1953 + ((adev)->virtualization.virtual_caps & AMDGPU_SRIOV_CAPS_SRIOV_VBIOS) 1954 + 1955 + #define amdgpu_passthrough(adev) \ 1956 + ((adev)->virtualization.virtual_caps & AMDGPU_PASSTHROUGH_MODE) 1957 + 1958 + static inline bool is_virtual_machine(void) 1959 + { 1960 + #ifdef CONFIG_X86 1961 + return boot_cpu_has(X86_FEATURE_HYPERVISOR); 1962 + #else 1963 + return false; 1964 + #endif 1965 + } 1944 1966 1945 1967 /* 1946 1968 * Core structure, functions and helpers. ··· 2280 2260 #define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev)) 2281 2261 #define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d)) 2282 2262 #define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec)) 2283 - #define amdgpu_asic_get_virtual_caps(adev) ((adev)->asic_funcs->get_virtual_caps((adev))) 2284 2263 #define amdgpu_get_pcie_lanes(adev) (adev)->asic_funcs->get_pcie_lanes((adev)) 2285 2264 #define amdgpu_set_pcie_lanes(adev, l) (adev)->asic_funcs->set_pcie_lanes((adev), (l)) 2286 2265 #define amdgpu_asic_get_gpu_clock_counter(adev) (adev)->asic_funcs->get_gpu_clock_counter((adev)) 2287 2266 #define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev)) 2288 2267 #define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l)) 2268 + #define amdgpu_asic_detect_hw_virtualization(adev) (adev)->asic_funcs->detect_hw_virtualization((adev)) 2289 2269 #define amdgpu_asic_read_register(adev, se, sh, offset, v)((adev)->asic_funcs->read_register((adev), (se), (sh), (offset), (v))) 2290 2270 #define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid)) 2291 2271 #define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
+15 -18
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
··· 110 110 bool always_indirect) 111 111 { 112 112 trace_amdgpu_mm_wreg(adev->pdev->device, reg, v); 113 - 113 + 114 114 if ((reg * 4) < adev->rmmio_size && !always_indirect) 115 115 writel(v, ((void __iomem *)adev->rmmio) + (reg * 4)); 116 116 else { ··· 1485 1485 return 0; 1486 1486 } 1487 1487 1488 - static bool amdgpu_device_is_virtual(void) 1488 + static void amdgpu_device_detect_sriov_bios(struct amdgpu_device *adev) 1489 1489 { 1490 - #ifdef CONFIG_X86 1491 - return boot_cpu_has(X86_FEATURE_HYPERVISOR); 1492 - #else 1493 - return false; 1494 - #endif 1490 + if (amdgpu_atombios_has_gpu_virtualization_table(adev)) 1491 + adev->virtualization.virtual_caps |= AMDGPU_SRIOV_CAPS_SRIOV_VBIOS; 1495 1492 } 1496 1493 1497 1494 /** ··· 1645 1648 goto failed; 1646 1649 } 1647 1650 1648 - /* See if the asic supports SR-IOV */ 1649 - adev->virtualization.supports_sr_iov = 1650 - amdgpu_atombios_has_gpu_virtualization_table(adev); 1651 - 1652 - /* Check if we are executing in a virtualized environment */ 1653 - adev->virtualization.is_virtual = amdgpu_device_is_virtual(); 1654 - adev->virtualization.caps = amdgpu_asic_get_virtual_caps(adev); 1651 + /* detect if we are with an SRIOV vbios */ 1652 + amdgpu_device_detect_sriov_bios(adev); 1655 1653 1656 1654 /* Post card if necessary */ 1657 - if (!amdgpu_card_posted(adev) || 1658 - (adev->virtualization.is_virtual && 1659 - !(adev->virtualization.caps & AMDGPU_VIRT_CAPS_SRIOV_EN))) { 1655 + if (!amdgpu_sriov_vf(adev) && 1656 + (!amdgpu_card_posted(adev) || amdgpu_passthrough(adev))) { 1660 1657 if (!adev->bios) { 1661 1658 dev_err(adev->dev, "Card not posted and no BIOS - ignoring\n"); 1662 1659 r = -EINVAL; 1663 1660 goto failed; 1664 1661 } 1665 1662 DRM_INFO("GPU not posted. posting now...\n"); 1666 - amdgpu_atom_asic_init(adev->mode_info.atom_context); 1663 + r = amdgpu_atom_asic_init(adev->mode_info.atom_context); 1664 + if (r) { 1665 + dev_err(adev->dev, "gpu post error!\n"); 1666 + goto failed; 1667 + } 1668 + } else { 1669 + DRM_INFO("GPU post is not needed\n"); 1667 1670 } 1668 1671 1669 1672 /* Initialize clocks */
+1 -1
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
··· 485 485 /* if we are running in a VM, make sure the device 486 486 * torn down properly on reboot/shutdown 487 487 */ 488 - if (adev->virtualization.is_virtual) 488 + if (amdgpu_passthrough(adev)) 489 489 amdgpu_pci_remove(pdev); 490 490 } 491 491
+7 -7
drivers/gpu/drm/amd/amdgpu/cik.c
··· 963 963 return true; 964 964 } 965 965 966 - static u32 cik_get_virtual_caps(struct amdgpu_device *adev) 967 - { 968 - /* CIK does not support SR-IOV */ 969 - return 0; 970 - } 971 - 972 966 static const struct amdgpu_allowed_register_entry cik_allowed_read_registers[] = { 973 967 {mmGRBM_STATUS, false}, 974 968 {mmGB_ADDR_CONFIG, false}, ··· 1633 1639 { 1634 1640 return (RREG32(mmCC_DRM_ID_STRAPS) & CC_DRM_ID_STRAPS__ATI_REV_ID_MASK) 1635 1641 >> CC_DRM_ID_STRAPS__ATI_REV_ID__SHIFT; 1642 + } 1643 + 1644 + static void cik_detect_hw_virtualization(struct amdgpu_device *adev) 1645 + { 1646 + if (is_virtual_machine()) /* passthrough mode */ 1647 + adev->virtualization.virtual_caps |= AMDGPU_PASSTHROUGH_MODE; 1636 1648 } 1637 1649 1638 1650 static const struct amdgpu_ip_block_version bonaire_ip_blocks[] = ··· 2384 2384 { 2385 2385 .read_disabled_bios = &cik_read_disabled_bios, 2386 2386 .read_bios_from_rom = &cik_read_bios_from_rom, 2387 + .detect_hw_virtualization = cik_detect_hw_virtualization, 2387 2388 .read_register = &cik_read_register, 2388 2389 .reset = &cik_asic_reset, 2389 2390 .set_vga_state = &cik_vga_set_state, 2390 2391 .get_xclk = &cik_get_xclk, 2391 2392 .set_uvd_clocks = &cik_set_uvd_clocks, 2392 2393 .set_vce_clocks = &cik_set_vce_clocks, 2393 - .get_virtual_caps = &cik_get_virtual_caps, 2394 2394 }; 2395 2395 2396 2396 static int cik_common_early_init(void *handle)
+1 -1
drivers/gpu/drm/amd/amdgpu/fiji_smc.c
··· 275 275 /* Skip SMC ucode loading on SR-IOV capable boards. 276 276 * vbios does this for us in asic_init in that case. 277 277 */ 278 - if (adev->virtualization.supports_sr_iov) 278 + if (amdgpu_sriov_bios(adev)) 279 279 return 0; 280 280 281 281 hdr = (const struct smc_firmware_header_v1_0 *)adev->pm.fw->data;
+3 -1
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
··· 261 261 262 262 /* Skip MC ucode loading on SR-IOV capable boards. 263 263 * vbios does this for us in asic_init in that case. 264 + * Skip MC ucode loading on VF, because hypervisor will do that 265 + * for this adaptor. 264 266 */ 265 - if (adev->virtualization.supports_sr_iov) 267 + if (amdgpu_sriov_bios(adev)) 266 268 return 0; 267 269 268 270 hdr = (const struct mc_firmware_header_v1_0 *)adev->mc.fw->data;
+1 -1
drivers/gpu/drm/amd/amdgpu/iceland_smc.c
··· 282 282 /* Skip SMC ucode loading on SR-IOV capable boards. 283 283 * vbios does this for us in asic_init in that case. 284 284 */ 285 - if (adev->virtualization.supports_sr_iov) 285 + if (amdgpu_sriov_bios(adev)) 286 286 return 0; 287 287 288 288 hdr = (const struct smc_firmware_header_v1_0 *)adev->pm.fw->data;
+7 -7
drivers/gpu/drm/amd/amdgpu/si.c
··· 952 952 spin_unlock_irqrestore(&adev->smc_idx_lock, flags); 953 953 } 954 954 955 - static u32 si_get_virtual_caps(struct amdgpu_device *adev) 956 - { 957 - /* SI does not support SR-IOV */ 958 - return 0; 959 - } 960 - 961 955 static struct amdgpu_allowed_register_entry si_allowed_read_registers[] = { 962 956 {GRBM_STATUS, false}, 963 957 {GB_ADDR_CONFIG, false}, ··· 1118 1124 return 0; 1119 1125 } 1120 1126 1127 + static void si_detect_hw_virtualization(struct amdgpu_device *adev) 1128 + { 1129 + if (is_virtual_machine()) /* passthrough mode */ 1130 + adev->virtualization.virtual_caps |= AMDGPU_PASSTHROUGH_MODE; 1131 + } 1132 + 1121 1133 static const struct amdgpu_asic_funcs si_asic_funcs = 1122 1134 { 1123 1135 .read_disabled_bios = &si_read_disabled_bios, 1136 + .detect_hw_virtualization = si_detect_hw_virtualization, 1124 1137 .read_register = &si_read_register, 1125 1138 .reset = &si_asic_reset, 1126 1139 .set_vga_state = &si_vga_set_state, 1127 1140 .get_xclk = &si_get_xclk, 1128 1141 .set_uvd_clocks = &si_set_uvd_clocks, 1129 1142 .set_vce_clocks = NULL, 1130 - .get_virtual_caps = &si_get_virtual_caps, 1131 1143 }; 1132 1144 1133 1145 static uint32_t si_get_rev_id(struct amdgpu_device *adev)
+1 -1
drivers/gpu/drm/amd/amdgpu/tonga_smc.c
··· 275 275 /* Skip SMC ucode loading on SR-IOV capable boards. 276 276 * vbios does this for us in asic_init in that case. 277 277 */ 278 - if (adev->virtualization.supports_sr_iov) 278 + if (amdgpu_sriov_bios(adev)) 279 279 return 0; 280 280 281 281 hdr = (const struct smc_firmware_header_v1_0 *)adev->pm.fw->data;
+17 -10
drivers/gpu/drm/amd/amdgpu/vi.c
··· 445 445 return true; 446 446 } 447 447 448 - static u32 vi_get_virtual_caps(struct amdgpu_device *adev) 448 + static void vi_detect_hw_virtualization(struct amdgpu_device *adev) 449 449 { 450 - u32 caps = 0; 451 - u32 reg = RREG32(mmBIF_IOV_FUNC_IDENTIFIER); 450 + uint32_t reg = RREG32(mmBIF_IOV_FUNC_IDENTIFIER); 451 + /* bit0: 0 means pf and 1 means vf */ 452 + /* bit31: 0 means disable IOV and 1 means enable */ 453 + if (reg & 1) 454 + adev->virtualization.virtual_caps |= AMDGPU_SRIOV_CAPS_IS_VF; 452 455 453 - if (REG_GET_FIELD(reg, BIF_IOV_FUNC_IDENTIFIER, IOV_ENABLE)) 454 - caps |= AMDGPU_VIRT_CAPS_SRIOV_EN; 456 + if (reg & 0x80000000) 457 + adev->virtualization.virtual_caps |= AMDGPU_SRIOV_CAPS_ENABLE_IOV; 455 458 456 - if (REG_GET_FIELD(reg, BIF_IOV_FUNC_IDENTIFIER, FUNC_IDENTIFIER)) 457 - caps |= AMDGPU_VIRT_CAPS_IS_VF; 458 - 459 - return caps; 459 + if (reg == 0) { 460 + if (is_virtual_machine()) /* passthrough mode exclus sr-iov mode */ 461 + adev->virtualization.virtual_caps |= AMDGPU_PASSTHROUGH_MODE; 462 + } 460 463 } 461 464 462 465 static const struct amdgpu_allowed_register_entry tonga_allowed_read_registers[] = { ··· 1524 1521 { 1525 1522 .read_disabled_bios = &vi_read_disabled_bios, 1526 1523 .read_bios_from_rom = &vi_read_bios_from_rom, 1524 + .detect_hw_virtualization = vi_detect_hw_virtualization, 1527 1525 .read_register = &vi_read_register, 1528 1526 .reset = &vi_asic_reset, 1529 1527 .set_vga_state = &vi_vga_set_state, 1530 1528 .get_xclk = &vi_get_xclk, 1531 1529 .set_uvd_clocks = &vi_set_uvd_clocks, 1532 1530 .set_vce_clocks = &vi_set_vce_clocks, 1533 - .get_virtual_caps = &vi_get_virtual_caps, 1534 1531 }; 1535 1532 1536 1533 static int vi_common_early_init(void *handle) ··· 1659 1656 /* FIXME: not supported yet */ 1660 1657 return -EINVAL; 1661 1658 } 1659 + 1660 + /* in early init stage, vbios code won't work */ 1661 + if (adev->asic_funcs->detect_hw_virtualization) 1662 + amdgpu_asic_detect_hw_virtualization(adev); 1662 1663 1663 1664 if (amdgpu_smc_load_fw && smc_enabled) 1664 1665 adev->firmware.smu_load = true;