Re: [Qemu-devel] [PATCH v8 5/5] RESEND: Inter-VM shared memory PCI device

2010-08-11 Thread Stefan Weil

Am 11.08.2010 19:07, schrieb Paolo Bonzini:

On 08/11/2010 11:49 AM, Cam Macdonell wrote:

The win32 problems (missing mmap, maybe more) remain.
Could you please fix them?


Could that be accomplished with excluding it on Windows on the 
makefiles?


Yes, just use obj-$(CONFIG_POSIX).

Paolo




Or use obj-$(CONFIG_KVM) if that file is only reasonable when KVM is 
supported.


Stefan




Re: [Qemu-devel] [PATCH v8 5/5] RESEND: Inter-VM shared memory PCI device

2010-08-11 Thread Paolo Bonzini

On 08/11/2010 11:49 AM, Cam Macdonell wrote:

The win32 problems (missing mmap, maybe more) remain.
Could you please fix them?


Could that be accomplished with excluding it on Windows on the makefiles?


Yes, just use obj-$(CONFIG_POSIX).

Paolo



Re: [Qemu-devel] [PATCH v8 5/5] RESEND: Inter-VM shared memory PCI device

2010-08-11 Thread Cam Macdonell
On Wed, Aug 11, 2010 at 4:35 AM, Stefan Weil  wrote:
> Am 27.07.2010 18:54, schrieb Cam Macdonell:
>>
>> resend for bug fix related to removal of irqfd
>>
>> Support an inter-vm shared memory device that maps a shared-memory object
>> as a
>> PCI device in the guest. This patch also supports interrupts between guest
>> by
>> communicating over a unix domain socket. This patch applies to the
>> qemu-kvm
>> repository.
>>
>> -device ivshmem,size=[,shm=]
>>
>> Interrupts are supported between multiple VMs by using a shared memory
>> server
>> by using a chardev socket.
>>
>> -device ivshmem,size=[,shm=]
>> [,chardev=][,msi=on][,ioeventfd=on][,vectors=n][,role=peer|master]
>> -chardev socket,path=,id=
>>
>> The shared memory server, sample programs and init scripts are in a git
>> repo here:
>>
>> www.gitorious.org/nahanni
>>
>> Signed-off-by: Cam Macdonell 
>> ---
>> Makefile.target | 3 +
>> hw/ivshmem.c | 828 +++
>> qemu-char.c | 6 +
>> qemu-char.h | 3 +
>> qemu-doc.texi | 43 +++
>> 5 files changed, 883 insertions(+), 0 deletions(-)
>> create mode 100644 hw/ivshmem.c
>>
>
> Hi,
>
> hw/ivshmem.c breaks compilation on 32 bit hosts, for targets without kvm
> support
> and for win32 environments.
>
> I sent patches to qemu-devel which fix the first two problems.
>
> The win32 problems (missing mmap, maybe more) remain.
> Could you please fix them?

Could that be accomplished with excluding it on Windows on the makefiles?

Thanks,
Cam

>
> Regards
> Stefan
>
>



Re: [Qemu-devel] [PATCH v8 5/5] RESEND: Inter-VM shared memory PCI device

2010-08-11 Thread Stefan Weil

Am 27.07.2010 18:54, schrieb Cam Macdonell:

resend for bug fix related to removal of irqfd

Support an inter-vm shared memory device that maps a shared-memory 
object as a
PCI device in the guest. This patch also supports interrupts between 
guest by
communicating over a unix domain socket. This patch applies to the 
qemu-kvm

repository.

-device ivshmem,size=[,shm=]

Interrupts are supported between multiple VMs by using a shared memory 
server

by using a chardev socket.

-device ivshmem,size=[,shm=]
[,chardev=][,msi=on][,ioeventfd=on][,vectors=n][,role=peer|master]
-chardev socket,path=,id=

The shared memory server, sample programs and init scripts are in a 
git repo here:


www.gitorious.org/nahanni

Signed-off-by: Cam Macdonell 
---
Makefile.target | 3 +
hw/ivshmem.c | 828 +++
qemu-char.c | 6 +
qemu-char.h | 3 +
qemu-doc.texi | 43 +++
5 files changed, 883 insertions(+), 0 deletions(-)
create mode 100644 hw/ivshmem.c



Hi,

hw/ivshmem.c breaks compilation on 32 bit hosts, for targets without kvm 
support

and for win32 environments.

I sent patches to qemu-devel which fix the first two problems.

The win32 problems (missing mmap, maybe more) remain.
Could you please fix them?

Regards
Stefan




[Qemu-devel] [PATCH v8 5/5] RESEND: Inter-VM shared memory PCI device

2010-07-27 Thread Cam Macdonell
resend for bug fix related to removal of irqfd

Support an inter-vm shared memory device that maps a shared-memory object as a
PCI device in the guest.  This patch also supports interrupts between guest by
communicating over a unix domain socket.  This patch applies to the qemu-kvm
repository.

-device ivshmem,size=[,shm=]

Interrupts are supported between multiple VMs by using a shared memory server
by using a chardev socket.

-device ivshmem,size=[,shm=]
   
[,chardev=][,msi=on][,ioeventfd=on][,vectors=n][,role=peer|master]
-chardev socket,path=,id=

The shared memory server, sample programs and init scripts are in a git repo 
here:

www.gitorious.org/nahanni

