xref: /linux/Documentation/driver-api/tee.rst (revision 06d07429858317ded2db7986113a9e0129cd599b)
1*50709576SSumit Garg.. SPDX-License-Identifier: GPL-2.0
2*50709576SSumit Garg
3*50709576SSumit Garg===============================================
4*50709576SSumit GargTEE (Trusted Execution Environment) driver API
5*50709576SSumit Garg===============================================
6*50709576SSumit Garg
7*50709576SSumit GargKernel provides a TEE bus infrastructure where a Trusted Application is
8*50709576SSumit Gargrepresented as a device identified via Universally Unique Identifier (UUID) and
9*50709576SSumit Gargclient drivers register a table of supported device UUIDs.
10*50709576SSumit Garg
11*50709576SSumit GargTEE bus infrastructure registers following APIs:
12*50709576SSumit Garg
13*50709576SSumit Gargmatch():
14*50709576SSumit Garg  iterates over the client driver UUID table to find a corresponding
15*50709576SSumit Garg  match for device UUID. If a match is found, then this particular device is
16*50709576SSumit Garg  probed via corresponding probe API registered by the client driver. This
17*50709576SSumit Garg  process happens whenever a device or a client driver is registered with TEE
18*50709576SSumit Garg  bus.
19*50709576SSumit Garg
20*50709576SSumit Garguevent():
21*50709576SSumit Garg  notifies user-space (udev) whenever a new device is registered on
22*50709576SSumit Garg  TEE bus for auto-loading of modularized client drivers.
23*50709576SSumit Garg
24*50709576SSumit GargTEE bus device enumeration is specific to underlying TEE implementation, so it
25*50709576SSumit Gargis left open for TEE drivers to provide corresponding implementation.
26*50709576SSumit Garg
27*50709576SSumit GargThen TEE client driver can talk to a matched Trusted Application using APIs
28*50709576SSumit Garglisted in include/linux/tee_drv.h.
29*50709576SSumit Garg
30*50709576SSumit GargTEE client driver example
31*50709576SSumit Garg-------------------------
32*50709576SSumit Garg
33*50709576SSumit GargSuppose a TEE client driver needs to communicate with a Trusted Application
34*50709576SSumit Garghaving UUID: ``ac6a4085-0e82-4c33-bf98-8eb8e118b6c2``, so driver registration
35*50709576SSumit Gargsnippet would look like::
36*50709576SSumit Garg
37*50709576SSumit Garg	static const struct tee_client_device_id client_id_table[] = {
38*50709576SSumit Garg		{UUID_INIT(0xac6a4085, 0x0e82, 0x4c33,
39*50709576SSumit Garg			   0xbf, 0x98, 0x8e, 0xb8, 0xe1, 0x18, 0xb6, 0xc2)},
40*50709576SSumit Garg		{}
41*50709576SSumit Garg	};
42*50709576SSumit Garg
43*50709576SSumit Garg	MODULE_DEVICE_TABLE(tee, client_id_table);
44*50709576SSumit Garg
45*50709576SSumit Garg	static struct tee_client_driver client_driver = {
46*50709576SSumit Garg		.id_table	= client_id_table,
47*50709576SSumit Garg		.driver		= {
48*50709576SSumit Garg			.name		= DRIVER_NAME,
49*50709576SSumit Garg			.bus		= &tee_bus_type,
50*50709576SSumit Garg			.probe		= client_probe,
51*50709576SSumit Garg			.remove		= client_remove,
52*50709576SSumit Garg		},
53*50709576SSumit Garg	};
54*50709576SSumit Garg
55*50709576SSumit Garg	static int __init client_init(void)
56*50709576SSumit Garg	{
57*50709576SSumit Garg		return driver_register(&client_driver.driver);
58*50709576SSumit Garg	}
59*50709576SSumit Garg
60*50709576SSumit Garg	static void __exit client_exit(void)
61*50709576SSumit Garg	{
62*50709576SSumit Garg		driver_unregister(&client_driver.driver);
63*50709576SSumit Garg	}
64*50709576SSumit Garg
65*50709576SSumit Garg	module_init(client_init);
66*50709576SSumit Garg	module_exit(client_exit);
67