imx: imx8m[m/n]_beacon: Enable SPL_DM_SERIAL
[platform/kernel/u-boot.git] / include / blk.h
index 19bab08..9503369 100644 (file)
@@ -34,9 +34,10 @@ enum if_type {
        IF_TYPE_SATA,
        IF_TYPE_HOST,
        IF_TYPE_NVME,
-       IF_TYPE_EFI,
+       IF_TYPE_EFI_LOADER,
        IF_TYPE_PVBLOCK,
        IF_TYPE_VIRTIO,
+       IF_TYPE_EFI_MEDIA,
 
        IF_TYPE_COUNT,                  /* Number of interface types */
 };
@@ -45,6 +46,9 @@ enum if_type {
 #define BLK_PRD_SIZE           20
 #define BLK_REV_SIZE           8
 
+#define PART_FORMAT_PCAT       0x1
+#define PART_FORMAT_GPT                0x2
+
 /*
  * Identifies the partition table type (ie. MBR vs GPT GUID) signature
  */
@@ -132,7 +136,7 @@ int blkcache_init(void);
  * @param blksz - size in bytes of each block
  * @param buf - buffer to contain cached data
  *
- * @return - 1 if block returned from cache, 0 otherwise.
+ * Return: - 1 if block returned from cache, 0 otherwise.
  */
 int blkcache_read(int iftype, int dev,
                  lbaint_t start, lbaint_t blkcnt,
@@ -293,7 +297,7 @@ unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
  * @if_type:   Interface type (enum if_type_t)
  * @devnum:    Device number (specific to each interface type)
  * @devp:      the device, if found
- * @return 0 if found, -ENODEV if no device found, or other -ve error value
+ * Return: 0 if found, -ENODEV if no device found, or other -ve error value
  */
 int blk_find_device(int if_type, int devnum, struct udevice **devp);
 
@@ -303,7 +307,7 @@ int blk_find_device(int if_type, int devnum, struct udevice **devp);
  * @if_type:   Interface type (enum if_type_t)
  * @devnum:    Device number (specific to each interface type)
  * @devp:      the device, if found
- * @return 0 if found, -ENODEV if no device found, or other -ve error value
+ * Return: 0 if found, -ENODEV if no device found, or other -ve error value
  */
 int blk_get_device(int if_type, int devnum, struct udevice **devp);
 
@@ -314,7 +318,7 @@ int blk_get_device(int if_type, int devnum, struct udevice **devp);
  *
  * @devnum:    Device number (specific to each interface type)
  * @devp:      the device, if found
- * @return 0 if found, -ENODEV if no device, or other -ve error value
+ * Return: 0 if found, -ENODEV if no device, or other -ve error value
  */
 int blk_first_device(int if_type, struct udevice **devp);
 
@@ -328,7 +332,7 @@ int blk_first_device(int if_type, struct udevice **devp);
  *
  * @devp:      On entry, the previous device returned. On exit, the next
  *             device, if found
- * @return 0 if found, -ENODEV if no device, or other -ve error value
+ * Return: 0 if found, -ENODEV if no device, or other -ve error value
  */
 int blk_next_device(struct udevice **devp);
 
@@ -367,12 +371,24 @@ int blk_create_devicef(struct udevice *parent, const char *drv_name,
                       lbaint_t lba, struct udevice **devp);
 
 /**
+ * blk_probe_or_unbind() - Try to probe
+ *
+ * Try to probe the device, primarily for enumerating partitions.
+ * If it fails, the device itself is unbound since it means that it won't
+ * work any more.
+ *
+ * @dev:       The device to probe
+ * Return:     0 if OK, -ve on error
+ */
+int blk_probe_or_unbind(struct udevice *dev);
+
+/**
  * blk_unbind_all() - Unbind all device of the given interface type
  *
  * The devices are removed and then unbound.
  *
  * @if_type:   Interface type to unbind
- * @return 0 if OK, -ve on error
+ * Return: 0 if OK, -ve on error
  */
 int blk_unbind_all(int if_type);
 
@@ -383,7 +399,7 @@ int blk_unbind_all(int if_type);
  * next number is safe to use for a newly allocated device.
  *
  * @if_type:   Interface type to scan
- * @return maximum device number found, or -ENODEV if none, or other -ve on
+ * Return: maximum device number found, or -ENODEV if none, or other -ve on
  * error
  */
 int blk_find_max_devnum(enum if_type if_type);
@@ -395,7 +411,7 @@ int blk_find_max_devnum(enum if_type if_type);
  * an interface type @if_type.
  *
  * @if_type:   Interface type to scan
- * @return next device number safe to use, or -ve on error
+ * Return: next device number safe to use, or -ve on error
  */
 int blk_next_free_devnum(enum if_type if_type);
 
@@ -406,7 +422,7 @@ int blk_next_free_devnum(enum if_type if_type);
  *
  * @dev:       Device to update
  * @hwpart:    Partition number to select
- * @return 0 if OK, -ve on error
+ * Return: 0 if OK, -ve on error
  */
 int blk_select_hwpart(struct udevice *dev, int hwpart);
 
@@ -418,6 +434,14 @@ int blk_select_hwpart(struct udevice *dev, int hwpart);
 int blk_get_from_parent(struct udevice *parent, struct udevice **devp);
 
 /**
+ * blk_get_devtype() - Get the device type of a block device
+ *
+ * @dev:       Block device to check
+ * Return: device tree, i.e. the uclass name of its parent, e.g. "mmc"
+ */
+const char *blk_get_devtype(struct udevice *dev);
+
+/**
  * blk_get_by_device() - Get the block device descriptor for the given device
  * @dev:       Instance of a storage device
  *
@@ -543,7 +567,7 @@ struct blk_driver *blk_driver_lookup_type(int if_type);
  *
  * @if_type:   Block device type
  * @devnum:    Device number
- * @return point to block device descriptor, or NULL if not found
+ * Return: point to block device descriptor, or NULL if not found
  */
 struct blk_desc *blk_get_devnum_by_type(enum if_type if_type, int devnum);
 
@@ -555,7 +579,7 @@ struct blk_desc *blk_get_devnum_by_type(enum if_type if_type, int devnum);
  *
  * @if_typename:       Block device type name
  * @devnum:            Device number
- * @return point to block device descriptor, or NULL if not found
+ * Return: point to block device descriptor, or NULL if not found
  */
 struct blk_desc *blk_get_devnum_by_typename(const char *if_typename,
                                            int devnum);
@@ -569,7 +593,7 @@ struct blk_desc *blk_get_devnum_by_typename(const char *if_typename,
  *
  * @desc:      Block device descriptor for the device to select
  * @hwpart:    Partition number to select
- * @return 0 if OK, -ve on error
+ * Return: 0 if OK, -ve on error
  */
 int blk_dselect_hwpart(struct blk_desc *desc, int hwpart);
 
@@ -580,7 +604,7 @@ int blk_dselect_hwpart(struct blk_desc *desc, int hwpart);
  * then displays a list of partitions.
  *
  * @if_type:   Block device type
- * @return 0 if OK, -ENODEV if there is none of that type
+ * Return: 0 if OK, -ENODEV if there is none of that type
  */
 int blk_list_part(enum if_type if_type);
 
@@ -601,7 +625,7 @@ void blk_list_devices(enum if_type if_type);
  *
  * @if_type:   Block device type
  * @devnum:    Device number
- * @return 0 if OK, -ENODEV for invalid device number
+ * Return: 0 if OK, -ENODEV for invalid device number
  */
 int blk_show_device(enum if_type if_type, int devnum);
 
@@ -613,7 +637,7 @@ int blk_show_device(enum if_type if_type, int devnum);
  *
  * @if_type:   Block device type
  * @devnum:    Device number
- * @return 0 if OK, -ENODEV for invalid device number, -ENOENT if the block
+ * Return: 0 if OK, -ENODEV for invalid device number, -ENOENT if the block
  * device is not connected
  */
 int blk_print_device_num(enum if_type if_type, int devnum);
@@ -623,7 +647,7 @@ int blk_print_device_num(enum if_type if_type, int devnum);
  *
  * @if_type:   Block device type
  * @devnum:    Device number
- * @return 0 if OK, -ENOENT if the block device is not connected, -ENOSYS if
+ * Return: 0 if OK, -ENOENT if the block device is not connected, -ENOSYS if
  * the interface type is not supported, other -ve on other error
  */
 int blk_print_part_devnum(enum if_type if_type, int devnum);
@@ -635,7 +659,7 @@ int blk_print_part_devnum(enum if_type if_type, int devnum);
  * @devnum:    Device number
  * @blkcnt:    Number of blocks to read
  * @buffer:    Address to write data to
- * @return number of blocks read, or -ve error number on error
+ * Return: number of blocks read, or -ve error number on error
  */
 ulong blk_read_devnum(enum if_type if_type, int devnum, lbaint_t start,
                      lbaint_t blkcnt, void *buffer);
@@ -647,7 +671,7 @@ ulong blk_read_devnum(enum if_type if_type, int devnum, lbaint_t start,
  * @devnum:    Device number
  * @blkcnt:    Number of blocks to write
  * @buffer:    Address to read data from
- * @return number of blocks written, or -ve error number on error
+ * Return: number of blocks written, or -ve error number on error
  */
 ulong blk_write_devnum(enum if_type if_type, int devnum, lbaint_t start,
                       lbaint_t blkcnt, const void *buffer);
@@ -661,7 +685,7 @@ ulong blk_write_devnum(enum if_type if_type, int devnum, lbaint_t start,
  * @if_type:   Block device type
  * @devnum:    Device number
  * @hwpart:    Partition number to select
- * @return 0 if OK, -ve on error
+ * Return: 0 if OK, -ve on error
  */
 int blk_select_hwpart_devnum(enum if_type if_type, int devnum, int hwpart);
 
@@ -669,7 +693,7 @@ int blk_select_hwpart_devnum(enum if_type if_type, int devnum, int hwpart);
  * blk_get_if_type_name() - Get the name of an interface type
  *
  * @if_type: Interface type to check
- * @return name of interface, or NULL if none
+ * Return: name of interface, or NULL if none
  */
 const char *blk_get_if_type_name(enum if_type if_type);
 
@@ -680,7 +704,7 @@ const char *blk_get_if_type_name(enum if_type if_type);
  * @argv: Command arguments
  * @if_type: Interface type
  * @cur_devnump: Current device number for this interface type
- * @return 0 if OK, CMD_RET_ERROR on error
+ * Return: 0 if OK, CMD_RET_ERROR on error
  */
 int blk_common_cmd(int argc, char *const argv[], enum if_type if_type,
                   int *cur_devnump);
@@ -698,7 +722,7 @@ enum blk_flag_t {
  *
  * @flags: Indicates type of device to return
  * @devp: Returns pointer to the first device in that uclass, or NULL if none
- * @return 0 if found, -ENODEV if not found, other -ve on error
+ * Return: 0 if found, -ENODEV if not found, other -ve on error
  */
 int blk_first_device_err(enum blk_flag_t flags, struct udevice **devp);
 
@@ -711,11 +735,56 @@ int blk_first_device_err(enum blk_flag_t flags, struct udevice **devp);
  * @devp: On entry, pointer to device to lookup. On exit, returns pointer
  * to the next device in the uclass if no error occurred, or -ENODEV if
  * there is no next device.
- * @return 0 if found, -ENODEV if not found, other -ve on error
+ * Return: 0 if found, -ENODEV if not found, other -ve on error
  */
 int blk_next_device_err(enum blk_flag_t flags, struct udevice **devp);
 
 /**
+ * blk_find_first() - Return the first matching block device
+ * @flags: Indicates type of device to return
+ * @devp:      Returns pointer to device, or NULL on error
+ *
+ * The device is not prepared for use - this is an internal function.
+ * The function uclass_get_device_tail() can be used to probe the device.
+ *
+ * Note that some devices are considered removable until they have been probed
+ *
+ * @return 0 if found, -ENODEV if not found
+ */
+int blk_find_first(enum blk_flag_t flags, struct udevice **devp);
+
+/**
+ * blk_find_next() - Return the next matching block device
+ * @flags: Indicates type of device to return
+ * @devp: On entry, pointer to device to lookup. On exit, returns pointer
+ * to the next device in the same uclass, or NULL if none
+ *
+ * The device is not prepared for use - this is an internal function.
+ * The function uclass_get_device_tail() can be used to probe the device.
+ *
+ * Note that some devices are considered removable until they have been probed
+ *
+ * @return 0 if found, -ENODEV if not found
+ */
+int blk_find_next(enum blk_flag_t flags, struct udevice **devp);
+
+/**
+ * blk_foreach() - iterate through block devices
+ *
+ * This creates a for() loop which works through the available block devices in
+ * order from start to end.
+ *
+ * If for some reason the uclass cannot be found, this does nothing.
+ *
+ * @_flags: Indicates type of device to return
+ * @_pos: struct udevice * to hold the current device. Set to NULL when there
+ * are no more devices.
+ */
+#define blk_foreach(_flags, _pos) \
+       for (int _ret = blk_find_first(_flags, &_pos); !_ret && _pos; \
+            _ret = blk_find_next(_flags, &_pos))
+
+/**
  * blk_foreach_probe() - Helper function to iteration through block devices
  *
  * This creates a for() loop which works through the available devices in
@@ -735,7 +804,7 @@ int blk_next_device_err(enum blk_flag_t flags, struct udevice **devp);
  * blk_count_devices() - count the number of devices of a particular type
  *
  * @flags: Indicates type of device to find
- * @return number of devices matching those flags
+ * Return: number of devices matching those flags
  */
 int blk_count_devices(enum blk_flag_t flag);