]>
git.ipfire.org Git - people/ms/u-boot.git/blob - include/blk.h
2 * (C) Copyright 2000-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
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 * With driver model (CONFIG_BLK) this is uclass platform data, accessible
39 * with dev_get_uclass_platdata(dev)
43 * TODO: With driver model we should be able to use the parent
44 * device's uclass instead.
46 enum if_type if_type
; /* type of the interface */
47 int devnum
; /* device number */
48 unsigned char part_type
; /* partition type */
49 unsigned char target
; /* target SCSI ID */
50 unsigned char lun
; /* target LUN */
51 unsigned char hwpart
; /* HW partition, e.g. for eMMC */
52 unsigned char type
; /* device type */
53 unsigned char removable
; /* removable device */
55 /* device can use 48bit addr (ATA/ATAPI v7) */
58 lbaint_t lba
; /* number of blocks */
59 unsigned long blksz
; /* block size */
60 int log2blksz
; /* for convenience: log2(blksz) */
61 char vendor
[40+1]; /* IDE model, SCSI Vendor */
62 char product
[20+1]; /* IDE Serial no, SCSI product */
63 char revision
[8+1]; /* firmware revision */
67 unsigned long (*block_read
)(struct blk_desc
*block_dev
,
71 unsigned long (*block_write
)(struct blk_desc
*block_dev
,
75 unsigned long (*block_erase
)(struct blk_desc
*block_dev
,
78 void *priv
; /* driver private struct pointer */
82 #define BLOCK_CNT(size, blk_desc) (PAD_COUNT(size, blk_desc->blksz))
83 #define PAD_TO_BLOCKSIZE(size, blk_desc) \
84 (PAD_SIZE(size, blk_desc->blksz))
89 /* Operations on block devices */
92 * read() - read from a block device
94 * @dev: Device to read from
95 * @start: Start block number to read (0=first)
96 * @blkcnt: Number of blocks to read
97 * @buffer: Destination buffer for data read
98 * @return number of blocks read, or -ve error number (see the
99 * IS_ERR_VALUE() macro
101 unsigned long (*read
)(struct udevice
*dev
, lbaint_t start
,
102 lbaint_t blkcnt
, void *buffer
);
105 * write() - write to a block device
107 * @dev: Device to write to
108 * @start: Start block number to write (0=first)
109 * @blkcnt: Number of blocks to write
110 * @buffer: Source buffer for data to write
111 * @return number of blocks written, or -ve error number (see the
112 * IS_ERR_VALUE() macro
114 unsigned long (*write
)(struct udevice
*dev
, lbaint_t start
,
115 lbaint_t blkcnt
, const void *buffer
);
118 * erase() - erase a section of a block device
120 * @dev: Device to (partially) erase
121 * @start: Start block number to erase (0=first)
122 * @blkcnt: Number of blocks to erase
123 * @return number of blocks erased, or -ve error number (see the
124 * IS_ERR_VALUE() macro
126 unsigned long (*erase
)(struct udevice
*dev
, lbaint_t start
,
130 #define blk_get_ops(dev) ((struct blk_ops *)(dev)->driver->ops)
133 * These functions should take struct udevice instead of struct blk_desc,
134 * but this is convenient for migration to driver model. Add a 'd' prefix
135 * to the function operations, so that blk_read(), etc. can be reserved for
136 * functions with the correct arguments.
138 unsigned long blk_dread(struct blk_desc
*block_dev
, lbaint_t start
,
139 lbaint_t blkcnt
, void *buffer
);
140 unsigned long blk_dwrite(struct blk_desc
*block_dev
, lbaint_t start
,
141 lbaint_t blkcnt
, const void *buffer
);
142 unsigned long blk_derase(struct blk_desc
*block_dev
, lbaint_t start
,
146 * blk_get_device() - Find and probe a block device ready for use
148 * @if_type: Interface type (enum if_type_t)
149 * @devnum: Device number (specific to each interface type)
150 * @devp: the device, if found
151 * @return - if found, -ENODEV if no device found, or other -ve error value
153 int blk_get_device(int if_type
, int devnum
, struct udevice
**devp
);
156 * blk_first_device() - Find the first device for a given interface
158 * The device is probed ready for use
160 * @devnum: Device number (specific to each interface type)
161 * @devp: the device, if found
162 * @return 0 if found, -ENODEV if no device, or other -ve error value
164 int blk_first_device(int if_type
, struct udevice
**devp
);
167 * blk_next_device() - Find the next device for a given interface
169 * This can be called repeatedly after blk_first_device() to iterate through
170 * all devices of the given interface type.
172 * The device is probed ready for use
174 * @devp: On entry, the previous device returned. On exit, the next
176 * @return 0 if found, -ENODEV if no device, or other -ve error value
178 int blk_next_device(struct udevice
**devp
);
181 * blk_create_device() - Create a new block device
183 * @parent: Parent of the new device
184 * @drv_name: Driver name to use for the block device
185 * @name: Name for the device
186 * @if_type: Interface type (enum if_type_t)
187 * @devnum: Device number, specific to the interface type
188 * @blksz: Block size of the device in bytes (typically 512)
189 * @size: Total size of the device in bytes
190 * @devp: the new device (which has not been probed)
192 int blk_create_device(struct udevice
*parent
, const char *drv_name
,
193 const char *name
, int if_type
, int devnum
, int blksz
,
194 lbaint_t size
, struct udevice
**devp
);
197 * blk_prepare_device() - Prepare a block device for use
199 * This reads partition information from the device if supported.
201 * @dev: Device to prepare
202 * @return 0 if ok, -ve on error
204 int blk_prepare_device(struct udevice
*dev
);
207 * blk_unbind_all() - Unbind all device of the given interface type
209 * The devices are removed and then unbound.
211 * @if_type: Interface type to unbind
212 * @return 0 if OK, -ve on error
214 int blk_unbind_all(int if_type
);
219 * These functions should take struct udevice instead of struct blk_desc,
220 * but this is convenient for migration to driver model. Add a 'd' prefix
221 * to the function operations, so that blk_read(), etc. can be reserved for
222 * functions with the correct arguments.
224 static inline ulong
blk_dread(struct blk_desc
*block_dev
, lbaint_t start
,
225 lbaint_t blkcnt
, void *buffer
)
228 * We could check if block_read is NULL and return -ENOSYS. But this
229 * bloats the code slightly (cause some board to fail to build), and
230 * it would be an error to try an operation that does not exist.
232 return block_dev
->block_read(block_dev
, start
, blkcnt
, buffer
);
235 static inline ulong
blk_dwrite(struct blk_desc
*block_dev
, lbaint_t start
,
236 lbaint_t blkcnt
, const void *buffer
)
238 return block_dev
->block_write(block_dev
, start
, blkcnt
, buffer
);
241 static inline ulong
blk_derase(struct blk_desc
*block_dev
, lbaint_t start
,
244 return block_dev
->block_erase(block_dev
, start
, blkcnt
);
246 #endif /* !CONFIG_BLK */