diff mbox

kvm tools: powerpc: convert spapr pci to new device iterators

Message ID 1354021228-19077-1-git-send-email-will.deacon@arm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Will Deacon Nov. 27, 2012, 1 p.m. UTC
Commit 8d35d32d0148 ("kvm tools: add generic device registration
mechanism") introduced a tree-based device lookup-by-bus mechanism as
well as iterators to enumerate the devices on a particular bus.

Whilst both x86 and ppc were converted by the original patch, the spapr
pci changes were incomplete, so include the required changes here.

Compile-tested only on ppc64 970mp. Note that I had to hack the Makefile
in order to build guest_init.o with a toolchain defaulting to ppc:

 $(GUEST_INIT): guest/init.c
        $(E) "  LINK    " $@
-       $(Q) $(CC) -static guest/init.c -o $@
-       $(Q) $(LD) -r -b binary -o guest/guest_init.o $(GUEST_INIT)
+       $(Q) $(CC) -m64 -static guest/init.c -o $@
+       $(Q) $(LD) -m elf64ppc -r -b binary -o guest/guest_init.o $(GUEST_INIT)

 $(DEPS):

Cc: Matt Evans <matt@ozlabs.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
---
 tools/kvm/powerpc/spapr_pci.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Matt Evans Nov. 28, 2012, 5:57 p.m. UTC | #1
Hi Will,

On 2012-11-27 13:00, Will Deacon wrote:
> Commit 8d35d32d0148 ("kvm tools: add generic device registration
> mechanism") introduced a tree-based device lookup-by-bus mechanism as
> well as iterators to enumerate the devices on a particular bus.
>
> Whilst both x86 and ppc were converted by the original patch, the 
> spapr
> pci changes were incomplete, so include the required changes here.
>
> Compile-tested only on ppc64 970mp. Note that I had to hack the 
> Makefile
> in order to build guest_init.o with a toolchain defaulting to ppc:
>
>  $(GUEST_INIT): guest/init.c
>         $(E) "  LINK    " $@
> -       $(Q) $(CC) -static guest/init.c -o $@
> -       $(Q) $(LD) -r -b binary -o guest/guest_init.o $(GUEST_INIT)
> +       $(Q) $(CC) -m64 -static guest/init.c -o $@
> +       $(Q) $(LD) -m elf64ppc -r -b binary -o guest/guest_init.o
> $(GUEST_INIT)
>
>  $(DEPS):
>
> Cc: Matt Evans <matt@ozlabs.org>
> Signed-off-by: Will Deacon <will.deacon@arm.com>

I lack PPC
But this patch appears too good
To be left aside

Acked-by: Matt Evans <matt@ozlabs.org>


Cheers,

Matt

> ---
>  tools/kvm/powerpc/spapr_pci.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/tools/kvm/powerpc/spapr_pci.c 
> b/tools/kvm/powerpc/spapr_pci.c
> index 5f4016c..ed4b9ab 100644
> --- a/tools/kvm/powerpc/spapr_pci.c
> +++ b/tools/kvm/powerpc/spapr_pci.c
> @@ -15,6 +15,7 @@
>
>  #include "spapr.h"
>  #include "spapr_pci.h"
> +#include "kvm/devices.h"
>  #include "kvm/fdt.h"
>  #include "kvm/util.h"
>  #include "kvm/pci.h"
> @@ -248,6 +249,7 @@ int spapr_populate_pci_devices(struct kvm *kvm,
>  			       void *fdt)
>  {
>  	int bus_off, node_off = 0, devid, fn, i, n, devices;
> +	struct device_header *dev_hdr;
>  	char nodename[256];
>  	struct {
>  		uint32_t hi;
> @@ -301,14 +303,15 @@ int spapr_populate_pci_devices(struct kvm *kvm,
>
>  	/* Populate PCI devices and allocate IRQs */
>  	devices = 0;
> -
> -	for (devid = 0; devid < KVM_MAX_DEVICES; devid++) {
> +	dev_hdr = device__first_dev(DEVICE_BUS_PCI);
> +	while (dev_hdr) {
>  		uint32_t *irqmap = interrupt_map[devices];
> -		struct pci_device_header *hdr = pci__find_dev(devid);
> +		struct pci_device_header *hdr = dev_hdr->data;
>
>  		if (!hdr)
>  			continue;
>
> +		devid = dev_hdr->dev_num;
>  		fn = 0; /* kvmtool doesn't yet do multifunction devices */
>
>  		sprintf(nodename, "pci@%u,%u", devid, fn);
> @@ -413,6 +416,7 @@ int spapr_populate_pci_devices(struct kvm *kvm,
>  		/* We don't set ibm,dma-window property as we don't have an IOMMU. 
> */
>
>  		++devices;
> +		dev_hdr = device__next_dev(dev_hdr);
>  	}
>
>  	/* Write interrupt map */

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Pekka Enberg Nov. 30, 2012, 8:35 a.m. UTC | #2
On Wed, 28 Nov 2012, Matt Evans wrote:
> On 2012-11-27 13:00, Will Deacon wrote:
> > Commit 8d35d32d0148 ("kvm tools: add generic device registration
> > mechanism") introduced a tree-based device lookup-by-bus mechanism as
> > well as iterators to enumerate the devices on a particular bus.
> > 
> > Whilst both x86 and ppc were converted by the original patch, the spapr
> > pci changes were incomplete, so include the required changes here.
> > 
> > Compile-tested only on ppc64 970mp. Note that I had to hack the Makefile
> > in order to build guest_init.o with a toolchain defaulting to ppc:
> > 
> >  $(GUEST_INIT): guest/init.c
> >         $(E) "  LINK    " $@
> > -       $(Q) $(CC) -static guest/init.c -o $@
> > -       $(Q) $(LD) -r -b binary -o guest/guest_init.o $(GUEST_INIT)
> > +       $(Q) $(CC) -m64 -static guest/init.c -o $@
> > +       $(Q) $(LD) -m elf64ppc -r -b binary -o guest/guest_init.o
> > $(GUEST_INIT)
> > 
> >  $(DEPS):
> > 
> > Cc: Matt Evans <matt@ozlabs.org>
> > Signed-off-by: Will Deacon <will.deacon@arm.com>
> 
> I lack PPC
> But this patch appears too good
> To be left aside
> 
> Acked-by: Matt Evans <matt@ozlabs.org>

Applied, thanks!
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/tools/kvm/powerpc/spapr_pci.c b/tools/kvm/powerpc/spapr_pci.c
index 5f4016c..ed4b9ab 100644
--- a/tools/kvm/powerpc/spapr_pci.c
+++ b/tools/kvm/powerpc/spapr_pci.c
@@ -15,6 +15,7 @@ 
 
 #include "spapr.h"
 #include "spapr_pci.h"
+#include "kvm/devices.h"
 #include "kvm/fdt.h"
 #include "kvm/util.h"
 #include "kvm/pci.h"
@@ -248,6 +249,7 @@  int spapr_populate_pci_devices(struct kvm *kvm,
 			       void *fdt)
 {
 	int bus_off, node_off = 0, devid, fn, i, n, devices;
+	struct device_header *dev_hdr;
 	char nodename[256];
 	struct {
 		uint32_t hi;
@@ -301,14 +303,15 @@  int spapr_populate_pci_devices(struct kvm *kvm,
 
 	/* Populate PCI devices and allocate IRQs */
 	devices = 0;
-
-	for (devid = 0; devid < KVM_MAX_DEVICES; devid++) {
+	dev_hdr = device__first_dev(DEVICE_BUS_PCI);
+	while (dev_hdr) {
 		uint32_t *irqmap = interrupt_map[devices];
-		struct pci_device_header *hdr = pci__find_dev(devid);
+		struct pci_device_header *hdr = dev_hdr->data;
 
 		if (!hdr)
 			continue;
 
+		devid = dev_hdr->dev_num;
 		fn = 0; /* kvmtool doesn't yet do multifunction devices */
 
 		sprintf(nodename, "pci@%u,%u", devid, fn);
@@ -413,6 +416,7 @@  int spapr_populate_pci_devices(struct kvm *kvm,
 		/* We don't set ibm,dma-window property as we don't have an IOMMU. */
 
 		++devices;
+		dev_hdr = device__next_dev(dev_hdr);
 	}
 
 	/* Write interrupt map */