public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Chris Lesiak <chris.lesiak@licor.com>
To: linux-kernel@vger.kernel.org
Cc: Chris Lesiak <chris.lesiak@licor.com>
Subject: memcpy_toio on i386 using byte writes even when n%2==0
Date: Fri, 26 May 2006 10:29:22 -0500	[thread overview]
Message-ID: <1148657362.4376.77.camel@emerson.licor.com> (raw)

I'm working on a driver for a custom PCI card on the i386 architecture.
The card uses a PLX9030 pci bridge to link an FPGA to the PCI bus using
a 16 bit bus.  I found that something broke when moving from 2.6.10 to
2.6.17-rc4.  In the driver, I use memcpy_toio to write 14 bytes to a
memory region in the FPGA.

To copy the 14 bytes, 2.6.10 does three 32 bit writes followed by one 16
bit write.  2.6.10 does three 32 bit writes followed by two 8 bit write.

The PLX9030 breaks the 32 bit writes into 16 bit writes for its local
bus just fine.  The problem is that my board doesn't handle byte
enables.  It was assumed that if all memory transfers were a multiple of
2 bytes, then byte accesses wouldn't be used.  This is no longer true in
2.6.7-rc4.

I've solved the problem by padding to 16 bytes, but should this be
considered a bug in the kernel?

Both kernels use __memcpy to implement memcpy_toio.  Here is the
relevent code from <asm-i386/string.h>

The 2.6.10 version:

static inline void * __memcpy(void * to, const void * from, size_t n)
{
int d0, d1, d2;
__asm__ __volatile__(
        "rep ; movsl\n\t"
        "testb $2,%b4\n\t"
        "je 1f\n\t"
        "movsw\n"
        "1:\ttestb $1,%b4\n\t"
        "je 2f\n\t"
        "movsb\n"
        "2:"
        : "=&c" (d0), "=&D" (d1), "=&S" (d2)
        :"0" (n/4), "q" (n),"1" ((long) to),"2" ((long) from)
        : "memory");
return (to);
}

The 2.6.17-rc4 version:

static __always_inline void * __memcpy(void * to, const void * from,
size_t n)
{
int d0, d1, d2;
__asm__ __volatile__(
        "rep ; movsl\n\t"
        "movl %4,%%ecx\n\t"
        "andl $3,%%ecx\n\t"
#if 1   /* want to pay 2 byte penalty for a chance to skip microcoded
rep? */
        "jz 1f\n\t"
#endif
        "rep ; movsb\n\t"
        "1:"
        : "=&c" (d0), "=&D" (d1), "=&S" (d2)
        : "0" (n/4), "g" (n), "1" ((long) to), "2" ((long) from)
        : "memory");
return (to);
}

-- 
Chris Lesiak
chris.lesiak@licor.com


             reply	other threads:[~2006-05-26 15:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-26 15:29 Chris Lesiak [this message]
     [not found] <6gMqr-8uW-23@gated-at.bofh.it>
2006-05-26 23:46 ` memcpy_toio on i386 using byte writes even when n%2==0 Robert Hancock
2006-05-29  7:38   ` H. Peter Anvin
2006-05-30 13:55   ` Chris Lesiak
2006-05-30 14:24     ` linux-os (Dick Johnson)
     [not found] <6gUec-3mb-7@gated-at.bofh.it>
     [not found] ` <6gUec-3mb-5@gated-at.bofh.it>
     [not found]   ` <6icVy-56r-9@gated-at.bofh.it>
     [not found]     ` <6idov-5Tc-7@gated-at.bofh.it>
2006-05-31  0:55       ` Robert Hancock
2006-05-31  1:13         ` H. Peter Anvin
     [not found] <6ined-4gY-17@gated-at.bofh.it>
     [not found] ` <6ined-4gY-21@gated-at.bofh.it>
     [not found]   ` <6inee-4gY-23@gated-at.bofh.it>
     [not found]     ` <6ined-4gY-15@gated-at.bofh.it>
     [not found]       ` <6inxv-4U2-17@gated-at.bofh.it>
2006-06-03 23:52         ` Robert Hancock
2006-06-04  0:48           ` H. Peter Anvin

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=1148657362.4376.77.camel@emerson.licor.com \
    --to=chris.lesiak@licor.com \
    --cc=linux-kernel@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