Sphinxes0o0 / notes

Learning's notes and misc.
https://sphinxes0o0.github.io/notes/
2 stars 0 forks source link

[Linux Kernel] [IRQ] sysfs exmaple #17

Open Sphinxes0o0 opened 1 year ago

Sphinxes0o0 commented 1 year ago

static ssize_t disable_show(struct kobject *kobj,
                                  struct kobj_attribute *attr, char *buf)
{
        struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
        int  irq = desc->irq_data.irq;
        ssize_t ret = 0;

    disable_irq(irq);

    ret += scnprintf(buf, PAGE_SIZE, "disable\n");

    return ret;
}
IRQ_ATTR_RO(disable);

static ssize_t enable_show(struct kobject *kobj,
                                  struct kobj_attribute *attr, char *buf)
{
        struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
        int  irq = desc->irq_data.irq;
        ssize_t ret = 0;

        enable_irq(irq);

        ret += scnprintf(buf, PAGE_SIZE, "enable\n");

        return ret;
}
IRQ_ATTR_RO(enable);

static struct attribute *irq_attrs[] = {
    &per_cpu_count_attr.attr,
    &disable_attr.attr,
    &enable_attr.attr,
    &chip_name_attr.attr,
    &hwirq_attr.attr,
    &type_attr.attr,
    &name_attr.attr,
    &actions_attr.attr,
    NULL
};
Sphinxes0o0 commented 1 year ago
cat /proc/interrupts // 查看对应的kernel 中断号

// 具体执行
cat  /sys/kernel/irq/8/disable
cat  /sys/kernel/irq/9/disable
cat  /sys/kernel/irq/5/disable
cat  /sys/kernel/irq/8/enable
cat  /sys/kernel/irq/9/enable
cat  /sys/kernel/irq/5/enable
Sphinxes0o0 commented 1 year ago

这里需要注意的是, android kernel 里面的中断号, 和 gic number 是一套对应关系

Sphinxes0o0 commented 1 year ago

文件路径: kernel/irq/irqdesc.c

需要学习一下 如何把内核的函数使能, 配置, 参数变化对应到 proc 上

Sphinxes0o0 commented 11 months ago

sysfs_example.zip 学学