From patchwork Tue Jul 10 05:51:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 170051 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 83BB42C01B4 for ; Tue, 10 Jul 2012 15:52:29 +1000 (EST) Received: from localhost ([::1]:46417 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoTN5-0008Vp-AD for incoming@patchwork.ozlabs.org; Tue, 10 Jul 2012 01:52:27 -0400 Received: from eggs.gnu.org ([208.118.235.92]:57077) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoTMc-0007PG-8Y for qemu-devel@nongnu.org; Tue, 10 Jul 2012 01:51:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SoTMZ-0004GB-9R for qemu-devel@nongnu.org; Tue, 10 Jul 2012 01:51:57 -0400 Received: from mail-gh0-f173.google.com ([209.85.160.173]:61354) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SoTMZ-0004Fp-5D for qemu-devel@nongnu.org; Tue, 10 Jul 2012 01:51:55 -0400 Received: by ghrr14 with SMTP id r14so11744469ghr.4 for ; Mon, 09 Jul 2012 22:51:53 -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=ONogteP69SQqjrp+PwS/vI+1Y0tW1QftQuGbk1Nk8C0=; b=nU0eL80F6B2joAzBPe1qdNtqzZDr8fZN3rrTxA4dSl+vKtKat5z4llHmF94pB5nyC3 UeHcaB5aCYI3G3EJe5wock3OlzU0uS8iuF8xVcKj0myNG37WugYjXmVgoqkudVGnWipB 4pxZOjVCVrl3eHSt+RQ7fwN0R6R5wqCfo+sf0qgO3jymnliYRoN7QzboZkmE5h9wgpXS t3o6P6blm3hEgUR71IOrK2EU6CW8sUS7X0Njy+KbCEYKdP2b3dB83jQVbRTflx0e6F2h QTFJdyP8OaFPjIIcP2RVeMzWIfpsUg30OGHsySt7T6t7HDlDZDUg7gw2blOdkT2nqHfJ YTPQ== Received: by 10.66.76.196 with SMTP id m4mr42747133paw.61.1341899513093; Mon, 09 Jul 2012 22:51:53 -0700 (PDT) Received: from ka1.ozlabs.ibm.com (ibmaus65.lnk.telstra.net. [165.228.126.9]) by mx.google.com with ESMTPS id pg3sm29203004pbc.2.2012.07.09.22.51.50 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 09 Jul 2012 22:51:52 -0700 (PDT) From: Alexey Kardashevskiy To: Date: Tue, 10 Jul 2012 15:51:36 +1000 Message-Id: <1341899497-23265-2-git-send-email-aik@ozlabs.ru> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1341899497-23265-1-git-send-email-aik@ozlabs.ru> References: <1341899497-23265-1-git-send-email-aik@ozlabs.ru> X-Gm-Message-State: ALoCoQn0AvaSeJxuHnten8yPNjUrHzeBjSbF5/UeSJYLqR32FjDMtLErhL+hm6xkskxuoDhAYfYx X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.173 Cc: Alexey Kardashevskiy , Alexander Graf , qemu-devel@nongnu.org, Alex Williamson , qemu-ppc@nongnu.org, David Gibson Subject: [Qemu-devel] [PATCH 1/2] pseries pci: spapr_finalize_pci_setup introduced 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 PCI bus setup was done in 3 steps: 1) create a PCI bus, configure DMA 2) create PCI devices on the bus 3) populate a PCI bus node in the Device Tree As some bus parameters can be configured only when some or all the devices got attached to the bus and initialized, the spapr_finalize_pci_setup has been introduced. As an example, such a handler can setup DMA window parameters taken from an IOMMU file descriptor available from a VFIO PCI device. Signed-off-by: Alexey Kardashevskiy --- hw/spapr.c | 7 +++++++ hw/spapr_pci.c | 13 ++++++++++--- hw/spapr_pci.h | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/hw/spapr.c b/hw/spapr.c index b83f83b..688a135 100644 --- a/hw/spapr.c +++ b/hw/spapr.c @@ -516,7 +516,14 @@ static void spapr_finalize_fdt(sPAPREnvironment *spapr, } QLIST_FOREACH(phb, &spapr->phbs, list) { + ret = spapr_finalize_pci_setup(phb); + if (ret < 0) { + break; + } ret = spapr_populate_pci_dt(phb, PHANDLE_XICP, fdt); + if (ret < 0) { + break; + } } if (ret < 0) { diff --git a/hw/spapr_pci.c b/hw/spapr_pci.c index 014297b..5f89003 100644 --- a/hw/spapr_pci.c +++ b/hw/spapr_pci.c @@ -573,9 +573,6 @@ static int spapr_phb_init(SysBusDevice *s) phb->host_state.bus = bus; 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); @@ -639,6 +636,16 @@ void spapr_create_phb(sPAPREnvironment *spapr, qdev_init_nofail(dev); } +/* Finalize PCI setup, called when all devices are already created */ +int spapr_finalize_pci_setup(sPAPRPHBState *phb) +{ + phb->dma_window_start = 0; + phb->dma_window_size = 0x40000000; + phb->dma = spapr_tce_new_dma_context(phb->dma_liobn, + phb->dma_window_size); + return 0; +} + /* Macros to operate with address in OF binding to PCI */ #define b_x(x, p, l) (((x) & ((1<<(l))-1)) << (p)) #define b_n(x) b_x((x), 31, 1) /* 0 if relocatable */ diff --git a/hw/spapr_pci.h b/hw/spapr_pci.h index 145071c..3aae273 100644 --- a/hw/spapr_pci.h +++ b/hw/spapr_pci.h @@ -68,6 +68,8 @@ void spapr_create_phb(sPAPREnvironment *spapr, uint64_t mem_win_addr, uint64_t mem_win_size, uint64_t io_win_addr, uint64_t msi_win_addr); +int spapr_finalize_pci_setup(sPAPRPHBState *phb); + int spapr_populate_pci_dt(sPAPRPHBState *phb, uint32_t xics_phandle, void *fdt);