Skip to content

Commit

Permalink
rename PCIAddress.Slot to PCIAddress.Device
Browse files Browse the repository at this point in the history
As noted by @pearsonk in #220, the PCIAddress.Slot field was a bit of a
misnomer, since the more common representation of a PCIAddress is
Bus:Device.Function, not Bus:Slot.Function. Actual PCI slot information
may be retrieved from DMI, but what we were referring to was not the
actual PCI slot information but rather the PCI address device component.

Fixes Issue #220
  • Loading branch information
jaypipes committed May 25, 2021
1 parent a7823c0 commit 9c46440
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,23 @@ The `ghw.PCIDevice` struct has the following fields:

The `ghw.PCIAddress` (which is an alias for the `ghw.pci.address.Address`
struct) contains the PCI address fields. It has a `ghw.PCIAddress.String()`
method that returns the canonical Domain:Bus:Slot.Function ([D]BSF)
representation of this Address
method that returns the canonical Domain:Bus:Device.Function ([D]BDF)
representation of this Address.

The `ghw.PCIAddress` struct has the following fields:

* `ghw.PCIAddress.Domain` is a string representing the PCI domain component of
the address.
* `ghw.PCIAddress.Bus` is a string representing the PCI bus component of
the address.
* `ghw.PCIAddress.Device` is a string representing the PCI device component of
the address.
* `ghw.PCIAddress.Function` is a string representing the PCI function component of
the address.

**NOTE**: Older versions (pre-`v0.9.0`) erroneously referred to the `Device`
field as the `Slot` field. As noted by [@pearsonk](https://github.com/pearsonk)
in [#220](https://github.com/jaypipes/ghw/issues/220), this was a misnomer.

#### Finding a PCI device by PCI address

Expand Down
18 changes: 9 additions & 9 deletions pkg/pci/address/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ var (
)
)

// Address contains the components of a PCI Address
type Address struct {
Domain string
Bus string
Slot string
Device string
Function string
}

// String() returns the canonical [D]BSF representation of this Address
// String() returns the canonical [D]BDF representation of this Address
func (addr *Address) String() string {
return addr.Domain + ":" + addr.Bus + ":" + addr.Slot + "." + addr.Function
return addr.Domain + ":" + addr.Bus + ":" + addr.Device + "." + addr.Function
}

// Given a string address, returns a complete Address struct, filled in with
// domain, bus, slot and function components. The address string may either
// be in $BUS:$SLOT.$FUNCTION (BSF) format or it can be a full PCI address
// that includes the 4-digit $DOMAIN information as well:
// $DOMAIN:$BUS:$SLOT.$FUNCTION.
// FromString returns an Address struct from an ddress string in either
// $BUS:$DEVICE.$FUNCTION (BDF) format or it can be a full PCI address that
// includes the 4-digit $DOMAIN information as well:
// $DOMAIN:$BUS:$DEVICE.$FUNCTION.
//
// Returns "" if the address string wasn't a valid PCI address.
func FromString(address string) *Address {
Expand All @@ -47,7 +47,7 @@ func FromString(address string) *Address {
return &Address{
Domain: dom,
Bus: matches[3],
Slot: matches[4],
Device: matches[4],
Function: matches[5],
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/pci/address/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestPCIAddressFromString(t *testing.T) {
expected: &pciaddr.Address{
Domain: "0000",
Bus: "00",
Slot: "00",
Device: "00",
Function: "0",
},
skipStringTest: true,
Expand All @@ -40,7 +40,7 @@ func TestPCIAddressFromString(t *testing.T) {
expected: &pciaddr.Address{
Domain: "0000",
Bus: "00",
Slot: "00",
Device: "00",
Function: "0",
},
},
Expand All @@ -49,7 +49,7 @@ func TestPCIAddressFromString(t *testing.T) {
expected: &pciaddr.Address{
Domain: "0000",
Bus: "03",
Slot: "00",
Device: "00",
Function: "0",
},
},
Expand All @@ -58,7 +58,7 @@ func TestPCIAddressFromString(t *testing.T) {
expected: &pciaddr.Address{
Domain: "0000",
Bus: "03",
Slot: "00",
Device: "00",
Function: "a",
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/pci/pci_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func getDeviceModaliasPath(ctx *context.Context, address string) string {
}
return filepath.Join(
paths.SysBusPciDevices,
pciAddr.Domain+":"+pciAddr.Bus+":"+pciAddr.Slot+"."+pciAddr.Function,
pciAddr.String(),
"modalias",
)
}
Expand Down

0 comments on commit 9c46440

Please sign in to comment.