// SPDX-License-Identifier: MIT /* * Copyright 2012 Advanced Micro Devices, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. *
*/
/** * amdgpu_atif_get_notification_params - determine notify configuration * * @atif: acpi handle * * Execute the ATIF_FUNCTION_GET_SYSTEM_PARAMETERS ATIF function * to determine if a notifier is used and if so which one * (all asics). This is either Notify(VGA, 0x81) or Notify(VGA, n) * where n is specified in the result if a notifier is used. * Returns 0 on success, error on failure.
*/ staticint amdgpu_atif_get_notification_params(struct amdgpu_atif *atif)
{ union acpi_object *info; struct amdgpu_atif_notification_cfg *n = &atif->notification_cfg; struct atif_system_params params;
size_t size; int err = 0;
info = amdgpu_atif_call(atif, ATIF_FUNCTION_GET_SYSTEM_PARAMETERS,
NULL); if (!info) {
err = -EIO; goto out;
}
/** * amdgpu_atif_query_backlight_caps - get min and max backlight input signal * * @atif: acpi handle * * Execute the QUERY_BRIGHTNESS_TRANSFER_CHARACTERISTICS ATIF function * to determine the acceptable range of backlight values * * Backlight_caps.caps_valid will be set to true if the query is successful * * The input signals are in range 0-255 * * This function assumes the display with backlight is the first LCD * * Returns 0 on success, error on failure.
*/ staticint amdgpu_atif_query_backlight_caps(struct amdgpu_atif *atif)
{ union acpi_object *info; struct atif_qbtc_output characteristics; struct atif_qbtc_arguments arguments; struct acpi_buffer params;
size_t size; int err = 0;
/** * amdgpu_atif_get_sbios_requests - get requested sbios event * * @atif: acpi handle * @req: atif sbios request struct * * Execute the ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS ATIF function * to determine what requests the sbios is making to the driver * (all asics). * Returns 0 on success, error on failure.
*/ staticint amdgpu_atif_get_sbios_requests(struct amdgpu_atif *atif, struct atif_sbios_requests *req)
{ union acpi_object *info;
size_t size; int count = 0;
info = amdgpu_atif_call(atif, ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS,
NULL); if (!info) return -EIO;
if (req.pending & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST) { if (atif->bd) {
DRM_DEBUG_DRIVER("Changing brightness to %d\n",
req.backlight_level); /* * XXX backlight_device_set_brightness() is * hardwired to post BACKLIGHT_UPDATE_SYSFS. * It probably should accept 'reason' parameter.
*/
backlight_device_set_brightness(atif->bd, req.backlight_level);
}
}
if (req.pending & ATIF_DGPU_DISPLAY_EVENT) { if (adev->flags & AMD_IS_PX) {
pm_runtime_get_sync(adev_to_drm(adev)->dev); /* Just fire off a uevent and let userspace tell us what to do */
drm_helper_hpd_irq_event(adev_to_drm(adev));
pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
}
} /* TODO: check other events */
}
/* We've handled the event, stop the notifier chain. The ACPI interface * overloads ACPI_VIDEO_NOTIFY_PROBE, we don't want to send that to * userspace if the event was generated only to signal a SBIOS * request.
*/ return NOTIFY_BAD;
}
/* Call the ATCS method
*/ /** * amdgpu_atcs_call - call an ATCS method * * @atcs: atcs structure * @function: the ATCS function to execute * @params: ATCS function params * * Executes the requested ATCS function (all asics). * Returns a pointer to the acpi output buffer.
*/ staticunion acpi_object *amdgpu_atcs_call(struct amdgpu_atcs *atcs, int function, struct acpi_buffer *params)
{
acpi_status status; union acpi_object atcs_arg_elements[2]; struct acpi_object_list atcs_arg; struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
if (params) {
atcs_arg_elements[1].type = ACPI_TYPE_BUFFER;
atcs_arg_elements[1].buffer.length = params->length;
atcs_arg_elements[1].buffer.pointer = params->pointer;
} else { /* We need a second fake parameter */
atcs_arg_elements[1].type = ACPI_TYPE_INTEGER;
atcs_arg_elements[1].integer.value = 0;
}
status = acpi_evaluate_object(atcs->handle, NULL, &atcs_arg, &buffer);
/* Fail only if calling the method fails and ATIF is supported */ if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
DRM_DEBUG_DRIVER("failed to evaluate ATCS got %s\n",
acpi_format_exception(status));
kfree(buffer.pointer); return NULL;
}
return buffer.pointer;
}
/** * amdgpu_atcs_parse_functions - parse supported functions * * @f: supported functions struct * @mask: supported functions mask from ATCS * * Use the supported functions mask from ATCS function * ATCS_FUNCTION_VERIFY_INTERFACE to determine what functions * are supported (all asics).
*/ staticvoid amdgpu_atcs_parse_functions(struct amdgpu_atcs_functions *f, u32 mask)
{
f->get_ext_state = mask & ATCS_GET_EXTERNAL_STATE_SUPPORTED;
f->pcie_perf_req = mask & ATCS_PCIE_PERFORMANCE_REQUEST_SUPPORTED;
f->pcie_dev_rdy = mask & ATCS_PCIE_DEVICE_READY_NOTIFICATION_SUPPORTED;
f->pcie_bus_width = mask & ATCS_SET_PCIE_BUS_WIDTH_SUPPORTED;
f->power_shift_control = mask & ATCS_SET_POWER_SHIFT_CONTROL_SUPPORTED;
}
/** * amdgpu_atcs_verify_interface - verify ATCS * * @atcs: amdgpu atcs struct * * Execute the ATCS_FUNCTION_VERIFY_INTERFACE ATCS function * to initialize ATCS and determine what features are supported * (all asics). * returns 0 on success, error on failure.
*/ staticint amdgpu_atcs_verify_interface(struct amdgpu_atcs *atcs)
{ union acpi_object *info; struct atcs_verify_interface output;
size_t size; int err = 0;
info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_VERIFY_INTERFACE, NULL); if (!info) return -EIO;
memset(&output, 0, sizeof(output));
size = *(u16 *) info->buffer.pointer; if (size < 8) {
DRM_INFO("ATCS buffer is too small: %zu\n", size);
err = -EINVAL; goto out;
}
size = min(sizeof(output), size);
memcpy(&output, info->buffer.pointer, size);
/* TODO: check version? */
DRM_DEBUG_DRIVER("ATCS version %u\n", output.version);
/** * amdgpu_acpi_is_pcie_performance_request_supported * * @adev: amdgpu_device pointer * * Check if the ATCS pcie_perf_req and pcie_dev_rdy methods * are supported (all asics). * returns true if supported, false if not.
*/ bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev)
{ struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;
if (atcs->functions.pcie_perf_req && atcs->functions.pcie_dev_rdy) returntrue;
returnfalse;
}
/** * amdgpu_acpi_is_power_shift_control_supported * * Check if the ATCS power shift control method * is supported. * returns true if supported, false if not.
*/ bool amdgpu_acpi_is_power_shift_control_supported(void)
{ return amdgpu_acpi_priv.atcs.functions.power_shift_control;
}
/** * amdgpu_acpi_pcie_notify_device_ready * * @adev: amdgpu_device pointer * * Executes the PCIE_DEVICE_READY_NOTIFICATION method * (all asics). * returns 0 on success, error on failure.
*/ int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev)
{ union acpi_object *info; struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;
if (!atcs->functions.pcie_dev_rdy) return -EINVAL;
info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_PCIE_DEVICE_READY_NOTIFICATION, NULL); if (!info) return -EIO;
kfree(info);
return 0;
}
/** * amdgpu_acpi_pcie_performance_request * * @adev: amdgpu_device pointer * @perf_req: requested perf level (pcie gen speed) * @advertise: set advertise caps flag if set * * Executes the PCIE_PERFORMANCE_REQUEST method to * change the pcie gen speed (all asics). * returns 0 on success, error on failure.
*/ int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
u8 perf_req, bool advertise)
{ union acpi_object *info; struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs; struct atcs_pref_req_input atcs_input; struct atcs_pref_req_output atcs_output; struct acpi_buffer params;
size_t size;
u32 retry = 3;
if (amdgpu_acpi_pcie_notify_device_ready(adev)) return -EINVAL;
if (!atcs->functions.pcie_perf_req) return -EINVAL;
atcs_input.size = sizeof(struct atcs_pref_req_input); /* client id (bit 2-0: func num, 7-3: dev num, 15-8: bus num) */
atcs_input.client_id = pci_dev_id(adev->pdev);
atcs_input.valid_flags_mask = ATCS_VALID_FLAGS_MASK;
atcs_input.flags = ATCS_WAIT_FOR_COMPLETION; if (advertise)
atcs_input.flags |= ATCS_ADVERTISE_CAPS;
atcs_input.req_type = ATCS_PCIE_LINK_SPEED;
atcs_input.perf_req = perf_req;
info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_POWER_SHIFT_CONTROL, ¶ms); if (!info) {
DRM_ERROR("ATCS PSC update failed\n"); return -EIO;
}
kfree(info); return 0;
}
/** * amdgpu_acpi_smart_shift_update - update dGPU device state to SBIOS * * @adev: amdgpu device pointer * @ss_state: current smart shift event * * returns 0 on success, * otherwise return error number.
*/ int amdgpu_acpi_smart_shift_update(struct amdgpu_device *adev, enum amdgpu_ss ss_state)
{ int r;
if (!amdgpu_device_supports_smart_shift(adev)) return 0;
switch (ss_state) { /* SBIOS trigger “stop”, “enable” and “start” at D0, Driver Operational. * SBIOS trigger “stop” at D3, Driver Not Operational. * SBIOS trigger “stop” and “disable” at D0, Driver NOT operational.
*/ case AMDGPU_SS_DRV_LOAD:
r = amdgpu_acpi_power_shift_control(adev,
AMDGPU_ATCS_PSC_DEV_STATE_D0,
AMDGPU_ATCS_PSC_DRV_STATE_OPR); break; case AMDGPU_SS_DEV_D0:
r = amdgpu_acpi_power_shift_control(adev,
AMDGPU_ATCS_PSC_DEV_STATE_D0,
AMDGPU_ATCS_PSC_DRV_STATE_OPR); break; case AMDGPU_SS_DEV_D3:
r = amdgpu_acpi_power_shift_control(adev,
AMDGPU_ATCS_PSC_DEV_STATE_D3_HOT,
AMDGPU_ATCS_PSC_DRV_STATE_NOT_OPR); break; case AMDGPU_SS_DRV_UNLOAD:
r = amdgpu_acpi_power_shift_control(adev,
AMDGPU_ATCS_PSC_DEV_STATE_D0,
AMDGPU_ATCS_PSC_DRV_STATE_NOT_OPR); break; default: return -EINVAL;
}
return r;
}
#ifdef CONFIG_ACPI_NUMA staticinline uint64_t amdgpu_acpi_get_numa_size(int nid)
{ /* This is directly using si_meminfo_node implementation as the * function is not exported.
*/ int zone_type;
uint64_t managed_pages = 0;
/** * amdgpu_acpi_get_node_id - obtain the NUMA node id for corresponding amdgpu * acpi device handle * * @handle: acpi handle * @numa_info: amdgpu_numa_info structure holding numa information * * Queries the ACPI interface to fetch the corresponding NUMA Node ID for a * given amdgpu acpi device. * * Returns ACPI STATUS OK with Node ID on success or the corresponding failure reason
*/ static acpi_status amdgpu_acpi_get_node_id(acpi_handle handle, struct amdgpu_numa_info **numa_info)
{ #ifdef CONFIG_ACPI_NUMA
u64 pxm;
acpi_status status;
if (!numa_info)
return_ACPI_STATUS(AE_ERROR);
status = acpi_evaluate_integer(handle, "_PXM", NULL, &pxm);
for (id = 0; id < AMD_XCC_MAX_HID; id++) {
sprintf(hid, "%s%d", "AMD", AMD_XCC_HID_START + id);
acpi_dev = acpi_dev_get_first_match_dev(hid, NULL, -1); /* These ACPI objects are expected to be in sequential order. If * one is not found, no need to check the rest.
*/ if (!acpi_dev) {
DRM_DEBUG_DRIVER("No matching acpi device found for %s",
hid); break;
}
xcc_info = kzalloc(sizeof(struct amdgpu_acpi_xcc_info),
GFP_KERNEL); if (!xcc_info) {
DRM_ERROR("Failed to allocate memory for xcc info\n"); return -ENOMEM;
}
/** * amdgpu_acpi_should_gpu_reset * * @adev: amdgpu_device_pointer * * returns true if should reset GPU, false if not
*/ bool amdgpu_acpi_should_gpu_reset(struct amdgpu_device *adev)
{ if ((adev->flags & AMD_IS_APU) &&
adev->gfx.imu.funcs) /* Not need to do mode2 reset for IMU enabled APUs */ returnfalse;
if ((adev->flags & AMD_IS_APU) &&
amdgpu_acpi_is_s3_active(adev)) returnfalse;
/* * amdgpu_acpi_detect - detect ACPI ATIF/ATCS methods * * Check if we have the ATIF/ATCS methods and populate * the structures in the driver.
*/ void amdgpu_acpi_detect(void)
{ struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif; struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs; struct pci_dev *pdev = NULL; int ret;
while ((pdev = pci_get_base_class(PCI_BASE_CLASS_DISPLAY, pdev))) { if ((pdev->class != PCI_CLASS_DISPLAY_VGA << 8) &&
(pdev->class != PCI_CLASS_DISPLAY_OTHER << 8)) continue;
if (!atif->handle)
amdgpu_atif_pci_probe_handle(pdev); if (!atcs->handle)
amdgpu_atcs_pci_probe_handle(pdev);
}
if (atif->functions.sbios_requests && !atif->functions.system_params) { /* XXX check this workraround, if sbios request function is * present we have to see how it's configured in the system * params
*/
atif->functions.system_params = true;
}
if (atif->functions.system_params) {
ret = amdgpu_atif_get_notification_params(atif); if (ret) {
DRM_DEBUG_DRIVER("Call to GET_SYSTEM_PARAMS failed: %d\n",
ret); /* Disable notification */
atif->notification_cfg.enabled = false;
}
}
if (atif->functions.query_backlight_transfer_characteristics) {
ret = amdgpu_atif_query_backlight_caps(atif); if (ret) {
DRM_DEBUG_DRIVER("Call to QUERY_BACKLIGHT_TRANSFER_CHARACTERISTICS failed: %d\n",
ret);
atif->backlight_caps.caps_valid = false;
}
} else {
atif->backlight_caps.caps_valid = false;
}
if (!(adev->pm.pp_feature & PP_GFXOFF_MASK)) returnfalse;
/* * If ACPI_FADT_LOW_POWER_S0 is not set in the FADT, it is generally * risky to do any special firmware-related preparations for entering * S0ix even though the system is suspending to idle, so return false * in that case.
*/ if (!(acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0)) {
dev_err_once(adev->dev, "Power consumption will be higher as BIOS has not been configured for suspend-to-idle.\n" "To use suspend-to-idle change the sleep mode in BIOS setup.\n"); returnfalse;
}
#if !IS_ENABLED(CONFIG_AMD_PMC)
dev_err_once(adev->dev, "Power consumption will be higher as the kernel has not been compiled with CONFIG_AMD_PMC.\n"); returnfalse; #else returntrue; #endif/* CONFIG_AMD_PMC */
} #endif/* CONFIG_SUSPEND */
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.