mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 23:22:37 +02:00
linux_spi: Dynamically detect max buffer size
Read max buffer size from sysfs if available. Change-Id: Ic541e548ced8488f074d388f1c92174cad123064 Signed-off-by: Keno Fischer <keno@juliacomputing.com> Signed-off-by: David Hendricks <dhendricks@fb.com> Reviewed-on: https://review.coreboot.org/22441 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nico Huber <nico.h@gmx.de>
This commit is contained in:
parent
22f2dc5ec0
commit
1f33cb5800
52
linux_spi.c
52
linux_spi.c
@ -42,6 +42,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static int fd = -1;
|
static int fd = -1;
|
||||||
|
#define BUF_SIZE_FROM_SYSFS "/sys/module/spidev/parameters/bufsiz"
|
||||||
|
static size_t max_kernel_buf_size;
|
||||||
|
|
||||||
static int linux_spi_shutdown(void *data);
|
static int linux_spi_shutdown(void *data);
|
||||||
static int linux_spi_send_command(struct flashctx *flash, unsigned int writecnt,
|
static int linux_spi_send_command(struct flashctx *flash, unsigned int writecnt,
|
||||||
@ -127,8 +129,45 @@ int linux_spi_init(void)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
register_spi_master(&spi_master_linux);
|
/* Read max buffer size from sysfs, or use page size as fallback. */
|
||||||
|
FILE *fp;
|
||||||
|
fp = fopen(BUF_SIZE_FROM_SYSFS, "r");
|
||||||
|
if (!fp) {
|
||||||
|
msg_pwarn("Cannot open %s: %s.\n", BUF_SIZE_FROM_SYSFS, strerror(errno));
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
char buf[10];
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
if (!fread(buf, 1, sizeof(buf) - 1, fp)) {
|
||||||
|
if (feof(fp))
|
||||||
|
msg_pwarn("Cannot read %s: file is empty.\n", BUF_SIZE_FROM_SYSFS);
|
||||||
|
else
|
||||||
|
msg_pwarn("Cannot read %s: %s.\n", BUF_SIZE_FROM_SYSFS, strerror(errno));
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
long int tmp;
|
||||||
|
errno = 0;
|
||||||
|
tmp = strtol(buf, NULL, 0);
|
||||||
|
if ((tmp < 0) || errno) {
|
||||||
|
msg_pwarn("Buffer size %ld from %s seems wrong.\n", tmp, BUF_SIZE_FROM_SYSFS);
|
||||||
|
} else {
|
||||||
|
msg_pdbg("%s: Using value from %s as max buffer size.\n", __func__, BUF_SIZE_FROM_SYSFS);
|
||||||
|
max_kernel_buf_size = (size_t)tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (fp)
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
if (!max_kernel_buf_size) {
|
||||||
|
msg_pdbg("%s: Using page size as max buffer size.\n", __func__);
|
||||||
|
max_kernel_buf_size = (size_t)getpagesize();
|
||||||
|
}
|
||||||
|
|
||||||
|
msg_pdbg("%s: max_kernel_buf_size: %zu\n", __func__, max_kernel_buf_size);
|
||||||
|
register_spi_master(&spi_master_linux);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,17 +218,16 @@ static int linux_spi_send_command(struct flashctx *flash, unsigned int writecnt,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int linux_spi_read(struct flashctx *flash, uint8_t *buf,
|
static int linux_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len)
|
||||||
unsigned int start, unsigned int len)
|
|
||||||
{
|
{
|
||||||
return spi_read_chunked(flash, buf, start, len,
|
/* Read buffer is fully utilized for data. */
|
||||||
(unsigned int)getpagesize());
|
return spi_read_chunked(flash, buf, start, len, max_kernel_buf_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int linux_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len)
|
static int linux_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len)
|
||||||
{
|
{
|
||||||
return spi_write_chunked(flash, buf, start, len,
|
/* 5 bytes must be reserved for longest possible command + address. */
|
||||||
((unsigned int)getpagesize()) - 4);
|
return spi_write_chunked(flash, buf, start, len, max_kernel_buf_size - 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CONFIG_LINUX_SPI == 1
|
#endif // CONFIG_LINUX_SPI == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user