From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58844) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yn2ZQ-0005KH-OW for qemu-devel@nongnu.org; Tue, 28 Apr 2015 06:16:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yn2ZN-0002cQ-Az for qemu-devel@nongnu.org; Tue, 28 Apr 2015 06:16:52 -0400 Date: Tue, 28 Apr 2015 17:48:21 +1000 From: David Gibson Message-ID: <20150428074821.GF24753@voom.redhat.com> References: <1429698934-28915-1-git-send-email-nikunj@linux.vnet.ibm.com> <1429698934-28915-3-git-send-email-nikunj@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="kR3zbvD4cgoYnS/6" Content-Disposition: inline In-Reply-To: <1429698934-28915-3-git-send-email-nikunj@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [RFC PATCH 2/2] spapr: populate ibm,loc-code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Nikunj A Dadhania Cc: aik@ozlabs.ru, qemu-ppc@nongnu.org, qemu-devel@nongnu.org, agraf@suse.de --kR3zbvD4cgoYnS/6 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Apr 22, 2015 at 04:05:34PM +0530, Nikunj A Dadhania wrote: > Each hardware instance has a platform unique location code. The OF > device tree that describes a part of a hardware entity must include > the =E2=80=9Cibm,loc-code=E2=80=9D property with a value that represents = the location > code for that hardware entity. >=20 > Populate ibm,loc-code. > 1) PCI passthru devices need to identify with its own ibm,loc-code > available on the host. > 2) Emulated devices encode as following: > qemu_::. >=20 > Signed-off-by: Nikunj A Dadhania This is going to conflict with Alexey's patches which merge the plan and vfio PAPR PHB types, so we'll need to work out which will go in first. > --- > hw/ppc/spapr_pci.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++-= ------ > 1 file changed, 75 insertions(+), 10 deletions(-) >=20 > diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c > index abf71f7..c69e732 100644 > --- a/hw/ppc/spapr_pci.c > +++ b/hw/ppc/spapr_pci.c > @@ -744,6 +744,70 @@ static AddressSpace *spapr_pci_dma_iommu(PCIBus *bus= , void *opaque, int devfn) > return &phb->iommu_as; > } > =20 > +static bool spapr_phb_vfio_get_devspec_value(PCIDevice *pdev, char **val= ue) > +{ > + char *host; > + char path[PATH_MAX]; > + > + host =3D object_property_get_str(OBJECT(pdev), "host", NULL); > + if (!host) { > + return false; > + } > + > + snprintf(path, sizeof(path), "/sys/bus/pci/devices/%s/devspec", host= ); > + g_free(host); > + > + return g_file_get_contents(path, value, NULL, NULL); > +} > + > +static char *spapr_phb_vfio_get_loc_code(sPAPRPHBState *sphb, PCIDevice= *pdev) > +{ > + char path[PATH_MAX], *buf =3D NULL; > + > + /* We have a vfio host bridge lets get the path. */ > + if (!spapr_phb_vfio_get_devspec_value(pdev, &buf)) { > + return NULL; > + } > + > + snprintf(path, sizeof(path), "/proc/device-tree%s/ibm,loc-code", buf= ); > + g_free(buf); > + > + if (g_file_get_contents(path, &buf, NULL, NULL)) { > + return buf; > + } else { > + return NULL; > + } > +} > + > +static char *spapr_phb_get_loc_code(sPAPRPHBState *sphb, PCIDevice *pde= v) > +{ > + char *path =3D g_malloc(PATH_MAX); > + > + if (!path) { > + return NULL; > + } > + > + /* > + * For non-vfio devices and failures make up the location code out > + * of the name, slot and function. > + * > + * qemu_::. > + */ > + snprintf(path, PATH_MAX, "qemu_%s:%02d:%02d.%1d", pdev->name, > + sphb->index, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); > + return path; > +} > + > + > +static char *spapr_ibm_get_loc_code(sPAPRPHBState *sphb, PCIDevice *pdev) > +{ > + if (object_dynamic_cast(OBJECT(pdev), "vfio-pci") !=3D NULL) { > + return spapr_phb_vfio_get_loc_code(sphb, pdev); > + } else { > + return spapr_phb_get_loc_code(sphb, pdev); > + } > +} > + > /* Macros to operate with address in OF binding to PCI */ > #define b_x(x, p, l) (((x) & ((1<<(l))-1)) << (p)) > #define b_n(x) b_x((x), 31, 1) /* 0 if relocatable */ > @@ -873,12 +937,12 @@ static void populate_resource_props(PCIDevice *d, R= esourceProps *rp) > } > =20 > static int spapr_populate_pci_child_dt(PCIDevice *dev, void *fdt, int of= fset, > - int phb_index, int drc_index, > - const char *drc_name) > + sPAPRPHBState *phb, int drc_index) > { > ResourceProps rp; > bool is_bridge =3D false; > int pci_status; > + char *buf =3D NULL; > =20 > if (pci_default_read_config(dev, PCI_HEADER_TYPE, 1) =3D=3D > PCI_HEADER_TYPE_BRIDGE) { > @@ -940,8 +1004,10 @@ static int spapr_populate_pci_child_dt(PCIDevice *d= ev, void *fdt, int offset, > * processed by OF beforehand > */ > _FDT(fdt_setprop_string(fdt, offset, "name", "pci")); > - if (drc_name) { > - _FDT(fdt_setprop(fdt, offset, "ibm,loc-code", drc_name, strlen(d= rc_name))); > + buf =3D spapr_ibm_get_loc_code(phb, dev); > + if (buf) { > + _FDT(fdt_setprop_string(fdt, offset, "ibm,loc-code", buf)); > + g_free(buf); > } > _FDT(fdt_setprop_cell(fdt, offset, "ibm,my-drc-index", drc_index)); > =20 > @@ -978,8 +1044,7 @@ static void *spapr_create_pci_child_dt(sPAPRPHBState= *phb, PCIDevice *dev, > sprintf(nodename, "pci@%d", slot); > } > offset =3D fdt_add_subnode(fdt, 0, nodename); > - ret =3D spapr_populate_pci_child_dt(dev, fdt, offset, phb->index, dr= c_index, > - drc_name); > + ret =3D spapr_populate_pci_child_dt(dev, fdt, offset, phb, drc_index= ); > g_assert(!ret); > =20 > *dt_offset =3D offset; > @@ -1476,7 +1541,7 @@ PCIHostState *spapr_create_phb(sPAPREnvironment *sp= apr, int index) > typedef struct sPAPRFDT { > void *fdt; > int node_off; > - uint32_t index; > + sPAPRPHBState *sphb; > } sPAPRFDT; > =20 > static int spapr_phb_children_dt(Object *child, void *opaque) > @@ -1511,7 +1576,7 @@ static void spapr_populate_pci_devices_dt(PCIBus *b= us, PCIDevice *pdev, void *op > sprintf(nodename, "pci@%d", slot); > } > offset =3D fdt_add_subnode(p->fdt, p->node_off, nodename); > - ret =3D spapr_populate_pci_child_dt(pdev, p->fdt, offset, p->index, = 0, NULL); > + ret =3D spapr_populate_pci_child_dt(pdev, p->fdt, offset, p->sphb, 0= ); > g_assert(!ret); > =20 > if ((pci_default_read_config(pdev, PCI_HEADER_TYPE, 1) =3D=3D > @@ -1520,7 +1585,7 @@ static void spapr_populate_pci_devices_dt(PCIBus *b= us, PCIDevice *pdev, void *op > if(sec_bus) { > pci_for_each_device(sec_bus, pci_bus_num(sec_bus), > spapr_populate_pci_devices_dt, > - &((sPAPRFDT){ .fdt =3D p->fdt, .node_off= =3D offset , .index =3D p->index })); > + &((sPAPRFDT){ .fdt =3D p->fdt, .node_off= =3D offset , .sphb =3D p->sphb })); > } > } > return; > @@ -1654,7 +1719,7 @@ int spapr_populate_pci_dt(sPAPRPHBState *phb, > _FDT(fdt_setprop_cell(fdt, bus_off, "qemu,phb-enumerated", 0x1)); > pci_for_each_device(bus, pci_bus_num(bus), > spapr_populate_pci_devices_dt, > - &((sPAPRFDT){ .fdt =3D fdt, .node_off =3D bus_of= f, .index =3D phb->index })); > + &((sPAPRFDT){ .fdt =3D fdt, .node_off =3D bus_of= f, .sphb =3D phb })); > =20 > ret =3D spapr_drc_populate_dt(fdt, bus_off, OBJECT(phb), > SPAPR_DR_CONNECTOR_TYPE_PCI); --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --kR3zbvD4cgoYnS/6 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJVPztFAAoJEGw4ysog2bOS12YP/Rb2Ia7fah+uZAochj+6UEqY EvYWZkYC/NRu8wSNKicsPx4ckTN9igDH9wZckWQVtlxUDGAVaISYkqnCaV/zMF8V EKQxGUUdVwAdLEXiM8f614mSumQVBVBAnFDaAlF12N3rmcEd3ixya5mh1oGl+SdH 5Usvk2IjUAnEbF6fQxdTIVzPEc8GCOIEA4iuZtFnKmub9+SRR+otXAYWQ7UeBy6r yvumN1V8lGLgRbI6Nl2qnzreK8DZn1+391QVXIq6jXHMUpVThGbcvN5GAiGbDaLu oZiiTUC5cnfbZdIdn53hk02Z6VMg8VgxJywhqz+pNgPvhESEtLfYoLSfIqisqNbf CC4aoE/wAUnCc03Wc4ywcNjrxBntpIwnJ3Qz9rcKHJW2gMOegB5VFh+4hO2g9xvB FaPMyRlCPfoAsnvCBmmx32tikP57nkOLD0CY58ke6CRKUtHJnvP/cgmoiat1ehTr dg39klSHUDmOZIG033nbOrZZNI3/gMEcUQsnJJOjoPSpXTjyRCDuD8kOxHZoY5qS RqDS/2Cw8PZd4A2x/UWH0ypslbJYD5RDXXnU7LJjHZMFtz+61XLgX15MmrFPIh+t 8rOXynOE4YuTFmLJIKGsQLUKZc/4Ss8+R4Nzy5k10IysklwfWt4wONEoMp5f/JJ+ mSbbOKYFzgPQVcVlZ+TW =4Ee2 -----END PGP SIGNATURE----- --kR3zbvD4cgoYnS/6--