Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Misc utility routines for accessing chip-specific features |
| 3 | * of the SiliconBackplane-based Broadcom chips. |
| 4 | * |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 5 | * Copyright (C) 1999-2012, Broadcom Corporation |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 6 | * |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 7 | * Unless you and Broadcom execute a separate written software license |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 8 | * agreement governing use of this software, this software is licensed to you |
| 9 | * under the terms of the GNU General Public License version 2 (the "GPL"), |
| 10 | * available at http://www.broadcom.com/licenses/GPLv2.php, with the |
| 11 | * following added to such license: |
| 12 | * |
| 13 | * As a special exception, the copyright holders of this software give you |
| 14 | * permission to link this software with independent modules, and to copy and |
| 15 | * distribute the resulting executable under terms of your choice, provided that |
| 16 | * you also meet, for each linked independent module, the terms and conditions of |
| 17 | * the license of that module. An independent module is a module which is not |
| 18 | * derived from this software. The special exception does not apply to any |
| 19 | * modifications of the software. |
| 20 | * |
| 21 | * Notwithstanding the above, under no circumstances may you combine this |
| 22 | * software in any way with any other Broadcom software provided under a license |
| 23 | * other than the GPL, without Broadcom's express prior written consent. |
| 24 | * |
Dmitry Shmidt | 4a3a0fa | 2012-04-12 10:18:39 -0700 | [diff] [blame^] | 25 | * $Id: aiutils.c 321247 2012-03-14 21:14:33Z $ |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 26 | */ |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 27 | #include <bcm_cfg.h> |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 28 | #include <typedefs.h> |
| 29 | #include <bcmdefs.h> |
| 30 | #include <osl.h> |
| 31 | #include <bcmutils.h> |
| 32 | #include <siutils.h> |
| 33 | #include <hndsoc.h> |
| 34 | #include <sbchipc.h> |
| 35 | #include <pcicfg.h> |
| 36 | |
| 37 | #include "siutils_priv.h" |
| 38 | |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 39 | #define BCM47162_DMP() (0) |
| 40 | #define BCM5357_DMP() (0) |
| 41 | #define remap_coreid(sih, coreid) (coreid) |
| 42 | #define remap_corerev(sih, corerev) (corerev) |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 43 | |
| 44 | |
| 45 | |
| 46 | static uint32 |
| 47 | get_erom_ent(si_t *sih, uint32 **eromptr, uint32 mask, uint32 match) |
| 48 | { |
| 49 | uint32 ent; |
| 50 | uint inv = 0, nom = 0; |
| 51 | |
| 52 | while (TRUE) { |
| 53 | ent = R_REG(si_osh(sih), *eromptr); |
| 54 | (*eromptr)++; |
| 55 | |
| 56 | if (mask == 0) |
| 57 | break; |
| 58 | |
| 59 | if ((ent & ER_VALID) == 0) { |
| 60 | inv++; |
| 61 | continue; |
| 62 | } |
| 63 | |
| 64 | if (ent == (ER_END | ER_VALID)) |
| 65 | break; |
| 66 | |
| 67 | if ((ent & mask) == match) |
| 68 | break; |
| 69 | |
| 70 | nom++; |
| 71 | } |
| 72 | |
| 73 | SI_VMSG(("%s: Returning ent 0x%08x\n", __FUNCTION__, ent)); |
| 74 | if (inv + nom) { |
| 75 | SI_VMSG((" after %d invalid and %d non-matching entries\n", inv, nom)); |
| 76 | } |
| 77 | return ent; |
| 78 | } |
| 79 | |
| 80 | static uint32 |
| 81 | get_asd(si_t *sih, uint32 **eromptr, uint sp, uint ad, uint st, uint32 *addrl, uint32 *addrh, |
| 82 | uint32 *sizel, uint32 *sizeh) |
| 83 | { |
| 84 | uint32 asd, sz, szd; |
| 85 | |
| 86 | asd = get_erom_ent(sih, eromptr, ER_VALID, ER_VALID); |
| 87 | if (((asd & ER_TAG1) != ER_ADD) || |
| 88 | (((asd & AD_SP_MASK) >> AD_SP_SHIFT) != sp) || |
| 89 | ((asd & AD_ST_MASK) != st)) { |
| 90 | |
| 91 | (*eromptr)--; |
| 92 | return 0; |
| 93 | } |
| 94 | *addrl = asd & AD_ADDR_MASK; |
| 95 | if (asd & AD_AG32) |
| 96 | *addrh = get_erom_ent(sih, eromptr, 0, 0); |
| 97 | else |
| 98 | *addrh = 0; |
| 99 | *sizeh = 0; |
| 100 | sz = asd & AD_SZ_MASK; |
| 101 | if (sz == AD_SZ_SZD) { |
| 102 | szd = get_erom_ent(sih, eromptr, 0, 0); |
| 103 | *sizel = szd & SD_SZ_MASK; |
| 104 | if (szd & SD_SG32) |
| 105 | *sizeh = get_erom_ent(sih, eromptr, 0, 0); |
| 106 | } else |
| 107 | *sizel = AD_SZ_BASE << (sz >> AD_SZ_SHIFT); |
| 108 | |
| 109 | SI_VMSG((" SP %d, ad %d: st = %d, 0x%08x_0x%08x @ 0x%08x_0x%08x\n", |
| 110 | sp, ad, st, *sizeh, *sizel, *addrh, *addrl)); |
| 111 | |
| 112 | return asd; |
| 113 | } |
| 114 | |
| 115 | static void |
| 116 | ai_hwfixup(si_info_t *sii) |
| 117 | { |
| 118 | } |
| 119 | |
| 120 | |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 121 | |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 122 | void |
| 123 | ai_scan(si_t *sih, void *regs, uint devid) |
| 124 | { |
| 125 | si_info_t *sii = SI_INFO(sih); |
| 126 | chipcregs_t *cc = (chipcregs_t *)regs; |
| 127 | uint32 erombase, *eromptr, *eromlim; |
| 128 | |
| 129 | erombase = R_REG(sii->osh, &cc->eromptr); |
| 130 | |
| 131 | switch (BUSTYPE(sih->bustype)) { |
| 132 | case SI_BUS: |
| 133 | eromptr = (uint32 *)REG_MAP(erombase, SI_CORE_SIZE); |
| 134 | break; |
| 135 | |
| 136 | case PCI_BUS: |
| 137 | |
| 138 | sii->curwrap = (void *)((uintptr)regs + SI_CORE_SIZE); |
| 139 | |
| 140 | |
| 141 | OSL_PCI_WRITE_CONFIG(sii->osh, PCI_BAR0_WIN, 4, erombase); |
| 142 | eromptr = regs; |
| 143 | break; |
| 144 | |
| 145 | case SPI_BUS: |
| 146 | case SDIO_BUS: |
| 147 | eromptr = (uint32 *)(uintptr)erombase; |
| 148 | break; |
| 149 | |
| 150 | case PCMCIA_BUS: |
| 151 | default: |
| 152 | SI_ERROR(("Don't know how to do AXI enumertion on bus %d\n", sih->bustype)); |
| 153 | ASSERT(0); |
| 154 | return; |
| 155 | } |
| 156 | eromlim = eromptr + (ER_REMAPCONTROL / sizeof(uint32)); |
| 157 | |
| 158 | SI_VMSG(("ai_scan: regs = 0x%p, erombase = 0x%08x, eromptr = 0x%p, eromlim = 0x%p\n", |
| 159 | regs, erombase, eromptr, eromlim)); |
| 160 | while (eromptr < eromlim) { |
| 161 | uint32 cia, cib, cid, mfg, crev, nmw, nsw, nmp, nsp; |
| 162 | uint32 mpd, asd, addrl, addrh, sizel, sizeh; |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 163 | uint i, j, idx; |
| 164 | bool br; |
| 165 | |
| 166 | br = FALSE; |
| 167 | |
| 168 | |
| 169 | cia = get_erom_ent(sih, &eromptr, ER_TAG, ER_CI); |
| 170 | if (cia == (ER_END | ER_VALID)) { |
| 171 | SI_VMSG(("Found END of erom after %d cores\n", sii->numcores)); |
| 172 | ai_hwfixup(sii); |
| 173 | return; |
| 174 | } |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 175 | |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 176 | cib = get_erom_ent(sih, &eromptr, 0, 0); |
| 177 | |
| 178 | if ((cib & ER_TAG) != ER_CI) { |
| 179 | SI_ERROR(("CIA not followed by CIB\n")); |
| 180 | goto error; |
| 181 | } |
| 182 | |
| 183 | cid = (cia & CIA_CID_MASK) >> CIA_CID_SHIFT; |
| 184 | mfg = (cia & CIA_MFG_MASK) >> CIA_MFG_SHIFT; |
| 185 | crev = (cib & CIB_REV_MASK) >> CIB_REV_SHIFT; |
| 186 | nmw = (cib & CIB_NMW_MASK) >> CIB_NMW_SHIFT; |
| 187 | nsw = (cib & CIB_NSW_MASK) >> CIB_NSW_SHIFT; |
| 188 | nmp = (cib & CIB_NMP_MASK) >> CIB_NMP_SHIFT; |
| 189 | nsp = (cib & CIB_NSP_MASK) >> CIB_NSP_SHIFT; |
| 190 | |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 191 | #ifdef BCMDBG_SI |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 192 | SI_VMSG(("Found component 0x%04x/0x%04x rev %d at erom addr 0x%p, with nmw = %d, " |
| 193 | "nsw = %d, nmp = %d & nsp = %d\n", |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 194 | mfg, cid, crev, eromptr - 1, nmw, nsw, nmp, nsp)); |
| 195 | #else |
| 196 | BCM_REFERENCE(crev); |
| 197 | #endif |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 198 | |
| 199 | if (((mfg == MFGID_ARM) && (cid == DEF_AI_COMP)) || (nsp == 0)) |
| 200 | continue; |
| 201 | if ((nmw + nsw == 0)) { |
| 202 | |
| 203 | if (cid == OOB_ROUTER_CORE_ID) { |
| 204 | asd = get_asd(sih, &eromptr, 0, 0, AD_ST_SLAVE, |
| 205 | &addrl, &addrh, &sizel, &sizeh); |
| 206 | if (asd != 0) { |
| 207 | sii->oob_router = addrl; |
| 208 | } |
| 209 | } |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 210 | if (cid != GMAC_COMMON_4706_CORE_ID) |
| 211 | continue; |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | idx = sii->numcores; |
| 215 | |
| 216 | sii->cia[idx] = cia; |
| 217 | sii->cib[idx] = cib; |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 218 | sii->coreid[idx] = remap_coreid(sih, cid); |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 219 | |
| 220 | for (i = 0; i < nmp; i++) { |
| 221 | mpd = get_erom_ent(sih, &eromptr, ER_VALID, ER_VALID); |
| 222 | if ((mpd & ER_TAG) != ER_MP) { |
| 223 | SI_ERROR(("Not enough MP entries for component 0x%x\n", cid)); |
| 224 | goto error; |
| 225 | } |
| 226 | SI_VMSG((" Master port %d, mp: %d id: %d\n", i, |
| 227 | (mpd & MPD_MP_MASK) >> MPD_MP_SHIFT, |
| 228 | (mpd & MPD_MUI_MASK) >> MPD_MUI_SHIFT)); |
| 229 | } |
| 230 | |
| 231 | |
| 232 | asd = get_asd(sih, &eromptr, 0, 0, AD_ST_SLAVE, &addrl, &addrh, &sizel, &sizeh); |
| 233 | if (asd == 0) { |
| 234 | |
| 235 | asd = get_asd(sih, &eromptr, 0, 0, AD_ST_BRIDGE, &addrl, &addrh, |
| 236 | &sizel, &sizeh); |
| 237 | if (asd != 0) |
| 238 | br = TRUE; |
| 239 | else |
| 240 | if ((addrh != 0) || (sizeh != 0) || (sizel != SI_CORE_SIZE)) { |
| 241 | SI_ERROR(("First Slave ASD for core 0x%04x malformed " |
| 242 | "(0x%08x)\n", cid, asd)); |
| 243 | goto error; |
| 244 | } |
| 245 | } |
| 246 | sii->coresba[idx] = addrl; |
| 247 | sii->coresba_size[idx] = sizel; |
| 248 | |
| 249 | j = 1; |
| 250 | do { |
| 251 | asd = get_asd(sih, &eromptr, 0, j, AD_ST_SLAVE, &addrl, &addrh, |
| 252 | &sizel, &sizeh); |
| 253 | if ((asd != 0) && (j == 1) && (sizel == SI_CORE_SIZE)) { |
| 254 | sii->coresba2[idx] = addrl; |
| 255 | sii->coresba2_size[idx] = sizel; |
| 256 | } |
| 257 | j++; |
| 258 | } while (asd != 0); |
| 259 | |
| 260 | |
| 261 | for (i = 1; i < nsp; i++) { |
| 262 | j = 0; |
| 263 | do { |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 264 | asd = get_asd(sih, &eromptr, i, j, AD_ST_SLAVE, &addrl, &addrh, |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 265 | &sizel, &sizeh); |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 266 | |
| 267 | if (asd == 0) |
| 268 | break; |
| 269 | j++; |
| 270 | } while (1); |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 271 | if (j == 0) { |
| 272 | SI_ERROR((" SP %d has no address descriptors\n", i)); |
| 273 | goto error; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | |
| 278 | for (i = 0; i < nmw; i++) { |
| 279 | asd = get_asd(sih, &eromptr, i, 0, AD_ST_MWRAP, &addrl, &addrh, |
| 280 | &sizel, &sizeh); |
| 281 | if (asd == 0) { |
| 282 | SI_ERROR(("Missing descriptor for MW %d\n", i)); |
| 283 | goto error; |
| 284 | } |
| 285 | if ((sizeh != 0) || (sizel != SI_CORE_SIZE)) { |
| 286 | SI_ERROR(("Master wrapper %d is not 4KB\n", i)); |
| 287 | goto error; |
| 288 | } |
| 289 | if (i == 0) |
| 290 | sii->wrapba[idx] = addrl; |
| 291 | } |
| 292 | |
| 293 | |
| 294 | for (i = 0; i < nsw; i++) { |
| 295 | uint fwp = (nsp == 1) ? 0 : 1; |
| 296 | asd = get_asd(sih, &eromptr, fwp + i, 0, AD_ST_SWRAP, &addrl, &addrh, |
| 297 | &sizel, &sizeh); |
| 298 | if (asd == 0) { |
| 299 | SI_ERROR(("Missing descriptor for SW %d\n", i)); |
| 300 | goto error; |
| 301 | } |
| 302 | if ((sizeh != 0) || (sizel != SI_CORE_SIZE)) { |
| 303 | SI_ERROR(("Slave wrapper %d is not 4KB\n", i)); |
| 304 | goto error; |
| 305 | } |
| 306 | if ((nmw == 0) && (i == 0)) |
| 307 | sii->wrapba[idx] = addrl; |
| 308 | } |
| 309 | |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 310 | |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 311 | |
| 312 | if (br) |
| 313 | continue; |
| 314 | |
| 315 | |
| 316 | sii->numcores++; |
| 317 | } |
| 318 | |
| 319 | SI_ERROR(("Reached end of erom without finding END")); |
| 320 | |
| 321 | error: |
| 322 | sii->numcores = 0; |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | |
| 327 | void * |
| 328 | ai_setcoreidx(si_t *sih, uint coreidx) |
| 329 | { |
| 330 | si_info_t *sii = SI_INFO(sih); |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 331 | uint32 addr, wrap; |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 332 | void *regs; |
| 333 | |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 334 | if (coreidx >= MIN(sii->numcores, SI_MAXCORES)) |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 335 | return (NULL); |
| 336 | |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 337 | addr = sii->coresba[coreidx]; |
| 338 | wrap = sii->wrapba[coreidx]; |
| 339 | |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 340 | |
| 341 | ASSERT((sii->intrsenabled_fn == NULL) || !(*(sii)->intrsenabled_fn)((sii)->intr_arg)); |
| 342 | |
| 343 | switch (BUSTYPE(sih->bustype)) { |
| 344 | case SI_BUS: |
| 345 | |
| 346 | if (!sii->regs[coreidx]) { |
| 347 | sii->regs[coreidx] = REG_MAP(addr, SI_CORE_SIZE); |
| 348 | ASSERT(GOODREGS(sii->regs[coreidx])); |
| 349 | } |
| 350 | sii->curmap = regs = sii->regs[coreidx]; |
| 351 | if (!sii->wrappers[coreidx]) { |
| 352 | sii->wrappers[coreidx] = REG_MAP(wrap, SI_CORE_SIZE); |
| 353 | ASSERT(GOODREGS(sii->wrappers[coreidx])); |
| 354 | } |
| 355 | sii->curwrap = sii->wrappers[coreidx]; |
| 356 | break; |
| 357 | |
| 358 | |
| 359 | case SPI_BUS: |
| 360 | case SDIO_BUS: |
| 361 | sii->curmap = regs = (void *)((uintptr)addr); |
| 362 | sii->curwrap = (void *)((uintptr)wrap); |
| 363 | break; |
| 364 | |
| 365 | case PCMCIA_BUS: |
| 366 | default: |
| 367 | ASSERT(0); |
| 368 | regs = NULL; |
| 369 | break; |
| 370 | } |
| 371 | |
| 372 | sii->curmap = regs; |
| 373 | sii->curidx = coreidx; |
| 374 | |
| 375 | return regs; |
| 376 | } |
| 377 | |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 378 | void |
| 379 | ai_coreaddrspaceX(si_t *sih, uint asidx, uint32 *addr, uint32 *size) |
| 380 | { |
| 381 | si_info_t *sii = SI_INFO(sih); |
| 382 | chipcregs_t *cc = NULL; |
| 383 | uint32 erombase, *eromptr, *eromlim; |
| 384 | uint i, j, cidx; |
| 385 | uint32 cia, cib, nmp, nsp; |
| 386 | uint32 asd, addrl, addrh, sizel, sizeh; |
| 387 | |
| 388 | for (i = 0; i < sii->numcores; i++) { |
| 389 | if (sii->coreid[i] == CC_CORE_ID) { |
| 390 | cc = (chipcregs_t *)sii->regs[i]; |
| 391 | break; |
| 392 | } |
| 393 | } |
| 394 | if (cc == NULL) |
| 395 | goto error; |
| 396 | |
| 397 | erombase = R_REG(sii->osh, &cc->eromptr); |
| 398 | eromptr = (uint32 *)REG_MAP(erombase, SI_CORE_SIZE); |
| 399 | eromlim = eromptr + (ER_REMAPCONTROL / sizeof(uint32)); |
| 400 | |
| 401 | cidx = sii->curidx; |
| 402 | cia = sii->cia[cidx]; |
| 403 | cib = sii->cib[cidx]; |
| 404 | |
| 405 | nmp = (cib & CIB_NMP_MASK) >> CIB_NMP_SHIFT; |
| 406 | nsp = (cib & CIB_NSP_MASK) >> CIB_NSP_SHIFT; |
| 407 | |
| 408 | |
| 409 | while (eromptr < eromlim) { |
| 410 | if ((get_erom_ent(sih, &eromptr, ER_TAG, ER_CI) == cia) && |
| 411 | (get_erom_ent(sih, &eromptr, 0, 0) == cib)) { |
| 412 | break; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | |
| 417 | for (i = 0; i < nmp; i++) |
| 418 | get_erom_ent(sih, &eromptr, ER_VALID, ER_VALID); |
| 419 | |
| 420 | |
| 421 | asd = get_asd(sih, &eromptr, 0, 0, AD_ST_SLAVE, &addrl, &addrh, &sizel, &sizeh); |
| 422 | if (asd == 0) { |
| 423 | |
| 424 | asd = get_asd(sih, &eromptr, 0, 0, AD_ST_BRIDGE, &addrl, &addrh, |
| 425 | &sizel, &sizeh); |
| 426 | } |
| 427 | |
| 428 | j = 1; |
| 429 | do { |
| 430 | asd = get_asd(sih, &eromptr, 0, j, AD_ST_SLAVE, &addrl, &addrh, |
| 431 | &sizel, &sizeh); |
| 432 | j++; |
| 433 | } while (asd != 0); |
| 434 | |
| 435 | |
| 436 | for (i = 1; i < nsp; i++) { |
| 437 | j = 0; |
| 438 | do { |
| 439 | asd = get_asd(sih, &eromptr, i, j, AD_ST_SLAVE, &addrl, &addrh, |
| 440 | &sizel, &sizeh); |
| 441 | if (asd == 0) |
| 442 | break; |
| 443 | |
| 444 | if (!asidx--) { |
| 445 | *addr = addrl; |
| 446 | *size = sizel; |
| 447 | return; |
| 448 | } |
| 449 | j++; |
| 450 | } while (1); |
| 451 | |
| 452 | if (j == 0) { |
| 453 | SI_ERROR((" SP %d has no address descriptors\n", i)); |
| 454 | break; |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | error: |
| 459 | *size = 0; |
| 460 | return; |
| 461 | } |
| 462 | |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 463 | |
| 464 | int |
| 465 | ai_numaddrspaces(si_t *sih) |
| 466 | { |
| 467 | return 2; |
| 468 | } |
| 469 | |
| 470 | |
| 471 | uint32 |
| 472 | ai_addrspace(si_t *sih, uint asidx) |
| 473 | { |
| 474 | si_info_t *sii; |
| 475 | uint cidx; |
| 476 | |
| 477 | sii = SI_INFO(sih); |
| 478 | cidx = sii->curidx; |
| 479 | |
| 480 | if (asidx == 0) |
| 481 | return sii->coresba[cidx]; |
| 482 | else if (asidx == 1) |
| 483 | return sii->coresba2[cidx]; |
| 484 | else { |
| 485 | SI_ERROR(("%s: Need to parse the erom again to find addr space %d\n", |
| 486 | __FUNCTION__, asidx)); |
| 487 | return 0; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | |
| 492 | uint32 |
| 493 | ai_addrspacesize(si_t *sih, uint asidx) |
| 494 | { |
| 495 | si_info_t *sii; |
| 496 | uint cidx; |
| 497 | |
| 498 | sii = SI_INFO(sih); |
| 499 | cidx = sii->curidx; |
| 500 | |
| 501 | if (asidx == 0) |
| 502 | return sii->coresba_size[cidx]; |
| 503 | else if (asidx == 1) |
| 504 | return sii->coresba2_size[cidx]; |
| 505 | else { |
| 506 | SI_ERROR(("%s: Need to parse the erom again to find addr space %d\n", |
| 507 | __FUNCTION__, asidx)); |
| 508 | return 0; |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | uint |
| 513 | ai_flag(si_t *sih) |
| 514 | { |
| 515 | si_info_t *sii; |
| 516 | aidmp_t *ai; |
| 517 | |
| 518 | sii = SI_INFO(sih); |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 519 | if (BCM47162_DMP()) { |
| 520 | SI_ERROR(("%s: Attempting to read MIPS DMP registers on 47162a0", __FUNCTION__)); |
| 521 | return sii->curidx; |
| 522 | } |
| 523 | if (BCM5357_DMP()) { |
| 524 | SI_ERROR(("%s: Attempting to read USB20H DMP registers on 5357b0\n", __FUNCTION__)); |
| 525 | return sii->curidx; |
| 526 | } |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 527 | ai = sii->curwrap; |
| 528 | |
| 529 | return (R_REG(sii->osh, &ai->oobselouta30) & 0x1f); |
| 530 | } |
| 531 | |
| 532 | void |
| 533 | ai_setint(si_t *sih, int siflag) |
| 534 | { |
| 535 | } |
| 536 | |
| 537 | uint |
| 538 | ai_wrap_reg(si_t *sih, uint32 offset, uint32 mask, uint32 val) |
| 539 | { |
| 540 | si_info_t *sii = SI_INFO(sih); |
| 541 | uint32 *map = (uint32 *) sii->curwrap; |
| 542 | |
| 543 | if (mask || val) { |
| 544 | uint32 w = R_REG(sii->osh, map+(offset/4)); |
| 545 | w &= ~mask; |
| 546 | w |= val; |
| 547 | W_REG(sii->osh, map+(offset/4), val); |
| 548 | } |
| 549 | |
| 550 | return (R_REG(sii->osh, map+(offset/4))); |
| 551 | } |
| 552 | |
| 553 | uint |
| 554 | ai_corevendor(si_t *sih) |
| 555 | { |
| 556 | si_info_t *sii; |
| 557 | uint32 cia; |
| 558 | |
| 559 | sii = SI_INFO(sih); |
| 560 | cia = sii->cia[sii->curidx]; |
| 561 | return ((cia & CIA_MFG_MASK) >> CIA_MFG_SHIFT); |
| 562 | } |
| 563 | |
| 564 | uint |
| 565 | ai_corerev(si_t *sih) |
| 566 | { |
| 567 | si_info_t *sii; |
| 568 | uint32 cib; |
| 569 | |
| 570 | sii = SI_INFO(sih); |
| 571 | cib = sii->cib[sii->curidx]; |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 572 | return remap_corerev(sih, (cib & CIB_REV_MASK) >> CIB_REV_SHIFT); |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | bool |
| 576 | ai_iscoreup(si_t *sih) |
| 577 | { |
| 578 | si_info_t *sii; |
| 579 | aidmp_t *ai; |
| 580 | |
| 581 | sii = SI_INFO(sih); |
| 582 | ai = sii->curwrap; |
| 583 | |
| 584 | return (((R_REG(sii->osh, &ai->ioctrl) & (SICF_FGC | SICF_CLOCK_EN)) == SICF_CLOCK_EN) && |
| 585 | ((R_REG(sii->osh, &ai->resetctrl) & AIRC_RESET) == 0)); |
| 586 | } |
| 587 | |
| 588 | |
| 589 | uint |
| 590 | ai_corereg(si_t *sih, uint coreidx, uint regoff, uint mask, uint val) |
| 591 | { |
| 592 | uint origidx = 0; |
| 593 | uint32 *r = NULL; |
| 594 | uint w; |
| 595 | uint intr_val = 0; |
| 596 | bool fast = FALSE; |
| 597 | si_info_t *sii; |
| 598 | |
| 599 | sii = SI_INFO(sih); |
| 600 | |
| 601 | ASSERT(GOODIDX(coreidx)); |
| 602 | ASSERT(regoff < SI_CORE_SIZE); |
| 603 | ASSERT((val & ~mask) == 0); |
| 604 | |
| 605 | if (coreidx >= SI_MAXCORES) |
| 606 | return 0; |
| 607 | |
| 608 | if (BUSTYPE(sih->bustype) == SI_BUS) { |
| 609 | |
| 610 | fast = TRUE; |
| 611 | |
| 612 | if (!sii->regs[coreidx]) { |
| 613 | sii->regs[coreidx] = REG_MAP(sii->coresba[coreidx], |
| 614 | SI_CORE_SIZE); |
| 615 | ASSERT(GOODREGS(sii->regs[coreidx])); |
| 616 | } |
| 617 | r = (uint32 *)((uchar *)sii->regs[coreidx] + regoff); |
| 618 | } else if (BUSTYPE(sih->bustype) == PCI_BUS) { |
| 619 | |
| 620 | |
| 621 | if ((sii->coreid[coreidx] == CC_CORE_ID) && SI_FAST(sii)) { |
| 622 | |
| 623 | |
| 624 | fast = TRUE; |
| 625 | r = (uint32 *)((char *)sii->curmap + PCI_16KB0_CCREGS_OFFSET + regoff); |
| 626 | } else if (sii->pub.buscoreidx == coreidx) { |
| 627 | |
| 628 | fast = TRUE; |
| 629 | if (SI_FAST(sii)) |
| 630 | r = (uint32 *)((char *)sii->curmap + |
| 631 | PCI_16KB0_PCIREGS_OFFSET + regoff); |
| 632 | else |
| 633 | r = (uint32 *)((char *)sii->curmap + |
| 634 | ((regoff >= SBCONFIGOFF) ? |
| 635 | PCI_BAR0_PCISBR_OFFSET : PCI_BAR0_PCIREGS_OFFSET) + |
| 636 | regoff); |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | if (!fast) { |
| 641 | INTR_OFF(sii, intr_val); |
| 642 | |
| 643 | |
| 644 | origidx = si_coreidx(&sii->pub); |
| 645 | |
| 646 | |
| 647 | r = (uint32*) ((uchar*) ai_setcoreidx(&sii->pub, coreidx) + regoff); |
| 648 | } |
| 649 | ASSERT(r != NULL); |
| 650 | |
| 651 | |
| 652 | if (mask || val) { |
| 653 | w = (R_REG(sii->osh, r) & ~mask) | val; |
| 654 | W_REG(sii->osh, r, w); |
| 655 | } |
| 656 | |
| 657 | |
| 658 | w = R_REG(sii->osh, r); |
| 659 | |
| 660 | if (!fast) { |
| 661 | |
| 662 | if (origidx != coreidx) |
| 663 | ai_setcoreidx(&sii->pub, origidx); |
| 664 | |
| 665 | INTR_RESTORE(sii, intr_val); |
| 666 | } |
| 667 | |
| 668 | return (w); |
| 669 | } |
| 670 | |
| 671 | void |
| 672 | ai_core_disable(si_t *sih, uint32 bits) |
| 673 | { |
| 674 | si_info_t *sii; |
| 675 | volatile uint32 dummy; |
Dmitry Shmidt | 4a3a0fa | 2012-04-12 10:18:39 -0700 | [diff] [blame^] | 676 | uint32 status; |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 677 | aidmp_t *ai; |
| 678 | |
| 679 | sii = SI_INFO(sih); |
| 680 | |
| 681 | ASSERT(GOODREGS(sii->curwrap)); |
| 682 | ai = sii->curwrap; |
| 683 | |
| 684 | |
| 685 | if (R_REG(sii->osh, &ai->resetctrl) & AIRC_RESET) |
| 686 | return; |
| 687 | |
Dmitry Shmidt | 4a3a0fa | 2012-04-12 10:18:39 -0700 | [diff] [blame^] | 688 | |
| 689 | SPINWAIT(((status = R_REG(sii->osh, &ai->resetstatus)) != 0), 300); |
| 690 | |
| 691 | |
| 692 | if (status != 0) { |
| 693 | |
| 694 | |
| 695 | SPINWAIT(((status = R_REG(sii->osh, &ai->resetstatus)) != 0), 10000); |
| 696 | |
| 697 | |
| 698 | } |
| 699 | |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 700 | W_REG(sii->osh, &ai->ioctrl, bits); |
| 701 | dummy = R_REG(sii->osh, &ai->ioctrl); |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 702 | BCM_REFERENCE(dummy); |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 703 | OSL_DELAY(10); |
| 704 | |
| 705 | W_REG(sii->osh, &ai->resetctrl, AIRC_RESET); |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 706 | dummy = R_REG(sii->osh, &ai->resetctrl); |
| 707 | BCM_REFERENCE(dummy); |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 708 | OSL_DELAY(1); |
| 709 | } |
| 710 | |
| 711 | |
| 712 | void |
| 713 | ai_core_reset(si_t *sih, uint32 bits, uint32 resetbits) |
| 714 | { |
| 715 | si_info_t *sii; |
| 716 | aidmp_t *ai; |
| 717 | volatile uint32 dummy; |
| 718 | |
| 719 | sii = SI_INFO(sih); |
| 720 | ASSERT(GOODREGS(sii->curwrap)); |
| 721 | ai = sii->curwrap; |
| 722 | |
| 723 | |
| 724 | ai_core_disable(sih, (bits | resetbits)); |
| 725 | |
| 726 | |
| 727 | W_REG(sii->osh, &ai->ioctrl, (bits | SICF_FGC | SICF_CLOCK_EN)); |
| 728 | dummy = R_REG(sii->osh, &ai->ioctrl); |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 729 | BCM_REFERENCE(dummy); |
| 730 | |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 731 | W_REG(sii->osh, &ai->resetctrl, 0); |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 732 | dummy = R_REG(sii->osh, &ai->resetctrl); |
| 733 | BCM_REFERENCE(dummy); |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 734 | OSL_DELAY(1); |
| 735 | |
| 736 | W_REG(sii->osh, &ai->ioctrl, (bits | SICF_CLOCK_EN)); |
| 737 | dummy = R_REG(sii->osh, &ai->ioctrl); |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 738 | BCM_REFERENCE(dummy); |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 739 | OSL_DELAY(1); |
| 740 | } |
| 741 | |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 742 | void |
| 743 | ai_core_cflags_wo(si_t *sih, uint32 mask, uint32 val) |
| 744 | { |
| 745 | si_info_t *sii; |
| 746 | aidmp_t *ai; |
| 747 | uint32 w; |
| 748 | |
| 749 | sii = SI_INFO(sih); |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 750 | |
| 751 | if (BCM47162_DMP()) { |
| 752 | SI_ERROR(("%s: Accessing MIPS DMP register (ioctrl) on 47162a0", |
| 753 | __FUNCTION__)); |
| 754 | return; |
| 755 | } |
| 756 | if (BCM5357_DMP()) { |
| 757 | SI_ERROR(("%s: Accessing USB20H DMP register (ioctrl) on 5357\n", |
| 758 | __FUNCTION__)); |
| 759 | return; |
| 760 | } |
| 761 | |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 762 | ASSERT(GOODREGS(sii->curwrap)); |
| 763 | ai = sii->curwrap; |
| 764 | |
| 765 | ASSERT((val & ~mask) == 0); |
| 766 | |
| 767 | if (mask || val) { |
| 768 | w = ((R_REG(sii->osh, &ai->ioctrl) & ~mask) | val); |
| 769 | W_REG(sii->osh, &ai->ioctrl, w); |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | uint32 |
| 774 | ai_core_cflags(si_t *sih, uint32 mask, uint32 val) |
| 775 | { |
| 776 | si_info_t *sii; |
| 777 | aidmp_t *ai; |
| 778 | uint32 w; |
| 779 | |
| 780 | sii = SI_INFO(sih); |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 781 | if (BCM47162_DMP()) { |
| 782 | SI_ERROR(("%s: Accessing MIPS DMP register (ioctrl) on 47162a0", |
| 783 | __FUNCTION__)); |
| 784 | return 0; |
| 785 | } |
| 786 | if (BCM5357_DMP()) { |
| 787 | SI_ERROR(("%s: Accessing USB20H DMP register (ioctrl) on 5357\n", |
| 788 | __FUNCTION__)); |
| 789 | return 0; |
| 790 | } |
| 791 | |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 792 | ASSERT(GOODREGS(sii->curwrap)); |
| 793 | ai = sii->curwrap; |
| 794 | |
| 795 | ASSERT((val & ~mask) == 0); |
| 796 | |
| 797 | if (mask || val) { |
| 798 | w = ((R_REG(sii->osh, &ai->ioctrl) & ~mask) | val); |
| 799 | W_REG(sii->osh, &ai->ioctrl, w); |
| 800 | } |
| 801 | |
| 802 | return R_REG(sii->osh, &ai->ioctrl); |
| 803 | } |
| 804 | |
| 805 | uint32 |
| 806 | ai_core_sflags(si_t *sih, uint32 mask, uint32 val) |
| 807 | { |
| 808 | si_info_t *sii; |
| 809 | aidmp_t *ai; |
| 810 | uint32 w; |
| 811 | |
| 812 | sii = SI_INFO(sih); |
Dmitry Shmidt | 8325232 | 2012-03-16 12:52:00 -0700 | [diff] [blame] | 813 | if (BCM47162_DMP()) { |
| 814 | SI_ERROR(("%s: Accessing MIPS DMP register (iostatus) on 47162a0", |
| 815 | __FUNCTION__)); |
| 816 | return 0; |
| 817 | } |
| 818 | if (BCM5357_DMP()) { |
| 819 | SI_ERROR(("%s: Accessing USB20H DMP register (iostatus) on 5357\n", |
| 820 | __FUNCTION__)); |
| 821 | return 0; |
| 822 | } |
| 823 | |
Dmitry Shmidt | 8ce1727 | 2011-05-24 11:14:33 -0700 | [diff] [blame] | 824 | ASSERT(GOODREGS(sii->curwrap)); |
| 825 | ai = sii->curwrap; |
| 826 | |
| 827 | ASSERT((val & ~mask) == 0); |
| 828 | ASSERT((mask & ~SISF_CORE_BITS) == 0); |
| 829 | |
| 830 | if (mask || val) { |
| 831 | w = ((R_REG(sii->osh, &ai->iostatus) & ~mask) | val); |
| 832 | W_REG(sii->osh, &ai->iostatus, w); |
| 833 | } |
| 834 | |
| 835 | return R_REG(sii->osh, &ai->iostatus); |
| 836 | } |