blk.h 21 KB

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