"Das U-Boot" Source Tree
1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Test-related constants for sandbox
4 *
5 * Copyright (c) 2014 Google, Inc
6 */
7
8#ifndef __ASM_TEST_H
9#define __ASM_TEST_H
10
11#include <pci_ids.h>
12
13struct unit_test_state;
14
15/* The sandbox driver always permits an I2C device with this address */
16#define SANDBOX_I2C_TEST_ADDR 0x59
17
18#define SANDBOX_PCI_VENDOR_ID 0x1234
19#define SANDBOX_PCI_SWAP_CASE_EMUL_ID 0x5678
20#define SANDBOX_PCI_PMC_EMUL_ID 0x5677
21#define SANDBOX_PCI_P2SB_EMUL_ID 0x5676
22#define SANDBOX_PCI_CLASS_CODE (PCI_CLASS_COMMUNICATION_SERIAL >> 8)
23#define SANDBOX_PCI_CLASS_SUB_CODE (PCI_CLASS_COMMUNICATION_SERIAL & 0xff)
24
25#define PCI_CAP_ID_PM_OFFSET 0x50
26#define PCI_CAP_ID_EXP_OFFSET 0x60
27#define PCI_CAP_ID_MSIX_OFFSET 0x70
28#define PCI_CAP_ID_EA_OFFSET 0x80
29
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
34/* Useful for PCI_VDEVICE() macro */
35#define PCI_VENDOR_ID_SANDBOX SANDBOX_PCI_VENDOR_ID
36#define SWAP_CASE_DRV_DATA 0x55aa
37
38#define SANDBOX_CLK_RATE 32768
39
40/* 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
52/* Used by the sandbox iommu driver */
53#define SANDBOX_IOMMU_DVA_ADDR 0x89abc000
54#define SANDBOX_IOMMU_PAGE_SIZE SZ_4K
55
56enum {
57 SANDBOX_IRQN_PEND = 1, /* Interrupt number for 'pending' test */
58};
59
60/* System controller driver data */
61enum {
62 SYSCON0 = 32,
63 SYSCON1,
64
65 SYSCON_COUNT
66};
67
68/**
69 */
70enum cros_ec_test_t {
71 CROSECT_BREAK_HELLO = BIT(1),
72 CROSECT_LID_OPEN = BIT(2),
73};
74
75/**
76 * 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
85enum 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
96void sandbox_i2c_eeprom_set_chip_addr_offset_mask(struct udevice *dev,
97 uint mask);
98
99uint sanbox_i2c_eeprom_get_prev_addr(struct udevice *dev);
100
101uint sanbox_i2c_eeprom_get_prev_offset(struct udevice *dev);
102
103/**
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)
110 * Return: old value of RTC offset
111 */
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)
120 * Return: old base time
121 */
122long sandbox_i2c_rtc_get_set_base_time(struct udevice *dev, long base_time);
123
124int sandbox_usb_keyb_add_string(struct udevice *dev, const char *str);
125
126/**
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);
134
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
144 * Return: 0 if OK, -ENOSPC if the PWM number is invalid
145 */
146int sandbox_pwm_get_config(struct udevice *dev, uint channel, uint *period_nsp,
147 uint *duty_nsp, bool *enablep, bool *polarityp);
148
149/**
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
157/**
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
167/**
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
173 * Return: sum of audio data
174 */
175int sandbox_get_i2s_sum(struct udevice *dev);
176
177/**
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
183 * Return: call count for the setup() method
184 */
185int sandbox_get_setup_called(struct udevice *dev);
186
187/**
188 * sandbox_get_sound_active() - Returns whether sound play is in progress
189 *
190 * Return: true if active, false if not
191 */
192int sandbox_get_sound_active(struct udevice *dev);
193
194/**
195 * 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/**
205 * 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
210 * Return: sum of audio data
211 */
212int sandbox_get_sound_sum(struct udevice *dev);
213
214/**
215 * 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
226 * Return: frequency of beep, if there is an active beep, else 0
227 */
228int sandbox_get_beep_frequency(struct udevice *dev);
229
230/**
231 * sandbox_spi_get_speed() - Get current speed setting of a sandbox spi bus
232 *
233 * @dev: Device to check
234 * Return: current bus speed
235 */
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
242 * Return: current mode
243 */
244uint sandbox_spi_get_mode(struct udevice *dev);
245
246/**
247 * sandbox_get_pch_spi_protect() - Get the PCI SPI protection status
248 *
249 * @dev: Device to check
250 * Return: 0 if not protected, 1 if protected
251 */
252int sandbox_get_pch_spi_protect(struct udevice *dev);
253
254/**
255 * sandbox_get_pci_ep_irq_count() - Get the PCI EP IRQ count
256 *
257 * @dev: Device to check
258 * Return: irq count
259 */
260int sandbox_get_pci_ep_irq_count(struct udevice *dev);
261
262/**
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
273 * Return: BAR value to return from emulator
274 */
275uint sandbox_pci_read_bar(u32 barval, int type, uint size);
276
277/**
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
288/**
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
296/**
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.
302 * Return: 0 if OK, -ENOSPC if the PWM number is invalid
303 */
304int sandbox_cros_ec_get_pwm_duty(struct udevice *dev, uint index, uint *duty);
305
306/**
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
317/**
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
334/**
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
350/**
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
364#endif