Exemple #1
0
def _try_set_pci_power_state(state):

    try:
        pci.set_power_state(state)
    except pci.PCIError as e:
        print(
            "ERROR : cannot set PCI power management state. Continuing. Error is : %s"
            % str(e))
Exemple #2
0
def _set_base_state(config):

    # Base state :
    # - no kernel module loaded on the card
    # - bbswitch state to ON if bbswitch is loaded
    # - PCI power state to "on"

    _unload_nvidia_modules()
    _unload_nouveau()
    if checks.is_module_loaded("bbswitch"):
        _set_bbswitch_state("ON")
    pci.set_power_state("on")

    if config["optimus"]["pci_reset"] == "yes":
        pci.reset_nvidia()
def _set_base_state(config):

    # Base state :
    # - no kernel module loaded on the card
    # - bbswitch state to ON if bbswitch is loaded
    # - PCI power state to "on"

    _unload_nvidia_modules()
    _unload_nouveau()

    if not pci.is_nvidia_visible():

        print("Nvidia card not visible in PCI bus")

        if checks.is_module_loaded("bbswitch"):
            _set_bbswitch_state("ON")

        # Unlike bbswitch, It's better to ignore acpi_call altogether if the config
        # file does not ask for it. The user could have this module loaded for other purposes,
        # and we don't want to fire a volley of ACPI commands unless strictly necessary.
        if checks.is_module_loaded("acpi_call") and \
        config["optimus"]["switching"] == "acpi_call":
            _set_acpi_call_state("ON")

        print("Rescanning PCI bus")
        pci.rescan()

        if not pci.is_nvidia_visible():
            raise KernelSetupError("Rescaning Nvidia PCI device failed")

    else:

        if checks.is_module_loaded("bbswitch"):
            _set_bbswitch_state("ON")
        if checks.is_module_loaded("acpi_call") and \
        config["optimus"]["switching"] == "acpi_call":
            _set_acpi_call_state("ON")

    pci.set_power_state("on")

    if config["optimus"]["pci_reset"] == "yes":
        pci.reset_nvidia()
Exemple #4
0
def _setup_intel_mode(config):

    # Resetting the Nvidia card to its base state
    _set_base_state(config)

    # Handling power switching according to the switching backend
    if config["optimus"]["switching"] == "nouveau":
        _load_nouveau(config)

    elif config["optimus"]["switching"] == "bbswitch":
        _load_bbswitch()
        _set_bbswitch_state("OFF")

    elif config["optimus"]["switching"] == "none":
        pass

    # Handling PCI power control
    if config["optimus"]["pci_power_control"] == "yes":
        if config["optimus"]["switching"] == "bbswitch":
            print("bbswitch is enabled, pci_power_control option ignored.")
        else:
            pci.set_power_state("auto")
def _setup_intel_mode(config):

    # Resetting the Nvidia card to its base state
    _set_base_state(config)

    # Handling power switching according to the switching backend
    if config["optimus"]["switching"] == "nouveau":

        try:
            _load_nouveau(config)
        except KernelSetupError as e:
            print("ERROR : cannot load nouveau. Moving on. Error is : %s" %
                  str(e))

    elif config["optimus"]["switching"] == "bbswitch":

        if not checks.is_module_available("bbswitch"):
            print(
                "ERROR : module bbswitch is not available for the current kernel."
                " Is bbswitch or bbswitch-dkms installed ? Moving on...")

        else:
            try:
                _load_bbswitch()
            except KernelSetupError as e:
                print(
                    "ERROR : cannot load bbswitch. Moving on. Error is : %s" %
                    str(e))
            else:
                if config["optimus"]["pci_remove"] == "yes":
                    pci.remove_nvidia()
                _set_bbswitch_state("OFF")

    elif config["optimus"]["switching"] == "acpi_call":

        if not checks.is_module_available("acpi_call"):
            print(
                "ERROR : module acpi_call is not available for the current kernel."
                " Is acpi_call or acpi_call-dkms installed ? Moving on...")

        else:
            try:
                _load_acpi_call()
            except KernelSetupError as e:
                print(
                    "ERROR : cannot load acpi_call. Moving on. Error is : %s" %
                    str(e))
            else:
                if config["optimus"]["pci_remove"] == "yes":
                    pci.remove_nvidia()
                _set_acpi_call_state("OFF")

    elif config["optimus"]["switching"] == "none":
        pass

    # Handling PCI power control
    if config["optimus"]["pci_power_control"] == "yes":
        if config["optimus"]["switching"] == "bbswitch":
            print("bbswitch is enabled, pci_power_control option ignored.")
        elif config["optimus"]["switching"] == "acpi_call":
            print("acpi_call is enabled, pci_power_control option ignored.")
        else:
            pci.set_power_state("auto")