sync with head yamt-nfs-mp
authoryamt <yamt@NetBSD.org>
Wed, 16 Sep 2009 13:37:34 +0000
branchyamt-nfs-mp
changeset 278942 80584c82bdad
parent 278941 7ce719a757bf
child 278943 b9ba33e09fe1
sync with head
sys/arch/algor/algor/bus_dma.c
sys/arch/algor/conf/files.algor
sys/arch/alpha/alpha/cpu.c
sys/arch/alpha/alpha/debug.s
sys/arch/alpha/alpha/dec_1000a.c
sys/arch/alpha/alpha/dec_2100_a500.c
sys/arch/alpha/alpha/dec_6600.c
sys/arch/alpha/alpha/dec_kn300.c
sys/arch/alpha/alpha/pmap.c
sys/arch/alpha/common/bus_dma.c
sys/arch/alpha/conf/GENERIC
sys/arch/alpha/conf/files.alpha
sys/arch/alpha/include/types.h
sys/arch/amd64/acpi/acpi_wakecode.S
sys/arch/amd64/conf/GENERIC
sys/arch/amd64/conf/XEN3_DOM0
sys/arch/amiga/amiga/adosglue.h
sys/arch/amiga/amiga/disksubr.c
sys/arch/amiga/amiga/pmap.c
sys/arch/amiga/conf/files.amiga
sys/arch/amiga/dev/clock.c
sys/arch/amiga/include/disklabel.h
sys/arch/amiga/include/vmparam.h
sys/arch/amigappc/include/disklabel.h
sys/arch/arm/footbridge/isa/isa_machdep.c
sys/arch/arm/include/arm32/pmap.h
sys/arch/arm/xscale/pxa2x0_intr.c
sys/arch/atari/atari/atari_init.c
sys/arch/atari/atari/machdep.c
sys/arch/atari/atari/pmap.c
sys/arch/atari/dev/clock.c
sys/arch/atari/include/iomap.h
sys/arch/atari/include/vmparam.h
sys/arch/atari/isa/isa_machdep.c
sys/arch/atari/stand/binpatch/Makefile
sys/arch/atari/stand/binpatch/binpatch.c
sys/arch/atari/stand/bootxx/bootxx.c
sys/arch/atari/stand/bootxx/filesystem.c
sys/arch/atari/stand/bootxxx/bootxxx.c
sys/arch/atari/stand/bootxxx/filesystem.c
sys/arch/cats/conf/Makefile.cats.inc
sys/arch/cesfic/cesfic/machdep.c
sys/arch/cesfic/include/vmparam.h
sys/arch/cobalt/cobalt/bus.c
sys/arch/cobalt/conf/files.cobalt
sys/arch/cobalt/dev/panel.c
sys/arch/cobalt/include/bus.h
sys/arch/dreamcast/conf/GENERIC
sys/arch/dreamcast/dev/g2/g2bus_bus_mem.c
sys/arch/dreamcast/include/bus.h
sys/arch/evbmips/conf/MALTA
sys/arch/evbppc/conf/PMPPC
sys/arch/ews4800mips/conf/files.ews4800mips
sys/arch/ews4800mips/ews4800mips/bus_dma.c
sys/arch/hp300/include/vmparam.h
sys/arch/hpcmips/conf/files.hpcmips
sys/arch/hpcmips/hpcmips/bus_dma.c
sys/arch/hpcmips/vr/vrecu.c
sys/arch/i386/Makefile
sys/arch/i386/acpi/acpi_wakecode.S
sys/arch/i386/conf/ALL
sys/arch/i386/conf/GENERIC
sys/arch/i386/conf/XEN3_DOM0
sys/arch/i386/i386/db_trace.c
sys/arch/i386/i386/ipkdb_glue.c
sys/arch/i386/i386/powernow_k7.c
sys/arch/i386/stand/boot/boot2.c
sys/arch/i386/stand/boot/version
sys/arch/i386/stand/lib/biosdisk.c
sys/arch/i386/stand/lib/bootmenu.c
sys/arch/i386/stand/lib/exec.c
sys/arch/i386/stand/lib/gatea20.c
sys/arch/i386/stand/lib/libi386.h
sys/arch/i386/stand/lib/pcio.c
sys/arch/i386/stand/lib/vbe.c
sys/arch/i386/stand/lib/vbe.h
sys/arch/i386/stand/pxeboot/main.c
sys/arch/ia64/ia64/machdep.c
sys/arch/luna68k/include/vmparam.h
sys/arch/m68k/include/pmap_motorola.h
sys/arch/m68k/m68k/pmap_motorola.c
sys/arch/mac68k/include/vmparam.h
sys/arch/mips/include/proc.h
sys/arch/mips/mips/genassym.cf
sys/arch/mips/mips/vm_machdep.c
sys/arch/mipsco/conf/files.mipsco
sys/arch/mipsco/mipsco/bus_dma.c
sys/arch/mvme68k/include/vmparam.h
sys/arch/mvme68k/stand/bootxx/bootxx.c
sys/arch/news68k/include/vmparam.h
sys/arch/newsmips/conf/files.newsmips
sys/arch/newsmips/newsmips/bus.c
sys/arch/next68k/dev/esp.c
sys/arch/next68k/include/vmparam.h
sys/arch/ofppc/stand/ofwboot/Makefile
sys/arch/ofppc/stand/ofwboot/mbr.c
sys/arch/ofppc/stand/ofwboot/mbr.h
sys/arch/ofppc/stand/ofwboot/ofdev.c
sys/arch/ofppc/stand/ofwboot/ofdev.h
sys/arch/ofppc/stand/ofwboot/rdb.c
sys/arch/ofppc/stand/ofwboot/rdb.h
sys/arch/ofppc/stand/ofwboot/version
sys/arch/playstation2/conf/files.playstation2
sys/arch/playstation2/playstation2/bus_dma.c
sys/arch/pmax/conf/files.pmax
sys/arch/pmax/include/loadfile_machdep.h
sys/arch/pmax/pmax/bus_dma.c
sys/arch/powerpc/include/isa_machdep.h
sys/arch/sgimips/conf/files.sgimips
sys/arch/sgimips/include/loadfile_machdep.h
sys/arch/sgimips/mace/if_mec.c
sys/arch/sgimips/sgimips/bus.c
sys/arch/shark/conf/Makefile.shark.inc
sys/arch/sparc/dev/cgfourteen.c
sys/arch/sparc/sparc/pmap.c
sys/arch/sparc/stand/bootxx/bootxx.c
sys/arch/sparc64/dev/ffb.c
sys/arch/vax/vax/clock.c
sys/arch/x68k/conf/files.x68k
sys/arch/x68k/include/vmparam.h
sys/arch/x68k/x68k/bus.c
sys/arch/x86/acpi/acpi_wakeup.c
sys/arch/x86/include/bootinfo.h
sys/arch/x86/include/vga_post.h
sys/arch/x86/pci/pchb.c
sys/arch/x86/pci/pcib.c
sys/arch/x86/x86/bus_space.c
sys/arch/x86/x86/genfb_machdep.c
sys/arch/x86/x86/powernow_k8.c
sys/arch/x86/x86/vga_post.c
sys/arch/x86/x86/x86_autoconf.c
sys/common/bus_dma/bus_dmamem_common.c
sys/common/bus_dma/bus_dmamem_common.h
sys/compat/irix/irix_fcntl.c
sys/compat/irix/irix_kmem.c
sys/compat/linux/common/linux_sched.c
sys/compat/linux/common/linux_uselib.c
sys/compat/ossaudio/ossaudio.c
sys/compat/sa/compat_sa.c
sys/conf/files
sys/conf/majors
sys/dev/acpi/acpi.c
sys/dev/acpi/acpi_acad.c
sys/dev/acpi/acpi_bat.c
sys/dev/acpi/acpi_button.c
sys/dev/acpi/acpi_lid.c
sys/dev/acpi/acpi_osd.h
sys/dev/acpi/acpi_tz.c
sys/dev/acpi/acpica/OsdEnvironment.c
sys/dev/acpi/acpica/OsdHardware.c
sys/dev/acpi/acpica/OsdSchedule.c
sys/dev/acpi/files.acpi
sys/dev/acpi/pckbc_acpi.c
sys/dev/ata/ata.c
sys/dev/bluetooth/bthidev.c
sys/dev/cardbus/if_ath_cardbus.c
sys/dev/cardbus/if_fxp_cardbus.c
sys/dev/cardbus/if_re_cardbus.c
sys/dev/cardbus/if_rtk_cardbus.c
sys/dev/cardbus/if_rtw_cardbus.c
sys/dev/cgd.c
sys/dev/dkwedge/dk.c
sys/dev/dm/dm_dev.c
sys/dev/dm/dm_ioctl.c
sys/dev/dm/dm_pdev.c
sys/dev/dm/dm_target.c
sys/dev/dm/dm_target_linear.c
sys/dev/dm/dm_target_stripe.c
sys/dev/gpib/cs80bus.c
sys/dev/gpib/ct.c
sys/dev/gpib/gpib.c
sys/dev/gpib/mt.c
sys/dev/gpib/ppi.c
sys/dev/gpib/rd.c
sys/dev/gpio/gpio.c
sys/dev/gpio/gpiovar.h
sys/dev/ic/aic79xx.c
sys/dev/ic/aic79xx_inline.h
sys/dev/ic/aic79xx_osm.c
sys/dev/ic/aic79xx_osm.h
sys/dev/ic/aic79xxvar.h
sys/dev/ic/aic7xxx.c
sys/dev/ic/aic7xxx_osm.c
sys/dev/ic/atw.c
sys/dev/ic/atwvar.h
sys/dev/ic/awi.c
sys/dev/ic/awivar.h
sys/dev/ic/dp83932.c
sys/dev/ic/dp83932var.h
sys/dev/ic/elink3.c
sys/dev/ic/elink3var.h
sys/dev/ic/elinkxl.c
sys/dev/ic/esiop.c
sys/dev/ic/esiopvar.h
sys/dev/ic/hd44780_subr.c
sys/dev/ic/hd44780reg.h
sys/dev/ic/hd44780var.h
sys/dev/ic/hme.c
sys/dev/ic/hmevar.h
sys/dev/ic/i82365.c
sys/dev/ic/i82365var.h
sys/dev/ic/i82557.c
sys/dev/ic/isp_netbsd.c
sys/dev/ic/isp_netbsd.h
sys/dev/ic/lance.c
sys/dev/ic/lancevar.h
sys/dev/ic/mb86960.c
sys/dev/ic/mfi.c
sys/dev/ic/ncr53c9x.c
sys/dev/ic/ncr53c9xreg.h
sys/dev/ic/ncr53c9xvar.h
sys/dev/ic/opl.c
sys/dev/ic/rt2560.c
sys/dev/ic/rt2661.c
sys/dev/ic/rtl8169.c
sys/dev/ic/rtl81x9.c
sys/dev/ic/rtl81x9reg.h
sys/dev/ic/rtl81x9var.h
sys/dev/ic/siop.c
sys/dev/ic/siop_common.c
sys/dev/ic/siopreg.h
sys/dev/ic/siopvar.h
sys/dev/ic/siopvar_common.h
sys/dev/ic/smc83c170.c
sys/dev/ic/smc83c170var.h
sys/dev/ic/tulip.c
sys/dev/ic/tulipreg.h
sys/dev/ic/wi.c
sys/dev/isa/attimer_isa.c
sys/dev/isa/cec.c
sys/dev/isa/i82365_isa.c
sys/dev/isa/i82365_isasubr.c
sys/dev/isa/i82365_isavar.h
sys/dev/isa/isa.c
sys/dev/isa/sbdsp.c
sys/dev/isapnp/isapnp.c
sys/dev/midi.c
sys/dev/mii/rgephy.c
sys/dev/mii/ukphy.c
sys/dev/mscp/mscp_disk.c
sys/dev/pad/files.pad
sys/dev/pad/padvol.c
sys/dev/pci/ahc_pci.c
sys/dev/pci/ahcisata_pci.c
sys/dev/pci/ahd_pci.c
sys/dev/pci/auich.c
sys/dev/pci/auichreg.h
sys/dev/pci/chipsfb.c
sys/dev/pci/files.pci
sys/dev/pci/genfb_pci.c
sys/dev/pci/genfb_pcivar.h
sys/dev/pci/hdaudio/files.hdaudio
sys/dev/pci/hdaudio/hdaudio.c
sys/dev/pci/hdaudio/hdaudio_afg.c
sys/dev/pci/hdaudio/hdaudio_mixer.h
sys/dev/pci/hdaudio/hdaudio_pci.c
sys/dev/pci/hdaudio/hdaudioio.h
sys/dev/pci/hdaudio/hdaudioreg.h
sys/dev/pci/hdaudio/hdaudiovar.h
sys/dev/pci/i82365_pci.c
sys/dev/pci/if_age.c
sys/dev/pci/if_ale.c
sys/dev/pci/if_an_pci.c
sys/dev/pci/if_ath_pci.c
sys/dev/pci/if_bce.c
sys/dev/pci/if_bge.c
sys/dev/pci/if_bnx.c
sys/dev/pci/if_fxp_pci.c
sys/dev/pci/if_gem_pci.c
sys/dev/pci/if_ipw.c
sys/dev/pci/if_iwi.c
sys/dev/pci/if_iwn.c
sys/dev/pci/if_iwnreg.h
sys/dev/pci/if_iwnvar.h
sys/dev/pci/if_lii.c
sys/dev/pci/if_msk.c
sys/dev/pci/if_nfe.c
sys/dev/pci/if_pcn.c
sys/dev/pci/if_re_pci.c
sys/dev/pci/if_rtk_pci.c
sys/dev/pci/if_rtw_pci.c
sys/dev/pci/if_sip.c
sys/dev/pci/if_sk.c
sys/dev/pci/if_stge.c
sys/dev/pci/if_tl.c
sys/dev/pci/if_tlp_pci.c
sys/dev/pci/if_vge.c
sys/dev/pci/if_vr.c
sys/dev/pci/if_wi_pci.c
sys/dev/pci/if_wm.c
sys/dev/pci/if_wpi.c
sys/dev/pci/isp_pci.c
sys/dev/pci/pci.c
sys/dev/pci/pci_quirks.c
sys/dev/pci/pciide_common.c
sys/dev/pci/pcireg.h
sys/dev/pci/pucdata.c
sys/dev/pci/r128fb.c
sys/dev/pci/viaide.c
sys/dev/pci/voodoofb.c
sys/dev/pci/voyagerfb.c
sys/dev/pcmcia/if_an_pcmcia.c
sys/dev/pcmcia/if_awi_pcmcia.c
sys/dev/pcmcia/if_ep_pcmcia.c
sys/dev/pcmcia/if_ne_pcmcia.c
sys/dev/pcmcia/if_ray.c
sys/dev/pcmcia/if_wi_pcmcia.c
sys/dev/rnd.c
sys/dev/sbus/agten.c
sys/dev/sbus/esp_sbus.c
sys/dev/sbus/if_hme_sbus.c
sys/dev/sbus/if_le.c
sys/dev/sbus/if_le_lebuffer.c
sys/dev/sbus/if_le_ledma.c
sys/dev/sbus/isp_sbus.c
sys/dev/sbus/p9100.c
sys/dev/sbus/tcx.c
sys/dev/sun/bt_subr.c
sys/dev/sun/cgsix.c
sys/dev/sun/fbio.h
sys/dev/tc/bba.c
sys/dev/tc/cfb.c
sys/dev/tc/mfb.c
sys/dev/tc/px.c
sys/dev/tc/pxg.c
sys/dev/tc/sfb.c
sys/dev/tc/sfbplus.c
sys/dev/tc/stic.c
sys/dev/tc/tcds.c
sys/dev/tc/tfb.c
sys/dev/tc/xcfb.c
sys/dev/usb/ehci.c
sys/dev/usb/ehcivar.h
sys/dev/usb/if_atu.c
sys/dev/usb/if_atureg.h
sys/dev/usb/if_aue.c
sys/dev/usb/if_auereg.h
sys/dev/usb/if_axe.c
sys/dev/usb/if_axereg.h
sys/dev/usb/if_cdce.c
sys/dev/usb/if_cdcereg.h
sys/dev/usb/if_cuereg.h
sys/dev/usb/if_kue.c
sys/dev/usb/if_udavreg.h
sys/dev/usb/if_urlreg.h
sys/dev/usb/ohci.c
sys/dev/usb/pseye.c
sys/dev/usb/stuirda.c
sys/dev/usb/ubt.c
sys/dev/usb/uhub.c
sys/dev/usb/ukbdmap.c
sys/dev/usb/umass.c
sys/dev/usb/usb.h
sys/dev/usb/usb_port.h
sys/dev/usb/usb_subr.c
sys/dev/usb/usbdi.h
sys/dev/usb/usbdi_util.h
sys/dev/usb/usbdivar.h
sys/dev/wscons/files.wscons
sys/dev/wscons/wsdisplay_vcons_util.c
sys/dev/wscons/wsdisplay_vconsvar.h
sys/dev/wsfb/genfb.c
sys/dev/wsfb/genfbvar.h
sys/dist/pf/net/if_pfsync.c
sys/dist/pf/net/if_pfsync.h
sys/dist/pf/net/pf.c
sys/dist/pf/net/pf_ioctl.c
sys/external/bsd/drm/dist/bsd-core/ati_pcigart.c
sys/external/bsd/drm/dist/bsd-core/drmP.h
sys/external/bsd/drm/dist/bsd-core/drm_bufs.c
sys/external/bsd/drm/dist/bsd-core/drm_drv.c
sys/external/bsd/drm/dist/bsd-core/drm_memory.c
sys/external/bsd/drm/dist/bsd-core/drm_pci.c
sys/external/bsd/drm/dist/shared-core/savage_bci.c
sys/external/intel-public/acpica/dist/tables/tbxfroot.c
sys/fs/adosfs/adosfs.h
sys/fs/adosfs/advfsops.c
sys/fs/adosfs/advnops.c
sys/fs/nilfs/nilfs_vnops.c
sys/fs/ntfs/ntfs_subr.c
sys/fs/ntfs/ntfs_vfsops.c
sys/fs/puffs/puffs_vnops.c
sys/fs/smbfs/Makefile
sys/fs/smbfs/smbfs_vfsops.c
sys/fs/tmpfs/tmpfs_subr.c
sys/fs/tmpfs/tmpfs_vnops.c
sys/fs/udf/udf_vnops.c
sys/kern/init_main.c
sys/kern/init_sysctl.c
sys/kern/kern_auth.c
sys/kern/kern_lwp.c
sys/kern/kern_malloc.c
sys/kern/kern_malloc_debug.c
sys/kern/kern_sysctl.c
sys/kern/kern_time.c
sys/kern/kern_turnstile.c
sys/kern/subr_autoconf.c
sys/kern/subr_devsw.c
sys/kern/subr_disk_open.c
sys/kern/subr_pool.c
sys/kern/subr_tftproot.c
sys/kern/sys_pipe.c
sys/kern/uipc_domain.c
sys/kern/uipc_socket.c
sys/kern/uipc_socket2.c
sys/kern/uipc_usrreq.c
sys/lib/libsa/Makefile
sys/net/files.pf
sys/net/if.c
sys/net/if.h
sys/net/if_gre.c
sys/net/if_tap.c
sys/net/rtsock.c
sys/net80211/ieee80211_input.c
sys/netatalk/aarp.c
sys/netbt/bt_proto.c
sys/netbt/hci.h
sys/netbt/hci_event.c
sys/netbt/hci_ioctl.c
sys/netbt/l2cap.h
sys/netbt/l2cap_misc.c
sys/netbt/rfcomm.h
sys/netbt/rfcomm_session.c
sys/netinet/accf_data.c
sys/netinet/accf_http.c
sys/netinet/igmp.c
sys/netinet/in.c
sys/netinet/in.h
sys/netinet/in_proto.c
sys/netinet/in_selsrc.c
sys/netinet/tcp_input.c
sys/netinet/tcp_usrreq.c
sys/netinet/tcp_var.h
sys/netinet6/in6.c
sys/netinet6/in6.h
sys/netinet6/in6_proto.c
sys/netinet6/nd6.c
sys/netinet6/scope6.c
sys/netsmb/Makefile
sys/netsmb/smb_dev.c
sys/netsmb/smb_iod.c
sys/netsmb/smb_rq.c
sys/netsmb/smb_rq.h
sys/netsmb/smb_trantcp.c
sys/nfs/nfs_srvsocket.c
sys/nfs/nfs_syscalls.c
sys/nfs/nfs_var.h
sys/opencrypto/cryptodev.h
sys/rump/Makefile
sys/rump/Makefile.rump
sys/rump/README.dirs
sys/rump/dev/Makefile.rumpdev
sys/rump/dev/lib/Makefile.inc
sys/rump/dev/lib/libcgd/Makefile
sys/rump/dev/lib/libcgd/component.c
sys/rump/dev/lib/libdisk/Makefile
sys/rump/dev/lib/libdisk/dummy.c
sys/rump/dev/lib/libnetsmb/Makefile
sys/rump/dev/lib/libnetsmb/component.c
sys/rump/dev/lib/libnetsmb/shlib_version
sys/rump/dev/lib/libraidframe/Makefile
sys/rump/dev/lib/libraidframe/component.c
sys/rump/dev/lib/librnd/Makefile
sys/rump/dev/lib/librnd/component.c
sys/rump/dev/lib/librnd/shlib_version
sys/rump/fs/Makefile.rumpfs
sys/rump/fs/lib/Makefile.inc
sys/rump/fs/lib/libsmbfs/Makefile
sys/rump/fs/lib/libsmbfs/shlib_version
sys/rump/include/rump/rumpuser.h
sys/rump/librump/Makefile
sys/rump/librump/rump_domain.c
sys/rump/librump/rump_module.c
sys/rump/librump/rumpdev/Makefile.rumpdev
sys/rump/librump/rumpdev/devnodes.c
sys/rump/librump/rumpdev/rump_dev.c
sys/rump/librump/rumpdev/rump_dev_private.h
sys/rump/librump/rumpkern/Makefile.rumpkern
sys/rump/librump/rumpkern/emul.c
sys/rump/librump/rumpkern/ltsleep.c
sys/rump/librump/rumpkern/pool.c
sys/rump/librump/rumpkern/rump.c
sys/rump/librump/rumpnet/Makefile.rumpnet
sys/rump/librump/rumpnet/net_emul.c
sys/rump/librump/rumpnet/opt/pfsync.h
sys/rump/librump/rumpuser/rumpuser_net.c
sys/rump/librump/rumpuser/rumpuser_pth.c
sys/rump/librump/rumpvfs/Makefile.rumpvfs
sys/rump/librump/rumpvfs/devnodes.c
sys/rump/librump/rumpvfs/rump_vfs_private.h
sys/rump/librump/rumpvfs/rumpfs.c
sys/rump/net/lib/liblocal/Makefile
sys/rump/net/lib/libnet/Makefile
sys/rump/net/lib/libsockin/Makefile
sys/rump/net/lib/libsockin/sockin.c
sys/secmodel/bsd44/secmodel_bsd44_suser.c
sys/secmodel/bsd44/suser.h
sys/secmodel/securelevel/secmodel_securelevel.c
sys/secmodel/securelevel/securelevel.h
sys/sys/Makefile
sys/sys/aout_mids.h
sys/sys/core.h
sys/sys/device.h
sys/sys/disklabel_rdb.h
sys/sys/domain.h
sys/sys/exec_aout.h
sys/sys/kauth.h
sys/sys/malloc.h
sys/sys/param.h
sys/sys/pool.h
sys/sys/savar.h
sys/sys/socket.h
sys/sys/socketvar.h
sys/sys/sockio.h
sys/sys/stat.h
sys/sys/sysctl.h
sys/sys/unistd.h
sys/ufs/ext2fs/ext2fs.h
sys/ufs/ext2fs/ext2fs_alloc.c
sys/ufs/ext2fs/ext2fs_dinode.h
sys/ufs/ext2fs/ext2fs_dir.h
sys/ufs/ext2fs/ext2fs_extern.h
sys/ufs/ext2fs/ext2fs_inode.c
sys/ufs/ext2fs/ext2fs_lookup.c
sys/ufs/ext2fs/ext2fs_readwrite.c
sys/ufs/ext2fs/ext2fs_vfsops.c
sys/ufs/ext2fs/ext2fs_vnops.c
sys/ufs/ffs/ffs_vfsops.c
sys/ufs/ffs/ffs_wapbl.c
sys/ufs/lfs/lfs_alloc.c
sys/ufs/lfs/lfs_syscalls.c
sys/ufs/lfs/lfs_vfsops.c
sys/ufs/ufs/ufs_extern.h
sys/uvm/uvm_aobj.c
sys/uvm/uvm_emap.c
sys/uvm/uvm_map.c
sys/uvm/uvm_pmap.h
sys/uvm/uvm_swap.c
--- a/sys/arch/algor/algor/bus_dma.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/algor/algor/bus_dma.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus_dma.c,v 1.18.44.2 2009/05/04 08:10:27 yamt Exp $	*/
+/*	$NetBSD: bus_dma.c,v 1.18.44.3 2009/09/16 13:37:34 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.18.44.2 2009/05/04 08:10:27 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.18.44.3 2009/09/16 13:37:34 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -51,6 +51,8 @@
 #include <machine/cpu.h>
 #include <machine/locore.h>
 
+#include <common/bus_dma/bus_dmamem_common.h>
+
 /*
  * Common function for DMA map creation.  May be called by bus-specific
  * DMA map creation functions.
@@ -554,54 +556,10 @@
     bus_size_t boundary, bus_dma_segment_t *segs, int nsegs, int *rsegs,
     int flags, paddr_t low, paddr_t high)
 {
-	paddr_t curaddr, lastaddr;
-	struct vm_page *m;    
-	struct pglist mlist;
-	int curseg, error;
 
-	/* Always round the size. */
-	size = round_page(size);
-
-	/*
-	 * Allocate pages from the VM system.
-	 */
-	error = uvm_pglistalloc(size, low, high, alignment, boundary,
-	    &mlist, nsegs, (flags & BUS_DMA_NOWAIT) == 0);
-	if (error)
-		return (error);
-
-	/*
-	 * Compute the location, size, and number of segments actually
-	 * returned by the VM code.
-	 */
-	m = mlist.tqh_first;
-	curseg = 0;
-	lastaddr = segs[curseg].ds_addr = VM_PAGE_TO_PHYS(m);
-	segs[curseg].ds_len = PAGE_SIZE;
-	m = m->pageq.queue.tqe_next;
-
-	for (; m != NULL; m = m->pageq.queue.tqe_next) {
-		curaddr = VM_PAGE_TO_PHYS(m);
-#ifdef DIAGNOSTIC
-		if (curaddr < low || curaddr >= high) {
-			printf("uvm_pglistalloc returned non-sensical"
-			    " address 0x%lx\n", curaddr);
-			panic("_bus_dmamem_alloc");
-		}
-#endif
-		if (curaddr == (lastaddr + PAGE_SIZE))
-			segs[curseg].ds_len += PAGE_SIZE;
-		else {
-			curseg++;
-			segs[curseg].ds_addr = curaddr;
-			segs[curseg].ds_len = PAGE_SIZE;
-		}
-		lastaddr = curaddr;
-	}
-
-	*rsegs = curseg + 1;
-
-	return (0);
+	return (_bus_dmamem_alloc_range_common(t, size, alignment, boundary,
+					       segs, nsegs, rsegs, flags,
+					       low, high));
 }
 
 /*
@@ -611,25 +569,8 @@
 void
 _bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs)
 {
-	struct vm_page *m;
-	bus_addr_t addr;
-	struct pglist mlist;
-	int curseg;
 
-	/*
-	 * Build a list of pages to free back to the VM system.
-	 */
-	TAILQ_INIT(&mlist);
-	for (curseg = 0; curseg < nsegs; curseg++) {
-		for (addr = segs[curseg].ds_addr;
-		    addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
-		    addr += PAGE_SIZE) {
-			m = PHYS_TO_VM_PAGE(addr);
-			TAILQ_INSERT_TAIL(&mlist, m, pageq.queue);
-		}
-	}
-
-	uvm_pglistfree(&mlist);
+	_bus_dmamem_free_common(t, segs, nsegs);
 }
 
 /*
@@ -640,11 +581,6 @@
 _bus_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
     size_t size, void **kvap, int flags)
 {
-	vaddr_t va;
-	bus_addr_t addr;
-	int curseg;
-	const uvm_flag_t kmflags =
-	    (flags & BUS_DMA_NOWAIT) != 0 ? UVM_KMF_NOWAIT : 0;
 
 	/*
 	 * If we're only mapping 1 segment, use K0SEG, to avoid
@@ -658,29 +594,8 @@
 		return (0);
 	}
 
-	size = round_page(size);
-
-	va = uvm_km_alloc(kernel_map, size, 0, UVM_KMF_VAONLY | kmflags);
-
-	if (va == 0)
-		return (ENOMEM);
-
-	*kvap = (void *)va;
-
-	for (curseg = 0; curseg < nsegs; curseg++) {
-		for (addr = segs[curseg].ds_addr;
-		    addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
-		    addr += PAGE_SIZE, va += PAGE_SIZE, size -= PAGE_SIZE) {
-			if (size == 0)
-				panic("_bus_dmamem_map: size botch");
-			pmap_enter(pmap_kernel(), va, addr,
-			    VM_PROT_READ | VM_PROT_WRITE,
-			    PMAP_WIRED | VM_PROT_READ | VM_PROT_WRITE);
-		}
-	}
-	pmap_update(pmap_kernel());
-
-	return (0);
+	/* XXX BUS_DMA_COHERENT */
+	return (_bus_dmamem_map_common(t, segs, nsegs, size, kvap, flags, 0));
 }
 
 /*
@@ -691,11 +606,6 @@
 _bus_dmamem_unmap(bus_dma_tag_t t, void *kva, size_t size)
 {
 
-#ifdef DIAGNOSTIC
-	if ((u_long)kva & PGOFSET)
-		panic("_bus_dmamem_unmap");
-#endif
-
 	/*
 	 * Nothing to do if we mapped it with KSEG0 or KSEG1 (i.e.
 	 * not in KSEG2).
@@ -704,10 +614,7 @@
 	    kva < (void *)MIPS_KSEG2_START)
 		return;
 
-	size = round_page(size);
-	pmap_remove(pmap_kernel(), (vaddr_t)kva, (vaddr_t)kva + size);
-	pmap_update(pmap_kernel());
-	uvm_km_free(kernel_map, (vaddr_t)kva, size, UVM_KMF_VAONLY);
+	_bus_dmamem_unmap_common(t, kva, size);
 }
 
 /*
@@ -718,26 +625,11 @@
 _bus_dmamem_mmap(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
     off_t off, int prot, int flags)
 {
-	int i;
+	bus_addr_t rv;
 
-	for (i = 0; i < nsegs; i++) {
-#ifdef DIAGNOSTIC
-		if (off & PGOFSET)
-			panic("_bus_dmamem_mmap: offset unaligned");
-		if (segs[i].ds_addr & PGOFSET)
-			panic("_bus_dmamem_mmap: segment unaligned");
-		if (segs[i].ds_len & PGOFSET)
-			panic("_bus_dmamem_mmap: segment size not multiple"
-			    " of page size");
-#endif
-		if (off >= segs[i].ds_len) {
-			off -= segs[i].ds_len;
-			continue;
-		}
-
-		return (mips_btop((char *)segs[i].ds_addr + off));
-	}
-
-	/* Page not found. */
-	return (-1);
+	rv = _bus_dmamem_mmap_common(t, segs, nsegs, off, prot, flags);
+	if (rv == (bus_addr_t)-1)
+		return (-1);
+	
+	return (mips_btop((char *)rv));
 }
--- a/sys/arch/algor/conf/files.algor	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/algor/conf/files.algor	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.algor,v 1.24.10.1 2009/08/19 18:45:52 yamt Exp $
+#	$NetBSD: files.algor,v 1.24.10.2 2009/09/16 13:37:34 yamt Exp $
 
 # Algorithmics evaluation board specific configuration info.
 
@@ -45,6 +45,8 @@
 file	arch/mips/mips/mips3_clock.c
 file	arch/mips/mips/mips3_clockintr.c
 
+file	common/bus_dma/bus_dmamem_common.c
+
 #
 # The autoconfiguration root.
 #
--- a/sys/arch/alpha/alpha/cpu.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/alpha/alpha/cpu.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.81.4.2 2009/05/04 08:10:27 yamt Exp $ */
+/* $NetBSD: cpu.c,v 1.81.4.3 2009/09/16 13:37:34 yamt Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.81.4.2 2009/05/04 08:10:27 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.81.4.3 2009/09/16 13:37:34 yamt Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -331,6 +331,12 @@
 		 * on its merry way.
 		 */
 		cpu_boot_secondary(ci);
+
+		/*
+		 * Link the processor into the list.
+		 */
+		ci->ci_next = cpu_info_list->ci_next;
+		cpu_info_list->ci_next = ci;
 #else /* ! MULTIPROCESSOR */
 		printf("%s: processor off-line; multiprocessor support "
 		    "not present in kernel\n", sc->sc_dev.dv_xname);
@@ -404,10 +410,8 @@
 		}
 
 		/*
-		 * Link the processor into the list, and launch it.
+		 * Launch the processor.
 		 */
-		ci->ci_next = cpu_info_list->ci_next;
-		cpu_info_list->ci_next = ci;
 		atomic_or_ulong(&ci->ci_flags, CPUF_RUNNING);
 		atomic_or_ulong(&cpus_running, (1U << i));
 	}
--- a/sys/arch/alpha/alpha/debug.s	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/alpha/alpha/debug.s	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.s,v 1.10.108.1 2008/05/16 02:21:44 yamt Exp $ */
+/* $NetBSD: debug.s,v 1.10.108.2 2009/09/16 13:37:34 yamt Exp $ */
 
 /*-
  * Copyright (c) 1999, 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-__KERNEL_RCSID(6, "$NetBSD: debug.s,v 1.10.108.1 2008/05/16 02:21:44 yamt Exp $")
+__KERNEL_RCSID(6, "$NetBSD: debug.s,v 1.10.108.2 2009/09/16 13:37:34 yamt Exp $")
 
 #include "opt_multiprocessor.h"
 #include "opt_kgdb.h"
@@ -47,7 +47,8 @@
  */
 #define	DEBUG_STACK_SIZE	8192
 BSS(debug_stack_bottom, DEBUG_STACK_SIZE)
-ABS(debug_stack_top, debug_stack_bottom + DEBUG_STACK_SIZE)
+
+#define debug_stack_top		(debug_stack_bottom + DEBUG_STACK_SIZE)
 
 /*
  * alpha_debug:
--- a/sys/arch/alpha/alpha/dec_1000a.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/alpha/alpha/dec_1000a.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dec_1000a.c,v 1.25.44.2 2009/05/04 08:10:27 yamt Exp $ */
+/* $NetBSD: dec_1000a.c,v 1.25.44.3 2009/09/16 13:37:34 yamt Exp $ */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: dec_1000a.c,v 1.25.44.2 2009/05/04 08:10:27 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dec_1000a.c,v 1.25.44.3 2009/09/16 13:37:34 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -98,6 +98,9 @@
 #include <dev/scsipi/scsipi_all.h>
 #include <dev/scsipi/scsiconf.h>
 
+#include <dev/ic/mlxio.h>
+#include <dev/ic/mlxvar.h>
+
 #include "pckbd.h"
 
 #ifndef CONSPEED
@@ -255,7 +258,8 @@
 		return;
 
 	if (!initted) {
-		diskboot = (strcasecmp(b->protocol, "SCSI") == 0);
+		diskboot = (strcasecmp(b->protocol, "SCSI") == 0) ||
+		    (strcasecmp(b->protocol, "RAID") == 0);
 		netboot = (strcasecmp(b->protocol, "BOOTP") == 0) ||
 		    (strcasecmp(b->protocol, "MOP") == 0);
 #if 0
@@ -335,4 +339,25 @@
 #endif
 		found = 1;
 	}
+
+	if (device_is_a(dev, "ld") && device_is_a(parent, "mlx")) {
+		/*
+		 * Argh!  The attach arguments for ld devices is not
+		 * consistent, so each supported raid controller requires
+		 * different checks.
+		 */
+		struct mlx_attach_args *mlxa = aux;
+
+		if (parent != ctrlrdev)
+			return;
+
+		if (b->unit != mlxa->mlxa_unit)
+			return;
+		/* we've found it! */
+		booted_device = dev;
+#if 0
+		printf("\nbooted_device = %s\n", dev->dv_xname);
+#endif
+		found = 1;
+	}
 }
