Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NRSZ3-0005pE-2J for qemu-devel@nongnu.org; Sun, 03 Jan 2010 10:40:21 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NRSYy-0005k0-HT for qemu-devel@nongnu.org; Sun, 03 Jan 2010 10:40:20 -0500 Received: from [199.232.76.173] (port=59055 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NRSYx-0005jg-Vx for qemu-devel@nongnu.org; Sun, 03 Jan 2010 10:40:16 -0500 Received: from cantor2.suse.de ([195.135.220.15]:58654 helo=mx2.suse.de) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NRSYx-0004gG-Eq for qemu-devel@nongnu.org; Sun, 03 Jan 2010 10:40:15 -0500 Mime-Version: 1.0 (Apple Message framework v1077) Content-Type: text/plain; charset=us-ascii From: Alexander Graf In-Reply-To: <20100103153215.GA8137@redhat.com> Date: Sun, 3 Jan 2010 16:40:12 +0100 Content-Transfer-Encoding: quoted-printable Message-Id: References: <1262483450-15206-1-git-send-email-agraf@suse.de> <1262483450-15206-3-git-send-email-agraf@suse.de> <20100103153215.GA8137@redhat.com> Subject: [Qemu-devel] Re: [PATCH 2/6] Add config space conversion function for uni_north List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S.Tsirkin" Cc: Blue Swirl , QEMU Developers , Aurelien Jarno On 03.01.2010, at 16:32, Michael S. Tsirkin wrote: > On Sun, Jan 03, 2010 at 02:50:46AM +0100, Alexander Graf wrote: >> As stated in the previous patch, the Uninorth PCI bridge requires = different >> layouts in its PCI config space accessors. >>=20 >> This patch introduces a conversion function that makes it compatible = with >> the way Linux accesses it. >>=20 >> I also kept an OpenBIOS compatibility hack in. I think it'd be better = to >> take small steps here and do the config space access rework in = OpenBIOS >> later on. When that's done we can remove that hack. >>=20 >> Signed-off-by: Alexander Graf >> --- >> hw/unin_pci.c | 35 +++++++++++++++++++++++++++++++++++ >> 1 files changed, 35 insertions(+), 0 deletions(-) >>=20 >> diff --git a/hw/unin_pci.c b/hw/unin_pci.c >> index fdb9401..1c49008 100644 >> --- a/hw/unin_pci.c >> +++ b/hw/unin_pci.c >> @@ -75,6 +75,40 @@ static void pci_unin_reset(void *opaque) >> { >> } >>=20 >> +static uint32_t unin_get_config_reg(PCIHostState *s, uint32_t addr) >> +{ >> + uint32_t retval; >> + uint32_t reg =3D s->config_reg; >> + >> + if (reg & (1u << 31)) { >> + /* XXX OpenBIOS compatibility hack */ >> + retval =3D reg; >> + addr |=3D reg & 7; >> + } else if (reg & 1) { >> + /* Set upper valid bit and remove lower one */ >> + retval =3D (reg & ~3u) | (1u << 31); >> + } else { >> + uint32_t slot, func; >> + uint32_t devfn; >> + >> + /* Grab CFA0 style values */ >> + slot =3D ffs(reg & 0xfffff800) - 1; >> + func =3D (reg >> 8) & 7; >> + devfn =3D PCI_DEVFN(slot, func); >> + >> + /* ... and then convert them to x86 format */ >> + retval =3D (reg & 0xfc) | (devfn << 8) | (1u << 31); >=20 > Is it a good idea to have a helper that encodes reg/dev/fn into a 32 = bit > number? This way this encoding can be changed down the road. I don't think I understand this comment? :-) >=20 >> + } >> + >> + retval &=3D ~3u; >> + retval |=3D (addr & 7); >> + >> + UNIN_DPRINTF("Converted config space accessor %08x/%08x -> = %08x\n", >> + reg, addr, retval); >> + >> + return retval; >> +} >> + >> static int pci_unin_main_init_device(SysBusDevice *dev) >> { >> UNINState *s; >> @@ -85,6 +119,7 @@ static int pci_unin_main_init_device(SysBusDevice = *dev) >> s =3D FROM_SYSBUS(UNINState, dev); >>=20 >> pci_host_init(&s->host_state); >> + s->host_state.get_config_reg =3D unin_get_config_reg; >=20 > This looks slightly ugly: let's make pci_host_init accept > the conversion function instead? Hmm. My guess was that 99% of the host adapters don't need a replacement = function, so I wanted to keep the defaults simple. If we later on add = additional helpers, that would also be easier, as we wouldn't need to = touch every initializer call but only the overriding ones. Alex=