ia64/xen-unstable

changeset 6550:112d44270733

Merge.
author adsharma@los-vmm.sc.intel.com
date Thu Aug 25 11:18:47 2005 -0700 (2005-08-25)
parents e2025593f702 b4b3f6be5226
children a9873d384da4
files .hgignore Config.mk Makefile buildconfigs/Rules.mk buildconfigs/mk.linux-2.6-xen buildconfigs/mk.linux-2.6-xen0 buildconfigs/mk.linux-2.6-xenU docs/src/user.tex extras/mini-os/include/hypervisor.h extras/mini-os/include/mm.h extras/mini-os/include/time.h extras/mini-os/kernel.c extras/mini-os/mm.c extras/mini-os/time.c linux-2.4-xen-sparse/arch/xen/Makefile linux-2.4-xen-sparse/arch/xen/config.in linux-2.4-xen-sparse/arch/xen/kernel/time.c linux-2.4-xen-sparse/include/asm-xen/bugs.h linux-2.4-xen-sparse/include/asm-xen/fixmap.h linux-2.4-xen-sparse/include/asm-xen/highmem.h linux-2.4-xen-sparse/include/asm-xen/hw_irq.h linux-2.4-xen-sparse/include/asm-xen/io.h linux-2.4-xen-sparse/include/asm-xen/irq.h linux-2.4-xen-sparse/include/asm-xen/mmu_context.h linux-2.4-xen-sparse/include/asm-xen/page.h linux-2.4-xen-sparse/include/asm-xen/pci.h linux-2.4-xen-sparse/include/asm-xen/pgalloc.h linux-2.4-xen-sparse/include/asm-xen/pgtable.h linux-2.4-xen-sparse/include/asm-xen/processor.h linux-2.4-xen-sparse/include/asm-xen/segment.h linux-2.4-xen-sparse/include/asm-xen/smp.h linux-2.4-xen-sparse/include/asm-xen/system.h linux-2.4-xen-sparse/include/asm-xen/vga.h linux-2.4-xen-sparse/include/linux/blk.h linux-2.4-xen-sparse/include/linux/highmem.h linux-2.4-xen-sparse/include/linux/irq.h linux-2.4-xen-sparse/include/linux/mm.h linux-2.4-xen-sparse/include/linux/sched.h linux-2.4-xen-sparse/include/linux/skbuff.h linux-2.4-xen-sparse/include/linux/timer.h linux-2.4-xen-sparse/mkbuildtree linux-2.6-xen-sparse/arch/xen/Kconfig linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_32 linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_64 linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_32 linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_64 linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_32 linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_64 linux-2.6-xen-sparse/arch/xen/i386/Kconfig linux-2.6-xen-sparse/arch/xen/i386/kernel/Makefile linux-2.6-xen-sparse/arch/xen/i386/kernel/cpu/common.c linux-2.6-xen-sparse/arch/xen/i386/kernel/entry.S linux-2.6-xen-sparse/arch/xen/i386/kernel/head.S linux-2.6-xen-sparse/arch/xen/i386/kernel/i386_ksyms.c linux-2.6-xen-sparse/arch/xen/i386/kernel/init_task.c linux-2.6-xen-sparse/arch/xen/i386/kernel/ioport.c linux-2.6-xen-sparse/arch/xen/i386/kernel/irq.c linux-2.6-xen-sparse/arch/xen/i386/kernel/ldt.c linux-2.6-xen-sparse/arch/xen/i386/kernel/mpparse.c linux-2.6-xen-sparse/arch/xen/i386/kernel/pci-dma.c linux-2.6-xen-sparse/arch/xen/i386/kernel/process.c linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c linux-2.6-xen-sparse/arch/xen/i386/kernel/smp.c linux-2.6-xen-sparse/arch/xen/i386/kernel/smpboot.c linux-2.6-xen-sparse/arch/xen/i386/kernel/swiotlb.c linux-2.6-xen-sparse/arch/xen/i386/kernel/time.c linux-2.6-xen-sparse/arch/xen/i386/kernel/traps.c linux-2.6-xen-sparse/arch/xen/i386/mm/fault.c linux-2.6-xen-sparse/arch/xen/i386/mm/highmem.c linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c linux-2.6-xen-sparse/arch/xen/i386/mm/init.c linux-2.6-xen-sparse/arch/xen/i386/mm/ioremap.c linux-2.6-xen-sparse/arch/xen/i386/mm/pgtable.c linux-2.6-xen-sparse/arch/xen/i386/pci/Makefile linux-2.6-xen-sparse/arch/xen/i386/pci/irq.c linux-2.6-xen-sparse/arch/xen/kernel/evtchn.c linux-2.6-xen-sparse/arch/xen/kernel/gnttab.c linux-2.6-xen-sparse/arch/xen/kernel/reboot.c linux-2.6-xen-sparse/arch/xen/kernel/skbuff.c linux-2.6-xen-sparse/arch/xen/x86_64/Kconfig linux-2.6-xen-sparse/arch/xen/x86_64/Makefile linux-2.6-xen-sparse/arch/xen/x86_64/ia32/Makefile linux-2.6-xen-sparse/arch/xen/x86_64/ia32/syscall32.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/Makefile linux-2.6-xen-sparse/arch/xen/x86_64/kernel/apic.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/e820.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/early_printk.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/entry.S linux-2.6-xen-sparse/arch/xen/x86_64/kernel/genapic.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/genapic_xen.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/head.S linux-2.6-xen-sparse/arch/xen/x86_64/kernel/head64.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/ioport.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/irq.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/pci-nommu.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/process.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup64.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/smp.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/smpboot.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/traps.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/vsyscall.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/xen_entry.S linux-2.6-xen-sparse/arch/xen/x86_64/mm/Makefile linux-2.6-xen-sparse/arch/xen/x86_64/mm/fault.c linux-2.6-xen-sparse/arch/xen/x86_64/mm/init.c linux-2.6-xen-sparse/arch/xen/x86_64/pci/Makefile linux-2.6-xen-sparse/drivers/xen/Makefile linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c linux-2.6-xen-sparse/drivers/xen/blkback/Makefile linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c linux-2.6-xen-sparse/drivers/xen/blkback/common.h linux-2.6-xen-sparse/drivers/xen/blkback/interface.c linux-2.6-xen-sparse/drivers/xen/blkback/vbd.c linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c linux-2.6-xen-sparse/drivers/xen/blkfront/block.h linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c linux-2.6-xen-sparse/drivers/xen/blktap/blktap.h linux-2.6-xen-sparse/drivers/xen/blktap/blktap_controlmsg.c linux-2.6-xen-sparse/drivers/xen/blktap/blktap_datapath.c linux-2.6-xen-sparse/drivers/xen/blktap/blktap_userdev.c linux-2.6-xen-sparse/drivers/xen/console/console.c linux-2.6-xen-sparse/drivers/xen/netback/Makefile linux-2.6-xen-sparse/drivers/xen/netback/common.h linux-2.6-xen-sparse/drivers/xen/netback/interface.c linux-2.6-xen-sparse/drivers/xen/netback/netback.c linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c linux-2.6-xen-sparse/drivers/xen/usbback/common.h linux-2.6-xen-sparse/drivers/xen/usbback/interface.c linux-2.6-xen-sparse/drivers/xen/usbback/usbback.c linux-2.6-xen-sparse/drivers/xen/usbfront/usbfront.c linux-2.6-xen-sparse/drivers/xen/usbfront/xhci.h linux-2.6-xen-sparse/drivers/xen/xenbus/Makefile linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.h linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c linux-2.6-xen-sparse/include/asm-generic/pgtable.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/desc.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/dma-mapping.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/fixmap.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/hypercall.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/io.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/kmap_types.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/mach-xen/irq_vectors.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/mach-xen/setup_arch_post.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/mmu_context.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/pci.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgalloc.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgtable-2level.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgtable-3level.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgtable.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/scatterlist.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/swiotlb.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/desc.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/dma-mapping.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/hypercall.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/io.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/mach-xen/irq_vectors.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/page.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/pci.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/pgtable.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/processor.h linux-2.6-xen-sparse/include/asm-xen/balloon.h linux-2.6-xen-sparse/include/asm-xen/ctrl_if.h linux-2.6-xen-sparse/include/asm-xen/evtchn.h linux-2.6-xen-sparse/include/asm-xen/gnttab.h linux-2.6-xen-sparse/include/asm-xen/hypervisor.h linux-2.6-xen-sparse/include/asm-xen/xenbus.h linux-2.6-xen-sparse/include/linux/highmem.h linux-2.6-xen-sparse/include/linux/mm.h linux-2.6-xen-sparse/kernel/irq/manage.c linux-2.6-xen-sparse/mkbuildtree linux-2.6-xen-sparse/mm/highmem.c linux-2.6-xen-sparse/mm/memory.c patches/linux-2.6.12/patch-2.6.12.5 patches/linux-2.6.12/smp-alts.patch tools/Makefile tools/Rules.mk tools/blktap/blktaplib.c tools/blktap/blktaplib.h tools/blktap/parallax/block-async.h tools/blktap/parallax/blockstore.h tools/console/Makefile tools/console/client/main.c tools/console/daemon/io.c tools/console/daemon/main.c tools/console/daemon/utils.c tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c tools/debugger/gdb/gdbbuild tools/debugger/libxendebug/Makefile tools/debugger/libxendebug/xendebug.c tools/debugger/libxendebug/xendebug.h tools/debugger/pdb/Domain.ml tools/debugger/pdb/Domain.mli tools/debugger/pdb/Makefile tools/debugger/pdb/PDB.ml tools/debugger/pdb/Process.ml tools/debugger/pdb/Process.mli tools/debugger/pdb/Util.ml tools/debugger/pdb/Xen_domain.ml tools/debugger/pdb/Xen_domain.mli tools/debugger/pdb/debugger.ml tools/debugger/pdb/linux-2.6-module/Makefile tools/debugger/pdb/linux-2.6-module/debug.c tools/debugger/pdb/linux-2.6-module/module.c tools/debugger/pdb/linux-2.6-module/pdb_debug.h tools/debugger/pdb/linux-2.6-module/pdb_module.h tools/debugger/pdb/linux-2.6-patches/Makefile tools/debugger/pdb/linux-2.6-patches/i386_ksyms.patch tools/debugger/pdb/linux-2.6-patches/kdebug.patch tools/debugger/pdb/linux-2.6-patches/makefile.patch tools/debugger/pdb/linux-2.6-patches/ptrace.patch tools/debugger/pdb/linux-2.6-patches/traps.patch tools/debugger/pdb/pdb_caml_domain.c tools/debugger/pdb/pdb_caml_evtchn.c tools/debugger/pdb/pdb_caml_process.c tools/debugger/pdb/pdb_caml_xc.c tools/debugger/pdb/pdb_caml_xcs.c tools/debugger/pdb/pdb_caml_xen.h tools/debugger/pdb/pdb_xen.c tools/debugger/pdb/readme tools/debugger/pdb/server.ml tools/examples/Makefile tools/examples/README tools/examples/backend.hotplug tools/examples/network-bridge tools/examples/vif-bridge tools/examples/xend-config.sxp tools/examples/xmexample.vmx tools/firmware/acpi/acpi2_0.h tools/firmware/rombios/rombios.c tools/firmware/vmxassist/vm86.c tools/ioemu/cpu-all.h tools/ioemu/exec.c tools/ioemu/hw/i8254.c tools/ioemu/hw/i8259.c tools/ioemu/hw/ide.c tools/ioemu/hw/ioapic.h tools/ioemu/hw/pc.c tools/ioemu/hw/pckbd.c tools/ioemu/hw/vga.c tools/ioemu/monitor.c tools/ioemu/target-i386-dm/Makefile tools/ioemu/target-i386-dm/helper2.c tools/ioemu/target-i386-dm/qemu-dm.debug tools/ioemu/vl.c tools/ioemu/vl.h tools/ioemu/vnc.c tools/libxc/Makefile tools/libxc/linux_boot_params.h tools/libxc/xc_core.c tools/libxc/xc_domain.c tools/libxc/xc_gnttab.c tools/libxc/xc_linux_build.c tools/libxc/xc_linux_restore.c tools/libxc/xc_linux_save.c tools/libxc/xc_load_aout9.c tools/libxc/xc_load_bin.c tools/libxc/xc_load_elf.c tools/libxc/xc_private.c tools/libxc/xc_private.h tools/libxc/xc_ptrace.c tools/libxc/xc_vmx_build.c tools/libxc/xenctrl.h tools/libxc/xenguest.h tools/libxc/xg_private.c tools/libxc/xg_private.h tools/misc/Makefile tools/misc/cpuperf/Makefile tools/misc/cpuperf/cpuperf_xeno.h tools/misc/xc_shadow.c tools/misc/xend tools/misc/xenperf.c tools/python/setup.py tools/python/xen/lowlevel/xc/xc.c tools/python/xen/lowlevel/xs/xs.c tools/python/xen/lowlevel/xu/xu.c tools/python/xen/sv/CreateDomain.py tools/python/xen/sv/DomInfo.py tools/python/xen/sv/GenTabbed.py tools/python/xen/sv/HTMLBase.py tools/python/xen/sv/Main.py tools/python/xen/sv/NodeInfo.py tools/python/xen/sv/RestoreDomain.py tools/python/xen/sv/Wizard.py tools/python/xen/sv/__init__.py tools/python/xen/sv/util.py tools/python/xen/web/SrvBase.py tools/python/xen/web/SrvDir.py tools/python/xen/web/__init__.py tools/python/xen/web/connection.py tools/python/xen/web/httpserver.py tools/python/xen/web/protocol.py tools/python/xen/web/reactor.py tools/python/xen/web/resource.py tools/python/xen/web/static.py tools/python/xen/web/tcp.py tools/python/xen/web/unix.py tools/python/xen/xend/Args.py tools/python/xen/xend/EventServer.py tools/python/xen/xend/PrettyPrint.py tools/python/xen/xend/Vifctl.py tools/python/xen/xend/XendCheckpoint.py tools/python/xen/xend/XendClient.py tools/python/xen/xend/XendDB.py tools/python/xen/xend/XendDmesg.py tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/XendError.py tools/python/xen/xend/XendLogging.py tools/python/xen/xend/XendNode.py tools/python/xen/xend/XendProtocol.py tools/python/xen/xend/XendRoot.py tools/python/xen/xend/XendVnet.py tools/python/xen/xend/encode.py tools/python/xen/xend/image.py tools/python/xen/xend/scheduler.py tools/python/xen/xend/server/SrvDaemon.py tools/python/xen/xend/server/SrvDmesg.py tools/python/xen/xend/server/SrvDomain.py tools/python/xen/xend/server/SrvDomainDir.py tools/python/xen/xend/server/SrvNode.py tools/python/xen/xend/server/SrvRoot.py tools/python/xen/xend/server/SrvServer.py tools/python/xen/xend/server/SrvVnetDir.py tools/python/xen/xend/server/SrvXendLog.py tools/python/xen/xend/server/blkif.py tools/python/xen/xend/server/channel.py tools/python/xen/xend/server/controller.py tools/python/xen/xend/server/event.py tools/python/xen/xend/server/messages.py tools/python/xen/xend/server/netif.py tools/python/xen/xend/server/params.py tools/python/xen/xend/server/pciif.py tools/python/xen/xend/server/relocate.py tools/python/xen/xend/sxp.py tools/python/xen/xend/uuid.py tools/python/xen/xend/xenstore/__init__.py tools/python/xen/xend/xenstore/xsnode.py tools/python/xen/xend/xenstore/xsobj.py tools/python/xen/xend/xenstore/xsresource.py tools/python/xen/xm/create.py tools/python/xen/xm/destroy.py tools/python/xen/xm/help.py tools/python/xen/xm/main.py tools/python/xen/xm/migrate.py tools/python/xen/xm/opts.py tools/python/xen/xm/shutdown.py tools/python/xen/xm/sysrq.py tools/security/Makefile tools/security/example.txt tools/security/install.txt tools/security/policies/chwall/chwall-security_label_template.xml tools/security/policies/chwall/chwall-security_policy.xml tools/security/policies/chwall_ste/chwall_ste-security_label_template.xml tools/security/policies/chwall_ste/chwall_ste-security_policy.xml tools/security/policies/null/null-security_label_template.xml tools/security/policies/null/null-security_policy.xml tools/security/policies/security_policy.xsd tools/security/policies/ste/ste-security_label_template.xml tools/security/policies/ste/ste-security_policy.xml tools/security/policy.txt tools/security/readme.txt tools/security/secpol_compat.h tools/security/secpol_tool.c tools/security/secpol_xml2bin.c tools/security/secpol_xml2bin.h tools/security/setlabel.sh tools/security/updategrub.sh tools/sv/Makefile tools/sv/images/destroy.png tools/sv/images/finish.png tools/sv/images/next.png tools/sv/images/pause.png tools/sv/images/previous.png tools/sv/images/reboot.png tools/sv/images/shutdown.png tools/sv/images/small-destroy.png tools/sv/images/small-pause.png tools/sv/images/small-unpause.png tools/sv/images/unpause.png tools/sv/images/xen.png tools/sv/inc/script.js tools/sv/inc/style.css tools/sv/index.psp tools/xcs/Makefile tools/xcs/dump.h tools/xcs/xcs.h tools/xcs/xcsdump.c tools/xcutils/Makefile tools/xcutils/xc_restore.c tools/xcutils/xc_save.c tools/xenstat/Makefile tools/xenstat/libxenstat/COPYING tools/xenstat/libxenstat/Makefile tools/xenstat/libxenstat/bindings/swig/perl/.empty tools/xenstat/libxenstat/bindings/swig/python/.empty tools/xenstat/libxenstat/bindings/swig/xenstat.i tools/xenstat/libxenstat/src/xen-interface.c tools/xenstat/libxenstat/src/xen-interface.h tools/xenstat/libxenstat/src/xenstat.c tools/xenstat/libxenstat/src/xenstat.h tools/xenstat/xentop/Makefile tools/xenstat/xentop/TODO tools/xenstat/xentop/xentop.1 tools/xenstat/xentop/xentop.c tools/xenstore/Makefile tools/xenstore/TODO tools/xenstore/testsuite/02directory.test tools/xenstore/testsuite/03write.test tools/xenstore/testsuite/06dirpermissions.test tools/xenstore/testsuite/test.sh tools/xenstore/utils.c tools/xenstore/utils.h tools/xenstore/xenstored.h tools/xenstore/xenstored_core.c tools/xenstore/xenstored_core.h tools/xenstore/xenstored_domain.c tools/xenstore/xenstored_domain.h tools/xenstore/xenstored_transaction.c tools/xenstore/xenstored_transaction.h tools/xenstore/xenstored_watch.c tools/xenstore/xenstored_watch.h tools/xenstore/xs.c tools/xenstore/xs.h tools/xenstore/xs_dom0_test.c tools/xenstore/xs_lib.c tools/xenstore/xs_lib.h tools/xenstore/xs_random.c tools/xenstore/xs_test.c tools/xentrace/Makefile tools/xentrace/xenctx.c tools/xentrace/xentrace.c xen/Makefile xen/Rules.mk xen/acm/acm_core.c xen/acm/acm_policy.c xen/arch/ia64/Makefile xen/arch/ia64/Rules.mk xen/arch/ia64/asm-offsets.c xen/arch/ia64/asm-xsi-offsets.c xen/arch/ia64/dom_fw.c xen/arch/ia64/domain.c xen/arch/ia64/grant_table.c xen/arch/ia64/hypercall.c xen/arch/ia64/hyperprivop.S xen/arch/ia64/mmio.c xen/arch/ia64/pal_emul.c xen/arch/ia64/patch/linux-2.6.11/irq_ia64.c xen/arch/ia64/patch/linux-2.6.11/kregs.h xen/arch/ia64/pcdp.c xen/arch/ia64/process.c xen/arch/ia64/regionreg.c xen/arch/ia64/tools/mkbuildtree xen/arch/ia64/vcpu.c xen/arch/ia64/vlsapic.c xen/arch/ia64/vmmu.c xen/arch/ia64/vmx_hypercall.c xen/arch/ia64/vmx_ivt.S xen/arch/ia64/vmx_support.c xen/arch/ia64/vmx_vcpu.c xen/arch/ia64/vmx_virt.c xen/arch/ia64/vtlb.c xen/arch/ia64/xenasm.S xen/arch/ia64/xenmem.c xen/arch/ia64/xenmisc.c xen/arch/ia64/xensetup.c xen/arch/ia64/xentime.c xen/arch/x86/Makefile xen/arch/x86/acpi/boot.c xen/arch/x86/apic.c xen/arch/x86/audit.c xen/arch/x86/cpu/amd.c xen/arch/x86/cpu/common.c xen/arch/x86/dom0_ops.c xen/arch/x86/domain.c xen/arch/x86/domain_build.c xen/arch/x86/genapic/es7000plat.c xen/arch/x86/i8259.c xen/arch/x86/io_apic.c xen/arch/x86/mm.c xen/arch/x86/mpparse.c xen/arch/x86/physdev.c xen/arch/x86/setup.c xen/arch/x86/shadow.c xen/arch/x86/shadow32.c xen/arch/x86/shadow_public.c xen/arch/x86/smpboot.c xen/arch/x86/time.c xen/arch/x86/traps.c xen/arch/x86/vmx.c xen/arch/x86/vmx_intercept.c xen/arch/x86/vmx_io.c xen/arch/x86/vmx_platform.c xen/arch/x86/vmx_vmcs.c xen/arch/x86/x86_32/entry.S xen/arch/x86/x86_32/mm.c xen/arch/x86/x86_32/traps.c xen/arch/x86/x86_64/entry.S xen/arch/x86/x86_64/mm.c xen/arch/x86/x86_64/traps.c xen/common/ac_timer.c xen/common/dom0_ops.c xen/common/dom_mem_ops.c xen/common/domain.c xen/common/event_channel.c xen/common/grant_table.c xen/common/kernel.c xen/common/lib.c xen/common/page_alloc.c xen/common/perfc.c xen/common/sched_sedf.c xen/common/schedule.c xen/common/symbols.c xen/common/trace.c xen/common/xmalloc.c xen/drivers/char/console.c xen/drivers/char/ns16550.c xen/include/acm/acm_core.h xen/include/acm/acm_hooks.h xen/include/asm-ia64/config.h xen/include/asm-ia64/domain.h xen/include/asm-ia64/event.h xen/include/asm-ia64/ia64_int.h xen/include/asm-ia64/privop.h xen/include/asm-ia64/regionreg.h xen/include/asm-ia64/regs.h xen/include/asm-ia64/vcpu.h xen/include/asm-ia64/vmx.h xen/include/asm-ia64/vmx_uaccess.h xen/include/asm-ia64/vmx_vcpu.h xen/include/asm-ia64/vmx_vpd.h xen/include/asm-ia64/xensystem.h xen/include/asm-x86/apicdef.h xen/include/asm-x86/config.h xen/include/asm-x86/e820.h xen/include/asm-x86/event.h xen/include/asm-x86/fixmap.h xen/include/asm-x86/genapic.h xen/include/asm-x86/hpet.h xen/include/asm-x86/io.h xen/include/asm-x86/mach-bigsmp/mach_apic.h xen/include/asm-x86/mach-default/mach_apic.h xen/include/asm-x86/mach-es7000/mach_apic.h xen/include/asm-x86/mach-generic/mach_apic.h xen/include/asm-x86/mach-summit/mach_apic.h xen/include/asm-x86/mach-summit/mach_mpparse.h xen/include/asm-x86/mm.h xen/include/asm-x86/page.h xen/include/asm-x86/shadow.h xen/include/asm-x86/shadow_64.h xen/include/asm-x86/shadow_public.h xen/include/asm-x86/time.h xen/include/asm-x86/types.h xen/include/asm-x86/uaccess.h xen/include/asm-x86/vmx.h xen/include/asm-x86/vmx_virpit.h xen/include/asm-x86/vmx_vmcs.h xen/include/asm-x86/x86_32/page-3level.h xen/include/asm-x86/x86_32/uaccess.h xen/include/asm-x86/x86_64/page.h xen/include/public/arch-ia64.h xen/include/public/arch-x86_32.h xen/include/public/arch-x86_64.h xen/include/public/dom0_ops.h xen/include/public/grant_table.h xen/include/public/io/blkif.h xen/include/public/io/domain_controller.h xen/include/public/io/netif.h xen/include/public/physdev.h xen/include/public/trace.h xen/include/public/xen.h xen/include/xen/ac_timer.h xen/include/xen/domain.h xen/include/xen/event.h xen/include/xen/grant_table.h xen/include/xen/mm.h xen/include/xen/perfc_defn.h xen/include/xen/sched.h xen/include/xen/serial.h xen/include/xen/symbols.h xen/include/xen/time.h xen/include/xen/trace.h xen/tools/Makefile xen/tools/symbols.c
line diff
     1.1 --- a/extras/mini-os/include/hypervisor.h	Wed Aug 24 16:16:52 2005 -0700
     1.2 +++ b/extras/mini-os/include/hypervisor.h	Thu Aug 25 11:18:47 2005 -0700
     1.3 @@ -80,17 +80,43 @@ static __inline__ int HYPERVISOR_set_tra
     1.4  
     1.5  static __inline__ int HYPERVISOR_mmu_update(mmu_update_t *req, 
     1.6                                              int count, 
     1.7 -                                            int *success_count)
     1.8 +                                            int *success_count, 
     1.9 +                                            domid_t domid)
    1.10  {
    1.11      int ret;
    1.12 +    unsigned long ign1, ign2, ign3, ign4;
    1.13 +
    1.14      __asm__ __volatile__ (
    1.15          TRAP_INSTR
    1.16 -        : "=a" (ret) : "0" (__HYPERVISOR_mmu_update), 
    1.17 -        _a1 (req), _a2 (count), _a3 (success_count)  : "memory" );
    1.18 +        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)
    1.19 +        : "0" (__HYPERVISOR_mmu_update), "1" (req), "2" (count),
    1.20 +          "3" (success_count), "4" (domid)
    1.21 +        : "memory" );
    1.22  
    1.23      return ret;
    1.24  }
    1.25  
    1.26 +
    1.27 +static __inline__ int HYPERVISOR_mmuext_op(struct mmuext_op *op, 
    1.28 +                                           int count, 
    1.29 +                                           int *success_count, 
    1.30 +                                           domid_t domid)
    1.31 +{
    1.32 +    int ret;
    1.33 +    unsigned long ign1, ign2, ign3, ign4;
    1.34 +
    1.35 +    __asm__ __volatile__ (
    1.36 +        TRAP_INSTR
    1.37 +        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)
    1.38 +        : "0" (__HYPERVISOR_mmuext_op), "1" (op), "2" (count),
    1.39 +          "3" (success_count), "4" (domid)
    1.40 +        : "memory" );
    1.41 +
    1.42 +    return ret;
    1.43 +}
    1.44 +
    1.45 +
    1.46 +
    1.47  static __inline__ int HYPERVISOR_set_gdt(unsigned long *frame_list, int entries)
    1.48  {
    1.49      int ret;
     2.1 --- a/extras/mini-os/include/mm.h	Wed Aug 24 16:16:52 2005 -0700
     2.2 +++ b/extras/mini-os/include/mm.h	Thu Aug 25 11:18:47 2005 -0700
     2.3 @@ -43,13 +43,27 @@
     2.4  #define PADDR_MASK              ((1UL << PADDR_BITS)-1)
     2.5  #define VADDR_MASK              ((1UL << VADDR_BITS)-1)
     2.6  
     2.7 -#define pte_to_mfn(_pte) (((_pte) & (PADDR_MASK&PAGE_MASK)) >> PAGE_SHIFT)
     2.8 +#define pte_to_mfn(_pte) (((_pte) & (PADDR_MASK&PAGE_MASK)) >> L1_PAGETABLE_SHIFT)
     2.9 +
    2.10 +#endif
    2.11 +
    2.12 +
    2.13 +
    2.14 +#ifdef __i386__
    2.15 +
    2.16 +#define L1_PAGETABLE_SHIFT      12
    2.17 +#define L2_PAGETABLE_SHIFT      22
    2.18 +
    2.19 +#define L1_PAGETABLE_ENTRIES    1024
    2.20 +#define L2_PAGETABLE_ENTRIES    1024
    2.21 +#endif
    2.22  
    2.23  /* Given a virtual address, get an entry offset into a page table. */
    2.24  #define l1_table_offset(_a) \
    2.25    (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1))
    2.26  #define l2_table_offset(_a) \
    2.27    (((_a) >> L2_PAGETABLE_SHIFT) & (L2_PAGETABLE_ENTRIES - 1))
    2.28 +#ifdef __x86_64__
    2.29  #define l3_table_offset(_a) \
    2.30    (((_a) >> L3_PAGETABLE_SHIFT) & (L3_PAGETABLE_ENTRIES - 1))
    2.31  #define l4_table_offset(_a) \
    2.32 @@ -67,13 +81,16 @@
    2.33  #define _PAGE_PSE      0x080UL
    2.34  #define _PAGE_GLOBAL   0x100UL
    2.35  
    2.36 -#define PAGE_SHIFT      12
    2.37 -#define PAGE_SIZE       (1UL << PAGE_SHIFT)
    2.38 +#define L1_PROT (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED)
    2.39 +#define L2_PROT (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_USER)
    2.40 +
    2.41 +#define PAGE_SIZE       (1UL << L1_PAGETABLE_SHIFT)
    2.42 +#define PAGE_SHIFT      L1_PAGETABLE_SHIFT
    2.43  #define PAGE_MASK       (~(PAGE_SIZE-1))
    2.44  
    2.45 -#define PFN_UP(x)	(((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
    2.46 -#define PFN_DOWN(x)	((x) >> PAGE_SHIFT)
    2.47 -#define PFN_PHYS(x)	((x) << PAGE_SHIFT)
    2.48 +#define PFN_UP(x)	(((x) + PAGE_SIZE-1) >> L1_PAGETABLE_SHIFT)
    2.49 +#define PFN_DOWN(x)	((x) >> L1_PAGETABLE_SHIFT)
    2.50 +#define PFN_PHYS(x)	((x) << L1_PAGETABLE_SHIFT)
    2.51  
    2.52  /* to align the pointer to the (next) page boundary */
    2.53  #define PAGE_ALIGN(addr)        (((addr)+PAGE_SIZE-1)&PAGE_MASK)
    2.54 @@ -83,14 +100,14 @@ extern unsigned long *phys_to_machine_ma
    2.55  #define mfn_to_pfn(_mfn) (machine_to_phys_mapping[(_mfn)])
    2.56  static __inline__ unsigned long phys_to_machine(unsigned long phys)
    2.57  {
    2.58 -    unsigned long machine = pfn_to_mfn(phys >> PAGE_SHIFT);
    2.59 -    machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK);
    2.60 +    unsigned long machine = pfn_to_mfn(phys >> L1_PAGETABLE_SHIFT);
    2.61 +    machine = (machine << L1_PAGETABLE_SHIFT) | (phys & ~PAGE_MASK);
    2.62      return machine;
    2.63  }
    2.64  static __inline__ unsigned long machine_to_phys(unsigned long machine)
    2.65  {
    2.66 -    unsigned long phys = mfn_to_pfn(machine >> PAGE_SHIFT);
    2.67 -    phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
    2.68 +    unsigned long phys = mfn_to_pfn(machine >> L1_PAGETABLE_SHIFT);
    2.69 +    phys = (phys << L1_PAGETABLE_SHIFT) | (machine & ~PAGE_MASK);
    2.70      return phys;
    2.71  }
    2.72  
    2.73 @@ -105,7 +122,10 @@ static __inline__ unsigned long machine_
    2.74  #define __va to_virt
    2.75  #define __pa to_phys
    2.76  
    2.77 +#define virt_to_pfn(_virt)         (PFN_DOWN(to_phys(_virt)))
    2.78 +
    2.79  void init_mm(void);
    2.80  unsigned long alloc_pages(int order);
    2.81 +int is_mfn_mapped(unsigned long mfn);
    2.82  
    2.83  #endif /* _MM_H_ */
     3.1 --- a/extras/mini-os/kernel.c	Wed Aug 24 16:16:52 2005 -0700
     3.2 +++ b/extras/mini-os/kernel.c	Thu Aug 25 11:18:47 2005 -0700
     3.3 @@ -133,7 +133,7 @@ void start_kernel(start_info_t *si)
     3.4      for ( ; ; ) 
     3.5      {      
     3.6  //        HYPERVISOR_yield();
     3.7 -        block(1);
     3.8 +        block(100);
     3.9          i++;
    3.10      }
    3.11  }
     4.1 --- a/extras/mini-os/mm.c	Wed Aug 24 16:16:52 2005 -0700
     4.2 +++ b/extras/mini-os/mm.c	Thu Aug 25 11:18:47 2005 -0700
     4.3 @@ -5,9 +5,9 @@
     4.4   *
     4.5   *        File: mm.c
     4.6   *      Author: Rolf Neugebauer (neugebar@dcs.gla.ac.uk)
     4.7 - *     Changes: 
     4.8 + *     Changes: Grzegorz Milos
     4.9   *              
    4.10 - *        Date: Aug 2003
    4.11 + *        Date: Aug 2003, chages Aug 2005
    4.12   * 
    4.13   * Environment: Xen Minimal OS
    4.14   * Description: memory management related functions
    4.15 @@ -41,86 +41,18 @@
    4.16  #include <types.h>
    4.17  #include <lib.h>
    4.18  
    4.19 +
    4.20 +#ifdef MM_DEBUG
    4.21 +#define DEBUG(_f, _a...) \
    4.22 +    printk("MINI_OS(file=mm.c, line=%d) " _f "\n", __LINE__, ## _a)
    4.23 +#else
    4.24 +#define DEBUG(_f, _a...)    ((void)0)
    4.25 +#endif
    4.26 +
    4.27  unsigned long *phys_to_machine_mapping;
    4.28  extern char *stack;
    4.29  extern char _text, _etext, _edata, _end;
    4.30  
    4.31 -static void init_page_allocator(unsigned long min, unsigned long max);
    4.32 -
    4.33 -void init_mm(void)
    4.34 -{
    4.35 -
    4.36 -    unsigned long start_pfn, max_pfn, max_free_pfn;
    4.37 -
    4.38 -    unsigned long *pgd = (unsigned long *)start_info.pt_base;
    4.39 -
    4.40 -    printk("MM: Init\n");
    4.41 -
    4.42 -    printk("  _text:        %p\n", &_text);
    4.43 -    printk("  _etext:       %p\n", &_etext);
    4.44 -    printk("  _edata:       %p\n", &_edata);
    4.45 -    printk("  stack start:  %p\n", &stack);
    4.46 -    printk("  _end:         %p\n", &_end);
    4.47 -
    4.48 -    /* set up minimal memory infos */
    4.49 -    start_pfn = PFN_UP(to_phys(&_end));
    4.50 -    max_pfn = start_info.nr_pages;
    4.51 -
    4.52 -    printk("  start_pfn:    %lx\n", start_pfn);
    4.53 -    printk("  max_pfn:      %lx\n", max_pfn);
    4.54 -
    4.55 -    /*
    4.56 -     * we know where free tables start (start_pfn) and how many we 
    4.57 -     * have (max_pfn). 
    4.58 -     * 
    4.59 -     * Currently the hypervisor stores page tables it providesin the
    4.60 -     * high region of the this memory range.
    4.61 -     * 
    4.62 -     * next we work out how far down this goes (max_free_pfn)
    4.63 -     * 
    4.64 -     * XXX this assumes the hypervisor provided page tables to be in
    4.65 -     * the upper region of our initial memory. I don't know if this 
    4.66 -     * is always true.
    4.67 -     */
    4.68 -
    4.69 -    max_free_pfn = PFN_DOWN(to_phys(pgd));
    4.70 -#ifdef __i386__
    4.71 -    {
    4.72 -        unsigned long *pgd = (unsigned long *)start_info.pt_base;
    4.73 -        unsigned long  pte;
    4.74 -        int i;
    4.75 -        printk("  pgd(pa(pgd)): %lx(%lx)", (u_long)pgd, to_phys(pgd));
    4.76 -
    4.77 -        for ( i = 0; i < (HYPERVISOR_VIRT_START>>22); i++ )
    4.78 -        {
    4.79 -            unsigned long pgde = *pgd++;
    4.80 -            if ( !(pgde & 1) ) continue;
    4.81 -            pte = machine_to_phys(pgde & PAGE_MASK);
    4.82 -            printk("  PT(%x): %lx(%lx)", i, (u_long)to_virt(pte), pte);
    4.83 -            if (PFN_DOWN(pte) <= max_free_pfn) 
    4.84 -                max_free_pfn = PFN_DOWN(pte);
    4.85 -        }
    4.86 -    }
    4.87 -    max_free_pfn--;
    4.88 -    printk("  max_free_pfn: %lx\n", max_free_pfn);
    4.89 -
    4.90 -    /*
    4.91 -     * now we can initialise the page allocator
    4.92 -     */
    4.93 -    printk("MM: Initialise page allocator for %lx(%lx)-%lx(%lx)\n",
    4.94 -           (u_long)to_virt(PFN_PHYS(start_pfn)), PFN_PHYS(start_pfn), 
    4.95 -           (u_long)to_virt(PFN_PHYS(max_free_pfn)), PFN_PHYS(max_free_pfn));
    4.96 -    init_page_allocator(PFN_PHYS(start_pfn), PFN_PHYS(max_free_pfn));   
    4.97 -#endif
    4.98 -
    4.99 -
   4.100 -    /* Now initialise the physical->machine mapping table. */
   4.101 -
   4.102 -
   4.103 -    printk("MM: done\n");
   4.104 -
   4.105 -    
   4.106 -}
   4.107  
   4.108  /*********************
   4.109   * ALLOCATION BITMAP
   4.110 @@ -214,6 +146,59 @@ static chunk_head_t  free_tail[FREELIST_
   4.111  #define round_pgdown(_p)  ((_p)&PAGE_MASK)
   4.112  #define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
   4.113  
   4.114 +#ifdef MM_DEBUG
   4.115 +/*
   4.116 + * Prints allocation[0/1] for @nr_pages, starting at @start
   4.117 + * address (virtual).
   4.118 + */
   4.119 +static void print_allocation(void *start, int nr_pages)
   4.120 +{
   4.121 +    unsigned long pfn_start = virt_to_pfn(start);
   4.122 +    int count;
   4.123 +    for(count = 0; count < nr_pages; count++)
   4.124 +        if(allocated_in_map(pfn_start + count)) printk("1");
   4.125 +        else printk("0");
   4.126 +        
   4.127 +    printk("\n");        
   4.128 +}
   4.129 +
   4.130 +/*
   4.131 + * Prints chunks (making them with letters) for @nr_pages starting
   4.132 + * at @start (virtual).
   4.133 + */
   4.134 +static void print_chunks(void *start, int nr_pages)
   4.135 +{
   4.136 +    char chunks[1001], current='A';
   4.137 +    int order, count;
   4.138 +    chunk_head_t *head;
   4.139 +    unsigned long pfn_start = virt_to_pfn(start);
   4.140 +   
   4.141 +    memset(chunks, (int)'_', 1000);
   4.142 +    if(nr_pages > 1000) 
   4.143 +    {
   4.144 +        DEBUG("Can only pring 1000 pages. Increase buffer size.");
   4.145 +    }
   4.146 +    
   4.147 +    for(order=0; order < FREELIST_SIZE; order++)
   4.148 +    {
   4.149 +        head = free_head[order];
   4.150 +        while(!FREELIST_EMPTY(head))
   4.151 +        {
   4.152 +            for(count = 0; count < 1<< head->level; count++)
   4.153 +            {
   4.154 +                if(count + virt_to_pfn(head) - pfn_start < 1000)
   4.155 +                    chunks[count + virt_to_pfn(head) - pfn_start] = current;
   4.156 +            }
   4.157 +            head = head->next;
   4.158 +            current++;
   4.159 +        }
   4.160 +    }
   4.161 +    chunks[nr_pages] = '\0';
   4.162 +    printk("%s\n", chunks);
   4.163 +}
   4.164 +#endif
   4.165 +
   4.166 +
   4.167  
   4.168  /*
   4.169   * Initialise allocator, placing addresses [@min,@max] in free pool.
   4.170 @@ -328,3 +313,198 @@ unsigned long alloc_pages(int order)
   4.171      return 0;
   4.172  }
   4.173  
   4.174 +void free_pages(void *pointer, int order)
   4.175 +{
   4.176 +    chunk_head_t *freed_ch, *to_merge_ch;
   4.177 +    chunk_tail_t *freed_ct;
   4.178 +    unsigned long mask;
   4.179 +    
   4.180 +    /* First free the chunk */
   4.181 +    map_free(virt_to_pfn(pointer), 1 << order);
   4.182 +    
   4.183 +    /* Create free chunk */
   4.184 +    freed_ch = (chunk_head_t *)pointer;
   4.185 +    freed_ct = (chunk_tail_t *)((char *)pointer + (1<<(order + PAGE_SHIFT)))-1;
   4.186 +    
   4.187 +    /* Now, possibly we can conseal chunks together */
   4.188 +    while(order < FREELIST_SIZE)
   4.189 +    {
   4.190 +        mask = 1 << (order + PAGE_SHIFT);
   4.191 +        if((unsigned long)freed_ch & mask) 
   4.192 +        {
   4.193 +            to_merge_ch = (chunk_head_t *)((char *)freed_ch - mask);
   4.194 +            if(allocated_in_map(virt_to_pfn(to_merge_ch)) ||
   4.195 +                    to_merge_ch->level != order)
   4.196 +                break;
   4.197 +            
   4.198 +            /* Merge with predecessor */
   4.199 +            freed_ch = to_merge_ch;   
   4.200 +        }
   4.201 +        else 
   4.202 +        {
   4.203 +            to_merge_ch = (chunk_head_t *)((char *)freed_ch + mask);
   4.204 +            if(allocated_in_map(virt_to_pfn(to_merge_ch)) ||
   4.205 +                    to_merge_ch->level != order)
   4.206 +                break;
   4.207 +            
   4.208 +            /* Merge with successor */
   4.209 +            freed_ct = (chunk_tail_t *)((char *)to_merge_ch + mask);
   4.210 +        }
   4.211 +        
   4.212 +        /* We are commited to merging, unlink the chunk */
   4.213 +        *(to_merge_ch->pprev) = to_merge_ch->next;
   4.214 +        to_merge_ch->next->pprev = to_merge_ch->pprev;
   4.215 +        
   4.216 +        order++;
   4.217 +    }
   4.218 +
   4.219 +    /* Link the new chunk */
   4.220 +    freed_ch->level = order;
   4.221 +    freed_ch->next  = free_head[order];
   4.222 +    freed_ch->pprev = &free_head[order];
   4.223 +    freed_ct->level = order;
   4.224 +    
   4.225 +    freed_ch->next->pprev = &freed_ch->next;
   4.226 +    free_head[order] = freed_ch;   
   4.227 +   
   4.228 +}
   4.229 +void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
   4.230 +{
   4.231 +    unsigned long pfn_to_map, pt_frame;
   4.232 +    unsigned long mach_ptd, max_mach_ptd;
   4.233 +    int count;
   4.234 +    unsigned long mach_pte, virt_pte;
   4.235 +    unsigned long *ptd = (unsigned long *)start_info.pt_base;
   4.236 +    mmu_update_t mmu_updates[L1_PAGETABLE_ENTRIES + 1];
   4.237 +    struct mmuext_op pin_request;
   4.238 +    
   4.239 +    /* Firstly work out what is the first pfn that is not yet in page tables
   4.240 +       NB. Assuming that builder fills whole pt_frames (which it does at the
   4.241 +       moment)
   4.242 +     */  
   4.243 +    pfn_to_map = (start_info.nr_pt_frames - 1) * L1_PAGETABLE_ENTRIES;
   4.244 +    DEBUG("start_pfn=%ld, first pfn_to_map %ld, max_pfn=%ld", 
   4.245 +            *start_pfn, pfn_to_map, *max_pfn);
   4.246 +
   4.247 +    /* Machine address of page table directory */
   4.248 +    mach_ptd = phys_to_machine(to_phys(start_info.pt_base));
   4.249 +    mach_ptd += sizeof(void *) * 
   4.250 +        l2_table_offset((unsigned long)to_virt(PFN_PHYS(pfn_to_map)));
   4.251 +  
   4.252 +    max_mach_ptd = sizeof(void *) * 
   4.253 +        l2_table_offset((unsigned long)to_virt(PFN_PHYS(*max_pfn)));
   4.254 +    
   4.255 +    /* Check that we are not trying to access Xen region */
   4.256 +    if(max_mach_ptd > sizeof(void *) * l2_table_offset(HYPERVISOR_VIRT_START))
   4.257 +    {
   4.258 +        printk("WARNING: mini-os will not use all the memory supplied\n");
   4.259 +        max_mach_ptd = sizeof(void *) * l2_table_offset(HYPERVISOR_VIRT_START);
   4.260 +        *max_pfn = virt_to_pfn(HYPERVISOR_VIRT_START - PAGE_SIZE);
   4.261 +    }
   4.262 +    max_mach_ptd += phys_to_machine(to_phys(start_info.pt_base));
   4.263 +    DEBUG("Max_mach_ptd 0x%lx", max_mach_ptd); 
   4.264 +   
   4.265 +    pt_frame = *start_pfn;
   4.266 +    /* Should not happen - no empty, mapped pages */
   4.267 +    if(pt_frame >= pfn_to_map)
   4.268 +    {
   4.269 +        printk("ERROR: Not even a single empty, mapped page\n");
   4.270 +        *(int*)0=0;
   4.271 +    }
   4.272 +    
   4.273 +    while(mach_ptd < max_mach_ptd)
   4.274 +    {
   4.275 +        /* Correct protection needs to be set for the new page table frame */
   4.276 +        virt_pte = (unsigned long)to_virt(PFN_PHYS(pt_frame));
   4.277 +        mach_pte = ptd[l2_table_offset(virt_pte)] & ~(PAGE_SIZE-1);
   4.278 +        mach_pte += sizeof(void *) * l1_table_offset(virt_pte);
   4.279 +        DEBUG("New page table page: pfn=0x%lx, mfn=0x%lx, virt_pte=0x%lx, "
   4.280 +                "mach_pte=0x%lx", pt_frame, pfn_to_mfn(pt_frame), 
   4.281 +                virt_pte, mach_pte);
   4.282 +        
   4.283 +        /* Update the entry */
   4.284 +        mmu_updates[0].ptr = mach_pte;
   4.285 +        mmu_updates[0].val = pfn_to_mfn(pt_frame) << PAGE_SHIFT | 
   4.286 +                                                    (L1_PROT & ~_PAGE_RW);
   4.287 +        if(HYPERVISOR_mmu_update(mmu_updates, 1, NULL, DOMID_SELF) < 0)
   4.288 +        {
   4.289 +            printk("PTE for new page table page could not be updated\n");
   4.290 +            *(int*)0=0;
   4.291 +        }
   4.292 +        
   4.293 +        /* Pin the page to provide correct protection */
   4.294 +        pin_request.cmd = MMUEXT_PIN_L1_TABLE;
   4.295 +        pin_request.mfn = pfn_to_mfn(pt_frame);
   4.296 +        if(HYPERVISOR_mmuext_op(&pin_request, 1, NULL, DOMID_SELF) < 0)
   4.297 +        {
   4.298 +            printk("ERROR: pinning failed\n");
   4.299 +            *(int*)0=0;
   4.300 +        }
   4.301 +        
   4.302 +        /* Now fill the new page table page with entries.
   4.303 +           Update the page directory as well. */
   4.304 +        count = 0;
   4.305 +        mmu_updates[count].ptr = mach_ptd;
   4.306 +        mmu_updates[count].val = pfn_to_mfn(pt_frame) << PAGE_SHIFT |
   4.307 +                                                         L2_PROT;
   4.308 +        count++;
   4.309 +        mach_ptd += sizeof(void *);
   4.310 +        mach_pte = phys_to_machine(PFN_PHYS(pt_frame++));
   4.311 +        
   4.312 +        for(;count <= L1_PAGETABLE_ENTRIES && pfn_to_map <= *max_pfn; count++)
   4.313 +        {
   4.314 +            mmu_updates[count].ptr = mach_pte;
   4.315 +            mmu_updates[count].val = 
   4.316 +                pfn_to_mfn(pfn_to_map++) << PAGE_SHIFT | L1_PROT;
   4.317 +            if(count == 1) DEBUG("mach_pte 0x%lx", mach_pte);
   4.318 +            mach_pte += sizeof(void *);
   4.319 +        }
   4.320 +        if(HYPERVISOR_mmu_update(mmu_updates, count, NULL, DOMID_SELF) < 0) 
   4.321 +        {            
   4.322 +            printk("ERROR: mmu_update failed\n");
   4.323 +            *(int*)0=0;
   4.324 +        }
   4.325 +        (*start_pfn)++;
   4.326 +    }
   4.327 +
   4.328 +    *start_pfn = pt_frame;
   4.329 +}
   4.330 +
   4.331 +void init_mm(void)
   4.332 +{
   4.333 +
   4.334 +    unsigned long start_pfn, max_pfn;
   4.335 +
   4.336 +    printk("MM: Init\n");
   4.337 +
   4.338 +    printk("  _text:        %p\n", &_text);
   4.339 +    printk("  _etext:       %p\n", &_etext);
   4.340 +    printk("  _edata:       %p\n", &_edata);
   4.341 +    printk("  stack start:  %p\n", &stack);
   4.342 +    printk("  _end:         %p\n", &_end);
   4.343 +
   4.344 +    /* set up minimal memory infos */
   4.345 +    phys_to_machine_mapping = (unsigned long *)start_info.mfn_list;
   4.346 +   
   4.347 +    /* First page follows page table pages and 3 more pages (store page etc) */
   4.348 +    start_pfn = PFN_UP(__pa(start_info.pt_base)) + start_info.nr_pt_frames + 3;
   4.349 +    max_pfn = start_info.nr_pages;
   4.350 +
   4.351 +    printk("  start_pfn:    %lx\n", start_pfn);
   4.352 +    printk("  max_pfn:      %lx\n", max_pfn);
   4.353 +
   4.354 +
   4.355 +    build_pagetable(&start_pfn, &max_pfn);
   4.356 +    
   4.357 +#ifdef __i386__
   4.358 +    /*
   4.359 +     * now we can initialise the page allocator
   4.360 +     */
   4.361 +    printk("MM: Initialise page allocator for %lx(%lx)-%lx(%lx)\n",
   4.362 +           (u_long)to_virt(PFN_PHYS(start_pfn)), PFN_PHYS(start_pfn), 
   4.363 +           (u_long)to_virt(PFN_PHYS(max_pfn)), PFN_PHYS(max_pfn));
   4.364 +    init_page_allocator(PFN_PHYS(start_pfn), PFN_PHYS(max_pfn));   
   4.365 +#endif
   4.366 +
   4.367 +    printk("MM: done\n");
   4.368 +}
     5.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/cpu/common.c	Wed Aug 24 16:16:52 2005 -0700
     5.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/cpu/common.c	Thu Aug 25 11:18:47 2005 -0700
     5.3 @@ -19,11 +19,13 @@
     5.4  
     5.5  #include "cpu.h"
     5.6  
     5.7 +#ifndef CONFIG_XEN
     5.8  DEFINE_PER_CPU(struct desc_struct, cpu_gdt_table[GDT_ENTRIES]);
     5.9  EXPORT_PER_CPU_SYMBOL(cpu_gdt_table);
    5.10  
    5.11  DEFINE_PER_CPU(unsigned char, cpu_16bit_stack[CPU_16BIT_STACK_SIZE]);
    5.12  EXPORT_PER_CPU_SYMBOL(cpu_16bit_stack);
    5.13 +#endif
    5.14  
    5.15  static int cachesize_override __initdata = -1;
    5.16  static int disable_x86_fxsr __initdata = 0;
     6.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/smpboot.c	Wed Aug 24 16:16:52 2005 -0700
     6.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/smpboot.c	Thu Aug 25 11:18:47 2005 -0700
     6.3 @@ -131,15 +131,7 @@ static void map_cpu_to_logical_apicid(vo
     6.4   */
     6.5  void __init smp_alloc_memory(void)
     6.6  {
     6.7 -#if 1
     6.8 -	int cpu;
     6.9 -
    6.10 -	for (cpu = 1; cpu < NR_CPUS; cpu++) {
    6.11 -		cpu_gdt_descr[cpu].address = (unsigned long)
    6.12 -			alloc_bootmem_low_pages(PAGE_SIZE);
    6.13 -		/* XXX free unused pages later */
    6.14 -	}
    6.15 -#else
    6.16 +#if 0
    6.17  	trampoline_base = (void *) alloc_bootmem_low_pages(PAGE_SIZE);
    6.18  	/*
    6.19  	 * Has to be in very low memory so we can execute
    6.20 @@ -861,8 +853,8 @@ static int __init do_boot_cpu(int apicid
    6.21  	atomic_set(&init_deasserted, 0);
    6.22  
    6.23  #if 1
    6.24 -	if (cpu_gdt_descr[0].size > PAGE_SIZE)
    6.25 -		BUG();
    6.26 +	cpu_gdt_descr[cpu].address = __get_free_page(GFP_KERNEL);
    6.27 +	BUG_ON(cpu_gdt_descr[0].size > PAGE_SIZE);
    6.28  	cpu_gdt_descr[cpu].size = cpu_gdt_descr[0].size;
    6.29  	printk("GDT: copying %d bytes from %lx to %lx\n",
    6.30  		cpu_gdt_descr[0].size, cpu_gdt_descr[0].address,
     7.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/traps.c	Wed Aug 24 16:16:52 2005 -0700
     7.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/traps.c	Thu Aug 25 11:18:47 2005 -0700
     7.3 @@ -871,6 +871,7 @@ fastcall void do_simd_coprocessor_error(
     7.4  	}
     7.5  }
     7.6  
     7.7 +#ifndef CONFIG_XEN
     7.8  fastcall void setup_x86_bogus_stack(unsigned char * stk)
     7.9  {
    7.10  	unsigned long *switch16_ptr, *switch32_ptr;
    7.11 @@ -915,6 +916,7 @@ fastcall unsigned char * fixup_x86_bogus
    7.12  	memcpy(stack32, stack16, len);
    7.13  	return stack32;
    7.14  }
    7.15 +#endif
    7.16  
    7.17  /*
    7.18   *  'math_state_restore()' saves the current math information in the
     8.1 --- a/linux-2.6-xen-sparse/arch/xen/kernel/gnttab.c	Wed Aug 24 16:16:52 2005 -0700
     8.2 +++ b/linux-2.6-xen-sparse/arch/xen/kernel/gnttab.c	Thu Aug 25 11:18:47 2005 -0700
     8.3 @@ -34,9 +34,11 @@
     8.4  
     8.5  
     8.6  EXPORT_SYMBOL(gnttab_grant_foreign_access);
     8.7 +EXPORT_SYMBOL(gnttab_end_foreign_access_ref);
     8.8  EXPORT_SYMBOL(gnttab_end_foreign_access);
     8.9  EXPORT_SYMBOL(gnttab_query_foreign_access);
    8.10  EXPORT_SYMBOL(gnttab_grant_foreign_transfer);
    8.11 +EXPORT_SYMBOL(gnttab_end_foreign_transfer_ref);
    8.12  EXPORT_SYMBOL(gnttab_end_foreign_transfer);
    8.13  EXPORT_SYMBOL(gnttab_alloc_grant_references);
    8.14  EXPORT_SYMBOL(gnttab_free_grant_references);
    8.15 @@ -160,7 +162,7 @@ gnttab_query_foreign_access(grant_ref_t 
    8.16  }
    8.17  
    8.18  void
    8.19 -gnttab_end_foreign_access(grant_ref_t ref, int readonly)
    8.20 +gnttab_end_foreign_access_ref(grant_ref_t ref, int readonly)
    8.21  {
    8.22      u16 flags, nflags;
    8.23  
    8.24 @@ -170,7 +172,12 @@ gnttab_end_foreign_access(grant_ref_t re
    8.25              printk(KERN_ALERT "WARNING: g.e. still in use!\n");
    8.26      }
    8.27      while ( (nflags = synch_cmpxchg(&shared[ref].flags, flags, 0)) != flags );
    8.28 +}
    8.29  
    8.30 +void
    8.31 +gnttab_end_foreign_access(grant_ref_t ref, int readonly)
    8.32 +{
    8.33 +    gnttab_end_foreign_access_ref(ref, readonly);
    8.34      put_free_entry(ref);
    8.35  }
    8.36  
    8.37 @@ -201,20 +208,13 @@ gnttab_grant_foreign_transfer_ref(grant_
    8.38  }
    8.39  
    8.40  unsigned long
    8.41 -gnttab_end_foreign_transfer(grant_ref_t ref)
    8.42 +gnttab_end_foreign_transfer_ref(grant_ref_t ref)
    8.43  {
    8.44      unsigned long frame = 0;
    8.45      u16           flags;
    8.46  
    8.47      flags = shared[ref].flags;
    8.48 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
    8.49 -    /*
    8.50 -     * But can't flags == (GTF_accept_transfer | GTF_transfer_completed)
    8.51 -     * if gnttab_donate executes without interruption???
    8.52 -     */
    8.53 -#else
    8.54 -    ASSERT(flags == (GTF_accept_transfer | GTF_transfer_committed));
    8.55 -#endif
    8.56 +
    8.57      /*
    8.58       * If a transfer is committed then wait for the frame address to appear.
    8.59       * Otherwise invalidate the grant entry against future use.
    8.60 @@ -224,8 +224,14 @@ gnttab_end_foreign_transfer(grant_ref_t 
    8.61          while ( unlikely((frame = shared[ref].frame) == 0) )
    8.62              cpu_relax();
    8.63  
    8.64 +    return frame;
    8.65 +}
    8.66 +
    8.67 +unsigned long
    8.68 +gnttab_end_foreign_transfer(grant_ref_t ref)
    8.69 +{
    8.70 +    unsigned long frame = gnttab_end_foreign_transfer_ref(ref);
    8.71      put_free_entry(ref);
    8.72 -
    8.73      return frame;
    8.74  }
    8.75  
     9.1 --- a/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c	Wed Aug 24 16:16:52 2005 -0700
     9.2 +++ b/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c	Thu Aug 25 11:18:47 2005 -0700
     9.3 @@ -129,14 +129,6 @@ static int __do_suspend(void *ignore)
     9.4      /* Hmmm... a cleaner interface to suspend/resume blkdevs would be nice. */
     9.5  	/* XXX SMH: yes it would :-( */	
     9.6  
     9.7 -#ifdef CONFIG_XEN_NETDEV_FRONTEND
     9.8 -    extern void netif_suspend(void);
     9.9 -    extern void netif_resume(void);  
    9.10 -#else
    9.11 -#define netif_suspend() do{}while(0)
    9.12 -#define netif_resume()  do{}while(0)
    9.13 -#endif
    9.14 -
    9.15  #ifdef CONFIG_XEN_USB_FRONTEND
    9.16      extern void usbif_resume();
    9.17  #else
    9.18 @@ -218,8 +210,6 @@ static int __do_suspend(void *ignore)
    9.19      kmem_cache_shrink(pgd_cache);
    9.20  #endif
    9.21  
    9.22 -    netif_suspend();
    9.23 -
    9.24      time_suspend();
    9.25  
    9.26  #ifdef CONFIG_SMP
    9.27 @@ -277,8 +267,6 @@ static int __do_suspend(void *ignore)
    9.28  
    9.29      time_resume();
    9.30  
    9.31 -    netif_resume();
    9.32 -
    9.33      usbif_resume();
    9.34  
    9.35      for_each_cpu_mask(i, prev_present_cpus) {
    10.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/early_printk.c	Wed Aug 24 16:16:52 2005 -0700
    10.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/early_printk.c	Thu Aug 25 11:18:47 2005 -0700
    10.3 @@ -6,6 +6,8 @@
    10.4  #include <asm/io.h>
    10.5  #include <asm/processor.h>
    10.6  
    10.7 +#ifndef CONFIG_XEN
    10.8 +
    10.9  /* Simple VGA output */
   10.10  
   10.11  #ifdef __i386__
   10.12 @@ -59,7 +61,6 @@ static struct console early_vga_console 
   10.13  	.index =	-1,
   10.14  };
   10.15  
   10.16 -#ifndef CONFIG_XEN
   10.17  /* Serial functions loosely based on a similar package from Klaus P. Gerlicher */ 
   10.18  
   10.19  static int early_serial_base = 0x3f8;  /* ttyS0 */
   10.20 @@ -148,7 +149,8 @@ static __init void early_serial_init(cha
   10.21  	outb((divisor >> 8) & 0xff, early_serial_base + DLH); 
   10.22  	outb(c & ~DLAB, early_serial_base + LCR);
   10.23  }
   10.24 -#else
   10.25 +
   10.26 +#else /* CONFIG_XEN */
   10.27  
   10.28  static void
   10.29  early_serial_write(struct console *con, const char *s, unsigned count)
   10.30 @@ -167,6 +169,13 @@ early_serial_write(struct console *con, 
   10.31  static __init void early_serial_init(char *s)
   10.32  {
   10.33  }
   10.34 +
   10.35 +/*
   10.36 + * No early VGA console on Xen, as we do not have convenient ISA-space
   10.37 + * mappings. Someone should fix this for domain 0. For now, use fake serial.
   10.38 + */
   10.39 +#define early_vga_console early_serial_console
   10.40 +
   10.41  #endif
   10.42  
   10.43  static struct console early_serial_console = {
    11.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/head.S	Wed Aug 24 16:16:52 2005 -0700
    11.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/head.S	Thu Aug 25 11:18:47 2005 -0700
    11.3 @@ -206,11 +206,13 @@ ENTRY(cpu_gdt_table)
    11.4  	.quad   0,0,0			/* three TLS descriptors */ 
    11.5  	.quad	0			/* unused now?   __KERNEL16_CS - 16bit PM for S3 wakeup. */
    11.6  
    11.7 -gdt_end:	
    11.8 +gdt_end:
    11.9 +#if 0
   11.10  	/* asm/segment.h:GDT_ENTRIES must match this */	
   11.11  	/* This should be a multiple of the cache line size */
   11.12  	/* GDTs of other CPUs: */	
   11.13  	.fill (GDT_SIZE * NR_CPUS) - (gdt_end - cpu_gdt_table)
   11.14 +#endif
   11.15  
   11.16  .org 0x8000
   11.17  ENTRY(empty_zero_page)
    12.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c	Wed Aug 24 16:16:52 2005 -0700
    12.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c	Thu Aug 25 11:18:47 2005 -0700
    12.3 @@ -536,48 +536,7 @@ static inline void copy_edd(void)
    12.4  }
    12.5  #endif
    12.6  
    12.7 -#ifdef CONFIG_XEN
    12.8 -#define reserve_ebda_region() void(0)
    12.9 -
   12.10 -static void __init print_memory_map(char *who)
   12.11 -{
   12.12 -        int i;
   12.13 -
   12.14 -        for (i = 0; i < e820.nr_map; i++) {
   12.15 -                early_printk(" %s: %016Lx - %016Lx ", who,
   12.16 -                        e820.map[i].addr,
   12.17 -                        e820.map[i].addr + e820.map[i].size);
   12.18 -                switch (e820.map[i].type) {
   12.19 -                case E820_RAM:  early_printk("(usable)\n");
   12.20 -                                break;
   12.21 -                case E820_RESERVED:
   12.22 -                                early_printk("(reserved)\n");
   12.23 -                                break;
   12.24 -                case E820_ACPI:
   12.25 -                                early_printk("(ACPI data)\n");
   12.26 -                                break;
   12.27 -                case E820_NVS:
   12.28 -                                early_printk("(ACPI NVS)\n");
   12.29 -                                break;
   12.30 -                default:        early_printk("type %u\n", e820.map[i].type);
   12.31 -                                break;
   12.32 -                }
   12.33 -        }
   12.34 -}
   12.35 -
   12.36 -void __init smp_alloc_memory(void)
   12.37 -{
   12.38 -	int cpu;
   12.39 -
   12.40 -	for (cpu = 1; cpu < NR_CPUS; cpu++) {
   12.41 -		cpu_gdt_descr[cpu].address = (unsigned long)
   12.42 -			alloc_bootmem_low_pages(PAGE_SIZE);
   12.43 -		/* XXX free unused pages later */
   12.44 -	}
   12.45 -}
   12.46 -
   12.47 -
   12.48 -#else
   12.49 +#ifndef CONFIG_XEN
   12.50  #define EBDA_ADDR_POINTER 0x40E
   12.51  static void __init reserve_ebda_region(void)
   12.52  {
   12.53 @@ -628,7 +587,6 @@ void __init setup_arch(char **cmdline_p)
   12.54  			     VMASST_TYPE_writable_pagetables);
   12.55  
   12.56          ARCH_SETUP
   12.57 -        print_memory_map(machine_specific_memory_setup());
   12.58  #else
   12.59   	ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
   12.60   	drive_info = DRIVE_INFO;
   12.61 @@ -744,9 +702,6 @@ void __init setup_arch(char **cmdline_p)
   12.62  		}
   12.63  	}
   12.64  #endif
   12.65 -#ifdef CONFIG_SMP
   12.66 -	smp_alloc_memory();
   12.67 -#endif
   12.68  #else	/* CONFIG_XEN */
   12.69  #ifdef CONFIG_BLK_DEV_INITRD
   12.70  	if (LOADER_TYPE && INITRD_START) {
    13.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup64.c	Wed Aug 24 16:16:52 2005 -0700
    13.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup64.c	Thu Aug 25 11:18:47 2005 -0700
    13.3 @@ -286,10 +286,10 @@ void __init cpu_init (void)
    13.4  
    13.5  	memcpy(me->thread.tls_array, cpu_gdt_table[cpu], GDT_ENTRY_TLS_ENTRIES * 8);
    13.6  #else
    13.7 - 	memcpy(me->thread.tls_array, &get_cpu_gdt_table(cpu)[GDT_ENTRY_TLS_MIN],
    13.8 +	memcpy(me->thread.tls_array, &get_cpu_gdt_table(cpu)[GDT_ENTRY_TLS_MIN],
    13.9  	    GDT_ENTRY_TLS_ENTRIES * 8);
   13.10  
   13.11 -    cpu_gdt_init(&cpu_gdt_descr[cpu]);
   13.12 +	cpu_gdt_init(&cpu_gdt_descr[cpu]);
   13.13  #endif
   13.14         
   13.15  	/*
    14.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/smpboot.c	Wed Aug 24 16:16:52 2005 -0700
    14.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/smpboot.c	Thu Aug 25 11:18:47 2005 -0700
    14.3 @@ -739,8 +739,8 @@ static int __cpuinit do_boot_cpu(int cpu
    14.4  	atomic_set(&init_deasserted, 0);
    14.5  
    14.6  #ifdef CONFIG_XEN
    14.7 -	if (cpu_gdt_descr[0].size > PAGE_SIZE)
    14.8 -		BUG();
    14.9 +	cpu_gdt_descr[cpu].address = __get_free_page(GFP_KERNEL);
   14.10 +	BUG_ON(cpu_gdt_descr[0].size > PAGE_SIZE);
   14.11  	cpu_gdt_descr[cpu].size = cpu_gdt_descr[0].size;
   14.12  	memcpy((void *)cpu_gdt_descr[cpu].address,
   14.13  		(void *)cpu_gdt_descr[0].address, cpu_gdt_descr[0].size);
   14.14 @@ -798,6 +798,8 @@ static int __cpuinit do_boot_cpu(int cpu
   14.15  	ctxt.ctrlreg[3] = virt_to_mfn(init_level4_pgt) << PAGE_SHIFT;
   14.16  
   14.17  	boot_error = HYPERVISOR_boot_vcpu(cpu, &ctxt);
   14.18 +	if (boot_error)
   14.19 +		printk("boot error: %ld\n", boot_error);
   14.20  
   14.21  	if (!boot_error) {
   14.22  		/*
    15.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/mm/init.c	Wed Aug 24 16:16:52 2005 -0700
    15.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/mm/init.c	Thu Aug 25 11:18:47 2005 -0700
    15.3 @@ -536,70 +536,38 @@ static void __init find_early_table_spac
    15.4  	    		  round_up(ptes * 8, PAGE_SIZE); 
    15.5  }
    15.6  
    15.7 -static void xen_copy_pt(void)
    15.8 -{
    15.9 -	unsigned long va = __START_KERNEL_map;
   15.10 -	unsigned long addr, *pte_page;
   15.11 -	int i;
   15.12 -	pud_t *pud; pmd_t *pmd; pte_t *pte;
   15.13 -	unsigned long *page = (unsigned long *) init_level4_pgt;
   15.14 -
   15.15 -	addr = (unsigned long) page[pgd_index(va)];
   15.16 -	addr_to_page(addr, page);
   15.17 -
   15.18 -	pud = (pud_t *) &page[pud_index(va)];
   15.19 -	addr = page[pud_index(va)];
   15.20 -	addr_to_page(addr, page);
   15.21 -
   15.22 -	level3_kernel_pgt[pud_index(va)] = 
   15.23 -		__pud(__pa_symbol(level2_kernel_pgt) | _KERNPG_TABLE | _PAGE_USER);
   15.24 -
   15.25 -	for (;;) {
   15.26 -		pmd = (pmd_t *) &page[pmd_index(va)];
   15.27 -		if (pmd_present(*pmd)) {
   15.28 -			level2_kernel_pgt[pmd_index(va)] = *pmd;
   15.29 -			/*
   15.30 -			 * if pmd is valid, check pte.
   15.31 -			 */
   15.32 -			addr = page[pmd_index(va)];
   15.33 -			addr_to_page(addr, pte_page);
   15.34 -			
   15.35 -			for (i = 0; i < PTRS_PER_PTE; i++) {
   15.36 -				pte = (pte_t *) &pte_page[pte_index(va)];
   15.37 -				if (pte_present(*pte))
   15.38 -					va += PAGE_SIZE;
   15.39 -				else
   15.40 -				    break;
   15.41 -			}
   15.42 -
   15.43 -		} else
   15.44 -		    break;
   15.45 -	}
   15.46 -
   15.47 -	init_level4_pgt[pgd_index(__START_KERNEL_map)] = 
   15.48 -		mk_kernel_pgd(__pa_symbol(level3_kernel_pgt));
   15.49 -}
   15.50 -
   15.51  void __init xen_init_pt(void)
   15.52  {
   15.53 +	unsigned long addr, *page;
   15.54  	int i;
   15.55  
   15.56  	for (i = 0; i < NR_CPUS; i++)
   15.57  		per_cpu(cur_pgd, i) = init_mm.pgd;
   15.58  
   15.59 -	memcpy((void *)init_level4_pgt, 
   15.60 -	       (void *)xen_start_info.pt_base, PAGE_SIZE);
   15.61 -
   15.62 +	memset((void *)init_level4_pgt,   0, PAGE_SIZE);
   15.63  	memset((void *)level3_kernel_pgt, 0, PAGE_SIZE);
   15.64  	memset((void *)level2_kernel_pgt, 0, PAGE_SIZE);
   15.65  
   15.66 -	xen_copy_pt();
   15.67 +	/* Find the initial pte page that was built for us. */
   15.68 +	page = (unsigned long *)xen_start_info.pt_base;
   15.69 +	addr = page[pgd_index(__START_KERNEL_map)];
   15.70 +	addr_to_page(addr, page);
   15.71 +	addr = page[pud_index(__START_KERNEL_map)];
   15.72 +	addr_to_page(addr, page);
   15.73 +
   15.74 +	/* Construct mapping of initial pte page in our own directories. */
   15.75 +	init_level4_pgt[pgd_index(__START_KERNEL_map)] = 
   15.76 +		mk_kernel_pgd(__pa_symbol(level3_kernel_pgt));
   15.77 +	level3_kernel_pgt[pud_index(__START_KERNEL_map)] = 
   15.78 +		__pud(__pa_symbol(level2_kernel_pgt) |
   15.79 +		      _KERNPG_TABLE | _PAGE_USER);
   15.80 +        memcpy((void *)level2_kernel_pgt, page, PAGE_SIZE);
   15.81  
   15.82  	make_page_readonly(init_level4_pgt);
   15.83 +	make_page_readonly(init_level4_user_pgt);
   15.84  	make_page_readonly(level3_kernel_pgt);
   15.85 +	make_page_readonly(level3_user_pgt);
   15.86  	make_page_readonly(level2_kernel_pgt);
   15.87 -	make_page_readonly(init_level4_user_pgt);
   15.88 -	make_page_readonly(level3_user_pgt); /* for vsyscall stuff */
   15.89  
   15.90  	xen_pgd_pin(__pa_symbol(init_level4_pgt));
   15.91  	xen_pgd_pin(__pa_symbol(init_level4_user_pgt));
   15.92 @@ -609,7 +577,6 @@ void __init xen_init_pt(void)
   15.93  
   15.94  	set_pgd((pgd_t *)(init_level4_user_pgt + 511), 
   15.95  		mk_kernel_pgd(__pa_symbol(level3_user_pgt)));
   15.96 -
   15.97  }
   15.98  
   15.99  /*
  15.100 @@ -617,69 +584,58 @@ void __init xen_init_pt(void)
  15.101   * mapping done by Xen is minimal (e.g. 8MB) and we need to extend the
  15.102   * mapping for early initialization.
  15.103   */
  15.104 -
  15.105 -#define MIN_INIT_SIZE	0x800000
  15.106  static unsigned long current_size, extended_size;
  15.107  
  15.108  void __init extend_init_mapping(void) 
  15.109  {
  15.110  	unsigned long va = __START_KERNEL_map;
  15.111 -	unsigned long addr, *pte_page;
  15.112 -
  15.113 -	unsigned long phys;
  15.114 +	unsigned long phys, addr, *pte_page;
  15.115          pmd_t *pmd;
  15.116  	pte_t *pte, new_pte;
  15.117  	unsigned long *page = (unsigned long *) init_level4_pgt;
  15.118  	int i;
  15.119  
  15.120 -	addr = (unsigned long) page[pgd_index(va)];
  15.121 +	addr = page[pgd_index(va)];
  15.122  	addr_to_page(addr, page);
  15.123 -
  15.124  	addr = page[pud_index(va)];
  15.125  	addr_to_page(addr, page);
  15.126  
  15.127  	for (;;) {
  15.128 -		pmd = (pmd_t *) &page[pmd_index(va)];
  15.129 -		if (pmd_present(*pmd)) {
  15.130 -			/*
  15.131 -			 * if pmd is valid, check pte.
  15.132 -			 */
  15.133 -			addr = page[pmd_index(va)];
  15.134 -			addr_to_page(addr, pte_page);
  15.135 -			
  15.136 -			for (i = 0; i < PTRS_PER_PTE; i++) {
  15.137 -				pte = (pte_t *) &pte_page[pte_index(va)];
  15.138 -				
  15.139 -				if (pte_present(*pte)) {
  15.140 -					va += PAGE_SIZE;
  15.141 -					current_size += PAGE_SIZE;
  15.142 -				} else
  15.143 -				    break;
  15.144 -			}
  15.145 -
  15.146 -		} else
  15.147 -		    break;
  15.148 +		pmd = (pmd_t *)&page[pmd_index(va)];
  15.149 +		if (!pmd_present(*pmd))
  15.150 +			break;
  15.151 +		addr = page[pmd_index(va)];
  15.152 +		addr_to_page(addr, pte_page);
  15.153 +		for (i = 0; i < PTRS_PER_PTE; i++) {
  15.154 +			pte = (pte_t *) &pte_page[pte_index(va)];
  15.155 +			if (!pte_present(*pte))
  15.156 +				break;
  15.157 +			va += PAGE_SIZE;
  15.158 +			current_size += PAGE_SIZE;
  15.159 +		}
  15.160  	}
  15.161  
  15.162 -	for (; va < __START_KERNEL_map + current_size + tables_space; ) {
  15.163 +	while (va < __START_KERNEL_map + current_size + tables_space) {
  15.164  		pmd = (pmd_t *) &page[pmd_index(va)];
  15.165 -
  15.166 -		if (pmd_none(*pmd)) {
  15.167 -			pte_page = (unsigned long *) alloc_static_page(&phys);
  15.168 -			make_page_readonly(pte_page);
  15.169 -			xen_pte_pin(phys);
  15.170 -			set_pmd(pmd, __pmd(phys | _KERNPG_TABLE | _PAGE_USER));
  15.171 +		if (!pmd_none(*pmd))
  15.172 +			continue;
  15.173 +		pte_page = (unsigned long *) alloc_static_page(&phys);
  15.174 +		make_page_readonly(pte_page);
  15.175 +		xen_pte_pin(phys);
  15.176 +		set_pmd(pmd, __pmd(phys | _KERNPG_TABLE | _PAGE_USER));
  15.177 +		for (i = 0; i < PTRS_PER_PTE; i++, va += PAGE_SIZE) {
  15.178 +			new_pte = pfn_pte(
  15.179 +				(va - __START_KERNEL_map) >> PAGE_SHIFT, 
  15.180 +				__pgprot(_KERNPG_TABLE | _PAGE_USER));
  15.181 +			pte = (pte_t *)&pte_page[pte_index(va)];
  15.182 +			xen_l1_entry_update(pte, new_pte);
  15.183 +			extended_size += PAGE_SIZE;
  15.184 +		}
  15.185 +	}
  15.186  
  15.187 -			for (i = 0; i < PTRS_PER_PTE; i++, va += PAGE_SIZE) {
  15.188 -				new_pte = pfn_pte((va -  __START_KERNEL_map) >> PAGE_SHIFT, 
  15.189 -						  __pgprot(_KERNPG_TABLE | _PAGE_USER));
  15.190 -
  15.191 -				pte = (pte_t *) &pte_page[pte_index(va)];
  15.192 -				xen_l1_entry_update(pte, new_pte);
  15.193 -				extended_size += PAGE_SIZE;
  15.194 -			}
  15.195 -		} 
  15.196 -	}
  15.197 +	/* Kill mapping of low 1MB. */
  15.198 +	for (va = __START_KERNEL_map; va < (unsigned long)&_text; va += PAGE_SIZE)
  15.199 +		HYPERVISOR_update_va_mapping(va, __pte_ma(0), 0);
  15.200  }
  15.201  
  15.202  
  15.203 @@ -720,10 +676,6 @@ void __init init_memory_mapping(unsigned
  15.204  
  15.205          start_pfn = ((current_size + extended_size) >> PAGE_SHIFT);
  15.206  
  15.207 -        /*
  15.208 -         * TBD: Need to calculate at runtime
  15.209 -         */
  15.210 -
  15.211  	__flush_tlb_all();
  15.212          init_mapping_done = 1;
  15.213  }
    16.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Wed Aug 24 16:16:52 2005 -0700
    16.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Thu Aug 25 11:18:47 2005 -0700
    16.3 @@ -57,26 +57,26 @@ static int blkback_remove(struct xenbus_
    16.4  /* Front end tells us frame. */
    16.5  static void frontend_changed(struct xenbus_watch *watch, const char *node)
    16.6  {
    16.7 -	unsigned long sharedmfn;
    16.8 +	unsigned long ring_ref;
    16.9  	unsigned int evtchn;
   16.10  	int err;
   16.11  	struct backend_info *be
   16.12  		= container_of(watch, struct backend_info, watch);
   16.13  
   16.14  	/* If other end is gone, delete ourself. */
   16.15 -	if (!xenbus_exists(be->frontpath, "")) {
   16.16 +	if (node && !xenbus_exists(be->frontpath, "")) {
   16.17  		xenbus_rm(be->dev->nodename, "");
   16.18  		device_unregister(&be->dev->dev);
   16.19  		return;
   16.20  	}
   16.21 -	if (be->blkif->status == CONNECTED)
   16.22 +	if (be->blkif == NULL || be->blkif->status == CONNECTED)
   16.23  		return;
   16.24  
   16.25 -	err = xenbus_gather(be->frontpath, "grant-id", "%lu", &sharedmfn,
   16.26 +	err = xenbus_gather(be->frontpath, "ring-ref", "%lu", &ring_ref,
   16.27  			    "event-channel", "%u", &evtchn, NULL);
   16.28  	if (err) {
   16.29  		xenbus_dev_error(be->dev, err,
   16.30 -				 "reading %s/grant-id and event-channel",
   16.31 +				 "reading %s/ring-ref and event-channel",
   16.32  				 be->frontpath);
   16.33  		return;
   16.34  	}
   16.35 @@ -113,11 +113,10 @@ static void frontend_changed(struct xenb
   16.36  	}
   16.37  
   16.38  	/* Map the shared frame, irq etc. */
   16.39 -	err = blkif_map(be->blkif, sharedmfn, evtchn);
   16.40 +	err = blkif_map(be->blkif, ring_ref, evtchn);
   16.41  	if (err) {
   16.42 -		xenbus_dev_error(be->dev, err,
   16.43 -				 "mapping shared-frame %lu port %u",
   16.44 -				 sharedmfn, evtchn);
   16.45 +		xenbus_dev_error(be->dev, err, "mapping ring-ref %lu port %u",
   16.46 +				 ring_ref, evtchn);
   16.47  		goto abort;
   16.48  	}
   16.49  
   16.50 @@ -139,62 +138,22 @@ static void backend_changed(struct xenbu
   16.51  {
   16.52  	int err;
   16.53  	char *p;
   16.54 -	char *frontend;
   16.55  	long int handle, pdev;
   16.56  	struct backend_info *be
   16.57  		= container_of(watch, struct backend_info, backend_watch);
   16.58  	struct xenbus_device *dev = be->dev;
   16.59  
   16.60 -	frontend = NULL;
   16.61 -	err = xenbus_gather(dev->nodename,
   16.62 -			    "frontend-id", "%li", &be->frontend_id,
   16.63 -			    "frontend", NULL, &frontend,
   16.64 -			    NULL);
   16.65 -	if (XENBUS_EXIST_ERR(err) ||
   16.66 -	    strlen(frontend) == 0 || !xenbus_exists(frontend, "")) {
   16.67 -		/* If we can't get a frontend path and a frontend-id,
   16.68 -		 * then our bus-id is no longer valid and we need to
   16.69 -		 * destroy the backend device.
   16.70 -		 */
   16.71 -		goto device_fail;
   16.72 -	}
   16.73 -	if (err < 0) {
   16.74 -		xenbus_dev_error(dev, err,
   16.75 -				 "reading %s/frontend or frontend-id",
   16.76 -				 dev->nodename);
   16.77 -		goto device_fail;
   16.78 -	}
   16.79 -
   16.80 -	if (!be->frontpath || strcmp(frontend, be->frontpath)) {
   16.81 -		if (be->watch.node)
   16.82 -			unregister_xenbus_watch(&be->watch);
   16.83 -		if (be->frontpath)
   16.84 -			kfree(be->frontpath);
   16.85 -		be->frontpath = frontend;
   16.86 -		frontend = NULL;
   16.87 -		be->watch.node = be->frontpath;
   16.88 -		be->watch.callback = frontend_changed;
   16.89 -		err = register_xenbus_watch(&be->watch);
   16.90 -		if (err) {
   16.91 -			be->watch.node = NULL;
   16.92 -			xenbus_dev_error(dev, err,
   16.93 -					 "adding frontend watch on %s",
   16.94 -					 be->frontpath);
   16.95 -			goto device_fail;
   16.96 -		}
   16.97 -	}
   16.98 -
   16.99  	err = xenbus_scanf(dev->nodename, "physical-device", "%li", &pdev);
  16.100  	if (XENBUS_EXIST_ERR(err))
  16.101 -		goto out;
  16.102 +		return;
  16.103  	if (err < 0) {
  16.104  		xenbus_dev_error(dev, err, "reading physical-device");
  16.105 -		goto device_fail;
  16.106 +		return;
  16.107  	}
  16.108  	if (be->pdev && be->pdev != pdev) {
  16.109  		printk(KERN_WARNING
  16.110  		       "changing physical-device not supported\n");
  16.111 -		goto device_fail;
  16.112 +		return;
  16.113  	}
  16.114  	be->pdev = pdev;
  16.115  
  16.116 @@ -215,32 +174,25 @@ static void backend_changed(struct xenbu
  16.117  			err = PTR_ERR(be->blkif);
  16.118  			be->blkif = NULL;
  16.119  			xenbus_dev_error(dev, err, "creating block interface");
  16.120 -			goto device_fail;
  16.121 +			return;
  16.122  		}
  16.123  
  16.124  		err = vbd_create(be->blkif, handle, be->pdev, be->readonly);
  16.125  		if (err) {
  16.126  			xenbus_dev_error(dev, err, "creating vbd structure");
  16.127 -			goto device_fail;
  16.128 +			return;
  16.129  		}
  16.130  
  16.131 -		frontend_changed(&be->watch, be->frontpath);
  16.132 +		/* Pass in NULL node to skip exist test. */
  16.133 +		frontend_changed(&be->watch, NULL);
  16.134  	}
  16.135 -
  16.136 - out:
  16.137 -	if (frontend)
  16.138 -		kfree(frontend);
  16.139 -	return;
  16.140 -
  16.141 - device_fail:
  16.142 -	device_unregister(&be->dev->dev);
  16.143 -	goto out;
  16.144  }
  16.145  
  16.146  static int blkback_probe(struct xenbus_device *dev,
  16.147  			 const struct xenbus_device_id *id)
  16.148  {
  16.149  	struct backend_info *be;
  16.150 +	char *frontend;
  16.151  	int err;
  16.152  
  16.153  	be = kmalloc(sizeof(*be), GFP_KERNEL);
  16.154 @@ -248,24 +200,63 @@ static int blkback_probe(struct xenbus_d
  16.155  		xenbus_dev_error(dev, -ENOMEM, "allocating backend structure");
  16.156  		return -ENOMEM;
  16.157  	}
  16.158 +	memset(be, 0, sizeof(*be));
  16.159  
  16.160 -	memset(be, 0, sizeof(*be));
  16.161 +	frontend = NULL;
  16.162 +	err = xenbus_gather(dev->nodename,
  16.163 +			    "frontend-id", "%li", &be->frontend_id,
  16.164 +			    "frontend", NULL, &frontend,
  16.165 +			    NULL);
  16.166 +	if (XENBUS_EXIST_ERR(err))
  16.167 +		goto free_be;
  16.168 +	if (err < 0) {
  16.169 +		xenbus_dev_error(dev, err,
  16.170 +				 "reading %s/frontend or frontend-id",
  16.171 +				 dev->nodename);
  16.172 +		goto free_be;
  16.173 +	}
  16.174 +	if (strlen(frontend) == 0 || !xenbus_exists(frontend, "")) {
  16.175 +		/* If we can't get a frontend path and a frontend-id,
  16.176 +		 * then our bus-id is no longer valid and we need to
  16.177 +		 * destroy the backend device.
  16.178 +		 */
  16.179 +		err = -ENOENT;
  16.180 +		goto free_be;
  16.181 +	}
  16.182  
  16.183  	be->dev = dev;
  16.184  	be->backend_watch.node = dev->nodename;
  16.185  	be->backend_watch.callback = backend_changed;
  16.186  	err = register_xenbus_watch(&be->backend_watch);
  16.187  	if (err) {
  16.188 +		be->backend_watch.node = NULL;
  16.189  		xenbus_dev_error(dev, err, "adding backend watch on %s",
  16.190  				 dev->nodename);
  16.191  		goto free_be;
  16.192  	}
  16.193  
  16.194 +	be->frontpath = frontend;
  16.195 +	be->watch.node = be->frontpath;
  16.196 +	be->watch.callback = frontend_changed;
  16.197 +	err = register_xenbus_watch(&be->watch);
  16.198 +	if (err) {
  16.199 +		be->watch.node = NULL;
  16.200 +		xenbus_dev_error(dev, err,
  16.201 +				 "adding frontend watch on %s",
  16.202 +				 be->frontpath);
  16.203 +		goto free_be;
  16.204 +	}
  16.205 +
  16.206  	dev->data = be;
  16.207  
  16.208  	backend_changed(&be->backend_watch, dev->nodename);
  16.209 -	return err;
  16.210 +	return 0;
  16.211 +
  16.212   free_be:
  16.213 +	if (be->backend_watch.node)
  16.214 +		unregister_xenbus_watch(&be->backend_watch);
  16.215 +	if (frontend)
  16.216 +		kfree(frontend);
  16.217  	kfree(be);
  16.218  	return err;
  16.219  }
    17.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Wed Aug 24 16:16:52 2005 -0700
    17.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Thu Aug 25 11:18:47 2005 -0700
    17.3 @@ -1084,7 +1084,8 @@ static void watch_for_status(struct xenb
    17.4  			    "sector-size", "%lu", &sector_size,
    17.5  			    NULL);
    17.6  	if (err) {
    17.7 -		xenbus_dev_error(info->xbdev, err, "reading backend fields");
    17.8 +		xenbus_dev_error(info->xbdev, err,
    17.9 +				 "reading backend fields at %s", watch->node);
   17.10  		return;
   17.11  	}
   17.12  
   17.13 @@ -1123,12 +1124,12 @@ static int setup_blkring(struct xenbus_d
   17.14  		xenbus_dev_error(dev, err, "granting access to ring page");
   17.15  		return err;
   17.16  	}
   17.17 -	info->grant_id = err;
   17.18 +	info->ring_ref = err;
   17.19  
   17.20  	op.u.alloc_unbound.dom = info->backend_id;
   17.21  	err = HYPERVISOR_event_channel_op(&op);
   17.22  	if (err) {
   17.23 -		gnttab_end_foreign_access(info->grant_id, 0);
   17.24 +		gnttab_end_foreign_access(info->ring_ref, 0);
   17.25  		free_page((unsigned long)info->ring.sring);
   17.26  		info->ring.sring = 0;
   17.27  		xenbus_dev_error(dev, err, "allocating event channel");
   17.28 @@ -1176,9 +1177,9 @@ static int talk_to_backend(struct xenbus
   17.29  		goto destroy_blkring;
   17.30  	}
   17.31  
   17.32 -	err = xenbus_printf(dev->nodename, "grant-id","%u", info->grant_id);
   17.33 +	err = xenbus_printf(dev->nodename, "ring-ref","%u", info->ring_ref);
   17.34  	if (err) {
   17.35 -		message = "writing grant-id";
   17.36 +		message = "writing ring-ref";
   17.37  		goto abort_transaction;
   17.38  	}
   17.39  	err = xenbus_printf(dev->nodename,
    18.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/block.h	Wed Aug 24 16:16:52 2005 -0700
    18.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/block.h	Thu Aug 25 11:18:47 2005 -0700
    18.3 @@ -112,7 +112,7 @@ struct blkfront_info
    18.4  	int connected;
    18.5  	char *backend;
    18.6  	int backend_id;
    18.7 -	int grant_id;
    18.8 +	int ring_ref;
    18.9  	blkif_front_ring_t ring;
   18.10  	unsigned int evtchn;
   18.11  	struct xlbd_major_info *mi;
    19.1 --- a/linux-2.6-xen-sparse/drivers/xen/console/console.c	Wed Aug 24 16:16:52 2005 -0700
    19.2 +++ b/linux-2.6-xen-sparse/drivers/xen/console/console.c	Thu Aug 25 11:18:47 2005 -0700
    19.3 @@ -240,7 +240,11 @@ console_initcall(xen_console_init);
    19.4  #endif
    19.5  
    19.6  /*** Useful function for console debugging -- goes straight to Xen. ***/
    19.7 +#ifdef CONFIG_XEN_PRIVILEGED_GUEST
    19.8  asmlinkage int xprintk(const char *fmt, ...)
    19.9 +#else
   19.10 +asmlinkage int xprintk(const char *fmt, ...)
   19.11 +#endif
   19.12  {
   19.13      va_list args;
   19.14      int printk_len;
    20.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/Makefile	Wed Aug 24 16:16:52 2005 -0700
    20.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/Makefile	Thu Aug 25 11:18:47 2005 -0700
    20.3 @@ -1,2 +1,2 @@
    20.4  
    20.5 -obj-y	:= netback.o control.o interface.o loopback.o
    20.6 +obj-y	:= netback.o xenbus.o interface.o loopback.o
    21.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/common.h	Wed Aug 24 16:16:52 2005 -0700
    21.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/common.h	Thu Aug 25 11:18:47 2005 -0700
    21.3 @@ -59,6 +59,7 @@ typedef struct netif_st {
    21.4      grant_ref_t      rx_shmem_ref; 
    21.5  #endif
    21.6      unsigned int     evtchn;
    21.7 +    unsigned int     remote_evtchn;
    21.8  
    21.9      /* The shared rings and indexes. */
   21.10      netif_tx_interface_t *tx;
   21.11 @@ -82,36 +83,30 @@ typedef struct netif_st {
   21.12      /* Miscellaneous private stuff. */
   21.13      enum { DISCONNECTED, DISCONNECTING, CONNECTED } status;
   21.14      int active;
   21.15 -    /*
   21.16 -     * DISCONNECT response is deferred until pending requests are ack'ed.
   21.17 -     * We therefore need to store the id from the original request.
   21.18 -     */
   21.19 -    u8               disconnect_rspid;
   21.20 -    struct netif_st *hash_next;
   21.21      struct list_head list;  /* scheduling list */
   21.22      atomic_t         refcnt;
   21.23      struct net_device *dev;
   21.24      struct net_device_stats stats;
   21.25  
   21.26 -    struct work_struct work;
   21.27 +    struct work_struct free_work;
   21.28  } netif_t;
   21.29  
   21.30 -void netif_create(netif_be_create_t *create);
   21.31 -void netif_destroy(netif_be_destroy_t *destroy);
   21.32 -void netif_creditlimit(netif_be_creditlimit_t *creditlimit);
   21.33 -void netif_connect(netif_be_connect_t *connect);
   21.34 -int  netif_disconnect(netif_be_disconnect_t *disconnect, u8 rsp_id);
   21.35 -void netif_disconnect_complete(netif_t *netif);
   21.36 -netif_t *netif_find_by_handle(domid_t domid, unsigned int handle);
   21.37 +void netif_creditlimit(netif_t *netif);
   21.38 +int  netif_disconnect(netif_t *netif);
   21.39 +
   21.40 +netif_t *alloc_netif(domid_t domid, unsigned int handle, u8 be_mac[ETH_ALEN]);
   21.41 +void free_netif_callback(netif_t *netif);
   21.42 +int netif_map(netif_t *netif, unsigned long tx_ring_ref,
   21.43 +	      unsigned long rx_ring_ref, unsigned int evtchn);
   21.44 +
   21.45  #define netif_get(_b) (atomic_inc(&(_b)->refcnt))
   21.46  #define netif_put(_b)                             \
   21.47      do {                                          \
   21.48          if ( atomic_dec_and_test(&(_b)->refcnt) ) \
   21.49 -            netif_disconnect_complete(_b);        \
   21.50 +            free_netif_callback(_b);              \
   21.51      } while (0)
   21.52  
   21.53 -void netif_interface_init(void);
   21.54 -void netif_ctrlif_init(void);
   21.55 +void netif_xenbus_init(void);
   21.56  
   21.57  void netif_schedule_work(netif_t *netif);
   21.58  void netif_deschedule_work(netif_t *netif);
    22.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/control.c	Wed Aug 24 16:16:52 2005 -0700
    22.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.3 @@ -1,58 +0,0 @@
    22.4 -/******************************************************************************
    22.5 - * arch/xen/drivers/netif/backend/control.c
    22.6 - * 
    22.7 - * Routines for interfacing with the control plane.
    22.8 - * 
    22.9 - * Copyright (c) 2004, Keir Fraser
   22.10 - */
   22.11 -
   22.12 -#include "common.h"
   22.13 -
   22.14 -static void netif_ctrlif_rx(ctrl_msg_t *msg, unsigned long id)
   22.15 -{
   22.16 -    DPRINTK("Received netif backend message, subtype=%d\n", msg->subtype);
   22.17 -    
   22.18 -    switch ( msg->subtype )
   22.19 -    {
   22.20 -    case CMSG_NETIF_BE_CREATE:
   22.21 -        netif_create((netif_be_create_t *)&msg->msg[0]);
   22.22 -        break;        
   22.23 -    case CMSG_NETIF_BE_DESTROY:
   22.24 -        netif_destroy((netif_be_destroy_t *)&msg->msg[0]);
   22.25 -        break;  
   22.26 -    case CMSG_NETIF_BE_CREDITLIMIT:
   22.27 -        netif_creditlimit((netif_be_creditlimit_t *)&msg->msg[0]);
   22.28 -        break;       
   22.29 -    case CMSG_NETIF_BE_CONNECT:
   22.30 -        netif_connect((netif_be_connect_t *)&msg->msg[0]);
   22.31 -        break; 
   22.32 -    case CMSG_NETIF_BE_DISCONNECT:
   22.33 -        if ( !netif_disconnect((netif_be_disconnect_t *)&msg->msg[0],msg->id) )
   22.34 -            return; /* Sending the response is deferred until later. */
   22.35 -        break;        
   22.36 -    default:
   22.37 -        DPRINTK("Parse error while reading message subtype %d, len %d\n",
   22.38 -                msg->subtype, msg->length);
   22.39 -        msg->length = 0;
   22.40 -        break;
   22.41 -    }
   22.42 -
   22.43 -    ctrl_if_send_response(msg);
   22.44 -}
   22.45 -
   22.46 -void netif_ctrlif_init(void)
   22.47 -{
   22.48 -    ctrl_msg_t cmsg;
   22.49 -    netif_be_driver_status_t st;
   22.50 -
   22.51 -    (void)ctrl_if_register_receiver(CMSG_NETIF_BE, netif_ctrlif_rx,
   22.52 -                                    CALLBACK_IN_BLOCKING_CONTEXT);
   22.53 -
   22.54 -    /* Send a driver-UP notification to the domain controller. */
   22.55 -    cmsg.type      = CMSG_NETIF_BE;
   22.56 -    cmsg.subtype   = CMSG_NETIF_BE_DRIVER_STATUS;
   22.57 -    cmsg.length    = sizeof(netif_be_driver_status_t);
   22.58 -    st.status      = NETIF_DRIVER_STATUS_UP;
   22.59 -    memcpy(cmsg.msg, &st, sizeof(st));
   22.60 -    ctrl_if_send_message_block(&cmsg, NULL, 0, TASK_UNINTERRUPTIBLE);
   22.61 -}
    23.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Wed Aug 24 16:16:52 2005 -0700
    23.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Thu Aug 25 11:18:47 2005 -0700
    23.3 @@ -9,24 +9,6 @@
    23.4  #include "common.h"
    23.5  #include <linux/rtnetlink.h>
    23.6  
    23.7 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    23.8 -#define VMALLOC_VMADDR(x) ((unsigned long)(x))
    23.9 -#endif
   23.10 -
   23.11 -#define NETIF_HASHSZ 1024
   23.12 -#define NETIF_HASH(_d,_h) (((int)(_d)^(int)(_h))&(NETIF_HASHSZ-1))
   23.13 -
   23.14 -static netif_t *netif_hash[NETIF_HASHSZ];
   23.15 -
   23.16 -netif_t *netif_find_by_handle(domid_t domid, unsigned int handle)
   23.17 -{
   23.18 -    netif_t *netif = netif_hash[NETIF_HASH(domid, handle)];
   23.19 -    while ( (netif != NULL) && 
   23.20 -            ((netif->domid != domid) || (netif->handle != handle)) )
   23.21 -        netif = netif->hash_next;
   23.22 -    return netif;
   23.23 -}
   23.24 -
   23.25  static void __netif_up(netif_t *netif)
   23.26  {
   23.27      struct net_device *dev = netif->dev;
   23.28 @@ -51,7 +33,7 @@ static void __netif_down(netif_t *netif)
   23.29  static int net_open(struct net_device *dev)
   23.30  {
   23.31      netif_t *netif = netdev_priv(dev);
   23.32 -    if ( netif->status == CONNECTED )
   23.33 +    if (netif->status == CONNECTED)
   23.34          __netif_up(netif);
   23.35      netif_start_queue(dev);
   23.36      return 0;
   23.37 @@ -61,92 +43,23 @@ static int net_close(struct net_device *
   23.38  {
   23.39      netif_t *netif = netdev_priv(dev);
   23.40      netif_stop_queue(dev);
   23.41 -    if ( netif->status == CONNECTED )
   23.42 +    if (netif->status == CONNECTED)
   23.43          __netif_down(netif);
   23.44      return 0;
   23.45  }
   23.46  
   23.47 -static void __netif_disconnect_complete(void *arg)
   23.48 +netif_t *alloc_netif(domid_t domid, unsigned int handle, u8 be_mac[ETH_ALEN])
   23.49  {
   23.50 -    netif_t              *netif = (netif_t *)arg;
   23.51 -    ctrl_msg_t            cmsg;
   23.52 -    netif_be_disconnect_t disc;
   23.53 -#if defined(CONFIG_XEN_NETDEV_GRANT_RX) || defined(CONFIG_XEN_NETDEV_GRANT_TX)
   23.54 -    struct gnttab_unmap_grant_ref op;
   23.55 -#endif
   23.56 -
   23.57 -    /*
   23.58 -     * These can't be done in netif_disconnect() because at that point there
   23.59 -     * may be outstanding requests in the network stack whose asynchronous
   23.60 -     * responses must still be notified to the remote driver.
   23.61 -     */
   23.62 -
   23.63 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
   23.64 -    op.host_addr    = netif->tx_shmem_vaddr;
   23.65 -    op.handle       = netif->tx_shmem_handle;
   23.66 -    op.dev_bus_addr = 0;
   23.67 -    BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   23.68 -#endif
   23.69 -
   23.70 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
   23.71 -    op.host_addr    = netif->rx_shmem_vaddr;
   23.72 -    op.handle       = netif->rx_shmem_handle;
   23.73 -    op.dev_bus_addr = 0;
   23.74 -    BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   23.75 -#endif
   23.76 -
   23.77 -
   23.78 -    vfree(netif->tx); /* Frees netif->rx as well. */
   23.79 -
   23.80 -    /* Construct the deferred response message. */
   23.81 -    cmsg.type         = CMSG_NETIF_BE;
   23.82 -    cmsg.subtype      = CMSG_NETIF_BE_DISCONNECT;
   23.83 -    cmsg.id           = netif->disconnect_rspid;
   23.84 -    cmsg.length       = sizeof(netif_be_disconnect_t);
   23.85 -    disc.domid        = netif->domid;
   23.86 -    disc.netif_handle = netif->handle;
   23.87 -    disc.status       = NETIF_BE_STATUS_OKAY;
   23.88 -    memcpy(cmsg.msg, &disc, sizeof(disc));
   23.89 -
   23.90 -    /*
   23.91 -     * Make sure message is constructed /before/ status change, because
   23.92 -     * after the status change the 'netif' structure could be deallocated at
   23.93 -     * any time. Also make sure we send the response /after/ status change,
   23.94 -     * as otherwise a subsequent CONNECT request could spuriously fail if
   23.95 -     * another CPU doesn't see the status change yet.
   23.96 -     */
   23.97 -    mb();
   23.98 -    if ( netif->status != DISCONNECTING )
   23.99 -        BUG();
  23.100 -    netif->status = DISCONNECTED;
  23.101 -    mb();
  23.102 -
  23.103 -    /* Send the successful response. */
  23.104 -    ctrl_if_send_response(&cmsg);
  23.105 -}
  23.106 -
  23.107 -void netif_disconnect_complete(netif_t *netif)
  23.108 -{
  23.109 -    INIT_WORK(&netif->work, __netif_disconnect_complete, (void *)netif);
  23.110 -    schedule_work(&netif->work);
  23.111 -}
  23.112 -
  23.113 -void netif_create(netif_be_create_t *create)
  23.114 -{
  23.115 -    int                err = 0;
  23.116 -    domid_t            domid  = create->domid;
  23.117 -    unsigned int       handle = create->netif_handle;
  23.118 +    int err = 0, i;
  23.119      struct net_device *dev;
  23.120 -    netif_t          **pnetif, *netif;
  23.121 -    char               name[IFNAMSIZ] = {};
  23.122 +    netif_t *netif;
  23.123 +    char name[IFNAMSIZ] = {};
  23.124  
  23.125      snprintf(name, IFNAMSIZ - 1, "vif%u.%u", domid, handle);
  23.126      dev = alloc_netdev(sizeof(netif_t), name, ether_setup);
  23.127 -    if ( dev == NULL )
  23.128 -    {
  23.129 +    if (dev == NULL) {
  23.130          DPRINTK("Could not create netif: out of memory\n");
  23.131 -        create->status = NETIF_BE_STATUS_OUT_OF_MEMORY;
  23.132 -        return;
  23.133 +        return NULL;
  23.134      }
  23.135  
  23.136      netif = netdev_priv(dev);
  23.137 @@ -161,19 +74,6 @@ void netif_create(netif_be_create_t *cre
  23.138      netif->credit_usec  = 0UL;
  23.139      init_timer(&netif->credit_timeout);
  23.140  
  23.141 -    pnetif = &netif_hash[NETIF_HASH(domid, handle)];
  23.142 -    while ( *pnetif != NULL )
  23.143 -    {
  23.144 -        if ( ((*pnetif)->domid == domid) && ((*pnetif)->handle == handle) )
  23.145 -        {
  23.146 -            DPRINTK("Could not create netif: already exists\n");
  23.147 -            create->status = NETIF_BE_STATUS_INTERFACE_EXISTS;
  23.148 -            free_netdev(dev);
  23.149 -            return;
  23.150 -        }
  23.151 -        pnetif = &(*pnetif)->hash_next;
  23.152 -    }
  23.153 -
  23.154      dev->hard_start_xmit = netif_be_start_xmit;
  23.155      dev->get_stats       = netif_be_get_stats;
  23.156      dev->open            = net_open;
  23.157 @@ -183,10 +83,10 @@ void netif_create(netif_be_create_t *cre
  23.158      /* Disable queuing. */
  23.159      dev->tx_queue_len = 0;
  23.160  
  23.161 -    if ( (create->be_mac[0] == 0) && (create->be_mac[1] == 0) &&
  23.162 -         (create->be_mac[2] == 0) && (create->be_mac[3] == 0) &&
  23.163 -         (create->be_mac[4] == 0) && (create->be_mac[5] == 0) )
  23.164 -    {
  23.165 +    for (i = 0; i < ETH_ALEN; i++)
  23.166 +	if (be_mac[i] != 0)
  23.167 +	    break;
  23.168 +    if (i == ETH_ALEN) {
  23.169          /*
  23.170           * Initialise a dummy MAC address. We choose the numerically largest
  23.171           * non-broadcast address to prevent the address getting stolen by an
  23.172 @@ -194,87 +94,200 @@ void netif_create(netif_be_create_t *cre
  23.173           */ 
  23.174          memset(dev->dev_addr, 0xFF, ETH_ALEN);
  23.175          dev->dev_addr[0] &= ~0x01;
  23.176 -    }
  23.177 -    else
  23.178 -    {
  23.179 -        memcpy(dev->dev_addr, create->be_mac, ETH_ALEN);
  23.180 -    }
  23.181 -
  23.182 -    memcpy(netif->fe_dev_addr, create->mac, ETH_ALEN);
  23.183 +    } else
  23.184 +        memcpy(dev->dev_addr, be_mac, ETH_ALEN);
  23.185  
  23.186      rtnl_lock();
  23.187      err = register_netdevice(dev);
  23.188      rtnl_unlock();
  23.189 -
  23.190 -    if ( err != 0 )
  23.191 -    {
  23.192 +    if (err) {
  23.193          DPRINTK("Could not register new net device %s: err=%d\n",
  23.194                  dev->name, err);
  23.195 -        create->status = NETIF_BE_STATUS_OUT_OF_MEMORY;
  23.196          free_netdev(dev);
  23.197 -        return;
  23.198 +        return NULL;
  23.199      }
  23.200  
  23.201 -    netif->hash_next = *pnetif;
  23.202 -    *pnetif = netif;
  23.203 -
  23.204      DPRINTK("Successfully created netif\n");
  23.205 -    create->status = NETIF_BE_STATUS_OKAY;
  23.206 +    return netif;
  23.207  }
  23.208  
  23.209 -void netif_destroy(netif_be_destroy_t *destroy)
  23.210 +static int map_frontend_page(netif_t *netif, unsigned long localaddr,
  23.211 +			     unsigned long tx_ring_ref, unsigned long rx_ring_ref)
  23.212  {
  23.213 -    domid_t       domid  = destroy->domid;
  23.214 -    unsigned int  handle = destroy->netif_handle;
  23.215 -    netif_t     **pnetif, *netif;
  23.216 +#if !defined(CONFIG_XEN_NETDEV_GRANT_TX)||!defined(CONFIG_XEN_NETDEV_GRANT_RX)
  23.217 +    pgprot_t      prot = __pgprot(_KERNPG_TABLE);
  23.218 +    int           err;
  23.219 +#endif
  23.220 +#if defined(CONFIG_XEN_NETDEV_GRANT_TX)
  23.221 +    {
  23.222 +        struct gnttab_map_grant_ref op;
  23.223  
  23.224 -    pnetif = &netif_hash[NETIF_HASH(domid, handle)];
  23.225 -    while ( (netif = *pnetif) != NULL )
  23.226 +        /* Map: Use the Grant table reference */
  23.227 +        op.host_addr = localaddr;
  23.228 +        op.flags     = GNTMAP_host_map;
  23.229 +        op.ref       = tx_ring_ref;
  23.230 +        op.dom       = netif->domid;
  23.231 +       
  23.232 +	BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) );
  23.233 +        if (op.handle < 0) { 
  23.234 +            DPRINTK(" Grant table operation failure !\n");
  23.235 +            return op.handle;
  23.236 +        }
  23.237 +
  23.238 +        netif->tx_shmem_ref    = tx_ring_ref;
  23.239 +        netif->tx_shmem_handle = op.handle;
  23.240 +        netif->tx_shmem_vaddr  = localaddr;
  23.241 +    }
  23.242 +#else 
  23.243 +    err = direct_remap_area_pages(&init_mm, localaddr,
  23.244 +				  tx_ring_ref<<PAGE_SHIFT, PAGE_SIZE,
  23.245 +				  prot, netif->domid); 
  23.246 +    if (err)
  23.247 +	return err;
  23.248 +#endif
  23.249 +
  23.250 +#if defined(CONFIG_XEN_NETDEV_GRANT_RX)
  23.251      {
  23.252 -        if ( (netif->domid == domid) && (netif->handle == handle) )
  23.253 -        {
  23.254 -            if ( netif->status != DISCONNECTED )
  23.255 -                goto still_connected;
  23.256 -            goto destroy;
  23.257 +        struct gnttab_map_grant_ref op;
  23.258 +
  23.259 +        /* Map: Use the Grant table reference */
  23.260 +        op.host_addr = localaddr + PAGE_SIZE;
  23.261 +        op.flags     = GNTMAP_host_map;
  23.262 +        op.ref       = rx_ring_ref;
  23.263 +        op.dom       = netif->domid;
  23.264 +
  23.265 +	BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) );
  23.266 +        if (op.handle < 0) { 
  23.267 +            DPRINTK(" Grant table operation failure !\n");
  23.268 +            return op.handle;
  23.269          }
  23.270 -        pnetif = &netif->hash_next;
  23.271 +
  23.272 +        netif->rx_shmem_ref    = rx_ring_ref;
  23.273 +        netif->rx_shmem_handle = op.handle;
  23.274 +        netif->rx_shmem_vaddr  = localaddr + PAGE_SIZE;
  23.275 +    }
  23.276 +#else 
  23.277 +    err = direct_remap_area_pages(&init_mm, localaddr + PAGE_SIZE,
  23.278 +				  rx_ring_ref<<PAGE_SHIFT, PAGE_SIZE,
  23.279 +				  prot, netif->domid);
  23.280 +    if (err)
  23.281 +	return err;
  23.282 +#endif
  23.283 +
  23.284 +    return 0;
  23.285 +}
  23.286 +
  23.287 +static void unmap_frontend_page(netif_t *netif)
  23.288 +{
  23.289 +#if defined(CONFIG_XEN_NETDEV_GRANT_RX) || defined(CONFIG_XEN_NETDEV_GRANT_TX)
  23.290 +    struct gnttab_unmap_grant_ref op;
  23.291 +#endif
  23.292 +
  23.293 +#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  23.294 +    op.host_addr    = netif->tx_shmem_vaddr;
  23.295 +    op.handle       = netif->tx_shmem_handle;
  23.296 +    op.dev_bus_addr = 0;
  23.297 +    BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
  23.298 +#endif
  23.299 +
  23.300 +#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  23.301 +    op.host_addr    = netif->rx_shmem_vaddr;
  23.302 +    op.handle       = netif->rx_shmem_handle;
  23.303 +    op.dev_bus_addr = 0;
  23.304 +    BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
  23.305 +#endif
  23.306 +}
  23.307 +
  23.308 +int netif_map(netif_t *netif, unsigned long tx_ring_ref,
  23.309 +	      unsigned long rx_ring_ref, unsigned int evtchn)
  23.310 +{
  23.311 +    struct vm_struct *vma;
  23.312 +    evtchn_op_t op = { .cmd = EVTCHNOP_bind_interdomain };
  23.313 +    int err;
  23.314 +
  23.315 +    vma = get_vm_area(2*PAGE_SIZE, VM_IOREMAP);
  23.316 +    if (vma == NULL)
  23.317 +        return -ENOMEM;
  23.318 +
  23.319 +    err = map_frontend_page(netif, (unsigned long)vma->addr, tx_ring_ref,
  23.320 +			    rx_ring_ref);
  23.321 +    if (err) {
  23.322 +        vfree(vma->addr);
  23.323 +	return err;
  23.324      }
  23.325  
  23.326 -    destroy->status = NETIF_BE_STATUS_INTERFACE_NOT_FOUND;
  23.327 -    return;
  23.328 +    op.u.bind_interdomain.dom1 = DOMID_SELF;
  23.329 +    op.u.bind_interdomain.dom2 = netif->domid;
  23.330 +    op.u.bind_interdomain.port1 = 0;
  23.331 +    op.u.bind_interdomain.port2 = evtchn;
  23.332 +    err = HYPERVISOR_event_channel_op(&op);
  23.333 +    if (err) {
  23.334 +	unmap_frontend_page(netif);
  23.335 +	vfree(vma->addr);
  23.336 +	return err;
  23.337 +    }
  23.338  
  23.339 - still_connected:
  23.340 -    destroy->status = NETIF_BE_STATUS_INTERFACE_CONNECTED;
  23.341 -    return;
  23.342 +    netif->evtchn = op.u.bind_interdomain.port1;
  23.343 +    netif->remote_evtchn = evtchn;
  23.344  
  23.345 - destroy:
  23.346 -    *pnetif = netif->hash_next;
  23.347 -    unregister_netdev(netif->dev);
  23.348 -    free_netdev(netif->dev);
  23.349 -    destroy->status = NETIF_BE_STATUS_OKAY;
  23.350 +    netif->tx = (netif_tx_interface_t *)vma->addr;
  23.351 +    netif->rx = (netif_rx_interface_t *)((char *)vma->addr + PAGE_SIZE);
  23.352 +    netif->tx->resp_prod = netif->rx->resp_prod = 0;
  23.353 +    netif_get(netif);
  23.354 +    wmb(); /* Other CPUs see new state before interface is started. */
  23.355 +
  23.356 +    rtnl_lock();
  23.357 +    netif->status = CONNECTED;
  23.358 +    wmb();
  23.359 +    if (netif_running(netif->dev))
  23.360 +        __netif_up(netif);
  23.361 +    rtnl_unlock();
  23.362 +
  23.363 +    return 0;
  23.364  }
  23.365  
  23.366 -void netif_creditlimit(netif_be_creditlimit_t *creditlimit)
  23.367 +static void free_netif(void *arg)
  23.368  {
  23.369 -    domid_t       domid  = creditlimit->domid;
  23.370 -    unsigned int  handle = creditlimit->netif_handle;
  23.371 -    netif_t      *netif;
  23.372 +    evtchn_op_t op = { .cmd = EVTCHNOP_close };
  23.373 +    netif_t *netif = (netif_t *)arg;
  23.374  
  23.375 -    netif = netif_find_by_handle(domid, handle);
  23.376 -    if ( unlikely(netif == NULL) )
  23.377 -    {
  23.378 -        DPRINTK("netif_creditlimit attempted for non-existent netif"
  23.379 -                " (%u,%u)\n", creditlimit->domid, creditlimit->netif_handle); 
  23.380 -        creditlimit->status = NETIF_BE_STATUS_INTERFACE_NOT_FOUND;
  23.381 -        return; 
  23.382 +    /*
  23.383 +     * These can't be done in netif_disconnect() because at that point there
  23.384 +     * may be outstanding requests in the network stack whose asynchronous
  23.385 +     * responses must still be notified to the remote driver.
  23.386 +     */
  23.387 +
  23.388 +    op.u.close.port = netif->evtchn;
  23.389 +    op.u.close.dom = DOMID_SELF;
  23.390 +    HYPERVISOR_event_channel_op(&op);
  23.391 +    op.u.close.port = netif->remote_evtchn;
  23.392 +    op.u.close.dom = netif->domid;
  23.393 +    HYPERVISOR_event_channel_op(&op);
  23.394 +
  23.395 +    unregister_netdev(netif->dev);
  23.396 +
  23.397 +    if (netif->tx) {
  23.398 +	unmap_frontend_page(netif);
  23.399 +	vfree(netif->tx); /* Frees netif->rx as well. */
  23.400      }
  23.401  
  23.402 +    free_netdev(netif->dev);
  23.403 +}
  23.404 +
  23.405 +void free_netif_callback(netif_t *netif)
  23.406 +{
  23.407 +    INIT_WORK(&netif->free_work, free_netif, (void *)netif);
  23.408 +    schedule_work(&netif->free_work);
  23.409 +}
  23.410 +
  23.411 +void netif_creditlimit(netif_t *netif)
  23.412 +{
  23.413 +#if 0
  23.414      /* Set the credit limit (reset remaining credit to new limit). */
  23.415      netif->credit_bytes = netif->remaining_credit = creditlimit->credit_bytes;
  23.416      netif->credit_usec = creditlimit->period_usec;
  23.417  
  23.418 -    if ( netif->status == CONNECTED )
  23.419 -    {
  23.420 +    if (netif->status == CONNECTED) {
  23.421          /*
  23.422           * Schedule work so that any packets waiting under previous credit 
  23.423           * limit are dealt with (acts like a replenishment point).
  23.424 @@ -282,184 +295,22 @@ void netif_creditlimit(netif_be_creditli
  23.425          netif->credit_timeout.expires = jiffies;
  23.426          netif_schedule_work(netif);
  23.427      }
  23.428 -    
  23.429 -    creditlimit->status = NETIF_BE_STATUS_OKAY;
  23.430 +#endif
  23.431  }
  23.432  
  23.433 -void netif_connect(netif_be_connect_t *connect)
  23.434 +int netif_disconnect(netif_t *netif)
  23.435  {
  23.436 -    domid_t       domid  = connect->domid;
  23.437 -    unsigned int  handle = connect->netif_handle;
  23.438 -    unsigned int  evtchn = connect->evtchn;
  23.439 -    unsigned long tx_shmem_frame = connect->tx_shmem_frame;
  23.440 -    unsigned long rx_shmem_frame = connect->rx_shmem_frame;
  23.441 -    struct vm_struct *vma;
  23.442 -#if !defined(CONFIG_XEN_NETDEV_GRANT_TX)||!defined(CONFIG_XEN_NETDEV_GRANT_RX)
  23.443 -    pgprot_t      prot = __pgprot(_KERNPG_TABLE);
  23.444 -    int           error;
  23.445 -#endif
  23.446 -    netif_t      *netif;
  23.447 -
  23.448 -    netif = netif_find_by_handle(domid, handle);
  23.449 -    if ( unlikely(netif == NULL) ) {
  23.450 -        DPRINTK("netif_connect attempted for non-existent netif (%u,%u)\n", 
  23.451 -                connect->domid, connect->netif_handle); 
  23.452 -        connect->status = NETIF_BE_STATUS_INTERFACE_NOT_FOUND;
  23.453 -        return;
  23.454 -    }
  23.455 -
  23.456 -    if ( netif->status != DISCONNECTED ) {
  23.457 -        connect->status = NETIF_BE_STATUS_INTERFACE_CONNECTED;
  23.458 -        return;
  23.459 -    }
  23.460 -
  23.461 -    if ( (vma = get_vm_area(2*PAGE_SIZE, VM_IOREMAP)) == NULL ) {
  23.462 -        connect->status = NETIF_BE_STATUS_OUT_OF_MEMORY;
  23.463 -        return;
  23.464 -    }
  23.465 -
  23.466 -
  23.467 -#if defined(CONFIG_XEN_NETDEV_GRANT_TX)
  23.468 -    {
  23.469 -        struct gnttab_map_grant_ref op;
  23.470 -        int tx_ref = connect->tx_shmem_ref; 
  23.471 -
  23.472 -        /* Map: Use the Grant table reference */
  23.473 -        op.host_addr = VMALLOC_VMADDR(vma->addr);
  23.474 -        op.flags     = GNTMAP_host_map;
  23.475 -        op.ref       = tx_ref;
  23.476 -        op.dom       = domid;
  23.477 -       
  23.478 -        if ((HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) < 0) || 
  23.479 -            (op.handle < 0)) { 
  23.480 -            DPRINTK(" Grant table operation failure !\n");
  23.481 -            connect->status = NETIF_BE_STATUS_MAPPING_ERROR;
  23.482 -            vfree(vma->addr);
  23.483 -            return;
  23.484 -        }
  23.485 -
  23.486 -        netif->tx_shmem_ref    = tx_ref;
  23.487 -        netif->tx_shmem_handle = op.handle;
  23.488 -        netif->tx_shmem_vaddr  = VMALLOC_VMADDR(vma->addr);
  23.489 -    }
  23.490 -        
  23.491 -
  23.492 -#else 
  23.493 -    error = direct_remap_area_pages(&init_mm, 
  23.494 -                                    VMALLOC_VMADDR(vma->addr),
  23.495 -                                    tx_shmem_frame<<PAGE_SHIFT, PAGE_SIZE,
  23.496 -                                    prot, domid); 
  23.497 -    if ( error != 0 )
  23.498 -    {
  23.499 -        if ( error == -ENOMEM )
  23.500 -            connect->status = NETIF_BE_STATUS_OUT_OF_MEMORY;
  23.501 -        else if ( error == -EFAULT )
  23.502 -            connect->status = NETIF_BE_STATUS_MAPPING_ERROR;
  23.503 -        else
  23.504 -            connect->status = NETIF_BE_STATUS_ERROR;
  23.505 -        vfree(vma->addr);
  23.506 -        return;
  23.507 -    }
  23.508 -#endif
  23.509 -
  23.510  
  23.511 -#if defined(CONFIG_XEN_NETDEV_GRANT_RX)
  23.512 -    {
  23.513 -        struct gnttab_map_grant_ref op;
  23.514 -        int rx_ref = connect->rx_shmem_ref; 
  23.515 -
  23.516 -
  23.517 -        /* Map: Use the Grant table reference */
  23.518 -        op.host_addr = VMALLOC_VMADDR(vma->addr) + PAGE_SIZE;
  23.519 -        op.flags     = GNTMAP_host_map;
  23.520 -        op.ref       = rx_ref;
  23.521 -        op.dom       = domid;
  23.522 -
  23.523 -        if ((HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) < 0) || 
  23.524 -            (op.handle < 0)) { 
  23.525 -            DPRINTK(" Grant table operation failure !\n");
  23.526 -            connect->status = NETIF_BE_STATUS_MAPPING_ERROR;
  23.527 -            vfree(vma->addr);
  23.528 -            return;
  23.529 -        }
  23.530 -
  23.531 -        netif->rx_shmem_ref    = rx_ref;
  23.532 -        netif->rx_shmem_handle = handle;
  23.533 -        netif->rx_shmem_vaddr  = VMALLOC_VMADDR(vma->addr) + PAGE_SIZE;
  23.534 -    }
  23.535 -#else 
  23.536 -    error = direct_remap_area_pages(&init_mm, 
  23.537 -                                     VMALLOC_VMADDR(vma->addr) + PAGE_SIZE,
  23.538 -                                     rx_shmem_frame<<PAGE_SHIFT, PAGE_SIZE,
  23.539 -                                     prot, domid);
  23.540 -    if ( error != 0 )
  23.541 -    {
  23.542 -        if ( error == -ENOMEM )
  23.543 -            connect->status = NETIF_BE_STATUS_OUT_OF_MEMORY;
  23.544 -        else if ( error == -EFAULT )
  23.545 -            connect->status = NETIF_BE_STATUS_MAPPING_ERROR;
  23.546 -        else
  23.547 -            connect->status = NETIF_BE_STATUS_ERROR;
  23.548 -        vfree(vma->addr);
  23.549 -        return;
  23.550 -    }
  23.551 -
  23.552 -#endif
  23.553 -
  23.554 -    netif->evtchn         = evtchn;
  23.555 -    netif->tx_shmem_frame = tx_shmem_frame;
  23.556 -    netif->rx_shmem_frame = rx_shmem_frame;
  23.557 -    netif->tx             = 
  23.558 -        (netif_tx_interface_t *)vma->addr;
  23.559 -    netif->rx             = 
  23.560 -        (netif_rx_interface_t *)((char *)vma->addr + PAGE_SIZE);
  23.561 -    netif->tx->resp_prod = netif->rx->resp_prod = 0;
  23.562 -    netif_get(netif);
  23.563 -    wmb(); /* Other CPUs see new state before interface is started. */
  23.564 -
  23.565 -    rtnl_lock();
  23.566 -    netif->status = CONNECTED;
  23.567 -    wmb();
  23.568 -    if ( netif_running(netif->dev) )
  23.569 -        __netif_up(netif);
  23.570 -    rtnl_unlock();
  23.571 -
  23.572 -    connect->status = NETIF_BE_STATUS_OKAY;
  23.573 -}
  23.574 -
  23.575 -int netif_disconnect(netif_be_disconnect_t *disconnect, u8 rsp_id)
  23.576 -{
  23.577 -    domid_t       domid  = disconnect->domid;
  23.578 -    unsigned int  handle = disconnect->netif_handle;
  23.579 -    netif_t      *netif;
  23.580 -
  23.581 -    netif = netif_find_by_handle(domid, handle);
  23.582 -    if ( unlikely(netif == NULL) )
  23.583 -    {
  23.584 -        DPRINTK("netif_disconnect attempted for non-existent netif"
  23.585 -                " (%u,%u)\n", disconnect->domid, disconnect->netif_handle); 
  23.586 -        disconnect->status = NETIF_BE_STATUS_INTERFACE_NOT_FOUND;
  23.587 -        return 1; /* Caller will send response error message. */
  23.588 -    }
  23.589 -
  23.590 -    if ( netif->status == CONNECTED )
  23.591 -    {
  23.592 +    if (netif->status == CONNECTED) {
  23.593          rtnl_lock();
  23.594          netif->status = DISCONNECTING;
  23.595 -        netif->disconnect_rspid = rsp_id;
  23.596          wmb();
  23.597 -        if ( netif_running(netif->dev) )
  23.598 +        if (netif_running(netif->dev))
  23.599              __netif_down(netif);
  23.600          rtnl_unlock();
  23.601          netif_put(netif);
  23.602          return 0; /* Caller should not send response message. */
  23.603      }
  23.604  
  23.605 -    disconnect->status = NETIF_BE_STATUS_OKAY;
  23.606      return 1;
  23.607  }
  23.608 -
  23.609 -void netif_interface_init(void)
  23.610 -{
  23.611 -    memset(netif_hash, 0, sizeof(netif_hash));
  23.612 -}
    24.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Wed Aug 24 16:16:52 2005 -0700
    24.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Thu Aug 25 11:18:47 2005 -0700
    24.3 @@ -13,10 +13,6 @@
    24.4  #include "common.h"
    24.5  #include <asm-xen/balloon.h>
    24.6  
    24.7 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
    24.8 -#include <linux/delay.h>
    24.9 -#endif
   24.10 -
   24.11  #if defined(CONFIG_XEN_NETDEV_GRANT_TX) || defined(CONFIG_XEN_NETDEV_GRANT_RX)
   24.12  #include <asm-xen/xen-public/grant_table.h>
   24.13  #include <asm-xen/gnttab.h>
   24.14 @@ -153,11 +149,7 @@ static inline void maybe_schedule_tx_act
   24.15  static inline int is_xen_skb(struct sk_buff *skb)
   24.16  {
   24.17      extern kmem_cache_t *skbuff_cachep;
   24.18 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
   24.19      kmem_cache_t *cp = (kmem_cache_t *)virt_to_page(skb->head)->lru.next;
   24.20 -#else
   24.21 -    kmem_cache_t *cp = (kmem_cache_t *)virt_to_page(skb->head)->list.next;
   24.22 -#endif
   24.23      return (cp == skbuff_cachep);
   24.24  }
   24.25  
   24.26 @@ -642,11 +634,7 @@ static void net_tx_action(unsigned long 
   24.27                  netif->credit_timeout.expires  = next_credit;
   24.28                  netif->credit_timeout.data     = (unsigned long)netif;
   24.29                  netif->credit_timeout.function = tx_credit_callback;
   24.30 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
   24.31                  add_timer_on(&netif->credit_timeout, smp_processor_id());
   24.32 -#else
   24.33 -                add_timer(&netif->credit_timeout); 
   24.34 -#endif
   24.35                  break;
   24.36              }
   24.37          }
   24.38 @@ -966,8 +954,6 @@ static int __init netback_init(void)
   24.39      net_timer.data = 0;
   24.40      net_timer.function = net_alarm;
   24.41      
   24.42 -    netif_interface_init();
   24.43 -
   24.44      page = balloon_alloc_empty_page_range(MAX_PENDING_REQS);
   24.45      BUG_ON(page == NULL);
   24.46      mmap_vstart = (unsigned long)pfn_to_kaddr(page_to_pfn(page));
   24.47 @@ -987,7 +973,7 @@ static int __init netback_init(void)
   24.48      spin_lock_init(&net_schedule_list_lock);
   24.49      INIT_LIST_HEAD(&net_schedule_list);
   24.50  
   24.51 -    netif_ctrlif_init();
   24.52 +    netif_xenbus_init();
   24.53  
   24.54      (void)request_irq(bind_virq_to_irq(VIRQ_DEBUG),
   24.55                        netif_be_dbg, SA_SHIRQ, 
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c	Thu Aug 25 11:18:47 2005 -0700
    25.3 @@ -0,0 +1,257 @@
    25.4 +/*  Xenbus code for netif backend
    25.5 +    Copyright (C) 2005 Rusty Russell <rusty@rustcorp.com.au>
    25.6 +
    25.7 +    This program is free software; you can redistribute it and/or modify
    25.8 +    it under the terms of the GNU General Public License as published by
    25.9 +    the Free Software Foundation; either version 2 of the License, or
   25.10 +    (at your option) any later version.
   25.11 +
   25.12 +    This program is distributed in the hope that it will be useful,
   25.13 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   25.14 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   25.15 +    GNU General Public License for more details.
   25.16 +
   25.17 +    You should have received a copy of the GNU General Public License
   25.18 +    along with this program; if not, write to the Free Software
   25.19 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   25.20 +*/
   25.21 +#include <stdarg.h>
   25.22 +#include <linux/module.h>
   25.23 +#include <asm-xen/xenbus.h>
   25.24 +#include "common.h"
   25.25 +
   25.26 +struct backend_info
   25.27 +{
   25.28 +	struct xenbus_device *dev;
   25.29 +
   25.30 +	/* our communications channel */
   25.31 +	netif_t *netif;
   25.32 +
   25.33 +	long int frontend_id;
   25.34 +#if 0
   25.35 +	long int pdev;
   25.36 +	long int readonly;
   25.37 +#endif
   25.38 +
   25.39 +	/* watch back end for changes */
   25.40 +	struct xenbus_watch backend_watch;
   25.41 +
   25.42 +	/* watch front end for changes */
   25.43 +	struct xenbus_watch watch;
   25.44 +	char *frontpath;
   25.45 +};
   25.46 +
   25.47 +static int netback_remove(struct xenbus_device *dev)
   25.48 +{
   25.49 +	struct backend_info *be = dev->data;
   25.50 +
   25.51 +	if (be->watch.node)
   25.52 +		unregister_xenbus_watch(&be->watch);
   25.53 +	unregister_xenbus_watch(&be->backend_watch);
   25.54 +	if (be->netif)
   25.55 +		netif_disconnect(be->netif);
   25.56 +	if (be->frontpath)
   25.57 +		kfree(be->frontpath);
   25.58 +	kfree(be);
   25.59 +	return 0;
   25.60 +}
   25.61 +
   25.62 +/* Front end tells us frame. */
   25.63 +static void frontend_changed(struct xenbus_watch *watch, const char *node)
   25.64 +{
   25.65 +	unsigned long tx_ring_ref, rx_ring_ref;
   25.66 +	unsigned int evtchn;
   25.67 +	int err;
   25.68 +	struct backend_info *be
   25.69 +		= container_of(watch, struct backend_info, watch);
   25.70 +	char *mac, *e, *s;
   25.71 +	int i;
   25.72 +
   25.73 +	/* If other end is gone, delete ourself. */
   25.74 +	if (node && !xenbus_exists(be->frontpath, "")) {
   25.75 +		xenbus_rm(be->dev->nodename, "");
   25.76 +		device_unregister(&be->dev->dev);
   25.77 +		return;
   25.78 +	}
   25.79 +	if (be->netif == NULL || be->netif->status == CONNECTED)
   25.80 +		return;
   25.81 +
   25.82 +	mac = xenbus_read(be->frontpath, "mac", NULL);
   25.83 +	if (IS_ERR(mac)) {
   25.84 +		err = PTR_ERR(mac);
   25.85 +		xenbus_dev_error(be->dev, err, "reading %s/mac",
   25.86 +				 be->dev->nodename);
   25.87 +		return;
   25.88 +	}
   25.89 +	s = mac;
   25.90 +	for (i = 0; i < ETH_ALEN; i++) {
   25.91 +		be->netif->fe_dev_addr[i] = simple_strtoul(s, &e, 16);
   25.92 +		if (s == e || (e[0] != ':' && e[0] != 0)) {
   25.93 +			kfree(mac);
   25.94 +			err = -ENOENT;
   25.95 +			xenbus_dev_error(be->dev, err, "parsing %s/mac",
   25.96 +					 be->dev->nodename);
   25.97 +			return;
   25.98 +		}
   25.99 +		s = &e[1];
  25.100 +	}
  25.101 +	kfree(mac);
  25.102 +
  25.103 +	err = xenbus_gather(be->frontpath, "tx-ring-ref", "%lu", &tx_ring_ref,
  25.104 +			    "rx-ring-ref", "%lu", &rx_ring_ref,
  25.105 +			    "event-channel", "%u", &evtchn, NULL);
  25.106 +	if (err) {
  25.107 +		xenbus_dev_error(be->dev, err,
  25.108 +				 "reading %s/ring-ref and event-channel",
  25.109 +				 be->frontpath);
  25.110 +		return;
  25.111 +	}
  25.112 +
  25.113 +	/* Map the shared frame, irq etc. */
  25.114 +	err = netif_map(be->netif, tx_ring_ref, rx_ring_ref, evtchn);
  25.115 +	if (err) {
  25.116 +		xenbus_dev_error(be->dev, err,
  25.117 +				 "mapping shared-frames %lu/%lu port %u",
  25.118 +				 tx_ring_ref, rx_ring_ref, evtchn);
  25.119 +		return;
  25.120 +	}
  25.121 +
  25.122 +	xenbus_dev_ok(be->dev);
  25.123 +
  25.124 +	return;
  25.125 +}
  25.126 +
  25.127 +/* 
  25.128 +   Setup supplies physical device.  
  25.129 +   We provide event channel and device details to front end.
  25.130 +   Frontend supplies shared frame and event channel.
  25.131 + */
  25.132 +static void backend_changed(struct xenbus_watch *watch, const char *node)
  25.133 +{
  25.134 +	int err;
  25.135 +	long int handle;
  25.136 +	struct backend_info *be
  25.137 +		= container_of(watch, struct backend_info, backend_watch);
  25.138 +	struct xenbus_device *dev = be->dev;
  25.139 +	u8 be_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
  25.140 +
  25.141 +	err = xenbus_scanf(dev->nodename, "handle", "%li", &handle);
  25.142 +	if (XENBUS_EXIST_ERR(err))
  25.143 +		return;
  25.144 +	if (err < 0) {
  25.145 +		xenbus_dev_error(dev, err, "reading handle");
  25.146 +		return;
  25.147 +	}
  25.148 +
  25.149 +	if (be->netif == NULL) {
  25.150 +		be->netif = alloc_netif(be->frontend_id, handle, be_mac);
  25.151 +		if (IS_ERR(be->netif)) {
  25.152 +			err = PTR_ERR(be->netif);
  25.153 +			be->netif = NULL;
  25.154 +			xenbus_dev_error(dev, err, "creating interface");
  25.155 +			return;
  25.156 +		}
  25.157 +
  25.158 +#if 0
  25.159 +		err = vbd_create(be->netif, handle, be->pdev, be->readonly);
  25.160 +		if (err) {
  25.161 +			xenbus_dev_error(dev, err, "creating vbd structure");
  25.162 +			return;
  25.163 +		}
  25.164 +#endif
  25.165 +
  25.166 +		/* Pass in NULL node to skip exist test. */
  25.167 +		frontend_changed(&be->watch, NULL);
  25.168 +	}
  25.169 +}
  25.170 +
  25.171 +static int netback_probe(struct xenbus_device *dev,
  25.172 +			 const struct xenbus_device_id *id)
  25.173 +{
  25.174 +	struct backend_info *be;
  25.175 +	char *frontend;
  25.176 +	int err;
  25.177 +
  25.178 +	be = kmalloc(sizeof(*be), GFP_KERNEL);
  25.179 +	if (!be) {
  25.180 +		xenbus_dev_error(dev, -ENOMEM, "allocating backend structure");
  25.181 +		return -ENOMEM;
  25.182 +	}
  25.183 +	memset(be, 0, sizeof(*be));
  25.184 +
  25.185 +	frontend = NULL;
  25.186 +	err = xenbus_gather(dev->nodename,
  25.187 +			    "frontend-id", "%li", &be->frontend_id,
  25.188 +			    "frontend", NULL, &frontend,
  25.189 +			    NULL);
  25.190 +	if (XENBUS_EXIST_ERR(err))
  25.191 +		goto free_be;
  25.192 +	if (err < 0) {
  25.193 +		xenbus_dev_error(dev, err,
  25.194 +				 "reading %s/frontend or frontend-id",
  25.195 +				 dev->nodename);
  25.196 +		goto free_be;
  25.197 +	}
  25.198 +	if (strlen(frontend) == 0 || !xenbus_exists(frontend, "")) {
  25.199 +		/* If we can't get a frontend path and a frontend-id,
  25.200 +		 * then our bus-id is no longer valid and we need to
  25.201 +		 * destroy the backend device.
  25.202 +		 */
  25.203 +		err = -ENOENT;
  25.204 +		goto free_be;
  25.205 +	}
  25.206 +
  25.207 +	be->dev = dev;
  25.208 +	be->backend_watch.node = dev->nodename;
  25.209 +	be->backend_watch.callback = backend_changed;
  25.210 +	err = register_xenbus_watch(&be->backend_watch);
  25.211 +	if (err) {
  25.212 +		be->backend_watch.node = NULL;
  25.213 +		xenbus_dev_error(dev, err, "adding backend watch on %s",
  25.214 +				 dev->nodename);
  25.215 +		goto free_be;
  25.216 +	}
  25.217 +
  25.218 +	be->frontpath = frontend;
  25.219 +	be->watch.node = be->frontpath;
  25.220 +	be->watch.callback = frontend_changed;
  25.221 +	err = register_xenbus_watch(&be->watch);
  25.222 +	if (err) {
  25.223 +		be->watch.node = NULL;
  25.224 +		xenbus_dev_error(dev, err,
  25.225 +				 "adding frontend watch on %s",
  25.226 +				 be->frontpath);
  25.227 +		goto free_be;
  25.228 +	}
  25.229 +
  25.230 +	dev->data = be;
  25.231 +
  25.232 +	backend_changed(&be->backend_watch, dev->nodename);
  25.233 +	return 0;
  25.234 +
  25.235 + free_be:
  25.236 +	if (be->backend_watch.node)
  25.237 +		unregister_xenbus_watch(&be->backend_watch);
  25.238 +	if (frontend)
  25.239 +		kfree(frontend);
  25.240 +	kfree(be);
  25.241 +	return err;
  25.242 +}
  25.243 +
  25.244 +static struct xenbus_device_id netback_ids[] = {
  25.245 +	{ "vif" },
  25.246 +	{ "" }
  25.247 +};
  25.248 +
  25.249 +static struct xenbus_driver netback = {
  25.250 +	.name = "vif",
  25.251 +	.owner = THIS_MODULE,
  25.252 +	.ids = netback_ids,
  25.253 +	.probe = netback_probe,
  25.254 +	.remove = netback_remove,
  25.255 +};
  25.256 +
  25.257 +void netif_xenbus_init(void)
  25.258 +{
  25.259 +	xenbus_register_backend(&netback);
  25.260 +}
    26.1 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Wed Aug 24 16:16:52 2005 -0700
    26.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Thu Aug 25 11:18:47 2005 -0700
    26.3 @@ -48,7 +48,7 @@
    26.4  #include <asm/io.h>
    26.5  #include <asm/uaccess.h>
    26.6  #include <asm-xen/evtchn.h>
    26.7 -#include <asm-xen/ctrl_if.h>
    26.8 +#include <asm-xen/xenbus.h>
    26.9  #include <asm-xen/xen-public/io/netif.h>
   26.10  #include <asm-xen/balloon.h>
   26.11  #include <asm/page.h>
   26.12 @@ -112,10 +112,14 @@ static grant_ref_t grant_rx_ref[NETIF_RX
   26.13  #endif
   26.14  
   26.15  #if defined(CONFIG_XEN_NETDEV_GRANT_TX) || defined(CONFIG_XEN_NETDEV_GRANT_RX)
   26.16 -static domid_t rdomid = 0;
   26.17  #define GRANT_INVALID_REF	(0xFFFF)
   26.18  #endif
   26.19  
   26.20 +#define NETIF_STATE_DISCONNECTED 0
   26.21 +#define NETIF_STATE_CONNECTED    1
   26.22 +
   26.23 +static unsigned int netif_state = NETIF_STATE_DISCONNECTED;
   26.24 +
   26.25  static void network_tx_buf_gc(struct net_device *dev);
   26.26  static void network_alloc_rx_buffers(struct net_device *dev);
   26.27  
   26.28 @@ -133,12 +137,11 @@ static void xennet_proc_delif(struct net
   26.29  #define xennet_proc_delif(d) ((void)0)
   26.30  #endif
   26.31  
   26.32 -static struct list_head dev_list;
   26.33 -
   26.34 +#define netfront_info net_private
   26.35  struct net_private
   26.36  {
   26.37      struct list_head list;
   26.38 -    struct net_device *dev;
   26.39 +    struct net_device *netdev;
   26.40  
   26.41      struct net_device_stats stats;
   26.42      NETIF_RING_IDX rx_resp_cons, tx_resp_cons;
   26.43 @@ -176,6 +179,14 @@ struct net_private
   26.44       */
   26.45      struct sk_buff *tx_skbs[NETIF_TX_RING_SIZE+1];
   26.46      struct sk_buff *rx_skbs[NETIF_RX_RING_SIZE+1];
   26.47 +
   26.48 +	struct xenbus_device *xbdev;
   26.49 +	char *backend;
   26.50 +	int backend_id;
   26.51 +	struct xenbus_watch watch;
   26.52 +	int tx_ring_ref;
   26.53 +	int rx_ring_ref;
   26.54 +	u8 mac[ETH_ALEN];
   26.55  };
   26.56  
   26.57  /* Access macros for acquiring freeing slots in {tx,rx}_skbs[]. */
   26.58 @@ -187,20 +198,14 @@ struct net_private
   26.59      (_list)[0]  = (_list)[_id];                    \
   26.60      (unsigned short)_id; })
   26.61  
   26.62 -static char *status_name[] = {
   26.63 -    [NETIF_INTERFACE_STATUS_CLOSED]       = "closed",
   26.64 -    [NETIF_INTERFACE_STATUS_DISCONNECTED] = "disconnected",
   26.65 -    [NETIF_INTERFACE_STATUS_CONNECTED]    = "connected",
   26.66 -    [NETIF_INTERFACE_STATUS_CHANGED]      = "changed",
   26.67 -};
   26.68 -
   26.69 +#ifdef DEBUG
   26.70  static char *be_state_name[] = {
   26.71      [BEST_CLOSED]       = "closed",
   26.72      [BEST_DISCONNECTED] = "disconnected",
   26.73      [BEST_CONNECTED]    = "connected",
   26.74  };
   26.75 +#endif
   26.76  
   26.77 -#define DEBUG
   26.78  #ifdef DEBUG
   26.79  #define DPRINTK(fmt, args...) \
   26.80      printk(KERN_ALERT "xen_net (%s:%d) " fmt, __FUNCTION__, __LINE__, ##args)
   26.81 @@ -212,89 +217,6 @@ static char *be_state_name[] = {
   26.82  #define WPRINTK(fmt, args...) \
   26.83      printk(KERN_WARNING "xen_net: " fmt, ##args)
   26.84  
   26.85 -static struct net_device *find_dev_by_handle(unsigned int handle)
   26.86 -{
   26.87 -    struct list_head *ent;
   26.88 -    struct net_private *np;
   26.89 -    list_for_each (ent, &dev_list) {
   26.90 -        np = list_entry(ent, struct net_private, list);
   26.91 -        if (np->handle == handle)
   26.92 -            return np->dev;
   26.93 -    }
   26.94 -    return NULL;
   26.95 -}
   26.96 -
   26.97 -/** Network interface info. */
   26.98 -struct netif_ctrl {
   26.99 -    /** Number of interfaces. */
  26.100 -    int interface_n;
  26.101 -    /** Number of connected interfaces. */
  26.102 -    int connected_n;
  26.103 -    /** Error code. */
  26.104 -    int err;
  26.105 -    int up;
  26.106 -};
  26.107 -
  26.108 -static struct netif_ctrl netctrl;
  26.109 -
  26.110 -static void netctrl_init(void)
  26.111 -{
  26.112 -    memset(&netctrl, 0, sizeof(netctrl));
  26.113 -    netctrl.up = NETIF_DRIVER_STATUS_DOWN;
  26.114 -}
  26.115 -
  26.116 -/** Get or set a network interface error.
  26.117 - */
  26.118 -static int netctrl_err(int err)
  26.119 -{
  26.120 -    if ((err < 0) && !netctrl.err)
  26.121 -        netctrl.err = err;
  26.122 -    return netctrl.err;
  26.123 -}
  26.124 -
  26.125 -/** Test if all network interfaces are connected.
  26.126 - *
  26.127 - * @return 1 if all connected, 0 if not, negative error code otherwise
  26.128 - */
  26.129 -static int netctrl_connected(void)
  26.130 -{
  26.131 -    int ok;
  26.132 -
  26.133 -    if (netctrl.err)
  26.134 -        ok = netctrl.err;
  26.135 -    else if (netctrl.up == NETIF_DRIVER_STATUS_UP)
  26.136 -        ok = (netctrl.connected_n == netctrl.interface_n);
  26.137 -    else
  26.138 -        ok = 0;
  26.139 -
  26.140 -    return ok;
  26.141 -}
  26.142 -
  26.143 -/** Count the connected network interfaces.
  26.144 - *
  26.145 - * @return connected count
  26.146 - */
  26.147 -static int netctrl_connected_count(void)
  26.148 -{
  26.149 -    
  26.150 -    struct list_head *ent;
  26.151 -    struct net_private *np;
  26.152 -    unsigned int connected;
  26.153 -
  26.154 -    connected = 0;
  26.155 -    
  26.156 -    list_for_each(ent, &dev_list) {
  26.157 -        np = list_entry(ent, struct net_private, list);
  26.158 -        if (np->backend_state == BEST_CONNECTED)
  26.159 -            connected++;
  26.160 -    }
  26.161 -
  26.162 -    netctrl.connected_n = connected;
  26.163 -    DPRINTK("> connected_n=%d interface_n=%d\n",
  26.164 -            netctrl.connected_n, netctrl.interface_n);
  26.165 -    return connected;
  26.166 -}
  26.167 -
  26.168  /** Send a packet on a net device to encourage switches to learn the
  26.169   * MAC. We send a fake ARP request.
  26.170   *
  26.171 @@ -364,7 +286,7 @@ static void network_tx_buf_gc(struct net
  26.172                         "still in use by backend domain.\n");
  26.173                  goto out; 
  26.174              }
  26.175 -            gnttab_end_foreign_access(grant_tx_ref[id], GNTMAP_readonly);
  26.176 +            gnttab_end_foreign_access_ref(grant_tx_ref[id], GNTMAP_readonly);
  26.177              gnttab_release_grant_reference(&gref_tx_head, grant_tx_ref[id]);
  26.178              grant_tx_ref[id] = GRANT_INVALID_REF;
  26.179  #endif
  26.180 @@ -448,7 +370,7 @@ static void network_alloc_rx_buffers(str
  26.181              BUG();
  26.182          }
  26.183          grant_rx_ref[id] = ref;
  26.184 -        gnttab_grant_foreign_transfer_ref(ref, rdomid,
  26.185 +        gnttab_grant_foreign_transfer_ref(ref, np->backend_id,
  26.186                                            virt_to_mfn(skb->head));
  26.187          np->rx->ring[MASK_NETIF_RX_IDX(req_prod + i)].req.gref = ref;
  26.188  #endif
  26.189 @@ -544,7 +466,7 @@ static int network_start_xmit(struct sk_
  26.190          BUG();
  26.191      }
  26.192      mfn = virt_to_mfn(skb->data);
  26.193 -    gnttab_grant_foreign_access_ref(ref, rdomid, mfn, GNTMAP_readonly);
  26.194 +    gnttab_grant_foreign_access_ref(ref, np->backend_id, mfn, GNTMAP_readonly);
  26.195      tx->addr = ref << PAGE_SHIFT;
  26.196      grant_tx_ref[id] = ref;
  26.197  #else
  26.198 @@ -650,7 +572,7 @@ static int netif_poll(struct net_device 
  26.199  #ifdef CONFIG_XEN_NETDEV_GRANT_RX
  26.200          ref = grant_rx_ref[rx->id];
  26.201          grant_rx_ref[rx->id] = GRANT_INVALID_REF;
  26.202 -        mfn = gnttab_end_foreign_transfer(ref);
  26.203 +        mfn = gnttab_end_foreign_transfer_ref(ref);
  26.204          gnttab_release_grant_reference(&gref_rx_head, ref);
  26.205  #endif
  26.206  
  26.207 @@ -809,7 +731,7 @@ static int network_close(struct net_devi
  26.208  {
  26.209      struct net_private *np = netdev_priv(dev);
  26.210      np->user_state = UST_CLOSED;
  26.211 -    netif_stop_queue(np->dev);
  26.212 +    netif_stop_queue(np->netdev);
  26.213      return 0;
  26.214  }
  26.215  
  26.216 @@ -821,8 +743,7 @@ static struct net_device_stats *network_
  26.217  }
  26.218  
  26.219  
  26.220 -static void network_connect(struct net_device *dev,
  26.221 -                            netif_fe_interface_status_t *status)
  26.222 +static void network_connect(struct net_device *dev)
  26.223  {
  26.224      struct net_private *np;
  26.225      int i, requeue_idx;
  26.226 @@ -890,7 +811,7 @@ static void network_connect(struct net_d
  26.227       */
  26.228      np->backend_state = BEST_CONNECTED;
  26.229      wmb();
  26.230 -    notify_via_evtchn(status->evtchn);  
  26.231 +    notify_via_evtchn(np->evtchn);  
  26.232      network_tx_buf_gc(dev);
  26.233  
  26.234      if (np->user_state == UST_OPEN)
  26.235 @@ -900,148 +821,21 @@ static void network_connect(struct net_d
  26.236      spin_unlock_irq(&np->tx_lock);
  26.237  }
  26.238  
  26.239 -static void vif_show(struct net_private *np)
  26.240 +static void show_device(struct net_private *np)
  26.241  {
  26.242  #ifdef DEBUG
  26.243 -    if (np) {
  26.244 -        IPRINTK("<vif handle=%u %s(%s) evtchn=%u tx=%p rx=%p>\n",
  26.245 -               np->handle,
  26.246 -               be_state_name[np->backend_state],
  26.247 -               np->user_state ? "open" : "closed",
  26.248 -               np->evtchn,
  26.249 -               np->tx,
  26.250 -               np->rx);
  26.251 -    } else {
  26.252 -        IPRINTK("<vif NULL>\n");
  26.253 -    }
  26.254 -#endif
  26.255 -}
  26.256 -
  26.257 -/* Send a connect message to xend to tell it to bring up the interface. */
  26.258 -static void send_interface_connect(struct net_private *np)
  26.259 -{
  26.260 -    int err;
  26.261 -    ctrl_msg_t cmsg = {
  26.262 -        .type    = CMSG_NETIF_FE,
  26.263 -        .subtype = CMSG_NETIF_FE_INTERFACE_CONNECT,
  26.264 -        .length  = sizeof(netif_fe_interface_connect_t),
  26.265 -    };
  26.266 -    netif_fe_interface_connect_t *msg = (void*)cmsg.msg;
  26.267 -
  26.268 -    msg->handle = np->handle;
  26.269 -    msg->tx_shmem_frame = virt_to_mfn(np->tx);
  26.270 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  26.271 -    err = gnttab_grant_foreign_access(rdomid, msg->tx_shmem_frame, 0);
  26.272 -    if (err < 0) {
  26.273 -        printk(KERN_ALERT "#### netfront can't grant access to tx_shmem\n");
  26.274 -        BUG();
  26.275 -    }
  26.276 -    msg->tx_shmem_ref = err;
  26.277 -#endif
  26.278 -
  26.279 -    msg->rx_shmem_frame = virt_to_mfn(np->rx);
  26.280 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  26.281 -    err = gnttab_grant_foreign_access(rdomid, msg->rx_shmem_frame, 0);
  26.282 -    if (err < 0) {
  26.283 -        printk(KERN_ALERT "#### netfront can't grant access to rx_shmem\n");
  26.284 -        BUG();
  26.285 -    }
  26.286 -    msg->rx_shmem_ref = err;
  26.287 +	if (np) {
  26.288 +		IPRINTK("<vif handle=%u %s(%s) evtchn=%u tx=%p rx=%p>\n",
  26.289 +			np->handle,
  26.290 +			be_state_name[np->backend_state],
  26.291 +			np->user_state ? "open" : "closed",
  26.292 +			np->evtchn,
  26.293 +			np->tx,
  26.294 +			np->rx);
  26.295 +	} else {
  26.296 +		IPRINTK("<vif NULL>\n");
  26.297 +	}
  26.298  #endif
  26.299 -
  26.300 -    ctrl_if_send_message_block(&cmsg, NULL, 0, TASK_UNINTERRUPTIBLE);
  26.301 -}
  26.302 -
  26.303 -/* Send a driver status notification to the domain controller. */
  26.304 -static int send_driver_status(int ok)
  26.305 -{
  26.306 -    int err = 0;
  26.307 -    ctrl_msg_t cmsg = {
  26.308 -        .type    = CMSG_NETIF_FE,
  26.309 -        .subtype = CMSG_NETIF_FE_DRIVER_STATUS,
  26.310 -        .length  = sizeof(netif_fe_driver_status_t),
  26.311 -    };
  26.312 -    netif_fe_driver_status_t *msg = (void*)cmsg.msg;
  26.313 -
  26.314 -    msg->status = (ok ? NETIF_DRIVER_STATUS_UP : NETIF_DRIVER_STATUS_DOWN);
  26.315 -    err = ctrl_if_send_message_block(&cmsg, NULL, 0, TASK_UNINTERRUPTIBLE);
  26.316 -    return err;
  26.317 -}
  26.318 -
  26.319 -/* Stop network device and free tx/rx queues and irq.
  26.320 - */
  26.321 -static void vif_release(struct net_private *np)
  26.322 -{
  26.323 -    /* Stop old i/f to prevent errors whilst we rebuild the state. */
  26.324 -    spin_lock_irq(&np->tx_lock);
  26.325 -    spin_lock(&np->rx_lock);
  26.326 -    netif_stop_queue(np->dev);
  26.327 -    /* np->backend_state = BEST_DISCONNECTED; */
  26.328 -    spin_unlock(&np->rx_lock);
  26.329 -    spin_unlock_irq(&np->tx_lock);
  26.330 -    
  26.331 -    /* Free resources. */
  26.332 -    if ( np->tx != NULL )
  26.333 -    {
  26.334 -        unbind_evtchn_from_irqhandler(np->evtchn, np->dev);
  26.335 -        free_page((unsigned long)np->tx);
  26.336 -        free_page((unsigned long)np->rx);
  26.337 -        np->evtchn = 0;
  26.338 -        np->tx = NULL;
  26.339 -        np->rx = NULL;
  26.340 -    }
  26.341 -}
  26.342 -
  26.343 -/* Release vif resources and close it down completely.
  26.344 - */
  26.345 -static void vif_close(struct net_private *np)
  26.346 -{
  26.347 -    WPRINTK("Unexpected netif-CLOSED message in state %s\n",
  26.348 -            be_state_name[np->backend_state]);
  26.349 -    vif_release(np);
  26.350 -    np->backend_state = BEST_CLOSED;
  26.351 -    /* todo: take dev down and free. */
  26.352 -    vif_show(np);
  26.353 -}
  26.354 -
  26.355 -/* Move the vif into disconnected state.
  26.356 - * Allocates tx/rx pages.
  26.357 - * Sends connect message to xend.
  26.358 - */
  26.359 -static void vif_disconnect(struct net_private *np)
  26.360 -{
  26.361 -    if(np->tx) free_page((unsigned long)np->tx);
  26.362 -    if(np->rx) free_page((unsigned long)np->rx);
  26.363 -    // Before this np->tx and np->rx had better be null.
  26.364 -    np->tx = (netif_tx_interface_t *)__get_free_page(GFP_KERNEL);
  26.365 -    np->rx = (netif_rx_interface_t *)__get_free_page(GFP_KERNEL);
  26.366 -    memset(np->tx, 0, PAGE_SIZE);
  26.367 -    memset(np->rx, 0, PAGE_SIZE);
  26.368 -    np->backend_state = BEST_DISCONNECTED;
  26.369 -    send_interface_connect(np);
  26.370 -    vif_show(np);
  26.371 -}
  26.372 -
  26.373 -/* Begin interface recovery.
  26.374 - *
  26.375 - * NB. Whilst we're recovering, we turn the carrier state off.  We
  26.376 - * take measures to ensure that this device isn't used for
  26.377 - * anything.  We also stop the queue for this device.  Various
  26.378 - * different approaches (e.g. continuing to buffer packets) have
  26.379 - * been tested but don't appear to improve the overall impact on
  26.380 - * TCP connections.
  26.381 - *
  26.382 - * TODO: (MAW) Change the Xend<->Guest protocol so that a recovery
  26.383 - * is initiated by a special "RESET" message - disconnect could
  26.384 - * just mean we're not allowed to use this interface any more.
  26.385 - */
  26.386 -static void vif_reset(struct net_private *np)
  26.387 -{
  26.388 -    IPRINTK("Attempting to reconnect network interface: handle=%u\n",
  26.389 -            np->handle);    
  26.390 -    vif_release(np);
  26.391 -    vif_disconnect(np);
  26.392 -    vif_show(np);
  26.393  }
  26.394  
  26.395  /* Move the vif into connected state.
  26.396 @@ -1049,26 +843,22 @@ static void vif_reset(struct net_private
  26.397   * Binds the irq to the event channel.
  26.398   */
  26.399  static void 
  26.400 -vif_connect(struct net_private *np, netif_fe_interface_status_t *status)
  26.401 +connect_device(struct net_private *np, unsigned int evtchn)
  26.402  {
  26.403 -    struct net_device *dev = np->dev;
  26.404 -    memcpy(dev->dev_addr, status->mac, ETH_ALEN);
  26.405 -    network_connect(dev, status);
  26.406 -    np->evtchn = status->evtchn;
  26.407 -#if defined(CONFIG_XEN_NETDEV_GRANT_TX) || defined(CONFIG_XEN_NETDEV_GRANT_RX)
  26.408 -    rdomid = status->domid;
  26.409 -#endif
  26.410 -    (void)bind_evtchn_to_irqhandler(
  26.411 -        np->evtchn, netif_int, SA_SAMPLE_RANDOM, dev->name, dev);
  26.412 -    netctrl_connected_count();
  26.413 -    (void)send_fake_arp(dev);
  26.414 -    vif_show(np);
  26.415 +	struct net_device *dev = np->netdev;
  26.416 +	memcpy(dev->dev_addr, np->mac, ETH_ALEN);
  26.417 +	np->evtchn = evtchn;
  26.418 +	network_connect(dev);
  26.419 +	(void)bind_evtchn_to_irqhandler(
  26.420 +		np->evtchn, netif_int, SA_SAMPLE_RANDOM, dev->name, dev);
  26.421 +	(void)send_fake_arp(dev);
  26.422 +	show_device(np);
  26.423  }
  26.424  
  26.425  static struct ethtool_ops network_ethtool_ops =
  26.426  {
  26.427 -    .get_tx_csum = ethtool_op_get_tx_csum,
  26.428 -    .set_tx_csum = ethtool_op_set_tx_csum,
  26.429 +	.get_tx_csum = ethtool_op_get_tx_csum,
  26.430 +	.set_tx_csum = ethtool_op_set_tx_csum,
  26.431  };
  26.432  
  26.433  /** Create a network device.
  26.434 @@ -1076,22 +866,24 @@ static struct ethtool_ops network_ethtoo
  26.435   * @param val return parameter for created device
  26.436   * @return 0 on success, error code otherwise
  26.437   */
  26.438 -static int create_netdev(int handle, struct net_device **val)
  26.439 +static int create_netdev(int handle, struct xenbus_device *dev,
  26.440 +			 struct net_device **val)
  26.441  {
  26.442      int i, err = 0;
  26.443 -    struct net_device *dev = NULL;
  26.444 +    struct net_device *netdev = NULL;
  26.445      struct net_private *np = NULL;
  26.446  
  26.447 -    if ((dev = alloc_etherdev(sizeof(struct net_private))) == NULL) {
  26.448 +    if ((netdev = alloc_etherdev(sizeof(struct net_private))) == NULL) {
  26.449          printk(KERN_WARNING "%s> alloc_etherdev failed.\n", __FUNCTION__);
  26.450          err = -ENOMEM;
  26.451          goto exit;
  26.452      }
  26.453  
  26.454 -    np                = netdev_priv(dev);
  26.455 +    np                = netdev_priv(netdev);
  26.456      np->backend_state = BEST_CLOSED;
  26.457      np->user_state    = UST_CLOSED;
  26.458      np->handle        = handle;
  26.459 +    np->xbdev         = dev;
  26.460      
  26.461      spin_lock_init(&np->tx_lock);
  26.462      spin_lock_init(&np->rx_lock);
  26.463 @@ -1115,268 +907,53 @@ static int create_netdev(int handle, str
  26.464  #endif
  26.465      }
  26.466  
  26.467 -    dev->open            = network_open;
  26.468 -    dev->hard_start_xmit = network_start_xmit;
  26.469 -    dev->stop            = network_close;
  26.470 -    dev->get_stats       = network_get_stats;
  26.471 -    dev->poll            = netif_poll;
  26.472 -    dev->weight          = 64;
  26.473 -    dev->features        = NETIF_F_IP_CSUM;
  26.474 +    netdev->open            = network_open;
  26.475 +    netdev->hard_start_xmit = network_start_xmit;
  26.476 +    netdev->stop            = network_close;
  26.477 +    netdev->get_stats       = network_get_stats;
  26.478 +    netdev->poll            = netif_poll;
  26.479 +    netdev->weight          = 64;
  26.480 +    netdev->features        = NETIF_F_IP_CSUM;
  26.481  
  26.482 -    SET_ETHTOOL_OPS(dev, &network_ethtool_ops);
  26.483 +    SET_ETHTOOL_OPS(netdev, &network_ethtool_ops);
  26.484  
  26.485 -    if ((err = register_netdev(dev)) != 0) {
  26.486 +    if ((err = register_netdev(netdev)) != 0) {
  26.487          printk(KERN_WARNING "%s> register_netdev err=%d\n", __FUNCTION__, err);
  26.488          goto exit;
  26.489      }
  26.490  
  26.491 -    if ((err = xennet_proc_addif(dev)) != 0) {
  26.492 -        unregister_netdev(dev);
  26.493 +    if ((err = xennet_proc_addif(netdev)) != 0) {
  26.494 +        unregister_netdev(netdev);
  26.495          goto exit;
  26.496      }
  26.497  
  26.498 -    np->dev = dev;
  26.499 -    list_add(&np->list, &dev_list);
  26.500 +    np->netdev = netdev;
  26.501  
  26.502    exit:
  26.503 -    if ((err != 0) && (dev != NULL))
  26.504 -        kfree(dev);
  26.505 +    if ((err != 0) && (netdev != NULL))
  26.506 +        kfree(netdev);
  26.507      else if (val != NULL)
  26.508 -        *val = dev;
  26.509 -    return err;
  26.510 -}
  26.511 -
  26.512 -/* Get the target interface for a status message.
  26.513 - * Creates the interface when it makes sense.
  26.514 - * The returned interface may be null when there is no error.
  26.515 - *
  26.516 - * @param status status message
  26.517 - * @param np return parameter for interface state
  26.518 - * @return 0 on success, error code otherwise
  26.519 - */
  26.520 -static int 
  26.521 -target_vif(netif_fe_interface_status_t *status, struct net_private **np)
  26.522 -{
  26.523 -    int err = 0;
  26.524 -    struct net_device *dev;
  26.525 -
  26.526 -    DPRINTK("> handle=%d\n", status->handle);
  26.527 -    if (status->handle < 0) {
  26.528 -        err = -EINVAL;
  26.529 -        goto exit;
  26.530 -    }
  26.531 -
  26.532 -    if ((dev = find_dev_by_handle(status->handle)) != NULL)
  26.533 -        goto exit;
  26.534 -
  26.535 -    if (status->status == NETIF_INTERFACE_STATUS_CLOSED)
  26.536 -        goto exit;
  26.537 -    if (status->status == NETIF_INTERFACE_STATUS_CHANGED)
  26.538 -        goto exit;
  26.539 -
  26.540 -    /* It's a new interface in a good state - create it. */
  26.541 -    DPRINTK("> create device...\n");
  26.542 -    if ((err = create_netdev(status->handle, &dev)) != 0)
  26.543 -        goto exit;
  26.544 -
  26.545 -    netctrl.interface_n++;
  26.546 -
  26.547 -  exit:
  26.548 -    if (np != NULL)
  26.549 -        *np = ((dev && !err) ? netdev_priv(dev) : NULL);
  26.550 -    DPRINTK("< err=%d\n", err);
  26.551 +        *val = netdev;
  26.552      return err;
  26.553  }
  26.554  
  26.555 -/* Handle an interface status message. */
  26.556 -static void netif_interface_status(netif_fe_interface_status_t *status)
  26.557 +static int destroy_netdev(struct net_device *netdev)
  26.558  {
  26.559 -    int err = 0;
  26.560 -    struct net_private *np = NULL;
  26.561 -    
  26.562 -    DPRINTK("> status=%s handle=%d\n",
  26.563 -            status_name[status->status], status->handle);
  26.564 -
  26.565 -    if ((err = target_vif(status, &np)) != 0) {
  26.566 -        WPRINTK("Invalid netif: handle=%u\n", status->handle);
  26.567 -        return;
  26.568 -    }
  26.569 -
  26.570 -    if (np == NULL) {
  26.571 -        DPRINTK("> no vif\n");
  26.572 -        return;
  26.573 -    }
  26.574 -
  26.575 -    switch (status->status) {
  26.576 -    case NETIF_INTERFACE_STATUS_CLOSED:
  26.577 -        switch (np->backend_state) {
  26.578 -        case BEST_CLOSED:
  26.579 -        case BEST_DISCONNECTED:
  26.580 -        case BEST_CONNECTED:
  26.581 -            vif_close(np);
  26.582 -            break;
  26.583 -        }
  26.584 -        break;
  26.585 -
  26.586 -    case NETIF_INTERFACE_STATUS_DISCONNECTED:
  26.587 -        switch (np->backend_state) {
  26.588 -        case BEST_CLOSED:
  26.589 -            vif_disconnect(np);
  26.590 -            break;
  26.591 -        case BEST_DISCONNECTED:
  26.592 -        case BEST_CONNECTED:
  26.593 -            vif_reset(np);
  26.594 -            break;
  26.595 -        }
  26.596 -        break;
  26.597 -
  26.598 -    case NETIF_INTERFACE_STATUS_CONNECTED:
  26.599 -        switch (np->backend_state) {
  26.600 -        case BEST_CLOSED:
  26.601 -            WPRINTK("Unexpected netif status %s in state %s\n",
  26.602 -                    status_name[status->status],
  26.603 -                    be_state_name[np->backend_state]);
  26.604 -            vif_disconnect(np);
  26.605 -            vif_connect(np, status);
  26.606 -            break;
  26.607 -        case BEST_DISCONNECTED:
  26.608 -            vif_connect(np, status);
  26.609 -            break;
  26.610 -        }
  26.611 -        break;
  26.612 -
  26.613 -    case NETIF_INTERFACE_STATUS_CHANGED:
  26.614 -        /*
  26.615 -         * The domain controller is notifying us that a device has been
  26.616 -         * added or removed.
  26.617 -         */
  26.618 -        break;
  26.619 -
  26.620 -    default:
  26.621 -        WPRINTK("Invalid netif status code %d\n", status->status);
  26.622 -        break;
  26.623 -    }
  26.624 -
  26.625 -    vif_show(np);
  26.626 -}
  26.627 -
  26.628 -/*
  26.629 - * Initialize the network control interface. 
  26.630 - */
  26.631 -static void netif_driver_status(netif_fe_driver_status_t *status)
  26.632 -{
  26.633 -    netctrl.up = status->status;
  26.634 -    netctrl_connected_count();
  26.635 -}
  26.636 -
  26.637 -/* Receive handler for control messages. */
  26.638 -static void netif_ctrlif_rx(ctrl_msg_t *msg, unsigned long id)
  26.639 -{
  26.640 -
  26.641 -    switch (msg->subtype) {
  26.642 -    case CMSG_NETIF_FE_INTERFACE_STATUS:
  26.643 -        netif_interface_status((netif_fe_interface_status_t *) &msg->msg[0]);
  26.644 -        break;
  26.645 -
  26.646 -    case CMSG_NETIF_FE_DRIVER_STATUS:
  26.647 -        netif_driver_status((netif_fe_driver_status_t *) &msg->msg[0]);
  26.648 -        break;
  26.649 +	struct net_private *np = NULL;
  26.650  
  26.651 -    default:
  26.652 -        msg->length = 0;
  26.653 -        break;
  26.654 -    }
  26.655 -
  26.656 -    ctrl_if_send_response(msg);
  26.657 -}
  26.658 -
  26.659 -
  26.660 -#if 1
  26.661 -/* Wait for all interfaces to be connected.
  26.662 - *
  26.663 - * This works OK, but we'd like to use the probing mode (see below).
  26.664 - */
  26.665 -static int probe_interfaces(void)
  26.666 -{
  26.667 -    int err = 0, conn = 0;
  26.668 -    int wait_i, wait_n = 100;
  26.669 +#ifdef CONFIG_PROC_FS
  26.670 +	xennet_proc_delif(netdev);
  26.671 +#endif
  26.672  
  26.673 -    DPRINTK(">\n");
  26.674 +        unregister_netdev(netdev);
  26.675  
  26.676 -    for (wait_i = 0; wait_i < wait_n; wait_i++) { 
  26.677 -        DPRINTK("> wait_i=%d\n", wait_i);
  26.678 -        conn = netctrl_connected();
  26.679 -        if(conn) break;
  26.680 -        DPRINTK("> schedule_timeout...\n");
  26.681 -        set_current_state(TASK_INTERRUPTIBLE);
  26.682 -        schedule_timeout(10);
  26.683 -    }
  26.684 +	np = netdev_priv(netdev);
  26.685 +	list_del(&np->list);
  26.686  
  26.687 -    DPRINTK("> wait finished...\n");
  26.688 -    if (conn <= 0) {
  26.689 -        err = netctrl_err(-ENETDOWN);
  26.690 -        WPRINTK("Failed to connect all virtual interfaces: err=%d\n", err);
  26.691 -    }
  26.692 +	kfree(netdev);
  26.693  
  26.694 -    DPRINTK("< err=%d\n", err);
  26.695 -
  26.696 -    return err;
  26.697 +	return 0;
  26.698  }
  26.699 -#else
  26.700 -/* Probe for interfaces until no more are found.
  26.701 - *
  26.702 - * This is the mode we'd like to use, but at the moment it panics the kernel.
  26.703 -*/
  26.704 -static int probe_interfaces(void)
  26.705 -{
  26.706 -    int err = 0;
  26.707 -    int wait_i, wait_n = 100;
  26.708 -    ctrl_msg_t cmsg = {
  26.709 -        .type    = CMSG_NETIF_FE,
  26.710 -        .subtype = CMSG_NETIF_FE_INTERFACE_STATUS,
  26.711 -        .length  = sizeof(netif_fe_interface_status_t),
  26.712 -    };
  26.713 -    netif_fe_interface_status_t msg = {};
  26.714 -    ctrl_msg_t rmsg = {};
  26.715 -    netif_fe_interface_status_t *reply = (void*)rmsg.msg;
  26.716 -    int state = TASK_UNINTERRUPTIBLE;
  26.717 -    u32 query = -1;
  26.718 -
  26.719 -    DPRINTK(">\n");
  26.720 -
  26.721 -    netctrl.interface_n = 0;
  26.722 -    for (wait_i = 0; wait_i < wait_n; wait_i++) { 
  26.723 -        DPRINTK("> wait_i=%d query=%d\n", wait_i, query);
  26.724 -        msg.handle = query;
  26.725 -        memcpy(cmsg.msg, &msg, sizeof(msg));
  26.726 -        DPRINTK("> set_current_state...\n");
  26.727 -        set_current_state(state);
  26.728 -        DPRINTK("> rmsg=%p msg=%p, reply=%p\n", &rmsg, rmsg.msg, reply);
  26.729 -        DPRINTK("> sending...\n");
  26.730 -        err = ctrl_if_send_message_and_get_response(&cmsg, &rmsg, state);
  26.731 -        DPRINTK("> err=%d\n", err);
  26.732 -        if(err) goto exit;
  26.733 -        DPRINTK("> rmsg=%p msg=%p, reply=%p\n", &rmsg, rmsg.msg, reply);
  26.734 -        if((int)reply->handle < 0) {
  26.735 -            // No more interfaces.
  26.736 -            break;
  26.737 -        }
  26.738 -        query = -reply->handle - 2;
  26.739 -        DPRINTK(">netif_interface_status ...\n");
  26.740 -        netif_interface_status(reply);
  26.741 -    }
  26.742 -
  26.743 -  exit:
  26.744 -    if (err) {
  26.745 -        err = netctrl_err(-ENETDOWN);
  26.746 -        WPRINTK("Connecting virtual network interfaces failed: err=%d\n", err);
  26.747 -    }
  26.748 -
  26.749 -    DPRINTK("< err=%d\n", err);
  26.750 -    return err;
  26.751 -}
  26.752 -
  26.753 -#endif
  26.754  
  26.755  /*
  26.756   * We use this notifier to send out a fake ARP reply to reset switches and
  26.757 @@ -1387,19 +964,11 @@ inetdev_notify(struct notifier_block *th
  26.758  {
  26.759      struct in_ifaddr  *ifa = (struct in_ifaddr *)ptr; 
  26.760      struct net_device *dev = ifa->ifa_dev->dev;
  26.761 -    struct list_head  *ent;
  26.762 -    struct net_private *np;
  26.763 -
  26.764 -    if (event != NETDEV_UP)
  26.765 -        goto out;
  26.766  
  26.767 -    list_for_each (ent, &dev_list) {
  26.768 -        np = list_entry(ent, struct net_private, list);
  26.769 -        if (np->dev == dev)
  26.770 -            (void)send_fake_arp(dev);
  26.771 -    }
  26.772 +    /* UP event and is it one of our devices? */
  26.773 +    if (event == NETDEV_UP && dev->open == network_open)
  26.774 +        (void)send_fake_arp(dev);
  26.775          
  26.776 - out:
  26.777      return NOTIFY_DONE;
  26.778  }
  26.779  
  26.780 @@ -1409,12 +978,367 @@ static struct notifier_block notifier_in
  26.781      .priority       = 0
  26.782  };
  26.783  
  26.784 +static struct xenbus_device_id netfront_ids[] = {
  26.785 +	{ "vif" },
  26.786 +	{ "" }
  26.787 +};
  26.788 +
  26.789 +static void watch_for_status(struct xenbus_watch *watch, const char *node)
  26.790 +{
  26.791 +}
  26.792 +
  26.793 +static int setup_device(struct xenbus_device *dev, struct netfront_info *info)
  26.794 +{
  26.795 +	evtchn_op_t op = { .cmd = EVTCHNOP_alloc_unbound };
  26.796 +	int err;
  26.797 +
  26.798 +#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  26.799 +	info->tx_ring_ref = GRANT_INVALID_REF;
  26.800 +#endif
  26.801 +#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  26.802 +	info->rx_ring_ref = GRANT_INVALID_REF;
  26.803 +#endif
  26.804 +
  26.805 +	info->tx = (netif_tx_interface_t *)__get_free_page(GFP_KERNEL);
  26.806 +	if (info->tx == 0) {
  26.807 +		err = -ENOMEM;
  26.808 +		xenbus_dev_error(dev, err, "allocating tx ring page");
  26.809 +		goto out;
  26.810 +	}
  26.811 +	info->rx = (netif_rx_interface_t *)__get_free_page(GFP_KERNEL);
  26.812 +	if (info->rx == 0) {
  26.813 +		err = -ENOMEM;
  26.814 +		xenbus_dev_error(dev, err, "allocating rx ring page");
  26.815 +		goto out;
  26.816 +	}
  26.817 +	memset(info->tx, 0, PAGE_SIZE);
  26.818 +	memset(info->rx, 0, PAGE_SIZE);
  26.819 +	info->backend_state = BEST_DISCONNECTED;
  26.820 +
  26.821 +#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  26.822 +	err = gnttab_grant_foreign_access(info->backend_id,
  26.823 +					  virt_to_mfn(info->tx), 0);
  26.824 +	if (err < 0) {
  26.825 +		xenbus_dev_error(dev, err, "granting access to tx ring page");
  26.826 +		goto out;
  26.827 +	}
  26.828 +	info->tx_ring_ref = err;
  26.829 +#else
  26.830 +	info->tx_ring_ref = virt_to_mfn(info->tx);
  26.831 +#endif
  26.832 +
  26.833 +#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  26.834 +	err = gnttab_grant_foreign_access(info->backend_id,
  26.835 +					  virt_to_mfn(info->rx), 0);
  26.836 +	if (err < 0) {
  26.837 +		xenbus_dev_error(dev, err, "granting access to rx ring page");
  26.838 +		goto out;
  26.839 +	}
  26.840 +	info->rx_ring_ref = err;
  26.841 +#else
  26.842 +	info->rx_ring_ref = virt_to_mfn(info->rx);
  26.843 +#endif
  26.844 +
  26.845 +	op.u.alloc_unbound.dom = info->backend_id;
  26.846 +	err = HYPERVISOR_event_channel_op(&op);
  26.847 +	if (err) {
  26.848 +		xenbus_dev_error(dev, err, "allocating event channel");
  26.849 +		goto out;
  26.850 +	}
  26.851 +	connect_device(info, op.u.alloc_unbound.port);
  26.852 +	return 0;
  26.853 +
  26.854 + out:
  26.855 +	if (info->tx)
  26.856 +		free_page((unsigned long)info->tx);
  26.857 +	info->tx = 0;
  26.858 +	if (info->rx)
  26.859 +		free_page((unsigned long)info->rx);
  26.860 +	info->rx = 0;
  26.861 +#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  26.862 +	if (info->tx_ring_ref != GRANT_INVALID_REF)
  26.863 +		gnttab_end_foreign_access(info->tx_ring_ref, 0);
  26.864 +	info->tx_ring_ref = GRANT_INVALID_REF;
  26.865 +#endif
  26.866 +#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  26.867 +	if (info->rx_ring_ref != GRANT_INVALID_REF)
  26.868 +		gnttab_end_foreign_access(info->rx_ring_ref, 0);
  26.869 +	info->rx_ring_ref = GRANT_INVALID_REF;
  26.870 +#endif
  26.871 +	return err;
  26.872 +}
  26.873 +
  26.874 +static void netif_free(struct netfront_info *info)
  26.875 +{
  26.876 +	if (info->tx)
  26.877 +		free_page((unsigned long)info->tx);
  26.878 +	info->tx = 0;
  26.879 +	if (info->rx)
  26.880 +		free_page((unsigned long)info->rx);
  26.881 +	info->rx = 0;
  26.882 +#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  26.883 +	if (info->tx_ring_ref != GRANT_INVALID_REF)
  26.884 +		gnttab_end_foreign_access(info->tx_ring_ref, 0);
  26.885 +	info->tx_ring_ref = GRANT_INVALID_REF;
  26.886 +#endif
  26.887 +#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  26.888 +	if (info->rx_ring_ref != GRANT_INVALID_REF)
  26.889 +		gnttab_end_foreign_access(info->rx_ring_ref, 0);
  26.890 +	info->rx_ring_ref = GRANT_INVALID_REF;
  26.891 +#endif
  26.892 +	unbind_evtchn_from_irqhandler(info->evtchn, info->netdev);
  26.893 +	info->evtchn = 0;
  26.894 +}
  26.895 +
  26.896 +/* Stop network device and free tx/rx queues and irq.
  26.897 + */
  26.898 +static void shutdown_device(struct net_private *np)
  26.899 +{
  26.900 +	/* Stop old i/f to prevent errors whilst we rebuild the state. */
  26.901 +	spin_lock_irq(&np->tx_lock);
  26.902 +	spin_lock(&np->rx_lock);
  26.903 +	netif_stop_queue(np->netdev);
  26.904 +	/* np->backend_state = BEST_DISCONNECTED; */
  26.905 +	spin_unlock(&np->rx_lock);
  26.906 +	spin_unlock_irq(&np->tx_lock);
  26.907 +    
  26.908 +	/* Free resources. */
  26.909 +	netif_free(np);
  26.910 +}
  26.911 +
  26.912 +/* Common code used when first setting up, and when resuming. */
  26.913 +static int talk_to_backend(struct xenbus_device *dev,
  26.914 +			   struct netfront_info *info)
  26.915 +{
  26.916 +	char *backend, *mac, *e, *s;
  26.917 +	const char *message;
  26.918 +	int err, i;
  26.919 +
  26.920 +	backend = NULL;
  26.921 +	err = xenbus_gather(dev->nodename,
  26.922 +			    "backend-id", "%i", &info->backend_id,
  26.923 +			    "backend", NULL, &backend,
  26.924 +			    NULL);
  26.925 +	if (XENBUS_EXIST_ERR(err))
  26.926 +		goto out;
  26.927 +	if (backend && strlen(backend) == 0) {
  26.928 +		err = -ENOENT;
  26.929 +		goto out;
  26.930 +	}
  26.931 +	if (err < 0) {
  26.932 +		xenbus_dev_error(dev, err, "reading %s/backend or backend-id",
  26.933 +				 dev->nodename);
  26.934 +		goto out;
  26.935 +	}
  26.936 +
  26.937 +	mac = xenbus_read(dev->nodename, "mac", NULL);
  26.938 +	if (IS_ERR(mac)) {
  26.939 +		err = PTR_ERR(mac);
  26.940 +		xenbus_dev_error(dev, err, "reading %s/mac",
  26.941 +				 dev->nodename);
  26.942 +		goto out;
  26.943 +	}
  26.944 +	s = mac;
  26.945 +	for (i = 0; i < ETH_ALEN; i++) {
  26.946 +		info->mac[i] = simple_strtoul(s, &e, 16);
  26.947 +		if (s == e || (e[0] != ':' && e[0] != 0)) {
  26.948 +			kfree(mac);
  26.949 +			err = -ENOENT;
  26.950 +			xenbus_dev_error(dev, err, "parsing %s/mac",
  26.951 +					 dev->nodename);
  26.952 +			goto out;
  26.953 +		}
  26.954 +		s = &e[1];
  26.955 +	}
  26.956 +	kfree(mac);
  26.957 +
  26.958 +	/* Create shared ring, alloc event channel. */
  26.959 +	err = setup_device(dev, info);
  26.960 +	if (err) {
  26.961 +		xenbus_dev_error(dev, err, "setting up ring");
  26.962 +		goto out;
  26.963 +	}
  26.964 +
  26.965 +	err = xenbus_transaction_start(dev->nodename);
  26.966 +	if (err) {
  26.967 +		xenbus_dev_error(dev, err, "starting transaction");
  26.968 +		goto destroy_ring;
  26.969 +	}
  26.970 +
  26.971 +	err = xenbus_printf(dev->nodename, "tx-ring-ref","%u",
  26.972 +			    info->tx_ring_ref);
  26.973 +	if (err) {
  26.974 +		message = "writing tx ring-ref";
  26.975 +		goto abort_transaction;
  26.976 +	}
  26.977 +	err = xenbus_printf(dev->nodename, "rx-ring-ref","%u",
  26.978 +			    info->rx_ring_ref);
  26.979 +	if (err) {
  26.980 +		message = "writing rx ring-ref";
  26.981 +		goto abort_transaction;
  26.982 +	}
  26.983 +	err = xenbus_printf(dev->nodename,
  26.984 +			    "event-channel", "%u", info->evtchn);
  26.985 +	if (err) {
  26.986 +		message = "writing event-channel";
  26.987 +		goto abort_transaction;
  26.988 +	}
  26.989 +
  26.990 +	info->backend = backend;
  26.991 +	backend = NULL;
  26.992 +
  26.993 +	info->watch.node = info->backend;
  26.994 +	info->watch.callback = watch_for_status;
  26.995 +	err = register_xenbus_watch(&info->watch);
  26.996 +	if (err) {
  26.997 +		message = "registering watch on backend";
  26.998 +		goto abort_transaction;
  26.999 +	}
 26.1000 +
 26.1001 +	err = xenbus_transaction_end(0);
 26.1002 +	if (err) {
 26.1003 +		xenbus_dev_error(dev, err, "completing transaction");
 26.1004 +		goto destroy_ring;
 26.1005 +	}
 26.1006 +
 26.1007 +	netif_state = NETIF_STATE_CONNECTED;
 26.1008 +
 26.1009 + out:
 26.1010 +	if (backend)
 26.1011 +		kfree(backend);
 26.1012 +	return err;
 26.1013 +
 26.1014 + abort_transaction:
 26.1015 +	xenbus_transaction_end(1);
 26.1016 +	/* Have to do this *outside* transaction.  */
 26.1017 +	xenbus_dev_error(dev, err, "%s", message);
 26.1018 + destroy_ring:
 26.1019 +	shutdown_device(info);
 26.1020 +	goto out;
 26.1021 +}
 26.1022 +
 26.1023 +/* Setup supplies the backend dir, virtual device.
 26.1024 +
 26.1025 +   We place an event channel and shared frame entries.
 26.1026 +   We watch backend to wait if it's ok. */
 26.1027 +static int netfront_probe(struct xenbus_device *dev,
 26.1028 +			  const struct xenbus_device_id *id)
 26.1029 +{
 26.1030 +	int err;
 26.1031 +	struct net_device *netdev;
 26.1032 +	struct netfront_info *info;
 26.1033 +	unsigned int handle;
 26.1034 +
 26.1035 +	err = xenbus_scanf(dev->nodename, "handle", "%u", &handle);
 26.1036 +	if (XENBUS_EXIST_ERR(err))
 26.1037 +		return err;
 26.1038 +	if (err < 0) {
 26.1039 +		xenbus_dev_error(dev, err, "reading handle");
 26.1040 +		return err;
 26.1041 +	}
 26.1042 +
 26.1043 +	err = create_netdev(handle, dev, &netdev);
 26.1044 +	if (err) {
 26.1045 +		xenbus_dev_error(dev, err, "creating netdev");
 26.1046 +		return err;
 26.1047 +	}
 26.1048 +
 26.1049 +	info = netdev_priv(netdev);
 26.1050 +	err = talk_to_backend(dev, info);
 26.1051 +	if (err) {
 26.1052 +		destroy_netdev(netdev);
 26.1053 +		return err;
 26.1054 +	}
 26.1055 +
 26.1056 +	/* Call once in case entries already there. */
 26.1057 +	watch_for_status(&info->watch, info->watch.node);
 26.1058 +
 26.1059 +	return 0;
 26.1060 +}
 26.1061 +
 26.1062 +static int netfront_remove(struct xenbus_device *dev)
 26.1063 +{
 26.1064 +	struct netfront_info *info = dev->data;
 26.1065 +
 26.1066 +	if (info->backend)
 26.1067 +		unregister_xenbus_watch(&info->watch);
 26.1068 +
 26.1069 +	netif_free(info);
 26.1070 +
 26.1071 +	kfree(info->backend);
 26.1072 +	kfree(info);
 26.1073 +
 26.1074 +	return 0;
 26.1075 +}
 26.1076 +
 26.1077 +static int netfront_suspend(struct xenbus_device *dev)
 26.1078 +{
 26.1079 +    struct net_private *np = dev->data;
 26.1080 +    /* Avoid having tx/rx stuff happen until we're ready. */
 26.1081 +    unbind_evtchn_from_irqhandler(np->evtchn, np->netdev);
 26.1082 +    return 0;
 26.1083 +}
 26.1084 +
 26.1085 +static int netfront_resume(struct xenbus_device *dev)
 26.1086 +{
 26.1087 +    struct net_private *np = dev->data;
 26.1088 +    /*
 26.1089 +     * Connect regardless of whether IFF_UP flag set.
 26.1090 +     * Stop bad things from happening until we're back up.
 26.1091 +     */
 26.1092 +    np->backend_state = BEST_DISCONNECTED;
 26.1093 +    memset(np->tx, 0, PAGE_SIZE);
 26.1094 +    memset(np->rx, 0, PAGE_SIZE);
 26.1095 +    
 26.1096 +    // send_interface_connect(np);
 26.1097 +    return 0;
 26.1098 +}
 26.1099 +
 26.1100 +static struct xenbus_driver netfront = {
 26.1101 +	.name = "vif",
 26.1102 +	.owner = THIS_MODULE,
 26.1103 +	.ids = netfront_ids,
 26.1104 +	.probe = netfront_probe,
 26.1105 +	.remove = netfront_remove,
 26.1106 +	.resume = netfront_resume,
 26.1107 +	.suspend = netfront_suspend,
 26.1108 +};
 26.1109 +
 26.1110 +static void __init init_net_xenbus(void)
 26.1111 +{
 26.1112 +	xenbus_register_device(&netfront);
 26.1113 +}
 26.1114 +
 26.1115 +static int wait_for_netif(void)
 26.1116 +{
 26.1117 +    int err = 0;
 26.1118 +    int i;
 26.1119 +
 26.1120 +    /*
 26.1121 +     * We should figure out how many and which devices we need to
 26.1122 +     * proceed and only wait for those.  For now, continue once the
 26.1123 +     * first device is around.
 26.1124 +     */
 26.1125 +    for ( i=0; netif_state != NETIF_STATE_CONNECTED && (i < 10*HZ); i++ )
 26.1126 +    {
 26.1127 +        set_current_state(TASK_INTERRUPTIBLE);
 26.1128 +        schedule_timeout(1);
 26.1129 +    }
 26.1130 +
 26.1131 +    if (netif_state != NETIF_STATE_CONNECTED) {
 26.1132 +        WPRINTK("Timeout connecting to device!\n");
 26.1133 +        err = -ENOSYS;
 26.1134 +    }
 26.1135 +    return err;
 26.1136 +}
 26.1137 +
 26.1138  static int __init netif_init(void)
 26.1139  {
 26.1140      int err = 0;
 26.1141  
 26.1142      if (xen_start_info.flags & SIF_INITDOMAIN)
 26.1143          return 0;
 26.1144 +
 26.1145  #ifdef CONFIG_XEN_NETDEV_GRANT_TX
 26.1146      /* A grant for every ring slot */
 26.1147      if (gnttab_alloc_grant_references(NETIF_TX_RING_SIZE,
 26.1148 @@ -1438,17 +1362,13 @@ static int __init netif_init(void)
 26.1149          return err;
 26.1150  
 26.1151      IPRINTK("Initialising virtual ethernet driver.\n");
 26.1152 -    INIT_LIST_HEAD(&dev_list);
 26.1153 +
 26.1154      (void)register_inetaddr_notifier(&notifier_inetdev);
 26.1155 -    netctrl_init();
 26.1156 -    (void)ctrl_if_register_receiver(CMSG_NETIF_FE, netif_ctrlif_rx,
 26.1157 -                                    CALLBACK_IN_BLOCKING_CONTEXT);
 26.1158 -    send_driver_status(1);
 26.1159 -    err = probe_interfaces();
 26.1160 -    if (err)
 26.1161 -        ctrl_if_unregister_receiver(CMSG_NETIF_FE, netif_ctrlif_rx);
 26.1162  
 26.1163 -    DPRINTK("< err=%d\n", err);
 26.1164 +    init_net_xenbus();
 26.1165 +
 26.1166 +    wait_for_netif();
 26.1167 +
 26.1168      return err;
 26.1169  }
 26.1170  
 26.1171 @@ -1462,47 +1382,6 @@ static void netif_exit(void)
 26.1172  #endif
 26.1173  }
 26.1174  
 26.1175 -static void vif_suspend(struct net_private *np)
 26.1176 -{
 26.1177 -    /* Avoid having tx/rx stuff happen until we're ready. */
 26.1178 -    unbind_evtchn_from_irqhandler(np->evtchn, np->dev);
 26.1179 -}
 26.1180 -
 26.1181 -static void vif_resume(struct net_private *np)
 26.1182 -{
 26.1183 -    /*
 26.1184 -     * Connect regardless of whether IFF_UP flag set.
 26.1185 -     * Stop bad things from happening until we're back up.
 26.1186 -     */
 26.1187 -    np->backend_state = BEST_DISCONNECTED;
 26.1188 -    memset(np->tx, 0, PAGE_SIZE);
 26.1189 -    memset(np->rx, 0, PAGE_SIZE);
 26.1190 -    
 26.1191 -    send_interface_connect(np);
 26.1192 -}
 26.1193 -
 26.1194 -void netif_suspend(void)
 26.1195 -{
 26.1196 -    struct list_head *ent;
 26.1197 -    struct net_private *np;
 26.1198 -    
 26.1199 -    list_for_each (ent, &dev_list) {
 26.1200 -        np = list_entry(ent, struct net_private, list);
 26.1201 -        vif_suspend(np);
 26.1202 -    }
 26.1203 -}
 26.1204 -
 26.1205 -void netif_resume(void)
 26.1206 -{
 26.1207 -    struct list_head *ent;
 26.1208 -    struct net_private *np;
 26.1209 -
 26.1210 -    list_for_each (ent, &dev_list) {
 26.1211 -        np = list_entry(ent, struct net_private, list);
 26.1212 -        vif_resume(np);
 26.1213 -    }
 26.1214 -}
 26.1215 -
 26.1216  #ifdef CONFIG_PROC_FS
 26.1217  
 26.1218  #define TARGET_MIN 0UL
    27.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h	Wed Aug 24 16:16:52 2005 -0700
    27.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h	Thu Aug 25 11:18:47 2005 -0700
    27.3 @@ -65,8 +65,26 @@
    27.4  extern unsigned int *phys_to_machine_mapping;
    27.5  #define pfn_to_mfn(pfn)	\
    27.6  ((unsigned long)phys_to_machine_mapping[(unsigned int)(pfn)] & 0x7FFFFFFFUL)
    27.7 -#define mfn_to_pfn(mfn)	\
    27.8 -((unsigned long)machine_to_phys_mapping[(unsigned int)(mfn)])
    27.9 +static inline unsigned long mfn_to_pfn(unsigned long mfn)
   27.10 +{
   27.11 +	unsigned int pfn;
   27.12 +
   27.13 +	/*
   27.14 +	 * The array access can fail (e.g., device space beyond end of RAM).
   27.15 +	 * In such cases it doesn't matter what we return (we return garbage),
   27.16 +	 * but we must handle the fault without crashing!
   27.17 +	 */
   27.18 +	asm (
   27.19 +		"1:	movl %1,%0\n"
   27.20 +		"2:\n"
   27.21 +		".section __ex_table,\"a\"\n"
   27.22 +		"	.align 4\n"
   27.23 +		"	.long 1b,2b\n"
   27.24 +		".previous"
   27.25 +		: "=r" (pfn) : "m" (machine_to_phys_mapping[mfn]) );
   27.26 +
   27.27 +	return (unsigned long)pfn;
   27.28 +}
   27.29  
   27.30  /* Definitions for machine and pseudophysical addresses. */
   27.31  #ifdef CONFIG_X86_PAE
    28.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/page.h	Wed Aug 24 16:16:52 2005 -0700
    28.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/page.h	Thu Aug 25 11:18:47 2005 -0700
    28.3 @@ -67,8 +67,26 @@ void copy_page(void *, void *);
    28.4  extern u32 *phys_to_machine_mapping;
    28.5  #define pfn_to_mfn(pfn)	\
    28.6  ((unsigned long)phys_to_machine_mapping[(unsigned int)(pfn)] & 0x7FFFFFFFUL)
    28.7 -#define mfn_to_pfn(mfn)	\
    28.8 -((unsigned long)machine_to_phys_mapping[(unsigned int)(mfn)])
    28.9 +static inline unsigned long mfn_to_pfn(unsigned long mfn)
   28.10 +{
   28.11 +	unsigned int pfn;
   28.12 +
   28.13 +	/*
   28.14 +	 * The array access can fail (e.g., device space beyond end of RAM).
   28.15 +	 * In such cases it doesn't matter what we return (we return garbage),
   28.16 +	 * but we must handle the fault without crashing!
   28.17 +	 */
   28.18 +	asm (
   28.19 +		"1:	movl %1,%k0\n"
   28.20 +		"2:\n"
   28.21 +		".section __ex_table,\"a\"\n"
   28.22 +		"	.align 8\n"
   28.23 +		"	.quad 1b,2b\n"
   28.24 +		".previous"
   28.25 +		: "=r" (pfn) : "m" (machine_to_phys_mapping[mfn]) );
   28.26 +
   28.27 +	return (unsigned long)pfn;
   28.28 +}
   28.29  
   28.30  /* Definitions for machine and pseudophysical addresses. */
   28.31  typedef unsigned long paddr_t;
    29.1 --- a/linux-2.6-xen-sparse/include/asm-xen/gnttab.h	Wed Aug 24 16:16:52 2005 -0700
    29.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/gnttab.h	Thu Aug 25 11:18:47 2005 -0700
    29.3 @@ -30,10 +30,12 @@ struct gnttab_free_callback {
    29.4  int gnttab_grant_foreign_access(domid_t domid, unsigned long frame,
    29.5  				int readonly);
    29.6  
    29.7 +void gnttab_end_foreign_access_ref(grant_ref_t ref, int readonly);
    29.8  void gnttab_end_foreign_access(grant_ref_t ref, int readonly);
    29.9  
   29.10  int gnttab_grant_foreign_transfer(domid_t domid, unsigned long pfn);
   29.11  
   29.12 +unsigned long gnttab_end_foreign_transfer_ref(grant_ref_t ref);
   29.13  unsigned long gnttab_end_foreign_transfer(grant_ref_t ref);
   29.14  
   29.15  int gnttab_query_foreign_access(grant_ref_t ref);
    30.1 --- a/patches/linux-2.6.12/workaround_double_br_del_if.patch	Wed Aug 24 16:16:52 2005 -0700
    30.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.3 @@ -1,11 +0,0 @@
    30.4 ---- linux-2.6.12/net/bridge/br_if.c	2005-06-17 14:48:29.000000000 -0500
    30.5 -+++ linux-2.6.12-xen0-smp/net/bridge/br_if.c	2005-08-18 15:17:27.302615846 -0500
    30.6 -@@ -382,7 +382,7 @@
    30.7 - {
    30.8 - 	struct net_bridge_port *p = dev->br_port;
    30.9 - 	
   30.10 --	if (!p || p->br != br) 
   30.11 -+	if (!p || p->br != br || p->state == BR_STATE_DISABLED)
   30.12 - 		return -EINVAL;
   30.13 - 
   30.14 - 	br_sysfs_removeif(p);
    31.1 --- a/tools/blktap/blktaplib.h	Wed Aug 24 16:16:52 2005 -0700
    31.2 +++ b/tools/blktap/blktaplib.h	Thu Aug 25 11:18:47 2005 -0700
    31.3 @@ -7,7 +7,7 @@
    31.4  #ifndef __BLKTAPLIB_H__
    31.5  #define __BLKTAPLIB_H__
    31.6  
    31.7 -#include <xc.h>
    31.8 +#include <xenctrl.h>
    31.9  #include <sys/user.h>
   31.10  #include <xen/xen.h>
   31.11  #include <xen/io/blkif.h>
    32.1 --- a/tools/blktap/parallax/block-async.h	Wed Aug 24 16:16:52 2005 -0700
    32.2 +++ b/tools/blktap/parallax/block-async.h	Thu Aug 25 11:18:47 2005 -0700
    32.3 @@ -7,7 +7,7 @@
    32.4  #define _BLOCKASYNC_H_
    32.5  
    32.6  #include <assert.h>
    32.7 -#include <xc.h>
    32.8 +#include <xenctrl.h>
    32.9  #include "vdi.h"
   32.10  
   32.11  struct io_ret
    33.1 --- a/tools/blktap/parallax/blockstore.h	Wed Aug 24 16:16:52 2005 -0700
    33.2 +++ b/tools/blktap/parallax/blockstore.h	Thu Aug 25 11:18:47 2005 -0700
    33.3 @@ -10,7 +10,7 @@
    33.4  #define __BLOCKSTORE_H__
    33.5  
    33.6  #include <netinet/in.h>
    33.7 -#include <xc.h>
    33.8 +#include <xenctrl.h>
    33.9  
   33.10  #define BLOCK_SIZE  4096
   33.11  #define BLOCK_SHIFT   12
    34.1 --- a/tools/console/Makefile	Wed Aug 24 16:16:52 2005 -0700
    34.2 +++ b/tools/console/Makefile	Thu Aug 25 11:18:47 2005 -0700
    34.3 @@ -26,11 +26,11 @@ clean:
    34.4  
    34.5  xenconsoled: $(patsubst %.c,%.o,$(wildcard daemon/*.c))
    34.6  	$(CC) $(CFLAGS) $^ -o $@ -L$(XEN_LIBXC) -L$(XEN_XENSTORE) \
    34.7 -              -lxc -lxenstore
    34.8 +              -lxenctrl -lxenstore
    34.9  
   34.10  xenconsole: $(patsubst %.c,%.o,$(wildcard client/*.c))
   34.11  	$(CC) $(CFLAGS) $^ -o $@ -L$(XEN_LIBXC) -L$(XEN_XENSTORE) \
   34.12 -	      -lxc -lxenstore
   34.13 +	      -lxenctrl -lxenstore
   34.14  
   34.15  install: $(BIN)
   34.16  	$(INSTALL_DIR) -p $(DESTDIR)/$(DAEMON_INSTALL_DIR)
    35.1 --- a/tools/console/client/main.c	Wed Aug 24 16:16:52 2005 -0700
    35.2 +++ b/tools/console/client/main.c	Thu Aug 25 11:18:47 2005 -0700
    35.3 @@ -36,7 +36,7 @@
    35.4  #include <errno.h>
    35.5  #include <pty.h>
    35.6  
    35.7 -#include "xc.h"
    35.8 +#include "xenctrl.h"
    35.9  #include "xs.h"
   35.10  
   35.11  #define ESCAPE_CHARACTER 0x1d
    36.1 --- a/tools/console/daemon/io.c	Wed Aug 24 16:16:52 2005 -0700
    36.2 +++ b/tools/console/daemon/io.c	Thu Aug 25 11:18:47 2005 -0700
    36.3 @@ -23,7 +23,7 @@
    36.4  #include "utils.h"
    36.5  #include "io.h"
    36.6  
    36.7 -#include "xc.h"
    36.8 +#include "xenctrl.h"
    36.9  #include "xs.h"
   36.10  #include "xen/io/domain_controller.h"
   36.11  #include "xcs_proto.h"
    37.1 --- a/tools/console/daemon/main.c	Wed Aug 24 16:16:52 2005 -0700
    37.2 +++ b/tools/console/daemon/main.c	Thu Aug 25 11:18:47 2005 -0700
    37.3 @@ -25,7 +25,7 @@
    37.4  #include <unistd.h>
    37.5  #include <sys/types.h>
    37.6  
    37.7 -#include "xc.h"
    37.8 +#include "xenctrl.h"
    37.9  #include "xen/io/domain_controller.h"
   37.10  #include "xcs_proto.h"
   37.11  
    38.1 --- a/tools/console/daemon/utils.c	Wed Aug 24 16:16:52 2005 -0700
    38.2 +++ b/tools/console/daemon/utils.c	Thu Aug 25 11:18:47 2005 -0700
    38.3 @@ -33,7 +33,7 @@
    38.4  #include <sys/un.h>
    38.5  #include <string.h>
    38.6  
    38.7 -#include "xc.h"
    38.8 +#include "xenctrl.h"
    38.9  #include "xen/io/domain_controller.h"
   38.10  #include "xcs_proto.h"
   38.11  
    39.1 --- a/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c	Wed Aug 24 16:16:52 2005 -0700
    39.2 +++ b/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c	Thu Aug 25 11:18:47 2005 -0700
    39.3 @@ -35,7 +35,7 @@
    39.4  #include <stdlib.h>
    39.5  #include <unistd.h>
    39.6  #include <errno.h>
    39.7 -#include <xc.h>
    39.8 +#include <xenctrl.h>
    39.9  #define TRACE_ENTER /* printf("enter %s\n", __FUNCTION__) */
   39.10  long (*myptrace)(enum __ptrace_request, pid_t, long, long);
   39.11  int (*myxcwait)(int domain, int *status, int options) ;
    40.1 --- a/tools/debugger/libxendebug/Makefile	Wed Aug 24 16:16:52 2005 -0700
    40.2 +++ b/tools/debugger/libxendebug/Makefile	Thu Aug 25 11:18:47 2005 -0700
    40.3 @@ -20,7 +20,7 @@ CFLAGS   += $(INCLUDES) -I. -I$(XEN_ROOT
    40.4  CFLAGS   += -Wp,-MD,.$(@F).d
    40.5  DEPS     = .*.d
    40.6  
    40.7 -LDFLAGS  += -L$(XEN_ROOT)/tools/libxc -lxc
    40.8 +LDFLAGS  += -L$(XEN_ROOT)/tools/libxc -lxenctrl
    40.9  
   40.10  LIB_OBJS := $(patsubst %.c,%.o,$(SRCS))
   40.11  PIC_OBJS := $(patsubst %.c,%.opic,$(SRCS))
    41.1 --- a/tools/debugger/libxendebug/xendebug.c	Wed Aug 24 16:16:52 2005 -0700
    41.2 +++ b/tools/debugger/libxendebug/xendebug.c	Thu Aug 25 11:18:47 2005 -0700
    41.3 @@ -12,7 +12,7 @@
    41.4  #include <string.h>
    41.5  #include <errno.h>
    41.6  #include <sys/mman.h>
    41.7 -#include <xc.h>
    41.8 +#include <xenctrl.h>
    41.9  #include "list.h"
   41.10  
   41.11  #if defined(__i386__)
    42.1 --- a/tools/debugger/libxendebug/xendebug.h	Wed Aug 24 16:16:52 2005 -0700
    42.2 +++ b/tools/debugger/libxendebug/xendebug.h	Thu Aug 25 11:18:47 2005 -0700
    42.3 @@ -9,7 +9,7 @@
    42.4  #ifndef _XENDEBUG_H_DEFINED
    42.5  #define _XENDEBUG_H_DEFINED
    42.6  
    42.7 -#include <xc.h>
    42.8 +#include <xenctrl.h>
    42.9  
   42.10  int xendebug_attach(int xc_handle,
   42.11  		    u32 domid,
    43.1 --- a/tools/debugger/pdb/pdb_caml_domain.c	Wed Aug 24 16:16:52 2005 -0700
    43.2 +++ b/tools/debugger/pdb/pdb_caml_domain.c	Thu Aug 25 11:18:47 2005 -0700
    43.3 @@ -6,7 +6,7 @@
    43.4   * PDB's OCaml interface library for debugging domains
    43.5   */
    43.6  
    43.7 -#include <xc.h>
    43.8 +#include <xenctrl.h>
    43.9  #include <xendebug.h>
   43.10  #include <errno.h>
   43.11  #include <stdio.h>
    44.1 --- a/tools/debugger/pdb/pdb_caml_evtchn.c	Wed Aug 24 16:16:52 2005 -0700
    44.2 +++ b/tools/debugger/pdb/pdb_caml_evtchn.c	Thu Aug 25 11:18:47 2005 -0700
    44.3 @@ -6,7 +6,7 @@
    44.4   * PDB's OCaml interface library for event channels
    44.5   */
    44.6  
    44.7 -#include <xc.h>
    44.8 +#include <xenctrl.h>
    44.9  #include <stdio.h>
   44.10  #include <stdlib.h>
   44.11  #include <string.h>
    45.1 --- a/tools/debugger/pdb/pdb_caml_process.c	Wed Aug 24 16:16:52 2005 -0700
    45.2 +++ b/tools/debugger/pdb/pdb_caml_process.c	Thu Aug 25 11:18:47 2005 -0700
    45.3 @@ -15,7 +15,7 @@
    45.4  #include <caml/memory.h>
    45.5  #include <caml/mlvalues.h>
    45.6  
    45.7 -#include <xc.h>
    45.8 +#include <xenctrl.h>
    45.9  #include <xen/xen.h>
   45.10  #include <xen/io/domain_controller.h>
   45.11  #include <xen/linux/privcmd.h>
    46.1 --- a/tools/debugger/pdb/pdb_caml_xc.c	Wed Aug 24 16:16:52 2005 -0700
    46.2 +++ b/tools/debugger/pdb/pdb_caml_xc.c	Thu Aug 25 11:18:47 2005 -0700
    46.3 @@ -6,7 +6,7 @@
    46.4   * PDB's OCaml interface library for debugging domains
    46.5   */
    46.6  
    46.7 -#include <xc.h>
    46.8 +#include <xenctrl.h>
    46.9  #include <xendebug.h>
   46.10  #include <errno.h>
   46.11  #include <stdio.h>
    47.1 --- a/tools/debugger/pdb/pdb_caml_xcs.c	Wed Aug 24 16:16:52 2005 -0700
    47.2 +++ b/tools/debugger/pdb/pdb_caml_xcs.c	Thu Aug 25 11:18:47 2005 -0700
    47.3 @@ -17,7 +17,7 @@
    47.4  #include <sys/types.h>
    47.5  #include <sys/socket.h>
    47.6  #include <errno.h>
    47.7 -#include <xc.h>
    47.8 +#include <xenctrl.h>
    47.9  
   47.10  #include <xen/xen.h>
   47.11  #include <xen/io/domain_controller.h>
    48.1 --- a/tools/debugger/pdb/pdb_xen.c	Wed Aug 24 16:16:52 2005 -0700
    48.2 +++ b/tools/debugger/pdb/pdb_xen.c	Thu Aug 25 11:18:47 2005 -0700
    48.3 @@ -7,7 +7,7 @@
    48.4   * PDB interface library for accessing Xen
    48.5   */
    48.6  
    48.7 -#include <xc.h>
    48.8 +#include <xenctrl.h>
    48.9  #include <stdio.h>
   48.10  #include <stdlib.h>
   48.11  #include <errno.h>
    49.1 --- a/tools/examples/Makefile	Wed Aug 24 16:16:52 2005 -0700
    49.2 +++ b/tools/examples/Makefile	Thu Aug 25 11:18:47 2005 -0700
    49.3 @@ -24,10 +24,14 @@ XEN_SCRIPTS += block-enbd
    49.4  XEN_BOOT_DIR = /usr/lib/xen/boot
    49.5  XEN_BOOT = mem-map.sxp
    49.6  
    49.7 +XEN_HOTPLUG_DIR = /etc/hotplug.d/xen-backend
    49.8 +XEN_HOTPLUG_SCRIPTS = backend.hotplug
    49.9 +
   49.10  all: 
   49.11  build:
   49.12  
   49.13 -install: all install-initd install-configs install-scripts install-boot
   49.14 +install: all install-initd install-configs install-scripts install-boot \
   49.15 +	 install-hotplug
   49.16  
   49.17  install-initd:
   49.18  	[ -d $(DESTDIR)/etc/init.d ] || $(INSTALL_DIR) $(DESTDIR)/etc/init.d
   49.19 @@ -60,4 +64,12 @@ install-boot:
   49.20  	    $(INSTALL_PROG) $$i $(DESTDIR)$(XEN_BOOT_DIR); \
   49.21  	done
   49.22  
   49.23 +install-hotplug:
   49.24 +	[ -d $(DESTDIR)$(XEN_HOTPLUG_DIR) ] || \
   49.25 +		$(INSTALL_DIR) $(DESTDIR)$(XEN_HOTPLUG_DIR)
   49.26 +	for i in $(XEN_HOTPLUG_SCRIPTS); \
   49.27 +	    do [ -a $(DESTDIR)$(XEN_HOTPLUG_DIR)/$$i ] || \
   49.28 +	    $(INSTALL_PROG) $$i $(DESTDIR)$(XEN_HOTPLUG_DIR); \
   49.29 +	done
   49.30 +
   49.31  clean:
    50.1 --- a/tools/examples/README	Wed Aug 24 16:16:52 2005 -0700
    50.2 +++ b/tools/examples/README	Thu Aug 25 11:18:47 2005 -0700
    50.3 @@ -9,9 +9,20 @@ If you write a useful script and would l
    50.4  send it (preferably with a little summary to go in this file) to
    50.5  <xen-devel@lists.sourceforge.net> so we can add it to this directory.
    50.6  
    50.7 +block-enbd          - binds/unbinds network block devices
    50.8 +block-file          - binds/unbinds file to loopback device
    50.9 +mem-map.sxp         - memory map xend configuration file.
   50.10  network             - default network setup script called by xend at startup.
   50.11 +network-route       - default xen network start/stop script.
   50.12 +network-nat         - default xen network start/stop script when using NAT.
   50.13  vif-bridge          - default virtual network interface setup script.
   50.14 +vif-route           - default xen virtual network start/stop script
   50.15 +vif-nat             - configures vif in routed-nat mode.
   50.16  xend-config.sxp     - default xend configuration file.
   50.17  xmexample1          - example configuration script for 'xm create'.
   50.18  xmexample2          - a more complex configuration script for 'xm create'.
   50.19 +xmexample3          - an advanced configuration script for 'xm create' 
   50.20 +                      that utilizes the vmid.
   50.21 +xmexample.vmx       - a configuration script for creating a vmx domain with
   50.22 +                      'xm create'.
   50.23  
    51.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    51.2 +++ b/tools/examples/backend.hotplug	Thu Aug 25 11:18:47 2005 -0700
    51.3 @@ -0,0 +1,21 @@
    51.4 +#! /bin/sh
    51.5 +
    51.6 +#DEVPATH=/devices/xen-backend/vif-1-0
    51.7 +#ACTION=add
    51.8 +
    51.9 +PATH=/etc/xen/scripts:$PATH
   51.10 +
   51.11 +DEV=$(basename "$DEVPATH")
   51.12 +case "$ACTION" in
   51.13 +  add)
   51.14 +    case "$DEV" in
   51.15 +      vif-*)
   51.16 +        vif=$(echo "$DEV" | sed 's/-\([0-9]*\)-\([0-9]*\)/\1.\2/')
   51.17 +        vif-bridge up domain=unknown vif="$vif" mac=fe:ff:ff:ff:ff:ff bridge=xen-br0 >/dev/null 2>&1
   51.18 +        ;;
   51.19 +    esac
   51.20 +    ;;
   51.21 +  remove)
   51.22 +    ;;
   51.23 +esac
   51.24 +
    52.1 --- a/tools/examples/vif-bridge	Wed Aug 24 16:16:52 2005 -0700
    52.2 +++ b/tools/examples/vif-bridge	Thu Aug 25 11:18:47 2005 -0700
    52.3 @@ -74,8 +74,10 @@ if [ "${bridge}" == "null" ] ; then
    52.4      exit
    52.5  fi
    52.6  
    52.7 -# Add/remove vif to/from bridge.
    52.8 -brctl ${brcmd} ${bridge} ${vif}
    52.9 +# Add vif to bridge. vifs are auto-removed from bridge.
   52.10 +if [ "${brcmd}" == "addif" ] ; then
   52.11 +    brctl ${brcmd} ${bridge} ${vif}
   52.12 +fi
   52.13  ifconfig ${vif} $OP
   52.14  
   52.15  if [ ${ip} ] ; then
    53.1 --- a/tools/firmware/acpi/acpi2_0.h	Wed Aug 24 16:16:52 2005 -0700
    53.2 +++ b/tools/firmware/acpi/acpi2_0.h	Thu Aug 25 11:18:47 2005 -0700
    53.3 @@ -18,7 +18,7 @@
    53.4  #ifndef _ACPI_2_0_H_
    53.5  #define _ACPI_2_0_H_
    53.6  
    53.7 -#include "xc.h"  // for u8, u16, u32, u64 definition
    53.8 +#include "xenctrl.h"  // for u8, u16, u32, u64 definition
    53.9  
   53.10  #pragma pack (1)
   53.11  
    54.1 --- a/tools/ioemu/hw/i8254.c	Wed Aug 24 16:16:52 2005 -0700
    54.2 +++ b/tools/ioemu/hw/i8254.c	Thu Aug 25 11:18:47 2005 -0700
    54.3 @@ -22,7 +22,7 @@
    54.4   * THE SOFTWARE.
    54.5   */
    54.6  #include "vl.h"
    54.7 -#include "xc.h"
    54.8 +#include "xenctrl.h"
    54.9  #include <io/ioreq.h>
   54.10  
   54.11  //#define DEBUG_PIT
    55.1 --- a/tools/ioemu/hw/i8259.c	Wed Aug 24 16:16:52 2005 -0700
    55.2 +++ b/tools/ioemu/hw/i8259.c	Thu Aug 25 11:18:47 2005 -0700
    55.3 @@ -22,7 +22,7 @@
    55.4   * THE SOFTWARE.
    55.5   */
    55.6  #include "vl.h"
    55.7 -#include "xc.h"
    55.8 +#include "xenctrl.h"
    55.9  #include <io/ioreq.h>
   55.10  
   55.11  /* debug PIC */
    56.1 --- a/tools/ioemu/hw/ioapic.h	Wed Aug 24 16:16:52 2005 -0700
    56.2 +++ b/tools/ioemu/hw/ioapic.h	Thu Aug 25 11:18:47 2005 -0700
    56.3 @@ -26,7 +26,7 @@
    56.4  #ifndef __IOAPIC_H
    56.5  #define __IOAPIC_H
    56.6  
    56.7 -#include "xc.h"
    56.8 +#include "xenctrl.h"
    56.9  #include <io/ioreq.h>
   56.10  #include <io/vmx_vlapic.h>
   56.11  
    57.1 --- a/tools/ioemu/target-i386-dm/Makefile	Wed Aug 24 16:16:52 2005 -0700
    57.2 +++ b/tools/ioemu/target-i386-dm/Makefile	Thu Aug 25 11:18:47 2005 -0700
    57.3 @@ -188,7 +188,7 @@ endif
    57.4  #########################################################
    57.5  
    57.6  DEFINES+=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DAPIC_SUPPORT
    57.7 -LIBS+=-lm -L../../libxc -lxc
    57.8 +LIBS+=-lm -L../../libxc -lxenctrl
    57.9  ifndef CONFIG_USER_ONLY
   57.10  LIBS+=-lz
   57.11  endif
    58.1 --- a/tools/ioemu/target-i386-dm/helper2.c	Wed Aug 24 16:16:52 2005 -0700
    58.2 +++ b/tools/ioemu/target-i386-dm/helper2.c	Thu Aug 25 11:18:47 2005 -0700
    58.3 @@ -47,7 +47,7 @@
    58.4  #include <fcntl.h>
    58.5  #include <sys/ioctl.h>
    58.6  
    58.7 -#include "xc.h"
    58.8 +#include "xenctrl.h"
    58.9  #include <io/ioreq.h>
   58.10  
   58.11  #include "cpu.h"
    59.1 --- a/tools/ioemu/vl.c	Wed Aug 24 16:16:52 2005 -0700
    59.2 +++ b/tools/ioemu/vl.c	Thu Aug 25 11:18:47 2005 -0700
    59.3 @@ -72,7 +72,7 @@
    59.4  #endif
    59.5  #endif /* CONFIG_SDL */
    59.6  
    59.7 -#include "xc.h"
    59.8 +#include "xenctrl.h"
    59.9  #include "exec-all.h"
   59.10  
   59.11  //#define DO_TB_FLUSH
    60.1 --- a/tools/libxc/Makefile	Wed Aug 24 16:16:52 2005 -0700
    60.2 +++ b/tools/libxc/Makefile	Thu Aug 25 11:18:47 2005 -0700
    60.3 @@ -12,28 +12,32 @@ CC       = gcc
    60.4  XEN_ROOT = ../..
    60.5  include $(XEN_ROOT)/tools/Rules.mk
    60.6  
    60.7 -SRCS     :=
    60.8 -SRCS     += xc_sedf.c
    60.9 -SRCS     += xc_bvtsched.c
   60.10 -SRCS     += xc_core.c
   60.11 -SRCS     += xc_domain.c
   60.12 -SRCS     += xc_evtchn.c
   60.13 -SRCS     += xc_gnttab.c
   60.14 -SRCS     += xc_load_bin.c
   60.15 -SRCS     += xc_load_elf.c
   60.16 -SRCS     += xc_linux_build.c
   60.17 -SRCS     += xc_misc.c
   60.18 -SRCS     += xc_physdev.c
   60.19 -SRCS     += xc_private.c
   60.20 +SRCS       :=
   60.21 +BUILD_SRCS :=
   60.22 +SRCS       += xc_bvtsched.c
   60.23 +SRCS       += xc_core.c
   60.24 +SRCS       += xc_domain.c
   60.25 +SRCS       += xc_evtchn.c
   60.26 +SRCS       += xc_gnttab.c
   60.27 +SRCS       += xc_misc.c
   60.28 +SRCS       += xc_physdev.c
   60.29 +SRCS       += xc_private.c
   60.30 +SRCS       += xc_sedf.c
   60.31 +
   60.32  ifeq ($(XEN_TARGET_ARCH),ia64)
   60.33 -SRCS     += xc_ia64_stubs.c
   60.34 +BUILD_SRCS += xc_ia64_stubs.c
   60.35  else
   60.36 -SRCS     += xc_load_aout9.c
   60.37 -SRCS     += xc_linux_restore.c
   60.38 -SRCS     += xc_linux_save.c
   60.39 -SRCS     += xc_vmx_build.c
   60.40 -SRCS     += xc_ptrace.c
   60.41 -SRCS     += xc_ptrace_core.c
   60.42 +SRCS       += xc_ptrace.c
   60.43 +SRCS       += xc_ptrace_core.c
   60.44 +
   60.45 +BUILD_SRCS := xc_load_aout9.c
   60.46 +BUILD_SRCS += xc_load_bin.c
   60.47 +BUILD_SRCS += xc_load_elf.c
   60.48 +BUILD_SRCS += xc_linux_build.c
   60.49 +BUILD_SRCS += xc_linux_restore.c
   60.50 +BUILD_SRCS += xc_linux_save.c
   60.51 +BUILD_SRCS += xc_vmx_build.c
   60.52 +BUILD_SRCS += xg_private.c
   60.53  endif
   60.54  
   60.55  CFLAGS   += -Wall
   60.56 @@ -43,13 +47,20 @@ CFLAGS   += -fno-strict-aliasing
   60.57  CFLAGS   += $(INCLUDES) -I.
   60.58  # Get gcc to generate the dependencies for us.
   60.59  CFLAGS   += -Wp,-MD,.$(@F).d
   60.60 +LDFLAGS  += -L.
   60.61  DEPS     = .*.d
   60.62  
   60.63  LIB_OBJS := $(patsubst %.c,%.o,$(SRCS))
   60.64  PIC_OBJS := $(patsubst %.c,%.opic,$(SRCS))
   60.65  
   60.66 -LIB      := libxc.a libxc-pic.a
   60.67 -LIB      += libxc.so libxc.so.$(MAJOR) libxc.so.$(MAJOR).$(MINOR)
   60.68 +LIB_BUILD_OBJS := $(patsubst %.c,%.o,$(BUILD_SRCS))
   60.69 +PIC_BUILD_OBJS := $(patsubst %.c,%.opic,$(BUILD_SRCS))
   60.70 +
   60.71 +LIB := libxenctrl.a
   60.72 +LIB += libxenctrl.so libxenctrl.so.$(MAJOR) libxenctrl.so.$(MAJOR).$(MINOR)
   60.73 +
   60.74 +LIB += libxenguest.a
   60.75 +LIB += libxenguest.so libxenguest.so.$(MAJOR) libxenguest.so.$(MAJOR).$(MINOR)
   60.76  
   60.77  all: build
   60.78  build: check-for-zlib mk-symlinks
   60.79 @@ -77,11 +88,16 @@ mk-symlinks:
   60.80  install: build
   60.81  	[ -d $(DESTDIR)/usr/$(LIBDIR) ] || $(INSTALL_DIR) $(DESTDIR)/usr/$(LIBDIR)
   60.82  	[ -d $(DESTDIR)/usr/include ] || $(INSTALL_DIR) $(DESTDIR)/usr/include
   60.83 -	$(INSTALL_PROG) libxc.so.$(MAJOR).$(MINOR) $(DESTDIR)/usr/$(LIBDIR)
   60.84 -	$(INSTALL_DATA) libxc.a $(DESTDIR)/usr/$(LIBDIR)
   60.85 -	ln -sf libxc.so.$(MAJOR).$(MINOR) $(DESTDIR)/usr/$(LIBDIR)/libxc.so.$(MAJOR)
   60.86 -	ln -sf libxc.so.$(MAJOR) $(DESTDIR)/usr/$(LIBDIR)/libxc.so
   60.87 -	$(INSTALL_DATA) xc.h $(DESTDIR)/usr/include
   60.88 +	$(INSTALL_PROG) libxenctrl.so.$(MAJOR).$(MINOR) $(DESTDIR)/usr/$(LIBDIR)
   60.89 +	$(INSTALL_DATA) libxenctrl.a $(DESTDIR)/usr/$(LIBDIR)
   60.90 +	ln -sf libxenctrl.so.$(MAJOR).$(MINOR) $(DESTDIR)/usr/$(LIBDIR)/libxenctrl.so.$(MAJOR)
   60.91 +	ln -sf libxenctrl.so.$(MAJOR) $(DESTDIR)/usr/$(LIBDIR)/libxenctrl.so
   60.92 +	$(INSTALL_DATA) xenctrl.h $(DESTDIR)/usr/include
   60.93 +
   60.94 +	$(INSTALL_PROG) libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)/usr/$(LIBDIR)
   60.95 +	$(INSTALL_DATA) libxenguest.a $(DESTDIR)/usr/$(LIBDIR)
   60.96 +	ln -sf libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)/usr/$(LIBDIR)/libxenguest.so.$(MAJOR)
   60.97 +	ln -sf libxenguest.so.$(MAJOR) $(DESTDIR)/usr/$(LIBDIR)/libxenguest.so
   60.98  
   60.99  .PHONY: TAGS clean rpm install all
  60.100  
  60.101 @@ -100,18 +116,30 @@ rpm: build
  60.102  	mv staging/i386/*.rpm .
  60.103  	rm -rf staging
  60.104  
  60.105 -libxc.a: $(LIB_OBJS)
  60.106 -	$(AR) rc $@ $^
  60.107 +# libxenctrl
  60.108  
  60.109 -libxc-pic.a: $(PIC_OBJS)
  60.110 +libxenctrl.a: $(LIB_OBJS)
  60.111  	$(AR) rc $@ $^
  60.112  
  60.113 -libxc.so: libxc.so.$(MAJOR)
  60.114 +libxenctrl.so: libxenctrl.so.$(MAJOR)
  60.115  	ln -sf $< $@
  60.116 -libxc.so.$(MAJOR): libxc.so.$(MAJOR).$(MINOR)
  60.117 +libxenctrl.so.$(MAJOR): libxenctrl.so.$(MAJOR).$(MINOR)
  60.118  	ln -sf $< $@
  60.119  
  60.120 -libxc.so.$(MAJOR).$(MINOR): $(PIC_OBJS)
  60.121 -	$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-soname -Wl,libxc.so.$(MAJOR) -shared -o $@ $^ -lz
  60.122 +libxenctrl.so.$(MAJOR).$(MINOR): $(PIC_OBJS)
  60.123 +	$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-soname -Wl,libxenctrl.so.$(MAJOR) -shared -o $@ $^
  60.124 +
  60.125 +# libxenguest
  60.126 +
  60.127 +libxenguest.a: $(LIB_BUILD_OBJS)
  60.128 +	$(AR) rc $@ $^
  60.129 +
  60.130 +libxenguest.so: libxenguest.so.$(MAJOR)
  60.131 +	ln -sf $< $@
  60.132 +libxenguest.so.$(MAJOR): libxenguest.so.$(MAJOR).$(MINOR)
  60.133 +	ln -sf $< $@
  60.134 +
  60.135 +libxenguest.so.$(MAJOR).$(MINOR): $(PIC_BUILD_OBJS)
  60.136 +	$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-soname -Wl,libxenguest.so.$(MAJOR) -shared -o $@ $^ -lz -lxenctrl
  60.137  
  60.138  -include $(DEPS)
    61.1 --- a/tools/libxc/xc.h	Wed Aug 24 16:16:52 2005 -0700
    61.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    61.3 @@ -1,558 +0,0 @@
    61.4 -/******************************************************************************
    61.5 - * xc.h
    61.6 - * 
    61.7 - * A library for low-level access to the Xen control interfaces.
    61.8 - * 
    61.9 - * Copyright (c) 2003-2004, K A Fraser.
   61.10 - */
   61.11 -
   61.12 -#ifndef __XC_H__
   61.13 -#define __XC_H__
   61.14 -
   61.15 -#include <stdint.h>
   61.16 -
   61.17 -typedef uint8_t            u8;
   61.18 -typedef uint16_t           u16;
   61.19 -typedef uint32_t           u32;
   61.20 -typedef uint64_t           u64;
   61.21 -typedef int8_t             s8;
   61.22 -typedef int16_t            s16;
   61.23 -typedef int32_t            s32;
   61.24 -typedef int64_t            s64;
   61.25 -
   61.26 -#include <sys/ptrace.h>
   61.27 -#include <xen/xen.h>
   61.28 -#include <xen/dom0_ops.h>
   61.29 -#include <xen/event_channel.h>
   61.30 -#include <xen/sched_ctl.h>
   61.31 -#include <xen/acm.h>
   61.32 -
   61.33 -#ifdef __ia64__
   61.34 -#define XC_PAGE_SHIFT           14
   61.35 -#else
   61.36 -#define XC_PAGE_SHIFT           12
   61.37 -#endif
   61.38 -#define XC_PAGE_SIZE            (1UL << XC_PAGE_SHIFT)
   61.39 -#define XC_PAGE_MASK            (~(XC_PAGE_SIZE-1))
   61.40 -
   61.41 -/*
   61.42 - *  DEFINITIONS FOR CPU BARRIERS
   61.43 - */ 
   61.44 -
   61.45 -#if defined(__i386__)
   61.46 -#define mb()  __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" )
   61.47 -#define rmb() __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" )
   61.48 -#define wmb() __asm__ __volatile__ ( "" : : : "memory")
   61.49 -#elif defined(__x86_64__)
   61.50 -#define mb()  __asm__ __volatile__ ( "mfence" : : : "memory")
   61.51 -#define rmb() __asm__ __volatile__ ( "lfence" : : : "memory")
   61.52 -#define wmb() __asm__ __volatile__ ( "" : : : "memory")
   61.53 -#elif defined(__ia64__)
   61.54 -/* FIXME */
   61.55 -#define mb()
   61.56 -#define rmb()
   61.57 -#define wmb()
   61.58 -#else
   61.59 -#error "Define barriers"
   61.60 -#endif
   61.61 -
   61.62 -/*
   61.63 - *  INITIALIZATION FUNCTIONS
   61.64 - */ 
   61.65 -
   61.66 -/**
   61.67 - * This function opens a handle to the hypervisor interface.  This function can
   61.68 - * be called multiple times within a single process.  Multiple processes can
   61.69 - * have an open hypervisor interface at the same time.
   61.70 - *
   61.71 - * Each call to this function should have a corresponding call to
   61.72 - * xc_interface_close().
   61.73 - *
   61.74 - * This function can fail if the caller does not have superuser permission or
   61.75 - * if a Xen-enabled kernel is not currently running.
   61.76 - *
   61.77 - * @return a handle to the hypervisor interface or -1 on failure
   61.78 - */
   61.79 -int xc_interface_open(void);
   61.80 -
   61.81 -/**
   61.82 - * This function closes an open hypervisor interface.
   61.83 - *
   61.84 - * This function can fail if the handle does not represent an open interface or
   61.85 - * if there were problems closing the interface.
   61.86 - *
   61.87 - * @parm xc_handle a handle to an open hypervisor interface
   61.88 - * @return 0 on success, -1 otherwise.
   61.89 - */
   61.90 -int xc_interface_close(int xc_handle);
   61.91 -
   61.92 -/*
   61.93 - * DOMAIN DEBUGGING FUNCTIONS
   61.94 - */
   61.95 -
   61.96 -typedef struct xc_core_header {
   61.97 -    unsigned int xch_magic;
   61.98 -    unsigned int xch_nr_vcpus;
   61.99 -    unsigned int xch_nr_pages;
  61.100 -    unsigned int xch_ctxt_offset;
  61.101 -    unsigned int xch_index_offset;
  61.102 -    unsigned int xch_pages_offset;
  61.103 -} xc_core_header_t;
  61.104 -
  61.105 -
  61.106 -long xc_ptrace(enum __ptrace_request request, 
  61.107 -               u32  domid,
  61.108 -               long addr, 
  61.109 -               long data);
  61.110 -
  61.111 -long xc_ptrace_core(enum __ptrace_request request, 
  61.112 -                    u32 domid, 
  61.113 -                    long addr, 
  61.114 -                    long data);
  61.115 -
  61.116 -int xc_waitdomain(int domain, 
  61.117 -                  int *status, 
  61.118 -                  int options);
  61.119 -
  61.120 -int xc_waitdomain_core(int domain, 
  61.121 -                       int *status, 
  61.122 -                       int options);
  61.123 -
  61.124 -/*
  61.125 - * DOMAIN MANAGEMENT FUNCTIONS
  61.126 - */
  61.127 -
  61.128 -typedef struct {
  61.129 -    u32           domid;
  61.130 -    u32           ssidref;
  61.131 -    unsigned int  dying:1, crashed:1, shutdown:1, 
  61.132 -                  paused:1, blocked:1, running:1;
  61.133 -    unsigned int  shutdown_reason; /* only meaningful if shutdown==1 */
  61.134 -    unsigned long nr_pages;
  61.135 -    unsigned long shared_info_frame;
  61.136 -    u64           cpu_time;
  61.137 -    unsigned long max_memkb;
  61.138 -    unsigned int  vcpus;
  61.139 -    s32           vcpu_to_cpu[MAX_VIRT_CPUS];
  61.140 -    cpumap_t      cpumap[MAX_VIRT_CPUS];
  61.141 -} xc_dominfo_t;
  61.142 -
  61.143 -typedef dom0_getdomaininfo_t xc_domaininfo_t;
  61.144 -int xc_domain_create(int xc_handle, 
  61.145 -                     u32 ssidref,
  61.146 -                     u32 *pdomid);
  61.147 -
  61.148 -
  61.149 -int xc_domain_dumpcore(int xc_handle, 
  61.150 -                       u32 domid,
  61.151 -                       const char *corename);
  61.152 -
  61.153 -
  61.154 -/**
  61.155 - * This function pauses a domain. A paused domain still exists in memory
  61.156 - * however it does not receive any timeslices from the hypervisor.
  61.157 - *
  61.158 - * @parm xc_handle a handle to an open hypervisor interface
  61.159 - * @parm domid the domain id to pause
  61.160 - * @return 0 on success, -1 on failure.
  61.161 - */
  61.162 -int xc_domain_pause(int xc_handle, 
  61.163 -                    u32 domid);
  61.164 -/**
  61.165 - * This function unpauses a domain.  The domain should have been previously
  61.166 - * paused.
  61.167 - *
  61.168 - * @parm xc_handle a handle to an open hypervisor interface
  61.169 - * @parm domid the domain id to unpause
  61.170 - * return 0 on success, -1 on failure
  61.171 - */
  61.172 -int xc_domain_unpause(int xc_handle, 
  61.173 -                      u32 domid);
  61.174 -
  61.175 -/**
  61.176 - * This function will destroy a domain.  Destroying a domain removes the domain
  61.177 - * completely from memory.  This function should be called after sending the
  61.178 - * domain a SHUTDOWN control message to free up the domain resources.
  61.179 - *
  61.180 - * @parm xc_handle a handle to an open hypervisor interface
  61.181 - * @parm domid the domain id to destroy
  61.182 - * @return 0 on success, -1 on failure
  61.183 - */
  61.184 -int xc_domain_destroy(int xc_handle, 
  61.185 -                      u32 domid);
  61.186 -int xc_domain_pincpu(int xc_handle,
  61.187 -                     u32 domid,
  61.188 -                     int vcpu,
  61.189 -                     cpumap_t *cpumap);
  61.190 -/**
  61.191 - * This function will return information about one or more domains. It is
  61.192 - * designed to iterate over the list of domains. If a single domain is
  61.193 - * requested, this function will return the next domain in the list - if
  61.194 - * one exists. It is, therefore, important in this case to make sure the
  61.195 - * domain requested was the one returned.
  61.196 - *
  61.197 - * @parm xc_handle a handle to an open hypervisor interface
  61.198 - * @parm first_domid the first domain to enumerate information from.  Domains
  61.199 - *                   are currently enumerate in order of creation.
  61.200 - * @parm max_doms the number of elements in info
  61.201 - * @parm info an array of max_doms size that will contain the information for
  61.202 - *            the enumerated domains.
  61.203 - * @return the number of domains enumerated or -1 on error
  61.204 - */
  61.205 -int xc_domain_getinfo(int xc_handle,
  61.206 -                      u32 first_domid, 
  61.207 -                      unsigned int max_doms,
  61.208 -                      xc_dominfo_t *info);
  61.209 -
  61.210 -/**
  61.211 - * This function will return information about one or more domains, using a
  61.212 - * single hypercall.  The domain information will be stored into the supplied
  61.213 - * array of xc_domaininfo_t structures.
  61.214 - *
  61.215 - * @parm xc_handle a handle to an open hypervisor interface
  61.216 - * @parm first_domain the first domain to enumerate information from.
  61.217 - *                    Domains are currently enumerate in order of creation.
  61.218 - * @parm max_domains the number of elements in info
  61.219 - * @parm info an array of max_doms size that will contain the information for
  61.220 - *            the enumerated domains.
  61.221 - * @return the number of domains enumerated or -1 on error
  61.222 - */
  61.223 -int xc_domain_getinfolist(int xc_handle,
  61.224 -                          u32 first_domain,
  61.225 -                          unsigned int max_domains,
  61.226 -                          xc_domaininfo_t *info);
  61.227 -
  61.228 -/**
  61.229 - * This function returns information about one domain.  This information is
  61.230 - * more detailed than the information from xc_domain_getinfo().
  61.231 - *
  61.232 - * @parm xc_handle a handle to an open hypervisor interface
  61.233 - * @parm domid the domain to get information from
  61.234 - * @parm info a pointer to an xc_domaininfo_t to store the domain information
  61.235 - * @parm ctxt a pointer to a structure to store the execution context of the
  61.236 - *            domain
  61.237 - * @return 0 on success, -1 on failure
  61.238 - */
  61.239 -int xc_domain_get_vcpu_context(int xc_handle,
  61.240 -                               u32 domid,
  61.241 -                               u32 vcpu,
  61.242 -                               vcpu_guest_context_t *ctxt);
  61.243 -
  61.244 -int xc_domain_setcpuweight(int xc_handle,
  61.245 -                           u32 domid,
  61.246 -                           float weight);
  61.247 -long long xc_domain_get_cpu_usage(int xc_handle,
  61.248 -                                  domid_t domid,
  61.249 -                                  int vcpu);
  61.250 -
  61.251 -
  61.252 -typedef dom0_shadow_control_stats_t xc_shadow_control_stats_t;
  61.253 -int xc_shadow_control(int xc_handle,
  61.254 -                      u32 domid, 
  61.255 -                      unsigned int sop,
  61.256 -                      unsigned long *dirty_bitmap,
  61.257 -                      unsigned long pages,
  61.258 -                      xc_shadow_control_stats_t *stats);
  61.259 -
  61.260 -
  61.261 -#define XCFLAGS_VERBOSE   1
  61.262 -#define XCFLAGS_LIVE      2
  61.263 -#define XCFLAGS_DEBUG     4
  61.264 -#define XCFLAGS_CONFIGURE 8
  61.265 -
  61.266 -struct XcIOContext;
  61.267 -
  61.268 -/**
  61.269 - * This function will save a domain running Linux.
  61.270 - *
  61.271 - * @parm xc_handle a handle to an open hypervisor interface
  61.272 - * @parm fd the file descriptor to save a domain to
  61.273 - * @parm dom the id of the domain
  61.274 - * @return 0 on success, -1 on failure
  61.275 - */
  61.276 -int xc_linux_save(int xc_handle, int fd, u32 dom);
  61.277 -
  61.278 -/**
  61.279 - * This function will restore a saved domain running Linux.
  61.280 - *
  61.281 - * @parm xc_handle a handle to an open hypervisor interface
  61.282 - * @parm fd the file descriptor to restore a domain from
  61.283 - * @parm dom the id of the domain
  61.284 - * @parm nr_pfns the number of pages
  61.285 - * @parm store_evtchn the store event channel for this domain to use
  61.286 - * @parm store_mfn returned with the mfn of the store page
  61.287 - * @return 0 on success, -1 on failure
  61.288 - */
  61.289 -int xc_linux_restore(int xc_handle, int io_fd, u32 dom, unsigned long nr_pfns,
  61.290 -		     unsigned int store_evtchn, unsigned long *store_mfn);
  61.291 -
  61.292 -int xc_linux_build(int xc_handle,
  61.293 -                   u32 domid,
  61.294 -                   const char *image_name,
  61.295 -                   const char *ramdisk_name,
  61.296 -                   const char *cmdline,
  61.297 -                   unsigned int control_evtchn,
  61.298 -                   unsigned long flags,
  61.299 -                   unsigned int vcpus,
  61.300 -                   unsigned int store_evtchn,
  61.301 -                   unsigned long *store_mfn);
  61.302 -
  61.303 -struct mem_map;
  61.304 -int xc_vmx_build(int xc_handle,
  61.305 -                 u32 domid,
  61.306 -                 int memsize,
  61.307 -                 const char *image_name,
  61.308 -                 struct mem_map *memmap,
  61.309 -                 const char *ramdisk_name,
  61.310 -                 const char *cmdline,
  61.311 -                 unsigned int control_evtchn,
  61.312 -                 unsigned long flags,
  61.313 -                 unsigned int vcpus,
  61.314 -                 unsigned int store_evtchn,
  61.315 -                 unsigned long *store_mfn);
  61.316 -
  61.317 -int xc_bvtsched_global_set(int xc_handle,
  61.318 -                           unsigned long ctx_allow);
  61.319 -
  61.320 -int xc_bvtsched_domain_set(int xc_handle,
  61.321 -                           u32 domid,
  61.322 -                           u32 mcuadv,
  61.323 -                           int warpback,
  61.324 -                           s32 warpvalue,
  61.325 -                           long long warpl,
  61.326 -                           long long warpu);
  61.327 -
  61.328 -int xc_bvtsched_global_get(int xc_handle,
  61.329 -                           unsigned long *ctx_allow);
  61.330 -
  61.331 -int xc_bvtsched_domain_get(int xc_handle,
  61.332 -                           u32 domid,
  61.333 -                           u32 *mcuadv,
  61.334 -                           int *warpback,
  61.335 -                           s32 *warpvalue,
  61.336 -                           long long *warpl,
  61.337 -                           long long *warpu);
  61.338 -
  61.339 -int xc_sedf_domain_set(int xc_handle,
  61.340 -                          u32 domid,
  61.341 -                          u64 period, u64 slice, u64 latency, u16 extratime, u16 weight);
  61.342 -
  61.343 -int xc_sedf_domain_get(int xc_handle,
  61.344 -                          u32 domid,
  61.345 -                          u64* period, u64 *slice, u64 *latency, u16 *extratime, u16* weight);
  61.346 -
  61.347 -typedef evtchn_status_t xc_evtchn_status_t;
  61.348 -
  61.349 -/*
  61.350 - * EVENT CHANNEL FUNCTIONS
  61.351 - */
  61.352 -
  61.353 -/**
  61.354 - * This function allocates an unbound port.  Ports are named endpoints used for
  61.355 - * interdomain communication.  This function is most useful in opening a
  61.356 - * well-known port within a domain to receive events on.
  61.357 - *
  61.358 - * @parm xc_handle a handle to an open hypervisor interface
  61.359 - * @parm dom the ID of the domain.  This maybe DOMID_SELF
  61.360 - * @parm port a pointer to a port.  This is an in/out parameter.  If *port is
  61.361 - *            0, then a new port will be assigned, if port is > 0 then that
  61.362 - *            port is allocated if the port is unallocated.
  61.363 - * @return 0 on success, -1 on failure
  61.364 - */
  61.365 -int xc_evtchn_alloc_unbound(int xc_handle,
  61.366 -                            u32 dom,
  61.367 -                            int *port);
  61.368 -
  61.369 -/**
  61.370 - * This function creates a pair of ports between two domains.  A port can only
  61.371 - * be bound once within a domain.
  61.372 - *
  61.373 - * @parm xc_handle a handle to an open hypervisor interface
  61.374 - * @parm dom1 one of the two domains to connect.  Can be DOMID_SELF.
  61.375 - * @parm dom2 the other domain to connect.  Can be DOMID_SELF.
  61.376 - * @parm port1 an in/out parameter.  If > 0, then try to connect *port.  If
  61.377 - *             0, then allocate a new port and store the port in *port.
  61.378 - * @parm port2 the port connected on port2.  This parameter behaves the same
  61.379 - *             way as port1.
  61.380 - * @return 0 on success, -1 on error.
  61.381 - */
  61.382 -int xc_evtchn_bind_interdomain(int xc_handle,
  61.383 -                               u32 dom1,
  61.384 -                               u32 dom2,
  61.385 -                               int *port1,
  61.386 -                               int *port2);
  61.387 -int xc_evtchn_bind_virq(int xc_handle,
  61.388 -                        int virq,
  61.389 -                        int *port);
  61.390 -
  61.391 -/**
  61.392 - * This function will close a single port on an event channel.
  61.393 - *
  61.394 - * @parm xc_handle a handle to an open hypervisor interface
  61.395 - * @parm dom the domain that the port exists on.  May be DOMID_SELF.
  61.396 - * @parm port the port to close
  61.397 - * @return 0 on success, -1 on error
  61.398 - */
  61.399 -int xc_evtchn_close(int xc_handle,
  61.400 -                    u32 dom,   /* may be DOMID_SELF */
  61.401 -                    int port);
  61.402 -
  61.403 -/**
  61.404 - * This function generates a notify event on a bound port.
  61.405 - *
  61.406 - * Notifies can be read within Linux by opening /dev/xen/evtchn and reading
  61.407 - * a 16 bit value.  The result will be the port the event occurred on.  When
  61.408 - * events occur, the port is masked until the 16 bit port value is written back
  61.409 - * to the file.  When /dev/xen/evtchn is opened, it has to be bound via an
  61.410 - * ioctl to each port to listen on.  The ioctl for binding is _IO('E', 2).  The
  61.411 - * parameter is the port to listen on.
  61.412 - *
  61.413 - * @parm xc_handle a handle to an open hypervisor interface
  61.414 - * @parm local_port the port to generate the notify on
  61.415 - * @return 0 on success, -1 on error
  61.416 - */
  61.417 -int xc_evtchn_send(int xc_handle,
  61.418 -                   int local_port);
  61.419 -int xc_evtchn_status(int xc_handle,
  61.420 -                     u32 dom, /* may be DOMID_SELF */
  61.421 -                     int port,
  61.422 -                     xc_evtchn_status_t *status);
  61.423 -
  61.424 -int xc_physdev_pci_access_modify(int xc_handle,
  61.425 -                                 u32 domid,
  61.426 -                                 int bus,
  61.427 -                                 int dev,
  61.428 -                                 int func,
  61.429 -                                 int enable);
  61.430 -
  61.431 -int xc_readconsolering(int xc_handle,
  61.432 -                       char **pbuffer,
  61.433 -                       unsigned int *pnr_chars, 
  61.434 -                       int clear);
  61.435 -
  61.436 -typedef dom0_physinfo_t xc_physinfo_t;
  61.437 -int xc_physinfo(int xc_handle,
  61.438 -                xc_physinfo_t *info);
  61.439 -
  61.440 -int xc_sched_id(int xc_handle,
  61.441 -                int *sched_id);
  61.442 -
  61.443 -int xc_domain_setmaxmem(int xc_handle,
  61.444 -                        u32 domid, 
  61.445 -                        unsigned int max_memkb);
  61.446 -
  61.447 -int xc_domain_memory_increase_reservation(int xc_handle,
  61.448 -                                          u32 domid, 
  61.449 -                                          unsigned int mem_kb);
  61.450 -
  61.451 -typedef dom0_perfc_desc_t xc_perfc_desc_t;
  61.452 -/* IMPORTANT: The caller is responsible for mlock()'ing the @desc array. */
  61.453 -int xc_perfc_control(int xc_handle,
  61.454 -                     u32 op,
  61.455 -                     xc_perfc_desc_t *desc);
  61.456 -
  61.457 -/* read/write msr */
  61.458 -long long xc_msr_read(int xc_handle, int cpu_mask, int msr);
  61.459 -int xc_msr_write(int xc_handle, int cpu_mask, int msr, unsigned int low,
  61.460 -                  unsigned int high);
  61.461 -
  61.462 -/**
  61.463 - * Memory maps a range within one domain to a local address range.  Mappings
  61.464 - * should be unmapped with munmap and should follow the same rules as mmap
  61.465 - * regarding page alignment.  Returns NULL on failure.
  61.466 - *
  61.467 - * In Linux, the ring queue for the control channel is accessible by mapping
  61.468 - * the shared_info_frame (from xc_domain_getinfo()) + 2048.  The structure
  61.469 - * stored there is of type control_if_t.
  61.470 - *
  61.471 - * @parm xc_handle a handle on an open hypervisor interface
  61.472 - * @parm dom the domain to map memory from
  61.473 - * @parm size the amount of memory to map (in multiples of page size)
  61.474 - * @parm prot same flag as in mmap().
  61.475 - * @parm mfn the frame address to map.
  61.476 - */
  61.477 -void *xc_map_foreign_range(int xc_handle, u32 dom,
  61.478 -                            int size, int prot,
  61.479 -                            unsigned long mfn );
  61.480 -
  61.481 -void *xc_map_foreign_batch(int xc_handle, u32 dom, int prot,
  61.482 -                           unsigned long *arr, int num );
  61.483 -
  61.484 -int xc_get_pfn_list(int xc_handle, u32 domid, unsigned long *pfn_buf, 
  61.485 -                    unsigned long max_pfns);
  61.486 -
  61.487 -int xc_ia64_get_pfn_list(int xc_handle, u32 domid, unsigned long *pfn_buf, 
  61.488 -                    unsigned int start_page, unsigned int nr_pages);
  61.489 -
  61.490 -/*\
  61.491 - *  GRANT TABLE FUNCTIONS
  61.492 -\*/ 
  61.493 -
  61.494 -/**
  61.495 - * This function opens a handle to the more restricted grant table hypervisor
  61.496 - * interface. This may be used where the standard interface is not
  61.497 - * available because the domain is not privileged.
  61.498 - * This function can  be called multiple times within a single process.
  61.499 - * Multiple processes can have an open hypervisor interface at the same time.
  61.500 - *
  61.501 - * Each call to this function should have a corresponding call to
  61.502 - * xc_grant_interface_close().
  61.503 - *
  61.504 - * This function can fail if a Xen-enabled kernel is not currently running.
  61.505 - *
  61.506 - * @return a handle to the hypervisor grant table interface or -1 on failure
  61.507 - */
  61.508 -int xc_grant_interface_open(void);
  61.509 -
  61.510 -/**
  61.511 - * This function closes an open grant table hypervisor interface.
  61.512 - *
  61.513 - * This function can fail if the handle does not represent an open interface or
  61.514 - * if there were problems closing the interface.
  61.515 - *
  61.516 - * @parm xc_handle a handle to an open grant table hypervisor interface
  61.517 - * @return 0 on success, -1 otherwise.
  61.518 - */
  61.519 -int xc_grant_interface_close(int xc_handle);
  61.520 -
  61.521 -int xc_gnttab_map_grant_ref(int  xc_handle,
  61.522 -                            u64  host_virt_addr,
  61.523 -                            u32  dom,
  61.524 -                            u16  ref,
  61.525 -                            u16  flags,
  61.526 -                            s16 *handle,
  61.527 -                            u64 *dev_bus_addr);
  61.528 -
  61.529 -int xc_gnttab_unmap_grant_ref(int  xc_handle,
  61.530 -                              u64  host_virt_addr,
  61.531 -                              u64  dev_bus_addr,
  61.532 -                              u16  handle,
  61.533 -                              s16 *status);
  61.534 -
  61.535 -int xc_gnttab_setup_table(int        xc_handle,
  61.536 -                          u32        dom,
  61.537 -                          u16        nr_frames,
  61.538 -                          s16       *status,
  61.539 -                          unsigned long **frame_list);
  61.540 -
  61.541 -/* Grant debug builds only: */
  61.542 -int xc_gnttab_dump_table(int        xc_handle,
  61.543 -                         u32        dom,
  61.544 -                         s16       *status);
  61.545 -
  61.546 -/* Get current total pages allocated to a domain. */
  61.547 -long xc_get_tot_pages(int xc_handle, u32 domid);
  61.548 -
  61.549 -/* Execute a privileged dom0 operation. */
  61.550 -int xc_dom0_op(int xc_handle, dom0_op_t *op);
  61.551 -
  61.552 -/* Initializes the store (for dom0)
  61.553 -   remote_port should be the remote end of a bound interdomain channel between
  61.554 -   the store and dom0.
  61.555 -
  61.556 -   This function returns a shared frame that should be passed to
  61.557 -   xs_introduce_domain
  61.558 - */
  61.559 -long xc_init_store(int xc_handle, int remote_port);
  61.560 -
  61.561 -#endif /* __XC_H__ */
    62.1 --- a/tools/libxc/xc_core.c	Wed Aug 24 16:16:52 2005 -0700
    62.2 +++ b/tools/libxc/xc_core.c	Thu Aug 25 11:18:47 2005 -0700
    62.3 @@ -1,4 +1,4 @@
    62.4 -#include "xc_private.h"
    62.5 +#include "xg_private.h"
    62.6  #define ELFSIZE 32
    62.7  #include "xc_elf.h"
    62.8  #include <stdlib.h>
    63.1 --- a/tools/libxc/xc_domain.c	Wed Aug 24 16:16:52 2005 -0700
    63.2 +++ b/tools/libxc/xc_domain.c	Thu Aug 25 11:18:47 2005 -0700
    63.3 @@ -266,7 +266,7 @@ int xc_domain_memory_increase_reservatio
    63.4      int err;
    63.5      unsigned int npages = mem_kb / (PAGE_SIZE/1024);
    63.6  
    63.7 -    err = do_dom_mem_op(xc_handle, MEMOP_increase_reservation, NULL,
    63.8 +    err = xc_dom_mem_op(xc_handle, MEMOP_increase_reservation, NULL,
    63.9                          npages, 0, domid);
   63.10      if (err == npages)
   63.11          return 0;
    64.1 --- a/tools/libxc/xc_linux_build.c	Wed Aug 24 16:16:52 2005 -0700
    64.2 +++ b/tools/libxc/xc_linux_build.c	Thu Aug 25 11:18:47 2005 -0700
    64.3 @@ -2,7 +2,8 @@
    64.4   * xc_linux_build.c
    64.5   */
    64.6  
    64.7 -#include "xc_private.h"
    64.8 +#include "xg_private.h"
    64.9 +#include <xenctrl.h>
   64.10  
   64.11  #if defined(__i386__)
   64.12  #define ELFSIZE 32
   64.13 @@ -340,7 +341,7 @@ static int setup_guest(int xc_handle,
   64.14      unsigned long count, i;
   64.15      start_info_t *start_info;
   64.16      shared_info_t *shared_info;
   64.17 -    mmu_t *mmu = NULL;
   64.18 +    xc_mmu_t *mmu = NULL;
   64.19      int rc;
   64.20  
   64.21      unsigned long nr_pt_pages;
   64.22 @@ -490,7 +491,7 @@ static int setup_guest(int xc_handle,
   64.23          }
   64.24      }
   64.25  
   64.26 -    if ( (mmu = init_mmu_updates(xc_handle, dom)) == NULL )
   64.27 +    if ( (mmu = xc_init_mmu_updates(xc_handle, dom)) == NULL )
   64.28          goto error_out;
   64.29  
   64.30      /* setup page tables */
   64.31 @@ -520,9 +521,9 @@ static int setup_guest(int xc_handle,
   64.32          page_array[physmap_pfn++]);
   64.33      for ( count = 0; count < nr_pages; count++ )
   64.34      {
   64.35 -        if ( add_mmu_update(xc_handle, mmu,
   64.36 -                            (page_array[count] << PAGE_SHIFT) | 
   64.37 -                            MMU_MACHPHYS_UPDATE, count) )
   64.38 +        if ( xc_add_mmu_update(xc_handle, mmu,
   64.39 +			       (page_array[count] << PAGE_SHIFT) | 
   64.40 +			       MMU_MACHPHYS_UPDATE, count) )
   64.41          {
   64.42              munmap(physmap, PAGE_SIZE);
   64.43              goto error_out;
   64.44 @@ -602,7 +603,7 @@ static int setup_guest(int xc_handle,
   64.45      munmap(shared_info, PAGE_SIZE);
   64.46  
   64.47      /* Send the page update requests down to the hypervisor. */
   64.48 -    if ( finish_mmu_updates(xc_handle, mmu) )
   64.49 +    if ( xc_finish_mmu_updates(xc_handle, mmu) )
   64.50          goto error_out;
   64.51  
   64.52      free(mmu);
   64.53 @@ -676,7 +677,7 @@ int xc_linux_build(int xc_handle,
   64.54  
   64.55      op.cmd = DOM0_GETDOMAININFO;
   64.56      op.u.getdomaininfo.domain = (domid_t)domid;
   64.57 -    if ( (do_dom0_op(xc_handle, &op) < 0) || 
   64.58 +    if ( (xc_dom0_op(xc_handle, &op) < 0) || 
   64.59           ((u16)op.u.getdomaininfo.domain != domid) )
   64.60      {
   64.61          PERROR("Could not get info on domain");
   64.62 @@ -793,7 +794,7 @@ int xc_linux_build(int xc_handle,
   64.63      launch_op.u.setdomaininfo.ctxt   = ctxt;
   64.64  
   64.65      launch_op.cmd = DOM0_SETDOMAININFO;
   64.66 -    rc = do_dom0_op(xc_handle, &launch_op);
   64.67 +    rc = xc_dom0_op(xc_handle, &launch_op);
   64.68      
   64.69      return rc;
   64.70  
    65.1 --- a/tools/libxc/xc_linux_restore.c	Wed Aug 24 16:16:52 2005 -0700
    65.2 +++ b/tools/libxc/xc_linux_restore.c	Thu Aug 25 11:18:47 2005 -0700
    65.3 @@ -6,7 +6,12 @@
    65.4   * Copyright (c) 2003, K A Fraser.
    65.5   */
    65.6  
    65.7 -#include "xc_private.h"
    65.8 +#include <stdlib.h>
    65.9 +#include <unistd.h>
   65.10 +
   65.11 +#include "xg_private.h"
   65.12 +#include <xenctrl.h>
   65.13 +
   65.14  #include <xen/linux/suspend.h>
   65.15  
   65.16  #define MAX_BATCH_SIZE 1024
   65.17 @@ -89,7 +94,7 @@ int xc_linux_restore(int xc_handle, int 
   65.18  
   65.19      char *region_base;
   65.20  
   65.21 -    mmu_t *mmu = NULL;
   65.22 +    xc_mmu_t *mmu = NULL;
   65.23  
   65.24      /* used by debug verify code */
   65.25      unsigned long buf[PAGE_SIZE/sizeof(unsigned long)];
   65.26 @@ -132,7 +137,7 @@ int xc_linux_restore(int xc_handle, int 
   65.27      /* Get the domain's shared-info frame. */
   65.28      op.cmd = DOM0_GETDOMAININFO;
   65.29      op.u.getdomaininfo.domain = (domid_t)dom;
   65.30 -    if (do_dom0_op(xc_handle, &op) < 0) {
   65.31 +    if (xc_dom0_op(xc_handle, &op) < 0) {
   65.32          ERR("Could not get information on new domain");
   65.33          goto out;
   65.34      }
   65.35 @@ -158,7 +163,7 @@ int xc_linux_restore(int xc_handle, int 
   65.36          goto out;
   65.37      }
   65.38  
   65.39 -    mmu = init_mmu_updates(xc_handle, dom);
   65.40 +    mmu = xc_init_mmu_updates(xc_handle, dom);
   65.41      if (mmu == NULL) {
   65.42          ERR("Could not initialise for MMU updates");
   65.43          goto out;
   65.44 @@ -355,8 +360,9 @@ int xc_linux_restore(int xc_handle, int 
   65.45                  }
   65.46              }
   65.47  
   65.48 -            if ( add_mmu_update(xc_handle, mmu,
   65.49 -                                (mfn<<PAGE_SHIFT) | MMU_MACHPHYS_UPDATE, pfn) )
   65.50 +            if ( xc_add_mmu_update(xc_handle, mmu,
   65.51 +				   (mfn<<PAGE_SHIFT) | MMU_MACHPHYS_UPDATE,
   65.52 +				   pfn) )
   65.53              {
   65.54                  printf("machpys mfn=%ld pfn=%ld\n",mfn,pfn);
   65.55                  goto out;
   65.56 @@ -370,7 +376,7 @@ int xc_linux_restore(int xc_handle, int 
   65.57  
   65.58      DPRINTF("Received all pages\n");
   65.59  
   65.60 -    if ( finish_mmu_updates(xc_handle, mmu) )
   65.61 +    if ( xc_finish_mmu_updates(xc_handle, mmu) )
   65.62          goto out;
   65.63  
   65.64      /*
   65.65 @@ -388,14 +394,14 @@ int xc_linux_restore(int xc_handle, int 
   65.66          pin[nr_pins].mfn = pfn_to_mfn_table[i];
   65.67          if ( ++nr_pins == MAX_PIN_BATCH )
   65.68          {
   65.69 -            if ( do_mmuext_op(xc_handle, pin, nr_pins, dom) < 0 )
   65.70 +            if ( xc_mmuext_op(xc_handle, pin, nr_pins, dom) < 0 )
   65.71                  goto out;
   65.72              nr_pins = 0;
   65.73          }
   65.74      }
   65.75  
   65.76      if ( (nr_pins != 0) &&
   65.77 -         (do_mmuext_op(xc_handle, pin, nr_pins, dom) < 0) )
   65.78 +         (xc_mmuext_op(xc_handle, pin, nr_pins, dom) < 0) )
   65.79          goto out;
   65.80  
   65.81      DPRINTF("\b\b\b\b100%%\n");
   65.82 @@ -435,7 +441,7 @@ int xc_linux_restore(int xc_handle, int 
   65.83  
   65.84  	if ( count > 0 )
   65.85  	{
   65.86 -	    if ( (rc = do_dom_mem_op( xc_handle,
   65.87 +	    if ( (rc = xc_dom_mem_op( xc_handle,
   65.88  				       MEMOP_decrease_reservation,
   65.89  				       pfntab, count, 0, dom )) <0 )
   65.90  	    {
   65.91 @@ -586,7 +592,7 @@ int xc_linux_restore(int xc_handle, int 
   65.92      op.u.setdomaininfo.domain = (domid_t)dom;
   65.93      op.u.setdomaininfo.vcpu   = 0;
   65.94      op.u.setdomaininfo.ctxt   = &ctxt;
   65.95 -    rc = do_dom0_op(xc_handle, &op);
   65.96 +    rc = xc_dom0_op(xc_handle, &op);
   65.97  
   65.98      if ( rc != 0 )
   65.99      {
  65.100 @@ -597,7 +603,7 @@ int xc_linux_restore(int xc_handle, int 
  65.101      DPRINTF("Domain ready to be unpaused\n");
  65.102      op.cmd = DOM0_UNPAUSEDOMAIN;
  65.103      op.u.unpausedomain.domain = (domid_t)dom;
  65.104 -    rc = do_dom0_op(xc_handle, &op);
  65.105 +    rc = xc_dom0_op(xc_handle, &op);
  65.106      if (rc == 0) {
  65.107          /* Success: print the domain id. */
  65.108          DPRINTF("DOM=%u\n", dom);
    66.1 --- a/tools/libxc/xc_linux_save.c	Wed Aug 24 16:16:52 2005 -0700
    66.2 +++ b/tools/libxc/xc_linux_save.c	Thu Aug 25 11:18:47 2005 -0700
    66.3 @@ -7,11 +7,15 @@
    66.4   */
    66.5  
    66.6  #include <inttypes.h>
    66.7 +#include <time.h>
    66.8 +#include <stdlib.h>
    66.9 +#include <unistd.h>
   66.10  #include <sys/time.h>
   66.11 -#include "xc_private.h"
   66.12 +
   66.13 +#include "xg_private.h"
   66.14 +
   66.15  #include <xen/linux/suspend.h>
   66.16  #include <xen/io/domain_controller.h>
   66.17 -#include <time.h>
   66.18  
   66.19  #define BATCH_SIZE 1024   /* 1024 pages (4MB) at a time */
   66.20  
   66.21 @@ -772,7 +776,7 @@ int xc_linux_save(int xc_handle, int io_
   66.22                  goto out;
   66.23              }
   66.24       
   66.25 -            if ( get_pfn_type_batch(xc_handle, dom, batch, pfn_type) ){
   66.26 +            if ( xc_get_pfn_type_batch(xc_handle, dom, batch, pfn_type) ){
   66.27                  ERR("get_pfn_type_batch failed");
   66.28                  goto out;
   66.29              }
    67.1 --- a/tools/libxc/xc_load_aout9.c	Wed Aug 24 16:16:52 2005 -0700
    67.2 +++ b/tools/libxc/xc_load_aout9.c	Thu Aug 25 11:18:47 2005 -0700
    67.3 @@ -1,5 +1,5 @@
    67.4  
    67.5 -#include "xc_private.h"
    67.6 +#include "xg_private.h"
    67.7  #include "xc_aout9.h"
    67.8  
    67.9  #if defined(__i386__)
    68.1 --- a/tools/libxc/xc_load_bin.c	Wed Aug 24 16:16:52 2005 -0700
    68.2 +++ b/tools/libxc/xc_load_bin.c	Thu Aug 25 11:18:47 2005 -0700
    68.3 @@ -66,7 +66,7 @@
    68.4   * Free Software Foundation, Inc.
    68.5   */
    68.6  
    68.7 -#include "xc_private.h"
    68.8 +#include "xg_private.h"
    68.9  #include <stdlib.h>
   68.10  
   68.11  #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
    69.1 --- a/tools/libxc/xc_load_elf.c	Wed Aug 24 16:16:52 2005 -0700
    69.2 +++ b/tools/libxc/xc_load_elf.c	Thu Aug 25 11:18:47 2005 -0700
    69.3 @@ -2,7 +2,7 @@
    69.4   * xc_elf_load.c
    69.5   */
    69.6  
    69.7 -#include "xc_private.h"
    69.8 +#include "xg_private.h"
    69.9  
   69.10  #if defined(__i386__)
   69.11  #define ELFSIZE 32
    70.1 --- a/tools/libxc/xc_private.c	Wed Aug 24 16:16:52 2005 -0700
    70.2 +++ b/tools/libxc/xc_private.c	Thu Aug 25 11:18:47 2005 -0700
    70.3 @@ -64,8 +64,8 @@ void *xc_map_foreign_range(int xc_handle
    70.4  /*******************/
    70.5  
    70.6  /* NB: arr must be mlock'ed */
    70.7 -int get_pfn_type_batch(int xc_handle, 
    70.8 -                       u32 dom, int num, unsigned long *arr)
    70.9 +int xc_get_pfn_type_batch(int xc_handle, 
   70.10 +			  u32 dom, int num, unsigned long *arr)
   70.11  {
   70.12      dom0_op_t op;
   70.13      op.cmd = DOM0_GETPAGEFRAMEINFO2;
   70.14 @@ -92,25 +92,40 @@ unsigned int get_pfn_type(int xc_handle,
   70.15      return op.u.getpageframeinfo.type;
   70.16  }
   70.17  
   70.18 -
   70.19 -
   70.20 -/*******************/
   70.21 -
   70.22 -int pin_table(
   70.23 -    int xc_handle, unsigned int type, unsigned long mfn, domid_t dom)
   70.24 +int xc_mmuext_op(
   70.25 +    int xc_handle,
   70.26 +    struct mmuext_op *op,
   70.27 +    unsigned int nr_ops,
   70.28 +    domid_t dom)
   70.29  {
   70.30 -    struct mmuext_op op;
   70.31 +    privcmd_hypercall_t hypercall;
   70.32 +    long ret = -EINVAL;
   70.33  
   70.34 -    op.cmd = type;
   70.35 -    op.mfn = mfn;
   70.36 +    hypercall.op     = __HYPERVISOR_mmuext_op;
   70.37 +    hypercall.arg[0] = (unsigned long)op;
   70.38 +    hypercall.arg[1] = (unsigned long)nr_ops;
   70.39 +    hypercall.arg[2] = (unsigned long)0;
   70.40 +    hypercall.arg[3] = (unsigned long)dom;
   70.41  
   70.42 -    if ( do_mmuext_op(xc_handle, &op, 1, dom) < 0 )
   70.43 -        return 1;
   70.44 +    if ( mlock(op, nr_ops*sizeof(*op)) != 0 )
   70.45 +    {
   70.46 +        PERROR("Could not lock memory for Xen hypercall");
   70.47 +        goto out1;
   70.48 +    }
   70.49  
   70.50 -    return 0;
   70.51 -}
   70.52 +    if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
   70.53 +    {
   70.54 +	fprintf(stderr, "Dom_mem operation failed (rc=%ld errno=%d)-- need to"
   70.55 +                    " rebuild the user-space tool set?\n",ret,errno);
   70.56 +    }
   70.57  
   70.58 -static int flush_mmu_updates(int xc_handle, mmu_t *mmu)
   70.59 +    safe_munlock(op, nr_ops*sizeof(*op));
   70.60 +
   70.61 + out1:
   70.62 +    return ret;
   70.63 +}    
   70.64 +
   70.65 +static int flush_mmu_updates(int xc_handle, xc_mmu_t *mmu)
   70.66  {
   70.67      int err = 0;
   70.68      privcmd_hypercall_t hypercall;
   70.69 @@ -145,9 +160,9 @@ static int flush_mmu_updates(int xc_hand
   70.70      return err;
   70.71  }
   70.72  
   70.73 -mmu_t *init_mmu_updates(int xc_handle, domid_t dom)
   70.74 +xc_mmu_t *xc_init_mmu_updates(int xc_handle, domid_t dom)
   70.75  {
   70.76 -    mmu_t *mmu = malloc(sizeof(mmu_t));
   70.77 +    xc_mmu_t *mmu = malloc(sizeof(xc_mmu_t));
   70.78      if ( mmu == NULL )
   70.79          return mmu;
   70.80      mmu->idx     = 0;
   70.81 @@ -155,8 +170,8 @@ mmu_t *init_mmu_updates(int xc_handle, d
   70.82      return mmu;
   70.83  }
   70.84  
   70.85 -int add_mmu_update(int xc_handle, mmu_t *mmu, 
   70.86 -                   unsigned long ptr, unsigned long val)
   70.87 +int xc_add_mmu_update(int xc_handle, xc_mmu_t *mmu, 
   70.88 +		      unsigned long ptr, unsigned long val)
   70.89  {
   70.90      mmu->updates[mmu->idx].ptr = ptr;
   70.91      mmu->updates[mmu->idx].val = val;
   70.92 @@ -167,11 +182,48 @@ int add_mmu_update(int xc_handle, mmu_t 
   70.93      return 0;
   70.94  }
   70.95  
   70.96 -int finish_mmu_updates(int xc_handle, mmu_t *mmu)
   70.97 +int xc_finish_mmu_updates(int xc_handle, xc_mmu_t *mmu)
   70.98  {
   70.99      return flush_mmu_updates(xc_handle, mmu);
  70.100  }
  70.101  
  70.102 +int xc_dom_mem_op(int xc_handle,
  70.103 +		  unsigned int memop, 
  70.104 +		  unsigned int *extent_list, 
  70.105 +		  unsigned int nr_extents,
  70.106 +		  unsigned int extent_order,
  70.107 +		  domid_t domid)
  70.108 +{
  70.109 +    privcmd_hypercall_t hypercall;
  70.110 +    long ret = -EINVAL;
  70.111 +
  70.112 +    hypercall.op     = __HYPERVISOR_dom_mem_op;
  70.113 +    hypercall.arg[0] = (unsigned long)memop;
  70.114 +    hypercall.arg[1] = (unsigned long)extent_list;
  70.115 +    hypercall.arg[2] = (unsigned long)nr_extents;
  70.116 +    hypercall.arg[3] = (unsigned long)extent_order;
  70.117 +    hypercall.arg[4] = (unsigned long)domid;
  70.118 +
  70.119 +    if ( (extent_list != NULL) && 
  70.120 +         (mlock(extent_list, nr_extents*sizeof(unsigned long)) != 0) )
  70.121 +    {
  70.122 +        PERROR("Could not lock memory for Xen hypercall");
  70.123 +        goto out1;
  70.124 +    }
  70.125 +
  70.126 +    if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
  70.127 +    {
  70.128 +	fprintf(stderr, "Dom_mem operation failed (rc=%ld errno=%d)-- need to"
  70.129 +                " rebuild the user-space tool set?\n",ret,errno);
  70.130 +    }
  70.131 +
  70.132 +    if ( extent_list != NULL )
  70.133 +        safe_munlock(extent_list, nr_extents*sizeof(unsigned long));
  70.134 +
  70.135 + out1:
  70.136 +    return ret;
  70.137 +}    
  70.138 +
  70.139  
  70.140  long long xc_domain_get_cpu_usage( int xc_handle, domid_t domid, int vcpu )
  70.141  {
  70.142 @@ -190,19 +242,6 @@ long long xc_domain_get_cpu_usage( int x
  70.143  }
  70.144  
  70.145  
  70.146 -/* This is shared between save and restore, and may generally be useful. */
  70.147 -unsigned long csum_page (void * page)
  70.148 -{
  70.149 -    int i;
  70.150 -    unsigned long *p = page;
  70.151 -    unsigned long long sum=0;
  70.152 -
  70.153 -    for ( i = 0; i < (PAGE_SIZE/sizeof(unsigned long)); i++ )
  70.154 -        sum += p[i];
  70.155 -
  70.156 -    return sum ^ (sum>>32);
  70.157 -}
  70.158 -
  70.159  unsigned long xc_get_m2p_start_mfn ( int xc_handle )
  70.160  {
  70.161      unsigned long mfn;
  70.162 @@ -332,53 +371,6 @@ unsigned long xc_get_filesz(int fd)
  70.163      return sz;
  70.164  }
  70.165  
  70.166 -char *xc_read_kernel_image(const char *filename, unsigned long *size)
  70.167 -{
  70.168 -    int kernel_fd = -1;
  70.169 -    gzFile kernel_gfd = NULL;
  70.170 -    char *image = NULL;
  70.171 -    unsigned int bytes;
  70.172 -
  70.173 -    if ( (kernel_fd = open(filename, O_RDONLY)) < 0 )
  70.174 -    {
  70.175 -        PERROR("Could not open kernel image");
  70.176 -        goto out;
  70.177 -    }
  70.178 -
  70.179 -    if ( (*size = xc_get_filesz(kernel_fd)) == 0 )
  70.180 -    {
  70.181 -        PERROR("Could not read kernel image");
  70.182 -        goto out;
  70.183 -    }
  70.184 -
  70.185 -    if ( (kernel_gfd = gzdopen(kernel_fd, "rb")) == NULL )
  70.186 -    {
  70.187 -        PERROR("Could not allocate decompression state for state file");
  70.188 -        goto out;
  70.189 -    }
  70.190 -
  70.191 -    if ( (image = malloc(*size)) == NULL )
  70.192 -    {
  70.193 -        PERROR("Could not allocate memory for kernel image");
  70.194 -        goto out;
  70.195 -    }
  70.196 -
  70.197 -    if ( (bytes = gzread(kernel_gfd, image, *size)) != *size )
  70.198 -    {
  70.199 -        PERROR("Error reading kernel image, could not"
  70.200 -               " read the whole image (%d != %ld).", bytes, *size);
  70.201 -        free(image);
  70.202 -        image = NULL;
  70.203 -    }
  70.204 -
  70.205 - out:
  70.206 -    if ( kernel_gfd != NULL )
  70.207 -        gzclose(kernel_gfd);
  70.208 -    else if ( kernel_fd >= 0 )
  70.209 -        close(kernel_fd);
  70.210 -    return image;
  70.211 -}
  70.212 -
  70.213  void xc_map_memcpy(unsigned long dst, char *src, unsigned long size,
  70.214                     int xch, u32 dom, unsigned long *parray,
  70.215                     unsigned long vstart)
    71.1 --- a/tools/libxc/xc_private.h	Wed Aug 24 16:16:52 2005 -0700
    71.2 +++ b/tools/libxc/xc_private.h	Thu Aug 25 11:18:47 2005 -0700
    71.3 @@ -1,124 +1,26 @@
    71.4  
    71.5 -#ifndef __XC_PRIVATE_H__
    71.6 -#define __XC_PRIVATE_H__
    71.7 +#ifndef XC_PRIVATE_H
    71.8 +#define XC_PRIVATE_H
    71.9  
   71.10  #include <unistd.h>
   71.11  #include <stdio.h>
   71.12  #include <errno.h>
   71.13  #include <fcntl.h>
   71.14 +#include <string.h>
   71.15  #include <sys/mman.h>
   71.16  #include <sys/types.h>
   71.17  #include <sys/stat.h>
   71.18  #include <stdlib.h>
   71.19  #include <sys/ioctl.h>
   71.20 -#include <errno.h>
   71.21 -#include <string.h>
   71.22  
   71.23 -#include "xc.h"
   71.24 +#include "xenctrl.h"
   71.25  
   71.26  #include <xen/linux/privcmd.h>
   71.27  
   71.28 -#define _PAGE_PRESENT   0x001
   71.29 -#define _PAGE_RW        0x002
   71.30 -#define _PAGE_USER      0x004
   71.31 -#define _PAGE_PWT       0x008
   71.32 -#define _PAGE_PCD       0x010
   71.33 -#define _PAGE_ACCESSED  0x020
   71.34 -#define _PAGE_DIRTY     0x040
   71.35 -#define _PAGE_PAT       0x080
   71.36 -#define _PAGE_PSE       0x080
   71.37 -#define _PAGE_GLOBAL    0x100
   71.38 -
   71.39 -#if defined(__i386__)
   71.40 -#define L1_PAGETABLE_SHIFT       12
   71.41 -#define L2_PAGETABLE_SHIFT       22
   71.42 -#define L1_PAGETABLE_SHIFT_PAE   12
   71.43 -#define L2_PAGETABLE_SHIFT_PAE   21
   71.44 -#define L3_PAGETABLE_SHIFT_PAE   30
   71.45 -#elif defined(__x86_64__)
   71.46 -#define L1_PAGETABLE_SHIFT      12
   71.47 -#define L2_PAGETABLE_SHIFT      21
   71.48 -#define L3_PAGETABLE_SHIFT      30
   71.49 -#define L4_PAGETABLE_SHIFT      39
   71.50 -#endif
   71.51 -
   71.52 -#if defined(__i386__) 
   71.53 -#define ENTRIES_PER_L1_PAGETABLE 1024
   71.54 -#define ENTRIES_PER_L2_PAGETABLE 1024
   71.55 -#define L1_PAGETABLE_ENTRIES_PAE  512
   71.56 -#define L2_PAGETABLE_ENTRIES_PAE  512
   71.57 -#define L3_PAGETABLE_ENTRIES_PAE    4
   71.58 -#elif defined(__x86_64__)
   71.59 -#define L1_PAGETABLE_ENTRIES    512
   71.60 -#define L2_PAGETABLE_ENTRIES    512
   71.61 -#define L3_PAGETABLE_ENTRIES    512
   71.62 -#define L4_PAGETABLE_ENTRIES    512
   71.63 -#endif
   71.64 - 
   71.65  #define PAGE_SHIFT              XC_PAGE_SHIFT
   71.66  #define PAGE_SIZE               (1UL << PAGE_SHIFT)
   71.67  #define PAGE_MASK               (~(PAGE_SIZE-1))
   71.68  
   71.69 -typedef u32 l1_pgentry_32_t;
   71.70 -typedef u32 l2_pgentry_32_t;
   71.71 -typedef u64 l1_pgentry_64_t;
   71.72 -typedef u64 l2_pgentry_64_t;
   71.73 -typedef u64 l3_pgentry_64_t;
   71.74 -typedef unsigned long l1_pgentry_t;
   71.75 -typedef unsigned long l2_pgentry_t;
   71.76 -#if defined(__x86_64__)
   71.77 -typedef unsigned long l3_pgentry_t;
   71.78 -typedef unsigned long l4_pgentry_t;
   71.79 -#endif
   71.80 -
   71.81 -#if defined(__i386__)
   71.82 -#define l1_table_offset(_a) \
   71.83 -          (((_a) >> L1_PAGETABLE_SHIFT) & (ENTRIES_PER_L1_PAGETABLE - 1))
   71.84 -#define l2_table_offset(_a) \
   71.85 -          ((_a) >> L2_PAGETABLE_SHIFT)
   71.86 -#define l1_table_offset_pae(_a) \
   71.87 -  (((_a) >> L1_PAGETABLE_SHIFT_PAE) & (L1_PAGETABLE_ENTRIES_PAE - 1))
   71.88 -#define l2_table_offset_pae(_a) \
   71.89 -  (((_a) >> L2_PAGETABLE_SHIFT_PAE) & (L2_PAGETABLE_ENTRIES_PAE - 1))
   71.90 -#define l3_table_offset_pae(_a) \
   71.91 -	(((_a) >> L3_PAGETABLE_SHIFT_PAE) & (L3_PAGETABLE_ENTRIES_PAE - 1))
   71.92 -#elif defined(__x86_64__)
   71.93 -#define l1_table_offset(_a) \
   71.94 -  (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1))
   71.95 -#define l2_table_offset(_a) \
   71.96 -  (((_a) >> L2_PAGETABLE_SHIFT) & (L2_PAGETABLE_ENTRIES - 1))
   71.97 -#define l3_table_offset(_a) \
   71.98 -	(((_a) >> L3_PAGETABLE_SHIFT) & (L3_PAGETABLE_ENTRIES - 1))
   71.99 -#define l4_table_offset(_a) \
  71.100 -	(((_a) >> L4_PAGETABLE_SHIFT) & (L4_PAGETABLE_ENTRIES - 1))
  71.101 -#endif
  71.102 -
  71.103 -struct domain_setup_info
  71.104 -{
  71.105 -    unsigned long v_start;
  71.106 -    unsigned long v_end;
  71.107 -    unsigned long v_kernstart;
  71.108 -    unsigned long v_kernend;
  71.109 -    unsigned long v_kernentry;
  71.110 -
  71.111 -    unsigned int  load_symtab;
  71.112 -    unsigned int  pae_kernel;
  71.113 -    unsigned long symtab_addr;
  71.114 -    unsigned long symtab_len;
  71.115 -};
  71.116 -
  71.117 -typedef int (*parseimagefunc)(char *image, unsigned long image_size,
  71.118 -			      struct domain_setup_info *dsi);
  71.119 -typedef int (*loadimagefunc)(char *image, unsigned long image_size, int xch,
  71.120 -			     u32 dom, unsigned long *parray,
  71.121 -			     struct domain_setup_info *dsi);
  71.122 -
  71.123 -struct load_funcs
  71.124 -{
  71.125 -    parseimagefunc parseimage;
  71.126 -    loadimagefunc loadimage;
  71.127 -};
  71.128 -
  71.129  #define ERROR(_m, _a...)                                \
  71.130  do {                                                    \
  71.131      int __saved_errno = errno;                          \
  71.132 @@ -186,97 +88,6 @@ static inline int do_dom0_op(int xc_hand
  71.133      return ret;
  71.134  }
  71.135  
  71.136 -static inline int do_dom_mem_op(int            xc_handle,
  71.137 -				unsigned int   memop, 
  71.138 -				unsigned int *extent_list, 
  71.139 -				unsigned int  nr_extents,
  71.140 -				unsigned int   extent_order,
  71.141 -				domid_t        domid)
  71.142 -{
  71.143 -    privcmd_hypercall_t hypercall;
  71.144 -    long ret = -EINVAL;
  71.145 -
  71.146 -    hypercall.op     = __HYPERVISOR_dom_mem_op;
  71.147 -    hypercall.arg[0] = (unsigned long)memop;
  71.148 -    hypercall.arg[1] = (unsigned long)extent_list;
  71.149 -    hypercall.arg[2] = (unsigned long)nr_extents;
  71.150 -    hypercall.arg[3] = (unsigned long)extent_order;
  71.151 -    hypercall.arg[4] = (unsigned long)domid;
  71.152 -
  71.153 -    if ( (extent_list != NULL) && 
  71.154 -         (mlock(extent_list, nr_extents*sizeof(unsigned long)) != 0) )
  71.155 -    {
  71.156 -        PERROR("Could not lock memory for Xen hypercall");
  71.157 -        goto out1;
  71.158 -    }
  71.159 -
  71.160 -    if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
  71.161 -    {
  71.162 -	fprintf(stderr, "Dom_mem operation failed (rc=%ld errno=%d)-- need to"
  71.163 -                " rebuild the user-space tool set?\n",ret,errno);
  71.164 -    }
  71.165 -
  71.166 -    if ( extent_list != NULL )
  71.167 -        safe_munlock(extent_list, nr_extents*sizeof(unsigned long));
  71.168 -
  71.169 - out1:
  71.170 -    return ret;
  71.171 -}    
  71.172 -
  71.173 -static inline int do_mmuext_op(
  71.174 -    int xc_handle,
  71.175 -    struct mmuext_op *op,
  71.176 -    unsigned int nr_ops,
  71.177 -    domid_t dom)
  71.178 -{
  71.179 -    privcmd_hypercall_t hypercall;
  71.180 -    long ret = -EINVAL;
  71.181 -
  71.182 -    hypercall.op     = __HYPERVISOR_mmuext_op;
  71.183 -    hypercall.arg[0] = (unsigned long)op;
  71.184 -    hypercall.arg[1] = (unsigned long)nr_ops;
  71.185 -    hypercall.arg[2] = (unsigned long)0;
  71.186 -    hypercall.arg[3] = (unsigned long)dom;
  71.187 -
  71.188 -    if ( mlock(op, nr_ops*sizeof(*op)) != 0 )
  71.189 -    {
  71.190 -        PERROR("Could not lock memory for Xen hypercall");
  71.191 -        goto out1;
  71.192 -    }
  71.193 -
  71.194 -    if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
  71.195 -    {
  71.196 -	fprintf(stderr, "Dom_mem operation failed (rc=%ld errno=%d)-- need to"
  71.197 -                    " rebuild the user-space tool set?\n",ret,errno);
  71.198 -    }
  71.199 -
  71.200 -    safe_munlock(op, nr_ops*sizeof(*op));
  71.201 -
  71.202 - out1:
  71.203 -    return ret;
  71.204 -}    
  71.205 -
  71.206 -
  71.207 -/*
  71.208 - * PFN mapping.
  71.209 - */
  71.210 -int get_pfn_type_batch(int xc_handle, u32 dom, int num, unsigned long *arr);
  71.211 -unsigned long csum_page (void * page);
  71.212 -
  71.213 -/*
  71.214 - * MMU updates.
  71.215 - */
  71.216 -#define MAX_MMU_UPDATES 1024
  71.217 -typedef struct {
  71.218 -    mmu_update_t updates[MAX_MMU_UPDATES];
  71.219 -    int          idx;
  71.220 -    domid_t      subject;
  71.221 -} mmu_t;
  71.222 -mmu_t *init_mmu_updates(int xc_handle, domid_t dom);
  71.223 -int add_mmu_update(int xc_handle, mmu_t *mmu, 
  71.224 -                   unsigned long ptr, unsigned long val);
  71.225 -int finish_mmu_updates(int xc_handle, mmu_t *mmu);
  71.226 -
  71.227  
  71.228  /*
  71.229   * ioctl-based mfn mapping interface
  71.230 @@ -296,38 +107,4 @@ typedef struct privcmd_mmap {
  71.231  } privcmd_mmap_t; 
  71.232  */
  71.233  
  71.234 -#define mfn_mapper_queue_size 128
  71.235 -
  71.236 -typedef struct mfn_mapper {
  71.237 -    int xc_handle;
  71.238 -    int size;
  71.239 -    int prot;
  71.240 -    int error;
  71.241 -    int max_queue_size;
  71.242 -    void * addr;
  71.243 -    privcmd_mmap_t ioctl; 
  71.244 -    
  71.245 -} mfn_mapper_t;
  71.246 -
  71.247 -unsigned long xc_get_m2p_start_mfn (int xc_handle);
  71.248 -
  71.249 -int xc_copy_to_domain_page(int xc_handle, u32 domid,
  71.250 -                            unsigned long dst_pfn, void *src_page);
  71.251 -
  71.252 -unsigned long xc_get_filesz(int fd);
  71.253 -
  71.254 -char *xc_read_kernel_image(const char *filename, unsigned long *size);
  71.255 -
  71.256 -void xc_map_memcpy(unsigned long dst, char *src, unsigned long size,
  71.257 -                   int xch, u32 dom, unsigned long *parray,
  71.258 -                   unsigned long vstart);
  71.259 -
  71.260 -int pin_table(int xc_handle, unsigned int type, unsigned long mfn,
  71.261 -	      domid_t dom);
  71.262 -
  71.263 -/* image loading */
  71.264 -int probe_elf(char *image, unsigned long image_size, struct load_funcs *funcs);
  71.265 -int probe_bin(char *image, unsigned long image_size, struct load_funcs *funcs);
  71.266 -int probe_aout9(char *image, unsigned long image_size, struct load_funcs *funcs);
  71.267 -
  71.268  #endif /* __XC_PRIVATE_H__ */
    72.1 --- a/tools/libxc/xc_vmx_build.c	Wed Aug 24 16:16:52 2005 -0700
    72.2 +++ b/tools/libxc/xc_vmx_build.c	Thu Aug 25 11:18:47 2005 -0700
    72.3 @@ -3,7 +3,7 @@
    72.4   */
    72.5  
    72.6  #include <stddef.h>
    72.7 -#include "xc_private.h"
    72.8 +#include "xg_private.h"
    72.9  #define ELFSIZE 32
   72.10  #include "xc_elf.h"
   72.11  #include <stdlib.h>
   72.12 @@ -243,7 +243,7 @@ static int setup_guest(int xc_handle,
   72.13      shared_info_t *shared_info;
   72.14      struct linux_boot_params * boot_paramsp;
   72.15      __u16 * boot_gdtp;
   72.16 -    mmu_t *mmu = NULL;
   72.17 +    xc_mmu_t *mmu = NULL;
   72.18      int rc;
   72.19  
   72.20      unsigned long nr_pt_pages;
   72.21 @@ -358,7 +358,7 @@ static int setup_guest(int xc_handle,
   72.22          }
   72.23      }
   72.24  
   72.25 -    if ( (mmu = init_mmu_updates(xc_handle, dom)) == NULL )
   72.26 +    if ( (mmu = xc_init_mmu_updates(xc_handle, dom)) == NULL )
   72.27          goto error_out;
   72.28  
   72.29  #ifdef __i386__
   72.30 @@ -459,9 +459,9 @@ static int setup_guest(int xc_handle,
   72.31      /* Write the machine->phys table entries. */
   72.32      for ( count = 0; count < nr_pages; count++ )
   72.33      {
   72.34 -        if ( add_mmu_update(xc_handle, mmu,
   72.35 -                            (page_array[count] << PAGE_SHIFT) | 
   72.36 -                            MMU_MACHPHYS_UPDATE, count) )
   72.37 +        if ( xc_add_mmu_update(xc_handle, mmu,
   72.38 +			       (page_array[count] << PAGE_SHIFT) | 
   72.39 +			       MMU_MACHPHYS_UPDATE, count) )
   72.40  	    goto error_out;
   72.41      }
   72.42      
   72.43 @@ -587,7 +587,7 @@ static int setup_guest(int xc_handle,
   72.44  #endif
   72.45  
   72.46      /* Send the page update requests down to the hypervisor. */
   72.47 -    if ( finish_mmu_updates(xc_handle, mmu) )
   72.48 +    if ( xc_finish_mmu_updates(xc_handle, mmu) )
   72.49          goto error_out;
   72.50  
   72.51      free(mmu);
   72.52 @@ -708,7 +708,7 @@ int xc_vmx_build(int xc_handle,
   72.53  
   72.54      op.cmd = DOM0_GETDOMAININFO;
   72.55      op.u.getdomaininfo.domain = (domid_t)domid;
   72.56 -    if ( (do_dom0_op(xc_handle, &op) < 0) || 
   72.57 +    if ( (xc_dom0_op(xc_handle, &op) < 0) || 
   72.58           ((u16)op.u.getdomaininfo.domain != domid) )
   72.59      {
   72.60          PERROR("Could not get info on domain");
   72.61 @@ -789,7 +789,7 @@ int xc_vmx_build(int xc_handle,
   72.62      launch_op.u.setdomaininfo.ctxt   = ctxt;
   72.63  
   72.64      launch_op.cmd = DOM0_SETDOMAININFO;
   72.65 -    rc = do_dom0_op(xc_handle, &launch_op);
   72.66 +    rc = xc_dom0_op(xc_handle, &launch_op);
   72.67      
   72.68      return rc;
   72.69  
    73.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    73.2 +++ b/tools/libxc/xenctrl.h	Thu Aug 25 11:18:47 2005 -0700
    73.3 @@ -0,0 +1,526 @@
    73.4 +/******************************************************************************
    73.5 + * xenctrl.h
    73.6 + * 
    73.7 + * A library for low-level access to the Xen control interfaces.
    73.8 + * 
    73.9 + * Copyright (c) 2003-2004, K A Fraser.
   73.10 + */
   73.11 +
   73.12 +#ifndef XENCTRL_H
   73.13 +#define XENCTRL_H
   73.14 +
   73.15 +#include <stdint.h>
   73.16 +
   73.17 +typedef uint8_t            u8;
   73.18 +typedef uint16_t           u16;
   73.19 +typedef uint32_t           u32;
   73.20 +typedef uint64_t           u64;
   73.21 +typedef int8_t             s8;
   73.22 +typedef int16_t            s16;
   73.23 +typedef int32_t            s32;
   73.24 +typedef int64_t            s64;
   73.25 +
   73.26 +#include <sys/ptrace.h>
   73.27 +#include <xen/xen.h>
   73.28 +#include <xen/dom0_ops.h>
   73.29 +#include <xen/event_channel.h>
   73.30 +#include <xen/sched_ctl.h>
   73.31 +#include <xen/acm.h>
   73.32 +
   73.33 +#ifdef __ia64__
   73.34 +#define XC_PAGE_SHIFT           14
   73.35 +#else
   73.36 +#define XC_PAGE_SHIFT           12
   73.37 +#endif
   73.38 +#define XC_PAGE_SIZE            (1UL << XC_PAGE_SHIFT)
   73.39 +#define XC_PAGE_MASK            (~(XC_PAGE_SIZE-1))
   73.40 +
   73.41 +/*
   73.42 + *  DEFINITIONS FOR CPU BARRIERS
   73.43 + */ 
   73.44 +
   73.45 +#if defined(__i386__)
   73.46 +#define mb()  __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" )
   73.47 +#define rmb() __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" )
   73.48 +#define wmb() __asm__ __volatile__ ( "" : : : "memory")
   73.49 +#elif defined(__x86_64__)
   73.50 +#define mb()  __asm__ __volatile__ ( "mfence" : : : "memory")
   73.51 +#define rmb() __asm__ __volatile__ ( "lfence" : : : "memory")
   73.52 +#define wmb() __asm__ __volatile__ ( "" : : : "memory")
   73.53 +#elif defined(__ia64__)
   73.54 +/* FIXME */
   73.55 +#define mb()
   73.56 +#define rmb()
   73.57 +#define wmb()
   73.58 +#else
   73.59 +#error "Define barriers"
   73.60 +#endif
   73.61 +
   73.62 +/*
   73.63 + *  INITIALIZATION FUNCTIONS
   73.64 + */ 
   73.65 +
   73.66 +/**
   73.67 + * This function opens a handle to the hypervisor interface.  This function can
   73.68 + * be called multiple times within a single process.  Multiple processes can
   73.69 + * have an open hypervisor interface at the same time.
   73.70 + *
   73.71 + * Each call to this function should have a corresponding call to
   73.72 + * xc_interface_close().
   73.73 + *
   73.74 + * This function can fail if the caller does not have superuser permission or
   73.75 + * if a Xen-enabled kernel is not currently running.
   73.76 + *
   73.77 + * @return a handle to the hypervisor interface or -1 on failure
   73.78 + */
   73.79 +int xc_interface_open(void);
   73.80 +
   73.81 +/**
   73.82 + * This function closes an open hypervisor interface.
   73.83 + *
   73.84 + * This function can fail if the handle does not represent an open interface or
   73.85 + * if there were problems closing the interface.
   73.86 + *
   73.87 + * @parm xc_handle a handle to an open hypervisor interface
   73.88 + * @return 0 on success, -1 otherwise.
   73.89 + */
   73.90 +int xc_interface_close(int xc_handle);
   73.91 +
   73.92 +/*
   73.93 + * DOMAIN DEBUGGING FUNCTIONS
   73.94 + */
   73.95 +
   73.96 +typedef struct xc_core_header {
   73.97 +    unsigned int xch_magic;
   73.98 +    unsigned int xch_nr_vcpus;
   73.99 +    unsigned int xch_nr_pages;
  73.100 +    unsigned int xch_ctxt_offset;
  73.101 +    unsigned int xch_index_offset;
  73.102 +    unsigned int xch_pages_offset;
  73.103 +} xc_core_header_t;
  73.104 +
  73.105 +
  73.106 +long xc_ptrace(enum __ptrace_request request, 
  73.107 +               u32  domid,
  73.108 +               long addr, 
  73.109 +               long data);
  73.110 +
  73.111 +long xc_ptrace_core(enum __ptrace_request request, 
  73.112 +                    u32 domid, 
  73.113 +                    long addr, 
  73.114 +                    long data);
  73.115 +
  73.116 +int xc_waitdomain(int domain, 
  73.117 +                  int *status, 
  73.118 +                  int options);
  73.119 +
  73.120 +int xc_waitdomain_core(int domain, 
  73.121 +                       int *status, 
  73.122 +                       int options);
  73.123 +
  73.124 +/*
  73.125 + * DOMAIN MANAGEMENT FUNCTIONS
  73.126 + */
  73.127 +
  73.128 +typedef struct {
  73.129 +    u32           domid;
  73.130 +    u32           ssidref;
  73.131 +    unsigned int  dying:1, crashed:1, shutdown:1, 
  73.132 +                  paused:1, blocked:1, running:1;
  73.133 +    unsigned int  shutdown_reason; /* only meaningful if shutdown==1 */
  73.134 +    unsigned long nr_pages;
  73.135 +    unsigned long shared_info_frame;
  73.136 +    u64           cpu_time;
  73.137 +    unsigned long max_memkb;
  73.138 +    unsigned int  vcpus;
  73.139 +    s32           vcpu_to_cpu[MAX_VIRT_CPUS];
  73.140 +    cpumap_t      cpumap[MAX_VIRT_CPUS];
  73.141 +} xc_dominfo_t;
  73.142 +
  73.143 +typedef dom0_getdomaininfo_t xc_domaininfo_t;
  73.144 +int xc_domain_create(int xc_handle, 
  73.145 +                     u32 ssidref,
  73.146 +                     u32 *pdomid);
  73.147 +
  73.148 +
  73.149 +int xc_domain_dumpcore(int xc_handle, 
  73.150 +                       u32 domid,
  73.151 +                       const char *corename);
  73.152 +
  73.153 +
  73.154 +/**
  73.155 + * This function pauses a domain. A paused domain still exists in memory
  73.156 + * however it does not receive any timeslices from the hypervisor.
  73.157 + *
  73.158 + * @parm xc_handle a handle to an open hypervisor interface
  73.159 + * @parm domid the domain id to pause
  73.160 + * @return 0 on success, -1 on failure.
  73.161 + */
  73.162 +int xc_domain_pause(int xc_handle, 
  73.163 +                    u32 domid);
  73.164 +/**
  73.165 + * This function unpauses a domain.  The domain should have been previously
  73.166 + * paused.
  73.167 + *
  73.168 + * @parm xc_handle a handle to an open hypervisor interface
  73.169 + * @parm domid the domain id to unpause
  73.170 + * return 0 on success, -1 on failure
  73.171 + */
  73.172 +int xc_domain_unpause(int xc_handle, 
  73.173 +                      u32 domid);
  73.174 +
  73.175 +/**
  73.176 + * This function will destroy a domain.  Destroying a domain removes the domain
  73.177 + * completely from memory.  This function should be called after sending the
  73.178 + * domain a SHUTDOWN control message to free up the domain resources.
  73.179 + *
  73.180 + * @parm xc_handle a handle to an open hypervisor interface
  73.181 + * @parm domid the domain id to destroy
  73.182 + * @return 0 on success, -1 on failure
  73.183 + */
  73.184 +int xc_domain_destroy(int xc_handle, 
  73.185 +                      u32 domid);
  73.186 +int xc_domain_pincpu(int xc_handle,
  73.187 +                     u32 domid,
  73.188 +                     int vcpu,
  73.189 +                     cpumap_t *cpumap);
  73.190 +/**
  73.191 + * This function will return information about one or more domains. It is
  73.192 + * designed to iterate over the list of domains. If a single domain is
  73.193 + * requested, this function will return the next domain in the list - if
  73.194 + * one exists. It is, therefore, important in this case to make sure the
  73.195 + * domain requested was the one returned.
  73.196 + *
  73.197 + * @parm xc_handle a handle to an open hypervisor interface
  73.198 + * @parm first_domid the first domain to enumerate information from.  Domains
  73.199 + *                   are currently enumerate in order of creation.
  73.200 + * @parm max_doms the number of elements in info
  73.201 + * @parm info an array of max_doms size that will contain the information for
  73.202 + *            the enumerated domains.
  73.203 + * @return the number of domains enumerated or -1 on error
  73.204 + */
  73.205 +int xc_domain_getinfo(int xc_handle,
  73.206 +                      u32 first_domid, 
  73.207 +                      unsigned int max_doms,
  73.208 +                      xc_dominfo_t *info);
  73.209 +
  73.210 +/**
  73.211 + * This function will return information about one or more domains, using a
  73.212 + * single hypercall.  The domain information will be stored into the supplied
  73.213 + * array of xc_domaininfo_t structures.
  73.214 + *
  73.215 + * @parm xc_handle a handle to an open hypervisor interface
  73.216 + * @parm first_domain the first domain to enumerate information from.
  73.217 + *                    Domains are currently enumerate in order of creation.
  73.218 + * @parm max_domains the number of elements in info
  73.219 + * @parm info an array of max_doms size that will contain the information for
  73.220 + *            the enumerated domains.
  73.221 + * @return the number of domains enumerated or -1 on error
  73.222 + */
  73.223 +int xc_domain_getinfolist(int xc_handle,
  73.224 +                          u32 first_domain,
  73.225 +                          unsigned int max_domains,
  73.226 +                          xc_domaininfo_t *info);
  73.227 +
  73.228 +/**
  73.229 + * This function returns information about one domain.  This information is
  73.230 + * more detailed than the information from xc_domain_getinfo().
  73.231 + *
  73.232 + * @parm xc_handle a handle to an open hypervisor interface
  73.233 + * @parm domid the domain to get information from
  73.234 + * @parm info a pointer to an xc_domaininfo_t to store the domain information
  73.235 + * @parm ctxt a pointer to a structure to store the execution context of the
  73.236 + *            domain
  73.237 + * @return 0 on success, -1 on failure
  73.238 + */
  73.239 +int xc_domain_get_vcpu_context(int xc_handle,
  73.240 +                               u32 domid,
  73.241 +                               u32 vcpu,
  73.242 +                               vcpu_guest_context_t *ctxt);
  73.243 +
  73.244 +int xc_domain_setcpuweight(int xc_handle,
  73.245 +                           u32 domid,
  73.246 +                           float weight);
  73.247 +long long xc_domain_get_cpu_usage(int xc_handle,
  73.248 +                                  domid_t domid,
  73.249 +                                  int vcpu);
  73.250 +
  73.251 +
  73.252 +typedef dom0_shadow_control_stats_t xc_shadow_control_stats_t;
  73.253 +int xc_shadow_control(int xc_handle,
  73.254 +                      u32 domid, 
  73.255 +                      unsigned int sop,
  73.256 +                      unsigned long *dirty_bitmap,
  73.257 +                      unsigned long pages,
  73.258 +                      xc_shadow_control_stats_t *stats);
  73.259 +
  73.260 +int xc_bvtsched_global_set(int xc_handle,
  73.261 +                           unsigned long ctx_allow);
  73.262 +
  73.263 +int xc_bvtsched_domain_set(int xc_handle,
  73.264 +                           u32 domid,
  73.265 +                           u32 mcuadv,
  73.266 +                           int warpback,
  73.267 +                           s32 warpvalue,
  73.268 +                           long long warpl,
  73.269 +                           long long warpu);
  73.270 +
  73.271 +int xc_bvtsched_global_get(int xc_handle,
  73.272 +                           unsigned long *ctx_allow);
  73.273 +
  73.274 +int xc_bvtsched_domain_get(int xc_handle,
  73.275 +                           u32 domid,
  73.276 +                           u32 *mcuadv,
  73.277 +                           int *warpback,
  73.278 +                           s32 *warpvalue,
  73.279 +                           long long *warpl,
  73.280 +                           long long *warpu);
  73.281 +
  73.282 +int xc_sedf_domain_set(int xc_handle,
  73.283 +                          u32 domid,
  73.284 +                          u64 period, u64 slice, u64 latency, u16 extratime, u16 weight);
  73.285 +
  73.286 +int xc_sedf_domain_get(int xc_handle,
  73.287 +                          u32 domid,
  73.288 +                          u64* period, u64 *slice, u64 *latency, u16 *extratime, u16* weight);
  73.289 +
  73.290 +typedef evtchn_status_t xc_evtchn_status_t;
  73.291 +
  73.292 +/*
  73.293 + * EVENT CHANNEL FUNCTIONS
  73.294 + */
  73.295 +
  73.296 +/**
  73.297 + * This function allocates an unbound port.  Ports are named endpoints used for
  73.298 + * interdomain communication.  This function is most useful in opening a
  73.299 + * well-known port within a domain to receive events on.
  73.300 + *
  73.301 + * @parm xc_handle a handle to an open hypervisor interface
  73.302 + * @parm dom the ID of the domain.  This maybe DOMID_SELF
  73.303 + * @parm port a pointer to a port.  This is an in/out parameter.  If *port is
  73.304 + *            0, then a new port will be assigned, if port is > 0 then that
  73.305 + *            port is allocated if the port is unallocated.
  73.306 + * @return 0 on success, -1 on failure
  73.307 + */
  73.308 +int xc_evtchn_alloc_unbound(int xc_handle,
  73.309 +                            u32 dom,
  73.310 +                            int *port);
  73.311 +
  73.312 +/**
  73.313 + * This function creates a pair of ports between two domains.  A port can only
  73.314 + * be bound once within a domain.
  73.315 + *
  73.316 + * @parm xc_handle a handle to an open hypervisor interface
  73.317 + * @parm dom1 one of the two domains to connect.  Can be DOMID_SELF.
  73.318 + * @parm dom2 the other domain to connect.  Can be DOMID_SELF.
  73.319 + * @parm port1 an in/out parameter.  If > 0, then try to connect *port.  If
  73.320 + *             0, then allocate a new port and store the port in *port.
  73.321 + * @parm port2 the port connected on port2.  This parameter behaves the same
  73.322 + *             way as port1.
  73.323 + * @return 0 on success, -1 on error.
  73.324 + */
  73.325 +int xc_evtchn_bind_interdomain(int xc_handle,
  73.326 +                               u32 dom1,
  73.327 +                               u32 dom2,
  73.328 +                               int *port1,
  73.329 +                               int *port2);
  73.330 +int xc_evtchn_bind_virq(int xc_handle,
  73.331 +                        int virq,
  73.332 +                        int *port);
  73.333 +
  73.334 +/**
  73.335 + * This function will close a single port on an event channel.
  73.336 + *
  73.337 + * @parm xc_handle a handle to an open hypervisor interface
  73.338 + * @parm dom the domain that the port exists on.  May be DOMID_SELF.
  73.339 + * @parm port the port to close
  73.340 + * @return 0 on success, -1 on error
  73.341 + */
  73.342 +int xc_evtchn_close(int xc_handle,
  73.343 +                    u32 dom,   /* may be DOMID_SELF */
  73.344 +                    int port);
  73.345 +
  73.346 +/**
  73.347 + * This function generates a notify event on a bound port.
  73.348 + *
  73.349 + * Notifies can be read within Linux by opening /dev/xen/evtchn and reading
  73.350 + * a 16 bit value.  The result will be the port the event occurred on.  When
  73.351 + * events occur, the port is masked until the 16 bit port value is written back
  73.352 + * to the file.  When /dev/xen/evtchn is opened, it has to be bound via an
  73.353 + * ioctl to each port to listen on.  The ioctl for binding is _IO('E', 2).  The
  73.354 + * parameter is the port to listen on.
  73.355 + *
  73.356 + * @parm xc_handle a handle to an open hypervisor interface
  73.357 + * @parm local_port the port to generate the notify on
  73.358 + * @return 0 on success, -1 on error
  73.359 + */
  73.360 +int xc_evtchn_send(int xc_handle,
  73.361 +                   int local_port);
  73.362 +int xc_evtchn_status(int xc_handle,
  73.363 +                     u32 dom, /* may be DOMID_SELF */
  73.364 +                     int port,
  73.365 +                     xc_evtchn_status_t *status);
  73.366 +
  73.367 +int xc_physdev_pci_access_modify(int xc_handle,
  73.368 +                                 u32 domid,
  73.369 +                                 int bus,
  73.370 +                                 int dev,
  73.371 +                                 int func,
  73.372 +                                 int enable);
  73.373 +
  73.374 +int xc_readconsolering(int xc_handle,
  73.375 +                       char **pbuffer,
  73.376 +                       unsigned int *pnr_chars, 
  73.377 +                       int clear);
  73.378 +
  73.379 +typedef dom0_physinfo_t xc_physinfo_t;
  73.380 +int xc_physinfo(int xc_handle,
  73.381 +                xc_physinfo_t *info);
  73.382 +
  73.383 +int xc_sched_id(int xc_handle,
  73.384 +                int *sched_id);
  73.385 +
  73.386 +int xc_domain_setmaxmem(int xc_handle,
  73.387 +                        u32 domid, 
  73.388 +                        unsigned int max_memkb);
  73.389 +
  73.390 +int xc_domain_memory_increase_reservation(int xc_handle,
  73.391 +                                          u32 domid, 
  73.392 +                                          unsigned int mem_kb);
  73.393 +
  73.394 +typedef dom0_perfc_desc_t xc_perfc_desc_t;
  73.395 +/* IMPORTANT: The caller is responsible for mlock()'ing the @desc array. */
  73.396 +int xc_perfc_control(int xc_handle,
  73.397 +                     u32 op,
  73.398 +                     xc_perfc_desc_t *desc);
  73.399 +
  73.400 +/* read/write msr */
  73.401 +long long xc_msr_read(int xc_handle, int cpu_mask, int msr);
  73.402 +int xc_msr_write(int xc_handle, int cpu_mask, int msr, unsigned int low,
  73.403 +                  unsigned int high);
  73.404 +
  73.405 +/**
  73.406 + * Memory maps a range within one domain to a local address range.  Mappings
  73.407 + * should be unmapped with munmap and should follow the same rules as mmap
  73.408 + * regarding page alignment.  Returns NULL on failure.
  73.409 + *
  73.410 + * In Linux, the ring queue for the control channel is accessible by mapping
  73.411 + * the shared_info_frame (from xc_domain_getinfo()) + 2048.  The structure
  73.412 + * stored there is of type control_if_t.
  73.413 + *
  73.414 + * @parm xc_handle a handle on an open hypervisor interface
  73.415 + * @parm dom the domain to map memory from
  73.416 + * @parm size the amount of memory to map (in multiples of page size)
  73.417 + * @parm prot same flag as in mmap().
  73.418 + * @parm mfn the frame address to map.
  73.419 + */
  73.420 +void *xc_map_foreign_range(int xc_handle, u32 dom,
  73.421 +                            int size, int prot,
  73.422 +                            unsigned long mfn );
  73.423 +
  73.424 +void *xc_map_foreign_batch(int xc_handle, u32 dom, int prot,
  73.425 +                           unsigned long *arr, int num );
  73.426 +
  73.427 +int xc_get_pfn_list(int xc_handle, u32 domid, unsigned long *pfn_buf, 
  73.428 +                    unsigned long max_pfns);
  73.429 +
  73.430 +int xc_ia64_get_pfn_list(int xc_handle, u32 domid, unsigned long *pfn_buf, 
  73.431 +                    unsigned int start_page, unsigned int nr_pages);
  73.432 +
  73.433 +int xc_mmuext_op(int xc_handle, struct mmuext_op *op, unsigned int nr_ops,
  73.434 +		 domid_t dom);
  73.435 +
  73.436 +int xc_dom_mem_op(int xc_handle, unsigned int memop, unsigned int *extent_list,
  73.437 +		  unsigned int nr_extents, unsigned int extent_order,
  73.438 +		  domid_t domid);
  73.439 +
  73.440 +int xc_get_pfn_type_batch(int xc_handle, u32 dom, int num, unsigned long *arr);
  73.441 +
  73.442 +
  73.443 +/*\
  73.444 + *  GRANT TABLE FUNCTIONS
  73.445 +\*/ 
  73.446 +
  73.447 +/**
  73.448 + * This function opens a handle to the more restricted grant table hypervisor
  73.449 + * interface. This may be used where the standard interface is not
  73.450 + * available because the domain is not privileged.
  73.451 + * This function can  be called multiple times within a single process.
  73.452 + * Multiple processes can have an open hypervisor interface at the same time.
  73.453 + *
  73.454 + * Each call to this function should have a corresponding call to
  73.455 + * xc_grant_interface_close().
  73.456 + *
  73.457 + * This function can fail if a Xen-enabled kernel is not currently running.
  73.458 + *
  73.459 + * @return a handle to the hypervisor grant table interface or -1 on failure
  73.460 + */
  73.461 +int xc_grant_interface_open(void);
  73.462 +
  73.463 +/**
  73.464 + * This function closes an open grant table hypervisor interface.
  73.465 + *
  73.466 + * This function can fail if the handle does not represent an open interface or
  73.467 + * if there were problems closing the interface.
  73.468 + *
  73.469 + * @parm xc_handle a handle to an open grant table hypervisor interface
  73.470 + * @return 0 on success, -1 otherwise.
  73.471 + */
  73.472 +int xc_grant_interface_close(int xc_handle);
  73.473 +
  73.474 +int xc_gnttab_map_grant_ref(int  xc_handle,
  73.475 +                            u64  host_virt_addr,
  73.476 +                            u32  dom,
  73.477 +                            u16  ref,
  73.478 +                            u16  flags,
  73.479 +                            s16 *handle,
  73.480 +                            u64 *dev_bus_addr);
  73.481 +
  73.482 +int xc_gnttab_unmap_grant_ref(int  xc_handle,
  73.483 +                              u64  host_virt_addr,
  73.484 +                              u64  dev_bus_addr,
  73.485 +                              u16  handle,
  73.486 +                              s16 *status);
  73.487 +
  73.488 +int xc_gnttab_setup_table(int        xc_handle,
  73.489 +                          u32        dom,
  73.490 +                          u16        nr_frames,
  73.491 +                          s16       *status,
  73.492 +                          unsigned long **frame_list);
  73.493 +
  73.494 +/* Grant debug builds only: */
  73.495 +int xc_gnttab_dump_table(int        xc_handle,
  73.496 +                         u32        dom,
  73.497 +                         s16       *status);
  73.498 +
  73.499 +/* Get current total pages allocated to a domain. */
  73.500 +long xc_get_tot_pages(int xc_handle, u32 domid);
  73.501 +
  73.502 +/* Execute a privileged dom0 operation. */
  73.503 +int xc_dom0_op(int xc_handle, dom0_op_t *op);
  73.504 +
  73.505 +/* Initializes the store (for dom0)
  73.506 +   remote_port should be the remote end of a bound interdomain channel between
  73.507 +   the store and dom0.
  73.508 +
  73.509 +   This function returns a shared frame that should be passed to
  73.510 +   xs_introduce_domain
  73.511 + */
  73.512 +long xc_init_store(int xc_handle, int remote_port);
  73.513 +
  73.514 +/*
  73.515 + * MMU updates.
  73.516 + */
  73.517 +#define MAX_MMU_UPDATES 1024
  73.518 +struct xc_mmu {
  73.519 +    mmu_update_t updates[MAX_MMU_UPDATES];
  73.520 +    int          idx;
  73.521 +    domid_t      subject;
  73.522 +};
  73.523 +typedef struct xc_mmu xc_mmu_t;
  73.524 +xc_mmu_t *xc_init_mmu_updates(int xc_handle, domid_t dom);
  73.525 +int xc_add_mmu_update(int xc_handle, xc_mmu_t *mmu, 
  73.526 +                   unsigned long ptr, unsigned long val);
  73.527 +int xc_finish_mmu_updates(int xc_handle, xc_mmu_t *mmu);
  73.528 +
  73.529 +#endif
    74.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    74.2 +++ b/tools/libxc/xenguest.h	Thu Aug 25 11:18:47 2005 -0700
    74.3 @@ -0,0 +1,66 @@
    74.4 +/******************************************************************************
    74.5 + * xenguest.h
    74.6 + * 
    74.7 + * A library for guest domain management in Xen.
    74.8 + * 
    74.9 + * Copyright (c) 2003-2004, K A Fraser.
   74.10 + */
   74.11 +
   74.12 +#ifndef XENBUILD_H
   74.13 +#define XENBUILD_H
   74.14 +
   74.15 +#define XCFLAGS_VERBOSE   1
   74.16 +#define XCFLAGS_LIVE      2
   74.17 +#define XCFLAGS_DEBUG     4
   74.18 +#define XCFLAGS_CONFIGURE 8
   74.19 +
   74.20 +/**
   74.21 + * This function will save a domain running Linux.
   74.22 + *
   74.23 + * @parm xc_handle a handle to an open hypervisor interface
   74.24 + * @parm fd the file descriptor to save a domain to
   74.25 + * @parm dom the id of the domain
   74.26 + * @return 0 on success, -1 on failure
   74.27 + */
   74.28 +int xc_linux_save(int xc_handle, int fd, uint32_t dom);
   74.29 +
   74.30 +/**
   74.31 + * This function will restore a saved domain running Linux.
   74.32 + *
   74.33 + * @parm xc_handle a handle to an open hypervisor interface
   74.34 + * @parm fd the file descriptor to restore a domain from
   74.35 + * @parm dom the id of the domain
   74.36 + * @parm nr_pfns the number of pages
   74.37 + * @parm store_evtchn the store event channel for this domain to use
   74.38 + * @parm store_mfn returned with the mfn of the store page
   74.39 + * @return 0 on success, -1 on failure
   74.40 + */
   74.41 +int xc_linux_restore(int xc_handle, int io_fd, uint32_t dom, unsigned long nr_pfns,
   74.42 +		     unsigned int store_evtchn, unsigned long *store_mfn);
   74.43 +
   74.44 +int xc_linux_build(int xc_handle,
   74.45 +                   uint32_t domid,
   74.46 +                   const char *image_name,
   74.47 +                   const char *ramdisk_name,
   74.48 +                   const char *cmdline,
   74.49 +                   unsigned int control_evtchn,
   74.50 +                   unsigned long flags,
   74.51 +                   unsigned int vcpus,
   74.52 +                   unsigned int store_evtchn,
   74.53 +                   unsigned long *store_mfn);
   74.54 +
   74.55 +struct mem_map;
   74.56 +int xc_vmx_build(int xc_handle,
   74.57 +                 uint32_t domid,
   74.58 +                 int memsize,
   74.59 +                 const char *image_name,
   74.60 +                 struct mem_map *memmap,
   74.61 +                 const char *ramdisk_name,
   74.62 +                 const char *cmdline,
   74.63 +                 unsigned int control_evtchn,
   74.64 +                 unsigned long flags,
   74.65 +                 unsigned int vcpus,
   74.66 +                 unsigned int store_evtchn,
   74.67 +                 unsigned long *store_mfn);
   74.68 +
   74.69 +#endif
    75.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    75.2 +++ b/tools/libxc/xg_private.c	Thu Aug 25 11:18:47 2005 -0700
    75.3 @@ -0,0 +1,86 @@
    75.4 +/******************************************************************************
    75.5 + * xg_private.c
    75.6 + * 
    75.7 + * Helper functions for the rest of the library.
    75.8 + */
    75.9 +
   75.10 +#include <stdlib.h>
   75.11 +#include <zlib.h>
   75.12 +
   75.13 +#include "xg_private.h"
   75.14 +
   75.15 +char *xc_read_kernel_image(const char *filename, unsigned long *size)
   75.16 +{
   75.17 +    int kernel_fd = -1;
   75.18 +    gzFile kernel_gfd = NULL;
   75.19 +    char *image = NULL;
   75.20 +    unsigned int bytes;
   75.21 +
   75.22 +    if ( (kernel_fd = open(filename, O_RDONLY)) < 0 )
   75.23 +    {
   75.24 +        PERROR("Could not open kernel image");
   75.25 +        goto out;
   75.26 +    }
   75.27 +
   75.28 +    if ( (*size = xc_get_filesz(kernel_fd)) == 0 )
   75.29 +    {
   75.30 +        PERROR("Could not read kernel image");
   75.31 +        goto out;
   75.32 +    }
   75.33 +
   75.34 +    if ( (kernel_gfd = gzdopen(kernel_fd, "rb")) == NULL )
   75.35 +    {
   75.36 +        PERROR("Could not allocate decompression state for state file");
   75.37 +        goto out;
   75.38 +    }
   75.39 +
   75.40 +    if ( (image = malloc(*size)) == NULL )
   75.41 +    {
   75.42 +        PERROR("Could not allocate memory for kernel image");
   75.43 +        goto out;
   75.44 +    }
   75.45 +
   75.46 +    if ( (bytes = gzread(kernel_gfd, image, *size)) != *size )
   75.47 +    {
   75.48 +        PERROR("Error reading kernel image, could not"
   75.49 +               " read the whole image (%d != %ld).", bytes, *size);
   75.50 +        free(image);
   75.51 +        image = NULL;
   75.52 +    }
   75.53 +
   75.54 + out:
   75.55 +    if ( kernel_gfd != NULL )
   75.56 +        gzclose(kernel_gfd);
   75.57 +    else if ( kernel_fd >= 0 )
   75.58 +        close(kernel_fd);
   75.59 +    return image;
   75.60 +}
   75.61 +
   75.62 +/*******************/
   75.63 +
   75.64 +int pin_table(
   75.65 +    int xc_handle, unsigned int type, unsigned long mfn, domid_t dom)
   75.66 +{
   75.67 +    struct mmuext_op op;
   75.68 +
   75.69 +    op.cmd = type;
   75.70 +    op.mfn = mfn;
   75.71 +
   75.72 +    if ( xc_mmuext_op(xc_handle, &op, 1, dom) < 0 )
   75.73 +        return 1;
   75.74 +
   75.75 +    return 0;
   75.76 +}
   75.77 +
   75.78 +/* This is shared between save and restore, and may generally be useful. */
   75.79 +unsigned long csum_page (void * page)
   75.80 +{
   75.81 +    int i;
   75.82 +    unsigned long *p = page;
   75.83 +    unsigned long long sum=0;
   75.84 +
   75.85 +    for ( i = 0; i < (PAGE_SIZE/sizeof(unsigned long)); i++ )
   75.86 +        sum += p[i];
   75.87 +
   75.88 +    return sum ^ (sum>>32);
   75.89 +}
    76.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    76.2 +++ b/tools/libxc/xg_private.h	Thu Aug 25 11:18:47 2005 -0700
    76.3 @@ -0,0 +1,170 @@
    76.4 +#ifndef XG_PRIVATE_H
    76.5 +#define XG_PRIVATE_H
    76.6 +
    76.7 +#include <errno.h>
    76.8 +#include <fcntl.h>
    76.9 +#include <stdio.h>
   76.10 +#include <string.h>
   76.11 +#include <sys/mman.h>
   76.12 +#include <sys/types.h>
   76.13 +#include <sys/stat.h>
   76.14 +
   76.15 +#include "xenctrl.h"
   76.16 +
   76.17 +#include <xen/linux/privcmd.h>
   76.18 +
   76.19 +char *xc_read_kernel_image(const char *filename, unsigned long *size);
   76.20 +unsigned long csum_page (void * page);
   76.21 +
   76.22 +#define _PAGE_PRESENT   0x001
   76.23 +#define _PAGE_RW        0x002
   76.24 +#define _PAGE_USER      0x004
   76.25 +#define _PAGE_PWT       0x008
   76.26 +#define _PAGE_PCD       0x010
   76.27 +#define _PAGE_ACCESSED  0x020
   76.28 +#define _PAGE_DIRTY     0x040
   76.29 +#define _PAGE_PAT       0x080
   76.30 +#define _PAGE_PSE       0x080
   76.31 +#define _PAGE_GLOBAL    0x100
   76.32 +
   76.33 +#if defined(__i386__)
   76.34 +#define L1_PAGETABLE_SHIFT       12
   76.35 +#define L2_PAGETABLE_SHIFT       22
   76.36 +#define L1_PAGETABLE_SHIFT_PAE   12
   76.37 +#define L2_PAGETABLE_SHIFT_PAE   21
   76.38 +#define L3_PAGETABLE_SHIFT_PAE   30
   76.39 +#elif defined(__x86_64__)
   76.40 +#define L1_PAGETABLE_SHIFT      12
   76.41 +#define L2_PAGETABLE_SHIFT      21
   76.42 +#define L3_PAGETABLE_SHIFT      30
   76.43 +#define L4_PAGETABLE_SHIFT      39
   76.44 +#endif
   76.45 +
   76.46 +#if defined(__i386__) 
   76.47 +#define ENTRIES_PER_L1_PAGETABLE 1024
   76.48 +#define ENTRIES_PER_L2_PAGETABLE 1024
   76.49 +#define L1_PAGETABLE_ENTRIES_PAE  512
   76.50 +#define L2_PAGETABLE_ENTRIES_PAE  512
   76.51 +#define L3_PAGETABLE_ENTRIES_PAE    4
   76.52 +#elif defined(__x86_64__)
   76.53 +#define L1_PAGETABLE_ENTRIES    512
   76.54 +#define L2_PAGETABLE_ENTRIES    512
   76.55 +#define L3_PAGETABLE_ENTRIES    512
   76.56 +#define L4_PAGETABLE_ENTRIES    512
   76.57 +#endif
   76.58 + 
   76.59 +#define PAGE_SHIFT              XC_PAGE_SHIFT
   76.60 +#define PAGE_SIZE               (1UL << PAGE_SHIFT)
   76.61 +#define PAGE_MASK               (~(PAGE_SIZE-1))
   76.62 +
   76.63 +typedef u32 l1_pgentry_32_t;
   76.64 +typedef u32 l2_pgentry_32_t;
   76.65 +typedef u64 l1_pgentry_64_t;
   76.66 +typedef u64 l2_pgentry_64_t;
   76.67 +typedef u64 l3_pgentry_64_t;
   76.68 +typedef unsigned long l1_pgentry_t;
   76.69 +typedef unsigned long l2_pgentry_t;
   76.70 +#if defined(__x86_64__)
   76.71 +typedef unsigned long l3_pgentry_t;
   76.72 +typedef unsigned long l4_pgentry_t;
   76.73 +#endif
   76.74 +
   76.75 +#if defined(__i386__)
   76.76 +#define l1_table_offset(_a) \
   76.77 +          (((_a) >> L1_PAGETABLE_SHIFT) & (ENTRIES_PER_L1_PAGETABLE - 1))
   76.78 +#define l2_table_offset(_a) \
   76.79 +          ((_a) >> L2_PAGETABLE_SHIFT)
   76.80 +#define l1_table_offset_pae(_a) \
   76.81 +  (((_a) >> L1_PAGETABLE_SHIFT_PAE) & (L1_PAGETABLE_ENTRIES_PAE - 1))
   76.82 +#define l2_table_offset_pae(_a) \
   76.83 +  (((_a) >> L2_PAGETABLE_SHIFT_PAE) & (L2_PAGETABLE_ENTRIES_PAE - 1))
   76.84 +#define l3_table_offset_pae(_a) \
   76.85 +	(((_a) >> L3_PAGETABLE_SHIFT_PAE) & (L3_PAGETABLE_ENTRIES_PAE - 1))
   76.86 +#elif defined(__x86_64__)
   76.87 +#define l1_table_offset(_a) \
   76.88 +  (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1))
   76.89 +#define l2_table_offset(_a) \
   76.90 +  (((_a) >> L2_PAGETABLE_SHIFT) & (L2_PAGETABLE_ENTRIES - 1))
   76.91 +#define l3_table_offset(_a) \
   76.92 +	(((_a) >> L3_PAGETABLE_SHIFT) & (L3_PAGETABLE_ENTRIES - 1))
   76.93 +#define l4_table_offset(_a) \
   76.94 +	(((_a) >> L4_PAGETABLE_SHIFT) & (L4_PAGETABLE_ENTRIES - 1))
   76.95 +#endif
   76.96 +
   76.97 +#define ERROR(_m, _a...)                                \
   76.98 +do {                                                    \
   76.99 +    int __saved_errno = errno;                          \
  76.100 +    fprintf(stderr, "ERROR: " _m "\n" , ## _a );        \
  76.101 +    errno = __saved_errno;                              \
  76.102 +} while (0)
  76.103 +
  76.104 +
  76.105 +#define PERROR(_m, _a...)                                       \
  76.106 +do {                                                            \
  76.107 +    int __saved_errno = errno;                                  \
  76.108 +    fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a ,       \
  76.109 +            __saved_errno, strerror(__saved_errno));            \
  76.110 +    errno = __saved_errno;                                      \
  76.111 +} while (0)
  76.112 +
  76.113 +
  76.114 +struct domain_setup_info
  76.115 +{
  76.116 +    unsigned long v_start;
  76.117 +    unsigned long v_end;
  76.118 +    unsigned long v_kernstart;
  76.119 +    unsigned long v_kernend;
  76.120 +    unsigned long v_kernentry;
  76.121 +
  76.122 +    unsigned int  load_symtab;
  76.123 +    unsigned int  pae_kernel;
  76.124 +    unsigned long symtab_addr;
  76.125 +    unsigned long symtab_len;
  76.126 +};
  76.127 +
  76.128 +typedef int (*parseimagefunc)(char *image, unsigned long image_size,
  76.129 +			      struct domain_setup_info *dsi);
  76.130 +typedef int (*loadimagefunc)(char *image, unsigned long image_size, int xch,
  76.131 +			     u32 dom, unsigned long *parray,
  76.132 +			     struct domain_setup_info *dsi);
  76.133 +
  76.134 +struct load_funcs
  76.135 +{
  76.136 +    parseimagefunc parseimage;
  76.137 +    loadimagefunc loadimage;
  76.138 +};
  76.139 +
  76.140 +#define mfn_mapper_queue_size 128
  76.141 +
  76.142 +typedef struct mfn_mapper {
  76.143 +    int xc_handle;
  76.144 +    int size;
  76.145 +    int prot;
  76.146 +    int error;
  76.147 +    int max_queue_size;
  76.148 +    void * addr;
  76.149 +    privcmd_mmap_t ioctl; 
  76.150 +    
  76.151 +} mfn_mapper_t;
  76.152 +
  76.153 +unsigned long xc_get_m2p_start_mfn (int xc_handle);
  76.154 +
  76.155 +int xc_copy_to_domain_page(int xc_handle, u32 domid,
  76.156 +                            unsigned long dst_pfn, void *src_page);
  76.157 +
  76.158 +unsigned long xc_get_filesz(int fd);
  76.159 +
  76.160 +void xc_map_memcpy(unsigned long dst, char *src, unsigned long size,
  76.161 +                   int xch, u32 dom, unsigned long *parray,
  76.162 +                   unsigned long vstart);
  76.163 +
  76.164 +int pin_table(int xc_handle, unsigned int type, unsigned long mfn,
  76.165 +	      domid_t dom);
  76.166 +
  76.167 +/* image loading */
  76.168 +int probe_elf(char *image, unsigned long image_size, struct load_funcs *funcs);
  76.169 +int probe_bin(char *image, unsigned long image_size, struct load_funcs *funcs);
  76.170 +int probe_aout9(char *image, unsigned long image_size, struct load_funcs *funcs);
  76.171 +
  76.172 +#endif
  76.173 +
    77.1 --- a/tools/misc/Makefile	Wed Aug 24 16:16:52 2005 -0700
    77.2 +++ b/tools/misc/Makefile	Thu Aug 25 11:18:47 2005 -0700
    77.3 @@ -50,4 +50,4 @@ clean:
    77.4  	$(CC) -c $(CFLAGS) -o $@ $<
    77.5  
    77.6  $(TARGETS): %: %.o Makefile
    77.7 -	$(CC) $(CFLAGS) -o $@ $< -L$(XEN_LIBXC) -lxc
    77.8 +	$(CC) $(CFLAGS) -o $@ $< -L$(XEN_LIBXC) -lxenctrl
    78.1 --- a/tools/misc/cpuperf/Makefile	Wed Aug 24 16:16:52 2005 -0700
    78.2 +++ b/tools/misc/cpuperf/Makefile	Thu Aug 25 11:18:47 2005 -0700
    78.3 @@ -37,7 +37,7 @@ clean:
    78.4  	$(CC) $(CFLAGS) -o $@ $<
    78.5  
    78.6  cpuperf-xen: cpuperf.c $(HDRS) Makefile
    78.7 -	$(CC) $(CFLAGS) -I $(XEN_LIBXC) -L$(XEN_LIBXC) -lxc -DXENO -o $@ $<
    78.8 +	$(CC) $(CFLAGS) -I $(XEN_LIBXC) -L$(XEN_LIBXC) -lxenctrl -DXENO -o $@ $<
    78.9  
   78.10  cpuperf-perfcntr: cpuperf.c $(HDRS) Makefile
   78.11  	$(CC) $(CFLAGS) -DPERFCNTR -o $@ $<
    79.1 --- a/tools/misc/cpuperf/cpuperf_xeno.h	Wed Aug 24 16:16:52 2005 -0700
    79.2 +++ b/tools/misc/cpuperf/cpuperf_xeno.h	Thu Aug 25 11:18:47 2005 -0700
    79.3 @@ -9,7 +9,7 @@
    79.4   *
    79.5   */
    79.6  
    79.7 -#include <xc.h>
    79.8 +#include <xenctrl.h>
    79.9  
   79.10  static int xc_handle;
   79.11  
    80.1 --- a/tools/misc/xc_shadow.c	Wed Aug 24 16:16:52 2005 -0700
    80.2 +++ b/tools/misc/xc_shadow.c	Thu Aug 25 11:18:47 2005 -0700
    80.3 @@ -11,7 +11,7 @@
    80.4   */
    80.5  
    80.6  
    80.7 -#include <xc.h>
    80.8 +#include <xenctrl.h>
    80.9  #include <stdio.h>
   80.10  #include <stdlib.h>
   80.11  #include <sys/mman.h>
    81.1 --- a/tools/misc/xenperf.c	Wed Aug 24 16:16:52 2005 -0700
    81.2 +++ b/tools/misc/xenperf.c	Thu Aug 25 11:18:47 2005 -0700
    81.3 @@ -11,7 +11,7 @@
    81.4   */
    81.5  
    81.6  
    81.7 -#include <xc.h>
    81.8 +#include <xenctrl.h>
    81.9  #include <stdio.h>
   81.10  #include <stdlib.h>
   81.11  #include <sys/mman.h>
    82.1 --- a/tools/python/setup.py	Wed Aug 24 16:16:52 2005 -0700
    82.2 +++ b/tools/python/setup.py	Thu Aug 25 11:18:47 2005 -0700
    82.3 @@ -17,7 +17,7 @@ library_dirs = [ XEN_ROOT + "/tools/libx
    82.4                   XEN_ROOT + "/tools/xenstore",
    82.5                   ]
    82.6  
    82.7 -libraries = [ "xc", "xenstore-pic" ]
    82.8 +libraries = [ "xenctrl", "xenguest", "xenstore" ]
    82.9  
   82.10  xc = Extension("xc",
   82.11                 extra_compile_args = extra_compile_args,
   82.12 @@ -41,7 +41,7 @@ xs = Extension("xs",
   82.13                 sources            = [ "xen/lowlevel/xs/xs.c" ])
   82.14  
   82.15  setup(name            = 'xen',
   82.16 -      version         = '2.0',
   82.17 +      version         = '3.0',
   82.18        description     = 'Xen',
   82.19        packages        = ['xen',
   82.20                           'xen.lowlevel',
    83.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Wed Aug 24 16:16:52 2005 -0700
    83.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Thu Aug 25 11:18:47 2005 -0700
    83.3 @@ -5,7 +5,8 @@
    83.4   */
    83.5  
    83.6  #include <Python.h>
    83.7 -#include <xc.h>
    83.8 +#include <xenctrl.h>
    83.9 +#include <xenguest.h>
   83.10  #include <zlib.h>
   83.11  #include <fcntl.h>
   83.12  #include <netinet/in.h>
    84.1 --- a/tools/python/xen/lowlevel/xu/xu.c	Wed Aug 24 16:16:52 2005 -0700
    84.2 +++ b/tools/python/xen/lowlevel/xu/xu.c	Thu Aug 25 11:18:47 2005 -0700
    84.3 @@ -21,7 +21,7 @@
    84.4  #include <unistd.h>
    84.5  #include <errno.h>
    84.6  #include <signal.h>
    84.7 -#include <xc.h>
    84.8 +#include <xenctrl.h>
    84.9  
   84.10  #include <xen/xen.h>
   84.11  #include <xen/io/domain_controller.h>
    85.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Wed Aug 24 16:16:52 2005 -0700
    85.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Aug 25 11:18:47 2005 -0700
    85.3 @@ -265,6 +265,8 @@ class XendDomainInfo:
    85.4          self.info = None
    85.5          self.blkif_backend = False
    85.6          self.netif_backend = False
    85.7 +        self.netif_idx = 0
    85.8 +        
    85.9          #todo: state: running, suspended
   85.10          self.state = STATE_VM_OK
   85.11          self.state_updated = threading.Condition()
   85.12 @@ -400,8 +402,7 @@ class XendDomainInfo:
   85.13              db['virtual-device'] = "%i" % devnum
   85.14              #db['backend'] = sxp.child_value(devconfig, 'backend', '0')
   85.15              db['backend'] = backdb.getPath()
   85.16 -            db['backend-id'] = "%i" % int(sxp.child_value(devconfig,
   85.17 -                                                          'backend', '0'))
   85.18 +            db['backend-id'] = "%i" % backdom.id
   85.19  
   85.20              backdb['frontend'] = db.getPath()
   85.21              (type, params) = string.split(sxp.child_value(devconfig, 'uname'), ':', 1)
   85.22 @@ -417,6 +418,37 @@ class XendDomainInfo:
   85.23              db.saveDB(save=True)
   85.24              
   85.25              return
   85.26 +
   85.27 +        if type == 'vif':
   85.28 +            backdom = domain_exists(sxp.child_value(devconfig, 'backend', '0'))
   85.29 +
   85.30 +            log.error(devconfig)
   85.31 +            
   85.32 +            devnum = self.netif_idx
   85.33 +            self.netif_idx += 1
   85.34 +
   85.35 +            # create backend db
   85.36 +            backdb = backdom.db.addChild("/backend/%s/%s/%d" %
   85.37 +                                         (type, self.uuid, devnum))
   85.38 +
   85.39 +            # create frontend db
   85.40 +            db = self.db.addChild("/device/%s/%d" % (type, devnum))
   85.41 +            
   85.42 +            backdb['frontend'] = db.getPath()
   85.43 +            backdb['frontend-id'] = "%i" % self.id
   85.44 +            backdb['handle'] = "%i" % devnum
   85.45 +            backdb.saveDB(save=True)
   85.46 +
   85.47 +            db['backend'] = backdb.getPath()
   85.48 +            db['backend-id'] = "%i" % backdom.id
   85.49 +            db['handle'] = "%i" % devnum
   85.50 +            log.error(sxp.child_value(devconfig, 'mac'))
   85.51 +            db['mac'] = sxp.child_value(devconfig, 'mac')
   85.52 +
   85.53 +            db.saveDB(save=True)
   85.54 +
   85.55 +            return
   85.56 +        
   85.57          ctrl = self.findDeviceController(type)
   85.58          return ctrl.createDevice(devconfig, recreate=self.recreate,
   85.59                                   change=change)
   85.60 @@ -718,6 +750,11 @@ class XendDomainInfo:
   85.61                                   devdb['node'].getData())
   85.62                      typedb[dev].delete()
   85.63                  typedb.saveDB(save=True)
   85.64 +            if type == 'vif':
   85.65 +                typedb = ddb.addChild(type)
   85.66 +                for dev in typedb.keys():
   85.67 +                    typedb[dev].delete()
   85.68 +                typedb.saveDB(save=True)
   85.69  
   85.70      def show(self):
   85.71          """Print virtual machine info.
    86.1 --- a/tools/python/xen/xm/main.py	Wed Aug 24 16:16:52 2005 -0700
    86.2 +++ b/tools/python/xen/xm/main.py	Thu Aug 25 11:18:47 2005 -0700
    86.3 @@ -665,8 +665,10 @@ def main(argv=sys.argv):
    86.4              err("Most commands need root access.  Please try again as root")
    86.5              sys.exit(1)
    86.6          except XendError, ex:
    86.7 +            if args[0] == "bogus":
    86.8 +                args.remove("bogus")
    86.9              if len(args) > 0:
   86.10 -                handle_xend_error(argv[1], args[1], ex)
   86.11 +                handle_xend_error(argv[1], args[0], ex)
   86.12              else:
   86.13                  print "Unexpected error:", sys.exc_info()[0]
   86.14                  print
    87.1 --- a/tools/xcs/Makefile	Wed Aug 24 16:16:52 2005 -0700
    87.2 +++ b/tools/xcs/Makefile	Thu Aug 25 11:18:47 2005 -0700
    87.3 @@ -34,10 +34,10 @@ clean:
    87.4  
    87.5  xcsdump: xcsdump.c dump.c
    87.6  	$(CC) $(CFLAGS) -o xcsdump xcsdump.c -L$(XEN_LIBXC) \
    87.7 -              ctrl_interface.c evtchn.c dump.c -lxc
    87.8 +              ctrl_interface.c evtchn.c dump.c -lxenctrl
    87.9  
   87.10  $(BIN): $(OBJS)
   87.11 -	$(CC) $(CFLAGS) $^ -o $@ -L$(XEN_LIBXC) -lxc 
   87.12 +	$(CC) $(CFLAGS) $^ -o $@ -L$(XEN_LIBXC) -lxenctrl 
   87.13  
   87.14  $(OBJS): $(HDRS)
   87.15  
    88.1 --- a/tools/xcs/dump.h	Wed Aug 24 16:16:52 2005 -0700
    88.2 +++ b/tools/xcs/dump.h	Thu Aug 25 11:18:47 2005 -0700
    88.3 @@ -20,7 +20,7 @@
    88.4  #define XENCTLD_ERROR_H
    88.5  
    88.6  #include <stdint.h>
    88.7 -#include <xc.h>
    88.8 +#include <xenctrl.h>
    88.9  #include <xen/io/domain_controller.h>
   88.10  
   88.11  void dump_msg(const control_msg_t *msg, uint64_t flags);
    89.1 --- a/tools/xcs/xcs.h	Wed Aug 24 16:16:52 2005 -0700
    89.2 +++ b/tools/xcs/xcs.h	Thu Aug 25 11:18:47 2005 -0700
    89.3 @@ -11,7 +11,7 @@
    89.4  #define __XCS_H__
    89.5  
    89.6  #include <pthread.h>
    89.7 -#include <xc.h>
    89.8 +#include <xenctrl.h>
    89.9  #include <xen/xen.h>
   89.10  #include <xen/io/domain_controller.h>
   89.11  #include <xen/linux/privcmd.h>
    90.1 --- a/tools/xcs/xcsdump.c	Wed Aug 24 16:16:52 2005 -0700
    90.2 +++ b/tools/xcs/xcsdump.c	Thu Aug 25 11:18:47 2005 -0700
    90.3 @@ -16,7 +16,7 @@
    90.4  #include <sys/socket.h>
    90.5  #include <sys/un.h>
    90.6  #include <ctype.h>
    90.7 -#include <xc.h>
    90.8 +#include <xenctrl.h>
    90.9  #include <xen/xen.h>
   90.10  #include <xen/io/domain_controller.h>
   90.11  #include <getopt.h>
    91.1 --- a/tools/xcutils/Makefile	Wed Aug 24 16:16:52 2005 -0700
    91.2 +++ b/tools/xcutils/Makefile	Thu Aug 25 11:18:47 2005 -0700
    91.3 @@ -30,7 +30,7 @@ PROG_DEP = .*.d
    91.4  
    91.5  PROGRAMS		= xc_restore xc_save
    91.6  
    91.7 -LDLIBS			= -L$(XEN_LIBXC) -lxc
    91.8 +LDLIBS			= -L$(XEN_LIBXC) -lxenguest -lxenctrl
    91.9  
   91.10  .PHONY: all
   91.11  all: build
    92.1 --- a/tools/xcutils/xc_restore.c	Wed Aug 24 16:16:52 2005 -0700
    92.2 +++ b/tools/xcutils/xc_restore.c	Thu Aug 25 11:18:47 2005 -0700
    92.3 @@ -7,11 +7,12 @@
    92.4   *
    92.5   */
    92.6  
    92.7 +#include <err.h>
    92.8  #include <stdlib.h>
    92.9 +#include <stdint.h>
   92.10  #include <stdio.h>
   92.11 -#include <err.h>
   92.12  
   92.13 -#include <xc.h>
   92.14 +#include <xenguest.h>
   92.15  
   92.16  int
   92.17  main(int argc, char **argv)
    93.1 --- a/tools/xcutils/xc_save.c	Wed Aug 24 16:16:52 2005 -0700
    93.2 +++ b/tools/xcutils/xc_save.c	Thu Aug 25 11:18:47 2005 -0700
    93.3 @@ -7,11 +7,12 @@
    93.4   *
    93.5   */
    93.6  
    93.7 +#include <err.h>
    93.8  #include <stdlib.h>
    93.9 +#include <stdint.h>
   93.10  #include <stdio.h>
   93.11 -#include <err.h>
   93.12  
   93.13 -#include <xc.h>
   93.14 +#include <xenguest.h>
   93.15  
   93.16  int
   93.17  main(int argc, char **argv)
    94.1 --- a/tools/xenstore/Makefile	Wed Aug 24 16:16:52 2005 -0700
    94.2 +++ b/tools/xenstore/Makefile	Thu Aug 25 11:18:47 2005 -0700
    94.3 @@ -32,7 +32,7 @@ xen:
    94.4  	ln -sf $(XEN_ROOT)/xen/include/public $@
    94.5  
    94.6  xenstored: xenstored_core.o xenstored_watch.o xenstored_domain.o xenstored_transaction.o xs_lib.o talloc.o utils.o
    94.7 -	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -lxc -o $@
    94.8 +	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -lxenctrl -o $@
    94.9  
   94.10  xenstored_test: xenstored_core_test.o xenstored_watch_test.o xenstored_domain_test.o xenstored_transaction_test.o xs_lib.o talloc_test.o fake_libxc.o utils.o
   94.11  	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
   94.12 @@ -109,7 +109,7 @@ stresstest: xs_stress xenstored_test
   94.13  	export $(TESTENV); PID=`./xenstored_test --output-pid --trace-file=/tmp/trace`; ./xs_stress 5000; ret=$$?; kill $$PID; exit $$ret
   94.14  
   94.15  xs_dom0_test: xs_dom0_test.o utils.o
   94.16 -	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -lxc -o $@
   94.17 +	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -lxenctrl -o $@
   94.18  
   94.19  TAGS:
   94.20  	etags `find . -name '*.[ch]'`
    95.1 --- a/tools/xenstore/xs_dom0_test.c	Wed Aug 24 16:16:52 2005 -0700
    95.2 +++ b/tools/xenstore/xs_dom0_test.c	Thu Aug 25 11:18:47 2005 -0700
    95.3 @@ -3,7 +3,7 @@
    95.4  #include <sys/ioctl.h>
    95.5  #include "xs.h"
    95.6  #include "utils.h"
    95.7 -#include <xc.h>
    95.8 +#include <xenctrl.h>
    95.9  #include <xen/linux/privcmd.h>
   95.10  #include <stdio.h>
   95.11  #include <unistd.h>
    96.1 --- a/tools/xenstore/xs_lib.h	Wed Aug 24 16:16:52 2005 -0700
    96.2 +++ b/tools/xenstore/xs_lib.h	Thu Aug 25 11:18:47 2005 -0700
    96.3 @@ -22,7 +22,7 @@
    96.4  
    96.5  #include <stdbool.h>
    96.6  #include <limits.h>
    96.7 -#include <xc.h>
    96.8 +#include <xenctrl.h>
    96.9  
   96.10  /* Bitmask of permissions. */
   96.11  enum xs_perm_type {
    97.1 --- a/tools/xentrace/Makefile	Wed Aug 24 16:16:52 2005 -0700
    97.2 +++ b/tools/xentrace/Makefile	Thu Aug 25 11:18:47 2005 -0700
    97.3 @@ -36,4 +36,4 @@ clean:
    97.4  	$(RM) *.a *.so *.o *.rpm $(BIN)
    97.5  
    97.6  %: %.c $(HDRS) Makefile
    97.7 -	$(CC) $(CFLAGS) -o $@ $< -L$(XEN_LIBXC) -lxc
    97.8 +	$(CC) $(CFLAGS) -o $@ $< -L$(XEN_LIBXC) -lxenctrl
    98.1 --- a/tools/xentrace/xenctx.c	Wed Aug 24 16:16:52 2005 -0700
    98.2 +++ b/tools/xentrace/xenctx.c	Thu Aug 25 11:18:47 2005 -0700
    98.3 @@ -21,7 +21,7 @@
    98.4  #include <argp.h>
    98.5  #include <signal.h>
    98.6  
    98.7 -#include "xc.h"
    98.8 +#include "xenctrl.h"
    98.9  
   98.10  #ifdef __i386__
   98.11  void print_ctx(vcpu_guest_context_t *ctx1)
    99.1 --- a/xen/arch/x86/x86_32/mm.c	Wed Aug 24 16:16:52 2005 -0700
    99.2 +++ b/xen/arch/x86/x86_32/mm.c	Thu Aug 25 11:18:47 2005 -0700
    99.3 @@ -93,15 +93,10 @@ void __init paging_init(void)
    99.4  
    99.5      /*
    99.6       * Allocate and map the machine-to-phys table and create read-only mapping 
    99.7 -     * of MPT for guest-OS use.  Without PAE we'll end up with one 4MB page, 
    99.8 -     * with PAE we'll allocate 2MB pages depending on the amount of memory 
    99.9 -     * installed, but at least 4MB to cover 4GB address space.  This is needed 
   99.10 -     * to make PCI I/O memory address lookups work in guests.
   99.11 +     * of MPT for guest-OS use.
   99.12       */
   99.13      mpt_size  = (max_page * 4) + (1UL << L2_PAGETABLE_SHIFT) - 1UL;
   99.14      mpt_size &= ~((1UL << L2_PAGETABLE_SHIFT) - 1UL);
   99.15 -    if ( mpt_size < (4 << 20) )
   99.16 -        mpt_size = 4 << 20;
   99.17      for ( i = 0; i < (mpt_size >> L2_PAGETABLE_SHIFT); i++ )
   99.18      {
   99.19          if ( (pg = alloc_domheap_pages(NULL, PAGETABLE_ORDER, 0)) == NULL )
   100.1 --- a/xen/arch/x86/x86_64/mm.c	Wed Aug 24 16:16:52 2005 -0700
   100.2 +++ b/xen/arch/x86/x86_64/mm.c	Thu Aug 25 11:18:47 2005 -0700
   100.3 @@ -74,7 +74,7 @@ l2_pgentry_t *virt_to_xen_l2e(unsigned l
   100.4  
   100.5  void __init paging_init(void)
   100.6  {
   100.7 -    unsigned long i;
   100.8 +    unsigned long i, mpt_size;
   100.9      l3_pgentry_t *l3_ro_mpt;
  100.10      l2_pgentry_t *l2_ro_mpt;
  100.11      struct pfn_info *pg;
  100.12 @@ -98,16 +98,17 @@ void __init paging_init(void)
  100.13       * Allocate and map the machine-to-phys table.
  100.14       * This also ensures L3 is present for fixmaps.
  100.15       */
  100.16 -    for ( i = 0; i < max_page; i += ((1UL << L2_PAGETABLE_SHIFT) / 8) )
  100.17 +    mpt_size  = (max_page * 4) + (1UL << L2_PAGETABLE_SHIFT) - 1UL;
  100.18 +    mpt_size &= ~((1UL << L2_PAGETABLE_SHIFT) - 1UL);
  100.19 +    for ( i = 0; i < (mpt_size >> L2_PAGETABLE_SHIFT); i++ )
  100.20      {
  100.21 -        pg = alloc_domheap_pages(NULL, PAGETABLE_ORDER, 0);
  100.22 -        if ( pg == NULL )
  100.23 +        if ( (pg = alloc_domheap_pages(NULL, PAGETABLE_ORDER, 0)) == NULL )
  100.24              panic("Not enough memory for m2p table\n");
  100.25          map_pages_to_xen(
  100.26 -            RDWR_MPT_VIRT_START + i*8, page_to_pfn(pg), 
  100.27 +            RDWR_MPT_VIRT_START + (i << L2_PAGETABLE_SHIFT), page_to_pfn(pg), 
  100.28              1UL << PAGETABLE_ORDER,
  100.29              PAGE_HYPERVISOR);
  100.30 -        memset((void *)(RDWR_MPT_VIRT_START + i*8), 0x55,
  100.31 +        memset((void *)(RDWR_MPT_VIRT_START + (i << L2_PAGETABLE_SHIFT)), 0x55,
  100.32                 1UL << L2_PAGETABLE_SHIFT);
  100.33          *l2_ro_mpt++ = l2e_from_page(
  100.34              pg, _PAGE_GLOBAL|_PAGE_PSE|_PAGE_USER|_PAGE_PRESENT);