2010-02-01 12:38:10 +07:00
|
|
|
/*
|
|
|
|
* 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 cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
ACPI / driver core: Store an ACPI device pointer in struct acpi_dev_node
Modify struct acpi_dev_node to contain a pointer to struct acpi_device
associated with the given device object (that is, its ACPI companion
device) instead of an ACPI handle corresponding to it. Introduce two
new macros for manipulating that pointer in a CONFIG_ACPI-safe way,
ACPI_COMPANION() and ACPI_COMPANION_SET(), and rework the
ACPI_HANDLE() macro to take the above changes into account.
Drop the ACPI_HANDLE_SET() macro entirely and rework its users to
use ACPI_COMPANION_SET() instead. For some of them who used to
pass the result of acpi_get_child() directly to ACPI_HANDLE_SET()
introduce a helper routine acpi_preset_companion() doing an
equivalent thing.
The main motivation for doing this is that there are things
represented by struct acpi_device objects that don't have valid
ACPI handles (so called fixed ACPI hardware features, such as
power and sleep buttons) and we would like to create platform
device objects for them and "glue" them to their ACPI companions
in the usual way (which currently is impossible due to the
lack of valid ACPI handles). However, there are more reasons
why it may be useful.
First, struct acpi_device pointers allow of much better type checking
than void pointers which are ACPI handles, so it should be more
difficult to write buggy code using modified struct acpi_dev_node
and the new macros. Second, the change should help to reduce (over
time) the number of places in which the result of ACPI_HANDLE() is
passed to acpi_bus_get_device() in order to obtain a pointer to the
struct acpi_device associated with the given "physical" device,
because now that pointer is returned by ACPI_COMPANION() directly.
Finally, the change should make it easier to write generic code that
will build both for CONFIG_ACPI set and unset without adding explicit
compiler directives to it.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com> # on Haswell
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Aaron Lu <aaron.lu@intel.com> # for ATA and SDIO part
2013-11-12 04:41:56 +07:00
|
|
|
#include <linux/acpi.h>
|
2010-02-01 12:38:10 +07:00
|
|
|
#include <linux/pci.h>
|
|
|
|
|
2012-07-19 00:28:52 +07:00
|
|
|
#include "radeon_acpi.h"
|
2010-02-01 12:38:10 +07:00
|
|
|
|
2012-08-17 01:01:57 +07:00
|
|
|
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 {
|
2012-08-17 01:07:37 +07:00
|
|
|
acpi_handle handle;
|
2012-08-17 01:01:57 +07:00
|
|
|
struct radeon_atpx_functions functions;
|
|
|
|
};
|
|
|
|
|
2010-02-01 12:38:10 +07:00
|
|
|
static struct radeon_atpx_priv {
|
|
|
|
bool atpx_detected;
|
|
|
|
/* handle for device - and atpx */
|
|
|
|
acpi_handle dhandle;
|
2012-08-17 01:01:57 +07:00
|
|
|
struct radeon_atpx atpx;
|
2010-02-01 12:38:10 +07:00
|
|
|
} radeon_atpx_priv;
|
|
|
|
|
2012-08-17 01:01:57 +07:00
|
|
|
struct atpx_verify_interface {
|
|
|
|
u16 size; /* structure size in bytes (includes size field) */
|
|
|
|
u16 version; /* version */
|
|
|
|
u32 function_bits; /* supported functions bit vector */
|
|
|
|
} __packed;
|
|
|
|
|
2013-02-20 00:55:52 +07:00
|
|
|
struct atpx_px_params {
|
|
|
|
u16 size; /* structure size in bytes (includes size field) */
|
|
|
|
u32 valid_flags; /* which flags are valid */
|
|
|
|
u32 flags; /* flags */
|
|
|
|
} __packed;
|
|
|
|
|
2012-08-17 01:07:37 +07:00
|
|
|
struct atpx_power_control {
|
|
|
|
u16 size;
|
|
|
|
u8 dgpu_state;
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
struct atpx_mux {
|
|
|
|
u16 size;
|
|
|
|
u16 mux;
|
|
|
|
} __packed;
|
|
|
|
|
2014-04-11 09:29:01 +07:00
|
|
|
bool radeon_has_atpx(void) {
|
2012-09-17 11:40:31 +07:00
|
|
|
return radeon_atpx_priv.atpx_detected;
|
|
|
|
}
|
|
|
|
|
2016-03-02 23:47:29 +07:00
|
|
|
bool radeon_has_atpx_dgpu_power_cntl(void) {
|
|
|
|
return radeon_atpx_priv.atpx.functions.power_cntl;
|
|
|
|
}
|
|
|
|
|
2012-08-17 01:01:57 +07:00
|
|
|
/**
|
|
|
|
* 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)
|
2010-02-01 12:38:10 +07:00
|
|
|
{
|
|
|
|
acpi_status status;
|
2012-08-17 01:01:57 +07:00
|
|
|
union acpi_object atpx_arg_elements[2];
|
2010-02-01 12:38:10 +07:00
|
|
|
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;
|
2012-08-17 01:01:57 +07:00
|
|
|
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;
|
|
|
|
}
|
2010-02-01 12:38:10 +07:00
|
|
|
|
2012-10-24 04:57:54 +07:00
|
|
|
status = acpi_evaluate_object(handle, NULL, &atpx_arg, &buffer);
|
2010-02-01 12:38:10 +07:00
|
|
|
|
2012-08-17 01:01:57 +07:00
|
|
|
/* 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;
|
2010-02-01 12:38:10 +07:00
|
|
|
}
|
2012-08-17 01:01:57 +07:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-02-20 00:55:52 +07:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-08-17 01:01:57 +07:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-08-17 01:07:37 +07:00
|
|
|
static int radeon_atpx_verify_interface(struct radeon_atpx *atpx)
|
2012-08-17 01:01:57 +07:00
|
|
|
{
|
|
|
|
union acpi_object *info;
|
|
|
|
struct atpx_verify_interface output;
|
|
|
|
size_t size;
|
|
|
|
int err = 0;
|
|
|
|
|
2012-08-17 01:07:37 +07:00
|
|
|
info = radeon_atpx_call(atpx->handle, ATPX_FUNCTION_VERIFY_INTERFACE, NULL);
|
2012-08-17 01:01:57 +07:00
|
|
|
if (!info)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
memset(&output, 0, sizeof(output));
|
|
|
|
|
|
|
|
size = *(u16 *) info->buffer.pointer;
|
|
|
|
if (size < 8) {
|
2012-10-16 07:15:45 +07:00
|
|
|
printk("ATPX buffer is too small: %zu\n", size);
|
2012-08-17 01:01:57 +07:00
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
size = min(sizeof(output), size);
|
|
|
|
|
|
|
|
memcpy(&output, info->buffer.pointer, size);
|
|
|
|
|
|
|
|
/* TODO: check version? */
|
2014-02-20 21:16:01 +07:00
|
|
|
printk("ATPX version %u, functions 0x%08x\n",
|
|
|
|
output.version, output.function_bits);
|
2012-08-17 01:01:57 +07:00
|
|
|
|
|
|
|
radeon_atpx_parse_functions(&atpx->functions, output.function_bits);
|
|
|
|
|
|
|
|
out:
|
|
|
|
kfree(info);
|
|
|
|
return err;
|
2010-02-01 12:38:10 +07:00
|
|
|
}
|
|
|
|
|
2012-08-17 01:09:21 +07:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-08-17 01:07:37 +07:00
|
|
|
static int radeon_atpx_set_discrete_state(struct radeon_atpx *atpx, u8 state)
|
2010-02-01 12:38:10 +07:00
|
|
|
{
|
2012-08-17 01:07:37 +07:00
|
|
|
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);
|
2010-02-01 12:38:10 +07:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-17 01:09:21 +07:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-08-17 01:07:37 +07:00
|
|
|
static int radeon_atpx_switch_disp_mux(struct radeon_atpx *atpx, u16 mux_id)
|
2010-02-01 12:38:10 +07:00
|
|
|
{
|
2012-08-17 01:07:37 +07:00
|
|
|
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;
|
2010-02-01 12:38:10 +07:00
|
|
|
}
|
|
|
|
|
2012-08-17 01:09:21 +07:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-08-17 01:07:37 +07:00
|
|
|
static int radeon_atpx_switch_i2c_mux(struct radeon_atpx *atpx, u16 mux_id)
|
2011-05-06 12:42:49 +07:00
|
|
|
{
|
2012-08-17 01:07:37 +07:00
|
|
|
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;
|
2011-05-06 12:42:49 +07:00
|
|
|
}
|
|
|
|
|
2012-08-17 01:09:21 +07:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-08-17 01:07:37 +07:00
|
|
|
static int radeon_atpx_switch_start(struct radeon_atpx *atpx, u16 mux_id)
|
2011-05-06 12:42:49 +07:00
|
|
|
{
|
2012-08-17 01:07:37 +07:00
|
|
|
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;
|
2011-05-06 12:42:49 +07:00
|
|
|
}
|
|
|
|
|
2012-08-17 01:09:21 +07:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-08-17 01:07:37 +07:00
|
|
|
static int radeon_atpx_switch_end(struct radeon_atpx *atpx, u16 mux_id)
|
2011-05-06 12:42:49 +07:00
|
|
|
{
|
2012-08-17 01:07:37 +07:00
|
|
|
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;
|
2011-05-06 12:42:49 +07:00
|
|
|
}
|
2010-02-01 12:38:10 +07:00
|
|
|
|
2012-08-17 01:09:21 +07:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2010-02-01 12:38:10 +07:00
|
|
|
static int radeon_atpx_switchto(enum vga_switcheroo_client_id id)
|
|
|
|
{
|
2012-08-17 01:07:37 +07:00
|
|
|
u16 gpu_id;
|
2011-05-06 12:42:49 +07:00
|
|
|
|
2010-02-01 12:38:10 +07:00
|
|
|
if (id == VGA_SWITCHEROO_IGD)
|
2012-07-19 00:28:52 +07:00
|
|
|
gpu_id = ATPX_INTEGRATED_GPU;
|
2010-02-01 12:38:10 +07:00
|
|
|
else
|
2012-07-19 00:28:52 +07:00
|
|
|
gpu_id = ATPX_DISCRETE_GPU;
|
2011-05-06 12:42:49 +07:00
|
|
|
|
2012-08-17 01:07:37 +07:00
|
|
|
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);
|
2011-05-06 12:42:49 +07:00
|
|
|
|
2010-02-01 12:38:10 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-17 01:09:21 +07:00
|
|
|
/**
|
2012-10-25 20:09:00 +07:00
|
|
|
* radeon_atpx_power_state - power down/up the requested GPU
|
2012-08-17 01:09:21 +07:00
|
|
|
*
|
2012-10-25 20:09:00 +07:00
|
|
|
* @id: GPU to power down/up
|
2012-08-17 01:09:21 +07:00
|
|
|
* @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.
|
|
|
|
*/
|
2010-02-01 12:38:10 +07:00
|
|
|
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;
|
|
|
|
|
2012-08-17 01:07:37 +07:00
|
|
|
radeon_atpx_set_discrete_state(&radeon_atpx_priv.atpx, state);
|
2010-02-01 12:38:10 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-17 01:09:21 +07:00
|
|
|
/**
|
2012-10-23 23:42:42 +07:00
|
|
|
* radeon_atpx_pci_probe_handle - look up the ATPX handle
|
2012-08-17 01:09:21 +07:00
|
|
|
*
|
|
|
|
* @pdev: pci device
|
|
|
|
*
|
2012-10-23 23:42:42 +07:00
|
|
|
* Look up the ATPX handles (all asics).
|
2012-08-17 01:09:21 +07:00
|
|
|
* Returns true if the handles are found, false if not.
|
|
|
|
*/
|
2010-02-01 12:38:10 +07:00
|
|
|
static bool radeon_atpx_pci_probe_handle(struct pci_dev *pdev)
|
|
|
|
{
|
2012-08-17 02:39:09 +07:00
|
|
|
acpi_handle dhandle, atpx_handle;
|
2010-02-01 12:38:10 +07:00
|
|
|
acpi_status status;
|
|
|
|
|
2013-11-15 05:17:21 +07:00
|
|
|
dhandle = ACPI_HANDLE(&pdev->dev);
|
2010-02-01 12:38:10 +07:00
|
|
|
if (!dhandle)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
status = acpi_get_handle(dhandle, "ATPX", &atpx_handle);
|
2014-09-11 04:30:08 +07:00
|
|
|
if (ACPI_FAILURE(status))
|
2010-02-01 12:38:10 +07:00
|
|
|
return false;
|
2014-09-11 04:30:08 +07:00
|
|
|
|
2010-02-01 12:38:10 +07:00
|
|
|
radeon_atpx_priv.dhandle = dhandle;
|
2012-08-17 01:07:37 +07:00
|
|
|
radeon_atpx_priv.atpx.handle = atpx_handle;
|
2010-02-01 12:38:10 +07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-17 01:09:21 +07:00
|
|
|
/**
|
|
|
|
* radeon_atpx_init - verify the ATPX interface
|
|
|
|
*
|
|
|
|
* Verify the ATPX interface (all asics).
|
|
|
|
* Returns 0 on success, error on failure.
|
|
|
|
*/
|
2010-02-01 12:38:10 +07:00
|
|
|
static int radeon_atpx_init(void)
|
|
|
|
{
|
2013-02-20 00:55:52 +07:00
|
|
|
int r;
|
|
|
|
|
2010-02-01 12:38:10 +07:00
|
|
|
/* set up the ATPX handle */
|
2013-02-20 00:55:52 +07:00
|
|
|
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;
|
2010-02-01 12:38:10 +07:00
|
|
|
}
|
|
|
|
|
2012-08-17 01:09:21 +07:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2010-02-01 12:38:10 +07:00
|
|
|
static int radeon_atpx_get_client_id(struct pci_dev *pdev)
|
|
|
|
{
|
2013-11-15 05:17:21 +07:00
|
|
|
if (radeon_atpx_priv.dhandle == ACPI_HANDLE(&pdev->dev))
|
2010-02-01 12:38:10 +07:00
|
|
|
return VGA_SWITCHEROO_IGD;
|
|
|
|
else
|
|
|
|
return VGA_SWITCHEROO_DIS;
|
|
|
|
}
|
|
|
|
|
2015-10-18 18:05:40 +07:00
|
|
|
static const struct vga_switcheroo_handler radeon_atpx_handler = {
|
2010-02-01 12:38:10 +07:00
|
|
|
.switchto = radeon_atpx_switchto,
|
|
|
|
.power_state = radeon_atpx_power_state,
|
|
|
|
.init = radeon_atpx_init,
|
|
|
|
.get_client_id = radeon_atpx_get_client_id,
|
|
|
|
};
|
|
|
|
|
2012-08-17 01:09:21 +07:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2010-02-01 12:38:10 +07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-04-15 23:44:34 +07:00
|
|
|
/* some newer PX laptops mark the dGPU as a non-VGA display device */
|
|
|
|
while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_OTHER << 8, pdev)) != NULL) {
|
|
|
|
vga_count++;
|
|
|
|
|
|
|
|
has_atpx |= (radeon_atpx_pci_probe_handle(pdev) == true);
|
|
|
|
}
|
|
|
|
|
2010-02-01 12:38:10 +07:00
|
|
|
if (has_atpx && vga_count == 2) {
|
2012-08-17 01:07:37 +07:00
|
|
|
acpi_get_name(radeon_atpx_priv.atpx.handle, ACPI_FULL_PATHNAME, &buffer);
|
2015-09-05 16:14:43 +07:00
|
|
|
printk(KERN_INFO "vga_switcheroo: detected switching method %s handle\n",
|
2010-02-01 12:38:10 +07:00
|
|
|
acpi_method_name);
|
|
|
|
radeon_atpx_priv.atpx_detected = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-17 01:09:21 +07:00
|
|
|
/**
|
|
|
|
* radeon_register_atpx_handler - register with vga_switcheroo
|
|
|
|
*
|
|
|
|
* Register the PX callbacks with vga_switcheroo (all asics).
|
|
|
|
*/
|
2010-02-01 12:38:10 +07:00
|
|
|
void radeon_register_atpx_handler(void)
|
|
|
|
{
|
|
|
|
bool r;
|
2016-01-12 02:09:20 +07:00
|
|
|
enum vga_switcheroo_handler_flags_t handler_flags = 0;
|
2010-02-01 12:38:10 +07:00
|
|
|
|
|
|
|
/* detect if we have any ATPX + 2 VGA in the system */
|
|
|
|
r = radeon_atpx_detect();
|
|
|
|
if (!r)
|
|
|
|
return;
|
|
|
|
|
2016-01-12 02:09:20 +07:00
|
|
|
vga_switcheroo_register_handler(&radeon_atpx_handler, handler_flags);
|
2010-02-01 12:38:10 +07:00
|
|
|
}
|
|
|
|
|
2012-08-17 01:09:21 +07:00
|
|
|
/**
|
|
|
|
* radeon_unregister_atpx_handler - unregister with vga_switcheroo
|
|
|
|
*
|
|
|
|
* Unregister the PX callbacks with vga_switcheroo (all asics).
|
|
|
|
*/
|
2010-02-01 12:38:10 +07:00
|
|
|
void radeon_unregister_atpx_handler(void)
|
|
|
|
{
|
|
|
|
vga_switcheroo_unregister_handler();
|
|
|
|
}
|