blk.h 21 KB

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