中断映射和中断DTS解析

本文介绍了Linux驱动中中断映射的过程,通过`irq_of_parse_and_map`等函数解析DTS配置,获取中断信息,并通过`irq_create_mapping`系列函数将硬件中断号与`allocated_irqs`建立对应关系。中断属性在DTS中定义,包括`interrupts`、`interrupt-parent`等,其解析方式取决于设备中断控制器的特性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

中断映射的大体过程如下:
在这里插入图片描述
先来看一个比较典型的例子,linux驱动开源源码

static int bcm2835_mbox_probe(struct platform_device *pdev)
{
   
   
	struct device *dev = &pdev->dev;
	int ret = 0;
	struct resource *iomem;
	struct bcm2835_mbox *mbox;

	mbox = devm_kzalloc(dev, sizeof(*mbox), GFP_KERNEL);
	if (mbox == NULL)
		return -ENOMEM;
	spin_lock_init(&mbox->lock);

	ret = devm_request_irq(dev, irq_of_parse_and_map(dev->of_node, 0),
			       bcm2835_mbox_irq, 0, dev_name(dev), mbox);
	if (ret) {
   
   
		dev_err(dev, "Failed to register a mailbox IRQ handler: %d\n",
			ret);
		return -ENODEV;
	}

irq_of_parse_and_map(dev->of_node, 0)这是我们比较常用的方法。 dev->of_node这是dts解析生成的结构体数据,0 这是中断数组下标表示你要映射的第几个中断。现在来看源码

1.irq_of_parse_and_map

unsigned int irq_of_parse_and_map(struct device_node *dev, int index)
{
   
   
	struct of_phandle_args oirq;

	//解析一个irq,读取其配置值
	if (of_irq_parse_one(dev, index, &oirq))
		return 0;
	//获取映射后的irq
	return irq_create_of_mapping(&oirq);
}

2.of_irq_parse_one

int of_irq_parse_one(struct device_node *device, int index, struct of_phandle_args *out_irq)
{
   
   
	struct device_node *p;
	const __be32 *intspec, *tmp, *addr;
	u32 intsize, intlen;
	int i, res;

	pr_debug("of_irq_parse_one: dev=%s, index=%d\n", of_node_full_name(device), index);

	/* OldWorld mac stuff is "special", handle out of line */
	if (of_irq_workarounds & OF_IMAP_OLDWORLD_MAC)
		return of_irq_parse_oldworld(device, index, out_irq);

	/* Get the reg property (if any) */
	addr = of_get_property(device, "reg", NULL);

	/* Try the new-style interrupts-extended first */
	res = of_parse_phandle_with_args(device, "interrupts-extended",
					"#interrupt-cells", index
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bruk_spp

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值