<div dir="ltr"><div dir="ltr">On Tue, Apr 12, 2022 at 11:22 AM Chan Kim <<a href="mailto:ckim@etri.re.kr">ckim@etri.re.kr</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="KO"><div class="gmail-m_4674134914294380538WordSection1"><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt;font-family:"\00b9d1\00c740  \00ace0\00b515"">Hi Ozgur,<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt;font-family:"\00b9d1\00c740  \00ace0\00b515"">When I run it on ubuntu-20.04, the irq number returned was 5. (in 5.4.188 vanila, it was 6) but this irq number will depend on the hardware configuration.<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt;font-family:"\00b9d1\00c740  \00ace0\00b515"">And if I don’t pass IRQF_SHARED, the kernel would have assigned a dedicated irq_desc so it will not be a problem.<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt;font-family:"\00b9d1\00c740  \00ace0\00b515"">And about irq 6 for floppy, isn’t it for intel specific? This irq number is virtual so I think kernel will assign the number as shared or dedicated I think.<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt;font-family:"\00b9d1\00c740  \00ace0\00b515"">My app/driver is just for test so that other members can do driver test on the virtual machine so for now it suits my need.<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt;font-family:"\00b9d1\00c740  \00ace0\00b515"">Thank you! (and I’ll be reading the references again soon)</span></p></div></div></blockquote><div><br></div><div>Hello Chan,</div><div><br></div><div>I'm not experienced in this matter so information i would give would be wrong. However, if you still want to drive a driver, is best to work with kernel modules. Indeed, if you look at how linux kernel works on Interrupt Handler as an example, i think you will find a solution much easier with a use driver.<br></div><div> </div><div>Regards</div><div><br></div><div>                   Ozgur</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="KO"><div class="gmail-m_4674134914294380538WordSection1"><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt;font-family:"\00b9d1\00c740  \00ace0\00b515""><u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt;font-family:"\00b9d1\00c740  \00ace0\00b515"">Chan<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt;font-family:"\00b9d1\00c740  \00ace0\00b515""><u></u> <u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt;font-family:"\00b9d1\00c740  \00ace0\00b515""><u></u> <u></u></span></p><div style="border-top:none;border-right:none;border-bottom:none;border-left:1.5pt solid blue;padding:0cm 0cm 0cm 4pt"><div><div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0cm 0cm"><p class="MsoNormal"><b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif"> Ozgur Karatas <<a href="mailto:ozgurk@ieee.org" target="_blank">ozgurk@ieee.org</a>> <br><b>Sent:</b> Tuesday, April 12, 2022 4:15 PM<br><b>To:</b> Chan Kim <<a href="mailto:ckim@etri.re.kr" target="_blank">ckim@etri.re.kr</a>><br><b>Cc:</b> Greg KH <<a href="mailto:greg@kroah.com" target="_blank">greg@kroah.com</a>>; <a href="mailto:kernelnewbies@kernelnewbies.org" target="_blank">kernelnewbies@kernelnewbies.org</a>; qemu-discuss <<a href="mailto:qemu-discuss@nongnu.org" target="_blank">qemu-discuss@nongnu.org</a>><br><b>Subject:</b> Re: Can't understand /proc/interrupts output for GICv3 case<u></u><u></u></span></p></div></div><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p><div><div><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US">On Tue, Apr 12, 2022 at 6:44 AM Chan Kim <<a href="mailto:ckim@etri.re.kr" target="_blank">ckim@etri.re.kr</a>> wrote:<u></u><u></u></span></p></div><div><blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm"><div><div><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt;font-family:"\0000b9d1\0000c740  \0000ace0\0000b515",serif">Hi Ozgur, </span><span lang="EN-US"><u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt;font-family:"\0000b9d1\0000c740  \0000ace0\0000b515",serif">My replies in-line.</span><span lang="EN-US"><u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt;font-family:"\0000b9d1\0000c740  \0000ace0\0000b515",serif">Thanks!</span><span lang="EN-US"><u></u><u></u></span></p></div></div></blockquote><div><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US">Hello Chan,<u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US">today, web-based online content is gaining more importance than books especially in <a href="http://kernel.org" target="_blank">kernel.org</a> you can browse serious content about IRQ and see examples.<u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US"> <u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US"><a href="https://www.kernel.org/doc/html/v4.12/core-api/genericirq.html" target="_blank">https://www.kernel.org/doc/html/v4.12/core-api/genericirq.html</a><u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US"><a href="https://www.kernel.org/doc/html/" target="_blank">https://www.kernel.org/doc/html/</a><u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US">You can search online.<u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US">And you received as "6" in your last e-mail was actually a old floopy address and your code would fail if you were using a floopy.<u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US">As Greg stated, if you use a domain driver over a kernel api, kernel would handle it in the get interrupt part.<u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US">Regards<u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US">                      Ozgur<u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p></div><blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm"><div><div><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt"> </span><span lang="EN-US"><u></u><u></u></span></p><div style="border-top:none;border-right:none;border-bottom:none;border-left:1.5pt solid blue;padding:0cm 0cm 0cm 4pt"><div><div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0cm 0cm"><p class="MsoNormal"><b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif"> Ozgur Karatas <<a href="mailto:ozgurk@ieee.org" target="_blank">ozgurk@ieee.org</a>> <br><b>Sent:</b> Monday, April 11, 2022 11:53 PM<br><b>To:</b> Chan Kim <<a href="mailto:ckim@etri.re.kr" target="_blank">ckim@etri.re.kr</a>><br><b>Cc:</b> Greg KH <<a href="mailto:greg@kroah.com" target="_blank">greg@kroah.com</a>>; <a href="mailto:kernelnewbies@kernelnewbies.org" target="_blank">kernelnewbies@kernelnewbies.org</a>; qemu-discuss <<a href="mailto:qemu-discuss@nongnu.org" target="_blank">qemu-discuss@nongnu.org</a>><br><b>Subject:</b> Re: Can't understand /proc/interrupts output for GICv3 case</span><span lang="EN-US"><u></u><u></u></span></p></div></div><p class="MsoNormal"><span lang="EN-US"> <u></u><u></u></span></p><div><div><p class="MsoNormal"><span lang="EN-US"> <u></u><u></u></span></p></div><p class="MsoNormal"><span lang="EN-US">Re-hi,<u></u><u></u></span></p><div><p class="MsoNormal"><span lang="EN-US"> <u></u><u></u></span></p><div><div><p class="MsoNormal"><span lang="EN-US">On Mon, Apr 11, 2022 at 6:16 PM Chan Kim <<a href="mailto:ckim@etri.re.kr" target="_blank">ckim@etri.re.kr</a>> wrote:<u></u><u></u></span></p></div><blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin:5pt 0cm 5pt 4.8pt"><p class="MsoNormal"><span lang="EN-US"><br>> > > What bus type is your driver written for?<br>> > ><br>> > That sounds very logical. In my case I added it to system bus.<br>> <br>> What exactly do you mean by "system bus"?<br>> <br>I meant 'sysbus' in qemu code that I showed in the qemu code.<br>And I think it's the CPU bus.<br><br>> <br>> Where is your kernel code?<br>> <br>This is the init function of my char driver. I thought if the struct cdev<br>contains struct device, maybe I could use the struct device's of_node to<br>call of_irq_get but it doesn't.<br>And I remember I've seen the cdev in usually contained in the driver data of<br>platform driver(?). Can I implement platform driver in kernel module form? <br>Below is the char driver init code. Currently it's request_irq(6, ... ) but<br>I want to know out the number 6 using program. If you have any advice,<br>please tell me.<br><br>static int __init chr_driver_init(void)<br>{<br>        int ret;<br>        /* Allocating Major number */<br>        if ((alloc_chrdev_region(&dev, 0, 1, "axpu_Dev")) < 0) {<br>                printk(KERN_INFO"Cannot allocate the major number..\n");<br>                return -1;<br>        }<br><br>        printk(KERN_INFO"Major = %d Minor = %d..\n",MAJOR(dev),MINOR(dev));<br><br>        /* creating cdev structure */<br>        cdev_init(&axpu_cdev, &fops);<br>        axpu_cdev.owner = THIS_MODULE;<br><br>        /* Adding character device to the system */<br>        if ((cdev_add(&axpu_cdev,dev,1)) < 0) {<br>                printk(KERN_INFO "Cannot add the device to the<br>system...\n");<br>                goto r_class;<br>        }<u></u><u></u></span></p></blockquote><div><p class="MsoNormal"><span lang="EN-US"> <u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US">I guess you got address 0x80000 randomly also may have this code from stackoverflow but it wont work for you.<u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US">as written stackoverflow, device_create must be a character device and an address under /sys/dev/char before getting NULL.<u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US">So did you create a char device with use mknod command?<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt"> </span><span lang="EN-US"><u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US"> ==> (I don</span>’<span lang="EN-US">t know how to remove this bar in the lefe when I add my in-line reply in outlook..) it</span>’<span lang="EN-US">s the size of address range of my device. My question is, how I can get the io virtual address when 1. my driver is a kernel module and 2. It is a character driver. For platform driver I got it from the resource table, but I think it</span>’<span lang="EN-US">s an old method now and we should ask the bus as Greg-KH said. The kernel already knows the addresses because it had processed the device table.<u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt"> </span><span lang="EN-US"><u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US">Actually register_chrdev will do this for you but you can do it with mknod if you wish.<u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US"> <u></u><u></u></span></p></div><blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin:5pt 0cm 5pt 4.8pt"><p class="MsoNormal"><span lang="EN-US">        /* creating struct class */<br>        if ((dev_class = class_create(THIS_MODULE, "axpu_class")) == NULL) {<br>                printk(KERN_INFO "cannot create the struct class...\n");<br>                goto r_class;<br>        }<br><br>        /* for interrupt test !! */<br>        /*  for vanilla work-around.. already made by mkdev */<br>        if ((device_create(dev_class, NULL, dev, NULL, "axpu_device")) ==<br>NULL) {<br>                printk(KERN_INFO "cannot create the device ..\n");<br>                goto r_device;<br>        }<br>        else { printk(KERN_INFO "axpu_device created..\n"); }<br>        /**/<br><br>        vaddr = ioremap(AXPU_BASE, 0x80000);   \<u></u><u></u></span></p></blockquote><div><p class="MsoNormal"><span lang="EN-US"> <u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US">Please first read Documentation/devices.txt because kernel can do dynamic allocation I think.<u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US">* <a href="https://www.oreilly.com/library/view/linux-device-drivers/0596000081/ch03s02.html" target="_blank">https://www.oreilly.com/library/view/linux-device-drivers/0596000081/ch03s02.html</a><u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US">* <a href="https://www.oreilly.com/library/view/linux-device-drivers/0596005903/ch03.html" target="_blank">https://www.oreilly.com/library/view/linux-device-drivers/0596005903/ch03.html</a><u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US"> <u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US"> ==> I understand by using class_create and device_create, the device file is generated under /dev (without using mknod). I am using this method without problem and the app/driver runs ok on the virtual machine. <u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt"> </span><span lang="EN-US"><u></u><u></u></span></p></div><blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin:5pt 0cm 5pt 4.8pt"><p class="MsoNormal" style="margin-bottom:12pt"><span lang="EN-US">        if(!vaddr)<br>        {<br>                printk(KERN_INFO"Failed to map the address.\n");<br>                release_mem_region(AXPU_BASE,AXPU_SIZE);<br>                return 1;<br>        }<br>        printk("----- AXPU_BASE mapped at vaddr = %px\n", vaddr);<br><br>        ret = request_irq(6, axpu_irq_handler, IRQF_SHARED, "axpu_irq",<br>&axpu_cdev);<br>        printk("request_irq returned %d\n", ret); // -EINVAL<br>        printk(KERN_INFO "Device driver inserted ..done properly..\n");<br>        return 0;<u></u><u></u></span></p></blockquote><div><p class="MsoNormal"><span lang="EN-US"> <u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US">You dont need to call manual, because it is defined in cdev.h.<u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US">* <a href="https://embeddedguruji.blogspot.com/2019/01/automatically-creating-device-nodes.html" target="_blank">https://embeddedguruji.blogspot.com/2019/01/automatically-creating-device-nodes.html</a><u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US"> <u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt;font-family:"\0000b9d1\0000c740  \0000ace0\0000b515",serif">==> your link doesn</span><span style="font-size:10pt;font-family:"\0000b9d1\0000c740  \0000ace0\0000b515",serif">’<span lang="EN-US">t show do any io access or irq processing. I want to know how I can get the io virtual address and the virtual irq number from the driver. My driver is a character device driver and it</span>’<span lang="EN-US">s a kernel module which is inserted after OS has booted. I thinks this should be possible.</span></span><span lang="EN-US"><u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt"> </span><span lang="EN-US"><u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US">in example for example device_destroy already destroys class.<u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US">  <u></u><u></u></span></p></div><blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin:5pt 0cm 5pt 4.8pt"><p class="MsoNormal" style="margin-bottom:12pt"><span lang="EN-US">r_device :<br>        class_destroy(dev_class);<br><br>r_class :<br>        unregister_chrdev_region(dev,1);<br>        return -1;<br>}<u></u><u></u></span></p></blockquote><div><p class="MsoNormal"><span lang="EN-US"> <u></u><u></u></span></p></div><p class="MsoNormal"><span lang="EN-US">it will be great that i will recommend three books to you again.<br><br>* Understanding the Linux Kernel<br>* Linux Device Drivers<u></u><u></u></span></p><div><p class="MsoNormal"><span lang="EN-US">* Linux Kernel Development<u></u><u></u></span></p></div><div><p class="MsoNormal"><span lang="EN-US"> <u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt;font-family:"\0000b9d1\0000c740  \0000ace0\0000b515",serif">==> Yes I</span><span style="font-size:10pt;font-family:"\0000b9d1\0000c740  \0000ace0\0000b515",serif">’<span lang="EN-US">ve read those books here and there in the past, but you know I</span>’<span lang="EN-US">m not given that much time for this and my job isn</span>’<span lang="EN-US">t always working with linux drivers. I will take some time to read those books thoroughly sometime later.</span></span><span lang="EN-US" style="font-size:10pt"> </span><span lang="EN-US" style="font-size:10pt;font-family:"\0000b9d1\0000c740  \0000ace0\0000b515",serif"> Thanks for the interest and advices.</span><span lang="EN-US"><u></u><u></u></span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:10pt"> </span><span lang="EN-US"><u></u><u></u></span></p></div><blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin:5pt 0cm 5pt 4.8pt"><p class="MsoNormal"><span lang="EN-US">Thank you.<br>Chan Kim<u></u><u></u></span></p></blockquote></div></div></div></div></div></div></blockquote></div></div></div></div></div></blockquote></div></div>