upload tizen1.0 source
[kernel/linux-2.6.36.git] / drivers / net / wireless / bcm4330 / src / shared / aiutils.c
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 $
26  */
27
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
39 #define BCM47162_DMP() (0)
40
41 /* EROM parsing */
42
43 static uint32
44 get_erom_ent(si_t *sih, uint32 **eromptr, uint32 mask, uint32 match)
45 {
46         uint32 ent;
47         uint inv = 0, nom = 0;
48
49         while (TRUE) {
50                 ent = R_REG(si_osh(sih), *eromptr);
51                 (*eromptr)++;
52
53                 if (mask == 0)
54                         break;
55
56                 if ((ent & ER_VALID) == 0) {
57                         inv++;
58                         continue;
59                 }
60
61                 if (ent == (ER_END | ER_VALID))
62                         break;
63
64                 if ((ent & mask) == match)
65                         break;
66
67                 nom++;
68         }
69
70         SI_VMSG(("%s: Returning ent 0x%08x\n", __FUNCTION__, ent));
71         if (inv + nom) {
72                 SI_VMSG(("  after %d invalid and %d non-matching entries\n", inv, nom));
73         }
74         return ent;
75 }
76
77 static uint32
78 get_asd(si_t *sih, uint32 **eromptr, uint sp, uint ad, uint st, uint32 *addrl, uint32 *addrh,
79         uint32 *sizel, uint32 *sizeh)
80 {
81         uint32 asd, sz, szd;
82
83         asd = get_erom_ent(sih, eromptr, ER_VALID, ER_VALID);
84         if (((asd & ER_TAG1) != ER_ADD) ||
85             (((asd & AD_SP_MASK) >> AD_SP_SHIFT) != sp) ||
86             ((asd & AD_ST_MASK) != st)) {
87                 /* This is not what we want, "push" it back */
88                 (*eromptr)--;
89                 return 0;
90         }
91         *addrl = asd & AD_ADDR_MASK;
92         if (asd & AD_AG32)
93                 *addrh = get_erom_ent(sih, eromptr, 0, 0);
94         else
95                 *addrh = 0;
96         *sizeh = 0;
97         sz = asd & AD_SZ_MASK;
98         if (sz == AD_SZ_SZD) {
99                 szd = get_erom_ent(sih, eromptr, 0, 0);
100                 *sizel = szd & SD_SZ_MASK;
101                 if (szd & SD_SG32)
102                         *sizeh = get_erom_ent(sih, eromptr, 0, 0);
103         } else
104                 *sizel = AD_SZ_BASE << (sz >> AD_SZ_SHIFT);
105
106         SI_VMSG(("  SP %d, ad %d: st = %d, 0x%08x_0x%08x @ 0x%08x_0x%08x\n",
107                 sp, ad, st, *sizeh, *sizel, *addrh, *addrl));
108
109         return asd;
110 }
111
112 static void
113 ai_hwfixup(si_info_t *sii)
114 {
115 }
116
117 /* parse the enumeration rom to identify all cores */
118 void
119 ai_scan(si_t *sih, void *regs, uint devid)
120 {
121         si_info_t *sii = SI_INFO(sih);
122         chipcregs_t *cc = (chipcregs_t *)regs;
123         uint32 erombase, *eromptr, *eromlim;
124
125         erombase = R_REG(sii->osh, &cc->eromptr);
126
127         switch (BUSTYPE(sih->bustype)) {
128         case SI_BUS:
129                 eromptr = (uint32 *)REG_MAP(erombase, SI_CORE_SIZE);
130                 break;
131
132         case PCI_BUS:
133                 /* Set wrappers address */
134                 sii->curwrap = (void *)((uintptr)regs + SI_CORE_SIZE);
135
136                 /* Now point the window at the erom */
137                 OSL_PCI_WRITE_CONFIG(sii->osh, PCI_BAR0_WIN, 4, erombase);
138                 eromptr = regs;
139                 break;
140
141         case SPI_BUS:
142         case SDIO_BUS:
143                 eromptr = (uint32 *)(uintptr)erombase;
144                 break;
145
146         case PCMCIA_BUS:
147         default:
148                 SI_ERROR(("Don't know how to do AXI enumertion on bus %d\n", sih->bustype));
149                 ASSERT(0);
150                 return;
151         }
152         eromlim = eromptr + (ER_REMAPCONTROL / sizeof(uint32));
153
154         SI_VMSG(("ai_scan: regs = 0x%p, erombase = 0x%08x, eromptr = 0x%p, eromlim = 0x%p\n",
155                  regs, erombase, eromptr, eromlim));
156         while (eromptr < eromlim) {
157                 uint32 cia, cib, cid, mfg, crev, nmw, nsw, nmp, nsp;
158                 uint32 mpd, asd, addrl, addrh, sizel, sizeh;
159                 uint32 *base;
160                 uint i, j, idx;
161                 bool br;
162
163                 br = FALSE;
164
165                 /* Grok a component */
166                 cia = get_erom_ent(sih, &eromptr, ER_TAG, ER_CI);
167                 if (cia == (ER_END | ER_VALID)) {
168                         SI_VMSG(("Found END of erom after %d cores\n", sii->numcores));
169                         ai_hwfixup(sii);
170                         return;
171                 }
172                 base = eromptr - 1;
173                 cib = get_erom_ent(sih, &eromptr, 0, 0);
174
175                 if ((cib & ER_TAG) != ER_CI) {
176                         SI_ERROR(("CIA not followed by CIB\n"));
177                         goto error;
178                 }
179
180                 cid = (cia & CIA_CID_MASK) >> CIA_CID_SHIFT;
181                 mfg = (cia & CIA_MFG_MASK) >> CIA_MFG_SHIFT;
182                 crev = (cib & CIB_REV_MASK) >> CIB_REV_SHIFT;
183                 nmw = (cib & CIB_NMW_MASK) >> CIB_NMW_SHIFT;
184                 nsw = (cib & CIB_NSW_MASK) >> CIB_NSW_SHIFT;
185                 nmp = (cib & CIB_NMP_MASK) >> CIB_NMP_SHIFT;
186                 nsp = (cib & CIB_NSP_MASK) >> CIB_NSP_SHIFT;
187
188                 SI_VMSG(("Found component 0x%04x/0x%04x rev %d at erom addr 0x%p, with nmw = %d, "
189                          "nsw = %d, nmp = %d & nsp = %d\n",
190                          mfg, cid, crev, base, nmw, nsw, nmp, nsp));
191
192                 if (((mfg == MFGID_ARM) && (cid == DEF_AI_COMP)) || (nsp == 0))
193                         continue;
194                 if ((nmw + nsw == 0)) {
195                         /* A component which is not a core */
196                         if (cid == OOB_ROUTER_CORE_ID) {
197                                 asd = get_asd(sih, &eromptr, 0, 0, AD_ST_SLAVE,
198                                         &addrl, &addrh, &sizel, &sizeh);
199                                 if (asd != 0) {
200                                         sii->oob_router = addrl;
201                                 }
202                         }
203                         continue;
204                 }
205
206                 idx = sii->numcores;
207 /*              sii->eromptr[idx] = base; */
208                 sii->cia[idx] = cia;
209                 sii->cib[idx] = cib;
210                 sii->coreid[idx] = cid;
211
212                 for (i = 0; i < nmp; i++) {
213                         mpd = get_erom_ent(sih, &eromptr, ER_VALID, ER_VALID);
214                         if ((mpd & ER_TAG) != ER_MP) {
215                                 SI_ERROR(("Not enough MP entries for component 0x%x\n", cid));
216                                 goto error;
217                         }
218                         SI_VMSG(("  Master port %d, mp: %d id: %d\n", i,
219                                  (mpd & MPD_MP_MASK) >> MPD_MP_SHIFT,
220                                  (mpd & MPD_MUI_MASK) >> MPD_MUI_SHIFT));
221                 }
222
223                 /* First Slave Address Descriptor should be port 0:
224                  * the main register space for the core
225                  */
226                 asd = get_asd(sih, &eromptr, 0, 0, AD_ST_SLAVE, &addrl, &addrh, &sizel, &sizeh);
227                 if (asd == 0) {
228                         /* Try again to see if it is a bridge */
229                         asd = get_asd(sih, &eromptr, 0, 0, AD_ST_BRIDGE, &addrl, &addrh,
230                                       &sizel, &sizeh);
231                         if (asd != 0)
232                                 br = TRUE;
233                         else
234                                 if ((addrh != 0) || (sizeh != 0) || (sizel != SI_CORE_SIZE)) {
235                                         SI_ERROR(("First Slave ASD for core 0x%04x malformed "
236                                                   "(0x%08x)\n", cid, asd));
237                                         goto error;
238                                 }
239                 }
240                 sii->coresba[idx] = addrl;
241                 sii->coresba_size[idx] = sizel;
242                 /* Get any more ASDs in port 0 */
243                 j = 1;
244                 do {
245                         asd = get_asd(sih, &eromptr, 0, j, AD_ST_SLAVE, &addrl, &addrh,
246                                       &sizel, &sizeh);
247                         if ((asd != 0) && (j == 1) && (sizel == SI_CORE_SIZE)) {
248                                 sii->coresba2[idx] = addrl;
249                                 sii->coresba2_size[idx] = sizel;
250                         }
251                         j++;
252                 } while (asd != 0);
253
254                 /* Go through the ASDs for other slave ports */
255                 for (i = 1; i < nsp; i++) {
256                         j = 0;
257                         do {
258                                 asd = get_asd(sih, &eromptr, i, j++, AD_ST_SLAVE, &addrl, &addrh,
259                                               &sizel, &sizeh);
260                         } while (asd != 0);
261                         if (j == 0) {
262                                 SI_ERROR((" SP %d has no address descriptors\n", i));
263                                 goto error;
264                         }
265                 }
266
267                 /* Now get master wrappers */
268                 for (i = 0; i < nmw; i++) {
269                         asd = get_asd(sih, &eromptr, i, 0, AD_ST_MWRAP, &addrl, &addrh,
270                                       &sizel, &sizeh);
271                         if (asd == 0) {
272                                 SI_ERROR(("Missing descriptor for MW %d\n", i));
273                                 goto error;
274                         }
275                         if ((sizeh != 0) || (sizel != SI_CORE_SIZE)) {
276                                 SI_ERROR(("Master wrapper %d is not 4KB\n", i));
277                                 goto error;
278                         }
279                         if (i == 0)
280                                 sii->wrapba[idx] = addrl;
281                 }
282
283                 /* And finally slave wrappers */
284                 for (i = 0; i < nsw; i++) {
285                         uint fwp = (nsp == 1) ? 0 : 1;
286                         asd = get_asd(sih, &eromptr, fwp + i, 0, AD_ST_SWRAP, &addrl, &addrh,
287                                       &sizel, &sizeh);
288                         if (asd == 0) {
289                                 SI_ERROR(("Missing descriptor for SW %d\n", i));
290                                 goto error;
291                         }
292                         if ((sizeh != 0) || (sizel != SI_CORE_SIZE)) {
293                                 SI_ERROR(("Slave wrapper %d is not 4KB\n", i));
294                                 goto error;
295                         }
296                         if ((nmw == 0) && (i == 0))
297                                 sii->wrapba[idx] = addrl;
298                 }
299
300                 /* Don't record bridges */
301                 if (br)
302                         continue;
303
304                 /* Done with core */
305                 sii->numcores++;
306         }
307
308         SI_ERROR(("Reached end of erom without finding END"));
309
310 error:
311         sii->numcores = 0;
312         return;
313 }
314
315 /* This function changes the logical "focus" to the indicated core.
316  * Return the current core's virtual address.
317  */
318 void *
319 ai_setcoreidx(si_t *sih, uint coreidx)
320 {
321         si_info_t *sii = SI_INFO(sih);
322         uint32 addr = sii->coresba[coreidx];
323         uint32 wrap = sii->wrapba[coreidx];
324         void *regs;
325
326         if (coreidx >= sii->numcores)
327                 return (NULL);
328
329         /*
330          * If the user has provided an interrupt mask enabled function,
331          * then assert interrupts are disabled before switching the core.
332          */
333         ASSERT((sii->intrsenabled_fn == NULL) || !(*(sii)->intrsenabled_fn)((sii)->intr_arg));
334
335         switch (BUSTYPE(sih->bustype)) {
336         case SI_BUS:
337                 /* map new one */
338                 if (!sii->regs[coreidx]) {
339                         sii->regs[coreidx] = REG_MAP(addr, SI_CORE_SIZE);
340                         ASSERT(GOODREGS(sii->regs[coreidx]));
341                 }
342                 sii->curmap = regs = sii->regs[coreidx];
343                 if (!sii->wrappers[coreidx]) {
344                         sii->wrappers[coreidx] = REG_MAP(wrap, SI_CORE_SIZE);
345                         ASSERT(GOODREGS(sii->wrappers[coreidx]));
346                 }
347                 sii->curwrap = sii->wrappers[coreidx];
348                 break;
349
350
351         case SPI_BUS:
352         case SDIO_BUS:
353                 sii->curmap = regs = (void *)((uintptr)addr);
354                 sii->curwrap = (void *)((uintptr)wrap);
355                 break;
356
357         case PCMCIA_BUS:
358         default:
359                 ASSERT(0);
360                 regs = NULL;
361                 break;
362         }
363
364         sii->curmap = regs;
365         sii->curidx = coreidx;
366
367         return regs;
368 }
369
370 /* Return the number of address spaces in current core */
371 int
372 ai_numaddrspaces(si_t *sih)
373 {
374         return 2;
375 }
376
377 /* Return the address of the nth address space in the current core */
378 uint32
379 ai_addrspace(si_t *sih, uint asidx)
380 {
381         si_info_t *sii;
382         uint cidx;
383
384         sii = SI_INFO(sih);
385         cidx = sii->curidx;
386
387         if (asidx == 0)
388                 return sii->coresba[cidx];
389         else if (asidx == 1)
390                 return sii->coresba2[cidx];
391         else {
392                 SI_ERROR(("%s: Need to parse the erom again to find addr space %d\n",
393                           __FUNCTION__, asidx));
394                 return 0;
395         }
396 }
397
398 /* Return the size of the nth address space in the current core */
399 uint32
400 ai_addrspacesize(si_t *sih, uint asidx)
401 {
402         si_info_t *sii;
403         uint cidx;
404
405         sii = SI_INFO(sih);
406         cidx = sii->curidx;
407
408         if (asidx == 0)
409                 return sii->coresba_size[cidx];
410         else if (asidx == 1)
411                 return sii->coresba2_size[cidx];
412         else {
413                 SI_ERROR(("%s: Need to parse the erom again to find addr space %d\n",
414                           __FUNCTION__, asidx));
415                 return 0;
416         }
417 }
418
419 uint
420 ai_flag(si_t *sih)
421 {
422         si_info_t *sii;
423         aidmp_t *ai;
424
425         sii = SI_INFO(sih);
426         if (BCM47162_DMP()) {
427                 SI_ERROR(("%s: Attempting to read MIPS DMP registers on 47162a0", __FUNCTION__));
428                 return sii->curidx;
429         }
430         ai = sii->curwrap;
431
432         return (R_REG(sii->osh, &ai->oobselouta30) & 0x1f);
433 }
434
435 void
436 ai_setint(si_t *sih, int siflag)
437 {
438 }
439
440 uint
441 ai_wrap_reg(si_t *sih, uint32 offset, uint32 mask, uint32 val)
442 {
443         si_info_t *sii = SI_INFO(sih);
444         uint32 *map = (uint32 *) sii->curwrap;
445
446         if (mask || val) {
447                 uint32 w = R_REG(sii->osh, map+(offset/4));
448                 w &= ~mask;
449                 w |= val;
450                 W_REG(sii->osh, map+(offset/4), val);
451         }
452
453         return (R_REG(sii->osh, map+(offset/4)));
454 }
455
456 uint
457 ai_corevendor(si_t *sih)
458 {
459         si_info_t *sii;
460         uint32 cia;
461
462         sii = SI_INFO(sih);
463         cia = sii->cia[sii->curidx];
464         return ((cia & CIA_MFG_MASK) >> CIA_MFG_SHIFT);
465 }
466
467 uint
468 ai_corerev(si_t *sih)
469 {
470         si_info_t *sii;
471         uint32 cib;
472
473         sii = SI_INFO(sih);
474         cib = sii->cib[sii->curidx];
475         return ((cib & CIB_REV_MASK) >> CIB_REV_SHIFT);
476 }
477
478 bool
479 ai_iscoreup(si_t *sih)
480 {
481         si_info_t *sii;
482         aidmp_t *ai;
483
484         sii = SI_INFO(sih);
485         ai = sii->curwrap;
486
487         return (((R_REG(sii->osh, &ai->ioctrl) & (SICF_FGC | SICF_CLOCK_EN)) == SICF_CLOCK_EN) &&
488                 ((R_REG(sii->osh, &ai->resetctrl) & AIRC_RESET) == 0));
489 }
490
491 /*
492  * Switch to 'coreidx', issue a single arbitrary 32bit register mask&set operation,
493  * switch back to the original core, and return the new value.
494  *
495  * When using the silicon backplane, no fiddling with interrupts or core switches is needed.
496  *
497  * Also, when using pci/pcie, we can optimize away the core switching for pci registers
498  * and (on newer pci cores) chipcommon registers.
499  */
500 uint
501 ai_corereg(si_t *sih, uint coreidx, uint regoff, uint mask, uint val)
502 {
503         uint origidx = 0;
504         uint32 *r = NULL;
505         uint w;
506         uint intr_val = 0;
507         bool fast = FALSE;
508         si_info_t *sii;
509
510         sii = SI_INFO(sih);
511
512         ASSERT(GOODIDX(coreidx));
513         ASSERT(regoff < SI_CORE_SIZE);
514         ASSERT((val & ~mask) == 0);
515
516         if (coreidx >= SI_MAXCORES)
517                 return 0;
518
519         if (BUSTYPE(sih->bustype) == SI_BUS) {
520                 /* If internal bus, we can always get at everything */
521                 fast = TRUE;
522                 /* map if does not exist */
523                 if (!sii->regs[coreidx]) {
524                         sii->regs[coreidx] = REG_MAP(sii->coresba[coreidx],
525                                                     SI_CORE_SIZE);
526                         ASSERT(GOODREGS(sii->regs[coreidx]));
527                 }
528                 r = (uint32 *)((uchar *)sii->regs[coreidx] + regoff);
529         } else if (BUSTYPE(sih->bustype) == PCI_BUS) {
530                 /* If pci/pcie, we can get at pci/pcie regs and on newer cores to chipc */
531
532                 if ((sii->coreid[coreidx] == CC_CORE_ID) && SI_FAST(sii)) {
533                         /* Chipc registers are mapped at 12KB */
534
535                         fast = TRUE;
536                         r = (uint32 *)((char *)sii->curmap + PCI_16KB0_CCREGS_OFFSET + regoff);
537                 } else if (sii->pub.buscoreidx == coreidx) {
538                         /* pci registers are at either in the last 2KB of an 8KB window
539                          * or, in pcie and pci rev 13 at 8KB
540                          */
541                         fast = TRUE;
542                         if (SI_FAST(sii))
543                                 r = (uint32 *)((char *)sii->curmap +
544                                                PCI_16KB0_PCIREGS_OFFSET + regoff);
545                         else
546                                 r = (uint32 *)((char *)sii->curmap +
547                                                ((regoff >= SBCONFIGOFF) ?
548                                                 PCI_BAR0_PCISBR_OFFSET : PCI_BAR0_PCIREGS_OFFSET) +
549                                                regoff);
550                 }
551         }
552
553         if (!fast) {
554                 INTR_OFF(sii, intr_val);
555
556                 /* save current core index */
557                 origidx = si_coreidx(&sii->pub);
558
559                 /* switch core */
560                 r = (uint32*) ((uchar*) ai_setcoreidx(&sii->pub, coreidx) + regoff);
561         }
562         ASSERT(r != NULL);
563
564         /* mask and set */
565         if (mask || val) {
566                 w = (R_REG(sii->osh, r) & ~mask) | val;
567                 W_REG(sii->osh, r, w);
568         }
569
570         /* readback */
571         w = R_REG(sii->osh, r);
572
573         if (!fast) {
574                 /* restore core index */
575                 if (origidx != coreidx)
576                         ai_setcoreidx(&sii->pub, origidx);
577
578                 INTR_RESTORE(sii, intr_val);
579         }
580
581         return (w);
582 }
583
584 void
585 ai_core_disable(si_t *sih, uint32 bits)
586 {
587         si_info_t *sii;
588         volatile uint32 dummy;
589         aidmp_t *ai;
590
591         sii = SI_INFO(sih);
592
593         ASSERT(GOODREGS(sii->curwrap));
594         ai = sii->curwrap;
595
596         /* if core is already in reset, just return */
597         if (R_REG(sii->osh, &ai->resetctrl) & AIRC_RESET)
598                 return;
599
600         W_REG(sii->osh, &ai->ioctrl, bits);
601         dummy = R_REG(sii->osh, &ai->ioctrl);
602         OSL_DELAY(10);
603
604         W_REG(sii->osh, &ai->resetctrl, AIRC_RESET);
605         OSL_DELAY(1);
606 }
607
608 /* reset and re-enable a core
609  * inputs:
610  * bits - core specific bits that are set during and after reset sequence
611  * resetbits - core specific bits that are set only during reset sequence
612  */
613 void
614 ai_core_reset(si_t *sih, uint32 bits, uint32 resetbits)
615 {
616         si_info_t *sii;
617         aidmp_t *ai;
618         volatile uint32 dummy;
619
620         sii = SI_INFO(sih);
621         ASSERT(GOODREGS(sii->curwrap));
622         ai = sii->curwrap;
623
624         /*
625          * Must do the disable sequence first to work for arbitrary current core state.
626          */
627         ai_core_disable(sih, (bits | resetbits));
628
629         /*
630          * Now do the initialization sequence.
631          */
632         W_REG(sii->osh, &ai->ioctrl, (bits | SICF_FGC | SICF_CLOCK_EN));
633         dummy = R_REG(sii->osh, &ai->ioctrl);
634         W_REG(sii->osh, &ai->resetctrl, 0);
635         OSL_DELAY(1);
636
637         W_REG(sii->osh, &ai->ioctrl, (bits | SICF_CLOCK_EN));
638         dummy = R_REG(sii->osh, &ai->ioctrl);
639         OSL_DELAY(1);
640 }
641
642
643 void
644 ai_core_cflags_wo(si_t *sih, uint32 mask, uint32 val)
645 {
646         si_info_t *sii;
647         aidmp_t *ai;
648         uint32 w;
649
650         sii = SI_INFO(sih);
651
652         if (BCM47162_DMP()) {
653                 SI_ERROR(("%s: Accessing MIPS DMP register (ioctrl) on 47162a0",
654                           __FUNCTION__));
655                 return;
656         }
657
658         ASSERT(GOODREGS(sii->curwrap));
659         ai = sii->curwrap;
660
661         ASSERT((val & ~mask) == 0);
662
663         if (mask || val) {
664                 w = ((R_REG(sii->osh, &ai->ioctrl) & ~mask) | val);
665                 W_REG(sii->osh, &ai->ioctrl, w);
666         }
667 }
668
669 uint32
670 ai_core_cflags(si_t *sih, uint32 mask, uint32 val)
671 {
672         si_info_t *sii;
673         aidmp_t *ai;
674         uint32 w;
675
676         sii = SI_INFO(sih);
677         if (BCM47162_DMP()) {
678                 SI_ERROR(("%s: Accessing MIPS DMP register (ioctrl) on 47162a0",
679                           __FUNCTION__));
680                 return 0;
681         }
682
683         ASSERT(GOODREGS(sii->curwrap));
684         ai = sii->curwrap;
685
686         ASSERT((val & ~mask) == 0);
687
688         if (mask || val) {
689                 w = ((R_REG(sii->osh, &ai->ioctrl) & ~mask) | val);
690                 W_REG(sii->osh, &ai->ioctrl, w);
691         }
692
693         return R_REG(sii->osh, &ai->ioctrl);
694 }
695
696 uint32
697 ai_core_sflags(si_t *sih, uint32 mask, uint32 val)
698 {
699         si_info_t *sii;
700         aidmp_t *ai;
701         uint32 w;
702
703         sii = SI_INFO(sih);
704         if (BCM47162_DMP()) {
705                 SI_ERROR(("%s: Accessing MIPS DMP register (iostatus) on 47162a0",
706                           __FUNCTION__));
707                 return 0;
708         }
709
710         ASSERT(GOODREGS(sii->curwrap));
711         ai = sii->curwrap;
712
713         ASSERT((val & ~mask) == 0);
714         ASSERT((mask & ~SISF_CORE_BITS) == 0);
715
716         if (mask || val) {
717                 w = ((R_REG(sii->osh, &ai->iostatus) & ~mask) | val);
718                 W_REG(sii->osh, &ai->iostatus, w);
719         }
720
721         return R_REG(sii->osh, &ai->iostatus);
722 }