2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
31 #include <mach/vm_param.h>
32 #include <vm/vm_kern.h>
33 #include <vm/vm_map.h>
34 #include <vm/vm_page.h>
36 #include <ppc/io_map_entries.h>
37 #include <ppc/Firmware.h>
38 #include <ppc/mappings.h>
39 #include <ppc/proc_reg.h>
41 extern vm_offset_t virtual_avail
;
44 * Allocate and map memory for devices that may need to be mapped
45 * outside the usual physical memory. If phys_addr is NULL then
46 * steal the appropriate number of physical pages from the vm
47 * system and map them.
50 io_map(phys_addr
, size
)
51 vm_offset_t phys_addr
;
61 assert (kernel_map
!= VM_MAP_NULL
); /* VM must be initialised */
65 /* make sure we map full contents of all the pages concerned */
66 size
= round_page(size
+ (phys_addr
& PAGE_MASK
));
68 /* Steal some free virtual addresses */
70 (void) kmem_alloc_pageable(kernel_map
, &start
, size
);
72 pmap_map_block(kernel_pmap
, start
, phys_addr
, size
,
73 VM_PROT_READ
|VM_PROT_WRITE
, PTE_WIMG_IO
, 0); /* Set up a block mapped area */
75 return (start
+ (phys_addr
& PAGE_MASK
));
79 /* Steal some free virtual addresses */
80 (void) kmem_alloc_pageable(kernel_map
, &start
, size
);
82 mapping_prealloc(size
); /* Make sure there are enough free mappings */
83 /* Steal some physical pages and map them one by one */
84 for (i
= 0; i
< size
; i
+= PAGE_SIZE
) {
86 while ((m
= vm_page_grab()) == VM_PAGE_NULL
)
89 (void) pmap_map_bd(start
+ i
,
91 m
->phys_addr
+ PAGE_SIZE
,
92 VM_PROT_READ
|VM_PROT_WRITE
);
95 mapping_relpre(); /* Allow mapping release */