10 Commits

Author SHA1 Message Date
e0313a70c3 try again! 2020-08-09 23:15:16 +00:00
fd987219fc try again 2020-08-09 23:05:16 +00:00
219c34f5a9 Update bbswitch.c 2020-08-09 22:54:07 +00:00
8ff86a7eff try another idea 2020-08-09 22:47:39 +00:00
c38a3e084d Initial changes 2020-08-09 20:45:42 +00:00
ddbd243638 Add missing proc_fs.h header
Required for 'struct proc_ops' since v5.7-rc1 with commit df23e2be3d24
("acpi: Remove header dependency").
2020-05-26 21:43:35 +02:00
07b110df46 Merge pull request #196 from mateuszmandera/kernel_560
Fix the build with Linux 5.6.0
2020-05-19 23:38:51 +02:00
b0fdcfd847 Use proc_ops structure for kernel version >= 5.6.0
Since 5.6.0, proc_create requires a `struct proc_ops *` argument instead
of `struct file_operations *`.
Commit with the migration in the kernel source can be found at
d56c0d45f0
2020-05-19 23:34:06 +02:00
9dd227019a Merge pull request #158 from karolherbst/fix_4.12
fix building against 4.12

Should work with older kernels too, it was first introduced with torvalds/linux@c22ce14 which includes asm/uaccess.h
2017-07-16 23:53:37 +02:00
322c9625c2 fix building against 4.12 2017-07-09 15:51:10 +02:00
4 changed files with 16 additions and 183 deletions

View File

