authorgravatar for ybham6@gmail.comfifty-six <ybham6@gmail.com> 2022-01-14 07:02:34-05:00
committergravatar for ybham6@gmail.comfifty-six <ybham6@gmail.com> 2022-01-14 07:02:55-05:00
loga2a2601da577dd424ea585da0449288a439871fe
tree7054ee2284703b8e55d55958e60731b736f4ff25
parentae084c5f59b0436a8fcb1b924008a16d90a9fe86

std/os/uefi: Complete DevicePathProtocol types


2 files changed, 283 insertions(+), 23 deletions(-)

lib/std/os/uefi.zig+12
......@@ -23,6 +23,18 @@ pub var system_table: *tables.SystemTable = undefined;
2323/// A handle to an event structure.
2424pub const Event = *opaque {};
2525
26pub const MacAddress = extern struct {
27 address: [32]u8,
28};
29
30pub const Ipv4Address = extern struct {
31 address: [4]u8,
32};
33
34pub const Ipv6Address = extern struct {
35 address: [16]u8,
36};
37
2638/// GUIDs must be align(8)
2739pub const Guid = extern struct {
2840 time_low: u32,
lib/std/os/uefi/protocols/device_path_protocol.zig+271-23
......@@ -265,24 +265,24 @@ pub const AcpiDevicePath = union(Subtype) {
265265};
266266
267267pub const MessagingDevicePath = union(Subtype) {
268 Atapi: void, // TODO
269 Scsi: void, // TODO
270 FibreChannel: void, // TODO
271 FibreChannelEx: void, // TODO
272 @"1394": void, // TODO
273 Usb: void, // TODO
274 Sata: void, // TODO
275 UsbWwid: void, // TODO
276 Lun: void, // TODO
277 UsbClass: void, // TODO
278 I2o: void, // TODO
279 MacAddress: void, // TODO
280 Ipv4: void, // TODO
281 Ipv6: void, // TODO
282 Vlan: void, // TODO
283 InfiniBand: void, // TODO
284 Uart: void, // TODO
285 Vendor: void, // TODO
268 Atapi: *const AtapiDevicePath,
269 Scsi: *const ScsiDevicePath,
270 FibreChannel: *const FibreChannelDevicePath,
271 FibreChannelEx: FibreChannelExDevicePath,
272 @"1394": *const F1394DevicePath,
273 Usb: *const UsbDevicePath,
274 Sata: *const SataDevicePath,
275 UsbWwid: *const UsbWwidDevicePath,
276 Lun: *const DeviceLogicalUnitDevicePath,
277 UsbClass: *const UsbClassDevicePath,
278 I2o: *const I2oDevicePath,
279 MacAddress: *const MacAddressDevicePath,
280 Ipv4: *const Ipv4DevicePath,
281 Ipv6: *const Ipv6DevicePath,
282 Vlan: *const VlanDevicePath,
283 InfiniBand: *const InfiniBandDevicePath,
284 Uart: *const UartDevicePath,
285 Vendor: *const VendorDefinedDevicePath,
286286
287287 pub const Subtype = enum(u8) {
288288 Atapi = 1,
......@@ -305,6 +305,232 @@ pub const MessagingDevicePath = union(Subtype) {
305305 Vendor = 10,
306306 _,
307307 };
308
309 pub const AtapiDevicePath = packed struct {
310 const Role = enum(u8) {
311 Master = 0,
312 Slave = 1,
313 };
314
315 const Rank = enum(u8) {
316 Primary = 0,
317 Secondary = 1,
318 };
319
320 type: DevicePathType,
321 subtype: Subtype,
322 length: u16,
323 primary_secondary: Rank,
324 slave_master: Role,
325 logical_unit_number: u16,
326 };
327
328 pub const ScsiDevicePath = packed struct {
329 type: DevicePathType,
330 subtype: Subtype,
331 length: u16,
332 target_id: u16,
333 logical_unit_number: u16,
334 };
335
336 pub const FibreChannelDevicePath = packed struct {
337 type: DevicePathType,
338 subtype: Subtype,
339 length: u16,
340 reserved: u32,
341 world_wide_name: u64,
342 logical_unit_number: u64,
343 };
344
345 pub const FibreChannelExDevicePath = packed struct {
346 type: DevicePathType,
347 subtype: Subtype,
348 length: u16,
349 reserved: u32,
350 world_wide_name: [8]u8,
351 logical_unit_number: [8]u8,
352 };
353
354 pub const F1394DevicePath = packed struct {
355 type: DevicePathType,
356 subtype: Subtype,
357 length: u16,
358 reserved: u32,
359 guid: u64,
360 };
361
362 pub const UsbDevicePath = packed struct {
363 type: DevicePathType,
364 subtype: Subtype,
365 length: u16,
366 parent_port_number: u8,
367 interface_number: u8,
368 };
369
370 pub const SataDevicePath = packed struct {
371 type: DevicePathType,
372 subtype: Subtype,
373 length: u16,
374 hba_port_number: u16,
375 port_multiplier_port_number: u16,
376 logical_unit_number: u16,
377 };
378
379 pub const UsbWwidDevicePath = packed struct {
380 type: DevicePathType,
381 subtype: Subtype,
382 length: u16,
383 interface_number: u16,
384 device_vendor_id: u16,
385 device_product_id: u16,
386
387 pub fn serial_number(self: *const UsbWwidDevicePath) []const u16 {
388 var serial_len = (self.length - @sizeOf(UsbWwidDevicePath)) / @sizeOf(u16);
389 return @ptrCast([*]u16, @ptrCast([*]u8, self) + @sizeOf(UsbWwidDevicePath))[0..serial_len];
390 }
391 };
392
393 pub const DeviceLogicalUnitDevicePath = packed struct {
394 type: DevicePathType,
395 subtype: Subtype,
396 length: u16,
397 lun: u8,
398 };
399
400 pub const UsbClassDevicePath = packed struct {
401 type: DevicePathType,
402 subtype: Subtype,
403 length: u16,
404 vendor_id: u16,
405 product_id: u16,
406 device_class: u8,
407 device_subclass: u8,
408 device_protocol: u8,
409 };
410
411 pub const I2oDevicePath = packed struct {
412 type: DevicePathType,
413 subtype: Subtype,
414 length: u16,
415 tid: u32,
416 };
417
418 pub const MacAddressDevicePath = packed struct {
419 type: DevicePathType,
420 subtype: Subtype,
421 length: u16,
422 mac_address: uefi.MacAddress,
423 if_type: u8,
424 };
425
426 pub const Ipv4DevicePath = packed struct {
427 pub const IpType = enum(u8) {
428 Dhcp = 0,
429 Static = 1,
430 };
431
432 type: DevicePathType,
433 subtype: Subtype,
434 length: u16,
435 local_ip_address: uefi.Ipv4Address,
436 remote_ip_address: uefi.Ipv4Address,
437 local_port: u16,
438 remote_port: u16,
439 network_protocol: u16,
440 static_ip_address: IpType,
441 gateway_ip_address: u32,
442 subnet_mask: u32,
443 };
444
445 pub const Ipv6DevicePath = packed struct {
446 pub const Origin = enum(u8) {
447 Manual = 0,
448 AssignedStateless = 1,
449 AssignedStateful = 2,
450 };
451
452 type: DevicePathType,
453 subtype: Subtype,
454 length: u16,
455 local_ip_address: uefi.Ipv6Address,
456 remote_ip_address: uefi.Ipv6Address,
457 local_port: u16,
458 remote_port: u16,
459 protocol: u16,
460 ip_address_origin: Origin,
461 prefix_length: u8,
462 gateway_ip_address: uefi.Ipv6Address,
463 };
464
465 pub const VlanDevicePath = packed struct {
466 type: DevicePathType,
467 subtype: Subtype,
468 length: u16,
469 vlan_id: u16,
470 };
471
472 pub const InfiniBandDevicePath = packed struct {
473 pub const ResourceFlags = packed struct {
474 pub const ControllerType = enum(u1) {
475 Ioc = 0,
476 Service = 1,
477 };
478
479 ioc_or_service: ControllerType,
480 extend_boot_environment: bool,
481 console_protocol: bool,
482 storage_protocol: bool,
483 network_protocol: bool,
484
485 // u1 + 4 * bool = 5 bits, we need a total of 32 bits
486 reserved: u27,
487 };
488
489 type: DevicePathType,
490 subtype: Subtype,
491 length: u16,
492 resource_flags: ResourceFlags,
493 port_gid: [16]u8,
494 service_id: u64,
495 target_port_id: u64,
496 device_id: u64,
497 };
498
499 pub const UartDevicePath = packed struct {
500 pub const Parity = enum(u8) {
501 Default = 0,
502 None = 1,
503 Even = 2,
504 Odd = 3,
505 Mark = 4,
506 Space = 5,
507 _,
508 };
509
510 pub const StopBits = enum(u8) {
511 Default = 0,
512 One = 1,
513 OneAndAHalf = 2,
514 Two = 3,
515 _,
516 };
517
518 type: DevicePathType,
519 subtype: Subtype,
520 length: u16,
521 reserved: u16,
522 baud_rate: u32,
523 data_bits: u8,
524 parity: Parity,
525 stop_bits: StopBits,
526 };
527
528 pub const VendorDefinedDevicePath = packed struct {
529 type: DevicePathType,
530 subtype: Subtype,
531 length: u16,
532 vendor_guid: Guid,
533 };
308534};
309535
310536pub const MediaDevicePath = union(Subtype) {
......@@ -332,24 +558,44 @@ pub const MediaDevicePath = union(Subtype) {
332558 };
333559
334560 pub const HardDriveDevicePath = packed struct {
561 pub const Format = enum(u8) {
562 LegacyMbr = 0x01,
563 GuidPartitionTable = 0x02,
564 };
565
566 pub const SignatureType = enum(u8) {
567 NoSignature = 0x00,
568 /// "32-bit signature from address 0x1b8 of the type 0x01 MBR"
569 MbrSignature = 0x01,
570 GuidSignature = 0x02,
571 };
572
335573 type: DevicePathType,
336574 subtype: Subtype,
337575 length: u16,
338 // TODO
576 partition_number: u32,
577 partition_start: u64,
578 partition_size: u64,
579 partition_signature: [16]u8,
580 partition_format: Format,
581 signature_type: SignatureType,
339582 };
340583
341584 pub const CdromDevicePath = packed struct {
342585 type: DevicePathType,
343586 subtype: Subtype,
344587 length: u16,
345 // TODO
588 boot_entry: u32,
589 partition_start: u64,
590 partition_size: u64,
346591 };
347592
348593 pub const VendorDevicePath = packed struct {
349594 type: DevicePathType,
350595 subtype: Subtype,
351596 length: u16,
352 // TODO
597 guid: Guid,
598 // vendor-defined variable data
353599 };
354600
355601 pub const FilePathDevicePath = packed struct {
......@@ -366,19 +612,21 @@ pub const MediaDevicePath = union(Subtype) {
366612 type: DevicePathType,
367613 subtype: Subtype,
368614 length: u16,
369 // TODO
615 guid: Guid,
370616 };
371617
372618 pub const PiwgFirmwareFileDevicePath = packed struct {
373619 type: DevicePathType,
374620 subtype: Subtype,
375621 length: u16,
622 fv_filename: Guid,
376623 };
377624
378625 pub const PiwgFirmwareVolumeDevicePath = packed struct {
379626 type: DevicePathType,
380627 subtype: Subtype,
381628 length: u16,
629 fv_name: Guid,
382630 };
383631
384632 pub const RelativeOffsetRangeDevicePath = packed struct {
......@@ -396,7 +644,7 @@ pub const MediaDevicePath = union(Subtype) {
396644 length: u16,
397645 start: u64,
398646 end: u64,
399 disk_type: uefi.Guid,
647 disk_type: Guid,
400648 instance: u16,
401649 };
402650};