Skip to content

Commit

Permalink
drivers/: Make 'fallback_{un}map' the default unless defined
Browse files Browse the repository at this point in the history
Drop the explicit need to specify the default 'fallback_{un}map'
callback function pointer from the 'programmer_entry' struct.
This is a reasonable default for every other driver in the tree
with only a select few exceptions [atavia, serprog, dummyflasher
and internal].

Thus this simplifies driver development and paves way
to remove the 'programmer' global handle.

Change-Id: I5ea7bd68f7ae2cd4af9902ef07255ab6ce0bfdb3
Signed-off-by: Edward O'Callaghan <[email protected]>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/67404
Tested-by: build bot (Jenkins) <[email protected]>
Reviewed-by: Felix Singer <[email protected]>
Reviewed-by: Anastasia Klimchuk <[email protected]>
Reviewed-by: Angel Pons <[email protected]>
  • Loading branch information
quasisec authored and Th3Fanbus committed Oct 8, 2022
1 parent 7e8d17a commit 67d5015
Show file tree
Hide file tree
Showing 37 changed files with 9 additions and 80 deletions.
2 changes: 0 additions & 2 deletions atahpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,4 @@ const struct programmer_entry programmer_atahpt = {
.type = PCI,
.devs.dev = ata_hpt,
.init = atahpt_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions atapromise.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,4 @@ const struct programmer_entry programmer_atapromise = {
.type = PCI,
.devs.dev = ata_promise,
.init = atapromise_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
1 change: 0 additions & 1 deletion atavia.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,4 @@ const struct programmer_entry programmer_atavia = {
.devs.dev = ata_via,
.init = atavia_init,
.map_flash_region = atavia_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions buspirate_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,4 @@ const struct programmer_entry programmer_buspirate_spi = {
/* FIXME */
.devs.note = "Dangerous Prototypes Bus Pirate\n",
.init = buspirate_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions ch341a_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,5 @@ const struct programmer_entry programmer_ch341a_spi = {
.type = USB,
.devs.dev = devs_ch341a_spi,
.init = ch341a_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
.delay = ch341a_spi_delay,
};
2 changes: 0 additions & 2 deletions dediprog.c
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,4 @@ const struct programmer_entry programmer_dediprog = {
.type = USB,
.devs.dev = devs_dediprog,
.init = dediprog_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions developerbox_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,4 @@ const struct programmer_entry programmer_developerbox = {
.type = USB,
.devs.dev = devs_developerbox_spi,
.init = developerbox_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions digilent_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,4 @@ const struct programmer_entry programmer_digilent_spi = {
.type = USB,
.devs.dev = devs_digilent_spi,
.init = digilent_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions drkaiser.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,4 @@ const struct programmer_entry programmer_drkaiser = {
.type = PCI,
.devs.dev = drkaiser_pcidev,
.init = drkaiser_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
19 changes: 9 additions & 10 deletions flashrom.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,22 @@ int programmer_shutdown(void)

void *programmer_map_flash_region(const char *descr, uintptr_t phys_addr, size_t len)
{
void *ret = programmer->map_flash_region(descr, phys_addr, len);
void *ret;
if (programmer->map_flash_region)
ret = programmer->map_flash_region(descr, phys_addr, len);
else
ret = fallback_map(descr, phys_addr, len);
msg_gspew("%s: mapping %s from 0x%0*" PRIxPTR " to 0x%0*" PRIxPTR "\n",
__func__, descr, PRIxPTR_WIDTH, phys_addr, PRIxPTR_WIDTH, (uintptr_t) ret);
return ret;
}

void programmer_unmap_flash_region(void *virt_addr, size_t len)
{
programmer->unmap_flash_region(virt_addr, len);
if (programmer->unmap_flash_region)
programmer->unmap_flash_region(virt_addr, len);
else
fallback_unmap(virt_addr, len);
msg_gspew("%s: unmapped 0x%0*" PRIxPTR "\n", __func__, PRIxPTR_WIDTH, (uintptr_t)virt_addr);
}

Expand Down Expand Up @@ -1423,14 +1430,6 @@ int selfcheck(void)
msg_gerr("Programmer %s does not have a valid init function!\n", p->name);
ret = 1;
}
if (p->map_flash_region == NULL) {
msg_gerr("Programmer %s does not have a valid map_flash_region function!\n", p->name);
ret = 1;
}
if (p->unmap_flash_region == NULL) {
msg_gerr("Programmer %s does not have a valid unmap_flash_region function!\n", p->name);
ret = 1;
}
}

/* It would be favorable if we could check for the correct layout (especially termination) of various
Expand Down
2 changes: 0 additions & 2 deletions ft2232_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,4 @@ const struct programmer_entry programmer_ft2232_spi = {
.type = USB,
.devs.dev = devs_ft2232spi,
.init = ft2232_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions gfxnvidia.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,4 @@ const struct programmer_entry programmer_gfxnvidia = {
.type = PCI,
.devs.dev = gfx_nvidia,
.init = gfxnvidia_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions it8212.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,4 @@ const struct programmer_entry programmer_it8212 = {
.type = PCI,
.devs.dev = devs_it8212,
.init = it8212_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions jlink_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,4 @@ const struct programmer_entry programmer_jlink_spi = {
.type = OTHER,
.init = jlink_spi_init,
.devs.note = "SEGGER J-Link and compatible devices\n",
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions linux_mtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,4 @@ const struct programmer_entry programmer_linux_mtd = {
.type = OTHER,
.devs.note = "Device files /dev/mtd*\n",
.init = linux_mtd_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions linux_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,4 @@ const struct programmer_entry programmer_linux_spi = {
.type = OTHER,
.devs.note = "Device files /dev/spidev*.*\n",
.init = linux_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions mediatek_i2c_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,4 @@ const struct programmer_entry programmer_mediatek_i2c_spi = {
.type = OTHER,
.devs.note = "Device files /dev/i2c-*\n",
.init = mediatek_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions mstarddc_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,4 @@ const struct programmer_entry programmer_mstarddc_spi = {
.type = OTHER,
.devs.note = "MSTAR DDC devices addressable via /dev/i2c-* on Linux.\n",
.init = mstarddc_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions ni845x_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,4 @@ const struct programmer_entry programmer_ni845x_spi = {
.type = OTHER, // choose other because NI-845x uses own USB implementation
.devs.note = "National Instruments USB-845x\n",
.init = ni845x_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions nic3com.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,4 @@ const struct programmer_entry programmer_nic3com = {
.type = PCI,
.devs.dev = nics_3com,
.init = nic3com_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions nicintel.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,4 @@ const struct programmer_entry programmer_nicintel = {
.type = PCI,
.devs.dev = nics_intel,
.init = nicintel_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions nicintel_eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,4 @@ const struct programmer_entry programmer_nicintel_eeprom = {
.type = PCI,
.devs.dev = nics_intel_ee,
.init = nicintel_ee_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions nicintel_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,4 @@ const struct programmer_entry programmer_nicintel_spi = {
.type = PCI,
.devs.dev = nics_intel_spi,
.init = nicintel_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions nicnatsemi.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,4 @@ const struct programmer_entry programmer_nicnatsemi = {
.type = PCI,
.devs.dev = nics_natsemi,
.init = nicnatsemi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions nicrealtek.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,4 @@ const struct programmer_entry programmer_nicrealtek = {
.type = PCI,
.devs.dev = nics_realtek,
.init = nicrealtek_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions ogp_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,4 @@ const struct programmer_entry programmer_ogp_spi = {
.type = PCI,
.devs.dev = ogp_spi,
.init = ogp_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions parade_lspcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,4 @@ const struct programmer_entry programmer_parade_lspcon = {
.type = OTHER,
.devs.note = "Device files /dev/i2c-*.\n",
.init = parade_lspcon_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions pickit2_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,4 @@ const struct programmer_entry programmer_pickit2_spi = {
.type = USB,
.devs.dev = devs_pickit2_spi,
.init = pickit2_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions pony_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,4 @@ const struct programmer_entry programmer_pony_spi = {
/* FIXME */
.devs.note = "Programmers compatible with SI-Prog, serbang or AJAWe\n",
.init = pony_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions raiden_debug_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1649,6 +1649,4 @@ const struct programmer_entry programmer_raiden_debug_spi = {
.type = USB,
.devs.dev = devs_raiden,
.init = raiden_debug_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions rayer_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,4 @@ const struct programmer_entry programmer_rayer_spi = {
/* FIXME */
.devs.note = "RayeR parallel port programmer\n",
.init = rayer_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions realtek_mst_i2c_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,4 @@ const struct programmer_entry programmer_realtek_mst_i2c_spi = {
.type = OTHER,
.devs.note = "Device files /dev/i2c-*.\n",
.init = realtek_mst_i2c_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions satamv.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,4 @@ const struct programmer_entry programmer_satamv = {
.type = PCI,
.devs.dev = satas_mv,
.init = satamv_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions satasii.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,4 @@ const struct programmer_entry programmer_satasii = {
.type = PCI,
.devs.dev = satas_sii,
.init = satasii_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
1 change: 0 additions & 1 deletion serprog.c
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,5 @@ const struct programmer_entry programmer_serprog = {
.devs.note = "All programmer devices speaking the serprog protocol\n",
.init = serprog_init,
.map_flash_region = serprog_map,
.unmap_flash_region = fallback_unmap,
.delay = serprog_delay,
};
2 changes: 0 additions & 2 deletions stlinkv3_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,4 @@ const struct programmer_entry programmer_stlinkv3_spi = {
.type = USB,
.devs.dev = devs_stlinkv3_spi,
.init = stlinkv3_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};
2 changes: 0 additions & 2 deletions usbblaster_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,4 @@ const struct programmer_entry programmer_usbblaster_spi = {
.type = USB,
.devs.dev = devs_usbblasterspi,
.init = usbblaster_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
};

0 comments on commit 67d5015

Please sign in to comment.