aboutsummaryrefslogtreecommitdiff
path: root/module/resource_perms/include/mod_resource_perms.h
blob: 0a1284d9581768373332d2681e8c2900362299e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
/*
 * Arm SCP/MCP Software
 * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 *
 * Description:
 *     System Control and Management Interface (SCMI)
 *      Resource Management Support.
 */

#ifndef MOD_SCMI_RESOURCE_PERMISSIONS_H
#define MOD_SCMI_RESOURCE_PERMISSIONS_H

#include <mod_scmi_std.h>

#include <fwk_assert.h>
#include <fwk_id.h>
#include <fwk_status.h>

#include <stdint.h>

/*
 * We will use type uint16_t to track the resources.
 */
typedef uint16_t mod_res_perms_t;

#define MOD_RES_PERMS_TYPE_BITS (sizeof(mod_res_perms_t) * CHAR_BIT)
#define MOD_RES_PERMS_TYPE_SHIFT (4)
#define MOD_RES_PERMS_TYPE_MASK ((1 << MOD_RES_PERMS_TYPE_SHIFT) - 1)

/*! Find the array element for the resource */
#define MOD_RES_PERMS_RESOURCE_ELEMENT(resource_id) \
    (resource_id >> MOD_RES_PERMS_TYPE_SHIFT)

/*! Find the bit in the array element for the resource */
#define MOD_RES_PERMS_RESOURCE_BIT(resource_id) \
    (resource_id & MOD_RES_PERMS_TYPE_MASK)

/*!
 * \brief Bits to set to deny Protocol permissions. Note that the default
 *        throughout is to allow access to a Protocol:Message:Resource.
 */
enum mod_res_perms_permissions {
    MOD_RES_PERMS_ACCESS_ALLOWED = 0,
    MOD_RES_PERMS_ACCESS_DENIED = 1,
};

#define MOD_RES_PERMS_PROTOCOL_OFFSET MOD_SCMI_PROTOCOL_ID_BASE

enum mod_res_perms_protocol_deny {
    MOD_RES_PERMS_SCMI_ALL_PROTOCOLS_ALLOWED = 0,
    MOD_RES_PERMS_SCMI_BASE_PROTOCOL_DENIED = MOD_RES_PERMS_ACCESS_DENIED
        << (MOD_SCMI_PROTOCOL_ID_BASE - MOD_RES_PERMS_PROTOCOL_OFFSET),
    MOD_RES_PERMS_SCMI_CLOCK_PROTOCOL_DENIED = MOD_RES_PERMS_ACCESS_DENIED
        << (MOD_SCMI_PROTOCOL_ID_CLOCK - MOD_RES_PERMS_PROTOCOL_OFFSET),
    MOD_RES_PERMS_SCMI_SYS_POWER_PROTOCOL_DENIED = MOD_RES_PERMS_ACCESS_DENIED
        << (MOD_SCMI_PROTOCOL_ID_SYS_POWER - MOD_RES_PERMS_PROTOCOL_OFFSET),
    MOD_RES_PERMS_SCMI_POWER_DOMAIN_DENIED = MOD_RES_PERMS_ACCESS_DENIED
        << (MOD_SCMI_PROTOCOL_ID_POWER_DOMAIN - MOD_RES_PERMS_PROTOCOL_OFFSET),
    MOD_RES_PERMS_SCMI_PERF_PROTOCOL_DENIED = MOD_RES_PERMS_ACCESS_DENIED
        << (MOD_SCMI_PROTOCOL_ID_PERF - MOD_RES_PERMS_PROTOCOL_OFFSET),
    MOD_RES_PERMS_SCMI_SENSOR_PROTOCOL_DENIED = MOD_RES_PERMS_ACCESS_DENIED
        << (MOD_SCMI_PROTOCOL_ID_SENSOR - MOD_RES_PERMS_PROTOCOL_OFFSET),
    MOD_RES_PERMS_SCMI_RESET_DOMAIN_PROTOCOL_DENIED =
        MOD_RES_PERMS_ACCESS_DENIED
        << (MOD_SCMI_PROTOCOL_ID_RESET_DOMAIN - MOD_RES_PERMS_PROTOCOL_OFFSET),
};

/*!
 * \brief Bitmask of the protocols disabled for the agent.
 */
