NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Issuing ACPI call methods to disable NVIDIA Optimus card



On Fri, Aug 24, 2012 at 01:57:09PM +0200, Bartek Krawczyk wrote:
> I know nothing about writing NetBSD kernel modules so I'll just post
> the methods used on Linux:
> \_SB.PCI0.PEG1.GFX0._OFF - for shutting Nvidia card down
> \_SB.PCI0.PEG1.GFX0._ON - for turning it on before suspend.

But you can also try something like the following.

1. Make a directory "src/sys/modules/nvidia". Create a Makefile there with:

        .include "../Makefile.inc"

        .PATH:  ${S}/dev/acpi

        KMOD=   nvidia
        SRCS=   nvidia.c

        WARNS=  4

        .include <bsd.kmodule.mk>

2. Edit file "src/sys/dev/acpi/files.acpi" and put the following there:

        device  nvidia
        file    dev/acpi/nvidia.c               acpi

3. Drop the attached nvidia.c to "src/sys/dev/acpi".

4. Build within the module directory and load the created .kmod.

- Jukka.
#include <sys/param.h>
#include <sys/module.h>

#include <dev/acpi/acpireg.h>
#include <dev/acpi/acpivar.h>

MODULE(MODULE_CLASS_DRIVER, nvidia, NULL);

#define NVIDIA_ON "\\_SB.PCI0.PEG1.GFX0._ON"
#define NVIDIA_OFF "\\_SB.PCI0.PEG1.GFX0._OFF"

/*
 * Turns nVidia card off upon load and on upon unload.
 */
static int
nvidia_modcmd(modcmd_t cmd, void *aux)
{
        ACPI_INTEGER val;
        ACPI_STATUS rv;

        switch (cmd) {

        case MODULE_CMD_INIT:
                rv = acpi_eval_integer(NULL, NVIDIA_OFF, &val);

                if (ACPI_FAILURE(rv))
                        (void)printf("Failed to evaluate '%s': %s\n",
                            NVIDIA_OFF, AcpiFormatException(rv));

                break;

        case MODULE_CMD_FINI:
                rv = acpi_eval_integer(NULL, NVIDIA_ON, &val);

                if (ACPI_FAILURE(rv))
                        (void)printf("Failed to evaluate '%s': %s\n",
                            NVIDIA_OFF, AcpiFormatException(rv));

                break;

        default:
                return ENOTTY;
        }

        return 0;
}


Home | Main Index | Thread Index | Old Index