xref: /xnu-11215.41.3/osfmk/kern/cpc.h (revision 33de042d024d46de5ff4e89f2471de6608e37fa4)
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 __result_use_check bool cpc_hw_acquire(cpc_hw_t hw, const char *owner_name);
48 bool cpc_hw_in_use(cpc_hw_t hw);
49 void cpc_hw_release(cpc_hw_t hw, const char *owner_name);
50 
51 /// Return whether the event encoding `event_selector` is allowed on a given `hw`.
52 ///
53 /// Parameters:
54 ///   - hw: The allow list to check differs by the hardware.
55 ///   - event_selector: The event encoding to be sent to the hardware.
56 bool cpc_event_allowed(cpc_hw_t hw, uint16_t event_selector);
57 
58 /// Return whether CPC is operating securely.
59 bool cpc_is_secure(void);
60 
61 #if CPC_INSECURE
62 
63 /// Change the security enforcement of CPC.
64 ///
65 /// Parameters:
66 ///   - enforce_security: Whether to enforce secure usage of CPC.
67 void cpc_change_security(bool enforce_security);
68 
69 #endif // CPC_INSECURE
70