]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/commpage/commpage.c
907ae701d00dd40b5e2453eaf84b77d3767e1c3b
[apple/xnu.git] / osfmk / ppc / commpage / commpage.c
1 /*
2 * Copyright (c) 2003 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 /*
27 * This is a simplifed version of the commpage support from 10.3.
28 * The supported feature is the tuning of _cpu_capabilities.
29 * There is no shared page for user processes.
30 */
31
32 #include <mach/mach_types.h>
33 #include <mach/machine.h>
34 #include <ppc/exception.h>
35 #include <ppc/machine_routines.h>
36 #include <machine/cpu_capabilities.h>
37 #include <machine/commpage.h>
38
39 int _cpu_capabilities = 0; // define the capability vector
40
41 /* Determine number of CPUs on this system. We cannot rely on
42 * machine_info.max_cpus this early in the boot.
43 */
44 static int
45 commpage_cpus( void )
46 {
47 int cpus;
48
49 cpus = ml_get_max_cpus(); // NB: this call can block
50
51 if (cpus == 0)
52 panic("commpage cpus==0");
53 if (cpus > 0xFF)
54 cpus = 0xFF;
55
56 return cpus;
57 }
58
59
60 /* Initialize kernel version of _cpu_capabilities vector (used by KEXTs.) */
61
62 static void
63 commpage_init_cpu_capabilities( void )
64 {
65 struct per_proc_info *pp;
66 procFeatures *pfp;
67 int cpus;
68 int available;
69
70 pp = per_proc_info; // use CPU 0's per-proc
71 pfp = &pp->pf; // point to features in per-proc
72 available = pfp->Available;
73
74 // If AltiVec is disabled make sure it is not reported as available.
75 if ((available & pfAltivec) == 0) {
76 _cpu_capabilities &= ~kHasAltivec;
77 }
78
79 if (_cpu_capabilities & kDcbaAvailable) { // if this processor has DCBA, time it...
80 _cpu_capabilities |= commpage_time_dcba(); // ...and set kDcbaRecomended if it helps.
81 }
82
83 cpus = commpage_cpus(); // how many CPUs do we have
84 if (cpus == 1) _cpu_capabilities |= kUP;
85 _cpu_capabilities |= (cpus << kNumCPUsShift);
86 }
87
88
89 /* Fill in commpage: called once, during kernel initialization, from the
90 * startup thread before user-mode code is running.
91 * See the top of this file for a list of what you have to do to add
92 * a new routine to the commpage.
93 */
94 void
95 commpage_populate( void )
96 {
97 commpage_init_cpu_capabilities();
98 }