Patrick Rudolph has uploaded this change for review.

View Change

device: Add support for multiple PCI segments

Add initial support for multiple PCI segments.

Since all platforms currently only use segment 0 this is not a
functional change.

Change-Id: Iab2c97a71a650e1ceadce4f985147ce05d4e8c86
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
---
M src/acpi/acpi.c
M src/device/Kconfig
M src/device/device.c
M src/device/device_const.c
M src/device/device_util.c
M src/device/pci_device.c
M src/include/device/device.h
M src/include/device/pci_def.h
M src/include/device/pci_ops.h
M src/lib/smbios.c
M src/soc/amd/common/block/data_fabric/domain.c
11 files changed, 56 insertions(+), 18 deletions(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/77/79877/1
diff --git a/src/acpi/acpi.c b/src/acpi/acpi.c
index beba5fd..d8e0f11 100644
--- a/src/acpi/acpi.c
+++ b/src/acpi/acpi.c
@@ -150,9 +150,14 @@

static unsigned long acpi_fill_mcfg(unsigned long current)
{
- current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current,
- CONFIG_ECAM_MMCONF_BASE_ADDRESS, 0, 0,
+ for (int i = 0; i < CONFIG_ECAM_SEGMENT_COUNT; i++) {
+ current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current,
+ CONFIG_ECAM_MMCONF_BASE_ADDRESS +
+ i * CONFIG_ECAM_MMCONF_LENGTH, i,
+ i * CONFIG_ECAM_MMCONF_BUS_NUMBER,
CONFIG_ECAM_MMCONF_BUS_NUMBER - 1);
+ }
+
return current;
}

@@ -695,6 +700,7 @@

