From: Fotis Xenakis <[email protected]> Committer: Waldemar Kozaczuk <[email protected]> Branch: master
virtio: expose shared memory regions Signed-off-by: Fotis Xenakis <[email protected]> Message-Id: <vi1pr03mb4383690324fc94dcdd3b4f53a6...@vi1pr03mb4383.eurprd03.prod.outlook.com> --- diff --git a/drivers/virtio-device.hh b/drivers/virtio-device.hh --- a/drivers/virtio-device.hh +++ b/drivers/virtio-device.hh @@ -76,6 +76,8 @@ public: virtual u8 read_config(u32 offset) = 0; virtual void dump_config() = 0; + virtual bool get_shm(u8 id, mmioaddr_t &addr, u64 &length) = 0; + virtual bool is_modern() = 0; virtual size_t get_vring_alignment() = 0; }; diff --git a/drivers/virtio-mmio.hh b/drivers/virtio-mmio.hh --- a/drivers/virtio-mmio.hh +++ b/drivers/virtio-mmio.hh @@ -136,6 +136,7 @@ public: bool parse_config(); + virtual bool get_shm(u8 id, mmioaddr_t &addr, u64 &length) { /* TODO */ return false; } private: mmio_device_info _dev_info; //u64 _id; diff --git a/drivers/virtio-pci-device.cc b/drivers/virtio-pci-device.cc --- a/drivers/virtio-pci-device.cc +++ b/drivers/virtio-pci-device.cc @@ -253,6 +253,30 @@ u8 virtio_modern_pci_device::read_and_ack_isr() return _isr_cfg->virtio_conf_readb(0); } +// Stores the address and length of the shared memory region identified by @id +// in @addr and @length respectively. Returns false and doesn't modify @addr and +// @length if no region with a matching id is found. +bool virtio_modern_pci_device::get_shm(u8 id, mmioaddr_t &addr, u64 &length) +{ + auto cap = std::find_if(_shm_cfgs.cbegin(), _shm_cfgs.cend(), + [id, this] (const std::unique_ptr<virtio_capability>& cap) { + u8 cap_id = _dev->pci_readb(cap->get_cfg_offset() + + offsetof(virtio_pci_cap, id)); + return cap_id == id; + }); + if (cap == _shm_cfgs.cend()) { + return false; + } + + auto bar = cap->get()->get_bar(); + if (!bar->is_mmio()) { + return false; + } + addr = bar->get_mmio(); + length = bar->get_size(); + return true; +} + bool virtio_modern_pci_device::parse_pci_config() { // Check ABI version diff --git a/drivers/virtio-pci-device.hh b/drivers/virtio-pci-device.hh --- a/drivers/virtio-pci-device.hh +++ b/drivers/virtio-pci-device.hh @@ -116,6 +116,8 @@ public: virtual u8 read_and_ack_isr(); virtual bool is_modern() { return false; } + + virtual bool get_shm(u8 id, mmioaddr_t &addr, u64 &length) { return false; } protected: virtual bool parse_pci_config(); @@ -243,6 +245,7 @@ public: _bar->writel(_bar_offset + offset, val); }; u32 get_cfg_offset() { return _cfg_offset; } + pci::bar* get_bar() { return _bar; } void print(const char *prefix) { virtio_d("%s bar=%d, offset=%x, size=%x", prefix, _bar_no, _bar_offset, _length); @@ -284,6 +287,7 @@ public: virtual bool is_modern() { return true; }; + virtual bool get_shm(u8 id, mmioaddr_t &addr, u64 &length); protected: virtual bool parse_pci_config(); private: -- You received this message because you are subscribed to the Google Groups "OSv Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/osv-dev/000000000000c27b2405a1008f27%40google.com.
