2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
34 #include <mach/vm_param.h>
35 #include <vm/vm_kern.h>
36 #include <vm/vm_map.h>
37 #include <vm/vm_page.h>
39 #include <ppc/io_map_entries.h>
40 #include <ppc/Firmware.h>
41 #include <ppc/mappings.h>
42 #include <ppc/proc_reg.h>
44 extern vm_offset_t virtual_avail
;
47 * Allocate and map memory for devices that may need to be mapped
48 * outside the usual physical memory. If phys_addr is NULL then
49 * steal the appropriate number of physical pages from the vm
50 * system and map them.
55 io_map(phys_addr
, size
)
56 vm_offset_t phys_addr
;
66 assert (kernel_map
!= VM_MAP_NULL
); /* VM must be initialised */
69 if (phys_addr
!= 0) { /* If they supplied a physical address, use it */
71 size
= round_page(size
+ (phys_addr
& PAGE_MASK
)); /* Make sure we map all of it */
73 (void) kmem_alloc_pageable(kernel_map
, &start
, size
); /* Get some virtual addresses to use */
75 (void)mapping_make(kernel_pmap
, (addr64_t
)start
, (ppnum_t
)(phys_addr
>> 12),
76 (mmFlgBlock
| mmFlgUseAttr
| mmFlgCInhib
| mmFlgGuarded
), /* Map as I/O page */
77 (size
>> 12), VM_PROT_READ
|VM_PROT_WRITE
);
79 return (start
+ (phys_addr
& PAGE_MASK
)); /* Pass back the physical address */
83 (void) kmem_alloc_pageable(kernel_map
, &start
, size
); /* Get some virtual addresses */
85 mapping_prealloc(size
); /* Make sure there are enough free mappings */
87 for (i
= 0; i
< size
; i
+= PAGE_SIZE
) {
89 while ((m
= vm_page_grab()) == VM_PAGE_NULL
) { /* Get a physical page */
90 VM_PAGE_WAIT(); /* Wait if we didn't have one */
94 (void)mapping_make(kernel_pmap
,
95 (addr64_t
)(start
+ i
), m
->phys_page
,
96 (mmFlgBlock
| mmFlgUseAttr
| mmFlgCInhib
| mmFlgGuarded
), /* Map as I/O page */
97 1, VM_PROT_READ
|VM_PROT_WRITE
);
101 mapping_relpre(); /* Allow mapping release */
108 * Allocate and map memory for devices before the VM system comes alive.
111 vm_offset_t
io_map_spec(vm_offset_t phys_addr
, vm_size_t size
)
115 if(kernel_map
!= VM_MAP_NULL
) { /* If VM system is up, redirect to normal routine */
117 return io_map(phys_addr
, size
); /* Map the address */
121 size
= round_page(size
+ (phys_addr
- (phys_addr
& -PAGE_SIZE
))); /* Extend the length to include it all */
122 start
= pmap_boot_map(size
); /* Get me some virtual address */
124 (void)mapping_make(kernel_pmap
, (addr64_t
)start
, (ppnum_t
)(phys_addr
>> 12),
125 (mmFlgBlock
| mmFlgUseAttr
| mmFlgCInhib
| mmFlgGuarded
), /* Map as I/O page */
126 (size
>> 12), VM_PROT_READ
|VM_PROT_WRITE
);
128 return (start
+ (phys_addr
& PAGE_MASK
));