2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
28 #include <mach/vm_param.h>
29 #include <vm/vm_kern.h>
30 #include <vm/vm_map.h>
31 #include <vm/vm_page.h>
33 #include <ppc/io_map_entries.h>
34 #include <ppc/Firmware.h>
35 #include <ppc/mappings.h>
36 #include <ppc/proc_reg.h>
38 extern vm_offset_t virtual_avail
;
41 * Allocate and map memory for devices that may need to be mapped
42 * outside the usual physical memory. If phys_addr is NULL then
43 * steal the appropriate number of physical pages from the vm
44 * system and map them.
47 io_map(phys_addr
, size
)
48 vm_offset_t phys_addr
;
58 assert (kernel_map
!= VM_MAP_NULL
); /* VM must be initialised */
62 /* make sure we map full contents of all the pages concerned */
63 size
= round_page(size
+ (phys_addr
& PAGE_MASK
));
65 /* Steal some free virtual addresses */
67 (void) kmem_alloc_pageable(kernel_map
, &start
, size
);
69 pmap_map_block(kernel_pmap
, start
, phys_addr
, size
,
70 VM_PROT_READ
|VM_PROT_WRITE
, PTE_WIMG_IO
, 0); /* Set up a block mapped area */
72 return (start
+ (phys_addr
& PAGE_MASK
));
76 /* Steal some free virtual addresses */
77 (void) kmem_alloc_pageable(kernel_map
, &start
, size
);
79 mapping_prealloc(size
); /* Make sure there are enough free mappings */
80 /* Steal some physical pages and map them one by one */
81 for (i
= 0; i
< size
; i
+= PAGE_SIZE
) {
83 while ((m
= vm_page_grab()) == VM_PAGE_NULL
)
86 (void) pmap_map_bd(start
+ i
,
88 m
->phys_addr
+ PAGE_SIZE
,
89 VM_PROT_READ
|VM_PROT_WRITE
);
92 mapping_relpre(); /* Allow mapping release */