trunks: improve FIFO read processing

When reading the FIFO contents in FTDI mode, the host polls the status
register to find out if there is more data available and keeps reading
one byte of FIFO data at a time. This makes FIFO read transactions
very slow.

The typical TPM response always includes a 6 byte header and then some
more data. The actual size of the response is stored in the network
byte order in the last 4 bytes of the header.

To speed up FIFO reads, we now always start with reading the first six
bytes. Once they are read, the total response size can be determined,
and the rest of the payload less one byte can be read. At this point
the 'data available' bit in the TPM_STS register must still be
asserted. Then we read the last byte from the FIFO and verify that the
'data available' is deasserted after that. This verifies that the FIFO
contents and the TPM__STS registers are in sync.

BUG=chrome-os-partner:43025
TEST=verified that trunksd starts up successfully when initializing
     CR50 over the FTDI interface.

Change-Id: I5d9ccf0df94eb7935667feff9e9a00caf447a5ff
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/293864
Reviewed-by: Utkarsh Sanghi <usanghi@chromium.org>
1 file changed
tree: 4c1c0641175982c172f7354e08f40b058c2b7875
  1. ftdi/
  2. generator/
  3. authorization_delegate.h
  4. background_command_transceiver.cc
  5. background_command_transceiver.h
  6. background_command_transceiver_test.cc
  7. blob_parser.cc
  8. blob_parser.h
  9. command_transceiver.h
  10. CPPLINT.cfg
  11. dbus_interface.h
  12. dbus_interface.proto
  13. error_codes.cc
  14. error_codes.h
  15. hmac_authorization_delegate.cc
  16. hmac_authorization_delegate.h
  17. hmac_authorization_delegate_unittest.cc
  18. hmac_session.h
  19. hmac_session_impl.cc
  20. hmac_session_impl.h
  21. hmac_session_test.cc
  22. Makefile
  23. mock_authorization_delegate.cc
  24. mock_authorization_delegate.h
  25. mock_blob_parser.cc
  26. mock_blob_parser.h
  27. mock_command_transceiver.cc
  28. mock_command_transceiver.h
  29. mock_hmac_session.cc
  30. mock_hmac_session.h
  31. mock_policy_session.cc
  32. mock_policy_session.h
  33. mock_session_manager.cc
  34. mock_session_manager.h
  35. mock_tpm.cc
  36. mock_tpm.h
  37. mock_tpm_state.cc
  38. mock_tpm_state.h
  39. mock_tpm_utility.cc
  40. mock_tpm_utility.h
  41. org.chromium.Trunks.conf
  42. OWNERS
  43. password_authorization_delegate.cc
  44. password_authorization_delegate.h
  45. password_authorization_delegate_unittest.cc
  46. policy_session.h
  47. policy_session_impl.cc
  48. policy_session_impl.h
  49. policy_session_test.cc
  50. README
  51. resource_manager.cc
  52. resource_manager.h
  53. resource_manager_test.cc
  54. scoped_key_handle.cc
  55. scoped_key_handle.h
  56. scoped_key_handle_test.cc
  57. session_manager.h
  58. session_manager_impl.cc
  59. session_manager_impl.h
  60. session_manager_test.cc
  61. tpm_constants.h
  62. tpm_generated.cc
  63. tpm_generated.h
  64. tpm_generated_test.cc
  65. tpm_handle.cc
  66. tpm_handle.h
  67. tpm_simulator_handle.cc
  68. tpm_simulator_handle.h
  69. tpm_state.h
  70. tpm_state_impl.cc
  71. tpm_state_impl.h
  72. tpm_state_test.cc
  73. tpm_utility.h
  74. tpm_utility_impl.cc
  75. tpm_utility_impl.h
  76. tpm_utility_test.cc
  77. trunks.gyp
  78. trunks_client.cc
  79. trunks_client_test.cc
  80. trunks_client_test.h
  81. trunks_export.h
  82. trunks_factory.h
  83. trunks_factory_for_test.cc
  84. trunks_factory_for_test.h
  85. trunks_factory_impl.cc
  86. trunks_factory_impl.h
  87. trunks_ftdi_spi.cc
  88. trunks_ftdi_spi.h
  89. trunks_proxy.cc
  90. trunks_proxy.h
  91. trunks_service.cc
  92. trunks_service.h
  93. trunks_testrunner.cc
  94. trunksd-seccomp-amd64.policy
  95. trunksd-seccomp-arm.policy
  96. trunksd-seccomp-x86.policy
  97. trunksd.cc
  98. trunksd.conf