Skip to contentSkip to conversation

dm: pci: Assign correct driver data when binding a driver

PATCH New Bin Meng 2 participants 8 messages Jul 25, 2018 – Jul 27, 2018 PCI

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH 1/3 dm: pci: Assign correct driver data when binding a driver

The correct driver data comes from the matching 'id' instead of 'find_id' in pci_find_and_bind_driver().

---

 drivers/pci/pci-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci-uclass.c +1 -1
index 46e9c71..7e16ad1 100644
@@ -690,7 +690,7 @@ static int pci_find_and_bind_driver(struct udevice *parent,
 			if (ret)
 				goto error;
 			debug("%s: Match found: %s\n", __func__, drv->name);
-			dev->driver_data = find_id->driver_data;
+			dev->driver_data = id->driver_data;
 			*devp = dev;
 			return 0;
 		}
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 2/3 pci: Add all known capability and extended capability ids

Currently we don't have a complete list of capability and extended capability ids. This adds them.

---

 include/pci.h | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
include/pci.h +19 -1
index 8e27cbf..cce69c4 100644
@@ -333,7 +333,21 @@
 #define  PCI_CAP_ID_SLOTID	0x04	/* Slot Identification */
 #define  PCI_CAP_ID_MSI		0x05	/* Message Signalled Interrupts */
 #define  PCI_CAP_ID_CHSWP	0x06	/* CompactPCI HotSwap */
-#define  PCI_CAP_ID_EXP 	0x10	/* PCI Express */
+#define  PCI_CAP_ID_PCIX	0x07	/* PCI-X */
+#define  PCI_CAP_ID_HT		0x08	/* HyperTransport */
+#define  PCI_CAP_ID_VNDR	0x09	/* Vendor-Specific */
+#define  PCI_CAP_ID_DBG		0x0A	/* Debug port */
+#define  PCI_CAP_ID_CCRC	0x0B	/* CompactPCI Central Resource Control */
+#define  PCI_CAP_ID_SHPC	0x0C	/* PCI Standard Hot-Plug Controller */
+#define  PCI_CAP_ID_SSVID	0x0D	/* Bridge subsystem vendor/device ID */
+#define  PCI_CAP_ID_AGP3	0x0E	/* AGP Target PCI-PCI bridge */
+#define  PCI_CAP_ID_SECDEV	0x0F	/* Secure Device */
+#define  PCI_CAP_ID_EXP		0x10	/* PCI Express */
+#define  PCI_CAP_ID_MSIX	0x11	/* MSI-X */
+#define  PCI_CAP_ID_SATA	0x12	/* SATA Data/Index Conf. */
+#define  PCI_CAP_ID_AF		0x13	/* PCI Advanced Features */
+#define  PCI_CAP_ID_EA		0x14	/* PCI Enhanced Allocation */
+#define  PCI_CAP_ID_MAX		PCI_CAP_ID_EA
 #define PCI_CAP_LIST_NEXT	1	/* Next capability in the list */
 #define PCI_CAP_FLAGS		2	/* Capability defined flags (16 bits) */
 #define PCI_CAP_SIZEOF		4
@@ -449,6 +463,10 @@
 #define PCI_EXT_CAP_ID_SECPCI	0x19	/* Secondary PCIe Capability */
 #define PCI_EXT_CAP_ID_PMUX	0x1A	/* Protocol Multiplexing */
 #define PCI_EXT_CAP_ID_PASID	0x1B	/* Process Address Space ID */
+#define PCI_EXT_CAP_ID_DPC	0x1D	/* Downstream Port Containment */
+#define PCI_EXT_CAP_ID_L1SS	0x1E	/* L1 PM Substates */
+#define PCI_EXT_CAP_ID_PTM	0x1F	/* Precision Time Measurement */
+#define PCI_EXT_CAP_ID_MAX	PCI_EXT_CAP_ID_PTM
 
 /* Include the ID list */
 
Signature · 1 line
2.7.4
author
#3 lore raw

PATCH 3/3 dm: pci: Add APIs to find capability and extended capability

In reply to Bin Meng

This introduces two new APIs dm_pci_find_capability() and dm_pci_find_ext_capability() to get PCI capability address and PCI express extended capability address for a given PCI device.

---

 drivers/pci/pci-uclass.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/pci.h            | 46 ++++++++++++++++++++++++++++++++
 2 files changed, 114 insertions(+)
drivers/pci/pci-uclass.c +68 -0
index 7e16ad1..c887989 100644
@@ -1319,6 +1319,74 @@ void *dm_pci_map_bar(struct udevice *dev, int bar, int flags)
 	return dm_pci_bus_to_virt(dev, pci_bus_addr, flags, 0, MAP_NOCACHE);
 }
 
