Path: blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
54335 views
// SPDX-License-Identifier: MIT1/*2* Copyright 2012 Advanced Micro Devices, Inc.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice shall be included in12* all copies or substantial portions of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR18* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,19* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR20* OTHER DEALINGS IN THE SOFTWARE.21*22*/2324#include <linux/pci.h>25#include <linux/acpi.h>26#include <linux/backlight.h>27#include <linux/slab.h>28#include <linux/xarray.h>29#include <linux/power_supply.h>30#include <linux/pm_runtime.h>31#include <linux/suspend.h>32#include <acpi/video.h>33#include <acpi/actbl.h>3435#include "amdgpu.h"36#include "amdgpu_pm.h"37#include "amdgpu_display.h"38#include "amd_acpi.h"39#include "atom.h"4041/* Declare GUID for AMD _DSM method for XCCs */42static const guid_t amd_xcc_dsm_guid = GUID_INIT(0x8267f5d5, 0xa556, 0x44f2,430xb8, 0xb4, 0x45, 0x56, 0x2e,440x8c, 0x5b, 0xec);4546#define AMD_XCC_HID_START 300047#define AMD_XCC_DSM_GET_NUM_FUNCS 048#define AMD_XCC_DSM_GET_SUPP_MODE 149#define AMD_XCC_DSM_GET_XCP_MODE 250#define AMD_XCC_DSM_GET_VF_XCC_MAPPING 451#define AMD_XCC_DSM_GET_TMR_INFO 552#define AMD_XCC_DSM_NUM_FUNCS 55354#define AMD_XCC_MAX_HID 245556struct xarray numa_info_xa;5758/* Encapsulates the XCD acpi object information */59struct amdgpu_acpi_xcc_info {60struct list_head list;61struct amdgpu_numa_info *numa_info;62uint8_t xcp_node;63uint8_t phy_id;64acpi_handle handle;65};6667struct amdgpu_acpi_dev_info {68struct list_head list;69struct list_head xcc_list;70uint32_t sbdf;71uint16_t supp_xcp_mode;72uint16_t xcp_mode;73uint16_t mem_mode;74uint64_t tmr_base;75uint64_t tmr_size;76};7778struct list_head amdgpu_acpi_dev_list;7980struct amdgpu_atif_notification_cfg {81bool enabled;82int command_code;83};8485struct amdgpu_atif_notifications {86bool thermal_state;87bool forced_power_state;88bool system_power_state;89bool brightness_change;90bool dgpu_display_event;91bool gpu_package_power_limit;92};9394struct amdgpu_atif_functions {95bool system_params;96bool sbios_requests;97bool temperature_change;98bool query_backlight_transfer_characteristics;99bool ready_to_undock;100bool external_gpu_information;101};102103struct amdgpu_atif {104acpi_handle handle;105106struct amdgpu_atif_notifications notifications;107struct amdgpu_atif_functions functions;108struct amdgpu_atif_notification_cfg notification_cfg;109struct backlight_device *bd;110struct amdgpu_dm_backlight_caps backlight_caps;111};112113struct amdgpu_atcs_functions {114bool get_ext_state;115bool pcie_perf_req;116bool pcie_dev_rdy;117bool pcie_bus_width;118bool get_uma_size;119bool power_shift_control;120bool set_uma_allocation_size;121};122123struct amdgpu_atcs {124acpi_handle handle;125126struct amdgpu_atcs_functions functions;127};128129static struct amdgpu_acpi_priv {130struct amdgpu_atif atif;131struct amdgpu_atcs atcs;132} amdgpu_acpi_priv;133134/* Call the ATIF method135*/136/**137* amdgpu_atif_call - call an ATIF method138*139* @atif: atif structure140* @function: the ATIF function to execute141* @params: ATIF function params142*143* Executes the requested ATIF function (all asics).144* Returns a pointer to the acpi output buffer.145*/146static union acpi_object *amdgpu_atif_call(struct amdgpu_atif *atif,147int function,148struct acpi_buffer *params)149{150acpi_status status;151union acpi_object *obj;152union acpi_object atif_arg_elements[2];153struct acpi_object_list atif_arg;154struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };155156atif_arg.count = 2;157atif_arg.pointer = &atif_arg_elements[0];158159atif_arg_elements[0].type = ACPI_TYPE_INTEGER;160atif_arg_elements[0].integer.value = function;161162if (params) {163atif_arg_elements[1].type = ACPI_TYPE_BUFFER;164atif_arg_elements[1].buffer.length = params->length;165atif_arg_elements[1].buffer.pointer = params->pointer;166} else {167/* We need a second fake parameter */168atif_arg_elements[1].type = ACPI_TYPE_INTEGER;169atif_arg_elements[1].integer.value = 0;170}171172status = acpi_evaluate_object(atif->handle, NULL, &atif_arg,173&buffer);174obj = (union acpi_object *)buffer.pointer;175176/* Fail if calling the method fails */177if (ACPI_FAILURE(status)) {178DRM_DEBUG_DRIVER("failed to evaluate ATIF got %s\n",179acpi_format_exception(status));180kfree(obj);181return NULL;182}183184if (obj->type != ACPI_TYPE_BUFFER) {185DRM_DEBUG_DRIVER("bad object returned from ATIF: %d\n",186obj->type);187kfree(obj);188return NULL;189}190191return obj;192}193194/**195* amdgpu_atif_parse_notification - parse supported notifications196*197* @n: supported notifications struct198* @mask: supported notifications mask from ATIF199*200* Use the supported notifications mask from ATIF function201* ATIF_FUNCTION_VERIFY_INTERFACE to determine what notifications202* are supported (all asics).203*/204static void amdgpu_atif_parse_notification(struct amdgpu_atif_notifications *n, u32 mask)205{206n->thermal_state = mask & ATIF_THERMAL_STATE_CHANGE_REQUEST_SUPPORTED;207n->forced_power_state = mask & ATIF_FORCED_POWER_STATE_CHANGE_REQUEST_SUPPORTED;208n->system_power_state = mask & ATIF_SYSTEM_POWER_SOURCE_CHANGE_REQUEST_SUPPORTED;209n->brightness_change = mask & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST_SUPPORTED;210n->dgpu_display_event = mask & ATIF_DGPU_DISPLAY_EVENT_SUPPORTED;211n->gpu_package_power_limit = mask & ATIF_GPU_PACKAGE_POWER_LIMIT_REQUEST_SUPPORTED;212}213214/**215* amdgpu_atif_parse_functions - parse supported functions216*217* @f: supported functions struct218* @mask: supported functions mask from ATIF219*220* Use the supported functions mask from ATIF function221* ATIF_FUNCTION_VERIFY_INTERFACE to determine what functions222* are supported (all asics).223*/224static void amdgpu_atif_parse_functions(struct amdgpu_atif_functions *f, u32 mask)225{226f->system_params = mask & ATIF_GET_SYSTEM_PARAMETERS_SUPPORTED;227f->sbios_requests = mask & ATIF_GET_SYSTEM_BIOS_REQUESTS_SUPPORTED;228f->temperature_change = mask & ATIF_TEMPERATURE_CHANGE_NOTIFICATION_SUPPORTED;229f->query_backlight_transfer_characteristics =230mask & ATIF_QUERY_BACKLIGHT_TRANSFER_CHARACTERISTICS_SUPPORTED;231f->ready_to_undock = mask & ATIF_READY_TO_UNDOCK_NOTIFICATION_SUPPORTED;232f->external_gpu_information = mask & ATIF_GET_EXTERNAL_GPU_INFORMATION_SUPPORTED;233}234235/**236* amdgpu_atif_verify_interface - verify ATIF237*238* @atif: amdgpu atif struct239*240* Execute the ATIF_FUNCTION_VERIFY_INTERFACE ATIF function241* to initialize ATIF and determine what features are supported242* (all asics).243* returns 0 on success, error on failure.244*/245static noinline_for_stack246int amdgpu_atif_verify_interface(struct amdgpu_atif *atif)247{248union acpi_object *info;249struct atif_verify_interface output;250size_t size;251int err = 0;252253info = amdgpu_atif_call(atif, ATIF_FUNCTION_VERIFY_INTERFACE, NULL);254if (!info)255return -EIO;256257memset(&output, 0, sizeof(output));258259size = *(u16 *) info->buffer.pointer;260if (size < 12) {261DRM_INFO("ATIF buffer is too small: %zu\n", size);262err = -EINVAL;263goto out;264}265size = min(sizeof(output), size);266267memcpy(&output, info->buffer.pointer, size);268269/* TODO: check version? */270DRM_DEBUG_DRIVER("ATIF version %u\n", output.version);271272amdgpu_atif_parse_notification(&atif->notifications, output.notification_mask);273amdgpu_atif_parse_functions(&atif->functions, output.function_bits);274275out:276kfree(info);277return err;278}279280/**281* amdgpu_atif_get_notification_params - determine notify configuration282*283* @atif: acpi handle284*285* Execute the ATIF_FUNCTION_GET_SYSTEM_PARAMETERS ATIF function286* to determine if a notifier is used and if so which one287* (all asics). This is either Notify(VGA, 0x81) or Notify(VGA, n)288* where n is specified in the result if a notifier is used.289* Returns 0 on success, error on failure.290*/291static noinline_for_stack292int amdgpu_atif_get_notification_params(struct amdgpu_atif *atif)293{294union acpi_object *info;295struct amdgpu_atif_notification_cfg *n = &atif->notification_cfg;296struct atif_system_params params;297size_t size;298int err = 0;299300info = amdgpu_atif_call(atif, ATIF_FUNCTION_GET_SYSTEM_PARAMETERS,301NULL);302if (!info) {303err = -EIO;304goto out;305}306307size = *(u16 *) info->buffer.pointer;308if (size < 10) {309err = -EINVAL;310goto out;311}312313memset(¶ms, 0, sizeof(params));314size = min(sizeof(params), size);315memcpy(¶ms, info->buffer.pointer, size);316317DRM_DEBUG_DRIVER("SYSTEM_PARAMS: mask = %#x, flags = %#x\n",318params.flags, params.valid_mask);319params.flags = params.flags & params.valid_mask;320321if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_NONE) {322n->enabled = false;323n->command_code = 0;324} else if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_81) {325n->enabled = true;326n->command_code = 0x81;327} else {328if (size < 11) {329err = -EINVAL;330goto out;331}332n->enabled = true;333n->command_code = params.command_code;334}335336out:337DRM_DEBUG_DRIVER("Notification %s, command code = %#x\n",338(n->enabled ? "enabled" : "disabled"),339n->command_code);340kfree(info);341return err;342}343344/**345* amdgpu_atif_query_backlight_caps - get min and max backlight input signal346*347* @atif: acpi handle348*349* Execute the QUERY_BRIGHTNESS_TRANSFER_CHARACTERISTICS ATIF function350* to determine the acceptable range of backlight values351*352* Backlight_caps.caps_valid will be set to true if the query is successful353*354* The input signals are in range 0-255355*356* This function assumes the display with backlight is the first LCD357*358* Returns 0 on success, error on failure.359*/360static noinline_for_stack361int amdgpu_atif_query_backlight_caps(struct amdgpu_atif *atif)362{363union acpi_object *info;364struct atif_qbtc_output characteristics;365struct atif_qbtc_arguments arguments;366struct acpi_buffer params;367size_t size;368int err = 0;369370arguments.size = sizeof(arguments);371arguments.requested_display = ATIF_QBTC_REQUEST_LCD1;372373params.length = sizeof(arguments);374params.pointer = (void *)&arguments;375376info = amdgpu_atif_call(atif,377ATIF_FUNCTION_QUERY_BRIGHTNESS_TRANSFER_CHARACTERISTICS,378¶ms);379if (!info) {380err = -EIO;381goto out;382}383384size = *(u16 *) info->buffer.pointer;385if (size < 10) {386err = -EINVAL;387goto out;388}389390memset(&characteristics, 0, sizeof(characteristics));391size = min(sizeof(characteristics), size);392memcpy(&characteristics, info->buffer.pointer, size);393394atif->backlight_caps.caps_valid = true;395atif->backlight_caps.min_input_signal =396characteristics.min_input_signal;397atif->backlight_caps.max_input_signal =398characteristics.max_input_signal;399atif->backlight_caps.ac_level = characteristics.ac_level;400atif->backlight_caps.dc_level = characteristics.dc_level;401atif->backlight_caps.data_points = characteristics.number_of_points;402memcpy(atif->backlight_caps.luminance_data,403characteristics.data_points,404sizeof(atif->backlight_caps.luminance_data));405out:406kfree(info);407return err;408}409410/**411* amdgpu_atif_get_sbios_requests - get requested sbios event412*413* @atif: acpi handle414* @req: atif sbios request struct415*416* Execute the ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS ATIF function417* to determine what requests the sbios is making to the driver418* (all asics).419* Returns 0 on success, error on failure.420*/421static int amdgpu_atif_get_sbios_requests(struct amdgpu_atif *atif,422struct atif_sbios_requests *req)423{424union acpi_object *info;425size_t size;426int count = 0;427428info = amdgpu_atif_call(atif, ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS,429NULL);430if (!info)431return -EIO;432433size = *(u16 *)info->buffer.pointer;434if (size < 0xd) {435count = -EINVAL;436goto out;437}438memset(req, 0, sizeof(*req));439440size = min(sizeof(*req), size);441memcpy(req, info->buffer.pointer, size);442DRM_DEBUG_DRIVER("SBIOS pending requests: %#x\n", req->pending);443444count = hweight32(req->pending);445446out:447kfree(info);448return count;449}450451/**452* amdgpu_atif_handler - handle ATIF notify requests453*454* @adev: amdgpu_device pointer455* @event: atif sbios request struct456*457* Checks the acpi event and if it matches an atif event,458* handles it.459*460* Returns:461* NOTIFY_BAD or NOTIFY_DONE, depending on the event.462*/463static int amdgpu_atif_handler(struct amdgpu_device *adev,464struct acpi_bus_event *event)465{466struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;467int count;468469DRM_DEBUG_DRIVER("event, device_class = %s, type = %#x\n",470event->device_class, event->type);471472if (strcmp(event->device_class, ACPI_VIDEO_CLASS) != 0)473return NOTIFY_DONE;474475/* Is this actually our event? */476if (!atif->notification_cfg.enabled ||477event->type != atif->notification_cfg.command_code) {478/* These events will generate keypresses otherwise */479if (event->type == ACPI_VIDEO_NOTIFY_PROBE)480return NOTIFY_BAD;481else482return NOTIFY_DONE;483}484485if (atif->functions.sbios_requests) {486struct atif_sbios_requests req;487488/* Check pending SBIOS requests */489count = amdgpu_atif_get_sbios_requests(atif, &req);490491if (count <= 0)492return NOTIFY_BAD;493494DRM_DEBUG_DRIVER("ATIF: %d pending SBIOS requests\n", count);495496if (req.pending & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST) {497if (atif->bd) {498DRM_DEBUG_DRIVER("Changing brightness to %d\n",499req.backlight_level);500/*501* XXX backlight_device_set_brightness() is502* hardwired to post BACKLIGHT_UPDATE_SYSFS.503* It probably should accept 'reason' parameter.504*/505backlight_device_set_brightness(atif->bd, req.backlight_level);506}507}508509if (req.pending & ATIF_DGPU_DISPLAY_EVENT) {510if (adev->flags & AMD_IS_PX) {511pm_runtime_get_sync(adev_to_drm(adev)->dev);512/* Just fire off a uevent and let userspace tell us what to do */513drm_helper_hpd_irq_event(adev_to_drm(adev));514pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);515}516}517/* TODO: check other events */518}519520/* We've handled the event, stop the notifier chain. The ACPI interface521* overloads ACPI_VIDEO_NOTIFY_PROBE, we don't want to send that to522* userspace if the event was generated only to signal a SBIOS523* request.524*/525return NOTIFY_BAD;526}527528/* Call the ATCS method529*/530/**531* amdgpu_atcs_call - call an ATCS method532*533* @atcs: atcs structure534* @function: the ATCS function to execute535* @params: ATCS function params536*537* Executes the requested ATCS function (all asics).538* Returns a pointer to the acpi output buffer.539*/540static union acpi_object *amdgpu_atcs_call(struct amdgpu_atcs *atcs,541int function,542struct acpi_buffer *params)543{544acpi_status status;545union acpi_object atcs_arg_elements[2];546struct acpi_object_list atcs_arg;547struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };548549atcs_arg.count = 2;550atcs_arg.pointer = &atcs_arg_elements[0];551552atcs_arg_elements[0].type = ACPI_TYPE_INTEGER;553atcs_arg_elements[0].integer.value = function;554555if (params) {556atcs_arg_elements[1].type = ACPI_TYPE_BUFFER;557atcs_arg_elements[1].buffer.length = params->length;558atcs_arg_elements[1].buffer.pointer = params->pointer;559} else {560/* We need a second fake parameter */561atcs_arg_elements[1].type = ACPI_TYPE_INTEGER;562atcs_arg_elements[1].integer.value = 0;563}564565status = acpi_evaluate_object(atcs->handle, NULL, &atcs_arg, &buffer);566567/* Fail only if calling the method fails and ATIF is supported */568if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {569DRM_DEBUG_DRIVER("failed to evaluate ATCS got %s\n",570acpi_format_exception(status));571kfree(buffer.pointer);572return NULL;573}574575return buffer.pointer;576}577578/**579* amdgpu_atcs_parse_functions - parse supported functions580*581* @f: supported functions struct582* @mask: supported functions mask from ATCS583*584* Use the supported functions mask from ATCS function585* ATCS_FUNCTION_VERIFY_INTERFACE to determine what functions586* are supported (all asics).587*/588static void amdgpu_atcs_parse_functions(struct amdgpu_atcs_functions *f, u32 mask)589{590f->get_ext_state = mask & ATCS_GET_EXTERNAL_STATE_SUPPORTED;591f->pcie_perf_req = mask & ATCS_PCIE_PERFORMANCE_REQUEST_SUPPORTED;592f->pcie_dev_rdy = mask & ATCS_PCIE_DEVICE_READY_NOTIFICATION_SUPPORTED;593f->pcie_bus_width = mask & ATCS_SET_PCIE_BUS_WIDTH_SUPPORTED;594f->get_uma_size = mask & ACPI_ATCS_GET_UMA_SIZE_SUPPORTED;595f->power_shift_control = mask & ATCS_SET_POWER_SHIFT_CONTROL_SUPPORTED;596f->set_uma_allocation_size = mask & ACPI_ATCS_SET_UMA_ALLOCATION_SIZE_SUPPORTED;597}598599/**600* amdgpu_atcs_verify_interface - verify ATCS601*602* @atcs: amdgpu atcs struct603*604* Execute the ATCS_FUNCTION_VERIFY_INTERFACE ATCS function605* to initialize ATCS and determine what features are supported606* (all asics).607* returns 0 on success, error on failure.608*/609static noinline_for_stack610int amdgpu_atcs_verify_interface(struct amdgpu_atcs *atcs)611{612union acpi_object *info;613struct atcs_verify_interface output;614size_t size;615int err = 0;616617info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_VERIFY_INTERFACE, NULL);618if (!info)619return -EIO;620621memset(&output, 0, sizeof(output));622623size = *(u16 *) info->buffer.pointer;624if (size < 8) {625DRM_INFO("ATCS buffer is too small: %zu\n", size);626err = -EINVAL;627goto out;628}629size = min(sizeof(output), size);630631memcpy(&output, info->buffer.pointer, size);632633/* TODO: check version? */634DRM_DEBUG_DRIVER("ATCS version %u\n", output.version);635636amdgpu_atcs_parse_functions(&atcs->functions, output.function_bits);637638out:639kfree(info);640return err;641}642643/**644* amdgpu_acpi_is_pcie_performance_request_supported645*646* @adev: amdgpu_device pointer647*648* Check if the ATCS pcie_perf_req and pcie_dev_rdy methods649* are supported (all asics).650* returns true if supported, false if not.651*/652bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev)653{654struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;655656if (atcs->functions.pcie_perf_req && atcs->functions.pcie_dev_rdy)657return true;658659return false;660}661662/**663* amdgpu_acpi_is_power_shift_control_supported664*665* Check if the ATCS power shift control method666* is supported.667* returns true if supported, false if not.668*/669bool amdgpu_acpi_is_power_shift_control_supported(void)670{671return amdgpu_acpi_priv.atcs.functions.power_shift_control;672}673674bool amdgpu_acpi_is_set_uma_allocation_size_supported(void)675{676return amdgpu_acpi_priv.atcs.functions.set_uma_allocation_size;677}678679/**680* amdgpu_acpi_pcie_notify_device_ready681*682* @adev: amdgpu_device pointer683*684* Executes the PCIE_DEVICE_READY_NOTIFICATION method685* (all asics).686* returns 0 on success, error on failure.687*/688int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev)689{690union acpi_object *info;691struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;692693if (!atcs->functions.pcie_dev_rdy)694return -EINVAL;695696info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_PCIE_DEVICE_READY_NOTIFICATION, NULL);697if (!info)698return -EIO;699700kfree(info);701702return 0;703}704705/**706* amdgpu_acpi_pcie_performance_request707*708* @adev: amdgpu_device pointer709* @perf_req: requested perf level (pcie gen speed)710* @advertise: set advertise caps flag if set711*712* Executes the PCIE_PERFORMANCE_REQUEST method to713* change the pcie gen speed (all asics).714* returns 0 on success, error on failure.715*/716int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,717u8 perf_req, bool advertise)718{719union acpi_object *info;720struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;721struct atcs_pref_req_input atcs_input;722struct atcs_pref_req_output atcs_output;723struct acpi_buffer params;724size_t size;725u32 retry = 3;726727if (amdgpu_acpi_pcie_notify_device_ready(adev))728return -EINVAL;729730if (!atcs->functions.pcie_perf_req)731return -EINVAL;732733atcs_input.size = sizeof(struct atcs_pref_req_input);734/* client id (bit 2-0: func num, 7-3: dev num, 15-8: bus num) */735atcs_input.client_id = pci_dev_id(adev->pdev);736atcs_input.valid_flags_mask = ATCS_VALID_FLAGS_MASK;737atcs_input.flags = ATCS_WAIT_FOR_COMPLETION;738if (advertise)739atcs_input.flags |= ATCS_ADVERTISE_CAPS;740atcs_input.req_type = ATCS_PCIE_LINK_SPEED;741atcs_input.perf_req = perf_req;742743params.length = sizeof(struct atcs_pref_req_input);744params.pointer = &atcs_input;745746while (retry--) {747info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_PCIE_PERFORMANCE_REQUEST, ¶ms);748if (!info)749return -EIO;750751memset(&atcs_output, 0, sizeof(atcs_output));752753size = *(u16 *) info->buffer.pointer;754if (size < 3) {755drm_info(adev_to_drm(adev),756"ATCS buffer is too small: %zu\n", size);757kfree(info);758return -EINVAL;759}760size = min(sizeof(atcs_output), size);761762memcpy(&atcs_output, info->buffer.pointer, size);763764kfree(info);765766switch (atcs_output.ret_val) {767case ATCS_REQUEST_REFUSED:768default:769return -EINVAL;770case ATCS_REQUEST_COMPLETE:771return 0;772case ATCS_REQUEST_IN_PROGRESS:773udelay(10);774break;775}776}777778return 0;779}780781/**782* amdgpu_acpi_power_shift_control783*784* @adev: amdgpu_device pointer785* @dev_state: device acpi state786* @drv_state: driver state787*788* Executes the POWER_SHIFT_CONTROL method to789* communicate current dGPU device state and790* driver state to APU/SBIOS.791* returns 0 on success, error on failure.792*/793int amdgpu_acpi_power_shift_control(struct amdgpu_device *adev,794u8 dev_state, bool drv_state)795{796union acpi_object *info;797struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;798struct atcs_pwr_shift_input atcs_input;799struct acpi_buffer params;800801if (!amdgpu_acpi_is_power_shift_control_supported())802return -EINVAL;803804atcs_input.size = sizeof(struct atcs_pwr_shift_input);805/* dGPU id (bit 2-0: func num, 7-3: dev num, 15-8: bus num) */806atcs_input.dgpu_id = pci_dev_id(adev->pdev);807atcs_input.dev_acpi_state = dev_state;808atcs_input.drv_state = drv_state;809810params.length = sizeof(struct atcs_pwr_shift_input);811params.pointer = &atcs_input;812813info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_POWER_SHIFT_CONTROL, ¶ms);814if (!info) {815drm_err(adev_to_drm(adev), "ATCS PSC call failed\n");816return -EIO;817}818819kfree(info);820return 0;821}822823/**824* amdgpu_acpi_smart_shift_update - update dGPU device state to SBIOS825*826* @adev: amdgpu device pointer827* @ss_state: current smart shift event828*829* returns 0 on success,830* otherwise return error number.831*/832int amdgpu_acpi_smart_shift_update(struct amdgpu_device *adev,833enum amdgpu_ss ss_state)834{835int r;836837if (!amdgpu_device_supports_smart_shift(adev))838return 0;839840switch (ss_state) {841/* SBIOS trigger “stop”, “enable” and “start” at D0, Driver Operational.842* SBIOS trigger “stop” at D3, Driver Not Operational.843* SBIOS trigger “stop” and “disable” at D0, Driver NOT operational.844*/845case AMDGPU_SS_DRV_LOAD:846r = amdgpu_acpi_power_shift_control(adev,847AMDGPU_ATCS_PSC_DEV_STATE_D0,848AMDGPU_ATCS_PSC_DRV_STATE_OPR);849break;850case AMDGPU_SS_DEV_D0:851r = amdgpu_acpi_power_shift_control(adev,852AMDGPU_ATCS_PSC_DEV_STATE_D0,853AMDGPU_ATCS_PSC_DRV_STATE_OPR);854break;855case AMDGPU_SS_DEV_D3:856r = amdgpu_acpi_power_shift_control(adev,857AMDGPU_ATCS_PSC_DEV_STATE_D3_HOT,858AMDGPU_ATCS_PSC_DRV_STATE_NOT_OPR);859break;860case AMDGPU_SS_DRV_UNLOAD:861r = amdgpu_acpi_power_shift_control(adev,862AMDGPU_ATCS_PSC_DEV_STATE_D0,863AMDGPU_ATCS_PSC_DRV_STATE_NOT_OPR);864break;865default:866return -EINVAL;867}868869return r;870}871872#ifdef CONFIG_ACPI_NUMA873static inline uint64_t amdgpu_acpi_get_numa_size(int nid)874{875/* This is directly using si_meminfo_node implementation as the876* function is not exported.877*/878int zone_type;879uint64_t managed_pages = 0;880881pg_data_t *pgdat = NODE_DATA(nid);882883for (zone_type = 0; zone_type < MAX_NR_ZONES; zone_type++)884managed_pages +=885zone_managed_pages(&pgdat->node_zones[zone_type]);886return managed_pages * PAGE_SIZE;887}888889static struct amdgpu_numa_info *amdgpu_acpi_get_numa_info(uint32_t pxm)890{891struct amdgpu_numa_info *numa_info;892int nid;893894numa_info = xa_load(&numa_info_xa, pxm);895896if (!numa_info) {897struct sysinfo info;898899numa_info = kzalloc(sizeof(*numa_info), GFP_KERNEL);900if (!numa_info)901return NULL;902903nid = pxm_to_node(pxm);904numa_info->pxm = pxm;905numa_info->nid = nid;906907if (numa_info->nid == NUMA_NO_NODE) {908si_meminfo(&info);909numa_info->size = info.totalram * info.mem_unit;910} else {911numa_info->size = amdgpu_acpi_get_numa_size(nid);912}913xa_store(&numa_info_xa, numa_info->pxm, numa_info, GFP_KERNEL);914}915916return numa_info;917}918#endif919920/**921* amdgpu_acpi_set_uma_allocation_size - Set Unified Memory Architecture allocation size via ACPI922* @adev: Pointer to the amdgpu_device structure923* @index: Index specifying the UMA allocation924* @type: Type of UMA allocation925*926* This function configures the UMA allocation size for the specified device927* using ACPI methods. The allocation is determined by the provided index and type.928* Returns 0 on success or a negative error code on failure.929*/930int amdgpu_acpi_set_uma_allocation_size(struct amdgpu_device *adev, u8 index, u8 type)931{932struct atcs_set_uma_allocation_size_input atcs_input;933struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;934struct acpi_buffer params;935union acpi_object *info;936937if (!amdgpu_acpi_is_set_uma_allocation_size_supported())938return -EINVAL;939940atcs_input.size = sizeof(struct atcs_set_uma_allocation_size_input);941atcs_input.uma_size_index = index;942atcs_input.uma_size_type = type;943944params.length = sizeof(struct atcs_set_uma_allocation_size_input);945params.pointer = &atcs_input;946947info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_SET_UMA_ALLOCATION_SIZE, ¶ms);948if (!info) {949drm_err(adev_to_drm(adev), "ATCS UMA allocation size update failed\n");950return -EIO;951}952953kfree(info);954955return 0;956}957958/**959* amdgpu_acpi_get_node_id - obtain the NUMA node id for corresponding amdgpu960* acpi device handle961*962* @handle: acpi handle963* @numa_info: amdgpu_numa_info structure holding numa information964*965* Queries the ACPI interface to fetch the corresponding NUMA Node ID for a966* given amdgpu acpi device.967*968* Returns ACPI STATUS OK with Node ID on success or the corresponding failure reason969*/970static acpi_status amdgpu_acpi_get_node_id(acpi_handle handle,971struct amdgpu_numa_info **numa_info)972{973#ifdef CONFIG_ACPI_NUMA974u64 pxm;975acpi_status status;976977if (!numa_info)978return_ACPI_STATUS(AE_ERROR);979980status = acpi_evaluate_integer(handle, "_PXM", NULL, &pxm);981982if (ACPI_FAILURE(status))983return status;984985*numa_info = amdgpu_acpi_get_numa_info(pxm);986987if (!*numa_info)988return_ACPI_STATUS(AE_ERROR);989990return_ACPI_STATUS(AE_OK);991#else992return_ACPI_STATUS(AE_NOT_EXIST);993#endif994}995996static struct amdgpu_acpi_dev_info *amdgpu_acpi_get_dev(u32 sbdf)997{998struct amdgpu_acpi_dev_info *acpi_dev;9991000if (list_empty(&amdgpu_acpi_dev_list))1001return NULL;10021003list_for_each_entry(acpi_dev, &amdgpu_acpi_dev_list, list)1004if (acpi_dev->sbdf == sbdf)1005return acpi_dev;10061007return NULL;1008}10091010static int amdgpu_acpi_dev_init(struct amdgpu_acpi_dev_info **dev_info,1011struct amdgpu_acpi_xcc_info *xcc_info, u32 sbdf)1012{1013struct amdgpu_acpi_dev_info *tmp;1014union acpi_object *obj;1015int ret = -ENOENT;10161017*dev_info = NULL;1018tmp = kzalloc(sizeof(struct amdgpu_acpi_dev_info), GFP_KERNEL);1019if (!tmp)1020return -ENOMEM;10211022INIT_LIST_HEAD(&tmp->xcc_list);1023INIT_LIST_HEAD(&tmp->list);1024tmp->sbdf = sbdf;10251026obj = acpi_evaluate_dsm_typed(xcc_info->handle, &amd_xcc_dsm_guid, 0,1027AMD_XCC_DSM_GET_SUPP_MODE, NULL,1028ACPI_TYPE_INTEGER);10291030if (!obj) {1031acpi_handle_debug(xcc_info->handle,1032"_DSM function %d evaluation failed",1033AMD_XCC_DSM_GET_SUPP_MODE);1034ret = -ENOENT;1035goto out;1036}10371038tmp->supp_xcp_mode = obj->integer.value & 0xFFFF;1039ACPI_FREE(obj);10401041obj = acpi_evaluate_dsm_typed(xcc_info->handle, &amd_xcc_dsm_guid, 0,1042AMD_XCC_DSM_GET_XCP_MODE, NULL,1043ACPI_TYPE_INTEGER);10441045if (!obj) {1046acpi_handle_debug(xcc_info->handle,1047"_DSM function %d evaluation failed",1048AMD_XCC_DSM_GET_XCP_MODE);1049ret = -ENOENT;1050goto out;1051}10521053tmp->xcp_mode = obj->integer.value & 0xFFFF;1054tmp->mem_mode = (obj->integer.value >> 32) & 0xFFFF;1055ACPI_FREE(obj);10561057/* Evaluate DSMs and fill XCC information */1058obj = acpi_evaluate_dsm_typed(xcc_info->handle, &amd_xcc_dsm_guid, 0,1059AMD_XCC_DSM_GET_TMR_INFO, NULL,1060ACPI_TYPE_PACKAGE);10611062if (!obj || obj->package.count < 2) {1063acpi_handle_debug(xcc_info->handle,1064"_DSM function %d evaluation failed",1065AMD_XCC_DSM_GET_TMR_INFO);1066ret = -ENOENT;1067goto out;1068}10691070tmp->tmr_base = obj->package.elements[0].integer.value;1071tmp->tmr_size = obj->package.elements[1].integer.value;1072ACPI_FREE(obj);10731074DRM_DEBUG_DRIVER(1075"New dev(%x): Supported xcp mode: %x curr xcp_mode : %x mem mode : %x, tmr base: %llx tmr size: %llx ",1076tmp->sbdf, tmp->supp_xcp_mode, tmp->xcp_mode, tmp->mem_mode,1077tmp->tmr_base, tmp->tmr_size);1078list_add_tail(&tmp->list, &amdgpu_acpi_dev_list);1079*dev_info = tmp;10801081return 0;10821083out:1084if (obj)1085ACPI_FREE(obj);1086kfree(tmp);10871088return ret;1089}10901091static int amdgpu_acpi_get_xcc_info(struct amdgpu_acpi_xcc_info *xcc_info,1092u32 *sbdf)1093{1094union acpi_object *obj;1095acpi_status status;1096int ret = -ENOENT;10971098obj = acpi_evaluate_dsm_typed(xcc_info->handle, &amd_xcc_dsm_guid, 0,1099AMD_XCC_DSM_GET_NUM_FUNCS, NULL,1100ACPI_TYPE_INTEGER);11011102if (!obj || obj->integer.value != AMD_XCC_DSM_NUM_FUNCS)1103goto out;1104ACPI_FREE(obj);11051106/* Evaluate DSMs and fill XCC information */1107obj = acpi_evaluate_dsm_typed(xcc_info->handle, &amd_xcc_dsm_guid, 0,1108AMD_XCC_DSM_GET_VF_XCC_MAPPING, NULL,1109ACPI_TYPE_INTEGER);11101111if (!obj) {1112acpi_handle_debug(xcc_info->handle,1113"_DSM function %d evaluation failed",1114AMD_XCC_DSM_GET_VF_XCC_MAPPING);1115ret = -EINVAL;1116goto out;1117}11181119/* PF xcc id [39:32] */1120xcc_info->phy_id = (obj->integer.value >> 32) & 0xFF;1121/* xcp node of this xcc [47:40] */1122xcc_info->xcp_node = (obj->integer.value >> 40) & 0xFF;1123/* PF domain of this xcc [31:16] */1124*sbdf = (obj->integer.value) & 0xFFFF0000;1125/* PF bus/dev/fn of this xcc [63:48] */1126*sbdf |= (obj->integer.value >> 48) & 0xFFFF;1127ACPI_FREE(obj);1128obj = NULL;11291130status =1131amdgpu_acpi_get_node_id(xcc_info->handle, &xcc_info->numa_info);11321133/* TODO: check if this check is required */1134if (ACPI_SUCCESS(status))1135ret = 0;1136out:1137if (obj)1138ACPI_FREE(obj);11391140return ret;1141}11421143static noinline_for_stack1144int amdgpu_acpi_enumerate_xcc(void)1145{1146struct amdgpu_acpi_dev_info *dev_info = NULL;1147struct amdgpu_acpi_xcc_info *xcc_info;1148struct acpi_device *acpi_dev;1149char hid[ACPI_ID_LEN];1150int ret, id;1151u32 sbdf;11521153INIT_LIST_HEAD(&amdgpu_acpi_dev_list);1154xa_init(&numa_info_xa);11551156for (id = 0; id < AMD_XCC_MAX_HID; id++) {1157sprintf(hid, "%s%d", "AMD", AMD_XCC_HID_START + id);1158acpi_dev = acpi_dev_get_first_match_dev(hid, NULL, -1);1159/* These ACPI objects are expected to be in sequential order. If1160* one is not found, no need to check the rest.1161*/1162if (!acpi_dev) {1163DRM_DEBUG_DRIVER("No matching acpi device found for %s\n",1164hid);1165break;1166}11671168xcc_info = kzalloc(sizeof(struct amdgpu_acpi_xcc_info),1169GFP_KERNEL);1170if (!xcc_info)1171return -ENOMEM;11721173INIT_LIST_HEAD(&xcc_info->list);1174xcc_info->handle = acpi_device_handle(acpi_dev);1175acpi_dev_put(acpi_dev);11761177ret = amdgpu_acpi_get_xcc_info(xcc_info, &sbdf);1178if (ret) {1179kfree(xcc_info);1180continue;1181}11821183dev_info = amdgpu_acpi_get_dev(sbdf);11841185if (!dev_info)1186ret = amdgpu_acpi_dev_init(&dev_info, xcc_info, sbdf);11871188if (ret == -ENOMEM)1189return ret;11901191if (!dev_info) {1192kfree(xcc_info);1193continue;1194}11951196list_add_tail(&xcc_info->list, &dev_info->xcc_list);1197}11981199return 0;1200}12011202int amdgpu_acpi_get_tmr_info(struct amdgpu_device *adev, u64 *tmr_offset,1203u64 *tmr_size)1204{1205struct amdgpu_acpi_dev_info *dev_info;1206u32 sbdf;12071208if (!tmr_offset || !tmr_size)1209return -EINVAL;12101211sbdf = (pci_domain_nr(adev->pdev->bus) << 16);1212sbdf |= pci_dev_id(adev->pdev);1213dev_info = amdgpu_acpi_get_dev(sbdf);1214if (!dev_info)1215return -ENOENT;12161217*tmr_offset = dev_info->tmr_base;1218*tmr_size = dev_info->tmr_size;12191220return 0;1221}12221223int amdgpu_acpi_get_mem_info(struct amdgpu_device *adev, int xcc_id,1224struct amdgpu_numa_info *numa_info)1225{1226struct amdgpu_acpi_dev_info *dev_info;1227struct amdgpu_acpi_xcc_info *xcc_info;1228u32 sbdf;12291230if (!numa_info)1231return -EINVAL;12321233sbdf = (pci_domain_nr(adev->pdev->bus) << 16);1234sbdf |= pci_dev_id(adev->pdev);1235dev_info = amdgpu_acpi_get_dev(sbdf);1236if (!dev_info)1237return -ENOENT;12381239list_for_each_entry(xcc_info, &dev_info->xcc_list, list) {1240if (xcc_info->phy_id == xcc_id) {1241memcpy(numa_info, xcc_info->numa_info,1242sizeof(*numa_info));1243return 0;1244}1245}12461247return -ENOENT;1248}12491250/**1251* amdgpu_acpi_event - handle notify events1252*1253* @nb: notifier block1254* @val: val1255* @data: acpi event1256*1257* Calls relevant amdgpu functions in response to various1258* acpi events.1259* Returns NOTIFY code1260*/1261static int amdgpu_acpi_event(struct notifier_block *nb,1262unsigned long val,1263void *data)1264{1265struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, acpi_nb);1266struct acpi_bus_event *entry = (struct acpi_bus_event *)data;12671268if (strcmp(entry->device_class, ACPI_AC_CLASS) == 0) {1269if (power_supply_is_system_supplied() > 0)1270DRM_DEBUG_DRIVER("pm: AC\n");1271else1272DRM_DEBUG_DRIVER("pm: DC\n");12731274amdgpu_pm_acpi_event_handler(adev);1275}12761277/* Check for pending SBIOS requests */1278return amdgpu_atif_handler(adev, entry);1279}12801281/* Call all ACPI methods here */1282/**1283* amdgpu_acpi_init - init driver acpi support1284*1285* @adev: amdgpu_device pointer1286*1287* Verifies the AMD ACPI interfaces and registers with the acpi1288* notifier chain (all asics).1289* Returns 0 on success, error on failure.1290*/1291int amdgpu_acpi_init(struct amdgpu_device *adev)1292{1293struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;12941295if (atif->notifications.brightness_change) {1296if (adev->dc_enabled) {1297#if defined(CONFIG_DRM_AMD_DC)1298struct amdgpu_display_manager *dm = &adev->dm;12991300if (dm->backlight_dev[0])1301atif->bd = dm->backlight_dev[0];1302#endif1303} else {1304struct drm_encoder *tmp;13051306/* Find the encoder controlling the brightness */1307list_for_each_entry(tmp, &adev_to_drm(adev)->mode_config.encoder_list,1308head) {1309struct amdgpu_encoder *enc = to_amdgpu_encoder(tmp);13101311if ((enc->devices & (ATOM_DEVICE_LCD_SUPPORT)) &&1312enc->enc_priv) {1313struct amdgpu_encoder_atom_dig *dig = enc->enc_priv;13141315if (dig->bl_dev) {1316atif->bd = dig->bl_dev;1317break;1318}1319}1320}1321}1322}1323adev->acpi_nb.notifier_call = amdgpu_acpi_event;1324register_acpi_notifier(&adev->acpi_nb);13251326return 0;1327}13281329void amdgpu_acpi_get_backlight_caps(struct amdgpu_dm_backlight_caps *caps)1330{1331struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;13321333memcpy(caps, &atif->backlight_caps, sizeof(*caps));1334}13351336/**1337* amdgpu_acpi_fini - tear down driver acpi support1338*1339* @adev: amdgpu_device pointer1340*1341* Unregisters with the acpi notifier chain (all asics).1342*/1343void amdgpu_acpi_fini(struct amdgpu_device *adev)1344{1345unregister_acpi_notifier(&adev->acpi_nb);1346}13471348/**1349* amdgpu_atif_pci_probe_handle - look up the ATIF handle1350*1351* @pdev: pci device1352*1353* Look up the ATIF handles (all asics).1354* Returns true if the handle is found, false if not.1355*/1356static bool amdgpu_atif_pci_probe_handle(struct pci_dev *pdev)1357{1358char acpi_method_name[255] = { 0 };1359struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};1360acpi_handle dhandle, atif_handle;1361acpi_status status;1362int ret;13631364dhandle = ACPI_HANDLE(&pdev->dev);1365if (!dhandle)1366return false;13671368status = acpi_get_handle(dhandle, "ATIF", &atif_handle);1369if (ACPI_FAILURE(status))1370return false;13711372amdgpu_acpi_priv.atif.handle = atif_handle;1373acpi_get_name(amdgpu_acpi_priv.atif.handle, ACPI_FULL_PATHNAME, &buffer);1374DRM_DEBUG_DRIVER("Found ATIF handle %s\n", acpi_method_name);1375ret = amdgpu_atif_verify_interface(&amdgpu_acpi_priv.atif);1376if (ret) {1377amdgpu_acpi_priv.atif.handle = 0;1378return false;1379}1380return true;1381}13821383/**1384* amdgpu_atcs_pci_probe_handle - look up the ATCS handle1385*1386* @pdev: pci device1387*1388* Look up the ATCS handles (all asics).1389* Returns true if the handle is found, false if not.1390*/1391static bool amdgpu_atcs_pci_probe_handle(struct pci_dev *pdev)1392{1393char acpi_method_name[255] = { 0 };1394struct acpi_buffer buffer = { sizeof(acpi_method_name), acpi_method_name };1395acpi_handle dhandle, atcs_handle;1396acpi_status status;1397int ret;13981399dhandle = ACPI_HANDLE(&pdev->dev);1400if (!dhandle)1401return false;14021403status = acpi_get_handle(dhandle, "ATCS", &atcs_handle);1404if (ACPI_FAILURE(status))1405return false;14061407amdgpu_acpi_priv.atcs.handle = atcs_handle;1408acpi_get_name(amdgpu_acpi_priv.atcs.handle, ACPI_FULL_PATHNAME, &buffer);1409DRM_DEBUG_DRIVER("Found ATCS handle %s\n", acpi_method_name);1410ret = amdgpu_atcs_verify_interface(&amdgpu_acpi_priv.atcs);1411if (ret) {1412amdgpu_acpi_priv.atcs.handle = 0;1413return false;1414}1415return true;1416}141714181419/**1420* amdgpu_acpi_should_gpu_reset1421*1422* @adev: amdgpu_device_pointer1423*1424* returns true if should reset GPU, false if not1425*/1426bool amdgpu_acpi_should_gpu_reset(struct amdgpu_device *adev)1427{1428if ((adev->flags & AMD_IS_APU) &&1429adev->gfx.imu.funcs) /* Not need to do mode2 reset for IMU enabled APUs */1430return false;14311432if ((adev->flags & AMD_IS_APU) &&1433amdgpu_acpi_is_s3_active(adev))1434return false;14351436if (amdgpu_sriov_vf(adev))1437return false;14381439#if IS_ENABLED(CONFIG_SUSPEND)1440return pm_suspend_target_state != PM_SUSPEND_TO_IDLE;1441#else1442return true;1443#endif1444}14451446/*1447* amdgpu_acpi_detect - detect ACPI ATIF/ATCS methods1448*1449* Check if we have the ATIF/ATCS methods and populate1450* the structures in the driver.1451*/1452void amdgpu_acpi_detect(void)1453{1454struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;1455struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;1456struct pci_dev *pdev = NULL;1457int ret;14581459while ((pdev = pci_get_base_class(PCI_BASE_CLASS_DISPLAY, pdev))) {1460if ((pdev->class != PCI_CLASS_DISPLAY_VGA << 8) &&1461(pdev->class != PCI_CLASS_DISPLAY_OTHER << 8))1462continue;14631464if (!atif->handle)1465amdgpu_atif_pci_probe_handle(pdev);1466if (!atcs->handle)1467amdgpu_atcs_pci_probe_handle(pdev);1468}14691470if (atif->functions.sbios_requests && !atif->functions.system_params) {1471/* XXX check this workraround, if sbios request function is1472* present we have to see how it's configured in the system1473* params1474*/1475atif->functions.system_params = true;1476}14771478if (atif->functions.system_params) {1479ret = amdgpu_atif_get_notification_params(atif);1480if (ret) {1481DRM_DEBUG_DRIVER("Call to GET_SYSTEM_PARAMS failed: %d\n",1482ret);1483/* Disable notification */1484atif->notification_cfg.enabled = false;1485}1486}14871488if (atif->functions.query_backlight_transfer_characteristics) {1489ret = amdgpu_atif_query_backlight_caps(atif);1490if (ret) {1491DRM_DEBUG_DRIVER("Call to QUERY_BACKLIGHT_TRANSFER_CHARACTERISTICS failed: %d\n",1492ret);1493atif->backlight_caps.caps_valid = false;1494}1495} else {1496atif->backlight_caps.caps_valid = false;1497}14981499amdgpu_acpi_enumerate_xcc();1500}15011502void amdgpu_acpi_release(void)1503{1504struct amdgpu_acpi_dev_info *dev_info, *dev_tmp;1505struct amdgpu_acpi_xcc_info *xcc_info, *xcc_tmp;1506struct amdgpu_numa_info *numa_info;1507unsigned long index;15081509xa_for_each(&numa_info_xa, index, numa_info) {1510kfree(numa_info);1511xa_erase(&numa_info_xa, index);1512}15131514if (list_empty(&amdgpu_acpi_dev_list))1515return;15161517list_for_each_entry_safe(dev_info, dev_tmp, &amdgpu_acpi_dev_list,1518list) {1519list_for_each_entry_safe(xcc_info, xcc_tmp, &dev_info->xcc_list,1520list) {1521list_del(&xcc_info->list);1522kfree(xcc_info);1523}15241525list_del(&dev_info->list);1526kfree(dev_info);1527}1528}15291530#if IS_ENABLED(CONFIG_SUSPEND)1531/**1532* amdgpu_acpi_is_s3_active1533*1534* @adev: amdgpu_device_pointer1535*1536* returns true if supported, false if not.1537*/1538bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev)1539{1540return !(adev->flags & AMD_IS_APU) ||1541(pm_suspend_target_state == PM_SUSPEND_MEM);1542}15431544/**1545* amdgpu_acpi_is_s0ix_active1546*1547* @adev: amdgpu_device_pointer1548*1549* returns true if supported, false if not.1550*/1551bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev)1552{1553if (!(adev->flags & AMD_IS_APU) ||1554(pm_suspend_target_state != PM_SUSPEND_TO_IDLE))1555return false;15561557if (adev->asic_type < CHIP_RAVEN)1558return false;15591560if (!(adev->pm.pp_feature & PP_GFXOFF_MASK))1561return false;15621563/*1564* If ACPI_FADT_LOW_POWER_S0 is not set in the FADT, it is generally1565* risky to do any special firmware-related preparations for entering1566* S0ix even though the system is suspending to idle, so return false1567* in that case.1568*/1569if (!(acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0)) {1570dev_err_once(adev->dev,1571"Power consumption will be higher as BIOS has not been configured for suspend-to-idle.\n"1572"To use suspend-to-idle change the sleep mode in BIOS setup.\n");1573return false;1574}15751576#if !IS_ENABLED(CONFIG_AMD_PMC)1577dev_err_once(adev->dev,1578"Power consumption will be higher as the kernel has not been compiled with CONFIG_AMD_PMC.\n");1579return false;1580#else1581return true;1582#endif /* CONFIG_AMD_PMC */1583}1584#endif /* CONFIG_SUSPEND */15851586#if IS_ENABLED(CONFIG_DRM_AMD_ISP)1587static const struct acpi_device_id isp_sensor_ids[] = {1588{ "OMNI5C10" },1589{ }1590};15911592static int isp_match_acpi_device_ids(struct device *dev, const void *data)1593{1594return acpi_match_device(data, dev) ? 1 : 0;1595}15961597int amdgpu_acpi_get_isp4_dev(struct acpi_device **dev)1598{1599struct device *pdev __free(put_device) = NULL;1600struct acpi_device *acpi_pdev;16011602pdev = bus_find_device(&platform_bus_type, NULL, isp_sensor_ids,1603isp_match_acpi_device_ids);1604if (!pdev)1605return -EINVAL;16061607acpi_pdev = ACPI_COMPANION(pdev);1608if (!acpi_pdev)1609return -ENODEV;16101611*dev = acpi_pdev;16121613return 0;1614}1615#endif /* CONFIG_DRM_AMD_ISP */161616171618