adnanpri / legion-wmi

A WMI driver for Lenovo Legion series of laptops
GNU General Public License v2.0
19 stars 2 forks source link

Helping with this #1

Open ghost opened 2 years ago

ghost commented 2 years ago

Hi, I might have the knowledge to help you on this:

Have you made any progress?

How you traced the acpi call to start with? Reverse Engendered the Bios or used Windbg ACPI tracing?

adnanpri commented 2 years ago

Hello,

No progress I'm afraid. I'm convinced it's an issue with nvidia drivers so I've left it up to them to fix it.

I did try and trace acpi calls with the AMLI debugger but it wasn't clear from the logs what functions were being called or what arguments were being passed. Please see attached file if it makes any sense.

Thanks.

fnq-p.txt (This is the log during going from balanced to perf mode with fn+q)

ghost commented 2 years ago

Ok, I extracted the acpi table from the bios from the Lenovo sites, and wow they are very different from my 4800H legion 5, the strangest thing that I have seen are the hardcode game file name, I would be curios to see for what they're used,seem that is used to shift power between gpu and CPU based on game.

Btw, the Trace make quite sense _Q13 sense byte change on offset 13 of embedded controller (If you open RW everything, or you dump 0xFF byte from 0xFE00D400Physical address If my understanding is corrent changing FN+Q should change offset 0x13).

Then Q13 make a couple of notify to GZFD set the probably, fan speed, so is useless for us. Then as you said it make a call to the NPCF WMI interface, and handle the controll to the nvpcf.inf driver.

The interesting thing are that on the NVPCF there are debug statement that I have not seen on your amli trace:

If you havent yet done it could try to run !amli spewon.

I expect to see something like: ------- NVPCF DSM -------- and other debug symbol that will tell you if nvpcf.inf have called other ACPI method.

Supposition: I think that you will see something like:

------- NVPCF DSM --------
                   NVPCF sub-func#x

------- NV JT DSM --------
           JT fun0 JT_FUNC_SUPPORT
...
           JT fun3 JT_FUNC_POWERCONTROL

Where JT, I think stand for JunctionTemperature as it make sense.

The most interesting to me seem JT_FUNC_POWERCONTROL from \_SB.PCI0.GPP0.PEGP.NVJT with argument 0x03

BTWThese are all Debug message that can appear from NVPCF, ordered with hierarchical order.

------- NV GPS DSM --------
       GPS fun 0
       GPS fun 19
       GPS fun 32
       GPS fun 42

GC6I-Enter-L2
GC6O-Resume-L0
   JT GC6I

------- NV JT DSM --------
           JT fun0 JT_FUNC_SUPPORT
           JT fun1 JT_FUNC_CAPS
           JT fun2 JT_FUNC_POLICYSELECT
           JT fun3 JT_FUNC_POWERCONTROL
           JT fun3 GPPC=
        ToInteger (GPPC)
               JT GETS() return 0x1
               JT GETS() return 0x3

   JT fun4 JT_FUNC_PLATPOLICY
        ------- NVPCF DSM --------
                   NVPCF sub-func#0
                   NVPCF sub-func#1
                   NVPCF sub-func#2
                   NVPCF sub-func#3
                   NVPCF sub-func#4
                   NVPCF sub-func#5
                   NVPCF sub-func#6
arabcian commented 2 years ago

Hey guys im excited after seeing an update on this topic. How it goes what are the chances that we can use our machines at full potential? Is there anything we can do to help? I own a Legion 5 Pro.

LankyFranky89 commented 2 years ago

Hey, I hope you guys can figure this one out, it has kept bugging me ever since I noticed that my GPU would not go over 80W so I am stuck with Windows for the time being. I can not code unfortunately , but I can try and help any way I can. I have a Legion 5 with Ryzen 5 5600H and an RTX 3060.

arabcian commented 2 years ago

No updates on the topic?

adnanpri commented 2 years ago

Sorry I wasn't able to work on this earlier but attempted to debug the method again yesterday.

@SmokelessCPU I'm not very familiar with kernel debugging on Windows so I'm listing out the steps I'd taken. Would greatly appreciate some suggestions here.

  1. Enable kernel debugging on local machine with

    bcdedit /debug on
    bcdedit /dbgsettings local

    Ref. https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/setting-up-local-kernel-debugging-of-a-single-computer-manually

  2. Install and run WinDbg (Ref. https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-download-tools) and run windbg -kl

  3. Add following symbols srv*DownstreamStore*https://msdl.microsoft.com/download/symbols

  4. Add breakpoints

    !amli bp \_SB_.NPCF.NPCF
    !amli bp \_SB.PCI0.GPP0.PEGP.NVJT
  5. Set debugging options

    !amli set spewon logon verboseon

I saw the applied break points with !amli bl and they seem to have been applied properly.

However I'm not sure exactly where I'm supposed to see the output. Every time I'd do something that might trigger an ACPI call (fn+Esc or fn+Q) I'd get the BSOD and crash out.

I tried running !amli debugger but it doesn't seem to do anything. It'd be great if I could step over some of these methods but I'm not sure if the approach is right or if I'm missing some steps.

@SmokelessCPU again some pointers here would be very helpful. Thanks!

