From patchwork Tue May 7 14:16:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 242335 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D698D2C00AD for ; Wed, 8 May 2013 00:48:36 +1000 (EST) Received: from localhost ([::1]:60978 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZix7-0006y3-SS for incoming@patchwork.ozlabs.org; Tue, 07 May 2013 10:33:13 -0400 Received: from eggs.gnu.org ([208.118.235.92]:33371) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZiuN-000435-9X for qemu-devel@nongnu.org; Tue, 07 May 2013 10:30:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UZiuK-0002Bh-Vo for qemu-devel@nongnu.org; Tue, 07 May 2013 10:30:23 -0400 Received: from mail-wi0-x236.google.com ([2a00:1450:400c:c05::236]:45166) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZiie-0005v7-AS for qemu-devel@nongnu.org; Tue, 07 May 2013 10:18:16 -0400 Received: by mail-wi0-f182.google.com with SMTP id m6so693836wiv.3 for ; Tue, 07 May 2013 07:18:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=tTcJWIWOJLGa9LHeBP2aiOjxgUP147jNBy6YpJmQfeY=; b=KxQGOL3DJKYs/JevlrDNFBrVLb0jCRTg886c8Gth/Xnx645c3LHT+lpse2zYOCLORF LnDFEEnLUtimyCWYNqTDwFF9CoSN5oT1Lm+MyAQ8wrh2gA9BSLGfyzFP1c/t9va4DR19 LrJJ5s7GmYgt+7ubNsFV6Bfm7QjcenT7XqbhYjXyVvy+znNubM+G0PQtmcSVNLDEqepf fLIJeDQMhHqstRNbq/3yYRYRNQc9ojlUBRrH2Be/5ljawtvXEUEInGG+ur6WH56Rtz3v DNW7i/fV5gIom1ewQhibYBS6ERDaBtq8oEznc6+M2ES3z/cT3vrt8oI20CrKGsDo5gJK YePg== X-Received: by 10.180.13.179 with SMTP id i19mr3721831wic.18.1367936295663; Tue, 07 May 2013 07:18:15 -0700 (PDT) Received: from localhost.localdomain (93-34-176-20.ip50.fastwebnet.it. [93.34.176.20]) by mx.google.com with ESMTPSA id ge7sm3335978wib.6.2013.05.07.07.18.13 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 07 May 2013 07:18:14 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 7 May 2013 16:16:55 +0200 Message-Id: <1367936238-12196-18-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1367936238-12196-1-git-send-email-pbonzini@redhat.com> References: <1367936238-12196-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::236 Cc: aik@ozlabs.ru, jan.kiszka@siemens.com, qemulist@gmail.com, stefanha@redhat.com, david@gibson.dropbear.id.au Subject: [Qemu-devel] [PATCH 17/40] spapr: make IOMMU translation go through IOMMUTLBEntry X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The next step is to introduce the translation code that will be used for IOMMU MemoryRegions, but still do the actual translation in a DMAContext. Acked-by: David Gibson Signed-off-by: Paolo Bonzini --- hw/ppc/spapr_iommu.c | 57 ++++++++++++++++++++++++++++---------------------- 1 files changed, 32 insertions(+), 25 deletions(-) diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c index 7a507e0..45fb81d 100644 --- a/hw/ppc/spapr_iommu.c +++ b/hw/ppc/spapr_iommu.c @@ -68,15 +68,8 @@ static sPAPRTCETable *spapr_tce_find_by_liobn(uint32_t liobn) return NULL; } -static int spapr_tce_translate(DMAContext *dma, - dma_addr_t addr, - hwaddr *paddr, - hwaddr *len, - DMADirection dir) +static IOMMUTLBEntry spapr_tce_translate_iommu(sPAPRTCETable *tcet, hwaddr addr) { - sPAPRTCETable *tcet = DO_UPCAST(sPAPRTCETable, dma, dma); - enum sPAPRTCEAccess access = (dir == DMA_DIRECTION_FROM_DEVICE) - ? SPAPR_TCE_WO : SPAPR_TCE_RO; uint64_t tce; #ifdef DEBUG_TCE @@ -85,9 +78,11 @@ static int spapr_tce_translate(DMAContext *dma, #endif if (tcet->bypass) { - *paddr = addr; - *len = (hwaddr)-1; - return 0; + return (IOMMUTLBEntry) { + .translated_addr = 0, + .addr_mask = ~(hwaddr)0, + .perm = { true, true }, + }; } /* Check if we are in bound */ @@ -95,28 +90,40 @@ static int spapr_tce_translate(DMAContext *dma, #ifdef DEBUG_TCE fprintf(stderr, "spapr_tce_translate out of bounds\n"); #endif - return -EFAULT; + return (IOMMUTLBEntry) { .perm = { false, false } }; } tce = tcet->table[addr >> SPAPR_TCE_PAGE_SHIFT].tce; - /* Check TCE */ - if (!(tce & access)) { - return -EPERM; - } +#ifdef DEBUG_TCE + fprintf(stderr, " -> *paddr=0x%llx, *len=0x%llx\n", + (tce & ~SPAPR_TCE_PAGE_MASK), SPAPR_TCE_PAGE_MASK + 1); +#endif - /* How much til end of page ? */ - *len = ((~addr) & SPAPR_TCE_PAGE_MASK) + 1; + return (IOMMUTLBEntry) { + .translated_addr = tce & ~SPAPR_TCE_PAGE_MASK, + .addr_mask = SPAPR_TCE_PAGE_MASK, + .perm = { [0] = tce & SPAPR_TCE_RO, [1] = tce & SPAPR_TCE_WO }, + }; +} - /* Translate */ - *paddr = (tce & ~SPAPR_TCE_PAGE_MASK) | - (addr & SPAPR_TCE_PAGE_MASK); +static int spapr_tce_translate(DMAContext *dma, + dma_addr_t addr, + hwaddr *paddr, + hwaddr *len, + DMADirection dir) + { + sPAPRTCETable *tcet = DO_UPCAST(sPAPRTCETable, dma, dma); + bool is_write = (dir == DMA_DIRECTION_FROM_DEVICE); + IOMMUTLBEntry entry = spapr_tce_translate_iommu(tcet, addr); -#ifdef DEBUG_TCE - fprintf(stderr, " -> *paddr=0x" TARGET_FMT_plx ", *len=0x" - TARGET_FMT_plx "\n", *paddr, *len); -#endif + if (!entry.perm[is_write]) { + return -EPERM; + } + /* Translate */ + *paddr = entry.translated_addr | (addr & entry.addr_mask); + *len = (addr | entry.addr_mask) - addr + 1; return 0; }