--- a/sys/arch/alpha/alpha/dec_2100_a500.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/alpha/alpha/dec_2100_a500.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dec_2100_a500.c,v 1.17.44.1 2008/05/16 02:21:44 yamt Exp $ */
+/* $NetBSD: dec_2100_a500.c,v 1.17.44.2 2009/09/16 13:37:34 yamt Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: dec_2100_a500.c,v 1.17.44.1 2008/05/16 02:21:44 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dec_2100_a500.c,v 1.17.44.2 2009/09/16 13:37:34 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -92,6 +92,9 @@
 #include <dev/scsipi/scsipi_all.h>
 #include <dev/scsipi/scsiconf.h>
 
+#include <dev/ic/mlxio.h>
+#include <dev/ic/mlxvar.h>
+
 #include "pckbd.h"
 
 #ifndef CONSPEED
@@ -243,7 +246,8 @@
 		return;
 
 	if (!initted) {
-		diskboot = (strcasecmp(b->protocol, "SCSI") == 0);
+		diskboot = (strcasecmp(b->protocol, "SCSI") == 0) ||
+		    (strcasecmp(b->protocol, "RAID") == 0);
 		netboot = (strcasecmp(b->protocol, "BOOTP") == 0) ||
 		    (strcasecmp(b->protocol, "MOP") == 0);
 #if 0
@@ -323,6 +327,27 @@
 #endif
 		found = 1;
 	}
+
+	if (device_is_a(dev, "ld") && device_is_a(parent, "mlx")) {
+		/*
+		 * Argh!  The attach arguments for ld devices is not
+		 * consistent, so each supported raid controller requires
+		 * different checks.
+		 */
+		struct mlx_attach_args *mlxa = aux;
+
+		if (parent != ctrlrdev)
+			return;
+
+		if (b->unit != mlxa->mlxa_unit)
+			return;
+		/* we've found it! */
+		booted_device = dev;
+#if 0
+		printf("\nbooted_device = %s\n", dev->dv_xname);
+#endif
+		found = 1;
+	}
 }
 
 /*
--- a/sys/arch/alpha/alpha/dec_6600.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/alpha/alpha/dec_6600.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dec_6600.c,v 1.26.44.1 2009/05/04 08:10:28 yamt Exp $ */
+/* $NetBSD: dec_6600.c,v 1.26.44.2 2009/09/16 13:37:34 yamt Exp $ */
 
 /*
  * Copyright (c) 1995, 1996, 1997 Carnegie-Mellon University.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: dec_6600.c,v 1.26.44.1 2009/05/04 08:10:28 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dec_6600.c,v 1.26.44.2 2009/09/16 13:37:34 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -63,6 +63,13 @@
 #include <dev/scsipi/scsiconf.h>
 #include <dev/ata/atavar.h>
 
+#include <dev/ic/mlxio.h>
+#include <dev/ic/mlxvar.h>
+
+#include <dev/i2o/i2o.h>
+#include <dev/i2o/iopio.h>
+#include <dev/i2o/iopvar.h>
+
 #include "pckbd.h"
 
 #ifndef CONSPEED
@@ -190,6 +197,8 @@
 
 	if (!initted) {
 		diskboot = (strcasecmp(b->protocol, "SCSI") == 0) ||
+		    (strcasecmp(b->protocol, "RAID") == 0) ||
+		    (strcasecmp(b->protocol, "I2O") == 0) ||
 		    (strcasecmp(b->protocol, "IDE") == 0);
 		netboot = (strcasecmp(b->protocol, "BOOTP") == 0) ||
 		    (strcasecmp(b->protocol, "MOP") == 0);
@@ -290,6 +299,44 @@
 		found = 1;
 	}
 
+	if (device_is_a(dev, "ld") && device_is_a(parent, "iop")) {
+		/*
+		 * Argh!  The attach arguments for ld devices is not
+		 * consistent, so each supported raid controller requires
+		 * different checks.
+		 */
+		struct iop_attach_args *iopa = aux;
+
+		if (parent != ctrlrdev)
+			return;
+
+		if (b->unit != iopa->ia_tid)
+			return;
+		/* we've found it! */
+		booted_device = dev;
+		DR_VERBOSE(printf("\nbooted_device = %s\n", dev->dv_xname));
+		found = 1;
+	}
+
+	if (device_is_a(dev, "ld") && device_is_a(parent, "mlx")) {
+		/*
+		 * Argh!  The attach arguments for ld devices is not
+		 * consistent, so each supported raid controller requires
+		 * different checks.
+		 */
+		struct mlx_attach_args *mlxa = aux;
+
+		if (parent != ctrlrdev)
+			return;
+
+		if (b->unit != mlxa->mlxa_unit)
+			return;
+		/* we've found it! */
+		booted_device = dev;
+		DR_VERBOSE(printf("\nbooted_device = %s\n", dev->dv_xname));
+		found = 1;
+	}
+
 	/*
 	 * Support to boot from IDE drives.
 	 */
--- a/sys/arch/alpha/alpha/dec_kn300.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/alpha/alpha/dec_kn300.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dec_kn300.c,v 1.34.44.1 2009/05/04 08:10:28 yamt Exp $ */
+/* $NetBSD: dec_kn300.c,v 1.34.44.2 2009/09/16 13:37:34 yamt Exp $ */
 
 /*
  * Copyright (c) 1998 by Matthew Jacob
@@ -34,7 +34,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: dec_kn300.c,v 1.34.44.1 2009/05/04 08:10:28 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dec_kn300.c,v 1.34.44.2 2009/09/16 13:37:34 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -72,6 +72,9 @@
 #include <dev/scsipi/scsipi_all.h>
 #include <dev/scsipi/scsiconf.h>
 
+#include <dev/ic/mlxio.h>
+#include <dev/ic/mlxvar.h>
+
 
 #include "pckbd.h"
 
@@ -229,7 +232,8 @@
 		return;
 
 	if (!initted) {
-		diskboot = (strcasecmp(b->protocol, "SCSI") == 0);
+		diskboot = (strcasecmp(b->protocol, "SCSI") == 0) ||
+		    (strcasecmp(b->protocol, "RAID") == 0);
 		netboot = (strcasecmp(b->protocol, "BOOTP") == 0) ||
 		    (strcasecmp(b->protocol, "MOP") == 0);
 #ifdef BDEBUG
@@ -345,6 +349,27 @@
 #endif
 		found = 1;
 	}
+
+	if (device_is_a(dev, "ld") && device_is_a(parent, "mlx")) {
+		/*
+		 * Argh!  The attach arguments for ld devices is not
+		 * consistent, so each supported raid controller requires
+		 * different checks.
+		 */
+		struct mlx_attach_args *mlxa = aux;
+
+		if (parent != ctrlrdev)
+			return;
+
+		if (b->unit != mlxa->mlxa_unit)
+			return;
+		/* we've found it! */
+		booted_device = dev;
+#if 0
+		printf("\nbooted_device = %s\n", dev->dv_xname);
+#endif
+		found = 1;
+	}
 }
 
 
--- a/sys/arch/alpha/alpha/pmap.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/alpha/alpha/pmap.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.235.4.3 2009/08/19 18:45:53 yamt Exp $ */
+/* $NetBSD: pmap.c,v 1.235.4.4 2009/09/16 13:37:34 yamt Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001, 2007, 2008 The NetBSD Foundation, Inc.
@@ -140,7 +140,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.235.4.3 2009/08/19 18:45:53 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.235.4.4 2009/09/16 13:37:34 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -422,11 +422,11 @@
 
 static struct pmap_tlb_shootdown_q {
 	TAILQ_HEAD(, pmap_tlb_shootdown_job) pq_head;	/* queue 16b */
-	kmutex_t pq_lock;		/* spin lock on queue 12b */
+	kmutex_t pq_lock;		/* spin lock on queue 16b */
 	int pq_pte;			/* aggregate PTE bits 4b */
 	int pq_count;			/* number of pending requests 4b */
 	int pq_tbia;			/* pending global flush 4b */
-	uint8_t pq_pad[64-16-12-4-4-4];	/* pad to 64 bytes */
+	uint8_t pq_pad[64-16-16-4-4-4];	/* pad to 64 bytes */
 } pmap_tlb_shootdown_q[ALPHA_MAXPROCS] __aligned(CACHE_LINE_SIZE);
 
 /* If we have more pending jobs than this, we just nail the whole TLB. */
@@ -3680,6 +3680,8 @@
 			continue;
 		}
 
+		cpumask |= 1UL << ci->ci_cpuid;
+
 		pq = &pmap_tlb_shootdown_q[ci->ci_cpuid];
 
 		/*
@@ -3719,7 +3721,6 @@
 			pq->pq_count++;
 			TAILQ_INSERT_TAIL(&pq->pq_head, pj, pj_list);
 		}
-		cpumask |= 1UL << ci->ci_cpuid;
 		mutex_spin_exit(&pq->pq_lock);
 	}
 
--- a/sys/arch/alpha/common/bus_dma.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/alpha/common/bus_dma.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bus_dma.c,v 1.64.44.2 2009/05/04 08:10:28 yamt Exp $ */
+/* $NetBSD: bus_dma.c,v 1.64.44.3 2009/09/16 13:37:34 yamt Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.64.44.2 2009/05/04 08:10:28 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.64.44.3 2009/09/16 13:37:34 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -48,6 +48,8 @@
 #include <machine/bus.h>
 #include <machine/intr.h>
 
+#include <common/bus_dma/bus_dmamem_common.h>
+
 int	_bus_dmamap_load_buffer_direct(bus_dma_tag_t,
 	    bus_dmamap_t, void *, bus_size_t, struct vmspace *, int,
 	    paddr_t *, int *, int);
@@ -476,54 +478,10 @@
     bus_size_t boundary, bus_dma_segment_t *segs, int nsegs, int *rsegs,
     int flags, paddr_t low, paddr_t high)
 {
-	paddr_t curaddr, lastaddr;
-	struct vm_page *m;    
-	struct pglist mlist;
-	int curseg, error;
 
-	/* Always round the size. */
-	size = round_page(size);
-
-	/*
-	 * Allocate pages from the VM system.
-	 */
-	error = uvm_pglistalloc(size, low, high, alignment, boundary,
-	    &mlist, nsegs, (flags & BUS_DMA_NOWAIT) == 0);
-	if (error)
-		return (error);
-
-	/*
-	 * Compute the location, size, and number of segments actually
-	 * returned by the VM code.
-	 */
-	m = mlist.tqh_first;
-	curseg = 0;
-	lastaddr = segs[curseg].ds_addr = VM_PAGE_TO_PHYS(m);
-	segs[curseg].ds_len = PAGE_SIZE;
-	m = m->pageq.queue.tqe_next;
-
-	for (; m != NULL; m = m->pageq.queue.tqe_next) {
-		curaddr = VM_PAGE_TO_PHYS(m);
-#ifdef DIAGNOSTIC
-		if (curaddr < avail_start || curaddr >= high) {
-			printf("uvm_pglistalloc returned non-sensical"
-			    " address 0x%lx\n", curaddr);
-			panic("_bus_dmamem_alloc");
-		}
-#endif
-		if (curaddr == (lastaddr + PAGE_SIZE))
-			segs[curseg].ds_len += PAGE_SIZE;
-		else {
-			curseg++;
-			segs[curseg].ds_addr = curaddr;
-			segs[curseg].ds_len = PAGE_SIZE;
-		}
-		lastaddr = curaddr;
-	}
-
-	*rsegs = curseg + 1;
-
-	return (0);
+	return (_bus_dmamem_alloc_range_common(t, size, alignment, boundary,
+					       segs, nsegs, rsegs, flags,
+					       low, high));
 }
 
 /*
@@ -533,25 +491,8 @@
 void
 _bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs)
 {
-	struct vm_page *m;
-	bus_addr_t addr;
-	struct pglist mlist;
-	int curseg;
 
-	/*
-	 * Build a list of pages to free back to the VM system.
-	 */
-	TAILQ_INIT(&mlist);
-	for (curseg = 0; curseg < nsegs; curseg++) {
-		for (addr = segs[curseg].ds_addr;
-		    addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
-		    addr += PAGE_SIZE) {
-			m = PHYS_TO_VM_PAGE(addr);
-			TAILQ_INSERT_TAIL(&mlist, m, pageq.queue);
-		}
-	}
-
-	uvm_pglistfree(&mlist);
+	_bus_dmamem_free_common(t, segs, nsegs);
 }
 
 /*
@@ -562,11 +503,6 @@
 _bus_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
     size_t size, void **kvap, int flags)
 {
-	vaddr_t va;
-	bus_addr_t addr;
-	int curseg;
-	const uvm_flag_t kmflags =
-	    (flags & BUS_DMA_NOWAIT) != 0 ? UVM_KMF_NOWAIT : 0;
 
 	/*
 	 * If we're only mapping 1 segment, use K0SEG, to avoid
@@ -577,29 +513,7 @@
 		return (0);
 	}
 
-	size = round_page(size);
-
-	va = uvm_km_alloc(kernel_map, size, 0, UVM_KMF_VAONLY | kmflags);
-
-	if (va == 0)
-		return (ENOMEM);
-
-	*kvap = (void *)va;
-
-	for (curseg = 0; curseg < nsegs; curseg++) {
-		for (addr = segs[curseg].ds_addr;
-		    addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
-		    addr += PAGE_SIZE, va += PAGE_SIZE, size -= PAGE_SIZE) {
-			if (size == 0)
-				panic("_bus_dmamem_map: size botch");
-			pmap_enter(pmap_kernel(), va, addr,
-			    VM_PROT_READ | VM_PROT_WRITE,
-			    PMAP_WIRED | VM_PROT_READ | VM_PROT_WRITE);
-		}
-	}
-	pmap_update(pmap_kernel());
-
-	return (0);
+	return (_bus_dmamem_map_common(t, segs, nsegs, size, kvap, flags, 0));
 }
 
 /*
@@ -610,11 +524,6 @@
 _bus_dmamem_unmap(bus_dma_tag_t t, void *kva, size_t size)
 {
 
-#ifdef DIAGNOSTIC
-	if ((u_long)kva & PGOFSET)
-		panic("_bus_dmamem_unmap");
-#endif
-
 	/*
 	 * Nothing to do if we mapped it with K0SEG.
 	 */
@@ -622,10 +531,7 @@
 	    kva <= (void *)ALPHA_K0SEG_END)
 		return;
 
-	size = round_page(size);
-	pmap_remove(pmap_kernel(), (vaddr_t)kva, (vaddr_t)kva + size);
-	pmap_update(pmap_kernel());
-	uvm_km_free(kernel_map, (vaddr_t)kva, size, UVM_KMF_VAONLY);
+	_bus_dmamem_unmap_common(t, kva, size);
 }
 
 /*
@@ -636,26 +542,11 @@
 _bus_dmamem_mmap(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
     off_t off, int prot, int flags)
 {
-	int i;
+	bus_addr_t rv;
 
-	for (i = 0; i < nsegs; i++) {
-#ifdef DIAGNOSTIC
-		if (off & PGOFSET)
-			panic("_bus_dmamem_mmap: offset unaligned");
-		if (segs[i].ds_addr & PGOFSET)
-			panic("_bus_dmamem_mmap: segment unaligned");
-		if (segs[i].ds_len & PGOFSET)
-			panic("_bus_dmamem_mmap: segment size not multiple"
-			    " of page size");
-#endif
-		if (off >= segs[i].ds_len) {
-			off -= segs[i].ds_len;
-			continue;
-		}
+	rv = _bus_dmamem_mmap_common(t, segs, nsegs, off, prot, flags);
+	if (rv == (bus_addr_t)-1)
+		return (-1);
 
-		return (alpha_btop((char *)segs[i].ds_addr + off));
-	}
-
-	/* Page not found. */
-	return (-1);
+	return (alpha_btop((char *)rv));
 }
--- a/sys/arch/alpha/conf/GENERIC	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/alpha/conf/GENERIC	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.322.10.1 2009/05/04 08:10:28 yamt Exp $
+# $NetBSD: GENERIC,v 1.322.10.2 2009/09/16 13:37:35 yamt Exp $
 #
 # This machine description file is used to generate the default NetBSD
 # kernel.
@@ -19,7 +19,7 @@
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-ident		"GENERIC-$Revision: 1.322.10.1 $"
+ident		"GENERIC-$Revision: 1.322.10.2 $"
 
 maxusers 32
 
@@ -386,6 +386,13 @@
 mpu*	at	eso?
 mpu*	at	yds?
 
+# I2O devices
+iop*	at pci? dev ? function ?	# I/O processor
+iopsp*	at iop? tid ?			# SCSI/FC-AL ports
+ld*	at iop? tid ?			# block devices
+# XXX dpti.c wants a processor type that is not assigned for x86-64
+#dpti*	at iop? tid 0			# DPT/Adaptec control interface
+
 # MII/PHY support
 exphy*	at mii? phy ?			# 3Com internal PHYs
 icsphy*	at mii? phy ?			# Integrated Circuit Systems ICS189x
--- a/sys/arch/alpha/conf/files.alpha	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/alpha/conf/files.alpha	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.alpha,v 1.179.10.1 2009/05/04 08:10:28 yamt Exp $
+# $NetBSD: files.alpha,v 1.179.10.2 2009/09/16 13:37:35 yamt Exp $
 #
 # alpha-specific configuration info
 
@@ -422,6 +422,8 @@
 file	dev/cons.c
 file	kern/kern_cctr.c
 
+file	common/bus_dma/bus_dmamem_common.c
+
 # PROM console support (for ports that don't have native console support)
 file	arch/alpha/alpha/promcons.c
 
--- a/sys/arch/alpha/include/types.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/alpha/include/types.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.40 2008/01/20 18:09:04 joerg Exp $ */
+/* $NetBSD: types.h,v 1.40.10.1 2009/09/16 13:37:35 yamt Exp $ */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -50,9 +50,16 @@
 typedef unsigned long	psize_t;
 typedef unsigned long	vaddr_t;
 typedef unsigned long	vsize_t;
+#define	PRTxPADDR	"lx"
+#define	PRTxPSIZE	"lx"
+#define	PRTxVADDR	"lx"
+#define	PRTxVSIZE	"lx"
 #endif
 
 typedef long int	register_t;
+#if defined(_NETBSD_SOURCE)
+#define	PRTxREGISTER	"lx"
+#endif
 
 typedef	volatile int		__cpu_simple_lock_t;
 
--- a/sys/arch/amd64/acpi/acpi_wakecode.S	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/amd64/acpi/acpi_wakecode.S	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_wakecode.S,v 1.3.14.2 2009/05/04 08:10:32 yamt Exp $	*/
+/*	$NetBSD: acpi_wakecode.S,v 1.3.14.3 2009/09/16 13:37:35 yamt Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger <joerg@netbsd.org>
@@ -115,6 +115,18 @@
 	movw	%cs,%ax
 	movw	%ax,%ds
 	movw	%ax,%ss
+
+	/* If we need to restore a VESA VBE mode, do it now */
+	cmpb	$0,WAKEUP_vesa_modenum
+	je	1f
+	movw	WAKEUP_vesa_modenum,%bx
+	orw	$0x4000,%bx
+	movw	$0x4f02,%ax
+	int	$0x10
+
+	movw	%cs,%ax
+	movw	%ax,%ds
+	movw	%ax,%ss
 1:
 
 	/* Disable beep again if machdep.acpi_beep_on_reset=1 */
@@ -253,6 +265,8 @@
 
 	.global WAKEUP_vbios_reset
 WAKEUP_vbios_reset:	.byte 0
+	.global WAKEUP_vesa_modenum
+WAKEUP_vesa_modenum:    .word 0
 	.global WAKEUP_beep_on_reset
 WAKEUP_beep_on_reset:	.byte 0
 
--- a/sys/arch/amd64/conf/GENERIC	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/amd64/conf/GENERIC	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.205.2.4 2009/08/19 18:45:55 yamt Exp $
+# $NetBSD: GENERIC,v 1.205.2.5 2009/09/16 13:37:35 yamt Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		"GENERIC-$Revision: 1.205.2.4 $"
+#ident 		"GENERIC-$Revision: 1.205.2.5 $"
 
 maxusers	64		# estimated number of users
 
@@ -954,6 +954,10 @@
 opl*	at fms?
 opl*	at sv?
 
+# High Definition Audio
+hdaudio*	at pci? dev ? function ?	# High Definition Audio
+hdafg*		at hdaudiobus?
+
 # Audio support
 audio*	at audiobus?
 
--- a/sys/arch/amd64/conf/XEN3_DOM0	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/amd64/conf/XEN3_DOM0	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: XEN3_DOM0,v 1.15.2.3 2009/08/19 18:45:55 yamt Exp $
+# $NetBSD: XEN3_DOM0,v 1.15.2.4 2009/09/16 13:37:35 yamt Exp $
 
 include 	"arch/amd64/conf/std.xen"
 
@@ -683,6 +683,10 @@
 opl*	at sv?
 opl*	at yds?
 
+# High Definition Audio
+hdaudio*	at pci? dev ? function ?	# High Definition Audio
+hdafg*		at hdaudiobus?
+
 # Audio support
 audio*	at audiobus?
 
--- a/sys/arch/amiga/amiga/adosglue.h	Wed Aug 19 18:45:51 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-/*	$NetBSD: adosglue.h,v 1.8 2006/11/24 19:38:55 christos Exp $	*/
-
-/*
- * Copyright (c) 1994 Christian E. Hopps
- * 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 Christian E. Hopps.
- * 4. 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.
- */
-#ifndef _ADOSGLUE_H_
-#define _ADOSGLUE_H_
-
-/*
- * Dos types for identifying file systems
- * bsd file systems will be 'N','B',x,y where y is the fstype found in
- * disklabel.h (for DOST_DOS it will be the version number)
- */
-#define DOST_XXXBSD	0x42534400	/* Old type back compat*/
-#define DOST_NBR	0x4e425200	/* 'NBRx' NetBSD root partition */
-#define DOST_NBS	0x4e425300	/* 'NBS0' NetBSD swap partition */
-#define DOST_NBU	0x4e425500	/* 'NBUx' NetBSD user partition */
-#define DOST_DOS	0x444f5300	/* 'DOSx' AmigaDos partition */
-#define DOST_AMIX	0x554e4900	/* 'UNIx' AmigaDos partition */
-#define DOST_MUFS	0x6d754600	/* 'muFx' AmigaDos partition (muFS) */
-#define DOST_EXT2	0x4c4e5800	/* 'LNX0' Linux fs partition (ext2fs) */
-#define DOST_LNXSWP	0x53575000	/* 'SWP0' Linux swap partition */
-#define DOST_RAID	0x52414900	/* 'RAID' Raidframe partition */
-
-struct adostype {
-	u_char archtype;	/* see ADT_xxx below */
-	u_char fstype;		/* byte 3 from amiga dostype */
-};
-
-/* archtypes */
-#define ADT_UNKNOWN	0
-#define ADT_AMIGADOS	1
-#define ADT_NETBSDROOT	2
-#define ADT_NETBSDSWAP	3
-#define ADT_NETBSDUSER	4
-#define ADT_AMIX	5
-#define ADT_EXT2	6
-#define ADT_RAID	7
-
-#define ISFSARCH_NETBSD(adt) \
-	((adt).archtype >= ADT_NETBSDROOT && (adt).archtype <= ADT_NETBSDUSER)
-
-#endif /* _ADOSGLUE_H_ */
--- a/sys/arch/amiga/amiga/disksubr.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/amiga/amiga/disksubr.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: disksubr.c,v 1.56.10.1 2009/05/04 08:10:33 yamt Exp $	*/
+/*	$NetBSD: disksubr.c,v 1.56.10.2 2009/09/16 13:37:35 yamt Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
@@ -66,14 +66,13 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.56.10.1 2009/05/04 08:10:33 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.56.10.2 2009/09/16 13:37:35 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/buf.h>
 #include <sys/disklabel.h>
 #include <sys/disk.h>
-#include <amiga/amiga/adosglue.h>
 
 /*
  * In /usr/src/sys/dev/scsipi/sd.c, routine sdstart() adjusts the
--- a/sys/arch/amiga/amiga/pmap.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/amiga/amiga/pmap.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.135.10.3 2009/08/19 18:45:55 yamt Exp $	*/
+/*	$NetBSD: pmap.c,v 1.135.10.4 2009/09/16 13:37:35 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -100,7 +100,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.135.10.3 2009/08/19 18:45:55 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.135.10.4 2009/09/16 13:37:35 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -273,7 +273,19 @@
 st_entry_t	*Segtabzero, *Segtabzeropa;
 vsize_t		Sysptsize = VM_KERNEL_PT_PAGES;
 
-struct pv_entry	*pv_table;	/* array of entries, one per page */
+struct pv_header {
+	struct pv_entry		pvh_first;	/* first PV entry */
+	uint16_t		pvh_attrs;	/* attributes:
+						   bits 0-7: PTE bits
+						   bits 8-15: flags */
+	uint16_t		pvh_cimappings;	/* # caller-specified CI
+						   mappings */
+};
+
+#define	PVH_CI		0x10	/* all entries are cache-inhibited */
+#define	PVH_PTPAGE	0x20	/* entry maps a page table page */
+
+struct pv_header *pv_table;	/* array of entries, one per page */
 
 static struct pmap kernel_pmap_store;
 struct pmap	*const kernel_pmap_ptr = &kernel_pmap_store;
@@ -287,7 +299,6 @@
 vaddr_t		virtual_end;	/* VA of last avail page (end of kernel AS) */
 int		page_cnt;	/* number of pages managed by the VM system */
 bool		pmap_initialized = false;	/* Has pmap_init completed? */
-char		*pmap_attributes;	/* reference and modify bits */
 TAILQ_HEAD(pv_page_list, pv_page) pv_page_freelist;
 int		pv_nfree;
 #if defined(M68040) || defined(M68060)
@@ -323,25 +334,13 @@
 
 #define	PAGE_IS_MANAGED(pa)	(pmap_initialized && uvm_pageismanaged(pa))
 
-static inline struct pv_entry *pa_to_pvh(paddr_t pa);
-static inline char *pa_to_attribute(paddr_t pa);
-
-static inline struct pv_entry *
+static inline struct pv_header *
 pa_to_pvh(paddr_t pa)
 {
 	int bank, pg = 0;	/* XXX gcc4 -Wuninitialized */
 
 	bank = vm_physseg_find(atop((pa)), &pg);
-	return &vm_physmem[bank].pmseg.pvent[pg];
-}
-
-static inline char *
-pa_to_attribute(paddr_t pa)
-{
-	int bank, pg = 0;	/* XXX gcc4 -Wuninitialized */
-
-	bank = vm_physseg_find(atop((pa)), &pg);
-	return &vm_physmem[bank].pmseg.attrs[pg];
+	return &vm_physmem[bank].pmseg.pvheader[pg];
 }
 
 /*
@@ -355,8 +354,7 @@
 	vaddr_t		addr, addr2;
 	vsize_t		s;
 	u_int		npg;
-	struct pv_entry *pv;
-	char            *attr;
+	struct pv_header *pvh;
 	int             rv, bank;
 #if defined(M68060)
 	struct kpt_page *kptp;
@@ -397,8 +395,7 @@
 #endif
 	}
 	s = M68K_STSIZE;				/* Segtabzero */
-	s += page_cnt * sizeof(struct pv_entry);	/* pv table */
-	s += page_cnt * sizeof(char);			/* attribute table */
+	s += page_cnt * sizeof(struct pv_header);	/* pv table */
 	s = round_page(s);
 
 	addr = uvm_km_alloc(kernel_map, s, 0, UVM_KMF_WIRED | UVM_KMF_ZERO);
@@ -408,30 +405,26 @@
 	(void) pmap_extract(pmap_kernel(), addr, (paddr_t *)(void *)&Segtabzeropa);
 	addr += M68K_STSIZE;
 
-	pv_table = (struct pv_entry *) addr;
-	addr += page_cnt * sizeof(struct pv_entry);
+	pv_table = (struct pv_header *) addr;
+	addr += page_cnt * sizeof(struct pv_header);
 
-	pmap_attributes = (char *) addr;
 #ifdef DEBUG
 	if (pmapdebug & PDB_INIT)
 		printf("pmap_init: %lx bytes: page_cnt %x s0 %p(%p) "
-			"tbl %p atr %p\n",
+			"tbl %p\n",
 			s, page_cnt, Segtabzero, Segtabzeropa,
-			pv_table, pmap_attributes);
+			pv_table);
 #endif
 
 	/*
 	 * Now that the pv and attribute tables have been allocated,
 	 * assign them to the memory segments.
 	 */
-	pv = pv_table;
-	attr = pmap_attributes;
+	pvh = pv_table;
 	for (bank = 0; bank < vm_nphysseg; bank++) {
 		npg = vm_physmem[bank].end - vm_physmem[bank].start;
-		vm_physmem[bank].pmseg.pvent = pv;
-		vm_physmem[bank].pmseg.attrs = attr;
-		pv += npg;
-		attr += npg;
+		vm_physmem[bank].pmseg.pvheader = pvh;
+		pvh += npg;
 	}
 
 	/*
@@ -796,6 +789,7 @@
 void
 pmap_page_protect(struct vm_page *pg, vm_prot_t prot)
 {
+	struct pv_header *pvh;
 	struct pv_entry *pv;
 	int s;
 	paddr_t	pa = VM_PAGE_TO_PHYS(pg);
@@ -815,7 +809,8 @@
 		break;
 	/* remove_all */
 	default:
