coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
storage.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #ifndef __COMMONLIB_STORAGE_H__
4 #define __COMMONLIB_STORAGE_H__
5 
7 
8 /*
9  * EXT_CSD fields
10  */
11 #define EXT_CSD_GP_SIZE_MULT_GP0 143 /* RO */
12 #define EXT_CSD_GP_SIZE_MULT_GP1 146 /* RO */
13 #define EXT_CSD_GP_SIZE_MULT_GP2 149 /* RO */
14 #define EXT_CSD_GP_SIZE_MULT_GP3 152 /* RO */
15 #define EXT_CSD_PARTITIONING_SUPPORT 160 /* RO */
16 #define EXT_CSD_RPMB_SIZE_MULT 168 /* RO */
17 #define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */
18 #define EXT_CSD_PART_CONF 179 /* R/W */
19 #define EXT_CSD_BUS_WIDTH 183 /* R/W */
20 #define EXT_CSD_STROBE_SUPPORT 184 /* RO */
21 #define EXT_CSD_HS_TIMING 185 /* R/W */
22 #define EXT_CSD_REV 192 /* RO */
23 #define EXT_CSD_CARD_TYPE 196 /* RO */
24 #define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */
25 #define EXT_CSD_HC_WP_GRP_SIZE 221 /* RO */
26 #define EXT_CSD_HC_ERASE_GRP_SIZE 224 /* RO */
27 #define EXT_CSD_BOOT_SIZE_MULT 226 /* RO */
28 #define EXT_CSD_TRIM_MULT 232 /* RO */
29 
30 /*
31  * EXT_CSD field definitions
32  */
33 
34 #define EXT_CSD_CMD_SET_NORMAL (1 << 0)
35 #define EXT_CSD_CMD_SET_SECURE (1 << 1)
36 #define EXT_CSD_CMD_SET_CPSECURE (1 << 2)
37 
38 #define EXT_CSD_CARD_TYPE_26 (1 << 0) /* Card can run at 26MHz */
39 #define EXT_CSD_CARD_TYPE_52 (1 << 1) /* Card can run at 52MHz */
40 
41 #define EXT_CSD_BUS_WIDTH_1 0 /* Card is in 1 bit mode */
42 #define EXT_CSD_BUS_WIDTH_4 1 /* Card is in 4 bit mode */
43 #define EXT_CSD_BUS_WIDTH_8 2 /* Card is in 8 bit mode */
44 #define EXT_CSD_DDR_BUS_WIDTH_4 5 /* Card is in 4 bit DDR mode */
45 #define EXT_CSD_DDR_BUS_WIDTH_8 6 /* Card is in 8 bit DDR mode */
46 #define EXT_CSD_BUS_WIDTH_STROBE (1<<7) /* Enhanced strobe mode */
47 
48 #define EXT_CSD_TIMING_BC 0 /* Backwards compatibility */
49 #define EXT_CSD_TIMING_HS 1 /* High speed */
50 #define EXT_CSD_TIMING_HS200 2 /* HS200 */
51 #define EXT_CSD_TIMING_HS400 3 /* HS400 */
52 
53 #define EXT_CSD_SIZE 512
54 
55 /* 179: EXT_CSD_PART_CONF */
56 #define EXT_CSD_PART_ACCESS_MASK 7 /* Partition access mask */
57 
58 /* 175: EXT_CSD_ERASE_GROUP_DEF */
59 #define EXT_CSD_PARTITION_ENABLE 1 /* Enable partition access */
60 
61 struct storage_media {
62  uint64_t capacity[8]; /* Partition capacity in bytes */
64 
65 #define MMC_PARTITION_USER 0
66 #define MMC_PARTITION_BOOT_1 1
67 #define MMC_PARTITION_BOOT_2 2
68 #define MMC_PARTITION_RPMB 3
69 #define MMC_PARTITION_GP1 4
70 #define MMC_PARTITION_GP2 5
71 #define MMC_PARTITION_GP3 6
72 #define MMC_PARTITION_GP4 7
73 
76 
77 #define SD_VERSION_SD 0x20000
78 #define SD_VERSION_2 (SD_VERSION_SD | 0x20)
79 #define SD_VERSION_1_0 (SD_VERSION_SD | 0x10)
80 #define SD_VERSION_1_10 (SD_VERSION_SD | 0x1a)
81 #define MMC_VERSION_MMC 0x10000
82 #define MMC_VERSION_UNKNOWN (MMC_VERSION_MMC)
83 #define MMC_VERSION_1_2 (MMC_VERSION_MMC | 0x12)
84 #define MMC_VERSION_1_4 (MMC_VERSION_MMC | 0x14)
85 #define MMC_VERSION_2_2 (MMC_VERSION_MMC | 0x22)
86 #define MMC_VERSION_3 (MMC_VERSION_MMC | 0x30)
87 #define MMC_VERSION_4 (MMC_VERSION_MMC | 0x40)
88 
93  /* Erase size in terms of block length. */
95  /* Trim operation multiplier for determining timeout. */
97 
99 
100 #define OCR_BUSY 0x80000000
101 #define OCR_HCS 0x40000000
102 #define OCR_VOLTAGE_MASK 0x00FFFF80
103 #define OCR_ACCESS_MODE 0x60000000
104 
105  uint32_t op_cond_response; // The response byte from the last op_cond
106 
111 
112  uint8_t partition_config; /* Duplicate of EXT_CSD_PART_CONF */
113 };
114 
116  uint64_t count);
118  uint64_t count, uint32_t fill_pattern);
120  uint64_t count, void *buffer);
122  uint64_t count, const void *buffer);
123 
125 const char *storage_partition_name(struct storage_media *media,
126  unsigned int partition_number);
128  struct sd_mmc_ctrlr *ctrlr);
129 
131  unsigned int partition_number);
132 
134 
135 #endif /* __COMMONLIB_STORAGE_H__ */
const char * storage_partition_name(struct storage_media *media, unsigned int partition_number)
Definition: storage.c:325
uint64_t storage_block_erase(struct storage_media *media, uint64_t start, uint64_t count)
Definition: storage_erase.c:10
int storage_set_partition(struct storage_media *media, unsigned int partition_number)
Definition: storage.c:309
int storage_setup_media(struct storage_media *media, struct sd_mmc_ctrlr *ctrlr)
Definition: storage.c:188
unsigned int storage_get_current_partition(struct storage_media *media)
Definition: storage.c:339
void storage_display_setup(struct storage_media *media)
Definition: storage.c:88
uint64_t storage_block_write(struct storage_media *media, uint64_t start, uint64_t count, const void *buffer)
Definition: storage_write.c:63
uint64_t storage_block_fill_write(struct storage_media *media, uint64_t start, uint64_t count, uint32_t fill_pattern)
Definition: storage_write.c:84
uint64_t storage_block_read(struct storage_media *media, uint64_t start, uint64_t count, void *buffer)
Definition: storage.c:286
u8 buffer[C2P_BUFFER_MAXSIZE]
Definition: psp_smm.c:18
static struct storage_media media
Definition: sd_media.c:21
unsigned short uint16_t
Definition: stdint.h:11
unsigned int uint32_t
Definition: stdint.h:14
unsigned long long uint64_t
Definition: stdint.h:17
unsigned char uint8_t
Definition: stdint.h:8
uint32_t ocr
Definition: storage.h:98
uint32_t trim_mult
Definition: storage.h:96
uint8_t partition_config
Definition: storage.h:112
uint32_t read_bl_len
Definition: storage.h:89
uint32_t version
Definition: storage.h:75
uint32_t write_bl_len
Definition: storage.h:90
uint32_t csd[4]
Definition: storage.h:108
struct sd_mmc_ctrlr * ctrlr
Definition: storage.h:63
uint32_t op_cond_response
Definition: storage.h:105
uint32_t cid[4]
Definition: storage.h:109
int high_capacity
Definition: storage.h:91
uint32_t tran_speed
Definition: storage.h:92
uint32_t erase_blocks
Definition: storage.h:94
uint16_t rca
Definition: storage.h:110
uint32_t caps
Definition: storage.h:74
uint32_t scr[2]
Definition: storage.h:107
#define count