[BACK]Return to cachectl.c CVS log [TXT][DIR] Up to [local] / sys / arch / m68k / m68k

Annotation of sys/arch/m68k/m68k/cachectl.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: cachectl.c,v 1.1 2005/08/01 11:54:24 miod Exp $       */
                      2: /*     $NetBSD: sys_machdep.c,v 1.17 1997/05/19 10:15:00 veego Exp $   */
                      3:
                      4: /*
                      5:  * Copyright (c) 1982, 1986, 1993
                      6:  *     The Regents of the University of California.  All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  * 3. Neither the name of the University nor the names of its contributors
                     17:  *    may be used to endorse or promote products derived from this software
                     18:  *    without specific prior written permission.
                     19:  *
                     20:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     21:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     22:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     23:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     24:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     25:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     26:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     27:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     28:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     29:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     30:  * SUCH DAMAGE.
                     31:  *
                     32:  *     @(#)sys_machdep.c       8.2 (Berkeley) 1/13/94
                     33:  */
                     34:
                     35: #include <sys/param.h>
                     36: #include <sys/systm.h>
                     37: #include <sys/proc.h>
                     38: #include <sys/kernel.h>
                     39:
                     40: #include <machine/cpu.h>
                     41:
                     42: #include <uvm/uvm_extern.h>
                     43:
                     44: /*
                     45:  * Note that what we do here for a 68040 is different than HP-UX.
                     46:  *
                     47:  * In HP-UX they either act on a line (len == 16), a page (len == NBPG)
                     48:  * or the whole cache (len == anything else).
                     49:  *
                     50:  * In BSD we attempt to be more optimal when acting on "odd" sizes.
                     51:  * For lengths up to 1024 we do all affected lines, up to 2 * NBPG we
                     52:  * do pages, above that we do the entire cache.
                     53:  */
                     54: /*ARGSUSED1*/
                     55: int
                     56: cachectl(struct proc *p, int req, vaddr_t addr, int len)
                     57: {
                     58:        int error = 0;
                     59:
                     60: #if defined(M68040) || defined(M68060)
                     61:        if (mmutype <= MMU_68040) {
                     62:                int inc = 0;
                     63:                int doall = 0;
                     64:                paddr_t pa = 0;
                     65:                vaddr_t end = 0;
                     66: #ifdef COMPAT_HPUX
                     67:                extern struct emul emul_hpux;
                     68:
                     69:                if ((p->p_emul == &emul_hpux) &&
                     70:                    len != 16 && len != NBPG)
                     71:                        doall = 1;
                     72: #endif
                     73:
                     74:                if (addr == 0 ||
                     75:                    ((req & ~CC_EXTPURGE) != CC_PURGE && len > 2*NBPG))
                     76:                        doall = 1;
                     77:
                     78:                if (!doall) {
                     79:                        end = addr + len;
                     80:                        if (len <= 1024) {
                     81:                                addr = addr & ~0xF;
                     82:                                inc = 16;
                     83:                        } else {
                     84:                                addr = addr & ~PGOFSET;
                     85:                                inc = NBPG;
                     86:                        }
                     87:                }
                     88:                do {
                     89:                        /*
                     90:                         * Convert to physical address if needed.
                     91:                         * If translation fails, we perform operation on
                     92:                         * entire cache (XXX is this a rational thing to do?)
                     93:                         */
                     94:                        if (!doall &&
                     95:                            (pa == 0 || ((int)addr & PGOFSET) == 0)) {
                     96:                                if (pmap_extract(
                     97:                                    p->p_vmspace->vm_map.pmap,
                     98:                                    addr, &pa) == FALSE)
                     99:                                        doall = 1;
                    100:                        }
                    101:                        switch (req) {
                    102:                        case CC_EXTPURGE|CC_IPURGE:
                    103:                        case CC_IPURGE:
                    104:                                if (doall) {
                    105:                                        DCFA();
                    106:                                        ICPA();
                    107:                                } else if (inc == 16) {
                    108:                                        DCFL(pa);
                    109:                                        ICPL(pa);
                    110:                                } else if (inc == NBPG) {
                    111:                                        DCFP(pa);
                    112:                                        ICPP(pa);
                    113:                                }
                    114:                                break;
                    115:
                    116:                        case CC_EXTPURGE|CC_PURGE:
                    117:                        case CC_PURGE:
                    118:                                if (doall)
                    119:                                        DCFA(); /* note: flush not purge */
                    120:                                else if (inc == 16)
                    121:                                        DCPL(pa);
                    122:                                else if (inc == NBPG)
                    123:                                        DCPP(pa);
                    124:                                break;
                    125:
                    126:                        case CC_EXTPURGE|CC_FLUSH:
                    127:                        case CC_FLUSH:
                    128:                                if (doall)
                    129:                                        DCFA();
                    130:                                else if (inc == 16)
                    131:                                        DCFL(pa);
                    132:                                else if (inc == NBPG)
                    133:                                        DCFP(pa);
                    134:                                break;
                    135:
                    136:                        default:
                    137:                                error = EINVAL;
                    138:                                break;
                    139:                        }
                    140:                        if (doall)
                    141:                                break;
                    142:                        pa += inc;
                    143:                        addr += inc;
                    144:                } while (addr < end);
                    145:                return (error);
                    146:        }
                    147: #endif
                    148:        switch (req) {
                    149:        case CC_EXTPURGE|CC_PURGE:
                    150:        case CC_EXTPURGE|CC_FLUSH:
                    151: #if defined(CACHE_HAVE_PAC)
                    152:                if (ectype == EC_PHYS)
                    153:                        PCIA();
                    154:                /* FALLTHROUGH */
                    155: #endif
                    156:        case CC_PURGE:
                    157:        case CC_FLUSH:
                    158:                DCIU();
                    159:                break;
                    160:        case CC_EXTPURGE|CC_IPURGE:
                    161: #if defined(CACHE_HAVE_PAC)
                    162:                if (ectype == EC_PHYS)
                    163:                        PCIA();
                    164:                else
                    165: #endif
                    166:                DCIU();
                    167:                /* FALLTHROUGH */
                    168:        case CC_IPURGE:
                    169:                ICIA();
                    170:                break;
                    171:        default:
                    172:                error = EINVAL;
                    173:                break;
                    174:        }
                    175:        return (error);
                    176: }

CVSweb