From patchwork Sun Jun 9 19:13:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 250127 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 B5A302C02A9 for ; Mon, 10 Jun 2013 06:08:49 +1000 (EST) Received: from localhost ([::1]:54338 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UllML-00052e-FU for incoming@patchwork.ozlabs.org; Sun, 09 Jun 2013 15:33:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59319) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ull4d-000131-Tm for qemu-devel@nongnu.org; Sun, 09 Jun 2013 15:14:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ull4b-0000pi-BX for qemu-devel@nongnu.org; Sun, 09 Jun 2013 15:14:43 -0400 Received: from cantor2.suse.de ([195.135.220.15]:44460 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ull4b-0000pP-09; Sun, 09 Jun 2013 15:14:41 -0400 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 856BFA51CB; Sun, 9 Jun 2013 21:14:40 +0200 (CEST) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Sun, 9 Jun 2013 21:13:14 +0200 Message-Id: <1370805206-26574-48-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1370805206-26574-1-git-send-email-afaerber@suse.de> References: <1370805206-26574-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 195.135.220.15 Cc: Alexander Graf , "open list:sPAPR" , =?UTF-8?q?Andreas=20F=C3=A4rber?= , David Gibson Subject: [Qemu-devel] [PATCH qom-cpu 47/59] spapr: Abstract spapr_fix_cpu_dt() with qemu_for_each_cpu() 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 Signed-off-by: Andreas Färber Reviewed-by: David Gibson --- hw/ppc/spapr.c | 91 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 38 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 218ea23..53b603d 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -128,53 +128,68 @@ int spapr_allocate_irq_block(int num, bool lsi) return first; } -static int spapr_fixup_cpu_dt(void *fdt, sPAPREnvironment *spapr) +typedef struct SPAPRFixupCPUDT { + void *fdt; + sPAPREnvironment *spapr; + int smt; + int ret; +} SPAPRFixupCPUDT; + +static void spapr_fixup_one_cpu_dt(CPUState *cs, void *data) { - int ret = 0, offset; - CPUPPCState *env; - CPUState *cpu; + SPAPRFixupCPUDT *s = data; char cpu_model[32]; - int smt = kvmppc_smt_threads(); - uint32_t pft_size_prop[] = {0, cpu_to_be32(spapr->htab_shift)}; - - assert(spapr->cpu_model); + int offset; + uint32_t associativity[] = { cpu_to_be32(0x5), + cpu_to_be32(0x0), + cpu_to_be32(0x0), + cpu_to_be32(0x0), + cpu_to_be32(cs->numa_node), + cpu_to_be32(cs->cpu_index) }; + uint32_t pft_size_prop[] = { 0, cpu_to_be32(s->spapr->htab_shift) }; - for (env = first_cpu; env != NULL; env = env->next_cpu) { - cpu = CPU(ppc_env_get_cpu(env)); - uint32_t associativity[] = {cpu_to_be32(0x5), - cpu_to_be32(0x0), - cpu_to_be32(0x0), - cpu_to_be32(0x0), - cpu_to_be32(cpu->numa_node), - cpu_to_be32(cpu->cpu_index)}; - - if ((cpu->cpu_index % smt) != 0) { - continue; - } + if (s->ret) { + return; + } - snprintf(cpu_model, 32, "/cpus/%s@%x", spapr->cpu_model, - cpu->cpu_index); + if ((cs->cpu_index % s->smt) != 0) { + return; + } - offset = fdt_path_offset(fdt, cpu_model); - if (offset < 0) { - return offset; - } + snprintf(cpu_model, 32, "/cpus/%s@%x", s->spapr->cpu_model, + cs->cpu_index); - if (nb_numa_nodes > 1) { - ret = fdt_setprop(fdt, offset, "ibm,associativity", associativity, - sizeof(associativity)); - if (ret < 0) { - return ret; - } - } + offset = fdt_path_offset(s->fdt, cpu_model); + if (offset < 0) { + s->ret = offset; + return; + } - ret = fdt_setprop(fdt, offset, "ibm,pft-size", - pft_size_prop, sizeof(pft_size_prop)); - if (ret < 0) { - return ret; + if (nb_numa_nodes > 1) { + s->ret = fdt_setprop(s->fdt, offset, "ibm,associativity", + associativity, sizeof(associativity)); + if (s->ret < 0) { + return; } } - return ret; + + s->ret = fdt_setprop(s->fdt, offset, "ibm,pft-size", + pft_size_prop, sizeof(pft_size_prop)); +} + +static int spapr_fixup_cpu_dt(void *fdt, sPAPREnvironment *spapr) +{ + SPAPRFixupCPUDT s = { + .fdt = fdt, + .spapr = spapr, + .smt = kvmppc_smt_threads(), + .ret = 0, + }; + + assert(spapr->cpu_model); + + qemu_for_each_cpu(spapr_fixup_one_cpu_dt, &s); + return s.ret; }