qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 3/4] pci: add default pci subsystem id for all devices.
Date: Wed,  1 Oct 2008 16:12:54 +0200	[thread overview]
Message-ID: <1222870375-13489-3-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1222870375-13489-1-git-send-email-kraxel@redhat.com>

This sets a default PCI subsystem ID for all emulated PCI devices.  PCI
specs require this, so do it.

Some background info:

Each PCI device has a PCI ID.  It should also have a PCI Subsystem ID.
The PCI subsystem ID wasn't mandatory in early PCI spec revisions, IIRC
2.0 added that requirement.  Thats why you usually get away without a
PCI subsystem ID, although it isn't correct.

Both IDs have a 16bit vendor and a 16bit device part.  The vendor IDs
are handed out by the PCI SIG.  The device IDs are assigned by the
vendor owning the vendor ID.

The PCI ID tells you which PCI chip is used, whereas the the PCI
Subsystem ID identifies the actual device (created using the PCI chip).

Example #1:  TV cards.  All TV cards using the bt878 chipset (first and
only one on the market for a few years in the 90-ies) have the same PCI
ID, the one of the bt878 chip.  But each TV card has different PCI
Subsystem IDs, which can be used to figure what the actual TV card is.

Example #2:  Laptops.  It is quite common to find the PCI Subsytem ID
pointing to the laptop vendor and model.  So the PCI ID says
'this is a intel ich7 ide controller', whereas the the PCI Subsystem ID
says 'this ich7 sits in a lenovo thinkpad', like this:

--------- cut here ----------
[root@zweiblum ~]# lspci -vs1f.1
00:1f.1 IDE interface: Intel Corporation 82801G (ICH7 Family) IDE
Controller (rev 02) (prog-if 8a [Master SecP PriP])
        Subsystem: Lenovo ThinkPad T60/R60 series
        [ ... more stuff snipped ... ]
--------- cut here ----------

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.

Right now the patch uses the vendor ID 0xfffa.  XenSource grabbed a
temporary ID (before they got one official assigned) from the 0xfffx
space too.  We'll better get something official though, to avoid
clashes.  We could try to get a vendor ID assigned (no idea how
difficuilt and/or expensive that would be).  Or we could try get get a
device ID range from a vendor (like the qumranet-sponsored IDs for
virtio ...).

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/pci.c |   11 +++++++++++
 hw/pci.h |    3 +++
 2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index bc55989..f2d0c4b 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -50,6 +50,8 @@ static void pci_update_mappings(PCIDevice *d);
 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_VENDOR_ID_QEMU;
+static uint16_t pci_default_sub_device_id = PCI_SUBDEVICE_ID_QEMU_DEFAULT;
 static int pci_irq_index;
 static PCIBus *first_bus;
 
@@ -145,6 +147,14 @@ int pci_device_load(PCIDevice *s, QEMUFile *f)
     return 0;
 }
 
+static int pci_set_default_subsystem_id(PCIDevice *pci_dev)
+{
+    struct pci_config_header *conf = (void*)pci_dev->config;
+
+    conf->sub_vendor_id = cpu_to_le16(pci_default_sub_vendor_id);
+    conf->sub_device_id = cpu_to_le16(pci_default_sub_device_id);
+}
+
 /* -1 for devfn means auto assign */
 PCIDevice *pci_register_device(PCIBus *bus, const char *name,
                                int instance_size, int devfn,
@@ -171,6 +181,7 @@ PCIDevice *pci_register_device(PCIBus *bus, const char *name,
     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;
diff --git a/hw/pci.h b/hw/pci.h
index f518e5e..d0b8a3e 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -34,6 +34,9 @@ struct pci_config_header {
 
 extern target_phys_addr_t pci_mem_base;
 
+#define PCI_VENDOR_ID_QEMU               0xfffa  /* FIXME: get one assigned */
+#define PCI_SUBDEVICE_ID_QEMU_DEFAULT    0x0001
+
 typedef void PCIConfigWriteFunc(PCIDevice *pci_dev,
                                 uint32_t address, uint32_t data, int len);
 typedef uint32_t PCIConfigReadFunc(PCIDevice *pci_dev,
-- 
1.5.5.1

  parent reply	other threads:[~2008-10-01 14:13 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-01 14:12 [Qemu-devel] [PATCH 1/4] add byteordered types to qemu Gerd Hoffmann
2008-10-01 14:12 ` [Qemu-devel] [PATCH 2/4] pci: add config space struct (from qemu-xen) Gerd Hoffmann
2008-10-01 14:12 ` Gerd Hoffmann [this message]
2008-10-01 14:12 ` [Qemu-devel] [PATCH 4/4] pci: use pci_config_header in pci.c Gerd Hoffmann
2008-10-01 16:30   ` Anthony Liguori
2008-10-01 19:09     ` Gerd Hoffmann
2008-10-01 19:27       ` Anthony Liguori
2008-10-02  7:56         ` Gerd Hoffmann
2008-10-02 15:52           ` Anthony Liguori
2008-10-06 16:04             ` Gerd Hoffmann
2008-10-02  8:21 ` [Qemu-devel] [PATCH 1/4] add byteordered types to qemu Christoph Hellwig
2008-10-02 12:46   ` Gerd Hoffmann
2008-10-02 12:55     ` Christoph Hellwig
2008-10-02 13:15       ` Gerd Hoffmann
2008-10-02 13:17         ` Christoph Hellwig
2008-10-02 14:08           ` Gerd Hoffmann
2008-10-02 15:55             ` Anthony Liguori
2008-10-06 16:07               ` Gerd Hoffmann
  -- strict thread matches above, loose matches on Subject: below --
2008-09-10 11:45 Gerd Hoffmann
2008-09-10 11:45 ` [Qemu-devel] [PATCH 3/4] pci: add default pci subsystem id for all devices Gerd Hoffmann
2008-09-10 12:43   ` Paul Brook
2008-09-10 13:40     ` Gerd Hoffmann
2008-08-28  8:36 [Qemu-devel] [PATCH 1/4] add byteordered types to qemu Gerd Hoffmann
2008-08-28  8:36 ` [Qemu-devel] [PATCH 3/4] pci: add default pci subsystem id for all devices Gerd Hoffmann
2008-08-28 20:37   ` Anthony Liguori
2008-08-29  9:05     ` Gerd Hoffmann
2008-09-07  2:39       ` Anthony Liguori
2008-09-08  8:45         ` Gerd Hoffmann
2008-09-22 16:38           ` Gerd Hoffmann
2008-08-27 13:45 [Qemu-devel] [PATCH 1/4] add byteordered types and accessor functions to qemu Gerd Hoffmann
2008-08-27 13:45 ` [Qemu-devel] [PATCH 3/4] pci: add default pci subsystem id for all devices Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1222870375-13489-3-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).