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
pub const Acpi = union(Subtype) {
acpi: *const BaseAcpiDevicePath,
expanded_acpi: *const ExpandedAcpiDevicePath,
adr: *const AdrDevicePath,
pub const Subtype = enum(u8) {
acpi = 1,
expanded_acpi = 2,
adr = 3,
_,
};
pub const BaseAcpiDevicePath = extern struct {
type: DevicePath.Type,
subtype: Subtype,
length: u16 align(1),
hid: u32 align(1),
uid: u32 align(1),
};
comptime {
assert(12 == @sizeOf(BaseAcpiDevicePath));
assert(1 == @alignOf(BaseAcpiDevicePath));
assert(0 == @offsetOf(BaseAcpiDevicePath, "type"));
assert(1 == @offsetOf(BaseAcpiDevicePath, "subtype"));
assert(2 == @offsetOf(BaseAcpiDevicePath, "length"));
assert(4 == @offsetOf(BaseAcpiDevicePath, "hid"));
assert(8 == @offsetOf(BaseAcpiDevicePath, "uid"));
}
pub const ExpandedAcpiDevicePath = extern struct {
type: DevicePath.Type,
subtype: Subtype,
length: u16 align(1),
hid: u32 align(1),
uid: u32 align(1),
cid: u32 align(1),
// variable length u16[*:0] strings
// hid_str, uid_str, cid_str
};
comptime {
assert(16 == @sizeOf(ExpandedAcpiDevicePath));
assert(1 == @alignOf(ExpandedAcpiDevicePath));
assert(0 == @offsetOf(ExpandedAcpiDevicePath, "type"));
assert(1 == @offsetOf(ExpandedAcpiDevicePath, "subtype"));
assert(2 == @offsetOf(ExpandedAcpiDevicePath, "length"));
assert(4 == @offsetOf(ExpandedAcpiDevicePath, "hid"));
assert(8 == @offsetOf(ExpandedAcpiDevicePath, "uid"));
assert(12 == @offsetOf(ExpandedAcpiDevicePath, "cid"));
}
pub const AdrDevicePath = extern struct {
type: DevicePath.Type,
subtype: Subtype,
length: u16 align(1),
adr: u32 align(1),
// multiple adr entries can optionally follow
pub fn adrs(self: *const AdrDevicePath) []align(1) const u32 {
// self.length is a minimum of 8 with one adr which is size 4.
const entries = (self.length - 4) / @sizeOf(u32);
return @as([*]align(1) const u32, @ptrCast(&self.adr))[0..entries];
}
};
comptime {
assert(8 == @sizeOf(AdrDevicePath));
assert(1 == @alignOf(AdrDevicePath));
assert(0 == @offsetOf(AdrDevicePath, "type"));
assert(1 == @offsetOf(AdrDevicePath, "subtype"));
assert(2 == @offsetOf(AdrDevicePath, "length"));
assert(4 == @offsetOf(AdrDevicePath, "adr"));
}
}