-		pv = pa_to_pvh(pa);
+		pvh = pa_to_pvh(pa);
+		pv = &pvh->pvh_first;
 		s = splvm();
 		while (pv->pv_pmap != NULL) {
 			pt_entry_t  *pte;
@@ -1030,13 +1025,15 @@
 	 * since pmap_enter can be called at interrupt time.
 	 */
 	if (PAGE_IS_MANAGED(pa)) {
+		struct pv_header *pvh;
 		struct pv_entry *pv, *npv;
 		int s;
 
 #ifdef DEBUG
 		enter_stats.managed++;
 #endif
-		pv = pa_to_pvh(pa);
+		pvh = pa_to_pvh(pa);
+		pv = &pvh->pvh_first;
 		s = splvm();
 #ifdef DEBUG
 		if (pmapdebug & PDB_ENTER)
@@ -1055,7 +1052,6 @@
 			pv->pv_next = NULL;
 			pv->pv_ptste = NULL;
 			pv->pv_ptpmap = NULL;
-			pv->pv_flags = 0;
 		}
 		/*
 		 * There is at least one other VA mapping this page.
@@ -1278,10 +1274,12 @@
 		while (sva < nssva) {
 			if (pmap_pte_v(pte)) {
 #ifdef DEBUG
+				struct pv_header *pvh;
 				struct pv_entry *pv;
 				int s;
 
-				pv = pa_to_pvh(pmap_pte_pa(pte));
+				pvh = pa_to_pvh(pmap_pte_pa(pte));
+				pv = &pvh->pvh_first;
 				s = splvm();
 				while (pv->pv_pmap != NULL) {
 					KASSERT(pv->pv_pmap != pmap_kernel() ||
@@ -1472,6 +1470,7 @@
 pmap_collect1(pmap_t pmap, paddr_t startpa, paddr_t endpa)
 {
 	paddr_t pa;
+	struct pv_header *pvh;
 	struct pv_entry *pv;
 	pt_entry_t *pte;
 	paddr_t kpa;
@@ -1487,8 +1486,10 @@
 		 * Locate physical pages which are being used as kernel
 		 * page table pages.
 		 */
-		pv = pa_to_pvh(pa);
-		if (pv->pv_pmap != pmap_kernel() || !(pv->pv_flags & PV_PTPAGE))
+		pvh = pa_to_pvh(pa);
+		pv = &pvh->pvh_first;
+		if (pv->pv_pmap != pmap_kernel() ||
+		    !(pvh->pvh_attrs & PVH_PTPAGE))
 			continue;
 		do {
 			if (pv->pv_ptste && pv->pv_ptpmap == pmap_kernel())
@@ -1812,6 +1813,7 @@
 pmap_remove_mapping(pmap_t pmap, vaddr_t va, pt_entry_t *pte, int flags)
 {
 	paddr_t pa;
+	struct pv_header *pvh;
 	struct pv_entry *pv, *npv;
 	pmap_t ptpmap;
 	st_entry_t *ste;
@@ -1878,6 +1880,7 @@
 		 */
 		if (refs == 0 && (flags & PRM_KEEPPTPAGE) == 0) {
 #ifdef DIAGNOSTIC
+			struct pv_header *_pvh;
 			struct pv_entry *_pv;
 #endif
 			paddr_t _pa;
@@ -1886,7 +1889,8 @@
 #ifdef DIAGNOSTIC
 			if (PAGE_IS_MANAGED(_pa) == 0)
 				panic("pmap_remove_mapping: unmanaged PT page");
-			_pv = pa_to_pvh(_pa);
+			_pvh = pa_to_pvh(_pa);
+			_pv = &_pvh->pvh_first;
 			if (_pv->pv_ptste == NULL)
 				panic("pmap_remove_mapping: ptste == NULL");
 			if (_pv->pv_pmap != pmap_kernel() ||
@@ -1918,7 +1922,8 @@
 	 * Otherwise remove it from the PV table
 	 * (raise IPL since we may be called at interrupt time).
 	 */
-	pv = pa_to_pvh(pa);
+	pvh = pa_to_pvh(pa);
+	pv = &pvh->pvh_first;
 	ste = ST_ENTRY_NULL;
 	s = splvm();
 	/*
@@ -1932,7 +1937,6 @@
 		ptpmap = pv->pv_ptpmap;
 		npv = pv->pv_next;
 		if (npv) {
-			npv->pv_flags = pv->pv_flags;
 			*pv = *npv;
 			pmap_free_pv(npv);
 		} else
@@ -1957,7 +1961,8 @@
 		ptpmap = npv->pv_ptpmap;
 		pv->pv_next = npv->pv_next;
 		pmap_free_pv(npv);
-		pv = pa_to_pvh(pa);
+		pvh = pa_to_pvh(pa);
+		pv = &pvh->pvh_first;
 	}
 
 	/*
@@ -2040,13 +2045,13 @@
 		else
 			TBIAU();
 #endif
-		pv->pv_flags &= ~PV_PTPAGE;
+		pvh->pvh_attrs &= ~PVH_PTPAGE;
 		ptpmap->pm_ptpages--;
 	}
 	/*
 	 * Update saved attributes for managed page
 	 */
-	*pa_to_attribute(pa) |= bits;
+	pvh->pvh_attrs |= bits;
 	splx(s);
 }
 
@@ -2088,18 +2093,20 @@
 bool
 pmap_testbit(paddr_t pa, int bit)
 {
+	struct pv_header *pvh;
 	struct pv_entry *pv;
 	int *pte;
 	int s;
 
-	pv = pa_to_pvh(pa);
+	pvh = pa_to_pvh(pa);
+	pv = &pvh->pvh_first;
 	s = splvm();
 
 	/*
 	 * Check saved info first
 	 */
 
-	if (*pa_to_attribute(pa) & bit) {
+	if (pvh->pvh_attrs & bit) {
 		splx(s);
 		return(true);
 	}
@@ -2125,6 +2132,7 @@
 static void
 pmap_changebit(paddr_t pa, int bit, bool setem)
 {
+	struct pv_header *pvh;
 	struct pv_entry *pv;
 	int *pte, npte;
 	vaddr_t va;
@@ -2139,7 +2147,8 @@
 		    pa, bit, setem ? "set" : "clear");
 #endif
 
-	pv = pa_to_pvh(pa);
+	pvh = pa_to_pvh(pa);
+	pv = &pvh->pvh_first;
 	s = splvm();
 
 	/*
@@ -2147,7 +2156,7 @@
 	 */
 
 	if (!setem)
-		*pa_to_attribute(pa) &= ~bit;
+		pvh->pvh_attrs &= ~bit;
 
 	/*
 	 * Loop over all current mappings setting/clearing as appropos
@@ -2195,6 +2204,7 @@
 {
 	paddr_t ptpa;
 	struct vm_page *pg;
+	struct pv_header *pvh;
 	struct pv_entry *pv;
 #ifdef M68060
 	u_int stpa;
@@ -2398,14 +2408,17 @@
 	 * record the STE address.  This is so that we can invalidate
 	 * the STE when we remove the mapping for the page.
 	 */
-	pv = pa_to_pvh(ptpa);
+	pvh = pa_to_pvh(ptpa);
 	s = splvm();
-	if (pv) {
-		pv->pv_flags |= PV_PTPAGE;
+	if (pvh) {
+		pv = &pvh->pvh_first;
+		pvh->pvh_attrs |= PVH_PTPAGE;
 		do {
 			if (pv->pv_pmap == pmap_kernel() && pv->pv_va == va)
 				break;
 		} while ((pv = pv->pv_next) > 0);
+	} else {
+		pv = NULL;
 	}
 #ifdef DEBUG
 	if (pv == NULL) {
@@ -2464,13 +2477,13 @@
 void
 pmap_pvdump(paddr_t pa)
 {
+	struct pv_header *pvh;
 	struct pv_entry *pv;
 
 	printf("pa %lx", pa);
-	for (pv = pa_to_pvh(pa); pv; pv = pv->pv_next)
-		printf(" -> pmap %p, va %lx, ptste %p, ptpmap %p, flags %x",
-		       pv->pv_pmap, pv->pv_va, pv->pv_ptste, pv->pv_ptpmap,
-		       pv->pv_flags);
+	for (pvh = pa_to_pvh(pa), pv = &pvh->pvh_first; pv; pv = pv->pv_next)
+		printf(" -> pmap %p, va %lx, ptste %p, ptpmap %p",
+		       pv->pv_pmap, pv->pv_va, pv->pv_ptste, pv->pv_ptpmap);
 	printf("\n");
 }
 
--- a/sys/arch/amiga/conf/files.amiga	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/amiga/conf/files.amiga	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.amiga,v 1.140 2008/02/20 21:43:33 drochner Exp $
+#	$NetBSD: files.amiga,v 1.140.10.1 2009/09/16 13:37:35 yamt Exp $
 
 # maxpartitions must be first item in files.${ARCH}.newconf
 maxpartitions 16			# NOTE THAT AMIGA IS SPECIAL!
@@ -435,14 +435,14 @@
 file	arch/amiga/amiga/dkbad.c
 file	arch/amiga/amiga/machdep.c
 file	arch/amiga/amiga/mem.c
-file	arch/amiga/amiga/pmap.c
+#file	arch/amiga/amiga/pmap.c
 file	arch/amiga/amiga/pmap_bootstrap.c
 file	arch/amiga/amiga/trap.c
 file	arch/amiga/amiga/cc.c
 file	dev/md_root.c			memory_disk_hooks
 file	arch/m68k/m68k/cacheops.c
 file	arch/m68k/m68k/db_memrw.c	ddb
-#file	arch/m68k/m68k/pmap_motorola.c
+file	arch/m68k/m68k/pmap_motorola.c
 file	arch/m68k/m68k/procfs_machdep.c	procfs
 file	arch/m68k/m68k/sys_machdep.c
 file	arch/m68k/m68k/vm_machdep.c
--- a/sys/arch/amiga/dev/clock.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/amiga/dev/clock.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.47.10.1 2009/05/04 08:10:34 yamt Exp $ */
+/*	$NetBSD: clock.c,v 1.47.10.2 2009/09/16 13:37:35 yamt Exp $ */
 
 /*
  * Copyright (c) 1982, 1990 The Regents of the University of California.
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.47.10.1 2009/05/04 08:10:34 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.47.10.2 2009/09/16 13:37:35 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -112,7 +112,7 @@
 static struct timecounter clk_timecounter = {
 	clk_getcounter,	/* get_timecount */
 	0,		/* no poll_pps */
-	0x0fffu,	/* counter_mask */
+	~0u,		/* counter_mask */
 	0,		/* frequency */
 	"clock",	/* name, overriden later */
 	100,		/* quality */
@@ -159,7 +159,6 @@
 clockattach(struct device *pdp, struct device *dp, void *auxp)
 {
 	const char *clockchip;
-	u_int counter_mask;
 	unsigned short interval;
 #ifdef DRACO
 	u_char dracorev;
@@ -189,14 +188,8 @@
 
 	amiga_clk_interval = (eclockfreq / hz);
 
-	counter_mask = 0x8000;
-	while (counter_mask != 0 && (counter_mask & amiga_clk_interval) == 0)
-		counter_mask >>= 1;
-	counter_mask -= 1;
-
 	clk_timecounter.tc_name = clockchip;
 	clk_timecounter.tc_frequency = eclockfreq;
-	clk_timecounter.tc_counter_mask = counter_mask;
 
 	fast_delay_limit = UINT_MAX / amiga_clk_interval;
 
@@ -333,6 +326,8 @@
 static u_int
 clk_getcounter(struct timecounter *tc)
 {
+	static int last_hardclock_ticks;
+	static u_int last_clock_tick = 0;
 	int old_hardclock_ticks;
 	u_int clock_tick;
 
@@ -341,6 +336,19 @@
 		clock_tick = clk_gettick();
 	} while (old_hardclock_ticks != hardclock_ticks);
 
+	/*
+	 * Handle the situation of a wrapped interval counter, while
+	 * the hardclock() interrupt was not yet executed to update
+	 * hardclock_ticks.
+	 */
+	if (last_hardclock_ticks > old_hardclock_ticks)
+		old_hardclock_ticks = last_hardclock_ticks;
+	if (clock_tick < last_clock_tick &&
+	    old_hardclock_ticks == last_hardclock_ticks)
+		old_hardclock_ticks++;
+	last_hardclock_ticks = old_hardclock_ticks;
+	last_clock_tick = clock_tick;
+
 	return old_hardclock_ticks * amiga_clk_interval + clock_tick;
 }
 
--- a/sys/arch/amiga/include/disklabel.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/amiga/include/disklabel.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: disklabel.h,v 1.6 1996/04/21 21:13:19 veego Exp $	*/
+/*	$NetBSD: disklabel.h,v 1.6.170.1 2009/09/16 13:37:35 yamt Exp $	*/
 
 /*
  * Copyright (c) 1994 Christian E. Hopps
@@ -37,163 +37,12 @@
 #define	MAXPARTITIONS	16			/* number of partitions */
 #define	RAW_PART	2			/* raw partition: xx?c */
 
-/*
- * describes ados Rigid Disk Blocks
- * which are used to partition a drive
- */
-#define RDBNULL ((u_long)0xffffffff)
-
-/*
- * you will find rdblock somewhere in [0, RDBMAXBLOCKS)
- */
-#define RDB_MAXBLOCKS	16
-
-struct rdblock {
-	u_long id;		/* 'RDSK' */
-	u_long nsumlong;	/* number of longs in check sum */
-	u_long chksum;		/* simple additive with wrap checksum */
-	u_long hostid;		/* scsi target of host */
-	u_long nbytes;		/* size of disk blocks */
-	u_long flags;
-	u_long badbhead;	/* linked list of badblocks */
-	u_long partbhead;	/* linked list of partblocks */
-	u_long fsbhead;		/*   "     "   of fsblocks */
-	u_long driveinit;
-	u_long resv1[6];	/* RDBNULL */
-	u_long ncylinders;	/* number of cylinders on drive */
-	u_long nsectors;	/* number of sectors per track */
-	u_long nheads;		/* number of tracks per cylinder */
-	u_long interleave;
-	u_long park;		/* only used with st506 i.e. not */
-	u_long resv2[3];
-	u_long wprecomp;	/* start cyl for write precomp */
-	u_long reducedwrite;	/* start cyl for reduced write current */
-	u_long steprate;	/* driver step rate in ?s */
-	u_long resv3[5];
-	u_long rdblowb;		/* lowblock of range for rdb's */
-	u_long rdbhighb;	/* high block of range for rdb's */
-	u_long lowcyl;		/* low cylinder of partition area */
-	u_long highcyl;		/* upper cylinder of partition area */
-	u_long secpercyl;	/* number of sectors per cylinder */
-	u_long parkseconds;	/* zero if no park needed */
-	u_long resv4[2];
-	char   diskvendor[8];	/* inquiry stuff */
-	char   diskproduct[16];	/* inquiry stuff */
-	char   diskrevision[4];	/* inquiry stuff */
-	char   contvendor[8];	/* inquiry stuff */
-	char   contproduct[16];	/* inquiry stuff */
-	char   contrevision[4];	/* inquiry stuff */
-#if never_use_secsize
-	u_long resv5[0];
-#endif
-};
-
-
-#define RDBF_LAST	0x1	/* last drive available */
-#define RDBF_LASTLUN	0x2	/* last LUN available */
-#define RDBF_LASTUNIT	0x4	/* last target available */
-#define RDBF_NORESELECT	0x8	/* do not use reselect */
-#define RDBF_DISKID	0x10	/* disk id is valid ?? */
-#define RDBF_CTRLID	0x20	/* ctrl id is valid ?? */
-#define RDBF_SYNC	0x40	/* drive supports SCSI synchronous mode */
-	
-struct ados_environ {
-	u_long tabsize;		/* 0: environ table size */
-	u_long sizeblock;	/* 1: n long words in a block */
-	u_long secorg;		/* 2: not used must be zero */
-	u_long numheads;	/* 3: number of surfaces */
-	u_long secperblk;	/* 4: must be 1 */
-	u_long secpertrk;	/* 5: blocks per track */
-	u_long resvblocks;	/* 6: reserved blocks at start */
-	u_long prefac;		/* 7: must be 0 */
-	u_long interleave;	/* 8: normally 1 */
-	u_long lowcyl;		/* 9: low cylinder of partition */
-	u_long highcyl;		/* 10: upper cylinder of partition */
-	u_long numbufs;		/* 11: ados: number of buffers */
-	u_long membuftype;	/* 12: ados: type of bufmem */
-	u_long maxtrans;	/* 13: maxtrans the ctrlr supports */
-	u_long mask;		/* 14: mask for valid address */
-	u_long bootpri;		/* 15: boot priority for autoboot */
-	u_long dostype;		/* 16: filesystem type */
-	u_long baud;		/* 17: serial handler baud rate */
-	u_long control;		/* 18: control word for fs */
-	u_long bootblocks;	/* 19: blocks containing boot code */
-	u_long fsize;		/* 20: file system block size */
-	u_long frag;		/* 21: allowable frags per block */
-	u_long cpg;		/* 22: cylinders per group */
-};
-
-struct partblock {
-	u_long id;		/* 'PART' */
-	u_long nsumlong;	/* number of longs in check sum */
-	u_long chksum;		/* simple additive with wrap checksum */
-	u_long hostid;		/* scsi target of host */
-	u_long next;		/* next in chain */
-	u_long flags;		/* see below */
-	u_long resv1[3];
-	u_char partname[32];	/* (BCPL) part name (may not be unique) */
-	u_long resv2[15];
-	struct ados_environ e;
-#if never_use_secsize
-	u_long extra[9];	/* 8 for extra added to environ */
-#endif
-};
-
-#define PBF_BOOTABLE	0x1	/* partition is bootable */
-#define PBF_NOMOUNT	0x2	/* partition should be mounted */
-
-struct badblock {
-	u_long id;		/* 'BADB' */
-	u_long nsumlong;	/* number of longs in check sum */
-	u_long chksum;		/* simple additive with wrap checksum */
-	u_long hostid;		/* scsi target of host */
-	u_long next;		/* next in chain */
-	u_long resv;
-	struct badblockent {
-		u_long badblock;
-		u_long goodblock;
-	} badtab[0];		/* 61 for secsize == 512 */
-};
-
-struct fsblock {
-	u_long id;		/* 'FSHD' */
-	u_long nsumlong;	/* number of longs in check sum */
-	u_long chksum;		/* simple additive with wrap checksum */
-	u_long hostid;		/* scsi target of host */
-	u_long next;		/* next in chain */
-	u_long flags;
-	u_long resv1[2];
-	u_long dostype;		/* this is a file system for this type */
-	u_long version;		/* version of this fs */
-	u_long patchflags;	/* describes which functions to replace */
-	u_long type;		/* zero */
-	u_long task;		/* zero */
-	u_long lock;		/* zero */
-	u_long handler;		/* zero */
-	u_long stacksize;	/* to use when loading handler */
-	u_long priority;	/* to run the fs at. */
-	u_long startup;		/* zero */
-	u_long lsegblocks;	/* linked list of lsegblocks of fs code */
-	u_long globalvec;	/* bcpl vector not used mostly */
-#if never_use_secsize
-	u_long resv2[44];
-#endif
-};
-
-struct lsegblock {
-	u_long id;		/* 'LSEG' */
-	u_long nsumlong;	/* number of longs in check sum */
-	u_long chksum;		/* simple additive with wrap checksum */
-	u_long hostid;		/* scsi target of host */
-	u_long next;		/* next in chain */
-	u_long loaddata[0];	/* load segment data, 123 for secsize == 512 */
-};
-
-#define RDBLOCK_ID	0x5244534b	/* 'RDSK' */
-#define PARTBLOCK_ID	0x50415254	/* 'PART' */
-#define BADBLOCK_ID	0x42414442	/* 'BADB' */
-#define FSBLOCK_ID	0x46534844	/* 'FSHD' */
-#define LSEGBLOCK_ID	0x4c534547	/* 'LSEG' */
+/* Pull in RDB partition definitions. */
+#if HAVE_NBTOOL_CONFIG_H
+#include <nbinclude/sys/disklabel_rdb.h>
+#else
+#include <sys/disklabel_rdb.h>
+#endif /* HAVE_NBTOOL_CONFIG_H */
 
 struct cpu_disklabel {
 	u_long rdblock;			/* may be RDBNULL which invalidates */
--- a/sys/arch/amiga/include/vmparam.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/amiga/include/vmparam.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmparam.h,v 1.36.20.1 2009/05/04 08:10:35 yamt Exp $	*/
+/*	$NetBSD: vmparam.h,v 1.36.20.2 2009/09/16 13:37:35 yamt Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
@@ -178,8 +178,7 @@
  * pmap-specific data stored in the vm_physmem[] array.
  */   
 struct pmap_physseg { 
-	struct pv_entry *pvent;         /* pv table for this seg */
-	char *attrs;                    /* page attributes for this seg */
+	struct pv_header *pvheader;	/* pv table for this seg */
 }; 
 
 /*
--- a/sys/arch/amigappc/include/disklabel.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/amigappc/include/disklabel.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: disklabel.h,v 1.1 2000/05/25 22:11:59 is Exp $	*/
+/*	$NetBSD: disklabel.h,v 1.1.134.1 2009/09/16 13:37:35 yamt Exp $	*/
 
 /*
  * Copyright (c) 1994 Christian E. Hopps
@@ -37,163 +37,12 @@
 #define	MAXPARTITIONS	16			/* number of partitions */
 #define	RAW_PART	2			/* raw partition: xx?c */
 
-/*
- * describes ados Rigid Disk Blocks
- * which are used to partition a drive
- */
-#define RDBNULL ((u_long)0xffffffff)
-
-/*
- * you will find rdblock somewhere in [0, RDBMAXBLOCKS)
- */
-#define RDB_MAXBLOCKS	16
-
-struct rdblock {
-	u_long id;		/* 'RDSK' */
-	u_long nsumlong;	/* number of longs in check sum */
-	u_long chksum;		/* simple additive with wrap checksum */
-	u_long hostid;		/* scsi target of host */
-	u_long nbytes;		/* size of disk blocks */
-	u_long flags;
-	u_long badbhead;	/* linked list of badblocks */
-	u_long partbhead;	/* linked list of partblocks */
-	u_long fsbhead;		/*   "     "   of fsblocks */
-	u_long driveinit;
-	u_long resv1[6];	/* RDBNULL */
-	u_long ncylinders;	/* number of cylinders on drive */
-	u_long nsectors;	/* number of sectors per track */
-	u_long nheads;		/* number of tracks per cylinder */
-	u_long interleave;
-	u_long park;		/* only used with st506 i.e. not */
-	u_long resv2[3];
-	u_long wprecomp;	/* start cyl for write precomp */
-	u_long reducedwrite;	/* start cyl for reduced write current */
-	u_long steprate;	/* driver step rate in ?s */
-	u_long resv3[5];
-	u_long rdblowb;		/* lowblock of range for rdb's */
-	u_long rdbhighb;	/* high block of range for rdb's */
-	u_long lowcyl;		/* low cylinder of partition area */
-	u_long highcyl;		/* upper cylinder of partition area */
-	u_long secpercyl;	/* number of sectors per cylinder */
-	u_long parkseconds;	/* zero if no park needed */
-	u_long resv4[2];
-	char   diskvendor[8];	/* inquiry stuff */
-	char   diskproduct[16];	/* inquiry stuff */
-	char   diskrevision[4];	/* inquiry stuff */
-	char   contvendor[8];	/* inquiry stuff */
-	char   contproduct[16];	/* inquiry stuff */
-	char   contrevision[4];	/* inquiry stuff */
-#if never_use_secsize
-	u_long resv5[0];
-#endif
-};
-
-
-#define RDBF_LAST	0x1	/* last drive available */
-#define RDBF_LASTLUN	0x2	/* last LUN available */
-#define RDBF_LASTUNIT	0x4	/* last target available */
-#define RDBF_NORESELECT	0x8	/* do not use reselect */
-#define RDBF_DISKID	0x10	/* disk id is valid ?? */
-#define RDBF_CTRLID	0x20	/* ctrl id is valid ?? */
-#define RDBF_SYNC	0x40	/* drive supports SCSI synchronous mode */
-	
-struct ados_environ {
-	u_long tabsize;		/* 0: environ table size */
-	u_long sizeblock;	/* 1: n long words in a block */
-	u_long secorg;		/* 2: not used must be zero */
-	u_long numheads;	/* 3: number of surfaces */
-	u_long secperblk;	/* 4: must be 1 */
-	u_long secpertrk;	/* 5: blocks per track */
-	u_long resvblocks;	/* 6: reserved blocks at start */
-	u_long prefac;		/* 7: must be 0 */
-	u_long interleave;	/* 8: normally 1 */
-	u_long lowcyl;		/* 9: low cylinder of partition */
-	u_long highcyl;		/* 10: upper cylinder of partition */
-	u_long numbufs;		/* 11: ados: number of buffers */
-	u_long membuftype;	/* 12: ados: type of bufmem */
-	u_long maxtrans;	/* 13: maxtrans the ctrlr supports */
-	u_long mask;		/* 14: mask for valid address */
-	u_long bootpri;		/* 15: boot priority for autoboot */
-	u_long dostype;		/* 16: filesystem type */
-	u_long baud;		/* 17: serial handler baud rate */
-	u_long control;		/* 18: control word for fs */
-	u_long bootblocks;	/* 19: blocks containing boot code */
-	u_long fsize;		/* 20: file system block size */
-	u_long frag;		/* 21: allowable frags per block */
-	u_long cpg;		/* 22: cylinders per group */
-};
-
-struct partblock {
-	u_long id;		/* 'PART' */
-	u_long nsumlong;	/* number of longs in check sum */
-	u_long chksum;		/* simple additive with wrap checksum */
-	u_long hostid;		/* scsi target of host */
-	u_long next;		/* next in chain */
-	u_long flags;		/* see below */
-	u_long resv1[3];
-	u_char partname[32];	/* (BCPL) part name (may not be unique) */
-	u_long resv2[15];
-	struct ados_environ e;
-#if never_use_secsize
-	u_long extra[9];	/* 8 for extra added to environ */
-#endif
-};
-
-#define PBF_BOOTABLE	0x1	/* partition is bootable */
-#define PBF_NOMOUNT	0x2	/* partition should be mounted */
-
-struct badblock {
-	u_long id;		/* 'BADB' */
-	u_long nsumlong;	/* number of longs in check sum */
-	u_long chksum;		/* simple additive with wrap checksum */
-	u_long hostid;		/* scsi target of host */
-	u_long next;		/* next in chain */
-	u_long resv;
-	struct badblockent {
-		u_long badblock;
-		u_long goodblock;
-	} badtab[0];		/* 61 for secsize == 512 */
-};
-
-struct fsblock {
-	u_long id;		/* 'FSHD' */
-	u_long nsumlong;	/* number of longs in check sum */
-	u_long chksum;		/* simple additive with wrap checksum */
-	u_long hostid;		/* scsi target of host */
-	u_long next;		/* next in chain */
-	u_long flags;
-	u_long resv1[2];
-	u_long dostype;		/* this is a file system for this type */
-	u_long version;		/* version of this fs */
-	u_long patchflags;	/* describes which functions to replace */
-	u_long type;		/* zero */
-	u_long task;		/* zero */
-	u_long lock;		/* zero */
-	u_long handler;		/* zero */
-	u_long stacksize;	/* to use when loading handler */
-	u_long priority;	/* to run the fs at. */
-	u_long startup;		/* zero */
-	u_long lsegblocks;	/* linked list of lsegblocks of fs code */
-	u_long globalvec;	/* bcpl vector not used mostly */
-#if never_use_secsize
-	u_long resv2[44];
-#endif
-};
-
-struct lsegblock {
-	u_long id;		/* 'LSEG' */
-	u_long nsumlong;	/* number of longs in check sum */
-	u_long chksum;		/* simple additive with wrap checksum */
-	u_long hostid;		/* scsi target of host */
-	u_long next;		/* next in chain */
-	u_long loaddata[0];	/* load segment data, 123 for secsize == 512 */
-};
-
-#define RDBLOCK_ID	0x5244534b	/* 'RDSK' */
-#define PARTBLOCK_ID	0x50415254	/* 'PART' */
-#define BADBLOCK_ID	0x42414442	/* 'BADB' */
-#define FSBLOCK_ID	0x46534844	/* 'FSHD' */
-#define LSEGBLOCK_ID	0x4c534547	/* 'LSEG' */
+/* Pull in RDB partition definitions. */
+#if HAVE_NBTOOL_CONFIG_H
+#include <nbinclude/sys/disklabel_rdb.h>
+#else
+#include <sys/disklabel_rdb.h>
+#endif /* HAVE_NBTOOL_CONFIG_H */
 
 struct cpu_disklabel {
 	u_long rdblock;			/* may be RDBNULL which invalidates */
--- a/sys/arch/arm/footbridge/isa/isa_machdep.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/arm/footbridge/isa/isa_machdep.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: isa_machdep.c,v 1.7.18.3 2009/08/19 18:45:59 yamt Exp $	*/
+/*	$NetBSD: isa_machdep.c,v 1.7.18.4 2009/09/16 13:37:36 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1996-1998 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.7.18.3 2009/08/19 18:45:59 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.7.18.4 2009/09/16 13:37:36 yamt Exp $");
 
 #include "opt_irqstats.h"
 
@@ -504,7 +504,7 @@
 isa_detach_hook(isa_chipset_tag_t ic, device_t self)
 {
 #if NISADMA > 0
-	isa_dma_destroy();
+	isa_dmadestroy(ic);
 #endif
 }
 
--- a/sys/arch/arm/include/arm32/pmap.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/arm/include/arm32/pmap.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.84.10.3 2009/08/19 18:46:00 yamt Exp $	*/
+/*	$NetBSD: pmap.h,v 1.84.10.4 2009/09/16 13:37:36 yamt Exp $	*/
 
 /*
  * Copyright (c) 2002, 2003 Wasabi Systems, Inc.
@@ -290,6 +290,7 @@
 
 #define	PMAP_NEED_PROCWR
 #define PMAP_GROWKERNEL		/* turn on pmap_growkernel interface */
+#define	PMAP_ENABLE_PMAP_KMPAGE	/* enable the PMAP_KMPAGE flag */
 
 #if ARM_MMU_V6 > 0
 #define	PMAP_PREFER(hint, vap, sz, td)	pmap_prefer((hint), (vap), (td))
--- a/sys/arch/arm/xscale/pxa2x0_intr.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/arm/xscale/pxa2x0_intr.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: pxa2x0_intr.c,v 1.13.12.2 2009/05/04 08:10:45 yamt Exp $	*/
+/*	$NetBSD: pxa2x0_intr.c,v 1.13.12.3 2009/09/16 13:37:36 yamt Exp $	*/
 
 /*
  * Copyright (c) 2002  Genetec Corporation.  All rights reserved.
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pxa2x0_intr.c,v 1.13.12.2 2009/05/04 08:10:45 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pxa2x0_intr.c,v 1.13.12.3 2009/09/16 13:37:36 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -262,25 +262,11 @@
 init_interrupt_masks(void)
 {
 
+	/*
+	 * disable all interrups until handlers are installed.
+	 */
 	memset(pxa2x0_imask, 0, sizeof(pxa2x0_imask));
 
-	/*
-	 * IPL_NONE has soft interrupts enabled only, at least until
-	 * hardware handlers are installed.
-	 */
-	pxa2x0_imask[IPL_NONE] = ~0;
-	/*
-	 * Initialize the soft interrupt masks to block themselves.
-	 */
-	pxa2x0_imask[IPL_SOFTCLOCK] = ~0;
-	pxa2x0_imask[IPL_SOFTBIO] = ~0;
-	pxa2x0_imask[IPL_SOFTNET] = ~0;
-	pxa2x0_imask[IPL_SOFTSERIAL] = ~0;
-
-	pxa2x0_imask[IPL_SOFTCLOCK] &= pxa2x0_imask[IPL_NONE];
-	pxa2x0_imask[IPL_SOFTBIO] &= pxa2x0_imask[IPL_SOFTCLOCK];
-	pxa2x0_imask[IPL_SOFTNET] &= pxa2x0_imask[IPL_SOFTBIO];
-	pxa2x0_imask[IPL_SOFTSERIAL] &= pxa2x0_imask[IPL_SOFTNET];
 }
 
 #undef splx
--- a/sys/arch/atari/atari/atari_init.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/atari/atari/atari_init.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: atari_init.c,v 1.67.44.2 2009/07/18 14:52:52 yamt Exp $	*/
+/*	$NetBSD: atari_init.c,v 1.67.44.3 2009/09/16 13:37:36 yamt Exp $	*/
 
 /*
  * Copyright (c) 1995 Leo Weppelman
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: atari_init.c,v 1.67.44.2 2009/07/18 14:52:52 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: atari_init.c,v 1.67.44.3 2009/09/16 13:37:36 yamt Exp $");
 
 #include "opt_ddb.h"
 #include "opt_mbtype.h"
@@ -55,6 +55,7 @@
 #include <sys/dkbad.h>
 #include <sys/reboot.h>
 #include <sys/exec.h>
+#include <sys/exec_aout.h>
 #include <sys/core.h>
 #include <sys/kcore.h>
 
@@ -177,9 +178,10 @@
 int kernel_copyback = 1;
 
 void
-start_c(int id, u_int ttphystart, u_int ttphysize, u_int stphysize, char *esym_addr)
+start_c(int id, u_int ttphystart, u_int ttphysize, u_int stphysize,
+    char *esym_addr)
 	/* id:			 Machine id			*/
-	/* ttphystart, ttphysize:	 Start address and size of TT-ram */
+	/* ttphystart, ttphysize: Start address and size of TT-ram */
 	/* stphysize:		 Size of ST-ram 		*/
 	/* esym_addr:		 Address of kernel '_esym' symbol */
 {
@@ -322,7 +324,7 @@
 	 * If present, add pci areas
 	 */
 	if (machineid & ATARI_HADES)
-		ptextra += btoc(PCI_CONF_SIZE + PCI_IO_SIZE + PCI_MEM_SIZE);
+		ptextra += btoc(PCI_CONFIG_SIZE + PCI_IO_SIZE + PCI_MEM_SIZE);
 	if (machineid & ATARI_MILAN)
 		ptextra += btoc(PCI_IO_SIZE + PCI_MEM_SIZE);
 	ptextra += btoc(BOOTM_VA_POOL);
@@ -731,7 +733,7 @@
  */
 static void
 map_io_areas(paddr_t ptpa, psize_t ptsize, u_int ptextra)
-	/* ptsize:		 Size of 'pt' in bytes	*/
+	/* ptsize:	 Size of 'pt' in bytes		*/
 	/* ptextra:	 #of additional I/O pte's	*/
 {
 	extern void	bootm_init(vaddr_t, pt_entry_t *, u_long);
@@ -774,9 +776,9 @@
 		 * Only Hades maps the PCI-config space!
 		 */
 		pci_conf_addr = ioaddr;
-		ioaddr       += PCI_CONF_SIZE;
+		ioaddr       += PCI_CONFIG_SIZE;
 		pg            = &pt[pci_conf_addr / PAGE_SIZE];
-		epg           = &pg[btoc(PCI_CONF_SIZE)];
+		epg           = &pg[btoc(PCI_CONFIG_SIZE)];
 		mask          = PCI_CONFM_PHYS;
 		pg_proto      = PCI_CONFB_PHYS | PG_RW | PG_CI | PG_V;
 		for (; pg < epg; mask <<= 1)
@@ -871,7 +873,7 @@
 	cpu_kcore_hdr_t *h = &cpu_kcore_hdr;
 	struct m68k_kcore_hdr *m = &h->un._m68k;
 	extern char end[];
-	int	i;
+	int i;
 
 	memset(&cpu_kcore_hdr, 0, sizeof(cpu_kcore_hdr));
 
@@ -925,11 +927,12 @@
 }
 
 void
-mmu030_setup(paddr_t sysseg_pa, u_int kstsize, paddr_t ptpa, psize_t ptsize, paddr_t sysptmap_pa, paddr_t kbase)
+mmu030_setup(paddr_t sysseg_pa, u_int kstsize, paddr_t ptpa, psize_t ptsize,
+    paddr_t sysptmap_pa, paddr_t kbase)
 	/* sysseg_pa:	 System segment table		*/
 	/* kstsize:	 size of 'sysseg' in pages	*/
-	/* ptpa:		 Kernel page table		*/
-	/* ptsize:		 size	of 'pt' in bytes	*/
+	/* ptpa:	 Kernel page table		*/
+	/* ptsize:	 size	of 'pt' in bytes	*/
 	/* sysptmap_pa:	 System page table		*/
 {
 	st_entry_t	sg_proto, *sg, *esg;
@@ -976,11 +979,12 @@
 
 #if defined(M68040) || defined(M68060)
 void
-mmu040_setup(paddr_t sysseg_pa, u_int kstsize, paddr_t ptpa, psize_t ptsize, paddr_t sysptmap_pa, paddr_t kbase)
+mmu040_setup(paddr_t sysseg_pa, u_int kstsize, paddr_t ptpa, psize_t ptsize,
+    paddr_t sysptmap_pa, paddr_t kbase)
 	/* sysseg_pa:	 System segment table		*/
 	/* kstsize:	 size of 'sysseg' in pages	*/
-	/* ptpa:		 Kernel page table		*/
-	/* ptsize:		 size	of 'pt' in bytes	*/
+	/* ptpa:	 Kernel page table		*/
+	/* ptsize:	 size	of 'pt' in bytes	*/
 	/* sysptmap_pa:	 System page table		*/
 {
 	int		nl1desc, nl2desc, i;
--- a/sys/arch/atari/atari/machdep.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/atari/atari/machdep.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.149.10.1 2009/05/04 08:10:46 yamt Exp $	*/
+/*	$NetBSD: machdep.c,v 1.149.10.2 2009/09/16 13:37:36 yamt Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.149.10.1 2009/05/04 08:10:46 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.149.10.2 2009/09/16 13:37:36 yamt Exp $");
 
 #include "opt_ddb.h"
 #include "opt_compat_netbsd.h"
@@ -106,6 +106,7 @@
 #include <sys/ksyms.h>
 #include <sys/intr.h>
 #include <sys/exec.h>
+#include <sys/exec_aout.h>
 #include <sys/cpu.h>
 #if defined(DDB) && defined(__ELF__)
 #include <sys/exec_elf.h>
--- a/sys/arch/atari/atari/pmap.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/atari/atari/pmap.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.102.20.3 2009/08/19 18:46:01 yamt Exp $	*/
+/*	$NetBSD: pmap.c,v 1.102.20.4 2009/09/16 13:37:36 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -100,7 +100,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.102.20.3 2009/08/19 18:46:01 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.102.20.4 2009/09/16 13:37:36 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -272,7 +272,19 @@
 st_entry_t	*Segtabzero, *Segtabzeropa;
 vsize_t		Sysptsize = VM_KERNEL_PT_PAGES;
 
-struct pv_entry	*pv_table;	/* array of entries, one per page */
+struct pv_header {
+	struct pv_entry		pvh_first;	/* first PV entry */
+	uint16_t		pvh_attrs;	/* attributes:
+						   bits 0-7: PTE bits
+						   bits 8-15: flags */
+	uint16_t		pvh_cimappings;	/* # caller-specified CI
+						   mappings */
+};
+
+#define	PVH_CI		0x10	/* all entries are cache-inhibited */
+#define	PVH_PTPAGE	0x20	/* entry maps a page table page */
+
+struct pv_header *pv_table;	/* array of entries, one per page */
 
 static struct pmap kernel_pmap_store;
 struct pmap	*const kernel_pmap_ptr = &kernel_pmap_store;
@@ -286,7 +298,6 @@
 vaddr_t		virtual_end;	/* VA of last avail page (end of kernel AS) */
 int		page_cnt;	/* number of pages managed by the VM system */
 bool		pmap_initialized = false;	/* Has pmap_init completed? */
-char		*pmap_attributes;	/* reference and modify bits */
 TAILQ_HEAD(pv_page_list, pv_page) pv_page_freelist;
 int		pv_nfree;
 #if defined(M68040) || defined(M68060)
@@ -318,25 +329,13 @@
 
 #define	PAGE_IS_MANAGED(pa)	(pmap_initialized && uvm_pageismanaged(pa))
 
-static inline struct pv_entry *pa_to_pvh(paddr_t pa);
-static inline char *pa_to_attribute(paddr_t pa);
-
-static inline struct pv_entry *
+static inline struct pv_header *
 pa_to_pvh(paddr_t pa)
 {
 	int bank, pg = 0;	/* XXX gcc4 -Wuninitialized */
 
 	bank = vm_physseg_find(atop((pa)), &pg);
-	return &vm_physmem[bank].pmseg.pvent[pg];
-}
-
-static inline char *
-pa_to_attribute(paddr_t pa)
-{
-	int bank, pg = 0;	/* XXX gcc4 -Wuninitialized */
-
-	bank = vm_physseg_find(atop((pa)), &pg);
-	return &vm_physmem[bank].pmseg.attrs[pg];
+	return &vm_physmem[bank].pmseg.pvheader[pg];
 }
 
 /*
@@ -350,8 +349,7 @@
 	vaddr_t		addr, addr2;
 	vsize_t		s;
 	u_int		npg;
-	struct pv_entry *pv;
-	char            *attr;
+	struct pv_header *pvh;
 	int             rv, bank;
 #if defined(M68060)
 	struct kpt_page *kptp;
@@ -392,8 +390,7 @@
 #endif
 	}
 	s = M68K_STSIZE;				/* Segtabzero */
-	s += page_cnt * sizeof(struct pv_entry);	/* pv table */
-	s += page_cnt * sizeof(char);			/* attribute table */
+	s += page_cnt * sizeof(struct pv_header);	/* pv table */
 	s = round_page(s);
 
 	addr = uvm_km_alloc(kernel_map, s, 0, UVM_KMF_WIRED | UVM_KMF_ZERO);
@@ -403,30 +400,26 @@
 	(void) pmap_extract(pmap_kernel(), addr, (paddr_t *)(void *)&Segtabzeropa);
 	addr += M68K_STSIZE;
 
-	pv_table = (struct pv_entry *) addr;
-	addr += page_cnt * sizeof(struct pv_entry);
+	pv_table = (struct pv_header *) addr;
+	addr += page_cnt * sizeof(struct pv_header);
 
-	pmap_attributes = (char *) addr;
 #ifdef DEBUG
 	if (pmapdebug & PDB_INIT)
 		printf("pmap_init: %lx bytes: page_cnt %x s0 %p(%p) "
-			"tbl %p atr %p\n",
+			"tbl %p\n",
 			s, page_cnt, Segtabzero, Segtabzeropa,
-			pv_table, pmap_attributes);
+			pv_table);
 #endif
 
 	/*
 	 * Now that the pv and attribute tables have been allocated,
 	 * assign them to the memory segments.
 	 */
-	pv = pv_table;
-	attr = pmap_attributes;
+	pvh = pv_table;
 	for (bank = 0; bank < vm_nphysseg; bank++) {
 		npg = vm_physmem[bank].end - vm_physmem[bank].start;
-		vm_physmem[bank].pmseg.pvent = pv;
-		vm_physmem[bank].pmseg.attrs = attr;
-		pv += npg;
-		attr += npg;
+		vm_physmem[bank].pmseg.pvheader = pvh;
+		pvh += npg;
 	}
 
 	/*
@@ -791,6 +784,7 @@
 void
 pmap_page_protect(struct vm_page *pg, vm_prot_t prot)
 {
+	struct pv_header *pvh;
 	struct pv_entry *pv;
 	int s;
 	paddr_t	pa = VM_PAGE_TO_PHYS(pg);
@@ -810,7 +804,8 @@
 		break;
 	/* remove_all */
 	default:
-		pv = pa_to_pvh(pa);
+		pvh = pa_to_pvh(pa);
+		pv = &pvh->pvh_first;
 		s = splvm();
 		while (pv->pv_pmap != NULL) {
 			pt_entry_t  *pte;
@@ -1025,13 +1020,15 @@
 	 * since pmap_enter can be called at interrupt time.
 	 */
 	if (PAGE_IS_MANAGED(pa)) {
+		struct pv_header *pvh;
 		struct pv_entry *pv, *npv;
 		int s;
 
 #ifdef DEBUG
 		enter_stats.managed++;
 #endif
-		pv = pa_to_pvh(pa);
+		pvh = pa_to_pvh(pa);
+		pv = &pvh->pvh_first;
 		s = splvm();
 #ifdef DEBUG
 		if (pmapdebug & PDB_ENTER)
@@ -1050,7 +1047,6 @@
 			pv->pv_next = NULL;
 			pv->pv_ptste = NULL;
 			pv->pv_ptpmap = NULL;
-			pv->pv_flags = 0;
 		}
 		/*
 		 * There is at least one other VA mapping this page.
@@ -1273,10 +1269,12 @@
 		while (sva < nssva) {
 			if (pmap_pte_v(pte)) {
 #ifdef DEBUG
+				struct pv_header *pvh;
 				struct pv_entry *pv;
 				int s;
 
-				pv = pa_to_pvh(pmap_pte_pa(pte));
+				pvh = pa_to_pvh(pmap_pte_pa(pte));
+				pv = &pvh->pvh_first;
 				s = splvm();
 				while (pv->pv_pmap != NULL) {
 					KASSERT(pv->pv_pmap != pmap_kernel() ||
@@ -1467,6 +1465,7 @@
 pmap_collect1(pmap_t pmap, paddr_t startpa, paddr_t endpa)
 {
 	paddr_t pa;
+	struct pv_header *pvh;
 	struct pv_entry *pv;
 	pt_entry_t *pte;
 	paddr_t kpa;
@@ -1482,8 +1481,10 @@
 		 * Locate physical pages which are being used as kernel
 		 * page table pages.
 		 */
-		pv = pa_to_pvh(pa);
-		if (pv->pv_pmap != pmap_kernel() || !(pv->pv_flags & PV_PTPAGE))
+		pvh = pa_to_pvh(pa);
+		pv = &pvh->pvh_first;
+		if (pv->pv_pmap != pmap_kernel() ||
+		    !(pvh->pvh_attrs & PVH_PTPAGE))
 			continue;
 		do {
 			if (pv->pv_ptste && pv->pv_ptpmap == pmap_kernel())
@@ -1807,6 +1808,7 @@
 pmap_remove_mapping(pmap_t pmap, vaddr_t va, pt_entry_t *pte, int flags)
 {
 	paddr_t pa;
+	struct pv_header *pvh;
 	struct pv_entry *pv, *npv;
 	pmap_t ptpmap;
 	st_entry_t *ste;
@@ -1873,6 +1875,7 @@
 		 */
 		if (refs == 0 && (flags & PRM_KEEPPTPAGE) == 0) {
 #ifdef DIAGNOSTIC
+			struct pv_header *_pvh;
 			struct pv_entry *_pv;
 #endif
 			paddr_t _pa;
@@ -1881,7 +1884,8 @@
 #ifdef DIAGNOSTIC
 			if (PAGE_IS_MANAGED(_pa) == 0)
 				panic("pmap_remove_mapping: unmanaged PT page");
-			_pv = pa_to_pvh(_pa);
+			_pvh = pa_to_pvh(_pa);
+			_pv = &_pvh->pvh_first;
 			if (_pv->pv_ptste == NULL)
 				panic("pmap_remove_mapping: ptste == NULL");
 			if (_pv->pv_pmap != pmap_kernel() ||
@@ -1913,7 +1917,8 @@
 	 * Otherwise remove it from the PV table
 	 * (raise IPL since we may be called at interrupt time).
 	 */
-	pv = pa_to_pvh(pa);
+	pvh = pa_to_pvh(pa);
+	pv = &pvh->pvh_first;
 	ste = ST_ENTRY_NULL;
 	s = splvm();
 	/*
@@ -1927,7 +1932,6 @@
 		ptpmap = pv->pv_ptpmap;
 		npv = pv->pv_next;
 		if (npv) {
-			npv->pv_flags = pv->pv_flags;
 			*pv = *npv;
 			pmap_free_pv(npv);
 		} else
@@ -1952,7 +1956,8 @@
 		ptpmap = npv->pv_ptpmap;
 		pv->pv_next = npv->pv_next;
 		pmap_free_pv(npv);
-		pv = pa_to_pvh(pa);
+		pvh = pa_to_pvh(pa);
+		pv = &pvh->pvh_first;
 	}
 
 	/*
@@ -2035,13 +2040,13 @@
 		else
 			TBIAU();
 #endif
-		pv->pv_flags &= ~PV_PTPAGE;
+		pvh->pvh_attrs &= ~PVH_PTPAGE;
 		ptpmap->pm_ptpages--;
 	}
 	/*
 	 * Update saved attributes for managed page
 	 */
-	*pa_to_attribute(pa) |= bits;
+	pvh->pvh_attrs |= bits;
 	splx(s);
 }
 
@@ -2083,18 +2088,20 @@
 bool
 pmap_testbit(paddr_t pa, int bit)
 {
+	struct pv_header *pvh;
 	struct pv_entry *pv;
 	int *pte;
 	int s;
 
-	pv = pa_to_pvh(pa);
+	pvh = pa_to_pvh(pa);
+	pv = &pvh->pvh_first;
 	s = splvm();
 
 	/*
 	 * Check saved info first
 	 */
 
-	if (*pa_to_attribute(pa) & bit) {
+	if (pvh->pvh_attrs & bit) {
 		splx(s);
 		return(true);
 	}
@@ -2120,6 +2127,7 @@
 static void
 pmap_changebit(paddr_t pa, int bit, bool setem)
 {
+	struct pv_header *pvh;
 	struct pv_entry *pv;
 	int *pte, npte;
 	vaddr_t va;
@@ -2134,7 +2142,8 @@
 		    pa, bit, setem ? "set" : "clear");
 #endif
 
-	pv = pa_to_pvh(pa);
+	pvh = pa_to_pvh(pa);
+	pv = &pvh->pvh_first;
 	s = splvm();
 
 	/*
@@ -2142,7 +2151,7 @@
 	 */
 
 	if (!setem)
-		*pa_to_attribute(pa) &= ~bit;
+		pvh->pvh_attrs &= ~bit;
 
 	/*
 	 * Loop over all current mappings setting/clearing as appropos
@@ -2190,6 +2199,7 @@
 {
 	paddr_t ptpa;
 	struct vm_page *pg;
+	struct pv_header *pvh;
 	struct pv_entry *pv;
 #ifdef M68060
 	u_int stpa;
@@ -2393,14 +2403,17 @@
 	 * record the STE address.  This is so that we can invalidate
 	 * the STE when we remove the mapping for the page.
 	 */
-	pv = pa_to_pvh(ptpa);
+	pvh = pa_to_pvh(ptpa);
 	s = splvm();
-	if (pv) {
-		pv->pv_flags |= PV_PTPAGE;
+	if (pvh) {
+		pv = &pvh->pvh_first;
+		pvh->pvh_attrs |= PVH_PTPAGE;
 		do {
 			if (pv->pv_pmap == pmap_kernel() && pv->pv_va == va)
 				break;
 		} while ((pv = pv->pv_next) > 0);
+	} else {
+		pv = NULL;
 	}
 #ifdef DEBUG
 	if (pv == NULL) {
@@ -2459,10 +2472,11 @@
 void
 pmap_pvdump(paddr_t pa)
 {
+	struct pv_header *pvh;
 	struct pv_entry *pv;
 
 	printf("pa %lx", pa);
-	for (pv = pa_to_pvh(pa); pv; pv = pv->pv_next)
+	for (pvh = pa_to_pvh(pa), pv = &pvh->pvh_first; pv; pv = pv->pv_next)
 		printf(" -> pmap %p, va %lx, ptste %p, ptpmap %p, flags %x",
 		       pv->pv_pmap, pv->pv_va, pv->pv_ptste, pv->pv_ptpmap,
 		       pv->pv_flags);
--- a/sys/arch/atari/dev/clock.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/atari/dev/clock.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.40.10.2 2009/07/18 14:52:52 yamt Exp $	*/
+/*	$NetBSD: clock.c,v 1.40.10.3 2009/09/16 13:37:36 yamt Exp $	*/
 
 /*
  * Copyright (c) 1982, 1990 The Regents of the University of California.
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.40.10.2 2009/07/18 14:52:52 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.40.10.3 2009/09/16 13:37:36 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -428,18 +428,20 @@
  *                   Real Time Clock support                           *
  ***********************************************************************/
 
-u_int mc146818_read(void *rtc, u_int regno)
+u_int mc146818_read(void *cookie, u_int regno)
 {
+	struct rtc *rtc = cookie;
 
-	((struct rtc *)rtc)->rtc_regno = regno;
-	return ((struct rtc *)rtc)->rtc_data & 0377;
+	rtc->rtc_regno = regno;
+	return rtc->rtc_data & 0xff;
 }
 
-void mc146818_write(void *rtc, u_int regno, u_int value)
+void mc146818_write(void *cookie, u_int regno, u_int value)
 {
+	struct rtc *rtc = cookie;
 
-	((struct rtc *)rtc)->rtc_regno = regno;
-	((struct rtc *)rtc)->rtc_data  = value;
+	rtc->rtc_regno = regno;
+	rtc->rtc_data  = value;
 }
 
 static int
--- a/sys/arch/atari/include/iomap.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/atari/include/iomap.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: iomap.h,v 1.12 2003/04/02 07:35:55 thorpej Exp $	*/
+/*	$NetBSD: iomap.h,v 1.12.108.1 2009/09/16 13:37:36 yamt Exp $	*/
 
 /*
  * Copyright (c) 1995 Leo Weppelman.
@@ -81,9 +81,9 @@
 /*
  * Pre-allocated PCI-memory regions (atari_init.c). We need those in the
  * boot-stages.
- * XXX: Can probably be reduced to only PCI_CONF_SIZE (Leo).
+ * XXX: Can probably be reduced to only PCI_CONFIG_SIZE (Leo).
  */
-#define PCI_CONF_SIZE	(4 * PAGE_SIZE)
+#define PCI_CONFIG_SIZE	(4 * PAGE_SIZE)
 #define PCI_IO_SIZE	(PAGE_SIZE)
 #define PCI_MEM_SIZE	(PAGE_SIZE)
 
--- a/sys/arch/atari/include/vmparam.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/atari/include/vmparam.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmparam.h,v 1.21.78.1 2009/05/04 08:10:47 yamt Exp $	*/
+/*	$NetBSD: vmparam.h,v 1.21.78.2 2009/09/16 13:37:36 yamt Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
@@ -169,8 +169,7 @@
  * pmap-specific data stored in the vm_physmem[] array.
  */   
 struct pmap_physseg { 
-	struct pv_entry *pvent;         /* pv table for this seg */
-	char *attrs;                    /* page attributes for this seg */
+	struct pv_header *pvheader;	/* pv table for this seg */
 }; 
 
 
--- a/sys/arch/atari/isa/isa_machdep.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/atari/isa/isa_machdep.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: isa_machdep.c,v 1.30.48.2 2009/08/19 18:46:03 yamt Exp $	*/
+/*	$NetBSD: isa_machdep.c,v 1.30.48.3 2009/09/16 13:37:36 yamt Exp $	*/
 
 /*
  * Copyright (c) 1997 Leo Weppelman.  All rights reserved.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.30.48.2 2009/08/19 18:46:03 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.30.48.3 2009/09/16 13:37:36 yamt Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -155,7 +155,7 @@
 }
 
 void
-isa_detach_hook(isa_chipset_tag_t, device_t self)
+isa_detach_hook(isa_chipset_tag_t ic, device_t self)
 {
 }
 
--- a/sys/arch/atari/stand/binpatch/Makefile	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/atari/stand/binpatch/Makefile	Wed Sep 16 13:37:34 2009 +0000
@@ -1,9 +1,50 @@
-#	$NetBSD: Makefile,v 1.5 2001/12/12 01:49:38 tv Exp $
+#	$NetBSD: Makefile,v 1.5.122.1 2009/09/16 13:37:36 yamt Exp $
+
+BINDIR?= /sbin
+WARNS?=	4
+
+PROG=	binpatch
+SRCS=	binpatch.c
+SRCS+=	exec_aout.c exec_ecoff.c exec_elf32.c exec_elf64.c exec_coff.c
+
+#MAN=	binpatch.8	# currently it's in src/share/man/man8/man8.atari
+NOMAN=
+
+MDSETIMAGE=${NETBSDSRCDIR}/usr.sbin/mdsetimage
+CPPFLAGS+= -I${MDSETIMAGE}
+.PATH:	${MDSETIMAGE}
+
+.include <bsd.own.mk>	# for ${MACHINE_CPU}
 
-PROG=binpatch
-NOMAN=	# defined
-
-BINDIR=/sbin
-LDFLAGS+=-static
+.if	${MACHINE_ARCH} == "alpha"
+CPPFLAGS+=-DNLIST_ECOFF
+CPPFLAGS+=-DNLIST_ELF64
+.elif	${MACHINE_CPU} == "mips"
+CPPFLAGS+=-DNLIST_ECOFF
+CPPFLAGS+=-DNLIST_ELF32
+CPPFLAGS+=-DNLIST_AOUT
+.elif	${MACHINE_ARCH} == "powerpc"
+CPPFLAGS+=-DNLIST_ELF32
+.elif	${MACHINE_ARCH} == "m68k" || \
+	${MACHINE_ARCH} == "m68000" || \
+	${MACHINE_ARCH} == "vax" || \
+	${MACHINE_CPU} == "arm"
+CPPFLAGS+=-DNLIST_ELF32
+CPPFLAGS+=-DNLIST_AOUT
+.elif	${MACHINE_CPU} == "sh3"
+CPPFLAGS+=-DNLIST_COFF
+CPPFLAGS+=-DNLIST_ELF32
+.elif   ${MACHINE_ARCH} == "sparc" || ${MACHINE_ARCH} == "sparc64"  || \
+	${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64"
+CPPFLAGS+=-DNLIST_ELF64
+CPPFLAGS+=-DNLIST_ELF32
+CPPFLAGS+=-DNLIST_AOUT
+.else
+#CPPFLAGS+=-DNLIST_AOUT
+#CPPFLAGS+=-DNLIST_ECOFF
+CPPFLAGS+=-DNLIST_ELF32
+#CPPFLAGS+=-DNLIST_ELF64
+#CPPFLAGS+=-DNLIST_COFF
+.endif
 
 .include <bsd.prog.mk>
--- a/sys/arch/atari/stand/binpatch/binpatch.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/atari/stand/binpatch/binpatch.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,8 +1,7 @@
-/*	$NetBSD: binpatch.c,v 1.4.62.1 2009/05/04 08:10:48 yamt Exp $	*/
+/* $NetBSD: binpatch.c,v 1.4.62.2 2009/09/16 13:37:36 yamt Exp $ */
 
-/*
- * Copyright (c) 1994 Christian E. Hopps
- * All rights reserved.
+/*-
+ * Copyright (c) 2009 Izumi Tsutsui.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -12,11 +11,6 @@
  * 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 Christian E. Hopps.
- * 4. 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
@@ -30,211 +24,352 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+/*
+ * Copyright (c) 1996 Christopher G. Demetriou
+ * 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.
+ * 
+ * <<Id: LICENSE_GC,v 1.1 2001/10/01 23:24:05 cgd Exp>>
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__COPYRIGHT("@(#) Copyright (c) 1996\
+ Christopher G. Demetriou.  All rights reserved.");
+#endif /* not lint */
+
+#ifndef lint
+__RCSID("$NetBSD: binpatch.c,v 1.4.62.2 2009/09/16 13:37:36 yamt Exp $");
+#endif /* not lint */
+
 #include <sys/types.h>
-#include <a.out.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/inttypes.h>
+
+#include <err.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <nlist.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
+#include <unistd.h>
 
-extern char *optarg;
-extern int optind;
+#include "extern.h"
+
+int		main(int, char *[]);
+static void	usage(void) __dead;
 
-void error (char *) __attribute__((__noreturn__));
+bool replace, verbose;
+u_long addr, offset;
+char *symbol;
+size_t size;
+uint64_t val;
+	
+#ifdef NLIST_AOUT
+/*
+ * Since we can't get the text address from an a.out executable, we
+ * need to be able to specify it.  Note: there's no way to test to
+ * see if the user entered a valid address!
+ */
+int	T_flag_specified;	/* the -T flag was specified */
+u_long	text_start;		/* Start of kernel text */
+#endif /* NLIST_AOUT */
 
-int test = 1;
-int testbss;
-char foo = 23;
+static const struct {
+	const char *name;
+	int	(*check)(const char *, size_t);
+	int	(*findoff)(const char *, size_t, u_long, size_t *);
+} exec_formats[] = {
+#ifdef NLIST_AOUT
+	{	"a.out",	check_aout,	findoff_aout,	},
+#endif
+#ifdef NLIST_ECOFF
+	{	"ECOFF",	check_ecoff,	findoff_ecoff,	},
+#endif
+#ifdef NLIST_ELF32
+	{	"ELF32",	check_elf32,	findoff_elf32,	},
+#endif
+#ifdef NLIST_ELF64
+	{	"ELF64",	check_elf64,	findoff_elf64,	},
+#endif
+#ifdef NLIST_COFF
+	{	"COFF",		check_coff,	findoff_coff,	},
+#endif
+};
 
 
 int
 main(int argc, char *argv[])
 {
-  struct exec e;
-  int c;
-  u_long addr = 0, offset = 0;
-  u_long replace = 0, do_replace = 0;
-  char *symbol = 0;
-  char size = 4;  /* default to long */
-  char *fname;
-  int fd;
-  int type, off;
-  u_long  lval;
-  u_short sval;
-  u_char  cval;
-  
+	const char *fname;
+	struct stat sb;
+	struct nlist nl[2];
+	char *mappedfile;
+	size_t valoff;
+	void *valp;
+	uint8_t uval8;
+	int8_t  sval8;
+	uint16_t uval16;
+	int16_t  sval16;
+	uint32_t uval32;
+	int32_t  sval32;
+	uint64_t uval64;
+	int64_t  sval64;
+	int ch, fd, rv, i, n;
 
-  while ((c = getopt (argc, argv, "a:bwlr:s:o:")) != -1)
-    switch (c)
-      {
-      case 'a':
-	if (addr || symbol)
-	  error ("only one address/symbol allowed");
-	if (! strncmp (optarg, "0x", 2))
-	  sscanf (optarg, "%x", &addr);
-	else
-	  addr = atoi (optarg);
-	if (! addr)
-	  error ("invalid address");
-	break;
-
-      case 'b':
-	size = 1;
-	break;
-
-      case 'w':
-	size = 2;
-	break;
-
-      case 'l':
-	size = 4;
-	break;
+	setprogname(argv[0]);
 
-      case 'r':
-	do_replace = 1;
-	if (! strncmp (optarg, "0x", 2))
-	  sscanf (optarg, "%x", &replace);
-	else
-	  replace = atoi (optarg);
-	break;
-
-      case 's':
-	if (addr || symbol)
-	  error ("only one address/symbol allowed");
-	symbol = optarg;
-	break;
+	while ((ch = getopt(argc, argv, "bwldT:a:s:o:r:v")) != -1)
+		switch (ch) {
+		case 'b':
+			size = sizeof(uint8_t);
+			break;
+		case 'w':
+			size = sizeof(uint16_t);
+			break;
+		case 'l':
+			size = sizeof(uint32_t);
+			break;
+		case 'd':
+			size = sizeof(uint64_t);
+			break;
+		case 'a':
+			if (addr != 0 || symbol != NULL)
+				errx(EXIT_FAILURE,
+				    "only one address/symbol allowed");
+			addr = strtoul(optarg, NULL, 0);
+			break;
+		case 's':
+			if (addr != 0 || symbol != NULL)
+				errx(EXIT_FAILURE,
+				    "only one address/symbol allowed");
+			symbol = optarg;
+			break;
+		case 'o':
+			if (offset != 0)
+				err(EXIT_FAILURE,
+				    "only one offset allowed");
+			offset = strtoul(optarg, NULL, 0);
+			break;
+		case 'r':
+			replace = true;
+			val = strtoull(optarg, NULL, 0);
+			break;
+		case 'v':
+			verbose = true;
+			break;
+		case 'T':
+#ifdef NLIST_AOUT
+			T_flag_specified = 1;
+			text_start = strtoul(optarg, NULL, 0);
+			break;
+#else
+			fprintf(stderr, "%s: unknown option -- %c\n",
+			    getprogname(), (char)ch);
+			/*FALLTHROUGH*/
+#endif /* NLIST_AOUT */
+		case '?':
+		default:
+			usage();
+	}
+	argc -= optind;
+	argv += optind;
 
-      case 'o':
-	if (offset)
-	  error ("only one offset allowed");
-	if (! strncmp (optarg, "0x", 2))
-	  sscanf (optarg, "%x", &offset);
-	else
-          offset = atoi (optarg);
-        break;
-      }
-  
-  argv += optind;
-  argc -= optind;
+	if (argc != 1)
+		usage();
+
+	if (addr == 0 && symbol == NULL) {
+		warnx("no address or symbol specified");
+		usage();
+	}
 
+	if (size == 0)
+		size = sizeof(uint32_t);	/* default to int */
+
+	fname = argv[0];
+
+	if ((fd = open(fname, replace ? O_RDWR : O_RDONLY, 0))  == -1)
+		err(EXIT_FAILURE, "open %s", fname);
 
-  if (argc < 1)
-    error ("No file to patch.");
-
-  fname = argv[0];
-  if ((fd = open (fname, 0)) < 0)
-    error ("Can't open file");
+	if (symbol != NULL) {
+		nl[0].n_name = symbol;
+		nl[1].n_name = NULL;
+		if ((rv = __fdnlist(fd, nl)) != 0)
+			errx(EXIT_FAILURE, "could not find symbol %s in %s",
+			    symbol, fname);
+		addr = nl[0].n_value;
+		if (verbose)
+			fprintf(stderr, "got symbol address 0x%lx from %s\n",
+			    addr, fname);
+	}
 
-  if (read (fd, &e, sizeof (e)) != sizeof (e)
-      || N_BADMAG (e))
-    error ("Not a valid executable.");
+	addr += offset * size;
+
+	if (fstat(fd, &sb) == -1)
+		err(EXIT_FAILURE, "fstat %s", fname);
+	if (sb.st_size != (ssize_t)sb.st_size)
+		errx(EXIT_FAILURE, "%s too big to map", fname);
 
-  /* fake mid, so the N_ macros work on the amiga.. */
-  e.a_midmag |= 127 << 16;
+	if ((mappedfile = mmap(NULL, sb.st_size,
+	    replace ? PROT_READ | PROT_WRITE : PROT_READ,
+	    MAP_FILE | MAP_SHARED, fd, 0)) == (char *)-1)
+		err(EXIT_FAILURE, "mmap %s", fname);
+	if (verbose)
+		fprintf(stderr, "mapped %s\n", fname);
 
-  if (symbol)
-    {
-      struct nlist nl[2];
-      nl[0].n_un.n_name = symbol;
-      nl[1].n_un.n_name = 0;
-      if (nlist (fname, nl) != 0)
-	error ("Symbol not found.");
-      addr = nl[0].n_value;
-      type = nl[0].n_type & N_TYPE;
-    }
-  else
-    {
-      type = N_UNDF;
-      if (addr >= N_TXTADDR(e) && addr < N_DATADDR(e))
-	type = N_TEXT;
-      else if (addr >= N_DATADDR(e) && addr < N_DATADDR(e) + e.a_data)
-	type = N_DATA;
-    }
-  addr += offset;
+	n = __arraycount(exec_formats);
+	for (i = 0; i < n; i++) {
+		if ((*exec_formats[i].check)(mappedfile, sb.st_size) == 0)
+			break;
+	}
+	if (i == n)
+		errx(EXIT_FAILURE, "%s: unknown executable format", fname);
 
-  /* if replace-mode, have to reopen the file for writing.
-     Can't do that from the beginning, or nlist() will not 
-     work (at least not under AmigaDOS) */
-  if (do_replace)
-    {
-      close (fd);
-      if ((fd = open (fname, 2)) == -1)
-	error ("Can't reopen file for writing.");
-    }
+	if (verbose) {
+		fprintf(stderr, "%s is an %s binary\n", fname,
+		    exec_formats[i].name);
+#ifdef NLIST_AOUT
+		if (T_flag_specified)
+			fprintf(stderr, "kernel text loads at 0x%lx\n",
+			    text_start);
+#endif
+	}
 
-  if (type != N_TEXT && type != N_DATA)
-    error ("address/symbol is not in text or data section.");
+	if ((*exec_formats[i].findoff)(mappedfile, sb.st_size,
+	    addr, &valoff) != 0)
+		errx(EXIT_FAILURE, "couldn't find file offset for %s in %s",
+		    symbol != NULL ? nl[0].n_name : "address" , fname);
 
-  if (type == N_TEXT)
-    off = addr - N_TXTADDR(e) + N_TXTOFF(e);
-  else
-    off = addr - N_DATADDR(e) + N_DATOFF(e);
+	valp = mappedfile + valoff;
 
-  if (lseek (fd, off, 0) == -1)
-    error ("lseek");
+	if (symbol)
+		printf("%s(0x%lx): ", symbol, addr);
+	else
+		printf("0x%lx: ", addr);
 
-  /* not beautiful, but works on big and little endian machines */
-  switch (size)
-    {
-    case 1:
-      if (read (fd, &cval, 1) != 1)
-	error ("cread");
-      lval = cval;
-      break;
+	switch (size) {
+	case sizeof(uint8_t):
+		uval8 = *(uint8_t *)valp;
+		sval8 = *(int8_t *)valp;
+		printf("0x%02" PRIx8 " (%" PRIu8, uval8, uval8);
+		if (sval8 < 0)
+			printf("/%" PRId8, sval8);
+		printf(")");
+		break;
+	case sizeof(uint16_t):
+		uval16 = *(uint16_t *)valp;
+		sval16 = *(int16_t *)valp;
+		printf("0x%04" PRIx16 " (%" PRIu16, uval16, uval16);
+		if (sval16 < 0)
+			printf("/%" PRId16, sval16);
+		printf(")");
+		break;
+	case sizeof(uint32_t):
+		uval32 = *(uint32_t *)valp;
+		sval32 = *(int32_t *)valp;
+		printf("0x%08" PRIx32 " (%" PRIu32, uval32, uval32);
+		if (sval32 < 0)
+			printf("/%" PRId32, sval32);
+		printf(")");
+		break;
+	case sizeof(uint64_t):
+		uval64 = *(uint64_t *)valp;
+		sval64 = *(int64_t *)valp;
+		printf("0x%016" PRIx64 " (%" PRIu64, uval64, uval64);
+		if (sval64 < 0)
+			printf("/%" PRId64, sval64);
+		printf(")");
+		break;
+	}
+	printf(", at offset %#lx in %s\n", (unsigned long)valoff, fname);
 
-    case 2:
-      if (read (fd, &sval, 2) != 2)
-	error ("sread");
-      lval = sval;
-      break;
+	if (!replace)
+		goto done;
 
-    case 4:
-      if (read (fd, &lval, 4) != 4)
-	error ("lread");
-      break;
-    }
-
-  
-  if (symbol)
-    printf ("%s(0x%x): %d (0x%x)\n", symbol, addr, lval, lval);
-  else
-    printf ("0x%x: %d (0x%x)\n", addr, lval, lval);
+	printf("new value: ");
 
-  if (do_replace)
-    {
-      if (lseek (fd, off, 0) == -1)
-	error ("write-lseek");
-      switch (size)
-	{
-	case 1:
-	  cval = replace;
-	  if (cval != replace)
-	    error ("byte-value overflow.");
-	  if (write (fd, &cval, 1) != 1)
-	    error ("cwrite");
-	  break;
+	switch (size) {
+	case sizeof(uint8_t):
+		uval8 = (uint8_t)val;
+		sval8 = (int8_t)val;
+		printf("0x%02" PRIx8 " (%" PRIu8, uval8, uval8);
+		if (sval8 < 0)
+			printf("/%" PRId8, sval8);
+		printf(")");
+		*(uint8_t *)valp = uval8;
+		break;
+	case sizeof(uint16_t):
+		uval16 = (uint16_t)val;
+		sval16 = (int16_t)val;
+		printf("0x%04" PRIx16 " (%" PRIu16, uval16, uval16);
+		if (sval16 < 0)
+			printf("/%" PRId16, sval16);
+		printf(")");
+		*(uint16_t *)valp = uval16;
+		break;
+	case sizeof(uint32_t):
+		uval32 = (uint32_t)val;
+		sval32 = (int32_t)val;
+		printf("0x%08" PRIx32 " (%" PRIu32, uval32, uval32);
+		if (sval32 < 0)
+			printf("/%" PRId32, sval32);
+		printf(")");
+		*(uint32_t *)valp = uval32;
+		break;
+	case sizeof(uint64_t):
+		uval64 = (uint64_t)val;
+		sval64 = (int64_t)val;
+		printf("0x%016" PRIx64 " (%" PRIu64, uval64, uval64);
+		if (sval64 < 0)
+			printf("/%" PRId64, sval64);
+		printf(")");
+		*(uint64_t *)valp = uval64;
+		break;
+	}
+	printf("\n");
+	
+ done:
+	munmap(mappedfile, sb.st_size);
+	close(fd);
 
-	case 2:
-	  sval = replace;
-	  if (sval != replace)
-	    error ("word-value overflow.");
-	  if (write (fd, &sval, 2) != 2)
-	    error ("swrite");
-	  break;
-
-	case 4:
-	  if (write (fd, &replace, 4) != 4)
-	    error ("lwrite");
-	  break;
-	}
-    }
-
-  close (fd);
+	if (verbose)
+		fprintf(stderr, "exiting\n");
+	exit(EXIT_SUCCESS);
 }
 
-
+static void
+usage(void)
+{
 
-void error (str)
-     char *str;
-{
-  fprintf (stderr, "%s\n", str);
-  exit (1);
+	fprintf(stderr,
+	    "usage: %s [-b|-w|-l|-d] [-a address | -s symbol] [-o offset]\n"
+	    "                [-r value] "
+#ifdef NLIST_AOUT
+	    "[-T text_start] "
+#endif
+	    "[-v] binary\n", getprogname());
+	exit(EXIT_FAILURE);
 }
--- a/sys/arch/atari/stand/bootxx/bootxx.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/atari/stand/bootxx/bootxx.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bootxx.c,v 1.12.78.1 2009/05/04 08:10:48 yamt Exp $	*/
+/*	$NetBSD: bootxx.c,v 1.12.78.2 2009/09/16 13:37:37 yamt Exp $	*/
 
 /*
  * Copyright (c) 1995 Waldi Ravens.
@@ -61,7 +61,7 @@
 	setheap(end, (void*)(LOADADDR3 - 4));
 
 	printf("\033v\nNetBSD/atari secondary bootloader"
-						" ($Revision: 1.12.78.1 $)\n\n");
+						" ($Revision: 1.12.78.2 $)\n\n");
 
 	if (init_dskio(readsector, disklabel, -1))
 		return -1;
@@ -191,7 +191,7 @@
 	}
 	if (fd < 0)
 		return -1;
-	while((bsize = read(fd, bstart, 1024)) > 0) {
+	while ((bsize = read(fd, bstart, 1024)) > 0) {
 		bstart += bsize;
 	}
 	close(fd);
@@ -201,7 +201,8 @@
 void
 _rtt(void)
 {
+
 	printf("Halting...\n");
-	for(;;)
+	for (;;)
 		;
 }
--- a/sys/arch/atari/stand/bootxx/filesystem.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/atari/stand/bootxx/filesystem.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: filesystem.c,v 1.7 2005/12/11 12:17:00 christos Exp $	*/
+/*	$NetBSD: filesystem.c,v 1.7.78.1 2009/09/16 13:37:37 yamt Exp $	*/
 
 /*
  * Copyright (c) 1993 Philip A. Nelson.
@@ -38,4 +38,4 @@
 	FS_OPS(ufs),
 };
 
-int nfsys = sizeof(file_system)/sizeof(struct fs_ops);
+int nfsys = __arraycount(file_system);
--- a/sys/arch/atari/stand/bootxxx/bootxxx.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/atari/stand/bootxxx/bootxxx.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bootxxx.c,v 1.3.78.1 2009/05/04 08:10:48 yamt Exp $	*/
+/*	$NetBSD: bootxxx.c,v 1.3.78.2 2009/09/16 13:37:37 yamt Exp $	*/
 
 /*
  * Copyright (c) 2001 Leo Weppelman.
@@ -47,10 +47,7 @@
 void	boot_BSD(struct kparamb *)__attribute__((noreturn));
 
 int
-bootxxx(readsector, disklabel, od)
-	void	*readsector,
-		*disklabel;
-	osdsc_t	*od;
+bootxxx(void *readsector, void *disklabel, osdsc_t *od)
 {
 	int		fd;
 	char		*errmsg;
@@ -61,20 +58,20 @@
 	/* XXX: Limit should be 16MB */
 	setheap(end, (void*)0x1000000);
 	printf("\033v\nNetBSD/Atari tertiary bootloader "
-					"($Revision: 1.3.78.1 $)\n\n");
+					"($Revision: 1.3.78.2 $)\n\n");
 
 	if (init_dskio(readsector, disklabel, od->rootfs))
-		return(-1);
+		return -1;
 
 	sys_info(od);
 	if (!(od->cputype & ATARI_ANYCPU)) {
 		printf("Unknown CPU-type.\n");
-		return(-2);
+		return -2;
 	}
 
 	if ((fd = open(od->osname, 0)) < 0) {
 		printf("Cannot open kernel '%s'\n", od->osname);
-		return (-3);
+		return -3;
 	}
 
 #ifndef __ELF__		/* a.out */
@@ -82,10 +79,10 @@
 #else
 	if (elf_load(fd, od, &errmsg, 1) != 0)
 #endif
-		return(-4);
+		return -4;
 
 	boot_BSD(&od->kp);
-	return(-5);
+	return -5;
 
 	/* NOTREACHED */
 }
@@ -93,7 +90,8 @@
 void
 _rtt(void)
 {
+
 	printf("Halting...\n");
-	for(;;)
+	for (;;)
 		;
 }
--- a/sys/arch/atari/stand/bootxxx/filesystem.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/atari/stand/bootxxx/filesystem.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: filesystem.c,v 1.3 2005/12/11 12:17:00 christos Exp $	*/
+/*	$NetBSD: filesystem.c,v 1.3.78.1 2009/09/16 13:37:37 yamt Exp $	*/
 
 /*
  * Copyright (c) 1993 Philip A. Nelson.
@@ -38,4 +38,4 @@
 	FS_OPS(ufs),
 };
 
-int nfsys = sizeof(file_system) / sizeof(file_system[0]);
+int nfsys = __arraycount(file_system);
--- a/sys/arch/cats/conf/Makefile.cats.inc	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/cats/conf/Makefile.cats.inc	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.cats.inc,v 1.20.10.1 2009/05/04 08:10:53 yamt Exp $
+#	$NetBSD: Makefile.cats.inc,v 1.20.10.2 2009/09/16 13:37:37 yamt Exp $
 
 MACHINE_ARCH=	arm
 CPPFLAGS+=	-D${MACHINE}
@@ -27,13 +27,13 @@
 		-R .ident -R .arm.atpcs -R .comment -R .note.netbsd.ident \
 		-R .debug_abbrev -R .debug_info -R .debug_line -R .debug_str \
 		-R .debug_frame -R .debug_loc -R .debug_pubnames \
-		-R .debug_aranges \
+		-R .debug_aranges -R .ARM.attributes \
 		$@ $@.aout"; \
 	${OBJCOPY} -O a.out-arm-netbsd \
 		-R .ident -R .arm.atpcs -R .comment -R .note.netbsd.ident \
 		-R .debug_abbrev -R .debug_info -R .debug_line -R .debug_str \
 		-R .debug_frame -R .debug_loc -R .debug_pubnames \
-		-R .debug_aranges \
+		-R .debug_aranges -R .ARM.attributes \
 		$@ $@.aout
 .endif
 .endif
--- a/sys/arch/cesfic/cesfic/machdep.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/cesfic/cesfic/machdep.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.40.10.2 2009/08/19 18:46:04 yamt Exp $	*/
+/*	$NetBSD: machdep.c,v 1.40.10.3 2009/09/16 13:37:37 yamt Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.40.10.2 2009/08/19 18:46:04 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.40.10.3 2009/09/16 13:37:37 yamt Exp $");
 
 #include "opt_bufcache.h"
 #include "opt_ddb.h"
@@ -531,7 +531,7 @@
 	dump = bdev->d_dump;
 	blkno = dumplo;
 
-	printf("\ndumping to dev 0x%x, offset %ld\n", dumpdev, dumplo);
+	printf("\ndumping to dev %"PRIx64", offset %ld\n", dumpdev, dumplo);
 
 	printf("dump ");
 	maddr = lowram;
--- a/sys/arch/cesfic/include/vmparam.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/cesfic/include/vmparam.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmparam.h,v 1.9.78.1 2009/05/04 08:10:54 yamt Exp $	*/
+/*	$NetBSD: vmparam.h,v 1.9.78.2 2009/09/16 13:37:37 yamt Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -188,8 +188,7 @@
  * pmap-specific data stored in the vm_physmem[] array.
  */
 struct pmap_physseg {
-	struct pv_entry *pvent;		/* pv table for this seg */
-	char *attrs;			/* page attributes for this seg */
+	struct pv_header *pvheader;	/* pv table for this seg */
 };
 
 #endif /* _MACHINE_VMPARAM_H_ */
--- a/sys/arch/cobalt/cobalt/bus.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/cobalt/cobalt/bus.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus.c,v 1.33.44.2 2009/05/04 08:10:54 yamt Exp $	*/
+/*	$NetBSD: bus.c,v 1.33.44.3 2009/09/16 13:37:37 yamt Exp $	*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus.c,v 1.33.44.2 2009/05/04 08:10:54 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus.c,v 1.33.44.3 2009/09/16 13:37:37 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -44,6 +44,8 @@
 #define _COBALT_BUS_DMA_PRIVATE
 #include <machine/bus.h>
 
+#include <common/bus_dma/bus_dmamem_common.h>
+
 #include <uvm/uvm_extern.h>
 
 #include <mips/cache.h>
@@ -117,6 +119,15 @@
 	return 0;
 }
 
+paddr_t
+bus_space_mmap(bus_space_tag_t t, bus_addr_t addr, off_t off, int prot,
+    int flags)
+{
+
+	/* XXX not implemented */
+	return -1;
+}
+
 /*
  * Common function for DMA map creation.  May be called by bus-specific
  * DMA map creation functions.
@@ -594,57 +605,11 @@
     int flags)
 {
 	extern paddr_t avail_start, avail_end;
-	vaddr_t curaddr, lastaddr;
-	psize_t high;
-	struct vm_page *m;
-	struct pglist mlist;
-	int curseg, error;
 
-	/* Always round the size. */
-	size = round_page(size);
-
-	high = avail_end - PAGE_SIZE;
-
-	/*
-	 * Allocate pages from the VM system.
-	 */
-	error = uvm_pglistalloc(size, avail_start, high, alignment, boundary,
-	    &mlist, nsegs, (flags & BUS_DMA_NOWAIT) == 0);
-	if (error)
-		return error;
-
-	/*
-	 * Compute the location, size, and number of segments actually
-	 * returned by the VM code.
-	 */
-	m = mlist.tqh_first;
-	curseg = 0;
-	lastaddr = segs[curseg].ds_addr = VM_PAGE_TO_PHYS(m);
-	segs[curseg].ds_len = PAGE_SIZE;
-	m = m->pageq.queue.tqe_next;
-
-	for (; m != NULL; m = m->pageq.queue.tqe_next) {
-		curaddr = VM_PAGE_TO_PHYS(m);
-#ifdef DIAGNOSTIC
-		if (curaddr < avail_start || curaddr >= high) {
-			printf("uvm_pglistalloc returned non-sensical"
-			    " address 0x%lx\n", curaddr);
-			panic("_bus_dmamem_alloc");
-		}
-#endif
-		if (curaddr == (lastaddr + PAGE_SIZE))
-			segs[curseg].ds_len += PAGE_SIZE;
-		else {
-			curseg++;
-			segs[curseg].ds_addr = curaddr;
-			segs[curseg].ds_len = PAGE_SIZE;
-		}
-		lastaddr = curaddr;
-	}
-
-	*rsegs = curseg + 1;
-
-	return 0;
+	return (_bus_dmamem_alloc_range_common(t, size, alignment, boundary,
+					       segs, nsegs, rsegs, flags,
+					       avail_start /*low*/,
+					       avail_end - PAGE_SIZE /*high*/));
 }
 
 /*
@@ -654,25 +619,8 @@
 void
 _bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs)
 {
-	struct vm_page *m;
-	bus_addr_t addr;
-	struct pglist mlist;
-	int curseg;
 
-	/*
-	 * Build a list of pages to free back to the VM system.
-	 */
-	TAILQ_INIT(&mlist);
-	for (curseg = 0; curseg < nsegs; curseg++) {
-		for (addr = segs[curseg].ds_addr;
-		    addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
-		    addr += PAGE_SIZE) {
-			m = PHYS_TO_VM_PAGE(addr);
-			TAILQ_INSERT_TAIL(&mlist, m, pageq.queue);
-		}
-	}
-
-	uvm_pglistfree(&mlist);
+	_bus_dmamem_free_common(t, segs, nsegs);
 }
 
 /*
@@ -683,11 +631,6 @@
 _bus_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
     size_t size, void **kvap, int flags)
 {
-	vaddr_t va;
-	bus_addr_t addr;
-	int curseg;
-	const uvm_flag_t kmflags =
-	    (flags & BUS_DMA_NOWAIT) != 0 ? UVM_KMF_NOWAIT : 0;
 
 	/*
 	 * If we're only mapping 1 segment, use KSEG0 or KSEG1, to avoid
@@ -701,31 +644,8 @@
 		return 0;
 	}
 
-	size = round_page(size);
-
-	va = uvm_km_alloc(kernel_map, size, 0, UVM_KMF_VAONLY | kmflags);
-
-	if (va == 0)
-		return (ENOMEM);
-
-	*kvap = (void *)va;
-
-	for (curseg = 0; curseg < nsegs; curseg++) {
-		for (addr = segs[curseg].ds_addr;
-		    addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
-		    addr += PAGE_SIZE, va += PAGE_SIZE, size -= PAGE_SIZE) {
-			if (size == 0)
-				panic("_bus_dmamem_map: size botch");
-			pmap_enter(pmap_kernel(), va, addr,
-			    VM_PROT_READ | VM_PROT_WRITE,
-			    VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED);
-
-			/* XXX Do something about COHERENT here. */
-		}
-	}
-	pmap_update(pmap_kernel());
-
-	return 0;
+	/* XXX BUS_DMA_COHERENT */
+	return (_bus_dmamem_map_common(t, segs, nsegs, size, kvap, flags, 0));
 }
 
 /*
@@ -736,11 +656,6 @@
 _bus_dmamem_unmap(bus_dma_tag_t t, void *kva, size_t size)
 {
 
-#ifdef DIAGNOSTIC
-	if ((u_long)kva & PGOFSET)
-		panic("_bus_dmamem_unmap");
-#endif
-
 	/*
 	 * Nothing to do if we mapped it with KSEG0 or KSEG1 (i.e.
 	 * not in KSEG2).
@@ -749,10 +664,7 @@
 	    kva < (void *)MIPS_KSEG2_START)
 		return;
 
-	size = round_page(size);
-	pmap_remove(pmap_kernel(), (vaddr_t)kva, (vaddr_t)kva + size);
-	pmap_update(pmap_kernel());
-	uvm_km_free(kernel_map, (vaddr_t)kva, size, UVM_KMF_VAONLY);
+	_bus_dmamem_unmap_common(t, kva, size);
 }
 
 /*
@@ -763,26 +675,11 @@
 _bus_dmamem_mmap(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
     off_t off, int prot, int flags)
 {
-	int i;
+	bus_addr_t rv;
 
-	for (i = 0; i < nsegs; i++) {
-#ifdef DIAGNOSTIC
-		if (off & PGOFSET)
-			panic("_bus_dmamem_mmap: offset unaligned");
-		if (segs[i].ds_addr & PGOFSET)
-			panic("_bus_dmamem_mmap: segment unaligned");
-		if (segs[i].ds_len & PGOFSET)
-			panic("_bus_dmamem_mmap: segment size not multiple"
-			    " of page size");
-#endif
-		if (off >= segs[i].ds_len) {
-			off -= segs[i].ds_len;
-			continue;
-		}
-
-		return mips_btop((char *)segs[i].ds_addr + off);
-	}
-
-	/* Page not found. */
-	return -1;
+	rv = _bus_dmamem_mmap_common(t, segs, nsegs, off, prot, flags);
+	if (rv == (bus_addr_t)-1)
+		return (-1);
+	
+	return (mips_btop((char *)rv));
 }
--- a/sys/arch/cobalt/conf/files.cobalt	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/cobalt/conf/files.cobalt	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.cobalt,v 1.32.4.1 2009/05/04 08:10:54 yamt Exp $
+#	$NetBSD: files.cobalt,v 1.32.4.2 2009/09/16 13:37:37 yamt Exp $
 
 maxpartitions 16
 
@@ -48,6 +48,8 @@
 
 file arch/mips/mips/softintr.c
 
+file common/bus_dma/bus_dmamem_common.c
+
 file dev/md_root.c			memory_disk_hooks
 
 file dev/cons.c
--- a/sys/arch/cobalt/dev/panel.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/cobalt/dev/panel.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: panel.c,v 1.17.4.1 2008/05/16 02:22:09 yamt Exp $ */
+/* $NetBSD: panel.c,v 1.17.4.2 2009/09/16 13:37:37 yamt Exp $ */
 
 /*
  * Copyright (c) 2002 Dennis I. Chernoivanov
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: panel.c,v 1.17.4.1 2008/05/16 02:22:09 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: panel.c,v 1.17.4.2 2009/09/16 13:37:37 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -41,6 +41,7 @@
 #include <sys/device.h>
 #include <sys/callout.h>
 #include <sys/select.h>
+#include <sys/reboot.h>
 
 #include <machine/bus.h>
 #include <machine/autoconf.h>
@@ -76,14 +77,18 @@
 	"NetBSD/cobalt   ",
 	"Starting up...  "
 };
-static const struct lcd_message shutdown_message = {
+static const struct lcd_message halt_message = {
 	"NetBSD/cobalt   ",
-	"Shutting down..."
+	"Halting...      "
+};
+static const struct lcd_message reboot_message = {
+	"NetBSD/cobalt   ",
+	"Rebooting...    "
 };
 
 static int	panel_match(device_t, cfdata_t, void *);
 static void	panel_attach(device_t, device_t, void *);
-static void	panel_shutdown(void *);
+static bool	panel_shutdown(device_t, int);
 
 static void	panel_soft(void *);
 
@@ -139,6 +144,8 @@
 	bus_space_subregion(sc->sc_lcd.sc_iot, sc->sc_lcd.sc_ioir, DATA_OFFSET,
 	    1, &sc->sc_lcd.sc_iodr);
 
+	printf("\n");
+
 	sc->sc_lcd.sc_dev_ok = 1;
 	sc->sc_lcd.sc_cols = PANEL_COLS;
 	sc->sc_lcd.sc_vcols = PANEL_VCOLS;
@@ -156,7 +163,7 @@
 	hd44780_ddram_io(&sc->sc_lcd, sc->sc_lcd.sc_curchip, &io,
 	    HD_DDRAM_WRITE);
 
-	shutdownhook_establish(panel_shutdown, sc);
+	pmf_device_register1(self, NULL, NULL, panel_shutdown);
 
 	sc->sc_kp.sc_iot = maa->ma_iot;
 	sc->sc_kp.sc_ioh = MIPS_PHYS_TO_KSEG1(PANEL_BASE); /* XXX */
@@ -169,22 +176,25 @@
 
 	callout_init(&sc->sc_callout, 0);
 	selinit(&sc->sc_selq);
-
-	printf("\n");
 }
 
-static void
-panel_shutdown(void *arg)
+static bool
+panel_shutdown(device_t self, int howto)
 {
-	struct panel_softc *sc = arg;
+	struct panel_softc *sc = device_private(self);
 	struct hd44780_io io;
 
 	/* Goodbye World */
 	io.dat = 0;
 	io.len = PANEL_VCOLS * PANEL_ROWS;
-	memcpy(io.buf, &shutdown_message, io.len);
+	if (howto & RB_HALT)
+		memcpy(io.buf, &halt_message, io.len);
+	else
+		memcpy(io.buf, &reboot_message, io.len);
 	hd44780_ddram_io(&sc->sc_lcd, sc->sc_lcd.sc_curchip, &io,
 	    HD_DDRAM_WRITE);
+
+	return true;
 }
 
 static uint8_t
--- a/sys/arch/cobalt/include/bus.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/cobalt/include/bus.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus.h,v 1.21.44.1 2008/05/16 02:22:09 yamt Exp $	*/
+/*	$NetBSD: bus.h,v 1.21.44.2 2009/09/16 13:37:37 yamt Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -88,6 +88,16 @@
 	    bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp);
 
 /*
+ *	paddr_t bus_space_mmap(bus_space_tag_t t,
+ *          bus_addr_t addr, off_t offset, int prot, int flags);
+ *
+ * Mmap bus space for a user application.
+ */
+
+paddr_t	bus_space_mmap(bus_space_tag_t t, bus_addr_t addr, off_t off, int prot,
+    int flags);
+
+/*
  *	int bus_space_alloc(bus_space_tag_t t, bus_addr_t, rstart,
  *	    bus_addr_t rend, bus_size_t size, bus_size_t align,
  *	    bus_size_t boundary, int flags, bus_addr_t *addrp,
--- a/sys/arch/dreamcast/conf/GENERIC	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/dreamcast/conf/GENERIC	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.82.10.2 2009/05/04 08:10:55 yamt Exp $
+# $NetBSD: GENERIC,v 1.82.10.3 2009/09/16 13:37:37 yamt Exp $
 #
 # GENERIC machine description file
 # 
@@ -187,7 +187,7 @@
 gapspci*	at g2bus?			# GAPS PCI bridge
 pci*		at gapspci?
 rtk*		at pci? dev ? function ?	# SEGA Broadband Adapter
-ukphy*		at mii? phy ?
+rlphy*		at mii? phy ?
 
 mbe*		at g2bus?			# SEGA LAN Adapter
 
--- a/sys/arch/dreamcast/dev/g2/g2bus_bus_mem.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/dreamcast/dev/g2/g2bus_bus_mem.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: g2bus_bus_mem.c,v 1.13.62.1 2008/05/16 02:22:09 yamt Exp $	*/
+/*	$NetBSD: g2bus_bus_mem.c,v 1.13.62.2 2009/09/16 13:37:37 yamt Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
-__KERNEL_RCSID(0, "$NetBSD: g2bus_bus_mem.c,v 1.13.62.1 2008/05/16 02:22:09 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: g2bus_bus_mem.c,v 1.13.62.2 2009/09/16 13:37:37 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -53,6 +53,7 @@
 int	g2bus_bus_mem_map(void *, bus_addr_t, bus_size_t, int,
 	    bus_space_handle_t *);
 void	g2bus_bus_mem_unmap(void *, bus_space_handle_t, bus_size_t);
+paddr_t	g2bus_bus_mem_mmap(void *, bus_addr_t, off_t, int, int);
 
 uint8_t g2bus_bus_mem_read_1(void *, bus_space_handle_t, bus_size_t);
 uint16_t g2bus_bus_mem_read_2(void *, bus_space_handle_t, bus_size_t);
@@ -114,6 +115,7 @@
 
 	t->dbs_map = g2bus_bus_mem_map;
 	t->dbs_unmap = g2bus_bus_mem_unmap;
+	t->dbs_mmap = g2bus_bus_mem_mmap;
 
 	t->dbs_r_1 = g2bus_bus_mem_read_1;
 	t->dbs_r_2 = g2bus_bus_mem_read_2;
@@ -153,6 +155,14 @@
 	/* Nothing to do. */
 }
 
+paddr_t
+g2bus_bus_mem_mmap(void *v, bus_addr_t addr, off_t offset, int prot, int flags)
+{
+
+	/* XXX not implemented */
+	return -1;
+}
+
 /*
  * G2 bus cycles must not be interrupted by IRQs or G2 DMA.
  * The following paired macros will take the necessary precautions.
--- a/sys/arch/dreamcast/include/bus.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/dreamcast/include/bus.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus.h,v 1.13.44.1 2008/05/16 02:22:09 yamt Exp $	*/
+/*	$NetBSD: bus.h,v 1.13.44.2 2009/09/16 13:37:38 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2000, 2001 The NetBSD Foundation, Inc.
@@ -121,6 +121,7 @@
 			    bus_size_t);
 	int		(*dbs_subregion)(void *, bus_space_handle_t,
 			    bus_size_t, bus_size_t, bus_space_handle_t *);
+	paddr_t		(*dbs_mmap)(void *, bus_addr_t, off_t, int, int);
 
 	/* allocation/deallocation */
 	int		(*dbs_alloc)(void *, bus_addr_t, bus_addr_t,
@@ -270,6 +271,8 @@
 	(*(t)->dbs_unmap)((t)->dbs_cookie, (h), (s))
 #define	bus_space_subregion(t, h, o, s, hp)				\
 	(*(t)->dbs_subregion)((t)->dbs_cookie, (h), (o), (s), (hp))
+#define	bus_space_mmap(t, a, o, p, f)				\
+	(*(t)->dbs_mmap)((t)->dbs_cookie, (a), (o), (p), (f))
 
 #endif /* _KERNEL */
 
--- a/sys/arch/evbmips/conf/MALTA	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/evbmips/conf/MALTA	Wed Sep 16 13:37:34 2009 +0000
@@ -1,10 +1,10 @@
-#	$NetBSD: MALTA,v 1.46.40.1 2009/05/04 08:11:01 yamt Exp $
+#	$NetBSD: MALTA,v 1.46.40.2 2009/09/16 13:37:38 yamt Exp $
 
 include 	"arch/evbmips/conf/std.malta"
 
 #options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		"MALTA-$Revision: 1.46.40.1 $"
+#ident 		"MALTA-$Revision: 1.46.40.2 $"
 
 maxusers	32
 
@@ -51,6 +51,7 @@
 options 	COMPAT_20	# NetBSD 2.0 binary compatibility
 options 	COMPAT_30	# NetBSD 3.0 compatibility.
 options 	COMPAT_40	# NetBSD 4.0 compatibility.
+options 	COMPAT_50	# NetBSD 5.0 compatibility.
 #options 	EXEC_ECOFF	# exec ECOFF binaries
 #options 	COMPAT_ULTRIX	# binary compatibility with Ultrix
 options 	COMPAT_BSDPTY	# /dev/[pt]ty?? ptys.
--- a/sys/arch/evbppc/conf/PMPPC	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/evbppc/conf/PMPPC	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: PMPPC,v 1.3.18.1 2009/05/04 08:11:02 yamt Exp $
+#	$NetBSD: PMPPC,v 1.3.18.2 2009/09/16 13:37:38 yamt Exp $
 #
 #	PMPPC
 #
@@ -33,7 +33,7 @@
 options 	DDB		# in-kernel debugger
 options 	DDB_HISTORY_SIZE=512	# enable history editing in DDB
 #options 	TRAP_PANICWAIT
-options 	SYMTAB_SPACE=510000	# size for embedded symbol table
+options 	SYMTAB_SPACE=524288	# size for embedded symbol table
 
 #options 	KGDB		# remote debugger
 #options 	KGDB_DEVNAME="\"com\"",KGDB_DEVADDR=0xff600400,KGDB_DEVRATE=9600
--- a/sys/arch/ews4800mips/conf/files.ews4800mips	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/ews4800mips/conf/files.ews4800mips	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.ews4800mips,v 1.3 2008/02/20 21:43:34 drochner Exp $
+#	$NetBSD: files.ews4800mips,v 1.3.10.1 2009/09/16 13:37:38 yamt Exp $
 
 maxpartitions 16
 
@@ -21,6 +21,8 @@
 file arch/ews4800mips/ews4800mips/sector.c		disk
 file arch/ews4800mips/ews4800mips/vtoc.c		disk
 
+file common/bus_dma/bus_dmamem_common.c
+
 file arch/ews4800mips/ews4800mips/cons_machdep.c
 file dev/cons.c
 
--- a/sys/arch/ews4800mips/ews4800mips/bus_dma.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/ews4800mips/ews4800mips/bus_dma.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus_dma.c,v 1.7.38.2 2009/05/04 08:11:04 yamt Exp $	*/
+/*	$NetBSD: bus_dma.c,v 1.7.38.3 2009/09/16 13:37:38 yamt Exp $	*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.7.38.2 2009/05/04 08:11:04 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.7.38.3 2009/09/16 13:37:38 yamt Exp $");
 
 /* #define	BUS_DMA_DEBUG */
 #include <sys/param.h>
@@ -45,6 +45,8 @@
 #include <machine/bus.h>
 #include <machine/sbdvar.h>
 
+#include <common/bus_dma/bus_dmamem_common.h>
+
 #include <uvm/uvm_extern.h>
 
 extern	paddr_t kvtophys(vaddr_t);		/* XXX */
@@ -539,57 +541,11 @@
     int flags)
 {
 	extern paddr_t avail_start, avail_end;
-	vaddr_t curaddr, lastaddr;
-	psize_t high;
-	struct vm_page *m;
-	struct pglist mlist;
-	int curseg, error;
 
-	/* Always round the size. */
-	size = round_page(size);
-
-	high = avail_end - PAGE_SIZE;
-
-	/*
-	 * Allocate pages from the VM system.
-	 */
-	error = uvm_pglistalloc(size, avail_start, high, alignment, boundary,
-	    &mlist, nsegs, (flags & BUS_DMA_NOWAIT) == 0);
-	if (error)
-		return error;
-
-	/*
-	 * Compute the location, size, and number of segments actually
-	 * returned by the VM code.
-	 */
-	m = mlist.tqh_first;
-	curseg = 0;
-	lastaddr = segs[curseg].ds_addr = VM_PAGE_TO_PHYS(m);
-	segs[curseg].ds_len = PAGE_SIZE;
-	m = m->pageq.queue.tqe_next;
-
-	for (; m != NULL; m = m->pageq.queue.tqe_next) {
-		curaddr = VM_PAGE_TO_PHYS(m);
-#ifdef DIAGNOSTIC
-		if (curaddr < avail_start || curaddr >= high) {
-			printf("uvm_pglistalloc returned non-sensical"
-			    " address 0x%lx\n", curaddr);
-			panic("_bus_dmamem_alloc");
-		}
-#endif
-		if (curaddr == (lastaddr + PAGE_SIZE))
-			segs[curseg].ds_len += PAGE_SIZE;
-		else {
-			curseg++;
-			segs[curseg].ds_addr = curaddr;
-			segs[curseg].ds_len = PAGE_SIZE;
-		}
-		lastaddr = curaddr;
-	}
-
-	*rsegs = curseg + 1;
-
-	return 0;
+	return (_bus_dmamem_alloc_range_common(t, size, alignment, boundary,
+					       segs, nsegs, rsegs, flags,
+					       avail_start /*low*/,
+					       avail_end - PAGE_SIZE /*high*/));
 }
 
 /*
@@ -599,25 +555,8 @@
 void
 _bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs)
 {
-	struct vm_page *m;
-	bus_addr_t addr;
-	struct pglist mlist;
-	int curseg;
 
-	/*
-	 * Build a list of pages to free back to the VM system.
-	 */
-	TAILQ_INIT(&mlist);
-	for (curseg = 0; curseg < nsegs; curseg++) {
-		for (addr = segs[curseg].ds_addr;
-		    addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
-		    addr += PAGE_SIZE) {
-			m = PHYS_TO_VM_PAGE(addr);
-			TAILQ_INSERT_TAIL(&mlist, m, pageq.queue);
-		}
-	}
-
-	uvm_pglistfree(&mlist);
+	_bus_dmamem_free_common(t, segs, nsegs);
 }
 
 /*
@@ -628,11 +567,6 @@
 _bus_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
     size_t size, void **kvap, int flags)
 {
-	vaddr_t va;
-	bus_addr_t addr;
-	int curseg;
-	const uvm_flag_t kmflags =
-	    (flags & BUS_DMA_NOWAIT) != 0 ? UVM_KMF_NOWAIT : 0;
 
 	/*
 	 * If we're only mapping 1 segment, use KSEG0 or KSEG1, to avoid
@@ -646,31 +580,8 @@
 		return 0;
 	}
 
-	size = round_page(size);
-
-	va = uvm_km_alloc(kernel_map, size, 0, UVM_KMF_VAONLY | kmflags);
-
-	if (va == 0)
-		return (ENOMEM);
-
-	*kvap = (void *)va;
-
-	for (curseg = 0; curseg < nsegs; curseg++) {
-		for (addr = segs[curseg].ds_addr;
-		    addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
-		    addr += PAGE_SIZE, va += PAGE_SIZE, size -= PAGE_SIZE) {
-			if (size == 0)
-				panic("_bus_dmamem_map: size botch");
-			pmap_enter(pmap_kernel(), va, addr,
-			    VM_PROT_READ | VM_PROT_WRITE,
-			    VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED);
-
-			/* XXX Do something about COHERENT here. */
-		}
-	}
-	pmap_update(pmap_kernel());
-
-	return 0;
+	/* XXX BUS_DMA_COHERENT */
+	return (_bus_dmamem_map_common(t, segs, nsegs, size, kvap, flags, 0));
 }
 
 /*
@@ -681,11 +592,6 @@
 _bus_dmamem_unmap(bus_dma_tag_t t, void *kva, size_t size)
 {
 
-#ifdef DIAGNOSTIC
-	if ((u_long)kva & PGOFSET)
-		panic("_bus_dmamem_unmap");
-#endif
-
 	/*
 	 * Nothing to do if we mapped it with KSEG0 or KSEG1 (i.e.
 	 * not in KSEG2).
@@ -694,10 +600,7 @@
 	    kva < (void *)MIPS_KSEG2_START)
 		return;
 
-	size = round_page(size);
-	pmap_remove(pmap_kernel(), (vaddr_t)kva, (vaddr_t)kva + size);
-	pmap_update(pmap_kernel());
-	uvm_km_free(kernel_map, (vaddr_t)kva, size, UVM_KMF_VAONLY);
+	_bus_dmamem_unmap_common(t, kva, size);
 }
 
 /*
@@ -708,26 +611,11 @@
 _bus_dmamem_mmap(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
     off_t off, int prot, int flags)
 {
-	int i;
+	bus_addr_t rv;
 
-	for (i = 0; i < nsegs; i++) {
-#ifdef DIAGNOSTIC
-		if (off & PGOFSET)
-			panic("_bus_dmamem_mmap: offset unaligned");
-		if (segs[i].ds_addr & PGOFSET)
-			panic("_bus_dmamem_mmap: segment unaligned");
-		if (segs[i].ds_len & PGOFSET)
-			panic("_bus_dmamem_mmap: segment size not multiple"
-			    " of page size");
-#endif
-		if (off >= segs[i].ds_len) {
-			off -= segs[i].ds_len;
-			continue;
-		}
-
-		return mips_btop((char *)segs[i].ds_addr + off);
-	}
-
-	/* Page not found. */
-	return -1;
+	rv = _bus_dmamem_mmap_common(t, segs, nsegs, off, prot, flags);
+	if (rv == (bus_addr_t)-1)
+		return (-1);
+	
+	return (mips_btop((char *)rv));
 }
--- a/sys/arch/hp300/include/vmparam.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/hp300/include/vmparam.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmparam.h,v 1.32.78.1 2009/05/04 08:11:05 yamt Exp $	*/
+/*	$NetBSD: vmparam.h,v 1.32.78.2 2009/09/16 13:37:38 yamt Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -182,8 +182,7 @@
  * pmap-specific data stored in the vm_physmem[] array.
  */
 struct pmap_physseg {
-	struct pv_entry *pvent;		/* pv table for this seg */
-	char *attrs;			/* page attributes for this seg */
+	struct pv_header *pvheader;	/* pv table for this seg */
 };
 
 #endif /* _HP300_VMPARAM_H_ */
--- a/sys/arch/hpcmips/conf/files.hpcmips	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/hpcmips/conf/files.hpcmips	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.hpcmips,v 1.102 2008/02/20 21:43:34 drochner Exp $
+#	$NetBSD: files.hpcmips,v 1.102.10.1 2009/09/16 13:37:38 yamt Exp $
 
 # maxpartitions must be first item in files.${ARCH}.
 maxpartitions 8
@@ -60,6 +60,8 @@
 file	arch/hpcmips/hpcmips/machdep.c
 file	arch/hpcmips/hpcmips/mainbus.c
 
+file	common/bus_dma/bus_dmamem_common.c
+
 file	dev/kloader.c				kloader
 file	arch/hpcmips/hpcmips/kloader_machdep.c	kloader
 file	arch/hpcmips/hpcmips/kloader_vr41.S	vr41xx & kloader
--- a/sys/arch/hpcmips/hpcmips/bus_dma.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/hpcmips/hpcmips/bus_dma.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus_dma.c,v 1.30.44.2 2009/05/04 08:11:11 yamt Exp $	*/
+/*	$NetBSD: bus_dma.c,v 1.30.44.3 2009/09/16 13:37:38 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.30.44.2 2009/05/04 08:11:11 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.30.44.3 2009/09/16 13:37:38 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -44,6 +44,8 @@
 #include <machine/bus.h>
 #include <machine/bus_dma_hpcmips.h>
 
+#include <common/bus_dma/bus_dmamem_common.h>
+
 static int _hpcmips_bd_map_load_buffer(bus_dmamap_t, void *, bus_size_t,
     struct vmspace *, int, vaddr_t *, int *, int);
 
@@ -531,59 +533,16 @@
     bus_dma_segment_t *segs, int nsegs, int *rsegs,
     int flags, paddr_t low, paddr_t high)
 {
-	vaddr_t curaddr, lastaddr;
-	struct vm_page *m;
-	struct pglist mlist;
-	int curseg, error;
 #ifdef DIAGNOSTIC
 	extern paddr_t avail_start, avail_end;		/* XXX */
 
 	high = high<(avail_end - PAGE_SIZE)? high: (avail_end - PAGE_SIZE);
 	low = low>avail_start? low: avail_start;
 #endif
-	/* Always round the size. */
-	size = round_page(size);
 
-	/*
-	 * Allocate pages from the VM system.
-	 */
-	error = uvm_pglistalloc(size, low, high, alignment, boundary,
-	    &mlist, nsegs, (flags & BUS_DMA_NOWAIT) == 0);
-	if (error)
-		return (error);
-
-	/*
-	 * Compute the location, size, and number of segments actually
-	 * returned by the VM code.
-	 */
-	m = mlist.tqh_first;
-	curseg = 0;
-	lastaddr = segs[curseg].ds_addr = VM_PAGE_TO_PHYS(m);
-	segs[curseg].ds_len = PAGE_SIZE;
-	m = m->pageq.queue.tqe_next;
-
-	for (; m != NULL; m = m->pageq.queue.tqe_next) {
-		curaddr = VM_PAGE_TO_PHYS(m);
-#ifdef DIAGNOSTIC
-		if (curaddr < low || curaddr >= high) {
-			printf("uvm_pglistalloc returned non-sensical"
-			    " address 0x%lx\n", curaddr);
-			panic("_hpcmips_bd_mem_alloc");
-		}
-#endif
-		if (curaddr == (lastaddr + PAGE_SIZE))
-			segs[curseg].ds_len += PAGE_SIZE;
-		else {
-			curseg++;
-			segs[curseg].ds_addr = curaddr;
-			segs[curseg].ds_len = PAGE_SIZE;
-		}
-		lastaddr = curaddr;
-	}
-
-	*rsegs = curseg + 1;
-
-	return (0);
+	return (_bus_dmamem_alloc_range_common(t, size, alignment, boundary,
+					       segs, nsegs, rsegs, flags,
+					       low, high));
 }
 
 /*
@@ -593,25 +552,8 @@
 void
 _hpcmips_bd_mem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs)
 {
-	struct vm_page *m;
-	bus_addr_t addr;
-	struct pglist mlist;
-	int curseg;
 
-	/*
-	 * Build a list of pages to free back to the VM system.
-	 */
-	TAILQ_INIT(&mlist);
-	for (curseg = 0; curseg < nsegs; curseg++) {
-		for (addr = segs[curseg].ds_addr;
-		    addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
-		    addr += PAGE_SIZE) {
-			m = PHYS_TO_VM_PAGE(addr);
-			TAILQ_INSERT_TAIL(&mlist, m, pageq.queue);
-		}
-	}
-
-	uvm_pglistfree(&mlist);
+	_bus_dmamem_free_common(t, segs, nsegs);
 }
 
 /*
@@ -622,11 +564,6 @@
 _hpcmips_bd_mem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
     size_t size, void **kvap, int flags)
 {
-	vaddr_t va;
-	bus_addr_t addr;
-	int curseg;
-	const uvm_flag_t kmflags =
-	    (flags & BUS_DMA_NOWAIT) != 0 ? UVM_KMF_NOWAIT : 0;
 
 	/*
 	 * If we're only mapping 1 segment, use KSEG0 or KSEG1, to avoid
@@ -640,31 +577,8 @@
 		return (0);
 	}
 
-	size = round_page(size);
-
-	va = uvm_km_alloc(kernel_map, size, 0, UVM_KMF_VAONLY | kmflags);
-
-	if (va == 0)
-		return (ENOMEM);
-
-	*kvap = (void *)va;
-
-	for (curseg = 0; curseg < nsegs; curseg++) {
-		for (addr = segs[curseg].ds_addr;
-		    addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
-		    addr += PAGE_SIZE, va += PAGE_SIZE, size -= PAGE_SIZE) {
-			if (size == 0)
-				panic("_hpcmips_bd_mem_map: size botch");
-			pmap_enter(pmap_kernel(), va, addr,
-			    VM_PROT_READ | VM_PROT_WRITE,
-			    VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED);
-
-			/* XXX Do something about COHERENT here. */
-		}
-	}
-	pmap_update(pmap_kernel());
-
-	return (0);
+	/* XXX BUS_DMA_COHERENT */
+	return (_bus_dmamem_map_common(t, segs, nsegs, size, kvap, flags, 0));
 }
 
 /*
@@ -675,11 +589,6 @@
 _hpcmips_bd_mem_unmap(bus_dma_tag_t t, void *kva, size_t size)
 {
 
-#ifdef DIAGNOSTIC
-	if ((u_long)kva & PGOFSET)
-		panic("_hpcmips_bd_mem_unmap");
-#endif
-
 	/*
 	 * Nothing to do if we mapped it with KSEG0 or KSEG1 (i.e.
 	 * not in KSEG2).
@@ -688,10 +597,7 @@
 	    kva < (void *)MIPS_KSEG2_START)
 		return;
 
-	size = round_page(size);
-	pmap_remove(pmap_kernel(), (vaddr_t)kva, (vaddr_t)kva + size);
-	pmap_update(pmap_kernel());
-	uvm_km_free(kernel_map, (vaddr_t)kva, size, UVM_KMF_VAONLY);
+	_bus_dmamem_unmap_common(t, kva, size);
 }
 
 /*
@@ -702,26 +608,11 @@
 _hpcmips_bd_mem_mmap(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
     off_t off, int prot, int flags)
 {
-	int i;
+	bus_addr_t rv;
 
-	for (i = 0; i < nsegs; i++) {
-#ifdef DIAGNOSTIC
-		if (off & PGOFSET)
-			panic("_hpcmips_bd_mem_mmap: offset unaligned");
-		if (segs[i].ds_addr & PGOFSET)
-			panic("_hpcmips_bd_mem_mmap: segment unaligned");
-		if (segs[i].ds_len & PGOFSET)
-			panic("_hpcmips_bd_mem_mmap: segment size not multiple"
-			    " of page size");
-#endif
-		if (off >= segs[i].ds_len) {
-			off -= segs[i].ds_len;
-			continue;
-		}
-
-		return (mips_btop((char *)segs[i].ds_addr + off));
-	}
-
-	/* Page not found. */
-	return (-1);
+	rv = _bus_dmamem_mmap_common(t, segs, nsegs, off, prot, flags);
+	if (rv == (bus_addr_t)-1)
+		return (-1);
+	
+	return (mips_btop((char *)rv));
 }
