2018-05-06 21:58:06 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2016-02-29 22:25:39 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2000-2004
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BLK_H
|
|
|
|
#define BLK_H
|
|
|
|
|
2023-08-13 23:49:59 +00:00
|
|
|
#include <bouncebuf.h>
|
2022-08-12 01:34:59 +00:00
|
|
|
#include <dm/uclass-id.h>
|
2017-09-13 22:05:25 +00:00
|
|
|
#include <efi.h>
|
|
|
|
|
2016-02-29 22:25:39 +00:00
|
|
|
#ifdef CONFIG_SYS_64BIT_LBA
|
|
|
|
typedef uint64_t lbaint_t;
|
|
|
|
#define LBAFlength "ll"
|
|
|
|
#else
|
|
|
|
typedef ulong lbaint_t;
|
|
|
|
#define LBAFlength "l"
|
|
|
|
#endif
|
|
|
|
#define LBAF "%" LBAFlength "x"
|
|
|
|
#define LBAFU "%" LBAFlength "u"
|
|
|
|
|
2021-07-05 22:32:59 +00:00
|
|
|
struct udevice;
|
|
|
|
|
2022-08-12 01:34:45 +00:00
|
|
|
static inline bool blk_enabled(void)
|
|
|
|
{
|
2022-08-12 01:34:48 +00:00
|
|
|
return CONFIG_IS_ENABLED(BLK) || IS_ENABLED(CONFIG_SPL_LEGACY_BLOCK);
|
2022-08-12 01:34:45 +00:00
|
|
|
}
|
|
|
|
|
2017-09-10 12:12:50 +00:00
|
|
|
#define BLK_VEN_SIZE 40
|
|
|
|
#define BLK_PRD_SIZE 20
|
|
|
|
#define BLK_REV_SIZE 8
|
|
|
|
|
2021-10-26 08:27:25 +00:00
|
|
|
#define PART_FORMAT_PCAT 0x1
|
|
|
|
#define PART_FORMAT_GPT 0x2
|
|
|
|
|
2017-09-13 22:05:25 +00:00
|
|
|
/*
|
|
|
|
* Identifies the partition table type (ie. MBR vs GPT GUID) signature
|
|
|
|
*/
|
|
|
|
enum sig_type {
|
|
|
|
SIG_TYPE_NONE,
|
|
|
|
SIG_TYPE_MBR,
|
|
|
|
SIG_TYPE_GUID,
|
|
|
|
|
|
|
|
SIG_TYPE_COUNT /* Number of signature types */
|
|
|
|
};
|
|
|
|
|
2016-02-29 22:25:55 +00:00
|
|
|
/*
|
|
|
|
* With driver model (CONFIG_BLK) this is uclass platform data, accessible
|
2020-12-03 23:55:18 +00:00
|
|
|
* with dev_get_uclass_plat(dev)
|
2016-02-29 22:25:55 +00:00
|
|
|
*/
|
2016-02-29 22:25:39 +00:00
|
|
|
struct blk_desc {
|
2016-02-29 22:25:55 +00:00
|
|
|
/*
|
|
|
|
* TODO: With driver model we should be able to use the parent
|
|
|
|
* device's uclass instead.
|
|
|
|
*/
|
2022-09-17 15:00:09 +00:00
|
|
|
enum uclass_id uclass_id; /* type of the interface */
|
2016-02-29 22:25:51 +00:00
|
|
|
int devnum; /* device number */
|
2016-02-29 22:25:39 +00:00
|
|
|
unsigned char part_type; /* partition type */
|
|
|
|
unsigned char target; /* target SCSI ID */
|
|
|
|
unsigned char lun; /* target LUN */
|
|
|
|
unsigned char hwpart; /* HW partition, e.g. for eMMC */
|
|
|
|
unsigned char type; /* device type */
|
|
|
|
unsigned char removable; /* removable device */
|
|
|
|
/* device can use 48bit addr (ATA/ATAPI v7) */
|
2023-04-25 16:54:41 +00:00
|
|
|
bool lba48;
|
2023-04-25 16:54:35 +00:00
|
|
|
unsigned char atapi; /* Use ATAPI protocol */
|
2016-02-29 22:25:39 +00:00
|
|
|
lbaint_t lba; /* number of blocks */
|
|
|
|
unsigned long blksz; /* block size */
|
|
|
|
int log2blksz; /* for convenience: log2(blksz) */
|
2017-09-10 12:12:50 +00:00
|
|
|
char vendor[BLK_VEN_SIZE + 1]; /* device vendor string */
|
|
|
|
char product[BLK_PRD_SIZE + 1]; /* device product number */
|
|
|
|
char revision[BLK_REV_SIZE + 1]; /* firmware revision */
|
2017-09-13 22:05:25 +00:00
|
|
|
enum sig_type sig_type; /* Partition table signature type */
|
|
|
|
union {
|
|
|
|
uint32_t mbr_sig; /* MBR integer signature */
|
|
|
|
efi_guid_t guid_sig; /* GPT GUID Signature */
|
|
|
|
};
|
2017-07-04 19:31:19 +00:00
|
|
|
#if CONFIG_IS_ENABLED(BLK)
|
2016-05-01 19:52:33 +00:00
|
|
|
/*
|
|
|
|
* For now we have a few functions which take struct blk_desc as a
|
|
|
|
* parameter. This field allows them to look up the associated
|
|
|
|
* device. Once these functions are removed we can drop this field.
|
|
|
|
*/
|
2016-02-29 22:25:55 +00:00
|
|
|
struct udevice *bdev;
|
|
|
|
#else
|
2016-02-29 22:25:39 +00:00
|
|
|
unsigned long (*block_read)(struct blk_desc *block_dev,
|
|
|
|
lbaint_t start,
|
|
|
|
lbaint_t blkcnt,
|
|
|
|
void *buffer);
|
|
|
|
unsigned long (*block_write)(struct blk_desc *block_dev,
|
|
|
|
lbaint_t start,
|
|
|
|
lbaint_t blkcnt,
|
|
|
|
const void *buffer);
|
|
|
|
unsigned long (*block_erase)(struct blk_desc *block_dev,
|
|
|
|
lbaint_t start,
|
|
|
|
lbaint_t blkcnt);
|
|
|
|
void *priv; /* driver private struct pointer */
|
2016-02-29 22:25:55 +00:00
|
|
|
#endif
|
2016-02-29 22:25:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define BLOCK_CNT(size, blk_desc) (PAD_COUNT(size, blk_desc->blksz))
|
|
|
|
#define PAD_TO_BLOCKSIZE(size, blk_desc) \
|
|
|
|
(PAD_SIZE(size, blk_desc->blksz))
|
|
|
|
|
2018-06-11 22:17:48 +00:00
|
|
|
#if CONFIG_IS_ENABLED(BLOCK_CACHE)
|
2020-01-21 09:37:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* blkcache_init() - initialize the block cache list pointers
|
|
|
|
*/
|
|
|
|
int blkcache_init(void);
|
|
|
|
|
2016-03-28 17:05:44 +00:00
|
|
|
/**
|
|
|
|
* blkcache_read() - attempt to read a set of blocks from cache
|
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* @param iftype - uclass_id_x for type of device
|
2016-03-28 17:05:44 +00:00
|
|
|
* @param dev - device index of particular type
|
|
|
|
* @param start - starting block number
|
|
|
|
* @param blkcnt - number of blocks to read
|
|
|
|
* @param blksz - size in bytes of each block
|
2022-10-17 07:35:04 +00:00
|
|
|
* @param buffer - buffer to contain cached data
|
2016-03-28 17:05:44 +00:00
|
|
|
*
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: - 1 if block returned from cache, 0 otherwise.
|
2016-03-28 17:05:44 +00:00
|
|
|
*/
|
2016-04-02 14:37:14 +00:00
|
|
|
int blkcache_read(int iftype, int dev,
|
|
|
|
lbaint_t start, lbaint_t blkcnt,
|
|
|
|
unsigned long blksz, void *buffer);
|
2016-03-28 17:05:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* blkcache_fill() - make data read from a block device available
|
|
|
|
* to the block cache
|
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* @param iftype - uclass_id_x for type of device
|
2016-03-28 17:05:44 +00:00
|
|
|
* @param dev - device index of particular type
|
|
|
|
* @param start - starting block number
|
|
|
|
* @param blkcnt - number of blocks available
|
|
|
|
* @param blksz - size in bytes of each block
|
2022-10-17 07:35:04 +00:00
|
|
|
* @param buffer - buffer containing data to cache
|
2016-03-28 17:05:44 +00:00
|
|
|
*
|
|
|
|
*/
|
2016-04-02 14:37:14 +00:00
|
|
|
void blkcache_fill(int iftype, int dev,
|
|
|
|
lbaint_t start, lbaint_t blkcnt,
|
|
|
|
unsigned long blksz, void const *buffer);
|
2016-03-28 17:05:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* blkcache_invalidate() - discard the cache for a set of blocks
|
|
|
|
* because of a write or device (re)initialization.
|
|
|
|
*
|
2022-10-30 01:47:08 +00:00
|
|
|
* @iftype - UCLASS_ID_ for type of device, or -1 for any
|
|
|
|
* @dev - device index of particular type, if @iftype is not -1
|
2016-03-28 17:05:44 +00:00
|
|
|
*/
|
2016-04-02 14:37:14 +00:00
|
|
|
void blkcache_invalidate(int iftype, int dev);
|
2016-03-28 17:05:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* blkcache_configure() - configure block cache
|
|
|
|
*
|
|
|
|
* @param blocks - maximum blocks per entry
|
|
|
|
* @param entries - maximum entries in cache
|
|
|
|
*/
|
|
|
|
void blkcache_configure(unsigned blocks, unsigned entries);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* statistics of the block cache
|
|
|
|
*/
|
|
|
|
struct block_cache_stats {
|
|
|
|
unsigned hits;
|
|
|
|
unsigned misses;
|
|
|
|
unsigned entries; /* current entry count */
|
|
|
|
unsigned max_blocks_per_entry;
|
|
|
|
unsigned max_entries;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get_blkcache_stats() - return statistics and reset
|
|
|
|
*
|
|
|
|
* @param stats - statistics are copied here
|
|
|
|
*/
|
|
|
|
void blkcache_stats(struct block_cache_stats *stats);
|
|
|
|
|
2022-10-30 01:47:08 +00:00
|
|
|
/** blkcache_free() - free all memory allocated to the block cache */
|
|
|
|
void blkcache_free(void);
|
|
|
|
|
2016-03-28 17:05:44 +00:00
|
|
|
#else
|
|
|
|
|
2016-04-02 14:37:14 +00:00
|
|
|
static inline int blkcache_read(int iftype, int dev,
|
|
|
|
lbaint_t start, lbaint_t blkcnt,
|
|
|
|
unsigned long blksz, void *buffer)
|
2016-03-28 17:05:44 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-02 14:37:14 +00:00
|
|
|
static inline void blkcache_fill(int iftype, int dev,
|
|
|
|
lbaint_t start, lbaint_t blkcnt,
|
|
|
|
unsigned long blksz, void const *buffer) {}
|
2016-03-28 17:05:44 +00:00
|
|
|
|
2016-04-02 14:37:14 +00:00
|
|
|
static inline void blkcache_invalidate(int iftype, int dev) {}
|
2016-03-28 17:05:44 +00:00
|
|
|
|
2022-10-30 01:47:08 +00:00
|
|
|
static inline void blkcache_free(void) {}
|
|
|
|
|
2016-03-28 17:05:44 +00:00
|
|
|
#endif
|
|
|
|
|
2017-07-04 19:31:19 +00:00
|
|
|
#if CONFIG_IS_ENABLED(BLK)
|
2016-02-29 22:25:55 +00:00
|
|
|
struct udevice;
|
|
|
|
|
|
|
|
/* Operations on block devices */
|
|
|
|
struct blk_ops {
|
|
|
|
/**
|
|
|
|
* read() - read from a block device
|
|
|
|
*
|
|
|
|
* @dev: Device to read from
|
|
|
|
* @start: Start block number to read (0=first)
|
|
|
|
* @blkcnt: Number of blocks to read
|
|
|
|
* @buffer: Destination buffer for data read
|
|
|
|
* @return number of blocks read, or -ve error number (see the
|
|
|
|
* IS_ERR_VALUE() macro
|
|
|
|
*/
|
|
|
|
unsigned long (*read)(struct udevice *dev, lbaint_t start,
|
|
|
|
lbaint_t blkcnt, void *buffer);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* write() - write to a block device
|
|
|
|
*
|
|
|
|
* @dev: Device to write to
|
|
|
|
* @start: Start block number to write (0=first)
|
|
|
|
* @blkcnt: Number of blocks to write
|
|
|
|
* @buffer: Source buffer for data to write
|
|
|
|
* @return number of blocks written, or -ve error number (see the
|
|
|
|
* IS_ERR_VALUE() macro
|
|
|
|
*/
|
|
|
|
unsigned long (*write)(struct udevice *dev, lbaint_t start,
|
|
|
|
lbaint_t blkcnt, const void *buffer);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* erase() - erase a section of a block device
|
|
|
|
*
|
|
|
|
* @dev: Device to (partially) erase
|
|
|
|
* @start: Start block number to erase (0=first)
|
|
|
|
* @blkcnt: Number of blocks to erase
|
|
|
|
* @return number of blocks erased, or -ve error number (see the
|
|
|
|
* IS_ERR_VALUE() macro
|
|
|
|
*/
|
|
|
|
unsigned long (*erase)(struct udevice *dev, lbaint_t start,
|
|
|
|
lbaint_t blkcnt);
|
2016-05-01 19:52:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* select_hwpart() - select a particular hardware partition
|
|
|
|
*
|
|
|
|
* Some devices (e.g. MMC) can support partitioning at the hardware
|
|
|
|
* level. This is quite separate from the normal idea of
|
|
|
|
* software-based partitions. MMC hardware partitions must be
|
|
|
|
* explicitly selected. Once selected only the region of the device
|
|
|
|
* covered by that partition is accessible.
|
|
|
|
*
|
|
|
|
* The MMC standard provides for two boot partitions (numbered 1 and 2),
|
|
|
|
* rpmb (3), and up to 4 addition general-purpose partitions (4-7).
|
|
|
|
*
|
2022-10-17 07:35:04 +00:00
|
|
|
* @dev: Block device to update
|
2016-05-01 19:52:30 +00:00
|
|
|
* @hwpart: Hardware partition number to select. 0 means the raw
|
|
|
|
* device, 1 is the first partition, 2 is the second, etc.
|
|
|
|
* @return 0 if OK, -ve on error
|
|
|
|
*/
|
|
|
|
int (*select_hwpart)(struct udevice *dev, int hwpart);
|
2023-08-13 23:49:59 +00:00
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_BOUNCE_BUFFER)
|
|
|
|
/**
|
|
|
|
* buffer_aligned() - test memory alignment of block operation buffer
|
|
|
|
*
|
|
|
|
* Some devices have limited DMA capabilities and require that the
|
|
|
|
* buffers passed to them fit specific properties. This optional
|
|
|
|
* callback can be used to indicate whether a buffer alignment is
|
|
|
|
* suitable for the device DMA or not, and trigger use of generic
|
|
|
|
* bounce buffer implementation to help use of unsuitable buffers
|
|
|
|
* at the expense of performance degradation.
|
|
|
|
*
|
|
|
|
* @dev: Block device associated with the request
|
|
|
|
* @state: Bounce buffer state
|
|
|
|
* @return 1 if OK, 0 if unaligned
|
|
|
|
*/
|
|
|
|
int (*buffer_aligned)(struct udevice *dev, struct bounce_buffer *state);
|
|
|
|
#endif /* CONFIG_BOUNCE_BUFFER */
|
2016-02-29 22:25:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These functions should take struct udevice instead of struct blk_desc,
|
|
|
|
* but this is convenient for migration to driver model. Add a 'd' prefix
|
|
|
|
* to the function operations, so that blk_read(), etc. can be reserved for
|
|
|
|
* functions with the correct arguments.
|
|
|
|
*/
|
|
|
|
unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
|
|
|
|
lbaint_t blkcnt, void *buffer);
|
|
|
|
unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
|
|
|
|
lbaint_t blkcnt, const void *buffer);
|
|
|
|
unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
|
|
|
|
lbaint_t blkcnt);
|
|
|
|
|
2022-10-21 00:22:54 +00:00
|
|
|
/**
|
|
|
|
* blk_read() - Read from a block device
|
|
|
|
*
|
|
|
|
* @dev: Device to read from
|
|
|
|
* @start: Start block for the read
|
|
|
|
* @blkcnt: Number of blocks to read
|
|
|
|
* @buf: Place to put the data
|
|
|
|
* @return number of blocks read (which may be less than @blkcnt),
|
|
|
|
* or -ve on error. This never returns 0 unless @blkcnt is 0
|
|
|
|
*/
|
|
|
|
long blk_read(struct udevice *dev, lbaint_t start, lbaint_t blkcnt,
|
|
|
|
void *buffer);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* blk_write() - Write to a block device
|
|
|
|
*
|
|
|
|
* @dev: Device to write to
|
|
|
|
* @start: Start block for the write
|
|
|
|
* @blkcnt: Number of blocks to write
|
|
|
|
* @buf: Data to write
|
|
|
|
* @return number of blocks written (which may be less than @blkcnt),
|
|
|
|
* or -ve on error. This never returns 0 unless @blkcnt is 0
|
|
|
|
*/
|
|
|
|
long blk_write(struct udevice *dev, lbaint_t start, lbaint_t blkcnt,
|
|
|
|
const void *buffer);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* blk_erase() - Erase part of a block device
|
|
|
|
*
|
|
|
|
* @dev: Device to erase
|
|
|
|
* @start: Start block for the erase
|
|
|
|
* @blkcnt: Number of blocks to erase
|
|
|
|
* @return number of blocks erased (which may be less than @blkcnt),
|
|
|
|
* or -ve on error. This never returns 0 unless @blkcnt is 0
|
|
|
|
*/
|
|
|
|
long blk_erase(struct udevice *dev, lbaint_t start, lbaint_t blkcnt);
|
|
|
|
|
2017-04-24 02:02:05 +00:00
|
|
|
/**
|
|
|
|
* blk_find_device() - Find a block device
|
|
|
|
*
|
|
|
|
* This function does not activate the device. The device will be returned
|
|
|
|
* whether or not it is activated.
|
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* @uclass_id: Interface type (enum uclass_id_t)
|
2017-04-24 02:02:05 +00:00
|
|
|
* @devnum: Device number (specific to each interface type)
|
|
|
|
* @devp: the device, if found
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if found, -ENODEV if no device found, or other -ve error value
|
2017-04-24 02:02:05 +00:00
|
|
|
*/
|
2022-09-17 15:00:09 +00:00
|
|
|
int blk_find_device(int uclass_id, int devnum, struct udevice **devp);
|
2017-04-24 02:02:05 +00:00
|
|
|
|
2016-02-29 22:25:55 +00:00
|
|
|
/**
|
|
|
|
* blk_get_device() - Find and probe a block device ready for use
|
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* @uclass_id: Interface type (enum uclass_id_t)
|
2016-02-29 22:25:55 +00:00
|
|
|
* @devnum: Device number (specific to each interface type)
|
|
|
|
* @devp: the device, if found
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if found, -ENODEV if no device found, or other -ve error value
|
2016-02-29 22:25:55 +00:00
|
|
|
*/
|
2022-09-17 15:00:09 +00:00
|
|
|
int blk_get_device(int uclass_id, int devnum, struct udevice **devp);
|
2016-02-29 22:25:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* blk_first_device() - Find the first device for a given interface
|
|
|
|
*
|
|
|
|
* The device is probed ready for use
|
|
|
|
*
|
|
|
|
* @devnum: Device number (specific to each interface type)
|
|
|
|
* @devp: the device, if found
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if found, -ENODEV if no device, or other -ve error value
|
2016-02-29 22:25:55 +00:00
|
|
|
*/
|
2022-09-17 15:00:09 +00:00
|
|
|
int blk_first_device(int uclass_id, struct udevice **devp);
|
2016-02-29 22:25:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* blk_next_device() - Find the next device for a given interface
|
|
|
|
*
|
|
|
|
* This can be called repeatedly after blk_first_device() to iterate through
|
|
|
|
* all devices of the given interface type.
|
|
|
|
*
|
|
|
|
* The device is probed ready for use
|
|
|
|
*
|
|
|
|
* @devp: On entry, the previous device returned. On exit, the next
|
|
|
|
* device, if found
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if found, -ENODEV if no device, or other -ve error value
|
2016-02-29 22:25:55 +00:00
|
|
|
*/
|
|
|
|
int blk_next_device(struct udevice **devp);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* blk_create_device() - Create a new block device
|
|
|
|
*
|
|
|
|
* @parent: Parent of the new device
|
|
|
|
* @drv_name: Driver name to use for the block device
|
|
|
|
* @name: Name for the device
|
2022-09-17 15:00:09 +00:00
|
|
|
* @uclass_id: Interface type (enum uclass_id_t)
|
2016-05-01 17:36:28 +00:00
|
|
|
* @devnum: Device number, specific to the interface type, or -1 to
|
|
|
|
* allocate the next available number
|
2016-02-29 22:25:55 +00:00
|
|
|
* @blksz: Block size of the device in bytes (typically 512)
|
2017-06-09 14:45:18 +00:00
|
|
|
* @lba: Total number of blocks of the device
|
2016-02-29 22:25:55 +00:00
|
|
|
* @devp: the new device (which has not been probed)
|
|
|
|
*/
|
|
|
|
int blk_create_device(struct udevice *parent, const char *drv_name,
|
2022-09-17 15:00:09 +00:00
|
|
|
const char *name, int uclass_id, int devnum, int blksz,
|
2017-06-09 14:45:18 +00:00
|
|
|
lbaint_t lba, struct udevice **devp);
|
2016-02-29 22:25:55 +00:00
|
|
|
|
2016-05-01 17:36:29 +00:00
|
|
|
/**
|
|
|
|
* blk_create_devicef() - Create a new named block device
|
|
|
|
*
|
|
|
|
* @parent: Parent of the new device
|
|
|
|
* @drv_name: Driver name to use for the block device
|
|
|
|
* @name: Name for the device (parent name is prepended)
|
2022-09-17 15:00:09 +00:00
|
|
|
* @uclass_id: Interface type (enum uclass_id_t)
|
2016-05-01 17:36:29 +00:00
|
|
|
* @devnum: Device number, specific to the interface type, or -1 to
|
|
|
|
* allocate the next available number
|
|
|
|
* @blksz: Block size of the device in bytes (typically 512)
|
2017-06-09 14:45:18 +00:00
|
|
|
* @lba: Total number of blocks of the device
|
2016-05-01 17:36:29 +00:00
|
|
|
* @devp: the new device (which has not been probed)
|
|
|
|
*/
|
|
|
|
int blk_create_devicef(struct udevice *parent, const char *drv_name,
|
2022-09-17 15:00:09 +00:00
|
|
|
const char *name, int uclass_id, int devnum, int blksz,
|
2017-06-09 14:45:18 +00:00
|
|
|
lbaint_t lba, struct udevice **devp);
|
2016-05-01 17:36:29 +00:00
|
|
|
|
2021-12-10 06:49:29 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2016-02-29 22:25:55 +00:00
|
|
|
/**
|
|
|
|
* blk_unbind_all() - Unbind all device of the given interface type
|
|
|
|
*
|
|
|
|
* The devices are removed and then unbound.
|
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* @uclass_id: Interface type to unbind
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if OK, -ve on error
|
2016-02-29 22:25:55 +00:00
|
|
|
*/
|
2022-09-17 15:00:09 +00:00
|
|
|
int blk_unbind_all(int uclass_id);
|
2016-02-29 22:25:55 +00:00
|
|
|
|
2016-05-01 17:36:28 +00:00
|
|
|
/**
|
|
|
|
* blk_find_max_devnum() - find the maximum device number for an interface type
|
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* Finds the last allocated device number for an interface type @uclass_id. The
|
2016-05-01 17:36:28 +00:00
|
|
|
* next number is safe to use for a newly allocated device.
|
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* @uclass_id: Interface type to scan
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: maximum device number found, or -ENODEV if none, or other -ve on
|
2016-05-01 17:36:28 +00:00
|
|
|
* error
|
|
|
|
*/
|
2022-09-17 15:00:09 +00:00
|
|
|
int blk_find_max_devnum(enum uclass_id uclass_id);
|
2016-05-01 17:36:28 +00:00
|
|
|
|
2018-10-15 09:21:09 +00:00
|
|
|
/**
|
|
|
|
* blk_next_free_devnum() - get the next device number for an interface type
|
|
|
|
*
|
|
|
|
* Finds the next number that is safe to use for a newly allocated device for
|
2022-09-17 15:00:09 +00:00
|
|
|
* an interface type @uclass_id.
|
2018-10-15 09:21:09 +00:00
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* @uclass_id: Interface type to scan
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: next device number safe to use, or -ve on error
|
2018-10-15 09:21:09 +00:00
|
|
|
*/
|
2022-09-17 15:00:09 +00:00
|
|
|
int blk_next_free_devnum(enum uclass_id uclass_id);
|
2018-10-15 09:21:09 +00:00
|
|
|
|
2016-05-01 19:52:30 +00:00
|
|
|
/**
|
|
|
|
* blk_select_hwpart() - select a hardware partition
|
|
|
|
*
|
|
|
|
* Select a hardware partition if the device supports it (typically MMC does)
|
|
|
|
*
|
|
|
|
* @dev: Device to update
|
|
|
|
* @hwpart: Partition number to select
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if OK, -ve on error
|
2016-05-01 19:52:30 +00:00
|
|
|
*/
|
|
|
|
int blk_select_hwpart(struct udevice *dev, int hwpart);
|
|
|
|
|
2022-10-30 01:47:14 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2017-06-10 14:01:05 +00:00
|
|
|
/**
|
|
|
|
* blk_get_from_parent() - obtain a block device by looking up its parent
|
|
|
|
*
|
2022-10-30 01:47:14 +00:00
|
|
|
* 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
|
2017-06-10 14:01:05 +00:00
|
|
|
*/
|
|
|
|
int blk_get_from_parent(struct udevice *parent, struct udevice **devp);
|
|
|
|
|
2022-04-25 05:31:03 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2018-07-06 08:26:36 +00:00
|
|
|
/**
|
|
|
|
* blk_get_by_device() - Get the block device descriptor for the given device
|
2022-10-21 00:22:54 +00:00
|
|
|
* @dev: Instance of a storage device (the parent of the block device)
|
2018-07-06 08:26:36 +00:00
|
|
|
*
|
|
|
|
* Return: With block device descriptor on success , NULL if there is no such
|
|
|
|
* block device.
|
|
|
|
*/
|
|
|
|
struct blk_desc *blk_get_by_device(struct udevice *dev);
|
|
|
|
|
2016-02-29 22:25:55 +00:00
|
|
|
#else
|
|
|
|
#include <errno.h>
|
2016-02-29 22:25:52 +00:00
|
|
|
/*
|
|
|
|
* These functions should take struct udevice instead of struct blk_desc,
|
|
|
|
* but this is convenient for migration to driver model. Add a 'd' prefix
|
|
|
|
* to the function operations, so that blk_read(), etc. can be reserved for
|
|
|
|
* functions with the correct arguments.
|
|
|
|
*/
|
|
|
|
static inline ulong blk_dread(struct blk_desc *block_dev, lbaint_t start,
|
|
|
|
lbaint_t blkcnt, void *buffer)
|
|
|
|
{
|
2016-03-28 17:05:44 +00:00
|
|
|
ulong blks_read;
|
2022-09-17 15:00:09 +00:00
|
|
|
if (blkcache_read(block_dev->uclass_id, block_dev->devnum,
|
2016-03-28 17:05:44 +00:00
|
|
|
start, blkcnt, block_dev->blksz, buffer))
|
|
|
|
return blkcnt;
|
|
|
|
|
2016-02-29 22:25:52 +00:00
|
|
|
/*
|
|
|
|
* We could check if block_read is NULL and return -ENOSYS. But this
|
|
|
|
* bloats the code slightly (cause some board to fail to build), and
|
|
|
|
* it would be an error to try an operation that does not exist.
|
|
|
|
*/
|
2016-03-28 17:05:44 +00:00
|
|
|
blks_read = block_dev->block_read(block_dev, start, blkcnt, buffer);
|
|
|
|
if (blks_read == blkcnt)
|
2022-09-17 15:00:09 +00:00
|
|
|
blkcache_fill(block_dev->uclass_id, block_dev->devnum,
|
2016-03-28 17:05:44 +00:00
|
|
|
start, blkcnt, block_dev->blksz, buffer);
|
|
|
|
|
|
|
|
return blks_read;
|
2016-02-29 22:25:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline ulong blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
|
|
|
|
lbaint_t blkcnt, const void *buffer)
|
|
|
|
{
|
2022-09-17 15:00:09 +00:00
|
|
|
blkcache_invalidate(block_dev->uclass_id, block_dev->devnum);
|
2016-02-29 22:25:52 +00:00
|
|
|
return block_dev->block_write(block_dev, start, blkcnt, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline ulong blk_derase(struct blk_desc *block_dev, lbaint_t start,
|
|
|
|
lbaint_t blkcnt)
|
|
|
|
{
|
2022-09-17 15:00:09 +00:00
|
|
|
blkcache_invalidate(block_dev->uclass_id, block_dev->devnum);
|
2016-02-29 22:25:52 +00:00
|
|
|
return block_dev->block_erase(block_dev, start, blkcnt);
|
|
|
|
}
|
2016-05-01 17:36:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* struct blk_driver - Driver for block interface types
|
|
|
|
*
|
|
|
|
* This provides access to the block devices for each interface type. One
|
|
|
|
* driver should be provided using U_BOOT_LEGACY_BLK() for each interface
|
|
|
|
* type that is to be supported.
|
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* @uclass_idname: Interface type name
|
|
|
|
* @uclass_id: Interface type
|
2016-05-01 17:36:03 +00:00
|
|
|
* @max_devs: Maximum number of devices supported
|
|
|
|
* @desc: Pointer to list of devices for this interface type,
|
|
|
|
* or NULL to use @get_dev() instead
|
|
|
|
*/
|
|
|
|
struct blk_driver {
|
2022-09-17 15:00:09 +00:00
|
|
|
const char *uclass_idname;
|
|
|
|
enum uclass_id uclass_id;
|
2016-05-01 17:36:03 +00:00
|
|
|
int max_devs;
|
|
|
|
struct blk_desc *desc;
|
|
|
|
/**
|
|
|
|
* get_dev() - get a pointer to a block device given its number
|
|
|
|
*
|
|
|
|
* Each interface allocates its own devices and typically
|
|
|
|
* struct blk_desc is contained with the interface's data structure.
|
|
|
|
* There is no global numbering for block devices. This method allows
|
|
|
|
* the device for an interface type to be obtained when @desc is NULL.
|
|
|
|
*
|
|
|
|
* @devnum: Device number (0 for first device on that interface,
|
|
|
|
* 1 for second, etc.
|
|
|
|
* @descp: Returns pointer to the block device on success
|
|
|
|
* @return 0 if OK, -ve on error
|
|
|
|
*/
|
|
|
|
int (*get_dev)(int devnum, struct blk_desc **descp);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* select_hwpart() - Select a hardware partition
|
|
|
|
*
|
|
|
|
* Some devices (e.g. MMC) can support partitioning at the hardware
|
|
|
|
* level. This is quite separate from the normal idea of
|
|
|
|
* software-based partitions. MMC hardware partitions must be
|
|
|
|
* explicitly selected. Once selected only the region of the device
|
|
|
|
* covered by that partition is accessible.
|
|
|
|
*
|
|
|
|
* The MMC standard provides for two boot partitions (numbered 1 and 2),
|
|
|
|
* rpmb (3), and up to 4 addition general-purpose partitions (4-7).
|
|
|
|
* Partition 0 is the main user-data partition.
|
|
|
|
*
|
|
|
|
* @desc: Block device descriptor
|
|
|
|
* @hwpart: Hardware partition number to select. 0 means the main
|
|
|
|
* user-data partition, 1 is the first partition, 2 is
|
|
|
|
* the second, etc.
|
|
|
|
* @return 0 if OK, other value for an error
|
|
|
|
*/
|
|
|
|
int (*select_hwpart)(struct blk_desc *desc, int hwpart);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Declare a new U-Boot legacy block driver. New drivers should use driver
|
|
|
|
* model (UCLASS_BLK).
|
|
|
|
*/
|
|
|
|
#define U_BOOT_LEGACY_BLK(__name) \
|
|
|
|
ll_entry_declare(struct blk_driver, __name, blk_driver)
|
|
|
|
|
2022-09-17 15:00:09 +00:00
|
|
|
struct blk_driver *blk_driver_lookup_type(int uclass_id);
|
2016-05-01 17:36:03 +00:00
|
|
|
|
2016-02-29 22:25:55 +00:00
|
|
|
#endif /* !CONFIG_BLK */
|
2016-02-29 22:25:52 +00:00
|
|
|
|
2016-05-01 17:36:03 +00:00
|
|
|
/**
|
2022-09-17 15:00:09 +00:00
|
|
|
* blk_get_devnum_by_uclass_idname() - Get a block device by type and number
|
2016-05-01 17:36:03 +00:00
|
|
|
*
|
|
|
|
* This looks through the available block devices of the given type, returning
|
|
|
|
* the one with the given @devnum.
|
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* @uclass_id: Block device type
|
2016-05-01 17:36:03 +00:00
|
|
|
* @devnum: Device number
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: point to block device descriptor, or NULL if not found
|
2016-05-01 17:36:03 +00:00
|
|
|
*/
|
2022-09-17 15:00:09 +00:00
|
|
|
struct blk_desc *blk_get_devnum_by_uclass_id(enum uclass_id uclass_id, int devnum);
|
2016-05-01 17:36:03 +00:00
|
|
|
|
|
|
|
/**
|
2022-09-17 15:00:09 +00:00
|
|
|
* blk_get_devnum_by_uclass_id() - Get a block device by type name, and number
|
2016-05-01 17:36:03 +00:00
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* This looks up the block device type based on @uclass_idname, then calls
|
|
|
|
* blk_get_devnum_by_uclass_id().
|
2016-05-01 17:36:03 +00:00
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* @uclass_idname: Block device type name
|
2016-05-01 17:36:03 +00:00
|
|
|
* @devnum: Device number
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: point to block device descriptor, or NULL if not found
|
2016-05-01 17:36:03 +00:00
|
|
|
*/
|
2022-09-17 15:00:09 +00:00
|
|
|
struct blk_desc *blk_get_devnum_by_uclass_idname(const char *uclass_idname,
|
2016-05-01 17:36:03 +00:00
|
|
|
int devnum);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* blk_dselect_hwpart() - select a hardware partition
|
|
|
|
*
|
|
|
|
* This selects a hardware partition (such as is supported by MMC). The block
|
|
|
|
* device size may change as this effectively points the block device to a
|
|
|
|
* partition at the hardware level. See the select_hwpart() method above.
|
|
|
|
*
|
|
|
|
* @desc: Block device descriptor for the device to select
|
|
|
|
* @hwpart: Partition number to select
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if OK, -ve on error
|
2016-05-01 17:36:03 +00:00
|
|
|
*/
|
|
|
|
int blk_dselect_hwpart(struct blk_desc *desc, int hwpart);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* blk_list_part() - list the partitions for block devices of a given type
|
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* This looks up the partition type for each block device of type @uclass_id,
|
2016-05-01 17:36:03 +00:00
|
|
|
* then displays a list of partitions.
|
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* @uclass_id: Block device type
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if OK, -ENODEV if there is none of that type
|
2016-05-01 17:36:03 +00:00
|
|
|
*/
|
2022-09-17 15:00:09 +00:00
|
|
|
int blk_list_part(enum uclass_id uclass_id);
|
2016-05-01 17:36:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* blk_list_devices() - list the block devices of a given type
|
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* This lists each block device of the type @uclass_id, showing the capacity
|
2016-05-01 17:36:03 +00:00
|
|
|
* as well as type-specific information.
|
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* @uclass_id: Block device type
|
2016-05-01 17:36:03 +00:00
|
|
|
*/
|
2022-09-17 15:00:09 +00:00
|
|
|
void blk_list_devices(enum uclass_id uclass_id);
|
2016-05-01 17:36:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* blk_show_device() - show information about a given block device
|
|
|
|
*
|
|
|
|
* This shows the block device capacity as well as type-specific information.
|
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* @uclass_id: Block device type
|
2016-05-01 17:36:03 +00:00
|
|
|
* @devnum: Device number
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if OK, -ENODEV for invalid device number
|
2016-05-01 17:36:03 +00:00
|
|
|
*/
|
2022-09-17 15:00:09 +00:00
|
|
|
int blk_show_device(enum uclass_id uclass_id, int devnum);
|
2016-05-01 17:36:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* blk_print_device_num() - show information about a given block device
|
|
|
|
*
|
|
|
|
* This is similar to blk_show_device() but returns an error if the block
|
|
|
|
* device type is unknown.
|
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* @uclass_id: Block device type
|
2016-05-01 17:36:03 +00:00
|
|
|
* @devnum: Device number
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if OK, -ENODEV for invalid device number, -ENOENT if the block
|
2016-05-01 17:36:03 +00:00
|
|
|
* device is not connected
|
|
|
|
*/
|
2022-09-17 15:00:09 +00:00
|
|
|
int blk_print_device_num(enum uclass_id uclass_id, int devnum);
|
2016-05-01 17:36:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* blk_print_part_devnum() - print the partition information for a device
|
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* @uclass_id: Block device type
|
2016-05-01 17:36:03 +00:00
|
|
|
* @devnum: Device number
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if OK, -ENOENT if the block device is not connected, -ENOSYS if
|
2016-05-01 17:36:03 +00:00
|
|
|
* the interface type is not supported, other -ve on other error
|
|
|
|
*/
|
2022-09-17 15:00:09 +00:00
|
|
|
int blk_print_part_devnum(enum uclass_id uclass_id, int devnum);
|
2016-05-01 17:36:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* blk_read_devnum() - read blocks from a device
|
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* @uclass_id: Block device type
|
2016-05-01 17:36:03 +00:00
|
|
|
* @devnum: Device number
|
2022-10-17 07:35:04 +00:00
|
|
|
* @start: Start block number to read (0=first)
|
2016-05-01 17:36:03 +00:00
|
|
|
* @blkcnt: Number of blocks to read
|
|
|
|
* @buffer: Address to write data to
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: number of blocks read, or -ve error number on error
|
2016-05-01 17:36:03 +00:00
|
|
|
*/
|
2022-09-17 15:00:09 +00:00
|
|
|
ulong blk_read_devnum(enum uclass_id uclass_id, int devnum, lbaint_t start,
|
2016-05-01 17:36:03 +00:00
|
|
|
lbaint_t blkcnt, void *buffer);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* blk_write_devnum() - write blocks to a device
|
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* @uclass_id: Block device type
|
2016-05-01 17:36:03 +00:00
|
|
|
* @devnum: Device number
|
2022-10-17 07:35:04 +00:00
|
|
|
* @start: Start block number to write (0=first)
|
2016-05-01 17:36:03 +00:00
|
|
|
* @blkcnt: Number of blocks to write
|
|
|
|
* @buffer: Address to read data from
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: number of blocks written, or -ve error number on error
|
2016-05-01 17:36:03 +00:00
|
|
|
*/
|
2022-09-17 15:00:09 +00:00
|
|
|
ulong blk_write_devnum(enum uclass_id uclass_id, int devnum, lbaint_t start,
|
2016-05-01 17:36:03 +00:00
|
|
|
lbaint_t blkcnt, const void *buffer);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* blk_select_hwpart_devnum() - select a hardware partition
|
|
|
|
*
|
|
|
|
* This is similar to blk_dselect_hwpart() but it looks up the interface and
|
|
|
|
* device number.
|
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* @uclass_id: Block device type
|
2016-05-01 17:36:03 +00:00
|
|
|
* @devnum: Device number
|
|
|
|
* @hwpart: Partition number to select
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if OK, -ve on error
|
2016-05-01 17:36:03 +00:00
|
|
|
*/
|
2022-09-17 15:00:09 +00:00
|
|
|
int blk_select_hwpart_devnum(enum uclass_id uclass_id, int devnum, int hwpart);
|
2016-05-01 17:36:03 +00:00
|
|
|
|
2017-07-29 17:34:53 +00:00
|
|
|
/**
|
2022-09-17 15:00:09 +00:00
|
|
|
* blk_get_uclass_name() - Get the name of an interface type
|
2017-07-29 17:34:53 +00:00
|
|
|
*
|
2022-09-17 15:00:09 +00:00
|
|
|
* @uclass_id: Interface type to check
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: name of interface, or NULL if none
|
2017-07-29 17:34:53 +00:00
|
|
|
*/
|
2022-09-17 15:00:09 +00:00
|
|
|
const char *blk_get_uclass_name(enum uclass_id uclass_id);
|
2017-07-29 17:34:53 +00:00
|
|
|
|
2017-07-29 17:34:54 +00:00
|
|
|
/**
|
|
|
|
* blk_common_cmd() - handle common commands with block devices
|
|
|
|
*
|
|
|
|
* @args: Number of arguments to the command (argv[0] is the command itself)
|
|
|
|
* @argv: Command arguments
|
2022-09-17 15:00:09 +00:00
|
|
|
* @uclass_id: Interface type
|
2017-07-29 17:34:54 +00:00
|
|
|
* @cur_devnump: Current device number for this interface type
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if OK, CMD_RET_ERROR on error
|
2017-07-29 17:34:54 +00:00
|
|
|
*/
|
2022-09-17 15:00:09 +00:00
|
|
|
int blk_common_cmd(int argc, char *const argv[], enum uclass_id uclass_id,
|
2017-07-29 17:34:54 +00:00
|
|
|
int *cur_devnump);
|
|
|
|
|
2021-07-05 22:32:59 +00:00
|
|
|
enum blk_flag_t {
|
|
|
|
BLKF_FIXED = 1 << 0,
|
|
|
|
BLKF_REMOVABLE = 1 << 1,
|
|
|
|
BLKF_BOTH = BLKF_FIXED | BLKF_REMOVABLE,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* blk_first_device_err() - Get the first block device
|
|
|
|
*
|
|
|
|
* The device returned is probed if necessary, and ready for use
|
|
|
|
*
|
|
|
|
* @flags: Indicates type of device to return
|
|
|
|
* @devp: Returns pointer to the first device in that uclass, or NULL if none
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if found, -ENODEV if not found, other -ve on error
|
2021-07-05 22:32:59 +00:00
|
|
|
*/
|
|
|
|
int blk_first_device_err(enum blk_flag_t flags, struct udevice **devp);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* blk_next_device_err() - Get the next block device
|
|
|
|
*
|
|
|
|
* The device returned is probed if necessary, and ready for use
|
|
|
|
*
|
|
|
|
* @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 uclass if no error occurred, or -ENODEV if
|
|
|
|
* there is no next device.
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: 0 if found, -ENODEV if not found, other -ve on error
|
2021-07-05 22:32:59 +00:00
|
|
|
*/
|
|
|
|
int blk_next_device_err(enum blk_flag_t flags, struct udevice **devp);
|
|
|
|
|
2022-02-28 19:08:35 +00:00
|
|
|
/**
|
|
|
|
* 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))
|
|
|
|
|
2021-07-05 22:32:59 +00:00
|
|
|
/**
|
|
|
|
* blk_foreach_probe() - Helper function to iteration through block devices
|
|
|
|
*
|
|
|
|
* This creates a for() loop which works through the available devices in
|
|
|
|
* a uclass in order from start to end. Devices are probed if necessary,
|
|
|
|
* and ready for use.
|
|
|
|
*
|
|
|
|
* @flags: Indicates type of device to return
|
|
|
|
* @dev: struct udevice * to hold the current device. Set to NULL when there
|
|
|
|
* are no more devices.
|
|
|
|
*/
|
|
|
|
#define blk_foreach_probe(flags, pos) \
|
|
|
|
for (int _ret = blk_first_device_err(flags, &(pos)); \
|
|
|
|
!_ret && pos; \
|
|
|
|
_ret = blk_next_device_err(flags, &(pos)))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* blk_count_devices() - count the number of devices of a particular type
|
|
|
|
*
|
|
|
|
* @flags: Indicates type of device to find
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: number of devices matching those flags
|
2021-07-05 22:32:59 +00:00
|
|
|
*/
|
|
|
|
int blk_count_devices(enum blk_flag_t flag);
|
|
|
|
|
2016-02-29 22:25:39 +00:00
|
|
|
#endif
|