Giter VIP home page Giter VIP logo

linux-surfacebook2-mshw0153's Introduction

Linux Driver for Surface Book 2 dGPU Hot-Plug System

Note: This module is now integrated into https://github.com/qzed/linux-surfacegen5-acpi, thus this repository will be archived shortly.

Allows powering on/off of the discrete GPU via sysfs.

This is not a complete replacement of bbswitch/prime, so you need to manually unload/re-load the driver modules before/after changing the power-state. Furthermore, you manually need to set the powerstate before running e.g. optirun.

Controlling the dGPU Power State

The easiest way to change the dGPU power state is to use the surface command line utility. With it installed, simply run sudo surface dgpu set <state> where <state> is either on or off. Alternatively, the dGPU power state can be accessed via its sysfs attribute

/sys/bus/acpi/devices/MSHW0153:00/physical_node/dgpu_power

i.e. it can be queried and set via this attribute using your standard boolean parameter strings (meaning one of off/0/n or on/1/y).

Warning: It is strongly recommended you unload the graphics driver (e.g. nvidia or nouveau) before disabling the dGPU dynamically. While it seems possible to disable the dGPU with the nvidia driver loaded programs using it will crash even though the driver itself won't. Unloading the module only succeeds when no program is using the dGPU and is therefore safe step to avoid such crashes.

Via Module Parameters

The dGPU power-state can also be automatically set when this module is loaded or unloaded via the following module parameters:

  • dgpu_power_init:

    • Description: The power-state to set when loading this module.
    • Values: 0 (off), 1 (on), -1 (as is).
    • Default: 0 (off).
  • dgpu_power_exit:

    • Description: The power-state to set when unloading this module.
    • Values: 0 (off), 1 (on), -1 (as is).
    • Default: 1 (on).
  • dgpu_power_susp:

    • Description: The power-state to set when suspending the device. The previous power-state will be restored when resuming.
    • Values: 0 (off), 1 (on), -1 (as is).
    • Default: -1 (as-is).

Warning: By default, the dGPU is turned off when the module loads, changing this behavior may have unwanted side-effects. Some desktop-environments (including Gnome) claim the dGPU when it is turned on during their initialization phase. This will result in you being unable to unload the graphics driver and ultimately crashes or hang-ups when you disable the dGPU dynamically. Keeping the dGPU disabled during this initialization phase avoids this problem, so if you want the dGPU to be permanently powered on, you may want to write a script that runs after you log in into your desktop environment.

Building the Module

Run make all inside the module directory. The module can then be loaded via insmod surfacebook2_dgpu_hps.ko (and removed with rmmod surfacebook2_dgpu_hps.ko).

Permanently Install the Module

On Arch-Linux

Simply run makepkg -si inside the module directory.

Via DKMS

If you want to permanently install the module (or ensure it is loaded during boot), you can run make dkms-install inside the module directory. To uninstall it, run make dkms-uninstall.

Setting-Up the dGPU for use with bumblebee and the Official Nvidia Driver on Arch Linux

This should be similar on other distributions, as always, consult your respective help-pages and wikis. For this, I assume you have the surface command line utility installed. Alternatively, have a look above on how to turn on/off the dGPU manually via sysfs.

To set-up the dGPU

  1. Install the nvidia driver (e.g. nvidia-dkms). Note that, if you have a custom kernel, it is important you choose a locally compiled version (as usually indicated by the -dkms suffix).
  2. Install bumblebee.
  3. Add your user to the bumblebee group (e.g. usermod -a -G bumblebee <yourusername>).
  4. Enable bumblebeed.service (systemctl enable bumblebeed.service). Alternatively, you can also start/stop the service before/after each use.
  5. Reboot.

Now you can actually use the dGPU. I recommend putting the commands below into a simple wrapper script.

  1. Turn on dGPU, e.g. via sudo surface dgpu set on.
  2. Load the Nvidia modules (sudo nvidia-modprobe).
  3. If you encounter a message indicating that the Bumblebee daemon has not been startet yet, you may need to wait a bit for bumblebeed.service to become active or alternatively run systemctl start bumblebeed.service.
  4. Run your desired application on the dGPU with optirun <application>. To verify the Nvidia GPU is actually used, you can run optirun glxgears -v.

To fully disable the dGPU (e.g. for power-savings)

  1. Close all applications using the dGPU.
  2. Unload the Nvidia driver modules (sudo modprobe -r nvidia_modeset followed by sudo modprobe -r nvidia). If you encounter a message specifying that the nvidia module is in use, you either have other modules depending on the nvidia driver, which you need to unload, or applications using it, which you need to close.
  3. Turn off the dGPU, e.g. via sudo surface dgpu set off.

Additionally, I recommend adjusting the performance mode of your device to your needs, e.g. by running sudo surface performance set 4 to set the device to best-performance mode or sudo surface performance set 1 to set the device to the default performance mode. This has a direct influence on the cooling strategy of the device. See the help-text printed when running surface performance for more details on this.