Signed-off-by: Cam Macdonell 
---
 Makefile.target |3 +
 hw/ivshmem.c|  828 +++
 qemu-char.c |6 +
 qemu-char.h |3 +
 qemu-doc.texi   |   43 +++
 5 files changed, 883 insertions(+), 0 deletions(-)
 create mode 100644 hw/ivshmem.c

diff --git a/Makefile.target b/Makefile.target
index 8a9c427..b791492 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -190,6 +190,9 @@ obj-$(CONFIG_USB_OHCI) += usb-ohci.o
 obj-y += rtl8139.o
 obj-y += e1000.o
 
+# Inter-VM PCI shared memory
+obj-y += ivshmem.o
+
 # Hardware support
 obj-i386-y += vga.o
 obj-i386-y += mc146818rtc.o i8259.o pc.o
diff --git a/hw/ivshmem.c b/hw/ivshmem.c
new file mode 100644
index 000..bbb5cba
--- /dev/null
+++ b/hw/ivshmem.c
@@ -0,0 +1,828 @@
+/*
+ * Inter-VM Shared Memory PCI device.
+ *
+ * Author:
+ *  Cam Macdonell 
+ *
+ * Based On: cirrus_vga.c
+ *  Copyright (c) 2004 Fabrice Bellard
+ *  Copyright (c) 2004 Makoto Suzuki (suzu)
+ *
+ *  and rtl8139.c
+ *  Copyright (c) 2006 Igor Kovalenko
+ *
+ * This code is licensed under the GNU GPL v2.
+ */
+#include "hw.h"
+#include "pc.h"
+#include "pci.h"
+#include "msix.h"
+#include "kvm.h"
+
+#include 
+#include 
+
+#define IVSHMEM_IOEVENTFD   0
+#define IVSHMEM_MSI 1
+
+#define IVSHMEM_PEER0
+#define IVSHMEM_MASTER  1
+
+#define IVSHMEM_REG_BAR_SIZE 0x100
+
+//#define DEBUG_IVSHMEM
+#ifdef DEBUG_IVSHMEM
+#define IVSHMEM_DPRINTF(fmt, ...)\
+do {printf("IVSHMEM: " fmt, ## __VA_ARGS__); } while (0)
+#else
+#define IVSHMEM_DPRINTF(fmt, ...)
+#endif
+
+typedef struct Peer {
+int nb_eventfds;
+int *eventfds;
+} Peer;
+
+typedef struct EventfdEntry {
+PCIDevice *pdev;
+int vector;
+} EventfdEntry;
+
+typedef struct IVShmemState {
+PCIDevice dev;
+uint32_t intrmask;
+uint32_t intrstatus;
+uint32_t doorbell;
+
+CharDriverState **eventfd_chr;
+CharDriverState *server_chr;
+int ivshmem_mmio_io_addr;
+
+pcibus_t mmio_addr;
+pcibus_t shm_pci_addr;
+uint64_t ivshmem_offset;
+uint64_t ivshmem_size; /* size of shared memory region */
+int shm_fd; /* shared memory file descriptor */
+
+Peer *peers;
+int nb_peers; /* how many guests we have space for */
+int max_peer; /* maximum numbered peer */
+
+int vm_id;
+uint32_t vectors;
+uint32_t features;
+EventfdEntry *eventfd_table;
+
+char * shmobj;
+char * sizearg;
+char * role;
+int role_val;   /* scalar to avoid multiple string comparisons */
+} IVShmemState;
+
+/* registers for the Inter-VM shared memory device */
+enum ivshmem_registers {
+INTRMASK = 0,
+INTRSTATUS = 4,
+IVPOSITION = 8,
+DOORBELL = 12,
+};
+
+static inline uint32_t ivshmem_has_feature(IVShmemState *ivs,
+unsigned int feature) {
+return (ivs->features & (1 << feature));
+}
+
+static inline bool is_power_of_two(uint64_t x) {
+return (x & (x - 1)) == 0;
+}
+
+static void ivshmem_map(PCIDevice *pci_dev, int region_num,
+pcibus_t addr, pcibus_t size, int type)
+{
+IVShmemState *s = DO_UPCAST(IVShmemState, dev, pci_dev);
+
+s->shm_pci_addr = addr;
+
+if (s->ivshmem_offset > 0) {
+cpu_register_physical_memory(s->shm_pci_addr, s->ivshmem_size,
+s->ivshmem_offset);
+}
+
+IVSHMEM_DPRINTF("guest pci addr = %" FMT_PCIBUS ", guest h/w addr = %"
+PRIu64 ", size = %" FMT_PCIBUS "\n", addr, s->ivshmem_offset, size);
+
+}
+
+/* accessing registers - based on rtl8139 */
+static void ivshmem_update_irq(IVShmemState *s, int val)
+{
+int isr;
+isr = (s->intrstatus & s->intrmask) & 0x;
+
+/* don't print ISR resets */
+if (isr) {
+IVSHMEM_DPRINTF("Set IRQ to %d (%04x %04x)\n",
+   isr ? 1 : 0, s->intrstatus, s->intrmask);
+}
+
+qemu_set_irq(s->dev.irq[0], (isr != 0));
+}
+
+static void ivshmem_IntrMask_write(IVShmemState *s, uint32_t val)
+{
+IVSHMEM_DPRINTF("IntrMask write(w) val = 0x%04x\n", val);
+
+s->intrmask = val;
+
+ivshmem_update_irq(s, val);
+}
+
+static uint32_t ivshmem_IntrMask_read(IVShmemState *s)
+{
+uint32_t ret = s->intrmask;
+
+