# How to enable graphics on latest AMD Ryzen cpu and gpu (7, 8, 9 family)



## priyadarshan (Jun 4, 2022)

I was experiencing kernel freeze first, and xorg freeze later, on a new PC, AMD Ryzen 9 5900HX cpu, Matisse GPU, "green_sardine" firmware,


```
pciconf -lv | grep -i vga
vgapci0@pci0:4:0:0:     class=0x030000 rev=0xc4 hdr=0x00 vendor=0x1002 device=0x1638 subvendor=0x1002 subdevice=0x0123
    subclass   = VGA
```

This is how it was fixed.

Description: As of June 2022, on latest AMD CPUs  (AMD Ryzen 7, 8, 9) AMD graphic drivers will not work yet, manual patching needs to be applied.

On a test machine, using AMD Ryzen 9 5900HX with Radeon Graphics,  I was able to have a perfectly healthy desktop using the following procedure, I believe the same would work with 5700x and 5800x families.

Packages will hopefully be available by August/September, until then, one needs to use ports.

The following is on a machine without source or ports.

*1. Make sure to track 'latest' repository

2. Install git*

`pkg install -y git`

*3. Make sure FreeBSD source is available*

`git clone -b releng/13.1 https://git.freebsd.org/src.git /usr/src`

*4. Make sure ports are available*

`cd /usr/ports`
`portsnap fetch extract`


*5. Build and install latest amd firmware*

`cd /usr/ports/graphics/gpu-firmware-amd-kmod/`

Make sure to drop into sh (not csh), then

`FLAVOR=green_sardine make install clean`


*6. Build and install latest drm-kmod*

`cd /usr/ports/graphics/drm-510-kmod/`

The latest firmware has a bug on our gpu class: Cannot allocate memory on green_sardine

It was fixed 2 weeks ago, see how to apply manually.

PR about Disable HDCP on green_sardine and renoir

Check that patch is already there, If not, apply manually to file `psp_v12_0.c`

`make install clean`

(2022-06-10: PR #172 was merged. No more need to patch *drm-kmod*)


*7. Build and install xf86-video-amdgpu*

`cd /usr/ports/x11-drivers/xf86-video-amdgpu`

`make extract`

Make sure it is updated at least to 22.0.0. If not, apply patch from here: https://reviews.freebsd.org/D35269

Then,

`make install clean`

(Edit 2022-06-19: No need to patch. Drivers are now at least  v.22.0.0)

*8. Install xorg and window manager of choice*

No need for any additional conf file. It should all work auto-magically. I personally like KDE but I prefer to start it manually. So I did this:

`echo "exec startplasma-x11" >> ~/.xinitrc`

Then I can start with:

`startx`

*9. Fix stuttering*

`sysctl kern.sched.steal_thresh=1`

I found it on this mailing list message, as linked from this reddit comment.

*10. Enjoy an excellent (IMHO) desktop experience*


Many thanks to grahamperrin  for pointing to the right way in many other threads, and also to SirDice for his generous assistance to so many beginners over the years. Thank you.


----

Edit 2022-08-30: Now only two ports need to be compiled.

Assuming one has install FreeBSD 13.1 with source and ports, do this from sh (not csh), root:


```
cd /usr/ports
portsnap fetch extract
cd /usr/ports/graphics/gpu-firmware-amd-kmod/
FLAVOR=green_sardine make install clean
cd /usr/ports/graphics/drm-510-kmod/
make install clean
sysrc  kld_list+="amdgpu"
pkg install -y xf86-video-amdgpu

# KDE
pkg install -y xorg kde5
echo "exec startplasma-x11" >> ~/.xinitrc/
```

Make sure to add your desktop user to video group.


----------



## zeissoctopus (Aug 2, 2022)

Ryzen 5600G APU works after installing graphics/drm-510-kmod, graphics/gpu-firmware-amd-kmod@green_sardine


----------



## cmoerz (Aug 3, 2022)

EDIT: Correction if anyone is reading this... I'm stupid; this probably might still not work - I should have focused more on the content of the post, which points out Ryzen 9. Below details were tested on Ryzen 7, so I can't actually say for sure that this works in the given scenario.

So take this with a grain of salt, but leaving it as a signpost for my own stupidity and myself to step speed reading...

I should probably also add that this requires 13 stable to work, if I remember correctly... so release is SOL.

--

One alternative that works with graphics/drm-devel-kmod and x11-servers/xorg-vfbserver is to add a patch file. At least, that's how it worked for me to get X11 running:


```
/usr/ports/graphics/drm-devel-kmod # cat files/patch-drivers_gpu_drm_amd_amdgpu_amdgpu__drv.c
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c.orig        2022-01-25 19:35:39 UTC
+++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -1019,6 +1019,7 @@ static const struct pci_device_id pciidlist[] = {
 
        /* Renoir */
        {0x1002, 0x1636, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RENOIR|AMD_IS_APU},
+       {0x1002, 0x1638, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RENOIR|AMD_IS_APU},
 
        /* Navi12 */
        {0x1002, 0x7360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_NAVI12|AMD_EXP_HW_SUPPORT},
```

this basically tells the driver to handle Cezanne graphics like the Renoir one.

I also had to add /usr/local/etc/X11/xorg.conf.d/amdgpu.conf:

```
Section "Device"
        Identifier "Card0"
        Driver "amdgpu"
EndSection
```


----------



## donallen (Sep 11, 2022)

priyadarshan said:


> I was experiencing kernel freeze first, and xorg freeze later, on a new PC, AMD Ryzen 9 5900HX cpu, Matisse GPU, "green_sardine" firmware,
> 
> 
> ```
> ...


Thank you very much for this. I just upgraded an old PC with a Ryzen 5600g on an MSI board. I installed FreeBSD 13.1 release and got nowhere trying to get
X to work until I found your message. You explained what you'd learned clearly and completely, which brought an hour or two of frustration to an end. Thanks again.


----------

