From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51945) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuZhg-0001cJ-5T for qemu-devel@nongnu.org; Tue, 19 May 2015 01:04:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YuZhb-0001Ql-8C for qemu-devel@nongnu.org; Tue, 19 May 2015 01:04:32 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:36291) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuZhb-0001QY-33 for qemu-devel@nongnu.org; Tue, 19 May 2015 01:04:27 -0400 Received: by pabts4 with SMTP id ts4so7210009pab.3 for ; Mon, 18 May 2015 22:04:25 -0700 (PDT) Message-ID: <555AC451.1070704@ozlabs.ru> Date: Tue, 19 May 2015 15:04:17 +1000 From: Alexey Kardashevskiy MIME-Version: 1.0 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> In-Reply-To: <87vbfpf9vl.fsf@abhimanyu.in.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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: Nikunj A Dadhania , qemu-devel@nongnu.org, david@gibson.dropbear.id.au Cc: nikunj.dadhania@gmail.com, qemu-ppc@nongnu.org, agraf@suse.de, mdroth@linux.vnet.ibm.com 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 include >>> the “ibm,loc-code” property with a value that represents the location >>> code for that hardware entity. >>> >>> Populate ibm,loc-code. >>> >>> 1) PCI passthru devices need to identify with its own ibm,loc-code >>> 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, char **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 difference between these two having 6 words names ;) Do not insist though. > >> >> >>> +{ >>> + char *host; >>> + char path[PATH_MAX]; >>> + >>> + host = 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 = 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); >>> + >>> + g_file_get_contents(path, &buf, NULL, NULL); >>> + return buf; >>> +} >>> + -- Alexey