From: "Michael S. Tsirkin" <mst@redhat.com>
To: Alexander Graf <agraf@suse.de>
Cc: Blue Swirl <blauwirbel@gmail.com>,
QEMU Developers <qemu-devel@nongnu.org>,
Aurelien Jarno <aurelien@aurel32.net>,
Isaku Yamahata <yamahata@valinux.co.jp>
Subject: Re: [Qemu-devel] Re: [PATCH 1/6] Make config space accessor host bus trapable
Date: Tue, 5 Jan 2010 01:12:35 +0200 [thread overview]
Message-ID: <20100104231234.GD21659@redhat.com> (raw)
In-Reply-To: <0FF40DC9-092F-4753-B93A-69E6B01B2568@suse.de>
On Tue, Jan 05, 2010 at 12:08:19AM +0100, Alexander Graf wrote:
>
> On 04.01.2010, at 23:59, Michael S. Tsirkin wrote:
>
> > On Tue, Jan 05, 2010 at 09:51:48AM +1100, Benjamin Herrenschmidt wrote:
> >> On Tue, 2010-01-05 at 00:25 +0200, Michael S. Tsirkin wrote:
> >>> On Tue, Jan 05, 2010 at 08:53:52AM +1100, Benjamin Herrenschmidt wrote:
> >>>>
> >>>>> Yes, but I think how you program your host to pci bridge is platform specific,
> >>>>> the standard (mostly) applies to what happens below the bridge. There's
> >>>>> no real standard for how PCI host bridge is connected to processor
> >>>>> AFAIK, it's by luck we can share code there at all.
> >>>>
> >>>> Well, yes and no ... there's a standard on how a PCI host bridge is
> >>>> connected in the sense that how normal MMIO accesses go through in term
> >>>> of endianness is well defined.
> >>>>
> >>>
> >>> Go through where? From processor to PCI?
> >>> Which spec do you refer to?
> >>
> >> The PCI spec from memory :-) Byte swizzling for MMIO between a processor
> >> and PCI bus is well defined.
> >
> > Couldn't find it in spec.
> >
> >> Now of course, since issuing config space cycles tend to be host-bridge
> >> chip specific, everything is possible there :-) In -most- cases though,
> >> they use a mechanism similar to x86 using the cf8/cfc ports or
> >> equivalent mapped wherever the PIO region is mapped in MMIO space for
> >> non-x86 processors, and thus end up with the exact same byte swizzling.
> >>
> >> In fact, this is true of accesses to PCI devices as well. Take for
> >> example, a device that has a 32-bit MMIO register. This register is
> >> meant to appear as little endian (well, unless the device itself plays
> >> tricks but most don't) whatever the host processor is. Thus an x86 host
> >> will need no byteswap but a powerpc host (assuming the ppc is running in
> >> BE mode) will.
> >>
> >> This is why for example the base readl and writel function in Linux do
> >> byteswap on powerpc.
> >>
> >> This is important to understand that this is a property of how the PCI
> >> bridge is connected to the host processor, such that the PCI "native"
> >> byte order is preserved along with address invariance for sub-32-bit
> >> quantities.
> >>
> >> The endianness of the host bridge config space access register is thus
> >> most of the time just a natural side effect of said register being part
> >> of the bridge PIO space and thus getting the natural byteswap explained
> >> above for a 32-bit LE register on PCI.
> >>
> >> Cheers,
> >> Ben.
> >
> > So, it appears that this is not the case for many platforms: bridge
> > itself does a byteswap to make devices behind it work according to spec,
> > but this does not apply to programming bridge itself.
> >
> > This seems common on BE platforms, this is why qemu has
> > ifdef TARGET_WORDS_BIGENDIAN there IIUC.
>
> IIRC qemu's mmio functions just pass the register value the guest had at that moment to the mmio function.
>
> While that is pretty simple, it means that we behave different from real hardware. Real hardware has 2 components:
>
> 1) CPU
> 2) Device
>
> The CPU sends an MMIO request in local byte order to the device. The device also has a native endianness - either BE or LE.
> So what the byte swap here does is simply converting from wrong LE (what Linux thought the device needs) to a proper variable.
>
> I'm not sure what the correct solution to this is. I'm inclined to suggest that mmio callbacks should get called with tswap'ed values. But then again the code as is works in quite a lot of cases and I don't want to spend months getting it back to where it is just because of a cosmetic change.
>
> Alex
If I understand correctly this is just a byteswap to emulate how host
bridge is connected, unrelated to local byte order. By anyway, I agree:
let's not spend months on this.
next prev parent reply other threads:[~2010-01-05 19:56 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-03 1:50 [Qemu-devel] [PATCH 0/6] PPC NewWorld fixery Alexander Graf
2010-01-03 1:50 ` [Qemu-devel] [PATCH 1/6] Make config space accessor host bus trapable Alexander Graf
2010-01-03 15:45 ` [Qemu-devel] " Michael S. Tsirkin
2010-01-03 16:09 ` Alexander Graf
2010-01-03 17:29 ` Michael S. Tsirkin
2010-01-03 17:40 ` Alexander Graf
2010-01-03 17:44 ` Michael S. Tsirkin
2010-01-03 17:50 ` Alexander Graf
2010-01-03 18:06 ` Michael S. Tsirkin
2010-01-03 19:18 ` Blue Swirl
2010-01-10 18:41 ` Blue Swirl
2010-01-11 21:29 ` Blue Swirl
2010-01-11 22:33 ` Igor Kovalenko
2010-01-12 19:29 ` Blue Swirl
2010-01-18 19:47 ` Blue Swirl
2010-01-03 20:27 ` Alexander Graf
2010-01-03 20:50 ` Benjamin Herrenschmidt
2010-01-04 3:26 ` Alexander Graf
2010-01-04 10:45 ` Isaku Yamahata
2010-01-04 10:55 ` Alexander Graf
2010-01-04 11:08 ` Isaku Yamahata
2010-01-04 11:07 ` Michael S. Tsirkin
2010-01-04 11:13 ` Alexander Graf
2010-01-04 20:10 ` Benjamin Herrenschmidt
2010-01-04 21:12 ` Michael S. Tsirkin
2010-01-04 21:25 ` Benjamin Herrenschmidt
2010-01-04 21:30 ` Michael S. Tsirkin
2010-01-04 21:53 ` Benjamin Herrenschmidt
2010-01-04 22:25 ` Michael S. Tsirkin
2010-01-04 22:51 ` Benjamin Herrenschmidt
2010-01-04 22:59 ` Michael S. Tsirkin
2010-01-04 23:08 ` Alexander Graf
2010-01-04 23:12 ` Michael S. Tsirkin [this message]
2010-01-04 23:39 ` Benjamin Herrenschmidt
2010-01-04 23:33 ` Benjamin Herrenschmidt
2010-01-03 1:50 ` [Qemu-devel] [PATCH 2/6] Add config space conversion function for uni_north Alexander Graf
2010-01-03 15:32 ` [Qemu-devel] " Michael S. Tsirkin
2010-01-03 15:40 ` Alexander Graf
2010-01-03 15:47 ` Michael S. Tsirkin
2010-01-03 16:13 ` Alexander Graf
2010-01-03 16:20 ` Michael S. Tsirkin
2010-01-03 16:35 ` Alexander Graf
2010-01-03 17:23 ` Michael S. Tsirkin
2010-01-03 15:48 ` Michael S. Tsirkin
2010-01-03 1:50 ` [Qemu-devel] [PATCH 3/6] Use Mac99_U3 type on ppc64 Alexander Graf
2010-01-03 1:50 ` [Qemu-devel] [PATCH 4/6] Include dump of lspci -nn on real G5 Alexander Graf
2010-01-03 1:50 ` [Qemu-devel] [PATCH 5/6] Make interrupts work Alexander Graf
2010-01-03 1:50 ` [Qemu-devel] [PATCH 6/6] Enable secondary cmd64x Alexander Graf
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=20100104231234.GD21659@redhat.com \
--to=mst@redhat.com \
--cc=agraf@suse.de \
--cc=aurelien@aurel32.net \
--cc=blauwirbel@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=yamahata@valinux.co.jp \
/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).