diff --git a/bitbang_spi.c b/bitbang_spi.c index fb404acc28d5e702d73bf88117125e00edf4d5b3..d63c769825a6a49254e5b424adc3f3b2d3cd96d2 100644 --- a/bitbang_spi.c +++ b/bitbang_spi.c @@ -151,14 +151,3 @@ int bitbang_spi_send_command(unsigned int writecnt, unsigned int readcnt, return 0; } - -int bitbang_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len) -{ - /* Maximum read length is unlimited, use 64k bytes. */ - return spi_read_chunked(flash, buf, start, len, 64 * 1024); -} - -int bitbang_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) -{ - return spi_write_chunked(flash, buf, start, len, 256); -} diff --git a/buspirate_spi.c b/buspirate_spi.c index d24f890b7a0bec9bab7f90c01dc79545be39c350..e7a7a10b46cdceb4e05c601a702717078b199161 100644 --- a/buspirate_spi.c +++ b/buspirate_spi.c @@ -326,13 +326,3 @@ int buspirate_spi_send_command(unsigned int writecnt, unsigned int readcnt, return ret; } - -int buspirate_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len) -{ - return spi_read_chunked(flash, buf, start, len, 12); -} - -int buspirate_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) -{ - return spi_write_chunked(flash, buf, start, len, 12); -} diff --git a/dummyflasher.c b/dummyflasher.c index d818a84ced4eb9a6219cc7def8c8857503fe83fc..b6e67db990af0cea6991157d5387de6d39319b38 100644 --- a/dummyflasher.c +++ b/dummyflasher.c @@ -507,12 +507,6 @@ int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt, return 0; } -int dummy_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len) -{ - /* Maximum read length is unlimited, use 64kB. */ - return spi_read_chunked(flash, buf, start, len, 64 * 1024); -} - int dummy_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) { return spi_write_chunked(flash, buf, start, len, diff --git a/ft2232_spi.c b/ft2232_spi.c index 737362482b741e06c78252fbed32e491b634c755..7ff1d81b4fa73f1c2ad3866588062e0d4be3ca3a 100644 --- a/ft2232_spi.c +++ b/ft2232_spi.c @@ -352,17 +352,6 @@ int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt, return failed ? -1 : 0; } -int ft2232_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len) -{ - /* Maximum read length is 64k bytes. */ - return spi_read_chunked(flash, buf, start, len, 64 * 1024); -} - -int ft2232_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) -{ - return spi_write_chunked(flash, buf, start, len, 256); -} - void print_supported_usbdevs(const struct usbdev_status *devs) { int i; diff --git a/ichspi.c b/ichspi.c index f2814d1b882912ff8dabf4bd89d9f2440902d47a..4315e78ea45db1e9498752dcf34dc8fa4a819dfc 100644 --- a/ichspi.c +++ b/ichspi.c @@ -834,26 +834,6 @@ static int run_opcode(OPCODE op, uint32_t offset, return -1; } -int ich_spi_read(struct flashchip *flash, uint8_t * buf, int start, int len) -{ - int maxdata = 64; - - if (spi_controller == SPI_CONTROLLER_VIA) - maxdata = 16; - - return spi_read_chunked(flash, buf, start, len, maxdata); -} - -int ich_spi_write_256(struct flashchip *flash, uint8_t * buf, int start, int len) -{ - int maxdata = 64; - - if (spi_controller == SPI_CONTROLLER_VIA) - maxdata = 16; - - return spi_write_chunked(flash, buf, start, len, maxdata); -} - int ich_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr) { diff --git a/it85spi.c b/it85spi.c index 1710d8e135f675ca2c513316a501b4bc0f081a06..a388d100705ca6a3fcefe53e092382581e0f4d48 100644 --- a/it85spi.c +++ b/it85spi.c @@ -347,14 +347,4 @@ int it85xx_spi_send_command(unsigned int writecnt, unsigned int readcnt, return 0; } -int it85_spi_read(struct flashchip *flash, uint8_t * buf, int start, int len) -{ - return spi_read_chunked(flash, buf, start, len, 64); -} - -int it85_spi_write_256(struct flashchip *flash, uint8_t * buf, int start, int len) -{ - return spi_write_chunked(flash, buf, start, len, 64); -} - #endif diff --git a/programmer.h b/programmer.h index 95d1fae956422892afe7aa2c0edb0d5e3f121ae8..6ade8ed791172cb3d1ec33f3ca49c725e649a8ee 100644 --- a/programmer.h +++ b/programmer.h @@ -374,7 +374,6 @@ uint32_t dummy_chip_readl(const chipaddr addr); void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len); int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr); -int dummy_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len); int dummy_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len); #endif @@ -487,8 +486,6 @@ struct usbdev_status { }; int ft2232_spi_init(void); int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr); -int ft2232_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len); -int ft2232_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len); extern const struct usbdev_status devs_ft2232spi[]; void print_supported_usbdevs(const struct usbdev_status *devs); #endif @@ -509,8 +506,6 @@ int mcp6x_spi_init(int want_spi); int bitbang_spi_init(const struct bitbang_spi_master *master, int halfperiod); int bitbang_spi_shutdown(const struct bitbang_spi_master *master); int bitbang_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr); -int bitbang_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len); -int bitbang_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len); /* buspirate_spi.c */ struct buspirate_spispeeds { @@ -520,8 +515,6 @@ struct buspirate_spispeeds { int buspirate_spi_init(void); int buspirate_spi_shutdown(void); int buspirate_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr); -int buspirate_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len); -int buspirate_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len); /* dediprog.c */ int dediprog_init(void); @@ -586,7 +579,13 @@ enum spi_controller { SPI_CONTROLLER_INVALID /* This must always be the last entry. */ }; extern const int spi_programmer_count; + +#define MAX_DATA_UNSPECIFIED 0 +#define MAX_DATA_READ_UNLIMITED 64 * 1024 +#define MAX_DATA_WRITE_UNLIMITED 256 struct spi_programmer { + int max_data_read; + int max_data_write; int (*command)(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr); int (*multicommand)(struct spi_command *cmds); @@ -601,6 +600,8 @@ extern const struct spi_programmer spi_programmer[]; int default_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr); int default_spi_send_multicommand(struct spi_command *cmds); +int default_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len); +int default_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len); /* ichspi.c */ #if CONFIG_INTERNAL == 1 @@ -610,8 +611,6 @@ int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb, int via_init_spi(struct pci_dev *dev); int ich_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr); -int ich_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len); -int ich_spi_write_256(struct flashchip *flash, uint8_t * buf, int start, int len); int ich_spi_send_multicommand(struct spi_command *cmds); #endif @@ -620,8 +619,6 @@ int it85xx_spi_init(struct superio s); int it85xx_shutdown(void); int it85xx_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr); -int it85_spi_read(struct flashchip *flash, uint8_t * buf, int start, int len); -int it85_spi_write_256(struct flashchip *flash, uint8_t * buf, int start, int len); /* it87spi.c */ void enter_conf_mode_ite(uint16_t port); @@ -638,8 +635,6 @@ int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf, int start, int sb600_probe_spi(struct pci_dev *dev); int sb600_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr); -int sb600_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len); -int sb600_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len); #endif /* wbsio_spi.c */ diff --git a/sb600spi.c b/sb600spi.c index 845cf58864b72fd4bf6ca0216deb546b40ca5a3d..269af8a0bbb57d5a8bab79dc569008472457d7a7 100644 --- a/sb600spi.c +++ b/sb600spi.c @@ -43,17 +43,6 @@ static uint8_t *sb600_spibar = NULL; -int sb600_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len) -{ - /* Maximum read length is 8 bytes. */ - return spi_read_chunked(flash, buf, start, len, 8); -} - -int sb600_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) -{ - return spi_write_chunked(flash, buf, start, len, 5); -} - static void reset_internal_fifo_pointer(void) { mmio_writeb(mmio_readb(sb600_spibar + 2) | 0x10, sb600_spibar + 2); diff --git a/spi.c b/spi.c index 7e9ff1a3bdcf79f96fe0cb1a31da8d05fcc686d1..5857fdac3e424683cc416447c96939cd8782106e 100644 --- a/spi.c +++ b/spi.c @@ -34,6 +34,8 @@ enum spi_controller spi_controller = SPI_CONTROLLER_NONE; const struct spi_programmer spi_programmer[] = { { /* SPI_CONTROLLER_NONE */ + .max_data_read = MAX_DATA_UNSPECIFIED, + .max_data_write = MAX_DATA_UNSPECIFIED, .command = NULL, .multicommand = NULL, .read = NULL, @@ -43,27 +45,35 @@ const struct spi_programmer spi_programmer[] = { #if CONFIG_INTERNAL == 1 #if defined(__i386__) || defined(__x86_64__) { /* SPI_CONTROLLER_ICH7 */ + .max_data_read = 64, + .max_data_write = 64, .command = ich_spi_send_command, .multicommand = ich_spi_send_multicommand, - .read = ich_spi_read, - .write_256 = ich_spi_write_256, + .read = default_spi_read, + .write_256 = default_spi_write_256, }, { /* SPI_CONTROLLER_ICH9 */ + .max_data_read = 64, + .max_data_write = 64, .command = ich_spi_send_command, .multicommand = ich_spi_send_multicommand, - .read = ich_spi_read, - .write_256 = ich_spi_write_256, + .read = default_spi_read, + .write_256 = default_spi_write_256, }, { /* SPI_CONTROLLER_IT85XX */ + .max_data_read = 64, + .max_data_write = 64, .command = it85xx_spi_send_command, .multicommand = default_spi_send_multicommand, - .read = it85_spi_read, - .write_256 = it85_spi_write_256, + .read = default_spi_read, + .write_256 = default_spi_write_256, }, { /* SPI_CONTROLLER_IT87XX */ + .max_data_read = MAX_DATA_UNSPECIFIED, + .max_data_write = MAX_DATA_UNSPECIFIED, .command = it8716f_spi_send_command, .multicommand = default_spi_send_multicommand, .read = it8716f_spi_chip_read, @@ -71,20 +81,26 @@ const struct spi_programmer spi_programmer[] = { }, { /* SPI_CONTROLLER_SB600 */ + .max_data_read = 8, + .max_data_write = 5, .command = sb600_spi_send_command, .multicommand = default_spi_send_multicommand, - .read = sb600_spi_read, - .write_256 = sb600_spi_write_256, + .read = default_spi_read, + .write_256 = default_spi_write_256, }, { /* SPI_CONTROLLER_VIA */ + .max_data_read = 16, + .max_data_write = 16, .command = ich_spi_send_command, .multicommand = ich_spi_send_multicommand, - .read = ich_spi_read, - .write_256 = ich_spi_write_256, + .read = default_spi_read, + .write_256 = default_spi_write_256, }, { /* SPI_CONTROLLER_WBSIO */ + .max_data_read = MAX_DATA_UNSPECIFIED, + .max_data_write = MAX_DATA_UNSPECIFIED, .command = wbsio_spi_send_command, .multicommand = default_spi_send_multicommand, .read = wbsio_spi_read, @@ -92,43 +108,53 @@ const struct spi_programmer spi_programmer[] = { }, { /* SPI_CONTROLLER_MCP6X_BITBANG */ + .max_data_read = MAX_DATA_READ_UNLIMITED, + .max_data_write = MAX_DATA_WRITE_UNLIMITED, .command = bitbang_spi_send_command, .multicommand = default_spi_send_multicommand, - .read = bitbang_spi_read, - .write_256 = bitbang_spi_write_256, + .read = default_spi_read, + .write_256 = default_spi_write_256, }, #endif #endif #if CONFIG_FT2232_SPI == 1 { /* SPI_CONTROLLER_FT2232 */ + .max_data_read = 64 * 1024, + .max_data_write = 256, .command = ft2232_spi_send_command, .multicommand = default_spi_send_multicommand, - .read = ft2232_spi_read, - .write_256 = ft2232_spi_write_256, + .read = default_spi_read, + .write_256 = default_spi_write_256, }, #endif #if CONFIG_DUMMY == 1 { /* SPI_CONTROLLER_DUMMY */ + .max_data_read = MAX_DATA_READ_UNLIMITED, + .max_data_write = MAX_DATA_UNSPECIFIED, .command = dummy_spi_send_command, .multicommand = default_spi_send_multicommand, - .read = dummy_spi_read, + .read = default_spi_read, .write_256 = dummy_spi_write_256, }, #endif #if CONFIG_BUSPIRATE_SPI == 1 { /* SPI_CONTROLLER_BUSPIRATE */ + .max_data_read = 12, + .max_data_write = 12, .command = buspirate_spi_send_command, .multicommand = default_spi_send_multicommand, - .read = buspirate_spi_read, - .write_256 = buspirate_spi_write_256, + .read = default_spi_read, + .write_256 = default_spi_write_256, }, #endif #if CONFIG_DEDIPROG == 1 { /* SPI_CONTROLLER_DEDIPROG */ + .max_data_read = MAX_DATA_UNSPECIFIED, + .max_data_write = MAX_DATA_UNSPECIFIED, .command = dediprog_spi_send_command, .multicommand = default_spi_send_multicommand, .read = dediprog_spi_read, @@ -138,28 +164,34 @@ const struct spi_programmer spi_programmer[] = { #if CONFIG_RAYER_SPI == 1 { /* SPI_CONTROLLER_RAYER */ + .max_data_read = MAX_DATA_READ_UNLIMITED, + .max_data_write = MAX_DATA_WRITE_UNLIMITED, .command = bitbang_spi_send_command, .multicommand = default_spi_send_multicommand, - .read = bitbang_spi_read, - .write_256 = bitbang_spi_write_256, + .read = default_spi_read, + .write_256 = default_spi_write_256, }, #endif #if CONFIG_NICINTEL_SPI == 1 { /* SPI_CONTROLLER_NICINTEL */ + .max_data_read = MAX_DATA_READ_UNLIMITED, + .max_data_write = MAX_DATA_WRITE_UNLIMITED, .command = bitbang_spi_send_command, .multicommand = default_spi_send_multicommand, - .read = bitbang_spi_read, - .write_256 = bitbang_spi_write_256, + .read = default_spi_read, + .write_256 = default_spi_write_256, }, #endif #if CONFIG_OGP_SPI == 1 { /* SPI_CONTROLLER_OGP */ + .max_data_read = MAX_DATA_READ_UNLIMITED, + .max_data_write = MAX_DATA_WRITE_UNLIMITED, .command = bitbang_spi_send_command, .multicommand = default_spi_send_multicommand, - .read = bitbang_spi_read, - .write_256 = bitbang_spi_write_256, + .read = default_spi_read, + .write_256 = default_spi_write_256, }, #endif @@ -223,6 +255,30 @@ int default_spi_send_multicommand(struct spi_command *cmds) return result; } +int default_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len) +{ + int max_data = spi_programmer[spi_controller].max_data_read; + if (max_data == MAX_DATA_UNSPECIFIED) { + msg_perr("%s called, but SPI read chunk size not defined " + "on this hardware. Please report a bug at " + "flashrom@flashrom.org\n", __func__); + return 1; + } + return spi_read_chunked(flash, buf, start, len, max_data); +} + +int default_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len) +{ + int max_data = spi_programmer[spi_controller].max_data_write; + if (max_data == MAX_DATA_UNSPECIFIED) { + msg_perr("%s called, but SPI write chunk size not defined " + "on this hardware. Please report a bug at " + "flashrom@flashrom.org\n", __func__); + return 1; + } + return spi_write_chunked(flash, buf, start, len, max_data); +} + int spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len) { int addrbase = 0;