Path: blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
26517 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 power_shift_control;119};120121struct amdgpu_atcs {122acpi_handle handle;123124struct amdgpu_atcs_functions functions;125};126127static struct amdgpu_acpi_priv {128struct amdgpu_atif atif;129struct amdgpu_atcs atcs;130} amdgpu_acpi_priv;131132/* Call the ATIF method133*/134/**135* amdgpu_atif_call - call an ATIF method136*137* @atif: atif structure138* @function: the ATIF function to execute139* @params: ATIF function params140*141* Executes the requested ATIF function (all asics).142* Returns a pointer to the acpi output buffer.143*/144static union acpi_object *amdgpu_atif_call(struct amdgpu_atif *atif,145int function,146struct acpi_buffer *params)147{148acpi_status status;149union acpi_object *obj;150union acpi_object atif_arg_elements[2];151struct acpi_object_list atif_arg;152struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };153154atif_arg.count = 2;155atif_arg.pointer = &atif_arg_elements[0];156157atif_arg_elements[0].type = ACPI_TYPE_INTEGER;158atif_arg_elements[0].integer.value = function;159160if (params) {161atif_arg_elements[1].type = ACPI_TYPE_BUFFER;162atif_arg_elements[1].buffer.length = params->length;163atif_arg_elements[1].buffer.pointer = params->pointer;164} else {165/* We need a second fake parameter */166atif_arg_elements[1].type = ACPI_TYPE_INTEGER;167atif_arg_elements[1].integer.value = 0;168}169170status = acpi_evaluate_object(atif->handle, NULL, &atif_arg,171&buffer);172obj = (union acpi_object *)buffer.pointer;173174/* Fail if calling the method fails */175if (ACPI_FAILURE(status)) {176DRM_DEBUG_DRIVER("failed to evaluate ATIF got %s\n",177acpi_format_exception(status));178kfree(obj);179return NULL;180}181182if (obj->type != ACPI_TYPE_BUFFER) {183DRM_DEBUG_DRIVER("bad object returned from ATIF: %d\n",184obj->type);185kfree(obj);186return NULL;187}188189return obj;190}191192/**193* amdgpu_atif_parse_notification - parse supported notifications194*195* @n: supported notifications struct196* @mask: supported notifications mask from ATIF197*198* Use the supported notifications mask from ATIF function199* ATIF_FUNCTION_VERIFY_INTERFACE to determine what notifications200* are supported (all asics).201*/202static void amdgpu_atif_parse_notification(struct amdgpu_atif_notifications *n, u32 mask)203{204n->thermal_state = mask & ATIF_THERMAL_STATE_CHANGE_REQUEST_SUPPORTED;205n->forced_power_state = mask & ATIF_FORCED_POWER_STATE_CHANGE_REQUEST_SUPPORTED;206n->system_power_state = mask & ATIF_SYSTEM_POWER_SOURCE_CHANGE_REQUEST_SUPPORTED;207n->brightness_change = mask & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST_SUPPORTED;208n->dgpu_display_event = mask & ATIF_DGPU_DISPLAY_EVENT_SUPPORTED;209n->gpu_package_power_limit = mask & ATIF_GPU_PACKAGE_POWER_LIMIT_REQUEST_SUPPORTED;210}211212/**213* amdgpu_atif_parse_functions - parse supported functions214*215* @f: supported functions struct216* @mask: supported functions mask from ATIF217*218* Use the supported functions mask from ATIF function219* ATIF_FUNCTION_VERIFY_INTERFACE to determine what functions220* are supported (all asics).221*/222static void amdgpu_atif_parse_functions(struct amdgpu_atif_functions *f, u32 mask)223{224f->system_params = mask & ATIF_GET_SYSTEM_PARAMETERS_SUPPORTED;225f->sbios_requests = mask & ATIF_GET_SYSTEM_BIOS_REQUESTS_SUPPORTED;226f->temperature_change = mask & ATIF_TEMPERATURE_CHANGE_NOTIFICATION_SUPPORTED;227f->query_backlight_transfer_characteristics =228mask & ATIF_QUERY_BACKLIGHT_TRANSFER_CHARACTERISTICS_SUPPORTED;229f->ready_to_undock = mask & ATIF_READY_TO_UNDOCK_NOTIFICATION_SUPPORTED;230f->external_gpu_information = mask & ATIF_GET_EXTERNAL_GPU_INFORMATION_SUPPORTED;231}232233/**234* amdgpu_atif_verify_interface - verify ATIF235*236* @atif: amdgpu atif struct237*238* Execute the ATIF_FUNCTION_VERIFY_INTERFACE ATIF function239* to initialize ATIF and determine what features are supported240* (all asics).241* returns 0 on success, error on failure.242*/243static int amdgpu_atif_verify_interface(struct amdgpu_atif *atif)244{245union acpi_object *info;246struct atif_verify_interface output;247size_t size;248int err = 0;249250info = amdgpu_atif_call(atif, ATIF_FUNCTION_VERIFY_INTERFACE, NULL);251if (!info)252return -EIO;253254memset(&output, 0, sizeof(output));255256size = *(u16 *) info->buffer.pointer;257if (size < 12) {258DRM_INFO("ATIF buffer is too small: %zu\n", size);259err = -EINVAL;260goto out;261}262size = min(sizeof(output), size);263264memcpy(&output, info->buffer.pointer, size);265266/* TODO: check version? */267DRM_DEBUG_DRIVER("ATIF version %u\n", output.version);268269amdgpu_atif_parse_notification(&atif->notifications, output.notification_mask);270amdgpu_atif_parse_functions(&atif->functions, output.function_bits);271272out:273kfree(info);274return err;275}276277/**278* amdgpu_atif_get_notification_params - determine notify configuration279*280* @atif: acpi handle281*282* Execute the ATIF_FUNCTION_GET_SYSTEM_PARAMETERS ATIF function283* to determine if a notifier is used and if so which one284* (all asics). This is either Notify(VGA, 0x81) or Notify(VGA, n)285* where n is specified in the result if a notifier is used.286* Returns 0 on success, error on failure.287*/288static int amdgpu_atif_get_notification_params(struct amdgpu_atif *atif)289{290union acpi_object *info;291struct amdgpu_atif_notification_cfg *n = &atif->notification_cfg;292struct atif_system_params params;293size_t size;294int err = 0;295296info = amdgpu_atif_call(atif, ATIF_FUNCTION_GET_SYSTEM_PARAMETERS,297NULL);298if (!info) {299err = -EIO;300goto out;301}302303size = *(u16 *) info->buffer.pointer;304if (size < 10) {305err = -EINVAL;306goto out;307}308309memset(¶ms, 0, sizeof(params));310size = min(sizeof(params), size);311memcpy(¶ms, info->buffer.pointer, size);312313DRM_DEBUG_DRIVER("SYSTEM_PARAMS: mask = %#x, flags = %#x\n",314params.flags, params.valid_mask);315params.flags = params.flags & params.valid_mask;316317if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_NONE) {318n->enabled = false;319n->command_code = 0;320} else if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_81) {321n->enabled = true;322n->command_code = 0x81;323} else {324if (size < 11) {325err = -EINVAL;326goto out;327}328n->enabled = true;329n->command_code = params.command_code;330}331332out:333DRM_DEBUG_DRIVER("Notification %s, command code = %#x\n",334(n->enabled ? "enabled" : "disabled"),335n->command_code);336kfree(info);337return err;338}339340/**341* amdgpu_atif_query_backlight_caps - get min and max backlight input signal342*343* @atif: acpi handle344*345* Execute the QUERY_BRIGHTNESS_TRANSFER_CHARACTERISTICS ATIF function346* to determine the acceptable range of backlight values347*348* Backlight_caps.caps_valid will be set to true if the query is successful349*350* The input signals are in range 0-255351*352* This function assumes the display with backlight is the first LCD353*354* Returns 0 on success, error on failure.355*/356static int amdgpu_atif_query_backlight_caps(struct amdgpu_atif *atif)357{358union acpi_object *info;359struct atif_qbtc_output characteristics;360struct atif_qbtc_arguments arguments;361struct acpi_buffer params;362size_t size;363int err = 0;364365arguments.size = sizeof(arguments);366arguments.requested_display = ATIF_QBTC_REQUEST_LCD1;367368params.length = sizeof(arguments);369params.pointer = (void *)&arguments;370371info = amdgpu_atif_call(atif,372ATIF_FUNCTION_QUERY_BRIGHTNESS_TRANSFER_CHARACTERISTICS,373¶ms);374if (!info) {375err = -EIO;376goto out;377}378379size = *(u16 *) info->buffer.pointer;380if (size < 10) {381err = -EINVAL;382goto out;383}384385memset(&characteristics, 0, sizeof(characteristics));386size = min(sizeof(characteristics), size);387memcpy(&characteristics, info->buffer.pointer, size);388389atif->backlight_caps.caps_valid = true;390atif->backlight_caps.min_input_signal =391characteristics.min_input_signal;392atif->backlight_caps.max_input_signal =393characteristics.max_input_signal;394atif->backlight_caps.ac_level = characteristics.ac_level;395atif->backlight_caps.dc_level = characteristics.dc_level;396atif->backlight_caps.data_points = characteristics.number_of_points;397memcpy(atif->backlight_caps.luminance_data,398characteristics.data_points,399sizeof(atif->backlight_caps.luminance_data));400out:401kfree(info);402return err;403}404405/**406* amdgpu_atif_get_sbios_requests - get requested sbios event407*408* @atif: acpi handle409* @req: atif sbios request struct410*411* Execute the ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS ATIF function412* to determine what requests the sbios is making to the driver413* (all asics).414* Returns 0 on success, error on failure.415*/416static int amdgpu_atif_get_sbios_requests(struct amdgpu_atif *atif,417struct atif_sbios_requests *req)418{419union acpi_object *info;420size_t size;421int count = 0;422423info = amdgpu_atif_call(atif, ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS,424NULL);425if (!info)426return -EIO;427428size = *(u16 *)info->buffer.pointer;429if (size < 0xd) {430count = -EINVAL;431goto out;432}433memset(req, 0, sizeof(*req));434435size = min(sizeof(*req), size);436memcpy(req, info->buffer.pointer, size);437DRM_DEBUG_DRIVER("SBIOS pending requests: %#x\n", req->pending);438439count = hweight32(req->pending);440441out:442kfree(info);443return count;444}445446/**447* amdgpu_atif_handler - handle ATIF notify requests448*449* @adev: amdgpu_device pointer450* @event: atif sbios request struct451*452* Checks the acpi event and if it matches an atif event,453* handles it.454*455* Returns:456* NOTIFY_BAD or NOTIFY_DONE, depending on the event.457*/458static int amdgpu_atif_handler(struct amdgpu_device *adev,459struct acpi_bus_event *event)460{461struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;462int count;463464DRM_DEBUG_DRIVER("event, device_class = %s, type = %#x\n",465event->device_class, event->type);466467if (strcmp(event->device_class, ACPI_VIDEO_CLASS) != 0)468return NOTIFY_DONE;469470/* Is this actually our event? */471if (!atif->notification_cfg.enabled ||472event->type != atif->notification_cfg.command_code) {473/* These events will generate keypresses otherwise */474if (event->type == ACPI_VIDEO_NOTIFY_PROBE)475return NOTIFY_BAD;476else477return NOTIFY_DONE;478}479480if (atif->functions.sbios_requests) {481struct atif_sbios_requests req;482483/* Check pending SBIOS requests */484count = amdgpu_atif_get_sbios_requests(atif, &req);485486if (count <= 0)487return NOTIFY_BAD;488489DRM_DEBUG_DRIVER("ATIF: %d pending SBIOS requests\n", count);490491if (req.pending & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST) {492if (atif->bd) {493DRM_DEBUG_DRIVER("Changing brightness to %d\n",494req.backlight_level);495/*496* XXX backlight_device_set_brightness() is497* hardwired to post BACKLIGHT_UPDATE_SYSFS.498* It probably should accept 'reason' parameter.499*/500backlight_device_set_brightness(atif->bd, req.backlight_level);501}502}503504if (req.pending & ATIF_DGPU_DISPLAY_EVENT) {505if (adev->flags & AMD_IS_PX) {506pm_runtime_get_sync(adev_to_drm(adev)->dev);507/* Just fire off a uevent and let userspace tell us what to do */508drm_helper_hpd_irq_event(adev_to_drm(adev));509pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);510pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);511}512}513/* TODO: check other events */514}515516/* We've handled the event, stop the notifier chain. The ACPI interface517* overloads ACPI_VIDEO_NOTIFY_PROBE, we don't want to send that to518* userspace if the event was generated only to signal a SBIOS519* request.520*/521return NOTIFY_BAD;522}523524/* Call the ATCS method525*/526/**527* amdgpu_atcs_call - call an ATCS method528*529* @atcs: atcs structure530* @function: the ATCS function to execute531* @params: ATCS function params532*533* Executes the requested ATCS function (all asics).534* Returns a pointer to the acpi output buffer.535*/536static union acpi_object *amdgpu_atcs_call(struct amdgpu_atcs *atcs,537int function,538struct acpi_buffer *params)539{540acpi_status status;541union acpi_object atcs_arg_elements[2];542struct acpi_object_list atcs_arg;543struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };544545atcs_arg.count = 2;546atcs_arg.pointer = &atcs_arg_elements[0];547548atcs_arg_elements[0].type = ACPI_TYPE_INTEGER;549atcs_arg_elements[0].integer.value = function;550551if (params) {552atcs_arg_elements[1].type = ACPI_TYPE_BUFFER;553atcs_arg_elements[1].buffer.length = params->length;554atcs_arg_elements[1].buffer.pointer = params->pointer;555} else {556/* We need a second fake parameter */557atcs_arg_elements[1].type = ACPI_TYPE_INTEGER;558atcs_arg_elements[1].integer.value = 0;559}560561status = acpi_evaluate_object(atcs->handle, NULL, &atcs_arg, &buffer);562563/* Fail only if calling the method fails and ATIF is supported */564if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {565DRM_DEBUG_DRIVER("failed to evaluate ATCS got %s\n",566acpi_format_exception(status));567kfree(buffer.pointer);568return NULL;569}570571return buffer.pointer;572}573574/**575* amdgpu_atcs_parse_functions - parse supported functions576*577* @f: supported functions struct578* @mask: supported functions mask from ATCS579*580* Use the supported functions mask from ATCS function581* ATCS_FUNCTION_VERIFY_INTERFACE to determine what functions582* are supported (all asics).583*/584static void amdgpu_atcs_parse_functions(struct amdgpu_atcs_functions *f, u32 mask)585{586f->get_ext_state = mask & ATCS_GET_EXTERNAL_STATE_SUPPORTED;587f->pcie_perf_req = mask & ATCS_PCIE_PERFORMANCE_REQUEST_SUPPORTED;588f->pcie_dev_rdy = mask & ATCS_PCIE_DEVICE_READY_NOTIFICATION_SUPPORTED;589f->pcie_bus_width = mask & ATCS_SET_PCIE_BUS_WIDTH_SUPPORTED;590f->power_shift_control = mask & ATCS_SET_POWER_SHIFT_CONTROL_SUPPORTED;591}592593/**594* amdgpu_atcs_verify_interface - verify ATCS595*596* @atcs: amdgpu atcs struct597*598* Execute the ATCS_FUNCTION_VERIFY_INTERFACE ATCS function599* to initialize ATCS and determine what features are supported600* (all asics).601* returns 0 on success, error on failure.602*/603static int amdgpu_atcs_verify_interface(struct amdgpu_atcs *atcs)604{605union acpi_object *info;606struct atcs_verify_interface output;607size_t size;608int err = 0;609610info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_VERIFY_INTERFACE, NULL);611if (!info)612return -EIO;613614memset(&output, 0, sizeof(output));615616size = *(u16 *) info->buffer.pointer;617if (size < 8) {618DRM_INFO("ATCS buffer is too small: %zu\n", size);619err = -EINVAL;620goto out;621}622size = min(sizeof(output), size);623624memcpy(&output, info->buffer.pointer, size);625626/* TODO: check version? */627DRM_DEBUG_DRIVER("ATCS version %u\n", output.version);628629amdgpu_atcs_parse_functions(&atcs->functions, output.function_bits);630631out:632kfree(info);633return err;634}635636/**637* amdgpu_acpi_is_pcie_performance_request_supported638*639* @adev: amdgpu_device pointer640*641* Check if the ATCS pcie_perf_req and pcie_dev_rdy methods642* are supported (all asics).643* returns true if supported, false if not.644*/645bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev)646{647struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;648649if (atcs->functions.pcie_perf_req && atcs->functions.pcie_dev_rdy)650return true;651652return false;653}654655/**656* amdgpu_acpi_is_power_shift_control_supported657*658* Check if the ATCS power shift control method659* is supported.660* returns true if supported, false if not.661*/662bool amdgpu_acpi_is_power_shift_control_supported(void)663{664return amdgpu_acpi_priv.atcs.functions.power_shift_control;665}666667/**668* amdgpu_acpi_pcie_notify_device_ready669*670* @adev: amdgpu_device pointer671*672* Executes the PCIE_DEVICE_READY_NOTIFICATION method673* (all asics).674* returns 0 on success, error on failure.675*/676int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev)677{678union acpi_object *info;679struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;680681if (!atcs->functions.pcie_dev_rdy)682return -EINVAL;683684info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_PCIE_DEVICE_READY_NOTIFICATION, NULL);685if (!info)686return -EIO;687688kfree(info);689690return 0;691}692693/**694* amdgpu_acpi_pcie_performance_request695*696* @adev: amdgpu_device pointer697* @perf_req: requested perf level (pcie gen speed)698* @advertise: set advertise caps flag if set699*700* Executes the PCIE_PERFORMANCE_REQUEST method to701* change the pcie gen speed (all asics).702* returns 0 on success, error on failure.703*/704int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,705u8 perf_req, bool advertise)706{707union acpi_object *info;708struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;709struct atcs_pref_req_input atcs_input;710struct atcs_pref_req_output atcs_output;711struct acpi_buffer params;712size_t size;713u32 retry = 3;714715if (amdgpu_acpi_pcie_notify_device_ready(adev))716return -EINVAL;717718if (!atcs->functions.pcie_perf_req)719return -EINVAL;720721atcs_input.size = sizeof(struct atcs_pref_req_input);722/* client id (bit 2-0: func num, 7-3: dev num, 15-8: bus num) */723atcs_input.client_id = pci_dev_id(adev->pdev);724atcs_input.valid_flags_mask = ATCS_VALID_FLAGS_MASK;725atcs_input.flags = ATCS_WAIT_FOR_COMPLETION;726if (advertise)727atcs_input.flags |= ATCS_ADVERTISE_CAPS;728atcs_input.req_type = ATCS_PCIE_LINK_SPEED;729atcs_input.perf_req = perf_req;730731params.length = sizeof(struct atcs_pref_req_input);732params.pointer = &atcs_input;733734while (retry--) {735info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_PCIE_PERFORMANCE_REQUEST, ¶ms);736if (!info)737return -EIO;738739memset(&atcs_output, 0, sizeof(atcs_output));740741size = *(u16 *) info->buffer.pointer;742if (size < 3) {743DRM_INFO("ATCS buffer is too small: %zu\n", size);744kfree(info);745return -EINVAL;746}747size = min(sizeof(atcs_output), size);748749memcpy(&atcs_output, info->buffer.pointer, size);750751kfree(info);752753switch (atcs_output.ret_val) {754case ATCS_REQUEST_REFUSED:755default:756return -EINVAL;757case ATCS_REQUEST_COMPLETE:758return 0;759case ATCS_REQUEST_IN_PROGRESS:760udelay(10);761break;762}763}764765return 0;766}767768/**769* amdgpu_acpi_power_shift_control770*771* @adev: amdgpu_device pointer772* @dev_state: device acpi state773* @drv_state: driver state774*775* Executes the POWER_SHIFT_CONTROL method to776* communicate current dGPU device state and777* driver state to APU/SBIOS.778* returns 0 on success, error on failure.779*/780int amdgpu_acpi_power_shift_control(struct amdgpu_device *adev,781u8 dev_state, bool drv_state)782{783union acpi_object *info;784struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;785struct atcs_pwr_shift_input atcs_input;786struct acpi_buffer params;787788if (!amdgpu_acpi_is_power_shift_control_supported())789return -EINVAL;790791atcs_input.size = sizeof(struct atcs_pwr_shift_input);792/* dGPU id (bit 2-0: func num, 7-3: dev num, 15-8: bus num) */793atcs_input.dgpu_id = pci_dev_id(adev->pdev);794atcs_input.dev_acpi_state = dev_state;795atcs_input.drv_state = drv_state;796797params.length = sizeof(struct atcs_pwr_shift_input);798params.pointer = &atcs_input;799800info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_POWER_SHIFT_CONTROL, ¶ms);801if (!info) {802DRM_ERROR("ATCS PSC update failed\n");803return -EIO;804}805806kfree(info);807return 0;808}809810/**811* amdgpu_acpi_smart_shift_update - update dGPU device state to SBIOS812*813* @adev: amdgpu device pointer814* @ss_state: current smart shift event815*816* returns 0 on success,817* otherwise return error number.818*/819int amdgpu_acpi_smart_shift_update(struct amdgpu_device *adev,820enum amdgpu_ss ss_state)821{822int r;823824if (!amdgpu_device_supports_smart_shift(adev))825return 0;826827switch (ss_state) {828/* SBIOS trigger “stop”, “enable” and “start” at D0, Driver Operational.829* SBIOS trigger “stop” at D3, Driver Not Operational.830* SBIOS trigger “stop” and “disable” at D0, Driver NOT operational.831*/832case AMDGPU_SS_DRV_LOAD:833r = amdgpu_acpi_power_shift_control(adev,834AMDGPU_ATCS_PSC_DEV_STATE_D0,835AMDGPU_ATCS_PSC_DRV_STATE_OPR);836break;837case AMDGPU_SS_DEV_D0:838r = amdgpu_acpi_power_shift_control(adev,839AMDGPU_ATCS_PSC_DEV_STATE_D0,840AMDGPU_ATCS_PSC_DRV_STATE_OPR);841break;842case AMDGPU_SS_DEV_D3:843r = amdgpu_acpi_power_shift_control(adev,844AMDGPU_ATCS_PSC_DEV_STATE_D3_HOT,845AMDGPU_ATCS_PSC_DRV_STATE_NOT_OPR);846break;847case AMDGPU_SS_DRV_UNLOAD:848r = amdgpu_acpi_power_shift_control(adev,849AMDGPU_ATCS_PSC_DEV_STATE_D0,850AMDGPU_ATCS_PSC_DRV_STATE_NOT_OPR);851break;852default:853return -EINVAL;854}855856return r;857}858859#ifdef CONFIG_ACPI_NUMA860static inline uint64_t amdgpu_acpi_get_numa_size(int nid)861{862/* This is directly using si_meminfo_node implementation as the863* function is not exported.864*/865int zone_type;866uint64_t managed_pages = 0;867868pg_data_t *pgdat = NODE_DATA(nid);869870for (zone_type = 0; zone_type < MAX_NR_ZONES; zone_type++)871managed_pages +=872zone_managed_pages(&pgdat->node_zones[zone_type]);873return managed_pages * PAGE_SIZE;874}875876static struct amdgpu_numa_info *amdgpu_acpi_get_numa_info(uint32_t pxm)877{878struct amdgpu_numa_info *numa_info;879int nid;880881numa_info = xa_load(&numa_info_xa, pxm);882883if (!numa_info) {884struct sysinfo info;885886numa_info = kzalloc(sizeof(*numa_info), GFP_KERNEL);887if (!numa_info)888return NULL;889890nid = pxm_to_node(pxm);891numa_info->pxm = pxm;892numa_info->nid = nid;893894if (numa_info->nid == NUMA_NO_NODE) {895si_meminfo(&info);896numa_info->size = info.totalram * info.mem_unit;897} else {898numa_info->size = amdgpu_acpi_get_numa_size(nid);899}900xa_store(&numa_info_xa, numa_info->pxm, numa_info, GFP_KERNEL);901}902903return numa_info;904}905#endif906907/**908* amdgpu_acpi_get_node_id - obtain the NUMA node id for corresponding amdgpu909* acpi device handle910*911* @handle: acpi handle912* @numa_info: amdgpu_numa_info structure holding numa information913*914* Queries the ACPI interface to fetch the corresponding NUMA Node ID for a915* given amdgpu acpi device.916*917* Returns ACPI STATUS OK with Node ID on success or the corresponding failure reason918*/919static acpi_status amdgpu_acpi_get_node_id(acpi_handle handle,920struct amdgpu_numa_info **numa_info)921{922#ifdef CONFIG_ACPI_NUMA923u64 pxm;924acpi_status status;925926if (!numa_info)927return_ACPI_STATUS(AE_ERROR);928929status = acpi_evaluate_integer(handle, "_PXM", NULL, &pxm);930931if (ACPI_FAILURE(status))932return status;933934*numa_info = amdgpu_acpi_get_numa_info(pxm);935936if (!*numa_info)937return_ACPI_STATUS(AE_ERROR);938939return_ACPI_STATUS(AE_OK);940#else941return_ACPI_STATUS(AE_NOT_EXIST);942#endif943}944945static struct amdgpu_acpi_dev_info *amdgpu_acpi_get_dev(u32 sbdf)946{947struct amdgpu_acpi_dev_info *acpi_dev;948949if (list_empty(&amdgpu_acpi_dev_list))950return NULL;951952list_for_each_entry(acpi_dev, &amdgpu_acpi_dev_list, list)953if (acpi_dev->sbdf == sbdf)954return acpi_dev;955956return NULL;957}958959static int amdgpu_acpi_dev_init(struct amdgpu_acpi_dev_info **dev_info,960struct amdgpu_acpi_xcc_info *xcc_info, u32 sbdf)961{962struct amdgpu_acpi_dev_info *tmp;963union acpi_object *obj;964int ret = -ENOENT;965966*dev_info = NULL;967tmp = kzalloc(sizeof(struct amdgpu_acpi_dev_info), GFP_KERNEL);968if (!tmp)969return -ENOMEM;970971INIT_LIST_HEAD(&tmp->xcc_list);972INIT_LIST_HEAD(&tmp->list);973tmp->sbdf = sbdf;974975obj = acpi_evaluate_dsm_typed(xcc_info->handle, &amd_xcc_dsm_guid, 0,976AMD_XCC_DSM_GET_SUPP_MODE, NULL,977ACPI_TYPE_INTEGER);978979if (!obj) {980acpi_handle_debug(xcc_info->handle,981"_DSM function %d evaluation failed",982AMD_XCC_DSM_GET_SUPP_MODE);983ret = -ENOENT;984goto out;985}986987tmp->supp_xcp_mode = obj->integer.value & 0xFFFF;988ACPI_FREE(obj);989990obj = acpi_evaluate_dsm_typed(xcc_info->handle, &amd_xcc_dsm_guid, 0,991AMD_XCC_DSM_GET_XCP_MODE, NULL,992ACPI_TYPE_INTEGER);993994if (!obj) {995acpi_handle_debug(xcc_info->handle,996"_DSM function %d evaluation failed",997AMD_XCC_DSM_GET_XCP_MODE);998ret = -ENOENT;999goto out;1000}10011002tmp->xcp_mode = obj->integer.value & 0xFFFF;1003tmp->mem_mode = (obj->integer.value >> 32) & 0xFFFF;1004ACPI_FREE(obj);10051006/* Evaluate DSMs and fill XCC information */1007obj = acpi_evaluate_dsm_typed(xcc_info->handle, &amd_xcc_dsm_guid, 0,1008AMD_XCC_DSM_GET_TMR_INFO, NULL,1009ACPI_TYPE_PACKAGE);10101011if (!obj || obj->package.count < 2) {1012acpi_handle_debug(xcc_info->handle,1013"_DSM function %d evaluation failed",1014AMD_XCC_DSM_GET_TMR_INFO);1015ret = -ENOENT;1016goto out;1017}10181019tmp->tmr_base = obj->package.elements[0].integer.value;1020tmp->tmr_size = obj->package.elements[1].integer.value;1021ACPI_FREE(obj);10221023DRM_DEBUG_DRIVER(1024"New dev(%x): Supported xcp mode: %x curr xcp_mode : %x mem mode : %x, tmr base: %llx tmr size: %llx ",1025tmp->sbdf, tmp->supp_xcp_mode, tmp->xcp_mode, tmp->mem_mode,1026tmp->tmr_base, tmp->tmr_size);1027list_add_tail(&tmp->list, &amdgpu_acpi_dev_list);1028*dev_info = tmp;10291030return 0;10311032out:1033if (obj)1034ACPI_FREE(obj);1035kfree(tmp);10361037return ret;1038}10391040static int amdgpu_acpi_get_xcc_info(struct amdgpu_acpi_xcc_info *xcc_info,1041u32 *sbdf)1042{1043union acpi_object *obj;1044acpi_status status;1045int ret = -ENOENT;10461047obj = acpi_evaluate_dsm_typed(xcc_info->handle, &amd_xcc_dsm_guid, 0,1048AMD_XCC_DSM_GET_NUM_FUNCS, NULL,1049ACPI_TYPE_INTEGER);10501051if (!obj || obj->integer.value != AMD_XCC_DSM_NUM_FUNCS)1052goto out;1053ACPI_FREE(obj);10541055/* Evaluate DSMs and fill XCC information */1056obj = acpi_evaluate_dsm_typed(xcc_info->handle, &amd_xcc_dsm_guid, 0,1057AMD_XCC_DSM_GET_VF_XCC_MAPPING, NULL,1058ACPI_TYPE_INTEGER);10591060if (!obj) {1061acpi_handle_debug(xcc_info->handle,1062"_DSM function %d evaluation failed",1063AMD_XCC_DSM_GET_VF_XCC_MAPPING);1064ret = -EINVAL;1065goto out;1066}10671068/* PF xcc id [39:32] */1069xcc_info->phy_id = (obj->integer.value >> 32) & 0xFF;1070/* xcp node of this xcc [47:40] */1071xcc_info->xcp_node = (obj->integer.value >> 40) & 0xFF;1072/* PF domain of this xcc [31:16] */1073*sbdf = (obj->integer.value) & 0xFFFF0000;1074/* PF bus/dev/fn of this xcc [63:48] */1075*sbdf |= (obj->integer.value >> 48) & 0xFFFF;1076ACPI_FREE(obj);1077obj = NULL;10781079status =1080amdgpu_acpi_get_node_id(xcc_info->handle, &xcc_info->numa_info);10811082/* TODO: check if this check is required */1083if (ACPI_SUCCESS(status))1084ret = 0;1085out:1086if (obj)1087ACPI_FREE(obj);10881089return ret;1090}10911092static int amdgpu_acpi_enumerate_xcc(void)1093{1094struct amdgpu_acpi_dev_info *dev_info = NULL;1095struct amdgpu_acpi_xcc_info *xcc_info;1096struct acpi_device *acpi_dev;1097char hid[ACPI_ID_LEN];1098int ret, id;1099u32 sbdf;11001101INIT_LIST_HEAD(&amdgpu_acpi_dev_list);1102xa_init(&numa_info_xa);11031104for (id = 0; id < AMD_XCC_MAX_HID; id++) {1105sprintf(hid, "%s%d", "AMD", AMD_XCC_HID_START + id);1106acpi_dev = acpi_dev_get_first_match_dev(hid, NULL, -1);1107/* These ACPI objects are expected to be in sequential order. If1108* one is not found, no need to check the rest.1109*/1110if (!acpi_dev) {1111DRM_DEBUG_DRIVER("No matching acpi device found for %s",1112hid);1113break;1114}11151116xcc_info = kzalloc(sizeof(struct amdgpu_acpi_xcc_info),1117GFP_KERNEL);1118if (!xcc_info) {1119DRM_ERROR("Failed to allocate memory for xcc info\n");1120return -ENOMEM;1121}11221123INIT_LIST_HEAD(&xcc_info->list);1124xcc_info->handle = acpi_device_handle(acpi_dev);1125acpi_dev_put(acpi_dev);11261127ret = amdgpu_acpi_get_xcc_info(xcc_info, &sbdf);1128if (ret) {1129kfree(xcc_info);1130continue;1131}11321133dev_info = amdgpu_acpi_get_dev(sbdf);11341135if (!dev_info)1136ret = amdgpu_acpi_dev_init(&dev_info, xcc_info, sbdf);11371138if (ret == -ENOMEM)1139return ret;11401141if (!dev_info) {1142kfree(xcc_info);1143continue;1144}11451146list_add_tail(&xcc_info->list, &dev_info->xcc_list);1147}11481149return 0;1150}11511152int amdgpu_acpi_get_tmr_info(struct amdgpu_device *adev, u64 *tmr_offset,1153u64 *tmr_size)1154{1155struct amdgpu_acpi_dev_info *dev_info;1156u32 sbdf;11571158if (!tmr_offset || !tmr_size)1159return -EINVAL;11601161sbdf = (pci_domain_nr(adev->pdev->bus) << 16);1162sbdf |= pci_dev_id(adev->pdev);1163dev_info = amdgpu_acpi_get_dev(sbdf);1164if (!dev_info)1165return -ENOENT;11661167*tmr_offset = dev_info->tmr_base;1168*tmr_size = dev_info->tmr_size;11691170return 0;1171}11721173int amdgpu_acpi_get_mem_info(struct amdgpu_device *adev, int xcc_id,1174struct amdgpu_numa_info *numa_info)1175{1176struct amdgpu_acpi_dev_info *dev_info;1177struct amdgpu_acpi_xcc_info *xcc_info;1178u32 sbdf;11791180if (!numa_info)1181return -EINVAL;11821183sbdf = (pci_domain_nr(adev->pdev->bus) << 16);1184sbdf |= pci_dev_id(adev->pdev);1185dev_info = amdgpu_acpi_get_dev(sbdf);1186if (!dev_info)1187return -ENOENT;11881189list_for_each_entry(xcc_info, &dev_info->xcc_list, list) {1190if (xcc_info->phy_id == xcc_id) {1191memcpy(numa_info, xcc_info->numa_info,1192sizeof(*numa_info));1193return 0;1194}1195}11961197return -ENOENT;1198}11991200/**1201* amdgpu_acpi_event - handle notify events1202*1203* @nb: notifier block1204* @val: val1205* @data: acpi event1206*1207* Calls relevant amdgpu functions in response to various1208* acpi events.1209* Returns NOTIFY code1210*/1211static int amdgpu_acpi_event(struct notifier_block *nb,1212unsigned long val,1213void *data)1214{1215struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, acpi_nb);1216struct acpi_bus_event *entry = (struct acpi_bus_event *)data;12171218if (strcmp(entry->device_class, ACPI_AC_CLASS) == 0) {1219if (power_supply_is_system_supplied() > 0)1220DRM_DEBUG_DRIVER("pm: AC\n");1221else1222DRM_DEBUG_DRIVER("pm: DC\n");12231224amdgpu_pm_acpi_event_handler(adev);1225}12261227/* Check for pending SBIOS requests */1228return amdgpu_atif_handler(adev, entry);1229}12301231/* Call all ACPI methods here */1232/**1233* amdgpu_acpi_init - init driver acpi support1234*1235* @adev: amdgpu_device pointer1236*1237* Verifies the AMD ACPI interfaces and registers with the acpi1238* notifier chain (all asics).1239* Returns 0 on success, error on failure.1240*/1241int amdgpu_acpi_init(struct amdgpu_device *adev)1242{1243struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;12441245if (atif->notifications.brightness_change) {1246if (adev->dc_enabled) {1247#if defined(CONFIG_DRM_AMD_DC)1248struct amdgpu_display_manager *dm = &adev->dm;12491250if (dm->backlight_dev[0])1251atif->bd = dm->backlight_dev[0];1252#endif1253} else {1254struct drm_encoder *tmp;12551256/* Find the encoder controlling the brightness */1257list_for_each_entry(tmp, &adev_to_drm(adev)->mode_config.encoder_list,1258head) {1259struct amdgpu_encoder *enc = to_amdgpu_encoder(tmp);12601261if ((enc->devices & (ATOM_DEVICE_LCD_SUPPORT)) &&1262enc->enc_priv) {1263struct amdgpu_encoder_atom_dig *dig = enc->enc_priv;12641265if (dig->bl_dev) {1266atif->bd = dig->bl_dev;1267break;1268}1269}1270}1271}1272}1273adev->acpi_nb.notifier_call = amdgpu_acpi_event;1274register_acpi_notifier(&adev->acpi_nb);12751276return 0;1277}12781279void amdgpu_acpi_get_backlight_caps(struct amdgpu_dm_backlight_caps *caps)1280{1281struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;12821283memcpy(caps, &atif->backlight_caps, sizeof(*caps));1284}12851286/**1287* amdgpu_acpi_fini - tear down driver acpi support1288*1289* @adev: amdgpu_device pointer1290*1291* Unregisters with the acpi notifier chain (all asics).1292*/1293void amdgpu_acpi_fini(struct amdgpu_device *adev)1294{1295unregister_acpi_notifier(&adev->acpi_nb);1296}12971298/**1299* amdgpu_atif_pci_probe_handle - look up the ATIF handle1300*1301* @pdev: pci device1302*1303* Look up the ATIF handles (all asics).1304* Returns true if the handle is found, false if not.1305*/1306static bool amdgpu_atif_pci_probe_handle(struct pci_dev *pdev)1307{1308char acpi_method_name[255] = { 0 };1309struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};1310acpi_handle dhandle, atif_handle;1311acpi_status status;1312int ret;13131314dhandle = ACPI_HANDLE(&pdev->dev);1315if (!dhandle)1316return false;13171318status = acpi_get_handle(dhandle, "ATIF", &atif_handle);1319if (ACPI_FAILURE(status))1320return false;13211322amdgpu_acpi_priv.atif.handle = atif_handle;1323acpi_get_name(amdgpu_acpi_priv.atif.handle, ACPI_FULL_PATHNAME, &buffer);1324DRM_DEBUG_DRIVER("Found ATIF handle %s\n", acpi_method_name);1325ret = amdgpu_atif_verify_interface(&amdgpu_acpi_priv.atif);1326if (ret) {1327amdgpu_acpi_priv.atif.handle = 0;1328return false;1329}1330return true;1331}13321333/**1334* amdgpu_atcs_pci_probe_handle - look up the ATCS handle1335*1336* @pdev: pci device1337*1338* Look up the ATCS handles (all asics).1339* Returns true if the handle is found, false if not.1340*/1341static bool amdgpu_atcs_pci_probe_handle(struct pci_dev *pdev)1342{1343char acpi_method_name[255] = { 0 };1344struct acpi_buffer buffer = { sizeof(acpi_method_name), acpi_method_name };1345acpi_handle dhandle, atcs_handle;1346acpi_status status;1347int ret;13481349dhandle = ACPI_HANDLE(&pdev->dev);1350if (!dhandle)1351return false;13521353status = acpi_get_handle(dhandle, "ATCS", &atcs_handle);1354if (ACPI_FAILURE(status))1355return false;13561357amdgpu_acpi_priv.atcs.handle = atcs_handle;1358acpi_get_name(amdgpu_acpi_priv.atcs.handle, ACPI_FULL_PATHNAME, &buffer);1359DRM_DEBUG_DRIVER("Found ATCS handle %s\n", acpi_method_name);1360ret = amdgpu_atcs_verify_interface(&amdgpu_acpi_priv.atcs);1361if (ret) {1362amdgpu_acpi_priv.atcs.handle = 0;1363return false;1364}1365return true;1366}136713681369/**1370* amdgpu_acpi_should_gpu_reset1371*1372* @adev: amdgpu_device_pointer1373*1374* returns true if should reset GPU, false if not1375*/1376bool amdgpu_acpi_should_gpu_reset(struct amdgpu_device *adev)1377{1378if ((adev->flags & AMD_IS_APU) &&1379adev->gfx.imu.funcs) /* Not need to do mode2 reset for IMU enabled APUs */1380return false;13811382if ((adev->flags & AMD_IS_APU) &&1383amdgpu_acpi_is_s3_active(adev))1384return false;13851386if (amdgpu_sriov_vf(adev))1387return false;13881389#if IS_ENABLED(CONFIG_SUSPEND)1390return pm_suspend_target_state != PM_SUSPEND_TO_IDLE;1391#else1392return true;1393#endif1394}13951396/*1397* amdgpu_acpi_detect - detect ACPI ATIF/ATCS methods1398*1399* Check if we have the ATIF/ATCS methods and populate1400* the structures in the driver.1401*/1402void amdgpu_acpi_detect(void)1403{1404struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;1405struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;1406struct pci_dev *pdev = NULL;1407int ret;14081409while ((pdev = pci_get_base_class(PCI_BASE_CLASS_DISPLAY, pdev))) {1410if ((pdev->class != PCI_CLASS_DISPLAY_VGA << 8) &&1411(pdev->class != PCI_CLASS_DISPLAY_OTHER << 8))1412continue;14131414if (!atif->handle)1415amdgpu_atif_pci_probe_handle(pdev);1416if (!atcs->handle)1417amdgpu_atcs_pci_probe_handle(pdev);1418}14191420if (atif->functions.sbios_requests && !atif->functions.system_params) {1421/* XXX check this workraround, if sbios request function is1422* present we have to see how it's configured in the system1423* params1424*/1425atif->functions.system_params = true;1426}14271428if (atif->functions.system_params) {1429ret = amdgpu_atif_get_notification_params(atif);1430if (ret) {1431DRM_DEBUG_DRIVER("Call to GET_SYSTEM_PARAMS failed: %d\n",1432ret);1433/* Disable notification */1434atif->notification_cfg.enabled = false;1435}1436}14371438if (atif->functions.query_backlight_transfer_characteristics) {1439ret = amdgpu_atif_query_backlight_caps(atif);1440if (ret) {1441DRM_DEBUG_DRIVER("Call to QUERY_BACKLIGHT_TRANSFER_CHARACTERISTICS failed: %d\n",1442ret);1443atif->backlight_caps.caps_valid = false;1444}1445} else {1446atif->backlight_caps.caps_valid = false;1447}14481449amdgpu_acpi_enumerate_xcc();1450}14511452void amdgpu_acpi_release(void)1453{1454struct amdgpu_acpi_dev_info *dev_info, *dev_tmp;1455struct amdgpu_acpi_xcc_info *xcc_info, *xcc_tmp;1456struct amdgpu_numa_info *numa_info;1457unsigned long index;14581459xa_for_each(&numa_info_xa, index, numa_info) {1460kfree(numa_info);1461xa_erase(&numa_info_xa, index);1462}14631464if (list_empty(&amdgpu_acpi_dev_list))1465return;14661467list_for_each_entry_safe(dev_info, dev_tmp, &amdgpu_acpi_dev_list,1468list) {1469list_for_each_entry_safe(xcc_info, xcc_tmp, &dev_info->xcc_list,1470list) {1471list_del(&xcc_info->list);1472kfree(xcc_info);1473}14741475list_del(&dev_info->list);1476kfree(dev_info);1477}1478}14791480#if IS_ENABLED(CONFIG_SUSPEND)1481/**1482* amdgpu_acpi_is_s3_active1483*1484* @adev: amdgpu_device_pointer1485*1486* returns true if supported, false if not.1487*/1488bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev)1489{1490return !(adev->flags & AMD_IS_APU) ||1491(pm_suspend_target_state == PM_SUSPEND_MEM);1492}14931494/**1495* amdgpu_acpi_is_s0ix_active1496*1497* @adev: amdgpu_device_pointer1498*1499* returns true if supported, false if not.1500*/1501bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev)1502{1503if (!(adev->flags & AMD_IS_APU) ||1504(pm_suspend_target_state != PM_SUSPEND_TO_IDLE))1505return false;15061507if (adev->asic_type < CHIP_RAVEN)1508return false;15091510if (!(adev->pm.pp_feature & PP_GFXOFF_MASK))1511return false;15121513/*1514* If ACPI_FADT_LOW_POWER_S0 is not set in the FADT, it is generally1515* risky to do any special firmware-related preparations for entering1516* S0ix even though the system is suspending to idle, so return false1517* in that case.1518*/1519if (!(acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0)) {1520dev_err_once(adev->dev,1521"Power consumption will be higher as BIOS has not been configured for suspend-to-idle.\n"1522"To use suspend-to-idle change the sleep mode in BIOS setup.\n");1523return false;1524}15251526#if !IS_ENABLED(CONFIG_AMD_PMC)1527dev_err_once(adev->dev,1528"Power consumption will be higher as the kernel has not been compiled with CONFIG_AMD_PMC.\n");1529return false;1530#else1531return true;1532#endif /* CONFIG_AMD_PMC */1533}1534#endif /* CONFIG_SUSPEND */15351536#if IS_ENABLED(CONFIG_DRM_AMD_ISP)1537static const struct acpi_device_id isp_sensor_ids[] = {1538{ "OMNI5C10" },1539{ }1540};15411542static int isp_match_acpi_device_ids(struct device *dev, const void *data)1543{1544return acpi_match_device(data, dev) ? 1 : 0;1545}15461547int amdgpu_acpi_get_isp4_dev(struct acpi_device **dev)1548{1549struct device *pdev __free(put_device) = NULL;1550struct acpi_device *acpi_pdev;15511552pdev = bus_find_device(&platform_bus_type, NULL, isp_sensor_ids,1553isp_match_acpi_device_ids);1554if (!pdev)1555return -EINVAL;15561557acpi_pdev = ACPI_COMPANION(pdev);1558if (!acpi_pdev)1559return -ENODEV;15601561*dev = acpi_pdev;15621563return 0;1564}1565#endif /* CONFIG_DRM_AMD_ISP */156615671568