aboutsummaryrefslogtreecommitdiff
path: root/util/autoport/root.go
blob: ca75d4b3851ef5f3ddf6db568aced50a0e1431d5 (plain)
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
package main

import "fmt"

var supportedPCIDevices map[uint32]PCIDevice = map[uint32]PCIDevice{}
var PCIMap map[PCIAddr]PCIDevData = map[PCIAddr]PCIDevData{}

func ScanRoot(ctx Context) {
	for _, pciDev := range ctx.InfoSource.GetPCIList() {
		PCIMap[pciDev.PCIAddr] = pciDev
	}
	for _, pciDev := range ctx.InfoSource.GetPCIList() {
		vendevid := (uint32(pciDev.PCIDevID) << 16) | uint32(pciDev.PCIVenID)

		dev, ok := supportedPCIDevices[vendevid]
		if !ok {
			if pciDev.PCIAddr.Bus != 0 {
				fmt.Printf("Unknown PCI device %04x:%04x, assuming removable\n",
					pciDev.PCIVenID, pciDev.PCIDevID)
				continue
			}
			fmt.Printf("Unsupported PCI device %04x:%04x\n",
				pciDev.PCIVenID, pciDev.PCIDevID)
			dev = GenericPCI{Comment: fmt.Sprintf("Unsupported PCI device %04x:%04x",
				pciDev.PCIVenID, pciDev.PCIDevID)}
		}
		dev.Scan(ctx, pciDev)
	}
	dmi := ctx.InfoSource.GetDMI()
	if !dmi.IsLaptop {
		NoEC(ctx)
	} else if dmi.Vendor == "LENOVO" {
		LenovoEC(ctx)
	} else {
		FIXMEEC(ctx)
	}
}

func RegisterPCI(VenID uint16, DevID uint16, dev PCIDevice) {
	vendevid := (uint32(DevID) << 16) | uint32(VenID)
	supportedPCIDevices[vendevid] = dev
}