**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 your FreeBSD sources
2. Rebuild kernel and bhyve
3. Apply sysutils_uefi-edk2-bhyve_files_2019-07-19.tgz patches to /usr/ports/sysutils/uefi-edk2-bhyve-csm
4. Rebuild /usr/ports/sysutils/uefi-edk2-bhyve-csm
5. 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
```
**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
**Known Issues:**
1. EFI fails with following message:
```
Legacy Boot: CDROM 0
Start of legacy boot
E820[ 0]: 0x 0 ---- 0x 9FC00, Type = 0x1
E820[ 1]: 0x 9FC00 ---- 0x A0000, Type = 0x2
E820[ 2]: 0x E0000 ---- 0x 100000, Type = 0x2
E820[ 3]: 0x 100000 ---- 0x BBFBE000, Type = 0x1
E820[ 4]: 0x BBFBE000 ---- 0x BBFDE000, Type = 0x3
E820[ 5]: 0x BBFDE000 ---- 0x BE1D8000, Type = 0x1
E820[ 6]: 0x BE1D8000 ---- 0x BE884000, Type = 0x3
E820[ 7]: 0x BE884000 ---- 0x BE8B4000, Type = 0x1
E820[ 8]: 0x BE8B4000 ---- 0x BF784000, Type = 0x3
E820[ 9]: 0x BF784000 ---- 0x BF789000, Type = 0x1
E820[10]: 0x BF789000 ---- 0x BF958000, Type = 0x3
E820[11]: 0x BF958000 ---- 0x BF95C000, Type = 0x2
E820[12]: 0x BF95C000 ---- 0x BF964000, Type = 0x3
E820[13]: 0x BF964000 ---- 0x BF968000, Type = 0x4
E820[14]: 0x BF968000 ---- 0x BFFF0000, Type = 0x3
E820[15]: 0x BFFF0000 ---- 0x C0000000, Type = 0x1
E820[16]: 0x C0000000 ---- 0x FC000000, Type = 0x2
E820[17]: 0x FEC00000 ---- 0x FEC01000, Type = 0x2
E820[18]: 0x FED00000 ---- 0x FED00400, Type = 0x2
E820[19]: 0x FEE00000 ---- 0x FEF00000, Type = 0x2
E820[20]: 0x 100000000 ---- 0x 140000000, Type = 0x1
PIRQ table in legacy region - F95B0
PCI VGA: 0x1002:0x15DD
PCI VGA: 0x1002:0x15DD
ASSERT /usr/ports/sysutils/uefi-edk2-bhyve-csm/work/uefi-edk2-aa8d718/IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacyPci.c(1732): (Status == 0) || (Status == ((RETURN_STATUS)(0x8000000000000000ULL | (14))))
```
This error is caused by `LegacyBiosInstallVgaRom` at line 2211:
```
2204 if (Status == EFI_SUCCESS) {
2205 Private->VgaInstalled = TRUE;
2206
2207 //
2208 // Attach the VGA thunk driver.
2209 // Assume the video is installed. This prevents potential of infinite recursion.
2210 //
2211 Status = gBS->ConnectController (
2212 VgaHandle,
2213 ConnectHandleBuffer,
2214 NULL,
2215 TRUE
2216 );
2217 }
```
2. It's possible to press a key on startup to enter Boot Menu. If I select `EFI DVD/CDROM` from `Boot Manager`, FreeBSD will start booting and fails with following message:
```
Unhandled ps2 mouse command 0xe1
psm0: <PS/2 Mouse> irq 12 on atkbdc0
psm0: [GIANT-LOCKED]
psm0: model Generic PS/2 mouse, device ID 0
uart0: <16550 or compatible> port 0x3f8-0x3ff irq 4 flags 0x10 on acpi0
uart0: console (115200,n,8,1)
uart1: <16550 or compatible> port 0x2f8-0x2ff irq 3 on acpi0
Unhandled memory access to 0xb0000
Failed to emulate instruction sequence [ f2a4eb110f1f4000488d7dd589c2fc ] at 0xffffffff8120c2e8
Abort trap
```