File indexing completed on 2025-05-11 08:23:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051 #ifndef LIBCPU_POWERPC_MPC55XX_H
0052 #define LIBCPU_POWERPC_MPC55XX_H
0053
0054 #include <mpc55xx/regs.h>
0055 #include <mpc55xx/regs-mmu.h>
0056
0057 #include <libcpu/powerpc-utility.h>
0058
0059 #ifdef __cplusplus
0060 extern "C" {
0061 #endif
0062
0063 int mpc55xx_flash_copy(void *dest, const void *src, size_t nbytes);
0064 int mpc55xx_flash_copy_op(void *rdest, const void *src, size_t nbytes,
0065 uint32_t opmask, uint32_t *p_fail_addr);
0066 int mpc55xx_flash_size(uint32_t *p_size);
0067 int mpc55xx_flash_writable(void);
0068 uint32_t mpc55xx_flash_address(void);
0069 void mpc55xx_flash_set_read_only(void);
0070 void mpc55xx_flash_set_read_write(void);
0071
0072 int mpc55xx_physical_address(const void *addr, uint32_t *p_result);
0073 int mpc55xx_mapped_address(const void *addr, uint32_t *p_result);
0074
0075
0076 #define MPC55XX_FLASH_BLANK_CHECK 0x01
0077 #define MPC55XX_FLASH_UNLOCK 0x02
0078 #define MPC55XX_FLASH_ERASE 0x04
0079 #define MPC55XX_FLASH_PROGRAM 0x08
0080 #define MPC55XX_FLASH_VERIFY 0x10
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092 #define MPC55XX_FLASH_CONFIG_ERR (-1)
0093 #define MPC55XX_FLASH_SIZE_ERR (-2)
0094 #define MPC55XX_FLASH_RANGE_ERR (-3)
0095 #define MPC55XX_FLASH_ERASE_ERR (-4)
0096 #define MPC55XX_FLASH_PROGRAM_ERR (-5)
0097 #define MPC55XX_FLASH_NOT_BLANK_ERR (-6)
0098 #define MPC55XX_FLASH_VERIFY_ERR (-7)
0099 #define MPC55XX_FLASH_LOCK_ERR (-8)
0100
0101 #define MPC55XX_CACHE_ALIGNED_MASK ((uintptr_t) 0x1f)
0102
0103 #define MPC55XX_CACHE_LINE_SIZE 32
0104
0105
0106
0107
0108 static inline int mpc55xx_is_cache_aligned( const void *s, size_t n)
0109 {
0110 return !(((uintptr_t) s & MPC55XX_CACHE_ALIGNED_MASK) || (n & MPC55XX_CACHE_ALIGNED_MASK));
0111 }
0112
0113 static inline uintptr_t mpc55xx_cache_aligned_start( const void *s)
0114 {
0115 return ((uintptr_t) s & MPC55XX_CACHE_ALIGNED_MASK) ? (((uintptr_t) s & ~MPC55XX_CACHE_ALIGNED_MASK) + MPC55XX_CACHE_LINE_SIZE) : (uintptr_t)s;
0116 }
0117
0118 static inline size_t mpc55xx_non_cache_aligned_size( const void *s)
0119 {
0120 return (uintptr_t) mpc55xx_cache_aligned_start( s) - (uintptr_t) s;
0121 }
0122
0123 static inline size_t mpc55xx_cache_aligned_size( const void *s, size_t n)
0124 {
0125 return (n - mpc55xx_non_cache_aligned_size( s)) & ~MPC55XX_CACHE_ALIGNED_MASK;
0126 }
0127
0128
0129
0130
0131 static inline uint32_t mpc55xx_count_leading_zeros( uint32_t value)
0132 {
0133 uint32_t count;
0134 __asm__ (
0135 "cntlzw %0, %1;"
0136 : "=r" (count)
0137 : "r" (value)
0138 );
0139 return count;
0140 }
0141
0142 static inline void mpc55xx_wait_for_interrupt(void)
0143 {
0144 #ifdef MPC55XX_HAS_WAIT_INSTRUCTION
0145 __asm__ volatile (
0146 ".machine \"push\"\n"
0147 ".machine \"any\"\n"
0148 "wait\n"
0149 ".machine \"pop\""
0150 );
0151 #else
0152 __asm__ volatile ("");
0153 #endif
0154 }
0155
0156 static inline void mpc55xx_mmu_apply_config(const struct MMU_tag *config)
0157 {
0158 PPC_SET_SPECIAL_PURPOSE_REGISTER(FSL_EIS_MAS0, config->MAS0.R);
0159 PPC_SET_SPECIAL_PURPOSE_REGISTER(FSL_EIS_MAS1, config->MAS1.R);
0160 PPC_SET_SPECIAL_PURPOSE_REGISTER(FSL_EIS_MAS2, config->MAS2.R);
0161 PPC_SET_SPECIAL_PURPOSE_REGISTER(FSL_EIS_MAS3, config->MAS3.R);
0162 __asm__ volatile ("tlbwe");
0163 }
0164
0165 #ifdef __cplusplus
0166 }
0167 #endif
0168
0169 #endif