blob: 7b2e5e286f2a9abdba513783431093ee0909c46f [file] [log] [blame]
Simon Glass1a736612016-02-29 15:25:39 -07001/*
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
12typedef uint64_t lbaint_t;
13#define LBAFlength "ll"
14#else
15typedef ulong lbaint_t;
16#define LBAFlength "l"
17#endif
18#define LBAF "%" LBAFlength "x"
19#define LBAFU "%" LBAFlength "u"
20
21/* Interface types: */
Simon Glass5ec4f1a2016-02-29 15:25:40 -070022enum 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};
Simon Glass1a736612016-02-29 15:25:39 -070036
37struct blk_desc {
Simon Glass5ec4f1a2016-02-29 15:25:40 -070038 enum if_type if_type; /* type of the interface */
Simon Glassbcce53d2016-02-29 15:25:51 -070039 int devnum; /* device number */
Simon Glass1a736612016-02-29 15:25:39 -070040 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
Simon Glass2a981dc2016-02-29 15:25:52 -070074/*
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 */
80static 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
91static 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
97static 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
Simon Glass1a736612016-02-29 15:25:39 -0700103#endif