All of lore.kernel.org
 help / color / mirror / Atom feed
* can't find device_create funtion in a driver containing cdev (habanalabs)
@ 2021-04-28 13:46 ckim
  2021-04-28 18:32 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: ckim @ 2021-04-28 13:46 UTC (permalink / raw)
  To: kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 562 bytes --]

Hello list members,

In habanalabs' goya chip driver,
(https://elixir.bootlin.com/linux/v5.4.21/source/drivers/misc/habanalabs/dev
ice.c#L1057)

I can see cdev_init, cdev_add and class_create functions. 

Cdev_init is called insde device_init_cdev and cdev_add is called from
device_cdev_sysfs_add -> cdev_device_add.

I can see class_create being called too. But I couldn't find device_create
function (which is used to make sysfs entry?)

Can anyone tell me where device_create is called? (or where alternative
method is being used?)

Thank you!

Chan Kim

 


[-- Attachment #1.2: Type: text/html, Size: 2972 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: can't find device_create funtion in a driver containing cdev (habanalabs)
  2021-04-28 13:46 can't find device_create funtion in a driver containing cdev (habanalabs) ckim
@ 2021-04-28 18:32 ` Greg KH
  2021-04-29  0:56   ` ckim
  0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2021-04-28 18:32 UTC (permalink / raw)
  To: ckim; +Cc: kernelnewbies

On Wed, Apr 28, 2021 at 10:46:21PM +0900, ckim@etri.re.kr wrote:
> Hello list members,
> 
> In habanalabs' goya chip driver,
> (https://elixir.bootlin.com/linux/v5.4.21/source/drivers/misc/habanalabs/dev
> ice.c#L1057)
> 
> I can see cdev_init, cdev_add and class_create functions. 
> 
> Cdev_init is called insde device_init_cdev and cdev_add is called from
> device_cdev_sysfs_add -> cdev_device_add.
> 
> I can see class_create being called too. But I couldn't find device_create
> function (which is used to make sysfs entry?)
> 
> Can anyone tell me where device_create is called? (or where alternative
> method is being used?)

Happens in the call to cdev_device_add()


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: can't find device_create funtion in a driver containing cdev (habanalabs)
  2021-04-28 18:32 ` Greg KH
@ 2021-04-29  0:56   ` ckim
  2021-04-29  7:29     ` 'Greg KH'
  0 siblings, 1 reply; 4+ messages in thread
From: ckim @ 2021-04-29  0:56 UTC (permalink / raw)
  To: 'Greg KH'; +Cc: kernelnewbies

Hi, Greg KH,

To me cdev_device_add seems to be calling only cdev_add(below). 
In this case since dev->devt already holds dev_t value ("hl%d"), it just
sets cdev_set_parent and cdev_add. 

int cdev_device_add(struct cdev *cdev, struct device *dev)
{       
    int rc = 0;
        
    if (dev->devt) {
        cdev_set_parent(cdev, &dev->kobj);

        rc = cdev_add(cdev, dev->devt, 1);
        if (rc)
            return rc;
    }   
    
    rc = device_add(dev);
    if (rc)
        cdev_del(cdev);

    return rc;
}

Are you sure cdev_device_add contains "device_create function"? Shouldn't
device_create be called after class_create?
Class_create is called much later inside the function device_cdev_sysfs_add
later in hl_device_init function(line 1238).

And device_cdev_sysfs_add contains this code. The hl_sysfs_init calls
device_add_groups which calls sysfs_create_groups.
Isn't this sysfs_create_groups function by any chance a group equivalent of
device_create function?

/* hl_sysfs_init() must be done after adding the device to the system */
    rc = hl_sysfs_init(hdev);
    if (rc) {
        dev_err(hdev->dev, "failed to initialize sysfs\n");
        goto delete_ctrl_cdev_device;
    }

    hdev->cdev_sysfs_created = true;

Thanks for helps and regards,

Chan Kim

> -----Original Message-----
> From: Greg KH <greg@kroah.com>
> Sent: Thursday, April 29, 2021 3:32 AM
> To: ckim@etri.re.kr
> Cc: kernelnewbies@kernelnewbies.org
> Subject: Re: can't find device_create funtion in a driver containing cdev
> (habanalabs)
> 
> On Wed, Apr 28, 2021 at 10:46:21PM +0900, ckim@etri.re.kr wrote:
> > Hello list members,
> >
> > In habanalabs' goya chip driver,
> > (https://elixir.bootlin.com/linux/v5.4.21/source/drivers/misc/habanala
> > bs/dev
> > ice.c#L1057)
> >
> > I can see cdev_init, cdev_add and class_create functions.
> >
> > Cdev_init is called insde device_init_cdev and cdev_add is called from
> > device_cdev_sysfs_add -> cdev_device_add.
> >
> > I can see class_create being called too. But I couldn't find
> > device_create function (which is used to make sysfs entry?)
> >
> > Can anyone tell me where device_create is called? (or where
> > alternative method is being used?)
> 
> Happens in the call to cdev_device_add()
> 





_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: can't find device_create funtion in a driver containing cdev (habanalabs)
  2021-04-29  0:56   ` ckim
@ 2021-04-29  7:29     ` 'Greg KH'
  0 siblings, 0 replies; 4+ messages in thread
From: 'Greg KH' @ 2021-04-29  7:29 UTC (permalink / raw)
  To: ckim; +Cc: kernelnewbies

On Thu, Apr 29, 2021 at 09:56:09AM +0900, ckim@etri.re.kr wrote:
> Hi, Greg KH,
> 
> To me cdev_device_add seems to be calling only cdev_add(below). 
> In this case since dev->devt already holds dev_t value ("hl%d"), it just
> sets cdev_set_parent and cdev_add. 
> 
> int cdev_device_add(struct cdev *cdev, struct device *dev)
> {       
>     int rc = 0;
>         
>     if (dev->devt) {
>         cdev_set_parent(cdev, &dev->kobj);
> 
>         rc = cdev_add(cdev, dev->devt, 1);
>         if (rc)
>             return rc;
>     }   
>     
>     rc = device_add(dev);

Right here is the line you are looking for.

device_create() is a wrapper around a call to device_initialize() and
device_add().  To use cdev_device_add() you have to have already called
device_initialize() which the habannalabs code already did.

Only on device_add() is the device really "added" to the driver core,
and the uevents are sent out and lots of other stuff happens.
device_create() wraps a lot of housekeeping logic up into a simpler call
if your driver doesn't need that level of flexibility, but there is no
requirement to call only it at all.

Hope this helps,

greg k-h

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-29  7:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-28 13:46 can't find device_create funtion in a driver containing cdev (habanalabs) ckim
2021-04-28 18:32 ` Greg KH
2021-04-29  0:56   ` ckim
2021-04-29  7:29     ` 'Greg KH'

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.