diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/blk.h | 37 | ||||
-rw-r--r-- | include/dm/uclass-id.h | 1 | ||||
-rw-r--r-- | include/os.h | 4 | ||||
-rw-r--r-- | include/sandbox_host.h | 125 | ||||
-rw-r--r-- | include/sandboxblockdev.h | 31 | ||||
-rw-r--r-- | include/test/ut.h | 7 |
6 files changed, 170 insertions, 35 deletions
diff --git a/include/blk.h b/include/blk.h index e854166edb..1db203c1ba 100644 --- a/include/blk.h +++ b/include/blk.h @@ -147,8 +147,8 @@ void blkcache_fill(int iftype, int dev, * blkcache_invalidate() - discard the cache for a set of blocks * because of a write or device (re)initialization. * - * @param iftype - uclass_id_x for type of device - * @param dev - device index of particular type + * @iftype - UCLASS_ID_ for type of device, or -1 for any + * @dev - device index of particular type, if @iftype is not -1 */ void blkcache_invalidate(int iftype, int dev); @@ -178,6 +178,9 @@ struct block_cache_stats { */ void blkcache_stats(struct block_cache_stats *stats); +/** blkcache_free() - free all memory allocated to the block cache */ +void blkcache_free(void); + #else static inline int blkcache_read(int iftype, int dev, @@ -193,6 +196,8 @@ static inline void blkcache_fill(int iftype, int dev, static inline void blkcache_invalidate(int iftype, int dev) {} +static inline void blkcache_free(void) {} + #endif #if CONFIG_IS_ENABLED(BLK) @@ -449,9 +454,35 @@ int blk_next_free_devnum(enum uclass_id uclass_id); int blk_select_hwpart(struct udevice *dev, int hwpart); /** + * blk_find_from_parent() - find a block device by looking up its parent + * + * All block devices have a parent 'media' device which provides the block + * driver for the block device, ensuring that access to the underlying medium + * is available. + * + * The block device is not activated by this function. See + * blk_get_from_parent() for that. + * + * @parent: Media device + * @devp: Returns the associated block device, if any + * Returns: 0 if OK, -ENODEV if @parent is not a media device and has no + * UCLASS_BLK child + */ +int blk_find_from_parent(struct udevice *parent, struct udevice **devp); + +/** * blk_get_from_parent() - obtain a block device by looking up its parent * - * All devices with + * All block devices have a parent 'media' device which provides the block + * driver for the block device, ensuring that access to the underlying medium + * is available. + * + * The block device is probed and ready for use. + * + * @parent: Media device + * @devp: Returns the associated block device, if any + * Returns: 0 if OK, -ENODEV if @parent is not a media device and has no + * UCLASS_BLK child */ int blk_get_from_parent(struct udevice *parent, struct udevice **devp); diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 1f3cf8c085..376f741cc2 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -63,6 +63,7 @@ enum uclass_id { UCLASS_GPIO, /* Bank of general-purpose I/O pins */ UCLASS_HASH, /* Hash device */ UCLASS_HWSPINLOCK, /* Hardware semaphores */ + UCLASS_HOST, /* Sandbox host device */ UCLASS_I2C, /* I2C bus */ UCLASS_I2C_EEPROM, /* I2C EEPROM device */ UCLASS_I2C_GENERIC, /* Generic I2C device */ diff --git a/include/os.h b/include/os.h index 54874f5e0e..0415f0f0e7 100644 --- a/include/os.h +++ b/include/os.h @@ -110,6 +110,10 @@ void os_exit(int exit_code) __attribute__((noreturn)); /** * os_alarm() - access to the OS alarm() system call + * + * @seconds: number of seconds before the signal is sent + * Returns: number of seconds remaining until any previously scheduled alarm was + * due to be delivered; 0 if there was no previously scheduled alarm */ unsigned int os_alarm(unsigned int seconds); diff --git a/include/sandbox_host.h b/include/sandbox_host.h new file mode 100644 index 0000000000..2e37ede235 --- /dev/null +++ b/include/sandbox_host.h @@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * sandbox host uclass + * + * Copyright 2022 Google LLC + */ + +#ifndef __SANDBOX_HOST__ +#define __SANDBOX_HOST__ + +/** + * struct host_sb_plat - platform data for a host device + * + * @label: Label for this device (allocated) + * @filename: Name of file this is attached to, or NULL (allocated) + * @fd: File descriptor of file, or 0 for none (file is not open) + */ +struct host_sb_plat { + char *label; + char *filename; + int fd; +}; + +/** + * struct host_ops - operations supported by UCLASS_HOST + * + * @attach_file: Attach a new file to a device + * @detach_file: Detach a file from a device + */ +struct host_ops { + /* + * attach_file() - Attach a new file to the device + * + * @dev: Device to update + * @filename: Name of the file, e.g. "/path/to/disk.img" + * Returns: 0 if OK, -EEXIST if a file is already attached, other -ve on + * other error + */ + int (*attach_file)(struct udevice *dev, const char *filename); + + /** + * detach_file() - Detach a file from the device + * + * @dev: Device to detach from + * Returns: 0 if OK, -ENOENT if no file is attached, other -ve on other + * error + */ + int (*detach_file)(struct udevice *dev); +}; + +#define host_get_ops(dev) ((struct host_ops *)(dev)->driver->ops) + +/** + * host_attach_file() - Attach a new file to the device + * + * @dev: Device to update + * @filename: Name of the file, e.g. "/path/to/disk.img" + * Returns: 0 if OK, -EEXIST if a file is already attached, other -ve on + * other error + */ +int host_attach_file(struct udevice *dev, const char *filename); + +/** + * host_detach_file() - Detach a file from the device + * + * @dev: Device to detach from + * Returns: 0 if OK, -ENOENT if no file is attached, other -ve on other + * error + */ +int host_detach_file(struct udevice *dev); + +/** + * host_create_device() - Create a new host device + * + * Any existing device with the same label is removed and unbound first + * + * @label: Label of the attachment, e.g. "test1" + * @removable: true if the device should be marked as removable, false + * if it is fixed. See enum blk_flag_t + * @devp: Returns the device created, on success + * Returns: 0 if OK, -ve on error + */ +int host_create_device(const char *label, bool removable, + struct udevice **devp); + +/** + * host_create_attach_file() - Create a new host device attached to a file + * + * @label: Label of the attachment, e.g. "test1" + * @filename: Name of the file, e.g. "/path/to/disk.img" + * @removable: true if the device should be marked as removable, false + * if it is fixed. See enum blk_flag_t + * @devp: Returns the device created, on success + * Returns: 0 if OK, -ve on error + */ +int host_create_attach_file(const char *label, const char *filename, + bool removable, struct udevice **devp); + +/** + * host_find_by_label() - Find a host by label + * + * Searches all host devices to find one with the given label + * + * @label: Label to find + * Returns: associated device, or NULL if not found + */ +struct udevice *host_find_by_label(const char *label); + +/** + * host_get_cur_dev() - Get the current device + * + * Returns current device, or NULL if none + */ +struct udevice *host_get_cur_dev(void); + +/** + * host_set_cur_dev() - Set the current device + * + * Sets the current device, or clears it if @dev is NULL + * + * @dev: Device to set as the current one + */ +void host_set_cur_dev(struct udevice *dev); + +#endif /* __SANDBOX_HOST__ */ diff --git a/include/sandboxblockdev.h b/include/sandboxblockdev.h deleted file mode 100644 index dc983f0417..0000000000 --- a/include/sandboxblockdev.h +++ /dev/null @@ -1,31 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (c) 2013, Henrik Nordstrom <henrik@henriknordstrom.net> - */ - -#ifndef __SANDBOX_BLOCK_DEV__ -#define __SANDBOX_BLOCK_DEV__ - -/* Maximum number of host devices - see drivers/block/sandbox.c */ -#define SANDBOX_HOST_MAX_DEVICES 4 - -struct host_block_dev { -#ifndef CONFIG_BLK - struct blk_desc blk_dev; -#endif - char *filename; - int fd; -}; - -/** - * host_dev_bind() - Bind or unbind a device - * - * @dev: Device number (0=first slot) - * @filename: Host filename to use, or NULL to unbind - * @removable: true if the block device should mark itself as removable - */ -int host_dev_bind(int dev, char *filename, bool removable); - -int host_get_dev_err(int dev, struct blk_desc **blk_devp); - -#endif diff --git a/include/test/ut.h b/include/test/ut.h index e0e618b58c..4d00b4eeca 100644 --- a/include/test/ut.h +++ b/include/test/ut.h @@ -410,10 +410,15 @@ void test_set_state(struct unit_test_state *uts); * then all tests are run * @runs_per_test: Number of times to run each test (typically 1) * @force_run: Run tests that are marked as manual-only (UT_TESTF_MANUAL) + * @test_insert: String describing a test to run after n other tests run, in the + * format n:name where n is the number of tests to run before this one and + * name is the name of the test to run. This is used to find which test causes + * another test to fail. If the one test fails, testing stops immediately. + * Pass NULL to disable this * Return: 0 if all tests passed, -1 if any failed */ int ut_run_list(const char *name, const char *prefix, struct unit_test *tests, int count, const char *select_name, int runs_per_test, - bool force_run); + bool force_run, const char *test_insert); #endif |