From: Sergiy Kibrik <[email protected]>
Committer: Nadav Har'El <[email protected]>
Branch: master

osv: aarch64: support processor::features()

Features used by various Xen drivers, i.e. xenbus.

Signed-off-by: Sergiy Kibrik <[email protected]>
Reviewed-by: Nadav Har'El <[email protected]>
Message-Id: <[email protected]>

---
diff --git a/arch/aarch64/cpuid.cc b/arch/aarch64/cpuid.cc
--- a/arch/aarch64/cpuid.cc
+++ b/arch/aarch64/cpuid.cc
@@ -7,6 +7,7 @@

 #include "cpuid.hh"
 #include "processor.hh"
+#include "xen.hh"

 namespace processor {

@@ -76,4 +77,21 @@ const std::string& features_str()
     return cpuid_str;
 }

+void process_cpuid(features_type& features)
+{
+    xen::get_features(features);
+}
+
+const features_type& features()
+{
+    // features() can be used very early, make sure it is initialized
+    static features_type f;
+    return f;
+}
+
+features_type::features_type()
+{
+    process_cpuid(*this);
+}
+
 }
diff --git a/arch/aarch64/cpuid.hh b/arch/aarch64/cpuid.hh
--- a/arch/aarch64/cpuid.hh
+++ b/arch/aarch64/cpuid.hh
@@ -28,6 +28,15 @@ enum hwcap_bit {
     HWCAP_BIT_N
 };

+struct features_type {
+    features_type();
+    bool xen_clocksource;
+    bool xen_vector_callback;
+    bool xen_pci;
+};
+
+extern const features_type& features();
+
 }

 #endif /* CPUID_HH_ */
diff --git a/arch/aarch64/xen.cc b/arch/aarch64/xen.cc
--- a/arch/aarch64/xen.cc
+++ b/arch/aarch64/xen.cc
@@ -8,20 +8,48 @@
 #include <osv/types.h>
 #include <osv/xen.hh>
 #include <xen/interface/xen.h>
+#include <xen/features.h>
 #include <bsd/porting/netport.h> /* __dead2 defined here */
 #include <machine/xen/xen-os.h>
 #include <xen/evtchn.h>

 #include "arch-dtb.hh"
+#include "cpuid.hh"

 shared_info_t *HYPERVISOR_shared_info;
+uint8_t xen_features[XENFEAT_NR_SUBMAPS * 32];

 namespace xen {

 shared_info_t dummy_info;
 struct xen_shared_info xen_shared_info __attribute__((aligned(4096)));
 constexpr int events_irq = 31; /*FIXME: get from FDT */

+/*TODO: this can be common x64/aarch64 code */
+void get_features(processor::features_type &features)
+{
+    if (!is_xen())
+        return;
+
+    for (unsigned int i = 0; i < XENFEAT_NR_SUBMAPS; i++) {
+        struct xen_feature_info info = {
+            .submap_idx = i,
+        };
+
+        if (HYPERVISOR_xen_version(XENVER_get_features, &info) < 0)
+            assert(0);
+
+        for (int j = 0; j < 32; j++)
+            xen_features[i * 32 + j] = !!(info.submap & 1<<j);
+    }
+
+    features.xen_clocksource = xen_feature(XENFEAT_hvm_safe_pvclock);
+ features.xen_vector_callback = xen_feature(XENFEAT_hvm_callback_vector);
+
+    if (!processor::features().xen_vector_callback)
+        evtchn_irq_is_legacy();
+}
+
 void irq_init()
 {
     if (!is_xen())
diff --git a/arch/aarch64/xen.hh b/arch/aarch64/xen.hh
--- a/arch/aarch64/xen.hh
+++ b/arch/aarch64/xen.hh
@@ -8,8 +8,12 @@
 #ifndef XEN_ARCH_HH
 #define XEN_ARCH_HH

+#include "cpuid.hh"
+
 namespace xen {

+void get_features(processor::features_type &features);
+
 }

 #endif /* XEN_ARCH_HH */

--
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].
For more options, visit https://groups.google.com/d/optout.

Reply via email to