From patchwork Wed Apr 7 08:04:05 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 49576 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 47D65B7D54 for ; Wed, 7 Apr 2010 18:33:29 +1000 (EST) Received: from localhost ([127.0.0.1]:53959 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NzQhS-0002qd-6A for incoming@patchwork.ozlabs.org; Wed, 07 Apr 2010 04:33:26 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NzQIk-0001pj-M6 for qemu-devel@nongnu.org; Wed, 07 Apr 2010 04:07:55 -0400 Received: from [140.186.70.92] (port=42762 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NzQIj-0001oe-43 for qemu-devel@nongnu.org; Wed, 07 Apr 2010 04:07:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NzQId-00084Q-MZ for qemu-devel@nongnu.org; Wed, 07 Apr 2010 04:07:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:63464) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NzQId-00084L-Cv for qemu-devel@nongnu.org; Wed, 07 Apr 2010 04:07:47 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3787jA1009675 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 7 Apr 2010 04:07:45 -0400 Received: from redhat.com (vpn2-11-250.ams2.redhat.com [10.36.11.250]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id o3787hkh028528; Wed, 7 Apr 2010 04:07:44 -0400 Date: Wed, 7 Apr 2010 11:04:05 +0300 From: "Michael S. Tsirkin" To: weil@mail.berlios.de, qemu-devel@nongnu.org Message-ID: <2b600ff5a3d1dd5fc1cb4c35c4403d21674b3377.1270627361.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mutt-Fcc: =sent User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Subject: [Qemu-devel] [PATCH 1/2] pci: add API to add capability at a known offset X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Unlike virtio, device emulations need to add pci capabilities at known offsets to match real hardware. Make this possible by adding an appropriate API. Signed-off-by: Michael S. Tsirkin --- hw/pci.c | 16 ++++++++++++---- hw/pci.h | 2 ++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 0dbca17..df03149 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -1789,12 +1789,10 @@ static int pci_add_option_rom(PCIDevice *pdev) } /* Reserve space and add capability to the linked list in pci config space */ -int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size) +int pci_add_capability_at_offset(PCIDevice *pdev, uint8_t cap_id, + uint8_t offset, uint8_t size) { - uint8_t offset = pci_find_space(pdev, size); uint8_t *config = pdev->config + offset; - if (!offset) - return -ENOSPC; config[PCI_CAP_LIST_ID] = cap_id; config[PCI_CAP_LIST_NEXT] = pdev->config[PCI_CAPABILITY_LIST]; pdev->config[PCI_CAPABILITY_LIST] = offset; @@ -1807,6 +1805,16 @@ int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size) return offset; } +/* Find and reserve space and add capability to the linked list + * in pci config space */ +int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size) +{ + uint8_t offset = pci_find_space(pdev, size); + if (!offset) + return -ENOSPC; + return pci_add_capability_at_offset(pdev, cap_id, offset, size); +} + /* Unlink capability from the pci config space. */ void pci_del_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size) { diff --git a/hw/pci.h b/hw/pci.h index 20c670e..625188c 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -190,6 +190,8 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num, PCIMapIORegionFunc *map_func); int pci_add_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size); +int pci_add_capability_at_offset(PCIDevice *pci_dev, uint8_t cap_id, + uint8_t cap_offset, uint8_t cap_size); void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);