From 2d9f0e49d785505702df7db6a62e91159e820460 Mon Sep 17 00:00:00 2001 From: Sergiy Kibrik Date: Mon, 20 Mar 2017 15:54:47 +0200 Subject: [PATCH] osv: xen: split xenbus into generic & PCI parts 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 Message-Id: <1490018087-16439-1-git-send-email-sergiy.kibrik@globallogic.com> --- Makefile | 1 + arch/x64/arch-setup.cc | 4 ++-- drivers/xenfront-xenbus.cc | 33 ++++-------------------------- drivers/xenfront-xenbus.hh | 12 +++-------- drivers/xenfront.hh | 2 -- drivers/xenplatform-pci.cc | 41 ++++++++++++++++++++++++++++++++++++++ drivers/xenplatform-pci.hh | 34 +++++++++++++++++++++++++++++++ 7 files changed, 85 insertions(+), 42 deletions(-) create mode 100644 drivers/xenplatform-pci.cc create mode 100644 drivers/xenplatform-pci.hh diff --git a/Makefile b/Makefile index 6846c5eabf..3f011fa802 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/arch/x64/arch-setup.cc b/arch/x64/arch-setup.cc index fb5deaaa1f..325c26ae21 100644 --- a/arch/x64/arch-setup.cc +++ b/arch/x64/arch-setup.cc @@ -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" @@ -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); diff --git a/drivers/xenfront-xenbus.cc b/drivers/xenfront-xenbus.cc index 3f6ab2992e..ba143841b9 100644 --- a/drivers/xenfront-xenbus.cc +++ b/drivers/xenfront-xenbus.cc @@ -5,8 +5,6 @@ * BSD license as described in the LICENSE file in the top-level directory. */ -#include "msr.hh" -#include "xen.hh" #include #include #include "string.h" @@ -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); @@ -127,27 +115,14 @@ void xenbus::for_each_child(std::function func) hw_driver* xenbus::probe(hw_device* dev) { - if (!processor::features().xen_pci) { + if (!is_xen()) return nullptr; - } - - if (auto pci_dev = dynamic_cast(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 */ } }; diff --git a/drivers/xenfront-xenbus.hh b/drivers/xenfront-xenbus.hh index 808545af61..4a587a429e 100644 --- a/drivers/xenfront-xenbus.hh +++ b/drivers/xenfront-xenbus.hh @@ -9,22 +9,18 @@ #define XENFRONT_BUS_DRIVER_H #include "drivers/xenfront.hh" -#include "drivers/pci-device.hh" +#include "drivers/device.hh" #include #include 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; } @@ -40,8 +36,6 @@ namespace xenfront { private: static struct xenbus *_instance; void wait_for_devices(); - pci::device& _dev; - std::unique_ptr _pgsi; struct device _xenstore_device; std::vector _children; diff --git a/drivers/xenfront.hh b/drivers/xenfront.hh index eaea39eba2..8f239dc9bb 100644 --- a/drivers/xenfront.hh +++ b/drivers/xenfront.hh @@ -18,8 +18,6 @@ #include #include -#define XEN_VENDOR_ID 0x5853 - struct xenbus_device_ivars; template diff --git a/drivers/xenplatform-pci.cc b/drivers/xenplatform-pci.cc new file mode 100644 index 0000000000..16488cfa42 --- /dev/null +++ b/drivers/xenplatform-pci.cc @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2013 Cloudius Systems, Ltd. + * 2017 Sergiy Kibrik + * + * 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(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)); +} +} diff --git a/drivers/xenplatform-pci.hh b/drivers/xenplatform-pci.hh new file mode 100644 index 0000000000..1875780445 --- /dev/null +++ b/drivers/xenplatform-pci.hh @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2013 Cloudius Systems, Ltd. + * 2017 Sergiy Kibrik + * + * 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 +#include + +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 _pgsi; + std::unique_ptr _xenbus; +}; +} +#endif /* XENPLATFORM_PCI_H */