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

Annotation of sys/arch/macppc/macppc/mem.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: mem.c,v 1.13 2005/12/17 07:31:26 miod Exp $   */
                      2: /*     $NetBSD: mem.c,v 1.1 1996/09/30 16:34:50 ws Exp $ */
                      3:
                      4: /*
                      5:  * Copyright (c) 1988 University of Utah.
                      6:  * Copyright (c) 1982, 1986, 1990, 1993
                      7:  *     The Regents of the University of California.  All rights reserved.
                      8:  *
                      9:  * This code is derived from software contributed to Berkeley by
                     10:  * the Systems Programming Group of the University of Utah Computer
                     11:  * Science Department.
                     12:  *
                     13:  * Redistribution and use in source and binary forms, with or without
                     14:  * modification, are permitted provided that the following conditions
                     15:  * are met:
                     16:  * 1. Redistributions of source code must retain the above copyright
                     17:  *    notice, this list of conditions and the following disclaimer.
                     18:  * 2. Redistributions in binary form must reproduce the above copyright
                     19:  *    notice, this list of conditions and the following disclaimer in the
                     20:  *    documentation and/or other materials provided with the distribution.
                     21:  * 3. Neither the name of the University nor the names of its contributors
                     22:  *    may be used to endorse or promote products derived from this software
                     23:  *    without specific prior written permission.
                     24:  *
                     25:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     26:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     27:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     28:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     29:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     30:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     31:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     32:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     33:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     34:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     35:  * SUCH DAMAGE.
                     36:  *
                     37:  *     @(#)mem.c       8.3 (Berkeley) 1/12/94
                     38:  */
                     39:
                     40: /*
                     41:  * Memory special file
                     42:  */
                     43:
                     44: #include <sys/param.h>
                     45: #include <sys/buf.h>
                     46: #include <sys/systm.h>
                     47: #include <sys/ioccom.h>
                     48: #include <sys/uio.h>
                     49: #include <sys/malloc.h>
                     50: #include <sys/types.h>
                     51:
                     52: #include <machine/cpu.h>
                     53:
                     54: #include <uvm/uvm_extern.h>
                     55:
                     56: #include <machine/conf.h>
                     57:
                     58: /* open counter for aperture */
                     59: #ifdef APERTURE
                     60: static int ap_open_count = 0;
                     61: extern int allowaperture;
                     62: #endif
                     63:
                     64: /*ARGSUSED*/
                     65: int
                     66: mmopen(dev_t dev, int flag, int mode, struct proc *p)
                     67: {
                     68:
                     69:        switch (minor(dev)) {
                     70:                case 0:
                     71:                case 1:
                     72:                case 2:
                     73:                case 12:
                     74:                        break;
                     75: #ifdef APERTURE
                     76:        case 4:
                     77:                if (suser(p, 0) != 0 || !allowaperture)
                     78:                        return (EPERM);
                     79:
                     80:                /* authorize only one simultaneous open() */
                     81:                if (ap_open_count > 0)
                     82:                        return(EPERM);
                     83:                ap_open_count++;
                     84:                break;
                     85: #endif
                     86:                default:
                     87:                        return (ENXIO);
                     88:        }
                     89:        return (0);
                     90: }
                     91:
                     92: /*ARGSUSED*/
                     93: int
                     94: mmclose(dev_t dev, int flag, int mode, struct proc *p)
                     95: {
                     96: #ifdef APERTURE
                     97:        if (minor(dev) == 4)
                     98:                ap_open_count--;
                     99: #endif
                    100:        return 0;
                    101: }
                    102:
                    103: /*ARGSUSED*/
                    104: int
                    105: mmrw(dev_t dev, struct uio *uio, int flags)
                    106: {
                    107:        vaddr_t v;
                    108:        vsize_t c;
                    109:        struct iovec *iov;
                    110:        int error = 0;
                    111:        static caddr_t zeropage;
                    112:
                    113:        while (uio->uio_resid > 0 && error == 0) {
                    114:                iov = uio->uio_iov;
                    115:                if (iov->iov_len == 0) {
                    116:                        uio->uio_iov++;
                    117:                        uio->uio_iovcnt--;
                    118:                        if (uio->uio_iovcnt < 0)
                    119:                                panic("mmrw");
                    120:                        continue;
                    121:                }
                    122:                switch (minor(dev)) {
                    123:
                    124:                /* minor device 0 is physical memory */
                    125:                case 0:
                    126:                        v = uio->uio_offset;
                    127:                        c = uio->uio_resid;
                    128:                        /* This doesn't allow device mapping!   XXX */
                    129:                        pmap_real_memory(&v, &c);
                    130:                        error = uiomove((caddr_t)v, c, uio);
                    131:                        continue;
                    132:
                    133:                /* minor device 1 is kernel memory */
                    134:                case 1:
                    135:                        v = uio->uio_offset;
                    136:                        c = min(iov->iov_len, MAXPHYS);
                    137:                        error = uiomove((caddr_t)v, c, uio);
                    138:                        continue;
                    139:
                    140:                /* minor device 2 is EOF/RATHOLE */
                    141:                case 2:
                    142:                        if (uio->uio_rw == UIO_WRITE)
                    143:                                uio->uio_resid = 0;
                    144:                        return 0;
                    145:
                    146:                /* minor device 12 (/dev/zero) is source of nulls on read,
                    147:                 * rathole on write
                    148:                 */
                    149:                case 12:
                    150:                        if (uio->uio_rw == UIO_WRITE) {
                    151:                                c = iov->iov_len;
                    152:                                break;
                    153:                        }
                    154:                        if (zeropage == NULL) {
                    155:                                zeropage = (caddr_t)malloc(PAGE_SIZE, M_TEMP,
                    156:                                    M_WAITOK);
                    157:                                bzero(zeropage, PAGE_SIZE);
                    158:                        }
                    159:                        c = min(iov->iov_len, PAGE_SIZE);
                    160:                        error = uiomove(zeropage, c, uio);
                    161:                        continue;
                    162:
                    163:                default:
                    164:                        return ENXIO;
                    165:                }
                    166:                if (error)
                    167:                        break;
                    168:                iov->iov_base += c;
                    169:                iov->iov_len -= c;
                    170:                uio->uio_offset += c;
                    171:                uio->uio_resid -= c;
                    172:        }
                    173:        return error;
                    174: }
                    175:
                    176: paddr_t
                    177: mmmmap(dev_t dev, off_t off, int prot)
                    178: {
                    179:        return (-1);
                    180: }
                    181:
                    182: /*ARGSUSED*/
                    183: int
                    184: mmioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
                    185: {
                    186:        return (EOPNOTSUPP);
                    187: }

CVSweb