Once upon a time usbdev_status was created for the ft2232
programmer. Its IDs are semantically different to pcidev_status
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 those structures by combining them into dev_status.
It is still possible to distinguish between PCI and USB devices
indirectly by using the struct programmer's type field.
Signed-off-by: Stefan Tauner <stefan.tauner(a)student.tuwien.ac.at>
---
atahpt.c | 2 +-
drkaiser.c | 2 +-
flashrom.c | 28 ++++++++++++++--------------
ft2232_spi.c | 2 +-
gfxnvidia.c | 2 +-
nic3com.c | 2 +-
nicintel.c | 2 +-
nicintel_spi.c | 2 +-
nicnatsemi.c | 2 +-
nicrealtek.c | 2 +-
ogp_spi.c | 2 +-
pcidev.c | 2 +-
print.c | 19 +++++++++----------
print_wiki.c | 37 +++++++------------------------------
programmer.h | 50 ++++++++++++++++++++++++++++----------------------
satamv.c | 2 +-
satasii.c | 2 +-
17 files changed, 71 insertions(+), 89 deletions(-)
diff --git a/atahpt.c b/atahpt.c
index 8ec0f3f..c81b3c4 100644
--- a/atahpt.c
+++ b/atahpt.c
@@ -33,7 +33,7 @@
#define PCI_VENDOR_ID_HPT 0x1103
-const struct pcidev_status ata_hpt[] = {
+const struct dev_status ata_hpt[] = {
{0x1103, 0x0004, NT, "Highpoint", "HPT366/368/370/370A/372/372N"},
{0x1103, 0x0005, NT, "Highpoint", "HPT372A/372N"},
{0x1103, 0x0006, NT, "Highpoint", "HPT302/302N"},
diff --git a/drkaiser.c b/drkaiser.c
index 8c9f560..9c6ba01 100644
--- a/drkaiser.c
+++ b/drkaiser.c
@@ -33,7 +33,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)"},
{0},
diff --git a/flashrom.c b/flashrom.c
index b585dc4..0f61936 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -90,7 +90,7 @@ const struct programmer_entry programmer_table[] = {
{
.name = "nic3com",
.type = PCI,
- .devs.pci = nics_3com,
+ .devs.status = nics_3com,
.init = nic3com_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -103,7 +103,7 @@ const struct programmer_entry programmer_table[] = {
/* This programmer works for Realtek RTL8139 and SMC 1211. */
.name = "nicrealtek",
.type = PCI,
- .devs.pci = nics_realtek,
+ .devs.status = nics_realtek,
.init = nicrealtek_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -115,7 +115,7 @@ const struct programmer_entry programmer_table[] = {
{
.name = "nicnatsemi",
.type = PCI,
- .devs.pci = nics_natsemi,
+ .devs.status = nics_natsemi,
.init = nicnatsemi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -127,7 +127,7 @@ const struct programmer_entry programmer_table[] = {
{
.name = "gfxnvidia",
.type = PCI,
- .devs.pci = gfx_nvidia,
+ .devs.status = gfx_nvidia,
.init = gfxnvidia_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -139,7 +139,7 @@ const struct programmer_entry programmer_table[] = {
{
.name = "drkaiser",
.type = PCI,
- .devs.pci = drkaiser_pcidev,
+ .devs.status = drkaiser_pcidev,
.init = drkaiser_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -151,7 +151,7 @@ const struct programmer_entry programmer_table[] = {
{
.name = "satasii",
.type = PCI,
- .devs.pci = satas_sii,
+ .devs.status = satas_sii,
.init = satasii_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -163,7 +163,7 @@ const struct programmer_entry programmer_table[] = {
{
.name = "atahpt",
.type = PCI,
- .devs.pci = ata_hpt,
+ .devs.status = ata_hpt,
.init = atahpt_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -175,7 +175,7 @@ const struct programmer_entry programmer_table[] = {
{
.name = "ft2232_spi",
.type = USB,
- .devs.usb = devs_ft2232spi,
+ .devs.status = devs_ft2232spi,
.init = ft2232_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -252,7 +252,7 @@ const struct programmer_entry programmer_table[] = {
{
.name = "nicintel",
.type = PCI,
- .devs.pci = nics_intel,
+ .devs.status = nics_intel,
.init = nicintel_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -264,7 +264,7 @@ const struct programmer_entry programmer_table[] = {
{
.name = "nicintel_spi",
.type = PCI,
- .devs.pci = nics_intel_spi,
+ .devs.status = nics_intel_spi,
.init = nicintel_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -276,7 +276,7 @@ const struct programmer_entry programmer_table[] = {
{
.name = "ogp_spi",
.type = PCI,
- .devs.pci = ogp_spi,
+ .devs.status = ogp_spi,
.init = ogp_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -288,7 +288,7 @@ const struct programmer_entry programmer_table[] = {
{
.name = "satamv",
.type = PCI,
- .devs.pci = satas_mv,
+ .devs.status = satas_mv,
.init = satamv_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
@@ -1624,7 +1624,7 @@ int selfcheck(void)
}
switch (p.type) {
case USB:
- if (p.devs.usb == NULL) {
+ if (p.devs.status == NULL) {
msg_gerr("Programmer %s is of type USB, but its device list is NULL!\n",
p.name);
ret = 1;
@@ -1632,7 +1632,7 @@ int selfcheck(void)
break;
#if NEED_PCI == 1
case PCI:
- if (p.devs.pci == NULL) {
+ if (p.devs.status == NULL) {
msg_gerr("Programmer %s is of type PCI, but its device list is NULL!\n",
p.name);
ret = 1;
diff --git a/ft2232_spi.c b/ft2232_spi.c
index dc17d00..aaeca67 100644
--- a/ft2232_spi.c
+++ b/ft2232_spi.c
@@ -57,7 +57,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, FTDI_FT232H_PID, OK, "FTDI", "FT232H"},
diff --git a/gfxnvidia.c b/gfxnvidia.c
index 7bdbda8..4c334eb 100644
--- a/gfxnvidia.c
+++ b/gfxnvidia.c
@@ -34,7 +34,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 c7fc800..4e623e0 100644
--- a/nic3com.c
+++ b/nic3com.c
@@ -36,7 +36,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 4399377..8c8ce0d 100644
--- a/nicintel.c
+++ b/nicintel.c
@@ -27,7 +27,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 24d5732..160e050 100644
--- a/nicintel_spi.c
+++ b/nicintel_spi.c
@@ -67,7 +67,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/nicnatsemi.c b/nicnatsemi.c
index fcfc613..e7ba5af 100644
--- a/nicnatsemi.c
+++ b/nicnatsemi.c
@@ -30,7 +30,7 @@
#define BOOT_ROM_ADDR 0x50
#define BOOT_ROM_DATA 0x54
-const struct pcidev_status nics_natsemi[] = {
+const struct dev_status nics_natsemi[] = {
{0x100b, 0x0020, NT, "National Semiconductor", "DP83815/DP83816"},
{0x100b, 0x0022, NT, "National Semiconductor", "DP83820"},
diff --git a/nicrealtek.c b/nicrealtek.c
index 92f48a8..2fee7c4 100644
--- a/nicrealtek.c
+++ b/nicrealtek.c
@@ -30,7 +30,7 @@
static int bios_rom_addr, bios_rom_data;
-const struct pcidev_status nics_realtek[] = {
+const struct dev_status nics_realtek[] = {
{0x10ec, 0x8139, OK, "Realtek", "RTL8139/8139C/8139C+"},
{0x10ec, 0x8169, NT, "Realtek", "RTL8169"},
{0x1113, 0x1211, OK, "SMC", "1211TX"}, /* RTL8139 clone */
diff --git a/ogp_spi.c b/ogp_spi.c
index 7aee72b..d2fec8a 100644
--- a/ogp_spi.c
+++ b/ogp_spi.c
@@ -47,7 +47,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"},
{0},
diff --git a/pcidev.c b/pcidev.c
index bfc8a5d..e1d3875 100644
--- a/pcidev.c
+++ b/pcidev.c
@@ -154,7 +154,7 @@ uintptr_t pcidev_readbar(struct pci_dev *dev, int bar)
return (uintptr_t)addr;
}
-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;
diff --git a/print.c b/print.c
index a2181bd..cf62b6e 100644
--- a/print.c
+++ b/print.c
@@ -433,11 +433,12 @@ static void print_supported_boards_helper(const struct board_info *boards,
}
#endif
-void print_supported_usbdevs(const struct usbdev_status *devs)
+void print_supported_devs(const struct programmer_entry prog, const char *const type)
{
int i;
- msg_pinfo("USB devices:\n");
+ const struct dev_status *const devs = prog.devs.status;
+ msg_ginfo("\nSupported %s devices for the %s programmer:\n", type, prog.name);
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)" : "");
@@ -478,20 +479,18 @@ int print_supported(void)
const struct programmer_entry prog = programmer_table[i];
switch (prog.type) {
case USB:
- msg_ginfo("\nSupported USB devices for the %s programmer:\n", prog.name);
- print_supported_usbdevs(prog.devs.usb);
+ print_supported_devs(prog, "USB");
break;
#if NEED_PCI == 1
case PCI:
- msg_ginfo("\nSupported PCI devices for the %s programmer:\n", prog.name);
- print_supported_pcidevs(prog.devs.pci);
+ print_supported_devs(prog, "PCI");
break;
#endif
case OTHER:
- if (prog.devs.note == NULL)
- break;
- msg_ginfo("\nSupported devices for the %s programmer:\n", prog.name);
- msg_ginfo("%s", prog.devs.note);
+ if (prog.devs.note != NULL) {
+ msg_ginfo("\nSupported devices for the %s programmer:\n", prog.name);
+ msg_ginfo("%s", prog.devs.note);
+ }
break;
default:
msg_gerr("\n%s: %s: Uninitialized programmer type! Please report a bug at "
diff --git a/print_wiki.c b/print_wiki.c
index 501a2d7..83f1ad9 100644
--- a/print_wiki.c
+++ b/print_wiki.c
@@ -300,7 +300,7 @@ static void print_supported_chips_wiki(int cols)
/* Following functions are not needed when no PCI/USB programmers are compiled in,
* but since print_wiki code has no size constraints we include it unconditionally. */
-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;
@@ -309,34 +309,11 @@ static int count_supported_pcidevs_wiki(const struct pcidev_status *devs)
return count;
}
-static void print_supported_pcidevs_wiki_helper(const struct pcidev_status *devs)
-{
- int i = 0;
- static int c = 0;
-
- /* Alternate colors if the vendor changes. */
- c = !c;
-
- for (i = 0; devs[i].vendor_name != NULL; i++) {
- printf("|- bgcolor=\"#%s\"\n| %s || %s || %04x:%04x || {{%s}}\n", (c) ? "eeeeee" : "dddddd",
- devs[i].vendor_name, devs[i].device_name, devs[i].vendor_id, devs[i].device_id,
- (devs[i].status == NT) ? "?3" : "OK");
- }
-}
-
-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 usbdev_status *devs)
+static void print_supported_devs_wiki_helper(const struct programmer_entry prog)
{
int i = 0;
static int c = 0;
+ const struct dev_status *devs = prog.devs.status;
/* Alternate colors if the vendor changes. */
c = !c;
@@ -358,10 +335,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.devs.usb);
+ usb_count += count_supported_devs_wiki(prog.devs.status);
break;
case PCI:
- pci_count += count_supported_pcidevs_wiki(prog.devs.pci);
+ pci_count += count_supported_devs_wiki(prog.devs.status);
break;
case OTHER:
default:
@@ -376,7 +353,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.devs.pci);
+ print_supported_devs_wiki_helper(prog);
}
}
printf("\n|}\n\n|}\n");
@@ -388,7 +365,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.devs.usb);
+ print_supported_devs_wiki_helper(prog);
}
}
printf("\n|}\n\n|}\n");
diff --git a/programmer.h b/programmer.h
index e2bb3d8..305bd00 100644
--- a/programmer.h
+++ b/programmer.h
@@ -96,12 +96,19 @@ 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 *name;
const 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;
} devs;
@@ -232,7 +239,7 @@ extern uint32_t io_base_addr;
extern struct pci_access *pacc;
extern struct pci_dev *pcidev_dev;
uintptr_t pcidev_readbar(struct pci_dev *dev, int bar);
-uintptr_t pcidev_init(int bar, const struct pcidev_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.
*/
@@ -241,12 +248,6 @@ int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
#endif
-/* 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
-/* Not needed for CONFIG_INTERNAL, but for all other PCI-based programmers. */
-void print_supported_pcidevs(const struct pcidev_status *devs);
-#endif
-
struct usbdev_status {
uint16_t vendor_id;
uint16_t device_id;
@@ -262,6 +263,12 @@ struct pcidev_status {
const char *device_name;
};
+/* 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
+/* Not needed for CONFIG_INTERNAL, but for all other PCI-based programmers. */
+void print_supported_pcidevs(const struct pcidev_status *devs);
+#endif
+
#if CONFIG_INTERNAL == 1
/* board_enable.c */
int board_parse_parameter(const char *boardstring, const char **vendor, const char **model);
@@ -375,74 +382,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
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 27ad699..0fc9a25 100644
--- a/satamv.c
+++ b/satamv.c
@@ -29,7 +29,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 f991686..96b73a1 100644
--- a/satasii.c
+++ b/satasii.c
@@ -30,7 +30,7 @@
static 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"},
--
Kind regards, Stefan Tauner