struct mod_res_agent_protocol_permissions {
    /*!
     * \details This bitmask specifies which protocols are DISABLED for this
     * agent. If a bit is set that agent does NOT have permission to
     * use the protocol.
     */
    mod_res_perms_t protocols;
};

/*!
 * \brief Bits to set to deny Message permissions. Note that the default
 *        throughout is to allow access to a Message:Resource.
 */
#define MOD_RES_PERMS_MESSAGE_OFFSET MOD_SCMI_PROTOCOL_ID_BASE

enum mod_res_perms_message_idx {
    MOD_RES_PERMS_SCMI_BASE_MESSAGE_IDX =
        MOD_SCMI_PROTOCOL_ID_BASE - MOD_RES_PERMS_MESSAGE_OFFSET,
    MOD_RES_PERMS_SCMI_CLOCK_MESSAGE_IDX =
        MOD_SCMI_PROTOCOL_ID_CLOCK - MOD_RES_PERMS_MESSAGE_OFFSET,
    MOD_RES_PERMS_SCMI_SYS_POWER_MESSAGE_IDX =
        MOD_SCMI_PROTOCOL_ID_SYS_POWER - MOD_RES_PERMS_MESSAGE_OFFSET,
    MOD_RES_PERMS_SCMI_POWER_DOMAIN_MESSAGE_IDX =
        MOD_SCMI_PROTOCOL_ID_POWER_DOMAIN - MOD_RES_PERMS_MESSAGE_OFFSET,
    MOD_RES_PERMS_SCMI_PERF_MESSAGE_IDX =
        MOD_SCMI_PROTOCOL_ID_PERF - MOD_RES_PERMS_MESSAGE_OFFSET,
    MOD_RES_PERMS_SCMI_SENSOR_MESSAGE_IDX =
        MOD_SCMI_PROTOCOL_ID_SENSOR - MOD_RES_PERMS_MESSAGE_OFFSET,
    MOD_RES_PERMS_SCMI_RESET_DOMAIN_MESSAGE_IDX =
        MOD_SCMI_PROTOCOL_ID_RESET_DOMAIN - MOD_RES_PERMS_MESSAGE_OFFSET,
};

/*!
 * \brief Bits to set when denying message permissions. The
 *      VERSION/ATTRIBUTES/MSG_ATTRIBUTES messages are available to all
 *      agents. The message bits for each protocol are defined as
 *      offsets from the corresponding base index.
 */
enum mod_res_perms_message_bitmask_base {
    MOD_RES_PERMS_SCMI_BASE_BITMASK_IDX = MOD_SCMI_BASE_NOTIFY_ERRORS,
    MOD_RES_PERMS_SCMI_CLOCK_BITMASK_IDX = MOD_SCMI_CLOCK_ATTRIBUTES,
    MOD_RES_PERMS_SCMI_SYS_POWER_BITMASK_IDX = MOD_SCMI_SYS_POWER_STATE_SET,
    MOD_RES_PERMS_SCMI_POWER_DOMAIN_BITMASK_IDX =
        MOD_SCMI_PD_POWER_DOMAIN_ATTRIBUTES,
    MOD_RES_PERMS_SCMI_PERF_BITMASK_IDX = MOD_SCMI_PERF_DOMAIN_ATTRIBUTES,
    MOD_RES_PERMS_SCMI_SENSOR_BITMASK_IDX = MOD_SCMI_SENSOR_DESCRIPTION_GET,
    MOD_RES_PERMS_SCMI_RESET_DOMAIN_BITMASK_IDX =
        MOD_SCMI_RESET_DOMAIN_ATTRIBUTES,
};

/*!
 * \brief Bitmask of the messages for each protocol disabled for
 *      the agent. Currently we have 8 SCMI protocols.
 */
struct mod_res_agent_msg_permissions {
    /*! \details Bitmask of the disabled messages for each protocol. */
    mod_res_perms_t messages[8];
};

