David Hendricks has uploaded this change for review. ( https://review.coreboot.org/22344
Change subject: linux_spi: Dynamically detect max buffer size ......................................................................
linux_spi: Dynamically detect max buffer size
The max buffer size of the linux kernel's SPI device is a compile-time parameter. Read it on initialization and use it to inform the max transfer size. We allow up to 5 bytes for the SPI command. On master, SPI commands are always 4 bytes, but 4ba support will raise that to 5. Choosing 5 makes sure this will keep working when 4ba support is merged.
Change-Id: Ic541e548ced8488f074d388f1c92174cad123064 Signed-off-by: Keno Fischer keno@juliacomputing.com --- M linux_spi.c 1 file changed, 18 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/44/22344/1
diff --git a/linux_spi.c b/linux_spi.c index e51fbc4..f7d9434 100644 --- a/linux_spi.c +++ b/linux_spi.c @@ -42,6 +42,7 @@ */
static int fd = -1; +static size_t max_kernel_buf_size = 4096;
static int linux_spi_shutdown(void *data); static int linux_spi_send_command(struct flashctx *flash, unsigned int writecnt, @@ -127,6 +128,19 @@ return 1; }
+ /* Try to read the kernel's max bufsize */ + char buf[10]; + memset(buf, 0, sizeof(buf)); + int param_fd = open("/sys/module/spidev/parameters/bufsiz", O_RDONLY); + if (param_fd == -1 || read(param_fd, &buf, sizeof(buf) - 1) == -1) { + msg_pwarn("%s: failed to retrieve kernel buffer size. Attempting to use default.\n", __func__); + } else { + max_kernel_buf_size = atoi(buf); + } + + if (param_fd != -1) + close(param_fd); + register_spi_master(&spi_master_linux);
return 0; @@ -182,14 +196,16 @@ static int linux_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len) { + /* The size of the command and the buffer may add up to no more than max_kernel_buf_size. + At the moment the command size is at most 5 bytes, so allow the rest for the buffer. */ return spi_read_chunked(flash, buf, start, len, - (unsigned int)getpagesize()); + max_kernel_buf_size - 5); }
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, - ((unsigned int)getpagesize()) - 4); + max_kernel_buf_size - 5); }
#endif // CONFIG_LINUX_SPI == 1