if (device->path.type == DEVICE_PATH_PCI) {
spmi->pci_device_flag = ACPI_IPMI_PCI_DEVICE_FLAG;
+ spmi->pci_segment_group = device->bus->segment;
spmi->pci_bus = device->bus->secondary;
spmi->pci_device = device->path.pci.devfn >> 3;
spmi->pci_function = device->path.pci.devfn & 0x7;
diff --git a/src/device/Kconfig b/src/device/Kconfig
index 8085bbd..501a0f0 100644
--- a/src/device/Kconfig
+++ b/src/device/Kconfig
@@ -556,6 +556,16 @@
Access mechanism (ECAM) method for accessing PCI config
address space.

+config ECAM_SEGMENT_COUNT
+ int
+ depends on ECAM_MMCONF_SUPPORT
+ default 1
+ help
+ Count of MMCONF segments. On mobile/desktop platforms this is
+ usually 1. On multi-socket server platforms this can be greater 1
+ if more than 256 PCI buses are supported. The segments are same
+ sized and continous in physical memory.
+
config PCIX_PLUGIN_SUPPORT
bool
default y
diff --git a/src/device/device.c b/src/device/device.c
index a635e73..f379de1 100644
--- a/src/device/device.c
+++ b/src/device/device.c
@@ -152,8 +152,8 @@
{
struct device *curdev;

- printk(BIOS_SPEW, "%s %s bus %d link: %d\n", dev_path(bus->dev),
- __func__, bus->secondary, bus->link_num);
+ printk(BIOS_SPEW, "%s %s segment %d bus %d link: %d\n", dev_path(bus->dev),
+ __func__, bus->segment, bus->secondary, bus->link_num);

/* Walk through all devices and find which resources they need. */
for (curdev = bus->children; curdev; curdev = curdev->sibling) {
@@ -176,8 +176,8 @@
read_resources(link);
}
post_log_clear();
- printk(BIOS_SPEW, "%s %s bus %d link: %d done\n",
- dev_path(bus->dev), __func__, bus->secondary, bus->link_num);
+ printk(BIOS_SPEW, "%s %s segment %d bus %d link: %d done\n",
+ dev_path(bus->dev), __func__, bus->segment, bus->secondary, bus->link_num);
}

struct device *vga_pri = NULL;
@@ -266,8 +266,8 @@
{
struct device *curdev;

- printk(BIOS_SPEW, "%s %s, bus %d link: %d\n",
- dev_path(bus->dev), __func__, bus->secondary, bus->link_num);
+ printk(BIOS_SPEW, "%s %s, segment %d bus %d link: %d\n",
+ dev_path(bus->dev), __func__, bus->segment, bus->secondary, bus->link_num);

for (curdev = bus->children; curdev; curdev = curdev->sibling) {
if (!curdev->enabled || !curdev->resource_list)
@@ -282,8 +282,8 @@
curdev->ops->set_resources(curdev);
}
post_log_clear();
- printk(BIOS_SPEW, "%s %s, bus %d link: %d done\n",
- dev_path(bus->dev), __func__, bus->secondary, bus->link_num);
+ printk(BIOS_SPEW, "%s %s, segment %d bus %d link: %d done\n",
+ dev_path(bus->dev), __func__, bus->segment, bus->secondary, bus->link_num);
}

/**
diff --git a/src/device/device_const.c b/src/device/device_const.c
index a63a629..b7516b1 100644
--- a/src/device/device_const.c
+++ b/src/device/device_const.c
@@ -35,6 +35,7 @@
for (dev = all_devices; dev; dev = dev->next) {
if ((dev->path.type == DEVICE_PATH_PCI) &&
(dev->bus->secondary == bus) &&
+ (dev->bus->segment == 0) &&
(dev->path.pci.devfn == devfn)) {
result = dev;
break;
@@ -224,8 +225,16 @@

DEVTREE_CONST struct device *pcidev_path_on_bus(unsigned int bus, pci_devfn_t devfn)
{
+ return pcidev_path_on_segbus(0, bus, devfn);
+}
+
+DEVTREE_CONST struct device *pcidev_path_on_segbus(unsigned int segment,
+ unsigned int bus,
+ pci_devfn_t devfn)
+{
DEVTREE_CONST struct bus *parent = pci_root_bus();
DEVTREE_CONST struct device *dev = parent->children;
+ assert(segment < CONFIG_ECAM_SEGMENT_COUNT);

/* FIXME: Write the loop with topology links. */
while (dev) {
@@ -233,7 +242,7 @@
dev = dev->next;
continue;
}
- if (dev->bus->secondary == bus)
+ if (dev->bus->secondary == bus && dev->bus->segment == segment)
return pcidev_path_behind(dev->bus, devfn);
dev = dev->next;
}
diff --git a/src/device/device_util.c b/src/device/device_util.c
index b37d1d9..fcc78e9 100644
--- a/src/device/device_util.c
+++ b/src/device/device_util.c
@@ -97,7 +97,7 @@
case DEVICE_PATH_ROOT:
break;
case DEVICE_PATH_PCI:
- ret |= dev->bus->secondary << 8 | dev->path.pci.devfn;
+ ret |= dev->bus->segment << 16 | dev->bus->secondary << 8 | dev->path.pci.devfn;
break;
case DEVICE_PATH_PNP:
ret |= dev->path.pnp.port << 8 | dev->path.pnp.device;
@@ -168,7 +168,8 @@
break;
case DEVICE_PATH_PCI:
snprintf(buffer, sizeof(buffer),
- "PCI: %02x:%02x.%01x",
+ "PCI: %02x:%02x:%02x.%01x",
+ dev->bus->segment,
dev->bus->secondary,
PCI_SLOT(dev->path.pci.devfn),
PCI_FUNC(dev->path.pci.devfn));
@@ -525,7 +526,8 @@

