linux --中断管理 -- irq的自动探测机制

irq自动探测机制

如果一个设备的驱动程序无法确定它说管理的设备的软件中断号irq,此时设备驱动程序可以使用irq的自动探测机制来获取其正在使用的irq。

使用自动探测机制的条件

  1. 内核与驱动,必须共同努力才能完成
  2. 只限于非共享中断的情况

探测前,驱动的设备关联到了某个irq,但是因为设备驱动程序还不清楚是哪个irq,因此无法调用request_irq来向该irq安装中断处理例程,所以对应irq的action为空,下面是一个设备驱动程序的使用示例:
在这里插入图片描述
probe_irq_on和probe_irq_off是内核为驱动程序员设计的两个自动探测的接口函数

irq自动探测的原理描述

在这里插入图片描述

probe_irq_on


/**
 *	probe_irq_on	- begin an interrupt autodetect
 *
 *	Commence probing for an interrupt. The interrupts are scanned
 *	and a mask of potential interrupt lines is returned.
 *
 * 开始探测中断,扫描中断并返回潜在中断线的mask
 */
unsigned long probe_irq_on(void)
{
   
	struct irq_desc *desc;
	unsigned long mask = 0;
	int i;

	/*
	 * quiesce the kernel, or at least the asynchronous portion
	 */
	async_synchronize_full();
	mutex_lock(&probing_active);
	/*
	 * something may have generated an irq long ago and we want to
	 * flush such a longstanding irq before considering it as spurious.
	 */
	for_each_irq_desc_reverse(i, desc) {
   
		raw_spin_lock_irq(&desc->lock);
		if (!desc->action && irq_settings_can_probe(desc)) {
   
			/*
			 * Some chips need to know about probing in
			 * progress:
			 */
			if (desc->irq_data.chip->irq_set_type)
				desc->irq_data.chip->irq_set_type(&desc->irq_data,
							 IRQ_TYPE_PROBE);
			irq_startup(desc);
		}
		raw_spin_unlock_irq(&desc->lock);
	}

	/* Wait for longstanding interrupts to trigger. */
	msleep(20);

	/*
	 * enable any unassigned irqs
	 * (we must startup again here because if a longstanding irq
	 * happened in the previous stage, it may have masked itself)
	 */
	for_each_irq_desc_reverse(i, desc) {
   
		raw_spin_lock_irq(&desc->lock);
		if (!desc->action && irq_settings_can_probe(desc)) {
   
			desc->istate |= IRQS_AUTODETECT | IRQS_WAITING;
			if (irq_startup(desc))
				desc->istate |= IRQS_PENDING;
		}
		raw_spin_unlock_irq(&desc->lock);
	}

	/*
	 * Wait for spurious interrupts to trigger
	 */
	msleep(100);

	/*
	 * Now filter out any obviously spurious interrupts
	 */
	for_each_irq_desc(i, desc) {
   
		raw_spin_lock_irq(&desc->lock);

		if (desc->istate & IRQS_AUTODETECT) {
   
			/* It triggered already - consider it spurious. */
			if (!(desc->istate & IRQS_WAITING)) {
   
				desc->istate &= ~IRQS_AUTODETECT;
				irq_shutdown(desc);
			} else
				if (i < 32)
					mask |= 1 << i;
		}
		raw_spin_unlock_irq(&desc->lock);
	}

	return mask;
}
EXPORT_SYMBOL(probe_irq_on);

probe_irq_off

/**
 *	probe_irq_off	- end an interrupt autodetect
 *	@val: mask of potential interrupts (unused)
 *
 *	Scans the unused interrupt lines and returns the line which
 *	appears to have triggered the interrupt. If no interrupt was
 *	found then zero is returned. If more than one interrupt is
 *	found then minus the first candidate is returned to indicate
 *	their is doubt.
 *
 *	The interrupt probe logic state is returned to its previous
 *	value.
 *
 *	BUGS: When used in a module (which arguably shouldn't happen)
 *	nothing prevents two IRQ probe callers from overlapping. The
 *	results of this are non-optimal.
 */
int probe_irq_off(unsigned long val)
{
   
	int i, irq_found = 0, nr_of_irqs = 0;
	struct irq_desc *desc;

	for_each_irq_desc(i, desc) {
   
		raw_spin_lock_irq(&desc->lock);

		if (desc->istate & IRQS_AUTODETECT) {
   
			if (!(desc->istate & IRQS_WAITING)) {
   
				if (!nr_of_irqs)
					irq_found = i;
				nr_of_irqs++;
			}
			desc->istate &= ~IRQS_AUTODETECT;
			irq_shutdown(desc);
		}
		raw_spin_unlock_irq(&desc->lock);
	}
	mutex_unlock(&probing_active);

	if (nr_of_irqs > 1)
		irq_found = -irq_found;

	return irq_found;
}
EXPORT_SYMBOL(probe_irq_off);

相关推荐

  1. Linux硬件中断IRQ基础知识

    2024-01-31 22:56:02       22 阅读
  2. linux irq

    2024-01-31 22:56:02       31 阅读
  3. 探索Spring Boot自动配置机制

    2024-01-31 22:56:02       26 阅读
  4. <span style='color:red;'>Linux</span> <span style='color:red;'>IRC</span>

    Linux IRC

    2024-01-31 22:56:02      42 阅读
  5. 深入探索Spring Boot自动配置机制

    2024-01-31 22:56:02       41 阅读
  6. Linux中断中断处理

    2024-01-31 22:56:02       52 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-31 22:56:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-31 22:56:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-31 22:56:02       87 阅读
  4. Python语言-面向对象

    2024-01-31 22:56:02       96 阅读

热门阅读

  1. 242. 有效的字母异位词(力扣LeetCode)

    2024-01-31 22:56:02       57 阅读
  2. Vue之在iframe标签里刷新外部页面

    2024-01-31 22:56:02       61 阅读
  3. docker程序镜像的安装

    2024-01-31 22:56:02       54 阅读
  4. MySQL-约束

    2024-01-31 22:56:02       52 阅读
  5. C++ easyX小程序:画五角星

    2024-01-31 22:56:02       53 阅读
  6. 使用Windows API实现屏幕截图及服务器传输

    2024-01-31 22:56:02       61 阅读
  7. SQL Server 函数参考手册

    2024-01-31 22:56:02       54 阅读
  8. Filebeat日志采集到Logstash再到Elasticsearch集群

    2024-01-31 22:56:02       66 阅读
  9. c++11学习笔记

    2024-01-31 22:56:02       73 阅读