10d163575Sopenharmony_ci/* 20d163575Sopenharmony_ci * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 30d163575Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 40d163575Sopenharmony_ci * 50d163575Sopenharmony_ci * Redistribution and use in source and binary forms, with or without modification, 60d163575Sopenharmony_ci * are permitted provided that the following conditions are met: 70d163575Sopenharmony_ci * 80d163575Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, this list of 90d163575Sopenharmony_ci * conditions and the following disclaimer. 100d163575Sopenharmony_ci * 110d163575Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, this list 120d163575Sopenharmony_ci * of conditions and the following disclaimer in the documentation and/or other materials 130d163575Sopenharmony_ci * provided with the distribution. 140d163575Sopenharmony_ci * 150d163575Sopenharmony_ci * 3. Neither the name of the copyright holder nor the names of its contributors may be used 160d163575Sopenharmony_ci * to endorse or promote products derived from this software without specific prior written 170d163575Sopenharmony_ci * permission. 180d163575Sopenharmony_ci * 190d163575Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 200d163575Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 210d163575Sopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 220d163575Sopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 230d163575Sopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 240d163575Sopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 250d163575Sopenharmony_ci * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 260d163575Sopenharmony_ci * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 270d163575Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 280d163575Sopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 290d163575Sopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 300d163575Sopenharmony_ci */ 310d163575Sopenharmony_ci 320d163575Sopenharmony_ci/** 330d163575Sopenharmony_ci * @defgroup los_hw Hardware 340d163575Sopenharmony_ci * @ingroup kernel 350d163575Sopenharmony_ci */ 360d163575Sopenharmony_ci#ifndef _LOS_HW_H 370d163575Sopenharmony_ci#define _LOS_HW_H 380d163575Sopenharmony_ci 390d163575Sopenharmony_ci#include "los_typedef.h" 400d163575Sopenharmony_ci#include "los_hw_cpu.h" 410d163575Sopenharmony_ci#ifdef __cplusplus 420d163575Sopenharmony_ci#if __cplusplus 430d163575Sopenharmony_ciextern "C" { 440d163575Sopenharmony_ci#endif /* __cplusplus */ 450d163575Sopenharmony_ci#endif /* __cplusplus */ 460d163575Sopenharmony_ci 470d163575Sopenharmony_ci#define OS_SCHEDULE_IN_IRQ 0x0 480d163575Sopenharmony_ci#define OS_SCHEDULE_IN_TASK 0x1 490d163575Sopenharmony_ci 500d163575Sopenharmony_ci#define PSR_T_ARM 0x00000000u 510d163575Sopenharmony_ci#define PSR_T_THUMB 0x00000020u 520d163575Sopenharmony_ci#define PSR_MODE_SVC 0x00000013u 530d163575Sopenharmony_ci#define PSR_MODE_SYS 0x0000001Fu 540d163575Sopenharmony_ci#define PSR_FIQ_DIS 0x00000040u 550d163575Sopenharmony_ci#define PSR_IRQ_DIS 0x00000080u 560d163575Sopenharmony_ci#define PSR_MODE_USR 0x00000010u 570d163575Sopenharmony_ci 580d163575Sopenharmony_ci#define PSR_MODE_SVC_THUMB (PSR_MODE_SVC | PSR_T_THUMB | PSR_FIQ_DIS | PSR_IRQ_DIS) 590d163575Sopenharmony_ci#define PSR_MODE_SVC_ARM (PSR_MODE_SVC | PSR_T_ARM | PSR_FIQ_DIS | PSR_IRQ_DIS) 600d163575Sopenharmony_ci 610d163575Sopenharmony_ci#define PSR_MODE_SYS_THUMB (PSR_MODE_SYS | PSR_T_THUMB) 620d163575Sopenharmony_ci#define PSR_MODE_SYS_ARM (PSR_MODE_SYS | PSR_T_ARM) 630d163575Sopenharmony_ci 640d163575Sopenharmony_ci#define PSR_MODE_USR_THUMB (PSR_MODE_USR | PSR_T_THUMB) 650d163575Sopenharmony_ci#define PSR_MODE_USR_ARM (PSR_MODE_USR | PSR_T_ARM) 660d163575Sopenharmony_ci 670d163575Sopenharmony_ci#define LOS_CHECK_SCHEDULE ((!OS_INT_ACTIVE) && OsPreemptable()) 680d163575Sopenharmony_ci 690d163575Sopenharmony_citypedef struct { 700d163575Sopenharmony_ci const UINT32 partNo; 710d163575Sopenharmony_ci const CHAR *cpuName; 720d163575Sopenharmony_ci} CpuVendor; 730d163575Sopenharmony_ci 740d163575Sopenharmony_ciextern CpuVendor g_cpuTable[]; 750d163575Sopenharmony_ciextern UINT64 g_cpuMap[]; 760d163575Sopenharmony_ci 770d163575Sopenharmony_ci#define CPU_MAP_GET(cpuid) g_cpuMap[(cpuid)] 780d163575Sopenharmony_ci#define CPU_MAP_SET(cpuid, hwid) g_cpuMap[(cpuid)] = (hwid) 790d163575Sopenharmony_ci 800d163575Sopenharmony_ci/** 810d163575Sopenharmony_ci * @ingroup los_hw 820d163575Sopenharmony_ci * @brief Invalidate instruction cache. 830d163575Sopenharmony_ci * 840d163575Sopenharmony_ci * @par Description: 850d163575Sopenharmony_ci * <ul> 860d163575Sopenharmony_ci * <li>This API is used to invalidate the instruction cache.</li> 870d163575Sopenharmony_ci * </ul> 880d163575Sopenharmony_ci * @attention None. 890d163575Sopenharmony_ci * 900d163575Sopenharmony_ci * @param None. 910d163575Sopenharmony_ci * 920d163575Sopenharmony_ci * @retval #None. 930d163575Sopenharmony_ci * 940d163575Sopenharmony_ci * @par Dependency: 950d163575Sopenharmony_ci * los_hw.h: the header file that contains the API declaration. 960d163575Sopenharmony_ci * @see None. 970d163575Sopenharmony_ci */ 980d163575Sopenharmony_ciextern VOID FlushICache(VOID); 990d163575Sopenharmony_ci 1000d163575Sopenharmony_ci/** 1010d163575Sopenharmony_ci * @ingroup los_hw 1020d163575Sopenharmony_ci * @brief Flush data cache. 1030d163575Sopenharmony_ci * 1040d163575Sopenharmony_ci * @par Description: 1050d163575Sopenharmony_ci * <ul> 1060d163575Sopenharmony_ci * <li>This API is used to flush the data cache to the memory.</li> 1070d163575Sopenharmony_ci * </ul> 1080d163575Sopenharmony_ci * @attention 1090d163575Sopenharmony_ci * <ul> 1100d163575Sopenharmony_ci * <li>The input end address must be greater than the input start address.</li> 1110d163575Sopenharmony_ci * </ul> 1120d163575Sopenharmony_ci * 1130d163575Sopenharmony_ci * @param start [IN] Type #int Flush start address. 1140d163575Sopenharmony_ci * @param end [IN] Type #int Flush end address. 1150d163575Sopenharmony_ci * 1160d163575Sopenharmony_ci * @retval #None. 1170d163575Sopenharmony_ci * 1180d163575Sopenharmony_ci * @par Dependency: 1190d163575Sopenharmony_ci * los_hw.h: the header file that contains the API declaration. 1200d163575Sopenharmony_ci * @see None. 1210d163575Sopenharmony_ci */ 1220d163575Sopenharmony_ciextern VOID DCacheFlushRange(UINTPTR start, UINTPTR end); 1230d163575Sopenharmony_ci 1240d163575Sopenharmony_ci/** 1250d163575Sopenharmony_ci * @ingroup los_hw 1260d163575Sopenharmony_ci * @brief Invalidate data cache. 1270d163575Sopenharmony_ci * 1280d163575Sopenharmony_ci * @par Description: 1290d163575Sopenharmony_ci * <ul> 1300d163575Sopenharmony_ci * <li>This API is used to Invalidate the data in cache.</li> 1310d163575Sopenharmony_ci * </ul> 1320d163575Sopenharmony_ci * @attention 1330d163575Sopenharmony_ci * <ul> 1340d163575Sopenharmony_ci * <li>The input end address must be greater than the input start address.</li> 1350d163575Sopenharmony_ci * </ul> 1360d163575Sopenharmony_ci * 1370d163575Sopenharmony_ci * @param start [IN] Type #int Invalidate start address. 1380d163575Sopenharmony_ci * @param end [IN] Type #int Invalidate end address . 1390d163575Sopenharmony_ci * 1400d163575Sopenharmony_ci * @retval #None. 1410d163575Sopenharmony_ci * 1420d163575Sopenharmony_ci * @par Dependency: 1430d163575Sopenharmony_ci * los_hw.h: the header file that contains the API declaration. 1440d163575Sopenharmony_ci * @see None. 1450d163575Sopenharmony_ci */ 1460d163575Sopenharmony_ciextern VOID DCacheInvRange(UINTPTR start, UINTPTR end); 1470d163575Sopenharmony_ci 1480d163575Sopenharmony_ci/** 1490d163575Sopenharmony_ci * @ingroup los_hw 1500d163575Sopenharmony_ci * @brief Get cpu core name. 1510d163575Sopenharmony_ci * 1520d163575Sopenharmony_ci * @par Description: 1530d163575Sopenharmony_ci * <ul> 1540d163575Sopenharmony_ci * <li>This API is used to get cpu core name.</li> 1550d163575Sopenharmony_ci * </ul> 1560d163575Sopenharmony_ci * @attention 1570d163575Sopenharmony_ci * <ul> 1580d163575Sopenharmony_ci * <li>None.</li> 1590d163575Sopenharmony_ci * </ul> 1600d163575Sopenharmony_ci * 1610d163575Sopenharmony_ci * @param 1620d163575Sopenharmony_ci * @retval #CHAR * cpu core name. 1630d163575Sopenharmony_ci * 1640d163575Sopenharmony_ci * @par Dependency: 1650d163575Sopenharmony_ci * los_hw.h: the header file that contains the API declaration. 1660d163575Sopenharmony_ci * @see None. 1670d163575Sopenharmony_ci */ 1680d163575Sopenharmony_ciSTATIC INLINE const CHAR *LOS_CpuInfo(VOID) 1690d163575Sopenharmony_ci{ 1700d163575Sopenharmony_ci INT32 i; 1710d163575Sopenharmony_ci UINT32 midr = OsMainIDGet(); 1720d163575Sopenharmony_ci /* [15:4] is the primary part number */ 1730d163575Sopenharmony_ci UINT32 partNo = (midr & 0xFFF0) >> 0x4; 1740d163575Sopenharmony_ci 1750d163575Sopenharmony_ci for (i = 0; g_cpuTable[i].partNo != 0; i++) { 1760d163575Sopenharmony_ci if (partNo == g_cpuTable[i].partNo) { 1770d163575Sopenharmony_ci return g_cpuTable[i].cpuName; 1780d163575Sopenharmony_ci } 1790d163575Sopenharmony_ci } 1800d163575Sopenharmony_ci 1810d163575Sopenharmony_ci return "unknown"; 1820d163575Sopenharmony_ci} 1830d163575Sopenharmony_ci 1840d163575Sopenharmony_ci#ifdef __cplusplus 1850d163575Sopenharmony_ci#if __cplusplus 1860d163575Sopenharmony_ci} 1870d163575Sopenharmony_ci#endif /* __cplusplus */ 1880d163575Sopenharmony_ci#endif /* __cplusplus */ 1890d163575Sopenharmony_ci 1900d163575Sopenharmony_ci#endif /* _LOS_HW_H */ 191