From 0059070b22e9442ca5dc1cc5befaaeb80a8a6223 Mon Sep 17 00:00:00 2001 From: Marius Schilder Date: Tue, 12 Dec 2017 21:34:30 -0800 Subject: [PATCH] g: tweak usart queuing for stream signing Guarded by CONFIG_STREAM_SIGNING Comes at 10K cost in SRAM Used by nm50 Signed-off-by: mschilder@google.com BRANCH=cr50 BUG=none TEST=sign nm50 target dump_state 115200 output w/o overruns Change-Id: I4db2dec4de8afbeba68d1bc72f43a91fc134ff85 Reviewed-on: https://chromium-review.googlesource.com/823264 Commit-Ready: Marius Schilder Tested-by: Marius Schilder Reviewed-by: Marius Schilder Reviewed-by: Vadim Bendebury --- chip/g/usart.c | 22 +++++++++++++++++++--- chip/g/usart.h | 14 +++++++++++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/chip/g/usart.c b/chip/g/usart.c index 598b4d4ed9..667a891e42 100644 --- a/chip/g/usart.c +++ b/chip/g/usart.c @@ -16,6 +16,19 @@ defined(SECTION_IS_RO))) #define QUEUE_SIZE 64 +#ifdef CONFIG_STREAM_SIGNATURE +/* + * When signing over streaming data, up the relevant queue sizes. + */ +#define QUEUE_SIZE_SIG_IN 1024 +#define QUEUE_SIZE_USB_IN 8192 +#define QUEUE_SIZE_UART_IN 1024 +#else +#define QUEUE_SIZE_SIG_IN QUEUE_SIZE +#define QUEUE_SIZE_USB_IN QUEUE_SIZE +#define QUEUE_SIZE_UART_IN QUEUE_SIZE +#endif + #ifdef CONFIG_STREAM_USART1 struct usb_stream_config const ap_usb; @@ -34,9 +47,11 @@ struct usart_config const ap_uart; */ struct signer_config const sig; static struct queue const ap_uart_output = - QUEUE_DIRECT(QUEUE_SIZE, uint8_t, ap_uart.producer, sig.consumer); + QUEUE_DIRECT(QUEUE_SIZE_SIG_IN, uint8_t, ap_uart.producer, + sig.consumer); static struct queue const sig_to_usb = - QUEUE_DIRECT(QUEUE_SIZE, uint8_t, sig.producer, ap_usb.consumer); + QUEUE_DIRECT(QUEUE_SIZE_USB_IN, uint8_t, sig.producer, + ap_usb.consumer); SIGNER_CONFIG(sig, stream_uart, sig_to_usb, ap_uart_output); @@ -46,7 +61,8 @@ static struct queue const ap_uart_output = #endif static struct queue const ap_usb_to_uart = - QUEUE_DIRECT(QUEUE_SIZE, uint8_t, ap_usb.producer, ap_uart.consumer); + QUEUE_DIRECT(QUEUE_SIZE_UART_IN, uint8_t, ap_usb.producer, + ap_uart.consumer); /* * AP UART data is sent to the ap_uart_output queue, and received from diff --git a/chip/g/usart.h b/chip/g/usart.h index 133dc7a3af..0be7a920bb 100644 --- a/chip/g/usart.h +++ b/chip/g/usart.h @@ -7,10 +7,22 @@ #include "producer.h" #include "registers.h" #include "task.h" +#include "board.h" #ifndef __CROS_FORWARD_UART_H #define __CROS_FORWARD_UART_H +#ifdef CONFIG_STREAM_SIGNATURE +/* + * When configured for signing over streaming data, call the consumer handler + * directly to help avoid incoming uart overruns. + * Note this will run under interrupt handler so consumer beware. + */ +#define CONFIGURE_INTERRUPTS__rx_int(NAME) send_data_to_usb(&NAME) +#else +#define CONFIGURE_INTERRUPTS__rx_int(NAME) hook_call_deferred(NAME.deferred, 0) +#endif + struct usart_config { int uart; @@ -43,7 +55,7 @@ extern struct producer_ops const uart_producer_ops; GR_UART_ISTATECLR(NAME.uart) = \ GC_UART_ISTATECLR_RX_MASK; \ /* Read input FIFO until empty */ \ - hook_call_deferred(NAME.deferred, 0); \ + CONFIGURE_INTERRUPTS__rx_int(NAME); \ }