drivers/base/physical_location.c
Source file repositories/reference/linux-study-clean/drivers/base/physical_location.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/base/physical_location.c- Extension
.c- Size
- 3313 bytes
- Lines
- 145
- Domain
- Driver Families
- Bucket
- drivers/base
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/acpi.hlinux/sysfs.hlinux/string_choices.hphysical_location.h
Detected Declarations
function dev_add_physical_locationfunction panel_showfunction vertical_position_showfunction horizontal_position_showfunction dock_showfunction lid_show
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Device physical location support
*
* Author: Won Chung <wonchung@google.com>
*/
#include <linux/acpi.h>
#include <linux/sysfs.h>
#include <linux/string_choices.h>
#include "physical_location.h"
bool dev_add_physical_location(struct device *dev)
{
struct acpi_pld_info *pld;
if (!has_acpi_companion(dev))
return false;
if (!acpi_get_physical_device_location(ACPI_HANDLE(dev), &pld))
return false;
dev->physical_location = kzalloc_obj(*dev->physical_location);
if (!dev->physical_location) {
ACPI_FREE(pld);
return false;
}
dev->physical_location->panel = pld->panel;
dev->physical_location->vertical_position = pld->vertical_position;
dev->physical_location->horizontal_position = pld->horizontal_position;
dev->physical_location->dock = pld->dock;
dev->physical_location->lid = pld->lid;
ACPI_FREE(pld);
return true;
}
static ssize_t panel_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
const char *panel;
switch (dev->physical_location->panel) {
case DEVICE_PANEL_TOP:
panel = "top";
break;
case DEVICE_PANEL_BOTTOM:
panel = "bottom";
break;
case DEVICE_PANEL_LEFT:
panel = "left";
break;
case DEVICE_PANEL_RIGHT:
panel = "right";
break;
case DEVICE_PANEL_FRONT:
panel = "front";
break;
case DEVICE_PANEL_BACK:
panel = "back";
break;
default:
panel = "unknown";
}
return sysfs_emit(buf, "%s\n", panel);
}
static DEVICE_ATTR_RO(panel);
static ssize_t vertical_position_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
const char *vertical_position;
switch (dev->physical_location->vertical_position) {
case DEVICE_VERT_POS_UPPER:
vertical_position = "upper";
break;
case DEVICE_VERT_POS_CENTER:
vertical_position = "center";
break;
case DEVICE_VERT_POS_LOWER:
vertical_position = "lower";
break;
default:
vertical_position = "unknown";
}
return sysfs_emit(buf, "%s\n", vertical_position);
}
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/sysfs.h`, `linux/string_choices.h`, `physical_location.h`.
- Detected declarations: `function dev_add_physical_location`, `function panel_show`, `function vertical_position_show`, `function horizontal_position_show`, `function dock_show`, `function lid_show`.
- Atlas domain: Driver Families / drivers/base.
- Implementation status: source 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.