7
7
#include <linux/module.h>
8
8
#include <linux/platform_device.h>
9
9
#include <linux/slab.h>
10
+ #include <linux/of.h>
10
11
#include <linux/of_address.h>
11
12
#include <linux/of_platform.h>
12
13
13
14
#include "cxl.h"
14
15
15
-
16
- static const __be32 * read_prop_string (const struct device_node * np ,
17
- const char * prop_name )
18
- {
19
- const __be32 * prop ;
20
-
21
- prop = of_get_property (np , prop_name , NULL );
22
- return prop ;
23
- }
24
-
25
- static const __be32 * read_prop_dword (const struct device_node * np ,
26
- const char * prop_name , u32 * val )
27
- {
28
- const __be32 * prop ;
29
-
30
- prop = of_get_property (np , prop_name , NULL );
31
- if (prop )
32
- * val = be32_to_cpu (prop [0 ]);
33
- return prop ;
34
- }
35
-
36
- static const __be64 * read_prop64_dword (const struct device_node * np ,
37
- const char * prop_name , u64 * val )
38
- {
39
- const __be64 * prop ;
40
-
41
- prop = of_get_property (np , prop_name , NULL );
42
- if (prop )
43
- * val = be64_to_cpu (prop [0 ]);
44
- return prop ;
45
- }
46
-
47
-
48
- static int read_handle (struct device_node * np , u64 * handle )
49
- {
50
- const __be32 * prop ;
51
- u64 size ;
52
-
53
- /* Get address and size of the node */
54
- prop = of_get_address (np , 0 , & size , NULL );
55
- if (size )
56
- return - EINVAL ;
57
-
58
- /* Helper to read a big number; size is in cells (not bytes) */
59
- * handle = of_read_number (prop , of_n_addr_cells (np ));
60
- return 0 ;
61
- }
62
-
63
16
static int read_phys_addr (struct device_node * np , char * prop_name ,
64
17
struct cxl_afu * afu )
65
18
{
@@ -121,17 +74,12 @@ static int read_vpd(struct cxl *adapter, struct cxl_afu *afu)
121
74
122
75
int cxl_of_read_afu_handle (struct cxl_afu * afu , struct device_node * afu_np )
123
76
{
124
- if (read_handle (afu_np , & afu -> guest -> handle ))
125
- return - EINVAL ;
126
- pr_devel ("AFU handle: 0x%.16llx\n" , afu -> guest -> handle );
127
-
128
- return 0 ;
77
+ return of_property_read_reg (afu_np , 0 , & afu -> guest -> handle , NULL );
129
78
}
130
79
131
80
int cxl_of_read_afu_properties (struct cxl_afu * afu , struct device_node * np )
132
81
{
133
82
int i , rc ;
134
- const __be32 * prop ;
135
83
u16 device_id , vendor_id ;
136
84
u32 val = 0 , class_code ;
137
85
@@ -150,30 +98,29 @@ int cxl_of_read_afu_properties(struct cxl_afu *afu, struct device_node *np)
150
98
else
151
99
afu -> psa = true;
152
100
153
- read_prop_dword (np , "ibm,#processes" , & afu -> max_procs_virtualised );
101
+ of_property_read_u32 (np , "ibm,#processes" , & afu -> max_procs_virtualised );
154
102
155
103
if (cxl_verbose )
156
104
read_vpd (NULL , afu );
157
105
158
- read_prop_dword (np , "ibm,max-ints-per-process" , & afu -> guest -> max_ints );
106
+ of_property_read_u32 (np , "ibm,max-ints-per-process" , & afu -> guest -> max_ints );
159
107
afu -> irqs_max = afu -> guest -> max_ints ;
160
108
161
- prop = read_prop_dword (np , "ibm,min-ints-per-process" , & afu -> pp_irqs );
162
- if (prop ) {
109
+ if (!of_property_read_u32 (np , "ibm,min-ints-per-process" , & afu -> pp_irqs )) {
163
110
/* One extra interrupt for the PSL interrupt is already
164
111
* included. Remove it now to keep only AFU interrupts and
165
112
* match the native case.
166
113
*/
167
114
afu -> pp_irqs -- ;
168
115
}
169
116
170
- read_prop64_dword (np , "ibm,error-buffer-size" , & afu -> eb_len );
117
+ of_property_read_u64 (np , "ibm,error-buffer-size" , & afu -> eb_len );
171
118
afu -> eb_offset = 0 ;
172
119
173
- read_prop64_dword (np , "ibm,config-record-size" , & afu -> crs_len );
120
+ of_property_read_u64 (np , "ibm,config-record-size" , & afu -> crs_len );
174
121
afu -> crs_offset = 0 ;
175
122
176
- read_prop_dword (np , "ibm,#config-records" , & afu -> crs_num );
123
+ of_property_read_u32 (np , "ibm,#config-records" , & afu -> crs_num );
177
124
178
125
if (cxl_verbose ) {
179
126
for (i = 0 ; i < afu -> crs_num ; i ++ ) {
@@ -201,14 +148,12 @@ int cxl_of_read_afu_properties(struct cxl_afu *afu, struct device_node *np)
201
148
* not supported
202
149
*/
203
150
val = 0 ;
204
- prop = read_prop_dword (np , "ibm,process-mmio" , & val );
205
- if (prop && val == 1 )
151
+ if (!of_property_read_u32 (np , "ibm,process-mmio" , & val ) && val == 1 )
206
152
afu -> pp_psa = true;
207
153
else
208
154
afu -> pp_psa = false;
209
155
210
- prop = read_prop_dword (np , "ibm,function-error-interrupt" , & val );
211
- if (prop )
156
+ if (!of_property_read_u32 (np , "ibm,function-error-interrupt" , & val ))
212
157
afu -> serr_hwirq = val ;
213
158
214
159
pr_devel ("AFU handle: %#llx\n" , afu -> guest -> handle );
@@ -279,55 +224,44 @@ static int read_adapter_irq_config(struct cxl *adapter, struct device_node *np)
279
224
280
225
int cxl_of_read_adapter_handle (struct cxl * adapter , struct device_node * np )
281
226
{
282
- if (read_handle (np , & adapter -> guest -> handle ))
283
- return - EINVAL ;
284
- pr_devel ("Adapter handle: 0x%.16llx\n" , adapter -> guest -> handle );
285
-
286
- return 0 ;
227
+ return of_property_read_reg (np , 0 , & adapter -> guest -> handle , NULL );
287
228
}
288
229
289
230
int cxl_of_read_adapter_properties (struct cxl * adapter , struct device_node * np )
290
231
{
291
232
int rc ;
292
- const __be32 * prop ;
233
+ const char * p ;
293
234
u32 val = 0 ;
294
235
295
236
/* Properties are read in the same order as listed in PAPR */
296
237
297
238
if ((rc = read_adapter_irq_config (adapter , np )))
298
239
return rc ;
299
240
300
- prop = read_prop_dword (np , "ibm,caia-version" , & val );
301
- if (prop ) {
241
+ if (!of_property_read_u32 (np , "ibm,caia-version" , & val )) {
302
242
adapter -> caia_major = (val & 0xFF00 ) >> 8 ;
303
243
adapter -> caia_minor = val & 0xFF ;
304
244
}
305
245
306
- prop = read_prop_dword (np , "ibm,psl-revision" , & val );
307
- if (prop )
246
+ if (!of_property_read_u32 (np , "ibm,psl-revision" , & val ))
308
247
adapter -> psl_rev = val ;
309
248
310
- prop = read_prop_string (np , "status" );
311
- if (prop ) {
312
- adapter -> guest -> status = kasprintf (GFP_KERNEL , "%s" , (char * ) prop );
249
+ if (!of_property_read_string (np , "status" , & p )) {
250
+ adapter -> guest -> status = kasprintf (GFP_KERNEL , "%s" , p );
313
251
if (adapter -> guest -> status == NULL )
314
252
return - ENOMEM ;
315
253
}
316
254
317
- prop = read_prop_dword (np , "vendor-id" , & val );
318
- if (prop )
255
+ if (!of_property_read_u32 (np , "vendor-id" , & val ))
319
256
adapter -> guest -> vendor = val ;
320
257
321
- prop = read_prop_dword (np , "device-id" , & val );
322
- if (prop )
258
+ if (!of_property_read_u32 (np , "device-id" , & val ))
323
259
adapter -> guest -> device = val ;
324
260
325
- prop = read_prop_dword (np , "subsystem-vendor-id" , & val );
326
- if (prop )
261
+ if (!of_property_read_u32 (np , "subsystem-vendor-id" , & val ))
327
262
adapter -> guest -> subsystem_vendor = val ;
328
263
329
- prop = read_prop_dword (np , "subsystem-id" , & val );
330
- if (prop )
264
+ if (!of_property_read_u32 (np , "subsystem-id" , & val ))
331
265
adapter -> guest -> subsystem = val ;
332
266
333
267
if (cxl_verbose )
0 commit comments