Luc Verhaegen has uploaded this change for review. ( https://review.coreboot.org/29083
Change subject: pci2: add device list printing support ......................................................................
pci2: add device list printing support
Change-Id: I3eea9edfcdf2ae1c35f4c935dca97fa93eaded58 Signed-off-by: Luc Verhaegen libv@skynet.be --- M flashrom.c M print.c M programmer.h 3 files changed, 76 insertions(+), 7 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/83/29083/1
diff --git a/flashrom.c b/flashrom.c index 59a7531..3b3e9bb 100644 --- a/flashrom.c +++ b/flashrom.c @@ -2098,6 +2098,7 @@ switch (p.type) { case USB: case PCI: + case PCI2: case OTHER: if (p.devs.note == NULL) { if (strcmp("internal", p.name) == 0) diff --git a/print.c b/print.c index 30f06c8..4636e1c 100644 --- a/print.c +++ b/print.c @@ -19,6 +19,11 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> + +#if NEED_PCI == 1 +#include <pci/pci.h> +#endif + #include "flash.h" #include "programmer.h"
@@ -462,6 +467,62 @@ } }
+#if NEED_PCI == 1 +/* + * We depend on libpcis built in list of names here. This makes formatting + * tricky/ugly. + * libpcis device only name lookup is currently not reliable, so look up the + * whole tuple. + */ +void print_supported_flashrom_pci_devices(const struct programmer_entry prog) +{ +#define PAD_LENGTH 64 + const struct flashrom_pci_match *matches = prog.devs.pci_match; + char buffer[256], *name; + unsigned int i, j, len; + + /* try to use already initialized pci_access structure */ + if (!pacc) { + pacc = pci_alloc(); + if (!pacc) { + msg_gerr("%s: Failed to allocate pci_access " + "structure.\n", __func__); + return; + } + pci_init(pacc); + + pci_load_name_list(pacc); + } else + msg_ginfo("Already initialized\n"); + + msg_ginfo("\nSupported PCI devices for the %s programmer:\n", + prog.name); + + len = msg_ginfo("Vendor - Device"); + if (len < PAD_LENGTH) + for (j = 0; j < (PAD_LENGTH - len); j++) + msg_ginfo(" "); + msg_ginfo("\tPCI IDS Status\n"); + + for (i = 0; matches[i].vendor_id; i++) { + name = pci_lookup_name(pacc, buffer, sizeof(buffer), + PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE, + matches[i].vendor_id, + matches[i].device_id); + len = msg_pinfo("%s", name); + if (len < PAD_LENGTH) + for (j = 0; j < (PAD_LENGTH - len); j++) + msg_pinfo(" "); + msg_pinfo("\t%04x:%04x %s\n", + matches[i].vendor_id, matches[i].device_id, + test_state_to_text(matches[i].status)); + } + + /* Don't bother cleaning up pacc, we either reuse it, or exit() */ +} +#endif /* NEED_PCI */ + + int print_supported(void) { unsigned int i; @@ -489,6 +550,11 @@ case PCI: print_supported_devs(prog, "PCI"); break; +#if NEED_PCI == 1 + case PCI2: + print_supported_flashrom_pci_devices(prog); + break; +#endif /* NEED_PCI */ case OTHER: if (prog.devs.note != NULL) { msg_ginfo("\nSupported devices for the %s programmer:\n", prog.name); diff --git a/programmer.h b/programmer.h index 5f02c6e..a5a1360 100644 --- a/programmer.h +++ b/programmer.h @@ -123,6 +123,7 @@
enum programmer_type { PCI = 1, /* to detect uninitialized values */ + PCI2, /* different pci infrastructure */ USB, OTHER, }; @@ -135,12 +136,20 @@ const char *device_name; };
+struct flashrom_pci_match { + uint16_t vendor_id; + uint16_t device_id; + const enum test_state status; + const void *private; /* programmer specific */ +}; + struct programmer_entry { const char *name; const enum programmer_type type; union { const struct dev_entry *const dev; const char *const note; + const struct flashrom_pci_match *pci_match; } devs;
int (*init) (void); @@ -850,13 +859,6 @@ struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, unsigned int num);
#if NEED_PCI == 1 -struct flashrom_pci_match { - uint16_t vendor_id; - uint16_t device_id; - const enum test_state status; - const void *private; /* programmer specific */ -}; - struct flashrom_pci_device { char *name; /* created from pci info */