Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* Copyright (C) 2018-2019, Intel Corporation. */
0003 
0004 #ifndef _PLDMFW_H_
0005 #define _PLDMFW_H_
0006 
0007 #include <linux/list.h>
0008 #include <linux/firmware.h>
0009 
0010 #define PLDM_DEVICE_UPDATE_CONTINUE_AFTER_FAIL BIT(0)
0011 
0012 #define PLDM_STRING_TYPE_UNKNOWN    0
0013 #define PLDM_STRING_TYPE_ASCII      1
0014 #define PLDM_STRING_TYPE_UTF8       2
0015 #define PLDM_STRING_TYPE_UTF16      3
0016 #define PLDM_STRING_TYPE_UTF16LE    4
0017 #define PLDM_STRING_TYPE_UTF16BE    5
0018 
0019 struct pldmfw_record {
0020     struct list_head entry;
0021 
0022     /* List of descriptor TLVs */
0023     struct list_head descs;
0024 
0025     /* Component Set version string*/
0026     const u8 *version_string;
0027     u8 version_type;
0028     u8 version_len;
0029 
0030     /* Package Data length */
0031     u16 package_data_len;
0032 
0033     /* Bitfield of Device Update Flags */
0034     u32 device_update_flags;
0035 
0036     /* Package Data block */
0037     const u8 *package_data;
0038 
0039     /* Bitmap of components applicable to this record */
0040     unsigned long *component_bitmap;
0041     u16 component_bitmap_len;
0042 };
0043 
0044 /* Standard descriptor TLV identifiers */
0045 #define PLDM_DESC_ID_PCI_VENDOR_ID  0x0000
0046 #define PLDM_DESC_ID_IANA_ENTERPRISE_ID 0x0001
0047 #define PLDM_DESC_ID_UUID       0x0002
0048 #define PLDM_DESC_ID_PNP_VENDOR_ID  0x0003
0049 #define PLDM_DESC_ID_ACPI_VENDOR_ID 0x0004
0050 #define PLDM_DESC_ID_PCI_DEVICE_ID  0x0100
0051 #define PLDM_DESC_ID_PCI_SUBVENDOR_ID   0x0101
0052 #define PLDM_DESC_ID_PCI_SUBDEV_ID  0x0102
0053 #define PLDM_DESC_ID_PCI_REVISION_ID    0x0103
0054 #define PLDM_DESC_ID_PNP_PRODUCT_ID 0x0104
0055 #define PLDM_DESC_ID_ACPI_PRODUCT_ID    0x0105
0056 #define PLDM_DESC_ID_VENDOR_DEFINED 0xFFFF
0057 
0058 struct pldmfw_desc_tlv {
0059     struct list_head entry;
0060 
0061     const u8 *data;
0062     u16 type;
0063     u16 size;
0064 };
0065 
0066 #define PLDM_CLASSIFICATION_UNKNOWN     0x0000
0067 #define PLDM_CLASSIFICATION_OTHER       0x0001
0068 #define PLDM_CLASSIFICATION_DRIVER      0x0002
0069 #define PLDM_CLASSIFICATION_CONFIG_SW       0x0003
0070 #define PLDM_CLASSIFICATION_APP_SW      0x0004
0071 #define PLDM_CLASSIFICATION_INSTRUMENTATION 0x0005
0072 #define PLDM_CLASSIFICATION_BIOS        0x0006
0073 #define PLDM_CLASSIFICATION_DIAGNOSTIC_SW   0x0007
0074 #define PLDM_CLASSIFICATION_OS          0x0008
0075 #define PLDM_CLASSIFICATION_MIDDLEWARE      0x0009
0076 #define PLDM_CLASSIFICATION_FIRMWARE        0x000A
0077 #define PLDM_CLASSIFICATION_CODE        0x000B
0078 #define PLDM_CLASSIFICATION_SERVICE_PACK    0x000C
0079 #define PLDM_CLASSIFICATION_SOFTWARE_BUNDLE 0x000D
0080 
0081 #define PLDM_ACTIVATION_METHOD_AUTO     BIT(0)
0082 #define PLDM_ACTIVATION_METHOD_SELF_CONTAINED   BIT(1)
0083 #define PLDM_ACTIVATION_METHOD_MEDIUM_SPECIFIC  BIT(2)
0084 #define PLDM_ACTIVATION_METHOD_REBOOT       BIT(3)
0085 #define PLDM_ACTIVATION_METHOD_DC_CYCLE     BIT(4)
0086 #define PLDM_ACTIVATION_METHOD_AC_CYCLE     BIT(5)
0087 
0088 #define PLDMFW_COMPONENT_OPTION_FORCE_UPDATE        BIT(0)
0089 #define PLDMFW_COMPONENT_OPTION_USE_COMPARISON_STAMP    BIT(1)
0090 
0091 struct pldmfw_component {
0092     struct list_head entry;
0093 
0094     /* component identifier */
0095     u16 classification;
0096     u16 identifier;
0097 
0098     u16 options;
0099     u16 activation_method;
0100 
0101     u32 comparison_stamp;
0102 
0103     u32 component_size;
0104     const u8 *component_data;
0105 
0106     /* Component version string */
0107     const u8 *version_string;
0108     u8 version_type;
0109     u8 version_len;
0110 
0111     /* component index */
0112     u8 index;
0113 
0114 };
0115 
0116 /* Transfer flag used for sending components to the firmware */
0117 #define PLDM_TRANSFER_FLAG_START        BIT(0)
0118 #define PLDM_TRANSFER_FLAG_MIDDLE       BIT(1)
0119 #define PLDM_TRANSFER_FLAG_END          BIT(2)
0120 
0121 struct pldmfw_ops;
0122 
0123 /* Main entry point to the PLDM firmware update engine. Device drivers
0124  * should embed this in a private structure and use container_of to obtain
0125  * a pointer to their own data, used to implement the device specific
0126  * operations.
0127  */
0128 struct pldmfw {
0129     const struct pldmfw_ops *ops;
0130     struct device *dev;
0131 };
0132 
0133 bool pldmfw_op_pci_match_record(struct pldmfw *context, struct pldmfw_record *record);
0134 
0135 /* Operations invoked by the generic PLDM firmware update engine. Used to
0136  * implement device specific logic.
0137  *
0138  * @match_record: check if the device matches the given record. For
0139  * convenience, a standard implementation is provided for PCI devices.
0140  *
0141  * @send_package_data: send the package data associated with the matching
0142  * record to firmware.
0143  *
0144  * @send_component_table: send the component data associated with a given
0145  * component to firmware. Called once for each applicable component.
0146  *
0147  * @flash_component: Flash the data for a given component to the device.
0148  * Called once for each applicable component, after all component tables have
0149  * been sent.
0150  *
0151  * @finalize_update: (optional) Finish the update. Called after all components
0152  * have been flashed.
0153  */
0154 struct pldmfw_ops {
0155     bool (*match_record)(struct pldmfw *context, struct pldmfw_record *record);
0156     int (*send_package_data)(struct pldmfw *context, const u8 *data, u16 length);
0157     int (*send_component_table)(struct pldmfw *context, struct pldmfw_component *component,
0158                     u8 transfer_flag);
0159     int (*flash_component)(struct pldmfw *context, struct pldmfw_component *component);
0160     int (*finalize_update)(struct pldmfw *context);
0161 };
0162 
0163 int pldmfw_flash_image(struct pldmfw *context, const struct firmware *fw);
0164 
0165 #endif