drivers/acpi/nhlt.c

Source file repositories/reference/linux-study-clean/drivers/acpi/nhlt.c

File Facts

System
Linux kernel
Corpus path
drivers/acpi/nhlt.c
Extension
.c
Size
8915 bytes
Lines
290
Domain
Driver Families
Bucket
drivers/acpi
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.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright(c) 2023-2024 Intel Corporation
 *
 * Authors: Cezary Rojewski <cezary.rojewski@intel.com>
 *          Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
 */

#define pr_fmt(fmt) "ACPI: NHLT: " fmt

#include <linux/acpi.h>
#include <linux/errno.h>
#include <linux/export.h>
#include <linux/minmax.h>
#include <linux/printk.h>
#include <linux/types.h>
#include <acpi/nhlt.h>

static struct acpi_table_nhlt *acpi_gbl_nhlt;

static struct acpi_table_nhlt empty_nhlt = {
	.header = {
		.signature = ACPI_SIG_NHLT,
	},
};

/**
 * acpi_nhlt_get_gbl_table - Retrieve a pointer to the first NHLT table.
 *
 * If there is no NHLT in the system, acpi_gbl_nhlt will instead point to an
 * empty table.
 *
 * Return: ACPI status code of the operation.
 */
acpi_status acpi_nhlt_get_gbl_table(void)
{
	acpi_status status;

	status = acpi_get_table(ACPI_SIG_NHLT, 0, (struct acpi_table_header **)(&acpi_gbl_nhlt));
	if (!acpi_gbl_nhlt)
		acpi_gbl_nhlt = &empty_nhlt;
	return status;
}
EXPORT_SYMBOL_GPL(acpi_nhlt_get_gbl_table);

/**
 * acpi_nhlt_put_gbl_table - Release the global NHLT table.
 */
void acpi_nhlt_put_gbl_table(void)
{
	acpi_put_table((struct acpi_table_header *)acpi_gbl_nhlt);
}
EXPORT_SYMBOL_GPL(acpi_nhlt_put_gbl_table);

/**
 * acpi_nhlt_endpoint_match - Verify if an endpoint matches criteria.
 * @ep:			the endpoint to check.
 * @link_type:		the hardware link type, e.g.: PDM or SSP.
 * @dev_type:		the device type.
 * @dir:		stream direction.
 * @bus_id:		the ID of virtual bus hosting the endpoint.
 *
 * Either of @link_type, @dev_type, @dir or @bus_id may be set to a negative
 * value to ignore the parameter when matching.
 *
 * Return: %true if endpoint matches specified criteria or %false otherwise.
 */
bool acpi_nhlt_endpoint_match(const struct acpi_nhlt_endpoint *ep,
			      int link_type, int dev_type, int dir, int bus_id)
{
	return ep &&
	       (link_type < 0 || ep->link_type == link_type) &&
	       (dev_type < 0 || ep->device_type == dev_type) &&
	       (bus_id < 0 || ep->virtual_bus_id == bus_id) &&
	       (dir < 0 || ep->direction == dir);
}
EXPORT_SYMBOL_GPL(acpi_nhlt_endpoint_match);

/**
 * acpi_nhlt_tb_find_endpoint - Search a NHLT table for an endpoint.
 * @tb:			the table to search.
 * @link_type:		the hardware link type, e.g.: PDM or SSP.
 * @dev_type:		the device type.
 * @dir:		stream direction.
 * @bus_id:		the ID of virtual bus hosting the endpoint.
 *
 * Either of @link_type, @dev_type, @dir or @bus_id may be set to a negative
 * value to ignore the parameter during the search.
 *
 * Return: A pointer to endpoint matching the criteria, %NULL if not found or

Annotation

Implementation Notes