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