Path: blob/master/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
49231 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_put_autosuspend(adev_to_drm(adev)->dev);510}511}512/* TODO: check other events */513}514515/* We've handled the event, stop the notifier chain. The ACPI interface516* overloads ACPI_VIDEO_NOTIFY_PROBE, we don't want to send that to517* userspace if the event was generated only to signal a SBIOS518* request.519*/520return NOTIFY_BAD;521}522523/* Call the ATCS method524*/525/**526* amdgpu_atcs_call - call an ATCS method527*528* @atcs: atcs structure529* @function: the ATCS function to execute530* @params: ATCS function params531*532* Executes the requested ATCS function (all asics).533* Returns a pointer to the acpi output buffer.534*/535static union acpi_object *amdgpu_atcs_call(struct amdgpu_atcs *atcs,536int function,537struct acpi_buffer *params)538{539acpi_status status;540union acpi_object atcs_arg_elements[2];541struct acpi_object_list atcs_arg;542struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };543544atcs_arg.count = 2;545atcs_arg.pointer = &atcs_arg_elements[0];546547atcs_arg_elements[0].type = ACPI_TYPE_INTEGER;548atcs_arg_elements[0].integer.value = function;549550if (params) {551atcs_arg_elements[1].type = ACPI_TYPE_BUFFER;552atcs_arg_elements[1].buffer.length = params->length;553atcs_arg_elements[1].buffer.pointer = params->pointer;554} else {555/* We need a second fake parameter */556atcs_arg_elements[1].type = ACPI_TYPE_INTEGER;557atcs_arg_elements[1].integer.value = 0;558}559560status = acpi_evaluate_object(atcs->handle, NULL, &atcs_arg, &buffer);561562/* Fail only if calling the method fails and ATIF is supported */563if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {564DRM_DEBUG_DRIVER("failed to evaluate ATCS got %s\n",565acpi_format_exception(status));566kfree(buffer.pointer);567return NULL;568}569570return buffer.pointer;571}572573/**574* amdgpu_atcs_parse_functions - parse supported functions575*576* @f: supported functions struct577* @mask: supported functions mask from ATCS578*579* Use the supported functions mask from ATCS function580* ATCS_FUNCTION_VERIFY_INTERFACE to determine what functions581* are supported (all asics).582*/583static void amdgpu_atcs_parse_functions(struct amdgpu_atcs_functions *f, u32 mask)584{585f->get_ext_state = mask & ATCS_GET_EXTERNAL_STATE_SUPPORTED;586f->pcie_perf_req = mask & ATCS_PCIE_PERFORMANCE_REQUEST_SUPPORTED;587f->pcie_dev_rdy = mask & ATCS_PCIE_DEVICE_READY_NOTIFICATION_SUPPORTED;588f->pcie_bus_width = mask & ATCS_SET_PCIE_BUS_WIDTH_SUPPORTED;589f->power_shift_control = mask & ATCS_SET_POWER_SHIFT_CONTROL_SUPPORTED;590}591592/**593* amdgpu_atcs_verify_interface - verify ATCS594*595* @atcs: amdgpu atcs struct596*597* Execute the ATCS_FUNCTION_VERIFY_INTERFACE ATCS function598* to initialize ATCS and determine what features are supported599* (all asics).600* returns 0 on success, error on failure.601*/602static int amdgpu_atcs_verify_interface(struct amdgpu_atcs *atcs)603{604union acpi_object *info;605struct atcs_verify_interface output;606size_t size;607int err = 0;608609info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_VERIFY_INTERFACE, NULL);610if (!info)611return -EIO;612613memset(&output, 0, sizeof(output));614615size = *(u16 *) info->buffer.pointer;616if (size < 8) {617DRM_INFO("ATCS buffer is too small: %zu\n", size);618err = -EINVAL;619goto out;620}621size = min(sizeof(output), size);622623memcpy(&output, info->buffer.pointer, size);624625/* TODO: check version? */626DRM_DEBUG_DRIVER("ATCS version %u\n", output.version);627628amdgpu_atcs_parse_functions(&atcs->functions, output.function_bits);629630out:631kfree(info);632return err;633}634635/**636* amdgpu_acpi_is_pcie_performance_request_supported637*638* @adev: amdgpu_device pointer639*640* Check if the ATCS pcie_perf_req and pcie_dev_rdy methods641* are supported (all asics).642* returns true if supported, false if not.643*/644bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev)645{646struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;647648if (atcs->functions.pcie_perf_req && atcs->functions.pcie_dev_rdy)649return true;650651return false;652}653654/**655* amdgpu_acpi_is_power_shift_control_supported656*657* Check if the ATCS power shift control method658* is supported.659* returns true if supported, false if not.660*/661bool amdgpu_acpi_is_power_shift_control_supported(void)662{663return amdgpu_acpi_priv.atcs.functions.power_shift_control;664}665666/**667* amdgpu_acpi_pcie_notify_device_ready668*669* @adev: amdgpu_device pointer670*671* Executes the PCIE_DEVICE_READY_NOTIFICATION method672* (all asics).673* returns 0 on success, error on failure.674*/675int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev)676{677union acpi_object *info;678struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;679680if (!atcs->functions.pcie_dev_rdy)681return -EINVAL;682683info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_PCIE_DEVICE_READY_NOTIFICATION, NULL);684if (!info)685return -EIO;686687kfree(info);688689return 0;690}691692/**693* amdgpu_acpi_pcie_performance_request694*695* @adev: amdgpu_device pointer696* @perf_req: requested perf level (pcie gen speed)697* @advertise: set advertise caps flag if set698*699* Executes the PCIE_PERFORMANCE_REQUEST method to700* change the pcie gen speed (all asics).701* returns 0 on success, error on failure.702*/703int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,704u8 perf_req, bool advertise)705{706union acpi_object *info;707struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;708struct atcs_pref_req_input atcs_input;709struct atcs_pref_req_output atcs_output;710struct acpi_buffer params;711size_t size;712u32 retry = 3;713714if (amdgpu_acpi_pcie_notify_device_ready(adev))715return -EINVAL;716717if (!atcs->functions.pcie_perf_req)718return -EINVAL;719720atcs_input.size = sizeof(struct atcs_pref_req_input);721/* client id (bit 2-0: func num, 7-3: dev num, 15-8: bus num) */722atcs_input.client_id = pci_dev_id(adev->pdev);723atcs_input.valid_flags_mask = ATCS_VALID_FLAGS_MASK;724atcs_input.flags = ATCS_WAIT_FOR_COMPLETION;725if (advertise)726atcs_input.flags |= ATCS_ADVERTISE_CAPS;727atcs_input.req_type = ATCS_PCIE_LINK_SPEED;728atcs_input.perf_req = perf_req;729730params.length = sizeof(struct atcs_pref_req_input);731params.pointer = &atcs_input;732733while (retry--) {734info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_PCIE_PERFORMANCE_REQUEST, ¶ms);735if (!info)736return -EIO;737738memset(&atcs_output, 0, sizeof(atcs_output));739740size = *(u16 *) info->buffer.pointer;741if (size < 3) {742DRM_INFO("ATCS buffer is too small: %zu\n", size);743kfree(info);744return -EINVAL;745}746size = min(sizeof(atcs_output), size);747748memcpy(&atcs_output, info->buffer.pointer, size);749750kfree(info);751752switch (atcs_output.ret_val) {753case ATCS_REQUEST_REFUSED:754default:755return -EINVAL;756case ATCS_REQUEST_COMPLETE:757return 0;758case ATCS_REQUEST_IN_PROGRESS:759udelay(10);760break;761}762}763764return 0;765}766767/**768* amdgpu_acpi_power_shift_control769*770* @adev: amdgpu_device pointer771* @dev_state: device acpi state772* @drv_state: driver state773*774* Executes the POWER_SHIFT_CONTROL method to775* communicate current dGPU device state and776* driver state to APU/SBIOS.777* returns 0 on success, error on failure.778*/779int amdgpu_acpi_power_shift_control(struct amdgpu_device *adev,780u8 dev_state, bool drv_state)781{782union acpi_object *info;783struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;784struct atcs_pwr_shift_input atcs_input;785struct acpi_buffer params;786787if (!amdgpu_acpi_is_power_shift_control_supported())788return -EINVAL;789790atcs_input.size = sizeof(struct atcs_pwr_shift_input);791/* dGPU id (bit 2-0: func num, 7-3: dev num, 15-8: bus num) */792atcs_input.dgpu_id = pci_dev_id(adev->pdev);793atcs_input.dev_acpi_state = dev_state;794atcs_input.drv_state = drv_state;795796params.length = sizeof(struct atcs_pwr_shift_input);797params.pointer = &atcs_input;798799info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_POWER_SHIFT_CONTROL, ¶ms);800if (!info) {801DRM_ERROR("ATCS PSC update failed\n");802return -EIO;803}804805kfree(info);806return 0;807}808809/**810* amdgpu_acpi_smart_shift_update - update dGPU device state to SBIOS811*812* @adev: amdgpu device pointer813* @ss_state: current smart shift event814*815* returns 0 on success,816* otherwise return error number.817*/818int amdgpu_acpi_smart_shift_update(struct amdgpu_device *adev,819enum amdgpu_ss ss_state)820{821int r;822823if (!amdgpu_device_supports_smart_shift(adev))824return 0;825826switch (ss_state) {827/* SBIOS trigger “stop”, “enable” and “start” at D0, Driver Operational.828* SBIOS trigger “stop” at D3, Driver Not Operational.829* SBIOS trigger “stop” and “disable” at D0, Driver NOT operational.830*/831case AMDGPU_SS_DRV_LOAD:832r = amdgpu_acpi_power_shift_control(adev,833AMDGPU_ATCS_PSC_DEV_STATE_D0,834AMDGPU_ATCS_PSC_DRV_STATE_OPR);835break;836case AMDGPU_SS_DEV_D0:837r = amdgpu_acpi_power_shift_control(adev,838AMDGPU_ATCS_PSC_DEV_STATE_D0,839AMDGPU_ATCS_PSC_DRV_STATE_OPR);840break;841case AMDGPU_SS_DEV_D3:842r = amdgpu_acpi_power_shift_control(adev,843AMDGPU_ATCS_PSC_DEV_STATE_D3_HOT,844AMDGPU_ATCS_PSC_DRV_STATE_NOT_OPR);845break;846case AMDGPU_SS_DRV_UNLOAD:847r = amdgpu_acpi_power_shift_control(adev,848AMDGPU_ATCS_PSC_DEV_STATE_D0,849AMDGPU_ATCS_PSC_DRV_STATE_NOT_OPR);850break;851default:852return -EINVAL;853}854855return r;856}857858#ifdef CONFIG_ACPI_NUMA859static inline uint64_t amdgpu_acpi_get_numa_size(int nid)860{861/* This is directly using si_meminfo_node implementation as the862* function is not exported.863*/864int zone_type;865uint64_t managed_pages = 0;866867pg_data_t *pgdat = NODE_DATA(nid);868869for (zone_type = 0; zone_type < MAX_NR_ZONES; zone_type++)870managed_pages +=871zone_managed_pages(&pgdat->node_zones[zone_type]);872return managed_pages * PAGE_SIZE;873}874875static struct amdgpu_numa_info *amdgpu_acpi_get_numa_info(uint32_t pxm)876{877struct amdgpu_numa_info *numa_info;878int nid;879880numa_info = xa_load(&numa_info_xa, pxm);881882if (!numa_info) {883struct sysinfo info;884885numa_info = kzalloc(sizeof(*numa_info), GFP_KERNEL);886if (!numa_info)887return NULL;888889nid = pxm_to_node(pxm);890numa_info->pxm = pxm;891numa_info->nid = nid;892893if (numa_info->nid == NUMA_NO_NODE) {894si_meminfo(&info);895numa_info->size = info.totalram * info.mem_unit;896} else {897numa_info->size = amdgpu_acpi_get_numa_size(nid);898}899xa_store(&numa_info_xa, numa_info->pxm, numa_info, GFP_KERNEL);900}901902return numa_info;903}904#endif905906/**907* amdgpu_acpi_get_node_id - obtain the NUMA node id for corresponding amdgpu908* acpi device handle909*910* @handle: acpi handle911* @numa_info: amdgpu_numa_info structure holding numa information912*913* Queries the ACPI interface to fetch the corresponding NUMA Node ID for a914* given amdgpu acpi device.915*916* Returns ACPI STATUS OK with Node ID on success or the corresponding failure reason917*/918static acpi_status amdgpu_acpi_get_node_id(acpi_handle handle,919struct amdgpu_numa_info **numa_info)920{921#ifdef CONFIG_ACPI_NUMA922u64 pxm;923acpi_status status;924925if (!numa_info)926return_ACPI_STATUS(AE_ERROR);927928status = acpi_evaluate_integer(handle, "_PXM", NULL, &pxm);929930if (ACPI_FAILURE(status))931return status;932933*numa_info = amdgpu_acpi_get_numa_info(pxm);934935if (!*numa_info)936return_ACPI_STATUS(AE_ERROR);937938return_ACPI_STATUS(AE_OK);939#else940return_ACPI_STATUS(AE_NOT_EXIST);941#endif942}943944static struct amdgpu_acpi_dev_info *amdgpu_acpi_get_dev(u32 sbdf)945{946struct amdgpu_acpi_dev_info *acpi_dev;947948if (list_empty(&amdgpu_acpi_dev_list))949return NULL;950951list_for_each_entry(acpi_dev, &amdgpu_acpi_dev_list, list)952if (acpi_dev->sbdf == sbdf)953return acpi_dev;954955return NULL;956}957958static int amdgpu_acpi_dev_init(struct amdgpu_acpi_dev_info **dev_info,959struct amdgpu_acpi_xcc_info *xcc_info, u32 sbdf)960{961struct amdgpu_acpi_dev_info *tmp;962union acpi_object *obj;963int ret = -ENOENT;964965*dev_info = NULL;966tmp = kzalloc(sizeof(struct amdgpu_acpi_dev_info), GFP_KERNEL);967if (!tmp)968return -ENOMEM;969970INIT_LIST_HEAD(&tmp->xcc_list);971INIT_LIST_HEAD(&tmp->list);972tmp->sbdf = sbdf;973974obj = acpi_evaluate_dsm_typed(xcc_info->handle, &amd_xcc_dsm_guid, 0,975AMD_XCC_DSM_GET_SUPP_MODE, NULL,976ACPI_TYPE_INTEGER);977978if (!obj) {979acpi_handle_debug(xcc_info->handle,980"_DSM function %d evaluation failed",981AMD_XCC_DSM_GET_SUPP_MODE);982ret = -ENOENT;983goto out;984}985986tmp->supp_xcp_mode = obj->integer.value & 0xFFFF;987ACPI_FREE(obj);988989obj = acpi_evaluate_dsm_typed(xcc_info->handle, &amd_xcc_dsm_guid, 0,990AMD_XCC_DSM_GET_XCP_MODE, NULL,991ACPI_TYPE_INTEGER);992993if (!obj) {994acpi_handle_debug(xcc_info->handle,995"_DSM function %d evaluation failed",996AMD_XCC_DSM_GET_XCP_MODE);997ret = -ENOENT;998goto out;999}10001001tmp->xcp_mode = obj->integer.value & 0xFFFF;1002tmp->mem_mode = (obj->integer.value >> 32) & 0xFFFF;1003ACPI_FREE(obj);10041005/* Evaluate DSMs and fill XCC information */1006obj = acpi_evaluate_dsm_typed(xcc_info->handle, &amd_xcc_dsm_guid, 0,1007AMD_XCC_DSM_GET_TMR_INFO, NULL,1008ACPI_TYPE_PACKAGE);10091010if (!obj || obj->package.count < 2) {1011acpi_handle_debug(xcc_info->handle,1012"_DSM function %d evaluation failed",1013AMD_XCC_DSM_GET_TMR_INFO);1014ret = -ENOENT;1015goto out;1016}10171018tmp->tmr_base = obj->package.elements[0].integer.value;1019tmp->tmr_size = obj->package.elements[1].integer.value;1020ACPI_FREE(obj);10211022DRM_DEBUG_DRIVER(1023"New dev(%x): Supported xcp mode: %x curr xcp_mode : %x mem mode : %x, tmr base: %llx tmr size: %llx ",1024tmp->sbdf, tmp->supp_xcp_mode, tmp->xcp_mode, tmp->mem_mode,1025tmp->tmr_base, tmp->tmr_size);1026list_add_tail(&tmp->list, &amdgpu_acpi_dev_list);1027*dev_info = tmp;10281029return 0;10301031out:1032if (obj)1033ACPI_FREE(obj);1034kfree(tmp);10351036return ret;1037}10381039static int amdgpu_acpi_get_xcc_info(struct amdgpu_acpi_xcc_info *xcc_info,1040u32 *sbdf)1041{1042union acpi_object *obj;1043acpi_status status;1044int ret = -ENOENT;10451046obj = acpi_evaluate_dsm_typed(xcc_info->handle, &amd_xcc_dsm_guid, 0,1047AMD_XCC_DSM_GET_NUM_FUNCS, NULL,1048ACPI_TYPE_INTEGER);10491050if (!obj || obj->integer.value != AMD_XCC_DSM_NUM_FUNCS)1051goto out;1052ACPI_FREE(obj);10531054/* Evaluate DSMs and fill XCC information */1055obj = acpi_evaluate_dsm_typed(xcc_info->handle, &amd_xcc_dsm_guid, 0,1056AMD_XCC_DSM_GET_VF_XCC_MAPPING, NULL,1057ACPI_TYPE_INTEGER);10581059if (!obj) {1060acpi_handle_debug(xcc_info->handle,1061"_DSM function %d evaluation failed",1062AMD_XCC_DSM_GET_VF_XCC_MAPPING);1063ret = -EINVAL;1064goto out;1065}10661067/* PF xcc id [39:32] */1068xcc_info->phy_id = (obj->integer.value >> 32) & 0xFF;1069/* xcp node of this xcc [47:40] */1070xcc_info->xcp_node = (obj->integer.value >> 40) & 0xFF;1071/* PF domain of this xcc [31:16] */1072*sbdf = (obj->integer.value) & 0xFFFF0000;1073/* PF bus/dev/fn of this xcc [63:48] */1074*sbdf |= (obj->integer.value >> 48) & 0xFFFF;1075ACPI_FREE(obj);1076obj = NULL;10771078status =1079amdgpu_acpi_get_node_id(xcc_info->handle, &xcc_info->numa_info);10801081/* TODO: check if this check is required */1082if (ACPI_SUCCESS(status))1083ret = 0;1084out:1085if (obj)1086ACPI_FREE(obj);10871088return ret;1089}10901091static int amdgpu_acpi_enumerate_xcc(void)1092{1093struct amdgpu_acpi_dev_info *dev_info = NULL;1094struct amdgpu_acpi_xcc_info *xcc_info;1095struct acpi_device *acpi_dev;1096char hid[ACPI_ID_LEN];1097int ret, id;1098u32 sbdf;10991100INIT_LIST_HEAD(&amdgpu_acpi_dev_list);1101xa_init(&numa_info_xa);11021103for (id = 0; id < AMD_XCC_MAX_HID; id++) {1104sprintf(hid, "%s%d", "AMD", AMD_XCC_HID_START + id);1105acpi_dev = acpi_dev_get_first_match_dev(hid, NULL, -1);1106/* These ACPI objects are expected to be in sequential order. If1107* one is not found, no need to check the rest.1108*/1109if (!acpi_dev) {1110DRM_DEBUG_DRIVER("No matching acpi device found for %s",1111hid);1112break;1113}11141115xcc_info = kzalloc(sizeof(struct amdgpu_acpi_xcc_info),1116GFP_KERNEL);1117if (!xcc_info) {1118DRM_ERROR("Failed to allocate memory for xcc info\n");1119return -ENOMEM;1120}11211122INIT_LIST_HEAD(&xcc_info->list);1123xcc_info->handle = acpi_device_handle(acpi_dev);1124acpi_dev_put(acpi_dev);11251126ret = amdgpu_acpi_get_xcc_info(xcc_info, &sbdf);1127if (ret) {1128kfree(xcc_info);1129continue;1130}11311132dev_info = amdgpu_acpi_get_dev(sbdf);11331134if (!dev_info)1135ret = amdgpu_acpi_dev_init(&dev_info, xcc_info, sbdf);11361137if (ret == -ENOMEM)1138return ret;11391140if (!dev_info) {1141kfree(xcc_info);1142continue;1143}11441145list_add_tail(&xcc_info->list, &dev_info->xcc_list);1146}11471148return 0;1149}11501151int amdgpu_acpi_get_tmr_info(struct amdgpu_device *adev, u64 *tmr_offset,1152u64 *tmr_size)1153{1154struct amdgpu_acpi_dev_info *dev_info;1155u32 sbdf;11561157if (!tmr_offset || !tmr_size)1158return -EINVAL;11591160sbdf = (pci_domain_nr(adev->pdev->bus) << 16);1161sbdf |= pci_dev_id(adev->pdev);1162dev_info = amdgpu_acpi_get_dev(sbdf);1163if (!dev_info)1164return -ENOENT;11651166*tmr_offset = dev_info->tmr_base;1167*tmr_size = dev_info->tmr_size;11681169return 0;1170}11711172int amdgpu_acpi_get_mem_info(struct amdgpu_device *adev, int xcc_id,1173struct amdgpu_numa_info *numa_info)1174{1175struct amdgpu_acpi_dev_info *dev_info;1176struct amdgpu_acpi_xcc_info *xcc_info;1177u32 sbdf;11781179if (!numa_info)1180return -EINVAL;11811182sbdf = (pci_domain_nr(adev->pdev->bus) << 16);1183sbdf |= pci_dev_id(adev->pdev);1184dev_info = amdgpu_acpi_get_dev(sbdf);1185if (!dev_info)1186return -ENOENT;11871188list_for_each_entry(xcc_info, &dev_info->xcc_list, list) {1189if (xcc_info->phy_id == xcc_id) {1190memcpy(numa_info, xcc_info->numa_info,1191sizeof(*numa_info));1192return 0;1193}1194}11951196return -ENOENT;1197}11981199/**1200* amdgpu_acpi_event - handle notify events1201*1202* @nb: notifier block1203* @val: val1204* @data: acpi event1205*1206* Calls relevant amdgpu functions in response to various1207* acpi events.1208* Returns NOTIFY code1209*/1210static int amdgpu_acpi_event(struct notifier_block *nb,1211unsigned long val,1212void *data)1213{1214struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, acpi_nb);1215struct acpi_bus_event *entry = (struct acpi_bus_event *)data;12161217if (strcmp(entry->device_class, ACPI_AC_CLASS) == 0) {1218if (power_supply_is_system_supplied() > 0)1219DRM_DEBUG_DRIVER("pm: AC\n");1220else1221DRM_DEBUG_DRIVER("pm: DC\n");12221223amdgpu_pm_acpi_event_handler(adev);1224}12251226/* Check for pending SBIOS requests */1227return amdgpu_atif_handler(adev, entry);1228}12291230/* Call all ACPI methods here */1231/**1232* amdgpu_acpi_init - init driver acpi support1233*1234* @adev: amdgpu_device pointer1235*1236* Verifies the AMD ACPI interfaces and registers with the acpi1237* notifier chain (all asics).1238* Returns 0 on success, error on failure.1239*/1240int amdgpu_acpi_init(struct amdgpu_device *adev)1241{1242struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;12431244if (atif->notifications.brightness_change) {1245if (adev->dc_enabled) {1246#if defined(CONFIG_DRM_AMD_DC)1247struct amdgpu_display_manager *dm = &adev->dm;12481249if (dm->backlight_dev[0])1250atif->bd = dm->backlight_dev[0];1251#endif1252} else {1253struct drm_encoder *tmp;12541255/* Find the encoder controlling the brightness */1256list_for_each_entry(tmp, &adev_to_drm(adev)->mode_config.encoder_list,1257head) {1258struct amdgpu_encoder *enc = to_amdgpu_encoder(tmp);12591260if ((enc->devices & (ATOM_DEVICE_LCD_SUPPORT)) &&1261enc->enc_priv) {1262struct amdgpu_encoder_atom_dig *dig = enc->enc_priv;12631264if (dig->bl_dev) {1265atif->bd = dig->bl_dev;1266break;1267}1268}1269}1270}1271}1272adev->acpi_nb.notifier_call = amdgpu_acpi_event;1273register_acpi_notifier(&adev->acpi_nb);12741275return 0;1276}12771278void amdgpu_acpi_get_backlight_caps(struct amdgpu_dm_backlight_caps *caps)1279{1280struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;12811282memcpy(caps, &atif->backlight_caps, sizeof(*caps));1283}12841285/**1286* amdgpu_acpi_fini - tear down driver acpi support1287*1288* @adev: amdgpu_device pointer1289*1290* Unregisters with the acpi notifier chain (all asics).1291*/1292void amdgpu_acpi_fini(struct amdgpu_device *adev)1293{1294unregister_acpi_notifier(&adev->acpi_nb);1295}12961297/**1298* amdgpu_atif_pci_probe_handle - look up the ATIF handle1299*1300* @pdev: pci device1301*1302* Look up the ATIF handles (all asics).1303* Returns true if the handle is found, false if not.1304*/1305static bool amdgpu_atif_pci_probe_handle(struct pci_dev *pdev)1306{1307char acpi_method_name[255] = { 0 };1308struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};1309acpi_handle dhandle, atif_handle;1310acpi_status status;1311int ret;13121313dhandle = ACPI_HANDLE(&pdev->dev);1314if (!dhandle)1315return false;13161317status = acpi_get_handle(dhandle, "ATIF", &atif_handle);1318if (ACPI_FAILURE(status))1319return false;13201321amdgpu_acpi_priv.atif.handle = atif_handle;1322acpi_get_name(amdgpu_acpi_priv.atif.handle, ACPI_FULL_PATHNAME, &buffer);1323DRM_DEBUG_DRIVER("Found ATIF handle %s\n", acpi_method_name);1324ret = amdgpu_atif_verify_interface(&amdgpu_acpi_priv.atif);1325if (ret) {1326amdgpu_acpi_priv.atif.handle = 0;1327return false;1328}1329return true;1330}13311332/**1333* amdgpu_atcs_pci_probe_handle - look up the ATCS handle1334*1335* @pdev: pci device1336*1337* Look up the ATCS handles (all asics).1338* Returns true if the handle is found, false if not.1339*/1340static bool amdgpu_atcs_pci_probe_handle(struct pci_dev *pdev)1341{1342char acpi_method_name[255] = { 0 };1343struct acpi_buffer buffer = { sizeof(acpi_method_name), acpi_method_name };1344acpi_handle dhandle, atcs_handle;1345acpi_status status;1346int ret;13471348dhandle = ACPI_HANDLE(&pdev->dev);1349if (!dhandle)1350return false;13511352status = acpi_get_handle(dhandle, "ATCS", &atcs_handle);1353if (ACPI_FAILURE(status))1354return false;13551356amdgpu_acpi_priv.atcs.handle = atcs_handle;1357acpi_get_name(amdgpu_acpi_priv.atcs.handle, ACPI_FULL_PATHNAME, &buffer);1358DRM_DEBUG_DRIVER("Found ATCS handle %s\n", acpi_method_name);1359ret = amdgpu_atcs_verify_interface(&amdgpu_acpi_priv.atcs);1360if (ret) {1361amdgpu_acpi_priv.atcs.handle = 0;1362return false;1363}1364return true;1365}136613671368/**1369* amdgpu_acpi_should_gpu_reset1370*1371* @adev: amdgpu_device_pointer1372*1373* returns true if should reset GPU, false if not1374*/1375bool amdgpu_acpi_should_gpu_reset(struct amdgpu_device *adev)1376{1377if ((adev->flags & AMD_IS_APU) &&1378adev->gfx.imu.funcs) /* Not need to do mode2 reset for IMU enabled APUs */1379return false;13801381if ((adev->flags & AMD_IS_APU) &&1382amdgpu_acpi_is_s3_active(adev))1383return false;13841385if (amdgpu_sriov_vf(adev))1386return false;13871388#if IS_ENABLED(CONFIG_SUSPEND)1389return pm_suspend_target_state != PM_SUSPEND_TO_IDLE;1390#else1391return true;1392#endif1393}13941395/*1396* amdgpu_acpi_detect - detect ACPI ATIF/ATCS methods1397*1398* Check if we have the ATIF/ATCS methods and populate1399* the structures in the driver.1400*/1401void amdgpu_acpi_detect(void)1402{1403struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;1404struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;1405struct pci_dev *pdev = NULL;1406int ret;14071408while ((pdev = pci_get_base_class(PCI_BASE_CLASS_DISPLAY, pdev))) {1409if ((pdev->class != PCI_CLASS_DISPLAY_VGA << 8) &&1410(pdev->class != PCI_CLASS_DISPLAY_OTHER << 8))1411continue;14121413if (!atif->handle)1414amdgpu_atif_pci_probe_handle(pdev);1415if (!atcs->handle)1416amdgpu_atcs_pci_probe_handle(pdev);1417}14181419if (atif->functions.sbios_requests && !atif->functions.system_params) {1420/* XXX check this workraround, if sbios request function is1421* present we have to see how it's configured in the system1422* params1423*/1424atif->functions.system_params = true;1425}14261427if (atif->functions.system_params) {1428ret = amdgpu_atif_get_notification_params(atif);1429if (ret) {1430DRM_DEBUG_DRIVER("Call to GET_SYSTEM_PARAMS failed: %d\n",1431ret);1432/* Disable notification */1433atif->notification_cfg.enabled = false;1434}1435}14361437if (atif->functions.query_backlight_transfer_characteristics) {1438ret = amdgpu_atif_query_backlight_caps(atif);1439if (ret) {1440DRM_DEBUG_DRIVER("Call to QUERY_BACKLIGHT_TRANSFER_CHARACTERISTICS failed: %d\n",1441ret);1442atif->backlight_caps.caps_valid = false;1443}1444} else {1445atif->backlight_caps.caps_valid = false;1446}14471448amdgpu_acpi_enumerate_xcc();1449}14501451void amdgpu_acpi_release(void)1452{1453struct amdgpu_acpi_dev_info *dev_info, *dev_tmp;1454struct amdgpu_acpi_xcc_info *xcc_info, *xcc_tmp;1455struct amdgpu_numa_info *numa_info;1456unsigned long index;14571458xa_for_each(&numa_info_xa, index, numa_info) {1459kfree(numa_info);1460xa_erase(&numa_info_xa, index);1461}14621463if (list_empty(&amdgpu_acpi_dev_list))1464return;14651466list_for_each_entry_safe(dev_info, dev_tmp, &amdgpu_acpi_dev_list,1467list) {1468list_for_each_entry_safe(xcc_info, xcc_tmp, &dev_info->xcc_list,1469list) {1470list_del(&xcc_info->list);1471kfree(xcc_info);1472}14731474list_del(&dev_info->list);1475kfree(dev_info);1476}1477}14781479#if IS_ENABLED(CONFIG_SUSPEND)1480/**1481* amdgpu_acpi_is_s3_active1482*1483* @adev: amdgpu_device_pointer1484*1485* returns true if supported, false if not.1486*/1487bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev)1488{1489return !(adev->flags & AMD_IS_APU) ||1490(pm_suspend_target_state == PM_SUSPEND_MEM);1491}14921493/**1494* amdgpu_acpi_is_s0ix_active1495*1496* @adev: amdgpu_device_pointer1497*1498* returns true if supported, false if not.1499*/1500bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev)1501{1502if (!(adev->flags & AMD_IS_APU) ||1503(pm_suspend_target_state != PM_SUSPEND_TO_IDLE))1504return false;15051506if (adev->asic_type < CHIP_RAVEN)1507return false;15081509if (!(adev->pm.pp_feature & PP_GFXOFF_MASK))1510return false;15111512/*1513* If ACPI_FADT_LOW_POWER_S0 is not set in the FADT, it is generally1514* risky to do any special firmware-related preparations for entering1515* S0ix even though the system is suspending to idle, so return false1516* in that case.1517*/1518if (!(acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0)) {1519dev_err_once(adev->dev,1520"Power consumption will be higher as BIOS has not been configured for suspend-to-idle.\n"1521"To use suspend-to-idle change the sleep mode in BIOS setup.\n");1522return false;1523}15241525#if !IS_ENABLED(CONFIG_AMD_PMC)1526dev_err_once(adev->dev,1527"Power consumption will be higher as the kernel has not been compiled with CONFIG_AMD_PMC.\n");1528return false;1529#else1530return true;1531#endif /* CONFIG_AMD_PMC */1532}1533#endif /* CONFIG_SUSPEND */15341535#if IS_ENABLED(CONFIG_DRM_AMD_ISP)1536static const struct acpi_device_id isp_sensor_ids[] = {1537{ "OMNI5C10" },1538{ }1539};15401541static int isp_match_acpi_device_ids(struct device *dev, const void *data)1542{1543return acpi_match_device(data, dev) ? 1 : 0;1544}15451546int amdgpu_acpi_get_isp4_dev(struct acpi_device **dev)1547{1548struct device *pdev __free(put_device) = NULL;1549struct acpi_device *acpi_pdev;15501551pdev = bus_find_device(&platform_bus_type, NULL, isp_sensor_ids,1552isp_match_acpi_device_ids);1553if (!pdev)1554return -EINVAL;15551556acpi_pdev = ACPI_COMPANION(pdev);1557if (!acpi_pdev)1558return -ENODEV;15591560*dev = acpi_pdev;15611562return 0;1563}1564#endif /* CONFIG_DRM_AMD_ISP */156515661567