-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFdt.c
202 lines (159 loc) · 4.36 KB
/
Fdt.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
/** @file
Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "FdtBusDxe.h"
/**
Given an FdtNode, return the device_type property or the empty string.
@param[in] TreeBase Devicetree blob base
@param[in] FdtNode INTN
@retval CHAR8 * Device type or empty string.
**/
CONST CHAR8 *
FdtGetDeviceType (
IN VOID *TreeBase,
IN INTN FdtNode
)
{
CONST CHAR8 *Buf;
Buf = fdt_getprop (TreeBase, FdtNode, "device_type", NULL);
if (Buf == NULL) {
return "";
}
return Buf;
}
/**
Given an FdtNode, return the device status.
@param[in] TreeBase Devicetree blob base
@param[in] FdtNode INTN
@retval EFI_DT_STATUS Enum.
**/
EFI_DT_STATUS
FdtGetStatus (
IN VOID *TreeBase,
IN INTN FdtNode
)
{
CONST CHAR8 *Buf;
Buf = fdt_getprop (TreeBase, FdtNode, "status", NULL);
if (Buf == NULL) {
return EFI_DT_STATUS_OKAY;
}
if (AsciiStrCmp (Buf, "okay") == 0) {
return EFI_DT_STATUS_OKAY;
} else if (AsciiStrCmp (Buf, "disabled") == 0) {
return EFI_DT_STATUS_DISABLED;
} else if (AsciiStrCmp (Buf, "reserved") == 0) {
return EFI_DT_STATUS_RESERVED;
} else if (AsciiStrCmp (Buf, "fail") == 0) {
return EFI_DT_STATUS_FAIL;
} else if (AsciiStrnCmp (Buf, "fail-", 5) == 0) {
return EFI_DT_STATUS_FAIL_WITH_CONDITION;
}
return EFI_DT_STATUS_BROKEN;
}
/**
Given an FdtNode, return the size cells in *Cells.
@param[in] TreeBase Devicetree blob base
@param[in] FdtNode INTN
@param[out] Cells UINTN
@retval EFI_SUCCESS *Out is populated.
@retval Others Errors.
**/
EFI_STATUS
FdtGetSizeCells (
IN VOID *TreeBase,
IN INTN FdtNode,
OUT UINT8 *Cells
)
{
INT32 Len;
UINT8 Value;
CONST EFI_DT_CELL *Buf;
Buf = fdt_getprop (TreeBase, FdtNode, "#size-cells", &Len);
if (!Buf) {
//
// Default value in 2.3.5 #address-cells and #size-cells.
//
*Cells = 1;
return EFI_SUCCESS;
}
if (Len != sizeof (EFI_DT_CELL)) {
return EFI_DEVICE_ERROR;
}
Value = fdt32_to_cpu (*Buf);
if (Value > FDT_MAX_NCELLS) {
return EFI_DEVICE_ERROR;
}
*Cells = Value;
return EFI_SUCCESS;
}
/**
Given an FdtNode, return the address cells in *Cells.
@param[in] TreeBase Devicetree blob base
@param[in] FdtNode INTN
@param[out] Cells UINTN
@retval EFI_SUCCESS *Out is populated.
@retval Others Errors.
**/
EFI_STATUS
FdtGetAddressCells (
IN VOID *TreeBase,
IN INTN FdtNode,
OUT UINT8 *Cells
)
{
INT32 Len;
UINT8 Value;
CONST EFI_DT_CELL *Buf;
Buf = fdt_getprop (TreeBase, FdtNode, "#address-cells", &Len);
if (!Buf) {
//
// Default value in 2.3.5 #address-cells and #size-cells.
//
*Cells = 2;
return EFI_SUCCESS;
}
if (Len != sizeof (EFI_DT_CELL)) {
return EFI_DEVICE_ERROR;
}
Value = fdt32_to_cpu (*Buf);
if (Value > FDT_MAX_NCELLS) {
return EFI_DEVICE_ERROR;
}
*Cells = Value;
return EFI_SUCCESS;
}
/**
Given an FdtNode, return whether this device is critical to platform
operation (e.g. it must be connected before or during EndOfDxe event).
@param[in] TreeBase Devicetree blob base
@param[in] FdtNode INTN
@retval TRUE Device is critical.
@retval FALSE Device is not critical.
**/
BOOLEAN
FdtIsDeviceCritical (
IN VOID *TreeBase,
IN INTN FdtNode
)
{
return fdt_getprop (TreeBase, FdtNode, "fdtbuspkg,critical", NULL) != NULL;
}
#ifndef MDEPKG_NDEBUG
/**
Given an FdtNode, return whether this device is a unit test device.
@param[in] TreeBase Devicetree blob base
@param[in] FdtNode INTN
@retval TRUE Device is critical.
@retval FALSE Device is not critical.
**/
BOOLEAN
FdtIsUnitTestDevice (
IN VOID *TreeBase,
IN INTN FdtNode
)
{
return fdt_getprop (TreeBase, FdtNode, "fdtbuspkg,unit-test-device", NULL) != NULL;
}
#endif /* MDEPKG_NDEBUG */