From patchwork Mon May 5 01:27:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 4111411 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2E5259F23C for ; Mon, 5 May 2014 01:29:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5795A2037A for ; Mon, 5 May 2014 01:29:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 752C720254 for ; Mon, 5 May 2014 01:29:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754043AbaEEB2A (ORCPT ); Sun, 4 May 2014 21:28:00 -0400 Received: from e23smtp05.au.ibm.com ([202.81.31.147]:46061 "EHLO e23smtp05.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753924AbaEEB16 (ORCPT ); Sun, 4 May 2014 21:27:58 -0400 Received: from /spool/local by e23smtp05.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 5 May 2014 11:27:56 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp05.au.ibm.com (202.81.31.211) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 5 May 2014 11:27:54 +1000 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [9.190.235.152]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 14A1A2CE8056; Mon, 5 May 2014 11:27:54 +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 s4516cl21311004; Mon, 5 May 2014 11:06:38 +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 s451RqAn013655; Mon, 5 May 2014 11:27:53 +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 s451RqxQ013652; Mon, 5 May 2014 11:27:52 +1000 Received: from shangw (haven.au.ibm.com [9.190.164.82]) by ozlabs.au.ibm.com (Postfix) with ESMTP id 7A082A0117; Mon, 5 May 2014 11:27:52 +1000 (EST) Received: by shangw (Postfix, from userid 1000) id 68F913E0370; Mon, 5 May 2014 11:28:14 +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 03/22] powerpc/eeh: Search EEH device by guest address Date: Mon, 5 May 2014 11:27:52 +1000 Message-Id: <1399253291-3975-4-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-1396-0000-0000-000004C7F980 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 patch introduces function eeh_vfio_dev_get() to search the EEH device according to its guest address, which is made up of VM indicator, PHB BUID, bus, slot and function number. The function is useful in the backends for EEH RTAS emulation. Signed-off-by: Gavin Shan --- arch/powerpc/include/asm/eeh.h | 6 ++++++ arch/powerpc/kernel/eeh_pe.c | 45 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/arch/powerpc/include/asm/eeh.h b/arch/powerpc/include/asm/eeh.h index 8bfb167..b12e3e9 100644 --- a/arch/powerpc/include/asm/eeh.h +++ b/arch/powerpc/include/asm/eeh.h @@ -384,6 +384,12 @@ static inline void eeh_remove_device(struct pci_dev *dev) { } #define EEH_IO_ERROR_VALUE(size) (-1UL) #endif /* CONFIG_EEH */ + +#ifdef CONFIG_KVM_EEH +struct eeh_dev *eeh_vfio_dev_get(struct eeh_vfio_pci_addr *addr); + +#endif /* CONFIG_KVM_EEH */ + #ifdef CONFIG_PPC64 /* * MMIO read/write operations with EEH support. diff --git a/arch/powerpc/kernel/eeh_pe.c b/arch/powerpc/kernel/eeh_pe.c index fbd01eb..dba7c82 100644 --- a/arch/powerpc/kernel/eeh_pe.c +++ b/arch/powerpc/kernel/eeh_pe.c @@ -248,6 +248,51 @@ struct eeh_pe *eeh_pe_get(struct eeh_dev *edev) return pe; } +#ifdef CONFIG_KVM_EEH +static void *__eeh_vfio_dev_get(void *data, void *flag) +{ + struct eeh_pe *pe = (struct eeh_pe *)data; + struct eeh_vfio_pci_addr *addr = (struct eeh_vfio_pci_addr *)flag; + struct eeh_dev *edev, *tmp; + + eeh_pe_for_each_dev(pe, edev, tmp) { + if (!eeh_dev_passed(edev)) + continue; + + /* Comparing the address in the guest */ + if (addr->kvm == edev->gaddr.kvm && + addr->buid_hi == edev->gaddr.buid_hi && + addr->buid_lo == edev->gaddr.buid_lo && + addr->bus == edev->gaddr.bus && + addr->devfn == edev->gaddr.devfn) + return edev; + } + + return NULL; +} + +/** + * eeh_vfio_dev_get - Search EEH device based on guest's address + * @addr: EEH device guest address + * + * Search the EEH device according to its guest's address, which + * is made up of PHB BUID, and PCI config address. + */ +struct eeh_dev *eeh_vfio_dev_get(struct eeh_vfio_pci_addr *addr) +{ + struct eeh_pe *root; + struct eeh_dev *edev; + + list_for_each_entry(root, &eeh_phb_pe, child) { + edev = eeh_pe_traverse(root, __eeh_vfio_dev_get, addr); + if (edev) + return edev; + } + + return NULL; +} +#endif /* CONFIG_KVM_EEH */ + /** * eeh_pe_get_parent - Retrieve the parent PE * @edev: EEH device