1 /* 2 * (C) Copyright 2000-2004 3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 4 * 5 * SPDX-License-Identifier: GPL-2.0+ 6 */ 7 8 #ifndef BLK_H 9 #define BLK_H 10 11 #ifdef CONFIG_SYS_64BIT_LBA 12 typedef uint64_t lbaint_t; 13 #define LBAFlength "ll" 14 #else 15 typedef ulong lbaint_t; 16 #define LBAFlength "l" 17 #endif 18 #define LBAF "%" LBAFlength "x" 19 #define LBAFU "%" LBAFlength "u" 20 21 /* Interface types: */ 22 enum if_type { 23 IF_TYPE_UNKNOWN = 0, 24 IF_TYPE_IDE, 25 IF_TYPE_SCSI, 26 IF_TYPE_ATAPI, 27 IF_TYPE_USB, 28 IF_TYPE_DOC, 29 IF_TYPE_MMC, 30 IF_TYPE_SD, 31 IF_TYPE_SATA, 32 IF_TYPE_HOST, 33 34 IF_TYPE_COUNT, /* Number of interface types */ 35 }; 36 37 struct blk_desc { 38 enum if_type if_type; /* type of the interface */ 39 int devnum; /* device number */ 40 unsigned char part_type; /* partition type */ 41 unsigned char target; /* target SCSI ID */ 42 unsigned char lun; /* target LUN */ 43 unsigned char hwpart; /* HW partition, e.g. for eMMC */ 44 unsigned char type; /* device type */ 45 unsigned char removable; /* removable device */ 46 #ifdef CONFIG_LBA48 47 /* device can use 48bit addr (ATA/ATAPI v7) */ 48 unsigned char lba48; 49 #endif 50 lbaint_t lba; /* number of blocks */ 51 unsigned long blksz; /* block size */ 52 int log2blksz; /* for convenience: log2(blksz) */ 53 char vendor[40+1]; /* IDE model, SCSI Vendor */ 54 char product[20+1]; /* IDE Serial no, SCSI product */ 55 char revision[8+1]; /* firmware revision */ 56 unsigned long (*block_read)(struct blk_desc *block_dev, 57 lbaint_t start, 58 lbaint_t blkcnt, 59 void *buffer); 60 unsigned long (*block_write)(struct blk_desc *block_dev, 61 lbaint_t start, 62 lbaint_t blkcnt, 63 const void *buffer); 64 unsigned long (*block_erase)(struct blk_desc *block_dev, 65 lbaint_t start, 66 lbaint_t blkcnt); 67 void *priv; /* driver private struct pointer */ 68 }; 69 70 #define BLOCK_CNT(size, blk_desc) (PAD_COUNT(size, blk_desc->blksz)) 71 #define PAD_TO_BLOCKSIZE(size, blk_desc) \ 72 (PAD_SIZE(size, blk_desc->blksz)) 73 74 /* 75 * These functions should take struct udevice instead of struct blk_desc, 76 * but this is convenient for migration to driver model. Add a 'd' prefix 77 * to the function operations, so that blk_read(), etc. can be reserved for 78 * functions with the correct arguments. 79 */ 80 static inline ulong blk_dread(struct blk_desc *block_dev, lbaint_t start, 81 lbaint_t blkcnt, void *buffer) 82 { 83 /* 84 * We could check if block_read is NULL and return -ENOSYS. But this 85 * bloats the code slightly (cause some board to fail to build), and 86 * it would be an error to try an operation that does not exist. 87 */ 88 return block_dev->block_read(block_dev, start, blkcnt, buffer); 89 } 90 91 static inline ulong blk_dwrite(struct blk_desc *block_dev, lbaint_t start, 92 lbaint_t blkcnt, const void *buffer) 93 { 94 return block_dev->block_write(block_dev, start, blkcnt, buffer); 95 } 96 97 static inline ulong blk_derase(struct blk_desc *block_dev, lbaint_t start, 98 lbaint_t blkcnt) 99 { 100 return block_dev->block_erase(block_dev, start, blkcnt); 101 } 102 103 #endif 104