1 /* 2 * Copyright (c) 2016-2017 The Linux Foundation. All rights reserved. 3 * Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for 6 * any purpose with or without fee is hereby granted, provided that the 7 * above copyright notice and this permission notice appear in all 8 * copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #ifndef HAL_HWIO_H 21 #define HAL_HWIO_H 22 /* 23 =========================================================================== 24 */ 25 /** 26 @file HALhwio.h 27 28 Public interface include file for accessing the HWIO HAL definitions. 29 30 The HALhwio.h file is the public API interface to the HW I/O (HWIO) 31 register access definitions. 32 */ 33 34 /*========================================================================= 35 Include Files 36 ==========================================================================*/ 37 38 39 /* 40 * Common types. 41 */ 42 #include "HALcomdef.h" 43 44 45 46 /* ----------------------------------------------------------------------- 47 ** Macros 48 ** ----------------------------------------------------------------------- */ 49 50 /** 51 @addtogroup macros 52 @{ 53 */ 54 55 /** 56 * Map a base name to the pointer to access the base. 57 * 58 * This macro maps a base name to the pointer to access the base. 59 * This is generally just used internally. 60 * 61 */ 62 #define HWIO_BASE_PTR(base) base##_BASE_PTR 63 64 65 66 67 /** 68 * Declare a HWIO base pointer. 69 * 70 * This macro will declare a HWIO base pointer data structure. The pointer 71 * will always be declared as a weak symbol so multiple declarations will 72 * resolve correctly to the same data at link-time. 73 */ 74 #ifdef __ARMCC_VERSION 75 #define DECLARE_HWIO_BASE_PTR(base) __weak uint8 *HWIO_BASE_PTR(base) 76 #else 77 #define DECLARE_HWIO_BASE_PTR(base) uint8 *HWIO_BASE_PTR(base) 78 #endif 79 80 /** 81 @} 82 */ 83 84 85 /** 86 @addtogroup hwio_macros 87 @{ 88 */ 89 90 /** 91 * @name Address Macros 92 * 93 * Macros for getting register addresses. 94 * These macros are used for retrieving the address of a register. 95 * HWIO_ADDR* will return the directly accessible address (virtual or physical based 96 * on environment), HWIO_PHYS* will always return the physical address. 97 * The offset from the base region can be retrieved using HWIO_OFFS*. 98 * The "X" extension is used for explicit addressing where the base address of 99 * the module in question is provided as an argument to the macro. 100 * 101 * @{ 102 */ 103 #define HWIO_ADDR(hwiosym) __msmhwio_addr(hwiosym) 104 #define HWIO_ADDRI(hwiosym, index) __msmhwio_addri(hwiosym, index) 105 #define HWIO_ADDRI2(hwiosym, index1, index2) __msmhwio_addri2(hwiosym, index1, index2) 106 #define HWIO_ADDRI3(hwiosym, index1, index2, index3) __msmhwio_addri3(hwiosym, index1, index2, index3) 107 108 #define HWIO_ADDRX(base, hwiosym) __msmhwio_addrx(base, hwiosym) 109 #define HWIO_ADDRXI(base, hwiosym, index) __msmhwio_addrxi(base, hwiosym, index) 110 #define HWIO_ADDRXI2(base, hwiosym, index1, index2) __msmhwio_addrxi2(base, hwiosym, index1, index2) 111 #define HWIO_ADDRXI3(base, hwiosym, index1, index2, index3) __msmhwio_addrxi3(base, hwiosym, index1, index2, index3) 112 113 #define HWIO_PHYS(hwiosym) __msmhwio_phys(hwiosym) 114 #define HWIO_PHYSI(hwiosym, index) __msmhwio_physi(hwiosym, index) 115 #define HWIO_PHYSI2(hwiosym, index1, index2) __msmhwio_physi2(hwiosym, index1, index2) 116 #define HWIO_PHYSI3(hwiosym, index1, index2, index3) __msmhwio_physi3(hwiosym, index1, index2, index3) 117 118 #define HWIO_PHYSX(base, hwiosym) __msmhwio_physx(base, hwiosym) 119 #define HWIO_PHYSXI(base, hwiosym, index) __msmhwio_physxi(base, hwiosym, index) 120 #define HWIO_PHYSXI2(base, hwiosym, index1, index2) __msmhwio_physxi2(base, hwiosym, index1, index2) 121 #define HWIO_PHYSXI3(base, hwiosym, index1, index2, index3) __msmhwio_physxi3(base, hwiosym, index1, index2, index3) 122 123 #define HWIO_OFFS(hwiosym) __msmhwio_offs(hwiosym) 124 #define HWIO_OFFSI(hwiosym, index) __msmhwio_offsi(hwiosym, index) 125 #define HWIO_OFFSI2(hwiosym, index1, index2) __msmhwio_offsi2(hwiosym, index1, index2) 126 #define HWIO_OFFSI3(hwiosym, index1, index2, index3) __msmhwio_offsi3(hwiosym, index1, index2, index3) 127 /** @} */ 128 129 /** 130 * @name Input Macros 131 * 132 * These macros are used for reading from a named hardware register. Register 133 * arrays ("indexed") use the macros with the "I" suffix. The "M" suffix 134 * indicates that the input will be masked with the supplied mask. The HWIO_INF* 135 * macros take a field name and will do the appropriate masking and shifting 136 * to return just the value of that field. 137 * The "X" extension is used for explicit addressing where the base address of 138 * the module in question is provided as an argument to the macro. 139 * 140 * Generally you want to use either HWIO_IN or HWIO_INF (with required indexing). 141 * 142 * @{ 143 */ 144 #define HWIO_IN(hwiosym) __msmhwio_in(hwiosym) 145 #define HWIO_INI(hwiosym, index) __msmhwio_ini(hwiosym, index) 146 #define HWIO_INI2(hwiosym, index1, index2) __msmhwio_ini2(hwiosym, index1, index2) 147 #define HWIO_INI3(hwiosym, index1, index2, index3) __msmhwio_ini3(hwiosym, index1, index2, index3) 148 149 #define HWIO_INM(hwiosym, mask) __msmhwio_inm(hwiosym, mask) 150 #define HWIO_INMI(hwiosym, index, mask) __msmhwio_inmi(hwiosym, index, mask) 151 #define HWIO_INMI2(hwiosym, index1, index2, mask) __msmhwio_inmi2(hwiosym, index1, index2, mask) 152 #define HWIO_INMI3(hwiosym, index1, index2, index3, mask) __msmhwio_inmi3(hwiosym, index1, index2, index3, mask) 153 154 #define HWIO_INF(io, field) (HWIO_INM(io, HWIO_FMSK(io, field)) >> HWIO_SHFT(io, field)) 155 #define HWIO_INFI(io, index, field) (HWIO_INMI(io, index, HWIO_FMSK(io, field)) >> HWIO_SHFT(io, field)) 156 #define HWIO_INFI2(io, index1, index2, field) (HWIO_INMI2(io, index1, index2, HWIO_FMSK(io, field)) >> HWIO_SHFT(io, field)) 157 #define HWIO_INFI3(io, index1, index2, index3, field) (HWIO_INMI3(io, index1, index2, index3, HWIO_FMSK(io, field)) >> HWIO_SHFT(io, field)) 158 159 #define HWIO_INX(base, hwiosym) __msmhwio_inx(base, hwiosym) 160 #define HWIO_INXI(base, hwiosym, index) __msmhwio_inxi(base, hwiosym, index) 161 #define HWIO_INXI2(base, hwiosym, index1, index2) __msmhwio_inxi2(base, hwiosym, index1, index2) 162 #define HWIO_INXI3(base, hwiosym, index1, index2, index3) __msmhwio_inxi3(base, hwiosym, index1, index2, index3) 163 164 #define HWIO_INXM(base, hwiosym, mask) __msmhwio_inxm(base, hwiosym, mask) 165 #define HWIO_INXMI(base, hwiosym, index, mask) __msmhwio_inxmi(base, hwiosym, index, mask) 166 #define HWIO_INXMI2(base, hwiosym, index1, index2, mask) __msmhwio_inxmi2(base, hwiosym, index1, index2, mask) 167 #define HWIO_INXMI3(base, hwiosym, index1, index2, index3, mask) __msmhwio_inxmi3(base, hwiosym, index1, index2, index3, mask) 168 169 #define HWIO_INXF(base, io, field) (HWIO_INXM(base, io, HWIO_FMSK(io, field)) >> HWIO_SHFT(io, field)) 170 #define HWIO_INXFI(base, io, index, field) (HWIO_INXMI(base, io, index, HWIO_FMSK(io, field)) >> HWIO_SHFT(io, field)) 171 #define HWIO_INXFI2(base, io, index1, index2, field) (HWIO_INXMI2(base, io, index1, index2, HWIO_FMSK(io, field)) >> HWIO_SHFT(io, field)) 172 #define HWIO_INXFI3(base, io, index1, index2, index3, field) (HWIO_INXMI3(base, io, index1, index2, index3, HWIO_FMSK(io, field)) >> HWIO_SHFT(io, field)) 173 /** @} */ 174 175 /** 176 * @name Output Macros 177 * 178 * These macros are used for writing to a named hardware register. Register 179 * arrays ("indexed") use the macros with the "I" suffix. The "M" suffix 180 * indicates that the output will be masked with the supplied mask (meaning these 181 * macros do a read first, mask in the supplied data, then write it back). 182 * The "X" extension is used for explicit addressing where the base address of 183 * the module in question is provided as an argument to the macro. 184 * The HWIO_OUTF* macros take a field name and will do the appropriate masking 185 * and shifting to output just the value of that field. 186 * HWIO_OUTV* registers take a named value instead of a numeric value and 187 * do the same masking/shifting as HWIO_OUTF. 188 * 189 * Generally you want to use either HWIO_OUT or HWIO_OUTF (with required indexing). 190 * 191 * @{ 192 */ 193 #define HWIO_OUT(hwiosym, val) __msmhwio_out(hwiosym, val) 194 #define HWIO_OUTI(hwiosym, index, val) __msmhwio_outi(hwiosym, index, val) 195 #define HWIO_OUTI2(hwiosym, index1, index2, val) __msmhwio_outi2(hwiosym, index1, index2, val) 196 #define HWIO_OUTI3(hwiosym, index1, index2, index3, val) __msmhwio_outi3(hwiosym, index1, index2, index3, val) 197 198 #define HWIO_OUTM(hwiosym, mask, val) __msmhwio_outm(hwiosym, mask, val) 199 #define HWIO_OUTMI(hwiosym, index, mask, val) __msmhwio_outmi(hwiosym, index, mask, val) 200 #define HWIO_OUTMI2(hwiosym, index1, index2, mask, val) __msmhwio_outmi2(hwiosym, index1, index2, mask, val) 201 #define HWIO_OUTMI3(hwiosym, index1, index2, index3, mask, val) __msmhwio_outmi3(hwiosym, index1, index2, index3, mask, val) 202 203 #define HWIO_OUTF(io, field, val) HWIO_OUTM(io, HWIO_FMSK(io, field), (uint32)(val) << HWIO_SHFT(io, field)) 204 #define HWIO_OUTFI(io, index, field, val) HWIO_OUTMI(io, index, HWIO_FMSK(io, field), (uint32)(val) << HWIO_SHFT(io, field)) 205 #define HWIO_OUTFI2(io, index1, index2, field, val) HWIO_OUTMI2(io, index1, index2, HWIO_FMSK(io, field), (uint32)(val) << HWIO_SHFT(io, field)) 206 #define HWIO_OUTFI3(io, index1, index2, index3, field, val) HWIO_OUTMI3(io, index1, index2, index3, HWIO_FMSK(io, field), (uint32)(val) << HWIO_SHFT(io, field)) 207 208 #define HWIO_OUTV(io, field, val) HWIO_OUTM(io, HWIO_FMSK(io, field), (uint32)(HWIO_VAL(io, field, val)) << HWIO_SHFT(io, field)) 209 #define HWIO_OUTVI(io, index, field, val) HWIO_OUTMI(io, index, HWIO_FMSK(io, field), (uint32)(HWIO_VAL(io, field, val)) << HWIO_SHFT(io, field)) 210 #define HWIO_OUTVI2(io, index1, index2, field, val) HWIO_OUTMI2(io, index1, index2, HWIO_FMSK(io, field), (uint32)(HWIO_VAL(io, field, val)) << HWIO_SHFT(io, field)) 211 #define HWIO_OUTVI3(io, index1, index2, index3, field, val) HWIO_OUTMI3(io, index1, index2, index3, HWIO_FMSK(io, field), (uint32)(HWIO_VAL(io, field, val)) << HWIO_SHFT(io, field)) 212 213 #define HWIO_OUTX(base, hwiosym, val) __msmhwio_outx(base, hwiosym, val) 214 #define HWIO_OUTXI(base, hwiosym, index, val) __msmhwio_outxi(base, hwiosym, index, val) 215 #define HWIO_OUTXI2(base, hwiosym, index1, index2, val) __msmhwio_outxi2(base, hwiosym, index1, index2, val) 216 #define HWIO_OUTXI3(base, hwiosym, index1, index2, index3, val) __msmhwio_outxi3(base, hwiosym, index1, index2, index3, val) 217 218 #define HWIO_OUTXM(base, hwiosym, mask, val) __msmhwio_outxm(base, hwiosym, mask, val) 219 #define HWIO_OUTXM2(base, hwiosym, mask1, mask2, val1, val2) __msmhwio_outxm2(base, hwiosym, mask1, mask2, val1, val2) 220 #define HWIO_OUTXM3(base, hwiosym, mask1, mask2, mask3, val1, val2, val3) __msmhwio_outxm3(base, hwiosym, mask1, mask2, mask3, val1, val2, val3) 221 #define HWIO_OUTXM4(base, hwiosym, mask1, mask2, mask3, mask4, val1, val2, val3, val4) __msmhwio_outxm4(base, hwiosym, mask1, mask2, mask3, mask4, val1, val2, val3, val4) 222 #define HWIO_OUTXMI(base, hwiosym, index, mask, val) __msmhwio_outxmi(base, hwiosym, index, mask, val) 223 #define HWIO_OUTXMI2(base, hwiosym, index1, index2, mask, val) __msmhwio_outxmi2(base, hwiosym, index1, index2, mask, val) 224 #define HWIO_OUTXMI3(base, hwiosym, index1, index2, index3, mask, val) __msmhwio_outxmi3(base, hwiosym, index1, index2, index3, mask, val) 225 226 #define HWIO_OUTXF(base, io, field, val) HWIO_OUTXM(base, io, HWIO_FMSK(io, field), (uint32)(val) << HWIO_SHFT(io, field)) 227 #define HWIO_OUTX2F(base, io, field1, field2, val1, val2) HWIO_OUTXM2(base, io, HWIO_FMSK(io, field1), HWIO_FMSK(io, field2), (uint32)(val1) << HWIO_SHFT(io, field1), (uint32)(val2) << HWIO_SHFT(io, field2)) 228 #define HWIO_OUTX3F(base, io, field1, field2, field3, val1, val2, val3) HWIO_OUTXM3(base, io, HWIO_FMSK(io, field1), HWIO_FMSK(io, field2), HWIO_FMSK(io, field3),(uint32)(val1) << HWIO_SHFT(io, field1), (uint32)(val2) << HWIO_SHFT(io, field2), (uint32)(val3) << HWIO_SHFT(io, field3) ) 229 #define HWIO_OUTX4F(base, io, field1, field2, field3, field4, val1, val2, val3, val4) HWIO_OUTXM4(base, io, HWIO_FMSK(io, field1), HWIO_FMSK(io, field2), HWIO_FMSK(io, field3), HWIO_FMSK(io, field4), (uint32)(val1) << HWIO_SHFT(io, field1) , (uint32)(val2) << HWIO_SHFT(io, field2), (uint32)(val3) << HWIO_SHFT(io, field3), (uint32)(val4) << HWIO_SHFT(io, field4) ) 230 231 #define HWIO_OUTXFI(base, io, index, field, val) HWIO_OUTXMI(base, io, index, HWIO_FMSK(io, field), (uint32)(val) << HWIO_SHFT(io, field)) 232 #define HWIO_OUTXFI2(base, io, index1, index2, field, val) HWIO_OUTXMI2(base, io, index1, index2, HWIO_FMSK(io, field), (uint32)(val) << HWIO_SHFT(io, field)) 233 #define HWIO_OUTXFI3(base, io, index1, index2, index3, field, val) HWIO_OUTXMI3(base, io, index1, index2, index3, HWIO_FMSK(io, field), (uint32)(val) << HWIO_SHFT(io, field)) 234 235 #define HWIO_OUTXV(base, io, field, val) HWIO_OUTXM(base, io, HWIO_FMSK(io, field), (uint32)(HWIO_VAL(io, field, val)) << HWIO_SHFT(io, field)) 236 #define HWIO_OUTXVI(base, io, index, field, val) HWIO_OUTXMI(base, io, index, HWIO_FMSK(io, field), (uint32)(HWIO_VAL(io, field, val)) << HWIO_SHFT(io, field)) 237 #define HWIO_OUTXVI2(base, io, index1, index2, field, val) HWIO_OUTXMI2(base, io, index1, index2, HWIO_FMSK(io, field), (uint32)(HWIO_VAL(io, field, val)) << HWIO_SHFT(io, field)) 238 #define HWIO_OUTXVI3(base, io, index1, index2, index3, field, val) HWIO_OUTXMI3(base, io, index1, index2, index3, HWIO_FMSK(io, field), (uint32)(HWIO_VAL(io, field, val)) << HWIO_SHFT(io, field)) 239 /** @} */ 240 241 /** 242 * @name Shift and Mask Macros 243 * 244 * Macros for getting shift and mask values for fields and registers. 245 * HWIO_RMSK: The mask value for accessing an entire register. For example: 246 * @code 247 * HWIO_RMSK(REG) -> 0xFFFFFFFF 248 * @endcode 249 * HWIO_RSHFT: The right-shift value for an entire register (rarely necessary).\n 250 * HWIO_SHFT: The right-shift value for accessing a field in a register. For example: 251 * @code 252 * HWIO_SHFT(REG, FLD) -> 8 253 * @endcode 254 * HWIO_FMSK: The mask value for accessing a field in a register. For example: 255 * @code 256 * HWIO_FMSK(REG, FLD) -> 0xFF00 257 * @endcode 258 * HWIO_VAL: The value for a field in a register. For example: 259 * @code 260 * HWIO_VAL(REG, FLD, ON) -> 0x1 261 * @endcode 262 * HWIO_FVAL: This macro takes a numerical value and will shift and mask it into 263 * the given field position. For example: 264 * @code 265 * HWIO_FVAL(REG, FLD, 0x1) -> 0x100 266 * @endcode 267 * HWIO_FVALV: This macro takes a logical (named) value and will shift and mask it 268 * into the given field position. For example: 269 * @code 270 * HWIO_FVALV(REG, FLD, ON) -> 0x100 271 * @endcode 272 * 273 * @{ 274 */ 275 #define HWIO_RMSK(hwiosym) __msmhwio_rmsk(hwiosym) 276 #define HWIO_RMSKI(hwiosym, index) __msmhwio_rmski(hwiosym, index) 277 #define HWIO_RSHFT(hwiosym) __msmhwio_rshft(hwiosym) 278 #define HWIO_SHFT(hwio_regsym, hwio_fldsym) __msmhwio_shft(hwio_regsym, hwio_fldsym) 279 #define HWIO_FMSK(hwio_regsym, hwio_fldsym) __msmhwio_fmsk(hwio_regsym, hwio_fldsym) 280 #define HWIO_VAL(io, field, val) __msmhwio_val(io, field, val) 281 #define HWIO_FVAL(io, field, val) (((uint32)(val) << HWIO_SHFT(io, field)) & HWIO_FMSK(io, field)) 282 #define HWIO_FVALV(io, field, val) (((uint32)(HWIO_VAL(io, field, val)) << HWIO_SHFT(io, field)) & HWIO_FMSK(io, field)) 283 /** @} */ 284 285 /** 286 * @name Shadow Register Macros 287 * 288 * These macros are used for directly reading the value stored in a 289 * shadow register. 290 * Shadow registers are defined for write-only registers. Generally these 291 * macros should not be necessary as HWIO_OUTM* macros will automatically use 292 * the shadow values internally. 293 * 294 * @{ 295 */ 296 #define HWIO_SHDW(hwiosym) __msmhwio_shdw(hwiosym) 297 #define HWIO_SHDWI(hwiosym, index) __msmhwio_shdwi(hwiosym, index) 298 /** @} */ 299 300 /** 301 @} 302 */ /* end_group */ 303 304 305 /** @cond */ 306 307 /* 308 * Map to final symbols. This remapping is done to allow register 309 * redefinitions. If we just define HWIO_IN(xreg) as HWIO_##xreg##_IN 310 * then remappings like "#define xreg xregnew" do not work as expected. 311 */ 312 #define __msmhwio_in(hwiosym) HWIO_##hwiosym##_IN 313 #define __msmhwio_ini(hwiosym, index) HWIO_##hwiosym##_INI(index) 314 #define __msmhwio_ini2(hwiosym, index1, index2) HWIO_##hwiosym##_INI2(index1, index2) 315 #define __msmhwio_ini3(hwiosym, index1, index2, index3) HWIO_##hwiosym##_INI3(index1, index2, index3) 316 #define __msmhwio_inm(hwiosym, mask) HWIO_##hwiosym##_INM(mask) 317 #define __msmhwio_inmi(hwiosym, index, mask) HWIO_##hwiosym##_INMI(index, mask) 318 #define __msmhwio_inmi2(hwiosym, index1, index2, mask) HWIO_##hwiosym##_INMI2(index1, index2, mask) 319 #define __msmhwio_inmi3(hwiosym, index1, index2, index3, mask) HWIO_##hwiosym##_INMI3(index1, index2, index3, mask) 320 #define __msmhwio_out(hwiosym, val) HWIO_##hwiosym##_OUT(val) 321 #define __msmhwio_outi(hwiosym, index, val) HWIO_##hwiosym##_OUTI(index,val) 322 #define __msmhwio_outi2(hwiosym, index1, index2, val) HWIO_##hwiosym##_OUTI2(index1, index2, val) 323 #define __msmhwio_outi3(hwiosym, index1, index2, index3, val) HWIO_##hwiosym##_OUTI2(index1, index2, index3, val) 324 #define __msmhwio_outm(hwiosym, mask, val) HWIO_##hwiosym##_OUTM(mask, val) 325 #define __msmhwio_outmi(hwiosym, index, mask, val) HWIO_##hwiosym##_OUTMI(index, mask, val) 326 #define __msmhwio_outmi2(hwiosym, idx1, idx2, mask, val) HWIO_##hwiosym##_OUTMI2(idx1, idx2, mask, val) 327 #define __msmhwio_outmi3(hwiosym, idx1, idx2, idx3, mask, val) HWIO_##hwiosym##_OUTMI3(idx1, idx2, idx3, mask, val) 328 #define __msmhwio_addr(hwiosym) HWIO_##hwiosym##_ADDR 329 #define __msmhwio_addri(hwiosym, index) HWIO_##hwiosym##_ADDR(index) 330 #define __msmhwio_addri2(hwiosym, idx1, idx2) HWIO_##hwiosym##_ADDR(idx1, idx2) 331 #define __msmhwio_addri3(hwiosym, idx1, idx2, idx3) HWIO_##hwiosym##_ADDR(idx1, idx2, idx3) 332 #define __msmhwio_phys(hwiosym) HWIO_##hwiosym##_PHYS 333 #define __msmhwio_physi(hwiosym, index) HWIO_##hwiosym##_PHYS(index) 334 #define __msmhwio_physi2(hwiosym, idx1, idx2) HWIO_##hwiosym##_PHYS(idx1, idx2) 335 #define __msmhwio_physi3(hwiosym, idx1, idx2, idx3) HWIO_##hwiosym##_PHYS(idx1, idx2, idx3) 336 #define __msmhwio_offs(hwiosym) HWIO_##hwiosym##_OFFS 337 #define __msmhwio_offsi(hwiosym, index) HWIO_##hwiosym##_OFFS(index) 338 #define __msmhwio_offsi2(hwiosym, idx1, idx2) HWIO_##hwiosym##_OFFS(idx1, idx2) 339 #define __msmhwio_offsi3(hwiosym, idx1, idx2, idx3) HWIO_##hwiosym##_OFFS(idx1, idx2, idx3) 340 #define __msmhwio_rmsk(hwiosym) HWIO_##hwiosym##_RMSK 341 #define __msmhwio_rmski(hwiosym, index) HWIO_##hwiosym##_RMSK(index) 342 #define __msmhwio_fmsk(hwiosym, hwiofldsym) HWIO_##hwiosym##_##hwiofldsym##_BMSK 343 #define __msmhwio_rshft(hwiosym) HWIO_##hwiosym##_SHFT 344 #define __msmhwio_shft(hwiosym, hwiofldsym) HWIO_##hwiosym##_##hwiofldsym##_SHFT 345 #define __msmhwio_shdw(hwiosym) HWIO_##hwiosym##_shadow 346 #define __msmhwio_shdwi(hwiosym, index) HWIO_##hwiosym##_SHDW(index) 347 #define __msmhwio_val(hwiosym, hwiofld, hwioval) HWIO_##hwiosym##_##hwiofld##_##hwioval##_FVAL 348 349 #define __msmhwio_inx(base, hwiosym) HWIO_##hwiosym##_IN(base) 350 #define __msmhwio_inxi(base, hwiosym, index) HWIO_##hwiosym##_INI(base, index) 351 #define __msmhwio_inxi2(base, hwiosym, index1, index2) HWIO_##hwiosym##_INI2(base, index1, index2) 352 #define __msmhwio_inxi3(base, hwiosym, index1, index2, index3) HWIO_##hwiosym##_INI3(base, index1, index2, index3) 353 #define __msmhwio_inxm(base, hwiosym, mask) HWIO_##hwiosym##_INM(base, mask) 354 #define __msmhwio_inxmi(base, hwiosym, index, mask) HWIO_##hwiosym##_INMI(base, index, mask) 355 #define __msmhwio_inxmi2(base, hwiosym, index1, index2, mask) HWIO_##hwiosym##_INMI2(base, index1, index2, mask) 356 #define __msmhwio_inxmi3(base, hwiosym, index1, index2, index3, mask) HWIO_##hwiosym##_INMI3(base, index1, index2, index3, mask) 357 #define __msmhwio_outx(base, hwiosym, val) HWIO_##hwiosym##_OUT(base, val) 358 #define __msmhwio_outxi(base, hwiosym, index, val) HWIO_##hwiosym##_OUTI(base, index,val) 359 #define __msmhwio_outxi2(base, hwiosym, index1, index2, val) HWIO_##hwiosym##_OUTI2(base, index1, index2, val) 360 #define __msmhwio_outxi3(base, hwiosym, index1, index2, index3, val) HWIO_##hwiosym##_OUTI2(base, index1, index2, index3, val) 361 #define __msmhwio_outxm(base, hwiosym, mask, val) HWIO_##hwiosym##_OUTM(base, mask, val) 362 #define __msmhwio_outxm2(base, hwiosym, mask1, mask2, val1, val2) { \ 363 HWIO_##hwiosym##_OUTM(base, mask1, val1); \ 364 HWIO_##hwiosym##_OUTM(base, mask2, val2); \ 365 } 366 #define __msmhwio_outxm3(base, hwiosym, mask1, mask2, mask3, val1, val2, val3) { \ 367 HWIO_##hwiosym##_OUTM(base, mask1, val1); \ 368 HWIO_##hwiosym##_OUTM(base, mask2, val2); \ 369 HWIO_##hwiosym##_OUTM(base, mask3, val3); \ 370 } 371 #define __msmhwio_outxm4(base, hwiosym, mask1, mask2, mask3, mask4, val1, val2, val3, val4) { \ 372 HWIO_##hwiosym##_OUTM(base, mask1, val1); \ 373 HWIO_##hwiosym##_OUTM(base, mask2, val2); \ 374 HWIO_##hwiosym##_OUTM(base, mask3, val3); \ 375 HWIO_##hwiosym##_OUTM(base, mask4, val4); \ 376 } 377 378 379 #define __msmhwio_outxmi(base, hwiosym, index, mask, val) HWIO_##hwiosym##_OUTMI(base, index, mask, val) 380 #define __msmhwio_outxmi2(base, hwiosym, idx1, idx2, mask, val) HWIO_##hwiosym##_OUTMI2(base, idx1, idx2, mask, val) 381 #define __msmhwio_outxmi3(base, hwiosym, idx1, idx2, idx3, mask, val) HWIO_##hwiosym##_OUTMI3(base, idx1, idx2, idx3, mask, val) 382 #define __msmhwio_addrx(base, hwiosym) HWIO_##hwiosym##_ADDR(base) 383 #define __msmhwio_addrxi(base, hwiosym, index) HWIO_##hwiosym##_ADDR(base, index) 384 #define __msmhwio_addrxi2(base, hwiosym, idx1, idx2) HWIO_##hwiosym##_ADDR(base, idx1, idx2) 385 #define __msmhwio_addrxi3(base, hwiosym, idx1, idx2, idx3) HWIO_##hwiosym##_ADDR(base, idx1, idx2, idx3) 386 #define __msmhwio_physx(base, hwiosym) HWIO_##hwiosym##_PHYS(base) 387 #define __msmhwio_physxi(base, hwiosym, index) HWIO_##hwiosym##_PHYS(base, index) 388 #define __msmhwio_physxi2(base, hwiosym, idx1, idx2) HWIO_##hwiosym##_PHYS(base, idx1, idx2) 389 #define __msmhwio_physxi3(base, hwiosym, idx1, idx2, idx3) HWIO_##hwiosym##_PHYS(base, idx1, idx2, idx3) 390 391 392 /* 393 * HWIO_INTLOCK 394 * 395 * Macro used by autogenerated code for mutual exclusion around 396 * read-mask-write operations. This is not supported in HAL 397 * code but can be overridden by non-HAL code. 398 */ 399 #define HWIO_INTLOCK() 400 #define HWIO_INTFREE() 401 402 403 #if defined(VISUAL_STUDIO) || defined(TEST_FRAMEWORK) 404 extern unsigned int registerRead(unsigned int port); 405 extern void registerWrite(unsigned int port, unsigned int val); 406 #define __inp(port) registerRead(port) 407 #define __inpw(port) registerRead(port) 408 #define __inpdw(port) registerRead(port) 409 #define __outp(port, val) registerWrite(port, val) 410 #define __outpw(port, val) registerWrite(port, val) 411 #define __outpdw(port, val) registerWrite(port, val) 412 413 #else 414 #if defined(CONFIG_SIMHW) 415 extern unsigned char * simhw_get_mac_addr(void); 416 extern uint8 __sim_inp(uint32 addr); 417 extern uint16 __sim_inpw(uint32 addr); 418 extern uint32 __sim_inpdw(uint32 addr); 419 extern void __sim_outp(uint32 addr, uint8 data); 420 extern void __sim_outpw(uint32 addr, uint16 data); 421 extern void __sim_outpdw(uint32 addr, uint32 data); 422 423 #define __inp(port) __sim_inp((unsigned int)port) 424 #define __inpw(port) __sim_inpw((unsigned int)port) 425 #define __inpdw(port) __sim_inpdw((unsigned int)port) 426 #define __outp(port, val) __sim_outp((unsigned int)port, val) 427 #define __outpw(port, val) __sim_outpw((unsigned int)port, val) 428 #define __outpdw(port, val) __sim_outpdw((unsigned int)port, val) 429 430 #define registerRead(port) __sim_inpdw(port) 431 #define registerWrite(port, val) __sim_outpdw(port, val) 432 433 #else // CONFIG_SIMHW 434 435 #ifdef FPGA 436 #define MAC_ADDRESS_POWER_CHECK 437 #else 438 #undef MAC_ADDRESS_POWER_CHECK 439 #endif 440 #ifdef MAC_ADDRESS_POWER_CHECK 441 extern void whal_pwr_debug_register_address_check(uint32 addr, int is_write); 442 #endif 443 444 445 /* 446 * Input/output port macros for memory mapped IO. 447 */ 448 #define __inp(port) (*((volatile uint8 *) ((uint32)(port)))) 449 #define __inpw(port) (*((volatile uint16 *) ((uint32)(port)))) 450 #ifdef MAC_ADDRESS_POWER_CHECK __inpdw(uint32 port)451 static inline uint32 __inpdw(uint32 port){ 452 whal_pwr_debug_register_address_check(port, FALSE); 453 return (*((volatile uint32 *) (port))); 454 } 455 #else 456 #define __inpdw(port) (*((volatile uint32 *) ((uint32)(port)))) 457 #endif 458 459 extern void busywait(uint32 pause_time_us); 460 461 #define __outp(port, val) (*((volatile uint8 *) ((uint32)(port))) = ((uint8) (val))) 462 #define __outpw(port, val) (*((volatile uint16 *) ((uint32)(port))) = ((uint16) (val))) 463 #define __outpdw(port, val) (*((volatile uint32 *) ((uint32)(port))) = ((uint32) (val))) 464 465 #define registerRead(port) (*((volatile uint32 *) ((uint32)(port) ))) 466 #define registerWrite(port, val) (*((volatile uint32 *) ((uint32)(port) )) = ((uint32) (val))) 467 #endif // CONFIG_SIMHW 468 #endif 469 470 #ifdef HAL_HWIO_EXTERNAL 471 472 /* 473 * Replace macros with externally supplied functions. 474 */ 475 #undef __inp 476 #undef __inpw 477 #undef __inpdw 478 #undef __outp 479 #undef __outpw 480 #undef __outpdw 481 482 #define __inp(port) __inp_extern(port) 483 #define __inpw(port) __inpw_extern(port) 484 #define __inpdw(port) __inpdw_extern(port) 485 #define __outp(port, val) __outp_extern(port, val) 486 #define __outpw(port, val) __outpw_extern(port, val) 487 #define __outpdw(port, val) __outpdw_extern(port, val) 488 489 extern uint8 __inp_extern ( uint32 nAddr ); 490 extern uint16 __inpw_extern ( uint32 nAddr ); 491 extern uint32 __inpdw_extern ( uint32 nAddr ); 492 extern void __outp_extern ( uint32 nAddr, uint8 nData ); 493 extern void __outpw_extern ( uint32 nAddr, uint16 nData ); 494 extern void __outpdw_extern ( uint32 nAddr, uint32 nData ); 495 496 #endif /* HAL_HWIO_EXTERNAL */ 497 498 499 /* 500 * Base 8-bit byte accessing macros. 501 */ 502 #define in_byte(addr) (__inp(addr)) 503 #define in_byte_masked(addr, mask) (__inp(addr) & (mask)) 504 #define out_byte(addr, val) __outp(addr,val) 505 #define out_byte_masked(io, mask, val, shadow) \ 506 HWIO_INTLOCK(); \ 507 out_byte( io, shadow); \ 508 shadow = (shadow & (uint16)(~(mask))) | ((uint16)((val) & (mask))); \ 509 HWIO_INTFREE() 510 #define out_byte_masked_ns(io, mask, val, current_reg_content) \ 511 out_byte( io, ((current_reg_content & (uint16)(~(mask))) | \ 512 ((uint16)((val) & (mask)))) ) 513 514 515 /* 516 * Base 16-bit word accessing macros. 517 */ 518 #define in_word(addr) (__inpw(addr)) 519 #define in_word_masked(addr, mask) (__inpw(addr) & (mask)) 520 #define out_word(addr, val) __outpw(addr,val) 521 #define out_word_masked(io, mask, val, shadow) \ 522 HWIO_INTLOCK( ); \ 523 shadow = (shadow & (uint16)(~(mask))) | ((uint16)((val) & (mask))); \ 524 out_word( io, shadow); \ 525 HWIO_INTFREE( ) 526 #define out_word_masked_ns(io, mask, val, current_reg_content) \ 527 out_word( io, ((current_reg_content & (uint16)(~(mask))) | \ 528 ((uint16)((val) & (mask)))) ) 529 530 531 /* 532 * Base 32-bit double-word accessing macros. 533 */ 534 #ifdef MAC_ADDRESS_POWER_CHECK 535 #define in_dword(addr) (__inpdw((uint32)addr)) 536 #define in_dword_masked(addr, mask) (__inpdw((uint32)addr) & (mask)) 537 #define out_dword(addr, val) __outpdw((uint32)addr,val) 538 #else 539 #define in_dword(addr) (__inpdw(addr)) 540 #define in_dword_masked(addr, mask) (__inpdw(addr) & (mask)) 541 #define out_dword(addr, val) __outpdw((uint32)addr,val) 542 #endif 543 #define out_dword_masked(io, mask, val, shadow) \ 544 HWIO_INTLOCK(); \ 545 shadow = (shadow & (uint32)(~(mask))) | ((uint32)((val) & (mask))); \ 546 out_dword( io, shadow); \ 547 HWIO_INTFREE() 548 #define out_dword_masked_ns(io, mask, val, current_reg_content) \ 549 out_dword( io, ((current_reg_content & (uint32)(~(mask))) | \ 550 ((uint32)((val) & (mask)))) ) 551 552 #define out_dword_masked_ns_shift(io, mask, val, current_reg_content, shift) \ 553 out_dword( io, ((current_reg_content & (uint32)(~(mask))) | \ 554 (((uint32)((val) & (mask))) << shift )) ) 555 /** @endcond */ 556 557 #endif /* HAL_HWIO_H */ 558 559