/*!
 * \brief Bitmask of the resources for each protocol:command disabled for
 * the agent.
 *
 * \details Each protocol will manage a unique number of commands, so
 * we specify different size tables.
 *
 * If the permissions table is not set then the agent is deemed
 * to be allowed access that protocol:command:resource. They will
 * be checked in order protocol->command->resource.
 *
 * In order for a protocol to be disabled for an agent, the
 * bit must be SET in the agent_protocol_permissions table.
 *
 * In order for a command to be disabled for an agent, the
 * bit must be SET in the agent_cmd_permissions table.
 *
 * In order for a resource to be disabled for an agent, the
 * bit must be SET in the agent_permission table.
 *
 * \note The VERSION/ATTRIBUTES/MSG_ATTRIBUTES commands
 * are available to all agents.
 *
 * \note The BASE and SYSTEM_POWER protocols are managed by
 *      agent:protocol:command, there are no resource
 *      permissions associated with these protocols.
 *
 */

/*!
 * \brief SCMI Clock Protocol Message index offset
 */
#define MOD_RES_PERMS_CLOCK_PERMS_OFFSET MOD_SCMI_CLOCK_ATTRIBUTES

/*!
 * \brief SCMI Clock Protocol Message Indices
 */
enum mod_res_clock_permissions_idx {
    MOD_RES_PERMS_SCMI_CLOCK_ATTRIBUTES_IDX =
        MOD_SCMI_CLOCK_ATTRIBUTES - MOD_RES_PERMS_CLOCK_PERMS_OFFSET,
    MOD_RES_PERMS_SCMI_CLOCK_DESCRIBE_RATE_IDX =
        MOD_SCMI_CLOCK_DESCRIBE_RATES - MOD_RES_PERMS_CLOCK_PERMS_OFFSET,
    MOD_RES_PERMS_SCMI_CLOCK_RATE_SET_IDX =
        MOD_SCMI_CLOCK_RATE_SET - MOD_RES_PERMS_CLOCK_PERMS_OFFSET,
    MOD_RES_PERMS_SCMI_CLOCK_RATE_GET_IDX =
        MOD_SCMI_CLOCK_RATE_GET - MOD_RES_PERMS_CLOCK_PERMS_OFFSET,
    MOD_RES_PERMS_SCMI_CLOCK_CONFIG_SET_IDX =
        MOD_SCMI_CLOCK_CONFIG_SET - MOD_RES_PERMS_CLOCK_PERMS_OFFSET,
};

/*!
 * \brief SCMI Power Domain Protocol Message index offset
 */
#define MOD_RES_PERMS_POWER_DOMAIN_PERMS_OFFSET \
    MOD_SCMI_PD_POWER_DOMAIN_ATTRIBUTES

/*!
 * \brief SCMI Power Domain Protocol Message Indices
 */
enum mod_res_power_domain_permissions_idx {
    MOD_RES_PERMS_SCMI_POWER_DOMAIN_ATTRIBUTES_IDX =
        MOD_SCMI_PD_POWER_DOMAIN_ATTRIBUTES -
        MOD_RES_PERMS_POWER_DOMAIN_PERMS_OFFSET,
    MOD_RES_PERMS_SCMI_POWER_DOMAIN_STATE_SET_IDX =
        MOD_SCMI_PD_POWER_STATE_SET - MOD_RES_PERMS_POWER_DOMAIN_PERMS_OFFSET,
    MOD_RES_PERMS_SCMI_POWER_DOMAIN_STATE_GET_IDX =
        MOD_SCMI_PD_POWER_STATE_GET - MOD_RES_PERMS_POWER_DOMAIN_PERMS_OFFSET,
    MOD_RES_PERMS_SCMI_POWER_DOMAIN_STATE_NOTIFY_IDX =
        MOD_SCMI_PD_POWER_STATE_NOTIFY -
        MOD_RES_PERMS_POWER_DOMAIN_PERMS_OFFSET,
};

/*!
 * \brief SCMI Performance Protocol Message index offset
 */
#define MOD_RES_PERMS_PERF_PERMS_OFFSET MOD_SCMI_PERF_DOMAIN_ATTRIBUTES

/*!
 * \brief SCMI Performance Protocol Message Indices
 */