EDIT: and what would be really cool is if we could somehow log every ACPI method call along with their arguments :)

ghost commented 2 years ago

Hi @adnanpri, Your approach is almost right, the only problem is that you are setting up a local debugger, Here the problem is that spewon most likely put a couple of bp in the acpi.sys, but breaking the kernel on which the debugger is running, will BSOD.

The solution is to setup a remote debugging, but you require another Windows PC, both connected with Ethernet to the same Router/Switch. The debugged one must be Ethernet, the debugger one could be WiFi, but Never tried.

On the other machine, if you don't want to downloads the all WDK, you can also download the Windbg Preview from the Store(around 80Mb).

Here how setup Remote Debugging: https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/setting-up-a-network-debugging-connection-automatically.

After you get the connection, you' will see that you can pause, break and amli will work, and every time is logging, the target is somehow choppy, as result of multiple breakpoint being hit. But the result will be a much nicer and complete log, not only the Function Entry/Exit, but a complete trace For example, this is for Fn+Space, RGB control

AMLI: FFFFF8025B327600: \_SB.PCI0.LPC0.EC0._QDE()

ffffbe0df4f605fa: {
ffffbe0df4f605fa: | Store(0xde,P80H)=0xde
ffffbe0df4f60601: | Notify(GZFD,0xe6)
ffffbe0df4f60608: }
AMLI: FFFFBE0DF9833040: \_SB.GZFD._WED(0xe6)

ffffbe0df4f6812a: {
ffffbe0df4f6812a: | If(LEqual(Arg0=0xe6,0xd0)=0x0)
ffffbe0df4f681a9: | If(LEqual(Arg0=0xe6,0xd1)=0x0)
ffffbe0df4f681b2: | If(LEqual(Arg0=0xe6,0xe0)=0x0)
ffffbe0df4f681bb: | If(LEqual(Arg0=0xe6,0xe1)=0x0)
ffffbe0df4f68241: | If(LEqual(Arg0=0xe6,0xe2)=0x0)
ffffbe0df4f682da: | If(LEqual(Arg0=0xe6,0xe3)=0x0)
ffffbe0df4f68385: | If(LEqual(Arg0=0xe6,0xe4)=0x0)
ffffbe0df4f68411: | If(LEqual(Arg0=0xe6,0xe5)=0x0)
ffffbe0df4f6849d: | If(LEqual(Arg0=0xe6,0xe6)=0xffffffff)
ffffbe0df4f684a3: | {
ffffbe0df4f684a3: | | Return(One)
ffffbe0df4f684a5: | }
ffffbe0df4f684a5: }

as You can see, it show all the evaluated ACPI code, and the executed one.

The one for FN+Q will be huge, but contain all things, for example, in this small snippet, you can see the Store to the SMUD\SMUF, and the call to ALIB, wich will set the Power Limit of the AMD CPU:

ffffbe0df4f5d9a6: | | | | | | Store(0x6,SMUF)=0x6
ffffbe0df4f5d9ad: | | | | | | Store(FPP5=0xbb80,SMUD)=0xbb80
ffffbe0df4f5d9b6: | | | | | | ALIB(0xc,XX11=Buffer(0x7){ 0x07,0x00,0x06,0x80,0xbb,0x00,0x00})
arabcian commented 2 years ago

Looks like Nvidia 510 drivers add configurable tdp support. But only for intel cpus. You can configure tdp level from Nvidia-settings. How yours going?

jucamohedano commented 2 years ago

Hi! where in the nvidia-settings do you set the tdp? I am currently running ubuntu 20.04 with RTX 3060 on the lenovo legion 5 pro. I wish to get full performance to run machine learning models.

phoon commented 2 years ago

Looks like Nvidia 510 drivers add configurable tdp support. But only for intel cpus. You can configure tdp level from Nvidia-settings. How yours going?

Will amd's cpus support it in the future?

sgraut commented 1 year ago

Hi there! Has anyone made progress on this specific problem? I own the same Laptop and am willing to help if needed. With the current Nvidia driver 525, the 3060 unfortunately still maxes out at 80Watts.

tamimmahmudkhan commented 1 year ago

Hey there! I have just recently gotten my hands on a legion 5 pro with 5800H and 3070. I don't know whether this can help or not but I will try to see if I can access the full 130W on my gpu if I run it through a windows vm using nvidia drivers. If there is some data or log I can obtain through a vm then do let me know.

wondersalmon commented 1 year ago

Arch linux. Legion 5 Pro 2022 6800h RTX 3060. Problem persists. Nvidia driver 530.41.03 (beta driver, there is also a problem with the stable driver). Tested on vanilla and zen kernel (6.2.12)

suchacomic commented 1 year ago

Have you tried enabling nvidia-powerd service? Enabling it fixed the issue for me and I was able to hit 130w on performance mode and power limits were being set correctly when changing modes. (nvidia > 535.54.03 is required)

hgaiser commented 11 months ago

Can confirm: on my Legion 5 Pro with 5800H and 3060 enabling nvidia-powerd made switching power profiles (Fn+Q) also change the wattage for the GPU (according to nvtop and nvidia-smi at least).