Skip to contentSkip to conversation

pci: fix info pci with host bridge.

PATCH In review Isaku Yamahata 3 participants 7 messages Feb 8, 2010 – Feb 9, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci: fix info pci with host bridge.

This patch fixes 525e05147d5a3bdc08caa422d108c1ef71b584b5. pci host bridge doesn't have header type of bridge. The check should be by header type, instead of pci class device.

Cc Blue Swirl <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
---
 hw/pci.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
hw/pci.c +3 -3
index e91d2e6..eb2043e 100644
@@ -1273,7 +1273,7 @@ static QObject *pci_get_devices_list(PCIBus *bus, int bus_num);
 
 static QObject *pci_get_dev_dict(PCIDevice *dev, PCIBus *bus, int bus_num)
 {
-    int class;
+    uint8_t type;
     QObject *obj;
 
     obj = qobject_from_jsonf("{ 'bus': %d, 'slot': %d, 'function': %d,"                                       "'class_info': %p, 'id': %p, 'regions': %p,"
@@ -1289,8 +1289,8 @@ static QObject *pci_get_dev_dict(PCIDevice *dev, PCIBus *bus, int bus_num)
         qdict_put(qdict, "irq", qint_from_int(dev->config[PCI_INTERRUPT_LINE]));
     }
 
-    class = pci_get_word(dev->config + PCI_CLASS_DEVICE);
-    if (class == PCI_CLASS_BRIDGE_HOST || class == PCI_CLASS_BRIDGE_PCI) {
+    type = dev->config[PCI_HEADER_TYPE] & ~PCI_HEADER_TYPE_MULTI_FUNCTION;
+    if (type == PCI_HEADER_TYPE_BRIDGE) {
         QDict *qdict;
         QObject *pci_bridge;
 
Signature · 1 line
1.6.6.1
#1 lore raw
Quoted 7 lines · Isaku Yamahata

This patch fixes 525e05147d5a3bdc08caa422d108c1ef71b584b5. pci host bridge doesn't have header type of bridge. The check should be by header type, instead of pci class device.

Cc Blue Swirl <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>

Re: 525e05147d5a3bdc08caa422d108c1ef71b584b5 this commit put hard-coded constant in pci.c. It would have been better to post it on list for review instead of direct commit.

Quoted 30 lines
---
 hw/pci.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
hw/pci.c +3 -3
index e91d2e6..eb2043e 100644
@@ -1273,7 +1273,7 @@ static QObject *pci_get_devices_list(PCIBus *bus, int bus_num);
 
 static QObject *pci_get_dev_dict(PCIDevice *dev, PCIBus *bus, int bus_num)
 {
-    int class;
+    uint8_t type;
     QObject *obj;
 
     obj = qobject_from_jsonf("{ 'bus': %d, 'slot': %d, 'function': %d,"                                       "'class_info': %p, 'id': %p, 'regions': %p,"
@@ -1289,8 +1289,8 @@ static QObject *pci_get_dev_dict(PCIDevice *dev, PCIBus *bus, int bus_num)
         qdict_put(qdict, "irq", qint_from_int(dev->config[PCI_INTERRUPT_LINE]));
     }
 
-    class = pci_get_word(dev->config + PCI_CLASS_DEVICE);
-    if (class == PCI_CLASS_BRIDGE_HOST || class == PCI_CLASS_BRIDGE_PCI) {
+    type = dev->config[PCI_HEADER_TYPE] & ~PCI_HEADER_TYPE_MULTI_FUNCTION;
+    if (type == PCI_HEADER_TYPE_BRIDGE) {
         QDict *qdict;
         QObject *pci_bridge;
 
Signature · 1 line
1.6.6.1
#2 lore raw
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Isaku Yamahata

This patch fixes 525e05147d5a3bdc08caa422d108c1ef71b584b5. pci host bridge doesn't have header type of bridge. The check should be by header type, instead of pci class device.

Quoted 8 lines
Quoted 3 lines
Cc Blue Swirl <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>

Re: 525e05147d5a3bdc08caa422d108c1ef71b584b5 this commit put hard-coded constant in pci.c. It would have been better to post it on list for review instead of direct commit.

Heh, I looked at the reverse patch for some reason, it didn't put in constants, it removed them :)

Quoted 30 lines
Quoted 30 lines
---
 hw/pci.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
hw/pci.c +3 -3
index e91d2e6..eb2043e 100644
@@ -1273,7 +1273,7 @@ static QObject *pci_get_devices_list(PCIBus *bus, int bus_num);
 
 static QObject *pci_get_dev_dict(PCIDevice *dev, PCIBus *bus, int bus_num)
 {
-    int class;
+    uint8_t type;
     QObject *obj;
 
     obj = qobject_from_jsonf("{ 'bus': %d, 'slot': %d, 'function': %d,"                                       "'class_info': %p, 'id': %p, 'regions': %p,"
@@ -1289,8 +1289,8 @@ static QObject *pci_get_dev_dict(PCIDevice *dev, PCIBus *bus, int bus_num)
         qdict_put(qdict, "irq", qint_from_int(dev->config[PCI_INTERRUPT_LINE]));
     }
 
-    class = pci_get_word(dev->config + PCI_CLASS_DEVICE);
-    if (class == PCI_CLASS_BRIDGE_HOST || class == PCI_CLASS_BRIDGE_PCI) {
+    type = dev->config[PCI_HEADER_TYPE] & ~PCI_HEADER_TYPE_MULTI_FUNCTION;
+    if (type == PCI_HEADER_TYPE_BRIDGE) {
         QDict *qdict;
         QObject *pci_bridge;
 
Signature · 1 line
1.6.6.1
#3 lore raw
In reply to Isaku Yamahata
Quoted 7 lines · Isaku Yamahata

This patch fixes 525e05147d5a3bdc08caa422d108c1ef71b584b5. pci host bridge doesn't have header type of bridge. The check should be by header type, instead of pci class device.

Cc Blue Swirl <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>

So the effect of this will be that info pci won't report host bridge, right? IOW, it kind of reverts 525e05147d5a3bdc08caa422d108c1ef71b584b5, or am I missing something?

Quoted 30 lines
---
 hw/pci.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
hw/pci.c +3 -3
index e91d2e6..eb2043e 100644
@@ -1273,7 +1273,7 @@ static QObject *pci_get_devices_list(PCIBus *bus, int bus_num);
 
 static QObject *pci_get_dev_dict(PCIDevice *dev, PCIBus *bus, int bus_num)
 {
-    int class;
+    uint8_t type;
     QObject *obj;
 
     obj = qobject_from_jsonf("{ 'bus': %d, 'slot': %d, 'function': %d,"                                       "'class_info': %p, 'id': %p, 'regions': %p,"
@@ -1289,8 +1289,8 @@ static QObject *pci_get_dev_dict(PCIDevice *dev, PCIBus *bus, int bus_num)
         qdict_put(qdict, "irq", qint_from_int(dev->config[PCI_INTERRUPT_LINE]));
     }
 
-    class = pci_get_word(dev->config + PCI_CLASS_DEVICE);
-    if (class == PCI_CLASS_BRIDGE_HOST || class == PCI_CLASS_BRIDGE_PCI) {
+    type = dev->config[PCI_HEADER_TYPE] & ~PCI_HEADER_TYPE_MULTI_FUNCTION;
+    if (type == PCI_HEADER_TYPE_BRIDGE) {
         QDict *qdict;
         QObject *pci_bridge;
 
Signature · 1 line
1.6.6.1
#4 lore raw
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Isaku Yamahata

This patch fixes 525e05147d5a3bdc08caa422d108c1ef71b584b5. pci host bridge doesn't have header type of bridge. The check should be by header type, instead of pci class device.

Quoted 8 lines
Quoted 3 lines
Cc Blue Swirl <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>

So the effect of this will be that info pci won't report host bridge, right? IOW, it kind of reverts 525e05147d5a3bdc08caa422d108c1ef71b584b5, or am I missing something?

Yes, it breaks info pci. PBM/APB does not use PCI_HEADER_TYPE_BRIDGE.

#5 lore raw
Quoted 10 lines · Blue Swirl
Quoted 9 lines · Michael S. Tsirkin
Quoted 7 lines · Isaku Yamahata

This patch fixes 525e05147d5a3bdc08caa422d108c1ef71b584b5. pci host bridge doesn't have header type of bridge. The check should be by header type, instead of pci class device.

Cc Blue Swirl <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Quoted 6 lines
Quoted 4 lines

So the effect of this will be that info pci won't report host bridge, right? IOW, it kind of reverts 525e05147d5a3bdc08caa422d108c1ef71b584b5, or am I missing something?

Yes, it breaks info pci. PBM/APB does not use PCI_HEADER_TYPE_BRIDGE.

Devices of pci host bridge class (!= PCI-PCI bridge) don't have header type PCI_HEADER_TYPE_BRIDGE (= 1), but PCI_HEADER_TYPE_NORMAL (= 0). In fact, i440fx pci host bridge is of PCI_HEADER_TYPE_NORMAL. You can see it in piix_pci.c.
Registers of offset 0x10-0x3F in configuration space are used differently depending on header type.
For example, PCI_HEADER_TYPE_NORMAL device don't have primary bus register, secondary bus register and so on. Those registers are used as BAR2. It doesn't make senses to show BAR2 as bus numbers.

Having said that, I'm confused. So I downloaded
"UltraSPARC IIi User's Manual", 805-0087.pdf.
Page 301, table 19-12, section 19l.3.1 says that its header type is 0x0. (= PCI_HEADER_TYPE_Normal).

cited from table 19-12.

offset

0x10-0x27       Base Address
0x28-0x2F       Reserved
0x30-0x34       Expansion ROM
0x34-0x3b       Reserved
0x3e            MIN_GNT
0x3f            MAX_LAT

...

So it doesn't make sense to access those registers as
primary bus number, etc...
However the manual also says that those shaded registers aren't implemented. Maybe it would make sense to use those unused/unimplemented registers for registers of header type 1 in PBM emulation.
This is what you want to do, Right?

Probably what you want in pci_info_device() is something like "if (type == PCI_HEADER_TYPE_BRIDGE ||

    (vendorid == PCI_VENDOR_ID_SUN && deviceid == PCI_DEVICE_ID_SUN_SABRE))"

This is ugly, so introducing device specific info callback?

Signature · 1 line
yamahata
#6 lore raw
Quoted 51 lines · Isaku Yamahata
Quoted 10 lines · Blue Swirl
Quoted 9 lines · Michael S. Tsirkin
Quoted 7 lines · Isaku Yamahata

This patch fixes 525e05147d5a3bdc08caa422d108c1ef71b584b5. pci host bridge doesn't have header type of bridge. The check should be by header type, instead of pci class device.

Cc Blue Swirl <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Quoted 6 lines
Quoted 4 lines

So the effect of this will be that info pci won't report host bridge, right? IOW, it kind of reverts 525e05147d5a3bdc08caa422d108c1ef71b584b5, or am I missing something?

Yes, it breaks info pci. PBM/APB does not use PCI_HEADER_TYPE_BRIDGE.

Devices of pci host bridge class (!= PCI-PCI bridge) don't have header type PCI_HEADER_TYPE_BRIDGE (= 1), but PCI_HEADER_TYPE_NORMAL (= 0). In fact, i440fx pci host bridge is of PCI_HEADER_TYPE_NORMAL. You can see it in piix_pci.c.
Registers of offset 0x10-0x3F in configuration space are used differently depending on header type.
For example, PCI_HEADER_TYPE_NORMAL device don't have primary bus register, secondary bus register and so on. Those registers are used as BAR2. It doesn't make senses to show BAR2 as bus numbers.

Having said that, I'm confused. So I downloaded
"UltraSPARC IIi User's Manual", 805-0087.pdf.
Page 301, table 19-12, section 19l.3.1 says that its header type is 0x0. (= PCI_HEADER_TYPE_Normal).

cited from table 19-12.

offset
0x10-0x27       Base Address
0x28-0x2F       Reserved
0x30-0x34       Expansion ROM
0x34-0x3b       Reserved
0x3e            MIN_GNT
0x3f            MAX_LAT
...

So it doesn't make sense to access those registers as
primary bus number, etc...
However the manual also says that those shaded registers aren't implemented. Maybe it would make sense to use those unused/unimplemented registers for registers of header type 1 in PBM emulation.
This is what you want to do, Right?

Quoted 5 lines

Probably what you want in pci_info_device() is something like "if (type == PCI_HEADER_TYPE_BRIDGE ||
   (vendorid == PCI_VENDOR_ID_SUN && deviceid == PCI_DEVICE_ID_SUN_SABRE))"

This is ugly, so introducing device specific info callback?

Or maybe header should be of normal type and the secondary/subordinate registers should not be used like they would be with a PCI-PCI bridge. In that case maybe the bus number checks are not correct, or perhaps OpenBIOS PCI code is wrong.