summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConstantine Sapuntzakis <csapuntz@cvs.openbsd.org>1999-09-22 03:16:49 +0000
committerConstantine Sapuntzakis <csapuntz@cvs.openbsd.org>1999-09-22 03:16:49 +0000
commitb7948e65df5ca1cb27c1a2318c6bd7ffcec11da4 (patch)
tree194067e41fe6dcb1b281ce218fa781a36715915e
parentf2e2e3ffeb45092329eef516524f86fdbbd7ffa6 (diff)
Add/update some man9 pages from NetBSD
-rw-r--r--share/man/man9/Makefile101
-rw-r--r--share/man/man9/access.984
-rw-r--r--share/man/man9/arp.9146
-rw-r--r--share/man/man9/audio.9420
-rw-r--r--share/man/man9/bus_dma.9673
-rw-r--r--share/man/man9/bus_space.91239
-rw-r--r--share/man/man9/ctxsw.9 (renamed from share/man/man9/mi_switch.9)19
-rw-r--r--share/man/man9/disk.964
-rw-r--r--share/man/man9/disklabel.9191
-rw-r--r--share/man/man9/ethersubr.9195
-rw-r--r--share/man/man9/extent.9211
-rw-r--r--share/man/man9/log.91
-rw-r--r--share/man/man9/man9.i386/Makefile7
-rw-r--r--share/man/man9/man9.i386/bioscall.9123
-rw-r--r--share/man/man9/mbuf.9574
-rw-r--r--share/man/man9/pool.9343
-rw-r--r--share/man/man9/printf.91
-rw-r--r--share/man/man9/uiomove.9146
-rw-r--r--share/man/man9/uvm.91012
-rw-r--r--share/man/man9/vslock.968
-rw-r--r--share/man/man9/wdc.9413
21 files changed, 5907 insertions, 124 deletions
diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile
index e0253a95b06..5ade4b884b2 100644
--- a/share/man/man9/Makefile
+++ b/share/man/man9/Makefile
@@ -1,21 +1,72 @@
-# $OpenBSD: Makefile,v 1.12 1999/09/05 16:23:11 espie Exp $
+# $OpenBSD: Makefile,v 1.13 1999/09/22 03:16:46 csapuntz Exp $
# $NetBSD: Makefile,v 1.4 1996/01/09 03:23:01 thorpej Exp $
# Makefile for section 9 (kernel function and variable) manual pages.
-MAN= boot.9 copy.9 disk.9 doshutdownhooks.9 fetch.9 fork1.9 \
+MAN= access.9 arp.9 audio.9 boot.9 bus_space.9 bus_dma.9 copy.9 ctxsw.9 \
+ disk.9 disklabel.9 doshutdownhooks.9 ethersubr.9 fetch.9 fork1.9 \
extent.9 hz.9 hzto.9 intro.9 inittodr.9 log.9 kthread.9 \
- malloc.9 md5.9 microtime.9 panic.9 pfind.9 printf.9 \
- psignal.9 resettodr.9 \
- random.9 shutdownhook_establish.9 sleep.9 spl.9 store.9 style.9 \
- time.9 timeout.9 vm_allocate.9 vm_map_copy.9 vm_deallocate.9 \
+ malloc.9 mbuf.9 md5.9 microtime.9 panic.9 pfind.9 pool.9 \
+ printf.9 psignal.9 resettodr.9 random.9 \
+ shutdownhook_establish.9 sleep.9 spl.9 \
+ store.9 style.9 time.9 timeout.9 uiomove.9 uvm.9 vslock.9 wdc.9 \
+ vm_allocate.9 vm_map_copy.9 vm_deallocate.9 \
vm_map_inherit.9 vm_map_protect.9
+MLINKS+=access.9 kernacc.9 access.9 useracc.9
+MLINKS+=arp.9 arp_ifinit.9 arp.9 arpresolve.9 arp.9 arpintr.9
+MLINKS+=bus_space.9 bus_space_alloc.9 bus_space.9 bus_space_barrier.9 \
+ bus_space.9 bus_space_copy_region_1.9 \
+ bus_space.9 bus_space_copy_region_2.9 \
+ bus_space.9 bus_space_copy_region_4.9 \
+ bus_space.9 bus_space_copy_region_8.9 \
+ bus_space.9 bus_space_free.9 bus_space.9 bus_space_map.9 \
+ bus_space.9 bus_space_read_1.9 bus_space.9 bus_space_read_2.9 \
+ bus_space.9 bus_space_read_4.9 bus_space.9 bus_space_read_8.9 \
+ bus_space.9 bus_space_read_multi_1.9 \
+ bus_space.9 bus_space_read_multi_2.9 \
+ bus_space.9 bus_space_read_multi_4.9 \
+ bus_space.9 bus_space_read_multi_8.9 \
+ bus_space.9 bus_space_read_region_1.9 \
+ bus_space.9 bus_space_read_region_2.9 \
+ bus_space.9 bus_space_read_region_4.9 \
+ bus_space.9 bus_space_read_region_8.9 \
+ bus_space.9 bus_space_set_region_1.9 \
+ bus_space.9 bus_space_set_region_2.9 \
+ bus_space.9 bus_space_set_region_4.9 \
+ bus_space.9 bus_space_set_region_8.9 \
+ bus_space.9 bus_space_subregion.9 bus_space.9 bus_space_unmap.9 \
+ bus_space.9 bus_space_write_1.9 bus_space.9 bus_space_write_2.9 \
+ bus_space.9 bus_space_write_4.9 bus_space.9 bus_space_write_8.9 \
+ bus_space.9 bus_space_write_multi_1.9 \
+ bus_space.9 bus_space_write_multi_2.9 \
+ bus_space.9 bus_space_write_multi_4.9 \
+ bus_space.9 bus_space_write_multi_8.9 \
+ bus_space.9 bus_space_write_region_1.9 \
+ bus_space.9 bus_space_write_region_2.9 \
+ bus_space.9 bus_space_write_region_4.9 \
+ bus_space.9 bus_space_write_region_8.9
+MLINKS+=bus_dma.9 bus_dmamap_create.9 bus_dma.9 bus_dmamap_destroy.9 \
+ bus_dma.9 bus_dmamap_load.9 bus_dma.9 bus_dmamap_load_mbuf.9 \
+ bus_dma.9 bus_dmamap_load_uio.9 bus_dma.9 bus_dmamap_load_raw.9 \
+ bus_dma.9 bus_dmamap_unload.9 bus_dma.9 bus_dmamap_sync.9 \
+ bus_dma.9 bus_dmamem_alloc.9 bus_dma.9 bus_dmamem_free.9 \
+ bus_dma.9 bus_dmamem_map.9 bus_dma.9 bus_dmamem_unmap.9 \
+ bus_dma.9 bus_dmamem_mmap.9
+
MLINKS+=copy.9 copyin.9 copy.9 copyout.9 copy.9 copystr.9 \
copy.9 copyinstr.9 copy.9 copyoutstr.9
-MLINKS+=disk.9 disk_init.9 disk.9 disk_attach.9 disk.9 disk_detatch.9 \
+MLINKS+=ctxsw.9 cpu_switch.9 ctxsw.9 mi_switch.9
+MLINKS+=disk.9 disk_init.9 disk.9 disk_attach.9 disk.9 disk_detach.9 \
disk.9 disk_busy.9 disk.9 disk_unbusy.9 disk.9 disk_find.9 \
disk.9 disk_resetstat.9
+MLINKS+=disklabel.9 readdisklabel.9 disklabel.9 writedisklabel.9 \
+ disklabel.9 setdisklabel.9 disklabel.9 bounds_check_with_label.9
+MLINKS+=ethersubr.9 ether_ifattach.9 ethersubr.9 ether_addmulti.9 \
+ ethersubr.9 ether_delmulti.9 ethersubr.9 ETHER_IS_MULTICAST.9 \
+ ethersubr.9 ETHER_FIRST_MULTI.9 ethersubr.9 ETHER_NEXT_MULTI.9 \
+ ethersubr.9 fddi_ifattach.9 \
+ ethersubr.9 fddi_addmulti.9 ethersubr.9 fddi_delmulti.9
MLINKS+=extent.9 extent_create.9 extent.9 extent_destroy.9 \
extent.9 extent_alloc.9 extent.9 extent_alloc_subregion.9 \
extent.9 extent_alloc_region.9 extent.9 extent_free.9 \
@@ -25,11 +76,25 @@ MLINKS+=fetch.9 fubyte.9 fetch.9 fuibyte.9 fetch.9 fusword.9 \
MLINKS+=kthread.9 kthread_create.9 kthread.9 kthread_exit.9 \
kthread.9 kthread_create_deferred.9
MLINKS+=log.9 addlog.9
+MLINKS+=malloc.9 free.9
+MLINKS+=mbuf.9 m_get.9 mbuf.9 m_getclr.9 mbuf.9 m_gethdr.9 mbuf.9 m_devget.9 \
+ mbuf.9 m_copym.9 mbuf.9 m_copypacket.9 mbuf.9 m_copydata.9 \
+ mbuf.9 m_copyback.9 mbuf.9 m_cat.9 mbuf.9 m_prepend.9 \
+ mbuf.9 m_pullup.9 mbuf.9 m_split.9 mbuf.9 m_adj.9 mbuf.9 m_free.9 \
+ mbuf.9 m_freem.9 mbuf.9 mtod.9 mbuf.9 mtocl.9 mbuf.9 cltom.9 \
+ mbuf.9 MGET.9 mbuf.9 MGETHDR.9 mbuf.9 MEXTMALLOC.9 \
+ mbuf.9 MEXTADD.9 mbuf.9 MCLGET.9 mbuf.9 M_COPY_PKTHDR.9 \
+ mbuf.9 M_ALIGN.9 mbuf.9 MH_ALIGN.9 mbuf.9 M_LEADINGSPACE.9 \
+ mbuf.9 M_TRAILINGSPACE.9 mbuf.9 M_PREPEND.9 mbuf.9 MCHTYPE.9 \
+ mbuf.9 MEXTREMOVE.9 mbuf.9 MFREE.9
MLINKS+=md5.9 MD5Init.9 md5.9 MD5Transform.9
MLINKS+=pfind.9 pgfind.9
MLINKS+=printf.9 sprintf.9 printf.9 vprintf.9 printf.9 uprintf.9 \
printf.9 ttyprintf.9 printf.9 db_printf.9
MLINKS+=psignal.9 pgsignal.9 psignal.9 gsignal.9
+MLINKS+=pool.9 pool_create.9 pool.9 pool_destroy.9 pool.9 pool_get.9 \
+ pool.9 pool_put.9 pool.9 pool_prime.9 pool.9 pool_sethiwat.9 \
+ pool.9 pool_setlowat.9
MLINKS+=shutdownhook_establish.9 shutdownhook_disestablish.9
MLINKS+=sleep.9 tsleep.9 sleep.9 wakeup.9
MLINKS+=spl.9 spl0.9 spl.9 splbio.9 spl.9 splclock.9 spl.9 splhigh.9 \
@@ -43,5 +108,27 @@ MLINKS+=timeout.9 untimeout.9
MLINKS+=vm_map_copy.9 vm_copy.9
MLINKS+=vm_map_inherit.9 vm_inherit.9
MLINKS+=vm_map_protect.9 vm_protect.9
+MLINKS+=uvm.9 uvm_init.9 uvm.9 uvm_init_limits.9 uvm.9 uvm_setpagesize.9 \
+ uvm.9 uvm_swap_init.9 uvm.9 uvm_map.9 uvm.9 uvm_map_pageable.9 \
+ uvm.9 uvm_map_checkprot.9 uvm.9 uvm_map_protect.9 \
+ uvm.9 uvm_deallocate.9 uvm.9 uvmspace_alloc.9 uvm.9 uvmspace_exec.9 \
+ uvm.9 uvmspace_fork.9 uvm.9 uvmspace_free.9 uvm.9 uvmspace_share.9 \
+ uvm.9 uvmspace_unshare.9 uvm.9 uvm_fault.9 uvm.9 uvn_attach.9 \
+ uvm.9 uvm_vnp_setsize.9 uvm.9 uvm_vnp_sync.9 uvm.9 uvm_vnp_terminate.9 \
+ uvm.9 uvm_io.9 uvm.9 uvm_km_alloc.9 uvm.9 uvm_km_zalloc.9 \
+ uvm.9 uvm_km_alloc1.9 uvm.9 uvm_km_kmemalloc.9 uvm.9 uvm_km_valloc.9 \
+ uvm.9 uvm_km_valloc_wait.9 uvm.9 uvm_km_suballoc.9 uvm.9 uvm_km_free.9 \
+ uvm.9 uvm_km_free_wakeup.9 uvm.9 uvm_pagealloc.9 \
+ uvm.9 uvm_pagerealloc.9 uvm.9 uvm_pagefree.9 uvm.9 uvm_pglistalloc.9 \
+ uvm.9 uvm_pglistfree.9 uvm.9 uvm_page_physload.9 uvm.9 uvm_pageout.9 \
+ uvm.9 uvm_scheduler.9 uvm.9 uvm_swapin.9 uvm.9 uao_create.9 \
+ uvm.9 uao_detach.9 uvm.9 uao_reference.9 uvm.9 uvm_chgkprot.9 \
+ uvm.9 uvm_kernacc.9 uvm.9 uvm_useracc.9 uvm.9 uvm_vslock.9 \
+ uvm.9 uvm_vsunlock.9 uvm.9 uvm_meter.9 uvm.9 uvm_sysctl.9 \
+ uvm.9 uvm_fork.9 uvm.9 uvm_grow.9 uvm.9 uvm_coredump.9
+MLINKS+=vslock.9 vsunlock.9
+
+SUBDIR= man9.i386
.include <bsd.prog.mk>
+.include <bsd.subdir.mk>
diff --git a/share/man/man9/access.9 b/share/man/man9/access.9
new file mode 100644
index 00000000000..bd4c585e673
--- /dev/null
+++ b/share/man/man9/access.9
@@ -0,0 +1,84 @@
+.\" $OpenBSD: access.9,v 1.1 1999/09/22 03:16:47 csapuntz Exp $
+.\" $NetBSD: access.9,v 1.7 1999/03/16 00:40:46 garbled Exp $
+.\"
+.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Paul Kranenburg.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd June 16, 1996
+.Dt ACCESS 9
+.Os
+.Sh NAME
+.Nm access ,
+.Nm kernacc ,
+.Nm useracc
+.Nd check memory regions for accessability
+.Sh SYNOPSIS
+.Ft int
+.Fn kernacc "caddr_t addr" "size_t len" "int rw"
+.Ft int
+.Fn useracc "caddr_t addr" "size_t len" "int rw"
+.Sh DESCRIPTION
+The
+.Fn kernacc
+and
+.Fn useracc
+functions check whether operations of the type specified in
+.Fa rw
+are permitted in the range of virtual addresses given by
+.Fa addr
+and
+.Fa len .
+The possible values of
+.Fa rw
+are
+.Dv B_READ
+and
+.Dv B_WRITE .
+.Fn kernacc
+checks addresses in the kernel address space, while
+.Fn useracc
+considers
+.Fa addr
+to represent an user space address.
+The process context to use for this operation is taken from the global variable
+.Va curproc .
+.Pp
+.Sh RETURN VALUES
+Both functions return 1 if the type of access specified by
+.Fa rw
+is permitted.
+Otherwise 0 is returned.
+.Pp
+.Sh BUGS
+The process pointer should be passed in as an argument.
diff --git a/share/man/man9/arp.9 b/share/man/man9/arp.9
new file mode 100644
index 00000000000..8076c0126a5
--- /dev/null
+++ b/share/man/man9/arp.9
@@ -0,0 +1,146 @@
+.\" $OpenBSD: arp.9,v 1.1 1999/09/22 03:16:47 csapuntz Exp $
+.\" $NetBSD: arp.9,v 1.16 1999/03/16 00:40:47 garbled Exp $
+.\"
+.\" Copyright (c) 1997 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Ignatios Souvatzis.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\"
+.Dd March 3, 1997
+.Dt ARP 9
+.Os
+.Sh NAME
+.Nm arp ,
+.Nm arp_ifinit ,
+.Nm arpresolve ,
+.Nm arpintr
+.Nd externally visible ARP functions
+.Sh SYNOPSIS
+.Fd #include <netinet/if_inarp.h>
+.Ft void
+.Fn arp_ifinit "struct ifnet *ifp" "struct ifaddr *ifa"
+.Ft int
+.Fn arpresolve "struct ifnet *ifp" "struct rtentry *rt" "struct mbuf *m" "struct sockaddr *dst" "u_char *desten"
+.Ft void
+.Fn arpintr
+.Sh DESCRIPTION
+The
+.Nm
+functions provide the interface between the
+.Nm
+module and the network drivers which need
+.Nm
+functionality.
+Such drivers must request the
+.Ar arp
+attribute in their "files" declaration.
+.Bl -tag -width "arp_ifinit()"
+.It Fn arp_ifinit
+Sets up the
+.Nm
+specific fields in
+.Fa ifa .
+Additionally, it sends out a gratitious
+.Nm
+request on
+.Fa ifp ,
+so that other machines are warned that we have a (new) address and
+duplicate addresses can be detected.
+.Pp
+You must call this in your drivers' ioctl function when you get a
+SIOCSIFADDR request with an AF_INET address family.
+.It Fn arpresolve
+is called by network output functions to resolve an IPv4 address.
+If no
+.Fa rt
+is given, a new one is looked up or created.
+If the passed or found
+.Fa rt
+does not contain a valid gateway link level address, a pointer to the packet
+in
+.Fa m
+is stored in the route entry, possibly replacing older stored packets, and an
+.Nm
+request is sent instead.
+When an
+.Nm
+reply is received, the last held packet is send.
+Otherwise, the looked up address is returned and written into the storage
+.Fa desten
+points to.
+.Fn arpresolve
+returns 1, if a valid address was stored to
+.Fa desten ,
+and the packet can be sent immediately.
+Else a 0 is returned.
+.It Fn arpintr
+When an
+.Nm
+packet is received, the network driver (class) input interupt handler queues
+the packet on the arpintrq queue, and requests an
+.Fn arpintr
+soft interupt callback.
+.Fn arpintr
+dequeues the packets, performs sanity checks and calls (for IPv4
+.Nm
+packes, which are the only ones supported currently) the
+.Fn in_arpinput
+function.
+.Fn in_arpinput
+either generates a reply to request packets, and adds the sender address
+translation to to the routing table, if a matching route entry is found.
+If the route entry contained a pointer to a held packet, that packet is
+sent.
+.El
+.Sh SEE ALSO
+.Xr ifattach 9 ,
+.Xr ether_ifattach 9 ,
+.Xr fddi_ifattach 9 ,
+.Xr arc_ifattach 9
+.br
+Plummer, D., "RFC826", An Ethernet Address Resolution Protocol.
+.Sh AUTHORS
+UCB CSRG (original implementation)
+.br
+Ignatios Souvatzis (support for non-Ethernet)
+.Sh CODE REFERENCES
+The ARP code is implemented in
+.Pa sys/net/if_arp.h ,
+.Pa sys/netinet/if_inarp.h
+and
+.Pa sys/netinet/if_arp.c .
+.Sh STANDARDS
+RFC 826
+.Sh HISTORY
+Rewritten to support other than Ethernet link level addresses in
+.Nx 1.3 .
diff --git a/share/man/man9/audio.9 b/share/man/man9/audio.9
new file mode 100644
index 00000000000..95927927756
--- /dev/null
+++ b/share/man/man9/audio.9
@@ -0,0 +1,420 @@
+.\" $OpenBSD: audio.9,v 1.1 1999/09/22 03:16:47 csapuntz Exp $
+.\" $NetBSD: audio.9,v 1.13 1999/06/16 14:19:27 kleink Exp $
+.\"
+.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Lennart Augustsson.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd October 19, 1997
+.Dt AUDIO 9
+.Os
+.Sh NAME
+.Nm audio
+.Nd interface between low and high level audio drivers
+.Sh DESCRIPTION
+The audio device driver is divided into a high level,
+hardware independent layer, and a low level hardware
+dependent layer. The interface between these is
+the
+.Va audio_hw_if
+structure.
+.Bd -literal
+struct audio_hw_if {
+ int (*open)__P((void *, int));
+ void (*close)__P((void *));
+ int (*drain)__P((void *));
+
+ int (*query_encoding)__P((void *, struct audio_encoding *));
+ int (*set_params)__P((void *, int, int,
+ struct audio_params *, struct audio_params *));
+ int (*round_blocksize)__P((void *, int));
+
+ int (*commit_settings)__P((void *));
+
+ int (*init_output)__P((void *, void *, int));
+ int (*init_input)__P((void *, void *, int));
+ int (*start_output)__P((void *, void *, int,
+ void (*)(void *), void *));
+ int (*start_input)__P((void *, void *, int,
+ void (*)(void *), void *));
+ int (*halt_output)__P((void *));
+ int (*halt_input)__P((void *));
+
+ int (*speaker_ctl)__P((void *, int));
+#define SPKR_ON 1
+#define SPKR_OFF 0
+
+ int (*getdev)__P((void *, struct audio_device *));
+ int (*setfd)__P((void *, int));
+
+ int (*set_port)__P((void *, mixer_ctrl_t *));
+ int (*get_port)__P((void *, mixer_ctrl_t *));
+
+ int (*query_devinfo)__P((void *, mixer_devinfo_t *));
+
+ void *(*allocm)__P((void *, int, size_t, int, int));
+ void (*freem)__P((void *, void *, int));
+ size_t (*round_buffersize)__P((void *, int, size_t));
+ int (*mappage)__P((void *, void *, int, int));
+
+ int (*get_props)__P((void *));
+};
+
+struct audio_params {
+ u_long sample_rate; /* sample rate */
+ u_int encoding; /* ulaw, linear, etc */
+ u_int precision; /* bits/sample */
+ u_int channels; /* mono(1), stereo(2) */
+ /* Software en/decode functions, set if SW coding required by HW */
+ void (*sw_code)__P((void *, u_char *, int));
+ int factor; /* coding space change */
+};
+.Ed
+.Pp
+The high level audio driver attaches to the low level driver
+when the latter calls
+.Va audio_attach_mi .
+This call should be
+.Bd -literal
+ void
+ audio_attach_mi(ahwp, mhwp, hdl, dev)
+ struct audio_hw_if *ahwp;
+ struct midi_hw_if *mhwp;
+ void *hdl;
+ struct device *dev;
+.Ed
+.Pp
+The
+.Va audio_hw_if
+struct is as shown above and the
+.Va midi_hw_if
+is unused (at the moment). The
+.Va hdl
+argument is a handle to some low level data structure.
+It is sent as the first argument to all the functions
+in
+.Va audio_hw_if
+when the high level driver calls them.
+.Va dev
+is the device struct for the hardware device.
+.Pp
+The upper layer of the audio driver allocates one buffer for playing
+and one for recording. It handles the buffering of data from the
+user processes in these. The data is presented to the lower level
+in smaller chunks, called blocks. If there, during playback, is
+no data available from the user process when the hardware request
+another block a block of silence will be used instead. Furthermore,
+if the user process does not read data quickly enough during recording
+data will be thrown away.
+.Pp
+The fields of
+.Va audio_hw_if
+are described in some more detail below.
+Some fields are optional and can be set to 0 if not needed.
+.Bl -tag -width indent
+.It Dv int open(void *hdl, int flags)
+is called when the audio device is opened. It should initialize
+the hardware for I/O. Every successful call to
+.Va open
+is matched by a call to
+.Va close .
+Return 0 on success, otherwise an error code.
+.It Dv void close(void *hdl)
+is called when the audio device is closed.
+.It Dv int drain(void *hdl)
+optional, is called before the device is closed or when
+.Dv AUDIO_DRAIN
+is called. It should make sure that no samples remain
+in to be played that could be lost when
+.Va close
+is called.
+Return 0 on success, otherwise an error code.
+.It Dv int query_encoding(void *hdl, struct audio_encoding *ae)
+is used when
+.Dv AUDIO_GETENC
+is called. It should fill the
+.Va audio_encoding
+structure and return 0 or, if there is no encoding with the
+given number, return EINVAL.
+.It Dv int set_params(void *hdl, int setmode, int usemode,
+.Dv "struct audio_params *play, struct audio_params *rec)"
+.br
+Called to set the audio encoding mode.
+.Va setmode
+is a combination of the
+.Dv AUMODE_RECORD
+and
+.Dv AUMODE_PLAY
+flags to indicate which mode(s) are to be set.
+.Va usemode
+is also a combination of these flags, but indicates the current
+mode of the device (i.e. the value of
+.Va mode
+in the
+.Va audio_info
+struct).
+The
+.Va play
+and
+.Va rec
+structures contain the encoding parameters that should be set.
+If the hardware requires software assistance with some encoding
+(e.g., it might be lacking mulaw support) it should fill the
+.Va sw_code
+and
+.Va factor
+fields of these structures.
+The values of the structures may also be modified if the hardware
+cannot be set to exactly the requested mode (e.g. if the requested
+sampling rate is not supported, but one close enough is).
+If the device does not have the
+.Dv AUDIO_PROP_INDEPENDENT
+property the same value is passed in both
+.Va play
+and
+.Va rec
+and the encoding parameters from
+.Va play
+is copied into
+.Va rec
+after the call to
+.Va set_params .
+Return 0 on success, otherwise an error code.
+.It Dv int round_blocksize(void *hdl, int bs)
+optional, is called with the block size,
+.Va bs ,
+that has been computed by the upper layer. It should return
+a block size, possibly changed according to the needs of the
+hardware driver.
+.It Dv int commit_settings(void *hdl)
+optional, is called after all calls to
+.Va set_params ,
+and
+.Va set_port ,
+are done. A hardware driver that needs to get the hardware in
+and out of command mode for each change can save all the changes
+during previous calls and do them all here.
+Return 0 on success, otherwise an error code.
+.It Dv int init_output(void *hdl, void *buffer, int size)
+optional, is called before any output starts, but when the total
+.Va size
+of the output
+.Va buffer
+has been determined. It can be used to initialize looping DMA
+for hardware that needs that.
+Return 0 on success, otherwise an error code.
+.It Dv int init_input(void *hdl, void *buffer, int size)
+optional, is called before any input starts, but when the total
+.Va size
+of the input
+.Va buffer
+has been determined. It can be used to initialize looping DMA
+for hardware that needs that.
+Return 0 on success, otherwise an error code.
+.It Dv int start_output(void *hdl, void *block, int bsize,
+.Dv "void (*intr)(void*), void *intrarg)"
+.br
+is called to start the transfer of
+.Va bsize
+bytes from
+.Va block
+to the audio hardware. The call should return when the data
+transfer has been initiated (normally with DMA). When the
+hardware is ready to accept more samples the function
+.Va intr
+should be called with the argument
+.Va intrarg .
+Calling
+.Va intr
+will normally initiate another call to
+.Va start_output .
+Return 0 on success, otherwise an error code.
+.It Dv int start_input(void *hdl, void *block, int bsize,
+.Dv "void (*intr)(void*), void *intrarg)"
+.br
+is called to start the transfer of
+.Va bsize
+bytes to
+.Va block
+from the audio hardware. The call should return when the data
+transfer has been initiated (normally with DMA). When the
+hardware is ready to deliver more samples the function
+.Va intr
+should be called with the argument
+.Va intrarg .
+Calling
+.Va intr
+will normally initiate another call to
+.Va start_input.
+Return 0 on success, otherwise an error code.
+.It Dv int halt_output(void *hdl)
+is called to abort the output transfer (started by
+.Va start_output )
+in progress.
+Return 0 on success, otherwise an error code.
+.It Dv int halt_input(void *hdl)
+is called to abort the input transfer (started by
+.Va start_input )
+in progress.
+Return 0 on success, otherwise an error code.
+.It Dv int speaker_ctl(void *hdl, int on)
+optional, is called when a half duplex device changes between
+playing and recording. It can, e.g., be used to turn on
+and off the speaker.
+Return 0 on success, otherwise an error code.
+.It Dv int getdev(void *hdl, struct audio_device *ret)
+Should fill the
+.Va audio_device
+struct with relevant information about the driver.
+Return 0 on success, otherwise an error code.
+.It Dv int setfd(void *hdl, int fd)
+optional, is called when
+.Dv AUDIO_SETFD
+is used, but only if the device has AUDIO_PROP_FULLDUPLEX set.
+Return 0 on success, otherwise an error code.
+.It Dv int set_port(void *hdl, mixer_ctl_t *mc)
+is called in when
+.Dv AUDIO_MIXER_WRITE
+is used. It should take data from the
+.Va mixer_ctl_t
+struct at set the corresponding mixer values.
+Return 0 on success, otherwise an error code.
+.It Dv int get_port(void *hdl, mixer_ctl_t *mc)
+is called in when
+.Dv AUDIO_MIXER_READ
+is used. It should fill the
+.Va mixer_ctl_t
+struct.
+Return 0 on success, otherwise an error code.
+.It Dv int query_devinfo(void *hdl, mixer_devinfo_t *di)
+is called in when
+.Dv AUDIO_MIXER_DEVINFO
+is used. It should fill the
+.Va mixer_devinfo_t
+struct.
+Return 0 on success, otherwise an error code.
+.It Dv "void *allocm(void *hdl, int direction, size_t size, int type, int flags)"
+.br
+optional, is called to allocate the device buffers. If not present
+.Xr malloc 9
+is used instead (with the same arguments but the first two).
+The reason for using a device dependent routine instead of
+.Xr malloc 9
+is that some buses need special allocation to do DMA.
+Returns the address of the buffer, or 0 on failure.
+.It Dv void freem(void *hdl, void *addr, int type)
+optional, is called to free memory allocated by
+.Va alloc .
+If not supplied
+.Xr free 9
+is used.
+.It Dv size_t round_buffersize(void *hdl, int direction, size_t bufsize)
+optional, is called at startup to determine the audio
+buffer size. The upper layer supplies the suggested
+size in
+.Va bufsize ,
+which the hardware driver can then change if needed.
+E.g., DMA on the ISA bus cannot exceed 65536 bytes.
+.It Dv "int mappage(void *hdl, void *addr, int offs, int prot)"
+.br
+optional, is called for
+.Xr mmap 2 .
+Should return the map value for the page at offset
+.Va offs
+from address
+.Va addr
+mapped with protection
+.Va prot .
+Returns -1 on failure, or a machine dependent opaque value
+on success.
+.It Dv int get_props(void *hdl)
+Should return the device properties; i.e. a combination of
+AUDIO_PROP_xxx.
+.El
+.Pp
+The
+.Va query_devinfo
+method should define certain mixer controls for
+.Dv AUDIO_SETINFO
+to be able to change the port and gain.
+.Pp
+If the audio hardware is capable of input from more
+than one source it should define
+.Dv AudioNsource
+in class
+.Dv AudioCrecord .
+This mixer control should be of type
+.Dv AUDIO_MIXER_ENUM
+or
+.Dv AUDIO_MIXER_SET
+and enumerate the possible input sources.
+For each of the named sources there should be
+a control in the
+.Dv AudioCinputs
+class of type
+.Dv AUDIO_MIXER_VALUE
+if recording level of the source can be set.
+If the overall recording level can be changed (i.e. regardless
+of the input source) then this control should be named
+.Dv AudioNrecord
+and be of class
+.Dv AudioCinputs .
+.Pp
+If the audio hardware is capable of output to more than
+one destination it should define
+.Dv AudioNoutput
+in class
+.Dv AudioCmonitor .
+This mixer control should be of type
+.Dv AUDIO_MIXER_ENUM
+or
+.Dv AUDIO_MIXER_SET
+and enumerate the possible destinations.
+For each of the named destinations there should be
+a control in the
+.Dv AudioCoutputs
+class of type
+.Dv AUDIO_MIXER_VALUE
+if output level of the destination can be set.
+If the overall output level can be changed (i.e. regardless
+of the destination) then this control should be named
+.Dv AudioNmaster
+and be of class
+.Dv AudioCoutputs .
+.Sh SEE ALSO
+.Xr audio 4
+.Sh HISTORY
+This
+.Nm
+interface first appeared in
+.Nx 1.3 .
diff --git a/share/man/man9/bus_dma.9 b/share/man/man9/bus_dma.9
new file mode 100644
index 00000000000..77f53340090
--- /dev/null
+++ b/share/man/man9/bus_dma.9
@@ -0,0 +1,673 @@
+.\" $OpenBSD: bus_dma.9,v 1.1 1999/09/22 03:16:47 csapuntz Exp $
+.\" $NetBSD: bus_dma.9,v 1.11 1999/03/16 00:40:47 garbled Exp $
+.\"
+.\" Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+.\" NASA Ames Research Center.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgment:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd February 3, 1998
+.Dt BUS_DMA 9
+.Os
+.Sh NAME
+.Nm bus_dma ,
+.Nm bus_dmamap_create ,
+.Nm bus_dmamap_destroy ,
+.Nm bus_dmamap_load ,
+.Nm bus_dmamap_load_mbuf ,
+.Nm bus_dmamap_load_uio ,
+.Nm bus_dmamap_load_raw ,
+.Nm bus_dmamap_unload ,
+.Nm bus_dmamap_sync ,
+.Nm bus_dmamem_alloc ,
+.Nm bus_dmamem_free ,
+.Nm bus_dmamem_map ,
+.Nm bus_dmamem_unmap ,
+.Nm bus_dmamem_mmap
+.Nd Bus and Machine Independent DMA Mapping Interface
+.Sh SYNOPSIS
+.Fd #include <machine/bus.h>
+.Ft int
+.Fn bus_dmamap_create "bus_dma_tag_t tag" "bus_size_t size" "int nsegments" \
+"bus_size_t maxsegsz" "bus_size_t boundary" "int flags" "bus_dmamap_t *dmamp"
+.Ft void
+.Fn bus_dmamap_destroy "bus_dma_tag_t tag" "bus_dmamap_t dmam"
+.Ft int
+.Fn bus_dmamap_load "bus_dma_tag_t tag" "bus_dmamap_t dmam" "void *buf" \
+"bus_size_t buflen" "struct proc *p" "int flags"
+.Ft int
+.Fn bus_dmamap_load_mbuf "bus_dma_tag_t tag" "bus_dmamap_t dmam" \
+"struct mbuf *chain" "int flags"
+.Ft int
+.Fn bus_dmamap_load_uio "bus_dma_tag_t tag" "bus_dmamap_t dmam" \
+"struct uio *uio" "int flags"
+.Ft int
+.Fn bus_dmamap_load_raw "bus_dma_tag_t tag" "bus_dmamap_t dmam" \
+"bus_dma_segment_t *segs" "int nsegs" "bus_size_t size" "int flags"
+.Ft void
+.Fn bus_dmamap_unload "bus_dma_tag_t tag" "bus_dmamap_t dmam"
+.Ft void
+.Fn bus_dmamap_sync "bus_dma_tag_t tag" "bus_dmamap_t dmam" \
+"bus_addr_t offset" "bus_size_t len" "int ops"
+.Ft int
+.Fn bus_dmamem_alloc "bus_dma_tag_t tag" "bus_size_t size" \
+"bus_size_t alignment" "bus_size_t boundary" "bus_dma_segment_t *segs" \
+"int nsegs" "int *rsegs" "int flags"
+.Ft void
+.Fn bus_dmamem_free "bus_dma_tag_t tag" "bus_dma_segment_t *segs" "int nsegs"
+.Ft int
+.Fn bus_dmamem_map "bus_dma_tag_t tag" "bus_dma_segment_t *segs" "int nsegs" \
+"size_t size" "caddr_t *kvap" "int flags"
+.Ft void
+.Fn bus_dmamem_unmap "bus_dma_tag_t tag" "caddr_t kva" "size_t size"
+.Ft int
+.Fn bus_dmamem_mmap "bus_dma_tag_t tag" "bus_dma_segment_t *segs" \
+"int nsegs" "int off" "int prot" "int flags"
+.Sh DESCRIPTION
+Provide a bus- and machine-independent "DMA mapping interface."
+.Sh NOTES
+.Pp
+All data structures, function prototypes, and macros will be defined
+by the port-specific header
+.Pa Aq machine/bus.h .
+Note that this document
+assumes the existence of types already defined by the current "bus.h"
+interface.
+.Pp
+Unless otherwise noted, all function calls in this interface may be
+defined as
+.Xr cpp 1
+macros.
+.Sh DATA TYPES
+.Pp
+Individual implementations may name these structures whatever they
+wish, providing that the external representations are:
+.Bl -tag -width compact
+.It Fa bus_dma_tag_t
+A machine-dependent opaque type describing the implementation of
+DMA for a given bus.
+.It Fa bus_dma_segment_t
+A structure with at least the following members:
+.Bd -literal
+ bus_addr_t ds_addr;
+ bus_size_t ds_len;
+.Ed
+.sp
+The structure may have machine-dependent members and arbitrary layout.
+The values in
+.Fa ds_addr
+and
+.Fa ds_len
+are suitable for programming into
+DMA controller address and length registers.
+.It Fa bus_dmamap_t
+A pointer to a structure with at least the following members:
+.Bd -literal
+ bus_size_t dm_mapsize;
+ int dm_nsegs;
+ bus_dma_segment_t *dm_segs;
+.Ed
+.sp
+The structure may have machine-dependent members and arbitrary layout.
+The
+.Fa dm_mapsize
+member indicates the size of the mapping. A value of 0 indicates the
+mapping is invalid.
+The
+.Fa dm_segs
+member may be an array of segments or a pointer to an
+array of segments. The
+.Fa dm_nsegs
+member indicates the number of segments in
+.Fa dm_segs .
+.El
+.Sh FUNCTIONS
+.Bl -tag -width compact
+.It Fn bus_dmamap_create "tag" "size" "nsegments" "maxsegsz" "boundary" "flags" "dmamp"
+Allocates a DMA handle and initializes it according to the parameters
+provided.
+Arguments are as follows:
+.Bl -tag -width nsegments -compact
+.It Fa tag
+This is the bus_dma_tag_t passed down from the parent driver via
+.Fa <bus>_attach_args .
+.It Fa size
+This is the maximum DMA transfer that can be mapped by the handle.
+.It Fa nsegments
+Number of segments the device can support in a single DMA transaction.
+This may be the number of scatter-gather descriptors supported by the
+device.
+.It Fa maxsegsz
+The maximum number of bytes that may be transferred by any given DMA
+segment.
+.It Fa boundary
+Some DMA controllers are not able to transfer data that crosses a
+particular boundary. This argument allows this boundary to be
+specified. The boundary lines begin at 0, and occur every
+.Fa boundary
+bytes. Mappings may begin on a boundary line but may not end on or
+cross a boundary line. If no boundary condition needs to be observed, a
+.Fa boundary
+argument of 0 should be used.
+.It Fa flags
+Flags are defined as follows:
+.Bl -tag -width BUS_DMA_ALLOCNOW -compact
+.It Dv BUS_DMA_WAITOK
+It is safe to wait (sleep) for resources during this call.
+.It Dv BUS_DMA_NOWAIT
+It is not safe to wait (sleep) for resources during this call.
+.It Dv BUS_DMA_ALLOCNOW
+Perform any resource allocation this handle may need now. If this is
+not specified, the allocation may be deferred to
+.Fn bus_dmamap_load .
+If this flag is specified,
+.Fn bus_dmamap_load
+will not block on resource
+allocation.
+.It Dv BUS_DMA_BUS[1-4]
+These flags are placeholders, and may be used by busses to provide
+bus-dependent functionality.
+.El
+.It Fa dmamp
+This is a pointer to a bus_dmamap_t. A DMA map will be allocated and
+pointed to by
+.Fa dmamp
+upon successful completion of this routine.
+.El
+.Pp
+Behavior is not defined if invalid arguments are passed to
+.Fn bus_dmamap_create .
+.Pp
+Returns 0 on success, or an error code to indicate mode of failure.
+.It Fn bus_dmamap_destroy "tag" "dmam"
+Frees all resources associated with a given DMA handle. Arguments are
+as follows:
+.Bl -tag -width dmam -compact
+.It Fa tag
+This is the bus_dma_tag_t passed down from the parent driver via
+.Fa <bus>_attach_args .
+.It Fa dmam
+The DMA handle to destroy.
+.El
+.Pp
+In the event that the DMA handle contains a valid mapping,
+the mapping will be unloaded via the same mechanism used by
+.Fn bus_dmamap_unload .
+.Pp
+Behavior is not defined if invalid arguments are passed to
+.Fn bus_dmamap_destroy .
+.Pp
+If given valid arguments,
+.Fn bus_dmamap_destroy
+always succeeds.
+.It Fn bus_dmamap_load "tag" "dmam" "buf" "buflen" "p" "flags"
+Loads a DMA handle with mappings for a DMA transfer. It assumes that
+all pages involved in a DMA transfer are wired.
+Arguments are as follows:
+.Bl -tag -width buflen -compact
+.It Fa tag
+This is the bus_dma_tag_t passed down from the parent driver via
+.Fa <bus>_attach_args .
+.It Fa dmam
+The DMA handle with which to map the transfer.
+.It Fa buf
+The buffer to be used for the DMA transfer.
+.It Fa buflen
+The size of the buffer.
+.It Fa p
+Used to indicate the address space in which the buffer is located. If
+.Dv NULL ,
+the buffer is assumed to be in kernel space. Otherwise, the
+buffer is assumed to be in process
+.Fa p Ns 's
+address space.
+.It Fa flags
+are defined as follows:
+.Bl -tag -width "BUS_DMA_BUS[1-4]" -compact
+.It Dv BUS_DMA_WAITOK
+It is safe to wait (sleep) for resources during this call.
+.It Dv BUS_DMA_NOWAIT
+It is not safe to wait (sleep) for resources during this call.
+.It Dv BUS_DMA_BUS[1-4]
+These flags are placeholders, and may be used by busses to
+provide bus-dependent functionality.
+.El
+.El
+.Pp
+As noted above, if a DMA handle is created with
+.Dv BUS_DMA_ALLOCNOW ,
+.Fn bus_dmamap_load
+will never block.
+.Pp
+If a call to
+.Fn bus_dmamap_load
+fails, the mapping in
+the DMA handle will be invalid. It is the responsibility
+of the caller to clean up any inconsistent device state
+resulting from incomplete iteration through the uio.
+.Pp
+Behavior is not defined if invalid arguments are passed to
+.Fn bus_dmamap_load .
+.Pp
+Returns 0 on success, or an error code to indicate mode of failure.
+.It Fn bus_dmamap_load_mbuf "tag" "dmam" "chain" "flags"
+This is a variation of
+.Fn bus_dmamap_load
+which maps mbuf chains
+for DMA transfers. Mbuf chains are assumed to be in kernel
+virtual address space.
+.It Fn bus_dmamap_load_uio "tag" "dmam" "uio" "flags"
+This is a variation of
+.Fn bus_dmamap_load
+which maps buffers pointed to by
+.Fa uio
+for DMA transfers. The value of
+.Fa "uio->uio_segflg"
+will
+determine if the buffers are in user or kernel virtual address space.
+If the buffers are in user address space, the buffers are assumed to be
+in
+.Fa "uio->uio_procp" Ns 's
+address space.
+.It Fn bus_dmamap_load_raw "tag" "dmam" "segs" "nsegs" "size" "flags"
+This is a variation of
+.Fn bus_dmamap_load
+which maps buffers
+allocated by
+.Fn bus_dmamem_alloc
+(see below). The
+.Fa segs
+argument is an array of bus_dma_segment_t's filled in
+by
+.Fn bus_dmamem_alloc .
+The
+.Fa nsegs
+argument is the number of segments in the array. The
+.Fa size
+argument is the size of the DMA transfer.
+.It Fn bus_dmamap_unload "tag" "dmam"
+Deletes the mappings for a given DMA handle. Arguments are as follows:
+.Bl -tag -width dmam -compact
+.It Fa tag
+This is the bus_dma_tag_t passed down from the parent driver via
+.Fa <bus>_attach_args .
+.It Fa dmam
+The DMA handle containing the mappings which are to be deleted.
+.El
+.Pp
+If the DMA handle was created with
+.Dv BUS_DMA_ALLOCNOW ,
+.Fn bus_dmamap_unload
+will not free the corresponding
+resources which were allocated by
+.Fn bus_dmamap_create .
+This is to ensure that
+.Fn bus_dmamap_load
+will never block
+on resources if the handle was created with
+.Dv BUS_DMA_ALLOCNOW .
+.Pp
+Behavior is not defined if invalid arguments are passed to
+.Fn bus_dmamap_unload .
+.Pp
+If given valid arguments,
+.Fn bus_dmamap_unload
+always succeeds.
+.It Fn bus_dmamap_sync "tag" "dmam" "offset" "len" "ops"
+Performs pre- and post-DMA operation cache and/or buffer synchronization.
+Arguments are as follows:
+.Bl -tag -width offset -compact
+.It Fa tag
+This is the bus_dma_tag_t passed down from the parent driver via
+.Fa <bus>_attach_args .
+.It Fa dmam
+The DMA mapping to be synchronized.
+.It Fa offset
+The offset into the DMA mapping to synchronize.
+.It Fa len
+The length of the mapping from
+.Fa offset
+to synchronize.
+.It Fa ops
+One or more synchronization operation to perform. The following DMA
+synchronization operations are defined:
+.Bl -tag -width BUS_DMASYNC_POSTWRITE -compact
+.It Dv BUS_DMASYNC_PREREAD
+Perform any pre-read DMA cache and/or bounce operations.
+.It Dv BUS_DMASYNC_POSTREAD
+Perform any post-read DMA cache and/or bounce operations.
+.It Dv BUS_DMASYNC_PREWRITE
+Perform any pre-write DMA cache and/or bounce operations.
+.It Dv BUS_DMASYNC_POSTWRITE
+Perform any post-write DMA cache and/or bounce operations.
+.El
+.Pp
+More than one operation may performed in a given synchronization call.
+Mixing of
+.Em PRE
+and
+.Em POST
+operations is not allowed, and behavior is undefined if this is attempted.
+.El
+.Pp
+Synchronization operations are expressed from the perspective of
+the host RAM, e.g. a
+.Em "device -> memory"
+operation is a
+.Em READ
+and a
+.Em "memory -> device"
+operation is a
+.Em WRITE .
+.Pp
+.Fn bus_dmamp_sync
+may consult state kept within the DMA map to determine if the memory
+is mapped in a DMA coherent fashion. If so,
+.Fn bus_dmamap_sync
+may elect to skip certain expensive operations, such as flushing
+of the data cache. See
+.Fn bus_dmamem_map
+for more information on this subject.
+.Pp
+On platforms which implement reordered stores,
+.Fn bus_dmamap_sync
+will always cause the store buffer to be flushed.
+.Pp
+This function exists so that multiple read and write transfers can be
+performed with the same buffer, and so that drivers can explicitly
+inform the
+.Nm
+code when their data is 'ready' in its DMA buffer.
+.Pp
+An example of multiple read-write use of a single mapping
+might look like:
+.Bd -literal
+bus_dmamap_load(...);
+
+while (not done) {
+ /* invalidate soon-to-be-stale cache blocks */
+ bus_dmamap_sync(..., BUS_DMASYNC_PREREAD);
+
+ [ do read DMA ]
+
+ /* copy from bounce */
+ bus_dmamap_sync(..., BUS_DMASYNC_POSTREAD);
+
+ /* read data now in driver-provided buffer */
+
+ [ computation ]
+
+ /* data to be written now in driver-provided buffer */
+
+ /* flush write buffers and writeback, copy to bounce */
+ bus_dmamap_sync(..., BUS_DMASYNC_PREWRITE);
+
+ [ do write DMA ]
+
+ /* probably a no-op, but provided for consistency */
+ bus_dmamap_sync(..., BUS_DMASYNC_POSTWRITE);
+}
+
+bus_dmamap_unload(...);
+.Ed
+.Pp
+If DMA read and write operations are not preceded and followed by the
+appropriate synchronization operations, behavior is undefined.
+.Pp
+Behavior is not defined if invalid arguments are passed to
+.Fn bus_dmamap_sync .
+.Pp
+If given valid arguments,
+.Fn bus_dmamap_sync
+always succeeds.
+.\" XXX: This does not work with all the arguments.
+.It Fn bus_dmamem_alloc "tag" "size" "alignment" "boundary" "segs" "..."
+Allocates memory that is "DMA safe" for the bus corresponding to the
+given tag. The mapping of this memory is machine-dependent (or
+"opaque"); machine-independent code is not to assume that the
+addresses returned are valid in kernel virtual address space, or that
+the addresses returned are system physical addresses.
+.Pp
+Allocations will always be rounded to the hardware page size. Callers
+may wish to take advantage of this, and cluster allocation of small
+data structures.
+Arguments are as follows:
+.Bl -tag -width alignment -compact
+.It Fa tag
+The is the bus_dma_tag_t passed down from the parent driver via
+.Fa <bus>_attach_args .
+.It Fa size
+The amount of memory to allocate.
+.It Fa alignment
+Each segment in the allocated memory will be aligned to this value. If
+the alignment is less than a hardware page size, it will be rounded up
+to the hardware page size. This value must be a power of two.
+.It Fa boundary
+Each segment in the allocated memory must not cross this boundary
+(relative to zero). This value must be a power of two. A boundary
+value less than the size of the allocation is invalid.
+.It Fa segs
+An array of bus_dma_segment_t's, filled in as memory is allocated,
+representing the opaque addresses of the memory chunks.
+.It Fa nsegs
+Specifies the number of segments in
+.Fa segs ,
+and this is the maximum number
+of segments that the allocated memory may contain.
+.It Fa rsegs
+Used to return the actual number of segments the memory contains.
+.It Fa flags
+Flags are defined as follows:
+.Bl -tag -width BUS_DMA_BUS[1-4] -compact
+.It Dv BUS_DMA_WAITOK
+It is safe to wait (sleep) for resources during this call.
+.It Dv BUS_DMA_NOWAIT
+It is not safe to wait (sleep) for resources during this call.
+.It Dv BUS_DMA_BUS[1-4]
+These flags are placeholders, and may be used by busses to provide
+bus-dependent functionality.
+.El
+.El
+.Pp
+All pages allocated by
+.Fn bus_dmamem_alloc
+will be wired down
+until they are freed by
+.Fn bus_dmamem_free .
+.Pp
+Behavior is undefined if invalid arguments are passed to
+.Fn bus_dmamem_alloc .
+.Pp
+Returns 0 on success, or an error code indicating mode of failure.
+.It Fn bus_dmamem_free "tag" "segs" "nsegs"
+Frees memory previously allocated by
+.Fn bus_dmamem_alloc .
+Any mappings
+will be invalidated. Arguments are as follows:
+.Bl -tag -width nsegs -compact
+.It Fa tag
+This is the bus_dma_tag_t passed down from the parent driver via
+.Fa <bus>_attach_args .
+.It Fa segs
+The array of bus_dma_segment_t's filled in by
+.Fn bus_dmamem_alloc .
+.It Fa nsegs
+The number of segments in
+.Fa segs .
+.El
+.Pp
+Behavior is undefined if invalid arguments are passed to
+.Fn bus_dmamem_free .
+.Pp
+If given valid arguments,
+.Fn bus_dmamem_free
+always succeeds.
+.It Fn bus_dmamem_map "tag" "segs" "nsegs" "size" "kvap" "flags"
+Maps memory allocated with
+.Fn bus_dmamem_alloc
+into kernel virtual address space. Arguments are as follows:
+.Bl -tag -width flags -compact
+.It Fa tag
+This is the bus_dma_tag_t passed down from the parent driver via
+.Fa <bus>_attach_args .
+.It Fa segs
+The array of bus_dma_segment_t's filled in by
+.Fn bus_dmamem_alloc ,
+representing the memory regions to map.
+.It Fa nsegs
+The number of segments in
+.Fa segs .
+.It Fa size
+The size of the mapping.
+.It Fa kvap
+Filled in to specify the kernel virtual address where the memory is mapped.
+.It Fa flags
+Flags are defined as follows:
+.Bl -tag -width BUS_DMA_COHERENT -compact
+.It Dv BUS_DMA_WAITOK
+It is safe to wait (sleep) for resources during this call.
+.It Dv BUS_DMA_NOWAIT
+It is not safe to wait (sleep) for resources during this call.
+.It Dv BUS_DMA_BUS[1-4]
+These flags are placeholders, and may be used by busses to provide
+bus-dependent functionality.
+.It Dv BUS_DMA_COHERENT
+This flag is a
+.Em hint
+to machine-dependent code. If possible, map the memory in such a way
+as it will be DMA coherent. This may include mapping the pages into
+uncached address space or setting the cache-inhibit bits in page table
+entries. If implementation of DMA coherent mappings is impossible, this
+is ignored.
+.Pp
+Later, when this memory is loaded into a DMA map, machine-dependent code
+will take whatever steps are necessary to determine if the memory was
+mapped in a DMA coherent fashion. This may include checking if the
+kernel virtual address lies within uncached address space or if the
+cache-inhibit bits are set in page table entries. If it is determined
+that the mapping is DMA coherent, state may be placed into the DMA map
+for use by later calls to
+.Fn bus_dmamap_sync .
+.El
+.El
+.Pp
+Behavior is undefined if invalid arguments are passed to
+.Fn bus_dmamem_map .
+.Pp
+Returns 0 on success, or an error code indicating mode of failure.
+.It Fn bus_dmamem_unmap "tag" "kva" "size"
+Unmaps memory previously mapped with
+.Fn bus_dmamem_map ,
+freeing the
+kernel virtual address space used by the mapping. The arguments are as
+follows:
+.Bl -tag -width size -compact
+.It Fa tag
+This is the bus_dma_tag_t passed down from the parent driver via
+.Fa <bus>_attach_args .
+.It Fa kva
+The kernel virtual address of the mapped memory.
+.It Fa size
+The size of the mapping.
+.El
+.Pp
+Behavior is undefined if invalid arguments are passed to
+.Fn bus_dmamem_unmap .
+.Pp
+If given valid arguments,
+.Fn bus_dmamem_unmap
+always succeeds.
+.It Fn bus_dmamem_mmap "tag" "segs" "nsegs" "off" "prot" "flags"
+Provides support for user
+.Xr mmap 2 Ns 'ing
+of DMA-safe memory. This function is to be called by a device
+driver's (*d_mmap)() entry point, which is called by the
+device pager for each page to be mapped. The arguments are
+as follows:
+.Bl -tag -width nsegs -compact
+.It Fa tag
+This is the bus_dma_tag_t passed down from the parent driver via
+.Fa <bus>_attach_args .
+.It Fa segs
+The array of bus_dma_segment_t's filled in by
+.Fn bus_dmamem_alloc ,
+representing the memory to be
+.Xr mmap 2 Ns 'ed.
+.It Fa nsegs
+The number of elements in the
+.Fa segs
+array.
+.It Fa off
+The offset of the page in DMA memory which is to be mapped.
+.It Fa prot
+The protection codes for the mapping.
+.It Fa flags
+Flags are defined as follows:
+.Bl -tag -width BUS_DMA_COHERENT -compact
+.It Dv BUS_DMA_WAITOK
+It is safe to wait (sleep) for resources during this call.
+.It Dv BUS_DMA_NOWAIT
+It is not safe to wait (sleep) for resources during this call.
+.It Dv BUS_DMA_BUS[1-4]
+These flags are placeholders, and may be used by busses to provide
+bus-dependent functionality.
+.It Dv BUS_DMA_COHERENT
+See
+.Fn bus_dmamem_map
+above for a description of this flag.
+.El
+.El
+.Pp
+Behavior is undefined if invalid arguments are passed
+to
+.Fn bus_dmamem_mmap .
+.Pp
+Returns -1 to indicate failure. Otherwise, returns an opaque
+value to be interpreted by the device pager.
+.El
+.Sh SEE ALSO
+.Xr bus_space 9
+.Sh AUTHOR
+The
+.Nm
+interface was designed and implemented by Jason R. Thorpe of the
+Numerical Aerospace Simulation Facility, NASA Ames Research Center.
+Additional input on the
+.Nm
+design was provided by Chris Demetriou, Charles Hannum, Ross Harvey,
+Matthew Jacob, Jonathan Stone, and Matt Thomas.
+.Sh HISTORY
+The
+.Nm
+interface appeared in
+.Nx 1.3 .
diff --git a/share/man/man9/bus_space.9 b/share/man/man9/bus_space.9
new file mode 100644
index 00000000000..560de0b3614
--- /dev/null
+++ b/share/man/man9/bus_space.9
@@ -0,0 +1,1239 @@
+.\" $OpenBSD: bus_space.9,v 1.1 1999/09/22 03:16:47 csapuntz Exp $
+.\" $NetBSD: bus_space.9,v 1.10 1999/03/16 00:40:47 garbled Exp $
+.\"
+.\" Copyright (c) 1997 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Christopher G. Demetriou.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgment:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd August 13, 1997
+.Dt BUS_SPACE 9
+.Os
+.Sh NAME
+.Nm bus_space ,
+.Nm bus_space_barrier ,
+.Nm bus_space_copy_region_1 ,
+.Nm bus_space_copy_region_2 ,
+.Nm bus_space_copy_region_4 ,
+.Nm bus_space_copy_region_8 ,
+.Nm bus_space_free ,
+.Nm bus_space_map ,
+.Nm bus_space_read_1 ,
+.Nm bus_space_read_2 ,
+.Nm bus_space_read_4 ,
+.Nm bus_space_read_8 ,
+.Nm bus_space_read_multi_1 ,
+.Nm bus_space_read_multi_2 ,
+.Nm bus_space_read_multi_4 ,
+.Nm bus_space_read_multi_8 ,
+.Nm bus_space_read_region_1 ,
+.Nm bus_space_read_region_2 ,
+.Nm bus_space_read_region_4 ,
+.Nm bus_space_read_region_8 ,
+.Nm bus_space_set_region_1 ,
+.Nm bus_space_set_region_2 ,
+.Nm bus_space_set_region_4 ,
+.Nm bus_space_set_region_8 ,
+.Nm bus_space_subregion ,
+.Nm bus_space_unmap ,
+.Nm bus_space_write_1 ,
+.Nm bus_space_write_2 ,
+.Nm bus_space_write_4 ,
+.Nm bus_space_write_8 ,
+.Nm bus_space_write_multi_1 ,
+.Nm bus_space_write_multi_2 ,
+.Nm bus_space_write_multi_4 ,
+.Nm bus_space_write_multi_8 ,
+.Nm bus_space_write_region_1 ,
+.Nm bus_space_write_region_2 ,
+.Nm bus_space_write_region_4 ,
+.Nm bus_space_write_region_8
+.Nd bus space manipulation functions
+.Sh SYNOPSIS
+.Fd #include <machine/bus.h>
+.Ft int
+.Fn bus_space_map "bus_space_tag_t space" "bus_addr_t address" \
+"bus_size_t size" "int flags" "bus_space_handle_t *handlep"
+.Ft void
+.Fn bus_space_unmap "bus_space_tag_t space" "bus_space_handle_t handle" \
+"bus_size_t size"
+.Ft int
+.Fn bus_space_subregion "bus_space_tag_t space" "bus_space_handle_t handle" \
+"bus_size_t offset" "bus_size_t size" "bus_space_handle_t *nhandlep"
+.Ft int
+.Fo bus_space_alloc
+.Fa "bus_space_tag_t space" "bus_addr_t reg_start" "bus_addr_t reg_end"
+.Fa "bus_size_t size" "bus_size_t alignment" "bus_size_t boundary"
+.Fa "int flags" "bus_addr_t *addrp" "bus_space_handle_t *handlep"
+.Fc
+.Ft void
+.Fn bus_space_free "bus_space_tag_t space" "bus_space_handle_t handle" \
+"bus_size_t size"
+.Ft u_int8_t
+.Fn bus_space_read_1 "bus_space_tag_t space" "bus_space_handle_t handle" \
+"bus_size_t offset"
+.Ft u_int16_t
+.Fn bus_space_read_2 "bus_space_tag_t space" "bus_space_handle_t handle" \
+"bus_size_t offset"
+.Ft u_int32_t
+.Fn bus_space_read_4 "bus_space_tag_t space" "bus_space_handle_t handle" \
+"bus_size_t offset"
+.Ft u_int64_t
+.Fn bus_space_read_8 "bus_space_tag_t space" "bus_space_handle_t handle" \
+"bus_size_t offset"
+.Ft void
+.Fn bus_space_write_1 "bus_space_tag_t space" "bus_space_handle_t handle" \
+"bus_size_t offset" "u_int8_t value"
+.Ft void
+.Fn bus_space_write_2 "bus_space_tag_t space" "bus_space_handle_t handle" \
+"bus_size_t offset" "u_int16_t value"
+.Ft void
+.Fn bus_space_write_4 "bus_space_tag_t space" "bus_space_handle_t handle" \
+"bus_size_t offset" "u_int32_t value"
+.Ft void
+.Fn bus_space_write_8 "bus_space_tag_t space" "bus_space_handle_t handle" \
+"bus_size_t offset" "u_int64_t value"
+.Ft void
+.Fn bus_space_barrier "bus_space_tag_t space" "bus_space_handle_t handle" \
+"bus_size_t offset" "bus_size_t length" "int flags"
+.Ft void
+.Fn bus_space_read_region_1 "bus_space_tag_t space" \
+"bus_space_handle_t handle" "bus_size_t offset" "u_int8_t *datap" \
+"bus_size_t count"
+.Ft void
+.Fn bus_space_read_region_2 "bus_space_tag_t space" \
+"bus_space_handle_t handle" "bus_size_t offset" "u_int16_t *datap" \
+"bus_size_t count"
+.Ft void
+.Fn bus_space_read_region_4 "bus_space_tag_t space" \
+"bus_space_handle_t handle" "bus_size_t offset" "u_int32_t *datap" \
+"bus_size_t count"
+.Ft void
+.Fn bus_space_read_region_8 "bus_space_tag_t space" \
+"bus_space_handle_t handle" "bus_size_t offset" "u_int64_t *datap" \
+"bus_size_t count"
+.Ft void
+.Fn bus_space_write_region_1 "bus_space_tag_t space" \
+"bus_space_handle_t handle" "bus_size_t offset" "u_int8_t *datap" \
+"bus_size_t count"
+.Ft void
+.Fn bus_space_write_region_2 "bus_space_tag_t space" \
+"bus_space_handle_t handle" "bus_size_t offset" "u_int16_t *datap" \
+"bus_size_t count"
+.Ft void
+.Fn bus_space_write_region_4 "bus_space_tag_t space" \
+"bus_space_handle_t handle" "bus_size_t offset" "u_int32_t *datap" \
+"bus_size_t count"
+.Ft void
+.Fn bus_space_write_region_8 "bus_space_tag_t space" \
+"bus_space_handle_t handle" "bus_size_t offset" "u_int64_t *datap" \
+"bus_size_t count"
+.Ft void
+.Fn bus_space_copy_region_1 "bus_space_tag_t space" \
+"bus_space_handle_t srchandle" "bus_size_t srcoffset" \
+"bus_space_handle_t dsthandle" "bus_size_t dstoffset" "bus_size_t count"
+.Ft void
+.Fn bus_space_copy_region_2 "bus_space_tag_t space" \
+"bus_space_handle_t srchandle" "bus_size_t srcoffset" \
+"bus_space_handle_t dsthandle" "bus_size_t dstoffset" "bus_size_t count"
+.Ft void
+.Fn bus_space_copy_region_4 "bus_space_tag_t space" \
+"bus_space_handle_t srchandle" "bus_size_t srcoffset" \
+"bus_space_handle_t dsthandle" "bus_size_t dstoffset" "bus_size_t count"
+.Ft void
+.Fn bus_space_copy_region_8 "bus_space_tag_t space" \
+"bus_space_handle_t srchandle" "bus_size_t srcoffset" \
+"bus_space_handle_t dsthandle" "bus_size_t dstoffset" "bus_size_t count"
+.Ft void
+.Fn bus_space_set_region_1 "bus_space_tag_t space" \
+"bus_space_handle_t handle" "bus_size_t offset" "u_int8_t value" \
+"bus_size_t count"
+.Ft void
+.Fn bus_space_set_region_2 "bus_space_tag_t space" \
+"bus_space_handle_t handle" "bus_size_t offset" "u_int16_t value" \
+"bus_size_t count"
+.Ft void
+.Fn bus_space_set_region_4 "bus_space_tag_t space" \
+"bus_space_handle_t handle" "bus_size_t offset" "u_int32_t value" \
+"bus_size_t count"
+.Ft void
+.Fn bus_space_set_region_8 "bus_space_tag_t space" \
+"bus_space_handle_t handle" "bus_size_t offset" "u_int64_t value" \
+"bus_size_t count"
+.Ft void
+.Fn bus_space_read_multi_1 "bus_space_tag_t space" \
+"bus_space_handle_t handle" "bus_size_t offset" "u_int8_t *datap" \
+"bus_size_t count"
+.Ft void
+.Fn bus_space_read_multi_2 "bus_space_tag_t space" \
+"bus_space_handle_t handle" "bus_size_t offset" "u_int16_t *datap" \
+"bus_size_t count"
+.Ft void
+.Fn bus_space_read_multi_4 "bus_space_tag_t space" \
+"bus_space_handle_t handle" "bus_size_t offset" "u_int32_t *datap" \
+"bus_size_t count"
+.Ft void
+.Fn bus_space_read_multi_8 "bus_space_tag_t space" \
+"bus_space_handle_t handle" "bus_size_t offset" "u_int64_t *datap" \
+"bus_size_t count"
+.Ft void
+.Fn bus_space_write_multi_1 "bus_space_tag_t space" \
+"bus_space_handle_t handle" "bus_size_t offset" "u_int8_t *datap" \
+"bus_size_t count"
+.Ft void
+.Fn bus_space_write_multi_2 "bus_space_tag_t space" \
+"bus_space_handle_t handle" "bus_size_t offset" "u_int16_t *datap" \
+"bus_size_t count"
+.Ft void
+.Fn bus_space_write_multi_4 "bus_space_tag_t space" \
+"bus_space_handle_t handle" "bus_size_t offset" "u_int32_t *datap" \
+"bus_size_t count"
+.Ft void
+.Fn bus_space_write_multi_8 "bus_space_tag_t space" \
+"bus_space_handle_t handle" "bus_size_t offset" "u_int64_t *datap" \
+"bus_size_t count"
+.Sh DESCRIPTION
+.Pp
+The
+.Nm
+functions exist to allow device drivers
+machine-independent access to bus memory and register areas. All of the
+functions and types described in this document can be used by including
+the
+.Pa Aq machine/bus.h
+header file.
+.Pp
+Many common devices are used on multiple architectures, but are accessed
+differently on each because of architectural constraints.
+For instance, a device which is mapped in one systems's I/O space may be
+mapped in memory space on a second system. On a third system, architectural
+limitations might change the way registers need to be accessed (e.g.
+creating a non-linear register space).
+In some cases, a single
+driver may need to access the same type of device in multiple ways in a
+single system or architecture. The goal of the
+.Nm
+functions is to allow a single driver source file to manipulate a set
+of devices on different system architectures, and to allow a single driver
+object file to manipulate a set of devices on multiple bus types on a
+single architecture.
+.Pp
+Not all busses have to implement all functions described in this
+document, though that is encouraged if the operations are logically
+supported by the bus. Unimplemented functions should cause
+compile-time errors if possible.
+.Pp
+All of the interface definitions described in this document are shown as
+function prototypes and discussed as if they were required to be
+functions. Implementations are encouraged to implement prototyped
+(type-checked) versions of these interfaces, but may implement them as
+macros if appropriate. Machine-dependent types, variables, and functions
+should be marked clearly in
+.Pa Aq machine/bus.h
+to avoid confusion with the
+machine-independent types and functions, and, if possible, should be
+given names which make the machine-dependence clear.
+.Sh CONCEPTS AND GUIDELINES
+.Pp
+Bus spaces are described by bus space tags, which can be created only by
+machine-dependent code. A given machine may have several different types
+of bus space (e.g. memory space and I/O space), and thus may provide
+multiple different bus space tags.
+Individual busses or devices on a machine may use more than one bus space
+tag. For instance, ISA devices are
+given an ISA memory space tag and an ISA I/O space tag. Architectures
+may have several different tags which represent the same type of
+space, for instance because of multiple different host bus interface
+chipsets.
+.Pp
+A range in bus space is described by a bus address and a bus size. The
+bus address describes the start of the range in bus space. The bus
+size describes the size of the range in bytes. Busses which are not byte
+addressable may require use of bus space ranges with appropriately
+aligned addresses and properly rounded sizes.
+.Pp
+Access to regions of bus space is facilitated by use of bus space handles,
+which are usually created by mapping a specific range of a bus space.
+Handles may also be created by allocating
+and mapping a range of bus space, the actual location of which is picked
+by the implementation within bounds specified by the caller of the
+allocation function.
+.Pp
+All of the bus space access functions require one bus space tag
+argument, at least one handle argument, and at least one offset argument
+(a bus size).
+The bus space tag specifies the space, each handle specifies a region in
+the space, and each offset specifies the offset into the region of the
+actual location(s) to be accessed. Offsets are given in bytes, though busses
+may impose alignment constraints. The offset used to access data
+relative to a given handle must be such that all of the data being
+accessed is in the mapped region that the handle describes. Trying to
+access data outside that region is an error.
+.Pp
+Because some architectures' memory systems use buffering to improve
+memory and device access performance, there is a mechanism which can be
+used to create
+.Dq barriers
+in the bus space read and write stream. There
+are three types of barriers: read, write, and read/write. All reads
+started to the region before a read barrier must complete before any reads
+after the read barrier are started. (The analogous requirement is true for
+write barriers.) Read/write barriers force all reads and writes started
+before the barrier to complete before any reads or writes after the
+barrier are started. Correctly-written drivers will include all
+appropriate barriers, and assume only the read/write ordering imposed by
+the barrier operations.
+.Pp
+People trying to write portable drivers with the
+.Nm
+functions should
+try to make minimal assumptions about what the system allows. In particular,
+they should expect that the system requires bus space addresses being
+accessed to be naturally aligned (i.e. base address of handle added to
+offset is a multiple of the access size), and that the system does
+alignment checking on pointers (i.e. pointer to objects being read and
+written must point to properly-aligned data).
+.Pp
+The descriptions of the
+.Nm
+functions given below all assume that
+they are called with proper arguments. If called with invalid arguments
+or arguments that are out of range (e.g. trying to access data outside of
+the region mapped when a given handle was created), undefined behaviour
+results. In that case, they may cause the
+system to halt, either intentionally (via panic) or unintentionally (by
+causing a fatal trap of by some other means) or may cause improper
+operation which is not immediately fatal. Functions which return
+void or which return data read from bus space (i.e., functions which
+don't obviously return an error code) do not fail. They could only fail
+if given invalid arguments, and in that case their behaviour is undefined.
+.Pp
+.Sh TYPES
+Several types are defined in
+.Pa Aq machine/bus.h
+to facilitate use of the
+.Nm
+functions by drivers.
+.Pp
+.Bl -ohang -compact
+.It Fa bus_addr_t
+.Pp
+The
+.Fa bus_addr_t
+type is used to describe bus addresses. It must be an
+unsigned integral type
+capable of holding the largest bus address usable by the architecture. This
+type is primarily used when mapping and unmapping bus space.
+.Pp
+.It Fa bus_size_t
+.Pp
+The
+.Fa bus_size_t
+type is used to describe sizes of ranges in bus space. It must be an
+unsigned integral type capable of holding the size of the largest bus
+address range usable on the architecture. This type is used by virtually all
+of the
+.Nm
+functions, describing sizes when mapping regions and
+offsets into regions when performing space access operations.
+.Pp
+.It Fa bus_space_tag_t
+.Pp
+The
+.Fa bus_space_tag_t
+type is used to describe a particular bus space on a machine. Its
+contents are machine-dependent and should be considered opaque by
+machine-independent code. This type is used by all
+.Nm
+functions to name the space on which they're operating.
+.Pp
+.It Fa bus_space_handle_t
+.Pp
+The
+.Fa bus_space_handle_t
+type is used to describe a mapping of a range of bus space. Its
+contents are machine-dependent and should be considered opaque by
+machine-independent code. This type is used when performing bus space
+access operations.
+.El
+.Pp
+.Sh MAPPING AND UNMAPPING BUS SPACE
+.Pp
+Bus space must be mapped before it can be used, and should be
+unmapped when it is no longer needed. The
+.Fn bus_space_map
+and
+.Fn bus_space_unmap
+functions provide these capabilities.
+.Pp
+Some drivers need to be able to pass a subregion of already-mapped bus
+space to another driver or module within a driver. The
+.Fn bus_space_subregion
+function allows such subregions to be created.
+.Pp
+.Bl -ohang -compact
+.It Fn bus_space_map "space" "address" "size" "flags" "handlep"
+.Pp
+The
+.Fn bus_space_map
+function maps the region of bus space named by the
+.Fa space ,
+.Fa address ,
+and
+.Fa size
+arguments. If successful, it returns zero
+and fills in the bus space handle pointed to by
+.Fa handlep
+with the handle
+that can be used to access the mapped region. If unsuccessful,
+it will return non-zero and leave the bus space handle pointed
+to by
+.Fa handlep
+in an undefined state.
+.Pp
+The
+.Fa flags
+argument controls how the space is to be mapped. Supported flags include:
+.Bl -tag -width BUS_SPACE_MAP_CACHEABLE -offset indent
+.It Dv BUS_SPACE_MAP_CACHEABLE
+Try to map the space so that accesses can be cached and/or
+prefetched by the system. If this flag is not specified, the
+implementation should map the space so that it will not be cached or
+prefetched.
+.Pp
+This flag must have a value of 1 on all implementations for backward
+compatibility.
+.It Dv BUS_SPACE_MAP_LINEAR
+Try to map the space so that its contents can be accessed linearly via
+normal memory access methods (e.g. pointer dereferencing and structure
+accesses).
+This is useful when software wants to do direct access to a memory
+device, e.g. a frame buffer. If this flag is specified and linear
+mapping is not possible, the
+.Fn bus_space_map
+call should fail. If this
+flag is not specified, the system may map the space in whatever way is
+most convenient.
+.El
+.Pp
+Not all combinations of flags make sense or are supported with all
+spaces. For instance,
+.Dv BUS_SPACE_MAP_CACHEABLE
+may be meaningless when
+used on many systems' I/O port spaces, and on some systems
+.Dv BUS_SPACE_MAP_LINEAR
+without
+.Dv BUS_SPACE_MAP_CACHEABLE
+may never work.
+When the system hardware or firmware provides hints as to how spaces should be
+mapped (e.g. the PCI memory mapping registers' "prefetchable" bit), those
+hints should be followed for maximum compatibility. On some systems,
+requesting a mapping that cannot be satisfied (e.g. requesting a
+non-cacheable mapping when the system can only provide a cacheable one)
+will cause the request to fail.
+.Pp
+Some implementations may keep track of use of bus space for some or all
+bus spaces and refuse to allow duplicate allocations. This is encouraged
+for bus spaces which have no notion of slot-specific space addressing,
+such as ISA and VME, and for spaces which coexist with those spaces
+(e.g. EISA and PCI memory and I/O spaces co-existing with ISA memory and
+I/O spaces).
+.Pp
+Mapped regions may contain areas for which no there is no device on the
+bus. If space in those areas is accessed, the results are
+bus-dependent.
+.Pp
+.It Fn bus_space_unmap "space" "handle" "size"
+.Pp
+The
+.Fn bus_space_unmap
+function unmaps a region of bus space mapped with
+.Fn bus_space_map .
+When unmapping a region, the
+.Fa size
+specified should be
+the same as the size given to
+.Fn bus_space_map
+when mapping that region.
+.Pp
+After
+.Fn bus_space_unmap
+is called on a handle, that handle is no longer
+valid. (If copies were made of the handle they are no longer valid,
+either.)
+.Pp
+This function will never fail. If it would fail (e.g. because of an
+argument error), that indicates a software bug which should cause a
+panic. In that case,
+.Fn bus_space_unmap
+will never return.
+.Pp
+.It Fn bus_space_subregion "space" "handle" "offset" "size" "nhandlep"
+.Pp
+The
+.Fn bus_space_subregion
+function is a convenience function which makes a
+new handle to some subregion of an already-mapped region of bus space.
+The subregion described by the new handle starts at byte offset
+.Fa offset
+into the region described by
+.Fa handle ,
+with the size give by
+.Fa size ,
+and must be wholly contained within the original region.
+.Pp
+If successful,
+.Fn bus_space_subregion
+returns zero and fills in the bus
+space handle pointed to by
+.Fa nhandlep .
+If unsuccessful, it returns non-zero and leaves the bus space handle
+pointed to by
+.Fa nhandlep
+in an
+undefined state. In either case, the handle described by
+.Fa handle
+remains valid and is unmodified.
+.Pp
+When done with a handle created by
+.Fn bus_space_subregion ,
+the handle should
+be thrown away. Under no circumstances should
+.Fn bus_space_unmap
+be used on the handle. Doing so may confuse any resource management
+being done on the space, and will result in undefined behaviour. When
+.Fn bus_space_unmap
+or
+.Fn bus_space_free
+is called on a handle, all subregions of that handle become invalid.
+.El
+.Pp
+.Sh ALLOCATING AND FREEING BUS SPACE
+.Pp
+Some devices require or allow bus space to be allocated by the operating
+system for device use. When the devices no longer need the space, the
+operating system should free it for use by other devices. The
+.Fn bus_space_alloc
+and
+.Fn bus_space_free
+functions provide these capabilities.
+.Pp
+.Bl -ohang -compact
+.It Xo
+.Fo bus_space_alloc
+.Fa "space" "reg_start" "reg_end" "size"
+.Fa "alignment" "boundary" "flags" "addrp" "handlep"
+.Fc
+.Xc
+.Pp
+The
+.Fn bus_space_alloc
+function allocates and maps a region of bus space with the size given by
+.Fa size ,
+corresponding to the given constraints. If successful, it returns
+zero, fills in the bus address pointed to by
+.Fa addrp
+with the bus space address of the allocated region, and fills in
+the bus space handle pointed to by
+.Fa handlep
+with the handle that can be used to access that region.
+If unsuccessful, it returns non-zero and leaves the bus address pointed to by
+.Fa addrp
+and the bus space handle pointed to by
+.Fa handlep
+in an undefined state.
+.Pp
+Constraints on the allocation are given by the
+.Fa reg_start ,
+.Fa reg_end ,
+.Fa alignment ,
+and
+.Fa boundary
+parameters. The allocated region will start at or after
+.Fa reg_start
+and end before or at
+.Fa reg_end .
+The
+.Fa alignment
+constraint must be a power of two, and the allocated region will start at
+an address that is an even multiple of that power of two. The
+.Fa boundary
+constraint, if non-zero, ensures that the region is allocated so that
+.Fa "first address in region"
+/
+.Fa boundary
+has the same value as
+.Fa "last address in region"
+/
+.Fa boundary .
+If the constraints cannot be met,
+.Fn bus_space_alloc
+will fail. It is an error to specify a set of
+constraints that can never be met
+.Po
+for example,
+.Fa size
+greater than
+.Fa boundary
+.Pc .
+.Pp
+The
+.Fa flags
+parameter is the same as the like-named parameter to
+.Fa bus_space_map ,
+the same flag values should be used, and they have the
+same meanings.
+.Pp
+Handles created by
+.Fn bus_space_alloc
+should only be freed with
+.Fn bus_space_free .
+Trying to use
+.Fn bus_space_unmap
+on them causes undefined behaviour. The
+.Fn bus_space_subregion
+function can be used on
+handles created by
+.Fn bus_space_alloc .
+.Pp
+.It Fn bus_space_free "space" "handle" "size"
+.Pp
+The
+.Fn bus_space_free
+function unmaps and frees a region of bus space mapped
+and allocated with
+.Fn bus_space_alloc .
+When unmapping a region, the
+.Fa size
+specified should be the same as the size given to
+.Fn bus_space_alloc
+when allocating the region.
+.Pp
+After
+.Fn bus_space_free
+is called on a handle, that handle is no longer valid. (If copies were
+made of the handle, they are no longer valid, either.)
+.Pp
+This function will never fail. If it would fail (e.g. because of an
+argument error), that indicates a software bug which should cause a
+panic. In that case,
+.Fn bus_space_free
+will never return.
+.El
+.Pp
+.Sh READING AND WRITING SINGLE DATA ITEMS
+.Pp
+The simplest way to access bus space is to read or write a single data
+item. The
+.Fn bus_space_read_N
+and
+.Fn bus_space_write_N
+families of functions provide
+the ability to read and write 1, 2, 4, and 8 byte data items on busses
+which support those access sizes.
+.Pp
+.Bl -ohang -compact
+.It Fn bus_space_read_1 "space" "handle" "offset"
+.It Fn bus_space_read_2 "space" "handle" "offset"
+.It Fn bus_space_read_4 "space" "handle" "offset"
+.It Fn bus_space_read_8 "space" "handle" "offset"
+.Pp
+The
+.Fn bus_space_read_N
+family of functions reads a 1, 2, 4, or 8 byte data item from
+the offset specified by
+.Fa offset
+into the region specified by
+.Fa handle
+of the bus space specified by
+.Fa space .
+The location being read must lie within the bus space region specified by
+.Fa handle .
+.Pp
+For portability, the starting address of the region specified by
+.Fa handle
+plus the offset should be a multiple of the size of data item being read.
+On some systems, not obeying this requirement may cause incorrect data to
+be read, on others it may cause a system crash.
+.Pp
+Read operations done by the
+.Fn bus_space_read_N
+functions may be executed out
+of order with respect to other pending read and write operations unless
+order is enforced by use of the
+.Fn bus_space_barrier
+function.
+.Pp
+These functions will never fail. If they would fail (e.g. because of an
+argument error), that indicates a software bug which should cause a
+panic. In that case, they will never return.
+.Pp
+.It Fn bus_space_write_1 "space" "handle" "offset" "value"
+.It Fn bus_space_write_2 "space" "handle" "offset" "value"
+.It Fn bus_space_write_4 "space" "handle" "offset" "value"
+.It Fn bus_space_write_8 "space" "handle" "offset" "value"
+.Pp
+The
+.Fn bus_space_write_N
+family of functions writes a 1, 2, 4, or 8 byte data item to the offset
+specified by
+.Fa offset
+into the region specified by
+.Fa handle
+of the bus space specified by
+.Fa space .
+The location being written must lie within
+the bus space region specified by
+.Fa handle .
+.Pp
+For portability, the starting address of the region specified by
+.Fa handle
+plus the offset should be a multiple of the size of data item being
+written. On some systems, not obeying this requirement may cause
+incorrect data to be written, on others it may cause a system crash.
+.Pp
+Write operations done by the
+.Fn bus_space_write_N
+functions may be executed
+out of order with respect to other pending read and write operations
+unless order is enforced by use of the
+.Fn bus_space_barrier
+function.
+.Pp
+These functions will never fail. If they would fail (e.g. because of an
+argument error), that indicates a software bug which should cause a
+panic. In that case, they will never return.
+.El
+.Pp
+.Sh BARRIERS
+.Pp
+In order to allow high-performance buffering implementations to avoid bus
+activity on every operation, read and write ordering should be specified
+explicitly by drivers when necessary. The
+.Fn bus_space_barrier
+function provides that ability.
+.Pp
+.Bl -ohang -compact
+.It Fn bus_space_barrier "space" "handle" "offset" "length" "flags"
+.Pp
+The
+.Fn bus_space_barrier
+function enforces ordering of bus space read and write operations
+for the specified subregion (described by the
+.Fa offset
+and
+.Fa length
+parameters) of the region named by
+.Fa handle
+in the space named by
+.Fa space .
+.Pp
+The
+.Fa flags
+argument controls what types of operations are to be ordered.
+Supported flags are:
+.Bl -tag -width BUS_SPACE_BARRIER_WRITE -offset indent
+.It Dv BUS_SPACE_BARRIER_READ
+Synchronize read operations.
+.It Dv BUS_SPACE_BARRIER_WRITE
+Synchronize write operations.
+.El
+.Pp
+Those flags can be combined (or-ed together) to enforce ordering on both
+read and write operations.
+.Pp
+All of the specified type(s) of operation which are done to the region
+before the barrier operation are guaranteed to complete before any of the
+specified type(s) of operation done after the barrier.
+.Pp
+Example: Consider a hypothetical device with two single-byte ports, one
+write-only input port (at offset 0) and a read-only output port (at
+offset 1). Operation of the device is as follows: data bytes are written
+to the input port, and are placed by the device on a stack, the top of
+which is read by reading from the output port. The sequence to correctly
+write two data bytes to the device then read those two data bytes back
+would be:
+.Pp
+.Bd -literal
+/*
+ * t and h are the tag and handle for the mapped device's
+ * space.
+ */
+bus_space_write_1(t, h, 0, data0);
+bus_space_barrier(t, h, 0, 1, BUS_SPACE_BARRIER_WRITE); /* 1 */
+bus_space_write_1(t, h, 0, data1);
+bus_space_barrier(t, h, 0, 2,
+ BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE); /* 2 */
+ndata1 = bus_space_read_1(t, h, 1);
+bus_space_barrier(t, h, 1, 1, BUS_SPACE_BARRIER_READ); /* 3 */
+ndata0 = bus_space_read_1(t, h, 1);
+/* data0 == ndata0, data1 == ndata1 */
+.Ed
+.Pp
+The first barrier makes sure that the first write finishes before the
+second write is issued, so that two writes to the input port are done
+in order and are not collapsed into a single write. This ensures that
+the data bytes are written to the device correctly and in order.
+.Pp
+The second barrier makes sure that the writes to the output port finish
+before any of the reads to the input port are issued, thereby making sure
+that all of the writes are finished before data is read. This ensures
+that the first byte read from the device really is the last one that was
+written.
+.Pp
+The third barrier makes sure that the first read finishes before the
+second read is issued, ensuring that data is read correctly and in order.
+.Pp
+The barriers in the example above are specified to cover the absolute
+minimum number of bus space locations. It is correct (and often
+easier) to make barrier operations cover the device's whole range of bus
+space, that is, to specify an offset of zero and the size of the
+whole region.
+.El
+.Pp
+.Sh REGION OPERATIONS
+.Pp
+Some devices use buffers which are mapped as regions in bus space.
+Often, drivers want to copy the contents of those buffers to or from
+memory, e.g. into mbufs which can be passed to higher levels of the
+system or from mbufs to be output to a network. In order to allow
+drivers to do this as efficiently as possible, the
+.Fn bus_space_read_region_N
+and
+.Fn bus_space_write_region_N
+families of functions are provided.
+.Pp
+Drivers occasionally need to copy one region of a bus space to another,
+or to set all locations in a region of bus space to contain a single
+value. The
+.Fn bus_space_copy_region_N
+family of functions and the
+.Fn bus_space_set_region_N
+family of functions allow drivers to perform these operations.
+.Pp
+.Bl -ohang -compact
+.It Fn bus_space_read_region_1 "space" "handle" "offset" "datap" "count"
+.It Fn bus_space_read_region_2 "space" "handle" "offset" "datap" "count"
+.It Fn bus_space_read_region_4 "space" "handle" "offset" "datap" "count"
+.It Fn bus_space_read_region_8 "space" "handle" "offset" "datap" "count"
+.Pp
+The
+.Fn bus_space_read_region_N
+family of functions reads
+.Fa count
+1, 2, 4, or 8 byte data items from bus space
+starting at byte offset
+.Fa offset
+in the region specified by
+.Fa handle
+of the bus space specified by
+.Fa space
+and writes them into the array specified by
+.Fa datap .
+Each successive data item is read from an offset
+1, 2, 4, or 8 bytes after the previous data item (depending on which
+function is used). All locations being read must lie within the bus
+space region specified by
+.Fa handle .
+.Pp
+For portability, the starting address of the region specified by
+.Fa handle
+plus the offset should be a multiple of the size of data items being
+read and the data array pointer should be properly aligned. On some
+systems, not obeying these requirements may cause incorrect data to be
+read, on others it may cause a system crash.
+.Pp
+Read operations done by the
+.Fn bus_space_read_region_N
+functions may be executed in any order. They may also be executed out
+of order with respect to other pending read and write operations unless
+order is enforced by use of the
+.Fn bus_space_barrier
+function. There is no way to insert barriers between reads of
+individual bus space locations executed by the
+.Fn bus_space_read_region_N
+functions.
+.Pp
+These functions will never fail. If they would fail (e.g. because of an
+argument error), that indicates a software bug which should cause a
+panic. In that case, they will never return.
+.Pp
+.It Fn bus_space_write_region_1 "space" "handle" "offset" "datap" "count"
+.It Fn bus_space_write_region_2 "space" "handle" "offset" "datap" "count"
+.It Fn bus_space_write_region_4 "space" "handle" "offset" "datap" "count"
+.It Fn bus_space_write_region_8 "space" "handle" "offset" "datap" "count"
+.Pp
+The
+.Fn bus_space_write_region_N
+family of functions reads
+.Fa count
+1, 2, 4, or 8 byte data items from the array
+specified by
+.Fa datap
+and writes them to bus space starting at byte offset
+.Fa offset
+in the region specified by
+.Fa handle
+of the bus space specified
+by
+.Fa space .
+Each successive data item is written to an offset 1, 2, 4,
+or 8 bytes after the previous data item (depending on which function is
+used). All locations being written must lie within the bus space region
+specified by
+.Fa handle .
+.Pp
+For portability, the starting address of the region specified by
+.Fa handle
+plus the offset should be a multiple of the size of data items being
+written and the data array pointer should be properly aligned. On some
+systems, not obeying these requirements may cause incorrect data to be
+written, on others it may cause a system crash.
+.Pp
+Write operations done by the
+.Fn bus_space_write_region_N
+functions may be
+executed in any order. They may also be executed out of order with
+respect to other pending read and write operations unless order is
+enforced by use of the
+.Fn bus_space_barrier
+function. There is no way to insert barriers between writes of
+individual bus space locations executed by the
+.Fn bus_space_write_region_N
+functions.
+.Pp
+These functions will never fail. If they would fail (e.g. because of an
+argument error), that indicates a software bug which should cause a
+panic. In that case, they will never return.
+.Pp
+.It Fn bus_space_copy_region_1 "space" "srchandle" "srcoffset" "dsthandle" \
+"dstoffset" "count"
+.It Fn bus_space_copy_region_2 "space" "srchandle" "srcoffset" "dsthandle" \
+"dstoffset" "count"
+.It Fn bus_space_copy_region_4 "space" "srchandle" "srcoffset" "dsthandle" \
+"dstoffset" "count"
+.It Fn bus_space_copy_region_8 "space" "srchandle" "srcoffset" "dsthandle" \
+"dstoffset" "count"
+.Pp
+The
+.Fn bus_space_copy_region_N
+family of functions copies
+.Fa count
+1, 2, 4, or 8 byte data items in bus space
+from the area starting at byte offset
+.Fa srcoffset
+in the region specified by
+.Fa srchandle
+of the bus space specified by
+.Fa space
+to the area starting at byte offset
+.Fa dstoffset
+in the region specified by
+.Fa dsthandle
+in the same bus space. Each successive data item read or written has
+an offset 1, 2, 4, or 8 bytes after the previous data item (depending
+on which function is used). All locations being read and written must
+lie within the bus space region specified by their respective handles.
+.Pp
+For portability, the starting addresses of the regions specified by the
+each handle plus its respective offset should be a multiple of the size
+of data items being copied. On some systems, not obeying this
+requirement may cause incorrect data to be copied, on others it may cause
+a system crash.
+.Pp
+Read and write operations done by the
+.Fn bus_space_copy_region_N
+functions may be executed in any order. They may also be executed out
+of order with respect to other pending read and write operations unless
+order is enforced by use of the
+.Fn bus_space_barrier function .
+There is no way to insert barriers between reads or writes of
+individual bus space locations executed by the
+.Fn bus_space_copy_region_N
+functions.
+.Pp
+Overlapping copies between different subregions of a single region
+of bus space are handled correctly by the
+.Fn bus_space_copy_region_N
+functions.
+.Pp
+These functions will never fail. If they would fail (e.g. because of an
+argument error), that indicates a software bug which should cause a
+panic. In that case, they will never return.
+.Pp
+.It Fn bus_space_set_region_1 "space" "handle" "offset" "value" "count"
+.It Fn bus_space_set_region_2 "space" "handle" "offset" "value" "count"
+.It Fn bus_space_set_region_4 "space" "handle" "offset" "value" "count"
+.It Fn bus_space_set_region_8 "space" "handle" "offset" "value" "count"
+.Pp
+The
+.Fn bus_space_set_region_N
+family of functions writes the given
+.Fa value
+to
+.Fa count
+1, 2, 4, or 8 byte
+data items in bus space starting at byte offset
+.Fa offset
+in the region specified by
+.Fa handle
+of the bus space specified by
+.Fa space .
+Each successive data item has an offset 1, 2, 4, or 8 bytes after the
+previous data item (depending on which function is used). All
+locations being written must lie within the bus space region specified
+by
+.Fa handle .
+.Pp
+For portability, the starting address of the region specified by
+.Fa handle
+plus the offset should be a multiple of the size of data items being
+written. On some systems, not obeying this requirement may cause
+incorrect data to be written, on others it may cause a system crash.
+.Pp
+Write operations done by the
+.Fn bus_space_set_region_N
+functions may be
+executed in any order. They may also be executed out of order with
+respect to other pending read and write operations unless order is
+enforced by use of the
+.Fn bus_space_barrier
+function. There is no way to insert barriers between writes of
+individual bus space locations executed by the
+.Fn bus_space_set_region_N
+functions.
+.Pp
+These functions will never fail. If they would fail (e.g. because of an
+argument error), that indicates a software bug which should cause a
+panic. In that case, they will never return.
+.El
+.Pp
+.Sh READING AND WRITING A SINGLE LOCATION MULTIPLE TIMES
+.Pp
+Some devices implement single locations in bus space which are to be read
+or written multiple times to communicate data, e.g. some ethernet
+devices' packet buffer FIFOs. In order to allow drivers to manipulate
+these types of devices as efficiently as possible, the
+.Fn bus_space_read_multi_N
+and
+.Fn bus_space_write_multi_N
+families of functions are provided.
+.Pp
+.Bl -ohang -compact
+.It Fn bus_space_read_multi_1 "space" "handle" "offset" "datap" "count"
+.It Fn bus_space_read_multi_2 "space" "handle" "offset" "datap" "count"
+.It Fn bus_space_read_multi_4 "space" "handle" "offset" "datap" "count"
+.It Fn bus_space_read_multi_8 "space" "handle" "offset" "datap" "count"
+.Pp
+The
+.Fn bus_space_read_multi_N
+family of functions reads
+.Fa count
+1, 2, 4, or 8 byte data items from bus space
+at byte offset
+.Fa offset
+in the region specified by
+.Fa handle
+of the bus space specified by
+.Fa space
+and writes them into the array specified by
+.Fa datap .
+Each successive data item is read from the same location in bus
+space. The location being read must lie within the bus space region
+specified by
+.Fa handle .
+.Pp
+For portability, the starting address of the region specified by
+.Fa handle
+plus the offset should be a multiple of the size of data items being
+read and the data array pointer should be properly aligned. On some
+systems, not obeying these requirements may cause incorrect data to be
+read, on others it may cause a system crash.
+.Pp
+Read operations done by the
+.Fn bus_space_read_multi_N
+functions may be
+executed out of order with respect to other pending read and write
+operations unless order is enforced by use of the
+.Fn bus_space_barrier
+function. Because the
+.Fn bus_space_read_multi_N
+functions read the same bus space location multiple times, they
+place an implicit read barrier between each successive read of that bus
+space location.
+.Pp
+These functions will never fail. If they would fail (e.g. because of an
+argument error), that indicates a software bug which should cause a
+panic. In that case, they will never return.
+.Pp
+.It Fn bus_space_write_multi_1 "space" "handle" "offset" "datap" "count"
+.It Fn bus_space_write_multi_2 "space" "handle" "offset" "datap" "count"
+.It Fn bus_space_write_multi_4 "space" "handle" "offset" "datap" "count"
+.It Fn bus_space_write_multi_8 "space" "handle" "offset" "datap" "count"
+.Pp
+The
+.Fn bus_space_write_multi_N
+family of functions reads
+.Fa count
+1, 2, 4, or 8 byte data items from the array
+specified by
+.Fa datap
+and writes them into bus space at byte offset
+.Fa offset
+in the region specified by
+.Fa handle
+of the bus space specified by
+.Fa space .
+Each successive data item is written to the same location in
+bus space. The location being written must lie within the bus space
+region specified by
+.Fa handle .
+.Pp
+For portability, the starting address of the region specified by
+.Fa handle
+plus the offset should be a multiple of the size of data items being
+written and the data array pointer should be properly aligned. On some
+systems, not obeying these requirements may cause incorrect data to be
+written, on others it may cause a system crash.
+.Pp
+Write operations done by the
+.Fn bus_space_write_multi_N
+functions may be executed out of order with respect to other pending
+read and write operations unless order is enforced by use of the
+.Fn bus_space_barrier
+function. Because the
+.Fn bus_space_write_multi_N
+functions write the same bus space location multiple times, they
+place an implicit write barrier between each successive write of that
+bus space location.
+.Pp
+These functions will never fail. If they would fail (e.g. because of an
+argument error), that indicates a software bug which should cause a
+panic. In that case, they will never return.
+.El
+.Pp
+.Sh EXPECTED CHANGES TO THE BUS_SPACE FUNCTIONS
+.Pp
+The definition of the
+.Nm
+functions should not yet be considered finalized. There are several
+changes and improvements which should be explored, including:
+.Pp
+.Bl -bullet
+.It
+Providing a mechanism by which incorrectly-written drivers will be
+automatically given barriers and properly-written drivers won't be forced
+to use more barriers than they need. This should probably be done via a
+.Li #define
+in the incorrectly-written drivers.
+Unfortunately, at this time, few drivers actually use barriers correctly
+(or at all). Because of that,
+.Nm
+implementations on architectures which do buffering must always
+do the barriers inside the
+.Nm
+calls, to be safe. That has a potentially significant
+performance impact.
+.It
+Exporting the
+.Nm
+functions to user-land so that applications
+(such as X servers) have easier, more portable access to device space.
+.It
+Redefining bus space tags and handles so that machine-independent bus
+interface drivers (for example PCI to VME bridges) could define and
+implement bus spaces without requiring machine-dependent code. If this
+is done, it should be done in such a way that machine-dependent
+optimizations should remain possible.
+.It
+Converting bus spaces (such as PCI configuration space) which currently
+use space-specific access methods to use the
+.Nm
+functions where that is appropriate.
+.It
+Redefining the way bus space is mapped and allocated, so that mapping
+and allocation are done with bus specific functions which return bus
+space tags. This would allow further optimization than is currently
+possible, and would also ease translation of the
+.Nm
+functions
+into user space (since mapping in user space would look like it just used
+a different bus-specific mapping function).
+.El
+.Pp
+.Sh COMPATIBILITY
+.Pp
+The current version of the
+.Nm
+interface specification differs slightly from the original
+specification that came into wide use.
+A few of the function names and arguments have changed
+for consistency and increased functionality.
+Drivers that were written to the
+old, deprecated specification can be compiled by defining the
+.Dv __BUS_SPACE_COMPAT_OLDDEFS
+preprocessor symbol before including
+.Pa Aq machine/bus.h .
+.Pp
+.Sh HISTORY
+.Pp
+The
+.Nm
+functions were introduced in a different form (memory and I/O spaces
+were accessed via different sets of functions) in
+.Nx 1.2 .
+The functions were merged to work on generic
+.Dq spaces
+early in the
+.Nx 1.3
+development cycle, and many drivers were converted to use them.
+This document was written later during the
+.Nx 1.3
+development cycle and the specification was updated to fix some
+consistency problems and to add some missing functionality.
+.Pp
+.Sh AUTHORS
+.Pp
+The
+.Nm
+interfaces were designed and implemented by the
+.Nx
+developer
+community. Primary contributors and implementors were Chris Demetriou,
+Jason Thorpe, and Charles Hannum, but the rest of the
+.Nx
+developers and the user community played a significant role in development.
+.Pp
+Chris Demetriou wrote this manual page.
+.Pp
+.Sh SEE ALSO
+.Xr bus_dma 9
diff --git a/share/man/man9/mi_switch.9 b/share/man/man9/ctxsw.9
index 217d15551c9..4217007166f 100644
--- a/share/man/man9/mi_switch.9
+++ b/share/man/man9/ctxsw.9
@@ -1,4 +1,4 @@
-.\" $OpenBSD: mi_switch.9,v 1.1 1999/09/05 16:23:11 espie Exp $
+.\" $OpenBSD: ctxsw.9,v 1.1 1999/09/22 03:16:47 csapuntz Exp $
.\" $NetBSD: ctxsw.9,v 1.10 1999/03/16 00:40:47 garbled Exp $
.\"
.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd November 24, 1996
-.Dt CONTEXT SWITCH 9
+.Dt CTXSW 9
.Os
.Sh NAME
.Nm mi_switch ,
@@ -75,7 +75,7 @@ detection of a change in the signal disposition of the current process, or
when a higher priority process might be available to run.
The latter event is communicated by the machine-independent scheduling
routines by calling the machine-dependent
-.Fn need_resched .
+.Fn need_resched "void" .
.It
In the signal handling code
.Pq see Xr issignal 9
@@ -95,7 +95,7 @@ cause a
After these administrative tasks are done,
.Fn mi_switch
hands over control to the machine dependent routine
-.Fn cpu_switch ,
+.Fn cpu_switch "void" ,
which will perform the actual process context switch.
.Pp
.Fn cpu_switch
@@ -103,7 +103,7 @@ will make a choice amongst the processes which are ready to run from a
priority queue data-structure.
The priority queue consists of an array
.Va qs[NQS]
-of queue header structures, each of which identifies a list of runnable
+of queue header structures each of which identifies a list of runnable
processes of equal priority
.Pq see Aq Pa sys/proc.h .
A single word
@@ -139,10 +139,7 @@ and thus
.Fn cpu_switch
should be called at
.Xr splhigh 9 .
-.Sh CODE_REFERENCES
-The
-.Fn mi_switch
-function is implemented in the file
-.Pa sys/kern/kern_synch.c .
+.Pp
.Sh SEE ALSO
-.Xr sleep 9 .
+.Xr tsleep 9 ,
+.Xr wakeup 9
diff --git a/share/man/man9/disk.9 b/share/man/man9/disk.9
index 9656fb748e3..2656764bb96 100644
--- a/share/man/man9/disk.9
+++ b/share/man/man9/disk.9
@@ -1,5 +1,5 @@
-.\" $OpenBSD: disk.9,v 1.8 1999/09/02 17:28:06 espie Exp $
-.\" $NetBSD: disk.9,v 1.2 1996/04/08 20:41:25 jtc Exp $
+.\" $OpenBSD: disk.9,v 1.9 1999/09/22 03:16:47 csapuntz Exp $
+.\" $NetBSD: disk.9,v 1.10 1999/03/16 00:40:47 garbled Exp $
.\"
.\" Copyright (c) 1995, 1996 Jason R. Thorpe.
.\" All rights reserved.
@@ -35,7 +35,14 @@
.Dt DISK 9
.Os
.Sh NAME
-.Nm disk
+.Nm disk ,
+.Nm disk_init ,
+.Nm disk_attach ,
+.Nm disk_detatch ,
+.Nm disk_busy ,
+.Nm disk_unbusy ,
+.Nm disk_find ,
+.Nm disk_resetstat
.Nd generic disk framework
.Sh SYNOPSIS
.Fd #include <sys/types.h>
@@ -46,7 +53,7 @@
.Ft void
.Fn disk_attach "struct disk *"
.Ft void
-.Fn disk_detatch "struct disk *"
+.Fn disk_detach "struct disk *"
.Ft void
.Fn disk_busy "struct disk *"
.Ft void
@@ -56,12 +63,12 @@
.Ft struct disk *
.Fn disk_find "char *"
.Sh DESCRIPTION
-The
-.Ox
+The
+.Nx
generic disk framework is designed to provide flexible,
scalable, and consistent handling of disk state and metrics information.
The fundamental component of this framework is the
-.Nm
+.Nm disk
structure, which is defined as follows:
.Bd -literal
struct disk {
@@ -81,7 +88,7 @@ struct disk {
int dk_busy; /* busy counter */
u_int64_t dk_xfer; /* total number of transfers */
u_int64_t dk_seek; /* total independent seek operations */
- u_int64_t dk_bytes; /* total bytes transferred */
+ u_int64_t dk_bytes; /* total bytes transfered */
struct timeval dk_attachtime; /* time disk was attached */
struct timeval dk_timestamp; /* timestamp of last unbusy */
struct timeval dk_time; /* total time spent busy */
@@ -122,7 +129,7 @@ Attach a disk; allocate storage for the disklabel, set the
.Dq attached time
timestamp, insert the disk into the disklist, and intrement the
system disk count.
-.It Fn disk_detatch
+.It Fn disk_detach
Detatch a disk; free storage for the disklabel, remove the disk
from the disklist, and decrement the system disk count. If the count
drops below zero, panic.
@@ -132,8 +139,7 @@ Increment the disk's
If this counter goes from 0 to 1, set the timestamp corresponding to
this transfer.
.It Fn disk_unbusy
-Decrement a disk's busy counter. If the count drops below zero, print
-a warning message.
+Decrement a disk's busy counter. If the count drops below zero, panic.
Get the current time, subtract it from the disk's timestamp, and add
the difference to the disk's running total. Set the disk's timestamp
to the current time. If the provided byte count is greater than 0,
@@ -148,7 +154,7 @@ or NULL if the disk does not exist.
.Pp
The functions typically called by device drivers are
.Fn disk_attach ,
-.Fn disk_detatch ,
+.Fn disk_detach ,
.Fn disk_busy ,
.Fn disk_unbusy ,
and
@@ -176,7 +182,7 @@ of the disk stucture, eg:
.Bd -literal
struct foo_softc {
struct device *sc_dev; /* generic device information */
- struct disk *sc_dk; /* generic disk information */
+ struct disk sc_dk; /* generic disk information */
[ . . . more . . . ]
};
.Ed
@@ -293,7 +299,7 @@ foodone(xfer)
[ . . . ]
/*
- * Get number of bytes transferred. If there is no buf
+ * Get number of bytes transfered. If there is no buf
* associated with the xfer, we are being called at the
* end of a non-I/O command.
*/
@@ -322,13 +328,20 @@ particular disk. For this function, the
.Fn disk_resetstat
routine is provided.
.Sh CODE REFERENCES
+This section describes places within the
+.Nx
+source tree where actual
+code implementing or utilizing the disk framework can be found. All
+pathnames are relative to
+.Pa /usr/src .
+.Pp
The disk framework itself is implemented within the file
.Pa sys/kern/subr_disk.c .
Data structures and function prototypes for the framework are located in
.Pa sys/sys/disk.h .
.Pp
-The
-.Ox
+The
+.Nx
machine-independent SCSI disk and CD-ROM drivers utilize the
disk framework. They are located in
.Pa sys/scsi/sd.c
@@ -336,7 +349,7 @@ and
.Pa sys/scsi/cd.c .
.Pp
The
-.Ox
+.Nx
.Nm ccd
and
.Nm vnd
@@ -346,17 +359,16 @@ They are located in
and
.Pa sys/dev/vnd.c .
.Sh AUTHOR
-The
-.Ox
-generic disk framework was architected and implemented within
+The
.Nx
-by Jason R. Thorpe <thorpej@NetBSD.ORG>.
+generic disk framework was architected and implemented by
+Jason R. Thorpe <thorpej@NetBSD.ORG>.
.Sh SEE ALSO
.Xr ccd 4 ,
.Xr vnd 4 ,
-.Xr spl 9 .
+.Xr spl 9
.Sh HISTORY
-The
-.Ox
-generic disk framework first appeared in
-.Nx at version 1.1A.
+The
+.Nx
+generic disk framework appeared in
+.Nx 1.2 .
diff --git a/share/man/man9/disklabel.9 b/share/man/man9/disklabel.9
new file mode 100644
index 00000000000..4c8e05167b5
--- /dev/null
+++ b/share/man/man9/disklabel.9
@@ -0,0 +1,191 @@
+.\" $OpenBSD: disklabel.9,v 1.1 1999/09/22 03:16:47 csapuntz Exp $
+.\" $NetBSD: disklabel.9,v 1.8 1999/03/16 00:40:47 garbled Exp $
+.\"
+.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Paul Kranenburg.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd December 26, 1996
+.Dt DISKLABEL 9
+.Os
+.Sh NAME
+.Nm disklabel ,
+.Nm readdisklabel ,
+.Nm writedisklabel ,
+.Nm setdisklabel ,
+.Nm bounds_check_with_label
+.Nd disk label management routines
+.Sh SYNOPSIS
+.Ft char *
+.Fn readdisklabel "dev_t dev" "void (*strat)(struct buf *)" "struct disklabel *lp" "struct cpu_disklabel *clp"
+.Ft int
+.Fn writedisklabel "dev_t dev" "void (*strat)(struct buf *)" "struct disklabel *lp" "struct cpu_disklabel *clp"
+.Ft int
+.Fn setdisklabel "struct disklabel *olp" "struct disklabel *nlp" "u_long openmask" "struct cpu_disklabel *clp"
+.Ft int
+.Fn bounds_check_with_label "struct buf *bp" "struct disklabel *lp" "int wlabel"
+.Sh DESCRIPTION
+This collection of routines provides a disklabel management interface to
+kernel device drivers.
+These routines are classified as machine- or architecture-dependent because
+of restrictions imposed by the machine architecture and boot-strapping code
+on the location of the label, or because cooperation with other operating
+systems requires specialized conversion code.
+.Pp
+.Fn readdisklabel
+attempts to read a disklabel from the device identified by
+.Fa dev ,
+using the device strategy routine passed in
+.Fa strat .
+Note that a buffer structure is required to pass to the strategy routine;
+it needs to be acquired and parametrized for the intended I/O operation,
+and disposed of when the operation has completed.
+Some fields in the in the disklabel passed in
+.Fa lp
+may be pre-initialized by the caller in order to meet device driver
+requirements for the I/O operation initiated to get to the disklabel data
+on the medium.
+In particular, the field
+.Dq d_secsize ,
+if non-zero, is used by
+.Fn readdisklabel
+to get an appropriately sized buffer to pass to the device strategy routine.
+Unspecified fields in
+.Fa lp
+should be set to zero.
+If the medium does not contain a native disklabel that can be read in directly,
+.Fn readdisklabel
+may resort to constructing a label from other machine-dependent information
+using the provided buffer passed in the
+.Fa clp
+argument.
+If a disk label can not be found or constructed, a string containing
+an approximated description of the failure mode is returned.
+Otherwise the
+.Dv NULL
+string is returned.
+.Pp
+.Fn writedisklabel
+stores disk label information contained in the disk label structure given by
+.Fa lp
+on the device identified by
+.Fa dev .
+Like
+.Fn readdisklabel ,
+it acquires and sets up an I/O buffer to pass to the strategy routine
+.Fa strat .
+.Fn writedisklabel
+may elect to do a machine-dependent conversion of the native disk label
+structure
+.Po
+using the buffer pointed at by
+.Fa clp
+.Pc ,
+to store the disk label onto the medium in a format complying with
+architectural contraints.
+.Fn writedisklabel
+returns 0 on success and
+.Dv EINVAL
+if the disk label specifies invalid or unconvertable values.
+Otherwise, any error condition reported by the device strategy routine
+in the buffer's
+.Dq Va b_error
+field is returned.
+.Pp
+.Fn setdisklabel
+checks a proposed new disk label passed in
+.Fa nlp
+for some amount of basic sanity.
+This includes a check on attempts to
+change the location, or reduce the size, of an existing disk partition
+that is currently in use by the system.
+The current disposition of the disk partitions is made available through
+.Fa olp
+and
+.Fa openmask ,
+which provide, respectively, the existing disk label and a bit mask
+identifying the partitions that are currently in use.
+Failure to pass on
+.Dq basic sanity ,
+results in a
+.Dv EINVAL
+return value, while a vetoed update of the partition layout is signaled by a
+.Dv EBUSY
+return value.
+Otherwise, 0 is returned.
+.Pp
+.Fn bounds_check_with_label
+is used to check whether a device transfer described by
+.Fa bp
+to the device identified by
+.Fa dev ,
+is properly contained within a disk partition of the disk with label
+.Fa lp .
+If this check fails,
+.Fn bounds_check_with_label
+sets the buffer's
+.Dq Va b_error
+field to
+.Dv EINVAL ,
+sets the
+.Dv B_ERROR
+flag in
+.Dq Va b_flags ,
+and returns -1.
+If the argument
+.Fa wlabel
+is zero, and the transfer is a write operation, a check is done if the transfer
+would overwrite
+.Pq a portion of
+the disklabel area on the medium.
+If that is the case,
+.Dv EROFS
+is set in
+.Dq Va b_error ,
+the
+.Dv B_ERROR
+flag is set in
+.Dq Va b_flags ,
+and -1 is returned.
+Note that
+.Fa wlabel
+should be set to a non-zero value if the intended operation is expected to
+install or update the disk label.
+Programs that intend to do so using the raw device interface should notify
+the driver by using a
+.Dv DIOCWLABEL
+ioctl function.
+.Pp
+.Sh SEE ALSO
+.Xr disklabel 5 ,
+.Xr disklabel 8
diff --git a/share/man/man9/ethersubr.9 b/share/man/man9/ethersubr.9
new file mode 100644
index 00000000000..8f30c9f0094
--- /dev/null
+++ b/share/man/man9/ethersubr.9
@@ -0,0 +1,195 @@
+.\" $OpenBSD: ethersubr.9,v 1.1 1999/09/22 03:16:47 csapuntz Exp $
+.\" $NetBSD: ethersubr.9,v 1.10 1999/03/16 00:40:47 garbled Exp $
+.\"
+.\" Copyright (c) 1997 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Ignatios Souvatzis.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd March 3, 1997
+.Dt ETHERSUBR 9
+.Os
+.Sh NAME
+.Nm ethersubr ,
+.Nm ether_ifattach ,
+.Nm ether_addmulti ,
+.Nm ether_delmulti ,
+.Nm ETHER_FIRST_MULTI ,
+.Nm ETHER_NEXT_MULTI ,
+.Nm ETHER_IS_MULTICAST ,
+.Nm fddi_ifattach ,
+.Nm fddi_addmulti ,
+.Nm fddi_delmulti
+.Nd Ethernet and FDDI driver support functions and macros
+.Sh SYNOPSIS
+.Fd #include <net/if_ether.h>
+.Ft void
+.Fn ether_ifattach "struct ifnet *ifp" "u_int8_t *lla"
+.Ft int
+.Fn ether_addmulti "struct ifrequest *ifr" "struct ethercom *ec"
+.Ft int
+.Fn ether_delmulti "struct ifrequest *ifr" "struct ethercom *ec"
+.Ft void
+.Fn ETHER_FIRST_MULTI "struct ether_multistep step" "struct ethercom *ec" "struct ether_multi *enm"
+.Ft void
+.Fn ETHER_NEXT_MULTI "struct ether_multistep step" "struct ether_multi *enm"
+.Ft int
+.Fn ETHER_IS_MULTICAST "u_int8_t *addr"
+.Fd #include <net/if_fddi.h>
+.Ft void
+.Fn fddi_ifattach "struct ifnet *ifp" "u_int8_t *lla"
+.Ft int
+.Fn fddi_addmulti "struct ifrequest *ifr" "struct ethercom *ec"
+.Ft int
+.Fn fddi_delmulti "struct ifrequest *ifr" "struct ethercom *ec"
+.Sh DESCRIPTION
+The
+.Nm
+functions provide the interface between the
+.Nm
+module and the network drivers which need Ethernet support.
+Such drivers must request the
+.Ar ether
+attribute in their
+.Ar files
+declaration and call the appropriate functions as specified below.
+.Pp
+FDDI drivers must request the "fddi" attribute in their "files"
+declaration and call the functions tagged with "fddi_" or "FDDI_"
+instead, where different.
+Some macros are shared.
+.Pp
+Note that you also need the
+.Xr arp 9
+stuff to support IPv4 on your hardware.
+.Bl -tag -width compact
+.It Fn ether_ifattach
+Perform the device-independent, but Ethernet-specific initialization of
+the interface pointed to by
+.Fa ifp .
+.Pp
+Among other duties, this function creates a record for the link level
+address in the interface's address list and records the link level address
+pointed to by
+.Fa lla
+there.
+.Pp
+You must call this function from the driver's attach function.
+.It Fn fddi_ifattach
+corresponding function for FDDI devices.
+.It Fn ether_addmulti
+.It Fn ether_delmulti
+Add
+.Pq Fn ether_addmulti
+or delete
+.Pq Fn ether_delmulti
+the address described by the
+.Fa ifr
+pointer to the Ethernet multicast list belonging to
+.Fa ec .
+.Pp
+These functions must be called from the driver's ioctl function to
+handle
+.Dv SIOCADDMULTI
+and
+.Dv SIOCDELMULTI
+requests.
+If they return
+.Er ENETRESET ,
+the hardware multicast filter must be reinitialized.
+.Pp
+These functions accept
+.Dv AF_UNSPEC
+addresses, which are interpreted as Ethernet addresses, or
+.Dv AF_INET
+addresses.
+In the latter case,
+.Dv INADDR_ANY
+is mapped to a range describing all the Ethernet address
+space reserved for IPv4 multicast addresses.
+.Pp
+.Fn ether_addmulti
+returns
+.Er EAFNOSUPPORT
+if an unsupported address family is specified,
+.Er EINVAL
+if a non-multicast address is specified, or
+.Er ENETRESET
+if
+the multicast list really changed and the driver should synchronize
+its hardware filter with it.
+.Pp
+.Fn ether_delmulti
+returns, in addition to the above errors,
+.Er ENXIO
+if the specified address
+can't be found in the list of multicast addresses.
+.It Fn fddi_addmulti
+.It Fn fddi_delmulti
+corresponding functions for FDDI devices.
+.It Fn ETHER_NEXT_MULTI
+is a macro to step through all of the ether_multi records, one at a time.
+The current position is remembered in
+.Fa step ,
+which the caller must provide.
+.It Fn ETHER_FIRST_MULTI
+must be called to initialize
+.Fa step
+and get the first record. Both macros return a
+.Dv NULL
+.Fa enm
+when there are no remaining records.
+.It Fn ETHER_IS_MULTICAST
+returns 1, if
+.Fa addr
+points to an Ethernet/FDDI multicast (or broadcast) address.
+Implemented as a macro.
+.El
+.Sh SEE ALSO
+.Xr arp 9
+.Sh AUTHORS
+UCB CSRG (original implementation)
+.br
+Ignatios Souvatzis (support for new ARP system)
+.Sh CODE REFERENCES
+Ethernet support functions are declared in
+.Aq Pa net/if_ether.h
+and defined (if not implemented as macro) in
+.Pa /usr/src/sys/net/if_ethersubr.c .
+.Pp
+FDDI support functions are declared in
+.Aq Pa net/if_fddi.h
+and defined (if not implemented as macro) in
+.Pa /usr/src/sys/net/if_fddisubr.c .
+.Sh HISTORY
+Rewritten to attach to the new ARP system in
+.Nx 1.3 .
diff --git a/share/man/man9/extent.9 b/share/man/man9/extent.9
index eb6ccd14529..c081e0e479d 100644
--- a/share/man/man9/extent.9
+++ b/share/man/man9/extent.9
@@ -1,4 +1,4 @@
-.\" $OpenBSD: extent.9,v 1.1 1999/09/05 16:23:11 espie Exp $
+.\" $OpenBSD: extent.9,v 1.2 1999/09/22 03:16:47 csapuntz Exp $
.\" $NetBSD: extent.9,v 1.15 1999/03/16 00:40:47 garbled Exp $
.\"
.\" Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
@@ -39,6 +39,7 @@
.Dt EXTENT 9
.Os
.Sh NAME
+.Nm extent ,
.Nm extent_create ,
.Nm extent_destroy ,
.Nm extent_alloc ,
@@ -59,17 +60,34 @@
.Ft int
.Fn extent_alloc_subregion "struct extent *ex" "u_long substart" "u_long subend" "u_long size" "u_long alignment" "u_long boundary" "u_long flags" "u_long *result"
.Ft int
+.Fn extent_alloc1 "struct extent *ex" "u_long size" "u_long alignment" "u_long skew" "u_long boundary" "int flags" "u_long *result"
+.Ft int
+.\" too many arguments for a single .Fn
+.Fo extent_alloc_subregion1
+.Fa "struct extent *ex"
+.Fa "u_long substart"
+.Fa "u_long subend"
+.Fa "u_long size"
+.Fa "u_long alignment"
+.Fa "u_long skew"
+.Fa "u_long boundary"
+.Fa "u_long flags"
+.Fa "u_long *result"
+.Fc
+.Ft int
.Fn extent_alloc_region "struct extent *ex" "u_long start" "u_long size" "int flags"
.Ft int
.Fn extent_free "struct extent *ex" "u_long start" "u_long size" "int flags"
.Ft void
.Fn extent_print "struct extent *ex"
.Sh DESCRIPTION
-The extent manager provides management of areas of memory or
-other enumerable spaces (such as I/O ports). An opaque structure
+The
+.Nx
+extent manager provides management of areas of memory or
+other number spaces (such as I/O ports). An opaque structure
called an
.Nm extent map
-keeps track of allocated regions within the enumerable space.
+keeps track of allocated regions within the number space.
.Pp
.Fn extent_create
creates an extent map managing the space from
@@ -84,17 +102,20 @@ see
.Pc .
The extent map will have the name
.Fa name ,
-used for identification in case of errors or in
-.Xr ddb 4
-.Ic show extents .
-If the flag
+used for identification in case of an error. If the flag
.Dv EX_NOCOALESCE
-is set, internal coalescing of regions is disabled,
-and only entire regions may be freed within the extent map, so that
+is specified, only entire regions may be freed within the extent map,
+but internal coalescing of regions is disabled so that
.Fn extent_free
-will never have to allocate a region descriptor.
+will never have to allocate a region descriptor and therefore will
+never fail. The caller must specify one of the flags
+.Dv EX_NOWAIT
+or
+.Dv EX_WAITOK ,
+specifying whether it is okay to wait for memory allocated for
+extent map overhead.
.Pp
-Some applications may want to use an extent map but
+There are some applications which may want to use an extent map but
can't use
.Fn malloc
and
@@ -117,27 +138,10 @@ A fixed extent has a fixed number of region descriptors, so care
should be taken to provide enough storage for them; alternatively, the
flag
.Dv EX_MALLOCOK
-may be passed to extent requests to indicate that a fixed extent
+may be passed to allocation requests to indicate that a fixed extent
map may be extended using a call to
.Fn malloc .
.Pp
-The caller should pass the flag
-.Dv EX_WAITOK
-or
-.Dv EX_NOWAIT
-to extent functions that have a memory overhead, to specify whether
-it is okay to wait. These functions are
-.Fn extent_create
-(non fixed extents),
-.Fn extent_free
-(unless
-.Dv EX_NOCOALESCE
-is set),
-.Fn extent_alloc ,
-.Fn extent_alloc_subregion
-and
-.Fn extent_alloc_region .
-.Pp
.Fn extent_destroy
destroys the extent map
.Fa ex ,
@@ -146,7 +150,7 @@ the region and internal extent descriptors themselves are freed.
This function always succeeds.
.Pp
.Fn extent_alloc
-allocates a region in the extent map
+allocates a region in extent
.Fa ex
of size
.Fa size
@@ -156,53 +160,55 @@ policies, which are selected by the
argument:
.Bl -tag -offset indent -width "XXXXXXXXX"
.It Dv EX_FAST
-Allocate the first region that fits the provided parameters, regardless
+Allocate the first region that fits the provided paramters, regardless
of resulting extent fragmentation.
.It default
Allocate the smallest region that is capable of holding the request,
thus minimizing fragmentation of the extent.
.El
.Pp
-The caller may specify that it is okay to wait for space to become free in the
-extent by setting the flag
+The caller must specify if waiting for space in the extent is allowed
+using the flag
.Dv EX_WAITSPACE .
If
.Dv EX_WAITSPACE
-is not set, the allocation will fail if the request can not be
+is not specified, the allocation will fail if the request can not be
satisfied without sleeping.
-.Pp
-The request will be aligned to a multiple of
-.Fa alignment .
-That value must be a power of 2. If no alignment
-is necessary, the value
-.Dv EX_NOALIGN
-should be specified. If
+The caller must also specify, using the
+.Dv EX_NOWAIT
+or
+.Dv EX_WAITOK
+flags, if waiting for overhead allocation is allowed.
+The request will be aligned to
+.Fa alignment
+boundaries. Alignment values must be a power of 2. If no alignment
+is necessary, the value 1 should be specified. If
.Fa boundary
-is not
-.Dv EX_NOBOUNDARY ,
-the allocated region will not cross any boundary lines, spaced
-.Fa boundary
-apart. If the caller specifies the
+is nonzero, the allocated region will not cross any of the numbers
+which are a multiple of
+.Fa boundary .
+If the caller specifies the
.Dv EX_BOUNDZERO
-flag, boundary lines begin at zero. Otherwise, boundary lines
+flag, the boundary lines begin at zero. Otherwise, the boundary lines
begin at the beginning of the extent. The allocated region may begin on a
-boundary line, but the end of the region will not touch nor cross a
-boundary line. A
-.Fa boundary
-argument smaller than the size of the request is
+boundary address, but the end of the region will not touch nor cross
+it. A boundary argument smaller than the size of the request is
invalid. Upon successful completion,
.Fa *result
will contain the start of the allocated region.
.Pp
.Fn extent_alloc_subregion
-is a generalized version of
-.Fn extent_alloc
-that also allows the caller to specify that the allocated region must
+is similar to
+.Fn extent_alloc ,
+but it allows the caller to specify that the allocated region must
fall within the subregion from
.Fa substart
to
.Fa subend
-inclusive.
+inclusive. The other arguments and the return values of
+.Fn extent_alloc_subregion
+are otherwise the same as those of
+.Fn extent_alloc .
.Pp
.Fn extent_alloc_region
allocates the specific region in the extent map
@@ -211,32 +217,73 @@ beginning at
.Fa start
with the size
.Fa size .
-The caller may specify that it is okay to wait for the indicated
-region to be free by setting the flag
+The caller must specify whether it is okay to wait for the indicated
+region to be free using the flag
.Dv EX_WAITSPACE .
If
.Dv EX_WAITSPACE
-is not set, the allocation will fail if the request can not be
+is not specified, the allocation will fail if the request can not be
satisfied without sleeping.
+The caller must also specify, using the
+.Dv EX_NOWAIT
+or
+.Dv EX_WAITOK
+flags, if waiting for overhead allocation is allowed.
+.Pp
+The
+.Fn extent_alloc1
+and
+.Fn extent_alloc_subregion1
+functions are extensions that take one additional argument,
+.Fa skew ,
+that modifies the requested alignment result in the following way:
+the value
+.Po Fa result
+\& -
+.Fa skew
+.Pc
+is aligned to
+.Fa alignment
+boundaries.
+.Fa skew
+must be a smaller number than
+.Fa alignment .
+Also, a boundary argument smaller than the sum of the requested skew
+and the size of the request is invalid.
.Pp
.Fn extent_free
frees a region of
.Fa size
-bytes starting at
-.Fa start
-in the extent map
-.Fa ex .
+bytes in extent
+.Fa ex
+starting at
+.Fa start .
If the extent has the
.Dv EX_NOCOALESCE
property, only entire regions may be freed. If the extent has the
.Dv EX_NOCOALESCE
property and the caller attempts to free a partial region, behavior is
-undefined.
+undefined. The caller must specify one of the flags
+.Dv EX_NOWAIT
+or
+.Dv EX_WAITOK
+to specify whether waiting for memory is okay; these flags have
+meaning in the event that allocation of a region descriptor is
+required during the freeing process. This situation occurs only when
+a partial region that begins and ends in the middle of another region
+is freed. Behavior is undefined if invalid arguments are provided.
.Pp
.Fn extent_print
-Prints out information about extent
+Print out information about extent
.Fa ex .
-This function always succeeds.
+This function always succeeds. Behavior is undefined if invalid
+arguments are provided.
+.Sh LOCKING
+The extent manager performs all necessary locking on the extent map
+itself, and any other data structures internal to the extent manager.
+The locks used by the extent manager are spin locks, and will never sleep.
+This should be taken into account when designing the locking protocol
+for users of the extent manager.
.Sh RETURN VALUES
The behavior of all extent manager functions is undefined if given
invalid arguments.
@@ -267,7 +314,8 @@ Requested region is not available and
was not specified.
.It Dv EINTR
Process received a signal while waiting for the requested region to
-become available in the extent.
+become available in the extent. Does not apply to
+.Fn extent_free .
.El
.Sh EXAMPLES
Here is an example of a (useless) function that uses several of the
@@ -304,31 +352,34 @@ func()
extent_destroy(foo_ex);
}
.Ed
-.\"
-.\" Yeah, right... document EX_CATCH first...
-.\"
-.\" .Sh LIMITATIONS
-.\" The flag
-.\" .Dv EX_CATCH
-.\" cannot be used to catch signals in all circumstances since
-.\" .Xr malloc 9
-.\" does not provide such a functionality.
.Sh CODE REFERENCES
+This section describes places within the
+.Nx
+source tree where
+actual code implementing or using the extent manager can be found.
+All pathnames are relative to
+.Pa /usr/src .
+.Pp
The extent manager itself is implemented within the file
.Pa sys/kern/subr_extent.c .
+Function prototypes for the framework are located in
+.Pa sys/sys/extent.h .
.Pp
The i386 bus management code uses the extent manager for managing I/O
-ports and I/O memory. See
+ports and I/O memory. This code is in the file
.Pa sys/arch/i386/i386/machdep.c .
.Sh AUTHOR
-The extent manager was designed and implemented by Jason
+The
+.Nx
+extent manager was architected and implemented by Jason
R. Thorpe <thorpej@NetBSD.ORG>. Matthias Drochner
<drochner@zelux6.zel.kfa-juelich.de> contributed to the initial
testing and optimization of the implementation. Chris Demetriou
<cgd@NetBSD.ORG> contributed many architectural suggestions.
.Sh SEE ALSO
-.Xr ddb 4 ,
.Xr malloc 9
.Sh HISTORY
-The extent manager appeared in
+The
+.Nx
+extent manager appeared in
.Nx 1.3 .
diff --git a/share/man/man9/log.9 b/share/man/man9/log.9
index 0ffa285336b..a1ad9d8fada 100644
--- a/share/man/man9/log.9
+++ b/share/man/man9/log.9
@@ -1,3 +1,4 @@
+.\" $OpenBSD: log.9,v 1.2 1999/09/22 03:16:47 csapuntz Exp $
.\" $NetBSD: log.9,v 1.6 1999/08/17 05:24:06 enami Exp $
.\"
.\" Copyright (c) 1997 The NetBSD Foundation, Inc.
diff --git a/share/man/man9/man9.i386/Makefile b/share/man/man9/man9.i386/Makefile
new file mode 100644
index 00000000000..e66aeb85815
--- /dev/null
+++ b/share/man/man9/man9.i386/Makefile
@@ -0,0 +1,7 @@
+# $OpenBSD: Makefile,v 1.1 1999/09/22 03:16:47 csapuntz Exp $
+# $NetBSD: Makefile,v 1.1 1998/10/01 02:33:50 jtk Exp $
+
+MAN= bioscall.9
+MANSUBDIR=/i386
+
+.include <bsd.prog.mk>
diff --git a/share/man/man9/man9.i386/bioscall.9 b/share/man/man9/man9.i386/bioscall.9
new file mode 100644
index 00000000000..75977bced73
--- /dev/null
+++ b/share/man/man9/man9.i386/bioscall.9
@@ -0,0 +1,123 @@
+.\" $OpenBSD: bioscall.9,v 1.1 1999/09/22 03:16:48 csapuntz Exp $
+.\" $NetBSD: bioscall.9,v 1.1 1998/10/01 02:33:51 jtk Exp $
+.\"
+.\" Copyright (c) 1998 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by John Kohl.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd October 1, 1998
+.Dt BIOSCALL 9 i386
+.Os NetBSD
+.Sh NAME
+.Nm bioscall
+.Nd call system BIOS function from real mode
+.Sh SYNOPSIS
+.Fd #include <i386/bioscall.h>
+.Ft void
+.Fn bioscall "int function" "struct bioscallregs *regs"
+.Sh DESCRIPTION
+The
+.Nm
+function switches the processor into real mode, calls the BIOS interrupt
+numbered
+.Fa function ,
+and returns to protected mode.
+.Pp
+This function is intended to be called during the initial system
+bootstrap when necessary to probe devices or pseudo-devices.
+.Pp
+The register values specified by
+.Fa *regs
+(with one exception) are installed before the BIOS interrupt is called.
+The processor flags are handled specially. Only the following flags are
+passed to the
+BIOS from the registers in
+.Fa regs
+(the remainder come from the processor's flags register at the time
+of the call):
+.Ar PSL_C ,
+.Ar PSL_PF ,
+.Ar PSL_AF ,
+.Ar PSL_Z ,
+.Ar PSL_N ,
+.Ar PSL_D ,
+.Ar PSL_V .
+.Pp
+The
+.Va bioscallregs
+structure is defined to contain structures for each register, to allow
+access to 32-, 16- or 8-bit wide sections of the registers.
+Definitions are provided which simplify access to the union members.
+.Sh RETURN VALUE
+.Nm
+fills in
+.Fa *regs
+with the processor registers as returned from the BIOS call.
+.Sh EXAMPLES
+The Advanced Power Management driver calls
+.Nm
+by setting up a register structure with the APM installation check and
+device types in registers
+.Fa ax
+and
+.Fa bx ,
+then calls the BIOS to fetch the details for calling the APM support
+through a protected-mode interface. The BIOS returns these details in
+the registers:
+.Pp
+.Bd -literal
+#include <i386/bioscall.h>
+#include <i386/apmvar.h>
+struct bioscallregs regs;
+
+regs.AX = APM_BIOS_FN(APM_INSTALLATION_CHECK);
+regs.BX = APM_DEV_APM_BIOS;
+regs.CX = regs.DX = 0;
+regs.ESI = regs.EDI = regs.EFLAGS = 0;
+bioscall(APM_SYSTEM_BIOS, &regs);
+.Ed
+.Pp
+.Sh CODE REFERENCES
+.Pa sys/arch/i386/i386/bioscall.s ,
+.Pa sys/arch/i386/bioscall/biostramp.S
+.Sh REFERENCES
+.Xr apm 4
+.Sh HISTORY
+.Nm
+first appeared in NetBSD-1.3.
+.Sh BUGS
+Not all BIOS functions are safe to call through the trampoline, as they
+may depend on system state which has been disturbed or used for other
+purposes once the
+.Nx
+kernel is running.
diff --git a/share/man/man9/mbuf.9 b/share/man/man9/mbuf.9
new file mode 100644
index 00000000000..c8be7c4f9a3
--- /dev/null
+++ b/share/man/man9/mbuf.9
@@ -0,0 +1,574 @@
+.\" $OpenBSD: mbuf.9,v 1.1 1999/09/22 03:16:47 csapuntz Exp $
+.\" $NetBSD: mbuf.9,v 1.7 1999/03/16 00:40:47 garbled Exp $
+.\"
+.\" Copyright (c) 1997 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This documentation is derived from text contributed to The NetBSD Foundation
+.\" by S.P.Zeidler (aka stargazer).
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd October 3, 1997
+.Dt MBUF 9
+.Os
+.Sh NAME
+.Nm mbuf ,
+.Nm m_get ,
+.Nm m_getclr ,
+.Nm m_gethdr ,
+.Nm m_devget ,
+.Nm m_copym ,
+.Nm m_copypacket ,
+.Nm m_copydata ,
+.Nm m_copyback ,
+.Nm m_cat ,
+.Nm m_prepend ,
+.Nm m_pullup ,
+.Nm m_split ,
+.Nm m_adj ,
+.Nm m_free ,
+.Nm m_freem ,
+.Nm mtod ,
+.Nm mtocl ,
+.Nm cltom ,
+.Nm MGET ,
+.Nm MGETHDR ,
+.Nm MEXTMALLOC ,
+.Nm MEXTADD ,
+.Nm MCLGET ,
+.Nm M_COPY_PKTHDR ,
+.Nm M_ALIGN ,
+.Nm MH_ALIGN ,
+.Nm M_LEADINGSPACE ,
+.Nm M_TRAILINGSPACE ,
+.Nm M_PREPEND ,
+.Nm MCHTYPE ,
+.Nm MEXTREMOVE ,
+.Nm MFREE ,
+.Nd functions and macros for managing memory used by networking code
+.Sh SYNOPSIS
+.Fd #include <sys/mbuf.h>
+.Ft struct mbuf *
+.Fn m_get "int nowait" "int type"
+.Ft struct mbuf *
+.Fn m_getclr "int nowait" "int type"
+.Ft struct mbuf *
+.Fn m_gethdr "int nowait" "int type"
+.Ft struct mbuf *
+.Fn m_devget "char *buf" "int totlen" "int off0" "struct ifnet *ifp" "void (*copy) __P((const void *, void *, size_t))"
+.Ft struct mbuf *
+.Fn m_copym "struct mbuf *m" "int off0" "int len" "int wait"
+.Ft struct mbuf *
+.Fn m_copypacket "struct mbuf *m" "int how"
+.Ft void
+.Fn m_copydata "struct mbuf *m" "int off" "int len" "caddr_t cp"
+.Ft void
+.Fn m_copyback "struct mbuf *m0" "int off" "int len" "caddr_t cp"
+.Ft void
+.Fn m_cat "struct mbuf *m" "struct mbuf *n"
+.Ft struct mbuf *
+.Fn m_prepend "struct mbuf *m" "int len" "int how"
+.Ft struct mbuf *
+.Fn m_pullup "struct mbuf *n" "int len"
+.Ft struct mbuf *
+.Fn m_split "struct mbuf *m0" "int len0" "int wait"
+.Ft void
+.Fn m_adj "struct mbuf *mp" "int req_len"
+.Ft struct mbuf *
+.Fn m_free "struct mbuf *m"
+.Ft void
+.Fn m_freem "struct mbuf *m"
+.Ft int
+.Fn mtod "struct mbuf *m" "datatype"
+.Ft u_long
+.Fn mtocl "void *datapointer"
+.Ft caddr_t
+.Fn cltom "u_long clusternum"
+.Ft void
+.Fn MGET "struct mbuf *m" "int how" "int type"
+.Ft void
+.Fn MGETHDR "struct mbuf *m" "int how" "int type"
+.Ft void
+.Fn MEXTMALLOC "struct mbuf *m" "int len" "int how"
+.Ft void
+.Fn MEXTADD "struct mbuf *m" "caddr_t buf" "int type" "void (*free) __P((caddr_t, u_int, void *))" "void *arg"
+.Ft void
+.Fn MCLGET "struct mbuf *m" "int how"
+.Ft void
+.Fn M_COPY_PKTHDR "struct mbuf *to" "struct mbuf *from"
+.Ft void
+.Fn M_ALIGN "struct mbuf *m" "int len"
+.Ft void
+.Fn MH_ALIGN "struct mbuf *m" "int len"
+.Ft int
+.Fn M_LEADINGSPACE "struct mbuf *m"
+.Ft int
+.Fn M_TRAILINGSPACE "struct mbuf *m"
+.Ft void
+.Fn M_PREPEND "struct mbuf *m" "int plen" "int how"
+.Ft void
+.Fn MCHTYPE "struct mbuf *m" "int type"
+.Ft void
+.Fn MEXTREMOVE "struct mbuf *m"
+.Ft void
+.Fn MFREE "struct mbuf *m" "struct mbuf *n"
+.Sh DESCRIPTION
+The
+.Nm
+functions and macros provide an easy and consistent way to handle
+a networking stack's memory management needs.
+An
+.Nm mbuf
+consists of a header and a data area.
+It is of a fixed size,
+.Dv MSIZE
+.Pq defined in Aq Pa machine/param.h ,
+which includes overhead.
+The header contains a pointer to the next
+.Nm mbuf
+in the
+.Nm mbuf chain ,
+a pointer to the next
+.Nm mbuf chain ,
+a pointer to the data area, the amount of data in this mbuf, its type
+and a
+.Dv flags
+field.
+.Pp
+The
+.Dv type
+variable can signify:
+.Bl -tag -compact -offset indent -width "XXXXXXXXXXX"
+.It Dv MT_FREE
+the mbuf should be on the ``free'' list
+.It Dv MT_DATA
+data was dynamically allocated
+.It Dv MT_HEADER
+data is a packet header
+.It Dv MT_SONAME
+data is a socket name
+.It Dv MT_SOOPTS
+data is socket options
+.It Dv MT_FTABLE
+data is the fragment reassembly header
+.It Dv MT_CONTROL
+mbuf contains ancillary \&(protocol control\&) data
+.It Dv MT_OOBDATA
+mbuf contains out-of-band data.
+.El
+.Pp
+The
+.Dv flags
+variable contains information describing the
+.Nm mbuf ,
+notably:
+.Bl -tag -compact -offset indent -width "XXXXXXXXXXX"
+.It Dv M_EXT
+has external storage
+.It Dv M_PKTHDR
+is start of record
+.It Dv M_EOR
+is end of record
+.It Dv M_CLUSTER
+external storage is a cluster.
+.El
+.Pp
+If an
+.Nm mbuf
+designates the start of a record
+.Pq Dv M_PKTHDR ,
+its
+.Dv flags
+field may contain additional information describing the content of
+the record:
+.Bl -tag -compact -offset indent -width "XXXXXXXXXXX"
+.It Dv M_BCAST
+sent/received as link-level broadcast
+.It Dv M_MCAST
+sent/received as link-level multicast
+.It Dv M_LINK0 , M_LINK1, MLINK2
+three link-level specific flags.
+.El
+.Pp
+An
+.Nm mbuf
+may add a single
+.Nm mbuf cluster
+of
+.Dv MCLBYTES
+bytes
+.Pq also defined in Aq Pa machine/param.h ,
+which has no additional overhead
+and is used instead of the internal data area; this is done when at least
+.Dv MINCLSIZE
+bytes of data must be stored.
+.Bl -tag -width compact
+.It Fn m_get "int nowait" "int type"
+Allocates an mbuf and initializes it to contain internal data.
+The
+.Fa nowait
+parameter is a choice of
+.Dv M_WAIT / M_DONTWAIT
+from caller.
+.Dv M_WAIT
+means the call cannot fail, but may take forever.
+The
+.Fa type
+parameter is an mbuf type.
+.It Fn m_getclr "int nowait" "int type"
+Allocates an mbuf and initializes it to contain internal data, then
+zeros the data area.
+The
+.Fa nowait
+parameter is a choice of
+.Dv M_WAIT / M_DONTWAIT
+from caller.
+The
+.Fa type
+parameter is an mbuf type.
+.It Fn m_gethdr "int nowait" "int type"
+Allocates an mbuf and initializes it to contain a packet header and internal
+data.
+The
+.Fa nowait
+parameter is a choice of
+.Dv M_WAIT / M_DONTWAIT
+from caller.
+The
+.Fa type
+parameter is an mbuf type.
+.It Fn m_devget "char *buf" "int totlen" "int off0" "struct ifnet *ifp" "void (*copy) __P((const void *, void *, size_t))"
+Copies
+.Fa len
+bytes from device local memory into mbufs using copy routine
+.Fa copy .
+If parameter
+.Fa off
+is non-zero, the packet is supposed to be trailer-encapsulated and
+.Fa off
+bytes plus the type and length fields will be skipped before copying.
+Returns the top of the mbuf chain it created.
+.It Fn m_copym "struct mbuf *m" "int off0" "int len" "int wait"
+Creates a copy of an mbuf chain starting
+.Fa off0
+bytes from the beginning, continuing for
+.Fa len
+bytes. If the
+.Fa len
+requested is
+.Dv M_COPYALL ,
+the complete mbuf chain will be copied.
+The
+.Fa wait
+parameter is a choice of
+.Dv M_WAIT / M_DONTWAIT
+from caller.
+.It Fn m_copypacket "struct mbuf *m" "int how"
+Copies an entire packet, including header (which must be present).
+This function is an optimization of the common case
+.Li m_copym(m, 0, Dv M_COPYALL, Fa how ) .
+.It Fn m_copydata "struct mbuf *m" "int off" "int len" "caddr_t cp"
+Copies
+.Fa len
+bytes data from mbuf chain
+.Fa m
+into the buffer
+.Fa cp ,
+starting
+.Fa off
+bytes from the beginning.
+.It Fn m_copyback "struct mbuf *m0" "int off" "int len" "caddr_t cp"
+Copies
+.Fa len
+bytes data from buffer
+.Fa cp
+back into the mbuf chain
+.Fa m0 ,
+starting
+.Fa off
+bytes from the beginning, extending the mbuf chain if necessary.
+.It Fn m_cat "struct mbuf *m" "struct mbuf *n"
+Concatenates mbuf chain
+.Fa n
+to
+.Fa m .
+Both chains must be of the same type; packet headers will
+.Em not
+be updated if present.
+.It Fn m_prepend "struct mbuf *m" "int len" "int how"
+Lesser-used path for
+.Fn M_PREPEND :
+allocates new mbuf
+.Fa m
+of size
+.Fa len
+to prepend to the chain, copying junk along.
+The
+.Fa how
+parameter is a choice of
+.Dv M_WAIT / M_DONTWAIT
+from caller.
+.It Fn m_pullup "struct mbuf *m" "int len"
+Rearranges an mbuf chain so that
+.Fa len
+bytes are contiguous
+and in the data area of an mbuf (so that
+.Fn mtod
+will work for a structure of size
+.Fa len ) .
+Returns the resulting
+mbuf chain on success, frees it and returns
+.Dv NULL
+on failure.
+If there is room, it will add up to
+.Dv max_protohdr
+-
+.Fa len
+extra bytes to the
+contiguous region to possibly avoid being called again.
+.It Fn m_split "struct mbuf *m0" "int len0" "int wait"
+Partitions an mbuf chain in two pieces, returning the tail,
+which is all but the first
+.Fa len0
+bytes. In case of failure, it returns
+.Dv NULL
+and attempts to
+restore the chain to its original state.
+.It Fn m_adj "struct mbuf *mp" "int req_len"
+Shaves off
+.Fa req_len
+bytes from head or tail of the (valid) data area.
+If
+.Fa req_len
+is greater than zero, front bytes are being shaved off, if it's smaller,
+from the back (and if it is zero, the mbuf will stay bearded).
+This function does not move data in any way, but is used to manipulate the
+data area pointer and data length variable of the mbuf in a non-clobbering
+way.
+.It Fn m_free "struct mbuf *m"
+Frees mbuf
+.Fa m .
+.It Fn m_freem "struct mbuf *m"
+Frees the mbuf chain beginning with
+.Fa m .
+This function contains the elementary sanity check for a
+.Dv NULL
+pointer.
+.It Fn mtod "struct mbuf *m" "datatype"
+Returns a pointer to the data contained in the specified mbuf
+.Fa m ,
+type-casted to the specified data type
+.Fa datatype .
+Implemented as a macro.
+.It Fn mtocl "void *datapointer"
+Takes a
+.Fa datapointer
+within an mbuf cluster and returns the cluster index number of the mbuf
+owning the data.
+Avoid this; it may be deprecated in the future.
+Implemented as a macro.
+.It Fn cltom "u_long clusternum"
+Takes an mbuf cluster index number
+.Fa clusternum
+and returns a pointer to the beginning of the cluster.
+Avoid this; it may be deprecated in the future.
+Implemented as a macro.
+.It Fn MGET "struct mbuf *m" "int how" "int type"
+Allocates mbuf
+.Fa m
+and initializes it to contain internal data.
+See
+.Fn m_get .
+Implemented as a macro.
+.It Fn MGETHDR "struct mbuf *m" "int how" "int type"
+Allocates mbuf
+.Fa m
+and initializes it to contain a packet header.
+See
+.Fn m_gethdr .
+Implemented as a macro.
+.It Fn MEXTMALLOC "struct mbuf *m" "int len" "int how"
+Allocates external storage of size
+.Fa len
+for mbuf
+.Fa m .
+The
+.Fa how
+parameter is a choice of
+.Dv M_WAIT / M_DONTWAIT
+from caller.
+The flag
+.Dv M_EXT
+is set upon success.
+Implemented as a macro.
+.It Fn MEXTADD "struct mbuf *m" "caddr_t buf" "int type" "void (*free) __P((caddr_t, u_int, void *))" "void *arg"
+Adds pre-allocated external storage
+.Fa buf
+to a normal mbuf
+.Fa m ;
+the parameters
+.Fa type ,
+.Fa free
+and
+.Fa arg
+describe the external storage.
+.Fa type
+describes the
+.Xr malloc 9
+type of the storage,
+.Fa free
+is a free routine (if not the usual one), and
+.Fa arg
+is a possible argument to the free routine.
+The flag
+.Dv M_EXT
+is set upon success.
+Implemented as a macro.
+.It Fn MCLGET "struct mbuf *m" "int how"
+Allocates and adds an mbuf cluster to a normal mbuf
+.Fa m .
+The
+.Fa how
+parameter is a choice of
+.Dv M_WAIT / M_DONTWAIT
+from caller.
+The flag
+.Dv M_EXT
+is set upon success.
+Implemented as a macro.
+.It Fn M_COPY_PKTHDR "struct mbuf *to" "struct mbuf *from"
+Copies the mbuf pkthdr from mbuf
+.Fa from
+to mbuf
+.Fa to .
+.Fa from
+must have the type flag
+.Dv M_PKTHDR
+set, and
+.Fa to
+must be empty.
+Implemented as a macro.
+.It Fn M_ALIGN "struct mbuf *m" "int len"
+Sets the data pointer of a newly allocated mbuf
+.Fa m
+to
+.Fa len
+bytes from the end of the mbuf data area, so that
+.Fa len
+bytes of data written to the mbuf
+.Fa m ,
+starting at the data pointer, will be aligned to the end of the data area.
+Implemented as a macro.
+.It Fn MH_ALIGN "struct mbuf *m" "int len"
+Sets the data pointer of a newly allocated packetheader mbuf
+.Fa m
+to
+.Fa len
+bytes from the end of the mbuf data area, so that
+.Fa len
+bytes of data written to the mbuf
+.Fa m ,
+starting at the data pointer, will be aligned to the end of the data area.
+Implemented as a macro.
+.It Fn M_LEADINGSPACE "struct mbuf *m"
+Returns the amount of space available before the current start of valid
+data in mbuf
+.Fa m .
+Implemented as a macro.
+.It Fn M_TRAILINGSPACE "struct mbuf *m"
+Returns the amount of space available after the current end of valid
+data in mbuf
+.Fa m .
+Implemented as a macro.
+.It Fn M_PREPEND "struct mbuf *m" "int plen" "int how"
+Prepends space of size
+.Fa plen
+to mbuf
+.Fa m .
+If a new mbuf must be allocated,
+.Fa how
+specifies whether to wait.
+If
+.Fa how
+is
+.Dv M_DONTWAIT
+and allocation fails, the original mbuf chain is freed and
+.Fa m
+is set to
+.Dv NULL .
+Implemented as a macro.
+.It Fn MCHTYPE "struct mbuf *m" "int type"
+Change mbuf
+.Fa m
+to new type
+.Fa type .
+Implemented as a macro.
+.It Fn MEXTREMOVE "struct mbuf *m"
+Removes external storage from mbuf
+.Fa m .
+The flag
+.Dv M_EXT
+is removed.
+Implemented as a macro.
+.It Fn MFREE "struct mbuf *m" "struct mbuf *n"
+Frees a single mbuf
+.Fa m
+and places the successor, if any, in mbuf
+.Fa n .
+Implemented as a macro.
+.El
+.\" .Sh ERRORS
+.Sh SEE ALSO
+.Xr /usr/share/doc/smm/18.net ,
+.Xr netstat 1 ,
+.Xr malloc 9
+.Sh AUTHORS
+The original mbuf data structures were designed by Rob Gurwitz
+when he did the initial TCP/IP implementation at BBN.
+.br
+Further extensions and enhancements were made by Bill Joy, Sam Leffler,
+and Mike Karels at CSRG.
+.br
+Current implementation of external storage by Matt Thomas
+.br
+<matt@3am-software.com> and Jason R. Thorpe <thorpej@NetBSD.ORG>.
+.Sh FILES
+The
+.Nm mbuf
+management functions are implemented within the file
+.Pa sys/kern/uipc_mbuf.c .
+Function prototypes, and the functions implemented as macros
+are located in
+.Pa sys/sys/mbuf.h .
+Both pathnames are relative to the root of the
+.Nx
+source tree,
+.Pa /usr/src .
+.\" .Sh HISTORY
diff --git a/share/man/man9/pool.9 b/share/man/man9/pool.9
new file mode 100644
index 00000000000..24903045e3b
--- /dev/null
+++ b/share/man/man9/pool.9
@@ -0,0 +1,343 @@
+.\" $OpenBSD: pool.9,v 1.1 1999/09/22 03:16:47 csapuntz Exp $
+.\" $NetBSD: pool.9,v 1.14 1999/08/05 04:00:04 sommerfeld Exp $
+.\"
+.\" Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Paul Kranenburg.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd July 23, 1998
+.Dt POOL 9
+.Os
+.Sh NAME
+.Nm pool_create ,
+.Nm pool_destroy ,
+.Nm pool_get ,
+.Nm pool_put ,
+.Nm pool_prime ,
+.Nm pool_sethiwat ,
+.Nm pool_setlowat
+.\".Nm POOL_STORAGE_SIZE
+.Nd resource-pool manager
+.Sh SYNOPSIS
+.Fd #include <sys/pool.h>
+.Ft struct pool *
+.\" too many arguments for a single .Fn
+.Fo pool_create
+.Fa "size_t size"
+.Fa "u_int align"
+.Fa "u_int align_offset"
+.Fa "int nitems"
+.Fa "char *wchan"
+.Fa "u_int pagesz"
+.Fa "void *(*palloc)(unsigned long sz, int flags, int tag)"
+.Fa "void (*prelease)(void *v, unsigned long sz, int tag)"
+.Fa "int mtag"
+.Fc
+.Ft void *
+.Fn pool_get "struct pool *pp" "int flags"
+.Ft void
+.Fn pool_put "struct pool *pp" "void *item"
+.Ft int
+.Fn pool_prime "struct pool *pp" "int nitems" "caddr_t storage"
+.Ft void
+.Fn pool_sethiwat "struct pool *pp" "int n"
+.Ft void
+.Fn pool_setlowat "struct pool *pp" "int n"
+.Fn POOL_STORAGE_SIZE "size" "nitems"
+.Sh DESCRIPTION
+These utility routines provide management of pools of fixed-sized
+areas of memory.
+Resource pools set aside an amount of memory for exclusive use by the resource
+pool owner.
+This can be used by applications to guarantee the availability of a minimum
+amount of memory needed to continue operation independent of the memory
+resources currently available from the system-wide memory allocator
+.Pq Xr malloc 9 .
+The pool manager can optionally obtain temporary memory by calling the
+.Fn palloc
+function passed to
+.Fn pool_create ,
+for extra pool items in case the number of allocations exceeds
+the nominal number of pool items managed by a pool resource.
+This temporary memory will be automatically returned to the system
+at a later time.
+.Ss CREATING A POOL
+The function
+.Fn pool_create
+initializes a resource pool and returns a handle to it.
+The arguments are:
+.Pp
+.Bl -tag -offset indent -width "prelease"
+.It Fa size
+Specifies the size of the memory items managed by the pool.
+.It Fa align
+Specifies the memory address aligment of the items returned by
+.Fn pool_get .
+This argument must be a power of two.
+If zero,
+the alignment defaults to a architecture-specific natural aligment.
+.It Fa align_offset
+The offset within an item to which the
+.Fa align
+parameter applies.
+.It Fa nitems
+Specifies the number of memory items that are allocated to
+the pool at creation time.
+This number may be zero,
+in which case
+.Fn pool_prime
+can be used at a later time to add permanent items to the pool.
+.It Fa wchan
+The
+.Sq wait channel
+passed on to
+.Xr tsleep 9
+if
+.Fn pool_get
+must wait for items to be returned to the pool.
+.It Fa pagesz
+The unit which is used to allocate additional memory to the pool.
+It must be a power of two.
+.It Fa palloc
+is called to add additional memory if the pool is depleted.
+It returns
+.Fa pagesz
+aligned memory.
+The argument
+.Fa sz
+will be a multiple of
+.Fa pagesz .
+.It Fa prelease
+is called to release pages back to the system.
+.Fn palloc
+and
+.Fn prelease
+may be
+.Dv NULL ,
+in which case the pool manager uses
+.Xr uvm_km_kmemalloc 9
+and
+.Xr uvm_km_free 9
+to allocate and release memory using the
+.Em kernel_map
+.Po see
+.Xr UVM 9
+.Pc .
+.It Fa mtag
+The memory tag passed to
+.Fn palloc
+and
+.Fn prelease
+when allocating or releasing memory pages.
+.It Fa storage
+Optional storage provided by the caller to use in lieu of
+.Xr malloc 9
+for both the pool handle and all pool items.
+.El
+.Pp
+If not enough memory is available to create the pool resource,
+.Fn pool_create
+returns
+.Dv NULL .
+If the
+.Fa storage
+parameter is used,
+the client is responsible for providing enough storage
+to accommodate the number of pool items specified by
+.Fa nitems ,
+as well as the space required by the pool's administrative overhead
+.Pq i.e. the pool handle .
+.\"The macro
+.\".Fn POOL_STORAGE_SIZE "size" "nitems"
+.\"can be used to determine the amount of storage needed to setup a pool,
+.\"given the size and number of the pool items.
+.Ss ALLOCATING ITEMS FROM A POOL
+.Fn pool_get
+allocates an item from the pool and returns a pointer to it.
+.Bl -tag -offset indent -width "flags"
+.It Fa pp
+The handle identifying the pool resource instance.
+.It Fa flags
+One or more of of
+.Dv PR_URGENT ,
+.Dv PR_WAITOK
+or
+.Dv PR_LIMITFAIL ,
+that define behaviour in case the pooled resources are depleted.
+If no resources are available and
+.Dv PR_WAITOK
+is given,
+this function will wait until items are returned to the pool.
+Otherwise
+.Fn pool_get
+returns
+.Dv NULL .
+If
+.Dv PR_URGENT
+is specified and no items are available and
+.Fn palloc
+cannot allocate a new page,
+the system will panic
+.Pq XXX .
+.\"Undefined behaviour results if
+.\".Dv PR_MALLOCOK
+.\"is specified on a pool handle that was created using client-provided
+.\"storage.
+.\" a bunch of other flags aren't documented.
+If both
+.Dv PR_LIMITFAIL
+and
+.Dv PR_WAITOK
+is specified, and the pool has reached its hard limit,
+.Fn pool_get
+will return
+.Dv NULL
+without waiting, allowing the caller to do its own garbage collection;
+however, it will still wait if the pool is not yet at its hard limit.
+.El
+.Ss RETURNING ITEMS TO A POOL
+.Fn pool_put
+returns the pool item pointed at by
+.Fa item
+to the resource pool identified by the pool handle
+.Fa pp .
+If the number of available items in the pool exceeds the maximum pool
+size set by
+.Fn pool_sethiwat
+and there are no outstanding requests for pool items,
+the excess items will be returned to the system by calling
+.Fn prelease .
+.Bl -tag -offset indent -width "item"
+.It Fa pp
+The handle identifying the pool resource instance.
+.It Fa item
+A pointer to a pool item previously obtained by
+.Fn pool_get .
+.El
+.Ss PRIMING A POOL
+.Fn pool_prime
+adds items to the pool.
+Storage space for the items is either allocated directly using
+.Xr malloc 9
+or given to
+.Fn pool_prime
+preallocated by the calling function.
+.Pp
+.Fn pool_prime
+.Bl -tag -offset indent -width "nitems"
+.It Fa pp
+The handle identifying the pool resource instance.
+.It Fa nitems
+The number of items to add to the pool.
+Storage for the pool items can be passed in the
+.Fa storage
+argument.
+If this parameter is
+.Dv NULL ,
+the items are allocated by using
+.Xr malloc 9 .
+This function may return
+.Dv ENOMEM
+in case the requested number of items could not be allocated.
+Otherwise,
+the return value is 0.
+.El
+.Ss SETTING POOL RESOURCE WATERMARKS
+A pool will attempt to increase its resource usage to keep up with the demand
+for its items.
+Conversely,
+it will return unused memory to the system should the number of accumulated
+unused items in the pool exceed a programmable limit.
+The limits for the minimum and maximum number of items which a pool should keep
+at hand are known as the high and low
+.Sy watermarks.
+The functions
+.Fn pool_sethiwat
+and
+.Fn pool_setlowat
+set a pool's high and low watermarks, respectively.
+.Pp
+.Fn pool_sethiwat
+.Bl -tag -offset indent -width "flags"
+.It Fa pp
+The handle identifying the pool resource instance.
+.It Fa n
+The maximum number of items to keep in the pool.
+As items are returned and the total number of pages in the pool is larger
+than the maximum set by this function,
+any completely unused pages are released immediately
+.Pq by calling Fn prelease .
+If this function is not used to specify a maximum number of items,
+the pages will remain associated with the pool until the system runs low
+on memory,
+at which point the VM system will try to reclaim unused pages.
+.El
+.Pp
+.Fn pool_setlowat
+.Bl -tag -offset indent -width "flags"
+.It Fa pp
+The handle identifying the pool resource instance.
+.It Fa n
+The minimum number of items to keep in the pool.
+The number pages in the pool will not decrease below the required value to
+accommodate the minimum number of items specified by this function.
+Unlike
+.Fn pool_prime ,
+this function does not allocate the necessary memory upfront.
+.El
+.Ss POTENTIAL PITFALLS
+Note that undefined behaviour results when mixing the storage providing
+methods supported by the pool resource routines.
+.Pp
+The pool resource code uses a per-pool lock to protect its internal state.
+If any pool functions are called in an interrupt context,
+the caller must block all interrupts that might cause the
+code to be reentered.
+.Ss DIAGNOSTICS
+Pool usage logs can be enabled by defining the compile-time option
+.Dv POOL_DIAGNOSTIC .
+.\" .Sh RETURN VALUES
+.\" .Sh EXAMPLES
+.Sh CODE REFERENCES
+The pool manager is implemented in the file
+.Pa sys/kern/subr_pool.c .
+.\" .Sh AUTHOR
+.Sh SEE ALSO
+.Xr malloc 9 ,
+.Xr free 9 ,
+.Xr uvm 9
+.Sh HISTORY
+The
+.Nx
+pool manager appeared in
+.Nx 1.4 .
diff --git a/share/man/man9/printf.9 b/share/man/man9/printf.9
index 5dd57396666..48bae6f322f 100644
--- a/share/man/man9/printf.9
+++ b/share/man/man9/printf.9
@@ -1,3 +1,4 @@
+.\" $OpenBSD: printf.9,v 1.2 1999/09/22 03:16:47 csapuntz Exp $
.\" $NetBSD: kprintf.9,v 1.6 1999/03/16 00:40:47 garbled Exp $
.\"
.\" Copyright (c) 1998 The NetBSD Foundation, Inc.
diff --git a/share/man/man9/uiomove.9 b/share/man/man9/uiomove.9
new file mode 100644
index 00000000000..2e28fca15e1
--- /dev/null
+++ b/share/man/man9/uiomove.9
@@ -0,0 +1,146 @@
+.\" $OpenBSD: uiomove.9,v 1.1 1999/09/22 03:16:47 csapuntz Exp $
+.\" $NetBSD: uiomove.9,v 1.3 1999/03/16 00:40:48 garbled Exp $
+.\"
+.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd February 12, 1999
+.Dt UIOMOVE 9
+.Os
+.Sh NAME
+.Nm uiomove
+.Nd move data described by a struct uio
+.Sh SYNOPSIS
+.Fd #include <sys/systm.h>
+.Ft int
+.Fn uiomove "void *buf" "int n" "struct uio *uio"
+.Sh DESCRIPTION
+
+The
+.Nm
+function copies up to
+.Fa n
+bytes between the kernel-space address pointed
+to by
+.Fa buf
+and the addresses described by
+.Fa uio ,
+which may be in user-space or kernel-space.
+
+The
+.Fa uio
+argument is a pointer to a
+.Fa struct uio
+as defined by
+.Aq Pa sys/uio.h :
+.Bd -literal
+struct uio {
+ struct iovec *uio_iov; /* pointer to array of iovecs */
+ int uio_iovcnt; /* number of iovecs in array */
+ off_t uio_offset; /* offset into file this uio corresponds to */
+ size_t uio_resid; /* residual i/o count */
+ enum uio_seg uio_segflg;
+ enum uio_rw uio_rw;
+ struct proc *uio_procp;/* process if UIO_USERSPACE */
+};
+.Ed
+
+A
+.Fa struct uio
+typically describes data in motion.
+Several of the fields described below reflect that expectation.
+
+.Bl -tag -width uio_xxxxxx
+.It uio_iov
+Pointer to array of
+.Fa struct iovecs :
+.Bd -literal
+struct iovec {
+ void *iov_base; /* Base address. */
+ size_t iov_len; /* Length. */
+};
+.Ed
+.It uio_iovcnt
+The number of iovecs in the array.
+.It uio_offset
+An offset into the corresponding object.
+.It uio_resid
+The amount of space described by the structure; notionally, the amount
+of data remaining to be transferred.
+.It uio_segflg
+A flag indicating whether the space described is in user-space
+(UIO_USERSPACE) or kernel-space (UIO_SYSSPACE).
+.It uio_rw
+A flag indicating whether date should be read into the space
+(UIO_READ) or written from the space (UIO_WRITE).
+.It uio_procp
+A pointer to the process whose data area is described by the
+structure, or NULL if the area is in kernel-space.
+.El
+
+The value of
+.Fa uio->uio_rw
+controls whether
+.Nm
+copies data from
+.Fa buf
+to
+.Fa uio
+or vice versa.
+
+The lesser of
+.Fa n
+or
+.Fa uio->resid
+bytes are copied.
+
+.Nm
+changes fields of the structure pointed to by
+.Fa uio ,
+such that
+.Fa uio->uio_resid
+is decremented by the amount of data moved,
+.Fa uio->uio_offset
+is incremented by the same amount, and the array of iovecs is adjusted
+to point that much farther into the region described.
+This allows multiple calls to
+.Nm
+to easily be used to fill or drain the region of data.
+
+
+.Sh RETURN VALUES
+.Nm
+returns 0 on success or EFAULT if a bad address is encountered.
+
+.Sh SEE ALSO
+.Xr fetch 9 ,
+.Xr store 9 ,
+.Xr copy 9
diff --git a/share/man/man9/uvm.9 b/share/man/man9/uvm.9
new file mode 100644
index 00000000000..432473d6771
--- /dev/null
+++ b/share/man/man9/uvm.9
@@ -0,0 +1,1012 @@
+.\" $OpenBSD: uvm.9,v 1.1 1999/09/22 03:16:47 csapuntz Exp $
+.\" $NetBSD: uvm.9,v 1.7 1999/05/06 12:04:50 hwr Exp $
+.\"
+.\" Copyright (c) 1998 Matthew R. Green
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. The name of the author may not be used to endorse or promote products
+.\" derived from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" XXX this manual sets nS to 1 or 0 in the description, to obtain
+.\" synopsis-like function prototypes. any better way?
+.\"
+.Dd April 10, 1998
+.Dt UVM 9
+.Os
+.Sh NAME
+.Nm UVM virtual memory system
+.Nd external interface
+.Sh SYNOPSIS
+.Fd #include <sys/param.h>
+.Fd #include <vm/vm.h>
+.Fd #include <uvm/uvm.h>
+.Sh DESCRIPTION
+The UVM virtual memory system manages access to the computer's memory
+resources. User processes and the kernel access these resources through
+UVM's exteral interface. UVM's external interface includes functions that:
+.Pp
+.Bl -hyphen -compact
+.It
+initialise UVM sub-systems
+.It
+manage virtual address spaces
+.It
+resolve page faults
+.It
+memory map files and devices
+.It
+perform uio-based I/O to virtual memory
+.It
+allocate and free kernel virtual memory
+.It
+allocate and free physical memory
+.El
+.Pp
+In addition to exporting these services, UVM has two kernel-level processes:
+pagedaemon and swapper. The pagedaemon process sleeps until physical memory
+becomes scarce. When that happens, pagedaemon is awoken. It scans physical
+memory, paging out and freeing memory that has not been recently used. The
+swapper process swaps in runnable processes that are currently swapped out,
+if there is room.
+.Pp
+There are also several miscellaneous functions.
+
+.Pp
+.Sh INITIALISATION
+
+.nr nS 1
+.Pp
+.Ft void
+.Fn uvm_init
+.Ft void
+.Fn uvm_init_limits "struct proc *p"
+.Ft void
+.Fn uvm_setpagesize
+.Ft void
+.Fn uvm_swap_init
+.nr nS 0
+
+.Pp
+.Fn uvm_init
+sets up the UVM system at system boot time, after the
+copyright has been printed. It initialises
+global state, the page, map, kernel virtual memory state,
+machine-dependent physical map, kernel memory allocator,
+pager and anonymous memory sub-systems, and then enables
+paging of kernel objects.
+
+.Pp
+.Fn uvm_init_limits
+initialises process limits for the named process. This is for use by
+the system startup for process zero, before any other processes are
+created.
+
+.Pp
+.Fn uvm_setpagesize
+initialises the uvmexp members pagesize (if not already done by
+machine-dependent code), pageshift and pagemask. It should be called by
+machine-dependent code early in the
+.Xr pmap_init 9
+call.
+
+.Pp
+.Fn uvm_swap_init
+initialises the swap sub-system.
+
+.Pp
+.Sh VIRTUAL ADDRESS SPACE MANAGEMENT
+
+.Pp
+.nr nS 1
+.Ft int
+.Fn uvm_map "vm_map_t map" "vaddr_t *startp" "vsize_t size" "struct uvm_object *uobj" "vaddr_t uoffset" "uvm_flag_t flags"
+.Ft int
+.Fn uvm_map_pageable "vm_map_t map" "vaddr_t start" "vaddr_t end" "boolean_t new_pageable"
+.Ft boolean_t
+.Fn uvm_map_checkprot "vm_map_t map" "vaddr_t start" "vaddr_t end" "vm_prot_t protection"
+.Ft int
+.Fn uvm_map_protect "vm_map_t map" "vaddr_t start" "vaddr_t end" "vm_prot_t new_prot" "boolean_t set_max"
+.Ft int
+.Fn uvm_deallocate "vm_map_t map" "vaddr_t start" "vsize_t size"
+
+.Ft struct vmspace *
+.Fn uvmspace_alloc "vaddr_t min" "vaddr_t max" "int pageable"
+.Ft void
+.Fn uvmspace_exec "struct proc *p"
+.Ft struct vmspace *
+.Fn uvmspace_fork "struct vmspace *vm"
+.Ft void
+.Fn uvmspace_free "struct vmspace *vm1"
+.Ft void
+.Fn uvmspace_share "struct proc *p1" "struct proc *p2"
+.Ft void
+.Fn uvmspace_unshare "struct proc *p"
+.nr nS 0
+
+.Pp
+.Fn uvm_map
+establishes a valid mapping in map
+.Fa map ,
+which must be unlocked. The new mapping has size
+.Fa size ,
+which must be in
+.Dv PAGE_SIZE
+units. The
+.Fa uobj
+and
+.Fa uoffset
+arguments can have four meanings. When
+.Fa uobj
+is
+.Dv NULL
+and
+.Fa uoffset
+is
+.Dv UVM_UNKNOWN_OFFSET ,
+.Fn uvm_map
+does not use the machine-dependant
+.Dv PMAP_PREFER
+function. If
+.Fa uoffset
+is any other value, it is used as the hint to
+.Dv PMAP_PREFER .
+When
+.Fa uobj
+is not
+.Dv NULL
+and
+.Fa uoffset
+is
+.Dv UVM_UNKNOWN_OFFSET ,
+.Fn uvm_map
+finds the offset based upon the virtual address, passed as
+.Fa startp .
+If
+.Fa uoffset
+is any other value, we are doing a normal mapping at this offset. The
+start address of the map will be returned in
+.Fa startp .
+.Pp
+.Fa flags
+passed to
+.Fn uvm_map
+are typically created using the
+.Fn UVM_MAPFLAG "vm_prot_t prot" "vm_prot_t maxprot" "vm_inherit_t inh" "int advice" "int flags"
+macro, which uses the following values.
+The
+.Fa prot
+and
+.Fa maxprot
+can take are:
+.Bd -literal
+#define UVM_PROT_MASK 0x07 /* protection mask */
+#define UVM_PROT_NONE 0x00 /* protection none */
+#define UVM_PROT_ALL 0x07 /* everything */
+#define UVM_PROT_READ 0x01 /* read */
+#define UVM_PROT_WRITE 0x02 /* write */
+#define UVM_PROT_EXEC 0x04 /* exec */
+#define UVM_PROT_R 0x01 /* read */
+#define UVM_PROT_W 0x02 /* write */
+#define UVM_PROT_RW 0x03 /* read-write */
+#define UVM_PROT_X 0x04 /* exec */
+#define UVM_PROT_RX 0x05 /* read-exec */
+#define UVM_PROT_WX 0x06 /* write-exec */
+#define UVM_PROT_RWX 0x07 /* read-write-exec */
+.Ed
+.Pp
+The values that
+.Fa inh
+can take are:
+.Bd -literal
+#define UVM_INH_MASK 0x30 /* inherit mask */
+#define UVM_INH_SHARE 0x00 /* "share" */
+#define UVM_INH_COPY 0x10 /* "copy" */
+#define UVM_INH_NONE 0x20 /* "none" */
+#define UVM_INH_DONATE 0x30 /* "donate" << not used */
+.Ed
+.Pp
+The values that
+.Fa advice
+can take are:
+.Bd -literal
+#define UVM_ADV_NORMAL 0x0 /* 'normal' */
+#define UVM_ADV_RANDOM 0x1 /* 'random' */
+#define UVM_ADV_SEQUENTIAL 0x2 /* 'sequential' */
+#define UVM_ADV_MASK 0x7 /* mask */
+.Ed
+.Pp
+The values that
+.Fa flags
+can take are:
+.Bd -literal
+#define UVM_FLAG_FIXED 0x010000 /* find space */
+#define UVM_FLAG_OVERLAY 0x020000 /* establish overlay */
+#define UVM_FLAG_NOMERGE 0x040000 /* don't merge map entries */
+#define UVM_FLAG_COPYONW 0x080000 /* set copy_on_write flag */
+#define UVM_FLAG_AMAPPAD 0x100000 /* for bss: pad amap to reduce malloc() */
+#define UVM_FLAG_TRYLOCK 0x200000 /* fail if we can not lock map */
+.Ed
+.Pp
+The
+.Dv UVM_MAPFLAG
+macro arguments can be combined with an or operator. There are
+several special purpose macros for checking protection combinations, e.g. the
+.Dv UVM_PROT_WX
+macro. There are also some additional macros to extract bits from
+the flags. The
+.Dv UVM_PROTECTION ,
+.Dv UVM_INHERIT ,
+.Dv UVM_MAXPROTECTION
+and
+.Dv UVM_ADVICE
+macros return the protection, inheritance, maximum protection and advice,
+respectively.
+.Fn uvm_map
+returns a standard UVM return value.
+
+.Pp
+.Fn uvm_map_pageable
+changes the pageability of the pages in the range from
+.Fa start
+to
+.Fa end
+in map
+.Fa map
+to
+.Fa new_pageable .
+.Fn uvm_map_pageable
+returns a standard UVM return value.
+
+.Pp
+.Fn uvm_map_checkprot
+checks the protection of the range from
+.Fa start
+to
+.Fa end
+in map
+.Fa map
+against
+.Fa protection .
+This returns either
+.Dv TRUE
+or
+.Dv FALSE .
+
+.Pp
+.Fn uvm_map_protect
+changes the protection
+.Fa start
+to
+.Fa end
+in map
+.Fa map
+to
+.Fa new_prot ,
+also setting the maximum protection to the region to
+.Fa new_prot
+if
+.Fa set_max
+is non-zero. This function returns a standard UVM return value.
+
+.Pp
+.Fn uvm_deallocate
+deallocates kernel memory in map
+.Fa map
+from address
+.Fa start
+to
+.Fa start + size .
+
+.Pp
+.Fn uvmspace_alloc
+allocates and returns a new address space, with ranges from
+.Fa min
+to
+.Fa max ,
+setting the pageability of the address space to
+.Fa pageable.
+
+.Pp
+.Fn uvmspace_exec
+either reuses the address space of process
+.Fa p
+if there are no other references to it, or creates
+a new one with
+.Fn uvmspace_alloc .
+
+.Pp
+.Fn uvmspace_fork
+creates and returns a new address space based upon the
+.Fa vm1
+address space, typically used when allocating an address space for a
+child process.
+
+.Pp
+.Fn uvmspace_free
+lowers the reference count on the address space
+.Fa vm ,
+freeing the data structures if there are no other references.
+
+.Pp
+.Fn uvmspace_share
+causes process
+.Pa p2
+to share the address space of
+.Fa p1 .
+
+.Pp
+.Fn uvmspace_unshare
+ensures that process
+.Fa p
+has its own, unshared address space, by creating a new one if
+necessary by calling
+.Fn uvmspace_fork .
+
+.Pp
+.Sh PAGE FAULT HANDLING
+
+.Pp
+.nr nS 1
+.Ft int
+.Fn uvm_fault "vm_map_t orig_map" "vaddr_t vaddr" "vm_fault_t fault_type" "vm_prot_t access_type"
+.nr nS 0
+.Pp
+.Fn uvm_fault
+is the main entry point for faults. It takes
+.Fa orig_map
+as the map the fault originated in, a
+.Fa vaddr
+offset into the map the fault occured,
+.Fa fault_type
+describing the type of fault, and
+.Fa access_type
+describing the type of access requested.
+.Fn uvm_fault
+returns a standard UVM return value.
+
+.Pp
+.Sh MEMORY MAPPING FILES AND DEVICES
+
+.Pp
+.nr nS 1
+.Ft struct uvm_object *
+.Fn uvn_attach "void *arg" "vm_prot_t accessprot"
+.Ft void
+.Fn uvm_vnp_setsize "struct vnode *vp" "u_quad_t newsize"
+.Ft void
+.Fn uvm_vnp_sync "struct mount *mp"
+.Ft void
+.Fn uvm_vnp_terminate "struct vnode *vp"
+.Ft boolean_t
+.Fn uvm_vnp_uncache "struct vnode *vp"
+.nr nS 0
+
+.Pp
+.Fn uvn_attach
+attaches a UVM object to vnode
+.Fa arg ,
+creating the object if necessary. The object is returned.
+
+.Pp
+.Fn uvm_vnp_setsize
+sets the size of vnode
+.Fa vp
+to
+.Fa newsize .
+Caller must hold a reference to the vnode. If the vnode shrinks, pages
+no longer used are discarded. This function will be removed when the
+filesystem and VM buffer caches are merged.
+
+.Pp
+.Fn uvm_vnp_sync
+flushes dirty vnodes from either the mount point passed in
+.Fa mp ,
+or all dirty vnodes if
+.Fa mp
+is
+.Dv NULL .
+This function will be removed when the filesystem and VM buffer caches
+are merged.
+
+.Pp
+.Fn uvm_vnp_terminate
+frees all VM resources allocated to vnode
+.Fa vp .
+If the vnode still has references, it will not be destroyed; however
+all future operations using this vnode will fail. This function will be
+removed when the filesystem and VM buffer caches are merged.
+
+.Pp
+.Fn uvm_vnp_uncache
+disables vnode
+.Fa vp
+from persisting when all references are freed. This function will be
+removed when the file-system and UVM caches are unified. Returns
+true if there is no active vnode.
+
+.Pp
+.Sh VIRTUAL MEMORY I/O
+
+.Pp
+.nr nS 1
+.Ft int
+.Fn uvm_io "vm_map_t map" "struct uio *uio"
+.nr nS 0
+
+.Pp
+.Fn uvm_io
+performs the I/O described in
+.Fa uio
+on the memory described in
+.Fa map .
+
+.Pp
+.Sh ALLOCATION OF KERNEL MEMORY
+
+.Pp
+.nr nS 1
+.Ft vaddr_t
+.Fn uvm_km_alloc "vm_map_t map" "vsize_t size"
+.Ft vaddr_t
+.Fn uvm_km_zalloc "vm_map_t map" "vsize_t size"
+.Ft vaddr_t
+.Fn uvm_km_alloc1 "vm_map_t map" "vsize_t size" "boolean_t zeroit"
+.Ft vaddr_t
+.Fn uvm_km_kmemalloc "vm_map_t map" "struct uvm_object *obj" "vsize_t size" "int flags"
+.Ft vaddr_t
+.Fn uvm_km_valloc "vm_map_t map" "vsize_t size"
+.Ft vaddr_t
+.Fn uvm_km_valloc_wait "vm_map_t map" "vsize_t size"
+.Ft struct vm_map *
+.Fn uvm_km_suballoc "vm_map_t map" "vaddr_t *min" "vaddr_t *max " "vsize_t size" "boolean_t pageable" "boolean_t fixed" "vm_map_t submap"
+.Ft void
+.Fn uvm_km_free "vm_map_t map" "vaddr_t addr" "vsize_t size"
+.Ft void
+.Fn uvm_km_free_wakeup "vm_map_t map" "vaddr_t addr" "vsize_t size"
+.nr nS 0
+
+.Pp
+.Fn uvm_km_alloc
+and
+.Fn uvm_km_zalloc
+allocate
+.Fa size
+bytes of wired kernel memory in map
+.Fa map .
+In addition to allocation,
+.Fn uvm_km_zalloc
+zeros the memory. Both of these functions are defined as macros in
+terms of
+.Fn uvm_km_alloc1 ,
+and should almost always be used in preference to
+.Fn uvm_km_alloc1 .
+
+.Pp
+.Fn uvm_km_alloc1
+allocates and returns
+.Fa size
+bytes of wired memory in the kernel map, zeroing the memory if the
+.Fa zeroit
+argument is non-zero.
+
+.Pp
+.Fn uvm_km_kmemalloc
+allocates and returns
+.Fa size
+bytes of wired kernel memory into
+.Fa obj .
+The flags can be any of:
+.Bd -literal
+#define UVM_KMF_NOWAIT 0x1 /* matches M_NOWAIT */
+#define UVM_KMF_VALLOC 0x2 /* allocate VA only */
+#define UVM_KMF_TRYLOCK UVM_FLAG_TRYLOCK /* try locking only */
+.Ed
+.Pp
+.Dv UVM_KMF_NOWAIT
+causes
+.Fn uvm_km_kmemalloc
+to return immediately if no memory is available.
+.Dv UVM_KMF_VALLOC
+causes no pages to be allocated, only a virtual address.
+.Dv UVM_KMF_TRYLOCK
+causes
+.Fn uvm_km_kmemalloc
+to use
+.Fn simple_lock_try
+when locking maps.
+
+.Pp
+.Fn uvm_km_valloc
+and
+.Fn uvm_km_valloc_wait
+return a newly allocated zero-filled address in the kernel map of size
+.Fa size .
+.Fn uvm_km_valloc_wait
+will also wait for kernel memory to become available, if there is a
+memory shortage.
+
+.Pp
+.Sh ALLOCATION OF PHYSICAL MEMORY
+
+.Pp
+.nr nS 1
+.Ft struct vm_page *
+.Fn uvm_pagealloc "struct uvm_object *uobj" "vaddr_t off" "struct vm_anon *anon"
+.Ft void
+.Fn uvm_pagerealloc "struct vm_page *pg" "struct uvm_object *newobj" "vaddr_t newoff"
+.Ft void
+.Fn uvm_pagefree "struct vm_page *pg"
+.Ft int
+.Fn uvm_pglistalloc "psize_t size" "paddr_t low" "paddr_t high" "paddr_t alignment" "paddr_t boundary" "struct pglist *rlist" "int nsegs" "int waitok"
+.Ft void
+.Fn uvm_pglistfree "struct pglist *list"
+.Ft void
+.Fn uvm_page_physload "vaddr_t start" "vaddr_t end" "vaddr_t avail_start" "vaddr_t avail_end"
+.nr nS 0
+
+.Pp
+.Fn uvm_pagealloc
+allocates a page of memory at virtual address
+.Fa off
+in either the object
+.Fa uobj
+or the anonymous memory
+.Fa anon ,
+which must be locked by the caller. Only one of
+.Fa off
+and
+.Fa uobj
+can be non
+.Dv NULL .
+Returns
+.Dv NULL
+when no page can be found.
+
+.Pp
+.Fn uvm_pagerealloc
+reallocates page
+.Fa pg
+to a new object
+.Fa newobj ,
+at a new offset
+.Fa newoff .
+
+.Pp
+.Fn uvm_pagefree
+free's the physical page
+.Fa pg .
+
+.Pp
+.Fn uvm_pglistalloc
+allocates a list of pages for size
+.Fa size
+byte under various constraints.
+.Fa low
+and
+.Fa high
+describe the lowest and highest addresses acceptable for the list. If
+.Fa alignment
+is non-zero, it describes the required alignment of the list, in
+power-of-two notation. If
+.Fa boundary
+is non-zero, no segment of the list may cross this power-of-two
+boundary, relative to zero.
+The
+.Fa nsegs
+and
+.Fa waitok
+arguments are currently ignored.
+
+.Pp
+.Fn uvm_pglistfree
+frees the list of pages pointed to by
+.Fa list .
+
+.Pp
+.Fn uvm_page_physload
+loads physical memory segments into VM space. It must be called at system
+boot time to setup physical memory management pages. The arguments describe
+the
+.Fa start
+and
+.Fa end
+of the physical addresses of the segment, and the available start and end
+addresses of pages not already in use.
+.\" XXX expand on "system boot time"!
+
+.Pp
+.Fn uvm_km_suballoc
+allocates submap from
+.Fa map ,
+creating a new map if
+.Fa submap
+is
+.Dv NULL .
+The addresses of the submap can be specified exactly by setting the
+.Fa fixed
+argument to non-zero, which causes the
+.Fa min
+argument specify the beginning of the address in thes submap. If
+.Fa fixed
+is zero, any address of size
+.Fa size
+will be allocated from
+.Fa map
+and the start and end addresses returned in
+.Fa min
+and
+.Fa max .
+If
+.Fa pageable
+is non-zero, entries in the map may be paged out.
+
+.Pp
+.Fn uvm_km_free
+and
+.Fn uvm_km_free_wakeup
+free
+.Fa size
+bytes of memory in the kernal map, starting at address
+.Fa addr .
+.Fn uvm_km_free_wakeup
+calls
+.Fn thread_wakeup
+on the map before unlocking the map.
+
+.Pp
+.Sh PROCESSES
+
+.Pp
+.nr nS 1
+.Ft void
+.Fn uvm_pageout
+.Ft void
+.Fn uvm_scheduler
+.Ft void
+.Fn uvm_swapin "struct proc *p"
+.Ft void
+
+.Pp
+.Fn uvm_pageout
+is the main loop for the page daemon.
+
+.Pp
+.Fn uvm_scheduler
+is the process zero main loop, which is to be called after the
+system has finished starting other processes. It handles the
+swapping in of runnable, swapped out processes in priority
+order.
+
+.Pp
+.Fn uvm_swapin
+swaps in the named process.
+
+.Pp
+.Sh MISCELLANEOUS FUNCTIONS
+
+.nr nS 1
+.Pp
+.Ft struct uvm_object *
+.Fn uao_create "vsize_t size" "int flags"
+.Ft void
+.Fn uao_detach "struct uvm_object *uobj"
+.Ft void
+.Fn uao_reference "struct uvm_object *uobj"
+
+.Ft boolean_t
+.Fn uvm_chgkprot "caddr_t addr" "size_t len" "int rw"
+.Ft void
+.Fn uvm_kernacc "caddr_t addr" "size_t len" "int rw"
+.Ft boolean_t
+.Fn uvm_useracc "caddr_t addr" "size_t len" "int rw"
+
+.Ft void
+.Fn uvm_vslock "struct proc *p" "caddr_t addr" "size_t len"
+.Ft void
+.Fn uvm_vsunlock "struct proc *p" "caddr_t addr" "size_t len"
+
+.Ft void
+.Fn uvm_meter
+.Ft int
+.Fn uvm_sysctl "int *name" "u_int namelen" "void *oldp" "size_t *oldlenp" "void *newp " "size_t newlen" "struct proc *p"
+
+.Ft void
+.Fn uvm_fork "struct proc *p1" "struct proc *p2" "boolean_t shared"
+.Ft int
+.Fn uvm_grow "struct proc *p" "vaddr_t sp"
+.Ft int
+.Fn uvm_coredump "struct proc *p" "struct vnode *vp" "struct ucred *cred" "struct core *chdr"
+.nr nS 0
+
+.Pp
+The
+.Fn uao_create ,
+.Fn uao_detach
+and
+.Fn uao_reference
+functions operate on anonymous memory objects, such as those used to support
+System V shared memory.
+.Fn uao_create
+returns an object of size
+.Fa size
+with flags:
+.Bd -literal
+#define UAO_FLAG_KERNOBJ 0x1 /* create kernel object */
+#define UAO_FLAG_KERNSWAP 0x2 /* enable kernel swap */
+.Pp
+.Ed
+which can only be used once each at system boot time.
+.Fn uao_reference
+creates an additional reference to the named anonymous memory object.
+.Fn uao_detach
+removes a reference from the named anonymous memory object, destroying
+it if removing the last reference.
+
+.Pp
+.Fn uvm_chgkprot
+changes the protection of kernel memory from
+.Fa addr
+to
+.Fa addr + len
+to the value of
+.Fa rw .
+This is primarily useful for debuggers, for setting breakpoints.
+This function is only available with options
+.Dv KGDB .
+
+.Pp
+.Fn uvm_kernacc
+and
+.Fn uvm_useracc
+check the access at address
+.Fa addr
+to
+.Fa addr + len
+for
+.Fa rw
+access, in the kernel address space, and the current process'
+address space respectively.
+
+.Pp
+.Fn uvm_vslock
+and
+.Fn uvm_vsunlock
+control the wiring and unwiring of pages for process
+.Fa p
+from
+.Fa addr
+to
+.Fa addr + len .
+These functions are normally used to wire memory for I/O.
+
+.Pp
+.Fn uvm_meter
+calculates the load average and wakes up the swapper if necessary.
+
+.Pp
+.Fn uvm_sysctl
+provides support for the
+.Dv CTL_VM
+domain of the
+.Xr sysctl 3
+hierarchy.
+.Fn uvm_sysctl
+handles the
+.Dv VM_LOADAVG ,
+.Dv VM_METER
+and
+.Dv VM_UVMEXP
+calls, which return the current load averages, calculates current VM
+totals, and returns the uvmexp structure respectively. The load averages
+are access from userland using the
+.Xr getloadavg 3
+function. The uvmexp structure has all global state of the UVM system,
+and has the following members:
+.Bd -literal
+/* vm_page constants */
+int pagesize; /* size of a page (PAGE_SIZE): must be power of 2 */
+int pagemask; /* page mask */
+int pageshift; /* page shift */
+
+/* vm_page counters */
+int npages; /* number of pages we manage */
+int free; /* number of free pages */
+int active; /* number of active pages */
+int inactive; /* number of pages that we free'd but may want back */
+int paging; /* number of pages in the process of being paged out */
+int wired; /* number of wired pages */
+int reserve_pagedaemon; /* number of pages reserved for pagedaemon */
+int reserve_kernel; /* number of pages reserved for kernel */
+
+/* pageout params */
+int freemin; /* min number of free pages */
+int freetarg; /* target number of free pages */
+int inactarg; /* target number of inactive pages */
+int wiredmax; /* max number of wired pages */
+
+/* swap */
+int nswapdev; /* number of configured swap devices in system */
+int swpages; /* number of PAGE_SIZE'ed swap pages */
+int swpginuse; /* number of swap pages in use */
+int nswget; /* number of times fault calls uvm_swap_get() */
+int nanon; /* number total of anon's in system */
+int nfreeanon; /* number of free anon's */
+
+/* stat counters */
+int faults; /* page fault count */
+int traps; /* trap count */
+int intrs; /* interrupt count */
+int swtch; /* context switch count */
+int softs; /* software interrupt count */
+int syscalls; /* system calls */
+int pageins; /* pagein operation count */
+ /* pageouts are in pdpageouts below */
+int swapins; /* swapins */
+int swapouts; /* swapouts */
+int pgswapin; /* pages swapped in */
+int pgswapout; /* pages swapped out */
+int forks; /* forks */
+int forks_ppwait; /* forks where parent waits */
+int forks_sharevm; /* forks where vmspace is shared */
+
+/* fault subcounters */
+int fltnoram; /* number of times fault was out of ram */
+int fltnoanon; /* number of times fault was out of anons */
+int fltpgwait; /* number of times fault had to wait on a page */
+int fltpgrele; /* number of times fault found a released page */
+int fltrelck; /* number of times fault relock called */
+int fltrelckok; /* number of times fault relock is a success */
+int fltanget; /* number of times fault gets anon page */
+int fltanretry; /* number of times fault retrys an anon get */
+int fltamcopy; /* number of times fault clears "needs copy" */
+int fltnamap; /* number of times fault maps a neighbor anon page */
+int fltnomap; /* number of times fault maps a neighbor obj page */
+int fltlget; /* number of times fault does a locked pgo_get */
+int fltget; /* number of times fault does an unlocked get */
+int flt_anon; /* number of times fault anon (case 1a) */
+int flt_acow; /* number of times fault anon cow (case 1b) */
+int flt_obj; /* number of times fault is on object page (2a) */
+int flt_prcopy; /* number of times fault promotes with copy (2b) */
+int flt_przero; /* number of times fault promotes with zerofill (2b) */
+
+/* daemon counters */
+int pdwoke; /* number of times daemon woke up */
+int pdrevs; /* number of times daemon rev'd clock hand */
+int pdswout; /* number of times daemon called for swapout */
+int pdfreed; /* number of pages daemon freed since boot */
+int pdscans; /* number of pages daemon scaned since boot */
+int pdanscan; /* number of anonymous pages scanned by daemon */
+int pdobscan; /* number of object pages scanned by daemon */
+int pdreact; /* number of pages daemon reactivated since boot */
+int pdbusy; /* number of times daemon found a busy page */
+int pdpageouts; /* number of times daemon started a pageout */
+int pdpending; /* number of times daemon got a pending pagout */
+int pddeact; /* number of pages daemon deactivates */
+.Ed
+
+.Pp
+.Fn uvm_fork
+forks a virtual address space for process' (old)
+.Fa p1
+and (new)
+.Fa p2 .
+If the
+.Fa shared
+argument is non zero, p1 shares its address space with p2,
+otherwise a new address space is created. This function
+currently has no return value, and thus cannot fail. In
+the future, this function will changed to allowed it to
+fail in low memory conditions.
+
+.Pp
+.Fn uvm_grow
+increases the stack segment of process
+.Fa p
+to include
+.Fa sp .
+
+.Pp
+.Fn uvm_coredump
+generates a coredump on vnode
+.Fa vp
+for process
+.Fa p
+with credentials
+.Fa cred
+and core header description in
+.Fa chdr .
+
+.Sh STANDARD UVM RETURN VALUES
+This section documents the standard return values that callers of UVM
+functions can expect. They are derived from the Mach VM values
+of the same function. The full list of values can be seen below.
+.Bd -literal
+#define KERN_SUCCESS 0
+#define KERN_INVALID_ADDRESS 1
+#define KERN_PROTECTION_FAILURE 2
+#define KERN_NO_SPACE 3
+#define KERN_INVALID_ARGUMENT 4
+#define KERN_FAILURE 5
+#define KERN_RESOURCE_SHORTAGE 6
+#define KERN_NOT_RECEIVER 7
+#define KERN_NO_ACCESS 8
+#define KERN_PAGES_LOCKED 9
+.Ed
+.Pp
+Note that
+.Dv KERN_NOT_RECEIVER
+and
+.Dv KERN_PAGES_LOCKED
+values are not actually returned by the UVM code.
+
+.Sh NOTES
+These functions are only available with options
+.Dv UVM .
+.Pp
+.Fn uvm_chgkprot
+is only available if the kernel has been compiled with options
+.Dv KGDB .
+.Pp
+The include file
+.Pa <vm/vm.h>
+will be deprecated when then Mach VM system is obsoleted. All structure
+and types whose names begin with ``vm_'' will be renamed to ``uvm_''.
+.Pp
+The
+.Xr pmap 9
+manual page is not yet written.
+
+.Sh HISTORY
+UVM is a new VM system developed at Washington University in St. Louis
+(Missouri). UVM's roots lie partly in the Mach-based
+.Bx 4.4
+VM system, the FreeBSD VM system, and the SunOS4 VM system. UVM's basic
+structure is based on the
+.Bx 4.4
+VM system. UVM's new i386 machine-depenent layer includes several ideas
+from FreeBSD. UVM's new anonymous memory system is based on the
+anonymous memory system found in SunOS4 VM (as described in papers by
+published Sun Microsystems, Inc.). UVM also includes a number of feature
+new to BSD including page loanout, map entry passing, simplified
+copy-on-write, and clustered anonymous memory pageout. UVM will be
+further documented in August 1998 in a dissertation by Charles D. Cranor.
+.Pp
+UVM appeared in
+.Nx 1.4 .
+
+.Sh AUTHOR
+Charles D. Cranor <chuck@ccrc.wustl.edu> designed and implemented UVM.
+.Pp
+Matthew Green <mrg@eterna.com.au> wrote the swap-space managemnt code
+and handled the logistical issues involed with merging UVM into the
+NetBSD source tree.
+.Pp
+Chuck Silvers <chuq@chuq.com> implemented the aobj pager, thus allowing
+UVM to support System V shared memory and process swapping.
+
+.Sh SEE ALSO
+.Xr getloadavg 3 ,
+.Xr kvm 3 ,
+.Xr sysctl 3 ,
+.Xr ddb 4 ,
+.Xr options 4
diff --git a/share/man/man9/vslock.9 b/share/man/man9/vslock.9
new file mode 100644
index 00000000000..583c745f4f9
--- /dev/null
+++ b/share/man/man9/vslock.9
@@ -0,0 +1,68 @@
+.\" $OpenBSD: vslock.9,v 1.1 1999/09/22 03:16:47 csapuntz Exp $
+.\" $NetBSD: vslock.9,v 1.8 1999/03/16 00:40:48 garbled Exp $
+.\"
+.\" Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Paul Kranenburg.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the NetBSD
+.\" Foundation, Inc. and its contributors.
+.\" 4. Neither the name of The NetBSD Foundation nor the names of its
+.\" contributors may be used to endorse or promote products derived
+.\" from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd June 15, 1996
+.Dt VSLOCK 9
+.Os
+.Sh NAME
+.Nm vslock ,
+.Nm vsunlock
+.Nd lock/unlock user space addresses in memory
+.Sh SYNOPSIS
+.Ft void
+.Fn vslock "struct proc *p" "caddr_t addr" "size_t len"
+.Ft void
+.Fn vsunlock "struct proc *p" "caddr_t addr" "size_t len"
+.Sh DESCRIPTION
+The
+.Fn vslock
+and
+.Fn vsunlock
+functions respectively lock and unlock a range of
+addresses belonging to the currently running process into memory.
+The actual amount of memory locked is a multiple of the machine's page size.
+The starting page number is computed by truncating
+.Fa addr
+to the nearest preceding page boundary, and by rounding up
+.Fa addr +
+.Fa len
+to the next page boundary.
+The process context to use for this operation is taken from
+.Fa p .
+.Pp
+.Sh SEE ALSO
+.Xr physio 9
diff --git a/share/man/man9/wdc.9 b/share/man/man9/wdc.9
new file mode 100644
index 00000000000..e6d5e66d705
--- /dev/null
+++ b/share/man/man9/wdc.9
@@ -0,0 +1,413 @@
+.\" $OpenBSD: wdc.9,v 1.1 1999/09/22 03:16:47 csapuntz Exp $
+.\" $NetBSD: wdc.9,v 1.3 1999/03/16 00:40:48 garbled Exp $
+
+.\"
+.\" Copyright (c) 1998 Manuel Bouyer.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\"
+
+.Dd October 18, 1998
+.Dt wdc 9
+.Os
+.Sh NAME
+.Nm wdc
+.Nd machine-indepedant IDE/ATAPI driver
+.Sh SYNOPSIS
+.Fd #include <dev/ata/atavar.h>
+.Fd #include <sys/dev/ic/wdcvar.h>
+.Ft int
+.Fn wdcprobe "struct channel_softc * chp"
+.Ft void
+.Fn wdcattach "struct channel_softc * chp"
+.Sh description
+The
+.Nm
+driver provides the machine independant core functions for driving IDE
+devices.
+IDE devices-specific drivers (
+.Nm wd
+or
+.Nm atapibus )
+will use services provided by
+.Nm wdc .
+.Pp
+The machine-dependant bus front-end provides informations to
+.Nm
+vith the
+.Va wdc_softc
+and
+.Va channel_softc
+structures.
+The first one defines global controller properties, and the second contain
+per-channel informations.
+.Nm
+returns informations about the attached devices in the
+.Va ata_drive_datas
+structure.
+.Bd -literal
+struct wdc_softc { /* Per controller state */
+ struct device sc_dev;
+ int cap;
+#define WDC_CAPABILITY_DATA16 0x0001
+#define WDC_CAPABILITY_DATA32 0x0002
+#define WDC_CAPABILITY_MODE 0x0004
+#define WDC_CAPABILITY_DMA 0x0008
+#define WDC_CAPABILITY_UDMA 0x0010
+#define WDC_CAPABILITY_HWLOCK 0x0020
+#define WDC_CAPABILITY_ATA_NOSTREAM 0x0040
+#define WDC_CAPABILITY_ATAPI_NOSTREAM 0x0080
+#define WDC_CAPABILITY_NO_EXTRA_RESETS 0x0100
+ u_int8_t pio_mode;
+ u_int8_t dma_mode;
+ int nchannels;
+ struct channel_softc *channels;
+
+ void *dma_arg;
+ int (*dma_init) __P((void *, int, int, void *, size_t,
+ void (*dma_start) __P((void *, int, int, int));
+ int (*dma_finish) __P((void *, int, int, int));
+#define WDC_DMA_READ 0x01
+#define WDC_DMA_POLL 0x02
+
+ int (*claim_hw) __P((void *, int));
+ void (*free_hw) __P((void *));
+};
+
+struct channel_softc { /* Per channel data */
+ int channel;
+ struct wdc_softc *wdc;
+ bus_space_tag_t cmd_iot;
+ bus_space_handle_t cmd_ioh;
+ bus_space_tag_t ctl_iot;
+ bus_space_handle_t ctl_ioh;
+ bus_space_tag_t data32iot;
+ bus_space_handle_t data32ioh;
+ int ch_flags;
+#define WDCF_ACTIVE 0x01
+#define WDCF_IRQ_WAIT 0x10
+ u_int8_t ch_status;
+ u_int8_t ch_error;
+ struct ata_drive_datas ch_drive[2];
+ struct channel_queue *ch_queue;
+};
+
+struct ata_drive_datas {
+ u_int8_t drive;
+ u_int8_t drive_flags;
+#define DRIVE_ATA 0x01
+#define DRIVE_ATAPI 0x02
+#define DRIVE (DRIVE_ATA|DRIVE_ATAPI)
+#define DRIVE_CAP32 0x04
+#define DRIVE_DMA 0x08
+#define DRIVE_UDMA 0x10
+#define DRIVE_MODE 0x20
+ u_int8_t PIO_mode;
+ u_int8_t DMA_mode;
+ u_int8_t UDMA_mode;
+ u_int8_t state;
+
+ struct device *drv_softc;
+ void* chnl_softc;
+};
+
+.Ed
+
+The bus front-end needs to fill in the following elements of
+.Va wdc_softc :
+.Bl -tag -compact -width "dma_finish" -offset "xxxx"
+.It cap
+supports one or more of the WDC_CAPABILITY flags
+.It nchannels
+number of channels supported by this controller
+.It channels
+array of
+.Va struct channel_softc
+of size
+.Va nchannels
+properly initialised
+.El
+The following elements are optional:
+.Bl -tag -compact -width "dma_finish" -offset "xxxx"
+.It pio_mode
+.It dma_mode
+.It dma_arg
+.It dma_init
+.It dma_start
+.It dma_finish
+.It claim_hw
+.It free_hw
+.El
+.Pp
+The
+.Va WDC_CAPABILITY_DATA16
+and
+.Va WDC_CAPABILITY_DATA32
+flags informs
+.Nm
+wether the controller supports 16 and 32 bits I/O accesses on the data port.
+If both are set, a test will be done for each drive using the ATA or
+ATAPI IDENTIFY command, to automatically select the working mode.
+.Pp
+The
+.Va WDC_CAPABILITY_DMA
+and
+.Va WDC_CAPABILITY_UDMA
+flags are set for controllers supporting the DMA and Utra-DMA modes.
+The bus front-end needs to provide the
+.Va dma_init ,
+.Va dma_start
+and
+.Va dma_finish
+functions.
+.Va dma_init
+is called just before issuing a DMA command to the IDE device.
+The arguments are, respectively:
+.Va dma_arg ,
+the channel number, the drive number on this channel,
+the virtual address of the DMA buffer, the size of the transfert, and the
+.Va WDC_DMA
+flags.
+.Va dma_start
+is called just after issuing a DMA command to the IDE device.
+The arguments are, respectively:
+.Va dma_arg ,
+the channel number, the drive number on this channel, and the
+.Va WDC_DMA
+flags.
+.Va dma_finish
+is called once the transfert is complete.
+The arguments are, respectively:
+.Va dma_arg ,
+the channel number, the drive number on this channel, and the
+.Va WDC_DMA
+flags.
+.Va WDC_DMA_READ
+indicates the direction of the data transfert, and
+.Va WDC_DMA_POLL
+indicates if the transfert will use (or used) interrupts.
+.Pp
+The
+.Va WDC_CAPABILITY_MODE
+flag means that the bus front-end can program the PIO and DMA modes, so
+.Nm
+needs to provide back the supported modes for each drives, and set the drives
+modes.
+The
+.Va pio_mode
+and
+.Va dma_mode
+needs to be set to the hightest PIO and DMA mode supported.
+If
+.Va WDC_CAPABILITY_UDMA
+is set, then
+.Va dma_mode
+must be set to the hightest Ultra-DMA mode supported.
+If
+.Va WDC_CAPABILITY_MODE
+is not set,
+.Nm
+will not attempt to change the current drives settings, assuming the host's
+firmware has done it rigth.
+.Pp
+The
+.Va WDC_CAPABILITY_HWLOCK
+flag is set for controllers needing hardware looking before access to the
+I/O ports.
+If this flag is set, the bus front-end needs to provide the
+.Va claim_hw
+and
+.Va free_hw
+functions.
+.Va claim_hw
+will be called when the driver wants to access the controller ports.
+The second parameter is set to 1 when it is possible to sleep wainting
+for the lock, 0 otherwise.
+It should return 1 when access has been granted, 0 otherwise.
+When access has not been granted and sleep is not allowed, the bus
+front-end shall call
+.Va wdcrestart()
+with the first argument passed to
+.Va claim_hw
+as argument.
+This arguments will also be the one passed to
+.Va free_hw.
+This function is called once the transfert is complete, so that the lock can
+be released.
+.Pp
+Access to the data port are done by using the bus_space stream functions,
+unless the
+.Va WDC_CAPABILITY_ATA_NOSTREAM
+or
+.Va WDC_CAPABILITY_ATAPI_NOSTREAM
+flags are set.
+This should not be used, unless the data bus is not wired properly (which
+seems common on big-endian systems), and byte-order needs to be preserved
+for compatibility with the host's firmware.
+Also note that the IDE bus is a little-endian bus, so the bus_space
+functions used for the bus_space tag passed in the
+.Va channel_softc
+have to do the apropriate byte-swapping for big-endian systems.
+.Pp
+.Va WDC_CAPABILITY_NO_EXTRA_RESETS
+avoid the controller reset at the end of the disks probe.
+This reset is needed for some controllers, and cause problems with some
+others.
+.Pp
+The bus front-end needs to fill in the following
+elements of
+.Va channel_softc :
+.Bl -tag -compact -width "dma_finish" -offset "xxxx"
+.It channel
+The channel number on the controller
+.It wdc
+A pointer to the controller's wdc_softc
+.It cmd_iot, cmd_ioh
+Bus-space tag and handle for access to the command block registers (which
+includes the 16-bit data port)
+.It ctl_iot, ctl_ioh
+Bus-space tag and handle for access to the control block registers
+.It ch_queue
+A pointer to a
+.Va struct channel_queue .
+This will hold the queues of outstanding commands for this controller.
+.El
+The following elements are optional:
+.Bl -tag -compact -width "dma_finish" -offset "xxxx"
+.It data32iot, data32ioh
+Bus-space tag and handle for 32-bit data accesses.
+Only needed if
+.Va WDC_CAPABILITY_DATA32
+is set in the controller's
+.Va wdc_softc .
+.El
+.Pp
+.Va ch_queue
+can point to a common
+.Va struct channel_queue
+if the controller doesn't support concurent access to his different channels.
+If each channels are independant, it his recommended that each channel have
+his own
+.Va ch_queue .
+Better performances will result.
+.Pp
+The bus-specific front-end can use the
+.Va wdcprobe()
+function, with a properly inithialised
+.Va struct channel_softc
+as argument (
+.Va wdc
+can be set to NULL.
+This allows
+.Va wdcprobe
+to be easily used in bus front-end probe functions).
+This function will return an integer where bit 0 will be set if the master
+device has been found, and 1 if the slave device has been found.
+.Pp
+The bus-specific's attach function has to call
+.Va wdcattach()
+for each channels, with a pointer to a properly initialised
+.Va channel softc
+as argument.
+This will probe devices attached to the IDE channel and attach them.
+Once this function returns, the
+.Va ch_drive
+array of the
+.Va channel_softc
+will contains the drive's capabilities.
+This can be used to properly initialise the controller's mode, or disable a
+channel without drives.
+.Pp
+The elements of interest in
+.Va ata_drive_datas
+for a bus front-end are:
+.Bl -tag -compact -width "dma_finish" -offset "xxxx"
+.It drive
+The drive number
+.It drive_flags
+Flags indicating the drive capabilities.
+A null
+.Va drive_flags
+indicate either that no drive are here, or that no driver was
+found for this device.
+.It PIO_mode, DMA_mode, UDMA_mode
+the hightest supported modes for this drive compatible with the controller's
+capabilities.
+Needs to be reset to the mode to use by the drive, if known.
+.It drv_softc
+A pointer to the drive's softc.
+Can be used to print the drive's name.
+.El
+.Pp
+.Va drive_flags
+handles the following flags:
+.Bl -tag -compact -width "dma_finish" -offset "xxxx"
+.It DRIVE_ATA, DRIVE_ATAPI
+Gives the drive type, if any.
+The shortcut DRIVE can be used to just test the presence/absence of a drive.
+.It DRIVE_CAP32
+This drive works with 32-bit data I/O.
+.It DRIVE_DMA
+This drive supports DMA
+.It DRIVE_UDMA
+This drive supports Ultra-DMA
+.It DRIVE_MODE
+This drive properly reported its PIO and DMA mode.
+.El
+.Pp
+Once the controller has been initialised, it has to reset the
+.Va DRIVE_DMA
+and
+.Va DRIVE_UDMA ,
+as well as the values of
+.Va PIO_mode ,
+.Va DMA_mode
+and
+.Va UDMA_mode
+if the modes to be used are not hightest ones supported by the drive.
+.Sh SEE ALSO
+.Xr wdc 4
+.Xr bus_space 9
+.Sh CODE REFERENCES
+The wdc core functions are implemented in
+.Pa sys/dev/ic/wdc.c .
+Low-level ATA and ATAPI support is provided by
+.Pa sys/dev/ata_wdc.c
+and
+.Pa sys/dev/scsipi/atapi_wdc.c
+respectively.
+.Pp
+An example of simple bus front-end can be found in
+.Pa sys/dev/isapnp/wdc_isapnp.c .
+A more complex one, with multiple channels and bus-master DMA support is
+.Pa sys/dev/pci/pciide.c .
+.Pa sys/arch/atari/dev/wdc_mb.c
+makes use of hardware locking, and also provides an example of bus-front
+end for a big-endian system, which needs byte-swapping bus_space functions.