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