linux-surfacebook2-mshw0153's People

Contributors

qzed avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

linux-surfacebook2-mshw0153's Issues

Nvidia on SB2

I'm struggling to get my surface book 2 nvidia card to work on manjaro.
It's pretty much a fresh install of manjaro kde with the latest jakeday patches on qzed's 5.2 kernel.
I followed the instructions here:
https://github.com/qzed/linux-surfacebook2-mshw0153#setting-up-the-dgpu-for-use-with-bumblebee-and-the-official-nvidia-driver-on-arch-linux
I was stuck on the very first step:
Install the nvidia driver (e.g. nvidia-dkms). Note that, if you have a custom kernel, it is important you choose a locally compiled version (as usually indicated by the -dkms suffix).
how do i install the nvidia driver?
I went to the manjaro settings manager where you normally install the nvidia proprietary drivers and it's not even available. only the intel drivers.
so i did "lspci" and there's no nvidia showing anywhere. i type "nvidia-settings" and get:
ERROR: NVIDIA driver is not loaded ERROR: Unable to load info from any available system
So i think i just need some clarification as to how to go about installing the nvidia-dkms as suggested.

EDIT---
I just looked up in my package manager and nvidia is already installed.

sudo mhwd -li -d

NAME: video-hybrid-intel-nvidia-418xx-bumblebee
ATTACHED: PCI
VERSION: 2019.08.24
INFO: Hybrid bumblebee solution for NVIDIA Optimus Technology - Closed source NVIDIA driver & open source intel driver.
PRIORITY: 9
FREEDRIVER: false
DEPENDS: -
CONFLICTS: video-intel video-nvidia-435xx video-nvidia-430xx video-nvidia-418xx video-nvidia-390xx video-nvidia-340xx video-hybrid-intel-nvidia-430xx-bumblebee video-hybrid-intel-nvidia-390xx-bumblebee video-hybrid-intel-nvidia-340xx-bumblebee video-hybrid-intel-nouveau-bumblebee
CLASSIDS: 0300 0302 0300
VENDORIDS: 10de 8086

So i skipped the step and installed bumblebee and now i get an error when i enter systemctl enable bumblebee and it tells me that the unit file can't be found.

How to use it on Ubuntu 18.04

Hello,

Thanks for this, I want to be able to enable / disable my nvidia card .. I installed latest jake kernel patch... and then your module via sudo make dkms-install

But when I try to use it I get command not found

tdurand@tdurand-Surface-Book-2:~$ dgpu_power_init
dgpu_power_init: command not found

I'm sure I'm not using it the they I should, maybe you can point me in the right direction

Thanks

Help Wanted: Debug output across different models

What is this all about?

I'm currently trying to write a driver for MSHW0091, which is central to a lot of functionality provided through the ACPI. A part of this is for the lid state. Now I hear you say "but who cares about the lid state if there's not even battery status?". Implementing the lid state is a lot easier than getting the battery information, and it seems like a good way to figure some things out, design-wise.

Now what does MSHW0153 have to do with the lid state? To determine the lid state, the ACPI lid device queries MSHW0091 for the current base status, i.e. if the base is attached or detached. It seems that those requests have to be handled by the driver of MSHW0091, thus this driver needs to know the status of the base. MSHW0153 seems provide this information, among other things.

Goal: MSHW0153 provides three GPIO signals with corresponding interrupts related to the base of the device. Most likely, these signals correspond to (as indicated in the corresponding _DSM function):

  • the base state (attached/detached),
  • the dedicated GPU power state,
  • the dedicated GPU presence.

I don't know, however, which signal corresponds to which state. I believe that with enough information, especially from device models without a discrete GPU, we can determine this.

How can I help?

  1. Clone this repository.
  2. Build the module (make).
  3. Load the module (sudo insmod sb2_mshw0153.ko).
  4. Detach the device from the base, wait a bit and then re-attach it.
  5. Repeat step 4 once or twice for good measure.
  6. Unload the module (sudo rmmod sb2_mshw0153.ko).
  7. Get the debug output (dmesg | grep mshw0153 > output.log)
  8. Post the debug output here in combination with your device configuration (most importantly dedicated GPU, the rest should not really matter).

If you own a device with a dedicated GPU, I recommend unloading the nouveau module first (sudo modprobe -r nouveau), as this may cause some issues when detaching.

Without DKMS

I'm on NixOS and I'd like to use sb2_shps but NixOS doesn't support DKMS. I tried repackaging this module as a kernel patch, but I'm no kernel developer, so my method was just pattern matching against the patches in linux-surface. While I did get the kernel to build with my patch, sysfs is still missing dgpu_power. So I'm wondering, are there any plans to get this module merged as a patch into jakeday/linux-surface?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.