drivers/tee/tee_core.c
Source file repositories/reference/linux-study-clean/drivers/tee/tee_core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tee/tee_core.c- Extension
.c- Size
- 39160 bytes
- Lines
- 1580
- Domain
- Driver Families
- Bucket
- drivers/tee
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cdev.hlinux/cred.hlinux/fs.hlinux/idr.hlinux/module.hlinux/overflow.hlinux/slab.hlinux/tee_core.hlinux/uaccess.hcrypto/sha1.htee_private.h
Detected Declarations
struct match_dev_datafunction teedev_ctx_getfunction teedev_ctx_releasefunction teedev_ctx_putfunction teedev_close_contextfunction tee_openfunction tee_releasefunction uuid_v5function tee_session_calc_client_uuidfunction tee_ioctl_versionfunction tee_ioctl_shm_allocfunction tee_ioctl_shm_registerfunction tee_ioctl_shm_register_fdfunction param_from_user_memreffunction params_from_userfunction params_to_userfunction free_paramsfunction tee_ioctl_open_sessionfunction tee_ioctl_invokefunction tee_ioctl_object_invokefunction tee_ioctl_cancelfunction tee_ioctl_close_sessionfunction params_to_suppfunction tee_ioctl_supp_recvfunction params_from_suppfunction tee_ioctl_supp_sendfunction tee_ioctlfunction tee_release_devicefunction tee_device_allocfunction tee_device_set_dev_groupsfunction implementation_id_showfunction revision_showfunction tee_revision_attr_is_visiblefunction tee_device_registerfunction tee_device_putfunction tee_device_getfunction tee_device_unregisterfunction tee_get_drvdatafunction match_devfunction tee_client_open_contextfunction tee_client_close_contextfunction tee_client_get_versionfunction tee_client_open_sessionfunction tee_client_close_sessionfunction tee_client_system_sessionfunction tee_client_invoke_funcfunction tee_client_cancel_reqfunction tee_client_device_match
Annotated Snippet
static const struct file_operations tee_fops = {
.owner = THIS_MODULE,
.open = tee_open,
.release = tee_release,
.unlocked_ioctl = tee_ioctl,
.compat_ioctl = compat_ptr_ioctl,
};
static void tee_release_device(struct device *dev)
{
struct tee_device *teedev = container_of(dev, struct tee_device, dev);
spin_lock(&driver_lock);
clear_bit(teedev->id, dev_mask);
spin_unlock(&driver_lock);
mutex_destroy(&teedev->mutex);
idr_destroy(&teedev->idr);
kfree(teedev);
}
/**
* tee_device_alloc() - Allocate a new struct tee_device instance
* @teedesc: Descriptor for this driver
* @dev: Parent device for this device
* @pool: Shared memory pool, NULL if not used
* @driver_data: Private driver data for this device
*
* Allocates a new struct tee_device instance. The device is
* removed by tee_device_unregister().
*
* @returns a pointer to a 'struct tee_device' or an ERR_PTR on failure
*/
struct tee_device *tee_device_alloc(const struct tee_desc *teedesc,
struct device *dev,
struct tee_shm_pool *pool,
void *driver_data)
{
struct tee_device *teedev;
void *ret;
int rc, max_id;
int offs = 0;
if (!teedesc || !teedesc->name || !teedesc->ops ||
!teedesc->ops->get_version || !teedesc->ops->open ||
!teedesc->ops->release)
return ERR_PTR(-EINVAL);
teedev = kzalloc_obj(*teedev);
if (!teedev) {
ret = ERR_PTR(-ENOMEM);
goto err;
}
max_id = TEE_NUM_DEVICES / 2;
if (teedesc->flags & TEE_DESC_PRIVILEGED) {
offs = TEE_NUM_DEVICES / 2;
max_id = TEE_NUM_DEVICES;
}
spin_lock(&driver_lock);
teedev->id = find_next_zero_bit(dev_mask, max_id, offs);
if (teedev->id < max_id)
set_bit(teedev->id, dev_mask);
spin_unlock(&driver_lock);
if (teedev->id >= max_id) {
ret = ERR_PTR(-ENOMEM);
goto err;
}
snprintf(teedev->name, sizeof(teedev->name), "tee%s%d",
teedesc->flags & TEE_DESC_PRIVILEGED ? "priv" : "",
teedev->id - offs);
teedev->dev.class = &tee_class;
teedev->dev.release = tee_release_device;
teedev->dev.parent = dev;
teedev->dev.devt = MKDEV(MAJOR(tee_devt), teedev->id);
rc = dev_set_name(&teedev->dev, "%s", teedev->name);
if (rc) {
ret = ERR_PTR(rc);
goto err_devt;
}
cdev_init(&teedev->cdev, &tee_fops);
teedev->cdev.owner = teedesc->owner;
Annotation
- Immediate include surface: `linux/cdev.h`, `linux/cred.h`, `linux/fs.h`, `linux/idr.h`, `linux/module.h`, `linux/overflow.h`, `linux/slab.h`, `linux/tee_core.h`.
- Detected declarations: `struct match_dev_data`, `function teedev_ctx_get`, `function teedev_ctx_release`, `function teedev_ctx_put`, `function teedev_close_context`, `function tee_open`, `function tee_release`, `function uuid_v5`, `function tee_session_calc_client_uuid`, `function tee_ioctl_version`.
- Atlas domain: Driver Families / drivers/tee.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.