54 lines
2.0 KiB
C++
54 lines
2.0 KiB
C++
/*
|
|
* RpiFirmware.hpp
|
|
* Raspberry Pi VideoCore firmware mailbox (property interface)
|
|
* Copyright (c) 2026 Daniel Hammer
|
|
*/
|
|
|
|
#pragma once
|
|
#include <cstdint>
|
|
|
|
// The VideoCore firmware owns parts of the board the ARM cores cannot reach
|
|
// directly: the GPIO expander that powers the Wi-Fi/Bluetooth radio, the
|
|
// clock tree, the board's OTP (serial number, MAC address). The ARM side asks
|
|
// for them through the property channel of the VideoCore mailbox, which
|
|
// ACPI describes as BCM2849 (\_SB.GDV0.RPIQ) on the Pi Firmware Task Force
|
|
// UEFI firmware.
|
|
//
|
|
// All calls are synchronous, take a process-context lock, and must not be
|
|
// made from interrupt context. They return false when there is no mailbox
|
|
// (any machine but a Pi) or the firmware rejects the request.
|
|
|
|
namespace Drivers::Platform::RpiFirmware {
|
|
|
|
// Find the mailbox through ACPI and allocate its message buffer.
|
|
// Idempotent; the other calls initialize on first use.
|
|
bool Initialize();
|
|
|
|
bool IsPresent();
|
|
|
|
// Clock identifiers (the firmware's numbering).
|
|
constexpr uint32_t CLOCK_EMMC = 1; // legacy EMMC (Arasan), runs the Wi-Fi SDIO bus
|
|
constexpr uint32_t CLOCK_CORE = 4; // VPU core clock, feeds the mini UART
|
|
|
|
// Current rate of a firmware clock, in Hz.
|
|
bool GetClockRate(uint32_t clockId, uint32_t& hz);
|
|
|
|
// Gate a firmware clock on or off.
|
|
bool SetClockState(uint32_t clockId, bool on);
|
|
|
|
// The firmware's GPIO expander lines are numbered from 128.
|
|
constexpr uint32_t EXPGPIO_BASE = 128;
|
|
constexpr uint32_t EXPGPIO_BT_ON = EXPGPIO_BASE + 0; // Bluetooth power (high = on)
|
|
constexpr uint32_t EXPGPIO_WL_ON = EXPGPIO_BASE + 1; // Wi-Fi power (high = on)
|
|
|
|
bool SetGpioState(uint32_t gpio, bool high);
|
|
// Configure the line as an output, then drive it (SET_GPIO_CONFIG).
|
|
bool SetGpioOutput(uint32_t gpio, bool high);
|
|
bool GetGpioState(uint32_t gpio, bool& high);
|
|
|
|
// The board's Ethernet MAC address from OTP, in transmission order
|
|
// (mac[0] is the first octet of the OUI).
|
|
bool GetBoardMacAddress(uint8_t mac[6]);
|
|
|
|
}
|