enum mod_res_perf_permissions_idx {
    MOD_RES_PERMS_SCMI_PERF_ATTRIBUTES_IDX =
        MOD_SCMI_PERF_DOMAIN_ATTRIBUTES - MOD_RES_PERMS_PERF_PERMS_OFFSET,
    MOD_RES_PERMS_SCMI_PERF_DESCRIBE_LEVELS_IDX =
        MOD_SCMI_PERF_DESCRIBE_LEVELS - MOD_RES_PERMS_PERF_PERMS_OFFSET,
    MOD_RES_PERMS_SCMI_PERF_LIMITS_SET_IDX =
        MOD_SCMI_PERF_LIMITS_SET - MOD_RES_PERMS_PERF_PERMS_OFFSET,
    MOD_RES_PERMS_SCMI_PERF_LIMITS_GET_IDX =
        MOD_SCMI_PERF_LIMITS_GET - MOD_RES_PERMS_PERF_PERMS_OFFSET,
    MOD_RES_PERMS_SCMI_PERF_LEVEL_SET_IDX =
        MOD_SCMI_PERF_LEVEL_SET - MOD_RES_PERMS_PERF_PERMS_OFFSET,
    MOD_RES_PERMS_SCMI_PERF_LEVEL_GET_IDX =
        MOD_SCMI_PERF_LEVEL_GET - MOD_RES_PERMS_PERF_PERMS_OFFSET,
    MOD_RES_PERMS_SCMI_PERF_NOTIFY_LIMITS_IDX =
        MOD_SCMI_PERF_NOTIFY_LIMITS - MOD_RES_PERMS_PERF_PERMS_OFFSET,
    MOD_RES_PERMS_SCMI_PERF_NOTIFY_LEVEL_IDX =
        MOD_SCMI_PERF_NOTIFY_LEVEL - MOD_RES_PERMS_PERF_PERMS_OFFSET,
    MOD_RES_PERMS_SCMI_PERF_DESCRIBE_FAST_CHANNEL_IDX =
        MOD_SCMI_PERF_DESCRIBE_FAST_CHANNEL - MOD_RES_PERMS_PERF_PERMS_OFFSET,
};

/*!
 * \brief SCMI Sensor Protocol Message index offset
 */
#define MOD_RES_PERMS_SENSOR_PERMS_OFFSET MOD_SCMI_SENSOR_DESCRIPTION_GET

/*!
 * \brief SCMI Sensor Protocol Message Indices
 */
enum mod_res_sensor_permissions_idx {
    MOD_RES_PERMS_SCMI_SENSOR_DESCRIPTION_GET_IDX =
        MOD_SCMI_PERF_DOMAIN_ATTRIBUTES - MOD_RES_PERMS_SENSOR_PERMS_OFFSET,
    MOD_RES_PERMS_SCMI_SENSOR_CONFIG_SET_IDX =
        MOD_SCMI_SENSOR_CONFIG_SET - MOD_RES_PERMS_SENSOR_PERMS_OFFSET,
    MOD_RES_PERMS_SCMI_SENSOR_TRIP_POINT_SET_IDX =
        MOD_SCMI_SENSOR_TRIP_POINT_SET - MOD_RES_PERMS_SENSOR_PERMS_OFFSET,
    MOD_RES_PERMS_SCMI_SENSOR_READING_GET_IDX =
        MOD_SCMI_SENSOR_READING_GET - MOD_RES_PERMS_SENSOR_PERMS_OFFSET,
};

/*!
 * \brief SCMI Reset Domain Management Protocol Message index offset
 */
#define MOD_RES_PERMS_RESET_DOMAIN_PERMS_OFFSET MOD_SCMI_RESET_DOMAIN_ATTRIBUTES

/*!
 * \brief SCMI Reset Domain Management Protocol Message Indices
 */
enum mod_res_reset_domain_permissions_idx {
    MOD_RES_PERMS_SCMI_RESET_DOMAIN_ATTRIBUTES_IDX =
        MOD_SCMI_RESET_DOMAIN_ATTRIBUTES -
        MOD_RES_PERMS_RESET_DOMAIN_PERMS_OFFSET,
    MOD_RES_PERMS_SCMI_RESET_DOMAIN_RESET_REQUEST_IDX =
        MOD_SCMI_RESET_REQUEST - MOD_RES_PERMS_RESET_DOMAIN_PERMS_OFFSET,
    MOD_RES_PERMS_SCMI_RESET_DOMAIN_RESET_NOTIFY_IDX =
        MOD_SCMI_RESET_NOTIFY - MOD_RES_PERMS_RESET_DOMAIN_PERMS_OFFSET,
};

/*!
 * \brief SCMI Domain Types
 */
