From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LAssr-0005NN-N1 for qemu-devel@nongnu.org; Thu, 11 Dec 2008 16:15:45 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LAssq-0005ME-VF for qemu-devel@nongnu.org; Thu, 11 Dec 2008 16:15:45 -0500 Received: from [199.232.76.173] (port=55270 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LAssq-0005M0-O4 for qemu-devel@nongnu.org; Thu, 11 Dec 2008 16:15:44 -0500 Received: from savannah.gnu.org ([199.232.41.3]:35887 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LAssq-0000OX-94 for qemu-devel@nongnu.org; Thu, 11 Dec 2008 16:15:44 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1LAssp-0000aY-P4 for qemu-devel@nongnu.org; Thu, 11 Dec 2008 21:15:43 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1LAssp-0000aU-AB for qemu-devel@nongnu.org; Thu, 11 Dec 2008 21:15:43 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Thu, 11 Dec 2008 21:15:43 +0000 Subject: [Qemu-devel] [5986] pci: add default pci subsystem id for all devices (Gerd Hoffman) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 5986 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5986 Author: aliguori Date: 2008-12-11 21:15:42 +0000 (Thu, 11 Dec 2008) Log Message: ----------- pci: add default pci subsystem id for all devices (Gerd Hoffman) This sets a default PCI subsystem ID for all emulated PCI devices. PCI specs require this, so do it. In many cases it is enougth to know the PCI ID to handle a device correctly. Sometimes a device driver must identify the exact piece of hardware (via PCI Subsystem ID) though. What does this patch to qemu devices: Right now the emulated PCI devices have no PCI subsystem ID, only the PCI ID. The discussed patch sets a default PCI subsystem ID for all emulated devices. Which will make the qemu devices look pretty much like in the laptop case: all PCI subsystem IDs will point to qemu by default. If a driver emulates a very specific piece of hardware where it has to emulate more than just the PCI chip, it can overwrite the PCI subsystem ID without problems. The es1370 driver does that for example. Signed-off-by: Gerd Hoffmann Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/hw/pci.c trunk/hw/pci.h Modified: trunk/hw/pci.c =================================================================== --- trunk/hw/pci.c 2008-12-11 21:06:49 UTC (rev 5985) +++ trunk/hw/pci.c 2008-12-11 21:15:42 UTC (rev 5986) @@ -50,6 +50,8 @@ static void pci_set_irq(void *opaque, int irq_num, int level); target_phys_addr_t pci_mem_base; +static uint16_t pci_default_sub_vendor_id = PCI_SUBVENDOR_ID_REDHAT_QUMRANET; +static uint16_t pci_default_sub_device_id = PCI_SUBDEVICE_ID_QEMU; static int pci_irq_index; static PCIBus *first_bus; @@ -145,6 +147,16 @@ return 0; } +static int pci_set_default_subsystem_id(PCIDevice *pci_dev) +{ + uint16_t *id; + + id = (void*)(&pci_dev->config[PCI_SUBVENDOR_ID]); + id[0] = cpu_to_le16(pci_default_sub_vendor_id); + id[1] = cpu_to_le16(pci_default_sub_device_id); + return 0; +} + /* -1 for devfn means auto assign */ PCIDevice *pci_register_device(PCIBus *bus, const char *name, int instance_size, int devfn, @@ -171,6 +183,7 @@ pci_dev->devfn = devfn; pstrcpy(pci_dev->name, sizeof(pci_dev->name), name); memset(pci_dev->irq_state, 0, sizeof(pci_dev->irq_state)); + pci_set_default_subsystem_id(pci_dev); if (!config_read) config_read = pci_default_read_config; Modified: trunk/hw/pci.h =================================================================== --- trunk/hw/pci.h 2008-12-11 21:06:49 UTC (rev 5985) +++ trunk/hw/pci.h 2008-12-11 21:15:42 UTC (rev 5986) @@ -8,6 +8,15 @@ extern target_phys_addr_t pci_mem_base; +/* see pci-ids.txt */ +#define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4 +#define PCI_SUBVENDOR_ID_REDHAT_QUMRANET 0x1af4 +#define PCI_SUBDEVICE_ID_QEMU 0x1100 + +#define PCI_DEVICE_ID_VIRTIO_NET 0x1000 +#define PCI_DEVICE_ID_VIRTIO_BLOCK 0x1001 +#define PCI_DEVICE_ID_VIRTIO_BALLOON 0x1002 + typedef void PCIConfigWriteFunc(PCIDevice *pci_dev, uint32_t address, uint32_t data, int len); typedef uint32_t PCIConfigReadFunc(PCIDevice *pci_dev, @@ -36,7 +45,10 @@ #define PCI_COMMAND 0x04 /* 16 bits */ #define PCI_COMMAND_IO 0x1 /* Enable response in I/O space */ #define PCI_COMMAND_MEMORY 0x2 /* Enable response in Memory space */ +#define PCI_REVISION 0x08 #define PCI_CLASS_DEVICE 0x0a /* Device class */ +#define PCI_SUBVENDOR_ID 0x2c /* 16 bits */ +#define PCI_SUBDEVICE_ID 0x2e /* 16 bits */ #define PCI_INTERRUPT_LINE 0x3c /* 8 bits */ #define PCI_INTERRUPT_PIN 0x3d /* 8 bits */ #define PCI_MIN_GNT 0x3e /* 8 bits */