]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/ppc/kern_machdep.c
6f9d2a154c4634f91e4de0491ef40f75cf83bf9d
[apple/xnu.git] / bsd / dev / ppc / kern_machdep.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
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
13 * file.
14 *
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.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Copyright (C) 1990, 1993 NeXT, Inc.
27 * Copyright (C) 1997 Apple Computer, Inc.
28 *
29 * File: next/kern_machdep.c
30 * Author: John Seamons
31 *
32 * Machine-specific kernel routines.
33 *
34 * HISTORY
35 * 8-Dec-91 Peter King (king) at NeXT
36 * Added grade_cpu_subtype().
37 * FIXME: Do we want to merge this with check_cpu_subtype()?
38 *
39 * 5-Mar-90 John Seamons (jks) at NeXT
40 * Created.
41 */
42
43 #include <sys/types.h>
44 #include <sys/param.h>
45 #include <mach/machine.h>
46 #include <mach/boolean.h>
47 #include <mach/vm_param.h>
48 #include <kern/cpu_number.h>
49
50 int
51 check_cpu_subtype(cpu_subtype_t cpu_subtype)
52 {
53 struct machine_slot *ms = &machine_slot[cpu_number()];
54
55 if (cpu_subtype == ms->cpu_subtype)
56 return (TRUE);
57
58 switch (cpu_subtype) {
59 case CPU_SUBTYPE_POWERPC_970:
60 case CPU_SUBTYPE_POWERPC_7450:
61 case CPU_SUBTYPE_POWERPC_7400:
62 case CPU_SUBTYPE_POWERPC_750:
63 case CPU_SUBTYPE_POWERPC_ALL:
64 return (TRUE);
65 }
66
67 return (FALSE);
68 }
69
70 /*
71 * Routine: grade_cpu_subtype()
72 *
73 * Function:
74 * Return a relative preference for cpu_subtypes in fat executable files.
75 * The higher the grade, the higher the preference.
76 * A grade of 0 means not acceptable.
77 */
78
79 int
80 grade_cpu_subtype(cpu_subtype_t cpu_subtype)
81 {
82 struct machine_slot *ms = &machine_slot[cpu_number()];
83
84 /*
85 * This code should match cpusubtype_findbestarch() in best_arch.c in the
86 * cctools project. As of 2/16/98 this is what has been agreed upon for
87 * the PowerPC subtypes. If an exact match is not found the subtype will
88 * be picked from the following order:
89 * 970, 7450, 7400, 750, ALL
90 * Note the 601 is NOT in the list above. It is only picked via an exact
91 * match. For details see Radar 2213821.
92 *
93 * To implement this function to follow what was agreed upon above, we use
94 * the fact there are currently 4 different subtypes. Exact matches return
95 * the value 6, and the values 5 thru 1 are returned for the
96 * subtypes listed in the order above.
97 */
98 if (ms->cpu_subtype == cpu_subtype)
99 return 6;
100 switch (cpu_subtype) {
101 case CPU_SUBTYPE_POWERPC_970:
102 return 5;
103 case CPU_SUBTYPE_POWERPC_7450:
104 return 4;
105 case CPU_SUBTYPE_POWERPC_7400:
106 return 3;
107 case CPU_SUBTYPE_POWERPC_750:
108 return 2;
109 case CPU_SUBTYPE_POWERPC_ALL:
110 return 1;
111 }
112 /*
113 * If we get here it is because it is a cpusubtype we don't support
114 * or a new cpusubtype that was added since this code was written. Both
115 * will be considered unacceptable.
116 */
117 return 0;
118 }
119
120 boolean_t
121 kernacc(
122 off_t start,
123 size_t len
124 )
125 {
126 off_t base;
127 off_t end;
128
129 base = trunc_page_64(start);
130 end = start + len;
131
132 while (base < end) {
133 if(kvtophys((vm_offset_t)base) == NULL)
134 return(FALSE);
135 base += page_size;
136 }
137
138 return (TRUE);
139 }