From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:49200) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R9NRA-0002BB-LP for qemu-devel@nongnu.org; Thu, 29 Sep 2011 16:42:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R9NR8-0000Of-BY for qemu-devel@nongnu.org; Thu, 29 Sep 2011 16:42:32 -0400 Received: from mail-qy0-f173.google.com ([209.85.216.173]:64669) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R9NR8-0000ON-7Y for qemu-devel@nongnu.org; Thu, 29 Sep 2011 16:42:30 -0400 Received: by qyc1 with SMTP id 1so4076123qyc.4 for ; Thu, 29 Sep 2011 13:42:29 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20110929134749.19559.26774.stgit@ginnungagap.bsc.es> References: <20110929134727.19559.54734.stgit@ginnungagap.bsc.es> <20110929134749.19559.26774.stgit@ginnungagap.bsc.es> From: Blue Swirl Date: Thu, 29 Sep 2011 20:42:07 +0000 Message-ID: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 4/5] backdoor: [softmmu] Add QEMU-side proxy to "libbackdoor.a" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?Q?Llu=C3=ADs_Vilanova?= Cc: Zhi Yong Wu , qemu-devel@nongnu.org 2011/9/29 Llu=C3=ADs Vilanova : > Uses a virtual device to proxy uses of the backdoor communication channel= to the > user-provided code. > > Signed-off-by: Llu=C3=ADs Vilanova > --- > =C2=A0Makefile.objs =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0 =C2=A01 > =C2=A0backdoor/qemu/softmmu.c | =C2=A0124 +++++++++++++++++++++++++++++++= ++++++++++++++++ > =C2=A0hw/pci.h =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| = =C2=A0 =C2=A01 > =C2=A03 files changed, 126 insertions(+), 0 deletions(-) > =C2=A0create mode 100644 backdoor/qemu/softmmu.c > > diff --git a/Makefile.objs b/Makefile.objs > index d39074d..5f54d10 100644 > --- a/Makefile.objs > +++ b/Makefile.objs > @@ -398,6 +398,7 @@ $(trace-obj-y): $(GENERATED_HEADERS) > =C2=A0# backdoor > > =C2=A0backdoor-nested-$(CONFIG_USER_ONLY) +=3D user.o > +backdoor-nested-$(CONFIG_SOFTMMU) +=3D softmmu.o > > =C2=A0backdoor-obj-y +=3D $(addprefix backdoor/qemu/, $(backdoor-nested-y= )) > > diff --git a/backdoor/qemu/softmmu.c b/backdoor/qemu/softmmu.c > new file mode 100644 > index 0000000..fdd3a25 > --- /dev/null > +++ b/backdoor/qemu/softmmu.c > @@ -0,0 +1,124 @@ > +/* > + * QEMU-side management of backdoor channels in softmmu emulation. > + * > + * Copyright (C) 2011 Llu=C3=ADs Vilanova > + * > + * This work is licensed under the terms of the GNU GPL, version 2 or la= ter. > + * See the COPYING file in the top-level directory. > + */ > + > +#include "hw/pci.h" > +#include "backdoor/qemu/qemu-backdoor.h" > + > + > +#define PAGE_SIZE TARGET_PAGE_SIZE > +#define CTRL_BYTES sizeof(uint64_t) > + > + > +typedef struct State > +{ > + =C2=A0 =C2=A0PCIDevice dev; > + > + =C2=A0 =C2=A0uint8_t pages; > + =C2=A0 =C2=A0uint64_t size; > + > + =C2=A0 =C2=A0uint64_t cmd; > + > + =C2=A0 =C2=A0void *data_ptr; > + =C2=A0 =C2=A0MemoryRegion data; > + =C2=A0 =C2=A0MemoryRegion control; > +} State; Please use BackdoorState. > + > + > +static uint64_t control_io_read(void *opaque, target_phys_addr_t addr, u= nsigned size) > +{ > + =C2=A0 =C2=A0State *s =3D opaque; > + > + =C2=A0 =C2=A0uint64_t res =3D ldq_p(&s->size); > + =C2=A0 =C2=A0uint8_t *resb =3D (uint8_t*)&res; > + =C2=A0 =C2=A0return resb[addr % CTRL_BYTES]; I don't think these lines do what you mean, but I'm also not sure what it is supposed to mean. > +} > + > +static void control_io_write(void *opaque, target_phys_addr_t addr, uint= 64_t data, unsigned size) > +{ > + =C2=A0 =C2=A0State *s =3D opaque; > + > + =C2=A0 =C2=A0uint8_t *cmdb =3D (uint8_t*)&s->cmd; > + =C2=A0 =C2=A0cmdb[addr % CTRL_BYTES] =3D (uint8_t)data; > + > + =C2=A0 =C2=A0if ((addr + size) % CTRL_BYTES =3D=3D 0) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0qemu_backdoor(ldq_p(&s->cmd), s->data_ptr); > + =C2=A0 =C2=A0} Same here. > +} > + > +static const MemoryRegionOps control_ops =3D { > + =C2=A0 =C2=A0.read =3D control_io_read, > + =C2=A0 =C2=A0.write =3D control_io_write, > + =C2=A0 =C2=A0.endianness =3D DEVICE_NATIVE_ENDIAN, > + =C2=A0 =C2=A0.impl =3D { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0.min_access_size =3D 1, > + =C2=A0 =C2=A0 =C2=A0 =C2=A0.max_access_size =3D 1, > + =C2=A0 =C2=A0}, > +}; > + > + > +static int init(PCIDevice *dev) > +{ > + =C2=A0 =C2=A0State *s =3D DO_UPCAST(State, dev, dev); > + > + =C2=A0 =C2=A0if (s->pages < 1) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0fprintf(stderr, "error: backdoor: " > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"the data channe= l must have one or more pages\n"); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0return -1; > + =C2=A0 =C2=A0} > + =C2=A0 =C2=A0s->size =3D s->pages * PAGE_SIZE; > + > + =C2=A0 =C2=A0pci_set_word(s->dev.config + PCI_COMMAND, > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 PCI_COMMAND_IO = | PCI_COMMAND_MEMORY); > + > + =C2=A0 =C2=A0memory_region_init_io(&s->control, &control_ops, s, "backd= oor.control", > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0PAGE_SIZE); > + =C2=A0 =C2=A0pci_register_bar(&s->dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY= , &s->control); > + > + =C2=A0 =C2=A0memory_region_init_ram(&s->data, &s->dev.qdev, "backdoor.d= ata", > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 s->size); > + =C2=A0 =C2=A0pci_register_bar(&s->dev, 1, PCI_BASE_ADDRESS_SPACE_MEMORY= , &s->data); > + =C2=A0 =C2=A0s->data_ptr =3D qemu_get_ram_ptr(s->data.ram_addr); > + > + =C2=A0 =C2=A0qemu_backdoor_init(s->size); > + > + =C2=A0 =C2=A0return 0; > +} > + > +static int fini(PCIDevice *dev) > +{ > + =C2=A0 =C2=A0State *s =3D DO_UPCAST(State, dev, dev); > + > + =C2=A0 =C2=A0memory_region_destroy(&s->data); > + =C2=A0 =C2=A0memory_region_destroy(&s->control); > + > + =C2=A0 =C2=A0return 0; > +} > + > + > +static PCIDeviceInfo info =3D { > + =C2=A0 =C2=A0.qdev.name =C2=A0=3D "backdoor", > + =C2=A0 =C2=A0.qdev.desc =C2=A0=3D "Backdoor communication channel", > + =C2=A0 =C2=A0.qdev.size =C2=A0=3D sizeof(State), > + =C2=A0 =C2=A0.init =C2=A0 =C2=A0 =C2=A0 =3D init, > + =C2=A0 =C2=A0.exit =C2=A0 =C2=A0 =C2=A0 =3D fini, > + =C2=A0 =C2=A0.vendor_id =C2=A0=3D PCI_VENDOR_ID_REDHAT_QUMRANET, > + =C2=A0 =C2=A0.device_id =C2=A0=3D PCI_DEVICE_ID_BACKDOOR, > + =C2=A0 =C2=A0.class_id =C2=A0 =3D PCI_CLASS_MEMORY_RAM, > + =C2=A0 =C2=A0.qdev.props =3D (Property[]) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0DEFINE_PROP_UINT8("pages", State, pages, 1), > + =C2=A0 =C2=A0 =C2=A0 =C2=A0DEFINE_PROP_END_OF_LIST(), > + =C2=A0 =C2=A0} > +}; > + > +static void register_device(void) > +{ > + =C2=A0 =C2=A0pci_qdev_register(&info); > +} > + > +device_init(register_device) > diff --git a/hw/pci.h b/hw/pci.h > index 86a81c8..4d7d161 100644 > --- a/hw/pci.h > +++ b/hw/pci.h > @@ -75,6 +75,7 @@ > =C2=A0#define PCI_DEVICE_ID_VIRTIO_BLOCK =C2=A0 =C2=A0 =C2=A0 0x1001 > =C2=A0#define PCI_DEVICE_ID_VIRTIO_BALLOON =C2=A0 =C2=A0 0x1002 > =C2=A0#define PCI_DEVICE_ID_VIRTIO_CONSOLE =C2=A0 =C2=A0 0x1003 > +#define PCI_DEVICE_ID_BACKDOOR =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0x1004 > > =C2=A0#define FMT_PCIBUS =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0PRIx64 > > > >