From patchwork Mon May 5 01:27:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 4111381 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 81B6BBFF02 for ; Mon, 5 May 2014 01:28:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AD25E20254 for ; Mon, 5 May 2014 01:28:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C27492037A for ; Mon, 5 May 2014 01:28:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754212AbaEEB2t (ORCPT ); Sun, 4 May 2014 21:28:49 -0400 Received: from e23smtp04.au.ibm.com ([202.81.31.146]:53219 "EHLO e23smtp04.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754047AbaEEB2B (ORCPT ); Sun, 4 May 2014 21:28:01 -0400 Received: from /spool/local by e23smtp04.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 5 May 2014 11:28:00 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp04.au.ibm.com (202.81.31.210) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 5 May 2014 11:27:57 +1000 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [9.190.235.152]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id EB75B3578048; Mon, 5 May 2014 11:27:56 +1000 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s4516f2F55574742; Mon, 5 May 2014 11:06:41 +1000 Received: from d23av03.au.ibm.com (localhost [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s451RtLZ013749; Mon, 5 May 2014 11:27:56 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.190.163.12]) by d23av03.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s451Rtes013746; Mon, 5 May 2014 11:27:55 +1000 Received: from shangw (haven.au.ibm.com [9.190.164.82]) by ozlabs.au.ibm.com (Postfix) with ESMTP id A6377A0117; Mon, 5 May 2014 11:27:55 +1000 (EST) Received: by shangw (Postfix, from userid 1000) id 941283E0370; Mon, 5 May 2014 11:28:17 +1000 (EST) From: Gavin Shan To: linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Cc: alex.williamson@redhat.com, benh@kernel.crashing.org, aik@ozlabs.ru, qiudayu@linux.vnet.ibm.com, Gavin Shan Subject: [PATCH 10/22] powerpc/eeh: Introduce kvmppc_eeh_format_addr() Date: Mon, 5 May 2014 11:27:59 +1000 Message-Id: <1399253291-3975-11-git-send-email-gwshan@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1399253291-3975-1-git-send-email-gwshan@linux.vnet.ibm.com> References: <1399253291-3975-1-git-send-email-gwshan@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14050501-9264-0000-0000-00000601375B Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The guest will pass 2 kinds of addresses: tranditional bus/device/ function combo, and guest sensitive PE address returned from host. The patch introduces function kvmppc_eeh_format_addr() to convert the guest address information from RTAS call argument (struct rtas_args) and retrieve the EEH device or PE instance if necessary. The function will be used by subsequent patches. Signed-off-by: Gavin Shan --- arch/powerpc/platforms/powernv/eeh-rtas.c | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/arch/powerpc/platforms/powernv/eeh-rtas.c b/arch/powerpc/platforms/powernv/eeh-rtas.c index fded461..f04b820 100644 --- a/arch/powerpc/platforms/powernv/eeh-rtas.c +++ b/arch/powerpc/platforms/powernv/eeh-rtas.c @@ -39,6 +39,58 @@ #include "powernv.h" #include "pci.h" +/* + * Guest is passing 2 types of addresses. First one would be + * traditional bus/device/function combo and another one is + * PE address, which starts from 0x10000 + */ +static int kvmppc_eeh_format_addr(struct kvm_vcpu *vcpu, + struct rtas_args *args, + struct eeh_vfio_pci_addr *addr, + bool is_legacy, + struct eeh_dev **pedev, + struct eeh_pe **ppe) +{ + struct eeh_dev *edev; + struct eeh_pe *pe; + + if (pedev) *pedev = NULL; + if (ppe) *ppe = NULL; + + addr->kvm = vcpu->kvm; + addr->buid_hi = args->args[1]; + addr->buid_lo = args->args[2]; + if (is_legacy) { + addr->bus = (args->args[0] >> 16) & 0xFF; + addr->devfn = (args->args[0] >> 8) & 0xFF; + + edev = eeh_vfio_dev_get(addr); + if (!edev) { + pr_warn("%s: Can't find VFIO device " + "(%08x-%08x-%02x-%02x)\n", + __func__, addr->buid_hi, + addr->buid_lo, addr->bus, addr->devfn); + return -EEXIST; + } + + if (pedev) *pedev = edev; + if (ppe) *ppe = edev->pe; + } else { + addr->pe_addr = args->args[0]; + pe = eeh_vfio_pe_get(addr); + if (!pe) { + pr_warn("%s: Can't find PE (%08x-%08x-%x)\n", + __func__, addr->buid_hi, + addr->buid_lo, addr->pe_addr); + return -EEXIST; + } + + if (ppe) *ppe = pe; + } + + return 0; +} + /** * kvmppc_eeh_rtas - Backend for EEH RTAS emulation * @vcpu: KVM virtual CPU