blk.h 21 KB

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