2008-08-12 20:01:57 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/consio.h>
|
2009-03-11 15:30:12 +00:00
|
|
|
#include <sys/priv.h>
|
2008-08-12 20:01:57 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/taskqueue.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <machine/stdarg.h>
|
Implement vector callback for PVHVM and unify event channel implementations
Re-structure Xen HVM support so that:
- Xen is detected and hypercalls can be performed very
early in system startup.
- Xen interrupt services are implemented using FreeBSD's native
interrupt delivery infrastructure.
- the Xen interrupt service implementation is shared between PV
and HVM guests.
- Xen interrupt handlers can optionally use a filter handler
in order to avoid the overhead of dispatch to an interrupt
thread.
- interrupt load can be distributed among all available CPUs.
- the overhead of accessing the emulated local and I/O apics
on HVM is removed for event channel port events.
- a similar optimization can eventually, and fairly easily,
be used to optimize MSI.
Early Xen detection, HVM refactoring, PVHVM interrupt infrastructure,
and misc Xen cleanups:
Sponsored by: Spectra Logic Corporation
Unification of PV & HVM interrupt infrastructure, bug fixes,
and misc Xen cleanups:
Submitted by: Roger Pau Monné
Sponsored by: Citrix Systems R&D
sys/x86/x86/local_apic.c:
sys/amd64/include/apicvar.h:
sys/i386/include/apicvar.h:
sys/amd64/amd64/apic_vector.S:
sys/i386/i386/apic_vector.s:
sys/amd64/amd64/machdep.c:
sys/i386/i386/machdep.c:
sys/i386/xen/exception.s:
sys/x86/include/segments.h:
Reserve IDT vector 0x93 for the Xen event channel upcall
interrupt handler. On Hypervisors that support the direct
vector callback feature, we can request that this vector be
called directly by an injected HVM interrupt event, instead
of a simulated PCI interrupt on the Xen platform PCI device.
This avoids all of the overhead of dealing with the emulated
I/O APIC and local APIC. It also means that the Hypervisor
can inject these events on any CPU, allowing upcalls for
different ports to be handled in parallel.
sys/amd64/amd64/mp_machdep.c:
sys/i386/i386/mp_machdep.c:
Map Xen per-vcpu area during AP startup.
sys/amd64/include/intr_machdep.h:
sys/i386/include/intr_machdep.h:
Increase the FreeBSD IRQ vector table to include space
for event channel interrupt sources.
sys/amd64/include/pcpu.h:
sys/i386/include/pcpu.h:
Remove Xen HVM per-cpu variable data. These fields are now
allocated via the dynamic per-cpu scheme. See xen_intr.c
for details.
sys/amd64/include/xen/hypercall.h:
sys/dev/xen/blkback/blkback.c:
sys/i386/include/xen/xenvar.h:
sys/i386/xen/clock.c:
sys/i386/xen/xen_machdep.c:
sys/xen/gnttab.c:
Prefer FreeBSD primatives to Linux ones in Xen support code.
sys/amd64/include/xen/xen-os.h:
sys/i386/include/xen/xen-os.h:
sys/xen/xen-os.h:
sys/dev/xen/balloon/balloon.c:
sys/dev/xen/blkback/blkback.c:
sys/dev/xen/blkfront/blkfront.c:
sys/dev/xen/console/xencons_ring.c:
sys/dev/xen/control/control.c:
sys/dev/xen/netback/netback.c:
sys/dev/xen/netfront/netfront.c:
sys/dev/xen/xenpci/xenpci.c:
sys/i386/i386/machdep.c:
sys/i386/include/pmap.h:
sys/i386/include/xen/xenfunc.h:
sys/i386/isa/npx.c:
sys/i386/xen/clock.c:
sys/i386/xen/mp_machdep.c:
sys/i386/xen/mptable.c:
sys/i386/xen/xen_clock_util.c:
sys/i386/xen/xen_machdep.c:
sys/i386/xen/xen_rtc.c:
sys/xen/evtchn/evtchn_dev.c:
sys/xen/features.c:
sys/xen/gnttab.c:
sys/xen/gnttab.h:
sys/xen/hvm.h:
sys/xen/xenbus/xenbus.c:
sys/xen/xenbus/xenbus_if.m:
sys/xen/xenbus/xenbusb_front.c:
sys/xen/xenbus/xenbusvar.h:
sys/xen/xenstore/xenstore.c:
sys/xen/xenstore/xenstore_dev.c:
sys/xen/xenstore/xenstorevar.h:
Pull common Xen OS support functions/settings into xen/xen-os.h.
sys/amd64/include/xen/xen-os.h:
sys/i386/include/xen/xen-os.h:
sys/xen/xen-os.h:
Remove constants, macros, and functions unused in FreeBSD's Xen
support.
sys/xen/xen-os.h:
sys/i386/xen/xen_machdep.c:
sys/x86/xen/hvm.c:
Introduce new functions xen_domain(), xen_pv_domain(), and
xen_hvm_domain(). These are used in favor of #ifdefs so that
FreeBSD can dynamically detect and adapt to the presence of
a hypervisor. The goal is to have an HVM optimized GENERIC,
but more is necessary before this is possible.
sys/amd64/amd64/machdep.c:
sys/dev/xen/xenpci/xenpcivar.h:
sys/dev/xen/xenpci/xenpci.c:
sys/x86/xen/hvm.c:
sys/sys/kernel.h:
Refactor magic ioport, Hypercall table and Hypervisor shared
information page setup, and move it to a dedicated HVM support
module.
HVM mode initialization is now triggered during the
SI_SUB_HYPERVISOR phase of system startup. This currently
occurs just after the kernel VM is fully setup which is
just enough infrastructure to allow the hypercall table
and shared info page to be properly mapped.
sys/xen/hvm.h:
sys/x86/xen/hvm.c:
Add definitions and a method for configuring Hypervisor event
delievery via a direct vector callback.
sys/amd64/include/xen/xen-os.h:
sys/x86/xen/hvm.c:
sys/conf/files:
sys/conf/files.amd64:
sys/conf/files.i386:
Adjust kernel build to reflect the refactoring of early
Xen startup code and Xen interrupt services.
sys/dev/xen/blkback/blkback.c:
sys/dev/xen/blkfront/blkfront.c:
sys/dev/xen/blkfront/block.h:
sys/dev/xen/control/control.c:
sys/dev/xen/evtchn/evtchn_dev.c:
sys/dev/xen/netback/netback.c:
sys/dev/xen/netfront/netfront.c:
sys/xen/xenstore/xenstore.c:
sys/xen/evtchn/evtchn_dev.c:
sys/dev/xen/console/console.c:
sys/dev/xen/console/xencons_ring.c
Adjust drivers to use new xen_intr_*() API.
sys/dev/xen/blkback/blkback.c:
Since blkback defers all event handling to a taskqueue,
convert this task queue to a "fast" taskqueue, and schedule
it via an interrupt filter. This avoids an unnecessary
ithread context switch.
sys/xen/xenstore/xenstore.c:
The xenstore driver is MPSAFE. Indicate as much when
registering its interrupt handler.
sys/xen/xenbus/xenbus.c:
sys/xen/xenbus/xenbusvar.h:
Remove unused event channel APIs.
sys/xen/evtchn.h:
Remove all kernel Xen interrupt service API definitions
from this file. It is now only used for structure and
ioctl definitions related to the event channel userland
device driver.
Update the definitions in this file to match those from
NetBSD. Implementing this interface will be necessary for
Dom0 support.
sys/xen/evtchn/evtchnvar.h:
Add a header file for implemenation internal APIs related
to managing event channels event delivery. This is used
to allow, for example, the event channel userland device
driver to access low-level routines that typical kernel
consumers of event channel services should never access.
sys/xen/interface/event_channel.h:
sys/xen/xen_intr.h:
Standardize on the evtchn_port_t type for referring to
an event channel port id. In order to prevent low-level
event channel APIs from leaking to kernel consumers who
should not have access to this data, the type is defined
twice: Once in the Xen provided event_channel.h, and again
in xen/xen_intr.h. The double declaration is protected by
__XEN_EVTCHN_PORT_DEFINED__ to ensure it is never declared
twice within a given compilation unit.
sys/xen/xen_intr.h:
sys/xen/evtchn/evtchn.c:
sys/x86/xen/xen_intr.c:
sys/dev/xen/xenpci/evtchn.c:
sys/dev/xen/xenpci/xenpcivar.h:
New implementation of Xen interrupt services. This is
similar in many respects to the i386 PV implementation with
the exception that events for bound to event channel ports
(i.e. not IPI, virtual IRQ, or physical IRQ) are further
optimized to avoid mask/unmask operations that aren't
necessary for these edge triggered events.
Stubs exist for supporting physical IRQ binding, but will
need additional work before this implementation can be
fully shared between PV and HVM.
sys/amd64/amd64/mp_machdep.c:
sys/i386/i386/mp_machdep.c:
sys/i386/xen/mp_machdep.c
sys/x86/xen/hvm.c:
Add support for placing vcpu_info into an arbritary memory
page instead of using HYPERVISOR_shared_info->vcpu_info.
This allows the creation of domains with more than 32 vcpus.
sys/i386/i386/machdep.c:
sys/i386/xen/clock.c:
sys/i386/xen/xen_machdep.c:
sys/i386/xen/exception.s:
Add support for new event channle implementation.
2013-08-29 19:52:18 +00:00
|
|
|
#include <xen/xen-os.h>
|
2008-12-29 06:31:03 +00:00
|
|
|
#include <xen/hypervisor.h>
|
|
|
|
#include <xen/xen_intr.h>
|
2008-08-12 20:01:57 +00:00
|
|
|
#include <sys/cons.h>
|
2009-03-11 15:30:12 +00:00
|
|
|
#include <sys/kdb.h>
|
2008-08-12 20:01:57 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
|
|
|
|
#include <dev/xen/console/xencons_ring.h>
|
|
|
|
#include <xen/interface/io/console.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "opt_ddb.h"
|
2014-03-11 10:09:23 +00:00
|
|
|
#include "opt_printf.h"
|
|
|
|
|
2008-08-12 20:01:57 +00:00
|
|
|
#ifdef DDB
|
|
|
|
#include <ddb/ddb.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static char driver_name[] = "xc";
|
|
|
|
devclass_t xc_devclass; /* do not make static */
|
2008-08-20 09:03:03 +00:00
|
|
|
static void xcoutwakeup(struct tty *);
|
2008-08-12 20:01:57 +00:00
|
|
|
static void xc_timeout(void *);
|
|
|
|
static void __xencons_tx_flush(void);
|
|
|
|
static boolean_t xcons_putc(int c);
|
|
|
|
|
|
|
|
/* switch console so that shutdown can occur gracefully */
|
|
|
|
static void xc_shutdown(void *arg, int howto);
|
|
|
|
static int xc_mute;
|
|
|
|
|
|
|
|
static void xcons_force_flush(void);
|
|
|
|
static void xencons_priv_interrupt(void *);
|
|
|
|
|
2009-08-24 08:27:42 +00:00
|
|
|
static cn_probe_t xc_cnprobe;
|
|
|
|
static cn_init_t xc_cninit;
|
|
|
|
static cn_term_t xc_cnterm;
|
|
|
|
static cn_getc_t xc_cngetc;
|
|
|
|
static cn_putc_t xc_cnputc;
|
2011-12-17 15:08:43 +00:00
|
|
|
static cn_grab_t xc_cngrab;
|
|
|
|
static cn_ungrab_t xc_cnungrab;
|
2008-08-12 20:01:57 +00:00
|
|
|
|
|
|
|
#define XC_POLLTIME (hz/10)
|
|
|
|
|
2009-08-24 08:27:42 +00:00
|
|
|
CONSOLE_DRIVER(xc);
|
2008-08-12 20:01:57 +00:00
|
|
|
|
|
|
|
static int xen_console_up;
|
|
|
|
static boolean_t xc_start_needed;
|
|
|
|
static struct callout xc_callout;
|
|
|
|
struct mtx cn_mtx;
|
|
|
|
|
|
|
|
#define RBUF_SIZE 1024
|
|
|
|
#define RBUF_MASK(_i) ((_i)&(RBUF_SIZE-1))
|
|
|
|
#define WBUF_SIZE 4096
|
|
|
|
#define WBUF_MASK(_i) ((_i)&(WBUF_SIZE-1))
|
|
|
|
static char wbuf[WBUF_SIZE];
|
|
|
|
static char rbuf[RBUF_SIZE];
|
|
|
|
static int rc, rp;
|
2014-03-11 10:09:23 +00:00
|
|
|
bool cnsl_evt_reg;
|
2008-08-12 20:01:57 +00:00
|
|
|
static unsigned int wc, wp; /* write_cons, write_prod */
|
Implement vector callback for PVHVM and unify event channel implementations
Re-structure Xen HVM support so that:
- Xen is detected and hypercalls can be performed very
early in system startup.
- Xen interrupt services are implemented using FreeBSD's native
interrupt delivery infrastructure.
- the Xen interrupt service implementation is shared between PV
and HVM guests.
- Xen interrupt handlers can optionally use a filter handler
in order to avoid the overhead of dispatch to an interrupt
thread.
- interrupt load can be distributed among all available CPUs.
- the overhead of accessing the emulated local and I/O apics
on HVM is removed for event channel port events.
- a similar optimization can eventually, and fairly easily,
be used to optimize MSI.
Early Xen detection, HVM refactoring, PVHVM interrupt infrastructure,
and misc Xen cleanups:
Sponsored by: Spectra Logic Corporation
Unification of PV & HVM interrupt infrastructure, bug fixes,
and misc Xen cleanups:
Submitted by: Roger Pau Monné
Sponsored by: Citrix Systems R&D
sys/x86/x86/local_apic.c:
sys/amd64/include/apicvar.h:
sys/i386/include/apicvar.h:
sys/amd64/amd64/apic_vector.S:
sys/i386/i386/apic_vector.s:
sys/amd64/amd64/machdep.c:
sys/i386/i386/machdep.c:
sys/i386/xen/exception.s:
sys/x86/include/segments.h:
Reserve IDT vector 0x93 for the Xen event channel upcall
interrupt handler. On Hypervisors that support the direct
vector callback feature, we can request that this vector be
called directly by an injected HVM interrupt event, instead
of a simulated PCI interrupt on the Xen platform PCI device.
This avoids all of the overhead of dealing with the emulated
I/O APIC and local APIC. It also means that the Hypervisor
can inject these events on any CPU, allowing upcalls for
different ports to be handled in parallel.
sys/amd64/amd64/mp_machdep.c:
sys/i386/i386/mp_machdep.c:
Map Xen per-vcpu area during AP startup.
sys/amd64/include/intr_machdep.h:
sys/i386/include/intr_machdep.h:
Increase the FreeBSD IRQ vector table to include space
for event channel interrupt sources.
sys/amd64/include/pcpu.h:
sys/i386/include/pcpu.h:
Remove Xen HVM per-cpu variable data. These fields are now
allocated via the dynamic per-cpu scheme. See xen_intr.c
for details.
sys/amd64/include/xen/hypercall.h:
sys/dev/xen/blkback/blkback.c:
sys/i386/include/xen/xenvar.h:
sys/i386/xen/clock.c:
sys/i386/xen/xen_machdep.c:
sys/xen/gnttab.c:
Prefer FreeBSD primatives to Linux ones in Xen support code.
sys/amd64/include/xen/xen-os.h:
sys/i386/include/xen/xen-os.h:
sys/xen/xen-os.h:
sys/dev/xen/balloon/balloon.c:
sys/dev/xen/blkback/blkback.c:
sys/dev/xen/blkfront/blkfront.c:
sys/dev/xen/console/xencons_ring.c:
sys/dev/xen/control/control.c:
sys/dev/xen/netback/netback.c:
sys/dev/xen/netfront/netfront.c:
sys/dev/xen/xenpci/xenpci.c:
sys/i386/i386/machdep.c:
sys/i386/include/pmap.h:
sys/i386/include/xen/xenfunc.h:
sys/i386/isa/npx.c:
sys/i386/xen/clock.c:
sys/i386/xen/mp_machdep.c:
sys/i386/xen/mptable.c:
sys/i386/xen/xen_clock_util.c:
sys/i386/xen/xen_machdep.c:
sys/i386/xen/xen_rtc.c:
sys/xen/evtchn/evtchn_dev.c:
sys/xen/features.c:
sys/xen/gnttab.c:
sys/xen/gnttab.h:
sys/xen/hvm.h:
sys/xen/xenbus/xenbus.c:
sys/xen/xenbus/xenbus_if.m:
sys/xen/xenbus/xenbusb_front.c:
sys/xen/xenbus/xenbusvar.h:
sys/xen/xenstore/xenstore.c:
sys/xen/xenstore/xenstore_dev.c:
sys/xen/xenstore/xenstorevar.h:
Pull common Xen OS support functions/settings into xen/xen-os.h.
sys/amd64/include/xen/xen-os.h:
sys/i386/include/xen/xen-os.h:
sys/xen/xen-os.h:
Remove constants, macros, and functions unused in FreeBSD's Xen
support.
sys/xen/xen-os.h:
sys/i386/xen/xen_machdep.c:
sys/x86/xen/hvm.c:
Introduce new functions xen_domain(), xen_pv_domain(), and
xen_hvm_domain(). These are used in favor of #ifdefs so that
FreeBSD can dynamically detect and adapt to the presence of
a hypervisor. The goal is to have an HVM optimized GENERIC,
but more is necessary before this is possible.
sys/amd64/amd64/machdep.c:
sys/dev/xen/xenpci/xenpcivar.h:
sys/dev/xen/xenpci/xenpci.c:
sys/x86/xen/hvm.c:
sys/sys/kernel.h:
Refactor magic ioport, Hypercall table and Hypervisor shared
information page setup, and move it to a dedicated HVM support
module.
HVM mode initialization is now triggered during the
SI_SUB_HYPERVISOR phase of system startup. This currently
occurs just after the kernel VM is fully setup which is
just enough infrastructure to allow the hypercall table
and shared info page to be properly mapped.
sys/xen/hvm.h:
sys/x86/xen/hvm.c:
Add definitions and a method for configuring Hypervisor event
delievery via a direct vector callback.
sys/amd64/include/xen/xen-os.h:
sys/x86/xen/hvm.c:
sys/conf/files:
sys/conf/files.amd64:
sys/conf/files.i386:
Adjust kernel build to reflect the refactoring of early
Xen startup code and Xen interrupt services.
sys/dev/xen/blkback/blkback.c:
sys/dev/xen/blkfront/blkfront.c:
sys/dev/xen/blkfront/block.h:
sys/dev/xen/control/control.c:
sys/dev/xen/evtchn/evtchn_dev.c:
sys/dev/xen/netback/netback.c:
sys/dev/xen/netfront/netfront.c:
sys/xen/xenstore/xenstore.c:
sys/xen/evtchn/evtchn_dev.c:
sys/dev/xen/console/console.c:
sys/dev/xen/console/xencons_ring.c
Adjust drivers to use new xen_intr_*() API.
sys/dev/xen/blkback/blkback.c:
Since blkback defers all event handling to a taskqueue,
convert this task queue to a "fast" taskqueue, and schedule
it via an interrupt filter. This avoids an unnecessary
ithread context switch.
sys/xen/xenstore/xenstore.c:
The xenstore driver is MPSAFE. Indicate as much when
registering its interrupt handler.
sys/xen/xenbus/xenbus.c:
sys/xen/xenbus/xenbusvar.h:
Remove unused event channel APIs.
sys/xen/evtchn.h:
Remove all kernel Xen interrupt service API definitions
from this file. It is now only used for structure and
ioctl definitions related to the event channel userland
device driver.
Update the definitions in this file to match those from
NetBSD. Implementing this interface will be necessary for
Dom0 support.
sys/xen/evtchn/evtchnvar.h:
Add a header file for implemenation internal APIs related
to managing event channels event delivery. This is used
to allow, for example, the event channel userland device
driver to access low-level routines that typical kernel
consumers of event channel services should never access.
sys/xen/interface/event_channel.h:
sys/xen/xen_intr.h:
Standardize on the evtchn_port_t type for referring to
an event channel port id. In order to prevent low-level
event channel APIs from leaking to kernel consumers who
should not have access to this data, the type is defined
twice: Once in the Xen provided event_channel.h, and again
in xen/xen_intr.h. The double declaration is protected by
__XEN_EVTCHN_PORT_DEFINED__ to ensure it is never declared
twice within a given compilation unit.
sys/xen/xen_intr.h:
sys/xen/evtchn/evtchn.c:
sys/x86/xen/xen_intr.c:
sys/dev/xen/xenpci/evtchn.c:
sys/dev/xen/xenpci/xenpcivar.h:
New implementation of Xen interrupt services. This is
similar in many respects to the i386 PV implementation with
the exception that events for bound to event channel ports
(i.e. not IPI, virtual IRQ, or physical IRQ) are further
optimized to avoid mask/unmask operations that aren't
necessary for these edge triggered events.
Stubs exist for supporting physical IRQ binding, but will
need additional work before this implementation can be
fully shared between PV and HVM.
sys/amd64/amd64/mp_machdep.c:
sys/i386/i386/mp_machdep.c:
sys/i386/xen/mp_machdep.c
sys/x86/xen/hvm.c:
Add support for placing vcpu_info into an arbritary memory
page instead of using HYPERVISOR_shared_info->vcpu_info.
This allows the creation of domains with more than 32 vcpus.
sys/i386/i386/machdep.c:
sys/i386/xen/clock.c:
sys/i386/xen/xen_machdep.c:
sys/i386/xen/exception.s:
Add support for new event channle implementation.
2013-08-29 19:52:18 +00:00
|
|
|
xen_intr_handle_t xen_intr_handle;
|
|
|
|
device_t xencons_dev;
|
2008-08-12 20:01:57 +00:00
|
|
|
|
2014-03-11 10:09:23 +00:00
|
|
|
/* Virtual address of the shared console page */
|
|
|
|
char *console_page;
|
|
|
|
|
2011-09-02 17:36:01 +00:00
|
|
|
#ifdef KDB
|
|
|
|
static int xc_altbrk;
|
|
|
|
#endif
|
|
|
|
|
2008-08-12 20:01:57 +00:00
|
|
|
#define CDEV_MAJOR 12
|
2008-09-27 08:51:18 +00:00
|
|
|
#define XCUNIT(x) (dev2unit(x))
|
2008-08-12 20:01:57 +00:00
|
|
|
#define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN))
|
|
|
|
#define CN_LOCK_INIT(x, _name) \
|
2009-05-11 22:55:49 +00:00
|
|
|
mtx_init(&x, _name, NULL, MTX_SPIN|MTX_RECURSE)
|
2008-08-12 20:01:57 +00:00
|
|
|
|
|
|
|
#define CN_LOCK(l) \
|
|
|
|
do { \
|
|
|
|
if (panicstr == NULL) \
|
2009-05-11 22:55:49 +00:00
|
|
|
mtx_lock_spin(&(l)); \
|
2008-08-12 20:01:57 +00:00
|
|
|
} while (0)
|
|
|
|
#define CN_UNLOCK(l) \
|
|
|
|
do { \
|
|
|
|
if (panicstr == NULL) \
|
2009-05-11 22:55:49 +00:00
|
|
|
mtx_unlock_spin(&(l)); \
|
2008-08-12 20:01:57 +00:00
|
|
|
} while (0)
|
|
|
|
#define CN_LOCK_ASSERT(x) mtx_assert(&x, MA_OWNED)
|
|
|
|
#define CN_LOCK_DESTROY(x) mtx_destroy(&x)
|
|
|
|
|
|
|
|
|
|
|
|
static struct tty *xccons;
|
|
|
|
|
2008-08-20 09:03:03 +00:00
|
|
|
static tsw_open_t xcopen;
|
|
|
|
static tsw_close_t xcclose;
|
2008-08-12 20:01:57 +00:00
|
|
|
|
2008-08-20 09:03:03 +00:00
|
|
|
static struct ttydevsw xc_ttydevsw = {
|
|
|
|
.tsw_flags = TF_NOPREFIX,
|
|
|
|
.tsw_open = xcopen,
|
|
|
|
.tsw_close = xcclose,
|
|
|
|
.tsw_outwakeup = xcoutwakeup,
|
2008-08-12 20:01:57 +00:00
|
|
|
};
|
|
|
|
|
2014-03-11 10:09:23 +00:00
|
|
|
/*----------------------------- Debug function -------------------------------*/
|
|
|
|
struct putchar_arg {
|
|
|
|
char *buf;
|
|
|
|
size_t size;
|
|
|
|
size_t n_next;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
putchar(int c, void *arg)
|
|
|
|
{
|
|
|
|
struct putchar_arg *pca;
|
|
|
|
|
|
|
|
pca = (struct putchar_arg *)arg;
|
|
|
|
|
|
|
|
if (pca->buf == NULL) {
|
|
|
|
/*
|
|
|
|
* We have no buffer, output directly to the
|
|
|
|
* console char by char.
|
|
|
|
*/
|
|
|
|
HYPERVISOR_console_write((char *)&c, 1);
|
|
|
|
} else {
|
|
|
|
pca->buf[pca->n_next++] = c;
|
|
|
|
if ((pca->size == pca->n_next) || (c = '\0')) {
|
|
|
|
/* Flush the buffer */
|
|
|
|
HYPERVISOR_console_write(pca->buf, pca->n_next);
|
|
|
|
pca->n_next = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xc_printf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
struct putchar_arg pca;
|
|
|
|
#ifdef PRINTF_BUFR_SIZE
|
|
|
|
char buf[PRINTF_BUFR_SIZE];
|
|
|
|
|
|
|
|
pca.buf = buf;
|
|
|
|
pca.size = sizeof(buf);
|
|
|
|
pca.n_next = 0;
|
|
|
|
#else
|
|
|
|
pca.buf = NULL;
|
|
|
|
pca.size = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
KASSERT((xen_domain()), ("call to xc_printf from non Xen guest"));
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
kvprintf(fmt, putchar, &pca, 10, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
#ifdef PRINTF_BUFR_SIZE
|
|
|
|
if (pca.n_next != 0)
|
|
|
|
HYPERVISOR_console_write(buf, pca.n_next);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-08-12 20:01:57 +00:00
|
|
|
static void
|
2009-08-24 08:27:42 +00:00
|
|
|
xc_cnprobe(struct consdev *cp)
|
2008-08-12 20:01:57 +00:00
|
|
|
{
|
2014-03-11 10:09:23 +00:00
|
|
|
if (!xen_pv_domain())
|
|
|
|
return;
|
|
|
|
|
2008-08-12 20:01:57 +00:00
|
|
|
cp->cn_pri = CN_REMOTE;
|
|
|
|
sprintf(cp->cn_name, "%s0", driver_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2009-08-24 08:27:42 +00:00
|
|
|
xc_cninit(struct consdev *cp)
|
2008-08-12 20:01:57 +00:00
|
|
|
{
|
|
|
|
CN_LOCK_INIT(cn_mtx,"XCONS LOCK");
|
|
|
|
|
|
|
|
}
|
2009-08-24 08:27:42 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
xc_cnterm(struct consdev *cp)
|
|
|
|
{
|
2008-08-12 20:01:57 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 15:08:43 +00:00
|
|
|
static void
|
|
|
|
xc_cngrab(struct consdev *cp)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xc_cnungrab(struct consdev *cp)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-08-24 08:27:42 +00:00
|
|
|
static int
|
|
|
|
xc_cngetc(struct consdev *dev)
|
2008-08-12 20:01:57 +00:00
|
|
|
{
|
2010-12-29 05:13:21 +00:00
|
|
|
int ret;
|
2009-03-11 15:30:12 +00:00
|
|
|
|
|
|
|
if (xencons_has_input())
|
|
|
|
xencons_handle_input(NULL);
|
2008-08-12 20:01:57 +00:00
|
|
|
|
|
|
|
CN_LOCK(cn_mtx);
|
2010-12-29 05:13:21 +00:00
|
|
|
if ((rp - rc) && !xc_mute) {
|
2008-08-12 20:01:57 +00:00
|
|
|
/* we need to return only one char */
|
|
|
|
ret = (int)rbuf[RBUF_MASK(rc)];
|
|
|
|
rc++;
|
2010-12-29 05:13:21 +00:00
|
|
|
} else
|
|
|
|
ret = -1;
|
2008-08-12 20:01:57 +00:00
|
|
|
CN_UNLOCK(cn_mtx);
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-08-24 08:27:42 +00:00
|
|
|
xc_cnputc_domu(struct consdev *dev, int c)
|
2008-08-12 20:01:57 +00:00
|
|
|
{
|
|
|
|
xcons_putc(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-08-24 08:27:42 +00:00
|
|
|
xc_cnputc_dom0(struct consdev *dev, int c)
|
2008-08-12 20:01:57 +00:00
|
|
|
{
|
|
|
|
HYPERVISOR_console_io(CONSOLEIO_write, 1, (char *)&c);
|
|
|
|
}
|
|
|
|
|
2009-08-24 08:27:42 +00:00
|
|
|
static void
|
|
|
|
xc_cnputc(struct consdev *dev, int c)
|
|
|
|
{
|
|
|
|
|
2014-03-11 10:09:23 +00:00
|
|
|
if (xen_initial_domain())
|
2009-08-24 08:27:42 +00:00
|
|
|
xc_cnputc_dom0(dev, c);
|
|
|
|
else
|
|
|
|
xc_cnputc_domu(dev, c);
|
|
|
|
}
|
|
|
|
|
2008-08-12 20:01:57 +00:00
|
|
|
static boolean_t
|
|
|
|
xcons_putc(int c)
|
|
|
|
{
|
|
|
|
int force_flush = xc_mute ||
|
|
|
|
#ifdef DDB
|
2014-03-17 16:45:28 +00:00
|
|
|
kdb_active ||
|
2008-08-12 20:01:57 +00:00
|
|
|
#endif
|
|
|
|
panicstr; /* we're not gonna recover, so force
|
|
|
|
* flush
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((wp-wc) < (WBUF_SIZE-1)) {
|
|
|
|
if ((wbuf[WBUF_MASK(wp++)] = c) == '\n') {
|
|
|
|
wbuf[WBUF_MASK(wp++)] = '\r';
|
|
|
|
#ifdef notyet
|
|
|
|
if (force_flush)
|
|
|
|
xcons_force_flush();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
} else if (force_flush) {
|
|
|
|
#ifdef notyet
|
|
|
|
xcons_force_flush();
|
|
|
|
#endif
|
|
|
|
}
|
2014-03-11 10:09:23 +00:00
|
|
|
__xencons_tx_flush();
|
2008-08-12 20:01:57 +00:00
|
|
|
|
|
|
|
/* inform start path that we're pretty full */
|
|
|
|
return ((wp - wc) >= WBUF_SIZE - 100) ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xc_identify(driver_t *driver, device_t parent)
|
|
|
|
{
|
|
|
|
device_t child;
|
2014-03-11 10:09:23 +00:00
|
|
|
|
|
|
|
if (!xen_pv_domain())
|
|
|
|
return;
|
|
|
|
|
2008-08-12 20:01:57 +00:00
|
|
|
child = BUS_ADD_CHILD(parent, 0, driver_name, 0);
|
|
|
|
device_set_driver(child, driver);
|
|
|
|
device_set_desc(child, "Xen Console");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
xc_probe(device_t dev)
|
|
|
|
{
|
|
|
|
|
2013-10-29 14:19:42 +00:00
|
|
|
return (BUS_PROBE_NOWILDCARD);
|
2008-08-12 20:01:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
xc_attach(device_t dev)
|
|
|
|
{
|
2008-12-29 06:31:03 +00:00
|
|
|
int error;
|
2008-08-12 20:01:57 +00:00
|
|
|
|
Implement vector callback for PVHVM and unify event channel implementations
Re-structure Xen HVM support so that:
- Xen is detected and hypercalls can be performed very
early in system startup.
- Xen interrupt services are implemented using FreeBSD's native
interrupt delivery infrastructure.
- the Xen interrupt service implementation is shared between PV
and HVM guests.
- Xen interrupt handlers can optionally use a filter handler
in order to avoid the overhead of dispatch to an interrupt
thread.
- interrupt load can be distributed among all available CPUs.
- the overhead of accessing the emulated local and I/O apics
on HVM is removed for event channel port events.
- a similar optimization can eventually, and fairly easily,
be used to optimize MSI.
Early Xen detection, HVM refactoring, PVHVM interrupt infrastructure,
and misc Xen cleanups:
Sponsored by: Spectra Logic Corporation
Unification of PV & HVM interrupt infrastructure, bug fixes,
and misc Xen cleanups:
Submitted by: Roger Pau Monné
Sponsored by: Citrix Systems R&D
sys/x86/x86/local_apic.c:
sys/amd64/include/apicvar.h:
sys/i386/include/apicvar.h:
sys/amd64/amd64/apic_vector.S:
sys/i386/i386/apic_vector.s:
sys/amd64/amd64/machdep.c:
sys/i386/i386/machdep.c:
sys/i386/xen/exception.s:
sys/x86/include/segments.h:
Reserve IDT vector 0x93 for the Xen event channel upcall
interrupt handler. On Hypervisors that support the direct
vector callback feature, we can request that this vector be
called directly by an injected HVM interrupt event, instead
of a simulated PCI interrupt on the Xen platform PCI device.
This avoids all of the overhead of dealing with the emulated
I/O APIC and local APIC. It also means that the Hypervisor
can inject these events on any CPU, allowing upcalls for
different ports to be handled in parallel.
sys/amd64/amd64/mp_machdep.c:
sys/i386/i386/mp_machdep.c:
Map Xen per-vcpu area during AP startup.
sys/amd64/include/intr_machdep.h:
sys/i386/include/intr_machdep.h:
Increase the FreeBSD IRQ vector table to include space
for event channel interrupt sources.
sys/amd64/include/pcpu.h:
sys/i386/include/pcpu.h:
Remove Xen HVM per-cpu variable data. These fields are now
allocated via the dynamic per-cpu scheme. See xen_intr.c
for details.
sys/amd64/include/xen/hypercall.h:
sys/dev/xen/blkback/blkback.c:
sys/i386/include/xen/xenvar.h:
sys/i386/xen/clock.c:
sys/i386/xen/xen_machdep.c:
sys/xen/gnttab.c:
Prefer FreeBSD primatives to Linux ones in Xen support code.
sys/amd64/include/xen/xen-os.h:
sys/i386/include/xen/xen-os.h:
sys/xen/xen-os.h:
sys/dev/xen/balloon/balloon.c:
sys/dev/xen/blkback/blkback.c:
sys/dev/xen/blkfront/blkfront.c:
sys/dev/xen/console/xencons_ring.c:
sys/dev/xen/control/control.c:
sys/dev/xen/netback/netback.c:
sys/dev/xen/netfront/netfront.c:
sys/dev/xen/xenpci/xenpci.c:
sys/i386/i386/machdep.c:
sys/i386/include/pmap.h:
sys/i386/include/xen/xenfunc.h:
sys/i386/isa/npx.c:
sys/i386/xen/clock.c:
sys/i386/xen/mp_machdep.c:
sys/i386/xen/mptable.c:
sys/i386/xen/xen_clock_util.c:
sys/i386/xen/xen_machdep.c:
sys/i386/xen/xen_rtc.c:
sys/xen/evtchn/evtchn_dev.c:
sys/xen/features.c:
sys/xen/gnttab.c:
sys/xen/gnttab.h:
sys/xen/hvm.h:
sys/xen/xenbus/xenbus.c:
sys/xen/xenbus/xenbus_if.m:
sys/xen/xenbus/xenbusb_front.c:
sys/xen/xenbus/xenbusvar.h:
sys/xen/xenstore/xenstore.c:
sys/xen/xenstore/xenstore_dev.c:
sys/xen/xenstore/xenstorevar.h:
Pull common Xen OS support functions/settings into xen/xen-os.h.
sys/amd64/include/xen/xen-os.h:
sys/i386/include/xen/xen-os.h:
sys/xen/xen-os.h:
Remove constants, macros, and functions unused in FreeBSD's Xen
support.
sys/xen/xen-os.h:
sys/i386/xen/xen_machdep.c:
sys/x86/xen/hvm.c:
Introduce new functions xen_domain(), xen_pv_domain(), and
xen_hvm_domain(). These are used in favor of #ifdefs so that
FreeBSD can dynamically detect and adapt to the presence of
a hypervisor. The goal is to have an HVM optimized GENERIC,
but more is necessary before this is possible.
sys/amd64/amd64/machdep.c:
sys/dev/xen/xenpci/xenpcivar.h:
sys/dev/xen/xenpci/xenpci.c:
sys/x86/xen/hvm.c:
sys/sys/kernel.h:
Refactor magic ioport, Hypercall table and Hypervisor shared
information page setup, and move it to a dedicated HVM support
module.
HVM mode initialization is now triggered during the
SI_SUB_HYPERVISOR phase of system startup. This currently
occurs just after the kernel VM is fully setup which is
just enough infrastructure to allow the hypercall table
and shared info page to be properly mapped.
sys/xen/hvm.h:
sys/x86/xen/hvm.c:
Add definitions and a method for configuring Hypervisor event
delievery via a direct vector callback.
sys/amd64/include/xen/xen-os.h:
sys/x86/xen/hvm.c:
sys/conf/files:
sys/conf/files.amd64:
sys/conf/files.i386:
Adjust kernel build to reflect the refactoring of early
Xen startup code and Xen interrupt services.
sys/dev/xen/blkback/blkback.c:
sys/dev/xen/blkfront/blkfront.c:
sys/dev/xen/blkfront/block.h:
sys/dev/xen/control/control.c:
sys/dev/xen/evtchn/evtchn_dev.c:
sys/dev/xen/netback/netback.c:
sys/dev/xen/netfront/netfront.c:
sys/xen/xenstore/xenstore.c:
sys/xen/evtchn/evtchn_dev.c:
sys/dev/xen/console/console.c:
sys/dev/xen/console/xencons_ring.c
Adjust drivers to use new xen_intr_*() API.
sys/dev/xen/blkback/blkback.c:
Since blkback defers all event handling to a taskqueue,
convert this task queue to a "fast" taskqueue, and schedule
it via an interrupt filter. This avoids an unnecessary
ithread context switch.
sys/xen/xenstore/xenstore.c:
The xenstore driver is MPSAFE. Indicate as much when
registering its interrupt handler.
sys/xen/xenbus/xenbus.c:
sys/xen/xenbus/xenbusvar.h:
Remove unused event channel APIs.
sys/xen/evtchn.h:
Remove all kernel Xen interrupt service API definitions
from this file. It is now only used for structure and
ioctl definitions related to the event channel userland
device driver.
Update the definitions in this file to match those from
NetBSD. Implementing this interface will be necessary for
Dom0 support.
sys/xen/evtchn/evtchnvar.h:
Add a header file for implemenation internal APIs related
to managing event channels event delivery. This is used
to allow, for example, the event channel userland device
driver to access low-level routines that typical kernel
consumers of event channel services should never access.
sys/xen/interface/event_channel.h:
sys/xen/xen_intr.h:
Standardize on the evtchn_port_t type for referring to
an event channel port id. In order to prevent low-level
event channel APIs from leaking to kernel consumers who
should not have access to this data, the type is defined
twice: Once in the Xen provided event_channel.h, and again
in xen/xen_intr.h. The double declaration is protected by
__XEN_EVTCHN_PORT_DEFINED__ to ensure it is never declared
twice within a given compilation unit.
sys/xen/xen_intr.h:
sys/xen/evtchn/evtchn.c:
sys/x86/xen/xen_intr.c:
sys/dev/xen/xenpci/evtchn.c:
sys/dev/xen/xenpci/xenpcivar.h:
New implementation of Xen interrupt services. This is
similar in many respects to the i386 PV implementation with
the exception that events for bound to event channel ports
(i.e. not IPI, virtual IRQ, or physical IRQ) are further
optimized to avoid mask/unmask operations that aren't
necessary for these edge triggered events.
Stubs exist for supporting physical IRQ binding, but will
need additional work before this implementation can be
fully shared between PV and HVM.
sys/amd64/amd64/mp_machdep.c:
sys/i386/i386/mp_machdep.c:
sys/i386/xen/mp_machdep.c
sys/x86/xen/hvm.c:
Add support for placing vcpu_info into an arbritary memory
page instead of using HYPERVISOR_shared_info->vcpu_info.
This allows the creation of domains with more than 32 vcpus.
sys/i386/i386/machdep.c:
sys/i386/xen/clock.c:
sys/i386/xen/xen_machdep.c:
sys/i386/xen/exception.s:
Add support for new event channle implementation.
2013-08-29 19:52:18 +00:00
|
|
|
xencons_dev = dev;
|
2009-05-29 06:41:23 +00:00
|
|
|
xccons = tty_alloc(&xc_ttydevsw, NULL);
|
2008-08-20 09:03:03 +00:00
|
|
|
tty_makedev(xccons, NULL, "xc%r", 0);
|
2008-08-12 20:01:57 +00:00
|
|
|
|
|
|
|
callout_init(&xc_callout, 0);
|
|
|
|
|
|
|
|
xencons_ring_init();
|
|
|
|
|
2014-03-11 10:09:23 +00:00
|
|
|
cnsl_evt_reg = true;
|
2008-08-12 20:01:57 +00:00
|
|
|
callout_reset(&xc_callout, XC_POLLTIME, xc_timeout, xccons);
|
|
|
|
|
2014-03-11 10:09:23 +00:00
|
|
|
if (xen_initial_domain()) {
|
Implement vector callback for PVHVM and unify event channel implementations
Re-structure Xen HVM support so that:
- Xen is detected and hypercalls can be performed very
early in system startup.
- Xen interrupt services are implemented using FreeBSD's native
interrupt delivery infrastructure.
- the Xen interrupt service implementation is shared between PV
and HVM guests.
- Xen interrupt handlers can optionally use a filter handler
in order to avoid the overhead of dispatch to an interrupt
thread.
- interrupt load can be distributed among all available CPUs.
- the overhead of accessing the emulated local and I/O apics
on HVM is removed for event channel port events.
- a similar optimization can eventually, and fairly easily,
be used to optimize MSI.
Early Xen detection, HVM refactoring, PVHVM interrupt infrastructure,
and misc Xen cleanups:
Sponsored by: Spectra Logic Corporation
Unification of PV & HVM interrupt infrastructure, bug fixes,
and misc Xen cleanups:
Submitted by: Roger Pau Monné
Sponsored by: Citrix Systems R&D
sys/x86/x86/local_apic.c:
sys/amd64/include/apicvar.h:
sys/i386/include/apicvar.h:
sys/amd64/amd64/apic_vector.S:
sys/i386/i386/apic_vector.s:
sys/amd64/amd64/machdep.c:
sys/i386/i386/machdep.c:
sys/i386/xen/exception.s:
sys/x86/include/segments.h:
Reserve IDT vector 0x93 for the Xen event channel upcall
interrupt handler. On Hypervisors that support the direct
vector callback feature, we can request that this vector be
called directly by an injected HVM interrupt event, instead
of a simulated PCI interrupt on the Xen platform PCI device.
This avoids all of the overhead of dealing with the emulated
I/O APIC and local APIC. It also means that the Hypervisor
can inject these events on any CPU, allowing upcalls for
different ports to be handled in parallel.
sys/amd64/amd64/mp_machdep.c:
sys/i386/i386/mp_machdep.c:
Map Xen per-vcpu area during AP startup.
sys/amd64/include/intr_machdep.h:
sys/i386/include/intr_machdep.h:
Increase the FreeBSD IRQ vector table to include space
for event channel interrupt sources.
sys/amd64/include/pcpu.h:
sys/i386/include/pcpu.h:
Remove Xen HVM per-cpu variable data. These fields are now
allocated via the dynamic per-cpu scheme. See xen_intr.c
for details.
sys/amd64/include/xen/hypercall.h:
sys/dev/xen/blkback/blkback.c:
sys/i386/include/xen/xenvar.h:
sys/i386/xen/clock.c:
sys/i386/xen/xen_machdep.c:
sys/xen/gnttab.c:
Prefer FreeBSD primatives to Linux ones in Xen support code.
sys/amd64/include/xen/xen-os.h:
sys/i386/include/xen/xen-os.h:
sys/xen/xen-os.h:
sys/dev/xen/balloon/balloon.c:
sys/dev/xen/blkback/blkback.c:
sys/dev/xen/blkfront/blkfront.c:
sys/dev/xen/console/xencons_ring.c:
sys/dev/xen/control/control.c:
sys/dev/xen/netback/netback.c:
sys/dev/xen/netfront/netfront.c:
sys/dev/xen/xenpci/xenpci.c:
sys/i386/i386/machdep.c:
sys/i386/include/pmap.h:
sys/i386/include/xen/xenfunc.h:
sys/i386/isa/npx.c:
sys/i386/xen/clock.c:
sys/i386/xen/mp_machdep.c:
sys/i386/xen/mptable.c:
sys/i386/xen/xen_clock_util.c:
sys/i386/xen/xen_machdep.c:
sys/i386/xen/xen_rtc.c:
sys/xen/evtchn/evtchn_dev.c:
sys/xen/features.c:
sys/xen/gnttab.c:
sys/xen/gnttab.h:
sys/xen/hvm.h:
sys/xen/xenbus/xenbus.c:
sys/xen/xenbus/xenbus_if.m:
sys/xen/xenbus/xenbusb_front.c:
sys/xen/xenbus/xenbusvar.h:
sys/xen/xenstore/xenstore.c:
sys/xen/xenstore/xenstore_dev.c:
sys/xen/xenstore/xenstorevar.h:
Pull common Xen OS support functions/settings into xen/xen-os.h.
sys/amd64/include/xen/xen-os.h:
sys/i386/include/xen/xen-os.h:
sys/xen/xen-os.h:
Remove constants, macros, and functions unused in FreeBSD's Xen
support.
sys/xen/xen-os.h:
sys/i386/xen/xen_machdep.c:
sys/x86/xen/hvm.c:
Introduce new functions xen_domain(), xen_pv_domain(), and
xen_hvm_domain(). These are used in favor of #ifdefs so that
FreeBSD can dynamically detect and adapt to the presence of
a hypervisor. The goal is to have an HVM optimized GENERIC,
but more is necessary before this is possible.
sys/amd64/amd64/machdep.c:
sys/dev/xen/xenpci/xenpcivar.h:
sys/dev/xen/xenpci/xenpci.c:
sys/x86/xen/hvm.c:
sys/sys/kernel.h:
Refactor magic ioport, Hypercall table and Hypervisor shared
information page setup, and move it to a dedicated HVM support
module.
HVM mode initialization is now triggered during the
SI_SUB_HYPERVISOR phase of system startup. This currently
occurs just after the kernel VM is fully setup which is
just enough infrastructure to allow the hypercall table
and shared info page to be properly mapped.
sys/xen/hvm.h:
sys/x86/xen/hvm.c:
Add definitions and a method for configuring Hypervisor event
delievery via a direct vector callback.
sys/amd64/include/xen/xen-os.h:
sys/x86/xen/hvm.c:
sys/conf/files:
sys/conf/files.amd64:
sys/conf/files.i386:
Adjust kernel build to reflect the refactoring of early
Xen startup code and Xen interrupt services.
sys/dev/xen/blkback/blkback.c:
sys/dev/xen/blkfront/blkfront.c:
sys/dev/xen/blkfront/block.h:
sys/dev/xen/control/control.c:
sys/dev/xen/evtchn/evtchn_dev.c:
sys/dev/xen/netback/netback.c:
sys/dev/xen/netfront/netfront.c:
sys/xen/xenstore/xenstore.c:
sys/xen/evtchn/evtchn_dev.c:
sys/dev/xen/console/console.c:
sys/dev/xen/console/xencons_ring.c
Adjust drivers to use new xen_intr_*() API.
sys/dev/xen/blkback/blkback.c:
Since blkback defers all event handling to a taskqueue,
convert this task queue to a "fast" taskqueue, and schedule
it via an interrupt filter. This avoids an unnecessary
ithread context switch.
sys/xen/xenstore/xenstore.c:
The xenstore driver is MPSAFE. Indicate as much when
registering its interrupt handler.
sys/xen/xenbus/xenbus.c:
sys/xen/xenbus/xenbusvar.h:
Remove unused event channel APIs.
sys/xen/evtchn.h:
Remove all kernel Xen interrupt service API definitions
from this file. It is now only used for structure and
ioctl definitions related to the event channel userland
device driver.
Update the definitions in this file to match those from
NetBSD. Implementing this interface will be necessary for
Dom0 support.
sys/xen/evtchn/evtchnvar.h:
Add a header file for implemenation internal APIs related
to managing event channels event delivery. This is used
to allow, for example, the event channel userland device
driver to access low-level routines that typical kernel
consumers of event channel services should never access.
sys/xen/interface/event_channel.h:
sys/xen/xen_intr.h:
Standardize on the evtchn_port_t type for referring to
an event channel port id. In order to prevent low-level
event channel APIs from leaking to kernel consumers who
should not have access to this data, the type is defined
twice: Once in the Xen provided event_channel.h, and again
in xen/xen_intr.h. The double declaration is protected by
__XEN_EVTCHN_PORT_DEFINED__ to ensure it is never declared
twice within a given compilation unit.
sys/xen/xen_intr.h:
sys/xen/evtchn/evtchn.c:
sys/x86/xen/xen_intr.c:
sys/dev/xen/xenpci/evtchn.c:
sys/dev/xen/xenpci/xenpcivar.h:
New implementation of Xen interrupt services. This is
similar in many respects to the i386 PV implementation with
the exception that events for bound to event channel ports
(i.e. not IPI, virtual IRQ, or physical IRQ) are further
optimized to avoid mask/unmask operations that aren't
necessary for these edge triggered events.
Stubs exist for supporting physical IRQ binding, but will
need additional work before this implementation can be
fully shared between PV and HVM.
sys/amd64/amd64/mp_machdep.c:
sys/i386/i386/mp_machdep.c:
sys/i386/xen/mp_machdep.c
sys/x86/xen/hvm.c:
Add support for placing vcpu_info into an arbritary memory
page instead of using HYPERVISOR_shared_info->vcpu_info.
This allows the creation of domains with more than 32 vcpus.
sys/i386/i386/machdep.c:
sys/i386/xen/clock.c:
sys/i386/xen/xen_machdep.c:
sys/i386/xen/exception.s:
Add support for new event channle implementation.
2013-08-29 19:52:18 +00:00
|
|
|
error = xen_intr_bind_virq(dev, VIRQ_CONSOLE, 0, NULL,
|
|
|
|
xencons_priv_interrupt, NULL,
|
|
|
|
INTR_TYPE_TTY, &xen_intr_handle);
|
|
|
|
KASSERT(error >= 0, ("can't register console interrupt"));
|
2008-08-12 20:01:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* register handler to flush console on shutdown */
|
|
|
|
if ((EVENTHANDLER_REGISTER(shutdown_post_sync, xc_shutdown,
|
|
|
|
NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
|
|
|
|
printf("xencons: shutdown event registration failed!\n");
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* return 0 for all console input, force flush all output.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
xc_shutdown(void *arg, int howto)
|
|
|
|
{
|
|
|
|
xc_mute = 1;
|
|
|
|
xcons_force_flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xencons_rx(char *buf, unsigned len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct tty *tp = xccons;
|
2008-08-20 09:03:03 +00:00
|
|
|
|
2009-03-11 15:30:12 +00:00
|
|
|
if (xen_console_up
|
|
|
|
#ifdef DDB
|
|
|
|
&& !kdb_active
|
|
|
|
#endif
|
|
|
|
) {
|
2008-08-20 09:03:03 +00:00
|
|
|
tty_lock(tp);
|
2011-09-02 17:36:01 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
#ifdef KDB
|
|
|
|
kdb_alt_break(buf[i], &xc_altbrk);
|
|
|
|
#endif
|
2008-08-20 09:03:03 +00:00
|
|
|
ttydisc_rint(tp, buf[i], 0);
|
2011-09-02 17:36:01 +00:00
|
|
|
}
|
2008-08-20 09:03:03 +00:00
|
|
|
ttydisc_rint_done(tp);
|
|
|
|
tty_unlock(tp);
|
|
|
|
} else {
|
2009-05-11 23:03:15 +00:00
|
|
|
CN_LOCK(cn_mtx);
|
2008-08-20 09:03:03 +00:00
|
|
|
for (i = 0; i < len; i++)
|
2008-08-12 20:01:57 +00:00
|
|
|
rbuf[RBUF_MASK(rp++)] = buf[i];
|
2009-05-11 23:03:15 +00:00
|
|
|
CN_UNLOCK(cn_mtx);
|
2008-08-12 20:01:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
__xencons_tx_flush(void)
|
|
|
|
{
|
2008-08-20 09:03:03 +00:00
|
|
|
int sz;
|
2008-08-12 20:01:57 +00:00
|
|
|
|
|
|
|
CN_LOCK(cn_mtx);
|
|
|
|
while (wc != wp) {
|
|
|
|
int sent;
|
|
|
|
sz = wp - wc;
|
|
|
|
if (sz > (WBUF_SIZE - WBUF_MASK(wc)))
|
|
|
|
sz = WBUF_SIZE - WBUF_MASK(wc);
|
2014-03-11 10:09:23 +00:00
|
|
|
if (xen_initial_domain()) {
|
2008-08-12 20:01:57 +00:00
|
|
|
HYPERVISOR_console_io(CONSOLEIO_write, sz, &wbuf[WBUF_MASK(wc)]);
|
|
|
|
wc += sz;
|
|
|
|
} else {
|
|
|
|
sent = xencons_ring_send(&wbuf[WBUF_MASK(wc)], sz);
|
|
|
|
if (sent == 0)
|
|
|
|
break;
|
|
|
|
wc += sent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CN_UNLOCK(cn_mtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xencons_tx(void)
|
|
|
|
{
|
|
|
|
__xencons_tx_flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xencons_priv_interrupt(void *arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
static char rbuf[16];
|
|
|
|
int l;
|
|
|
|
|
|
|
|
while ((l = HYPERVISOR_console_io(CONSOLEIO_read, 16, rbuf)) > 0)
|
|
|
|
xencons_rx(rbuf, l);
|
|
|
|
|
|
|
|
xencons_tx();
|
|
|
|
}
|
|
|
|
|
2008-08-20 09:03:03 +00:00
|
|
|
static int
|
|
|
|
xcopen(struct tty *tp)
|
2008-08-12 20:01:57 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
xen_console_up = 1;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2008-08-20 09:03:03 +00:00
|
|
|
static void
|
|
|
|
xcclose(struct tty *tp)
|
2008-08-12 20:01:57 +00:00
|
|
|
{
|
|
|
|
|
2008-08-20 09:03:03 +00:00
|
|
|
xen_console_up = 0;
|
2008-08-12 20:01:57 +00:00
|
|
|
}
|
|
|
|
|
2014-02-15 12:37:26 +00:00
|
|
|
#if 0
|
2008-08-12 20:01:57 +00:00
|
|
|
static inline int
|
|
|
|
__xencons_put_char(int ch)
|
|
|
|
{
|
|
|
|
char _ch = (char)ch;
|
|
|
|
if ((wp - wc) == WBUF_SIZE)
|
|
|
|
return 0;
|
|
|
|
wbuf[WBUF_MASK(wp++)] = _ch;
|
|
|
|
return 1;
|
|
|
|
}
|
2014-02-15 12:37:26 +00:00
|
|
|
#endif
|
2008-08-12 20:01:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
2008-08-20 09:03:03 +00:00
|
|
|
xcoutwakeup(struct tty *tp)
|
2008-08-12 20:01:57 +00:00
|
|
|
{
|
|
|
|
boolean_t cons_full = FALSE;
|
2008-08-20 09:03:03 +00:00
|
|
|
char c;
|
2008-08-12 20:01:57 +00:00
|
|
|
|
2008-08-20 09:03:03 +00:00
|
|
|
while (ttydisc_getc(tp, &c, 1) == 1 && !cons_full)
|
|
|
|
cons_full = xcons_putc(c);
|
2008-08-12 20:01:57 +00:00
|
|
|
|
2008-08-20 09:03:03 +00:00
|
|
|
if (cons_full) {
|
2008-08-12 20:01:57 +00:00
|
|
|
/* let the timeout kick us in a bit */
|
|
|
|
xc_start_needed = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xc_timeout(void *v)
|
|
|
|
{
|
|
|
|
struct tty *tp;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
tp = (struct tty *)v;
|
|
|
|
|
2008-08-20 09:03:03 +00:00
|
|
|
tty_lock(tp);
|
2009-08-24 08:27:42 +00:00
|
|
|
while ((c = xc_cngetc(NULL)) != -1)
|
2008-08-20 09:03:03 +00:00
|
|
|
ttydisc_rint(tp, c, 0);
|
2008-08-12 20:01:57 +00:00
|
|
|
|
|
|
|
if (xc_start_needed) {
|
|
|
|
xc_start_needed = FALSE;
|
2008-08-20 09:03:03 +00:00
|
|
|
xcoutwakeup(tp);
|
2008-08-12 20:01:57 +00:00
|
|
|
}
|
2008-08-20 09:47:49 +00:00
|
|
|
tty_unlock(tp);
|
2008-08-12 20:01:57 +00:00
|
|
|
|
|
|
|
callout_reset(&xc_callout, XC_POLLTIME, xc_timeout, tp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static device_method_t xc_methods[] = {
|
|
|
|
DEVMETHOD(device_identify, xc_identify),
|
|
|
|
DEVMETHOD(device_probe, xc_probe),
|
|
|
|
DEVMETHOD(device_attach, xc_attach),
|
2013-01-30 18:01:20 +00:00
|
|
|
|
|
|
|
DEVMETHOD_END
|
2008-08-12 20:01:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t xc_driver = {
|
|
|
|
driver_name,
|
|
|
|
xc_methods,
|
2008-08-20 09:03:03 +00:00
|
|
|
0,
|
2008-08-12 20:01:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*** Forcibly flush console data before dying. ***/
|
|
|
|
void
|
|
|
|
xcons_force_flush(void)
|
|
|
|
{
|
|
|
|
int sz;
|
|
|
|
|
2014-03-11 10:09:23 +00:00
|
|
|
if (xen_initial_domain())
|
2008-08-12 20:01:57 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Spin until console data is flushed through to the domain controller. */
|
|
|
|
while (wc != wp) {
|
|
|
|
int sent = 0;
|
|
|
|
if ((sz = wp - wc) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sent = xencons_ring_send(&wbuf[WBUF_MASK(wc)], sz);
|
|
|
|
if (sent > 0)
|
|
|
|
wc += sent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-16 08:44:33 +00:00
|
|
|
DRIVER_MODULE(xc, xenpv, xc_driver, xc_devclass, 0, 0);
|