--- a/sys/arch/hpcmips/vr/vrecu.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/hpcmips/vr/vrecu.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vrecu.c,v 1.6.78.1 2008/05/16 02:22:30 yamt Exp $ */
+/* $NetBSD: vrecu.c,v 1.6.78.2 2009/09/16 13:37:38 yamt Exp $ */
 
 /*
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vrecu.c,v 1.6.78.1 2008/05/16 02:22:30 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vrecu.c,v 1.6.78.2 2009/09/16 13:37:38 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -65,8 +65,8 @@
 
 struct pcic_vrip_softc {
 	struct pcic_softc	sc_pcic;	/* real pcic softc */
-	u_int16_t		sc_intr_mask;
-	u_int16_t		sc_intr_valid;
+	uint16_t		sc_intr_mask;
+	uint16_t		sc_intr_valid;
 	struct intrhand {
 		int	(*ih_fun)(void *);
 		void	*ih_arg;
@@ -105,8 +105,8 @@
 static void
 pcic_vrip_attach(struct device *parent, struct device *self, void *aux)
 {
-	struct pcic_softc	*sc = (void *) self;
-	struct pcic_vrip_softc	*vsc = (void *) self;
+	struct pcic_vrip_softc	*vsc = device_private(self);
+	struct pcic_softc	*sc = &vsc->sc_pcic;
 	struct vrip_attach_args	*va = aux;
 	bus_space_handle_t	ioh;
 	bus_space_handle_t	memh;
@@ -118,9 +118,9 @@
 		vsc->sc_intrhand[i].ih_fun = NULL;
 
 	if ((sc->ih = vrip_intr_establish(va->va_vc, va->va_unit, 0,
-					  IPL_NET, pcic_vrip_intr, sc))
+					  IPL_NET, pcic_vrip_intr, vsc))
 	    == NULL) {
-		printf("%s: can't establish interrupt", sc->dev.dv_xname);
+		printf(": can't establish interrupt");
 	}
 
         /* Map i/o space. */
