[Bug 73901] Kernel crash after modprobe radeon runpm=1

bugzilla-daemon
2014-04-14T22:15:47Z

--- Comment #9 from Pali Rohár <pali.rohar@gmail.com> ---
I looked into radeon_atpx_handler.c code and I found reason why radeon kernel
driver does not detect ATPX...

First here is lspci output:
00:02.0 VGA compatible controller [0300]: Intel Corporation 4th Gen Core
Processor Integrated Graphics Controller [8086:0416] (rev 06)
01:00.0 Display controller [0380]: Advanced Micro Devices, Inc. [AMD/ATI] Sun
XT [Radeon HD 8670A/8670M/8690M] [1002:6660]

Second here is relevant code of function radeon_atpx_detect(void) from file
radeon_atpx_handler.c

int vga_count = 0;

while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
vga_count++;

has_atpx |= (radeon_atpx_pci_probe_handle(pdev) == true);
}

if (has_atpx && vga_count == 2) { ... ATPX was detected ... }

And some defines (from pci_ids.h):

#define PCI_CLASS_DISPLAY_VGA 0x0300
#define PCI_CLASS_DISPLAY_OTHER 0x0380

Because my Radeon card has pci class 0380 and not 0300 it is not checked for
ATPX in while loop and so vgaswitcheroo is not enabled.

I created this quick & dirty patch and after that runpm=1 working without any
crash.

--- radeon_atpx_handler.c.orig 2014-04-14 17:36:36.583744668 +0200
+++ radeon_atpx_handler.c 2014-04-14 23:50:53.354492060 +0200
@@ -528,6 +528,12 @@ static bool radeon_atpx_detect(void)
has_atpx |= (radeon_atpx_pci_probe_handle(pdev) == true);
}

+ while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_OTHER << 8, pdev)) != NULL)
{
+ vga_count++;
+
+ has_atpx |= (radeon_atpx_pci_probe_handle(pdev) == true);
+ }
+
if (has_atpx && vga_count == 2) {
acpi_get_name(radeon_atpx_priv.atpx.handle, ACPI_FULL_PATHNAME,
&buffer);
printk(KERN_INFO "VGA switcheroo: detected switching method %s
handle\n",

Now also vgaswitcheroo debugfs file appeared:

$ sudo cat /sys/kernel/debug/vgaswitcheroo/switch
0:IGD:+:Pwr:0000:00:02.0
1:DIS: :DynPwr:0000:01:00.0

Alex, I think that now you have everything needed for implementing proper fix
for this bug.