/* * 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/acpi.h> #include <linux/backlight.h> #include <linux/pci.h> #include <linux/pm_runtime.h> #include <linux/power_supply.h> #include <linux/slab.h> #include <acpi/acpi_bus.h> #include <acpi/video.h> #include <drm/drm_probe_helper.h> #include "atom.h" #include "radeon.h" #include "radeon_acpi.h" #include "radeon_pm.h" #if defined(CONFIG_VGA_SWITCHEROO) bool radeon_atpx_dgpu_req_power_for_displays(void); #else static inline bool radeon_atpx_dgpu_req_power_for_displays(void) { return false; } #endif #define ACPI_AC_CLASS … struct atif_verify_interface { … } __packed; struct atif_system_params { … } __packed; struct atif_sbios_requests { … } __packed; #define ATIF_NOTIFY_MASK … #define ATIF_NOTIFY_NONE … #define ATIF_NOTIFY_81 … #define ATIF_NOTIFY_N … struct atcs_verify_interface { … } __packed; #define ATCS_VALID_FLAGS_MASK … struct atcs_pref_req_input { … } __packed; struct atcs_pref_req_output { … } __packed; /* Call the ATIF method */ /** * radeon_atif_call - call an ATIF method * * @handle: acpi handle * @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 *radeon_atif_call(acpi_handle handle, int function, struct acpi_buffer *params) { … } /** * radeon_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 radeon_atif_parse_notification(struct radeon_atif_notifications *n, u32 mask) { … } /** * radeon_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 radeon_atif_parse_functions(struct radeon_atif_functions *f, u32 mask) { … } /** * radeon_atif_verify_interface - verify ATIF * * @handle: acpi handle * @atif: radeon 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 radeon_atif_verify_interface(acpi_handle handle, struct radeon_atif *atif) { … } /** * radeon_atif_get_notification_params - determine notify configuration * * @handle: acpi handle * @n: atif notification configuration struct * * 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 radeon_atif_get_notification_params(acpi_handle handle, struct radeon_atif_notification_cfg *n) { … } /** * radeon_atif_get_sbios_requests - get requested sbios event * * @handle: 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 radeon_atif_get_sbios_requests(acpi_handle handle, struct atif_sbios_requests *req) { … } /** * radeon_atif_handler - handle ATIF notify requests * * @rdev: radeon_device pointer * @event: atif sbios request struct * * Checks the acpi event and if it matches an atif event, * handles it. * Returns NOTIFY code */ static int radeon_atif_handler(struct radeon_device *rdev, struct acpi_bus_event *event) { … } /* Call the ATCS method */ /** * radeon_atcs_call - call an ATCS method * * @handle: acpi handle * @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 *radeon_atcs_call(acpi_handle handle, int function, struct acpi_buffer *params) { … } /** * radeon_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 radeon_atcs_parse_functions(struct radeon_atcs_functions *f, u32 mask) { … } /** * radeon_atcs_verify_interface - verify ATCS * * @handle: acpi handle * @atcs: radeon 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 radeon_atcs_verify_interface(acpi_handle handle, struct radeon_atcs *atcs) { … } /** * radeon_acpi_is_pcie_performance_request_supported * * @rdev: radeon_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 radeon_acpi_is_pcie_performance_request_supported(struct radeon_device *rdev) { … } /** * radeon_acpi_pcie_notify_device_ready * * @rdev: radeon_device pointer * * Executes the PCIE_DEVICE_READY_NOTIFICATION method * (all asics). * returns 0 on success, error on failure. */ int radeon_acpi_pcie_notify_device_ready(struct radeon_device *rdev) { … } /** * radeon_acpi_pcie_performance_request * * @rdev: radeon_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 radeon_acpi_pcie_performance_request(struct radeon_device *rdev, u8 perf_req, bool advertise) { … } /** * radeon_acpi_event - handle notify events * * @nb: notifier block * @val: val * @data: acpi event * * Calls relevant radeon functions in response to various * acpi events. * Returns NOTIFY code */ static int radeon_acpi_event(struct notifier_block *nb, unsigned long val, void *data) { … } /* Call all ACPI methods here */ /** * radeon_acpi_init - init driver acpi support * * @rdev: radeon_device pointer * * Verifies the AMD ACPI interfaces and registers with the acpi * notifier chain (all asics). * Returns 0 on success, error on failure. */ int radeon_acpi_init(struct radeon_device *rdev) { … } /** * radeon_acpi_fini - tear down driver acpi support * * @rdev: radeon_device pointer * * Unregisters with the acpi notifier chain (all asics). */ void radeon_acpi_fini(struct radeon_device *rdev) { … }