X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Faccess.c;h=b257849a685e198418de511d2d0fed12607f850b;hb=8b122188dfd404984eb360e8d876682fe7eb1613;hp=d9911292f2e05efef8ede4144a494c73be316f86;hpb=4186391b43bf101fda08e92185359c94812e2c3d;p=pciutils.git diff --git a/lib/access.c b/lib/access.c index d991129..b257849 100644 --- a/lib/access.c +++ b/lib/access.c @@ -1,7 +1,7 @@ /* * The PCI Library -- User Access * - * Copyright (c) 1997--2014 Martin Mares + * Copyright (c) 1997--2018 Martin Mares * * Can be freely distributed and used under the terms of the GNU GPL. */ @@ -67,14 +67,25 @@ pci_get_dev(struct pci_access *a, int domain, int bus, int dev, int func) return d; } +static void +pci_free_properties(struct pci_dev *d) +{ + struct pci_property *p; + + while (p = d->properties) + { + d->properties = p->next; + pci_mfree(p); + } +} + void pci_free_dev(struct pci_dev *d) { if (d->methods->cleanup_dev) d->methods->cleanup_dev(d); + pci_free_caps(d); - pci_mfree(d->module_alias); - pci_mfree(d->label); - pci_mfree(d->phy_slot); + pci_free_properties(d); pci_mfree(d); } @@ -166,16 +177,27 @@ pci_write_block(struct pci_dev *d, int pos, byte *buf, int len) return d->methods->write(d, pos, buf, len); } +static void +pci_reset_properties(struct pci_dev *d) +{ + d->known_fields = 0; + d->phy_slot = NULL; + d->module_alias = NULL; + d->label = NULL; + pci_free_caps(d); + pci_free_properties(d); +} + int pci_fill_info_v35(struct pci_dev *d, int flags) { - if (flags & PCI_FILL_RESCAN) + unsigned int uflags = flags; + if (uflags & PCI_FILL_RESCAN) { - flags &= ~PCI_FILL_RESCAN; - d->known_fields = 0; - pci_free_caps(d); + uflags &= ~PCI_FILL_RESCAN; + pci_reset_properties(d); } - if (flags & ~d->known_fields) + if (uflags & ~d->known_fields) d->known_fields |= d->methods->fill_info(d, flags & ~d->known_fields); return d->known_fields; } @@ -201,3 +223,44 @@ pci_setup_cache(struct pci_dev *d, byte *cache, int len) d->cache = cache; d->cache_len = len; } + +char * +pci_set_property(struct pci_dev *d, u32 key, char *value) +{ + struct pci_property *p; + struct pci_property **pp = &d->properties; + + while (p = *pp) + { + if (p->key == key) + { + *pp = p->next; + pci_mfree(p); + } + else + pp = &p->next; + } + + if (!value) + return NULL; + + p = pci_malloc(d->access, sizeof(*p) + strlen(value)); + *pp = p; + p->next = NULL; + p->key = key; + strcpy(p->value, value); + + return p->value; +} + +char * +pci_get_string_property(struct pci_dev *d, u32 prop) +{ + struct pci_property *p; + + for (p = d->properties; p; p = p->next) + if (p->key == prop) + return p->value; + + return NULL; +}