1 /*
2  * Copyright (c) 2022, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef __RSE_COMMS_ATU_H__
9 #define __RSE_COMMS_ATU_H__
10 
11 #include "tfm_plat_defs.h"
12 #include "rse_comms_atu_hal.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 typedef struct {
19     uint32_t ref_counts[RSE_COMMS_ATU_REGION_AM];
20 } comms_atu_region_set_t;
21 
22 /* Add an ATU region to a set of ATU regions */
23 enum tfm_plat_err_t comms_atu_add_region_to_set(comms_atu_region_set_t *set,
24                                                 uint8_t region);
25 
26 /* Convert a host pointer into a pointer in the rse address space (inside the
27  * given region), or return an error if that host pointer cannot be accessed in
28  * the given region
29  */
30 enum tfm_plat_err_t comms_atu_get_rse_ptr_from_host_addr(uint8_t region,
31                                                          uint64_t host_addr,
32                                                          void **rse_ptr);
33 
34 /* Allocate an ATU region to contain the given host buffer, and return the index
35  * of it. If there is already a region allocated that contains that host buffer,
36  * increment the reference counter for it and return the index of that region.
37  */
38 enum tfm_plat_err_t comms_atu_alloc_region(uint64_t host_addr, uint32_t size,
39                                            uint8_t *region);
40 
41 /* Decrease the regerence count to the particular region. If this is the last
42  * reference to that region, uninitialise it and return it to the pool that can
43  * be allocated.
44  */
45 enum tfm_plat_err_t comms_atu_free_region(uint8_t region);
46 
47 /* For each region in the set, decrease the reference count to the region by the
48  * reference count in the set. If this causes any regions to have no references,
49  * uninitialise the regions and return them to the pool that can be allocated.
50  */
51 enum tfm_plat_err_t comms_atu_free_regions(comms_atu_region_set_t regions);
52 
53 #ifdef __cplusplus
54 }
55 #endif
56 
57 #endif /* __RSE_COMMS_ATU_H__ */
58