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 | * |
| 5 | * Copyright (C) 1999-2011, Broadcom Corporation |
| 6 | * |
| 7 | * Unless you and Broadcom execute a separate written software license |
| 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 | * |
| 25 | * $Id: aiutils.c,v 1.26.2.1 2010-03-09 18:41:21 Exp $ |
| 26 | */ |
| 27 | |
| 28 | |
| 29 | #include <typedefs.h> |
| 30 | #include <bcmdefs.h> |
| 31 | #include <osl.h> |
| 32 | #include <bcmutils.h> |
| 33 | #include <siutils.h> |
| 34 | #include <hndsoc.h> |
| 35 | #include <sbchipc.h> |
| 36 | #include <pcicfg.h> |
| 37 | |
| 38 | #include "siutils_priv.h" |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | static uint32 |
| 45 | get_erom_ent(si_t *sih, uint32 **eromptr, uint32 mask, uint32 match) |
| 46 | { |
| 47 | uint32 ent; |
| 48 | uint inv = 0, nom = 0; |
| 49 | |
| 50 | while (TRUE) { |
| 51 | ent = R_REG(si_osh(sih), *eromptr); |
| 52 | (*eromptr)++; |
| 53 | |
| 54 | if (mask == 0) |
| 55 | break; |
| 56 | |
| 57 | if ((ent & ER_VALID) == 0) { |
| 58 | inv++; |
| 59 | continue; |
| 60 | } |
| 61 | |
| 62 | if (ent == (ER_END | ER_VALID)) |
| 63 | break; |
| 64 | |
| 65 | if ((ent & mask) == match) |
| 66 | break; |
| 67 | |
| 68 | nom++; |
| 69 | } |
| 70 | |
| 71 | SI_VMSG(("%s: Returning ent 0x%08x\n", __FUNCTION__, ent)); |
| 72 | if (inv + nom) { |
| 73 | SI_VMSG((" after %d invalid and %d non-matching entries\n", inv, nom)); |
| 74 | } |
| 75 | return ent; |
| 76 | } |
| 77 | |
| 78 | static uint32 |
| 79 | get_asd(si_t *sih, uint32 **eromptr, uint sp, uint ad, uint st, uint32 *addrl, uint32 *addrh, |
| 80 | uint32 *sizel, uint32 *sizeh) |
| 81 | { |
| 82 | uint32 asd, sz, szd; |
| 83 | |
| 84 | asd = get_erom_ent(sih, eromptr, ER_VALID, ER_VALID); |
| 85 | if (((asd & ER_TAG1) != ER_ADD) || |
| 86 | (((asd & AD_SP_MASK) >> AD_SP_SHIFT) != sp) || |
| 87 | ((asd & AD_ST_MASK) != st)) { |
| 88 | |
| 89 | (*eromptr)--; |
| 90 | return 0; |
| 91 | } |
| 92 | *addrl = asd & AD_ADDR_MASK; |
| 93 | if (asd & AD_AG32) |
| 94 | *addrh = get_erom_ent(sih, eromptr, 0, 0); |
| 95 | else |
| 96 | *addrh = 0; |
| 97 | *sizeh = 0; |
| 98 | sz = asd & AD_SZ_MASK; |
| 99 | if (sz == AD_SZ_SZD) { |
| 100 | szd = get_erom_ent(sih, eromptr, 0, 0); |
| 101 | *sizel = szd & SD_SZ_MASK; |
| 102 | if (szd & SD_SG32) |
| 103 | *sizeh = get_erom_ent(sih, eromptr, 0, 0); |
| 104 | } else |
| 105 | *sizel = AD_SZ_BASE << (sz >> AD_SZ_SHIFT); |
| 106 | |
| 107 | SI_VMSG((" SP %d, ad %d: st = %d, 0x%08x_0x%08x @ 0x%08x_0x%08x\n", |
| 108 | sp, ad, st, *sizeh, *sizel, *addrh, *addrl)); |
| 109 | |
| 110 | return asd; |
| 111 | } |
| 112 | |
| 113 | static void |
| 114 | ai_hwfixup(si_info_t *sii) |
| 115 | { |
| 116 | } |
| 117 | |
| 118 | |
| 119 | void |
| 120 | ai_scan(si_t *sih, void *regs, uint devid) |
| 121 | { |
| 122 | si_info_t *sii = SI_INFO(sih); |
| 123 | chipcregs_t *cc = (chipcregs_t *)regs; |
| 124 | uint32 erombase, *eromptr, *eromlim; |
| 125 | |
| 126 | erombase = R_REG(sii->osh, &cc->eromptr); |
| 127 | |
| 128 | switch (BUSTYPE(sih->bustype)) { |
| 129 | case SI_BUS: |
| 130 | eromptr = (uint32 *)REG_MAP(erombase, SI_CORE_SIZE); |
| 131 | break; |
| 132 | |
| 133 | case PCI_BUS: |
| 134 | |
| 135 | sii->curwrap = (void *)((uintptr)regs + SI_CORE_SIZE); |
| 136 | |
| 137 | |
| 138 | OSL_PCI_WRITE_CONFIG(sii->osh, PCI_BAR0_WIN, 4, erombase); |
| 139 | eromptr = regs; |
| 140 | break; |
| 141 | |
| 142 | case SPI_BUS: |
| 143 | case SDIO_BUS: |
| 144 | eromptr = (uint32 *)(uintptr)erombase; |
| 145 | break; |
| 146 | |
| 147 | case PCMCIA_BUS: |
| 148 | default: |
| 149 | SI_ERROR(("Don't know how to do AXI enumertion on bus %d\n", sih->bustype)); |
| 150 | ASSERT(0); |
| 151 | return; |
| 152 | } |
| 153 | eromlim = eromptr + (ER_REMAPCONTROL / sizeof(uint32)); |
| 154 | |
| 155 | SI_VMSG(("ai_scan: regs = 0x%p, erombase = 0x%08x, eromptr = 0x%p, eromlim = 0x%p\n", |
| 156 | regs, erombase, eromptr, eromlim)); |
| 157 | while (eromptr < eromlim) { |
| 158 | uint32 cia, cib, cid, mfg, crev, nmw, nsw, nmp, nsp; |
| 159 | uint32 mpd, asd, addrl, addrh, sizel, sizeh; |
| 160 | uint32 *base; |
| 161 | uint i, j, idx; |
| 162 | bool br; |
| 163 | |
| 164 | br = FALSE; |
| 165 | |
| 166 | |
| 167 | cia = get_erom_ent(sih, &eromptr, ER_TAG, ER_CI); |
| 168 | if (cia == (ER_END | ER_VALID)) { |
| 169 | SI_VMSG(("Found END of erom after %d cores\n", sii->numcores)); |
| 170 | ai_hwfixup(sii); |
| 171 | return; |
| 172 | } |
| 173 | base = eromptr - 1; |
| 174 | cib = get_erom_ent(sih, &eromptr, 0, 0); |
| 175 | |
| 176 | if ((cib & ER_TAG) != ER_CI) { |
| 177 | SI_ERROR(("CIA not followed by CIB\n")); |
| 178 | goto error; |
| 179 | } |
| 180 | |
| 181 | cid = (cia & CIA_CID_MASK) >> CIA_CID_SHIFT; |
| 182 | mfg = (cia & CIA_MFG_MASK) >> CIA_MFG_SHIFT; |
| 183 | crev = (cib & CIB_REV_MASK) >> CIB_REV_SHIFT; |
| 184 | nmw = (cib & CIB_NMW_MASK) >> CIB_NMW_SHIFT; |
| 185 | nsw = (cib & CIB_NSW_MASK) >> CIB_NSW_SHIFT; |
| 186 | nmp = (cib & CIB_NMP_MASK) >> CIB_NMP_SHIFT; |
| 187 | nsp = (cib & CIB_NSP_MASK) >> CIB_NSP_SHIFT; |
| 188 | |
| 189 | SI_VMSG(("Found component 0x%04x/0x%04x rev %d at erom addr 0x%p, with nmw = %d, " |
| 190 | "nsw = %d, nmp = %d & nsp = %d\n", |
| 191 | mfg, cid, crev, base, nmw, nsw, nmp, nsp)); |
| 192 | |
| 193 | if (((mfg == MFGID_ARM) && (cid == DEF_AI_COMP)) || (nsp == 0)) |
| 194 | continue; |
| 195 | if ((nmw + nsw == 0)) { |
| 196 | |
| 197 | if (cid == OOB_ROUTER_CORE_ID) { |
| 198 | asd = get_asd(sih, &eromptr, 0, 0, AD_ST_SLAVE, |
| 199 | &addrl, &addrh, &sizel, &sizeh); |
| 200 | if (asd != 0) { |
| 201 | sii->oob_router = addrl; |
| 202 | } |
| 203 | } |
| 204 | continue; |
| 205 | } |
| 206 | |
| 207 | idx = sii->numcores; |
| 208 | |
| 209 | sii->cia[idx] = cia; |
| 210 | sii->cib[idx] = cib; |
| 211 | sii->coreid[idx] = cid; |
| 212 | |
| 213 | for (i = 0; i < nmp; i++) { |
| 214 | mpd = get_erom_ent(sih, &eromptr, ER_VALID, ER_VALID); |
| 215 | if ((mpd & ER_TAG) != ER_MP) { |
| 216 | SI_ERROR(("Not enough MP entries for component 0x%x\n", cid)); |
| 217 | goto error; |
| 218 | } |
| 219 | SI_VMSG((" Master port %d, mp: %d id: %d\n", i, |
| 220 | (mpd & MPD_MP_MASK) >> MPD_MP_SHIFT, |
| 221 | (mpd & MPD_MUI_MASK) >> MPD_MUI_SHIFT)); |
| 222 | } |
| 223 | |
| 224 | |
| 225 | asd = get_asd(sih, &eromptr, 0, 0, AD_ST_SLAVE, &addrl, &addrh, &sizel, &sizeh); |
| 226 | if (asd == 0) { |
| 227 | |
| 228 | asd = get_asd(sih, &eromptr, 0, 0, AD_ST_BRIDGE, &addrl, &addrh, |
| 229 | &sizel, &sizeh); |
| 230 | if (asd != 0) |
| 231 | br = TRUE; |
| 232 | else |
| 233 | if ((addrh != 0) || (sizeh != 0) || (sizel != SI_CORE_SIZE)) { |
| 234 | SI_ERROR(("First Slave ASD for core 0x%04x malformed " |
| 235 | "(0x%08x)\n", cid, asd)); |
| 236 | goto error; |
| 237 | } |
| 238 | } |
| 239 | sii->coresba[idx] = addrl; |
| 240 | sii->coresba_size[idx] = sizel; |
| 241 | |
| 242 | j = 1; |
| 243 | do { |
| 244 | asd = get_asd(sih, &eromptr, 0, j, AD_ST_SLAVE, &addrl, &addrh, |
| 245 | &sizel, &sizeh); |
| 246 | if ((asd != 0) && (j == 1) && (sizel == SI_CORE_SIZE)) { |
| 247 | sii->coresba2[idx] = addrl; |
| 248 | sii->coresba2_size[idx] = sizel; |
| 249 | } |
| 250 | j++; |
| 251 | } while (asd != 0); |
| 252 | |
| 253 | |
| 254 | for (i = 1; i < nsp; i++) { |
| 255 | j = 0; |
| 256 | do { |
| 257 | asd = get_asd(sih, &eromptr, i, j++, AD_ST_SLAVE, &addrl, &addrh, |
| 258 | &sizel, &sizeh); |
| 259 | } while (asd != 0); |
| 260 | if (j == 0) { |
| 261 | SI_ERROR((" SP %d has no address descriptors\n", i)); |
| 262 | goto error; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | |
| 267 | for (i = 0; i < nmw; i++) { |
| 268 | asd = get_asd(sih, &eromptr, i, 0, AD_ST_MWRAP, &addrl, &addrh, |
| 269 | &sizel, &sizeh); |
| 270 | if (asd == 0) { |
| 271 | SI_ERROR(("Missing descriptor for MW %d\n", i)); |
| 272 | goto error; |
| 273 | } |
| 274 | if ((sizeh != 0) || (sizel != SI_CORE_SIZE)) { |
| 275 | SI_ERROR(("Master wrapper %d is not 4KB\n", i)); |
| 276 | goto error; |
| 277 | } |
| 278 | if (i == 0) |
| 279 | sii->wrapba[idx] = addrl; |
| 280 | } |
| 281 | |
| 282 | |
| 283 | for (i = 0; i < nsw; i++) { |
| 284 | uint fwp = (nsp == 1) ? 0 : 1; |
| 285 | asd = get_asd(sih, &eromptr, fwp + i, 0, AD_ST_SWRAP, &addrl, &addrh, |
| 286 | &sizel, &sizeh); |
| 287 | if (asd == 0) { |
| 288 | SI_ERROR(("Missing descriptor for SW %d\n", i)); |
| 289 | goto error; |
| 290 | } |
| 291 | if ((sizeh != 0) || (sizel != SI_CORE_SIZE)) { |
| 292 | SI_ERROR(("Slave wrapper %d is not 4KB\n", i)); |
| 293 | goto error; |
| 294 | } |
| 295 | if ((nmw == 0) && (i == 0)) |
| 296 | sii->wrapba[idx] = addrl; |
| 297 | } |
| 298 | |
| 299 | |
| 300 | if (br) |
| 301 | continue; |
| 302 | |
| 303 | |
| 304 | sii->numcores++; |
| 305 | } |
| 306 | |
| 307 | SI_ERROR(("Reached end of erom without finding END")); |
| 308 | |
| 309 | error: |
| 310 | sii->numcores = 0; |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | |
| 315 | void * |
| 316 | ai_setcoreidx(si_t *sih, uint coreidx) |
| 317 | { |
| 318 | si_info_t *sii = SI_INFO(sih); |
| 319 | uint32 addr = sii->coresba[coreidx]; |
| 320 | uint32 wrap = sii->wrapba[coreidx]; |
| 321 | void *regs; |
| 322 | |
| 323 | if (coreidx >= sii->numcores) |
| 324 | return (NULL); |
| 325 | |
| 326 | |
| 327 | ASSERT((sii->intrsenabled_fn == NULL) || !(*(sii)->intrsenabled_fn)((sii)->intr_arg)); |
| 328 | |
| 329 | switch (BUSTYPE(sih->bustype)) { |
| 330 | case SI_BUS: |
| 331 | |
| 332 | if (!sii->regs[coreidx]) { |
| 333 | sii->regs[coreidx] = REG_MAP(addr, SI_CORE_SIZE); |
| 334 | ASSERT(GOODREGS(sii->regs[coreidx])); |
| 335 | } |
| 336 | sii->curmap = regs = sii->regs[coreidx]; |
| 337 | if (!sii->wrappers[coreidx]) { |
| 338 | sii->wrappers[coreidx] = REG_MAP(wrap, SI_CORE_SIZE); |
| 339 | ASSERT(GOODREGS(sii->wrappers[coreidx])); |
| 340 | } |
| 341 | sii->curwrap = sii->wrappers[coreidx]; |
| 342 | break; |
| 343 | |
| 344 | |
| 345 | case SPI_BUS: |
| 346 | case SDIO_BUS: |
| 347 | sii->curmap = regs = (void *)((uintptr)addr); |
| 348 | sii->curwrap = (void *)((uintptr)wrap); |
| 349 | break; |
| 350 | |
| 351 | case PCMCIA_BUS: |
| 352 | default: |
| 353 | ASSERT(0); |
| 354 | regs = NULL; |
| 355 | break; |
| 356 | } |
| 357 | |
| 358 | sii->curmap = regs; |
| 359 | sii->curidx = coreidx; |
| 360 | |
| 361 | return regs; |
| 362 | } |
| 363 | |
| 364 | |
| 365 | int |
| 366 | ai_numaddrspaces(si_t *sih) |
| 367 | { |
| 368 | return 2; |
| 369 | } |
| 370 | |
| 371 | |
| 372 | uint32 |
| 373 | ai_addrspace(si_t *sih, uint asidx) |
| 374 | { |
| 375 | si_info_t *sii; |
| 376 | uint cidx; |
| 377 | |
| 378 | sii = SI_INFO(sih); |
| 379 | cidx = sii->curidx; |
| 380 | |
| 381 | if (asidx == 0) |
| 382 | return sii->coresba[cidx]; |
| 383 | else if (asidx == 1) |
| 384 | return sii->coresba2[cidx]; |
| 385 | else { |
| 386 | SI_ERROR(("%s: Need to parse the erom again to find addr space %d\n", |
| 387 | __FUNCTION__, asidx)); |
| 388 | return 0; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | |
| 393 | uint32 |
| 394 | ai_addrspacesize(si_t *sih, uint asidx) |
| 395 | { |
| 396 | si_info_t *sii; |
| 397 | uint cidx; |
| 398 | |
| 399 | sii = SI_INFO(sih); |
| 400 | cidx = sii->curidx; |
| 401 | |
| 402 | if (asidx == 0) |
| 403 | return sii->coresba_size[cidx]; |
| 404 | else if (asidx == 1) |
| 405 | return sii->coresba2_size[cidx]; |
| 406 | else { |
| 407 | SI_ERROR(("%s: Need to parse the erom again to find addr space %d\n", |
| 408 | __FUNCTION__, asidx)); |
| 409 | return 0; |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | uint |
| 414 | ai_flag(si_t *sih) |
| 415 | { |
| 416 | si_info_t *sii; |
| 417 | aidmp_t *ai; |
| 418 | |
| 419 | sii = SI_INFO(sih); |
| 420 | ai = sii->curwrap; |
| 421 | |
| 422 | return (R_REG(sii->osh, &ai->oobselouta30) & 0x1f); |
| 423 | } |
| 424 | |
| 425 | void |
| 426 | ai_setint(si_t *sih, int siflag) |
| 427 | { |
| 428 | } |
| 429 | |
| 430 | uint |
| 431 | ai_wrap_reg(si_t *sih, uint32 offset, uint32 mask, uint32 val) |
| 432 | { |
| 433 | si_info_t *sii = SI_INFO(sih); |
| 434 | uint32 *map = (uint32 *) sii->curwrap; |
| 435 | |
| 436 | if (mask || val) { |
| 437 | uint32 w = R_REG(sii->osh, map+(offset/4)); |
| 438 | w &= ~mask; |
| 439 | w |= val; |
| 440 | W_REG(sii->osh, map+(offset/4), val); |
| 441 | } |
| 442 | |
| 443 | return (R_REG(sii->osh, map+(offset/4))); |
| 444 | } |
| 445 | |
| 446 | uint |
| 447 | ai_corevendor(si_t *sih) |
| 448 | { |
| 449 | si_info_t *sii; |
| 450 | uint32 cia; |
| 451 | |
| 452 | sii = SI_INFO(sih); |
| 453 | cia = sii->cia[sii->curidx]; |
| 454 | return ((cia & CIA_MFG_MASK) >> CIA_MFG_SHIFT); |
| 455 | } |
| 456 | |
| 457 | uint |
| 458 | ai_corerev(si_t *sih) |
| 459 | { |
| 460 | si_info_t *sii; |
| 461 | uint32 cib; |
| 462 | |
| 463 | sii = SI_INFO(sih); |
| 464 | cib = sii->cib[sii->curidx]; |
| 465 | return ((cib & CIB_REV_MASK) >> CIB_REV_SHIFT); |
| 466 | } |
| 467 | |
| 468 | bool |
| 469 | ai_iscoreup(si_t *sih) |
| 470 | { |
| 471 | si_info_t *sii; |
| 472 | aidmp_t *ai; |
| 473 | |
| 474 | sii = SI_INFO(sih); |
| 475 | ai = sii->curwrap; |
| 476 | |
| 477 | return (((R_REG(sii->osh, &ai->ioctrl) & (SICF_FGC | SICF_CLOCK_EN)) == SICF_CLOCK_EN) && |
| 478 | ((R_REG(sii->osh, &ai->resetctrl) & AIRC_RESET) == 0)); |
| 479 | } |
| 480 | |
| 481 | |
| 482 | uint |
| 483 | ai_corereg(si_t *sih, uint coreidx, uint regoff, uint mask, uint val) |
| 484 | { |
| 485 | uint origidx = 0; |
| 486 | uint32 *r = NULL; |
| 487 | uint w; |
| 488 | uint intr_val = 0; |
| 489 | bool fast = FALSE; |
| 490 | si_info_t *sii; |
| 491 | |
| 492 | sii = SI_INFO(sih); |
| 493 | |
| 494 | ASSERT(GOODIDX(coreidx)); |
| 495 | ASSERT(regoff < SI_CORE_SIZE); |
| 496 | ASSERT((val & ~mask) == 0); |
| 497 | |
| 498 | if (coreidx >= SI_MAXCORES) |
| 499 | return 0; |
| 500 | |
| 501 | if (BUSTYPE(sih->bustype) == SI_BUS) { |
| 502 | |
| 503 | fast = TRUE; |
| 504 | |
| 505 | if (!sii->regs[coreidx]) { |
| 506 | sii->regs[coreidx] = REG_MAP(sii->coresba[coreidx], |
| 507 | SI_CORE_SIZE); |
| 508 | ASSERT(GOODREGS(sii->regs[coreidx])); |
| 509 | } |
| 510 | r = (uint32 *)((uchar *)sii->regs[coreidx] + regoff); |
| 511 | } else if (BUSTYPE(sih->bustype) == PCI_BUS) { |
| 512 | |
| 513 | |
| 514 | if ((sii->coreid[coreidx] == CC_CORE_ID) && SI_FAST(sii)) { |
| 515 | |
| 516 | |
| 517 | fast = TRUE; |
| 518 | r = (uint32 *)((char *)sii->curmap + PCI_16KB0_CCREGS_OFFSET + regoff); |
| 519 | } else if (sii->pub.buscoreidx == coreidx) { |
| 520 | |
| 521 | fast = TRUE; |
| 522 | if (SI_FAST(sii)) |
| 523 | r = (uint32 *)((char *)sii->curmap + |
| 524 | PCI_16KB0_PCIREGS_OFFSET + regoff); |
| 525 | else |
| 526 | r = (uint32 *)((char *)sii->curmap + |
| 527 | ((regoff >= SBCONFIGOFF) ? |
| 528 | PCI_BAR0_PCISBR_OFFSET : PCI_BAR0_PCIREGS_OFFSET) + |
| 529 | regoff); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | if (!fast) { |
| 534 | INTR_OFF(sii, intr_val); |
| 535 | |
| 536 | |
| 537 | origidx = si_coreidx(&sii->pub); |
| 538 | |
| 539 | |
| 540 | r = (uint32*) ((uchar*) ai_setcoreidx(&sii->pub, coreidx) + regoff); |
| 541 | } |
| 542 | ASSERT(r != NULL); |
| 543 | |
| 544 | |
| 545 | if (mask || val) { |
| 546 | w = (R_REG(sii->osh, r) & ~mask) | val; |
| 547 | W_REG(sii->osh, r, w); |
| 548 | } |
| 549 | |
| 550 | |
| 551 | w = R_REG(sii->osh, r); |
| 552 | |
| 553 | if (!fast) { |
| 554 | |
| 555 | if (origidx != coreidx) |
| 556 | ai_setcoreidx(&sii->pub, origidx); |
| 557 | |
| 558 | INTR_RESTORE(sii, intr_val); |
| 559 | } |
| 560 | |
| 561 | return (w); |
| 562 | } |
| 563 | |
| 564 | void |
| 565 | ai_core_disable(si_t *sih, uint32 bits) |
| 566 | { |
| 567 | si_info_t *sii; |
| 568 | volatile uint32 dummy; |
| 569 | aidmp_t *ai; |
| 570 | |
| 571 | sii = SI_INFO(sih); |
| 572 | |
| 573 | ASSERT(GOODREGS(sii->curwrap)); |
| 574 | ai = sii->curwrap; |
| 575 | |
| 576 | |
| 577 | if (R_REG(sii->osh, &ai->resetctrl) & AIRC_RESET) |
| 578 | return; |
| 579 | |
| 580 | W_REG(sii->osh, &ai->ioctrl, bits); |
| 581 | dummy = R_REG(sii->osh, &ai->ioctrl); |
| 582 | OSL_DELAY(10); |
| 583 | |
| 584 | W_REG(sii->osh, &ai->resetctrl, AIRC_RESET); |
| 585 | OSL_DELAY(1); |
| 586 | } |
| 587 | |
| 588 | |
| 589 | void |
| 590 | ai_core_reset(si_t *sih, uint32 bits, uint32 resetbits) |
| 591 | { |
| 592 | si_info_t *sii; |
| 593 | aidmp_t *ai; |
| 594 | volatile uint32 dummy; |
| 595 | |
| 596 | sii = SI_INFO(sih); |
| 597 | ASSERT(GOODREGS(sii->curwrap)); |
| 598 | ai = sii->curwrap; |
| 599 | |
| 600 | |
| 601 | ai_core_disable(sih, (bits | resetbits)); |
| 602 | |
| 603 | |
| 604 | W_REG(sii->osh, &ai->ioctrl, (bits | SICF_FGC | SICF_CLOCK_EN)); |
| 605 | dummy = R_REG(sii->osh, &ai->ioctrl); |
| 606 | W_REG(sii->osh, &ai->resetctrl, 0); |
| 607 | OSL_DELAY(1); |
| 608 | |
| 609 | W_REG(sii->osh, &ai->ioctrl, (bits | SICF_CLOCK_EN)); |
| 610 | dummy = R_REG(sii->osh, &ai->ioctrl); |
| 611 | OSL_DELAY(1); |
| 612 | } |
| 613 | |
| 614 | |
| 615 | void |
| 616 | ai_core_cflags_wo(si_t *sih, uint32 mask, uint32 val) |
| 617 | { |
| 618 | si_info_t *sii; |
| 619 | aidmp_t *ai; |
| 620 | uint32 w; |
| 621 | |
| 622 | sii = SI_INFO(sih); |
| 623 | ASSERT(GOODREGS(sii->curwrap)); |
| 624 | ai = sii->curwrap; |
| 625 | |
| 626 | ASSERT((val & ~mask) == 0); |
| 627 | |
| 628 | if (mask || val) { |
| 629 | w = ((R_REG(sii->osh, &ai->ioctrl) & ~mask) | val); |
| 630 | W_REG(sii->osh, &ai->ioctrl, w); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | uint32 |
| 635 | ai_core_cflags(si_t *sih, uint32 mask, uint32 val) |
| 636 | { |
| 637 | si_info_t *sii; |
| 638 | aidmp_t *ai; |
| 639 | uint32 w; |
| 640 | |
| 641 | sii = SI_INFO(sih); |
| 642 | ASSERT(GOODREGS(sii->curwrap)); |
| 643 | ai = sii->curwrap; |
| 644 | |
| 645 | ASSERT((val & ~mask) == 0); |
| 646 | |
| 647 | if (mask || val) { |
| 648 | w = ((R_REG(sii->osh, &ai->ioctrl) & ~mask) | val); |
| 649 | W_REG(sii->osh, &ai->ioctrl, w); |
| 650 | } |
| 651 | |
| 652 | return R_REG(sii->osh, &ai->ioctrl); |
| 653 | } |
| 654 | |
| 655 | uint32 |
| 656 | ai_core_sflags(si_t *sih, uint32 mask, uint32 val) |
| 657 | { |
| 658 | si_info_t *sii; |
| 659 | aidmp_t *ai; |
| 660 | uint32 w; |
| 661 | |
| 662 | sii = SI_INFO(sih); |
| 663 | ASSERT(GOODREGS(sii->curwrap)); |
| 664 | ai = sii->curwrap; |
| 665 | |
| 666 | ASSERT((val & ~mask) == 0); |
| 667 | ASSERT((mask & ~SISF_CORE_BITS) == 0); |
| 668 | |
| 669 | if (mask || val) { |
| 670 | w = ((R_REG(sii->osh, &ai->iostatus) & ~mask) | val); |
| 671 | W_REG(sii->osh, &ai->iostatus, w); |
| 672 | } |
| 673 | |
| 674 | return R_REG(sii->osh, &ai->iostatus); |
| 675 | } |