drivers/hid/surface-hid/surface_hid_core.c
Source file repositories/reference/linux-study-clean/drivers/hid/surface-hid/surface_hid_core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/surface-hid/surface_hid_core.c- Extension
.c- Size
- 7839 bytes
- Lines
- 294
- Domain
- Driver Families
- Bucket
- drivers/hid
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/unaligned.hlinux/hid.hlinux/kernel.hlinux/module.hlinux/types.hlinux/usb/ch9.hlinux/surface_aggregator/controller.hsurface_hid_core.h
Detected Declarations
function Copyrightfunction surface_hid_load_hid_descriptorfunction surface_hid_load_device_attributesfunction surface_hid_startfunction surface_hid_stopfunction surface_hid_openfunction surface_hid_closefunction surface_hid_raw_requestfunction surface_hid_device_addfunction surface_hid_device_destroyfunction surface_hid_suspendfunction surface_hid_resumefunction surface_hid_freezefunction surface_hid_powerofffunction surface_hid_restoreexport surface_hid_device_addexport surface_hid_device_destroyexport surface_hid_pm_opsexport surface_hid_pm_ops
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0+
/*
* Common/core components for the Surface System Aggregator Module (SSAM) HID
* transport driver. Provides support for integrated HID devices on Microsoft
* Surface models.
*
* Copyright (C) 2019-2021 Maximilian Luz <luzmaximilian@gmail.com>
*/
#include <linux/unaligned.h>
#include <linux/hid.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/usb/ch9.h>
#include <linux/surface_aggregator/controller.h>
#include "surface_hid_core.h"
/* -- Utility functions. ---------------------------------------------------- */
static bool surface_hid_is_hot_removed(struct surface_hid_device *shid)
{
/*
* Non-ssam client devices, i.e. platform client devices, cannot be
* hot-removed.
*/
if (!is_ssam_device(shid->dev))
return false;
return ssam_device_is_hot_removed(to_ssam_device(shid->dev));
}
/* -- Device descriptor access. --------------------------------------------- */
static int surface_hid_load_hid_descriptor(struct surface_hid_device *shid)
{
int status;
if (surface_hid_is_hot_removed(shid))
return -ENODEV;
status = shid->ops.get_descriptor(shid, SURFACE_HID_DESC_HID,
(u8 *)&shid->hid_desc, sizeof(shid->hid_desc));
if (status)
return status;
if (shid->hid_desc.desc_len != sizeof(shid->hid_desc)) {
dev_err(shid->dev, "unexpected HID descriptor length: got %u, expected %zu\n",
shid->hid_desc.desc_len, sizeof(shid->hid_desc));
return -EPROTO;
}
if (shid->hid_desc.desc_type != HID_DT_HID) {
dev_err(shid->dev, "unexpected HID descriptor type: got %#04x, expected %#04x\n",
shid->hid_desc.desc_type, HID_DT_HID);
return -EPROTO;
}
if (shid->hid_desc.num_descriptors != 1) {
dev_err(shid->dev, "unexpected number of descriptors: got %u, expected 1\n",
shid->hid_desc.num_descriptors);
return -EPROTO;
}
if (shid->hid_desc.report_desc_type != HID_DT_REPORT) {
dev_err(shid->dev, "unexpected report descriptor type: got %#04x, expected %#04x\n",
shid->hid_desc.report_desc_type, HID_DT_REPORT);
return -EPROTO;
}
return 0;
}
static int surface_hid_load_device_attributes(struct surface_hid_device *shid)
{
int status;
if (surface_hid_is_hot_removed(shid))
return -ENODEV;
status = shid->ops.get_descriptor(shid, SURFACE_HID_DESC_ATTRS,
(u8 *)&shid->attrs, sizeof(shid->attrs));
if (status)
return status;
if (get_unaligned_le32(&shid->attrs.length) != sizeof(shid->attrs)) {
Annotation
- Immediate include surface: `linux/unaligned.h`, `linux/hid.h`, `linux/kernel.h`, `linux/module.h`, `linux/types.h`, `linux/usb/ch9.h`, `linux/surface_aggregator/controller.h`, `surface_hid_core.h`.
- Detected declarations: `function Copyright`, `function surface_hid_load_hid_descriptor`, `function surface_hid_load_device_attributes`, `function surface_hid_start`, `function surface_hid_stop`, `function surface_hid_open`, `function surface_hid_close`, `function surface_hid_raw_request`, `function surface_hid_device_add`, `function surface_hid_device_destroy`.
- Atlas domain: Driver Families / drivers/hid.
- Implementation status: integration implementation candidate.
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.