usbdev_status was created for the ft2232 programmer. Its IDs are semantically different because they indicate USB instead of PCI IDs, but apart from that both data structures are equal. This change makes life easier for everything involved in handling and printing the status of devices that is noted in that structure.
--- It is still possible to distinguish between PCI and USB devices by using the struct programmer's type field. It still seems a bit hacky, but i think we are better off with it anyway. If we really would want to distinguish between the different types of IDs i'd rater make the IDs a union of different ID types inside struct dev_status.
Signed-off-by: Stefan Tauner stefan.tauner@student.tuwien.ac.at --- drkaiser.c | 2 +- flashrom.c | 38 ++++++++++++++++++------------------ ft2232_spi.c | 2 +- gfxnvidia.c | 2 +- nic3com.c | 2 +- nicintel.c | 2 +- nicintel_spi.c | 2 +- nicrealtek.c | 2 +- ogp_spi.c | 2 +- pcidev.c | 6 ++-- print.c | 23 +++------------------ print_wiki.c | 51 ++++++++---------------------------------------- programmer.h | 58 ++++++++++++++++++++++++------------------------------- satamv.c | 2 +- satasii.c | 2 +- 15 files changed, 70 insertions(+), 126 deletions(-)
diff --git a/drkaiser.c b/drkaiser.c index 362db57..faa7035 100644 --- a/drkaiser.c +++ b/drkaiser.c @@ -32,7 +32,7 @@ /* Mask to restrict flash accesses to the 128kB memory window. */ #define DRKAISER_MEMMAP_MASK ((1 << 17) - 1)
-const struct pcidev_status drkaiser_pcidev[] = { +const struct dev_status drkaiser_pcidev[] = { {0x1803, 0x5057, OK, "Dr. Kaiser", "PC-Waechter (Actel FPGA)"}, {}, }; diff --git a/flashrom.c b/flashrom.c index bf1e157..20a41f2 100644 --- a/flashrom.c +++ b/flashrom.c @@ -63,7 +63,7 @@ const struct programmer_entry programmer_table[] = { { .name = "internal", .type = OTHER, - .devices.note = NULL, + .devs.note = NULL, .init = internal_init, .map_flash_region = physmap, .unmap_flash_region = physunmap, @@ -76,7 +76,7 @@ const struct programmer_entry programmer_table[] = { .name = "dummy", .type = OTHER, /* FIXME */ - .devices.note = "Dummy device, does nothing and logs all accesses\n", + .devs.note = "Dummy device, does nothing and logs all accesses\n", .init = dummy_init, .map_flash_region = dummy_map, .unmap_flash_region = dummy_unmap, @@ -88,7 +88,7 @@ const struct programmer_entry programmer_table[] = { { .name = "nic3com", .type = PCI, - .devices.pci = nics_3com, + .devs.status = nics_3com, .init = nic3com_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -101,7 +101,7 @@ const struct programmer_entry programmer_table[] = { /* This programmer works for Realtek RTL8139 and SMC 1211. */ .name = "nicrealtek", .type = PCI, - .devices.pci = nics_realtek, + .devs.status = nics_realtek, //.name = "nicsmc1211", .init = nicrealtek_init, .map_flash_region = fallback_map, @@ -114,7 +114,7 @@ const struct programmer_entry programmer_table[] = { { .name = "nicnatsemi", .type = PCI, - .devices.pci = nics_natsemi, + .devs.status = nics_natsemi, .init = nicnatsemi_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -126,7 +126,7 @@ const struct programmer_entry programmer_table[] = { { .name = "gfxnvidia", .type = PCI, - .devices.pci = gfx_nvidia, + .devs.status = gfx_nvidia, .init = gfxnvidia_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -138,7 +138,7 @@ const struct programmer_entry programmer_table[] = { { .name = "drkaiser", .type = PCI, - .devices.pci = drkaiser_pcidev, + .devs.status = drkaiser_pcidev, .init = drkaiser_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -150,7 +150,7 @@ const struct programmer_entry programmer_table[] = { { .name = "satasii", .type = PCI, - .devices.pci = satas_sii, + .devs.status = satas_sii, .init = satasii_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -162,7 +162,7 @@ const struct programmer_entry programmer_table[] = { { .name = "atahpt", .type = PCI, - .devices.pci = ata_hpt, + .devs.status = ata_hpt, .init = atahpt_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -174,7 +174,7 @@ const struct programmer_entry programmer_table[] = { { .name = "ft2232_spi", .type = USB, - .devices.usb = devs_ft2232spi, + .devs.status = devs_ft2232spi, .init = ft2232_spi_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -187,7 +187,7 @@ const struct programmer_entry programmer_table[] = { .name = "serprog", .type = OTHER, /* FIXME */ - .devices.note = "All programmer devices speaking the serprog protocol\n", + .devs.note = "All programmer devices speaking the serprog protocol\n", .init = serprog_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -200,7 +200,7 @@ const struct programmer_entry programmer_table[] = { .name = "buspirate_spi", .type = OTHER, /* FIXME */ - .devices.note = "Dangerous Prototypes Bus Pirate\n", + .devs.note = "Dangerous Prototypes Bus Pirate\n", .init = buspirate_spi_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -213,7 +213,7 @@ const struct programmer_entry programmer_table[] = { .name = "dediprog", .type = OTHER, /* FIXME */ - .devices.note = "Dediprog SF100\n", + .devs.note = "Dediprog SF100\n", .init = dediprog_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -226,7 +226,7 @@ const struct programmer_entry programmer_table[] = { .name = "rayer_spi", .type = OTHER, /* FIXME */ - .devices.note = "RayeR parallel port programmer\n", + .devs.note = "RayeR parallel port programmer\n", .init = rayer_spi_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -238,7 +238,7 @@ const struct programmer_entry programmer_table[] = { { .name = "nicintel", .type = PCI, - .devices.pci = nics_intel, + .devs.status = nics_intel, .init = nicintel_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -250,7 +250,7 @@ const struct programmer_entry programmer_table[] = { { .name = "nicintel_spi", .type = PCI, - .devices.pci = nics_intel_spi, + .devs.status = nics_intel_spi, .init = nicintel_spi_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -262,7 +262,7 @@ const struct programmer_entry programmer_table[] = { { .name = "ogp_spi", .type = PCI, - .devices.pci = ogp_spi, + .devs.status = ogp_spi, .init = ogp_spi_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -274,7 +274,7 @@ const struct programmer_entry programmer_table[] = { { .name = "satamv", .type = PCI, - .devices.pci = satas_mv, + .devs.status = satas_mv, .init = satamv_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, @@ -286,7 +286,7 @@ const struct programmer_entry programmer_table[] = { { .name = "linux_spi", .type = OTHER, - .devices.note = "Device files /dev/spidev*.*\n", + .devs.note = "Device files /dev/spidev*.*\n", .init = linux_spi_init, .map_flash_region = fallback_map, .unmap_flash_region = fallback_unmap, diff --git a/ft2232_spi.c b/ft2232_spi.c index ec4934e..069421c 100644 --- a/ft2232_spi.c +++ b/ft2232_spi.c @@ -49,7 +49,7 @@ #define OLIMEX_ARM_OCD_H_PID 0x002B #define OLIMEX_ARM_TINY_H_PID 0x002A
-const struct usbdev_status devs_ft2232spi[] = { +const struct dev_status devs_ft2232spi[] = { {FTDI_VID, FTDI_FT2232H_PID, OK, "FTDI", "FT2232H"}, {FTDI_VID, FTDI_FT4232H_PID, OK, "FTDI", "FT4232H"}, {FTDI_VID, TIAO_TUMPA_PID, OK, "TIAO", "USB Multi-Protocol Adapter"}, diff --git a/gfxnvidia.c b/gfxnvidia.c index b8750b3..bcd53a7 100644 --- a/gfxnvidia.c +++ b/gfxnvidia.c @@ -33,7 +33,7 @@
uint8_t *nvidia_bar;
-const struct pcidev_status gfx_nvidia[] = { +const struct dev_status gfx_nvidia[] = { {0x10de, 0x0010, NT, "NVIDIA", "Mutara V08 [NV2]" }, {0x10de, 0x0018, NT, "NVIDIA", "RIVA 128" }, {0x10de, 0x0020, NT, "NVIDIA", "RIVA TNT" }, diff --git a/nic3com.c b/nic3com.c index 473c7b1..2fff346 100644 --- a/nic3com.c +++ b/nic3com.c @@ -35,7 +35,7 @@ static uint32_t internal_conf; static uint16_t id;
-const struct pcidev_status nics_3com[] = { +const struct dev_status nics_3com[] = { /* 3C90xB */ {0x10b7, 0x9055, OK, "3COM", "3C90xB: PCI 10/100 Mbps; shared 10BASE-T/100BASE-TX"}, {0x10b7, 0x9001, NT, "3COM", "3C90xB: PCI 10/100 Mbps; shared 10BASE-T/100BASE-T4" }, diff --git a/nicintel.c b/nicintel.c index 0415f46..5261263 100644 --- a/nicintel.c +++ b/nicintel.c @@ -26,7 +26,7 @@ uint8_t *nicintel_bar; uint8_t *nicintel_control_bar;
-const struct pcidev_status nics_intel[] = { +const struct dev_status nics_intel[] = { {PCI_VENDOR_ID_INTEL, 0x1209, NT, "Intel", "8255xER/82551IT Fast Ethernet Controller"}, {PCI_VENDOR_ID_INTEL, 0x1229, OK, "Intel", "82557/8/9/0/1 Ethernet Pro 100"},
diff --git a/nicintel_spi.c b/nicintel_spi.c index 4ff8554..132673a 100644 --- a/nicintel_spi.c +++ b/nicintel_spi.c @@ -64,7 +64,7 @@
uint8_t *nicintel_spibar;
-const struct pcidev_status nics_intel_spi[] = { +const struct dev_status nics_intel_spi[] = { {PCI_VENDOR_ID_INTEL, 0x105e, OK, "Intel", "82571EB Gigabit Ethernet Controller"}, {PCI_VENDOR_ID_INTEL, 0x1076, OK, "Intel", "82541GI Gigabit Ethernet Controller"}, {PCI_VENDOR_ID_INTEL, 0x107c, OK, "Intel", "82541PI Gigabit Ethernet Controller"}, diff --git a/nicrealtek.c b/nicrealtek.c index 32aa434..66f5eda 100644 --- a/nicrealtek.c +++ b/nicrealtek.c @@ -30,7 +30,7 @@ #define BIOS_ROM_ADDR 0xD4 #define BIOS_ROM_DATA 0xD7
-const struct pcidev_status nics_realtek[] = { +const struct dev_status nics_realtek[] = { {0x10ec, 0x8139, OK, "Realtek", "RTL8139/8139C/8139C+"}, {0x1113, 0x1211, OK, "SMC2", "1211TX"}, /* RTL8139 clone */ {}, diff --git a/ogp_spi.c b/ogp_spi.c index 812420c..231c110 100644 --- a/ogp_spi.c +++ b/ogp_spi.c @@ -45,7 +45,7 @@ static uint32_t ogp_reg_siso; static uint32_t ogp_reg__ce; static uint32_t ogp_reg_sck;
-const struct pcidev_status ogp_spi[] = { +const struct dev_status ogp_spi[] = { {PCI_VENDOR_ID_OGP, 0x0000, OK, "Open Graphics Project", "Development Board OGD1"}, {}, }; diff --git a/pcidev.c b/pcidev.c index 6e5d0f1..13031d5 100644 --- a/pcidev.c +++ b/pcidev.c @@ -36,7 +36,7 @@ enum pci_bartype { };
uintptr_t pcidev_validate(struct pci_dev *dev, int bar, - const struct pcidev_status *devs) + const struct dev_status *devs) { int i; uint64_t addr; @@ -188,7 +188,7 @@ uintptr_t pcidev_validate(struct pci_dev *dev, int bar, return 0; }
-uintptr_t pcidev_init(int bar, const struct pcidev_status *devs) +uintptr_t pcidev_init(int bar, const struct dev_status *devs) { struct pci_dev *dev; struct pci_filter filter; @@ -240,7 +240,7 @@ uintptr_t pcidev_init(int bar, const struct pcidev_status *devs) return curaddr; }
-void print_supported_pcidevs(const struct pcidev_status *devs) +void print_supported_devs(const struct dev_status *devs) { int i;
diff --git a/print.c b/print.c index 8bab8e3..4e5e086 100644 --- a/print.c +++ b/print.c @@ -422,21 +422,6 @@ static void print_supported_boards_helper(const struct board_info *boards, } #endif
-#if CONFIG_FT2232_SPI == 1 -void print_supported_usbdevs(const struct usbdev_status *devs) -{ - int i; - - msg_pinfo("USB devices:\n"); - for (i = 0; devs[i].vendor_name != NULL; i++) { - msg_pinfo("%s %s [%04x:%04x]%s\n", devs[i].vendor_name, - devs[i].device_name, devs[i].vendor_id, - devs[i].device_id, - (devs[i].status == NT) ? " (untested)" : ""); - } -} -#endif - void print_supported(void) { unsigned int i; @@ -459,19 +444,19 @@ void print_supported(void) case USB: msg_ginfo("\nSupported USB devices for the %s programmer:\n", prog.name); - print_supported_usbdevs(prog.devices.usb); + print_supported_devs(prog.devs.status); break; case PCI: msg_ginfo("\nSupported PCI devices for the %s programmer:\n", prog.name); - print_supported_pcidevs(prog.devices.pci); + print_supported_devs(prog.devs.status); break; case OTHER: - if (prog.devices.note == NULL) + if (prog.devs.note == NULL) break; msg_ginfo("\nSupported devices for the %s programmer:\n", prog.name); - msg_ginfo("%s", prog.devices.note); + msg_ginfo("%s", prog.devs.note); break; default: break; diff --git a/print_wiki.c b/print_wiki.c index c25ec28..479f426 100644 --- a/print_wiki.c +++ b/print_wiki.c @@ -294,54 +294,21 @@ static void print_supported_chips_wiki(int cols) printf("|}\n\n"); }
-/* Not needed for CONFIG_INTERNAL, but for all other PCI-based programmers. */ -#if CONFIG_NIC3COM+CONFIG_NICREALTEK+CONFIG_NICNATSEMI+CONFIG_GFXNVIDIA+CONFIG_DRKAISER+CONFIG_SATASII+CONFIG_ATAHPT+CONFIG_NICINTEL+CONFIG_NICINTEL_SPI+CONFIG_OGP_SPI+CONFIG_SATAMV >= 1 -static int count_supported_pcidevs_wiki(const struct pcidev_status *devs) +static int count_supported_devs_wiki(const struct dev_status *devs) { unsigned int count = 0; unsigned int i = 0; for (i = 0; devs[i].vendor_name != NULL; i++) - count++; + count++; return count; }
-static void print_supported_pcidevs_wiki_helper(const struct programmer_entry prog) +static void print_supported_devs_wiki_helper(const struct programmer_entry prog) { int i = 0; static int c = 0; - const struct pcidev_status *devs = prog.devices.pci; - const unsigned int count = count_supported_pcidevs_wiki(devs); - - /* Alternate colors if the vendor changes. */ - c = !c; - - for (i = 0; devs[i].vendor_name != NULL; i++) { - printf("|- bgcolor="#%s"\n", (c) ? "eeeeee" : "dddddd"); - if (i == 0) - printf("| rowspan="%u" | %s |", count, prog.name); - printf("| %s || %s || %04x:%04x || {{%s}}\n", - devs[i].vendor_name, devs[i].device_name, - devs[i].vendor_id, devs[i].device_id, - (devs[i].status == NT) ? "?3" : "OK"); - } -} -#endif - -static int count_supported_usbdevs_wiki(const struct usbdev_status *devs) -{ - unsigned int count = 0; - unsigned int i = 0; - for (i = 0; devs[i].vendor_name != NULL; i++) - count++; - return count; -} - -static void print_supported_usbdevs_wiki_helper(const struct programmer_entry prog) -{ - int i = 0; - static int c = 0; - const struct usbdev_status *devs = prog.devices.usb; - const unsigned int count = count_supported_usbdevs_wiki(devs); + const struct dev_status *devs = prog.devs.status; + const unsigned int count = count_supported_devs_wiki(devs);
/* Alternate colors if the vendor changes. */ c = !c; @@ -367,10 +334,10 @@ static void print_supported_devs_wiki() const struct programmer_entry prog = programmer_table[i]; switch (prog.type) { case USB: - usb_count += count_supported_usbdevs_wiki(prog.devices.usb); + usb_count += count_supported_devs_wiki(prog.devs.status); break; case PCI: - pci_count += count_supported_pcidevs_wiki(prog.devices.pci); + pci_count += count_supported_devs_wiki(prog.devs.status); break; case OTHER: default: @@ -387,7 +354,7 @@ static void print_supported_devs_wiki() for (i = 0; i < PROGRAMMER_INVALID; i++) { const struct programmer_entry prog = programmer_table[i]; if (prog.type == PCI) { - print_supported_pcidevs_wiki_helper(prog); + print_supported_devs_wiki_helper(prog); } } printf("\n|}\n"); @@ -401,7 +368,7 @@ static void print_supported_devs_wiki() for (i = 0; i < PROGRAMMER_INVALID; i++) { const struct programmer_entry prog = programmer_table[i]; if (prog.type == USB) { - print_supported_usbdevs_wiki_helper(prog); + print_supported_devs_wiki_helper(prog); } } printf("\n|}\n"); diff --git a/programmer.h b/programmer.h index 9f90fe5..b52727e 100644 --- a/programmer.h +++ b/programmer.h @@ -93,15 +93,22 @@ enum programmer_type { OTHER, };
+struct dev_status { + uint16_t vendor_id; + uint16_t device_id; + const enum test_state status; + const char *vendor_name; + const char *device_name; +}; + struct programmer_entry { const char *vendor; const char *name; enum programmer_type type; union { - const struct pcidev_status *const pci; - const struct usbdev_status *const usb; + const struct dev_status *const status; const char * const note; - } devices; + } devs;
int (*init) (void);
@@ -226,15 +233,8 @@ void internal_delay(int usecs); extern uint32_t io_base_addr; extern struct pci_access *pacc; extern struct pci_dev *pcidev_dev; -struct pcidev_status { - uint16_t vendor_id; - uint16_t device_id; - const enum test_state status; - const char *vendor_name; - const char *device_name; -}; -uintptr_t pcidev_validate(struct pci_dev *dev, int bar, const struct pcidev_status *devs); -uintptr_t pcidev_init(int bar, const struct pcidev_status *devs); +uintptr_t pcidev_validate(struct pci_dev *dev, int bar, const struct dev_status *devs); +uintptr_t pcidev_init(int bar, const struct dev_status *devs); /* rpci_write_* are reversible writes. The original PCI config space register * contents will be restored on shutdown. */ @@ -245,7 +245,7 @@ int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
/* print.c */ #if CONFIG_NIC3COM+CONFIG_NICREALTEK+CONFIG_NICNATSEMI+CONFIG_GFXNVIDIA+CONFIG_DRKAISER+CONFIG_SATASII+CONFIG_ATAHPT+CONFIG_NICINTEL+CONFIG_NICINTEL_SPI+CONFIG_OGP_SPI+CONFIG_SATAMV >= 1 -void print_supported_pcidevs(const struct pcidev_status *devs); +void print_supported_devs(const struct dev_status *devs); #endif
#if CONFIG_INTERNAL == 1 @@ -360,81 +360,73 @@ void dummy_unmap(void *virt_addr, size_t len); /* nic3com.c */ #if CONFIG_NIC3COM == 1 int nic3com_init(void); -extern const struct pcidev_status nics_3com[]; +extern const struct dev_status nics_3com[]; #endif
/* gfxnvidia.c */ #if CONFIG_GFXNVIDIA == 1 int gfxnvidia_init(void); -extern const struct pcidev_status gfx_nvidia[]; +extern const struct dev_status gfx_nvidia[]; #endif
/* drkaiser.c */ #if CONFIG_DRKAISER == 1 int drkaiser_init(void); -extern const struct pcidev_status drkaiser_pcidev[]; +extern const struct dev_status drkaiser_pcidev[]; #endif
/* nicrealtek.c */ #if CONFIG_NICREALTEK == 1 int nicrealtek_init(void); -extern const struct pcidev_status nics_realtek[]; +extern const struct dev_status nics_realtek[]; #endif
/* nicnatsemi.c */ #if CONFIG_NICNATSEMI == 1 int nicnatsemi_init(void); -extern const struct pcidev_status nics_natsemi[]; +extern const struct dev_status nics_natsemi[]; #endif
/* nicintel.c */ #if CONFIG_NICINTEL == 1 int nicintel_init(void); -extern const struct pcidev_status nics_intel[]; +extern const struct dev_status nics_intel[]; #endif
/* nicintel_spi.c */ #if CONFIG_NICINTEL_SPI == 1 int nicintel_spi_init(void); -extern const struct pcidev_status nics_intel_spi[]; +extern const struct dev_status nics_intel_spi[]; #endif
/* ogp_spi.c */ #if CONFIG_OGP_SPI == 1 int ogp_spi_init(void); -extern const struct pcidev_status ogp_spi[]; +extern const struct dev_status ogp_spi[]; #endif
/* satamv.c */ #if CONFIG_SATAMV == 1 int satamv_init(void); -extern const struct pcidev_status satas_mv[]; +extern const struct dev_status satas_mv[]; #endif
/* satasii.c */ #if CONFIG_SATASII == 1 int satasii_init(void); -extern const struct pcidev_status satas_sii[]; +extern const struct dev_status satas_sii[]; #endif
/* atahpt.c */ #if CONFIG_ATAHPT == 1 int atahpt_init(void); -extern const struct pcidev_status ata_hpt[]; +extern const struct dev_status ata_hpt[]; #endif
/* ft2232_spi.c */ #if CONFIG_FT2232_SPI == 1 -struct usbdev_status { - uint16_t vendor_id; - uint16_t device_id; - const enum test_state status; - const char *vendor_name; - const char *device_name; -}; int ft2232_spi_init(void); -extern const struct usbdev_status devs_ft2232spi[]; -void print_supported_usbdevs(const struct usbdev_status *devs); +extern const struct dev_status devs_ft2232spi[]; #endif
/* rayer_spi.c */ diff --git a/satamv.c b/satamv.c index e39385b..689855f 100644 --- a/satamv.c +++ b/satamv.c @@ -28,7 +28,7 @@ uint8_t *mv_bar; uint16_t mv_iobar;
-const struct pcidev_status satas_mv[] = { +const struct dev_status satas_mv[] = { /* 88SX6041 and 88SX6042 are the same according to the datasheet. */ {0x11ab, 0x7042, OK, "Marvell", "88SX7042 PCI-e 4-port SATA-II"},
diff --git a/satasii.c b/satasii.c index 387c605..eac1f37 100644 --- a/satasii.c +++ b/satasii.c @@ -31,7 +31,7 @@ uint8_t *sii_bar; static uint16_t id;
-const struct pcidev_status satas_sii[] = { +const struct dev_status satas_sii[] = { {0x1095, 0x0680, OK, "Silicon Image", "PCI0680 Ultra ATA-133 Host Ctrl"}, {0x1095, 0x3112, OK, "Silicon Image", "SiI 3112 [SATALink/SATARaid] SATA Ctrl"}, {0x1095, 0x3114, OK, "Silicon Image", "SiI 3114 [SATALink/SATARaid] SATA Ctrl"},