~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/driver-api/driver-model/device.rst

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /Documentation/driver-api/driver-model/device.rst (Version linux-6.12-rc7) and /Documentation/driver-api/driver-model/device.rst (Version linux-4.15.18)


  1 ==========================                        
  2 The Basic Device Structure                        
  3 ==========================                        
  4                                                   
  5 See the kerneldoc for the struct device.          
  6                                                   
  7                                                   
  8 Programming Interface                             
  9 ~~~~~~~~~~~~~~~~~~~~~                             
 10 The bus driver that discovers the device uses     
 11 device with the core::                            
 12                                                   
 13   int device_register(struct device * dev);       
 14                                                   
 15 The bus should initialize the following fields    
 16                                                   
 17     - parent                                      
 18     - name                                        
 19     - bus_id                                      
 20     - bus                                         
 21                                                   
 22 A device is removed from the core when its ref    
 23 0. The reference count can be adjusted using::    
 24                                                   
 25   struct device * get_device(struct device * d    
 26   void put_device(struct device * dev);           
 27                                                   
 28 get_device() will return a pointer to the stru    
 29 if the reference is not already 0 (if it's in     
 30 removed already).                                 
 31                                                   
 32 A driver can access the lock in the device str    
 33                                                   
 34   void lock_device(struct device * dev);          
 35   void unlock_device(struct device * dev);        
 36                                                   
 37                                                   
 38 Attributes                                        
 39 ~~~~~~~~~~                                        
 40                                                   
 41 ::                                                
 42                                                   
 43   struct device_attribute {                       
 44         struct attribute        attr;             
 45         ssize_t (*show)(struct device *dev, st    
 46                         char *buf);               
 47         ssize_t (*store)(struct device *dev, s    
 48                          const char *buf, size    
 49   };                                              
 50                                                   
 51 Attributes of devices can be exported by a dev    
 52                                                   
 53 Please see Documentation/filesystems/sysfs.rst    
 54 on how sysfs works.                               
 55                                                   
 56 As explained in Documentation/core-api/kobject    
 57 created before the KOBJ_ADD uevent is generate    
 58 that is by defining an attribute group.           
 59                                                   
 60 Attributes are declared using a macro called D    
 61                                                   
 62   #define DEVICE_ATTR(name,mode,show,store)       
 63                                                   
 64 Example:::                                        
 65                                                   
 66   static DEVICE_ATTR(type, 0444, type_show, NU    
 67   static DEVICE_ATTR(power, 0644, power_show,     
 68                                                   
 69 Helper macros are available for common values     
 70 can be simplified to:::                           
 71                                                   
 72   static DEVICE_ATTR_RO(type);                    
 73   static DEVICE_ATTR_RW(power);                   
 74                                                   
 75 This declares two structures of type struct de    
 76 names 'dev_attr_type' and 'dev_attr_power'. Th    
 77 organized as follows into a group::               
 78                                                   
 79   static struct attribute *dev_attrs[] = {        
 80         &dev_attr_type.attr,                      
 81         &dev_attr_power.attr,                     
 82         NULL,                                     
 83   };                                              
 84                                                   
 85   static struct attribute_group dev_group = {     
 86         .attrs = dev_attrs,                       
 87   };                                              
 88                                                   
 89   static const struct attribute_group *dev_gro    
 90         &dev_group,                               
 91         NULL,                                     
 92   };                                              
 93                                                   
 94 A helper macro is available for the common cas    
 95 above two structures can be declared using:::     
 96                                                   
 97   ATTRIBUTE_GROUPS(dev);                          
 98                                                   
 99 This array of groups can then be associated wi    
100 group pointer in struct device before device_r    
101                                                   
102         dev->groups = dev_groups;                 
103         device_register(dev);                     
104                                                   
105 The device_register() function will use the 'g    
106 device attributes and the device_unregister()     
107 to remove the device attributes.                  
108                                                   
109 Word of warning:  While the kernel allows devi    
110 device_remove_file() to be called on a device     
111 strict expectations on when attributes get cre    
112 registered in the kernel, a uevent is generate    
113 udev) that a new device is available.  If attr    
114 device is registered, then userspace won't get    
115 not know about the new attributes.                
116                                                   
117 This is important for device driver that need     
118 attributes for a device at driver probe time.     
119 calls device_create_file() on the device struc    
120 userspace will never be notified of the new at    
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php