-
Notifications
You must be signed in to change notification settings - Fork 2
/
DtIoProp.c
475 lines (388 loc) · 11.9 KB
/
DtIoProp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
/** @file
Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "FdtBusDxe.h"
/**
Given a string list property name and a value of one of the strings,
returns the strings index.
This is useful to look up other properties indexed by name, e.g.
foo = <value1>, <value2>, <value3>;
foo-names = "index1", "index2", "index3";
@param This A pointer to the EFI_DT_IO_PROTOCOL instance.
@param Name Property to examine.
@param Value String to search for.
@param Index Pointer for returning found index.
@retval EFI_SUCCESS String found.
@retval EFI_NOT_FOUND Could not find property or string.
@retval EFI_DEVICE_ERROR Devicetree error.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
**/
EFI_STATUS
EFIAPI
DtIoGetStringIndex (
IN EFI_DT_IO_PROTOCOL *This,
IN CONST CHAR8 *Name,
IN CONST CHAR8 *Value,
OUT UINTN *Index
)
{
EFI_STATUS Status;
UINTN CurrentIndex;
EFI_DT_PROPERTY Property;
CONST CHAR8 *EndOfString;
if ((This == NULL) || (Name == NULL) ||
(Value == NULL) || (Index == NULL))
{
return EFI_INVALID_PARAMETER;
}
Status = DtIoGetProp (This, Name, &Property);
if (EFI_ERROR (Status)) {
return Status;
}
CurrentIndex = 0;
while (Property.Iter < Property.End) {
EndOfString = AsciiStrFindEnd (Property.Iter, Property.End);
if (EndOfString == NULL) {
return EFI_NOT_FOUND;
}
if (AsciiStrCmp (Property.Iter, Value) == 0) {
*Index = CurrentIndex;
return EFI_SUCCESS;
}
CurrentIndex++;
Property.Iter = EndOfString;
}
return EFI_NOT_FOUND;
}
/**
Looks up a UINT32 property value by index.
@param This A pointer to the EFI_DT_IO_PROTOCOL instance.
@param Name Name of the property.
@param Index Index of the value to return.
@param U32 Pointer to a UINT32.
@retval EFI_SUCCESS Lookup successful.
@retval EFI_NOT_FOUND Could not find property.
@retval EFI_DEVICE_ERROR Devicetree error.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
**/
EFI_STATUS
EFIAPI
DtIoGetU32 (
IN EFI_DT_IO_PROTOCOL *This,
IN CONST CHAR8 *Name,
IN UINTN Index,
OUT UINT32 *U32
)
{
EFI_STATUS Status;
EFI_DT_PROPERTY Property;
DT_DEVICE *DtDevice;
if ((This == NULL) || (Name == NULL) || (U32 == NULL)) {
return EFI_INVALID_PARAMETER;
}
DtDevice = DT_DEV_FROM_THIS (This);
Status = DtIoGetProp (This, Name, &Property);
if (EFI_ERROR (Status)) {
return Status;
}
Status = DtIoParseProp (
This,
&Property,
EFI_DT_VALUE_U32,
Index,
U32
);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
/**
Looks up a UINT64 property value by index.
@param This A pointer to the EFI_DT_IO_PROTOCOL instance.
@param Name Name of the property.
@param Index Index of the value to return.
@param U64 Pointer to a UINT64.
@retval EFI_SUCCESS Lookup successful.
@retval EFI_NOT_FOUND Could not find property.
@retval EFI_DEVICE_ERROR Devicetree error.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
**/
EFI_STATUS
EFIAPI
DtIoGetU64 (
IN EFI_DT_IO_PROTOCOL *This,
IN CONST CHAR8 *Name,
IN UINTN Index,
OUT UINT64 *U64
)
{
EFI_STATUS Status;
EFI_DT_PROPERTY Property;
DT_DEVICE *DtDevice;
if ((This == NULL) || (Name == NULL) || (U64 == NULL)) {
return EFI_INVALID_PARAMETER;
}
DtDevice = DT_DEV_FROM_THIS (This);
Status = DtIoGetProp (This, Name, &Property);
if (EFI_ERROR (Status)) {
return Status;
}
Status = DtIoParseProp (
This,
&Property,
EFI_DT_VALUE_U64,
Index,
U64
);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
/**
Looks up an EFI_DT_U128 property value by index.
@param This A pointer to the EFI_DT_IO_PROTOCOL instance.
@param Name Name of the property.
@param Index Index of the value to return.
@param U128 Pointer to an EFI_DT_U128.
@retval EFI_SUCCESS Lookup successful.
@retval EFI_NOT_FOUND Could not find property.
@retval EFI_DEVICE_ERROR Devicetree error.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
**/
EFI_STATUS
EFIAPI
DtIoGetU128 (
IN EFI_DT_IO_PROTOCOL *This,
IN CONST CHAR8 *Name,
IN UINTN Index,
OUT EFI_DT_U128 *U128
)
{
EFI_STATUS Status;
EFI_DT_PROPERTY Property;
DT_DEVICE *DtDevice;
if ((This == NULL) || (Name == NULL) || (U128 == NULL)) {
return EFI_INVALID_PARAMETER;
}
DtDevice = DT_DEV_FROM_THIS (This);
Status = DtIoGetProp (This, Name, &Property);
if (EFI_ERROR (Status)) {
return Status;
}
Status = DtIoParseProp (
This,
&Property,
EFI_DT_VALUE_U128,
Index,
U128
);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
/**
Looks up a reg property value by index for a EFI_DT_IO_PROTOCOL instance.
@param This A pointer to the EFI_DT_IO_PROTOCOL instance.
@param Index Index of the reg value to return.
@param Reg Pointer to the EFI_DT_REG to fill.
@retval EFI_SUCCESS Lookup successful.
@retval EFI_NOT_FOUND Could not find property.
@retval EFI_DEVICE_ERROR Devicetree error.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
**/
EFI_STATUS
EFIAPI
DtIoGetReg (
IN EFI_DT_IO_PROTOCOL *This,
IN UINTN Index,
OUT EFI_DT_REG *Reg
)
{
EFI_STATUS Status;
EFI_DT_PROPERTY Property;
DT_DEVICE *DtDevice;
if ((This == NULL) || (Reg == NULL)) {
return EFI_INVALID_PARAMETER;
}
DtDevice = DT_DEV_FROM_THIS (This);
Status = DtIoGetProp (This, "reg", &Property);
if (EFI_ERROR (Status)) {
return Status;
}
Status = DtIoParseProp (
This,
&Property,
EFI_DT_VALUE_REG,
Index,
Reg
);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
/**
Looks up a reg property value by name for a EFI_DT_IO_PROTOCOL instance.
Note: Lookups by name involve examining the reg-names property.
Note 2: The returned address is in CPU space, not bus space, if these are
different.
@param This A pointer to the EFI_DT_IO_PROTOCOL instance.
@param Name Name of the reg value to return.
@param Reg Pointer to the EFI_DT_REG to fill.
@retval EFI_SUCCESS Lookup successful.
@retval EFI_NOT_FOUND Could not find property.
@retval EFI_DEVICE_ERROR Devicetree error.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
**/
EFI_STATUS
EFIAPI
DtIoGetRegByName (
IN EFI_DT_IO_PROTOCOL *This,
IN CHAR8 *Name,
OUT EFI_DT_REG *Reg
)
{
EFI_STATUS Status;
UINTN Index;
if ((This == NULL) || (Name == NULL) || (Reg == NULL)) {
return EFI_INVALID_PARAMETER;
}
Status = DtIoGetStringIndex (This, "reg-names", Name, &Index);
if (EFI_ERROR (Status)) {
return Status;
}
return DtIoGetReg (This, Index, Reg);
}
/**
Looks up a ranges property value by index.
@param This A pointer to the EFI_DT_IO_PROTOCOL instance.
@param Name Name of the ranges property to examine.
@param Index Index of the ranges value to return.
@param Range Pointer to an EFI_DT_RANGE.
@retval EFI_SUCCESS Lookup successful.
@retval EFI_NOT_FOUND Could not find property.
@retval EFI_DEVICE_ERROR Devicetree error.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
**/
EFI_STATUS
EFIAPI
DtIoGetRange (
IN EFI_DT_IO_PROTOCOL *This,
IN CHAR8 *Name,
IN UINTN Index,
OUT EFI_DT_RANGE *Range
)
{
EFI_STATUS Status;
EFI_DT_PROPERTY Property;
DT_DEVICE *DtDevice;
if ((This == NULL) || (Name == NULL) || (Range == NULL)) {
return EFI_INVALID_PARAMETER;
}
DtDevice = DT_DEV_FROM_THIS (This);
Status = DtIoGetProp (This, Name, &Property);
if (EFI_ERROR (Status)) {
return Status;
}
Status = DtIoParseProp (
This,
&Property,
EFI_DT_VALUE_RANGE,
Index,
Range
);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
/**
Looks up a string property value by index.
@param This A pointer to the EFI_DT_IO_PROTOCOL instance.
@param Name Name of the property.
@param Index Index of the string to return.
@param String Pointer to a CHAR8*.
@retval EFI_SUCCESS Lookup successful.
@retval EFI_NOT_FOUND Could not find property.
@retval EFI_DEVICE_ERROR Devicetree error.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
**/
EFI_STATUS
EFIAPI
DtIoGetString (
IN EFI_DT_IO_PROTOCOL *This,
IN CONST CHAR8 *Name,
IN UINTN Index,
OUT CONST CHAR8 **String
)
{
EFI_STATUS Status;
EFI_DT_PROPERTY Property;
DT_DEVICE *DtDevice;
if ((This == NULL) || (Name == NULL) || (String == NULL)) {
return EFI_INVALID_PARAMETER;
}
DtDevice = DT_DEV_FROM_THIS (This);
Status = DtIoGetProp (This, Name, &Property);
if (EFI_ERROR (Status)) {
return Status;
}
Status = DtIoParseProp (
This,
&Property,
EFI_DT_VALUE_STRING,
Index,
String
);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
/**
Looks up a device EFI_HANDLE from property value by index.
@param This A pointer to the EFI_DT_IO_PROTOCOL instance.
@param Name Name of the property.
@param Index Index of the device to return.
@param Handle Pointer to an EFI_HANDLE.
@retval EFI_SUCCESS Lookup successful.
@retval EFI_NOT_FOUND Could not find property.
@retval EFI_DEVICE_ERROR Devicetree error.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid.
**/
EFI_STATUS
EFIAPI
DtIoGetDevice (
IN EFI_DT_IO_PROTOCOL *This,
IN CONST CHAR8 *Name,
IN UINTN Index,
OUT EFI_HANDLE *Handle
)
{
EFI_STATUS Status;
EFI_DT_PROPERTY Property;
DT_DEVICE *DtDevice;
if ((This == NULL) || (Name == NULL) || (Handle == NULL)) {
return EFI_INVALID_PARAMETER;
}
DtDevice = DT_DEV_FROM_THIS (This);
Status = DtIoGetProp (This, Name, &Property);
if (EFI_ERROR (Status)) {
return Status;
}
Status = DtIoParseProp (
This,
&Property,
EFI_DT_VALUE_DEVICE,
Index,
Handle
);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}