From patchwork Mon Dec 12 03:08:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 704912 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tcSjW3tjMz9svs for ; Mon, 12 Dec 2016 14:18:55 +1100 (AEDT) Received: from localhost ([::1]:58366 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cGH8f-0002Ii-4O for incoming@patchwork.ozlabs.org; Sun, 11 Dec 2016 22:18:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55324) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cGGz6-0002y0-IQ for qemu-devel@nongnu.org; Sun, 11 Dec 2016 22:09:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cGGz5-0003Q0-QA for qemu-devel@nongnu.org; Sun, 11 Dec 2016 22:09:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36702) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cGGz5-0003Pv-KF for qemu-devel@nongnu.org; Sun, 11 Dec 2016 22:08:59 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DBAB985365; Mon, 12 Dec 2016 03:08:58 +0000 (UTC) Received: from pxdev.xzpeter.org (vpn1-5-149.pek2.redhat.com [10.72.5.149]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uBC38M83005906; Sun, 11 Dec 2016 22:08:55 -0500 From: Peter Xu To: qemu-devel@nongnu.org, kvm@vger.kernel.org Date: Mon, 12 Dec 2016 11:08:16 +0800 Message-Id: <1481512100-10380-11-git-send-email-peterx@redhat.com> In-Reply-To: <1481512100-10380-1-git-send-email-peterx@redhat.com> References: <1481512100-10380-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 12 Dec 2016 03:08:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [kvm-unit-tests PATCH v8 10/14] pci: provide pci_enable_defaults() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: drjones@redhat.com, rkrcmar@redhat.com, peterx@redhat.com, agordeev@redhat.com, jan.kiszka@web.de, pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" One helper function to set/clear specific bit in PCI_COMMAND register is introduced. Then, provide a function to do most of the common PCI init work. Suggested-by: Andrew Jones Reviewed-by: Andrew Jones Signed-off-by: Peter Xu --- lib/pci.c | 19 +++++++++++++++++++ lib/pci.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/lib/pci.c b/lib/pci.c index d4521be..bf2a3df 100644 --- a/lib/pci.c +++ b/lib/pci.c @@ -7,6 +7,18 @@ #include "pci.h" #include "asm/pci.h" +void pci_cmd_set_clr(struct pci_dev *dev, uint16_t set, uint16_t clr) +{ + uint16_t val = pci_config_readw(dev->bdf, PCI_COMMAND); + + /* No overlap is allowed */ + assert((set & clr) == 0); + val |= set; + val &= ~clr; + + pci_config_writew(dev->bdf, PCI_COMMAND, val); +} + bool pci_dev_exists(pcidevaddr_t dev) { return (pci_config_readw(dev, PCI_VENDOR_ID) != 0xffff && @@ -242,3 +254,10 @@ void pci_scan_bars(struct pci_dev *dev) } } } + +void pci_enable_defaults(struct pci_dev *dev) +{ + pci_scan_bars(dev); + /* Enable device DMA operations */ + pci_cmd_set_clr(dev, PCI_COMMAND_MASTER, 0); +} diff --git a/lib/pci.h b/lib/pci.h index 8215c9d..d3052ef 100644 --- a/lib/pci.h +++ b/lib/pci.h @@ -25,6 +25,8 @@ struct pci_dev { extern void pci_dev_init(struct pci_dev *dev, pcidevaddr_t bdf); extern void pci_scan_bars(struct pci_dev *dev); +extern void pci_cmd_set_clr(struct pci_dev *dev, uint16_t set, uint16_t clr); +extern void pci_enable_defaults(struct pci_dev *dev); extern bool pci_probe(void); extern void pci_print(void);