RTEMS 6.1-rc6
Loading...
Searching...
No Matches
mpc55xx.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
11/*
12 * Copyright (C) 2008, 2012 embedded brains GmbH & Co. KG
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
51#ifndef LIBCPU_POWERPC_MPC55XX_H
52#define LIBCPU_POWERPC_MPC55XX_H
53
54#include <mpc55xx/regs.h>
55#include <mpc55xx/regs-mmu.h>
56
58
59#ifdef __cplusplus
60extern "C" {
61#endif /* __cplusplus */
62
63int mpc55xx_flash_copy(void *dest, const void *src, size_t nbytes);
64int mpc55xx_flash_copy_op(void *rdest, const void *src, size_t nbytes,
65 uint32_t opmask, uint32_t *p_fail_addr);
66int mpc55xx_flash_size(uint32_t *p_size);
67int mpc55xx_flash_writable(void);
68uint32_t mpc55xx_flash_address(void);
69void mpc55xx_flash_set_read_only(void);
70void mpc55xx_flash_set_read_write(void);
71
72int mpc55xx_physical_address(const void *addr, uint32_t *p_result);
73int mpc55xx_mapped_address(const void *addr, uint32_t *p_result);
74
75/* Bits for opmask. */
76#define MPC55XX_FLASH_BLANK_CHECK 0x01
77#define MPC55XX_FLASH_UNLOCK 0x02
78#define MPC55XX_FLASH_ERASE 0x04
79#define MPC55XX_FLASH_PROGRAM 0x08
80#define MPC55XX_FLASH_VERIFY 0x10
81
82/* Error returns. CONFIG or SIZE might mean you just
83 * need to check for new configuration bits.
84 * SIZE and RANGE mean you are outside of a known flash region.
85 * ERASE means the erase failed,
86 * PROGRAM means the program failed,
87 * BLANK means it wasn't blank and BLANK_CHECK was specified,
88 * VERIFY means VERIFY was set and it didn't match the source,
89 * and LOCK means either the locking failed or you needed to
90 * specify MPC55XX_FLASH_UNLOCK and didn't.
91 */
92#define MPC55XX_FLASH_CONFIG_ERR (-1)
93#define MPC55XX_FLASH_SIZE_ERR (-2)
94#define MPC55XX_FLASH_RANGE_ERR (-3)
95#define MPC55XX_FLASH_ERASE_ERR (-4)
96#define MPC55XX_FLASH_PROGRAM_ERR (-5)
97#define MPC55XX_FLASH_NOT_BLANK_ERR (-6)
98#define MPC55XX_FLASH_VERIFY_ERR (-7)
99#define MPC55XX_FLASH_LOCK_ERR (-8)
100
101#define MPC55XX_CACHE_ALIGNED_MASK ((uintptr_t) 0x1f)
102
103#define MPC55XX_CACHE_LINE_SIZE 32
104
108static inline int mpc55xx_is_cache_aligned( const void *s, size_t n)
109{
110 return !(((uintptr_t) s & MPC55XX_CACHE_ALIGNED_MASK) || (n & MPC55XX_CACHE_ALIGNED_MASK));
111}
112
113static inline uintptr_t mpc55xx_cache_aligned_start( const void *s)
114{
115 return ((uintptr_t) s & MPC55XX_CACHE_ALIGNED_MASK) ? (((uintptr_t) s & ~MPC55XX_CACHE_ALIGNED_MASK) + MPC55XX_CACHE_LINE_SIZE) : (uintptr_t)s;
116}
117
118static inline size_t mpc55xx_non_cache_aligned_size( const void *s)
119{
120 return (uintptr_t) mpc55xx_cache_aligned_start( s) - (uintptr_t) s;
121}
122
123static inline size_t mpc55xx_cache_aligned_size( const void *s, size_t n)
124{
125 return (n - mpc55xx_non_cache_aligned_size( s)) & ~MPC55XX_CACHE_ALIGNED_MASK;
126}
127
131static inline uint32_t mpc55xx_count_leading_zeros( uint32_t value)
132{
133 uint32_t count;
134 __asm__ (
135 "cntlzw %0, %1;"
136 : "=r" (count)
137 : "r" (value)
138 );
139 return count;
140}
141
142static inline void mpc55xx_wait_for_interrupt(void)
143{
144 #ifdef MPC55XX_HAS_WAIT_INSTRUCTION
145 __asm__ volatile (
146 ".machine \"push\"\n"
147 ".machine \"any\"\n"
148 "wait\n"
149 ".machine \"pop\""
150 );
151 #else
152 __asm__ volatile ("");
153 #endif
154}
155
156static inline void mpc55xx_mmu_apply_config(const struct MMU_tag *config)
157{
158 PPC_SET_SPECIAL_PURPOSE_REGISTER(FSL_EIS_MAS0, config->MAS0.R);
159 PPC_SET_SPECIAL_PURPOSE_REGISTER(FSL_EIS_MAS1, config->MAS1.R);
160 PPC_SET_SPECIAL_PURPOSE_REGISTER(FSL_EIS_MAS2, config->MAS2.R);
161 PPC_SET_SPECIAL_PURPOSE_REGISTER(FSL_EIS_MAS3, config->MAS3.R);
162 __asm__ volatile ("tlbwe");
163}
164
165#ifdef __cplusplus
166}
167#endif /* __cplusplus */
168
169#endif /* LIBCPU_POWERPC_MPC55XX_H */
#define PPC_SET_SPECIAL_PURPOSE_REGISTER(spr, val)
Sets the Special Purpose Register with number spr to the value in val.
Definition: powerpc-utility.h:590
General purpose assembler macros, linker command file support and some inline functions for direct re...
Register definitions for the MPC55xx and MPC56xx microcontroller family.
Definition: regs-mmu.h:60
Definition: deflate.c:114