1101043Sdes/* SPDX-License-Identifier: GPL-2.0 */
2101043Sdes/* Copyright (C) 2018-2019, Intel Corporation. */
3101043Sdes
4101043Sdes#ifndef _PLDMFW_H_
5101043Sdes#define _PLDMFW_H_
6101043Sdes
7101043Sdes#include <linux/list.h>
8101043Sdes#include <linux/firmware.h>
9101043Sdes
10101043Sdes#define PLDM_DEVICE_UPDATE_CONTINUE_AFTER_FAIL BIT(0)
11101043Sdes
12101043Sdes#define PLDM_STRING_TYPE_UNKNOWN	0
13101043Sdes#define PLDM_STRING_TYPE_ASCII		1
14101043Sdes#define PLDM_STRING_TYPE_UTF8		2
15101043Sdes#define PLDM_STRING_TYPE_UTF16		3
16101043Sdes#define PLDM_STRING_TYPE_UTF16LE	4
17101043Sdes#define PLDM_STRING_TYPE_UTF16BE	5
18101043Sdes
19101043Sdesstruct pldmfw_record {
20101043Sdes	struct list_head entry;
21101043Sdes
22101043Sdes	/* List of descriptor TLVs */
23101043Sdes	struct list_head descs;
24101043Sdes
25101043Sdes	/* Component Set version string*/
26101043Sdes	const u8 *version_string;
27101043Sdes	u8 version_type;
28101043Sdes	u8 version_len;
29101043Sdes
30101043Sdes	/* Package Data length */
31101043Sdes	u16 package_data_len;
32101043Sdes
33101043Sdes	/* Bitfield of Device Update Flags */
34101043Sdes	u32 device_update_flags;
35101043Sdes
36101043Sdes	/* Package Data block */
37101043Sdes	const u8 *package_data;
38101043Sdes
39101043Sdes	/* Bitmap of components applicable to this record */
40101043Sdes	unsigned long *component_bitmap;
41101043Sdes	u16 component_bitmap_len;
42101163Sdes};
43101163Sdes
44101043Sdes/* Standard descriptor TLV identifiers */
45101043Sdes#define PLDM_DESC_ID_PCI_VENDOR_ID	0x0000
46101043Sdes#define PLDM_DESC_ID_IANA_ENTERPRISE_ID	0x0001
47101043Sdes#define PLDM_DESC_ID_UUID		0x0002
48101043Sdes#define PLDM_DESC_ID_PNP_VENDOR_ID	0x0003
49101043Sdes#define PLDM_DESC_ID_ACPI_VENDOR_ID	0x0004
50101043Sdes#define PLDM_DESC_ID_PCI_DEVICE_ID	0x0100
51101043Sdes#define PLDM_DESC_ID_PCI_SUBVENDOR_ID	0x0101
52101043Sdes#define PLDM_DESC_ID_PCI_SUBDEV_ID	0x0102
53101043Sdes#define PLDM_DESC_ID_PCI_REVISION_ID	0x0103
54101043Sdes#define PLDM_DESC_ID_PNP_PRODUCT_ID	0x0104
55101043Sdes#define PLDM_DESC_ID_ACPI_PRODUCT_ID	0x0105
56101043Sdes#define PLDM_DESC_ID_VENDOR_DEFINED	0xFFFF
57101043Sdes
58101043Sdesstruct pldmfw_desc_tlv {
59101043Sdes	struct list_head entry;
60101043Sdes
61101043Sdes	const u8 *data;
62101043Sdes	u16 type;
63101043Sdes	u16 size;
64101043Sdes};
65237671Sthompsa
66179115Sbms#define PLDM_CLASSIFICATION_UNKNOWN		0x0000
67101043Sdes#define PLDM_CLASSIFICATION_OTHER		0x0001
68101043Sdes#define PLDM_CLASSIFICATION_DRIVER		0x0002
69101043Sdes#define PLDM_CLASSIFICATION_CONFIG_SW		0x0003
70101043Sdes#define PLDM_CLASSIFICATION_APP_SW		0x0004
71164201Skeramida#define PLDM_CLASSIFICATION_INSTRUMENTATION	0x0005
72164201Skeramida#define PLDM_CLASSIFICATION_BIOS		0x0006
73164201Skeramida#define PLDM_CLASSIFICATION_DIAGNOSTIC_SW	0x0007
74164201Skeramida#define PLDM_CLASSIFICATION_OS			0x0008
75164201Skeramida#define PLDM_CLASSIFICATION_MIDDLEWARE		0x0009
76164201Skeramida#define PLDM_CLASSIFICATION_FIRMWARE		0x000A
77164201Skeramida#define PLDM_CLASSIFICATION_CODE		0x000B
78164201Skeramida#define PLDM_CLASSIFICATION_SERVICE_PACK	0x000C
79164201Skeramida#define PLDM_CLASSIFICATION_SOFTWARE_BUNDLE	0x000D
80164201Skeramida
81101043Sdes#define PLDM_ACTIVATION_METHOD_AUTO		BIT(0)
82101043Sdes#define PLDM_ACTIVATION_METHOD_SELF_CONTAINED	BIT(1)
83101043Sdes#define PLDM_ACTIVATION_METHOD_MEDIUM_SPECIFIC	BIT(2)
84101043Sdes#define PLDM_ACTIVATION_METHOD_REBOOT		BIT(3)
85101043Sdes#define PLDM_ACTIVATION_METHOD_DC_CYCLE		BIT(4)
86101043Sdes#define PLDM_ACTIVATION_METHOD_AC_CYCLE		BIT(5)
87101043Sdes
88101043Sdes#define PLDMFW_COMPONENT_OPTION_FORCE_UPDATE		BIT(0)
89101043Sdes#define PLDMFW_COMPONENT_OPTION_USE_COMPARISON_STAMP	BIT(1)
90231779Sjilles
91101043Sdesstruct pldmfw_component {
92101043Sdes	struct list_head entry;
93101043Sdes
94101043Sdes	/* component identifier */
95101043Sdes	u16 classification;
96101043Sdes	u16 identifier;
97101043Sdes
98101043Sdes	u16 options;
99101043Sdes	u16 activation_method;
100101043Sdes
101101043Sdes	u32 comparison_stamp;
102101043Sdes
103101043Sdes	u32 component_size;
104101043Sdes	const u8 *component_data;
105101043Sdes
106101043Sdes	/* Component version string */
107101043Sdes	const u8 *version_string;
108101043Sdes	u8 version_type;
109101043Sdes	u8 version_len;
110101043Sdes
111101043Sdes	/* component index */
112101043Sdes	u8 index;
113101043Sdes
114101043Sdes};
115101043Sdes
116101043Sdes/* Transfer flag used for sending components to the firmware */
117101043Sdes#define PLDM_TRANSFER_FLAG_START		BIT(0)
118101043Sdes#define PLDM_TRANSFER_FLAG_MIDDLE		BIT(1)
119101043Sdes#define PLDM_TRANSFER_FLAG_END			BIT(2)
120164201Skeramida
121164201Skeramidastruct pldmfw_ops;
122164201Skeramida
123164201Skeramida/* Main entry point to the PLDM firmware update engine. Device drivers
124164201Skeramida * should embed this in a private structure and use container_of to obtain
125164201Skeramida * a pointer to their own data, used to implement the device specific
126164201Skeramida * operations.
127164201Skeramida */
128164201Skeramidastruct pldmfw {
129164201Skeramida	const struct pldmfw_ops *ops;
130164201Skeramida	struct device *dev;
131164201Skeramida};
132164201Skeramida
133164201Skeramidabool pldmfw_op_pci_match_record(struct pldmfw *context, struct pldmfw_record *record);
134164201Skeramida
135164201Skeramida/* Operations invoked by the generic PLDM firmware update engine. Used to
136164201Skeramida * implement device specific logic.
137164201Skeramida *
138164201Skeramida * @match_record: check if the device matches the given record. For
139164201Skeramida * convenience, a standard implementation is provided for PCI devices.
140164201Skeramida *
141164201Skeramida * @send_package_data: send the package data associated with the matching
142164201Skeramida * record to firmware.
143164201Skeramida *
144164201Skeramida * @send_component_table: send the component data associated with a given
145164201Skeramida * component to firmware. Called once for each applicable component.
146164201Skeramida *
147164201Skeramida * @flash_component: Flash the data for a given component to the device.
148164201Skeramida * Called once for each applicable component, after all component tables have
149164201Skeramida * been sent.
150164201Skeramida *
151164201Skeramida * @finalize_update: (optional) Finish the update. Called after all components
152164201Skeramida * have been flashed.
153164201Skeramida */
154164201Skeramidastruct pldmfw_ops {
155164201Skeramida	bool (*match_record)(struct pldmfw *context, struct pldmfw_record *record);
156164201Skeramida	int (*send_package_data)(struct pldmfw *context, const u8 *data, u16 length);
157164201Skeramida	int (*send_component_table)(struct pldmfw *context, struct pldmfw_component *component,
158164201Skeramida				    u8 transfer_flag);
159164201Skeramida	int (*flash_component)(struct pldmfw *context, struct pldmfw_component *component);
160164201Skeramida	int (*finalize_update)(struct pldmfw *context);
161164201Skeramida};
162164201Skeramida
163164201Skeramidaint pldmfw_flash_image(struct pldmfw *context, const struct firmware *fw);
164164201Skeramida
165164201Skeramida#endif
166164201Skeramida