Annotation of kernel/vm/pmap.h, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
                      7:  * Reserved.  This file contains Original Code and/or Modifications of
                      8:  * Original Code as defined in and that are subject to the Apple Public
                      9:  * Source License Version 1.1 (the "License").  You may not use this file
                     10:  * except in compliance with the License.  Please obtain a copy of the
                     11:  * License at http://www.apple.com/publicsource and read it before using
                     12:  * this file.
                     13:  * 
                     14:  * The Original Code and all software distributed under the License are
                     15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
                     19:  * License for the specific language governing rights and limitations
                     20:  * under the License.
                     21:  * 
                     22:  * @APPLE_LICENSE_HEADER_END@
                     23:  */
                     24: 
                     25: /* 
                     26:  * Mach Operating System
                     27:  * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
                     28:  * All Rights Reserved.
                     29:  * 
                     30:  * Permission to use, copy, modify and distribute this software and its
                     31:  * documentation is hereby granted, provided that both the copyright
                     32:  * notice and this permission notice appear in all copies of the
                     33:  * software, derivative works or modified versions, and any portions
                     34:  * thereof, and that both notices appear in supporting documentation.
                     35:  * 
                     36:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
                     37:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
                     38:  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
                     39:  * 
                     40:  * Carnegie Mellon requests users of this software to return to
                     41:  * 
                     42:  *  Software Distribution Coordinator  or  [email protected]
                     43:  *  School of Computer Science
                     44:  *  Carnegie Mellon University
                     45:  *  Pittsburgh PA 15213-3890
                     46:  * 
                     47:  * any improvements or extensions that they make and grant Carnegie Mellon
                     48:  * the rights to redistribute these changes.
                     49:  */
                     50: /*
                     51:  * HISTORY
                     52:  * Revision 1.1.1.1  1997/09/30 02:45:35  wsanchez
                     53:  * Import of kernel from umeshv/kernel
                     54:  *
                     55:  * 
                     56:  * Revision ?.?  97/07/17  14:39:51  umeshv
                     57:  *     Fixed multipe definition of kernel_pmap.
                     58:  * 
                     59:  * Revision 2.6  91/05/18  14:39:51  rpd
                     60:  *     Removed pmap_update.
                     61:  *     [91/04/12            rpd]
                     62:  *     Removed pmap_bootstrap, pmap_map, pmap_valid_page.
                     63:  *     Added pmap_startup, pmap_steal_memory, pmap_free_pages,
                     64:  *     pmap_virtual_space, pmap_next_page.
                     65:  *     [91/03/22            rpd]
                     66:  * 
                     67:  * Revision 2.5  91/05/14  17:48:08  mrt
                     68:  *     Correcting copyright
                     69:  * 
                     70:  * Revision 2.4  91/02/05  17:57:34  mrt
                     71:  *     Changed to new Mach copyright
                     72:  *     [91/02/01  16:31:04  mrt]
                     73:  * 
                     74:  * Revision 2.3  90/01/22  23:09:05  af
                     75:  *     Added (optional) pmap_attributes.  This should be implemented
                     76:  *     just as a macro that evaluates to KERN_INVALID_ARGUMENT for
                     77:  *     those architectures that do not support any special memory
                     78:  *     feature in hardware.  NUMA machines and cache-incoherent
                     79:  *     machines (e.g. mips) should instead implement it as appropriate.
                     80:  *     [89/12/08            af]
                     81:  * 
                     82:  * Revision 2.2  89/11/29  14:16:53  af
                     83:  *     Carried over the following mods from impure kernel.
                     84:  *             Added pmap_phys_to_frame as inverse of pmap_phys_address, for use by
                     85:  *             memory map function in machine-independent pseudo device drivers.
                     86:  *             The correct thing to do, of course, is to change the device driver map
                     87:  *             function spec to return a physical address instead of a frame, but
                     88:  *             this would require changing too many device drivers...
                     89:  *             [89/09/05  16:45:48  jsb]
                     90:  * 
                     91:  *             Removed unused and ugly pmap_redzone() from the list of required
                     92:  *             pmap functions.  Made more routines implementable as macros.
                     93:  *             [89/08/05            af]
                     94:  *     Separate user and kernel cases of PMAP_ACTIVATE and
                     95:  *     PMAP_DEACTIVATE; supply default definitions.
                     96:  *     [89/04/28            dbg]
                     97:  * 
                     98:  * Revision 2.1  89/08/03  16:44:35  rwd
                     99:  * Created.
                    100:  * 
                    101:  * Revision 2.8  89/04/18  21:24:43  mwyoung
                    102:  *     Recent history [mwyoung]:
                    103:  *             Remove pmap_remove_all(), pmap_copy_on_write(), as they're
                    104:  *              no longer required routines.  The machine-independent code
                    105:  *              uses pmap_page_protect() instead.
                    106:  *             Documented interface.  The precise interface specification
                    107:  *              should be reconstructed from the pmap implementations.
                    108:  *     History condensation:
                    109:  *             Added calls for page locking [mwyoung].
                    110:  *             Added reference bit handling [avie].
                    111:  *             Created [avie].
                    112:  *     [89/04/18            mwyoung]
                    113:  * 
                    114:  */
                    115: /*
                    116:  *     File:   vm/pmap.h
                    117:  *     Author: Avadis Tevanian, Jr.
                    118:  *     Date:   1985
                    119:  *
                    120:  *     Machine address mapping definitions -- machine-independent
                    121:  *     section.  [For machine-dependent section, see "machine/pmap.h".]
                    122:  */
                    123: 
                    124: #ifndef        _VM_PMAP_H_
                    125: #define _VM_PMAP_H_
                    126: 
                    127: #import <mach/features.h>
                    128: 
                    129: #include <machdep/machine/pmap.h>
                    130: #include <mach/machine/vm_types.h>
                    131: #include <mach/boolean.h>
                    132: 
                    133: #if    OLD_VM_CODE
                    134: void           pmap_bootstrap();
                    135: void           pmap_init();
                    136: vm_offset_t    pmap_map();
                    137: pmap_t         pmap_create();
                    138: #ifdef pmap_kernel
                    139: extern
                    140: #endif
                    141: pmap_t         pmap_kernel();
                    142: void           pmap_destroy();
                    143: void           pmap_reference();
                    144: void           pmap_remove();
                    145: void           pmap_remove_all();
                    146: void           pmap_copy_on_write();
                    147: void           pmap_protect();
                    148: void           pmap_enter();
                    149: vm_offset_t    pmap_extract();
                    150: void           pmap_update();
                    151: void           pmap_collect();
                    152: void           pmap_activate();
                    153: void           pmap_deactivate();
                    154: #if !defined(ppc)
                    155: void           pmap_copy();
                    156: #endif
                    157: void           pmap_statistics();
                    158: void           pmap_clear_reference();
                    159: boolean_t      pmap_is_referenced();
                    160: void           pmap_change_wiring();
                    161: void           pmap_clear_modify();
                    162: void           pmap_page_protect();
                    163: 
                    164: void           pmap_redzone();
                    165: boolean_t      pmap_access();
                    166: 
                    167: typedef struct mem_region {
                    168:        struct vm_page  *vm_page_array; /* First resident page in table */
                    169:        unsigned        first_page;     /* first physical page number */
                    170:                                        /* ... represented in vm_page_array */
                    171:        unsigned        last_page;      /* last physical page number + 1 */
                    172:                                        /* ... represented in vm_page_array */
                    173:                                        /* [INCLUSIVE] */
                    174:        unsigned        num_pages;      /* last_page - first_page */
                    175:        vm_offset_t     base_phys_addr; /* fixed base of region for dump() */
                    176:        vm_offset_t     first_phys_addr;/* physical address for first_page */
                    177:        vm_offset_t     last_phys_addr; /* physical address for last_page */
                    178: } *mem_region_t;
                    179: 
                    180: /*
                    181:  * Machine dependent code must initialize the mem_region table before
                    182:  * calling any machine independent code.
                    183:  *
                    184:  * Machine dependent code should initialize the following fields of
                    185:  * mem_region:
                    186:  *     base_phys_addr --       first physical address of the contiguous
                    187:  *                             memory region
                    188:  *     first_phys_addr --      same as base_phys_addr
                    189:  *     last_phys_addr --       last_phys_addr + 1 of the contiguous
                    190:  *                             memory region
                    191:  *
                    192:  * Currently, machine independent code assumes (bogusly) that it can
                    193:  * allocate 1-1 mapped kernel data from mem_regions.
                    194:  * FIXME: Undo this.  It's not portable.
                    195:  * 
                    196:  * After all 1-1 allocations are complete, MI code (vm_resident) then
                    197:  * goes and allocates vm_page_t's for the remaining memory in the
                    198:  * mem_region table, and sets or modifies the following values in the
                    199:  * mem_region table:
                    200:  *
                    201:  *     vm_page_array --        points to the allocated vm_page_t's
                    202:  *                             for the physical page frame of this region
                    203:  *     first_page --           phys page num of first page in vm_page_array
                    204:  *     last_page --            phys page num + 1 of last page in vm_page_array
                    205:  *     num_pages --            number of page frames in this mem region
                    206:  *     first_phys_addr --      address corresponding to first_page
                    207:  *     last_phys_ddr --        address corresponding to last_page
                    208:  */
                    209: extern         struct mem_region mem_region[];
                    210: extern int     num_regions;
                    211: 
                    212: /* convert a pa to an ordinal of the physical page frames */
                    213: extern unsigned vm_ppi(vm_offset_t pa);
                    214: /* returns true if p refers to a page frame */
                    215: extern boolean_t vm_valid_page(vm_offset_t p);
                    216: /* translates physical address to vm_page pointer */
                    217: extern struct vm_page *vm_phys_to_vm_page(vm_offset_t pa);
                    218: /* allocates memory from the mem regions */
                    219: extern vm_offset_t vm_alloc_from_region(vm_size_t size, vm_size_t align);
                    220: #else
                    221: /*
                    222:  *     The following is a description of the interface to the
                    223:  *     machine-dependent "physical map" data structure.  The module
                    224:  *     must provide a "pmap_t" data type that represents the
                    225:  *     set of valid virtual-to-physical addresses for one user
                    226:  *     address space.  [The kernel address space is represented
                    227:  *     by a distinguished "pmap_t".]  The routines described manage
                    228:  *     this type, install and update virtual-to-physical mappings,
                    229:  *     and perform operations on physical addresses common to
                    230:  *     many address spaces.
                    231:  */
                    232: 
                    233: /*
                    234:  *     Routines used for initialization.
                    235:  *     There is traditionally also a pmap_bootstrap,
                    236:  *     used very early by machine-dependent code,
                    237:  *     but it is not part of the interface.
                    238:  */
                    239: 
                    240: extern vm_offset_t     pmap_steal_memory();    /* During VM initialization,
                    241:                                                 * steal a chunk of memory.
                    242:                                                 */
                    243: extern unsigned int    pmap_free_pages();      /* During VM initialization,
                    244:                                                 * report remaining unused
                    245:                                                 * physical pages.
                    246:                                                 */
                    247: extern void            pmap_startup();         /* During VM initialization,
                    248:                                                 * use remaining physical pages
                    249:                                                 * to allocate page frames.
                    250:                                                 */
                    251: extern void            pmap_init();            /* Initialization,
                    252:                                                 * after kernel runs
                    253:                                                 * in virtual memory.
                    254:                                                 */
                    255: 
                    256: #ifndef        MACHINE_PAGES
                    257: /*
                    258:  *     If machine/pmap.h defines MACHINE_PAGES, it must implement
                    259:  *     the above functions.  The pmap module has complete control.
                    260:  *     Otherwise, it must implement
                    261:  *             pmap_free_pages
                    262:  *             pmap_virtual_space
                    263:  *             pmap_next_page
                    264:  *             pmap_init
                    265:  *     and vm/vm_resident.c implements pmap_steal_memory and pmap_startup
                    266:  *     using pmap_free_pages, pmap_next_page, pmap_virtual_space,
                    267:  *     and pmap_enter.  pmap_free_pages may over-estimate the number
                    268:  *     of unused physical pages, and pmap_next_page may return FALSE
                    269:  *     to indicate that there are no more unused pages to return.
                    270:  *     However, for best performance pmap_free_pages should be accurate.
                    271:  */
                    272: 
                    273: extern boolean_t       pmap_next_page();       /* During VM initialization,
                    274:                                                 * return the next unused
                    275:                                                 * physical page.
                    276:                                                 */
                    277: extern void            pmap_virtual_space();   /* During VM initialization,
                    278:                                                 * report virtual space
                    279:                                                 * available for the kernel.
                    280:                                                 */
                    281: #endif /* MACHINE_PAGES */
                    282: 
                    283: /*
                    284:  *     Routines to manage the physical map data structure.
                    285:  */
                    286: extern pmap_t          pmap_create();          /* Create a pmap_t. */
                    287: #ifndef pmap_kernel
                    288: extern pmap_t          pmap_kernel();          /* Return the kernel's pmap_t. */
                    289: #endif /* pmap_kernel */
                    290: extern void            pmap_reference();       /* Gain a reference. */
                    291: extern void            pmap_destroy();         /* Release a reference. */
                    292: 
                    293: extern void            pmap_enter();           /* Enter a mapping */
                    294: 
                    295: /*
                    296:  *     Routines that operate on ranges of virtual addresses.
                    297:  */
                    298: extern void            pmap_remove();          /* Remove mappings. */
                    299: extern void            pmap_protect();         /* Change protections. */
                    300: 
                    301: /*
                    302:  *     Routines to set up hardware state for physical maps to be used.
                    303:  */
                    304: extern void            pmap_activate();        /* Prepare pmap_t to run
                    305:                                                 * on a given processor.
                    306:                                                 */
                    307: extern void            pmap_deactivate();      /* Release pmap_t from
                    308:                                                 * use on processor.
                    309:                                                 */
                    310: 
                    311: 
                    312: /*
                    313:  *     Routines that operate on physical addresses.
                    314:  */
                    315: extern void            pmap_page_protect();    /* Restrict access to page. */
                    316: 
                    317: /*
                    318:  *     Routines to manage reference/modify bits based on
                    319:  *     physical addresses, simulating them if not provided
                    320:  *     by the hardware.
                    321:  */
                    322: extern void            pmap_clear_reference(); /* Clear reference bit */
                    323: #ifndef pmap_is_referenced
                    324: extern boolean_t       pmap_is_referenced();   /* Return reference bit */
                    325: #endif /* pmap_is_referenced */
                    326: extern void            pmap_clear_modify();    /* Clear modify bit */
                    327: extern boolean_t       pmap_is_modified();     /* Return modify bit */
                    328: 
                    329: 
                    330: /*
                    331:  *     Statistics routines
                    332:  */
                    333: extern void            pmap_statistics();      /* Return statistics */
                    334: 
                    335: #ifndef        pmap_resident_count
                    336: extern int             pmap_resident_count();
                    337: #endif /* pmap_resident_count */
                    338: 
                    339: /*
                    340:  *     Sundry required routines
                    341:  */
                    342: extern vm_offset_t     pmap_extract();         /* Return a virtual-to-physical
                    343:                                                 * mapping, if possible.
                    344:                                                 */
                    345: 
                    346: extern boolean_t       pmap_access();          /* Is virtual address valid? */
                    347: 
                    348: extern void            pmap_collect();         /* Perform garbage
                    349:                                                 * collection, if any
                    350:                                                 */
                    351: 
                    352: extern void            pmap_change_wiring();   /* Specify pageability */
                    353: 
                    354: #ifndef        pmap_phys_address
                    355: extern vm_offset_t     pmap_phys_address();    /* Transform address
                    356:                                                 * returned by device
                    357:                                                 * driver mapping function
                    358:                                                 * to physical address
                    359:                                                 * known to this module.
                    360:                                                 */
                    361: #endif /* pmap_phys_address */
                    362: #ifndef        pmap_phys_to_frame
                    363: extern int             pmap_phys_to_frame();   /* Inverse of
                    364:                                                 * pmap_phys_address,
                    365:                                                 * for use by device driver
                    366:                                                 * mapping function in
                    367:                                                 * machine-independent
                    368:                                                 * pseudo-devices.
                    369:                                                 */
                    370: #endif /* pmap_phys_to_frame */
                    371: 
                    372: /*
                    373:  *     Optional routines
                    374:  */
                    375: #ifndef        pmap_copy
                    376: extern void            pmap_copy();            /* Copy range of
                    377:                                                 * mappings, if desired.
                    378:                                                 */
                    379: #endif /* pmap_copy */
                    380: #ifndef pmap_attribute
                    381: extern kern_return_t   pmap_attribute();       /* Get/Set special
                    382:                                                 * memory attributes
                    383:                                                 */
                    384: #endif /* pmap_attribute */
                    385: 
                    386: /*
                    387:  * Routines defined as macros.
                    388:  */
                    389: #ifndef        PMAP_ACTIVATE_USER
                    390: #define        PMAP_ACTIVATE_USER(pmap, thread, cpu) {         \
                    391:        if ((pmap) != kernel_pmap)                      \
                    392:            PMAP_ACTIVATE(pmap, thread, cpu);           \
                    393: }
                    394: #endif /* PMAP_ACTIVATE_USER */
                    395: 
                    396: #ifndef        PMAP_DEACTIVATE_USER
                    397: #define        PMAP_DEACTIVATE_USER(pmap, thread, cpu) {       \
                    398:        if ((pmap) != kernel_pmap)                      \
                    399:            PMAP_DEACTIVATE(pmap, thread, cpu);         \
                    400: }
                    401: #endif /* PMAP_DEACTIVATE_USER */
                    402: 
                    403: 
                    404: 
                    405: #ifndef        PMAP_ACTIVATE_KERNEL
                    406: #define        PMAP_ACTIVATE_KERNEL(cpu)                       \
                    407:                PMAP_ACTIVATE(kernel_pmap, THREAD_NULL, cpu)
                    408: #endif /* PMAP_ACTIVATE_KERNEL */
                    409: 
                    410: #ifndef        PMAP_DEACTIVATE_KERNEL
                    411: #define        PMAP_DEACTIVATE_KERNEL(cpu)                     \
                    412:                PMAP_DEACTIVATE(kernel_pmap, THREAD_NULL, cpu)
                    413: #endif /* PMAP_DEACTIVATE_KERNEL */
                    414: #endif
                    415: 
                    416: /*
                    417:  *     Exported data structures
                    418:  */
                    419: 
                    420: extern pmap_t  kernel_pmap;                    /* The kernel's map */
                    421: 
                    422: #endif /* _VM_PMAP_H_ */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.