Julian Hall | ead5b62 | 2021-11-23 17:31:07 +0100 | [diff] [blame] | 1 | /* |
Julian Hall | 98656d5 | 2022-05-05 11:09:21 +0100 | [diff] [blame] | 2 | * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved. |
Julian Hall | ead5b62 | 2021-11-23 17:31:07 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <stddef.h> |
| 8 | #include <protocols/rpc/common/packed-c/encoding.h> |
Julian Hall | 98656d5 | 2022-05-05 11:09:21 +0100 | [diff] [blame] | 9 | #include <service/uefi/smm_variable/provider/smm_variable_provider.h> |
Julian Hall | ead5b62 | 2021-11-23 17:31:07 +0100 | [diff] [blame] | 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 */ |
| 27 | static 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 Kis | 6472142 | 2023-07-28 15:18:30 +0200 | [diff] [blame] | 33 | struct rpc_caller_session *nv_storage_session; |
Julian Hall | ead5b62 | 2021-11-23 17:31:07 +0100 | [diff] [blame] | 34 | |
| 35 | } smm_gateway_instance; |
| 36 | |
| 37 | |
Imre Kis | 6472142 | 2023-07-28 15:18:30 +0200 | [diff] [blame] | 38 | struct rpc_service_interface *smm_gateway_create(uint32_t owner_id) |
Julian Hall | ead5b62 | 2021-11-23 17:31:07 +0100 | [diff] [blame] | 39 | { |
Imre Kis | 6472142 | 2023-07-28 15:18:30 +0200 | [diff] [blame] | 40 | service_locator_envinit(); |
Julian Hall | ead5b62 | 2021-11-23 17:31:07 +0100 | [diff] [blame] | 41 | |
| 42 | /* todo - add option to use configurable service location */ |
| 43 | smm_gateway_instance.nv_storage_service_context = |
Imre Kis | 6472142 | 2023-07-28 15:18:30 +0200 | [diff] [blame] | 44 | service_locator_query(SMM_GATEWAY_NV_STORE_SN); |
Julian Hall | ead5b62 | 2021-11-23 17:31:07 +0100 | [diff] [blame] | 45 | |
Imre Kis | 6472142 | 2023-07-28 15:18:30 +0200 | [diff] [blame] | 46 | if (!smm_gateway_instance.nv_storage_service_context) |
| 47 | return NULL; |
Julian Hall | ead5b62 | 2021-11-23 17:31:07 +0100 | [diff] [blame] | 48 | |
Imre Kis | 6472142 | 2023-07-28 15:18:30 +0200 | [diff] [blame] | 49 | smm_gateway_instance.nv_storage_session = service_context_open( |
| 50 | smm_gateway_instance.nv_storage_service_context); |
Julian Hall | ead5b62 | 2021-11-23 17:31:07 +0100 | [diff] [blame] | 51 | |
Imre Kis | 6472142 | 2023-07-28 15:18:30 +0200 | [diff] [blame] | 52 | if (!smm_gateway_instance.nv_storage_session) |
| 53 | return NULL; |
Julian Hall | ead5b62 | 2021-11-23 17:31:07 +0100 | [diff] [blame] | 54 | |
| 55 | /* Initialize a storage client to access the remote NV store */ |
Julian Hall | ead5b62 | 2021-11-23 17:31:07 +0100 | [diff] [blame] | 56 | struct storage_backend *persistent_backend = secure_storage_client_init( |
| 57 | &smm_gateway_instance.nv_store_client, |
Imre Kis | 6472142 | 2023-07-28 15:18:30 +0200 | [diff] [blame] | 58 | smm_gateway_instance.nv_storage_session); |
| 59 | if (!persistent_backend) |
| 60 | return NULL; |
Julian Hall | ead5b62 | 2021-11-23 17:31:07 +0100 | [diff] [blame] | 61 | |
| 62 | /* Initialize the volatile storage backend */ |
| 63 | struct storage_backend *volatile_backend = mock_store_init( |
| 64 | &smm_gateway_instance.volatile_store); |
Imre Kis | 6472142 | 2023-07-28 15:18:30 +0200 | [diff] [blame] | 65 | if (!volatile_backend) |
| 66 | return NULL; |
Julian Hall | ead5b62 | 2021-11-23 17:31:07 +0100 | [diff] [blame] | 67 | |
| 68 | /* Initialize the smm_variable service provider */ |
Imre Kis | 6472142 | 2023-07-28 15:18:30 +0200 | [diff] [blame] | 69 | struct rpc_service_interface *service_iface = smm_variable_provider_init( |
Julian Hall | ead5b62 | 2021-11-23 17:31:07 +0100 | [diff] [blame] | 70 | &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 | } |