blob: 0e8d19ce23253939862b1c7e3ba787c8288f1ed8 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass45be32c2014-12-10 08:55:51 -07002/*
3 * Test-related constants for sandbox
4 *
5 * Copyright (c) 2014 Google, Inc
Simon Glass45be32c2014-12-10 08:55:51 -07006 */
7
8#ifndef __ASM_TEST_H
9#define __ASM_TEST_H
10
Pali Rohár417ae2c2022-02-18 13:16:18 +010011#include <pci_ids.h>
Simon Glassc3b5adf2021-11-19 13:23:50 -070012
Simon Glass57b00a92022-09-06 20:27:10 -060013struct unit_test_state;
14
Simon Glass45be32c2014-12-10 08:55:51 -070015/* The sandbox driver always permits an I2C device with this address */
Simon Glass70778bc2015-03-05 12:25:26 -070016#define SANDBOX_I2C_TEST_ADDR 0x59
17
18#define SANDBOX_PCI_VENDOR_ID 0x1234
Simon Glass21c8f1a2019-09-25 08:56:01 -060019#define SANDBOX_PCI_SWAP_CASE_EMUL_ID 0x5678
Simon Glass8c501022019-12-06 21:41:54 -070020#define SANDBOX_PCI_PMC_EMUL_ID 0x5677
Simon Glass937bb472019-12-06 21:41:57 -070021#define SANDBOX_PCI_P2SB_EMUL_ID 0x5676
Pali Rohár417ae2c2022-02-18 13:16:18 +010022#define SANDBOX_PCI_CLASS_CODE (PCI_CLASS_COMMUNICATION_SERIAL >> 8)
23#define SANDBOX_PCI_CLASS_SUB_CODE (PCI_CLASS_COMMUNICATION_SERIAL & 0xff)
Simon Glass45be32c2014-12-10 08:55:51 -070024
Bin Mengd74d3122018-08-03 01:14:53 -070025#define PCI_CAP_ID_PM_OFFSET 0x50
26#define PCI_CAP_ID_EXP_OFFSET 0x60
27#define PCI_CAP_ID_MSIX_OFFSET 0x70
Alex Margineanf1274432019-06-07 11:24:24 +030028#define PCI_CAP_ID_EA_OFFSET 0x80
Bin Mengd74d3122018-08-03 01:14:53 -070029
30#define PCI_EXT_CAP_ID_ERR_OFFSET 0x100
31#define PCI_EXT_CAP_ID_VC_OFFSET 0x200
32#define PCI_EXT_CAP_ID_DSN_OFFSET 0x300
33
Bin Mengc69ae412018-08-03 01:14:46 -070034/* Useful for PCI_VDEVICE() macro */
35#define PCI_VENDOR_ID_SANDBOX SANDBOX_PCI_VENDOR_ID
36#define SWAP_CASE_DRV_DATA 0x55aa
37
Simon Glass8cc4d822015-07-06 12:54:24 -060038#define SANDBOX_CLK_RATE 32768
39
Alex Margineanf1274432019-06-07 11:24:24 +030040/* Macros used to test PCI EA capability structure */
41#define PCI_CAP_EA_BASE_LO0 0x00100000
42#define PCI_CAP_EA_BASE_LO1 0x00110000
43#define PCI_CAP_EA_BASE_LO2 0x00120000
44#define PCI_CAP_EA_BASE_LO4 0x00140000
45#define PCI_CAP_EA_BASE_HI2 0x00020000ULL
46#define PCI_CAP_EA_BASE_HI4 0x00040000ULL
47#define PCI_CAP_EA_SIZE_LO 0x0000ffff
48#define PCI_CAP_EA_SIZE_HI 0x00000010ULL
49#define PCI_EA_BAR2_MAGIC 0x72727272
50#define PCI_EA_BAR4_MAGIC 0x74747474
51
Sughosh Ganu0c0ed2b2024-08-26 17:29:36 +053052/* Used by the sandbox iommu driver */
53#define SANDBOX_IOMMU_DVA_ADDR 0x89abc000
54#define SANDBOX_IOMMU_PAGE_SIZE SZ_4K
55
Simon Glassa847b272020-02-06 09:54:57 -070056enum {
57 SANDBOX_IRQN_PEND = 1, /* Interrupt number for 'pending' test */
58};
59
Simon Glasscd556522015-07-06 12:54:35 -060060/* System controller driver data */
61enum {
62 SYSCON0 = 32,
63 SYSCON1,
64
65 SYSCON_COUNT
66};
67
Simon Glass4c70ed92015-04-20 12:37:15 -060068/**
Simon Glass9b306e52021-01-16 14:52:22 -070069 */
70enum cros_ec_test_t {
71 CROSECT_BREAK_HELLO = BIT(1),
Simon Glass9d702522021-01-16 14:52:28 -070072 CROSECT_LID_OPEN = BIT(2),
Simon Glass9b306e52021-01-16 14:52:22 -070073};
74
75/**
Simon Glass4c70ed92015-04-20 12:37:15 -060076 * sandbox_i2c_set_test_mode() - set test mode for running unit tests
77 *
78 * See sandbox_i2c_xfer() for the behaviour changes.
79 *
80 * @bus: sandbox I2C bus to adjust
81 * @test_mode: true to select test mode, false to run normally
82 */
83void sandbox_i2c_set_test_mode(struct udevice *bus, bool test_mode);
84
Simon Glass45be32c2014-12-10 08:55:51 -070085enum sandbox_i2c_eeprom_test_mode {
86 SIE_TEST_MODE_NONE,
87 /* Permits read/write of only one byte per I2C transaction */
88 SIE_TEST_MODE_SINGLE_BYTE,
89};
90
91void sandbox_i2c_eeprom_set_test_mode(struct udevice *dev,
92 enum sandbox_i2c_eeprom_test_mode mode);
93
94void sandbox_i2c_eeprom_set_offset_len(struct udevice *dev, int offset_len);
95
Robert Beckettf695f6e2019-10-28 17:44:59 +000096void sandbox_i2c_eeprom_set_chip_addr_offset_mask(struct udevice *dev,
97 uint mask);
98
Robert Beckett1fe8a492019-10-28 17:44:58 +000099uint sanbox_i2c_eeprom_get_prev_addr(struct udevice *dev);
100
101uint sanbox_i2c_eeprom_get_prev_offset(struct udevice *dev);
102
Simon Glassc404aa62015-04-20 12:37:24 -0600103/**
104 * sandbox_i2c_rtc_set_offset() - set the time offset from system/base time
105 *
106 * @dev: RTC device to adjust
107 * @use_system_time: true to use system time, false to use @base_time
108 * @offset: RTC offset from current system/base time (-1 for no
109 * change)
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100110 * Return: old value of RTC offset
Simon Glassc404aa62015-04-20 12:37:24 -0600111 */
112long sandbox_i2c_rtc_set_offset(struct udevice *dev, bool use_system_time,
113 int offset);
114
115/**
116 * sandbox_i2c_rtc_get_set_base_time() - get and set the base time
117 *
118 * @dev: RTC device to adjust
119 * @base_time: New base system time (set to -1 for no change)
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100120 * Return: old base time
Simon Glassc404aa62015-04-20 12:37:24 -0600121 */
122long sandbox_i2c_rtc_get_set_base_time(struct udevice *dev, long base_time);
123
Simon Glassbe4ebd12015-11-08 23:48:06 -0700124int sandbox_usb_keyb_add_string(struct udevice *dev, const char *str);
125
Mario Six02ad6fb2018-09-27 09:19:31 +0200126/**
127 * sandbox_osd_get_mem() - get the internal memory of a sandbox OSD
128 *
129 * @dev: OSD device for which to access the internal memory for
130 * @buf: pointer to buffer to receive the OSD memory data
131 * @buflen: length of buffer in bytes
132 */
133int sandbox_osd_get_mem(struct udevice *dev, u8 *buf, size_t buflen);
Simon Glass5620cf82018-10-01 12:22:40 -0600134
135/**
136 * sandbox_pwm_get_config() - get the PWM config for a channel
137 *
138 * @dev: Device to check
139 * @channel: Channel number to check
140 * @period_ns: Period of the PWM in nanoseconds
141 * @duty_ns: Current duty cycle of the PWM in nanoseconds
142 * @enable: true if the PWM is enabled
143 * @polarity: true if the PWM polarity is active high
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100144 * Return: 0 if OK, -ENOSPC if the PWM number is invalid
Simon Glass5620cf82018-10-01 12:22:40 -0600145 */
146int sandbox_pwm_get_config(struct udevice *dev, uint channel, uint *period_nsp,
147 uint *duty_nsp, bool *enablep, bool *polarityp);
148
Simon Glass36eee8c2018-11-06 15:21:41 -0700149/**
150 * sandbox_sf_set_block_protect() - Set the BP bits of the status register
151 *
152 * @dev: Device to update
153 * @bp_mask: BP bits to set (bits 2:0, so a value of 0 to 7)
154 */
155void sandbox_sf_set_block_protect(struct udevice *dev, int bp_mask);
156
Simon Glassed96cde2018-12-10 10:37:33 -0700157/**
158 * sandbox_get_codec_params() - Read back codec parameters
159 *
160 * This reads back the parameters set by audio_codec_set_params() for the
161 * sandbox audio driver. Arguments are as for that function.
162 */
163void sandbox_get_codec_params(struct udevice *dev, int *interfacep, int *ratep,
164 int *mclk_freqp, int *bits_per_samplep,
165 uint *channelsp);
166
Simon Glassc953aaf2018-12-10 10:37:34 -0700167/**
168 * sandbox_get_i2s_sum() - Read back the sum of the audio data so far
169 *
170 * This data is provided to the sandbox driver by the I2S tx_data() method.
171 *
172 * @dev: Device to check
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100173 * Return: sum of audio data
Simon Glassc953aaf2018-12-10 10:37:34 -0700174 */
175int sandbox_get_i2s_sum(struct udevice *dev);
176
Simon Glass76072ac2018-12-10 10:37:36 -0700177/**
178 * sandbox_get_setup_called() - Returns the number of times setup(*) was called
179 *
180 * This is used in the sound test
181 *
182 * @dev: Device to check
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100183 * Return: call count for the setup() method
Simon Glass76072ac2018-12-10 10:37:36 -0700184 */
185int sandbox_get_setup_called(struct udevice *dev);
186
187/**
Simon Glass70bc14b2020-02-03 07:36:06 -0700188 * sandbox_get_sound_active() - Returns whether sound play is in progress
189 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100190 * Return: true if active, false if not
Simon Glass70bc14b2020-02-03 07:36:06 -0700191 */
192int sandbox_get_sound_active(struct udevice *dev);
193
194/**
Heinrich Schuchardt707a6fc2022-12-04 17:11:41 +0100195 * sandbox_get_sound_count() - Read back the count of the sound data so far
196 *
197 * This data is provided to the sandbox driver by the sound play() method.
198 *
199 * @dev: Device to check
200 * Return: count of audio data
201 */
202int sandbox_get_sound_count(struct udevice *dev);
203
204/**
Simon Glass76072ac2018-12-10 10:37:36 -0700205 * sandbox_get_sound_sum() - Read back the sum of the sound data so far
206 *
207 * This data is provided to the sandbox driver by the sound play() method.
208 *
209 * @dev: Device to check
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100210 * Return: sum of audio data
Simon Glass76072ac2018-12-10 10:37:36 -0700211 */
212int sandbox_get_sound_sum(struct udevice *dev);
213
Simon Glass53a68b32019-02-16 20:24:50 -0700214/**
Simon Glassecd02e72019-02-16 20:24:54 -0700215 * sandbox_set_allow_beep() - Set whether the 'beep' interface is supported
216 *
217 * @dev: Device to update
218 * @allow: true to allow the start_beep() method, false to disallow it
219 */
220void sandbox_set_allow_beep(struct udevice *dev, bool allow);
221
222/**
223 * sandbox_get_beep_frequency() - Get the frequency of the current beep
224 *
225 * @dev: Device to check
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100226 * Return: frequency of beep, if there is an active beep, else 0
Simon Glassecd02e72019-02-16 20:24:54 -0700227 */
228int sandbox_get_beep_frequency(struct udevice *dev);
229
230/**
Ovidiu Panaita2c9d012020-12-14 19:06:49 +0200231 * sandbox_spi_get_speed() - Get current speed setting of a sandbox spi bus
232 *
233 * @dev: Device to check
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100234 * Return: current bus speed
Ovidiu Panaita2c9d012020-12-14 19:06:49 +0200235 */
236uint sandbox_spi_get_speed(struct udevice *dev);
237
238/**
239 * sandbox_spi_get_mode() - Get current mode setting of a sandbox spi bus
240 *
241 * @dev: Device to check
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100242 * Return: current mode
Ovidiu Panaita2c9d012020-12-14 19:06:49 +0200243 */
244uint sandbox_spi_get_mode(struct udevice *dev);
245
246/**
Simon Glass53a68b32019-02-16 20:24:50 -0700247 * sandbox_get_pch_spi_protect() - Get the PCI SPI protection status
248 *
249 * @dev: Device to check
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100250 * Return: 0 if not protected, 1 if protected
Simon Glass53a68b32019-02-16 20:24:50 -0700251 */
252int sandbox_get_pch_spi_protect(struct udevice *dev);
253
Ramon Friedafdb3422019-04-27 11:15:24 +0300254/**
255 * sandbox_get_pci_ep_irq_count() - Get the PCI EP IRQ count
256 *
257 * @dev: Device to check
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100258 * Return: irq count
Ramon Friedafdb3422019-04-27 11:15:24 +0300259 */
260int sandbox_get_pci_ep_irq_count(struct udevice *dev);
261
Simon Glass72231f72019-09-25 08:56:42 -0600262/**
263 * sandbox_pci_read_bar() - Read the BAR value for a read_config operation
264 *
265 * This is used in PCI emulators to read a base address reset. This has special
266 * rules because when the register is set to 0xffffffff it can be used to
267 * discover the type and size of the BAR.
268 *
269 * @barval: Current value of the BAR
270 * @type: Type of BAR (PCI_BASE_ADDRESS_SPACE_IO or
271 * PCI_BASE_ADDRESS_MEM_TYPE_32)
272 * @size: Size of BAR in bytes
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100273 * Return: BAR value to return from emulator
Simon Glass72231f72019-09-25 08:56:42 -0600274 */
275uint sandbox_pci_read_bar(u32 barval, int type, uint size);
276
Simon Glassc667fb02019-10-11 16:16:48 -0600277/**
278 * sandbox_set_enable_memio() - Enable readl/writel() for sandbox
279 *
280 * Normally these I/O functions do nothing with sandbox. Certain tests need them
281 * to work as for other architectures, so this function can be used to enable
282 * them.
283 *
284 * @enable: true to enable, false to disable
285 */
286void sandbox_set_enable_memio(bool enable);
287
Simon Glass9b306e52021-01-16 14:52:22 -0700288/**
289 * sandbox_cros_ec_set_test_flags() - Set behaviour for testing purposes
290 *
291 * @dev: Device to check
292 * @flags: Flags to control behaviour (CROSECT_...)
293 */
294void sandbox_cros_ec_set_test_flags(struct udevice *dev, uint flags);
295
Alper Nebi Yasak8a8cd4f2021-05-19 19:33:31 +0300296/**
297 * sandbox_cros_ec_get_pwm_duty() - Get EC PWM config for testing purposes
298 *
299 * @dev: Device to check
300 * @index: PWM channel index
301 * @duty: Current duty cycle in 0..EC_PWM_MAX_DUTY range.
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100302 * Return: 0 if OK, -ENOSPC if the PWM number is invalid
Alper Nebi Yasak8a8cd4f2021-05-19 19:33:31 +0300303 */
304int sandbox_cros_ec_get_pwm_duty(struct udevice *dev, uint index, uint *duty);
305
Simon Glass161e1e32022-07-30 15:52:22 -0600306/**
307 * sandbox_set_fake_efi_mgr_dev() - Control EFI bootmgr producing valid bootflow
308 *
309 * This is only used for testing.
310 *
311 * @dev: efi_mgr bootmeth device
312 * @fake_dev: true to produce a valid bootflow when requested, false to produce
313 * an error
314 */
315void sandbox_set_fake_efi_mgr_dev(struct udevice *dev, bool fake_dev);
316
Simon Glass57b00a92022-09-06 20:27:10 -0600317/**
318 * sandbox_load_other_fdt() - load the 'other' FDT into the test state
319 *
320 * This copies the other.dtb file into the test state, so that a fresh version
321 * can be used for a test that is about to run.
322 *
323 * If @uts->other_fdt is NULL, as it is when first set up, this allocates a
324 * buffer for the other FDT and sets @uts->other_fdt_size to its size.
325 *
326 * In any case, the other FDT is copied from the sandbox state into
327 * @uts->other_fdt ready for use.
328 *
329 * @uts: Unit test state
330 * @return 0 if OK, -ve on error
331 */
332int sandbox_load_other_fdt(void **fdtp, int *sizep);
333
Simon Glass66014cc2023-01-17 10:47:27 -0700334/**
335 * sandbox_set_eth_enable() - Enable / disable Ethernet
336 *
337 * Allows control of whether Ethernet packets are actually send/received
338 *
339 * @enable: true to enable Ethernet, false to disable
340 */
341void sandbox_set_eth_enable(bool enable);
342
343/**
344 * sandbox_eth_enabled() - Check if Ethernet is enabled
345 *
346 * Returns: true if Ethernet is enabled on sandbox, False if not
347 */
348bool sandbox_eth_enabled(void);
349
Simon Glass4937be02023-01-17 10:48:02 -0700350/**
351 * sandbox_sf_bootdev_enabled() - Check if SPI flash bootdevs should be bound
352 *
353 * Returns: true if sandbox should bind bootdevs for SPI flash, false if not
354 */
355bool sandbox_sf_bootdev_enabled(void);
356
357/**
358 * sandbox_sf_set_enable_bootdevs() - Enable / disable the SPI flash bootdevs
359 *
360 * @enable: true to bind the SPI flash bootdevs, false to skip
361 */
362void sandbox_sf_set_enable_bootdevs(bool enable);
363
Simon Glass45be32c2014-12-10 08:55:51 -0700364#endif