Simon Glass | 9bd1aa8 | 2022-10-29 19:47:15 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * sandbox host uclass |
| 4 | * |
| 5 | * Copyright 2022 Google LLC |
| 6 | */ |
| 7 | |
| 8 | #ifndef __SANDBOX_HOST__ |
| 9 | #define __SANDBOX_HOST__ |
| 10 | |
| 11 | /** |
| 12 | * struct host_sb_plat - platform data for a host device |
| 13 | * |
| 14 | * @label: Label for this device (allocated) |
| 15 | * @filename: Name of file this is attached to, or NULL (allocated) |
| 16 | * @fd: File descriptor of file, or 0 for none (file is not open) |
| 17 | */ |
| 18 | struct host_sb_plat { |
| 19 | char *label; |
| 20 | char *filename; |
| 21 | int fd; |
| 22 | }; |
| 23 | |
| 24 | /** |
| 25 | * struct host_ops - operations supported by UCLASS_HOST |
Simon Glass | 9bd1aa8 | 2022-10-29 19:47:15 -0600 | [diff] [blame] | 26 | */ |
| 27 | struct host_ops { |
Heinrich Schuchardt | dd706c8 | 2022-11-14 10:16:02 +0100 | [diff] [blame] | 28 | /** |
| 29 | * @attach_file: - Attach a new file to the device |
Simon Glass | 9bd1aa8 | 2022-10-29 19:47:15 -0600 | [diff] [blame] | 30 | * |
Heinrich Schuchardt | dd706c8 | 2022-11-14 10:16:02 +0100 | [diff] [blame] | 31 | * @attach_file.dev: Device to update |
| 32 | * @attach_file.filename: Name of the file, e.g. "/path/to/disk.img" |
| 33 | * @attach_file.Returns: 0 if OK, -EEXIST if a file is already attached, other -ve on |
Simon Glass | 9bd1aa8 | 2022-10-29 19:47:15 -0600 | [diff] [blame] | 34 | * other error |
| 35 | */ |
| 36 | int (*attach_file)(struct udevice *dev, const char *filename); |
| 37 | |
| 38 | /** |
Heinrich Schuchardt | dd706c8 | 2022-11-14 10:16:02 +0100 | [diff] [blame] | 39 | * @detach_file: - Detach a file from the device |
Simon Glass | 9bd1aa8 | 2022-10-29 19:47:15 -0600 | [diff] [blame] | 40 | * |
Heinrich Schuchardt | dd706c8 | 2022-11-14 10:16:02 +0100 | [diff] [blame] | 41 | * @detach_file.dev: Device to detach from |
| 42 | * @detach_file.Returns: 0 if OK, -ENOENT if no file is attached, other -ve on other |
Simon Glass | 9bd1aa8 | 2022-10-29 19:47:15 -0600 | [diff] [blame] | 43 | * error |
| 44 | */ |
| 45 | int (*detach_file)(struct udevice *dev); |
| 46 | }; |
| 47 | |
| 48 | #define host_get_ops(dev) ((struct host_ops *)(dev)->driver->ops) |
| 49 | |
| 50 | /** |
| 51 | * host_attach_file() - Attach a new file to the device |
| 52 | * |
| 53 | * @dev: Device to update |
| 54 | * @filename: Name of the file, e.g. "/path/to/disk.img" |
| 55 | * Returns: 0 if OK, -EEXIST if a file is already attached, other -ve on |
| 56 | * other error |
| 57 | */ |
| 58 | int host_attach_file(struct udevice *dev, const char *filename); |
| 59 | |
| 60 | /** |
| 61 | * host_detach_file() - Detach a file from the device |
| 62 | * |
| 63 | * @dev: Device to detach from |
| 64 | * Returns: 0 if OK, -ENOENT if no file is attached, other -ve on other |
| 65 | * error |
| 66 | */ |
| 67 | int host_detach_file(struct udevice *dev); |
| 68 | |
| 69 | /** |
| 70 | * host_create_device() - Create a new host device |
| 71 | * |
| 72 | * Any existing device with the same label is removed and unbound first |
| 73 | * |
| 74 | * @label: Label of the attachment, e.g. "test1" |
| 75 | * @removable: true if the device should be marked as removable, false |
| 76 | * if it is fixed. See enum blk_flag_t |
| 77 | * @devp: Returns the device created, on success |
| 78 | * Returns: 0 if OK, -ve on error |
| 79 | */ |
| 80 | int host_create_device(const char *label, bool removable, |
| 81 | struct udevice **devp); |
| 82 | |
| 83 | /** |
| 84 | * host_create_attach_file() - Create a new host device attached to a file |
| 85 | * |
| 86 | * @label: Label of the attachment, e.g. "test1" |
| 87 | * @filename: Name of the file, e.g. "/path/to/disk.img" |
| 88 | * @removable: true if the device should be marked as removable, false |
| 89 | * if it is fixed. See enum blk_flag_t |
| 90 | * @devp: Returns the device created, on success |
| 91 | * Returns: 0 if OK, -ve on error |
| 92 | */ |
| 93 | int host_create_attach_file(const char *label, const char *filename, |
| 94 | bool removable, struct udevice **devp); |
| 95 | |
| 96 | /** |
| 97 | * host_find_by_label() - Find a host by label |
| 98 | * |
| 99 | * Searches all host devices to find one with the given label |
| 100 | * |
| 101 | * @label: Label to find |
| 102 | * Returns: associated device, or NULL if not found |
| 103 | */ |
| 104 | struct udevice *host_find_by_label(const char *label); |
| 105 | |
| 106 | /** |
| 107 | * host_get_cur_dev() - Get the current device |
| 108 | * |
| 109 | * Returns current device, or NULL if none |
| 110 | */ |
| 111 | struct udevice *host_get_cur_dev(void); |
| 112 | |
| 113 | /** |
| 114 | * host_set_cur_dev() - Set the current device |
| 115 | * |
| 116 | * Sets the current device, or clears it if @dev is NULL |
| 117 | * |
| 118 | * @dev: Device to set as the current one |
| 119 | */ |
| 120 | void host_set_cur_dev(struct udevice *dev); |
| 121 | |
| 122 | #endif /* __SANDBOX_HOST__ */ |