+int dm_pci_find_capability(struct udevice *dev, int cap)
+{
+	u16 status;
+	u8 header_type;
+	int ttl = PCI_FIND_CAP_TTL;
+	u8 id;
+	u16 ent;
+	u8 pos;
+
+	dm_pci_read_config16(dev, PCI_STATUS, &status);
+	if (!(status & PCI_STATUS_CAP_LIST))
+		return 0;
+
+	dm_pci_read_config8(dev, PCI_HEADER_TYPE, &header_type);
+	if (header_type == PCI_HEADER_TYPE_CARDBUS)
+		pos = PCI_CB_CAPABILITY_LIST;
+	else
+		pos = PCI_CAPABILITY_LIST;
+
+	dm_pci_read_config8(dev, pos, &pos);
+	while (ttl--) {
+		if (pos < PCI_STD_HEADER_SIZEOF)
+			break;
+		pos &= ~3;
+		dm_pci_read_config16(dev, pos, &ent);
+
+		id = ent & 0xff;
+		if (id == 0xff)
+			break;
+		if (id == cap)
+			return pos;
+		pos = (ent >> 8);
+	}
+
+	return 0;
+}
+
+int dm_pci_find_ext_capability(struct udevice *dev, int cap)
+{
+	u32 header;
+	int ttl;
+	int pos = PCI_CFG_SPACE_SIZE;
+
+	/* minimum 8 bytes per capability */
+	ttl = (PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE) / 8;
+
+	dm_pci_read_config32(dev, pos, &header);
+	/*
+	 * If we have no capabilities, this is indicated by cap ID,
+	 * cap version and next pointer all being 0.
+	 */
+	if (header == 0)
+		return 0;
+
+	while (ttl--) {
+		if (PCI_EXT_CAP_ID(header) == cap)
+			return pos;
+
+		pos = PCI_EXT_CAP_NEXT(header);
+		if (pos < PCI_CFG_SPACE_SIZE)
+			break;
+
+		dm_pci_read_config32(dev, pos, &header);
+	}
+
+	return 0;
+}
+
 UCLASS_DRIVER(pci) = {
 	.id		= UCLASS_PCI,
 	.name		= "pci",
include/pci.h +46 -0

58 lines not on this page · raw message

Signature · 1 line
2.7.4
#4 lore raw

PATCH 3/3 dm: pci: Add APIs to find capability and extended capability

In reply to Bin Meng

Hi Bin,

Quoted 10 lines · Bin Meng

This introduces two new APIs dm_pci_find_capability() and dm_pci_find_ext_capability() to get PCI capability address and PCI express extended capability address for a given PCI device.

---

 drivers/pci/pci-uclass.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/pci.h            | 46 ++++++++++++++++++++++++++++++++
 2 files changed, 114 insertions(+)

Could you create a test for these two functions?

Regards,
Simon

author
#6 lore raw

PATCH 1/3 dm: pci: Assign correct driver data when binding a driver

In reply to Simon Glass

Hi Simon,

Quoted 7 lines · Simon Glass
Quoted 6 lines · Bin Meng

The correct driver data comes from the matching 'id' instead of 'find_id' in pci_find_and_bind_driver().

---

Quoted 6 lines
Quoted 2 lines
 drivers/pci/pci-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Perhaps the pci test should be updated to check this.

I looked at this and found out that the test to pci_bind_bus_devices(), the API that calls pci_find_and_bind_driver(), cannot be done due to a chicken and egg issue. pci_find_and_bind_driver() will only get called if no PCI device is explicitly declared in the device tree, however:

- without a emulation device (eg: "sandbox,swap-case") in the device tree, the emulation device won't be probed, hence pci_config_read() to the emulation device returns nothing
- without a vendor id & device id from pci_config_read() results, pci_find_and_bind_driver() won't work.

Do you have better ideas?

Regards,
Bin

author
#7 lore raw

PATCH 1/3 dm: pci: Assign correct driver data when binding a driver

Hi Simon,

Quoted 23 lines · Bin Meng

Hi Simon,

Quoted 7 lines · Simon Glass
Quoted 6 lines · Bin Meng

The correct driver data comes from the matching 'id' instead of 'find_id' in pci_find_and_bind_driver().

---

Quoted 6 lines
Quoted 2 lines
 drivers/pci/pci-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Perhaps the pci test should be updated to check this.

I looked at this and found out that the test to pci_bind_bus_devices(), the API that calls pci_find_and_bind_driver(), cannot be done due to a chicken and egg issue. pci_find_and_bind_driver() will only get called if no PCI device is explicitly declared in the device tree, however:

Quoted 8 lines

- without a emulation device (eg: "sandbox,swap-case") in the device tree, the emulation device won't be probed, hence pci_config_read() to the emulation device returns nothing
- without a vendor id & device id from pci_config_read() results, pci_find_and_bind_driver() won't work.

Do you have better ideas?

Looks I figured out a way. I will send v2 to include test cases.

Regards,
Bin