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

TOMOYO Linux Cross Reference
Linux/arch/powerpc/sysdev/scom.c

Version: ~ [ linux-5.16-rc3 ] ~ [ linux-5.15.5 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.82 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.162 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.218 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.256 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.291 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.293 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ 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.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /arch/powerpc/sysdev/scom.c (Version linux-3.14.79) and /arch/alpha/sysdev/scom.c (Version linux-5.3.18)


  1 /*                                                  1 
  2  * Copyright 2010 Benjamin Herrenschmidt, IBM     
  3  *                <benh@kernel.crashing.org>      
  4  *     and        David Gibson, IBM Corporatio    
  5  *                                                
  6  *   This program is free software;  you can r    
  7  *   it under the terms of the GNU General Pub    
  8  *   the Free Software Foundation; either vers    
  9  *   (at your option) any later version.          
 10  *                                                
 11  *   This program is distributed in the hope t    
 12  *   but WITHOUT ANY WARRANTY;  without even t    
 13  *   MERCHANTABILITY or FITNESS FOR A PARTICUL    
 14  *   the GNU General Public License for more d    
 15  *                                                
 16  *   You should have received a copy of the GN    
 17  *   along with this program;  if not, write t    
 18  *   Foundation, Inc., 59 Temple Place, Suite     
 19  */                                               
 20                                                   
 21 #include <linux/kernel.h>                         
 22 #include <linux/debugfs.h>                        
 23 #include <linux/slab.h>                           
 24 #include <linux/export.h>                         
 25 #include <asm/debug.h>                            
 26 #include <asm/prom.h>                             
 27 #include <asm/scom.h>                             
 28 #include <asm/uaccess.h>                          
 29                                                   
 30 const struct scom_controller *scom_controller;    
 31 EXPORT_SYMBOL_GPL(scom_controller);               
 32                                                   
 33 struct device_node *scom_find_parent(struct de    
 34 {                                                 
 35         struct device_node *par, *tmp;            
 36         const u32 *p;                             
 37                                                   
 38         for (par = of_node_get(node); par;) {     
 39                 if (of_get_property(par, "scom    
 40                         break;                    
 41                 p = of_get_property(par, "scom    
 42                 tmp = par;                        
 43                 if (p == NULL)                    
 44                         par = of_get_parent(pa    
 45                 else                              
 46                         par = of_find_node_by_    
 47                 of_node_put(tmp);                 
 48         }                                         
 49         return par;                               
 50 }                                                 
 51 EXPORT_SYMBOL_GPL(scom_find_parent);              
 52                                                   
 53 scom_map_t scom_map_device(struct device_node     
 54 {                                                 
 55         struct device_node *parent;               
 56         unsigned int cells, size;                 
 57         const __be32 *prop, *sprop;               
 58         u64 reg, cnt;                             
 59         scom_map_t ret;                           
 60                                                   
 61         parent = scom_find_parent(dev);           
 62                                                   
 63         if (parent == NULL)                       
 64                 return 0;                         
 65                                                   
 66         /*                                        
 67          * We support "scom-reg" properties fo    
 68          * to a random device-tree node with a    
 69          *                                        
 70          * We also support the simple "reg" pr    
 71          * a direct child of a scom controller    
 72          *                                        
 73          * In case both exist, "scom-reg" take    
 74          */                                       
 75         prop = of_get_property(dev, "scom-reg"    
 76         sprop = of_get_property(parent, "#scom    
 77         if (!prop && parent == dev->parent) {     
 78                 prop = of_get_property(dev, "r    
 79                 sprop = of_get_property(parent    
 80         }                                         
 81         if (!prop)                                
 82                 return NULL;                      
 83         cells = sprop ? be32_to_cpup(sprop) :     
 84         size >>= 2;                               
 85                                                   
 86         if (index >= (size / (2*cells)))          
 87                 return 0;                         
 88                                                   
 89         reg = of_read_number(&prop[index * cel    
 90         cnt = of_read_number(&prop[index * cel    
 91                                                   
 92         ret = scom_map(parent, reg, cnt);         
 93         of_node_put(parent);                      
 94                                                   
 95         return ret;                               
 96 }                                                 
 97 EXPORT_SYMBOL_GPL(scom_map_device);               
 98                                                   
 99 #ifdef CONFIG_SCOM_DEBUGFS                        
100 struct scom_debug_entry {                         
101         struct device_node *dn;                   
102         struct debugfs_blob_wrapper path;         
103         char name[16];                            
104 };                                                
105                                                   
106 static ssize_t scom_debug_read(struct file *fi    
107                                size_t count, l    
108 {                                                 
109         struct scom_debug_entry *ent = filp->p    
110         u64 __user *ubuf64 = (u64 __user *)ubu    
111         loff_t off = *ppos;                       
112         ssize_t done = 0;                         
113         u64 reg, reg_cnt, val;                    
114         scom_map_t map;                           
115         int rc;                                   
116                                                   
117         if (off < 0 || (off & 7) || (count & 7    
118                 return -EINVAL;                   
119         reg = off >> 3;                           
120         reg_cnt = count >> 3;                     
121                                                   
122         map = scom_map(ent->dn, reg, reg_cnt);    
123         if (!scom_map_ok(map))                    
124                 return -ENXIO;                    
125                                                   
126         for (reg = 0; reg < reg_cnt; reg++) {     
127                 rc = scom_read(map, reg, &val)    
128                 if (!rc)                          
129                         rc = put_user(val, ubu    
130                 if (rc) {                         
131                         if (!done)                
132                                 done = rc;        
133                         break;                    
134                 }                                 
135                 ubuf64++;                         
136                 *ppos += 8;                       
137                 done += 8;                        
138         }                                         
139         scom_unmap(map);                          
140         return done;                              
141 }                                                 
142                                                   
143 static ssize_t scom_debug_write(struct file* f    
144                                 size_t count,     
145 {                                                 
146         struct scom_debug_entry *ent = filp->p    
147         u64 __user *ubuf64 = (u64 __user *)ubu    
148         loff_t off = *ppos;                       
149         ssize_t done = 0;                         
150         u64 reg, reg_cnt, val;                    
151         scom_map_t map;                           
152         int rc;                                   
153                                                   
154         if (off < 0 || (off & 7) || (count & 7    
155                 return -EINVAL;                   
156         reg = off >> 3;                           
157         reg_cnt = count >> 3;                     
158                                                   
159         map = scom_map(ent->dn, reg, reg_cnt);    
160         if (!scom_map_ok(map))                    
161                 return -ENXIO;                    
162                                                   
163         for (reg = 0; reg < reg_cnt; reg++) {     
164                 rc = get_user(val, ubuf64);       
165                 if (!rc)                          
166                         rc = scom_write(map, r    
167                 if (rc) {                         
168                         if (!done)                
169                                 done = rc;        
170                         break;                    
171                 }                                 
172                 ubuf64++;                         
173                 done += 8;                        
174         }                                         
175         scom_unmap(map);                          
176         return done;                              
177 }                                                 
178                                                   
179 static const struct file_operations scom_debug    
180         .read =         scom_debug_read,          
181         .write =        scom_debug_write,         
182         .open =         simple_open,              
183         .llseek =       default_llseek,           
184 };                                                
185                                                   
186 static int scom_debug_init_one(struct dentry *    
187                                int i)             
188 {                                                 
189         struct scom_debug_entry *ent;             
190         struct dentry *dir;                       
191                                                   
192         ent = kzalloc(sizeof(*ent), GFP_KERNEL    
193         if (!ent)                                 
194                 return -ENOMEM;                   
195                                                   
196         ent->dn = of_node_get(dn);                
197         snprintf(ent->name, 16, "%08x", i);       
198         ent->path.data = (void*) dn->full_name    
199         ent->path.size = strlen(dn->full_name)    
200                                                   
201         dir = debugfs_create_dir(ent->name, ro    
202         if (!dir) {                               
203                 of_node_put(dn);                  
204                 kfree(ent);                       
205                 return -1;                        
206         }                                         
207                                                   
208         debugfs_create_blob("devspec", 0400, d    
209         debugfs_create_file("access", 0600, di    
210                                                   
211         return 0;                                 
212 }                                                 
213                                                   
214 static int scom_debug_init(void)                  
215 {                                                 
216         struct device_node *dn;                   
217         struct dentry *root;                      
218         int i, rc;                                
219                                                   
220         root = debugfs_create_dir("scom", powe    
221         if (!root)                                
222                 return -1;                        
223                                                   
224         i = rc = 0;                               
225         for_each_node_with_property(dn, "scom-    
226                 int id = of_get_ibm_chip_id(dn    
227                 if (id == -1)                     
228                         id = i;                   
229                 rc |= scom_debug_init_one(root    
230                 i++;                              
231         }                                         
232                                                   
233         return rc;                                
234 }                                                 
235 device_initcall(scom_debug_init);                 
236 #endif /* CONFIG_SCOM_DEBUGFS */                  
237                                                   

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp