File: dp_pci_root.go

package info (click to toggle)
golang-github-canonical-go-efilib 1.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,836 kB
  • sloc: makefile: 3
file content (41 lines) | stat: -rw-r--r-- 1,152 bytes parent folder | download
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
// Copyright 2021 Canonical Ltd.
// Licensed under the LGPLv3 with static-linking exception.
// See LICENCE file for details.

package linux

import (
	"fmt"
	"path/filepath"
	"regexp"
)

// pcirootRE matches a pcixxxx.xx path component.
var pcirootRE = regexp.MustCompile(`^pci[[:xdigit:]]{4}:[[:xdigit:]]{2}$`)

func handlePCIRootDevicePathNode(state *devicePathBuilderState) error {
	component := state.PeekUnhandledSysfsComponents(1)
	if !pcirootRE.MatchString(component) {
		return errSkipDevicePathNodeHandler
	}

	state.AdvanceSysfsPath(1)

	node, err := newACPIExtendedDevicePathNode(filepath.Join(state.SysfsPath(), "firmware_node"))
	if err != nil {
		return err
	}
	if node.HID.Vendor() != "PNP" || (node.HID.Product() != 0x0a03 && node.HID.Product() != 0x0a08) {
		return fmt.Errorf("unexpected hid: %v", node.HID)
	}
	node.HID = 0x0a0341d0

	if node.CID != 0 && (node.CID.Vendor() != "PNP" || (node.CID.Product() != 0x0a03 && node.CID.Product() != 0x0a08)) {
		return fmt.Errorf("unexpected cid: %v", node.CID)
	}

	state.Interface = interfaceTypePCI
	state.Path = append(state.Path, maybeUseSimpleACPIDevicePathNode(node))

	return nil
}