Starting with this one, all further patches are sort of
work in progress. This diff implements a way to detach
emulated devices (like a em network interface) in order
to switch them to paravirtualized drivers (e.g. Netfront).
Currently I'm not detaching anything, but provide a way
to do it via three global variables. We'll have to decide
later what policy do we want to implement regarding this:
keep a mix of em's and netfronts or convert them all.
So this is strictly not necessary, but the code is written
and tested, so I'd rather keep it around for later.
OK?
---
sys/dev/pv/xen.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git sys/dev/pv/xen.c sys/dev/pv/xen.c
index 2c7c161..c78cc75 100644
--- sys/dev/pv/xen.c
+++ sys/dev/pv/xen.c
@@ -40,10 +40,11 @@ int xen_init_hypercall(struct xen_softc *);
int xen_getversion(struct xen_softc *);
int xen_getfeatures(struct xen_softc *);
int xen_init_info_page(struct xen_softc *);
int xen_init_cbvec(struct xen_softc *);
int xen_init_interrupts(struct xen_softc *);
+void xen_disable_emulated_devices(struct xen_softc *);
int xen_match(struct device *, void *, void *);
void xen_attach(struct device *, struct device *, void *);
void xen_deferred(void *);
void xen_resume(struct device *);
@@ -104,10 +105,12 @@ xen_attach(struct device *parent, struct device *self,
void *aux)
return;
if (xs_attach(sc))
return;
+ xen_disable_emulated_devices(sc);
+
mountroothook_establish(xen_deferred, sc);
}
void
xen_deferred(void *arg)
@@ -717,5 +720,38 @@ xen_intr_enable(void)
printf("%s: unmasking port %u failed\n",
sc->sc_dev.dv_xname, xi->xi_port);
}
}
}
+
+#include <machine/pio.h>
+
+#define XMI_PORT 0x10
+#define XMI_MAGIC 0x49d2
+#define XMI_UNPLUG_IDE 0x01
+#define XMI_UNPLUG_NIC 0x02
+#define XMI_UNPLUG_IDESEC 0x04
+
+int xen_disable_pv_ide, xen_disable_pv_idesec, xen_disable_pv_nic;
+
+void
+xen_disable_emulated_devices(struct xen_softc *sc)
+{
+#if defined(__i386__) || defined(__amd64__)
+ ushort unplug = 0;
+
+ if (inw(XMI_PORT) != XMI_MAGIC) {
+ printf("%s: no magic!\n", sc->sc_dev.dv_xname);
+ return;
+ }
+ if (xen_disable_pv_ide)
+ unplug |= XMI_UNPLUG_IDE;
+ if (xen_disable_pv_idesec)
+ unplug |= XMI_UNPLUG_IDESEC;
+ if (xen_disable_pv_nic)
+ unplug |= XMI_UNPLUG_NIC;
+ if (unplug) {
+ outw(XMI_PORT, unplug);
+ DPRINTF("%s: disabled emulated devices\n", sc->sc_dev.dv_xname);
+ }
+#endif /* __i386__ || __amd64__ */
+}
--
2.6.3