Received: from eggs.gnu.org ([2001:4830:134:3::10]:49813) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpPvx-0008Rw-4B for qemu-devel@nongnu.org; Wed, 19 Jun 2013 17:28:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UpPvv-0005me-MH for qemu-devel@nongnu.org; Wed, 19 Jun 2013 17:28:53 -0400 Mime-Version: 1.0 (Apple Message framework v1278) Content-Type: text/plain; charset=us-ascii From: Alexander Graf In-Reply-To: <1371674435-14973-10-git-send-email-aliguori@us.ibm.com> Date: Wed, 19 Jun 2013 23:28:45 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: References: <1371674435-14973-1-git-send-email-aliguori@us.ibm.com> <1371674435-14973-10-git-send-email-aliguori@us.ibm.com> Subject: Re: [Qemu-devel] [PATCH 09/12] spapr-vio: move special case handling for reg=0 to vio List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Alexey Kardashevskiy , qemu-devel qemu-devel , "qemu-ppc@nongnu.org list:PowerPC" , Paul Mackerras , Andreas Faerber On 19.06.2013, at 22:40, Anthony Liguori wrote: > The creatively named reg field is a hypervisor assigned global > identifier for a virtual device. Despite the fact that no device > is assigned a reg of 0, guests still use it to refer to early > console. >=20 > Instead of handling this in the VTY device, handle this in the VIO > bus since this is ultimately about how devices are decoded. >=20 > This does not produce a change in behavior since reg=3D0 hcalls to > non-VTY devices will still fail as gloriously as they did before > just for a different reason (invalid device instead of invalid reg). Ben, is it true that reg=3D0 is guaranteed to be free, regardless of the = target call? Also, are there no other PAPR calls that could possibly = refer to reg=3D0 but mean something different from the VTY device? Alex >=20 > Signed-off-by: Anthony Liguori > --- > hw/char/spapr_vty.c | 58 = ++-------------------------------------------- > hw/ppc/spapr_vio.c | 46 ++++++++++++++++++++++++++++++++++++ > include/hw/ppc/spapr_vio.h | 2 -- > 3 files changed, 48 insertions(+), 58 deletions(-) >=20 > diff --git a/hw/char/spapr_vty.c b/hw/char/spapr_vty.c > index 4bac79e..45fc3ce 100644 > --- a/hw/char/spapr_vty.c > +++ b/hw/char/spapr_vty.c > @@ -86,23 +86,6 @@ static int spapr_vty_init(VIOsPAPRDevice *sdev) > return 0; > } >=20 > -static VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, = target_ulong reg) > -{ > - VIOsPAPRDevice *sdev; > - > - sdev =3D spapr_vio_find_by_reg(spapr->vio_bus, reg); > - if (!sdev && reg =3D=3D 0) { > - /* Hack for kernel early debug, which always specifies = reg=3D=3D0. > - * We search all VIO devices, and grab the vty with the = lowest > - * reg. This attempts to mimic existing PowerVM behaviour > - * (early debug does work there, despite having no vty with > - * reg=3D=3D0. */ > - return spapr_vty_get_default(spapr->vio_bus); > - } > - > - return sdev; > -} > - > /* Forward declaration */ > static target_ulong h_put_term_char(PowerPCCPU *cpu, sPAPREnvironment = *spapr, > target_ulong opcode, target_ulong = *args) > @@ -114,7 +97,7 @@ static target_ulong h_put_term_char(PowerPCCPU = *cpu, sPAPREnvironment *spapr, > VIOsPAPRDevice *sdev; > uint8_t buf[16]; >=20 > - sdev =3D vty_lookup(spapr, reg); > + sdev =3D spapr_vio_find_by_reg(spapr->vio_bus, reg); > if (!sdev) { > return H_PARAMETER; > } > @@ -141,7 +124,7 @@ static target_ulong h_get_term_char(PowerPCCPU = *cpu, sPAPREnvironment *spapr, > VIOsPAPRDevice *sdev; > uint8_t buf[16]; >=20 > - sdev =3D vty_lookup(spapr, reg); > + sdev =3D spapr_vio_find_by_reg(spapr->vio_bus, reg); > if (!sdev) { > return H_PARAMETER; > } > @@ -191,43 +174,6 @@ static const TypeInfo spapr_vty_info =3D { > .class_init =3D spapr_vty_class_init, > }; >=20 > -VIOsPAPRDevice *spapr_vty_get_default(VIOsPAPRBus *bus) > -{ > - VIOsPAPRDevice *sdev, *selected; > - BusChild *kid; > - > - /* > - * To avoid the console bouncing around we want one VTY to be > - * the "default". We haven't really got anything to go on, so > - * arbitrarily choose the one with the lowest reg value. > - */ > - > - selected =3D NULL; > - QTAILQ_FOREACH(kid, &bus->bus.children, sibling) { > - DeviceState *iter =3D kid->child; > - > - /* Only look at VTY devices */ > - if (!object_dynamic_cast(OBJECT(iter), "spapr-vty")) { > - continue; > - } > - > - sdev =3D VIO_SPAPR_DEVICE(iter); > - > - /* First VTY we've found, so it is selected for now */ > - if (!selected) { > - selected =3D sdev; > - continue; > - } > - > - /* Choose VTY with lowest reg value */ > - if (sdev->reg < selected->reg) { > - selected =3D sdev; > - } > - } > - > - return selected; > -} > - > static void spapr_vty_register_types(void) > { > spapr_register_hypercall(H_PUT_TERM_CHAR, h_put_term_char); > diff --git a/hw/ppc/spapr_vio.c b/hw/ppc/spapr_vio.c > index 2c5b159..ee99eec 100644 > --- a/hw/ppc/spapr_vio.c > +++ b/hw/ppc/spapr_vio.c > @@ -77,11 +77,57 @@ static const TypeInfo spapr_vio_bus_info =3D { > .instance_size =3D sizeof(VIOsPAPRBus), > }; >=20 > +static VIOsPAPRDevice *spapr_vty_get_default(VIOsPAPRBus *bus) > +{ > + VIOsPAPRDevice *sdev, *selected; > + BusChild *kid; > + > + /* > + * To avoid the console bouncing around we want one VTY to be > + * the "default". We haven't really got anything to go on, so > + * arbitrarily choose the one with the lowest reg value. > + */ > + > + selected =3D NULL; > + QTAILQ_FOREACH(kid, &bus->bus.children, sibling) { > + DeviceState *iter =3D kid->child; > + > + /* Only look at VTY devices */ > + if (!object_dynamic_cast(OBJECT(iter), "spapr-vty")) { > + continue; > + } > + > + sdev =3D VIO_SPAPR_DEVICE(iter); > + > + /* First VTY we've found, so it is selected for now */ > + if (!selected) { > + selected =3D sdev; > + continue; > + } > + > + /* Choose VTY with lowest reg value */ > + if (sdev->reg < selected->reg) { > + selected =3D sdev; > + } > + } > + > + return selected; > +} > + > VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg) > { > BusChild *kid; > VIOsPAPRDevice *dev =3D NULL; >=20 > + /* Hack for kernel early debug, which always specifies reg=3D=3D0. > + * We search all VIO devices, and grab the vty with the lowest > + * reg. This attempts to mimic existing PowerVM behaviour > + * (early debug does work there, despite having no vty with > + * reg=3D=3D0. */ > + if (reg =3D=3D 0) { > + return spapr_vty_get_default(bus); > + } > + > QTAILQ_FOREACH(kid, &bus->bus.children, sibling) { > dev =3D (VIOsPAPRDevice *)kid->child; > if (dev->reg =3D=3D reg) { > diff --git a/include/hw/ppc/spapr_vio.h b/include/hw/ppc/spapr_vio.h > index 817f5ff..f55eb90 100644 > --- a/include/hw/ppc/spapr_vio.h > +++ b/include/hw/ppc/spapr_vio.h > @@ -127,8 +127,6 @@ void spapr_vty_create(VIOsPAPRBus *bus, = CharDriverState *chardev); > void spapr_vlan_create(VIOsPAPRBus *bus, NICInfo *nd); > void spapr_vscsi_create(VIOsPAPRBus *bus); >=20 > -VIOsPAPRDevice *spapr_vty_get_default(VIOsPAPRBus *bus); > - > void spapr_vio_quiesce(void); >=20 > #endif /* _HW_SPAPR_VIO_H */ > --=20 > 1.8.0 >=20