mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-18 08:22:04 +00:00
Refactor 32-bit register definitions
This commit is contained in:
parent
c0f99fcd1c
commit
a6c7a2c57e
26 changed files with 126 additions and 98 deletions
|
@ -1,5 +1,4 @@
|
||||||
#include <stdint.h>
|
#include "utils.h"
|
||||||
|
|
||||||
#include "lp0.h"
|
#include "lp0.h"
|
||||||
#include "emc.h"
|
#include "emc.h"
|
||||||
#include "pmc.h"
|
#include "pmc.h"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef EXOSPHERE_BPMPFW_EMC_H
|
#ifndef EXOSPHERE_BPMPFW_EMC_H
|
||||||
#define EXOSPHERE_BPMPFW_EMC_H
|
#define EXOSPHERE_BPMPFW_EMC_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include "utils.h"
|
||||||
|
|
||||||
#define EMC_BASE (0x7001B000)
|
#define EMC_BASE (0x7001B000)
|
||||||
|
|
||||||
|
@ -9,10 +9,10 @@
|
||||||
#define EMC1_BASE (0x7001F000)
|
#define EMC1_BASE (0x7001F000)
|
||||||
|
|
||||||
|
|
||||||
#define MAKE_EMC_REG(ofs) ((*((volatile uint32_t *)(EMC_BASE + ofs))))
|
#define MAKE_EMC_REG(ofs) (MAKE_REG32(EMC_BASE + ofs))
|
||||||
|
|
||||||
#define MAKE_EMC0_REG(ofs) ((*((volatile uint32_t *)(EMC0_BASE + ofs))))
|
#define MAKE_EMC0_REG(ofs) (MAKE_REG32(EMC0_BASE + ofs))
|
||||||
#define MAKE_EMC1_REG(ofs) ((*((volatile uint32_t *)(EMC1_BASE + ofs))))
|
#define MAKE_EMC1_REG(ofs) (MAKE_REG32(EMC1_BASE + ofs))
|
||||||
|
|
||||||
#define EMC_CFG_0 MAKE_EMC_REG(0x00C)
|
#define EMC_CFG_0 MAKE_EMC_REG(0x00C)
|
||||||
|
|
||||||
|
@ -46,8 +46,6 @@
|
||||||
|
|
||||||
#define EMC_FBIO_CFG7_0 MAKE_EMC_REG(0x584)
|
#define EMC_FBIO_CFG7_0 MAKE_EMC_REG(0x584)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void emc_put_dram_in_self_refresh_mode(void);
|
void emc_put_dram_in_self_refresh_mode(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,12 +1,12 @@
|
||||||
#ifndef EXOSPHERE_BPMPFW_I2C_H
|
#ifndef EXOSPHERE_BPMPFW_I2C_H
|
||||||
#define EXOSPHERE_BPMPFW_I2C_H
|
#define EXOSPHERE_BPMPFW_I2C_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include "utils.h"
|
||||||
|
|
||||||
/* I2C_BASE = I2C4. */
|
/* I2C_BASE = I2C4. */
|
||||||
#define I2C_BASE (0x7000D000)
|
#define I2C_BASE (0x7000D000)
|
||||||
|
|
||||||
#define MAKE_I2C_REG(ofs) ((*((volatile uint32_t *)(I2C_BASE + ofs))))
|
#define MAKE_I2C_REG(ofs) (MAKE_REG32(I2C_BASE + ofs))
|
||||||
|
|
||||||
#define I2C_I2C_CNFG_0 MAKE_I2C_REG(0x000)
|
#define I2C_I2C_CNFG_0 MAKE_I2C_REG(0x000)
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,18 @@
|
||||||
#include <stdint.h>
|
#include "utils.h"
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include "lp0.h"
|
#include "lp0.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "pmc.h"
|
#include "pmc.h"
|
||||||
#include "emc.h"
|
#include "emc.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
|
|
||||||
#define CACHE_CTRL (*((volatile uint32_t *)0x50040000))
|
#define CACHE_CTRL MAKE_REG32(0x50040000)
|
||||||
|
|
||||||
#define PRI_ICTLR_COP_IER_CLR_0 (*((volatile uint32_t *)0x60004038))
|
#define PRI_ICTLR_COP_IER_CLR_0 MAKE_REG32(0x60004038)
|
||||||
#define SEC_ICTLR_COP_IER_CLR_0 (*((volatile uint32_t *)0x60004138))
|
#define SEC_ICTLR_COP_IER_CLR_0 MAKE_REG32(0x60004138)
|
||||||
#define TRI_ICTLR_COP_IER_CLR_0 (*((volatile uint32_t *)0x60004238))
|
#define TRI_ICTLR_COP_IER_CLR_0 MAKE_REG32(0x60004238)
|
||||||
#define QUAD_ICTLR_COP_IER_CLR_0 (*((volatile uint32_t *)0x60004338))
|
#define QUAD_ICTLR_COP_IER_CLR_0 MAKE_REG32(0x60004338)
|
||||||
#define PENTA_ICTLR_COP_IER_CLR_0 (*((volatile uint32_t *)0x60004438))
|
#define PENTA_ICTLR_COP_IER_CLR_0 MAKE_REG32(0x60004438)
|
||||||
#define HEXA_ICTLR_COP_IER_CLR_0 (*((volatile uint32_t *)0x60004538))
|
#define HEXA_ICTLR_COP_IER_CLR_0 MAKE_REG32(0x60004538)
|
||||||
|
|
||||||
void reboot(void) {
|
void reboot(void) {
|
||||||
/* Write MAIN_RST */
|
/* Write MAIN_RST */
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef EXOSPHERE_BPMPFW_LP0_H
|
#ifndef EXOSPHERE_BPMPFW_LP0_H
|
||||||
#define EXOSPHERE_BPMPFW_LP0_H
|
#define EXOSPHERE_BPMPFW_LP0_H
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
void lp0_entry_main(void);
|
void lp0_entry_main(void);
|
||||||
|
|
||||||
void reboot(void);
|
void reboot(void);
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#ifndef EXOSPHERE_BPMPFW_PMC_H
|
#ifndef EXOSPHERE_BPMPFW_PMC_H
|
||||||
#define EXOSPHERE_BPMPFW_PMC_H
|
#define EXOSPHERE_BPMPFW_PMC_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include "utils.h"
|
||||||
|
|
||||||
#define PMC_BASE (0x7000E400)
|
#define PMC_BASE (0x7000E400)
|
||||||
|
|
||||||
#define MAKE_PMC_REG(ofs) ((*((volatile uint32_t *)(PMC_BASE + ofs))))
|
#define MAKE_PMC_REG(ofs) (MAKE_REG32(PMC_BASE + ofs))
|
||||||
|
|
||||||
#define APBDEV_PMC_CNTRL_0 MAKE_PMC_REG(0x000)
|
#define APBDEV_PMC_CNTRL_0 MAKE_PMC_REG(0x000)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef EXOSPHERE_BPMPFW_TIMER_H
|
#ifndef EXOSPHERE_BPMPFW_TIMER_H
|
||||||
#define EXOSPHERE_BPMPFW_TIMER_H
|
#define EXOSPHERE_BPMPFW_TIMER_H
|
||||||
|
|
||||||
#define TIMERUS_CNTR_1US_0 (*((volatile uint32_t *)(0x60005010)))
|
#include "utils.h"
|
||||||
|
|
||||||
|
#define TIMERUS_CNTR_1US_0 MAKE_REG32(0x60005010)
|
||||||
|
|
||||||
static inline void timer_wait(uint32_t microseconds) {
|
static inline void timer_wait(uint32_t microseconds) {
|
||||||
uint32_t old_time = TIMERUS_CNTR_1US_0;
|
uint32_t old_time = TIMERUS_CNTR_1US_0;
|
||||||
|
|
22
exosphere/bpmpfw/src/utils.h
Normal file
22
exosphere/bpmpfw/src/utils.h
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef EXOSPHERE_BPMPFW_UTILS_H
|
||||||
|
#define EXOSPHERE_BPMPFW_UTILS_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define BIT(n) (1u << (n))
|
||||||
|
#define BITL(n) (1ull << (n))
|
||||||
|
#define MASK(n) (BIT(n) - 1)
|
||||||
|
#define MASKL(n) (BITL(n) - 1)
|
||||||
|
#define MASK2(a,b) (MASK(a) & ~MASK(b))
|
||||||
|
#define MASK2L(a,b) (MASKL(a) & ~MASKL(b))
|
||||||
|
|
||||||
|
#define MAKE_REG32(a) (*(volatile uint32_t *)(a))
|
||||||
|
|
||||||
|
#define ALIGN(m) __attribute__((aligned(m)))
|
||||||
|
#define PACKED __attribute__((packed))
|
||||||
|
|
||||||
|
#define ALINLINE __attribute__((always_inline))
|
||||||
|
|
||||||
|
#endif
|
|
@ -8,7 +8,7 @@
|
||||||
/* NOTE: ACTMON registers lie in the SYSREG region! */
|
/* NOTE: ACTMON registers lie in the SYSREG region! */
|
||||||
#define ACTMON_BASE (SYSREG_BASE + 0x800)
|
#define ACTMON_BASE (SYSREG_BASE + 0x800)
|
||||||
|
|
||||||
#define MAKE_ACTMON_REG(n) (*((volatile uint32_t *)(ACTMON_BASE + n)))
|
#define MAKE_ACTMON_REG(n) MAKE_REG32(ACTMON_BASE + n)
|
||||||
|
|
||||||
#define ACTMON_GLB_STATUS_0 MAKE_ACTMON_REG(0x000)
|
#define ACTMON_GLB_STATUS_0 MAKE_ACTMON_REG(0x000)
|
||||||
#define ACTMON_COP_CTRL_0 MAKE_ACTMON_REG(0x0C0)
|
#define ACTMON_COP_CTRL_0 MAKE_ACTMON_REG(0x0C0)
|
||||||
|
|
|
@ -12,15 +12,15 @@ static inline uintptr_t get_bpmp_vector_base(void) {
|
||||||
|
|
||||||
#define BPMP_VECTOR_BASE (get_bpmp_vector_base())
|
#define BPMP_VECTOR_BASE (get_bpmp_vector_base())
|
||||||
|
|
||||||
#define EVP_CPU_RESET_VECTOR_0 (*((volatile uint32_t *)(BPMP_VECTOR_BASE + 0x100)))
|
#define EVP_CPU_RESET_VECTOR_0 MAKE_REG32(BPMP_VECTOR_BASE + 0x100)
|
||||||
|
|
||||||
#define BPMP_VECTOR_RESET (*((volatile uint32_t *)(BPMP_VECTOR_BASE + 0x200)))
|
#define BPMP_VECTOR_RESET MAKE_REG32(BPMP_VECTOR_BASE + 0x200)
|
||||||
#define BPMP_VECTOR_UNDEF (*((volatile uint32_t *)(BPMP_VECTOR_BASE + 0x204)))
|
#define BPMP_VECTOR_UNDEF MAKE_REG32(BPMP_VECTOR_BASE + 0x204)
|
||||||
#define BPMP_VECTOR_SWI (*((volatile uint32_t *)(BPMP_VECTOR_BASE + 0x208)))
|
#define BPMP_VECTOR_SWI MAKE_REG32(BPMP_VECTOR_BASE + 0x208)
|
||||||
#define BPMP_VECTOR_PREFETCH_ABORT (*((volatile uint32_t *)(BPMP_VECTOR_BASE + 0x20C)))
|
#define BPMP_VECTOR_PREFETCH_ABORT MAKE_REG32(BPMP_VECTOR_BASE + 0x20C)
|
||||||
#define BPMP_VECTOR_DATA_ABORT (*((volatile uint32_t *)(BPMP_VECTOR_BASE + 0x210)))
|
#define BPMP_VECTOR_DATA_ABORT MAKE_REG32(BPMP_VECTOR_BASE + 0x210)
|
||||||
#define BPMP_VECTOR_UNK (*((volatile uint32_t *)(BPMP_VECTOR_BASE + 0x214)))
|
#define BPMP_VECTOR_UNK MAKE_REG32(BPMP_VECTOR_BASE + 0x214)
|
||||||
#define BPMP_VECTOR_IRQ (*((volatile uint32_t *)(BPMP_VECTOR_BASE + 0x218)))
|
#define BPMP_VECTOR_IRQ MAKE_REG32(BPMP_VECTOR_BASE + 0x218)
|
||||||
#define BPMP_VECTOR_FIQ (*((volatile uint32_t *)(BPMP_VECTOR_BASE + 0x21C)))
|
#define BPMP_VECTOR_FIQ MAKE_REG32(BPMP_VECTOR_BASE + 0x21C)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
#define CAR_BASE (MMIO_GET_DEVICE_ADDRESS(MMIO_DEVID_CLKRST))
|
#define CAR_BASE (MMIO_GET_DEVICE_ADDRESS(MMIO_DEVID_CLKRST))
|
||||||
|
|
||||||
#define MAKE_CAR_REG(n) (*((volatile uint32_t *)(CAR_BASE + n)))
|
#define MAKE_CAR_REG(n) MAKE_REG32(CAR_BASE + n)
|
||||||
|
|
||||||
#define CLK_RST_CONTROLLER_MISC_CLK_ENB_0 MAKE_CAR_REG(0x048)
|
#define CLK_RST_CONTROLLER_MISC_CLK_ENB_0 MAKE_CAR_REG(0x048)
|
||||||
#define CLK_RST_CONTROLLER_RST_DEVICES_H_0 MAKE_CAR_REG(0x008)
|
#define CLK_RST_CONTROLLER_RST_DEVICES_H_0 MAKE_CAR_REG(0x008)
|
||||||
|
|
|
@ -13,7 +13,7 @@ static inline uintptr_t get_flow_base(void) {
|
||||||
|
|
||||||
#define FLOW_BASE (get_flow_base())
|
#define FLOW_BASE (get_flow_base())
|
||||||
|
|
||||||
#define MAKE_FLOW_REG(ofs) (*((volatile uint32_t *)(FLOW_BASE + ofs)))
|
#define MAKE_FLOW_REG(ofs) MAKE_REG32(FLOW_BASE + ofs)
|
||||||
|
|
||||||
#define FLOW_CTLR_HALT_COP_EVENTS_0 MAKE_FLOW_REG(0x004)
|
#define FLOW_CTLR_HALT_COP_EVENTS_0 MAKE_FLOW_REG(0x004)
|
||||||
#define FLOW_CTLR_FLOW_DBG_QUAL_0 MAKE_FLOW_REG(0x050)
|
#define FLOW_CTLR_FLOW_DBG_QUAL_0 MAKE_FLOW_REG(0x050)
|
||||||
|
|
|
@ -24,7 +24,7 @@ static inline uintptr_t get_gicc_base(void) {
|
||||||
#define GICD_BASE (get_gicd_base())
|
#define GICD_BASE (get_gicd_base())
|
||||||
#define GICC_BASE (get_gicc_base())
|
#define GICC_BASE (get_gicc_base())
|
||||||
|
|
||||||
#define GICD_CTLR (*((volatile uint32_t *)(GICD_BASE + 0x000ull)))
|
#define GICD_CTLR MAKE_REG32(GICD_BASE + 0x000ull)
|
||||||
#define GICD_IGROUPR ((volatile uint32_t *)(GICD_BASE + 0x080ull))
|
#define GICD_IGROUPR ((volatile uint32_t *)(GICD_BASE + 0x080ull))
|
||||||
#define GICD_ISENABLER ((volatile uint32_t *)(GICD_BASE + 0x100ull))
|
#define GICD_ISENABLER ((volatile uint32_t *)(GICD_BASE + 0x100ull))
|
||||||
#define GICD_ISPENDR ((volatile uint32_t *)(GICD_BASE + 0x200ull))
|
#define GICD_ISPENDR ((volatile uint32_t *)(GICD_BASE + 0x200ull))
|
||||||
|
@ -32,11 +32,11 @@ static inline uintptr_t get_gicc_base(void) {
|
||||||
#define GICD_ITARGETSR ((volatile uint8_t *)(GICD_BASE + 0x800ull))
|
#define GICD_ITARGETSR ((volatile uint8_t *)(GICD_BASE + 0x800ull))
|
||||||
#define GICD_ICFGR ((volatile uint32_t *)(GICD_BASE + 0xC00ull))
|
#define GICD_ICFGR ((volatile uint32_t *)(GICD_BASE + 0xC00ull))
|
||||||
|
|
||||||
#define GICC_CTLR (*((volatile uint32_t *)(GICC_BASE + 0x0000ull)))
|
#define GICC_CTLR MAKE_REG32(GICC_BASE + 0x0000ull)
|
||||||
#define GICC_PMR (*((volatile uint32_t *)(GICC_BASE + 0x0004ull)))
|
#define GICC_PMR MAKE_REG32(GICC_BASE + 0x0004ull)
|
||||||
#define GICC_BPR (*((volatile uint32_t *)(GICC_BASE + 0x0008ull)))
|
#define GICC_BPR MAKE_REG32(GICC_BASE + 0x0008ull)
|
||||||
#define GICC_IAR (*((volatile uint32_t *)(GICC_BASE + 0x000CULL)))
|
#define GICC_IAR MAKE_REG32(GICC_BASE + 0x000CULL)
|
||||||
#define GICC_EOIR (*((volatile uint32_t *)(GICC_BASE + 0x0010ull)))
|
#define GICC_EOIR MAKE_REG32(GICC_BASE + 0x0010ull)
|
||||||
|
|
||||||
#define GIC_PRI_HIGHEST_SECURE 0x00
|
#define GIC_PRI_HIGHEST_SECURE 0x00
|
||||||
#define GIC_PRI_HIGHEST_NONSECURE 0x80
|
#define GIC_PRI_HIGHEST_NONSECURE 0x80
|
||||||
|
|
|
@ -90,7 +90,7 @@ uint32_t cpu_suspend(uint64_t power_state, uint64_t entrypoint, uint64_t argumen
|
||||||
uint32_t start_time = get_time();
|
uint32_t start_time = get_time();
|
||||||
bool should_wait = true;
|
bool should_wait = true;
|
||||||
/* TODO: This is GPIO-6 GPIO_IN_1 */
|
/* TODO: This is GPIO-6 GPIO_IN_1 */
|
||||||
while ((*((volatile uint32_t *)(MMIO_GET_DEVICE_ADDRESS(MMIO_DEVID_GPIO) + 0x634))) & 1) {
|
while (MAKE_REG32(MMIO_GET_DEVICE_ADDRESS(MMIO_DEVID_GPIO) + 0x634) & 1) {
|
||||||
if (get_time() - start_time > 50000) {
|
if (get_time() - start_time > 50000) {
|
||||||
should_wait = false;
|
should_wait = false;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -12,7 +12,7 @@ static inline uintptr_t get_mc_base(void) {
|
||||||
|
|
||||||
#define MC_BASE (get_mc_base())
|
#define MC_BASE (get_mc_base())
|
||||||
|
|
||||||
#define MAKE_MC_REG(n) (*((volatile uint32_t *)(MC_BASE + n)))
|
#define MAKE_MC_REG(n) MAKE_REG32(MC_BASE + n)
|
||||||
|
|
||||||
#define MC_SECURITY_CFG0_0 MAKE_MC_REG(0x070)
|
#define MC_SECURITY_CFG0_0 MAKE_MC_REG(0x070)
|
||||||
#define MC_SECURITY_CFG1_0 MAKE_MC_REG(0x074)
|
#define MC_SECURITY_CFG1_0 MAKE_MC_REG(0x074)
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
#define MISC_BASE (MMIO_GET_DEVICE_ADDRESS(MMIO_DEVID_MISC))
|
#define MISC_BASE (MMIO_GET_DEVICE_ADDRESS(MMIO_DEVID_MISC))
|
||||||
|
|
||||||
#define MAKE_MISC_REG(n) (*((volatile uint32_t *)(MISC_BASE + n)))
|
#define MAKE_MISC_REG(n) MAKE_REG32(MISC_BASE + n)
|
||||||
|
|
||||||
|
|
||||||
#define APB_MISC_SECURE_REGS_APB_SLAVE_SECURITY_ENABLE_REG0_0 MAKE_MISC_REG(0x0C00)
|
#define APB_MISC_SECURE_REGS_APB_SLAVE_SECURITY_ENABLE_REG0_0 MAKE_MISC_REG(0x0C00)
|
||||||
|
|
|
@ -14,7 +14,7 @@ static inline uintptr_t get_nx_bootloader_mailbox_base(void) {
|
||||||
|
|
||||||
#define MAILBOX_NX_BOOTLOADER_BASE (get_nx_bootloader_mailbox_base())
|
#define MAILBOX_NX_BOOTLOADER_BASE (get_nx_bootloader_mailbox_base())
|
||||||
|
|
||||||
#define MAILBOX_NX_BOOTLOADER_SETUP_STATE (*((volatile uint32_t *)(MAILBOX_NX_BOOTLOADER_BASE + 0xEF8ull)))
|
#define MAILBOX_NX_BOOTLOADER_SETUP_STATE MAKE_REG32(MAILBOX_NX_BOOTLOADER_BASE + 0xEF8ull)
|
||||||
|
|
||||||
#define NX_BOOTLOADER_STATE_INIT 0
|
#define NX_BOOTLOADER_STATE_INIT 0
|
||||||
#define NX_BOOTLOADER_STATE_MOVED_BOOTCONFIG 1
|
#define NX_BOOTLOADER_STATE_MOVED_BOOTCONFIG 1
|
||||||
|
@ -27,7 +27,7 @@ static inline uintptr_t get_nx_bootloader_mailbox_base(void) {
|
||||||
#define NX_BOOTLOADER_STATE_FINISHED_4X 4
|
#define NX_BOOTLOADER_STATE_FINISHED_4X 4
|
||||||
|
|
||||||
/* Physaddr 0x40002EFC */
|
/* Physaddr 0x40002EFC */
|
||||||
#define MAILBOX_NX_BOOTLOADER_IS_SECMON_AWAKE (*((volatile uint32_t *)(MAILBOX_NX_BOOTLOADER_BASE + 0xEFCULL)))
|
#define MAILBOX_NX_BOOTLOADER_IS_SECMON_AWAKE MAKE_REG32(MAILBOX_NX_BOOTLOADER_BASE + 0xEFCULL)
|
||||||
|
|
||||||
#define NX_BOOTLOADER_BOOTCONFIG_POINTER ((void *)(0x4003D000ull))
|
#define NX_BOOTLOADER_BOOTCONFIG_POINTER ((void *)(0x4003D000ull))
|
||||||
|
|
||||||
|
|
|
@ -12,32 +12,32 @@ static inline uintptr_t get_pmc_base(void) {
|
||||||
|
|
||||||
#define PMC_BASE (get_pmc_base())
|
#define PMC_BASE (get_pmc_base())
|
||||||
|
|
||||||
#define APBDEV_PMC_DPD_ENABLE_0 (*((volatile uint32_t *)(PMC_BASE + 0x24)))
|
#define APBDEV_PMC_DPD_ENABLE_0 MAKE_REG32(PMC_BASE + 0x24)
|
||||||
|
|
||||||
#define APBDEV_PMC_PWRGATE_TOGGLE_0 (*((volatile uint32_t *)(PMC_BASE + 0x30)))
|
#define APBDEV_PMC_PWRGATE_TOGGLE_0 MAKE_REG32(PMC_BASE + 0x30)
|
||||||
#define APBDEV_PMC_PWRGATE_STATUS_0 (*((volatile uint32_t *)(PMC_BASE + 0x38)))
|
#define APBDEV_PMC_PWRGATE_STATUS_0 MAKE_REG32(PMC_BASE + 0x38)
|
||||||
|
|
||||||
#define APBDEV_PMC_SCRATCH0_0 (*((volatile uint32_t *)(PMC_BASE + 0x50)))
|
#define APBDEV_PMC_SCRATCH0_0 MAKE_REG32(PMC_BASE + 0x50)
|
||||||
|
|
||||||
#define APBDEV_PMC_CRYPTO_OP_0 (*((volatile uint32_t *)(PMC_BASE + 0xF4)))
|
#define APBDEV_PMC_CRYPTO_OP_0 MAKE_REG32(PMC_BASE + 0xF4)
|
||||||
|
|
||||||
#define APBDEV_PM_0 (*((volatile uint32_t *)(PMC_BASE + 0x14)))
|
#define APBDEV_PM_0 MAKE_REG32(PMC_BASE + 0x14)
|
||||||
#define APBDEV_PMC_WAKE2_STATUS_0 (*((volatile uint32_t *)(PMC_BASE + 0x168)))
|
#define APBDEV_PMC_WAKE2_STATUS_0 MAKE_REG32(PMC_BASE + 0x168)
|
||||||
#define APBDEV_PMC_CNTRL2_0 (*((volatile uint32_t *)(PMC_BASE + 0x440)))
|
#define APBDEV_PMC_CNTRL2_0 MAKE_REG32(PMC_BASE + 0x440)
|
||||||
|
|
||||||
#define APBDEV_PMC_SCRATCH43_0 (*((volatile uint32_t *)(PMC_BASE + 0x22C)))
|
#define APBDEV_PMC_SCRATCH43_0 MAKE_REG32(PMC_BASE + 0x22C)
|
||||||
#define APBDEV_PMC_SEC_DISABLE8_0 (*((volatile uint32_t *)(PMC_BASE + 0x5C0)))
|
#define APBDEV_PMC_SEC_DISABLE8_0 MAKE_REG32(PMC_BASE + 0x5C0)
|
||||||
#define APBDEV_PMC_SECURE_SCRATCH112_0 (*((volatile uint32_t *)(PMC_BASE + 0xB18)))
|
#define APBDEV_PMC_SECURE_SCRATCH112_0 MAKE_REG32(PMC_BASE + 0xB18)
|
||||||
#define APBDEV_PMC_SECURE_SCRATCH113_0 (*((volatile uint32_t *)(PMC_BASE + 0xB1C)))
|
#define APBDEV_PMC_SECURE_SCRATCH113_0 MAKE_REG32(PMC_BASE + 0xB1C)
|
||||||
#define APBDEV_PMC_SECURE_SCRATCH114_0 (*((volatile uint32_t *)(PMC_BASE + 0xB20)))
|
#define APBDEV_PMC_SECURE_SCRATCH114_0 MAKE_REG32(PMC_BASE + 0xB20)
|
||||||
#define APBDEV_PMC_SECURE_SCRATCH115_0 (*((volatile uint32_t *)(PMC_BASE + 0xB24)))
|
#define APBDEV_PMC_SECURE_SCRATCH115_0 MAKE_REG32(PMC_BASE + 0xB24)
|
||||||
|
|
||||||
#define APBDEV_PMC_SCRATCH200_0 (*((volatile uint32_t *)(PMC_BASE + 0x840)))
|
#define APBDEV_PMC_SCRATCH200_0 MAKE_REG32(PMC_BASE + 0x840)
|
||||||
|
|
||||||
|
|
||||||
#define APBDEV_PMC_SEC_DISABLE3_0 (*((volatile uint32_t *)(PMC_BASE + 0x2D8)))
|
#define APBDEV_PMC_SEC_DISABLE3_0 MAKE_REG32(PMC_BASE + 0x2D8)
|
||||||
#define APBDEV_PMC_SECURE_SCRATCH34_0 (*((volatile uint32_t *)(PMC_BASE + 0x368)))
|
#define APBDEV_PMC_SECURE_SCRATCH34_0 MAKE_REG32(PMC_BASE + 0x368)
|
||||||
#define APBDEV_PMC_SECURE_SCRATCH35_0 (*((volatile uint32_t *)(PMC_BASE + 0x36C)))
|
#define APBDEV_PMC_SECURE_SCRATCH35_0 MAKE_REG32(PMC_BASE + 0x36C)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "synchronization.h"
|
||||||
#include "interrupt.h"
|
#include "interrupt.h"
|
||||||
#include "se.h"
|
#include "se.h"
|
||||||
#include "memory_map.h"
|
#include "memory_map.h"
|
||||||
|
@ -281,7 +282,7 @@ void se_aes_crypt_insecure_internal(unsigned int keyslot, uint32_t out_ll_paddr,
|
||||||
SECURITY_ENGINE->OPERATION_REG = 1;
|
SECURITY_ENGINE->OPERATION_REG = 1;
|
||||||
|
|
||||||
/* Ensure writes go through. */
|
/* Ensure writes go through. */
|
||||||
__asm__ __volatile__ ("dsb ish" : : : "memory");
|
__dsb_ish();
|
||||||
}
|
}
|
||||||
|
|
||||||
void se_aes_ctr_crypt_insecure(unsigned int keyslot, uint32_t out_ll_paddr, uint32_t in_ll_paddr, size_t size, const void *ctr, unsigned int (*callback)(void)) {
|
void se_aes_ctr_crypt_insecure(unsigned int keyslot, uint32_t out_ll_paddr, uint32_t in_ll_paddr, size_t size, const void *ctr, unsigned int (*callback)(void)) {
|
||||||
|
@ -442,7 +443,7 @@ void trigger_se_rsa_op(void *buf, size_t size) {
|
||||||
SECURITY_ENGINE->OPERATION_REG = 1;
|
SECURITY_ENGINE->OPERATION_REG = 1;
|
||||||
|
|
||||||
/* Ensure writes go through. */
|
/* Ensure writes go through. */
|
||||||
__asm__ __volatile__ ("dsb ish" : : : "memory");
|
__dsb_ish();
|
||||||
}
|
}
|
||||||
|
|
||||||
void trigger_se_blocking_op(unsigned int op, void *dst, size_t dst_size, const void *src, size_t src_size) {
|
void trigger_se_blocking_op(unsigned int op, void *dst, size_t dst_size, const void *src, size_t src_size) {
|
||||||
|
|
|
@ -17,6 +17,10 @@ static inline void __dsb_sy(void) {
|
||||||
__asm__ __volatile__ ("dsb sy" ::: "memory");
|
__asm__ __volatile__ ("dsb sy" ::: "memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void __dsb_ish(void) {
|
||||||
|
__asm__ __volatile__ ("dsb ish" ::: "memory");
|
||||||
|
}
|
||||||
|
|
||||||
static inline void __dmb_sy(void) {
|
static inline void __dmb_sy(void) {
|
||||||
__asm__ __volatile__ ("dmb sy" ::: "memory");
|
__asm__ __volatile__ ("dmb sy" ::: "memory");
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#define SYSCRT0_BASE (MMIO_GET_DEVICE_ADDRESS(MMIO_DEVID_SYSCTR0))
|
#define SYSCRT0_BASE (MMIO_GET_DEVICE_ADDRESS(MMIO_DEVID_SYSCTR0))
|
||||||
|
|
||||||
|
|
||||||
#define MAKE_SYSCRT0_REG(n) (*((volatile uint32_t *)(SYSCRT0_BASE + n)))
|
#define MAKE_SYSCRT0_REG(n) MAKE_REG32(SYSCRT0_BASE + n)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
|
|
||||||
#define SB_BASE (SYSREG_BASE + 0x200)
|
#define SB_BASE (SYSREG_BASE + 0x200)
|
||||||
|
|
||||||
#define MAKE_SYSREG(n) (*((volatile uint32_t *)(SYSREG_BASE + n)))
|
#define MAKE_SYSREG(n) MAKE_REG32(SYSREG_BASE + n)
|
||||||
#define MAKE_SB_REG(n) (*((volatile uint32_t *)(SB_BASE + n)))
|
#define MAKE_SB_REG(n) MAKE_REG32(SB_BASE + n)
|
||||||
|
|
||||||
#define SB_CSR_0 MAKE_SB_REG(0x00)
|
#define SB_CSR_0 MAKE_SB_REG(0x00)
|
||||||
#define SB_PIROM_START_0 MAKE_SB_REG(0x04)
|
#define SB_PIROM_START_0 MAKE_SB_REG(0x04)
|
||||||
|
|
|
@ -12,9 +12,9 @@ static inline uintptr_t get_timers_base(void) {
|
||||||
|
|
||||||
#define TIMERS_BASE (get_timers_base())
|
#define TIMERS_BASE (get_timers_base())
|
||||||
|
|
||||||
#define MAKE_TIMERS_REG(n) (*((volatile uint32_t *)(TIMERS_BASE + n)))
|
#define MAKE_TIMERS_REG(n) MAKE_REG32(TIMERS_BASE + n)
|
||||||
|
|
||||||
#define TIMERUS_CNTR_1US_0 (*((volatile uint32_t *)(TIMERS_BASE + 0x10)))
|
#define TIMERUS_CNTR_1US_0 MAKE_REG32(TIMERS_BASE + 0x10)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t CONFIG;
|
uint32_t CONFIG;
|
||||||
|
@ -25,7 +25,7 @@ typedef struct {
|
||||||
|
|
||||||
#define GET_WDT(n) ((volatile watchdog_timers_t *)(TIMERS_BASE + 0x100 + 0x20 * n))
|
#define GET_WDT(n) ((volatile watchdog_timers_t *)(TIMERS_BASE + 0x100 + 0x20 * n))
|
||||||
#define WDT_REBOOT_PATTERN 0xC45A
|
#define WDT_REBOOT_PATTERN 0xC45A
|
||||||
#define GET_WDT_REBOOT_CFG_REG(n) (*((volatile uint32_t *)(TIMERS_BASE + 0x60 + 0x8*n)))
|
#define GET_WDT_REBOOT_CFG_REG(n) MAKE_REG32(TIMERS_BASE + 0x60 + 0x8*n)
|
||||||
|
|
||||||
void wait(uint32_t microseconds);
|
void wait(uint32_t microseconds);
|
||||||
|
|
||||||
|
|
|
@ -14,11 +14,11 @@ static inline uintptr_t get_uarta_base(void) {
|
||||||
|
|
||||||
#define UARTA_BASE (get_uarta_base())
|
#define UARTA_BASE (get_uarta_base())
|
||||||
|
|
||||||
#define UART_THR_DLAB_0_0 (*((volatile uint32_t *)(UARTA_BASE + 0x0)))
|
#define UART_THR_DLAB_0_0 MAKE_REG32(UARTA_BASE + 0x0)
|
||||||
#define UART_IER_DLAB_0_0 (*((volatile uint32_t *)(UARTA_BASE + 0x4)))
|
#define UART_IER_DLAB_0_0 MAKE_REG32(UARTA_BASE + 0x4)
|
||||||
#define UART_IIR_FCR_0 (*((volatile uint32_t *)(UARTA_BASE+ 0x8)))
|
#define UART_IIR_FCR_0 MAKE_REG32(UARTA_BASE+ 0x8)
|
||||||
#define UART_LCR_0 (*((volatile uint32_t *)(UARTA_BASE + 0xC)))
|
#define UART_LCR_0 MAKE_REG32(UARTA_BASE + 0xC)
|
||||||
#define UART_LSR_0 (*((volatile uint32_t *)(UARTA_BASE + 0x14)))
|
#define UART_LSR_0 MAKE_REG32(UARTA_BASE + 0x14)
|
||||||
|
|
||||||
void uart_initialize(uint16_t divider);
|
void uart_initialize(uint16_t divider);
|
||||||
void uart_transmit_char(char ch);
|
void uart_transmit_char(char ch);
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
#define MASK2(a,b) (MASK(a) & ~MASK(b))
|
#define MASK2(a,b) (MASK(a) & ~MASK(b))
|
||||||
#define MASK2L(a,b) (MASKL(a) & ~MASKL(b))
|
#define MASK2L(a,b) (MASKL(a) & ~MASKL(b))
|
||||||
|
|
||||||
|
#define MAKE_REG32(a) (*(volatile uint32_t *)(a))
|
||||||
|
|
||||||
#define ALIGN(m) __attribute__((aligned(m)))
|
#define ALIGN(m) __attribute__((aligned(m)))
|
||||||
#define PACKED __attribute__((packed))
|
#define PACKED __attribute__((packed))
|
||||||
|
|
||||||
|
|
|
@ -33,35 +33,35 @@ void init_dma_controllers(void) {
|
||||||
/* TODO: 4.x does slightly different init. How should we handle this? We can't detect master key revision yet. */
|
/* TODO: 4.x does slightly different init. How should we handle this? We can't detect master key revision yet. */
|
||||||
|
|
||||||
/* SYSCTR0_CNTCR_0 = ENABLE | HALT_ON_DEBUG (write-once init) */
|
/* SYSCTR0_CNTCR_0 = ENABLE | HALT_ON_DEBUG (write-once init) */
|
||||||
(*((volatile uint32_t *)(0x700F0000))) = 3;
|
MAKE_REG32(0x700F0000) = 3;
|
||||||
|
|
||||||
/* Set some unknown registers in HOST1X. */
|
/* Set some unknown registers in HOST1X. */
|
||||||
(*((volatile uint32_t *)(0x500038F8))) &= 0xFFFFFFFE;
|
MAKE_REG32(0x500038F8) &= 0xFFFFFFFE;
|
||||||
(*((volatile uint32_t *)(0x50003300))) = 0;
|
MAKE_REG32(0x50003300) = 0;
|
||||||
|
|
||||||
/* AHB_MASTER_SWID_0 */
|
/* AHB_MASTER_SWID_0 */
|
||||||
(*((volatile uint32_t *)(0x6000C018))) = 0;
|
MAKE_REG32(0x6000C018) = 0;
|
||||||
|
|
||||||
/* AHB_MASTER_SWID_1 - Makes USB1/USB2 use SWID[1] */
|
/* AHB_MASTER_SWID_1 - Makes USB1/USB2 use SWID[1] */
|
||||||
(*((volatile uint32_t *)(0x6000C038))) = 0x40040;
|
MAKE_REG32(0x6000C038) = 0x40040;
|
||||||
|
|
||||||
/* APBDMA_CHANNEL_SWID_0 = ~0 (SWID = 1 for all APB-DMA channels) */
|
/* APBDMA_CHANNEL_SWID_0 = ~0 (SWID = 1 for all APB-DMA channels) */
|
||||||
(*((volatile uint32_t *)(0x6002003C))) = 0xFFFFFFFF;
|
MAKE_REG32(0x6002003C) = 0xFFFFFFFF;
|
||||||
|
|
||||||
/* APBDMA_CHANNEL_SWID1_0 = 0 (See above) */
|
/* APBDMA_CHANNEL_SWID1_0 = 0 (See above) */
|
||||||
(*((volatile uint32_t *)(0x60020054))) = 0;
|
MAKE_REG32(0x60020054) = 0;
|
||||||
|
|
||||||
/* APBDMA_SECURITY_REG_0 = 0 (All APB-DMA channels non-secure) */
|
/* APBDMA_SECURITY_REG_0 = 0 (All APB-DMA channels non-secure) */
|
||||||
(*((volatile uint32_t *)(0x60020038))) = 0;
|
MAKE_REG32(0x60020038) = 0;
|
||||||
|
|
||||||
/* MSELECT_CONFIG_0 |= WRAP_TO_INCR_SLAVE0(APC) | WRAP_TO_INCR_SLAVE1(PCIe) | WRAP_TO_INCR_SLAVE2(GPU) */
|
/* MSELECT_CONFIG_0 |= WRAP_TO_INCR_SLAVE0(APC) | WRAP_TO_INCR_SLAVE1(PCIe) | WRAP_TO_INCR_SLAVE2(GPU) */
|
||||||
(*((volatile uint32_t *)(0x50060000))) |= 0x38000000;
|
MAKE_REG32(0x50060000) |= 0x38000000;
|
||||||
|
|
||||||
/* AHB_ARBITRATION_PRIORITY_CTRL_0 - Select high prio group with prio 7 */
|
/* AHB_ARBITRATION_PRIORITY_CTRL_0 - Select high prio group with prio 7 */
|
||||||
(*((volatile uint32_t *)(0x6000C008))) = 0xE0000001;
|
MAKE_REG32(0x6000C008) = 0xE0000001;
|
||||||
|
|
||||||
/* AHB_GIZMO_TZRAM_0 |= DONT_SPLIT_AHB_WR */
|
/* AHB_GIZMO_TZRAM_0 |= DONT_SPLIT_AHB_WR */
|
||||||
(*((volatile uint32_t *)(0x6000C054))) = 0x80;
|
MAKE_REG32(0x6000C054) = 0x80;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_memory_registers_enable_mmu(void) {
|
void set_memory_registers_enable_mmu(void) {
|
||||||
|
|
Loading…
Reference in a new issue