blob: 4884a040e015dab9ecf70a01bf3191ef8fc6551a [file] [log] [blame]
Julian Hallead5b622021-11-23 17:31:07 +01001/*
2 * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <stddef.h>
8#include <protocols/rpc/common/packed-c/encoding.h>
9#include <service/smm_variable/provider/smm_variable_provider.h>
10#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;
33 rpc_session_handle nv_storage_session_handle;
34
35} smm_gateway_instance;
36
37
38static struct rpc_caller *locate_nv_store(void)
39{
40 int status = 0;
41 struct rpc_caller *caller = NULL;
42
43 /* todo - add option to use configurable service location */
44 smm_gateway_instance.nv_storage_service_context =
45 service_locator_query(SMM_GATEWAY_NV_STORE_SN, &status);
46
47 if (smm_gateway_instance.nv_storage_service_context) {
48
49 smm_gateway_instance.nv_storage_session_handle = service_context_open(
50 smm_gateway_instance.nv_storage_service_context,
51 TS_RPC_ENCODING_PACKED_C,
52 &caller);
53 }
54
55 return caller;
56}
57
58struct rpc_interface *smm_gateway_create(uint32_t owner_id)
59{
60 service_locator_init();
61
62 /* Initialize a storage client to access the remote NV store */
63 struct rpc_caller *nv_store_caller = locate_nv_store();
64 struct storage_backend *persistent_backend = secure_storage_client_init(
65 &smm_gateway_instance.nv_store_client,
66 nv_store_caller);
67
68 /* Initialize the volatile storage backend */
69 struct storage_backend *volatile_backend = mock_store_init(
70 &smm_gateway_instance.volatile_store);
71
72 /* Initialize the smm_variable service provider */
73 struct rpc_interface *service_iface = smm_variable_provider_init(
74 &smm_gateway_instance.smm_variable_provider,
75 owner_id,
76 SMM_GATEWAY_MAX_UEFI_VARIABLES,
77 persistent_backend,
78 volatile_backend);
79
80 return service_iface;
81}