blob: 5e94f0e096b86046f85829999d221b652c8bb616 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glassac8162f2016-02-29 15:25:39 -07002/*
3 * (C) Copyright 2000-2004
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Simon Glassac8162f2016-02-29 15:25:39 -07005 */
6
7#ifndef BLK_H
8#define BLK_H
9
Peter Jonesc27e1c12017-09-13 18:05:25 -040010#include <efi.h>
11
Simon Glassac8162f2016-02-29 15:25:39 -070012#ifdef CONFIG_SYS_64BIT_LBA
13typedef uint64_t lbaint_t;
14#define LBAFlength "ll"
15#else
16typedef ulong lbaint_t;
17#define LBAFlength "l"
18#endif
19#define LBAF "%" LBAFlength "x"
20#define LBAFU "%" LBAFlength "u"
21
22/* Interface types: */
Simon Glass83b783f2016-02-29 15:25:40 -070023enum if_type {
24 IF_TYPE_UNKNOWN = 0,
25 IF_TYPE_IDE,
26 IF_TYPE_SCSI,
27 IF_TYPE_ATAPI,
28 IF_TYPE_USB,
29 IF_TYPE_DOC,
30 IF_TYPE_MMC,
31 IF_TYPE_SD,
32 IF_TYPE_SATA,
33 IF_TYPE_HOST,
Zhikang Zhang182fccd2017-08-03 02:30:56 -070034 IF_TYPE_NVME,
Heinrich Schuchardt11206f42018-01-21 19:29:30 +010035 IF_TYPE_EFI,
Simon Glass83b783f2016-02-29 15:25:40 -070036
37 IF_TYPE_COUNT, /* Number of interface types */
38};
Simon Glassac8162f2016-02-29 15:25:39 -070039
Bin Mengcf406d22017-09-10 05:12:50 -070040#define BLK_VEN_SIZE 40
41#define BLK_PRD_SIZE 20
42#define BLK_REV_SIZE 8
43
Simon Glasscceee552016-02-29 15:25:55 -070044/*
Peter Jonesc27e1c12017-09-13 18:05:25 -040045 * Identifies the partition table type (ie. MBR vs GPT GUID) signature
46 */
47enum sig_type {
48 SIG_TYPE_NONE,
49 SIG_TYPE_MBR,
50 SIG_TYPE_GUID,
51
52 SIG_TYPE_COUNT /* Number of signature types */
53};
54
55/*
Simon Glasscceee552016-02-29 15:25:55 -070056 * With driver model (CONFIG_BLK) this is uclass platform data, accessible
57 * with dev_get_uclass_platdata(dev)
58 */
Simon Glassac8162f2016-02-29 15:25:39 -070059struct blk_desc {
Simon Glasscceee552016-02-29 15:25:55 -070060 /*
61 * TODO: With driver model we should be able to use the parent
62 * device's uclass instead.
63 */
Simon Glass83b783f2016-02-29 15:25:40 -070064 enum if_type if_type; /* type of the interface */
Simon Glass2f26fff2016-02-29 15:25:51 -070065 int devnum; /* device number */
Simon Glassac8162f2016-02-29 15:25:39 -070066 unsigned char part_type; /* partition type */
67 unsigned char target; /* target SCSI ID */
68 unsigned char lun; /* target LUN */
69 unsigned char hwpart; /* HW partition, e.g. for eMMC */
70 unsigned char type; /* device type */
71 unsigned char removable; /* removable device */
72#ifdef CONFIG_LBA48
73 /* device can use 48bit addr (ATA/ATAPI v7) */
74 unsigned char lba48;
75#endif
76 lbaint_t lba; /* number of blocks */
77 unsigned long blksz; /* block size */
78 int log2blksz; /* for convenience: log2(blksz) */
Bin Mengcf406d22017-09-10 05:12:50 -070079 char vendor[BLK_VEN_SIZE + 1]; /* device vendor string */
80 char product[BLK_PRD_SIZE + 1]; /* device product number */
81 char revision[BLK_REV_SIZE + 1]; /* firmware revision */
Peter Jonesc27e1c12017-09-13 18:05:25 -040082 enum sig_type sig_type; /* Partition table signature type */
83 union {
84 uint32_t mbr_sig; /* MBR integer signature */
85 efi_guid_t guid_sig; /* GPT GUID Signature */
86 };
Simon Glass5f4bd8c2017-07-04 13:31:19 -060087#if CONFIG_IS_ENABLED(BLK)
Simon Glass8f5f7222016-05-01 13:52:33 -060088 /*
89 * For now we have a few functions which take struct blk_desc as a
90 * parameter. This field allows them to look up the associated
91 * device. Once these functions are removed we can drop this field.
92 */
Simon Glasscceee552016-02-29 15:25:55 -070093 struct udevice *bdev;
94#else
Simon Glassac8162f2016-02-29 15:25:39 -070095 unsigned long (*block_read)(struct blk_desc *block_dev,
96 lbaint_t start,
97 lbaint_t blkcnt,
98 void *buffer);
99 unsigned long (*block_write)(struct blk_desc *block_dev,
100 lbaint_t start,
101 lbaint_t blkcnt,
102 const void *buffer);
103 unsigned long (*block_erase)(struct blk_desc *block_dev,
104 lbaint_t start,
105 lbaint_t blkcnt);
106 void *priv; /* driver private struct pointer */
Simon Glasscceee552016-02-29 15:25:55 -0700107#endif
Simon Glassac8162f2016-02-29 15:25:39 -0700108};
109
110#define BLOCK_CNT(size, blk_desc) (PAD_COUNT(size, blk_desc->blksz))
111#define PAD_TO_BLOCKSIZE(size, blk_desc) \
112 (PAD_SIZE(size, blk_desc->blksz))
113
Adam Fordd693fb92018-06-11 17:17:48 -0500114#if CONFIG_IS_ENABLED(BLOCK_CACHE)
Eric Nelsonfaf4f052016-03-28 10:05:44 -0700115/**
116 * blkcache_read() - attempt to read a set of blocks from cache
117 *
118 * @param iftype - IF_TYPE_x for type of device
119 * @param dev - device index of particular type
120 * @param start - starting block number
121 * @param blkcnt - number of blocks to read
122 * @param blksz - size in bytes of each block
123 * @param buf - buffer to contain cached data
124 *
125 * @return - '1' if block returned from cache, '0' otherwise.
126 */
Eric Nelsonf201f232016-04-02 07:37:14 -0700127int blkcache_read(int iftype, int dev,
128 lbaint_t start, lbaint_t blkcnt,
129 unsigned long blksz, void *buffer);
Eric Nelsonfaf4f052016-03-28 10:05:44 -0700130
131/**
132 * blkcache_fill() - make data read from a block device available
133 * to the block cache
134 *
135 * @param iftype - IF_TYPE_x for type of device
136 * @param dev - device index of particular type
137 * @param start - starting block number
138 * @param blkcnt - number of blocks available
139 * @param blksz - size in bytes of each block
140 * @param buf - buffer containing data to cache
141 *
142 */
Eric Nelsonf201f232016-04-02 07:37:14 -0700143void blkcache_fill(int iftype, int dev,
144 lbaint_t start, lbaint_t blkcnt,
145 unsigned long blksz, void const *buffer);
Eric Nelsonfaf4f052016-03-28 10:05:44 -0700146
147/**
148 * blkcache_invalidate() - discard the cache for a set of blocks
149 * because of a write or device (re)initialization.
150 *
151 * @param iftype - IF_TYPE_x for type of device
152 * @param dev - device index of particular type
153 */
Eric Nelsonf201f232016-04-02 07:37:14 -0700154void blkcache_invalidate(int iftype, int dev);
Eric Nelsonfaf4f052016-03-28 10:05:44 -0700155
156/**
157 * blkcache_configure() - configure block cache
158 *
159 * @param blocks - maximum blocks per entry
160 * @param entries - maximum entries in cache
161 */
162void blkcache_configure(unsigned blocks, unsigned entries);
163
164/*
165 * statistics of the block cache
166 */
167struct block_cache_stats {
168 unsigned hits;
169 unsigned misses;
170 unsigned entries; /* current entry count */
171 unsigned max_blocks_per_entry;
172 unsigned max_entries;
173};
174
175/**
176 * get_blkcache_stats() - return statistics and reset
177 *
178 * @param stats - statistics are copied here
179 */
180void blkcache_stats(struct block_cache_stats *stats);
181
182#else
183
Eric Nelsonf201f232016-04-02 07:37:14 -0700184static inline int blkcache_read(int iftype, int dev,
185 lbaint_t start, lbaint_t blkcnt,
186 unsigned long blksz, void *buffer)
Eric Nelsonfaf4f052016-03-28 10:05:44 -0700187{
188 return 0;
189}
190
Eric Nelsonf201f232016-04-02 07:37:14 -0700191static inline void blkcache_fill(int iftype, int dev,
192 lbaint_t start, lbaint_t blkcnt,
193 unsigned long blksz, void const *buffer) {}
Eric Nelsonfaf4f052016-03-28 10:05:44 -0700194
Eric Nelsonf201f232016-04-02 07:37:14 -0700195static inline void blkcache_invalidate(int iftype, int dev) {}
Eric Nelsonfaf4f052016-03-28 10:05:44 -0700196
197#endif
198
Simon Glass5f4bd8c2017-07-04 13:31:19 -0600199#if CONFIG_IS_ENABLED(BLK)
Simon Glasscceee552016-02-29 15:25:55 -0700200struct udevice;
201
202/* Operations on block devices */
203struct blk_ops {
204 /**
205 * read() - read from a block device
206 *
207 * @dev: Device to read from
208 * @start: Start block number to read (0=first)
209 * @blkcnt: Number of blocks to read
210 * @buffer: Destination buffer for data read
211 * @return number of blocks read, or -ve error number (see the
212 * IS_ERR_VALUE() macro
213 */
214 unsigned long (*read)(struct udevice *dev, lbaint_t start,
215 lbaint_t blkcnt, void *buffer);
216
217 /**
218 * write() - write to a block device
219 *
220 * @dev: Device to write to
221 * @start: Start block number to write (0=first)
222 * @blkcnt: Number of blocks to write
223 * @buffer: Source buffer for data to write
224 * @return number of blocks written, or -ve error number (see the
225 * IS_ERR_VALUE() macro
226 */
227 unsigned long (*write)(struct udevice *dev, lbaint_t start,
228 lbaint_t blkcnt, const void *buffer);
229
230 /**
231 * erase() - erase a section of a block device
232 *
233 * @dev: Device to (partially) erase
234 * @start: Start block number to erase (0=first)
235 * @blkcnt: Number of blocks to erase
236 * @return number of blocks erased, or -ve error number (see the
237 * IS_ERR_VALUE() macro
238 */
239 unsigned long (*erase)(struct udevice *dev, lbaint_t start,
240 lbaint_t blkcnt);
Simon Glass13c2c292016-05-01 13:52:30 -0600241
242 /**
243 * select_hwpart() - select a particular hardware partition
244 *
245 * Some devices (e.g. MMC) can support partitioning at the hardware
246 * level. This is quite separate from the normal idea of
247 * software-based partitions. MMC hardware partitions must be
248 * explicitly selected. Once selected only the region of the device
249 * covered by that partition is accessible.
250 *
251 * The MMC standard provides for two boot partitions (numbered 1 and 2),
252 * rpmb (3), and up to 4 addition general-purpose partitions (4-7).
253 *
254 * @desc: Block device to update
255 * @hwpart: Hardware partition number to select. 0 means the raw
256 * device, 1 is the first partition, 2 is the second, etc.
257 * @return 0 if OK, -ve on error
258 */
259 int (*select_hwpart)(struct udevice *dev, int hwpart);
Simon Glasscceee552016-02-29 15:25:55 -0700260};
261
262#define blk_get_ops(dev) ((struct blk_ops *)(dev)->driver->ops)
263
264/*
265 * These functions should take struct udevice instead of struct blk_desc,
266 * but this is convenient for migration to driver model. Add a 'd' prefix
267 * to the function operations, so that blk_read(), etc. can be reserved for
268 * functions with the correct arguments.
269 */
270unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
271 lbaint_t blkcnt, void *buffer);
272unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
273 lbaint_t blkcnt, const void *buffer);
274unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
275 lbaint_t blkcnt);
276
277/**
Simon Glassd5d4c102017-04-23 20:02:05 -0600278 * blk_find_device() - Find a block device
279 *
280 * This function does not activate the device. The device will be returned
281 * whether or not it is activated.
282 *
283 * @if_type: Interface type (enum if_type_t)
284 * @devnum: Device number (specific to each interface type)
285 * @devp: the device, if found
286 * @return 0 if found, -ENODEV if no device found, or other -ve error value
287 */
288int blk_find_device(int if_type, int devnum, struct udevice **devp);
289
290/**
Simon Glasscceee552016-02-29 15:25:55 -0700291 * blk_get_device() - Find and probe a block device ready for use
292 *
293 * @if_type: Interface type (enum if_type_t)
294 * @devnum: Device number (specific to each interface type)
295 * @devp: the device, if found
Simon Glassd5d4c102017-04-23 20:02:05 -0600296 * @return 0 if found, -ENODEV if no device found, or other -ve error value
Simon Glasscceee552016-02-29 15:25:55 -0700297 */
298int blk_get_device(int if_type, int devnum, struct udevice **devp);
299
300/**
301 * blk_first_device() - Find the first device for a given interface
302 *
303 * The device is probed ready for use
304 *
305 * @devnum: Device number (specific to each interface type)
306 * @devp: the device, if found
307 * @return 0 if found, -ENODEV if no device, or other -ve error value
308 */
309int blk_first_device(int if_type, struct udevice **devp);
310
311/**
312 * blk_next_device() - Find the next device for a given interface
313 *
314 * This can be called repeatedly after blk_first_device() to iterate through
315 * all devices of the given interface type.
316 *
317 * The device is probed ready for use
318 *
319 * @devp: On entry, the previous device returned. On exit, the next
320 * device, if found
321 * @return 0 if found, -ENODEV if no device, or other -ve error value
322 */
323int blk_next_device(struct udevice **devp);
324
325/**
326 * blk_create_device() - Create a new block device
327 *
328 * @parent: Parent of the new device
329 * @drv_name: Driver name to use for the block device
330 * @name: Name for the device
331 * @if_type: Interface type (enum if_type_t)
Simon Glassd089ba32016-05-01 11:36:28 -0600332 * @devnum: Device number, specific to the interface type, or -1 to
333 * allocate the next available number
Simon Glasscceee552016-02-29 15:25:55 -0700334 * @blksz: Block size of the device in bytes (typically 512)
Jean-Jacques Hiblot99b324a2017-06-09 16:45:18 +0200335 * @lba: Total number of blocks of the device
Simon Glasscceee552016-02-29 15:25:55 -0700336 * @devp: the new device (which has not been probed)
337 */
338int blk_create_device(struct udevice *parent, const char *drv_name,
339 const char *name, int if_type, int devnum, int blksz,
Jean-Jacques Hiblot99b324a2017-06-09 16:45:18 +0200340 lbaint_t lba, struct udevice **devp);
Simon Glasscceee552016-02-29 15:25:55 -0700341
342/**
Simon Glass966b6952016-05-01 11:36:29 -0600343 * blk_create_devicef() - Create a new named block device
344 *
345 * @parent: Parent of the new device
346 * @drv_name: Driver name to use for the block device
347 * @name: Name for the device (parent name is prepended)
348 * @if_type: Interface type (enum if_type_t)
349 * @devnum: Device number, specific to the interface type, or -1 to
350 * allocate the next available number
351 * @blksz: Block size of the device in bytes (typically 512)
Jean-Jacques Hiblot99b324a2017-06-09 16:45:18 +0200352 * @lba: Total number of blocks of the device
Simon Glass966b6952016-05-01 11:36:29 -0600353 * @devp: the new device (which has not been probed)
354 */
355int blk_create_devicef(struct udevice *parent, const char *drv_name,
356 const char *name, int if_type, int devnum, int blksz,
Jean-Jacques Hiblot99b324a2017-06-09 16:45:18 +0200357 lbaint_t lba, struct udevice **devp);
Simon Glass966b6952016-05-01 11:36:29 -0600358
359/**
Simon Glasscceee552016-02-29 15:25:55 -0700360 * blk_unbind_all() - Unbind all device of the given interface type
361 *
362 * The devices are removed and then unbound.
363 *
364 * @if_type: Interface type to unbind
365 * @return 0 if OK, -ve on error
366 */
367int blk_unbind_all(int if_type);
368
Simon Glassd089ba32016-05-01 11:36:28 -0600369/**
370 * blk_find_max_devnum() - find the maximum device number for an interface type
371 *
372 * Finds the last allocated device number for an interface type @if_type. The
373 * next number is safe to use for a newly allocated device.
374 *
375 * @if_type: Interface type to scan
376 * @return maximum device number found, or -ENODEV if none, or other -ve on
377 * error
378 */
379int blk_find_max_devnum(enum if_type if_type);
380
Simon Glass13c2c292016-05-01 13:52:30 -0600381/**
Bin Mengfd5eda72018-10-15 02:21:09 -0700382 * blk_next_free_devnum() - get the next device number for an interface type
383 *
384 * Finds the next number that is safe to use for a newly allocated device for
385 * an interface type @if_type.
386 *
387 * @if_type: Interface type to scan
388 * @return next device number safe to use, or -ve on error
389 */
390int blk_next_free_devnum(enum if_type if_type);
391
392/**
Simon Glass13c2c292016-05-01 13:52:30 -0600393 * blk_select_hwpart() - select a hardware partition
394 *
395 * Select a hardware partition if the device supports it (typically MMC does)
396 *
397 * @dev: Device to update
398 * @hwpart: Partition number to select
399 * @return 0 if OK, -ve on error
400 */
401int blk_select_hwpart(struct udevice *dev, int hwpart);
402
Tom Rini7c41d142017-06-10 10:01:05 -0400403/**
404 * blk_get_from_parent() - obtain a block device by looking up its parent
405 *
406 * All devices with
407 */
408int blk_get_from_parent(struct udevice *parent, struct udevice **devp);
409
Tien Fong Chee10378522018-07-06 16:26:36 +0800410/**
411 * blk_get_by_device() - Get the block device descriptor for the given device
412 * @dev: Instance of a storage device
413 *
414 * Return: With block device descriptor on success , NULL if there is no such
415 * block device.
416 */
417struct blk_desc *blk_get_by_device(struct udevice *dev);
418
Simon Glasscceee552016-02-29 15:25:55 -0700419#else
420#include <errno.h>
Simon Glass2ee8ada2016-02-29 15:25:52 -0700421/*
422 * These functions should take struct udevice instead of struct blk_desc,
423 * but this is convenient for migration to driver model. Add a 'd' prefix
424 * to the function operations, so that blk_read(), etc. can be reserved for
425 * functions with the correct arguments.
426 */
427static inline ulong blk_dread(struct blk_desc *block_dev, lbaint_t start,
428 lbaint_t blkcnt, void *buffer)
429{
Eric Nelsonfaf4f052016-03-28 10:05:44 -0700430 ulong blks_read;
431 if (blkcache_read(block_dev->if_type, block_dev->devnum,
432 start, blkcnt, block_dev->blksz, buffer))
433 return blkcnt;
434
Simon Glass2ee8ada2016-02-29 15:25:52 -0700435 /*
436 * We could check if block_read is NULL and return -ENOSYS. But this
437 * bloats the code slightly (cause some board to fail to build), and
438 * it would be an error to try an operation that does not exist.
439 */
Eric Nelsonfaf4f052016-03-28 10:05:44 -0700440 blks_read = block_dev->block_read(block_dev, start, blkcnt, buffer);
441 if (blks_read == blkcnt)
442 blkcache_fill(block_dev->if_type, block_dev->devnum,
443 start, blkcnt, block_dev->blksz, buffer);
444
445 return blks_read;
Simon Glass2ee8ada2016-02-29 15:25:52 -0700446}
447
448static inline ulong blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
449 lbaint_t blkcnt, const void *buffer)
450{
Eric Nelsonfaf4f052016-03-28 10:05:44 -0700451 blkcache_invalidate(block_dev->if_type, block_dev->devnum);
Simon Glass2ee8ada2016-02-29 15:25:52 -0700452 return block_dev->block_write(block_dev, start, blkcnt, buffer);
453}
454
455static inline ulong blk_derase(struct blk_desc *block_dev, lbaint_t start,
456 lbaint_t blkcnt)
457{
Eric Nelsonfaf4f052016-03-28 10:05:44 -0700458 blkcache_invalidate(block_dev->if_type, block_dev->devnum);
Simon Glass2ee8ada2016-02-29 15:25:52 -0700459 return block_dev->block_erase(block_dev, start, blkcnt);
460}
Simon Glass3bf2ab92016-05-01 11:36:03 -0600461
462/**
463 * struct blk_driver - Driver for block interface types
464 *
465 * This provides access to the block devices for each interface type. One
466 * driver should be provided using U_BOOT_LEGACY_BLK() for each interface
467 * type that is to be supported.
468 *
469 * @if_typename: Interface type name
470 * @if_type: Interface type
471 * @max_devs: Maximum number of devices supported
472 * @desc: Pointer to list of devices for this interface type,
473 * or NULL to use @get_dev() instead
474 */
475struct blk_driver {
476 const char *if_typename;
477 enum if_type if_type;
478 int max_devs;
479 struct blk_desc *desc;
480 /**
481 * get_dev() - get a pointer to a block device given its number
482 *
483 * Each interface allocates its own devices and typically
484 * struct blk_desc is contained with the interface's data structure.
485 * There is no global numbering for block devices. This method allows
486 * the device for an interface type to be obtained when @desc is NULL.
487 *
488 * @devnum: Device number (0 for first device on that interface,
489 * 1 for second, etc.
490 * @descp: Returns pointer to the block device on success
491 * @return 0 if OK, -ve on error
492 */
493 int (*get_dev)(int devnum, struct blk_desc **descp);
494
495 /**
496 * select_hwpart() - Select a hardware partition
497 *
498 * Some devices (e.g. MMC) can support partitioning at the hardware
499 * level. This is quite separate from the normal idea of
500 * software-based partitions. MMC hardware partitions must be
501 * explicitly selected. Once selected only the region of the device
502 * covered by that partition is accessible.
503 *
504 * The MMC standard provides for two boot partitions (numbered 1 and 2),
505 * rpmb (3), and up to 4 addition general-purpose partitions (4-7).
506 * Partition 0 is the main user-data partition.
507 *
508 * @desc: Block device descriptor
509 * @hwpart: Hardware partition number to select. 0 means the main
510 * user-data partition, 1 is the first partition, 2 is
511 * the second, etc.
512 * @return 0 if OK, other value for an error
513 */
514 int (*select_hwpart)(struct blk_desc *desc, int hwpart);
515};
516
517/*
518 * Declare a new U-Boot legacy block driver. New drivers should use driver
519 * model (UCLASS_BLK).
520 */
521#define U_BOOT_LEGACY_BLK(__name) \
522 ll_entry_declare(struct blk_driver, __name, blk_driver)
523
524struct blk_driver *blk_driver_lookup_type(int if_type);
525
Simon Glasscceee552016-02-29 15:25:55 -0700526#endif /* !CONFIG_BLK */
Simon Glass2ee8ada2016-02-29 15:25:52 -0700527
Simon Glass3bf2ab92016-05-01 11:36:03 -0600528/**
529 * blk_get_devnum_by_typename() - Get a block device by type and number
530 *
531 * This looks through the available block devices of the given type, returning
532 * the one with the given @devnum.
533 *
534 * @if_type: Block device type
535 * @devnum: Device number
536 * @return point to block device descriptor, or NULL if not found
537 */
538struct blk_desc *blk_get_devnum_by_type(enum if_type if_type, int devnum);
539
540/**
541 * blk_get_devnum_by_type() - Get a block device by type name, and number
542 *
543 * This looks up the block device type based on @if_typename, then calls
544 * blk_get_devnum_by_type().
545 *
546 * @if_typename: Block device type name
547 * @devnum: Device number
548 * @return point to block device descriptor, or NULL if not found
549 */
550struct blk_desc *blk_get_devnum_by_typename(const char *if_typename,
551 int devnum);
552
553/**
554 * blk_dselect_hwpart() - select a hardware partition
555 *
556 * This selects a hardware partition (such as is supported by MMC). The block
557 * device size may change as this effectively points the block device to a
558 * partition at the hardware level. See the select_hwpart() method above.
559 *
560 * @desc: Block device descriptor for the device to select
561 * @hwpart: Partition number to select
562 * @return 0 if OK, -ve on error
563 */
564int blk_dselect_hwpart(struct blk_desc *desc, int hwpart);
565
566/**
567 * blk_list_part() - list the partitions for block devices of a given type
568 *
569 * This looks up the partition type for each block device of type @if_type,
570 * then displays a list of partitions.
571 *
572 * @if_type: Block device type
573 * @return 0 if OK, -ENODEV if there is none of that type
574 */
575int blk_list_part(enum if_type if_type);
576
577/**
578 * blk_list_devices() - list the block devices of a given type
579 *
580 * This lists each block device of the type @if_type, showing the capacity
581 * as well as type-specific information.
582 *
583 * @if_type: Block device type
584 */
585void blk_list_devices(enum if_type if_type);
586
587/**
588 * blk_show_device() - show information about a given block device
589 *
590 * This shows the block device capacity as well as type-specific information.
591 *
592 * @if_type: Block device type
593 * @devnum: Device number
594 * @return 0 if OK, -ENODEV for invalid device number
595 */
596int blk_show_device(enum if_type if_type, int devnum);
597
598/**
599 * blk_print_device_num() - show information about a given block device
600 *
601 * This is similar to blk_show_device() but returns an error if the block
602 * device type is unknown.
603 *
604 * @if_type: Block device type
605 * @devnum: Device number
606 * @return 0 if OK, -ENODEV for invalid device number, -ENOENT if the block
607 * device is not connected
608 */
609int blk_print_device_num(enum if_type if_type, int devnum);
610
611/**
612 * blk_print_part_devnum() - print the partition information for a device
613 *
614 * @if_type: Block device type
615 * @devnum: Device number
616 * @return 0 if OK, -ENOENT if the block device is not connected, -ENOSYS if
617 * the interface type is not supported, other -ve on other error
618 */
619int blk_print_part_devnum(enum if_type if_type, int devnum);
620
621/**
622 * blk_read_devnum() - read blocks from a device
623 *
624 * @if_type: Block device type
625 * @devnum: Device number
626 * @blkcnt: Number of blocks to read
627 * @buffer: Address to write data to
628 * @return number of blocks read, or -ve error number on error
629 */
630ulong blk_read_devnum(enum if_type if_type, int devnum, lbaint_t start,
631 lbaint_t blkcnt, void *buffer);
632
633/**
634 * blk_write_devnum() - write blocks to a device
635 *
636 * @if_type: Block device type
637 * @devnum: Device number
638 * @blkcnt: Number of blocks to write
639 * @buffer: Address to read data from
640 * @return number of blocks written, or -ve error number on error
641 */
642ulong blk_write_devnum(enum if_type if_type, int devnum, lbaint_t start,
643 lbaint_t blkcnt, const void *buffer);
644
645/**
646 * blk_select_hwpart_devnum() - select a hardware partition
647 *
648 * This is similar to blk_dselect_hwpart() but it looks up the interface and
649 * device number.
650 *
651 * @if_type: Block device type
652 * @devnum: Device number
653 * @hwpart: Partition number to select
654 * @return 0 if OK, -ve on error
655 */
656int blk_select_hwpart_devnum(enum if_type if_type, int devnum, int hwpart);
657
Simon Glass85af5a42017-07-29 11:34:53 -0600658/**
659 * blk_get_if_type_name() - Get the name of an interface type
660 *
661 * @if_type: Interface type to check
662 * @return name of interface, or NULL if none
663 */
664const char *blk_get_if_type_name(enum if_type if_type);
665
Simon Glassbf2e7952017-07-29 11:34:54 -0600666/**
667 * blk_common_cmd() - handle common commands with block devices
668 *
669 * @args: Number of arguments to the command (argv[0] is the command itself)
670 * @argv: Command arguments
671 * @if_type: Interface type
672 * @cur_devnump: Current device number for this interface type
673 * @return 0 if OK, CMD_RET_ERROR on error
674 */
675int blk_common_cmd(int argc, char * const argv[], enum if_type if_type,
676 int *cur_devnump);
677
Simon Glassac8162f2016-02-29 15:25:39 -0700678#endif