summaryrefslogtreecommitdiff
path: root/chip/host
diff options
context:
space:
mode:
authorJack Rosenthal <jrosenth@chromium.org>2021-11-04 12:11:58 -0600
committerCommit Bot <commit-bot@chromium.org>2021-11-05 04:22:34 +0000
commit252457d4b21f46889eebad61d4c0a65331919cec (patch)
tree01856c4d31d710b20e85a74c8d7b5836e35c3b98 /chip/host
parent08f5a1e6fc2c9467230444ac9b582dcf4d9f0068 (diff)
downloadchrome-ec-252457d4b21f46889eebad61d4c0a65331919cec.tar.gz
In the interest of making long-term branch maintenance incur as little technical debt on us as possible, we should not maintain any files on the branch we are not actually using. This has the added effect of making it extremely clear when merging CLs from the main branch when changes have the possibility to affect us. The follow-on CL adds a convenience script to actually pull updates from the main branch and generate a CL for the update. BUG=b:204206272 BRANCH=ish TEST=make BOARD=arcada_ish && make BOARD=drallion_ish Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: I17e4694c38219b5a0823e0a3e55a28d1348f4b18 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3262038 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Tom Hughes <tomhughes@chromium.org>
Diffstat (limited to 'chip/host')
-rw-r--r--chip/host/adc_chip.h16
-rw-r--r--chip/host/build.mk21
-rw-r--r--chip/host/clock.c13
-rw-r--r--chip/host/config_chip.h58
-rw-r--r--chip/host/flash.c177
-rw-r--r--chip/host/gpio.c98
-rw-r--r--chip/host/host_test.h17
-rw-r--r--chip/host/i2c.c137
-rw-r--r--chip/host/keyboard_raw.c46
-rw-r--r--chip/host/lpc.c33
-rw-r--r--chip/host/persistence.c110
-rw-r--r--chip/host/persistence.h27
-rw-r--r--chip/host/reboot.c32
-rw-r--r--chip/host/reboot.h18
-rw-r--r--chip/host/registers.h11
-rw-r--r--chip/host/spi_controller.c42
-rw-r--r--chip/host/system.c282
-rw-r--r--chip/host/trng.c40
-rw-r--r--chip/host/uart.c195
-rw-r--r--chip/host/usb_pd_phy.c370
20 files changed, 0 insertions, 1743 deletions
diff --git a/chip/host/adc_chip.h b/chip/host/adc_chip.h
deleted file mode 100644
index 8754be266e..0000000000
--- a/chip/host/adc_chip.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/* Host-specific ADC module for Chrome EC */
-
-#ifndef __CROS_EC_ADC_CHIP_H
-#define __CROS_EC_ADC_CHIP_H
-
-/* Place-holder data structure to define ADC channels. */
-struct adc_t {
- int unused;
-};
-
-#endif /* __CROS_EC_ADC_CHIP_H */
diff --git a/chip/host/build.mk b/chip/host/build.mk
deleted file mode 100644
index 6f8ea250ca..0000000000
--- a/chip/host/build.mk
+++ /dev/null
@@ -1,21 +0,0 @@
-# -*- makefile -*-
-# Copyright 2013 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-#
-# emulator specific files build
-#
-
-CORE:=host
-
-chip-y=system.o gpio.o uart.o persistence.o flash.o lpc.o reboot.o \
- clock.o spi_controller.o trng.o
-
-ifndef CONFIG_KEYBOARD_NOT_RAW
-chip-$(HAS_TASK_KEYSCAN)+=keyboard_raw.o
-endif
-chip-$(CONFIG_USB_PD_TCPC)+=usb_pd_phy.o
-
-dirs-y += chip/host/dcrypto
-
-chip-$(CONFIG_I2C)+= i2c.o
diff --git a/chip/host/clock.c b/chip/host/clock.c
deleted file mode 100644
index 2c3c48661e..0000000000
--- a/chip/host/clock.c
+++ /dev/null
@@ -1,13 +0,0 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Mock clock driver for unit test.
- */
-
-#include "clock.h"
-
-int clock_get_freq(void)
-{
- return 16000000;
-}
diff --git a/chip/host/config_chip.h b/chip/host/config_chip.h
deleted file mode 100644
index 84e254d8a0..0000000000
--- a/chip/host/config_chip.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/* Chip config header file */
-
-#ifndef __CROS_EC_CONFIG_CHIP_H
-#define __CROS_EC_CONFIG_CHIP_H
-
-/* Memory mapping */
-#if !defined(TEST_NVMEM) && !defined(TEST_CR50_FUZZ)
-#define CONFIG_FLASH_SIZE_BYTES 0x00020000
-#define CONFIG_FLASH_BANK_SIZE 0x1000
-#else
-#define CONFIG_FLASH_SIZE_BYTES (512 * 1024)
-#define CONFIG_FLASH_BANK_SIZE 0x800
-#endif
-
-extern char __host_flash[CONFIG_FLASH_SIZE_BYTES];
-
-#define CONFIG_PROGRAM_MEMORY_BASE ((uintptr_t)__host_flash)
-#define CONFIG_FLASH_ERASE_SIZE 0x0010 /* erase bank size */
-#define CONFIG_FLASH_WRITE_SIZE 0x0002 /* minimum write size */
-#define CONFIG_FLASH_WRITE_IDEAL_SIZE 0x0080 /* ideal write size */
-#define CONFIG_RAM_BASE 0x0 /* Not supported */
-#define CONFIG_RAM_SIZE 0x0 /* Not supported */
-
-#define CONFIG_FPU
-
-/* Memory-mapped internal flash */
-#define CONFIG_INTERNAL_STORAGE
-#define CONFIG_MAPPED_STORAGE
-
-/* Program is run directly from storage */
-#define CONFIG_MAPPED_STORAGE_BASE CONFIG_PROGRAM_MEMORY_BASE
-
-/* Compute the rest of the flash params from these */
-#include "config_std_internal_flash.h"
-
-/* Default task stack size */
-#define TASK_STACK_SIZE 512
-
-/* Interval between HOOK_TICK notifications */
-#define HOOK_TICK_INTERVAL_MS 250
-#define HOOK_TICK_INTERVAL (HOOK_TICK_INTERVAL_MS * MSEC)
-
-/* Do NOT use common panic code (designed to output information on the UART) */
-#undef CONFIG_COMMON_PANIC_OUTPUT
-/* Do NOT use common timer code which is designed for hardware counters. */
-#undef CONFIG_COMMON_TIMER
-
-#define GPIO_PIN(port, index) GPIO_##port, BIT(index)
-#define GPIO_PIN_MASK(p, m) .port = GPIO_##p, .mask = (m)
-
-#define I2C_PORT_COUNT 1
-
-#endif /* __CROS_EC_CONFIG_CHIP_H */
diff --git a/chip/host/flash.c b/chip/host/flash.c
deleted file mode 100644
index 75212737e0..0000000000
--- a/chip/host/flash.c
+++ /dev/null
@@ -1,177 +0,0 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/* Flash module for emulator */
-
-#include <stdio.h>
-
-#include "common.h"
-#include "config_chip.h"
-#include "flash.h"
-#include "persistence.h"
-#include "util.h"
-
-/* This needs to be aligned to the erase bank size for NVCTR. */
-__aligned(CONFIG_FLASH_ERASE_SIZE) char __host_flash[CONFIG_FLASH_SIZE_BYTES];
-uint8_t __host_flash_protect[PHYSICAL_BANKS];
-
-/* Override this function to make flash erase/write operation fail */
-test_mockable int flash_pre_op(void)
-{
- return EC_SUCCESS;
-}
-
-static int flash_check_protect(int offset, int size)
-{
- int first_bank = offset / CONFIG_FLASH_BANK_SIZE;
- int last_bank = DIV_ROUND_UP(offset + size,
- CONFIG_FLASH_BANK_SIZE);
- int bank;
-
- for (bank = first_bank; bank < last_bank; ++bank)
- if (__host_flash_protect[bank])
- return 1;
- return 0;
-}
-
-static void flash_set_persistent(void)
-{
- FILE *f = get_persistent_storage("flash", "wb");
- int sz;
-
- ASSERT(f != NULL);
-
- sz = fwrite(__host_flash, sizeof(__host_flash), 1, f);
- ASSERT(sz == 1);
-
- release_persistent_storage(f);
-}
-
-static void flash_get_persistent(void)
-{
- FILE *f = get_persistent_storage("flash", "rb");
- int sz;
-
- if (f == NULL) {
- fprintf(stderr,
- "No flash storage found. Initializing to 0xff.\n");
- memset(__host_flash, 0xff, sizeof(__host_flash));
- return;
- }
-
- sz = fread(__host_flash, sizeof(__host_flash), 1, f);
- ASSERT(sz == 1);
-
- release_persistent_storage(f);
-}
-
-int crec_flash_physical_write(int offset, int size, const char *data)
-{
- ASSERT((size & (CONFIG_FLASH_WRITE_SIZE - 1)) == 0);
-
- if (flash_pre_op() != EC_SUCCESS)
- return EC_ERROR_UNKNOWN;
-
- if (flash_check_protect(offset, size))
- return EC_ERROR_ACCESS_DENIED;
-
- memcpy(__host_flash + offset, data, size);
- flash_set_persistent();
-
- return EC_SUCCESS;
-}
-
-int crec_flash_physical_erase(int offset, int size)
-{
- ASSERT((size & (CONFIG_FLASH_ERASE_SIZE - 1)) == 0);
-
- if (flash_pre_op() != EC_SUCCESS)
- return EC_ERROR_UNKNOWN;
-
- if (flash_check_protect(offset, size))
- return EC_ERROR_ACCESS_DENIED;
-
- memset(__host_flash + offset, 0xff, size);
- flash_set_persistent();
-
- return EC_SUCCESS;
-}
-
-int crec_flash_physical_get_protect(int bank)
-{
- return __host_flash_protect[bank];
-}
-
-uint32_t crec_flash_physical_get_protect_flags(void)
-{
- int i;
- uint32_t flags = EC_FLASH_PROTECT_ALL_NOW;
-
- for (i = 0; i < PHYSICAL_BANKS; ++i)
- if (__host_flash_protect[i] == 0)
- flags = 0;
-
- return flags;
-}
-
-int crec_flash_physical_protect_now(int all)
-{
- memset(__host_flash_protect, 1, all ? PHYSICAL_BANKS : WP_BANK_COUNT);
- return EC_SUCCESS;
-}
-
-uint32_t crec_flash_physical_get_valid_flags(void)
-{
- return EC_FLASH_PROTECT_RO_AT_BOOT |
- EC_FLASH_PROTECT_RO_NOW |
- EC_FLASH_PROTECT_ALL_NOW;
-}
-
-uint32_t crec_flash_physical_get_writable_flags(uint32_t cur_flags)
-{
- uint32_t ret = 0;
-
- /* If RO protection isn't enabled, its at-boot state can be changed. */
- if (!(cur_flags & EC_FLASH_PROTECT_RO_NOW))
- ret |= EC_FLASH_PROTECT_RO_AT_BOOT;
-
- /*
- * If entire flash isn't protected at this boot, it can be enabled if
- * the WP GPIO is asserted.
- */
- if (!(cur_flags & EC_FLASH_PROTECT_ALL_NOW) &&
- (cur_flags & EC_FLASH_PROTECT_GPIO_ASSERTED))
- ret |= EC_FLASH_PROTECT_ALL_NOW;
-
- return ret;
-}
-
-int crec_flash_pre_init(void)
-{
- uint32_t prot_flags;
-
- flash_get_persistent();
-
- prot_flags = crec_flash_get_protect();
-
- if (prot_flags & EC_FLASH_PROTECT_GPIO_ASSERTED) {
- /*
- * Write protect is asserted. If we want RO flash protected,
- * protect it now.
- */
- if ((prot_flags & EC_FLASH_PROTECT_RO_AT_BOOT) &&
- !(prot_flags & EC_FLASH_PROTECT_RO_NOW)) {
- int rv = crec_flash_set_protect(EC_FLASH_PROTECT_RO_NOW,
- EC_FLASH_PROTECT_RO_NOW);
- if (rv)
- return rv;
-
- /* Re-read flags */
- prot_flags = crec_flash_get_protect();
- }
- }
-
- return EC_SUCCESS;
-}
diff --git a/chip/host/gpio.c b/chip/host/gpio.c
deleted file mode 100644
index 3c15205ad5..0000000000
--- a/chip/host/gpio.c
+++ /dev/null
@@ -1,98 +0,0 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/* GPIO module for emulator */
-
-#include "console.h"
-
-#include "common.h"
-#include "console.h"
-#include "gpio.h"
-#include "timer.h"
-#include "util.h"
-
-static int gpio_values[GPIO_COUNT];
-static int gpio_interrupt_enabled[GPIO_COUNT];
-
-/* Create a dictionary of names for debug console print */
-#define GPIO_INT(name, pin, flags, signal) #name,
-#define GPIO(name, pin, flags) #name,
-const char * gpio_names[GPIO_COUNT] = {
- #include "gpio.wrap"
-};
-#undef GPIO
-#undef GPIO_INT
-
-test_mockable void gpio_pre_init(void)
-{
- /* Nothing */
-}
-
-test_mockable int gpio_get_level(enum gpio_signal signal)
-{
- return gpio_values[signal];
-}
-
-static int gpio_interrupt_check(uint32_t flags, int old, int new)
-{
- if ((flags & GPIO_INT_F_RISING) && old == 0 && new == 1)
- return 1;
- if ((flags & GPIO_INT_F_FALLING) && old == 1 && new == 0)
- return 1;
- if ((flags & GPIO_INT_F_LOW) && new == 0)
- return 1;
- if ((flags & GPIO_INT_F_HIGH) && new == 1)
- return 1;
- return 0;
-}
-
-test_mockable void gpio_set_level(enum gpio_signal signal, int value)
-{
- const struct gpio_info *g = gpio_list + signal;
- const uint32_t flags = g->flags;
- const int old_value = gpio_values[signal];
- void (*ih)(enum gpio_signal signal);
-
- gpio_values[signal] = value;
-
- ccprints("Setting GPIO_%s to %d", gpio_names[signal], value);
-
- if (signal >= GPIO_IH_COUNT || !gpio_interrupt_enabled[signal])
- return;
-
- ih = gpio_irq_handlers[signal];
-
- if (gpio_interrupt_check(flags, old_value, value))
- ih(signal);
-}
-
-test_mockable int gpio_enable_interrupt(enum gpio_signal signal)
-{
- gpio_interrupt_enabled[signal] = 1;
- return EC_SUCCESS;
-}
-
-test_mockable int gpio_disable_interrupt(enum gpio_signal signal)
-{
- gpio_interrupt_enabled[signal] = 0;
- return EC_SUCCESS;
-}
-
-test_mockable int gpio_clear_pending_interrupt(enum gpio_signal signal)
-{
- return EC_SUCCESS;
-}
-
-test_mockable void gpio_set_flags_by_mask(uint32_t port, uint32_t mask,
- uint32_t flags)
-{
- /* Nothing */
-}
-
-test_mockable void gpio_set_alternate_function(uint32_t port, uint32_t mask,
- enum gpio_alternate_func func)
-{
- /* Nothing */
-}
diff --git a/chip/host/host_test.h b/chip/host/host_test.h
deleted file mode 100644
index e2bf5448c3..0000000000
--- a/chip/host/host_test.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/* Unit testing for Chrome EC */
-
-#ifndef __CROS_EC_HOST_TEST_H
-#define __CROS_EC_HOST_TEST_H
-
-/* Emulator exit codes */
-#define EXIT_CODE_HIBERNATE BIT(7)
-
-/* Get emulator executable name */
-const char *__get_prog_name(void);
-
-#endif /* __CROS_EC_HOST_TEST_H */
diff --git a/chip/host/i2c.c b/chip/host/i2c.c
deleted file mode 100644
index ba4ab376d2..0000000000
--- a/chip/host/i2c.c
+++ /dev/null
@@ -1,137 +0,0 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Mock I2C driver for unit test.
- */
-
-#include "hooks.h"
-#include "i2c.h"
-#include "i2c_private.h"
-#include "link_defs.h"
-#include "test_util.h"
-
-#define MAX_DETACHED_DEV_COUNT 3
-
-struct i2c_dev {
- int port;
- uint16_t addr_flags;
- int valid;
-};
-
-static struct i2c_dev detached_devs[MAX_DETACHED_DEV_COUNT];
-
-static void detach_init(void)
-{
- int i;
- for (i = 0; i < MAX_DETACHED_DEV_COUNT; ++i)
- detached_devs[i].valid = 0;
-}
-DECLARE_HOOK(HOOK_INIT, detach_init, HOOK_PRIO_FIRST);
-
-int test_detach_i2c(const int port, const uint16_t addr_flags)
-{
- int i;
-
- for (i = 0; i < MAX_DETACHED_DEV_COUNT; ++i)
- if (detached_devs[i].valid == 0)
- break;
-
- if (i == MAX_DETACHED_DEV_COUNT)
- return EC_ERROR_OVERFLOW;
-
- detached_devs[i].port = port;
- detached_devs[i].addr_flags = addr_flags;
- detached_devs[i].valid = 1;
-
- return EC_SUCCESS;
-}
-
-int test_attach_i2c(const int port, const uint16_t addr_flags)
-{
- int i;
-
- for (i = 0; i < MAX_DETACHED_DEV_COUNT; ++i)
- if (detached_devs[i].valid &&
- detached_devs[i].port == port &&
- detached_devs[i].addr_flags == addr_flags)
- break;
-
- if (i == MAX_DETACHED_DEV_COUNT)
- return EC_ERROR_INVAL;
-
- detached_devs[i].valid = 0;
- return EC_SUCCESS;
-}
-
-static int test_check_detached(const int port,
- const uint16_t addr_flags)
-{
- int i;
-
- for (i = 0; i < MAX_DETACHED_DEV_COUNT; ++i)
- if (detached_devs[i].valid &&
- detached_devs[i].port == port &&
- detached_devs[i].addr_flags == addr_flags)
- return 1;
- return 0;
-}
-
-int chip_i2c_xfer(const int port, const uint16_t addr_flags,
- const uint8_t *out, int out_size,
- uint8_t *in, int in_size, int flags)
-{
- const struct test_i2c_xfer *p;
- int rv;
-
- if (test_check_detached(port, addr_flags))
- return EC_ERROR_UNKNOWN;
- for (p = __test_i2c_xfer; p < __test_i2c_xfer_end; ++p) {
- rv = p->routine(port, addr_flags,
- out, out_size,
- in, in_size, flags);
- if (rv != EC_ERROR_INVAL)
- return rv;
- }
- return EC_ERROR_UNKNOWN;
-}
-
-int chip_i2c_set_freq(int port, enum i2c_freq freq)
-{
- return EC_ERROR_UNIMPLEMENTED;
-}
-
-enum i2c_freq chip_i2c_get_freq(int port)
-{
- switch (i2c_ports[port].kbps) {
- case 1000:
- return I2C_FREQ_1000KHZ;
- case 400:
- return I2C_FREQ_400KHZ;
- case 100:
- return I2C_FREQ_100KHZ;
- }
-
- /* fallback to 100k */
- return I2C_FREQ_100KHZ;
-}
-
-int i2c_raw_get_scl(int port)
-{
- return 1;
-}
-
-int i2c_raw_get_sda(int port)
-{
- return 1;
-}
-
-int i2c_get_line_levels(int port)
-{
- return 0;
-}
-
-void i2c_init(void)
-{
- /* We don't actually need to initialize anything here for host tests */
-}
diff --git a/chip/host/keyboard_raw.c b/chip/host/keyboard_raw.c
deleted file mode 100644
index 3e1f755f7f..0000000000
--- a/chip/host/keyboard_raw.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/* Raw keyboard I/O layer for emulator */
-
-#include "common.h"
-#include "keyboard_config.h"
-#include "keyboard_raw.h"
-#include "keyboard_scan.h"
-#include "task.h"
-#include "util.h"
-
-test_mockable void keyboard_raw_init(void)
-{
- /* Nothing */
-}
-
-test_mockable void keyboard_raw_task_start(void)
-{
- /* Nothing */
-}
-
-test_mockable void keyboard_raw_drive_column(int out)
-{
- /* Nothing */
-}
-
-test_mockable int keyboard_raw_read_rows(void)
-{
- /* Nothing pressed */
- return 0;
-}
-
-test_mockable void keyboard_raw_enable_interrupt(int enable)
-{
- /* Nothing */
-}
-
-test_mockable void keyboard_raw_gpio_interrupt(enum gpio_signal signal)
-{
-#ifdef HAS_TASK_KEYSCAN
- task_wake(TASK_ID_KEYSCAN);
-#endif
-}
diff --git a/chip/host/lpc.c b/chip/host/lpc.c
deleted file mode 100644
index dd64be9275..0000000000
--- a/chip/host/lpc.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/* LPC module for Chrome EC emulator */
-
-#include "lpc.h"
-
-test_mockable int lpc_keyboard_has_char(void)
-{
- return 0;
-}
-
-test_mockable int lpc_keyboard_input_pending(void)
-{
- return 0;
-}
-
-test_mockable void lpc_keyboard_put_char(uint8_t chr, int send_irq)
-{
- /* Do nothing */
-}
-
-test_mockable void lpc_keyboard_clear_buffer(void)
-{
- /* Do nothing */
-}
-
-test_mockable void lpc_keyboard_resume_irq(void)
-{
- /* Do nothing */
-}
diff --git a/chip/host/persistence.c b/chip/host/persistence.c
deleted file mode 100644
index 44d60f1bb8..0000000000
--- a/chip/host/persistence.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/* Persistence module for emulator */
-
-/* This provides storage that can be opened, closed and reopened by the
- * current process at will, whose naming even remains stable across multiple
- * invocations of the same executable, while providing a unique name for
- * each executable (as determined by path) that uses these routines.
- *
- * Useful when semi-permanent storage is required even with many
- * similar processes running in parallel (e.g. in a highly parallel
- * test suite run.
- *
- * mkstemp and friends don't provide these properties which is why we have
- * this homegrown implementation of something similar-yet-different.
- */
-
-#include <linux/limits.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "util.h"
-
-/* The longest path in a chroot seems to be about 280 characters (as of
- * April 2021) so define a cut-off instead of just hoping for the best:
- * If we were to run into a path that is nearly PATH_MAX bytes long,
- * file names could end up being reused inadvertedly because the various
- * snprintf calls would cut off the trailing characters, so the "tag" (and
- * maybe more) is gone even though it only exists for differentiation.
- *
- * Instead bail out if we encounter a path (to an executable using these
- * routines) that is longer than we expect.
- *
- * Round up for some spare room because why not?
- */
-static const int max_len = 300;
-
-/* This must be at least the size of the prefix added in get_storage_path */
-static const int max_prefix_len = 25;
-
-static void get_storage_path(char *out)
-{
- char buf[PATH_MAX];
- int sz;
- char *current;
-
- sz = readlink("/proc/self/exe", buf, PATH_MAX - 1);
- buf[sz] = '\0';
-
- ASSERT(sz <= max_len);
-
- /* replace / by underscores in the path to get the shared memory name */
- current = strchr(buf, '/');
- while (current) {
- *current = '_';
- current = strchr(current, '/');
- }
-
-
- sz = snprintf(out, PATH_MAX - 1, "/dev/shm/EC_persist_%.*s",
- max_len, buf);
- out[PATH_MAX - 1] = '\0';
-
- ASSERT(sz <= max_len + max_prefix_len);
-}
-
-FILE *get_persistent_storage(const char *tag, const char *mode)
-{
- char buf[PATH_MAX];
- char path[PATH_MAX];
-
- /* There's no longer tag in use right now, and there shouldn't be. */
- ASSERT(strlen(tag) < 32);
-
- /*
- * The persistent storage with tag 'foo' for test 'bar' would
- * be named 'bar_persist_foo'
- */
- get_storage_path(buf);
- snprintf(path, PATH_MAX - 1, "%.*s_%32s",
- max_len + max_prefix_len, buf, tag);
- path[PATH_MAX - 1] = '\0';
-
- return fopen(path, mode);
-}
-
-void release_persistent_storage(FILE *ps)
-{
- fclose(ps);
-}
-
-void remove_persistent_storage(const char *tag)
-{
- char buf[PATH_MAX];
- char path[PATH_MAX];
-
- /* There's no longer tag in use right now, and there shouldn't be. */
- ASSERT(strlen(tag) < 32);
-
- get_storage_path(buf);
- snprintf(path, PATH_MAX - 1, "%.*s_%32s",
- max_len + max_prefix_len, buf, tag);
- path[PATH_MAX - 1] = '\0';
-
- unlink(path);
-}
diff --git a/chip/host/persistence.h b/chip/host/persistence.h
deleted file mode 100644
index a473f8dfb0..0000000000
--- a/chip/host/persistence.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/* Persistence module for emulator */
-
-#ifndef __CROS_EC_PERSISTENCE_H
-#define __CROS_EC_PERSISTENCE_H
-
-#include <stdio.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-FILE *get_persistent_storage(const char *tag, const char *mode);
-
-void release_persistent_storage(FILE *ps);
-
-void remove_persistent_storage(const char *tag);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __CROS_EC_PERSISTENCE_H */
diff --git a/chip/host/reboot.c b/chip/host/reboot.c
deleted file mode 100644
index e932c5f11a..0000000000
--- a/chip/host/reboot.c
+++ /dev/null
@@ -1,32 +0,0 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/* Emulator self-reboot procedure */
-
-#include <string.h>
-#include <unistd.h>
-
-#include "console.h"
-#include "host_test.h"
-#include "reboot.h"
-#include "test_util.h"
-
-#ifdef TEST_FUZZ
-/* reboot breaks fuzzing, let's just not do it. */
-void emulator_reboot(void)
-{
- ccprints("Emulator would reboot here. Fuzzing: doing nothing.");
-}
-#else /* !TEST_FUZZ */
-noreturn
-void emulator_reboot(void)
-{
- char *argv[] = {strdup(__get_prog_name()), NULL};
- emulator_flush();
- execv(__get_prog_name(), argv);
- while (1)
- ;
-}
-#endif /* !TEST_FUZZ */
diff --git a/chip/host/reboot.h b/chip/host/reboot.h
deleted file mode 100644
index 1c1201f451..0000000000
--- a/chip/host/reboot.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/* Emulator self-reboot procedure */
-
-#ifndef __CROS_EC_REBOOT_H
-#define __CROS_EC_REBOOT_H
-
-#include <stdnoreturn.h>
-
-#ifndef TEST_FUZZ
-noreturn
-#endif
-void emulator_reboot(void);
-
-#endif
diff --git a/chip/host/registers.h b/chip/host/registers.h
deleted file mode 100644
index 7347ce04d3..0000000000
--- a/chip/host/registers.h
+++ /dev/null
@@ -1,11 +0,0 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/* Empty registers header for emulator */
-
-/*
- * There is no register for emulator, but this file exists to prevent
- * compilation failure if any file includes registers.h
- */
diff --git a/chip/host/spi_controller.c b/chip/host/spi_controller.c
deleted file mode 100644
index c7afea5d39..0000000000
--- a/chip/host/spi_controller.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Mock SPI Controller driver for unit test.
- */
-
-#include <stdint.h>
-
-#include "common.h"
-#include "gpio.h"
-
-#include "spi.h"
-
-test_mockable int spi_enable(const struct spi_device_t *spi_device, int enable)
-{
- return EC_SUCCESS;
-}
-
-test_mockable int spi_transaction(const struct spi_device_t *spi_device,
- const uint8_t *txdata, int txlen,
- uint8_t *rxdata, int rxlen)
-{
- return EC_SUCCESS;
-}
-
-test_mockable int spi_transaction_async(const struct spi_device_t *spi_device,
- const uint8_t *txdata, int txlen,
- uint8_t *rxdata, int rxlen)
-{
- return EC_SUCCESS;
-}
-
-test_mockable int spi_transaction_flush(const struct spi_device_t *spi_device)
-{
- return EC_SUCCESS;
-}
-
-test_mockable int spi_transaction_wait(const struct spi_device_t *spi_device)
-{
- return EC_SUCCESS;
-}
diff --git a/chip/host/system.c b/chip/host/system.c
deleted file mode 100644
index 60d765deab..0000000000
--- a/chip/host/system.c
+++ /dev/null
@@ -1,282 +0,0 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/* System module for emulator */
-
-#include "common.h"
-#include "ec_commands.h"
-#include "host_test.h"
-#include "panic.h"
-#include "persistence.h"
-#include "reboot.h"
-#include "system.h"
-#include "timer.h"
-#include "util.h"
-
-// Forward declaration from <stdlib.h> to avoid declaration conflicts.
-void exit(int);
-
-#define SHARED_MEM_SIZE 0x2000 /* bytes */
-#define RAM_DATA_SIZE (sizeof(struct panic_data) + 512) /* bytes */
-uint8_t __shared_mem_buf[SHARED_MEM_SIZE + RAM_DATA_SIZE];
-
-static char *__ram_data = __shared_mem_buf + SHARED_MEM_SIZE;
-
-static enum ec_image __running_copy;
-
-static void ramdata_set_persistent(void)
-{
- FILE *f = get_persistent_storage("ramdata", "wb");
- int sz;
-
- ASSERT(f != NULL);
-
- sz = fwrite(__ram_data, RAM_DATA_SIZE, 1, f);
- ASSERT(sz == 1);
-
- release_persistent_storage(f);
-}
-
-static void ramdata_get_persistent(void)
-{
- FILE *f = get_persistent_storage("ramdata", "rb");
-
- if ((f == NULL) || (fread(__ram_data, RAM_DATA_SIZE, 1, f) != 1)) {
- fprintf(stderr,
- "No RAM data found. Initializing to 0x00.\n");
- memset(__ram_data, 0, RAM_DATA_SIZE);
- return;
- }
-
- release_persistent_storage(f);
-
- /*
- * Assumes RAM data doesn't preserve across reboot except for sysjump.
- * Clear persistent data once it's read.
- */
- remove_persistent_storage("ramdata");
-}
-
-static void set_image_copy(uint32_t copy)
-{
- FILE *f = get_persistent_storage("image_copy", "wb");
-
- ASSERT(f != NULL);
- ASSERT(fwrite(&copy, sizeof(copy), 1, f) == 1);
-
- release_persistent_storage(f);
-}
-
-static uint32_t get_image_copy(void)
-{
- FILE *f = get_persistent_storage("image_copy", "rb");
- uint32_t ret;
-
- if ((f == NULL) || (fread(&ret, sizeof(ret), 1, f) != 1))
- return EC_IMAGE_UNKNOWN;
- release_persistent_storage(f);
- remove_persistent_storage("image_copy");
-
- return ret;
-}
-
-static void save_reset_flags(uint32_t flags)
-{
- FILE *f = get_persistent_storage("reset_flags", "wb");
-
- ASSERT(f != NULL);
- ASSERT(fwrite(&flags, sizeof(flags), 1, f) == 1);
-
- release_persistent_storage(f);
-}
-
-static uint32_t load_reset_flags(void)
-{
- FILE *f = get_persistent_storage("reset_flags", "rb");
- uint32_t ret;
-
- if ((f == NULL) || (fread(&ret, sizeof(ret), 1, f) != 1))
- return EC_RESET_FLAG_POWER_ON;
- release_persistent_storage(f);
- remove_persistent_storage("reset_flags");
-
- return ret;
-}
-
-static void save_time(timestamp_t t)
-{
- FILE *f = get_persistent_storage("time", "wb");
-
- ASSERT(f != NULL);
- ASSERT(fwrite(&t, sizeof(t), 1, f) == 1);
-
- release_persistent_storage(f);
-}
-
-static int load_time(timestamp_t *t)
-{
- FILE *f = get_persistent_storage("time", "rb");
-
- if ((f == NULL) || (fread(t, sizeof(*t), 1, f) != 1))
- return 0;
- release_persistent_storage(f);
- remove_persistent_storage("time");
-
- return 1;
-}
-
-test_mockable struct panic_data *panic_get_data(void)
-{
- return (struct panic_data *)
- (__ram_data + RAM_DATA_SIZE - sizeof(struct panic_data));
-}
-
-test_mockable uintptr_t get_panic_data_start()
-{
- return (uintptr_t)
- (__ram_data + RAM_DATA_SIZE - sizeof(struct panic_data));
-}
-
-test_mockable void system_reset(int flags)
-{
- uint32_t save_flags = 0;
- if (flags & SYSTEM_RESET_PRESERVE_FLAGS)
- save_flags = system_get_reset_flags() | EC_RESET_FLAG_PRESERVED;
- if (flags & SYSTEM_RESET_LEAVE_AP_OFF)
- save_flags |= EC_RESET_FLAG_AP_OFF;
- if (flags & SYSTEM_RESET_HARD)
- save_flags |= EC_RESET_FLAG_HARD;
- if (save_flags)
- save_reset_flags(save_flags);
- emulator_reboot();
-}
-
-test_mockable void system_hibernate(uint32_t seconds, uint32_t microseconds)
-{
- uint32_t i;
-
- if (board_hibernate)
- board_hibernate();
-
- save_reset_flags(EC_RESET_FLAG_HIBERNATE);
-
- if (!seconds && !microseconds)
- exit(EXIT_CODE_HIBERNATE);
-
- for (i = 0; i < seconds; ++i)
- udelay(SECOND);
- udelay(microseconds);
- emulator_reboot();
-}
-
-test_mockable int system_is_locked(void)
-{
- return 0;
-}
-
-#ifdef TEST_FUZZ
-/* When fuzzing, do not allow sysjumps. */
-int system_run_image_copy(enum ec_image copy)
-{
- ccprints("Emulator would sysjump here. Fuzzing: doing nothing.");
- return EC_ERROR_UNKNOWN;
-}
-#endif
-
-const char *system_get_chip_vendor(void)
-{
- return "chromeos";
-}
-
-const char *system_get_chip_name(void)
-{
- return "emu";
-}
-
-const char *system_get_chip_revision(void)
-{
- return "";
-}
-
-int system_get_bbram(enum system_bbram_idx idx, uint8_t *value)
-{
- return EC_ERROR_UNIMPLEMENTED;
-}
-
-int system_set_bbram(enum system_bbram_idx idx, uint8_t value)
-{
- return EC_ERROR_UNIMPLEMENTED;
-}
-
-enum ec_image system_get_image_copy(void)
-{
- return __running_copy;
-}
-
-int system_set_scratchpad(uint32_t value)
-{
- FILE *f = get_persistent_storage("scratchpad", "w");
-
- fprintf(f, "%u", value);
- release_persistent_storage(f);
-
- return EC_SUCCESS;
-}
-
-int system_get_scratchpad(uint32_t *value)
-{
- FILE *f = get_persistent_storage("scratchpad", "r");
- int success;
-
- if (f == NULL)
- return EC_ERROR_UNKNOWN;
-
- success = fscanf(f, "%u", value);
- release_persistent_storage(f);
-
- if (success)
- return EC_SUCCESS;
- else
- return EC_ERROR_UNKNOWN;
-}
-
-static void __jump_resetvec(void)
-{
- save_time(get_time());
- ramdata_set_persistent();
- emulator_reboot();
-}
-
-static void __ro_jump_resetvec(void)
-{
- set_image_copy(EC_IMAGE_RO);
- __jump_resetvec();
-}
-
-static void __rw_jump_resetvec(void)
-{
- set_image_copy(EC_IMAGE_RW);
- __jump_resetvec();
-}
-
-void system_pre_init(void)
-{
- timestamp_t t;
-
- if (load_time(&t))
- force_time(t);
-
- ramdata_get_persistent();
- __running_copy = get_image_copy();
- if (__running_copy == EC_IMAGE_UNKNOWN) {
- __running_copy = EC_IMAGE_RO;
- system_set_reset_flags(load_reset_flags());
- }
-
- *(uintptr_t *)(__host_flash + CONFIG_RO_MEM_OFF + 4) =
- (uintptr_t)__ro_jump_resetvec;
- *(uintptr_t *)(__host_flash + CONFIG_RW_MEM_OFF + 4) =
- (uintptr_t)__rw_jump_resetvec;
-}
diff --git a/chip/host/trng.c b/chip/host/trng.c
deleted file mode 100644
index 8407aa6ea1..0000000000
--- a/chip/host/trng.c
+++ /dev/null
@@ -1,40 +0,0 @@
-
-/* Copyright 2019 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Mock TRNG driver for unit test.
- *
- * Although a TRNG is designed to be anything but predictable,
- * this implementation strives to be as predictable and defined
- * as possible to allow reproducing unit tests and fuzzer crashes.
- */
-
-#ifndef TEST_BUILD
-#error "This fake trng driver must not be used in non-test builds."
-#endif
-
-#include <stdint.h>
-#include <stdlib.h> /* Only valid for host */
-
-#include "common.h"
-
-static unsigned int seed;
-
-test_mockable void init_trng(void)
-{
- seed = 0;
- srand(seed);
-}
-
-test_mockable void exit_trng(void)
-{
-}
-
-test_mockable void rand_bytes(void *buffer, size_t len)
-{
- uint8_t *b, *end;
-
- for (b = buffer, end = b+len; b != end; b++)
- *b = (uint8_t)rand_r(&seed);
-}
diff --git a/chip/host/uart.c b/chip/host/uart.c
deleted file mode 100644
index 578924612f..0000000000
--- a/chip/host/uart.c
+++ /dev/null
@@ -1,195 +0,0 @@
-/* Copyright 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/* UART driver for emulator */
-
-#include <pthread.h>
-#include <signal.h>
-#include <stdio.h>
-#include <termio.h>
-#include <unistd.h>
-
-#include "common.h"
-#include "queue.h"
-#include "task.h"
-#include "test_util.h"
-#include "uart.h"
-#include "util.h"
-
-static int stopped = 1;
-static int init_done;
-
-#ifndef TEST_FUZZ
-static pthread_t input_thread;
-#endif
-
-#define INPUT_BUFFER_SIZE 16
-static int char_available;
-
-static struct queue const cached_char = QUEUE_NULL(INPUT_BUFFER_SIZE, char);
-
-#define CONSOLE_CAPTURE_SIZE 2048
-static char capture_buf[CONSOLE_CAPTURE_SIZE];
-static int capture_size;
-static int capture_enabled;
-
-void test_capture_console(int enabled)
-{
- if (enabled == capture_enabled)
- return;
-
- if (enabled)
- capture_size = 0;
- else
- capture_buf[capture_size] = '\0';
-
- capture_enabled = enabled;
-}
-
-static void test_capture_char(char c)
-{
- if (capture_size == CONSOLE_CAPTURE_SIZE)
- return;
- capture_buf[capture_size++] = c;
-}
-
-
-const char *test_get_captured_console(void)
-{
- return (const char *)capture_buf;
-}
-
-static void uart_interrupt(void)
-{
- uart_process_input();
- uart_process_output();
-}
-
-int uart_init_done(void)
-{
- return init_done;
-}
-
-void uart_tx_start(void)
-{
- stopped = 0;
- task_trigger_test_interrupt(uart_interrupt);
-}
-
-void uart_tx_stop(void)
-{
- stopped = 1;
-}
-
-int uart_tx_stopped(void)
-{
- return stopped;
-}
-
-void uart_tx_flush(void)
-{
- /* Nothing */
-}
-
-int uart_tx_ready(void)
-{
- return 1;
-}
-
-int uart_rx_available(void)
-{
- return char_available;
-}
-
-void uart_write_char(char c)
-{
- if (capture_enabled)
- test_capture_char(c);
- printf("%c", c);
- fflush(stdout);
-}
-
-int uart_read_char(void)
-{
- char ret;
- ASSERT(in_interrupt_context());
- queue_remove_unit(&cached_char, &ret);
- --char_available;
- return ret;
-}
-
-void uart_inject_char(char *s, int sz)
-{
- int i;
- int num_char;
-
- for (i = 0; i < sz; i += INPUT_BUFFER_SIZE - 1) {
- num_char = MIN(INPUT_BUFFER_SIZE - 1, sz - i);
- if (queue_space(&cached_char) < num_char)
- return;
- queue_add_units(&cached_char, s + i, num_char);
- char_available = num_char;
- task_trigger_test_interrupt(uart_interrupt);
- }
-}
-
-/*
- * We do not really need console input when fuzzing, and having it enabled
- * breaks terminal when an error is detected.
- */
-#ifndef TEST_FUZZ
-static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t uart_monitor_initialized = PTHREAD_COND_INITIALIZER;
-
-void *uart_monitor_stdin(void *d)
-{
- struct termios org_settings, new_settings;
- char buf[INPUT_BUFFER_SIZE];
- int rv;
-
- pthread_mutex_lock(&mutex);
- tcgetattr(0, &org_settings);
- new_settings = org_settings;
- new_settings.c_lflag &= ~(ECHO | ICANON);
- new_settings.c_cc[VTIME] = 0;
- new_settings.c_cc[VMIN] = 1;
-
- printf("Console input initialized\n");
- /* Allow uart_init to proceed now that UART monitor is initialized. */
- pthread_cond_signal(&uart_monitor_initialized);
- pthread_mutex_unlock(&mutex);
- while (1) {
- tcsetattr(0, TCSANOW, &new_settings);
- rv = read(0, buf, INPUT_BUFFER_SIZE);
- if (queue_space(&cached_char) >= rv) {
- queue_add_units(&cached_char, buf, rv);
- char_available = rv;
- }
- tcsetattr(0, TCSANOW, &org_settings);
- /*
- * Trigger emulated interrupt to process input. Keyboard
- * input while interrupt handler runs is queued by the
- * system.
- */
- task_trigger_test_interrupt(uart_interrupt);
- }
-
- return 0;
-}
-#endif /* !TEST_FUZZ */
-
-void uart_init(void)
-{
-#ifndef TEST_FUZZ
- /* Create UART monitor thread and wait for it to initialize. */
- pthread_mutex_lock(&mutex);
- pthread_create(&input_thread, NULL, uart_monitor_stdin, NULL);
- pthread_cond_wait(&uart_monitor_initialized, &mutex);
- pthread_mutex_unlock(&mutex);
-#endif
-
- stopped = 1; /* Not transmitting yet */
- init_done = 1;
-}
diff --git a/chip/host/usb_pd_phy.c b/chip/host/usb_pd_phy.c
deleted file mode 100644
index ba81b986ad..0000000000
--- a/chip/host/usb_pd_phy.c
+++ /dev/null
@@ -1,370 +0,0 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "common.h"
-#include "console.h"
-#include "crc.h"
-#include "task.h"
-#include "usb_pd.h"
-#include "usb_pd_config.h"
-#include "util.h"
-
-#define PREAMBLE_OFFSET 60 /* Any number should do */
-
-/*
- * Maximum size of a Power Delivery packet (in bits on the wire) :
- * 16-bit header + 0..7 32-bit data objects (+ 4b5b encoding)
- * 64-bit preamble + SOP (4x 5b) + message in 4b5b + 32-bit CRC + EOP (1x 5b)
- * = 64 + 4*5 + 16 * 5/4 + 7 * 32 * 5/4 + 32 * 5/4 + 5
- */
-#define PD_BIT_LEN 429
-
-static struct pd_physical {
- int hw_init_done;
-
- uint8_t bits[PD_BIT_LEN];
- int total;
- int has_preamble;
- int rx_started;
- int rx_monitoring;
-
- int preamble_written;
- int has_msg;
- int last_edge_written;
- uint8_t out_msg[PD_BIT_LEN / 5];
- int verified_idx;
-} pd_phy[CONFIG_USB_PD_PORT_MAX_COUNT];
-
-static const uint16_t enc4b5b[] = {
- 0x1E, 0x09, 0x14, 0x15, 0x0A, 0x0B, 0x0E, 0x0F, 0x12, 0x13, 0x16,
- 0x17, 0x1A, 0x1B, 0x1C, 0x1D};
-
-/* Test utilities */
-static void pd_test_reset_phy(int port)
-{
- int i;
- int enc_len = PD_BIT_LEN / 5;
-
- for (i = 0; i < PD_BIT_LEN; i++)
- pd_phy[port].bits[i] = 0;
-
- for (i = 0; i < enc_len; i++)
- pd_phy[port].out_msg[i] = 0;
-
- pd_phy[port].total = 0;
- pd_phy[port].has_preamble = 0;
- pd_phy[port].rx_started = 0;
- pd_phy[port].rx_monitoring = 0;
- pd_phy[port].preamble_written = 0;
- pd_phy[port].has_msg = 0;
- pd_phy[port].last_edge_written = 0;
- pd_phy[port].verified_idx = 0;
-}
-
-void pd_test_rx_set_preamble(int port, int has_preamble)
-{
- pd_phy[port].total = 0;
- pd_phy[port].has_preamble = has_preamble;
-}
-
-void pd_test_rx_msg_append_bits(int port, uint32_t bits, int nb)
-{
- int i;
-
- for (i = 0; i < nb; ++i) {
- pd_phy[port].bits[pd_phy[port].total++] = bits & 1;
- bits >>= 1;
- }
-}
-
-void pd_test_rx_msg_append_kcode(int port, uint8_t kcode)
-{
- pd_test_rx_msg_append_bits(port, kcode, 5);
-}
-
-void pd_test_rx_msg_append_sop(int port)
-{
- pd_test_rx_msg_append_kcode(port, PD_SYNC1);
- pd_test_rx_msg_append_kcode(port, PD_SYNC1);
- pd_test_rx_msg_append_kcode(port, PD_SYNC1);
- pd_test_rx_msg_append_kcode(port, PD_SYNC2);
-}
-
-void pd_test_rx_msg_append_sop_prime(int port)
-{
- pd_test_rx_msg_append_kcode(port, PD_SYNC1);
- pd_test_rx_msg_append_kcode(port, PD_SYNC1);
- pd_test_rx_msg_append_kcode(port, PD_SYNC3);
- pd_test_rx_msg_append_kcode(port, PD_SYNC3);
-}
-
-void pd_test_rx_msg_append_sop_prime_prime(int port)
-{
- pd_test_rx_msg_append_kcode(port, PD_SYNC1);
- pd_test_rx_msg_append_kcode(port, PD_SYNC3);
- pd_test_rx_msg_append_kcode(port, PD_SYNC1);
- pd_test_rx_msg_append_kcode(port, PD_SYNC3);
-}
-
-void pd_test_rx_msg_append_eop(int port)
-{
- pd_test_rx_msg_append_kcode(port, PD_EOP);
-}
-
-void pd_test_rx_msg_append_last_edge(int port)
-{
- /* end with 1, 1, 0 similar to pd_write_last_edge() */
- pd_test_rx_msg_append_bits(port, 3, 6);
-}
-
-void pd_test_rx_msg_append_4b(int port, uint8_t val)
-{
- pd_test_rx_msg_append_bits(port, enc4b5b[val & 0xF], 5);
-}
-
-void pd_test_rx_msg_append_short(int port, uint16_t val)
-{
- pd_test_rx_msg_append_4b(port, (val >> 0) & 0xF);
- pd_test_rx_msg_append_4b(port, (val >> 4) & 0xF);
- pd_test_rx_msg_append_4b(port, (val >> 8) & 0xF);
- pd_test_rx_msg_append_4b(port, (val >> 12) & 0xF);
-}
-
-void pd_test_rx_msg_append_word(int port, uint32_t val)
-{
- pd_test_rx_msg_append_short(port, val & 0xFFFF);
- pd_test_rx_msg_append_short(port, val >> 16);
-}
-
-void pd_simulate_rx(int port)
-{
- if (!pd_phy[port].rx_monitoring)
- return;
-
- pd_phy[port].rx_started = 1;
- pd_rx_disable_monitoring(port);
- pd_rx_event(port);
-}
-
-static int pd_test_tx_msg_verify(int port, uint8_t raw)
-{
- int verified_idx = pd_phy[port].verified_idx++;
- return pd_phy[port].out_msg[verified_idx] == raw;
-}
-
-int pd_test_tx_msg_verify_kcode(int port, uint8_t kcode)
-{
- return pd_test_tx_msg_verify(port, kcode);
-}
-
-int pd_test_tx_msg_verify_sop(int port)
-{
- crc32_init();
- return pd_test_tx_msg_verify_kcode(port, PD_SYNC1) &&
- pd_test_tx_msg_verify_kcode(port, PD_SYNC1) &&
- pd_test_tx_msg_verify_kcode(port, PD_SYNC1) &&
- pd_test_tx_msg_verify_kcode(port, PD_SYNC2);
-}
-
-int pd_test_tx_msg_verify_sop_prime(int port)
-{
- crc32_init();
- return pd_test_tx_msg_verify_kcode(port, PD_SYNC1) &&
- pd_test_tx_msg_verify_kcode(port, PD_SYNC1) &&
- pd_test_tx_msg_verify_kcode(port, PD_SYNC3) &&
- pd_test_tx_msg_verify_kcode(port, PD_SYNC3);
-}
-
-int pd_test_tx_msg_verify_sop_prime_prime(int port)
-{
- crc32_init();
- return pd_test_tx_msg_verify_kcode(port, PD_SYNC1) &&
- pd_test_tx_msg_verify_kcode(port, PD_SYNC3) &&
- pd_test_tx_msg_verify_kcode(port, PD_SYNC1) &&
- pd_test_tx_msg_verify_kcode(port, PD_SYNC3);
-}
-
-int pd_test_tx_msg_verify_eop(int port)
-{
- return pd_test_tx_msg_verify_kcode(port, PD_EOP);
-}
-
-int pd_test_tx_msg_verify_4b5b(int port, uint8_t b4)
-{
- return pd_test_tx_msg_verify(port, enc4b5b[b4]);
-}
-
-int pd_test_tx_msg_verify_short(int port, uint16_t val)
-{
- crc32_hash16(val);
- return pd_test_tx_msg_verify_4b5b(port, (val >> 0) & 0xF) &&
- pd_test_tx_msg_verify_4b5b(port, (val >> 4) & 0xF) &&
- pd_test_tx_msg_verify_4b5b(port, (val >> 8) & 0xF) &&
- pd_test_tx_msg_verify_4b5b(port, (val >> 12) & 0xF);
-}
-
-int pd_test_tx_msg_verify_word(int port, uint32_t val)
-{
- return pd_test_tx_msg_verify_short(port, val & 0xFFFF) &&
- pd_test_tx_msg_verify_short(port, val >> 16);
-}
-
-int pd_test_tx_msg_verify_crc(int port)
-{
- return pd_test_tx_msg_verify_word(port, crc32_result());
-}
-
-
-/* Mock functions */
-
-void pd_init_dequeue(int port)
-{
-}
-
-int pd_dequeue_bits(int port, int off, int len, uint32_t *val)
-{
- int i;
-
- /* Rx must have started to receive message */
- ASSERT(pd_phy[port].rx_started);
-
- if (pd_phy[port].total <= off + len - PREAMBLE_OFFSET)
- return -1;
- *val = 0;
- for (i = 0; i < len; ++i)
- *val |= pd_phy[port].bits[off + i - PREAMBLE_OFFSET] << i;
- return off + len;
-}
-
-int pd_find_preamble(int port)
-{
- return pd_phy[port].has_preamble ? PREAMBLE_OFFSET : -1;
-}
-
-int pd_write_preamble(int port)
-{
- ASSERT(pd_phy[port].preamble_written == 0);
- pd_phy[port].preamble_written = 1;
- ASSERT(pd_phy[port].has_msg == 0);
- return 0;
-}
-
-static uint8_t decode_bmc(uint32_t val10)
-{
- uint8_t ret = 0;
- int i;
-
- for (i = 0; i < 5; ++i)
- if (!!(val10 & (1 << (2 * i))) !=
- !!(val10 & (1 << (2 * i + 1))))
- ret |= BIT(i);
- return ret;
-}
-
-int pd_write_sym(int port, int bit_off, uint32_t val10)
-{
- pd_phy[port].out_msg[bit_off] = decode_bmc(val10);
- pd_phy[port].has_msg = 1;
- return bit_off + 1;
-}
-
-int pd_write_last_edge(int port, int bit_off)
-{
- pd_phy[port].last_edge_written = 1;
- return bit_off;
-}
-
-void pd_dump_packet(int port, const char *msg)
-{
- /* Not implemented */
-}
-
-void pd_tx_set_circular_mode(int port)
-{
- /* Not implemented */
-}
-
-void pd_tx_clear_circular_mode(int port)
-{
- /* Not implemented */
-}
-
-int pd_start_tx(int port, int polarity, int bit_len)
-{
- ASSERT(pd_phy[port].hw_init_done);
- pd_phy[port].has_msg = 0;
- pd_phy[port].preamble_written = 0;
- pd_phy[port].verified_idx = 0;
- pd_phy[port].total = 0;
-
- /*
- * Hand over to test runner. The test runner must wake us after
- * processing the packet.
- */
- task_wake(TASK_ID_TEST_RUNNER);
- task_wait_event(-1);
-
- return bit_len;
-}
-
-void pd_tx_done(int port, int polarity)
-{
- pd_test_reset_phy(port);
-}
-
-void pd_rx_start(int port)
-{
- ASSERT(pd_phy[port].hw_init_done);
-
- task_wake(TASK_ID_TEST_RUNNER);
- task_wait_event(-1);
-
- pd_phy[port].rx_started = 1;
-}
-
-void pd_rx_complete(int port)
-{
- ASSERT(pd_phy[port].hw_init_done);
- pd_test_reset_phy(port);
-}
-
-int pd_rx_started(int port)
-{
- return pd_phy[port].rx_started;
-}
-
-void pd_rx_enable_monitoring(int port)
-{
- ASSERT(pd_phy[port].hw_init_done);
- pd_phy[port].rx_monitoring = 1;
-}
-
-void pd_rx_disable_monitoring(int port)
-{
- /*
- * We disabled RX monitoring in TCPMv1 in set_state when
- * transitioning from suspended to disconnected, but we only
- * reinitialize after we have fully transitioned to disconnected. Don't
- * assert that hw_init_done here since we have "valid" code that
- * requires hw_init_done to be false when a port is suspended.
- */
- pd_phy[port].rx_monitoring = 0;
-}
-
-void pd_hw_release(int port)
-{
- pd_phy[port].hw_init_done = 0;
-}
-
-void pd_hw_init(int port, enum pd_power_role role)
-{
- pd_config_init(port, role);
- pd_phy[port].hw_init_done = 1;
-}
-
-void pd_set_clock(int port, int freq)
-{
- /* Not implemented */
-}