xref: /xnu-10002.61.3/osfmk/kern/cpc.h (revision 0f4c859e951fba394238ab619495c4e1d54d0f34)
1 // Copyright (c) 2023 Apple Inc. All rights reserved.
2 //
3 // @APPLE_OSREFERENCE_LICENSE_HEADER_START@
4 //
5 // This file contains Original Code and/or Modifications of Original Code
6 // as defined in and that are subject to the Apple Public Source License
7 // Version 2.0 (the 'License'). You may not use this file except in
8 // compliance with the License. The rights granted to you under the License
9 // may not be used to create, or enable the creation or redistribution of,
10 // unlawful or unlicensed copies of an Apple operating system, or to
11 // circumvent, violate, or enable the circumvention or violation of, any
12 // terms of an Apple operating system software license agreement.
13 //
14 // Please obtain a copy of the License at
15 // http://www.opensource.apple.com/apsl/ and read it before using this file.
16 //
17 // The Original Code and all software distributed under the License are
18 // distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
19 // EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
20 // INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
22 // Please see the License for the specific language governing rights and
23 // limitations under the License.
24 //
25 // @APPLE_OSREFERENCE_LICENSE_HEADER_END@
26 
27 #pragma once
28 
29 #include <os/base.h>
30 #include <stdbool.h>
31 #include <stdint.h>
32 
33 // Define whether CPC is operating in a secure environment,
34 // negated to fail closed (on missing `#include`).
35 #if DEVELOPMENT || DEBUG
36 #define CPC_INSECURE 1
37 #else // DEVELOPMENT || DEBUG
38 #define CPC_INSECURE 0
39 #endif // DEVELOPMENT || DEBUG
40 
41 __enum_decl(cpc_hw_t, unsigned int, {
42 	CPC_HW_CPMU,
43 	CPC_HW_UPMU,
44 	CPC_HW_COUNT,
45 });
46 
47 /// Return whether the event encoding `event_selector` is allowed on a given `hw`.
48 ///
49 /// Parameters:
50 ///   - hw: The allow list to check differs by the hardware.
51 ///   - event_selector: The event encoding to be sent to the hardware.
52 bool cpc_event_allowed(cpc_hw_t hw, uint16_t event_selector);
53 
54 /// Return whether CPC is operating securely.
55 bool cpc_is_secure(void);
56 
57 #if CPC_INSECURE
58 
59 /// Change the security enforcement of CPC.
60 ///
61 /// Parameters:
62 ///   - enforce_security: Whether to enforce secure usage of CPC.
63 void cpc_change_security(bool enforce_security);
64 
65 #endif // CPC_INSECURE
66