Skip to content

Commit

Permalink
virtio: expose shared memory regions
Browse files Browse the repository at this point in the history
Signed-off-by: Fotis Xenakis <[email protected]>
Message-Id: <VI1PR03MB4383690324FC94DCDD3B4F53A6F90@VI1PR03MB4383.eurprd03.prod.outlook.com>
  • Loading branch information
foxeng authored and wkozaczuk committed Mar 16, 2020
1 parent a7c4a46 commit 22a0f99
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/virtio-device.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
1 change: 1 addition & 0 deletions drivers/virtio-mmio.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions drivers/virtio-pci-device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions drivers/virtio-pci-device.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 22a0f99

Please sign in to comment.