From patchwork Mon Apr 22 08:02:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 238358 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 1AD9F2C0124 for ; Mon, 22 Apr 2013 18:04:46 +1000 (EST) Received: from localhost ([::1]:34148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUBjw-0003LM-83 for incoming@patchwork.ozlabs.org; Mon, 22 Apr 2013 04:04:44 -0400 Received: from eggs.gnu.org ([208.118.235.92]:40108) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUBiP-0001d5-4O for qemu-devel@nongnu.org; Mon, 22 Apr 2013 04:03:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UUBiK-0006ke-B3 for qemu-devel@nongnu.org; Mon, 22 Apr 2013 04:03:09 -0400 Received: from mail-pd0-f176.google.com ([209.85.192.176]:44372) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUBiK-0006kU-3C for qemu-devel@nongnu.org; Mon, 22 Apr 2013 04:03:04 -0400 Received: by mail-pd0-f176.google.com with SMTP id r11so3367190pdi.21 for ; Mon, 22 Apr 2013 01:03:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=MdB07FY5y7iBvLX/0XgIXTgFqu7OPuLrCteEkOXvBSw=; b=Y3A3tP11G1/rVs/lAHKrqFZnxI7vtqorHGyXHfU2kvOoQzUPilCe3Zp4co9kHAHQOf wvYGv+poguFjkSP2tRMfhmo6bYlr8TRWo2bEnJ+WiKTht+4TMmP8bSy3QiS2p7tnewpx qRzTFNXsyodyziYVplRoHWt99mRekpJOx6irA+hY+xcBkhjmUjIq+RLKgxSh718ubthW K5uyMOG/11eDH2i1WIZIOSBvO9O5itnrdaiscLiGyv/XZd3bw9luhAGGCtHXttucUrl3 svfjX3d4IlYB7KEhiq7tCSUM0pIsbfYYKF226ps7Qh11h+cVea5XrImxuE4qF6TVNkX3 nNFQ== X-Received: by 10.68.113.101 with SMTP id ix5mr31691993pbb.142.1366617783392; Mon, 22 Apr 2013 01:03:03 -0700 (PDT) Received: from ka1.ozlabs.ibm.com (ibmaus65.lnk.telstra.net. [165.228.126.9]) by mx.google.com with ESMTPS id to7sm26152009pab.0.2013.04.22.01.02.57 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 22 Apr 2013 01:03:01 -0700 (PDT) From: Alexey Kardashevskiy To: Alex Williamson Date: Mon, 22 Apr 2013 18:02:36 +1000 Message-Id: <1366617757-6604-3-git-send-email-aik@ozlabs.ru> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1366617757-6604-1-git-send-email-aik@ozlabs.ru> References: <1366617757-6604-1-git-send-email-aik@ozlabs.ru> X-Gm-Message-State: ALoCoQk2i9Q2vw5HnGAHrkH/a4WsrvRQC72IETRlwEE8DrZI8qXfTFw7p3QeD3+BBgBug1TotI4G X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.192.176 Cc: Alexey Kardashevskiy , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, David Gibson Subject: [Qemu-devel] [PATCH 2/3] vfio: add support for spapr platform (powerpc64 server) 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 existing code assumes that containers are capable of multiple groups support which is not the case for POWERPC64 where groups are defined by the hardware configuration and cannot share one container. The earlier proposal for PPC64 support was: - spapr_phb_vfio_init(): create a spapr-pci-vfio-host-bridge, IOMMU ID is already known at this stage; - spapr_pci_vfio_scan(): start scanning the group and adding devices; - vfio_initfn(): the VFIO device init function allocates a group struct (if not yet); - vfio_get_group(): a group struct allocator allocates a container (if not yet); - vfio_connect_container(): connects a group to a container, requests POWERPC64 specific properties and calls a callback to spapr_pci.c passing those properties. As the group ID is knows from the very beginning (as it is supplied via the command line), it makes more sense to create group and container structs first and then add devices from this group. In order to achieve this, this patch adds a vfio_container_spapr_alloc() function which allocates sPAPR container and returns its properties which are a DMA window size and start. Cc: David Gibson Signed-off-by: Alexey Kardashevskiy --- hw/misc/vfio.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/misc/vfio.h | 3 ++ 2 files changed, 82 insertions(+) diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c index 503125e..adcbb80 100644 --- a/hw/misc/vfio.c +++ b/hw/misc/vfio.c @@ -2684,6 +2684,85 @@ static int vfio_connect_container(VFIOGroup *group) return 0; } +VFIOContainer *vfio_container_spapr_alloc(VFIOGroup *group, + struct vfio_iommu_spapr_tce_info *info) +{ + VFIOContainer *container; + int ret, fd; + + if (group->container) { + return NULL; + } + + fd = qemu_open("/dev/vfio/vfio", O_RDWR); + if (fd < 0) { + error_report("vfio: failed to open /dev/vfio/vfio: %m"); + return NULL; + } + + ret = ioctl(fd, VFIO_GET_API_VERSION); + if (ret != VFIO_API_VERSION) { + error_report("vfio: supported vfio version: %d, " + "reported version: %d", VFIO_API_VERSION, ret); + close(fd); + return NULL; + } + + container = g_malloc0(sizeof(*container)); + container->fd = fd; + + if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_SPAPR_TCE_IOMMU)) { + ret = ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &fd); + if (ret) { + error_report("vfio: failed to set group container: %s", + strerror(errno)); + g_free(container); + close(fd); + return NULL; + } + + ret = ioctl(fd, VFIO_SET_IOMMU, VFIO_SPAPR_TCE_IOMMU); + if (ret) { + error_report("vfio: failed to set iommu for container: %s", + strerror(errno)); + g_free(container); + close(fd); + return NULL; + } + + ret = ioctl(fd, VFIO_IOMMU_SPAPR_TCE_GET_INFO, info); + if (ret) { + error_report("vfio: failed to get iommu info for container: %s", + strerror(errno)); + g_free(container); + close(fd); + return NULL; + } + + ret = ioctl(container->fd, VFIO_IOMMU_ENABLE); + if (ret) { + error_report("vfio: failed to enable container: %s", + strerror(errno)); + g_free(container); + close(fd); + return NULL; + } + } else { + error_report("vfio: No available IOMMU models"); + g_free(container); + close(fd); + return NULL; + } + + QLIST_INIT(&container->group_list); + QLIST_INSERT_HEAD(&container_list, container, next); + + group->container = container; + QLIST_INSERT_HEAD(&container->group_list, group, container_next); + + return container; +} + static void vfio_disconnect_container(VFIOGroup *group) { VFIOContainer *container = group->container; diff --git a/include/hw/misc/vfio.h b/include/hw/misc/vfio.h index f39aef8..d1c7ff1 100644 --- a/include/hw/misc/vfio.h +++ b/include/hw/misc/vfio.h @@ -14,4 +14,7 @@ extern int vfio_dma_map(struct VFIOContainer *container, hwaddr iova, extern struct VFIOGroup *vfio_get_group(int groupid, bool connect); +extern struct VFIOContainer *vfio_container_spapr_alloc(struct VFIOGroup *group, + struct vfio_iommu_spapr_tce_info *info); + #endif