Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1C394C433EF for ; Tue, 12 Apr 2022 07:23:11 +0000 (UTC) Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94.2) (envelope-from ) id 1neArW-0004ur-0j; Tue, 12 Apr 2022 03:22:54 -0400 Received: from mscreen.etri.re.kr ([129.254.9.16]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA (Exim 4.94.2) (envelope-from ) id 1neArS-0004tJ-IJ for kernelnewbies@kernelnewbies.org; Tue, 12 Apr 2022 03:22:51 -0400 Received: from unknown (HELO send001-relay.gov-dooray.com) (211.180.235.152) by 129.254.9.16 with ESMTP; 12 Apr 2022 16:22:44 +0900 X-Original-SENDERIP: 211.180.235.152 X-Original-MAILFROM: ckim@etri.re.kr X-Original-RCPTTO: kernelnewbies@kernelnewbies.org Received: from [10.162.225.106] (HELO smtp001-imp.gov-dooray.com) ([10.162.225.106]) by send001-relay.gov-dooray.com with SMTP id 5ce4241e625528c4; Tue, 12 Apr 2022 16:22:44 +0900 DKIM-Signature: a=rsa-sha256; b=Z4QPTTZiyrod8y/GSoNz1XlJ/cU+lY0efMC3zg8s05vz9UMS2gBw0xKa8kEgNwifBp7sr5gqmh ncbsa+MtUbfPRrV9NB+BECKGoEfgnCsgu5VRty1sRPwqgNfa5dIVcRO+AJjDJKiGdHZuXL1rI6G1 yWxS79lwziTiqdx6oEJCaVswSevL0D1h2u/Ib9I+xsDqo+ZyOlnl9m4ngghYi2bQFdwmafSmMdUm 9CwUtgpDleYz1JPoR4ZtsfK8iScRby6K2tGT4e6SFlhHXvzwldWQiGw6gbKiP5vj/s8M6Vb9BT+9 zNY6iSKbFxUEh+74VYDdUdObbVweUKtxOi0yxCFQ==; c=relaxed/relaxed; s=selector; d=dooray.com; v=1; bh=qVTbx0DIxhUGj5oPNb2Ey4BfJFra2OO91u8SWm0P9yY=; h=From:To:Subject:Message-ID; Received: from [129.254.132.39] (HELO CHANKIMPC) ([129.254.132.39]) by smtp001-imp.gov-dooray.com with SMTP id 4058b184625528c3; Tue, 12 Apr 2022 16:22:43 +0900 From: "Chan Kim" To: "'Ozgur Karatas'" References: <049201d84b04$951cbab0$bf563010$@etri.re.kr> <06c401d84da0$bc1a5ca0$344f15e0$@etri.re.kr> <06cf01d84da5$f7a1fa80$e6e5ef80$@etri.re.kr> <06fc01d84dae$a9e4ebf0$fdaec3d0$@etri.re.kr> <07e201d84e17$28dff590$7a9fe0b0$@etri.re.kr> In-Reply-To: Subject: RE: Can't understand /proc/interrupts output for GICv3 case Date: Tue, 12 Apr 2022 16:22:43 +0900 Message-ID: <080801d84e3e$19f3da20$4ddb8e60$@etri.re.kr> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Content-Language: ko Thread-Index: AQKunJY+kgmmewJd0lkF9aO9YfiVjAIaT1gqAvLDBPgCO+ksNAHbZ20SANY7s3IBjFOXBAFrftpxAY82MGuqyzQ+wA== Cc: 'Greg KH' , 'qemu-discuss' , kernelnewbies@kernelnewbies.org X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============6497984888537221344==" Errors-To: kernelnewbies-bounces@kernelnewbies.org This is a multipart message in MIME format. --===============6497984888537221344== Content-Type: multipart/alternative; boundary="----=_NextPart_000_0809_01D84E89.89DF2BA0" Content-Language: ko This is a multipart message in MIME format. ------=_NextPart_000_0809_01D84E89.89DF2BA0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Ozgur, 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. And if I don=E2=80=99t pass IRQF_SHARED, the kernel would have assigned = a dedicated irq_desc so it will not be a problem. And about irq 6 for floppy, isn=E2=80=99t it for intel specific? This = irq number is virtual so I think kernel will assign the number as shared = or dedicated I think. 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. Thank you! (and I=E2=80=99ll be reading the references again soon) Chan =20 =20 From: Ozgur Karatas =20 Sent: Tuesday, April 12, 2022 4:15 PM To: Chan Kim Cc: Greg KH ; kernelnewbies@kernelnewbies.org; = qemu-discuss Subject: Re: Can't understand /proc/interrupts output for GICv3 case =20 =20 On Tue, Apr 12, 2022 at 6:44 AM Chan Kim > wrote: Hi Ozgur,=20 My replies in-line. Thanks! =20 Hello Chan, =20 today, web-based online content is gaining more importance than books = especially in kernel.org you can browse serious = content about IRQ and see examples. =20 https://www.kernel.org/doc/html/v4.12/core-api/genericirq.html https://www.kernel.org/doc/html/ =20 You can search online. =20 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. As Greg stated, if you use a domain driver over a kernel api, kernel = would handle it in the get interrupt part. =20 Regards =20 Ozgur =20 =20 From: Ozgur Karatas >=20 Sent: Monday, April 11, 2022 11:53 PM To: Chan Kim > Cc: Greg KH >; = kernelnewbies@kernelnewbies.org = ; qemu-discuss = > Subject: Re: Can't understand /proc/interrupts output for GICv3 case =20 =20 Re-hi, =20 On Mon, Apr 11, 2022 at 6:16 PM Chan Kim > wrote: > > > What bus type is your driver written for? > > > > > That sounds very logical. In my case I added it to system bus. >=20 > What exactly do you mean by "system bus"? >=20 I meant 'sysbus' in qemu code that I showed in the qemu code. And I think it's the CPU bus. >=20 > Where is your kernel code? >=20 This is the init function of my char driver. I thought if the struct = cdev contains struct device, maybe I could use the struct device's of_node to call of_irq_get but it doesn't. And I remember I've seen the cdev in usually contained in the driver = data of platform driver(?). Can I implement platform driver in kernel module = form?=20 Below is the char driver init code. Currently it's request_irq(6, ... ) = but I want to know out the number 6 using program. If you have any advice, please tell me. static int __init chr_driver_init(void) { int ret; /* Allocating Major number */ if ((alloc_chrdev_region(&dev, 0, 1, "axpu_Dev")) < 0) { printk(KERN_INFO"Cannot allocate the major number..\n"); return -1; } printk(KERN_INFO"Major =3D %d Minor =3D = %d..\n",MAJOR(dev),MINOR(dev)); /* creating cdev structure */ cdev_init(&axpu_cdev, &fops); axpu_cdev.owner =3D THIS_MODULE; /* Adding character device to the system */ if ((cdev_add(&axpu_cdev,dev,1)) < 0) { printk(KERN_INFO "Cannot add the device to the system...\n"); goto r_class; } =20 I guess you got address 0x80000 randomly also may have this code from = stackoverflow but it wont work for you. as written stackoverflow, device_create must be a character device and = an address under /sys/dev/char before getting NULL. So did you create a char device with use mknod command? =20 =3D=3D> (I don=E2=80=99t know how to remove this bar in the lefe when I = add my in-line reply in outlook..) it=E2=80=99s 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=E2=80=99s 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. =20 Actually register_chrdev will do this for you but you can do it with = mknod if you wish. =20 /* creating struct class */ if ((dev_class =3D class_create(THIS_MODULE, "axpu_class")) = =3D=3D NULL) { printk(KERN_INFO "cannot create the struct class...\n"); goto r_class; } /* for interrupt test !! */ /* for vanilla work-around.. already made by mkdev */ if ((device_create(dev_class, NULL, dev, NULL, "axpu_device")) = =3D=3D NULL) { printk(KERN_INFO "cannot create the device ..\n"); goto r_device; } else { printk(KERN_INFO "axpu_device created..\n"); } /**/ vaddr =3D ioremap(AXPU_BASE, 0x80000); \ =20 Please first read Documentation/devices.txt because kernel can do = dynamic allocation I think. * = https://www.oreilly.com/library/view/linux-device-drivers/0596000081/ch03= s02.html * = https://www.oreilly.com/library/view/linux-device-drivers/0596005903/ch03= .html =20 =3D=3D> 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.=20 =20 if(!vaddr) { printk(KERN_INFO"Failed to map the address.\n"); release_mem_region(AXPU_BASE,AXPU_SIZE); return 1; } printk("----- AXPU_BASE mapped at vaddr =3D %px\n", vaddr); ret =3D request_irq(6, axpu_irq_handler, IRQF_SHARED, = "axpu_irq", &axpu_cdev); printk("request_irq returned %d\n", ret); // -EINVAL printk(KERN_INFO "Device driver inserted ..done properly..\n"); return 0; =20 You dont need to call manual, because it is defined in cdev.h. * = https://embeddedguruji.blogspot.com/2019/01/automatically-creating-device= -nodes.html =20 =3D=3D> your link doesn=E2=80=99t 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=E2=80=99s a kernel module which is inserted after OS has = booted. I thinks this should be possible. =20 in example for example device_destroy already destroys class. =20 r_device : class_destroy(dev_class); r_class : unregister_chrdev_region(dev,1); return -1; } =20 it will be great that i will recommend three books to you again. * Understanding the Linux Kernel * Linux Device Drivers * Linux Kernel Development =20 =3D=3D> Yes I=E2=80=99ve read those books here and there in the past, = but you know I=E2=80=99m not given that much time for this and my job = isn=E2=80=99t always working with linux drivers. I will take some time = to read those books thoroughly sometime later. Thanks for the interest = and advices. =20 Thank you. Chan Kim ------=_NextPart_000_0809_01D84E89.89DF2BA0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Hi Ozgur,

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.

And if I don=E2=80=99t pass IRQF_SHARED, the kernel = would have assigned a dedicated irq_desc so it will not be a = problem.

And about irq 6 for floppy, isn=E2=80=99t it for = intel specific? This irq number is virtual so I think kernel will assign = the number as shared or dedicated I think.

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.

Thank you! (and I=E2=80=99ll be reading the = references again soon)

Chan

 

 

From:<= /b> Ozgur = Karatas <ozgurk@ieee.org>
Sent: Tuesday, April 12, 2022 = 4:15 PM
To: Chan Kim <ckim@etri.re.kr>
Cc: = Greg KH <greg@kroah.com>; kernelnewbies@kernelnewbies.org; = qemu-discuss <qemu-discuss@nongnu.org>
Subject: Re: = Can't understand /proc/interrupts output for GICv3 = case

 

 

On Tue, Apr 12, 2022 at 6:44 AM = Chan Kim <ckim@etri.re.kr> = wrote:

Hi Ozgur,

My replies in-line.

Thanks!

 

Hello = Chan,

 

today, web-based online content is = gaining more importance than books especially in kernel.org you can browse serious content = about IRQ and see examples.

 

 

You can search = online.

 

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.

As Greg stated, if you use a domain driver over a kernel = api, kernel would handle it in the get interrupt = part.

 

Regards

 

          =             = Ozgur

 

 

From:<= /b> Ozgur = Karatas <ozgurk@ieee.org>
Sent: Monday, April = 11, 2022 11:53 PM
To: Chan Kim <ckim@etri.re.kr>
Cc: Greg KH <greg@kroah.com>; = kernelnewbies@kernelnewbies.org; qemu-discuss = <qemu-discuss@nongnu.org>
Subject: Re: = Can't understand /proc/interrupts output for GICv3 case

 

 

Re-hi,

 

On Mon, Apr 11, 2022 at 6:16 PM Chan Kim <ckim@etri.re.kr> = wrote:


> > > What bus type is your driver written = for?
> > >
> > That sounds very logical. In my case = I added it to system bus.
>
> What exactly do you mean by = "system bus"?
>
I meant 'sysbus' in qemu code that I = showed in the qemu code.
And I think it's the CPU bus.

> =
> Where is your kernel code?
>
This is the init = function of my char driver. I thought if the struct cdev
contains = struct device, maybe I could use the struct device's of_node to
call = of_irq_get but it doesn't.
And I remember I've seen the cdev in = usually contained in the driver data of
platform driver(?). Can I = implement platform driver in kernel module form?
Below is the char = driver init code. Currently it's request_irq(6, ... ) but
I want to = know out the number 6 using program. If you have any advice,
please = tell me.

static int __init chr_driver_init(void)
{
  =       int ret;
        /* = Allocating Major number */
        if = ((alloc_chrdev_region(&dev, 0, 1, "axpu_Dev")) < 0) = {
                = printk(KERN_INFO"Cannot allocate the major = number..\n");
              =   return -1;
        }

    =     printk(KERN_INFO"Major =3D %d Minor =3D = %d..\n",MAJOR(dev),MINOR(dev));

        = /* creating cdev structure */
        = cdev_init(&axpu_cdev, &fops);
        = axpu_cdev.owner =3D THIS_MODULE;

        /* = Adding character device to the system */
        = if ((cdev_add(&axpu_cdev,dev,1)) < 0) {
      =           printk(KERN_INFO "Cannot add the = device to the
system...\n");
        =         goto r_class;
        = }

 

I guess you got address 0x80000 randomly also may have this = code from stackoverflow but it wont work for = you.

as written stackoverflow, device_create must be a character = device and an address under /sys/dev/char before getting = NULL.

So did you create a char device with use mknod = command?

 

 =3D=3D> (I don=E2=80=99t = know how to remove this bar in the lefe when I add my in-line reply in = outlook..) it=E2=80=99s 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=E2=80=99s 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.

 

Actually register_chrdev will do this for you but you can = do it with mknod if you wish.

 

        /* creating struct class = */
        if ((dev_class =3D = class_create(THIS_MODULE, "axpu_class")) =3D=3D NULL) = {
                = printk(KERN_INFO "cannot create the struct = class...\n");
              =   goto r_class;
        }

  =       /* for interrupt test !! */
      =   /*  for vanilla work-around.. already made by mkdev = */
        if ((device_create(dev_class, NULL, = dev, NULL, "axpu_device")) =3D=3D
NULL) {
    =             printk(KERN_INFO "cannot = create the device ..\n");
          =       goto r_device;
        = }
        else { printk(KERN_INFO = "axpu_device created..\n"); }
        = /**/

        vaddr =3D ioremap(AXPU_BASE, = 0x80000);   \

 

Please first = read Documentation/devices.txt because kernel can do dynamic = allocation I think.

 

 =3D=3D> 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.

 

        if(!vaddr)
    =     {
              =   printk(KERN_INFO"Failed to map the = address.\n");
              =   release_mem_region(AXPU_BASE,AXPU_SIZE);
      =           return 1;
      =   }
        printk("----- AXPU_BASE = mapped at vaddr =3D %px\n", vaddr);

      =   ret =3D request_irq(6, axpu_irq_handler, IRQF_SHARED, = "axpu_irq",
&axpu_cdev);
        = printk("request_irq returned %d\n", ret); // -EINVAL
  =       printk(KERN_INFO "Device driver inserted = ..done properly..\n");
        return = 0;

 

You dont need to call manual, because it is defined in = cdev.h.

 

=3D=3D> your link doesn=E2=80=99t 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=E2=80=99s a = kernel module which is inserted after OS has booted. I thinks this = should be possible.

 

in example for example device_destroy already destroys = class.

  

r_device :
        = class_destroy(dev_class);

r_class :
      =   unregister_chrdev_region(dev,1);
        = return -1;
}

 

it will be great that i will recommend three books to you = again.

* Understanding the Linux Kernel
* Linux Device = Drivers

* Linux Kernel = Development

 

=3D=3D> Yes I=E2=80=99ve read those books = here and there in the past, but you know I=E2=80=99m not given that much time for this and my job = isn=E2=80=99t always working with linux = drivers. I will take some time to read those books thoroughly sometime = later.  Thanks for the interest and = advices.

 

Thank you.
Chan = Kim

------=_NextPart_000_0809_01D84E89.89DF2BA0-- --===============6497984888537221344== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies --===============6497984888537221344==--