From: Alexander Gordeev <agordeev@redhat.com>
To: Thomas Huth <thuth@redhat.com>
Cc: kvm@vger.kernel.org, Andrew Jones <drjones@redhat.com>
Subject: Re: [PATCH RFC 10/15] pci: Add pci_print() and pci_type_desc()
Date: Thu, 14 Apr 2016 10:34:21 +0200 [thread overview]
Message-ID: <20160414083420.GA26536@agordeev.lab.eng.brq.redhat.com> (raw)
In-Reply-To: <570F4A04.10002@redhat.com>
On Thu, Apr 14, 2016 at 09:43:00AM +0200, Thomas Huth wrote:
> On 11.04.2016 13:04, Alexander Gordeev wrote:
> > Cc: Thomas Huth <thuth@redhat.com>
> > Cc: Andrew Jones <drjones@redhat.com>
> > Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
> > ---
> > lib/asm-generic/pci.h | 6 +++++
> > lib/pci.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++
> > lib/pci.h | 3 +++
> > 3 files changed, 76 insertions(+)
> >
> > diff --git a/lib/asm-generic/pci.h b/lib/asm-generic/pci.h
> > index 15f23079f27e..3f2c6913f0d4 100644
> > --- a/lib/asm-generic/pci.h
> > +++ b/lib/asm-generic/pci.h
> > @@ -22,4 +22,10 @@ phys_addr_t pci_xlate_addr(pcidevaddr_t __unused dev, uint64_t addr)
> > }
> > #endif
> >
> > +#ifndef pci_print_arch
> > +static inline void pci_print_arch(void)
> > +{
> > +}
> > +#endif
> > +
> > #endif
> > diff --git a/lib/pci.c b/lib/pci.c
> > index 46aee60e0f90..a3c680670fe0 100644
> > --- a/lib/pci.c
> > +++ b/lib/pci.c
> > @@ -116,3 +116,70 @@ bool pci_bar_is64(pcidevaddr_t dev, int bar_num)
> > else
> > return false;
> > }
> > +
> > +void pci_type_desc(int type, char *desc, int len)
> > +{
> > + if ((type & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO) {
> > + strcpy(desc, "PIO"); /* strncpy() would be better */
>
> Maybe that's a good point in time now to introduce strncpy to
> kvm-unit-tests? (or maybe even a better variant like strlcpy?)
Andrew?
> > + } else {
> > + static char *str[] = { "32", "1M", "64" };
>
> Since you're depending on external values as array index below, I'd play
> safe here and add a fourth entry like "??" or "RES" or so.
As I got from previous Andrew's explanations we would rather crash
in case of incorrect access.
> > + int idx = (type & PCI_BASE_ADDRESS_MEM_TYPE_MASK) >> 1;
> > + int pfetch = type & PCI_BASE_ADDRESS_MEM_PREFETCH;
> > + snprintf(desc, len, "MEM%s%s", str[idx], pfetch ? "/p" : "");
> > + }
> > +}
> > +
> > +static void pci_dev_print(pcidevaddr_t dev)
> > +{
> > + uint16_t vendor_id = pci_config_readw(dev, PCI_VENDOR_ID);
> > + uint16_t device_id = pci_config_readw(dev, PCI_DEVICE_ID);
> > + uint8_t header = pci_config_readb(dev, PCI_HEADER_TYPE);
>
> I think you should mask away the uppermost bit of the header type byte -
> otherwise your code does not work with multi-function devices.
See below.
> > + uint8_t progif = pci_config_readb(dev, PCI_CLASS_PROG);
> > + uint8_t subclass = pci_config_readb(dev, PCI_CLASS_DEVICE);
> > + uint8_t class = pci_config_readb(dev, PCI_CLASS_DEVICE + 1);
> > + int bar;
> > +
> > + printf("dev %2d fn %d vendor_id %04x device_id %04x type %02x "
> > + "progif %02x class %02x subclass %02x\n",
> > + dev / 8, dev % 8, vendor_id, device_id, header,
> > + progif, class, subclass);
> > +
> > + if (header != PCI_HEADER_TYPE_NORMAL)
> > + return;
if ((header & 0x7f) != PCI_HEADER_TYPE_NORMAL) /* mask multi-function bit */
return;
I would rather masked it here.
?
> > +
> > + for (bar = 0; bar < 6; bar++) {
> > + phys_addr_t start, end;
> > + char desc[8];
> > +
> > + if (!pci_bar_is_valid(dev, bar))
> > + break;
> > +
> > + start = pci_bar_addr(dev, bar);
> > + end = start + pci_bar_size(dev, bar) - 1;
> > +
> > + pci_type_desc(bar, desc, sizeof(desc));
> > +
> > + if (pci_bar_is64(dev, bar)) {
> > + printf("\tBAR#%d,%d [%-7s %" PRIx64 "-%" PRIx64 "]\n",
> > + bar, bar + 1, desc, start, end);
> > + bar++;
> > + } else {
> > + printf("\tBAR#%d [%-7s %02x-%02x]\n",
> > + bar, desc, (uint32_t)start, (uint32_t)end);
> > + }
> > + }
> > +}
>
> Thomas
>
next prev parent reply other threads:[~2016-04-14 8:35 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-11 11:04 [PATCH RFC 00/15] PCI bus support Alexander Gordeev
2016-04-11 11:04 ` [PATCH RFC 01/15] Update ioremap() prototype to conform to the Linux one Alexander Gordeev
2016-04-11 11:34 ` Andrew Jones
2016-04-11 11:04 ` [PATCH RFC 02/15] x86: Add basic ioremap() implementation Alexander Gordeev
2016-04-11 11:45 ` Andrew Jones
2016-04-11 11:04 ` [PATCH RFC 03/15] x86/vmexit: Make use of ioremap() Alexander Gordeev
2016-04-11 11:46 ` Andrew Jones
2016-04-11 12:02 ` Alexander Gordeev
2016-04-11 11:04 ` [PATCH RFC 04/15] pci: Fix indentation in generic PCI files Alexander Gordeev
2016-04-11 11:50 ` Andrew Jones
2016-04-11 12:06 ` Alexander Gordeev
2016-04-11 12:21 ` Andrew Jones
2016-04-11 11:04 ` [PATCH RFC 05/15] pci/x86: Rename pci_config_read() to pci_config_readl() Alexander Gordeev
2016-04-11 11:51 ` Andrew Jones
2016-04-13 12:55 ` Thomas Huth
2016-04-14 13:13 ` Alexander Gordeev
2016-04-11 11:04 ` [PATCH RFC 06/15] pci/x86: Add remaining PCI configuration space accessors Alexander Gordeev
2016-04-14 7:29 ` Andrew Jones
2016-04-11 11:04 ` [PATCH RFC 07/15] pci: Add pci_probe() and pci_shutdown() Alexander Gordeev
2016-04-14 7:45 ` Thomas Huth
2016-04-14 13:23 ` Alexander Gordeev
2016-04-22 15:04 ` Andrew Jones
2016-04-11 11:04 ` [PATCH RFC 08/15] pci: Rework pci_bar_addr() Alexander Gordeev
2016-04-13 13:28 ` Thomas Huth
2016-04-13 17:46 ` Alexander Gordeev
2016-04-13 18:05 ` Andrew Jones
2016-04-22 15:20 ` Andrew Jones
2016-04-22 15:22 ` Andrew Jones
2016-04-11 11:04 ` [PATCH RFC 09/15] pci: Add pci_bar_set() Alexander Gordeev
2016-04-13 15:01 ` Thomas Huth
2016-04-13 16:38 ` Andrew Jones
2016-04-13 18:39 ` Alexander Gordeev
2016-04-14 7:30 ` Andrew Jones
2016-04-11 11:04 ` [PATCH RFC 10/15] pci: Add pci_print() and pci_type_desc() Alexander Gordeev
2016-04-14 7:43 ` Thomas Huth
2016-04-14 8:34 ` Alexander Gordeev [this message]
2016-04-14 8:41 ` Thomas Huth
2016-04-14 9:42 ` Andrew Jones
2016-04-22 15:35 ` Andrew Jones
2016-05-18 9:03 ` Alexander Gordeev
2016-05-23 15:10 ` Andrew Jones
2016-04-11 11:04 ` [PATCH RFC 11/15] pci/x86: Adopt PCI framework changes Alexander Gordeev
2016-04-22 15:37 ` Andrew Jones
2016-04-11 11:04 ` [PATCH RFC 12/15] Factor out generic architecture code Alexander Gordeev
2016-04-14 7:50 ` Thomas Huth
2016-04-14 8:16 ` Alexander Gordeev
2016-04-22 15:40 ` Andrew Jones
2016-04-22 16:14 ` Alexander Gordeev
2016-04-22 15:54 ` Andrew Jones
2016-04-22 16:35 ` Alexander Gordeev
2016-04-26 8:24 ` Alexander Gordeev
2016-04-26 9:37 ` Andrew Jones
2016-04-11 11:04 ` [PATCH RFC 13/15] pci/arm: Add generic ECAM host support Alexander Gordeev
2016-04-22 17:07 ` Andrew Jones
2016-05-29 19:54 ` Alexander Gordeev
2016-05-30 6:12 ` Andrew Jones
2016-05-30 6:28 ` Alexander Gordeev
2016-05-30 6:40 ` Andrew Jones
2016-04-11 11:04 ` [PATCH RFC 14/15] pci: Add pci-testdev PCI bus test device Alexander Gordeev
2016-04-22 17:23 ` Andrew Jones
2016-05-23 8:02 ` Alexander Gordeev
2016-05-23 15:17 ` Andrew Jones
2016-05-29 17:48 ` Alexander Gordeev
2016-05-30 6:09 ` Andrew Jones
2016-04-11 11:04 ` [PATCH RFC 15/15] pci/arm: Add pci-testdev PCI device operation test Alexander Gordeev
2016-04-22 17:33 ` Andrew Jones
2016-05-29 20:03 ` Alexander Gordeev
2016-05-30 6:15 ` Andrew Jones
2016-05-31 20:13 ` Alexander Gordeev
2016-05-31 20:27 ` Andrew Jones
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=20160414083420.GA26536@agordeev.lab.eng.brq.redhat.com \
--to=agordeev@redhat.com \
--cc=drjones@redhat.com \
--cc=kvm@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).