1 /*
2 * Copyright (c) 2020-2023 Huawei Device Co., Ltd.
3 *
4 * HDF is dual licensed: you can use it either under the terms of
5 * the GPL, or the BSD license, at your option.
6 * See the LICENSE file in the root of this repository for complete details.
7 */
8
9 #include "mmc_dispatch.h"
10 #include "hdf_log.h"
11 #include "mmc_corex.h"
12 #include "mmc_emmc.h"
13 #include "mmc_sdio.h"
14
MmcCmdDevPresent(struct MmcCntlr * cntlr,struct HdfSBuf * data,struct HdfSBuf * reply)15 static int32_t MmcCmdDevPresent(struct MmcCntlr *cntlr, struct HdfSBuf *data, struct HdfSBuf *reply)
16 {
17 (void)data;
18 if (reply == NULL) {
19 return HDF_ERR_INVALID_PARAM;
20 }
21 if (!HdfSbufWriteUint8(reply, MmcCntlrDevPresent(cntlr))) {
22 HDF_LOGE("MmcCmdDevPresent: write reply sbuf fail!");
23 return HDF_ERR_IO;
24 }
25 return HDF_SUCCESS;
26 }
27
MmcDispatch(struct MmcCntlr * cntlr,int cmd,struct HdfSBuf * data,struct HdfSBuf * reply)28 static int32_t MmcDispatch(struct MmcCntlr *cntlr, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
29 {
30 if (cmd == MMC_CMD_DEV_PRESENT) {
31 return MmcCmdDevPresent(cntlr, data, reply);
32 } else {
33 HDF_LOGE("MmcDispatch: cmd: %d is not support!", cmd);
34 return HDF_ERR_NOT_SUPPORT;
35 }
36 }
37
EmmcCmdGetCid(struct MmcCntlr * cntlr,struct HdfSBuf * reply)38 static int32_t EmmcCmdGetCid(struct MmcCntlr *cntlr, struct HdfSBuf *reply)
39 {
40 int32_t ret;
41 uint8_t cid[EMMC_CID_LEN] = {0};
42
43 if (reply == NULL || cntlr == NULL) {
44 HDF_LOGE("EmmcCmdGetCid: reply or cntlr is null!");
45 return HDF_ERR_INVALID_PARAM;
46 }
47
48 ret = EmmcDeviceGetCid((struct EmmcDevice *)cntlr->curDev, cid, EMMC_CID_LEN);
49 if (ret != HDF_SUCCESS) {
50 HDF_LOGE("EmmcCmdGetCid: get cid fail, ret: %d!", ret);
51 return ret;
52 }
53
54 if (HdfSbufWriteBuffer(reply, cid, EMMC_CID_LEN) == false) {
55 HDF_LOGE("EmmcCmdGetCid: write back cid fail!");
56 return HDF_ERR_IO;
57 }
58
59 return HDF_SUCCESS;
60 }
61
EmmcDispatch(struct MmcCntlr * cntlr,int cmd,struct HdfSBuf * data,struct HdfSBuf * reply)62 static int32_t EmmcDispatch(struct MmcCntlr *cntlr, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
63 {
64 (void)data;
65
66 if (cmd == EMMC_CMD_GET_CID) {
67 return EmmcCmdGetCid(cntlr, reply);
68 } else {
69 HDF_LOGE("EmmcDispatch: cmd: %d is not support!", cmd);
70 return HDF_ERR_NOT_SUPPORT;
71 }
72 }
73
SdioDispatch(struct MmcCntlr * cntlr,int cmd,struct HdfSBuf * data,struct HdfSBuf * reply)74 static int32_t SdioDispatch(struct MmcCntlr *cntlr, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
75 {
76 (void)cntlr;
77 (void)cmd;
78 (void)data;
79 (void)reply;
80 return HDF_ERR_NOT_SUPPORT;
81 }
82
MmcIoDispatch(struct HdfDeviceIoClient * client,int cmd,struct HdfSBuf * data,struct HdfSBuf * reply)83 int32_t MmcIoDispatch(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
84 {
85 int32_t ret;
86 struct MmcCntlr *cntlr = NULL;
87
88 if (client == NULL || client->device == NULL) {
89 HDF_LOGE("MmcIoDispatch: client or hdf dev obj is null!");
90 return HDF_ERR_INVALID_OBJECT;
91 }
92
93 cntlr = (struct MmcCntlr *)client->device->service;
94 if (cntlr == NULL) {
95 HDF_LOGE("MmcIoDispatch: service is null!");
96 return HDF_ERR_INVALID_OBJECT;
97 }
98
99 if (cmd < MMC_CMD_MAX) {
100 ret = MmcDispatch(cntlr, cmd, data, reply);
101 } else if (cmd < EMMC_CMD_MAX) {
102 ret = EmmcDispatch(cntlr, cmd, data, reply);
103 } else if (cmd < SDIO_CMD_MAX) {
104 ret = SdioDispatch(cntlr, cmd, data, reply);
105 } else {
106 ret = HDF_ERR_NOT_SUPPORT;
107 }
108
109 return ret;
110 }
111