@@ -203,8 +203,8 @@
 
 
 	h = (struct pcic_handle *) pch;
-	sc = (struct pcic_softc *) h->ph_parent;
-	vsc = (struct pcic_vrip_softc *) h->ph_parent;
+	vsc = device_private(h->ph_parent);
+	sc = &vsc->sc_pcic;
 
 
 	ih = &vsc->sc_intrhand[irq];
@@ -239,8 +239,8 @@
 	int	r;
 
 	h = (struct pcic_handle *) pch;
-	sc = (struct pcic_softc *) h->ph_parent;
-	vsc = (struct pcic_vrip_softc *) h->ph_parent;
+	vsc = device_private(h->ph_parent);
+	sc = &vsc->sc_pcic;
 
 	if (ih != &vsc->sc_intrhand[h->ih_irq])
 		panic("pcic_vrip_chip_intr_disestablish: bad handler");
@@ -270,10 +270,10 @@
 static int
 pcic_vrip_intr(void *arg)
 {
-	struct pcic_softc	*sc = arg;
 	struct pcic_vrip_softc	*vsc = arg;
+	struct pcic_softc	*sc = &vsc->sc_pcic;
 	int			i;
-	u_int16_t		r;
+	uint16_t		r;
 
 	r = bus_space_read_2(sc->iot, sc->ioh, ECU_INTSTAT_REG_W)
 		& ~vsc->sc_intr_mask;
--- a/sys/arch/i386/Makefile	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/i386/Makefile	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.33.10.2 2009/06/20 07:20:05 yamt Exp $
+#	$NetBSD: Makefile,v 1.33.10.3 2009/09/16 13:37:38 yamt Exp $
 
 # Makefile for i386 tags file and boot blocks
 
@@ -13,8 +13,7 @@
 	${SYSDIR}/arch/i386/pnpbios/*.[ch] \
 	${SYSDIR}/external/isc/atheros_hal/dist/*.[ch] \
 	${SYSDIR}/external/isc/atheros_hal/dist/*/*.[ch] \
-	${SYSDIR}/external/isc/atheros_hal/ic/*.[ch] \
-	${SYSDIR}/dist/acpica/*.[ch]
+	${SYSDIR}/external/isc/atheros_hal/ic/*.[ch]
 SI386+=	${SYSDIR}/arch/x86/x86/*.[ch] \
 	${SYSDIR}/arch/x86/acpi/*.[ch] \
 	${SYSDIR}/arch/x86/include/*.h \
@@ -30,6 +29,8 @@
 tags:
 	-rm -f ${TI386}
 	-echo ${SI386} | xargs ctags -wadtf ${TI386}
+	-find -H ${SYSDIR}/external/intel-public/acpica/dist/ -name '*.[ch]' | \
+	    sort -t / -u | xargs ctags -wadtf ${TI386}
 	-${FINDCOMM} | xargs ctags -wadtf ${TI386}
 	egrep "^ENTRY(.*)|^ALTENTRY(.*)" ${AI386} | \
 	    ${TOOL_SED} -e \
--- a/sys/arch/i386/acpi/acpi_wakecode.S	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/i386/acpi/acpi_wakecode.S	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_wakecode.S,v 1.11.10.1 2008/05/16 02:22:32 yamt Exp $	*/
+/*	$NetBSD: acpi_wakecode.S,v 1.11.10.2 2009/09/16 13:37:39 yamt Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -111,6 +111,18 @@
 	movw	%cs,%ax
 	movw	%ax,%ds
 	movw	%ax,%ss
+
+	/* If we need to restore a VESA VBE mode, do it now */
+	cmpb	$0,WAKEUP_vesa_modenum
+	je	1f
+	movw	WAKEUP_vesa_modenum,%bx
+	orw	$0x4000,%bx
+	movw	$0x4f02,%ax
+	int	$0x10
+
+	movw	%cs,%ax
+	movw	%ax,%ds
+	movw	%ax,%ss
 1:
 
 	/* Disable beep again if machdep.acpi_beep_on_reset=1 */
@@ -199,5 +211,7 @@
 
 	.global WAKEUP_vbios_reset
 WAKEUP_vbios_reset:	.byte 0
+	.global WAKEUP_vesa_modenum
+WAKEUP_vesa_modenum:	.word 0
 	.global WAKEUP_beep_on_reset
 WAKEUP_beep_on_reset:	.byte 0
--- a/sys/arch/i386/conf/ALL	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/i386/conf/ALL	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.167.2.4 2009/08/19 18:46:18 yamt Exp $
+# $NetBSD: ALL,v 1.167.2.5 2009/09/16 13:37:39 yamt Exp $
 # From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
 #
 # ALL machine description file
@@ -17,7 +17,7 @@
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		"ALL-$Revision: 1.167.2.4 $"
+#ident 		"ALL-$Revision: 1.167.2.5 $"
 
 maxusers	32		# estimated number of users
 
@@ -114,8 +114,8 @@
 options 	DDB_VERBOSE_HELP
 options 	KGDB		# remote debugger
 options 	KGDB_DEVNAME="\"com\"",KGDB_DEVADDR=0x3f8,KGDB_DEVRATE=9600
-#options 	IPKDB		# IP Kernel Debugger
-#options 	IPKDBKEY="\"yes\""
+options 	IPKDB		# IP Kernel Debugger
+options 	IPKDBKEY="\"Pass_phrase_to_debug_over_network\""
 makeoptions 	DEBUG="-g"	# compile full symbol table
 options 	SYSCALL_STATS	# per syscall counts
 options 	SYSCALL_TIMES 	# per syscall times
@@ -180,6 +180,7 @@
 file-system 	EFS		# Silicon Graphics Extent File System
 file-system 	FILECORE	# Acorn filecore file system
 file-system 	ADOSFS		# AmigaDOS file system
+file-system	NILFS		# experimental - NTT's NiLFS(2)
 
 # File system options
 options 	QUOTA		# UFS quotas
@@ -612,6 +613,17 @@
 lpt1	at isa? port 0x278
 lpt2	at isa? port 0x3bc
 
+# ISA IEEE488 GPIB interfaces
+cec0	at isa? port 0x2b8 irq 5 drq 1
+gpib*	at cec?
+
+# IEEE488 GPIB support
+ppi*	at gpib?
+cs80bus* at gpib?
+ct*	at cs80bus? slave ? punit ?
+mt*	at cs80bus? slave ? punit ?
+rd*	at cs80bus? slave ? punit ?
+
 # Hardware monitors
 
 amdtemp* at pci? dev ? function ?	# AMD CPU Temperature sensors
@@ -1317,6 +1329,10 @@
 opl*	at yds?
 opl*	at ym?
 
+# High Definition Audio
+hdaudio*	at pci? dev ? function ?	# High Definition Audio
+hdafg*		at hdaudiobus?
+
 # Audio support
 audio*	at audiobus?
 
@@ -1819,6 +1835,8 @@
 options HD64461PCMCIA_DEBUG
 options HD64461VIDEO_DEBUG
 options HD64465PCMCIA_DEBUG
+options HDAUDIO_DEBUG
+options HDAUDIO_AFG_DEBUG
 options HDLCDEBUG
 options HIFN_DEBUG
 options HMEDEBUG
@@ -1994,6 +2012,7 @@
 options RPC_DEBUG
 options RQDEBUG
 options RTC_DEBUG
+options RTSOCK_DEBUG
 options RTW_DEBUG
 options SACKBCDEBUG
 options SBC_DEBUG
--- a/sys/arch/i386/conf/GENERIC	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/i386/conf/GENERIC	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.890.2.3 2009/08/19 18:46:18 yamt Exp $
+# $NetBSD: GENERIC,v 1.890.2.4 2009/09/16 13:37:39 yamt Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		"GENERIC-$Revision: 1.890.2.3 $"
+#ident 		"GENERIC-$Revision: 1.890.2.4 $"
 
 maxusers	64		# estimated number of users
 
@@ -1314,6 +1314,10 @@
 opl*	at yds?
 opl*	at ym?
 
+# High Definition Audio
+hdaudio*	at pci? dev ? function ?	# High Definition Audio
+hdafg*		at hdaudiobus?
+
 # Audio support
 audio*	at audiobus?
 
--- a/sys/arch/i386/conf/XEN3_DOM0	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/i386/conf/XEN3_DOM0	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: XEN3_DOM0,v 1.8.10.3 2009/08/19 18:46:19 yamt Exp $
+#	$NetBSD: XEN3_DOM0,v 1.8.10.4 2009/09/16 13:37:39 yamt Exp $
 #
 #	XEN3_0: Xen 3.0 domain0 kernel
 
@@ -669,6 +669,10 @@
 opl*	at sv?
 opl*	at yds?
 
+# High Definition Audio
+hdaudio*	at pci? dev ? function ?	# High Definition Audio
+hdafg*		at hdaudiobus?
+
 # Audio support
 audio*	at audiobus?
 
--- a/sys/arch/i386/i386/db_trace.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/i386/i386/db_trace.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_trace.c,v 1.58.20.2 2009/05/04 08:11:16 yamt Exp $	*/
+/*	$NetBSD: db_trace.c,v 1.58.20.3 2009/09/16 13:37:39 yamt Exp $	*/
 
 /* 
  * Mach Operating System
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.58.20.2 2009/05/04 08:11:16 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.58.20.3 2009/09/16 13:37:39 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -501,7 +501,7 @@
 		sym = db_frame_info(frame, callpc, &name, &offset, &is_trap,
 				    &narg);
 
-		if (lastframe == 0 && sym == (db_sym_t)0) {
+		if (lastframe == 0 && sym == (db_sym_t)0 && callpc != 0) {
 			/* Symbol not found, peek at code */
 			int	instr = db_get_value(callpc, 4, false);
 
--- a/sys/arch/i386/i386/ipkdb_glue.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/i386/i386/ipkdb_glue.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipkdb_glue.c,v 1.8.78.1 2009/05/04 08:11:16 yamt Exp $	*/
+/*	$NetBSD: ipkdb_glue.c,v 1.8.78.2 2009/09/16 13:37:39 yamt Exp $	*/
 
 /*
  * Copyright (C) 2000 Wolfgang Solfrank.
@@ -31,7 +31,7 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ipkdb_glue.c,v 1.8.78.1 2009/05/04 08:11:16 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipkdb_glue.c,v 1.8.78.2 2009/09/16 13:37:39 yamt Exp $");
 
 #include "opt_ipkdb.h"
 
@@ -42,6 +42,7 @@
 
 #include <machine/ipkdb.h>
 #include <machine/psl.h>
+#include <machine/cpufunc.h>
 
 int ipkdbregs[NREG];
 
@@ -72,7 +73,7 @@
 ipkdb_trap(void)
 {
 	ipkdb_mode = IPKDB_CMD_STEP;
-	x86_write_eflags(x86_read_eflags() | PSL_T);
+	x86_write_flags(x86_read_flags() | PSL_T);
 }
 
 int
--- a/sys/arch/i386/i386/powernow_k7.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/i386/i386/powernow_k7.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: powernow_k7.c,v 1.29.4.2 2009/05/04 08:11:16 yamt Exp $ */
+/*	$NetBSD: powernow_k7.c,v 1.29.4.3 2009/09/16 13:37:39 yamt Exp $ */
 /*	$OpenBSD: powernow-k7.c,v 1.24 2006/06/16 05:58:50 gwk Exp $ */
 
 /*-
@@ -59,7 +59,7 @@
 /* AMD POWERNOW K7 driver */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: powernow_k7.c,v 1.29.4.2 2009/05/04 08:11:16 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: powernow_k7.c,v 1.29.4.3 2009/09/16 13:37:39 yamt Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -468,7 +468,7 @@
 
 	aprint_normal("%s: AMD %s Technology %d MHz\n",
 	    cpuname, techname, cur_freq);
-	aprint_normal("%s: frequencies available (Mhz): %s\n",
+	aprint_normal("%s: frequencies available (MHz): %s\n",
 	    cpuname, freq_names);
 
 	return;
--- a/sys/arch/i386/stand/boot/boot2.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/i386/stand/boot/boot2.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot2.c,v 1.22.6.2 2009/05/04 08:11:18 yamt Exp $	*/
+/*	$NetBSD: boot2.c,v 1.22.6.3 2009/09/16 13:37:39 yamt Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -420,7 +420,8 @@
 	const char *file; /* dummy */
 
 	if (*arg == '\0') {
-		printf("%s%d%c:\n", default_devname, default_unit,
+		biosdisk_probe();
+		printf("default %s%d%c\n", default_devname, default_unit,
 		       'a' + default_partition);
 		return;
 	}
--- a/sys/arch/i386/stand/boot/version	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/i386/stand/boot/version	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.5.78.2 2009/05/04 08:11:18 yamt Exp $
+$NetBSD: version,v 1.5.78.3 2009/09/16 13:37:39 yamt Exp $
 
 NOTE ANY CHANGES YOU MAKE TO THE BOOTBLOCKS HERE.  The format of this
 file is important - make sure the entries are appended on end, last item
@@ -40,3 +40,5 @@
 5.1:	Change boot messages to replace build date with kernel version.
 5.2:	Support for multiboot.
 5.3:	Autoload kernel module for root file system.
+5.4:	The VESA VBE mode number is now passed to the kernel so it can be
+	restored on ACPI resume.
--- a/sys/arch/i386/stand/lib/biosdisk.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/i386/stand/lib/biosdisk.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: biosdisk.c,v 1.28 2008/01/05 15:28:43 dsl Exp $	*/
+/*	$NetBSD: biosdisk.c,v 1.28.10.1 2009/09/16 13:37:39 yamt Exp $	*/
 
 /*
  * Copyright (c) 1996, 1998
@@ -63,16 +63,21 @@
  * the rights to redistribute these changes.
  */
 
+#ifndef NO_DISKLABEL
+#define FSTYPENAMES
+#endif
+
 #include <sys/types.h>
-#include <sys/disklabel.h>
 #include <sys/md5.h>
 #include <sys/param.h>
+#include <sys/disklabel.h>
 
 #include <fs/cd9660/iso.h>
 
 #include <lib/libsa/stand.h>
 #include <lib/libsa/saerrno.h>
 #include <machine/stdarg.h>
+#include <machine/cpu.h>
 
 #include "libi386.h"
 #include "biosdisk_ll.h"
@@ -292,6 +297,79 @@
 }
 #endif /* NO_DISKLABEL */
 
+void
+biosdisk_probe(void)
+{
+#ifndef NO_DISKLABEL
+	struct disklabel *lp;
+	int first, part;
+#endif
+	struct biosdisk d;
+	struct biosdisk_extinfo ed;
+	uint64_t size;
+	int i;
+
+	for (i = 0; i < MAX_BIOSDISKS + 2; i++) {
+		first = 1;
+		memset(&d, 0, sizeof(d));
+		memset(&ed, 0, sizeof(ed));
+		if (i >= MAX_BIOSDISKS)
+			d.ll.dev = 0x00 + i - MAX_BIOSDISKS;	/* fd */
+		else
+			d.ll.dev = 0x80 + i;			/* hd/cd */
+		if (set_geometry(&d.ll, &ed))
+			continue;
+		switch (d.ll.type) {
+		case BIOSDISK_TYPE_CD:
+			printf("disk cd0\n");
+			printf("  cd0a(unknown)\n");
+			break;
+		case BIOSDISK_TYPE_FD:
+			printf("disk fd%d\n", d.ll.dev & 0x7f);
+			printf("  fd%da(unknown)\n", d.ll.dev & 0x7f);
+			break;
+		case BIOSDISK_TYPE_HD:
+			printf("disk hd%d", d.ll.dev & 0x7f);
+			if (d.ll.flags & BIOSDISK_INT13EXT) {
+				printf(" size ");
+				size = ed.totsec * ed.sbytes;
+				if (size >= (10ULL * 1024 * 1024 * 1024))
+					printf("%llu GB",
+					    size / (1024 * 1024 * 1024));
+				else
+					printf("%llu MB",
+					    size / (1024 * 1024));
+			}
+			printf("\n");
+			break;
+		}
+#ifndef NO_DISKLABEL
+		if (read_label(&d) == -1)
+			break;
+		lp = (struct disklabel *)(d.buf + LABELOFFSET);
+		for (part = 0; part < lp->d_npartitions; part++) {
+			if (lp->d_partitions[part].p_size == 0)
+				continue;
+			if (lp->d_partitions[part].p_fstype == FS_UNUSED)
+				continue;
+			if (first) {
+				printf(" ");
+				first = 0;
+			}
+			printf(" hd%d%c(", d.ll.dev & 0x7f, part + 'a');
+			if (lp->d_partitions[part].p_fstype < FSMAXTYPES)
+				printf("%s",
+				  fstypenames[lp->d_partitions[part].p_fstype]);
+			else
+				printf("%d", lp->d_partitions[part].p_fstype);
+			printf(")");
+		}
+		if (first == 0)
+			printf("\n");
+#endif
+	}
+}
+
 /* Determine likely partition for possible sector number of dos
  * partition.
  */
--- a/sys/arch/i386/stand/lib/bootmenu.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/i386/stand/lib/bootmenu.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bootmenu.c,v 1.6.2.2 2009/05/04 08:11:19 yamt Exp $	*/
+/*	$NetBSD: bootmenu.c,v 1.6.2.3 2009/09/16 13:37:39 yamt Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -261,11 +261,15 @@
 static int
 getchoicefrominput(char *input, int def)
 {
-	int choice;
+	int choice, usedef;
+
 	choice = -1;
-	if (*input == '\0' || *input == '\r' || *input == '\n')
+	usedef = 0;
+
+	if (*input == '\0' || *input == '\r' || *input == '\n') {
 		choice = def;
-	else if (*input >= 'A' && *input < bootconf.nummenu + 'A')
+		usedef = 1;
+	} else if (*input >= 'A' && *input < bootconf.nummenu + 'A')
 		choice = (*input) - 'A';
 	else if (*input >= 'a' && *input < bootconf.nummenu + 'a')
 		choice = (*input) - 'a';
@@ -274,6 +278,11 @@
 		if (choice < 0 || choice >= bootconf.nummenu)
 			choice = -1;
 	}
+
+	if (bootconf.menuformat != MENUFORMAT_LETTER &&
+	    !isnum(*input) && !usedef)
+		choice = -1;
+
 	return choice;
 }
 
--- a/sys/arch/i386/stand/lib/exec.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/i386/stand/lib/exec.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: exec.c,v 1.22.78.2 2009/05/04 08:11:19 yamt Exp $	 */
+/*	$NetBSD: exec.c,v 1.22.78.3 2009/09/16 13:37:39 yamt Exp $	 */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -114,6 +114,7 @@
 #include "libi386.h"
 #include "bootinfo.h"
 #include "bootmod.h"
+#include "vbe.h"
 #ifdef SUPPORT_PS2
 #include "biosmca.h"
 #endif
@@ -124,6 +125,8 @@
 #define	PAGE_SIZE	4096
 #endif
 
+#define MODULE_WARNING_DELAY	5000000
+
 extern struct btinfo_console btinfo_console;
 
 boot_module_t *boot_modules;
@@ -138,7 +141,7 @@
 static char module_base[64] = "/";
 static int howto;
 
-static void	module_init(void);
+static void	module_init(const char *);
 
 void
 framebuffer_configure(struct btinfo_framebuffer *fb)
@@ -287,8 +290,6 @@
 	BI_ALLOC(32); /* ??? */
 
 	BI_ADD(&btinfo_console, BTINFO_CONSOLE, sizeof(struct btinfo_console));
-	BI_ADD(&btinfo_framebuffer, BTINFO_FRAMEBUFFER,
-	    sizeof(struct btinfo_framebuffer));
 
 	howto = boothowto;
 
@@ -304,7 +305,7 @@
 
 	/* pull in any modules if necessary */
 	if (boot_modules_enabled) {
-		module_init();
+		module_init(file);
 		if (btinfo_modulelist) {
 			BI_ADD(btinfo_modulelist, BTINFO_MODULELIST,
 			    btinfo_modulelist_size);
@@ -321,6 +322,11 @@
 	btinfo_symtab.esym = marks[MARK_END];
 	BI_ADD(&btinfo_symtab, BTINFO_SYMTAB, sizeof(struct btinfo_symtab));
 
+	/* set new video mode if necessary */
+	vbe_commit();
+	BI_ADD(&btinfo_framebuffer, BTINFO_FRAMEBUFFER,
+	    sizeof(struct btinfo_framebuffer));
+
 	if (callback != NULL)
 		(*callback)();
 	startprog(marks[MARK_ENTRY], BOOT_NARGS, boot_argv,
@@ -333,12 +339,26 @@
 	return -1;
 }
 
+static void
+extract_device(const char *path, char *buf, size_t buflen)
+{
+	int i;
+
+	if (strchr(path, ':') != NULL) {
+		for (i = 0; i < buflen - 2 && path[i] != ':'; i++)
+			buf[i] = path[i];
+		buf[i++] = ':';
+		buf[i] = '\0';
+	} else
+		buf[0] = '\0';
+}
+
 static const char *
-module_path(boot_module_t *bm)
+module_path(boot_module_t *bm, const char *kdev)
 {
 	static char buf[256];
-	char name_buf[256];
-	const char *name, *name2;
+	char name_buf[256], dev_buf[64];
+	const char *name, *name2, *p;
 
 	name = bm->bm_path;
 	for (name2 = name; *name2; ++name2) {
@@ -350,45 +370,69 @@
 			break;
 		}
 	}
- 	if (name[0] == '/')
-		snprintf(buf, sizeof(buf), "%s", name);
-	else
-		snprintf(buf, sizeof(buf), "%s/%s/%s.kmod",
-		    module_base, name, name);
+	if ((p = strchr(name, ':')) != NULL) {
+		/* device specified, use it */
+		if (p[1] == '/')
+			snprintf(buf, sizeof(buf), "%s", name);
+		else {
+			p++;
+			extract_device(name, dev_buf, sizeof(dev_buf));
+			snprintf(buf, sizeof(buf), "%s%s/%s/%s.kmod",
+			    dev_buf, module_base, p, p);
+		}
+	} else {
+		/* device not specified; load from kernel device if known */
+ 		if (name[0] == '/')
+			snprintf(buf, sizeof(buf), "%s%s", kdev, name);
+		else
+			snprintf(buf, sizeof(buf), "%s%s/%s/%s.kmod",
+			    kdev, module_base, name, name);
+	}
 
 	return buf;
 }
 
 static int
-module_open(boot_module_t *bm, int mode)
+module_open(boot_module_t *bm, int mode, const char *kdev, bool doload)
 {
 	int fd;
 	const char *path;
 
 	/* check the expanded path first */
-	path = module_path(bm);
+	path = module_path(bm, kdev);
 	fd = open(path, mode);
-	if (fd == -1) {
-		printf("WARNING: couldn't open %s\n", path);
+	if (fd != -1) {
+		if ((howto & AB_SILENT) == 0 && doload)
+			printf("Loading %s ", path);
+	} else {
 		/* now attempt the raw path provided */
 		fd = open(bm->bm_path, mode);
-		if (fd == -1)
-			printf("WARNING: couldn't open %s\n", bm->bm_path);
+		if (fd != -1 && (howto & AB_SILENT) == 0 && doload)
+			printf("Loading %s ", bm->bm_path);
+	}
+	if (!doload && fd == -1) {
+		printf("WARNING: couldn't open %s", bm->bm_path);
+		if (strcmp(bm->bm_path, path) != 0)
+			printf(" (%s)", path);
+		printf("\n");
 	}
 	return fd;
 }
 
 static void
-module_init(void)
+module_init(const char *kernel_path)
 {
 	struct bi_modulelist_entry *bi;
 	struct stat st;
 	const char *machine;
+	char kdev[64];
 	char *buf;
 	boot_module_t *bm;
 	size_t len;
 	off_t off;
-	int err, fd;
+	int err, fd, nfail = 0;
+
+	extract_device(kernel_path, kdev, sizeof(kdev));
 
 	switch (netbsd_elf_class) {
 	case ELFCLASS32:
@@ -419,9 +463,10 @@
 	/* First, see which modules are valid and calculate btinfo size */
 	len = sizeof(struct btinfo_modulelist);
 	for (bm = boot_modules; bm; bm = bm->bm_next) {
-		fd = module_open(bm, 0);
+		fd = module_open(bm, 0, kdev, false);
 		if (fd == -1) {
 			bm->bm_len = -1;
+			++nfail;
 			continue;
 		}
 		err = fstat(fd, &st);
@@ -429,6 +474,7 @@
 			printf("WARNING: couldn't stat %s\n", bm->bm_path);
 			close(fd);
 			bm->bm_len = -1;
+			++nfail;
 			continue;
 		}
 		bm->bm_len = st.st_size;
@@ -440,6 +486,7 @@
 	btinfo_modulelist = alloc(len);
 	if (btinfo_modulelist == NULL) {
 		printf("WARNING: couldn't allocate module list\n");
+		delay(MODULE_WARNING_DELAY);
 		return;
 	}
 	memset(btinfo_modulelist, 0, len);
@@ -453,13 +500,9 @@
 	for (bm = boot_modules; bm; bm = bm->bm_next) {
 		if (bm->bm_len == -1)
 			continue;
-		if ((howto & AB_SILENT) == 0)
-			printf("Loading %s ", bm->bm_path);
-		fd = module_open(bm, 0);
-		if (fd == -1) {
-			printf("ERROR: couldn't open %s\n", bm->bm_path);
+		fd = module_open(bm, 0, kdev, true);
+		if (fd == -1)
 			continue;
-		}
 		image_end = (image_end + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
 		len = pread(fd, (void *)image_end, SSIZE_MAX);
 		if (len < bm->bm_len) {
@@ -482,6 +525,14 @@
 		close(fd);
 	}
 	btinfo_modulelist->endpa = image_end;
+
+	if (nfail > 0) {
+		printf("WARNING: %d module%s failed to load\n",
+		    nfail, nfail == 1 ? "" : "s");
+#if notyet
+		delay(MODULE_WARNING_DELAY);
+#endif
+	}
 }
 
 int
@@ -515,7 +566,7 @@
 
 	/* pull in any modules if necessary */
 	if (boot_modules_enabled) {
-		module_init();
+		module_init(file);
 		if (btinfo_modulelist) {
 			mbm = alloc(sizeof(struct multiboot_module) *
 					   btinfo_modulelist->num);
--- a/sys/arch/i386/stand/lib/gatea20.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/i386/stand/lib/gatea20.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: gatea20.c,v 1.10.20.1 2009/05/04 08:11:19 yamt Exp $	*/
+/*	$NetBSD: gatea20.c,v 1.10.20.2 2009/09/16 13:37:39 yamt Exp $	*/
 
 /* extracted from freebsd:sys/i386/boot/biosboot/io.c */
 
@@ -67,12 +67,10 @@
 
 		outb(K_CMD, KC_CMD_WOUT);
 
-		delay(100);
 		while (inb(K_STATUS) & K_IBUF_FUL);
 
 		outb(K_RDWR, x_20);
 
-		delay(100);
 		while (inb(K_STATUS) & K_IBUF_FUL);
 
 		while (inb(K_STATUS) & K_OBUF_FUL)
--- a/sys/arch/i386/stand/lib/libi386.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/i386/stand/lib/libi386.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: libi386.h,v 1.23.78.1 2009/05/04 08:11:19 yamt Exp $	*/
+/*	$NetBSD: libi386.h,v 1.23.78.2 2009/09/16 13:37:39 yamt Exp $	*/
 
 /*
  * Copyright (c) 1996
@@ -122,6 +122,7 @@
 struct biosdisk_extinfo;
 void biosdisk_getextinfo(int, struct biosdisk_extinfo *);
 int get_harddrives(void);
+void biosdisk_probe(void);
 
 int pcibios_cfgread(unsigned int, int, int *);
 int pcibios_cfgwrite(unsigned int, int, int);
--- a/sys/arch/i386/stand/lib/pcio.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/i386/stand/lib/pcio.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: pcio.c,v 1.21.76.2 2009/07/18 14:52:54 yamt Exp $	 */
+/*	$NetBSD: pcio.c,v 1.21.76.3 2009/09/16 13:37:39 yamt Exp $	 */
 
 /*
  * Copyright (c) 1996, 1997
@@ -71,6 +71,20 @@
 
 #define POLL_FREQ 10
 
+static void
+wait(int us)
+{
+	int prev = biosgetsystime();
+	int tgt = prev + (20 * us) / 1000000;
+	int new;
+
+	while ((new = biosgetsystime()) < tgt) {
+		if (new < prev) /* XXX timer wrapped */
+			break;
+		prev = new;
+	}
+}
+
 #ifdef SUPPORT_SERIAL
 static int
 getcomaddr(int idx)
@@ -346,7 +360,7 @@
 			goto out;
 		}
 		if (i--)
-			delay(1000000 / POLL_FREQ);
+			wait(1000000 / POLL_FREQ);
 		else
 			break;
 	}
--- a/sys/arch/i386/stand/lib/vbe.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/i386/stand/lib/vbe.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vbe.c,v 1.2.4.2 2009/05/04 08:11:19 yamt Exp $ */
+/* $NetBSD: vbe.c,v 1.2.4.3 2009/09/16 13:37:39 yamt Exp $ */
 
 /*-
  * Copyright (c) 2009 Jared D. McNeill <jmcneill@invisible.ca>
@@ -42,6 +42,7 @@
 
 static struct _vbestate {
 	int		available;
+	int		modenum;
 } vbestate;
 
 static void
@@ -91,6 +92,7 @@
 
 	vbe_dump(&vbe);
 	vbestate.available = 1;
+	vbestate.modenum = 0;
 }
 
 int
@@ -166,12 +168,29 @@
 	fb.gpos = mi.GreenFieldPosition;
 	fb.bnum = mi.BlueMaskSize;
 	fb.bpos = mi.BlueFieldPosition;
+	fb.vbemode = modenum;
 
 	framebuffer_configure(&fb);
 
 	return 0;
 }
 
+int
+vbe_commit(void)
+{
+	int ret = 1;
+
+	if (vbestate.modenum > 0) {
+		ret = vbe_set_mode(vbestate.modenum);
+		if (ret) {
+			printf("WARNING: failed to set VESA VBE mode 0x%x\n",
+			    vbestate.modenum);
+			delay(5000000);
+		}
+	}
+	return ret;
+}
+
 static void *
 vbe_farptr(uint32_t farptr)
 {
@@ -329,8 +348,7 @@
 	}
 
 	if (strcmp(arg, "disabled") == 0 || strcmp(arg, "off") == 0) {
-		framebuffer_configure(NULL);
-		biosvideomode();
+		vbestate.modenum = 0;
 		return;
 	}
 
@@ -340,13 +358,15 @@
 		modenum = strtoul(arg, NULL, 0);
 	else if (strchr(arg, 'x') != NULL) {
 		modenum = vbe_find_mode(arg);
-		if (modenum == 0)
+		if (modenum == 0) {
+			printf("mode %s not supported by firmware\n", arg);
 			return;
+		}
 	} else
 		modenum = 0;
 
 	if (modenum >= 0x100) {
-		vbe_set_mode(modenum);
+		vbestate.modenum = modenum;
 		return;
 	}
 
--- a/sys/arch/i386/stand/lib/vbe.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/i386/stand/lib/vbe.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vbe.h,v 1.1.4.2 2009/05/04 08:11:19 yamt Exp $ */
+/* $NetBSD: vbe.h,v 1.1.4.3 2009/09/16 13:37:39 yamt Exp $ */
 
 /*-
  * Copyright (c) 2009 Jared D. McNeill <jmcneill@invisible.ca>
@@ -94,6 +94,7 @@
 
 /* high-level VBE helpers, from vbe.c */
 void vbe_init(void);
+int vbe_commit(void);
 int vbe_available(void);
 int vbe_set_mode(int);
 int vbe_set_palette(const uint8_t *, int);
--- a/sys/arch/i386/stand/pxeboot/main.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/i386/stand/pxeboot/main.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.12.10.2 2009/05/04 08:11:20 yamt Exp $	*/
+/*	$NetBSD: main.c,v 1.12.10.3 2009/09/16 13:37:39 yamt Exp $	*/
 
 /*
  * Copyright (c) 1996
@@ -48,6 +48,7 @@
 #include <bootmenu.h>
 #include <bootmod.h>
 #include "pxeboot.h"
+#include "vbe.h"
 
 extern struct x86_boot_params boot_params;
 
@@ -72,6 +73,7 @@
 	{ "consdev",	command_consdev },
 	{ "modules",    command_modules },
 	{ "load",	module_add },
+	{ "vesa",	command_vesa },
 	{ NULL,		NULL },
 };
 
@@ -180,6 +182,7 @@
 	       "boot [filename] [-adsqv]\n"
 	       "     (ex. \"netbsd.old -s\"\n"
 	       "consdev {pc|com[0123]|com[0123]kbd|auto}\n"
+	       "vesa {enabled|disabled|list|modenum}\n"
 	       "modules {enabled|disabled}\n"
 	       "load {path_to_module}\n"
 	       "help|?\n"
--- a/sys/arch/ia64/ia64/machdep.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/ia64/ia64/machdep.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.7.4.3 2009/08/19 18:46:21 yamt Exp $	*/
+/*	$NetBSD: machdep.c,v 1.7.4.4 2009/09/16 13:37:39 yamt Exp $	*/
 
 /*-
  * Copyright (c) 2003,2004 Marcel Moolenaar
@@ -227,7 +227,7 @@
 
 	printf("CPU: %s (", model_name);
 	if (processor_frequency) {
-		printf("%ld.%02ld-Mhz ", (processor_frequency + 4999) / Mhz,
+		printf("%ld.%02ld-MHz ", (processor_frequency + 4999) / Mhz,
 		    ((processor_frequency + 4999) / (Mhz/100)) % 100);
 	}
 	printf("%s)\n", family_name);
--- a/sys/arch/luna68k/include/vmparam.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/luna68k/include/vmparam.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmparam.h,v 1.11.78.1 2009/05/04 08:11:24 yamt Exp $	*/
+/*	$NetBSD: vmparam.h,v 1.11.78.2 2009/09/16 13:37:40 yamt Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -162,8 +162,7 @@
  * pmap-specific data stored in the vm_physmem[] array.
  */
 struct pmap_physseg {
-	struct pv_entry *pvent;		/* pv table for this seg */
-	char *attrs;			/* page attributes for this seg */
+	struct pv_header *pvheader;	/* pv table for this seg */
 };
 
 #endif /* _MACHINE_VMPARAM_H_ */
--- a/sys/arch/m68k/include/pmap_motorola.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/m68k/include/pmap_motorola.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_motorola.h,v 1.16.10.1 2009/05/04 08:11:26 yamt Exp $	*/
+/*	$NetBSD: pmap_motorola.h,v 1.16.10.2 2009/09/16 13:37:40 yamt Exp $	*/
 
 /* 
  * Copyright (c) 1991, 1993
@@ -136,12 +136,8 @@
 	vaddr_t		pv_va;		/* virtual address for mapping */
 	st_entry_t	*pv_ptste;	/* non-zero if VA maps a PT page */
 	struct pmap	*pv_ptpmap;	/* if pv_ptste, pmap for PT page */
-	int		pv_flags;	/* flags */
 };
 
-#define PV_CI		0x01	/* header: all entries are cache inhibited */
-#define PV_PTPAGE	0x02	/* header: entry maps a page table page */
-
 struct pv_page;
 
 struct pv_page_info {
@@ -171,7 +167,7 @@
 	(curproc && \
 	 (pm) != pmap_kernel() && (pm) == curproc->p_vmspace->vm_map.pmap)
 
-extern struct pv_entry	*pv_table;	/* array of entries, one per page */
+extern struct pv_header	*pv_table;	/* array of entries, one per page */
 
 #define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
 #define	pmap_wired_count(pmap)		((pmap)->pm_stats.wired_count)
--- a/sys/arch/m68k/m68k/pmap_motorola.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/m68k/m68k/pmap_motorola.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_motorola.c,v 1.36.2.3 2009/08/19 18:46:28 yamt Exp $        */
+/*	$NetBSD: pmap_motorola.c,v 1.36.2.4 2009/09/16 13:37:40 yamt Exp $        */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -117,7 +117,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap_motorola.c,v 1.36.2.3 2009/08/19 18:46:28 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_motorola.c,v 1.36.2.4 2009/09/16 13:37:40 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -249,8 +249,20 @@
 int		page_cnt;	/* number of pages managed by VM system */
 
 bool		pmap_initialized = false;	/* Has pmap_init completed? */
-struct pv_entry	*pv_table;
-char		*pmap_attributes;	/* reference and modify bits */
+
+struct pv_header {
+	struct pv_entry		pvh_first;	/* first PV entry */
+	uint16_t		pvh_attrs;	/* attributes:
+						   bits 0-7: PTE bits
+						   bits 8-15: flags */
+	uint16_t		pvh_cimappings;	/* # caller-specified CI
+						   mappings */
+};
+
+#define	PVH_CI		0x10	/* all entries are cache-inhibited */
+#define	PVH_PTPAGE	0x20	/* entry maps a page table page */
+
+struct pv_header *pv_table;
 TAILQ_HEAD(pv_page_list, pv_page) pv_page_freelist;
 int		pv_nfree;
 
@@ -272,25 +284,13 @@
 
 #define	PAGE_IS_MANAGED(pa)	(pmap_initialized && uvm_pageismanaged(pa))
 
-static inline struct pv_entry *pa_to_pvh(paddr_t pa);
-static inline char *pa_to_attribute(paddr_t pa);
-
-static inline struct pv_entry *
+static inline struct pv_header *
 pa_to_pvh(paddr_t pa)
 {
 	int bank, pg = 0;	/* XXX gcc4 -Wuninitialized */
 
 	bank = vm_physseg_find(atop((pa)), &pg);
-	return &vm_physmem[bank].pmseg.pvent[pg];
-}
-
-static inline char *
-pa_to_attribute(paddr_t pa)
-{
-	int bank, pg = 0;	/* XXX gcc4 -Wuninitialized */
-
-	bank = vm_physseg_find(atop((pa)), &pg);
-	return &vm_physmem[bank].pmseg.attrs[pg];
+	return &vm_physmem[bank].pmseg.pvheader[pg];
 }
 
 /*
@@ -349,8 +349,7 @@
 {
 	vaddr_t		addr, addr2;
 	vsize_t		s;
-	struct pv_entry	*pv;
-	char		*attr;
+	struct pv_header *pvh;
 	int		rv;
 	int		npages;
 	int		bank;
@@ -378,8 +377,7 @@
 	for (page_cnt = 0, bank = 0; bank < vm_nphysseg; bank++)
 		page_cnt += vm_physmem[bank].end - vm_physmem[bank].start;
 	s = M68K_STSIZE;					/* Segtabzero */
-	s += page_cnt * sizeof(struct pv_entry);	/* pv table */
-	s += page_cnt * sizeof(char);			/* attribute table */
+	s += page_cnt * sizeof(struct pv_header);	/* pv table */
 	s = round_page(s);
 	addr = uvm_km_alloc(kernel_map, s, 0, UVM_KMF_WIRED | UVM_KMF_ZERO);
 	if (addr == 0)
@@ -390,28 +388,23 @@
 	    (paddr_t *)(void *)&Segtabzeropa);
 	addr += M68K_STSIZE;
 
-	pv_table = (struct pv_entry *) addr;
-	addr += page_cnt * sizeof(struct pv_entry);
-
-	pmap_attributes = (char *)addr;
+	pv_table = (struct pv_header *) addr;
+	addr += page_cnt * sizeof(struct pv_header);
 
 	PMAP_DPRINTF(PDB_INIT, ("pmap_init: %lx bytes: page_cnt %x s0 %p(%p) "
-	    "tbl %p atr %p\n",
+	    "tbl %p\n",
 	    s, page_cnt, Segtabzero, Segtabzeropa,
-	    pv_table, pmap_attributes));
+	    pv_table));
 
 	/*
 	 * Now that the pv and attribute tables have been allocated,
 	 * assign them to the memory segments.
 	 */
-	pv = pv_table;
-	attr = pmap_attributes;
+	pvh = pv_table;
 	for (bank = 0; bank < vm_nphysseg; bank++) {
 		npages = vm_physmem[bank].end - vm_physmem[bank].start;
-		vm_physmem[bank].pmseg.pvent = pv;
-		vm_physmem[bank].pmseg.attrs = attr;
-		pv += npages;
-		attr += npages;
+		vm_physmem[bank].pmseg.pvheader = pvh;
+		pvh += npages;
 	}
 
 	/*
@@ -606,6 +599,7 @@
 	struct pv_page_list pv_page_collectlist;
 	struct pv_page *pvp, *npvp;
 	struct pv_entry *ph, *ppv, *pv, *npv;
+	struct pv_header *pvh;
 	int s;
 
 	TAILQ_INIT(&pv_page_collectlist);
@@ -626,7 +620,8 @@
 	if (TAILQ_FIRST(&pv_page_collectlist) == NULL)
 		return;
 
-	for (ph = &pv_table[page_cnt - 1]; ph >= &pv_table[0]; ph--) {
+	for (pvh = &pv_table[page_cnt - 1]; pvh >= &pv_table[0]; pvh--) {
+		ph = &pvh->pvh_first;
 		if (ph->pv_pmap == NULL)
 			continue;
 		s = splvm();
@@ -974,6 +969,7 @@
 pmap_page_protect(struct vm_page *pg, vm_prot_t prot)
 {
 	paddr_t pa = VM_PAGE_TO_PHYS(pg);
+	struct pv_header *pvh;
 	struct pv_entry *pv;
 	pt_entry_t *pte;
 	int s;
@@ -1000,7 +996,8 @@
 		break;
 	}
 
-	pv = pa_to_pvh(pa);
+	pvh = pa_to_pvh(pa);
+	pv = &pvh->pvh_first;
 	s = splvm();
 	while (pv->pv_pmap != NULL) {
 
@@ -1229,10 +1226,12 @@
 	 * since pmap_enter can be called at interrupt time.
 	 */
 	if (PAGE_IS_MANAGED(pa)) {
+		struct pv_header *pvh;
 		struct pv_entry *pv, *npv;
 		int s;
 
-		pv = pa_to_pvh(pa);
+		pvh = pa_to_pvh(pa);
+		pv = &pvh->pvh_first;
 		s = splvm();
 
 		PMAP_DPRINTF(PDB_ENTER,
@@ -1247,7 +1246,7 @@
 			pv->pv_next = NULL;
 			pv->pv_ptste = NULL;
 			pv->pv_ptpmap = NULL;
-			pv->pv_flags = 0;
+			pvh->pvh_attrs = 0;
 		}
 		/*
 		 * There is at least one other VA mapping this page.
@@ -1265,7 +1264,6 @@
 			npv->pv_next = pv->pv_next;
 			npv->pv_ptste = NULL;
 			npv->pv_ptpmap = NULL;
-			npv->pv_flags = 0;
 			pv->pv_next = npv;
 
 #ifdef M68K_MMU_HP
@@ -1294,7 +1292,7 @@
 			 */
 
 			if (pmap_aliasmask) {
-				if (pv->pv_flags & PV_CI) {
+				if (pvh->pvh_attrs & PVH_CI) {
 					PMAP_DPRINTF(PDB_CACHE,
 					    ("enter: pa %lx already CI'ed\n",
 					    pa));
@@ -1309,7 +1307,7 @@
 					    ("enter: pa %lx CI'ing all\n",
 					    pa));
 					cacheable = false;
-					pv->pv_flags |= PV_CI;
+					pvh->pvh_attrs |= PVH_CI;
 				}
 			}
 #endif
@@ -1324,9 +1322,9 @@
 			panic("pmap_enter: access_type exceeds prot");
 #endif
 		if (flags & VM_PROT_WRITE)
-			*pa_to_attribute(pa) |= (PG_U|PG_M);
+			pvh->pvh_attrs |= (PG_U|PG_M);
 		else if (flags & VM_PROT_ALL)
-			*pa_to_attribute(pa) |= PG_U;
+			pvh->pvh_attrs |= PG_U;
 
 		splx(s);
 	}
@@ -1725,6 +1723,7 @@
 pmap_collect1(pmap_t pmap, paddr_t startpa, paddr_t endpa)
 {
 	paddr_t pa;
+	struct pv_header *pvh;
 	struct pv_entry *pv;
 	pt_entry_t *pte;
 	paddr_t kpa;
@@ -1741,8 +1740,10 @@
 		 * page table pages.
 		 */
 
-		pv = pa_to_pvh(pa);
-		if (pv->pv_pmap != pmap_kernel() || !(pv->pv_flags & PV_PTPAGE))
+		pvh = pa_to_pvh(pa);
+		pv = &pvh->pvh_first;
+		if (pv->pv_pmap != pmap_kernel() ||
+		    !(pvh->pvh_attrs & PVH_PTPAGE))
 			continue;
 		do {
 			if (pv->pv_ptste && pv->pv_ptpmap == pmap_kernel())
@@ -2065,6 +2066,7 @@
 pmap_remove_mapping(pmap_t pmap, vaddr_t va, pt_entry_t *pte, int flags)
 {
 	paddr_t pa;
+	struct pv_header *pvh;
 	struct pv_entry *pv, *npv;
 	struct pmap *ptpmap;
 	st_entry_t *ste;
@@ -2162,6 +2164,7 @@
 
 		if (refs == 0 && (flags & PRM_KEEPPTPAGE) == 0) {
 #ifdef DIAGNOSTIC
+			struct pv_header *ptppvh;
 			struct pv_entry *ptppv;
 #endif
 			paddr_t ptppa;
@@ -2170,7 +2173,8 @@
 #ifdef DIAGNOSTIC
 			if (PAGE_IS_MANAGED(ptppa) == 0)
 				panic("pmap_remove_mapping: unmanaged PT page");
-			ptppv = pa_to_pvh(ptppa);
+			ptppvh = pa_to_pvh(ptppa);
+			ptppv = &ptppvh->pvh_first;
 			if (ptppv->pv_ptste == NULL)
 				panic("pmap_remove_mapping: ptste == NULL");
 			if (ptppv->pv_pmap != pmap_kernel() ||
@@ -2204,7 +2208,8 @@
 	 * (raise IPL since we may be called at interrupt time).
 	 */
 
-	pv = pa_to_pvh(pa);
+	pvh = pa_to_pvh(pa);
+	pv = &pvh->pvh_first;
 	ste = NULL;
 	s = splvm();
 
@@ -2220,7 +2225,6 @@
 		ptpmap = pv->pv_ptpmap;
 		npv = pv->pv_next;
 		if (npv) {
-			npv->pv_flags = pv->pv_flags;
 			*pv = *npv;
 			pmap_free_pv(npv);
 		} else
@@ -2239,7 +2243,8 @@
 		ptpmap = npv->pv_ptpmap;
 		pv->pv_next = npv->pv_next;
 		pmap_free_pv(npv);
-		pv = pa_to_pvh(pa);
+		pvh = pa_to_pvh(pa);
+		pv = &pvh->pvh_first;
 	}
 
 #ifdef M68K_MMU_HP
@@ -2249,10 +2254,10 @@
 	 */
 
 	if (pmap_aliasmask &&
-	    pv->pv_pmap && pv->pv_next == NULL && (pv->pv_flags & PV_CI)) {
+	    pv->pv_pmap && pv->pv_next == NULL && (pvh->pvh_attrs & PVH_CI)) {
 		PMAP_DPRINTF(PDB_CACHE,
 		    ("remove: clearing CI for pa %lx\n", pa));
-		pv->pv_flags &= ~PV_CI;
+		pvh->pvh_attrs &= ~PVH_CI;
 		pmap_changebit(pa, 0, ~PG_CI);
 #ifdef DEBUG
 		if ((pmapdebug & (PDB_CACHE|PDB_PVDUMP)) ==
@@ -2333,7 +2338,7 @@
 					PMAP_ACTIVATE(ptpmap, 1);
 			}
 		}
-		pv->pv_flags &= ~PV_PTPAGE;
+		pvh->pvh_attrs &= ~PVH_PTPAGE;
 		ptpmap->pm_ptpages--;
 	}
 
@@ -2341,7 +2346,7 @@
 	 * Update saved attributes for managed page
 	 */
 
-	*pa_to_attribute(pa) |= bits;
+	pvh->pvh_attrs |= bits;
 	splx(s);
 }
 
@@ -2354,18 +2359,20 @@
 bool
 pmap_testbit(paddr_t pa, int bit)
 {
+	struct pv_header *pvh;
 	struct pv_entry *pv;
 	pt_entry_t *pte;
 	int s;
 
-	pv = pa_to_pvh(pa);
+	pvh = pa_to_pvh(pa);
+	pv = &pvh->pvh_first;
 	s = splvm();
 
 	/*
 	 * Check saved info first
 	 */
 
-	if (*pa_to_attribute(pa) & bit) {
+	if (pvh->pvh_attrs & bit) {
 		splx(s);
 		return true;
 	}
@@ -2389,7 +2396,7 @@
 		for (; pv; pv = pv->pv_next) {
 			pte = pmap_pte(pv->pv_pmap, pv->pv_va);
 			if (*pte & bit) {
-				*pa_to_attribute(pa) |= bit;
+				pvh->pvh_attrs |= bit;
 				splx(s);
 				return true;
 			}
@@ -2409,10 +2416,10 @@
 bool
 pmap_changebit(paddr_t pa, int set, int mask)
 {
+	struct pv_header *pvh;
 	struct pv_entry *pv;
 	pt_entry_t *pte, npte;
 	vaddr_t va;
-	char *attrp;
 	int s;
 #if defined(M68K_MMU_HP) || defined(M68040) || defined(M68060)
 	bool firstpage = true;
@@ -2422,16 +2429,16 @@
 	PMAP_DPRINTF(PDB_BITS,
 	    ("pmap_changebit(%lx, %x, %x)\n", pa, set, mask));
 
-	pv = pa_to_pvh(pa);
+	pvh = pa_to_pvh(pa);
+	pv = &pvh->pvh_first;
 	s = splvm();
 
 	/*
 	 * Clear saved attributes (modify, reference)
 	 */
 
-	attrp = pa_to_attribute(pa);
-	r = *attrp & ~mask;
-	*attrp &= mask;
+	r = (pvh->pvh_attrs & ~mask) != 0;
+	pvh->pvh_attrs &= mask;
 
 	/*
 	 * Loop over all current mappings setting/clearing as appropos
@@ -2502,6 +2509,7 @@
 {
 	paddr_t ptpa;
 	struct vm_page *pg;
+	struct pv_header *pvh;
 	struct pv_entry *pv;
 	st_entry_t *ste;
 	int s;
@@ -2687,14 +2695,17 @@
 	 * record the STE address.  This is so that we can invalidate
 	 * the STE when we remove the mapping for the page.
 	 */
-	pv = pa_to_pvh(ptpa);
+	pvh = pa_to_pvh(ptpa);
 	s = splvm();
-	if (pv) {
-		pv->pv_flags |= PV_PTPAGE;
+	if (pvh) {
+		pv = &pvh->pvh_first;
+		pvh->pvh_attrs |= PVH_PTPAGE;
 		do {
 			if (pv->pv_pmap == pmap_kernel() && pv->pv_va == va)
 				break;
 		} while ((pv = pv->pv_next));
+	} else {
+		pv = NULL;
 	}
 #ifdef DEBUG
 	if (pv == NULL)
@@ -2868,10 +2879,12 @@
 void
 pmap_pvdump(paddr_t pa)
 {
+	struct pv_header *pvh;
 	struct pv_entry *pv;
 
 	printf("pa %lx", pa);
-	for (pv = pa_to_pvh(pa); pv; pv = pv->pv_next)
+	pvh = pa_to_pvh(pa);
+	for (pv = &pvh->pvh_first; pv; pv = pv->pv_next)
 		printf(" -> pmap %p, va %lx, ptste %p, ptpmap %p, flags %x",
 		    pv->pv_pmap, pv->pv_va, pv->pv_ptste, pv->pv_ptpmap,
 		    pv->pv_flags);
--- a/sys/arch/mac68k/include/vmparam.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/mac68k/include/vmparam.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmparam.h,v 1.36.78.1 2009/05/04 08:11:27 yamt Exp $	*/
+/*	$NetBSD: vmparam.h,v 1.36.78.2 2009/09/16 13:37:40 yamt Exp $	*/
 
 /*
  * Copyright (c) 1982, 1990 The Regents of the University of California.
@@ -208,8 +208,7 @@
  * pmap-specific data stored in the vm_physmem[] array.
  */
 struct pmap_physseg {
-	struct pv_entry *pvent;		/* pv table for this seg */
-	char *attrs;			/* page attributes for this seg */
+	struct pv_header *pvheader;	/* pv table for this seg */
 };
 
 #endif /* _MAC68K_VMPARAM_H_ */
--- a/sys/arch/mips/include/proc.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/mips/include/proc.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: proc.h,v 1.21.18.1 2009/08/19 18:46:30 yamt Exp $	*/
+/*	$NetBSD: proc.h,v 1.21.18.2 2009/09/16 13:37:40 yamt Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -38,6 +38,7 @@
 #define _MIPS_PROC_H_
 
 #include <sys/param.h>
+#include <mips/vmparam.h>
 
 struct lwp;
 
--- a/sys/arch/mips/mips/genassym.cf	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/mips/mips/genassym.cf	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: genassym.cf,v 1.42.20.1 2009/05/04 08:11:31 yamt Exp $
+#	$NetBSD: genassym.cf,v 1.42.20.2 2009/09/16 13:37:40 yamt Exp $
 #
 # Copyright (c) 1992, 1993
 #	The Regents of the University of California.  All rights reserved.
@@ -100,9 +100,11 @@
 
 # Process status constants
 define	L_CPU			offsetof(struct lwp, l_cpu)
+if USPACE > PAGE_SIZE
 define	L_MD_REGS		offsetof(struct lwp, l_md.md_regs)
 define	L_MD_UPTE_0		offsetof(struct lwp, l_md.md_upte[0])
 define	L_MD_UPTE_1		offsetof(struct lwp, l_md.md_upte[1])
+endif
 define	L_MD_ASTPENDING		offsetof(struct lwp, l_md.md_astpending)
 
 define	P_RASLIST		offsetof(struct proc, p_raslist)
--- a/sys/arch/mips/mips/vm_machdep.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/mips/mips/vm_machdep.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm_machdep.c,v 1.120.20.3 2009/08/19 18:46:31 yamt Exp $	*/
+/*	$NetBSD: vm_machdep.c,v 1.120.20.4 2009/09/16 13:37:40 yamt Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.120.20.3 2009/08/19 18:46:31 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.120.20.4 2009/09/16 13:37:40 yamt Exp $");
 
 #include "opt_ddb.h"
 
@@ -215,6 +215,7 @@
 void
 cpu_swapin(struct lwp *l)
 {
+#if USPACE > PAGE_SIZE
 	pt_entry_t *pte;
 	int i, x;
 
@@ -229,6 +230,7 @@
 	pte = kvtopte(l->l_addr);
 	for (i = 0; i < UPAGES; i++)
 		l->l_md.md_upte[i] = pte[i].pt_entry &~ x;
+#endif
 }
 
 void
--- a/sys/arch/mipsco/conf/files.mipsco	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/mipsco/conf/files.mipsco	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.mipsco,v 1.13 2006/09/01 13:28:17 cube Exp $
+#	$NetBSD: files.mipsco,v 1.13.60.1 2009/09/16 13:37:40 yamt Exp $
 
 #  MIPS Computer Corp -specific configuration info
 
@@ -61,6 +61,8 @@
 file arch/mipsco/mipsco/prom.c
 file dev/cons.c
 
+file common/bus_dma/bus_dmamem_common.c
+
 # Memory Disk
 file dev/md_root.c			memory_disk_hooks
 
--- a/sys/arch/mipsco/mipsco/bus_dma.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/mipsco/mipsco/bus_dma.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus_dma.c,v 1.20.44.2 2009/05/04 08:11:32 yamt Exp $	*/
+/*	$NetBSD: bus_dma.c,v 1.20.44.3 2009/09/16 13:37:40 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.20.44.2 2009/05/04 08:11:32 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.20.44.3 2009/09/16 13:37:40 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -44,6 +44,8 @@
 #define _MIPSCO_BUS_DMA_PRIVATE
 #include <machine/bus.h>
 
+#include <common/bus_dma/bus_dmamem_common.h>
+
 #include <mips/cache.h>
 
 paddr_t	kvtophys(vaddr_t);	/* XXX */
@@ -510,58 +512,10 @@
 	paddr_t low;
 	paddr_t high;
 {
-	paddr_t curaddr, lastaddr;
-	struct vm_page *m;
-	struct pglist mlist;
-	int curseg, error;
 
-	/* Always round the size. */
-	size = round_page(size);
-
-	high = avail_end - PAGE_SIZE;
-
-	/*
-	 * Allocate pages from the VM system.
-	 */
-	error = uvm_pglistalloc(size, low, high, alignment, boundary,
-	    &mlist, nsegs, (flags & BUS_DMA_NOWAIT) == 0);
-	if (error)
-		return (error);
-
-	/*
-	 * Compute the location, size, and number of segments actually
-	 * returned by the VM code.
-	 */
-	m = mlist.tqh_first;
-	curseg = 0;
-	lastaddr = segs[curseg]._ds_paddr = VM_PAGE_TO_PHYS(m);
-	segs[curseg].ds_addr = segs[curseg]._ds_paddr + t->dma_offset;
-	segs[curseg].ds_len = PAGE_SIZE;
-	m = m->pageq.queue.tqe_next;
-
-	for (; m != NULL; m = m->pageq.queue.tqe_next) {
-		curaddr = VM_PAGE_TO_PHYS(m);
-#ifdef DIAGNOSTIC
-		if (curaddr < avail_start || curaddr >= high) {
-			printf("uvm_pglistalloc returned non-sensical"
-			    " address 0x%llx\n", (long long)curaddr);
-			panic("_bus_dmamem_alloc_range");
-		}
-#endif
-		if (curaddr == (lastaddr + PAGE_SIZE))
-			segs[curseg].ds_len += PAGE_SIZE;
-		else {
-			curseg++;
-			segs[curseg].ds_addr = curaddr + t->dma_offset;
-			segs[curseg].ds_len = PAGE_SIZE;
-			segs[curseg]._ds_paddr = curaddr;
-		}
-		lastaddr = curaddr;
-	}
-
-	*rsegs = curseg + 1;
-
-	return (0);
+	return (_bus_dmamem_alloc_range_common(t, size, alignment, boundary,
+					       segs, nsegs, rsegs, flags,
+					       low, high));
 }
 
 /*
@@ -571,25 +525,8 @@
 void
 _bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs)
 {
-	struct vm_page *m;
-	bus_addr_t addr;
-	struct pglist mlist;
-	int curseg;
 
-	/*
-	 * Build a list of pages to free back to the VM system.
-	 */
-	TAILQ_INIT(&mlist);
-	for (curseg = 0; curseg < nsegs; curseg++) {
-		for (addr = segs[curseg]._ds_paddr;
-		    addr < (segs[curseg]._ds_paddr + segs[curseg].ds_len);
-		    addr += PAGE_SIZE) {
-			m = PHYS_TO_VM_PAGE(addr);
-			TAILQ_INSERT_TAIL(&mlist, m, pageq.queue);
-		}
-	}
-
-	uvm_pglistfree(&mlist);
+	_bus_dmamem_free_common(t, segs, nsegs);
 }
 
 /*
@@ -599,11 +536,6 @@
 int
 _bus_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs, size_t size, void **kvap, int flags)
 {
-	vaddr_t va;
-	bus_addr_t addr;
-	int curseg;
-	const uvm_flag_t kmflags =
-	    (flags & BUS_DMA_NOWAIT) != 0 ? UVM_KMF_NOWAIT : 0;
 
 	/*
 	 * If we're only mapping 1 segment, use KSEG0 or KSEG1, to avoid
@@ -617,32 +549,8 @@
 		return (0);
 	}
 
-	size = round_page(size);
-
-	va = uvm_km_alloc(kernel_map, size, 0, UVM_KMF_VAONLY | kmflags);
-
-	if (va == 0)
-		return (ENOMEM);
-
-	*kvap = (void *)va;
-
-	for (curseg = 0; curseg < nsegs; curseg++) {
-		segs[curseg]._ds_vaddr = va;
-		for (addr = segs[curseg]._ds_paddr;
-		    addr < (segs[curseg]._ds_paddr + segs[curseg].ds_len);
-		    addr += PAGE_SIZE, va += PAGE_SIZE, size -= PAGE_SIZE) {
-			if (size == 0)
-				panic("_bus_dmamem_map: size botch");
-			pmap_enter(pmap_kernel(), va, addr,
-			    VM_PROT_READ | VM_PROT_WRITE,
-			    VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED);
-
-			/* XXX Do something about COHERENT here. */
-		}
-	}
-	pmap_update(pmap_kernel());
-
-	return (0);
+	/* XXX BUS_DMA_COHERENT */
+	return (_bus_dmamem_map_common(t, segs, nsegs, size, kvap, flags, 0));
 }
 
 /*
@@ -653,11 +561,6 @@
 _bus_dmamem_unmap(bus_dma_tag_t t, void *kva, size_t size)
 {
 
-#ifdef DIAGNOSTIC
-	if ((u_long)kva & PGOFSET)
-		panic("_bus_dmamem_unmap");
-#endif
-
 	/*
 	 * Nothing to do if we mapped it with KSEG0 or KSEG1 (i.e.
 	 * not in KSEG2).
@@ -666,9 +569,7 @@
 	    kva < (void *)MIPS_KSEG2_START)
 		return;
 
-	pmap_remove(pmap_kernel(), (vaddr_t)kva, (vaddr_t)kva + size);
-	pmap_update(pmap_kernel());
-	uvm_km_free(kernel_map, (vaddr_t)kva, size, UVM_KMF_VAONLY);
+	_bus_dmamem_unmap_common(t, kva, size);
 }
 
 /*
@@ -678,26 +579,11 @@
 paddr_t
 _bus_dmamem_mmap(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs, off_t off, int prot, int flags)
 {
-	int i;
+	bus_addr_t rv;
 
-	for (i = 0; i < nsegs; i++) {
-#ifdef DIAGNOSTIC
-		if (off & PGOFSET)
-			panic("_bus_dmamem_mmap: offset unaligned");
-		if (segs[i]._ds_paddr & PGOFSET)
-			panic("_bus_dmamem_mmap: segment unaligned");
-		if (segs[i].ds_len & PGOFSET)
-			panic("_bus_dmamem_mmap: segment size not multiple"
-			    " of page size");
-#endif
-		if (off >= segs[i].ds_len) {
-			off -= segs[i].ds_len;
-			continue;
-		}
-
-		return (mips_btop(segs[i]._ds_paddr + off));
-	}
-
-	/* Page not found. */
-	return (-1);
+	rv = _bus_dmamem_mmap_common(t, segs, nsegs, off, prot, flags);
+	if (rv == (bus_addr_t)-1)
+		return (-1);
+	
+	return (mips_btop((char *)rv));
 }
--- a/sys/arch/mvme68k/include/vmparam.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/mvme68k/include/vmparam.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmparam.h,v 1.28.20.1 2009/05/04 08:11:34 yamt Exp $	*/
+/*	$NetBSD: vmparam.h,v 1.28.20.2 2009/09/16 13:37:40 yamt Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -174,8 +174,7 @@
  * pmap-specific data stored in the vm_physmem[] array.
  */
 struct pmap_physseg {
-	struct pv_entry *pvent;		/* pv table for this seg */
-	char *attrs;			/* page attributes for this seg */
+	struct pv_header *pvheader;	/* pv table for this seg */
 };
 
 #endif /* _MVME68K_VMPARAM_H_ */
--- a/sys/arch/mvme68k/stand/bootxx/bootxx.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/mvme68k/stand/bootxx/bootxx.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bootxx.c,v 1.14.10.1 2008/05/16 02:22:56 yamt Exp $ */
+/*	$NetBSD: bootxx.c,v 1.14.10.2 2009/09/16 13:37:41 yamt Exp $ */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -43,6 +43,7 @@
 #include <sys/time.h>
 #include <sys/exec.h>
 #include <sys/exec_elf.h>
+#include <sys/exec_aout.h>
 #include <machine/prom.h>
 
 #include <lib/libsa/stand.h>
--- a/sys/arch/news68k/include/vmparam.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/news68k/include/vmparam.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmparam.h,v 1.13.78.1 2009/05/04 08:11:37 yamt Exp $	*/
+/*	$NetBSD: vmparam.h,v 1.13.78.2 2009/09/16 13:37:41 yamt Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -172,8 +172,7 @@
  * pmap-specific data stored in the vm_physmem[] array.
  */
 struct pmap_physseg {
-	struct pv_entry *pvent;		/* pv table for this seg */
-	char *attrs;			/* page attributes for this seg */
+	struct pv_header *pvheader;	/* pv table for this seg */
 };
 
 #endif /* _NEWS68K_VMPARAM_H_ */
--- a/sys/arch/newsmips/conf/files.newsmips	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/newsmips/conf/files.newsmips	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.newsmips,v 1.26 2008/02/20 21:43:34 drochner Exp $
+#	$NetBSD: files.newsmips,v 1.26.10.1 2009/09/16 13:37:41 yamt Exp $
 
 # NEWSMIPS-specific configuration info
 
@@ -96,6 +96,8 @@
 file arch/newsmips/newsmips/cpu_cons.c
 file dev/cons.c
 
+file common/bus_dma/bus_dmamem_common.c
+
 file arch/mips/mips/softintr.c
 
 #
--- a/sys/arch/newsmips/newsmips/bus.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/newsmips/newsmips/bus.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus.c,v 1.26.44.2 2009/05/04 08:11:38 yamt Exp $	*/
+/*	$NetBSD: bus.c,v 1.26.44.3 2009/09/16 13:37:41 yamt Exp $	*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus.c,v 1.26.44.2 2009/05/04 08:11:38 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus.c,v 1.26.44.3 2009/09/16 13:37:41 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -45,6 +45,8 @@
 #include <machine/bus.h>
 #include <machine/cpu.h>
 
+#include <common/bus_dma/bus_dmamem_common.h>
+
 #include <uvm/uvm_extern.h>
 
 #include <mips/cache.h>
@@ -700,57 +702,11 @@
     int flags)
 {
 	extern paddr_t avail_start, avail_end;
-	vaddr_t curaddr, lastaddr;
-	psize_t high;
-	struct vm_page *m;
-	struct pglist mlist;
-	int curseg, error;
 
-	/* Always round the size. */
-	size = round_page(size);
-
-	high = avail_end - PAGE_SIZE;
-
-	/*
-	 * Allocate pages from the VM system.
-	 */
-	error = uvm_pglistalloc(size, avail_start, high, alignment, boundary,
-	    &mlist, nsegs, (flags & BUS_DMA_NOWAIT) == 0);
-	if (error)
-		return error;
-
-	/*
-	 * Compute the location, size, and number of segments actually
-	 * returned by the VM code.
-	 */
-	m = mlist.tqh_first;
-	curseg = 0;
-	lastaddr = segs[curseg].ds_addr = VM_PAGE_TO_PHYS(m);
-	segs[curseg].ds_len = PAGE_SIZE;
-	m = m->pageq.queue.tqe_next;
-
-	for (; m != NULL; m = m->pageq.queue.tqe_next) {
-		curaddr = VM_PAGE_TO_PHYS(m);
-#ifdef DIAGNOSTIC
-		if (curaddr < avail_start || curaddr >= high) {
-			printf("uvm_pglistalloc returned non-sensical"
-			    " address 0x%lx\n", curaddr);
-			panic("_bus_dmamem_alloc");
-		}
-#endif
-		if (curaddr == (lastaddr + PAGE_SIZE))
-			segs[curseg].ds_len += PAGE_SIZE;
-		else {
-			curseg++;
-			segs[curseg].ds_addr = curaddr;
-			segs[curseg].ds_len = PAGE_SIZE;
-		}
-		lastaddr = curaddr;
-	}
-
-	*rsegs = curseg + 1;
-
-	return 0;
+	return (_bus_dmamem_alloc_range_common(t, size, alignment, boundary,
+					       segs, nsegs, rsegs, flags,
+					       avail_start /*low*/,
+					       avail_end - PAGE_SIZE /*high*/));
 }
 
 /*
@@ -760,25 +716,8 @@
 void
 _bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs)
 {
-	struct vm_page *m;
-	bus_addr_t addr;
-	struct pglist mlist;
-	int curseg;
 
-	/*
-	 * Build a list of pages to free back to the VM system.
-	 */
-	TAILQ_INIT(&mlist);
-	for (curseg = 0; curseg < nsegs; curseg++) {
-		for (addr = segs[curseg].ds_addr;
-		    addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
-		    addr += PAGE_SIZE) {
-			m = PHYS_TO_VM_PAGE(addr);
-			TAILQ_INSERT_TAIL(&mlist, m, pageq.queue);
-		}
-	}
-
-	uvm_pglistfree(&mlist);
+	_bus_dmamem_free_common(t, segs, nsegs);
 }
 
 /*
@@ -789,11 +728,6 @@
 _bus_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
     size_t size, void **kvap, int flags)
 {
-	vaddr_t va;
-	bus_addr_t addr;
-	int curseg;
-	const uvm_flag_t kmflags =
-	    (flags & BUS_DMA_NOWAIT) != 0 ? UVM_KMF_NOWAIT : 0;
 
 	/*
 	 * If we're only mapping 1 segment, and the address is lower than
@@ -807,31 +741,8 @@
 		return 0;
 	}
 
-	size = round_page(size);
-
-	va = uvm_km_alloc(kernel_map, size, 0, UVM_KMF_VAONLY | kmflags);
-
-	if (va == 0)
-		return ENOMEM;
-
-	*kvap = (void *)va;
-
-	for (curseg = 0; curseg < nsegs; curseg++) {
-		for (addr = segs[curseg].ds_addr;
-		    addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
-		    addr += PAGE_SIZE, va += PAGE_SIZE, size -= PAGE_SIZE) {
-			if (size == 0)
-				panic("_bus_dmamem_map: size botch");
-			pmap_enter(pmap_kernel(), va, addr,
-			    VM_PROT_READ | VM_PROT_WRITE,
-			    VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED);
-
-			/* XXX Do something about COHERENT here. */
-		}
-	}
-	pmap_update(pmap_kernel());
-
-	return 0;
+	/* XXX BUS_DMA_COHERENT */
+	return (_bus_dmamem_map_common(t, segs, nsegs, size, kvap, flags, 0));
 }
 
 /*
@@ -842,11 +753,6 @@
 _bus_dmamem_unmap(bus_dma_tag_t t, void *kva, size_t size)
 {
 
-#ifdef DIAGNOSTIC
-	if ((u_long)kva & PGOFSET)
-		panic("_bus_dmamem_unmap");
-#endif
-
 	/*
 	 * Nothing to do if we mapped it with KSEG0 or KSEG1 (i.e.
 	 * not in KSEG2).
@@ -855,10 +761,7 @@
 	    kva < (void *)MIPS_KSEG2_START)
 		return;
 
-	size = round_page(size);
-	pmap_remove(pmap_kernel(), (vaddr_t)kva, (vaddr_t)kva + size);
-	pmap_update(pmap_kernel());
-	uvm_km_free(kernel_map, (vaddr_t)kva, size, UVM_KMF_VAONLY);
+	_bus_dmamem_unmap_common(t, kva, size);
 }
 
 /*
@@ -869,26 +772,11 @@
 _bus_dmamem_mmap(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
     off_t off, int prot, int flags)
 {
-	int i;
+	bus_addr_t rv;
 
-	for (i = 0; i < nsegs; i++) {
-#ifdef DIAGNOSTIC
-		if (off & PGOFSET)
-			panic("_bus_dmamem_mmap: offset unaligned");
-		if (segs[i].ds_addr & PGOFSET)
-			panic("_bus_dmamem_mmap: segment unaligned");
-		if (segs[i].ds_len & PGOFSET)
-			panic("_bus_dmamem_mmap: segment size not multiple"
-			    " of page size");
-#endif
-		if (off >= segs[i].ds_len) {
-			off -= segs[i].ds_len;
-			continue;
-		}
-
-		return mips_btop((char *)segs[i].ds_addr + off);
-	}
-
-	/* Page not found. */
-	return -1;
+	rv = _bus_dmamem_mmap_common(t, segs, nsegs, off, prot, flags);
+	if (rv == (bus_addr_t)-1)
+		return (-1);
+	
+	return (mips_btop((char *)rv));
 }
