From 9c48ed23cd16066e662b45f5ff1776b0b8a1bd4c Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 31 Dec 2018 15:28:25 +0100 Subject: [PATCH] Library: The list of capabilities is ordered properly Ordering of our cached list of capabilities now respects the original order in the device's configuration space. --- lib/caps.c | 7 +++++-- lib/pci.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/caps.c b/lib/caps.c index 00b9653..6574a10 100644 --- a/lib/caps.c +++ b/lib/caps.c @@ -15,8 +15,11 @@ pci_add_cap(struct pci_dev *d, unsigned int addr, unsigned int id, unsigned int { struct pci_cap *cap = pci_malloc(d->access, sizeof(*cap)); - cap->next = d->first_cap; - d->first_cap = cap; + if (d->last_cap) + d->last_cap->next = cap; + else + d->first_cap = cap; + d->last_cap = cap; cap->addr = addr; cap->id = id; cap->type = type; diff --git a/lib/pci.h b/lib/pci.h index a08f5ec..abee05a 100644 --- a/lib/pci.h +++ b/lib/pci.h @@ -150,6 +150,7 @@ struct pci_dev { int hdrtype; /* Cached low 7 bits of header type, -1 if unknown */ void *aux; /* Auxiliary data */ struct pci_property *properties; /* A linked list of extra properties */ + struct pci_cap *last_cap; /* Last capability in the list */ }; #define PCI_ADDR_IO_MASK (~(pciaddr_t) 0x3) -- 2.39.2