mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-23 02:54:32 +08:00
5a0e3ad6af
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>
259 lines
6.4 KiB
C
259 lines
6.4 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 <acpi/acpi.h>
|
|
#include <acpi/acpi_bus.h>
|
|
#include <linux/pci.h>
|
|
|
|
#define ATPX_VERSION 0
|
|
#define ATPX_GPU_PWR 2
|
|
#define ATPX_MUX_SELECT 3
|
|
|
|
#define ATPX_INTEGRATED 0
|
|
#define ATPX_DISCRETE 1
|
|
|
|
#define ATPX_MUX_IGD 0
|
|
#define ATPX_MUX_DISCRETE 1
|
|
|
|
static struct radeon_atpx_priv {
|
|
bool atpx_detected;
|
|
/* handle for device - and atpx */
|
|
acpi_handle dhandle;
|
|
acpi_handle atpx_handle;
|
|
acpi_handle atrm_handle;
|
|
} radeon_atpx_priv;
|
|
|
|
/* retrieve the ROM in 4k blocks */
|
|
static int radeon_atrm_call(acpi_handle atrm_handle, uint8_t *bios,
|
|
int offset, int len)
|
|
{
|
|
acpi_status status;
|
|
union acpi_object atrm_arg_elements[2], *obj;
|
|
struct acpi_object_list atrm_arg;
|
|
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL};
|
|
|
|
atrm_arg.count = 2;
|
|
atrm_arg.pointer = &atrm_arg_elements[0];
|
|
|
|
atrm_arg_elements[0].type = ACPI_TYPE_INTEGER;
|
|
atrm_arg_elements[0].integer.value = offset;
|
|
|
|
atrm_arg_elements[1].type = ACPI_TYPE_INTEGER;
|
|
atrm_arg_elements[1].integer.value = len;
|
|
|
|
status = acpi_evaluate_object(atrm_handle, NULL, &atrm_arg, &buffer);
|
|
if (ACPI_FAILURE(status)) {
|
|
printk("failed to evaluate ATRM got %s\n", acpi_format_exception(status));
|
|
return -ENODEV;
|
|
}
|
|
|
|
obj = (union acpi_object *)buffer.pointer;
|
|
memcpy(bios+offset, obj->buffer.pointer, len);
|
|
kfree(buffer.pointer);
|
|
return len;
|
|
}
|
|
|
|
bool radeon_atrm_supported(struct pci_dev *pdev)
|
|
{
|
|
/* get the discrete ROM only via ATRM */
|
|
if (!radeon_atpx_priv.atpx_detected)
|
|
return false;
|
|
|
|
if (radeon_atpx_priv.dhandle == DEVICE_ACPI_HANDLE(&pdev->dev))
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
|
|
int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len)
|
|
{
|
|
return radeon_atrm_call(radeon_atpx_priv.atrm_handle, bios, offset, len);
|
|
}
|
|
|
|
static int radeon_atpx_get_version(acpi_handle handle)
|
|
{
|
|
acpi_status status;
|
|
union acpi_object atpx_arg_elements[2], *obj;
|
|
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 = ATPX_VERSION;
|
|
|
|
atpx_arg_elements[1].type = ACPI_TYPE_INTEGER;
|
|
atpx_arg_elements[1].integer.value = ATPX_VERSION;
|
|
|
|
status = acpi_evaluate_object(handle, NULL, &atpx_arg, &buffer);
|
|
if (ACPI_FAILURE(status)) {
|
|
printk("%s: failed to call ATPX: %s\n", __func__, acpi_format_exception(status));
|
|
return -ENOSYS;
|
|
}
|
|
obj = (union acpi_object *)buffer.pointer;
|
|
if (obj && (obj->type == ACPI_TYPE_BUFFER))
|
|
printk(KERN_INFO "radeon atpx: version is %d\n", *((u8 *)(obj->buffer.pointer) + 2));
|
|
kfree(buffer.pointer);
|
|
return 0;
|
|
}
|
|
|
|
static int radeon_atpx_execute(acpi_handle handle, int cmd_id, u16 value)
|
|
{
|
|
acpi_status status;
|
|
union acpi_object atpx_arg_elements[2];
|
|
struct acpi_object_list atpx_arg;
|
|
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
|
|
uint8_t buf[4] = {0};
|
|
|
|
if (!handle)
|
|
return -EINVAL;
|
|
|
|
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 = cmd_id;
|
|
|
|
buf[2] = value & 0xff;
|
|
buf[3] = (value >> 8) & 0xff;
|
|
|
|
atpx_arg_elements[1].type = ACPI_TYPE_BUFFER;
|
|
atpx_arg_elements[1].buffer.length = 4;
|
|
atpx_arg_elements[1].buffer.pointer = buf;
|
|
|
|
status = acpi_evaluate_object(handle, NULL, &atpx_arg, &buffer);
|
|
if (ACPI_FAILURE(status)) {
|
|
printk("%s: failed to call ATPX: %s\n", __func__, acpi_format_exception(status));
|
|
return -ENOSYS;
|
|
}
|
|
kfree(buffer.pointer);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int radeon_atpx_set_discrete_state(acpi_handle handle, int state)
|
|
{
|
|
return radeon_atpx_execute(handle, ATPX_GPU_PWR, state);
|
|
}
|
|
|
|
static int radeon_atpx_switch_mux(acpi_handle handle, int mux_id)
|
|
{
|
|
return radeon_atpx_execute(handle, ATPX_MUX_SELECT, mux_id);
|
|
}
|
|
|
|
|
|
static int radeon_atpx_switchto(enum vga_switcheroo_client_id id)
|
|
{
|
|
if (id == VGA_SWITCHEROO_IGD)
|
|
radeon_atpx_switch_mux(radeon_atpx_priv.atpx_handle, 0);
|
|
else
|
|
radeon_atpx_switch_mux(radeon_atpx_priv.atpx_handle, 1);
|
|
return 0;
|
|
}
|
|
|
|
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_handle, state);
|
|
return 0;
|
|
}
|
|
|
|
static bool radeon_atpx_pci_probe_handle(struct pci_dev *pdev)
|
|
{
|
|
acpi_handle dhandle, atpx_handle, atrm_handle;
|
|
acpi_status status;
|
|
|
|
dhandle = DEVICE_ACPI_HANDLE(&pdev->dev);
|
|
if (!dhandle)
|
|
return false;
|
|
|
|
status = acpi_get_handle(dhandle, "ATPX", &atpx_handle);
|
|
if (ACPI_FAILURE(status))
|
|
return false;
|
|
|
|
status = acpi_get_handle(dhandle, "ATRM", &atrm_handle);
|
|
if (ACPI_FAILURE(status))
|
|
return false;
|
|
|
|
radeon_atpx_priv.dhandle = dhandle;
|
|
radeon_atpx_priv.atpx_handle = atpx_handle;
|
|
radeon_atpx_priv.atrm_handle = atrm_handle;
|
|
return true;
|
|
}
|
|
|
|
static int radeon_atpx_init(void)
|
|
{
|
|
/* set up the ATPX handle */
|
|
|
|
radeon_atpx_get_version(radeon_atpx_priv.atpx_handle);
|
|
return 0;
|
|
}
|
|
|
|
static int radeon_atpx_get_client_id(struct pci_dev *pdev)
|
|
{
|
|
if (radeon_atpx_priv.dhandle == DEVICE_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,
|
|
};
|
|
|
|
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;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
void radeon_unregister_atpx_handler(void)
|
|
{
|
|
vga_switcheroo_unregister_handler();
|
|
}
|