--- a/sys/arch/next68k/dev/esp.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/next68k/dev/esp.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: esp.c,v 1.55.4.2 2009/05/04 08:11:39 yamt Exp $	*/
+/*	$NetBSD: esp.c,v 1.55.4.3 2009/09/16 13:37:41 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: esp.c,v 1.55.4.2 2009/05/04 08:11:39 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: esp.c,v 1.55.4.3 2009/09/16 13:37:41 yamt Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -649,7 +649,6 @@
 				}
 				xfer_len = esc->sc_dmasize - resid;
 			} else {
-extern void	ncr53c9x_abort(struct ncr53c9x_softc *, struct ncr53c9x_ecb *);
 #define ncr53c9x_sched_msgout(m) \
 	do {							\
 		NCR_MISC(("ncr53c9x_sched_msgout %x %d", m, __LINE__));	\
--- a/sys/arch/next68k/include/vmparam.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/next68k/include/vmparam.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmparam.h,v 1.18.78.1 2009/05/04 08:11:39 yamt Exp $	*/
+/*	$NetBSD: vmparam.h,v 1.18.78.2 2009/09/16 13:37:41 yamt Exp $	*/
 
 /*
  * This file was taken from from mvme68k/include/vmparam.h and
@@ -177,8 +177,7 @@
  * pmap-specific data stored in the vm_physmem[] array.
  */
 struct pmap_physseg {
-	struct pv_entry *pvent;		/* pv table for this seg */
-	char *attrs;			/* page attributes for this seg */
+	struct pv_header *pvheader;	/* pv table for this seg */
 };
 
 #endif /* _MVME68K_VMPARAM_H_ */
