**Description:**
Add support of GPU Passthrough for integrated graphics of AMD Ryzen V1000 APUs.
//Note://
This patch is currently not working on any system.
**Prerequisites:**
- AMD Ryzen V1000 APU with Vega graphics
**How to enable GPU Passthrough:**
Use the new "apu-d" device for your graphics card.
Your bhyve config could look like:
```
bhyve -c 1 -m 4G -HwS \
-s 0,hostbridge \
-s 2,apu-d,4/0/0 \
-s 4,ahci-cd,/root/fbsd/fbsd.iso \
-s 5,ahci-hd,/root/fbsd/fbsd.img \
-s 6,virtio-net,tap10 \
-s 31,lpc \
-l com1,stdio \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI_CSM.fd \
fbsd
```
**Tested Scenarios:**
CPU: AMD Ryzen Embedded V1807B
| **OS** | |
| Windows | Not Working |
| Debian | Not Working |
| FreeBSD | Not Working |
**Installation Steps:**
1. Apply this patch to yourCreate a FreeBSD sourcesimage
2. Rebuild kernel and bhyveApply this patch to your FreeBSD sources
3. Apply sysutils_uefi-edk2-bhyve_files_2019-07-19.tgz patches to /usr/ports/sysutils/uefi-edk2-Rebuild kernel and bhyve-csm
4. RebuildApply following patches of sysutils_uefi-edk2-bhyve_files_2019-07-19.tgz to /usr/ports/sysutils/uefi-edk2-bhyve-csm:
5. Start vm with following config: - patch-IntelFrameWorkModulePkg_Csm_LegacyBiosDxe_LegacyBootSupport.c
- patch-IntelFrameWorkModulePkg_Csm_LegacyBiosDxe_LegacyPci.c
5. Rebuild /usr/ports/sysutils/uefi-edk2-bhyve-csm
6. Start vm with following config:
```
bhyve -c 1 -m 4G -HwS \
-s 0,hostbridge \
-s 2,apu-d,4/0/0 \
-s 4,ahci-cd,/root/fbsd/fbsd.iso \
-s 5,ahci-hd,/root/fbsd/fbsd.img \
-s 6,virtio-net,tap10 \
-s 31,lpc \
-l com1,stdio \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI_CSM.fd \
fbsd
```
7. Press a key to enter Boot Menu
8. Boot your FreeBSD image (`Boot Manager -> EFI Hard Drive`)
9. Build gpu-firmware-kmod, drm-current-kmod and drm-kmod from ports
10. load amdgpu
- `kldload amdgpu`
**Known Limitations:**
- Detection of VBIOS address only uses VFCT table. `drm-kmod/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c` contains more options
**What I've done so far:**
1. Extract PCI ROM support from [[ https://www.gulbra.net/freebsd-bhyve/ | vga-bios patches ]]
2. Add an ioctl to get VBIOS from VFCT
3. Add an apu-d device
- It's a passthru device
- It maps VBIOS into PCI ROM
- Passthrough VGA-Ports and VGA-Memory
4. Add a dummy pci device to allow shadowing of OpROM
**Known Issues:**
1. EFI hangs up after dispatching ROM for APU:Load of amdgpu driver fails with following message:
```
PlatformBdsGetDriverOption<6>[drm] Found VCN firmware Version ENC: 1.9 DEC: 1 VEP: 0 Revision: 28
Boot Mode:0<6>[drm] PSP loading VCN firmware
Found PCI VGA device<6>[drm] reserve 0x400000 from 0xf43f800000 for PSP TMR
PCI VGA: 0x1002:0x15DD<4>[drm] psp command failed and response status is (0x0)
PIRQ table in legacy region - F95B0[drm ERROR :psp_hw_start] PSP load asd failed!
Shadowing OpROM [drm ERROR :psp_hw_init/runtime/isize = C0000/C0000/D400] PSP firmware loading failed
Shadowing OpROM on the PCI device 0/2/0[drm ERROR :amdgpu_device_fw_loading] hw_init of IP block <psp> failed -22
Legacy16DispatchOprom - 00/02/00drmn0: amdgpu_device_ip_init failed
drmn0: Fatal error during GPU init
<6>[drm] amdgpu: finishing device.
<6>[drm] amdgpu: ttm finalized
Warning: can't remove non-dynamic nodes (dri)!
device_attach: drmn0 attach returned 22
```