Avoid beyond bounds copy while caching ACL
[zen-stable.git] / drivers / staging / tidspbridge / dynload / params.h
blobd797fcd3b66236c79fac19759b36bfaa2330aaf5
1 /*
2 * params.h
4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
6 * This file defines host and target properties for all machines
7 * supported by the dynamic loader. To be tedious...
9 * host: the machine on which the dynamic loader runs
10 * target: the machine that the dynamic loader is loading
12 * Host and target may or may not be the same, depending upon the particular
13 * use.
15 * Copyright (C) 2005-2006 Texas Instruments, Inc.
17 * This package is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License version 2 as
19 * published by the Free Software Foundation.
21 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
23 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26 /******************************************************************************
28 * Host Properties
30 **************************************************************************** */
32 #define BITS_PER_BYTE 8 /* bits in the standard PC/SUN byte */
33 #define LOG_BITS_PER_BYTE 3 /* log base 2 of same */
34 #define BYTE_MASK ((1U<<BITS_PER_BYTE)-1)
36 #if defined(__TMS320C55X__) || defined(_TMS320C5XX)
37 #define BITS_PER_AU 16
38 #define LOG_BITS_PER_AU 4
39 /* use this print string in error messages for uint32_t */
40 #define FMT_UI32 "0x%lx"
41 #define FMT8_UI32 "%08lx" /* same but no 0x, fixed width field */
42 #else
43 /* bits in the smallest addressable data storage unit */
44 #define BITS_PER_AU 8
45 /* log base 2 of the same; useful for shift counts */
46 #define LOG_BITS_PER_AU 3
47 #define FMT_UI32 "0x%x"
48 #define FMT8_UI32 "%08x"
49 #endif
51 /* generic fastest method for swapping bytes and shorts */
52 #define SWAP32BY16(zz) (((zz) << 16) | ((zz) >> 16))
53 #define SWAP16BY8(zz) (((zz) << 8) | ((zz) >> 8))
55 /* !! don't be tempted to insert type definitions here; use <stdint.h> !! */
57 /******************************************************************************
59 * Target Properties
61 **************************************************************************** */
63 /*-------------------------------------------------------------------------- */
64 /* TMS320C6x Target Specific Parameters (byte-addressable) */
65 /*-------------------------------------------------------------------------- */
66 #if TMS32060
67 #define MEMORG 0x0L /* Size of configured memory */
68 #define MEMSIZE 0x0L /* (full address space) */
70 #define CINIT_ALIGN 8 /* alignment of cinit record in TDATA AUs */
71 #define CINIT_COUNT 4 /* width of count field in TDATA AUs */
72 #define CINIT_ADDRESS 4 /* width of address field in TDATA AUs */
73 #define CINIT_PAGE_BITS 0 /* Number of LSBs of address that
74 * are page number */
76 #define LENIENT_SIGNED_RELEXPS 0 /* DOES SIGNED ALLOW MAX UNSIGNED */
78 #undef TARGET_ENDIANNESS /* may be big or little endian */
80 /* align a target address to a word boundary */
81 #define TARGET_WORD_ALIGN(zz) (((zz) + 0x3) & -0x4)
82 #endif
84 /*--------------------------------------------------------------------------
86 * DEFAULT SETTINGS and DERIVED PROPERTIES
88 * This section establishes defaults for values not specified above
89 *-------------------------------------------------------------------------- */
90 #ifndef TARGET_AU_BITS
91 #define TARGET_AU_BITS 8 /* width of the target addressable unit */
92 #define LOG_TARGET_AU_BITS 3 /* log2 of same */
93 #endif
95 #ifndef CINIT_DEFAULT_PAGE
96 #define CINIT_DEFAULT_PAGE 0 /* default .cinit page number */
97 #endif
99 #ifndef DATA_RUN2LOAD
100 #define DATA_RUN2LOAD(zz) (zz) /* translate data run address to load address */
101 #endif
103 #ifndef DBG_LIST_PAGE
104 #define DBG_LIST_PAGE 0 /* page number for .dllview section */
105 #endif
107 #ifndef TARGET_WORD_ALIGN
108 /* align a target address to a word boundary */
109 #define TARGET_WORD_ALIGN(zz) (zz)
110 #endif
112 #ifndef TDATA_TO_TADDR
113 #define TDATA_TO_TADDR(zz) (zz) /* target data address to target AU address */
114 #define TADDR_TO_TDATA(zz) (zz) /* target AU address to target data address */
115 #define TDATA_AU_BITS TARGET_AU_BITS /* bits per data AU */
116 #define LOG_TDATA_AU_BITS LOG_TARGET_AU_BITS
117 #endif
121 * Useful properties and conversions derived from the above
126 * Conversions between host and target addresses
128 #if LOG_BITS_PER_AU == LOG_TARGET_AU_BITS
129 /* translate target addressable unit to host address */
130 #define TADDR_TO_HOST(x) (x)
131 /* translate host address to target addressable unit */
132 #define HOST_TO_TADDR(x) (x)
133 #elif LOG_BITS_PER_AU > LOG_TARGET_AU_BITS
134 #define TADDR_TO_HOST(x) ((x) >> (LOG_BITS_PER_AU-LOG_TARGET_AU_BITS))
135 #define HOST_TO_TADDR(x) ((x) << (LOG_BITS_PER_AU-LOG_TARGET_AU_BITS))
136 #else
137 #define TADDR_TO_HOST(x) ((x) << (LOG_TARGET_AU_BITS-LOG_BITS_PER_AU))
138 #define HOST_TO_TADDR(x) ((x) >> (LOG_TARGET_AU_BITS-LOG_BITS_PER_AU))
139 #endif
141 #if LOG_BITS_PER_AU == LOG_TDATA_AU_BITS
142 /* translate target addressable unit to host address */
143 #define TDATA_TO_HOST(x) (x)
144 /* translate host address to target addressable unit */
145 #define HOST_TO_TDATA(x) (x)
146 /* translate host address to target addressable unit, round up */
147 #define HOST_TO_TDATA_ROUND(x) (x)
148 /* byte offset to host offset, rounded up for TDATA size */
149 #define BYTE_TO_HOST_TDATA_ROUND(x) BYTE_TO_HOST_ROUND(x)
150 #elif LOG_BITS_PER_AU > LOG_TDATA_AU_BITS
151 #define TDATA_TO_HOST(x) ((x) >> (LOG_BITS_PER_AU-LOG_TDATA_AU_BITS))
152 #define HOST_TO_TDATA(x) ((x) << (LOG_BITS_PER_AU-LOG_TDATA_AU_BITS))
153 #define HOST_TO_TDATA_ROUND(x) ((x) << (LOG_BITS_PER_AU-LOG_TDATA_AU_BITS))
154 #define BYTE_TO_HOST_TDATA_ROUND(x) BYTE_TO_HOST_ROUND(x)
155 #else
156 #define TDATA_TO_HOST(x) ((x) << (LOG_TDATA_AU_BITS-LOG_BITS_PER_AU))
157 #define HOST_TO_TDATA(x) ((x) >> (LOG_TDATA_AU_BITS-LOG_BITS_PER_AU))
158 #define HOST_TO_TDATA_ROUND(x) (((x) +\
159 (1<<(LOG_TDATA_AU_BITS-LOG_BITS_PER_AU))-1) >>\
160 (LOG_TDATA_AU_BITS-LOG_BITS_PER_AU))
161 #define BYTE_TO_HOST_TDATA_ROUND(x) (BYTE_TO_HOST((x) +\
162 (1<<(LOG_TDATA_AU_BITS-LOG_BITS_PER_BYTE))-1) &\
163 -(TDATA_AU_BITS/BITS_PER_AU))
164 #endif
167 * Input in DOFF format is always expresed in bytes, regardless of loading host
168 * so we wind up converting from bytes to target and host units even when the
169 * host is not a byte machine.
171 #if LOG_BITS_PER_AU == LOG_BITS_PER_BYTE
172 #define BYTE_TO_HOST(x) (x)
173 #define BYTE_TO_HOST_ROUND(x) (x)
174 #define HOST_TO_BYTE(x) (x)
175 #elif LOG_BITS_PER_AU >= LOG_BITS_PER_BYTE
176 #define BYTE_TO_HOST(x) ((x) >> (LOG_BITS_PER_AU - LOG_BITS_PER_BYTE))
177 #define BYTE_TO_HOST_ROUND(x) ((x + (BITS_PER_AU/BITS_PER_BYTE-1)) >>\
178 (LOG_BITS_PER_AU - LOG_BITS_PER_BYTE))
179 #define HOST_TO_BYTE(x) ((x) << (LOG_BITS_PER_AU - LOG_BITS_PER_BYTE))
180 #else
181 /* lets not try to deal with sub-8-bit byte machines */
182 #endif
184 #if LOG_TARGET_AU_BITS == LOG_BITS_PER_BYTE
185 /* translate target addressable unit to byte address */
186 #define TADDR_TO_BYTE(x) (x)
187 /* translate byte address to target addressable unit */
188 #define BYTE_TO_TADDR(x) (x)
189 #elif LOG_TARGET_AU_BITS > LOG_BITS_PER_BYTE
190 #define TADDR_TO_BYTE(x) ((x) << (LOG_TARGET_AU_BITS-LOG_BITS_PER_BYTE))
191 #define BYTE_TO_TADDR(x) ((x) >> (LOG_TARGET_AU_BITS-LOG_BITS_PER_BYTE))
192 #else
193 /* lets not try to deal with sub-8-bit byte machines */
194 #endif
196 #ifdef _BIG_ENDIAN
197 #define HOST_ENDIANNESS 1
198 #else
199 #define HOST_ENDIANNESS 0
200 #endif
202 #ifdef TARGET_ENDIANNESS
203 #define TARGET_ENDIANNESS_DIFFERS(rtend) (HOST_ENDIANNESS^TARGET_ENDIANNESS)
204 #elif HOST_ENDIANNESS
205 #define TARGET_ENDIANNESS_DIFFERS(rtend) (!(rtend))
206 #else
207 #define TARGET_ENDIANNESS_DIFFERS(rtend) (rtend)
208 #endif
210 /* the unit in which we process target image data */
211 #if TARGET_AU_BITS <= 8
212 typedef u8 tgt_au_t;
213 #elif TARGET_AU_BITS <= 16
214 typedef u16 tgt_au_t;
215 #else
216 typedef u32 tgt_au_t;
217 #endif
219 /* size of that unit */
220 #if TARGET_AU_BITS < BITS_PER_AU
221 #define TGTAU_BITS BITS_PER_AU
222 #define LOG_TGTAU_BITS LOG_BITS_PER_AU
223 #else
224 #define TGTAU_BITS TARGET_AU_BITS
225 #define LOG_TGTAU_BITS LOG_TARGET_AU_BITS
226 #endif