The use of software-triggered interrupt SGI (IPI) in Linux [transfer]

Transfer from: https://blog.csdn.net/qq_23274715/article/details/103524515


What is the use of software-triggered interrupt SGI SGI
SGI: software-triggered interrupt (Software Generated Interrupt). In the arm processor, there are 16 SGIs, and the hardware interrupt numbers are ID0 ~ ID15. It is usually used for communication between multiple cores. SGI is usually used as IPI interrupt (inter-processor interrupts)
in the Linux kernel . In the Linux kernel, the following IPI interrupts have been defined, so when users use custom IPI interrupts, it is recommended to use these unused 8 ~ 15 Interrupt.

//arch\arm\kernel\smp.c
enum {ipi_msg_type
IPI_WAKEUP,
IPI_TIMER,
IPI_RESCHEDULE,
IPI_CALL_FUNC,
IPI_CPU_STOP,
IPI_IRQ_WORK,
IPI_COMPLETION,
IPI_CPU_BACKTRACE,
/ *
* SGI8-15 CAN BE Reserved by Secure Firmware, and THUS May
* Usable not BE by the kernel. Please keep the above limited
* to at most 8 entries.
* /
};

How to use SGI
related functions in the Linux driver
void gic_raise_softirq (const struct cpumask * mask, unsigned int irq)
Description: release a software interrupt
mask: use cpumask_of (number), passing the cpu to be controlled.
irq: interrupt number. 0 ~ 15.
Eg: gic_raise_softirq (cpumask_of (1), 14). Send 14 SGI to cpu1.
int set_ipi_handler (int ipinr, void * handler, char * desc)
Description: Apply and set the interrupt callback function of SGI.
ipinr: interrupt number. 0 ~ 15.
handler: Interrupt function pointer. The type of interrupt function required is void handler_name (void).
Desc: name. Such as "sgi14handler".
Return: Successfully returned 0.
eg: set_ipi_handler (14, ipi_kick, "sgi14handler").
Clear_ipi_handler (int ipinr)
Description: Clear the interruption of the application.
ipinr: interrupt number. 0 ~ 15.
eg: clear_ipi_handler (14).
Use steps
Use the set_ipi_handler () function to register the SGI interrupt number and callback function to be used during driver initialization.
Use the clear_ipi_handler () function to log out when the driver is uninstalled.
Call gic_raise_softirq () at a suitable place in the driver to trigger a soft interrupt.
After starting linux, use insmod to mount the written driver.
After the mount is successful, you can use cat / proc / interrupts to check whether the interrupt is applied successfully.
Part of the driver program is as follows:

/ * 1. Software interrupt number used * /
#define REV_SGI_ID 14

/ * 2. The sgi callback function, called back by the set_ipi_handler () function during initialization * /
static void ipi_kick (void)
{
printk ("ipi_kick:% d \ n", ++ kickcount);
}

/ * 3. Part of the module initialization procedure * /
static int __init char_init (void)
{
...
/ * apply for an initialization soft interrupt * /
int ret = 0;
ret = set_ipi_handler (REV_SGI_ID, ipi_kick, "Firmware kick");
if (ret) {
printk ("ipi (% d) error. \ n", REV_SGI_ID);
}
...
}

/ * 4. Unregister some programs of the module * /
static void __exit char_exit (void)
{
...
/ * logout interrupt * /
clear_ipi_handler (REV_SGI_ID);
...
}

/ * 5. Write part of the function, the user triggers a soft interrupt to use * /
static ssize_t char_write (struct file * filp, const char __user * buf, size_t cnt, loff_t * offt)
{
int revalue = 0;
char tempbuff [2];

revalue = copy_from_user (tempbuff, buf, 2);
if (revalue == 0) {
/ * trigger a soft interrupt.
1. eg: tempbuff [0] = 0, tempbuff [1] = 14; then trigger interrupt No. 14 of cpu0
1. eg: tempbuff [0] = 1, tempbuff [1] = 13; trigger interrupt No. 13 of cpu1
* /
gic_raise_softirq (cpumask_of (tempbuff [0]), tempbuff [1]);
}

return 0;
} The text after the

technical exchange
here has nothing to do with the content of the title, so you can skip it .
qq group: 825695030
WeChat public number: embedded daily
If the above article is useful to you, welcome to reward, like, comment

Like 2
————————————————
Copyright Notice: This article is an original article by CSDN blogger "theboynoName", following the CC 4.0 BY-SA copyright agreement, please attach the original source link for reprint And this statement.
Original link: https://blog.csdn.net/qq_23274715/java/article/details/103524515

Guess you like

Origin www.cnblogs.com/sky-heaven/p/12753298.html