From patchwork Thu Dec 22 21:55:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13080342 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 15A6FC4332F for ; Thu, 22 Dec 2022 21:58:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p8TXx-00060b-7k; Thu, 22 Dec 2022 16:56:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p8TXu-0005zv-VZ for qemu-devel@nongnu.org; Thu, 22 Dec 2022 16:56:10 -0500 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p8TXs-00079G-TW for qemu-devel@nongnu.org; Thu, 22 Dec 2022 16:56:10 -0500 Received: by mail-ej1-x62c.google.com with SMTP id qk9so7984918ejc.3 for ; Thu, 22 Dec 2022 13:56:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WO7iVynT/sEzTHQRGzivhFt/eqGQoyfPA70WfNKwLOg=; b=r8aK67xYtN7byddt2ja6SDNAZSuUkzinXBmBfDN6EXe9Hi6j7BaDxLCL2/xXx3IanF 08Wh+sUQVipBtmii0Pemt/DWy8qK11Lkzaasa8aeTXfU2eQcpsXnv13VS1SUt39VIY+A /WeQupkoRFe4NCBsKymdyayfdRYH4IkOZ1eLRIpHm0x3Xa0gvAVWaWGjxTkg5Nqc0YFI LmTBW0eW6heCKhoB5IlTY+gI66Wyy3wexGCSVgLzAhoCTj4T8b3W5QqYF+l8dzBmZ7lw 3qrUDYvWa3iibIEeGLkOv0Rg1fEMkkRXd0ivrXte7ACWAx9K4FsFX5i/fNdDA8HlkcoL 3KCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WO7iVynT/sEzTHQRGzivhFt/eqGQoyfPA70WfNKwLOg=; b=41m/xA1OB3A/NVD23L+fSbBFR6Y/+59DhzzyhhUNyTZ3NbTK6+Isimz/PBK++c8haZ hvKB/KlZYxy6JTi/ROaqq2TQn6/B0gU8HdS5BNCxEL6ulO/f4nNRjJ3oXBSNr8+0TyTV kryxi2ubndg4cYQ08cpTre058c6d3MlOusUTLhzVCv6tYsw+5H+qqD9yOt3Iyc6QMzTV Yu4szu4cbXppzHauGB1Dq1aSqNGp4FZr9ciRDht5NhnhzeDvIH7uZmqbteTSTe5ayoEq 65lIucOh5IFvuPpAZxKh9RpH5GWq/iE1Pdhy25ckf9CsDzo6jaoOkWyFc9do/qOZmTHm 0iOw== X-Gm-Message-State: AFqh2kq027CYxRt4R+BNSW3U+PeyapyWQ4QJzt6qgMUVtTRDpfgKbClr BhcWMwgpZOdKVh3OmTBPIdOw1CThCzS2gvgAogg= X-Google-Smtp-Source: AMrXdXv83/+HvK/EcdqE+SnXeiZihONsPv7C08cMlk8kYuYV61QSm+LEvwPqS0JzW7Ju1YoYH1aY1Q== X-Received: by 2002:a17:906:d044:b0:7c0:e7a7:50b with SMTP id bo4-20020a170906d04400b007c0e7a7050bmr4888865ejb.48.1671746167393; Thu, 22 Dec 2022 13:56:07 -0800 (PST) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id s2-20020a170906168200b00808c5e283e8sm664876ejd.178.2022.12.22.13.56.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 22 Dec 2022 13:56:06 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Andrew Jeffery , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Igor Mitsyanko , Joel Stanley , Havard Skinnemoen , Peter Maydell , "Edgar E. Iglesias" , =?utf-8?q?C=C3=A9dric_Le_Go?= =?utf-8?q?ater?= , Alistair Francis , qemu-arm@nongnu.org, Tyrone Ting Subject: [PATCH 1/6] hw/arm/aspeed: Fix smpboot[] on big-endian hosts Date: Thu, 22 Dec 2022 22:55:44 +0100 Message-Id: <20221222215549.86872-2-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221222215549.86872-1-philmd@linaro.org> References: <20221222215549.86872-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=philmd@linaro.org; helo=mail-ej1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org ARM CPUs fetch instructions in little-endian. smpboot[] encoded instructions are written in little-endian. This is fine on little-endian host, but on big-endian ones the smpboot[] array ends swapped. Use the const_le32() macro so the instructions are always in little-endian in the smpboot[] array. Fixes: 9bb6d14081 ("aspeed: Add boot stub for smp booting") Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Signed-off-by: Cédric Le Goater --- hw/arm/aspeed.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c index 55f114ef72..adff9a0d73 100644 --- a/hw/arm/aspeed.c +++ b/hw/arm/aspeed.c @@ -194,22 +194,22 @@ static void aspeed_write_smpboot(ARMCPU *cpu, * r1 = AST_SMP_MBOX_FIELD_ENTRY * r0 = AST_SMP_MBOX_FIELD_GOSIGN */ - 0xee100fb0, /* mrc p15, 0, r0, c0, c0, 5 */ - 0xe21000ff, /* ands r0, r0, #255 */ - 0xe59f201c, /* ldr r2, [pc, #28] */ - 0xe1822000, /* orr r2, r2, r0 */ + const_le32(0xee100fb0), /* mrc p15, 0, r0, c0, c0, 5 */ + const_le32(0xe21000ff), /* ands r0, r0, #255 */ + const_le32(0xe59f201c), /* ldr r2, [pc, #28] */ + const_le32(0xe1822000), /* orr r2, r2, r0 */ - 0xe59f1018, /* ldr r1, [pc, #24] */ - 0xe59f0018, /* ldr r0, [pc, #24] */ + const_le32(0xe59f1018), /* ldr r1, [pc, #24] */ + const_le32(0xe59f0018), /* ldr r0, [pc, #24] */ - 0xe320f002, /* wfe */ - 0xe5904000, /* ldr r4, [r0] */ - 0xe1520004, /* cmp r2, r4 */ - 0x1afffffb, /* bne */ - 0xe591f000, /* ldr pc, [r1] */ - AST_SMP_MBOX_GOSIGN, - AST_SMP_MBOX_FIELD_ENTRY, - AST_SMP_MBOX_FIELD_GOSIGN, + const_le32(0xe320f002), /* wfe */ + const_le32(0xe5904000), /* ldr r4, [r0] */ + const_le32(0xe1520004), /* cmp r2, r4 */ + const_le32(0x1afffffb), /* bne */ + const_le32(0xe591f000), /* ldr pc, [r1] */ + const_le32(AST_SMP_MBOX_GOSIGN), + const_le32(AST_SMP_MBOX_FIELD_ENTRY), + const_le32(AST_SMP_MBOX_FIELD_GOSIGN) }; rom_add_blob_fixed("aspeed.smpboot", poll_mailbox_ready, From patchwork Thu Dec 22 21:55:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13080339 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A3106C3DA7A for ; Thu, 22 Dec 2022 21:56:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p8TY2-00061M-Mu; Thu, 22 Dec 2022 16:56:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p8TY1-000617-V3 for qemu-devel@nongnu.org; Thu, 22 Dec 2022 16:56:17 -0500 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p8TY0-0007A8-8f for qemu-devel@nongnu.org; Thu, 22 Dec 2022 16:56:17 -0500 Received: by mail-ed1-x532.google.com with SMTP id i9so4765411edj.4 for ; Thu, 22 Dec 2022 13:56:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AlbISwcoF8H6Ar9FnAMnX+v9JsbwYxtSUgLoTP68Yao=; b=TjwkXWpK7sWdeaEkSOn7VT6qF7d7U8U4y7e75Dbmw4WyOYjJiSn2Q59SoqZ1U0M5Cs gZ+aKXgZPEwZ7TrwDS5W0ocFtv2inntkkeITuG51lYDt57W6sjYJmUpVFRlEjeI4Po3f v/mH+76S7WXUvektN2uPZMGkc7ytKYvLhYis5wdpWThDm70iXsHNqBaQDaMCaFNo6fZ5 h3T09DbKCeVju37PxiP4bqAbs+iB2ymmQkHDFUM8159OPpqA8/CqEHGOa7cMPWtl7bHZ CqhKMjgc/ae3eARHs7O9q+vDgnfrmlANQYVAr1rQWcj0rksi6T/UVvcERFoLoJxGJij8 L6lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AlbISwcoF8H6Ar9FnAMnX+v9JsbwYxtSUgLoTP68Yao=; b=UV4g4fjEmxcisLiCO4kj7NYkAqZ7cQdtlFaV0OTKQmC7sCUceXNh1jDgwM100UYedE gmec/E3/AfzirNlKRSlc6xYag20XAIW4dAwIAKjRU1VNPh/zHyH9Zm/KI+v9NYUPfWk/ 4jEnlMk9bmEC0djGhwXUU8b5JWApyLgEwQrUkx/XzxfL7Cn703S1RXNhGAtppnfiK+hT Gh7pZsUPu9Yb9PfOG7M+FS8EeLcm18YzxEfN6eohbPWssrq8/K5IcyjKABDZFYDxdFnt o878DbUqJpIG1HuTDj+hKvWnr+2lAHkEBfwL2mphnbZDJKIgNn00/etohsJg1R9DTilw f6dg== X-Gm-Message-State: AFqh2kqgbQhzRN/yrJIpq6reB+oz7Rb91R2C0fdc08jhMw0pdWupApms NkrhW/R/ES2pa4EvsqdvaUNzlpcVTsdM1LIZF2I= X-Google-Smtp-Source: AMrXdXvTA8vLw/AgFJrzMvLYp1nTaUc+EyP9VkgEGvTgWnHV/UHQWivhWRlU9ptlT6jBPzXF6IfLVw== X-Received: by 2002:a05:6402:25c6:b0:478:5688:7c9f with SMTP id x6-20020a05640225c600b0047856887c9fmr11440513edb.29.1671746174701; Thu, 22 Dec 2022 13:56:14 -0800 (PST) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id g24-20020a50ec18000000b0046b847d6a1csm792523edr.21.2022.12.22.13.56.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 22 Dec 2022 13:56:14 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Andrew Jeffery , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Igor Mitsyanko , Joel Stanley , Havard Skinnemoen , Peter Maydell , "Edgar E. Iglesias" , =?utf-8?q?C=C3=A9dric_Le_Go?= =?utf-8?q?ater?= , Alistair Francis , qemu-arm@nongnu.org, Tyrone Ting Subject: [PATCH 2/6] hw/arm/raspi: Fix smpboot[] on big-endian hosts Date: Thu, 22 Dec 2022 22:55:45 +0100 Message-Id: <20221222215549.86872-3-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221222215549.86872-1-philmd@linaro.org> References: <20221222215549.86872-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::532; envelope-from=philmd@linaro.org; helo=mail-ed1-x532.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org ARM CPUs fetch instructions in little-endian. smpboot[] encoded instructions are written in little-endian. This is fine on little-endian host, but on big-endian ones the smpboot[] array ends swapped. Use the const_le32() macro so the instructions are always in little-endian in the smpboot[] array. Fixes: 1df7d1f930 ("raspi: add raspberry pi 2 machine") Signed-off-by: Philippe Mathieu-Daudé --- hw/arm/raspi.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index 92d068d1f9..72572a45c2 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -125,18 +125,18 @@ static const char *board_type(uint32_t board_rev) static void write_smpboot(ARMCPU *cpu, const struct arm_boot_info *info) { static const uint32_t smpboot[] = { - 0xe1a0e00f, /* mov lr, pc */ - 0xe3a0fe00 + (BOARDSETUP_ADDR >> 4), /* mov pc, BOARDSETUP_ADDR */ - 0xee100fb0, /* mrc p15, 0, r0, c0, c0, 5;get core ID */ - 0xe7e10050, /* ubfx r0, r0, #0, #2 ;extract LSB */ - 0xe59f5014, /* ldr r5, =0x400000CC ;load mbox base */ - 0xe320f001, /* 1: yield */ - 0xe7953200, /* ldr r3, [r5, r0, lsl #4] ;read mbox for our core*/ - 0xe3530000, /* cmp r3, #0 ;spin while zero */ - 0x0afffffb, /* beq 1b */ - 0xe7853200, /* str r3, [r5, r0, lsl #4] ;clear mbox */ - 0xe12fff13, /* bx r3 ;jump to target */ - 0x400000cc, /* (constant: mailbox 3 read/clear base) */ + const_le32(0xe1a0e00f), /* mov lr, pc */ + const_le32(0xe3a0fe00 + (BOARDSETUP_ADDR >> 4)), /* mov pc, BOARDSETUP_ADDR */ + const_le32(0xee100fb0), /* mrc p15, 0, r0, c0, c0, 5;get core ID */ + const_le32(0xe7e10050), /* ubfx r0, r0, #0, #2 ;extract LSB */ + const_le32(0xe59f5014), /* ldr r5, =0x400000CC ;load mbox base */ + const_le32(0xe320f001), /* 1: yield */ + const_le32(0xe7953200), /* ldr r3, [r5, r0, lsl #4] ;read mbox for our core*/ + const_le32(0xe3530000), /* cmp r3, #0 ;spin while zero */ + const_le32(0x0afffffb), /* beq 1b */ + const_le32(0xe7853200), /* str r3, [r5, r0, lsl #4] ;clear mbox */ + const_le32(0xe12fff13), /* bx r3 ;jump to target */ + const_le32(0x400000cc), /* (constant: mailbox 3 read/clear base) */ }; /* check that we don't overrun board setup vectors */ @@ -162,17 +162,17 @@ static void write_smpboot64(ARMCPU *cpu, const struct arm_boot_info *info) * a rom blob, so that the reset for ROM contents zeroes them for us. */ static const uint32_t smpboot[] = { - 0xd2801b05, /* mov x5, 0xd8 */ - 0xd53800a6, /* mrs x6, mpidr_el1 */ - 0x924004c6, /* and x6, x6, #0x3 */ - 0xd503205f, /* spin: wfe */ - 0xf86678a4, /* ldr x4, [x5,x6,lsl #3] */ - 0xb4ffffc4, /* cbz x4, spin */ - 0xd2800000, /* mov x0, #0x0 */ - 0xd2800001, /* mov x1, #0x0 */ - 0xd2800002, /* mov x2, #0x0 */ - 0xd2800003, /* mov x3, #0x0 */ - 0xd61f0080, /* br x4 */ + const_le32(0xd2801b05), /* mov x5, 0xd8 */ + const_le32(0xd53800a6), /* mrs x6, mpidr_el1 */ + const_le32(0x924004c6), /* and x6, x6, #0x3 */ + const_le32(0xd503205f), /* spin: wfe */ + const_le32(0xf86678a4), /* ldr x4, [x5,x6,lsl #3] */ + const_le32(0xb4ffffc4), /* cbz x4, spin */ + const_le32(0xd2800000), /* mov x0, #0x0 */ + const_le32(0xd2800001), /* mov x1, #0x0 */ + const_le32(0xd2800002), /* mov x2, #0x0 */ + const_le32(0xd2800003), /* mov x3, #0x0 */ + const_le32(0xd61f0080), /* br x4 */ }; static const uint64_t spintables[] = { From patchwork Thu Dec 22 21:55:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13080340 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 181D1C4332F for ; Thu, 22 Dec 2022 21:56:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p8TYB-00063b-4V; Thu, 22 Dec 2022 16:56:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p8TY9-00062T-HU for qemu-devel@nongnu.org; Thu, 22 Dec 2022 16:56:25 -0500 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p8TY7-0007AX-Tb for qemu-devel@nongnu.org; Thu, 22 Dec 2022 16:56:25 -0500 Received: by mail-ed1-x52a.google.com with SMTP id d14so4727089edj.11 for ; Thu, 22 Dec 2022 13:56:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XrBY8xhhloPHHStYYTzLZIUBphfWCL1Sr3LvXL9Y2+E=; b=vZZzVd2GmPjInNPlJIQ7HLDrLVkDwzvBoAawnQ3s64Se3LU/32AzmhOvbDfL/oUoQG jrzmdjznaxldhfv2Eiv60h3JKNPCkLEivxWEpFR3eUj+3+0IFgc6c1qWveXW51sqJIf6 muL5K9YYLzKof4V+nUeLeqGRYmPGS9unr70lZLWPbKmiQQ1FNWVeUF8xrMLukjz4s3wG lM4RxS/ydo+esz3Se40mIhj0g+hI9HomJbp0X5ewuY8dDcsAJQfBfv3Kmd19cgnEnDaq 8XhqdDlRYuR+rQ5LzRSTbDMhJmOFCPiC1axyOXliDhH9jNX5cq3FYtQklxrH2nXkfjV8 ARVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XrBY8xhhloPHHStYYTzLZIUBphfWCL1Sr3LvXL9Y2+E=; b=J+o9USfXg5waRPVYdARA7Lt8oIi/GIk7Vo/Kdox3jKf9CyBsXM1xVxTxDQvELhebAC WkWj9XB71fZZHAEuBiJZ4x8J6Q76Ufc1mmVlsq4WkYKy1c//xw6Pg3sySmN6KlFaTFdX yPdAu26L6O+rEagCGBqO6Yfcj8RgLn5PMX+/pqaP9x+FUdxdNtnHP4uxzutZU9Uz1unH Tmmttf6ObkkHPccTwZwtTWXvs0XZvug2OSWIogq8EMG1gd4FyOcrVGUgOjObTe1D7V/v fVVVMaL7Zr+nao9kxERnNYvwnNQvsybrcrtLei0HUUmIrwxwwKgtK6iRTcbiHD/84EvP d2MA== X-Gm-Message-State: AFqh2koA7pCiYGmFiQSf6++47+6Lrbsj6s6x/PScNnmt75uEhINwKe24 tcdyI+72KjKFjXOzw2iqAYpDFFHInsfDn3zCr80= X-Google-Smtp-Source: AMrXdXvJWZGKtgF0u8IpdXQ57xPzM/UvjNEFZBGsVuVZ+HieahWzQ7cKHXxf2anpT90WjkVOXAWlEQ== X-Received: by 2002:a05:6402:1cce:b0:472:1b3b:35f1 with SMTP id ds14-20020a0564021cce00b004721b3b35f1mr7556762edb.21.1671746182342; Thu, 22 Dec 2022 13:56:22 -0800 (PST) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id k6-20020aa7d2c6000000b00467c3cbab6fsm791917edr.77.2022.12.22.13.56.19 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 22 Dec 2022 13:56:21 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Andrew Jeffery , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Igor Mitsyanko , Joel Stanley , Havard Skinnemoen , Peter Maydell , "Edgar E. Iglesias" , =?utf-8?q?C=C3=A9dric_Le_Go?= =?utf-8?q?ater?= , Alistair Francis , qemu-arm@nongnu.org, Tyrone Ting Subject: [PATCH 3/6] hw/arm/exynos4210: Remove tswap32() calls and constify smpboot[] Date: Thu, 22 Dec 2022 22:55:46 +0100 Message-Id: <20221222215549.86872-4-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221222215549.86872-1-philmd@linaro.org> References: <20221222215549.86872-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52a; envelope-from=philmd@linaro.org; helo=mail-ed1-x52a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org ARM CPUs fetch instructions in little-endian. smpboot[] encoded instructions are written in little-endian. We call tswap32() on the array. tswap32 function swap a 32-bit value if the target endianness doesn't match the host one. Otherwise it is a NOP. * On a little-endian host, the array is stored as it. tswap32() is a NOP, and the vCPU fetches the instructions as it, in little-endian. * On a big-endian host, the array is stored as it. tswap32() swap the instructions to little-endian, and the vCPU fetches the instructions as it, in little-endian. Using tswap() on system emulation is a bit odd: while the target particularities might change the system emulation, the host ones (such its endianness) shouldn't interfere. We can simplify by using const_le32() to always store the instructions in the array in little-endian, removing the need for the dubious tswap(). Signed-off-by: Philippe Mathieu-Daudé --- hw/arm/exynos4210.c | 48 ++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/hw/arm/exynos4210.c b/hw/arm/exynos4210.c index 8dafa2215b..89ee83456d 100644 --- a/hw/arm/exynos4210.c +++ b/hw/arm/exynos4210.c @@ -468,35 +468,29 @@ static const MemoryRegionOps exynos4210_chipid_and_omr_ops = { } }; -void exynos4210_write_secondary(ARMCPU *cpu, - const struct arm_boot_info *info) +void exynos4210_write_secondary(ARMCPU *cpu, const struct arm_boot_info *info) { - int n; - uint32_t smpboot[] = { - 0xe59f3034, /* ldr r3, External gic_cpu_if */ - 0xe59f2034, /* ldr r2, Internal gic_cpu_if */ - 0xe59f0034, /* ldr r0, startaddr */ - 0xe3a01001, /* mov r1, #1 */ - 0xe5821000, /* str r1, [r2] */ - 0xe5831000, /* str r1, [r3] */ - 0xe3a010ff, /* mov r1, #0xff */ - 0xe5821004, /* str r1, [r2, #4] */ - 0xe5831004, /* str r1, [r3, #4] */ - 0xf57ff04f, /* dsb */ - 0xe320f003, /* wfi */ - 0xe5901000, /* ldr r1, [r0] */ - 0xe1110001, /* tst r1, r1 */ - 0x0afffffb, /* beq */ - 0xe12fff11, /* bx r1 */ - EXYNOS4210_EXT_GIC_CPU_BASE_ADDR, - 0, /* gic_cpu_if: base address of Internal GIC CPU interface */ - 0 /* bootreg: Boot register address is held here */ + const uint32_t smpboot[] = { + const_le32(0xe59f3034), /* ldr r3, External gic_cpu_if */ + const_le32(0xe59f2034), /* ldr r2, Internal gic_cpu_if */ + const_le32(0xe59f0034), /* ldr r0, startaddr */ + const_le32(0xe3a01001), /* mov r1, #1 */ + const_le32(0xe5821000), /* str r1, [r2] */ + const_le32(0xe5831000), /* str r1, [r3] */ + const_le32(0xe3a010ff), /* mov r1, #0xff */ + const_le32(0xe5821004), /* str r1, [r2, #4] */ + const_le32(0xe5831004), /* str r1, [r3, #4] */ + const_le32(0xf57ff04f), /* dsb */ + const_le32(0xe320f003), /* wfi */ + const_le32(0xe5901000), /* ldr r1, [r0] */ + const_le32(0xe1110001), /* tst r1, r1 */ + const_le32(0x0afffffb), /* beq */ + const_le32(0xe12fff11), /* bx r1 */ + const_le32(EXYNOS4210_EXT_GIC_CPU_BASE_ADDR), + cpu_to_le32(info->gic_cpu_if_addr), /* base address of Internal GIC CPU interface */ + cpu_to_le32(info->smp_bootreg_addr) /* Boot register address is held here */ }; - smpboot[ARRAY_SIZE(smpboot) - 1] = info->smp_bootreg_addr; - smpboot[ARRAY_SIZE(smpboot) - 2] = info->gic_cpu_if_addr; - for (n = 0; n < ARRAY_SIZE(smpboot); n++) { - smpboot[n] = tswap32(smpboot[n]); - } + rom_add_blob_fixed("smpboot", smpboot, sizeof(smpboot), info->smp_loader_start); } From patchwork Thu Dec 22 21:55:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13080344 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 98BFDC4332F for ; Thu, 22 Dec 2022 21:58:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p8TYQ-0006GU-3w; Thu, 22 Dec 2022 16:56:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p8TYO-0006Eu-Mg for qemu-devel@nongnu.org; Thu, 22 Dec 2022 16:56:40 -0500 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p8TYM-0007BZ-UK for qemu-devel@nongnu.org; Thu, 22 Dec 2022 16:56:40 -0500 Received: by mail-ej1-x629.google.com with SMTP id x22so7916808ejs.11 for ; Thu, 22 Dec 2022 13:56:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tY6SKki/uWVAIv0MsBbw55az0oWSvt0PY3G9FmsSaas=; b=dL2p6foofY2Hh8ZXBKcxBNbv/lgbNEFe5cLgSUrKSUL+jWtf1wanV1AMKwCRFciuJa xIooGOS3YkjLkhuit47Mn5MbWS5t3Gducg7evlcKxWBkrhN76QWacmDIZmIlLXYvm7qx SyxOTaumiunB9eCKnaAkO+jHD5r7UQRRkrmFxgpDS3cBCebveK5sjIgtkk7iJtW3roKl T2J5nZh9xPTzhnyW/q2vQfs/lqb4A91T00B/8JIRDmVo8Ya365bwU/dN4Zt5lO8hlUMj 0dM3DrIkHCTqCds2lywM8cCGc50ct5xYEz2qOCErERNvUR4Z8YAW/UIIhwl7QMSskyM8 thCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tY6SKki/uWVAIv0MsBbw55az0oWSvt0PY3G9FmsSaas=; b=EL1xUyHVHGV/qwbMgBP8JOxaHBx3ufRqG16drb/6yzzuOEOMtifRVkaPtFTZgqTfXb aAEAPb3vzJJp6GkpG7JONIDkkHBYYARj/Kn1n2Vdmjm36fJwwZ5Tk7f/p6DpZ3JNAe4R fp3lFJqsJhXPQZBzb7Hv5D95Iak0wsXevrmr1pJ5PsZNRHsvT+5tjw6QGPVomNQLkHK/ vMGIIpyC6jCLrZpMuIQFrfptOHzYZv4vDxngRxfmbC3CT9QBgQUoiylNfmptJ6UZqIit Yr+dnRepdNeK7hqzYqSUuLyD1C1SYEgv2k8nPjcg7TW/hnhMh4yLQGPkYQYXHC6vbmtM 74mw== X-Gm-Message-State: AFqh2krmGFTM1p4jfWFUeEC8y6ef9ifA/cfy5Nl0zQd+oqFiUQ0tVA2Z chGkwuUX+ErAILaj4zCj3nEaMVo+94R6UebeTUQ= X-Google-Smtp-Source: AMrXdXtHMU7gQ8Ru7YY8/bkUVTK46FlRiW6635DDWvaACMvDiMLjDtB//vZufnjG6WdCU78F4x66CQ== X-Received: by 2002:a17:907:9a98:b0:7c1:d4c:f08c with SMTP id km24-20020a1709079a9800b007c10d4cf08cmr5506851ejc.4.1671746197418; Thu, 22 Dec 2022 13:56:37 -0800 (PST) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id v6-20020a1709062f0600b007933047f923sm646867eji.118.2022.12.22.13.56.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 22 Dec 2022 13:56:37 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Andrew Jeffery , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Igor Mitsyanko , Joel Stanley , Havard Skinnemoen , Peter Maydell , "Edgar E. Iglesias" , =?utf-8?q?C=C3=A9dric_Le_Go?= =?utf-8?q?ater?= , Alistair Francis , qemu-arm@nongnu.org, Tyrone Ting Subject: [PATCH 4/6] hw/arm/npcm7xx: Remove tswap32() calls and constify smpboot[] Date: Thu, 22 Dec 2022 22:55:47 +0100 Message-Id: <20221222215549.86872-5-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221222215549.86872-1-philmd@linaro.org> References: <20221222215549.86872-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=philmd@linaro.org; helo=mail-ej1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org ARM CPUs fetch instructions in little-endian. smpboot[] encoded instructions are written in little-endian. We call tswap32() on the array. tswap32 function swap a 32-bit value if the target endianness doesn't match the host one. Otherwise it is a NOP. * On a little-endian host, the array is stored as it. tswap32() is a NOP, and the vCPU fetches the instructions as it, in little-endian. * On a big-endian host, the array is stored as it. tswap32() swap the instructions to little-endian, and the vCPU fetches the instructions as it, in little-endian. Using tswap() on system emulation is a bit odd: while the target particularities might change the system emulation, the host ones (such its endianness) shouldn't interfere. We can simplify by using const_le32() to always store the instructions in the array in little-endian, removing the need for the dubious tswap(). Signed-off-by: Philippe Mathieu-Daudé --- Note there is still a tswap() call in npcm7xx_init_fuses() --- hw/arm/npcm7xx.c | 49 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c index d85cc02765..2976192731 100644 --- a/hw/arm/npcm7xx.c +++ b/hw/arm/npcm7xx.c @@ -291,22 +291,18 @@ static const struct { static void npcm7xx_write_board_setup(ARMCPU *cpu, const struct arm_boot_info *info) { - uint32_t board_setup[] = { - 0xe59f0010, /* ldr r0, clk_base_addr */ - 0xe59f1010, /* ldr r1, pllcon1_value */ - 0xe5801010, /* str r1, [r0, #16] */ - 0xe59f100c, /* ldr r1, clksel_value */ - 0xe5801004, /* str r1, [r0, #4] */ - 0xe12fff1e, /* bx lr */ - NPCM7XX_CLK_BA, - NPCM7XX_PLLCON1_FIXUP_VAL, - NPCM7XX_CLKSEL_FIXUP_VAL, + static const uint32_t board_setup[] = { + const_le32(0xe59f0010), /* ldr r0, clk_base_addr */ + const_le32(0xe59f1010), /* ldr r1, pllcon1_value */ + const_le32(0xe5801010), /* str r1, [r0, #16] */ + const_le32(0xe59f100c), /* ldr r1, clksel_value */ + const_le32(0xe5801004), /* str r1, [r0, #4] */ + const_le32(0xe12fff1e), /* bx lr */ + const_le32(NPCM7XX_CLK_BA), + const_le32(NPCM7XX_PLLCON1_FIXUP_VAL), + const_le32(NPCM7XX_CLKSEL_FIXUP_VAL), }; - int i; - for (i = 0; i < ARRAY_SIZE(board_setup); i++) { - board_setup[i] = tswap32(board_setup[i]); - } rom_add_blob_fixed("board-setup", board_setup, sizeof(board_setup), info->board_setup_addr); } @@ -321,22 +317,17 @@ static void npcm7xx_write_secondary_boot(ARMCPU *cpu, * we need to provide our own smpboot stub that can not use 'wfi', it has * to spin the secondary CPU until the first CPU writes to the SCRPAD reg. */ - uint32_t smpboot[] = { - 0xe59f2018, /* ldr r2, bootreg_addr */ - 0xe3a00000, /* mov r0, #0 */ - 0xe5820000, /* str r0, [r2] */ - 0xe320f002, /* wfe */ - 0xe5921000, /* ldr r1, [r2] */ - 0xe1110001, /* tst r1, r1 */ - 0x0afffffb, /* beq */ - 0xe12fff11, /* bx r1 */ - NPCM7XX_SMP_BOOTREG_ADDR, + static const uint32_t smpboot[] = { + const_le32(0xe59f2018), /* ldr r2, bootreg_addr */ + const_le32(0xe3a00000), /* mov r0, #0 */ + const_le32(0xe5820000), /* str r0, [r2] */ + const_le32(0xe320f002), /* wfe */ + const_le32(0xe5921000), /* ldr r1, [r2] */ + const_le32(0xe1110001), /* tst r1, r1 */ + const_le32(0x0afffffb), /* beq */ + const_le32(0xe12fff11), /* bx r1 */ + const_le32(NPCM7XX_SMP_BOOTREG_ADDR), }; - int i; - - for (i = 0; i < ARRAY_SIZE(smpboot); i++) { - smpboot[i] = tswap32(smpboot[i]); - } rom_add_blob_fixed("smpboot", smpboot, sizeof(smpboot), NPCM7XX_SMP_LOADER_START); From patchwork Thu Dec 22 21:55:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13080341 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AA568C4332F for ; Thu, 22 Dec 2022 21:57:56 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p8TYZ-0006JV-QK; Thu, 22 Dec 2022 16:56:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p8TYY-0006J8-J0 for qemu-devel@nongnu.org; Thu, 22 Dec 2022 16:56:50 -0500 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p8TYW-0007BZ-VC for qemu-devel@nongnu.org; Thu, 22 Dec 2022 16:56:50 -0500 Received: by mail-ej1-x629.google.com with SMTP id x22so7917543ejs.11 for ; Thu, 22 Dec 2022 13:56:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eJ7KNsaeAIcuwibRTmPK9N9xgsftdW4nEKhohT2Tqnw=; b=iEJLpHzxwaMTP58pZ88b0id+U1wBqsANL8xy71bWCVFNFM5kcDG3ZdVXfazrcPtyX/ ixcgwz+TC0oP0uRW97t/ytQ+1XJdlDOFCwuC/hjbSiIu/IMX9NUMtXef0b+/rjzN6iaG wsFz61/5/GT/yfanAI+qySmtDVLSMasDNPux5GBjDmQ3RamY1zvRJ5gDjKuoEN8BaIGg /hqnFlGpvU+xN5E/MOOZj0aavFIXbWtp9CcjTT5txDXZp+mVNxK/cIYN0FXI4s3UDx6s lX32iIwQD3rrfo/yVo0IAAOTWfhwD8XXnC5Rc1ZGXNyIEFKN+xvaZwWcLT4b85wIxC/F cJkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eJ7KNsaeAIcuwibRTmPK9N9xgsftdW4nEKhohT2Tqnw=; b=NeqxxRzBShtfHObof87ByPCK3YWDPijfjyHkBycWXy+apEFzqvW++THhJJRiQVbZSl TPscShFagaZpaGmHkvCJ71JtgpKWDbif5VZiqJXyOUCOgcqp1BZk68OVrWNpGuqaMrMe LG/od5dX5wJ9pF9d+xAg/lgNTTQbdU5IU7H4NdGG8mCemweh+n2UyK5cJt6pmHAMqV8w jpQTVMyp95MvxLj8UCTSfbsgxw4QJHlqnQMWSJcUXlQPR5uCdwhYiSFik/mTGeDnxxm5 tHT/y1FhPVpz4nki3oqUO2IaHWLSth1sEag++OZUl3d2EhrPndkdD++XeB9cCteUXgyx FtGw== X-Gm-Message-State: AFqh2kpaa8VjsXpqPnO/j5SIZLkNsJv+6ar7uRqJR+qxycxFgCHD8q+g A2jvZpbHKpyeZNGoa2s0Ps5v2gbDWYIzW0MLE6M= X-Google-Smtp-Source: AMrXdXtuss5o08KxNpb5nby1BGvCG90E3B43FCMc4TXwkj2/xqgItww1hPCW2i/2MjMOMUbEN/UOxw== X-Received: by 2002:a17:907:c28f:b0:7c1:eb:b2a7 with SMTP id tk15-20020a170907c28f00b007c100ebb2a7mr9430560ejc.13.1671746208107; Thu, 22 Dec 2022 13:56:48 -0800 (PST) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id s22-20020aa7cb16000000b00457b5ba968csm788692edt.27.2022.12.22.13.56.45 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 22 Dec 2022 13:56:47 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Andrew Jeffery , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Igor Mitsyanko , Joel Stanley , Havard Skinnemoen , Peter Maydell , "Edgar E. Iglesias" , =?utf-8?q?C=C3=A9dric_Le_Go?= =?utf-8?q?ater?= , Alistair Francis , qemu-arm@nongnu.org, Tyrone Ting Subject: [PATCH 5/6] hw/arm/xilinx_zynq: Remove tswap32() calls and constify smpboot[] Date: Thu, 22 Dec 2022 22:55:48 +0100 Message-Id: <20221222215549.86872-6-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221222215549.86872-1-philmd@linaro.org> References: <20221222215549.86872-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=philmd@linaro.org; helo=mail-ej1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org ARM CPUs fetch instructions in little-endian. smpboot[] encoded instructions are written in little-endian. We call tswap32() on the array. tswap32 function swap a 32-bit value if the target endianness doesn't match the host one. Otherwise it is a NOP. * On a little-endian host, the array is stored as it. tswap32() is a NOP, and the vCPU fetches the instructions as it, in little-endian. * On a big-endian host, the array is stored as it. tswap32() swap the instructions to little-endian, and the vCPU fetches the instructions as it, in little-endian. Using tswap() on system emulation is a bit odd: while the target particularities might change the system emulation, the host ones (such its endianness) shouldn't interfere. We can simplify by using const_le32() to always store the instructions in the array in little-endian, removing the need for the dubious tswap(). Signed-off-by: Philippe Mathieu-Daudé --- hw/arm/xilinx_zynq.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/hw/arm/xilinx_zynq.c b/hw/arm/xilinx_zynq.c index 3190cc0b8d..4316143b71 100644 --- a/hw/arm/xilinx_zynq.c +++ b/hw/arm/xilinx_zynq.c @@ -71,6 +71,11 @@ static const int dma_irqs[8] = { #define ZYNQ_SDHCI_CAPABILITIES 0x69ec0080 /* Datasheet: UG585 (v1.12.1) */ +struct ZynqMachineState { + MachineState parent; + Clock *ps_clk; +}; + #define ARMV7_IMM16(x) (extract32((x), 0, 12) | \ extract32((x), 12, 4) << 16) @@ -79,29 +84,21 @@ static const int dma_irqs[8] = { */ #define SLCR_WRITE(addr, val) \ - 0xe3001000 + ARMV7_IMM16(extract32((val), 0, 16)), /* movw r1 ... */ \ - 0xe3401000 + ARMV7_IMM16(extract32((val), 16, 16)), /* movt r1 ... */ \ - 0xe5801000 + (addr) - -struct ZynqMachineState { - MachineState parent; - Clock *ps_clk; -}; + cpu_to_le32(0xe3001000 + ARMV7_IMM16(extract32((val), 0, 16))), /* movw r1 ... */ \ + cpu_to_le32(0xe3401000 + ARMV7_IMM16(extract32((val), 16, 16))), /* movt r1 ... */ \ + const_le32(0xe5801000 + (addr)) static void zynq_write_board_setup(ARMCPU *cpu, const struct arm_boot_info *info) { - int n; - uint32_t board_setup_blob[] = { - 0xe3a004f8, /* mov r0, #0xf8000000 */ + const uint32_t board_setup_blob[] = { + const_le32(0xe3a004f8), /* mov r0, #0xf8000000 */ SLCR_WRITE(SLCR_UNLOCK_OFFSET, SLCR_XILINX_UNLOCK_KEY), SLCR_WRITE(SLCR_ARM_PLL_OFFSET, 0x00014008), SLCR_WRITE(SLCR_LOCK_OFFSET, SLCR_XILINX_LOCK_KEY), - 0xe12fff1e, /* bx lr */ + const_le32(0xe12fff1e) /* bx lr */ }; - for (n = 0; n < ARRAY_SIZE(board_setup_blob); n++) { - board_setup_blob[n] = tswap32(board_setup_blob[n]); - } + rom_add_blob_fixed("board-setup", board_setup_blob, sizeof(board_setup_blob), BOARD_SETUP_ADDR); } From patchwork Thu Dec 22 21:55:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 13080343 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 42F91C4332F for ; Thu, 22 Dec 2022 21:58:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p8TYm-0006VT-Ei; Thu, 22 Dec 2022 16:57:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p8TYk-0006Un-Mb for qemu-devel@nongnu.org; Thu, 22 Dec 2022 16:57:02 -0500 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p8TYh-0007EH-UN for qemu-devel@nongnu.org; Thu, 22 Dec 2022 16:57:02 -0500 Received: by mail-ed1-x536.google.com with SMTP id d20so4822554edn.0 for ; Thu, 22 Dec 2022 13:56:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oaCMViCuj4W9XyEnm5VQb8sPut9cn3g3RlnYgzpwXls=; b=b63W81rKmo4/ZnXugf6jX8/2b0n871C2CAv6YBF7wVsUO+p0rhxKUe3xLhiobUCKbk 4fJPeXp7s0bM5I0J5UR03+whgmV/+06B7XinRm6gmT2JTtGVt67SnbecTEKjvv8JzVQ4 PwJbBgk45AJ7195pPg2J7xIJRYMa78j63MyH4J3QMmjyKFyz9eC+HKROHiJCV06v/4T8 9+EtVUPRf46b0PeHSLluzF7d5eHcykEuZYLZct4vgBv1+wRjhUw2znsi+qlXTEqMzCTI FR1IueVwJpCIAnPbgX13TIlrmFDFHbI0mq/Q3SZYgHWJowpxIh606AUPbFDrMPzg4BSv mAGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oaCMViCuj4W9XyEnm5VQb8sPut9cn3g3RlnYgzpwXls=; b=0AUVjJQT5xsuwUcBFupxc2gL2BN69pOUvmEKpRi8rvrkYrdhEt6P8GHqDXl48ITwag V1eqcyxMSAVaiR3XLsCTJneGx764e5So0OpnUh6turuLgj8URt9lzw7DTwiRW8+RY6cc VH9UGHjVOMv+7hY8uKLAIzCd9r7YIXbuKAyKP1abcqhhJheDtrtL63yOYlCAtQNRjBSA GcJR82Bpeg9zieXfiuCATCCwpDjIR8zyRtPiZVdcgEyf4uuc+50iuBJT59el229n7Y9y pNoXKGMqD82UIE+6KWM9s3LCrxyrKTZiEJl7x5zBfWulkyCCqhy0ZDzinKrqn7VMi+YC oT1g== X-Gm-Message-State: AFqh2kr4TT/qpBulNCPCpH+4ITHwARWJelOMRdC87wHfjrZGcslbj8U+ chF0UnH7nZInLENVOvkeupcfVvUjFqxFqz7VoKg= X-Google-Smtp-Source: AMrXdXvUDSJYD7cxIJogQUH51O3kMECLUfAK4IN5Oq9qfUJCj7/C8Txk6DJtHnnM1TfKyAyT4tW/EQ== X-Received: by 2002:a05:6402:4141:b0:461:8be6:1ac4 with SMTP id x1-20020a056402414100b004618be61ac4mr6322707eda.20.1671746218073; Thu, 22 Dec 2022 13:56:58 -0800 (PST) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id b15-20020aa7c90f000000b0046aa78ecd8asm803616edt.3.2022.12.22.13.56.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 22 Dec 2022 13:56:57 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Andrew Jeffery , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Igor Mitsyanko , Joel Stanley , Havard Skinnemoen , Peter Maydell , "Edgar E. Iglesias" , =?utf-8?q?C=C3=A9dric_Le_Go?= =?utf-8?q?ater?= , Alistair Francis , qemu-arm@nongnu.org, Tyrone Ting Subject: [PATCH 6/6] hw/arm/boot: Remove tswap32() calls and constify board_setup_blob[] Date: Thu, 22 Dec 2022 22:55:49 +0100 Message-Id: <20221222215549.86872-7-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221222215549.86872-1-philmd@linaro.org> References: <20221222215549.86872-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::536; envelope-from=philmd@linaro.org; helo=mail-ed1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org ARM CPUs fetch instructions in little-endian. board_setup_blob[] encoded instructions are written in little-endian. We call tswap32() on the array. tswap32 function swap a 32-bit value if the target endianness doesn't match the host one. Otherwise it is a NOP. * On a little-endian host, the array is stored as it. tswap32() is a NOP, and the vCPU fetches the instructions as it, in little-endian. * On a big-endian host, the array is stored as it. tswap32() swap the instructions to little-endian, and the vCPU fetches the instructions as it, in little-endian. Using tswap() on system emulation is a bit odd: while the target particularities might change the system emulation, the host ones (such its endianness) shouldn't interfere. We can simplify by using const_le32() to always store the instructions in the array in little-endian, removing the need for the dubious tswap(). Signed-off-by: Philippe Mathieu-Daudé --- hw/arm/boot.c | 52 ++++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 3d7d11f782..22a100f19b 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -189,7 +189,7 @@ static void write_bootloader(const char *name, hwaddr addr, default: abort(); } - code[i] = tswap32(insn); + code[i] = cpu_to_le32(insn); } assert((len * sizeof(uint32_t)) < BOOTLOADER_MAX_SIZE); @@ -222,34 +222,33 @@ void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu, hwaddr mvbar_addr) { AddressSpace *as = arm_boot_address_space(cpu, info); - int n; - uint32_t mvbar_blob[] = { + static const uint32_t mvbar_blob[] = { /* mvbar_addr: secure monitor vectors * Default unimplemented and unused vectors to spin. Makes it * easier to debug (as opposed to the CPU running away). */ - 0xeafffffe, /* (spin) */ - 0xeafffffe, /* (spin) */ - 0xe1b0f00e, /* movs pc, lr ;SMC exception return */ - 0xeafffffe, /* (spin) */ - 0xeafffffe, /* (spin) */ - 0xeafffffe, /* (spin) */ - 0xeafffffe, /* (spin) */ - 0xeafffffe, /* (spin) */ + const_le32(0xeafffffe), /* (spin) */ + const_le32(0xeafffffe), /* (spin) */ + const_le32(0xe1b0f00e), /* movs pc, lr ;SMC exception return */ + const_le32(0xeafffffe), /* (spin) */ + const_le32(0xeafffffe), /* (spin) */ + const_le32(0xeafffffe), /* (spin) */ + const_le32(0xeafffffe), /* (spin) */ + const_le32(0xeafffffe) /* (spin) */ }; - uint32_t board_setup_blob[] = { + const uint32_t board_setup_blob[] = { /* board setup addr */ - 0xee110f51, /* mrc p15, 0, r0, c1, c1, 2 ;read NSACR */ - 0xe3800b03, /* orr r0, #0xc00 ;set CP11, CP10 */ - 0xee010f51, /* mcr p15, 0, r0, c1, c1, 2 ;write NSACR */ - 0xe3a00e00 + (mvbar_addr >> 4), /* mov r0, #mvbar_addr */ - 0xee0c0f30, /* mcr p15, 0, r0, c12, c0, 1 ;set MVBAR */ - 0xee110f11, /* mrc p15, 0, r0, c1 , c1, 0 ;read SCR */ - 0xe3800031, /* orr r0, #0x31 ;enable AW, FW, NS */ - 0xee010f11, /* mcr p15, 0, r0, c1, c1, 0 ;write SCR */ - 0xe1a0100e, /* mov r1, lr ;save LR across SMC */ - 0xe1600070, /* smc #0 ;call monitor to flush SCR */ - 0xe1a0f001, /* mov pc, r1 ;return */ + const_le32(0xee110f51), /* mrc p15, 0, r0, c1, c1, 2 ;read NSACR */ + const_le32(0xe3800b03), /* orr r0, #0xc00 ;set CP11, CP10 */ + const_le32(0xee010f51), /* mcr p15, 0, r0, c1, c1, 2 ;write NSACR */ + const_le32(0xe3a00e00 + (mvbar_addr >> 4)), /* mov r0, #mvbar_addr */ + const_le32(0xee0c0f30), /* mcr p15, 0, r0, c12, c0, 1 ;set MVBAR */ + const_le32(0xee110f11), /* mrc p15, 0, r0, c1 , c1, 0 ;read SCR */ + const_le32(0xe3800031), /* orr r0, #0x31 ;enable AW, FW, NS */ + const_le32(0xee010f11), /* mcr p15, 0, r0, c1, c1, 0 ;write SCR */ + const_le32(0xe1a0100e), /* mov r1, lr ;save LR across SMC */ + const_le32(0xe1600070), /* smc #0 ;call monitor to flush SCR */ + const_le32(0xe1a0f001) /* mov pc, r1 ;return */ }; /* check that mvbar_addr is correctly aligned and relocatable (using MOV) */ @@ -259,15 +258,8 @@ void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu, assert((mvbar_addr + sizeof(mvbar_blob) <= info->board_setup_addr) || (info->board_setup_addr + sizeof(board_setup_blob) <= mvbar_addr)); - for (n = 0; n < ARRAY_SIZE(mvbar_blob); n++) { - mvbar_blob[n] = tswap32(mvbar_blob[n]); - } rom_add_blob_fixed_as("board-setup-mvbar", mvbar_blob, sizeof(mvbar_blob), mvbar_addr, as); - - for (n = 0; n < ARRAY_SIZE(board_setup_blob); n++) { - board_setup_blob[n] = tswap32(board_setup_blob[n]); - } rom_add_blob_fixed_as("board-setup", board_setup_blob, sizeof(board_setup_blob), info->board_setup_addr, as); }