pldmfw.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2018-2019, Intel Corporation. */
  3. #ifndef _PLDMFW_H_
  4. #define _PLDMFW_H_
  5. #include <linux/list.h>
  6. #include <linux/firmware.h>
  7. #define PLDM_DEVICE_UPDATE_CONTINUE_AFTER_FAIL BIT(0)
  8. #define PLDM_STRING_TYPE_UNKNOWN 0
  9. #define PLDM_STRING_TYPE_ASCII 1
  10. #define PLDM_STRING_TYPE_UTF8 2
  11. #define PLDM_STRING_TYPE_UTF16 3
  12. #define PLDM_STRING_TYPE_UTF16LE 4
  13. #define PLDM_STRING_TYPE_UTF16BE 5
  14. struct pldmfw_record {
  15. struct list_head entry;
  16. /* List of descriptor TLVs */
  17. struct list_head descs;
  18. /* Component Set version string*/
  19. const u8 *version_string;
  20. u8 version_type;
  21. u8 version_len;
  22. /* Package Data length */
  23. u16 package_data_len;
  24. /* Bitfield of Device Update Flags */
  25. u32 device_update_flags;
  26. /* Package Data block */
  27. const u8 *package_data;
  28. /* Bitmap of components applicable to this record */
  29. unsigned long *component_bitmap;
  30. u16 component_bitmap_len;
  31. };
  32. /* Standard descriptor TLV identifiers */
  33. #define PLDM_DESC_ID_PCI_VENDOR_ID 0x0000
  34. #define PLDM_DESC_ID_IANA_ENTERPRISE_ID 0x0001
  35. #define PLDM_DESC_ID_UUID 0x0002
  36. #define PLDM_DESC_ID_PNP_VENDOR_ID 0x0003
  37. #define PLDM_DESC_ID_ACPI_VENDOR_ID 0x0004
  38. #define PLDM_DESC_ID_PCI_DEVICE_ID 0x0100
  39. #define PLDM_DESC_ID_PCI_SUBVENDOR_ID 0x0101
  40. #define PLDM_DESC_ID_PCI_SUBDEV_ID 0x0102
  41. #define PLDM_DESC_ID_PCI_REVISION_ID 0x0103
  42. #define PLDM_DESC_ID_PNP_PRODUCT_ID 0x0104
  43. #define PLDM_DESC_ID_ACPI_PRODUCT_ID 0x0105
  44. #define PLDM_DESC_ID_VENDOR_DEFINED 0xFFFF
  45. struct pldmfw_desc_tlv {
  46. struct list_head entry;
  47. const u8 *data;
  48. u16 type;
  49. u16 size;
  50. };
  51. #define PLDM_CLASSIFICATION_UNKNOWN 0x0000
  52. #define PLDM_CLASSIFICATION_OTHER 0x0001
  53. #define PLDM_CLASSIFICATION_DRIVER 0x0002
  54. #define PLDM_CLASSIFICATION_CONFIG_SW 0x0003
  55. #define PLDM_CLASSIFICATION_APP_SW 0x0004
  56. #define PLDM_CLASSIFICATION_INSTRUMENTATION 0x0005
  57. #define PLDM_CLASSIFICATION_BIOS 0x0006
  58. #define PLDM_CLASSIFICATION_DIAGNOSTIC_SW 0x0007
  59. #define PLDM_CLASSIFICATION_OS 0x0008
  60. #define PLDM_CLASSIFICATION_MIDDLEWARE 0x0009
  61. #define PLDM_CLASSIFICATION_FIRMWARE 0x000A
  62. #define PLDM_CLASSIFICATION_CODE 0x000B
  63. #define PLDM_CLASSIFICATION_SERVICE_PACK 0x000C
  64. #define PLDM_CLASSIFICATION_SOFTWARE_BUNDLE 0x000D
  65. #define PLDM_ACTIVATION_METHOD_AUTO BIT(0)
  66. #define PLDM_ACTIVATION_METHOD_SELF_CONTAINED BIT(1)
  67. #define PLDM_ACTIVATION_METHOD_MEDIUM_SPECIFIC BIT(2)
  68. #define PLDM_ACTIVATION_METHOD_REBOOT BIT(3)
  69. #define PLDM_ACTIVATION_METHOD_DC_CYCLE BIT(4)
  70. #define PLDM_ACTIVATION_METHOD_AC_CYCLE BIT(5)
  71. #define PLDMFW_COMPONENT_OPTION_FORCE_UPDATE BIT(0)
  72. #define PLDMFW_COMPONENT_OPTION_USE_COMPARISON_STAMP BIT(1)
  73. struct pldmfw_component {
  74. struct list_head entry;
  75. /* component identifier */
  76. u16 classification;
  77. u16 identifier;
  78. u16 options;
  79. u16 activation_method;
  80. u32 comparison_stamp;
  81. u32 component_size;
  82. const u8 *component_data;
  83. /* Component version string */
  84. const u8 *version_string;
  85. u8 version_type;
  86. u8 version_len;
  87. /* component index */
  88. u8 index;
  89. };
  90. /* Transfer flag used for sending components to the firmware */
  91. #define PLDM_TRANSFER_FLAG_START BIT(0)
  92. #define PLDM_TRANSFER_FLAG_MIDDLE BIT(1)
  93. #define PLDM_TRANSFER_FLAG_END BIT(2)
  94. struct pldmfw_ops;
  95. /* Main entry point to the PLDM firmware update engine. Device drivers
  96. * should embed this in a private structure and use container_of to obtain
  97. * a pointer to their own data, used to implement the device specific
  98. * operations.
  99. */
  100. struct pldmfw {
  101. const struct pldmfw_ops *ops;
  102. struct device *dev;
  103. };
  104. bool pldmfw_op_pci_match_record(struct pldmfw *context, struct pldmfw_record *record);
  105. /* Operations invoked by the generic PLDM firmware update engine. Used to
  106. * implement device specific logic.
  107. *
  108. * @match_record: check if the device matches the given record. For
  109. * convenience, a standard implementation is provided for PCI devices.
  110. *
  111. * @send_package_data: send the package data associated with the matching
  112. * record to firmware.
  113. *
  114. * @send_component_table: send the component data associated with a given
  115. * component to firmware. Called once for each applicable component.
  116. *
  117. * @flash_component: Flash the data for a given component to the device.
  118. * Called once for each applicable component, after all component tables have
  119. * been sent.
  120. *
  121. * @finalize_update: (optional) Finish the update. Called after all components
  122. * have been flashed.
  123. */
  124. struct pldmfw_ops {
  125. bool (*match_record)(struct pldmfw *context, struct pldmfw_record *record);
  126. int (*send_package_data)(struct pldmfw *context, const u8 *data, u16 length);
  127. int (*send_component_table)(struct pldmfw *context, struct pldmfw_component *component,
  128. u8 transfer_flag);
  129. int (*flash_component)(struct pldmfw *context, struct pldmfw_component *component);
  130. int (*finalize_update)(struct pldmfw *context);
  131. };
  132. int pldmfw_flash_image(struct pldmfw *context, const struct firmware *fw);
  133. #endif