blob: a0e812cd2bf595e7ecc3c19e56a2f8c14e7b0f7a [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
Arunachalam Ganapathyaedca162025-04-21 16:39:06 +010065 realm_printf("======================================\n");
66 realm_printf("Realm: Lock -> Accept -> Unlock device: (bdf: 0x%x)\n",
67 rdev->id);
68 realm_printf("======================================\n");
69
Arunachalam Ganapathyc58e4692025-01-28 12:28:59 +000070 rsi_rc = realm_rsi_rdev_get_state(rdev);
71 if (rsi_rc != RSI_SUCCESS) {
72 return false;
73 }
74
75 /* Before lock get_measurement */
76 rsi_rc = realm_rsi_rdev_get_measurements(rdev, rdev_meas_params);
77 if (rsi_rc != RSI_SUCCESS) {
78 return false;
79 }
80
81 rsi_rc = realm_rsi_rdev_lock(rdev);
82 if (rsi_rc != RSI_SUCCESS) {
83 return false;
84 }
85
86 /* After lock get_measurement */
87 rsi_rc = realm_rsi_rdev_get_measurements(rdev, rdev_meas_params);
88 if (rsi_rc != RSI_SUCCESS) {
89 return false;
90 }
91
92 rsi_rc = realm_rsi_rdev_get_interface_report(rdev);
93 if (rsi_rc != RSI_SUCCESS) {
94 return false;
95 }
96
97 /* After meas and ifc_report, get device info */
98 rsi_rc = realm_rsi_rdev_get_info(rdev, rdev_info);
99 if (rsi_rc != RSI_SUCCESS) {
100 return false;
101 }
102
103 /*
104 * Get cached device attestation from Host and verify it with device
105 * attestation digest
106 */
107 (void)realm_verify_device_attestation(rdev, rdev_info);
108
109 rsi_rc = realm_rsi_rdev_start(rdev);
110 if (rsi_rc != RSI_SUCCESS) {
111 return false;
112 }
113
114 rsi_rc = realm_rsi_rdev_stop(rdev);
115 if (rsi_rc != RSI_SUCCESS) {
116 return false;
117 }
118
119 return true;
120}