// Copyright lowRISC contributors.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "sw/device/lib/testing/json/spi_passthru.h"

#include <stdbool.h>
#include <stdint.h>

#include "sw/device/lib/arch/device.h"
#include "sw/device/lib/base/status.h"
#include "sw/device/lib/dif/dif_spi_device.h"
#include "sw/device/lib/dif/dif_spi_host.h"
#include "sw/device/lib/runtime/log.h"
#include "sw/device/lib/testing/json/command.h"
#include "sw/device/lib/testing/spi_device_testutils.h"
#include "sw/device/lib/testing/spi_flash_testutils.h"
#include "sw/device/lib/testing/test_framework/check.h"
#include "sw/device/lib/testing/test_framework/ottf_flow_control.h"
#include "sw/device/lib/testing/test_framework/ottf_main.h"
#include "sw/device/lib/testing/test_framework/ujson_ottf.h"
#include "sw/device/lib/ujson/ujson.h"

#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"

OTTF_DEFINE_TEST_CONFIG(.enable_uart_flow_control = true);

static dif_spi_device_handle_t spid;
static dif_spi_host_t spih;

static status_t configure_jedec_id(ujson_t *uj, dif_spi_device_handle_t *spid) {
  config_jedec_id_t config;
  TRY(ujson_deserialize_config_jedec_id_t(uj, &config));
  dif_spi_device_flash_id_t id = {
      .device_id = config.device_id,
      .manufacturer_id = config.manufacturer_id,
      .continuation_code = config.continuation_code,
      .num_continuation_code = config.continuation_len,
  };
  TRY(dif_spi_device_set_flash_id(spid, id));
  return RESP_OK_STATUS(uj);
}

static status_t write_status_register(ujson_t *uj,
                                      dif_spi_device_handle_t *spid) {
  status_register_t sr;
  TRY(ujson_deserialize_status_register_t(uj, &sr));
  TRY(dif_spi_device_set_flash_status_registers(spid, sr.status));
  return RESP_OK_STATUS(uj);
}

static status_t read_status_register(ujson_t *uj,
                                     dif_spi_device_handle_t *spid) {
  status_register_t sr;
  dif_toggle_t addr_4b;
  TRY(dif_spi_device_get_flash_status_registers(spid, &sr.status));
  TRY(dif_spi_device_get_4b_address_mode(spid, &addr_4b));
  sr.addr_4b = addr_4b;
  RESP_OK(ujson_serialize_status_register_t, uj, &sr);
  return OK_STATUS();
}

static status_t write_sfdp_data(ujson_t *uj, dif_spi_device_handle_t *spid) {
  sfdp_data_t sfdp;
  TRY(ujson_deserialize_sfdp_data_t(uj, &sfdp));
  TRY(dif_spi_device_write_flash_buffer(spid, kDifSpiDeviceFlashBufferTypeSfdp,
                                        0, sizeof(sfdp.data), sfdp.data));
  return RESP_OK_STATUS(uj);
}

