tech-kern archive

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

Radeon R7



Hello,

I have been trying to make my radeon graphics devices work on NetBSD
9.2. Because the brightness can not be adjusted with the GOP driver.

My system has 2 radeon devices. One is the Kaveri R7 Graphics
(0x1002/0x1309) and the other is the OpalXT R7 M265 (0x1002/0x6604).
And the system is using NetBSD 9.2 (amd64).

My kernel driver was not finding the bios for these devices and was
stopping with a kernel panic. I was able to find the bios for the
Kaveri device in the ACPI tables (FVCT table) and could make the
Kaveri device load and be able to use the system using my external
monitor.

I tried to follow Taylor's suggestion and define CONFIG_ACPI in the
radeon.h header. But this on the other hand made the kernel build fail
in the radeon_ci_dpm.c. This requires me to investigate more, which I
will be doing in the comming days, trying to put as much time as I
can. I will also be researching on how to enable the OpalTX (R7 M265)
and find the bios for that device.

But for now, in the hope that others may find this useful, I am
sending my diff (obtained with "cvs -q diff -u"). The patch/diff
follows below.

Regards,
Riza

? arch/amd64/compile/GENERIC_RADEON_GENFB
? arch/amd64/conf/GENERIC_RADEON_GENFB
Index: dev/pci/pcireg.h
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/pcireg.h,v
retrieving revision 1.147.4.2
diff -u -r1.147.4.2 pcireg.h
--- dev/pci/pcireg.h    19 Mar 2020 19:05:34 -0000    1.147.4.2
+++ dev/pci/pcireg.h    7 Dec 2021 02:43:17 -0000
@@ -487,6 +487,8 @@

 #define    PCI_MAPREG_ROM_ADDR(mr)                        \
         ((mr) & PCI_MAPREG_ROM_ADDR_MASK)
+#define    PCI_MAPREG_ROM_SIZE(mr)                        \
+        (PCI_MAPREG_ROM_ADDR(mr) & -PCI_MAPREG_ROM_ADDR(mr))
 #define    PCI_MAPREG_ROM_VALID_STAT   __BITS(3, 1) /* Validation Status */
 #define    PCI_MAPREG_ROM_VSTAT_NOTSUPP    0x0 /* Validation not supported */
 #define    PCI_MAPREG_ROM_VSTAT_INPROG    0x1 /* Validation in Progress */
Index: external/bsd/drm2/dist/drm/radeon/radeon_bios.c
===================================================================
RCS file: /cvsroot/src/sys/external/bsd/drm2/dist/drm/radeon/radeon_bios.c,v
retrieving revision 1.6
diff -u -r1.6 radeon_bios.c
--- external/bsd/drm2/dist/drm/radeon/radeon_bios.c    27 Aug 2018
13:55:59 -0000    1.6
+++ external/bsd/drm2/dist/drm/radeon/radeon_bios.c    7 Dec 2021 02:43:23 -0000
@@ -34,10 +34,12 @@
 #include "radeon_reg.h"
 #include "radeon.h"
 #include "atom.h"
+#include "atombios.h"

 #include <linux/slab.h>
 #include <linux/acpi.h>
 #include <linux/string.h>
+
 /*
  * BIOS.
  */
@@ -649,6 +651,82 @@
         return legacy_read_disabled_bios(rdev);
 }

+// ******************************************************************************
+// HACK
+
+/*
+ * This code is experimental and is written to make the driver work
on the system
+ * for the radeon r7 m265 device.
+ *
+ * Problems:
+ *
+ *     Do not know why CONFIG_ACPI is not defined.
+ *
+ * Revisions:
+ *
+ *    v3: Made the code resemble the original (ACPI based) using goto's.
+ *    v2: Revised code to use the atom bios structures defined in
netbsd (atombios.h).
+ *     v1: Have used the structures from the openbsd/linux atomfirmware.h file.
+ *         Reusing the acpi_table_header defined in the netbsd acpica
framework.
+ */
+
+#ifndef CONFIG_ACPI
+static bool _radeon_acpi_vfct_bios(struct radeon_device *rdev)
+{
+    bool ret = false;
+    AMD_ACPI_DESCRIPTION_HEADER *hdr;
+    ULONG tbl_size;
+    UEFI_ACPI_VFCT *vfct;
+    GOP_VBIOS_CONTENT *vbios;
+    VFCT_IMAGE_HEADER *vhdr;
+
+  if (!ACPI_SUCCESS(AcpiGetTable("VFCT", 1, (ACPI_TABLE_HEADER**)&hdr))) {
+        return false;
+  }
+
+  tbl_size = hdr->TableLength;
+
+    if (tbl_size < sizeof(UEFI_ACPI_VFCT)) {
+        DRM_ERROR("ACPI VFCT table present but broken (too short #1)\n");
+        goto out_unmap;
+    }
+
+    vfct = (UEFI_ACPI_VFCT *)hdr;
+    if (vfct->VBIOSImageOffset + sizeof(VFCT_IMAGE_HEADER) > tbl_size) {
+        DRM_ERROR("ACPI VFCT table present but broken (too short #2)\n");
+        goto out_unmap;
+    }
+
+    vbios = (GOP_VBIOS_CONTENT *)((char *)hdr + vfct->VBIOSImageOffset);
+    vhdr = &vbios->VbiosHeader;
+    DRM_INFO("ACPI VFCT contains a BIOS for %02x:%02x.%d %04x:%04x, size %d\n",
+            vhdr->PCIBus, vhdr->PCIDevice, vhdr->PCIFunction,
+            vhdr->VendorID, vhdr->DeviceID, vhdr->ImageLength);
+
+    if (vhdr->PCIBus != rdev->pdev->bus->number ||
+        vhdr->PCIDevice != PCI_SLOT(rdev->pdev->devfn) ||
+        vhdr->PCIFunction != PCI_FUNC(rdev->pdev->devfn) ||
+        vhdr->VendorID != rdev->pdev->vendor ||
+        vhdr->DeviceID != rdev->pdev->device) {
+        DRM_INFO("ACPI VFCT table is not for this card\n");
+        goto out_unmap;
+    }
+
+    if (vfct->VBIOSImageOffset + sizeof(VFCT_IMAGE_HEADER) +
vhdr->ImageLength > tbl_size) {
+        DRM_ERROR("ACPI VFCT image truncated\n");
+        goto out_unmap;
+    }
+
+    rdev->bios = kmemdup(&vbios->VbiosContent, vhdr->ImageLength, GFP_KERNEL);
+    ret = !!rdev->bios;
+
+out_unmap:
+    return ret;
+}
+#endif
+
+// ******************************************************************************
+
 #ifdef CONFIG_ACPI
 static bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
 {
@@ -701,7 +779,7 @@
 #else
 static inline bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
 {
-    return false;
+    return _radeon_acpi_vfct_bios(rdev);
 }
 #endif


Home | Main Index | Thread Index | Old Index