Skip to contentSkip to conversation

hw/pc: implement multiple primary busses for pc machines

PATCH Superseded Marcel Apfelbaum 8 participants 66 messages Mar 8, 2015 – Mar 11, 2015

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v4 cover hw/pc: implement multiple primary busses for pc machines

Notes:
- Sorry for the late submission, I was waiting for dynamic ACPI series to get merged in order to submit - my bad.
- The prev version (v2) was wrongfully tagged by me as RFC, it was actually ready but not rebased. V3 only rebases with no actual functionality changed.
- This series is not that big, patches 1-8 are really small and can be submitted separately, however I preferred to keep them here to get the whole picture.

The series is fully functional.
- Limitations:
- Pxb's bus does not support hotplug. It will be addressed on top of this series because is already getting to big.
- Depends on:
- [SeaBIOS] [PATCH V3 0/2] fw/pci: better support for multiple host bridges
- It was already reviewed/accepted by the maintainers, it will be merged after this series gets accepted.
- You are more than welcome to try using:

       -device pxb-device,id=pxb,bus_nr=4,numa_node=1 -device e1000,bus=pxb,addr=0x1 -bios <patched with the above series>

v3->v4:
- Addressed Michael S. Tsirkin's review:
- refactored build_prt method (patch 11/25) hw/apci: add _PRT method for extra PCI root busses
- Addressed Igor Mammedov's reiew
- add assert to aml_index (patch 5/25)
- Fixed aml_equal implementation (patch 1/25)

v2->v3:
- Rebased on Michael S. Tsirkin's pci branch (that includes now all the dependencies)
- Refactored acpi terms patch into multiple patches to match Igor's design.

v1->v2:
- Add support for multiple pxb devices.
- Attach pxb's bus to specific NUMA node.
- Got rid of the hacks from prev version.
- Tested also for Win7 and Fedora 20, and for virtio blk devices.
- Several bug-fixes resulting in a stable version ready for submission.

Reasoning:
We need multiple primary busess for a few reasons, the most important one is to be able to associate a pass-trough device with a guest NUMA node. The OS-es are able to associate a NUMA node only to a primary bus, not to a specific PCI device or a pci-2-pci bridge.
PC machines support multiple NUMA nodes for CPUs and memory, however the IO was not yet supported.

patch 1-9 adds the necessary acpi constructs based on Igor's series
patch 10-13 implements acpi code needed to expose the pxb's primary bus to guests patch 14 separates the pci_bus code into a designated file
patch 15-19 handles the implicit assumptions in code that only one primary bus can exist patch 20 handles the actual implementation of the PXB devices
patch 21-22 enables the device
patch 23 implements PXB map_irq function, (can be squashed into the actual PXB) patch 24-25 adds NUMA support

Marcel Apfelbaum (25):
acpi: fix aml_equal term implementation
acpi: add aml_or() term
acpi: add aml_add() term
acpi: add aml_lless() term
acpi: add aml_index() term
acpi: add aml_shiftleft() term
acpi: add aml_shiftright() term
acpi: add aml_increment() term
acpi: add aml_while() term
hw/acpi: add support for multiple root busses hw/apci: add _PRT method for extra PCI root busses hw/acpi: add _CRS method for extra root busses hw/acpi: remove from root bus 0 the crs resources used by other
busses.
hw/pci: move pci bus related code to separate files hw/pci: made pci_bus_is_root a PCIBusClass method hw/pci: made pci_bus_num a PCIBusClass method
hw/pci: introduce TYPE_PCI_MAIN_HOST_BRIDGE interface hw/pci: removed 'rootbus nr is 0' assumption from qmp_pci_query hw/pci: implement iteration over multiple host bridges hw/pci: introduce PCI Expander Bridge (PXB)
hw/pci: inform bios if the system has more than one pci bridge hw/pci: piix - suport multiple host bridges
hw/pxb: add map_irq func
hw/pci_bus: add support for NUMA nodes
hw/pxb: add numa_node parameter

 arch_init.c                         |   1 +
 hw/acpi/aml-build.c                 |  79 +++++-
 hw/alpha/typhoon.c                  |   1 +
 hw/i386/acpi-build.c                | 347 +++++++++++++++++++++++-
 hw/i386/kvm/pci-assign.c            |   1 +
 hw/i386/pc.c                        |  13 +
 hw/mips/gt64xxx_pci.c               |   1 +
 hw/pci-bridge/Makefile.objs         |   1 +
 hw/pci-bridge/pci_expander_bridge.c | 208 +++++++++++++++
 hw/pci-host/bonito.c                |   1 +
 hw/pci-host/grackle.c               |   1 +
 hw/pci-host/piix.c                  |  63 ++++-
 hw/pci-host/ppce500.c               |   1 +
 hw/pci-host/q35.c                   |   5 +
 hw/pci-host/uninorth.c              |   1 +
 hw/pci/Makefile.objs                |   2 +-
 hw/pci/pci.c                        | 501 +---------------------------------
 hw/pci/pci_bus.c                    | 517 ++++++++++++++++++++++++++++++++++++
 hw/pci/pci_host.c                   |   6 +
 hw/ppc/ppc4xx_pci.c                 |   1 +
 hw/scsi/megasas.c                   |   1 +
 hw/sh4/r2d.c                        |   1 +
 hw/sh4/sh_pci.c                     |   1 +
 hw/vfio/pci.c                       |   1 +
 hw/xen/xen_pt.c                     |   1 +
 include/hw/acpi/aml-build.h         |   8 +
 include/hw/pci/pci.h                |   6 +-
 include/hw/pci/pci_bus.h            |  35 +++
 include/hw/pci/pci_host.h           |  11 +
 include/sysemu/sysemu.h             |   1 +
 30 files changed, 1307 insertions(+), 510 deletions(-)
 create mode 100644 hw/pci-bridge/pci_expander_bridge.c
 create mode 100644 hw/pci/pci_bus.c
Signature · 1 line
2.1.0
#1 lore raw

PATCH v4 1/25 acpi: fix aml_equal term implementation

The DefLEqual op does not have a target operand. Remove it.

---
 hw/acpi/aml-build.c | 1 -
 1 file changed, 1 deletion(-)
hw/acpi/aml-build.c +0 -1
index 876cada..0d14561 100644
@@ -542,7 +542,6 @@ Aml *aml_equal(Aml *arg1, Aml *arg2)
     Aml *var = aml_opcode(0x93 /* LequalOp */);
     aml_append(var, arg1);
     aml_append(var, arg2);
-    build_append_int(var->buf, 0x00); /* NullNameOp */
     return var;
 }
 
Signature · 1 line
2.1.0
Reviewed-by on v4 1/25
#2 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 01/25] acpi: fix aml_equal term implementation

Quoted 3 lines · On Sun, 8 Mar 2015 13:16:03 +0200 Marcel Apfelbaum <[email protected]> wrote:

The DefLEqual op does not have a target operand. Remove it.

hw/acpi/aml-build.c Aml *aml_equal(Aml *arg1, Aml *arg2) · line 545

Quoted 13 lines
---
 hw/acpi/aml-build.c | 1 -
 1 file changed, 1 deletion(-)
hw/acpi/aml-build.c +0 -1
index 876cada..0d14561 100644
@@ -542,7 +542,6 @@ Aml *aml_equal(Aml *arg1, Aml *arg2)
     Aml *var = aml_opcode(0x93 /* LequalOp */);
     aml_append(var, arg1);
     aml_append(var, arg2);
-    build_append_int(var->buf, 0x00); /* NullNameOp */

It's just happens to work in case CPU and PCI hotplug because it LEqual was the only predicate in if block and NullNameOp was considered as part of inner code-block, like:
if (LEqual(a, b)) {
NullName; // nop
...
}

Quoted 3 lines
hw/acpi/aml-build.c +0 -0
     return var;
 }
 
#3 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 01/25] acpi: fix aml_equal term implementation

Quoted 12 lines · Igor Mammedov
Quoted 3 lines · On Sun, 8 Mar 2015 13:16:03 +0200 Marcel Apfelbaum <[email protected]> wrote:

The DefLEqual op does not have a target operand. Remove it.

Quoted 4 lines
---
 hw/acpi/aml-build.c | 1 -
 1 file changed, 1 deletion(-)
Quoted 16 lines

hw/acpi/aml-build.c Aml *aml_equal(Aml *arg1, Aml *arg2) · line 545

Quoted 9 lines
hw/acpi/aml-build.c +0 -1
index 876cada..0d14561 100644
@@ -542,7 +542,6 @@ Aml *aml_equal(Aml *arg1, Aml *arg2)
     Aml *var = aml_opcode(0x93 /* LequalOp */);
     aml_append(var, arg1);
     aml_append(var, arg2);
-    build_append_int(var->buf, 0x00); /* NullNameOp */

It's just happens to work in case CPU and PCI hotplug because it LEqual was the only predicate in if block and NullNameOp was considered as part of inner code-block, like:
if (LEqual(a, b)) {
NullName; // nop
...
}

So - maybe aml_if should get 3rd parameter - the command?

Quoted 3 lines
Quoted 3 lines
hw/acpi/aml-build.c +0 -0
     return var;
 }
 
#4 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 01/25] acpi: fix aml_equal term implementation

Quoted 30 lines · On Mon, 9 Mar 2015 12:04:51 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 12 lines · Igor Mammedov
Quoted 3 lines · On Sun, 8 Mar 2015 13:16:03 +0200 Marcel Apfelbaum <[email protected]> wrote:

The DefLEqual op does not have a target operand. Remove it.

Quoted 4 lines
---
 hw/acpi/aml-build.c | 1 -
 1 file changed, 1 deletion(-)
Quoted 16 lines

hw/acpi/aml-build.c Aml *aml_equal(Aml *arg1, Aml *arg2) · line 545

Quoted 9 lines
hw/acpi/aml-build.c +0 -1
index 876cada..0d14561 100644
@@ -542,7 +542,6 @@ Aml *aml_equal(Aml *arg1, Aml *arg2)
     Aml *var = aml_opcode(0x93 /* LequalOp */);
     aml_append(var, arg1);
     aml_append(var, arg2);
-    build_append_int(var->buf, 0x00); /* NullNameOp */

It's just happens to work in case CPU and PCI hotplug because it LEqual was the only predicate in if block and NullNameOp was considered as part of inner code-block, like:
if (LEqual(a, b)) {
NullName; // nop
...
}

Quoted 1 line

So - maybe aml_if should get 3rd parameter - the command?

it's not only one command it's block of AML code inside of 'if' scope. Adding 3rd argument would mean inventing another not defined by spec element like aml_block() where you could put AML items that are in block, I'd like to keep non spec items to minimum and not add them unless we have to.

Then for consistence purposes we would add this 'aml_block' argument to other block constructs like 'device, scope, package, ...' So I think current way of defining context and then putting items in it is pretty clean way as opposed to doing it backwards, first defining elements somewhere and then passing that somewhere as argument to a AML block construct.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hw/acpi/aml-build.c +0 -0
     return var;
 }
 
#5 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 01/25] acpi: fix aml_equal term implementation

Quoted 33 lines · Igor Mammedov
Quoted 30 lines · On Mon, 9 Mar 2015 12:04:51 +0100 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 28 lines · Igor Mammedov
Quoted 3 lines · On Sun, 8 Mar 2015 13:16:03 +0200 Marcel Apfelbaum <[email protected]> wrote:

The DefLEqual op does not have a target operand. Remove it.

hw/acpi/aml-build.c Aml *aml_equal(Aml *arg1, Aml *arg2) · line 545

Quoted 13 lines
---
 hw/acpi/aml-build.c | 1 -
 1 file changed, 1 deletion(-)
hw/acpi/aml-build.c +0 -1
index 876cada..0d14561 100644
@@ -542,7 +542,6 @@ Aml *aml_equal(Aml *arg1, Aml *arg2)
     Aml *var = aml_opcode(0x93 /* LequalOp */);
     aml_append(var, arg1);
     aml_append(var, arg2);
-    build_append_int(var->buf, 0x00); /* NullNameOp */

It's just happens to work in case CPU and PCI hotplug because it LEqual was the only predicate in if block and NullNameOp was considered as part of inner code-block, like:
if (LEqual(a, b)) {
NullName; // nop
...
}

Quoted 5 lines
Quoted 1 line

So - maybe aml_if should get 3rd parameter - the command?

it's not only one command it's block of AML code inside of 'if' scope. Adding 3rd argument would mean inventing another not defined by spec element like aml_block() where you could put AML items that are in block, I'd like to keep non spec items to minimum and not add them unless we have to.

In fact, it's TermList in spec, isn't it?
But I don't insist.

Quoted 7 lines

Then for consistence purposes we would add this 'aml_block' argument to other block constructs like 'device, scope, package, ...' So I think current way of defining context and then putting items in it is pretty clean way as opposed to doing it backwards, first defining elements somewhere and then passing that somewhere as argument to a AML block construct.

I think it's just a question of adding a convenience wrapper for the most common case.

/* Convenience wrapper for when there's a single
* term in TermList
*/
Aml *aml_if_then_1term(Aml *predicate, Aml *term)

{
    Aml *if_ctx = aml_if(predicate);

    aml_append(if_ctx, term);
    return if_ctx;
}
#6 lore raw

PATCH v4 2/25 acpi: add aml_or() term

In reply to Marcel Apfelbaum

Add encoding for ACPI DefOr Opcode.

---
 hw/acpi/aml-build.c         | 10 ++++++++++
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 11 insertions(+)
hw/acpi/aml-build.c +10 -0
index 0d14561..603c0c4 100644
@@ -448,6 +448,16 @@ Aml *aml_and(Aml *arg1, Aml *arg2)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefOr */
+Aml *aml_or(Aml *arg1, Aml *arg2)
+{
+    Aml *var = aml_opcode(0x7D /* OrOp */);
+    aml_append(var, arg1);
+    aml_append(var, arg2);
+    build_append_int(var->buf, 0x00); /* NullNameOp */
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefNotify */
 Aml *aml_notify(Aml *arg1, Aml *arg2)
 {
include/hw/acpi/aml-build.h +1 -0
index f6735ea..84d4180 100644
@@ -137,6 +137,7 @@ Aml *aml_int(const uint64_t val);
 Aml *aml_arg(int pos);
 Aml *aml_store(Aml *val, Aml *target);
 Aml *aml_and(Aml *arg1, Aml *arg2);
+Aml *aml_or(Aml *arg1, Aml *arg2);
 Aml *aml_notify(Aml *arg1, Aml *arg2);
 Aml *aml_call1(const char *method, Aml *arg1);
 Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2);
Signature · 1 line
2.1.0
#7 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 02/25] acpi: add aml_or() term

Quoted 14 lines · Marcel Apfelbaum

Add encoding for ACPI DefOr Opcode.

---
 hw/acpi/aml-build.c         | 10 ++++++++++
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 11 insertions(+)
hw/acpi/aml-build.c +0 -0
index 0d14561..603c0c4 100644

hw/acpi/aml-build.c Aml *aml_and(Aml *arg1, Aml *arg2) · line 457

Quoted 10 lines
hw/acpi/aml-build.c +7 -0
@@ -448,6 +448,16 @@ Aml *aml_and(Aml *arg1, Aml *arg2)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefOr */
+Aml *aml_or(Aml *arg1, Aml *arg2)
+{
+    Aml *var = aml_opcode(0x7D /* OrOp */);
+    aml_append(var, arg1);
+    aml_append(var, arg2);
+    build_append_int(var->buf, 0x00); /* NullNameOp */

Hi,

I notice that MST has sent a patch which uses build_append_byte instead of build_append_int. Maybe we can fix this patch before apply.

Thanks,
Shannon

Quoted 3 lines
hw/acpi/aml-build.c +3 -0
+    return var;
+}
+
#8 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 02/25] acpi: add aml_or() term

Quoted 18 lines · Shannon Zhao
Quoted 17 lines · Marcel Apfelbaum

Add encoding for ACPI DefOr Opcode.

---
  hw/acpi/aml-build.c         | 10 ++++++++++
  include/hw/acpi/aml-build.h |  1 +
  2 files changed, 11 insertions(+)
hw/acpi/aml-build.c +0 -0
index 0d14561..603c0c4 100644
@@ -448,6 +448,16 @@ Aml *aml_and(Aml *arg1, Aml *arg2)
      return var;
  }
 
Quoted 8 lines

hw/acpi/aml-build.c Aml *aml_and(Aml *arg1, Aml *arg2) · line 457

Quoted 7 lines
hw/acpi/aml-build.c +7 -0
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefOr */
+Aml *aml_or(Aml *arg1, Aml *arg2)
+{
+    Aml *var = aml_opcode(0x7D /* OrOp */);
+    aml_append(var, arg1);
+    aml_append(var, arg2);
+    build_append_int(var->buf, 0x00); /* NullNameOp */

Hi,

Hi Shannon, thank you for your review.

Quoted 3 lines

I notice that MST has sent a patch which uses build_append_byte instead of build_append_int. Maybe we can fix this patch before apply.

Sure, thank you for bringing this to my attention. Marcel

Quoted 8 lines

Thanks,
Shannon

Quoted 3 lines
hw/acpi/aml-build.c +3 -0
+    return var;
+}
+
#9 lore raw

PATCH v4 3/25 acpi: add aml_add() term

In reply to Marcel Apfelbaum

Add encoding for ACPI DefAdd Opcode.

