Skip to content

Commit

Permalink
osv: xen: split xenbus into generic & PCI parts
Browse files Browse the repository at this point in the history
Xen platform PCI is x86-specific feature, not currently present on aarch64.

For xenbus to work on both platforms the generic xenbus driver should be probed
directly (under aarch64 in case Xen is detected), but in case of x64 special PCI
driver checks for Xen platform PCI device and probes generic xenbus driver
if such device is found, pretty much like the way it is done in Linux.

Signed-off-by: Sergiy Kibrik <sergiy.kibrik@globallogic.com>
Message-Id: <1490018087-16439-1-git-send-email-sergiy.kibrik@globallogic.com>
  • Loading branch information
sa-kib authored and nyh committed Mar 21, 2017
1 parent 688b58f commit 2d9f0e4
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 42 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ drivers += drivers/ahci.o
drivers += drivers/ide.o
drivers += drivers/scsi-common.o
drivers += drivers/vmw-pvscsi.o
drivers += drivers/xenplatform-pci.o
endif # x64

ifeq ($(arch),aarch64)
Expand Down
4 changes: 2 additions & 2 deletions arch/x64/arch-setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void arch_init_premain()
#include "drivers/virtio-net.hh"
#include "drivers/virtio-assign.hh"
#include "drivers/virtio-rng.hh"
#include "drivers/xenfront-xenbus.hh"
#include "drivers/xenplatform-pci.hh"
#include "drivers/ahci.hh"
#include "drivers/vmw-pvscsi.hh"
#include "drivers/vmxnet3.hh"
Expand Down Expand Up @@ -283,7 +283,7 @@ void arch_init_drivers()
drvman->register_driver(virtio::net::probe);
}
drvman->register_driver(virtio::rng::probe);
drvman->register_driver(xenfront::xenbus::probe);
drvman->register_driver(xenfront::xenplatform_pci::probe);
drvman->register_driver(ahci::hba::probe);
drvman->register_driver(vmw::pvscsi::probe);
drvman->register_driver(vmw::vmxnet3::probe);
Expand Down
33 changes: 4 additions & 29 deletions drivers/xenfront-xenbus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* BSD license as described in the LICENSE file in the top-level directory.
*/

#include "msr.hh"
#include "xen.hh"
#include <osv/types.h>
#include <osv/mmu.hh>
#include "string.h"
Expand Down Expand Up @@ -46,27 +44,17 @@ namespace xenfront {

xenbus *xenbus::_instance = nullptr;

xenbus::xenbus(pci::device& pci_dev)
xenbus::xenbus()
: hw_driver()
, _dev(pci_dev)
{
int irqno = pci_dev.get_interrupt_line();

if (_instance) {
return;
} else {
_instance = this;
}

parse_pci_config();

_dev.set_bus_master(true);
_driver_name = std::string("xenfront-xenbus");

if (!processor::features().xen_vector_callback) {
_pgsi.reset(xen::xen_set_callback(irqno));
}

xs_attach(&_xenstore_device);

xs_scanf(XST_NIL, "domid", "", NULL, "%d", &_domid);
Expand Down Expand Up @@ -127,27 +115,14 @@ void xenbus::for_each_child(std::function<void(xenfront_driver *d)> func)

hw_driver* xenbus::probe(hw_device* dev)
{
if (!processor::features().xen_pci) {
if (!is_xen())
return nullptr;
}

if (auto pci_dev = dynamic_cast<pci::device*>(dev)) {
// dev id is the same for all xen devices?
if (pci_dev->get_subsystem_vid() == XEN_VENDOR_ID) {
return new xenbus(*pci_dev);
}
}
return nullptr;
return new xenbus();
}

void xenbus::dump_config()
{
_dev.dump_config();
}

bool xenbus::parse_pci_config()
{
return true;
/*TODO: print type, name and node path */
}
};

Expand Down
12 changes: 3 additions & 9 deletions drivers/xenfront-xenbus.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,18 @@
#define XENFRONT_BUS_DRIVER_H

#include "drivers/xenfront.hh"
#include "drivers/pci-device.hh"
#include "drivers/device.hh"
#include <osv/device.h>
#include <bsd/porting/bus.h>

namespace xenfront {

class xenbus : public hw_driver {
public:

explicit xenbus(pci::device& dev);
explicit xenbus();
static hw_driver* probe(hw_device* dev);
pci::device& pci_device() { return _dev; }

bool parse_pci_config();
void dump_config();

virtual void dump_config();
virtual std::string get_name() const { return _driver_name; }
const std::string &get_node_path() { return _node_path; }

Expand All @@ -40,8 +36,6 @@ namespace xenfront {
private:
static struct xenbus *_instance;
void wait_for_devices();
pci::device& _dev;
std::unique_ptr<gsi_level_interrupt> _pgsi;
struct device _xenstore_device;

std::vector<xenfront_driver *> _children;
Expand Down
2 changes: 0 additions & 2 deletions drivers/xenfront.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#include <bsd/porting/bus.h>
#include <xen/interface/io/xenbus.h>

#define XEN_VENDOR_ID 0x5853

struct xenbus_device_ivars;

template <typename T>
Expand Down
41 changes: 41 additions & 0 deletions drivers/xenplatform-pci.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2013 Cloudius Systems, Ltd.
* 2017 Sergiy Kibrik <sergiy.kibrik@globallogic.com>
*
* This work is open source software, licensed under the terms of the
* BSD license as described in the LICENSE file in the top-level directory.
*/

#include "xen.hh"
#include "xenplatform-pci.hh"

#define XEN_VENDOR_ID 0x5853
#define XEN_DEVICE_ID 0x0001

namespace xenfront {

hw_driver* xenplatform_pci::probe(hw_device *dev)
{
if (!processor::features().xen_pci)
return nullptr;

if (dev->get_id() == hw_device_id(XEN_VENDOR_ID, XEN_DEVICE_ID)) {
auto pci_dev = dynamic_cast<pci::device*>(dev);
return new xenplatform_pci(*pci_dev);
}

return nullptr;
}

xenplatform_pci::xenplatform_pci(pci::device& dev)
: hw_driver()
, _dev(dev)
{
_dev.set_bus_master(true);
if (!processor::features().xen_vector_callback) {
int irqno = _dev.get_interrupt_line();
_pgsi.reset(xen::xen_set_callback(irqno));
}
_xenbus.reset(xenfront::xenbus::probe(NULL));
}
}
34 changes: 34 additions & 0 deletions drivers/xenplatform-pci.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2013 Cloudius Systems, Ltd.
* 2017 Sergiy Kibrik <sergiy.kibrik@globallogic.com>
*
* This work is open source software, licensed under the terms of the
* BSD license as described in the LICENSE file in the top-level directory.
*/

#ifndef XENPLATFORM_PCI_H
#define XENPLATFORM_PCI_H

#include <drivers/driver.hh>
#include <drivers/xenfront-xenbus.hh>

namespace xenfront {

class xenplatform_pci : public hw_driver {

public:
static hw_driver* probe(hw_device* dev);

explicit xenplatform_pci(pci::device& dev);
virtual void dump_config() { _dev.dump_config(); }
virtual std::string get_name() const {
return std::string("xen-platform-pci");
}

private:
pci::device& _dev;
std::unique_ptr<gsi_level_interrupt> _pgsi;
std::unique_ptr<hw_driver> _xenbus;
};
}
#endif /* XENPLATFORM_PCI_H */

0 comments on commit 2d9f0e4

Please sign in to comment.