@ -59,45 +59,6 @@ To uninstall it, run:
# make -f Makefile.dkms uninstall
Lenovo IdeaPad Y470/Y570 and Toshiba SATELLITE P870
---------------------------------------------------
[This kernel bug](https://bugzilla.kernel.org/show_bug.cgi?id=42696) is fixed in
Linux 3.9-rc1 and Linux 3.8.5 which obsoletes this hack. Linux 3.7 is
incompatible with this hack (and already EOL'd, so a backport fix won't be made
available).
In kernel version 3.6 and older, you need to apply an ugly hack on these laptops
to make bbswitch and the
driver (both nouveau and nvidia) work. For now I have decided not to put the
hack in the bbswitch module since it is a very ugly hack that is comparable to
writing a maximum allowable speed of 130 km/h on a traffic sign for a road
where 120 km/h is allowed just because the radar gun does not work properly.
The module has been tested on a Lenovo IdeaPad Y570 running an up-to-date
version of Ubuntu 11.10 Oneiric (64-bit) with Bumblebee 3.0 (3.0-1~oneiricppa2)
installed using the nvidia driver.
To make use of it, use the `hack-lenovo` branch. An example using DKMS:
$ git clone git://github.com/Bumblebee-Project/bbswitch.git -b hack-lenovo
$ cd bbswitch
$ mkdir /usr/src/acpi-handle-hack-0.0.2
# cp Makefile acpi-handle-hack.c /usr/src/acpi-handle-hack-0.0.2
# cp dkms/acpi-handle-hack.conf /usr/src/acpi-handle-hack-0.0.2/dkms.conf
# dkms install -m acpi-handle-hack -v 0.0.2
If everything goes well, you now need to get the hack loaded on boot. On
Ubuntu and Debian, this can be done with:
echo acpi-handle-hack | sudo tee -a /etc/modules
sudo update-initramfs -u
For other systems, adopt the instructions from the *Disable card on boot*
section below. Please do not copy these instructions to blogs/forums/whatever
without warning that the method is a hack (you can refer to the metaphore above)
and that it may crash the machine if incorrectly applied. To apply these
changes, you have to reboot (technically, unloading nvidia/nouveau, bbswitch and
stopping bumblebeed, `modprobe acpi-handle-hack` and starting bumblebeed should
work as well, but saying reboot is shorter)
Usage
-----

View File

@ -1,134 +0,0 @@
/**
* Very ugly hack to work around a wrongly detected ACPI handle, see
* https://bugzilla.kernel.org/show_bug.cgi?id=42696
* https://bugzilla.kernel.org/show_bug.cgi?id=60829
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/acpi.h>
#include <linux/dmi.h>
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Dirty ACPI handle hack for Lenovo IdeaPad Y[45]70");
MODULE_AUTHOR("Peter Lekensteyn <lekensteyn@gmail.com>");
MODULE_VERSION("0.0.2");
static struct pci_dev *dis_dev;
static acpi_handle orig_handle;
/**
* Returns true if the system needs an ACPI handle hack
*/
static bool __init need_acpi_handle_hack(void) {
return dmi_match(DMI_PRODUCT_VERSION, "Lenovo IdeaPad Y470 ")
|| dmi_match(DMI_PRODUCT_VERSION, "Lenovo IdeaPad Y480")
|| dmi_match(DMI_PRODUCT_VERSION, "Lenovo IdeaPad Y570 ")
|| dmi_match(DMI_PRODUCT_VERSION, "LENOVO IDEAPAD Y570 ") /* sys-product-name: PIQY0 */
|| dmi_match(DMI_PRODUCT_VERSION, "Lenovo IdeaPad Y580")
|| dmi_match(DMI_PRODUCT_VERSION, "Lenovo IdeaPad U510")
|| dmi_match(DMI_PRODUCT_VERSION, "PSPLBE-01V00HFR") /* TOSHIBA SATELLITE P870 */
|| dmi_match(DMI_PRODUCT_VERSION, "PSPLBA-02300S") /* TOSHIBA Satellite P870 */
|| dmi_match(DMI_PRODUCT_VERSION, "PSPLFE-00E009FR") /* TOSHIBA Satellite P870 */
|| dmi_match(DMI_PRODUCT_VERSION, "Lenovo G580")
|| dmi_match(DMI_PRODUCT_VERSION, "Lenovo G780")
|| dmi_match(DMI_PRODUCT_VERSION, "Lenovo IdeaPad Z500")
|| (dmi_match(DMI_SYS_VENDOR, "LENOVO") && dmi_match(DMI_PRODUCT_NAME, "PIQY0")) /* Lenovo IdeaPad Y570 */
|| dmi_match(DMI_PRODUCT_NAME, "Aspire V5-573G")
|| dmi_match(DMI_PRODUCT_NAME, "Aspire V5-573PG")
;
}
static struct pci_dev __init *get_discrete_device(void) {
struct pci_dev *pdev = NULL;
while ((pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {
int pci_class = pdev->class >> 8;
if (pci_class != PCI_CLASS_DISPLAY_VGA &&
pci_class != PCI_CLASS_DISPLAY_3D)
continue;
if (pdev->vendor != PCI_VENDOR_ID_INTEL) {
return pdev;
}
}
return NULL;
}
/**
* Very ugly hack to set the ACPI handle, do not use this as exemplary code!
*/
static void dev_set_acpi_handle(struct pci_dev *pdev, acpi_handle handle) {
#ifdef ACPI_HANDLE_SET
ACPI_HANDLE_SET(&pdev->dev, handle);
#else
/* for Linux 3.7 and earlier */
pdev->dev.archdata.acpi_handle = handle;
#endif
}
static int __init hack_apply(void) {
acpi_handle tmp_handle, new_handle;
struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL };
if (!need_acpi_handle_hack()) {
pr_err("Machine does not need ACPI handle hack\n");
return -ENODEV;
}
dis_dev = get_discrete_device();
if (!dis_dev) {
pr_err("No discrete video card found\n");
return -ENODEV;
}
#ifdef ACPI_HANDLE
/* since Linux 3.8 */
orig_handle = ACPI_HANDLE(&dis_dev->dev);
#else
/* removed since Linux 3.13 */
orig_handle = DEVICE_ACPI_HANDLE(&dis_dev->dev);
#endif
if (!orig_handle) {
pr_err("No ACPI handle found for discrete video card\n");
goto free_dev;
}
if (ACPI_FAILURE(acpi_get_name(orig_handle, ACPI_SINGLE_NAME, &buf))) {
pr_err("Could not acquire name for discrete video card\n");
goto free_dev;
}
if (strcmp((char *)buf.pointer, "PEGP") == 0) {
pr_err("Handle has already been changed to PEGP\n");
goto free_name;
}
/* \_SB.PCI0.PEG0.VGA_ -> \_SB.PCI0.PEG0.PEGP */
if (ACPI_FAILURE(acpi_get_parent(orig_handle, &tmp_handle))) {
pr_err("No parent device found for %s\n", (char *)buf.pointer);
goto free_name;
}
if (ACPI_FAILURE(acpi_get_handle(tmp_handle, "PEGP", &new_handle))) {
pr_err("No PEGP handle found on %s\n", (char *)buf.pointer);
goto free_name;
}
pr_info("Setting new ACPI handle for discrete video card\n");
dev_set_acpi_handle(dis_dev, new_handle);
kfree(buf.pointer);
pci_dev_put(dis_dev);
return 0;
free_name:
kfree(buf.pointer);
free_dev:
pci_dev_put(dis_dev);
return -ENODEV;
}
static void __exit hack_undo(void) {
if (orig_handle) {
pr_info("Restoring original ACPI handle for discrete"
" video card\n");
dev_set_acpi_handle(dis_dev, orig_handle);
}
}
module_init(hack_apply);
module_exit(hack_undo);

View File

@ -31,10 +31,12 @@
#include <linux/pci.h>
#include <linux/acpi.h>
#include <linux/module.h>
#include <asm/uaccess.h>
#include <linux/uaccess.h>
#include <linux/suspend.h>
#include <linux/seq_file.h>
#include <linux/pm_runtime.h>
#include <linux/proc_fs.h>
#include <linux/version.h>
#define BBSWITCH_VERSION "0.8"
@ -285,7 +287,7 @@ static void bbswitch_on(void) {
return;
pr_info("enabling discrete graphics\n");
//pci_bridge_secondary_bus_reset(dis_dev);
if (bbswitch_acpi_on())
pr_warn("The discrete card could not be enabled by a _DSM call\n");
@ -375,6 +377,15 @@ static int bbswitch_pm_handler(struct notifier_block *nbp,
return 0;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0)
static struct proc_ops bbswitch_fops = {
.proc_open = bbswitch_proc_open,
.proc_read = seq_read,
.proc_write = bbswitch_proc_write,
.proc_lseek = seq_lseek,
.proc_release= single_release
};
#else
static struct file_operations bbswitch_fops = {
.open = bbswitch_proc_open,
.read = seq_read,
@ -382,6 +393,7 @@ static struct file_operations bbswitch_fops = {
.llseek = seq_lseek,
.release= single_release
};
#endif
static struct notifier_block nb = {
.notifier_call = &bbswitch_pm_handler
@ -418,12 +430,13 @@ static int __init bbswitch_init(void) {
acpi_get_name(handle, ACPI_FULL_PATHNAME, &buf);
if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
if (pdev->vendor == PCI_VENDOR_ID_ATI) {
igd_handle = handle;
pr_info("Found integrated VGA device %s: %s\n",
dev_name(&pdev->dev), (char *)buf.pointer);
} else {
dis_dev = pdev;
pci_d3cold_enable(pdev);
dis_handle = handle;
pr_info("Found discrete VGA device %s: %s\n",
dev_name(&pdev->dev), (char *)buf.pointer);

View File

@ -1,7 +0,0 @@
PACKAGE_NAME="acpi-handle-hack"
PACKAGE_VERSION="0.0.2"
MAKE[0]="make KVERSION=$kernelver modname=acpi-handle-hack"
CLEAN="make clean"
BUILT_MODULE_NAME[0]="acpi-handle-hack"
DEST_MODULE_LOCATION[0]="/kernel/drivers/acpi"
AUTOINSTALL="yes"