From patchwork Tue Jul 10 13:46:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 170193 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 3E90A2C01B4 for ; Wed, 11 Jul 2012 00:17:22 +1000 (EST) Received: from localhost ([::1]:44735 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoanB-00034b-FS for incoming@patchwork.ozlabs.org; Tue, 10 Jul 2012 09:47:53 -0400 Received: from eggs.gnu.org ([208.118.235.92]:52985) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Soam6-0008Rf-Ux for qemu-devel@nongnu.org; Tue, 10 Jul 2012 09:46:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Soam1-000173-BH for qemu-devel@nongnu.org; Tue, 10 Jul 2012 09:46:46 -0400 Received: from mail-yx0-f173.google.com ([209.85.213.173]:33674) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Soam1-00016d-7H for qemu-devel@nongnu.org; Tue, 10 Jul 2012 09:46:41 -0400 Received: by yenl1 with SMTP id l1so12163749yen.4 for ; Tue, 10 Jul 2012 06:46:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=gX4RKq/eciDHqE2+xLHcarRYzC1qBIxePO+5c8KBVzE=; b=I1q7OHjk71BmqWdLrt2eugLRJJRe2nES2oHpGjm0xL5gw6EBwmp9OAPGC2xFsMoEMr oNIfKiKHwOEBGkSqkaC3PiuZKwxKwCqy01X+30ksSQgtFB6rQiLh5Hr5MTLx1TUI4SHD fnwlTBwxuh8R9sDxX3eOA/vel68AbTh/CylE8oqhppKHXNsKU2yJsThnzEK2DqKoRk8C HlQd6u8zi7ki5w/6Uso2T996Lo7cvc6mWT2246LmoCj/Hh5eB6rxxwB2UelTpWauoJA/ hq1hG1bKFgxijSbnNaFXL8TzePj4a0MzUpI3FsBC3L2oXX4sBXehuIspi3BGuRus5JcA PbUw== Received: by 10.68.203.73 with SMTP id ko9mr70239315pbc.66.1341927999090; Tue, 10 Jul 2012 06:46:39 -0700 (PDT) Received: from ka1.ozlabs.ibm.com (ibmaus65.lnk.telstra.net. [165.228.126.9]) by mx.google.com with ESMTPS id pz9sm8349748pbb.61.2012.07.10.06.46.36 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 10 Jul 2012 06:46:38 -0700 (PDT) From: Alexey Kardashevskiy To: Date: Tue, 10 Jul 2012 23:46:13 +1000 Message-Id: <1341927973-5615-6-git-send-email-aik@ozlabs.ru> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1341927973-5615-1-git-send-email-aik@ozlabs.ru> References: <1341927973-5615-1-git-send-email-aik@ozlabs.ru> X-Gm-Message-State: ALoCoQm9BLLcwYTm9SvT9TwcylRclmds45MeFDu10kSLQdD9aZH4o3h46BMIR1MEpUefcb+xoTlI X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.213.173 Cc: Alexey Kardashevskiy , qemu-devel@nongnu.org, Alexander Graf , qemu-ppc@nongnu.org, David Gibson Subject: [Qemu-devel] [PATCH] pseries dma: DMA window params added to PHB and DT population changed 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 Previously the only PCI bus supported was the emulated PCI bus with fixed DMA window with start at 0 and size 1GB. As we are going to support PCI pass through which DMA window properties are set by the host kernel, we have to support DMA windows with parameters other than default. This patch adds: 1. DMA window properties to sPAPRPHBState: LIOBN (bus id), start, size of the window. 2. An additional function spapr_dma_dt() to populate DMA window properties in the device tree which simply accepts all the parameters and does not try to guess what kind of IOMMU is given to it. The original spapr_dma_dt() is renamed to spapr_tcet_dma_dt(). Signed-off-by: Alexey Kardashevskiy --- hw/spapr.h | 4 +++- hw/spapr_iommu.c | 58 ++++++++++++++++++++++++++++++++++-------------------- hw/spapr_pci.c | 11 +++++++---- hw/spapr_pci.h | 6 ++++++ hw/spapr_vio.c | 2 +- 5 files changed, 54 insertions(+), 27 deletions(-) diff --git a/hw/spapr.h b/hw/spapr.h index 4a3520f..b37f337 100644 --- a/hw/spapr.h +++ b/hw/spapr.h @@ -336,6 +336,8 @@ void spapr_iommu_init(void); DMAContext *spapr_tce_new_dma_context(uint32_t liobn, size_t window_size); void spapr_tce_free(DMAContext *dma); int spapr_dma_dt(void *fdt, int node_off, const char *propname, - DMAContext *dma); + uint32_t liobn, uint64_t window, uint32_t size); +int spapr_tcet_dma_dt(void *fdt, int node_off, const char *propname, + DMAContext *dma); #endif /* !defined (__HW_SPAPR_H__) */ diff --git a/hw/spapr_iommu.c b/hw/spapr_iommu.c index 3021bfe..50c288d 100644 --- a/hw/spapr_iommu.c +++ b/hw/spapr_iommu.c @@ -221,31 +221,47 @@ void spapr_iommu_init(void) } int spapr_dma_dt(void *fdt, int node_off, const char *propname, - DMAContext *dma) + uint32_t liobn, uint64_t window, uint32_t size) { - if (dma) { - sPAPRTCETable *tcet = DO_UPCAST(sPAPRTCETable, dma, dma); - uint32_t dma_prop[] = {cpu_to_be32(tcet->liobn), - 0, 0, - 0, cpu_to_be32(tcet->window_size)}; - int ret; - - ret = fdt_setprop_cell(fdt, node_off, "ibm,#dma-address-cells", 2); - if (ret < 0) { - return ret; - } + uint32_t dma_prop[5]; + int ret; - ret = fdt_setprop_cell(fdt, node_off, "ibm,#dma-size-cells", 2); - if (ret < 0) { - return ret; - } + dma_prop[0] = cpu_to_be32(liobn); + dma_prop[1] = cpu_to_be32(window >> 32); + dma_prop[2] = cpu_to_be32(window & 0xFFFFFFFF); + dma_prop[3] = 0; /* window size is 32 bits */ + dma_prop[4] = cpu_to_be32(size); - ret = fdt_setprop(fdt, node_off, propname, dma_prop, - sizeof(dma_prop)); - if (ret < 0) { - return ret; - } + 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, propname, dma_prop, sizeof(dma_prop)); + if (ret < 0) { + return ret; } return 0; } + +int spapr_tcet_dma_dt(void *fdt, int node_off, const char *propname, + DMAContext *iommu) +{ + if (!iommu) { + return 0; + } + + if (iommu->translate == spapr_tce_translate) { + sPAPRTCETable *tcet = DO_UPCAST(sPAPRTCETable, dma, iommu); + return spapr_dma_dt(fdt, node_off, propname, + tcet->liobn, 0, tcet->window_size); + } + + return -1; +} diff --git a/hw/spapr_pci.c b/hw/spapr_pci.c index 7a17d54..f98cd7e 100644 --- a/hw/spapr_pci.c +++ b/hw/spapr_pci.c @@ -282,7 +282,6 @@ static int spapr_phb_init(SysBusDevice *s) char *namebuf; int i; PCIBus *bus; - uint32_t liobn; phb->dtbusname = g_strdup_printf("pci@%" PRIx64, phb->buid); namebuf = alloca(strlen(phb->dtbusname) + 32); @@ -323,8 +322,10 @@ static int spapr_phb_init(SysBusDevice *s) PCI_DEVFN(0, 0), PCI_NUM_PINS); phb->host_state.bus = bus; - liobn = SPAPR_PCI_BASE_LIOBN | (pci_find_domain(bus) << 16); - phb->dma = spapr_tce_new_dma_context(liobn, 0x40000000); + phb->dma_liobn = SPAPR_PCI_BASE_LIOBN | (pci_find_domain(bus) << 16); + phb->dma_window_start = 0; + phb->dma_window_size = 0x40000000; + phb->dma = spapr_tce_new_dma_context(phb->dma_liobn, phb->dma_window_size); pci_setup_iommu(bus, spapr_pci_dma_context_fn, phb); QLIST_INSERT_HEAD(&spapr->phbs, phb, list); @@ -476,7 +477,9 @@ int spapr_populate_pci_dt(sPAPRPHBState *phb, _FDT(fdt_setprop(fdt, bus_off, "interrupt-map", &interrupt_map, sizeof(interrupt_map))); - spapr_dma_dt(fdt, bus_off, "ibm,dma-window", phb->dma); + spapr_dma_dt(fdt, bus_off, "ibm,dma-window", + phb->dma_liobn, phb->dma_window_start, + phb->dma_window_size); return 0; } diff --git a/hw/spapr_pci.h b/hw/spapr_pci.h index 05447b4..e54809a 100644 --- a/hw/spapr_pci.h +++ b/hw/spapr_pci.h @@ -37,6 +37,12 @@ typedef struct sPAPRPHBState { MemoryRegion memspace, iospace; target_phys_addr_t mem_win_addr, mem_win_size, io_win_addr, io_win_size; MemoryRegion memwindow, iowindow; + target_phys_addr_t msi_win_addr; + MemoryRegion msiwindow; + + uint32_t dma_liobn; + uint64_t dma_window_start; + uint64_t dma_window_size; DMAContext *dma; struct { diff --git a/hw/spapr_vio.c b/hw/spapr_vio.c index 05b5503..c734eb4 100644 --- a/hw/spapr_vio.c +++ b/hw/spapr_vio.c @@ -142,7 +142,7 @@ static int vio_make_devnode(VIOsPAPRDevice *dev, } } - ret = spapr_dma_dt(fdt, node_off, "ibm,my-dma-window", dev->dma); + ret = spapr_tcet_dma_dt(fdt, node_off, "ibm,my-dma-window", dev->dma); if (ret < 0) { return ret; }