blob: c442b2157856abefbd9d9aa5633cb5fbce6e3b3e [file] [log] [blame]
Arunachalam Ganapathyc58e4692025-01-28 12:28:59 +00001/*
2 * Copyright (c) 2025, Arm Limited. All rights reserved.
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include <assert.h>
7#include <stdlib.h>
8
9#include <realm_da_helpers.h>
10#include <realm_rsi.h>
11
12#include <arch.h>
13#include <arch_features.h>
14#include <arch_helpers.h>
15#include <debug.h>
16#include <host_shared_data.h>
17#include <sync.h>
18
Arunachalam Ganapathyc58e4692025-01-28 12:28:59 +000019static struct rdev gbl_rdev;
20
21/* Measurement parameters */
22static struct rsi_dev_measure_params gbl_rdev_meas_params
23__aligned(GRANULE_SIZE);
24
25/* RDEV info. decice type and attestation evidence digest */
26static struct rsi_dev_info gbl_rdev_info __aligned(GRANULE_SIZE);
27
Arunachalam Ganapathyc58e4692025-01-28 12:28:59 +000028/*
29 * If the Realm supports DA feature, this function calls series of RSI RDEV
30 * on the assigned device.
31 *
32 * Returns 'false' on success.
33 */
34bool test_realm_da_rsi_calls(void)
35{
36 struct rdev *rdev;
37 unsigned long rsi_rc;
38 u_register_t rsi_feature_reg0;
39 struct rsi_dev_measure_params *rdev_meas_params;
40 struct rsi_dev_info *rdev_info;
41
42 /* Check if RSI_FEATURES support DA */
43 rsi_rc = rsi_features(RSI_FEATURE_REGISTER_0_INDEX, &rsi_feature_reg0);
44 if (rsi_rc != RSI_SUCCESS) {
45 return false;
46 }
47
48 if (EXTRACT(RSI_FEATURE_REGISTER_0_DA, rsi_feature_reg0) !=
49 RSI_FEATURE_TRUE) {
50 realm_printf("RSI feature DA not supported for current Realm\n");
51 return false;
52 }
53
54 /* Get the global RDEV. Currently only one RDEV is supported */
55 rdev = &gbl_rdev;
56 rdev_meas_params = &gbl_rdev_meas_params;
57 rdev_info = &gbl_rdev_info;
58
59 rsi_rc = realm_rdev_init(rdev, RDEV_ID);
60 if (rdev == NULL) {
61 realm_printf("realm_rdev_init failed\n");
62 return false;
63 }
64
65 rsi_rc = realm_rsi_rdev_get_state(rdev);
66 if (rsi_rc != RSI_SUCCESS) {
67 return false;
68 }
69
70 /* Before lock get_measurement */
71 rsi_rc = realm_rsi_rdev_get_measurements(rdev, rdev_meas_params);
72 if (rsi_rc != RSI_SUCCESS) {
73 return false;
74 }
75
76 rsi_rc = realm_rsi_rdev_lock(rdev);
77 if (rsi_rc != RSI_SUCCESS) {
78 return false;
79 }
80
81 /* After lock get_measurement */
82 rsi_rc = realm_rsi_rdev_get_measurements(rdev, rdev_meas_params);
83 if (rsi_rc != RSI_SUCCESS) {
84 return false;
85 }
86
87 rsi_rc = realm_rsi_rdev_get_interface_report(rdev);
88 if (rsi_rc != RSI_SUCCESS) {
89 return false;
90 }
91
92 /* After meas and ifc_report, get device info */
93 rsi_rc = realm_rsi_rdev_get_info(rdev, rdev_info);
94 if (rsi_rc != RSI_SUCCESS) {
95 return false;
96 }
97
98 /*
99 * Get cached device attestation from Host and verify it with device
100 * attestation digest
101 */
102 (void)realm_verify_device_attestation(rdev, rdev_info);
103
104 rsi_rc = realm_rsi_rdev_start(rdev);
105 if (rsi_rc != RSI_SUCCESS) {
106 return false;
107 }
108
109 rsi_rc = realm_rsi_rdev_stop(rdev);
110 if (rsi_rc != RSI_SUCCESS) {
111 return false;
112 }
113
114 return true;
115}