18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ciIntroduction
48c2ecf20Sopenharmony_ci============
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ciThe Intel Management Engine (Intel ME) is an isolated and protected computing
78c2ecf20Sopenharmony_ciresource (Co-processor) residing inside certain Intel chipsets. The Intel ME
88c2ecf20Sopenharmony_ciprovides support for computer/IT management and security features.
98c2ecf20Sopenharmony_ciThe actual feature set depends on the Intel chipset SKU.
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ciThe Intel Management Engine Interface (Intel MEI, previously known as HECI)
128c2ecf20Sopenharmony_ciis the interface between the Host and Intel ME. This interface is exposed
138c2ecf20Sopenharmony_cito the host as a PCI device, actually multiple PCI devices might be exposed.
148c2ecf20Sopenharmony_ciThe Intel MEI Driver is in charge of the communication channel between
158c2ecf20Sopenharmony_cia host application and the Intel ME features.
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ciEach Intel ME feature, or Intel ME Client is addressed by a unique GUID and
188c2ecf20Sopenharmony_cieach client has its own protocol. The protocol is message-based with a
198c2ecf20Sopenharmony_ciheader and payload up to maximal number of bytes advertised by the client,
208c2ecf20Sopenharmony_ciupon connection.
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciIntel MEI Driver
238c2ecf20Sopenharmony_ci================
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ciThe driver exposes a character device with device nodes /dev/meiX.
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ciAn application maintains communication with an Intel ME feature while
288c2ecf20Sopenharmony_ci/dev/meiX is open. The binding to a specific feature is performed by calling
298c2ecf20Sopenharmony_ci:c:macro:`MEI_CONNECT_CLIENT_IOCTL`, which passes the desired GUID.
308c2ecf20Sopenharmony_ciThe number of instances of an Intel ME feature that can be opened
318c2ecf20Sopenharmony_ciat the same time depends on the Intel ME feature, but most of the
328c2ecf20Sopenharmony_cifeatures allow only a single instance.
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ciThe driver is transparent to data that are passed between firmware feature
358c2ecf20Sopenharmony_ciand host application.
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ciBecause some of the Intel ME features can change the system
388c2ecf20Sopenharmony_ciconfiguration, the driver by default allows only a privileged
398c2ecf20Sopenharmony_ciuser to access it.
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ciThe session is terminated calling :c:expr:`close(fd)`.
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciA code snippet for an application communicating with Intel AMTHI client:
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ciIn order to support virtualization or sandboxing a trusted supervisor
468c2ecf20Sopenharmony_cican use :c:macro:`MEI_CONNECT_CLIENT_IOCTL_VTAG` to create
478c2ecf20Sopenharmony_civirtual channels with an Intel ME feature. Not all features support
488c2ecf20Sopenharmony_civirtual channels such client with answer EOPNOTSUPP.
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci.. code-block:: C
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	struct mei_connect_client_data data;
538c2ecf20Sopenharmony_ci	fd = open(MEI_DEVICE);
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci	data.d.in_client_uuid = AMTHI_GUID;
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	ioctl(fd, IOCTL_MEI_CONNECT_CLIENT, &data);
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	printf("Ver=%d, MaxLen=%ld\n",
608c2ecf20Sopenharmony_ci	       data.d.in_client_uuid.protocol_version,
618c2ecf20Sopenharmony_ci	       data.d.in_client_uuid.max_msg_length);
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	[...]
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	write(fd, amthi_req_data, amthi_req_data_len);
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	[...]
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci	read(fd, &amthi_res_data, amthi_res_data_len);
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	[...]
728c2ecf20Sopenharmony_ci	close(fd);
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ciUser space API
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ciIOCTLs:
788c2ecf20Sopenharmony_ci=======
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ciThe Intel MEI Driver supports the following IOCTL commands:
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ciIOCTL_MEI_CONNECT_CLIENT
838c2ecf20Sopenharmony_ci-------------------------
848c2ecf20Sopenharmony_ciConnect to firmware Feature/Client.
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci.. code-block:: none
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	Usage:
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci        struct mei_connect_client_data client_data;
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci        ioctl(fd, IOCTL_MEI_CONNECT_CLIENT, &client_data);
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci	Inputs:
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci        struct mei_connect_client_data - contain the following
978c2ecf20Sopenharmony_ci	Input field:
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci		in_client_uuid -	GUID of the FW Feature that needs
1008c2ecf20Sopenharmony_ci					to connect to.
1018c2ecf20Sopenharmony_ci         Outputs:
1028c2ecf20Sopenharmony_ci		out_client_properties - Client Properties: MTU and Protocol Version.
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci         Error returns:
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci                ENOTTY  No such client (i.e. wrong GUID) or connection is not allowed.
1078c2ecf20Sopenharmony_ci		EINVAL	Wrong IOCTL Number
1088c2ecf20Sopenharmony_ci		ENODEV	Device or Connection is not initialized or ready.
1098c2ecf20Sopenharmony_ci		ENOMEM	Unable to allocate memory to client internal data.
1108c2ecf20Sopenharmony_ci		EFAULT	Fatal Error (e.g. Unable to access user input data)
1118c2ecf20Sopenharmony_ci		EBUSY	Connection Already Open
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci:Note:
1148c2ecf20Sopenharmony_ci        max_msg_length (MTU) in client properties describes the maximum
1158c2ecf20Sopenharmony_ci        data that can be sent or received. (e.g. if MTU=2K, can send
1168c2ecf20Sopenharmony_ci        requests up to bytes 2k and received responses up to 2k bytes).
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ciIOCTL_MEI_CONNECT_CLIENT_VTAG:
1198c2ecf20Sopenharmony_ci------------------------------
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci.. code-block:: none
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci        Usage:
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci        struct mei_connect_client_data_vtag client_data_vtag;
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci        ioctl(fd, IOCTL_MEI_CONNECT_CLIENT_VTAG, &client_data_vtag);
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci        Inputs:
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci        struct mei_connect_client_data_vtag - contain the following
1328c2ecf20Sopenharmony_ci        Input field:
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci                in_client_uuid -  GUID of the FW Feature that needs
1358c2ecf20Sopenharmony_ci                                  to connect to.
1368c2ecf20Sopenharmony_ci                vtag - virtual tag [1, 255]
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci         Outputs:
1398c2ecf20Sopenharmony_ci                out_client_properties - Client Properties: MTU and Protocol Version.
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci         Error returns:
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci                ENOTTY No such client (i.e. wrong GUID) or connection is not allowed.
1448c2ecf20Sopenharmony_ci                EINVAL Wrong IOCTL Number or tag == 0
1458c2ecf20Sopenharmony_ci                ENODEV Device or Connection is not initialized or ready.
1468c2ecf20Sopenharmony_ci                ENOMEM Unable to allocate memory to client internal data.
1478c2ecf20Sopenharmony_ci                EFAULT Fatal Error (e.g. Unable to access user input data)
1488c2ecf20Sopenharmony_ci                EBUSY  Connection Already Open
1498c2ecf20Sopenharmony_ci                EOPNOTSUPP Vtag is not supported
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ciIOCTL_MEI_NOTIFY_SET
1528c2ecf20Sopenharmony_ci---------------------
1538c2ecf20Sopenharmony_ciEnable or disable event notifications.
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci.. code-block:: none
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci	Usage:
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci		uint32_t enable;
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci		ioctl(fd, IOCTL_MEI_NOTIFY_SET, &enable);
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci		uint32_t enable = 1;
1668c2ecf20Sopenharmony_ci		or
1678c2ecf20Sopenharmony_ci		uint32_t enable[disable] = 0;
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci	Error returns:
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci		EINVAL	Wrong IOCTL Number
1738c2ecf20Sopenharmony_ci		ENODEV	Device  is not initialized or the client not connected
1748c2ecf20Sopenharmony_ci		ENOMEM	Unable to allocate memory to client internal data.
1758c2ecf20Sopenharmony_ci		EFAULT	Fatal Error (e.g. Unable to access user input data)
1768c2ecf20Sopenharmony_ci		EOPNOTSUPP if the device doesn't support the feature
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci:Note:
1798c2ecf20Sopenharmony_ci	The client must be connected in order to enable notification events
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ciIOCTL_MEI_NOTIFY_GET
1838c2ecf20Sopenharmony_ci--------------------
1848c2ecf20Sopenharmony_ciRetrieve event
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci.. code-block:: none
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci	Usage:
1898c2ecf20Sopenharmony_ci		uint32_t event;
1908c2ecf20Sopenharmony_ci		ioctl(fd, IOCTL_MEI_NOTIFY_GET, &event);
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci	Outputs:
1938c2ecf20Sopenharmony_ci		1 - if an event is pending
1948c2ecf20Sopenharmony_ci		0 - if there is no even pending
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci	Error returns:
1978c2ecf20Sopenharmony_ci		EINVAL	Wrong IOCTL Number
1988c2ecf20Sopenharmony_ci		ENODEV	Device is not initialized or the client not connected
1998c2ecf20Sopenharmony_ci		ENOMEM	Unable to allocate memory to client internal data.
2008c2ecf20Sopenharmony_ci		EFAULT	Fatal Error (e.g. Unable to access user input data)
2018c2ecf20Sopenharmony_ci		EOPNOTSUPP if the device doesn't support the feature
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci:Note:
2048c2ecf20Sopenharmony_ci	The client must be connected and event notification has to be enabled
2058c2ecf20Sopenharmony_ci	in order to receive an event
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ciSupported Chipsets
2108c2ecf20Sopenharmony_ci==================
2118c2ecf20Sopenharmony_ci82X38/X48 Express and newer
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_cilinux-mei@linux.intel.com
214