drivers/platform/surface/surface_dtx.c
Source file repositories/reference/linux-study-clean/drivers/platform/surface/surface_dtx.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/surface/surface_dtx.c- Extension
.c- Size
- 34163 bytes
- Lines
- 1283
- Domain
- Driver Families
- Bucket
- drivers/platform
- 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/fs.hlinux/input.hlinux/ioctl.hlinux/kernel.hlinux/kfifo.hlinux/kref.hlinux/miscdevice.hlinux/module.hlinux/mutex.hlinux/platform_device.hlinux/poll.hlinux/rwsem.hlinux/slab.hlinux/workqueue.hlinux/surface_aggregator/controller.hlinux/surface_aggregator/device.hlinux/surface_aggregator/dtx.h
Detected Declarations
struct ssam_bas_base_infostruct sdtx_devicestruct sdtx_clientstruct sdtx_status_eventstruct sdtx_base_info_eventenum sam_event_cid_basenum ssam_bas_base_stateenum ssam_bas_latch_statusenum ssam_bas_cancel_reasonenum sdtx_device_stateenum sdtx_client_statefunction __sdtx_device_releasefunction sdtx_device_putfunction sdtx_translate_base_statefunction sdtx_translate_latch_statusfunction sdtx_translate_cancel_reasonfunction sdtx_ioctl_get_base_infofunction sdtx_ioctl_get_device_modefunction sdtx_ioctl_get_latch_statusfunction __surface_dtx_ioctlfunction surface_dtx_ioctlfunction surface_dtx_openfunction surface_dtx_releasefunction surface_dtx_readfunction surface_dtx_pollfunction surface_dtx_fasyncfunction sdtx_push_eventfunction sdtx_notifierfunction sdtx_device_mode_invalidfunction sdtx_device_mode_workfnfunction casesfunction sdtx_update_device_modefunction __sdtx_device_state_update_basefunction __sdtx_device_state_update_modefunction __sdtx_device_state_update_latchfunction sdtx_device_state_workfnfunction sdtx_update_device_statefunction sdtx_device_initfunction sdtx_device_destroyfunction surface_dtx_pm_completefunction surface_dtx_platform_probefunction surface_dtx_platform_removefunction surface_dtx_ssam_probefunction surface_dtx_ssam_removefunction ssam_dtx_driver_registerfunction ssam_dtx_driver_unregisterfunction ssam_dtx_driver_registerfunction ssam_dtx_driver_unregister
Annotated Snippet
static const struct file_operations surface_dtx_fops = {
.owner = THIS_MODULE,
.open = surface_dtx_open,
.release = surface_dtx_release,
.read = surface_dtx_read,
.poll = surface_dtx_poll,
.fasync = surface_dtx_fasync,
.unlocked_ioctl = surface_dtx_ioctl,
.compat_ioctl = surface_dtx_ioctl,
};
/* -- Event handling/forwarding. -------------------------------------------- */
/*
* The device operation mode is not immediately updated on the EC when the
* base has been connected, i.e. querying the device mode inside the
* connection event callback yields an outdated value. Thus, we can only
* determine the new tablet-mode switch and device mode values after some
* time.
*
* These delays have been chosen by experimenting. We first delay on connect
* events, then check and validate the device mode against the base state and
* if invalid delay again by the "recheck" delay.
*/
#define SDTX_DEVICE_MODE_DELAY_CONNECT msecs_to_jiffies(100)
#define SDTX_DEVICE_MODE_DELAY_RECHECK msecs_to_jiffies(100)
struct sdtx_status_event {
struct sdtx_event e;
__u16 v;
} __packed;
struct sdtx_base_info_event {
struct sdtx_event e;
struct sdtx_base_info v;
} __packed;
union sdtx_generic_event {
struct sdtx_event common;
struct sdtx_status_event status;
struct sdtx_base_info_event base;
};
static void sdtx_update_device_mode(struct sdtx_device *ddev, unsigned long delay);
/* Must be executed with ddev->write_lock held. */
static void sdtx_push_event(struct sdtx_device *ddev, struct sdtx_event *evt)
{
const size_t len = sizeof(struct sdtx_event) + evt->length;
struct sdtx_client *client;
lockdep_assert_held(&ddev->write_lock);
down_read(&ddev->client_lock);
list_for_each_entry(client, &ddev->client_list, node) {
if (!test_bit(SDTX_CLIENT_EVENTS_ENABLED_BIT, &client->flags))
continue;
if (likely(kfifo_avail(&client->buffer) >= len))
kfifo_in(&client->buffer, (const u8 *)evt, len);
else
dev_warn(ddev->dev, "event buffer overrun\n");
kill_fasync(&client->fasync, SIGIO, POLL_IN);
}
up_read(&ddev->client_lock);
wake_up_interruptible(&ddev->waitq);
}
static u32 sdtx_notifier(struct ssam_event_notifier *nf, const struct ssam_event *in)
{
struct sdtx_device *ddev = container_of(nf, struct sdtx_device, notif);
union sdtx_generic_event event;
size_t len;
/* Validate event payload length. */
switch (in->command_id) {
case SAM_EVENT_CID_DTX_CONNECTION:
len = 2 * sizeof(u8);
break;
case SAM_EVENT_CID_DTX_REQUEST:
len = 0;
break;
case SAM_EVENT_CID_DTX_CANCEL:
len = sizeof(u8);
break;
Annotation
- Immediate include surface: `linux/fs.h`, `linux/input.h`, `linux/ioctl.h`, `linux/kernel.h`, `linux/kfifo.h`, `linux/kref.h`, `linux/miscdevice.h`, `linux/module.h`.
- Detected declarations: `struct ssam_bas_base_info`, `struct sdtx_device`, `struct sdtx_client`, `struct sdtx_status_event`, `struct sdtx_base_info_event`, `enum sam_event_cid_bas`, `enum ssam_bas_base_state`, `enum ssam_bas_latch_status`, `enum ssam_bas_cancel_reason`, `enum sdtx_device_state`.
- Atlas domain: Driver Families / drivers/platform.
- 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.