Home | History | Annotate | only in /src/sys/arch/xen/include
History log of /src/sys/arch/xen/include
RevisionDateAuthorComments
 1.7 31-Aug-2020  bouyer Add back <xen/xenio3.h>, it's needed by xentools413
 1.6 24-Jul-2020  jdolecek <xen/xenio.h> is in fact used by the newly imported xentools 4.13,
reinstantiate it

header is for use by xentools only, which define domid_t themselves,
so it should not be a problem the header doesn't define it per PR port-xen/52874
 1.5 17-Jul-2020  jdolecek don't install xen/xenio.h and xen/xenio3.h anymore, xentools don't use it

PR port-xen/52874
 1.4 25-Apr-2020  bouyer Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.3 17-Feb-2008  bouyer branches: 1.3.108;
Install xenio.h and xenio3.h in /usr/include/xen, for the benefit
of xentools3.

XXX ignore those in Makefile.ioctl-c, they don't compile properly outside
of the Xen context and the ioctls from xenio.h conflicts with
soundcard.h
 1.2 11-Dec-2005  christos branches: 1.2.24; 1.2.40; 1.2.50; 1.2.56;
merge ktrace-lwp.
 1.1 12-May-2004  cl branches: 1.1.2; 1.1.4; 1.1.18;
``build.sh -m xen-i386 release'' now builds a release for NetBSD/xen
for i386. The resulting release consists of:
- NetBSD/xen for i386 kernel, loader and docuemntation
- NetBSD/i386 userland sets
 1.1.18.1 27-Feb-2008  yamt sync with head.
 1.1.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.4.2 03-Aug-2004  skrll Sync with HEAD
 1.1.4.1 12-May-2004  skrll file Makefile was added on branch ktrace-lwp on 2004-08-03 10:43:10 +0000
 1.1.2.2 22-May-2004  he Pull up revision 1.1 (requested by cl in ticket #337):
Upgrade xen support:
- add block device driver
- network device driver bug fixes
- support for vga/keyboard/mouse
- support for domain0 operations
- fix /dev/mem and i386_iopl, reboot, event dispatch
- fix clock support, cpu speed report, lazy fpu switching
- add xen12load loader
- sys/arch/xen parts of build.sh release support
[cl, ticket #337]
 1.1.2.1 12-May-2004  he file Makefile was added on branch netbsd-2-0 on 2004-05-22 15:59:21 +0000
 1.2.56.1 18-Feb-2008  mjf Sync with HEAD.
 1.2.50.1 23-Mar-2008  matt sync with HEAD
 1.2.40.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.2.24.1 23-Mar-2008  jdc Pull up revisions (requested by bouyer in ticket #1087):
src/distrib/sets/lists/comp/md.i386 1.104
src/sys/arch/i386/Makefile 1.33
src/sys/arch/xen/include/Makefile 1.3
src/usr.bin/kdump/Makefile.ioctl-c 1.20

Install xenio.h and xenio3.h in /usr/include/xen, for the benefit
of xentools3.

XXX ignore those in Makefile.ioctl-c, they don't compile properly outside
of the Xen context and the ioctls from xenio.h conflicts with
soundcard.h
 1.3.108.1 25-Apr-2020  bouyer Also install xen/intrdefs.h
 1.2 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.1 09-Apr-2006  bouyer branches: 1.1.2; 1.1.4; 1.1.6; 1.1.10; 1.1.14; 1.1.20; 1.1.50; 1.1.56; 1.1.64;
Add support for ACPI in xen-3 dom0 support. We can now boot a xen-3 dom0
kernel with a default xen comamnd line.
 1.1.64.1 10-Jan-2008  bouyer Change xeni386 build to match xenamd64:
- machine/ points to xen/include/i386
- remove includes that were identical to the i386/include/ ones; the build
will find them though the xen-ma/machine link.
- include xen files using xen/ not machine/
 1.1.56.1 18-Feb-2008  mjf Sync with HEAD.
 1.1.50.1 23-Mar-2008  matt sync with HEAD
 1.1.20.2 09-Sep-2006  rpaulo sync with head
 1.1.20.1 09-Apr-2006  rpaulo file acpi_func.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:44:56 +0000
 1.1.14.3 21-Jan-2008  yamt sync with head
 1.1.14.2 21-Jun-2006  yamt sync with head.
 1.1.14.1 09-Apr-2006  yamt file acpi_func.h was added on branch yamt-lazymbuf on 2006-06-21 14:58:15 +0000
 1.1.10.2 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.1.10.1 09-Apr-2006  tron file acpi_func.h was added on branch peter-altq on 2006-05-24 15:48:25 +0000
 1.1.6.2 22-Apr-2006  simonb Sync with head.
 1.1.6.1 09-Apr-2006  simonb file acpi_func.h was added on branch simonb-timecounters on 2006-04-22 11:38:11 +0000
 1.1.4.2 19-Apr-2006  elad sync with head - hopefully this will work
 1.1.4.1 09-Apr-2006  elad file acpi_func.h was added on branch elad-kernelauth on 2006-04-19 02:34:03 +0000
 1.1.2.2 11-Apr-2006  yamt sync with head
 1.1.2.1 09-Apr-2006  yamt file acpi_func.h was added on branch yamt-pdpolicy on 2006-04-11 11:53:48 +0000
 1.2 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.1 09-Apr-2006  bouyer branches: 1.1.2; 1.1.4; 1.1.6; 1.1.10; 1.1.14; 1.1.20; 1.1.50; 1.1.56; 1.1.64;
Add support for ACPI in xen-3 dom0 support. We can now boot a xen-3 dom0
kernel with a default xen comamnd line.
 1.1.64.1 10-Jan-2008  bouyer Change xeni386 build to match xenamd64:
- machine/ points to xen/include/i386
- remove includes that were identical to the i386/include/ ones; the build
will find them though the xen-ma/machine link.
- include xen files using xen/ not machine/
 1.1.56.1 18-Feb-2008  mjf Sync with HEAD.
 1.1.50.1 23-Mar-2008  matt sync with HEAD
 1.1.20.2 09-Sep-2006  rpaulo sync with head
 1.1.20.1 09-Apr-2006  rpaulo file acpi_machdep.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:44:56 +0000
 1.1.14.3 21-Jan-2008  yamt sync with head
 1.1.14.2 21-Jun-2006  yamt sync with head.
 1.1.14.1 09-Apr-2006  yamt file acpi_machdep.h was added on branch yamt-lazymbuf on 2006-06-21 14:58:15 +0000
 1.1.10.2 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.1.10.1 09-Apr-2006  tron file acpi_machdep.h was added on branch peter-altq on 2006-05-24 15:48:25 +0000
 1.1.6.2 22-Apr-2006  simonb Sync with head.
 1.1.6.1 09-Apr-2006  simonb file acpi_machdep.h was added on branch simonb-timecounters on 2006-04-22 11:38:11 +0000
 1.1.4.2 19-Apr-2006  elad sync with head - hopefully this will work
 1.1.4.1 09-Apr-2006  elad file acpi_machdep.h was added on branch elad-kernelauth on 2006-04-19 02:34:03 +0000
 1.1.2.2 11-Apr-2006  yamt sync with head
 1.1.2.1 09-Apr-2006  yamt file acpi_machdep.h was added on branch yamt-pdpolicy on 2006-04-11 11:53:48 +0000
 1.1 06-Jul-2010  cherry branches: 1.1.2; 1.1.4; 1.1.6; 1.1.12;
The Xen balloon driver enables growing and shrinking
PV domains on the fly, by collaborating with UVM and the hypervisor
 1.1.12.2 05-Mar-2011  rmind sync with head
 1.1.12.1 06-Jul-2010  rmind file balloon.h was added on branch rmind-uvmplock on 2011-03-05 20:52:33 +0000
 1.1.6.2 24-Oct-2010  jym Sync with HEAD
 1.1.6.1 06-Jul-2010  jym file balloon.h was added on branch jym-xensuspend on 2010-10-24 22:48:21 +0000
 1.1.4.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.1.4.1 06-Jul-2010  uebayasi file balloon.h was added on branch uebayasi-xip on 2010-08-17 06:45:35 +0000
 1.1.2.2 11-Aug-2010  yamt sync with head.
 1.1.2.1 06-Jul-2010  yamt file balloon.h was added on branch yamt-nfs-mp on 2010-08-11 22:52:59 +0000
 1.4 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.3 11-Dec-2005  christos branches: 1.3.50; 1.3.56; 1.3.64;
merge ktrace-lwp.
 1.2 09-Mar-2005  bouyer branches: 1.2.4; 1.2.6; 1.2.8;
Merge the bouyer-xen2 branch. This add supports for the Xen 2.0 virtual
machine kernel (both privileged and non-privileged domains), and remove support
for the old xen 1.2.
 1.1 18-Jan-2005  bouyer branches: 1.1.2; 1.1.4;
file bus.h was initially added on branch bouyer-xen2.
 1.1.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.2.1 18-Jan-2005  bouyer Add a suitable <machine/bus.h>. Just #include <x86/bus.h> for now.
 1.2.8.1 21-Jan-2008  yamt sync with head
 1.2.6.2 29-Apr-2005  kent sync with -current
 1.2.6.1 09-Mar-2005  kent file bus.h was added on branch kent-audio2 on 2005-04-29 11:28:29 +0000
 1.2.4.2 01-Apr-2005  skrll Sync with HEAD.
 1.2.4.1 09-Mar-2005  skrll file bus.h was added on branch ktrace-lwp on 2005-04-01 14:29:10 +0000
 1.3.64.1 10-Jan-2008  bouyer Change xeni386 build to match xenamd64:
- machine/ points to xen/include/i386
- remove includes that were identical to the i386/include/ ones; the build
will find them though the xen-ma/machine link.
- include xen files using xen/ not machine/
 1.3.56.1 18-Feb-2008  mjf Sync with HEAD.
 1.3.50.1 23-Mar-2008  matt sync with HEAD
 1.10 14-Feb-2019  cherry Snag the final bits of PV only code to conditionally compile under
-DXENPV

This completes the bifurcation.

The next step is to add -DXENPVHVM code.
 1.9 23-Jan-2008  bouyer branches: 1.9.98;
Merge the bouyer-xeni386 branch. This brings in PAE support to NetBSD xeni386
(domU only). PAE support is enabled by 'options PAE', see the new XEN3PAE_DOMU
and INSTALL_XEN3PAE_DOMU kernel config files.

See the comments in arch/i386/include/{pte.h,pmap.h} to see how it works.
In short, we still handle it as a 2-level MMU, with the second level page
directory being 4 pages in size. pmap switching is done by switching the
L2 pages in the L3 entries, instead of loading %cr3. This is almost required
by Xen, which handle the last L2 page (the one mapping 0xc0000000 - 0xffffffff)
in a very special way. But this approach should also work for native PAE
support if ever supported (in fact, the pmap should almost suport native
PAE, what's missing is bootstrap code in locore.S).
 1.8 22-Nov-2007  bouyer branches: 1.8.6;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.7 28-Aug-2006  bouyer branches: 1.7.12; 1.7.30; 1.7.32; 1.7.36; 1.7.38;
Some bus_dma(9) fixes for Xen:
- Attempt to gracefully recover from a failed decrease_reservation or
increase_reservation, by avoiding physical memory loss.
- always store a machine address in ds_addr; this avoids some mistakes
where machine address would in some case be freed at physical address, or
mapped as physical address.
 1.6 16-Feb-2006  perry branches: 1.6.2; 1.6.12;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.5 24-Dec-2005  perry branches: 1.5.2; 1.5.4; 1.5.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.4 11-Dec-2005  christos merge ktrace-lwp.
 1.3 22-Aug-2005  bouyer branches: 1.3.6;
Rename _PRIVATE_BUS_DMAMEM_ALLOC_RANGE to _BUS_DMAMEM_ALLOC_RANGE for
consistency with other macros defined in bus_private.h. Pointed out by
YAMAMOTO Takashi.
 1.2 20-Aug-2005  bouyer Deal with the machine address space being non-contigous in bus_dmamem_alloc():
- Define _BUS_AVAIL_END to 0xffffffff, as we don't have an easy way to
find the upper bound for our machine address space (and this can change
when we swap pages with the hypervisor).
- implement _xen_bus_dmamem_alloc_range(), which will request a contigous
set of pages to the hypervisor if the pages returned by uvm_pglistalloc()
don't fit the constraints.
We can't deal with the low/high constraints yet, because Xen doesn't offer a
way to get pages in a specific ranges of addresses.

Based on patches from Dave Thompson (in private mail), with heavy hacking
by me.
 1.1 16-Apr-2005  yamt branches: 1.1.2; 1.1.4; 1.1.6;
add files which i forgot to add with arch/x86/x86/bus_dma.c rev.1.21.
 1.1.6.4 04-Feb-2008  yamt sync with head.
 1.1.6.3 07-Dec-2007  yamt sync with head
 1.1.6.2 30-Dec-2006  yamt sync with head.
 1.1.6.1 21-Jun-2006  yamt sync with head.
 1.1.4.2 29-Apr-2005  kent sync with -current
 1.1.4.1 16-Apr-2005  kent file bus_private.h was added on branch kent-audio2 on 2005-04-29 11:28:29 +0000
 1.1.2.5 16-Sep-2006  ghen Pull up following revision(s) (requested by bouyer in ticket #1510):
sys/arch/xen/x86/xen_bus_dma.c: revision 1.7
sys/arch/xen/x86/xen_bus_dma.c: revision 1.8
sys/arch/x86/include/bus_private.h: revision 1.6
sys/arch/x86/x86/bus_dma.c: revision 1.30
sys/arch/xen/include/bus_private.h: revision 1.7
Some bus_dma(9) fixes for Xen:
- Attempt to gracefully recover from a failed decrease_reservation or
increase_reservation, by avoiding physical memory loss.
- always store a machine address in ds_addr; this avoids some mistakes
where machine address would in some case be freed at physical address, or
mapped as physical address.
Wrap some printfs in #ifdef DEBUG, as we should not leak memory any more when
bus_dma memory allocation fails.
 1.1.2.4 25-Aug-2005  tron Pull up following revision(s) (requested by bouyer in ticket #697):
sys/arch/x86/x86/bus_dma.c: revision 1.23
sys/arch/x86/include/bus_private.h: revision 1.3
sys/arch/xen/include/bus_private.h: revision 1.3
Rename _PRIVATE_BUS_DMAMEM_ALLOC_RANGE to _BUS_DMAMEM_ALLOC_RANGE for
consistency with other macros defined in bus_private.h. Pointed out by
YAMAMOTO Takashi.
 1.1.2.3 25-Aug-2005  tron Pull up following revision(s) (requested by bouyer in ticket #696):
sys/arch/xen/x86/xen_bus_dma.c: revision 1.1
sys/arch/xen/include/bus_private.h: revision 1.2
sys/arch/xen/conf/files.xen: revision 1.28
Deal with the machine address space being non-contigous in bus_dmamem_alloc():
- Define _BUS_AVAIL_END to 0xffffffff, as we don't have an easy way to
find the upper bound for our machine address space (and this can change
when we swap pages with the hypervisor).
- implement _xen_bus_dmamem_alloc_range(), which will request a contigous
set of pages to the hypervisor if the pages returned by uvm_pglistalloc()
don't fit the constraints.
We can't deal with the low/high constraints yet, because Xen doesn't offer a
way to get pages in a specific ranges of addresses.
Based on patches from Dave Thompson (in private mail), with heavy hacking
by me.
 1.1.2.2 21-Apr-2005  tron Pull up revision 1.1 (requested by yamt in ticket #175):
add files which i forgot to add with arch/x86/x86/bus_dma.c rev.1.21.
 1.1.2.1 16-Apr-2005  tron file bus_private.h was added on branch netbsd-3 on 2005-04-21 18:43:01 +0000
 1.3.6.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.3.6.1 22-Aug-2005  skrll file bus_private.h was added on branch ktrace-lwp on 2005-11-10 14:00:34 +0000
 1.5.6.1 22-Apr-2006  simonb Sync with head.
 1.5.4.1 09-Sep-2006  rpaulo sync with head
 1.5.2.1 18-Feb-2006  yamt sync with head.
 1.6.12.1 14-Sep-2006  riz Pull up following revision(s) (requested by bouyer in ticket #150):
sys/arch/xen/x86/xen_bus_dma.c: revision 1.7
sys/arch/xen/x86/xen_bus_dma.c: revision 1.8
sys/arch/x86/include/bus_private.h: revision 1.6
sys/arch/x86/x86/bus_dma.c: revision 1.30
sys/arch/xen/include/bus_private.h: revision 1.7
Some bus_dma(9) fixes for Xen:
- Attempt to gracefully recover from a failed decrease_reservation or
increase_reservation, by avoiding physical memory loss.
- always store a machine address in ds_addr; this avoids some mistakes
where machine address would in some case be freed at physical address, or
mapped as physical address.
Wrap some printfs in #ifdef DEBUG, as we should not leak memory any more when
bus_dma memory allocation fails.
 1.6.2.1 03-Sep-2006  yamt sync with head.
 1.7.38.2 18-Feb-2008  mjf Sync with HEAD.
 1.7.38.1 08-Dec-2007  mjf Sync with HEAD.
 1.7.36.1 21-Nov-2007  bouyer Use an appropriate _BUS_AVAIL_END for _LP64
 1.7.32.2 23-Mar-2008  matt sync with HEAD
 1.7.32.1 09-Jan-2008  matt sync with HEAD
 1.7.30.1 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.7.12.1 03-Dec-2007  ad Sync with HEAD.
 1.8.6.1 13-Jan-2008  bouyer Work in progress on xeni386 PAE support:
Make xeni386 build with a 64bit paddr_t. For this vaddr_t vs paddr_t vs
pointers usages had to be clarified.
If 'options PAE' is present in a Xen3 kernel, switch paddr_t, pd_entry_t
and pt_entry_t to 64bits, and add the PAE entry in the __xen_guest ELF section.
 1.9.98.1 10-Jun-2019  christos Sync with HEAD
 1.29 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.28 05-Jan-2008  yamt g/c ci_idle_pcb_paddr
 1.27 04-Jan-2008  yamt i386:
- make tss per-cpu. this considerably speeds up context switch for,
at least, pentium4, where ltr instruction seems very slow.
i386, xen:
- kill cpu_maxproc.
kvm86:
- adapt to per-cpu tss.
- cleanup and simplify.
- move kvm86_mp_lock to more meaningful place.
- disable preemption during a call.
 1.26 01-Jan-2008  yamt try to detect processor resource sharing topologies. ie. package/core/smt IDs.
 1.25 25-Dec-2007  perry Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.24 22-Nov-2007  bouyer branches: 1.24.2; 1.24.6;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.23 26-Oct-2007  joerg branches: 1.23.2;
Match delay/DELAY on x86 with delay(9). It takes an unsigned int as
argument. Use this and replace the inline assembly (mul + div using the
64bit intermediate result) with normal 32bit multiplication and
division. The compiler can turn the division into a multiplication and
shift, making it even cheaper then the original assembly. For extreme
long delays, just use 64bit arithmetic.
 1.22 17-Oct-2007  garbled Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.21 25-Sep-2007  ad branches: 1.21.2;
ci_astpending is no more.
 1.20 17-May-2007  yamt branches: 1.20.8; 1.20.10; 1.20.12;
merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.
 1.19 12-May-2007  jld Convert the xen port to use timecounters; ok'ed by bouyer@.
 1.18 12-Mar-2007  ad branches: 1.18.2; 1.18.8;
Include sys/simplelock.h, not sys/lock.h.
 1.17 05-Mar-2007  drochner branches: 1.17.2;
clean up how cpus and ioapics are attached at the mainbus:
Seperate "cpubus" and "ioapicbus" -- while they share a common "address
space" (the apic id), the kernel doesn't use this fact. There are different
data passed to cpus and apics, which caused some ugly polymorphism. This
also saves the special "submatch" functions needed to distingush cpus
and ioapics for autoconf. (And it makes that "apid" locators wired
in the kernel configuration are honored now; this allows one to dumb down
an mp box to singleprocessor by userconfig.)
Print "apid" locators in the buses "print" function "as everyone does",
so the per-port cpu drivers don't need to do it.
Being here, constify "struct cpu_functions" and g/c the unused MP_PICMODE
flag.
 1.16 04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.15 16-Feb-2007  ad branches: 1.15.2;
Remove spllowersoftclock() and CLKF_BASEPRI(), and always dispatch callouts
via a soft interrupt. In the near future, softclock will be run from process
context.
 1.14 09-Feb-2007  ad Merge newlock2 to head.
 1.13 08-Dec-2006  yamt - pass intrframe by-pointer, not by-value.
- make i386 and xen use per-cpu interrupt stack.

xen part is reviewed by Manuel Bouyer.
 1.12 16-Feb-2006  perry branches: 1.12.14; 1.12.16; 1.12.18; 1.12.20;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.11 24-Dec-2005  perry branches: 1.11.2; 1.11.4; 1.11.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.10 11-Dec-2005  christos merge ktrace-lwp.
 1.9 11-Aug-2005  cube Change all archs that did:

#define clockframe somethingelse

to:

struct clockframe {
struct somethingelse cf_se;
};

and change access macros accordingly.

That means that, at least for that very issue, things will not go
ka-boomy if you don't have the actual definition of struct clockframe
before including systm.h.
 1.8 16-Apr-2005  bouyer branches: 1.8.2;
Get rid of the event to pseudo-irq mapping. We are limited to 32 pseudo-irq,
including soft interrupt, and this is way too low in some use (lots of domains,
or domains with lots of xennet, or even hardware with lots of devices at
different interrupts).
Based on idea from YAMAMOTO Takashi, keep one list of handler per-event and
one per-IPL (so the same handler is now in 2 lists). In the common case were
an event is received at low IPL, we can call the handlers quickly (there
is usually only one handler per event, unless the event is mapped to a
physical interrupt and this interrupt is shared by different devices).
Deffered events and software interrupts are handled by a bitmask (as before)
with one bit per IPL. When one IPL has an event pending all handlers for
this IPL will be called.
With this change, it is now possible to have all the 1024 events active.

While here, handle debug event in a special way: the handler is always called,
regardless of the current IPL. Make the handler print usefull informations
about events and IPL states.
Also remove code not used on Xen in files inherited from the x86 port.
 1.7 22-Sep-2004  yamt branches: 1.7.6; 1.7.12;
move some per-cpu data definitions to MI place so that they can be modified
without touching all ports. discussed on tech-kern@.
 1.6 07-May-2004  cl branches: 1.6.2;
fix lazy fpu state saving
 1.5 26-Apr-2004  cl Move struct xen_netinfo into include/xen.h so that xen12load compiles again.
 1.4 26-Apr-2004  cl Rework the physical<->machine memory mapping: offset physical addresses
by 0x100000 (above the I/O Memory "hole") leaving all physical addresses
below unused, don't perform phys<->mach mapping for addresses below 0x100000
or beyond the real hardware's physical memory.

-> /dev/mem works now as expected and X works in domain0.
 1.3 25-Apr-2004  cl Move some of the context switching code into a C function.
 1.2 24-Apr-2004  cl Make kernel command line parsing support additional keywords without
having to change existing code which calls the parser.
 1.1 11-Mar-2004  cl branches: 1.1.2;
Add port to the Xen virtual machine monitor.
(see http://www.cl.cam.ac.uk/Research/SRG/netos/xen/)
 1.1.2.1 22-May-2004  he Pull up revisions 1.2-1.6 (requested by cl in ticket #337):
Upgrade xen support:
- add block device driver
- network device driver bug fixes
- support for vga/keyboard/mouse
- support for domain0 operations
- fix /dev/mem and i386_iopl, reboot, event dispatch
- fix clock support, cpu speed report, lazy fpu switching
- add xen12load loader
- sys/arch/xen parts of build.sh release support
[cl, ticket #337]
 1.6.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.6.2.5 24-Sep-2004  skrll Sync with HEAD.
 1.6.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.6.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.6.2.2 03-Aug-2004  skrll Sync with HEAD
 1.6.2.1 07-May-2004  skrll file cpu.h was added on branch ktrace-lwp on 2004-08-03 10:43:10 +0000
 1.7.12.1 28-Apr-2005  tron Pull up revision 1.8 (requested by bouyer in ticket #192):
Get rid of the event to pseudo-irq mapping. We are limited to 32 pseudo-irq,
including soft interrupt, and this is way too low in some use (lots of domains,
or domains with lots of xennet, or even hardware with lots of devices at
different interrupts).
Based on idea from YAMAMOTO Takashi, keep one list of handler per-event and
one per-IPL (so the same handler is now in 2 lists). In the common case were
an event is received at low IPL, we can call the handlers quickly (there
is usually only one handler per event, unless the event is mapped to a
physical interrupt and this interrupt is shared by different devices).
Deffered events and software interrupts are handled by a bitmask (as before)
with one bit per IPL. When one IPL has an event pending all handlers for
this IPL will be called.
With this change, it is now possible to have all the 1024 events active.
While here, handle debug event in a special way: the handler is always called,
regardless of the current IPL. Make the handler print usefull informations
about events and IPL states.
Also remove code not used on Xen in files inherited from the x86 port.
 1.7.6.1 29-Apr-2005  kent sync with -current
 1.8.2.7 21-Jan-2008  yamt sync with head
 1.8.2.6 07-Dec-2007  yamt sync with head
 1.8.2.5 27-Oct-2007  yamt sync with head.
 1.8.2.4 03-Sep-2007  yamt sync with head.
 1.8.2.3 26-Feb-2007  yamt sync with head.
 1.8.2.2 30-Dec-2006  yamt sync with head.
 1.8.2.1 21-Jun-2006  yamt sync with head.
 1.11.6.1 22-Apr-2006  simonb Sync with head.
 1.11.4.1 09-Sep-2006  rpaulo sync with head
 1.11.2.1 18-Feb-2006  yamt sync with head.
 1.12.20.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.12.18.1 10-Jun-2007  bouyer Pull up following revision(s) (requested by jld in ticket #711):
sys/arch/xen/xen/clock.c: revision 1.35 via patch
sys/arch/xen/include/types.h: revision 1.5 via patch
sys/arch/xen/i386/machdep.c: revision 1.38 via patch
sys/arch/xen/conf/files.xen: revision 1.60 via patch
sys/arch/xen/include/cpu.h: revision 1.19 via patch
Convert the xen port to use timecounters; ok'ed by bouyer@.
 1.12.16.1 10-Dec-2006  yamt sync with head.
 1.12.14.4 28-Jan-2007  ad xen MD changes.
 1.12.14.3 12-Jan-2007  ad Sync with head.
 1.12.14.2 11-Jan-2007  ad Checkpoint work in progress.
 1.12.14.1 29-Dec-2006  ad Checkpoint work in progress.
 1.15.2.4 17-May-2007  yamt sync with head.
 1.15.2.3 26-Mar-2007  yamt adapt xen.
 1.15.2.2 17-Mar-2007  rmind Backport lock.h split into the simplelock.h and other #include changes
from HEAD. This fixes the problems with circular includes.
 1.15.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.17.2.4 03-Dec-2007  ad Sync with HEAD.
 1.17.2.3 09-Oct-2007  ad Sync with head.
 1.17.2.2 27-May-2007  ad Sync with head.
 1.17.2.1 13-Mar-2007  ad Sync with head.
 1.18.8.2 03-Oct-2007  garbled Sync with HEAD
 1.18.8.1 22-May-2007  matt Update to HEAD.
 1.18.2.1 11-Jul-2007  mjf Sync with head.
 1.20.12.1 06-Oct-2007  yamt sync with head.
 1.20.10.3 23-Mar-2008  matt sync with HEAD
 1.20.10.2 09-Jan-2008  matt sync with HEAD
 1.20.10.1 06-Nov-2007  matt sync with HEAD
 1.20.8.3 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.20.8.2 28-Oct-2007  joerg Sync with HEAD.
 1.20.8.1 02-Oct-2007  joerg Sync with HEAD.
 1.21.2.4 16-Nov-2007  bouyer Initial domain0 support for xenamd64. The kernel boots multiuser, but
xen tools have not been tried yet.
In this process, cleanup some more the page table bootstrap, and properly
handle event counters for soft interrupts.
 1.21.2.3 13-Nov-2007  bouyer Sync with HEAD
 1.21.2.2 26-Oct-2007  bouyer Make amd64, i386 and xen kernels build and work again.
 1.21.2.1 17-Oct-2007  bouyer Prepare for xenamd64:
- kill xen/i386/identcpu.c, use i386/i386/identcpu.c instead (with a few
#ifndef XEN)
- move some files that can be shared between i386 and amd64 from
xen/i386 to xen/x86 (or to xen/xen for non-cpu-specific code)
- split assembly out of xen/include/hypervisor.h to xen/include/hypercalls.h
- use <xen/...> instead of <machine/...> for cpu-independant include files.

more work needed here, i386-specific files should got out of arch/xen to
arch/xeni386, and more code shared with arch/i386.
 1.23.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.23.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.24.6.4 06-Jan-2008  bouyer Merge needed changes to genassym.cf and locore.S for xeni386 back to
arch/i386. Switch xeni386 to use the arch/i386 cpu.h.
 1.24.6.3 05-Jan-2008  bouyer Not used anymore since xen/i386 has been switched to xen_pmap_bootstrap()
 1.24.6.2 02-Jan-2008  bouyer Sync with HEAD
 1.24.6.1 11-Dec-2007  bouyer Switch i386 to x86/x86/pmap.c
 1.24.2.1 26-Dec-2007  ad Sync with head.
 1.20 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.19 22-Nov-2007  bouyer branches: 1.19.6;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.18 17-Oct-2007  garbled branches: 1.18.2;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.17 26-Sep-2007  ad branches: 1.17.2;
x86 changes for pcc and LKMs.

- Replace most inline assembly with proper functions. As a side effect
this reduces the size of amd64 GENERIC by about 120kB, and i386 by a
smaller amount. Nearly all of the inlines did something slow, or something
that does not need to be fast.
- Make curcpu() and curlwp functions proper, unless __GNUC__ && _KERNEL.
In that case make them inlines. Makes curlwp LKM and preemption safe.
- Make bus_space and bus_dma more LKM friendly.
- Share a few more files between the ports.
- Other minor changes.
 1.16 23-Sep-2007  bouyer branches: 1.16.2;
Ajust for Xen 3.1.0 public headers. From Christoph Egger in private mail.
 1.15 04-Mar-2007  christos branches: 1.15.2; 1.15.10; 1.15.18; 1.15.20;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.14 14-Jan-2007  ad branches: 1.14.2;
Update x86_pause() as per i386.
 1.13 15-Oct-2006  bouyer Define x86_mfence(). Use it where appropriate. Seems to fix a hang in
the network interface front-end/back-end for me ...
 1.12 19-Aug-2006  dsl branches: 1.12.2; 1.12.4;
Fix build of machdep.c with -Os and -O3
 1.11 06-Mar-2006  bouyer branches: 1.11.10;
Add x86_sfence() for symetry, which is just a __insn_barrier() here.
 1.10 28-Dec-2005  perry branches: 1.10.4; 1.10.6; 1.10.8;
inline -> __inline
 1.9 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.8 11-Dec-2005  christos merge ktrace-lwp.
 1.7 22-Apr-2005  yamt branches: 1.7.2;
don't use block scope static function decl. found by gcc4.
 1.6 26-Mar-2005  bouyer Don't assume we're on a uniprocessor system (the hypervisor may be running SMP)
and add "lock;" barrier to avoid instruction reordering in event handlings.
This fix the last issue with event loss I was getting on SMP systems.
 1.5 09-Mar-2005  bouyer branches: 1.5.2;
Merge the bouyer-xen2 branch. This add supports for the Xen 2.0 virtual
machine kernel (both privileged and non-privileged domains), and remove support
for the old xen 1.2.
 1.4 10-Dec-2004  christos branches: 1.4.2; 1.4.4; 1.4.6;
Move the disable_intr and enable_intr functions from xenfunc.h to cpufunc.h,
because the x86/intr.h needs them and does not include xenfunc.h. Including
xenfunc.h in cpufunc.h is a clear lose because xenfunc.h needs a boatload
of include functions in order to compile.
 1.3 07-May-2004  cl branches: 1.3.2;
replace rdr6/ldr6 with the corresponding hypervisor traps
 1.2 10-Apr-2004  cl Make rcr2() always return 0. We only get cr2's value for page faults and
trap() knows where to find it.
 1.1 11-Mar-2004  cl branches: 1.1.2;
Add port to the Xen virtual machine monitor.
(see http://www.cl.cam.ac.uk/Research/SRG/netos/xen/)
 1.1.2.1 22-May-2004  he Pull up revisions 1.2-1.3 (requested by cl in ticket #337):
Upgrade xen support:
- add block device driver
- network device driver bug fixes
- support for vga/keyboard/mouse
- support for domain0 operations
- fix /dev/mem and i386_iopl, reboot, event dispatch
- fix clock support, cpu speed report, lazy fpu switching
- add xen12load loader
- sys/arch/xen parts of build.sh release support
[cl, ticket #337]
 1.3.2.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.3.2.6 01-Apr-2005  skrll Sync with HEAD.
 1.3.2.5 18-Dec-2004  skrll Sync with HEAD.
 1.3.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.3.2.2 03-Aug-2004  skrll Sync with HEAD
 1.3.2.1 07-May-2004  skrll file cpufunc.h was added on branch ktrace-lwp on 2004-08-03 10:43:10 +0000
 1.4.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.4.4.1 29-Apr-2005  kent sync with -current
 1.4.2.2 18-Jan-2005  bouyer The wbinvd instruction can't be used with xen, it case a kernel trap.
Implement wbinvd() with MMUEXT_FLUSH_CACHE.
Make shared_info_t volatile.
 1.4.2.1 17-Dec-2004  bouyer arch/x86/include/intr.h:spllower() now use read_psl/write_psl to reenable
interrupts if they were enabled at spllower() call.
Change read_psl()/write_psl() to DTRT with
HYPERVISOR_shared_info->vcpu_data[0].evtchn_upcall_mask.
XXX maybe spllower() should use __save_flags/__restore_flags instead.
 1.5.2.4 22-Jan-2007  tron Pull up following revision(s) (requested by bouyer in ticket #1652):
sys/arch/xen/include/cpufunc.h: revision 1.13
sys/arch/xen/include/xen3-public/io/ring.h: revision 1.6
Define x86_mfence(). Use it where appropriate. Seems to fix a hang in
the network interface front-end/back-end for me ...
 1.5.2.3 07-Apr-2006  tron branches: 1.5.2.3.2;
Apply patch (requested by bouyer in ticket #1245):
Pull up Xen3 domU support. This adds support for the Xen-3 memory bootstrap,
xenstore, and block and network device frontend. Xen-3 support is turned
on by 'options XEN3', which disable Xen-2 support.
Changes affecting non-xen3 specific code:
- xbd and xennet at hypervisor now attaches with xbd_hypervisor and
xennet_hypervisor
- x86_atomic_* renamed to xen_atomic_*
- use genassim.cf to pull in more constant from include files for assembly
- Map the shared info page from locore.S instead of the 0xffffffff hack
in xen_machdep.c
- remove some unused code
- some __asm__ __volatile__ -> __asm volatile and __inline__ -> inline
- more debug code
 1.5.2.2 01-May-2005  tron Pull up revision 1.7 (requested by yamt in ticket #233):
don't use block scope static function decl. found by gcc4.
 1.5.2.1 30-Mar-2005  tron Pull up revision 1.6 (requested by bouyer in ticket #71):
Don't assume we're on a uniprocessor system (the hypervisor may be running SMP)
and add "lock;" barrier to avoid instruction reordering in event handlings.
This fix the last issue with event loss I was getting on SMP systems.
 1.5.2.3.2.1 22-Jan-2007  tron Pull up following revision(s) (requested by bouyer in ticket #1652):
sys/arch/xen/include/cpufunc.h: revision 1.13
sys/arch/xen/include/xen3-public/io/ring.h: revision 1.6
Define x86_mfence(). Use it where appropriate. Seems to fix a hang in
the network interface front-end/back-end for me ...
 1.7.2.7 21-Jan-2008  yamt sync with head
 1.7.2.6 07-Dec-2007  yamt sync with head
 1.7.2.5 27-Oct-2007  yamt sync with head.
 1.7.2.4 03-Sep-2007  yamt sync with head.
 1.7.2.3 26-Feb-2007  yamt sync with head.
 1.7.2.2 30-Dec-2006  yamt sync with head.
 1.7.2.1 21-Jun-2006  yamt sync with head.
 1.10.8.2 03-Sep-2006  yamt sync with head.
 1.10.8.1 13-Mar-2006  yamt sync with head.
 1.10.6.1 22-Apr-2006  simonb Sync with head.
 1.10.4.1 09-Sep-2006  rpaulo sync with head
 1.11.10.1 27-Aug-2006  riz Pull up following revision(s) (requested by dsl in ticket #69):
sys/arch/xen/include/cpufunc.h: revision 1.12
Fix build of machdep.c with -Os and -O3
 1.12.4.1 22-Oct-2006  yamt sync with head
 1.12.2.2 01-Feb-2007  ad Sync with head.
 1.12.2.1 18-Nov-2006  ad Sync with head.
 1.14.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.15.20.3 23-Mar-2008  matt sync with HEAD
 1.15.20.2 09-Jan-2008  matt sync with HEAD
 1.15.20.1 06-Nov-2007  matt sync with HEAD
 1.15.18.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.15.18.1 02-Oct-2007  joerg Sync with HEAD.
 1.15.10.1 03-Oct-2007  garbled Sync with HEAD
 1.15.2.2 03-Dec-2007  ad Sync with HEAD.
 1.15.2.1 09-Oct-2007  ad Sync with head.
 1.16.2.1 06-Oct-2007  yamt sync with head.
 1.17.2.1 17-Oct-2007  bouyer Prepare for xenamd64:
- kill xen/i386/identcpu.c, use i386/i386/identcpu.c instead (with a few
#ifndef XEN)
- move some files that can be shared between i386 and amd64 from
xen/i386 to xen/x86 (or to xen/xen for non-cpu-specific code)
- split assembly out of xen/include/hypervisor.h to xen/include/hypercalls.h
- use <xen/...> instead of <machine/...> for cpu-independant include files.

more work needed here, i386-specific files should got out of arch/xen to
arch/xeni386, and more code shared with arch/i386.
 1.18.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.18.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.19.6.1 10-Jan-2008  bouyer Change xeni386 build to match xenamd64:
- machine/ points to xen/include/i386
- remove includes that were identical to the i386/include/ ones; the build
will find them though the xen-ma/machine link.
- include xen files using xen/ not machine/
 1.6 29-Jul-2009  cegger remove Xen2 support.
ok bouyer@
 1.5 17-Oct-2007  garbled branches: 1.5.20; 1.5.34;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.4 23-Sep-2007  bouyer Add NetBSD RCS Id.
 1.3 20-Apr-2005  bouyer branches: 1.3.2; 1.3.38; 1.3.46; 1.3.56; 1.3.58;
Add polling support to the domain controller. Use this in xencons instead
of relying on the fact that the domain controller is still getting interrupts
when xenconscn_getc()/xenconscn_putc() is called.
Now that polling is fixed, move IPL_CTRL down between IPL_SOFTSERIAL and
IPL_TTY, fixing port-xen/29999 by YAMAMOTO Takashi.
Now that IPL_CTRL is low enouth, remove the softintr stuff from the
domain controller, and call wakeup() directly.

Thanks to YAMAMOTO Takashi and Christian Limpach for feedback and suggestions.
 1.2 09-Mar-2005  bouyer branches: 1.2.2; 1.2.4;
Merge the bouyer-xen2 branch. This add supports for the Xen 2.0 virtual
machine kernel (both privileged and non-privileged domains), and remove support
for the old xen 1.2.
 1.1 13-Dec-2004  bouyer branches: 1.1.2; 1.1.4; 1.1.6;
file ctrl_if.h was initially added on branch bouyer-xen2.
 1.1.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.4.1 29-Apr-2005  kent sync with -current
 1.1.2.1 13-Dec-2004  bouyer Commit files from netbsd-2.0-xen-sparse/sys/arch/xen in the Xen-2.0
distribution. These are the files modified from the 2.0 tree to get
NetBSD/xen working with Xen 2.
 1.2.4.3 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.4.2 01-Apr-2005  skrll Sync with HEAD.
 1.2.4.1 09-Mar-2005  skrll file ctrl_if.h was added on branch ktrace-lwp on 2005-04-01 14:29:10 +0000
 1.2.2.1 28-Apr-2005  tron Pull up revision 1.3 (requested by bouyer in ticket #193):
Add polling support to the domain controller. Use this in xencons instead
of relying on the fact that the domain controller is still getting interrupts
when xenconscn_getc()/xenconscn_putc() is called.
Now that polling is fixed, move IPL_CTRL down between IPL_SOFTSERIAL and
IPL_TTY, fixing port-xen/29999 by YAMAMOTO Takashi.
Now that IPL_CTRL is low enouth, remove the softintr stuff from the
domain controller, and call wakeup() directly.
Thanks to YAMAMOTO Takashi and Christian Limpach for feedback and suggestions.
 1.3.58.1 06-Nov-2007  matt sync with HEAD
 1.3.56.1 02-Oct-2007  joerg Sync with HEAD.
 1.3.46.1 03-Oct-2007  garbled Sync with HEAD
 1.3.38.1 09-Oct-2007  ad Sync with head.
 1.3.2.1 27-Oct-2007  yamt sync with head.
 1.5.34.1 01-Nov-2009  jym Sync with HEAD.
 1.5.20.1 19-Aug-2009  yamt sync with head.
 1.4 09-Mar-2005  bouyer Merge the bouyer-xen2 branch. This add supports for the Xen 2.0 virtual
machine kernel (both privileged and non-privileged domains), and remove support
for the old xen 1.2.
 1.3 24-Apr-2004  cl branches: 1.3.2; 1.3.6; 1.3.8; 1.3.10;
Let event_set_handler set the void * argument to event handlers.
 1.2 17-Apr-2004  cl - fix event dispatching for event 0
- use struct trapframe instead of struct pt_regs
 1.1 11-Mar-2004  cl branches: 1.1.2;
Add port to the Xen virtual machine monitor.
(see http://www.cl.cam.ac.uk/Research/SRG/netos/xen/)
 1.1.2.1 22-May-2004  he Pull up revisions 1.2-1.3 (requested by cl in ticket #337):
Upgrade xen support:
- add block device driver
- network device driver bug fixes
- support for vga/keyboard/mouse
- support for domain0 operations
- fix /dev/mem and i386_iopl, reboot, event dispatch
- fix clock support, cpu speed report, lazy fpu switching
- add xen12load loader
- sys/arch/xen parts of build.sh release support
[cl, ticket #337]
 1.3.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.3.8.1 29-Apr-2005  kent sync with -current
 1.3.6.1 18-Jan-2005  bouyer Remove unused files.
 1.3.2.5 01-Apr-2005  skrll Sync with HEAD.
 1.3.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.3.2.2 03-Aug-2004  skrll Sync with HEAD
 1.3.2.1 24-Apr-2004  skrll file events.h was added on branch ktrace-lwp on 2004-08-03 10:43:10 +0000
 1.32 07-May-2020  bouyer Change event_set_handler() to take the target CPU parameter. If ci is NULL,
event_set_handler() will choose the CPU and bind the event.
If ci is not NULL the caller is responsible for binding the event.
Use a IPI xcall to register the handlers if needed.
pull in a hack from x86 to force pirq handlers to be mpsafe if registered at
a level != IPL_VM. This is for the com at isa interrupt handler, which
registers at IPL_HIGH and has to way to tell it's mpsafe (taking
KERNEL_LOCK at IPL_HIGH causes deadlocks on MP systems).
 1.31 04-May-2020  jdolecek add support for using MSI for XenPV Dom0

use PHYSDEVOP_map_pirq to get the pirq/gsi for MSI/MSI-X, switch also INTx
to use it instead of PHYSDEVOP_alloc_irq_vector

MSI confirmed working with single-vector MSI for wm(4), ahcisata(4), bge(4)

XXX added some provision for MSI-X, but it doesn't actually work (no interrupts
delivered), needs some further investigation; disable MSI-X for XENPV
via flag in x86/pci/pci_machdep.c
 1.30 25-Apr-2020  bouyer Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.29 13-Apr-2020  bouyer By default, events are bound to CPU 0 (exept for IPIs and VTIMERs which
are bound to a different CPU at creation time).
Recent MI changes caused the scheduler to choose a different CPU when
probing and attaching xennet devices (I guess it's the xenbus thread which
runs on a different CPU). This cause the callback to be called on a different
CPU than the one expected by the kernel, and the event is ignored.
It is handled when the clock causes the callback to be called on the right
CPU, which is why xennet still run, but slowly.

Change event_set_handler() to do a EVTCHNOP_bind_vcpu if requested to,
and make sure we don't do it for IPIs and VIRQs (for theses, the op fails).
 1.28 06-Apr-2020  jdolecek branches: 1.28.2;
add known_mpsafe parameter also to pirq_establish(), and pass the parameter
to underlying event_set_handler()
 1.27 06-Apr-2020  jdolecek remove restriction on interrupt level for MP-safe interrupt handlers
 1.26 24-Jun-2018  jdolecek branches: 1.26.2;
add support for kern.intr.list aka intrctl(8) 'list' for xen

event_set_handler() and pirq_establish() now have extra intrname
parameter; shared intr_create_intrid() is used to provide the value

xen drivers were changed to pass the specific driver instance
name as the xname, e.g. 'vcpu0 clock' instead just 'clock', or
'xencons0' instead of 'xencons'

associated evcnt is now changed to use intrname - this matches native x86
 1.25 04-Nov-2017  cherry branches: 1.25.2;
Retire xen/x86/intr.c and use the new xen specific glue in x86/x86/intr.c

The purpose of this change is to expose the x86/include/intr.h API
to drivers. Specifically the following functions:

void *intr_establish_xname(...);
void *intr_establish(...);
void intr_disestablish(...);

while maintaining the old API from xen/include/evtchn.h, specifically
the following functions:

int event_set_handler(...);
int event_remove_handler(...);

This is so that if things break, we can keep using the old API until
everything stabilises. This is a stepping stone towards getting the
actual XEN event callback path rework code in place - which can be
done opaquely behind the intr.h API - NetBSD/XEN specific drivers that
have been ported to the intr.h API should then work without
significant further modifications.
 1.24 16-Jul-2017  cherry branches: 1.24.2;
Add a glue function to inspect event channel<->legacy IRQ mappings.
This is towards getting xen to use more x86/ "native" code.
 1.23 14-Mar-2015  bouyer Properly implemement pci_intr_disestablish(9), so that interrupt
handlers stop being called when the device has been detached.
Should fix PR port-xen/47720 (which turns out to not be related to raidframe).
While there fix possible races in event_remove_handler() and pirq_establish().
 1.22 12-Jan-2013  bouyer branches: 1.22.12; 1.22.14;
Back out this commit:
http://mail-index.netbsd.org/source-changes/2012/12/28/msg039950.html
which cause a panic when running tests on amd64, as shown on:
http://www-soc.lip6.fr/~bouyer/NetBSD-tests/xen/HEAD/
(i386 hangs for unrelated reasons).
 1.21 28-Dec-2012  cherry Simplify the xen event handler callback by:
- moving the interrupt handler callback traversal into a separate
function.
- using evt_iterate_bits() to scan through the pending bitfield
- removing cross-cpu pending actions - events recieved on the wrong
vcpu are re-routed via hypervisor_send_event().
- simplifying nested while() loops by encapsulating them in
equivalent functions.

Many thanks for multiple reviews by bouyer@ and jym@
 1.20 20-Sep-2011  jym branches: 1.20.8; 1.20.12;
Merge jym-xensuspend branch in -current. ok bouyer@.

Goal: save/restore support in NetBSD domUs, for i386, i386 PAE and amd64.

Executive summary:
- split all Xen drivers (xenbus(4), grant tables, xbd(4), xennet(4))
in two parts: suspend and resume, and hook them to pmf(9).
- modify pmap so that Xen hypervisor does not cry out loud in case
it finds "unexpected" recursive memory mappings
- provide a sysctl(7), machdep.xen.suspend, to command suspend from
userland via powerd(8). Note: a suspend can only be handled correctly
when dom0 requested it, so provide a mechanism that will prevent
kernel to blindly validate user's commands

The code is still in experimental state, use at your own risk: restore
can corrupt backend communications rings; this can completely thrash
dom0 as it will loop at a high interrupt level trying to honor
all domU requests.

XXX PAE suspend does not work in amd64 currently, due to (yet again!)
page validation issues with hypervisor. Will fix.

XXX secondary CPUs are not suspended, I will write the handlers
in sync with cherry's Xen MP work.

Tested under i386 and amd64, bear in mind ring corruption though.

No build break expected, GENERICs and XEN* kernels should be fine.
./build.sh distribution still running. In any case: sorry if it does
break for you, contact me directly for reports.
 1.19 11-Aug-2011  cherry Make event/interrupt handling MP aware
 1.18 23-Oct-2009  snj branches: 1.18.10;
Remove 3rd and 4th clauses. OK cl@ (copyright holder).
 1.17 24-Oct-2008  jym branches: 1.17.8;
- rename init_events() to events_init(), to better reflect netbsd semantics

- change unbind_[pv]irq_from_evtch() so that they now return the event
channel the [PV]IRQ was bound to. It reflects the opposite behaviour of the
bind_[pv]irq_to_evtch() functions.

- remove xenbus_suspend() and xenbus_resume() prototypes, as they are not
used anywhere else, and will conflict with the xenbus pmf(9) handlers.

- make start_info aligned on a page boundary, as Xen expects it to be so.

- mask event channel during xbd detach before removing its handler (can
avoid spurious events).

- add the "protocol" entry in xenstore during xbd initialization. Normally
created during domU's boot by xentools, it is under domU's responsibility
in all other cases (save/restore, hot plugging, etc.).

- modifications to xs_init(), so that it can properly return an error.

Reviewed by Christoph (cegger@).
 1.16 01-Jul-2008  bouyer branches: 1.16.2;
Raise ci_idepth (and switch to interrupt stack on i386) becore calling
xenevt_event().
 1.15 19-Feb-2008  bouyer branches: 1.15.6; 1.15.10; 1.15.12; 1.15.14;
Fix xenevt to not call softint_schedule() above IPL_HIGH:
Register a ipl callback for IPL_HIGH.
if the current ipl level is too high, just record the event in a bitmap,
and record IPL_HIGH as pending. The callback will process the pending events.
 1.14 12-Dec-2007  bouyer cleanup the debug event handler to not use the IPL system at all. Fix
debug event storm on XEN2.
 1.13 08-Dec-2006  yamt branches: 1.13.24; 1.13.32; 1.13.34; 1.13.36;
- pass intrframe by-pointer, not by-value.
- make i386 and xen use per-cpu interrupt stack.

xen part is reviewed by Manuel Bouyer.
 1.12 28-Sep-2006  bouyer Add Xen3 support for ACPI and/or MPBIOS + IOAPIC. To help with this, physical
CPUs are now configured on mainbus only in dom0, and only to know about
their APIC id. virtual CPUs are attached to hypervisor as:
vcpu* at hypervisor?
and this is what's used as curcpu(). The kernel config files needs to be
updated for this, see XEN3_DOM0 or XEN3_DOMU for examples.
XEN3_DOM0 now has acpi, MPBIOS and ioapic by default.
Note that a Xen dom0 kernel doens't have access to the lapic.
 1.11 11-Dec-2005  christos branches: 1.11.20; 1.11.22;
merge ktrace-lwp.
 1.10 10-Sep-2005  bouyer The line number in the PCI interrupt register can be larger than 31 on
some hardware, depending on how Xen set things up. So bump NR_PIRQ from 32
to 256.
 1.9 28-Apr-2005  yamt branches: 1.9.2;
rename do_event to evtchan_do_event.
the former is too generic name and it actually hides a bug in xennetback.
 1.8 20-Apr-2005  bouyer Event handling optimisations:
- sort the ih_evt_handler list by IPL, higher first. Otherwise some handlers
would have been delayed, event if they could run at the current IPL.
- As ih_evt_handler is sorted, remove IPLs that have been processed for
an event when calling hypervisor_set_ipending()
- In hypervisor_set_ipending(), enter the event in ipl_evt_mask only
for the lowest IPL. As deffered IPLs are processed high to low,
this ensure that hypervisor_enable_event() will be called only when all
callbacks have been called for an event. We don't need the evtch_maskcount[]
counters any more.

Thanks to YAMAMOTO Takashi for ideas and feedback.
 1.7 18-Apr-2005  yamt don't unmask an event channel until all interrupts for it are served.
fix problems with shared (physical) interrupts.
 1.6 17-Apr-2005  bouyer Allow to pass a more descriptive name to event_set_handler() (e.g. IRQ number
for physical IRQ, or device name for xen device drivers). This makes
systat and vmstat output more usable, especially as the channel numbers
change each time a guest reboots.
 1.5 16-Apr-2005  bouyer Get rid of the event to pseudo-irq mapping. We are limited to 32 pseudo-irq,
including soft interrupt, and this is way too low in some use (lots of domains,
or domains with lots of xennet, or even hardware with lots of devices at
different interrupts).
Based on idea from YAMAMOTO Takashi, keep one list of handler per-event and
one per-IPL (so the same handler is now in 2 lists). In the common case were
an event is received at low IPL, we can call the handlers quickly (there
is usually only one handler per event, unless the event is mapped to a
physical interrupt and this interrupt is shared by different devices).
Deffered events and software interrupts are handled by a bitmask (as before)
with one bit per IPL. When one IPL has an event pending all handlers for
this IPL will be called.
With this change, it is now possible to have all the 1024 events active.

While here, handle debug event in a special way: the handler is always called,
regardless of the current IPL. Make the handler print usefull informations
about events and IPL states.
Also remove code not used on Xen in files inherited from the x86 port.
 1.4 11-Apr-2005  yamt fix a bug which corrupts runqueue.
when dealing with events, which are handed to xenevt pseudo device,
don't call wakeup(9)/selnotify(9) at too high IPL. PR/29792.
 1.3 11-Apr-2005  yamt don't stamp soft interrupts.
 1.2 09-Mar-2005  bouyer branches: 1.2.2; 1.2.4;
Merge the bouyer-xen2 branch. This add supports for the Xen 2.0 virtual
machine kernel (both privileged and non-privileged domains), and remove support
for the old xen 1.2.
 1.1 13-Dec-2004  bouyer branches: 1.1.2; 1.1.4; 1.1.6;
file evtchn.h was initially added on branch bouyer-xen2.
 1.1.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.4.1 29-Apr-2005  kent sync with -current
 1.1.2.4 08-Mar-2005  bouyer Add infrastructure to unregsiter event callbacks.
 1.1.2.3 21-Jan-2005  bouyer - Add a centralised handler for physical interrupts, which will call the
real handler. This is not necessery but is usefull for debug.
- make irq_needs_unmask_notify[] per-IRQ, instead of per physical IRQ
- use a static physdev_op_t for PHYSDEVOP_IRQ_UNMASK_NOTIFY (it never changes,
so no need to allocate a new one each time)
- call pirq_notify() from hypervisor_enable_irq().
 1.1.2.2 18-Jan-2005  bouyer Implement physical IRQ mapping.
 1.1.2.1 13-Dec-2004  bouyer Commit files from netbsd-2.0-xen-sparse/sys/arch/xen in the Xen-2.0
distribution. These are the files modified from the 2.0 tree to get
NetBSD/xen working with Xen 2.
 1.2.4.3 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.4.2 01-Apr-2005  skrll Sync with HEAD.
 1.2.4.1 09-Mar-2005  skrll file evtchn.h was added on branch ktrace-lwp on 2005-04-01 14:29:10 +0000
 1.2.2.8 14-Sep-2005  tron Pull up following revision(s) (requested by bouyer in ticket #777):
sys/arch/xen/include/evtchn.h: revision 1.10
The line number in the PCI interrupt register can be larger than 31 on
some hardware, depending on how Xen set things up. So bump NR_PIRQ from 32
to 256.
 1.2.2.7 01-May-2005  tron Pull up revision 1.9 (requested by yamt in ticket #238):
rename do_event to evtchan_do_event.
the former is too generic name and it actually hides a bug in xennetback.
 1.2.2.6 28-Apr-2005  tron Pull up revision 1.8 (requested by bouyer in ticket #192):
Event handling optimisations:
- sort the ih_evt_handler list by IPL, higher first. Otherwise some handlers
would have been delayed, event if they could run at the current IPL.
- As ih_evt_handler is sorted, remove IPLs that have been processed for
an event when calling hypervisor_set_ipending()
- In hypervisor_set_ipending(), enter the event in ipl_evt_mask only
for the lowest IPL. As deffered IPLs are processed high to low,
this ensure that hypervisor_enable_event() will be called only when all
callbacks have been called for an event. We don't need the evtch_maskcount[]
counters any more.
Thanks to YAMAMOTO Takashi for ideas and feedback.
 1.2.2.5 28-Apr-2005  tron Pull up revision 1.7 (requested by bouyer in ticket #192):
don't unmask an event channel until all interrupts for it are served.
fix problems with shared (physical) interrupts.
 1.2.2.4 28-Apr-2005  tron Pull up revision 1.6 (requested by bouyer in ticket #192):
Allow to pass a more descriptive name to event_set_handler() (e.g. IRQ number
for physical IRQ, or device name for xen device drivers). This makes
systat and vmstat output more usable, especially as the channel numbers
change each time a guest reboots.
 1.2.2.3 28-Apr-2005  tron Pull up revision 1.5 (requested by bouyer in ticket #192):
Get rid of the event to pseudo-irq mapping. We are limited to 32 pseudo-irq,
including soft interrupt, and this is way too low in some use (lots of domains,
or domains with lots of xennet, or even hardware with lots of devices at
different interrupts).
Based on idea from YAMAMOTO Takashi, keep one list of handler per-event and
one per-IPL (so the same handler is now in 2 lists). In the common case were
an event is received at low IPL, we can call the handlers quickly (there
is usually only one handler per event, unless the event is mapped to a
physical interrupt and this interrupt is shared by different devices).
Deffered events and software interrupts are handled by a bitmask (as before)
with one bit per IPL. When one IPL has an event pending all handlers for
this IPL will be called.
With this change, it is now possible to have all the 1024 events active.
While here, handle debug event in a special way: the handler is always called,
regardless of the current IPL. Make the handler print usefull informations
about events and IPL states.
Also remove code not used on Xen in files inherited from the x86 port.
 1.2.2.2 13-Apr-2005  tron Pull up revision 1.4 (requested by yamt in ticket #146):
fix a bug which corrupts runqueue.
when dealing with events, which are handed to xenevt pseudo device,
don't call wakeup(9)/selnotify(9) at too high IPL. PR/29792.
 1.2.2.1 13-Apr-2005  tron Pull up revision 1.3 (requested by yamt in ticket #143):
don't stamp soft interrupts.
 1.9.2.4 27-Feb-2008  yamt sync with head.
 1.9.2.3 21-Jan-2008  yamt sync with head
 1.9.2.2 30-Dec-2006  yamt sync with head.
 1.9.2.1 21-Jun-2006  yamt sync with head.
 1.11.22.2 10-Dec-2006  yamt sync with head.
 1.11.22.1 22-Oct-2006  yamt sync with head
 1.11.20.2 12-Jan-2007  ad Sync with head.
 1.11.20.1 18-Nov-2006  ad Sync with head.
 1.13.36.1 13-Dec-2007  bouyer cleanup the way debug event is handled: make it bypass the IPL system
completely, it's called by shortcuts in the normal path because we want it to
be always called, even if the IPL is high.
Fix debug even recursion on XEN2
 1.13.34.1 13-Dec-2007  yamt sync with head.
 1.13.32.1 26-Dec-2007  ad Sync with head.
 1.13.24.2 23-Mar-2008  matt sync with HEAD
 1.13.24.1 09-Jan-2008  matt sync with HEAD
 1.15.14.1 03-Jul-2008  simonb Sync with head.
 1.15.12.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.15.10.2 11-Mar-2010  yamt sync with head
 1.15.10.1 04-May-2009  yamt sync with head.
 1.15.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.15.6.1 02-Jul-2008  mjf Sync with HEAD.
 1.16.2.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.17.8.4 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.17.8.3 01-Nov-2009  jym - Upgrade suspend/resume code to comply with Xen2 removal.
- Add support for PAE domUs suspend/resume.
- Fix an issue regarding initialization of the xbd ring I/O that could end
badly during resume, with invalid block operations submitted to dom0 backend.

NetBSD supports PAE under x86_32 by considering the L2 page as being
4 pages long instead of 1.

Xen validates the page types during resume. Sadly, the hypervisor handles
alternative recursive mappings (== PG/PD entries pointing to pages other
than self) inadequately, which could lead to incorrect page pinning.

As a result, the important change with this patch is to clear these alternative
mappings during suspend, and reset them back to their former self upon
resume. For PAE, approx. all 4 PDIR_SLOT_PTEs could be considered as
alternative recursive mappings.

See comments in pmap.c for further details.

Now, let the testing and bug hunting begin.
 1.17.8.2 01-Nov-2009  jym Sync with HEAD.
 1.17.8.1 09-Feb-2009  jym Initial code for xen save/restore/migrate facilities.

- split the attach code of frontends in two half: one that is only needed
during autoconf(9) attach/detach phases, and one used at each save/restore
of device state (between suspend and resume).

Applies to hypervisor, xencons, xenbus, xbd, and xennet.

- add a rwlock(9) ("ptom_lock") to protect the different parts in the kernel
that manipulate MFNs (which could change between a suspend and a resume,
without the kernel noticing it). Parts that require MFNs acquire a reader lock,
while suspend code will acquire a writer lock to ensure that no-other parts
in kernel still use MFNs.

- integrate the suspend code with sysmon.

- various things in pmap(9), and clock.

TODO:
- factorize code a bit more inside frontends drivers.
- remove all alternative recursive (APDP_PDE) mappings found in PD/PT during
suspend, as Xen does not support them.
- abstract the ptom_lock locking, it is only required when kernel preemption
is enabled, or on MP systems.

Current code works mostly. You may experience difficulties in some corner
cases (dom0 warnings about xennet interface errors, and Xen tools failing to
validate NetBSD's alternative pmaps).
 1.18.10.3 17-Aug-2011  cherry Pullup relevant changes from -current
 1.18.10.2 04-Aug-2011  cherry first cut at per-cpu event handling
 1.18.10.1 03-Jun-2011  cherry Initial import of xen MP sources, with kernel and userspace tests.
- this is a source priview.
- boots to single user.
- spurious interrupt and pmap related panics are normal
 1.20.12.1 03-Dec-2017  jdolecek update from HEAD
 1.20.8.1 14-Apr-2015  msaitoh Pull up following revision(s) (requested by bouyer in ticket #1278):
sys/arch/xen/include/evtchn.h: revision 1.23
sys/arch/xen/xen/evtchn.c: revision 1.71
sys/arch/xen/xen/pci_intr_machdep.c: revision 1.17
Properly implemement pci_intr_disestablish(9), so that interrupt
handlers stop being called when the device has been detached.
Should fix PR port-xen/47720 (which turns out to not be related to raidframe).
While there fix possible races in event_remove_handler() and pirq_establish().
 1.22.14.2 28-Aug-2017  skrll Sync with HEAD
 1.22.14.1 06-Apr-2015  skrll Sync with HEAD
 1.22.12.1 18-Mar-2015  snj Pull up following revision(s) (requested by bouyer in ticket #618):
sys/arch/xen/include/evtchn.h: revision 1.23
sys/arch/xen/xen/evtchn.c: revision 1.71
sys/arch/xen/xen/pci_intr_machdep.c: revision 1.17
Properly implemement pci_intr_disestablish(9), so that interrupt
handlers stop being called when the device has been detached.
Should fix PR port-xen/47720 (which turns out to not be related to raidframe).
While there fix possible races in event_remove_handler() and pirq_establish().
 1.24.2.2 16-Jul-2017  cherry 2752365
 1.24.2.1 16-Jul-2017  cherry file evtchn.h was added on branch perseant-stdc-iso10646 on 2017-07-16 05:03:37 +0000
 1.25.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.26.2.3 21-Apr-2020  martin Sync with HEAD
 1.26.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.26.2.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.28.2.3 20-Apr-2020  bouyer Misc fixes after merge
 1.28.2.2 20-Apr-2020  bouyer Sync with HEAD
 1.28.2.1 19-Apr-2020  bouyer Add a struct pic * member to struct intrhand.
This will be used for interrupt_get_count()
For Xen remplace pic_type with a pointer to the pic, and add a pointer
to intrhand, in struct pintrhand
Make event_set_handler return the pointer to struct intrhand.
Don't allocate a fake intrhand in xen_intr_establish_xname(), use the
one returned by event_set_handler().
 1.6 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.5 21-Nov-2006  yamt branches: 1.5.28; 1.5.34; 1.5.42;
include the i386 frameasm.h rather than inlining it.
 1.4 15-Jan-2006  bouyer branches: 1.4.18; 1.4.20;
Snapshot of work in progress on NetBSD port to Xen3:
- kernel (both dom0 and domU) boot, console is functionnal and it can starts
software from a ramdisk
- there is no driver front-end expect console for domU yet.
- dom0 can probe devices and ex(4) work when Xen3 is booted without acpi
and apic support. But the on-board IDE doens't get interrupts.
The PCI code still needs work (it's hardcoded to mode 1). Some of this
code should be shared with ../x86
The physical insterrupt code needs to get MPBIOS and ACPI support, and
do interrupt routing to properly interract with Xen.
To enable Xen-3.0 support, add
options XEN3
to your kernel config file (this will disable Xen2 support)
Changes affecting Xen-2.0 support (no functionnal changes intended):
- get more constants from genassym for assembly code
- remove some unneeded registers move from start()
- map the shared info page from start(), and remove the pte = 0xffffffff hack
- vector.S: in hypervisor_callback() make sure %esi points to
HYPERVISOR_shared_info before accessing the info page. Remplace some
hand-written assembly with the equivalent macro defined in frameasm.h
- more debug code, dissabled by default.

while here added my copyright on some files I worked on in 2005.
 1.3 11-Dec-2005  christos branches: 1.3.2;
merge ktrace-lwp.
 1.2 09-Mar-2005  bouyer branches: 1.2.2; 1.2.4;
Merge the bouyer-xen2 branch. This add supports for the Xen 2.0 virtual
machine kernel (both privileged and non-privileged domains), and remove support
for the old xen 1.2.
 1.1 11-Mar-2004  cl branches: 1.1.4; 1.1.8; 1.1.12; 1.1.14;
Add port to the Xen virtual machine monitor.
(see http://www.cl.cam.ac.uk/Research/SRG/netos/xen/)
 1.1.14.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.12.1 29-Apr-2005  kent sync with -current
 1.1.8.2 21-Jan-2005  bouyer Redefine __HYPERVISOR_physdev_op in frameasm.h, so that we can use the
symbolic name in assembly.
 1.1.8.1 13-Dec-2004  bouyer Commit files from netbsd-2.0-xen-sparse/sys/arch/xen in the Xen-2.0
distribution. These are the files modified from the 2.0 tree to get
NetBSD/xen working with Xen 2.
 1.1.4.5 01-Apr-2005  skrll Sync with HEAD.
 1.1.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.4.2 03-Aug-2004  skrll Sync with HEAD
 1.1.4.1 11-Mar-2004  skrll file frameasm.h was added on branch ktrace-lwp on 2004-08-03 10:43:10 +0000
 1.2.4.3 21-Jan-2008  yamt sync with head
 1.2.4.2 30-Dec-2006  yamt sync with head.
 1.2.4.1 21-Jun-2006  yamt sync with head.
 1.2.2.1 07-Apr-2006  tron Apply patch (requested by bouyer in ticket #1245):
Pull up Xen3 domU support. This adds support for the Xen-3 memory bootstrap,
xenstore, and block and network device frontend. Xen-3 support is turned
on by 'options XEN3', which disable Xen-2 support.
Changes affecting non-xen3 specific code:
- xbd and xennet at hypervisor now attaches with xbd_hypervisor and
xennet_hypervisor
- x86_atomic_* renamed to xen_atomic_*
- use genassim.cf to pull in more constant from include files for assembly
- Map the shared info page from locore.S instead of the 0xffffffff hack
in xen_machdep.c
- remove some unused code
- some __asm__ __volatile__ -> __asm volatile and __inline__ -> inline
- more debug code
 1.3.2.1 01-Feb-2006  yamt sync with head.
 1.4.20.1 10-Dec-2006  yamt sync with head.
 1.4.18.1 12-Jan-2007  ad Sync with head.
 1.5.42.1 09-Jan-2008  bouyer Move Xen bits to i386/include/frameasm.h and add CLI/STI macros for
i386. Make native i386 kernels build again.
 1.5.34.1 18-Feb-2008  mjf Sync with HEAD.
 1.5.28.1 23-Mar-2008  matt sync with HEAD
 1.11 05-Apr-2020  jdolecek remove xengnt_grant_transfer() and xengnt_revoke_transfer(), nothing
uses it any more
 1.10 02-Feb-2019  cherry Switch NetBSD/xen to use XEN api tag RELEASE-4.11.1

The headers for this api are in sys/external/mit/xen-include-public/dist/
 1.9 07-Dec-2011  cegger branches: 1.9.48;
switch from xen3-public to xen-public.
 1.8 20-Sep-2011  jym branches: 1.8.2; 1.8.6;
Merge jym-xensuspend branch in -current. ok bouyer@.

Goal: save/restore support in NetBSD domUs, for i386, i386 PAE and amd64.

Executive summary:
- split all Xen drivers (xenbus(4), grant tables, xbd(4), xennet(4))
in two parts: suspend and resume, and hook them to pmf(9).
- modify pmap so that Xen hypervisor does not cry out loud in case
it finds "unexpected" recursive memory mappings
- provide a sysctl(7), machdep.xen.suspend, to command suspend from
userland via powerd(8). Note: a suspend can only be handled correctly
when dom0 requested it, so provide a mechanism that will prevent
kernel to blindly validate user's commands

The code is still in experimental state, use at your own risk: restore
can corrupt backend communications rings; this can completely thrash
dom0 as it will loop at a high interrupt level trying to honor
all domU requests.

XXX PAE suspend does not work in amd64 currently, due to (yet again!)
page validation issues with hypervisor. Will fix.

XXX secondary CPUs are not suspended, I will write the handlers
in sync with cherry's Xen MP work.

Tested under i386 and amd64, bear in mind ring corruption though.

No build break expected, GENERICs and XEN* kernels should be fine.
./build.sh distribution still running. In any case: sorry if it does
break for you, contact me directly for reports.
 1.7 19-Oct-2009  bouyer Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.6 30-Oct-2008  cegger branches: 1.6.6;
make this header compile standalone
 1.5 24-Oct-2008  jym branches: 1.5.2;
- printf -> aprint_*
- fix and add comments
- make some panic/error messages more relevant
- remove last '\n' in DPRINTK() macros, not required as it is already part of format string.

No functional changes.
 1.4 22-Nov-2007  bouyer branches: 1.4.14; 1.4.18; 1.4.24;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.3 17-Oct-2007  garbled branches: 1.3.2;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.2 05-Sep-2007  bouyer branches: 1.2.4;
Switch to dynamically-sized grant tables, available since Xen-3.1.0.
This removes a hard limit that would prevent a guest from running with more
than 7 virtual network interface.
If running on a hypervisor that doesn't support GNTTABOP_query_size, fall back
to a 4-pages grant table, so this change is backward-compatible.
 1.1 06-Mar-2006  bouyer branches: 1.1.4; 1.1.8; 1.1.10; 1.1.16; 1.1.22; 1.1.26; 1.1.32; 1.1.40; 1.1.42; 1.1.46; 1.1.50; 1.1.52;
Implement granttables operations.
 1.1.52.2 09-Jan-2008  matt sync with HEAD
 1.1.52.1 06-Nov-2007  matt sync with HEAD
 1.1.50.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.1.50.1 02-Oct-2007  joerg Sync with HEAD.
 1.1.46.1 10-Sep-2007  skrll Sync with HEAD.
 1.1.42.1 23-Sep-2007  wrstuden Sync with somewhat-recent netbsd-4.
 1.1.40.1 03-Oct-2007  garbled Sync with HEAD
 1.1.32.2 03-Dec-2007  ad Sync with HEAD.
 1.1.32.1 09-Oct-2007  ad Sync with head.
 1.1.26.1 11-Sep-2007  xtraeme Pull up following revision(s) (requested by bouyer in ticket #875):
sys/arch/xen/include/granttables.h: revision 1.2
sys/arch/xen/include/xen3-public/grant_table.h: revision 1.4
sys/arch/xen/xen/xengnt.c: revision 1.3
Switch to dynamically-sized grant tables, available since Xen-3.1.0.
This removes a hard limit that would prevent a guest from running with more
than 7 virtual network interface.
If running on a hypervisor that doesn't support GNTTABOP_query_size, fall back
to a 4-pages grant table, so this change is backward-compatible.
 1.1.22.2 09-Sep-2006  rpaulo sync with head
 1.1.22.1 06-Mar-2006  rpaulo file granttables.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:44:56 +0000
 1.1.16.4 07-Dec-2007  yamt sync with head
 1.1.16.3 27-Oct-2007  yamt sync with head.
 1.1.16.2 21-Jun-2006  yamt sync with head.
 1.1.16.1 06-Mar-2006  yamt file granttables.h was added on branch yamt-lazymbuf on 2006-06-21 14:58:15 +0000
 1.1.10.2 22-Apr-2006  simonb Sync with head.
 1.1.10.1 06-Mar-2006  simonb file granttables.h was added on branch simonb-timecounters on 2006-04-22 11:38:11 +0000
 1.1.8.3 15-Oct-2007  riz Pull up following revision(s) (requested by bouyer in ticket #1836):
sys/arch/xen/include/granttables.h: revision 1.2 via patch
sys/arch/xen/include/xen3-public/grant_table.h: revision 1.4 via patch
sys/arch/xen/xen/xengnt.c: revision 1.3 via patch
Switch to dynamically-sized grant tables, available since Xen-3.1.0.
This removes a hard limit that would prevent a guest from running with more
than 7 virtual network interface.
If running on a hypervisor that doesn't support GNTTABOP_query_size, fall back
to a 4-pages grant table, so this change is backward-compatible.
 1.1.8.2 07-Apr-2006  tron Apply patch (requested by bouyer in ticket #1245):
Pull up Xen3 domU support. This adds support for the Xen-3 memory bootstrap,
xenstore, and block and network device frontend. Xen-3 support is turned
on by 'options XEN3', which disable Xen-2 support.
Changes affecting non-xen3 specific code:
- xbd and xennet at hypervisor now attaches with xbd_hypervisor and
xennet_hypervisor
- x86_atomic_* renamed to xen_atomic_*
- use genassim.cf to pull in more constant from include files for assembly
- Map the shared info page from locore.S instead of the 0xffffffff hack
in xen_machdep.c
- remove some unused code
- some __asm__ __volatile__ -> __asm volatile and __inline__ -> inline
- more debug code
 1.1.8.1 06-Mar-2006  tron file granttables.h was added on branch netbsd-3 on 2006-04-07 12:51:25 +0000
 1.1.4.2 13-Mar-2006  yamt sync with head.
 1.1.4.1 06-Mar-2006  yamt file granttables.h was added on branch yamt-pdpolicy on 2006-03-13 09:07:03 +0000
 1.2.4.1 17-Oct-2007  bouyer Prepare for xenamd64:
- kill xen/i386/identcpu.c, use i386/i386/identcpu.c instead (with a few
#ifndef XEN)
- move some files that can be shared between i386 and amd64 from
xen/i386 to xen/x86 (or to xen/xen for non-cpu-specific code)
- split assembly out of xen/include/hypervisor.h to xen/include/hypercalls.h
- use <xen/...> instead of <machine/...> for cpu-independant include files.

more work needed here, i386-specific files should got out of arch/xen to
arch/xeni386, and more code shared with arch/i386.
 1.3.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.4.24.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.4.18.2 11-Mar-2010  yamt sync with head
 1.4.18.1 04-May-2009  yamt sync with head.
 1.4.14.1 17-Jan-2009  mjf Sync with HEAD.
 1.5.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.6.6.3 01-Nov-2009  jym - Upgrade suspend/resume code to comply with Xen2 removal.
- Add support for PAE domUs suspend/resume.
- Fix an issue regarding initialization of the xbd ring I/O that could end
badly during resume, with invalid block operations submitted to dom0 backend.

NetBSD supports PAE under x86_32 by considering the L2 page as being
4 pages long instead of 1.

Xen validates the page types during resume. Sadly, the hypervisor handles
alternative recursive mappings (== PG/PD entries pointing to pages other
than self) inadequately, which could lead to incorrect page pinning.

As a result, the important change with this patch is to clear these alternative
mappings during suspend, and reset them back to their former self upon
resume. For PAE, approx. all 4 PDIR_SLOT_PTEs could be considered as
alternative recursive mappings.

See comments in pmap.c for further details.

Now, let the testing and bug hunting begin.
 1.6.6.2 01-Nov-2009  jym Sync with HEAD.
 1.6.6.1 09-Feb-2009  jym Initial code for xen save/restore/migrate facilities.

- split the attach code of frontends in two half: one that is only needed
during autoconf(9) attach/detach phases, and one used at each save/restore
of device state (between suspend and resume).

Applies to hypervisor, xencons, xenbus, xbd, and xennet.

- add a rwlock(9) ("ptom_lock") to protect the different parts in the kernel
that manipulate MFNs (which could change between a suspend and a resume,
without the kernel noticing it). Parts that require MFNs acquire a reader lock,
while suspend code will acquire a writer lock to ensure that no-other parts
in kernel still use MFNs.

- integrate the suspend code with sysmon.

- various things in pmap(9), and clock.

TODO:
- factorize code a bit more inside frontends drivers.
- remove all alternative recursive (APDP_PDE) mappings found in PD/PT during
suspend, as Xen does not support them.
- abstract the ptom_lock locking, it is only required when kernel preemption
is enabled, or on MP systems.

Current code works mostly. You may experience difficulties in some corner
cases (dom0 warnings about xennet interface errors, and Xen tools failing to
validate NetBSD's alternative pmaps).
 1.8.6.1 18-Feb-2012  mrg merge to -current.
 1.8.2.1 17-Apr-2012  yamt sync with head
 1.9.48.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.9.48.1 10-Jun-2019  christos Sync with HEAD
 1.3 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.2 22-Nov-2007  bouyer branches: 1.2.2; 1.2.4; 1.2.8; 1.2.12; 1.2.16;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.1 17-Oct-2007  bouyer branches: 1.1.2; 1.1.4;
file hypercalls.h was initially added on branch bouyer-xenamd64.
 1.1.4.2 18-Feb-2008  mjf Sync with HEAD.
 1.1.4.1 08-Dec-2007  mjf Sync with HEAD.
 1.1.2.1 17-Oct-2007  bouyer Prepare for xenamd64:
- kill xen/i386/identcpu.c, use i386/i386/identcpu.c instead (with a few
#ifndef XEN)
- move some files that can be shared between i386 and amd64 from
xen/i386 to xen/x86 (or to xen/xen for non-cpu-specific code)
- split assembly out of xen/include/hypervisor.h to xen/include/hypercalls.h
- use <xen/...> instead of <machine/...> for cpu-independant include files.

more work needed here, i386-specific files should got out of arch/xen to
arch/xeni386, and more code shared with arch/i386.
 1.2.16.3 23-Mar-2008  matt sync with HEAD
 1.2.16.2 09-Jan-2008  matt sync with HEAD
 1.2.16.1 22-Nov-2007  matt file hypercalls.h was added on branch matt-armv6 on 2008-01-09 01:50:06 +0000
 1.2.12.2 10-Jan-2008  bouyer Change xeni386 build to match xenamd64:
- machine/ points to xen/include/i386
- remove includes that were identical to the i386/include/ ones; the build
will find them though the xen-ma/machine link.
- include xen files using xen/ not machine/
 1.2.12.1 05-Jan-2008  bouyer Fix HYPERVISOR_update_va_mapping() for XEN2 (which was unused until now).
Make XEN2 kernels boot.
 1.2.8.3 21-Jan-2008  yamt sync with head
 1.2.8.2 07-Dec-2007  yamt sync with head
 1.2.8.1 22-Nov-2007  yamt file hypercalls.h was added on branch yamt-lazymbuf on 2007-12-07 17:27:09 +0000
 1.2.4.2 03-Dec-2007  ad Sync with HEAD.
 1.2.4.1 22-Nov-2007  ad file hypercalls.h was added on branch vmlocking on 2007-12-03 19:04:36 +0000
 1.2.2.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.2.2.1 22-Nov-2007  joerg file hypercalls.h was added on branch jmcneill-pm on 2007-11-27 19:36:06 +0000
 1.60 16-Jul-2024  riastradh xen: Don't hotpatch away LOCK prefix in xen_mb, even on UP boots.

Both xen_mb and membar_sync are designed to provide store-before-load
ordering, but xen_mb has to provide it in synchronizing guest with
hypervisor, while membar_sync only has to provide it in synchronizing
one (guest) CPU with another (guest) CPU.

It is safe to hotpatch away the LOCK prefix in membar_sync on a
uniprocessor boot because membar_sync is only designed to coordinate
between normal memory on multiple CPUs, and is never necessary when
there's only one CPU involved.

But xen_mb is used to coordinate between the guest and the `device'
implemented by a hypervisor, which might be running on another
_physical_ CPU even if the NetBSD guest only sees one `CPU', i.e.,
one _virtual_ CPU. So even on `uniprocessor' boots, xen_mb must
still issue an instruction with store-before-load ordering on
multiprocessor systems, such as a LOCK ADD (or MFENCE, but MFENCE is
costlier for no benefit here).

No need to change xen_wmb (release ordering, load/store-before-store)
or xen_rmb (acquire ordering, load-before-load/store) because every
x86 store is a store-release and every x86 load is a load-acquire,
even on multiprocessor systems, so there's no hotpatching involved
anyway.

PR kern/57199
 1.59 16-Oct-2023  bouyer branches: 1.59.6;
Move the pvh_xencons so xen_machdep.c as early_xencons, so it can be
used in the future as early ouput for plain PV guests too.
 1.58 16-Oct-2023  bouyer Xen's start_info_t is larger than 512 bytes these days, so bump the copy
size to a whole PAGE_SIZE, and CTASSERT() that start_info_t is smaller.
Luckily we didn't use yet the parts skipped
 1.57 25-Feb-2023  riastradh xen/hypervisor.h: Nix trailing whitespace.

No functional change intended.
 1.56 25-Feb-2023  riastradh xen: Fix sense of xen_rmb/wmb to make sense.

Use membar_acquire and membar_release, not membar_consumer and
membar_producer, out of paranoia -- that better matches Linux's
rmb/wmb (at least for non-I/O loads and stores).

Proposed on port-xen:
https://mail-index.netbsd.org/port-xen/2022/07/13/msg010248.html
 1.55 07-Sep-2022  knakahara branches: 1.55.4;
NetBSD/x86: Raise the number of interrupt sources per CPU from 32 to 56.

There has been no objection for three years.
https://mail-index.netbsd.org/port-amd64/2019/09/22/msg003012.html
Implemented by nonaka@n.o, updated by me.
 1.54 25-May-2022  bouyer PVH and HVM guests can easily have more than XEN_LEGACY_MAX_VCPUS (32) cpus.
Support up to HVM_MAX_VCPUS (256). This requires resizing a few arrays in
evtchn.c, and using
VCPUOP_register_vcpu_info for vcpuid >= XEN_LEGACY_MAX_VCPUS
Tested with 96 vCPUs.
 1.53 19-May-2022  bouyer Restore de EOI mechanism for pirq, using the newer hypervisor interface.
It is needed.
Hopefully fixes kern/56291, kern/56793, kern/55667
 1.52 02-May-2020  bouyer Introduce Xen PVH support in GENERIC.
This is compiled in with
options XENPVHVM
x86 changes:
- add Xen section and xen pvh entry points to locore.S. Set vm_guest
to VM_GUEST_XENPVH in this entry point.
Most of the boot procedure (especially page table setup and switch to
paged mode) is shared with native.
- change some x86_delay() to delay_func(), which points to x86_delay() for
native/HVM, and xen_delay() for PVH

Xen changes:
- remove Xen bits from init_x86_64_ksyms() and init386_ksyms()
and move to xen_init_ksyms(), used for both PV and PVH
- set ISA no-legacy-devices property for PVH
- factor out code from Xen's cpu_bootconf() to xen_bootconf()
in xen_machdep.c
- set up a specific pvh_consinit() which starts with printk()
(which uses a simple hypercall that is available early) and switch to
xencons when we can use pmap_kenter_pa().
 1.51 25-Apr-2020  bouyer Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.50 21-Apr-2020  jdolecek convert to newer HYPERVISOR_physdev_op() interface, now command and the
arg are separate arguments - this is needed for newer physdev_op commands

remove code for PHYSDEVOP_IRQ_UNMASK_NOTIFY, it is obsolete since
interface version 0x00030202 and is unsupported by newer versions of Xen

confirmed working on amd64 Dom0, i386 compile-tested only
 1.49 04-Feb-2019  cherry branches: 1.49.10;
Bump up XEN source API compatibility to 0x00030208 from 0x00030201,

but maintain backwards source API compilation compatibility.

ie; sources with config(5)
options __XEN_INTERFACE_VERSION__=0x00030201 # Xen 3.1 interface

should compile and run without problems.

Not that API version 0x00030201 is the lowest version we support now.
 1.48 02-Feb-2019  cherry Remove mb(), rmb() and wmb() from the kernel namespace.

These are introduced by external/bsd/common/include/asm/barrier.h

The purpose of barrier.h is to bridge the use of linux API calls
within code which uses them, such as drm code. The XEN api implicitly
uses these calls which are linuxisms within io/ring.h

This diff undos the damage.

The correct fix is to modify io/ring.h to not assume that all OSs that
XEN runs on has these functions, and to appropriately conditionally via
#ifdef __NetBSD__/#endif use the appropriate NetBSD functions. These
changes then need to be pushed upstream.
 1.47 02-Feb-2019  cherry Switch NetBSD/xen to use XEN api tag RELEASE-4.11.1

The headers for this api are in sys/external/mit/xen-include-public/dist/
 1.46 26-Oct-2018  cherry Decompose hypervisor_enable_event() into functional steps.

The hypervisor_unmask_event() step is relevant for any event.

The pirq related step is only relevant for pirq bound events.

Prune blanket usage of this, so that usage is semantically appropriate.
 1.45 23-Sep-2018  cherry Encapsulate pre-processing of registered (pirq,evtchn) pair in
preparation for API reorg.
 1.44 14-Jun-2014  pgoyette branches: 1.44.26; 1.44.28;
Define a macro to check hypervisor version. OK cherry@
 1.43 13-Jan-2013  bouyer branches: 1.43.10;
Re-apply
http://mail-index.netbsd.org/source-changes/2012/11/25/msg039125.html
http://mail-index.netbsd.org/source-changes/2012/11/25/msg039126.html
they're not involved in i386 domU hang shown by ATF.
 1.42 12-Jan-2013  bouyer Revert these commits from november 2012:
http://mail-index.netbsd.org/source-changes/2012/11/25/msg039125.html
http://mail-index.netbsd.org/source-changes/2012/11/25/msg039126.html
http://mail-index.netbsd.org/source-changes/2012/11/25/msg039142.html

they cause a i386PAE domU to hang while running ATF tests, as shown in
http://www-soc.lip6.fr/~bouyer/NetBSD-tests/xen/HEAD/

(we should pay more attention to test results, myself first).
 1.41 12-Jan-2013  bouyer Back out this commit:
http://mail-index.netbsd.org/source-changes/2012/12/28/msg039950.html
which cause a panic when running tests on amd64, as shown on:
http://www-soc.lip6.fr/~bouyer/NetBSD-tests/xen/HEAD/
(i386 hangs for unrelated reasons).
 1.40 28-Dec-2012  cherry Simplify the xen event handler callback by:
- moving the interrupt handler callback traversal into a separate
function.
- using evt_iterate_bits() to scan through the pending bitfield
- removing cross-cpu pending actions - events recieved on the wrong
vcpu are re-routed via hypervisor_send_event().
- simplifying nested while() loops by encapsulating them in
equivalent functions.

Many thanks for multiple reviews by bouyer@ and jym@
 1.39 25-Nov-2012  cherry Make hypervisor_set_ipending() and its consumers cpu unaware. This syncs syntax with semantics
 1.38 17-Feb-2012  bouyer branches: 1.38.2;
- make xen_version globally available, with macros to access major and
minor xen version.
- In xen_initclocks(), do a VCPUOP_stop_periodic_timer only for Xen 3.1
and later
Should fix PR port-xen/45961
 1.37 17-Feb-2012  bouyer Apply patch proposed in PR port-xen/45975 (this does not solve the exact
problem reported here but is part of the solution):
xen_kpm_sync() is not working as expected,
leading to races between CPUs.
1 the check (xpq_cpu != &x86_curcpu) is always false because we
have different x86_curcpu symbols with different addresses in the kernel.
Fortunably, all addresses dissaemble to the same code.
Because of this we always use the code intended for bootstrap, which doesn't
use cross-calls or lock.

2 once 1 above is fixed, xen_kpm_sync() will use xcalls to sync other CPUs,
which cause it to sleep and pmap.c doesn't like that. It triggers this
KASSERT() in pmap_unmap_ptes():
KASSERT(pmap->pm_ncsw == curlwp->l_ncsw);
3 pmap->pm_cpus is not safe for the purpose of xen_kpm_sync(), which
needs to know on which CPU a pmap is loaded *now*:
pmap->pm_cpus is cleared before cpu_load_pmap() is called to switch
to a new pmap, leaving a window where a pmap is still in a CPU's
ci_kpm_pdir but not in pm_cpus. As a virtual CPU may be preempted
by the hypervisor at any time, it can be large enough to let another
CPU free the PTP and reuse it as a normal page.

To fix 2), avoid cross-calls and IPIs completely, and instead
use a mutex to update all CPU's ci_kpm_pdir from the local CPU.
It's safe because we just need to update the table page, a tlbflush IPI will
happen later. As a side effect, we don't need a different code for bootstrap,
fixing 1). The mutex added to struct cpu needs a small headers reorganisation.

to fix 3), introduce a pm_xen_ptp_cpus which is updated from
cpu_pmap_load(), whith the ci_kpm_mtx mutex held. Checking it with
ci_kpm_mtx held will avoid overwriting the wrong pmap's ci_kpm_pdir.

While there I removed the unused pmap_is_active() function;
and added some more details to DIAGNOSTIC panics.
 1.36 07-Dec-2011  cegger branches: 1.36.2;
switch from xen3-public to xen-public.
 1.35 19-Nov-2011  cherry branches: 1.35.4;
[merging from cherry-xenmp] bring in bouyer@'s changes via:
http://mail-index.netbsd.org/source-changes/2011/10/22/msg028271.html
From the Log:
Log Message:
Various interrupt fixes, mainly:
keep a per-cpu mask of enabled events, and use it to get pending events.
A cpu-specific event (all of them at this time) should not be ever masked
by another CPU, because it may prevent the target CPU from seeing it
(the clock events all fires at once for example).
 1.34 06-Nov-2011  cherry [merging from cherry-xenmp] Make the xen MMU op queue locking api private. Implement per-cpu queues.
 1.33 20-Sep-2011  jym branches: 1.33.2;
Merge jym-xensuspend branch in -current. ok bouyer@.

Goal: save/restore support in NetBSD domUs, for i386, i386 PAE and amd64.

Executive summary:
- split all Xen drivers (xenbus(4), grant tables, xbd(4), xennet(4))
in two parts: suspend and resume, and hook them to pmf(9).
- modify pmap so that Xen hypervisor does not cry out loud in case
it finds "unexpected" recursive memory mappings
- provide a sysctl(7), machdep.xen.suspend, to command suspend from
userland via powerd(8). Note: a suspend can only be handled correctly
when dom0 requested it, so provide a mechanism that will prevent
kernel to blindly validate user's commands

The code is still in experimental state, use at your own risk: restore
can corrupt backend communications rings; this can completely thrash
dom0 as it will loop at a high interrupt level trying to honor
all domU requests.

XXX PAE suspend does not work in amd64 currently, due to (yet again!)
page validation issues with hypervisor. Will fix.

XXX secondary CPUs are not suspended, I will write the handlers
in sync with cherry's Xen MP work.

Tested under i386 and amd64, bear in mind ring corruption though.

No build break expected, GENERICs and XEN* kernels should be fine.
./build.sh distribution still running. In any case: sorry if it does
break for you, contact me directly for reports.
 1.32 10-Aug-2011  cherry refactor the bitstring/mask operations to be behind an API. Make pending interrupt marking cpu aware.
 1.31 19-Oct-2009  bouyer branches: 1.31.10;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.30 29-Jul-2009  cegger remove Xen2 support.
ok bouyer@
 1.29 13-Nov-2008  cegger branches: 1.29.4;
Finish preparation to new interface.
New interface not yet used by default. It needs some testing first.
 1.28 13-Nov-2008  cegger prepare move to new interface
 1.27 16-Sep-2008  bouyer branches: 1.27.2;
Implement the arch-dependent p2m frame lists list. This adds support for
'xm dump-core' for NetBSD domUs.
From Jean-Yves Migeon (jean-yves dot migeon at espci dot fr)
 1.26 05-Sep-2008  tron Compile NetBSD/amd64 kernels with "-Wextra". Patches contributed by
Juan RP in PR port-amd64/39266.
 1.25 14-Apr-2008  cegger branches: 1.25.4; 1.25.6; 1.25.10;
- use POSIX integer types
- ansify functions
 1.24 22-Nov-2007  bouyer branches: 1.24.14;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.23 17-Oct-2006  bouyer branches: 1.23.8; 1.23.26; 1.23.28; 1.23.32; 1.23.34;
XEN_NO_HYPERCALLPAGE is redundant with XEN_COMPAT_030001; make
XEN_COMPAT_030001 disable the hypercall page too and remove
XEN_NO_HYPERCALLPAGE
 1.22 24-Sep-2006  bouyer The Xen folks says everyone should use hypercall call page now, make it so.
Old hypercall call method still still available with
options XEN_NO_HYPERCALLPAGE
but this is disabled by default (xen-3.0.2-2 supports hypercall call page
just fine).
While there add a VIRT_BASE= string in __xen_guest section; from
Bastian Blank on port-xen@.
 1.21 24-Sep-2006  bouyer Factor out some hypercall code in macros, so that it's easier to change
the way hypercalls are called.
 1.20 06-Mar-2006  bouyer branches: 1.20.12; 1.20.14;
Correct arguments for __HYPERVISOR_set_timer_op
 1.19 16-Feb-2006  perry branches: 1.19.2;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.18 15-Jan-2006  bouyer branches: 1.18.2; 1.18.4;
Snapshot of work in progress on NetBSD port to Xen3:
- kernel (both dom0 and domU) boot, console is functionnal and it can starts
software from a ramdisk
- there is no driver front-end expect console for domU yet.
- dom0 can probe devices and ex(4) work when Xen3 is booted without acpi
and apic support. But the on-board IDE doens't get interrupts.
The PCI code still needs work (it's hardcoded to mode 1). Some of this
code should be shared with ../x86
The physical insterrupt code needs to get MPBIOS and ACPI support, and
do interrupt routing to properly interract with Xen.
To enable Xen-3.0 support, add
options XEN3
to your kernel config file (this will disable Xen2 support)
Changes affecting Xen-2.0 support (no functionnal changes intended):
- get more constants from genassym for assembly code
- remove some unneeded registers move from start()
- map the shared info page from start(), and remove the pte = 0xffffffff hack
- vector.S: in hypervisor_callback() make sure %esi points to
HYPERVISOR_shared_info before accessing the info page. Remplace some
hand-written assembly with the equivalent macro defined in frameasm.h
- more debug code, dissabled by default.

while here added my copyright on some files I worked on in 2005.
 1.17 24-Dec-2005  perry branches: 1.17.2;
__asm__ -> __asm
__const__ -> const
__inline__ -> inline
__volatile__ -> volatile
 1.16 11-Dec-2005  christos merge ktrace-lwp.
 1.15 20-Sep-2005  bouyer inline 2 trivial functions that are called often (according to profiling
data).
 1.14 11-May-2005  yamt branches: 1.14.2;
add no_instrument_function attribute to hypervisor_force_callback
because it's used from mcount. kernel profiling now works.
 1.13 20-Apr-2005  bouyer Event handling optimisations:
- sort the ih_evt_handler list by IPL, higher first. Otherwise some handlers
would have been delayed, event if they could run at the current IPL.
- As ih_evt_handler is sorted, remove IPLs that have been processed for
an event when calling hypervisor_set_ipending()
- In hypervisor_set_ipending(), enter the event in ipl_evt_mask only
for the lowest IPL. As deffered IPLs are processed high to low,
this ensure that hypervisor_enable_event() will be called only when all
callbacks have been called for an event. We don't need the evtch_maskcount[]
counters any more.

Thanks to YAMAMOTO Takashi for ideas and feedback.
 1.12 16-Apr-2005  bouyer Remove functions that just call another one.
Inline a function used at only one place.
 1.11 16-Apr-2005  bouyer Get rid of the event to pseudo-irq mapping. We are limited to 32 pseudo-irq,
including soft interrupt, and this is way too low in some use (lots of domains,
or domains with lots of xennet, or even hardware with lots of devices at
different interrupts).
Based on idea from YAMAMOTO Takashi, keep one list of handler per-event and
one per-IPL (so the same handler is now in 2 lists). In the common case were
an event is received at low IPL, we can call the handlers quickly (there
is usually only one handler per event, unless the event is mapped to a
physical interrupt and this interrupt is shared by different devices).
Deffered events and software interrupts are handled by a bitmask (as before)
with one bit per IPL. When one IPL has an event pending all handlers for
this IPL will be called.
With this change, it is now possible to have all the 1024 events active.

While here, handle debug event in a special way: the handler is always called,
regardless of the current IPL. Make the handler print usefull informations
about events and IPL states.
Also remove code not used on Xen in files inherited from the x86 port.
 1.10 09-Mar-2005  bouyer branches: 1.10.2;
Merge the bouyer-xen2 branch. This add supports for the Xen 2.0 virtual
machine kernel (both privileged and non-privileged domains), and remove support
for the old xen 1.2.
 1.9 10-Dec-2004  christos branches: 1.9.2; 1.9.4; 1.9.6;
Just when I thought it was all working... Unfortunately cpu.h defines
clockframe -> intrframe, but that is included too late, because this
file includes systm.h and it is in the path of including systm.h. Fix
it by not including <systm.h>; it was only needed for the panic() calls
which I have disabled, since they look more like debugging calls to me.
Also add forward struct declaration for trapframe.
 1.8 14-Jun-2004  cl branches: 1.8.2;
cleanup low-level bit mangling code
 1.7 26-Apr-2004  cl Rework the physical<->machine memory mapping: offset physical addresses
by 0x100000 (above the I/O Memory "hole") leaving all physical addresses
below unused, don't perform phys<->mach mapping for addresses below 0x100000
or beyond the real hardware's physical memory.

-> /dev/mem works now as expected and X works in domain0.
 1.6 25-Apr-2004  cl Add memory barriers.
 1.5 24-Apr-2004  cl Consistently use xencons for eveything reffering to Xen's virtual console.

rename arch/xen/xen/console.c -> arch/xen/xen/xencons.c
 1.4 24-Apr-2004  cl Add ``hypervisor at mainbus'' and attach all devices provided by the
hypervisor to it instead of mainbus.

rename arch/xen/i386/hypervisor.c -> arch/xen/i386/hypervisor_machdep.c
 1.3 17-Apr-2004  cl - fix event dispatching for event 0
- use struct trapframe instead of struct pt_regs
 1.2 10-Apr-2004  cl - fix signatures for HYPERVISOR_stop, HYPERVISOR_dom0_op and
HYPERVISOR_block_io_op
- add error checking for HYPERVISOR_mmu_update and
HYPERVISOR_update_va_mapping
- add missing memory barriers
- initialize dom0_op->interface_version
 1.1 11-Mar-2004  cl branches: 1.1.2;
Add port to the Xen virtual machine monitor.
(see http://www.cl.cam.ac.uk/Research/SRG/netos/xen/)
 1.1.2.2 17-Jun-2004  tron Pull up revision 1.8 (requested by cl in ticket #498):
cleanup low-level bit mangling code
 1.1.2.1 22-May-2004  he Pull up revisions 1.2-1.7 (requested by cl in ticket #337):
Upgrade xen support:
- add block device driver
- network device driver bug fixes
- support for vga/keyboard/mouse
- support for domain0 operations
- fix /dev/mem and i386_iopl, reboot, event dispatch
- fix clock support, cpu speed report, lazy fpu switching
- add xen12load loader
- sys/arch/xen parts of build.sh release support
[cl, ticket #337]
 1.8.2.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.8.2.6 01-Apr-2005  skrll Sync with HEAD.
 1.8.2.5 18-Dec-2004  skrll Sync with HEAD.
 1.8.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.8.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.8.2.2 03-Aug-2004  skrll Sync with HEAD
 1.8.2.1 14-Jun-2004  skrll file hypervisor.h was added on branch ktrace-lwp on 2004-08-03 10:43:10 +0000
 1.9.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.9.4.1 29-Apr-2005  kent sync with -current
 1.9.2.3 18-Jan-2005  bouyer snapshot of work in progress on physical devices support:
- support pci at hypervisor. Attach one PCI bus for each bus returned by
PHYSDEVOP_PCI_PROBE_ROOT_BUSES (it looks like xen hides ppb bridges from
the guest OS).
- implement pci_conf_read()/pci_conf_write() using the appropriate
PHYSDEVOP_PCI_* calls.
- call PHYSDEVOP_PCI_INITIALISE_DEVICE from pci_intr_map() to make xen
do interrupts routing if needed, and map the hardware interrupt to
a xen interrupt.
- add pci and associated devices to files.xen

This is enouth to have IDE controllers work in PIO mode.
TODO: bus_dma support (currently bus_dma won't translate pseudo-physical
addresses to machine addresses), ISA support, test memory-mapped
I/O registers.
 1.9.2.2 17-Dec-2004  bouyer Merge in changes between netbsd-2-0-RELEASE and 1.9.
 1.9.2.1 13-Dec-2004  bouyer Commit files from netbsd-2.0-xen-sparse/sys/arch/xen in the Xen-2.0
distribution. These are the files modified from the 2.0 tree to get
NetBSD/xen working with Xen 2.
 1.10.2.6 07-Apr-2006  tron Apply patch (requested by bouyer in ticket #1245):
Pull up Xen3 domU support. This adds support for the Xen-3 memory bootstrap,
xenstore, and block and network device frontend. Xen-3 support is turned
on by 'options XEN3', which disable Xen-2 support.
Changes affecting non-xen3 specific code:
- xbd and xennet at hypervisor now attaches with xbd_hypervisor and
xennet_hypervisor
- x86_atomic_* renamed to xen_atomic_*
- use genassim.cf to pull in more constant from include files for assembly
- Map the shared info page from locore.S instead of the 0xffffffff hack
in xen_machdep.c
- remove some unused code
- some __asm__ __volatile__ -> __asm volatile and __inline__ -> inline
- more debug code
 1.10.2.5 05-Jan-2006  riz Pull up following revision(s) (requested by bouyer in ticket #1085):
sys/arch/xen/xen/hypervisor.c: revision 1.17
sys/arch/xen/i386/hypervisor_machdep.c: revision 1.13
sys/arch/xen/include/hypervisor.h: revision 1.15
inline 2 trivial functions that are called often (according to profiling
data).
 1.10.2.4 22-May-2005  snj Pull up revision 1.14 (requested by yamt in ticket #315):
add no_instrument_function attribute to hypervisor_force_callback
because it's used from mcount. kernel profiling now works.
 1.10.2.3 28-Apr-2005  tron Pull up revision 1.13 (requested by bouyer in ticket #192):
Event handling optimisations:
- sort the ih_evt_handler list by IPL, higher first. Otherwise some handlers
would have been delayed, event if they could run at the current IPL.
- As ih_evt_handler is sorted, remove IPLs that have been processed for
an event when calling hypervisor_set_ipending()
- In hypervisor_set_ipending(), enter the event in ipl_evt_mask only
for the lowest IPL. As deffered IPLs are processed high to low,
this ensure that hypervisor_enable_event() will be called only when all
callbacks have been called for an event. We don't need the evtch_maskcount[]
counters any more.
Thanks to YAMAMOTO Takashi for ideas and feedback.
 1.10.2.2 28-Apr-2005  tron Pull up revision 1.12 (requested by bouyer in ticket #192):
Remove functions that just call another one.
Inline a function used at only one place.
 1.10.2.1 28-Apr-2005  tron Pull up revision 1.11 (requested by bouyer in ticket #192):
Get rid of the event to pseudo-irq mapping. We are limited to 32 pseudo-irq,
including soft interrupt, and this is way too low in some use (lots of domains,
or domains with lots of xennet, or even hardware with lots of devices at
different interrupts).
Based on idea from YAMAMOTO Takashi, keep one list of handler per-event and
one per-IPL (so the same handler is now in 2 lists). In the common case were
an event is received at low IPL, we can call the handlers quickly (there
is usually only one handler per event, unless the event is mapped to a
physical interrupt and this interrupt is shared by different devices).
Deffered events and software interrupts are handled by a bitmask (as before)
with one bit per IPL. When one IPL has an event pending all handlers for
this IPL will be called.
With this change, it is now possible to have all the 1024 events active.
While here, handle debug event in a special way: the handler is always called,
regardless of the current IPL. Make the handler print usefull informations
about events and IPL states.
Also remove code not used on Xen in files inherited from the x86 port.
 1.14.2.3 07-Dec-2007  yamt sync with head
 1.14.2.2 30-Dec-2006  yamt sync with head.
 1.14.2.1 21-Jun-2006  yamt sync with head.
 1.17.2.2 18-Feb-2006  yamt sync with head.
 1.17.2.1 01-Feb-2006  yamt sync with head.
 1.18.4.1 22-Apr-2006  simonb Sync with head.
 1.18.2.1 09-Sep-2006  rpaulo sync with head
 1.19.2.1 13-Mar-2006  yamt sync with head.
 1.20.14.1 22-Oct-2006  yamt sync with head
 1.20.12.1 18-Nov-2006  ad Sync with head.
 1.23.34.1 08-Dec-2007  mjf Sync with HEAD.
 1.23.32.1 17-Oct-2007  bouyer Prepare for xenamd64:
- kill xen/i386/identcpu.c, use i386/i386/identcpu.c instead (with a few
#ifndef XEN)
- move some files that can be shared between i386 and amd64 from
xen/i386 to xen/x86 (or to xen/xen for non-cpu-specific code)
- split assembly out of xen/include/hypervisor.h to xen/include/hypercalls.h
- use <xen/...> instead of <machine/...> for cpu-independant include files.

more work needed here, i386-specific files should got out of arch/xen to
arch/xeni386, and more code shared with arch/i386.
 1.23.28.1 09-Jan-2008  matt sync with HEAD
 1.23.26.1 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.23.8.1 03-Dec-2007  ad Sync with HEAD.
 1.24.14.3 17-Jan-2009  mjf Sync with HEAD.
 1.24.14.2 28-Sep-2008  mjf Sync with HEAD.
 1.24.14.1 02-Jun-2008  mjf Sync with HEAD.
 1.25.10.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.25.10.1 19-Oct-2008  haad Sync with HEAD.
 1.25.6.2 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.25.6.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.25.4.3 11-Mar-2010  yamt sync with head
 1.25.4.2 19-Aug-2009  yamt sync with head.
 1.25.4.1 04-May-2009  yamt sync with head.
 1.27.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.29.4.4 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.29.4.3 01-Nov-2009  jym - Upgrade suspend/resume code to comply with Xen2 removal.
- Add support for PAE domUs suspend/resume.
- Fix an issue regarding initialization of the xbd ring I/O that could end
badly during resume, with invalid block operations submitted to dom0 backend.

NetBSD supports PAE under x86_32 by considering the L2 page as being
4 pages long instead of 1.

Xen validates the page types during resume. Sadly, the hypervisor handles
alternative recursive mappings (== PG/PD entries pointing to pages other
than self) inadequately, which could lead to incorrect page pinning.

As a result, the important change with this patch is to clear these alternative
mappings during suspend, and reset them back to their former self upon
resume. For PAE, approx. all 4 PDIR_SLOT_PTEs could be considered as
alternative recursive mappings.

See comments in pmap.c for further details.

Now, let the testing and bug hunting begin.
 1.29.4.2 01-Nov-2009  jym Sync with HEAD.
 1.29.4.1 09-Feb-2009  jym Initial code for xen save/restore/migrate facilities.

- split the attach code of frontends in two half: one that is only needed
during autoconf(9) attach/detach phases, and one used at each save/restore
of device state (between suspend and resume).

Applies to hypervisor, xencons, xenbus, xbd, and xennet.

- add a rwlock(9) ("ptom_lock") to protect the different parts in the kernel
that manipulate MFNs (which could change between a suspend and a resume,
without the kernel noticing it). Parts that require MFNs acquire a reader lock,
while suspend code will acquire a writer lock to ensure that no-other parts
in kernel still use MFNs.

- integrate the suspend code with sysmon.

- various things in pmap(9), and clock.

TODO:
- factorize code a bit more inside frontends drivers.
- remove all alternative recursive (APDP_PDE) mappings found in PD/PT during
suspend, as Xen does not support them.
- abstract the ptom_lock locking, it is only required when kernel preemption
is enabled, or on MP systems.

Current code works mostly. You may experience difficulties in some corner
cases (dom0 warnings about xennet interface errors, and Xen tools failing to
validate NetBSD's alternative pmaps).
 1.31.10.3 18-Sep-2011  cherry Use an IPI to re-route events to the cpu where the handler has been registered
 1.31.10.2 20-Aug-2011  cherry PAE MP support (preliminary), amd64 per-cpu L4 model redesigned, i386 pmap_pa_start/end fixup
 1.31.10.1 04-Aug-2011  cherry first cut at per-cpu event handling
 1.33.2.3 16-Jan-2013  yamt sync with (a bit old) head
 1.33.2.2 17-Apr-2012  yamt sync with head
 1.33.2.1 10-Nov-2011  yamt sync with head
 1.35.4.1 18-Feb-2012  mrg merge to -current.
 1.36.2.2 22-Feb-2012  riz Pull up following revision(s) (requested by bouyer in ticket #29):
sys/arch/xen/x86/x86_xpmap.c: revision 1.39
sys/arch/xen/include/hypervisor.h: revision 1.37
sys/arch/xen/include/intr.h: revision 1.34
sys/arch/xen/x86/xen_ipi.c: revision 1.10
sys/arch/x86/x86/cpu.c: revision 1.97
sys/arch/x86/include/cpu.h: revision 1.48
sys/uvm/uvm_map.c: revision 1.315
sys/arch/x86/x86/pmap.c: revision 1.165
sys/arch/xen/x86/cpu.c: revision 1.81
sys/arch/x86/x86/pmap.c: revision 1.167
sys/arch/xen/x86/cpu.c: revision 1.82
sys/arch/x86/x86/pmap.c: revision 1.168
sys/arch/xen/x86/xen_pmap.c: revision 1.17
sys/uvm/uvm_km.c: revision 1.122
sys/uvm/uvm_kmguard.c: revision 1.10
sys/arch/x86/include/pmap.h: revision 1.50
Apply patch proposed in PR port-xen/45975 (this does not solve the exact
problem reported here but is part of the solution):
xen_kpm_sync() is not working as expected,
leading to races between CPUs.
1 the check (xpq_cpu != &x86_curcpu) is always false because we
have different x86_curcpu symbols with different addresses in the kernel.
Fortunably, all addresses dissaemble to the same code.
Because of this we always use the code intended for bootstrap, which doesn't
use cross-calls or lock.
2 once 1 above is fixed, xen_kpm_sync() will use xcalls to sync other CPUs,
which cause it to sleep and pmap.c doesn't like that. It triggers this
KASSERT() in pmap_unmap_ptes():
KASSERT(pmap->pm_ncsw == curlwp->l_ncsw);
3 pmap->pm_cpus is not safe for the purpose of xen_kpm_sync(), which
needs to know on which CPU a pmap is loaded *now*:
pmap->pm_cpus is cleared before cpu_load_pmap() is called to switch
to a new pmap, leaving a window where a pmap is still in a CPU's
ci_kpm_pdir but not in pm_cpus. As a virtual CPU may be preempted
by the hypervisor at any time, it can be large enough to let another
CPU free the PTP and reuse it as a normal page.
To fix 2), avoid cross-calls and IPIs completely, and instead
use a mutex to update all CPU's ci_kpm_pdir from the local CPU.
It's safe because we just need to update the table page, a tlbflush IPI will
happen later. As a side effect, we don't need a different code for bootstrap,
fixing 1). The mutex added to struct cpu needs a small headers reorganisation.
to fix 3), introduce a pm_xen_ptp_cpus which is updated from
cpu_pmap_load(), whith the ci_kpm_mtx mutex held. Checking it with
ci_kpm_mtx held will avoid overwriting the wrong pmap's ci_kpm_pdir.
While there I removed the unused pmap_is_active() function;
and added some more details to DIAGNOSTIC panics.
When using uvm_km_pgremove_intrsafe() make sure mappings are removed
before returning the pages to the free pool. Otherwise, under Xen,
a page which still has a writable mapping could be allocated for
a PDP by another CPU and the hypervisor would refuse it (this is
PR port-xen/45975).
For this, move the pmap_kremove() calls inside uvm_km_pgremove_intrsafe(),
and do pmap_kremove()/uvm_pagefree() in batch of (at most) 16 entries
(as suggested by Chuck Silvers on tech-kern@, see also
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012727.html and
followups).
Avoid early use of xen_kpm_sync(); locks are not available at this time.
Don't call cpu_init() twice.
Makes LOCKDEBUG kernels boot again
Revert pmap_pte_flush() -> xpq_flush_queue() in previous.
 1.36.2.1 22-Feb-2012  riz Pull up following revision(s) (requested by bouyer in ticket #28):
sys/arch/xen/include/hypervisor.h: revision 1.38
sys/arch/xen/xen/hypervisor.c: revision 1.61
sys/arch/xen/xen/clock.c: revision 1.62
- make xen_version globally available, with macros to access major and
minor xen version.
- In xen_initclocks(), do a VCPUOP_stop_periodic_timer only for Xen 3.1
and later
Should fix PR port-xen/45961
- make xen_version globally available, with macros to access major and
minor xen version.
- In xen_initclocks(), do a VCPUOP_stop_periodic_timer only for Xen 3.1
and later
Should fix PR port-xen/45961
 1.38.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.38.2.1 25-Feb-2013  tls resync with head
 1.43.10.1 10-Aug-2014  tls Rebase.
 1.44.28.1 10-Jun-2019  christos Sync with HEAD
 1.44.26.2 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.44.26.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.49.10.4 25-Apr-2020  bouyer Sync with bouyer-xenpvh-base2 (HEAD)
 1.49.10.3 18-Apr-2020  bouyer Add PVHVM multiprocessor support:
We need the hypervisor to be set up before cpus attaches.
Move hypervisor setup to a new function xen_hvm_init(), called at the
beggining of mainbus_attach(). This function searches the cfdata[] array
to see if the hypervisor device is enabled (so you can disable PV
support with
disable hypervisor
from userconf).
For HVM, ci_cpuid doens't match the virtual CPU index needed by Xen.
Introduce ci_vcpuid to cpu_info. Introduce xen_hvm_init_cpu(), to be
called for each CPU in in its context, which initialize ci_vcpuid and
ci_vcpu, and setup the event callback.
Change Xen code to use ci_vcpuid.

Do not call lapic_calibrate_timer() for VM_GUEST_XENPVHVM, we will use
Xen timers.

Don't call lapic_initclocks() from cpu_hatch(); instead set
x86_cpu_initclock_func to lapic_initclocks() in lapic_calibrate_timer(),
and call *(x86_cpu_initclock_func)() from cpu_hatch().
Also call x86_cpu_initclock_func from cpu_attach() for the boot CPU.
As x86_cpu_initclock_func is called for all CPUs, x86_initclock_func can
be a NOP for lapic timer.

Reorganize Xen code for x86_initclock_func/x86_cpu_initclock_func.
Move x86_cpu_idle_xen() to hypervisor_machdep.c
 1.49.10.2 16-Apr-2020  bouyer Reorganise sources to make it possible to include Xen PVHVM support in
native kernels. Among others:
- move xen/include/amd64/hypercall.h to amd64/include/xen and
xen/include/i386/hypercall.h to i386/include/xen
- exclude some native files from the build for xenpv
- add xen to "machine" config statement for amd64 and i386
- split arch/xen/conf/files.xen to arch/xen/conf/files.xen (for pv drivers)
and arch/xen/conf/files.xen.pv (for full pv support)
- add GENERIC_XENHVM kernel config which includes GENERIC and add Xen PV
drivers.
 1.49.10.1 12-Apr-2020  bouyer Get rid of xen-specific ci_x* interrupt handling:
- use the general SIR mechanism, reserving 3 more slots for IPL_VM, IPL_SCHED
and IPL_HIGH
- remove specific handling from C sources, or change to ipending
- convert IPL number to SIR number in various places
- Remove XUNMASK/XPENDING in assembly or change to IUNMASK/IPENDING
- remove Xen-specific ci_xsources, ci_xmask, ci_xunmask, ci_xpending from
struct cpu_info
- for now remove a KASSERT that there are no pending interrupts in
idle_block(). We can get there with some software interrupts pending
in autoconf XXX needs to be looked at.
 1.55.4.4 20-Jul-2024  martin Pull up following revision(s) (requested by riastradh in ticket #764):

common/lib/libc/arch/i386/atomic/atomic.S: revision 1.37
sys/arch/xen/include/xenring.h: revision 1.8
sys/arch/i386/i386/cpufunc.S: revision 1.52
sys/arch/amd64/amd64/cpufunc.S: revision 1.68
sys/arch/xen/include/hypervisor.h: revision 1.60
common/lib/libc/arch/x86_64/atomic/atomic.S: revision 1.30

xen: Don't hotpatch away LOCK prefix in xen_mb, even on UP boots.

Both xen_mb and membar_sync are designed to provide store-before-load
ordering, but xen_mb has to provide it in synchronizing guest with
hypervisor, while membar_sync only has to provide it in synchronizing
one (guest) CPU with another (guest) CPU.

It is safe to hotpatch away the LOCK prefix in membar_sync on a
uniprocessor boot because membar_sync is only designed to coordinate
between normal memory on multiple CPUs, and is never necessary when
there's only one CPU involved.

But xen_mb is used to coordinate between the guest and the `device'
implemented by a hypervisor, which might be running on another
_physical_ CPU even if the NetBSD guest only sees one `CPU', i.e.,
one _virtual_ CPU. So even on `uniprocessor' boots, xen_mb must
still issue an instruction with store-before-load ordering on
multiprocessor systems, such as a LOCK ADD (or MFENCE, but MFENCE is
costlier for no benefit here).

No need to change xen_wmb (release ordering, load/store-before-store)
or xen_rmb (acquire ordering, load-before-load/store) because every
x86 store is a store-release and every x86 load is a load-acquire,
even on multiprocessor systems, so there's no hotpatching involved
anyway.

PR kern/57199
 1.55.4.3 18-Oct-2023  martin Pull up following revision(s) (requested by bouyer in ticket #428):

sys/arch/xen/xen/xen_machdep.c: revision 1.28
sys/arch/x86/pci/pci_machdep.c: revision 1.97
sys/arch/xen/xen/genfb_xen.c: revision 1.1
sys/arch/xen/xen/genfb_xen.c: revision 1.2
sys/arch/xen/include/hypervisor.h: revision 1.59
sys/arch/i386/conf/XEN3PAE_DOM0: revision 1.41 (patch)
sys/arch/x86/x86/genfb_machdep.c: revision 1.22
sys/arch/xen/x86/consinit.c: revision 1.18
sys/arch/xen/x86/autoconf.c: revision 1.26
sys/external/mit/xen-include-public/dist/xen/include/public/platform.h: revision 1.2
sys/arch/xen/conf/files.xen: revision 1.188
sys/arch/x86/x86/consinit.c: revision 1.37
sys/arch/xen/conf/files.xen: revision 1.189
sys/arch/x86/x86/consinit.c: revision 1.38
sys/external/mit/xen-include-public/dist/xen/include/public/xen.h: revision 1.2
sys/arch/x86/include/genfb_machdep.h: revision 1.7
sys/arch/xen/x86/pvh_consinit.c: revision 1.5
sys/arch/xen/x86/pvh_consinit.c: revision 1.6
sys/arch/amd64/conf/XEN3_DOM0: revision 1.201

Move the pvh_xencons so xen_machdep.c as early_xencons, so it can be
used in the future as early ouput for plain PV guests too.

Support non-VGA framebuffers for Xen dom0. This is mandatory for graphic
console on EFI-only hardware.

Add a xen_genfb_getbtinfo() function which will return a btinfo_framebuffer
structure, filled in with parameters provided by Xen

when runing as a Xen dom0, call xen_genfb_getbtinfo() instead of
lookup_bootinfo(BTINFO_FRAMEBUFFER) when adding properties to the
PCI graphic device (when genfb is attached) and in x86_genfb_init()
when genfb is used as console.

x86/x86/consinit.c: If running as a Xen dom0, use xen_genfb_getbtinfo()
to check if we have a genfb console

xen/x86/consinit.c: support genfb as possible console

xen/x86/consinit.c: use the hypervior IO as console until a better one
is found. If the hypervisor is using a serial port for boot messages,
we'll get NetBSD's boot message on the serial port too until
the real console takes over.

xen/x86/autoconf.c: rework device_register() to be closer to the x86 version.
Especially make sure that device_pci_register() is called.

Make sure to always fall back to xen_early_console, even for dom0

Enable genfb in DOM0 kernels

Add ext_lfb_base to dom0_vga_console_info, from recent Xen. We know if it's
present or not by checking dom0.info_size

Add XENPF_get_dom0_console, which gets a dom0_vga_console_info stucture
from the hypervisor. To be used by PVH dom0 kernels.

XENPVH option is not used. Fix consinit.c to use XENPVHVM as intended
and XENPVH from defflag
for a dom0 PVH, the dom0_vga_console_info structure has to be retrieved
using a platform hypercall; do so in the XENPVHVM case.

Now genfb works in a PVH dom0 running on Xen 4.18 (Xen 4.15 doesn't support
this platoform op, so no way to make it work here).
 1.55.4.2 18-Oct-2023  martin Pull up following revision(s) (requested by bouyer in ticket #427):

sys/arch/xen/include/hypervisor.h: revision 1.58
sys/arch/i386/i386/locore.S: revision 1.197
sys/arch/amd64/amd64/locore.S: revision 1.224

Xen's start_info_t is larger than 512 bytes these days, so bump the copy
size to a whole PAGE_SIZE, and CTASSERT() that start_info_t is smaller.

Luckily we didn't use yet the parts skipped
 1.55.4.1 31-Jul-2023  martin Pull up following revision(s) (requested by riastradh in ticket #268):

sys/arch/xen/xenbus/xenbus_comms.c: revision 1.25
sys/arch/xen/xenbus/xenbus_comms.c: revision 1.26
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.110
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.111
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.112
sys/arch/xen/x86/cpu.c: revision 1.144
sys/arch/xen/x86/cpu.c: revision 1.145
sys/arch/xen/include/hypervisor.h: revision 1.56
sys/arch/xen/include/hypervisor.h: revision 1.57
sys/arch/xen/xen/xbdback_xenbus.c: revision 1.102
sys/arch/xen/xen/xbdback_xenbus.c: revision 1.103
sys/arch/xen/include/xenring.h: revision 1.7
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.109
sys/arch/xen/xen/xengnt.c: revision 1.40
sys/arch/xen/xen/xengnt.c: revision 1.41
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.129
sys/arch/xen/xen/xencons.c: revision 1.51
sys/arch/xen/xen/xencons.c: revision 1.52
sys/arch/xen/xen/xencons.c: revision 1.53
sys/arch/xen/xen/xbd_xenbus.c: revision 1.130 (patch)
sys/arch/xen/xen/xbd_xenbus.c: revision 1.131 (patch)

xen: Fix sense of xen_rmb/wmb to make sense.

Use membar_acquire and membar_release, not membar_consumer and
membar_producer, out of paranoia -- that better matches Linux's
rmb/wmb (at least for non-I/O loads and stores).

Proposed on port-xen:
https://mail-index.netbsd.org/port-xen/2022/07/13/msg010248.html

xen/x86/cpu.c: Membar audit.

I see no reason for store-before-load ordering here; as far as I'm
aware, evtchn_upcall_mask is only shared between a (v)CPU and its
(hypervisor) interrupts, not other (v)CPUs.

xennet(4): Membar audit.
- xennet_tx_complete: Other side owns rsp_prod, giving us responses
to tx commands. We own rsp_cons, recording which responess we've
processed already.
1. Other side initializes responses before advancing rsp_prod, so
we must observe rsp_prod before trying to examine the responses.
Hence load from rsp_prod must be followed by xen_rmb.
(Can this just use atomic_load_acquire?)
2. As soon as other side observes rsp_event, it may start to
overwrite now-unused response slots, so we must finish using the
response before advancing rsp_cons. Hence we must issue xen_wmb
before store to rsp_event.
(Can this just use atomic_store_release?)
(Should this use RING_FINAL_CHECK_FOR_RESPONSES?)
3. When loop is done and we set rsp_event, we must ensure the other
side has had a chance to see that we want more before we check
whether there is more to consume; otherwise the other side might
not bother to send us an interrupt. Hence after setting
rsp_event, we must issue xen_mb (store-before-load) before
re-checking rsp_prod.
- xennet_handler (rx): Same deal, except the xen_mb is buried in
RING_FINAL_CHECK_FOR_RESPONSES. Unclear why xennet_tx_complete has
this open-coded while xennet_handler (rx) uses the macro.

xbd(4): Membar audit.
After consuming slots, must issue xen_wmb before notifying the other
side that we've consumed them in RING_FINAL_CHECK_FOR_RESPONSES.
xbdback(4): Membar audit.

After consuming request slots, must issue xen_wmb notifying the other
side that we've consumed them in RING_FINAL_CHECK_FOR_REQUESTS.

xencons(4): Membar audit.
- xenconscn_getc: Once we have consumed an input slot, it is clearer
to issue xen_wmb (release, i.e., load/store-before-store) before
advancing in_cons so that the update becomes a store-release
freeing the input slot for the other side to reuse.
- xenconscn_putc: After filling an output slot, must issue xen_wmb
(release, i.e., load/store-before-store) before advancing out_prod,
and another one before notifying the other side of the advance.

xencons(4): Reduce unnecessary membars.
- xencons_handler: After advancing in_cons, only need one xen_wmb
before notifying the hypervisor that we're ready for more.
(XXX Should this do xen_mb and re-check in_prod at that point, or
does hypervisor_notify_via_evtchn obviate the need for this?)
- xenvonscn_getc: After reading in_prod, only need one xen_rmb before
using the slots it is telling us are now ready.

xengnt(4): Membar audit.
This had the sense of membars reversed, presumably because xen_rmb
and xen_wmb had gotten reversed at some point.
xenbus_comms.c: Membar audit.

This had the sense of membars reversed, presumably because xen_rmb
and xen_wmb had gotten reversed at some point.

xennetback(4): Fix xennetback_evthandler loop.
- After observing the other side has produced pending tx requests by
reading sring->req_prod, must issue xen_rmb before touching them.
Despite all the effort to use the heavy-weight
RING_FINAL_CHECK_FOR_REQUESTS on each request in the loop, this
barrier was missing.
- No need to update req_cons at each iteration in the loop. It's
private. Just update it once at the end.
- After consuming requests, must issue xen_wmb before releasing the
slots with RING_FINAL_CHECK_FOR_REQUEST for the other side to
reuse.

xennetback(4): Fix membars in xennetback_rx_copy_process.
- No need for barrier around touching req_cons and rsp_prod_pvt,
which are private.
- RING_PUSH_RESPONSES_AND_CHECK_NOTIFY already issues xen_wmb, no
need to add one explicitly.
- After pushing responses, must issue xen_wmb (not xen_rmb) before
hypervisor_notify_via_evtchn.

xennetback(4): Omit needless membars in xennetback_connect.
xneti is a private data structure to which we have exclusive access
here; ordering the stores doesn't make sense.

xen/hypervisor.h: Nix trailing whitespace.
No functional change intended.

xen/x86/cpu.c: Nix trailing whitespace.
No functional change intended.

xbd(4): Nix trailing whitespace.

xbdback(4): Nix trailing whitespace.
No functional change intended.

xencons(4): Nix trailing whitespace.
No functional change intended.

xengnt(4): Nix trailing whitespace.
No functional change intended.

xenbus_comms.c: Nix trailing whitespace.
No functional change intended.

xennetback(4): Nix trailing whitespace.
No functional change intended.
 1.59.6.1 02-Aug-2025  perseant Sync with HEAD
 1.2 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.1 28-Sep-2006  bouyer branches: 1.1.2; 1.1.4; 1.1.8; 1.1.34; 1.1.40; 1.1.48;
Add Xen3 support for ACPI and/or MPBIOS + IOAPIC. To help with this, physical
CPUs are now configured on mainbus only in dom0, and only to know about
their APIC id. virtual CPUs are attached to hypervisor as:
vcpu* at hypervisor?
and this is what's used as curcpu(). The kernel config files needs to be
updated for this, see XEN3_DOM0 or XEN3_DOMU for examples.
XEN3_DOM0 now has acpi, MPBIOS and ioapic by default.
Note that a Xen dom0 kernel doens't have access to the lapic.
 1.1.48.1 10-Jan-2008  bouyer Change xeni386 build to match xenamd64:
- machine/ points to xen/include/i386
- remove includes that were identical to the i386/include/ ones; the build
will find them though the xen-ma/machine link.
- include xen files using xen/ not machine/
 1.1.40.1 18-Feb-2008  mjf Sync with HEAD.
 1.1.34.1 23-Mar-2008  matt sync with HEAD
 1.1.8.3 21-Jan-2008  yamt sync with head
 1.1.8.2 30-Dec-2006  yamt sync with head.
 1.1.8.1 28-Sep-2006  yamt file i82093reg.h was added on branch yamt-lazymbuf on 2006-12-30 20:47:25 +0000
 1.1.4.2 18-Nov-2006  ad Sync with head.
 1.1.4.1 28-Sep-2006  ad file i82093reg.h was added on branch newlock2 on 2006-11-18 21:29:39 +0000
 1.1.2.2 22-Oct-2006  yamt sync with head
 1.1.2.1 28-Sep-2006  yamt file i82093reg.h was added on branch yamt-splraiseipl on 2006-10-22 06:05:20 +0000
 1.7 25-Apr-2020  bouyer Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.6 21-Apr-2020  jdolecek convert to newer HYPERVISOR_physdev_op() interface, now command and the
arg are separate arguments - this is needed for newer physdev_op commands

remove code for PHYSDEVOP_IRQ_UNMASK_NOTIFY, it is obsolete since
interface version 0x00030202 and is unsupported by newer versions of Xen

confirmed working on amd64 Dom0, i386 compile-tested only
 1.5 04-Nov-2017  cherry branches: 1.5.14;
protect header against recursive include
 1.4 22-Mar-2010  cegger branches: 1.4.18;
Ignore ioapic write failures.
They happen when writing to ioapic pins Xen already disabled.
This makes netbsd dom0 booting.
 1.3 29-Jul-2009  cegger branches: 1.3.2; 1.3.4;
remove Xen2 support.
ok bouyer@
 1.2 14-Apr-2008  cegger branches: 1.2.4; 1.2.18;
- use POSIX integer types
- ansify functions
 1.1 28-Sep-2006  bouyer branches: 1.1.2; 1.1.4; 1.1.8; 1.1.58;
Add Xen3 support for ACPI and/or MPBIOS + IOAPIC. To help with this, physical
CPUs are now configured on mainbus only in dom0, and only to know about
their APIC id. virtual CPUs are attached to hypervisor as:
vcpu* at hypervisor?
and this is what's used as curcpu(). The kernel config files needs to be
updated for this, see XEN3_DOM0 or XEN3_DOMU for examples.
XEN3_DOM0 now has acpi, MPBIOS and ioapic by default.
Note that a Xen dom0 kernel doens't have access to the lapic.
 1.1.58.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.8.2 30-Dec-2006  yamt sync with head.
 1.1.8.1 28-Sep-2006  yamt file i82093var.h was added on branch yamt-lazymbuf on 2006-12-30 20:47:25 +0000
 1.1.4.2 18-Nov-2006  ad Sync with head.
 1.1.4.1 28-Sep-2006  ad file i82093var.h was added on branch newlock2 on 2006-11-18 21:29:39 +0000
 1.1.2.2 22-Oct-2006  yamt sync with head
 1.1.2.1 28-Sep-2006  yamt file i82093var.h was added on branch yamt-splraiseipl on 2006-10-22 06:05:20 +0000
 1.2.18.2 24-Oct-2010  jym Sync with HEAD
 1.2.18.1 01-Nov-2009  jym Sync with HEAD.
 1.2.4.2 11-Aug-2010  yamt sync with head.
 1.2.4.1 19-Aug-2009  yamt sync with head.
 1.3.4.1 30-May-2010  rmind sync with head
 1.3.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.4.18.1 03-Dec-2017  jdolecek update from HEAD
 1.5.14.1 25-Apr-2020  bouyer Sync with bouyer-xenpvh-base2 (HEAD)
 1.2 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.1 28-Sep-2006  bouyer branches: 1.1.2; 1.1.4; 1.1.8; 1.1.34; 1.1.40; 1.1.48;
Add Xen3 support for ACPI and/or MPBIOS + IOAPIC. To help with this, physical
CPUs are now configured on mainbus only in dom0, and only to know about
their APIC id. virtual CPUs are attached to hypervisor as:
vcpu* at hypervisor?
and this is what's used as curcpu(). The kernel config files needs to be
updated for this, see XEN3_DOM0 or XEN3_DOMU for examples.
XEN3_DOM0 now has acpi, MPBIOS and ioapic by default.
Note that a Xen dom0 kernel doens't have access to the lapic.
 1.1.48.1 10-Jan-2008  bouyer Change xeni386 build to match xenamd64:
- machine/ points to xen/include/i386
- remove includes that were identical to the i386/include/ ones; the build
will find them though the xen-ma/machine link.
- include xen files using xen/ not machine/
 1.1.40.1 18-Feb-2008  mjf Sync with HEAD.
 1.1.34.1 23-Mar-2008  matt sync with HEAD
 1.1.8.3 21-Jan-2008  yamt sync with head
 1.1.8.2 30-Dec-2006  yamt sync with head.
 1.1.8.1 28-Sep-2006  yamt file i82489reg.h was added on branch yamt-lazymbuf on 2006-12-30 20:47:25 +0000
 1.1.4.2 18-Nov-2006  ad Sync with head.
 1.1.4.1 28-Sep-2006  ad file i82489reg.h was added on branch newlock2 on 2006-11-18 21:29:39 +0000
 1.1.2.2 22-Oct-2006  yamt sync with head
 1.1.2.1 28-Sep-2006  yamt file i82489reg.h was added on branch yamt-splraiseipl on 2006-10-22 06:05:20 +0000
 1.3 16-Sep-2021  andvar fix various typos, mainly in comments.
 1.2 14-Nov-2010  bouyer Explain why we hardwire lapic_cpu_number() to 0 on Xen.
 1.1 28-Sep-2006  bouyer branches: 1.1.2; 1.1.4; 1.1.8; 1.1.76; 1.1.84;
Add Xen3 support for ACPI and/or MPBIOS + IOAPIC. To help with this, physical
CPUs are now configured on mainbus only in dom0, and only to know about
their APIC id. virtual CPUs are attached to hypervisor as:
vcpu* at hypervisor?
and this is what's used as curcpu(). The kernel config files needs to be
updated for this, see XEN3_DOM0 or XEN3_DOMU for examples.
XEN3_DOM0 now has acpi, MPBIOS and ioapic by default.
Note that a Xen dom0 kernel doens't have access to the lapic.
 1.1.84.1 05-Mar-2011  rmind sync with head
 1.1.76.1 10-Jan-2011  jym Sync with HEAD
 1.1.8.2 30-Dec-2006  yamt sync with head.
 1.1.8.1 28-Sep-2006  yamt file i82489var.h was added on branch yamt-lazymbuf on 2006-12-30 20:47:25 +0000
 1.1.4.2 18-Nov-2006  ad Sync with head.
 1.1.4.1 28-Sep-2006  ad file i82489var.h was added on branch newlock2 on 2006-11-18 21:29:39 +0000
 1.1.2.2 22-Oct-2006  yamt sync with head
 1.1.2.1 28-Sep-2006  yamt file i82489var.h was added on branch yamt-splraiseipl on 2006-10-22 06:05:20 +0000
 1.14 23-Oct-2009  snj Remove 3rd and 4th clauses. OK cl@ (copyright holder).
 1.13 16-Apr-2008  cegger branches: 1.13.4; 1.13.18;
device_t / softc split
reviewed, tested and approved by bouyer
 1.12 22-Nov-2007  bouyer branches: 1.12.14;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.11 08-Jan-2006  bouyer branches: 1.11.28; 1.11.46; 1.11.48; 1.11.52; 1.11.54;
Move if_xennet private functions and structures from if_xennetvar.h
to if_xennet.c
 1.10 11-Dec-2005  christos branches: 1.10.2;
merge ktrace-lwp.
 1.9 02-Oct-2005  bouyer Have xennet_start() schedule a software interrupt to defer processing of the
send queue. This give upper layer an opportunity to queue up all available
packets before starting to process them. This reduce the number of interrupt
generated on the backend, and the time spent doing hypercalls in a significant
way.
 1.8 11-Sep-2005  bouyer Use MCLGET() instead of local list of buffers. Garbage-collect
struct xennet_txbuf usage.
 1.7 06-Jun-2005  yamt branches: 1.7.2;
fix a typo (NETIF_TX_RING_SIZE <-> NETIF_RX_RING_SIZE)
 1.6 17-Apr-2005  bouyer Add a kernel thread to the control interface, to handle deferred callacks
(which may sleep). Fix port-xen/29851 by YAMAMOTO Takashi.
Use config_pending_incr()/config_pending_decr() in if_xennet instead of
busy-looping (which doesn't work any more).
Remove the kernel thread from xbd, which isn't needed any more.
 1.5 16-Apr-2005  bouyer Get rid of the event to pseudo-irq mapping. We are limited to 32 pseudo-irq,
including soft interrupt, and this is way too low in some use (lots of domains,
or domains with lots of xennet, or even hardware with lots of devices at
different interrupts).
Based on idea from YAMAMOTO Takashi, keep one list of handler per-event and
one per-IPL (so the same handler is now in 2 lists). In the common case were
an event is received at low IPL, we can call the handlers quickly (there
is usually only one handler per event, unless the event is mapped to a
physical interrupt and this interrupt is shared by different devices).
Deffered events and software interrupts are handled by a bitmask (as before)
with one bit per IPL. When one IPL has an event pending all handlers for
this IPL will be called.
With this change, it is now possible to have all the 1024 events active.

While here, handle debug event in a special way: the handler is always called,
regardless of the current IPL. Make the handler print usefull informations
about events and IPL states.
Also remove code not used on Xen in files inherited from the x86 port.
 1.4 09-Mar-2005  bouyer branches: 1.4.2;
Merge the bouyer-xen2 branch. This add supports for the Xen 2.0 virtual
machine kernel (both privileged and non-privileged domains), and remove support
for the old xen 1.2.
 1.3 15-Sep-2004  tls branches: 1.3.4; 1.3.6; 1.3.8;
Actually mix samples into the kernel RNG pool. There's a buglet here: all
disk samples are reported as belonging to the first disk.
 1.2 24-Apr-2004  cl branches: 1.2.2;
Add ``hypervisor at mainbus'' and attach all devices provided by the
hypervisor to it instead of mainbus.

rename arch/xen/i386/hypervisor.c -> arch/xen/i386/hypervisor_machdep.c
 1.1 11-Mar-2004  cl branches: 1.1.2;
Add port to the Xen virtual machine monitor.
(see http://www.cl.cam.ac.uk/Research/SRG/netos/xen/)
 1.1.2.2 16-Sep-2004  jmc Pullup rev 1.3 (requested by tls in ticket #846)

Actually mix samples into the kernel RNG pool.
 1.1.2.1 22-May-2004  he Pull up revision 1.2 (requested by cl in ticket #337):
Upgrade xen support:
- add block device driver
- network device driver bug fixes
- support for vga/keyboard/mouse
- support for domain0 operations
- fix /dev/mem and i386_iopl, reboot, event dispatch
- fix clock support, cpu speed report, lazy fpu switching
- add xen12load loader
- sys/arch/xen parts of build.sh release support
[cl, ticket #337]
 1.2.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.2.5 01-Apr-2005  skrll Sync with HEAD.
 1.2.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.2.2.2 03-Aug-2004  skrll Sync with HEAD
 1.2.2.1 24-Apr-2004  skrll file if_xennetvar.h was added on branch ktrace-lwp on 2004-08-03 10:43:11 +0000
 1.3.8.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.3.6.1 29-Apr-2005  kent sync with -current
 1.3.4.1 13-Dec-2004  bouyer Commit files from netbsd-2.0-xen-sparse/sys/arch/xen in the Xen-2.0
distribution. These are the files modified from the 2.0 tree to get
NetBSD/xen working with Xen 2.
 1.4.2.6 07-Apr-2006  tron Apply patch (requested by bouyer in ticket #1245):
Pull up Xen3 domU support. This adds support for the Xen-3 memory bootstrap,
xenstore, and block and network device frontend. Xen-3 support is turned
on by 'options XEN3', which disable Xen-2 support.
Changes affecting non-xen3 specific code:
- xbd and xennet at hypervisor now attaches with xbd_hypervisor and
xennet_hypervisor
- x86_atomic_* renamed to xen_atomic_*
- use genassim.cf to pull in more constant from include files for assembly
- Map the shared info page from locore.S instead of the 0xffffffff hack
in xen_machdep.c
- remove some unused code
- some __asm__ __volatile__ -> __asm volatile and __inline__ -> inline
- more debug code
 1.4.2.5 06-Apr-2006  tron Pull up following revision(s) (requested by bouyer in ticket #1239):
sys/arch/xen/include/if_xennetvar.h: revision 1.9
sys/arch/xen/xen/if_xennet.c: revision 1.37
Have xennet_start() schedule a software interrupt to defer processing of the
send queue. This give upper layer an opportunity to queue up all available
packets before starting to process them. This reduce the number of interrupt
generated on the backend, and the time spent doing hypercalls in a significant
way.
 1.4.2.4 22-Jan-2006  tron Pull up following revision(s) (requested by bouyer in ticket #1105):
sys/arch/xen/include/if_xennetvar.h: revision 1.8
Use MCLGET() instead of local list of buffers. Garbage-collect
struct xennet_txbuf usage.
 1.4.2.3 18-Jun-2005  tron Pull up revision 1.7 (requested by yamt in ticket #471):
fix a typo (NETIF_TX_RING_SIZE <-> NETIF_RX_RING_SIZE)
 1.4.2.2 28-Apr-2005  tron Pull up revision 1.5 (requested by bouyer in ticket #192):
Get rid of the event to pseudo-irq mapping. We are limited to 32 pseudo-irq,
including soft interrupt, and this is way too low in some use (lots of domains,
or domains with lots of xennet, or even hardware with lots of devices at
different interrupts).
Based on idea from YAMAMOTO Takashi, keep one list of handler per-event and
one per-IPL (so the same handler is now in 2 lists). In the common case were
an event is received at low IPL, we can call the handlers quickly (there
is usually only one handler per event, unless the event is mapped to a
physical interrupt and this interrupt is shared by different devices).
Deffered events and software interrupts are handled by a bitmask (as before)
with one bit per IPL. When one IPL has an event pending all handlers for
this IPL will be called.
With this change, it is now possible to have all the 1024 events active.
While here, handle debug event in a special way: the handler is always called,
regardless of the current IPL. Make the handler print usefull informations
about events and IPL states.
Also remove code not used on Xen in files inherited from the x86 port.
 1.4.2.1 25-Apr-2005  tron Pull up revision 1.6 (requested by bouyer in ticket #187):
Add a kernel thread to the control interface, to handle deferred callacks
(which may sleep). Fix port-xen/29851 by YAMAMOTO Takashi.
Use config_pending_incr()/config_pending_decr() in if_xennet instead of
busy-looping (which doesn't work any more).
Remove the kernel thread from xbd, which isn't needed any more.
 1.7.2.2 07-Dec-2007  yamt sync with head
 1.7.2.1 21-Jun-2006  yamt sync with head.
 1.10.2.1 15-Jan-2006  yamt sync with head.
 1.11.54.1 08-Dec-2007  mjf Sync with HEAD.
 1.11.52.1 17-Oct-2007  bouyer Prepare for xenamd64:
- kill xen/i386/identcpu.c, use i386/i386/identcpu.c instead (with a few
#ifndef XEN)
- move some files that can be shared between i386 and amd64 from
xen/i386 to xen/x86 (or to xen/xen for non-cpu-specific code)
- split assembly out of xen/include/hypervisor.h to xen/include/hypercalls.h
- use <xen/...> instead of <machine/...> for cpu-independant include files.

more work needed here, i386-specific files should got out of arch/xen to
arch/xeni386, and more code shared with arch/i386.
 1.11.48.1 09-Jan-2008  matt sync with HEAD
 1.11.46.1 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.11.28.1 03-Dec-2007  ad Sync with HEAD.
 1.12.14.1 02-Jun-2008  mjf Sync with HEAD.
 1.13.18.1 01-Nov-2009  jym Sync with HEAD.
 1.13.4.1 11-Mar-2010  yamt sync with head
 1.61 18-Aug-2025  andvar Fix various typos, mainly in comments:
s/invaid/invalid/
s/instad/instead/
s/wich/with/
s/tranform/transform/
s/tranmist/transmit/
s/tranceiver/transceiver/
s/Tranparent/Transparent/
s/tranlated/translated/
s/tranfer/transfer/
s/tranmissions/transmissions/
s/condtions/conditions/
s/Recient/Recent/
 1.60 07-Sep-2022  knakahara NetBSD/x86: Raise the number of interrupt sources per CPU from 32 to 56.

There has been no objection for three years.
https://mail-index.netbsd.org/port-amd64/2019/09/22/msg003012.html
Implemented by nonaka@n.o, updated by me.
 1.59 23-May-2022  bouyer Work in progress on MSI/MSI-X on Xen (MSI works on my hardware, more work
needed for MSI-X):
- Xen silently rejects 32 bits writes to MSI configuration registers
(especially when setting PCI_MSI_CTL_MSI_ENABLE/PCI_MSIX_CTL_ENABLE),
it expects 16 bits writes. So introduce a pci_conf_write16(),
only available on XENPV (and working only for mode 1 without
PCI_OVERRIDE_CONF_WRITE) and use it to enable MSI or MSI-X on XENPV.
- for multi-MSI vectors, Xen allocates all of them in a single hypercall,
so it's not convenient to do it at intr_establish() time.
So do it at alloc() time and register the pirqs in the msipic structure.
xen_pic_to_gsi() now just returns the values cached in the msipic.
As a bonus, if the PHYSDEVOP_map_pirq hypercall fails we can fail
the alloc() and we don't need the xen_pci_msi*_probe() hacks.

options NO_PCI_MSI_MSIX still on by default for XEN3_DOM0.
 1.58 19-Jul-2020  jdolecek for Xen MSI, fallback to INTx when PHYSDEVOP_map_pirq fails for the device

apparently Xen requires VT-d to be enabled in BIOS for PHYSDEVOP_map_pirq
to work, this change makes it work on systems with VT-d disabled or missing

adresses the panic part of PR port-xen/55285 by Patrick Welche
 1.57 15-May-2020  jdolecek use short for irq2port[] to save memory (4KB), it only needs to store
numbers <= NR_EVENT_CHANNELS (2048)
 1.56 14-May-2020  jdolecek xen_vec_alloc() is no more
 1.55 25-Apr-2020  bouyer Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.54 21-Apr-2020  jdolecek adjust so that this at least compiles and links with __HAVE_PCI_MSI_MSIX
 1.53 23-Dec-2019  thorpej branches: 1.53.6;
Provide XEN stubs for intr_mask() / intr_unmask().
 1.52 02-Feb-2019  cherry Switch NetBSD/xen to use XEN api tag RELEASE-4.11.1

The headers for this api are in sys/external/mit/xen-include-public/dist/
 1.51 25-Dec-2018  cherry Excise XEN specific code out of x86/x86/intr.c into xen/x86/xen_intr.c

While at it, separate the source function tracking so that the interrupt
paths are truly independant.

Use weak symbol exporting to provision for future PVHVM co-existence
of both files, but with independant paths. Introduce assembler code
such that in a unified scenario, native interrupts get first priority
in spllower(), followed by XEN event callbacks. IPL management and
semantics are unchanged - native handlers and xen callbacks are
expected to maintain their ipl related semantics.

In summary, after this commit, native and XEN now have completely
unrelated interrupt handling mechanisms, including
intr_establish_xname() and assembler stubs and intr handler
management.

Happy Christmas!
 1.50 24-Dec-2018  cherry Bifurcate the interrupt establish functions between XEN and non-XEN

Thus intr_establish_xname() becomes xen_intr_establish_xname() etc.

One consequence of this is that dom0 devices expect the native
function calls to be available and we thus provide weak aliasing for
dom0 builds to succeed. XEN and non-XEN devices are distinguished by
the PIC they are established on. XEN interrupts are exclusively
established on xen_pic, while dom0 interrupts are established on
natively available PICs.

This allows us an orthogonal path to xen device management (eg:
xenstore events) in XENPVHVM, without having to worry about unifying
the vector entry paths, etc., which is quite challenging.
 1.49 10-Oct-2018  cherry Do not export the 'irq<->vector' abstraction outside of pintr.c
anymore. We now think of them as a unified thing called 'gsi',
which is generated by mpacpi/mpbios
 1.48 07-Oct-2018  cherry Switch over to a "GSI" concept for guest irqs.

On XEN there is a namespace called GSI which includes:

i) legacy_irq (0 - 16)
ii) "gsi" (16-nr_irqs_gsi)
iii) msi

We try to mirror this in guest space, but are mindful that legacy_irq
is 1:1 bound to actual hardware legacy_irq. Apart from this, XEN doesn't
really care what number scheme we use, as long as it doesn't encroach
on the MSI space, which is TBD for us.

Thus we trust the mpbios.c/mpacpi.c code to correctly map the pic,pin
tuples into the correct global gsi space, which we then register with
xen. As we now do, we allow for duplicate gsi registrations, in case
any hardware shares the same (pic,pin);

This enables us to now use the (pic,pin) tuple as the canonical reference
for device interrupt addresses, and leave any global mappings to specific
code. Thus xen_pic_to_gsi().

Note that this requires separate support for MSI, which I will get around to
once things stabilise - however the API change facilitates this nicely.

I note that the msi addroute() function does not use the "pin" parameter.
This can be made use of, to encode the gsi number, for XEN. This is however
TBD.

We further tweak the xen_vec_alloc() code to be uniform for the NIOAPICS
and other cases, and ensure that i8259.c DTRT wrt to route().

This will allow us to use pic->pic_addroute() without needing to worry about
pic specific issues.

The next step is to consolidate the pic_addroute() XEN related #ifdefs into
a -DXEN specific file, so that we don't clutter x86/ code with #ifdef XENs.

This change has functional implications, and there is likely breakage coming
especially on bespoke platforms that I haven't been able to test yet.

I am especially interested in bug reports from platforms with legacy (esp. i386)
and with multiple ioapics.
 1.47 06-Oct-2018  cherry Change the name of xen_pirq_alloc() to xen_vec_alloc() to reflect
its actual job.

The idea is that we will strip this down until it is as close to
idt_vec_alloc() as possible.
 1.46 24-Jun-2018  jdolecek branches: 1.46.2;
add support for kern.intr.list aka intrctl(8) 'list' for xen

event_set_handler() and pirq_establish() now have extra intrname
parameter; shared intr_create_intrid() is used to provide the value

xen drivers were changed to pass the specific driver instance
name as the xname, e.g. 'vcpu0 clock' instead just 'clock', or
'xencons0' instead of 'xencons'

associated evcnt is now changed to use intrname - this matches native x86
 1.45 13-Dec-2017  bouyer branches: 1.45.2;
Fixes for physical interrupts on Xen:
- do not cast int * to intr_handle_t *, they're not the same size
- legacy_irq is not always -1 for ioapic interrupts, test pic_type instead
- change irq2port[] to hold (port + 1) so that 0 is an invalid value
- add KASSERTs to make sure vect, port or irq values extracted from arrays are
valid (or that they are invalid before write)
- for the !ioapic case, we still need to do PHYSDEVOP_ASSIGN_VECTOR and
bind_pirq_to_evtch().

now XEN3_DOM0 boots again
 1.44 04-Nov-2017  cherry Retire xen/x86/intr.c and use the new xen specific glue in x86/x86/intr.c

The purpose of this change is to expose the x86/include/intr.h API
to drivers. Specifically the following functions:

void *intr_establish_xname(...);
void *intr_establish(...);
void intr_disestablish(...);

while maintaining the old API from xen/include/evtchn.h, specifically
the following functions:

int event_set_handler(...);
int event_remove_handler(...);

This is so that if things break, we can keep using the old API until
everything stabilises. This is a stepping stone towards getting the
actual XEN event callback path rework code in place - which can be
done opaquely behind the intr.h API - NetBSD/XEN specific drivers that
have been ported to the intr.h API should then work without
significant further modifications.
 1.43 04-Nov-2017  cherry On XEN dom0, the function xen/x86/intr.c:xen_intr_map() is used to map
hardware interrupts to XEN callbacks called 'events'. This function
combines both the allocation and the binding.

This change is the first part of breaking up that combination into
xen_pirq_alloc() and the binding will happen as part of the
pic_addroute() callback of a new pseudo PIC_XEN

This code will be added later on.
 1.42 16-Jul-2017  cherry branches: 1.42.2;
Unify the xen and native x86/ interrupt setup functions and
spl traversal data structures.

This is towards PVHVM.
 1.41 16-Jul-2017  cherry Remove the xen specific interrupt type for the x86 intr_handle_t
For this to work, we use the evtchn.c:get_pirq_to_evtchn() glue
function to make things easier.
 1.40 23-May-2017  nonaka x86: Add preliminary x2APIC support.

x2APIC is used only when x2APIC is enabled in BIOS/UEFI.
LAPIC ID is not supported above 256.
 1.39 17-Oct-2016  jdolecek provide stub intr xname establish for xen
 1.38 16-Oct-2016  kre This should return the amd64 build to a working state (and hopefully
i386 as well) - but this is a hideous hack, and should be reverted
as soon as a better (which means any) alternative is available.
 1.37 07-Jul-2016  msaitoh branches: 1.37.2;
KNF. Remove extra spaces. No functional change.
 1.36 27-Apr-2015  knakahara add x86 MD MSI/MSI-X support code.
 1.35 27-Dec-2012  cherry branches: 1.35.14;
Remove unused header evtchn.h from intr.h
 1.34 17-Feb-2012  bouyer branches: 1.34.2;
Apply patch proposed in PR port-xen/45975 (this does not solve the exact
problem reported here but is part of the solution):
xen_kpm_sync() is not working as expected,
leading to races between CPUs.
1 the check (xpq_cpu != &x86_curcpu) is always false because we
have different x86_curcpu symbols with different addresses in the kernel.
Fortunably, all addresses dissaemble to the same code.
Because of this we always use the code intended for bootstrap, which doesn't
use cross-calls or lock.

2 once 1 above is fixed, xen_kpm_sync() will use xcalls to sync other CPUs,
which cause it to sleep and pmap.c doesn't like that. It triggers this
KASSERT() in pmap_unmap_ptes():
KASSERT(pmap->pm_ncsw == curlwp->l_ncsw);
3 pmap->pm_cpus is not safe for the purpose of xen_kpm_sync(), which
needs to know on which CPU a pmap is loaded *now*:
pmap->pm_cpus is cleared before cpu_load_pmap() is called to switch
to a new pmap, leaving a window where a pmap is still in a CPU's
ci_kpm_pdir but not in pm_cpus. As a virtual CPU may be preempted
by the hypervisor at any time, it can be large enough to let another
CPU free the PTP and reuse it as a normal page.

To fix 2), avoid cross-calls and IPIs completely, and instead
use a mutex to update all CPU's ci_kpm_pdir from the local CPU.
It's safe because we just need to update the table page, a tlbflush IPI will
happen later. As a side effect, we don't need a different code for bootstrap,
fixing 1). The mutex added to struct cpu needs a small headers reorganisation.

to fix 3), introduce a pm_xen_ptp_cpus which is updated from
cpu_pmap_load(), whith the ci_kpm_mtx mutex held. Checking it with
ci_kpm_mtx held will avoid overwriting the wrong pmap's ci_kpm_pdir.

While there I removed the unused pmap_is_active() function;
and added some more details to DIAGNOSTIC panics.
 1.33 11-Aug-2011  cherry branches: 1.33.2; 1.33.6; 1.33.8;
Make event/interrupt handling MP aware
 1.32 10-Aug-2011  cherry xen ipi infrastructure
 1.31 29-Jul-2009  cegger branches: 1.31.10;
remove Xen2 support.
ok bouyer@
 1.30 27-Mar-2009  dyoung Explicitly #include <sys/device.h> and <sys/evcnt.h>. These files only
got the definitions they needed by chance, before.
 1.29 30-May-2008  ad branches: 1.29.6; 1.29.12;
Add a 'known_mpsafe' argument to intr_establish().
 1.28 24-May-2008  bouyer G/C dead code: remove now-unused softintr-related code.
 1.27 28-Apr-2008  martin branches: 1.27.2;
Remove clause 3 and 4 from TNF licenses
 1.26 25-Apr-2008  ad branches: 1.26.2;
Include null IPI functions if !MULTIPROCESSOR.
 1.25 19-Apr-2008  cegger Use interrupt biglock wrapper as in x86/x86/intr.c
This change is based on http://mail-index.netbsd.org/port-amd64/2004/02/22/0000.html
OK bouyer
 1.24 14-Apr-2008  cegger branches: 1.24.2;
- use POSIX integer types
- ansify functions
 1.23 19-Feb-2008  bouyer branches: 1.23.6;
The event bitmasks provided by the hypervisor are unsigned long (so 64bits
on amd64). Make sure to use the right type to store and manipulate them.
This fixes amd64, where basically any event channel > 31 was not working
(and you get there after starting/stopping a domU a few times). Things
would occasionally unwedge though the spllower() callbacks.
 1.22 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.21 26-Dec-2007  yamt - share idt entry allocation code among x86.
- introduce a function to reserve an idt entry and use it instead of
manipulating idt_allocmap directly.
- rename idt to xen_idt for amd64 xen. add missing #ifdef XEN.
 1.20 03-Dec-2007  ad branches: 1.20.2; 1.20.6;
Interrupt handling changes, in discussion since February:

- Reduce available SPL levels for hardware devices to none, vm, sched, high.
- Acquire kernel_lock only for interrupts at IPL_VM.
- Implement threaded soft interrupts.
 1.19 22-Nov-2007  bouyer Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.18 17-Oct-2007  garbled branches: 1.18.2;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.17 26-Sep-2007  ad branches: 1.17.2;
x86 changes for pcc and LKMs.

- Replace most inline assembly with proper functions. As a side effect
this reduces the size of amd64 GENERIC by about 120kB, and i386 by a
smaller amount. Nearly all of the inlines did something slow, or something
that does not need to be fast.
- Make curcpu() and curlwp functions proper, unless __GNUC__ && _KERNEL.
In that case make them inlines. Makes curlwp LKM and preemption safe.
- Make bus_space and bus_dma more LKM friendly.
- Share a few more files between the ports.
- Other minor changes.
 1.16 17-May-2007  yamt branches: 1.16.8; 1.16.10; 1.16.12;
merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.
 1.15 16-Feb-2007  ad branches: 1.15.2; 1.15.6; 1.15.8; 1.15.14;
Remove spllowersoftclock() and CLKF_BASEPRI(), and always dispatch callouts
via a soft interrupt. In the near future, softclock will be run from process
context.
 1.14 26-Dec-2006  ad Define ipl_t as uint8_t so that it can be packed into a word with a lock
byte. Ok yamt@.
 1.13 21-Dec-2006  yamt merge yamt-splraiseipl branch.

- finish implementing splraiseipl (and makeiplcookie).
http://mail-index.NetBSD.org/tech-kern/2006/07/01/0000.html
- complete workqueue(9) and fix its ipl problem, which is reported
to cause audio skipping.
- fix netbt (at least compilation problems) for some ports.
- fix PR/33218.
 1.12 28-Sep-2006  bouyer Add Xen3 support for ACPI and/or MPBIOS + IOAPIC. To help with this, physical
CPUs are now configured on mainbus only in dom0, and only to know about
their APIC id. virtual CPUs are attached to hypervisor as:
vcpu* at hypervisor?
and this is what's used as curcpu(). The kernel config files needs to be
updated for this, see XEN3_DOM0 or XEN3_DOMU for examples.
XEN3_DOM0 now has acpi, MPBIOS and ioapic by default.
Note that a Xen dom0 kernel doens't have access to the lapic.
 1.11 15-May-2006  dogcow branches: 1.11.8; 1.11.10;
For whatever reason, GCC4 really really wants extern struct decls to be
after the struct is defined.
 1.10 09-Apr-2006  bouyer Add support for ACPI in xen-3 dom0 support. We can now boot a xen-3 dom0
kernel with a default xen comamnd line.
 1.9 16-Feb-2006  perry branches: 1.9.2; 1.9.4; 1.9.6;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.8 24-Dec-2005  perry branches: 1.8.2; 1.8.4; 1.8.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.7 11-Dec-2005  christos merge ktrace-lwp.
 1.6 03-Nov-2005  yamt - use sys/spl.h.
- add some IPL_ definitions.
 1.5 29-Oct-2005  yamt add splraiseipl().
 1.4 28-Oct-2005  yamt remove duplicated spllpt().
 1.3 16-Apr-2005  bouyer branches: 1.3.2; 1.3.4;
Get rid of the event to pseudo-irq mapping. We are limited to 32 pseudo-irq,
including soft interrupt, and this is way too low in some use (lots of domains,
or domains with lots of xennet, or even hardware with lots of devices at
different interrupts).
Based on idea from YAMAMOTO Takashi, keep one list of handler per-event and
one per-IPL (so the same handler is now in 2 lists). In the common case were
an event is received at low IPL, we can call the handlers quickly (there
is usually only one handler per event, unless the event is mapped to a
physical interrupt and this interrupt is shared by different devices).
Deffered events and software interrupts are handled by a bitmask (as before)
with one bit per IPL. When one IPL has an event pending all handlers for
this IPL will be called.
With this change, it is now possible to have all the 1024 events active.

While here, handle debug event in a special way: the handler is always called,
regardless of the current IPL. Make the handler print usefull informations
about events and IPL states.
Also remove code not used on Xen in files inherited from the x86 port.
 1.2 11-Apr-2005  yamt fix a bug which corrupts runqueue.
when dealing with events, which are handed to xenevt pseudo device,
don't call wakeup(9)/selnotify(9) at too high IPL. PR/29792.
 1.1 11-Mar-2004  cl branches: 1.1.4; 1.1.12; 1.1.18;
Add port to the Xen virtual machine monitor.
(see http://www.cl.cam.ac.uk/Research/SRG/netos/xen/)
 1.1.18.2 28-Apr-2005  tron Pull up revision 1.3 (requested by bouyer in ticket #192):
Get rid of the event to pseudo-irq mapping. We are limited to 32 pseudo-irq,
including soft interrupt, and this is way too low in some use (lots of domains,
or domains with lots of xennet, or even hardware with lots of devices at
different interrupts).
Based on idea from YAMAMOTO Takashi, keep one list of handler per-event and
one per-IPL (so the same handler is now in 2 lists). In the common case were
an event is received at low IPL, we can call the handlers quickly (there
is usually only one handler per event, unless the event is mapped to a
physical interrupt and this interrupt is shared by different devices).
Deffered events and software interrupts are handled by a bitmask (as before)
with one bit per IPL. When one IPL has an event pending all handlers for
this IPL will be called.
With this change, it is now possible to have all the 1024 events active.
While here, handle debug event in a special way: the handler is always called,
regardless of the current IPL. Make the handler print usefull informations
about events and IPL states.
Also remove code not used on Xen in files inherited from the x86 port.
 1.1.18.1 13-Apr-2005  tron Pull up revision 1.2 (requested by yamt in ticket #146):
fix a bug which corrupts runqueue.
when dealing with events, which are handed to xenevt pseudo device,
don't call wakeup(9)/selnotify(9) at too high IPL. PR/29792.
 1.1.12.1 29-Apr-2005  kent sync with -current
 1.1.4.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.4.2 03-Aug-2004  skrll Sync with HEAD
 1.1.4.1 11-Mar-2004  skrll file intr.h was added on branch ktrace-lwp on 2004-08-03 10:43:11 +0000
 1.3.4.1 02-Nov-2005  yamt sync with head.
 1.3.2.8 27-Feb-2008  yamt sync with head.
 1.3.2.7 21-Jan-2008  yamt sync with head
 1.3.2.6 07-Dec-2007  yamt sync with head
 1.3.2.5 27-Oct-2007  yamt sync with head.
 1.3.2.4 03-Sep-2007  yamt sync with head.
 1.3.2.3 26-Feb-2007  yamt sync with head.
 1.3.2.2 30-Dec-2006  yamt sync with head.
 1.3.2.1 21-Jun-2006  yamt sync with head.
 1.8.6.2 01-Jun-2006  kardel Sync with head.
 1.8.6.1 22-Apr-2006  simonb Sync with head.
 1.8.4.1 09-Sep-2006  rpaulo sync with head
 1.8.2.1 18-Feb-2006  yamt sync with head.
 1.9.6.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.9.4.1 19-Apr-2006  elad sync with head - hopefully this will work
 1.9.2.2 24-May-2006  yamt sync with head.
 1.9.2.1 11-Apr-2006  yamt sync with head
 1.11.10.3 22-Oct-2006  yamt sync with head
 1.11.10.2 21-Sep-2006  yamt rename splraiseipl argument to match with the rest of ports.
 1.11.10.1 18-Sep-2006  yamt implement new api for xen.
 1.11.8.2 12-Jan-2007  ad Sync with head.
 1.11.8.1 18-Nov-2006  ad Sync with head.
 1.15.14.2 03-Oct-2007  garbled Sync with HEAD
 1.15.14.1 22-May-2007  matt Update to HEAD.
 1.15.8.1 11-Jul-2007  mjf Sync with head.
 1.15.6.3 03-Dec-2007  ad Sync with HEAD.
 1.15.6.2 09-Oct-2007  ad Sync with head.
 1.15.6.1 27-May-2007  ad Sync with head.
 1.15.2.1 26-Mar-2007  yamt adapt xen.
 1.16.12.1 06-Oct-2007  yamt sync with head.
 1.16.10.3 23-Mar-2008  matt sync with HEAD
 1.16.10.2 09-Jan-2008  matt sync with HEAD
 1.16.10.1 06-Nov-2007  matt sync with HEAD
 1.16.8.3 09-Dec-2007  jmcneill Sync with HEAD.
 1.16.8.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.16.8.1 02-Oct-2007  joerg Sync with HEAD.
 1.17.2.1 17-Oct-2007  bouyer Prepare for xenamd64:
- kill xen/i386/identcpu.c, use i386/i386/identcpu.c instead (with a few
#ifndef XEN)
- move some files that can be shared between i386 and amd64 from
xen/i386 to xen/x86 (or to xen/xen for non-cpu-specific code)
- split assembly out of xen/include/hypervisor.h to xen/include/hypercalls.h
- use <xen/...> instead of <machine/...> for cpu-independant include files.

more work needed here, i386-specific files should got out of arch/xen to
arch/xeni386, and more code shared with arch/i386.
 1.18.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.18.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.20.6.3 06-Jan-2008  bouyer Remove unused splsoftxenevt()
 1.20.6.2 05-Jan-2008  bouyer Remove files that just include the x86 counterpart.
 1.20.6.1 02-Jan-2008  bouyer Sync with HEAD
 1.20.2.1 26-Dec-2007  ad Sync with head.
 1.23.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.24.2.2 04-Jun-2008  yamt sync with head
 1.24.2.1 18-May-2008  yamt sync with head.
 1.26.2.3 19-Aug-2009  yamt sync with head.
 1.26.2.2 04-May-2009  yamt sync with head.
 1.26.2.1 16-May-2008  yamt sync with head.
 1.27.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.29.12.3 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.29.12.2 01-Nov-2009  jym Sync with HEAD.
 1.29.12.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.29.6.1 28-Apr-2009  skrll Sync with HEAD.
 1.31.10.4 17-Aug-2011  cherry Pullup relevant changes from -current
 1.31.10.3 04-Aug-2011  cherry first cut at per-cpu event handling
 1.31.10.2 26-Jun-2011  cherry Unbreak uniprocessor build
 1.31.10.1 03-Jun-2011  cherry Initial import of xen MP sources, with kernel and userspace tests.
- this is a source priview.
- boots to single user.
- spurious interrupt and pmap related panics are normal
 1.33.8.1 22-Feb-2012  riz Pull up following revision(s) (requested by bouyer in ticket #29):
sys/arch/xen/x86/x86_xpmap.c: revision 1.39
sys/arch/xen/include/hypervisor.h: revision 1.37
sys/arch/xen/include/intr.h: revision 1.34
sys/arch/xen/x86/xen_ipi.c: revision 1.10
sys/arch/x86/x86/cpu.c: revision 1.97
sys/arch/x86/include/cpu.h: revision 1.48
sys/uvm/uvm_map.c: revision 1.315
sys/arch/x86/x86/pmap.c: revision 1.165
sys/arch/xen/x86/cpu.c: revision 1.81
sys/arch/x86/x86/pmap.c: revision 1.167
sys/arch/xen/x86/cpu.c: revision 1.82
sys/arch/x86/x86/pmap.c: revision 1.168
sys/arch/xen/x86/xen_pmap.c: revision 1.17
sys/uvm/uvm_km.c: revision 1.122
sys/uvm/uvm_kmguard.c: revision 1.10
sys/arch/x86/include/pmap.h: revision 1.50
Apply patch proposed in PR port-xen/45975 (this does not solve the exact
problem reported here but is part of the solution):
xen_kpm_sync() is not working as expected,
leading to races between CPUs.
1 the check (xpq_cpu != &x86_curcpu) is always false because we
have different x86_curcpu symbols with different addresses in the kernel.
Fortunably, all addresses dissaemble to the same code.
Because of this we always use the code intended for bootstrap, which doesn't
use cross-calls or lock.
2 once 1 above is fixed, xen_kpm_sync() will use xcalls to sync other CPUs,
which cause it to sleep and pmap.c doesn't like that. It triggers this
KASSERT() in pmap_unmap_ptes():
KASSERT(pmap->pm_ncsw == curlwp->l_ncsw);
3 pmap->pm_cpus is not safe for the purpose of xen_kpm_sync(), which
needs to know on which CPU a pmap is loaded *now*:
pmap->pm_cpus is cleared before cpu_load_pmap() is called to switch
to a new pmap, leaving a window where a pmap is still in a CPU's
ci_kpm_pdir but not in pm_cpus. As a virtual CPU may be preempted
by the hypervisor at any time, it can be large enough to let another
CPU free the PTP and reuse it as a normal page.
To fix 2), avoid cross-calls and IPIs completely, and instead
use a mutex to update all CPU's ci_kpm_pdir from the local CPU.
It's safe because we just need to update the table page, a tlbflush IPI will
happen later. As a side effect, we don't need a different code for bootstrap,
fixing 1). The mutex added to struct cpu needs a small headers reorganisation.
to fix 3), introduce a pm_xen_ptp_cpus which is updated from
cpu_pmap_load(), whith the ci_kpm_mtx mutex held. Checking it with
ci_kpm_mtx held will avoid overwriting the wrong pmap's ci_kpm_pdir.
While there I removed the unused pmap_is_active() function;
and added some more details to DIAGNOSTIC panics.
When using uvm_km_pgremove_intrsafe() make sure mappings are removed
before returning the pages to the free pool. Otherwise, under Xen,
a page which still has a writable mapping could be allocated for
a PDP by another CPU and the hypervisor would refuse it (this is
PR port-xen/45975).
For this, move the pmap_kremove() calls inside uvm_km_pgremove_intrsafe(),
and do pmap_kremove()/uvm_pagefree() in batch of (at most) 16 entries
(as suggested by Chuck Silvers on tech-kern@, see also
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012727.html and
followups).
Avoid early use of xen_kpm_sync(); locks are not available at this time.
Don't call cpu_init() twice.
Makes LOCKDEBUG kernels boot again
Revert pmap_pte_flush() -> xpq_flush_queue() in previous.
 1.33.6.1 18-Feb-2012  mrg merge to -current.
 1.33.2.2 23-Jan-2013  yamt sync with head
 1.33.2.1 17-Apr-2012  yamt sync with head
 1.34.2.2 03-Dec-2017  jdolecek update from HEAD
 1.34.2.1 25-Feb-2013  tls resync with head
 1.35.14.4 28-Aug-2017  skrll Sync with HEAD
 1.35.14.3 05-Dec-2016  skrll Sync with HEAD
 1.35.14.2 09-Jul-2016  skrll Sync with HEAD
 1.35.14.1 06-Jun-2015  skrll Sync with HEAD
 1.37.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.42.2.2 16-Jul-2017  cherry 2302677
 1.42.2.1 16-Jul-2017  cherry file intr.h was added on branch perseant-stdc-iso10646 on 2017-07-16 14:02:49 +0000
 1.45.2.3 26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.45.2.2 20-Oct-2018  pgoyette Sync with head
 1.45.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.46.2.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.46.2.1 10-Jun-2019  christos Sync with HEAD
 1.53.6.4 25-Apr-2020  bouyer Sync with bouyer-xenpvh-base2 (HEAD)
 1.53.6.3 19-Apr-2020  bouyer Add per-PIC callbacks for interrupt_get_devname(), interrupt_get_assigned()
and interrupt_get_count(). Implement Xen-specific callbacks for
PIC_XEN and use the x86 one for others.
In event_set_handler(), call intr_allocate_io_intrsource() so that
events appears in interrupt list (intrctl list).
 1.53.6.2 16-Apr-2020  bouyer Reorganise sources to make it possible to include Xen PVHVM support in
native kernels. Among others:
- move xen/include/amd64/hypercall.h to amd64/include/xen and
xen/include/i386/hypercall.h to i386/include/xen
- exclude some native files from the build for xenpv
- add xen to "machine" config statement for amd64 and i386
- split arch/xen/conf/files.xen to arch/xen/conf/files.xen (for pv drivers)
and arch/xen/conf/files.xen.pv (for full pv support)
- add GENERIC_XENHVM kernel config which includes GENERIC and add Xen PV
drivers.
 1.53.6.1 12-Apr-2020  bouyer Get rid of xen-specific ci_x* interrupt handling:
- use the general SIR mechanism, reserving 3 more slots for IPL_VM, IPL_SCHED
and IPL_HIGH
- remove specific handling from C sources, or change to ipending
- convert IPL number to SIR number in various places
- Remove XUNMASK/XPENDING in assembly or change to IUNMASK/IPENDING
- remove Xen-specific ci_xsources, ci_xmask, ci_xunmask, ci_xpending from
struct cpu_info
- for now remove a KASSERT that there are no pending interrupts in
idle_block(). We can get there with some software interrupts pending
in autoconf XXX needs to be looked at.
 1.17 25-Apr-2020  bouyer Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.16 21-Apr-2020  ad XEN_IPI_KICK was replaced by XEN_IPI_AST.
 1.15 03-Apr-2020  ad branches: 1.15.2;
Attach xen IPI event counters.
 1.14 23-Nov-2019  ad cpu_need_resched():

- Remove all code that should be MI, leaving the bare minimum under arch/.
- Make the required actions very explicit.
- Pass in LWP pointer for convenience.
- When a trap is required on another CPU, have the IPI set it locally.
- Expunge cpu_did_resched().
 1.13 10-Sep-2018  cherry Make the use of 'irqs' in the range 0 < irq < 255 by xen
as a handle for internal use explicit.

This allows us to pass up the handle as "legacy" irq while
establishing interrupt handlers for xen.

No functional change.
 1.12 19-May-2014  rmind branches: 1.12.26; 1.12.28;
Implement MI IPI interface with cross-call support.
 1.11 07-Nov-2011  cherry branches: 1.11.10; 1.11.24;
Add an ipi callback to force hypervisor callback. this is useful to "re-route" interrupts to a given vcpu
 1.10 10-Aug-2011  cherry branches: 1.10.2;
Add Xen specific ipi bitmasks
 1.9 11-Jan-2008  bouyer branches: 1.9.18; 1.9.34;
Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.8 03-Dec-2007  ad branches: 1.8.6;
Interrupt handling changes, in discussion since February:

- Reduce available SPL levels for hardware devices to none, vm, sched, high.
- Acquire kernel_lock only for interrupts at IPL_VM.
- Implement threaded soft interrupts.
 1.7 22-Nov-2007  bouyer Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.6 28-Sep-2006  bouyer branches: 1.6.8; 1.6.26; 1.6.28; 1.6.32; 1.6.34;
Add Xen3 support for ACPI and/or MPBIOS + IOAPIC. To help with this, physical
CPUs are now configured on mainbus only in dom0, and only to know about
their APIC id. virtual CPUs are attached to hypervisor as:
vcpu* at hypervisor?
and this is what's used as curcpu(). The kernel config files needs to be
updated for this, see XEN3_DOM0 or XEN3_DOMU for examples.
XEN3_DOM0 now has acpi, MPBIOS and ioapic by default.
Note that a Xen dom0 kernel doens't have access to the lapic.
 1.5 09-Apr-2006  bouyer branches: 1.5.8; 1.5.10;
Add support for ACPI in xen-3 dom0 support. We can now boot a xen-3 dom0
kernel with a default xen comamnd line.
 1.4 11-Dec-2005  christos branches: 1.4.4; 1.4.6; 1.4.8; 1.4.10; 1.4.12;
merge ktrace-lwp.
 1.3 03-Nov-2005  yamt branches: 1.3.2;
- use sys/spl.h.
- add some IPL_ definitions.
 1.2 20-Apr-2005  bouyer branches: 1.2.2; 1.2.4; 1.2.6;
Add polling support to the domain controller. Use this in xencons instead
of relying on the fact that the domain controller is still getting interrupts
when xenconscn_getc()/xenconscn_putc() is called.
Now that polling is fixed, move IPL_CTRL down between IPL_SOFTSERIAL and
IPL_TTY, fixing port-xen/29999 by YAMAMOTO Takashi.
Now that IPL_CTRL is low enouth, remove the softintr stuff from the
domain controller, and call wakeup() directly.

Thanks to YAMAMOTO Takashi and Christian Limpach for feedback and suggestions.
 1.1 16-Apr-2005  bouyer Get rid of the event to pseudo-irq mapping. We are limited to 32 pseudo-irq,
including soft interrupt, and this is way too low in some use (lots of domains,
or domains with lots of xennet, or even hardware with lots of devices at
different interrupts).
Based on idea from YAMAMOTO Takashi, keep one list of handler per-event and
one per-IPL (so the same handler is now in 2 lists). In the common case were
an event is received at low IPL, we can call the handlers quickly (there
is usually only one handler per event, unless the event is mapped to a
physical interrupt and this interrupt is shared by different devices).
Deffered events and software interrupts are handled by a bitmask (as before)
with one bit per IPL. When one IPL has an event pending all handlers for
this IPL will be called.
With this change, it is now possible to have all the 1024 events active.

While here, handle debug event in a special way: the handler is always called,
regardless of the current IPL. Make the handler print usefull informations
about events and IPL states.
Also remove code not used on Xen in files inherited from the x86 port.
 1.2.6.4 21-Jan-2008  yamt sync with head
 1.2.6.3 07-Dec-2007  yamt sync with head
 1.2.6.2 30-Dec-2006  yamt sync with head.
 1.2.6.1 21-Jun-2006  yamt sync with head.
 1.2.4.2 29-Apr-2005  kent sync with -current
 1.2.4.1 20-Apr-2005  kent file intrdefs.h was added on branch kent-audio2 on 2005-04-29 11:28:29 +0000
 1.2.2.3 28-Apr-2005  tron Pull up revision 1.2 (requested by bouyer in ticket #193):
Add polling support to the domain controller. Use this in xencons instead
of relying on the fact that the domain controller is still getting interrupts
when xenconscn_getc()/xenconscn_putc() is called.
Now that polling is fixed, move IPL_CTRL down between IPL_SOFTSERIAL and
IPL_TTY, fixing port-xen/29999 by YAMAMOTO Takashi.
Now that IPL_CTRL is low enouth, remove the softintr stuff from the
domain controller, and call wakeup() directly.
Thanks to YAMAMOTO Takashi and Christian Limpach for feedback and suggestions.
 1.2.2.2 28-Apr-2005  tron Pull up revision 1.1 (requested by bouyer in ticket #192):
Get rid of the event to pseudo-irq mapping. We are limited to 32 pseudo-irq,
including soft interrupt, and this is way too low in some use (lots of domains,
or domains with lots of xennet, or even hardware with lots of devices at
different interrupts).
Based on idea from YAMAMOTO Takashi, keep one list of handler per-event and
one per-IPL (so the same handler is now in 2 lists). In the common case were
an event is received at low IPL, we can call the handlers quickly (there
is usually only one handler per event, unless the event is mapped to a
physical interrupt and this interrupt is shared by different devices).
Deffered events and software interrupts are handled by a bitmask (as before)
with one bit per IPL. When one IPL has an event pending all handlers for
this IPL will be called.
With this change, it is now possible to have all the 1024 events active.
While here, handle debug event in a special way: the handler is always called,
regardless of the current IPL. Make the handler print usefull informations
about events and IPL states.
Also remove code not used on Xen in files inherited from the x86 port.
 1.2.2.1 20-Apr-2005  tron file intrdefs.h was added on branch netbsd-3 on 2005-04-28 10:20:11 +0000
 1.3.2.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.3.2.1 03-Nov-2005  skrll file intrdefs.h was added on branch ktrace-lwp on 2005-11-10 14:00:34 +0000
 1.4.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.4.10.1 19-Apr-2006  elad sync with head - hopefully this will work
 1.4.8.1 11-Apr-2006  yamt sync with head
 1.4.6.1 22-Apr-2006  simonb Sync with head.
 1.4.4.1 09-Sep-2006  rpaulo sync with head
 1.5.10.1 22-Oct-2006  yamt sync with head
 1.5.8.1 18-Nov-2006  ad Sync with head.
 1.6.34.2 18-Feb-2008  mjf Sync with HEAD.
 1.6.34.1 08-Dec-2007  mjf Sync with HEAD.
 1.6.32.2 25-Oct-2007  bouyer Finish sync with HEAD. Especially use the new x86 pmap for xenamd64.
For this:
- rename pmap_pte_set() to pmap_pte_testset()
- make pmap_pte_set() a function or macro for non-atomic PTE write
- define and use pmap_pa2pte()/pmap_pte2pa() to read/write PTE entries
- define pmap_pte_flush() which is a nop in x86 case, and flush the
MMUops queue in the Xen case
 1.6.32.1 17-Oct-2007  bouyer Prepare for xenamd64:
- kill xen/i386/identcpu.c, use i386/i386/identcpu.c instead (with a few
#ifndef XEN)
- move some files that can be shared between i386 and amd64 from
xen/i386 to xen/x86 (or to xen/xen for non-cpu-specific code)
- split assembly out of xen/include/hypervisor.h to xen/include/hypercalls.h
- use <xen/...> instead of <machine/...> for cpu-independant include files.

more work needed here, i386-specific files should got out of arch/xen to
arch/xeni386, and more code shared with arch/i386.
 1.6.28.2 23-Mar-2008  matt sync with HEAD
 1.6.28.1 09-Jan-2008  matt sync with HEAD
 1.6.26.2 09-Dec-2007  jmcneill Sync with HEAD.
 1.6.26.1 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.6.8.1 03-Dec-2007  ad Sync with HEAD.
 1.8.6.1 05-Jan-2008  bouyer Remove files that just include the x86 counterpart.
 1.9.34.3 18-Sep-2011  cherry Use an IPI to re-route events to the cpu where the handler has been registered
 1.9.34.2 03-Jun-2011  cherry Initial import of xen MP sources, with kernel and userspace tests.
- this is a source priview.
- boots to single user.
- spurious interrupt and pmap related panics are normal
 1.9.34.1 11-Jan-2008  cherry file intrdefs.h was added on branch cherry-xenmp on 2011-06-03 13:27:40 +0000
 1.9.18.1 27-Aug-2011  jym Add/remove files, like in HEAD.
 1.10.2.1 10-Nov-2011  yamt sync with head
 1.11.24.1 10-Aug-2014  tls Rebase.
 1.11.10.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.12.28.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.12.28.1 10-Jun-2019  christos Sync with HEAD
 1.12.26.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.15.2.2 25-Apr-2020  bouyer Sync with bouyer-xenpvh-base2 (HEAD)
 1.15.2.1 11-Apr-2020  bouyer Move softint and preemtion-related functions out of x86/x86/intr.c to
its own file, x86/x86/x86_softintr.c
Add x86/x86/x86_softintr.c for native and XenPV
Make sure XenPV also check ci_ioending, which is used for softints.
Switch XenPV to fast softints and allow kernel preemption.
kpreempt_disable() before calling pmap_changeprot_local()
run xen_wallclock_time() and xen_global_systime_ns() at splshed() to
avoid being interrupted.

XXX amd64 lock stubs are racy for XPENDING
 1.4 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.3 11-Dec-2005  christos branches: 1.3.50; 1.3.56; 1.3.64;
merge ktrace-lwp.
 1.2 09-Mar-2005  bouyer branches: 1.2.4; 1.2.6; 1.2.8; 1.2.10;
Merge the bouyer-xen2 branch. This add supports for the Xen 2.0 virtual
machine kernel (both privileged and non-privileged domains), and remove support
for the old xen 1.2.
 1.1 08-Mar-2005  bouyer branches: 1.1.2;
file isa_machdep.h was initially added on branch bouyer-xen2.
 1.1.2.1 08-Mar-2005  bouyer Add support for ISA bus.
Clean up console attachement, and add support for VGA/pckbc console.
Add support for USB devices, including USB audio (which means others audio
devices should work too)
Add some more generic options to XEN0.
 1.2.10.1 21-Jan-2008  yamt sync with head
 1.2.8.2 29-Apr-2005  kent sync with -current
 1.2.8.1 09-Mar-2005  kent file isa_machdep.h was added on branch kent-audio2 on 2005-04-29 11:28:29 +0000
 1.2.6.2 01-Apr-2005  skrll Sync with HEAD.
 1.2.6.1 09-Mar-2005  skrll file isa_machdep.h was added on branch ktrace-lwp on 2005-04-01 14:29:10 +0000
 1.2.4.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.4.1 09-Mar-2005  yamt file isa_machdep.h was added on branch yamt-km on 2005-03-19 08:33:26 +0000
 1.3.64.1 10-Jan-2008  bouyer Change xeni386 build to match xenamd64:
- machine/ points to xen/include/i386
- remove includes that were identical to the i386/include/ ones; the build
will find them though the xen-ma/machine link.
- include xen files using xen/ not machine/
 1.3.56.1 18-Feb-2008  mjf Sync with HEAD.
 1.3.50.1 23-Mar-2008  matt sync with HEAD
 1.3 23-Oct-2009  snj Remove 3rd and 4th clauses. OK cl@ (copyright holder).
 1.2 11-Dec-2005  christos branches: 1.2.78; 1.2.92;
merge ktrace-lwp.
 1.1 07-May-2004  cl branches: 1.1.2; 1.1.4;
Add support for domain0 operations:
- access to all physical memory
- access to hypervisor traps from userland
- setup/config Xen's network routing/firewall rules
 1.1.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.4.2 03-Aug-2004  skrll Sync with HEAD
 1.1.4.1 07-May-2004  skrll file kernfs_machdep.h was added on branch ktrace-lwp on 2004-08-03 10:43:11 +0000
 1.1.2.2 22-May-2004  he Pull up revision 1.1 (requested by cl in ticket #337):
Upgrade xen support:
- add block device driver
- network device driver bug fixes
- support for vga/keyboard/mouse
- support for domain0 operations
- fix /dev/mem and i386_iopl, reboot, event dispatch
- fix clock support, cpu speed report, lazy fpu switching
- add xen12load loader
- sys/arch/xen parts of build.sh release support
[cl, ticket #337]
 1.1.2.1 07-May-2004  he file kernfs_machdep.h was added on branch netbsd-2-0 on 2004-05-22 15:59:21 +0000
 1.2.92.1 01-Nov-2009  jym Sync with HEAD.
 1.2.78.1 11-Mar-2010  yamt sync with head
 1.2 23-May-2017  nonaka x86: Add preliminary x2APIC support.

x2APIC is used only when x2APIC is enabled in BIOS/UEFI.
LAPIC ID is not supported above 256.
 1.1 28-Sep-2006  bouyer branches: 1.1.2; 1.1.4; 1.1.8; 1.1.106; 1.1.126;
Add Xen3 support for ACPI and/or MPBIOS + IOAPIC. To help with this, physical
CPUs are now configured on mainbus only in dom0, and only to know about
their APIC id. virtual CPUs are attached to hypervisor as:
vcpu* at hypervisor?
and this is what's used as curcpu(). The kernel config files needs to be
updated for this, see XEN3_DOM0 or XEN3_DOMU for examples.
XEN3_DOM0 now has acpi, MPBIOS and ioapic by default.
Note that a Xen dom0 kernel doens't have access to the lapic.
 1.1.126.1 28-Aug-2017  skrll Sync with HEAD
 1.1.106.1 03-Dec-2017  jdolecek update from HEAD
 1.1.8.2 30-Dec-2006  yamt sync with head.
 1.1.8.1 28-Sep-2006  yamt file mpacpi.h was added on branch yamt-lazymbuf on 2006-12-30 20:47:25 +0000
 1.1.4.2 18-Nov-2006  ad Sync with head.
 1.1.4.1 28-Sep-2006  ad file mpacpi.h was added on branch newlock2 on 2006-11-18 21:29:39 +0000
 1.1.2.2 22-Oct-2006  yamt sync with head
 1.1.2.1 28-Sep-2006  yamt file mpacpi.h was added on branch yamt-splraiseipl on 2006-10-22 06:05:20 +0000
 1.2 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.1 28-Sep-2006  bouyer branches: 1.1.2; 1.1.4; 1.1.8; 1.1.34; 1.1.40; 1.1.48;
Add Xen3 support for ACPI and/or MPBIOS + IOAPIC. To help with this, physical
CPUs are now configured on mainbus only in dom0, and only to know about
their APIC id. virtual CPUs are attached to hypervisor as:
vcpu* at hypervisor?
and this is what's used as curcpu(). The kernel config files needs to be
updated for this, see XEN3_DOM0 or XEN3_DOMU for examples.
XEN3_DOM0 now has acpi, MPBIOS and ioapic by default.
Note that a Xen dom0 kernel doens't have access to the lapic.
 1.1.48.1 10-Jan-2008  bouyer Change xeni386 build to match xenamd64:
- machine/ points to xen/include/i386
- remove includes that were identical to the i386/include/ ones; the build
will find them though the xen-ma/machine link.
- include xen files using xen/ not machine/
 1.1.40.1 18-Feb-2008  mjf Sync with HEAD.
 1.1.34.1 23-Mar-2008  matt sync with HEAD
 1.1.8.3 21-Jan-2008  yamt sync with head
 1.1.8.2 30-Dec-2006  yamt sync with head.
 1.1.8.1 28-Sep-2006  yamt file mpbiosvar.h was added on branch yamt-lazymbuf on 2006-12-30 20:47:25 +0000
 1.1.4.2 18-Nov-2006  ad Sync with head.
 1.1.4.1 28-Sep-2006  ad file mpbiosvar.h was added on branch newlock2 on 2006-11-18 21:29:39 +0000
 1.1.2.2 22-Oct-2006  yamt sync with head
 1.1.2.1 28-Sep-2006  yamt file mpbiosvar.h was added on branch yamt-splraiseipl on 2006-10-22 06:05:20 +0000
 1.3 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.2 09-Feb-2007  ad branches: 1.2.4; 1.2.26; 1.2.32; 1.2.38;
Merge newlock2 to head.
 1.1 22-Dec-2006  ad branches: 1.1.2;
file mutex.h was initially added on branch newlock2.
 1.1.2.1 22-Dec-2006  ad Pull in x86 headers.
 1.2.38.1 05-Jan-2008  bouyer Remove files that just include the x86 counterpart.
 1.2.32.1 18-Feb-2008  mjf Sync with HEAD.
 1.2.26.1 23-Mar-2008  matt sync with HEAD
 1.2.4.3 21-Jan-2008  yamt sync with head
 1.2.4.2 26-Feb-2007  yamt sync with head.
 1.2.4.1 09-Feb-2007  yamt file mutex.h was added on branch yamt-lazymbuf on 2007-02-26 09:08:55 +0000
 1.24 23-Jun-2024  riastradh pci: Pass cookie through pci_find_device, pci_enumerate_bus, take 2.

New functions pci_find_device1 and pci_enumerate_bus1 have the cookie
argument. Existing symbols pci_find_device and pci_enumerate_bus are
now wrappers for the cookieless version.

This will allow pci_find_device callers to pass a cookie through to
the match function so they can keep state or pass in extra parameters
like b/d/f numbers, which will allow us to nix some horrible kludges
in the Linux PCI API emulation for drm (and, perhaps, Intel wifi).

This change drops the symbol pci_probe_device, in favour of a new
pci_probe_device1 with the cookie argument. But I don't think that
requires a revbump because it's only called by MD pci_enumerate_bus1
implementations, which don't live in modules anyway.

Take 2: Make sure to handle NULL match function.
 1.23 20-May-2024  riastradh Revert "pci: Pass cookie through pci_find_device, pci_enumerate_bus."

Evidently something is wrong with this, to be diagnosed and redone
once the builds and tests are in better shape.
 1.22 20-May-2024  riastradh pci: Pass cookie through pci_find_device, pci_enumerate_bus.

New functions pci_find_device1 and pci_enumerate_bus1 have the cookie
argument. Existing symbols pci_find_device and pci_enumerate_bus are
now wrappers for the cookieless version.

This drops the symbol pci_probe_device, in favour of a new
pci_probe_device1 with the cookie argument. But I don't think that
requires a revbump because it's only called by MD pci_enumerate_bus1
implementations, which don't live in modules anyway.
 1.21 23-May-2022  bouyer branches: 1.21.4;
Work in progress on MSI/MSI-X on Xen (MSI works on my hardware, more work
needed for MSI-X):
- Xen silently rejects 32 bits writes to MSI configuration registers
(especially when setting PCI_MSI_CTL_MSI_ENABLE/PCI_MSIX_CTL_ENABLE),
it expects 16 bits writes. So introduce a pci_conf_write16(),
only available on XENPV (and working only for mode 1 without
PCI_OVERRIDE_CONF_WRITE) and use it to enable MSI or MSI-X on XENPV.
- for multi-MSI vectors, Xen allocates all of them in a single hypercall,
so it's not convenient to do it at intr_establish() time.
So do it at alloc() time and register the pirqs in the msipic structure.
xen_pic_to_gsi() now just returns the values cached in the msipic.
As a bonus, if the PHYSDEVOP_map_pirq hypercall fails we can fail
the alloc() and we don't need the xen_pci_msi*_probe() hacks.

options NO_PCI_MSI_MSIX still on by default for XEN3_DOM0.
 1.20 12-Feb-2019  cherry conditionally include XENPV specific code.

This explicitly excludes PV only functionality that would be wrong to
attempt to use in other modes, for eg: p2m table management.
 1.19 16-Jul-2017  cherry branches: 1.19.2; 1.19.6;
Remove the xen specific interrupt type for the x86 intr_handle_t
For this to work, we use the evtchn.c:get_pirq_to_evtchn() glue
function to make things easier.
 1.18 04-Apr-2011  dyoung branches: 1.18.14; 1.18.32;
Neither pci_dma64_available(), pci_probe_device(), pci_mapreg_map(9),
pci_find_rom(), pci_intr_map(9), pci_enumerate_bus(), nor the match
predicate passed to pciide_compat_intr_establish() should ever modify
their pci_attach_args argument, so make their pci_attach_args arguments
const and deal with the fallout throughout the kernel.

For the most part, these changes add a 'const' where there was no
'const' before, however, some drivers and MD code used to modify
pci_attach_args. Now those drivers either copy their pci_attach_args
and modify the copy, or refrain from modifying pci_attach_args:

Xen: according to Manuel Bouyer, writing to pci_attach_args in
pci_intr_map() was a leftover from Xen 2. Probably a bug. I
stopped writing it. I have not tested this change.

siside(4): sis_hostbr_match() needlessly wrote to pci_attach_args.
Probably a bug. I use a temporary variable. I have not tested this
change.

slide(4): sl82c105_chip_map() overwrote the caller's pci_attach_args.
Probably a bug. Use a local pci_attach_args. I have not tested
this change.

viaide(4): via_sata_chip_map() and via_sata_chip_map_new() overwrote the
caller's pci_attach_args. Probably a bug. Make a local copy of the
caller's pci_attach_args and modify the copy. I have not tested
this change.

While I'm here, make pci_mapreg_submap() static.

With these changes in place, I have tested the compilation of these
kernels:

alpha GENERIC
amd64 GENERIC XEN3_DOM0
arc GENERIC
atari HADES MILAN-PCIIDE
bebox GENERIC
cats GENERIC
cobalt GENERIC
evbarm-eb NSLU2
evbarm-el ADI_BRH ARMADILLO9 CP3100 GEMINI GEMINI_MASTER GEMINI_SLAVE GUMSTIX
HDL_G IMX31LITE INTEGRATOR IQ31244 IQ80310 IQ80321 IXDP425 IXM1200
KUROBOX_PRO LUBBOCK MARVELL_NAS NAPPI SHEEVAPLUG SMDK2800 TEAMASA_NPWR
TEAMASA_NPWR_FC TS7200 TWINTAIL ZAO425
evbmips-el AP30 DBAU1500 DBAU1550 MALTA MERAKI MTX-1 OMSAL400 RB153 WGT624V3
evbmips64-el XLSATX
evbppc EV64260 MPC8536DS MPC8548CDS OPENBLOCKS200 OPENBLOCKS266
OPENBLOCKS266_OPT P2020RDB PMPPC RB800 WALNUT
hp700 GENERIC
i386 ALL XEN3_DOM0 XEN3_DOMU
ibmnws GENERIC
macppc GENERIC
mvmeppc GENERIC
netwinder GENERIC
ofppc GENERIC
prep GENERIC
sandpoint GENERIC
sgimips GENERIC32_IP2x
sparc GENERIC_SUN4U KRUPS
sparc64 GENERIC

As of Sun Apr 3 15:26:26 CDT 2011, I could not compile these kernels
with or without my patches in place:

### evbmips-el GDIUM

nbmake: nbmake: don't know how to make /home/dyoung/pristine-nbsd/src/sys/arch/mips/mips/softintr.c. Stop

### evbarm-el MPCSA_GENERIC
src/sys/arch/evbarm/conf/MPCSA_GENERIC:318: ds1672rtc*: unknown device `ds1672rtc'

### ia64 GENERIC

/tmp/genassym.28085/assym.c: In function 'f111':
/tmp/genassym.28085/assym.c:67: error: invalid application of 'sizeof' to incomplete type 'struct pcb'
/tmp/genassym.28085/assym.c:76: error: dereferencing pointer to incomplete type

### sgimips GENERIC32_IP3x

crmfb.o: In function `crmfb_attach':
crmfb.c:(.text+0x2304): undefined reference to `ddc_read_edid'
crmfb.c:(.text+0x2304): relocation truncated to fit: R_MIPS_26 against `ddc_read_edid'
crmfb.c:(.text+0x234c): undefined reference to `edid_parse'
crmfb.c:(.text+0x234c): relocation truncated to fit: R_MIPS_26 against `edid_parse'
crmfb.c:(.text+0x2354): undefined reference to `edid_print'
crmfb.c:(.text+0x2354): relocation truncated to fit: R_MIPS_26 against `edid_print'
 1.17 14-Mar-2010  dyoung branches: 1.17.2; 1.17.4;
Add a new member, pc_super, to x86's pci_chipset_tag: pc.pc_super points
to the tag that pc inherits its behavior from. Add code to deal with
pc.pc_super.

Pull identical declarations out of xen/include/pci_machdep.h and
x86/include/pci_machdep.h into x86/include/pci_machdep_common.h.
 1.16 25-Feb-2010  dyoung Fix Xen.

XXX Almost everything in this header file, x86, amd64, and i386 should
XXX share.
 1.15 16-Feb-2010  dyoung Declare pci_mode_set().
 1.14 15-Feb-2010  dyoung Get pci_mode out of the global namespace.
 1.13 19-Oct-2009  bouyer branches: 1.13.2;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.12 29-Jul-2009  cegger remove Xen2 support.
ok bouyer@
 1.11 13-Feb-2009  bouyer Work in progress on PCI front-end/back-end support
front-end:
- add a xpci* at xenbus? which provides pci busses from the dom0
xpci provides support routines for PCI config space operations and
enumeration in xpci_xenbus.c
- hypervisor.c: do dom0-style PCI attach only ifdef DOM0OPS
- pci_intr_machdep.c: check line value only if DOM0OPS

back-end:
- add a pciback* at pci? device which takes precedences over all
other PCI devices (match return 500) and matches all devices passed
to pciback.hide option on boot command line.
It exports the PCI device informations to files in /kern/xen/pci/
- hypervisor.c: create /kern/xen earlier so pciback can create its
entries while PCI devices are probed
- xen_machdep.c: add handling for pciback.hide=

frontend is know working on Xen 3.1.x dom0 with ahc(4) and pciide(4)
devices. uhci(4) fail when trying to allocate a large contigous DMA
buffer.

backend is work in progress; support in xentools is not there yet.
 1.10 30-May-2008  cegger branches: 1.10.6; 1.10.8; 1.10.12; 1.10.16;
build fix: add missing prototype
 1.9 16-Apr-2008  cegger branches: 1.9.2; 1.9.4; 1.9.6;
device_t / softc split
reviewed, tested and approved by bouyer
 1.8 14-Apr-2008  cegger - use POSIX integer types
- ansify functions
 1.7 28-Sep-2006  bouyer branches: 1.7.52;
Add Xen3 support for ACPI and/or MPBIOS + IOAPIC. To help with this, physical
CPUs are now configured on mainbus only in dom0, and only to know about
their APIC id. virtual CPUs are attached to hypervisor as:
vcpu* at hypervisor?
and this is what's used as curcpu(). The kernel config files needs to be
updated for this, see XEN3_DOM0 or XEN3_DOMU for examples.
XEN3_DOM0 now has acpi, MPBIOS and ioapic by default.
Note that a Xen dom0 kernel doens't have access to the lapic.
 1.6 09-Apr-2006  bouyer branches: 1.6.8; 1.6.10;
Add support for ACPI in xen-3 dom0 support. We can now boot a xen-3 dom0
kernel with a default xen comamnd line.
 1.5 11-Dec-2005  christos branches: 1.5.4; 1.5.6; 1.5.8; 1.5.10; 1.5.12;
merge ktrace-lwp.
 1.4 19-Aug-2005  bouyer Provide a PCI_MACHDEP_ENUMERATE_BUS to the MI pci system. We can't use
the generic pci_enumerate_bus() in Xen because the hypervisor may
hide the function 0, but give access to other functions of the same device
and pci_enumerate_bus() will stop if function 0 isn't available.
 1.3 16-Apr-2005  bouyer branches: 1.3.2; 1.3.4;
Get rid of the event to pseudo-irq mapping. We are limited to 32 pseudo-irq,
including soft interrupt, and this is way too low in some use (lots of domains,
or domains with lots of xennet, or even hardware with lots of devices at
different interrupts).
Based on idea from YAMAMOTO Takashi, keep one list of handler per-event and
one per-IPL (so the same handler is now in 2 lists). In the common case were
an event is received at low IPL, we can call the handlers quickly (there
is usually only one handler per event, unless the event is mapped to a
physical interrupt and this interrupt is shared by different devices).
Deffered events and software interrupts are handled by a bitmask (as before)
with one bit per IPL. When one IPL has an event pending all handlers for
this IPL will be called.
With this change, it is now possible to have all the 1024 events active.

While here, handle debug event in a special way: the handler is always called,
regardless of the current IPL. Make the handler print usefull informations
about events and IPL states.
Also remove code not used on Xen in files inherited from the x86 port.
 1.2 09-Mar-2005  bouyer branches: 1.2.2; 1.2.4;
Merge the bouyer-xen2 branch. This add supports for the Xen 2.0 virtual
machine kernel (both privileged and non-privileged domains), and remove support
for the old xen 1.2.
 1.1 18-Jan-2005  bouyer branches: 1.1.2; 1.1.4;
file pci_machdep.h was initially added on branch bouyer-xen2.
 1.1.4.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.2.1 18-Jan-2005  bouyer snapshot of work in progress on physical devices support:
- support pci at hypervisor. Attach one PCI bus for each bus returned by
PHYSDEVOP_PCI_PROBE_ROOT_BUSES (it looks like xen hides ppb bridges from
the guest OS).
- implement pci_conf_read()/pci_conf_write() using the appropriate
PHYSDEVOP_PCI_* calls.
- call PHYSDEVOP_PCI_INITIALISE_DEVICE from pci_intr_map() to make xen
do interrupts routing if needed, and map the hardware interrupt to
a xen interrupt.
- add pci and associated devices to files.xen

This is enouth to have IDE controllers work in PIO mode.
TODO: bus_dma support (currently bus_dma won't translate pseudo-physical
addresses to machine addresses), ISA support, test memory-mapped
I/O registers.
 1.2.4.3 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.4.2 01-Apr-2005  skrll Sync with HEAD.
 1.2.4.1 09-Mar-2005  skrll file pci_machdep.h was added on branch ktrace-lwp on 2005-04-01 14:29:10 +0000
 1.2.2.2 25-Aug-2005  tron Pull up following revision(s) (requested by bouyer in ticket #694):
sys/arch/xen/xen/pci_machdep.c: revision 1.5
sys/arch/xen/include/pci_machdep.h: revision 1.4
Provide a PCI_MACHDEP_ENUMERATE_BUS to the MI pci system. We can't use
the generic pci_enumerate_bus() in Xen because the hypervisor may
hide the function 0, but give access to other functions of the same device
and pci_enumerate_bus() will stop if function 0 isn't available.
 1.2.2.1 28-Apr-2005  tron Pull up revision 1.3 (requested by bouyer in ticket #192):
Get rid of the event to pseudo-irq mapping. We are limited to 32 pseudo-irq,
including soft interrupt, and this is way too low in some use (lots of domains,
or domains with lots of xennet, or even hardware with lots of devices at
different interrupts).
Based on idea from YAMAMOTO Takashi, keep one list of handler per-event and
one per-IPL (so the same handler is now in 2 lists). In the common case were
an event is received at low IPL, we can call the handlers quickly (there
is usually only one handler per event, unless the event is mapped to a
physical interrupt and this interrupt is shared by different devices).
Deffered events and software interrupts are handled by a bitmask (as before)
with one bit per IPL. When one IPL has an event pending all handlers for
this IPL will be called.
With this change, it is now possible to have all the 1024 events active.
While here, handle debug event in a special way: the handler is always called,
regardless of the current IPL. Make the handler print usefull informations
about events and IPL states.
Also remove code not used on Xen in files inherited from the x86 port.
 1.3.4.2 30-Dec-2006  yamt sync with head.
 1.3.4.1 21-Jun-2006  yamt sync with head.
 1.3.2.2 29-Apr-2005  kent sync with -current
 1.3.2.1 16-Apr-2005  kent file pci_machdep.h was added on branch kent-audio2 on 2005-04-29 11:28:29 +0000
 1.5.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.5.10.1 19-Apr-2006  elad sync with head - hopefully this will work
 1.5.8.1 11-Apr-2006  yamt sync with head
 1.5.6.1 22-Apr-2006  simonb Sync with head.
 1.5.4.1 09-Sep-2006  rpaulo sync with head
 1.6.10.1 22-Oct-2006  yamt sync with head
 1.6.8.1 18-Nov-2006  ad Sync with head.
 1.7.52.1 02-Jun-2008  mjf Sync with HEAD.
 1.9.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.9.4.4 11-Aug-2010  yamt sync with head.
 1.9.4.3 11-Mar-2010  yamt sync with head
 1.9.4.2 19-Aug-2009  yamt sync with head.
 1.9.4.1 04-May-2009  yamt sync with head.
 1.9.2.1 04-Jun-2008  yamt sync with head
 1.10.16.1 21-Apr-2010  matt sync to netbsd-5
 1.10.12.4 02-May-2011  jym Sync with head.
 1.10.12.3 24-Oct-2010  jym Sync with HEAD
 1.10.12.2 01-Nov-2009  jym Sync with HEAD.
 1.10.12.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.10.8.1 03-Oct-2009  snj Pull up following revision(s) (requested by bouyer in ticket #1054):
sys/arch/xen/conf/files.xen: revision 1.93
sys/arch/xen/include/pci_machdep.h: revision 1.11
sys/arch/xen/include/xen.h: revision 1.31
sys/arch/xen/xen/hypervisor.c: revision 1.44
sys/arch/xen/xen/pci_intr_machdep.c: revision 1.8
sys/arch/xen/xen/pciback.c: revision 1.1
sys/arch/xen/xen/xen_machdep.c: revision 1.5
sys/arch/xen/xen/xpci_xenbus.c: revision 1.1
Work in progress on PCI front-end/back-end support
front-end:
- add a xpci* at xenbus? which provides pci busses from the dom0
xpci provides support routines for PCI config space operations and
enumeration in xpci_xenbus.c
- hypervisor.c: do dom0-style PCI attach only ifdef DOM0OPS
- pci_intr_machdep.c: check line value only if DOM0OPS
back-end:
- add a pciback* at pci? device which takes precedences over all
other PCI devices (match return 500) and matches all devices passed
to pciback.hide option on boot command line.
It exports the PCI device informations to files in /kern/xen/pci/
- hypervisor.c: create /kern/xen earlier so pciback can create its
entries while PCI devices are probed
- xen_machdep.c: add handling for pciback.hide=
frontend is know working on Xen 3.1.x dom0 with ahc(4) and pciide(4)
devices. uhci(4) fail when trying to allocate a large contigous DMA
buffer.
backend is work in progress; support in xentools is not there yet.
 1.10.6.1 03-Mar-2009  skrll Sync with HEAD.
 1.13.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.17.4.1 06-Jun-2011  jruoho Sync with HEAD.
 1.17.2.1 21-Apr-2011  rmind sync with head
 1.18.32.1 28-Aug-2017  skrll Sync with HEAD
 1.18.14.1 03-Dec-2017  jdolecek update from HEAD
 1.19.6.1 10-Jun-2019  christos Sync with HEAD
 1.19.2.2 16-Jul-2017  cherry 2739767
 1.19.2.1 16-Jul-2017  cherry file pci_machdep.h was added on branch perseant-stdc-iso10646 on 2017-07-16 06:14:25 +0000
 1.21.4.1 04-Oct-2024  martin Pull up following revision(s) (requested by rin in ticket #928):

sys/external/bsd/drm2/dist/drm/drm_gem.c: revision 1.25
sys/external/bsd/drm2/dist/drm/radeon/radeon_ci_dpm.c: revision 1.7
sys/external/bsd/drm2/dist/drm/nouveau/nvkm/engine/device/priv.h: revision 1.4
sys/external/bsd/drm2/dist/drm/nouveau/nvkm/engine/device/nouveau_nvkm_engine_device_acpi.c: revision 1.4
sys/external/bsd/drm2/dist/drm/i915/display/intel_opregion.h: revision 1.6
sys/external/bsd/drm2/dist/drm/i915/i915_drv.h: revision 1.49
sys/external/bsd/drm2/include/linux/mxm-wmi.h: revision 1.1
sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/nouveau_nvkm_subdev_pci_pcie.c: revision 1.4
sys/external/bsd/drm2/dist/drm/nouveau/nvkm/engine/device/nouveau_nvkm_engine_device_base.c: revision 1.13
sys/external/bsd/common/include/linux/bitops.h: revision 1.17
sys/external/bsd/drm2/nouveau/files.nouveau: revision 1.40
sys/external/bsd/drm2/linux/linux_pci.c: revision 1.30
sys/external/bsd/drm2/dist/drm/radeon/radeon_drv.h: revision 1.5
sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/pci/nouveau_nvkm_subdev_pci_pcie.c: revision 1.5
sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/mxm/nouveau_nvkm_subdev_mxm_base.c: revision 1.5
sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_gart.c: revision 1.12
sys/external/bsd/drm2/dist/drm/radeon/radeon_rv770.c: revision 1.3
sys/external/bsd/drm2/dist/drm/nouveau/nvkm/engine/disp/nouveau_nvkm_engine_disp_sorgm200.c: revision 1.3
sys/external/bsd/common/include/linux/printk.h: revision 1.14
sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/instmem/nouveau_nvkm_subdev_instmem_gk20a.c: revision 1.10
sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_vi.c: revision 1.4
sys/external/bsd/drm2/include/linux/acpi.h: revision 1.11
sys/external/bsd/drm2/drm/drm_cdevsw.c: revision 1.31
sys/external/bsd/drm2/dist/drm/radeon/radeon_si.c: revision 1.6
sys/external/bsd/drm2/dist/drm/nouveau/nouveau_acpi.c: revision 1.5
sys/external/bsd/drm2/dist/drm/i915/display/intel_acpi.h: revision 1.5
sys/external/bsd/drm2/include/acpi/video.h: revision 1.3
sys/external/bsd/drm2/dist/drm/radeon/radeon_evergreen.c: revision 1.6
sys/external/bsd/drm2/dist/drm/nouveau/nouveau_acpi.h: revision 1.4
sys/arch/sparc64/include/pci_machdep.h: revision 1.31
sys/arch/sparc64/dev/pci_machdep.c: revision 1.83
sys/external/bsd/drm2/include/linux/kref.h: revision 1.14
sys/external/bsd/drm2/dist/drm/nouveau/nvkm/engine/device/nouveau_nvkm_engine_device_pci.c: revision 1.12
sys/external/bsd/drm2/linux/linux_dma_buf.c: revision 1.17
sys/external/bsd/drm2/dist/drm/nouveau/nvkm/subdev/bios/nouveau_nvkm_subdev_bios_shadowacpi.c: revision 1.4
sys/external/bsd/drm2/drm/drm_module.c: revision 1.32
sys/external/bsd/drm2/dist/drm/i915/i915_gem.h: revision 1.8
sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_dmabuf.c: revision 1.7
sys/external/bsd/drm2/include/linux/smp.h: revision 1.5
sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_si.c: revision 1.5
sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_device.c: revision 1.20
sys/arch/x86/x86/bus_dma.c: revision 1.91
sys/external/bsd/drm2/radeon/files.radeon: revision 1.40
sys/external/bsd/drm2/include/acpi/acpi_bus.h: revision 1.1
sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drv.h: revision 1.5
sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_device.c: revision 1.21
sys/external/bsd/common/include/asm/barrier.h: revision 1.20
sys/external/bsd/drm2/include/linux/nbsd-namespace-acpi.h: revision 1.2
sys/external/bsd/common/include/asm/barrier.h: revision 1.21
sys/modules/drmkms/drmkms_pci.h: revision 1.1
sys/external/bsd/drm2/dist/drm/drm_dp_helper.c: revision 1.17
sys/external/bsd/drm2/radeon/radeon_pci.c: revision 1.23
sys/external/bsd/drm2/linux/linux_xa.c: revision 1.4
sys/external/bsd/drm2/ttm/ttm_bo_vm.c: revision 1.23
sys/external/bsd/drm2/ttm/ttm_bo_vm.c: revision 1.24
sys/external/bsd/drm2/ttm/ttm_bo_vm.c: revision 1.25
sys/external/bsd/drm2/linux/linux_pci.c: revision 1.26
sys/dev/pci/pcivar.h: revision 1.120
sys/arch/xen/include/pci_machdep.h: revision 1.24
sys/external/bsd/drm2/ttm/ttm_bo_vm.c: revision 1.26
sys/external/bsd/drm2/linux/linux_pci.c: revision 1.27
sys/external/bsd/drm2/ttm/ttm_bo_vm.c: revision 1.27
sys/external/bsd/drm2/linux/linux_pci.c: revision 1.28
sys/external/bsd/drm2/dist/drm/radeon/radeon_cik.c: revision 1.8
sys/external/bsd/drm2/ttm/ttm_bo_vm.c: revision 1.28
sys/external/bsd/drm2/linux/linux_pci.c: revision 1.29
sys/external/bsd/drm2/include/linux/pci.h: revision 1.57
sys/external/bsd/drm2/include/linux/pci.h: revision 1.58
sys/external/bsd/drm2/dist/drm/radeon/radeon_acpi.c: revision 1.5
sys/external/bsd/drm2/dist/drm/nouveau/nouveau_display.c: revision 1.6
sys/external/bsd/drm2/dist/drm/amd/powerplay/hwmgr/amdgpu_hwmgr.c: revision 1.3
sys/external/bsd/drm2/dist/drm/amd/display/dc/core/amdgpu_dc_stream.c: revision 1.3
share/man/man9/bus_dma.9: revision 1.69
sys/external/bsd/drm2/drm/drm_gem_cma_helper.c: revision 1.15
sys/external/bsd/drm2/dist/drm/radeon/radeon_acpi.c: revision 1.6
sys/external/bsd/drm2/dist/drm/radeon/radeon.h: revision 1.12
sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_cik.c: revision 1.7
sys/dev/acpi/acpi_mcfg.c: revision 1.29
sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu_acpi.c: revision 1.6
sys/external/bsd/drm2/dist/drm/radeon/radeon_r600.c: revision 1.7
sys/external/bsd/drm2/dist/drm/radeon/radeon_bios.c: revision 1.13
sys/modules/amdgpu/Makefile: revision 1.9
sys/external/bsd/drm2/dist/drm/radeon/radeon_bios.c: revision 1.14
sys/external/bsd/common/linux/linux_tasklet.c: revision 1.12
sys/external/bsd/drm2/dist/drm/nouveau/include/nvkm/core/device.h: revision 1.10
sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_mman.c: revision 1.23
sys/external/bsd/drm2/dist/drm/amd/amdgpu/amdgpu.h: revision 1.9
sys/external/bsd/drm2/include/linux/interval_tree.h: revision 1.14
sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_mman.c: revision 1.26
sys/external/bsd/drm2/dist/drm/amd/powerplay/hwmgr/amdgpu_smu7_hwmgr.c: revision 1.5
sys/dev/pci/pci.c: revision 1.168
sys/external/bsd/drm2/dist/drm/i915/gem/i915_gem_mman.c: revision 1.27
sys/external/bsd/drm2/dist/drm/radeon/radeon_si_dpm.c: revision 1.9
sys/external/bsd/drm2/pci/files.drmkms_pci: revision 1.18
sys/external/bsd/drm2/linux/linux_sync_file.c: revision 1.3
sys/external/bsd/drm2/amdgpu/files.amdgpu: revision 1.31
sys/external/bsd/drm2/dist/drm/nouveau/nvkm/engine/device/nouveau_nvkm_engine_device_tegra.c: revision 1.4
sys/external/bsd/drm2/dist/drm/drm_gem.c: revision 1.24
sys/arch/xen/xen/xpci_xenbus.c: revision 1.29

drm: Eliminate __HAVE_ATOMIC_AS_MEMBAR conditionals.
Discussed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2023/02/23/msg028729.html

linux asm/barrier.h: Fix !MULTIPROCESSOR build.

remove "nouveau" from a comment. noted by jmcneill.

drm: KASSERT(A && B) -> KASSERT(A); KASSERT(B)
comment a function that has a clear overbounds read but it isn't used.
found by GCC 12.

nix the NetBSD specific GEM_BUG_ON().
avoids GCC 12 warnings, and matches upstream closer.
avoid uninitialised variable usage in drm_gem_cma_create_internal().
in the case nothing has returned 'error', 'nsegs' and the dma info
are (potentially) uninitialised, so consider this an error.
found by GCC 12.

avoid a GCC 12 warning.
there's a 1-element long array and a loop conditional that tries to see
if indexes for it are not identical. as these indexes will always both
be 0, the only valid index, the condition is always false. GCC 12
triggers a strange warning on this code that can never run (see below),
so simply assert the array size is 1 and comment the rest.
amdgpu_dc_stream.c:470:55: error: array subscript [0, 0] is outside array bounds of 'struct dc_writeback_info[1]' [-Werror=array-bounds]
470 | stream->writeback_info[j] = stream->writeback_info[i];

convert a KASSERT() into an if () panic() sequence to appease GCC 12.
OK riastradh@.

drm: Fix conditionals around drmkms_pci and agp.
Kernel should build now with all pci drm drivers stripped out but
DRM_LEGACY still enabled. (Might not be very useful, but it'll
build. Maybe we should also have DRM_LEGACY_PCI so those drivers can
be modloaded later.)

drmkms: Fix module build.
avoid an unlikely array bounds issue picked up by GCC 12.
nvkm_pcie_speed() can return -1, which is then used as an array index,
so make this default return PCIe 1.0 speeds.

drm: enable almost all PCIe functionality
linux_pci.c revisions 1.24 and 1.25 implemented most of the remaining
missing PCIe backends, but only enabled them for some amdgpu portions.
this enables all code marked with "XXX amdgpu pcie", "XXX radeon pcie",
and "XXX pcie speed". for most of it, simply removing #ifndefs __NetBSD__
to enable compliation was required, once the new "bus->max_bus_speed"
member was added to struct pci_bus. add an "always fails" backend for
pci_enable_atomic_ops_to_root() which seems to only be necessary
for virtual GPU functionality (and could be implemented if needed.)
tested on radeon 5450, 7750, R7 240 [radeon], and RX 550 [amdgpu], and
nvidia 750 and 1030 [nouveau].
this still does not quite work on nvidia cards. there are two problems
that remain:
- the call to set the link speed is skipped because the speed is set
to the default value of "-1". nvkm_pcie_set_link() will actually
determine the right value for this and for some cards, calling this
function if the current speed is -1 helps set the link speed. it
may be that on linux other paths we don't have enabled properly
would set this (there's one via debugfs, and a jetson specific one,
though perhaps setting either AC or DC speed values as boot options
(after hooking up these for netbsd) would currently work.
- worse, cards newer than kepler - geforce 900, 1000, and newer, are
all lacking the backing support to set pcie link speed. the GT 1030
card i have been testing with remains at pcie 1.0.

radeon: fix and enable ACPI methods for getting ROM BIOS
The hacky way of getting the BIOS mapped only works on x86. ACPI
should be preferred if available. Makes BIOS reading though VFCT
work on aarch64 with EDK2. (But only if EDK2 has POSTed the GPU.)
XXX amdgpu should get the same treatment.

drm: put_cpu() should enable preemption, not disable it again

drm(4): make pr_debug equivalent to aprint_debug
significantly reduces the default spam from amdgpu(4).

drm: Set CONFIG_ACPI in linux/acpi.h and make it build.

Leave a little ACPI-related functionality disabled for now, like
getting EDID out of ACPI -- needs a bit more work to make this work,
and I don't have hardware to work on that.
Should help with failures of the forms:
- unable to locate a BIOS ROM
- bios: unable to locate usable image
on various machines.

radeon_acpi.c: ifdef out unused function on NetBSD.
Should fix syzkaller build.

drm(4): Fix st_rdev in stat.
dminor->index already has the 64*type adjustment, as allocated in
drm_minor_alloc.
PR kern/58180

linux_sync_file: Fix missing init/fini steps.
Noted by rjs@.
PR kern/58210

ttm: Sync ttm_bo_uvm_fault_idle better with Linux.
PR xsrc/58133
ttm: Undo mistake in previous.

PR xsrc/58133
linux: Add a few more cases to pci_get_class.
Should fix crash on boot with amdgpu now that the ACPI business is
enabled.

i915: Fix dmabuf mmap object.

drm: Fix missing bounds checks in dma buf mmap.

drm_gem.c: Fix sense of assertion.
This is the opposite of WARN_ON.
Noted by rjs@.

drm_gem.c: Enable drm_gem_fence_array_add now that we emulate xa.
linux_xa: Delete and replace collision in xa_store as intended.
Don't free the colliding node that's still in the tree.
Noted by rjs@.

i915_gem_mman.c: Apply mmap types via pmap flags.
This way, userland gets buffers mapped write-combining or uncached as
needed.
PR xsrc/58307

x86: Teach bus_dmamem_map about BUS_DMA_PREFETCHABLE.
PR port-amd64/58308

bus_dma(9): Document BUS_DMA_PREFETCHABLE.
Like BUS_DMA_NOCACHE. Doesn't absolve you of the need for
bus_dmamap_sync, but if you later pass the vaddr to bus_dmamap_load,
the DMA map might notice the mapping is write-combining and use this
to make bus_dmamap_sync cheaper.
PR kern/58309

nouveau_nvkm_subdev_instmem_gk20a.c: Use BUS_DMA_PREFETCHABLE.
Matches Linux's pgprot_writecombine.
Unclear where the appropriate bus_dmamap_sync happens, or is supposed
to happen -- not using it would be wrong, but asking for a
prefetchable mapping may paper over symptoms, at least!

ttm: Sync more with Linux.
Add the original copyright and attribution since this is now,
intentionally, a modified copy of the original and not just roughly
the same algorithm.

ttm: Respect PGO_ALLPAGES.
Not sure this is useful but it reduces XXX's and makes this match
udv_fault better so it's easier to understand.

ttm: Sync cacheability flag logic with Linux.

ttm: Add XXX about readahead fault failures.

pci: Pass cookie through pci_find_device, pci_enumerate_bus, take 2.
New functions pci_find_device1 and pci_enumerate_bus1 have the cookie
argument. Existing symbols pci_find_device and pci_enumerate_bus are
now wrappers for the cookieless version.
This will allow pci_find_device callers to pass a cookie through to
the match function so they can keep state or pass in extra parameters
like b/d/f numbers, which will allow us to nix some horrible kludges
in the Linux PCI API emulation for drm (and, perhaps, Intel wifi).
This change drops the symbol pci_probe_device, in favour of a new
pci_probe_device1 with the cookie argument. But I don't think that
requires a revbump because it's only called by MD pci_enumerate_bus1
implementations, which don't live in modules anyway.
Take 2: Make sure to handle NULL match function.
linux_pci: Nix pci enumeration kludges.
Now that we can pass a cookie through, this stuff will be a little
less fragile.

i915: Omit needless i915_gem_object_pin/unpin_pages cycle in fault.
vm_fault_cpu and vm_fault_gtt, called by i915_gem_fault, already do
the pinning and unpinning internally, so there is no need for
i915_gem_fault to do it.
No functional change intended, except that the transient pin count
will be one lower than before during the fault routine (but it will
still be positive).

i915: Match Linux fault routine return code actions.
Omit needless EINTR interception -- this is now handled by
i915_error_to_vmf_fault.
Earlier revert was over a false alarm -- bisection shows the new
warnings arose from linux_pci.c 1.29 here:
https://mail-index.netbsd.org/source-changes/2024/06/23/msg151929.html

linux_pci: Fix shifto in pci_get_class.
It looks like Linux's pci_get_class also matches the interface part
of the PCI class register (but not the revision part), and I hadn't
noticed that in the previous shim structured differently.

With GCC12 kernel ALL/amd64 triggers "'sor' may be used uninitialized".
If "sublinks & 3" is zero GCC is right and sor[1] may be returned unitialized.
Fix by initializing "sor" to zero to return -1 instead of uninitialized value.
Ok: Taylor R Campbell <riastradh@>

amdgpu: Map BAR 2, not BAR 5, on pre-bonaire chips.
PR kern/58384

amdgpu: Map consecutive pages, not the same one over and over again.
PR kern/58385

linux/bitops: Fix overestimate for BITS_TO_LONGS(9)
Fortunately, this seems harmless except for allocating
excessive buffer memory.
Pointed out by nonaka@, OK riastradh@.
 1.3 02-Jul-2008  drochner remove some obviously obsolete definitions
 1.2 11-Dec-2005  christos branches: 1.2.74; 1.2.78; 1.2.80; 1.2.82;
merge ktrace-lwp.
 1.1 11-Mar-2004  cl branches: 1.1.4;
Add port to the Xen virtual machine monitor.
(see http://www.cl.cam.ac.uk/Research/SRG/netos/xen/)
 1.1.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.4.2 03-Aug-2004  skrll Sync with HEAD
 1.1.4.1 11-Mar-2004  skrll file pic.h was added on branch ktrace-lwp on 2004-08-03 10:43:11 +0000
 1.2.82.1 03-Jul-2008  simonb Sync with head.
 1.2.80.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.2.78.1 04-May-2009  yamt sync with head.
 1.2.74.1 28-Sep-2008  mjf Sync with HEAD.
 1.19 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.18 25-Dec-2007  perry Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.17 28-Nov-2007  ad branches: 1.17.2; 1.17.6;
Remove remaining CPUCLASS_386 tests.
 1.16 28-Nov-2007  ad Use the new atomic ops.
 1.15 22-Nov-2007  bouyer Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.14 15-Nov-2007  ad Remove support for 80386 level CPUs. PR port-i386/36163.
 1.13 17-Oct-2007  garbled branches: 1.13.2;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.12 04-Sep-2007  bouyer branches: 1.12.4;
Fix build failure when for kernel with options LOCKDEBUG.
Pointed out by Christoph Egger.
 1.11 29-Aug-2007  ad Merge most x86 changes from the vmlocking branch, except the threaded soft
interrupt stuff. This is mostly comprised of changes to the pmap modules to
work on multiprocessor systems without kernel_lock, and changes to speed up
tlb shootdowns.
 1.10 21-Feb-2007  thorpej branches: 1.10.4; 1.10.12; 1.10.16; 1.10.20; 1.10.22;
Replace the Mach-derived boolean_t type with the C99 bool type. A
future commit will replace use of TRUE and FALSE with true and false.
 1.9 16-Feb-2006  perry branches: 1.9.20;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.8 23-Jan-2006  yamt branches: 1.8.2; 1.8.4;
merge xen pmap_enter, pmap_enter_ma, pmap_remap_pages.
ok'ed by Manuel Bouyer.
 1.7 24-Dec-2005  perry branches: 1.7.2;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.6 11-Dec-2005  christos merge ktrace-lwp.
 1.5 10-Sep-2005  bouyer Add a vm_prot_t parameter to pmap_remap_pages(), and use it for the new PTE
instead to always trying PG_RW and falling back to PG_RO if this fails.
Use uvm_map_checkprot() in IOCTL_PRIVCMD_MMAP and IOCTL_PRIVCMD_MMAP_BATCH
to compute the appropriate vm_prot_t for pmap_remap_pages().
Thanks to Jed Davis for pointing out uvm_map_checkprot().
 1.4 09-Mar-2005  bouyer branches: 1.4.2; 1.4.4;
Merge the bouyer-xen2 branch. This add supports for the Xen 2.0 virtual
machine kernel (both privileged and non-privileged domains), and remove support
for the old xen 1.2.
 1.3 24-Apr-2004  cl branches: 1.3.2; 1.3.6; 1.3.8; 1.3.10;
Make bus_space map machine addresses instead of physical addresses.
 1.2 10-Apr-2004  cl add prototype for pmap_kenter_ma
 1.1 11-Mar-2004  cl branches: 1.1.2;
Add port to the Xen virtual machine monitor.
(see http://www.cl.cam.ac.uk/Research/SRG/netos/xen/)
 1.1.2.1 22-May-2004  he Pull up revisions 1.2-1.3 (requested by cl in ticket #337):
Upgrade xen support:
- add block device driver
- network device driver bug fixes
- support for vga/keyboard/mouse
- support for domain0 operations
- fix /dev/mem and i386_iopl, reboot, event dispatch
- fix clock support, cpu speed report, lazy fpu switching
- add xen12load loader
- sys/arch/xen parts of build.sh release support
[cl, ticket #337]
 1.3.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.3.8.1 29-Apr-2005  kent sync with -current
 1.3.6.5 09-Mar-2005  bouyer bus_space_map/unmap() should map machine addresses, not physical addresses,
for memory-mapped I/O. So use pmap_kenter_ma() instead of pmap_kenter_pa(),
and introduce pmap_extract_ma() to get the machine address of a mapping.
Now memory-mapped I/O should work outside of the ISA hole (note that PCI
devices are usually mapped in the ISA memory hole anyway).
 1.3.6.4 12-Feb-2005  bouyer Implement pmap_remap_pages(), which remplace one or more pages in a
mapping with different pages, possibly from a foreing domain.
Use this to implement IOCTL_PRIVCMD_MMAP.
 1.3.6.3 17-Dec-2004  bouyer merge changes from i386/include/pmap.h 1.81:
Fix various typos in comments including ones that weren't noticed
for years.

This syncs pmap.h with i386/include/pmap.h 1.82, without 1.80 (NKPTP dynamic
adjustement) which cause the domain to reset when booting.
 1.3.6.2 17-Dec-2004  bouyer Merge in changes from arch/i386/pmap.h 1.82
 1.3.6.1 13-Dec-2004  bouyer Commit files from netbsd-2.0-xen-sparse/sys/arch/xen in the Xen-2.0
distribution. These are the files modified from the 2.0 tree to get
NetBSD/xen working with Xen 2.
 1.3.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.3.2.5 01-Apr-2005  skrll Sync with HEAD.
 1.3.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.3.2.2 03-Aug-2004  skrll Sync with HEAD
 1.3.2.1 24-Apr-2004  skrll file pmap.h was added on branch ktrace-lwp on 2004-08-03 10:43:11 +0000
 1.4.4.6 21-Jan-2008  yamt sync with head
 1.4.4.5 07-Dec-2007  yamt sync with head
 1.4.4.4 27-Oct-2007  yamt sync with head.
 1.4.4.3 03-Sep-2007  yamt sync with head.
 1.4.4.2 26-Feb-2007  yamt sync with head.
 1.4.4.1 21-Jun-2006  yamt sync with head.
 1.4.2.1 20-Jan-2006  riz Pull up following revision(s) (requested by bouyer in ticket #1104):
sys/arch/xen/xen/privcmd.c: revision 1.6
sys/arch/xen/i386/pmap.c: revision 1.14
sys/arch/xen/include/pmap.h: revision 1.5
sys/arch/xen/xen/xennetback.c: revision 1.12 via patch
sys/arch/xen/xen/xbdback.c: revision 1.15
Add a vm_prot_t parameter to pmap_remap_pages(), and use it for the new PTE
instead to always trying PG_RW and falling back to PG_RO if this fails.
Use uvm_map_checkprot() in IOCTL_PRIVCMD_MMAP and IOCTL_PRIVCMD_MMAP_BATCH
to compute the appropriate vm_prot_t for pmap_remap_pages().
Thanks to Jed Davis for pointing out uvm_map_checkprot().
 1.7.2.2 18-Feb-2006  yamt sync with head.
 1.7.2.1 01-Feb-2006  yamt sync with head.
 1.8.4.1 22-Apr-2006  simonb Sync with head.
 1.8.2.1 09-Sep-2006  rpaulo sync with head
 1.9.20.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.10.22.3 23-Mar-2008  matt sync with HEAD
 1.10.22.2 09-Jan-2008  matt sync with HEAD
 1.10.22.1 06-Nov-2007  matt sync with HEAD
 1.10.20.5 03-Dec-2007  joerg Sync with HEAD.
 1.10.20.4 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.10.20.3 21-Nov-2007  joerg Sync with HEAD.
 1.10.20.2 02-Oct-2007  joerg Sync with HEAD.
 1.10.20.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.10.16.2 10-Sep-2007  skrll Sync with HEAD.
 1.10.16.1 03-Sep-2007  skrll Sync with HEAD.
 1.10.12.1 03-Oct-2007  garbled Sync with HEAD
 1.10.4.2 03-Dec-2007  ad Sync with HEAD.
 1.10.4.1 09-Oct-2007  ad Sync with head.
 1.12.4.3 18-Nov-2007  bouyer Sync with HEAD
 1.12.4.2 25-Oct-2007  bouyer Finish sync with HEAD. Especially use the new x86 pmap for xenamd64.
For this:
- rename pmap_pte_set() to pmap_pte_testset()
- make pmap_pte_set() a function or macro for non-atomic PTE write
- define and use pmap_pa2pte()/pmap_pte2pa() to read/write PTE entries
- define pmap_pte_flush() which is a nop in x86 case, and flush the
MMUops queue in the Xen case
 1.12.4.1 17-Oct-2007  bouyer Prepare for xenamd64:
- kill xen/i386/identcpu.c, use i386/i386/identcpu.c instead (with a few
#ifndef XEN)
- move some files that can be shared between i386 and amd64 from
xen/i386 to xen/x86 (or to xen/xen for non-cpu-specific code)
- split assembly out of xen/include/hypervisor.h to xen/include/hypercalls.h
- use <xen/...> instead of <machine/...> for cpu-independant include files.

more work needed here, i386-specific files should got out of arch/xen to
arch/xeni386, and more code shared with arch/i386.
 1.13.2.3 18-Feb-2008  mjf Sync with HEAD.
 1.13.2.2 08-Dec-2007  mjf Sync with HEAD.
 1.13.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.17.6.1 11-Dec-2007  bouyer Switch i386 to x86/x86/pmap.c
 1.17.2.1 26-Dec-2007  ad Sync with head.
 1.3 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.2 09-Feb-2007  ad branches: 1.2.4; 1.2.26; 1.2.32; 1.2.38;
Merge newlock2 to head.
 1.1 22-Dec-2006  ad branches: 1.1.2;
file rwlock.h was initially added on branch newlock2.
 1.1.2.1 22-Dec-2006  ad Pull in x86 headers.
 1.2.38.1 05-Jan-2008  bouyer Remove files that just include the x86 counterpart.
 1.2.32.1 18-Feb-2008  mjf Sync with HEAD.
 1.2.26.1 23-Mar-2008  matt sync with HEAD
 1.2.4.3 21-Jan-2008  yamt sync with head
 1.2.4.2 26-Feb-2007  yamt sync with head.
 1.2.4.1 09-Feb-2007  yamt file rwlock.h was added on branch yamt-lazymbuf on 2007-02-26 09:08:56 +0000
 1.8 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.7 04-Jan-2008  yamt i386:
- make tss per-cpu. this considerably speeds up context switch for,
at least, pentium4, where ltr instruction seems very slow.
i386, xen:
- kill cpu_maxproc.
kvm86:
- adapt to per-cpu tss.
- cleanup and simplify.
- move kvm86_mp_lock to more meaningful place.
- disable preemption during a call.
 1.6 26-Dec-2007  yamt - share idt entry allocation code among x86.
- introduce a function to reserve an idt entry and use it instead of
manipulating idt_allocmap directly.
- rename idt to xen_idt for amd64 xen. add missing #ifdef XEN.
 1.5 25-Dec-2007  perry Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.4 11-Nov-2007  ad branches: 1.4.2; 1.4.6;
Make xen build again.
 1.3 15-Jan-2006  bouyer branches: 1.3.28; 1.3.46; 1.3.48; 1.3.52; 1.3.54;
Snapshot of work in progress on NetBSD port to Xen3:
- kernel (both dom0 and domU) boot, console is functionnal and it can starts
software from a ramdisk
- there is no driver front-end expect console for domU yet.
- dom0 can probe devices and ex(4) work when Xen3 is booted without acpi
and apic support. But the on-board IDE doens't get interrupts.
The PCI code still needs work (it's hardcoded to mode 1). Some of this
code should be shared with ../x86
The physical insterrupt code needs to get MPBIOS and ACPI support, and
do interrupt routing to properly interract with Xen.
To enable Xen-3.0 support, add
options XEN3
to your kernel config file (this will disable Xen2 support)
Changes affecting Xen-2.0 support (no functionnal changes intended):
- get more constants from genassym for assembly code
- remove some unneeded registers move from start()
- map the shared info page from start(), and remove the pte = 0xffffffff hack
- vector.S: in hypervisor_callback() make sure %esi points to
HYPERVISOR_shared_info before accessing the info page. Remplace some
hand-written assembly with the equivalent macro defined in frameasm.h
- more debug code, dissabled by default.

while here added my copyright on some files I worked on in 2005.
 1.2 11-Dec-2005  christos branches: 1.2.2;
merge ktrace-lwp.
 1.1 11-Mar-2004  cl branches: 1.1.4; 1.1.18; 1.1.20;
Add port to the Xen virtual machine monitor.
(see http://www.cl.cam.ac.uk/Research/SRG/netos/xen/)
 1.1.20.3 21-Jan-2008  yamt sync with head
 1.1.20.2 15-Nov-2007  yamt sync with head.
 1.1.20.1 21-Jun-2006  yamt sync with head.
 1.1.18.1 07-Apr-2006  tron Apply patch (requested by bouyer in ticket #1245):
Pull up Xen3 domU support. This adds support for the Xen-3 memory bootstrap,
xenstore, and block and network device frontend. Xen-3 support is turned
on by 'options XEN3', which disable Xen-2 support.
Changes affecting non-xen3 specific code:
- xbd and xennet at hypervisor now attaches with xbd_hypervisor and
xennet_hypervisor
- x86_atomic_* renamed to xen_atomic_*
- use genassim.cf to pull in more constant from include files for assembly
- Map the shared info page from locore.S instead of the 0xffffffff hack
in xen_machdep.c
- remove some unused code
- some __asm__ __volatile__ -> __asm volatile and __inline__ -> inline
- more debug code
 1.1.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.4.2 03-Aug-2004  skrll Sync with HEAD
 1.1.4.1 11-Mar-2004  skrll file segments.h was added on branch ktrace-lwp on 2004-08-03 10:43:11 +0000
 1.2.2.1 01-Feb-2006  yamt sync with head.
 1.3.54.2 18-Feb-2008  mjf Sync with HEAD.
 1.3.54.1 19-Nov-2007  mjf Sync with HEAD.
 1.3.52.1 13-Nov-2007  bouyer Sync with HEAD
 1.3.48.2 23-Mar-2008  matt sync with HEAD
 1.3.48.1 09-Jan-2008  matt sync with HEAD
 1.3.46.1 11-Nov-2007  joerg Sync with HEAD.
 1.3.28.1 03-Dec-2007  ad Sync with HEAD.
 1.4.6.3 07-Jan-2008  bouyer Move Xen support to i386/i386/machdep.c. two less files in xen/ :)
 1.4.6.2 02-Jan-2008  bouyer Sync with HEAD
 1.4.6.1 11-Dec-2007  bouyer Switch i386 to x86/x86/pmap.c
 1.4.2.1 26-Dec-2007  ad Sync with head.
 1.5 28-Jul-2012  matt Fix some -fno-common fallout.
 1.4 20-Sep-2011  jym branches: 1.4.2;
Merge jym-xensuspend branch in -current. ok bouyer@.

Goal: save/restore support in NetBSD domUs, for i386, i386 PAE and amd64.

Executive summary:
- split all Xen drivers (xenbus(4), grant tables, xbd(4), xennet(4))
in two parts: suspend and resume, and hook them to pmf(9).
- modify pmap so that Xen hypervisor does not cry out loud in case
it finds "unexpected" recursive memory mappings
- provide a sysctl(7), machdep.xen.suspend, to command suspend from
userland via powerd(8). Note: a suspend can only be handled correctly
when dom0 requested it, so provide a mechanism that will prevent
kernel to blindly validate user's commands

The code is still in experimental state, use at your own risk: restore
can corrupt backend communications rings; this can completely thrash
dom0 as it will loop at a high interrupt level trying to honor
all domU requests.

XXX PAE suspend does not work in amd64 currently, due to (yet again!)
page validation issues with hypervisor. Will fix.

XXX secondary CPUs are not suspended, I will write the handlers
in sync with cherry's Xen MP work.

Tested under i386 and amd64, bear in mind ring corruption though.

No build break expected, GENERICs and XEN* kernels should be fine.
./build.sh distribution still running. In any case: sorry if it does
break for you, contact me directly for reports.
 1.3 17-Oct-2007  garbled branches: 1.3.34;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.2 23-Sep-2007  bouyer Add NetBSD RCS Id.
 1.1 11-Aug-2006  yamt branches: 1.1.2; 1.1.6; 1.1.8; 1.1.10; 1.1.16; 1.1.22; 1.1.30; 1.1.40; 1.1.42;
"xm shutdown" support for xen3. ok'ed by Manuel Bouyer.
 1.1.42.1 06-Nov-2007  matt sync with HEAD
 1.1.40.1 02-Oct-2007  joerg Sync with HEAD.
 1.1.30.1 03-Oct-2007  garbled Sync with HEAD
 1.1.22.1 09-Oct-2007  ad Sync with head.
 1.1.16.3 27-Oct-2007  yamt sync with head.
 1.1.16.2 30-Dec-2006  yamt sync with head.
 1.1.16.1 11-Aug-2006  yamt file shutdown_xenbus.h was added on branch yamt-lazymbuf on 2006-12-30 20:47:25 +0000
 1.1.10.2 09-Sep-2006  rpaulo sync with head
 1.1.10.1 11-Aug-2006  rpaulo file shutdown_xenbus.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:44:56 +0000
 1.1.8.1 08-Sep-2006  rpaulo Pull up following revision(s) (requested by jld in ticket #129):
sys/arch/xen/conf/files.xen: revision 1.46
sys/arch/xen/xen/hypervisor.c: revision 1.26
sys/arch/xen/xen/shutdown_xenbus.c: revision 1.1
sys/arch/xen/xenbus/xenbus_probe.c: revision 1.13
sys/arch/xen/include/shutdown_xenbus.h: revision 1.1
"xm shutdown" support for xen3. ok'ed by Manuel Bouyer.
 1.1.6.2 08-Sep-2006  ghen Pull up following revision(s) (requested by jld in ticket #1499):
sys/arch/xen/conf/files.xen: revision 1.46
sys/arch/xen/xen/hypervisor.c: revision 1.26
sys/arch/xen/xen/shutdown_xenbus.c: revision 1.1
sys/arch/xen/xenbus/xenbus_probe.c: revision 1.13
sys/arch/xen/include/shutdown_xenbus.h: revision 1.1
"xm shutdown" support for xen3. ok'ed by Manuel Bouyer.
 1.1.6.1 11-Aug-2006  ghen file shutdown_xenbus.h was added on branch netbsd-3 on 2006-09-08 10:27:36 +0000
 1.1.2.2 11-Aug-2006  yamt sync with head
 1.1.2.1 11-Aug-2006  yamt file shutdown_xenbus.h was added on branch yamt-pdpolicy on 2006-08-11 15:43:16 +0000
 1.3.34.1 27-Aug-2011  jym Rename the functions for suspend to reflect that Xen does not hijack
the ACPI "sleepstate" sysctl(7) node anymore.

Add a boolean value to mark that the save/suspend operation has been
notified by dom0, so as to avoid possible errors where admin would like
to schedule the domain for sleep without dom0 being prepared for that. Fail
with EAGAIN in this case.

Sprinkle some KNF.
 1.4.2.1 30-Oct-2012  yamt sync with head
 1.10 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.9 08-Jan-2008  joerg Switch Xen to generic TODR. Tested by Manuel Bouyer.
 1.8 04-Jan-2008  yamt i386:
- make tss per-cpu. this considerably speeds up context switch for,
at least, pentium4, where ltr instruction seems very slow.
i386, xen:
- kill cpu_maxproc.
kvm86:
- adapt to per-cpu tss.
- cleanup and simplify.
- move kvm86_mp_lock to more meaningful place.
- disable preemption during a call.
 1.7 17-Oct-2007  garbled branches: 1.7.2; 1.7.8;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.6 14-Jul-2007  ad branches: 1.6.10;
Generic soft interrupts are mandatory.
 1.5 12-May-2007  jld Convert the xen port to use timecounters; ok'ed by bouyer@.
 1.4 09-Feb-2007  ad branches: 1.4.2; 1.4.6; 1.4.8; 1.4.14;
Merge newlock2 to head.
 1.3 03-Sep-2006  bjh21 branches: 1.3.2; 1.3.4; 1.3.8; 1.3.10;
Nothing in the kernel now tests __HAVE_NWSCONS, so stop defining it everywhere.
 1.2 07-Jun-2006  kardel branches: 1.2.4; 1.2.6; 1.2.8;
no timecounters yet - provide a local types.h
 1.1 30-Apr-2006  kardel branches: 1.1.2;
file types.h was initially added on branch simonb-timecounters.
 1.1.2.1 30-Apr-2006  kardel - provide no timecounter version of types.h as
XEN derivitives have not yet been converted
 1.2.8.3 14-Sep-2006  yamt sync with head.
 1.2.8.2 26-Jun-2006  yamt sync with head.
 1.2.8.1 07-Jun-2006  yamt file types.h was added on branch yamt-pdpolicy on 2006-06-26 12:45:40 +0000
 1.2.6.7 21-Jan-2008  yamt sync with head
 1.2.6.6 03-Sep-2007  yamt sync with head.
 1.2.6.5 26-Feb-2007  yamt sync with head.
 1.2.6.4 30-Dec-2006  yamt define __HAVE_LAZY_MBUF.
 1.2.6.3 30-Dec-2006  yamt sync with head.
 1.2.6.2 21-Jun-2006  yamt sync with head.
 1.2.6.1 07-Jun-2006  yamt file types.h was added on branch yamt-lazymbuf on 2006-06-21 14:58:15 +0000
 1.2.4.2 19-Jun-2006  chap Sync with head.
 1.2.4.1 07-Jun-2006  chap file types.h was added on branch chap-midi on 2006-06-19 03:45:36 +0000
 1.3.10.1 03-Sep-2007  wrstuden Sync w/ NetBSD-4-RC_1
 1.3.8.1 10-Jun-2007  bouyer Pull up following revision(s) (requested by jld in ticket #711):
sys/arch/xen/xen/clock.c: revision 1.35 via patch
sys/arch/xen/include/types.h: revision 1.5 via patch
sys/arch/xen/i386/machdep.c: revision 1.38 via patch
sys/arch/xen/conf/files.xen: revision 1.60 via patch
sys/arch/xen/include/cpu.h: revision 1.19 via patch
Convert the xen port to use timecounters; ok'ed by bouyer@.
 1.3.4.2 09-Sep-2006  rpaulo sync with head
 1.3.4.1 03-Sep-2006  rpaulo file types.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:44:56 +0000
 1.3.2.1 29-Dec-2006  ad Checkpoint work in progress.
 1.4.14.2 03-Oct-2007  garbled Sync with HEAD
 1.4.14.1 22-May-2007  matt Update to HEAD.
 1.4.8.1 11-Jul-2007  mjf Sync with head.
 1.4.6.2 15-Jul-2007  ad Sync with head.
 1.4.6.1 27-May-2007  ad Sync with head.
 1.4.2.1 17-May-2007  yamt sync with head.
 1.6.10.3 23-Mar-2008  matt sync with HEAD
 1.6.10.2 09-Jan-2008  matt sync with HEAD
 1.6.10.1 06-Nov-2007  matt sync with HEAD
 1.7.8.2 10-Jan-2008  bouyer Change xeni386 build to match xenamd64:
- machine/ points to xen/include/i386
- remove includes that were identical to the i386/include/ ones; the build
will find them though the xen-ma/machine link.
- include xen files using xen/ not machine/
 1.7.8.1 08-Jan-2008  bouyer Sync with HEAD
 1.7.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.1 06-Mar-2007  yamt branches: 1.1.4; 1.1.24;
fix vcpu after recent cpubus changes.
 1.1.24.2 03-Sep-2007  yamt sync with head.
 1.1.24.1 06-Mar-2007  yamt file vcpuvar.h was added on branch yamt-lazymbuf on 2007-09-03 14:31:35 +0000
 1.1.4.2 12-Mar-2007  rmind Sync with HEAD (missed new files in previous).
 1.1.4.1 06-Mar-2007  rmind file vcpuvar.h was added on branch yamt-idlelwp on 2007-03-12 06:14:50 +0000
 1.3 09-Mar-2005  bouyer Merge the bouyer-xen2 branch. This add supports for the Xen 2.0 virtual
machine kernel (both privileged and non-privileged domains), and remove support
for the old xen 1.2.
 1.2 24-Apr-2004  cl branches: 1.2.2; 1.2.4; 1.2.8; 1.2.10; 1.2.12;
remove trailing empty lines
 1.1 24-Apr-2004  cl Add vga display support.
 1.2.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.10.1 29-Apr-2005  kent sync with -current
 1.2.8.1 08-Mar-2005  bouyer Add support for ISA bus.
Clean up console attachement, and add support for VGA/pckbc console.
Add support for USB devices, including USB audio (which means others audio
devices should work too)
Add some more generic options to XEN0.
 1.2.4.5 01-Apr-2005  skrll Sync with HEAD.
 1.2.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.2.4.2 03-Aug-2004  skrll Sync with HEAD
 1.2.4.1 24-Apr-2004  skrll file vga_xenvar.h was added on branch ktrace-lwp on 2004-08-03 10:43:11 +0000
 1.2.2.2 22-May-2004  he Pull up revisions 1.1-1.2 (requested by cl in ticket #337):
Upgrade xen support:
- add block device driver
- network device driver bug fixes
- support for vga/keyboard/mouse
- support for domain0 operations
- fix /dev/mem and i386_iopl, reboot, event dispatch
- fix clock support, cpu speed report, lazy fpu switching
- add xen12load loader
- sys/arch/xen parts of build.sh release support
[cl, ticket #337]
 1.2.2.1 24-Apr-2004  he file vga_xenvar.h was added on branch netbsd-2-0 on 2004-05-22 15:57:25 +0000
 1.3 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.2 18-Oct-2007  yamt branches: 1.2.2; 1.2.8;
merge yamt-x86pmap branch.

- reduce differences between amd64 and i386. notably, share pmap.c
between them. it makes several i386 pmap improvements available to
amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
- implement deferred pmap switching for amd64.
- remove LARGEPAGES option. always use large pages if available.
also, make it work on amd64.
 1.1 22-Nov-2005  yamt branches: 1.1.2; 1.1.4; 1.1.22; 1.1.36; 1.1.54; 1.1.56; 1.1.58; 1.1.60;
simplify memory layout.
 1.1.60.1 25-Oct-2007  bouyer Sync with HEAD.
 1.1.58.1 24-Sep-2007  yamt a hack to make xen kernels at least buildable.
 1.1.56.2 23-Mar-2008  matt sync with HEAD
 1.1.56.1 06-Nov-2007  matt sync with HEAD
 1.1.54.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.1.36.1 23-Oct-2007  ad Sync with head.
 1.1.22.4 21-Jan-2008  yamt sync with head
 1.1.22.3 27-Oct-2007  yamt sync with head.
 1.1.22.2 21-Jun-2006  yamt sync with head.
 1.1.22.1 22-Nov-2005  yamt file vmparam.h was added on branch yamt-lazymbuf on 2006-06-21 14:58:15 +0000
 1.1.4.2 11-Dec-2005  christos Sync with head.
 1.1.4.1 22-Nov-2005  christos file vmparam.h was added on branch ktrace-lwp on 2005-12-11 10:28:46 +0000
 1.1.2.2 22-Nov-2005  yamt sync with head.
 1.1.2.1 22-Nov-2005  yamt file vmparam.h was added on branch yamt-readahead on 2005-11-22 16:08:06 +0000
 1.2.8.1 11-Dec-2007  bouyer Switch i386 to x86/x86/pmap.c
 1.2.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.17 02-May-2015  mlelstv Merge dk_intf and dkdriver interfaces.
Merge common disk driver functionality in ld.c with dksubr.c.
Adjust the two previous users of dk_intf (cgd and xbd) to
the changes.

bump kernel version to 7.99.14
 1.16 14-Apr-2015  riastradh Include <sys/rndsource.h> where it is actually used.

I had removed <sys/rnd.h> from files that didn't mention anything of
the rnd(9) API. But they included other files which assumed
<sys/rnd.h> had already been included.
 1.15 20-Mar-2014  skrll branches: 1.15.6;
Mechanically replace simplelock with kmutex_t.
 1.14 02-Feb-2012  tls branches: 1.14.6; 1.14.10;
Entropy-pool implementation move and cleanup.

1) Move core entropy-pool code and source/sink/sample management code
to sys/kern from sys/dev.

2) Remove use of NRND as test for presence of entropy-pool code throughout
source tree.

3) Remove use of RND_ENABLED in device drivers as microoptimization to
avoid expensive operations on disabled entropy sources; make the
rnd_add calls do this directly so all callers benefit.

4) Fix bug in recent rnd_add_data()/rnd_add_uint32() changes that might
have lead to slight entropy overestimation for some sources.

5) Add new source types for environmental sensors, power sensors, VM
system events, and skew between clocks, with a sample implementation
for each.

ok releng to go in before the branch due to the difficulty of later
pullup (widespread #ifdef removal and moved files). Tested with release
builds on amd64 and evbarm and live testing on amd64.
 1.13 19-Nov-2011  tls branches: 1.13.2;
First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>. This change includes
the following:

An initial cleanup and minor reorganization of the entropy pool
code in sys/dev/rnd.c and sys/dev/rndpool.c. Several bugs are
fixed. Some effort is made to accumulate entropy more quickly at
boot time.

A generic interface, "rndsink", is added, for stream generators to
request that they be re-keyed with good quality entropy from the pool
as soon as it is available.

The arc4random()/arc4randbytes() implementation in libkern is
adjusted to use the rndsink interface for rekeying, which helps
address the problem of low-quality keys at boot time.

An implementation of the FIPS 140-2 statistical tests for random
number generator quality is provided (libkern/rngtest.c). This
is based on Greg Rose's implementation from Qualcomm.

A new random stream generator, nist_ctr_drbg, is provided. It is
based on an implementation of the NIST SP800-90 CTR_DRBG by
Henric Jungheim. This generator users AES in a modified counter
mode to generate a backtracking-resistant random stream.

An abstraction layer, "cprng", is provided for in-kernel consumers
of randomness. The arc4random/arc4randbytes API is deprecated for
in-kernel use. It is replaced by "cprng_strong". The current
cprng_fast implementation wraps the existing arc4random
implementation. The current cprng_strong implementation wraps the
new CTR_DRBG implementation. Both interfaces are rekeyed from
the entropy pool automatically at intervals justifiable from best
current cryptographic practice.

In some quick tests, cprng_fast() is about the same speed as
the old arc4randbytes(), and cprng_strong() is about 20% faster
than rnd_extract_data(). Performance is expected to improve.

The AES code in src/crypto/rijndael is no longer an optional
kernel component, as it is required by cprng_strong, which is
not an optional kernel component.

The entropy pool output is subjected to the rngtest tests at
startup time; if it fails, the system will reboot. There is
approximately a 3/10000 chance of a false positive from these
tests. Entropy pool _input_ from hardware random numbers is
subjected to the rngtest tests at attach time, as well as the
FIPS continuous-output test, to detect bad or stuck hardware
RNGs; if any are detected, they are detached, but the system
continues to run.

A problem with rndctl(8) is fixed -- datastructures with
pointers in arrays are no longer passed to userspace (this
was not a security problem, but rather a major issue for
compat32). A new kernel will require a new rndctl.

The sysctl kern.arandom() and kern.urandom() nodes are hooked
up to the new generators, but the /dev/*random pseudodevices
are not, yet.

Manual pages for the new kernel interfaces are forthcoming.
 1.12 23-Oct-2009  snj branches: 1.12.12;
Remove 3rd and 4th clauses. OK cl@ (copyright holder).
 1.11 16-Apr-2008  cegger branches: 1.11.4; 1.11.18;
device_t / softc split
reviewed, tested and approved by bouyer
 1.10 11-Jan-2008  bouyer branches: 1.10.6;
Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.9 05-May-2006  jld branches: 1.9.38; 1.9.44; 1.9.52;
Suspend/resume support for xbd -- keep enough info on live I/O to replay.

The rest of suspend/resume isn't there yet, but the parts that touch
regular usage have been tested. Discussed on port-xen on 2006-04-25;
approved by bouyer@.
 1.8 11-Dec-2005  christos branches: 1.8.4; 1.8.6; 1.8.8; 1.8.10; 1.8.12;
merge ktrace-lwp.
 1.7 09-Mar-2005  bouyer branches: 1.7.4;
Merge the bouyer-xen2 branch. This add supports for the Xen 2.0 virtual
machine kernel (both privileged and non-privileged domains), and remove support
for the old xen 1.2.
 1.6 15-Sep-2004  tls branches: 1.6.4; 1.6.6; 1.6.8;
Actually mix samples into the kernel RNG pool. There's a buglet here: all
disk samples are reported as belonging to the first disk.
 1.5 07-May-2004  cl branches: 1.5.2; 1.5.4;
add support for hot-add/-remove of block devices
 1.4 24-Apr-2004  cl Add sysctl nodes for Xen disk cookies used by domain creation tools.
 1.3 24-Apr-2004  cl Allow the block device driver to impersonate wd/sd/cd devices. This allows
for most system seamless migration from a NetBSD/i386 setup to a NetBSD/xen
setup without changing /etc/fstab or creating additional device nodes.
 1.2 24-Apr-2004  cl Add ``hypervisor at mainbus'' and attach all devices provided by the
hypervisor to it instead of mainbus.

rename arch/xen/i386/hypervisor.c -> arch/xen/i386/hypervisor_machdep.c
 1.1 17-Apr-2004  cl add block device driver
 1.5.4.5 01-Apr-2005  skrll Sync with HEAD.
 1.5.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.5.4.2 03-Aug-2004  skrll Sync with HEAD
 1.5.4.1 07-May-2004  skrll file xbdvar.h was added on branch ktrace-lwp on 2004-08-03 10:43:11 +0000
 1.5.2.3 16-Sep-2004  jmc Pullup rev 1.6 (requested by tls in ticket #846)

Actually mix samples into the kernel RNG pool.
 1.5.2.2 22-May-2004  he Pull up revisions 1.1-1.5 (requested by cl in ticket #337):
Upgrade xen support:
- add block device driver
- network device driver bug fixes
- support for vga/keyboard/mouse
- support for domain0 operations
- fix /dev/mem and i386_iopl, reboot, event dispatch
- fix clock support, cpu speed report, lazy fpu switching
- add xen12load loader
- sys/arch/xen parts of build.sh release support
[cl, ticket #337]
 1.5.2.1 07-May-2004  he file xbdvar.h was added on branch netbsd-2-0 on 2004-05-22 15:58:45 +0000
 1.6.8.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.6.6.1 29-Apr-2005  kent sync with -current
 1.6.4.2 18-Jan-2005  bouyer xbd_scan_finish() is dead.
 1.6.4.1 13-Dec-2004  bouyer Commit files from netbsd-2.0-xen-sparse/sys/arch/xen in the Xen-2.0
distribution. These are the files modified from the 2.0 tree to get
NetBSD/xen working with Xen 2.
 1.7.4.2 21-Jan-2008  yamt sync with head
 1.7.4.1 21-Jun-2006  yamt sync with head.
 1.8.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.8.10.1 11-May-2006  elad sync with head
 1.8.8.1 24-May-2006  yamt sync with head.
 1.8.6.1 01-Jun-2006  kardel Sync with head.
 1.8.4.1 09-Sep-2006  rpaulo sync with head
 1.9.52.1 08-Jan-2008  bouyer Make XEN kernels build again.
 1.9.44.1 18-Feb-2008  mjf Sync with HEAD.
 1.9.38.1 23-Mar-2008  matt sync with HEAD
 1.10.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.11.18.1 01-Nov-2009  jym Sync with HEAD.
 1.11.4.1 11-Mar-2010  yamt sync with head
 1.12.12.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.12.12.1 17-Apr-2012  yamt sync with head
 1.13.2.1 18-Feb-2012  mrg merge to -current.
 1.14.10.1 18-May-2014  rmind sync with head
 1.14.6.2 03-Dec-2017  jdolecek update from HEAD
 1.14.6.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.15.6.1 06-Jun-2015  skrll Sync with HEAD
 1.48 24-Mar-2023  bouyer Allow a PVH dom0 to use VGA as console: make xen_pvh_consinit() return 1 if
it handles the console and 0 otherwise (especially when console=tty0 or
console=pc is present on the command line).
In consinit() fallback to native console selection if xen_pvh_consinit()
returns 0.
 1.47 02-May-2020  bouyer branches: 1.47.20;
Introduce Xen PVH support in GENERIC.
This is compiled in with
options XENPVHVM
x86 changes:
- add Xen section and xen pvh entry points to locore.S. Set vm_guest
to VM_GUEST_XENPVH in this entry point.
Most of the boot procedure (especially page table setup and switch to
paged mode) is shared with native.
- change some x86_delay() to delay_func(), which points to x86_delay() for
native/HVM, and xen_delay() for PVH

Xen changes:
- remove Xen bits from init_x86_64_ksyms() and init386_ksyms()
and move to xen_init_ksyms(), used for both PV and PVH
- set ISA no-legacy-devices property for PVH
- factor out code from Xen's cpu_bootconf() to xen_bootconf()
in xen_machdep.c
- set up a specific pvh_consinit() which starts with printk()
(which uses a simple hypercall that is available early) and switch to
xencons when we can use pmap_kenter_pa().
 1.46 25-Apr-2020  bouyer Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.45 09-Apr-2020  jdolecek update to __XEN_INTERFACE_VERSION__ 0x0003020a aka Xen 3.2.10

this brings grant memory v2 support:
- status separated from flags - revoking access needs just memory barrier,
no need for expensive cmpxchg16 any more
- sub-page hypervisor copy-only grants, to be used by xennet(4)
- 64-bit frame, i.e. support for DomU RAM >16TB

the grant table is now always allocated on boot to maximum size, it's now
never grown in runtime; switch back to regular kmem_alloc()/kmem_free()

code now requires v2 support, no compatibility for grant version 1 retained -
Xen v2 support predates all currently supported Xen versions

also interface for baloon changed slightly, code updated
 1.44 09-May-2019  bouyer branches: 1.44.8;
sti/cli are not allowed on Xen, we have to clear/set a bit in the
shared page. Revert x86_disable_intr/x86_enable_intr to plain function
calls on XENPV.
While there, clean up unused functions and macros, and change cli()/sti()
macros to x86_disable_intr/x86_enable_intr.
Makes Xen domU boot again
(http://www-soc.lip6.fr/~bouyer/NetBSD-tests/xen/HEAD/)
 1.43 04-Feb-2019  cherry Bump up XEN source API compatibility to 0x00030208 from 0x00030201,

but maintain backwards source API compilation compatibility.

ie; sources with config(5)
options __XEN_INTERFACE_VERSION__=0x00030201 # Xen 3.1 interface

should compile and run without problems.

Not that API version 0x00030201 is the lowest version we support now.
 1.42 02-Feb-2019  cherry Switch NetBSD/xen to use XEN api tag RELEASE-4.11.1

The headers for this api are in sys/external/mit/xen-include-public/dist/
 1.41 10-Oct-2018  cherry In xen_atomic_test_and_clear_bit()

Use the appropriate sized variable for inline assembler.
 1.40 07-Oct-2018  mlelstv Support bootspec.
 1.39 26-Jul-2018  maxv Merge the content of xen_debug.c into xen_machdep.c, there is only one
function.
 1.38 26-Jul-2018  maxv Remove dead code. This looks like a leftover from when our Xen port was
being developed (2004), and it seems to have been copied from the Xen
kernel examples. It can't have any use, so get rid of it. Also remove
vprintk, unused.
 1.37 07-Jul-2016  msaitoh branches: 1.37.10; 1.37.16; 1.37.18;
KNF. Remove extra spaces. No functional change.
 1.36 29-May-2016  bouyer Switch to elf notes for amd64 instead of the old key=value list to describe the
guest requirements and support.
Add infrastructure to query the hypervisor about features support.
For verbose boot, print the features suppoted by the hypervisor for this
guest.
 1.35 20-Sep-2011  jym branches: 1.35.12; 1.35.30;
Merge jym-xensuspend branch in -current. ok bouyer@.

Goal: save/restore support in NetBSD domUs, for i386, i386 PAE and amd64.

Executive summary:
- split all Xen drivers (xenbus(4), grant tables, xbd(4), xennet(4))
in two parts: suspend and resume, and hook them to pmf(9).
- modify pmap so that Xen hypervisor does not cry out loud in case
it finds "unexpected" recursive memory mappings
- provide a sysctl(7), machdep.xen.suspend, to command suspend from
userland via powerd(8). Note: a suspend can only be handled correctly
when dom0 requested it, so provide a mechanism that will prevent
kernel to blindly validate user's commands

The code is still in experimental state, use at your own risk: restore
can corrupt backend communications rings; this can completely thrash
dom0 as it will loop at a high interrupt level trying to honor
all domU requests.

XXX PAE suspend does not work in amd64 currently, due to (yet again!)
page validation issues with hypervisor. Will fix.

XXX secondary CPUs are not suspended, I will write the handlers
in sync with cherry's Xen MP work.

Tested under i386 and amd64, bear in mind ring corruption though.

No build break expected, GENERICs and XEN* kernels should be fine.
./build.sh distribution still running. In any case: sorry if it does
break for you, contact me directly for reports.
 1.34 17-Jul-2011  joerg Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.33 17-Apr-2011  mrg apply some _KERNEL_OPT.
 1.32 29-Jul-2009  cegger branches: 1.32.4; 1.32.6;
remove Xen2 support.
ok bouyer@
 1.31 13-Feb-2009  bouyer Work in progress on PCI front-end/back-end support
front-end:
- add a xpci* at xenbus? which provides pci busses from the dom0
xpci provides support routines for PCI config space operations and
enumeration in xpci_xenbus.c
- hypervisor.c: do dom0-style PCI attach only ifdef DOM0OPS
- pci_intr_machdep.c: check line value only if DOM0OPS

back-end:
- add a pciback* at pci? device which takes precedences over all
other PCI devices (match return 500) and matches all devices passed
to pciback.hide option on boot command line.
It exports the PCI device informations to files in /kern/xen/pci/
- hypervisor.c: create /kern/xen earlier so pciback can create its
entries while PCI devices are probed
- xen_machdep.c: add handling for pciback.hide=

frontend is know working on Xen 3.1.x dom0 with ahc(4) and pciide(4)
devices. uhci(4) fail when trying to allocate a large contigous DMA
buffer.

backend is work in progress; support in xentools is not there yet.
 1.30 21-Oct-2008  cegger branches: 1.30.2; 1.30.4; 1.30.8; 1.30.12;
introduce two macros: xendomain_is_dom0() and xendomain_is_privileged(). Use them.
 1.29 21-Apr-2008  cegger branches: 1.29.2; 1.29.8;
Access Xen's vcpu info structure per-CPU.
Tested on i386 and amd64 (both dom0 and domU) by me.
Xen2 tested (both dom0 and domU) by bouyer.
OK bouyer
 1.28 19-Feb-2008  bouyer branches: 1.28.6; 1.28.8;
The event bitmasks provided by the hypervisor are unsigned long (so 64bits
on amd64). Make sure to use the right type to store and manipulate them.
This fixes amd64, where basically any event channel > 31 was not working
(and you get there after starting/stopping a domU a few times). Things
would occasionally unwedge though the spllower() callbacks.
 1.27 19-Feb-2008  bouyer Fix xenevt to not call softint_schedule() above IPL_HIGH:
Register a ipl callback for IPL_HIGH.
if the current ipl level is too high, just record the event in a bitmap,
and record IPL_HIGH as pending. The callback will process the pending events.
 1.26 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.25 22-Nov-2007  bouyer branches: 1.25.6;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.24 17-Oct-2007  garbled branches: 1.24.2;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.23 26-Sep-2007  ad branches: 1.23.2;
x86 changes for pcc and LKMs.

- Replace most inline assembly with proper functions. As a side effect
this reduces the size of amd64 GENERIC by about 120kB, and i386 by a
smaller amount. Nearly all of the inlines did something slow, or something
that does not need to be fast.
- Make curcpu() and curlwp functions proper, unless __GNUC__ && _KERNEL.
In that case make them inlines. Makes curlwp LKM and preemption safe.
- Make bus_space and bus_dma more LKM friendly.
- Share a few more files between the ports.
- Other minor changes.
 1.22 23-Sep-2007  bouyer branches: 1.22.2;
Ajust for Xen 3.1.0 public headers. From Christoph Egger in private mail.
 1.21 06-Mar-2006  bouyer branches: 1.21.22; 1.21.30; 1.21.40; 1.21.42;
Add xen_atomic_cmpxchg16(), which exports the cmpxchgw instruction to C.
 1.20 16-Feb-2006  perry branches: 1.20.2;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.19 15-Jan-2006  bouyer branches: 1.19.2; 1.19.4;
Snapshot of work in progress on NetBSD port to Xen3:
- kernel (both dom0 and domU) boot, console is functionnal and it can starts
software from a ramdisk
- there is no driver front-end expect console for domU yet.
- dom0 can probe devices and ex(4) work when Xen3 is booted without acpi
and apic support. But the on-board IDE doens't get interrupts.
The PCI code still needs work (it's hardcoded to mode 1). Some of this
code should be shared with ../x86
The physical insterrupt code needs to get MPBIOS and ACPI support, and
do interrupt routing to properly interract with Xen.
To enable Xen-3.0 support, add
options XEN3
to your kernel config file (this will disable Xen2 support)
Changes affecting Xen-2.0 support (no functionnal changes intended):
- get more constants from genassym for assembly code
- remove some unneeded registers move from start()
- map the shared info page from start(), and remove the pte = 0xffffffff hack
- vector.S: in hypervisor_callback() make sure %esi points to
HYPERVISOR_shared_info before accessing the info page. Remplace some
hand-written assembly with the equivalent macro defined in frameasm.h
- more debug code, dissabled by default.

while here added my copyright on some files I worked on in 2005.
 1.18 24-Dec-2005  perry branches: 1.18.2;
__asm__ -> __asm
__const__ -> const
__inline__ -> inline
__volatile__ -> volatile
 1.17 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.16 11-Dec-2005  christos merge ktrace-lwp.
 1.15 15-Jun-2005  bouyer branches: 1.15.2;
Add support for x86 boot flags:
-s boot single user
-a ask root device
XXX -d is ifdef'd out for now, it cause early panic (no console message).
 1.14 31-May-2005  yamt always provide prototype of printk for now. because:
- currently its implementation is always compiled in.
- there're users which don't honor XENDEBUG.
 1.13 31-May-2005  yamt x86_variable_test_bit: don't remove const qualifier unnecessarily.
 1.12 11-Apr-2005  yamt fix a bug which corrupts runqueue.
when dealing with events, which are handed to xenevt pseudo device,
don't call wakeup(9)/selnotify(9) at too high IPL. PR/29792.
 1.11 26-Mar-2005  bouyer Don't assume we're on a uniprocessor system (the hypervisor may be running SMP)
and add "lock;" barrier to avoid instruction reordering in event handlings.
This fix the last issue with event loss I was getting on SMP systems.
 1.10 09-Mar-2005  bouyer branches: 1.10.2;
Merge the bouyer-xen2 branch. This add supports for the Xen 2.0 virtual
machine kernel (both privileged and non-privileged domains), and remove support
for the old xen 1.2.
 1.9 10-Dec-2004  christos branches: 1.9.2; 1.9.4; 1.9.6;
don't use va_list here; use _BSD_VA_LIST_ because we could be included
before va_list is defined. This is common practice for kernel header
files (syslog.h)
 1.8 14-Jun-2004  cl branches: 1.8.2;
cleanup low-level bit mangling code
 1.7 07-May-2004  cl Add support for domain0 operations:
- access to all physical memory
- access to hypervisor traps from userland
- setup/config Xen's network routing/firewall rules
 1.6 07-May-2004  cl cleanup debugging code
 1.5 26-Apr-2004  cl Move struct xen_netinfo into include/xen.h so that xen12load compiles again.
 1.4 24-Apr-2004  cl Make kernel command line parsing support additional keywords without
having to change existing code which calls the parser.
 1.3 24-Apr-2004  cl Consistently use xencons for eveything reffering to Xen's virtual console.

rename arch/xen/xen/console.c -> arch/xen/xen/xencons.c
 1.2 17-Apr-2004  cl - fix event dispatching for event 0
- use struct trapframe instead of struct pt_regs
 1.1 11-Mar-2004  cl branches: 1.1.2;
Add port to the Xen virtual machine monitor.
(see http://www.cl.cam.ac.uk/Research/SRG/netos/xen/)
 1.1.2.2 17-Jun-2004  tron Pull up revision 1.8 (requested by cl in ticket #498):
cleanup low-level bit mangling code
 1.1.2.1 22-May-2004  he Pull up revisions 1.2-1.7 (requested by cl in ticket #337):
Upgrade xen support:
- add block device driver
- network device driver bug fixes
- support for vga/keyboard/mouse
- support for domain0 operations
- fix /dev/mem and i386_iopl, reboot, event dispatch
- fix clock support, cpu speed report, lazy fpu switching
- add xen12load loader
- sys/arch/xen parts of build.sh release support
[cl, ticket #337]
 1.8.2.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.8.2.6 01-Apr-2005  skrll Sync with HEAD.
 1.8.2.5 18-Dec-2004  skrll Sync with HEAD.
 1.8.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.8.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.8.2.2 03-Aug-2004  skrll Sync with HEAD
 1.8.2.1 14-Jun-2004  skrll file xen.h was added on branch ktrace-lwp on 2004-08-03 10:43:11 +0000
 1.9.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.9.4.1 29-Apr-2005  kent sync with -current
 1.9.2.6 16-Feb-2005  bouyer Glue xen_shm and the block and network backends to the system.
 1.9.2.5 12-Feb-2005  bouyer Remove prototypes for xenvfr_init and xenmachmem_init
 1.9.2.4 31-Jan-2005  bouyer First pieces of domain control operations:
- use an up to date xenio.h
- update privcmd.c for newer ioctls (incomplete, some just return an error for
now)
- add a /dev/xenevt pseudo-device, which provide to userland an interface to
xen events
Now xend starts, and basic xm commands (such as list) work.
 1.9.2.3 18-Jan-2005  bouyer The wbinvd instruction can't be used with xen, it case a kernel trap.
Implement wbinvd() with MMUEXT_FLUSH_CACHE.
Make shared_info_t volatile.
 1.9.2.2 17-Dec-2004  bouyer Merge change from rev 1.9
 1.9.2.1 13-Dec-2004  bouyer Commit files from netbsd-2.0-xen-sparse/sys/arch/xen in the Xen-2.0
distribution. These are the files modified from the 2.0 tree to get
NetBSD/xen working with Xen 2.
 1.10.2.6 07-Apr-2006  tron Apply patch (requested by bouyer in ticket #1245):
Pull up Xen3 domU support. This adds support for the Xen-3 memory bootstrap,
xenstore, and block and network device frontend. Xen-3 support is turned
on by 'options XEN3', which disable Xen-2 support.
Changes affecting non-xen3 specific code:
- xbd and xennet at hypervisor now attaches with xbd_hypervisor and
xennet_hypervisor
- x86_atomic_* renamed to xen_atomic_*
- use genassim.cf to pull in more constant from include files for assembly
- Map the shared info page from locore.S instead of the 0xffffffff hack
in xen_machdep.c
- remove some unused code
- some __asm__ __volatile__ -> __asm volatile and __inline__ -> inline
- more debug code
 1.10.2.5 28-Jun-2005  tron Pull up revision 1.15 (requested by bouyer in ticket #481):
Add support for x86 boot flags:
-s boot single user
-a ask root device
XXX -d is ifdef'd out for now, it cause early panic (no console message).
 1.10.2.4 18-Jun-2005  tron Pull up revision 1.14 (requested by yamt in ticket #462):
always provide prototype of printk for now. because:
- currently its implementation is always compiled in.
- there're users which don't honor XENDEBUG.
 1.10.2.3 18-Jun-2005  tron Pull up revision 1.13 (requested by yamt in ticket #461):
x86_variable_test_bit: don't remove const qualifier unnecessarily.
 1.10.2.2 13-Apr-2005  tron Pull up revision 1.12 (requested by yamt in ticket #146):
fix a bug which corrupts runqueue.
when dealing with events, which are handed to xenevt pseudo device,
don't call wakeup(9)/selnotify(9) at too high IPL. PR/29792.
 1.10.2.1 30-Mar-2005  tron Pull up revision 1.11 (requested by bouyer in ticket #71):
Don't assume we're on a uniprocessor system (the hypervisor may be running SMP)
and add "lock;" barrier to avoid instruction reordering in event handlings.
This fix the last issue with event loss I was getting on SMP systems.
 1.15.2.5 27-Feb-2008  yamt sync with head.
 1.15.2.4 21-Jan-2008  yamt sync with head
 1.15.2.3 07-Dec-2007  yamt sync with head
 1.15.2.2 27-Oct-2007  yamt sync with head.
 1.15.2.1 21-Jun-2006  yamt sync with head.
 1.18.2.2 18-Feb-2006  yamt sync with head.
 1.18.2.1 01-Feb-2006  yamt sync with head.
 1.19.4.1 22-Apr-2006  simonb Sync with head.
 1.19.2.1 09-Sep-2006  rpaulo sync with head
 1.20.2.1 13-Mar-2006  yamt sync with head.
 1.21.42.3 23-Mar-2008  matt sync with HEAD
 1.21.42.2 09-Jan-2008  matt sync with HEAD
 1.21.42.1 06-Nov-2007  matt sync with HEAD
 1.21.40.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.21.40.1 02-Oct-2007  joerg Sync with HEAD.
 1.21.30.1 03-Oct-2007  garbled Sync with HEAD
 1.21.22.2 03-Dec-2007  ad Sync with HEAD.
 1.21.22.1 09-Oct-2007  ad Sync with head.
 1.22.2.1 06-Oct-2007  yamt sync with head.
 1.23.2.1 17-Oct-2007  bouyer Prepare for xenamd64:
- kill xen/i386/identcpu.c, use i386/i386/identcpu.c instead (with a few
#ifndef XEN)
- move some files that can be shared between i386 and amd64 from
xen/i386 to xen/x86 (or to xen/xen for non-cpu-specific code)
- split assembly out of xen/include/hypervisor.h to xen/include/hypercalls.h
- use <xen/...> instead of <machine/...> for cpu-independant include files.

more work needed here, i386-specific files should got out of arch/xen to
arch/xeni386, and more code shared with arch/i386.
 1.24.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.24.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.25.6.1 08-Jan-2008  bouyer Make XEN kernels build again.
 1.28.8.1 18-May-2008  yamt sync with head.
 1.28.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.28.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.29.8.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.29.2.2 19-Aug-2009  yamt sync with head.
 1.29.2.1 04-May-2009  yamt sync with head.
 1.30.12.1 21-Apr-2010  matt sync to netbsd-5
 1.30.8.8 27-Aug-2011  jym Rename the functions for suspend to reflect that Xen does not hijack
the ACPI "sleepstate" sysctl(7) node anymore.

Add a boolean value to mark that the save/suspend operation has been
notified by dom0, so as to avoid possible errors where admin would like
to schedule the domain for sleep without dom0 being prepared for that. Fail
with EAGAIN in this case.

Sprinkle some KNF.
 1.30.8.7 27-Aug-2011  jym (HEAD fix) _BSD_VA_LIST_ => va_list
 1.30.8.6 27-Aug-2011  jym Further sync with HEAD.
 1.30.8.5 02-May-2011  jym Sync with head.
 1.30.8.4 01-Nov-2009  jym - Upgrade suspend/resume code to comply with Xen2 removal.
- Add support for PAE domUs suspend/resume.
- Fix an issue regarding initialization of the xbd ring I/O that could end
badly during resume, with invalid block operations submitted to dom0 backend.

NetBSD supports PAE under x86_32 by considering the L2 page as being
4 pages long instead of 1.

Xen validates the page types during resume. Sadly, the hypervisor handles
alternative recursive mappings (== PG/PD entries pointing to pages other
than self) inadequately, which could lead to incorrect page pinning.

As a result, the important change with this patch is to clear these alternative
mappings during suspend, and reset them back to their former self upon
resume. For PAE, approx. all 4 PDIR_SLOT_PTEs could be considered as
alternative recursive mappings.

See comments in pmap.c for further details.

Now, let the testing and bug hunting begin.
 1.30.8.3 01-Nov-2009  jym Sync with HEAD.
 1.30.8.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.30.8.1 09-Feb-2009  jym Initial code for xen save/restore/migrate facilities.

- split the attach code of frontends in two half: one that is only needed
during autoconf(9) attach/detach phases, and one used at each save/restore
of device state (between suspend and resume).

Applies to hypervisor, xencons, xenbus, xbd, and xennet.

- add a rwlock(9) ("ptom_lock") to protect the different parts in the kernel
that manipulate MFNs (which could change between a suspend and a resume,
without the kernel noticing it). Parts that require MFNs acquire a reader lock,
while suspend code will acquire a writer lock to ensure that no-other parts
in kernel still use MFNs.

- integrate the suspend code with sysmon.

- various things in pmap(9), and clock.

TODO:
- factorize code a bit more inside frontends drivers.
- remove all alternative recursive (APDP_PDE) mappings found in PD/PT during
suspend, as Xen does not support them.
- abstract the ptom_lock locking, it is only required when kernel preemption
is enabled, or on MP systems.

Current code works mostly. You may experience difficulties in some corner
cases (dom0 warnings about xennet interface errors, and Xen tools failing to
validate NetBSD's alternative pmaps).
 1.30.4.1 03-Oct-2009  snj Pull up following revision(s) (requested by bouyer in ticket #1054):
sys/arch/xen/conf/files.xen: revision 1.93
sys/arch/xen/include/pci_machdep.h: revision 1.11
sys/arch/xen/include/xen.h: revision 1.31
sys/arch/xen/xen/hypervisor.c: revision 1.44
sys/arch/xen/xen/pci_intr_machdep.c: revision 1.8
sys/arch/xen/xen/pciback.c: revision 1.1
sys/arch/xen/xen/xen_machdep.c: revision 1.5
sys/arch/xen/xen/xpci_xenbus.c: revision 1.1
Work in progress on PCI front-end/back-end support
front-end:
- add a xpci* at xenbus? which provides pci busses from the dom0
xpci provides support routines for PCI config space operations and
enumeration in xpci_xenbus.c
- hypervisor.c: do dom0-style PCI attach only ifdef DOM0OPS
- pci_intr_machdep.c: check line value only if DOM0OPS
back-end:
- add a pciback* at pci? device which takes precedences over all
other PCI devices (match return 500) and matches all devices passed
to pciback.hide option on boot command line.
It exports the PCI device informations to files in /kern/xen/pci/
- hypervisor.c: create /kern/xen earlier so pciback can create its
entries while PCI devices are probed
- xen_machdep.c: add handling for pciback.hide=
frontend is know working on Xen 3.1.x dom0 with ahc(4) and pciide(4)
devices. uhci(4) fail when trying to allocate a large contigous DMA
buffer.
backend is work in progress; support in xentools is not there yet.
 1.30.2.1 03-Mar-2009  skrll Sync with HEAD.
 1.32.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.32.4.1 21-Apr-2011  rmind sync with head
 1.35.30.1 09-Jul-2016  skrll Sync with HEAD
 1.35.12.1 03-Dec-2017  jdolecek update from HEAD
 1.37.18.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.37.18.1 10-Jun-2019  christos Sync with HEAD
 1.37.16.2 20-Oct-2018  pgoyette Sync with head
 1.37.16.1 28-Jul-2018  pgoyette Sync with HEAD
 1.37.10.2 31-Jul-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1862):

sys/arch/xen/x86/xen_intr.c: revision 1.31 (patch)
sys/arch/xen/include/xen.h (apply patch)

xen_intr.c: Use kpreempt_disable/enable around access to curcpu().

curcpu() is not otherwise guaranteed to be stable at these points.

While here, nix nonsensical membars. This need only be synchronized
with interrupts on the same CPU.

Proposed on port-xen:
https://mail-index.netbsd.org/port-xen/2022/07/13/msg010250.html
 1.37.10.1 13-Oct-2018  martin Pull up following revision(s) (requested by mlelstv in ticket #1057):

sys/arch/xen/x86/autoconf.c: revision 1.20
sys/arch/xen/include/xen.h: revision 1.40

Support bootspec.
 1.44.8.2 20-Apr-2020  bouyer Sync with HEAD
 1.44.8.1 18-Apr-2020  bouyer Add PVHVM multiprocessor support:
We need the hypervisor to be set up before cpus attaches.
Move hypervisor setup to a new function xen_hvm_init(), called at the
beggining of mainbus_attach(). This function searches the cfdata[] array
to see if the hypervisor device is enabled (so you can disable PV
support with
disable hypervisor
from userconf).
For HVM, ci_cpuid doens't match the virtual CPU index needed by Xen.
Introduce ci_vcpuid to cpu_info. Introduce xen_hvm_init_cpu(), to be
called for each CPU in in its context, which initialize ci_vcpuid and
ci_vcpu, and setup the event callback.
Change Xen code to use ci_vcpuid.

Do not call lapic_calibrate_timer() for VM_GUEST_XENPVHVM, we will use
Xen timers.

Don't call lapic_initclocks() from cpu_hatch(); instead set
x86_cpu_initclock_func to lapic_initclocks() in lapic_calibrate_timer(),
and call *(x86_cpu_initclock_func)() from cpu_hatch().
Also call x86_cpu_initclock_func from cpu_attach() for the boot CPU.
As x86_cpu_initclock_func is called for all CPUs, x86_initclock_func can
be a NOP for lapic timer.

Reorganize Xen code for x86_initclock_func/x86_cpu_initclock_func.
Move x86_cpu_idle_xen() to hypervisor_machdep.c
 1.47.20.1 30-Mar-2023  martin Pull up following revision(s) (requested by bouyer in ticket #131):

sys/arch/x86/x86/consinit.c: revision 1.36
sys/arch/xen/x86/pvh_consinit.c: revision 1.3
sys/arch/xen/include/xen.h: revision 1.48

Allow a PVH dom0 to use VGA as console: make xen_pvh_consinit() return 1 if
it handles the console and 0 otherwise (especially when console=tty0 or
console=pc is present on the command line).

In consinit() fallback to native console selection if xen_pvh_consinit()
returns 0.
 1.12 25-Apr-2020  bouyer Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.11 19-Apr-2020  jdolecek change interface for xen_shm_map() so that caller always supplies the VA,
it now fails only if the Xen hypercall fails, in which case the failure
is final

change xbdback to pre-allocate KVA on xbdback attach (and free on detach),
so it has always KVA to map the request pages

remove no longer needed KVA allocation failure handling
 1.10 08-Jan-2019  jdolecek branches: 1.10.10;
remove explicit <machine/param.h> include, code including this already includes
<sys/param.h>
 1.9 19-Oct-2009  bouyer branches: 1.9.62; 1.9.64;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.8 29-Jul-2009  cegger remove Xen2 support.
ok bouyer@
 1.7 25-Jun-2006  bouyer branches: 1.7.62; 1.7.76;
Allow xen_shm_map() to map multiple grants in a contigous virtual address
space.
While here garbage-collect unused xen_shm_vaddr2ma()
 1.6 25-May-2006  bouyer branches: 1.6.2;
Convert xen_shm_map() and xen_shm_unmap() to the Xen3 grant table
interface.
 1.5 11-Dec-2005  christos branches: 1.5.4; 1.5.6; 1.5.8; 1.5.14;
merge ktrace-lwp.
 1.4 17-Jul-2005  tls Improvements to xbdback (the domain 0 driver that provides "xbd" virtual
disks to other domains) from Jed Davis, <jld@panix.com>:

* Issue multiple requests when necessary rather than
assuming that arbitrary requests can be mapped into single
contiguous virtual address ranges.

* Don't assume that all data for a request is consecutive
in memory. With some client OSes, it's not.

The above two changes fix data corruption issues with Linux
clients with certain filesystem block sizes.

* Gracefully handle memory or pool allocation failures after
beginning to handle a request from the ring.

* Merge contiguous requests to avoid the "64K turns into 44K + 20K
and doubles the transactions per second at the disk" problem
caused by the 11-page limit caused by the structure of Xen
ring entries. This causes a very slight performance decrease
for sequential 64K I/O if the disk is not already saturated with
requests (about 1%) but halves the transactions per second we
hit the disk with -- or better. It even compensates for bizarre
Linux behaviour like breaking long requests up into 5.5K pieces.

* Probably some stuff I forgot to mention.

Disk throughput (though not latency) is now much, much closer to the
"raw hardware" case than it was before.
 1.3 16-Apr-2005  yamt branches: 1.3.2; 1.3.4;
s/foreing/foreign/g
ok'ed by Manuel Bouyer.
 1.2 09-Mar-2005  bouyer branches: 1.2.2; 1.2.4; 1.2.6;
Merge the bouyer-xen2 branch. This add supports for the Xen 2.0 virtual
machine kernel (both privileged and non-privileged domains), and remove support
for the old xen 1.2.
 1.1 16-Feb-2005  bouyer branches: 1.1.2;
file xen_shm.h was initially added on branch bouyer-xen2.
 1.1.2.2 08-Mar-2005  bouyer Improve ressource shortage recovery: if xen_shm_map() fails, register a
callback wich will retry the I/O when xen_shm_unmap() is called.
 1.1.2.1 16-Feb-2005  bouyer Support functions to map/unmap guest's memory into our kernel VM space.
This will be used by the block and network back-end.
The caller provide a list of machine address pages, and we return the
address virtual address they've been mapped to. These mapping are not
registered to the pmap (we don't have physical addresses for these pages),
so change bus_dma(9) to handle these mappings as well.
 1.2.6.3 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.6.2 01-Apr-2005  skrll Sync with HEAD.
 1.2.6.1 09-Mar-2005  skrll file xen_shm.h was added on branch ktrace-lwp on 2005-04-01 14:29:10 +0000
 1.2.4.2 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.2.4.1 09-Mar-2005  yamt file xen_shm.h was added on branch yamt-km on 2005-03-19 08:33:26 +0000
 1.2.2.2 15-Aug-2005  tron Pull up revision 1.4 (requested by tls in ticket #656):
Improvements to xbdback (the domain 0 driver that provides "xbd" virtual
disks to other domains) from Jed Davis, <jld@panix.com>:
* Issue multiple requests when necessary rather than
assuming that arbitrary requests can be mapped into single
contiguous virtual address ranges.
* Don't assume that all data for a request is consecutive
in memory. With some client OSes, it's not.
The above two changes fix data corruption issues with Linux
clients with certain filesystem block sizes.
* Gracefully handle memory or pool allocation failures after
beginning to handle a request from the ring.
* Merge contiguous requests to avoid the "64K turns into 44K + 20K
and doubles the transactions per second at the disk" problem
caused by the 11-page limit caused by the structure of Xen
ring entries. This causes a very slight performance decrease
for sequential 64K I/O if the disk is not already saturated with
requests (about 1%) but halves the transactions per second we
hit the disk with -- or better. It even compensates for bizarre
Linux behaviour like breaking long requests up into 5.5K pieces.
* Probably some stuff I forgot to mention.
Disk throughput (though not latency) is now much, much closer to the
"raw hardware" case than it was before.
 1.2.2.1 21-Apr-2005  tron Pull up revision 1.3 (requested by yamt in ticket #173):
s/foreing/foreign/g
ok'ed by Manuel Bouyer.
 1.3.4.2 30-Dec-2006  yamt sync with head.
 1.3.4.1 21-Jun-2006  yamt sync with head.
 1.3.2.2 29-Apr-2005  kent sync with -current
 1.3.2.1 16-Apr-2005  kent file xen_shm.h was added on branch kent-audio2 on 2005-04-29 11:28:29 +0000
 1.5.14.1 19-Jun-2006  chap Sync with head.
 1.5.8.1 26-Jun-2006  yamt sync with head.
 1.5.6.1 01-Jun-2006  kardel Sync with head.
 1.5.4.1 09-Sep-2006  rpaulo sync with head
 1.6.2.1 13-Jul-2006  gdamore Merge from HEAD.
 1.7.76.1 01-Nov-2009  jym Sync with HEAD.
 1.7.62.2 11-Mar-2010  yamt sync with head
 1.7.62.1 19-Aug-2009  yamt sync with head.
 1.9.64.2 21-Apr-2020  martin Sync with HEAD
 1.9.64.1 10-Jun-2019  christos Sync with HEAD
 1.9.62.1 18-Jan-2019  pgoyette Synch with HEAD
 1.10.10.1 20-Apr-2020  bouyer Sync with HEAD
 1.25 25-Apr-2020  bouyer Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.24 11-Apr-2020  jdolecek put xenbus dmat into xenbus_device so it's available also for backend
devices which don't use autoconfig, remove from attach args
 1.23 10-Apr-2020  jdolecek add and pass dma tag to PV drivers attached to xenbus, so thay can
use bus_dmamap_load_mbuf() et.al.

due to XENPV override, _BUS_BUS_TO_PHYS() dmamap segment ds_addr
gets filled with ma, so value can be directly used for e.g. grant calls
 1.22 07-Apr-2020  jdolecek branches: 1.22.2;
add wrapper to free response from xenbus_dev_request_and_reply(), so
that call in xenbus_dev_write() wouldn't need to know how it's allocated
 1.21 07-Apr-2020  jdolecek add a small wrapper xenbus_directory_free() to free result of
xenbus_directory(), so that caller doesn't need to be aware how the memory
was allocated
 1.20 07-Apr-2020  jdolecek partially convert to kmem_alloc()

plug memory leak in one xenbus_probe_device_type() error path
when read_backend_details() fails
 1.19 07-Apr-2020  jdolecek convert the node watch code to use kmem_alloc() instead of malloc()
 1.18 07-Apr-2020  jdolecek make xenbus_watch_path() static, it's not used outside xenbus_client.c
 1.17 07-Apr-2020  jdolecek revert the watch.node change, xenbus_watch_path() and xenbus_watch_path2()
need to use non-constant path
 1.16 07-Apr-2020  jdolecek change xenbus_read() interface so that caller supplies the buffer and it's
size, caller doesn't free(9) the returned value any more
 1.15 07-Apr-2020  jdolecek no need to malloc()+copy watch.node, it's constant string - either "device"
or "backend"; just use the strings direct
 1.14 02-Feb-2019  cherry Switch NetBSD/xen to use XEN api tag RELEASE-4.11.1

The headers for this api are in sys/external/mit/xen-include-public/dist/
 1.13 07-Dec-2011  cegger branches: 1.13.48;
switch from xen3-public to xen-public.
 1.12 20-Sep-2011  jym branches: 1.12.2; 1.12.6;
Merge jym-xensuspend branch in -current. ok bouyer@.

Goal: save/restore support in NetBSD domUs, for i386, i386 PAE and amd64.

Executive summary:
- split all Xen drivers (xenbus(4), grant tables, xbd(4), xennet(4))
in two parts: suspend and resume, and hook them to pmf(9).
- modify pmap so that Xen hypervisor does not cry out loud in case
it finds "unexpected" recursive memory mappings
- provide a sysctl(7), machdep.xen.suspend, to command suspend from
userland via powerd(8). Note: a suspend can only be handled correctly
when dom0 requested it, so provide a mechanism that will prevent
kernel to blindly validate user's commands

The code is still in experimental state, use at your own risk: restore
can corrupt backend communications rings; this can completely thrash
dom0 as it will loop at a high interrupt level trying to honor
all domU requests.

XXX PAE suspend does not work in amd64 currently, due to (yet again!)
page validation issues with hypervisor. Will fix.

XXX secondary CPUs are not suspended, I will write the handlers
in sync with cherry's Xen MP work.

Tested under i386 and amd64, bear in mind ring corruption though.

No build break expected, GENERICs and XEN* kernels should be fine.
./build.sh distribution still running. In any case: sorry if it does
break for you, contact me directly for reports.
 1.11 29-Oct-2008  cegger branches: 1.11.6;
make this header standalone
 1.10 24-Oct-2008  jym branches: 1.10.2;
- rename init_events() to events_init(), to better reflect netbsd semantics

- change unbind_[pv]irq_from_evtch() so that they now return the event
channel the [PV]IRQ was bound to. It reflects the opposite behaviour of the
bind_[pv]irq_to_evtch() functions.

- remove xenbus_suspend() and xenbus_resume() prototypes, as they are not
used anywhere else, and will conflict with the xenbus pmf(9) handlers.

- make start_info aligned on a page boundary, as Xen expects it to be so.

- mask event channel during xbd detach before removing its handler (can
avoid spurious events).

- add the "protocol" entry in xenstore during xbd initialization. Normally
created during domU's boot by xentools, it is under domU's responsibility
in all other cases (save/restore, hot plugging, etc.).

- modifications to xs_init(), so that it can properly return an error.

Reviewed by Christoph (cegger@).
 1.9 16-Apr-2008  cegger branches: 1.9.4; 1.9.10;
device_t / softc split
reviewed, tested and approved by bouyer
 1.8 14-Mar-2008  ichiro make compile
- add xenbus_read_ull prototype into include/xenbus.h
 1.7 22-Nov-2007  bouyer branches: 1.7.10; 1.7.14;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.6 25-Jun-2006  bouyer branches: 1.6.6; 1.6.10; 1.6.16; 1.6.26; 1.6.34; 1.6.36; 1.6.40; 1.6.42;
Add a 'base' argument to xenbus_read_ul, so that we can read number is base
other than 10.
 1.5 23-May-2006  bouyer branches: 1.5.2; 1.5.4;
Add needed framework for backend drivers.
As we want some control on the name the backend driver will have we
can't use autoconf(9) here. Instead backend drivers registers to
xenbus, which will call a create callback when a new device is there.
Backend devices won't have a "struct device" in xenbus, use a void pointer
instead.
 1.4 26-Mar-2006  bouyer branches: 1.4.2; 1.4.4; 1.4.6;
Properly handle dynamic attach/detach of device:
- keep a linked list of xenbus_device in the xenbus_infrastructure, and
keep a pointer to struct device for each xenbus_device
- xenbus_probe_device_type(): check that the device is not already attached
- when we get a frontend_changed callback, call xenbus_probe_device_type()
- When a device changes to state XenbusStateClosed, config_detach() it
and free the structures.
While there, move xbusd_path[] to the end of struct xenbus_device, and
allocate only the space needed to store the path. Garbage-collect
struct xenbus_driver, it's not needed.
 1.3 16-Mar-2006  bouyer Add a xenbus_read_ul() which reads a node and convert it to unsigned long.
Make xenbus_switch_state() and xenbus_read_driver_state() do something usefull.
 1.2 15-Mar-2006  bouyer branches: 1.2.2;
Implement watch of xenstore nodes, and install watches for otherend'state
node.
 1.1 06-Mar-2006  bouyer branches: 1.1.2; 1.1.4;
Xenbus public functions
 1.1.4.5 26-Jun-2006  yamt sync with head.
 1.1.4.4 24-May-2006  yamt sync with head.
 1.1.4.3 01-Apr-2006  yamt sync with head.
 1.1.4.2 13-Mar-2006  yamt sync with head.
 1.1.4.1 06-Mar-2006  yamt file xenbus.h was added on branch yamt-pdpolicy on 2006-03-13 09:07:03 +0000
 1.1.2.1 19-Apr-2006  elad sync with head - hopefully this will work
 1.2.2.2 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.2.2.1 28-Mar-2006  tron Merge 2006-03-28 NetBSD-current into the "peter-altq" branch.
 1.4.6.1 19-Jun-2006  chap Sync with head.
 1.4.4.3 01-Jun-2006  kardel Sync with head.
 1.4.4.2 22-Apr-2006  simonb Sync with head.
 1.4.4.1 26-Mar-2006  simonb file xenbus.h was added on branch simonb-timecounters on 2006-04-22 11:38:11 +0000
 1.4.2.2 07-Apr-2006  tron Apply patch (requested by bouyer in ticket #1245):
Pull up Xen3 domU support. This adds support for the Xen-3 memory bootstrap,
xenstore, and block and network device frontend. Xen-3 support is turned
on by 'options XEN3', which disable Xen-2 support.
Changes affecting non-xen3 specific code:
- xbd and xennet at hypervisor now attaches with xbd_hypervisor and
xennet_hypervisor
- x86_atomic_* renamed to xen_atomic_*
- use genassim.cf to pull in more constant from include files for assembly
- Map the shared info page from locore.S instead of the 0xffffffff hack
in xen_machdep.c
- remove some unused code
- some __asm__ __volatile__ -> __asm volatile and __inline__ -> inline
- more debug code
 1.4.2.1 26-Mar-2006  tron file xenbus.h was added on branch netbsd-3 on 2006-04-07 12:51:26 +0000
 1.5.4.5 17-Mar-2008  yamt sync with head.
 1.5.4.4 07-Dec-2007  yamt sync with head
 1.5.4.3 30-Dec-2006  yamt sync with head.
 1.5.4.2 21-Jun-2006  yamt sync with head.
 1.5.4.1 23-May-2006  yamt file xenbus.h was added on branch yamt-lazymbuf on 2006-06-21 14:58:15 +0000
 1.5.2.1 13-Jul-2006  gdamore Merge from HEAD.
 1.6.42.1 08-Dec-2007  mjf Sync with HEAD.
 1.6.40.1 17-Oct-2007  bouyer Prepare for xenamd64:
- kill xen/i386/identcpu.c, use i386/i386/identcpu.c instead (with a few
#ifndef XEN)
- move some files that can be shared between i386 and amd64 from
xen/i386 to xen/x86 (or to xen/xen for non-cpu-specific code)
- split assembly out of xen/include/hypervisor.h to xen/include/hypercalls.h
- use <xen/...> instead of <machine/...> for cpu-independant include files.

more work needed here, i386-specific files should got out of arch/xen to
arch/xeni386, and more code shared with arch/i386.
 1.6.36.2 23-Mar-2008  matt sync with HEAD
 1.6.36.1 09-Jan-2008  matt sync with HEAD
 1.6.34.1 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.6.26.1 04-Sep-2008  skrll Sync with netbsd-4.
 1.6.16.1 03-Dec-2007  ad Sync with HEAD.
 1.6.10.1 31-Aug-2008  jdc Pull up revisions:
sys/arch/xen/include/xenbus.h:1.8
sys/arch/xen/xen/xbd_xenbus.c:1.24
sys/arch/xen/xen/xbdback_xenbus.c:1.15
sys/arch/xen/xenbus/xenbus_xs.c:1.14
via patch (requested by bouyer in ticket #1149).
 1.6.6.2 09-Sep-2006  rpaulo sync with head
 1.6.6.1 25-Jun-2006  rpaulo file xenbus.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:44:56 +0000
 1.7.14.3 17-Jan-2009  mjf Sync with HEAD.
 1.7.14.2 02-Jun-2008  mjf Sync with HEAD.
 1.7.14.1 03-Apr-2008  mjf Sync with HEAD.
 1.7.10.1 24-Mar-2008  keiichi sync with head.
 1.9.10.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.9.4.1 04-May-2009  yamt sync with head.
 1.10.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.11.6.3 01-Nov-2009  jym - Upgrade suspend/resume code to comply with Xen2 removal.
- Add support for PAE domUs suspend/resume.
- Fix an issue regarding initialization of the xbd ring I/O that could end
badly during resume, with invalid block operations submitted to dom0 backend.

NetBSD supports PAE under x86_32 by considering the L2 page as being
4 pages long instead of 1.

Xen validates the page types during resume. Sadly, the hypervisor handles
alternative recursive mappings (== PG/PD entries pointing to pages other
than self) inadequately, which could lead to incorrect page pinning.

As a result, the important change with this patch is to clear these alternative
mappings during suspend, and reset them back to their former self upon
resume. For PAE, approx. all 4 PDIR_SLOT_PTEs could be considered as
alternative recursive mappings.

See comments in pmap.c for further details.

Now, let the testing and bug hunting begin.
 1.11.6.2 01-Nov-2009  jym Sync with HEAD.
 1.11.6.1 31-May-2009  jym Modifications for the Xen suspend/migrate/resume branch:

- introduce xenbus_device_{suspend,resume}() functions. These are routines
used to suspend/resume MI parts of the Xenbus device interfaces, like updating
frontend/backend devices' paths found in XenStore.

- introduce HYPERVISOR_sysctl(), an hypercall used only by Xentools to obtain
information from hypervisor (listing VMs, printing console, etc.). I use it
to query xenconsole from ddb(), as a last resort in case of a panic() in
dom0 (xm being not available). Currently unused in the branch; could be, if
requested.

- disable the rwlock(9) used to protect code that could use transient MFNs.
It could trigger nasty context switches in place it should not to.

- fix some bugs in the xennet/xbd suspend/resume pmf(9) handlers.

- following XenSource's design, talk_to_otherend() is now called
watch_otherend(), and free_otherend_details() is used by Xenbus device
suspend/resume routines.

- some slight modifications in pmap regarding APDP. Introduce an inline
function (pmap_unmap_apdp_pde()) that clears APDP entry for the current pmap.

- similarly, implement pmap_unmap_all_apdp_pdes() that iterates through all
pmaps and tears down APDP, as Xen does not handle them properly.

TODO/XXX:

- pmap_unmap_apdp_pde() does not handle APDP shadow entry of PAE. It will,
once I figure out how PAE uses it.

- revisit the pmap locking issue regarding transient MFNs. As NetBSD does not
use kernel preemption and MP for Xen, this could be skipped momentarily. See
http://mail-index.netbsd.org/port-xen/2009/04/27/msg004903.html for details.

- fix a bug regarding grant tables which could technically DoS a dom0 if
ridiculously high consumer/producer indexes are passed down in the ring during
a resume.

All in all, once the grant table index issue and APDP PAE are fixed, next step
is to torture test this branch.

Tested under i386 PAE and non-PAE, Xen3 dom0 and domU. amd64 is only compile
tested.
 1.12.6.1 18-Feb-2012  mrg merge to -current.
 1.12.2.1 17-Apr-2012  yamt sync with head
 1.13.48.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.13.48.1 10-Jun-2019  christos Sync with HEAD
 1.22.2.1 20-Apr-2020  bouyer Sync with HEAD
 1.18 09-May-2019  bouyer sti/cli are not allowed on Xen, we have to clear/set a bit in the
shared page. Revert x86_disable_intr/x86_enable_intr to plain function
calls on XENPV.
While there, clean up unused functions and macros, and change cli()/sti()
macros to x86_disable_intr/x86_enable_intr.
Makes Xen domU boot again
(http://www-soc.lip6.fr/~bouyer/NetBSD-tests/xen/HEAD/)
 1.17 12-Feb-2019  cherry Move xen event related code which interfaces with the NetBSD interrupt
subsystem into a separate namespace where it can co-exist with the
native equivalent in PVHVM mode.

On PV, we alias and export the native symbols - this means that
although the namespace is different, the semantics must be identical.

Eg: xen_intr_establish_xname() vs. intr_establish_xname().

The specific functions we need in PVHVM are:

- spllower, xen_spllower (for native as well as XEN event spl
despatch/defer)
- xen_disable_intr()/xen_enable_intr() ,
x86_disable_intr()/x86_enable_intr()
- xen_read_psl()/xen_write_psl(),
x86_read_psl()/x86_write_psl()
- intr_establish() et. al, xen_intr_establish() et. al.

This gives us the ability to manage Paravirtualised drivers such as
xbd(4) as well as fully emulated ones such as wd(4)., for eg
 1.16 26-Jul-2018  maxv Retire XENDEBUG_LOW, and switch its only user to XENDEBUG.
 1.15 23-Oct-2009  snj branches: 1.15.62; 1.15.64;
Remove 3rd and 4th clauses. OK cl@ (copyright holder).
 1.14 11-Jan-2008  bouyer branches: 1.14.10; 1.14.24;
Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.13 22-Nov-2007  bouyer branches: 1.13.6;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.12 17-Oct-2007  garbled branches: 1.12.2;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.11 26-Sep-2007  ad branches: 1.11.2;
x86 changes for pcc and LKMs.

- Replace most inline assembly with proper functions. As a side effect
this reduces the size of amd64 GENERIC by about 120kB, and i386 by a
smaller amount. Nearly all of the inlines did something slow, or something
that does not need to be fast.
- Make curcpu() and curlwp functions proper, unless __GNUC__ && _KERNEL.
In that case make them inlines. Makes curlwp LKM and preemption safe.
- Make bus_space and bus_dma more LKM friendly.
- Share a few more files between the ports.
- Other minor changes.
 1.10 16-Feb-2006  perry branches: 1.10.24; 1.10.32; 1.10.42; 1.10.44; 1.10.46;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.9 24-Dec-2005  perry branches: 1.9.2; 1.9.4; 1.9.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.8 11-Dec-2005  christos merge ktrace-lwp.
 1.7 31-May-2005  yamt branches: 1.7.2;
constify.
 1.6 26-May-2005  bouyer Always call the xpq_queue*() functions at splvm(), so that it's safe to call
them from interrupt context.
xpq_flush_queue() is called from IPL_NET in if_xennet.c, and
other xpq_queue* functions may be called from interrupt context via
pmap_kenter*(). Should fix port-xen/30153.
Thanks to Jason Thorpe and YAMAMOTO Takashi for enlightments on this issue.
 1.5 22-Apr-2005  yamt don't use block scope static function decl. found by gcc4.
 1.4 09-Mar-2005  bouyer branches: 1.4.2;
Merge the bouyer-xen2 branch. This add supports for the Xen 2.0 virtual
machine kernel (both privileged and non-privileged domains), and remove support
for the old xen 1.2.
 1.3 10-Dec-2004  christos branches: 1.3.2; 1.3.4; 1.3.6;
Move the disable_intr and enable_intr functions from xenfunc.h to cpufunc.h,
because the x86/intr.h needs them and does not include xenfunc.h. Including
xenfunc.h in cpufunc.h is a clear lose because xenfunc.h needs a boatload
of include functions in order to compile.
 1.2 07-May-2004  cl branches: 1.2.2;
replace rdr6/ldr6 with the corresponding hypervisor traps
 1.1 11-Mar-2004  cl branches: 1.1.2;
Add port to the Xen virtual machine monitor.
(see http://www.cl.cam.ac.uk/Research/SRG/netos/xen/)
 1.1.2.1 22-May-2004  he Pull up revision 1.2 (requested by cl in ticket #337):
Upgrade xen support:
- add block device driver
- network device driver bug fixes
- support for vga/keyboard/mouse
- support for domain0 operations
- fix /dev/mem and i386_iopl, reboot, event dispatch
- fix clock support, cpu speed report, lazy fpu switching
- add xen12load loader
- sys/arch/xen parts of build.sh release support
[cl, ticket #337]
 1.2.2.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.2.6 01-Apr-2005  skrll Sync with HEAD.
 1.2.2.5 18-Dec-2004  skrll Sync with HEAD.
 1.2.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.2.2.2 03-Aug-2004  skrll Sync with HEAD
 1.2.2.1 07-May-2004  skrll file xenfunc.h was added on branch ktrace-lwp on 2004-08-03 10:43:11 +0000
 1.3.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.3.4.1 29-Apr-2005  kent sync with -current
 1.3.2.2 17-Dec-2004  bouyer Merge chanages from rev 1.3.
 1.3.2.1 13-Dec-2004  bouyer Commit files from netbsd-2.0-xen-sparse/sys/arch/xen in the Xen-2.0
distribution. These are the files modified from the 2.0 tree to get
NetBSD/xen working with Xen 2.
 1.4.2.3 18-Jun-2005  tron Pull up revision 1.7 (requested by yamt in ticket #464):
constify.
 1.4.2.2 28-May-2005  tron Pull up revision 1.6 (requested by bouyer in ticket #355):
Always call the xpq_queue*() functions at splvm(), so that it's safe to call
them from interrupt context.
xpq_flush_queue() is called from IPL_NET in if_xennet.c, and
other xpq_queue* functions may be called from interrupt context via
pmap_kenter*(). Should fix port-xen/30153.
Thanks to Jason Thorpe and YAMAMOTO Takashi for enlightments on this issue.
 1.4.2.1 01-May-2005  tron Pull up revision 1.5 (requested by yamt in ticket #233):
don't use block scope static function decl. found by gcc4.
 1.7.2.3 21-Jan-2008  yamt sync with head
 1.7.2.2 07-Dec-2007  yamt sync with head
 1.7.2.1 27-Oct-2007  yamt sync with head.
 1.9.6.1 22-Apr-2006  simonb Sync with head.
 1.9.4.1 09-Sep-2006  rpaulo sync with head
 1.9.2.1 18-Feb-2006  yamt sync with head.
 1.10.46.1 06-Oct-2007  yamt sync with head.
 1.10.44.3 23-Mar-2008  matt sync with HEAD
 1.10.44.2 09-Jan-2008  matt sync with HEAD
 1.10.44.1 06-Nov-2007  matt sync with HEAD
 1.10.42.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.10.42.1 02-Oct-2007  joerg Sync with HEAD.
 1.10.32.1 03-Oct-2007  garbled Sync with HEAD
 1.10.24.2 03-Dec-2007  ad Sync with HEAD.
 1.10.24.1 09-Oct-2007  ad Sync with head.
 1.11.2.2 21-Oct-2007  bouyer Factorise some Xen pmap code in x86_xpmap.c.
More xpmap_{ptom,mtop} -> xpmap_{ptom,mtop}_masked

The xenamd64 kernel is now good enough to complete a sysinst install from
xennet to xbd.
 1.11.2.1 17-Oct-2007  bouyer Prepare for xenamd64:
- kill xen/i386/identcpu.c, use i386/i386/identcpu.c instead (with a few
#ifndef XEN)
- move some files that can be shared between i386 and amd64 from
xen/i386 to xen/x86 (or to xen/xen for non-cpu-specific code)
- split assembly out of xen/include/hypervisor.h to xen/include/hypercalls.h
- use <xen/...> instead of <machine/...> for cpu-independant include files.

more work needed here, i386-specific files should got out of arch/xen to
arch/xeni386, and more code shared with arch/i386.
 1.12.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.12.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.13.6.1 09-Jan-2008  bouyer Merge xen bits to i386/i386/gdt.c. Convert remaining uses of PTE_* macros to
pmap_pte_* macros/inlines.
Fix think-o in pmap.c for native i386.
 1.14.24.3 29-Mar-2011  jym More sync fixes. And add the mbr_gpt files.
 1.14.24.2 10-Jan-2011  jym Sync with HEAD
 1.14.24.1 01-Nov-2009  jym Sync with HEAD.
 1.14.10.1 11-Mar-2010  yamt sync with head
 1.15.64.1 10-Jun-2019  christos Sync with HEAD
 1.15.62.1 28-Jul-2018  pgoyette Sync with HEAD
 1.12 26-May-2020  bouyer Implement new ioctl, needed by Xen 4.13:
IOCTL_PRIVCMD_MMAPBATCH_V2
IOCTL_PRIVCMD_MMAP_RESOURCE
IOCTL_GNTDEV_MMAP_GRANT_REF
IOCTL_GNTDEV_ALLOC_GRANT_REF
 1.11 07-Jul-2016  msaitoh branches: 1.11.22;
KNF. Remove extra spaces. No functional change.
 1.10 07-Sep-2015  dholland Final bit of PR 41200: headers that declare ioctls should include sys/ioccom.h.
This covers most if not all of the MD headers.

XXX: a lot of the ioctl definitions in some of these files are cutpasted.
 1.9 10-Jan-2011  cegger branches: 1.9.18; 1.9.36;
fix typo in ioctl definition
 1.8 15-Dec-2010  cegger add privcmd ioctl that got introduced with Xen 4
 1.7 03-Sep-2010  cegger match header protection with filename
 1.6 17-Feb-2008  bouyer branches: 1.6.10; 1.6.24; 1.6.30; 1.6.32;
Fix IOCTL_PRIVCMD_HYPERCALL issue which shows up with xen-3.1.3:
some hypercalls results are returned though the error path (depending on
sign, it's an error code or a result), and some results are interpreted in
a special way by the NetBSD kernel (e.g. -1).
Add a 'retval' member to the privcmd_hypercall_t argument, which holds
the hypercall result if it completed without error. The error code
is returned via the usual error path.
Handle the old IOCTL_PRIVCMD_HYPERCALL under COMPAT_40.

While there, make the double-inclusion protection #define match the
convention in xenio3.h and xenio.h.
 1.5 11-Dec-2005  christos branches: 1.5.24; 1.5.40; 1.5.50; 1.5.56;
merge ktrace-lwp.
 1.4 10-Sep-2005  bouyer Fix typo reported by Jed Davis on port-xen:
IOCTL_PRIVCMD_GET_MACH2PHYS_START_MFN is a read, not a write.
 1.3 24-May-2005  yamt branches: 1.3.2;
privcmd_ioctl: don't abuse errno for IOCTL_PRIVCMD_INITDOMAIN_EVTCHN.
renumber the ioctl and keep the old one for compatibility.
PR/30027.
 1.2 09-Mar-2005  bouyer branches: 1.2.2;
Merge the bouyer-xen2 branch. This add supports for the Xen 2.0 virtual
machine kernel (both privileged and non-privileged domains), and remove support
for the old xen 1.2.
 1.1 07-May-2004  cl branches: 1.1.2; 1.1.4; 1.1.8; 1.1.10; 1.1.12;
Add support for domain0 operations:
- access to all physical memory
- access to hypervisor traps from userland
- setup/config Xen's network routing/firewall rules
 1.1.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.10.1 29-Apr-2005  kent sync with -current
 1.1.8.3 09-Mar-2005  bouyer Add CVS Id.
 1.1.8.2 12-Feb-2005  bouyer IOCTL_PRIVCMD_HYPERCALL is _IOWR.
 1.1.8.1 31-Jan-2005  bouyer First pieces of domain control operations:
- use an up to date xenio.h
- update privcmd.c for newer ioctls (incomplete, some just return an error for
now)
- add a /dev/xenevt pseudo-device, which provide to userland an interface to
xen events
Now xend starts, and basic xm commands (such as list) work.
 1.1.4.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.4.5 01-Apr-2005  skrll Sync with HEAD.
 1.1.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.4.2 03-Aug-2004  skrll Sync with HEAD
 1.1.4.1 07-May-2004  skrll file xenio.h was added on branch ktrace-lwp on 2004-08-03 10:43:11 +0000
 1.1.2.2 22-May-2004  he Pull up revision 1.1 (requested by cl in ticket #337):
Upgrade xen support:
- add block device driver
- network device driver bug fixes
- support for vga/keyboard/mouse
- support for domain0 operations
- fix /dev/mem and i386_iopl, reboot, event dispatch
- fix clock support, cpu speed report, lazy fpu switching
- add xen12load loader
- sys/arch/xen parts of build.sh release support
[cl, ticket #337]
 1.1.2.1 07-May-2004  he file xenio.h was added on branch netbsd-2-0 on 2004-05-22 15:59:21 +0000
 1.2.2.2 14-Sep-2005  tron Pull up following revision(s) (requested by boyuer in ticket #774):
sys/arch/xen/include/xenio.h: revision 1.4
Fix typo reported by Jed Davis on port-xen:
IOCTL_PRIVCMD_GET_MACH2PHYS_START_MFN is a read, not a write.
 1.2.2.1 28-May-2005  tron Pull up revision 1.3 (requested by yamt in ticket #351):
privcmd_ioctl: don't abuse errno for IOCTL_PRIVCMD_INITDOMAIN_EVTCHN.
renumber the ioctl and keep the old one for compatibility.
PR/30027.
 1.3.2.2 27-Feb-2008  yamt sync with head.
 1.3.2.1 21-Jun-2006  yamt sync with head.
 1.5.56.1 18-Feb-2008  mjf Sync with HEAD.
 1.5.50.1 23-Mar-2008  matt sync with HEAD
 1.5.40.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.5.24.1 23-Mar-2008  jdc Pull up revisions: (requested by bouyer in ticket #1083)
src/sys/arch/xen/include/xenio.h 1.6
src/sys/arch/xen/include/xenio3.h 1.2
src/sys/arch/xen/xen/privcmd.c 1.25

Fix IOCTL_PRIVCMD_HYPERCALL issue which shows up with xen-3.1.3:
some hypercalls results are returned though the error path (depending on
sign, it's an error code or a result), and some results are interpreted in
a special way by the NetBSD kernel (e.g. -1).
Add a 'retval' member to the privcmd_hypercall_t argument, which holds
the hypercall result if it completed without error. The error code
is returned via the usual error path.
Handle the old IOCTL_PRIVCMD_HYPERCALL under COMPAT_40.

While there, make the double-inclusion protection #define match the
convention in xenio3.h and xenio.h.
 1.6.32.1 05-Mar-2011  rmind sync with head
 1.6.30.1 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.6.24.3 28-Mar-2011  jym Sync with HEAD. TODO before merge:
- shortcut for suspend code in sysmon, when powerd(8) is not running.
Borrow ``xs_watch'' thread context?
- bug hunting in xbd + xennet resume. Rings are currently thrashed upon
resume, so current implementation force flush them on suspend. It's not
really needed.
 1.6.24.2 10-Jan-2011  jym Sync with HEAD
 1.6.24.1 24-Oct-2010  jym Sync with HEAD
 1.6.10.1 09-Oct-2010  yamt sync with head
 1.9.36.2 09-Jul-2016  skrll Sync with HEAD
 1.9.36.1 22-Sep-2015  skrll Sync with HEAD
 1.9.18.1 03-Dec-2017  jdolecek update from HEAD
 1.11.22.1 31-May-2020  martin Pull up following revision(s) (requested by bouyer in ticket #935):

sys/arch/xen/x86/x86_xpmap.c: revision 1.89
sys/arch/x86/include/pmap.h: revision 1.121
sys/arch/xen/xen/privcmd.c: revision 1.58
sys/external/mit/xen-include-public/dist/xen/include/public/memory.h: revision 1.2
sys/arch/xen/include/xenpmap.h: revision 1.44
sys/arch/xen/include/xenio.h: revision 1.12
sys/arch/x86/x86/pmap.c: revision 1.394
(all via patch)

Ajust pmap_enter_ma() for upcoming new Xen privcmd ioctl:
pass flags to xpq_update_foreign()

Introduce a pmap MD flag: PMAP_MD_XEN_NOTR, which cause xpq_update_foreign()
to use the MMU_PT_UPDATE_NO_TRANSLATE flag.
make xpq_update_foreign() return the raw Xen error. This will cause
pmap_enter_ma() to return a negative error number in this case, but the
only user of this code path is privcmd.c and it can deal with it.

Add pmap_enter_gnt()m which maps a set of Xen grant entries at the
specified va in the specified pmap. Use the hooks implemented for EPT to
keep track of mapped grand entries in the pmap, and unmap them
when pmap_remove() is called. This requires pmap_remove() to be split
into a pmap_remove_locked(), to be called from pmap_remove_gnt().

Implement new ioctl, needed by Xen 4.13:
IOCTL_PRIVCMD_MMAPBATCH_V2
IOCTL_PRIVCMD_MMAP_RESOURCE
IOCTL_GNTDEV_MMAP_GRANT_REF
IOCTL_GNTDEV_ALLOC_GRANT_REF

Always enable declarations needed by privcmd.c
 1.4 07-Sep-2015  dholland Final bit of PR 41200: headers that declare ioctls should include sys/ioccom.h.
This covers most if not all of the MD headers.

XXX: a lot of the ioctl definitions in some of these files are cutpasted.
 1.3 03-Sep-2010  cegger branches: 1.3.18; 1.3.36;
match header protection with filename
 1.2 17-Feb-2008  bouyer branches: 1.2.10; 1.2.24; 1.2.30; 1.2.32;
Fix IOCTL_PRIVCMD_HYPERCALL issue which shows up with xen-3.1.3:
some hypercalls results are returned though the error path (depending on
sign, it's an error code or a result), and some results are interpreted in
a special way by the NetBSD kernel (e.g. -1).
Add a 'retval' member to the privcmd_hypercall_t argument, which holds
the hypercall result if it completed without error. The error code
is returned via the usual error path.
Handle the old IOCTL_PRIVCMD_HYPERCALL under COMPAT_40.

While there, make the double-inclusion protection #define match the
convention in xenio3.h and xenio.h.
 1.1 07-May-2006  bouyer branches: 1.1.2; 1.1.6; 1.1.8; 1.1.10; 1.1.14; 1.1.20; 1.1.24; 1.1.40; 1.1.50; 1.1.56;
Add dom0 operation support for Xen3. Probably buggy, but it's enouth to have
xend and xenstored starting; xm info and xm list works.
 1.1.56.1 18-Feb-2008  mjf Sync with HEAD.
 1.1.50.1 23-Mar-2008  matt sync with HEAD
 1.1.40.1 03-Jun-2008  skrll Sync with netbsd-4.
 1.1.24.1 23-Mar-2008  jdc Pull up revisions: (requested by bouyer in ticket #1083)
src/sys/arch/xen/include/xenio.h 1.6
src/sys/arch/xen/include/xenio3.h 1.2
src/sys/arch/xen/xen/privcmd.c 1.25

Fix IOCTL_PRIVCMD_HYPERCALL issue which shows up with xen-3.1.3:
some hypercalls results are returned though the error path (depending on
sign, it's an error code or a result), and some results are interpreted in
a special way by the NetBSD kernel (e.g. -1).
Add a 'retval' member to the privcmd_hypercall_t argument, which holds
the hypercall result if it completed without error. The error code
is returned via the usual error path.
Handle the old IOCTL_PRIVCMD_HYPERCALL under COMPAT_40.

While there, make the double-inclusion protection #define match the
convention in xenio3.h and xenio.h.
 1.1.20.2 09-Sep-2006  rpaulo sync with head
 1.1.20.1 07-May-2006  rpaulo file xenio3.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:44:56 +0000
 1.1.14.3 27-Feb-2008  yamt sync with head.
 1.1.14.2 21-Jun-2006  yamt sync with head.
 1.1.14.1 07-May-2006  yamt file xenio3.h was added on branch yamt-lazymbuf on 2006-06-21 14:58:15 +0000
 1.1.10.2 01-Jun-2006  kardel Sync with head.
 1.1.10.1 07-May-2006  kardel file xenio3.h was added on branch simonb-timecounters on 2006-06-01 22:35:36 +0000
 1.1.8.2 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.1.8.1 07-May-2006  tron file xenio3.h was added on branch peter-altq on 2006-05-24 15:48:25 +0000
 1.1.6.2 24-May-2006  yamt sync with head.
 1.1.6.1 07-May-2006  yamt file xenio3.h was added on branch yamt-pdpolicy on 2006-05-24 10:57:22 +0000
 1.1.2.2 11-May-2006  elad sync with head
 1.1.2.1 07-May-2006  elad file xenio3.h was added on branch elad-kernelauth on 2006-05-11 23:27:14 +0000
 1.2.32.1 05-Mar-2011  rmind sync with head
 1.2.30.1 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.2.24.1 24-Oct-2010  jym Sync with HEAD
 1.2.10.1 09-Oct-2010  yamt sync with head
 1.3.36.1 22-Sep-2015  skrll Sync with HEAD
 1.3.18.1 03-Dec-2017  jdolecek update from HEAD
 1.2 07-Sep-2015  dholland Final bit of PR 41200: headers that declare ioctls should include sys/ioccom.h.
This covers most if not all of the MD headers.

XXX: a lot of the ioctl definitions in some of these files are cutpasted.
 1.1 15-Dec-2010  cegger branches: 1.1.6; 1.1.20; 1.1.38;
add gnttab ioctl definitions to implement
 1.1.38.1 22-Sep-2015  skrll Sync with HEAD
 1.1.20.1 03-Dec-2017  jdolecek update from HEAD
 1.1.6.2 05-Mar-2011  rmind sync with head
 1.1.6.1 15-Dec-2010  rmind file xenio_gntdev.h was added on branch rmind-uvmplock on 2011-03-05 20:52:33 +0000
 1.2 09-Mar-2005  bouyer Merge the bouyer-xen2 branch. This add supports for the Xen 2.0 virtual
machine kernel (both privileged and non-privileged domains), and remove support
for the old xen 1.2.
 1.1 24-Apr-2004  cl branches: 1.1.2; 1.1.4; 1.1.8; 1.1.10; 1.1.12;
Add keyboard support and wscons config options.
 1.1.12.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.1.10.1 29-Apr-2005  kent sync with -current
 1.1.8.1 08-Mar-2005  bouyer Add support for ISA bus.
Clean up console attachement, and add support for VGA/pckbc console.
Add support for USB devices, including USB audio (which means others audio
devices should work too)
Add some more generic options to XEN0.
 1.1.4.5 01-Apr-2005  skrll Sync with HEAD.
 1.1.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.4.2 03-Aug-2004  skrll Sync with HEAD
 1.1.4.1 24-Apr-2004  skrll file xenkbcvar.h was added on branch ktrace-lwp on 2004-08-03 10:43:11 +0000
 1.1.2.2 22-May-2004  he Pull up revision 1.1 (requested by cl in ticket #337):
Upgrade xen support:
- add block device driver
- network device driver bug fixes
- support for vga/keyboard/mouse
- support for domain0 operations
- fix /dev/mem and i386_iopl, reboot, event dispatch
- fix clock support, cpu speed report, lazy fpu switching
- add xen12load loader
- sys/arch/xen parts of build.sh release support
[cl, ticket #337]
 1.1.2.1 24-Apr-2004  he file xenkbcvar.h was added on branch netbsd-2-0 on 2004-05-22 15:59:21 +0000
 1.2 31-Aug-2022  bouyer Remove XENPV support from xenmem; it's only used for !XENPV at this time.
 1.1 31-Aug-2022  bouyer Work in progress on dom0 PVH support: ioctl support for tools.
Basically, in PVH mode (where XENFEAT_auto_translated_physmap is enabled),
the hypervisor will not map foreing ressources in our virtual address
space for us. Instead, we have to pass it an address in our physical
address space (but not mapped to some RAM) where the ressource will show up
and then enter this PA in pour page table.

For this, introduce xenmem_* which manage the PA space. In PVH mode this
is just allocated from the iomem_ex extent.

With this, I can start a PV domU, and the guest's kernel boots (and
the console works). It hangs because the backend driver can't map the
frontend ressources (yet).

Note that, per https://xenbits.xen.org/docs/unstable/support-matrix.html,
dom0 PVH support is still considered experimental by Xen.
 1.5 01-May-2020  jdolecek make the csum blank/undefer counters per interface
 1.4 22-Mar-2020  jdolecek actually in data_validated case, there is no need to inspect the data for Rx,
simply set the supported csum offload flags to skip the software csum
verification
 1.3 18-Mar-2020  jdolecek use NET[RT]XF_data_validated flag to mark when Tx packet has valid
checksum; this is used to skip software checksum validation on
xennet Rx side when configured for Rx offloading

in Dom0 assume that checksum is valid when the Tx mbuf has no offload flags
- in that case either it's local packet where checksum has just been
computed in software, or forwarded external packet already
verified when received on Dom0

practical offshot of this is that DomU doesn't re-verify checksum of
packets forwarded from external hosts, e.g. via bridge(4)
 1.2 16-Mar-2020  jdolecek drop the disabled M_EXT_ROMAP mbuf code, convert xennet_checksum_fill()
to use in_undefer_cksum() instead of custom code to compute the checksum
for Rx packets, and set csum_data appropriately for eventual hw offloading

make it possible to skip the sw checksum computation by appropriate Rx
flag similarily as we do for Tx

XXX for now, the Rx flag is mostly for testing as it only works for
dom0<->domu, need some further network stack changes to arrange for
the checksum to be eventually computed when packets goes outside xen
 1.1 12-Jul-2006  yamt branches: 1.1.2; 1.1.6; 1.1.10; 1.1.16; 1.1.158;
implement a simple NETTXF_csum_blank/NETRXF_csum_blank workaround
so that we can talk with linux guests at least.
just fill checksum field of received packets if the flag is set.
maybe should be revisited later.
 1.1.158.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.1.16.2 30-Dec-2006  yamt sync with head.
 1.1.16.1 12-Jul-2006  yamt file xennet_checksum.h was added on branch yamt-lazymbuf on 2006-12-30 20:47:25 +0000
 1.1.10.2 09-Sep-2006  rpaulo sync with head
 1.1.10.1 12-Jul-2006  rpaulo file xennet_checksum.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:44:56 +0000
 1.1.6.2 11-Aug-2006  yamt sync with head
 1.1.6.1 12-Jul-2006  yamt file xennet_checksum.h was added on branch yamt-pdpolicy on 2006-08-11 15:43:16 +0000
 1.1.2.2 13-Jul-2006  gdamore Merge from HEAD.
 1.1.2.1 12-Jul-2006  gdamore file xennet_checksum.h was added on branch gdamore-uart on 2006-07-13 17:49:06 +0000
 1.44 26-May-2020  bouyer Ajust pmap_enter_ma() for upcoming new Xen privcmd ioctl:
pass flags to xpq_update_foreign()
Introduce a pmap MD flag: PMAP_MD_XEN_NOTR, which cause xpq_update_foreign()
to use the MMU_PT_UPDATE_NO_TRANSLATE flag.
make xpq_update_foreign() return the raw Xen error. This will cause
pmap_enter_ma() to return a negative error number in this case, but the
only user of this code path is privcmd.c and it can deal with it.

Add pmap_enter_gnt()m which maps a set of Xen grant entries at the
specified va in the specified pmap. Use the hooks implemented for EPT to
keep track of mapped grand entries in the pmap, and unmap them
when pmap_remove() is called. This requires pmap_remove() to be split
into a pmap_remove_locked(), to be called from pmap_remove_gnt().
 1.43 25-Apr-2020  bouyer Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.42 30-Oct-2019  maxv branches: 1.42.6;
Switch to new PTE bits.
 1.41 13-Feb-2019  cherry branches: 1.41.4;
Further restrict the scope of XENPV to relevant parts.
 1.40 26-Jul-2018  maxv Remove the non-PAE-i386 code of Xen. The branches are reordered so that
__x86_64__ comes first, eg:

#if defined(PAE)
/* i386+PAE */
#elif defined(__x86_64__)
/* amd64 */
#else
/* i386 */
#endif

becomes

#ifdef __x86_64__
/* amd64 */
#else
/* i386+PAE */
#endif

Tested on i386pae-domU and amd64-dom0.
 1.39 08-Mar-2017  maxv branches: 1.39.12; 1.39.14;
A few changes:
* Use markers to reduce false sharing.
* Remove XENDEBUG_SYNC and several debug messages, they are just useless.
* Remove xen_vcpu_*. They are unused and not optimized: if we really
wanted to flush ranges we should pack the VAs in a mmuext_op array
instead of performing several hypercalls in a loop.
* Start removing PG_k.
* KNF, reorder, simplify and remove stupid comments.
 1.38 06-May-2014  cherry branches: 1.38.4; 1.38.8; 1.38.12;
Use the hypervisor to copy/zero pages. This saves us the extra overheads
of setting up temporary kernel mapping/unmapping.

riz@ reports savings of about 2s on a 120s kernel build.
 1.37 30-Jun-2012  jym branches: 1.37.2; 1.37.4; 1.37.12;
Extend the xpmap API, as described in [1]. This change is mechanical and
avoids exposing the MD phys_to_machine/machine_to_phys tables directly.
Added:

- xpmap_ptom handles PFN (pseudo physical) to MFN (machine frame number)
translations, and is under control of the domain.
- xpmap_mtop is its counterpart (MFN to PFN), and is under control of
hypervisor.

xpmap_ptom_map() map a pseudo-phys address to a machine address
xpmap_ptom_unmap() unmap a pseudo-phys address (invalidation)
xpmap_ptom_isvalid() check for pseudo-phys address validity

The parameters are physical/machine addresses, like bus_dma/bus_space(9).
As x86 MFNs are tracked by u_long (Xen's choice) while machine addresses
can be 64 bits entities (PAE), use ptoa() to avoid truncation when bit
shifting by PAGE_SHIFT.

I kept the same namespace (xpmap_) to avoid code churn.

[1] http://mail-index.netbsd.org/port-xen/2009/05/09/msg004951.html

XXX will document ptoa/atop/trunc_page separately.
 1.36 27-Jun-2012  jym Retire XEN_COMPAT_030001 as detailed on port-xen@:

http://mail-index.netbsd.org/port-xen/2012/06/25/msg007431.html

The xen_p2m API comes next.

ok bouyer@.
Tested on i386 PAE and amd64 (Xen 3.3 on private test bed, and
Xen 3.4 for Amazon EC2).

FWIW, Amazon always reported:

hypervisor0 at mainbus0: Xen version 3.4.3-kaos_t1micro

multiple times for Europe and US West-1, so I guess they are now at
3.4 (32 and 64 bits).
 1.35 24-Jun-2012  jym Enable the map/unmap recursive mapping functions for all Xen ports for
save/restore.

For an unknown reason (to me) Xen refuses to update VM translations
when the entry is pointing back to itself (which is precisely
what our recursive VM model does). So enable the functions that take
care of this, which will avoid all sort of memory corruption upon restore
leading domU to trample upon itself.

Save/restore works again for amd64. The occasional domU frontend corruption is
still present, but is harmless to dom0. Now we have a working shell and
ddb inside domU, that helps debugging a tiny bit.

XXX pull-up to -6.
 1.34 20-Apr-2012  rmind - Convert x86 MD code, mainly pmap(9) e.g. TLB shootdown code, to use
kcpuset(9) and thus replace hardcoded CPU bitmasks. This removes the
limitation of maximum CPUs.

- Support up to 256 CPUs on amd64 architecture by default.

Bug fixes, improvements, completion of Xen part and testing on 64-core
AMD Opteron(tm) Processor 6282 SE (also, as Xen HVM domU with 128 CPUs)
by Manuel Bouyer.
 1.33 30-Dec-2011  cherry branches: 1.33.2;
per-cpu shadow directory pages should be updated locally via cross-calls. Do this.
 1.32 23-Nov-2011  jym branches: 1.32.2;
Move Xen-specific functions to Xen pmap. Requested by cherry@.

Un'ifdef XEN in xen_pmap.c, it is always defined there.
 1.31 08-Nov-2011  cherry Expose the PG_k #define pt/pd bit to both xen and "baremetal" x86. This is required, since kernel pages are mapped with user permissions in XEN/amd64 since the VM kernel runs in ring3. Since XEN/i386(including PAE) runs in ring1, supervisor mode is appropriate for these ports. We need to share this since the pmap implementation is still shared. Once the xen implementation is sufficiently independant of the x86 one, this can be made private to xen/include/xenpmap.h
 1.30 06-Nov-2011  cherry [merging from cherry-xenmp] Make the xen MMU op queue locking api private. Implement per-cpu queues.
 1.29 13-Aug-2011  cherry branches: 1.29.2;
remove unnecessary locking overhead for UP
 1.28 10-Aug-2011  cherry Introduce locking primitives for Xen pte operations, and xen helper calls for MP related MMU ops
 1.27 29-Apr-2011  jym branches: 1.27.2;
Apply DRY: xpmap_{mtop,ptom}() can reuse xpmap_{mtop,ptom}_masked() for
the frame number lookup.

No functional change.
 1.26 17-Apr-2011  mrg apply some _KERNEL_OPT.
 1.25 10-Feb-2011  jym Use only one function to pin pages with Xen, and provide macros to
call it for different levels (L1 => L4).

Replace all calls to xpq_queue_pin_table(...) in MD code with these new
functions, with proper #ifdef'ing depending on $MACHINE.

Rationale:
- only one function to modify for logging
- pushes responsibility to caller for chosing the proper pin level, rather
than Xen internal functions; this makes the pin level explicit rather than
implicit.

Boot tested for dom0 i386/amd64, PAE included. No functional change intended.
 1.24 23-Oct-2009  snj branches: 1.24.4; 1.24.6; 1.24.8;
Remove 3rd and 4th clauses. OK cl@ (copyright holder).
 1.23 29-Jul-2009  cegger remove Xen2 support.
ok bouyer@
 1.22 10-Mar-2009  bouyer More i386PAE fixes:
- x86_round_page, x86_trunc_page, x86_btop and x86_ptob macros are used with
physical addresses; cast to paddr_t instead of u_long. Issue pointed out
by jym@
- machine_to_phys_mapping[] is a long. This is fine as it holds page
frame numbers (and this fits in a 32bit int as physical addresses are
only 36bits), but cast to paddr_t before << PAGE_SHIFT
- xen_start_info.store_mfn is a long; cast it to paddr_t before << PAGE_SHIFT.
should fix issue pointed out by cegger@
 1.21 24-Oct-2008  jym branches: 1.21.2; 1.21.4; 1.21.8; 1.21.12;
- add mfn_to_pfn() and pfn_to_mfn() macros, for rapid conversion between
pseudo-physical and machine frame numbers.

- add HYPERVISOR_crash() for i386 and amd64. Intended to be used by a domain
to notify Xen that it crashed on purpose, and request a dump (if applicable).

No functional changes intended.

Reviewed by Christoph (cegger@).
 1.20 24-Oct-2008  jym - printf -> aprint_*
- fix and add comments
- make some panic/error messages more relevant
- remove last '\n' in DPRINTK() macros, not required as it is already part of format string.

No functional changes.
 1.19 23-Jan-2008  bouyer branches: 1.19.6; 1.19.10; 1.19.16;
Merge the bouyer-xeni386 branch. This brings in PAE support to NetBSD xeni386
(domU only). PAE support is enabled by 'options PAE', see the new XEN3PAE_DOMU
and INSTALL_XEN3PAE_DOMU kernel config files.

See the comments in arch/i386/include/{pte.h,pmap.h} to see how it works.
In short, we still handle it as a 2-level MMU, with the second level page
directory being 4 pages in size. pmap switching is done by switching the
L2 pages in the L3 entries, instead of loading %cr3. This is almost required
by Xen, which handle the last L2 page (the one mapping 0xc0000000 - 0xffffffff)
in a very special way. But this approach should also work for native PAE
support if ever supported (in fact, the pmap should almost suport native
PAE, what's missing is bootstrap code in locore.S).
 1.18 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.17 28-Nov-2007  ad branches: 1.17.6;
Use the new atomic ops.
 1.16 22-Nov-2007  bouyer Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.15 17-Oct-2006  bouyer branches: 1.15.8; 1.15.14; 1.15.26; 1.15.28; 1.15.32; 1.15.34;
Add ELF_PADDR_OFFSET and VIRT_ENTRY strings to __xen_guest ELF section,
so that our kernels works with newer xen-3 hypervisors; and correct the value
of VIRT_BASE for dom0.
Now that we can embed the values of KERNBASE and KERNTEXTOFF in the binary
for Xen, make the domU memory layout the same as dom0 for Xen3 (making
it the other way round doens't work; probably because of alignement
constraints in the hypervisor). The old domU layout is used if options
XEN_COMPAT_030001 is present in the kernel config file. Enable this the
domU kernel config files for now, in case someone wants to run a NetBSD
domU on an older Xen3 installation.
 1.14 06-Mar-2006  bouyer branches: 1.14.12; 1.14.14;
Implement MULTI_update_va_mapping() and MULTI_update_va_mapping_otherdomain(),
which fills in multicall arguments for __HYPERVISOR_update_va_mapping
and __HYPERVISOR_update_va_mapping_otherdomain dealing with
differences between i386 and amd64.
 1.13 16-Feb-2006  perry branches: 1.13.2;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.12 15-Jan-2006  bouyer branches: 1.12.2; 1.12.4;
Snapshot of work in progress on NetBSD port to Xen3:
- kernel (both dom0 and domU) boot, console is functionnal and it can starts
software from a ramdisk
- there is no driver front-end expect console for domU yet.
- dom0 can probe devices and ex(4) work when Xen3 is booted without acpi
and apic support. But the on-board IDE doens't get interrupts.
The PCI code still needs work (it's hardcoded to mode 1). Some of this
code should be shared with ../x86
The physical insterrupt code needs to get MPBIOS and ACPI support, and
do interrupt routing to properly interract with Xen.
To enable Xen-3.0 support, add
options XEN3
to your kernel config file (this will disable Xen2 support)
Changes affecting Xen-2.0 support (no functionnal changes intended):
- get more constants from genassym for assembly code
- remove some unneeded registers move from start()
- map the shared info page from start(), and remove the pte = 0xffffffff hack
- vector.S: in hypervisor_callback() make sure %esi points to
HYPERVISOR_shared_info before accessing the info page. Remplace some
hand-written assembly with the equivalent macro defined in frameasm.h
- more debug code, dissabled by default.

while here added my copyright on some files I worked on in 2005.
 1.11 24-Dec-2005  perry branches: 1.11.2;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.10 11-Dec-2005  christos merge ktrace-lwp.
 1.9 07-Nov-2005  yamt some assym cleanup.
- move copyin and friends from locore.S to their own file, copy.S.
share it between i386 and xen.
- defparam KERNBASE and kill KERNBASE_LOCORE hack.
- add more symbols to assym.h and use it where appropriate.
 1.8 20-Aug-2005  bouyer Implement xpq_queue_machphys_update(), which queues a request to
update the machine to physical table (to be used after a
MEMOP_increase_reservation).
 1.7 31-May-2005  yamt branches: 1.7.2;
avoid variable shadowing.
 1.6 26-May-2005  bouyer Always call the xpq_queue*() functions at splvm(), so that it's safe to call
them from interrupt context.
xpq_flush_queue() is called from IPL_NET in if_xennet.c, and
other xpq_queue* functions may be called from interrupt context via
pmap_kenter*(). Should fix port-xen/30153.
Thanks to Jason Thorpe and YAMAMOTO Takashi for enlightments on this issue.
 1.5 16-Apr-2005  yamt s/foreing/foreign/g
ok'ed by Manuel Bouyer.
 1.4 09-Mar-2005  bouyer branches: 1.4.2;
Merge the bouyer-xen2 branch. This add supports for the Xen 2.0 virtual
machine kernel (both privileged and non-privileged domains), and remove support
for the old xen 1.2.
 1.3 26-Apr-2004  cl branches: 1.3.2; 1.3.6; 1.3.8; 1.3.10;
Rework the physical<->machine memory mapping: offset physical addresses
by 0x100000 (above the I/O Memory "hole") leaving all physical addresses
below unused, don't perform phys<->mach mapping for addresses below 0x100000
or beyond the real hardware's physical memory.

-> /dev/mem works now as expected and X works in domain0.
 1.2 24-Apr-2004  cl Make bus_space map machine addresses instead of physical addresses.
 1.1 11-Mar-2004  cl branches: 1.1.2;
Add port to the Xen virtual machine monitor.
(see http://www.cl.cam.ac.uk/Research/SRG/netos/xen/)
 1.1.2.1 22-May-2004  he Pull up revisions 1.2-1.3 (requested by cl in ticket #337):
Upgrade xen support:
- add block device driver
- network device driver bug fixes
- support for vga/keyboard/mouse
- support for domain0 operations
- fix /dev/mem and i386_iopl, reboot, event dispatch
- fix clock support, cpu speed report, lazy fpu switching
- add xen12load loader
- sys/arch/xen parts of build.sh release support
[cl, ticket #337]
 1.3.10.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.3.8.1 29-Apr-2005  kent sync with -current
 1.3.6.2 12-Feb-2005  bouyer Implement pmap_remap_pages(), which remplace one or more pages in a
mapping with different pages, possibly from a foreing domain.
Use this to implement IOCTL_PRIVCMD_MMAP.
 1.3.6.1 13-Dec-2004  bouyer Commit files from netbsd-2.0-xen-sparse/sys/arch/xen in the Xen-2.0
distribution. These are the files modified from the 2.0 tree to get
NetBSD/xen working with Xen 2.
 1.3.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.3.2.5 01-Apr-2005  skrll Sync with HEAD.
 1.3.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.3.2.2 03-Aug-2004  skrll Sync with HEAD
 1.3.2.1 26-Apr-2004  skrll file xenpmap.h was added on branch ktrace-lwp on 2004-08-03 10:43:11 +0000
 1.4.2.5 07-Apr-2006  tron Apply patch (requested by bouyer in ticket #1245):
Pull up Xen3 domU support. This adds support for the Xen-3 memory bootstrap,
xenstore, and block and network device frontend. Xen-3 support is turned
on by 'options XEN3', which disable Xen-2 support.
Changes affecting non-xen3 specific code:
- xbd and xennet at hypervisor now attaches with xbd_hypervisor and
xennet_hypervisor
- x86_atomic_* renamed to xen_atomic_*
- use genassim.cf to pull in more constant from include files for assembly
- Map the shared info page from locore.S instead of the 0xffffffff hack
in xen_machdep.c
- remove some unused code
- some __asm__ __volatile__ -> __asm volatile and __inline__ -> inline
- more debug code
 1.4.2.4 25-Aug-2005  tron Pull up following revision(s) (requested by bouyer in ticket #696):
sys/arch/xen/i386/xen_machdep.c: revision 1.11
sys/arch/xen/include/xenpmap.h: revision 1.8
Implement xpq_queue_machphys_update(), which queues a request to
update the machine to physical table (to be used after a
MEMOP_increase_reservation).
 1.4.2.3 18-Jun-2005  tron Pull up revision 1.7 (requested by yamt in ticket #460):
avoid variable shadowing.
 1.4.2.2 28-May-2005  tron Pull up revision 1.6 (requested by bouyer in ticket #355):
Always call the xpq_queue*() functions at splvm(), so that it's safe to call
them from interrupt context.
xpq_flush_queue() is called from IPL_NET in if_xennet.c, and
other xpq_queue* functions may be called from interrupt context via
pmap_kenter*(). Should fix port-xen/30153.
Thanks to Jason Thorpe and YAMAMOTO Takashi for enlightments on this issue.
 1.4.2.1 21-Apr-2005  tron Pull up revision 1.5 (requested by yamt in ticket #173):
s/foreing/foreign/g
ok'ed by Manuel Bouyer.
 1.7.2.5 04-Feb-2008  yamt sync with head.
 1.7.2.4 21-Jan-2008  yamt sync with head
 1.7.2.3 07-Dec-2007  yamt sync with head
 1.7.2.2 30-Dec-2006  yamt sync with head.
 1.7.2.1 21-Jun-2006  yamt sync with head.
 1.11.2.2 18-Feb-2006  yamt sync with head.
 1.11.2.1 01-Feb-2006  yamt sync with head.
 1.12.4.1 22-Apr-2006  simonb Sync with head.
 1.12.2.1 09-Sep-2006  rpaulo sync with head
 1.13.2.1 13-Mar-2006  yamt sync with head.
 1.14.14.1 22-Oct-2006  yamt sync with head
 1.14.12.1 18-Nov-2006  ad Sync with head.
 1.15.34.2 18-Feb-2008  mjf Sync with HEAD.
 1.15.34.1 08-Dec-2007  mjf Sync with HEAD.
 1.15.32.3 21-Oct-2007  bouyer Factorise some Xen pmap code in x86_xpmap.c.
More xpmap_{ptom,mtop} -> xpmap_{ptom,mtop}_masked

The xenamd64 kernel is now good enough to complete a sysinst install from
xennet to xbd.
 1.15.32.2 18-Oct-2007  bouyer Introduce xpmap_mtop_masked().
 1.15.32.1 17-Oct-2007  bouyer Prepare for xenamd64:
- kill xen/i386/identcpu.c, use i386/i386/identcpu.c instead (with a few
#ifndef XEN)
- move some files that can be shared between i386 and amd64 from
xen/i386 to xen/x86 (or to xen/xen for non-cpu-specific code)
- split assembly out of xen/include/hypervisor.h to xen/include/hypercalls.h
- use <xen/...> instead of <machine/...> for cpu-independant include files.

more work needed here, i386-specific files should got out of arch/xen to
arch/xeni386, and more code shared with arch/i386.
 1.15.28.2 23-Mar-2008  matt sync with HEAD
 1.15.28.1 09-Jan-2008  matt sync with HEAD
 1.15.26.2 03-Dec-2007  joerg Sync with HEAD.
 1.15.26.1 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.15.14.1 18-Apr-2007  thorpej Convert i386 and amd64 to the new atomic ops API.
 1.15.8.1 03-Dec-2007  ad Sync with HEAD.
 1.17.6.3 13-Jan-2008  bouyer Make non-PAE kernels build again
 1.17.6.2 13-Jan-2008  bouyer Work in progress on xeni386 PAE support:
Make xeni386 build with a 64bit paddr_t. For this vaddr_t vs paddr_t vs
pointers usages had to be clarified.
If 'options PAE' is present in a Xen3 kernel, switch paddr_t, pd_entry_t
and pt_entry_t to 64bits, and add the PAE entry in the __xen_guest ELF section.
 1.17.6.1 09-Jan-2008  bouyer Merge xen bits to i386/i386/gdt.c. Convert remaining uses of PTE_* macros to
pmap_pte_* macros/inlines.
Fix think-o in pmap.c for native i386.
 1.19.16.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.19.10.3 11-Mar-2010  yamt sync with head
 1.19.10.2 19-Aug-2009  yamt sync with head.
 1.19.10.1 04-May-2009  yamt sync with head.
 1.19.6.1 17-Jan-2009  mjf Sync with HEAD.
 1.21.12.1 21-Apr-2010  matt sync to netbsd-5
 1.21.8.9 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.21.8.8 02-May-2011  jym Sync with head.
 1.21.8.7 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.21.8.6 28-Mar-2011  jym Sync with HEAD. TODO before merge:
- shortcut for suspend code in sysmon, when powerd(8) is not running.
Borrow ``xs_watch'' thread context?
- bug hunting in xbd + xennet resume. Rings are currently thrashed upon
resume, so current implementation force flush them on suspend. It's not
really needed.
 1.21.8.5 01-Nov-2009  jym - Upgrade suspend/resume code to comply with Xen2 removal.
- Add support for PAE domUs suspend/resume.
- Fix an issue regarding initialization of the xbd ring I/O that could end
badly during resume, with invalid block operations submitted to dom0 backend.

NetBSD supports PAE under x86_32 by considering the L2 page as being
4 pages long instead of 1.

Xen validates the page types during resume. Sadly, the hypervisor handles
alternative recursive mappings (== PG/PD entries pointing to pages other
than self) inadequately, which could lead to incorrect page pinning.

As a result, the important change with this patch is to clear these alternative
mappings during suspend, and reset them back to their former self upon
resume. For PAE, approx. all 4 PDIR_SLOT_PTEs could be considered as
alternative recursive mappings.

See comments in pmap.c for further details.

Now, let the testing and bug hunting begin.
 1.21.8.4 01-Nov-2009  jym Sync with HEAD.
 1.21.8.3 24-Jul-2009  jym - rework the page pinning API, so that now a function is provided for
each level of indirection encountered during virtual memory translations. Update
pmap accordingly. Pinning looks cleaner that way, and it offers the possibility
to pin lower level pages if necessary (NetBSD does not do it currently).

- some fixes and comments to explain how page validation/invalidation take
place during save/restore/migrate under Xen. L2 shadow entries from PAE are now
handled, so basically, suspend/resume works with PAE.

- fixes an issue reported by Christoph (cegger@) for xencons suspend/resume
in dom0.

TODO:

- PAE save/restore is currently limited to single-user only, multi-user
support requires modifications in PAE pmap that should be discussed first. See
the comments about the L2 shadow pages cached in pmap_pdp_cache in this commit.

- grant table bug is still there; do not use the kernels of this branch
to test suspend/resume, unless you want to experience bad crashes in dom0,
and push the big red button.

Now there is light at the end of the tunnel :)

Note: XEN2 kernels will neither build nor work with this branch.
 1.21.8.2 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.21.8.1 09-Feb-2009  jym Initial code for xen save/restore/migrate facilities.

- split the attach code of frontends in two half: one that is only needed
during autoconf(9) attach/detach phases, and one used at each save/restore
of device state (between suspend and resume).

Applies to hypervisor, xencons, xenbus, xbd, and xennet.

- add a rwlock(9) ("ptom_lock") to protect the different parts in the kernel
that manipulate MFNs (which could change between a suspend and a resume,
without the kernel noticing it). Parts that require MFNs acquire a reader lock,
while suspend code will acquire a writer lock to ensure that no-other parts
in kernel still use MFNs.

- integrate the suspend code with sysmon.

- various things in pmap(9), and clock.

TODO:
- factorize code a bit more inside frontends drivers.
- remove all alternative recursive (APDP_PDE) mappings found in PD/PT during
suspend, as Xen does not support them.
- abstract the ptom_lock locking, it is only required when kernel preemption
is enabled, or on MP systems.

Current code works mostly. You may experience difficulties in some corner
cases (dom0 warnings about xennet interface errors, and Xen tools failing to
validate NetBSD's alternative pmaps).
 1.21.4.1 30-Sep-2009  snj Pull up following revision(s) (requested by bouyer in ticket #1040):
sys/arch/i386/include/param.h: revision 1.71
sys/arch/i386/i386/db_memrw.c: revision 1.25
sys/arch/xen/include/xenpmap.h: revision 1.22
sys/arch/xen/xen/xenevt.c: revision 1.31
More i386PAE fixes:
- x86_round_page, x86_trunc_page, x86_btop and x86_ptob macros are used with
physical addresses; cast to paddr_t instead of u_long. Issue pointed out
by jym@
- machine_to_phys_mapping[] is a long. This is fine as it holds page
frame numbers (and this fits in a 32bit int as physical addresses are
only 36bits), but cast to paddr_t before << PAGE_SHIFT
- xen_start_info.store_mfn is a long; cast it to paddr_t before << PAGE_SHIFT.
should fix issue pointed out by cegger@
 1.21.2.1 28-Apr-2009  skrll Sync with HEAD.
 1.24.8.1 17-Feb-2011  bouyer Sync with HEAD
 1.24.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.24.4.3 31-May-2011  rmind sync with head
 1.24.4.2 21-Apr-2011  rmind sync with head
 1.24.4.1 05-Mar-2011  rmind sync with head
 1.27.2.5 20-Sep-2011  cherry Remove the "xpq lock", since we have per-cpu mmu queues now. This may need further testing. Also add some preliminary locking around queue-ops in the network backend driver
 1.27.2.4 09-Sep-2011  cherry make #define PG_k visible on all xen archs
 1.27.2.3 17-Aug-2011  cherry Pullup relevant changes from -current
 1.27.2.2 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.27.2.1 03-Jun-2011  cherry Initial import of xen MP sources, with kernel and userspace tests.
- this is a source priview.
- boots to single user.
- spurious interrupt and pmap related panics are normal
 1.29.2.5 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.29.2.4 30-Oct-2012  yamt sync with head
 1.29.2.3 23-May-2012  yamt sync with head.
 1.29.2.2 17-Apr-2012  yamt sync with head
 1.29.2.1 10-Nov-2011  yamt sync with head
 1.32.2.2 29-Apr-2012  mrg sync to latest -current.
 1.32.2.1 18-Feb-2012  mrg merge to -current.
 1.33.2.2 02-Jul-2012  jdc Pull up revisions:
src/sys/arch/xen/include/xenpmap.h revision 1.35 via patch
src/sys/arch/xen/x86/xen_pmap.c revision 1.22 via patch
(requested by jym in ticket #372).

Enable the map/unmap recursive mapping functions for all Xen ports for
save/restore.

For an unknown reason (to me) Xen refuses to update VM translations
when the entry is pointing back to itself (which is precisely
what our recursive VM model does). So enable the functions that take
care of this, which will avoid all sort of memory corruption upon restore
leading domU to trample upon itself.

Save/restore works again for amd64. The occasional domU frontend
corruption is
still present, but is harmless to dom0. Now we have a working shell and
ddb inside domU, that helps debugging a tiny bit.

XXX pull-up to -6.
 1.33.2.1 09-May-2012  riz Pull up following revision(s) (requested by rmind in ticket #202):
sys/arch/x86/include/cpuvar.h: revision 1.46
sys/arch/xen/include/xenpmap.h: revision 1.34
sys/arch/i386/include/param.h: revision 1.77
sys/arch/x86/x86/pmap_tlb.c: revision 1.5
sys/arch/x86/x86/pmap_tlb.c: revision 1.6
sys/arch/i386/i386/genassym.cf: revision 1.92
sys/arch/xen/x86/cpu.c: revision 1.91
sys/arch/x86/x86/pmap.c: revision 1.177
sys/arch/xen/x86/xen_pmap.c: revision 1.21
sys/arch/x86/acpi/acpi_wakeup.c: revision 1.31
sys/kern/subr_kcpuset.c: revision 1.5
sys/arch/amd64/include/param.h: revision 1.18
sys/sys/kcpuset.h: revision 1.5
sys/arch/x86/x86/mtrr_i686.c: revision 1.26
sys/arch/x86/x86/mtrr_i686.c: revision 1.27
sys/arch/xen/x86/x86_xpmap.c: revision 1.43
sys/arch/x86/x86/cpu.c: revision 1.98
sys/arch/amd64/amd64/mptramp.S: revision 1.14
sys/kern/sys_sched.c: revision 1.42
sys/arch/amd64/amd64/genassym.cf: revision 1.50
sys/arch/i386/i386/mptramp.S: revision 1.24
sys/arch/x86/include/pmap.h: revision 1.52
sys/arch/x86/include/cpu.h: revision 1.50
- Convert x86 MD code, mainly pmap(9) e.g. TLB shootdown code, to use
kcpuset(9) and thus replace hardcoded CPU bitmasks. This removes the
limitation of maximum CPUs.
- Support up to 256 CPUs on amd64 architecture by default.
Bug fixes, improvements, completion of Xen part and testing on 64-core
AMD Opteron(tm) Processor 6282 SE (also, as Xen HVM domU with 128 CPUs)
by Manuel Bouyer.
- pmap_tlb_shootdown: do not overwrite tp_cpumask with pm_cpus, but merge
like pm_kernel_cpus. Remove unecessary intersection with kcpuset_running.
Do not reset tp_userpmap if pmap_kernel().
- Remove pmap_tlb_mailbox_t wrapping, which is pointless after recent changes.
- pmap_tlb_invalidate, pmap_tlb_intr: constify for packet structure.
i686_mtrr_init_first: handle the case when there are no variable-size MTRR
registers available (i686_mtrr_vcnt == 0).
 1.37.12.1 10-Aug-2014  tls Rebase.
 1.37.4.1 18-May-2014  rmind sync with head
 1.37.2.2 03-Dec-2017  jdolecek update from HEAD
 1.37.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.38.12.1 21-Apr-2017  bouyer Sync with HEAD
 1.38.8.1 20-Mar-2017  pgoyette Sync with HEAD
 1.38.4.1 28-Aug-2017  skrll Sync with HEAD
 1.39.14.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.39.14.1 10-Jun-2019  christos Sync with HEAD
 1.39.12.1 28-Jul-2018  pgoyette Sync with HEAD
 1.41.4.1 31-May-2020  martin Pull up following revision(s) (requested by bouyer in ticket #935):

sys/arch/xen/x86/x86_xpmap.c: revision 1.89
sys/arch/x86/include/pmap.h: revision 1.121
sys/arch/xen/xen/privcmd.c: revision 1.58
sys/external/mit/xen-include-public/dist/xen/include/public/memory.h: revision 1.2
sys/arch/xen/include/xenpmap.h: revision 1.44
sys/arch/xen/include/xenio.h: revision 1.12
sys/arch/x86/x86/pmap.c: revision 1.394
(all via patch)

Ajust pmap_enter_ma() for upcoming new Xen privcmd ioctl:
pass flags to xpq_update_foreign()

Introduce a pmap MD flag: PMAP_MD_XEN_NOTR, which cause xpq_update_foreign()
to use the MMU_PT_UPDATE_NO_TRANSLATE flag.
make xpq_update_foreign() return the raw Xen error. This will cause
pmap_enter_ma() to return a negative error number in this case, but the
only user of this code path is privcmd.c and it can deal with it.

Add pmap_enter_gnt()m which maps a set of Xen grant entries at the
specified va in the specified pmap. Use the hooks implemented for EPT to
keep track of mapped grand entries in the pmap, and unmap them
when pmap_remove() is called. This requires pmap_remove() to be split
into a pmap_remove_locked(), to be called from pmap_remove_gnt().

Implement new ioctl, needed by Xen 4.13:
IOCTL_PRIVCMD_MMAPBATCH_V2
IOCTL_PRIVCMD_MMAP_RESOURCE
IOCTL_GNTDEV_MMAP_GRANT_REF
IOCTL_GNTDEV_ALLOC_GRANT_REF

Always enable declarations needed by privcmd.c
 1.42.6.1 16-Apr-2020  bouyer Reorganise sources to make it possible to include Xen PVHVM support in
native kernels. Among others:
- move xen/include/amd64/hypercall.h to amd64/include/xen and
xen/include/i386/hypercall.h to i386/include/xen
- exclude some native files from the build for xenpv
- add xen to "machine" config statement for amd64 and i386
- split arch/xen/conf/files.xen to arch/xen/conf/files.xen (for pv drivers)
and arch/xen/conf/files.xen.pv (for full pv support)
- add GENERIC_XENHVM kernel config which includes GENERIC and add Xen PV
drivers.
 1.8 16-Jul-2024  riastradh xen: Don't hotpatch away LOCK prefix in xen_mb, even on UP boots.

Both xen_mb and membar_sync are designed to provide store-before-load
ordering, but xen_mb has to provide it in synchronizing guest with
hypervisor, while membar_sync only has to provide it in synchronizing
one (guest) CPU with another (guest) CPU.

It is safe to hotpatch away the LOCK prefix in membar_sync on a
uniprocessor boot because membar_sync is only designed to coordinate
between normal memory on multiple CPUs, and is never necessary when
there's only one CPU involved.

But xen_mb is used to coordinate between the guest and the `device'
implemented by a hypervisor, which might be running on another
_physical_ CPU even if the NetBSD guest only sees one `CPU', i.e.,
one _virtual_ CPU. So even on `uniprocessor' boots, xen_mb must
still issue an instruction with store-before-load ordering on
multiprocessor systems, such as a LOCK ADD (or MFENCE, but MFENCE is
costlier for no benefit here).

No need to change xen_wmb (release ordering, load/store-before-store)
or xen_rmb (acquire ordering, load-before-load/store) because every
x86 store is a store-release and every x86 load is a load-acquire,
even on multiprocessor systems, so there's no hotpatching involved
anyway.

PR kern/57199
 1.7 25-Feb-2023  riastradh branches: 1.7.6;
xen: Fix sense of xen_rmb/wmb to make sense.

Use membar_acquire and membar_release, not membar_consumer and
membar_producer, out of paranoia -- that better matches Linux's
rmb/wmb (at least for non-I/O loads and stores).

Proposed on port-xen:
https://mail-index.netbsd.org/port-xen/2022/07/13/msg010248.html
 1.6 25-Apr-2020  bouyer branches: 1.6.20;
Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.5 21-Apr-2020  jdolecek add blkif_x86_{32,64}_request_indirect types
 1.4 07-Apr-2019  bouyer branches: 1.4.4; 1.4.12;
blkif_x86_{32,64}_* are not identical to blkif_*, internal fields have
different alignements and this change their sizes. Copy them back from
their netbsd-8 definitions.
Fixes PR port-xen/54099
 1.3 02-Feb-2019  cherry Fix build. A multiline macro needs 'line continuation'.
 1.2 02-Feb-2019  cherry Remove mb(), rmb() and wmb() from the kernel namespace.

These are introduced by external/bsd/common/include/asm/barrier.h

The purpose of barrier.h is to bridge the use of linux API calls
within code which uses them, such as drm code. The XEN api implicitly
uses these calls which are linuxisms within io/ring.h

This diff undos the damage.

The correct fix is to modify io/ring.h to not assume that all OSs that
XEN runs on has these functions, and to appropriately conditionally via
#ifdef __NetBSD__/#endif use the appropriate NetBSD functions. These
changes then need to be pushed upstream.
 1.1 02-Feb-2019  cherry Switch NetBSD/xen to use XEN api tag RELEASE-4.11.1

The headers for this api are in sys/external/mit/xen-include-public/dist/
 1.4.12.1 25-Apr-2020  bouyer Sync with bouyer-xenpvh-base2 (HEAD)
 1.4.4.3 21-Apr-2020  martin Sync with HEAD
 1.4.4.2 10-Jun-2019  christos Sync with HEAD
 1.4.4.1 07-Apr-2019  christos file xenring.h was added on branch phil-wifi on 2019-06-10 22:06:54 +0000
 1.6.20.2 20-Jul-2024  martin Pull up following revision(s) (requested by riastradh in ticket #764):

common/lib/libc/arch/i386/atomic/atomic.S: revision 1.37
sys/arch/xen/include/xenring.h: revision 1.8
sys/arch/i386/i386/cpufunc.S: revision 1.52
sys/arch/amd64/amd64/cpufunc.S: revision 1.68
sys/arch/xen/include/hypervisor.h: revision 1.60
common/lib/libc/arch/x86_64/atomic/atomic.S: revision 1.30

xen: Don't hotpatch away LOCK prefix in xen_mb, even on UP boots.

Both xen_mb and membar_sync are designed to provide store-before-load
ordering, but xen_mb has to provide it in synchronizing guest with
hypervisor, while membar_sync only has to provide it in synchronizing
one (guest) CPU with another (guest) CPU.

It is safe to hotpatch away the LOCK prefix in membar_sync on a
uniprocessor boot because membar_sync is only designed to coordinate
between normal memory on multiple CPUs, and is never necessary when
there's only one CPU involved.

But xen_mb is used to coordinate between the guest and the `device'
implemented by a hypervisor, which might be running on another
_physical_ CPU even if the NetBSD guest only sees one `CPU', i.e.,
one _virtual_ CPU. So even on `uniprocessor' boots, xen_mb must
still issue an instruction with store-before-load ordering on
multiprocessor systems, such as a LOCK ADD (or MFENCE, but MFENCE is
costlier for no benefit here).

No need to change xen_wmb (release ordering, load/store-before-store)
or xen_rmb (acquire ordering, load-before-load/store) because every
x86 store is a store-release and every x86 load is a load-acquire,
even on multiprocessor systems, so there's no hotpatching involved
anyway.

PR kern/57199
 1.6.20.1 31-Jul-2023  martin Pull up following revision(s) (requested by riastradh in ticket #268):

sys/arch/xen/xenbus/xenbus_comms.c: revision 1.25
sys/arch/xen/xenbus/xenbus_comms.c: revision 1.26
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.110
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.111
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.112
sys/arch/xen/x86/cpu.c: revision 1.144
sys/arch/xen/x86/cpu.c: revision 1.145
sys/arch/xen/include/hypervisor.h: revision 1.56
sys/arch/xen/include/hypervisor.h: revision 1.57
sys/arch/xen/xen/xbdback_xenbus.c: revision 1.102
sys/arch/xen/xen/xbdback_xenbus.c: revision 1.103
sys/arch/xen/include/xenring.h: revision 1.7
sys/arch/xen/xen/xennetback_xenbus.c: revision 1.109
sys/arch/xen/xen/xengnt.c: revision 1.40
sys/arch/xen/xen/xengnt.c: revision 1.41
sys/arch/xen/xen/if_xennet_xenbus.c: revision 1.129
sys/arch/xen/xen/xencons.c: revision 1.51
sys/arch/xen/xen/xencons.c: revision 1.52
sys/arch/xen/xen/xencons.c: revision 1.53
sys/arch/xen/xen/xbd_xenbus.c: revision 1.130 (patch)
sys/arch/xen/xen/xbd_xenbus.c: revision 1.131 (patch)

xen: Fix sense of xen_rmb/wmb to make sense.

Use membar_acquire and membar_release, not membar_consumer and
membar_producer, out of paranoia -- that better matches Linux's
rmb/wmb (at least for non-I/O loads and stores).

Proposed on port-xen:
https://mail-index.netbsd.org/port-xen/2022/07/13/msg010248.html

xen/x86/cpu.c: Membar audit.

I see no reason for store-before-load ordering here; as far as I'm
aware, evtchn_upcall_mask is only shared between a (v)CPU and its
(hypervisor) interrupts, not other (v)CPUs.

xennet(4): Membar audit.
- xennet_tx_complete: Other side owns rsp_prod, giving us responses
to tx commands. We own rsp_cons, recording which responess we've
processed already.
1. Other side initializes responses before advancing rsp_prod, so
we must observe rsp_prod before trying to examine the responses.
Hence load from rsp_prod must be followed by xen_rmb.
(Can this just use atomic_load_acquire?)
2. As soon as other side observes rsp_event, it may start to
overwrite now-unused response slots, so we must finish using the
response before advancing rsp_cons. Hence we must issue xen_wmb
before store to rsp_event.
(Can this just use atomic_store_release?)
(Should this use RING_FINAL_CHECK_FOR_RESPONSES?)
3. When loop is done and we set rsp_event, we must ensure the other
side has had a chance to see that we want more before we check
whether there is more to consume; otherwise the other side might
not bother to send us an interrupt. Hence after setting
rsp_event, we must issue xen_mb (store-before-load) before
re-checking rsp_prod.
- xennet_handler (rx): Same deal, except the xen_mb is buried in
RING_FINAL_CHECK_FOR_RESPONSES. Unclear why xennet_tx_complete has
this open-coded while xennet_handler (rx) uses the macro.

xbd(4): Membar audit.
After consuming slots, must issue xen_wmb before notifying the other
side that we've consumed them in RING_FINAL_CHECK_FOR_RESPONSES.
xbdback(4): Membar audit.

After consuming request slots, must issue xen_wmb notifying the other
side that we've consumed them in RING_FINAL_CHECK_FOR_REQUESTS.

xencons(4): Membar audit.
- xenconscn_getc: Once we have consumed an input slot, it is clearer
to issue xen_wmb (release, i.e., load/store-before-store) before
advancing in_cons so that the update becomes a store-release
freeing the input slot for the other side to reuse.
- xenconscn_putc: After filling an output slot, must issue xen_wmb
(release, i.e., load/store-before-store) before advancing out_prod,
and another one before notifying the other side of the advance.

xencons(4): Reduce unnecessary membars.
- xencons_handler: After advancing in_cons, only need one xen_wmb
before notifying the hypervisor that we're ready for more.
(XXX Should this do xen_mb and re-check in_prod at that point, or
does hypervisor_notify_via_evtchn obviate the need for this?)
- xenvonscn_getc: After reading in_prod, only need one xen_rmb before
using the slots it is telling us are now ready.

xengnt(4): Membar audit.
This had the sense of membars reversed, presumably because xen_rmb
and xen_wmb had gotten reversed at some point.
xenbus_comms.c: Membar audit.

This had the sense of membars reversed, presumably because xen_rmb
and xen_wmb had gotten reversed at some point.

xennetback(4): Fix xennetback_evthandler loop.
- After observing the other side has produced pending tx requests by
reading sring->req_prod, must issue xen_rmb before touching them.
Despite all the effort to use the heavy-weight
RING_FINAL_CHECK_FOR_REQUESTS on each request in the loop, this
barrier was missing.
- No need to update req_cons at each iteration in the loop. It's
private. Just update it once at the end.
- After consuming requests, must issue xen_wmb before releasing the
slots with RING_FINAL_CHECK_FOR_REQUEST for the other side to
reuse.

xennetback(4): Fix membars in xennetback_rx_copy_process.
- No need for barrier around touching req_cons and rsp_prod_pvt,
which are private.
- RING_PUSH_RESPONSES_AND_CHECK_NOTIFY already issues xen_wmb, no
need to add one explicitly.
- After pushing responses, must issue xen_wmb (not xen_rmb) before
hypervisor_notify_via_evtchn.

xennetback(4): Omit needless membars in xennetback_connect.
xneti is a private data structure to which we have exclusive access
here; ordering the stores doesn't make sense.

xen/hypervisor.h: Nix trailing whitespace.
No functional change intended.

xen/x86/cpu.c: Nix trailing whitespace.
No functional change intended.

xbd(4): Nix trailing whitespace.

xbdback(4): Nix trailing whitespace.
No functional change intended.

xencons(4): Nix trailing whitespace.
No functional change intended.

xengnt(4): Nix trailing whitespace.
No functional change intended.

xenbus_comms.c: Nix trailing whitespace.
No functional change intended.

xennetback(4): Nix trailing whitespace.
No functional change intended.
 1.7.6.1 02-Aug-2025  perseant Sync with HEAD
 1.2 22-Nov-2007  bouyer branches: 1.2.2; 1.2.6; 1.2.14; 1.2.16;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.1 19-Nov-2007  bouyer branches: 1.1.2;
file bus_private.h was initially added on branch bouyer-xenamd64.
 1.1.2.1 19-Nov-2007  bouyer Get rid of arch/xenamd64, step 2: move xenamd64/include to xen/include/amd64
 1.2.16.2 09-Jan-2008  matt sync with HEAD
 1.2.16.1 22-Nov-2007  matt file bus_private.h was added on branch matt-armv6 on 2008-01-09 01:50:08 +0000
 1.2.14.2 22-Nov-2007  bouyer Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.2.14.1 22-Nov-2007  bouyer file bus_private.h was added on branch mjf-devfs on 2007-11-22 16:16:59 +0000
 1.2.6.2 07-Dec-2007  yamt sync with head
 1.2.6.1 22-Nov-2007  yamt file bus_private.h was added on branch yamt-lazymbuf on 2007-12-07 17:27:12 +0000
 1.2.2.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.2.2.1 22-Nov-2007  joerg file bus_private.h was added on branch jmcneill-pm on 2007-11-27 19:36:10 +0000
 1.14 25-Apr-2020  bouyer Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.13 21-Apr-2020  jdolecek convert to newer HYPERVISOR_physdev_op() interface, now command and the
arg are separate arguments - this is needed for newer physdev_op commands

remove code for PHYSDEVOP_IRQ_UNMASK_NOTIFY, it is obsolete since
interface version 0x00030202 and is unsupported by newer versions of Xen

confirmed working on amd64 Dom0, i386 compile-tested only
 1.12 10-Feb-2019  cherry branches: 1.12.10;
Catchup hypercall interfaces for HYPERVISOR_sched_op which use
arguments to __XEN_INTERFACE_VERSION__ >= 0x00030201

We've been using the sched_op_compat API with sched_op arguments.

fixes PR port-xen/53965
 1.11 02-Feb-2019  cherry Switch NetBSD/xen to use XEN api tag RELEASE-4.11.1

The headers for this api are in sys/external/mit/xen-include-public/dist/
 1.10 24-Jan-2019  cherry The event_channel_op hypercall uses a newer API since
__XEN_INTERFACE_VERSION__ 0x00030202

Since hvm_op only supports event_channel_op via the newer API, we
can't get away with our current event_channel_op_compat shim.

We thus introduce the new API to our internal hypercall C API
interface.

This change should have no effect on the PV kernels, since they will
continue to use the pre 0x00030202 API.
 1.9 24-Jan-2019  cherry hvm_op returns a signed value.

The pattern is that a hypercall which returns a value < 0 may imply an
error.
 1.8 07-Dec-2011  cegger branches: 1.8.46; 1.8.48;
switch from xen3-public to xen-public.
 1.7 07-Dec-2011  cegger switch from xen3-public to xen-public.
 1.6 30-Mar-2011  jym branches: 1.6.2; 1.6.4; 1.6.8;
Add the HYPERVISOR_sysctl() hypercall.

Although the hypercall arguments (like struct sysctl_readconsole) are not
compatible between different XEN_SYSCTL_INTERFACE_VERSIONs (one of the
reasons why the sysctl calls should only be used by xentools directly),
it's still practical to have when one wants to query Xen's dmesg from
ddb(4) in case of a panic.

Note: additional code is needed for readconsole() functionality, but adding
the hypercall should not cause any harm.
 1.5 13-Nov-2008  cegger branches: 1.5.4; 1.5.8; 1.5.10;
prepare move to new interface
 1.4 24-Oct-2008  jym branches: 1.4.2;
- add mfn_to_pfn() and pfn_to_mfn() macros, for rapid conversion between
pseudo-physical and machine frame numbers.

- add HYPERVISOR_crash() for i386 and amd64. Intended to be used by a domain
to notify Xen that it crashed on purpose, and request a dump (if applicable).

No functional changes intended.

Reviewed by Christoph (cegger@).
 1.3 25-Aug-2008  cegger Add machine check hypercall.
There will be one file where this will be used. In the initialization a hypervisor version check will verify, if this feature is usable or not.
 1.2 22-Nov-2007  bouyer branches: 1.2.2; 1.2.6; 1.2.14; 1.2.16; 1.2.22; 1.2.26; 1.2.28; 1.2.32;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.1 19-Nov-2007  bouyer branches: 1.1.2;
file hypercalls.h was initially added on branch bouyer-xenamd64.
 1.1.2.1 19-Nov-2007  bouyer Get rid of arch/xenamd64, step 2: move xenamd64/include to xen/include/amd64
 1.2.32.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.2.32.1 19-Oct-2008  haad Sync with HEAD.
 1.2.28.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.2.26.1 04-May-2009  yamt sync with head.
 1.2.22.2 17-Jan-2009  mjf Sync with HEAD.
 1.2.22.1 28-Sep-2008  mjf Sync with HEAD.
 1.2.16.2 09-Jan-2008  matt sync with HEAD
 1.2.16.1 22-Nov-2007  matt file hypercalls.h was added on branch matt-armv6 on 2008-01-09 01:50:09 +0000
 1.2.14.2 22-Nov-2007  bouyer Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.2.14.1 22-Nov-2007  bouyer file hypercalls.h was added on branch mjf-devfs on 2007-11-22 16:16:59 +0000
 1.2.6.2 07-Dec-2007  yamt sync with head
 1.2.6.1 22-Nov-2007  yamt file hypercalls.h was added on branch yamt-lazymbuf on 2007-12-07 17:27:12 +0000
 1.2.2.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.2.2.1 22-Nov-2007  joerg file hypercalls.h was added on branch jmcneill-pm on 2007-11-27 19:36:10 +0000
 1.4.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.5.10.1 06-Jun-2011  jruoho Sync with HEAD.
 1.5.8.1 21-Apr-2011  rmind sync with head
 1.5.4.5 02-May-2011  jym Sync with head.
 1.5.4.4 30-Mar-2011  jym Sync with my commits in HEAD.
 1.5.4.3 01-Nov-2009  jym - Upgrade suspend/resume code to comply with Xen2 removal.
- Add support for PAE domUs suspend/resume.
- Fix an issue regarding initialization of the xbd ring I/O that could end
badly during resume, with invalid block operations submitted to dom0 backend.

NetBSD supports PAE under x86_32 by considering the L2 page as being
4 pages long instead of 1.

Xen validates the page types during resume. Sadly, the hypervisor handles
alternative recursive mappings (== PG/PD entries pointing to pages other
than self) inadequately, which could lead to incorrect page pinning.

As a result, the important change with this patch is to clear these alternative
mappings during suspend, and reset them back to their former self upon
resume. For PAE, approx. all 4 PDIR_SLOT_PTEs could be considered as
alternative recursive mappings.

See comments in pmap.c for further details.

Now, let the testing and bug hunting begin.
 1.5.4.2 01-Nov-2009  jym Sync with HEAD.
 1.5.4.1 31-May-2009  jym Modifications for the Xen suspend/migrate/resume branch:

- introduce xenbus_device_{suspend,resume}() functions. These are routines
used to suspend/resume MI parts of the Xenbus device interfaces, like updating
frontend/backend devices' paths found in XenStore.

- introduce HYPERVISOR_sysctl(), an hypercall used only by Xentools to obtain
information from hypervisor (listing VMs, printing console, etc.). I use it
to query xenconsole from ddb(), as a last resort in case of a panic() in
dom0 (xm being not available). Currently unused in the branch; could be, if
requested.

- disable the rwlock(9) used to protect code that could use transient MFNs.
It could trigger nasty context switches in place it should not to.

- fix some bugs in the xennet/xbd suspend/resume pmf(9) handlers.

- following XenSource's design, talk_to_otherend() is now called
watch_otherend(), and free_otherend_details() is used by Xenbus device
suspend/resume routines.

- some slight modifications in pmap regarding APDP. Introduce an inline
function (pmap_unmap_apdp_pde()) that clears APDP entry for the current pmap.

- similarly, implement pmap_unmap_all_apdp_pdes() that iterates through all
pmaps and tears down APDP, as Xen does not handle them properly.

TODO/XXX:

- pmap_unmap_apdp_pde() does not handle APDP shadow entry of PAE. It will,
once I figure out how PAE uses it.

- revisit the pmap locking issue regarding transient MFNs. As NetBSD does not
use kernel preemption and MP for Xen, this could be skipped momentarily. See
http://mail-index.netbsd.org/port-xen/2009/04/27/msg004903.html for details.

- fix a bug regarding grant tables which could technically DoS a dom0 if
ridiculously high consumer/producer indexes are passed down in the ring during
a resume.

All in all, once the grant table index issue and APDP PAE are fixed, next step
is to torture test this branch.

Tested under i386 PAE and non-PAE, Xen3 dom0 and domU. amd64 is only compile
tested.
 1.6.8.1 18-Feb-2012  mrg merge to -current.
 1.6.4.1 17-Apr-2012  yamt sync with head
 1.6.2.1 03-Jun-2011  cherry Initial import of xen MP sources, with kernel and userspace tests.
- this is a source priview.
- boots to single user.
- spurious interrupt and pmap related panics are normal
 1.8.48.1 10-Jun-2019  christos Sync with HEAD
 1.8.46.1 26-Jan-2019  pgoyette Sync with HEAD
 1.12.10.1 16-Apr-2020  bouyer Reorganise sources to make it possible to include Xen PVHVM support in
native kernels. Among others:
- move xen/include/amd64/hypercall.h to amd64/include/xen and
xen/include/i386/hypercall.h to i386/include/xen
- exclude some native files from the build for xenpv
- add xen to "machine" config statement for amd64 and i386
- split arch/xen/conf/files.xen to arch/xen/conf/files.xen (for pv drivers)
and arch/xen/conf/files.xen.pv (for full pv support)
- add GENERIC_XENHVM kernel config which includes GENERIC and add Xen PV
drivers.
 1.2 22-Nov-2007  bouyer branches: 1.2.2; 1.2.6; 1.2.14; 1.2.16;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.1 19-Nov-2007  bouyer branches: 1.1.2;
file i82093var.h was initially added on branch bouyer-xenamd64.
 1.1.2.1 19-Nov-2007  bouyer Get rid of arch/xenamd64, step 2: move xenamd64/include to xen/include/amd64
 1.2.16.2 09-Jan-2008  matt sync with HEAD
 1.2.16.1 22-Nov-2007  matt file i82093var.h was added on branch matt-armv6 on 2008-01-09 01:50:09 +0000
 1.2.14.2 22-Nov-2007  bouyer Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.2.14.1 22-Nov-2007  bouyer file i82093var.h was added on branch mjf-devfs on 2007-11-22 16:17:00 +0000
 1.2.6.2 07-Dec-2007  yamt sync with head
 1.2.6.1 22-Nov-2007  yamt file i82093var.h was added on branch yamt-lazymbuf on 2007-12-07 17:27:12 +0000
 1.2.2.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.2.2.1 22-Nov-2007  joerg file i82093var.h was added on branch jmcneill-pm on 2007-11-27 19:36:11 +0000
 1.2 22-Nov-2007  bouyer branches: 1.2.2; 1.2.6; 1.2.14; 1.2.16;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.1 19-Nov-2007  bouyer branches: 1.1.2;
file i82489var.h was initially added on branch bouyer-xenamd64.
 1.1.2.1 19-Nov-2007  bouyer Get rid of arch/xenamd64, step 2: move xenamd64/include to xen/include/amd64
 1.2.16.2 09-Jan-2008  matt sync with HEAD
 1.2.16.1 22-Nov-2007  matt file i82489var.h was added on branch matt-armv6 on 2008-01-09 01:50:09 +0000
 1.2.14.2 22-Nov-2007  bouyer Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.2.14.1 22-Nov-2007  bouyer file i82489var.h was added on branch mjf-devfs on 2007-11-22 16:17:00 +0000
 1.2.6.2 07-Dec-2007  yamt sync with head
 1.2.6.1 22-Nov-2007  yamt file i82489var.h was added on branch yamt-lazymbuf on 2007-12-07 17:27:13 +0000
 1.2.2.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.2.2.1 22-Nov-2007  joerg file i82489var.h was added on branch jmcneill-pm on 2007-11-27 19:36:12 +0000
 1.2 22-Nov-2007  bouyer branches: 1.2.2; 1.2.6; 1.2.14; 1.2.16;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.1 19-Nov-2007  bouyer branches: 1.1.2;
file intr.h was initially added on branch bouyer-xenamd64.
 1.1.2.1 19-Nov-2007  bouyer Get rid of arch/xenamd64, step 2: move xenamd64/include to xen/include/amd64
 1.2.16.2 09-Jan-2008  matt sync with HEAD
 1.2.16.1 22-Nov-2007  matt file intr.h was added on branch matt-armv6 on 2008-01-09 01:50:10 +0000
 1.2.14.2 22-Nov-2007  bouyer Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.2.14.1 22-Nov-2007  bouyer file intr.h was added on branch mjf-devfs on 2007-11-22 16:17:01 +0000
 1.2.6.2 07-Dec-2007  yamt sync with head
 1.2.6.1 22-Nov-2007  yamt file intr.h was added on branch yamt-lazymbuf on 2007-12-07 17:27:13 +0000
 1.2.2.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.2.2.1 22-Nov-2007  joerg file intr.h was added on branch jmcneill-pm on 2007-11-27 19:36:12 +0000
 1.3 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.2 22-Nov-2007  bouyer branches: 1.2.2; 1.2.6; 1.2.10; 1.2.14; 1.2.16;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.1 19-Nov-2007  bouyer branches: 1.1.2;
file intrdefs.h was initially added on branch bouyer-xenamd64.
 1.1.2.1 19-Nov-2007  bouyer Get rid of arch/xenamd64, step 2: move xenamd64/include to xen/include/amd64
 1.2.16.3 23-Mar-2008  matt sync with HEAD
 1.2.16.2 09-Jan-2008  matt sync with HEAD
 1.2.16.1 22-Nov-2007  matt file intrdefs.h was added on branch matt-armv6 on 2008-01-09 01:50:10 +0000
 1.2.14.2 18-Feb-2008  mjf Sync with HEAD.
 1.2.14.1 22-Nov-2007  mjf file intrdefs.h was added on branch mjf-devfs on 2008-02-18 21:05:20 +0000
 1.2.10.1 05-Jan-2008  bouyer Remove files that just include the x86 counterpart.
 1.2.6.3 21-Jan-2008  yamt sync with head
 1.2.6.2 07-Dec-2007  yamt sync with head
 1.2.6.1 22-Nov-2007  yamt file intrdefs.h was added on branch yamt-lazymbuf on 2007-12-07 17:27:13 +0000
 1.2.2.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.2.2.1 22-Nov-2007  joerg file intrdefs.h was added on branch jmcneill-pm on 2007-11-27 19:36:13 +0000
 1.3 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.2 22-Nov-2007  bouyer branches: 1.2.2; 1.2.6; 1.2.10; 1.2.14; 1.2.16;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.1 19-Nov-2007  bouyer branches: 1.1.2;
file mpacpi.h was initially added on branch bouyer-xenamd64.
 1.1.2.1 19-Nov-2007  bouyer Get rid of arch/xenamd64, step 2: move xenamd64/include to xen/include/amd64
 1.2.16.3 23-Mar-2008  matt sync with HEAD
 1.2.16.2 09-Jan-2008  matt sync with HEAD
 1.2.16.1 22-Nov-2007  matt file mpacpi.h was added on branch matt-armv6 on 2008-01-09 01:50:10 +0000
 1.2.14.2 18-Feb-2008  mjf Sync with HEAD.
 1.2.14.1 22-Nov-2007  mjf file mpacpi.h was added on branch mjf-devfs on 2008-02-18 21:05:20 +0000
 1.2.10.1 05-Jan-2008  bouyer Remove files that just include the x86 counterpart.
 1.2.6.3 21-Jan-2008  yamt sync with head
 1.2.6.2 07-Dec-2007  yamt sync with head
 1.2.6.1 22-Nov-2007  yamt file mpacpi.h was added on branch yamt-lazymbuf on 2007-12-07 17:27:13 +0000
 1.2.2.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.2.2.1 22-Nov-2007  joerg file mpacpi.h was added on branch jmcneill-pm on 2007-11-27 19:36:14 +0000
 1.3 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.2 22-Nov-2007  bouyer branches: 1.2.2; 1.2.6; 1.2.10; 1.2.14; 1.2.16;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.1 19-Nov-2007  bouyer branches: 1.1.2;
file mutex.h was initially added on branch bouyer-xenamd64.
 1.1.2.1 19-Nov-2007  bouyer Get rid of arch/xenamd64, step 2: move xenamd64/include to xen/include/amd64
 1.2.16.3 23-Mar-2008  matt sync with HEAD
 1.2.16.2 09-Jan-2008  matt sync with HEAD
 1.2.16.1 22-Nov-2007  matt file mutex.h was added on branch matt-armv6 on 2008-01-09 01:50:10 +0000
 1.2.14.2 18-Feb-2008  mjf Sync with HEAD.
 1.2.14.1 22-Nov-2007  mjf file mutex.h was added on branch mjf-devfs on 2008-02-18 21:05:20 +0000
 1.2.10.1 05-Jan-2008  bouyer Remove files that just include the x86 counterpart.
 1.2.6.3 21-Jan-2008  yamt sync with head
 1.2.6.2 07-Dec-2007  yamt sync with head
 1.2.6.1 22-Nov-2007  yamt file mutex.h was added on branch yamt-lazymbuf on 2007-12-07 17:27:14 +0000
 1.2.2.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.2.2.1 22-Nov-2007  joerg file mutex.h was added on branch jmcneill-pm on 2007-11-27 19:36:14 +0000
 1.2 22-Nov-2007  bouyer branches: 1.2.2; 1.2.6; 1.2.14; 1.2.16;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.1 19-Nov-2007  bouyer branches: 1.1.2;
file pci_machdep.h was initially added on branch bouyer-xenamd64.
 1.1.2.1 19-Nov-2007  bouyer Get rid of arch/xenamd64, step 2: move xenamd64/include to xen/include/amd64
 1.2.16.2 09-Jan-2008  matt sync with HEAD
 1.2.16.1 22-Nov-2007  matt file pci_machdep.h was added on branch matt-armv6 on 2008-01-09 01:50:11 +0000
 1.2.14.2 22-Nov-2007  bouyer Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.2.14.1 22-Nov-2007  bouyer file pci_machdep.h was added on branch mjf-devfs on 2007-11-22 16:17:02 +0000
 1.2.6.2 07-Dec-2007  yamt sync with head
 1.2.6.1 22-Nov-2007  yamt file pci_machdep.h was added on branch yamt-lazymbuf on 2007-12-07 17:27:14 +0000
 1.2.2.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.2.2.1 22-Nov-2007  joerg file pci_machdep.h was added on branch jmcneill-pm on 2007-11-27 19:36:15 +0000
 1.2 22-Nov-2007  bouyer branches: 1.2.2; 1.2.6; 1.2.14; 1.2.16;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.1 19-Nov-2007  bouyer branches: 1.1.2;
file pic.h was initially added on branch bouyer-xenamd64.
 1.1.2.1 19-Nov-2007  bouyer Get rid of arch/xenamd64, step 2: move xenamd64/include to xen/include/amd64
 1.2.16.2 09-Jan-2008  matt sync with HEAD
 1.2.16.1 22-Nov-2007  matt file pic.h was added on branch matt-armv6 on 2008-01-09 01:50:11 +0000
 1.2.14.2 22-Nov-2007  bouyer Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.2.14.1 22-Nov-2007  bouyer file pic.h was added on branch mjf-devfs on 2007-11-22 16:17:02 +0000
 1.2.6.2 07-Dec-2007  yamt sync with head
 1.2.6.1 22-Nov-2007  yamt file pic.h was added on branch yamt-lazymbuf on 2007-12-07 17:27:14 +0000
 1.2.2.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.2.2.1 22-Nov-2007  joerg file pic.h was added on branch jmcneill-pm on 2007-11-27 19:36:15 +0000
 1.3 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.2 22-Nov-2007  bouyer branches: 1.2.2; 1.2.6; 1.2.10; 1.2.14; 1.2.16;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.1 19-Nov-2007  bouyer branches: 1.1.2;
file rwlock.h was initially added on branch bouyer-xenamd64.
 1.1.2.1 19-Nov-2007  bouyer Get rid of arch/xenamd64, step 2: move xenamd64/include to xen/include/amd64
 1.2.16.3 23-Mar-2008  matt sync with HEAD
 1.2.16.2 09-Jan-2008  matt sync with HEAD
 1.2.16.1 22-Nov-2007  matt file rwlock.h was added on branch matt-armv6 on 2008-01-09 01:50:11 +0000
 1.2.14.2 18-Feb-2008  mjf Sync with HEAD.
 1.2.14.1 22-Nov-2007  mjf file rwlock.h was added on branch mjf-devfs on 2008-02-18 21:05:20 +0000
 1.2.10.1 05-Jan-2008  bouyer Remove files that just include the x86 counterpart.
 1.2.6.3 21-Jan-2008  yamt sync with head
 1.2.6.2 07-Dec-2007  yamt sync with head
 1.2.6.1 22-Nov-2007  yamt file rwlock.h was added on branch yamt-lazymbuf on 2007-12-07 17:27:15 +0000
 1.2.2.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.2.2.1 22-Nov-2007  joerg file rwlock.h was added on branch jmcneill-pm on 2007-11-27 19:36:16 +0000
 1.4 25-Aug-2023  riastradh xen: Provide definitions or ifdefs to make drm build in XEN3_DOM0.

No idea if it works, but it builds now.

PR port-xen/49330
 1.3 14-Feb-2019  cherry Snag the final bits of PV only code to conditionally compile under
-DXENPV

This completes the bifurcation.

The next step is to add -DXENPVHVM code.
 1.2 22-Nov-2007  bouyer branches: 1.2.2; 1.2.6; 1.2.14; 1.2.16; 1.2.114;
Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.1 19-Nov-2007  bouyer branches: 1.1.2;
file vmparam.h was initially added on branch bouyer-xenamd64.
 1.1.2.1 19-Nov-2007  bouyer Get rid of arch/xenamd64, step 2: move xenamd64/include to xen/include/amd64
 1.2.114.1 10-Jun-2019  christos Sync with HEAD
 1.2.16.2 09-Jan-2008  matt sync with HEAD
 1.2.16.1 22-Nov-2007  matt file vmparam.h was added on branch matt-armv6 on 2008-01-09 01:50:11 +0000
 1.2.14.2 22-Nov-2007  bouyer Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.2.14.1 22-Nov-2007  bouyer file vmparam.h was added on branch mjf-devfs on 2007-11-22 16:17:03 +0000
 1.2.6.2 07-Dec-2007  yamt sync with head
 1.2.6.1 22-Nov-2007  yamt file vmparam.h was added on branch yamt-lazymbuf on 2007-12-07 17:27:15 +0000
 1.2.2.2 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.2.2.1 22-Nov-2007  joerg file vmparam.h was added on branch jmcneill-pm on 2007-11-27 19:36:16 +0000
 1.2 11-Jan-2008  bouyer branches: 1.2.2; 1.2.4; 1.2.12;
Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.1 10-Jan-2008  bouyer branches: 1.1.2;
file bus_private.h was initially added on branch bouyer-xeni386.
 1.1.2.1 10-Jan-2008  bouyer Change xeni386 build to match xenamd64:
- machine/ points to xen/include/i386
- remove includes that were identical to the i386/include/ ones; the build
will find them though the xen-ma/machine link.
- include xen files using xen/ not machine/
 1.2.12.2 23-Mar-2008  matt sync with HEAD
 1.2.12.1 11-Jan-2008  matt file bus_private.h was added on branch matt-armv6 on 2008-03-23 02:04:30 +0000
 1.2.4.2 18-Feb-2008  mjf Sync with HEAD.
 1.2.4.1 11-Jan-2008  mjf file bus_private.h was added on branch mjf-devfs on 2008-02-18 21:05:20 +0000
 1.2.2.2 21-Jan-2008  yamt sync with head
 1.2.2.1 11-Jan-2008  yamt file bus_private.h was added on branch yamt-lazymbuf on 2008-01-21 09:40:28 +0000
 1.21 25-Apr-2020  bouyer Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.20 21-Apr-2020  jdolecek convert to newer HYPERVISOR_physdev_op() interface, now command and the
arg are separate arguments - this is needed for newer physdev_op commands

remove code for PHYSDEVOP_IRQ_UNMASK_NOTIFY, it is obsolete since
interface version 0x00030202 and is unsupported by newer versions of Xen

confirmed working on amd64 Dom0, i386 compile-tested only
 1.19 10-Feb-2019  cherry branches: 1.19.10;
Catchup hypercall interfaces for HYPERVISOR_sched_op which use
arguments to __XEN_INTERFACE_VERSION__ >= 0x00030201

We've been using the sched_op_compat API with sched_op arguments.

fixes PR port-xen/53965
 1.18 02-Feb-2019  cherry Switch NetBSD/xen to use XEN api tag RELEASE-4.11.1

The headers for this api are in sys/external/mit/xen-include-public/dist/
 1.17 24-Jan-2019  cherry The event_channel_op hypercall uses a newer API since
__XEN_INTERFACE_VERSION__ 0x00030202

Since hvm_op only supports event_channel_op via the newer API, we
can't get away with our current event_channel_op_compat shim.

We thus introduce the new API to our internal hypercall C API
interface.

This change should have no effect on the PV kernels, since they will
continue to use the pre 0x00030202 API.
 1.16 26-Jul-2018  maxv Remove the non-PAE-i386 code of Xen. The branches are reordered so that
__x86_64__ comes first, eg:

#if defined(PAE)
/* i386+PAE */
#elif defined(__x86_64__)
/* amd64 */
#else
/* i386 */
#endif

becomes

#ifdef __x86_64__
/* amd64 */
#else
/* i386+PAE */
#endif

Tested on i386pae-domU and amd64-dom0.
 1.15 27-Jun-2012  jym branches: 1.15.38; 1.15.40;
Retire XEN_COMPAT_030001 as detailed on port-xen@:

http://mail-index.netbsd.org/port-xen/2012/06/25/msg007431.html

The xen_p2m API comes next.

ok bouyer@.
Tested on i386 PAE and amd64 (Xen 3.3 on private test bed, and
Xen 3.4 for Amazon EC2).

FWIW, Amazon always reported:

hypervisor0 at mainbus0: Xen version 3.4.3-kaos_t1micro

multiple times for Europe and US West-1, so I guess they are now at
3.4 (32 and 64 bits).
 1.14 07-Dec-2011  cegger switch from xen3-public to xen-public.
 1.13 07-Dec-2011  cegger switch from xen3-public to xen-public.
 1.12 07-Jun-2011  bouyer branches: 1.12.2; 1.12.6;
Don't call psignal() without holding proc_lock. This is the cause of
the reboot of PR port-xen/45028
Now that Xen2 is gone, handle FPU context switches the same way as
amd64. This makes all tests in /usr/tests/lib/libc/ieeefp pass.
 1.11 30-Mar-2011  jym branches: 1.11.2;
Add the HYPERVISOR_sysctl() hypercall.

Although the hypercall arguments (like struct sysctl_readconsole) are not
compatible between different XEN_SYSCTL_INTERFACE_VERSIONs (one of the
reasons why the sysctl calls should only be used by xentools directly),
it's still practical to have when one wants to query Xen's dmesg from
ddb(4) in case of a panic.

Note: additional code is needed for readconsole() functionality, but adding
the hypercall should not cause any harm.
 1.10 19-Oct-2009  bouyer branches: 1.10.4; 1.10.6;
Remove closes 3 & 4 from my licence. Lots of thanks to Soren Jacobsen
for the booring work !
 1.9 29-Jul-2009  cegger remove Xen2 support.
ok bouyer@
 1.8 13-Nov-2008  cegger branches: 1.8.4;
add platform_op hypercall (already exists for amd64)
 1.7 13-Nov-2008  cegger prepare move to new interface
 1.6 24-Oct-2008  jym branches: 1.6.2;
- add mfn_to_pfn() and pfn_to_mfn() macros, for rapid conversion between
pseudo-physical and machine frame numbers.

- add HYPERVISOR_crash() for i386 and amd64. Intended to be used by a domain
to notify Xen that it crashed on purpose, and request a dump (if applicable).

No functional changes intended.

Reviewed by Christoph (cegger@).
 1.5 21-Oct-2008  cegger catch up with amd64: add hvm_op hypercall
 1.4 25-Aug-2008  cegger Add machine check hypercall.
There will be one file where this will be used. In the initialization a hypervisor version check will verify, if this feature is usable or not.
 1.3 23-Jan-2008  bouyer branches: 1.3.2; 1.3.8; 1.3.10; 1.3.14; 1.3.16; 1.3.20;
Merge the bouyer-xeni386 branch. This brings in PAE support to NetBSD xeni386
(domU only). PAE support is enabled by 'options PAE', see the new XEN3PAE_DOMU
and INSTALL_XEN3PAE_DOMU kernel config files.

See the comments in arch/i386/include/{pte.h,pmap.h} to see how it works.
In short, we still handle it as a 2-level MMU, with the second level page
directory being 4 pages in size. pmap switching is done by switching the
L2 pages in the L3 entries, instead of loading %cr3. This is almost required
by Xen, which handle the last L2 page (the one mapping 0xc0000000 - 0xffffffff)
in a very special way. But this approach should also work for native PAE
support if ever supported (in fact, the pmap should almost suport native
PAE, what's missing is bootstrap code in locore.S).
 1.2 11-Jan-2008  bouyer branches: 1.2.2;
Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.1 10-Jan-2008  bouyer branches: 1.1.2;
file hypercalls.h was initially added on branch bouyer-xeni386.
 1.1.2.4 20-Jan-2008  bouyer Remove debug printk()
 1.1.2.3 13-Jan-2008  bouyer Make non-PAE kernels build again.
 1.1.2.2 13-Jan-2008  bouyer Work in progress on xeni386 PAE support:
Make xeni386 build with a 64bit paddr_t. For this vaddr_t vs paddr_t vs
pointers usages had to be clarified.
If 'options PAE' is present in a Xen3 kernel, switch paddr_t, pd_entry_t
and pt_entry_t to 64bits, and add the PAE entry in the __xen_guest ELF section.
 1.1.2.1 10-Jan-2008  bouyer Change xeni386 build to match xenamd64:
- machine/ points to xen/include/i386
- remove includes that were identical to the i386/include/ ones; the build
will find them though the xen-ma/machine link.
- include xen files using xen/ not machine/
 1.2.2.3 04-Feb-2008  yamt sync with head.
 1.2.2.2 21-Jan-2008  yamt sync with head
 1.2.2.1 11-Jan-2008  yamt file hypercalls.h was added on branch yamt-lazymbuf on 2008-01-21 09:40:29 +0000
 1.3.20.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.3.20.1 19-Oct-2008  haad Sync with HEAD.
 1.3.16.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.3.14.3 11-Mar-2010  yamt sync with head
 1.3.14.2 19-Aug-2009  yamt sync with head.
 1.3.14.1 04-May-2009  yamt sync with head.
 1.3.10.2 23-Mar-2008  matt sync with HEAD
 1.3.10.1 23-Jan-2008  matt file hypercalls.h was added on branch matt-armv6 on 2008-03-23 02:04:30 +0000
 1.3.8.2 17-Jan-2009  mjf Sync with HEAD.
 1.3.8.1 28-Sep-2008  mjf Sync with HEAD.
 1.3.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.3.2.1 23-Jan-2008  mjf file hypercalls.h was added on branch mjf-devfs on 2008-02-18 21:05:20 +0000
 1.6.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.8.4.6 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.8.4.5 02-May-2011  jym Sync with head.
 1.8.4.4 30-Mar-2011  jym Sync with my commits in HEAD.
 1.8.4.3 01-Nov-2009  jym - Upgrade suspend/resume code to comply with Xen2 removal.
- Add support for PAE domUs suspend/resume.
- Fix an issue regarding initialization of the xbd ring I/O that could end
badly during resume, with invalid block operations submitted to dom0 backend.

NetBSD supports PAE under x86_32 by considering the L2 page as being
4 pages long instead of 1.

Xen validates the page types during resume. Sadly, the hypervisor handles
alternative recursive mappings (== PG/PD entries pointing to pages other
than self) inadequately, which could lead to incorrect page pinning.

As a result, the important change with this patch is to clear these alternative
mappings during suspend, and reset them back to their former self upon
resume. For PAE, approx. all 4 PDIR_SLOT_PTEs could be considered as
alternative recursive mappings.

See comments in pmap.c for further details.

Now, let the testing and bug hunting begin.
 1.8.4.2 01-Nov-2009  jym Sync with HEAD.
 1.8.4.1 31-May-2009  jym Modifications for the Xen suspend/migrate/resume branch:

- introduce xenbus_device_{suspend,resume}() functions. These are routines
used to suspend/resume MI parts of the Xenbus device interfaces, like updating
frontend/backend devices' paths found in XenStore.

- introduce HYPERVISOR_sysctl(), an hypercall used only by Xentools to obtain
information from hypervisor (listing VMs, printing console, etc.). I use it
to query xenconsole from ddb(), as a last resort in case of a panic() in
dom0 (xm being not available). Currently unused in the branch; could be, if
requested.

- disable the rwlock(9) used to protect code that could use transient MFNs.
It could trigger nasty context switches in place it should not to.

- fix some bugs in the xennet/xbd suspend/resume pmf(9) handlers.

- following XenSource's design, talk_to_otherend() is now called
watch_otherend(), and free_otherend_details() is used by Xenbus device
suspend/resume routines.

- some slight modifications in pmap regarding APDP. Introduce an inline
function (pmap_unmap_apdp_pde()) that clears APDP entry for the current pmap.

- similarly, implement pmap_unmap_all_apdp_pdes() that iterates through all
pmaps and tears down APDP, as Xen does not handle them properly.

TODO/XXX:

- pmap_unmap_apdp_pde() does not handle APDP shadow entry of PAE. It will,
once I figure out how PAE uses it.

- revisit the pmap locking issue regarding transient MFNs. As NetBSD does not
use kernel preemption and MP for Xen, this could be skipped momentarily. See
http://mail-index.netbsd.org/port-xen/2009/04/27/msg004903.html for details.

- fix a bug regarding grant tables which could technically DoS a dom0 if
ridiculously high consumer/producer indexes are passed down in the ring during
a resume.

All in all, once the grant table index issue and APDP PAE are fixed, next step
is to torture test this branch.

Tested under i386 PAE and non-PAE, Xen3 dom0 and domU. amd64 is only compile
tested.
 1.10.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.10.4.2 12-Jun-2011  rmind sync with head
 1.10.4.1 21-Apr-2011  rmind sync with head
 1.11.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.12.6.1 18-Feb-2012  mrg merge to -current.
 1.12.2.2 30-Oct-2012  yamt sync with head
 1.12.2.1 17-Apr-2012  yamt sync with head
 1.15.40.1 10-Jun-2019  christos Sync with HEAD
 1.15.38.2 26-Jan-2019  pgoyette Sync with HEAD
 1.15.38.1 28-Jul-2018  pgoyette Sync with HEAD
 1.19.10.1 16-Apr-2020  bouyer Reorganise sources to make it possible to include Xen PVHVM support in
native kernels. Among others:
- move xen/include/amd64/hypercall.h to amd64/include/xen and
xen/include/i386/hypercall.h to i386/include/xen
- exclude some native files from the build for xenpv
- add xen to "machine" config statement for amd64 and i386
- split arch/xen/conf/files.xen to arch/xen/conf/files.xen (for pv drivers)
and arch/xen/conf/files.xen.pv (for full pv support)
- add GENERIC_XENHVM kernel config which includes GENERIC and add Xen PV
drivers.
 1.2 11-Jan-2008  bouyer branches: 1.2.2; 1.2.4; 1.2.12;
Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.1 10-Jan-2008  bouyer branches: 1.1.2;
file i82093var.h was initially added on branch bouyer-xeni386.
 1.1.2.1 10-Jan-2008  bouyer Change xeni386 build to match xenamd64:
- machine/ points to xen/include/i386
- remove includes that were identical to the i386/include/ ones; the build
will find them though the xen-ma/machine link.
- include xen files using xen/ not machine/
 1.2.12.2 23-Mar-2008  matt sync with HEAD
 1.2.12.1 11-Jan-2008  matt file i82093var.h was added on branch matt-armv6 on 2008-03-23 02:04:30 +0000
 1.2.4.2 18-Feb-2008  mjf Sync with HEAD.
 1.2.4.1 11-Jan-2008  mjf file i82093var.h was added on branch mjf-devfs on 2008-02-18 21:05:20 +0000
 1.2.2.2 21-Jan-2008  yamt sync with head
 1.2.2.1 11-Jan-2008  yamt file i82093var.h was added on branch yamt-lazymbuf on 2008-01-21 09:40:29 +0000
 1.2 11-Jan-2008  bouyer branches: 1.2.2; 1.2.4; 1.2.12;
Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.1 10-Jan-2008  bouyer branches: 1.1.2;
file i82489var.h was initially added on branch bouyer-xeni386.
 1.1.2.1 10-Jan-2008  bouyer Change xeni386 build to match xenamd64:
- machine/ points to xen/include/i386
- remove includes that were identical to the i386/include/ ones; the build
will find them though the xen-ma/machine link.
- include xen files using xen/ not machine/
 1.2.12.2 23-Mar-2008  matt sync with HEAD
 1.2.12.1 11-Jan-2008  matt file i82489var.h was added on branch matt-armv6 on 2008-03-23 02:04:30 +0000
 1.2.4.2 18-Feb-2008  mjf Sync with HEAD.
 1.2.4.1 11-Jan-2008  mjf file i82489var.h was added on branch mjf-devfs on 2008-02-18 21:05:20 +0000
 1.2.2.2 21-Jan-2008  yamt sync with head
 1.2.2.1 11-Jan-2008  yamt file i82489var.h was added on branch yamt-lazymbuf on 2008-01-21 09:40:29 +0000
 1.2 11-Jan-2008  bouyer branches: 1.2.2; 1.2.4; 1.2.12;
Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.1 10-Jan-2008  bouyer branches: 1.1.2;
file intr.h was initially added on branch bouyer-xeni386.
 1.1.2.1 10-Jan-2008  bouyer Change xeni386 build to match xenamd64:
- machine/ points to xen/include/i386
- remove includes that were identical to the i386/include/ ones; the build
will find them though the xen-ma/machine link.
- include xen files using xen/ not machine/
 1.2.12.2 23-Mar-2008  matt sync with HEAD
 1.2.12.1 11-Jan-2008  matt file intr.h was added on branch matt-armv6 on 2008-03-23 02:04:30 +0000
 1.2.4.2 18-Feb-2008  mjf Sync with HEAD.
 1.2.4.1 11-Jan-2008  mjf file intr.h was added on branch mjf-devfs on 2008-02-18 21:05:20 +0000
 1.2.2.2 21-Jan-2008  yamt sync with head
 1.2.2.1 11-Jan-2008  yamt file intr.h was added on branch yamt-lazymbuf on 2008-01-21 09:40:30 +0000
 1.2 11-Jan-2008  bouyer branches: 1.2.2; 1.2.4; 1.2.12;
Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.1 10-Jan-2008  bouyer branches: 1.1.2;
file pci_machdep.h was initially added on branch bouyer-xeni386.
 1.1.2.1 10-Jan-2008  bouyer Change xeni386 build to match xenamd64:
- machine/ points to xen/include/i386
- remove includes that were identical to the i386/include/ ones; the build
will find them though the xen-ma/machine link.
- include xen files using xen/ not machine/
 1.2.12.2 23-Mar-2008  matt sync with HEAD
 1.2.12.1 11-Jan-2008  matt file pci_machdep.h was added on branch matt-armv6 on 2008-03-23 02:04:30 +0000
 1.2.4.2 18-Feb-2008  mjf Sync with HEAD.
 1.2.4.1 11-Jan-2008  mjf file pci_machdep.h was added on branch mjf-devfs on 2008-02-18 21:05:20 +0000
 1.2.2.2 21-Jan-2008  yamt sync with head
 1.2.2.1 11-Jan-2008  yamt file pci_machdep.h was added on branch yamt-lazymbuf on 2008-01-21 09:40:30 +0000
 1.2 11-Jan-2008  bouyer branches: 1.2.2; 1.2.4; 1.2.12;
Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.1 10-Jan-2008  bouyer branches: 1.1.2;
file pic.h was initially added on branch bouyer-xeni386.
 1.1.2.1 10-Jan-2008  bouyer Change xeni386 build to match xenamd64:
- machine/ points to xen/include/i386
- remove includes that were identical to the i386/include/ ones; the build
will find them though the xen-ma/machine link.
- include xen files using xen/ not machine/
 1.2.12.2 23-Mar-2008  matt sync with HEAD
 1.2.12.1 11-Jan-2008  matt file pic.h was added on branch matt-armv6 on 2008-03-23 02:04:30 +0000
 1.2.4.2 18-Feb-2008  mjf Sync with HEAD.
 1.2.4.1 11-Jan-2008  mjf file pic.h was added on branch mjf-devfs on 2008-02-18 21:05:20 +0000
 1.2.2.2 21-Jan-2008  yamt sync with head
 1.2.2.1 11-Jan-2008  yamt file pic.h was added on branch yamt-lazymbuf on 2008-01-21 09:40:30 +0000

RSS XML Feed