From cd0f69e64377e6460185cbc55cd6bfa7966c2ff4 Mon Sep 17 00:00:00 2001 From: purplerain Date: Tue, 12 Mar 2024 06:37:44 +0000 Subject: [PATCH] sync with OpenBSD -current --- sys/arch/amd64/amd64/vmm_machdep.c | 71 ++++++++++++++----- sys/conf/newvers.sh | 8 +-- .../amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 6 +- .../pci/drm/amd/pm/legacy-dpm/amdgpu_si_dpm.c | 29 ++++++++ sys/dev/pci/drm/drm_buddy.c | 10 +++ 5 files changed, 101 insertions(+), 23 deletions(-) diff --git a/sys/arch/amd64/amd64/vmm_machdep.c b/sys/arch/amd64/amd64/vmm_machdep.c index e3abe2f72..d94fa95ae 100644 --- a/sys/arch/amd64/amd64/vmm_machdep.c +++ b/sys/arch/amd64/amd64/vmm_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm_machdep.c,v 1.20 2024/02/29 16:10:52 guenther Exp $ */ +/* $OpenBSD: vmm_machdep.c,v 1.21 2024/03/12 02:31:15 guenther Exp $ */ /* * Copyright (c) 2014 Mike Larkin * @@ -6017,6 +6017,58 @@ svm_handle_msr(struct vcpu *vcpu) return (0); } +/* Handle cpuid(0xd) and its subleafs */ +static void +vmm_handle_cpuid_0xd(struct vcpu *vcpu, uint32_t subleaf, uint64_t *rax, + uint32_t eax, uint32_t ebx, uint32_t ecx, uint32_t edx) +{ + if (subleaf == 0) { + /* + * CPUID(0xd.0) depends on the value in XCR0 and MSR_XSS. If + * the guest XCR0 isn't the same as the host then set it, redo + * the CPUID, and restore it. + */ + uint64_t xcr0 = vcpu->vc_gueststate.vg_xcr0; + + /* + * "ecx enumerates the size required ... for an area + * containing all the ... components supported by this + * processor" + * "ebx enumerates the size required ... for an area + * containing all the ... components corresponding to bits + * currently set in xcr0" + * So: since the VMM 'processor' is what our base kernel uses, + * the VMM ecx is our ebx + */ + ecx = ebx; + if (xcr0 != (xsave_mask & XFEATURE_XCR0_MASK)) { + uint32_t dummy; + xsetbv(0, xcr0); + CPUID_LEAF(0xd, subleaf, eax, ebx, dummy, edx); + xsetbv(0, xsave_mask & XFEATURE_XCR0_MASK); + } + eax = xsave_mask & XFEATURE_XCR0_MASK; + edx = (xsave_mask & XFEATURE_XCR0_MASK) >> 32; + } else if (subleaf == 1) { + /* mask out XSAVEC, XSAVES, and XFD support */ + eax &= XSAVE_XSAVEOPT | XSAVE_XGETBV1; + ebx = 0; /* no xsavec or xsaves for now */ + ecx = edx = 0; /* no xsaves for now */ + } else if (subleaf >= 63 || + ((1ULL << subleaf) & xsave_mask & XFEATURE_XCR0_MASK) == 0) { + /* disclaim subleaves of features we don't expose */ + eax = ebx = ecx = edx = 0; + } else { + /* disclaim compressed alignment or xfd support */ + ecx = 0; + } + + *rax = eax; + vcpu->vc_gueststate.vg_rbx = ebx; + vcpu->vc_gueststate.vg_rcx = ecx; + vcpu->vc_gueststate.vg_rdx = edx; +} + /* * vmm_handle_cpuid * @@ -6227,22 +6279,7 @@ vmm_handle_cpuid(struct vcpu *vcpu) *rdx = 0; break; case 0x0d: /* Processor ext. state information */ - if (subleaf == 0) { - *rax = xsave_mask; - *rbx = ebx; - *rcx = ecx; - *rdx = edx; - } else if (subleaf == 1) { - *rax = 0; - *rbx = 0; - *rcx = 0; - *rdx = 0; - } else { - *rax = eax; - *rbx = ebx; - *rcx = ecx; - *rdx = edx; - } + vmm_handle_cpuid_0xd(vcpu, subleaf, rax, eax, ebx, ecx, edx); break; case 0x0f: /* QoS info (not supported) */ DPRINTF("%s: function 0x0f (QoS info) not supported\n", diff --git a/sys/conf/newvers.sh b/sys/conf/newvers.sh index 1c112c112..d8e897002 100644 --- a/sys/conf/newvers.sh +++ b/sys/conf/newvers.sh @@ -1,6 +1,6 @@ #!/bin/sh - # -# $OpenBSD: newvers.sh,v 1.202 2024/02/29 17:05:10 deraadt Exp $ +# $OpenBSD: newvers.sh,v 1.203 2024/03/12 01:20:30 deraadt Exp $ # $NetBSD: newvers.sh,v 1.17.2.1 1995/10/12 05:17:11 jtc Exp $ # # Copyright (c) 1984, 1986, 1990, 1993 @@ -71,10 +71,10 @@ ost="SecBSD" osr="1.5" cat >vers.c <panel_patch.remove_sink_ext_caps = true; break; @@ -119,6 +121,8 @@ enum dc_edid_status dm_helpers_parse_edid_caps( edid_caps->edid_hdmi = connector->display_info.is_hdmi; + apply_edid_quirks(edid_buf, edid_caps); + sad_count = drm_edid_to_sad((struct edid *) edid->raw_edid, &sads); if (sad_count <= 0) return result; @@ -145,8 +149,6 @@ enum dc_edid_status dm_helpers_parse_edid_caps( else edid_caps->speaker_flags = DEFAULT_SPEAKER_LOCATION; - apply_edid_quirks(edid_buf, edid_caps); - kfree(sads); kfree(sadb); diff --git a/sys/dev/pci/drm/amd/pm/legacy-dpm/amdgpu_si_dpm.c b/sys/dev/pci/drm/amd/pm/legacy-dpm/amdgpu_si_dpm.c index f81e4bd48..99dde52a4 100644 --- a/sys/dev/pci/drm/amd/pm/legacy-dpm/amdgpu_si_dpm.c +++ b/sys/dev/pci/drm/amd/pm/legacy-dpm/amdgpu_si_dpm.c @@ -6925,6 +6925,23 @@ static int si_dpm_enable(struct amdgpu_device *adev) return 0; } +static int si_set_temperature_range(struct amdgpu_device *adev) +{ + int ret; + + ret = si_thermal_enable_alert(adev, false); + if (ret) + return ret; + ret = si_thermal_set_temperature_range(adev, R600_TEMP_RANGE_MIN, R600_TEMP_RANGE_MAX); + if (ret) + return ret; + ret = si_thermal_enable_alert(adev, true); + if (ret) + return ret; + + return ret; +} + static void si_dpm_disable(struct amdgpu_device *adev) { struct rv7xx_power_info *pi = rv770_get_pi(adev); @@ -7608,6 +7625,18 @@ static int si_dpm_process_interrupt(struct amdgpu_device *adev, static int si_dpm_late_init(void *handle) { + int ret; + struct amdgpu_device *adev = (struct amdgpu_device *)handle; + + if (!adev->pm.dpm_enabled) + return 0; + + ret = si_set_temperature_range(adev); + if (ret) + return ret; +#if 0 //TODO ? + si_dpm_powergate_uvd(adev, true); +#endif return 0; } diff --git a/sys/dev/pci/drm/drm_buddy.c b/sys/dev/pci/drm/drm_buddy.c index 03457c65a..7d47a58a5 100644 --- a/sys/dev/pci/drm/drm_buddy.c +++ b/sys/dev/pci/drm/drm_buddy.c @@ -342,6 +342,7 @@ alloc_range_bias(struct drm_buddy *mm, u64 start, u64 end, unsigned int order) { + u64 req_size = mm->chunk_size << order; struct drm_buddy_block *block; struct drm_buddy_block *buddy; DRM_LIST_HEAD(dfs); @@ -377,6 +378,15 @@ alloc_range_bias(struct drm_buddy *mm, if (drm_buddy_block_is_allocated(block)) continue; + if (block_start < start || block_end > end) { + u64 adjusted_start = max(block_start, start); + u64 adjusted_end = min(block_end, end); + + if (round_down(adjusted_end + 1, req_size) <= + round_up(adjusted_start, req_size)) + continue; + } + if (contains(start, end, block_start, block_end) && order == drm_buddy_block_order(block)) { /*