mirror of
https://git.savannah.gnu.org/git/grub.git
synced 2026-10-24 16:19:22 +00:00
indent code coming from depthcharge and add missing acknowledgements
This commit is contained in:
1 parent
8af937d133
commit
3bf4907004
2 files changed
+55
-36
No files matched your search
@@ -4,6 +4,8 @@
|
|||||||
* Copyright (C) 2012 Google Inc.
|
* Copyright (C) 2012 Google Inc.
|
||||||
* Copyright (C) 2016 Free Software Foundation, Inc.
|
* Copyright (C) 2016 Free Software Foundation, Inc.
|
||||||
*
|
*
|
||||||
|
* This is based on depthcharge code.
|
||||||
|
*
|
||||||
* GRUB is free software: you can redistribute it and/or modify
|
* GRUB is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
* Copyright (C) 2012 Google Inc.
|
* Copyright (C) 2012 Google Inc.
|
||||||
* Copyright (C) 2016 Free Software Foundation, Inc.
|
* Copyright (C) 2016 Free Software Foundation, Inc.
|
||||||
*
|
*
|
||||||
|
* This is based on depthcharge code.
|
||||||
|
*
|
||||||
* GRUB is free software: you can redistribute it and/or modify
|
* GRUB is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
@@ -102,25 +104,30 @@ static const uint8_t EcFramingByte = 0xec;
|
|||||||
|
|
||||||
static uint64_t last_transfer;
|
static uint64_t last_transfer;
|
||||||
|
|
||||||
static void stop_bus(void)
|
static void
|
||||||
|
stop_bus (void)
|
||||||
{
|
{
|
||||||
spi_stop ();
|
spi_stop ();
|
||||||
last_transfer = grub_get_time_us ();
|
last_transfer = grub_get_time_us ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int wait_for_frame(void)
|
static int
|
||||||
|
wait_for_frame (void)
|
||||||
{
|
{
|
||||||
uint64_t start = grub_get_time_us ();
|
uint64_t start = grub_get_time_us ();
|
||||||
uint8_t byte;
|
uint8_t byte;
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
if (spi_read (&byte, 1))
|
if (spi_read (&byte, 1))
|
||||||
return -1;
|
return -1;
|
||||||
if (byte != EcFramingByte &&
|
if (byte != EcFramingByte &&
|
||||||
grub_get_time_us() - start > FramingTimeoutUs) {
|
grub_get_time_us () - start > FramingTimeoutUs)
|
||||||
|
{
|
||||||
grub_dprintf ("cros", "Timeout waiting for framing byte.\n");
|
grub_dprintf ("cros", "Timeout waiting for framing byte.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} while (byte != EcFramingByte);
|
}
|
||||||
|
while (byte != EcFramingByte);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +138,8 @@ static int wait_for_frame(void)
|
|||||||
* @param size Size of data block in bytes
|
* @param size Size of data block in bytes
|
||||||
* @return checksum value (0 to 255)
|
* @return checksum value (0 to 255)
|
||||||
*/
|
*/
|
||||||
static uint8_t cros_ec_calc_checksum(const void *data, int size)
|
static uint8_t
|
||||||
|
cros_ec_calc_checksum (const void *data, int size)
|
||||||
{
|
{
|
||||||
uint8_t csum;
|
uint8_t csum;
|
||||||
const uint8_t *bytes = data;
|
const uint8_t *bytes = data;
|
||||||
@@ -142,23 +150,24 @@ static uint8_t cros_ec_calc_checksum(const void *data, int size)
|
|||||||
return csum & 0xff;
|
return csum & 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum {
|
enum
|
||||||
// response, arglen
|
{
|
||||||
|
/* response, arglen */
|
||||||
CROS_EC_SPI_IN_HDR_SIZE = 2,
|
CROS_EC_SPI_IN_HDR_SIZE = 2,
|
||||||
// version, cmd, arglen
|
/* version, cmd, arglen */
|
||||||
CROS_EC_SPI_OUT_HDR_SIZE = 3
|
CROS_EC_SPI_OUT_HDR_SIZE = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
static grub_uint8_t busbuf[256];
|
static grub_uint8_t busbuf[256];
|
||||||
#define MSG_BYTES ((int)sizeof (busbuf))
|
#define MSG_BYTES ((int)sizeof (busbuf))
|
||||||
|
|
||||||
static int ec_command(int cmd, int cmd_version,
|
static int
|
||||||
const void *dout, int dout_len,
|
ec_command (int cmd, int cmd_version,
|
||||||
void *din, int din_len)
|
const void *dout, int dout_len, void *din, int din_len)
|
||||||
{
|
{
|
||||||
uint8_t *bytes;
|
uint8_t *bytes;
|
||||||
|
|
||||||
// Header + data + checksum.
|
/* Header + data + checksum. */
|
||||||
uint32_t out_bytes = CROS_EC_SPI_OUT_HDR_SIZE + dout_len + 1;
|
uint32_t out_bytes = CROS_EC_SPI_OUT_HDR_SIZE + dout_len + 1;
|
||||||
uint32_t in_bytes = CROS_EC_SPI_IN_HDR_SIZE + din_len + 1;
|
uint32_t in_bytes = CROS_EC_SPI_IN_HDR_SIZE + din_len + 1;
|
||||||
|
|
||||||
@@ -166,16 +175,18 @@ static int ec_command(int cmd, int cmd_version,
|
|||||||
* Sanity-check I/O sizes given transaction overhead in internal
|
* Sanity-check I/O sizes given transaction overhead in internal
|
||||||
* buffers.
|
* buffers.
|
||||||
*/
|
*/
|
||||||
if (out_bytes > MSG_BYTES) {
|
if (out_bytes > MSG_BYTES)
|
||||||
|
{
|
||||||
grub_dprintf ("cros", "Cannot send %d bytes\n", dout_len);
|
grub_dprintf ("cros", "Cannot send %d bytes\n", dout_len);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (in_bytes > MSG_BYTES) {
|
if (in_bytes > MSG_BYTES)
|
||||||
|
{
|
||||||
grub_dprintf ("cros", "Cannot receive %d bytes\n", din_len);
|
grub_dprintf ("cros", "Cannot receive %d bytes\n", din_len);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare the output.
|
/* Prepare the output. */
|
||||||
bytes = busbuf;
|
bytes = busbuf;
|
||||||
*bytes++ = EC_CMD_VERSION0 + cmd_version;
|
*bytes++ = EC_CMD_VERSION0 + cmd_version;
|
||||||
*bytes++ = cmd;
|
*bytes++ = cmd;
|
||||||
@@ -192,40 +203,44 @@ static int ec_command(int cmd, int cmd_version,
|
|||||||
if (spi_start ())
|
if (spi_start ())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// Allow EC to ramp up clock after being awoken.
|
/* Allow EC to ramp up clock after being awoken. */
|
||||||
// See chrome-os-partner:32223 for more details.
|
/* See chrome-os-partner:32223 for more details. */
|
||||||
grub_microsleep (100);
|
grub_microsleep (100);
|
||||||
|
|
||||||
if (spi_send(busbuf, out_bytes)) {
|
if (spi_send (busbuf, out_bytes))
|
||||||
|
{
|
||||||
stop_bus ();
|
stop_bus ();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait until the EC is ready.
|
/* Wait until the EC is ready. */
|
||||||
if (wait_for_frame()) {
|
if (wait_for_frame ())
|
||||||
|
{
|
||||||
stop_bus ();
|
stop_bus ();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the response code and the data length.
|
/* Read the response code and the data length. */
|
||||||
bytes = busbuf;
|
bytes = busbuf;
|
||||||
if (spi_read(bytes, 2)) {
|
if (spi_read (bytes, 2))
|
||||||
|
{
|
||||||
stop_bus ();
|
stop_bus ();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
uint8_t result = *bytes++;
|
uint8_t result = *bytes++;
|
||||||
uint8_t length = *bytes++;
|
uint8_t length = *bytes++;
|
||||||
|
|
||||||
// Make sure there's enough room for the data.
|
/* Make sure there's enough room for the data. */
|
||||||
if (CROS_EC_SPI_IN_HDR_SIZE + length + 1 > MSG_BYTES) {
|
if (CROS_EC_SPI_IN_HDR_SIZE + length + 1 > MSG_BYTES)
|
||||||
grub_dprintf("cros", "Received length %#02x too large\n",
|
{
|
||||||
length);
|
grub_dprintf ("cros", "Received length %#02x too large\n", length);
|
||||||
stop_bus ();
|
stop_bus ();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the data and the checksum, and finish up.
|
/* Read the data and the checksum, and finish up. */
|
||||||
if (spi_read(bytes, length + 1)) {
|
if (spi_read (bytes, length + 1))
|
||||||
|
{
|
||||||
stop_bus ();
|
stop_bus ();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -233,8 +248,9 @@ static int ec_command(int cmd, int cmd_version,
|
|||||||
int expected = *bytes++;
|
int expected = *bytes++;
|
||||||
stop_bus ();
|
stop_bus ();
|
||||||
|
|
||||||
// Check the integrity of the response.
|
/* Check the integrity of the response. */
|
||||||
if (result != 0) {
|
if (result != 0)
|
||||||
|
{
|
||||||
grub_dprintf ("cros", "Received bad result code %d\n", result);
|
grub_dprintf ("cros", "Received bad result code %d\n", result);
|
||||||
return -result;
|
return -result;
|
||||||
}
|
}
|
||||||
@@ -242,18 +258,19 @@ static int ec_command(int cmd, int cmd_version,
|
|||||||
int csum = cros_ec_calc_checksum (busbuf,
|
int csum = cros_ec_calc_checksum (busbuf,
|
||||||
CROS_EC_SPI_IN_HDR_SIZE + length);
|
CROS_EC_SPI_IN_HDR_SIZE + length);
|
||||||
|
|
||||||
if (csum != expected) {
|
if (csum != expected)
|
||||||
|
{
|
||||||
grub_dprintf ("cros", "Invalid checksum rx %#02x, calced %#02x\n",
|
grub_dprintf ("cros", "Invalid checksum rx %#02x, calced %#02x\n",
|
||||||
expected, csum);
|
expected, csum);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the caller wants the response, copy it out for them.
|
/* If the caller wants the response, copy it out for them. */
|
||||||
if (length < din_len)
|
if (length < din_len)
|
||||||
din_len = length;
|
din_len = length;
|
||||||
if (din) {
|
if (din)
|
||||||
memcpy(din, (uint8_t *)busbuf + CROS_EC_SPI_IN_HDR_SIZE,
|
{
|
||||||
din_len);
|
memcpy (din, (uint8_t *) busbuf + CROS_EC_SPI_IN_HDR_SIZE, din_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return din_len;
|
return din_len;
|
||||||
|
|||||||
Reference in new issue
Block a user