static status_t wait_for_upload(ujson_t *uj, dif_spi_device_handle_t *spid) {
  // Wait for a SPI transaction cause an upload.
  bool upload_pending;
  do {
    // The UploadCmdfifoNotEmpty interrupt status is updated after the SPI
    // transaction completes.
    TRY(dif_spi_device_irq_is_pending(
        &spid->dev, kDifSpiDeviceIrqUploadCmdfifoNotEmpty, &upload_pending));
  } while (!upload_pending);

  upload_info_t info = {0};
  uint8_t occupancy;

  // Get the SPI opcode.
  TRY(dif_spi_device_get_flash_command_fifo_occupancy(spid, &occupancy));
  if (occupancy != 1) {
    // Cannot have an uploaded command without an opcode.
    return INTERNAL();
  }
  TRY(dif_spi_device_pop_flash_command_fifo(spid, &info.opcode));
  // Get the flash_status register.
  TRY(dif_spi_device_get_flash_status_registers(spid, &info.flash_status));

  // Get the SPI address (if available).
  TRY(dif_spi_device_get_flash_address_fifo_occupancy(spid, &occupancy));
  if (occupancy) {
    dif_toggle_t addr_4b;
    TRY(dif_spi_device_get_4b_address_mode(spid, &addr_4b));
    info.addr_4b = addr_4b;
    TRY(dif_spi_device_pop_flash_address_fifo(spid, &info.address));
    info.has_address = true;
  }

  // Get the SPI data payload (if available).
  uint32_t start;
  TRY(dif_spi_device_get_flash_payload_fifo_occupancy(spid, &info.data_len,
                                                      &start));
  if (info.data_len) {
    if (info.data_len > sizeof(info.data)) {
      // We aren't expecting more than 256 bytes of data.
      return INVALID_ARGUMENT();
    }
    TRY(dif_spi_device_read_flash_buffer(spid,
                                         kDifSpiDeviceFlashBufferTypePayload,
                                         start, info.data_len, info.data));
  }

  // Finished: ack the IRQ and clear the busy bit (and all other bits)
  // in flash_status.
  TRY(dif_spi_device_irq_acknowledge(&spid->dev,
                                     kDifSpiDeviceIrqUploadCmdfifoNotEmpty));
  TRY(dif_spi_device_set_flash_status_registers(spid, 0));
  RESP_OK(ujson_serialize_upload_info_t, uj, &info);
  return OK_STATUS();
}

status_t spi_flash_read_id(ujson_t *uj, dif_spi_host_t *spih,
                           dif_spi_device_handle_t *spid) {
  TRY(dif_spi_device_set_passthrough_mode(spid, kDifToggleDisabled));
  spi_flash_testutils_jedec_id_t jedec_id;
  spi_flash_testutils_read_id(spih, &jedec_id);
  TRY(dif_spi_device_set_passthrough_mode(spid, kDifToggleEnabled));

  spi_flash_read_id_t uj_id = {
      .device_id = jedec_id.device_id,
      .manufacturer_id = jedec_id.manufacturer_id,
      .continuation_len = jedec_id.continuation_len,
  };
  return RESP_OK(ujson_serialize_spi_flash_read_id_t, uj, &uj_id);
}

status_t spi_flash_read_sfdp(ujson_t *uj, dif_spi_host_t *spih,
                             dif_spi_device_handle_t *spid) {
  TRY(dif_spi_device_set_passthrough_mode(spid, kDifToggleDisabled));
  spi_flash_read_sfdp_t op;
  TRY(ujson_deserialize_spi_flash_read_sfdp_t(uj, &op));

  sfdp_data_t sfdp;
  CHECK(op.length <= sizeof(sfdp.data));
  spi_flash_testutils_read_sfdp(spih, op.address, sfdp.data, op.length);
  TRY(dif_spi_device_set_passthrough_mode(spid, kDifToggleEnabled));

  return RESP_OK(ujson_serialize_sfdp_data_t, uj, &sfdp);
}

status_t spi_flash_erase_sector(ujson_t *uj, dif_spi_host_t *spih,
                                dif_spi_device_handle_t *spid) {
  spi_flash_erase_sector_t op;
  TRY(dif_spi_device_set_passthrough_mode(spid, kDifToggleDisabled));
  TRY(ujson_deserialize_spi_flash_erase_sector_t(uj, &op));
  spi_flash_testutils_erase_sector(spih, op.address, op.addr4b);
  TRY(dif_spi_device_set_passthrough_mode(spid, kDifToggleEnabled));
  return RESP_OK_STATUS(uj);
}

