[Skiboot] [PATCH 19/19] core/pldm: Get file handle and file length
Christophe Lombard
clombard at linux.vnet.ibm.com
Sat Feb 26 01:28:48 AEDT 2022
Retrieve the file handle and file length based on attribute name.
Signed-off-by: Christophe Lombard <clombard at linux.vnet.ibm.com>
---
core/pldm/pldm-file-io-requests.c | 91 +++++++++++++++++++++++++++++++
core/pldm/pldm.h | 3 +
2 files changed, 94 insertions(+)
diff --git a/core/pldm/pldm-file-io-requests.c b/core/pldm/pldm-file-io-requests.c
index 04880124..e09cd59a 100644
--- a/core/pldm/pldm-file-io-requests.c
+++ b/core/pldm/pldm-file-io-requests.c
@@ -33,6 +33,97 @@ static void file_io_init_complete(bool success)
file_io_ready = true;
}
+#define CHKSUM_PADDING 8
+
+/*
+ * Retrieve the file handle and file length from the file attribute
+ * table.
+ */
+static int find_file_handle_by_lid_name(uint32_t *file_handle,
+ uint32_t *file_length,
+ char *lid_name)
+{
+ const struct pldm_file_attr_table_entry *file_entry;
+ char *startptr, *endptr;
+ uint16_t file_name_length;
+
+ if ((file_attr_table == NULL) || (file_attr_length == 0))
+ return OPAL_PARAMETER;
+
+ startptr = (char *)file_attr_table;
+ endptr = startptr + file_attr_length - CHKSUM_PADDING;
+ *file_handle = 0;
+ *file_length = 0;
+
+ while (startptr < endptr) {
+ /* file entry:
+ * 4 Bytes: file handle
+ * 2 Bytes: file name length
+ * <file name length> Bytes: file name
+ * 4 Bytes: file length
+ */
+ file_entry = (struct pldm_file_attr_table_entry *)startptr;
+
+ *file_handle = le32_to_cpu(file_entry->file_handle);
+ startptr += sizeof(uint32_t);
+
+ file_name_length = le16_to_cpu(file_entry->file_name_length);
+ startptr += sizeof(file_name_length);
+
+ if (!strncmp(startptr, lid_name, strlen(lid_name))) {
+ startptr += file_name_length;
+ *file_length = le32_to_cpu(*(uint32_t *)startptr);
+ break;
+ }
+ startptr += file_name_length;
+ startptr += sizeof(uint32_t);
+ startptr += sizeof(bitfield32_t);
+ }
+
+ if (*file_length == 0) {
+ prlog(PR_ERR, "%s - No file handle found, lid_name: %s\n",
+ __func__, lid_name);
+ return OPAL_PARAMETER;
+ }
+
+ prlog(PR_DEBUG, "%s - lid_name: %s, file_handle: %d, file_length: %d\n",
+ __func__, lid_name, *file_handle, *file_length);
+
+ return OPAL_SUCCESS;
+}
+
+/*
+ * Retrieve the file handle and file length based on attribute name.
+ */
+int pldm_find_file_handle_by_attr_name(const char *name,
+ uint32_t *file_handle,
+ uint32_t *file_length)
+{
+ char *lid_name = NULL;
+ int rc;
+
+ if (!file_io_ready)
+ return OPAL_PARAMETER;
+
+ /* Read bios attributs to get lid name */
+ rc = pldm_bios_find_lid_by_attr_name(name, &lid_name);
+ if (rc)
+ goto out;
+
+ /* Search the file handle */
+ rc = find_file_handle_by_lid_name(file_handle,
+ file_length,
+ lid_name);
+ if (rc)
+ goto out;
+
+out:
+ if (lid_name)
+ free(lid_name);
+
+ return rc;
+}
+
/* maximum currently transfer size for PLDM */
#define KILOBYTE 1024ul
#define MAX_TRANSFER_SIZE_BYTES (127 * KILOBYTE + 1)
diff --git a/core/pldm/pldm.h b/core/pldm/pldm.h
index 78bdcc3a..d3b7cfd5 100644
--- a/core/pldm/pldm.h
+++ b/core/pldm/pldm.h
@@ -50,6 +50,9 @@ int pldm_rx_handle_request(struct pldm_rx_data *rx);
int pldm_mctp_responder_init(void);
/* Requester support */
+int pldm_find_file_handle_by_attr_name(const char *name,
+ uint32_t *file_handle,
+ uint32_t *file_length);
int pldm_file_io_read_file(uint32_t file_handle,
uint32_t file_length,
void *buf, uint32_t offset,
--
2.35.1
More information about the Skiboot
mailing list