// SPDX-License-Identifier: GPL-2.012//! GPU Firmware (`GFW`) support, a.k.a `devinit`.3//!4//! Upon reset, the GPU runs some firmware code from the BIOS to setup its core parameters. Most of5//! the GPU is considered unusable until this step is completed, so we must wait on it before6//! performing driver initialization.7//!8//! A clarification about devinit terminology: devinit is a sequence of register read/writes after9//! reset that performs tasks such as:10//! 1. Programming VRAM memory controller timings.11//! 2. Power sequencing.12//! 3. Clock and PLL configuration.13//! 4. Thermal management.14//!15//! devinit itself is a 'script' which is interpreted by an interpreter program typically running16//! on the PMU microcontroller.17//!18//! Note that the devinit sequence also needs to run during suspend/resume.1920use kernel::{21io::poll::read_poll_timeout,22prelude::*,23time::Delta, //24};2526use crate::{27driver::Bar0,28regs, //29};3031/// Wait for the `GFW` (GPU firmware) boot completion signal (`GFW_BOOT`), or a 4 seconds timeout.32///33/// Upon GPU reset, several microcontrollers (such as PMU, SEC2, GSP etc) run some firmware code to34/// setup its core parameters. Most of the GPU is considered unusable until this step is completed,35/// so it must be waited on very early during driver initialization.36///37/// The `GFW` code includes several components that need to execute before the driver loads. These38/// components are located in the VBIOS ROM and executed in a sequence on these different39/// microcontrollers. The devinit sequence typically runs on the PMU, and the FWSEC runs on the40/// GSP.41///42/// This function waits for a signal indicating that core initialization is complete. Before this43/// signal is received, little can be done with the GPU. This signal is set by the FWSEC running on44/// the GSP in Heavy-secured mode.45pub(crate) fn wait_gfw_boot_completion(bar: &Bar0) -> Result {46// Before accessing the completion status in `NV_PGC6_AON_SECURE_SCRATCH_GROUP_05`, we must47// first check `NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_PRIV_LEVEL_MASK`. This is because48// `NV_PGC6_AON_SECURE_SCRATCH_GROUP_05` becomes accessible only after the secure firmware49// (FWSEC) lowers the privilege level to allow CPU (LS/Light-secured) access. We can only50// safely read the status register from CPU (LS/Light-secured) once the mask indicates51// that the privilege level has been lowered.52//53// TIMEOUT: arbitrarily large value. GFW starts running immediately after the GPU is put out of54// reset, and should complete in less time than that.55read_poll_timeout(56|| {57Ok(58// Check that FWSEC has lowered its protection level before reading the GFW_BOOT59// status.60regs::NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_PRIV_LEVEL_MASK::read(bar)61.read_protection_level0()62&& regs::NV_PGC6_AON_SECURE_SCRATCH_GROUP_05_0_GFW_BOOT::read(bar).completed(),63)64},65|&gfw_booted| gfw_booted,66Delta::from_millis(1),67Delta::from_secs(4),68)69.map(|_| ())70}717273