status_t spi_flash_write(ujson_t *uj, dif_spi_host_t *spih,
                         dif_spi_device_handle_t *spid) {
  spi_flash_write_t op;
  TRY(dif_spi_device_set_passthrough_mode(spid, kDifToggleDisabled));
  TRY(ujson_deserialize_spi_flash_write_t(uj, &op));
  if (op.length > sizeof(op.data)) {
    LOG_ERROR("Flash write length larger than buffer: %u", op.length);
    return INVALID_ARGUMENT();
  }

  spi_flash_testutils_program_page(spih, op.data, op.length, op.address,
                                   op.addr4b);
  TRY(dif_spi_device_set_passthrough_mode(spid, kDifToggleEnabled));
  return RESP_OK_STATUS(uj);
}

status_t command_processor(ujson_t *uj) {
  while (true) {
    test_command_t command;
    TRY(ujson_deserialize_test_command_t(uj, &command));
    switch (command) {
      case kTestCommandSpiConfigureJedecId:
        RESP_ERR(uj, configure_jedec_id(uj, &spid));
        break;
      case kTestCommandSpiReadStatus:
        RESP_ERR(uj, read_status_register(uj, &spid));
        break;
      case kTestCommandSpiWriteStatus:
        RESP_ERR(uj, write_status_register(uj, &spid));
        break;
      case kTestCommandSpiWriteSfdp:
        RESP_ERR(uj, write_sfdp_data(uj, &spid));
        break;
      case kTestCommandSpiWaitForUpload:
        RESP_ERR(uj, wait_for_upload(uj, &spid));
        break;
      case kTestCommandSpiFlashReadId:
        RESP_ERR(uj, spi_flash_read_id(uj, &spih, &spid));
        break;
      case kTestCommandSpiFlashReadSfdp:
        RESP_ERR(uj, spi_flash_read_sfdp(uj, &spih, &spid));
        break;
      case kTestCommandSpiFlashEraseSector:
        RESP_ERR(uj, spi_flash_erase_sector(uj, &spih, &spid));
        break;
      case kTestCommandSpiFlashWrite:
        RESP_ERR(uj, spi_flash_write(uj, &spih, &spid));
        break;

      default:
        LOG_ERROR("Unrecognized command: %d", command);
        RESP_ERR(uj, INVALID_ARGUMENT());
    }
  }
  // We should never reach here.
  return INTERNAL();
}

bool test_main(void) {
  const uint32_t spi_host_clock_freq_hz =
      (uint32_t)kClockFreqHiSpeedPeripheralHz;
  CHECK_DIF_OK(dif_spi_host_init(
      mmio_region_from_addr(TOP_EARLGREY_SPI_HOST0_BASE_ADDR), &spih));
  dif_spi_host_config_t config = {
      .spi_clock = spi_host_clock_freq_hz / 4,
      .peripheral_clock_freq_hz = spi_host_clock_freq_hz,
      .chip_select =
          {
              .idle = 2,
              .trail = 2,
              .lead = 2,
          },
  };
  CHECK_DIF_OK(dif_spi_host_configure(&spih, config));
  CHECK_DIF_OK(dif_spi_host_output_set_enabled(&spih, /*enabled=*/true));

  CHECK_DIF_OK(dif_spi_device_init_handle(
      mmio_region_from_addr(TOP_EARLGREY_SPI_DEVICE_BASE_ADDR), &spid));

  // We want to block passthru of the first 5 read commands, corresponding to
  // ReadStatus{1,2,3}, ReadJedecID and ReadSfdp.
  // We also block all write commands.
  spi_device_testutils_configure_passthrough(&spid,
                                             /*filters=*/0x1F,
                                             /*upload_write_commands=*/true);

  dif_spi_device_passthrough_intercept_config_t passthru_cfg = {
      .status = true,
      .jedec_id = true,
      .sfdp = true,
      .mailbox = false,
  };
  CHECK_DIF_OK(
      dif_spi_device_set_passthrough_intercept_config(&spid, passthru_cfg));

  ujson_t uj = ujson_ottf_console();
  status_t s = command_processor(&uj);
  LOG_INFO("status = %r", s);
  return status_ok(s);
}
