linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Du, Changbin" <changbin.du@intel.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: "Du, Changbin" <changbin.du@intel.com>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [Q] What about PCI mmio access alignment?
Date: Sun, 28 May 2017 18:54:16 +0800	[thread overview]
Message-ID: <20170528105415.GA17556@intel.com> (raw)
In-Reply-To: <CAHp75VcfYuDAO-1e0VHOmeudS2dDti1FM8+N+gNVEux-D8PMUQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1734 bytes --]

Thank you. I have some experiment on my PC. The result is:
  o I always can get expected value if the unaligned access doesn't across a
    DWORD boundary, like readw(bar0+1). I suspect that the chipset should read
    a whole DWORD in behind. This may trigger unexpected behaviour on device.
  o If read across DWORD boundary, I get some intersting value, like
    readl(bar0+2). For some device, I get a cyclic shifted value of the first
    DWORD, while some device return all FF.

So my conclusion is that no unaligned access and at least access one DWORD size.

On Sat, May 27, 2017 at 06:32:48PM +0300, Andy Shevchenko wrote:
> On Thu, May 25, 2017 at 1:12 PM, Du, Changbin <changbin.du@intel.com> wrote:
> > I have a basic quesion about the alignment when access PCI bar mmio space. Is
> > the address accessed must be DW aligned and count must be DW aligned?
> 
> I guess the best answer is PCI architecture specification.
> Book I have nearby tells me IIDnMS that yes, you have to follow alignment.
> 
> > As far as I know, The address field of TLB ignore lower 2 bits and the unit of
> > length field also is DW. So does it mean above question is Yes? Else will CPU
> > handle unaligned access for mmio space?
> 
> Here you perhaps meant the bus, not the CPU. PCI allows it as long as
> actual device allows it.
> 
> (I recall patch series that tries to micro optimize PCI config space
> access by grouping some bytes into words or even dwords, and it was
> rejected).
> 
> > I want to know wether below access illegal or not:
> >   - readb(bar0)
> >   - readb(bar0 + 1)
> >   - readl(bar0)
> 
> It depends.
> 
> -- 
> With Best Regards,
> Andy Shevchenko

-- 
Thanks,
Changbin Du

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

      reply	other threads:[~2017-05-28 10:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-25 10:12 [Q] What about PCI mmio access alignment? Du, Changbin
2017-05-27 15:32 ` Andy Shevchenko
2017-05-28 10:54   ` Du, Changbin [this message]

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=20170528105415.GA17556@intel.com \
    --to=changbin.du@intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    /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).