Date: Fri, 5 Dec 2008 15:00:59 +0000 (UTC) From: Doug Rabson <dfr@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r185637 - in user/dfr/xenhvm/6/sys: amd64/include/xen dev/xen/blkfront dev/xen/console dev/xen/netfront dev/xen/xenpci i386/conf i386/i386 i386/include i386/include/xen i386/isa i386/xe... Message-ID: <200812051500.mB5F0xsJ057455@svn.freebsd.org>
index | next in thread | raw e-mail
Author: dfr Date: Fri Dec 5 15:00:59 2008 New Revision: 185637 URL: http://svn.freebsd.org/changeset/base/185637 Log: Major cleaning up and refactoring, including but not limited to: * Move MI Xen headers from <machine/xen/foo.h> to <xen/foo.h> * Try to cut down the amount of times one include cross-includes another * Remove all the linux compatibiity macros in favour of an unobfuscated native FreeBSD style. * Don't multiplex error and result values using negative errno return values. * On FreeBSD, malloc(..., M_WAITOK) doesn't return NULL - simplify accordingly. Added: user/dfr/xenhvm/6/sys/xen/evtchn.h (contents, props changed) - copied, changed from r185387, user/dfr/xenhvm/6/sys/i386/include/xen/evtchn.h user/dfr/xenhvm/6/sys/xen/features.h (props changed) - copied unchanged from r185387, user/dfr/xenhvm/6/sys/i386/include/xen/features.h user/dfr/xenhvm/6/sys/xen/hypervisor.h (contents, props changed) - copied, changed from r185387, user/dfr/xenhvm/6/sys/amd64/include/xen/hypervisor.h user/dfr/xenhvm/6/sys/xen/xen_intr.h (contents, props changed) - copied, changed from r185387, user/dfr/xenhvm/6/sys/i386/include/xen/xen_intr.h Deleted: user/dfr/xenhvm/6/sys/amd64/include/xen/evtchn.h user/dfr/xenhvm/6/sys/amd64/include/xen/features.h user/dfr/xenhvm/6/sys/amd64/include/xen/hypervisor.h user/dfr/xenhvm/6/sys/amd64/include/xen/xen_intr.h user/dfr/xenhvm/6/sys/amd64/include/xen/xenstored.h user/dfr/xenhvm/6/sys/i386/include/xen/evtchn.h user/dfr/xenhvm/6/sys/i386/include/xen/features.h user/dfr/xenhvm/6/sys/i386/include/xen/hypervisor.h user/dfr/xenhvm/6/sys/i386/include/xen/xen_intr.h user/dfr/xenhvm/6/sys/i386/include/xen/xenstored.h Modified: user/dfr/xenhvm/6/sys/amd64/include/xen/hypercall.h user/dfr/xenhvm/6/sys/amd64/include/xen/xen-os.h user/dfr/xenhvm/6/sys/amd64/include/xen/xenfunc.h user/dfr/xenhvm/6/sys/amd64/include/xen/xenpmap.h user/dfr/xenhvm/6/sys/amd64/include/xen/xenvar.h user/dfr/xenhvm/6/sys/dev/xen/blkfront/blkfront.c user/dfr/xenhvm/6/sys/dev/xen/console/console.c user/dfr/xenhvm/6/sys/dev/xen/console/xencons_ring.c user/dfr/xenhvm/6/sys/dev/xen/netfront/netfront.c user/dfr/xenhvm/6/sys/dev/xen/xenpci/evtchn.c user/dfr/xenhvm/6/sys/dev/xen/xenpci/xenpci.c user/dfr/xenhvm/6/sys/i386/conf/XEN user/dfr/xenhvm/6/sys/i386/i386/genassym.c user/dfr/xenhvm/6/sys/i386/i386/machdep.c user/dfr/xenhvm/6/sys/i386/i386/sys_machdep.c user/dfr/xenhvm/6/sys/i386/i386/vm_machdep.c user/dfr/xenhvm/6/sys/i386/include/pcpu.h user/dfr/xenhvm/6/sys/i386/include/xen/hypercall.h user/dfr/xenhvm/6/sys/i386/include/xen/xen-os.h user/dfr/xenhvm/6/sys/i386/include/xen/xenfunc.h user/dfr/xenhvm/6/sys/i386/include/xen/xenpmap.h user/dfr/xenhvm/6/sys/i386/include/xen/xenvar.h user/dfr/xenhvm/6/sys/i386/isa/npx.c user/dfr/xenhvm/6/sys/i386/xen/clock.c user/dfr/xenhvm/6/sys/i386/xen/mp_machdep.c user/dfr/xenhvm/6/sys/i386/xen/mptable.c user/dfr/xenhvm/6/sys/i386/xen/pmap.c user/dfr/xenhvm/6/sys/i386/xen/xen_bus.c user/dfr/xenhvm/6/sys/i386/xen/xen_machdep.c user/dfr/xenhvm/6/sys/xen/evtchn/evtchn.c user/dfr/xenhvm/6/sys/xen/evtchn/evtchn_dev.c user/dfr/xenhvm/6/sys/xen/features.c user/dfr/xenhvm/6/sys/xen/gnttab.c user/dfr/xenhvm/6/sys/xen/gnttab.h user/dfr/xenhvm/6/sys/xen/reboot.c user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_client.c user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_comms.c user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_comms.h user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_dev.c user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_probe.c user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_probe_backend.c user/dfr/xenhvm/6/sys/xen/xenbus/xenbus_xs.c user/dfr/xenhvm/6/sys/xen/xenbus/xenbusvar.h Modified: user/dfr/xenhvm/6/sys/amd64/include/xen/hypercall.h ============================================================================== --- user/dfr/xenhvm/6/sys/amd64/include/xen/hypercall.h Fri Dec 5 14:37:14 2008 (r185636) +++ user/dfr/xenhvm/6/sys/amd64/include/xen/hypercall.h Fri Dec 5 15:00:59 2008 (r185637) @@ -34,12 +34,12 @@ * IN THE SOFTWARE. */ -#ifndef __HYPERCALL_H__ -#define __HYPERCALL_H__ +#ifndef __MACHINE_XEN_HYPERCALL_H__ +#define __MACHINE_XEN_HYPERCALL_H__ #include <sys/systm.h> -#ifndef __HYPERVISOR_H__ +#ifndef __XEN_HYPERVISOR_H__ # error "please don't include this file directly" #endif @@ -412,4 +412,4 @@ HYPERVISOR_kexec_op( #undef __must_check -#endif /* __HYPERCALL_H__ */ +#endif /* __MACHINE_XEN_HYPERCALL_H__ */ Modified: user/dfr/xenhvm/6/sys/amd64/include/xen/xen-os.h ============================================================================== --- user/dfr/xenhvm/6/sys/amd64/include/xen/xen-os.h Fri Dec 5 14:37:14 2008 (r185636) +++ user/dfr/xenhvm/6/sys/amd64/include/xen/xen-os.h Fri Dec 5 15:00:59 2008 (r185637) @@ -6,7 +6,7 @@ #ifndef _XEN_OS_H_ #define _XEN_OS_H_ -#include <machine/param.h> + #ifdef PAE #define CONFIG_X86_PAE #endif @@ -24,43 +24,10 @@ /* Force a proper event-channel callback from Xen. */ void force_evtchn_callback(void); -#ifndef vtophys -#include <vm/vm.h> -#include <vm/vm_param.h> -#include <vm/pmap.h> -#endif - extern int gdtset; -#ifdef SMP -#include <sys/time.h> /* XXX for pcpu.h */ -#include <sys/pcpu.h> /* XXX for PCPU_GET */ -static inline int -smp_processor_id(void) -{ - if (__predict_true(gdtset)) - return PCPU_GET(cpuid); - return 0; -} - -#else -#define smp_processor_id() 0 -#endif - -#ifndef NULL -#define NULL (void *)0 -#endif - -#ifndef PANIC_IF -#define PANIC_IF(exp) if (unlikely(exp)) {panic("%s: %s:%d", #exp, __FILE__, __LINE__);} -#endif extern shared_info_t *HYPERVISOR_shared_info; -/* Somewhere in the middle of the GCC 2.96 development cycle, we implemented - a mechanism by which the user can annotate likely branch directions and - expect the blocks to be reordered appropriately. Define __builtin_expect - to nothing for earlier compilers. */ - /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */ static inline void rep_nop(void) { @@ -68,13 +35,6 @@ static inline void rep_nop(void) } #define cpu_relax() rep_nop() - -#if __GNUC__ == 2 && __GNUC_MINOR__ < 96 -#define __builtin_expect(x, expected_value) (x) -#endif - -#define per_cpu(var, cpu) (pcpu_find((cpu))->pc_ ## var) - /* crude memory allocator for memory allocation early in * boot */ @@ -84,7 +44,6 @@ void bootmem_free(void *ptr, unsigned in /* Everything below this point is not included by assembler (.S) files. */ #ifndef __ASSEMBLY__ -#include <sys/types.h> void printk(const char *fmt, ...); @@ -106,7 +65,7 @@ void trap_init(void); #define __cli() \ do { \ vcpu_info_t *_vcpu; \ - _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \ + _vcpu = &HYPERVISOR_shared_info->vcpu_info[PCPU_GET(cpuid)]; \ _vcpu->evtchn_upcall_mask = 1; \ barrier(); \ } while (0) @@ -115,7 +74,7 @@ do { do { \ vcpu_info_t *_vcpu; \ barrier(); \ - _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \ + _vcpu = &HYPERVISOR_shared_info->vcpu_info[PCPU_GET(cpuid)]; \ _vcpu->evtchn_upcall_mask = 0; \ barrier(); /* unmask then check (avoid races) */ \ if ( unlikely(_vcpu->evtchn_upcall_pending) ) \ @@ -126,7 +85,7 @@ do { do { \ vcpu_info_t *_vcpu; \ barrier(); \ - _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \ + _vcpu = &HYPERVISOR_shared_info->vcpu_info[PCPU_GET(cpuid)]; \ if ((_vcpu->evtchn_upcall_mask = (x)) == 0) { \ barrier(); /* unmask then check (avoid races) */ \ if ( unlikely(_vcpu->evtchn_upcall_pending) ) \ @@ -141,7 +100,7 @@ do { #define __save_and_cli(x) \ do { \ vcpu_info_t *_vcpu; \ - _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \ + _vcpu = &HYPERVISOR_shared_info->vcpu_info[PCPU_GET(cpuid)]; \ (x) = _vcpu->evtchn_upcall_mask; \ _vcpu->evtchn_upcall_mask = 1; \ barrier(); \ @@ -332,33 +291,6 @@ static __inline__ void atomic_inc(atomic #define rdtscll(val) \ __asm__ __volatile__("rdtsc" : "=A" (val)) - - -/* - * Kernel pointers have redundant information, so we can use a - * scheme where we can return either an error code or a dentry - * pointer with the same return value. - * - * This should be a per-architecture thing, to allow different - * error and pointer decisions. - */ -#define IS_ERR_VALUE(x) unlikely((x) > (unsigned long)-1000L) - -static inline void *ERR_PTR(long error) -{ - return (void *) error; -} - -static inline long PTR_ERR(const void *ptr) -{ - return (long) ptr; -} - -static inline long IS_ERR(const void *ptr) -{ - return IS_ERR_VALUE((unsigned long)ptr); -} - #endif /* !__ASSEMBLY__ */ #endif /* _OS_H_ */ Modified: user/dfr/xenhvm/6/sys/amd64/include/xen/xenfunc.h ============================================================================== --- user/dfr/xenhvm/6/sys/amd64/include/xen/xenfunc.h Fri Dec 5 14:37:14 2008 (r185636) +++ user/dfr/xenhvm/6/sys/amd64/include/xen/xenfunc.h Fri Dec 5 15:00:59 2008 (r185637) @@ -30,15 +30,13 @@ #ifndef _XEN_XENFUNC_H_ #define _XEN_XENFUNC_H_ -#include <machine/xen/xen-os.h> -#include <machine/xen/hypervisor.h> #ifdef XENHVM #include <machine/xen/xenvar.h> #else #include <machine/xen/xenpmap.h> #include <machine/segments.h> #endif -#include <sys/pcpu.h> + #define BKPT __asm__("int3"); #define XPQ_CALL_DEPTH 5 #define XPQ_CALL_COUNT 2 Modified: user/dfr/xenhvm/6/sys/amd64/include/xen/xenpmap.h ============================================================================== --- user/dfr/xenhvm/6/sys/amd64/include/xen/xenpmap.h Fri Dec 5 14:37:14 2008 (r185636) +++ user/dfr/xenhvm/6/sys/amd64/include/xen/xenpmap.h Fri Dec 5 15:00:59 2008 (r185637) @@ -33,6 +33,9 @@ #ifndef _XEN_XENPMAP_H_ #define _XEN_XENPMAP_H_ + +#include <machine/xen/features.h> + void _xen_queue_pt_update(vm_paddr_t, vm_paddr_t, char *, int); void xen_pt_switch(vm_paddr_t); void xen_set_ldt(vm_paddr_t, unsigned long); @@ -53,10 +56,6 @@ void pmap_ref(pt_entry_t *pte, vm_paddr_ #define xen_queue_pt_update(a, b) _xen_queue_pt_update((a), (b), NULL, 0) #endif - -#include <sys/param.h> -#include <sys/pcpu.h> - #ifdef PMAP_DEBUG #define PMAP_REF pmap_ref #define PMAP_DEC_REF_PAGE pmap_dec_ref_page Modified: user/dfr/xenhvm/6/sys/amd64/include/xen/xenvar.h ============================================================================== --- user/dfr/xenhvm/6/sys/amd64/include/xen/xenvar.h Fri Dec 5 14:37:14 2008 (r185636) +++ user/dfr/xenhvm/6/sys/amd64/include/xen/xenvar.h Fri Dec 5 15:00:59 2008 (r185637) @@ -37,7 +37,7 @@ extern int xendebug_flags; #else #define XENPRINTF printf #endif -#include <machine/xen/features.h> +#include <xen/features.h> #if 0 #define TRACE_ENTER XENPRINTF("(file=%s, line=%d) entered %s\n", __FILE__, __LINE__, __FUNCTION__) @@ -111,18 +111,8 @@ extern xen_pfn_t *xen_machine_phys; #endif - void xpq_init(void); -#define BITS_PER_LONG 32 -#define NR_CPUS MAX_VIRT_CPUS - -#define BITS_TO_LONGS(bits) \ - (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG) -#define DECLARE_BITMAP(name,bits) \ - unsigned long name[BITS_TO_LONGS(bits)] -typedef struct { DECLARE_BITMAP(bits, NR_CPUS); } xen_cpumask_t; - int xen_create_contiguous_region(vm_page_t pages, int npages); void xen_destroy_contiguous_region(void * addr, int npages); Modified: user/dfr/xenhvm/6/sys/dev/xen/blkfront/blkfront.c ============================================================================== --- user/dfr/xenhvm/6/sys/dev/xen/blkfront/blkfront.c Fri Dec 5 14:37:14 2008 (r185636) +++ user/dfr/xenhvm/6/sys/dev/xen/blkfront/blkfront.c Fri Dec 5 15:00:59 2008 (r185637) @@ -40,17 +40,18 @@ __FBSDID("$FreeBSD$"); #include <machine/intr_machdep.h> #include <machine/vmparam.h> -#include <machine/xen/hypervisor.h> #include <machine/xen/xen-os.h> -#include <machine/xen/xen_intr.h> -#include <machine/xen/evtchn.h> +#include <xen/hypervisor.h> +#include <machine/xen/xenfunc.h> + +#include <xen/xen_intr.h> +#include <xen/evtchn.h> +#include <xen/gnttab.h> #include <xen/interface/grant_table.h> #include <xen/interface/io/protocols.h> #include <xen/xenbus/xenbusvar.h> #include <geom/geom_disk.h> -#include <machine/xen/xenfunc.h> -#include <xen/gnttab.h> #include <dev/xen/blkfront/block.h> @@ -106,7 +107,7 @@ static char * blkif_status_name[] = { #endif #define WPRINTK(fmt, args...) printf("[XEN] " fmt, ##args) #if 0 -#define DPRINTK(fmt, args...) printf("[XEN] %s:%d" fmt ".\n", __FUNCTION__, __LINE__,##args) +#define DPRINTK(fmt, args...) printf("[XEN] %s:%d: " fmt ".\n", __func__, __LINE__, ##args) #else #define DPRINTK(fmt, args...) #endif @@ -322,17 +323,17 @@ blkfront_probe(device_t dev) static int blkfront_attach(device_t dev) { - int err, vdevice, i, unit; + int error, vdevice, i, unit; struct blkfront_info *info; const char *name; /* FIXME: Use dynamic device id if this is not set. */ - err = xenbus_scanf(XBT_NIL, xenbus_get_node(dev), - "virtual-device", "%i", &vdevice); - if (err != 1) { - xenbus_dev_fatal(dev, err, "reading virtual-device"); + error = xenbus_scanf(XBT_NIL, xenbus_get_node(dev), + "virtual-device", NULL, "%i", &vdevice); + if (error) { + xenbus_dev_fatal(dev, error, "reading virtual-device"); printf("couldn't find virtual device"); - return (err); + return (error); } blkfront_vdevice_to_unit(vdevice, &unit, &name); @@ -361,10 +362,9 @@ blkfront_attach(device_t dev) /* Front end dir is a number, which is used as the id. */ info->handle = strtoul(strrchr(xenbus_get_node(dev),'/')+1, NULL, 0); - err = talk_to_backend(dev, info); - if (err) { - return err; - } + error = talk_to_backend(dev, info); + if (error) + return (error); return (0); } @@ -375,7 +375,7 @@ blkfront_resume(device_t dev) struct blkfront_info *info = device_get_softc(dev); int err; - DPRINTK("blkfront_resume: %s\n", dev->nodename); + DPRINTK("blkfront_resume: %s\n", xenbus_get_node(dev)); blkif_free(info, 1); @@ -450,7 +450,7 @@ static int setup_blkring(device_t dev, struct blkfront_info *info) { blkif_sring_t *sring; - int err; + int error; info->ring_ref = GRANT_INVALID_REF; @@ -462,28 +462,27 @@ setup_blkring(device_t dev, struct blkfr SHARED_RING_INIT(sring); FRONT_RING_INIT(&info->ring, sring, PAGE_SIZE); - err = xenbus_grant_ring(dev, (vtomach(info->ring.sring) >> PAGE_SHIFT)); - if (err < 0) { + error = xenbus_grant_ring(dev, + (vtomach(info->ring.sring) >> PAGE_SHIFT), &info->ring_ref); + if (error) { free(sring, M_DEVBUF); info->ring.sring = NULL; goto fail; } - info->ring_ref = err; - err = bind_listening_port_to_irqhandler(xenbus_get_otherend_id(dev), - "xbd", (driver_intr_t *)blkif_int, info, - INTR_TYPE_BIO | INTR_MPSAFE, NULL); - if (err <= 0) { - xenbus_dev_fatal(dev, err, - "bind_evtchn_to_irqhandler failed"); + error = bind_listening_port_to_irqhandler(xenbus_get_otherend_id(dev), + "xbd", (driver_intr_t *)blkif_int, info, + INTR_TYPE_BIO | INTR_MPSAFE, &info->irq); + if (error) { + xenbus_dev_fatal(dev, error, + "bind_evtchn_to_irqhandler failed"); goto fail; } - info->irq = err; - return 0; + return (0); fail: blkif_free(info, 0); - return err; + return (error); } @@ -495,7 +494,7 @@ blkfront_backend_changed(device_t dev, X { struct blkfront_info *info = device_get_softc(dev); - DPRINTK("blkfront:backend_changed.\n"); + DPRINTK("backend_state=%d\n", backend_state); switch (backend_state) { case XenbusStateUnknown: @@ -708,7 +707,7 @@ blkif_open(struct disk *dp) struct xb_softc *sc = (struct xb_softc *)dp->d_drv1; if (sc == NULL) { - printk("xb%d: not found", sc->xb_unit); + printf("xb%d: not found", sc->xb_unit); return (ENXIO); } @@ -999,7 +998,7 @@ blkif_free(struct blkfront_info *info, i info->ring.sring = NULL; } if (info->irq) - unbind_from_irqhandler(info->irq, info); + unbind_from_irqhandler(info->irq); info->irq = 0; } @@ -1022,7 +1021,6 @@ blkif_recover(struct blkfront_info *info /* Stage 1: Make a safe copy of the shadow state. */ copy = (struct blk_shadow *)malloc(sizeof(info->shadow), M_DEVBUF, M_NOWAIT|M_ZERO); - PANIC_IF(copy == NULL); memcpy(copy, info->shadow, sizeof(info->shadow)); /* Stage 2: Set up free list. */ Modified: user/dfr/xenhvm/6/sys/dev/xen/console/console.c ============================================================================== --- user/dfr/xenhvm/6/sys/dev/xen/console/console.c Fri Dec 5 14:37:14 2008 (r185636) +++ user/dfr/xenhvm/6/sys/dev/xen/console/console.c Fri Dec 5 15:00:59 2008 (r185637) @@ -15,8 +15,8 @@ #include <sys/bus.h> #include <machine/stdarg.h> #include <machine/xen/xen-os.h> -#include <machine/xen/hypervisor.h> -#include <machine/xen/xen_intr.h> +#include <xen/hypervisor.h> +#include <xen/xen_intr.h> #include <sys/cons.h> #include <sys/proc.h> @@ -234,7 +234,7 @@ static int xc_attach(device_t dev) { struct xc_softc *sc = (struct xc_softc *)device_get_softc(dev); - + int error; if (xen_start_info->flags & SIF_INITDOMAIN) { xc_consdev.cn_putc = xccnputc_dom0; @@ -259,16 +259,11 @@ xc_attach(device_t dev) callout_reset(&xc_callout, XC_POLLTIME, xc_timeout, xccons); if (xen_start_info->flags & SIF_INITDOMAIN) { - PANIC_IF(bind_virq_to_irqhandler( - VIRQ_CONSOLE, - 0, - "console", - xencons_priv_interrupt, - INTR_TYPE_TTY) < 0); - + error = bind_virq_to_irqhandler(VIRQ_CONSOLE, 0, "console", + xencons_priv_interrupt, INTR_TYPE_TTY, NULL); + KASSERT(error >= 0, ("can't register console interrupt")); } - /* register handler to flush console on shutdown */ if ((EVENTHANDLER_REGISTER(shutdown_post_sync, xc_shutdown, NULL, SHUTDOWN_PRI_DEFAULT)) == NULL) Modified: user/dfr/xenhvm/6/sys/dev/xen/console/xencons_ring.c ============================================================================== --- user/dfr/xenhvm/6/sys/dev/xen/console/xencons_ring.c Fri Dec 5 14:37:14 2008 (r185636) +++ user/dfr/xenhvm/6/sys/dev/xen/console/xencons_ring.c Fri Dec 5 15:00:59 2008 (r185637) @@ -13,17 +13,17 @@ __FBSDID("$FreeBSD$"); #include <sys/conf.h> #include <sys/kernel.h> #include <sys/bus.h> -#include <machine/stdarg.h> -#include <machine/xen/xen-os.h> -#include <machine/xen/hypervisor.h> -#include <machine/xen/xen_intr.h> #include <sys/cons.h> +#include <machine/stdarg.h> +#include <machine/xen/xen-os.h> +#include <xen/hypervisor.h> -#include <dev/xen/console/xencons_ring.h> -#include <machine/xen/evtchn.h> +#include <xen/xen_intr.h> +#include <xen/evtchn.h> #include <xen/interface/io/console.h> +#include <dev/xen/console/xencons_ring.h> #define console_evtchn console.domU.evtchn extern char *console_page; @@ -59,7 +59,8 @@ xencons_ring_send(const char *data, unsi sent = 0; mb(); - PANIC_IF((prod - cons) > sizeof(intf->out)); + KASSERT((prod - cons) <= sizeof(intf->out), + ("console send ring inconsistent")); while ((sent < len) && ((prod - cons) < sizeof(intf->out))) intf->out[MASK_XENCONS_IDX(prod++, intf->out)] = data[sent++]; @@ -116,8 +117,8 @@ xencons_ring_init(void) return 0; err = bind_caller_port_to_irqhandler(xen_start_info->console_evtchn, - "xencons", xencons_handle_input, NULL, - INTR_TYPE_MISC | INTR_MPSAFE, NULL); + "xencons", xencons_handle_input, NULL, + INTR_TYPE_MISC | INTR_MPSAFE, NULL); if (err) { return err; } Modified: user/dfr/xenhvm/6/sys/dev/xen/netfront/netfront.c ============================================================================== --- user/dfr/xenhvm/6/sys/dev/xen/netfront/netfront.c Fri Dec 5 14:37:14 2008 (r185636) +++ user/dfr/xenhvm/6/sys/dev/xen/netfront/netfront.c Fri Dec 5 15:00:59 2008 (r185637) @@ -63,17 +63,19 @@ __FBSDID("$FreeBSD$"); #include <machine/intr_machdep.h> #include <machine/xen/xen-os.h> -#include <machine/xen/hypervisor.h> -#include <machine/xen/xen_intr.h> -#include <machine/xen/evtchn.h> +#include <xen/hypervisor.h> #include <machine/xen/xenvar.h> +#include <xen/features.h> + +#include <xen/xen_intr.h> +#include <xen/evtchn.h> #include <xen/gnttab.h> #include <xen/interface/memory.h> -#include <dev/xen/netfront/mbufq.h> -#include <machine/xen/features.h> #include <xen/interface/io/netif.h> #include <xen/xenbus/xenbusvar.h> +#include <dev/xen/netfront/mbufq.h> + #include "xenbus_if.h" #define GRANT_INVALID_REF 0 @@ -368,24 +370,25 @@ makembuf (struct mbuf *buf) static int xen_net_read_mac(device_t dev, uint8_t mac[]) { - char *s; - int i; - char *e; - char *macstr = xenbus_read(XBT_NIL, xenbus_get_node(dev), "mac", NULL); - if (IS_ERR(macstr)) { - return PTR_ERR(macstr); - } + int error, i; + char *s, *e, *macstr; + + error = xenbus_read(XBT_NIL, xenbus_get_node(dev), "mac", NULL, + (void **) &macstr); + if (error) + return (error); + s = macstr; for (i = 0; i < ETHER_ADDR_LEN; i++) { mac[i] = strtoul(s, &e, 16); if (s == e || (e[0] != ':' && e[0] != 0)) { free(macstr, M_DEVBUF); - return ENOENT; + return (ENOENT); } s = &e[1]; } free(macstr, M_DEVBUF); - return 0; + return (0); } /** @@ -537,7 +540,7 @@ setup_device(device_t dev, struct netfro { netif_tx_sring_t *txs; netif_rx_sring_t *rxs; - int err; + int error; struct ifnet *ifp; ifp = info->xn_ifp; @@ -550,51 +553,48 @@ setup_device(device_t dev, struct netfro txs = (netif_tx_sring_t *)malloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT|M_ZERO); if (!txs) { - err = ENOMEM; - xenbus_dev_fatal(dev, err, "allocating tx ring page"); + error = ENOMEM; + xenbus_dev_fatal(dev, error, "allocating tx ring page"); goto fail; } SHARED_RING_INIT(txs); FRONT_RING_INIT(&info->tx, txs, PAGE_SIZE); - err = xenbus_grant_ring(dev, virt_to_mfn(txs)); - if (err < 0) + error = xenbus_grant_ring(dev, virt_to_mfn(txs), &info->tx_ring_ref); + if (error) goto fail; - info->tx_ring_ref = err; rxs = (netif_rx_sring_t *)malloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT|M_ZERO); if (!rxs) { - err = ENOMEM; - xenbus_dev_fatal(dev, err, "allocating rx ring page"); + error = ENOMEM; + xenbus_dev_fatal(dev, error, "allocating rx ring page"); goto fail; } SHARED_RING_INIT(rxs); FRONT_RING_INIT(&info->rx, rxs, PAGE_SIZE); - err = xenbus_grant_ring(dev, virt_to_mfn(rxs)); - if (err < 0) + error = xenbus_grant_ring(dev, virt_to_mfn(rxs), &info->rx_ring_ref); + if (error) goto fail; - info->rx_ring_ref = err; #if 0 network_connect(info); #endif - err = bind_listening_port_to_irqhandler(xenbus_get_otherend_id(dev), - "xn", xn_intr, info, INTR_TYPE_NET | INTR_MPSAFE, NULL); + error = bind_listening_port_to_irqhandler(xenbus_get_otherend_id(dev), + "xn", xn_intr, info, INTR_TYPE_NET | INTR_MPSAFE, &info->irq); - if (err <= 0) { - xenbus_dev_fatal(dev, err, + if (error) { + xenbus_dev_fatal(dev, error, "bind_evtchn_to_irqhandler failed"); goto fail; } - info->irq = err; show_device(info); - return 0; + return (0); fail: netif_free(info); - return err; + return (error); } /** @@ -1562,18 +1562,18 @@ xn_stop(struct netfront_info *sc) int network_connect(struct netfront_info *np) { - int i, requeue_idx, err; + int i, requeue_idx, error; grant_ref_t ref; netif_rx_request_t *req; u_int feature_rx_copy, feature_rx_flip; - err = xenbus_scanf(XBT_NIL, xenbus_get_otherend_path(np->xbdev), - "feature-rx-copy", "%u", &feature_rx_copy); - if (err != 1) + error = xenbus_scanf(XBT_NIL, xenbus_get_otherend_path(np->xbdev), + "feature-rx-copy", NULL, "%u", &feature_rx_copy); + if (error) feature_rx_copy = 0; - err = xenbus_scanf(XBT_NIL, xenbus_get_otherend_path(np->xbdev), - "feature-rx-flip", "%u", &feature_rx_flip); - if (err != 1) + error = xenbus_scanf(XBT_NIL, xenbus_get_otherend_path(np->xbdev), + "feature-rx-flip", NULL, "%u", &feature_rx_flip); + if (error) feature_rx_flip = 1; /* @@ -1586,9 +1586,9 @@ network_connect(struct netfront_info *np XN_LOCK(np); /* Recovery procedure: */ - err = talk_to_backend(np->xbdev, np); - if (err) - return (err); + error = talk_to_backend(np->xbdev, np); + if (error) + return (error); /* Step 1: Reinitialise variables. */ netif_release_tx_bufs(np); @@ -1796,7 +1796,7 @@ static void netif_disconnect_backend(str #if 0 if (info->irq) - unbind_from_irqhandler(info->irq, info->netdev); + unbind_from_irqhandler(info->irq); #else panic("FIX ME"); #endif Modified: user/dfr/xenhvm/6/sys/dev/xen/xenpci/evtchn.c ============================================================================== --- user/dfr/xenhvm/6/sys/dev/xen/xenpci/evtchn.c Fri Dec 5 14:37:14 2008 (r185636) +++ user/dfr/xenhvm/6/sys/dev/xen/xenpci/evtchn.c Fri Dec 5 15:00:59 2008 (r185637) @@ -36,20 +36,17 @@ __FBSDID("$FreeBSD: user/dfr/xenhvm/6/sy #include <sys/bus.h> #include <sys/malloc.h> #include <sys/kernel.h> +#include <sys/limits.h> #include <sys/lock.h> #include <sys/mutex.h> #include <sys/interrupt.h> #include <sys/pcpu.h> -#include <machine/cpufunc.h> -#include <machine/intr_machdep.h> - #include <machine/xen/xen-os.h> #include <machine/xen/xenvar.h> -#include <machine/xen/xen_intr.h> -#include <machine/xen/synch_bitops.h> -#include <machine/xen/evtchn.h> -#include <machine/xen/hypervisor.h> +#include <xen/hypervisor.h> +#include <xen/xen_intr.h> +#include <xen/evtchn.h> #include <sys/smp.h> #include <dev/xen/xenpci/xenpcivar.h> @@ -81,10 +78,11 @@ static struct mtx irq_alloc_lock; #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) -static int alloc_xen_irq(void) +static unsigned int +alloc_xen_irq(void) { static int warned; - int irq; + unsigned int irq; mtx_lock(&irq_alloc_lock); @@ -107,40 +105,46 @@ static int alloc_xen_irq(void) return -ENOSPC; } -static void free_xen_irq(int irq) +static void +free_xen_irq(int irq) { + mtx_lock(&irq_alloc_lock); irq_evtchn[irq].inuse = 0; mtx_unlock(&irq_alloc_lock); } -int irq_to_evtchn_port(int irq) +int +irq_to_evtchn_port(int irq) { + return irq_evtchn[irq].evtchn; } -void mask_evtchn(int port) +void +mask_evtchn(int port) { shared_info_t *s = HYPERVISOR_shared_info; + synch_set_bit(port, &s->evtchn_mask[0]); } -void unmask_evtchn(int port) +void +unmask_evtchn(int port) { evtchn_unmask_t op = { .port = port }; + HYPERVISOR_event_channel_op(EVTCHNOP_unmask, &op); } -int bind_listening_port_to_irqhandler( - unsigned int remote_domain, - const char *devname, - driver_intr_t handler, - void *arg, - unsigned long irqflags, - void **cookiep) +int +bind_listening_port_to_irqhandler(unsigned int remote_domain, + const char *devname, driver_intr_t handler, void *arg, + unsigned long irqflags, unsigned int *irqp) { struct evtchn_alloc_unbound alloc_unbound; - int err, irq; + unsigned int irq; + int error; irq = alloc_xen_irq(); if (irq < 0) @@ -150,12 +154,12 @@ int bind_listening_port_to_irqhandler( alloc_unbound.dom = DOMID_SELF; alloc_unbound.remote_dom = remote_domain; - err = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, + error = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &alloc_unbound); - if (err) { + if (error) { mtx_unlock(&irq_evtchn[irq].lock); free_xen_irq(irq); - return err; + return (-error); } irq_evtchn[irq].handler = handler; @@ -169,18 +173,17 @@ int bind_listening_port_to_irqhandler( mtx_unlock(&irq_evtchn[irq].lock); - return irq; + if (irqp) + *irqp = irq; + return (0); } -int bind_caller_port_to_irqhandler( - unsigned int caller_port, - const char *devname, - driver_intr_t handler, - void *arg, - unsigned long irqflags, - void **cookiep) +int +bind_caller_port_to_irqhandler(unsigned int caller_port, + const char *devname, driver_intr_t handler, void *arg, + unsigned long irqflags, unsigned int *irqp) { - int irq; + unsigned int irq; irq = alloc_xen_irq(); if (irq < 0) @@ -199,10 +202,13 @@ int bind_caller_port_to_irqhandler( mtx_unlock(&irq_evtchn[irq].lock); - return irq; + if (irqp) + *irqp = irq; + return (0); } -void unbind_from_irqhandler(unsigned int irq, void *dev_id) +void +unbind_from_irqhandler(unsigned int irq) { int evtchn; @@ -258,6 +264,7 @@ evtchn_interrupt(void *arg) int irq; shared_info_t *s = HYPERVISOR_shared_info; vcpu_info_t *v = &s->vcpu_info[cpu]; + struct pcpu *pc = pcpu_find(cpu); unsigned long l1, l2; v->evtchn_upcall_pending = 0; @@ -271,17 +278,17 @@ evtchn_interrupt(void *arg) l1 = atomic_readandclear_long(&v->evtchn_pending_sel); - l1i = per_cpu(last_processed_l1i, cpu); - l2i = per_cpu(last_processed_l2i, cpu); + l1i = pc->pc_last_processed_l1i; + l2i = pc->pc_last_processed_l2i; while (l1 != 0) { - l1i = (l1i + 1) % BITS_PER_LONG; + l1i = (l1i + 1) % LONG_BIT; masked_l1 = l1 & ((~0UL) << l1i); if (masked_l1 == 0) { /* if we masked out all events, wrap around to the beginning */ - l1i = BITS_PER_LONG - 1; - l2i = BITS_PER_LONG - 1; + l1i = LONG_BIT - 1; + l2i = LONG_BIT - 1; continue; } l1i = __ffs(masked_l1); @@ -289,17 +296,17 @@ evtchn_interrupt(void *arg) do { l2 = active_evtchns(cpu, s, l1i); - l2i = (l2i + 1) % BITS_PER_LONG; + l2i = (l2i + 1) % LONG_BIT; masked_l2 = l2 & ((~0UL) << l2i); if (masked_l2 == 0) { /* if we masked out all events, move on */ - l2i = BITS_PER_LONG - 1; + l2i = LONG_BIT - 1; break; } l2i = __ffs(masked_l2); /* process port */ - port = (l1i * BITS_PER_LONG) + l2i; + port = (l1i * LONG_BIT) + l2i; synch_clear_bit(port, &s->evtchn_pending[0]); irq = evtchn_to_irq[port]; @@ -327,10 +334,10 @@ evtchn_interrupt(void *arg) mtx_unlock(&irq_evtchn[irq].lock); /* if this is the final port processed, we'll pick up here+1 next time */ - per_cpu(last_processed_l1i, cpu) = l1i; - per_cpu(last_processed_l2i, cpu) = l2i; + pc->pc_last_processed_l1i = l1i; + pc->pc_last_processed_l2i = l2i; - } while (l2i != BITS_PER_LONG - 1); + } while (l2i != LONG_BIT - 1); l2 = active_evtchns(cpu, s, l1i); if (l2 == 0) /* we handled all ports, so we can clear the selector bit */ @@ -363,8 +370,8 @@ xenpci_irq_init(device_t device, struct mtx_init(&irq_evtchn[irq].lock, "irq-evtchn", NULL, MTX_DEF); for (cpu = 0; cpu < mp_ncpus; cpu++) { - per_cpu(last_processed_l1i, cpu) = BITS_PER_LONG - 1; - per_cpu(last_processed_l2i, cpu) = BITS_PER_LONG - 1; + pcpu_find(cpu)->pc_last_processed_l1i = LONG_BIT - 1; + pcpu_find(cpu)->pc_last_processed_l2i = LONG_BIT - 1; } error = BUS_SETUP_INTR(device_get_parent(device), device, Modified: user/dfr/xenhvm/6/sys/dev/xen/xenpci/xenpci.c ============================================================================== --- user/dfr/xenhvm/6/sys/dev/xen/xenpci/xenpci.c Fri Dec 5 14:37:14 2008 (r185636) +++ user/dfr/xenhvm/6/sys/dev/xen/xenpci/xenpci.c Fri Dec 5 15:00:59 2008 (r185637) @@ -41,8 +41,9 @@ __FBSDID("$FreeBSD$"); #include <sys/rman.h> #include <machine/stdarg.h> -#include <machine/xen/features.h> -#include <machine/xen/hypervisor.h> +#include <machine/xen/xen-os.h> +#include <xen/features.h> +#include <xen/hypervisor.h> #include <xen/interface/memory.h> #include <xen/interface/hvm/params.h> Modified: user/dfr/xenhvm/6/sys/i386/conf/XEN ============================================================================== --- user/dfr/xenhvm/6/sys/i386/conf/XEN Fri Dec 5 14:37:14 2008 (r185636) +++ user/dfr/xenhvm/6/sys/i386/conf/XEN Fri Dec 5 15:00:59 2008 (r185637) @@ -61,8 +61,8 @@ options AUDIT # Security event auditi options KDB # Enable kernel debugger support. options DDB # Support DDB. options GDB # Support remote GDB. -options INVARIANTS # Enable calls of extra sanity checking -options INVARIANT_SUPPORT # Extra sanity checks of internal structures, required by INVARIANTS +#options INVARIANTS # Enable calls of extra sanity checking +#options INVARIANT_SUPPORT # Extra sanity checks of internal structures, required by INVARIANTS #options WITNESS # Enable checks to detect deadlocks and cycles #options WITNESS_SKIPSPIN # Don't run witness on spinlocks for speed Modified: user/dfr/xenhvm/6/sys/i386/i386/genassym.c ============================================================================== --- user/dfr/xenhvm/6/sys/i386/i386/genassym.c Fri Dec 5 14:37:14 2008 (r185636) +++ user/dfr/xenhvm/6/sys/i386/i386/genassym.c Fri Dec 5 15:00:59 2008 (r185637) @@ -229,7 +229,7 @@ ASSYM(BUS_SPACE_HANDLE_IAT, offsetof(str #endif #ifdef XEN -#include <machine/xen/hypervisor.h> +#include <xen/hypervisor.h> ASSYM(PC_CR3, offsetof(struct pcpu, pc_cr3)); ASSYM(HYPERVISOR_VIRT_START, __HYPERVISOR_VIRT_START); #endif Modified: user/dfr/xenhvm/6/sys/i386/i386/machdep.c ============================================================================== --- user/dfr/xenhvm/6/sys/i386/i386/machdep.c Fri Dec 5 14:37:14 2008 (r185636) +++ user/dfr/xenhvm/6/sys/i386/i386/machdep.c Fri Dec 5 15:00:59 2008 (r185637) @@ -143,11 +143,11 @@ uint32_t arch_i386_xbox_memsize = 0; #ifdef XEN /* XEN includes */ -#include <machine/xen/hypervisor.h> +#include <xen/hypervisor.h> #include <machine/xen/xen-os.h> #include <machine/xen/xenvar.h> #include <machine/xen/xenfunc.h> -#include <machine/xen/xen_intr.h> +#include <xen/xen_intr.h> void Xhypervisor_callback(void); void failsafe_callback(void); @@ -2255,13 +2255,16 @@ init386(int first) ssdtosd(&gdt_segs[x], &gdt[x].sd); - printk("gdt=%p\n", gdt); - printk("PTmap=%p\n", PTmap); - printk("addr=%p\n", *vtopte((unsigned long)gdt) & ~PG_RW); + if (bootverbose) { + printf("gdt=%p\n", gdt); + printf("PTmap=%p\n", PTmap); + printf("addr=%#jx\n", (uintmax_t)*vtopte((unsigned long)gdt) & ~PG_RW); + } gdtmachpfn = vtomach(gdt) >> PAGE_SHIFT; PT_SET_MA(gdt, *vtopte((unsigned long)gdt) & ~(PG_RW|PG_M|PG_A)); - PANIC_IF(HYPERVISOR_set_gdt(&gdtmachpfn, 512) != 0); + error = HYPERVISOR_set_gdt(&gdtmachpfn, 512); + KASSERT(error == 0, ("unexpected result from set_gdt")); lgdt(&r_gdt /* unused */); gdtset = 1; Modified: user/dfr/xenhvm/6/sys/i386/i386/sys_machdep.c ============================================================================== --- user/dfr/xenhvm/6/sys/i386/i386/sys_machdep.c Fri Dec 5 14:37:14 2008 (r185636) +++ user/dfr/xenhvm/6/sys/i386/i386/sys_machdep.c Fri Dec 5 15:00:59 2008 (r185637) @@ -59,6 +59,8 @@ __FBSDID("$FreeBSD$"); #include <vm/vm_kern.h> /* for kernel_map */ #ifdef XEN *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200812051500.mB5F0xsJ057455>
