1 /* SPDX-License-Identifier: GPL-2.0+ */
5 * Copyright 2022 Google LLC
8 #ifndef __SANDBOX_HOST__
9 #define __SANDBOX_HOST__
12 * struct host_sb_plat - platform data for a host device
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)
25 * struct host_ops - operations supported by UCLASS_HOST
27 * @attach_file: Attach a new file to a device
28 * @detach_file: Detach a file from a device
32 * attach_file() - Attach a new file to the device
34 * @dev: Device to update
35 * @filename: Name of the file, e.g. "/path/to/disk.img"
36 * Returns: 0 if OK, -EEXIST if a file is already attached, other -ve on
39 int (*attach_file)(struct udevice *dev, const char *filename);
42 * detach_file() - Detach a file from the device
44 * @dev: Device to detach from
45 * Returns: 0 if OK, -ENOENT if no file is attached, other -ve on other
48 int (*detach_file)(struct udevice *dev);
51 #define host_get_ops(dev) ((struct host_ops *)(dev)->driver->ops)
54 * host_attach_file() - Attach a new file to the device
56 * @dev: Device to update
57 * @filename: Name of the file, e.g. "/path/to/disk.img"
58 * Returns: 0 if OK, -EEXIST if a file is already attached, other -ve on
61 int host_attach_file(struct udevice *dev, const char *filename);
64 * host_detach_file() - Detach a file from the device
66 * @dev: Device to detach from
67 * Returns: 0 if OK, -ENOENT if no file is attached, other -ve on other
70 int host_detach_file(struct udevice *dev);
73 * host_create_device() - Create a new host device
75 * Any existing device with the same label is removed and unbound first
77 * @label: Label of the attachment, e.g. "test1"
78 * @removable: true if the device should be marked as removable, false
79 * if it is fixed. See enum blk_flag_t
80 * @devp: Returns the device created, on success
81 * Returns: 0 if OK, -ve on error
83 int host_create_device(const char *label, bool removable,
84 struct udevice **devp);
87 * host_create_attach_file() - Create a new host device attached to a file
89 * @label: Label of the attachment, e.g. "test1"
90 * @filename: Name of the file, e.g. "/path/to/disk.img"
91 * @removable: true if the device should be marked as removable, false
92 * if it is fixed. See enum blk_flag_t
93 * @devp: Returns the device created, on success
94 * Returns: 0 if OK, -ve on error
96 int host_create_attach_file(const char *label, const char *filename,
97 bool removable, struct udevice **devp);
100 * host_find_by_label() - Find a host by label
102 * Searches all host devices to find one with the given label
104 * @label: Label to find
105 * Returns: associated device, or NULL if not found
107 struct udevice *host_find_by_label(const char *label);
110 * host_get_cur_dev() - Get the current device
112 * Returns current device, or NULL if none
114 struct udevice *host_get_cur_dev(void);
117 * host_set_cur_dev() - Set the current device
119 * Sets the current device, or clears it if @dev is NULL
121 * @dev: Device to set as the current one
123 void host_set_cur_dev(struct udevice *dev);
125 #endif /* __SANDBOX_HOST__ */