1 /*
2 * (C) Copyright 2000-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8 #ifndef BLK_H
9 #define BLK_H
10
11 #include <efi.h>
12 #include <asm/uspinlock.h>
13
14 #ifdef CONFIG_SYS_64BIT_LBA
15 typedef uint64_t lbaint_t;
16 #define LBAFlength "ll"
17 #else
18 typedef ulong lbaint_t;
19 #define LBAFlength "l"
20 #endif
21 #define LBAF "%" LBAFlength "x"
22 #define LBAFU "%" LBAFlength "u"
23
24 /* Interface types: */
25 enum if_type {
26 IF_TYPE_UNKNOWN = 0,
27 IF_TYPE_IDE,
28 IF_TYPE_SCSI,
29 IF_TYPE_ATAPI,
30 IF_TYPE_USB,
31 IF_TYPE_DOC,
32 IF_TYPE_MMC,
33 IF_TYPE_SD,
34 IF_TYPE_SATA,
35 IF_TYPE_HOST,
36 IF_TYPE_SYSTEMACE,
37 IF_TYPE_NVME,
38 IF_TYPE_RKNAND,
39 IF_TYPE_SPINAND,
40 IF_TYPE_SPINOR,
41 IF_TYPE_RAMDISK,
42 IF_TYPE_MTD,
43 IF_TYPE_COUNT, /* Number of interface types */
44 };
45
46 /* define mtd device devnum */
47 #define BLK_MTD_NAND 0
48 #define BLK_MTD_SPI_NAND 1
49 #define BLK_MTD_SPI_NOR 2
50
51 #define BLK_VEN_SIZE 40
52 #define BLK_PRD_SIZE 20
53 #define BLK_REV_SIZE 8
54
55 /* define block device operation flags */
56 #define BLK_PRE_RW BIT(0) /* Block prepare read & write*/
57 #define BLK_MTD_CONT_WRITE BIT(1) /* Special for Nand device P/E */
58
59 /*
60 * Identifies the partition table type (ie. MBR vs GPT GUID) signature
61 */
62 enum sig_type {
63 SIG_TYPE_NONE,
64 SIG_TYPE_MBR,
65 SIG_TYPE_GUID,
66
67 SIG_TYPE_COUNT /* Number of signature types */
68 };
69
70 /*
71 * With driver model (CONFIG_BLK) this is uclass platform data, accessible
72 * with dev_get_uclass_platdata(dev)
73 */
74 struct blk_desc {
75 /*
76 * TODO: With driver model we should be able to use the parent
77 * device's uclass instead.
78 */
79 enum if_type if_type; /* type of the interface */
80 int devnum; /* device number */
81 unsigned char part_type; /* partition type */
82 unsigned char target; /* target SCSI ID */
83 unsigned char lun; /* target LUN */
84 unsigned char hwpart; /* HW partition, e.g. for eMMC */
85 unsigned char type; /* device type */
86 unsigned char removable; /* removable device */
87 unsigned char op_flag; /* Some special operation flags */
88 #ifdef CONFIG_LBA48
89 /* device can use 48bit addr (ATA/ATAPI v7) */
90 unsigned char lba48;
91 #endif
92 lbaint_t lba; /* number of blocks */
93 lbaint_t rawlba; /* physical number of blocks */
94 unsigned long blksz; /* block size */
95 unsigned long rawblksz; /* block size */
96 void *align_sector_buf; /* allocate alignment buffer for 4k size blocks */
97 int log2blksz; /* for convenience: log2(blksz) */
98 char vendor[BLK_VEN_SIZE + 1]; /* device vendor string */
99 char product[BLK_PRD_SIZE + 1]; /* device product number */
100 char revision[BLK_REV_SIZE + 1]; /* firmware revision */
101 enum sig_type sig_type; /* Partition table signature type */
102 union {
103 uint32_t mbr_sig; /* MBR integer signature */
104 efi_guid_t guid_sig; /* GPT GUID Signature */
105 };
106 #if CONFIG_IS_ENABLED(BLK)
107 /*
108 * For now we have a few functions which take struct blk_desc as a
109 * parameter. This field allows them to look up the associated
110 * device. Once these functions are removed we can drop this field.
111 */
112 struct udevice *bdev;
113 #else
114 unsigned long (*block_read)(struct blk_desc *block_dev,
115 lbaint_t start,
116 lbaint_t blkcnt,
117 void *buffer);
118 unsigned long (*block_write)(struct blk_desc *block_dev,
119 lbaint_t start,
120 lbaint_t blkcnt,
121 const void *buffer);
122 unsigned long (*block_erase)(struct blk_desc *block_dev,
123 lbaint_t start,
124 lbaint_t blkcnt);
125 void *priv; /* driver private struct pointer */
126 #endif
127
128 uspinlock_t blk_lock;
129 };
130
131 #define BLOCK_CNT(size, blk_desc) (PAD_COUNT(size, blk_desc->blksz))
132 #define PAD_TO_BLOCKSIZE(size, blk_desc) \
133 (PAD_SIZE(size, blk_desc->blksz))
134
135 #ifdef CONFIG_BLOCK_CACHE
136 /**
137 * blkcache_read() - attempt to read a set of blocks from cache
138 *
139 * @param iftype - IF_TYPE_x for type of device
140 * @param dev - device index of particular type
141 * @param start - starting block number
142 * @param blkcnt - number of blocks to read
143 * @param blksz - size in bytes of each block
144 * @param buf - buffer to contain cached data
145 *
146 * @return - '1' if block returned from cache, '0' otherwise.
147 */
148 int blkcache_read(int iftype, int dev,
149 lbaint_t start, lbaint_t blkcnt,
150 unsigned long blksz, void *buffer);
151
152 /**
153 * blkcache_fill() - make data read from a block device available
154 * to the block cache
155 *
156 * @param iftype - IF_TYPE_x for type of device
157 * @param dev - device index of particular type
158 * @param start - starting block number
159 * @param blkcnt - number of blocks available
160 * @param blksz - size in bytes of each block
161 * @param buf - buffer containing data to cache
162 *
163 */
164 void blkcache_fill(int iftype, int dev,
165 lbaint_t start, lbaint_t blkcnt,
166 unsigned long blksz, void const *buffer);
167
168 /**
169 * blkcache_invalidate() - discard the cache for a set of blocks
170 * because of a write or device (re)initialization.
171 *
172 * @param iftype - IF_TYPE_x for type of device
173 * @param dev - device index of particular type
174 */
175 void blkcache_invalidate(int iftype, int dev);
176
177 /**
178 * blkcache_configure() - configure block cache
179 *
180 * @param blocks - maximum blocks per entry
181 * @param entries - maximum entries in cache
182 */
183 void blkcache_configure(unsigned blocks, unsigned entries);
184
185 /*
186 * statistics of the block cache
187 */
188 struct block_cache_stats {
189 unsigned hits;
190 unsigned misses;
191 unsigned entries; /* current entry count */
192 unsigned max_blocks_per_entry;
193 unsigned max_entries;
194 };
195
196 /**
197 * get_blkcache_stats() - return statistics and reset
198 *
199 * @param stats - statistics are copied here
200 */
201 void blkcache_stats(struct block_cache_stats *stats);
202
203 #else
204
blkcache_read(int iftype,int dev,lbaint_t start,lbaint_t blkcnt,unsigned long blksz,void * buffer)205 static inline int blkcache_read(int iftype, int dev,
206 lbaint_t start, lbaint_t blkcnt,
207 unsigned long blksz, void *buffer)
208 {
209 return 0;
210 }
211
blkcache_fill(int iftype,int dev,lbaint_t start,lbaint_t blkcnt,unsigned long blksz,void const * buffer)212 static inline void blkcache_fill(int iftype, int dev,
213 lbaint_t start, lbaint_t blkcnt,
214 unsigned long blksz, void const *buffer) {}
215
blkcache_invalidate(int iftype,int dev)216 static inline void blkcache_invalidate(int iftype, int dev) {}
217
218 #endif
219
220 #if CONFIG_IS_ENABLED(BLK)
221 struct udevice;
222
223 /* Operations on block devices */
224 struct blk_ops {
225 /**
226 * read() - read from a block device
227 *
228 * @dev: Device to read from
229 * @start: Start block number to read (0=first)
230 * @blkcnt: Number of blocks to read
231 * @buffer: Destination buffer for data read
232 * @return number of blocks read, or -ve error number (see the
233 * IS_ERR_VALUE() macro
234 */
235 unsigned long (*read)(struct udevice *dev, lbaint_t start,
236 lbaint_t blkcnt, void *buffer);
237
238 /**
239 * write() - write to a block device
240 *
241 * @dev: Device to write to
242 * @start: Start block number to write (0=first)
243 * @blkcnt: Number of blocks to write
244 * @buffer: Source buffer for data to write
245 * @return number of blocks written, or -ve error number (see the
246 * IS_ERR_VALUE() macro
247 */
248 unsigned long (*write)(struct udevice *dev, lbaint_t start,
249 lbaint_t blkcnt, const void *buffer);
250
251 /**
252 * write_zeroes() - write zeroes to a block device
253 *
254 * @dev: Device to write to
255 * @start: Start block number to write (0=first)
256 * @blkcnt: Number of blocks to write
257 * @return number of blocks written, or -ve error number (see the
258 * IS_ERR_VALUE() macro
259 */
260 unsigned long (*write_zeroes)(struct udevice *dev, lbaint_t start,
261 lbaint_t blkcnt);
262
263 /**
264 * erase() - erase a section of a block device
265 *
266 * @dev: Device to (partially) erase
267 * @start: Start block number to erase (0=first)
268 * @blkcnt: Number of blocks to erase
269 * @return number of blocks erased, or -ve error number (see the
270 * IS_ERR_VALUE() macro
271 */
272 unsigned long (*erase)(struct udevice *dev, lbaint_t start,
273 lbaint_t blkcnt);
274
275 /**
276 * select_hwpart() - select a particular hardware partition
277 *
278 * Some devices (e.g. MMC) can support partitioning at the hardware
279 * level. This is quite separate from the normal idea of
280 * software-based partitions. MMC hardware partitions must be
281 * explicitly selected. Once selected only the region of the device
282 * covered by that partition is accessible.
283 *
284 * The MMC standard provides for two boot partitions (numbered 1 and 2),
285 * rpmb (3), and up to 4 addition general-purpose partitions (4-7).
286 *
287 * @desc: Block device to update
288 * @hwpart: Hardware partition number to select. 0 means the raw
289 * device, 1 is the first partition, 2 is the second, etc.
290 * @return 0 if OK, -ve on error
291 */
292 int (*select_hwpart)(struct udevice *dev, int hwpart);
293 };
294
295 #define blk_get_ops(dev) ((struct blk_ops *)(dev)->driver->ops)
296
297 /*
298 * These functions should take struct udevice instead of struct blk_desc,
299 * but this is convenient for migration to driver model. Add a 'd' prefix
300 * to the function operations, so that blk_read(), etc. can be reserved for
301 * functions with the correct arguments.
302 */
303 unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
304 lbaint_t blkcnt, void *buffer);
305 unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
306 lbaint_t blkcnt, const void *buffer);
307 unsigned long blk_dwrite_zeroes(struct blk_desc *block_dev, lbaint_t start,
308 lbaint_t blkcnt);
309 unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
310 lbaint_t blkcnt);
311
312 /**
313 * blk_find_device() - Find a block device
314 *
315 * This function does not activate the device. The device will be returned
316 * whether or not it is activated.
317 *
318 * @if_type: Interface type (enum if_type_t)
319 * @devnum: Device number (specific to each interface type)
320 * @devp: the device, if found
321 * @return 0 if found, -ENODEV if no device found, or other -ve error value
322 */
323 int blk_find_device(int if_type, int devnum, struct udevice **devp);
324
325 /**
326 * blk_get_device() - Find and probe a block device ready for use
327 *
328 * @if_type: Interface type (enum if_type_t)
329 * @devnum: Device number (specific to each interface type)
330 * @devp: the device, if found
331 * @return 0 if found, -ENODEV if no device found, or other -ve error value
332 */
333 int blk_get_device(int if_type, int devnum, struct udevice **devp);
334
335 /**
336 * blk_first_device() - Find the first device for a given interface
337 *
338 * The device is probed ready for use
339 *
340 * @devnum: Device number (specific to each interface type)
341 * @devp: the device, if found
342 * @return 0 if found, -ENODEV if no device, or other -ve error value
343 */
344 int blk_first_device(int if_type, struct udevice **devp);
345
346 /**
347 * blk_next_device() - Find the next device for a given interface
348 *
349 * This can be called repeatedly after blk_first_device() to iterate through
350 * all devices of the given interface type.
351 *
352 * The device is probed ready for use
353 *
354 * @devp: On entry, the previous device returned. On exit, the next
355 * device, if found
356 * @return 0 if found, -ENODEV if no device, or other -ve error value
357 */
358 int blk_next_device(struct udevice **devp);
359
360 /**
361 * blk_create_device() - Create a new block device
362 *
363 * @parent: Parent of the new device
364 * @drv_name: Driver name to use for the block device
365 * @name: Name for the device
366 * @if_type: Interface type (enum if_type_t)
367 * @devnum: Device number, specific to the interface type, or -1 to
368 * allocate the next available number
369 * @blksz: Block size of the device in bytes (typically 512)
370 * @size: Total size of the device in bytes
371 * @devp: the new device (which has not been probed)
372 */
373 int blk_create_device(struct udevice *parent, const char *drv_name,
374 const char *name, int if_type, int devnum, int blksz,
375 lbaint_t size, struct udevice **devp);
376
377 /**
378 * blk_create_devicef() - Create a new named block device
379 *
380 * @parent: Parent of the new device
381 * @drv_name: Driver name to use for the block device
382 * @name: Name for the device (parent name is prepended)
383 * @if_type: Interface type (enum if_type_t)
384 * @devnum: Device number, specific to the interface type, or -1 to
385 * allocate the next available number
386 * @blksz: Block size of the device in bytes (typically 512)
387 * @size: Total size of the device in bytes
388 * @devp: the new device (which has not been probed)
389 */
390 int blk_create_devicef(struct udevice *parent, const char *drv_name,
391 const char *name, int if_type, int devnum, int blksz,
392 lbaint_t size, struct udevice **devp);
393
394 /**
395 * blk_prepare_device() - Prepare a block device for use
396 *
397 * This reads partition information from the device if supported.
398 *
399 * @dev: Device to prepare
400 * @return 0 if ok, -ve on error
401 */
402 int blk_prepare_device(struct udevice *dev);
403
404 /**
405 * blk_unbind_all() - Unbind all device of the given interface type
406 *
407 * The devices are removed and then unbound.
408 *
409 * @if_type: Interface type to unbind
410 * @return 0 if OK, -ve on error
411 */
412 int blk_unbind_all(int if_type);
413
414 /**
415 * blk_find_max_devnum() - find the maximum device number for an interface type
416 *
417 * Finds the last allocated device number for an interface type @if_type. The
418 * next number is safe to use for a newly allocated device.
419 *
420 * @if_type: Interface type to scan
421 * @return maximum device number found, or -ENODEV if none, or other -ve on
422 * error
423 */
424 int blk_find_max_devnum(enum if_type if_type);
425
426 /**
427 * blk_select_hwpart() - select a hardware partition
428 *
429 * Select a hardware partition if the device supports it (typically MMC does)
430 *
431 * @dev: Device to update
432 * @hwpart: Partition number to select
433 * @return 0 if OK, -ve on error
434 */
435 int blk_select_hwpart(struct udevice *dev, int hwpart);
436
437 /**
438 * blk_get_from_parent() - obtain a block device by looking up its parent
439 *
440 * All devices with
441 */
442 int blk_get_from_parent(struct udevice *parent, struct udevice **devp);
443
444 #else
445 #include <errno.h>
446 /*
447 * These functions should take struct udevice instead of struct blk_desc,
448 * but this is convenient for migration to driver model. Add a 'd' prefix
449 * to the function operations, so that blk_read(), etc. can be reserved for
450 * functions with the correct arguments.
451 */
blk_dread(struct blk_desc * block_dev,lbaint_t start,lbaint_t blkcnt,void * buffer)452 static inline ulong blk_dread(struct blk_desc *block_dev, lbaint_t start,
453 lbaint_t blkcnt, void *buffer)
454 {
455 ulong blks_read;
456 if (blkcache_read(block_dev->if_type, block_dev->devnum,
457 start, blkcnt, block_dev->blksz, buffer))
458 return blkcnt;
459
460 /*
461 * We could check if block_read is NULL and return -ENOSYS. But this
462 * bloats the code slightly (cause some board to fail to build), and
463 * it would be an error to try an operation that does not exist.
464 */
465 blks_read = block_dev->block_read(block_dev, start, blkcnt, buffer);
466 if (blks_read == blkcnt)
467 blkcache_fill(block_dev->if_type, block_dev->devnum,
468 start, blkcnt, block_dev->blksz, buffer);
469
470 return blks_read;
471 }
472
blk_dwrite(struct blk_desc * block_dev,lbaint_t start,lbaint_t blkcnt,const void * buffer)473 static inline ulong blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
474 lbaint_t blkcnt, const void *buffer)
475 {
476 blkcache_invalidate(block_dev->if_type, block_dev->devnum);
477 return block_dev->block_write(block_dev, start, blkcnt, buffer);
478 }
479
blk_derase(struct blk_desc * block_dev,lbaint_t start,lbaint_t blkcnt)480 static inline ulong blk_derase(struct blk_desc *block_dev, lbaint_t start,
481 lbaint_t blkcnt)
482 {
483 blkcache_invalidate(block_dev->if_type, block_dev->devnum);
484 return block_dev->block_erase(block_dev, start, blkcnt);
485 }
486
487 /**
488 * struct blk_driver - Driver for block interface types
489 *
490 * This provides access to the block devices for each interface type. One
491 * driver should be provided using U_BOOT_LEGACY_BLK() for each interface
492 * type that is to be supported.
493 *
494 * @if_typename: Interface type name
495 * @if_type: Interface type
496 * @max_devs: Maximum number of devices supported
497 * @desc: Pointer to list of devices for this interface type,
498 * or NULL to use @get_dev() instead
499 */
500 struct blk_driver {
501 const char *if_typename;
502 enum if_type if_type;
503 int max_devs;
504 struct blk_desc *desc;
505 /**
506 * get_dev() - get a pointer to a block device given its number
507 *
508 * Each interface allocates its own devices and typically
509 * struct blk_desc is contained with the interface's data structure.
510 * There is no global numbering for block devices. This method allows
511 * the device for an interface type to be obtained when @desc is NULL.
512 *
513 * @devnum: Device number (0 for first device on that interface,
514 * 1 for second, etc.
515 * @descp: Returns pointer to the block device on success
516 * @return 0 if OK, -ve on error
517 */
518 int (*get_dev)(int devnum, struct blk_desc **descp);
519
520 /**
521 * select_hwpart() - Select a hardware partition
522 *
523 * Some devices (e.g. MMC) can support partitioning at the hardware
524 * level. This is quite separate from the normal idea of
525 * software-based partitions. MMC hardware partitions must be
526 * explicitly selected. Once selected only the region of the device
527 * covered by that partition is accessible.
528 *
529 * The MMC standard provides for two boot partitions (numbered 1 and 2),
530 * rpmb (3), and up to 4 addition general-purpose partitions (4-7).
531 * Partition 0 is the main user-data partition.
532 *
533 * @desc: Block device descriptor
534 * @hwpart: Hardware partition number to select. 0 means the main
535 * user-data partition, 1 is the first partition, 2 is
536 * the second, etc.
537 * @return 0 if OK, other value for an error
538 */
539 int (*select_hwpart)(struct blk_desc *desc, int hwpart);
540 };
541
542 /*
543 * Declare a new U-Boot legacy block driver. New drivers should use driver
544 * model (UCLASS_BLK).
545 */
546 #define U_BOOT_LEGACY_BLK(__name) \
547 ll_entry_declare(struct blk_driver, __name, blk_driver)
548
549 struct blk_driver *blk_driver_lookup_type(int if_type);
550
551 #endif /* !CONFIG_BLK */
552
553 /**
554 * blk_get_devnum_by_typename() - Get a block device by type and number
555 *
556 * This looks through the available block devices of the given type, returning
557 * the one with the given @devnum.
558 *
559 * @if_type: Block device type
560 * @devnum: Device number
561 * @return point to block device descriptor, or NULL if not found
562 */
563 struct blk_desc *blk_get_devnum_by_type(enum if_type if_type, int devnum);
564
565 /**
566 * blk_get_devnum_by_type() - Get a block device by type name, and number
567 *
568 * This looks up the block device type based on @if_typename, then calls
569 * blk_get_devnum_by_type().
570 *
571 * @if_typename: Block device type name
572 * @devnum: Device number
573 * @return point to block device descriptor, or NULL if not found
574 */
575 struct blk_desc *blk_get_devnum_by_typename(const char *if_typename,
576 int devnum);
577
578 /**
579 * blk_dselect_hwpart() - select a hardware partition
580 *
581 * This selects a hardware partition (such as is supported by MMC). The block
582 * device size may change as this effectively points the block device to a
583 * partition at the hardware level. See the select_hwpart() method above.
584 *
585 * @desc: Block device descriptor for the device to select
586 * @hwpart: Partition number to select
587 * @return 0 if OK, -ve on error
588 */
589 int blk_dselect_hwpart(struct blk_desc *desc, int hwpart);
590
591 /**
592 * blk_list_part() - list the partitions for block devices of a given type
593 *
594 * This looks up the partition type for each block device of type @if_type,
595 * then displays a list of partitions.
596 *
597 * @if_type: Block device type
598 * @return 0 if OK, -ENODEV if there is none of that type
599 */
600 int blk_list_part(enum if_type if_type);
601
602 /**
603 * blk_list_devices() - list the block devices of a given type
604 *
605 * This lists each block device of the type @if_type, showing the capacity
606 * as well as type-specific information.
607 *
608 * @if_type: Block device type
609 */
610 void blk_list_devices(enum if_type if_type);
611
612 /**
613 * blk_show_device() - show information about a given block device
614 *
615 * This shows the block device capacity as well as type-specific information.
616 *
617 * @if_type: Block device type
618 * @devnum: Device number
619 * @return 0 if OK, -ENODEV for invalid device number
620 */
621 int blk_show_device(enum if_type if_type, int devnum);
622
623 /**
624 * blk_print_device_num() - show information about a given block device
625 *
626 * This is similar to blk_show_device() but returns an error if the block
627 * device type is unknown.
628 *
629 * @if_type: Block device type
630 * @devnum: Device number
631 * @return 0 if OK, -ENODEV for invalid device number, -ENOENT if the block
632 * device is not connected
633 */
634 int blk_print_device_num(enum if_type if_type, int devnum);
635
636 /**
637 * blk_print_part_devnum() - print the partition information for a device
638 *
639 * @if_type: Block device type
640 * @devnum: Device number
641 * @return 0 if OK, -ENOENT if the block device is not connected, -ENOSYS if
642 * the interface type is not supported, other -ve on other error
643 */
644 int blk_print_part_devnum(enum if_type if_type, int devnum);
645
646 /**
647 * blk_read_devnum() - read blocks from a device
648 *
649 * @if_type: Block device type
650 * @devnum: Device number
651 * @blkcnt: Number of blocks to read
652 * @buffer: Address to write data to
653 * @return number of blocks read, or -ve error number on error
654 */
655 ulong blk_read_devnum(enum if_type if_type, int devnum, lbaint_t start,
656 lbaint_t blkcnt, void *buffer);
657
658 /**
659 * blk_write_devnum() - write blocks to a device
660 *
661 * @if_type: Block device type
662 * @devnum: Device number
663 * @blkcnt: Number of blocks to write
664 * @buffer: Address to read data from
665 * @return number of blocks written, or -ve error number on error
666 */
667 ulong blk_write_devnum(enum if_type if_type, int devnum, lbaint_t start,
668 lbaint_t blkcnt, const void *buffer);
669
670 /**
671 * blk_write_zeroes_devnum() - write blocks to a device with zero data
672 *
673 * @if_type: Block device type
674 * @devnum: Device number
675 * @blkcnt: Number of blocks to write
676 * @return number of blocks written, or -ve error number on error
677 */
678 ulong blk_write_zeroes_devnum(enum if_type if_type, int devnum, lbaint_t start,
679 lbaint_t blkcnt);
680
681 /**
682 * blk_erase_devnum() - erase blocks to a device
683 *
684 * @if_type: Block device type
685 * @devnum: Device number
686 * @blkcnt: Number of blocks to erase
687 * @return number of blocks erased, or -ve error number on error
688 */
689 ulong blk_erase_devnum(enum if_type if_type, int devnum, lbaint_t start,
690 lbaint_t blkcnt);
691 /**
692 * blk_select_hwpart_devnum() - select a hardware partition
693 *
694 * This is similar to blk_dselect_hwpart() but it looks up the interface and
695 * device number.
696 *
697 * @if_type: Block device type
698 * @devnum: Device number
699 * @hwpart: Partition number to select
700 * @return 0 if OK, -ve on error
701 */
702 int blk_select_hwpart_devnum(enum if_type if_type, int devnum, int hwpart);
703
704 /**
705 * blk_get_if_type_name() - Get the name of an interface type
706 *
707 * @if_type: Interface type to check
708 * @return name of interface, or NULL if none
709 */
710 const char *blk_get_if_type_name(enum if_type if_type);
711
712 /**
713 * blk_common_cmd() - handle common commands with block devices
714 *
715 * @args: Number of arguments to the command (argv[0] is the command itself)
716 * @argv: Command arguments
717 * @if_type: Interface type
718 * @cur_devnump: Current device number for this interface type
719 * @return 0 if OK, CMD_RET_ERROR on error
720 */
721 int blk_common_cmd(int argc, char * const argv[], enum if_type if_type,
722 int *cur_devnump);
723
724 /**
725 * if_typename_to_iftype() - get iftype according to iftype name
726 *
727 * @if_typename: iftype name
728 * @return iftype index
729 */
730 enum if_type if_typename_to_iftype(const char *if_typename);
731
732 #endif
733