drivers/ptp/ptp_vmclock.c

Source file repositories/reference/linux-study-clean/drivers/ptp/ptp_vmclock.c

File Facts

System
Linux kernel
Corpus path
drivers/ptp/ptp_vmclock.c
Extension
.c
Size
19951 bytes
Lines
792
Domain
Driver Families
Bucket
drivers/ptp
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.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct file_operations vmclock_miscdev_fops = {
	.owner = THIS_MODULE,
	.open = vmclock_miscdev_open,
	.release = vmclock_miscdev_release,
	.mmap = vmclock_miscdev_mmap,
	.read = vmclock_miscdev_read,
	.poll = vmclock_miscdev_poll,
};

/* module operations */

#if IS_ENABLED(CONFIG_ACPI)
static acpi_status vmclock_acpi_resources(struct acpi_resource *ares, void *data)
{
	struct vmclock_state *st = data;
	struct resource_win win;
	struct resource *res = &win.res;

	if (ares->type == ACPI_RESOURCE_TYPE_END_TAG)
		return AE_OK;

	/* There can be only one */
	if (resource_type(&st->res) == IORESOURCE_MEM)
		return AE_ERROR;

	if (acpi_dev_resource_memory(ares, res) ||
	    acpi_dev_resource_address_space(ares, &win)) {

		if (resource_type(res) != IORESOURCE_MEM ||
		    resource_size(res) < sizeof(st->clk))
			return AE_ERROR;

		st->res = *res;
		return AE_OK;
	}

	return AE_ERROR;
}

static void
vmclock_acpi_notification_handler(acpi_handle __always_unused handle,
				  u32 __always_unused event, void *dev)
{
	struct device *device = dev;
	struct vmclock_state *st = device->driver_data;

	wake_up_interruptible(&st->disrupt_wait);
}

static int vmclock_setup_acpi_notification(struct device *dev)
{
	struct acpi_device *adev = ACPI_COMPANION(dev);
	acpi_status status;

	/*
	 * This should never happen as this function is only called when
	 * has_acpi_companion(dev) is true, but the logic is sufficiently
	 * complex that Coverity can't see the tautology.
	 */
	if (!adev)
		return -ENODEV;

	status = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY,
					     vmclock_acpi_notification_handler,
					     dev);
	if (ACPI_FAILURE(status)) {
		dev_err(dev, "failed to install notification handler");
		return -ENODEV;
	}

	return 0;
}

static int vmclock_probe_acpi(struct device *dev, struct vmclock_state *st)
{
	struct acpi_device *adev = ACPI_COMPANION(dev);
	acpi_status status;

	/*
	 * This should never happen as this function is only called when
	 * has_acpi_companion(dev) is true, but the logic is sufficiently
	 * complex that Coverity can't see the tautology.
	 */
	if (!adev)
		return -ENODEV;

	status = acpi_walk_resources(adev->handle, METHOD_NAME__CRS,
				     vmclock_acpi_resources, st);
	if (ACPI_FAILURE(status) || resource_type(&st->res) != IORESOURCE_MEM) {
		dev_err(dev, "failed to get resources\n");

Annotation

Implementation Notes