USB Raw Gadget (an interface that allows to emulate USB devices through the USB Gadget subsystem) has been merged into mainline: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f2c2e717642c66f7fe7e5dd69b2e8ff5849f4d10 …
There are hardware based solutions, but I'm not aware of any implemented solutions for emulating PCI devices within the kernel. Would love to know if something like this exists