From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40136) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuuRd-0000KI-Os for qemu-devel@nongnu.org; Tue, 19 May 2015 23:13:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YuuRa-0004Fl-Ao for qemu-devel@nongnu.org; Tue, 19 May 2015 23:13:21 -0400 Received: from e28smtp08.in.ibm.com ([122.248.162.8]:44913) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuuRZ-0004Ec-I0 for qemu-devel@nongnu.org; Tue, 19 May 2015 23:13:18 -0400 Received: from /spool/local by e28smtp08.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 20 May 2015 08:43:13 +0530 From: Nikunj A Dadhania In-Reply-To: <555B19C8.1040401@suse.de> References: <1430983314-5009-1-git-send-email-nikunj@linux.vnet.ibm.com> <1430983314-5009-5-git-send-email-nikunj@linux.vnet.ibm.com> <554C68DC.4020604@ozlabs.ru> <87vbfpf9vl.fsf@abhimanyu.in.ibm.com> <555AC451.1070704@ozlabs.ru> <87pp5xf42c.fsf@abhimanyu.in.ibm.com> <555AE946.5080802@ozlabs.ru> <87h9r9f0hf.fsf@abhimanyu.in.ibm.com> <555B052A.1030303@ozlabs.ru> <87d21wga8d.fsf@abhimanyu.in.ibm.com> <555B19C8.1040401@suse.de> Date: Wed, 20 May 2015 08:43:07 +0530 Message-ID: <87h9r8szzw.fsf@abhimanyu.in.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v4 4/4] spapr_pci: populate ibm,loc-code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Graf , Alexey Kardashevskiy , qemu-devel@nongnu.org, david@gibson.dropbear.id.au Cc: nikunj.dadhania@gmail.com, qemu-ppc@nongnu.org, mdroth@linux.vnet.ibm.com Alexander Graf writes: > On 05/19/2015 11:58 AM, Nikunj A Dadhania wrote: >> Alexey Kardashevskiy writes: >> >>> On 05/19/2015 06:14 PM, Nikunj A Dadhania wrote: >>>> Alexey Kardashevskiy writes: >>>> >>>>> On 05/19/2015 04:56 PM, Nikunj A Dadhania wrote: >>>>>> Alexey Kardashevskiy writes: >>>>>> >>>>>>> On 05/19/2015 02:51 PM, Nikunj A Dadhania wrote: >>>>>>>> Alexey Kardashevskiy writes: >>>>>>>> >>>>>>>>> On 05/07/2015 05:21 PM, 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 incl= ude >>>>>>>>>> the =E2=80=9Cibm,loc-code=E2=80=9D property with a value that re= presents the location >>>>>>>>>> code for that hardware entity. >>>>>>>>>> >>>>>>>>>> Populate ibm,loc-code. >>>>>>>>>> >>>>>>>>>> 1) PCI passthru devices need to identify with its own ibm,loc-co= de >>>>>>>>>> available on the host. In failure cases use: >>>>>>>>>> vfio_::. >>>>>>>>>> >>>>>>>>>> 2) Emulated devices encode as following: >>>>>>>>>> qemu_::. >>>>>>>>>> >>>>>>>>>> Signed-off-by: Nikunj A Dadhania >>>>>>>>>> --- >>>>>>>>>> hw/ppc/spapr_pci.c | 98 ++++++++++++++++++++++++++++++++++= +++++++++++++------- >>>>>>>>>> 1 file changed, 86 insertions(+), 12 deletions(-) >>>>>>>>>> >>>>>>>>>> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c >>>>>>>>>> index 12f1b9c..d901007 100644 >>>>>>>>>> --- a/hw/ppc/spapr_pci.c >>>>>>>>>> +++ b/hw/ppc/spapr_pci.c >>>>>>>>>> @@ -769,6 +769,81 @@ static uint32_t spapr_phb_get_pci_drc_index= (sPAPRPHBState *phb, >>>>>>>>>> return drck->get_index(drc); >>>>>>>>>> } >>>>>>>>>> >>>>>>>>>> +static bool spapr_phb_vfio_get_devspec_value(PCIDevice *pdev, c= har **value) >>>>>>>>> Does it have to be a separate function? >>>>>>>> For better readability, i would prefer it this way. >>>>>>> This is why I asked - I was having problems understanding the diffe= rence >>>>>>> between these two having 6 words names ;) Do not insist though. >>>>>>> >>>>>> This is what I have now, simplified: >>>>>> >>>>>> +static char *spapr_phb_vfio_get_loc_code(sPAPRPHBState *sphb, PCID= evice *pdev) >>>>>> +{ >>>>>> + char *path =3D NULL, *buf =3D NULL; >>>>>> + char *host =3D NULL; >>>>>> + >>>>>> + /* Get the PCI VFIO host id */ >>>>>> + host =3D object_property_get_str(OBJECT(pdev), "host", NULL); >>>>>> + if (!host) { >>>>>> + goto err_out; >>>>>> + } >>>>>> + >>>>>> + /* Construct the path of the file that will give us the DT loca= tion */ >>>>>> + path =3D g_strdup_printf("/sys/bus/pci/devices/%s/devspec", hos= t); >>>>>> + g_free(host); >>>>>> + if (path && !g_file_get_contents(path, &buf, NULL, NULL)) { >>>>>> + goto err_out; >>>>>> + } >>>>>> + g_free(path); >>>>>> + >>>>>> + /* Construct and read from host device tree the loc-code */ >>>>>> + path =3D g_strdup_printf("/proc/device-tree%s/ibm,loc-code", bu= f); >>>>>> + g_free(buf); >>>>>> + if (path && !g_file_get_contents(path, &buf, NULL, NULL)) { >>>>>> + goto err_out; >>>>>> + } >>>>>> + return buf; >>>>>> + >>>>>> +err_out: >>>>>> + g_free(path); >>>>>> + return NULL; >>>>>> +} >>>>>> + >>>>>> +static char *spapr_phb_get_loc_code(sPAPRPHBState *sphb, PCIDevice = *pdev) >>>>>> +{ >>>>>> + if (object_dynamic_cast(OBJECT(pdev), "vfio-pci")) { >>>>>> + char *buf =3D spapr_phb_vfio_get_loc_code(sphb, pdev); >>>>>> + >>>>>> + /* >>>>>> + * In case of failures reading the loc-code, make it up >>>>>> + * indicating a vfio device >>>>>> + */ >>>>>> + if (!buf) { >>>>>> + buf =3D g_strdup_printf("vfio_%s:%02d:%02d.%1d", pdev->= name, >>>>>> + sphb->index, PCI_SLOT(pdev->devfn= ), >>>>>> + PCI_FUNC(pdev->devfn)); >>>>>> + } >>>>>> + return buf; >>>>>> + } else { >>>>>> + return g_strdup_printf("qemu_%s:%02d:%02d.%1d", pdev->name, >>>>>> + sphb->index, PCI_SLOT(pdev->devfn), >>>>>> + PCI_FUNC(pdev->devfn)); >>>>>> + } >>>>>> +} >>>>> >>>>> I'd do this but I do not insist :) >>>> That is fine as well. >>>> >>>>> static char *spapr_phb_get_loc_code(sPAPRPHBState *sphb, PCIDevice *p= dev) >>>>> { >>>>> char *buf; >>>>> char *devtype =3D "qemu"; >>>>> >>>>> if (object_dynamic_cast(OBJECT(pdev), "vfio-pci")) { >>>>> buf =3D spapr_phb_vfio_get_loc_code(sphb, pdev); >>>>> if (buf) { >>>>> return buf; >>>>> } >>>>> devtype =3D "vfio"; >>>> That has to be a snprintf. >>> No it does not. g_strdup_printf() below is enough >> CC ppc64-softmmu/hw/ppc/spapr_pci.o >> hw/ppc/spapr_pci.c: In function =E2=80=98spapr_phb_get_loc_code=E2=80=99: >> hw/ppc/spapr_pci.c:807:21: error: initialization discards =E2=80=98const= =E2=80=99 qualifier from pointer target type [-Werror] >> char *devtype =3D "qemu"; >> ^ >> hw/ppc/spapr_pci.c:814:17: error: assignment discards =E2=80=98const=E2= =80=99 qualifier from pointer target type [-Werror] >> devtype =3D "vfio"; >> ^ >> cc1: all warnings being treated as errors >> make[1]: *** [hw/ppc/spapr_pci.o] Error 1 >> make: *** [subdir-ppc64-softmmu] Error 2 > > Make it const char *devtype? Cool, that works. Regards, Nikunj