Annotation of XNU/osfmk/ppc/io_map.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * The contents of this file constitute Original Code as defined in and
        !             7:  * are subject to the Apple Public Source License Version 1.1 (the
        !             8:  * "License").  You may not use this file except in compliance with the
        !             9:  * License.  Please obtain a copy of the License at
        !            10:  * http://www.apple.com/publicsource and read it before using this file.
        !            11:  * 
        !            12:  * This Original Code and all software distributed under the License are
        !            13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            17:  * License for the specific language governing rights and limitations
        !            18:  * under the License.
        !            19:  * 
        !            20:  * @APPLE_LICENSE_HEADER_END@
        !            21:  */
        !            22: /*
        !            23:  * @OSF_COPYRIGHT@
        !            24:  * 
        !            25:  */
        !            26: 
        !            27: #include <debug.h>
        !            28: #include <mach/vm_param.h>
        !            29: #include <vm/vm_kern.h>
        !            30: #include <vm/vm_map.h>
        !            31: #include <vm/vm_page.h>
        !            32: #include <ppc/pmap.h>
        !            33: #include <ppc/io_map_entries.h>
        !            34: #include <ppc/Firmware.h>
        !            35: #include <ppc/mappings.h>
        !            36: 
        !            37: extern vm_offset_t     virtual_avail;
        !            38: 
        !            39: /*
        !            40:  * Allocate and map memory for devices that may need to be mapped 
        !            41:  * outside the usual physical memory. If phys_addr is NULL then
        !            42:  * steal the appropriate number of physical pages from the vm
        !            43:  * system and map them.
        !            44:  */
        !            45: vm_offset_t
        !            46: io_map(phys_addr, size)
        !            47:        vm_offset_t     phys_addr;
        !            48:        vm_size_t       size;
        !            49: {
        !            50:        vm_offset_t     start;
        !            51:        int             i;
        !            52:        unsigned int j;
        !            53:        vm_page_t       m;
        !            54: 
        !            55: 
        !            56: #if DEBUG
        !            57:        assert (kernel_map != VM_MAP_NULL);                     /* VM must be initialised */
        !            58: #endif
        !            59:        
        !            60:        mapping_prealloc(size);                                         /* TEMPORARY - make sure there are enough free mappings */
        !            61: 
        !            62:        if (phys_addr != 0) {
        !            63:                /* make sure we map full contents of all the pages concerned */
        !            64:                size = round_page(size + (phys_addr & PAGE_MASK));
        !            65: 
        !            66:                /* Steal some free virtual addresses */
        !            67: 
        !            68:                (void) kmem_alloc_pageable(kernel_map, &start, size);
        !            69:        
        !            70:                (void) pmap_map_bd(start,
        !            71:                                   trunc_page(phys_addr),
        !            72:                                   trunc_page(phys_addr) + size,
        !            73:                                   VM_PROT_READ|VM_PROT_WRITE);
        !            74: 
        !            75:                mapping_relpre();                                               /* TEMPORARY - Allow mapping release */
        !            76:                return (start + (phys_addr & PAGE_MASK));
        !            77:        
        !            78:        } else {
        !            79:                /* Steal some free virtual addresses */
        !            80:                (void) kmem_alloc_pageable(kernel_map, &start, size);
        !            81: 
        !            82:                /* Steal some physical pages and map them one by one */
        !            83:                for (i = 0; i < size ; i += PAGE_SIZE) {
        !            84:                        m = VM_PAGE_NULL;
        !            85:                        while ((m = vm_page_grab()) == VM_PAGE_NULL)
        !            86:                                VM_PAGE_WAIT();
        !            87:                        vm_page_gobble(m);
        !            88:                        (void) pmap_map_bd(start + i,
        !            89:                                           m->phys_addr,
        !            90:                                           m->phys_addr + PAGE_SIZE,
        !            91:                                           VM_PROT_READ|VM_PROT_WRITE);
        !            92:                }
        !            93: 
        !            94:                mapping_relpre();                                               /* TEMPORARY - Allow mapping release */
        !            95:                return start;
        !            96:        }
        !            97: }

unix.superglobalmegacorp.com

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