From patchwork Fri May 16 10:53:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiejun Chen X-Patchwork-Id: 349566 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7901E140094 for ; Fri, 16 May 2014 20:55:53 +1000 (EST) Received: from localhost ([::1]:34740 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WlFnr-0005XJ-G3 for incoming@patchwork.ozlabs.org; Fri, 16 May 2014 06:55:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47332) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WlFn4-0004En-6m for qemu-devel@nongnu.org; Fri, 16 May 2014 06:55:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WlFmw-0001af-R5 for qemu-devel@nongnu.org; Fri, 16 May 2014 06:55:02 -0400 Received: from mga01.intel.com ([192.55.52.88]:62789) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WlFmw-0001ab-Ld for qemu-devel@nongnu.org; Fri, 16 May 2014 06:54:54 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 16 May 2014 03:54:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="4.97,1066,1389772800"; d="scan'208"; a="540167970" Received: from tchen0-linux.bj.intel.com ([10.238.154.58]) by fmsmga002.fm.intel.com with ESMTP; 16 May 2014 03:54:51 -0700 From: Tiejun Chen To: anthony.perard@citrix.com, stefano.stabellini@eu.citrix.com, mst@redhat.com, Kelly.Zytaruk@amd.com Date: Fri, 16 May 2014 18:53:38 +0800 Message-Id: <1400237624-8505-3-git-send-email-tiejun.chen@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1400237624-8505-1-git-send-email-tiejun.chen@intel.com> References: <1400237624-8505-1-git-send-email-tiejun.chen@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.88 Cc: peter.maydell@linaro.org, xen-devel@lists.xensource.com, weidong.han@intel.com, allen.m.kay@intel.com, qemu-devel@nongnu.org, jean.guyader@eu.citrix.com, anthony@codemonkey.ws, yang.z.zhang@Intel.com Subject: [Qemu-devel] [v2][PATCH 2/8] pci: provide a way to reserve some specific devfn 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 Sometime we may need to reserve some specific devfn since some vgabios or drivers have to work well with a fixed bdf. Signed-off-by: Tiejun Chen --- v2: * New patch hw/pci/pci.c | 11 +++++++++++ include/hw/pci/pci.h | 1 + 2 files changed, 12 insertions(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index ef944cf..06b0c92 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -813,6 +813,17 @@ static void do_pci_unregister_device(PCIDevice *pci_dev) memory_region_destroy(&pci_dev->bus_master_enable_region); } + +void pci_reserve_pci_devfn(PCIBus *bus, uint8_t devfn) +{ + int ret = test_and_set_bit(devfn, bus->pci_bdf_bitmap); + if (ret) { + error_report("PCI: %02x:%02x:%02x is not available to reserve.", + pci_bus_num(bus), PCI_SLOT(devfn), PCI_FUNC(devfn)); + return; + } +} + /* -1 for devfn means auto assign */ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, const char *name, int devfn) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 8c25ae5..cbb174e 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -342,6 +342,7 @@ void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent, MemoryRegion *address_space_mem, MemoryRegion *address_space_io, uint8_t devfn_min, const char *typename); +void pci_reserve_pci_devfn(PCIBus *bus, uint8_t devfn); PCIBus *pci_bus_new(DeviceState *parent, const char *name, MemoryRegion *address_space_mem, MemoryRegion *address_space_io,