enum mod_res_domain_device_types {
    MOD_RES_POWER_DOMAIN_DEVICE = 0,
    MOD_RES_PERF_DOMAIN_DEVICE,
    MOD_RES_CLOCK_DOMAIN_DEVICE,
    MOD_RES_SENSOR_DOMAIN_DEVICE,
    MOD_RES_RESET_DOMAIN_DEVICE,
    MOD_RES_PLATFORM_DOMAIN_DEVICE,
    MOD_RES_DOMAIN_DEVICE_INVALID
};

/*!
 * \brief Each device is made up multiple domain devices.
 *      The protocol is determined by the device type.
 *      The resource ID for a protocol is the element ID of the
 *      device_id.
 */
struct mod_res_domain_device {
    /*! \brief Identifier of the domain device instance */
    fwk_id_t device_id;

    /*! \brief Type of the domain device instance */
    enum mod_res_domain_device_types type;
};

/*!
 * \brief Device definition.
 */
struct mod_res_device {
    /*! \brief Device Identifier */
    uint16_t device_id;

    /*! \brief List of domain devices in the device */
    struct mod_res_domain_device *domain_devices;
};

/*!
 * \brief SCMI Agent Permissions
 *
 * \details An agent may have any combination of the permissions
 *      tables set.
 */
struct mod_res_agent_permission {
    /*! \brief  Protocol permissions. */
    struct mod_res_agent_protocol_permissions *agent_protocol_permissions;

    /*! \brief Protocol:Message permissions. */
    struct mod_res_agent_msg_permissions *agent_msg_permissions;

    /*! \brief Power Domain:Resource permissions. */
    mod_res_perms_t *scmi_pd_perms;

    /*! Performance:Resource permissions. */
    mod_res_perms_t *scmi_perf_perms;

    /*! \brief Clock:Resource permissions. */
    mod_res_perms_t *scmi_clock_perms;

    /*! \brief Sensor:Resource permissions. */
    mod_res_perms_t *scmi_sensor_perms;

#ifdef BUILD_HAS_SCMI_RESET
    /*! \brief Reset Domain:Resource permissions. */
    mod_res_perms_t *scmi_reset_domain_perms;
#endif
};

/*!
 * \brief Type of the interfaces exposed by the resource permissions module.
 */
enum mod_res_perms_api_idx {
    MOD_RES_PERM_RESOURCE_PERMS,
    MOD_RES_PERM_API_IDX_COUNT,
};

/*!
 * \brief Interfaces exposed by the resource permissions module.
 */
struct mod_res_permissions_api {
    /*!
     * \brief Check whether the agent has permission to access a protocol.
     *
     * \param agent_id      identifier of the agent.
     * \param protocol_id   identifier of the protocol.
     *
     * \retval MOD_RES_PERMS_ACCESS_ALLOWED The agent has permissions to
     *      use the protocol.
     * \retval MOD_RES_PERMS_ACCESS_DENIED The agent does not have
     *      permissions to use the protocol.
     */
    enum mod_res_perms_permissions (*agent_has_protocol_permission)(
        uint32_t agent_id,
        uint32_t protocol_id);

    /*!
     * \brief Check whether the agent has permission to access a message.
     *
     * \param agent_id      identifier of the agent.
     * \param protocol_id   identifier of the protocol.
     * \param message_id    identifier of the message.
     *
     * \retval MOD_RES_PERMS_ACCESS_ALLOWED The agent has permissions to
     *      use the protocol.
     * \retval MOD_RES_PERMS_ACCESS_DENIED The agent does not have
     *      permissions to use the message.
     */
    enum mod_res_perms_permissions (*agent_has_message_permission)(
        uint32_t agent_id,
        uint32_t protocol_id,
        uint32_t message_id);

    /*!
     * \brief Check whether the agent has permission to access a resource.
     *
     * \param agent_id      identifier of the agent.
     * \param protocol_id   identifier of the protocol.
     * \param message_id    identifier of the message.
     * \param resource_id   identifier of the resource.
     *
     * \retval MOD_RES_PERMS_ACCESS_ALLOWED The agent has permissions to
     *      use the protocol.
     * \retval MOD_RES_PERMS_ACCESS_DENIED The agent does not have
     *      permissions to use the resource.
     */
    enum mod_res_perms_permissions (*agent_has_resource_permission)(
        uint32_t agent_id,
        uint32_t protocol_id,
        uint32_t message_id,
        uint32_t resource_id);

