linux Do-it-yourself 探测
探测也可以在驱动自身实现没有太大麻烦. 它是一个少有的驱动必须实现它自己的探测, 但是看它是如何工作的能够给出对这个过程的内部认识. 为此目的, short 模块进行 do- it-yourself 的 IRQ 线探测, 如果它使用 probe=2 加载.
这个机制与前面描述的相同: 使能所有未使用的中断, 接着等待并观察发生什么. 我们能 够, 然而, 利用我们对设备的知识. 常常地一个设备能够配置为使用一个 IRQ 号从 3 个 或者 4 个一套; 只探测这些 IRQ 使我们能够探测正确的一个, 不必测试所有的可能中断.
short 实现假定 3, 5, 7, 和 9 是唯一可能的 IRQ 值. 这些数实际上是一些并口设备允 许你选择的数.
下面的代码通过测试所有"可能的"中断并且查看发生的事情来探测中断. trials 数组列 出要尝试的中断, 以 0 作为结尾标志; tried 数组用来跟踪哪个处理实际上被这个驱动 注册.
int trials[] =
{
};
3, 5, 7, 9, 0
int tried[] = {0, 0, 0, 0, 0}; int i, count = 0;
/*
* install the probing handler for all possible lines. Remember
* the result (0 for success, or -EBUSY) in order to only free
* what has been acquired */ for (i = 0; trials[i]; i++)
tried[i] = request_irq(trials[i], short_probing,
SA_INTERRUPT, "short probe", NULL);
do
{
short_irq = 0; /* none got, yet */ outb_p(0x10,short_base+2); /* enable */ outb_p(0x00,short_base); outb_p(0xFF,short_base); /* toggle the bit */ outb_p(0x00,short_base+2); /* disable */ udelay(5); /* give it some time */
/* the value has been set by the handler */ if (short_irq == 0) { /* none of them? */
printk(KERN_INFO "short: no irq reported by probe\n");
}
/*
* If more than one line has been activated, the result is
* negative. We should service the interrupt (but the lpt port
* doesn't need it) and loop over again. Do it at most 5 times
*/
} while (short_irq <=0 && count++ < 5);
/* end of loop, uninstall the handler */ for (i = 0; trials[i]; i++)
if (tried[i] == 0)
free_irq(trials[i], NULL);
if (short_irq < 0)
printk("short: probe failed %i times, giving up\n", count);
你可能事先不知道"可能的" IRQ 值是什么. 在这个情况, 你需要探测所有空闲的中断, 不是限制你自己在几个 trials[]. 为探测所有的中断, 你不得不从 IRQ 0 到 IRQ NR_IRQS-1 探测, 这里 NR_IRQS 在 <asm/irq.h> 中定义并且是独立于平台的.
现在我们只缺少探测处理自己了. 处理者的角色是更新 short_irq, 根据实际收到哪个中 断. short_irq 中的 0 值意味着"什么没有", 而一个负值意味着"模糊的". 这些值选择 来和 probe_irq_off 相一致并且允许同样的代码来调用任一种 short.c 中的探测.
irqreturn_t short_probing(int irq, void *dev_id, struct pt_regs *regs)
{
if (short_irq == 0) short_irq = irq; /* found */
if (short_irq != irq) short_irq = -irq; /* ambiguous */ return IRQ_HANDLED;
}
处理的参数在后面描述. 知道 irq 是在处理的中断应当是足够的来理解刚刚展示的函数.
相关文章
- 【Linux】linux常用基本命令
- Kali linux 渗透测试技术之搭建WordPress Turnkey Linux及检测WordPress 应用程序漏洞
- 用linux mail命令发送邮件[Linux]
- STM32MP157 Linux系统移植开发篇12:Linux内核MIPI LCD驱动移植
- 如何更改 Linux 的 I/O 调度器
- Linux有问必答 - 如何在linux上安装WPS
- Linux 有问必答: 如何在红帽系linux中编译Ixgbe驱动
- 你知道 Linux 内核是如何构建的吗?
- 基于Linux的机房自动化IT运维监控
- linux 结束某个进程,并且结束子进程
- linux清理 clientmqueue 垃圾文件防止 inode 被占满
- Linux 内核kobject 层次, kset, 和子系统
- Linux 内核 启动时间
- lilybbs-faq - linux入门以及百合 Linux 版精华区导读
- Linux中使用expect脚本实现远程机器自动登录_linux shell
- Linux: ssh命令 远程登录
- Linux磁盘阵列(RAID)概述与实战
- 记录一次实验室linux系统的GPU服务器死机故障的排查——Linux系统的Power States
- Linux常用基本命令:三剑客命令之-awk内置函数用法
- linux服务器安装nodeJS步骤及踩坑记录(解决node -v报错cannot execute binary file: Exec format error的问题 - 在Linux中安装适用于arm64位的nodejs)以及node环境项目部署
- Linux 系统的日志目录
- 【数字IC验证快速入门】5、快速上手Linux下的文本编辑神器gvim
- Linux学习笔记(19)linux定时任务(crontab)
- Linux学习笔记(14)linux在6.x和7.x系列的安装与基本使用区别
- Linux学习笔记(12)linux文件目录与用户管理
- Linux学习笔记(2)linux系统信息与进程相关命令
- linux学习之防火墙,查看Linux防火墙状态,开启/关闭Linux防火墙,Linux防火墙开放5236端口