From: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: agraf@suse.de, Thomas Huth <thuth@redhat.com>,
aik@ozlabs.ru, mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org,
qemu-ppc@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v3 6/6] spapr_pci: populate ibm,loc-code
Date: Thu, 07 May 2015 10:26:57 +0530 [thread overview]
Message-ID: <87twvphtnq.fsf@linux.vnet.ibm.com> (raw)
In-Reply-To: <20150507003256.GA20149@voom.redhat.com>
David Gibson <david@gibson.dropbear.id.au> writes:
> On Wed, May 06, 2015 at 11:44:59AM +0530, Nikunj A Dadhania wrote:
>> Thomas Huth <thuth@redhat.com> writes:
>>
>> > On Tue, 5 May 2015 14:23:56 +0530
>> > Nikunj A Dadhania <nikunj@linux.vnet.ibm.com> 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.
>> >> 2) Emulated devices encode as following:
>> >> qemu_<name>:<phb-index>:<slot>.<fn>
>> >>
>> >> Signed-off-by: Nikunj A Dadhania <nikunj@linux.vnet.ibm.com>
>> >> ---
>> >> hw/ppc/spapr_pci.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++-------
>> >> 1 file changed, 75 insertions(+), 11 deletions(-)
>> >>
>> >> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
>> >> index cbd5661..eacf0bd 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;
>> >> }
>> >>
>> >> +static bool spapr_phb_vfio_get_devspec_value(PCIDevice *pdev, char **value)
>> >> +{
>> >> + 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);
>> >> +
>> >> + if (g_file_get_contents(path, &buf, NULL, NULL)) {
>> >> + return buf;
>> >> + } else {
>> >> + return NULL;
>> >> + }
>> >
>> > Minor idea for an optimization: g_file_get_contents() should set buf to
>> > NULL in case of errors anyway, so you could omit the "if" and
>> > "return NULLL" and simply always "return buf" here.
>>
>> Sure
>>
>> >
>> >> +}
>> >> +
>> >> +static char *spapr_phb_get_loc_code(sPAPRPHBState *sphb, PCIDevice *pdev)
>> >> +{
>> >> + char *path = g_malloc(PATH_MAX);
>> >> +
>> >> + if (!path) {
>> >> + return NULL;
>> >> + }
>> >> +
>> >> + /*
>> >> + * For non-vfio devices and failures make up the location code out
>> >
>> > This comment ("and failures") ...
>>
>> Oh right, one option is to drop that...
>>
>> >
>> >> + * of the name, slot and function.
>> >> + *
>> >> + * qemu_<name>:<phb-index>:<slot>.<fn>
>> >> + */
>> >> + 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") != NULL) {
>> >> + return spapr_phb_vfio_get_loc_code(sphb, pdev);
>> >> + } else {
>> >> + return spapr_phb_get_loc_code(sphb, pdev);
>> >> + }
>> >
>> > ... does not match quite the behavior here, as far as I can see. I
>> > guess you also wanted to fall back to spapr_phb_get_loc_code() in case
>> > spapr_phb_vfio_get_loc_code() did not work as expected (eg. when the
>> > access to the /sys or /proc filesystem failed)?
>>
>> ... In current case, if getting vfio device loc_code fails, we would not
>> add any ibm,loc_code info. I thought that would be the proper
>> behaviour. As "qemu_" would indicate it as an emulated device, which is
>> not true. Or encode it as follows:
>>
>> "vfio_<name>:<phb-index>:<slot>.<fn>"
>>
>> So more checks would be needed here in that case:
>>
>> if (vfio) {
>> buf = vfio_get_loc_code()
>> if (!buf)
>> buf = cook_vfio_get_loc_code()
>> return buf;
>> } else { ... }
>
> If you can't determine the loc code, I think just leaving it out is
> probably the best option for now. We can add fancier fallbacks in
> future if they seem like they make sense.
I already have the fancy version now, will send it for review.
Regards
Nikunj
next prev parent reply other threads:[~2015-05-07 4:57 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-05 8:53 [Qemu-devel] [PATCH v3 0/6] spapr_pci: DT field fixes and PCI DT node creation in QEMU Nikunj A Dadhania
2015-05-05 8:53 ` [Qemu-devel] [PATCH v3 1/6] spapr_pci: remove duplicate macros Nikunj A Dadhania
2015-05-05 13:53 ` Thomas Huth
2015-05-06 5:41 ` Nikunj A Dadhania
2015-05-07 0:55 ` David Gibson
2015-05-07 4:55 ` Nikunj A Dadhania
2015-05-05 8:53 ` [Qemu-devel] [PATCH v3 2/6] spapr_pci: encode missing 64-bit memory address space Nikunj A Dadhania
2015-05-05 14:28 ` Thomas Huth
2015-05-06 5:44 ` Nikunj A Dadhania
2015-05-06 7:01 ` Thomas Huth
2015-05-06 8:23 ` Nikunj A Dadhania
2015-05-05 8:53 ` [Qemu-devel] [PATCH v3 3/6] spapr_pci: encode class code including Prog IF register Nikunj A Dadhania
2015-05-05 12:55 ` David Gibson
2015-05-05 14:50 ` Thomas Huth
2015-05-05 8:53 ` [Qemu-devel] [PATCH v3 4/6] spapr_pci: enumerate and add PCI device tree Nikunj A Dadhania
2015-05-05 15:32 ` Thomas Huth
2015-05-06 5:56 ` Nikunj A Dadhania
2015-05-05 8:53 ` [Qemu-devel] [PATCH v3 5/6] spapr_pci: fix boot-time device tree fields for pci hotplug Nikunj A Dadhania
2015-05-05 13:09 ` David Gibson
2015-05-06 5:57 ` Nikunj A Dadhania
2015-05-05 8:53 ` [Qemu-devel] [PATCH v3 6/6] spapr_pci: populate ibm,loc-code Nikunj A Dadhania
2015-05-05 16:03 ` Thomas Huth
2015-05-06 6:14 ` Nikunj A Dadhania
2015-05-07 0:32 ` David Gibson
2015-05-07 4:56 ` Nikunj A Dadhania [this message]
-- strict thread matches above, loose matches on Subject: below --
2015-05-05 8:43 [Qemu-devel] [PATCH v3 0/6] spapr_pci: DT field fixes and PCI DT node creation in QEMU Nikunj A Dadhania
2015-05-05 8:43 ` [Qemu-devel] [PATCH v3 6/6] spapr_pci: populate ibm,loc-code Nikunj A Dadhania
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87twvphtnq.fsf@linux.vnet.ibm.com \
--to=nikunj@linux.vnet.ibm.com \
--cc=agraf@suse.de \
--cc=aik@ozlabs.ru \
--cc=david@gibson.dropbear.id.au \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.