This diff doesn't do much by itself, just hooks up minimal Xen files to the tree. I've split it so that all changes on top will look logically complete.
OK? --- sys/arch/amd64/conf/GENERIC | 2 + sys/dev/pv/files.pv | 5 ++ sys/dev/pv/xen.c | 113 ++++++++++++++++++++++++++++++++++++++++++++ sys/dev/pv/xenvar.h | 25 ++++++++++ 4 files changed, 145 insertions(+) create mode 100644 sys/dev/pv/xen.c create mode 100644 sys/dev/pv/xenvar.h diff --git sys/arch/amd64/conf/GENERIC sys/arch/amd64/conf/GENERIC index 2e4f979..b20b62b 100644 --- sys/arch/amd64/conf/GENERIC +++ sys/arch/amd64/conf/GENERIC @@ -66,10 +66,12 @@ mpbios0 at bios0 ipmi0 at mainbus? disable # IPMI vmt0 at pvbus? # VMware Tools +#xen0 at pvbus? # Xen HVM domU + option PCIVERBOSE option USBVERBOSE pchb* at pci? # PCI-Host bridges aapic* at pci? # AMD 8131 IO apic diff --git sys/dev/pv/files.pv sys/dev/pv/files.pv index 2acad4b..1e5c9bd 100644 --- sys/dev/pv/files.pv +++ sys/dev/pv/files.pv @@ -10,5 +10,10 @@ file dev/pv/pvbus.c pvbus needs-flag # VMware Tools device vmt attach vmt at pvbus file dev/pv/vmt.c vmt needs-flag + +# Xen +device xen {} +attach xen at pvbus +file dev/pv/xen.c xen needs-flag diff --git sys/dev/pv/xen.c sys/dev/pv/xen.c new file mode 100644 index 0000000..ee16d99 --- /dev/null +++ sys/dev/pv/xen.c @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2015 Mike Belopuhov + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/atomic.h> +#include <sys/malloc.h> +#include <sys/kernel.h> +#include <sys/device.h> + +#include <machine/bus.h> +#include <machine/cpu.h> +#include <machine/cpufunc.h> + +#include <uvm/uvm_extern.h> + +#include <dev/pv/pvvar.h> +#include <dev/pv/xenvar.h> + +struct xen_softc *xen_sc; + +void xen_find_base(struct xen_softc *); + +int xen_match(struct device *, void *, void *); +void xen_attach(struct device *, struct device *, void *); +void xen_resume(struct device *); +int xen_activate(struct device *, int); + +struct cfdriver xen_cd = { + NULL, "xen", DV_DULL +}; + +struct cfattach xen_ca = { + sizeof(struct xen_softc), xen_match, xen_attach, NULL, xen_activate +}; + +int +xen_match(struct device *parent, void *match, void *aux) +{ + struct pv_attach_args *pva = aux; + struct pvbus_hv *hv = &pva->pva_hv[PVBUS_XEN]; + + if (hv->hv_base == 0) + return (0); + + return (1); +} + +void +xen_attach(struct device *parent, struct device *self, void *aux) +{ + struct pv_attach_args *pva = (struct pv_attach_args *)aux; + struct pvbus_hv *hv = &pva->pva_hv[PVBUS_XEN]; + struct xen_softc *sc = (struct xen_softc *)self; + + sc->sc_base = hv->hv_base; + + xen_find_base(sc); + + printf("\n"); + + /* Wire it up to the global */ + xen_sc = sc; +} + +void +xen_resume(struct device *self) +{ +} + +int +xen_activate(struct device *self, int act) +{ + int rv = 0; + + switch (act) { + case DVACT_RESUME: + xen_resume(self); + break; + } + return (rv); +} + +void +xen_find_base(struct xen_softc *sc) +{ + uint32_t base, regs[4]; + + for (base = 0x40000000; base < 0x40010000; base += 0x100) { + CPUID(base, regs[0], regs[1], regs[2], regs[3]); + if (!memcmp("XenVMMXenVMM", ®s[1], 12) && + (regs[0] - base) >= 2) { + if (base != sc->sc_base) { + printf(": new base %#x", base); + sc->sc_base = base; + } + break; + } + } +} diff --git sys/dev/pv/xenvar.h sys/dev/pv/xenvar.h new file mode 100644 index 0000000..76061ee --- /dev/null +++ sys/dev/pv/xenvar.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2015 Mike Belopuhov + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _XENVAR_H_ +#define _XENVAR_H_ + +struct xen_softc { + struct device sc_dev; + uint32_t sc_base; +}; + +#endif /* _XENVAR_H_ */ -- 2.6.3