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