--- a/sys/arch/ofppc/stand/ofwboot/Makefile	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/ofppc/stand/ofwboot/Makefile	Wed Sep 16 13:37:34 2009 +0000
@@ -1,9 +1,10 @@
-#	$NetBSD: Makefile,v 1.23.10.1 2009/05/04 08:11:40 yamt Exp $
+#	$NetBSD: Makefile,v 1.23.10.2 2009/09/16 13:37:41 yamt Exp $
 
 S!=	cd ${.CURDIR}/../../../.. ; pwd
 
 PROG=		ofwboot
-SRCS=		ofwstart.S Locore.c boot.c ofdev.c net.c netif_of.c vers.c
+SRCS=		ofwstart.S Locore.c boot.c ofdev.c net.c netif_of.c
+SRCS+=		mbr.c rdb.c vers.c
 CFLAGS+=	-msoft-float -Wno-main -ffreestanding
 CFLAGS+=	-Wall -Wmissing-prototypes -Wstrict-prototypes -Wpointer-arith
 #CPPFLAGS+=	-g -DALLOC_TRACE -DDEBUG #-DOFW_DEBUG -DNETIF_DEBUG
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/ofppc/stand/ofwboot/mbr.c	Wed Sep 16 13:37:34 2009 +0000
@@ -0,0 +1,113 @@
+/*	$NetBSD: mbr.c,v 1.1.2.2 2009/09/16 13:37:41 yamt Exp $	*/
+
+/*
+ * Copyright (C) 1995, 1996 Wolfgang Solfrank.
+ * Copyright (C) 1995, 1996 TooLs GmbH.
+ * 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 TooLs GmbH.
+ * 4. The name of TooLs GmbH may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
+ */
+
+#include <sys/param.h>
+#include <sys/bootblock.h>
+
+#include <lib/libsa/byteorder.h>
+#include <lib/libsa/stand.h>
+
+#include "mbr.h"
+
+
+static u_long
+get_long(const void *p)
+{
+	const unsigned char *cp = p;
+
+	return cp[0] | (cp[1] << 8) | (cp[2] << 16) | (cp[3] << 24);
+}
+
+
+/*
+ * Find a valid MBR disklabel.
+ */
+int
+search_mbr_label(struct of_dev *devp, u_long off, char *buf,
+    struct disklabel *lp, u_long off0)
+{
+	size_t read;
+	struct mbr_partition *p;
+	int i;
+	u_long poff;
+	static int recursion;
+
+	if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read)
+	    || read != DEV_BSIZE)
+		return ERDLAB;
+
+	if (*(u_int16_t *)&buf[MBR_MAGIC_OFFSET] != sa_htole16(MBR_MAGIC))
+		return ERDLAB;
+
+	if (recursion++ <= 1)
+		off0 += off;
+	for (p = (struct mbr_partition *)(buf + MBR_PART_OFFSET), i = 0;
+	     i < MBR_PART_COUNT; i++, p++) {
+		if (p->mbrp_type == MBR_PTYPE_NETBSD
+#ifdef COMPAT_386BSD_MBRPART
+		    || (p->mbrp_type == MBR_PTYPE_386BSD &&
+			(printf("WARNING: old BSD partition ID!\n"), 1)
+			/* XXX XXX - libsa printf() is void */ )
+#endif
+		    ) {
+			poff = get_long(&p->mbrp_start) + off0;
+			if (strategy(devp, F_READ, poff + LABELSECTOR,
+				     DEV_BSIZE, buf, &read) == 0
+			    && read == DEV_BSIZE) {
+				if (!getdisklabel(buf, lp)) {
+					recursion--;
+					return 0;
+				}
+			}
+			if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read)
+			    || read != DEV_BSIZE) {
+				recursion--;
+				return ERDLAB;
+			}
+		} else if (p->mbrp_type == MBR_PTYPE_EXT) {
+			poff = get_long(&p->mbrp_start);
+			if (!search_mbr_label(devp, poff, buf, lp, off0)) {
+				recursion--;
+				return 0;
+			}
+			if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read)
+			    || read != DEV_BSIZE) {
+				recursion--;
+				return ERDLAB;
+			}
+		}
+	}
+
+	recursion--;
+	return ERDLAB;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/ofppc/stand/ofwboot/mbr.h	Wed Sep 16 13:37:34 2009 +0000
@@ -0,0 +1,43 @@
+/* $NetBSD: mbr.h,v 1.1.2.2 2009/09/16 13:37:41 yamt Exp $ */
+
+/*
+ * Copyright (C) 1995, 1996 Wolfgang Solfrank.
+ * Copyright (C) 1995, 1996 TooLs GmbH.
+ * 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 TooLs GmbH.
+ * 4. The name of TooLs GmbH may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
+ */
+
+#ifndef MBR_H_
+#define MBR_H_
+
+#include <sys/disklabel.h>
+#include "ofdev.h"
+
+int search_mbr_label(struct of_dev *, u_long, char *, struct disklabel *,
+    u_long);
+
+#endif /* MBR_H_ */
--- a/sys/arch/ofppc/stand/ofwboot/ofdev.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/ofppc/stand/ofwboot/ofdev.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofdev.c,v 1.15.10.1 2009/05/04 08:11:40 yamt Exp $	*/
+/*	$NetBSD: ofdev.c,v 1.15.10.2 2009/09/16 13:37:41 yamt Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -37,8 +37,6 @@
 #include "ofdev.h"
 
 #include <sys/param.h>
-#include <sys/disklabel.h>
-#include <sys/bootblock.h>
 
 #include <netinet/in.h>
 
@@ -52,6 +50,8 @@
 
 #include "net.h"
 #include "openfirm.h"
+#include "mbr.h"
+#include "rdb.h"
 
 extern char bootdev[];
 
@@ -120,7 +120,7 @@
 	return 0;
 }
 
-static int
+int
 strategy(void *devdata, int rw, daddr_t blk, size_t size, void *buf,
 	 size_t *rsize)
 {
@@ -186,76 +186,6 @@
 char opened_name[256];
 int floppyboot;
 
-static u_long
-get_long(const void *p)
-{
-	const unsigned char *cp = p;
-
-	return cp[0] | (cp[1] << 8) | (cp[2] << 16) | (cp[3] << 24);
-}
-
-/*
- * Find a valid disklabel.
- */
-static int
-search_label(struct of_dev *devp, u_long off, char *buf, struct disklabel *lp,
-								u_long off0)
-{
-	size_t read;
-	struct mbr_partition *p;
-	int i;
-	u_long poff;
-	static int recursion;
-
-	if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read)
-	    || read != DEV_BSIZE)
-		return ERDLAB;
-
-	if (*(u_int16_t *)&buf[MBR_MAGIC_OFFSET] != sa_htole16(MBR_MAGIC))
-		return ERDLAB;
-
-	if (recursion++ <= 1)
-		off0 += off;
-	for (p = (struct mbr_partition *)(buf + MBR_PART_OFFSET), i = 0;
-	     i < MBR_PART_COUNT; i++, p++) {
-		if (p->mbrp_type == MBR_PTYPE_NETBSD
-#ifdef COMPAT_386BSD_MBRPART
-		    || (p->mbrp_type == MBR_PTYPE_386BSD &&
-			(printf("WARNING: old BSD partition ID!\n"), 1)
-			/* XXX XXX - libsa printf() is void */ )
-#endif
-		    ) {
-			poff = get_long(&p->mbrp_start) + off0;
-			if (strategy(devp, F_READ, poff + LABELSECTOR,
-				     DEV_BSIZE, buf, &read) == 0
-			    && read == DEV_BSIZE) {
-				if (!getdisklabel(buf, lp)) {
-					recursion--;
-					return 0;
-				}
-			}
-			if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read)
-			    || read != DEV_BSIZE) {
-				recursion--;
-				return ERDLAB;
-			}
-		} else if (p->mbrp_type == MBR_PTYPE_EXT) {
-			poff = get_long(&p->mbrp_start);
-			if (!search_label(devp, poff, buf, lp, off0)) {
-				recursion--;
-				return 0;
-			}
-			if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read)
-			    || read != DEV_BSIZE) {
-				recursion--;
-				return ERDLAB;
-			}
-		}
-	}
-
-	recursion--;
-	return ERDLAB;
-}
 
 int
 devopen(struct open_file *of, const char *name, char **file)
@@ -263,11 +193,12 @@
 	char *cp;
 	char partition;
 	char fname[256];
-	char buf[DEV_BSIZE];
 	struct disklabel label;
 	int handle, part;
 	size_t read;
 	int error = 0;
+	/* allow disk blocks up to 65536 bytes */
+	char buf[DEV_BSIZE<<7];
 
 	if (ofdev.handle != -1)
 		panic("devopen");
@@ -326,14 +257,19 @@
 		ofdev.type = OFDEV_DISK;
 		ofdev.bsize = DEV_BSIZE;
 
-		/* First try to find a disklabel without MBR partitions */
+		/* First try to find a disklabel without MBR/RDB partitions */
 		if (strategy(&ofdev, F_READ,
 			     LABELSECTOR, DEV_BSIZE, buf, &read) != 0
 		    || read != DEV_BSIZE
 		    || getdisklabel(buf, &label)) {
 
 			/* Else try MBR partitions */
-			error = search_label(&ofdev, 0, buf, &label, 0);
+			error = search_mbr_label(&ofdev, 0, buf, &label, 0);
+			if (error && error != ERDLAB)
+				goto bad;
+
+			/* and finally try RDB partitions */
+			error = search_rdb_label(&ofdev, buf, &label);
 			if (error && error != ERDLAB)
 				goto bad;
 		}