---
 hw/acpi/aml-build.c         | 10 ++++++++++
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 11 insertions(+)
hw/acpi/aml-build.c +10 -0
index 603c0c4..be60f4e 100644
@@ -458,6 +458,16 @@ Aml *aml_or(Aml *arg1, Aml *arg2)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefAdd */
+Aml *aml_add(Aml *arg1, Aml *arg2)
+{
+    Aml *var = aml_opcode(0x72 /* AddOp */);
+    aml_append(var, arg1);
+    aml_append(var, arg2);
+    build_append_int(var->buf, 0x00 /* NullNameOp */);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefNotify */
 Aml *aml_notify(Aml *arg1, Aml *arg2)
 {
include/hw/acpi/aml-build.h +1 -0
index 84d4180..991eacb 100644
@@ -138,6 +138,7 @@ Aml *aml_arg(int pos);
 Aml *aml_store(Aml *val, Aml *target);
 Aml *aml_and(Aml *arg1, Aml *arg2);
 Aml *aml_or(Aml *arg1, Aml *arg2);
+Aml *aml_add(Aml *arg1, Aml *arg2);
 Aml *aml_notify(Aml *arg1, Aml *arg2);
 Aml *aml_call1(const char *method, Aml *arg1);
 Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2);
Signature · 1 line
2.1.0
#10 lore raw

PATCH v4 4/25 acpi: add aml_lless() term

In reply to Marcel Apfelbaum

Add encoding for ACPI DefLLess Opcode.

---
 hw/acpi/aml-build.c         | 9 +++++++++
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 10 insertions(+)
hw/acpi/aml-build.c +9 -0
index be60f4e..49ba8c1 100644
@@ -458,6 +458,15 @@ Aml *aml_or(Aml *arg1, Aml *arg2)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLLess */
+Aml *aml_lless(Aml *arg1, Aml *arg2)
+{
+    Aml *var = aml_opcode(0x95 /* LLessOp */);
+    aml_append(var, arg1);
+    aml_append(var, arg2);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefAdd */
 Aml *aml_add(Aml *arg1, Aml *arg2)
 {
include/hw/acpi/aml-build.h +1 -0
index 991eacb..edc0520 100644
@@ -138,6 +138,7 @@ Aml *aml_arg(int pos);
 Aml *aml_store(Aml *val, Aml *target);
 Aml *aml_and(Aml *arg1, Aml *arg2);
 Aml *aml_or(Aml *arg1, Aml *arg2);
+Aml *aml_lless(Aml *arg1, Aml *arg2);
 Aml *aml_add(Aml *arg1, Aml *arg2);
 Aml *aml_notify(Aml *arg1, Aml *arg2);
 Aml *aml_call1(const char *method, Aml *arg1);
Signature · 1 line
2.1.0
Reviewed-by on v4 4/25
#11 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 04/25] acpi: add aml_lless() term

Quoted 4 lines · Marcel Apfelbaum

Add encoding for ACPI DefLLess Opcode.

Quoted 38 lines
---
 hw/acpi/aml-build.c         | 9 +++++++++
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 10 insertions(+)
hw/acpi/aml-build.c +9 -0
index be60f4e..49ba8c1 100644
@@ -458,6 +458,15 @@ Aml *aml_or(Aml *arg1, Aml *arg2)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLLess */
+Aml *aml_lless(Aml *arg1, Aml *arg2)
+{
+    Aml *var = aml_opcode(0x95 /* LLessOp */);
+    aml_append(var, arg1);
+    aml_append(var, arg2);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefAdd */
 Aml *aml_add(Aml *arg1, Aml *arg2)
 {
include/hw/acpi/aml-build.h +1 -0
index 991eacb..edc0520 100644
@@ -138,6 +138,7 @@ Aml *aml_arg(int pos);
 Aml *aml_store(Aml *val, Aml *target);
 Aml *aml_and(Aml *arg1, Aml *arg2);
 Aml *aml_or(Aml *arg1, Aml *arg2);
+Aml *aml_lless(Aml *arg1, Aml *arg2);
 Aml *aml_add(Aml *arg1, Aml *arg2);
 Aml *aml_notify(Aml *arg1, Aml *arg2);
 Aml *aml_call1(const char *method, Aml *arg1);
Signature · 2 lines
Thanks,
Shannon
#12 lore raw

PATCH v4 5/25 acpi: add aml_index() term

In reply to Marcel Apfelbaum

Add encoding for ACPI DefIndex Opcode.

---
 hw/acpi/aml-build.c         | 13 +++++++++++++
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 14 insertions(+)
hw/acpi/aml-build.c +13 -0
index 49ba8c1..b3372df 100644
@@ -477,6 +477,19 @@ Aml *aml_add(Aml *arg1, Aml *arg2)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefIndex */
+Aml *aml_index(Aml *arg1, Aml *idx)
+{
+    Aml *var = aml_opcode(0x88 /* IndexOp */);
+
+    g_assert(arg1->block_flags & (AML_PACKAGE | AML_EXT_PACKAGE | AML_BUFFER));
+
+    aml_append(var, arg1);
+    aml_append(var, idx);
+    build_append_int(var->buf, 0x00 /* NullNameOp */);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefNotify */
 Aml *aml_notify(Aml *arg1, Aml *arg2)
 {
include/hw/acpi/aml-build.h +1 -0
index edc0520..b860732 100644
@@ -140,6 +140,7 @@ Aml *aml_and(Aml *arg1, Aml *arg2);
 Aml *aml_or(Aml *arg1, Aml *arg2);
 Aml *aml_lless(Aml *arg1, Aml *arg2);
 Aml *aml_add(Aml *arg1, Aml *arg2);
+Aml *aml_index(Aml *arg1, Aml *idx);
 Aml *aml_notify(Aml *arg1, Aml *arg2);
 Aml *aml_call1(const char *method, Aml *arg1);
 Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2);
Signature · 1 line
2.1.0
#13 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 05/25] acpi: add aml_index() term

Quoted 13 lines · On Sun, 8 Mar 2015 13:16:07 +0200 Marcel Apfelbaum <[email protected]> wrote:

Add encoding for ACPI DefIndex Opcode.

---
 hw/acpi/aml-build.c         | 13 +++++++++++++
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 14 insertions(+)
hw/acpi/aml-build.c +0 -0
index 49ba8c1..b3372df 100644

hw/acpi/aml-build.c Aml *aml_add(Aml *arg1, Aml *arg2) · line 485

Quoted 9 lines
hw/acpi/aml-build.c +6 -0
@@ -477,6 +477,19 @@ Aml *aml_add(Aml *arg1, Aml *arg2)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefIndex */
+Aml *aml_index(Aml *arg1, Aml *idx)
+{
+    Aml *var = aml_opcode(0x88 /* IndexOp */);
+
+    g_assert(arg1->block_flags & (AML_PACKAGE | AML_EXT_PACKAGE | AML_BUFFER));

it couldn't be AML_EXT_PACKAGE, it's either a plain DefPackage or DefBuffer i.e. I'd suggest to add to above check also checking for specific opcodes arg1->op = 0x11 /* buffer */ ...

Also a newer spec (>1.0b) allows to use DefString as argument as well.

Quoted 22 lines
hw/acpi/aml-build.c +7 -0
+
+    aml_append(var, arg1);
+    aml_append(var, idx);
+    build_append_int(var->buf, 0x00 /* NullNameOp */);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefNotify */
 Aml *aml_notify(Aml *arg1, Aml *arg2)
 {
include/hw/acpi/aml-build.h +1 -0
index edc0520..b860732 100644
@@ -140,6 +140,7 @@ Aml *aml_and(Aml *arg1, Aml *arg2);
 Aml *aml_or(Aml *arg1, Aml *arg2);
 Aml *aml_lless(Aml *arg1, Aml *arg2);
 Aml *aml_add(Aml *arg1, Aml *arg2);
+Aml *aml_index(Aml *arg1, Aml *idx);
 Aml *aml_notify(Aml *arg1, Aml *arg2);
 Aml *aml_call1(const char *method, Aml *arg1);
 Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2);
#14 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 05/25] acpi: add aml_index() term

Quoted 29 lines · Igor Mammedov
Quoted 13 lines · On Sun, 8 Mar 2015 13:16:07 +0200 Marcel Apfelbaum <[email protected]> wrote:

Add encoding for ACPI DefIndex Opcode.

---
 hw/acpi/aml-build.c         | 13 +++++++++++++
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 14 insertions(+)
hw/acpi/aml-build.c +0 -0
index 49ba8c1..b3372df 100644

hw/acpi/aml-build.c Aml *aml_add(Aml *arg1, Aml *arg2) · line 485

Quoted 9 lines
hw/acpi/aml-build.c +6 -0
@@ -477,6 +477,19 @@ Aml *aml_add(Aml *arg1, Aml *arg2)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefIndex */
+Aml *aml_index(Aml *arg1, Aml *idx)
+{
+    Aml *var = aml_opcode(0x88 /* IndexOp */);
+
+    g_assert(arg1->block_flags & (AML_PACKAGE | AML_EXT_PACKAGE | AML_BUFFER));

it couldn't be AML_EXT_PACKAGE, it's either a plain DefPackage or DefBuffer i.e. I'd suggest to add to above check also checking for specific opcodes arg1->op = 0x11 /* buffer */ ...

Quoted 1 line

Also a newer spec (>1.0b) allows to use DefString as argument as well.

You really can have a lot of things there, e.g. a method call will also work.
I think it's best to drop these asserts at this point, and maybe blacklist specific bad configs down the road.

Quoted 22 lines
Quoted 22 lines
hw/acpi/aml-build.c +7 -0
+
+    aml_append(var, arg1);
+    aml_append(var, idx);
+    build_append_int(var->buf, 0x00 /* NullNameOp */);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefNotify */
 Aml *aml_notify(Aml *arg1, Aml *arg2)
 {
include/hw/acpi/aml-build.h +1 -0
index edc0520..b860732 100644
@@ -140,6 +140,7 @@ Aml *aml_and(Aml *arg1, Aml *arg2);
 Aml *aml_or(Aml *arg1, Aml *arg2);
 Aml *aml_lless(Aml *arg1, Aml *arg2);
 Aml *aml_add(Aml *arg1, Aml *arg2);
+Aml *aml_index(Aml *arg1, Aml *idx);
 Aml *aml_notify(Aml *arg1, Aml *arg2);
 Aml *aml_call1(const char *method, Aml *arg1);
 Aml *aml_call2(const char *method, Aml *arg1, Aml *arg2);
#15 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 05/25] acpi: add aml_index() term

Quoted 30 lines · Michael S. Tsirkin
Quoted 29 lines · Igor Mammedov
Quoted 13 lines · On Sun, 8 Mar 2015 13:16:07 +0200 Marcel Apfelbaum <[email protected]> wrote:

Add encoding for ACPI DefIndex Opcode.

---
  hw/acpi/aml-build.c         | 13 +++++++++++++
  include/hw/acpi/aml-build.h |  1 +
  2 files changed, 14 insertions(+)
hw/acpi/aml-build.c +0 -0
index 49ba8c1..b3372df 100644

hw/acpi/aml-build.c Aml *aml_add(Aml *arg1, Aml *arg2) · line 485

Quoted 9 lines
hw/acpi/aml-build.c +6 -0
@@ -477,6 +477,19 @@ Aml *aml_add(Aml *arg1, Aml *arg2)
      return var;
  }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefIndex */
+Aml *aml_index(Aml *arg1, Aml *idx)
+{
+    Aml *var = aml_opcode(0x88 /* IndexOp */);
+
+    g_assert(arg1->block_flags & (AML_PACKAGE | AML_EXT_PACKAGE | AML_BUFFER));

it couldn't be AML_EXT_PACKAGE, it's either a plain DefPackage or DefBuffer i.e. I'd suggest to add to above check also checking for specific opcodes arg1->op = 0x11 /* buffer */ ...

Quoted 6 lines
Quoted 1 line

Also a newer spec (>1.0b) allows to use DefString as argument as well.

You really can have a lot of things there, e.g. a method call will also work.
I think it's best to drop these asserts at this point, and maybe blacklist specific bad configs down the road.

OK, I'll drop the assert for now.

Thanks,
Marcel

#16 lore raw

PATCH v4 6/25 acpi: add aml_shiftleft() term

In reply to Marcel Apfelbaum

Add encoding for ACPI DefShiftLeft Opcode.

---
 hw/acpi/aml-build.c         | 10 ++++++++++
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 11 insertions(+)
hw/acpi/aml-build.c +10 -0
index b3372df..497713e 100644
@@ -458,6 +458,16 @@ Aml *aml_or(Aml *arg1, Aml *arg2)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefShiftLeft */
+Aml *aml_shiftleft(Aml *arg1, Aml *count)
+{
+    Aml *var = aml_opcode(0x79 /* ShiftLeftOp */);
+    aml_append(var, arg1);
+    aml_append(var, count);
+    build_append_int(var->buf, 0x00); /* NullNameOp */
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLLess */
 Aml *aml_lless(Aml *arg1, Aml *arg2)
 {
include/hw/acpi/aml-build.h +1 -0
index b860732..4ab0533 100644
@@ -138,6 +138,7 @@ Aml *aml_arg(int pos);
 Aml *aml_store(Aml *val, Aml *target);
 Aml *aml_and(Aml *arg1, Aml *arg2);
 Aml *aml_or(Aml *arg1, Aml *arg2);
+Aml *aml_shiftleft(Aml *arg1, Aml *count);
 Aml *aml_lless(Aml *arg1, Aml *arg2);
 Aml *aml_add(Aml *arg1, Aml *arg2);
 Aml *aml_index(Aml *arg1, Aml *idx);
Signature · 1 line
2.1.0
#17 lore raw

PATCH v4 7/25 acpi: add aml_shiftright() term

In reply to Marcel Apfelbaum

Add encoding for ACPI DefShiftRight Opcode.

---
 hw/acpi/aml-build.c         | 10 ++++++++++
 include/hw/acpi/aml-build.h |  1 +
 2 files changed, 11 insertions(+)
hw/acpi/aml-build.c +10 -0
index 497713e..09a543c 100644
@@ -468,6 +468,16 @@ Aml *aml_shiftleft(Aml *arg1, Aml *count)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefShiftRight */
+Aml *aml_shiftright(Aml *arg1, Aml *count)
+{
+    Aml *var = aml_opcode(0x7A /* ShiftRightOp */);
+    aml_append(var, arg1);
+    aml_append(var, count);
+    build_append_int(var->buf, 0x00); /* NullNameOp */
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLLess */
 Aml *aml_lless(Aml *arg1, Aml *arg2)
 {
include/hw/acpi/aml-build.h +1 -0
index 4ab0533..74a9033 100644
@@ -139,6 +139,7 @@ Aml *aml_store(Aml *val, Aml *target);
 Aml *aml_and(Aml *arg1, Aml *arg2);
 Aml *aml_or(Aml *arg1, Aml *arg2);
 Aml *aml_shiftleft(Aml *arg1, Aml *count);
+Aml *aml_shiftright(Aml *arg1, Aml *count);
 Aml *aml_lless(Aml *arg1, Aml *arg2);
 Aml *aml_add(Aml *arg1, Aml *arg2);
 Aml *aml_index(Aml *arg1, Aml *idx);
Signature · 1 line
2.1.0
#18 lore raw

PATCH v4 8/25 acpi: add aml_increment() term

In reply to Marcel Apfelbaum

Add encoding for ACPI DefIncrement Opcode.

---
 hw/acpi/aml-build.c         | 8 ++++++++
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 9 insertions(+)
hw/acpi/aml-build.c +8 -0
index 09a543c..6315ea0 100644
@@ -497,6 +497,14 @@ Aml *aml_add(Aml *arg1, Aml *arg2)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefIncrement */
+Aml *aml_increment(Aml *arg)
+{
+    Aml *var = aml_opcode(0x75 /* IncrementOp */);
+    aml_append(var, arg);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefIndex */
 Aml *aml_index(Aml *arg1, Aml *idx)
 {
include/hw/acpi/aml-build.h +1 -0
index 74a9033..c41f400 100644
@@ -142,6 +142,7 @@ Aml *aml_shiftleft(Aml *arg1, Aml *count);
 Aml *aml_shiftright(Aml *arg1, Aml *count);
 Aml *aml_lless(Aml *arg1, Aml *arg2);
 Aml *aml_add(Aml *arg1, Aml *arg2);
+Aml *aml_increment(Aml *arg);
 Aml *aml_index(Aml *arg1, Aml *idx);
 Aml *aml_notify(Aml *arg1, Aml *arg2);
 Aml *aml_call1(const char *method, Aml *arg1);
Signature · 1 line
2.1.0
#19 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 08/25] acpi: add aml_increment() term

Quoted 43 lines · Marcel Apfelbaum

Add encoding for ACPI DefIncrement Opcode.

---
 hw/acpi/aml-build.c         | 8 ++++++++
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 9 insertions(+)
hw/acpi/aml-build.c +8 -0
index 09a543c..6315ea0 100644
@@ -497,6 +497,14 @@ Aml *aml_add(Aml *arg1, Aml *arg2)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefIncrement */
+Aml *aml_increment(Aml *arg)
+{
+    Aml *var = aml_opcode(0x75 /* IncrementOp */);
+    aml_append(var, arg);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefIndex */
 Aml *aml_index(Aml *arg1, Aml *idx)
 {
include/hw/acpi/aml-build.h +1 -0
index 74a9033..c41f400 100644
@@ -142,6 +142,7 @@ Aml *aml_shiftleft(Aml *arg1, Aml *count);
 Aml *aml_shiftright(Aml *arg1, Aml *count);
 Aml *aml_lless(Aml *arg1, Aml *arg2);
 Aml *aml_add(Aml *arg1, Aml *arg2);
+Aml *aml_increment(Aml *arg);
 Aml *aml_index(Aml *arg1, Aml *idx);
 Aml *aml_notify(Aml *arg1, Aml *arg2);
 Aml *aml_call1(const char *method, Aml *arg1);
Signature · 2 lines
Thanks,
Shannon
Reviewed-by on v4 8/25
#20 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 08/25] acpi: add aml_increment() term

In reply to Marcel Apfelbaum
Quoted 4 lines · Marcel Apfelbaum

Add encoding for ACPI DefIncrement Opcode.

Quoted 37 lines
---
 hw/acpi/aml-build.c         | 8 ++++++++
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 9 insertions(+)
hw/acpi/aml-build.c +8 -0
index 09a543c..6315ea0 100644
@@ -497,6 +497,14 @@ Aml *aml_add(Aml *arg1, Aml *arg2)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefIncrement */
+Aml *aml_increment(Aml *arg)
+{
+    Aml *var = aml_opcode(0x75 /* IncrementOp */);
+    aml_append(var, arg);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefIndex */
 Aml *aml_index(Aml *arg1, Aml *idx)
 {
include/hw/acpi/aml-build.h +1 -0
index 74a9033..c41f400 100644
@@ -142,6 +142,7 @@ Aml *aml_shiftleft(Aml *arg1, Aml *count);
 Aml *aml_shiftright(Aml *arg1, Aml *count);
 Aml *aml_lless(Aml *arg1, Aml *arg2);
 Aml *aml_add(Aml *arg1, Aml *arg2);
+Aml *aml_increment(Aml *arg);
 Aml *aml_index(Aml *arg1, Aml *idx);
 Aml *aml_notify(Aml *arg1, Aml *arg2);
 Aml *aml_call1(const char *method, Aml *arg1);
#21 lore raw

PATCH v4 9/25 acpi: add aml_while() term

In reply to Marcel Apfelbaum

Add encoding for ACPI DefWhile Opcode.

---
 hw/acpi/aml-build.c         | 8 ++++++++
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 9 insertions(+)
hw/acpi/aml-build.c +8 -0
index 6315ea0..f85a0fb 100644
@@ -623,6 +623,14 @@ Aml *aml_if(Aml *predicate)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefWhile */
+Aml *aml_while(Aml *predicate)
+{
+    Aml *var = aml_bundle(0xA2 /* WhileOp */, AML_PACKAGE);
+    aml_append(var, predicate);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefMethod */
 Aml *aml_method(const char *name, int arg_count)
 {
include/hw/acpi/aml-build.h +1 -0
index c41f400..4f695a2 100644
@@ -189,6 +189,7 @@ Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_method(const char *name, int arg_count);
 Aml *aml_if(Aml *predicate);
+Aml *aml_while(Aml *predicate);
 Aml *aml_package(uint8_t num_elements);
 Aml *aml_buffer(void);
 Aml *aml_resource_template(void);
Signature · 1 line
2.1.0
Reviewed-by on v4 9/25
#22 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 09/25] acpi: add aml_while() term

Quoted 4 lines · Marcel Apfelbaum

Add encoding for ACPI DefWhile Opcode.

Quoted 37 lines
---
 hw/acpi/aml-build.c         | 8 ++++++++
 include/hw/acpi/aml-build.h | 1 +
 2 files changed, 9 insertions(+)
hw/acpi/aml-build.c +8 -0
index 6315ea0..f85a0fb 100644
@@ -623,6 +623,14 @@ Aml *aml_if(Aml *predicate)
     return var;
 }
 
+/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefWhile */
+Aml *aml_while(Aml *predicate)
+{
+    Aml *var = aml_bundle(0xA2 /* WhileOp */, AML_PACKAGE);
+    aml_append(var, predicate);
+    return var;
+}
+
 /* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefMethod */
 Aml *aml_method(const char *name, int arg_count)
 {
include/hw/acpi/aml-build.h +1 -0
index c41f400..4f695a2 100644
@@ -189,6 +189,7 @@ Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_device(const char *name_format, ...) GCC_FMT_ATTR(1, 2);
 Aml *aml_method(const char *name, int arg_count);
 Aml *aml_if(Aml *predicate);
+Aml *aml_while(Aml *predicate);
 Aml *aml_package(uint8_t num_elements);
 Aml *aml_buffer(void);
 Aml *aml_resource_template(void);
Signature · 2 lines
Thanks,
Shannon
#23 lore raw

PATCH v4 10/25 hw/acpi: add support for multiple root busses

In reply to Marcel Apfelbaum

If the machine has several root busses, we need to add them to acpi in order to be properly detected by guests.

---
 hw/i386/acpi-build.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
hw/i386/acpi-build.c +32 -0
index b94e47e..e5709e8 100644
@@ -60,6 +60,8 @@
 #include "qom/qom-qobject.h"
 #include "exec/ram_addr.h"
 
+#include "qmp-commands.h"
+
 /* These are used to size the ACPI tables for -M pc-i440fx-1.7 and
  * -M pc-i440fx-2.0.  Even if the actual amount of AML generated grows
  * a little bit, there should be plenty of free space since the DSDT
@@ -682,6 +684,36 @@ build_ssdt(GArray *table_data, GArray *linker,
     /* Reserve space for header */
     acpi_data_push(ssdt->buf, sizeof(AcpiTableHeader));
 
+    {
+        PciInfoList *info_list, *info;
+        Error *err = NULL;
+
+        info_list = qmp_query_pci(&err);
+        if (err) {
+            error_free(err);
+            return;
+        }
+
+        for (info = info_list; info; info = info->next) {
+            PciInfo *bus_info = info->value;
+
+            if (bus_info->bus == 0) {
+                continue;
+            }
+
+            scope = aml_scope("\\_SB");
+            dev = aml_device("PC%.02X", (uint8_t)bus_info->bus);
+            aml_append(dev, aml_name_decl("_UID",
+                aml_string("PC%.02X", (uint8_t)bus_info->bus)));
+            aml_append(dev, aml_name_decl("_HID", aml_string("PNP0A03")));
+            aml_append(dev,
+                aml_name_decl("_BBN", aml_int((uint8_t)bus_info->bus)));
+            aml_append(scope, dev);
+            aml_append(ssdt, scope);
+        }
+        qapi_free_PciInfoList(info_list);
+    }
+
     scope = aml_scope("\\_SB.PCI0");
     /* build PCI0._CRS */
     crs = aml_resource_template();
Signature · 1 line
2.1.0
#24 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 10/25] hw/acpi: add support for multiple root busses

Quoted 39 lines · Marcel Apfelbaum

If the machine has several root busses, we need to add them to acpi in order to be properly detected by guests.

---
 hw/i386/acpi-build.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
hw/i386/acpi-build.c +16 -0
index b94e47e..e5709e8 100644
@@ -60,6 +60,8 @@
 #include "qom/qom-qobject.h"
 #include "exec/ram_addr.h"
 
+#include "qmp-commands.h"
+
 /* These are used to size the ACPI tables for -M pc-i440fx-1.7 and
  * -M pc-i440fx-2.0.  Even if the actual amount of AML generated grows
  * a little bit, there should be plenty of free space since the DSDT
@@ -682,6 +684,36 @@ build_ssdt(GArray *table_data, GArray *linker,
     /* Reserve space for header */
     acpi_data_push(ssdt->buf, sizeof(AcpiTableHeader));
 
+    {
+        PciInfoList *info_list, *info;
+        Error *err = NULL;
+
+        info_list = qmp_query_pci(&err);
+        if (err) {
+            error_free(err);
+            return;
+        }
+
+        for (info = info_list; info; info = info->next) {
+            PciInfo *bus_info = info->value;
+
+            if (bus_info->bus == 0) {

hw/i386/acpi-build.c build_ssdt(GArray *table_data, GArray *linker, · line 710

Quoted 10 lines
hw/i386/acpi-build.c +10 -0
+                continue;
+            }
+
+            scope = aml_scope("\\_SB");
+            dev = aml_device("PC%.02X", (uint8_t)bus_info->bus);
+            aml_append(dev, aml_name_decl("_UID",
+                aml_string("PC%.02X", (uint8_t)bus_info->bus)));
+            aml_append(dev, aml_name_decl("_HID", aml_string("PNP0A03")));
+            aml_append(dev,
+                aml_name_decl("_BBN", aml_int((uint8_t)bus_info->bus)));

Hmm not all pci buses have hardware-assigned bus numbers, a separate segment is also an option.
How about only getting your specific ones?

Quoted 11 lines
hw/i386/acpi-build.c +6 -0
+            aml_append(scope, dev);
+            aml_append(ssdt, scope);
+        }
+        qapi_free_PciInfoList(info_list);
+    }
+
     scope = aml_scope("\\_SB.PCI0");
     /* build PCI0._CRS */
     crs = aml_resource_template();
Signature · 1 line
2.1.0
#25 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 10/25] hw/acpi: add support for multiple root busses

Quoted 26 lines · Michael S. Tsirkin
Quoted 25 lines · Marcel Apfelbaum

If the machine has several root busses, we need to add them to acpi in order to be properly detected by guests.

---
  hw/i386/acpi-build.c | 32 ++++++++++++++++++++++++++++++++
  1 file changed, 32 insertions(+)
hw/i386/acpi-build.c +2 -0
index b94e47e..e5709e8 100644
@@ -60,6 +60,8 @@
  #include "qom/qom-qobject.h"
  #include "exec/ram_addr.h"
 
+#include "qmp-commands.h"
+
  /* These are used to size the ACPI tables for -M pc-i440fx-1.7 and
   * -M pc-i440fx-2.0.  Even if the actual amount of AML generated grows
   * a little bit, there should be plenty of free space since the DSDT
@@ -682,6 +684,36 @@ build_ssdt(GArray *table_data, GArray *linker,
      /* Reserve space for header */
      acpi_data_push(ssdt->buf, sizeof(AcpiTableHeader));
 
Quoted 13 lines

hw/i386/acpi-build.c build_ssdt(GArray *table_data, GArray *linker, · line 699

Quoted 13 lines
hw/i386/acpi-build.c +13 -0
+    {
+        PciInfoList *info_list, *info;
+        Error *err = NULL;
+
+        info_list = qmp_query_pci(&err);
+        if (err) {
+            error_free(err);
+            return;
+        }
+
+        for (info = info_list; info; info = info->next) {
+            PciInfo *bus_info = info->value;
+

Hi,

Quoted 3 lines

hw/i386/acpi-build.c build_ssdt(GArray *table_data, GArray *linker, · line 702

Quoted 3 lines
hw/i386/acpi-build.c +3 -0
+            if (bus_info->bus == 0) {
+                continue;
+            }

[1] This code works only for root buses with bus number > 0

Quoted 9 lines

hw/i386/acpi-build.c build_ssdt(GArray *table_data, GArray *linker, · line 710

Quoted 8 lines
hw/i386/acpi-build.c +8 -0
+
+            scope = aml_scope("\\_SB");
+            dev = aml_device("PC%.02X", (uint8_t)bus_info->bus);
+            aml_append(dev, aml_name_decl("_UID",
+                aml_string("PC%.02X", (uint8_t)bus_info->bus)));
+            aml_append(dev, aml_name_decl("_HID", aml_string("PNP0A03")));
+            aml_append(dev,
+                aml_name_decl("_BBN", aml_int((uint8_t)bus_info->bus)));
Quoted 3 lines

Hmm not all pci buses have hardware-assigned bus numbers, a separate segment is also an option.
How about only getting your specific ones?

As you can see it [1] we only deal with buses that have hardware-assigned bus numbers, and if the bus number is > 0, we *must* supply BBN. So at the end, it works only for our PXBs.

Thanks,
Marcel

Quoted 13 lines
Quoted 13 lines
hw/i386/acpi-build.c +6 -1
+            aml_append(scope, dev);
+            aml_append(ssdt, scope);
+        }
+        qapi_free_PciInfoList(info_list);
+    }
+
      scope = aml_scope("\\_SB.PCI0");
      /* build PCI0._CRS */
      crs = aml_resource_template();
--

2.1.0

#26 lore raw

PATCH v4 11/25 hw/apci: add _PRT method for extra PCI root busses

In reply to Marcel Apfelbaum
---
 hw/i386/acpi-build.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
hw/i386/acpi-build.c +65 -0
index e5709e8..e7a1a36 100644
@@ -664,6 +664,70 @@ static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus,
     aml_append(parent_scope, method);
 }
 
+static Aml *build_link(Aml *lnk, Aml *lnk_pkg, const char *link_name, int idx)
+{
+    Aml *if_ctx, *pkg;
+
+    if_ctx = aml_if(aml_equal(lnk, aml_int(idx)));
+    pkg = aml_package(4);
+    aml_append(pkg, aml_int(0));
+    aml_append(pkg, aml_int(0));
+    aml_append(pkg, aml_name(link_name, ""));
+    aml_append(pkg, aml_int(0));
+    aml_append(if_ctx, aml_store(pkg, lnk_pkg));
+
+    return if_ctx;
+}
+
+static Aml *build_prt(void)
+{
+    Aml *method, *while_ctx, *pin, *slot, *lnk, *pkg, *res;
+
+    method = aml_method("_PRT", 0);
+    res = aml_local(0);
+    pin = aml_local(1);
+    slot = aml_local(2);
+    lnk = aml_local(3);
+    pkg = aml_local(4);
+
+    aml_append(method, aml_store(aml_package(128), res));
+    aml_append(method, aml_store(aml_int(0), pin));
+
+    /* while (pin < 128) */
+    while_ctx = aml_while(aml_lless(pin, aml_int(128)));
+    {
+        /* slot = pin >> 2 */
+        aml_append(while_ctx,
+                   aml_store(aml_shiftright(pin, aml_int(2)), slot));
+        /* lnk = (slot + pin) & 3 */
+        aml_append(while_ctx,
+                   aml_store(aml_and(aml_add(pin, slot), aml_int(3)), lnk));
+
+        /* pkg[2] = "LNK[A|B|C|D]", selection based on lnk % 3  */
+        aml_append(while_ctx, build_link(lnk, pkg, "LNKD", 0));
+        aml_append(while_ctx, build_link(lnk, pkg, "LNKA", 1));
+        aml_append(while_ctx, build_link(lnk, pkg, "LNKB", 2));
+        aml_append(while_ctx, build_link(lnk, pkg, "LNKC", 3));
+
+        /* pkg[0] = 0x[slot]FFFF */
+        aml_append(while_ctx,
+            aml_store(aml_or(aml_shiftleft(slot, aml_int(16)), aml_int(0xFFFF)),
+                      aml_index(pkg, aml_int(0))));
+        /* pkg[1] = pin & 3 */
+        aml_append(while_ctx,
+            aml_store(aml_and(pin, aml_int(3)), aml_index(pkg, aml_int(1))));
+        /* res[pin] = pkg */
+        aml_append(while_ctx, aml_store(pkg, aml_index(res, pin)));
+        /* pin++ */
+        aml_append(while_ctx, aml_increment(pin));
+    }
+    aml_append(method, while_ctx);
+    /* return res*/
+    aml_append(method, aml_return(res));
+
+    return method;
+}
+
 static void
 build_ssdt(GArray *table_data, GArray *linker,
            AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -708,6 +772,7 @@ build_ssdt(GArray *table_data, GArray *linker,
             aml_append(dev, aml_name_decl("_HID", aml_string("PNP0A03")));
             aml_append(dev,
                 aml_name_decl("_BBN", aml_int((uint8_t)bus_info->bus)));
+            aml_append(dev, build_prt());
             aml_append(scope, dev);
             aml_append(ssdt, scope);
         }
Signature · 1 line
2.1.0
#27 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 11/25] hw/apci: add _PRT method for extra PCI root busses

Quoted 10 lines · Marcel Apfelbaum
---
 hw/i386/acpi-build.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
hw/i386/acpi-build.c +0 -0
index e5709e8..e7a1a36 100644

hw/i386/acpi-build.c static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus, · line 667

Quoted 4 lines
hw/i386/acpi-build.c +1 -0
@@ -664,6 +664,70 @@ static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus,
     aml_append(parent_scope, method);
 }
 
+static Aml *build_link(Aml *lnk, Aml *lnk_pkg, const char *link_name, int idx)

Pls document arguments, and generally make this function more readable.

hw/i386/acpi-build.c static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus, · line 672

Quoted 5 lines
hw/i386/acpi-build.c +5 -0
+{
+    Aml *if_ctx, *pkg;
+
+    if_ctx = aml_if(aml_equal(lnk, aml_int(idx)));
+    pkg = aml_package(4);

These assignments can be part of declarations.

hw/i386/acpi-build.c static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus, · line 675

Quoted 3 lines
hw/i386/acpi-build.c +3 -0
+    aml_append(pkg, aml_int(0));
+    aml_append(pkg, aml_int(0));
+    aml_append(pkg, aml_name(link_name, ""));

this sould be aml_name(link_name) I think?

Quoted 21 lines
hw/i386/acpi-build.c +21 -0
+    aml_append(pkg, aml_int(0));
+    aml_append(if_ctx, aml_store(pkg, lnk_pkg));
+
+    return if_ctx;
+}
+
+static Aml *build_prt(void)
+{
+    Aml *method, *while_ctx, *pin, *slot, *lnk, *pkg, *res;
+
+    method = aml_method("_PRT", 0);
+    res = aml_local(0);
+    pin = aml_local(1);
+    slot = aml_local(2);
+    lnk = aml_local(3);
+    pkg = aml_local(4);
+
+    aml_append(method, aml_store(aml_package(128), res));
+    aml_append(method, aml_store(aml_int(0), pin));
+
+    /* while (pin < 128) */

hw/i386/acpi-build.c static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus, · line 706

Quoted 10 lines
hw/i386/acpi-build.c +10 -0
+    while_ctx = aml_while(aml_lless(pin, aml_int(128)));
+    {
+        /* slot = pin >> 2 */
+        aml_append(while_ctx,
+                   aml_store(aml_shiftright(pin, aml_int(2)), slot));
+        /* lnk = (slot + pin) & 3 */
+        aml_append(while_ctx,
+                   aml_store(aml_and(aml_add(pin, slot), aml_int(3)), lnk));
+
+        /* pkg[2] = "LNK[A|B|C|D]", selection based on lnk % 3  */

in fact pkg here is not same as pkg above, is it?

Quoted 37 lines
hw/i386/acpi-build.c +25 -0
+        aml_append(while_ctx, build_link(lnk, pkg, "LNKD", 0));
+        aml_append(while_ctx, build_link(lnk, pkg, "LNKA", 1));
+        aml_append(while_ctx, build_link(lnk, pkg, "LNKB", 2));
+        aml_append(while_ctx, build_link(lnk, pkg, "LNKC", 3));
+
+        /* pkg[0] = 0x[slot]FFFF */
+        aml_append(while_ctx,
+            aml_store(aml_or(aml_shiftleft(slot, aml_int(16)), aml_int(0xFFFF)),
+                      aml_index(pkg, aml_int(0))));
+        /* pkg[1] = pin & 3 */
+        aml_append(while_ctx,
+            aml_store(aml_and(pin, aml_int(3)), aml_index(pkg, aml_int(1))));
+        /* res[pin] = pkg */
+        aml_append(while_ctx, aml_store(pkg, aml_index(res, pin)));
+        /* pin++ */
+        aml_append(while_ctx, aml_increment(pin));
+    }
+    aml_append(method, while_ctx);
+    /* return res*/
+    aml_append(method, aml_return(res));
+
+    return method;
+}
+
 static void
 build_ssdt(GArray *table_data, GArray *linker,
            AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -708,6 +772,7 @@ build_ssdt(GArray *table_data, GArray *linker,
             aml_append(dev, aml_name_decl("_HID", aml_string("PNP0A03")));
             aml_append(dev,
                 aml_name_decl("_BBN", aml_int((uint8_t)bus_info->bus)));
+            aml_append(dev, build_prt());
             aml_append(scope, dev);
             aml_append(ssdt, scope);
         }
Signature · 1 line
2.1.0
#28 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 11/25] hw/apci: add _PRT method for extra PCI root busses

Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · Marcel Apfelbaum
---
  hw/i386/acpi-build.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 65 insertions(+)
hw/i386/acpi-build.c +0 -0
index e5709e8..e7a1a36 100644
@@ -664,6 +664,70 @@ static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus,
      aml_append(parent_scope, method);
  }
 
Quoted 4 lines

hw/i386/acpi-build.c static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus, · line 667

Quoted 1 line
hw/i386/acpi-build.c +1 -0
+static Aml *build_link(Aml *lnk, Aml *lnk_pkg, const char *link_name, int idx)

Pls document arguments, and generally make this function more readable.

I'll think of something

Quoted 8 lines

hw/i386/acpi-build.c static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus, · line 672

Quoted 6 lines
hw/i386/acpi-build.c +5 -0
+{
+    Aml *if_ctx, *pkg;
+
+    if_ctx = aml_if(aml_equal(lnk, aml_int(idx)));
+    pkg = aml_package(4);

These assignments can be part of declarations.

OK

Quoted 6 lines

hw/i386/acpi-build.c static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus, · line 675

Quoted 4 lines
hw/i386/acpi-build.c +3 -0
+    aml_append(pkg, aml_int(0));
+    aml_append(pkg, aml_int(0));
+    aml_append(pkg, aml_name(link_name, ""));

this sould be aml_name(link_name) I think?

It doesn't work without the "" agument, works only for literals. If you have any idea how to make it work, I'll be glad to change it.

Quoted 26 lines
Quoted 26 lines
hw/i386/acpi-build.c +25 -0
+    aml_append(pkg, aml_int(0));
+    aml_append(if_ctx, aml_store(pkg, lnk_pkg));
+
+    return if_ctx;
+}
+
+static Aml *build_prt(void)
+{
+    Aml *method, *while_ctx, *pin, *slot, *lnk, *pkg, *res;
+
+    method = aml_method("_PRT", 0);
+    res = aml_local(0);
+    pin = aml_local(1);
+    slot = aml_local(2);
+    lnk = aml_local(3);
+    pkg = aml_local(4);
+
+    aml_append(method, aml_store(aml_package(128), res));
+    aml_append(method, aml_store(aml_int(0), pin));
+
+    /* while (pin < 128) */
+    while_ctx = aml_while(aml_lless(pin, aml_int(128)));
+    {
+        /* slot = pin >> 2 */
+        aml_append(while_ctx,
Quoted 8 lines

hw/i386/acpi-build.c static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus, · line 706

Quoted 6 lines
hw/i386/acpi-build.c +6 -0
+                   aml_store(aml_shiftright(pin, aml_int(2)), slot));
+        /* lnk = (slot + pin) & 3 */
+        aml_append(while_ctx,
+                   aml_store(aml_and(aml_add(pin, slot), aml_int(3)), lnk));
+
+        /* pkg[2] = "LNK[A|B|C|D]", selection based on lnk % 3  */

in fact pkg here is not same as pkg above, is it?

The same, but I can move the declaration to the while block.

Thanks,
Marcel

Quoted 38 lines
Quoted 38 lines
hw/i386/acpi-build.c +25 -1
+        aml_append(while_ctx, build_link(lnk, pkg, "LNKD", 0));
+        aml_append(while_ctx, build_link(lnk, pkg, "LNKA", 1));
+        aml_append(while_ctx, build_link(lnk, pkg, "LNKB", 2));
+        aml_append(while_ctx, build_link(lnk, pkg, "LNKC", 3));
+
+        /* pkg[0] = 0x[slot]FFFF */
+        aml_append(while_ctx,
+            aml_store(aml_or(aml_shiftleft(slot, aml_int(16)), aml_int(0xFFFF)),
+                      aml_index(pkg, aml_int(0))));
+        /* pkg[1] = pin & 3 */
+        aml_append(while_ctx,
+            aml_store(aml_and(pin, aml_int(3)), aml_index(pkg, aml_int(1))));
+        /* res[pin] = pkg */
+        aml_append(while_ctx, aml_store(pkg, aml_index(res, pin)));
+        /* pin++ */
+        aml_append(while_ctx, aml_increment(pin));
+    }
+    aml_append(method, while_ctx);
+    /* return res*/
+    aml_append(method, aml_return(res));
+
+    return method;
+}
+
  static void
  build_ssdt(GArray *table_data, GArray *linker,
             AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -708,6 +772,7 @@ build_ssdt(GArray *table_data, GArray *linker,
              aml_append(dev, aml_name_decl("_HID", aml_string("PNP0A03")));
              aml_append(dev,
                  aml_name_decl("_BBN", aml_int((uint8_t)bus_info->bus)));
+            aml_append(dev, build_prt());
              aml_append(scope, dev);
              aml_append(ssdt, scope);
          }
--

2.1.0

#29 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 11/25] hw/apci: add _PRT method for extra PCI root busses

Quoted 32 lines · Marcel Apfelbaum
Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · Marcel Apfelbaum
---
 hw/i386/acpi-build.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
hw/i386/acpi-build.c +0 -0
index e5709e8..e7a1a36 100644
@@ -664,6 +664,70 @@ static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus,
     aml_append(parent_scope, method);
 }
 
Quoted 4 lines

hw/i386/acpi-build.c static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus, · line 667

Quoted 1 line
hw/i386/acpi-build.c +1 -0
+static Aml *build_link(Aml *lnk, Aml *lnk_pkg, const char *link_name, int idx)

Pls document arguments, and generally make this function more readable.

I'll think of something

Quoted 8 lines

hw/i386/acpi-build.c static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus, · line 672

Quoted 6 lines
hw/i386/acpi-build.c +5 -0
+{
+    Aml *if_ctx, *pkg;
+
+    if_ctx = aml_if(aml_equal(lnk, aml_int(idx)));
+    pkg = aml_package(4);

These assignments can be part of declarations.

OK

Quoted 1 line
Quoted 7 lines
Quoted 5 lines

hw/i386/acpi-build.c static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus, · line 675

Quoted 3 lines
hw/i386/acpi-build.c +3 -0
+    aml_append(pkg, aml_int(0));
+    aml_append(pkg, aml_int(0));
+    aml_append(pkg, aml_name(link_name, ""));

this sould be aml_name(link_name) I think?

It doesn't work without the "" agument, works only for literals. If you have any idea how to make it work, I'll be glad to change it.

So use "%s" format then.

Quoted 77 lines
Quoted 26 lines
Quoted 26 lines
hw/i386/acpi-build.c +25 -0
+    aml_append(pkg, aml_int(0));
+    aml_append(if_ctx, aml_store(pkg, lnk_pkg));
+
+    return if_ctx;
+}
+
+static Aml *build_prt(void)
+{
+    Aml *method, *while_ctx, *pin, *slot, *lnk, *pkg, *res;
+
+    method = aml_method("_PRT", 0);
+    res = aml_local(0);
+    pin = aml_local(1);
+    slot = aml_local(2);
+    lnk = aml_local(3);
+    pkg = aml_local(4);
+
+    aml_append(method, aml_store(aml_package(128), res));
+    aml_append(method, aml_store(aml_int(0), pin));
+
+    /* while (pin < 128) */
+    while_ctx = aml_while(aml_lless(pin, aml_int(128)));
+    {
+        /* slot = pin >> 2 */
+        aml_append(while_ctx,
Quoted 8 lines

hw/i386/acpi-build.c static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus, · line 706

Quoted 6 lines
hw/i386/acpi-build.c +6 -0
+                   aml_store(aml_shiftright(pin, aml_int(2)), slot));
+        /* lnk = (slot + pin) & 3 */
+        aml_append(while_ctx,
+                   aml_store(aml_and(aml_add(pin, slot), aml_int(3)), lnk));
+
+        /* pkg[2] = "LNK[A|B|C|D]", selection based on lnk % 3  */

in fact pkg here is not same as pkg above, is it?

The same, but I can move the declaration to the while block.

Thanks,
Marcel

Quoted 38 lines
Quoted 38 lines
hw/i386/acpi-build.c +25 -1
+        aml_append(while_ctx, build_link(lnk, pkg, "LNKD", 0));
+        aml_append(while_ctx, build_link(lnk, pkg, "LNKA", 1));
+        aml_append(while_ctx, build_link(lnk, pkg, "LNKB", 2));
+        aml_append(while_ctx, build_link(lnk, pkg, "LNKC", 3));
+
+        /* pkg[0] = 0x[slot]FFFF */
+        aml_append(while_ctx,
+            aml_store(aml_or(aml_shiftleft(slot, aml_int(16)), aml_int(0xFFFF)),
+                      aml_index(pkg, aml_int(0))));
+        /* pkg[1] = pin & 3 */
+        aml_append(while_ctx,
+            aml_store(aml_and(pin, aml_int(3)), aml_index(pkg, aml_int(1))));
+        /* res[pin] = pkg */
+        aml_append(while_ctx, aml_store(pkg, aml_index(res, pin)));
+        /* pin++ */
+        aml_append(while_ctx, aml_increment(pin));
+    }
+    aml_append(method, while_ctx);
+    /* return res*/
+    aml_append(method, aml_return(res));
+
+    return method;
+}
+
 static void
 build_ssdt(GArray *table_data, GArray *linker,
            AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -708,6 +772,7 @@ build_ssdt(GArray *table_data, GArray *linker,
             aml_append(dev, aml_name_decl("_HID", aml_string("PNP0A03")));
             aml_append(dev,
                 aml_name_decl("_BBN", aml_int((uint8_t)bus_info->bus)));
+            aml_append(dev, build_prt());
             aml_append(scope, dev);
             aml_append(ssdt, scope);
         }
--

2.1.0

#30 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 11/25] hw/apci: add _PRT method for extra PCI root busses

Quoted 33 lines · Michael S. Tsirkin
Quoted 32 lines · Marcel Apfelbaum
Quoted 32 lines · Michael S. Tsirkin
Quoted 14 lines
Quoted 14 lines · Marcel Apfelbaum
Quoted 13 lines
Quoted 13 lines
---
 hw/i386/acpi-build.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
hw/i386/acpi-build.c +0 -0
index e5709e8..e7a1a36 100644
@@ -664,6 +664,70 @@ static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus,
     aml_append(parent_scope, method);
 }
 
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

hw/i386/acpi-build.c static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus, · line 667

Quoted 1 line
hw/i386/acpi-build.c +1 -0
+static Aml *build_link(Aml *lnk, Aml *lnk_pkg, const char *link_name, int idx)

Pls document arguments, and generally make this function more readable.

I'll think of something

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

hw/i386/acpi-build.c static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus, · line 672

Quoted 6 lines
hw/i386/acpi-build.c +5 -0
+{
+    Aml *if_ctx, *pkg;
+
+    if_ctx = aml_if(aml_equal(lnk, aml_int(idx)));
+    pkg = aml_package(4);

These assignments can be part of declarations.

OK

Quoted 1 line
Quoted 1 line
Quoted 9 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

hw/i386/acpi-build.c static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus, · line 675

Quoted 3 lines
hw/i386/acpi-build.c +3 -0
+    aml_append(pkg, aml_int(0));
+    aml_append(pkg, aml_int(0));
+    aml_append(pkg, aml_name(link_name, ""));

this sould be aml_name(link_name) I think?

It doesn't work without the "" agument, works only for literals. If you have any idea how to make it work, I'll be glad to change it.

So use "%s" format then.

Yes, use aml_name("%s", link_name) it should work.

Signature · 2 lines
Thanks,
Shannon
#31 lore raw

PATCH v4 12/25 hw/acpi: add _CRS method for extra root busses

In reply to Marcel Apfelbaum

Save the IO/mem/bus numbers ranges assigned to the extra root busses to be removed from the root bus 0 range.

---
 hw/i386/acpi-build.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 149 insertions(+)
hw/i386/acpi-build.c +149 -0
index e7a1a36..f4d8816 100644
@@ -728,6 +728,148 @@ static Aml *build_prt(void)
     return method;
 }
 
+typedef struct PciRangeEntry {
+    QLIST_ENTRY(PciRangeEntry) entry;
+    int64_t base;
+    int64_t limit;
+} PciRangeEntry;
+
+typedef QLIST_HEAD(PciRangeQ, PciRangeEntry) PciRangeQ;
+
+static void pci_range_insert(PciRangeQ *list, int64_t base, int64_t limit)
+{
+    PciRangeEntry *entry, *next, *e;
+
+    if (!base) {
+        return;
+    }
+
+    e = g_malloc(sizeof(*entry));
+    e->base = base;
+    e->limit = limit;
+
+    if (QLIST_EMPTY(list)) {
+        QLIST_INSERT_HEAD(list, e, entry);
+    } else {
+        QLIST_FOREACH_SAFE(entry, list, entry, next) {
+            if (base < entry->base) {
+                QLIST_INSERT_BEFORE(entry, e, entry);
+                break;
+            } else if (!next) {
+                QLIST_INSERT_AFTER(entry, e, entry);
+                break;
+            }
+        }
+    }
+}
+
+static void pci_range_list_free(PciRangeQ *list)
+{
+    PciRangeEntry *entry, *next;
+
+    QLIST_FOREACH_SAFE(entry, list, entry, next) {
+        QLIST_REMOVE(entry, entry);
+        g_free(entry);
+    }
+}
+
+static Aml *build_crs(PcPciInfo *pci, PciInfo *bus_info,
+                      PciRangeQ *io_ranges, PciRangeQ *mem_ranges)
+{
+    PciDeviceInfoList *dev_list;
+    PciMemoryRange range;
+    uint8_t max_bus;
+    Aml *crs;
+
+    crs = aml_resource_template();
+    max_bus = bus_info->bus;
+
+    for (dev_list = bus_info->devices; dev_list; dev_list = dev_list->next) {
+        PciMemoryRegionList *region;
+
+        for (region = dev_list->value->regions; region; region = region->next) {
+            range.base = region->value->address;
+            range.limit = region->value->address + region->value->size - 1;
+
+            if (!strcmp(region->value->type, "io")) {
+                aml_append(crs,
+                    aml_word_io(aml_min_fixed, aml_max_fixed,
+                                aml_pos_decode, aml_entire_range,
+                                0,
+                                range.base,
+                                range.limit,
+                                0,
+                                range.limit - range.base + 1));
+                pci_range_insert(io_ranges, range.base, range.limit);
+            } else { /* "memory" */
+                aml_append(crs,
+                    aml_dword_memory(aml_pos_decode, aml_min_fixed,
+                                     aml_max_fixed, aml_non_cacheable,
+                                     aml_ReadWrite,
+                                     0,
+                                     range.base,
+                                     range.limit,
+                                     0,
+                                     range.limit - range.base + 1));
+                pci_range_insert(mem_ranges, range.base, range.limit);
+            }
+        }
+
+        if (dev_list->value->has_pci_bridge) {
+            PciBridgeInfo *bridge_info = dev_list->value->pci_bridge;
+
+            if (bridge_info->bus.subordinate > max_bus) {
+                max_bus = bridge_info->bus.subordinate;
+            }
+
+            range = *bridge_info->bus.io_range;
+            aml_append(crs,
+                aml_word_io(aml_min_fixed, aml_max_fixed,
+                            aml_pos_decode, aml_entire_range,
+                            0,
+                            range.base,
+                            range.limit,
+                            0,
+                            range.limit - range.base + 1));
+            pci_range_insert(io_ranges, range.base, range.limit);
+
+            range = *bridge_info->bus.memory_range;
+            aml_append(crs,
+                aml_dword_memory(aml_pos_decode, aml_min_fixed,
+                                 aml_max_fixed, aml_non_cacheable,
+                                 aml_ReadWrite,
+                                 0,
+                                 range.base,
+                                 range.limit,
+                                 0,
+                                 range.limit - range.base + 1));
+            pci_range_insert(mem_ranges, range.base, range.limit);
+
+            range = *bridge_info->bus.prefetchable_range;
+            aml_append(crs,
+                aml_dword_memory(aml_pos_decode, aml_min_fixed,
+                                 aml_max_fixed, aml_non_cacheable,
+                                 aml_ReadWrite,
+                                 0,
+                                 range.base,
+                                 range.limit,
+                                 0,
+                                 range.limit - range.base + 1));
+            pci_range_insert(mem_ranges, range.base, range.limit);
+        }
+    }
+
+    aml_append(crs,
+        aml_word_bus_number(aml_min_fixed, aml_max_fixed, aml_pos_decode,
+                            0,
+                            bus_info->bus,
+                            max_bus,
+                            0,
+                            max_bus - bus_info->bus + 1));
+
+    return crs;
+}
+
 static void
 build_ssdt(GArray *table_data, GArray *linker,
            AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -737,6 +879,8 @@ build_ssdt(GArray *table_data, GArray *linker,
     uint32_t nr_mem = machine->ram_slots;
     unsigned acpi_cpus = guest_info->apic_id_limit;
     Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx;
+    PciRangeQ io_ranges = QLIST_HEAD_INITIALIZER(io_ranges);
+    PciRangeQ mem_ranges = QLIST_HEAD_INITIALIZER(mem_ranges);
     int i;
 
     ssdt = init_aml_allocator();
@@ -773,9 +917,14 @@ build_ssdt(GArray *table_data, GArray *linker,
             aml_append(dev,
                 aml_name_decl("_BBN", aml_int((uint8_t)bus_info->bus)));
             aml_append(dev, build_prt());
+            crs = build_crs(pci, bus_info, &io_ranges, &mem_ranges);
+            aml_append(dev, aml_name_decl("_CRS", crs));
             aml_append(scope, dev);
             aml_append(ssdt, scope);
         }
+
+        pci_range_list_free(&io_ranges);
+        pci_range_list_free(&mem_ranges);
         qapi_free_PciInfoList(info_list);
     }
 
Signature · 1 line
2.1.0
#32 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 12/25] hw/acpi: add _CRS method for extra root busses

Quoted 15 lines · Marcel Apfelbaum

Save the IO/mem/bus numbers ranges assigned to the extra root busses to be removed from the root bus 0 range.

---
 hw/i386/acpi-build.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 149 insertions(+)
hw/i386/acpi-build.c +0 -0
index e7a1a36..f4d8816 100644
@@ -728,6 +728,148 @@ static Aml *build_prt(void)
     return method;
 }

hw/i386/acpi-build.c static Aml *build_prt(void) · line 739

Quoted 10 lines
hw/i386/acpi-build.c +9 -0
 
+typedef struct PciRangeEntry {
+    QLIST_ENTRY(PciRangeEntry) entry;
+    int64_t base;
+    int64_t limit;
+} PciRangeEntry;
+
+typedef QLIST_HEAD(PciRangeQ, PciRangeEntry) PciRangeQ;
+
+static void pci_range_insert(PciRangeQ *list, int64_t base, int64_t limit)

Don't start with pci_ or Pci prefixes, this is for pci things. signed values for base/limit might be problematic, even though currenly guests don't assign such values normally.
I know it's a qmp bug/feature, but you don't have to use qmp.

Quoted 26 lines
hw/i386/acpi-build.c +26 -0
+{
+    PciRangeEntry *entry, *next, *e;
+
+    if (!base) {
+        return;
+    }
+
+    e = g_malloc(sizeof(*entry));
+    e->base = base;
+    e->limit = limit;
+
+    if (QLIST_EMPTY(list)) {
+        QLIST_INSERT_HEAD(list, e, entry);
+    } else {
+        QLIST_FOREACH_SAFE(entry, list, entry, next) {
+            if (base < entry->base) {
+                QLIST_INSERT_BEFORE(entry, e, entry);
+                break;
+            } else if (!next) {
+                QLIST_INSERT_AFTER(entry, e, entry);
+                break;
+            }
+        }
+    }
+}
+

hw/i386/acpi-build.c static Aml *build_prt(void) · line 775

Quoted 10 lines
hw/i386/acpi-build.c +10 -0
+static void pci_range_list_free(PciRangeQ *list)
+{
+    PciRangeEntry *entry, *next;
+
+    QLIST_FOREACH_SAFE(entry, list, entry, next) {
+        QLIST_REMOVE(entry, entry);
+        g_free(entry);
+    }
+}
+

Not very happy about manual memory management here. Isn't there something you can do with
And how about using g_array_sort to sort things?

Quoted 36 lines
hw/i386/acpi-build.c +36 -0
+static Aml *build_crs(PcPciInfo *pci, PciInfo *bus_info,
+                      PciRangeQ *io_ranges, PciRangeQ *mem_ranges)
+{
+    PciDeviceInfoList *dev_list;
+    PciMemoryRange range;
+    uint8_t max_bus;
+    Aml *crs;
+
+    crs = aml_resource_template();
+    max_bus = bus_info->bus;
+
+    for (dev_list = bus_info->devices; dev_list; dev_list = dev_list->next) {
+        PciMemoryRegionList *region;
+
+        for (region = dev_list->value->regions; region; region = region->next) {
+            range.base = region->value->address;
+            range.limit = region->value->address + region->value->size - 1;
+
+            if (!strcmp(region->value->type, "io")) {
+                aml_append(crs,
+                    aml_word_io(aml_min_fixed, aml_max_fixed,
+                                aml_pos_decode, aml_entire_range,
+                                0,
+                                range.base,
+                                range.limit,
+                                0,
+                                range.limit - range.base + 1));
+                pci_range_insert(io_ranges, range.base, range.limit);
+            } else { /* "memory" */
+                aml_append(crs,
+                    aml_dword_memory(aml_pos_decode, aml_min_fixed,
+                                     aml_max_fixed, aml_non_cacheable,
+                                     aml_ReadWrite,
+                                     0,
+                                     range.base,
+                                     range.limit,

hw/i386/acpi-build.c static Aml *build_prt(void) · line 821

Quoted 10 lines
hw/i386/acpi-build.c +10 -0
+                                     0,
+                                     range.limit - range.base + 1));
+                pci_range_insert(mem_ranges, range.base, range.limit);
+            }
+        }
+
+        if (dev_list->value->has_pci_bridge) {
+            PciBridgeInfo *bridge_info = dev_list->value->pci_bridge;
+
+            if (bridge_info->bus.subordinate > max_bus) {

What's this doing?

Quoted 80 lines
hw/i386/acpi-build.c +58 -0
+                max_bus = bridge_info->bus.subordinate;
+            }
+
+            range = *bridge_info->bus.io_range;
+            aml_append(crs,
+                aml_word_io(aml_min_fixed, aml_max_fixed,
+                            aml_pos_decode, aml_entire_range,
+                            0,
+                            range.base,
+                            range.limit,
+                            0,
+                            range.limit - range.base + 1));
+            pci_range_insert(io_ranges, range.base, range.limit);
+
+            range = *bridge_info->bus.memory_range;
+            aml_append(crs,
+                aml_dword_memory(aml_pos_decode, aml_min_fixed,
+                                 aml_max_fixed, aml_non_cacheable,
+                                 aml_ReadWrite,
+                                 0,
+                                 range.base,
+                                 range.limit,
+                                 0,
+                                 range.limit - range.base + 1));
+            pci_range_insert(mem_ranges, range.base, range.limit);
+
+            range = *bridge_info->bus.prefetchable_range;
+            aml_append(crs,
+                aml_dword_memory(aml_pos_decode, aml_min_fixed,
+                                 aml_max_fixed, aml_non_cacheable,
+                                 aml_ReadWrite,
+                                 0,
+                                 range.base,
+                                 range.limit,
+                                 0,
+                                 range.limit - range.base + 1));
+            pci_range_insert(mem_ranges, range.base, range.limit);
+        }
+    }
+
+    aml_append(crs,
+        aml_word_bus_number(aml_min_fixed, aml_max_fixed, aml_pos_decode,
+                            0,
+                            bus_info->bus,
+                            max_bus,
+                            0,
+                            max_bus - bus_info->bus + 1));
+
+    return crs;
+}
+
 static void
 build_ssdt(GArray *table_data, GArray *linker,
            AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -737,6 +879,8 @@ build_ssdt(GArray *table_data, GArray *linker,
     uint32_t nr_mem = machine->ram_slots;
     unsigned acpi_cpus = guest_info->apic_id_limit;
     Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx;
+    PciRangeQ io_ranges = QLIST_HEAD_INITIALIZER(io_ranges);
+    PciRangeQ mem_ranges = QLIST_HEAD_INITIALIZER(mem_ranges);
     int i;
 
     ssdt = init_aml_allocator();
@@ -773,9 +917,14 @@ build_ssdt(GArray *table_data, GArray *linker,
             aml_append(dev,
                 aml_name_decl("_BBN", aml_int((uint8_t)bus_info->bus)));
             aml_append(dev, build_prt());
+            crs = build_crs(pci, bus_info, &io_ranges, &mem_ranges);
+            aml_append(dev, aml_name_decl("_CRS", crs));
             aml_append(scope, dev);
             aml_append(ssdt, scope);
         }
+
+        pci_range_list_free(&io_ranges);
+        pci_range_list_free(&mem_ranges);
         qapi_free_PciInfoList(info_list);
     }
 
Signature · 1 line
2.1.0
#33 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 12/25] hw/acpi: add _CRS method for extra root busses

Quoted 17 lines · Michael S. Tsirkin
Quoted 16 lines · Marcel Apfelbaum

Save the IO/mem/bus numbers ranges assigned to the extra root busses to be removed from the root bus 0 range.

---
  hw/i386/acpi-build.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 149 insertions(+)
hw/i386/acpi-build.c +0 -0
index e7a1a36..f4d8816 100644
@@ -728,6 +728,148 @@ static Aml *build_prt(void)
      return method;
  }
 
Quoted 15 lines

hw/i386/acpi-build.c static Aml *build_prt(void) · line 739

Quoted 9 lines
hw/i386/acpi-build.c +9 -0
+typedef struct PciRangeEntry {
+    QLIST_ENTRY(PciRangeEntry) entry;
+    int64_t base;
+    int64_t limit;
+} PciRangeEntry;
+
+typedef QLIST_HEAD(PciRangeQ, PciRangeEntry) PciRangeQ;
+
+static void pci_range_insert(PciRangeQ *list, int64_t base, int64_t limit)

Don't start with pci_ or Pci prefixes, this is for pci things. signed values for base/limit might be problematic, even though currenly guests don't assign such values normally.
I know it's a qmp bug/feature, but you don't have to use qmp.

Sure, no problem, I'll take care of it.

Quoted 32 lines
Quoted 32 lines
hw/i386/acpi-build.c +31 -0
+{
+    PciRangeEntry *entry, *next, *e;
+
+    if (!base) {
+        return;
+    }
+
+    e = g_malloc(sizeof(*entry));
+    e->base = base;
+    e->limit = limit;
+
+    if (QLIST_EMPTY(list)) {
+        QLIST_INSERT_HEAD(list, e, entry);
+    } else {
+        QLIST_FOREACH_SAFE(entry, list, entry, next) {
+            if (base < entry->base) {
+                QLIST_INSERT_BEFORE(entry, e, entry);
+                break;
+            } else if (!next) {
+                QLIST_INSERT_AFTER(entry, e, entry);
+                break;
+            }
+        }
+    }
+}
+
+static void pci_range_list_free(PciRangeQ *list)
+{
+    PciRangeEntry *entry, *next;
+
+    QLIST_FOREACH_SAFE(entry, list, entry, next) {
Quoted 8 lines

hw/i386/acpi-build.c static Aml *build_prt(void) · line 775

Quoted 5 lines
hw/i386/acpi-build.c +5 -0
+        QLIST_REMOVE(entry, entry);
+        g_free(entry);
+    }
+}
+

Not very happy about manual memory management here. Isn't there something you can do with

The context is pretty simple:
1. We create the ranges and add them to the lists as we go.
2. We use the lists to create the aml IO ranges.
3. Delete them once we finish.
All that in the same context (the same chunk of code) It seems pretty straight forward to me.

Quoted 1 line

And how about using g_array_sort to sort things?

We can, but the code simply inserts the range into the
appropriate position, why using g_array_sort be better?
Maybe we can find another reason to use g_array, we can leverage this method. I thought about it and I had a problem with g_array, however I don't remember it now.

And BTW manual memory management, we will need to create and destroy the g_array.

Quoted 41 lines
Quoted 41 lines
hw/i386/acpi-build.c +40 -0
+static Aml *build_crs(PcPciInfo *pci, PciInfo *bus_info,
+                      PciRangeQ *io_ranges, PciRangeQ *mem_ranges)
+{
+    PciDeviceInfoList *dev_list;
+    PciMemoryRange range;
+    uint8_t max_bus;
+    Aml *crs;
+
+    crs = aml_resource_template();
+    max_bus = bus_info->bus;
+
+    for (dev_list = bus_info->devices; dev_list; dev_list = dev_list->next) {
+        PciMemoryRegionList *region;
+
+        for (region = dev_list->value->regions; region; region = region->next) {
+            range.base = region->value->address;
+            range.limit = region->value->address + region->value->size - 1;
+
+            if (!strcmp(region->value->type, "io")) {
+                aml_append(crs,
+                    aml_word_io(aml_min_fixed, aml_max_fixed,
+                                aml_pos_decode, aml_entire_range,
+                                0,
+                                range.base,
+                                range.limit,
+                                0,
+                                range.limit - range.base + 1));
+                pci_range_insert(io_ranges, range.base, range.limit);
+            } else { /* "memory" */
+                aml_append(crs,
+                    aml_dword_memory(aml_pos_decode, aml_min_fixed,
+                                     aml_max_fixed, aml_non_cacheable,
+                                     aml_ReadWrite,
+                                     0,
+                                     range.base,
+                                     range.limit,
+                                     0,
+                                     range.limit - range.base + 1));
+                pci_range_insert(mem_ranges, range.base, range.limit);
+            }
Quoted 8 lines

hw/i386/acpi-build.c static Aml *build_prt(void) · line 821

Quoted 6 lines
hw/i386/acpi-build.c +6 -0
+        }
+
+        if (dev_list->value->has_pci_bridge) {
+            PciBridgeInfo *bridge_info = dev_list->value->pci_bridge;
+
+            if (bridge_info->bus.subordinate > max_bus) {

What's this doing?

It keeps track of the max bus number for piix hostbridge bus num range. (see [1] below) Pci root bus 0 range is [0 - <minimmum bus number used by other pci root buses> Maybe the variable name is not so good, I am open to suggestions: min_extra_root_bus_nr?

Quoted 40 lines
Quoted 40 lines
hw/i386/acpi-build.c +39 -0
+                max_bus = bridge_info->bus.subordinate;
+            }
+
+            range = *bridge_info->bus.io_range;
+            aml_append(crs,
+                aml_word_io(aml_min_fixed, aml_max_fixed,
+                            aml_pos_decode, aml_entire_range,
+                            0,
+                            range.base,
+                            range.limit,
+                            0,
+                            range.limit - range.base + 1));
+            pci_range_insert(io_ranges, range.base, range.limit);
+
+            range = *bridge_info->bus.memory_range;
+            aml_append(crs,
+                aml_dword_memory(aml_pos_decode, aml_min_fixed,
+                                 aml_max_fixed, aml_non_cacheable,
+                                 aml_ReadWrite,
+                                 0,
+                                 range.base,
+                                 range.limit,
+                                 0,
+                                 range.limit - range.base + 1));
+            pci_range_insert(mem_ranges, range.base, range.limit);
+
+            range = *bridge_info->bus.prefetchable_range;
+            aml_append(crs,
+                aml_dword_memory(aml_pos_decode, aml_min_fixed,
+                                 aml_max_fixed, aml_non_cacheable,
+                                 aml_ReadWrite,
+                                 0,
+                                 range.base,
+                                 range.limit,
+                                 0,
+                                 range.limit - range.base + 1));
+            pci_range_insert(mem_ranges, range.base, range.limit);
+        }
+    }
Quoted 8 lines

hw/i386/acpi-build.c static Aml *build_prt(void) · line 868

Quoted 8 lines
hw/i386/acpi-build.c +8 -0
+
+    aml_append(crs,
+        aml_word_bus_number(aml_min_fixed, aml_max_fixed, aml_pos_decode,
+                            0,
+                            bus_info->bus,
+                            max_bus,
+                            0,
+                            max_bus - bus_info->bus + 1));

[1] The bus numbers range for piix host-bridge (bus 0).

Thanks,
Marcel

Quoted 33 lines
Quoted 33 lines
hw/i386/acpi-build.c +11 -1
+
+    return crs;
+}
+
  static void
  build_ssdt(GArray *table_data, GArray *linker,
             AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -737,6 +879,8 @@ build_ssdt(GArray *table_data, GArray *linker,
      uint32_t nr_mem = machine->ram_slots;
      unsigned acpi_cpus = guest_info->apic_id_limit;
      Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx;
+    PciRangeQ io_ranges = QLIST_HEAD_INITIALIZER(io_ranges);
+    PciRangeQ mem_ranges = QLIST_HEAD_INITIALIZER(mem_ranges);
      int i;
 
      ssdt = init_aml_allocator();
@@ -773,9 +917,14 @@ build_ssdt(GArray *table_data, GArray *linker,
              aml_append(dev,
                  aml_name_decl("_BBN", aml_int((uint8_t)bus_info->bus)));
              aml_append(dev, build_prt());
+            crs = build_crs(pci, bus_info, &io_ranges, &mem_ranges);
+            aml_append(dev, aml_name_decl("_CRS", crs));
              aml_append(scope, dev);
              aml_append(ssdt, scope);
          }
+
+        pci_range_list_free(&io_ranges);
+        pci_range_list_free(&mem_ranges);
          qapi_free_PciInfoList(info_list);
      }
 
--

2.1.0

#34 lore raw

PATCH v4 13/25 hw/acpi: remove from root bus 0 the crs resources used by other busses.

In reply to Marcel Apfelbaum

If multiple root busses are used, root bus 0 cannot use all the pci holes ranges. Remove the IO/mem ranges used by the other primary busses.

---
 hw/i386/acpi-build.c | 84 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 72 insertions(+), 12 deletions(-)
hw/i386/acpi-build.c +72 -12
index f4d8816..44819b8 100644
@@ -881,6 +881,9 @@ build_ssdt(GArray *table_data, GArray *linker,
     Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx;
     PciRangeQ io_ranges = QLIST_HEAD_INITIALIZER(io_ranges);
     PciRangeQ mem_ranges = QLIST_HEAD_INITIALIZER(mem_ranges);
+    PciMemoryRange range;
+    PciRangeEntry *entry;
+    int root_bus_limit = 0xFF;
     int i;
 
     ssdt = init_aml_allocator();
@@ -909,6 +912,10 @@ build_ssdt(GArray *table_data, GArray *linker,
                 continue;
             }
 
+            if (bus_info->bus < root_bus_limit) {
+                root_bus_limit = bus_info->bus - 1;
+            }
+
             scope = aml_scope("\\_SB");
             dev = aml_device("PC%.02X", (uint8_t)bus_info->bus);
             aml_append(dev, aml_name_decl("_UID",
@@ -923,8 +930,6 @@ build_ssdt(GArray *table_data, GArray *linker,
             aml_append(ssdt, scope);
         }
 
-        pci_range_list_free(&io_ranges);
-        pci_range_list_free(&mem_ranges);
         qapi_free_PciInfoList(info_list);
     }
 
@@ -933,26 +938,78 @@ build_ssdt(GArray *table_data, GArray *linker,
     crs = aml_resource_template();
     aml_append(crs,
         aml_word_bus_number(aml_min_fixed, aml_max_fixed, aml_pos_decode,
-                            0x0000, 0x0000, 0x00FF, 0x0000, 0x0100));
+                            0x0000, 0x0, root_bus_limit,
+                            0x0000, root_bus_limit + 1));
     aml_append(crs, aml_io(aml_decode16, 0x0CF8, 0x0CF8, 0x01, 0x08));
 
     aml_append(crs,
         aml_word_io(aml_min_fixed, aml_max_fixed,
                     aml_pos_decode, aml_entire_range,
                     0x0000, 0x0000, 0x0CF7, 0x0000, 0x0CF8));
-    aml_append(crs,
-        aml_word_io(aml_min_fixed, aml_max_fixed,
-                    aml_pos_decode, aml_entire_range,
-                    0x0000, 0x0D00, 0xFFFF, 0x0000, 0xF300));
+
+    /* prepare PCI IO ranges */
+    range.base = 0x0D00;
+    range.limit = 0xFFFF;
+    if (QLIST_EMPTY(&io_ranges)) {
+        aml_append(crs,
+            aml_word_io(aml_min_fixed, aml_max_fixed,
+                        aml_pos_decode, aml_entire_range,
+                        0x0000, range.base, range.limit,
+                        0x0000, range.limit - range.base + 1));
+    } else {
+        QLIST_FOREACH(entry, &io_ranges, entry) {
+            if (range.base < entry->base) {
+                aml_append(crs,
+                    aml_word_io(aml_min_fixed, aml_max_fixed,
+                                aml_pos_decode, aml_entire_range,
+                                0x0000, range.base, entry->base - 1,
+                                0x0000, entry->base - range.base));
+            }
+            range.base = entry->limit + 1;
+            if (!QLIST_NEXT(entry, entry)) {
+                aml_append(crs,
+                    aml_word_io(aml_min_fixed, aml_max_fixed,
+                                aml_pos_decode, aml_entire_range,
+                                0x0000, range.base, range.limit,
+                                0x0000, range.limit - range.base + 1));
+            }
+        }
+    }
+
     aml_append(crs,
         aml_dword_memory(aml_pos_decode, aml_min_fixed, aml_max_fixed,
                          aml_cacheable, aml_ReadWrite,
                          0, 0x000A0000, 0x000BFFFF, 0, 0x00020000));
-    aml_append(crs,
-        aml_dword_memory(aml_pos_decode, aml_min_fixed, aml_max_fixed,
-                         aml_non_cacheable, aml_ReadWrite,
-                         0, pci->w32.begin, pci->w32.end - 1, 0,
-                         pci->w32.end - pci->w32.begin));
+
+    /* prepare PCI memory ranges */
+    range.base = pci->w32.begin;
+    range.limit = pci->w32.end - 1;
+    if (QLIST_EMPTY(&mem_ranges)) {
+        aml_append(crs,
+            aml_dword_memory(aml_pos_decode, aml_min_fixed, aml_max_fixed,
+                             aml_non_cacheable, aml_ReadWrite,
+                             0, range.base, range.limit,
+                             0, range.limit - range.base + 1));
+    } else {
+        QLIST_FOREACH(entry, &mem_ranges, entry) {
+            if (range.base < entry->base) {
+                aml_append(crs,
+                    aml_dword_memory(aml_pos_decode, aml_min_fixed, aml_max_fixed,
+                                     aml_non_cacheable, aml_ReadWrite,
+                                     0, range.base, entry->base - 1,
+                                     0, entry->base - range.base));
+            }
+            range.base = entry->limit + 1;
+            if (!QLIST_NEXT(entry, entry)) {
+                aml_append(crs,
+                    aml_dword_memory(aml_pos_decode, aml_min_fixed, aml_max_fixed,
+                                     aml_non_cacheable, aml_ReadWrite,
+                                     0, range.base, range.limit,
+                                     0, range.base - range.limit + 1));
+            }
+        }
+    }
+
     if (pci->w64.begin) {
         aml_append(crs,
             aml_qword_memory(aml_pos_decode, aml_min_fixed, aml_max_fixed,
@@ -975,6 +1032,9 @@ build_ssdt(GArray *table_data, GArray *linker,
     aml_append(dev, aml_name_decl("_CRS", crs));
     aml_append(scope, dev);
 
+    pci_range_list_free(&io_ranges);
+    pci_range_list_free(&mem_ranges);
+
     /* reserve PCIHP resources */
     if (pm->pcihp_io_len) {
         dev = aml_device("PHPR");
Signature · 1 line
2.1.0
#35 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 13/25] hw/acpi: remove from root bus 0 the crs resources used by other busses.

Quoted 3 lines · Marcel Apfelbaum

If multiple root busses are used, root bus 0 cannot use all the pci holes ranges. Remove the IO/mem ranges used by the other primary busses.

[...]

Quoted 23 lines
hw/i386/acpi-build.c +19 -4
-    aml_append(crs,
-        aml_word_io(aml_min_fixed, aml_max_fixed,
-                    aml_pos_decode, aml_entire_range,
-                    0x0000, 0x0D00, 0xFFFF, 0x0000, 0xF300));
+
+    /* prepare PCI IO ranges */
+    range.base = 0x0D00;
+    range.limit = 0xFFFF;
+    if (QLIST_EMPTY(&io_ranges)) {
+        aml_append(crs,
+            aml_word_io(aml_min_fixed, aml_max_fixed,
+                        aml_pos_decode, aml_entire_range,
+                        0x0000, range.base, range.limit,
+                        0x0000, range.limit - range.base + 1));
+    } else {
+        QLIST_FOREACH(entry, &io_ranges, entry) {
+            if (range.base < entry->base) {
+                aml_append(crs,
+                    aml_word_io(aml_min_fixed, aml_max_fixed,
+                                aml_pos_decode, aml_entire_range,
+                                0x0000, range.base, entry->base - 1,
+                                0x0000, entry->base - range.base));
+            }

hw/i386/acpi-build.c build_ssdt(GArray *table_data, GArray *linker, · line 977

Quoted 10 lines
hw/i386/acpi-build.c +10 -0
+            range.base = entry->limit + 1;
+            if (!QLIST_NEXT(entry, entry)) {
+                aml_append(crs,
+                    aml_word_io(aml_min_fixed, aml_max_fixed,
+                                aml_pos_decode, aml_entire_range,
+                                0x0000, range.base, range.limit,
+                                0x0000, range.limit - range.base + 1));
+            }
+        }
+    }

If I read this correctly, it looks like a machine with two root buses and 20 devices, each with one memory range and one io range, would end up with 40 CRS ranges (ie, a CRS range for every resource). It also looks like this furthers the requirement that the guest firmware assign the PCI resources prior to QEMU being able to generate the ACPI tables.

Am I correct? If so, that doesn't sound ideal.

-Kevin

#36 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 13/25] hw/acpi: remove from root bus 0 the crs resources used by other busses.

Quoted 30 lines · Kevin O'Connor
Quoted 3 lines · Marcel Apfelbaum

If multiple root busses are used, root bus 0 cannot use all the pci holes ranges. Remove the IO/mem ranges used by the other primary busses.

[...]

Quoted 25 lines
hw/i386/acpi-build.c +21 -4
-    aml_append(crs,
-        aml_word_io(aml_min_fixed, aml_max_fixed,
-                    aml_pos_decode, aml_entire_range,
-                    0x0000, 0x0D00, 0xFFFF, 0x0000, 0xF300));
+
+    /* prepare PCI IO ranges */
+    range.base = 0x0D00;
+    range.limit = 0xFFFF;
+    if (QLIST_EMPTY(&io_ranges)) {
+        aml_append(crs,
+            aml_word_io(aml_min_fixed, aml_max_fixed,
+                        aml_pos_decode, aml_entire_range,
+                        0x0000, range.base, range.limit,
+                        0x0000, range.limit - range.base + 1));
+    } else {
+        QLIST_FOREACH(entry, &io_ranges, entry) {
+            if (range.base < entry->base) {
+                aml_append(crs,
+                    aml_word_io(aml_min_fixed, aml_max_fixed,
+                                aml_pos_decode, aml_entire_range,
+                                0x0000, range.base, entry->base - 1,
+                                0x0000, entry->base - range.base));
+            }
+            range.base = entry->limit + 1;
+            if (!QLIST_NEXT(entry, entry)) {
Quoted 9 lines

hw/i386/acpi-build.c build_ssdt(GArray *table_data, GArray *linker, · line 976

Quoted 8 lines
hw/i386/acpi-build.c +8 -0
+                aml_append(crs,
+                    aml_word_io(aml_min_fixed, aml_max_fixed,
+                                aml_pos_decode, aml_entire_range,
+                                0x0000, range.base, range.limit,
+                                0x0000, range.limit - range.base + 1));
+            }
+        }
+    }

Hi Kevin,
Thank you for your review!

Quoted 3 lines

If I read this correctly, it looks like a machine with two root buses and 20 devices, each with one memory range and one io range, would end up with 40 CRS ranges (ie, a CRS range for every resource).

Correct.

As Michael pointed out in another thread, the firmware is considered guest code and QEMU cannot assume anything on how the resources are assigned. This is why this solution was chosen.

However we have two things that make the situation a little better.
1. The PXB implementation includes a pci-bridge and all devices are automatically attached to the secondary bus, in this way we have one IO/MEM range per extra root bus.
2. On top of this series we can add a merge algorithm that will bring together consecutive ranges. This series does not include this optimization and it focuses on the correctness.

It also

Quoted 5 lines

looks like this furthers the requirement that the guest firmware assign the PCI resources prior to QEMU being able to generate the ACPI tables.

Am I correct? If so, that doesn't sound ideal.

You are correct, however is not that bad because we have the following sequence:
- Early in the boot sequence the bios scans the PCI buses and assigns IO/MEM ranges
- At this moment all resources needed by QEMU are present in the configuration space.
- At the end of the boot sequence the BIOS queries the ACPI tables and *only then* the tables are computed.

I think we use that implicitly for other features, anyway, it looks like an elegant solution with no real drawbacks. (Our assumptions are safe)

Thanks,
Marcel

Quoted 3 lines

-Kevin

#37 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 13/25] hw/acpi: remove from root bus 0 the crs resources used by other busses.

Quoted 6 lines · Marcel Apfelbaum
Quoted 3 lines · Kevin O'Connor

If I read this correctly, it looks like a machine with two root buses and 20 devices, each with one memory range and one io range, would end up with 40 CRS ranges (ie, a CRS range for every resource).

Correct.

Quoted 7 lines

As Michael pointed out in another thread, the firmware is considered guest code and QEMU cannot assume anything on how the resources are assigned. This is why this solution was chosen.

However we have two things that make the situation a little better.
1. The PXB implementation includes a pci-bridge and all devices are automatically attached to the secondary bus, in this way we have one IO/MEM range per extra root bus.

Out of curiosity, does the PXB implementation add the pci-bridge just to simplify the IO/MEM range, or are there other technical reasons for it?

Quoted 10 lines

2. On top of this series we can add a merge algorithm that will bring together consecutive ranges. This series does not include this optimization and it focuses on the correctness.

It also

Quoted 5 lines

looks like this furthers the requirement that the guest firmware assign the PCI resources prior to QEMU being able to generate the ACPI tables.

Am I correct? If so, that doesn't sound ideal.

Quoted 8 lines

You are correct, however is not that bad because we have the following sequence:
- Early in the boot sequence the bios scans the PCI buses and assigns IO/MEM ranges
- At this moment all resources needed by QEMU are present in the configuration space.
- At the end of the boot sequence the BIOS queries the ACPI tables and *only then* the tables are computed.

I think we use that implicitly for other features, anyway, it looks like an elegant solution with no real drawbacks. (Our assumptions are safe)

Thank you for the clarification. I understand that it works, but I've never been that comfortable with the QEMU<->firmware dance with PCI resources. I do understand that the alternatives have as many or more problems though. So, I'm not objecting to this implementation.

Cheers,
-Kevin

#38 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 13/25] hw/acpi: remove from root bus 0 the crs resources used by other busses.

Quoted 11 lines · Kevin O'Connor
Quoted 10 lines · Marcel Apfelbaum
Quoted 3 lines · Kevin O'Connor

If I read this correctly, it looks like a machine with two root buses and 20 devices, each with one memory range and one io range, would end up with 40 CRS ranges (ie, a CRS range for every resource).

Correct.

As Michael pointed out in another thread, the firmware is considered guest code and QEMU cannot assume anything on how the resources are assigned. This is why this solution was chosen.

Quoted 7 lines
Quoted 3 lines

However we have two things that make the situation a little better.
1. The PXB implementation includes a pci-bridge and all devices are automatically attached to the secondary bus, in this way we have one IO/MEM range per extra root bus.

Out of curiosity, does the PXB implementation add the pci-bridge just to simplify the IO/MEM range, or are there other technical reasons for it?

We have another elephant there :) -> pci hotplug.
All the "free" memory ranges are assigned to bus 0, this will leave the pxb buses without the hotplug capability.
Using a PCI bridge will give us some IO/MEM ranges for hotplug: the ones created because of minimum requirement by PCI spec and not used currently by any devices.

Quoted 17 lines
Quoted 17 lines

2. On top of this series we can add a merge algorithm that will bring together consecutive ranges. This series does not include this optimization and it focuses on the correctness.

It also

Quoted 5 lines

looks like this furthers the requirement that the guest firmware assign the PCI resources prior to QEMU being able to generate the ACPI tables.

Am I correct? If so, that doesn't sound ideal.

You are correct, however is not that bad because we have the following sequence:
- Early in the boot sequence the bios scans the PCI buses and assigns IO/MEM ranges
- At this moment all resources needed by QEMU are present in the configuration space.
- At the end of the boot sequence the BIOS queries the ACPI tables and *only then* the tables are computed.

Quoted 7 lines
Quoted 2 lines

I think we use that implicitly for other features, anyway, it looks like an elegant solution with no real drawbacks. (Our assumptions are safe)

Thank you for the clarification. I understand that it works, but I've never been that comfortable with the QEMU<->firmware dance with PCI resources. I do understand that the alternatives have as many or more problems though. So, I'm not objecting to this implementation.

No problem, thank you and your review is much appreciated as always, Marcel

Quoted 4 lines

Cheers,
-Kevin

#39 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 13/25] hw/acpi: remove from root bus 0 the crs resources used by other busses.

In reply to Kevin O'Connor
Quoted 39 lines · Kevin O'Connor
Quoted 3 lines · Marcel Apfelbaum

If multiple root busses are used, root bus 0 cannot use all the pci holes ranges. Remove the IO/mem ranges used by the other primary busses.

[...]

Quoted 23 lines
hw/i386/acpi-build.c +19 -4
-    aml_append(crs,
-        aml_word_io(aml_min_fixed, aml_max_fixed,
-                    aml_pos_decode, aml_entire_range,
-                    0x0000, 0x0D00, 0xFFFF, 0x0000, 0xF300));
+
+    /* prepare PCI IO ranges */
+    range.base = 0x0D00;
+    range.limit = 0xFFFF;
+    if (QLIST_EMPTY(&io_ranges)) {
+        aml_append(crs,
+            aml_word_io(aml_min_fixed, aml_max_fixed,
+                        aml_pos_decode, aml_entire_range,
+                        0x0000, range.base, range.limit,
+                        0x0000, range.limit - range.base + 1));
+    } else {
+        QLIST_FOREACH(entry, &io_ranges, entry) {
+            if (range.base < entry->base) {
+                aml_append(crs,
+                    aml_word_io(aml_min_fixed, aml_max_fixed,
+                                aml_pos_decode, aml_entire_range,
+                                0x0000, range.base, entry->base - 1,
+                                0x0000, entry->base - range.base));
+            }

hw/i386/acpi-build.c build_ssdt(GArray *table_data, GArray *linker, · line 977

Quoted 10 lines
hw/i386/acpi-build.c +10 -0
+            range.base = entry->limit + 1;
+            if (!QLIST_NEXT(entry, entry)) {
+                aml_append(crs,
+                    aml_word_io(aml_min_fixed, aml_max_fixed,
+                                aml_pos_decode, aml_entire_range,
+                                0x0000, range.base, range.limit,
+                                0x0000, range.limit - range.base + 1));
+            }
+        }
+    }
Quoted 3 lines

If I read this correctly, it looks like a machine with two root buses and 20 devices, each with one memory range and one io range, would end up with 40 CRS ranges (ie, a CRS range for every resource).

I think that's only if you stick multiple devices directly behind the bridge. Looks like with a single pci bridge behind root, there will only be 2 ranges.

Maybe try to enforce this sane topology?

Quoted 4 lines

It also
looks like this furthers the requirement that the guest firmware assign the PCI resources prior to QEMU being able to generate the ACPI tables.

That seems unavoidable unless we want to assign ranges from hardware/management.
Which I think would be a mistake: management doesn't really know, or care.

Quoted 2 lines

-Kevin

#40 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 13/25] hw/acpi: remove from root bus 0 the crs resources used by other busses.

Quoted 8 lines · Michael S. Tsirkin
Quoted 3 lines · Kevin O'Connor

If I read this correctly, it looks like a machine with two root buses and 20 devices, each with one memory range and one io range, would end up with 40 CRS ranges (ie, a CRS range for every resource).

I think that's only if you stick multiple devices directly behind the bridge. Looks like with a single pci bridge behind root, there will only be 2 ranges.

Yeah, that makes sense, so doesn't seem to be a problem.

Quoted 11 lines

Maybe try to enforce this sane topology?

Quoted 4 lines

It also
looks like this furthers the requirement that the guest firmware assign the PCI resources prior to QEMU being able to generate the ACPI tables.

That seems unavoidable unless we want to assign ranges from hardware/management.
Which I think would be a mistake: management doesn't really know, or care.

I understand. I think what would help me is if we could document somewhere that the firmware has to assign PCI resources before querying the bios tables and that it is the *only* pre-requisite for querying them. Looking now, though, I don't see any fw_cfg documentation in the repo, so I'm not sure where that could be added.

Thanks,
-Kevin

#41 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 13/25] hw/acpi: remove from root bus 0 the crs resources used by other busses.

Quoted 24 lines · Kevin O'Connor
Quoted 8 lines · Michael S. Tsirkin
Quoted 3 lines · Kevin O'Connor

If I read this correctly, it looks like a machine with two root buses and 20 devices, each with one memory range and one io range, would end up with 40 CRS ranges (ie, a CRS range for every resource).

I think that's only if you stick multiple devices directly behind the bridge. Looks like with a single pci bridge behind root, there will only be 2 ranges.

Yeah, that makes sense, so doesn't seem to be a problem.

Quoted 11 lines

Maybe try to enforce this sane topology?

Quoted 4 lines

It also
looks like this furthers the requirement that the guest firmware assign the PCI resources prior to QEMU being able to generate the ACPI tables.

That seems unavoidable unless we want to assign ranges from hardware/management.
Which I think would be a mistake: management doesn't really know, or care.

Quoted 8 lines

I understand. I think what would help me is if we could document somewhere that the firmware has to assign PCI resources before querying the bios tables and that it is the *only* pre-requisite for querying them. Looking now, though, I don't see any fw_cfg documentation in the repo, so I'm not sure where that could be added.

Thanks,
-Kevin

Sigh. Might make a GSoC project?

Signature · 1 line
MST
#42 lore raw

Re: [Qemu-devel] [PATCH v4 for-2.3 13/25] hw/acpi: remove from root bus 0 the crs resources used by other busses.

Quoted 31 lines · Michael S. Tsirkin
Quoted 30 lines · Kevin O'Connor
Quoted 8 lines · Michael S. Tsirkin
Quoted 3 lines · Kevin O'Connor

If I read this correctly, it looks like a machine with two root buses and 20 devices, each with one memory range and one io range, would end up with 40 CRS ranges (ie, a CRS range for every resource).

I think that's only if you stick multiple devices directly behind the bridge. Looks like with a single pci bridge behind root, there will only be 2 ranges.

Yeah, that makes sense, so doesn't seem to be a problem.

Quoted 11 lines

Maybe try to enforce this sane topology?

Quoted 4 lines

It also
looks like this furthers the requirement that the guest firmware assign the PCI resources prior to QEMU being able to generate the ACPI tables.

That seems unavoidable unless we want to assign ranges from hardware/management.
Which I think would be a mistake: management doesn't really know, or care.

I understand. I think what would help me is if we could document somewhere that the firmware has to assign PCI resources before querying the bios tables and that it is the *only* pre-requisite for querying them. Looking now, though, I don't see any fw_cfg documentation in the repo, so I'm not sure where that could be added.

Quoted 4 lines
Quoted 2 lines

Thanks,
-Kevin

Sigh. Might make a GSoC project?

Documentation projects are not possible under Google Summer of Code:

https://www.google-melange.com/gsoc/document/show/gsoc_program/google/gsoc2015/help_page#12._Are_proposals_for_documentation_work

If there is a coding project you are interested in mentoring, there is a project idea template to fill out here:

http://qemu-project.org/Google_Summer_of_Code_2015#Project_idea_template

Stefan

#43 lore raw

PATCH v4 14/25 hw/pci: move pci bus related code to separate files

In reply to Marcel Apfelbaum

This refactoring moves all the code needed (recursively) to register TYPE_PCI_BUS type to a new file hw/pci/pci_bus.c . This allows to properly add new functionality to the pci bus class.

---
 arch_init.c              |   1 +
 hw/alpha/typhoon.c       |   1 +
 hw/mips/gt64xxx_pci.c    |   1 +
 hw/pci-host/bonito.c     |   1 +
 hw/pci-host/grackle.c    |   1 +
 hw/pci-host/piix.c       |   1 +
 hw/pci-host/ppce500.c    |   1 +
 hw/pci-host/q35.c        |   1 +
 hw/pci-host/uninorth.c   |   1 +
 hw/pci/Makefile.objs     |   2 +-
 hw/pci/pci.c             | 472 +--------------------------------------------
 hw/pci/pci_bus.c         | 491 +++++++++++++++++++++++++++++++++++++++++++++++
 hw/ppc/ppc4xx_pci.c      |   1 +
 hw/sh4/r2d.c             |   1 +
 hw/sh4/sh_pci.c          |   1 +
 include/hw/pci/pci.h     |   3 +-
 include/hw/pci/pci_bus.h |   8 +
 17 files changed, 514 insertions(+), 474 deletions(-)
 create mode 100644 hw/pci/pci_bus.c
arch_init.c +1 -0
index 691b5e2..cbebf6d 100644
@@ -37,6 +37,7 @@
 #include "audio/audio.h"
 #include "hw/i386/pc.h"
 #include "hw/pci/pci.h"
+#include "hw/pci/pci_bus.h"
 #include "hw/audio/audio.h"
 #include "sysemu/kvm.h"
 #include "migration/migration.h"
hw/alpha/typhoon.c +1 -0
index 62af946..d3fad5d 100644
@@ -8,6 +8,7 @@
 
 #include "cpu.h"
 #include "hw/hw.h"
+#include "hw/pci/pci_bus.h"
 #include "hw/devices.h"
 #include "sysemu/sysemu.h"
 #include "alpha_sys.h"
hw/mips/gt64xxx_pci.c +1 -0
index 10fcca3..c4ca6f3 100644
@@ -25,6 +25,7 @@
 #include "hw/hw.h"
 #include "hw/mips/mips.h"
 #include "hw/pci/pci.h"
+#include "hw/pci/pci_bus.h"
 #include "hw/pci/pci_host.h"
 #include "hw/i386/pc.h"
 #include "exec/address-spaces.h"
hw/pci-host/bonito.c +1 -0
index 8bdd569..49e1122 100644
@@ -41,6 +41,7 @@
 
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
+#include "hw/pci/pci_bus.h"
 #include "hw/i386/pc.h"
 #include "hw/mips/mips.h"
 #include "hw/pci/pci_host.h"
hw/pci-host/grackle.c +1 -0
index bfe707a..89745cd 100644
@@ -26,6 +26,7 @@
 #include "hw/pci/pci_host.h"
 #include "hw/ppc/mac.h"
 #include "hw/pci/pci.h"
+#include "hw/pci/pci_bus.h"
 
 /* debug Grackle */
 //#define DEBUG_GRACKLE
hw/pci-host/piix.c +1 -0
index 723836f..292b6e9 100644
@@ -25,6 +25,7 @@
 #include "hw/hw.h"
 #include "hw/i386/pc.h"
 #include "hw/pci/pci.h"
+#include "hw/pci/pci_bus.h"
 #include "hw/pci/pci_host.h"
 #include "hw/isa/isa.h"
 #include "hw/sysbus.h"
hw/pci-host/ppce500.c +1 -0
index 613ba73..4363951 100644
@@ -17,6 +17,7 @@
 #include "hw/hw.h"
 #include "hw/ppc/e500-ccsr.h"
 #include "hw/pci/pci.h"
+#include "hw/pci/pci_bus.h"
 #include "hw/pci/pci_host.h"
 #include "qemu/bswap.h"
 #include "hw/pci-host/ppce500.h"
hw/pci-host/q35.c +1 -0
index df60e61..a42d0fb 100644
@@ -28,6 +28,7 @@
  * THE SOFTWARE.
  */
 #include "hw/hw.h"
+#include "hw/pci/pci_bus.h"
 #include "hw/pci-host/q35.h"
 #include "qapi/visitor.h"
 
hw/pci-host/uninorth.c +1 -0
index 53f2b59..1406b42 100644
@@ -24,6 +24,7 @@
 #include "hw/hw.h"
 #include "hw/ppc/mac.h"
 #include "hw/pci/pci.h"
+#include "hw/pci/pci_bus.h"
 #include "hw/pci/pci_host.h"
 
 /* debug UniNorth */
hw/pci/Makefile.objs +1 -1
index 9f905e6..a05cca0 100644
@@ -1,4 +1,4 @@
-common-obj-$(CONFIG_PCI) += pci.o pci_bridge.o
+common-obj-$(CONFIG_PCI) += pci.o pci_bridge.o pci_bus.o
 common-obj-$(CONFIG_PCI) += msix.o msi.o
 common-obj-$(CONFIG_PCI) += shpc.o
 common-obj-$(CONFIG_PCI) += slotid_cap.o
hw/pci/pci.c +1 -471

531 lines not on this page · raw message

hw/pci/pci_bus.c new file +491 -0

491 lines not on this page · raw message

hw/ppc/ppc4xx_pci.c +1 -0
index 0bb3cdb..f5847bc 100644
@@ -23,6 +23,7 @@
 #include "hw/ppc/ppc.h"
 #include "hw/ppc/ppc4xx.h"
 #include "hw/pci/pci.h"
+#include "hw/pci/pci_bus.h"
 #include "hw/pci/pci_host.h"
 #include "exec/address-spaces.h"
 
hw/sh4/r2d.c +1 -0
index d1d0847..8dd2ce3 100644
@@ -30,6 +30,7 @@
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
 #include "hw/pci/pci.h"
+#include "hw/pci/pci_bus.h"
 #include "net/net.h"
 #include "sh7750_regs.h"
 #include "hw/ide.h"
hw/sh4/sh_pci.c +1 -0
index a2f6d9e..f02e998 100644
@@ -24,6 +24,7 @@
 #include "hw/sysbus.h"
 #include "hw/sh4/sh.h"
 #include "hw/pci/pci.h"
+#include "hw/pci/pci_bus.h"
 #include "hw/pci/pci_host.h"
 #include "qemu/bswap.h"
 #include "exec/address-spaces.h"
include/hw/pci/pci.h +1 -2
index be2d9b8..47077cd 100644
@@ -337,8 +337,6 @@ 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);
 typedef PCIINTxRoute (*pci_route_irq_fn)(void *opaque, int pin);
 
-#define TYPE_PCI_BUS "PCI"
-#define PCI_BUS(obj) OBJECT_CHECK(PCIBus, (obj), TYPE_PCI_BUS)
 #define TYPE_PCIE_BUS "PCIE"
 
 bool pci_bus_is_express(PCIBus *bus);
@@ -370,6 +368,7 @@ void pci_bus_fire_intx_routing_notifier(PCIBus *bus);
 void pci_device_set_intx_routing_notifier(PCIDevice *dev,
                                           PCIINTxRoutingNotifier notifier);
 void pci_device_reset(PCIDevice *dev);
+void pci_do_device_reset(PCIDevice *dev);
 
 PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,
                                const char *default_model,
include/hw/pci/pci_bus.h +8 -0
index fabaeee..ea427a3 100644
@@ -1,6 +1,8 @@
 #ifndef QEMU_PCI_BUS_H
 #define QEMU_PCI_BUS_H
 
+#include "hw/pci/pci.h"
+
 /*
  * PCI Bus and Bridge datastructures.
  *
@@ -8,6 +10,12 @@
  * use accessor functions in pci.h, pci_bridge.h
  */
 
+PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num);
+PciDeviceInfoList *qmp_query_pci_devices(PCIBus *bus, int bus_num);
+
+#define TYPE_PCI_BUS "PCI"
+#define PCI_BUS(obj) OBJECT_CHECK(PCIBus, (obj), TYPE_PCI_BUS)
+
 struct PCIBus {
     BusState qbus;
     PCIIOMMUFunc iommu_fn;
Signature · 1 line
2.1.0
#44 lore raw

PATCH v4 15/25 hw/pci: made pci_bus_is_root a PCIBusClass method

In reply to Marcel Apfelbaum

From: Marcel Apfelbaum <[email protected]>

Refactoring it as a method of PCIBusClass will allow different implementations for subclasses.

Removed the assumption that the root bus does not have a parent device because is specific only to the default class implementation.

---
 hw/pci/pci.c             | 11 ++++-------
 hw/pci/pci_bus.c         |  9 +++++++++
 hw/vfio/pci.c            |  1 +
 include/hw/pci/pci.h     |  1 -
 include/hw/pci/pci_bus.h | 15 +++++++++++++++
 5 files changed, 29 insertions(+), 8 deletions(-)
hw/pci/pci.c +4 -7
index 442d209..196989f 100644
@@ -205,7 +205,10 @@ PCIBus *pci_device_root_bus(const PCIDevice *d)
 {
     PCIBus *bus = d->bus;
 
-    while ((d = bus->parent_dev) != NULL) {
+    while (!pci_bus_is_root(bus)) {
+        d = bus->parent_dev;
+        assert(d != NULL);
+
         bus = d->bus;
     }
 
@@ -218,7 +221,6 @@ const char *pci_root_bus_path(PCIDevice *dev)
     PCIHostState *host_bridge = PCI_HOST_BRIDGE(rootbus->qbus.parent);
     PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_GET_CLASS(host_bridge);
 
-    assert(!rootbus->parent_dev);
     assert(host_bridge->bus == rootbus);
 
     if (hc->root_bus_path) {
@@ -250,11 +252,6 @@ bool pci_bus_is_express(PCIBus *bus)
     return object_dynamic_cast(OBJECT(bus), TYPE_PCIE_BUS);
 }
 
-bool pci_bus_is_root(PCIBus *bus)
-{
-    return !bus->parent_dev;
-}
-
 void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent,
                          const char *name,
                          MemoryRegion *address_space_mem,
hw/pci/pci_bus.c +9 -0
index d156194..0922a75 100644
@@ -464,9 +464,15 @@ static void pcibus_reset(BusState *qbus)
     }
 }
 
+static bool pcibus_is_root(PCIBus *bus)
+{
+    return !bus->parent_dev;
+}
+
 static void pci_bus_class_init(ObjectClass *klass, void *data)
 {
     BusClass *k = BUS_CLASS(klass);
+    PCIBusClass *pbc = PCI_BUS_CLASS(klass);
 
     k->print_dev = pcibus_dev_print;
     k->get_dev_path = pcibus_get_dev_path;
@@ -474,11 +480,14 @@ static void pci_bus_class_init(ObjectClass *klass, void *data)
     k->realize = pci_bus_realize;
     k->unrealize = pci_bus_unrealize;
     k->reset = pcibus_reset;
+
+    pbc->is_root = pcibus_is_root;
 }
 
 static const TypeInfo pci_bus_info = {
     .name = TYPE_PCI_BUS,
     .parent = TYPE_BUS,
+    .class_size = sizeof(PCIBusClass),
     .instance_size = sizeof(PCIBus),
     .class_init = pci_bus_class_init,
 };
hw/vfio/pci.c +1 -0
index 84e9d99..e8057db 100644
@@ -32,6 +32,7 @@
 #include "hw/pci/msi.h"
 #include "hw/pci/msix.h"
 #include "hw/pci/pci.h"
+#include "hw/pci/pci_bus.h"
 #include "qemu-common.h"
 #include "qemu/error-report.h"
 #include "qemu/event_notifier.h"
include/hw/pci/pci.h +0 -1
index 47077cd..ae2c4a5 100644
@@ -340,7 +340,6 @@ typedef PCIINTxRoute (*pci_route_irq_fn)(void *opaque, int pin);
 #define TYPE_PCIE_BUS "PCIE"
 
 bool pci_bus_is_express(PCIBus *bus);
-bool pci_bus_is_root(PCIBus *bus);
 void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent,
                          const char *name,
                          MemoryRegion *address_space_mem,
include/hw/pci/pci_bus.h +15 -0
index ea427a3..306ef10 100644
@@ -15,6 +15,16 @@ PciDeviceInfoList *qmp_query_pci_devices(PCIBus *bus, int bus_num);
 
 #define TYPE_PCI_BUS "PCI"
 #define PCI_BUS(obj) OBJECT_CHECK(PCIBus, (obj), TYPE_PCI_BUS)
+#define PCI_BUS_CLASS(klass) OBJECT_CLASS_CHECK(PCIBusClass, (klass), TYPE_PCI_BUS)
+#define PCI_BUS_GET_CLASS(obj) OBJECT_GET_CLASS(PCIBusClass, (obj), TYPE_PCI_BUS)
+
+typedef struct PCIBusClass {
+    /*< private >*/
+    BusClass parent_class;
+    /*< public >*/
+
+    bool (*is_root)(PCIBus *bus);
+} PCIBusClass;
 
 struct PCIBus {
     BusState qbus;
@@ -39,6 +49,11 @@ struct PCIBus {
     int *irq_count;
 };
 
+static inline bool pci_bus_is_root(PCIBus *bus)
+{
+    return PCI_BUS_GET_CLASS(bus)->is_root(bus);
+}
+
 typedef struct PCIBridgeWindows PCIBridgeWindows;
 
 /*
Signature · 1 line
2.1.0
#45 lore raw

PATCH v4 16/25 hw/pci: made pci_bus_num a PCIBusClass method

In reply to Marcel Apfelbaum

From: Marcel Apfelbaum <[email protected]>

Refactoring it as a method of PCIBusClass will allow different implementations for subclasses.

---
 hw/i386/kvm/pci-assign.c |  1 +
 hw/pci/pci.c             |  7 -------
 hw/pci/pci_bus.c         | 10 ++++++++++
 hw/scsi/megasas.c        |  1 +
 hw/xen/xen_pt.c          |  1 +
 include/hw/pci/pci.h     |  1 -
 include/hw/pci/pci_bus.h |  6 ++++++
 7 files changed, 19 insertions(+), 8 deletions(-)
hw/i386/kvm/pci-assign.c +1 -0
index 9db7c77..ad573ec 100644
@@ -35,6 +35,7 @@
 #include "qemu/range.h"
 #include "sysemu/sysemu.h"
 #include "hw/pci/pci.h"
+#include "hw/pci/pci_bus.h"
 #include "hw/pci/msi.h"
 #include "kvm_i386.h"
 
hw/pci/pci.c +0 -7
index 196989f..e386f2c 100644
@@ -301,13 +301,6 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name,
     return bus;
 }
 
-int pci_bus_num(PCIBus *s)
-{
-    if (pci_bus_is_root(s))
-        return 0;       /* pci host bridge */
-    return s->parent_dev->config[PCI_SECONDARY_BUS];
-}
-
 static int get_pci_config_device(QEMUFile *f, void *pv, size_t size)
 {
     PCIDevice *s = container_of(pv, PCIDevice, config);
hw/pci/pci_bus.c +10 -0
index 0922a75..ed99208 100644
@@ -469,6 +469,15 @@ static bool pcibus_is_root(PCIBus *bus)
     return !bus->parent_dev;
 }
 
+static int pcibus_num(PCIBus *bus)
+{
+    if (pcibus_is_root(bus)) {
+        return 0;       /* pci host bridge */
+    }
+
+    return bus->parent_dev->config[PCI_SECONDARY_BUS];
+}
+
 static void pci_bus_class_init(ObjectClass *klass, void *data)
 {
     BusClass *k = BUS_CLASS(klass);
@@ -482,6 +491,7 @@ static void pci_bus_class_init(ObjectClass *klass, void *data)
     k->reset = pcibus_reset;
 
     pbc->is_root = pcibus_is_root;
+    pbc->bus_num = pcibus_num;
 }
 
 static const TypeInfo pci_bus_info = {
hw/scsi/megasas.c +1 -0
index 4852237..fa4e3d0 100644
@@ -20,6 +20,7 @@
 
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
+#include "hw/pci/pci_bus.h"
 #include "sysemu/dma.h"
 #include "sysemu/block-backend.h"
 #include "hw/pci/msi.h"
hw/xen/xen_pt.c +1 -0
index f2893b2..cf56a48 100644
@@ -55,6 +55,7 @@
 #include <sys/ioctl.h>
 
 #include "hw/pci/pci.h"
+#include "hw/pci/pci_bus.h"
 #include "hw/xen/xen.h"
 #include "hw/xen/xen_backend.h"
 #include "xen_pt.h"
include/hw/pci/pci.h +0 -1
index ae2c4a5..a69cf94 100644
@@ -375,7 +375,6 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,
 
 PCIDevice *pci_vga_init(PCIBus *bus);
 
-int pci_bus_num(PCIBus *s);
 void pci_for_each_device(PCIBus *bus, int bus_num,
                          void (*fn)(PCIBus *bus, PCIDevice *d, void *opaque),
                          void *opaque);
include/hw/pci/pci_bus.h +6 -0
index 306ef10..553814e 100644
@@ -24,6 +24,7 @@ typedef struct PCIBusClass {
     /*< public >*/
 
     bool (*is_root)(PCIBus *bus);
+    int (*bus_num)(PCIBus *bus);
 } PCIBusClass;
 
 struct PCIBus {
@@ -54,6 +55,11 @@ static inline bool pci_bus_is_root(PCIBus *bus)
     return PCI_BUS_GET_CLASS(bus)->is_root(bus);
 }
 
+static inline int pci_bus_num(PCIBus *bus)
+{
+    return PCI_BUS_GET_CLASS(bus)->bus_num(bus);
+}
+
 typedef struct PCIBridgeWindows PCIBridgeWindows;
 
 /*
Signature · 1 line
2.1.0
#46 lore raw

PATCH v4 17/25 hw/pci: introduce TYPE_PCI_MAIN_HOST_BRIDGE interface

In reply to Marcel Apfelbaum

From: Marcel Apfelbaum <[email protected]>

This is a marker interface used to differentiate the "default" host bridge on a system with multiple host bridges. This differentiation is required only for pc machines for now by the ACPI subsystem.

---
 hw/i386/acpi-build.c      | 9 ++++++---
 hw/pci-host/piix.c        | 5 +++++
 hw/pci-host/q35.c         | 4 ++++
 hw/pci/pci_host.c         | 6 ++++++
 include/hw/pci/pci_host.h | 7 +++++++
 5 files changed, 28 insertions(+), 3 deletions(-)
hw/i386/acpi-build.c +6 -3
index 44819b8..7cd011d 100644
@@ -251,7 +251,8 @@ static void acpi_get_pci_info(PcPciInfo *info)
     Object *pci_host;
     bool ambiguous;
 
-    pci_host = object_resolve_path_type("", TYPE_PCI_HOST_BRIDGE, &ambiguous);
+    pci_host = object_resolve_path_type("", TYPE_PCI_MAIN_HOST_BRIDGE,
+                                        &ambiguous);
     g_assert(!ambiguous);
     g_assert(pci_host);
 
@@ -1311,7 +1312,8 @@ build_ssdt(GArray *table_data, GArray *linker,
             PCIBus *bus = NULL;
             bool ambiguous;
 
-            pci_host = object_resolve_path_type("", TYPE_PCI_HOST_BRIDGE, &ambiguous);
+            pci_host = object_resolve_path_type("", TYPE_PCI_MAIN_HOST_BRIDGE,
+                                                &ambiguous);
             if (!ambiguous && pci_host) {
                 bus = PCI_HOST_BRIDGE(pci_host)->bus;
             }
@@ -1656,7 +1658,8 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)
     QObject *o;
     bool ambiguous;
 
-    pci_host = object_resolve_path_type("", TYPE_PCI_HOST_BRIDGE, &ambiguous);
+    pci_host = object_resolve_path_type("", TYPE_PCI_MAIN_HOST_BRIDGE,
+                                        &ambiguous);
     g_assert(!ambiguous);
     g_assert(pci_host);
 
hw/pci-host/piix.c +5 -0
index 292b6e9..0033ab4 100644
@@ -766,6 +766,11 @@ static const TypeInfo i440fx_pcihost_info = {
     .instance_size = sizeof(I440FXState),
     .instance_init = i440fx_pcihost_initfn,
     .class_init    = i440fx_pcihost_class_init,
+    .interfaces    = (InterfaceInfo[]) {
+        { TYPE_PCI_MAIN_HOST_BRIDGE },
+        { }
+    }
+
 };
 
 static void i440fx_register_types(void)
hw/pci-host/q35.c +4 -0
index a42d0fb..70a86af 100644
@@ -193,6 +193,10 @@ static const TypeInfo q35_host_info = {
     .instance_size = sizeof(Q35PCIHost),
     .instance_init = q35_host_initfn,
     .class_init = q35_host_class_init,
+    .interfaces = (InterfaceInfo[]) {
+        { TYPE_PCI_MAIN_HOST_BRIDGE },
+        { }
+    }
 };
 
 /****************************************************************************
hw/pci/pci_host.c +6 -0
index 3e26f92..87180c8 100644
@@ -175,6 +175,11 @@ const MemoryRegionOps pci_host_data_be_ops = {
     .endianness = DEVICE_BIG_ENDIAN,
 };
 
+static const TypeInfo pci_main_host_interface_info = {
+    .name          = TYPE_PCI_MAIN_HOST_BRIDGE,
+    .parent        = TYPE_INTERFACE,
+};
+
 static const TypeInfo pci_host_type_info = {
     .name = TYPE_PCI_HOST_BRIDGE,
     .parent = TYPE_SYS_BUS_DEVICE,
@@ -185,6 +190,7 @@ static const TypeInfo pci_host_type_info = {
 
 static void pci_host_register_types(void)
 {
+    type_register_static(&pci_main_host_interface_info);
     type_register_static(&pci_host_type_info);
 }
 
include/hw/pci/pci_host.h +7 -0
index ba31595..3c72e26 100644
@@ -30,6 +30,13 @@
 
 #include "hw/sysbus.h"
 
+/**
+ * Marker interface for classes whose instances can
+ * be main host bridges. It is intended to be used
+ * when the QOM tree includes multiple host bridges.
+ */
+#define TYPE_PCI_MAIN_HOST_BRIDGE "pci-main-host-bridge"
+
 #define TYPE_PCI_HOST_BRIDGE "pci-host-bridge"
 #define PCI_HOST_BRIDGE(obj) \
     OBJECT_CHECK(PCIHostState, (obj), TYPE_PCI_HOST_BRIDGE)
Signature · 1 line
2.1.0
#47 lore raw

PATCH v4 18/25 hw/pci: removed 'rootbus nr is 0' assumption from qmp_pci_query

In reply to Marcel Apfelbaum

From: Marcel Apfelbaum <[email protected]>

Use the newer pci_bus_num to correctly get the root bus number.

---
 hw/pci/pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/pci/pci.c +2 -1
index e386f2c..53598bd 100644
@@ -1266,7 +1266,8 @@ PciInfoList *qmp_query_pci(Error **errp)
 
     QLIST_FOREACH(host_bridge, &pci_host_bridges, next) {
         info = g_malloc0(sizeof(*info));
-        info->value = qmp_query_pci_bus(host_bridge->bus, 0);
+        info->value = qmp_query_pci_bus(host_bridge->bus,
+                                        pci_bus_num(host_bridge->bus));
 
         /* XXX: waiting for the qapi to support GSList */
         if (!cur_item) {
Signature · 1 line
2.1.0
#48 lore raw

PATCH v4 19/25 hw/pci: implement iteration over multiple host bridges

In reply to Marcel Apfelbaum

From: Marcel Apfelbaum <[email protected]>

---
 hw/pci/pci.c              | 8 ++++----
 include/hw/pci/pci_host.h | 4 ++++
 2 files changed, 8 insertions(+), 4 deletions(-)
hw/pci/pci.c +4 -4
index 53598bd..f0cf752 100644
@@ -69,7 +69,7 @@ static void pci_del_option_rom(PCIDevice *pdev);
 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 QLIST_HEAD(, PCIHostState) pci_host_bridges;
+struct PCIHostQ pci_host_bridges = QLIST_HEAD_INITIALIZER(pci_host_bridges);
 
 static int pci_bar(PCIDevice *d, int reg)
 {
@@ -190,7 +190,7 @@ PCIBus *pci_find_primary_bus(void)
     PCIBus *primary_bus = NULL;
     PCIHostState *host;
 
-    QLIST_FOREACH(host, &pci_host_bridges, next) {
+    HOST_BRIDGE_FOREACH(host) {
         if (primary_bus) {
             /* We have multiple root buses, refuse to select a primary */
             return NULL;
@@ -1264,7 +1264,7 @@ PciInfoList *qmp_query_pci(Error **errp)
     PciInfoList *info, *head = NULL, *cur_item = NULL;
     PCIHostState *host_bridge;
 
-    QLIST_FOREACH(host_bridge, &pci_host_bridges, next) {
+    HOST_BRIDGE_FOREACH(host_bridge) {
         info = g_malloc0(sizeof(*info));
         info->value = qmp_query_pci_bus(host_bridge->bus,
                                         pci_bus_num(host_bridge->bus));
@@ -1802,7 +1802,7 @@ int pci_qdev_find_device(const char *id, PCIDevice **pdev)
     PCIHostState *host_bridge;
     int rc = -ENODEV;
 
-    QLIST_FOREACH(host_bridge, &pci_host_bridges, next) {
+    HOST_BRIDGE_FOREACH(host_bridge) {
         int tmp = pci_qdev_find_recursive(host_bridge->bus, id, pdev);
         if (!tmp) {
             rc = 0;
include/hw/pci/pci_host.h +4 -0
index 3c72e26..ba5272f 100644
@@ -63,6 +63,10 @@ typedef struct PCIHostBridgeClass {
     const char *(*root_bus_path)(PCIHostState *, PCIBus *);
 } PCIHostBridgeClass;
 
+QLIST_HEAD(PCIHostQ, PCIHostState);
+extern struct PCIHostQ pci_host_bridges;
+#define HOST_BRIDGE_FOREACH(host) QLIST_FOREACH(host, &pci_host_bridges, next)
+
 /* common internal helpers for PCI/PCIe hosts, cut off overflows */
 void pci_host_config_write_common(PCIDevice *pci_dev, uint32_t addr,
                                   uint32_t limit, uint32_t val, uint32_t len);
Signature · 1 line
2.1.0
#49 lore raw

PATCH v4 20/25 hw/pci: introduce PCI Expander Bridge (PXB)

In reply to Marcel Apfelbaum

From: Marcel Apfelbaum <[email protected]>

PXB is a "light-weight" host bridge whose purpose is to enable the main host bridge to support multiple PCI root buses.

As oposed to PCI-2-PCI bridge's secondary bus, PXB's bus is a primary bus and can be associated with a NUMA node (different from the main host bridge) allowing the guest OS to recognize the proximity of a pass-through device to other resources as RAM and CPUs.

The PXB is composed from:
- A primary PCI bus (can be associated with a NUMA node) Acts like a normal pci bus and from the functionality point of view is an "expansion" of the bus behind the
main host bridge.
- A pci-2-pci bridge behind the primary PCI bus where the actual devices will be attached.
- A host-bridge PCI device
Situated on the bus behind the main host bridge, allows the BIOS to configure the bus number and IO/mem resources. It does not have its own config/data register for configuration cycles, this being handled by the main host bridge.
- A host-bridge sysbus to comply with QEMU current design.

---
 hw/pci-bridge/Makefile.objs         |   1 +
 hw/pci-bridge/pci_expander_bridge.c | 173 ++++++++++++++++++++++++++++++++++++
 include/hw/pci/pci.h                |   1 +
 3 files changed, 175 insertions(+)
 create mode 100644 hw/pci-bridge/pci_expander_bridge.c
hw/pci-bridge/Makefile.objs +1 -0
index 968b369..632e442 100644
@@ -1,4 +1,5 @@
 common-obj-y += pci_bridge_dev.o
+common-obj-y += pci_expander_bridge.o
 common-obj-y += ioh3420.o xio3130_upstream.o xio3130_downstream.o
 common-obj-y += i82801b11.o
 # NewWorld PowerMac
hw/pci-bridge/pci_expander_bridge.c new file +173 -0

173 lines not on this page · raw message

include/hw/pci/pci.h +1 -0
index a69cf94..4325784 100644
@@ -90,6 +90,7 @@
 #define PCI_DEVICE_ID_REDHAT_TEST        0x0005
 #define PCI_DEVICE_ID_REDHAT_SDHCI       0x0007
 #define PCI_DEVICE_ID_REDHAT_PCIE_HOST   0x0008
+#define PCI_DEVICE_ID_REDHAT_PXB         0x0009
 #define PCI_DEVICE_ID_REDHAT_QXL         0x0100
 
 #define FMT_PCIBUS                      PRIx64
Signature · 1 line
2.1.0
#50 lore raw

PATCH v4 21/25 hw/pci: inform bios if the system has more than one pci bridge

In reply to Marcel Apfelbaum

From: Marcel Apfelbaum <[email protected]>

The bios looks for 'etc/extra-pci-roots' to decide if is going to scan further buses after bus 0 tree.

---
 hw/i386/pc.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
hw/i386/pc.c +13 -0
index ae3ef0a..71d2f5b 100644
@@ -1072,9 +1072,22 @@ typedef struct PcGuestInfoState {
 static
 void pc_guest_info_machine_done(Notifier *notifier, void *data)
 {
+    PCIHostState *host;
+    int hosts = 0;
     PcGuestInfoState *guest_info_state = container_of(notifier,
                                                       PcGuestInfoState,
                                                       machine_done);
+    HOST_BRIDGE_FOREACH(host) {
+        hosts++;
+    }
+
+    if (hosts && guest_info_state->info.fw_cfg) {
+        uint64_t *val = g_malloc(sizeof(*val));
+        *val = cpu_to_le64(hosts - 1);
+        fw_cfg_add_file(guest_info_state->info.fw_cfg,
+                        "etc/extra-pci-roots", val, sizeof(*val));
+    }
+
     acpi_setup(&guest_info_state->info);
 }
 
Signature · 1 line
2.1.0
#51 lore raw

PATCH v4 22/25 hw/pci: piix - suport multiple host bridges

In reply to Marcel Apfelbaum

From: Marcel Apfelbaum <[email protected]>

Instead of assuming it has only one bus, it
enumerates all the host bridges until it finds
the one with bus number corresponding with the
config register.

---
 hw/pci-host/piix.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 56 insertions(+), 1 deletion(-)
hw/pci-host/piix.c +56 -1
index 0033ab4..3c3a192 100644
@@ -255,6 +255,61 @@ static void i440fx_pcihost_get_pci_hole64_end(Object *obj, Visitor *v,
     visit_type_uint64(v, &w64.end, name, errp);
 }
 
+static PCIBus *i440fx_find_primary_bus(int bus_num)
+{
+    PCIHostState *host;
+    PCIBus *bus = NULL;
+    int current = -1;
+
+    HOST_BRIDGE_FOREACH(host) {
+        int b = pci_bus_num(host->bus);
+        if (b <= bus_num && b > current) {
+            current = b;
+            bus = host->bus;
+        }
+    }
+
+    return bus;
+}
+
+static void i440fx_pcihost_data_write(void *opaque, hwaddr addr,
+                                      uint64_t val, unsigned len)
+{
+    uint32_t config_reg = PCI_HOST_BRIDGE(opaque)->config_reg;
+
+    if (config_reg & (1u << 31)) {
+        int bus_num = (config_reg >> 16) & 0xFF;
+        PCIBus *bus = i440fx_find_primary_bus(bus_num);
+
+        if (bus) {
+            pci_data_write(bus, config_reg | (addr & 3), val, len);
+        }
+    }
+}
+
+static uint64_t i440fx_pcihost_data_read(void *opaque,
+                                         hwaddr addr, unsigned len)
+{
+    uint32_t config_reg = PCI_HOST_BRIDGE(opaque)->config_reg;
+
+    if (config_reg & (1U << 31)) {
+        int bus_num = (config_reg >> 16) & 0xFF;
+        PCIBus *bus = i440fx_find_primary_bus(bus_num);
+
+        if (bus) {
+            return pci_data_read(bus, config_reg | (addr & 3), len);
+        }
+    }
+
+    return 0xffffffff;
+}
+
+const MemoryRegionOps i440fx_pcihost_data_le_ops = {
+    .read = i440fx_pcihost_data_read,
+    .write = i440fx_pcihost_data_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+};
+
 static void i440fx_pcihost_initfn(Object *obj)
 {
     PCIHostState *s = PCI_HOST_BRIDGE(obj);
@@ -262,7 +317,7 @@ static void i440fx_pcihost_initfn(Object *obj)
 
     memory_region_init_io(&s->conf_mem, obj, &pci_host_conf_le_ops, s,
                           "pci-conf-idx", 4);
-    memory_region_init_io(&s->data_mem, obj, &pci_host_data_le_ops, s,
+    memory_region_init_io(&s->data_mem, obj, &i440fx_pcihost_data_le_ops, s,
                           "pci-conf-data", 4);
 
     object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_START, "int",
Signature · 1 line
2.1.0
#52 lore raw

PATCH v4 23/25 hw/pxb: add map_irq func

In reply to Marcel Apfelbaum

The bios does not index the pxb slot number when it computes the IRQ because it resides on bus 0 and not on the current bus.
However Qemu routes the irq through bus 0 and adds the pxb slot to the IRQ computation.

Synchronize between bios and Qemu by canceling pxb's effect.

---
 hw/pci-bridge/pci_expander_bridge.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
hw/pci-bridge/pci_expander_bridge.c +19 -1
index 941f3c8..87515c1 100644
@@ -92,6 +92,24 @@ static const TypeInfo pxb_host_info = {
     .class_init    = pxb_host_class_init,
 };
 
+
+static int pxb_map_irq_fn(PCIDevice *pci_dev, int pin)
+{
+    PCIDevice *pxb = pci_dev->bus->parent_dev;
+
+    /*
+     * The bios does not index the pxb slot number when
+     * it computes the IRQ because it resides on bus 0
+     * and not on the current bus.
+     * However QEMU routes the irq through bus 0 and adds
+     * the pxb slot to the IRQ computation.
+     *
+     * Synchronize between bios and QEMU by canceling
+     * pxb's effect.
+     */
+    return pin - PCI_SLOT(pxb->devfn);
+}
+
 static int pxb_dev_initfn(PCIDevice *dev)
 {
     PXBDev *pxb = PXB_DEV(dev);
@@ -118,7 +136,7 @@ static int pxb_dev_initfn(PCIDevice *dev)
     bus->parent_dev = dev;
     bus->address_space_mem = dev->bus->address_space_mem;
     bus->address_space_io = dev->bus->address_space_io;
-    bus->map_irq = pci_swizzle_map_irq_fn;
+    bus->map_irq = pxb_map_irq_fn;
 
     bds = qdev_create(BUS(bus), "pci-bridge");
     bds->id = dev_name;
Signature · 1 line
2.1.0
#53 lore raw

PATCH v4 24/25 hw/pci_bus: add support for NUMA nodes

In reply to Marcel Apfelbaum

PCI root buses can be attached to a specific NUMA node. PCI buses are not attached be default to a NUMA node.

---
 hw/pci/pci_bus.c         | 7 +++++++
 include/hw/pci/pci_bus.h | 6 ++++++
 include/sysemu/sysemu.h  | 1 +
 3 files changed, 14 insertions(+)
hw/pci/pci_bus.c +7 -0
index ed99208..15882a7 100644
@@ -13,6 +13,7 @@
 #include "hw/pci/pci_bus.h"
 #include "hw/pci/pci_bridge.h"
 #include "monitor/monitor.h"
+#include "sysemu/sysemu.h"
 
 typedef struct {
     uint16_t class;
@@ -478,6 +479,11 @@ static int pcibus_num(PCIBus *bus)
     return bus->parent_dev->config[PCI_SECONDARY_BUS];
 }
 
+static uint16_t pcibus_numa_node(PCIBus *bus)
+{
+    return NUMA_NODE_UNASSIGNED;
+}
+
 static void pci_bus_class_init(ObjectClass *klass, void *data)
 {
     BusClass *k = BUS_CLASS(klass);
@@ -492,6 +498,7 @@ static void pci_bus_class_init(ObjectClass *klass, void *data)
 
     pbc->is_root = pcibus_is_root;
     pbc->bus_num = pcibus_num;
+    pbc->numa_node = pcibus_numa_node;
 }
 
 static const TypeInfo pci_bus_info = {
include/hw/pci/pci_bus.h +6 -0
index 553814e..75cd1fa 100644
@@ -25,6 +25,7 @@ typedef struct PCIBusClass {
 
     bool (*is_root)(PCIBus *bus);
     int (*bus_num)(PCIBus *bus);
+    uint16_t (*numa_node)(PCIBus *bus);
 } PCIBusClass;
 
 struct PCIBus {
@@ -60,6 +61,11 @@ static inline int pci_bus_num(PCIBus *bus)
     return PCI_BUS_GET_CLASS(bus)->bus_num(bus);
 }
 
+static inline int pci_bus_numa_node(PCIBus *bus)
+{
+    return PCI_BUS_GET_CLASS(bus)->numa_node(bus);
+}
+
 typedef struct PCIBridgeWindows PCIBridgeWindows;
 
 /*
include/sysemu/sysemu.h +1 -0
index e7135e1..934eb5d 100644
@@ -136,6 +136,7 @@ extern const char *mem_path;
 extern int mem_prealloc;
 
 #define MAX_NODES 128
+#define NUMA_NODE_UNASSIGNED MAX_NODES
 
 /* The following shall be true for all CPUs:
  *   cpu->cpu_index < max_cpus <= MAX_CPUMASK_BITS
Signature · 1 line
2.1.0
#54 lore raw

PATCH v4 25/25 hw/pxb: add numa_node parameter

In reply to Marcel Apfelbaum

The pxb can be attach to and existing numa node by specifying numa_node option that equals the desired numa nodeid.

---
 hw/i386/acpi-build.c                | 12 ++++++++++++
 hw/pci-bridge/pci_expander_bridge.c | 17 +++++++++++++++++
 2 files changed, 29 insertions(+)
hw/i386/acpi-build.c +12 -0
index 7cd011d..b5c0e86 100644
@@ -908,6 +908,7 @@ build_ssdt(GArray *table_data, GArray *linker,
 
         for (info = info_list; info; info = info->next) {
             PciInfo *bus_info = info->value;
+            PCIHostState *host;
 
             if (bus_info->bus == 0) {
                 continue;
@@ -924,6 +925,17 @@ build_ssdt(GArray *table_data, GArray *linker,
             aml_append(dev, aml_name_decl("_HID", aml_string("PNP0A03")));
             aml_append(dev,
                 aml_name_decl("_BBN", aml_int((uint8_t)bus_info->bus)));
+
+            HOST_BRIDGE_FOREACH(host) {
+                if (pci_bus_num(host->bus) == bus_info->bus) {
+                    int numa_node = pci_bus_numa_node(host->bus);
+                    if (numa_node != NUMA_NODE_UNASSIGNED) {
+                        aml_append(dev,
+                            aml_name_decl("_PXM", aml_int(numa_node)));
+                    }
+                }
+            }
+
             aml_append(dev, build_prt());
             crs = build_crs(pci, bus_info, &io_ranges, &mem_ranges);
             aml_append(dev, aml_name_decl("_CRS", crs));
hw/pci-bridge/pci_expander_bridge.c +17 -0
index 87515c1..9329aab 100644
@@ -16,6 +16,7 @@
 #include "hw/pci/pci_bus.h"
 #include "qemu/range.h"
 #include "qemu/error-report.h"
+#include "sysemu/sysemu.h"
 
 #define TYPE_PXB_BUS "pxb-bus"
 #define PXB_BUS(obj) OBJECT_CHECK(PXBBus, (obj), TYPE_PXB_BUS)
@@ -37,6 +38,7 @@ typedef struct PXBDev {
     /*< public >*/
 
     uint8_t bus_nr;
+    uint16_t numa_node;
 } PXBDev;
 
 #define TYPE_PXB_HOST "pxb-host"
@@ -53,12 +55,20 @@ static bool pxb_is_root(PCIBus *bus)
     return true; /* by definition */
 }
 
+static uint16_t pxb_bus_numa_node(PCIBus *bus)
+{
+    PXBDev *pxb = PXB_DEV(bus->parent_dev);
+
+    return pxb->numa_node;
+}
+
 static void pxb_bus_class_init(ObjectClass *class, void *data)
 {
     PCIBusClass *pbc = PCI_BUS_CLASS(class);
 
     pbc->bus_num = pxb_bus_num;
     pbc->is_root = pxb_is_root;
+    pbc->numa_node = pxb_bus_numa_node;
 }
 
 static const TypeInfo pxb_bus_info = {
@@ -126,6 +136,12 @@ static int pxb_dev_initfn(PCIDevice *dev)
         }
     }
 
+    if (pxb->numa_node != NUMA_NODE_UNASSIGNED &&
+        pxb->numa_node >= nb_numa_nodes) {
+        error_report("Illegal numa node %d.", pxb->numa_node);
+        return -EINVAL;
+    }
+
     if (dev->qdev.id && *dev->qdev.id) {
         dev_name = dev->qdev.id;
     }
@@ -157,6 +173,7 @@ static int pxb_dev_initfn(PCIDevice *dev)
 static Property pxb_dev_properties[] = {
     /* Note: 0 is not a legal a PXB bus number. */
     DEFINE_PROP_UINT8("bus_nr", PXBDev, bus_nr, 0),
+    DEFINE_PROP_UINT16("numa_node", PXBDev, numa_node, NUMA_NODE_UNASSIGNED),
     DEFINE_PROP_END_OF_LIST(),
 };
 
Signature · 1 line
2.1.0
#55 lore raw
In reply to Marcel Apfelbaum
Quoted 7 lines · Marcel Apfelbaum

Notes:
- Sorry for the late submission, I was waiting for dynamic ACPI series to get merged in order to submit - my bad.
- The prev version (v2) was wrongfully tagged by me as RFC, it was actually ready but not rebased. V3 only rebases with no actual functionality changed.
- This series is not that big, patches 1-8 are really small and can be submitted separately, however I preferred to keep them here to get the whole picture.

Which tree this does apply against?
Do you have a git tree with this somewhere?

cheers,
Gerd

#56 lore raw
Quoted 11 lines · Gerd Hoffmann
Quoted 7 lines · Marcel Apfelbaum

Notes:
- Sorry for the late submission, I was waiting for dynamic ACPI series to get merged in order to submit - my bad.
- The prev version (v2) was wrongfully tagged by me as RFC, it was actually ready but not rebased. V3 only rebases with no actual functionality changed.
- This series is not that big, patches 1-8 are really small and can be submitted separately, however I preferred to keep them here to get the whole picture.

Which tree this does apply against?
Do you have a git tree with this somewhere?

Michael's pci branch of:
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git

Thanks,
Marcel

Quoted 5 lines

cheers,
Gerd

#57 lore raw
Quoted 10 lines · Marcel Apfelbaum
Quoted 9 lines · Gerd Hoffmann
Quoted 7 lines · Marcel Apfelbaum

Notes:
- Sorry for the late submission, I was waiting for dynamic ACPI series to get merged in order to submit - my bad.
- The prev version (v2) was wrongfully tagged by me as RFC, it was actually ready but not rebased. V3 only rebases with no actual functionality changed.
- This series is not that big, patches 1-8 are really small and can be submitted separately, however I preferred to keep them here to get the whole picture.

Quoted 5 lines
Quoted 2 lines

Which tree this does apply against?
Do you have a git tree with this somewhere?

Michael's pci branch of:
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git

Hmm, not working for me ...

nilsson kraxel ~/projects/qemu ((a3b66ab...))# git checkout -b testing mst/pci
M roms/seabios
Branch testing set up to track remote branch pci from mst. Switched to a new branch 'testing'
nilsson kraxel ~/projects/qemu (testing)# git am -s ~/Downloads/patches/testing/\[Qemu-devel\]_\[PATCH_v4_for-2.3_01_25 \]_acpi\:_fix_aml_equal_term_implementation.mbox
Applying: acpi: fix aml_equal term implementation
error: patch failed: hw/acpi/aml-build.c:542
error: hw/acpi/aml-build.c: patch does not apply
Patch failed at 0001 acpi: fix aml_equal term implementation The copy of the patch that failed is found in:
/home/kraxel/projects/qemu/.git/rebase-apply/patch
When you have resolved this problem, run "git am --resolved". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". nilsson kraxel ~/projects/qemu (testing|AM 1/25)#

cheers,
Gerd

#58 lore raw
Quoted 29 lines · Gerd Hoffmann
Quoted 10 lines · Marcel Apfelbaum
Quoted 9 lines · Gerd Hoffmann
Quoted 7 lines · Marcel Apfelbaum

Notes:
- Sorry for the late submission, I was waiting for dynamic ACPI series to get merged in order to submit - my bad.
- The prev version (v2) was wrongfully tagged by me as RFC, it was actually ready but not rebased. V3 only rebases with no actual functionality changed.
- This series is not that big, patches 1-8 are really small and can be submitted separately, however I preferred to keep them here to get the whole picture.

Quoted 5 lines
Quoted 2 lines

Which tree this does apply against?
Do you have a git tree with this somewhere?

Michael's pci branch of:
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git

Hmm, not working for me ...

nilsson kraxel ~/projects/qemu ((a3b66ab...))# git checkout -b testing mst/pci
M roms/seabios
Branch testing set up to track remote branch pci from mst. Switched to a new branch 'testing'
nilsson kraxel ~/projects/qemu (testing)# git am -s ~/Downloads/patches/testing/\[Qemu-devel\]_\[PATCH_v4_for-2.3_01_25 \]_acpi\:_fix_aml_equal_term_implementation.mbox
Applying: acpi: fix aml_equal term implementation
error: patch failed: hw/acpi/aml-build.c:542

Quoted 8 lines

error: hw/acpi/aml-build.c: patch does not apply
Patch failed at 0001 acpi: fix aml_equal term implementation The copy of the patch that failed is found in:
/home/kraxel/projects/qemu/.git/rebase-apply/patch
When you have resolved this problem, run "git am --resolved". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". nilsson kraxel ~/projects/qemu (testing|AM 1/25)#

My series is based on commit 09d219a. Try please on top of this commit. I'll rebase it to HEAD for v5 (today or tomorrow)

Thanks,
Marcel

Quoted 5 lines

cheers,
Gerd

#59 lore raw

Hi,

Quoted 1 line

My series is based on commit 09d219a. Try please on top of this commit.

Ok, that works. Going to play with that now ;)

thanks,
Gerd

#60 lore raw
Quoted 5 lines · Gerd Hoffmann
   Hi,
Quoted 1 line

My series is based on commit 09d219a. Try please on top of this commit.

Ok, that works. Going to play with that now ;)

Good luck! ... and tell me what you think :)
If you need any help with the command line of the pxb device, let me know,.

Thanks,
Marcel

Quoted 5 lines

thanks,
Gerd

#61 lore raw
Quoted 8 lines · Marcel Apfelbaum
Quoted 5 lines · Gerd Hoffmann
   Hi,
Quoted 1 line

My series is based on commit 09d219a. Try please on top of this commit.

Ok, that works. Going to play with that now ;)

Good luck! ... and tell me what you think :)
If you need any help with the command line of the pxb device, let me know,.

First thing I've noticed: You need to define a numa node so you can pass a valid numa node to the pxb-device. Guess that is ok as the whole point of this is to assign pci devices to numa nodes. More complete test instructions would be nice though.

Second thing: Booting with an unpatched seabios has bad effects:

[root@localhost ~]# cat /proc/iomem
00000000-000fffff : PCI Bus 0000:10
00000000-00000fff : reserved
00001000-0009fbff : System RAM
0009fc00-0009ffff : reserved
000c0000-000c91ff : Video ROM
000c9800-000ca1ff : Adapter ROM
000ca800-000ccbff : Adapter ROM
000f0000-000fffff : reserved

    000f0000-000fffff : System ROM

00100000-3ffdffff : System RAM
01000000-0174bde4 : Kernel code
0174bde5-01d30cff : Kernel data
01eaa000-0202afff : Kernel bss
3ffe0000-3fffffff : reserved
fd000000-fdffffff : 0000:00:02.0
fd000000-fdffffff : bochs-drm
febc0000-febdffff : 0000:00:03.0
febc0000-febdffff : e1000
febf0000-febf0fff : 0000:00:02.0
febf0000-febf0fff : bochs-drm
fec00000-fec003ff : IOAPIC 0
fed00000-fed003ff : HPET 0
fed00000-fed003ff : PNP0103:00
fee00000-fee00fff : Local APIC
feffc000-feffffff : reserved
fffc0000-ffffffff : reserved

"PCI Bus 0000:10" is bogus and "PCI Bus 0000:00" isn't there at all.

cheers,
Gerd

#62 lore raw
Quoted 6 lines · Gerd Hoffmann
Quoted 5 lines · Marcel Apfelbaum
Quoted 4 lines · Gerd Hoffmann
    Hi,
Quoted 1 line

My series is based on commit 09d219a. Try please on top of this commit.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Ok, that works. Going to play with that now ;)

Good luck! ... and tell me what you think :)
If you need any help with the command line of the pxb device, let me know,.

First thing I've noticed: You need to define a numa node so you can pass a valid numa node to the pxb-device. Guess that is ok as the whole point of this is to assign pci devices to numa nodes. More complete test instructions would be nice though.

Exactly, this is by design. But you can also use it without specifying the NUMA node...

A detailed command line would be:

[qemu-bin + storage options]
-bios [seabios-dir]/out/bios.bin -L [seabios-dir]/out/
-m 2G
-object memory-backend-ram,size=1024M,policy=bind,host-nodes=0,id=ram-node0 -numa node,nodeid=0,cpus=0,memdev=ram-node0 -object memory-backend-ram,size=1024M,policy=interleave,host-nodes=0,id=ram-node1 -numa node,nodeid=1,cpus=1,memdev=ram-node1 -device pxb-device,id=bridge1,bus=pci.0,numa_node=1,bus_nr=4 -netdev user,id=nd-device e1000,bus=bridge1,addr=0x4,netdev=nd -device pxb-device,id=bridge2,bus=pci.0,numa_node=0,bus_nr=8 -device e1000,bus=bridge2,addr=0x3
-device pxb-device,id=bridge3,bus=pci.0,bus_nr=40 -drive if=none,id=drive0,file=[img] -device virtio-blk-pci,drive=drive0,scsi=off,bus=bridge3,addr=1

Here you have:
- 2 NUMA nodes for the guest, 0 and 1. (both mapped to the same NUMA node in host, but you can and should put it in different host NUMA nodes)
- a pxb host bridge attached to NUMA 1 with an e1000 behind it
- a pxb host bridge attached to NUMA 0 with an e1000 behind it
- a pxb host bridge not attached to any NUMA with a hard drive behind it.

As you can see, since you already "decide" NUMA mapping at command line, it is "natural" also to attach the pxbs to the NUMA nodes.

Quoted 31 lines

Second thing: Booting with an unpatched seabios has bad effects:

[root@localhost ~]# cat /proc/iomem
00000000-000fffff : PCI Bus 0000:10
00000000-00000fff : reserved
00001000-0009fbff : System RAM
0009fc00-0009ffff : reserved
000c0000-000c91ff : Video ROM
000c9800-000ca1ff : Adapter ROM
000ca800-000ccbff : Adapter ROM
000f0000-000fffff : reserved

     000f0000-000fffff : System ROM

00100000-3ffdffff : System RAM
01000000-0174bde4 : Kernel code
0174bde5-01d30cff : Kernel data
01eaa000-0202afff : Kernel bss
3ffe0000-3fffffff : reserved
fd000000-fdffffff : 0000:00:02.0
fd000000-fdffffff : bochs-drm
febc0000-febdffff : 0000:00:03.0
febc0000-febdffff : e1000
febf0000-febf0fff : 0000:00:02.0
febf0000-febf0fff : bochs-drm
fec00000-fec003ff : IOAPIC 0
fed00000-fed003ff : HPET 0
fed00000-fed003ff : PNP0103:00
fee00000-fee00fff : Local APIC
feffc000-feffffff : reserved
fffc0000-ffffffff : reserved

Quoted 1 line

"PCI Bus 0000:10" is bogus and "PCI Bus 0000:00" isn't there at all.

Yes, you shouldn't use pxb if you are not using the corresponding SeaBIOS. However, as I understand we always attach a SeaBIOS binary with a QEMU release, so we should be OK with this.

And this is the reason I wanted bios support *before* the PXB device implementation, but anyway, even if we have them in the same time, as long as the release has both pxb and BIOS with pxb support, is OK. (I think...)

I appreciate you looking into this and if you need further assistance don't hesitate to mail me! :)

Thanks,
Marcel

Quoted 5 lines

cheers,
Gerd

#63 lore raw
Quoted 29 lines · Marcel Apfelbaum
Quoted 6 lines · Gerd Hoffmann
Quoted 5 lines · Marcel Apfelbaum
Quoted 4 lines · Gerd Hoffmann
    Hi,
Quoted 1 line

My series is based on commit 09d219a. Try please on top of this commit.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Ok, that works. Going to play with that now ;)

Good luck! ... and tell me what you think :)
If you need any help with the command line of the pxb device, let me know,.

First thing I've noticed: You need to define a numa node so you can pass a valid numa node to the pxb-device. Guess that is ok as the whole point of this is to assign pci devices to numa nodes. More complete test instructions would be nice though.

Exactly, this is by design. But you can also use it without specifying the NUMA node...

A detailed command line would be:

[qemu-bin + storage options]

(quoted diff) +0 -5
-bios [seabios-dir]/out/bios.bin -L [seabios-dir]/out/
-m 2G
-object memory-backend-ram,size=1024M,policy=bind,host-nodes=0,id=ram-node0
-numa node,nodeid=0,cpus=0,memdev=ram-node0
-object

memory-backend-ram,size=1024M,policy=interleave,host-nodes=0,id=ram-node1

(quoted diff) +0 -2
-numa node,nodeid=1,cpus=1,memdev=ram-node1
-device pxb-device,id=bridge1,bus=pci.0,numa_node=1,bus_nr=4 -netdev
Quoted 6 lines

user,id=nd-device e1000,bus=bridge1,addr=0x4,netdev=nd -device pxb-device,id=bridge2,bus=pci.0,numa_node=0,bus_nr=8 -device e1000,bus=bridge2,addr=0x3
-device pxb-device,id=bridge3,bus=pci.0,bus_nr=40 -drive if=none,id=drive0,file=[img] -device virtio-blk-pci,drive=drive0,scsi=off,bus=bridge3,addr=1

I replayed this patchset on top of 09d219a "acpi: update generated files" and got this:

qemu-system-x86_64: -object memory-backend-ram,size=1024M,policy=bind,host-nodes=0,id=ram-node0: NUMA node binding are not supported by this QEMU
qemu-system-x86_64: -object memory-backend-ram,size=1024M,policy=interleave,host-nodes=0,id=ram-node1: NUMA node binding are not supported by this QEMU

This is my exact command line:

/scratch/alexey/p/qemu-build/x86_x86_64/x86_64-softmmu/qemu-system-x86_64 \
-L /home/alexey/p/qemu/pc-bios/ \
-hda x86/fc19_24GB_x86.qcow2 \
-enable-kvm \
-kernel x86/vmlinuz-3.12.11-201.fc19.x86_64 \
-initrd x86/initramfs-3.12.11-201.fc19.x86_64.img \
-append "root=/dev/sda3 console=ttyS0" \
-nographic \
-nodefaults \
-chardev stdio,id=id2,signal=off,mux=on \
-device isa-serial,id=id3,chardev=id2 \
-mon id=id4,chardev=id2,mode=readline \
-m 2G \
-object memory-backend-ram,size=1024M,policy=bind,host-nodes=0,id=ram-node0 \
-numa node,nodeid=0,cpus=0,memdev=ram-node0 \
-object memory-backend-ram,size=1024M,policy=interleave,host-nodes=0,id=ram-node1 \
-numa node,nodeid=1,cpus=1,memdev=ram-node1 \
-device pxb-device,id=bridge1,bus=pci.0,numa_node=1,bus_nr=4 \
-netdev user,id=nd-device e1000,bus=bridge1,addr=0x4,netdev=nd \
-device pxb-device,id=bridge2,bus=pci.0,numa_node=0,bus_nr=8 \
-device e1000,bus=bridge2,addr=0x3 \
-device pxb-device,id=bridge3,bus=pci.0,bus_nr=40 \
-drive if=none,id=drive0,file=debian_lenny_powerpc_desktop.qcow2 \
-device virtio-blk-pci,drive=drive0,scsi=off,bus=bridge3,addr=1 \

What am I missing here?

What I actually wanted to find out (instead of asking what I am doing now) is is this PXB device a PCI device sitting on the same PCI host bus adapter (1) or it is a separate PHB (2) with its own PCI domain (new XXXX in XXXX:00:00.0 PCI address)? I would think it is (1) but then what exactly do you call "A primary PCI bus" here (that's my ignorance speaking, yes :) )? Thanks.

Quoted 65 lines

Here you have:
- 2 NUMA nodes for the guest, 0 and 1. (both mapped to the same NUMA node
in host, but you can and should put it in different host NUMA nodes)
- a pxb host bridge attached to NUMA 1 with an e1000 behind it
- a pxb host bridge attached to NUMA 0 with an e1000 behind it
- a pxb host bridge not attached to any NUMA with a hard drive behind it.

As you can see, since you already "decide" NUMA mapping at command line, it is "natural" also to attach the pxbs to the NUMA nodes.

Quoted 31 lines

Second thing: Booting with an unpatched seabios has bad effects:

[root@localhost ~]# cat /proc/iomem
00000000-000fffff : PCI Bus 0000:10
00000000-00000fff : reserved
00001000-0009fbff : System RAM
0009fc00-0009ffff : reserved
000c0000-000c91ff : Video ROM
000c9800-000ca1ff : Adapter ROM
000ca800-000ccbff : Adapter ROM
000f0000-000fffff : reserved

     000f0000-000fffff : System ROM

00100000-3ffdffff : System RAM
01000000-0174bde4 : Kernel code
0174bde5-01d30cff : Kernel data
01eaa000-0202afff : Kernel bss
3ffe0000-3fffffff : reserved
fd000000-fdffffff : 0000:00:02.0
fd000000-fdffffff : bochs-drm
febc0000-febdffff : 0000:00:03.0
febc0000-febdffff : e1000
febf0000-febf0fff : 0000:00:02.0
febf0000-febf0fff : bochs-drm
fec00000-fec003ff : IOAPIC 0
fed00000-fed003ff : HPET 0
fed00000-fed003ff : PNP0103:00
fee00000-fee00fff : Local APIC
feffc000-feffffff : reserved
fffc0000-ffffffff : reserved

Quoted 1 line

"PCI Bus 0000:10" is bogus and "PCI Bus 0000:00" isn't there at all.

Yes, you shouldn't use pxb if you are not using the corresponding SeaBIOS. However, as I understand we always attach a SeaBIOS binary with a QEMU release,
so we should be OK with this.

And this is the reason I wanted bios support *before* the PXB device implementation,
but anyway, even if we have them in the same time, as long as the release has both pxb and BIOS with pxb support, is OK. (I think...)

I appreciate you looking into this and if you need further assistance don't hesitate to mail me! :)

Thanks,
Marcel

Quoted 5 lines

cheers,
Gerd

Signature · 1 line
Alexey
#64 lore raw
Quoted 41 lines · Alexey Kardashevskiy
Quoted 29 lines · Marcel Apfelbaum
Quoted 6 lines · Gerd Hoffmann
Quoted 5 lines · Marcel Apfelbaum
Quoted 4 lines · Gerd Hoffmann
    Hi,
Quoted 1 line

My series is based on commit 09d219a. Try please on top of this commit.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Ok, that works. Going to play with that now ;)

Good luck! ... and tell me what you think :)
If you need any help with the command line of the pxb device, let me know,.

First thing I've noticed: You need to define a numa node so you can pass a valid numa node to the pxb-device. Guess that is ok as the whole point of this is to assign pci devices to numa nodes. More complete test instructions would be nice though.

Exactly, this is by design. But you can also use it without specifying the NUMA node...

A detailed command line would be:

[qemu-bin + storage options]

(quoted diff) +0 -5
-bios [seabios-dir]/out/bios.bin -L [seabios-dir]/out/
-m 2G
-object memory-backend-ram,size=1024M,policy=bind,host-nodes=0,id=ram-node0
-numa node,nodeid=0,cpus=0,memdev=ram-node0
-object

memory-backend-ram,size=1024M,policy=interleave,host-nodes=0,id=ram-node1

(quoted diff) +0 -2
-numa node,nodeid=1,cpus=1,memdev=ram-node1
-device pxb-device,id=bridge1,bus=pci.0,numa_node=1,bus_nr=4 -netdev
Quoted 6 lines

user,id=nd-device e1000,bus=bridge1,addr=0x4,netdev=nd -device pxb-device,id=bridge2,bus=pci.0,numa_node=0,bus_nr=8 -device e1000,bus=bridge2,addr=0x3
-device pxb-device,id=bridge3,bus=pci.0,bus_nr=40 -drive if=none,id=drive0,file=[img] -device virtio-blk-pci,drive=drive0,scsi=off,bus=bridge3,addr=1

I replayed this patchset on top of 09d219a "acpi: update generated files" and got this:

Quoted 2 lines

qemu-system-x86_64: -object memory-backend-ram,size=1024M,policy=bind,host-nodes=0,id=ram-node0: NUMA node binding are not supported by this QEMU
qemu-system-x86_64: -object memory-backend-ram,size=1024M,policy=interleave,host-nodes=0,id=ram-node1: NUMA node binding are not supported by this QEMU

Hi,

Please check your configuration (after you run ./configure script). See if you have a line like this:
- NUMA host support yes

Quoted 30 lines

This is my exact command line:

/scratch/alexey/p/qemu-build/x86_x86_64/x86_64-softmmu/qemu-system-x86_64 \

(quoted diff) +0 -23
-L /home/alexey/p/qemu/pc-bios/ \
-hda x86/fc19_24GB_x86.qcow2 \
-enable-kvm \
-kernel x86/vmlinuz-3.12.11-201.fc19.x86_64 \
-initrd x86/initramfs-3.12.11-201.fc19.x86_64.img \
-append "root=/dev/sda3 console=ttyS0" \
-nographic \
-nodefaults \
-chardev stdio,id=id2,signal=off,mux=on \
-device isa-serial,id=id3,chardev=id2 \
-mon id=id4,chardev=id2,mode=readline \
-m 2G \
-object memory-backend-ram,size=1024M,policy=bind,host-nodes=0,id=ram-node0 \
-numa node,nodeid=0,cpus=0,memdev=ram-node0 \
-object memory-backend-ram,size=1024M,policy=interleave,host-nodes=0,id=ram-node1 \
-numa node,nodeid=1,cpus=1,memdev=ram-node1 \
-device pxb-device,id=bridge1,bus=pci.0,numa_node=1,bus_nr=4 \
-netdev user,id=nd-device e1000,bus=bridge1,addr=0x4,netdev=nd \
-device pxb-device,id=bridge2,bus=pci.0,numa_node=0,bus_nr=8 \
-device e1000,bus=bridge2,addr=0x3 \
-device pxb-device,id=bridge3,bus=pci.0,bus_nr=40 \
-drive if=none,id=drive0,file=debian_lenny_powerpc_desktop.qcow2 \
-device virtio-blk-pci,drive=drive0,scsi=off,bus=bridge3,addr=1 \
Quoted 1 line

What am I missing here?

See above, check for NUMA host support

Quoted 4 lines

What I actually wanted to find out (instead of asking what I am doing now) is is this PXB device a PCI device sitting on the same PCI host bus adapter (1) or it is a separate PHB (2) with its own PCI domain (new XXXX in XXXX:00:00.0 PCI address)? I would think it is (1) but then what exactly do you call "A primary PCI bus" here (that's my ignorance speaking, yes :) )? Thanks.

You are right, the PXB is a device on the piix host-bridge bus and its bus uses the same PCI domain. However, the bus behind is exposed through ACPI as Primary PCI bus and starts a new PCI hierarchy.

You have a similar approach on Intel 450x chipset:
http://www.intel.com/design/chipsets/datashts/243771.htm
Look for 82454NX PCI Expander Bridge (PXB)

Thanks,
Marcel

Quoted 70 lines
Quoted 68 lines

Here you have:
- 2 NUMA nodes for the guest, 0 and 1. (both mapped to the same NUMA node
in host, but you can and should put it in different host NUMA nodes)
- a pxb host bridge attached to NUMA 1 with an e1000 behind it
- a pxb host bridge attached to NUMA 0 with an e1000 behind it
- a pxb host bridge not attached to any NUMA with a hard drive behind it.

As you can see, since you already "decide" NUMA mapping at command line, it is "natural" also to attach the pxbs to the NUMA nodes.

Quoted 31 lines

Second thing: Booting with an unpatched seabios has bad effects:

[root@localhost ~]# cat /proc/iomem
00000000-000fffff : PCI Bus 0000:10
00000000-00000fff : reserved
00001000-0009fbff : System RAM
0009fc00-0009ffff : reserved
000c0000-000c91ff : Video ROM
000c9800-000ca1ff : Adapter ROM
000ca800-000ccbff : Adapter ROM
000f0000-000fffff : reserved

     000f0000-000fffff : System ROM

00100000-3ffdffff : System RAM
01000000-0174bde4 : Kernel code
0174bde5-01d30cff : Kernel data
01eaa000-0202afff : Kernel bss
3ffe0000-3fffffff : reserved
fd000000-fdffffff : 0000:00:02.0
fd000000-fdffffff : bochs-drm
febc0000-febdffff : 0000:00:03.0
febc0000-febdffff : e1000
febf0000-febf0fff : 0000:00:02.0
febf0000-febf0fff : bochs-drm
fec00000-fec003ff : IOAPIC 0
fed00000-fed003ff : HPET 0
fed00000-fed003ff : PNP0103:00
fee00000-fee00fff : Local APIC
feffc000-feffffff : reserved
fffc0000-ffffffff : reserved

Quoted 1 line

"PCI Bus 0000:10" is bogus and "PCI Bus 0000:00" isn't there at all.

Yes, you shouldn't use pxb if you are not using the corresponding SeaBIOS. However, as I understand we always attach a SeaBIOS binary with a QEMU release,
so we should be OK with this.

And this is the reason I wanted bios support *before* the PXB device implementation,
but anyway, even if we have them in the same time, as long as the release has both pxb and BIOS with pxb support, is OK. (I think...)

I appreciate you looking into this and if you need further assistance don't hesitate to mail me! :)

Thanks,
Marcel

Quoted 5 lines

cheers,
Gerd

#65 lore raw
In reply to Marcel Apfelbaum

Hi,

Quoted 30 lines
Quoted 30 lines

Second thing: Booting with an unpatched seabios has bad effects:

[root@localhost ~]# cat /proc/iomem
00000000-000fffff : PCI Bus 0000:10
00000000-00000fff : reserved
00001000-0009fbff : System RAM
0009fc00-0009ffff : reserved
000c0000-000c91ff : Video ROM
000c9800-000ca1ff : Adapter ROM
000ca800-000ccbff : Adapter ROM
000f0000-000fffff : reserved

     000f0000-000fffff : System ROM

00100000-3ffdffff : System RAM
01000000-0174bde4 : Kernel code
0174bde5-01d30cff : Kernel data
01eaa000-0202afff : Kernel bss
3ffe0000-3fffffff : reserved
fd000000-fdffffff : 0000:00:02.0
fd000000-fdffffff : bochs-drm
febc0000-febdffff : 0000:00:03.0
febc0000-febdffff : e1000
febf0000-febf0fff : 0000:00:02.0
febf0000-febf0fff : bochs-drm
fec00000-fec003ff : IOAPIC 0
fed00000-fed003ff : HPET 0
fed00000-fed003ff : PNP0103:00
fee00000-fee00fff : Local APIC
feffc000-feffffff : reserved
fffc0000-ffffffff : reserved

Quoted 4 lines
Quoted 1 line

"PCI Bus 0000:10" is bogus and "PCI Bus 0000:00" isn't there at all.

Yes, you shouldn't use pxb if you are not using the corresponding SeaBIOS. However, as I understand we always attach a SeaBIOS binary with a QEMU release, so we should be OK with this.

IMO the qemu side should be more robust and not assume specific guest behavior. The guest firmware simply not configuring the pxb shouldn't cause the resources for bus 0 breaking that badly. pxb not working if you run firmware without pxb support is ok. But everything else should continue to work as it did before.

cheers,
Gerd