From patchwork Wed Jun 19 20:40:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 252662 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 92D642C00B1 for ; Thu, 20 Jun 2013 06:48:16 +1000 (EST) Received: from localhost ([::1]:60522 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpPIc-0000dn-Gm for incoming@patchwork.ozlabs.org; Wed, 19 Jun 2013 16:48:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33958) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpPD5-00026p-0D for qemu-devel@nongnu.org; Wed, 19 Jun 2013 16:42:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UpPD3-0005Pu-Hx for qemu-devel@nongnu.org; Wed, 19 Jun 2013 16:42:30 -0400 Received: from e7.ny.us.ibm.com ([32.97.182.137]:48944) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpPD3-0005Ph-BW for qemu-devel@nongnu.org; Wed, 19 Jun 2013 16:42:29 -0400 Received: from /spool/local by e7.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 19 Jun 2013 16:42:29 -0400 Received: from d01dlp03.pok.ibm.com (9.56.250.168) by e7.ny.us.ibm.com (192.168.1.107) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 19 Jun 2013 16:42:27 -0400 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id 99441C90050; Wed, 19 Jun 2013 16:42:25 -0400 (EDT) Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r5JKfNmY303610; Wed, 19 Jun 2013 16:41:24 -0400 Received: from d03av03.boulder.ibm.com (loopback [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r5JKfL60025175; Wed, 19 Jun 2013 14:41:21 -0600 Received: from titi.austin.rr.com ([9.49.221.0]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r5JKeaBj020317; Wed, 19 Jun 2013 14:41:15 -0600 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Wed, 19 Jun 2013 15:40:34 -0500 Message-Id: <1371674435-14973-12-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1371674435-14973-1-git-send-email-aliguori@us.ibm.com> References: <1371674435-14973-1-git-send-email-aliguori@us.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13061920-5806-0000-0000-000021C9FF8E X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 32.97.182.137 Cc: Anthony Liguori , Alexey Kardashevskiy , Alex Graf , qemu-ppc@nongnu.org, Paul Mackerras , Andreas Faerber Subject: [Qemu-devel] [PATCH 11/12] spapr-vio: pass type to spapr_vio_find_by_reg() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Today if an invalid hcall is made to an otherwise valid device we abort due to QOM casting. This adds a parameter to find_by_reg() to indicate which type of device we're looking for. Signed-off-by: Anthony Liguori --- hw/char/spapr_vty.c | 14 ++++---------- hw/net/spapr_llan.c | 15 ++++++++++----- hw/ppc/spapr_vio.c | 24 +++++++++++++++--------- include/hw/ppc/spapr_vio.h | 3 ++- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/hw/char/spapr_vty.c b/hw/char/spapr_vty.c index bbd5ecb..aa56f10 100644 --- a/hw/char/spapr_vty.c +++ b/hw/char/spapr_vty.c @@ -94,15 +94,12 @@ static target_ulong h_put_term_char(PowerPCCPU *cpu, sPAPREnvironment *spapr, uint8_t buf[16]; int i; - sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg); + sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg, + TYPE_VIO_SPAPR_VTY_DEVICE); if (!sdev) { return H_PARAMETER; } - if (!object_dynamic_cast(OBJECT(sdev), TYPE_VIO_SPAPR_VTY_DEVICE)) { - return H_PARAMETER; - } - if (len > 16) { return H_PARAMETER; } @@ -128,15 +125,12 @@ static target_ulong h_get_term_char(PowerPCCPU *cpu, sPAPREnvironment *spapr, uint8_t buf[16]; int i; - sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg); + sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg, + TYPE_VIO_SPAPR_VTY_DEVICE); if (!sdev) { return H_PARAMETER; } - if (!object_dynamic_cast(OBJECT(sdev), TYPE_VIO_SPAPR_VTY_DEVICE)) { - return H_PARAMETER; - } - len = spapr_vty_getchars(VIO_SPAPR_VTY_DEVICE(sdev), buf, sizeof(buf)); args[0] = len; diff --git a/hw/net/spapr_llan.c b/hw/net/spapr_llan.c index 03a09f2..429d020 100644 --- a/hw/net/spapr_llan.c +++ b/hw/net/spapr_llan.c @@ -285,7 +285,8 @@ static target_ulong h_register_logical_lan(PowerPCCPU *cpu, target_ulong buf_list = args[1]; target_ulong rec_queue = args[2]; target_ulong filter_list = args[3]; - VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg); + VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg, + TYPE_VIO_SPAPR_VLAN_DEVICE); VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev); vlan_bd_t filter_list_bd; @@ -346,7 +347,8 @@ static target_ulong h_free_logical_lan(PowerPCCPU *cpu, sPAPREnvironment *spapr, target_ulong opcode, target_ulong *args) { target_ulong reg = args[0]; - VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg); + VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg, + TYPE_VIO_SPAPR_VLAN_DEVICE); VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev); if (!dev) { @@ -370,7 +372,8 @@ static target_ulong h_add_logical_lan_buffer(PowerPCCPU *cpu, { target_ulong reg = args[0]; target_ulong buf = args[1]; - VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg); + VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg, + TYPE_VIO_SPAPR_VLAN_DEVICE); VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev); vlan_bd_t bd; @@ -418,7 +421,8 @@ static target_ulong h_send_logical_lan(PowerPCCPU *cpu, sPAPREnvironment *spapr, target_ulong reg = args[0]; target_ulong *bufs = args + 1; target_ulong continue_token = args[7]; - VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg); + VIOsPAPRDevice *sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg, + TYPE_VIO_SPAPR_VLAN_DEVICE); VIOsPAPRVLANDevice *dev = VIO_SPAPR_VLAN_DEVICE(sdev); unsigned total_len; uint8_t *lbuf, *p; @@ -485,7 +489,8 @@ static target_ulong h_multicast_ctrl(PowerPCCPU *cpu, sPAPREnvironment *spapr, target_ulong opcode, target_ulong *args) { target_ulong reg = args[0]; - VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg); + VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg, + TYPE_VIO_SPAPR_VLAN_DEVICE); if (!dev) { return H_PARAMETER; diff --git a/hw/ppc/spapr_vio.c b/hw/ppc/spapr_vio.c index ee99eec..b4ef48b 100644 --- a/hw/ppc/spapr_vio.c +++ b/hw/ppc/spapr_vio.c @@ -114,7 +114,8 @@ static VIOsPAPRDevice *spapr_vty_get_default(VIOsPAPRBus *bus) return selected; } -VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg) +VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg, + const char *typename) { BusChild *kid; VIOsPAPRDevice *dev = NULL; @@ -129,8 +130,8 @@ VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg) } QTAILQ_FOREACH(kid, &bus->bus.children, sibling) { - dev = (VIOsPAPRDevice *)kid->child; - if (dev->reg == reg) { + dev = VIO_SPAPR_DEVICE(kid->child); + if (dev->reg == reg && object_dynamic_cast(OBJECT(dev), typename)) { return dev; } } @@ -212,7 +213,8 @@ static target_ulong h_reg_crq(PowerPCCPU *cpu, sPAPREnvironment *spapr, target_ulong reg = args[0]; target_ulong queue_addr = args[1]; target_ulong queue_len = args[2]; - VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg); + VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg, + TYPE_VIO_SPAPR_DEVICE); if (!dev) { hcall_dprintf("Unit 0x" TARGET_FMT_lx " does not exist\n", reg); @@ -268,7 +270,8 @@ static target_ulong h_free_crq(PowerPCCPU *cpu, sPAPREnvironment *spapr, target_ulong opcode, target_ulong *args) { target_ulong reg = args[0]; - VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg); + VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg, + TYPE_VIO_SPAPR_DEVICE); if (!dev) { hcall_dprintf("Unit 0x" TARGET_FMT_lx " does not exist\n", reg); @@ -284,7 +287,8 @@ static target_ulong h_send_crq(PowerPCCPU *cpu, sPAPREnvironment *spapr, target_ulong reg = args[0]; target_ulong msg_hi = args[1]; target_ulong msg_lo = args[2]; - VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg); + VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg, + TYPE_VIO_SPAPR_DEVICE); uint64_t crq_mangle[2]; if (!dev) { @@ -305,7 +309,8 @@ static target_ulong h_enable_crq(PowerPCCPU *cpu, sPAPREnvironment *spapr, target_ulong opcode, target_ulong *args) { target_ulong reg = args[0]; - VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg); + VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg, + TYPE_VIO_SPAPR_DEVICE); if (!dev) { hcall_dprintf("Unit 0x" TARGET_FMT_lx " does not exist\n", reg); @@ -382,7 +387,7 @@ static void rtas_set_tce_bypass(PowerPCCPU *cpu, sPAPREnvironment *spapr, } unit = rtas_ld(args, 0); enable = rtas_ld(args, 1); - dev = spapr_vio_find_by_reg(bus, unit); + dev = spapr_vio_find_by_reg(bus, unit, TYPE_VIO_SPAPR_DEVICE); if (!dev) { rtas_st(rets, 0, -3); return; @@ -513,7 +518,8 @@ static target_ulong h_vio_signal(PowerPCCPU *cpu, sPAPREnvironment *spapr, { target_ulong reg = args[0]; target_ulong mode = args[1]; - VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg); + VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg, + TYPE_VIO_SPAPR_DEVICE); VIOsPAPRDeviceClass *pc; if (!dev) { diff --git a/include/hw/ppc/spapr_vio.h b/include/hw/ppc/spapr_vio.h index f55eb90..e513889 100644 --- a/include/hw/ppc/spapr_vio.h +++ b/include/hw/ppc/spapr_vio.h @@ -77,7 +77,8 @@ struct VIOsPAPRBus { }; extern VIOsPAPRBus *spapr_vio_bus_init(void); -extern VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg); +extern VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg, + const char *typename); extern int spapr_populate_vdevice(VIOsPAPRBus *bus, void *fdt); extern int spapr_populate_chosen_stdout(void *fdt, VIOsPAPRBus *bus);