--- a/sys/arch/ofppc/stand/ofwboot/ofdev.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/ofppc/stand/ofwboot/ofdev.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofdev.h,v 1.2 2003/06/26 20:47:51 aymeric Exp $	*/
+/*	$NetBSD: ofdev.h,v 1.2.108.1 2009/09/16 13:37:41 yamt Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -51,4 +51,6 @@
 extern char opened_name[];
 extern int floppyboot;
 
+int strategy(void *, int, daddr_t, size_t, void *, size_t *);
+
 #endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/ofppc/stand/ofwboot/rdb.c	Wed Sep 16 13:37:34 2009 +0000
@@ -0,0 +1,253 @@
+/*	$NetBSD: rdb.c,v 1.1.2.2 2009/09/16 13:37:41 yamt Exp $	*/
+
+/*-
+ * Copyright (c) 2009 Frank Wille.
+ * All rights reserved.
+ *
+ * Written by Frank Wille for The NetBSD Project.
+ *
+ * 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.
+ *
+ * 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.
+ */
+
+#include <sys/param.h>
+#include <sys/disklabel_rdb.h>
+
+#include <lib/libsa/stand.h>
+
+#include "rdb.h"
+
+
+static u_long
+rdbchksum(void *bdata)
+{
+	u_long *blp, cnt, val;
+
+	blp = bdata;
+	cnt = blp[1];
+	val = 0;
+
+	while (cnt--)
+		val += *blp++;
+	return val;
+}
+
+
+static struct adostype
+getadostype(u_long dostype)
+{
+	struct adostype adt;
+	u_long t3, b1;
+
+	t3 = dostype & 0xffffff00;
+	b1 = dostype & 0x000000ff;
+
+	adt.fstype = b1;
+
+	switch (t3) {
+	case DOST_NBR:
+		adt.archtype = ADT_NETBSDROOT;
+		return adt;
+	case DOST_NBS:
+		adt.archtype = ADT_NETBSDSWAP;
+		return adt;
+	case DOST_NBU:
+		adt.archtype = ADT_NETBSDUSER;
+		return adt;
+	case DOST_AMIX:
+		adt.archtype = ADT_AMIX;
+		if (b1 == 2)
+			adt.fstype = FS_BSDFFS;
+		else
+			adt.fstype = FS_UNUSED;
+		return adt;
+	case DOST_XXXBSD:
+		if (b1 == 'S') {
+			dostype = DOST_NBS;
+			dostype |= FS_SWAP;
+		} else {
+			if (b1 == 'R')
+				dostype = DOST_NBR;
+			else
+				dostype = DOST_NBU;
+			dostype |= FS_BSDFFS;
+		}
+		return getadostype(dostype);
+	case DOST_EXT2:
+		adt.archtype = ADT_EXT2;
+		adt.fstype = FS_EX2FS;
+		return adt;
+	case DOST_RAID:
+		adt.archtype = ADT_RAID;
+		adt.fstype = FS_RAID;
+		return adt;
+	default:
+		adt.archtype = ADT_UNKNOWN;
+		adt.fstype = FS_UNUSED;
+		return adt;
+	}
+}
+
+
+/*
+ * Find a valid RDB disklabel.
+ */
+int
+search_rdb_label(struct of_dev *devp, char *buf, struct disklabel *lp)
+{
+	struct adostype adt;
+	struct rdblock *rbp;
+	struct partblock *pbp;
+	struct disklabel *dlp;
+	struct partition *pp;
+	u_long blk;
+	size_t read;
+	int i;
+
+	/*
+	 * Scan the first RDB_MAXBLOCKS of a disk for an RDB block.
+	 */
+	rbp = (struct rdblock *)buf;
+	for (blk = 0; blk < RDB_MAXBLOCKS; blk++) {
+		if (strategy(devp, F_READ, blk, DEV_BSIZE, buf, &read)
+		    || read != DEV_BSIZE)
+			return ERDLAB;
+
+		/* check for valid RDB */
+		if (rbp->id == RDBLOCK_ID && rdbchksum(rbp) == 0)
+			break;
+
+		/* check for native NetBSD label */
+		dlp = (struct disklabel *)(buf + LABELOFFSET);
+		if (dlp->d_magic == DISKMAGIC && dkcksum(dlp) == 0) {
+			*lp = *dlp;
+			return 0;
+		}
+	}
+	if (blk == RDB_MAXBLOCKS)
+		return ERDLAB;
+
+	/* Found RDB, clear disklabel partitions before reading PART blocks. */
+	lp->d_npartitions = RAW_PART + 1;
+	for (i = 0; i < MAXPARTITIONS; i++) {
+		lp->d_partitions[i].p_size = 0;
+		lp->d_partitions[i].p_offset = 0;
+		lp->d_partitions[i].p_fstype = 0;
+	}
+
+	/*
+	 * Construct a disklabel from RDB.
+	 */
+	lp->d_secsize = rbp->nbytes;
+	lp->d_nsectors = rbp->nsectors;
+	lp->d_ntracks = rbp->nheads;
+	/* be prepared that rbp->ncylinders may be a bogus value */
+	if (rbp->highcyl == 0)
+		lp->d_ncylinders = rbp->ncylinders;
+	else
+		lp->d_ncylinders = rbp->highcyl + 1;
+	/* also don't trust rbp->secpercyl */
+	lp->d_secpercyl = (rbp->secpercyl <= lp->d_nsectors * lp->d_ntracks) ?
+	    rbp->secpercyl : lp->d_nsectors * lp->d_ntracks;
+	if (lp->d_secpercyl == 0)
+		lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks;
+
+	lp->d_secperunit = lp->d_secpercyl * lp->d_ncylinders;
+	lp->d_acylinders = rbp->ncylinders - (rbp->highcyl - rbp->lowcyl + 1);
+	lp->d_rpm = 3600;
+	lp->d_interleave = rbp->interleave;
+	lp->d_headswitch = lp->d_flags = lp->d_trackskew = lp->d_cylskew = 0;
+	lp->d_trkseek = 0;
+
+	/* raw partition gets the entire disk */
+	lp->d_partitions[RAW_PART].p_size = rbp->ncylinders * lp->d_secpercyl;
+
+	/*
+	 * Now scan for partition blocks.
+	 */
+	pbp = (struct partblock *)buf;
+	for (blk = rbp->partbhead; blk != RDBNULL; blk = pbp->next) {
+		if (strategy(devp, F_READ, blk * (lp->d_secsize / DEV_BSIZE),
+		    lp->d_secsize, buf, &read)
+		    || read != lp->d_secsize)
+			return ERDLAB;
+
+		/* verify ID and checksum of PART block */
+		if (pbp->id != PARTBLOCK_ID || rdbchksum(pbp))
+			return ERDLAB;
+
+		/* environment table in PART block needs at least 11 entries */
+		if (pbp->e.tabsize < 11)
+			return ERDLAB;
+
+		/* need a table size of 16 for a valid dostype */
+		if (pbp->e.tabsize < 16)
+			pbp->e.dostype = 0;
+		adt = getadostype(pbp->e.dostype);
+
+		/* determine partition index */
+		switch (adt.archtype) {
+		case ADT_NETBSDROOT:
+			pp = &lp->d_partitions[0];
+			if (pp->p_size)
+				continue;
+			break;
+		case ADT_NETBSDSWAP:
+			pp = &lp->d_partitions[1];
+			if (pp->p_size)
+				continue;
+			break;
+		default:
+			pp = &lp->d_partitions[lp->d_npartitions++];
+			break;
+		}
+
+		/* sort partitions after RAW_PART by offset */
+		while ((pp - lp->d_partitions) > RAW_PART + 1) {
+			daddr_t boff;
+
+			boff = pbp->e.lowcyl * pbp->e.secpertrk
+			    * pbp->e.numheads
+			    * ((pbp->e.sizeblock << 2) / lp->d_secsize);
+			if (boff > (pp - 1)->p_offset)
+				break;
+			*pp = *(pp - 1);	/* struct copy */
+			pp--;
+		}
+
+		/* get partition size, offset, fstype */
+		pp->p_size = (pbp->e.highcyl - pbp->e.lowcyl + 1)
+		    * pbp->e.secpertrk * pbp->e.numheads
+		    * ((pbp->e.sizeblock << 2) / lp->d_secsize);
+		pp->p_offset = pbp->e.lowcyl * pbp->e.secpertrk
+		    * pbp->e.numheads
+		    * ((pbp->e.sizeblock << 2) / lp->d_secsize);
+		pp->p_fstype = adt.fstype;
+	}
+
+	/*
+	 * All partitions have been found. The disklabel is valid.
+	 */
+	lp->d_magic = lp->d_magic2 = DISKMAGIC;
+	lp->d_checksum = 0;
+	lp->d_checksum = dkcksum(lp);
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/ofppc/stand/ofwboot/rdb.h	Wed Sep 16 13:37:34 2009 +0000
@@ -0,0 +1,39 @@
+/* $NetBSD: rdb.h,v 1.1.2.2 2009/09/16 13:37:41 yamt Exp $ */
+
+/*-
+ * Copyright (c) 2009 Frank Wille.
+ * All rights reserved.
+ *
+ * Written by Frank Wille for The NetBSD Project.
+ *
+ * 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.
+ *
+ * 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.
+ */
+
+#ifndef RDB_H_
+#define RDB_H_
+
+#include <sys/disklabel.h>
+#include "ofdev.h"
+
+int search_rdb_label(struct of_dev *, char *, struct disklabel *);
+
+#endif /* RDB_H_ */
--- a/sys/arch/ofppc/stand/ofwboot/version	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/ofppc/stand/ofwboot/version	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.10 2008/02/13 20:11:38 garbled Exp $
+$NetBSD: version,v 1.10.10.1 2009/09/16 13:37:41 yamt Exp $
 
 1.1:		Boot program for OpenFirmware; initial revision
 1.2:		Boot program rearrangement
@@ -10,3 +10,4 @@
 1.8:		Support IBM RS/6000, switch to stock libsa alloc
 1.9:		Add support for auto-detection of 64bit CPUs
 1.10:		Change note to indicate real mode, add ldscript to support 7046
+1.11:		Support for RDB partitions.
--- a/sys/arch/playstation2/conf/files.playstation2	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/playstation2/conf/files.playstation2	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.playstation2,v 1.17 2008/02/20 21:43:35 drochner Exp $
+#	$NetBSD: files.playstation2,v 1.17.10.1 2009/09/16 13:37:41 yamt Exp $
 
 maxpartitions 8
 
@@ -25,6 +25,7 @@
 file arch/playstation2/playstation2/sifbios.c
 file arch/mips/mips/mips3_clock.c
 
+file common/bus_dma/bus_dmamem_common.c
 
 file dev/kloader.c					kloader
 file arch/playstation2/playstation2/kloader_machdep.c	kloader
--- a/sys/arch/playstation2/playstation2/bus_dma.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/playstation2/playstation2/bus_dma.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus_dma.c,v 1.16.44.2 2009/05/04 08:11:40 yamt Exp $	*/
+/*	$NetBSD: bus_dma.c,v 1.16.44.3 2009/09/16 13:37:41 yamt Exp $	*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.16.44.2 2009/05/04 08:11:40 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.16.44.3 2009/09/16 13:37:41 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/malloc.h>
@@ -43,6 +43,8 @@
 #define _PLAYSTATION2_BUS_DMA_PRIVATE
 #include <machine/bus.h>
 
+#include <common/bus_dma/bus_dmamem_common.h>
+
 #include <uvm/uvm_extern.h>
 
 #include <machine/locore.h>
@@ -478,57 +480,11 @@
     int flags)
 {
 	extern paddr_t avail_start, avail_end;
-	vaddr_t curaddr, lastaddr;
-	psize_t high;
-	struct vm_page *m;
-	struct pglist mlist;
-	int curseg, error;
 
-	/* Always round the size. */
-	size = round_page(size);
-
-	high = avail_end - PAGE_SIZE;
-
-	/*
-	 * Allocate pages from the VM system.
-	 */
-	error = uvm_pglistalloc(size, avail_start, high, alignment, boundary,
-	    &mlist, nsegs, (flags & BUS_DMA_NOWAIT) == 0);
-	if (error)
-		return error;
-
-	/*
-	 * Compute the location, size, and number of segments actually
-	 * returned by the VM code.
-	 */
-	m = mlist.tqh_first;
-	curseg = 0;
-	lastaddr = segs[curseg].ds_addr = VM_PAGE_TO_PHYS(m);
-	segs[curseg].ds_len = PAGE_SIZE;
-	m = m->pageq.queue.tqe_next;
-
-	for (; m != NULL; m = m->pageq.queue.tqe_next) {
-		curaddr = VM_PAGE_TO_PHYS(m);
-#ifdef DIAGNOSTIC
-		if (curaddr < avail_start || curaddr >= high) {
-			printf("uvm_pglistalloc returned non-sensical"
-			    " address 0x%lx\n", curaddr);
-			panic("_bus_dmamem_alloc");
-		}
-#endif
-		if (curaddr == (lastaddr + PAGE_SIZE))
-			segs[curseg].ds_len += PAGE_SIZE;
-		else {
-			curseg++;
-			segs[curseg].ds_addr = curaddr;
-			segs[curseg].ds_len = PAGE_SIZE;
-		}
-		lastaddr = curaddr;
-	}
-
-	*rsegs = curseg + 1;
-
-	return 0;
+	return (_bus_dmamem_alloc_range_common(t, size, alignment, boundary,
+					       segs, nsegs, rsegs, flags,
+					       avail_start /*low*/,
+					       avail_end - PAGE_SIZE /*high*/));
 }
 
 /*
@@ -538,25 +494,8 @@
 void
 _bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs)
 {
-	struct vm_page *m;
-	bus_addr_t addr;
-	struct pglist mlist;
-	int curseg;
 
-	/*
-	 * Build a list of pages to free back to the VM system.
-	 */
-	TAILQ_INIT(&mlist);
-	for (curseg = 0; curseg < nsegs; curseg++) {
-		for (addr = segs[curseg].ds_addr;
-		    addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
-		    addr += PAGE_SIZE) {
-			m = PHYS_TO_VM_PAGE(addr);
-			TAILQ_INSERT_TAIL(&mlist, m, pageq.queue);
-		}
-	}
-
-	uvm_pglistfree(&mlist);
+	_bus_dmamem_free_common(t, segs, nsegs);
 }
 
 /*
@@ -567,11 +506,6 @@
 _bus_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
     size_t size, void **kvap, int flags)
 {
-	vaddr_t va;
-	bus_addr_t addr;
-	int curseg;
-	const uvm_flag_t kmflags =
-	    (flags & BUS_DMA_NOWAIT) != 0 ? UVM_KMF_NOWAIT : 0;
 
 	/*
 	 * If we're only mapping 1 segment, use KSEG0 or KSEG1, to avoid
@@ -585,31 +519,8 @@
 		return 0;
 	}
 
-	size = round_page(size);
-
-	va = uvm_km_alloc(kernel_map, size, 0, UVM_KMF_VAONLY | kmflags);
-
-	if (va == 0)
-		return (ENOMEM);
-
-	*kvap = (void *)va;
-
-	for (curseg = 0; curseg < nsegs; curseg++) {
-		for (addr = segs[curseg].ds_addr;
-		    addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
-		    addr += PAGE_SIZE, va += PAGE_SIZE, size -= PAGE_SIZE) {
-			if (size == 0)
-				panic("_bus_dmamem_map: size botch");
-			pmap_enter(pmap_kernel(), va, addr,
-			    VM_PROT_READ | VM_PROT_WRITE,
-			    VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED);
-
-			/* XXX Do something about COHERENT here. */
-		}
-	}
-	pmap_update(pmap_kernel());
-
-	return 0;
+	/* XXX BUS_DMA_COHERENT */
+	return (_bus_dmamem_map_common(t, segs, nsegs, size, kvap, flags, 0));
 }
 
 /*
@@ -620,11 +531,6 @@
 _bus_dmamem_unmap(bus_dma_tag_t t, void *kva, size_t size)
 {
 
-#ifdef DIAGNOSTIC
-	if ((u_long)kva & PGOFSET)
-		panic("_bus_dmamem_unmap");
-#endif
-
 	/*
 	 * Nothing to do if we mapped it with KSEG0 or KSEG1 (i.e.
 	 * not in KSEG2).
@@ -633,10 +539,7 @@
 	    kva < (void *)MIPS_KSEG2_START)
 		return;
 
-	size = round_page(size);
-	pmap_remove(pmap_kernel(), (vaddr_t)kva, (vaddr_t)kva + size);
-	pmap_update(pmap_kernel());
-	uvm_km_free(kernel_map, (vaddr_t)kva, size, UVM_KMF_VAONLY);
+	_bus_dmamem_unmap_common(t, kva, size);
 }
 
 /*
@@ -647,26 +550,11 @@
 _bus_dmamem_mmap(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
     off_t off, int prot, int flags)
 {
-	int i;
+	bus_addr_t rv;
 
-	for (i = 0; i < nsegs; i++) {
-#ifdef DIAGNOSTIC
-		if (off & PGOFSET)
-			panic("_bus_dmamem_mmap: offset unaligned");
-		if (segs[i].ds_addr & PGOFSET)
-			panic("_bus_dmamem_mmap: segment unaligned");
-		if (segs[i].ds_len & PGOFSET)
-			panic("_bus_dmamem_mmap: segment size not multiple"
-			    " of page size");
-#endif
-		if (off >= segs[i].ds_len) {
-			off -= segs[i].ds_len;
-			continue;
-		}
-
-		return mips_btop((void *)segs[i].ds_addr + off);
-	}
-
-	/* Page not found. */
-	return -1;
+	rv = _bus_dmamem_mmap_common(t, segs, nsegs, off, prot, flags);
+	if (rv == (bus_addr_t)-1)
+		return (-1);
+	
+	return (mips_btop((char *)rv));
 }
--- a/sys/arch/pmax/conf/files.pmax	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/pmax/conf/files.pmax	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.pmax,v 1.111 2008/02/20 21:43:35 drochner Exp $
+#	$NetBSD: files.pmax,v 1.111.10.1 2009/09/16 13:37:42 yamt Exp $
 # DECstation-specific configuration info
 
 # maxpartitions must be first item in files.${ARCH}.
@@ -122,6 +122,8 @@
 file	arch/pmax/stand/common/callvec.c
 file	dev/cons.c
 
+file	common/bus_dma/bus_dmamem_common.c
+
 file arch/mips/mips/softintr.c
 
 #
--- a/sys/arch/pmax/include/loadfile_machdep.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/pmax/include/loadfile_machdep.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: loadfile_machdep.h,v 1.5.76.1 2008/05/16 02:22:59 yamt Exp $	 */
+/*	$NetBSD: loadfile_machdep.h,v 1.5.76.2 2009/09/16 13:37:42 yamt Exp $	 */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -32,7 +32,6 @@
 #ifndef _PMAX_LOADFILE_MACHDEP_H_
 #define _PMAX_LOADFILE_MACHDEP_H_
 
-#define BOOT_AOUT
 #define BOOT_ECOFF
 #define BOOT_ELF32
 
--- a/sys/arch/pmax/pmax/bus_dma.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/pmax/pmax/bus_dma.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus_dma.c,v 1.47.44.3 2009/08/19 18:46:38 yamt Exp $	*/
+/*	$NetBSD: bus_dma.c,v 1.47.44.4 2009/09/16 13:37:42 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.47.44.3 2009/08/19 18:46:38 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.47.44.4 2009/09/16 13:37:42 yamt Exp $");
 
 #include "opt_cputype.h"
 
@@ -45,6 +45,8 @@
 #define _PMAX_BUS_DMA_PRIVATE
 #include <machine/bus.h>
 
+#include <common/bus_dma/bus_dmamem_common.h>
+
 #include <mips/cache.h>
 
 static int	_bus_dmamap_load_buffer(bus_dmamap_t,
@@ -655,57 +657,11 @@
     int flags)
 {
 	extern paddr_t avail_start, avail_end;		/* XXX */
-	vaddr_t curaddr, lastaddr;
-	psize_t high;
-	struct vm_page *m;
-	struct pglist mlist;
-	int curseg, error;
 
-	/* Always round the size. */
-	size = round_page(size);
-
-	high = avail_end - PAGE_SIZE;
-
-	/*
-	 * Allocate pages from the VM system.
-	 */
-	error = uvm_pglistalloc(size, avail_start, high, alignment, boundary,
-	    &mlist, nsegs, (flags & BUS_DMA_NOWAIT) == 0);
-	if (error)
-		return (error);
-
-	/*
-	 * Compute the location, size, and number of segments actually
-	 * returned by the VM code.
-	 */
-	m = mlist.tqh_first;
-	curseg = 0;
-	lastaddr = segs[curseg].ds_addr = VM_PAGE_TO_PHYS(m);
-	segs[curseg].ds_len = PAGE_SIZE;
-	m = m->pageq.queue.tqe_next;
-
-	for (; m != NULL; m = m->pageq.queue.tqe_next) {
-		curaddr = VM_PAGE_TO_PHYS(m);
-#ifdef DIAGNOSTIC
-		if (curaddr < avail_start || curaddr >= high) {
-			printf("uvm_pglistalloc returned non-sensical"
-			    " address 0x%lx\n", curaddr);
-			panic("_bus_dmamem_alloc");
-		}
-#endif
-		if (curaddr == (lastaddr + PAGE_SIZE))
-			segs[curseg].ds_len += PAGE_SIZE;
-		else {
-			curseg++;
-			segs[curseg].ds_addr = curaddr;
-			segs[curseg].ds_len = PAGE_SIZE;
-		}
-		lastaddr = curaddr;
-	}
-
-	*rsegs = curseg + 1;
-
-	return 0;
+	return (_bus_dmamem_alloc_range_common(t, size, alignment, boundary,
+					       segs, nsegs, rsegs, flags,
+					       avail_start /*low*/,
+					       avail_end - PAGE_SIZE /*high*/));
 }
 
 /*
@@ -715,25 +671,8 @@
 void
 _bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs)
 {
-	struct vm_page *m;
-	bus_addr_t addr;
-	struct pglist mlist;
-	int curseg;
 
-	/*
-	 * Build a list of pages to free back to the VM system.
-	 */
-	TAILQ_INIT(&mlist);
-	for (curseg = 0; curseg < nsegs; curseg++) {
-		for (addr = segs[curseg].ds_addr;
-		    addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
-		    addr += PAGE_SIZE) {
-			m = PHYS_TO_VM_PAGE(addr);
-			TAILQ_INSERT_TAIL(&mlist, m, pageq.queue);
-		}
-	}
-
-	uvm_pglistfree(&mlist);
+	_bus_dmamem_free_common(t, segs, nsegs);
 }
 
 /*
@@ -744,11 +683,6 @@
 _bus_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
     size_t size, void **kvap, int flags)
 {
-	vaddr_t va;
-	bus_addr_t addr;
-	int curseg;
-	const uvm_flag_t kmflags =
-	    (flags & BUS_DMA_NOWAIT) != 0 ? UVM_KMF_NOWAIT : 0;
 
 	/*
 	 * If we're only mapping 1 segment, use KSEG0 or KSEG1, to avoid
@@ -762,31 +696,7 @@
 		return 0;
 	}
 
-	size = round_page(size);
-
-	va = uvm_km_alloc(kernel_map, size, 0, UVM_KMF_VAONLY | kmflags);
-
-	if (va == 0)
-		return ENOMEM;
-
-	*kvap = (void *)va;
-
-	for (curseg = 0; curseg < nsegs; curseg++) {
-		for (addr = segs[curseg].ds_addr;
-		    addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
-		    addr += PAGE_SIZE, va += PAGE_SIZE, size -= PAGE_SIZE) {
-			if (size == 0)
-				panic("_bus_dmamem_map: size botch");
-			pmap_enter(pmap_kernel(), va, addr,
-			    VM_PROT_READ | VM_PROT_WRITE,
-			    VM_PROT_READ | VM_PROT_WRITE | PMAP_WIRED);
-
-			/* XXX Do something about COHERENT here. */
-		}
-	}
-	pmap_update(pmap_kernel());
-
-	return 0;
+	return (_bus_dmamem_map_common(t, segs, nsegs, size, kvap, flags, 0));
 }
 
 /*
@@ -797,11 +707,6 @@
 _bus_dmamem_unmap(bus_dma_tag_t t, void *kva, size_t size)
 {
 
-#ifdef DIAGNOSTIC
-	if ((u_long)kva & PGOFSET)
-		panic("_bus_dmamem_unmap");
-#endif
-
 	/*
 	 * Nothing to do if we mapped it with KSEG0 or KSEG1 (i.e.
 	 * not in KSEG2).
@@ -810,10 +715,7 @@
 	    kva < (void *)MIPS_KSEG2_START)
 		return;
 
-	size = round_page(size);
-	pmap_remove(pmap_kernel(), (vaddr_t)kva, (vaddr_t)kva + size);
-	pmap_update(pmap_kernel());
-	uvm_km_free(kernel_map, (vaddr_t)kva, size, UVM_KMF_VAONLY);
+	_bus_dmamem_unmap_common(t, kva, size);
 }
 
 /*
@@ -824,26 +726,11 @@
 _bus_dmamem_mmap(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs, off_t off,
     int prot, int flags)
 {
-	int i;
+	bus_addr_t rv;
 
-	for (i = 0; i < nsegs; i++) {
-#ifdef DIAGNOSTIC
-		if (off & PGOFSET)
-			panic("_bus_dmamem_mmap: offset unaligned");
-		if (segs[i].ds_addr & PGOFSET)
-			panic("_bus_dmamem_mmap: segment unaligned");
-		if (segs[i].ds_len & PGOFSET)
-			panic("_bus_dmamem_mmap: segment size not multiple"
-			    " of page size");
-#endif
-		if (off >= segs[i].ds_len) {
-			off -= segs[i].ds_len;
-			continue;
-		}
-
-		return mips_btop(segs[i].ds_addr + off);
-	}
-
-	/* Page not found. */
-	return -1;
+	rv = _bus_dmamem_mmap_common(t, segs, nsegs, off, prot, flags);
+	if (rv == (bus_addr_t)-1)
+		return (-1);
+	
+	return (mips_btop((char *)rv));
 }
--- a/sys/arch/powerpc/include/isa_machdep.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/powerpc/include/isa_machdep.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: isa_machdep.h,v 1.3.20.2 2009/08/19 18:46:40 yamt Exp $	*/
+/*	$NetBSD: isa_machdep.h,v 1.3.20.3 2009/09/16 13:37:42 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -101,6 +101,7 @@
  */
 void	genppc_isa_attach_hook(struct device *, struct device *,
 	    struct isabus_attach_args *);
+void	genppc_isa_detach_hook(isa_chipset_tag_t, device_t);
 const struct evcnt *genppc_isa_intr_evcnt(isa_chipset_tag_t, int);
 void	*genppc_isa_intr_establish(isa_chipset_tag_t, int /*irq*/, int /*type*/,
 	    int /*level*/, int (*ih_fun)(void *), void *);
--- a/sys/arch/sgimips/conf/files.sgimips	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/sgimips/conf/files.sgimips	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: files.sgimips,v 1.47.10.1 2009/05/04 08:11:48 yamt Exp $
+#	$NetBSD: files.sgimips,v 1.47.10.2 2009/09/16 13:37:42 yamt Exp $
 
 maxpartitions 16
 
@@ -25,6 +25,8 @@
 file arch/sgimips/sgimips/disksubr.c
 file arch/sgimips/sgimips/machdep.c
 
+file common/bus_dma/bus_dmamem_common.c
+
 file arch/mips/mips/mips3_clock.c	mips3
 file arch/mips/mips/mips3_clockintr.c	mips3
 
--- a/sys/arch/sgimips/include/loadfile_machdep.h	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/sgimips/include/loadfile_machdep.h	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: loadfile_machdep.h,v 1.5.20.1 2008/05/16 02:23:05 yamt Exp $	 */
+/*	$NetBSD: loadfile_machdep.h,v 1.5.20.2 2009/09/16 13:37:42 yamt Exp $	 */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -32,7 +32,6 @@
 #ifndef _SGIMIPS_LOADFILE_MACHDEP_H_
 #define _SGIMIPS_LOADFILE_MACHDEP_H_
 
-#define BOOT_AOUT
 #define BOOT_ECOFF
 #define BOOT_ELF32
 
--- a/sys/arch/sgimips/mace/if_mec.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/sgimips/mace/if_mec.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_mec.c,v 1.18.4.3 2009/05/16 10:41:16 yamt Exp $ */
+/* $NetBSD: if_mec.c,v 1.18.4.4 2009/09/16 13:37:42 yamt Exp $ */
 
 /*-
  * Copyright (c) 2004, 2008 Izumi Tsutsui.  All rights reserved.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_mec.c,v 1.18.4.3 2009/05/16 10:41:16 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_mec.c,v 1.18.4.4 2009/09/16 13:37:42 yamt Exp $");
 
 #include "opt_ddb.h"
 #include "bpfilter.h"
@@ -293,7 +293,6 @@
 	bus_space_tag_t sc_st;		/* bus_space tag */
 	bus_space_handle_t sc_sh;	/* bus_space handle */
 	bus_dma_tag_t sc_dmat;		/* bus_dma tag */
-	void *sc_sdhook;		/* shutdown hook */
 
 	struct ethercom sc_ethercom;	/* Ethernet common part */
 
@@ -416,7 +415,7 @@
 static void	mec_rxcsum(struct mec_softc *, struct mbuf *, uint16_t,
 		    uint32_t);
 static void	mec_txintr(struct mec_softc *, uint32_t);
-static void	mec_shutdown(void *);
+static bool	mec_shutdown(device_t, int);
 
 CFATTACH_DECL_NEW(mec, sizeof(struct mec_softc),
     mec_match, mec_attach, NULL, NULL);
@@ -727,7 +726,10 @@
 #endif
 
 	/* set shutdown hook to reset interface on powerdown */
-	sc->sc_sdhook = shutdownhook_establish(mec_shutdown, sc);
+	if (pmf_device_register1(self, NULL, NULL, mec_shutdown))
+		pmf_class_network_register(self, ifp);
+	else
+		aprint_error_dev(self, "couldn't establish power handler\n");
 
 	return;
 
@@ -1952,12 +1954,14 @@
 		ifp->if_flags &= ~IFF_OACTIVE;
 }
 
-static void
-mec_shutdown(void *arg)
+static bool
+mec_shutdown(device_t self, int howto)
 {
-	struct mec_softc *sc = arg;
+	struct mec_softc *sc = device_private(self);
 
 	mec_stop(&sc->sc_ethercom.ec_if, 1);
 	/* make sure to stop DMA etc. */
 	mec_reset(sc);
+
+	return true;
 }
--- a/sys/arch/sgimips/sgimips/bus.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/sgimips/sgimips/bus.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus.c,v 1.53.10.2 2009/05/04 08:11:50 yamt Exp $	*/
+/*	$NetBSD: bus.c,v 1.53.10.3 2009/09/16 13:37:42 yamt Exp $	*/
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus.c,v 1.53.10.2 2009/05/04 08:11:50 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus.c,v 1.53.10.3 2009/09/16 13:37:42 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -48,6 +48,8 @@
 #include <machine/cpu.h>
 #include <machine/machtype.h>
 
+#include <common/bus_dma/bus_dmamem_common.h>
+
 #include <uvm/uvm_extern.h>
 
 #include <mips/cpuregs.h>
@@ -1082,57 +1084,11 @@
 		  int nsegs, int *rsegs, int flags)
 {
 	extern paddr_t avail_start, avail_end;
-	vaddr_t curaddr, lastaddr;
-	psize_t high;
-	struct vm_page *m;
-	struct pglist mlist;
-	int curseg, error;
 
-	/* Always round the size. */
-	size = round_page(size);
-
-	high = avail_end - PAGE_SIZE;
-
-	/*
-	 * Allocate pages from the VM system.
-	 */
-	error = uvm_pglistalloc(size, avail_start, high, alignment, boundary,
-	    &mlist, nsegs, (flags & BUS_DMA_NOWAIT) == 0);
-	if (error)
-		return error;
-
-	/*
-	 * Compute the location, size, and number of segments actually
-	 * returned by the VM code.
-	 */
-	m = mlist.tqh_first;
-	curseg = 0;
-	lastaddr = segs[curseg].ds_addr = VM_PAGE_TO_PHYS(m);
-	segs[curseg].ds_len = PAGE_SIZE;
-	m = m->pageq.queue.tqe_next;
-
-	for (; m != NULL; m = m->pageq.queue.tqe_next) {
-		curaddr = VM_PAGE_TO_PHYS(m);
-#ifdef DIAGNOSTIC
-		if (curaddr < avail_start || curaddr >= high) {
-			printf("uvm_pglistalloc returned non-sensical"
-			    " address 0x%lx\n", curaddr);
-			panic("_bus_dmamem_alloc");
-		}
-#endif
-		if (curaddr == (lastaddr + PAGE_SIZE))
-			segs[curseg].ds_len += PAGE_SIZE;
-		else {
-			curseg++;
-			segs[curseg].ds_addr = curaddr;
-			segs[curseg].ds_len = PAGE_SIZE;
-		}
-		lastaddr = curaddr;
-	}
-
-	*rsegs = curseg + 1;
-
-	return 0;
+	return (_bus_dmamem_alloc_range_common(t, size, alignment, boundary,
+					       segs, nsegs, rsegs, flags,
+					       avail_start /*low*/,
+					       avail_end - PAGE_SIZE /*high*/));
 }
 
 /*
@@ -1142,25 +1098,8 @@
 void
 _bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs)
 {
-	struct vm_page *m;
-	bus_addr_t addr;
-	struct pglist mlist;
-	int curseg;
 
-	/*
-	 * Build a list of pages to free back to the VM system.
-	 */
-	TAILQ_INIT(&mlist);
-	for (curseg = 0; curseg < nsegs; curseg++) {
-		for (addr = segs[curseg].ds_addr;
-		    addr < (segs[curseg].ds_addr + segs[curseg].ds_len);
-		    addr += PAGE_SIZE) {
-			m = PHYS_TO_VM_PAGE(addr);
-			TAILQ_INSERT_TAIL(&mlist, m, pageq.queue);
-		}
-	}
-
-	uvm_pglistfree(&mlist);
+	_bus_dmamem_free_common(t, segs, nsegs);
 }
 
 /*
@@ -1229,11 +1168,6 @@
 _bus_dmamem_unmap(bus_dma_tag_t t, void *kva, size_t size)
 {
 
-#ifdef DIAGNOSTIC
-	if ((u_long)kva & PGOFSET)
-		panic("_bus_dmamem_unmap");
-#endif
-
 	/*
 	 * Nothing to do if we mapped it with KSEG0 or KSEG1 (i.e.
 	 * not in KSEG2).
@@ -1242,10 +1176,7 @@
 	    kva < (void *)MIPS_KSEG2_START)
 		return;
 
-	size = round_page(size);
-	pmap_remove(pmap_kernel(), (vaddr_t)kva, (vaddr_t)kva + size);
-	pmap_update(pmap_kernel());
-	uvm_km_free(kernel_map, (vaddr_t)kva, size, UVM_KMF_VAONLY);
+	_bus_dmamem_unmap_common(t, kva, size);
 }
 
 /*
@@ -1256,32 +1187,17 @@
 _bus_dmamem_mmap(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs,
 		 off_t off, int prot, int flags)
 {
-	int i;
+	bus_addr_t rv;
 
-	for (i = 0; i < nsegs; i++) {
-#ifdef DIAGNOSTIC
-		if (off & PGOFSET)
-			panic("_bus_dmamem_mmap: offset unaligned");
-		if (segs[i].ds_addr & PGOFSET)
-			panic("_bus_dmamem_mmap: segment unaligned");
-		if (segs[i].ds_len & PGOFSET)
-			panic("_bus_dmamem_mmap: segment size not multiple"
-			    " of page size");
+	rv = _bus_dmamem_mmap_common(t, segs, nsegs, off, prot, flags);
+	if (rv == (bus_addr_t)-1)
+		return (-1);
+	
+#if defined(_MIPS_PADDR_T_64BIT) || defined(_LP64)
+	return (mips_btop(rv | PMAP_NOCACHE));
+#else
+	return (mips_btop(rv));
 #endif
-		if (off >= segs[i].ds_len) {
-			off -= segs[i].ds_len;
-			continue;
-		}
-
-#if defined(_MIPS_PADDR_T_64BIT) || defined(_LP64)
-		return mips_btop((segs[i].ds_addr + off) | PMAP_NOCACHE);
-#else
-		return mips_btop(segs[i].ds_addr + off);
-#endif
-	}
-
-	/* Page not found. */
-	return -1;
 }
 
 paddr_t
--- a/sys/arch/shark/conf/Makefile.shark.inc	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/shark/conf/Makefile.shark.inc	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.shark.inc,v 1.10.10.1 2009/05/04 08:11:53 yamt Exp $
+#	$NetBSD: Makefile.shark.inc,v 1.10.10.2 2009/09/16 13:37:42 yamt Exp $
 
 MACHINE_ARCH=		arm
 CPPFLAGS+=		-D${MACHINE}
@@ -22,13 +22,13 @@
 		-R .ident -R .arm.atpcs -R .comment -R .note.netbsd.ident \
 		-R .debug_abbrev -R .debug_info -R .debug_line -R .debug_str \
 		-R .debug_frame -R .debug_loc -R .debug_pubnames \
-		-R .debug_aranges \
+		-R .debug_aranges -R .ARM.attributes \
 		$@ $@.aout"; \
 	${OBJCOPY} -O a.out-arm-netbsd \
 		-R .ident -R .arm.atpcs -R .comment -R .note.netbsd.ident \
 		-R .debug_abbrev -R .debug_info -R .debug_line -R .debug_str \
 		-R .debug_frame -R .debug_loc -R .debug_pubnames \
-		-R .debug_aranges \
+		-R .debug_aranges -R .ARM.attributes \
 		$@ $@.aout
 
 KERNIMAGES=	netbsd netbsd.aout
--- a/sys/arch/sparc/dev/cgfourteen.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/sparc/dev/cgfourteen.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: cgfourteen.c,v 1.52.20.3 2009/07/18 14:52:55 yamt Exp $ */
+/*	$NetBSD: cgfourteen.c,v 1.52.20.4 2009/09/16 13:37:42 yamt Exp $ */
 
 /*
  * Copyright (c) 1996
@@ -834,6 +834,7 @@
 		sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
 		wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
 		    defattr);
+		vcons_replay_msgbuf(&sc->sc_console_screen);
 	} else {
 		/*
 		 * since we're not the console we can postpone the rest
--- a/sys/arch/sparc/sparc/pmap.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/sparc/sparc/pmap.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.322.10.3 2009/08/19 18:46:47 yamt Exp $ */
+/*	$NetBSD: pmap.c,v 1.322.10.4 2009/09/16 13:37:43 yamt Exp $ */
 
 /*
  * Copyright (c) 1996
@@ -56,7 +56,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.322.10.3 2009/08/19 18:46:47 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.322.10.4 2009/09/16 13:37:43 yamt Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -3467,6 +3467,7 @@
 			setpte4(p, getpte4(p) & ~PG_NC);
 
 	}
+	cpus[0] = (struct cpu_info *)CPUINFO_VA;
 }
 #endif
 
--- a/sys/arch/sparc/stand/bootxx/bootxx.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/sparc/stand/bootxx/bootxx.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bootxx.c,v 1.19.44.2 2009/05/04 08:11:56 yamt Exp $ */
+/*	$NetBSD: bootxx.c,v 1.19.44.3 2009/09/16 13:37:43 yamt Exp $ */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,6 +31,7 @@
 
 #include <sys/param.h>
 #include <sys/exec.h>
+#include <sys/exec_aout.h>
 #include <sys/bootblock.h>
 
 #include <lib/libkern/libkern.h>
--- a/sys/arch/sparc64/dev/ffb.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/sparc64/dev/ffb.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffb.c,v 1.33.4.1 2009/05/04 08:11:57 yamt Exp $	*/
+/*	$NetBSD: ffb.c,v 1.33.4.2 2009/09/16 13:37:43 yamt Exp $	*/
 /*	$OpenBSD: creator.c,v 1.20 2002/07/30 19:48:15 jason Exp $	*/
 
 /*
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ffb.c,v 1.33.4.1 2009/05/04 08:11:57 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffb.c,v 1.33.4.2 2009/09/16 13:37:43 yamt Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -239,11 +239,12 @@
 	sc->sc_fb.fb_device = &sc->sc_dv;
 	fb_attach(&sc->sc_fb, sc->sc_console);
 
+	ffb_clearscreen(sc);
+
 	if (sc->sc_console) {
 		wsdisplay_cnattach(&ffb_stdscreen, ri, 0, 0, defattr);
+		vcons_replay_msgbuf(&ffb_console_screen);
 	}
-
-	ffb_clearscreen(sc);
 	
 	waa.console = sc->sc_console;
 	waa.scrdata = &ffb_screenlist;
@@ -433,7 +434,6 @@
 		break;
 #endif
 	}
-
 	return (-1);
 }
 
--- a/sys/arch/vax/vax/clock.c	Wed Aug 19 18:45:51 2009 +0000
+++ b/sys/arch/vax/vax/clock.c	Wed Sep 16 13:37:34 2009 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.49.10.1 2009/05/04 08:12:04 yamt Exp $	 */
+/*	$NetBSD: clock.c,v 1.49.10.2 2009/09/16 13:37:43 yamt Exp $	 */
 /*
  * Copyright (c) 1995 Ludd, University of Lule}, Sweden.
  * All rights reserved.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.49.10.1 2009/05/04 08:12:04 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.49.10.2 2009/09/16 13:37:43 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -83,13 +83,31 @@
 {
 	int cur_hardclock;
 	u_int counter;
+	static int prev_count, prev_hardclock;
 
 	do {
 		cur_hardclock = hardclock_ticks;
-		counter = mfpr(PR_ICR);
+		counter = mfpr(PR_ICR) + tick;
 	} while (cur_hardclock != hardclock_ticks);
 
-	return counter + hardclock_ticks * tick;
+	/*
+	 * Handle interval counter wrapping with interrupts blocked.
+	 * If the current hardclock_ticks is less than what we saw
+	 *   previously, use the previous value.
+	 * If the interval counter is smaller, assume it has wrapped,
+	 *   and if the [adjusted] current hardclock ticks is the same
+	 *   as what we saw previously, increment the local copy of
+	 *   the hardclock ticks.
+	 */
+	if (cur_hardclock < prev_hardclock)
+		cur_hardclock = prev_hardclock;
+	if (counter < prev_count && cur_hardclock == prev_hardclock)
+		cur_hardclock++;
+
+	prev_count = counter;
+	prev_hardclock=cur_hardclock;
+