diff options
Diffstat (limited to 'roms/u-boot/arch/sandbox/include/asm')
41 files changed, 2584 insertions, 0 deletions
diff --git a/roms/u-boot/arch/sandbox/include/asm/acpi_table.h b/roms/u-boot/arch/sandbox/include/asm/acpi_table.h new file mode 100644 index 000000000..921c7f420 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/acpi_table.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2019 Google LLC + */ + +#ifndef __ASM_ACPI_TABLE_H__ +#define __ASM_ACPI_TABLE_H__ + +#endif /* __ASM_ACPI_TABLE_H__ */ diff --git a/roms/u-boot/arch/sandbox/include/asm/axi.h b/roms/u-boot/arch/sandbox/include/asm/axi.h new file mode 100644 index 000000000..d483f7b65 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/axi.h @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * (C) Copyright 2018 + * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc + */ + +#ifndef __asm_axi_h +#define __asm_axi_h + +#define axi_emul_get_ops(dev) ((struct axi_emul_ops *)(dev)->driver->ops) + +/** + * axi_sandbox_get_emul() - Retrieve a pointer to a AXI emulation device + * @bus: The AXI bus from which to retrieve a emulation device + * @address: The address of a transfer that should be handled by a emulation + * device + * @length: The data width of a transfer that should be handled by a emulation + * device + * @emulp: Pointer to a buffer receiving the emulation device that handles + * the transfer specified by the address and length parameters + * + * To test the AXI uclass, we implement a simple AXI emulation device, which is + * a virtual device on a AXI bus that exposes a simple storage interface: When + * reading and writing from the device, the addresses are translated to offsets + * within the device's storage. For write accesses the data is written to the + * specified storage offset, and for read accesses the data is read from the + * specified storage offset. + * + * A DTS entry might look like this: + * + * axi: axi@0 { + * compatible = "sandbox,axi"; + * #address-cells = <0x1>; + * #size-cells = <0x1>; + * store@0 { + * compatible = "sandbox,sandbox_store"; + * reg = <0x0 0x400>; + * }; + * }; + * + * This function may then be used to retrieve the pointer to the sandbox_store + * emulation device given the AXI bus device, and the data (address, data + * width) of a AXI transfer which should be handled by a emulation device. + * + * Return: 0 of OK, -ENODEV if no device capable of handling the specified + * transfer exists or the device could not be retrieved + */ +int axi_sandbox_get_emul(struct udevice *bus, ulong address, uint length, + struct udevice **emulp); +/** + * axi_get_store() - Get address of internal storage of a emulated AXI device + * @dev: Emulated AXI device to get the pointer of the internal storage + * for. + * @storep: Pointer to the internal storage of the emulated AXI device. + * + * To preset or read back the contents internal storage of the emulated AXI + * device, this function returns the pointer to the storage. Changes to the + * contents of the storage are reflected when using the AXI read/write API + * methods, and vice versa, so by using this method expected read data can be + * set up in advance, and written data can be checked in unit tests. + * + * Return: 0 if OK, -ve on error. + */ +int axi_get_store(struct udevice *dev, u8 **storep); + +#endif /* __asm_axi_h */ diff --git a/roms/u-boot/arch/sandbox/include/asm/bitops.h b/roms/u-boot/arch/sandbox/include/asm/bitops.h new file mode 100644 index 000000000..f27d5e98c --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/bitops.h @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * + * Modified from Linux arch/arm/include/asm/bitops.h + * + * Copyright 1995, Russell King. + * Various bits and pieces copyrights include: + * Linus Torvalds (test_bit). + * + * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1). + * + * Please note that the code in this file should never be included + * from user space. Many of these are not implemented in assembler + * since they would be too costly. Also, they require priviledged + * instructions (which are not available from user mode) to ensure + * that they are atomic. + */ + +#ifndef __ASM_SANDBOX_BITOPS_H +#define __ASM_SANDBOX_BITOPS_H + +#include <linux/compiler.h> +#include <asm/system.h> +#include <asm-generic/bitops/fls.h> +#include <asm-generic/bitops/__fls.h> +#include <asm-generic/bitops/fls64.h> +#include <asm-generic/bitops/__ffs.h> + +#ifdef __KERNEL__ + +#define smp_mb__before_clear_bit() do { } while (0) +#define smp_mb__after_clear_bit() do { } while (0) + +/* + * Function prototypes to keep gcc -Wall happy. + */ +extern void set_bit(int nr, void *addr); + +extern void clear_bit(int nr, void *addr); + +extern void change_bit(int nr, void *addr); + +static inline void __change_bit(int nr, void *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + + *p ^= mask; +} + +static inline int __test_and_set_bit(int nr, void *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + unsigned long old = *p; + + *p = old | mask; + return (old & mask) != 0; +} + +static inline int test_and_set_bit(int nr, void *addr) +{ + unsigned long __always_unused flags; + int out; + + local_irq_save(flags); + out = __test_and_set_bit(nr, addr); + local_irq_restore(flags); + + return out; +} + +static inline int __test_and_clear_bit(int nr, void *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + unsigned long old = *p; + + *p = old & ~mask; + return (old & mask) != 0; +} + +static inline int test_and_clear_bit(int nr, void *addr) +{ + unsigned long __always_unused flags; + int out; + + local_irq_save(flags); + out = __test_and_clear_bit(nr, addr); + local_irq_restore(flags); + + return out; +} + +extern int test_and_change_bit(int nr, void *addr); + +static inline int __test_and_change_bit(int nr, void *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + unsigned long old = *p; + + *p = old ^ mask; + return (old & mask) != 0; +} + +extern int find_first_zero_bit(void *addr, unsigned size); +extern int find_next_zero_bit(void *addr, int size, int offset); + +/* + * This routine doesn't need to be atomic. + */ +static inline int test_bit(int nr, const void *addr) +{ + return ((unsigned char *) addr)[nr >> 3] & (1U << (nr & 7)); +} + +/* + * ffz = Find First Zero in word. Undefined if no zero exists, + * so code should check against ~0UL first.. + */ +static inline unsigned long ffz(unsigned long word) +{ + int k; + + word = ~word; + k = 31; + if (word & 0x0000ffff) { + k -= 16; word <<= 16; + } + if (word & 0x00ff0000) { + k -= 8; word <<= 8; + } + if (word & 0x0f000000) { + k -= 4; word <<= 4; + } + if (word & 0x30000000) { + k -= 2; word <<= 2; + } + if (word & 0x40000000) + k -= 1; + return k; +} + +/* + * hweightN: returns the hamming weight (i.e. the number + * of bits set) of a N-bit word + */ + +#define hweight32(x) generic_hweight32(x) +#define hweight16(x) generic_hweight16(x) +#define hweight8(x) generic_hweight8(x) + +#define ext2_set_bit test_and_set_bit +#define ext2_clear_bit test_and_clear_bit +#define ext2_test_bit test_bit +#define ext2_find_first_zero_bit find_first_zero_bit +#define ext2_find_next_zero_bit find_next_zero_bit + +/* Bitmap functions for the minix filesystem. */ +#define minix_test_and_set_bit(nr, addr) test_and_set_bit(nr, addr) +#define minix_set_bit(nr, addr) set_bit(nr, addr) +#define minix_test_and_clear_bit(nr, addr) test_and_clear_bit(nr, addr) +#define minix_test_bit(nr, addr) test_bit(nr, addr) +#define minix_find_first_zero_bit(addr, size) find_first_zero_bit(addr, size) + +#endif /* __KERNEL__ */ + +#endif /* _ARM_BITOPS_H */ diff --git a/roms/u-boot/arch/sandbox/include/asm/byteorder.h b/roms/u-boot/arch/sandbox/include/asm/byteorder.h new file mode 100644 index 000000000..70b4c078a --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/byteorder.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2011 The Chromium OS Authors. + */ + +#ifndef __ASM_SANDBOX_BYTEORDER_H +#define __ASM_SANDBOX_BYTEORDER_H + + +#include <asm/types.h> + +#if !defined(__STRICT_ANSI__) || defined(__KERNEL__) +# define __BYTEORDER_HAS_U64__ +# define __SWAB_64_THRU_32__ +#endif + +#ifdef CONFIG_SANDBOX_BIG_ENDIAN +#include <linux/byteorder/big_endian.h> +#else +#include <linux/byteorder/little_endian.h> +#endif + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/cache.h b/roms/u-boot/arch/sandbox/include/asm/cache.h new file mode 100644 index 000000000..9348a13e7 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/cache.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2011 The Chromium OS Authors. + */ + +#ifndef __SANDBOX_CACHE_H__ +#define __SANDBOX_CACHE_H__ + +/* + * For native compilation of the sandbox we should still align + * the contents of stack buffers to something reasonable. The + * GCC macro __BIGGEST_ALIGNMENT__ is defined to be the maximum + * required alignment for any basic type. This seems reasonable. + * This is however GCC specific so if we don't have that available + * assume that 16 is large enough. + */ +#ifdef __BIGGEST_ALIGNMENT__ +#define ARCH_DMA_MINALIGN __BIGGEST_ALIGNMENT__ +#else +#define ARCH_DMA_MINALIGN 16 +#endif +#define CONFIG_SYS_CACHELINE_SIZE ARCH_DMA_MINALIGN + +#endif /* __SANDBOX_CACHE_H__ */ diff --git a/roms/u-boot/arch/sandbox/include/asm/clk.h b/roms/u-boot/arch/sandbox/include/asm/clk.h new file mode 100644 index 000000000..df7156fe3 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/clk.h @@ -0,0 +1,217 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2016, NVIDIA CORPORATION. + */ + +#ifndef __SANDBOX_CLK_H +#define __SANDBOX_CLK_H + +#include <common.h> +#include <clk.h> +#include <dt-structs.h> +#include <linux/clk-provider.h> + +struct udevice; + +/** + * enum sandbox_clk_id - Identity of clocks implemented by the sandbox clock + * provider. + * + * These IDs are within/relative-to the clock provider. + */ +enum sandbox_clk_id { + SANDBOX_CLK_ID_SPI, + SANDBOX_CLK_ID_I2C, + SANDBOX_CLK_ID_UART1, + SANDBOX_CLK_ID_UART2, + SANDBOX_CLK_ID_BUS, + + SANDBOX_CLK_ID_COUNT, +}; + +/** + * enum sandbox_clk_test_id - Identity of the clocks consumed by the sandbox + * clock test device. + * + * These are the IDs the clock consumer knows the clocks as. + */ +enum sandbox_clk_test_id { + SANDBOX_CLK_TEST_ID_FIXED, + SANDBOX_CLK_TEST_ID_SPI, + SANDBOX_CLK_TEST_ID_I2C, + SANDBOX_CLK_TEST_ID_DEVM1, + SANDBOX_CLK_TEST_ID_DEVM2, + SANDBOX_CLK_TEST_ID_DEVM_NULL, + + SANDBOX_CLK_TEST_ID_COUNT, +}; + +#define SANDBOX_CLK_TEST_NON_DEVM_COUNT SANDBOX_CLK_TEST_ID_DEVM1 + +struct sandbox_clk_priv { + bool probed; + ulong rate[SANDBOX_CLK_ID_COUNT]; + bool enabled[SANDBOX_CLK_ID_COUNT]; + bool requested[SANDBOX_CLK_ID_COUNT]; +}; + +struct sandbox_clk_test { + struct clk clks[SANDBOX_CLK_TEST_NON_DEVM_COUNT]; + struct clk *clkps[SANDBOX_CLK_TEST_ID_COUNT]; + struct clk_bulk bulk; +}; + +/* Platform data for the sandbox fixed-rate clock driver */ +struct sandbox_clk_fixed_rate_plat { +#if CONFIG_IS_ENABLED(OF_PLATDATA) + struct dtd_sandbox_fixed_clock dtplat; +#endif + struct clk_fixed_rate fixed; +}; + +/** + * sandbox_clk_query_rate - Query the current rate of a sandbox clock. + * + * @dev: The sandbox clock provider device. + * @id: The clock to query. + * @return: The rate of the clock. + */ +ulong sandbox_clk_query_rate(struct udevice *dev, int id); +/** + * sandbox_clk_query_enable - Query the enable state of a sandbox clock. + * + * @dev: The sandbox clock provider device. + * @id: The clock to query. + * @return: The rate of the clock. + */ +int sandbox_clk_query_enable(struct udevice *dev, int id); +/** + * sandbox_clk_query_requested - Query the requested state of a sandbox clock. + * + * @dev: The sandbox clock provider device. + * @id: The clock to query. + * @return: The rate of the clock. + */ +int sandbox_clk_query_requested(struct udevice *dev, int id); + +/** + * sandbox_clk_test_get - Ask the sandbox clock test device to request its + * clocks. + * + * @dev: The sandbox clock test (client) device. + * @return: 0 if OK, or a negative error code. + */ +int sandbox_clk_test_get(struct udevice *dev); + +/** + * sandbox_clk_test_devm_get - Ask the sandbox clock test device to request its + * clocks using the managed API. + * + * @dev: The sandbox clock test (client) device. + * @return: 0 if OK, or a negative error code. + */ +int sandbox_clk_test_devm_get(struct udevice *dev); + +/** + * sandbox_clk_test_get_bulk - Ask the sandbox clock test device to request its + * clocks with the bulk clk API. + * + * @dev: The sandbox clock test (client) device. + * @return: 0 if OK, or a negative error code. + */ +int sandbox_clk_test_get_bulk(struct udevice *dev); +/** + * sandbox_clk_test_get_rate - Ask the sandbox clock test device to query a + * clock's rate. + * + * @dev: The sandbox clock test (client) device. + * @id: The test device's clock ID to query. + * @return: The rate of the clock. + */ +ulong sandbox_clk_test_get_rate(struct udevice *dev, int id); +/** + * sandbox_clk_test_round_rate - Ask the sandbox clock test device to round a + * clock's rate. + * + * @dev: The sandbox clock test (client) device. + * @id: The test device's clock ID to configure. + * @return: The rounded rate of the clock. + */ +ulong sandbox_clk_test_round_rate(struct udevice *dev, int id, ulong rate); +/** + * sandbox_clk_test_set_rate - Ask the sandbox clock test device to set a + * clock's rate. + * + * @dev: The sandbox clock test (client) device. + * @id: The test device's clock ID to configure. + * @return: The new rate of the clock. + */ +ulong sandbox_clk_test_set_rate(struct udevice *dev, int id, ulong rate); +/** + * sandbox_clk_test_enable - Ask the sandbox clock test device to enable a + * clock. + * + * @dev: The sandbox clock test (client) device. + * @id: The test device's clock ID to configure. + * @return: 0 if OK, or a negative error code. + */ +int sandbox_clk_test_enable(struct udevice *dev, int id); +/** + * sandbox_clk_test_enable_bulk - Ask the sandbox clock test device to enable + * all clocks in it's clock bulk struct. + * + * @dev: The sandbox clock test (client) device. + * @return: 0 if OK, or a negative error code. + */ +int sandbox_clk_test_enable_bulk(struct udevice *dev); +/** + * sandbox_clk_test_disable - Ask the sandbox clock test device to disable a + * clock. + * + * @dev: The sandbox clock test (client) device. + * @id: The test device's clock ID to configure. + * @return: 0 if OK, or a negative error code. + */ +int sandbox_clk_test_disable(struct udevice *dev, int id); +/** + * sandbox_clk_test_disable_bulk - Ask the sandbox clock test device to disable + * all clocks in it's clock bulk struct. + * + * @dev: The sandbox clock test (client) device. + * @return: 0 if OK, or a negative error code. + */ +int sandbox_clk_test_disable_bulk(struct udevice *dev); +/** + * sandbox_clk_test_free - Ask the sandbox clock test device to free its + * clocks. + * + * @dev: The sandbox clock test (client) device. + * @return: 0 if OK, or a negative error code. + */ +int sandbox_clk_test_free(struct udevice *dev); +/** + * sandbox_clk_test_release_bulk - Ask the sandbox clock test device to release + * all clocks in it's clock bulk struct. + * + * @dev: The sandbox clock test (client) device. + * @return: 0 if OK, or a negative error code. + */ +int sandbox_clk_test_release_bulk(struct udevice *dev); +/** + * sandbox_clk_test_valid - Ask the sandbox clock test device to check its + * clocks are valid. + * + * @dev: The sandbox clock test (client) device. + * @return: 0 if OK, or a negative error code. + */ +int sandbox_clk_test_valid(struct udevice *dev); +/** + * sandbox_clk_test_valid - Ask the sandbox clock test device to check its + * clocks are valid. + * + * @dev: The sandbox clock test (client) device. + * @return: 0 if OK, or a negative error code. + */ +struct clk *sandbox_clk_test_get_devm_clk(struct udevice *dev, int id); + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/config.h b/roms/u-boot/arch/sandbox/include/asm/config.h new file mode 100644 index 000000000..50215b35d --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/config.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2011 The Chromium OS Authors. + */ + +#ifndef _ASM_CONFIG_H_ +#define _ASM_CONFIG_H_ + +#define CONFIG_SANDBOX_ARCH + +/* Used by drivers/spi/sandbox_spi.c and arch/sandbox/include/asm/state.h */ +#ifndef CONFIG_SANDBOX_SPI_MAX_BUS +#define CONFIG_SANDBOX_SPI_MAX_BUS 1 +#endif +#ifndef CONFIG_SANDBOX_SPI_MAX_CS +#define CONFIG_SANDBOX_SPI_MAX_CS 10 +#endif + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/cpu.h b/roms/u-boot/arch/sandbox/include/asm/cpu.h new file mode 100644 index 000000000..c97ac7ba9 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/cpu.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2020 Sean Anderson <seanga2@gmail.com> + */ + +#ifndef __SANDBOX_CPU_H +#define __SANDBOX_CPU_H + +void cpu_sandbox_set_current(const char *name); + +#endif /* __SANDBOX_CPU_H */ diff --git a/roms/u-boot/arch/sandbox/include/asm/dma-mapping.h b/roms/u-boot/arch/sandbox/include/asm/dma-mapping.h new file mode 100644 index 000000000..853b0877b --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/dma-mapping.h @@ -0,0 +1 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ diff --git a/roms/u-boot/arch/sandbox/include/asm/eth-raw-os.h b/roms/u-boot/arch/sandbox/include/asm/eth-raw-os.h new file mode 100644 index 000000000..0b511db70 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/eth-raw-os.h @@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2015 National Instruments + * + * (C) Copyright 2015 + * Joe Hershberger <joe.hershberger@ni.com> + */ + +#ifndef __ETH_RAW_OS_H +#define __ETH_RAW_OS_H + +#define IFNAMSIZ 16 + +/** + * struct eth_sandbox_raw_priv - raw socket session + * + * sd: socket descriptor - the open socket during a session + * host_ifname: interface name on the host to use for sending our packets + * host_ifindex: interface index number on the host + * device: struct sockaddr_ll - the host interface packets move to/from + * local: 1 or 0 to select the local interface ('lo') or not + * local_bindsd: socket descriptor to prevent the kernel from sending + * a message to the server claiming the port is + * unreachable + * local_bind_udp_port: The UDP port number that we bound to + */ +struct eth_sandbox_raw_priv { + int sd; + char host_ifname[IFNAMSIZ]; + unsigned int host_ifindex; + void *device; + int local; + int local_bind_sd; + unsigned short local_bind_udp_port; +}; + +/* A struct to mimic if_nameindex but that does not depend on Linux headers */ +struct sandbox_eth_raw_if_nameindex { + unsigned int if_index; /* Index of interface (1, 2, ...) */ + char *if_name; /* Null-terminated name ("eth0", etc.) */ +}; + +/* Enumerate host network interfaces */ +struct sandbox_eth_raw_if_nameindex *sandbox_eth_raw_if_nameindex(void); +/* Free the data structure of enumerated network interfaces */ +void sandbox_eth_raw_if_freenameindex(struct sandbox_eth_raw_if_nameindex *ptr); + +/* + * Check if the interface named "ifname" is a localhost interface or not. + * ifname - the interface name on the host to check + * + * returns - 0 if real interface, 1 if local, negative if error + */ +int sandbox_eth_raw_os_is_local(const char *ifname); + +/* + * Look up the name of the interface based on the ifindex populated in priv. + * + * Overwrite the host_ifname member in priv based on looking up host_ifindex + * + * returns - 0 if success, negative if error + */ +int sandbox_eth_raw_os_idx_to_name(struct eth_sandbox_raw_priv *priv); + +int sandbox_eth_raw_os_start(struct eth_sandbox_raw_priv *priv, + unsigned char *ethmac); +int sandbox_eth_raw_os_send(void *packet, int length, + struct eth_sandbox_raw_priv *priv); +int sandbox_eth_raw_os_recv(void *packet, int *length, + const struct eth_sandbox_raw_priv *priv); +void sandbox_eth_raw_os_stop(struct eth_sandbox_raw_priv *priv); + +#endif /* __ETH_RAW_OS_H */ diff --git a/roms/u-boot/arch/sandbox/include/asm/eth.h b/roms/u-boot/arch/sandbox/include/asm/eth.h new file mode 100644 index 000000000..b313bf57c --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/eth.h @@ -0,0 +1,111 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2015 National Instruments + * + * (C) Copyright 2015 + * Joe Hershberger <joe.hershberger@ni.com> + */ + +#ifndef __ETH_H +#define __ETH_H + +#include <net.h> + +void sandbox_eth_disable_response(int index, bool disable); + +void sandbox_eth_skip_timeout(void); + +/* + * sandbox_eth_arp_req_to_reply() + * + * Check for an arp request to be sent. If so, inject a reply + * + * @dev: device that received the packet + * @packet: pointer to the received pacaket buffer + * @len: length of received packet + * @return 0 if injected, -EAGAIN if not + */ +int sandbox_eth_arp_req_to_reply(struct udevice *dev, void *packet, + unsigned int len); + +/* + * sandbox_eth_ping_req_to_reply() + * + * Check for a ping request to be sent. If so, inject a reply + * + * @dev: device that received the packet + * @packet: pointer to the received pacaket buffer + * @len: length of received packet + * @return 0 if injected, -EAGAIN if not + */ +int sandbox_eth_ping_req_to_reply(struct udevice *dev, void *packet, + unsigned int len); + +/* + * sandbox_eth_recv_arp_req() + * + * Inject an ARP request for this target + * + * @dev: device that received the packet + * @return 0 if injected, -EOVERFLOW if not + */ +int sandbox_eth_recv_arp_req(struct udevice *dev); + +/* + * sandbox_eth_recv_ping_req() + * + * Inject a ping request for this target + * + * @dev: device that received the packet + * @return 0 if injected, -EOVERFLOW if not + */ +int sandbox_eth_recv_ping_req(struct udevice *dev); + +/** + * A packet handler + * + * dev - device pointer + * pkt - pointer to the "sent" packet + * len - packet length + */ +typedef int sandbox_eth_tx_hand_f(struct udevice *dev, void *pkt, + unsigned int len); + +/** + * struct eth_sandbox_priv - memory for sandbox mock driver + * + * fake_host_hwaddr - MAC address of mocked machine + * fake_host_ipaddr - IP address of mocked machine + * disabled - Will not respond + * recv_packet_buffer - buffers of the packet returned as received + * recv_packet_length - lengths of the packet returned as received + * recv_packets - number of packets returned + * tx_handler - function to generate responses to sent packets + * priv - a pointer to some structure a test may want to keep track of + */ +struct eth_sandbox_priv { + uchar fake_host_hwaddr[ARP_HLEN]; + struct in_addr fake_host_ipaddr; + bool disabled; + uchar * recv_packet_buffer[PKTBUFSRX]; + int recv_packet_length[PKTBUFSRX]; + int recv_packets; + sandbox_eth_tx_hand_f *tx_handler; + void *priv; +}; + +/* + * Set packet handler + * + * handler - The func ptr to call on send. If NULL, set to default handler + */ +void sandbox_eth_set_tx_handler(int index, sandbox_eth_tx_hand_f *handler); + +/* + * Set priv ptr + * + * priv - priv void ptr to store in the device + */ +void sandbox_eth_set_priv(int index, void *priv); + +#endif /* __ETH_H */ diff --git a/roms/u-boot/arch/sandbox/include/asm/getopt.h b/roms/u-boot/arch/sandbox/include/asm/getopt.h new file mode 100644 index 000000000..d2145ad6e --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/getopt.h @@ -0,0 +1,72 @@ +/* + * Code for setting up command line flags like `./u-boot --help` + * + * Copyright (c) 2011 The Chromium OS Authors. + * + * Licensed under the GPL-2 or later. + */ + +#ifndef __SANDBOX_GETOPT_H +#define __SANDBOX_GETOPT_H + +struct sandbox_state; + +/* + * Internal structure for storing details about the flag. + * Most people should not have to dig around in this as + * it only gets parsed by the core sandbox code. End + * consumer code should focus on the macros below and + * the callback function. + */ +struct sandbox_cmdline_option { + /* The long flag name: "help" for "--help" */ + const char *flag; + /* The (optional) short flag name: "h" for "-h" */ + int flag_short; + /* The help string shown to the user when processing --help */ + const char *help; + /* Whether this flag takes an argument */ + int has_arg; + /* Callback into the end consumer code with the option */ + int (*callback)(struct sandbox_state *state, const char *opt); +}; + +/* + * Internal macro to expand the lower macros into the necessary + * magic junk that makes this all work. + */ +#define _SANDBOX_CMDLINE_OPT(f, s, ha, h) \ + static struct sandbox_cmdline_option sandbox_cmdline_option_##f = { \ + .flag = #f, \ + .flag_short = s, \ + .help = h, \ + .has_arg = ha, \ + .callback = sandbox_cmdline_cb_##f, \ + }; \ + /* Ppointer to the struct in a special section for the linker script */ \ + static __used __section(".u_boot_sandbox_getopt") \ + struct sandbox_cmdline_option \ + *sandbox_cmdline_option_##f##_ptr = \ + &sandbox_cmdline_option_##f + +/** + * Macros for end code to declare new command line flags. + * + * @param f The long flag name e.g. help + * @param ha Does the flag have an argument e.g. 0/1 + * @param h The help string displayed when showing --help + * + * This invocation: + * SANDBOX_CMDLINE_OPT(foo, 0, "The foo arg"); + * Will create a new flag named "--foo" (no short option) that takes + * no argument. If the user specifies "--foo", then the callback func + * sandbox_cmdline_cb_foo() will automatically be called. + */ +#define SANDBOX_CMDLINE_OPT(f, ha, h) _SANDBOX_CMDLINE_OPT(f, 0, ha, h) +/* + * Same as above, but @s is used to specify a short flag e.g. + * SANDBOX_CMDLINE_OPT(foo, 'f', 0, "The foo arg"); + */ +#define SANDBOX_CMDLINE_OPT_SHORT(f, s, ha, h) _SANDBOX_CMDLINE_OPT(f, s, ha, h) + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/global_data.h b/roms/u-boot/arch/sandbox/include/asm/global_data.h new file mode 100644 index 000000000..f95ddb058 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/global_data.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * + * (C) Copyright 2002-2010 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + */ + +#ifndef __ASM_GBL_DATA_H +#define __ASM_GBL_DATA_H + +/* Architecture-specific global data */ +struct arch_global_data { + uint8_t *ram_buf; /* emulated RAM buffer */ + void *text_base; /* pointer to base of text region */ + ulong acpi_start; /* Start address of ACPI tables */ +}; + +#include <asm-generic/global_data.h> + +#define DECLARE_GLOBAL_DATA_PTR extern gd_t *gd + +#endif /* __ASM_GBL_DATA_H */ diff --git a/roms/u-boot/arch/sandbox/include/asm/gpio.h b/roms/u-boot/arch/sandbox/include/asm/gpio.h new file mode 100644 index 000000000..9e1005266 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/gpio.h @@ -0,0 +1,94 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * This is the interface to the sandbox GPIO driver for test code which + * wants to change the GPIO values reported to U-Boot. + * + * Copyright (c) 2011 The Chromium OS Authors. + */ + +#ifndef __ASM_SANDBOX_GPIO_H +#define __ASM_SANDBOX_GPIO_H + +/* + * We use the generic interface, and add a back-channel. + * + * The back-channel functions are declared in this file. They should not be used + * except in test code. + * + * Test code can, for example, call sandbox_gpio_set_value() to set the value of + * a simulated GPIO. From then on, normal code in U-Boot will see this new + * value when it calls gpio_get_value(). + * + * NOTE: DO NOT use the functions in this file except in test code! + */ +#include <asm-generic/gpio.h> + +/* Our own private GPIO flags, which musn't conflict with GPIOD_... */ +#define GPIOD_EXT_HIGH BIT(31) /* external source is high (else low) */ +#define GPIOD_EXT_DRIVEN BIT(30) /* external source is driven */ +#define GPIOD_EXT_PULL_UP BIT(29) /* GPIO has external pull-up */ +#define GPIOD_EXT_PULL_DOWN BIT(28) /* GPIO has external pull-down */ + +#define GPIOD_EXT_PULL (BIT(28) | BIT(29)) +#define GPIOD_SANDBOX_MASK GENMASK(31, 28) + +/** + * Return the simulated value of a GPIO (used only in sandbox test code) + * + * @param dev device to use + * @param offset GPIO offset within bank + * @return -1 on error, 0 if GPIO is low, >0 if high + */ +int sandbox_gpio_get_value(struct udevice *dev, unsigned int offset); + +/** + * Set the simulated value of a GPIO (used only in sandbox test code) + * + * @param dev device to use + * @param offset GPIO offset within bank + * @param value value to set (0 for low, non-zero for high) + * @return -1 on error, 0 if ok + */ +int sandbox_gpio_set_value(struct udevice *dev, unsigned int offset, int value); + +/** + * Return the simulated direction of a GPIO (used only in sandbox test code) + * + * @param dev device to use + * @param offset GPIO offset within bank + * @return -1 on error, 0 if GPIO is input, >0 if output + */ +int sandbox_gpio_get_direction(struct udevice *dev, unsigned int offset); + +/** + * Set the simulated direction of a GPIO (used only in sandbox test code) + * + * @param dev device to use + * @param offset GPIO offset within bank + * @param output 0 to set as input, 1 to set as output + * @return -1 on error, 0 if ok + */ +int sandbox_gpio_set_direction(struct udevice *dev, unsigned int offset, + int output); + +/** + * Return the simulated flags of a GPIO (used only in sandbox test code) + * + * @param dev device to use + * @param offset GPIO offset within bank + * @return dir_flags: bitfield accesses by GPIOD_ defines + */ +ulong sandbox_gpio_get_flags(struct udevice *dev, unsigned int offset); + +/** + * Set the simulated flags of a GPIO (used only in sandbox test code) + * + * @param dev device to use + * @param offset GPIO offset within bank + * @param flags bitfield accesses by GPIOD_ defines + * @return -1 on error, 0 if ok + */ +int sandbox_gpio_set_flags(struct udevice *dev, unsigned int offset, + ulong flags); + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/handoff.h b/roms/u-boot/arch/sandbox/include/asm/handoff.h new file mode 100644 index 000000000..be4e7b0fa --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/handoff.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Architecture-specific SPL handoff information for sandbox + * + * Copyright 2018 Google, Inc + * Written by Simon Glass <sjg@chromium.org> + */ + +#ifndef __handoff_h +#define __handoff_h + +#define TEST_HANDOFF_MAGIC 0x14f93c7b + +struct arch_spl_handoff { + ulong magic; /* Used for testing */ +}; + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/i2c.h b/roms/u-boot/arch/sandbox/include/asm/i2c.h new file mode 100644 index 000000000..4fc190be4 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/i2c.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2020 Google LLC + * Written by Simon Glass <sjg@chromium.org> + */ + +#ifndef __asn_i2c_h +#define __asn_i2c_h + +struct sandbox_i2c_priv { + bool test_mode; +}; + +/** + * struct i2c_emul_uc_plat - information about the emulator for this device + * + * This is used by devices in UCLASS_I2C_EMUL to record information about the + * device being emulated. It is accessible with dev_get_uclass_plat() + * + * @dev: Device being emulated + * @idx: of-platdata index, set up by the device's bind() method if of-platdata + * is in use + */ +struct i2c_emul_uc_plat { + struct udevice *dev; + int idx; +}; + +#endif /* __asn_i2c_h */ diff --git a/roms/u-boot/arch/sandbox/include/asm/io.h b/roms/u-boot/arch/sandbox/include/asm/io.h new file mode 100644 index 000000000..ad6c29a4e --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/io.h @@ -0,0 +1,233 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2011 The Chromium OS Authors. + */ + +#ifndef __SANDBOX_ASM_IO_H +#define __SANDBOX_ASM_IO_H + +enum sandboxio_size_t { + SB_SIZE_8, + SB_SIZE_16, + SB_SIZE_32, + SB_SIZE_64, +}; + +void *phys_to_virt(phys_addr_t paddr); +#define phys_to_virt phys_to_virt + +phys_addr_t virt_to_phys(void *vaddr); +#define virt_to_phys virt_to_phys + +void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags); +#define map_physmem map_physmem + +/* + * Take down a mapping set up by map_physmem(). + */ +void unmap_physmem(const void *vaddr, unsigned long flags); +#define unmap_physmem unmap_physmem + +#include <asm-generic/io.h> + +/* For sandbox, we want addresses to point into our RAM buffer */ +static inline void *map_sysmem(phys_addr_t paddr, unsigned long len) +{ + return map_physmem(paddr, len, MAP_WRBACK); +} + +/* Remove a previous mapping */ +static inline void unmap_sysmem(const void *vaddr) +{ + unmap_physmem(vaddr, MAP_WRBACK); +} + +/* Map from a pointer to our RAM buffer */ +phys_addr_t map_to_sysmem(const void *ptr); + +unsigned int sandbox_read(const void *addr, enum sandboxio_size_t size); +void sandbox_write(void *addr, unsigned int val, enum sandboxio_size_t size); + +#define readb(addr) sandbox_read((const void *)addr, SB_SIZE_8) +#define readw(addr) sandbox_read((const void *)addr, SB_SIZE_16) +#define readl(addr) sandbox_read((const void *)addr, SB_SIZE_32) +#ifdef CONFIG_SANDBOX64 +#define readq(addr) sandbox_read((const void *)addr, SB_SIZE_64) +#endif +#define writeb(v, addr) sandbox_write((void *)addr, v, SB_SIZE_8) +#define writew(v, addr) sandbox_write((void *)addr, v, SB_SIZE_16) +#define writel(v, addr) sandbox_write((void *)addr, v, SB_SIZE_32) +#ifdef CONFIG_SANDBOX64 +#define writeq(v, addr) sandbox_write((void *)addr, v, SB_SIZE_64) +#endif + +/* + * Clear and set bits in one shot. These macros can be used to clear and + * set multiple bits in a register using a single call. These macros can + * also be used to set a multiple-bit bit pattern using a mask, by + * specifying the mask in the 'clear' parameter and the new bit pattern + * in the 'set' parameter. + */ + +#define out_arch(type,endian,a,v) write##type(cpu_to_##endian(v),a) +#define in_arch(type,endian,a) endian##_to_cpu(read##type(a)) + +#define out_le64(a,v) out_arch(q,le64,a,v) +#define out_le32(a,v) out_arch(l,le32,a,v) +#define out_le16(a,v) out_arch(w,le16,a,v) + +#define in_le64(a) in_arch(q,le64,a) +#define in_le32(a) in_arch(l,le32,a) +#define in_le16(a) in_arch(w,le16,a) + +#define out_be32(a,v) out_arch(l,be32,a,v) +#define out_be16(a,v) out_arch(w,be16,a,v) + +#define in_be32(a) in_arch(l,be32,a) +#define in_be16(a) in_arch(w,be16,a) + +#define out_8(a,v) writeb(v,a) +#define in_8(a) readb(a) + +#define clrbits(type, addr, clear) \ + out_##type((addr), in_##type(addr) & ~(clear)) + +#define setbits(type, addr, set) \ + out_##type((addr), in_##type(addr) | (set)) + +#define clrsetbits(type, addr, clear, set) \ + out_##type((addr), (in_##type(addr) & ~(clear)) | (set)) + +#define clrbits_be32(addr, clear) clrbits(be32, addr, clear) +#define setbits_be32(addr, set) setbits(be32, addr, set) +#define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set) + +#define clrbits_le32(addr, clear) clrbits(le32, addr, clear) +#define setbits_le32(addr, set) setbits(le32, addr, set) +#define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set) + +#define clrbits_be16(addr, clear) clrbits(be16, addr, clear) +#define setbits_be16(addr, set) setbits(be16, addr, set) +#define clrsetbits_be16(addr, clear, set) clrsetbits(be16, addr, clear, set) + +#define clrbits_le16(addr, clear) clrbits(le16, addr, clear) +#define setbits_le16(addr, set) setbits(le16, addr, set) +#define clrsetbits_le16(addr, clear, set) clrsetbits(le16, addr, clear, set) + +#define clrbits_8(addr, clear) clrbits(8, addr, clear) +#define setbits_8(addr, set) setbits(8, addr, set) +#define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set) + +/* I/O access functions */ +int _inl(unsigned int addr); +int _inw(unsigned int addr); +int _inb(unsigned int addr); + +void _outl(unsigned int value, unsigned int addr); +void _outw(unsigned int value, unsigned int addr); +void _outb(unsigned int value, unsigned int addr); + +#define inb(port) _inb((uintptr_t)(port)) +#define inw(port) _inw((uintptr_t)(port)) +#define inl(port) _inl((uintptr_t)(port)) + +#define outb(val, port) _outb(val, (uintptr_t)(port)) +#define outw(val, port) _outw(val, (uintptr_t)(port)) +#define outl(val, port) _outl(val, (uintptr_t)(port)) + +#define out_arch(type,endian,a,v) write##type(cpu_to_##endian(v),a) +#define in_arch(type,endian,a) endian##_to_cpu(read##type(a)) + +#define out_le32(a,v) out_arch(l,le32,a,v) +#define out_le16(a,v) out_arch(w,le16,a,v) + +#define in_le32(a) in_arch(l,le32,a) +#define in_le16(a) in_arch(w,le16,a) + +#define out_be32(a,v) out_arch(l,be32,a,v) +#define out_be16(a,v) out_arch(w,be16,a,v) + +#define in_be32(a) in_arch(l,be32,a) +#define in_be16(a) in_arch(w,be16,a) + +#define out_8(a,v) writeb(v,a) +#define in_8(a) readb(a) + +#define clrbits(type, addr, clear) \ + out_##type((addr), in_##type(addr) & ~(clear)) + +#define setbits(type, addr, set) \ + out_##type((addr), in_##type(addr) | (set)) + +#define clrsetbits(type, addr, clear, set) \ + out_##type((addr), (in_##type(addr) & ~(clear)) | (set)) + +#define clrbits_be32(addr, clear) clrbits(be32, addr, clear) +#define setbits_be32(addr, set) setbits(be32, addr, set) +#define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set) + +#define clrbits_le32(addr, clear) clrbits(le32, addr, clear) +#define setbits_le32(addr, set) setbits(le32, addr, set) +#define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set) + +#define clrbits_be16(addr, clear) clrbits(be16, addr, clear) +#define setbits_be16(addr, set) setbits(be16, addr, set) +#define clrsetbits_be16(addr, clear, set) clrsetbits(be16, addr, clear, set) + +#define clrbits_le16(addr, clear) clrbits(le16, addr, clear) +#define setbits_le16(addr, set) setbits(le16, addr, set) +#define clrsetbits_le16(addr, clear, set) clrsetbits(le16, addr, clear, set) + +#define clrbits_8(addr, clear) clrbits(8, addr, clear) +#define setbits_8(addr, set) setbits(8, addr, set) +#define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set) + +static inline void _insw(volatile u16 *port, void *buf, int ns) +{ +} + +static inline void _outsw(volatile u16 *port, const void *buf, int ns) +{ +} + +static inline void memset_io(volatile void *addr, unsigned char val, int count) +{ +} + +static inline void memcpy_fromio(void *dst, const volatile void *src, int count) +{ +} + +static inline void memcpy_toio(volatile void *dst, const void *src, int count) +{ +} + +#define insw(port, buf, ns) _insw((u16 *)port, buf, ns) +#define outsw(port, buf, ns) _outsw((u16 *)port, buf, ns) + +/* IO space accessors */ +#define clrio(type, addr, clear) \ + out##type(in##type(addr) & ~(clear), (addr)) + +#define setio(type, addr, set) \ + out##type(in##type(addr) | (set), (addr)) + +#define clrsetio(type, addr, clear, set) \ + out##type((in##type(addr) & ~(clear)) | (set), (addr)) + +#define clrio_32(addr, clear) clrio(l, addr, clear) +#define clrio_16(addr, clear) clrio(w, addr, clear) +#define clrio_8(addr, clear) clrio(b, addr, clear) + +#define setio_32(addr, set) setio(l, addr, set) +#define setio_16(addr, set) setio(w, addr, set) +#define setio_8(addr, set) setio(b, addr, set) + +#define clrsetio_32(addr, clear, set) clrsetio(l, addr, clear, set) +#define clrsetio_16(addr, clear, set) clrsetio(w, addr, clear, set) +#define clrsetio_8(addr, clear, set) clrsetio(b, addr, clear, set) + +#include <iotrace.h> +#include <asm/types.h> + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/linkage.h b/roms/u-boot/arch/sandbox/include/asm/linkage.h new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/linkage.h diff --git a/roms/u-boot/arch/sandbox/include/asm/malloc.h b/roms/u-boot/arch/sandbox/include/asm/malloc.h new file mode 100644 index 000000000..a1467b5ea --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/malloc.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Sandbox access to system malloc (i.e. not U-Boot's) + * + * Copyright 2020 Google LLC + */ + +#ifndef __ASM_MALLOC_H + +void *malloc(size_t size); +void free(void *ptr); +void *calloc(size_t nmemb, size_t size); +void *realloc(void *ptr, size_t size); +void *reallocarray(void *ptr, size_t nmemb, size_t size); + +/* + * This header allows calling the system allocation routines. It makes no + * sense to also include U-Boot's malloc.h since that redfines malloc to + * have a 'dl' prefix. These two implementations cannot be mixed and matched + * in the same file. + */ +#ifdef __MALLOC_H__ +#error "This sandbox header file cannot be included with malloc.h" +#endif + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/mbox.h b/roms/u-boot/arch/sandbox/include/asm/mbox.h new file mode 100644 index 000000000..70f36d7af --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/mbox.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2016, NVIDIA CORPORATION. + */ + +#ifndef __SANDBOX_MBOX_H +#define __SANDBOX_MBOX_H + +#include <common.h> + +#define SANDBOX_MBOX_PING_XOR 0x12345678 + +struct udevice; + +int sandbox_mbox_test_get(struct udevice *dev); +int sandbox_mbox_test_send(struct udevice *dev, uint32_t msg); +int sandbox_mbox_test_recv(struct udevice *dev, uint32_t *msg); +int sandbox_mbox_test_free(struct udevice *dev); + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/posix_types.h b/roms/u-boot/arch/sandbox/include/asm/posix_types.h new file mode 100644 index 000000000..ec18ed7e3 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/posix_types.h @@ -0,0 +1,57 @@ +/* + * linux/include/asm-arm/posix_types.h + * + * Copyright (C) 1996-1998 Russell King. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Changelog: + * 27-06-1996 RMK Created + */ +#ifndef __ARCH_ARM_POSIX_TYPES_H +#define __ARCH_ARM_POSIX_TYPES_H + +/* + * This file is generally used by user-level software, so you need to + * be a little careful about namespace pollution etc. Also, we cannot + * assume GCC is being used. + */ + +typedef unsigned short __kernel_dev_t; +typedef unsigned long __kernel_ino_t; +typedef unsigned short __kernel_mode_t; +typedef unsigned short __kernel_nlink_t; +typedef long __kernel_off_t; +typedef int __kernel_pid_t; +typedef unsigned short __kernel_ipc_pid_t; +typedef unsigned short __kernel_uid_t; +typedef unsigned short __kernel_gid_t; +#if CONFIG_SANDBOX_BITS_PER_LONG == 32 +typedef unsigned int __kernel_size_t; +typedef int __kernel_ssize_t; +typedef int __kernel_ptrdiff_t; +#else +typedef unsigned long __kernel_size_t; +typedef long __kernel_ssize_t; +typedef long __kernel_ptrdiff_t; +#endif +typedef long __kernel_time_t; +typedef long __kernel_suseconds_t; +typedef long __kernel_clock_t; +typedef int __kernel_daddr_t; +typedef char *__kernel_caddr_t; +typedef unsigned short __kernel_uid16_t; +typedef unsigned short __kernel_gid16_t; +typedef unsigned int __kernel_uid32_t; +typedef unsigned int __kernel_gid32_t; + +typedef unsigned short __kernel_old_uid_t; +typedef unsigned short __kernel_old_gid_t; + +#ifdef __GNUC__ +typedef long long __kernel_loff_t; +#endif + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/power-domain.h b/roms/u-boot/arch/sandbox/include/asm/power-domain.h new file mode 100644 index 000000000..1845bc8d3 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/power-domain.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2016, NVIDIA CORPORATION. + */ + +#ifndef __SANDBOX_POWER_DOMAIN_H +#define __SANDBOX_POWER_DOMAIN_H + +#include <common.h> + +struct udevice; + +int sandbox_power_domain_query(struct udevice *dev, unsigned long id); + +int sandbox_power_domain_test_get(struct udevice *dev); +int sandbox_power_domain_test_on(struct udevice *dev); +int sandbox_power_domain_test_off(struct udevice *dev); +int sandbox_power_domain_test_free(struct udevice *dev); + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/processor.h b/roms/u-boot/arch/sandbox/include/asm/processor.h new file mode 100644 index 000000000..8dced6006 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/processor.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2014 Google, Inc + */ + +#ifndef _ASM_PROCESSOR_H +#define _ASM_PROCESSOR_H + +/* This file is required for PCI */ + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/ptrace.h b/roms/u-boot/arch/sandbox/include/asm/ptrace.h new file mode 100644 index 000000000..78e58173f --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/ptrace.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2011 The Chromium OS Authors. + */ + +#ifndef __ASM_SANDBOX_PTRACE_H +#define __ASM_SANDBOX_PTRACE_H + +#ifndef __ASSEMBLY__ +/* This is not used in the sandbox architecture, but required by U-Boot */ +struct pt_regs { +}; + +#ifdef __KERNEL__ +extern void show_regs(struct pt_regs *); + +#endif + +#endif /* __ASSEMBLY__ */ + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/reset.h b/roms/u-boot/arch/sandbox/include/asm/reset.h new file mode 100644 index 000000000..40d3e61c1 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/reset.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2016, NVIDIA CORPORATION. + */ + +#ifndef __SANDBOX_RESET_H +#define __SANDBOX_RESET_H + +#include <common.h> + +struct udevice; + +int sandbox_reset_query(struct udevice *dev, unsigned long id); +int sandbox_reset_is_requested(struct udevice *dev, unsigned long id); + +int sandbox_reset_test_get(struct udevice *dev); +int sandbox_reset_test_get_devm(struct udevice *dev); +int sandbox_reset_test_get_bulk(struct udevice *dev); +int sandbox_reset_test_get_bulk_devm(struct udevice *dev); +int sandbox_reset_test_assert(struct udevice *dev); +int sandbox_reset_test_assert_bulk(struct udevice *dev); +int sandbox_reset_test_deassert(struct udevice *dev); +int sandbox_reset_test_deassert_bulk(struct udevice *dev); +int sandbox_reset_test_free(struct udevice *dev); +int sandbox_reset_test_release_bulk(struct udevice *dev); + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/rtc.h b/roms/u-boot/arch/sandbox/include/asm/rtc.h new file mode 100644 index 000000000..025cd6c67 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/rtc.h @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Simulate an I2C real time clock + * + * Copyright (c) 2015 Google, Inc + * Written by Simon Glass <sjg@chromium.org> + */ + +#ifndef __asm_rtc_h +#define __asm_rtc_h + +#include <dt-structs.h> + +/* Register numbers in the sandbox RTC */ +enum { + REG_SEC = 5, + REG_MIN, + REG_HOUR, + REG_MDAY, + REG_MON, + REG_YEAR, + REG_WDAY, + + REG_RESET = 0x20, + + REG_AUX0 = 0x30, + REG_AUX1, + REG_AUX2, + REG_AUX3, + + REG_COUNT = 0x80, +}; + +/** + * struct sandbox_i2c_rtc_plat_data - platform data for the RTC + * + * @base_time: Base system time when RTC device was bound + * @offset: RTC offset from current system time + * @use_system_time: true to use system time, false to use @base_time + * @reg: Register values + */ +struct sandbox_i2c_rtc_plat_data { +#if CONFIG_IS_ENABLED(OF_PLATDATA) + struct dtd_sandbox_i2c_rtc_emul dtplat; +#endif + long base_time; + long offset; + bool use_system_time; + u8 reg[REG_COUNT]; +}; + +struct sandbox_i2c_rtc { + unsigned int offset_secs; +}; + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/scmi_test.h b/roms/u-boot/arch/sandbox/include/asm/scmi_test.h new file mode 100644 index 000000000..2930e686d --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/scmi_test.h @@ -0,0 +1,120 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2020, Linaro Limited + */ + +#ifndef __SANDBOX_SCMI_TEST_H +#define __SANDBOX_SCMI_TEST_H + +struct udevice; +struct sandbox_scmi_agent; +struct sandbox_scmi_service; + +/** + * struct sandbox_scmi_clk - Simulated clock exposed by SCMI + * @id: Identifier of the clock used in the SCMI protocol + * @enabled: Clock state: true if enabled, false if disabled + * @rate: Clock rate in Hertz + */ +struct sandbox_scmi_clk { + uint id; + bool enabled; + ulong rate; +}; + +/** + * struct sandbox_scmi_reset - Simulated reset controller exposed by SCMI + * @id: Identifier of the reset controller used in the SCMI protocol + * @asserted: Reset control state: true if asserted, false if desasserted + */ +struct sandbox_scmi_reset { + uint id; + bool asserted; +}; + +/** + * struct sandbox_scmi_voltd - Simulated voltage regulator exposed by SCMI + * @id: Identifier of the voltage domain used in the SCMI protocol + * @enabled: Regulator state: true if on, false if off + * @voltage_uv: Regulator current voltage in microvoltd (uV) + */ +struct sandbox_scmi_voltd { + uint id; + bool enabled; + int voltage_uv; +}; + +/** + * struct sandbox_scmi_agent - Simulated SCMI service seen by SCMI agent + * @idx: Identifier for the SCMI agent, its index + * @clk: Simulated clocks + * @clk_count: Simulated clocks array size + * @reset: Simulated reset domains + * @reset_count: Simulated reset domains array size + * @voltd: Simulated voltage domains (regulators) + * @voltd_count: Simulated voltage domains array size + */ +struct sandbox_scmi_agent { + uint idx; + struct sandbox_scmi_clk *clk; + size_t clk_count; + struct sandbox_scmi_reset *reset; + size_t reset_count; + struct sandbox_scmi_voltd *voltd; + size_t voltd_count; +}; + +/** + * struct sandbox_scmi_service - Reference to simutaed SCMI agents/services + * @agent: Pointer to SCMI sandbox agent pointers array + * @agent_count: Number of emulated agents exposed in array @agent. + */ +struct sandbox_scmi_service { + struct sandbox_scmi_agent **agent; + size_t agent_count; +}; + +/** + * struct sandbox_scmi_devices - Reference to devices probed through SCMI + * @clk: Array the clock devices + * @clk_count: Number of clock devices probed + * @reset: Array the reset controller devices + * @reset_count: Number of reset controller devices probed + * @regul: Array regulator devices + * @regul_count: Number of regulator devices probed + */ +struct sandbox_scmi_devices { + struct clk *clk; + size_t clk_count; + struct reset_ctl *reset; + size_t reset_count; + struct udevice **regul; + size_t regul_count; +}; + +#ifdef CONFIG_SCMI_FIRMWARE +/** + * sandbox_scmi_service_context - Get the simulated SCMI services context + * @return: Reference to backend simulated resources state + */ +struct sandbox_scmi_service *sandbox_scmi_service_ctx(void); + +/** + * sandbox_scmi_devices_get_ref - Get references to devices accessed through SCMI + * @dev: Reference to the test device used get test resources + * @return: Reference to the devices probed by the SCMI test + */ +struct sandbox_scmi_devices *sandbox_scmi_devices_ctx(struct udevice *dev); +#else +static inline struct sandbox_scmi_service *sandbox_scmi_service_ctx(void) +{ + return NULL; +} + +static inline +struct sandbox_scmi_devices *sandbox_scmi_devices_ctx(struct udevice *dev) +{ + return NULL; +} +#endif /* CONFIG_SCMI_FIRMWARE */ +#endif /* __SANDBOX_SCMI_TEST_H */ diff --git a/roms/u-boot/arch/sandbox/include/asm/sdl.h b/roms/u-boot/arch/sandbox/include/asm/sdl.h new file mode 100644 index 000000000..47fc4889d --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/sdl.h @@ -0,0 +1,127 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2013 Google, Inc + */ + +#ifndef __SANDBOX_SDL_H +#define __SANDBOX_SDL_H + +#include <errno.h> + +#ifdef CONFIG_SANDBOX_SDL + +/** + * sandbox_sdl_init_display() - Set up SDL video ready for use + * + * @width: Window width in pixels + * @height Window height in pixels + * @log2_bpp: Log to base 2 of the number of bits per pixel. So a 32bpp + * display will pass 5, since 2*5 = 32 + * @double_size: true to double the visible size in each direction for high-DPI + * displays + * @return 0 if OK, -ENODEV if no device, -EIO if SDL failed to initialize + * and -EPERM if the video failed to come up. + */ +int sandbox_sdl_init_display(int width, int height, int log2_bpp, + bool double_size); + +/** + * sandbox_sdl_sync() - Sync current U-Boot LCD frame buffer to SDL + * + * This must be called periodically to update the screen for SDL so that the + * user can see it. + * + * @lcd_base: Base of frame buffer + * @return 0 if screen was updated, -ENODEV is there is no screen. + */ +int sandbox_sdl_sync(void *lcd_base); + +/** + * sandbox_sdl_scan_keys() - scan for pressed keys + * + * Works out which keys are pressed and returns a list + * + * @key: Array to receive keycodes + * @max_keys: Size of array + * @return number of keycodes found, 0 if none, -ENODEV if no keyboard + */ +int sandbox_sdl_scan_keys(int key[], int max_keys); + +/** + * sandbox_sdl_key_pressed() - check if a particular key is pressed + * + * @keycode: Keycode to check (KEY_... - see include/linux/input.h + * @return 0 if pressed, -ENOENT if not pressed. -ENODEV if keybord not + * available, + */ +int sandbox_sdl_key_pressed(int keycode); + +/** + * sandbox_sdl_sound_play() - Play a sound + * + * @data: Data to play (typically 16-bit) + * @count: Number of bytes in data + */ +int sandbox_sdl_sound_play(const void *data, uint count); + +/** + * sandbox_sdl_sound_stop() - stop playing a sound + * + * @return 0 if OK, -ENODEV if no sound is available + */ +int sandbox_sdl_sound_stop(void); + +/** + * sandbox_sdl_sound_init() - set up the sound system + * + * @rate: Sample rate to use + * @channels: Number of channels to use (1=mono, 2=stereo) + * @return 0 if OK, -ENODEV if no sound is available + */ +int sandbox_sdl_sound_init(int rate, int channels); + +#else +static inline int sandbox_sdl_init_display(int width, int height, int log2_bpp, + bool double_size) +{ + return -ENODEV; +} + +static inline int sandbox_sdl_sync(void *lcd_base) +{ + return -ENODEV; +} + +static inline int sandbox_sdl_scan_keys(int key[], int max_keys) +{ + return -ENODEV; +} + +static inline int sandbox_sdl_key_pressed(int keycode) +{ + return -ENODEV; +} + +static inline int sandbox_sdl_sound_start(uint frequency) +{ + return -ENODEV; +} + +static inline int sandbox_sdl_sound_play(const void *data, uint count) +{ + return -ENODEV; +} + +static inline int sandbox_sdl_sound_stop(void) +{ + return -ENODEV; +} + +static inline int sandbox_sdl_sound_init(int rate, int channels) +{ + return -ENODEV; +} + +#endif + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/sections.h b/roms/u-boot/arch/sandbox/include/asm/sections.h new file mode 100644 index 000000000..f4351ae7d --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/sections.h @@ -0,0 +1,39 @@ +/* + * decls for symbols defined in the linker script + * + * Copyright (c) 2012 The Chromium OS Authors. + * + * Licensed under the GPL-2 or later. + */ + +#ifndef __SANDBOX_SECTIONS_H +#define __SANDBOX_SECTIONS_H + +#include <asm-generic/sections.h> + +struct sandbox_cmdline_option; + +static inline struct sandbox_cmdline_option ** +__u_boot_sandbox_option_start(void) +{ + static char start[0] __aligned(4) __attribute__((unused)) + __section(".u_boot_sandbox_getopt_start"); + + return (struct sandbox_cmdline_option **)&start; +} + +static inline struct sandbox_cmdline_option ** +__u_boot_sandbox_option_end(void) +{ + static char end[0] __aligned(4) __attribute__((unused)) + __section(".u_boot_sandbox_getopt_end"); + + return (struct sandbox_cmdline_option **)&end; +} + +static inline size_t __u_boot_sandbox_option_count(void) +{ + return __u_boot_sandbox_option_end() - __u_boot_sandbox_option_start(); +} + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/serial.h b/roms/u-boot/arch/sandbox/include/asm/serial.h new file mode 100644 index 000000000..bc82aebd0 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/serial.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2020 Google LLC + * Written by Simon Glass <sjg@chromium.org> + */ + +#ifndef __asm_serial_h +#define __asm_serial_h + +#include <dt-structs.h> + +struct sandbox_serial_plat { +#if CONFIG_IS_ENABLED(OF_PLATDATA) + struct dtd_sandbox_serial dtplat; +#endif + int colour; /* Text colour to use for output, -1 for none */ +}; + +/** + * struct sandbox_serial_priv - Private data for this driver + * + * @buf: holds input characters available to be read by this driver + */ +struct sandbox_serial_priv { + struct membuff buf; + char serial_buf[16]; + bool start_of_line; +}; + +#endif /* __asm_serial_h */ diff --git a/roms/u-boot/arch/sandbox/include/asm/setjmp.h b/roms/u-boot/arch/sandbox/include/asm/setjmp.h new file mode 100644 index 000000000..001c7ea32 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/setjmp.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * (C) 2018 Google, Inc + * Written by Simon Glass <sjg@chromium.org> + */ + +#ifndef _SETJMP_H_ +#define _SETJMP_H_ + +struct jmp_buf_data { + /* + * We're not sure how long this should be: + * + * amd64: 200 bytes + * arm64: 392 bytes + * armhf: 392 bytes + * + * So allow space for all of those, plus some extra. + * We don't need to worry about 16-byte alignment, since this does not + * run on Windows. + */ + ulong data[128]; +}; + +typedef struct jmp_buf_data jmp_buf[1]; + +/* + * We have to directly link with the system versions of + * setjmp/longjmp, because setjmp must not return as otherwise + * the stack may become invalid. + */ +int setjmp(jmp_buf jmp); +__noreturn void longjmp(jmp_buf jmp, int ret); + +#endif /* _SETJMP_H_ */ diff --git a/roms/u-boot/arch/sandbox/include/asm/spi.h b/roms/u-boot/arch/sandbox/include/asm/spi.h new file mode 100644 index 000000000..e8268bbe0 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/spi.h @@ -0,0 +1,35 @@ +/* + * Simulate a SPI port and clients (see doc/arch/sandbox.rst for details) + * + * Copyright (c) 2011-2013 The Chromium OS Authors. + * See file CREDITS for list of people who contributed to this + * project. + * + * Licensed under the GPL-2 or later. + */ + +#ifndef __ASM_SPI_H__ +#define __ASM_SPI_H__ + +#include <linux/types.h> + +/* + * The interface between the SPI bus and the SPI client. The bus will + * instantiate a client, and that then call into it via these entry + * points. These should be enough for the client to emulate the SPI + * device just like the real hardware. + */ +struct sandbox_spi_emu_ops { + /* The bus wants to instantiate a new client, so setup everything */ + int (*setup)(void **priv, const char *spec); + /* The bus is done with us, so break things down */ + void (*free)(void *priv); + /* The CS has been "activated" -- we won't worry about low/high */ + void (*cs_activate)(void *priv); + /* The CS has been "deactivated" -- we won't worry about low/high */ + void (*cs_deactivate)(void *priv); + /* The client is rx-ing bytes from the bus, so it should tx some */ + int (*xfer)(void *priv, const u8 *rx, u8 *tx, uint bytes); +}; + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/spl.h b/roms/u-boot/arch/sandbox/include/asm/spl.h new file mode 100644 index 000000000..51e9d95d5 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/spl.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2016 Google, Inc + */ + +#ifndef __asm_spl_h +#define __asm_spl_h + +#define CONFIG_SPL_BOARD_LOAD_IMAGE + +enum { + BOOT_DEVICE_BOARD, +}; + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/state.h b/roms/u-boot/arch/sandbox/include/asm/state.h new file mode 100644 index 000000000..bca130698 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/state.h @@ -0,0 +1,279 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2011-2012 The Chromium OS Authors. + */ + +#ifndef __SANDBOX_STATE_H +#define __SANDBOX_STATE_H + +#include <config.h> +#include <sysreset.h> +#include <stdbool.h> +#include <linux/list.h> +#include <linux/stringify.h> + +/** + * Selects the behavior of the serial terminal. + * + * If Ctrl-C is processed by U-Boot, then the only way to quit sandbox is with + * the 'reset' command, or equivalent. + * + * If the terminal is cooked, then Ctrl-C will terminate U-Boot, and the + * command line will not be quite such a faithful emulation. + * + * Options are: + * + * raw-with-sigs - Raw, but allow signals (Ctrl-C will quit) + * raw - Terminal is always raw + * cooked - Terminal is always cooked + */ +enum state_terminal_raw { + STATE_TERM_RAW_WITH_SIGS, /* Default */ + STATE_TERM_RAW, + STATE_TERM_COOKED, + + STATE_TERM_COUNT, +}; + +struct sandbox_spi_info { + struct udevice *emul; +}; + +struct sandbox_wdt_info { + unsigned long long counter; + uint reset_count; + bool running; +}; + +/** + * struct sandbox_mapmem_entry - maps pointers to/from U-Boot addresses + * + * When map_to_sysmem() is called with an address outside sandbox's emulated + * RAM, a record is created with a tag that can be used to reference that + * pointer. When map_sysmem() is called later with that tag, the pointer will + * be returned, just as it would for a normal sandbox address. + * + * @tag: Address tag (a value which U-Boot uses to refer to the address) + * @ptr: Associated pointer for that tag + */ +struct sandbox_mapmem_entry { + ulong tag; + void *ptr; + struct list_head sibling_node; +}; + +/* The complete state of the test system */ +struct sandbox_state { + const char *cmd; /* Command to execute */ + bool interactive; /* Enable cmdline after execute */ + bool run_distro_boot; /* Automatically run distro bootcommands */ + const char *fdt_fname; /* Filename of FDT binary */ + const char *parse_err; /* Error to report from parsing */ + int argc; /* Program arguments */ + char **argv; /* Command line arguments */ + const char *jumped_fname; /* Jumped from previous U_Boot */ + uint8_t *ram_buf; /* Emulated RAM buffer */ + unsigned long ram_size; /* Size of RAM buffer */ + const char *ram_buf_fname; /* Filename to use for RAM buffer */ + bool ram_buf_rm; /* Remove RAM buffer file after read */ + bool write_ram_buf; /* Write RAM buffer on exit */ + const char *state_fname; /* File containing sandbox state */ + void *state_fdt; /* Holds saved state for sandbox */ + bool read_state; /* Read sandbox state on startup */ + bool write_state; /* Write sandbox state on exit */ + bool ignore_missing_state_on_read; /* No error if state missing */ + bool show_lcd; /* Show LCD on start-up */ + bool double_lcd; /* Double display size for high-DPI */ + enum sysreset_t last_sysreset; /* Last system reset type */ + bool sysreset_allowed[SYSRESET_COUNT]; /* Allowed system reset types */ + enum state_terminal_raw term_raw; /* Terminal raw/cooked */ + bool skip_delays; /* Ignore any time delays (for test) */ + bool show_test_output; /* Don't suppress stdout in tests */ + int default_log_level; /* Default log level for sandbox */ + bool ram_buf_read; /* true if we read the RAM buffer */ + bool run_unittests; /* Run unit tests */ + const char *select_unittests; /* Unit test to run */ + + /* Pointer to information for each SPI bus/cs */ + struct sandbox_spi_info spi[CONFIG_SANDBOX_SPI_MAX_BUS] + [CONFIG_SANDBOX_SPI_MAX_CS]; + + /* Information about Watchdog */ + struct sandbox_wdt_info wdt; + + ulong next_tag; /* Next address tag to allocate */ + struct list_head mapmem_head; /* struct sandbox_mapmem_entry */ + bool hwspinlock; /* Hardware Spinlock status */ + bool allow_memio; /* Allow readl() etc. to work */ + + /* + * This struct is getting large. + * + * Consider putting test data in driver-private structs, like + * sandbox_pch.c. + * + * If you add new members, please put them above this comment. + */ +}; + +/* Minimum space we guarantee in the state FDT when calling read/write*/ +#define SANDBOX_STATE_MIN_SPACE 0x1000 + +/** + * struct sandbox_state_io - methods to saved/restore sandbox state + * @name: Name of of the device tree node, also the name of the variable + * holding this data so it should be an identifier (use underscore + * instead of minus) + * @compat: Compatible string for the node containing this state + * + * @read: Function to read state from FDT + * If data is available, then blob and node will provide access to it. If + * not (blob == NULL and node == -1) this function should set up an empty + * data set for start-of-day. + * @param blob: Pointer to device tree blob, or NULL if no data to read + * @param node: Node offset to read from + * @return 0 if OK, -ve on error + * + * @write: Function to write state to FDT + * The caller will ensure that there is a node ready for the state. The + * node may already contain the old state, in which case it should be + * overridden. There is guaranteed to be SANDBOX_STATE_MIN_SPACE bytes + * of free space, so error checking is not required for fdt_setprop...() + * calls which add up to less than this much space. + * + * For adding larger properties, use state_setprop(). + * + * @param blob: Device tree blob holding state + * @param node: Node to write our state into + * + * Note that it is possible to save data as large blobs or as individual + * hierarchical properties. However, unless you intend to keep state files + * around for a long time and be able to run an old state file on a new + * sandbox, it might not be worth using individual properties for everything. + * This is certainly supported, it is just a matter of the effort you wish + * to put into the state read/write feature. + */ +struct sandbox_state_io { + const char *name; + const char *compat; + int (*write)(void *blob, int node); + int (*read)(const void *blob, int node); +}; + +/** + * SANDBOX_STATE_IO - Declare sandbox state to read/write + * + * Sandbox permits saving state from one run and restoring it in another. This + * allows the test system to retain state between runs and thus better + * emulate a real system. Examples of state that might be useful to save are + * the emulated GPIOs pin settings, flash memory contents and TPM private + * data. U-Boot memory contents is dealth with separately since it is large + * and it is not normally useful to save it (since a normal system does not + * preserve DRAM between runs). See the '-m' option for this. + * + * See struct sandbox_state_io above for member documentation. + */ +#define SANDBOX_STATE_IO(_name, _compat, _read, _write) \ + ll_entry_declare(struct sandbox_state_io, _name, state_io) = { \ + .name = __stringify(_name), \ + .read = _read, \ + .write = _write, \ + .compat = _compat, \ + } + +/** + * Gets a pointer to the current state. + * + * @return pointer to state + */ +struct sandbox_state *state_get_current(void); + +/** + * Read the sandbox state from the supplied device tree file + * + * This calls all registered state handlers to read in the sandbox state + * from a previous test run. + * + * @param state Sandbox state to update + * @param fname Filename of device tree file to read from + * @return 0 if OK, -ve on error + */ +int sandbox_read_state(struct sandbox_state *state, const char *fname); + +/** + * Write the sandbox state to the supplied device tree file + * + * This calls all registered state handlers to write out the sandbox state + * so that it can be preserved for a future test run. + * + * If the file exists it is overwritten. + * + * @param state Sandbox state to update + * @param fname Filename of device tree file to write to + * @return 0 if OK, -ve on error + */ +int sandbox_write_state(struct sandbox_state *state, const char *fname); + +/** + * Add a property to a sandbox state node + * + * This is equivalent to fdt_setprop except that it automatically enlarges + * the device tree if necessary. That means it is safe to write any amount + * of data here. + * + * This function can only be called from within struct sandbox_state_io's + * ->write method, i.e. within state I/O drivers. + * + * @param node Device tree node to write to + * @param prop_name Property to write + * @param data Data to write into property + * @param size Size of data to write into property + */ +int state_setprop(int node, const char *prop_name, const void *data, int size); + +/** + * Control skipping of time delays + * + * Some tests have unnecessay time delays (e.g. USB). Allow these to be + * skipped to speed up testing + * + * @param skip_delays true to skip delays from now on, false to honour delay + * requests + */ +void state_set_skip_delays(bool skip_delays); + +/** + * See if delays should be skipped + * + * @return true if delays should be skipped, false if they should be honoured + */ +bool state_get_skip_delays(void); + +/** + * state_reset_for_test() - Reset ready to re-run tests + * + * This clears out any test state ready for another test run. + */ +void state_reset_for_test(struct sandbox_state *state); + +/** + * state_show() - Show information about the sandbox state + * + * @param state Sandbox state to show + */ +void state_show(struct sandbox_state *state); + +/** + * Initialize the test system state + */ +int state_init(void); + +/** + * Uninitialize the test system state, writing out state if configured to + * do so. + * + * @return 0 if OK, -ve on error + */ +int state_uninit(void); + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/string.h b/roms/u-boot/arch/sandbox/include/asm/string.h new file mode 100644 index 000000000..32685b317 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/string.h @@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2011 The Chromium OS Authors. + */ + +#include <linux/string.h> diff --git a/roms/u-boot/arch/sandbox/include/asm/system.h b/roms/u-boot/arch/sandbox/include/asm/system.h new file mode 100644 index 000000000..7933b6292 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/system.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2011 The Chromium OS Authors. + */ + +#ifndef __ASM_SANDBOX_SYSTEM_H +#define __ASM_SANDBOX_SYSTEM_H + +/* Define this as nops for sandbox architecture */ +#define local_irq_save(x) +#define local_irq_enable() +#define local_irq_disable() +#define local_save_flags(x) +#define local_irq_restore(x) + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/test.h b/roms/u-boot/arch/sandbox/include/asm/test.h new file mode 100644 index 000000000..1cb960ac2 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/test.h @@ -0,0 +1,278 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Test-related constants for sandbox + * + * Copyright (c) 2014 Google, Inc + */ + +#ifndef __ASM_TEST_H +#define __ASM_TEST_H + +/* The sandbox driver always permits an I2C device with this address */ +#define SANDBOX_I2C_TEST_ADDR 0x59 + +#define SANDBOX_PCI_VENDOR_ID 0x1234 +#define SANDBOX_PCI_SWAP_CASE_EMUL_ID 0x5678 +#define SANDBOX_PCI_PMC_EMUL_ID 0x5677 +#define SANDBOX_PCI_P2SB_EMUL_ID 0x5676 +#define SANDBOX_PCI_CLASS_CODE PCI_CLASS_CODE_COMM +#define SANDBOX_PCI_CLASS_SUB_CODE PCI_CLASS_SUB_CODE_COMM_SERIAL + +#define PCI_CAP_ID_PM_OFFSET 0x50 +#define PCI_CAP_ID_EXP_OFFSET 0x60 +#define PCI_CAP_ID_MSIX_OFFSET 0x70 +#define PCI_CAP_ID_EA_OFFSET 0x80 + +#define PCI_EXT_CAP_ID_ERR_OFFSET 0x100 +#define PCI_EXT_CAP_ID_VC_OFFSET 0x200 +#define PCI_EXT_CAP_ID_DSN_OFFSET 0x300 + +/* Useful for PCI_VDEVICE() macro */ +#define PCI_VENDOR_ID_SANDBOX SANDBOX_PCI_VENDOR_ID +#define SWAP_CASE_DRV_DATA 0x55aa + +#define SANDBOX_CLK_RATE 32768 + +/* Macros used to test PCI EA capability structure */ +#define PCI_CAP_EA_BASE_LO0 0x00100000 +#define PCI_CAP_EA_BASE_LO1 0x00110000 +#define PCI_CAP_EA_BASE_LO2 0x00120000 +#define PCI_CAP_EA_BASE_LO4 0x00140000 +#define PCI_CAP_EA_BASE_HI2 0x00020000ULL +#define PCI_CAP_EA_BASE_HI4 0x00040000ULL +#define PCI_CAP_EA_SIZE_LO 0x0000ffff +#define PCI_CAP_EA_SIZE_HI 0x00000010ULL +#define PCI_EA_BAR2_MAGIC 0x72727272 +#define PCI_EA_BAR4_MAGIC 0x74747474 + +enum { + SANDBOX_IRQN_PEND = 1, /* Interrupt number for 'pending' test */ +}; + +/* System controller driver data */ +enum { + SYSCON0 = 32, + SYSCON1, + + SYSCON_COUNT +}; + +/** + */ +enum cros_ec_test_t { + CROSECT_BREAK_HELLO = BIT(1), + CROSECT_LID_OPEN = BIT(2), +}; + +/** + * sandbox_i2c_set_test_mode() - set test mode for running unit tests + * + * See sandbox_i2c_xfer() for the behaviour changes. + * + * @bus: sandbox I2C bus to adjust + * @test_mode: true to select test mode, false to run normally + */ +void sandbox_i2c_set_test_mode(struct udevice *bus, bool test_mode); + +enum sandbox_i2c_eeprom_test_mode { + SIE_TEST_MODE_NONE, + /* Permits read/write of only one byte per I2C transaction */ + SIE_TEST_MODE_SINGLE_BYTE, +}; + +void sandbox_i2c_eeprom_set_test_mode(struct udevice *dev, + enum sandbox_i2c_eeprom_test_mode mode); + +void sandbox_i2c_eeprom_set_offset_len(struct udevice *dev, int offset_len); + +void sandbox_i2c_eeprom_set_chip_addr_offset_mask(struct udevice *dev, + uint mask); + +uint sanbox_i2c_eeprom_get_prev_addr(struct udevice *dev); + +uint sanbox_i2c_eeprom_get_prev_offset(struct udevice *dev); + +/** + * sandbox_i2c_rtc_set_offset() - set the time offset from system/base time + * + * @dev: RTC device to adjust + * @use_system_time: true to use system time, false to use @base_time + * @offset: RTC offset from current system/base time (-1 for no + * change) + * @return old value of RTC offset + */ +long sandbox_i2c_rtc_set_offset(struct udevice *dev, bool use_system_time, + int offset); + +/** + * sandbox_i2c_rtc_get_set_base_time() - get and set the base time + * + * @dev: RTC device to adjust + * @base_time: New base system time (set to -1 for no change) + * @return old base time + */ +long sandbox_i2c_rtc_get_set_base_time(struct udevice *dev, long base_time); + +int sandbox_usb_keyb_add_string(struct udevice *dev, const char *str); + +/** + * sandbox_osd_get_mem() - get the internal memory of a sandbox OSD + * + * @dev: OSD device for which to access the internal memory for + * @buf: pointer to buffer to receive the OSD memory data + * @buflen: length of buffer in bytes + */ +int sandbox_osd_get_mem(struct udevice *dev, u8 *buf, size_t buflen); + +/** + * sandbox_pwm_get_config() - get the PWM config for a channel + * + * @dev: Device to check + * @channel: Channel number to check + * @period_ns: Period of the PWM in nanoseconds + * @duty_ns: Current duty cycle of the PWM in nanoseconds + * @enable: true if the PWM is enabled + * @polarity: true if the PWM polarity is active high + * @return 0 if OK, -ENOSPC if the PWM number is invalid + */ +int sandbox_pwm_get_config(struct udevice *dev, uint channel, uint *period_nsp, + uint *duty_nsp, bool *enablep, bool *polarityp); + +/** + * sandbox_sf_set_block_protect() - Set the BP bits of the status register + * + * @dev: Device to update + * @bp_mask: BP bits to set (bits 2:0, so a value of 0 to 7) + */ +void sandbox_sf_set_block_protect(struct udevice *dev, int bp_mask); + +/** + * sandbox_get_codec_params() - Read back codec parameters + * + * This reads back the parameters set by audio_codec_set_params() for the + * sandbox audio driver. Arguments are as for that function. + */ +void sandbox_get_codec_params(struct udevice *dev, int *interfacep, int *ratep, + int *mclk_freqp, int *bits_per_samplep, + uint *channelsp); + +/** + * sandbox_get_i2s_sum() - Read back the sum of the audio data so far + * + * This data is provided to the sandbox driver by the I2S tx_data() method. + * + * @dev: Device to check + * @return sum of audio data + */ +int sandbox_get_i2s_sum(struct udevice *dev); + +/** + * sandbox_get_setup_called() - Returns the number of times setup(*) was called + * + * This is used in the sound test + * + * @dev: Device to check + * @return call count for the setup() method + */ +int sandbox_get_setup_called(struct udevice *dev); + +/** + * sandbox_get_sound_active() - Returns whether sound play is in progress + * + * @return true if active, false if not + */ +int sandbox_get_sound_active(struct udevice *dev); + +/** + * sandbox_get_sound_sum() - Read back the sum of the sound data so far + * + * This data is provided to the sandbox driver by the sound play() method. + * + * @dev: Device to check + * @return sum of audio data + */ +int sandbox_get_sound_sum(struct udevice *dev); + +/** + * sandbox_set_allow_beep() - Set whether the 'beep' interface is supported + * + * @dev: Device to update + * @allow: true to allow the start_beep() method, false to disallow it + */ +void sandbox_set_allow_beep(struct udevice *dev, bool allow); + +/** + * sandbox_get_beep_frequency() - Get the frequency of the current beep + * + * @dev: Device to check + * @return frequency of beep, if there is an active beep, else 0 + */ +int sandbox_get_beep_frequency(struct udevice *dev); + +/** + * sandbox_spi_get_speed() - Get current speed setting of a sandbox spi bus + * + * @dev: Device to check + * @return current bus speed + */ +uint sandbox_spi_get_speed(struct udevice *dev); + +/** + * sandbox_spi_get_mode() - Get current mode setting of a sandbox spi bus + * + * @dev: Device to check + * @return current mode + */ +uint sandbox_spi_get_mode(struct udevice *dev); + +/** + * sandbox_get_pch_spi_protect() - Get the PCI SPI protection status + * + * @dev: Device to check + * @return 0 if not protected, 1 if protected + */ +int sandbox_get_pch_spi_protect(struct udevice *dev); + +/** + * sandbox_get_pci_ep_irq_count() - Get the PCI EP IRQ count + * + * @dev: Device to check + * @return irq count + */ +int sandbox_get_pci_ep_irq_count(struct udevice *dev); + +/** + * sandbox_pci_read_bar() - Read the BAR value for a read_config operation + * + * This is used in PCI emulators to read a base address reset. This has special + * rules because when the register is set to 0xffffffff it can be used to + * discover the type and size of the BAR. + * + * @barval: Current value of the BAR + * @type: Type of BAR (PCI_BASE_ADDRESS_SPACE_IO or + * PCI_BASE_ADDRESS_MEM_TYPE_32) + * @size: Size of BAR in bytes + * @return BAR value to return from emulator + */ +uint sandbox_pci_read_bar(u32 barval, int type, uint size); + +/** + * sandbox_set_enable_memio() - Enable readl/writel() for sandbox + * + * Normally these I/O functions do nothing with sandbox. Certain tests need them + * to work as for other architectures, so this function can be used to enable + * them. + * + * @enable: true to enable, false to disable + */ +void sandbox_set_enable_memio(bool enable); + +/** + * sandbox_cros_ec_set_test_flags() - Set behaviour for testing purposes + * + * @dev: Device to check + * @flags: Flags to control behaviour (CROSECT_...) + */ +void sandbox_cros_ec_set_test_flags(struct udevice *dev, uint flags); + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/types.h b/roms/u-boot/arch/sandbox/include/asm/types.h new file mode 100644 index 000000000..c1a5d2af8 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/types.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2011 The Chromium OS Authors. + */ + +#ifndef __ASM_SANDBOX_TYPES_H +#define __ASM_SANDBOX_TYPES_H + +#include <asm-generic/int-ll64.h> + +typedef unsigned short umode_t; + +/* + * These aren't exported outside the kernel to avoid name space clashes + */ +#ifdef __KERNEL__ + +/* + * Number of bits in a C 'long' on this architecture. + */ +#ifdef CONFIG_PHYS_64BIT +#define BITS_PER_LONG 64 +#else /* CONFIG_PHYS_64BIT */ +#define BITS_PER_LONG 32 +#endif /* CONFIG_PHYS_64BIT */ + +#ifdef CONFIG_PHYS_64BIT +typedef unsigned long long dma_addr_t; +typedef u64 phys_addr_t; +typedef u64 phys_size_t; +#else /* CONFIG_PHYS_64BIT */ +typedef unsigned long dma_addr_t; +typedef u32 phys_addr_t; +typedef u32 phys_size_t; +#endif /* CONFIG_PHYS_64BIT */ + +#endif /* __KERNEL__ */ + +#endif diff --git a/roms/u-boot/arch/sandbox/include/asm/u-boot-sandbox.h b/roms/u-boot/arch/sandbox/include/asm/u-boot-sandbox.h new file mode 100644 index 000000000..73b189719 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/u-boot-sandbox.h @@ -0,0 +1,100 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2011 The Chromium OS Authors. + * + * (C) Copyright 2002 + * Sysgo Real-Time Solutions, GmbH <www.elinos.com> + * Marius Groeger <mgroeger@sysgo.de> + * + * (C) Copyright 2002 + * Sysgo Real-Time Solutions, GmbH <www.elinos.com> + * Alex Zuepke <azu@sysgo.de> + */ + +#ifndef _U_BOOT_SANDBOX_H_ +#define _U_BOOT_SANDBOX_H_ + +/* board/.../... */ +int board_init(void); + +/* start.c */ +int sandbox_early_getopt_check(void); +int sandbox_main_loop_init(void); + +int cleanup_before_linux(void); + +/* drivers/video/sandbox_sdl.c */ +int sandbox_lcd_sdl_early_init(void); + +struct udevice; + +/** + * pci_map_physmem() - map a PCI device into memory + * + * This is used on sandbox to map a device into memory so that it can be + * used with normal memory access. After this call, some part of the device's + * internal structure becomes visible. + * + * This function is normally called from sandbox's map_sysmem() automatically. + * + * @paddr: Physical memory address, normally corresponding to a PCI BAR + * @lenp: On entry, the size of the area to map, On exit it is updated + * to the size actually mapped, which may be less if the device + * has less space + * @devp: Returns the device which mapped into this space + * @ptrp: Returns a pointer to the mapped address. The device's space + * can be accessed as @lenp bytes starting here + * @return 0 if OK, -ve on error + */ +int pci_map_physmem(phys_addr_t paddr, unsigned long *lenp, + struct udevice **devp, void **ptrp); + +/** + * pci_unmap_physmem() - undo a memory mapping + * + * This must be called after pci_map_physmem() to undo the mapping. + * + * @paddr: Physical memory address, as passed to pci_map_physmem() + * @len: Size of area mapped, as returned by pci_map_physmem() + * @dev: Device to unmap, as returned by pci_map_physmem() + * @return 0 if OK, -ve on error + */ +int pci_unmap_physmem(const void *addr, unsigned long len, + struct udevice *dev); + +/** + * sandbox_set_enable_pci_map() - Enable / disable PCI address mapping + * + * Since address mapping involves calling every driver, provide a way to + * enable and disable this. It can be handled automatically by the emulator + * uclass, which knows if any emulators are currently active. + * + * If this is disabled, pci_map_physmem() will not be called from + * map_sysmem(). + * + * @enable: 0 to disable, 1 to enable + */ +void sandbox_set_enable_pci_map(int enable); + +/** + * sandbox_read_fdt_from_file() - Read a device tree from a file + * + * Read a device tree file from a host file and set it up for use as the + * control FDT. + */ +int sandbox_read_fdt_from_file(void); + +/** + * sandbox_reset() - reset sandbox + * + * This functions implements the cold reboot of the sandbox. It relaunches the + * U-Boot binary with the same command line parameters as the original call. + * The PID of the process stays the same. All file descriptors that have not + * been opened with O_CLOEXEC stay open including stdin, stdout, stderr. + */ +void sandbox_reset(void); + +/* Exit sandbox (quit U-Boot) */ +void sandbox_exit(void); + +#endif /* _U_BOOT_SANDBOX_H_ */ diff --git a/roms/u-boot/arch/sandbox/include/asm/u-boot.h b/roms/u-boot/arch/sandbox/include/asm/u-boot.h new file mode 100644 index 000000000..34fcb7149 --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/u-boot.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * (C) Copyright 2002 + * Sysgo Real-Time Solutions, GmbH <www.elinos.com> + * Marius Groeger <mgroeger@sysgo.de> + * + * (C) Copyright 2002 + * Sysgo Real-Time Solutions, GmbH <www.elinos.com> + * Alex Zuepke <azu@sysgo.de> + * + ******************************************************************** + * NOTE: This header file defines an interface to U-Boot. Including + * this (unmodified) header file in another file is considered normal + * use of U-Boot, and does *not* fall under the heading of "derived + * work". + ******************************************************************** + */ + +#ifndef _U_BOOT_H_ +#define _U_BOOT_H_ 1 + +/* Use the generic board which requires a unified bd_info */ +#include <asm-generic/u-boot.h> +#include <asm/u-boot-sandbox.h> + +/* For image.h:image_check_target_arch() */ +#define IH_ARCH_DEFAULT IH_ARCH_SANDBOX + +#endif /* _U_BOOT_H_ */ diff --git a/roms/u-boot/arch/sandbox/include/asm/unaligned.h b/roms/u-boot/arch/sandbox/include/asm/unaligned.h new file mode 100644 index 000000000..2cb2a17fa --- /dev/null +++ b/roms/u-boot/arch/sandbox/include/asm/unaligned.h @@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2011 The Chromium OS Authors. + */ + +#include <asm-generic/unaligned.h> |