bootstd: Add the concept of a bootdev hunter

Some bootdevs must be enumerated before they appear. For example, USB
bootdevs are not visible until USB is enumerated.

With standard boot this needs to happen automatically, since we only
want to enumerate a bus if it is needed.

Add a way to define bootdev 'hunters' which can be used to hunt for
bootdevs of a given type. Track which ones have been used and add a
command to list them.

Include a clang work-around which seems to be needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2023-01-17 10:47:33 -07:00 committed by Tom Rini
parent 3722cc973f
commit bd90b09288
5 changed files with 176 additions and 3 deletions

View file

@ -11,6 +11,7 @@
struct bootflow;
struct bootflow_iter;
struct bootstd_priv;
struct udevice;
/**
@ -33,6 +34,53 @@ enum bootdev_prio_t {
BOOTDEVP_COUNT,
};
struct bootdev_hunter;
/**
* bootdev_hunter_func - function to probe for bootdevs of a given type
*
* This should hunt around for bootdevs of the given type, binding them as it
* finds them. This may involve bus enumeration, etc.
*
* @info: Info structure describing this hunter
* @show: true to show information from the hunter
* Returns: 0 if OK, -ve on error
*/
typedef int (*bootdev_hunter_func)(struct bootdev_hunter *info, bool show);
/**
* struct bootdev_hunter - information about how to hunt for bootdevs
*
* @prio: Scanning priority of this hunter
* @uclass: Uclass ID for the media associated with this bootdev
* @drv: bootdev driver for the things found by this hunter
* @hunt: Function to call to hunt for bootdevs of this type (NULL if none)
*
* Some bootdevs are not visible until other devices are enumerated. For
* example, USB bootdevs only appear when the USB bus is enumerated.
*
* On the other hand, we don't always want to enumerate all the buses just to
* find the first valid bootdev. Ideally we want to work through them in
* priority order, so that the fastest bootdevs are discovered first.
*
* This struct holds information about the bootdev so we can determine the probe
* order and how to hunt for bootdevs of this type
*/
struct bootdev_hunter {
enum bootdev_prio_t prio;
enum uclass_id uclass;
struct driver *drv;
bootdev_hunter_func hunt;
};
/* declare a new bootdev hunter */
#define BOOTDEV_HUNTER(__name) \
ll_entry_declare(struct bootdev_hunter, __name, bootdev_hunter)
/* access a bootdev hunter by name */
#define BOOTDEV_HUNTER_GET(__name) \
ll_entry_get(struct bootdev_hunter, __name, bootdev_hunter)
/**
* struct bootdev_uc_plat - uclass information about a bootdev
*
@ -205,6 +253,16 @@ int bootdev_find_by_any(const char *name, struct udevice **devp);
*/
int bootdev_setup_iter_order(struct bootflow_iter *iter, struct udevice **devp);
/**
* bootdev_list_hunters() - List the available bootdev hunters
*
* These provide a way to find new bootdevs by enumerating buses, etc. This
* function lists the available hunters
*
* @std: Pointer to bootstd private info
*/
void bootdev_list_hunters(struct bootstd_priv *std);
#if CONFIG_IS_ENABLED(BOOTSTD)
/**
* bootdev_setup_for_dev() - Bind a new bootdev device (deprecated)