mirror of
https://github.com/torvalds/linux.git
synced 2024-11-19 10:31:48 +00:00
82023bb7f7
- ACPI-based device hotplug fixes for issues introduced recently and a fix for an older error code path bug in the ACPI PCI host bridge driver. - Fix for recently broken OMAP cpufreq build from Viresh Kumar. - Fix for a recent hibernation regression related to s2disk. - Fix for a locking-related regression in the ACPI EC driver from Puneet Kumar. - System suspend error code path fix related to runtime PM and runtime PM documentation update from Ulf Hansson. - cpufreq's conservative governor fix from Xiaoguang Chen. - New processor IDs for intel_idle and turbostat and removal of an obsolete Kconfig option from Len Brown. - New device IDs for the ACPI LPSS (Low-Power Subsystem) driver and ACPI-based PCI hotplug (ACPIPHP) cleanup from Mika Westerberg. - Removal of several ACPI video DMI blacklist entries that are not necessary any more from Aaron Lu. - Rework of the ACPI companion representation in struct device and code cleanup related to that change from Rafael J Wysocki, Lan Tianyu and Jarkko Nikula. - Fixes for assigning names to ACPI-enumerated I2C and SPI devices from Jarkko Nikula. / -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iQIcBAABCAAGBQJSjLYNAAoJEILEb/54YlRxkEQP/1pmFWNwSsxLtTHd+PEs0Xbo QccqvjQrnw/c8GcmK4eZrz6/xyuepmmjy9kfRKj2ENZniy0NEsSFqkTdSO3vYlva 8HKWUj7MV3evhFERXAF6Tu0b4Enx4jOP7VMtmYxJo3qrSnKRUcUzc6DGv/ACsUT1 Nkj0Lhdsg053Z+YzIXrl50w0tCDEMhVmWlMHBtYgr+dMNVnkfPBGkqMblMkKCXT2 w/yHvauZlxQHtI+8bVqTuGgNN0CPzdlpFGiuUF+5mDf6dRX8zlSn56Ia+Wyw1k9X dQp4jYQOgPRo03rNKqQPDiPxUdc7T0RAHRvDB51Ncweuh5PfZGguQe71p6/LKY2W i6zblZ0f/vc13hTiMrP+qzKcwZvgPB5DH7SfnHr61JKV7GNFCdYAqoceS5hYMzR9 d2Fd+txgm763IHWewXfDS/G2cU492R5qr4jpmUIACBQKWDZcqmSRDwRj83t56Ltb jgFBMbg4vZxG7IARhind74xsALxdhsgmFjPmx+0qPWjYxcU8otQZpXbgGNI9iOuW pxIQv5WPQW0tTmwO4HSuVCOwDPLPz5R0jkev7SvSj3Ek3TeD7He4LmnK055CATiC puq+6dp1FISPOPJYk+0DI61qN/CB/qNwRp8LU3ctZwudPVhznIE9FFQ3iN1FdBg2 X8VDcT9t7VvVuxSBjgkj =QMp+ -----END PGP SIGNATURE----- Merge tag 'pm+acpi-2-3.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm Pull more ACPI and power management updates from Rafael Wysocki: - ACPI-based device hotplug fixes for issues introduced recently and a fix for an older error code path bug in the ACPI PCI host bridge driver - Fix for recently broken OMAP cpufreq build from Viresh Kumar - Fix for a recent hibernation regression related to s2disk - Fix for a locking-related regression in the ACPI EC driver from Puneet Kumar - System suspend error code path fix related to runtime PM and runtime PM documentation update from Ulf Hansson - cpufreq's conservative governor fix from Xiaoguang Chen - New processor IDs for intel_idle and turbostat and removal of an obsolete Kconfig option from Len Brown - New device IDs for the ACPI LPSS (Low-Power Subsystem) driver and ACPI-based PCI hotplug (ACPIPHP) cleanup from Mika Westerberg - Removal of several ACPI video DMI blacklist entries that are not necessary any more from Aaron Lu - Rework of the ACPI companion representation in struct device and code cleanup related to that change from Rafael J Wysocki, Lan Tianyu and Jarkko Nikula - Fixes for assigning names to ACPI-enumerated I2C and SPI devices from Jarkko Nikula * tag 'pm+acpi-2-3.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (24 commits) PCI / hotplug / ACPI: Drop unused acpiphp_debug declaration ACPI / scan: Set flags.match_driver in acpi_bus_scan_fixed() ACPI / PCI root: Clear driver_data before failing enumeration ACPI / hotplug: Fix PCI host bridge hot removal ACPI / hotplug: Fix acpi_bus_get_device() return value check cpufreq: governor: Remove fossil comment in the cpufreq_governor_dbs() ACPI / video: clean up DMI table for initial black screen problem ACPI / EC: Ensure lock is acquired before accessing ec struct members PM / Hibernate: Do not crash kernel in free_basic_memory_bitmaps() ACPI / AC: Remove struct acpi_device pointer from struct acpi_ac spi: Use stable dev_name for ACPI enumerated SPI slaves i2c: Use stable dev_name for ACPI enumerated I2C slaves ACPI: Provide acpi_dev_name accessor for struct acpi_device device name ACPI / bind: Use (put|get)_device() on ACPI device objects too ACPI: Eliminate the DEVICE_ACPI_HANDLE() macro ACPI / driver core: Store an ACPI device pointer in struct acpi_dev_node cpufreq: OMAP: Fix compilation error 'r & ret undeclared' PM / Runtime: Fix error path for prepare PM / Runtime: Update documentation around probe|remove|suspend cpufreq: conservative: set requested_freq to policy max when it is over policy max ...
564 lines
14 KiB
C
564 lines
14 KiB
C
/*
|
|
* Copyright (c) 2010 Red Hat Inc.
|
|
* Author : Dave Airlie <airlied@redhat.com>
|
|
*
|
|
* Licensed under GPLv2
|
|
*
|
|
* ATPX support for both Intel/ATI
|
|
*/
|
|
#include <linux/vga_switcheroo.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/acpi.h>
|
|
#include <linux/pci.h>
|
|
|
|
#include "radeon_acpi.h"
|
|
|
|
struct radeon_atpx_functions {
|
|
bool px_params;
|
|
bool power_cntl;
|
|
bool disp_mux_cntl;
|
|
bool i2c_mux_cntl;
|
|
bool switch_start;
|
|
bool switch_end;
|
|
bool disp_connectors_mapping;
|
|
bool disp_detetion_ports;
|
|
};
|
|
|
|
struct radeon_atpx {
|
|
acpi_handle handle;
|
|
struct radeon_atpx_functions functions;
|
|
};
|
|
|
|
static struct radeon_atpx_priv {
|
|
bool atpx_detected;
|
|
/* handle for device - and atpx */
|
|
acpi_handle dhandle;
|
|
struct radeon_atpx atpx;
|
|
} radeon_atpx_priv;
|
|
|
|
struct atpx_verify_interface {
|
|
u16 size; /* structure size in bytes (includes size field) */
|
|
u16 version; /* version */
|
|
u32 function_bits; /* supported functions bit vector */
|
|
} __packed;
|
|
|
|
struct atpx_px_params {
|
|
u16 size; /* structure size in bytes (includes size field) */
|
|
u32 valid_flags; /* which flags are valid */
|
|
u32 flags; /* flags */
|
|
} __packed;
|
|
|
|
struct atpx_power_control {
|
|
u16 size;
|
|
u8 dgpu_state;
|
|
} __packed;
|
|
|
|
struct atpx_mux {
|
|
u16 size;
|
|
u16 mux;
|
|
} __packed;
|
|
|
|
bool radeon_is_px(void) {
|
|
return radeon_atpx_priv.atpx_detected;
|
|
}
|
|
|
|
/**
|
|
* radeon_atpx_call - call an ATPX method
|
|
*
|
|
* @handle: acpi handle
|
|
* @function: the ATPX function to execute
|
|
* @params: ATPX function params
|
|
*
|
|
* Executes the requested ATPX function (all asics).
|
|
* Returns a pointer to the acpi output buffer.
|
|
*/
|
|
static union acpi_object *radeon_atpx_call(acpi_handle handle, int function,
|
|
struct acpi_buffer *params)
|
|
{
|
|
acpi_status status;
|
|
union acpi_object atpx_arg_elements[2];
|
|
struct acpi_object_list atpx_arg;
|
|
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
|
|
|
|
atpx_arg.count = 2;
|
|
atpx_arg.pointer = &atpx_arg_elements[0];
|
|
|
|
atpx_arg_elements[0].type = ACPI_TYPE_INTEGER;
|
|
atpx_arg_elements[0].integer.value = function;
|
|
|
|
if (params) {
|
|
atpx_arg_elements[1].type = ACPI_TYPE_BUFFER;
|
|
atpx_arg_elements[1].buffer.length = params->length;
|
|
atpx_arg_elements[1].buffer.pointer = params->pointer;
|
|
} else {
|
|
/* We need a second fake parameter */
|
|
atpx_arg_elements[1].type = ACPI_TYPE_INTEGER;
|
|
atpx_arg_elements[1].integer.value = 0;
|
|
}
|
|
|
|
status = acpi_evaluate_object(handle, NULL, &atpx_arg, &buffer);
|
|
|
|
/* Fail only if calling the method fails and ATPX is supported */
|
|
if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
|
|
printk("failed to evaluate ATPX got %s\n",
|
|
acpi_format_exception(status));
|
|
kfree(buffer.pointer);
|
|
return NULL;
|
|
}
|
|
|
|
return buffer.pointer;
|
|
}
|
|
|
|
/**
|
|
* radeon_atpx_parse_functions - parse supported functions
|
|
*
|
|
* @f: supported functions struct
|
|
* @mask: supported functions mask from ATPX
|
|
*
|
|
* Use the supported functions mask from ATPX function
|
|
* ATPX_FUNCTION_VERIFY_INTERFACE to determine what functions
|
|
* are supported (all asics).
|
|
*/
|
|
static void radeon_atpx_parse_functions(struct radeon_atpx_functions *f, u32 mask)
|
|
{
|
|
f->px_params = mask & ATPX_GET_PX_PARAMETERS_SUPPORTED;
|
|
f->power_cntl = mask & ATPX_POWER_CONTROL_SUPPORTED;
|
|
f->disp_mux_cntl = mask & ATPX_DISPLAY_MUX_CONTROL_SUPPORTED;
|
|
f->i2c_mux_cntl = mask & ATPX_I2C_MUX_CONTROL_SUPPORTED;
|
|
f->switch_start = mask & ATPX_GRAPHICS_DEVICE_SWITCH_START_NOTIFICATION_SUPPORTED;
|
|
f->switch_end = mask & ATPX_GRAPHICS_DEVICE_SWITCH_END_NOTIFICATION_SUPPORTED;
|
|
f->disp_connectors_mapping = mask & ATPX_GET_DISPLAY_CONNECTORS_MAPPING_SUPPORTED;
|
|
f->disp_detetion_ports = mask & ATPX_GET_DISPLAY_DETECTION_PORTS_SUPPORTED;
|
|
}
|
|
|
|
/**
|
|
* radeon_atpx_validate_functions - validate ATPX functions
|
|
*
|
|
* @atpx: radeon atpx struct
|
|
*
|
|
* Validate that required functions are enabled (all asics).
|
|
* returns 0 on success, error on failure.
|
|
*/
|
|
static int radeon_atpx_validate(struct radeon_atpx *atpx)
|
|
{
|
|
/* make sure required functions are enabled */
|
|
/* dGPU power control is required */
|
|
atpx->functions.power_cntl = true;
|
|
|
|
if (atpx->functions.px_params) {
|
|
union acpi_object *info;
|
|
struct atpx_px_params output;
|
|
size_t size;
|
|
u32 valid_bits;
|
|
|
|
info = radeon_atpx_call(atpx->handle, ATPX_FUNCTION_GET_PX_PARAMETERS, NULL);
|
|
if (!info)
|
|
return -EIO;
|
|
|
|
memset(&output, 0, sizeof(output));
|
|
|
|
size = *(u16 *) info->buffer.pointer;
|
|
if (size < 10) {
|
|
printk("ATPX buffer is too small: %zu\n", size);
|
|
kfree(info);
|
|
return -EINVAL;
|
|
}
|
|
size = min(sizeof(output), size);
|
|
|
|
memcpy(&output, info->buffer.pointer, size);
|
|
|
|
valid_bits = output.flags & output.valid_flags;
|
|
/* if separate mux flag is set, mux controls are required */
|
|
if (valid_bits & ATPX_SEPARATE_MUX_FOR_I2C) {
|
|
atpx->functions.i2c_mux_cntl = true;
|
|
atpx->functions.disp_mux_cntl = true;
|
|
}
|
|
/* if any outputs are muxed, mux controls are required */
|
|
if (valid_bits & (ATPX_CRT1_RGB_SIGNAL_MUXED |
|
|
ATPX_TV_SIGNAL_MUXED |
|
|
ATPX_DFP_SIGNAL_MUXED))
|
|
atpx->functions.disp_mux_cntl = true;
|
|
|
|
kfree(info);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* radeon_atpx_verify_interface - verify ATPX
|
|
*
|
|
* @atpx: radeon atpx struct
|
|
*
|
|
* Execute the ATPX_FUNCTION_VERIFY_INTERFACE ATPX function
|
|
* to initialize ATPX and determine what features are supported
|
|
* (all asics).
|
|
* returns 0 on success, error on failure.
|
|
*/
|
|
static int radeon_atpx_verify_interface(struct radeon_atpx *atpx)
|
|
{
|
|
union acpi_object *info;
|
|
struct atpx_verify_interface output;
|
|
size_t size;
|
|
int err = 0;
|
|
|
|
info = radeon_atpx_call(atpx->handle, ATPX_FUNCTION_VERIFY_INTERFACE, NULL);
|
|
if (!info)
|
|
return -EIO;
|
|
|
|
memset(&output, 0, sizeof(output));
|
|
|
|
size = *(u16 *) info->buffer.pointer;
|
|
if (size < 8) {
|
|
printk("ATPX buffer is too small: %zu\n", size);
|
|
err = -EINVAL;
|
|
goto out;
|
|
}
|
|
size = min(sizeof(output), size);
|
|
|
|
memcpy(&output, info->buffer.pointer, size);
|
|
|
|
/* TODO: check version? */
|
|
printk("ATPX version %u\n", output.version);
|
|
|
|
radeon_atpx_parse_functions(&atpx->functions, output.function_bits);
|
|
|
|
out:
|
|
kfree(info);
|
|
return err;
|
|
}
|
|
|
|
/**
|
|
* radeon_atpx_set_discrete_state - power up/down discrete GPU
|
|
*
|
|
* @atpx: atpx info struct
|
|
* @state: discrete GPU state (0 = power down, 1 = power up)
|
|
*
|
|
* Execute the ATPX_FUNCTION_POWER_CONTROL ATPX function to
|
|
* power down/up the discrete GPU (all asics).
|
|
* Returns 0 on success, error on failure.
|
|
*/
|
|
static int radeon_atpx_set_discrete_state(struct radeon_atpx *atpx, u8 state)
|
|
{
|
|
struct acpi_buffer params;
|
|
union acpi_object *info;
|
|
struct atpx_power_control input;
|
|
|
|
if (atpx->functions.power_cntl) {
|
|
input.size = 3;
|
|
input.dgpu_state = state;
|
|
params.length = input.size;
|
|
params.pointer = &input;
|
|
info = radeon_atpx_call(atpx->handle,
|
|
ATPX_FUNCTION_POWER_CONTROL,
|
|
¶ms);
|
|
if (!info)
|
|
return -EIO;
|
|
kfree(info);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* radeon_atpx_switch_disp_mux - switch display mux
|
|
*
|
|
* @atpx: atpx info struct
|
|
* @mux_id: mux state (0 = integrated GPU, 1 = discrete GPU)
|
|
*
|
|
* Execute the ATPX_FUNCTION_DISPLAY_MUX_CONTROL ATPX function to
|
|
* switch the display mux between the discrete GPU and integrated GPU
|
|
* (all asics).
|
|
* Returns 0 on success, error on failure.
|
|
*/
|
|
static int radeon_atpx_switch_disp_mux(struct radeon_atpx *atpx, u16 mux_id)
|
|
{
|
|
struct acpi_buffer params;
|
|
union acpi_object *info;
|
|
struct atpx_mux input;
|
|
|
|
if (atpx->functions.disp_mux_cntl) {
|
|
input.size = 4;
|
|
input.mux = mux_id;
|
|
params.length = input.size;
|
|
params.pointer = &input;
|
|
info = radeon_atpx_call(atpx->handle,
|
|
ATPX_FUNCTION_DISPLAY_MUX_CONTROL,
|
|
¶ms);
|
|
if (!info)
|
|
return -EIO;
|
|
kfree(info);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* radeon_atpx_switch_i2c_mux - switch i2c/hpd mux
|
|
*
|
|
* @atpx: atpx info struct
|
|
* @mux_id: mux state (0 = integrated GPU, 1 = discrete GPU)
|
|
*
|
|
* Execute the ATPX_FUNCTION_I2C_MUX_CONTROL ATPX function to
|
|
* switch the i2c/hpd mux between the discrete GPU and integrated GPU
|
|
* (all asics).
|
|
* Returns 0 on success, error on failure.
|
|
*/
|
|
static int radeon_atpx_switch_i2c_mux(struct radeon_atpx *atpx, u16 mux_id)
|
|
{
|
|
struct acpi_buffer params;
|
|
union acpi_object *info;
|
|
struct atpx_mux input;
|
|
|
|
if (atpx->functions.i2c_mux_cntl) {
|
|
input.size = 4;
|
|
input.mux = mux_id;
|
|
params.length = input.size;
|
|
params.pointer = &input;
|
|
info = radeon_atpx_call(atpx->handle,
|
|
ATPX_FUNCTION_I2C_MUX_CONTROL,
|
|
¶ms);
|
|
if (!info)
|
|
return -EIO;
|
|
kfree(info);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* radeon_atpx_switch_start - notify the sbios of a GPU switch
|
|
*
|
|
* @atpx: atpx info struct
|
|
* @mux_id: mux state (0 = integrated GPU, 1 = discrete GPU)
|
|
*
|
|
* Execute the ATPX_FUNCTION_GRAPHICS_DEVICE_SWITCH_START_NOTIFICATION ATPX
|
|
* function to notify the sbios that a switch between the discrete GPU and
|
|
* integrated GPU has begun (all asics).
|
|
* Returns 0 on success, error on failure.
|
|
*/
|
|
static int radeon_atpx_switch_start(struct radeon_atpx *atpx, u16 mux_id)
|
|
{
|
|
struct acpi_buffer params;
|
|
union acpi_object *info;
|
|
struct atpx_mux input;
|
|
|
|
if (atpx->functions.switch_start) {
|
|
input.size = 4;
|
|
input.mux = mux_id;
|
|
params.length = input.size;
|
|
params.pointer = &input;
|
|
info = radeon_atpx_call(atpx->handle,
|
|
ATPX_FUNCTION_GRAPHICS_DEVICE_SWITCH_START_NOTIFICATION,
|
|
¶ms);
|
|
if (!info)
|
|
return -EIO;
|
|
kfree(info);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* radeon_atpx_switch_end - notify the sbios of a GPU switch
|
|
*
|
|
* @atpx: atpx info struct
|
|
* @mux_id: mux state (0 = integrated GPU, 1 = discrete GPU)
|
|
*
|
|
* Execute the ATPX_FUNCTION_GRAPHICS_DEVICE_SWITCH_END_NOTIFICATION ATPX
|
|
* function to notify the sbios that a switch between the discrete GPU and
|
|
* integrated GPU has ended (all asics).
|
|
* Returns 0 on success, error on failure.
|
|
*/
|
|
static int radeon_atpx_switch_end(struct radeon_atpx *atpx, u16 mux_id)
|
|
{
|
|
struct acpi_buffer params;
|
|
union acpi_object *info;
|
|
struct atpx_mux input;
|
|
|
|
if (atpx->functions.switch_end) {
|
|
input.size = 4;
|
|
input.mux = mux_id;
|
|
params.length = input.size;
|
|
params.pointer = &input;
|
|
info = radeon_atpx_call(atpx->handle,
|
|
ATPX_FUNCTION_GRAPHICS_DEVICE_SWITCH_END_NOTIFICATION,
|
|
¶ms);
|
|
if (!info)
|
|
return -EIO;
|
|
kfree(info);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* radeon_atpx_switchto - switch to the requested GPU
|
|
*
|
|
* @id: GPU to switch to
|
|
*
|
|
* Execute the necessary ATPX functions to switch between the discrete GPU and
|
|
* integrated GPU (all asics).
|
|
* Returns 0 on success, error on failure.
|
|
*/
|
|
static int radeon_atpx_switchto(enum vga_switcheroo_client_id id)
|
|
{
|
|
u16 gpu_id;
|
|
|
|
if (id == VGA_SWITCHEROO_IGD)
|
|
gpu_id = ATPX_INTEGRATED_GPU;
|
|
else
|
|
gpu_id = ATPX_DISCRETE_GPU;
|
|
|
|
radeon_atpx_switch_start(&radeon_atpx_priv.atpx, gpu_id);
|
|
radeon_atpx_switch_disp_mux(&radeon_atpx_priv.atpx, gpu_id);
|
|
radeon_atpx_switch_i2c_mux(&radeon_atpx_priv.atpx, gpu_id);
|
|
radeon_atpx_switch_end(&radeon_atpx_priv.atpx, gpu_id);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* radeon_atpx_power_state - power down/up the requested GPU
|
|
*
|
|
* @id: GPU to power down/up
|
|
* @state: requested power state (0 = off, 1 = on)
|
|
*
|
|
* Execute the necessary ATPX function to power down/up the discrete GPU
|
|
* (all asics).
|
|
* Returns 0 on success, error on failure.
|
|
*/
|
|
static int radeon_atpx_power_state(enum vga_switcheroo_client_id id,
|
|
enum vga_switcheroo_state state)
|
|
{
|
|
/* on w500 ACPI can't change intel gpu state */
|
|
if (id == VGA_SWITCHEROO_IGD)
|
|
return 0;
|
|
|
|
radeon_atpx_set_discrete_state(&radeon_atpx_priv.atpx, state);
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* radeon_atpx_pci_probe_handle - look up the ATPX handle
|
|
*
|
|
* @pdev: pci device
|
|
*
|
|
* Look up the ATPX handles (all asics).
|
|
* Returns true if the handles are found, false if not.
|
|
*/
|
|
static bool radeon_atpx_pci_probe_handle(struct pci_dev *pdev)
|
|
{
|
|
acpi_handle dhandle, atpx_handle;
|
|
acpi_status status;
|
|
|
|
dhandle = ACPI_HANDLE(&pdev->dev);
|
|
if (!dhandle)
|
|
return false;
|
|
|
|
status = acpi_get_handle(dhandle, "ATPX", &atpx_handle);
|
|
if (ACPI_FAILURE(status))
|
|
return false;
|
|
|
|
radeon_atpx_priv.dhandle = dhandle;
|
|
radeon_atpx_priv.atpx.handle = atpx_handle;
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* radeon_atpx_init - verify the ATPX interface
|
|
*
|
|
* Verify the ATPX interface (all asics).
|
|
* Returns 0 on success, error on failure.
|
|
*/
|
|
static int radeon_atpx_init(void)
|
|
{
|
|
int r;
|
|
|
|
/* set up the ATPX handle */
|
|
r = radeon_atpx_verify_interface(&radeon_atpx_priv.atpx);
|
|
if (r)
|
|
return r;
|
|
|
|
/* validate the atpx setup */
|
|
r = radeon_atpx_validate(&radeon_atpx_priv.atpx);
|
|
if (r)
|
|
return r;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* radeon_atpx_get_client_id - get the client id
|
|
*
|
|
* @pdev: pci device
|
|
*
|
|
* look up whether we are the integrated or discrete GPU (all asics).
|
|
* Returns the client id.
|
|
*/
|
|
static int radeon_atpx_get_client_id(struct pci_dev *pdev)
|
|
{
|
|
if (radeon_atpx_priv.dhandle == ACPI_HANDLE(&pdev->dev))
|
|
return VGA_SWITCHEROO_IGD;
|
|
else
|
|
return VGA_SWITCHEROO_DIS;
|
|
}
|
|
|
|
static struct vga_switcheroo_handler radeon_atpx_handler = {
|
|
.switchto = radeon_atpx_switchto,
|
|
.power_state = radeon_atpx_power_state,
|
|
.init = radeon_atpx_init,
|
|
.get_client_id = radeon_atpx_get_client_id,
|
|
};
|
|
|
|
/**
|
|
* radeon_atpx_detect - detect whether we have PX
|
|
*
|
|
* Check if we have a PX system (all asics).
|
|
* Returns true if we have a PX system, false if not.
|
|
*/
|
|
static bool radeon_atpx_detect(void)
|
|
{
|
|
char acpi_method_name[255] = { 0 };
|
|
struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
|
|
struct pci_dev *pdev = NULL;
|
|
bool has_atpx = false;
|
|
int vga_count = 0;
|
|
|
|
while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
|
|
vga_count++;
|
|
|
|
has_atpx |= (radeon_atpx_pci_probe_handle(pdev) == true);
|
|
}
|
|
|
|
if (has_atpx && vga_count == 2) {
|
|
acpi_get_name(radeon_atpx_priv.atpx.handle, ACPI_FULL_PATHNAME, &buffer);
|
|
printk(KERN_INFO "VGA switcheroo: detected switching method %s handle\n",
|
|
acpi_method_name);
|
|
radeon_atpx_priv.atpx_detected = true;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* radeon_register_atpx_handler - register with vga_switcheroo
|
|
*
|
|
* Register the PX callbacks with vga_switcheroo (all asics).
|
|
*/
|
|
void radeon_register_atpx_handler(void)
|
|
{
|
|
bool r;
|
|
|
|
/* detect if we have any ATPX + 2 VGA in the system */
|
|
r = radeon_atpx_detect();
|
|
if (!r)
|
|
return;
|
|
|
|
vga_switcheroo_register_handler(&radeon_atpx_handler);
|
|
}
|
|
|
|
/**
|
|
* radeon_unregister_atpx_handler - unregister with vga_switcheroo
|
|
*
|
|
* Unregister the PX callbacks with vga_switcheroo (all asics).
|
|
*/
|
|
void radeon_unregister_atpx_handler(void)
|
|
{
|
|
vga_switcheroo_unregister_handler();
|
|
}
|