]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm: Fix PCI config space emulation
authorPekka Enberg <penberg@cs.helsinki.fi>
Sat, 31 Jul 2010 20:01:10 +0000 (23:01 +0300)
committerPekka Enberg <penberg@cs.helsinki.fi>
Sat, 31 Jul 2010 20:01:10 +0000 (23:01 +0300)
This fixes the two problems:

  1. Yes, 'register number' is offset in 4 bytes, not 1 byte

  2. We must be able to return sane values for the whole 256 configuration
     space, not just for the first 64 bytes that's covered by the fixed header

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
tools/kvm/pci.c

index b79ac17b32c5c94fa772dae98b20e651f8260858..0ac0ae5f374f9c3ec4568899007682c8619f168b 100644 (file)
@@ -57,9 +57,15 @@ static bool pci_device_matches(uint8_t bus_number, uint8_t device_number, uint8_
 static bool pci_config_data_in(struct kvm *self, uint16_t port, void *data, int size, uint32_t count)
 {
        if (pci_device_matches(0, 1, 0)) {
-               void *p = &virtio_device;
+               unsigned long offset;
 
-               memcpy(data, p + pci_config_address.register_number, size);
+               offset          = pci_config_address.register_number << 2;
+               if (offset < sizeof(struct pci_device_header)) {
+                       void *p = &virtio_device;
+
+                       memcpy(data, p + (pci_config_address.register_number << 2), size);
+               } else
+                       memset(data, 0x00, size);
        } else
                memset(data, 0xff, size);