2 * (C) Copyright 2000-2004
5 * SPDX-License-Identifier: GPL-2.0+
11 #ifdef CONFIG_SYS_64BIT_LBA
12 typedef uint64_t lbaint_t;
13 #define LBAFlength "ll"
15 typedef ulong lbaint_t;
16 #define LBAFlength "l"
18 #define LBAF "%" LBAFlength "x"
19 #define LBAFU "%" LBAFlength "u"
21 /* Interface types: */
34 IF_TYPE_COUNT, /* Number of interface types */
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 */
47 /* device can use 48bit addr (ATA/ATAPI v7) */
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,
60 unsigned long (*block_write)(struct blk_desc *block_dev,
64 unsigned long (*block_erase)(struct blk_desc *block_dev,
67 void *priv; /* driver private struct pointer */
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))
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.
80 static inline ulong blk_dread(struct blk_desc *block_dev, lbaint_t start,
81 lbaint_t blkcnt, void *buffer)
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.
88 return block_dev->block_read(block_dev, start, blkcnt, buffer);
91 static inline ulong blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
92 lbaint_t blkcnt, const void *buffer)
94 return block_dev->block_write(block_dev, start, blkcnt, buffer);
97 static inline ulong blk_derase(struct blk_desc *block_dev, lbaint_t start,
100 return block_dev->block_erase(block_dev, start, blkcnt);