Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71F92C4708F for ; Wed, 2 Jun 2021 23:32:51 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id F16CC6139A for ; Wed, 2 Jun 2021 23:32:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F16CC6139A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=sigbus.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1loaLy-0002WG-0G for qemu-devel@archiver.kernel.org; Wed, 02 Jun 2021 19:32:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46410) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1loaLM-0001ir-RL for qemu-devel@nongnu.org; Wed, 02 Jun 2021 19:32:12 -0400 Received: from phong.sigbus.net ([71.19.155.206]:38346) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1loaLK-0002d3-Oo for qemu-devel@nongnu.org; Wed, 02 Jun 2021 19:32:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=sigbus.net; s=2020; t=1622676728; bh=EUtIMZUj4vexH9WITndRzrOGcKbc9pZdOrpXaPQ0q4I=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=Fb1TP5DJEuzTQSW13gy9R3sWVmnWGpgUjVIQ1YF/upKOK87OC31Q3sHxBotuZn3Wf FvqpsHNHaXeu4H2lFoSUbCJYwcvFUQbEK5aOkaoX8fFIzp5Iu/DWgpNI+xxWW+Ho22 TPqOV6rjVfemIPta3Sqns7VHy2exkEr4EAQsdTe0VQhbyYm/58h+oMnaKVfZk08R8B V0Qq3OiIQfraVI+fyVCdvnQLgrXT4bZ6TZbZoJtENxYwgrn299k2DDg0qE+SuypsHa PSAy+voHGkud718vq4B3J0piV4uJHtRWLNKd9VVc9Aez0T8XwIvwgxglTX09Uaibnv hlV9FGUM6TPvQ== Subject: Re: [PATCH qemu] Add basic power management to raspi. To: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= , qemu-devel@nongnu.org References: <162137039825.30884.2445825798240809194-0@git.sr.ht> <65187b48-2449-e2b4-2d13-ed9ffb6fe2a8@amsat.org> <7669dd87-e040-a049-e953-9f31a4557ee5@sigbus.net> <596d4b19-a1b8-4ae3-d449-376bcd88cbe5@amsat.org> From: Nolan Message-ID: <9f24edda-8c09-052e-cd3d-fb84946511fa@sigbus.net> Date: Wed, 2 Jun 2021 16:32:06 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: <596d4b19-a1b8-4ae3-d449-376bcd88cbe5@amsat.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=71.19.155.206; envelope-from=nolan@sigbus.net; helo=phong.sigbus.net X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 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, NICE_REPLY_A=-0.613, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-arm@nongnu.org, Andrew Baumann Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 6/2/21 4:22 PM, Philippe Mathieu-Daudé wrote: > On 6/2/21 11:33 PM, Nolan wrote: >> On 5/31/21 4:23 AM, Philippe Mathieu-Daudé wrote: >>> Hi Nolan, >>> >>> Thanks for your patch! >>> >>> There is something odd with your email address, which apparently >>> became sourcehut@sigbus.net instead of nolan@sigbus.net. >> >> Ugh, oops. I was trying out sourcehut for this, and reflexively gave >> them a marker email. I'm pretty sure sourcehut won't sell my email >> address, so I'll just change it. >> >>> On 5/18/21 10:24 PM, ~nolanl wrote: >>>> From: Nolan Leake >>>> >>>> This is just enough to make reboot and poweroff work. >>> >>> Please precise "for Linux kernels", since this doesn't work >>> with firmwares (ideally we should implement the FIRMWARE_NOTIFY_REBOOT >>> property - which Linux sends - to handle the machine reboot/halt >>> via the videocore firmware model). >> >> Thanks, good point re: this being tuned to what Linux (and u-boot) do. >> Poking around a bit, it looks like >> "trusted-firmware-a"/"arm-trusted-firmware" uses the same method, as do >> a couple of bare-metal/hobby OSes. Couldn't immediately figure out what >> FreeBSD does. >> >> I'm not sure I understand your point about FIRMWARE_NOTIFY_REBOOT, my >> understanding is that message is there to tell the GPU firmware that >> we're about to reboot, so it can do things like reload the PCIe USB >> chip's firmware. In my testing without the watchdog module loaded, my >> physical pi4 does not reboot, so it appears that sending >> FIRMWARE_NOTIFY_REBOOT is not enough on its own. > > From the ARM core point of view, once it sent the FIRMWARE_NOTIFY_REBOOT > message, it can't really power-off itself, it waits in a busy loop for > the VC to disable its power domain. > > hw/misc/bcm2835_property.c is our model of the VC behavior. IMO this > should be where QEMU shuts down. How I'd model it is: > > - ARM: sends FIRMWARE_NOTIFY_REBOOT and loops > > - VC emulated via property: delays (200ms?) then calls > SHUTDOWN_CAUSE_GUEST_RESET. > > (it helps to see hw/misc/bcm2835_property.c as an external component). This is not what I see on my hardware pi4. With the following kernel config: ... CONFIG_RASPBERRYPI_FIRMWARE=y ... CONFIG_BCM2835_WDT=m ... if I reboot the machine without the WDT module (but with the firmware module), I get this: # echo b > /proc/sysrq-trigger [ 54.498768] sysrq: Resetting [ 54.501713] SMP: stopping secondary CPUs [ 54.505701] Reboot failed -- System halted and it hangs forever there. If I load the WDT module, it reboots successfully. >>>> qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); >>>> +            } else { >>>> +                qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); >>>> +            } >>>> +        } >>> >>> Shouldn't we log the unsupported bits? >> >> I can add that, I didn't originally because the unsupported writes are >> expected. > > I'd prefer we log them, even if unsupported, so in case something > behaves oddly we could look at those bits. In v2, I log the writes, since any side effects they have (notably the watchdog register) are unimplemented. I didn't log the reads, since they actually behave exactly as the real hardware does... >>>> +static void bcm2835_powermgt_reset(DeviceState *dev) >>>> +{ >>>> +    BCM2835PowerMgtState *s = BCM2835_POWERMGT(dev); >>>> + >>>> +    s->rstc = 0x00000102; >>>> +    s->rsts = 0x00001000; >>>> +    s->wdog = 0x00000000; >>> >>> Where these bits come from? >> >> From my pi4. https://elinux.org/BCM2835_registers agrees (processed from >> Broadcom source code). > > OK, so please add a comment referring to > https://elinux.org/BCM2835_registers#PM. > > Looking forward for v2 :) Already sent. Is the link comment here worth a v3?