Skip to content

Commit

Permalink
Merge pull request #3 from Seagate/feature/embed-pci_ids
Browse files Browse the repository at this point in the history
Use embeded pci.ids
  • Loading branch information
HJ-Fan authored Jun 21, 2023
2 parents 5fbbe3d + 78ccf87 commit 0995780
Show file tree
Hide file tree
Showing 5 changed files with 36,442 additions and 24 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ cxl-lib project repository is maintained at https://github.com/Seagate.

***cxl-lib*** follows CXL specification rev 1.1.

***pci.ids*** is the database for parsing pci vendor. User could obtain the latest version from http://pci-ids.ucw.cz/ or https://github.com/pciutils/pciids.git

## Usage

Expand Down
10 changes: 2 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ module github.com/Seagate/cxl-lib

go 1.20

require (
github.com/jaypipes/pcidb v1.0.0
k8s.io/klog/v2 v2.100.1
)
require k8s.io/klog/v2 v2.100.1

require (
github.com/go-logr/logr v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.0.0 // indirect
)
require github.com/go-logr/logr v1.2.0 // indirect
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
github.com/go-logr/logr v1.2.0 h1:QK40JKJyMdUDz+h+xvCsru/bJhvG0UxvePV0ufL/AcE=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/jaypipes/pcidb v1.0.0 h1:vtZIfkiCUE42oYbJS0TAq9XSfSmcsgo9IdxSm9qzYU8=
github.com/jaypipes/pcidb v1.0.0/go.mod h1:TnYUvqhPBzCKnH34KrIX22kAeEbDCSRJ9cqLRCuNDfk=
github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg=
k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
49 changes: 37 additions & 12 deletions pkg/cxl/cxl-util.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ import (
"strings"
"syscall"

"github.com/jaypipes/pcidb"
"k8s.io/klog/v2"

_ "embed"
)

//go:embed "pci.ids"
var pci_ids string

var PciVendor map[string]string

// Base address of PCI memory mapped configurations
var PCI_MMCONFIG_BASE_ADDR int64

Expand Down Expand Up @@ -59,18 +65,35 @@ type CxlMemAttr struct {
WriteBandwidth uint16
}

func init() {
initVendorTable()
getPciMmConfig()
ACPITables.FetchCedt()
}

func initVendorTable() {
PciVendor = make(map[string]string)
fileScanner := bufio.NewScanner(strings.NewReader(pci_ids))
fileScanner.Split(bufio.ScanLines)
for fileScanner.Scan() {
id, vendor, cut := strings.Cut(fileScanner.Text(), " ")
if cut {
if len(id) == 4 {
if !strings.HasPrefix(id, "\t") {
PciVendor[id] = vendor
}
}
}
}
}

type ACPI struct {
CEDT *cedt_table_struct
}

// ACPI tables are static, initialize via init() func
var ACPITables = ACPI{}

func init() {
getPciMmConfig()
ACPITables.FetchCedt()
}

// Update local copy of the cedt .
func (a *ACPI) FetchCedt() {
b, err := readACPI("CEDT")
Expand Down Expand Up @@ -279,13 +302,15 @@ func (c *CxlDev) GetPcieHdr() *PCIE_CONFIG_HDR {

// return the Vendor Info of the PCIe/CXL device
func (c *CxlDev) GetVendorInfo() string {
//map of vendor
Pcidbs, err := pcidb.New()
if err != nil {
fmt.Printf("Error getting PCI info: %v", err)
}
pcieHeader := parseStruct(c.PCIE, PCIE_CONFIG_HDR{})
return Pcidbs.Vendors[fmt.Sprintf("%x", pcieHeader.Vendor_ID)].Name
vendor, ok := PciVendor[fmt.Sprintf("%x", pcieHeader.Vendor_ID)]
if ok {
return vendor

} else {
return "Unkown Vendor"
}

}

// return the Vendor Info of the PCIe/CXL device
Expand Down
Loading

0 comments on commit 0995780

Please sign in to comment.