From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=53077 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pzz6Q-0002Xp-Bs for qemu-devel@nongnu.org; Wed, 16 Mar 2011 18:22:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pzz6O-0004w8-Gb for qemu-devel@nongnu.org; Wed, 16 Mar 2011 18:22:01 -0400 Received: from mail-iy0-f173.google.com ([209.85.210.173]:61416) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pzz6O-0004w4-CC for qemu-devel@nongnu.org; Wed, 16 Mar 2011 18:22:00 -0400 Received: by iym7 with SMTP id 7so2446025iym.4 for ; Wed, 16 Mar 2011 15:21:59 -0700 (PDT) Message-ID: <4D8137C5.3010708@codemonkey.ws> Date: Wed, 16 Mar 2011 17:20:53 -0500 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 21/26] Implement TCE translation for sPAPR VIO References: <1300251423-6715-1-git-send-email-david@gibson.dropbear.id.au> <1300251423-6715-22-git-send-email-david@gibson.dropbear.id.au> In-Reply-To: <1300251423-6715-22-git-send-email-david@gibson.dropbear.id.au> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Gibson Cc: paulus@samba.org, agraf@suse.de, anton@samba.org, qemu-devel@nongnu.org On 03/15/2011 11:56 PM, David Gibson wrote: > From: Ben Herrenschmidt > > This patch implements the necessary infrastructure and hypercalls for > sPAPR's TCE (Translation Control Entry) IOMMU mechanism. This is necessary > for all virtual IO devices which do DMA (i.e. nearly all of them). > > Signed-off-by: Ben Herrenschmidt > Signed-off-by: David Gibson > --- > hw/spapr.c | 3 +- > hw/spapr_vio.c | 232 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > hw/spapr_vio.h | 32 ++++++++ > 3 files changed, 266 insertions(+), 1 deletions(-) > > diff --git a/hw/spapr.c b/hw/spapr.c > index e7f8864..a362889 100644 > --- a/hw/spapr.c > +++ b/hw/spapr.c > @@ -62,7 +62,8 @@ static void *spapr_create_fdt(int *fdt_size, ram_addr_t ramsize, > uint32_t start_prop = cpu_to_be32(initrd_base); > uint32_t end_prop = cpu_to_be32(initrd_base + initrd_size); > uint32_t pft_size_prop[] = {0, cpu_to_be32(hash_shift)}; > - char hypertas_prop[] = "hcall-pft\0hcall-term\0hcall-dabr\0hcall-interrupt"; > + char hypertas_prop[] = "hcall-pft\0hcall-term\0hcall-dabr\0hcall-interrupt" > + "\0hcall-tce"; > uint32_t interrupt_server_ranges_prop[] = {0, cpu_to_be32(smp_cpus)}; > int i; > char *modelname; > diff --git a/hw/spapr_vio.c b/hw/spapr_vio.c > index 45edd94..37cf51e 100644 > --- a/hw/spapr_vio.c > +++ b/hw/spapr_vio.c > @@ -37,6 +37,7 @@ > #endif /* CONFIG_FDT */ > > /* #define DEBUG_SPAPR */ > +/* #define DEBUG_TCE */ > > #ifdef DEBUG_SPAPR > #define dprintf(fmt, ...) \ > @@ -114,6 +115,28 @@ static int vio_make_devnode(VIOsPAPRDevice *dev, > return ret; > } > > + if (dev->rtce_window_size) { > + uint32_t dma_prop[] = {cpu_to_be32(dev->reg), > + 0, 0, > + 0, cpu_to_be32(dev->rtce_window_size)}; > + > + ret = fdt_setprop_cell(fdt, node_off, "ibm,#dma-address-cells", 2); > + if (ret< 0) { > + return ret; > + } > + > + ret = fdt_setprop_cell(fdt, node_off, "ibm,#dma-size-cells", 2); > + if (ret< 0) { > + return ret; > + } > + > + ret = fdt_setprop(fdt, node_off, "ibm,my-dma-window", dma_prop, > + sizeof(dma_prop)); > + if (ret< 0) { > + return ret; > + } > + } > + > if (info->devnode) { > ret = (info->devnode)(dev, fdt, node_off); > if (ret< 0) { > @@ -125,6 +148,210 @@ static int vio_make_devnode(VIOsPAPRDevice *dev, > } > #endif /* CONFIG_FDT */ > > +/* > + * RTCE handling > + */ > + > +static void rtce_init(VIOsPAPRDevice *dev) > +{ > + size_t size = (dev->rtce_window_size>> SPAPR_VIO_TCE_PAGE_SHIFT) > + * sizeof(VIOsPAPR_RTCE); > + > + if (size) { > + dev->rtce_table = qemu_mallocz(size); > + } > +} > + > +static target_ulong h_put_tce(CPUState *env, sPAPREnvironment *spapr, > + target_ulong opcode, target_ulong *args) > +{ > + target_ulong liobn = args[0]; > + target_ulong ioba = args[1]; > + target_ulong tce = args[2]; > + VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, liobn); > + VIOsPAPR_RTCE *rtce; > + > + if (!dev) { > + fprintf(stderr, "spapr_vio_put_tce on non-existent LIOBN " > + TARGET_FMT_lx "\n", > + liobn); You generally want to avoid guest triggered fprintfs as it can be exploited in scenarios where qemu's stdout is logged to disk (libvirt). We usually wrap this in a DPRINTF() of some sort. Regards, Anthony Liguori