From beb095eb19b0ca82e85d7c3524e5b33334e459e5 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Sun, 1 Aug 2010 14:06:17 +0400 Subject: [PATCH] kvm, pci: Claim virtio device ioport in pci header It still doesn't work because we need to fill .class properly. But at least virtio probe function passes fine now. Signed-off-by: Cyrill Gorcunov --- include/kvm/ioport.h | 4 ++++ include/kvm/pci.h | 4 ++-- ioport.c | 2 +- pci.c | 22 ++++++++++++++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/kvm/ioport.h b/include/kvm/ioport.h index 3721910..4243850 100644 --- a/include/kvm/ioport.h +++ b/include/kvm/ioport.h @@ -4,6 +4,10 @@ #include #include +/* some ports we reserve for own use */ +#define IOPORT_DBG 0xe0 +#define IOPORT_VIRTIO 0xea + struct kvm; struct ioport_operations { diff --git a/include/kvm/pci.h b/include/kvm/pci.h index 28d9ada..e8551d8 100644 --- a/include/kvm/pci.h +++ b/include/kvm/pci.h @@ -34,8 +34,8 @@ struct pci_device_header { uint8_t cacheline_size; uint8_t latency_timer; uint8_t header_type; - uint8_t BIST; - uint32_t BAR[6]; + uint8_t bist; + uint32_t bar[6]; uint32_t card_bus; uint16_t subsys_vendor_id; uint16_t subsys_id; diff --git a/ioport.c b/ioport.c index 7fc28dc..874894f 100644 --- a/ioport.c +++ b/ioport.c @@ -86,7 +86,7 @@ static struct ioport_operations *ioport_ops[USHRT_MAX] = { /* PORT 00E0-00EF are 'motherboard specific' so we use them for our internal debugging purposes. */ - [0x00E0] = &debug_ops, + [IOPORT_DBG] = &debug_ops, /* PORT 00ED - DUMMY PORT FOR DELAY??? */ [0x00ED] = &dummy_write_only_ioport_ops, diff --git a/pci.c b/pci.c index d68d56b..1341494 100644 --- a/pci.c +++ b/pci.c @@ -41,6 +41,8 @@ static struct pci_device_header virtio_device = { .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET, .device_id = PCI_DEVICE_ID_VIRTIO_BLK, .header_type = PCI_HEADER_TYPE_NORMAL, + /* .class = (0x01 << 16) | (0x01 << 8) | ((1<<7) | * (1<<1)), */ + .bar[0] = (IOPORT_VIRTIO << 4) | PCI_BASE_ADDRESS_SPACE_IO, }; static bool pci_device_matches(uint8_t bus_number, uint8_t device_number, uint8_t function_number) @@ -84,8 +86,28 @@ static struct ioport_operations pci_config_data_ops = { .io_out = pci_config_data_out, }; +static bool virtio_in(struct kvm *self, uint16_t port, void *data, int size, uint32_t count) +{ + info("virtio_in"); + return true; +} + +static bool virtio_out(struct kvm *self, uint16_t port, void *data, int size, uint32_t count) +{ + info("virtio_out"); + return true; +} + +static struct ioport_operations virtio_io_ops = { + .io_in = virtio_in, + .io_out = virtio_out, +}; + void pci__init(void) { + + ioport__register(IOPORT_VIRTIO, &virtio_io_ops); + ioport__register(PCI_CONFIG_DATA + 0, &pci_config_data_ops); ioport__register(PCI_CONFIG_DATA + 1, &pci_config_data_ops); ioport__register(PCI_CONFIG_DATA + 2, &pci_config_data_ops);