]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/commpage/commpage.c
xnu-1699.32.7.tar.gz
[apple/xnu.git] / osfmk / i386 / commpage / commpage.c
CommitLineData
43866e37 1/*
6d2010ae 2 * Copyright (c) 2003-2010 Apple Inc. All rights reserved.
43866e37 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
43866e37 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
43866e37
A
27 */
28
55e303ae
A
29/*
30 * Here's what to do if you want to add a new routine to the comm page:
31 *
0c530ab8 32 * 1. Add a definition for it's address in osfmk/i386/cpu_capabilities.h,
55e303ae
A
33 * being careful to reserve room for future expansion.
34 *
35 * 2. Write one or more versions of the routine, each with it's own
36 * commpage_descriptor. The tricky part is getting the "special",
37 * "musthave", and "canthave" fields right, so that exactly one
38 * version of the routine is selected for every machine.
0c530ab8 39 * The source files should be in osfmk/i386/commpage/.
55e303ae
A
40 *
41 * 3. Add a ptr to your new commpage_descriptor(s) in the "routines"
0c530ab8
A
42 * array in osfmk/i386/commpage/commpage_asm.s. There are two
43 * arrays, one for the 32-bit and one for the 64-bit commpage.
55e303ae
A
44 *
45 * 4. Write the code in Libc to use the new routine.
46 */
47
48#include <mach/mach_types.h>
49#include <mach/machine.h>
91447636 50#include <mach/vm_map.h>
b0d623f7 51#include <mach/mach_vm.h>
7e4a7d39
A
52#include <mach/machine.h>
53#include <i386/cpuid.h>
2d21ac55 54#include <i386/tsc.h>
6d2010ae 55#include <i386/rtclock_protos.h>
2d21ac55 56#include <i386/cpu_data.h>
b0d623f7
A
57#include <i386/machine_routines.h>
58#include <i386/misc_protos.h>
7e4a7d39 59#include <i386/cpuid.h>
43866e37
A
60#include <machine/cpu_capabilities.h>
61#include <machine/commpage.h>
55e303ae
A
62#include <machine/pmap.h>
63#include <vm/vm_kern.h>
91447636 64#include <vm/vm_map.h>
b0d623f7 65
91447636
A
66#include <ipc/ipc_port.h>
67
0c530ab8 68#include <kern/page_decrypt.h>
6d2010ae 69#include <kern/processor.h>
4452a7af 70
0c530ab8
A
71/* the lists of commpage routines are in commpage_asm.s */
72extern commpage_descriptor* commpage_32_routines[];
73extern commpage_descriptor* commpage_64_routines[];
4452a7af 74
2d21ac55
A
75extern vm_map_t commpage32_map; // the shared submap, set up in vm init
76extern vm_map_t commpage64_map; // the shared submap, set up in vm init
4452a7af 77
0c530ab8
A
78char *commPagePtr32 = NULL; // virtual addr in kernel map of 32-bit commpage
79char *commPagePtr64 = NULL; // ...and of 64-bit commpage
6d2010ae 80uint32_t _cpu_capabilities = 0; // define the capability vector
6601e61a 81
0c530ab8
A
82int noVMX = 0; /* if true, do not set kHasAltivec in ppc _cpu_capabilities */
83
b0d623f7
A
84typedef uint32_t commpage_address_t;
85
86static commpage_address_t next; // next available address in comm page
87static commpage_address_t cur_routine; // comm page address of "current" routine
88static boolean_t matched; // true if we've found a match for "current" routine
0c530ab8
A
89
90static char *commPagePtr; // virtual addr in kernel map of commpage we are working on
b0d623f7 91static commpage_address_t commPageBaseOffset; // subtract from 32-bit runtime address to get offset in virtual commpage in kernel map
55e303ae 92
2d21ac55
A
93static commpage_time_data *time_data32 = NULL;
94static commpage_time_data *time_data64 = NULL;
95
6d2010ae
A
96decl_simple_lock_data(static,commpage_active_cpus_lock);
97
55e303ae
A
98/* Allocate the commpage and add to the shared submap created by vm:
99 * 1. allocate a page in the kernel map (RW)
100 * 2. wire it down
101 * 3. make a memory entry out of it
102 * 4. map that entry into the shared comm region map (R-only)
103 */
104
105static void*
0c530ab8 106commpage_allocate(
2d21ac55 107 vm_map_t submap, // commpage32_map or commpage_map64
0c530ab8 108 size_t area_used ) // _COMM_PAGE32_AREA_USED or _COMM_PAGE64_AREA_USED
55e303ae 109{
2d21ac55 110 vm_offset_t kernel_addr = 0; // address of commpage in kernel map
0c530ab8
A
111 vm_offset_t zero = 0;
112 vm_size_t size = area_used; // size actually populated
113 vm_map_entry_t entry;
114 ipc_port_t handle;
115
116 if (submap == NULL)
117 panic("commpage submap is null");
118
2d21ac55 119 if (vm_map(kernel_map,&kernel_addr,area_used,0,VM_FLAGS_ANYWHERE,NULL,0,FALSE,VM_PROT_ALL,VM_PROT_ALL,VM_INHERIT_NONE))
0c530ab8
A
120 panic("cannot allocate commpage");
121
122 if (vm_map_wire(kernel_map,kernel_addr,kernel_addr+area_used,VM_PROT_DEFAULT,FALSE))
123 panic("cannot wire commpage");
124
125 /*
126 * Now that the object is created and wired into the kernel map, mark it so that no delay
127 * copy-on-write will ever be performed on it as a result of mapping it into user-space.
128 * If such a delayed copy ever occurred, we could remove the kernel's wired mapping - and
129 * that would be a real disaster.
130 *
131 * JMM - What we really need is a way to create it like this in the first place.
132 */
133 if (!vm_map_lookup_entry( kernel_map, vm_map_trunc_page(kernel_addr), &entry) || entry->is_sub_map)
134 panic("cannot find commpage entry");
135 entry->object.vm_object->copy_strategy = MEMORY_OBJECT_COPY_NONE;
136
137 if (mach_make_memory_entry( kernel_map, // target map
138 &size, // size
139 kernel_addr, // offset (address in kernel map)
2d21ac55 140 VM_PROT_ALL, // map it RWX
0c530ab8
A
141 &handle, // this is the object handle we get
142 NULL )) // parent_entry (what is this?)
143 panic("cannot make entry for commpage");
144
145 if (vm_map_64( submap, // target map (shared submap)
146 &zero, // address (map into 1st page in submap)
147 area_used, // size
148 0, // mask
149 VM_FLAGS_FIXED, // flags (it must be 1st page in submap)
150 handle, // port is the memory entry we just made
151 0, // offset (map 1st page in memory entry)
152 FALSE, // copy
2d21ac55
A
153 VM_PROT_READ|VM_PROT_EXECUTE, // cur_protection (R-only in user map)
154 VM_PROT_READ|VM_PROT_EXECUTE, // max_protection
0c530ab8
A
155 VM_INHERIT_SHARE )) // inheritance
156 panic("cannot map commpage");
157
158 ipc_port_release(handle);
6d2010ae
A
159
160 // Initialize the text section of the commpage with INT3
161 char *commpage_ptr = (char*)(intptr_t)kernel_addr;
162 vm_size_t i;
163 for( i = _COMM_PAGE_TEXT_START - _COMM_PAGE_START_ADDRESS; i < size; i++ )
164 // This is the hex for the X86 opcode INT3
165 commpage_ptr[i] = 0xCC;
0c530ab8 166
b0d623f7 167 return (void*)(intptr_t)kernel_addr; // return address in kernel map
55e303ae
A
168}
169
170/* Get address (in kernel map) of a commpage field. */
171
91447636 172static void*
55e303ae 173commpage_addr_of(
b0d623f7 174 commpage_address_t addr_at_runtime )
55e303ae 175{
b0d623f7 176 return (void*) ((uintptr_t)commPagePtr + (addr_at_runtime - commPageBaseOffset));
55e303ae
A
177}
178
179/* Determine number of CPUs on this system. We cannot rely on
180 * machine_info.max_cpus this early in the boot.
181 */
182static int
183commpage_cpus( void )
184{
185 int cpus;
186
187 cpus = ml_get_max_cpus(); // NB: this call can block
188
189 if (cpus == 0)
190 panic("commpage cpus==0");
191 if (cpus > 0xFF)
192 cpus = 0xFF;
193
194 return cpus;
195}
43866e37 196
55e303ae 197/* Initialize kernel version of _cpu_capabilities vector (used by KEXTs.) */
43866e37 198
55e303ae
A
199static void
200commpage_init_cpu_capabilities( void )
201{
6d2010ae 202 uint32_t bits;
55e303ae
A
203 int cpus;
204 ml_cpu_info_t cpu_info;
43866e37 205
55e303ae
A
206 bits = 0;
207 ml_cpu_get_info(&cpu_info);
208
209 switch (cpu_info.vector_unit) {
6d2010ae
A
210 case 9:
211 bits |= kHasAVX1_0;
212 /* fall thru */
2d21ac55
A
213 case 8:
214 bits |= kHasSSE4_2;
215 /* fall thru */
216 case 7:
217 bits |= kHasSSE4_1;
218 /* fall thru */
0c530ab8
A
219 case 6:
220 bits |= kHasSupplementalSSE3;
221 /* fall thru */
55e303ae 222 case 5:
91447636 223 bits |= kHasSSE3;
55e303ae
A
224 /* fall thru */
225 case 4:
226 bits |= kHasSSE2;
227 /* fall thru */
228 case 3:
229 bits |= kHasSSE;
230 /* fall thru */
231 case 2:
232 bits |= kHasMMX;
233 default:
234 break;
235 }
236 switch (cpu_info.cache_line_size) {
237 case 128:
238 bits |= kCache128;
239 break;
240 case 64:
241 bits |= kCache64;
242 break;
243 case 32:
244 bits |= kCache32;
245 break;
246 default:
247 break;
248 }
249 cpus = commpage_cpus(); // how many CPUs do we have
250
251 if (cpus == 1)
252 bits |= kUP;
253
254 bits |= (cpus << kNumCPUsShift);
255
91447636
A
256 bits |= kFastThreadLocalStorage; // we use %gs for TLS
257
0c530ab8
A
258 if (cpu_mode_is64bit()) // k64Bit means processor is 64-bit capable
259 bits |= k64Bit;
260
2d21ac55
A
261 if (tscFreq <= SLOW_TSC_THRESHOLD) /* is TSC too slow for _commpage_nanotime? */
262 bits |= kSlow;
263
7ddcb079 264 bits |= (cpuid_features() & CPUID_FEATURE_AES) ? kHasAES : 0;
d1ecb069 265
13f56ec4
A
266 bits |= (cpuid_features() & CPUID_FEATURE_F16C) ? kHasF16C : 0;
267 bits |= (cpuid_features() & CPUID_FEATURE_RDRAND) ? kHasRDRAND : 0;
268 bits |= ((cpuid_leaf7_features() & CPUID_LEAF7_FEATURE_ENFSTRG) &&
269 (rdmsr64(MSR_IA32_MISC_ENABLE) & 1ULL )) ? kHasENFSTRG : 0;
270
55e303ae
A
271 _cpu_capabilities = bits; // set kernel version for use by drivers etc
272}
273
0c530ab8 274int
2d21ac55 275_get_cpu_capabilities(void)
0c530ab8
A
276{
277 return _cpu_capabilities;
278}
279
55e303ae
A
280/* Copy data into commpage. */
281
282static void
283commpage_stuff(
b0d623f7 284 commpage_address_t address,
0c530ab8 285 const void *source,
55e303ae
A
286 int length )
287{
288 void *dest = commpage_addr_of(address);
289
b0d623f7 290 if (address < next)
6d2010ae 291 panic("commpage overlap at address 0x%p, 0x%x < 0x%x", dest, address, next);
55e303ae
A
292
293 bcopy(source,dest,length);
43866e37 294
b0d623f7 295 next = address + length;
55e303ae
A
296}
297
298/* Copy a routine into comm page if it matches running machine.
299 */
300static void
301commpage_stuff_routine(
302 commpage_descriptor *rd )
303{
b0d623f7 304 uint32_t must,cant;
55e303ae
A
305
306 if (rd->commpage_address != cur_routine) {
307 if ((cur_routine!=0) && (matched==0))
b0d623f7 308 panic("commpage no match for last, next address %08x", rd->commpage_address);
55e303ae
A
309 cur_routine = rd->commpage_address;
310 matched = 0;
311 }
312
313 must = _cpu_capabilities & rd->musthave;
314 cant = _cpu_capabilities & rd->canthave;
315
316 if ((must == rd->musthave) && (cant == 0)) {
317 if (matched)
b0d623f7 318 panic("commpage multiple matches for address %08x", rd->commpage_address);
55e303ae
A
319 matched = 1;
320
321 commpage_stuff(rd->commpage_address,rd->code_address,rd->code_length);
322 }
323}
324
0c530ab8 325/* Fill in the 32- or 64-bit commpage. Called once for each.
55e303ae
A
326 */
327
0c530ab8
A
328static void
329commpage_populate_one(
2d21ac55 330 vm_map_t submap, // commpage32_map or compage64_map
0c530ab8
A
331 char ** kernAddressPtr, // &commPagePtr32 or &commPagePtr64
332 size_t area_used, // _COMM_PAGE32_AREA_USED or _COMM_PAGE64_AREA_USED
b0d623f7 333 commpage_address_t base_offset, // will become commPageBaseOffset
0c530ab8 334 commpage_descriptor** commpage_routines, // list of routine ptrs for this commpage
2d21ac55 335 commpage_time_data** time_data, // &time_data32 or &time_data64
0c530ab8 336 const char* signature ) // "commpage 32-bit" or "commpage 64-bit"
55e303ae 337{
6d2010ae 338 uint8_t c1;
91447636 339 short c2;
6d2010ae
A
340 int c4;
341 uint64_t c8;
342 uint32_t cfamily;
55e303ae
A
343 commpage_descriptor **rd;
344 short version = _COMM_PAGE_THIS_VERSION;
55e303ae 345
b0d623f7 346 next = 0;
0c530ab8
A
347 cur_routine = 0;
348 commPagePtr = (char *)commpage_allocate( submap, (vm_size_t) area_used );
349 *kernAddressPtr = commPagePtr; // save address either in commPagePtr32 or 64
350 commPageBaseOffset = base_offset;
b0d623f7 351
2d21ac55 352 *time_data = commpage_addr_of( _COMM_PAGE_TIME_DATA_START );
55e303ae
A
353
354 /* Stuff in the constants. We move things into the comm page in strictly
355 * ascending order, so we can check for overlap and panic if so.
356 */
b0d623f7 357 commpage_stuff(_COMM_PAGE_SIGNATURE,signature,(int)strlen(signature));
6d2010ae 358 commpage_stuff(_COMM_PAGE_VERSION,&version,sizeof(short));
0c530ab8
A
359 commpage_stuff(_COMM_PAGE_CPU_CAPABILITIES,&_cpu_capabilities,sizeof(int));
360
6d2010ae
A
361 c2 = 32; // default
362 if (_cpu_capabilities & kCache64)
91447636
A
363 c2 = 64;
364 else if (_cpu_capabilities & kCache128)
365 c2 = 128;
366 commpage_stuff(_COMM_PAGE_CACHE_LINESIZE,&c2,2);
b0d623f7
A
367
368 c4 = MP_SPIN_TRIES;
369 commpage_stuff(_COMM_PAGE_SPIN_COUNT,&c4,4);
91447636 370
6d2010ae
A
371 /* machine_info valid after ml_get_max_cpus() */
372 c1 = machine_info.physical_cpu_max;
373 commpage_stuff(_COMM_PAGE_PHYSICAL_CPUS,&c1,1);
374 c1 = machine_info.logical_cpu_max;
375 commpage_stuff(_COMM_PAGE_LOGICAL_CPUS,&c1,1);
376
377 c8 = ml_cpu_cache_size(0);
378 commpage_stuff(_COMM_PAGE_MEMORY_SIZE, &c8, 8);
379
380 cfamily = cpuid_info()->cpuid_cpufamily;
381 commpage_stuff(_COMM_PAGE_CPUFAMILY, &cfamily, 4);
6601e61a 382
0c530ab8 383 for( rd = commpage_routines; *rd != NULL ; rd++ )
55e303ae
A
384 commpage_stuff_routine(*rd);
385
386 if (!matched)
387 panic("commpage no match on last routine");
388
b0d623f7
A
389 if (next > _COMM_PAGE_END)
390 panic("commpage overflow: next = 0x%08x, commPagePtr = 0x%p", next, commPagePtr);
91447636 391
43866e37 392}
91447636 393
0c530ab8
A
394
395/* Fill in commpages: called once, during kernel initialization, from the
396 * startup thread before user-mode code is running.
397 *
398 * See the top of this file for a list of what you have to do to add
399 * a new routine to the commpage.
400 */
91447636
A
401
402void
0c530ab8 403commpage_populate( void )
91447636 404{
0c530ab8
A
405 commpage_init_cpu_capabilities();
406
2d21ac55 407 commpage_populate_one( commpage32_map,
0c530ab8
A
408 &commPagePtr32,
409 _COMM_PAGE32_AREA_USED,
410 _COMM_PAGE32_BASE_ADDRESS,
411 commpage_32_routines,
2d21ac55 412 &time_data32,
0c530ab8 413 "commpage 32-bit");
b0d623f7 414#ifndef __LP64__
0c530ab8
A
415 pmap_commpage32_init((vm_offset_t) commPagePtr32, _COMM_PAGE32_BASE_ADDRESS,
416 _COMM_PAGE32_AREA_USED/INTEL_PGBYTES);
b0d623f7 417#endif
2d21ac55 418 time_data64 = time_data32; /* if no 64-bit commpage, point to 32-bit */
0c530ab8
A
419
420 if (_cpu_capabilities & k64Bit) {
2d21ac55 421 commpage_populate_one( commpage64_map,
0c530ab8
A
422 &commPagePtr64,
423 _COMM_PAGE64_AREA_USED,
b0d623f7 424 _COMM_PAGE32_START_ADDRESS, /* commpage address are relative to 32-bit commpage placement */
0c530ab8 425 commpage_64_routines,
2d21ac55 426 &time_data64,
0c530ab8 427 "commpage 64-bit");
b0d623f7 428#ifndef __LP64__
0c530ab8
A
429 pmap_commpage64_init((vm_offset_t) commPagePtr64, _COMM_PAGE64_BASE_ADDRESS,
430 _COMM_PAGE64_AREA_USED/INTEL_PGBYTES);
b0d623f7 431#endif
0c530ab8 432 }
6601e61a 433
6d2010ae
A
434 simple_lock_init(&commpage_active_cpus_lock, 0);
435
436 commpage_update_active_cpus();
0c530ab8 437 rtc_nanotime_init_commpage();
91447636 438}
2d21ac55
A
439
440
441/* Update commpage nanotime information. Note that we interleave
442 * setting the 32- and 64-bit commpages, in order to keep nanotime more
443 * nearly in sync between the two environments.
444 *
445 * This routine must be serialized by some external means, ie a lock.
446 */
447
448void
449commpage_set_nanotime(
450 uint64_t tsc_base,
451 uint64_t ns_base,
452 uint32_t scale,
453 uint32_t shift )
454{
455 commpage_time_data *p32 = time_data32;
456 commpage_time_data *p64 = time_data64;
457 static uint32_t generation = 0;
458 uint32_t next_gen;
459
460 if (p32 == NULL) /* have commpages been allocated yet? */
461 return;
462
463 if ( generation != p32->nt_generation )
464 panic("nanotime trouble 1"); /* possibly not serialized */
465 if ( ns_base < p32->nt_ns_base )
466 panic("nanotime trouble 2");
467 if ((shift != 32) && ((_cpu_capabilities & kSlow)==0) )
468 panic("nanotime trouble 3");
469
470 next_gen = ++generation;
471 if (next_gen == 0)
472 next_gen = ++generation;
473
474 p32->nt_generation = 0; /* mark invalid, so commpage won't try to use it */
475 p64->nt_generation = 0;
476
477 p32->nt_tsc_base = tsc_base;
478 p64->nt_tsc_base = tsc_base;
479
480 p32->nt_ns_base = ns_base;
481 p64->nt_ns_base = ns_base;
482
483 p32->nt_scale = scale;
484 p64->nt_scale = scale;
485
486 p32->nt_shift = shift;
487 p64->nt_shift = shift;
488
489 p32->nt_generation = next_gen; /* mark data as valid */
490 p64->nt_generation = next_gen;
491}
492
493
494/* Disable commpage gettimeofday(), forcing commpage to call through to the kernel. */
495
496void
497commpage_disable_timestamp( void )
498{
499 time_data32->gtod_generation = 0;
500 time_data64->gtod_generation = 0;
501}
502
503
504/* Update commpage gettimeofday() information. As with nanotime(), we interleave
505 * updates to the 32- and 64-bit commpage, in order to keep time more nearly in sync
506 * between the two environments.
507 *
508 * This routine must be serializeed by some external means, ie a lock.
509 */
510
511 void
512 commpage_set_timestamp(
513 uint64_t abstime,
514 uint64_t secs )
515{
516 commpage_time_data *p32 = time_data32;
517 commpage_time_data *p64 = time_data64;
518 static uint32_t generation = 0;
519 uint32_t next_gen;
520
521 next_gen = ++generation;
522 if (next_gen == 0)
523 next_gen = ++generation;
524
525 p32->gtod_generation = 0; /* mark invalid, so commpage won't try to use it */
526 p64->gtod_generation = 0;
527
528 p32->gtod_ns_base = abstime;
529 p64->gtod_ns_base = abstime;
530
531 p32->gtod_sec_base = secs;
532 p64->gtod_sec_base = secs;
533
534 p32->gtod_generation = next_gen; /* mark data as valid */
535 p64->gtod_generation = next_gen;
536}
b0d623f7
A
537
538
539/* Update _COMM_PAGE_MEMORY_PRESSURE. Called periodically from vm's compute_memory_pressure() */
540
541void
542commpage_set_memory_pressure(
543 unsigned int pressure )
544{
545 char *cp;
546 uint32_t *ip;
547
548 cp = commPagePtr32;
549 if ( cp ) {
550 cp += (_COMM_PAGE_MEMORY_PRESSURE - _COMM_PAGE32_BASE_ADDRESS);
551 ip = (uint32_t*) cp;
552 *ip = (uint32_t) pressure;
553 }
554
555 cp = commPagePtr64;
556 if ( cp ) {
557 cp += (_COMM_PAGE_MEMORY_PRESSURE - _COMM_PAGE32_START_ADDRESS);
558 ip = (uint32_t*) cp;
559 *ip = (uint32_t) pressure;
560 }
561
562}
563
564
565/* Update _COMM_PAGE_SPIN_COUNT. We might want to reduce when running on a battery, etc. */
566
567void
568commpage_set_spin_count(
569 unsigned int count )
570{
571 char *cp;
572 uint32_t *ip;
573
574 if (count == 0) /* we test for 0 after decrement, not before */
575 count = 1;
576
577 cp = commPagePtr32;
578 if ( cp ) {
579 cp += (_COMM_PAGE_SPIN_COUNT - _COMM_PAGE32_BASE_ADDRESS);
580 ip = (uint32_t*) cp;
581 *ip = (uint32_t) count;
582 }
583
584 cp = commPagePtr64;
585 if ( cp ) {
586 cp += (_COMM_PAGE_SPIN_COUNT - _COMM_PAGE32_START_ADDRESS);
587 ip = (uint32_t*) cp;
588 *ip = (uint32_t) count;
589 }
590
591}
592
6d2010ae
A
593/* Updated every time a logical CPU goes offline/online */
594void
595commpage_update_active_cpus(void)
596{
597 char *cp;
598 volatile uint8_t *ip;
599
600 /* At least 32-bit commpage must be initialized */
601 if (!commPagePtr32)
602 return;
603
604 simple_lock(&commpage_active_cpus_lock);
605
606 cp = commPagePtr32;
607 cp += (_COMM_PAGE_ACTIVE_CPUS - _COMM_PAGE32_BASE_ADDRESS);
608 ip = (volatile uint8_t*) cp;
609 *ip = (uint8_t) processor_avail_count;
610
611 cp = commPagePtr64;
612 if ( cp ) {
613 cp += (_COMM_PAGE_ACTIVE_CPUS - _COMM_PAGE32_START_ADDRESS);
614 ip = (volatile uint8_t*) cp;
615 *ip = (uint8_t) processor_avail_count;
616 }
617
618 simple_unlock(&commpage_active_cpus_lock);
619}
620
b0d623f7
A
621
622/* Check to see if a given address is in the Preemption Free Zone (PFZ) */
623
624uint32_t
625commpage_is_in_pfz32(uint32_t addr32)
626{
627 if ( (addr32 >= _COMM_PAGE_PFZ_START) && (addr32 < _COMM_PAGE_PFZ_END)) {
628 return 1;
629 }
630 else
631 return 0;
632}
633
634uint32_t
635commpage_is_in_pfz64(addr64_t addr64)
636{
637 if ( (addr64 >= _COMM_PAGE_32_TO_64(_COMM_PAGE_PFZ_START))
638 && (addr64 < _COMM_PAGE_32_TO_64(_COMM_PAGE_PFZ_END))) {
639 return 1;
640 }
641 else
642 return 0;
643}
644