blob: 329c8838bd5c2da60c2c6cceb116ba3c9168e740 [file] [log] [blame]
Julian Hallead5b622021-11-23 17:31:07 +01001/*
Julian Hall98656d52022-05-05 11:09:21 +01002 * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
Julian Hallead5b622021-11-23 17:31:07 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <stddef.h>
8#include <protocols/rpc/common/packed-c/encoding.h>
Julian Hall98656d52022-05-05 11:09:21 +01009#include <service/uefi/smm_variable/provider/smm_variable_provider.h>
Julian Hallead5b622021-11-23 17:31:07 +010010#include <service/secure_storage/backend/secure_storage_client/secure_storage_client.h>
11#include <service/secure_storage/backend/mock_store/mock_store.h>
12#include <service_locator.h>
13
14/* Build-time default configuration */
15
16/* Default to using the Protected Storage SP */
17#ifndef SMM_GATEWAY_NV_STORE_SN
18#define SMM_GATEWAY_NV_STORE_SN "sn:ffa:751bf801-3dde-4768-a514-0f10aeed1790:0"
19#endif
20
21/* Default maximum number of UEFI variables */
22#ifndef SMM_GATEWAY_MAX_UEFI_VARIABLES
23#define SMM_GATEWAY_MAX_UEFI_VARIABLES (40)
24#endif
25
26/* The smm_gateway instance - it's a singleton */
27static struct smm_gateway
28{
29 struct smm_variable_provider smm_variable_provider;
30 struct secure_storage_client nv_store_client;
31 struct mock_store volatile_store;
32 struct service_context *nv_storage_service_context;
Imre Kis64721422023-07-28 15:18:30 +020033 struct rpc_caller_session *nv_storage_session;
Julian Hallead5b622021-11-23 17:31:07 +010034
35} smm_gateway_instance;
36
37
Imre Kis64721422023-07-28 15:18:30 +020038struct rpc_service_interface *smm_gateway_create(uint32_t owner_id)
Julian Hallead5b622021-11-23 17:31:07 +010039{
Imre Kis64721422023-07-28 15:18:30 +020040 service_locator_envinit();
Julian Hallead5b622021-11-23 17:31:07 +010041
42 /* todo - add option to use configurable service location */
43 smm_gateway_instance.nv_storage_service_context =
Imre Kis64721422023-07-28 15:18:30 +020044 service_locator_query(SMM_GATEWAY_NV_STORE_SN);
Julian Hallead5b622021-11-23 17:31:07 +010045
Imre Kis64721422023-07-28 15:18:30 +020046 if (!smm_gateway_instance.nv_storage_service_context)
47 return NULL;
Julian Hallead5b622021-11-23 17:31:07 +010048
Imre Kis64721422023-07-28 15:18:30 +020049 smm_gateway_instance.nv_storage_session = service_context_open(
50 smm_gateway_instance.nv_storage_service_context);
Julian Hallead5b622021-11-23 17:31:07 +010051
Imre Kis64721422023-07-28 15:18:30 +020052 if (!smm_gateway_instance.nv_storage_session)
53 return NULL;
Julian Hallead5b622021-11-23 17:31:07 +010054
55 /* Initialize a storage client to access the remote NV store */
Julian Hallead5b622021-11-23 17:31:07 +010056 struct storage_backend *persistent_backend = secure_storage_client_init(
57 &smm_gateway_instance.nv_store_client,
Imre Kis64721422023-07-28 15:18:30 +020058 smm_gateway_instance.nv_storage_session);
59 if (!persistent_backend)
60 return NULL;
Julian Hallead5b622021-11-23 17:31:07 +010061
62 /* Initialize the volatile storage backend */
63 struct storage_backend *volatile_backend = mock_store_init(
64 &smm_gateway_instance.volatile_store);
Imre Kis64721422023-07-28 15:18:30 +020065 if (!volatile_backend)
66 return NULL;
Julian Hallead5b622021-11-23 17:31:07 +010067
68 /* Initialize the smm_variable service provider */
Imre Kis64721422023-07-28 15:18:30 +020069 struct rpc_service_interface *service_iface = smm_variable_provider_init(
Julian Hallead5b622021-11-23 17:31:07 +010070 &smm_gateway_instance.smm_variable_provider,
71 owner_id,
72 SMM_GATEWAY_MAX_UEFI_VARIABLES,
73 persistent_backend,
74 volatile_backend);
75
76 return service_iface;
77}