1 /*
2 * Copyright (c) 2018 - 2024, Nordic Semiconductor ASA
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * 3. Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #ifndef NRF_ACL_H__
35 #define NRF_ACL_H__
36
37 #include <nrfx.h>
38 #include <hal/nrf_ficr.h>
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 #define NRF_ACL_REGION_SIZE_MAX \
45 (nrf_ficr_codepagesize_get(NRF_FICR) * nrf_ficr_codesize_get(NRF_FICR))
46
47 /**
48 * @defgroup nrf_acl_hal ACL HAL
49 * @{
50 * @ingroup nrf_acl
51 * @brief Hardware access layer for managing the Access Control List (ACL) peripheral.
52 */
53
54 /** @brief ACL permissions. */
55 typedef enum
56 {
57 NRF_ACL_PERM_READ_NO_WRITE = ACL_ACL_PERM_WRITE_Msk, /**< Read allowed, write disallowed. */
58 NRF_ACL_PERM_NO_READ_WRITE = ACL_ACL_PERM_READ_Msk, /**< Read disallowed, write allowed. */
59 NRF_ACL_PERM_NO_READ_NO_WRITE = ACL_ACL_PERM_READ_Msk | ACL_ACL_PERM_WRITE_Msk /**< Read disallowed, write disallowed. */
60 } nrf_acl_perm_t;
61
62 /**
63 * @brief Function for setting region parameters for given ACL region.
64 *
65 * Address must be word and page aligned. Size must be page aligned.
66 *
67 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
68 * @param[in] region_id ACL region index.
69 * @param[in] address Start address.
70 * @param[in] size Size of region to protect in bytes.
71 * @param[in] perm Permissions to set for region to protect.
72 */
73 NRF_STATIC_INLINE void nrf_acl_region_set(NRF_ACL_Type * p_reg,
74 uint32_t region_id,
75 uint32_t address,
76 size_t size,
77 nrf_acl_perm_t perm);
78
79 /**
80 * @brief Function for getting the configured region address of a specific ACL region.
81 *
82 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
83 * @param[in] region_id ACL region index.
84 *
85 * @return Configured region address of given ACL region.
86 */
87 NRF_STATIC_INLINE uint32_t nrf_acl_region_address_get(NRF_ACL_Type const * p_reg,
88 uint32_t region_id);
89
90 /**
91 * @brief Function for getting the configured region size of a specific ACL region.
92 *
93 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
94 * @param[in] region_id ACL region index.
95 *
96 * @return Configured region size of given ACL region.
97 */
98 NRF_STATIC_INLINE size_t nrf_acl_region_size_get(NRF_ACL_Type const * p_reg, uint32_t region_id);
99
100 /**
101 * @brief Function for getting the configured region permissions of a specific ACL region.
102 *
103 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
104 * @param[in] region_id ACL region index.
105 *
106 * @return Configured region permissions of given ACL region.
107 */
108 NRF_STATIC_INLINE nrf_acl_perm_t nrf_acl_region_perm_get(NRF_ACL_Type const * p_reg,
109 uint32_t region_id);
110
111 #ifndef NRF_DECLARE_ONLY
112
nrf_acl_region_set(NRF_ACL_Type * p_reg,uint32_t region_id,uint32_t address,size_t size,nrf_acl_perm_t perm)113 NRF_STATIC_INLINE void nrf_acl_region_set(NRF_ACL_Type * p_reg,
114 uint32_t region_id,
115 uint32_t address,
116 size_t size,
117 nrf_acl_perm_t perm)
118 {
119 NRFX_ASSERT(region_id < ACL_REGIONS_COUNT);
120 NRFX_ASSERT(address % nrf_ficr_codepagesize_get(NRF_FICR) == 0);
121 NRFX_ASSERT(size <= NRF_ACL_REGION_SIZE_MAX);
122 NRFX_ASSERT(size != 0);
123 NRFX_ASSERT(size % nrf_ficr_codepagesize_get(NRF_FICR) == 0);
124
125 p_reg->ACL[region_id].ADDR = address;
126 p_reg->ACL[region_id].SIZE = size;
127 p_reg->ACL[region_id].PERM = perm;
128 }
129
nrf_acl_region_address_get(NRF_ACL_Type const * p_reg,uint32_t region_id)130 NRF_STATIC_INLINE uint32_t nrf_acl_region_address_get(NRF_ACL_Type const * p_reg,
131 uint32_t region_id)
132 {
133 return (uint32_t)p_reg->ACL[region_id].ADDR;
134 }
135
nrf_acl_region_size_get(NRF_ACL_Type const * p_reg,uint32_t region_id)136 NRF_STATIC_INLINE size_t nrf_acl_region_size_get(NRF_ACL_Type const * p_reg, uint32_t region_id)
137 {
138 return (size_t)p_reg->ACL[region_id].SIZE;
139 }
140
nrf_acl_region_perm_get(NRF_ACL_Type const * p_reg,uint32_t region_id)141 NRF_STATIC_INLINE nrf_acl_perm_t nrf_acl_region_perm_get(NRF_ACL_Type const * p_reg,
142 uint32_t region_id)
143 {
144 return (nrf_acl_perm_t)p_reg->ACL[region_id].PERM;
145 }
146
147 #endif // NRF_DECLARE_ONLY
148
149 /** @} */
150
151 #ifdef __cplusplus
152 }
153 #endif
154
155 #endif // NRF_ACL_H__
156