github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/pkg/pci/lookup.go (about) 1 // Copyright 2012-2017 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package pci 6 7 import "fmt" 8 9 const venDevFmt = "%04x" 10 11 // Lookup takes PCI and device ID values and returns human 12 // readable labels for both the vendor and device. It returns the input ID value if 13 // if label is not found in the ids map. 14 func Lookup(ids map[uint16]Vendor, vendor uint16, device uint16) (string, string) { 15 if v, ok := ids[vendor]; ok { 16 if d, ok := v.Devices[device]; ok { 17 return v.Name, string(d) 18 } 19 // If entry for device doesn't exist return the hex ID 20 return v.Name, fmt.Sprintf(venDevFmt, device) 21 } 22 // If entry for vendor doesn't exist both hex IDs 23 return fmt.Sprintf(venDevFmt, vendor), fmt.Sprintf(venDevFmt, device) 24 }