内核ACPI函数API之acpi_os_read_pci_configuration

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tiantao2012/article/details/79955839
acpi_os_read_pci_configuration 用于在acpi这边读取形参指定的pcie设备对应的寄存器里面的值
其源码分析如下:
acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
			       u64 *value, u32 width)
{
	int result, size;
	u32 value32;
	#如果value为null,则说明没有空间保存读到的值
	if (!value)
		return AE_BAD_PARAMETER;

	switch (width) {
	case 8:
		size = 1;
		break;
	case 16:
		size = 2;
		break;
	case 32:
		size = 4;
		break;
	default:
		return AE_ERROR;
	}
	读取pcie寄存器的值,可见为了区分不同的pcie设备,需要四个参数,分别是segment/bus/device/function
	result = raw_pci_read(pci_id->segment, pci_id->bus,
				PCI_DEVFN(pci_id->device, pci_id->function),
				reg, size, &value32);
	#将读到的值返回给用户
	*value = value32;

	return (result ? AE_ERROR : AE_OK);
}

int raw_pci_read(unsigned int domain, unsigned int bus,
		  unsigned int devfn, int reg, int len, u32 *val)
{	
	#找到这个pcie设备对应的bug
	struct pci_bus *b = pci_find_bus(domain, bus);

	if (!b)
		return PCIBIOS_DEVICE_NOT_FOUND;
	#通过bus提供的read函数来读取pcie寄存器的值
	return b->ops->read(b, devfn, reg, len, val);
}
与读对应的是写寄存器函数,也同样是通过bus提供的write函数进行
int raw_pci_write(unsigned int domain, unsigned int bus,
		unsigned int devfn, int reg, int len, u32 val)
{
	struct pci_bus *b = pci_find_bus(domain, bus);

	if (!b)
		return PCIBIOS_DEVICE_NOT_FOUND;
	return b->ops->write(b, devfn, reg, len, val);
}

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页