2024-04-03 16:40:57 +08:00
|
|
|
/*
|
2025-01-08 19:12:06 +08:00
|
|
|
* Copyright (c) 2022-2024, ArtInChip Technology Co., Ltd
|
2023-08-30 16:21:18 +08:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <aic_core.h>
|
2023-11-09 20:19:51 +08:00
|
|
|
#include <aic_hal.h>
|
2023-08-30 16:21:18 +08:00
|
|
|
|
|
|
|
|
#define align_cache_line(addr, len, a, l) \
|
|
|
|
|
unsigned long a = (unsigned long)addr; \
|
|
|
|
|
unsigned long l = (unsigned long)len; \
|
|
|
|
|
if (addr % CACHE_LINE_SIZE) { \
|
|
|
|
|
a -= (addr % CACHE_LINE_SIZE); \
|
|
|
|
|
l += (addr % CACHE_LINE_SIZE); \
|
|
|
|
|
} \
|
|
|
|
|
if (l % CACHE_LINE_SIZE) { \
|
|
|
|
|
l += CACHE_LINE_SIZE - (l % CACHE_LINE_SIZE); \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void aicmac_low_level_init(uint32_t port, bool en)
|
|
|
|
|
{
|
|
|
|
|
uint32_t id = CLK_GMAC0 + port;
|
|
|
|
|
|
|
|
|
|
/* pin-mux */
|
|
|
|
|
|
|
|
|
|
/* mac clock */
|
|
|
|
|
if (en) {
|
|
|
|
|
/* Set clock frequence = 50M */
|
|
|
|
|
hal_clk_set_freq(id, 50000000);
|
|
|
|
|
/* clock enable & reset deassert */
|
|
|
|
|
hal_clk_enable_deassertrst_iter(id);
|
|
|
|
|
} else {
|
|
|
|
|
/* clock enable & reset deassert */
|
|
|
|
|
hal_clk_disable_assertrst(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void aicmac_dcache_clean(uintptr_t addr, uint32_t len)
|
|
|
|
|
{
|
|
|
|
|
#ifndef CONFIG_MAC_USE_UNCACHE_BUF
|
|
|
|
|
align_cache_line(addr, len, a, l);
|
|
|
|
|
aicos_dcache_clean_range((unsigned long *)a, (int64_t)l);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void aicmac_dcache_invalid(uintptr_t addr, uint32_t len)
|
|
|
|
|
{
|
|
|
|
|
#ifndef CONFIG_MAC_USE_UNCACHE_BUF
|
|
|
|
|
align_cache_line(addr, len, a, l);
|
|
|
|
|
aicos_dcache_invalid_range((unsigned long *)a, (int64_t)l);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void aicmac_dcache_clean_invalid(uintptr_t addr, uint32_t len)
|
|
|
|
|
{
|
|
|
|
|
#ifndef CONFIG_MAC_USE_UNCACHE_BUF
|
|
|
|
|
align_cache_line(addr, len, a, l);
|
|
|
|
|
aicos_dcache_clean_invalid_range((unsigned long *)a, (int64_t)l);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-03 16:40:57 +08:00
|
|
|
void aicmac_gdma_sync(void)
|
|
|
|
|
{
|
|
|
|
|
aicos_dma_sync();
|
|
|
|
|
}
|