if (dev->link_list && (resource->flags & IORESOURCE_PCI_BRIDGE)) {
snprintf(buf, sizeof(buf),
- "bus %02x ", dev->link_list->secondary);
+ "seg %02x bus %02x ", dev->link_list->segment,
+ dev->link_list->secondary);
}
printk(BIOS_DEBUG, "%s %02lx <- [0x%016llx - 0x%016llx] size 0x%08llx "
"gran 0x%02x %s%s%s\n", dev_path(dev), resource->index,
diff --git a/src/device/pci_device.c b/src/device/pci_device.c
index 21b4352..f3fd5ee 100644
--- a/src/device/pci_device.c
+++ b/src/device/pci_device.c
@@ -1314,7 +1314,8 @@
*/
unsigned int pci_match_simple_dev(struct device *dev, pci_devfn_t sdev)
{
- return dev->bus->secondary == PCI_DEV2SEGBUS(sdev) &&
+ return dev->bus->secondary == PCI_DEV2BUS(sdev) &&
+ dev->bus->segment == PCI_DEV2SEG(sdev) &&
dev->path.pci.devfn == PCI_DEV2DEVFN(sdev);
}

@@ -1428,7 +1429,8 @@
struct device *dev, **prev;
int once = 0;

- printk(BIOS_DEBUG, "PCI: %s for bus %02x\n", __func__, bus->secondary);
+ printk(BIOS_DEBUG, "PCI: %s for segment %02x bus %02x\n", __func__,
+ bus->segment, bus->secondary);

/* Maximum sane devfn is 0xFF. */
if (max_devfn > 0xff) {
@@ -1550,6 +1552,7 @@
link->max_subordinate = parent->max_subordinate
? parent->max_subordinate
: (CONFIG_ECAM_MMCONF_BUS_NUMBER - 1);
+ link->segment = parent->segment;
}

if (link->secondary > link->max_subordinate)
diff --git a/src/include/device/device.h b/src/include/device/device.h
index 41ec528..ab73f16 100644
--- a/src/include/device/device.h
+++ b/src/include/device/device.h
@@ -86,6 +86,7 @@
uint16_t secondary; /* secondary bus number */
uint16_t subordinate; /* subordinate bus number */
uint16_t max_subordinate; /* max subordinate bus number */
+ uint8_t segment; /* PCI segment */

unsigned int reset_needed : 1;
unsigned int no_vga16 : 1; /* No support for 16-bit VGA decoding */
@@ -425,6 +426,9 @@
pci_devfn_t devfn);
DEVTREE_CONST struct device *pcidev_path_on_root(pci_devfn_t devfn);
DEVTREE_CONST struct device *pcidev_path_on_bus(unsigned int bus, pci_devfn_t devfn);
+DEVTREE_CONST struct device *pcidev_path_on_segbus(unsigned int segment,
+ unsigned int bus,
+ pci_devfn_t devfn);
DEVTREE_CONST struct device *pcidev_on_root(uint8_t dev, uint8_t fn);
DEVTREE_CONST struct bus *pci_root_bus(void);
/* Find PCI device with given D#:F# sitting behind the given PCI-to-PCI bridge device. */
diff --git a/src/include/device/pci_def.h b/src/include/device/pci_def.h
index 8b90163..7821bc1 100644
--- a/src/include/device/pci_def.h
+++ b/src/include/device/pci_def.h
@@ -594,6 +594,8 @@
/* Translation from PCI_DEV() to devicetree bus and path.pci.devfn. */
#define PCI_DEV2DEVFN(sdev) (((sdev)>>12) & 0xff)
#define PCI_DEV2SEGBUS(sdev) (((sdev)>>20) & 0xfff)
+#define PCI_DEV2BUS(sdev) (((sdev)>>20) & 0xff)
+#define PCI_DEV2SEG(sdev) (((sdev)>>28) & 0xf)

/* Fields from within the device's class value. */
#define PCI_CLASS_GET_DEVICE(c) (c >> 8)
diff --git a/src/include/device/pci_ops.h b/src/include/device/pci_ops.h
index b5d4e23..3e75be7 100644
--- a/src/include/device/pci_ops.h
+++ b/src/include/device/pci_ops.h
@@ -12,7 +12,8 @@

static __always_inline pci_devfn_t pcidev_bdf(const struct device *dev)
{
- return (dev->path.pci.devfn << 12) | (dev->bus->secondary << 20);
+ return (dev->path.pci.devfn << 12) | (dev->bus->secondary << 20) |
+ (dev->bus->segment << 28);
}

static __always_inline pci_devfn_t pcidev_assert(const struct device *dev)
diff --git a/src/lib/smbios.c b/src/lib/smbios.c
index 3ef3c21..2763a29 100644
--- a/src/lib/smbios.c
+++ b/src/lib/smbios.c
@@ -1113,7 +1113,7 @@
return smbios_write_type41(current, handle,
name, // name
instance_id, // inst
- 0, // segment
+ dev->bus->segment, // segment
dev->bus->secondary, //bus
PCI_SLOT(dev->path.pci.devfn), // device
PCI_FUNC(dev->path.pci.devfn), // func
diff --git a/src/soc/amd/common/block/data_fabric/domain.c b/src/soc/amd/common/block/data_fabric/domain.c
index 39f5790..7e7bb53 100644
--- a/src/soc/amd/common/block/data_fabric/domain.c
+++ b/src/soc/amd/common/block/data_fabric/domain.c
@@ -38,6 +38,7 @@
domain->link_list->subordinate = bus;
/* Tell allocator about maximum PCI bus number in domain */
domain->link_list->max_subordinate = limit;
+ domain->link_list->segment = segment_group;

pci_host_bridge_scan_bus(domain);
}

To view, visit change 79877. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: main
Gerrit-Change-Id: Iab2c97a71a650e1ceadce4f985147ce05d4e8c86
Gerrit-Change-Number: 79877
Gerrit-PatchSet: 1
Gerrit-Owner: Patrick Rudolph <patrick.rudolph@9elements.com>
Gerrit-MessageType: newchange