    /*!
     * \brief Set device permissions for an agent
     *
     * \param agent_id      identifier of the agent.
     * \param device_id     identifier of the device.
     * \param flags         permissions to set.
     *
     * \retval FWK_SUCCESS  The operation has completed successfully.
     * \retval FWK_E_PARAM  Unknown agent_id or device_id.
     * \retval FWK_E_INVAL  Invalid flags.
     */
    int (*agent_set_device_permission)(
        uint32_t agent_id,
        uint32_t device_id,
        uint32_t flags);

    /*!
     * \brief Set device protocol permissions for an agent
     *
     * \param agent_id      identifier of the agent.
     * \param device_id     identifier of the device.
     * \param device_id     identifier of the protocol.
     * \param flags         permissions to set.
     *
     * \retval FWK_SUCCESS  The operation has completed successfully.
     * \retval FWK_E_PARAM  Unknown agent_id or device_id.
     * \retval FWK_E_INVAL  Invalid flags or protocol_ID.
     */
    int (*agent_set_device_protocol_permission)(
        uint32_t agent_id,
        uint32_t device_id,
        uint32_t protocol_id,
        uint32_t flags);

    /*!
     * \brief Reset permissions for an agent
     *
     * \param agent_id      identifier of the agent.
     * \param flags         permissions to set.
     *
     * \retval FWK_SUCCESS  The operation has completed successfully.
     * \retval FWK_E_PARAM  Unknown agent_id.
     * \retval FWK_E_INVAL  Invalid flags.
     */
    int (*agent_reset_config)(uint32_t agent_id, uint32_t flags);
};

/*!
 * \brief Resource Permissions module configuration data.
 *
 * \note If the agent_permissions table is not set in the config then no
 *      resource permissions are implemented.
 */
struct mod_res_resource_perms_config {
    /*! \brief Number of agents on the platform. */
    uint32_t agent_count;

    /*! \brief Number of SCMI protocols supported by the platform. */
    uint32_t protocol_count;

    /*! \brief Number of clocks supported by the platform. */
    uint32_t clock_count;

    /*! \brief Number of sensors supported by the platform. */
    uint32_t sensor_count;

    /*! \brief Number of power domains supported by the platform. */
    uint32_t pd_count;

    /*! \brief Number of performance domains supported by the platform. */
    uint32_t perf_count;

#ifdef BUILD_HAS_SCMI_RESET
    /*! \brief Number of reset domains supported by the platform. */
    uint32_t reset_domain_count;
#endif

    /*! \brief Number of devices supported by the platform. */
    uint32_t device_count;

    /*! \brief Address of the permissions table */
    uintptr_t agent_permissions;

    /*! \brief Address of the domain devices */
    uintptr_t domain_devices;
};

/*!
 * \defgroup GroupResPerms Mapping
 *
 * \brief Resource Permissions Identifier Mapping.
 *
 * \details The Resource Permissions Identifier Checkin and Mapping functions
 *      are weak definitions to allow a platform to implement a function
 *      for mapping agent IDs, SCMI protocol IDs and SCMI Message IDs
 *      appropriate to that platform. The permissons checking functions
 *      may also be implemented. The Resource Permissions Identifier
 *      Mapping/Checking functions may be overridden in the
 *      `product/<platform>/src` directory.
 *      This may be useful for platforms with non-contiguous or
 *      platform-specific agent:protocol:command identifiers.
 *
 * \{
 */

/*!
 * \brief Resource Permissions Map Agent ID to index.
 *
 * \details This function maps an Agent ID to an index in the
 *      resource permissions table.
 *
 *      The Resource Permissions Mapping handlers have default
 *      weak implementations that allow a platform to implement
 *      a policy appropriate for that platform.
 *
 * \param[out] agent_idx Index for agent.
 * \param[in] agent_id Identifier of the agent.
 *
 * \retval ::FWK_SUCCESS The operation succeeded.
 *
 * \return Status code representing the result of the operation.
 */
int mod_res_agent_id_to_index(uint32_t agent_id, uint32_t *agent_idx);

