ufs.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. /*
  2. * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef UFS_H
  7. #define UFS_H
  8. #include <lib/utils_def.h>
  9. /* register map of UFSHCI */
  10. /* Controller Capabilities */
  11. #define CAP 0x00
  12. #define CAP_NUTRS_MASK 0x1F
  13. /* UFS Version */
  14. #define VER 0x08
  15. /* Host Controller Identification - Product ID */
  16. #define HCDDID 0x10
  17. /* Host Controller Identification Descriptor - Manufacturer ID */
  18. #define HCPMID 0x14
  19. /* Auto-Hibernate Idle Timer */
  20. #define AHIT 0x18
  21. /* Interrupt Status */
  22. #define IS 0x20
  23. /* Interrupt Enable */
  24. #define IE 0x24
  25. /* System Bus Fatal Error Status */
  26. #define UFS_INT_SBFES (1 << 17)
  27. /* Host Controller Fatal Error Status */
  28. #define UFS_INT_HCFES (1 << 16)
  29. /* UTP Error Status */
  30. #define UFS_INT_UTPES (1 << 12)
  31. /* Device Fatal Error Status */
  32. #define UFS_INT_DFES (1 << 11)
  33. /* UIC Command Completion Status */
  34. #define UFS_INT_UCCS (1 << 10)
  35. /* UTP Task Management Request Completion Status */
  36. #define UFS_INT_UTMRCS (1 << 9)
  37. /* UIC Link Startup Status */
  38. #define UFS_INT_ULSS (1 << 8)
  39. /* UIC Link Lost Status */
  40. #define UFS_INT_ULLS (1 << 7)
  41. /* UIC Hibernate Enter Status */
  42. #define UFS_INT_UHES (1 << 6)
  43. /* UIC Hibernate Exit Status */
  44. #define UFS_INT_UHXS (1 << 5)
  45. /* UIC Power Mode Status */
  46. #define UFS_INT_UPMS (1 << 4)
  47. /* UIC Test Mode Status */
  48. #define UFS_INT_UTMS (1 << 3)
  49. /* UIC Error */
  50. #define UFS_INT_UE (1 << 2)
  51. /* UIC DME_ENDPOINTRESET Indication */
  52. #define UFS_INT_UDEPRI (1 << 1)
  53. /* UTP Transfer Request Completion Status */
  54. #define UFS_INT_UTRCS (1 << 0)
  55. #define UFS_INT_FATAL (UFS_INT_DFES |\
  56. UFS_INT_HCFES |\
  57. UFS_INT_SBFES)
  58. #define UFS_INT_ERR (UFS_INT_FATAL |\
  59. UFS_INT_UE)
  60. #define UFS_UIC_PA_ERROR_MASK 0x8000001F
  61. #define UFS_UIC_DL_ERROR_MASK 0x8000FFFF
  62. #define UFS_UIC_NL_ERROR_MASK 0x80000007
  63. #define UFS_UIC_TL_ERROR_MASK 0x8000007F
  64. #define UFS_UIC_DME_ERROR_MASK 0x80000001
  65. #define PA_INIT_ERR (1 << 13)
  66. #define PA_LAYER_GEN_ERR (1 << 4)
  67. /* Host Controller Status */
  68. #define HCS 0x30
  69. #define HCS_UPMCRS_MASK (7 << 8)
  70. #define HCS_PWR_LOCAL (1 << 8)
  71. #define HCS_UCRDY (1 << 3)
  72. #define HCS_UTMRLRDY (1 << 2)
  73. #define HCS_UTRLRDY (1 << 1)
  74. #define HCS_DP (1 << 0)
  75. /* Host Controller Enable */
  76. #define HCE 0x34
  77. #define HCE_ENABLE 1
  78. #define HCE_DISABLE 0
  79. /* Host UIC Error Code PHY Adapter Layer */
  80. #define UECPA 0x38
  81. /* Host UIC Error Code Data Link Layer */
  82. #define UECDL 0x3C
  83. /* Host UIC Error Code Network Layer */
  84. #define UECN 0x40
  85. /* Host UIC Error Code Transport Layer */
  86. #define UECT 0x44
  87. /* Host UIC Error Code */
  88. #define UECDME 0x48
  89. /* UTP Transfer Request Interrupt Aggregation Control Register */
  90. #define UTRIACR 0x4C
  91. #define UTRIACR_IAEN (1U << 31)
  92. #define UTRIACR_IAPWEN (1 << 24)
  93. #define UTRIACR_IASB (1 << 20)
  94. #define UTRIACR_CTR (1 << 16)
  95. #define UTRIACR_IACTH(x) (((x) & 0x1F) << 8)
  96. #define UTRIACR_IATOVAL(x) ((x) & 0xFF)
  97. /* UTP Transfer Request List Base Address */
  98. #define UTRLBA 0x50
  99. /* UTP Transfer Request List Base Address Upper 32-bits */
  100. #define UTRLBAU 0x54
  101. /* UTP Transfer Request List Door Bell Register */
  102. #define UTRLDBR 0x58
  103. /* UTP Transfer Request List Clear Register */
  104. #define UTRLCLR 0x5C
  105. /* UTP Transfer Request List Run Stop Register */
  106. #define UTRLRSR 0x60
  107. #define UTMRLBA 0x70
  108. #define UTMRLBAU 0x74
  109. #define UTMRLDBR 0x78
  110. #define UTMRLCLR 0x7C
  111. #define UTMRLRSR 0x80
  112. /* UIC Command */
  113. #define UICCMD 0x90
  114. /* UIC Command Argument 1 */
  115. #define UCMDARG1 0x94
  116. /* UIC Command Argument 2 */
  117. #define UCMDARG2 0x98
  118. /* UIC Command Argument 3 */
  119. #define UCMDARG3 0x9C
  120. #define UFS_BLOCK_SHIFT 12 /* 4KB */
  121. #define UFS_BLOCK_SIZE (1 << UFS_BLOCK_SHIFT)
  122. #define UFS_BLOCK_MASK (UFS_BLOCK_SIZE - 1)
  123. #define UFS_MAX_LUNS 8
  124. /* UTP Transfer Request Descriptor */
  125. /* Command Type */
  126. #define CT_UFS_STORAGE 1
  127. #define CT_SCSI 0
  128. /* Data Direction */
  129. #define DD_OUT 2 /* Device --> Host */
  130. #define DD_IN 1 /* Host --> Device */
  131. #define DD_NO_DATA_TRANSFER 0
  132. #define UTP_TRD_SIZE 32
  133. /* Transaction Type */
  134. #define TRANS_TYPE_HD (1 << 7) /* E2ECRC */
  135. #define TRANS_TYPE_DD (1 << 6)
  136. #define TRANS_TYPE_CODE_MASK 0x3F
  137. #define QUERY_RESPONSE_UPIU (0x36 << 0)
  138. #define READY_TO_TRANSACTION_UPIU (0x31 << 0)
  139. #define DATA_IN_UPIU (0x22 << 0)
  140. #define RESPONSE_UPIU (0x21 << 0)
  141. #define NOP_IN_UPIU (0x20 << 0)
  142. #define QUERY_REQUEST_UPIU (0x16 << 0)
  143. #define DATA_OUT_UPIU (0x02 << 0)
  144. #define CMD_UPIU (0x01 << 0)
  145. #define NOP_OUT_UPIU (0x00 << 0)
  146. #define OCS_SUCCESS 0x0
  147. #define OCS_INVALID_FUNC_ATTRIBUTE 0x1
  148. #define OCS_MISMATCH_REQUEST_SIZE 0x2
  149. #define OCS_MISMATCH_RESPONSE_SIZE 0x3
  150. #define OCS_PEER_COMMUNICATION_FAILURE 0x4
  151. #define OCS_ABORTED 0x5
  152. #define OCS_FATAL_ERROR 0x6
  153. #define OCS_MASK 0xF
  154. /* UIC Command */
  155. #define DME_GET 0x01
  156. #define DME_SET 0x02
  157. #define DME_PEER_GET 0x03
  158. #define DME_PEER_SET 0x04
  159. #define DME_POWERON 0x10
  160. #define DME_POWEROFF 0x11
  161. #define DME_ENABLE 0x12
  162. #define DME_RESET 0x14
  163. #define DME_ENDPOINTRESET 0x15
  164. #define DME_LINKSTARTUP 0x16
  165. #define DME_HIBERNATE_ENTER 0x17
  166. #define DME_HIBERNATE_EXIT 0x18
  167. #define DME_TEST_MODE 0x1A
  168. #define GEN_SELECTOR_IDX(x) ((x) & 0xFFFF)
  169. #define CONFIG_RESULT_CODE_MASK 0xFF
  170. #define CDBCMD_TEST_UNIT_READY 0x00
  171. #define CDBCMD_READ_6 0x08
  172. #define CDBCMD_WRITE_6 0x0A
  173. #define CDBCMD_START_STOP_UNIT 0x1B
  174. #define CDBCMD_READ_CAPACITY_10 0x25
  175. #define CDBCMD_READ_10 0x28
  176. #define CDBCMD_WRITE_10 0x2A
  177. #define CDBCMD_READ_16 0x88
  178. #define CDBCMD_WRITE_16 0x8A
  179. #define CDBCMD_READ_CAPACITY_16 0x9E
  180. #define CDBCMD_REPORT_LUNS 0xA0
  181. #define UPIU_FLAGS_R (1 << 6)
  182. #define UPIU_FLAGS_W (1 << 5)
  183. #define UPIU_FLAGS_ATTR_MASK (3 << 0)
  184. #define UPIU_FLAGS_ATTR_S (0 << 0) /* Simple */
  185. #define UPIU_FLAGS_ATTR_O (1 << 0) /* Ordered */
  186. #define UPIU_FLAGS_ATTR_HQ (2 << 0) /* Head of Queue */
  187. #define UPIU_FLAGS_ATTR_ACA (3 << 0)
  188. #define UPIU_FLAGS_O (1 << 6)
  189. #define UPIU_FLAGS_U (1 << 5)
  190. #define UPIU_FLAGS_D (1 << 4)
  191. #define QUERY_FUNC_STD_READ 0x01
  192. #define QUERY_FUNC_STD_WRITE 0x81
  193. #define QUERY_NOP 0x00
  194. #define QUERY_READ_DESC 0x01
  195. #define QUERY_WRITE_DESC 0x02
  196. #define QUERY_READ_ATTR 0x03
  197. #define QUERY_WRITE_ATTR 0x04
  198. #define QUERY_READ_FLAG 0x05
  199. #define QUERY_SET_FLAG 0x06
  200. #define QUERY_CLEAR_FLAG 0x07
  201. #define QUERY_TOGGLE_FLAG 0x08
  202. #define RW_WITHOUT_CACHE 0x18
  203. #define DESC_TYPE_DEVICE 0x00
  204. #define DESC_TYPE_CONFIGURATION 0x01
  205. #define DESC_TYPE_UNIT 0x02
  206. #define DESC_TYPE_INTERCONNECT 0x04
  207. #define DESC_TYPE_STRING 0x05
  208. #define DESC_DEVICE_MAX_SIZE 0x1F
  209. #define DEVICE_DESC_PARAM_MANF_ID 0x18
  210. #define ATTR_CUR_PWR_MODE 0x02 /* bCurrentPowerMode */
  211. #define ATTR_ACTIVECC 0x03 /* bActiveICCLevel */
  212. #define DEVICE_DESCRIPTOR_LEN 0x40
  213. #define UNIT_DESCRIPTOR_LEN 0x23
  214. #define QUERY_RESP_SUCCESS 0x00
  215. #define QUERY_RESP_OPCODE 0xFE
  216. #define QUERY_RESP_GENERAL_FAIL 0xFF
  217. #define SENSE_KEY_NO_SENSE 0x00
  218. #define SENSE_KEY_RECOVERED_ERROR 0x01
  219. #define SENSE_KEY_NOT_READY 0x02
  220. #define SENSE_KEY_MEDIUM_ERROR 0x03
  221. #define SENSE_KEY_HARDWARE_ERROR 0x04
  222. #define SENSE_KEY_ILLEGAL_REQUEST 0x05
  223. #define SENSE_KEY_UNIT_ATTENTION 0x06
  224. #define SENSE_KEY_DATA_PROTECT 0x07
  225. #define SENSE_KEY_BLANK_CHECK 0x08
  226. #define SENSE_KEY_VENDOR_SPECIFIC 0x09
  227. #define SENSE_KEY_COPY_ABORTED 0x0A
  228. #define SENSE_KEY_ABORTED_COMMAND 0x0B
  229. #define SENSE_KEY_VOLUME_OVERFLOW 0x0D
  230. #define SENSE_KEY_MISCOMPARE 0x0E
  231. #define SENSE_DATA_VALID 0x70
  232. #define SENSE_DATA_LENGTH 18
  233. #define READ_CAPACITY_LENGTH 8
  234. #define FLAG_DEVICE_INIT 0x01
  235. #define UFS_VENDOR_SKHYNIX U(0x1AD)
  236. #define MAX_MODEL_LEN 16
  237. /* maximum number of retries for a general UIC command */
  238. #define UFS_UIC_COMMAND_RETRIES 3
  239. /* maximum number of retries for a transfer command */
  240. #define UFS_CMD_RETRIES 3
  241. /* maximum number of retries for reading UFS capacity */
  242. #define UFS_READ_CAPACITY_RETRIES 10
  243. /* maximum number of link-startup retries */
  244. #define DME_LINKSTARTUP_RETRIES 10
  245. #define HCE_ENABLE_OUTER_RETRIES 3
  246. #define HCE_ENABLE_INNER_RETRIES 50
  247. #define HCE_ENABLE_TIMEOUT_US 100
  248. #define HCE_DISABLE_TIMEOUT_US 1000
  249. #define FDEVICEINIT_TIMEOUT_MS 1500
  250. #define UIC_CMD_TIMEOUT_MS 500
  251. #define QUERY_REQ_TIMEOUT_MS 1500
  252. #define NOP_OUT_TIMEOUT_MS 50
  253. #define CMD_TIMEOUT_MS 5000
  254. /**
  255. * ufs_dev_desc - ufs device details from the device descriptor
  256. * @wmanufacturerid: card details
  257. * @model: card model
  258. */
  259. struct ufs_dev_desc {
  260. uint16_t wmanufacturerid;
  261. int8_t model[MAX_MODEL_LEN + 1];
  262. };
  263. /* UFS Driver Flags */
  264. #define UFS_FLAGS_SKIPINIT (1 << 0)
  265. #define UFS_FLAGS_VENDOR_SKHYNIX (U(1) << 2)
  266. typedef struct sense_data {
  267. uint8_t resp_code : 7;
  268. uint8_t valid : 1;
  269. uint8_t reserved0;
  270. uint8_t sense_key : 4;
  271. uint8_t reserved1 : 1;
  272. uint8_t ili : 1;
  273. uint8_t eom : 1;
  274. uint8_t file_mark : 1;
  275. uint8_t info[4];
  276. uint8_t asl;
  277. uint8_t cmd_spec_len[4];
  278. uint8_t asc;
  279. uint8_t ascq;
  280. uint8_t fruc;
  281. uint8_t sense_key_spec0 : 7;
  282. uint8_t sksv : 1;
  283. uint8_t sense_key_spec1;
  284. uint8_t sense_key_spec2;
  285. } sense_data_t;
  286. /* UTP Transfer Request Descriptor */
  287. typedef struct utrd_header {
  288. uint32_t reserved0 : 24;
  289. uint32_t i : 1; /* interrupt */
  290. uint32_t dd : 2; /* data direction */
  291. uint32_t reserved1 : 1;
  292. uint32_t ct : 4; /* command type */
  293. uint32_t reserved2;
  294. uint32_t ocs : 8; /* Overall Command Status */
  295. uint32_t reserved3 : 24;
  296. uint32_t reserved4;
  297. uint32_t ucdba; /* aligned to 128-byte */
  298. uint32_t ucdbau; /* Upper 32-bits */
  299. uint32_t rul : 16; /* Response UPIU Length */
  300. uint32_t ruo : 16; /* Response UPIU Offset */
  301. uint32_t prdtl : 16; /* PRDT Length */
  302. uint32_t prdto : 16; /* PRDT Offset */
  303. } utrd_header_t; /* 8 words with little endian */
  304. /* UTP Task Management Request Descriptor */
  305. typedef struct utp_utmrd {
  306. /* 4 words with little endian */
  307. uint32_t reserved0 : 24;
  308. uint32_t i : 1; /* interrupt */
  309. uint32_t reserved1 : 7;
  310. uint32_t reserved2;
  311. uint32_t ocs : 8; /* Overall Command Status */
  312. uint32_t reserved3 : 24;
  313. uint32_t reserved4;
  314. /* followed by 8 words UPIU with big endian */
  315. /* followed by 8 words Response UPIU with big endian */
  316. } utp_utmrd_t;
  317. /* NOP OUT UPIU */
  318. typedef struct nop_out_upiu {
  319. uint8_t trans_type;
  320. uint8_t flags;
  321. uint8_t reserved0;
  322. uint8_t task_tag;
  323. uint8_t reserved1;
  324. uint8_t reserved2;
  325. uint8_t reserved3;
  326. uint8_t reserved4;
  327. uint8_t total_ehs_len;
  328. uint8_t reserved5;
  329. uint16_t data_segment_len;
  330. uint32_t reserved6;
  331. uint32_t reserved7;
  332. uint32_t reserved8;
  333. uint32_t reserved9;
  334. uint32_t reserved10;
  335. uint32_t e2ecrc;
  336. } nop_out_upiu_t; /* 36 bytes with big endian */
  337. /* NOP IN UPIU */
  338. typedef struct nop_in_upiu {
  339. uint8_t trans_type;
  340. uint8_t flags;
  341. uint8_t reserved0;
  342. uint8_t task_tag;
  343. uint8_t reserved1;
  344. uint8_t reserved2;
  345. uint8_t response;
  346. uint8_t reserved3;
  347. uint8_t total_ehs_len;
  348. uint8_t dev_info;
  349. uint16_t data_segment_len;
  350. uint32_t reserved4;
  351. uint32_t reserved5;
  352. uint32_t reserved6;
  353. uint32_t reserved7;
  354. uint32_t reserved8;
  355. uint32_t e2ecrc;
  356. } nop_in_upiu_t; /* 36 bytes with big endian */
  357. /* Command UPIU */
  358. typedef struct cmd_upiu {
  359. uint8_t trans_type;
  360. uint8_t flags;
  361. uint8_t lun;
  362. uint8_t task_tag;
  363. uint8_t cmd_set_type;
  364. uint8_t reserved0;
  365. uint8_t reserved1;
  366. uint8_t reserved2;
  367. uint8_t total_ehs_len;
  368. uint8_t reserved3;
  369. uint16_t data_segment_len;
  370. uint32_t exp_data_trans_len;
  371. /*
  372. * A CDB has a fixed length of 16bytes or a variable length
  373. * of between 12 and 260 bytes
  374. */
  375. uint8_t cdb[16]; /* little endian */
  376. } cmd_upiu_t; /* 32 bytes with big endian except for cdb[] */
  377. typedef struct query_desc {
  378. uint8_t opcode;
  379. uint8_t idn;
  380. uint8_t index;
  381. uint8_t selector;
  382. uint8_t reserved0[2];
  383. uint16_t length;
  384. uint32_t reserved2[2];
  385. } query_desc_t; /* 16 bytes with big endian */
  386. typedef struct query_flag {
  387. uint8_t opcode;
  388. uint8_t idn;
  389. uint8_t index;
  390. uint8_t selector;
  391. uint8_t reserved0[7];
  392. uint8_t value;
  393. uint32_t reserved8;
  394. } query_flag_t; /* 16 bytes with big endian */
  395. typedef struct query_attr {
  396. uint8_t opcode;
  397. uint8_t idn;
  398. uint8_t index;
  399. uint8_t selector;
  400. uint8_t reserved0[4];
  401. uint32_t value; /* little endian */
  402. uint32_t reserved4;
  403. } query_attr_t; /* 16 bytes with big endian except for value */
  404. /* Query Request UPIU */
  405. typedef struct query_upiu {
  406. uint8_t trans_type;
  407. uint8_t flags;
  408. uint8_t reserved0;
  409. uint8_t task_tag;
  410. uint8_t reserved1;
  411. uint8_t query_func;
  412. uint8_t reserved2;
  413. uint8_t reserved3;
  414. uint8_t total_ehs_len;
  415. uint8_t reserved4;
  416. uint16_t data_segment_len;
  417. /* Transaction Specific Fields */
  418. union {
  419. query_desc_t desc;
  420. query_flag_t flag;
  421. query_attr_t attr;
  422. } ts;
  423. uint32_t reserved5;
  424. } query_upiu_t; /* 32 bytes with big endian */
  425. /* Query Response UPIU */
  426. typedef struct query_resp_upiu {
  427. uint8_t trans_type;
  428. uint8_t flags;
  429. uint8_t reserved0;
  430. uint8_t task_tag;
  431. uint8_t reserved1;
  432. uint8_t query_func;
  433. uint8_t query_resp;
  434. uint8_t reserved2;
  435. uint8_t total_ehs_len;
  436. uint8_t dev_info;
  437. uint16_t data_segment_len;
  438. union {
  439. query_desc_t desc;
  440. query_flag_t flag;
  441. query_attr_t attr;
  442. } ts;
  443. uint32_t reserved3;
  444. } query_resp_upiu_t; /* 32 bytes with big endian */
  445. /* Response UPIU */
  446. typedef struct resp_upiu {
  447. uint8_t trans_type;
  448. uint8_t flags;
  449. uint8_t lun;
  450. uint8_t task_tag;
  451. uint8_t cmd_set_type;
  452. uint8_t reserved0;
  453. uint8_t reserved1;
  454. uint8_t status;
  455. uint8_t total_ehs_len;
  456. uint8_t dev_info;
  457. uint16_t data_segment_len;
  458. uint32_t res_trans_cnt; /* Residual Transfer Count */
  459. uint32_t reserved2[4];
  460. uint16_t sense_data_len;
  461. union {
  462. uint8_t sense_data[18];
  463. sense_data_t sense;
  464. } sd;
  465. } resp_upiu_t; /* 52 bytes with big endian */
  466. typedef struct cmd_info {
  467. uintptr_t buf;
  468. size_t length;
  469. int lba;
  470. uint8_t op;
  471. uint8_t direction;
  472. uint8_t lun;
  473. } cmd_info_t;
  474. typedef struct utp_utrd {
  475. uintptr_t header; /* utrd_header_t */
  476. uintptr_t upiu;
  477. uintptr_t resp_upiu;
  478. uintptr_t prdt;
  479. size_t size_upiu;
  480. size_t size_resp_upiu;
  481. size_t prdt_length;
  482. int task_tag;
  483. } utp_utrd_t;
  484. /* Physical Region Description Table */
  485. typedef struct prdt {
  486. uint32_t dba; /* Data Base Address */
  487. uint32_t dbau; /* Data Base Address Upper 32-bits */
  488. uint32_t reserved0;
  489. uint32_t dbc : 18; /* Data Byte Count */
  490. uint32_t reserved1 : 14;
  491. } prdt_t;
  492. typedef struct uic_cmd {
  493. uint32_t op;
  494. uint32_t arg1;
  495. uint32_t arg2;
  496. uint32_t arg3;
  497. } uic_cmd_t;
  498. typedef struct ufs_params {
  499. uintptr_t reg_base;
  500. uintptr_t desc_base;
  501. size_t desc_size;
  502. unsigned long flags;
  503. } ufs_params_t;
  504. typedef struct ufs_ops {
  505. int (*phy_init)(ufs_params_t *params);
  506. int (*phy_set_pwr_mode)(ufs_params_t *params);
  507. } ufs_ops_t;
  508. int ufshc_send_uic_cmd(uintptr_t base, uic_cmd_t *cmd);
  509. int ufshc_dme_get(unsigned int attr, unsigned int idx, unsigned int *val);
  510. int ufshc_dme_set(unsigned int attr, unsigned int idx, unsigned int val);
  511. unsigned int ufs_read_attr(int idn);
  512. void ufs_write_attr(int idn, unsigned int value);
  513. unsigned int ufs_read_flag(int idn);
  514. void ufs_set_flag(int idn);
  515. void ufs_clear_flag(int idn);
  516. void ufs_read_desc(int idn, int index, uintptr_t buf, size_t size);
  517. void ufs_write_desc(int idn, int index, uintptr_t buf, size_t size);
  518. size_t ufs_read_blocks(int lun, int lba, uintptr_t buf, size_t size);
  519. size_t ufs_write_blocks(int lun, int lba, const uintptr_t buf, size_t size);
  520. int ufs_init(const ufs_ops_t *ops, ufs_params_t *params);
  521. #endif /* UFS_H */