Playing Around With QEMU and VT-d

Blog post by pfoetchen on Sat, 2012-04-07 21:38

Yesterday I played a bit with qemu and the VT-d/IOMMU extension. The Vt-d extension present in many modern processors allows you to forward a PCI-device directly to your virtual machine so you can access it from the virtual machine as if it were a real device. This can be very helpful to develop drivers for PCI-devices without having to reboot the whole computer all the time.

For example in my PC I use my Intel-onboard graphic as my main graphics card but I also have a Radeon in the PCI-express slot so I tried to forward it to my Haiku VM and it was more or less successful ;). To do that under Linux you have to detach the card from its real driver (probably the radeon kernel module under linux) and give it to the pci-stub module (you might have to load it first). To get the PCI-IDs and all the other information use lspci.

# where 1002 is the vendor ID and 68f9 is the device ID of the Radeon card
echo "68f9 1002" > /sys/bus/pci/drivers/pci-stub/new_id
#unbind the device from the driver "0000:01:00.0" is the first device on the PCI-express-bus
echo 0000:01:00.0 > /sys/bus/pci/devices/0000:01:00.0/driver/unbind
# unbinding might take some time so better be save than sorry ;)
sleep 5
#and finaly bind it to pci-stub
echo 0000:01:00.0 > /sys/bus/pci/drivers/pci-stub/bind

Now the Radeon card should be assigned to the pci-stub driver (you might have to rebind the audio part, too). This threw some errors for me but it still worked ;)

So we can come to the interesting part of it all: starting qemu with the new device I used the following comandline:

qemu-system-x86_64  -m 1024  -cdrom haiku-nightly-anyboot.image -device pci-assign,host=01:00.0  -serial file:log.txt

The thing that does all the work is the -device pci-assign,host=01:00.0 part that assigns the radeon card we just bound to the pci-stub driver to the virtual machine. Qemu should now start and boot on the normal qemu window but as soon as it loads the (Haiku) radeon driver with some luck your monitor attached to the Radeon card will go on and display something that should look like Haiku ;). It worked for me after some help from Alexander von Gluck.

This method will work with many devices but it has some caveats:

  • binding a graphics card is not yet officially supported by qemu
  • the graphics card was not yet started by the bios so the driver has to start it itself and that is probably the reason why I did get a rather distorted picture an my monitor sounded like it would explode soon ;)...
  • binding single devices does only work with PCI-express. If you want to bind a normal PCI-device you have to bind the whole PCI bus afaik
  • and the whole system is still quite experimental ;)

So have fun with this little trick and develop/test some cool drivers for haiku ;)

Ps: It works for Windows, too: I could play HL2 without any problems on my real Radeon (but I often get bluescreens if the card tries to save power...)
PPs: you should probably not annoy kallist5 with vt-d related bugs to much it is not supposed to work yet ;)

Driver status update : Radeon HD

Blog post by kallisti5 on Fri, 2011-05-13 15:35

EDIT: 05/28/2011: Add card functionality as of r41792

I have recently been working on the radeon_hd graphics driver and accelerant to get extended mode setting complete for the Radeon r600-r800 chipsets (Roughly Radeon HD 31xx - Radeon HD 59xx)

We still have a *very* long way to go, however the following is now working in the driver:

  • Identifying a pretty large range of Radeon HD cards based on PCIID
  • Reading card information such as Memory and recording it
  • Reading the active monitor EDID
  • Creating mode lines from the EDID information above and adding them to the available mode lines
  • Passing the active monitor EDID to the screen preflet for monitor vendor/model/serial identification

Here are the short-term todo items (with focus on getting extended mode setting working):

  • Set non-vesa (extended) mode lines by toggling the vendor-specific Radeon registers
  • Implement PLL controls
  • Add a few card-specific screen preflet options

Here are the long-term todo items:

  • Finish AtomBIOS support to support advanced card functionality
  • Multi-monitor support

I am looking forward to (hopefully!) getting base functionality to the ATI Radeon HD cards. If you have and comments / PCI ID numbers / etc feel free to contact me and let me know.

Here are the current card test results as of 5/28/2011 r41792

Radeon HD 3450 r620  -- kallisti5
   Primary monitor works at native resolution of
   1440x900 but image offset and cut off.

Radeon XT 2600 r630 -- Benjamin Angerer 
  Primary monitor works perfectly. Plugging secondary
  monitor causes major issues as we are using EDID VESA
  results. (we try to use the VESA primary monitor modelines
  on the secondary monitor)

Radeon HD 4350 r710 -- kallisti5
  White screen of doom, incorrect screen mode change.

Radeon HD 5830 r800 -- kallisti5
  White screen of doom, incorrect screen mode change.
Syndicate content