]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/x86/xen/multicalls.c
x86: change copy_e820_map to append_e820_map
[linux-2.6-omap-h63xx.git] / arch / x86 / xen / multicalls.c
index c837e8e463db3567c0336357e0f0e0590af1bdaf..3c63c4da7ed19cbe4ae43234fe6f6068eb638a79 100644 (file)
 
 #include "multicalls.h"
 
+#define MC_DEBUG       1
+
 #define MC_BATCH       32
-#define MC_ARGS                (MC_BATCH * 16 / sizeof(u64))
+#define MC_ARGS                (MC_BATCH * 16)
 
 struct mc_buffer {
        struct multicall_entry entries[MC_BATCH];
-       u64 args[MC_ARGS];
-       unsigned mcidx, argidx;
+#if MC_DEBUG
+       struct multicall_entry debug[MC_BATCH];
+#endif
+       unsigned char args[MC_ARGS];
+       struct callback {
+               void (*fn)(void *);
+               void *data;
+       } callbacks[MC_BATCH];
+       unsigned mcidx, argidx, cbidx;
 };
 
 static DEFINE_PER_CPU(struct mc_buffer, mc_buffer);
@@ -43,6 +52,7 @@ void xen_mc_flush(void)
        struct mc_buffer *b = &__get_cpu_var(mc_buffer);
        int ret = 0;
        unsigned long flags;
+       int i;
 
        BUG_ON(preemptible());
 
@@ -51,13 +61,31 @@ void xen_mc_flush(void)
        local_irq_save(flags);
 
        if (b->mcidx) {
-               int i;
+#if MC_DEBUG
+               memcpy(b->debug, b->entries,
+                      b->mcidx * sizeof(struct multicall_entry));
+#endif
 
                if (HYPERVISOR_multicall(b->entries, b->mcidx) != 0)
                        BUG();
                for (i = 0; i < b->mcidx; i++)
                        if (b->entries[i].result < 0)
                                ret++;
+
+#if MC_DEBUG
+               if (ret) {
+                       printk(KERN_ERR "%d multicall(s) failed: cpu %d\n",
+                              ret, smp_processor_id());
+                       for (i = 0; i < b->mcidx; i++) {
+                               printk("  call %2d/%d: op=%lu arg=[%lx] result=%ld\n",
+                                      i+1, b->mcidx,
+                                      b->debug[i].op,
+                                      b->debug[i].args[0],
+                                      b->entries[i].result);
+                       }
+               }
+#endif
+
                b->mcidx = 0;
                b->argidx = 0;
        } else
@@ -65,6 +93,13 @@ void xen_mc_flush(void)
 
        local_irq_restore(flags);
 
+       for (i = 0; i < b->cbidx; i++) {
+               struct callback *cb = &b->callbacks[i];
+
+               (*cb->fn)(cb->data);
+       }
+       b->cbidx = 0;
+
        BUG_ON(ret);
 }
 
@@ -72,19 +107,60 @@ struct multicall_space __xen_mc_entry(size_t args)
 {
        struct mc_buffer *b = &__get_cpu_var(mc_buffer);
        struct multicall_space ret;
-       unsigned argspace = (args + sizeof(u64) - 1) / sizeof(u64);
+       unsigned argidx = roundup(b->argidx, sizeof(u64));
 
        BUG_ON(preemptible());
-       BUG_ON(argspace > MC_ARGS);
+       BUG_ON(b->argidx > MC_ARGS);
 
        if (b->mcidx == MC_BATCH ||
-           (b->argidx + argspace) > MC_ARGS)
+           (argidx + args) > MC_ARGS) {
                xen_mc_flush();
+               argidx = roundup(b->argidx, sizeof(u64));
+       }
 
        ret.mc = &b->entries[b->mcidx];
        b->mcidx++;
+       ret.args = &b->args[argidx];
+       b->argidx = argidx + args;
+
+       BUG_ON(b->argidx > MC_ARGS);
+       return ret;
+}
+
+struct multicall_space xen_mc_extend_args(unsigned long op, size_t size)
+{
+       struct mc_buffer *b = &__get_cpu_var(mc_buffer);
+       struct multicall_space ret = { NULL, NULL };
+
+       BUG_ON(preemptible());
+       BUG_ON(b->argidx > MC_ARGS);
+
+       if (b->mcidx == 0)
+               return ret;
+
+       if (b->entries[b->mcidx - 1].op != op)
+               return ret;
+
+       if ((b->argidx + size) > MC_ARGS)
+               return ret;
+
+       ret.mc = &b->entries[b->mcidx - 1];
        ret.args = &b->args[b->argidx];
-       b->argidx += argspace;
+       b->argidx += size;
 
+       BUG_ON(b->argidx > MC_ARGS);
        return ret;
 }
+
+void xen_mc_callback(void (*fn)(void *), void *data)
+{
+       struct mc_buffer *b = &__get_cpu_var(mc_buffer);
+       struct callback *cb;
+
+       if (b->cbidx == MC_BATCH)
+               xen_mc_flush();
+
+       cb = &b->callbacks[b->cbidx++];
+       cb->fn = fn;
+       cb->data = data;
+}