From patchwork Mon Nov 13 13:28:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 10056025 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 627DC60215 for ; Mon, 13 Nov 2017 13:29:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 554792906B for ; Mon, 13 Nov 2017 13:29:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48A5D290CE; Mon, 13 Nov 2017 13:29:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 716082906B for ; Mon, 13 Nov 2017 13:29:53 +0000 (UTC) Received: from localhost ([::1]:54430 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEEoC-0003LQ-EJ for patchwork-qemu-devel@patchwork.kernel.org; Mon, 13 Nov 2017 08:29:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEEnK-0003J1-OP for qemu-devel@nongnu.org; Mon, 13 Nov 2017 08:28:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eEEnJ-0001Q7-FI for qemu-devel@nongnu.org; Mon, 13 Nov 2017 08:28:58 -0500 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:54758) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eEEnA-00017D-Rs; Mon, 13 Nov 2017 08:28:49 -0500 Received: by mail-pg0-x242.google.com with SMTP id c123so4640552pga.11; Mon, 13 Nov 2017 05:28:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=9fX1SLjVvUdQJw/fQCbFmQUHXDAbwO3bVianCvY/EnQ=; b=ST8HDhbRUpya6msOv3JQ9sMWSa8PHdw6bxCeMVbHLIaZB6Mx368ohbkpMt7jt3TrjQ hrc7XYn6mFb986Qi06slykZO+IHOqcpx45spnPHi9ipcFCDflF2Gu2wGoM+FRMSRRCqf GEycs3c5VlcB1GkAd6M8TP80c/taacZIOnutjdHdvxJRFLu5yAPsg+GXSYQpjQpcchR/ maR4XWhS+J761vYxFdobKvxkXqg1tih4bjdaz0cyxasPTvjGi1XyUe8RHmuHimAShfYz 6m0fpkM1Tnka5GWWQl+vtLck2yG8upMb0BWenkJDxjQB8PCAxyLsu/xYX/B5urZo6Tfr a+aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=9fX1SLjVvUdQJw/fQCbFmQUHXDAbwO3bVianCvY/EnQ=; b=tNxMJtBQIq+/KtEORUArKH1tfZ4o6jCoUPqeyKksPoSAwda9bpHpbSVEvya7sxiTc/ Hqi6vND4fwAlEam5io+kGcNLxYH3vUeGNkp8s23R8l7dAZLlidcvryt2KzxzXzHq8Ccf DMB1Yst/pYJyoGewf9VW8/sP7gAX1gaGPUsen2NoHvq6YISfzvJTrzIBnOlRuT4C5raQ l0bUVUZM64HKxvMW+t3HMciGNeI6ykEWSZp7ltEZP5ncPj+5vU+BCDaTk51h6HHvm24T 6Cw1jcmaUacSK3b5jW//qkC/BLGZ9abA7KQIL2rOqqYPBXhx2jUaI2FeDcTAgMjKv1jF 8zmA== X-Gm-Message-State: AJaThX4EXddq8fWCqnYBxMc+UYZY0wL59LhaO1CBUAJxb4px7vrjkEvC lUA2GtZ68xgKtMYz6q7zi1U= X-Google-Smtp-Source: AGs4zMbJ+nOKpLRGoujVfRo7WnrEQjR46H6J821KSHgwy+glm30fNvnNUT+2L6GcuIMFUbPKOEdfpA== X-Received: by 10.84.248.77 with SMTP id e13mr9117827pln.200.1510579727421; Mon, 13 Nov 2017 05:28:47 -0800 (PST) Received: from aurora.jms.id.au ([45.124.203.19]) by smtp.gmail.com with ESMTPSA id y5sm32541032pfk.3.2017.11.13.05.28.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 13 Nov 2017 05:28:45 -0800 (PST) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Mon, 13 Nov 2017 23:58:38 +1030 From: Joel Stanley To: Peter Maydell Date: Mon, 13 Nov 2017 23:58:01 +1030 Message-Id: <20171113132801.8562-1-joel@jms.id.au> X-Mailer: git-send-email 2.14.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::242 Subject: [Qemu-devel] [PATCH v2] hw/arm/aspeed: Unlock SCU when running kernel X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , qemu-arm@nongnu.org, qemu-devel@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The ASPEED hardware contains a lock register for the SCU that disables any writes to the SCU when it is locked. The machine comes up with the lock enabled, but on all known hardware u-boot will unlock it and leave it unlocked when loading the kernel. This means the kernel expects the SCU to be unlocked. When booting from an emulated ROM the normal u-boot unlock path is executed. Things don't go well when booting using the -kernel command line, as u-boot does not run first. Change behaviour so that when a kernel is passed to the machine, set the reset value of the SCU to be unlocked. Signed-off-by: Joel Stanley --- v2: - use the correct value for the key - rename it ASPEED_SCU_PROT_KEY --- hw/arm/aspeed.c | 10 ++++++++++ hw/arm/aspeed_soc.c | 2 ++ hw/misc/aspeed_scu.c | 5 +++-- include/hw/misc/aspeed_scu.h | 3 +++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c index ab895ad490af..754df8403273 100644 --- a/hw/arm/aspeed.c +++ b/hw/arm/aspeed.c @@ -36,6 +36,7 @@ typedef struct AspeedBoardState { typedef struct AspeedBoardConfig { const char *soc_name; uint32_t hw_strap1; + uint32_t hw_prot_key; const char *fmc_model; const char *spi_model; uint32_t num_cs; @@ -186,6 +187,15 @@ static void aspeed_board_init(MachineState *machine, &error_abort); object_property_set_int(OBJECT(&bmc->soc), cfg->num_cs, "num-cs", &error_abort); + if (machine->kernel_filename) { + /* + * When booting with a -kernel command line there is no u-boot + * that runs to unlock the SCU. In this case set the default to + * be unlocked as the kernel expects + */ + object_property_set_int(OBJECT(&bmc->soc), ASPEED_SCU_PROT_KEY, + "hw-prot-key", &error_abort); + } object_property_set_bool(OBJECT(&bmc->soc), true, "realized", &error_abort); diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c index 5aa3d2ddd9cd..c83b7e207b86 100644 --- a/hw/arm/aspeed_soc.c +++ b/hw/arm/aspeed_soc.c @@ -154,6 +154,8 @@ static void aspeed_soc_init(Object *obj) "hw-strap1", &error_abort); object_property_add_alias(obj, "hw-strap2", OBJECT(&s->scu), "hw-strap2", &error_abort); + object_property_add_alias(obj, "hw-prot-key", OBJECT(&s->scu), + "hw-prot-key", &error_abort); object_initialize(&s->fmc, sizeof(s->fmc), sc->info->fmc_typename); object_property_add_child(obj, "fmc", OBJECT(&s->fmc), NULL); diff --git a/hw/misc/aspeed_scu.c b/hw/misc/aspeed_scu.c index 95022d3607ad..74537ce9755d 100644 --- a/hw/misc/aspeed_scu.c +++ b/hw/misc/aspeed_scu.c @@ -85,7 +85,6 @@ #define BMC_REV TO_REG(0x19C) #define BMC_DEV_ID TO_REG(0x1A4) -#define PROT_KEY_UNLOCK 0x1688A8A8 #define SCU_IO_REGION_SIZE 0x1000 static const uint32_t ast2400_a0_resets[ASPEED_SCU_NR_REGS] = { @@ -192,7 +191,7 @@ static void aspeed_scu_write(void *opaque, hwaddr offset, uint64_t data, } if (reg > PROT_KEY && reg < CPU2_BASE_SEG1 && - s->regs[PROT_KEY] != PROT_KEY_UNLOCK) { + s->regs[PROT_KEY] != ASPEED_SCU_PROT_KEY) { qemu_log_mask(LOG_GUEST_ERROR, "%s: SCU is locked!\n", __func__); return; } @@ -246,6 +245,7 @@ static void aspeed_scu_reset(DeviceState *dev) s->regs[SILICON_REV] = s->silicon_rev; s->regs[HW_STRAP1] = s->hw_strap1; s->regs[HW_STRAP2] = s->hw_strap2; + s->regs[PROT_KEY] = s->hw_prot_key; } static uint32_t aspeed_silicon_revs[] = { @@ -299,6 +299,7 @@ static Property aspeed_scu_properties[] = { DEFINE_PROP_UINT32("silicon-rev", AspeedSCUState, silicon_rev, 0), DEFINE_PROP_UINT32("hw-strap1", AspeedSCUState, hw_strap1, 0), DEFINE_PROP_UINT32("hw-strap2", AspeedSCUState, hw_strap2, 0), + DEFINE_PROP_UINT32("hw-prot-key", AspeedSCUState, hw_prot_key, 0), DEFINE_PROP_END_OF_LIST(), }; diff --git a/include/hw/misc/aspeed_scu.h b/include/hw/misc/aspeed_scu.h index bd4ac013f997..d70cc0aeca61 100644 --- a/include/hw/misc/aspeed_scu.h +++ b/include/hw/misc/aspeed_scu.h @@ -29,6 +29,7 @@ typedef struct AspeedSCUState { uint32_t silicon_rev; uint32_t hw_strap1; uint32_t hw_strap2; + uint32_t hw_prot_key; } AspeedSCUState; #define AST2400_A0_SILICON_REV 0x02000303U @@ -38,6 +39,8 @@ typedef struct AspeedSCUState { extern bool is_supported_silicon_rev(uint32_t silicon_rev); +#define ASPEED_SCU_PROT_KEY 0x1688A8A8 + /* * Extracted from Aspeed SDK v00.03.21. Fixes and extra definitions * were added.