blk.h 21 KB

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