// SPDX-License-Identifier: MIT /* * Copyright 2012 Advanced Micro Devices, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * */ #include <linux/pci.h> #include <linux/acpi.h> #include <linux/backlight.h> #include <linux/slab.h> #include <linux/xarray.h> #include <linux/power_supply.h> #include <linux/pm_runtime.h> #include <linux/suspend.h> #include <acpi/video.h> #include <acpi/actbl.h> #include "amdgpu.h" #include "amdgpu_pm.h" #include "amdgpu_display.h" #include "amd_acpi.h" #include "atom.h" /* Declare GUID for AMD _DSM method for XCCs */ static const guid_t amd_xcc_dsm_guid = …; #define AMD_XCC_HID_START … #define AMD_XCC_DSM_GET_NUM_FUNCS … #define AMD_XCC_DSM_GET_SUPP_MODE … #define AMD_XCC_DSM_GET_XCP_MODE … #define AMD_XCC_DSM_GET_VF_XCC_MAPPING … #define AMD_XCC_DSM_GET_TMR_INFO … #define AMD_XCC_DSM_NUM_FUNCS … #define AMD_XCC_MAX_HID … struct xarray numa_info_xa; /* Encapsulates the XCD acpi object information */ struct amdgpu_acpi_xcc_info { … }; struct amdgpu_acpi_dev_info { … }; struct list_head amdgpu_acpi_dev_list; struct amdgpu_atif_notification_cfg { … }; struct amdgpu_atif_notifications { … }; struct amdgpu_atif_functions { … }; struct amdgpu_atif { … }; struct amdgpu_atcs_functions { … }; struct amdgpu_atcs { … }; static struct amdgpu_acpi_priv { … } amdgpu_acpi_priv; /* Call the ATIF method */ /** * amdgpu_atif_call - call an ATIF method * * @atif: atif structure * @function: the ATIF function to execute * @params: ATIF function params * * Executes the requested ATIF function (all asics). * Returns a pointer to the acpi output buffer. */ static union acpi_object *amdgpu_atif_call(struct amdgpu_atif *atif, int function, struct acpi_buffer *params) { … } /** * amdgpu_atif_parse_notification - parse supported notifications * * @n: supported notifications struct * @mask: supported notifications mask from ATIF * * Use the supported notifications mask from ATIF function * ATIF_FUNCTION_VERIFY_INTERFACE to determine what notifications * are supported (all asics). */ static void amdgpu_atif_parse_notification(struct amdgpu_atif_notifications *n, u32 mask) { … } /** * amdgpu_atif_parse_functions - parse supported functions * * @f: supported functions struct * @mask: supported functions mask from ATIF * * Use the supported functions mask from ATIF function * ATIF_FUNCTION_VERIFY_INTERFACE to determine what functions * are supported (all asics). */ static void amdgpu_atif_parse_functions(struct amdgpu_atif_functions *f, u32 mask) { … } /** * amdgpu_atif_verify_interface - verify ATIF * * @atif: amdgpu atif struct * * Execute the ATIF_FUNCTION_VERIFY_INTERFACE ATIF function * to initialize ATIF and determine what features are supported * (all asics). * returns 0 on success, error on failure. */ static int amdgpu_atif_verify_interface(struct amdgpu_atif *atif) { … } /** * amdgpu_atif_get_notification_params - determine notify configuration * * @atif: acpi handle * * Execute the ATIF_FUNCTION_GET_SYSTEM_PARAMETERS ATIF function * to determine if a notifier is used and if so which one * (all asics). This is either Notify(VGA, 0x81) or Notify(VGA, n) * where n is specified in the result if a notifier is used. * Returns 0 on success, error on failure. */ static int amdgpu_atif_get_notification_params(struct amdgpu_atif *atif) { … } /** * amdgpu_atif_query_backlight_caps - get min and max backlight input signal * * @atif: acpi handle * * Execute the QUERY_BRIGHTNESS_TRANSFER_CHARACTERISTICS ATIF function * to determine the acceptable range of backlight values * * Backlight_caps.caps_valid will be set to true if the query is successful * * The input signals are in range 0-255 * * This function assumes the display with backlight is the first LCD * * Returns 0 on success, error on failure. */ static int amdgpu_atif_query_backlight_caps(struct amdgpu_atif *atif) { … } /** * amdgpu_atif_get_sbios_requests - get requested sbios event * * @atif: acpi handle * @req: atif sbios request struct * * Execute the ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS ATIF function * to determine what requests the sbios is making to the driver * (all asics). * Returns 0 on success, error on failure. */ static int amdgpu_atif_get_sbios_requests(struct amdgpu_atif *atif, struct atif_sbios_requests *req) { … } /** * amdgpu_atif_handler - handle ATIF notify requests * * @adev: amdgpu_device pointer * @event: atif sbios request struct * * Checks the acpi event and if it matches an atif event, * handles it. * * Returns: * NOTIFY_BAD or NOTIFY_DONE, depending on the event. */ static int amdgpu_atif_handler(struct amdgpu_device *adev, struct acpi_bus_event *event) { … } /* Call the ATCS method */ /** * amdgpu_atcs_call - call an ATCS method * * @atcs: atcs structure * @function: the ATCS function to execute * @params: ATCS function params * * Executes the requested ATCS function (all asics). * Returns a pointer to the acpi output buffer. */ static union acpi_object *amdgpu_atcs_call(struct amdgpu_atcs *atcs, int function, struct acpi_buffer *params) { … } /** * amdgpu_atcs_parse_functions - parse supported functions * * @f: supported functions struct * @mask: supported functions mask from ATCS * * Use the supported functions mask from ATCS function * ATCS_FUNCTION_VERIFY_INTERFACE to determine what functions * are supported (all asics). */ static void amdgpu_atcs_parse_functions(struct amdgpu_atcs_functions *f, u32 mask) { … } /** * amdgpu_atcs_verify_interface - verify ATCS * * @atcs: amdgpu atcs struct * * Execute the ATCS_FUNCTION_VERIFY_INTERFACE ATCS function * to initialize ATCS and determine what features are supported * (all asics). * returns 0 on success, error on failure. */ static int amdgpu_atcs_verify_interface(struct amdgpu_atcs *atcs) { … } /** * amdgpu_acpi_is_pcie_performance_request_supported * * @adev: amdgpu_device pointer * * Check if the ATCS pcie_perf_req and pcie_dev_rdy methods * are supported (all asics). * returns true if supported, false if not. */ bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev) { … } /** * amdgpu_acpi_is_power_shift_control_supported * * Check if the ATCS power shift control method * is supported. * returns true if supported, false if not. */ bool amdgpu_acpi_is_power_shift_control_supported(void) { … } /** * amdgpu_acpi_pcie_notify_device_ready * * @adev: amdgpu_device pointer * * Executes the PCIE_DEVICE_READY_NOTIFICATION method * (all asics). * returns 0 on success, error on failure. */ int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev) { … } /** * amdgpu_acpi_pcie_performance_request * * @adev: amdgpu_device pointer * @perf_req: requested perf level (pcie gen speed) * @advertise: set advertise caps flag if set * * Executes the PCIE_PERFORMANCE_REQUEST method to * change the pcie gen speed (all asics). * returns 0 on success, error on failure. */ int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev, u8 perf_req, bool advertise) { … } /** * amdgpu_acpi_power_shift_control * * @adev: amdgpu_device pointer * @dev_state: device acpi state * @drv_state: driver state * * Executes the POWER_SHIFT_CONTROL method to * communicate current dGPU device state and * driver state to APU/SBIOS. * returns 0 on success, error on failure. */ int amdgpu_acpi_power_shift_control(struct amdgpu_device *adev, u8 dev_state, bool drv_state) { … } /** * amdgpu_acpi_smart_shift_update - update dGPU device state to SBIOS * * @dev: drm_device pointer * @ss_state: current smart shift event * * returns 0 on success, * otherwise return error number. */ int amdgpu_acpi_smart_shift_update(struct drm_device *dev, enum amdgpu_ss ss_state) { … } #ifdef CONFIG_ACPI_NUMA static inline uint64_t amdgpu_acpi_get_numa_size(int nid) { … } static struct amdgpu_numa_info *amdgpu_acpi_get_numa_info(uint32_t pxm) { … } #endif /** * amdgpu_acpi_get_node_id - obtain the NUMA node id for corresponding amdgpu * acpi device handle * * @handle: acpi handle * @numa_info: amdgpu_numa_info structure holding numa information * * Queries the ACPI interface to fetch the corresponding NUMA Node ID for a * given amdgpu acpi device. * * Returns ACPI STATUS OK with Node ID on success or the corresponding failure reason */ static acpi_status amdgpu_acpi_get_node_id(acpi_handle handle, struct amdgpu_numa_info **numa_info) { … } static struct amdgpu_acpi_dev_info *amdgpu_acpi_get_dev(u32 sbdf) { … } static int amdgpu_acpi_dev_init(struct amdgpu_acpi_dev_info **dev_info, struct amdgpu_acpi_xcc_info *xcc_info, u32 sbdf) { … } static int amdgpu_acpi_get_xcc_info(struct amdgpu_acpi_xcc_info *xcc_info, u32 *sbdf) { … } static int amdgpu_acpi_enumerate_xcc(void) { … } int amdgpu_acpi_get_tmr_info(struct amdgpu_device *adev, u64 *tmr_offset, u64 *tmr_size) { … } int amdgpu_acpi_get_mem_info(struct amdgpu_device *adev, int xcc_id, struct amdgpu_numa_info *numa_info) { … } /** * amdgpu_acpi_event - handle notify events * * @nb: notifier block * @val: val * @data: acpi event * * Calls relevant amdgpu functions in response to various * acpi events. * Returns NOTIFY code */ static int amdgpu_acpi_event(struct notifier_block *nb, unsigned long val, void *data) { … } /* Call all ACPI methods here */ /** * amdgpu_acpi_init - init driver acpi support * * @adev: amdgpu_device pointer * * Verifies the AMD ACPI interfaces and registers with the acpi * notifier chain (all asics). * Returns 0 on success, error on failure. */ int amdgpu_acpi_init(struct amdgpu_device *adev) { … } void amdgpu_acpi_get_backlight_caps(struct amdgpu_dm_backlight_caps *caps) { … } /** * amdgpu_acpi_fini - tear down driver acpi support * * @adev: amdgpu_device pointer * * Unregisters with the acpi notifier chain (all asics). */ void amdgpu_acpi_fini(struct amdgpu_device *adev) { … } /** * amdgpu_atif_pci_probe_handle - look up the ATIF handle * * @pdev: pci device * * Look up the ATIF handles (all asics). * Returns true if the handle is found, false if not. */ static bool amdgpu_atif_pci_probe_handle(struct pci_dev *pdev) { … } /** * amdgpu_atcs_pci_probe_handle - look up the ATCS handle * * @pdev: pci device * * Look up the ATCS handles (all asics). * Returns true if the handle is found, false if not. */ static bool amdgpu_atcs_pci_probe_handle(struct pci_dev *pdev) { … } /** * amdgpu_acpi_should_gpu_reset * * @adev: amdgpu_device_pointer * * returns true if should reset GPU, false if not */ bool amdgpu_acpi_should_gpu_reset(struct amdgpu_device *adev) { … } /* * amdgpu_acpi_detect - detect ACPI ATIF/ATCS methods * * Check if we have the ATIF/ATCS methods and populate * the structures in the driver. */ void amdgpu_acpi_detect(void) { … } void amdgpu_acpi_release(void) { … } #if IS_ENABLED(CONFIG_SUSPEND) /** * amdgpu_acpi_is_s3_active * * @adev: amdgpu_device_pointer * * returns true if supported, false if not. */ bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev) { … } /** * amdgpu_acpi_is_s0ix_active * * @adev: amdgpu_device_pointer * * returns true if supported, false if not. */ bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev) { … } /** * amdgpu_choose_low_power_state * * @adev: amdgpu_device_pointer * * Choose the target low power state for the GPU */ void amdgpu_choose_low_power_state(struct amdgpu_device *adev) { … } #endif /* CONFIG_SUSPEND */