GK SDK 源码库: XMIPCLinuxV100R005C00SPC030 (kernel/tools/open_source excluded)

This commit is contained in:
lai
2026-09-06 03:52:57 +08:00
commit b1928b41c0
21813 changed files with 4413081 additions and 0 deletions
@@ -0,0 +1,135 @@
/*
* Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <string.h>
#include <platform_def.h>
#include <arch_helpers.h>
#include <common/debug.h>
#include <drivers/console.h>
#include <drivers/delay_timer.h>
#include <lib/mmio.h>
#include <plat_private.h>
#include <soc.h>
#include "ddr_parameter.h"
/*
* The miniloader delivers the parameters about ddr usage info from address
* 0x02000000 and the data format is defined as below figure. It tells ATF the
* areas of ddr that are used by platform, we treat them as non-secure regions
* by default. Then we should parse the other part regions and configurate them
* as secure regions to avoid illegal access.
*
* [ddr usage info data format]
* 0x02000000
* -----------------------------------------------------------------------------
* | <name> | <size> | <description> |
* -----------------------------------------------------------------------------
* | count | 4byte | the array numbers of the |
* | | | 'addr_array' and 'size_array' |
* -----------------------------------------------------------------------------
* | reserved | 4byte | just for 'addr_array' 8byte aligned |
* -----------------------------------------------------------------------------
* | addr_array[count] | per 8byte | memory region base address |
* -----------------------------------------------------------------------------
* | size_array[count] | per 8byte | memory region size (byte) |
* -----------------------------------------------------------------------------
*/
/*
* function: read parameters info(ns-regions) and try to parse s-regions info
*
* @addr: head address to the ddr usage struct from miniloader
* @max_mb: the max ddr capacity(MB) that the platform support
*/
struct param_ddr_usage ddr_region_usage_parse(uint64_t addr, uint64_t max_mb)
{
uint64_t base, top;
uint32_t i, addr_offset, size_offset;
struct param_ddr_usage p;
memset(&p, 0, sizeof(p));
/* read how many blocks of ns-regions, read from offset: 0x0 */
p.ns_nr = mmio_read_32(addr + REGION_NR_OFFSET);
if ((p.ns_nr > DDR_REGION_NR_MAX) || (p.ns_nr == 0)) {
ERROR("over or zero region, nr=%d, max=%d\n",
p.ns_nr, DDR_REGION_NR_MAX);
return p;
}
/* whole ddr regions boundary, it will be used when parse s-regions */
p.boundary = max_mb;
/* calculate ns-region base addr and size offset */
addr_offset = REGION_ADDR_OFFSET;
size_offset = REGION_ADDR_OFFSET + p.ns_nr * REGION_DATA_PER_BYTES;
/* read all ns-regions base and top address */
for (i = 0; i < p.ns_nr; i++) {
base = mmio_read_64(addr + addr_offset);
top = base + mmio_read_64(addr + size_offset);
/*
* translate byte to MB and store info,
* Miniloader will promise every ns-region is MB aligned.
*/
p.ns_base[i] = RG_SIZE_MB(base);
p.ns_top[i] = RG_SIZE_MB(top);
addr_offset += REGION_DATA_PER_BYTES;
size_offset += REGION_DATA_PER_BYTES;
}
/*
* a s-region's base starts from previous ns-region's top, and a
* s-region's top ends with next ns-region's base. maybe like this:
*
* case1: ns-regison start from 0MB
* -----------------------------------------------
* | ns0 | S0 | ns1 | S1 | ns2 |
* 0----------------------------------------------- max_mb
*
*
* case2: ns-regison not start from 0MB
* -----------------------------------------------
* | S0 | ns0 | ns1 | ns2 | S1 |
* 0----------------------------------------------- max_mb
*/
/* like above case2 figure, ns-region is not start from 0MB */
if (p.ns_base[0] != 0) {
p.s_base[p.s_nr] = 0;
p.s_top[p.s_nr] = p.ns_base[0];
p.s_nr++;
}
/*
* notice: if ns-regions not start from 0MB, p.s_nr = 1 now, otherwise 0
*/
for (i = 0; i < p.ns_nr; i++) {
/*
* if current ns-regions top covers boundary,
* that means s-regions are all parsed yet, so finsh.
*/
if (p.ns_top[i] == p.boundary)
goto out;
/* s-region's base starts from previous ns-region's top */
p.s_base[p.s_nr] = p.ns_top[i];
/* s-region's top ends with next ns-region's base */
if (i + 1 < p.ns_nr)
p.s_top[p.s_nr] = p.ns_base[i + 1];
else
p.s_top[p.s_nr] = p.boundary;
p.s_nr++;
}
out:
return p;
}
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef DDR_PARAMETER_H
#define DDR_PARAMETER_H
#include <string.h>
#include <platform_def.h>
#include <arch_helpers.h>
#include <common/debug.h>
#include <drivers/console.h>
#include <drivers/delay_timer.h>
#include <lib/mmio.h>
#include <plat_private.h>
#include <soc.h>
#define DDR_REGION_NR_MAX 10
#define REGION_NR_OFFSET 0
#define REGION_ADDR_OFFSET 8
#define REGION_DATA_PER_BYTES 8
#define RG_SIZE_MB(byte) ((byte) >> 20)
/* unit: MB */
struct param_ddr_usage {
uint64_t boundary;
uint32_t ns_nr;
uint64_t ns_base[DDR_REGION_NR_MAX];
uint64_t ns_top[DDR_REGION_NR_MAX];
uint32_t s_nr;
uint64_t s_base[DDR_REGION_NR_MAX + 1];
uint64_t s_top[DDR_REGION_NR_MAX + 1];
};
struct param_ddr_usage ddr_region_usage_parse(uint64_t addr, uint64_t max_mb);
#endif /* DDR_PARAMETER_H */
@@ -0,0 +1,122 @@
/*
* Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef PMU_COM_H
#define PMU_COM_H
#ifndef CHECK_CPU_WFIE_BASE
#define CHECK_CPU_WFIE_BASE (PMU_BASE + PMU_CORE_PWR_ST)
#endif
/*
* Use this macro to instantiate lock before it is used in below
* rockchip_pd_lock_xxx() macros
*/
DECLARE_BAKERY_LOCK(rockchip_pd_lock);
/*
* These are wrapper macros to the powe domain Bakery Lock API.
*/
#define rockchip_pd_lock_init() bakery_lock_init(&rockchip_pd_lock)
#define rockchip_pd_lock_get() bakery_lock_get(&rockchip_pd_lock)
#define rockchip_pd_lock_rls() bakery_lock_release(&rockchip_pd_lock)
/*****************************************************************************
* power domain on or off
*****************************************************************************/
enum pmu_pd_state {
pmu_pd_on = 0,
pmu_pd_off = 1
};
#pragma weak plat_ic_get_pending_interrupt_id
#pragma weak pmu_power_domain_ctr
#pragma weak check_cpu_wfie
static inline uint32_t pmu_power_domain_st(uint32_t pd)
{
uint32_t pwrdn_st = mmio_read_32(PMU_BASE + PMU_PWRDN_ST) & BIT(pd);
if (pwrdn_st)
return pmu_pd_off;
else
return pmu_pd_on;
}
static int pmu_power_domain_ctr(uint32_t pd, uint32_t pd_state)
{
uint32_t val;
uint32_t loop = 0;
int ret = 0;
rockchip_pd_lock_get();
val = mmio_read_32(PMU_BASE + PMU_PWRDN_CON);
if (pd_state == pmu_pd_off)
val |= BIT(pd);
else
val &= ~BIT(pd);
mmio_write_32(PMU_BASE + PMU_PWRDN_CON, val);
dsb();
while ((pmu_power_domain_st(pd) != pd_state) && (loop < PD_CTR_LOOP)) {
udelay(1);
loop++;
}
if (pmu_power_domain_st(pd) != pd_state) {
WARN("%s: %d, %d, error!\n", __func__, pd, pd_state);
ret = -EINVAL;
}
rockchip_pd_lock_rls();
return ret;
}
static int check_cpu_wfie(uint32_t cpu_id, uint32_t wfie_msk)
{
uint32_t cluster_id, loop = 0;
if (cpu_id >= PLATFORM_CLUSTER0_CORE_COUNT) {
cluster_id = 1;
cpu_id -= PLATFORM_CLUSTER0_CORE_COUNT;
} else {
cluster_id = 0;
}
/*
* wfe/wfi tracking not possible, hopefully the host
* was sucessful in enabling wfe/wfi.
* We'll give a bit of additional time, like the kernel does.
*/
if ((cluster_id && clstb_cpu_wfe < 0) ||
(!cluster_id && clstl_cpu_wfe < 0)) {
mdelay(1);
return 0;
}
if (cluster_id)
wfie_msk <<= (clstb_cpu_wfe + cpu_id);
else
wfie_msk <<= (clstl_cpu_wfe + cpu_id);
while (!(mmio_read_32(CHECK_CPU_WFIE_BASE) & wfie_msk) &&
(loop < CHK_CPU_LOOP)) {
udelay(1);
loop++;
}
if ((mmio_read_32(CHECK_CPU_WFIE_BASE) & wfie_msk) == 0) {
WARN("%s: %d, %d, %d, error!\n", __func__,
cluster_id, cpu_id, wfie_msk);
return -EINVAL;
}
return 0;
}
#endif /* PMU_COM_H */