From patchwork Thu Jul 21 18:14:41 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 996452 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p6LIEseG002893 for ; Thu, 21 Jul 2011 18:15:13 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753111Ab1GUSOx (ORCPT ); Thu, 21 Jul 2011 14:14:53 -0400 Received: from goliath.siemens.de ([192.35.17.28]:26949 "EHLO goliath.siemens.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753094Ab1GUSOr (ORCPT ); Thu, 21 Jul 2011 14:14:47 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by goliath.siemens.de (8.13.6/8.13.6) with ESMTP id p6LIEh4M024570; Thu, 21 Jul 2011 20:14:43 +0200 Received: from mchn199C.mchp.siemens.de ([139.25.109.49]) by mail1.siemens.de (8.13.6/8.13.6) with ESMTP id p6LIEft4006280; Thu, 21 Jul 2011 20:14:42 +0200 From: Jan Kiszka To: Avi Kivity , Marcelo Tosatti Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , Alex Williamson Subject: [PATCH v2 7/7] qemu-kvm: Resolve PCI upstream diffs Date: Thu, 21 Jul 2011 20:14:41 +0200 Message-Id: <1787d74ef6c6f9563835d0d845fedb64b5318e5c.1311272079.git.jan.kiszka@siemens.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: References: In-Reply-To: References: Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 21 Jul 2011 18:15:15 +0000 (UTC) Device assignment no longer peeks into config_map, so we can drop all the related changes and sync the PCI core with upstream. Signed-off-by: Jan Kiszka --- hw/pci.c | 29 +++++++++++++++-------------- hw/pci.h | 8 ++++++-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 34b3881..4323ac3 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -793,7 +793,7 @@ static void pci_config_alloc(PCIDevice *pci_dev) pci_dev->cmask = qemu_mallocz(config_size); pci_dev->wmask = qemu_mallocz(config_size); pci_dev->w1cmask = qemu_mallocz(config_size); - pci_dev->config_map = qemu_mallocz(config_size); + pci_dev->used = qemu_mallocz(config_size); } static void pci_config_free(PCIDevice *pci_dev) @@ -802,7 +802,7 @@ static void pci_config_free(PCIDevice *pci_dev) qemu_free(pci_dev->cmask); qemu_free(pci_dev->wmask); qemu_free(pci_dev->w1cmask); - qemu_free(pci_dev->config_map); + qemu_free(pci_dev->used); } /* -1 for devfn means auto assign */ @@ -833,8 +833,6 @@ static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus, pci_dev->irq_state = 0; pci_config_alloc(pci_dev); - memset(pci_dev->config_map, 0xff, PCI_CONFIG_HEADER_SIZE); - pci_config_set_vendor_id(pci_dev->config, info->vendor_id); pci_config_set_device_id(pci_dev->config, info->device_id); pci_config_set_revision(pci_dev->config, info->revision); @@ -1897,7 +1895,7 @@ static int pci_find_space(PCIDevice *pdev, uint8_t size) int offset = PCI_CONFIG_HEADER_SIZE; int i; for (i = PCI_CONFIG_HEADER_SIZE; i < config_size; ++i) - if (pdev->config_map[i]) + if (pdev->used[i]) offset = i + 1; else if (i - offset + 1 == size) return offset; @@ -2078,13 +2076,13 @@ int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, int i; for (i = offset; i < offset + size; i++) { - if (pdev->config_map[i]) { + if (pdev->used[i]) { fprintf(stderr, "ERROR: %04x:%02x:%02x.%x " "Attempt to add PCI capability %x at offset " "%x overlaps existing capability %x at offset %x\n", pci_find_domain(pdev->bus), pci_bus_num(pdev->bus), PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), - cap_id, offset, pdev->config_map[i], i); + cap_id, offset, pdev->used[i], i); return -EINVAL; } } @@ -2094,14 +2092,12 @@ int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, config[PCI_CAP_LIST_ID] = cap_id; config[PCI_CAP_LIST_NEXT] = pdev->config[PCI_CAPABILITY_LIST]; pdev->config[PCI_CAPABILITY_LIST] = offset; - memset(pdev->config_map + offset, cap_id, size); + pdev->config[PCI_STATUS] |= PCI_STATUS_CAP_LIST; + memset(pdev->used + offset, 0xFF, size); /* Make capability read-only by default */ memset(pdev->wmask + offset, 0, size); /* Check capability by default */ memset(pdev->cmask + offset, 0xFF, size); - - pdev->config[PCI_STATUS] |= PCI_STATUS_CAP_LIST; - return offset; } @@ -2117,11 +2113,16 @@ void pci_del_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size) memset(pdev->w1cmask + offset, 0, size); /* Clear cmask as device-specific registers can't be checked */ memset(pdev->cmask + offset, 0, size); - memset(pdev->config_map + offset, 0, size); + memset(pdev->used + offset, 0, size); - if (!pdev->config[PCI_CAPABILITY_LIST]) { + if (!pdev->config[PCI_CAPABILITY_LIST]) pdev->config[PCI_STATUS] &= ~PCI_STATUS_CAP_LIST; - } +} + +/* Reserve space for capability at a known offset (to call after load). */ +void pci_reserve_capability(PCIDevice *pdev, uint8_t offset, uint8_t size) +{ + memset(pdev->used + offset, 0xff, size); } uint8_t pci_find_capability(PCIDevice *pdev, uint8_t cap_id) diff --git a/hw/pci.h b/hw/pci.h index c7081bc..ed734b3 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -146,8 +146,8 @@ struct PCIDevice { /* Used to implement RW1C(Write 1 to Clear) bytes */ uint8_t *w1cmask; - /* Used to allocate config space and track capabilities. */ - uint8_t *config_map; + /* Used to allocate config space capabilities. */ + uint8_t *used; /* the following fields are read only */ PCIBus *bus; @@ -233,14 +233,18 @@ int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size); +void pci_reserve_capability(PCIDevice *pci_dev, uint8_t offset, uint8_t size); + uint8_t pci_find_capability(PCIDevice *pci_dev, uint8_t cap_id); + uint32_t pci_default_read_config(PCIDevice *d, uint32_t address, int len); void pci_default_write_config(PCIDevice *d, uint32_t address, uint32_t val, int len); void pci_device_save(PCIDevice *s, QEMUFile *f); int pci_device_load(PCIDevice *s, QEMUFile *f); + typedef void (*pci_set_irq_fn)(void *opaque, int irq_num, int level); typedef int (*pci_map_irq_fn)(PCIDevice *pci_dev, int irq_num);