4 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved.
6 * Written by Jeuk Kim <jeuk20.kim@samsung.com>
8 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include "hw/pci/pci_device.h"
15 #include "hw/scsi/scsi.h"
16 #include "block/ufs.h"
18 #define UFS_MAX_LUS 32
19 #define UFS_BLOCK_SIZE 4096
21 typedef struct UfsBusClass
{
22 BusClass parent_class
;
23 bool (*parent_check_address
)(BusState
*bus
, DeviceState
*dev
, Error
**errp
);
26 typedef struct UfsBus
{
30 #define TYPE_UFS_BUS "ufs-bus"
31 DECLARE_OBJ_CHECKERS(UfsBus
, UfsBusClass
, UFS_BUS
, TYPE_UFS_BUS
)
33 typedef enum UfsRequestState
{
35 UFS_REQUEST_READY
= 1,
36 UFS_REQUEST_RUNNING
= 2,
37 UFS_REQUEST_COMPLETE
= 3,
38 UFS_REQUEST_ERROR
= 4,
41 typedef enum UfsReqResult
{
42 UFS_REQUEST_SUCCESS
= 0,
44 UFS_REQUEST_NO_COMPLETE
= 2,
47 typedef struct UfsRequest
{
49 UfsRequestState state
;
52 UtpTransferReqDesc utrd
;
56 /* for scsi command */
60 typedef struct UfsLu
{
63 UnitDescriptor unit_desc
;
66 typedef struct UfsWLu
{
71 typedef struct UfsParams
{
73 uint8_t nutrs
; /* Number of UTP Transfer Request Slots */
74 uint8_t nutmrs
; /* Number of UTP Task Management Request Slots */
77 typedef struct UfsHc
{
86 UfsLu
*lus
[UFS_MAX_LUS
];
91 DeviceDescriptor device_desc
;
92 GeometryDescriptor geometry_desc
;
93 Attributes attributes
;
101 #define TYPE_UFS "ufs"
102 #define UFS(obj) OBJECT_CHECK(UfsHc, (obj), TYPE_UFS)
104 #define TYPE_UFS_LU "ufs-lu"
105 #define UFSLU(obj) OBJECT_CHECK(UfsLu, (obj), TYPE_UFS_LU)
107 #define TYPE_UFS_WLU "ufs-wlu"
108 #define UFSWLU(obj) OBJECT_CHECK(UfsWLu, (obj), TYPE_UFS_WLU)
110 typedef enum UfsQueryFlagPerm
{
111 UFS_QUERY_FLAG_NONE
= 0x0,
112 UFS_QUERY_FLAG_READ
= 0x1,
113 UFS_QUERY_FLAG_SET
= 0x2,
114 UFS_QUERY_FLAG_CLEAR
= 0x4,
115 UFS_QUERY_FLAG_TOGGLE
= 0x8,
118 typedef enum UfsQueryAttrPerm
{
119 UFS_QUERY_ATTR_NONE
= 0x0,
120 UFS_QUERY_ATTR_READ
= 0x1,
121 UFS_QUERY_ATTR_WRITE
= 0x2,
124 static inline bool is_wlun(uint8_t lun
)
126 return (lun
== UFS_UPIU_REPORT_LUNS_WLUN
||
127 lun
== UFS_UPIU_UFS_DEVICE_WLUN
|| lun
== UFS_UPIU_BOOT_WLUN
||
128 lun
== UFS_UPIU_RPMB_WLUN
);
131 #endif /* HW_UFS_UFS_H */