1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2020 Marvell International Ltd.
6 #ifndef _CVMX_GLOBAL_RESOURCES_T_
7 #define _CVMX_GLOBAL_RESOURCES_T_
9 #define CVMX_GLOBAL_RESOURCES_DATA_NAME "cvmx-global-resources"
11 /*In macros below abbreviation GR stands for global resources. */
12 #define CVMX_GR_TAG_INVALID \
13 cvmx_get_gr_tag('i', 'n', 'v', 'a', 'l', 'i', 'd', '.', '.', '.', '.', '.', '.', '.', '.', \
15 /*Tag for pko que table range. */
16 #define CVMX_GR_TAG_PKO_QUEUES \
17 cvmx_get_gr_tag('c', 'v', 'm', '_', 'p', 'k', 'o', '_', 'q', 'u', 'e', 'u', 's', '.', '.', \
19 /*Tag for a pko internal ports range */
20 #define CVMX_GR_TAG_PKO_IPORTS \
21 cvmx_get_gr_tag('c', 'v', 'm', '_', 'p', 'k', 'o', '_', 'i', 'p', 'o', 'r', 't', '.', '.', \
23 #define CVMX_GR_TAG_FPA \
24 cvmx_get_gr_tag('c', 'v', 'm', '_', 'f', 'p', 'a', '.', '.', '.', '.', '.', '.', '.', '.', \
26 #define CVMX_GR_TAG_FAU \
27 cvmx_get_gr_tag('c', 'v', 'm', '_', 'f', 'a', 'u', '.', '.', '.', '.', '.', '.', '.', '.', \
29 #define CVMX_GR_TAG_SSO_GRP(n) \
30 cvmx_get_gr_tag('c', 'v', 'm', '_', 's', 's', 'o', '_', '0', (n) + '0', '.', '.', '.', \
32 #define CVMX_GR_TAG_TIM(n) \
33 cvmx_get_gr_tag('c', 'v', 'm', '_', 't', 'i', 'm', '_', (n) + '0', '.', '.', '.', '.', \
35 #define CVMX_GR_TAG_CLUSTERS(x) \
36 cvmx_get_gr_tag('c', 'v', 'm', '_', 'c', 'l', 'u', 's', 't', 'e', 'r', '_', (x + '0'), \
38 #define CVMX_GR_TAG_CLUSTER_GRP(x) \
39 cvmx_get_gr_tag('c', 'v', 'm', '_', 'c', 'l', 'g', 'r', 'p', '_', (x + '0'), '.', '.', \
41 #define CVMX_GR_TAG_STYLE(x) \
42 cvmx_get_gr_tag('c', 'v', 'm', '_', 's', 't', 'y', 'l', 'e', '_', (x + '0'), '.', '.', \
44 #define CVMX_GR_TAG_QPG_ENTRY(x) \
45 cvmx_get_gr_tag('c', 'v', 'm', '_', 'q', 'p', 'g', 'e', 't', '_', (x + '0'), '.', '.', \
47 #define CVMX_GR_TAG_BPID(x) \
48 cvmx_get_gr_tag('c', 'v', 'm', '_', 'b', 'p', 'i', 'd', 's', '_', (x + '0'), '.', '.', \
50 #define CVMX_GR_TAG_MTAG_IDX(x) \
51 cvmx_get_gr_tag('c', 'v', 'm', '_', 'm', 't', 'a', 'g', 'x', '_', (x + '0'), '.', '.', \
53 #define CVMX_GR_TAG_PCAM(x, y, z) \
54 cvmx_get_gr_tag('c', 'v', 'm', '_', 'p', 'c', 'a', 'm', '_', (x + '0'), (y + '0'), \
55 (z + '0'), '.', '.', '.', '.')
57 #define CVMX_GR_TAG_CIU3_IDT(_n) \
58 cvmx_get_gr_tag('c', 'v', 'm', '_', 'c', 'i', 'u', '3', '_', ((_n) + '0'), '_', 'i', 'd', \
61 /* Allocation of the 512 SW INTSTs (in the 12 bit SW INTSN space) */
62 #define CVMX_GR_TAG_CIU3_SWINTSN(_n) \
63 cvmx_get_gr_tag('c', 'v', 'm', '_', 'c', 'i', 'u', '3', '_', ((_n) + '0'), '_', 's', 'w', \
66 #define TAG_INIT_PART(A, B, C, D, E, F, G, H) \
67 ((((u64)(A) & 0xff) << 56) | (((u64)(B) & 0xff) << 48) | (((u64)(C) & 0xff) << 40) | \
68 (((u64)(D) & 0xff) << 32) | (((u64)(E) & 0xff) << 24) | (((u64)(F) & 0xff) << 16) | \
69 (((u64)(G) & 0xff) << 8) | (((u64)(H) & 0xff)))
71 struct global_resource_tag {
76 enum cvmx_resource_err { CVMX_RESOURCE_ALLOC_FAILED = -1, CVMX_RESOURCE_ALREADY_RESERVED = -2 };
80 * Creates a tag from the specified characters.
82 static inline struct global_resource_tag cvmx_get_gr_tag(char a, char b, char c, char d, char e,
83 char f, char g, char h, char i, char j,
84 char k, char l, char m, char n, char o,
87 struct global_resource_tag tag;
89 tag.lo = TAG_INIT_PART(a, b, c, d, e, f, g, h);
90 tag.hi = TAG_INIT_PART(i, j, k, l, m, n, o, p);
94 static inline int cvmx_gr_same_tag(struct global_resource_tag gr1, struct global_resource_tag gr2)
96 return (gr1.hi == gr2.hi) && (gr1.lo == gr2.lo);
101 * Creates a global resource range that can hold the specified number of
103 * @param tag is the tag of the range. The taga is created using the method
105 * @param nelements is the number of elements to be held in the resource range.
107 int cvmx_create_global_resource_range(struct global_resource_tag tag, int nelements);
111 * Allocate nelements in the global resource range with the specified tag. It
112 * is assumed that prior
113 * to calling this the global resource range has already been created using
114 * cvmx_create_global_resource_range().
115 * @param tag is the tag of the global resource range.
116 * @param nelements is the number of elements to be allocated.
117 * @param owner is a 64 bit number that identifes the owner of this range.
118 * @aligment specifes the required alignment of the returned base number.
119 * Return: returns the base of the allocated range. -1 return value indicates
122 int cvmx_allocate_global_resource_range(struct global_resource_tag tag, u64 owner, int nelements,
127 * Allocate nelements in the global resource range with the specified tag.
128 * The elements allocated need not be contiguous. It is assumed that prior to
129 * calling this the global resource range has already
130 * been created using cvmx_create_global_resource_range().
131 * @param tag is the tag of the global resource range.
132 * @param nelements is the number of elements to be allocated.
133 * @param owner is a 64 bit number that identifes the owner of the allocated
135 * @param allocated_elements returns indexs of the allocated entries.
136 * Return: returns 0 on success and -1 on failure.
138 int cvmx_resource_alloc_many(struct global_resource_tag tag, u64 owner, int nelements,
139 int allocated_elements[]);
140 int cvmx_resource_alloc_reverse(struct global_resource_tag, u64 owner);
143 * Reserve nelements starting from base in the global resource range with the
145 * It is assumed that prior to calling this the global resource range has
146 * already been created using cvmx_create_global_resource_range().
147 * @param tag is the tag of the global resource range.
148 * @param nelements is the number of elements to be allocated.
149 * @param owner is a 64 bit number that identifes the owner of this range.
150 * @base specifies the base start of nelements.
151 * Return: returns the base of the allocated range. -1 return value indicates
154 int cvmx_reserve_global_resource_range(struct global_resource_tag tag, u64 owner, int base,
158 * Free nelements starting at base in the global resource range with the
160 * @param tag is the tag of the global resource range.
161 * @param base is the base number
162 * @param nelements is the number of elements that are to be freed.
163 * Return: returns 0 if successful and -1 on failure.
165 int cvmx_free_global_resource_range_with_base(struct global_resource_tag tag, int base,
170 * Free nelements with the bases specified in bases[] with the
172 * @param tag is the tag of the global resource range.
173 * @param bases is an array containing the bases to be freed.
174 * @param nelements is the number of elements that are to be freed.
175 * Return: returns 0 if successful and -1 on failure.
177 int cvmx_free_global_resource_range_multiple(struct global_resource_tag tag, int bases[],
181 * Free elements from the specified owner in the global resource range with the
183 * @param tag is the tag of the global resource range.
184 * @param owner is the owner of resources that are to be freed.
185 * Return: returns 0 if successful and -1 on failure.
187 int cvmx_free_global_resource_range_with_owner(struct global_resource_tag tag, int owner);
191 * Frees all the global resources that have been created.
192 * For use only from the bootloader, when it shutdown and boots up the
193 * application or kernel.
195 int free_global_resources(void);
197 u64 cvmx_get_global_resource_owner(struct global_resource_tag tag, int base);
200 * Shows the global resource range with the specified tag. Use mainly for debug.
202 void cvmx_show_global_resource_range(struct global_resource_tag tag);
206 * Shows all the global resources. Used mainly for debug.
208 void cvmx_global_resources_show(void);
210 u64 cvmx_allocate_app_id(void);
211 u64 cvmx_get_app_id(void);