2 * Copyright (c) 2000-2010 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
31 #if defined(__x86_64__)
32 void pmap_pcid_initialize(pmap_t
);
33 void pmap_pcid_initialize_kernel(pmap_t
);
34 pcid_t
pmap_pcid_allocate_pcid(int);
35 void pmap_pcid_deallocate_pcid(int, pmap_t
);
36 void pmap_destroy_pcid_sync_action(void *);
37 void pmap_destroy_pcid_sync(pmap_t
);
38 void pmap_pcid_lazy_flush(pmap_t
);
39 void pmap_pcid_activate(pmap_t
, int, boolean_t
, boolean_t
);
40 pcid_t
pcid_for_pmap_cpu_tuple(pmap_t
, thread_t
, int);
42 #define PMAP_INVALID ((pmap_t)0xDEAD7347)
43 #define PMAP_PCID_INVALID_PCID (0xDEAD)
44 #define PMAP_PCID_MAX_REFCOUNT (0xF0)
45 #define PMAP_PCID_MIN_PCID (1)
47 extern uint32_t pmap_pcid_ncpus
;
50 tlb_flush_global(void) {
51 uintptr_t cr4
= get_cr4();
52 pmap_assert(ml_get_interrupts_enabled() == FALSE
|| get_preemption_level() !=0);
53 pmap_assert2(((cr4
& CR4_PGE
) || ml_at_interrupt_context()), "CR4: 0x%lx", cr4
);
55 * We are, unfortunately, forced to rely on this expensive
56 * read-modify-write-write scheme due to the inadequate
57 * TLB invalidation ISA. The read is necessary as
58 * the kernel does not "own" the contents of CR4, the VMX
59 * feature in particular. It may be possible to
60 * avoid a global flush and instead track a generation
61 * count of kernel invalidations, but that scheme
62 * has its disadvantages as well.
65 set_cr4(cr4
& ~CR4_PGE
);
66 set_cr4(cr4
| CR4_PGE
);
68 set_cr3_raw(get_cr3_raw());
73 static inline void pmap_pcid_invalidate_all_cpus(pmap_t tpmap
) {
76 pmap_assert((sizeof(tpmap
->pmap_pcid_coherency_vector
) >= real_ncpus
) && (!(sizeof(tpmap
->pmap_pcid_coherency_vector
) & 7)));
78 for (i
= 0; i
< real_ncpus
; i
+=8) {
79 *(uint64_t *)(uintptr_t)&tpmap
->pmap_pcid_coherency_vector
[i
] = (~0ULL);
83 static inline void pmap_pcid_validate_current(void) {
84 int ccpu
= cpu_number();
85 volatile uint8_t *cptr
= cpu_datap(ccpu
)->cpu_pmap_pcid_coherentp
;
87 pmap_assert(cptr
== &(current_thread()->map
->pmap
->pmap_pcid_coherency_vector
[ccpu
]));
94 static inline void pmap_pcid_invalidate_cpu(pmap_t tpmap
, int ccpu
) {
95 tpmap
->pmap_pcid_coherency_vector
[ccpu
] = 0xFF;
98 static inline void pmap_pcid_validate_cpu(pmap_t tpmap
, int ccpu
) {
99 tpmap
->pmap_pcid_coherency_vector
[ccpu
] = 0;