11a73661bSSimon Glass /* 21a73661bSSimon Glass * (C) Copyright 2000-2004 31a73661bSSimon Glass * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 41a73661bSSimon Glass * 51a73661bSSimon Glass * SPDX-License-Identifier: GPL-2.0+ 61a73661bSSimon Glass */ 71a73661bSSimon Glass 81a73661bSSimon Glass #ifndef BLK_H 91a73661bSSimon Glass #define BLK_H 101a73661bSSimon Glass 111a73661bSSimon Glass #ifdef CONFIG_SYS_64BIT_LBA 121a73661bSSimon Glass typedef uint64_t lbaint_t; 131a73661bSSimon Glass #define LBAFlength "ll" 141a73661bSSimon Glass #else 151a73661bSSimon Glass typedef ulong lbaint_t; 161a73661bSSimon Glass #define LBAFlength "l" 171a73661bSSimon Glass #endif 181a73661bSSimon Glass #define LBAF "%" LBAFlength "x" 191a73661bSSimon Glass #define LBAFU "%" LBAFlength "u" 201a73661bSSimon Glass 211a73661bSSimon Glass /* Interface types: */ 225ec4f1a5SSimon Glass enum if_type { 235ec4f1a5SSimon Glass IF_TYPE_UNKNOWN = 0, 245ec4f1a5SSimon Glass IF_TYPE_IDE, 255ec4f1a5SSimon Glass IF_TYPE_SCSI, 265ec4f1a5SSimon Glass IF_TYPE_ATAPI, 275ec4f1a5SSimon Glass IF_TYPE_USB, 285ec4f1a5SSimon Glass IF_TYPE_DOC, 295ec4f1a5SSimon Glass IF_TYPE_MMC, 305ec4f1a5SSimon Glass IF_TYPE_SD, 315ec4f1a5SSimon Glass IF_TYPE_SATA, 325ec4f1a5SSimon Glass IF_TYPE_HOST, 335ec4f1a5SSimon Glass 345ec4f1a5SSimon Glass IF_TYPE_COUNT, /* Number of interface types */ 355ec4f1a5SSimon Glass }; 361a73661bSSimon Glass 3709d71aacSSimon Glass /* 3809d71aacSSimon Glass * With driver model (CONFIG_BLK) this is uclass platform data, accessible 3909d71aacSSimon Glass * with dev_get_uclass_platdata(dev) 4009d71aacSSimon Glass */ 411a73661bSSimon Glass struct blk_desc { 4209d71aacSSimon Glass /* 4309d71aacSSimon Glass * TODO: With driver model we should be able to use the parent 4409d71aacSSimon Glass * device's uclass instead. 4509d71aacSSimon Glass */ 465ec4f1a5SSimon Glass enum if_type if_type; /* type of the interface */ 47bcce53d0SSimon Glass int devnum; /* device number */ 481a73661bSSimon Glass unsigned char part_type; /* partition type */ 491a73661bSSimon Glass unsigned char target; /* target SCSI ID */ 501a73661bSSimon Glass unsigned char lun; /* target LUN */ 511a73661bSSimon Glass unsigned char hwpart; /* HW partition, e.g. for eMMC */ 521a73661bSSimon Glass unsigned char type; /* device type */ 531a73661bSSimon Glass unsigned char removable; /* removable device */ 541a73661bSSimon Glass #ifdef CONFIG_LBA48 551a73661bSSimon Glass /* device can use 48bit addr (ATA/ATAPI v7) */ 561a73661bSSimon Glass unsigned char lba48; 571a73661bSSimon Glass #endif 581a73661bSSimon Glass lbaint_t lba; /* number of blocks */ 591a73661bSSimon Glass unsigned long blksz; /* block size */ 601a73661bSSimon Glass int log2blksz; /* for convenience: log2(blksz) */ 611a73661bSSimon Glass char vendor[40+1]; /* IDE model, SCSI Vendor */ 621a73661bSSimon Glass char product[20+1]; /* IDE Serial no, SCSI product */ 631a73661bSSimon Glass char revision[8+1]; /* firmware revision */ 6409d71aacSSimon Glass #ifdef CONFIG_BLK 6509d71aacSSimon Glass struct udevice *bdev; 6609d71aacSSimon Glass #else 671a73661bSSimon Glass unsigned long (*block_read)(struct blk_desc *block_dev, 681a73661bSSimon Glass lbaint_t start, 691a73661bSSimon Glass lbaint_t blkcnt, 701a73661bSSimon Glass void *buffer); 711a73661bSSimon Glass unsigned long (*block_write)(struct blk_desc *block_dev, 721a73661bSSimon Glass lbaint_t start, 731a73661bSSimon Glass lbaint_t blkcnt, 741a73661bSSimon Glass const void *buffer); 751a73661bSSimon Glass unsigned long (*block_erase)(struct blk_desc *block_dev, 761a73661bSSimon Glass lbaint_t start, 771a73661bSSimon Glass lbaint_t blkcnt); 781a73661bSSimon Glass void *priv; /* driver private struct pointer */ 7909d71aacSSimon Glass #endif 801a73661bSSimon Glass }; 811a73661bSSimon Glass 821a73661bSSimon Glass #define BLOCK_CNT(size, blk_desc) (PAD_COUNT(size, blk_desc->blksz)) 831a73661bSSimon Glass #define PAD_TO_BLOCKSIZE(size, blk_desc) \ 841a73661bSSimon Glass (PAD_SIZE(size, blk_desc->blksz)) 851a73661bSSimon Glass 86e40cf34aSEric Nelson #ifdef CONFIG_BLOCK_CACHE 87e40cf34aSEric Nelson /** 88e40cf34aSEric Nelson * blkcache_read() - attempt to read a set of blocks from cache 89e40cf34aSEric Nelson * 90e40cf34aSEric Nelson * @param iftype - IF_TYPE_x for type of device 91e40cf34aSEric Nelson * @param dev - device index of particular type 92e40cf34aSEric Nelson * @param start - starting block number 93e40cf34aSEric Nelson * @param blkcnt - number of blocks to read 94e40cf34aSEric Nelson * @param blksz - size in bytes of each block 95e40cf34aSEric Nelson * @param buf - buffer to contain cached data 96e40cf34aSEric Nelson * 97e40cf34aSEric Nelson * @return - '1' if block returned from cache, '0' otherwise. 98e40cf34aSEric Nelson */ 99c8e4d2a8SEric Nelson int blkcache_read(int iftype, int dev, 100e40cf34aSEric Nelson lbaint_t start, lbaint_t blkcnt, 101e40cf34aSEric Nelson unsigned long blksz, void *buffer); 102e40cf34aSEric Nelson 103e40cf34aSEric Nelson /** 104e40cf34aSEric Nelson * blkcache_fill() - make data read from a block device available 105e40cf34aSEric Nelson * to the block cache 106e40cf34aSEric Nelson * 107e40cf34aSEric Nelson * @param iftype - IF_TYPE_x for type of device 108e40cf34aSEric Nelson * @param dev - device index of particular type 109e40cf34aSEric Nelson * @param start - starting block number 110e40cf34aSEric Nelson * @param blkcnt - number of blocks available 111e40cf34aSEric Nelson * @param blksz - size in bytes of each block 112e40cf34aSEric Nelson * @param buf - buffer containing data to cache 113e40cf34aSEric Nelson * 114e40cf34aSEric Nelson */ 115c8e4d2a8SEric Nelson void blkcache_fill(int iftype, int dev, 116e40cf34aSEric Nelson lbaint_t start, lbaint_t blkcnt, 117e40cf34aSEric Nelson unsigned long blksz, void const *buffer); 118e40cf34aSEric Nelson 119e40cf34aSEric Nelson /** 120e40cf34aSEric Nelson * blkcache_invalidate() - discard the cache for a set of blocks 121e40cf34aSEric Nelson * because of a write or device (re)initialization. 122e40cf34aSEric Nelson * 123e40cf34aSEric Nelson * @param iftype - IF_TYPE_x for type of device 124e40cf34aSEric Nelson * @param dev - device index of particular type 125e40cf34aSEric Nelson */ 126c8e4d2a8SEric Nelson void blkcache_invalidate(int iftype, int dev); 127e40cf34aSEric Nelson 128e40cf34aSEric Nelson /** 129e40cf34aSEric Nelson * blkcache_configure() - configure block cache 130e40cf34aSEric Nelson * 131e40cf34aSEric Nelson * @param blocks - maximum blocks per entry 132e40cf34aSEric Nelson * @param entries - maximum entries in cache 133e40cf34aSEric Nelson */ 134e40cf34aSEric Nelson void blkcache_configure(unsigned blocks, unsigned entries); 135e40cf34aSEric Nelson 136e40cf34aSEric Nelson /* 137e40cf34aSEric Nelson * statistics of the block cache 138e40cf34aSEric Nelson */ 139e40cf34aSEric Nelson struct block_cache_stats { 140e40cf34aSEric Nelson unsigned hits; 141e40cf34aSEric Nelson unsigned misses; 142e40cf34aSEric Nelson unsigned entries; /* current entry count */ 143e40cf34aSEric Nelson unsigned max_blocks_per_entry; 144e40cf34aSEric Nelson unsigned max_entries; 145e40cf34aSEric Nelson }; 146e40cf34aSEric Nelson 147e40cf34aSEric Nelson /** 148e40cf34aSEric Nelson * get_blkcache_stats() - return statistics and reset 149e40cf34aSEric Nelson * 150e40cf34aSEric Nelson * @param stats - statistics are copied here 151e40cf34aSEric Nelson */ 152e40cf34aSEric Nelson void blkcache_stats(struct block_cache_stats *stats); 153e40cf34aSEric Nelson 154e40cf34aSEric Nelson #else 155e40cf34aSEric Nelson 156c8e4d2a8SEric Nelson static inline int blkcache_read(int iftype, int dev, 157e40cf34aSEric Nelson lbaint_t start, lbaint_t blkcnt, 158e40cf34aSEric Nelson unsigned long blksz, void *buffer) 159e40cf34aSEric Nelson { 160e40cf34aSEric Nelson return 0; 161e40cf34aSEric Nelson } 162e40cf34aSEric Nelson 163c8e4d2a8SEric Nelson static inline void blkcache_fill(int iftype, int dev, 164e40cf34aSEric Nelson lbaint_t start, lbaint_t blkcnt, 165e40cf34aSEric Nelson unsigned long blksz, void const *buffer) {} 166e40cf34aSEric Nelson 167c8e4d2a8SEric Nelson static inline void blkcache_invalidate(int iftype, int dev) {} 168e40cf34aSEric Nelson 169e40cf34aSEric Nelson #endif 170e40cf34aSEric Nelson 17109d71aacSSimon Glass #ifdef CONFIG_BLK 17209d71aacSSimon Glass struct udevice; 17309d71aacSSimon Glass 17409d71aacSSimon Glass /* Operations on block devices */ 17509d71aacSSimon Glass struct blk_ops { 17609d71aacSSimon Glass /** 17709d71aacSSimon Glass * read() - read from a block device 17809d71aacSSimon Glass * 17909d71aacSSimon Glass * @dev: Device to read from 18009d71aacSSimon Glass * @start: Start block number to read (0=first) 18109d71aacSSimon Glass * @blkcnt: Number of blocks to read 18209d71aacSSimon Glass * @buffer: Destination buffer for data read 18309d71aacSSimon Glass * @return number of blocks read, or -ve error number (see the 18409d71aacSSimon Glass * IS_ERR_VALUE() macro 18509d71aacSSimon Glass */ 18609d71aacSSimon Glass unsigned long (*read)(struct udevice *dev, lbaint_t start, 18709d71aacSSimon Glass lbaint_t blkcnt, void *buffer); 18809d71aacSSimon Glass 18909d71aacSSimon Glass /** 19009d71aacSSimon Glass * write() - write to a block device 19109d71aacSSimon Glass * 19209d71aacSSimon Glass * @dev: Device to write to 19309d71aacSSimon Glass * @start: Start block number to write (0=first) 19409d71aacSSimon Glass * @blkcnt: Number of blocks to write 19509d71aacSSimon Glass * @buffer: Source buffer for data to write 19609d71aacSSimon Glass * @return number of blocks written, or -ve error number (see the 19709d71aacSSimon Glass * IS_ERR_VALUE() macro 19809d71aacSSimon Glass */ 19909d71aacSSimon Glass unsigned long (*write)(struct udevice *dev, lbaint_t start, 20009d71aacSSimon Glass lbaint_t blkcnt, const void *buffer); 20109d71aacSSimon Glass 20209d71aacSSimon Glass /** 20309d71aacSSimon Glass * erase() - erase a section of a block device 20409d71aacSSimon Glass * 20509d71aacSSimon Glass * @dev: Device to (partially) erase 20609d71aacSSimon Glass * @start: Start block number to erase (0=first) 20709d71aacSSimon Glass * @blkcnt: Number of blocks to erase 20809d71aacSSimon Glass * @return number of blocks erased, or -ve error number (see the 20909d71aacSSimon Glass * IS_ERR_VALUE() macro 21009d71aacSSimon Glass */ 21109d71aacSSimon Glass unsigned long (*erase)(struct udevice *dev, lbaint_t start, 21209d71aacSSimon Glass lbaint_t blkcnt); 21309d71aacSSimon Glass }; 21409d71aacSSimon Glass 21509d71aacSSimon Glass #define blk_get_ops(dev) ((struct blk_ops *)(dev)->driver->ops) 21609d71aacSSimon Glass 21709d71aacSSimon Glass /* 21809d71aacSSimon Glass * These functions should take struct udevice instead of struct blk_desc, 21909d71aacSSimon Glass * but this is convenient for migration to driver model. Add a 'd' prefix 22009d71aacSSimon Glass * to the function operations, so that blk_read(), etc. can be reserved for 22109d71aacSSimon Glass * functions with the correct arguments. 22209d71aacSSimon Glass */ 22309d71aacSSimon Glass unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start, 22409d71aacSSimon Glass lbaint_t blkcnt, void *buffer); 22509d71aacSSimon Glass unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start, 22609d71aacSSimon Glass lbaint_t blkcnt, const void *buffer); 22709d71aacSSimon Glass unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start, 22809d71aacSSimon Glass lbaint_t blkcnt); 22909d71aacSSimon Glass 23009d71aacSSimon Glass /** 23109d71aacSSimon Glass * blk_get_device() - Find and probe a block device ready for use 23209d71aacSSimon Glass * 23309d71aacSSimon Glass * @if_type: Interface type (enum if_type_t) 23409d71aacSSimon Glass * @devnum: Device number (specific to each interface type) 23509d71aacSSimon Glass * @devp: the device, if found 23609d71aacSSimon Glass * @return - if found, -ENODEV if no device found, or other -ve error value 23709d71aacSSimon Glass */ 23809d71aacSSimon Glass int blk_get_device(int if_type, int devnum, struct udevice **devp); 23909d71aacSSimon Glass 24009d71aacSSimon Glass /** 24109d71aacSSimon Glass * blk_first_device() - Find the first device for a given interface 24209d71aacSSimon Glass * 24309d71aacSSimon Glass * The device is probed ready for use 24409d71aacSSimon Glass * 24509d71aacSSimon Glass * @devnum: Device number (specific to each interface type) 24609d71aacSSimon Glass * @devp: the device, if found 24709d71aacSSimon Glass * @return 0 if found, -ENODEV if no device, or other -ve error value 24809d71aacSSimon Glass */ 24909d71aacSSimon Glass int blk_first_device(int if_type, struct udevice **devp); 25009d71aacSSimon Glass 25109d71aacSSimon Glass /** 25209d71aacSSimon Glass * blk_next_device() - Find the next device for a given interface 25309d71aacSSimon Glass * 25409d71aacSSimon Glass * This can be called repeatedly after blk_first_device() to iterate through 25509d71aacSSimon Glass * all devices of the given interface type. 25609d71aacSSimon Glass * 25709d71aacSSimon Glass * The device is probed ready for use 25809d71aacSSimon Glass * 25909d71aacSSimon Glass * @devp: On entry, the previous device returned. On exit, the next 26009d71aacSSimon Glass * device, if found 26109d71aacSSimon Glass * @return 0 if found, -ENODEV if no device, or other -ve error value 26209d71aacSSimon Glass */ 26309d71aacSSimon Glass int blk_next_device(struct udevice **devp); 26409d71aacSSimon Glass 26509d71aacSSimon Glass /** 26609d71aacSSimon Glass * blk_create_device() - Create a new block device 26709d71aacSSimon Glass * 26809d71aacSSimon Glass * @parent: Parent of the new device 26909d71aacSSimon Glass * @drv_name: Driver name to use for the block device 27009d71aacSSimon Glass * @name: Name for the device 27109d71aacSSimon Glass * @if_type: Interface type (enum if_type_t) 27209d71aacSSimon Glass * @devnum: Device number, specific to the interface type 27309d71aacSSimon Glass * @blksz: Block size of the device in bytes (typically 512) 27409d71aacSSimon Glass * @size: Total size of the device in bytes 27509d71aacSSimon Glass * @devp: the new device (which has not been probed) 27609d71aacSSimon Glass */ 27709d71aacSSimon Glass int blk_create_device(struct udevice *parent, const char *drv_name, 27809d71aacSSimon Glass const char *name, int if_type, int devnum, int blksz, 27909d71aacSSimon Glass lbaint_t size, struct udevice **devp); 28009d71aacSSimon Glass 28109d71aacSSimon Glass /** 28209d71aacSSimon Glass * blk_prepare_device() - Prepare a block device for use 28309d71aacSSimon Glass * 28409d71aacSSimon Glass * This reads partition information from the device if supported. 28509d71aacSSimon Glass * 28609d71aacSSimon Glass * @dev: Device to prepare 28709d71aacSSimon Glass * @return 0 if ok, -ve on error 28809d71aacSSimon Glass */ 28909d71aacSSimon Glass int blk_prepare_device(struct udevice *dev); 29009d71aacSSimon Glass 29109d71aacSSimon Glass /** 29209d71aacSSimon Glass * blk_unbind_all() - Unbind all device of the given interface type 29309d71aacSSimon Glass * 29409d71aacSSimon Glass * The devices are removed and then unbound. 29509d71aacSSimon Glass * 29609d71aacSSimon Glass * @if_type: Interface type to unbind 29709d71aacSSimon Glass * @return 0 if OK, -ve on error 29809d71aacSSimon Glass */ 29909d71aacSSimon Glass int blk_unbind_all(int if_type); 30009d71aacSSimon Glass 30109d71aacSSimon Glass #else 30209d71aacSSimon Glass #include <errno.h> 3032a981dc2SSimon Glass /* 3042a981dc2SSimon Glass * These functions should take struct udevice instead of struct blk_desc, 3052a981dc2SSimon Glass * but this is convenient for migration to driver model. Add a 'd' prefix 3062a981dc2SSimon Glass * to the function operations, so that blk_read(), etc. can be reserved for 3072a981dc2SSimon Glass * functions with the correct arguments. 3082a981dc2SSimon Glass */ 3092a981dc2SSimon Glass static inline ulong blk_dread(struct blk_desc *block_dev, lbaint_t start, 3102a981dc2SSimon Glass lbaint_t blkcnt, void *buffer) 3112a981dc2SSimon Glass { 312e40cf34aSEric Nelson ulong blks_read; 313e40cf34aSEric Nelson if (blkcache_read(block_dev->if_type, block_dev->devnum, 314e40cf34aSEric Nelson start, blkcnt, block_dev->blksz, buffer)) 315e40cf34aSEric Nelson return blkcnt; 316e40cf34aSEric Nelson 3172a981dc2SSimon Glass /* 3182a981dc2SSimon Glass * We could check if block_read is NULL and return -ENOSYS. But this 3192a981dc2SSimon Glass * bloats the code slightly (cause some board to fail to build), and 3202a981dc2SSimon Glass * it would be an error to try an operation that does not exist. 3212a981dc2SSimon Glass */ 322e40cf34aSEric Nelson blks_read = block_dev->block_read(block_dev, start, blkcnt, buffer); 323e40cf34aSEric Nelson if (blks_read == blkcnt) 324e40cf34aSEric Nelson blkcache_fill(block_dev->if_type, block_dev->devnum, 325e40cf34aSEric Nelson start, blkcnt, block_dev->blksz, buffer); 326e40cf34aSEric Nelson 327e40cf34aSEric Nelson return blks_read; 3282a981dc2SSimon Glass } 3292a981dc2SSimon Glass 3302a981dc2SSimon Glass static inline ulong blk_dwrite(struct blk_desc *block_dev, lbaint_t start, 3312a981dc2SSimon Glass lbaint_t blkcnt, const void *buffer) 3322a981dc2SSimon Glass { 333e40cf34aSEric Nelson blkcache_invalidate(block_dev->if_type, block_dev->devnum); 3342a981dc2SSimon Glass return block_dev->block_write(block_dev, start, blkcnt, buffer); 3352a981dc2SSimon Glass } 3362a981dc2SSimon Glass 3372a981dc2SSimon Glass static inline ulong blk_derase(struct blk_desc *block_dev, lbaint_t start, 3382a981dc2SSimon Glass lbaint_t blkcnt) 3392a981dc2SSimon Glass { 340e40cf34aSEric Nelson blkcache_invalidate(block_dev->if_type, block_dev->devnum); 3412a981dc2SSimon Glass return block_dev->block_erase(block_dev, start, blkcnt); 3422a981dc2SSimon Glass } 343*6eef6eacSSimon Glass 344*6eef6eacSSimon Glass /** 345*6eef6eacSSimon Glass * struct blk_driver - Driver for block interface types 346*6eef6eacSSimon Glass * 347*6eef6eacSSimon Glass * This provides access to the block devices for each interface type. One 348*6eef6eacSSimon Glass * driver should be provided using U_BOOT_LEGACY_BLK() for each interface 349*6eef6eacSSimon Glass * type that is to be supported. 350*6eef6eacSSimon Glass * 351*6eef6eacSSimon Glass * @if_typename: Interface type name 352*6eef6eacSSimon Glass * @if_type: Interface type 353*6eef6eacSSimon Glass * @max_devs: Maximum number of devices supported 354*6eef6eacSSimon Glass * @desc: Pointer to list of devices for this interface type, 355*6eef6eacSSimon Glass * or NULL to use @get_dev() instead 356*6eef6eacSSimon Glass */ 357*6eef6eacSSimon Glass struct blk_driver { 358*6eef6eacSSimon Glass const char *if_typename; 359*6eef6eacSSimon Glass enum if_type if_type; 360*6eef6eacSSimon Glass int max_devs; 361*6eef6eacSSimon Glass struct blk_desc *desc; 362*6eef6eacSSimon Glass /** 363*6eef6eacSSimon Glass * get_dev() - get a pointer to a block device given its number 364*6eef6eacSSimon Glass * 365*6eef6eacSSimon Glass * Each interface allocates its own devices and typically 366*6eef6eacSSimon Glass * struct blk_desc is contained with the interface's data structure. 367*6eef6eacSSimon Glass * There is no global numbering for block devices. This method allows 368*6eef6eacSSimon Glass * the device for an interface type to be obtained when @desc is NULL. 369*6eef6eacSSimon Glass * 370*6eef6eacSSimon Glass * @devnum: Device number (0 for first device on that interface, 371*6eef6eacSSimon Glass * 1 for second, etc. 372*6eef6eacSSimon Glass * @descp: Returns pointer to the block device on success 373*6eef6eacSSimon Glass * @return 0 if OK, -ve on error 374*6eef6eacSSimon Glass */ 375*6eef6eacSSimon Glass int (*get_dev)(int devnum, struct blk_desc **descp); 376*6eef6eacSSimon Glass 377*6eef6eacSSimon Glass /** 378*6eef6eacSSimon Glass * select_hwpart() - Select a hardware partition 379*6eef6eacSSimon Glass * 380*6eef6eacSSimon Glass * Some devices (e.g. MMC) can support partitioning at the hardware 381*6eef6eacSSimon Glass * level. This is quite separate from the normal idea of 382*6eef6eacSSimon Glass * software-based partitions. MMC hardware partitions must be 383*6eef6eacSSimon Glass * explicitly selected. Once selected only the region of the device 384*6eef6eacSSimon Glass * covered by that partition is accessible. 385*6eef6eacSSimon Glass * 386*6eef6eacSSimon Glass * The MMC standard provides for two boot partitions (numbered 1 and 2), 387*6eef6eacSSimon Glass * rpmb (3), and up to 4 addition general-purpose partitions (4-7). 388*6eef6eacSSimon Glass * Partition 0 is the main user-data partition. 389*6eef6eacSSimon Glass * 390*6eef6eacSSimon Glass * @desc: Block device descriptor 391*6eef6eacSSimon Glass * @hwpart: Hardware partition number to select. 0 means the main 392*6eef6eacSSimon Glass * user-data partition, 1 is the first partition, 2 is 393*6eef6eacSSimon Glass * the second, etc. 394*6eef6eacSSimon Glass * @return 0 if OK, other value for an error 395*6eef6eacSSimon Glass */ 396*6eef6eacSSimon Glass int (*select_hwpart)(struct blk_desc *desc, int hwpart); 397*6eef6eacSSimon Glass }; 398*6eef6eacSSimon Glass 399*6eef6eacSSimon Glass /* 400*6eef6eacSSimon Glass * Declare a new U-Boot legacy block driver. New drivers should use driver 401*6eef6eacSSimon Glass * model (UCLASS_BLK). 402*6eef6eacSSimon Glass */ 403*6eef6eacSSimon Glass #define U_BOOT_LEGACY_BLK(__name) \ 404*6eef6eacSSimon Glass ll_entry_declare(struct blk_driver, __name, blk_driver) 405*6eef6eacSSimon Glass 406*6eef6eacSSimon Glass struct blk_driver *blk_driver_lookup_type(int if_type); 407*6eef6eacSSimon Glass 40809d71aacSSimon Glass #endif /* !CONFIG_BLK */ 4092a981dc2SSimon Glass 410*6eef6eacSSimon Glass /** 411*6eef6eacSSimon Glass * blk_get_devnum_by_typename() - Get a block device by type and number 412*6eef6eacSSimon Glass * 413*6eef6eacSSimon Glass * This looks through the available block devices of the given type, returning 414*6eef6eacSSimon Glass * the one with the given @devnum. 415*6eef6eacSSimon Glass * 416*6eef6eacSSimon Glass * @if_type: Block device type 417*6eef6eacSSimon Glass * @devnum: Device number 418*6eef6eacSSimon Glass * @return point to block device descriptor, or NULL if not found 419*6eef6eacSSimon Glass */ 420*6eef6eacSSimon Glass struct blk_desc *blk_get_devnum_by_type(enum if_type if_type, int devnum); 421*6eef6eacSSimon Glass 422*6eef6eacSSimon Glass /** 423*6eef6eacSSimon Glass * blk_get_devnum_by_type() - Get a block device by type name, and number 424*6eef6eacSSimon Glass * 425*6eef6eacSSimon Glass * This looks up the block device type based on @if_typename, then calls 426*6eef6eacSSimon Glass * blk_get_devnum_by_type(). 427*6eef6eacSSimon Glass * 428*6eef6eacSSimon Glass * @if_typename: Block device type name 429*6eef6eacSSimon Glass * @devnum: Device number 430*6eef6eacSSimon Glass * @return point to block device descriptor, or NULL if not found 431*6eef6eacSSimon Glass */ 432*6eef6eacSSimon Glass struct blk_desc *blk_get_devnum_by_typename(const char *if_typename, 433*6eef6eacSSimon Glass int devnum); 434*6eef6eacSSimon Glass 435*6eef6eacSSimon Glass /** 436*6eef6eacSSimon Glass * blk_dselect_hwpart() - select a hardware partition 437*6eef6eacSSimon Glass * 438*6eef6eacSSimon Glass * This selects a hardware partition (such as is supported by MMC). The block 439*6eef6eacSSimon Glass * device size may change as this effectively points the block device to a 440*6eef6eacSSimon Glass * partition at the hardware level. See the select_hwpart() method above. 441*6eef6eacSSimon Glass * 442*6eef6eacSSimon Glass * @desc: Block device descriptor for the device to select 443*6eef6eacSSimon Glass * @hwpart: Partition number to select 444*6eef6eacSSimon Glass * @return 0 if OK, -ve on error 445*6eef6eacSSimon Glass */ 446*6eef6eacSSimon Glass int blk_dselect_hwpart(struct blk_desc *desc, int hwpart); 447*6eef6eacSSimon Glass 448*6eef6eacSSimon Glass /** 449*6eef6eacSSimon Glass * blk_list_part() - list the partitions for block devices of a given type 450*6eef6eacSSimon Glass * 451*6eef6eacSSimon Glass * This looks up the partition type for each block device of type @if_type, 452*6eef6eacSSimon Glass * then displays a list of partitions. 453*6eef6eacSSimon Glass * 454*6eef6eacSSimon Glass * @if_type: Block device type 455*6eef6eacSSimon Glass * @return 0 if OK, -ENODEV if there is none of that type 456*6eef6eacSSimon Glass */ 457*6eef6eacSSimon Glass int blk_list_part(enum if_type if_type); 458*6eef6eacSSimon Glass 459*6eef6eacSSimon Glass /** 460*6eef6eacSSimon Glass * blk_list_devices() - list the block devices of a given type 461*6eef6eacSSimon Glass * 462*6eef6eacSSimon Glass * This lists each block device of the type @if_type, showing the capacity 463*6eef6eacSSimon Glass * as well as type-specific information. 464*6eef6eacSSimon Glass * 465*6eef6eacSSimon Glass * @if_type: Block device type 466*6eef6eacSSimon Glass */ 467*6eef6eacSSimon Glass void blk_list_devices(enum if_type if_type); 468*6eef6eacSSimon Glass 469*6eef6eacSSimon Glass /** 470*6eef6eacSSimon Glass * blk_show_device() - show information about a given block device 471*6eef6eacSSimon Glass * 472*6eef6eacSSimon Glass * This shows the block device capacity as well as type-specific information. 473*6eef6eacSSimon Glass * 474*6eef6eacSSimon Glass * @if_type: Block device type 475*6eef6eacSSimon Glass * @devnum: Device number 476*6eef6eacSSimon Glass * @return 0 if OK, -ENODEV for invalid device number 477*6eef6eacSSimon Glass */ 478*6eef6eacSSimon Glass int blk_show_device(enum if_type if_type, int devnum); 479*6eef6eacSSimon Glass 480*6eef6eacSSimon Glass /** 481*6eef6eacSSimon Glass * blk_print_device_num() - show information about a given block device 482*6eef6eacSSimon Glass * 483*6eef6eacSSimon Glass * This is similar to blk_show_device() but returns an error if the block 484*6eef6eacSSimon Glass * device type is unknown. 485*6eef6eacSSimon Glass * 486*6eef6eacSSimon Glass * @if_type: Block device type 487*6eef6eacSSimon Glass * @devnum: Device number 488*6eef6eacSSimon Glass * @return 0 if OK, -ENODEV for invalid device number, -ENOENT if the block 489*6eef6eacSSimon Glass * device is not connected 490*6eef6eacSSimon Glass */ 491*6eef6eacSSimon Glass int blk_print_device_num(enum if_type if_type, int devnum); 492*6eef6eacSSimon Glass 493*6eef6eacSSimon Glass /** 494*6eef6eacSSimon Glass * blk_print_part_devnum() - print the partition information for a device 495*6eef6eacSSimon Glass * 496*6eef6eacSSimon Glass * @if_type: Block device type 497*6eef6eacSSimon Glass * @devnum: Device number 498*6eef6eacSSimon Glass * @return 0 if OK, -ENOENT if the block device is not connected, -ENOSYS if 499*6eef6eacSSimon Glass * the interface type is not supported, other -ve on other error 500*6eef6eacSSimon Glass */ 501*6eef6eacSSimon Glass int blk_print_part_devnum(enum if_type if_type, int devnum); 502*6eef6eacSSimon Glass 503*6eef6eacSSimon Glass /** 504*6eef6eacSSimon Glass * blk_read_devnum() - read blocks from a device 505*6eef6eacSSimon Glass * 506*6eef6eacSSimon Glass * @if_type: Block device type 507*6eef6eacSSimon Glass * @devnum: Device number 508*6eef6eacSSimon Glass * @blkcnt: Number of blocks to read 509*6eef6eacSSimon Glass * @buffer: Address to write data to 510*6eef6eacSSimon Glass * @return number of blocks read, or -ve error number on error 511*6eef6eacSSimon Glass */ 512*6eef6eacSSimon Glass ulong blk_read_devnum(enum if_type if_type, int devnum, lbaint_t start, 513*6eef6eacSSimon Glass lbaint_t blkcnt, void *buffer); 514*6eef6eacSSimon Glass 515*6eef6eacSSimon Glass /** 516*6eef6eacSSimon Glass * blk_write_devnum() - write blocks to a device 517*6eef6eacSSimon Glass * 518*6eef6eacSSimon Glass * @if_type: Block device type 519*6eef6eacSSimon Glass * @devnum: Device number 520*6eef6eacSSimon Glass * @blkcnt: Number of blocks to write 521*6eef6eacSSimon Glass * @buffer: Address to read data from 522*6eef6eacSSimon Glass * @return number of blocks written, or -ve error number on error 523*6eef6eacSSimon Glass */ 524*6eef6eacSSimon Glass ulong blk_write_devnum(enum if_type if_type, int devnum, lbaint_t start, 525*6eef6eacSSimon Glass lbaint_t blkcnt, const void *buffer); 526*6eef6eacSSimon Glass 527*6eef6eacSSimon Glass /** 528*6eef6eacSSimon Glass * blk_select_hwpart_devnum() - select a hardware partition 529*6eef6eacSSimon Glass * 530*6eef6eacSSimon Glass * This is similar to blk_dselect_hwpart() but it looks up the interface and 531*6eef6eacSSimon Glass * device number. 532*6eef6eacSSimon Glass * 533*6eef6eacSSimon Glass * @if_type: Block device type 534*6eef6eacSSimon Glass * @devnum: Device number 535*6eef6eacSSimon Glass * @hwpart: Partition number to select 536*6eef6eacSSimon Glass * @return 0 if OK, -ve on error 537*6eef6eacSSimon Glass */ 538*6eef6eacSSimon Glass int blk_select_hwpart_devnum(enum if_type if_type, int devnum, int hwpart); 539*6eef6eacSSimon Glass 5401a73661bSSimon Glass #endif 541