/*!
 * \brief Resource Permissions Map Protocol ID to index.
 *
 * \details This function maps an SCMI Protocol ID to an index in the
 *      resource permissions table.
 *
 *      The Resource Permissions Mapping handlers have default
 *      weak implementations that allow a platform to implement
 *      a policy appropriate for that platform.
 *
 * \param[out] protocol_idx Index for protocol.
 * \param[in] protocol_id Identifier of the Protocol.
 *
 * \retval ::FWK_SUCCESS The operation succeeded.
 *
 * \return Status code representing the result of the operation.
 */
int mod_res_plat_protocol_id_to_index(
    uint32_t protocol_id,
    uint32_t *protocol_idx);

/*!
 * \brief Resource Permissions Map Message ID to index.
 *
 * \details This function maps an SCMI Message ID to an index in the
 *      resource permissions table.
 *
 *      The Resource Permissions Mapping handlers have default
 *      weak implementations that allow a platform to implement
 *      a policy appropriate for that platform.
 *
 * \param[out] message_idx Index for message.
 * \param[in] protocol_id Identifier of the Protocol.
 * \param[in] message_id Identifier of the Message.
 *
 * \retval ::FWK_SUCCESS The operation succeeded.
 *
 * \return Status code representing the result of the operation.
 */
int mod_res_plat_message_id_to_index(
    uint32_t protocol_id,
    uint32_t message_id,
    int32_t *message_idx);

/*!
 * \brief Resource Permissions Map Resource ID to index.
 *
 * \details This function maps an SCMI Resource ID to an index in the
 *      resource permissions table.
 *
 *      The Resource Permissions Mapping handlers have default
 *      weak implementations that allow a platform to implement
 *      a policy appropriate for that platform.
 *
 * \param[out] resource_idx Index for resource.
 * \param[in] agent_id Identifier of the Agent.
 * \param[in] protocol_id Identifier of the Protocol.
 * \param[in] message_id Identifier of the Message.
 * \param[in] resource_id Identifier of the Resource.
 *
 * \retval ::FWK_SUCCESS The operation succeeded.
 *
 * \return Status code representing the result of the operation.
 */
int mod_res_plat_resource_id_to_index(
    uint32_t agent_id,
    uint32_t protocol_id,
    uint32_t message_id,
    uint32_t resource_id,
    int32_t *resource_idx);

/*!
 * \brief Check whether the agent has permission to access a protocol.
 *
 * \param agent_id      identifier of the agent.
 * \param protocol_id   identifier of the protocol.
 *
 * \retval MOD_RES_PERMS_ACCESS_ALLOWED The agent has permissions to
 *      use the protocol.
 * \retval MOD_RES_PERMS_ACCESS_DENIED The agent does not have
 *      permissions to use the protocol.
 */
enum mod_res_perms_permissions mod_res_plat_agent_protocol_permission(
    uint32_t agent_id,
    uint32_t protocol_id);

/*!
 * \brief Check whether the agent has permission to access a message.
 *
 * \param agent_id      identifier of the agent.
 * \param protocol_id   identifier of the protocol.
 * \param message_id    identifier of the message.
 *
 * \retval MOD_RES_PERMS_ACCESS_ALLOWED The agent has permissions to
 *      use the protocol.
 * \retval MOD_RES_PERMS_ACCESS_DENIED The agent does not have
 *      permissions to use the message.
 */
enum mod_res_perms_permissions mod_res_plat_agent_message_permission(
    uint32_t agent_id,
    uint32_t protocol_id,
    uint32_t message_id);

/*!
 * \brief Check whether the agent has permission to access a resource.
 *
 * \param agent_id      identifier of the agent.
 * \param protocol_id   identifier of the protocol.
 * \param message_id    identifier of the message.
 * \param resource_id   identifier of the resource.
 *
 * \retval MOD_RES_PERMS_ACCESS_ALLOWED The agent has permissions to
 *      use the protocol.
 * \retval MOD_RES_PERMS_ACCESS_DENIED The agent does not have
 *      permissions to use the resource.
 */
enum mod_res_perms_permissions mod_res_plat_agent_resource_permissions(
    uint32_t agent_id,
    uint32_t protocol_id,
    uint32_t message_id,
    uint32_t resource_id);

/*!
 * \}
 */

#endif /* MOD_SCMI_RESOURCE_PERMISSIONS_H */