diff --git a/include/platform/emmc_if.h b/include/platform/emmc_if.h index 0d5a807e79e9ebb77f0dbb3bcc109a585da15a12..6132d60ab034e7194401acb938fcbef3bb840a36 100644 --- a/include/platform/emmc_if.h +++ b/include/platform/emmc_if.h @@ -29,7 +29,7 @@ #ifndef EMMC_IF_H #define EMMC_IF_H -#include "hdf_platform.h" +#include "mmc_if.h" #ifdef __cplusplus #if __cplusplus @@ -50,13 +50,17 @@ extern "C" { * Before using the EMMC interface, you can obtain the device handle of the EMMC controller * by calling {@link EmmcOpen}. This function is used in pair with {@link EmmcClose}. * - * @param busNum Indicates the bus number. + * @param mmcBusNum Indicates the bus number. * * @return Returns the device handle {@link DevHandle} of the EMMC controller if the operation is successful; * returns NULL otherwise. + * * @since 1.0 */ -DevHandle EmmcOpen(int16_t busNum); +static inline DevHandle EmmcOpen(int16_t mmcBusNum) +{ + return MmcOpen(mmcBusNum); +} /** * @brief Closes an EMMC controller. @@ -64,13 +68,16 @@ DevHandle EmmcOpen(int16_t busNum); * After the EMMC interface is used, you can close the EMMC controller by calling {@link EmmcClose}. * This function is used in pair with {@link EmmcOpen}. * - * @param handle Indicates the pointer to the device handle of the EMMC controller. + * @param handle Indicates the device handle of the EMMC controller. * * @return Returns 0 if the operation is successful; returns a negative value if the operation fails. * * @since 1.0 */ -void EmmcClose(DevHandle handle); +static inline void EmmcClose(DevHandle handle) +{ + MmcClose(handle); +} /** * @brief Get The CID of EMMC device. @@ -86,7 +93,7 @@ void EmmcClose(DevHandle handle); int32_t EmmcGetCid(DevHandle handle, uint8_t *cid, uint32_t size); /** - * @brief Get The HUID(Hardware Unique ID, that is CID) of EMMC device, + * @brief Get The HUID(Hardware Unique ID, that is CID) of EMMC device. * * @param cid Indicates the pointer to the CID to read. * @param size Indicates the length of the CID. diff --git a/include/platform/mmc_if.h b/include/platform/mmc_if.h new file mode 100644 index 0000000000000000000000000000000000000000..8add72a319a154e447121a3fb016af4a6d4acd77 --- /dev/null +++ b/include/platform/mmc_if.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +/** + * @addtogroup MMC + * @{ + * + * @brief Declares standard APIs of basic embedded multi media card (MMC) capabilities. + * + * You can use this module to access the MMC and enable the driver to operate an MMC-compliant device. + * @since 1.0 + */ + + /** + * @file mmc_if.h + * + * @brief Declares the standard MMC APIs. + * + * @since 1.0 + */ + +#ifndef MMC_IF_H +#define MMC_IF_H + +#include "hdf_platform.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +/** + * @brief Enumerates MMC I/O commands. + * + * @since 1.0 + */ +enum MmcIoCmd { + MMC_CMD_DEV_PRESENT, + MMC_CMD_MAX, + EMMC_CMD_GET_CID, + EMMC_CMD_MAX, + SDIO_CMD_MAX, +}; + +/** + * @brief Opens an MMC controller with a specified number. + * + * Before using the MMC interface, you can obtain the device handle of the MMC controller + * by calling {@link MmcOpen}. This function is used in pair with {@link MmcClose}. + * + * @param number Indicates the mmc bus number. + * + * @return Returns the device handle {@link DevHandle} of the MMC controller if the operation is successful; + * returns NULL otherwise. + * + * @since 1.0 + */ +DevHandle MmcOpen(int16_t number); + +/** + * @brief Closes an MMC controller. + * + * After the MMC interface is used, you can close the MMC controller by calling {@link MmcClose}. + * This function is used in pair with {@link MmcOpen}. + * + * @param handle Indicates device handle of the MMC controller. + * + * @return Returns 0 if the operation is successful; returns a negative value if the operation fails. + * + * @since 1.0 + */ +void MmcClose(DevHandle handle); + +/** + * @brief Check if a controller has a device present. + * + * This function is used to check if a controller has a device plugged. + * + * @param handle Indicates the device handle of the MMC controller. + * + * @return Returns true if there is a device present; otherwise false. + * + * @since 1.0 + */ +bool MmcDevPresent(DevHandle handle); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* MMC_IF_H */ diff --git a/include/platform/sdio_if.h b/include/platform/sdio_if.h index 743fe322c8c9393ba85b4ef09c9c749108a7ebaf..030971a39ecda314e461ffd56b64ea9076b1f51d 100644 --- a/include/platform/sdio_if.h +++ b/include/platform/sdio_if.h @@ -30,7 +30,7 @@ #ifndef SDIO_IF_H #define SDIO_IF_H -#include "hdf_platform.h" +#include "mmc_if.h" #ifdef __cplusplus #if __cplusplus @@ -43,6 +43,8 @@ extern "C" { * * When obtaining SDIO common information by calling {@link SdioGetCommonInfo} or setting the information * by calling {@link SdioSetCommonInfo}, you need to pass the information type. + * + * @since 1.0 */ typedef enum { SDIO_FUNC_INFO = 0, /**< Functionality information */ @@ -54,6 +56,8 @@ typedef enum { * * You can obtain and set the SDIO capabilities by calling {@link SdioGetCommonInfo} and {@link SdioSetCommonInfo} * with {@link SdioCommonInfo} and {@link SdioCommonInfoType} passed. + * + * @since 1.0 */ typedef struct { uint32_t maxBlockNum; /**< Maximum number of blocks in a request */ @@ -76,11 +80,27 @@ typedef struct { * * You can obtain and set common SDIO information by calling {@link SdioGetCommonInfo} and {@link SdioSetCommonInfo} * with {@link SdioCommonInfo} and {@link SdioCommonInfoType} passed. + * + * @since 1.0 */ typedef union { SdioFuncInfo funcInfo; /**< Functionality information */ } SdioCommonInfo; +/** + * @brief Defines SDIO function config. + * + * When enabling an SDIO controller, you must specify its SDIO functionality configurations for + * selecting the required functionality. For details, see {@link SdioOpen}. + * + * @since 1.0 + */ +struct SdioFunctionConfig { + uint32_t funcNr; /**< Functionality number, ranging from 1 to 7. */ + uint16_t vendorId; /**< Vendor ID */ + uint16_t deviceId; /**< Device ID */ +}; + /** * @brief Defines the function type of an SDIO IRQ. * @@ -98,13 +118,15 @@ typedef void SdioIrqHandler(void *); * Before using the SDIO interface, you can obtain the device handle of the SDIO controller * by calling {@link SdioOpen}. This function is used in pair with {@link SdioClose}. * - * @param busNum Indicates the bus number. + * @param mmcBusNum Indicates the bus number. + * @param config Indicates the pointer to SDIO functionality configurations. * * @return Returns the device handle {@link DevHandle} of the SDIO controller if the operation is successful; * returns NULL otherwise. + * * @since 1.0 */ -DevHandle SdioOpen(int16_t busNum); +DevHandle SdioOpen(int16_t mmcBusNum, struct SdioFunctionConfig *config); /** * @brief Closes an SDIO controller. @@ -128,15 +150,12 @@ void SdioClose(DevHandle handle); * @param data Indicates the pointer to the data to read. * @param addr Indicates the start address of the data to read. * @param size Indicates the length of the data to read. - * @param timeOut Indicates the timeout duration for reading data, in milliseconds. - * If the value is 0,the default value is used. The default value varies according to the application. - * Generally, the default value is 1 second. * * @return Returns 0 if the operation is successful; returns a negative value if the operation fails. + * * @since 1.0 */ -int32_t SdioReadBytes(DevHandle handle, uint8_t *data, uint32_t addr, - uint32_t size, uint32_t timeOut); +int32_t SdioReadBytes(DevHandle handle, uint8_t *data, uint32_t addr, uint32_t size); /** * @brief Incrementally writes a given length of data into the specified SDIO address. @@ -148,15 +167,12 @@ int32_t SdioReadBytes(DevHandle handle, uint8_t *data, uint32_t addr, * @param data Indicates the pointer to the data to write. * @param addr Indicates the start address of the data to write. * @param size Indicates the length of the data to write. - * @param timeOut Indicates the timeout duration for writing data, in milliseconds. - * If the value is 0, the default value is used. The default value varies according to the application. - * Generally, the default value is 1 second. * * @return Returns 0 if the operation is successful; returns a negative value if the operation fails. + * * @since 1.0 */ -int32_t SdioWriteBytes(DevHandle handle, uint8_t *data, uint32_t addr, - uint32_t size, uint32_t timeOut); +int32_t SdioWriteBytes(DevHandle handle, uint8_t *data, uint32_t addr, uint32_t size); /** * @brief Reads a given length of data from the fixed SDIO address. @@ -168,15 +184,15 @@ int32_t SdioWriteBytes(DevHandle handle, uint8_t *data, uint32_t addr, * @param data Indicates the pointer to the data to read. * @param addr Indicates the fixed address of the data to read. * @param size Indicates the length of the data to read. - * @param timeOut Indicates the timeout duration for reading data, in milliseconds. - * If the value is 0, the default value is used. The default value varies according to the application. - * Generally, the default value is 1 second. + * @param scatterLen Indicates the length of the scatter list. If this value is not 0, the data is of the + * scatter list type. * * @return Returns 0 if the operation is successful; returns a negative value if the operation fails. + * * @since 1.0 */ int32_t SdioReadBytesFromFixedAddr(DevHandle handle, uint8_t *data, - uint32_t addr, uint32_t size, uint32_t timeOut); + uint32_t addr, uint32_t size, uint32_t scatterLen); /** * @brief Writes a given length of data into the fixed SDIO address. @@ -188,15 +204,15 @@ int32_t SdioReadBytesFromFixedAddr(DevHandle handle, uint8_t *data, * @param data Indicates the pointer to the data to write. * @param addr Indicates the fixed address of the data to write. * @param size Indicates the length of the data to write. - * @param timeOut Indicates the timeout duration for writing data, in milliseconds. - * If the value is 0, the default value is used. The default value varies according to the application. - * Generally, the default value is 1 second. + * @param scatterLen Indicates the length of the scatter list. If this value is not 0, the data is of the + * scatter list type. * * @return Returns 0 if the operation is successful; returns a negative value if the operation fails. + * * @since 1.0 */ int32_t SdioWriteBytesToFixedAddr(DevHandle handle, uint8_t *data, - uint32_t addr, uint32_t size, uint32_t timeOut); + uint32_t addr, uint32_t size, uint32_t scatterLen); /** * @brief Reads a given length of data from the address space of SDIO function 0. @@ -207,15 +223,12 @@ int32_t SdioWriteBytesToFixedAddr(DevHandle handle, uint8_t *data, * @param data Indicates the pointer to the data to read. * @param addr Indicates the start address of the data to read. * @param size Indicates the length of the data to read. - * @param timeOut Indicates the timeout duration for reading data, in milliseconds. - * If the value is 0, the default value is used. The default value varies according to the application. - * Generally, the default value is 1 second. * * @return Returns 0 if the operation is successful; returns a negative value if the operation fails. + * * @since 1.0 */ -int32_t SdioReadBytesFromFunc0(DevHandle handle, uint8_t *data, - uint32_t addr, uint32_t size, uint32_t timeOut); +int32_t SdioReadBytesFromFunc0(DevHandle handle, uint8_t *data, uint32_t addr, uint32_t size); /** * @brief Writes a given length of data into the address space of SDIO function 0. @@ -226,15 +239,12 @@ int32_t SdioReadBytesFromFunc0(DevHandle handle, uint8_t *data, * @param data Indicates the pointer to the data to write. * @param addr Indicates the start address of the data to write. * @param size Indicates the length of the data to write. - * @param timeOut Indicates the timeout duration for writing data, in milliseconds. - * If the value is 0, the default value is used. The default value varies according to the application. - * Generally, the default value is 1 second. * * @return Returns 0 if the operation is successful; returns a negative value if the operation fails. + * * @since 1.0 */ -int32_t SdioWriteBytesToFunc0(DevHandle handle, uint8_t *data, - uint32_t addr, uint32_t size, uint32_t timeOut); +int32_t SdioWriteBytesToFunc0(DevHandle handle, uint8_t *data, uint32_t addr, uint32_t size); /** * @brief Sets the block size. @@ -246,6 +256,7 @@ int32_t SdioWriteBytesToFunc0(DevHandle handle, uint8_t *data, * The value ranges from 1 to 2048 bytes. * * @return Returns 0 if the operation is successful; returns a negative value if the operation fails. + * * @since 1.0 */ int32_t SdioSetBlockSize(DevHandle handle, uint32_t blockSize); @@ -262,6 +273,7 @@ int32_t SdioSetBlockSize(DevHandle handle, uint32_t blockSize); * For details, see {@link SdioCommonInfoType}. * * @return Returns 0 if the operation is successful; returns a negative value if the operation fails. + * * @since 1.0 */ int32_t SdioGetCommonInfo(DevHandle handle, SdioCommonInfo *info, SdioCommonInfoType infoType); @@ -278,6 +290,7 @@ int32_t SdioGetCommonInfo(DevHandle handle, SdioCommonInfo *info, SdioCommonInfo * For details, see {@link SdioCommonInfoType}. * * @return Returns 0 if the operation is successful; returns a negative value if the operation fails. + * * @since 1.0 */ int32_t SdioSetCommonInfo(DevHandle handle, SdioCommonInfo *info, SdioCommonInfoType infoType); @@ -290,6 +303,7 @@ int32_t SdioSetCommonInfo(DevHandle handle, SdioCommonInfo *info, SdioCommonInfo * @param handle Indicates the pointer to the device handle of the SDIO controller obtained by {@link SdioOpen}. * * @return Returns 0 if the operation is successful; returns a negative value if the operation fails. + * * @since 1.0 */ int32_t SdioFlushData(DevHandle handle); @@ -324,6 +338,7 @@ void SdioReleaseHost(DevHandle handle); * @param handle Indicates the pointer to the device handle of the SDIO controller obtained by {@link SdioOpen}. * * @return Returns 0 if the operation is successful; returns a negative value if the operation fails. + * * @since 1.0 */ int32_t SdioEnableFunc(DevHandle handle); @@ -336,6 +351,7 @@ int32_t SdioEnableFunc(DevHandle handle); * @param handle Indicates the pointer to the device handle of the SDIO controller obtained by {@link SdioOpen}. * * @return Returns 0 if the operation is successful; returns a negative value if the operation fails. + * * @since 1.0 */ int32_t SdioDisableFunc(DevHandle handle); @@ -349,6 +365,7 @@ int32_t SdioDisableFunc(DevHandle handle); * @param irqHandler Indicates the pointer to the SDIO IRQ function. For details, see {@link SdioIrqHandler}. * * @return Returns 0 if the operation is successful; returns a negative value if the operation fails. + * * @since 1.0 */ int32_t SdioClaimIrq(DevHandle handle, SdioIrqHandler *irqHandler); @@ -361,6 +378,7 @@ int32_t SdioClaimIrq(DevHandle handle, SdioIrqHandler *irqHandler); * @param handle Indicates the pointer to the device handle of the SDIO controller obtained by {@link SdioOpen}. * * @return Returns 0 if the operation is successful; returns a negative value if the operation fails. + * * @since 1.0 */ int32_t SdioReleaseIrq(DevHandle handle); diff --git a/include/wifi/hdf_ibus_intf.h b/include/wifi/hdf_ibus_intf.h new file mode 100644 index 0000000000000000000000000000000000000000..11a7d455aa990383ce7b00d69d9912b31ec3eb7e --- /dev/null +++ b/include/wifi/hdf_ibus_intf.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2021-2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef HDF_IBUS_INTF_H +#define HDF_IBUS_INTF_H + +#include "hdf_wlan_config.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +struct BusDev; +typedef void IrqHandler(void *); + +struct SdioConfigInfo { + uint32_t maxBlockNum; + uint32_t maxBlockSize; + uint32_t maxRequestSize; + uint32_t funcNumSize; + uint32_t irqCap; + void *data; +}; + +union BusInfo { + struct SdioConfigInfo sdioInfo; +}; + +struct BusConfig { + uint8_t busType; + union BusInfo busInfo; +}; + +struct PrivateData { + void *data; + const char *driverName; + int32_t (*release)(void *data); +}; + +struct DevOps { + int32_t (*getBusInfo)(struct BusDev *dev, struct BusConfig *busCfg); + void (*deInit)(struct BusDev *dev); + int32_t (*init)(struct BusDev *dev, const struct HdfConfigWlanBus *busCfg); + + int32_t (*readData)(struct BusDev *dev, uint32_t addr, uint32_t cnt, uint8_t *buf); + int32_t (*writeData)(struct BusDev *dev, uint32_t addr, uint32_t cnt, uint8_t *buf); + + int32_t (*bulkRead)(struct BusDev *dev, uint32_t addr, uint32_t cnt, uint8_t *buf, uint32_t sg_len); + int32_t (*bulkWrite)(struct BusDev *dev, uint32_t addr, uint32_t cnt, uint8_t *buf, uint32_t sg_len); + + int32_t (*readFunc0)(struct BusDev *dev, uint32_t addr, uint32_t cnt, uint8_t *buf); + int32_t (*writeFunc0)(struct BusDev *dev, uint32_t addr, uint32_t cnt, uint8_t *buf); + + int32_t (*disableBus)(struct BusDev *dev); + int32_t (*claimIrq)(struct BusDev *dev, IrqHandler *handler, void *data); + int32_t (*releaseIrq)(struct BusDev *dev); + int32_t (*reset)(struct BusDev *dev); + + void (*claimHost)(struct BusDev *dev); + void (*releaseHost)(struct BusDev *dev); +}; + +struct BusDev { + void *devBase; + struct DevOps ops; + struct PrivateData priData; +}; + +struct BusDev *HdfWlanCreateBusManager(const struct HdfConfigWlanBus *busConfig); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif + +#endif diff --git a/include/wifi/hdf_wifi_product.h b/include/wifi/hdf_wifi_product.h index 40bf8842078c92b6ebeb64e13e0687d028cb43e3..ddce78376c25da0b64bbab5d33cbf1392db3967a 100644 --- a/include/wifi/hdf_wifi_product.h +++ b/include/wifi/hdf_wifi_product.h @@ -36,6 +36,7 @@ #include "hdf_wlan_config.h" #include "hdf_wlan_power_manager.h" #include "hdf_wlan_reset_manager.h" +#include "hdf_ibus_intf.h" #ifdef __cplusplus extern "C" { @@ -74,6 +75,7 @@ struct HdfWlanDevice { struct HdfWlanManufacturer manufacturer; /**< WLAN device manufacturer */ struct ResetManager *reset; /**< Chip reset management API */ struct PowerManager *powers; /**< Chip power management APIs */ + struct BusDev *bus; }; /** diff --git a/model/network/wifi/bus/hdf_ibus_intf.c b/model/network/wifi/bus/hdf_ibus_intf.c new file mode 100644 index 0000000000000000000000000000000000000000..4139843752a5867966038f35e7cf7e50871b2987 --- /dev/null +++ b/model/network/wifi/bus/hdf_ibus_intf.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021-2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include "hdf_sdio_intf.h" +#include "osal_mem.h" +#include "securec.h" +#include "wifi_inc.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +struct BusDev *HdfWlanCreateBusManager(const struct HdfConfigWlanBus *busConfig) +{ + if (busConfig == NULL) { + return NULL; + } + struct BusDev *bus = (struct BusDev *)OsalMemCalloc(sizeof(struct BusDev)); + if (bus == NULL) { + return NULL; + } + + switch (busConfig->busType) { + case BUS_SDIO: + if (HdfSdioBusInit(bus, busConfig) != HDF_SUCCESS) { + OsalMemFree(bus); + return NULL; + } + break; + default: + HDF_LOGE("%s:bus type not support!", __func__); + OsalMemFree(bus); + return NULL; + } + return bus; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif diff --git a/model/network/wifi/bus/hdf_sdio_intf.c b/model/network/wifi/bus/hdf_sdio_intf.c new file mode 100644 index 0000000000000000000000000000000000000000..ad2b6a8da2b2dadb8044c2d8452df67d31ac0912 --- /dev/null +++ b/model/network/wifi/bus/hdf_sdio_intf.c @@ -0,0 +1,385 @@ +/* + * Copyright (c) 2021-2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include "hdf_sdio_intf.h" +#include "osal_mem.h" +#include "sdio_if.h" +#include "wifi_inc.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +static int32_t HdfGetSdioInfo(struct BusDev *dev, struct BusConfig *busCfg) +{ + int32_t ret; + struct DevHandle *handle = NULL; + SdioCommonInfo palSdioCommonInfo; + if (dev == NULL || busCfg == NULL || busCfg->busType != BUS_SDIO) { + HDF_LOGE("%s:input parameter error!", __func__); + return HDF_FAILURE; + } + handle = (struct DevHandle *)dev->devBase; + (void)memset_s(&palSdioCommonInfo, sizeof(SdioCommonInfo), 0, sizeof(SdioCommonInfo)); + + ret = SdioGetCommonInfo(handle, &palSdioCommonInfo, SDIO_FUNC_INFO); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s:get sdio info error!", __func__); + return ret; + } + busCfg->busInfo.sdioInfo.maxBlockNum = palSdioCommonInfo.funcInfo.maxBlockNum; + busCfg->busInfo.sdioInfo.maxBlockSize = palSdioCommonInfo.funcInfo.maxBlockSize; + busCfg->busInfo.sdioInfo.maxRequestSize = palSdioCommonInfo.funcInfo.maxRequestSize; + busCfg->busInfo.sdioInfo.funcNumSize = palSdioCommonInfo.funcInfo.funcNum; + busCfg->busInfo.sdioInfo.irqCap = palSdioCommonInfo.funcInfo.irqCap; + busCfg->busInfo.sdioInfo.data = palSdioCommonInfo.funcInfo.data; + + return ret; +} + +static void HdfSdioReleaseDev(struct BusDev *dev) +{ + if (dev == NULL) { + HDF_LOGE("%s:input parameter error!", __func__); + return; + } + if (dev->priData.data != NULL) { + dev->priData.release(dev->priData.data); + dev->priData.data = NULL; + } + OsalMemFree(dev); + dev = NULL; +} + +static int32_t HdfSdioEnableFunc(struct BusDev *dev) +{ + int32_t ret; + struct DevHandle *handle = NULL; + if (dev == NULL) { + HDF_LOGE("%s:input parameter error!", __func__); + return HDF_FAILURE; + } + handle = (struct DevHandle *)dev->devBase; + ret = SdioEnableFunc(handle); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s:enable sdio func failed!", __func__); + } + return ret; +} + +static int32_t HdfSdioDisableFunc(struct BusDev *dev) +{ + int32_t ret; + struct DevHandle *handle = NULL; + if (dev == NULL) { + HDF_LOGE("%s:input parameter error!", __func__); + return HDF_FAILURE; + } + handle = (struct DevHandle *)dev->devBase; + ret = SdioDisableFunc(handle); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s:disable sdio func failed!", __func__); + } + return ret; +} + +static int32_t HdfSdioCliamIrq(struct BusDev *dev, IrqHandler *handler, void *data) +{ + (void)data; + int32_t ret; + struct DevHandle *handle = NULL; + if (dev == NULL) { + HDF_LOGE("%s:input parameter error!", __func__); + return HDF_FAILURE; + } + handle = (struct DevHandle *)dev->devBase; + ret = SdioClaimIrq(handle, (SdioIrqHandler *)handler); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s:claim sdio irq failed!", __func__); + } + return ret; +} + +static void HdfSdioClaimHost(struct BusDev *dev) +{ + struct DevHandle *handle = NULL; + if (dev == NULL) { + HDF_LOGE("%s:input parameter error!", __func__); + return; + } + handle = (struct DevHandle *)dev->devBase; + SdioClaimHost(handle); +} + +static void HdfSdioReleaseHost(struct BusDev *dev) +{ + struct DevHandle *handle = NULL; + if (dev == NULL) { + HDF_LOGE("%s:input parameter error!", __func__); + return; + } + handle = (struct DevHandle *)dev->devBase; + SdioReleaseHost(handle); +} + + +static int32_t HdfSdioReleaseIrq(struct BusDev *dev) +{ + int32_t ret; + struct DevHandle *handle = NULL; + if (dev == NULL) { + HDF_LOGE("%s:input parameter error!", __func__); + return HDF_FAILURE; + } + handle = (struct DevHandle *)dev->devBase; + ret = SdioReleaseIrq(handle); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s:release sdio irq failed!", __func__); + } + return ret; +} + +static int32_t HdfSdioReset(struct BusDev *dev) +{ + int32_t ret; + struct DevHandle *handle = NULL; + if (dev == NULL) { + HDF_LOGE("%s:input parameter error!", __func__); + return HDF_FAILURE; + } + handle = (struct DevHandle *)dev->devBase; + ret = SdioFlushData(handle); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s:reset sdio failed!", __func__); + } + return ret; +} + +static int32_t HdfSdioReadN(struct BusDev *dev, uint32_t addr, uint32_t cnt, uint8_t *buf) +{ + int32_t ret; + struct DevHandle *handle = NULL; + if (dev == NULL) { + HDF_LOGE("%s:input parameter error!", __func__); + return HDF_FAILURE; + } + handle = (struct DevHandle *)dev->devBase; + ret = SdioReadBytes(handle, buf, addr, cnt); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s:read sdio data failed!", __func__); + } + return ret; +} + +static int32_t HdfSdioReadFunc0(struct BusDev *dev, uint32_t addr, uint32_t cnt, uint8_t *buf) +{ + int32_t ret; + struct DevHandle *handle = NULL; + if (dev == NULL) { + HDF_LOGE("%s:input parameter error!", __func__); + return HDF_FAILURE; + } + handle = (struct DevHandle *)dev->devBase; + ret = SdioReadBytesFromFunc0(handle, buf, addr, cnt); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s:read sdio func0 data failed!", __func__); + } + return ret; +} + +static int32_t HdfSdioReadSpcReg(struct BusDev *dev, uint32_t addr, uint32_t cnt, uint8_t *buf, uint32_t sg_len) +{ + int32_t ret; + struct DevHandle *handle = NULL; + if (dev == NULL) { + HDF_LOGE("%s:input parameter error!", __func__); + return HDF_FAILURE; + } + handle = (struct DevHandle *)dev->devBase; + ret = SdioReadBytesFromFixedAddr(handle, buf, addr, cnt, sg_len); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s:read sdio special reg data failed!", __func__); + } + return ret; +} + +static int32_t HdfSdioWriteN(struct BusDev *dev, uint32_t addr, uint32_t cnt, uint8_t *buf) +{ + int32_t ret; + struct DevHandle *handle = NULL; + if (dev == NULL || buf == NULL) { + HDF_LOGE("%s:input parameter error!", __func__); + return HDF_FAILURE; + } + handle = (struct DevHandle *)dev->devBase; + ret = SdioWriteBytes(handle, buf, addr, cnt); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s:write sdio data failed!", __func__); + } + return ret; +} + +static int32_t HdfSdioWriteFunc0(struct BusDev *dev, uint32_t addr, uint32_t cnt, uint8_t *buf) +{ + int32_t ret; + struct DevHandle *handle = NULL; + if (dev == NULL || buf == NULL) { + HDF_LOGE("%s:input parameter error!", __func__); + return HDF_FAILURE; + } + handle = (struct DevHandle *)dev->devBase; + ret = SdioWriteBytesToFunc0(handle, buf, addr, cnt); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s:write sdio func0 data failed!", __func__); + } + return ret; +} + +static int32_t HdfSdioWriteSpcReg(struct BusDev *dev, uint32_t addr, uint32_t cnt, uint8_t *buf, uint32_t sg_len) +{ + int32_t ret; + struct DevHandle *handle = NULL; + if (dev == NULL || buf == NULL) { + HDF_LOGE("%s:input parameter error!", __func__); + return HDF_FAILURE; + } + handle = (struct DevHandle *)dev->devBase; + ret = SdioWriteBytesToFixedAddr(handle, buf, addr, cnt, sg_len); + if (ret != HDF_SUCCESS) { + HDF_LOGI("%s:write sdio special reg data failed!", __func__); + } + return ret; +} + +static int32_t HdfSdioSetBlk(struct BusDev *dev, uint32_t blkSize) +{ + int32_t ret; + struct DevHandle *handle = NULL; + if (dev == NULL) { + HDF_LOGE("%s:input parameter error!", __func__); + return HDF_FAILURE; + } + handle = (struct DevHandle *)dev->devBase; + ret = SdioSetBlockSize(handle, blkSize); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s:sdio set block size failed!", __func__); + } + return ret; +} + +static struct DevHandle *HdfGetDevHandle(struct BusDev *dev, const struct HdfConfigWlanBus *busCfg) +{ + struct DevHandle *handle = NULL; + int32_t cnt; + struct SdioFunctionConfig palSdioConfig[WLAN_MAX_CHIP_NUM] = {0}; + struct HdfConfigWlanChipList *tmpChipList = NULL; + + struct HdfConfigWlanRoot *rootConfig = HdfWlanGetModuleConfigRoot(); + if (rootConfig == NULL) { + HDF_LOGE("%s: NULL ptr!", __func__); + return NULL; + } + tmpChipList = &rootConfig->wlanConfig.chipList; + for (cnt = 0; (cnt < tmpChipList->chipInstSize) && (cnt < WLAN_MAX_CHIP_NUM); cnt++) { + // once detected card break + palSdioConfig[cnt].deviceId = tmpChipList->chipInst[cnt].chipSdio.deviceId[0]; + palSdioConfig[cnt].vendorId = tmpChipList->chipInst[cnt].chipSdio.vendorId; + palSdioConfig[cnt].funcNr = busCfg->funcNum[0]; + handle = SdioOpen(busCfg->busIdx, &palSdioConfig[cnt]); + if (handle != NULL) { + HDF_LOGI("%s: sdio card detected!", __func__); + break; + } + } + if (cnt == tmpChipList->chipInstSize || cnt == WLAN_MAX_CHIP_NUM) { + HDF_LOGE("%s: NO sdio card detected!", __func__); + SdioClose(handle); + return NULL; + } + dev->devBase = handle; + dev->priData.driverName = tmpChipList->chipInst[cnt].driverName; + return handle; +} + +static int32_t HdfSdioInit(struct BusDev *dev, const struct HdfConfigWlanBus *busCfg) +{ + int32_t ret; + struct DevHandle *handle = NULL; + SdioCommonInfo palSdioCommonInfo; + + if (dev == NULL || busCfg == NULL) { + HDF_LOGE("%s: input parameter error!", __func__); + goto sdioInitFail; + } + handle = HdfGetDevHandle(dev, busCfg); + if (handle == NULL) { + HDF_LOGE("%s: sdio card detected fail!", __func__); + return HDF_FAILURE; + } + SdioClaimHost(handle); + (void)memset_s(&palSdioCommonInfo, sizeof(SdioCommonInfo), 0, sizeof(SdioCommonInfo)); + SdioGetCommonInfo(handle, &palSdioCommonInfo, SDIO_FUNC_INFO); + palSdioCommonInfo.funcInfo.enTimeout = busCfg->timeout; + SdioSetCommonInfo(handle, &palSdioCommonInfo, SDIO_FUNC_INFO); + ret = HdfSdioEnableFunc(dev); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: enable sdio failed!", __func__); + goto sdioInitFail; + } + ret = HdfSdioSetBlk(dev, busCfg->blockSize); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: set sdio block size failed!", __func__); + goto sdioInitFail; + } + SdioReleaseHost(handle); + HDF_LOGI("%s: sdio bus init success!", __func__); + return ret; + +sdioInitFail: + SdioClose(handle); + return HDF_FAILURE; +} + +static void HdfSetBusOps(struct BusDev *dev) +{ + dev->ops.getBusInfo = HdfGetSdioInfo; + dev->ops.deInit = HdfSdioReleaseDev; + dev->ops.init = HdfSdioInit; + + dev->ops.readData = HdfSdioReadN; + dev->ops.writeData = HdfSdioWriteN; + dev->ops.bulkRead = HdfSdioReadSpcReg; + dev->ops.bulkWrite = HdfSdioWriteSpcReg; + dev->ops.readFunc0 = HdfSdioReadFunc0; + dev->ops.writeFunc0 = HdfSdioWriteFunc0; + + dev->ops.claimIrq = HdfSdioCliamIrq; + dev->ops.releaseIrq = HdfSdioReleaseIrq; + dev->ops.disableBus = HdfSdioDisableFunc; + dev->ops.reset = HdfSdioReset; + + dev->ops.claimHost = HdfSdioClaimHost; + dev->ops.releaseHost = HdfSdioReleaseHost; +} +int32_t HdfSdioBusInit(struct BusDev *dev, const struct HdfConfigWlanBus *busConfig) +{ + if (dev == NULL) { + HDF_LOGE("%s:set sdio device ops failed!", __func__); + return HDF_FAILURE; + } + HdfSetBusOps(dev); + return HdfSdioInit(dev, busConfig); +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif diff --git a/model/network/wifi/bus/hdf_sdio_intf.h b/model/network/wifi/bus/hdf_sdio_intf.h new file mode 100644 index 0000000000000000000000000000000000000000..bcc42f7a49345f6c3ffff2932bdbe3f1ab633cb6 --- /dev/null +++ b/model/network/wifi/bus/hdf_sdio_intf.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2021-2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef HDF_SDIO_INTF_H +#define HDF_SDIO_INTF_H + +#include "hdf_base.h" +#include "hdf_ibus_intf.h" +#include "hdf_log.h" +#include "securec.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +int32_t HdfSdioBusInit(struct BusDev *dev, const struct HdfConfigWlanBus *busConfig); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif + +#endif + diff --git a/model/network/wifi/core/hdf_wifi_core.c b/model/network/wifi/core/hdf_wifi_core.c index 75c26ae9265033aa670780cd65a3bbe5bce2c547..bbb107ea6cc2a9e667b4f1ad91a9604c2a586b35 100644 --- a/model/network/wifi/core/hdf_wifi_core.c +++ b/model/network/wifi/core/hdf_wifi_core.c @@ -19,7 +19,6 @@ #include "message/message_router.h" #include "hdf_wlan_chipdriver_manager.h" #include "hdf_wlan_sdio.h" -#include "hdf_wlan_sdio.h" #include "hdf_wlan_config.h" #include "hdf_wlan_utils.h" @@ -39,18 +38,21 @@ int32_t HdfWifiGetBusIdx(void) * @brief as for now, we just support one wlan module in one board cause driver binds to wlan featere * due to that reason, once we detected one chip, we stop rescan. */ -int32_t HdfWlanSdioScan(struct HdfWlanDevice *data, struct HdfConfigWlanBus *busConfig) +int HdfWlanBusInit(struct HdfWlanDevice *data, const struct HdfConfigWlanBus *busConfig) { - /* get config vendId, deviceId and chip-name which used in detect match process */ - HdfWlanGetSdioTableByConfig(); - - HdfWlanSdioScanTriggerByBusIndex(busConfig->busIdx); - int32_t ret = HdfWlanGetDetectedChip(data, busConfig); - HdfWlanSdioDriverUnReg(); - if (ret != HDF_SUCCESS) { - return ret; + struct BusDev *bus = NULL; + bus = HdfWlanCreateBusManager(busConfig); + if (bus == NULL) { + HDF_LOGE("%s:Create bus manager failed!", __func__); + return HDF_FAILURE; } - HDF_LOGI("driver name = %s", __func__, data->driverName); + data->bus = bus; + if (bus->priData.driverName == NULL) { + HDF_LOGE("%s:get driver name failed!", __func__); + return HDF_FAILURE; + } + data->driverName = bus->priData.driverName; + HDF_LOGI("%s: driver name = %s", __func__, data->driverName); return HDF_SUCCESS; } @@ -324,6 +326,10 @@ inline static void ReleaseWlanDevice(struct HdfWlanDevice *device) device->reset->Release(device->reset); device->reset = NULL; } + if (device->bus != NULL && device->bus->ops.deInit != NULL) { + device->bus->ops.deInit(device->bus); + device->bus = NULL; + } OsalMemFree(device); } @@ -355,7 +361,7 @@ static struct HdfWlanDevice *ProbeDevice(struct HdfConfigWlanDevInst *deviceConf break; } - ret = HdfWlanSdioScan(device, &deviceConfig->bus); + ret = HdfWlanBusInit(device, &deviceConfig->bus); if (ret != HDF_SUCCESS) { HDF_LOGE("%s:NO Sdio Card in hdf wlan init proc", __func__); break; @@ -546,3 +552,4 @@ struct HdfDriverEntry g_hdfWifiEntry = { }; HDF_INIT(g_hdfWifiEntry); + diff --git a/model/network/wifi/core/hdf_wlan_sdio.h b/model/network/wifi/core/hdf_wlan_sdio.h index 553c17fcafff220ecd45e40346e56844dc3748ed..d1436356c72052548b90ec53d545fb63c52f189b 100644 --- a/model/network/wifi/core/hdf_wlan_sdio.h +++ b/model/network/wifi/core/hdf_wlan_sdio.h @@ -19,11 +19,6 @@ extern "C" { #endif #endif -void HdfWlanGetSdioTableByConfig(void); -void HdfWlanSdioScanTriggerByBusIndex(int32_t busIdex); -void HdfWlanSdioDriverUnReg(void); -int HdfWlanGetDetectedChip(struct HdfWlanDevice *device, const struct HdfConfigWlanBus *busConfig); - int32_t HdfWlanConfigSDIO(uint8_t busId); #ifdef __cplusplus @@ -34,3 +29,4 @@ int32_t HdfWlanConfigSDIO(uint8_t busId); #endif + diff --git a/model/storage/include/common/storage.h b/model/storage/include/common/storage.h new file mode 100644 index 0000000000000000000000000000000000000000..d85a4a25955227ad1df346fd14d287ca95a979fd --- /dev/null +++ b/model/storage/include/common/storage.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef STORAGE_H +#define STORAGE_H + +#include "hdf_base.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +#define STORAGE_MAX_BYTES ((size_t)(-1)) + +enum StorageType { + MEDIA_MMC = 0, + MEDIA_MTD = 1, + MEDIA_ERR = 2, +}; + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* STORAGE_H */ diff --git a/model/storage/include/common/storage_block.h b/model/storage/include/common/storage_block.h new file mode 100644 index 0000000000000000000000000000000000000000..726c84d13ad98b64b93fc635b8d3c187b3f57f5e --- /dev/null +++ b/model/storage/include/common/storage_block.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef STORAGE_BLOCK_H +#define STORAGE_BLOCK_H + +#include "storage.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +#define STORAGE_SEC_SIZE 512 +#define STORAGE_SEC_SHIFT 9 +#define STORAGE_MAX_SEC_NR (STORAGE_MAX_BYTES >> STORAGE_SEC_SHIFT) + +#define STORAGE_SEC_PARAM_INVALID(s, n) \ + (s >= STORAGE_MAX_SEC_NR || \ + n >= STORAGE_MAX_SEC_NR || \ + (STORAGE_MAX_SEC_NR - n) <= s) + +#define BLOCK_NAME_LEN 32 + +struct StorageBlock { + char name[BLOCK_NAME_LEN]; /* name of the block device */ + int32_t index; + enum StorageType type; /* indicate which type of media is used */ + bool removeable; + void *media; /* media device of the block */ + size_t capacity; /* sized by sector */ + size_t secSize; /* sized by bytes */ + uint32_t errCnt; /* err count on io transfer */ + struct StorageBlockMethod *ops; /* storage oparations provided by specific media */ + void *bops; /* block operations of specific os */ +}; + +struct StorageBlockMethod { + ssize_t (*read)(struct StorageBlock *sb, uint8_t *buf, size_t secStart, size_t secNr); + ssize_t (*write)(struct StorageBlock *sb, const uint8_t *buf, size_t secStart, size_t secNr); + ssize_t (*erase)(struct StorageBlock *sb, size_t secStart, size_t secNr); + size_t (*getCapacity)(struct StorageBlock *sb); + bool (*isPresent)(struct StorageBlock *sb); + uint32_t (*getAuSize)(struct StorageBlock *sb); +}; + +ssize_t StorageBlockRead(struct StorageBlock *sb, uint8_t *buf, size_t secStart, size_t secNr); +ssize_t StorageBlockWrite(struct StorageBlock *sb, const uint8_t *buf, size_t secStart, size_t secNr); +ssize_t StorageBlockErase(struct StorageBlock *sb, size_t secStart, size_t secNr); +size_t StorageBlockGetCapacity(struct StorageBlock *sb); +bool StorageBlockIsPresent(struct StorageBlock *sb); +int32_t StorageBlockGetAuSize(struct StorageBlock *sb, uint32_t *auSize); + +int32_t StorageBlockAdd(struct StorageBlock *sb); +void StorageBlockDel(struct StorageBlock *sb); + +/* these two functions gona implemented by specific os */ +int32_t StorageBlockOsInit(struct StorageBlock *sb); +void StorageBlockOsUninit(struct StorageBlock *sb); + +ssize_t StorageBlockMmcErase(uint32_t blockId, size_t secStart, size_t secNr); +struct StorageBlock *StorageBlockFromNumber(uint32_t number); + + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* STORAGE_BLOCK_H */ diff --git a/model/storage/src/common/storage_block.c b/model/storage/src/common/storage_block.c new file mode 100644 index 0000000000000000000000000000000000000000..51a4b7065f2ef47cbaa03d366e0fea1b19fd1097 --- /dev/null +++ b/model/storage/src/common/storage_block.c @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ +#include "hdf_base.h" +#include "hdf_log.h" +#include "platform_common.h" +#include "storage_block.h" + +#define HDF_LOG_TAG storage_block_c + +#define MAX_BLOCK_COUNT 3 + +static struct StorageBlock *g_blocks[MAX_BLOCK_COUNT]; + +ssize_t StorageBlockErase(struct StorageBlock *sb, size_t secStart, size_t secNr) +{ + if (sb == NULL) { + return HDF_ERR_INVALID_OBJECT; + } + if (sb->ops == NULL || sb->ops->erase == NULL) { + return HDF_ERR_NOT_SUPPORT; + } + return sb->ops->erase(sb, secStart, secNr); +} + +ssize_t StorageBlockWrite(struct StorageBlock *sb, const uint8_t *buf, size_t secStart, size_t secNr) +{ + if (sb == NULL) { + return HDF_ERR_INVALID_OBJECT; + } + if (sb->ops == NULL || sb->ops->write == NULL) { + return HDF_ERR_NOT_SUPPORT; + } + return sb->ops->write(sb, buf, secStart, secNr); +} + +ssize_t StorageBlockRead(struct StorageBlock *sb, uint8_t *buf, size_t secStart, size_t secNr) +{ + if (sb == NULL) { + return HDF_ERR_INVALID_OBJECT; + } + if (sb->ops == NULL || sb->ops->read == NULL) { + return HDF_ERR_NOT_SUPPORT; + } + return sb->ops->read(sb, buf, secStart, secNr); +} + +int32_t StorageBlockGetAuSize(struct StorageBlock *sb, uint32_t *auSize) +{ + if (sb == NULL) { + return HDF_ERR_INVALID_OBJECT; + } + if (sb->ops == NULL || sb->ops->getAuSize == NULL) { + return HDF_ERR_NOT_SUPPORT; + } + *auSize = sb->ops->getAuSize(sb); + return HDF_SUCCESS; +} + +size_t StorageBlockGetCapacity(struct StorageBlock *sb) +{ + return (sb == NULL) ? 0 : sb->capacity; +} + +bool StorageBlockIsPresent(struct StorageBlock *sb) +{ + return (sb != NULL && sb->ops != NULL && + sb->ops->isPresent != NULL && sb->ops->isPresent(sb)); +} + +int32_t StorageBlockAdd(struct StorageBlock *sb) +{ + int i; + int32_t ret; + + if (sb == NULL) { + return HDF_ERR_INVALID_OBJECT; + } + + for (i = 0; i < MAX_BLOCK_COUNT; i++) { + if (g_blocks[i] == NULL) { + g_blocks[i] = sb; + sb->index = i; + break; + } + } + if (i >= MAX_BLOCK_COUNT) { + return HDF_PLT_ERR_DEV_FULL; + } + + if (sb->secSize == 0) { + sb->secSize = STORAGE_SEC_SIZE; + } + + ret = StorageBlockOsInit(sb); + if (ret != HDF_SUCCESS) { + g_blocks[i] = NULL; + return ret; + } + + return HDF_SUCCESS; +} + +void StorageBlockDel(struct StorageBlock *sb) +{ + int i; + + if (sb == NULL) { + return; + } + + for (i = 0; i < MAX_BLOCK_COUNT; i++) { + if (g_blocks[i] == sb) { + g_blocks[i] = NULL; + } + } + + StorageBlockOsUninit(sb); +} + +struct StorageBlock *StorageBlockFromNumber(uint32_t number) +{ + if (number >= MAX_BLOCK_COUNT) { + HDF_LOGE("StorageBlockFromNumber: invalid number:%d", number); + return NULL; + } + return g_blocks[number]; +} diff --git a/support/platform/include/emmc_core.h b/support/platform/include/emmc_core.h deleted file mode 100644 index d6730afb894559c9569dd91f94f16fc5c4ef574a..0000000000000000000000000000000000000000 --- a/support/platform/include/emmc_core.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#ifndef EMMC_CORE_H -#define EMMC_CORE_H - -#include "emmc_if.h" -#include "hdf_base.h" -#include "hdf_device_desc.h" - -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif -#endif /* __cplusplus */ - -struct EmmcMethod; - -enum EmmcIoCmd { - EMMC_IO_GET_CID = 0, -}; - -struct EmmcConfigData { - uint32_t hostId; -}; - -struct EmmcCntlr { - struct IDeviceIoService service; - struct HdfDeviceObject *device; - struct EmmcConfigData configData; - void *priv; - struct EmmcMethod *method; -}; - -/** - * @brief emmc host device operations. - * These methods need to be filled up by specific platform. - */ -struct EmmcMethod { - int32_t (*getCid)(struct EmmcCntlr *, uint8_t *, uint32_t); - int32_t (*findHost)(struct EmmcCntlr *, struct EmmcConfigData *); -}; - -int32_t EmmcCntlrFindHost(struct EmmcCntlr *cntlr); - -/** - * @brief Create a new EmmcCntlr struct, and bind it to a HdfDeviceObject. - * - * @param device The HdfDeviceObject of this EmmcCntlr. - * - * @return Retrns the pointer of the EmmcCntlr struct on success; returns NULL otherwise. - * @since 1.0 - */ -struct EmmcCntlr *EmmcCntlrCreateAndBind(struct HdfDeviceObject *device); - -/** - * @brief Destroy a EmmcCntlr struct, you should always destroy it with this function. - * - * @param cntlr Indicates the emmc cntlr device. - * - * @since 1.0 - */ -void EmmcCntlrDestroy(struct EmmcCntlr *cntlr); - -/** - * @brief Fill config data for an EmmcCntlr. - * - * @param device The HdfDeviceObject of this EmmcCntlr. - * @param configData The config data of this EmmcCntlr. - * - * @return Retrns zero on success; returns negative errno otherwise. - * @since 1.0 - */ -int32_t EmmcFillConfigData(struct HdfDeviceObject *device, struct EmmcConfigData *configData); - -/** - * @brief Turn EmmcCntlr to a HdfDeviceObject. - * - * @param cntlr Indicates the emmc cntlr device. - * - * @return Retrns the pointer of the HdfDeviceObject on success; returns NULL otherwise. - * @since 1.0 - */ -static inline struct HdfDeviceObject *EmmcCntlrToDevice(struct EmmcCntlr *cntlr) -{ - return (cntlr == NULL) ? NULL : cntlr->device; -} - -/** - * @brief Turn HdfDeviceObject to an EmmcCntlr. - * - * @param device Indicates a HdfDeviceObject. - * - * @return Retrns the pointer of the EmmcCntlr on success; returns NULL otherwise. - * @since 1.0 - */ -static inline struct EmmcCntlr *EmmcCntlrFromDevice(struct HdfDeviceObject *device) -{ - return (device == NULL) ? NULL : (struct EmmcCntlr *)device->service; -} - -/** - * @brief Get The CID of EMMC device. - * - * @param cntlr Indicates the emmc cntlr device. - * @param cid Indicates the pointer to the CID to read. - * @param size Indicates the length of the CID. - * - * @return Returns 0 if the operation is successful; returns a negative value if the operation fails. - * - * @since 1.0 - */ -int32_t EmmcCntlrGetCid(struct EmmcCntlr *cntlr, uint8_t *cid, uint32_t size); - -#ifdef __cplusplus -#if __cplusplus -} -#endif -#endif /* __cplusplus */ - -#endif /* EMMC_CORE_H */ diff --git a/support/platform/include/sdio_core.h b/support/platform/include/sdio_core.h deleted file mode 100644 index ef18b6c5cced7bc9b660c8cafe1658e2487a9a75..0000000000000000000000000000000000000000 --- a/support/platform/include/sdio_core.h +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#ifndef SDIO_CORE_H -#define SDIO_CORE_H - -#include "hdf_base.h" -#include "hdf_device_desc.h" -#include "sdio_if.h" - -#ifdef __cplusplus -#if __cplusplus -extern "C" { -#endif -#endif /* __cplusplus */ - -struct SdioCntlr; -struct SdioMethod; - -struct SdioConfigData { - uint32_t funcNum; - uint32_t vendorId; - uint32_t deviceId; -}; - -struct SdioCntlr { - struct IDeviceIoService service; - struct HdfDeviceObject *device; - struct SdioConfigData configData; - void *priv; - struct SdioMethod *method; -}; - -/** - * @brief sdio host device operations. - * These methods need to be filled up by specific platform. - */ -struct SdioMethod { - int32_t (*incrAddrReadBytes)(struct SdioCntlr *, uint8_t *, uint32_t, uint32_t, uint32_t); - int32_t (*incrAddrWriteBytes)(struct SdioCntlr *, uint8_t *, uint32_t, uint32_t, uint32_t); - int32_t (*fixedAddrReadBytes)(struct SdioCntlr *, uint8_t *, uint32_t, uint32_t, uint32_t); - int32_t (*fixedAddrWriteBytes)(struct SdioCntlr *, uint8_t *, uint32_t, uint32_t, uint32_t); - int32_t (*func0ReadBytes)(struct SdioCntlr *, uint8_t *, uint32_t, uint32_t, uint32_t); - int32_t (*func0WriteBytes)(struct SdioCntlr *, uint8_t *, uint32_t, uint32_t, uint32_t); - int32_t (*setBlockSize)(struct SdioCntlr *, uint32_t); - int32_t (*getCommonInfo)(struct SdioCntlr *, SdioCommonInfo *, uint32_t); - int32_t (*setCommonInfo)(struct SdioCntlr *, SdioCommonInfo *, uint32_t); - int32_t (*flushData)(struct SdioCntlr *); - void (*claimHost)(struct SdioCntlr *); - void (*releaseHost)(struct SdioCntlr *); - int32_t (*enableFunc)(struct SdioCntlr *); - int32_t (*disableFunc)(struct SdioCntlr *); - int32_t (*claimIrq)(struct SdioCntlr *, SdioIrqHandler *); - int32_t (*releaseIrq)(struct SdioCntlr *); - int32_t (*findFunc)(struct SdioCntlr *, struct SdioConfigData *); -}; - -/** - * @brief Create a new SdioCntlr struct, and bind it to a HdfDeviceObject. - * - * @param device The HdfDeviceObject of this SdioCntlr. - * - * @return Retrns the pointer of the SdioCntlr struct on success; returns NULL otherwise. - * @since 1.0 - */ -struct SdioCntlr *SdioCntlrCreateAndBind(struct HdfDeviceObject *device); - -/** - * @brief Destroy a SdioCntlr struct, you should always destroy it with this function. - * - * @param cntlr Indicates the SDIO cntlr device. - * - * @since 1.0 - */ -void SdioCntlrDestroy(struct SdioCntlr *cntlr); - -/** - * @brief Fill config data for an SdioCntlr. - * - * @param device The HdfDeviceObject of this SdioCntlr. - * @param configData The config data of this SdioCntlr. - * - * @return Retrns zero on success; returns negative errno otherwise. - * @since 1.0 - */ -int32_t SdioFillConfigData(struct HdfDeviceObject *device, struct SdioConfigData *configData); - -/** - * @brief Turn SdioCntlr to a HdfDeviceObject. - * - * @param cntlr Indicates the SDIO cntlr device. - * - * @return Retrns the pointer of the HdfDeviceObject on success; returns NULL otherwise. - * @since 1.0 - */ -static inline struct HdfDeviceObject *SdioCntlrToDevice(struct SdioCntlr *cntlr) -{ - return (cntlr == NULL) ? NULL : cntlr->device; -} - -/** - * @brief Turn HdfDeviceObject to an SdioCntlr. - * - * @param device Indicates a HdfDeviceObject. - * - * @return Retrns the pointer of the SdioCntlr on success; returns NULL otherwise. - * @since 1.0 - */ -static inline struct SdioCntlr *SdioCntlrFromDevice(struct HdfDeviceObject *device) -{ - return (device == NULL) ? NULL : (struct SdioCntlr *)device->service; -} - -#ifdef __cplusplus -#if __cplusplus -} -#endif -#endif /* __cplusplus */ - -#endif /* SDIO_CORE_H */ diff --git a/support/platform/src/common/platform_device.c b/support/platform/src/common/platform_device.c index 0e70cddfc7fb2643055132c6290add7332dd6c7e..05ae7ea72d311f35a7dc2fa773077532ea0f7aa6 100644 --- a/support/platform/src/common/platform_device.c +++ b/support/platform/src/common/platform_device.c @@ -184,13 +184,13 @@ void PlatformDeviceClearNotifier(struct PlatformDevice *device) } int32_t PlatformDeviceAdd(struct PlatformDevice *device) -{ +{ struct PlatformManager *manager = NULL; - + if (device == NULL) { return HDF_ERR_INVALID_OBJECT; } - + PlatformDeviceInit(device); manager = device->manager; if (manager == NULL) { diff --git a/support/platform/src/emmc_core.c b/support/platform/src/emmc_core.c deleted file mode 100644 index 91c0061c86461d9b94b5143b16771725d431db84..0000000000000000000000000000000000000000 --- a/support/platform/src/emmc_core.c +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#include "emmc_core.h" -#include "device_resource_if.h" -#include "hdf_log.h" -#include "osal_mem.h" - -#define HDF_LOG_TAG emmc_core_c - -int32_t EmmcCntlrFindHost(struct EmmcCntlr *cntlr) -{ - if (cntlr == NULL || cntlr->method == NULL || cntlr->method->findHost == NULL) { - HDF_LOGE("EmmcCntlrFindHost: cntlr or method or findHost is null!"); - return HDF_ERR_INVALID_PARAM; - } - if (cntlr->method->findHost(cntlr, &(cntlr->configData)) != HDF_SUCCESS) { - HDF_LOGE("EmmcCntlrFindHost: findHost failed"); - return HDF_ERR_INVALID_OBJECT; - } - return HDF_SUCCESS; -} - -int32_t EmmcCntlrGetCid(struct EmmcCntlr *cntlr, uint8_t *cid, uint32_t size) -{ - if (cntlr == NULL) { - HDF_LOGE("EmmcCntlrGetCid: cntlr is null"); - return HDF_ERR_INVALID_OBJECT; - } - - if (cntlr->method == NULL || cntlr->method->getCid == NULL) { - HDF_LOGE("EmmcCntlrGetCid: ops or getCid is null"); - return HDF_ERR_NOT_SUPPORT; - } - return cntlr->method->getCid(cntlr, cid, size); -} - -static int32_t EmmcGetCidWriteBackReply(struct HdfSBuf *reply, uint8_t *cid, uint32_t size) -{ - if (!HdfSbufWriteBuffer(reply, cid, size)) { - HDF_LOGE("EmmcGetCidWriteBackReply: write to reply failed"); - return HDF_ERR_IO; - } - return HDF_SUCCESS; -} - -static int32_t EmmcGetCidDispatch(struct EmmcCntlr *cntlr, struct HdfSBuf *reply) -{ - int32_t ret; - uint8_t cid[EMMC_CID_LEN] = {0}; - - ret = EmmcCntlrGetCid(cntlr, cid, EMMC_CID_LEN); - if (ret != HDF_SUCCESS) { - HDF_LOGE("EmmcGetCidDispatch: EmmcCntlrGetCid failed"); - return ret; - } - return EmmcGetCidWriteBackReply(reply, cid, EMMC_CID_LEN); -} - -static int32_t EmmcIoDispatch(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply) -{ - int32_t ret; - struct EmmcCntlr *cntlr = NULL; - (void)data; - - if (client == NULL || client->device == NULL) { - HDF_LOGE("EmmcIoDispatch: client or client->device is null"); - return HDF_ERR_INVALID_OBJECT; - } - - if (reply == NULL) { - HDF_LOGE("EmmcIoDispatch: reply is null"); - return HDF_ERR_INVALID_PARAM; - } - - cntlr = (struct EmmcCntlr *)client->device->service; - if (cntlr == NULL) { - HDF_LOGE("EmmcIoDispatch: service is null"); - return HDF_ERR_INVALID_OBJECT; - } - if (cntlr->priv == NULL) { - if (EmmcCntlrFindHost(cntlr) != HDF_SUCCESS) { - HDF_LOGE("EmmcIoDispatch: find host failed"); - return HDF_ERR_INVALID_OBJECT; - } - } - - switch (cmd) { - case EMMC_IO_GET_CID: - ret = EmmcGetCidDispatch(cntlr, reply); - break; - default: - ret = HDF_ERR_NOT_SUPPORT; - break; - } - - return ret; -} - -struct EmmcCntlr *EmmcCntlrCreateAndBind(struct HdfDeviceObject *device) -{ - struct EmmcCntlr *cntlr = NULL; - - if (device == NULL) { - HDF_LOGE("EmmcCntlrCreateAndBind: device is null!"); - return NULL; - } - - cntlr = (struct EmmcCntlr *)OsalMemCalloc(sizeof(*cntlr)); - if (cntlr == NULL) { - HDF_LOGE("EmmcCntlrCreateAndBind: malloc host failed"); - return NULL; - } - cntlr->device = device; - device->service = &cntlr->service; - cntlr->device->service->Dispatch = EmmcIoDispatch; - return cntlr; -} - -void EmmcCntlrDestroy(struct EmmcCntlr *cntlr) -{ - if (cntlr != NULL) { - cntlr->device = NULL; - cntlr->priv = NULL; - cntlr->method = NULL; - OsalMemFree(cntlr); - } -} - -int32_t EmmcFillConfigData(struct HdfDeviceObject *device, struct EmmcConfigData *configData) -{ - const struct DeviceResourceNode *node = NULL; - struct DeviceResourceIface *drsOps = NULL; - int32_t ret; - - if (device == NULL || configData == NULL) { - HDF_LOGE("EmmcFillConfigData: input para is null."); - return HDF_FAILURE; - } - - node = device->property; - if (node == NULL) { - HDF_LOGE("EmmcFillConfigData: drs node is null."); - return HDF_FAILURE; - } - drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); - if (drsOps == NULL || drsOps->GetUint32 == NULL) { - HDF_LOGE("EmmcFillConfigData: invalid drs ops failed"); - return HDF_FAILURE; - } - - ret = drsOps->GetUint32(node, "hostId", &(configData->hostId), 0); - if (ret != HDF_SUCCESS) { - HDF_LOGE("EmmcFillConfigData: read funcNum failed"); - return ret; - } - - HDF_LOGD("EmmcFillConfigData: Success! hostId = %u.", configData->hostId); - return HDF_SUCCESS; -} diff --git a/support/platform/src/emmc_if.c b/support/platform/src/emmc_if.c deleted file mode 100644 index ed70d88c7ee53d588c77062f3c8a5e1e0f451203..0000000000000000000000000000000000000000 --- a/support/platform/src/emmc_if.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#include "emmc_if.h" -#include -#ifndef __USER__ -#include "devsvc_manager_clnt.h" -#include "emmc_core.h" -#endif -#include "hdf_base.h" -#ifdef __USER__ -#include "hdf_io_service_if.h" -#endif -#include "hdf_log.h" -#include "osal_mem.h" -#include "securec.h" - -#define HDF_LOG_TAG emmc_if_c - -#define EMMC_NAME_LEN 32 - -static void *EmmcCntlrObjGetByNumber(int16_t busNum) -{ - void *object = NULL; - char *serviceName = NULL; - - if (busNum < 0) { - HDF_LOGE("EmmcCntlrObjGetByNumber: invalid bus:%d", busNum); - return NULL; - } - serviceName = OsalMemCalloc(EMMC_NAME_LEN + 1); - if (serviceName == NULL) { - HDF_LOGE("EmmcCntlrObjGetByNumber: OsalMemCalloc fail!"); - return NULL; - } - if (snprintf_s(serviceName, EMMC_NAME_LEN + 1, EMMC_NAME_LEN, - "HDF_PLATFORM_EMMC_%d", busNum) < 0) { - HDF_LOGE("EmmcCntlrObjGetByNumber: format service name fail!"); - goto __ERR; - } - -#ifdef __USER__ - object = (void *)HdfIoServiceBind(serviceName); - HDF_LOGD("EmmcCntlrObjGetByNumber: user status"); -#else - object = (void *)DevSvcManagerClntGetService(serviceName); - HDF_LOGD("EmmcCntlrObjGetByNumber: kernel status"); -#endif - if (object == NULL) { - HDF_LOGE("EmmcCntlrObjGetByNumber: get service fail!"); - goto __ERR; - } - -#ifndef __USER__ - struct EmmcCntlr *cntlr = (struct EmmcCntlr *)object; - if (cntlr->priv == NULL && EmmcCntlrFindHost(cntlr) != HDF_SUCCESS) { - HDF_LOGE("EmmcCntlrObjGetByNumber: EmmcCntlrFindHost fail!"); - goto __ERR; - } -#endif - - HDF_LOGD("EmmcCntlrObjGetByNumber: success"); - OsalMemFree(serviceName); - return object; -__ERR: - OsalMemFree(serviceName); - return NULL; -} - -DevHandle EmmcOpen(int16_t busNum) -{ - return (DevHandle)EmmcCntlrObjGetByNumber(busNum); -} - -void EmmcClose(DevHandle handle) -{ - if (handle != NULL) { -#ifdef __USER__ - HdfIoServiceRecycle((struct HdfIoService *)handle); -#endif - } -} - -#ifdef __USER__ -enum EmmcIoCmd { - EMMC_IO_GET_CID = 0, -}; - -static int32_t EmmcGetCidReadReplyData(struct HdfSBuf *reply, uint8_t *cid, uint32_t size) -{ - uint32_t rLen; - const void *rBuf = NULL; - - if (!HdfSbufReadBuffer(reply, &rBuf, &rLen)) { - HDF_LOGE("EmmcGetCidReadReplyData: read rBuf fail!"); - return HDF_ERR_IO; - } - - if (memcpy_s(cid, size, rBuf, rLen) != EOK) { - HDF_LOGE("EmmcGetCidReadReplyData: memcpy rBuf fail!"); - return HDF_ERR_IO; - } - HDF_LOGD("EmmcGetCidReadReplyData: success"); - return HDF_SUCCESS; -} - -static int32_t EmmcServiceGetCid(struct HdfIoService *service, uint8_t *cid, uint32_t size) -{ - int32_t ret; - struct HdfSBuf *reply = NULL; - - reply = HdfSBufObtainDefaultSize(); - if (reply == NULL) { - HDF_LOGE("EmmcServiceGetCid: failed to obtain reply!"); - ret = HDF_ERR_MALLOC_FAIL; - goto __EXIT; - } - - if (service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) { - HDF_LOGE("EmmcServiceGetCid: dispatcher or Dispatch is NULL!"); - ret = HDF_ERR_NOT_SUPPORT; - goto __EXIT; - } - - ret = service->dispatcher->Dispatch(&service->object, EMMC_IO_GET_CID, NULL, reply); - if (ret != HDF_SUCCESS) { - HDF_LOGE("EmmcServiceGetCid: failed to send service call:%d", ret); - goto __EXIT; - } - - ret = EmmcGetCidReadReplyData(reply, cid, size); - if (ret != HDF_SUCCESS) { - goto __EXIT; - } - HDF_LOGD("EmmcServiceGetCid: success"); - -__EXIT: - if (reply != NULL) { - HdfSBufRecycle(reply); - } - return ret; -} -#endif - -int32_t EmmcGetCid(DevHandle handle, uint8_t *cid, uint32_t size) -{ - if (handle == NULL) { - HDF_LOGE("EmmcGetCid: handle is NULL!"); - return HDF_ERR_INVALID_OBJECT; - } - - if (cid == NULL || size < EMMC_CID_LEN) { - HDF_LOGE("EmmcGetCid: error params!"); - return HDF_ERR_INVALID_PARAM; - } -#ifdef __USER__ - return EmmcServiceGetCid((struct HdfIoService *)handle, cid, size); -#else - return EmmcCntlrGetCid((struct EmmcCntlr *)handle, cid, size); -#endif -} - -void EmmcGetHuid(uint8_t *cid, uint32_t size) -{ - DevHandle handle = NULL; - - if (cid == NULL || size == 0) { - HDF_LOGE("EmmcGetUdid: error params!"); - return; - } - if (memset_s(cid, sizeof(uint8_t) * size, 0, sizeof(uint8_t) * size) != EOK) { - HDF_LOGE("EmmcGetUdid: memset_s fail!"); - return; - } - - handle = EmmcOpen(0); - if (handle == NULL) { - HDF_LOGW("EmmcGetUdid: open fail, use default value!"); - return; - } - if (EmmcGetCid(handle, cid, size) != HDF_SUCCESS) { - HDF_LOGW("EmmcGetUdid: get fail, use default value!"); - } - EmmcClose(handle); -} diff --git a/support/platform/src/sdio_core.c b/support/platform/src/sdio_core.c deleted file mode 100644 index 737480a90680ad34855101f0adfa59dcf3b284e8..0000000000000000000000000000000000000000 --- a/support/platform/src/sdio_core.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#include "sdio_core.h" -#include "device_resource_if.h" -#include "osal_mem.h" -#include "plat_log.h" - -#define HDF_LOG_TAG sdio_core - -struct SdioCntlr *SdioCntlrCreateAndBind(struct HdfDeviceObject *device) -{ - struct SdioCntlr *cntlr = NULL; - - if (device == NULL) { - HDF_LOGE("SdioCntlrCreateAndBind: device is NULL!"); - return NULL; - } - - cntlr = (struct SdioCntlr *)OsalMemCalloc(sizeof(*cntlr)); - if (cntlr == NULL) { - HDF_LOGE("SdioCntlrCreateAndBind: malloc host fail!"); - return NULL; - } - cntlr->device = device; - device->service = &cntlr->service; - return cntlr; -} - -void SdioCntlrDestroy(struct SdioCntlr *cntlr) -{ - if (cntlr != NULL) { - cntlr->device = NULL; - cntlr->priv = NULL; - cntlr->method = NULL; - OsalMemFree(cntlr); - } -} - -int32_t SdioFillConfigData(struct HdfDeviceObject *device, struct SdioConfigData *configData) -{ - const struct DeviceResourceNode *node = NULL; - struct DeviceResourceIface *drsOps = NULL; - int32_t ret; - - if (device == NULL || configData == NULL) { - HDF_LOGE("SdioFillConfigData: input para is NULL."); - return HDF_FAILURE; - } - - node = device->property; - if (node == NULL) { - HDF_LOGE("SdioFillConfigData: drs node is NULL."); - return HDF_FAILURE; - } - drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); - if (drsOps == NULL || drsOps->GetUint32 == NULL) { - HDF_LOGE("SdioFillConfigData: invalid drs ops fail!"); - return HDF_FAILURE; - } - - ret = drsOps->GetUint32(node, "funcNum", &(configData->funcNum), 0); - if (ret != HDF_SUCCESS) { - HDF_LOGE("SdioFillConfigData: read funcNum fail!"); - return ret; - } - ret = drsOps->GetUint32(node, "vendorId", &(configData->vendorId), 0); - if (ret != HDF_SUCCESS) { - HDF_LOGE("SdioFillConfigData: read vendorId fail!"); - return ret; - } - ret = drsOps->GetUint32(node, "deviceId", &(configData->deviceId), 0); - if (ret != HDF_SUCCESS) { - HDF_LOGE("SdioFillConfigData: read deviceId fail!"); - return ret; - } - - PLAT_LOGV("SdioFillConfigData: Success! funcNum = %d", configData->funcNum); - return HDF_SUCCESS; -} diff --git a/support/platform/src/sdio_if.c b/support/platform/src/sdio_if.c deleted file mode 100644 index 24059a47aa60ca6d211f3006aefb59372a3d57a7..0000000000000000000000000000000000000000 --- a/support/platform/src/sdio_if.c +++ /dev/null @@ -1,410 +0,0 @@ -/* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - * - * HDF is dual licensed: you can use it either under the terms of - * the GPL, or the BSD license, at your option. - * See the LICENSE file in the root of this repository for complete details. - */ - -#include "devsvc_manager_clnt.h" -#include "hdf_base.h" -#include "osal_mem.h" -#include "plat_log.h" -#include "securec.h" -#include "sdio_core.h" - -#define HDF_LOG_TAG sdio_if_c - -#define SDIO_NAME_LEN 32 -#define SDIO_BUS_MAX 2 - -static struct SdioCntlr *SdioGetCntlrByBusNum(int16_t busNum) -{ - struct SdioCntlr *cntlr = NULL; - char *serviceName = NULL; - - if (busNum < 0 || busNum >= SDIO_BUS_MAX) { - HDF_LOGE("SdioGetCntlrByBusNum: invalid bus:%d", busNum); - return NULL; - } - serviceName = OsalMemCalloc(SDIO_NAME_LEN + 1); - if (serviceName == NULL) { - return NULL; - } - if (snprintf_s(serviceName, SDIO_NAME_LEN + 1, SDIO_NAME_LEN, - "HDF_PLATFORM_SDIO_%d", busNum) < 0) { - HDF_LOGE("SdioGetCntlrByBusNum: format service name fail!"); - OsalMemFree(serviceName); - return NULL; - } - cntlr = (struct SdioCntlr*)DevSvcManagerClntGetService(serviceName); - if (cntlr == NULL) { - HDF_LOGE("SdioGetCntlrByBusNum: get service fail!"); - } - OsalMemFree(serviceName); - return cntlr; -} - -DevHandle SdioOpen(int16_t busNum) -{ - struct SdioCntlr *cntlr = NULL; - int32_t ret; - - cntlr = SdioGetCntlrByBusNum(busNum); - if (cntlr == NULL) { - HDF_LOGE("SdioOpen: SdioGetCntlrByBusNum fail!"); - return NULL; - } - if (cntlr->method == NULL) { - HDF_LOGE("SdioOpen: method is NULL!"); - return NULL; - } - if (cntlr->method->findFunc == NULL) { - HDF_LOGE("SdioOpen: findFunc is NULL!"); - return NULL; - } - - ret = cntlr->method->findFunc(cntlr, &(cntlr->configData)); - if (ret != HDF_SUCCESS) { - HDF_LOGE("SdioOpen: findFunc fail!"); - return NULL; - } - - PLAT_LOGV("SdioOpen: Success!"); - return (DevHandle)cntlr; -} - -void SdioClose(DevHandle handle) -{ - (void)handle; -} - -int32_t SdioReadBytes(DevHandle handle, uint8_t *data, uint32_t addr, - uint32_t size, uint32_t timeOut) -{ - struct SdioCntlr *cntlr = NULL; - - if (handle == NULL) { - HDF_LOGE("SdioReadBytes: handle or object is null!"); - return HDF_ERR_INVALID_OBJECT; - } - if (data == NULL) { - HDF_LOGE("SdioReadBytes: data is null!"); - return HDF_ERR_INVALID_PARAM; - } - - cntlr = (struct SdioCntlr *)handle; - if (cntlr->method == NULL || cntlr->method->incrAddrReadBytes == NULL) { - HDF_LOGE("SdioReadBytes: method or incrAddrReadBytes is null!"); - return HDF_ERR_NOT_SUPPORT; - } - PLAT_LOGV("SdioReadBytes: Success!"); - return cntlr->method->incrAddrReadBytes(cntlr, data, addr, size, timeOut); -} - -int32_t SdioWriteBytes(DevHandle handle, uint8_t *data, uint32_t addr, - uint32_t size, uint32_t timeOut) -{ - struct SdioCntlr *cntlr = NULL; - - if (handle == NULL) { - HDF_LOGE("SdioWriteBytes: handle or object is null!"); - return HDF_ERR_INVALID_OBJECT; - } - if (data == NULL) { - HDF_LOGE("SdioWriteBytes: data is null!"); - return HDF_ERR_INVALID_PARAM; - } - - cntlr = (struct SdioCntlr *)handle; - if (cntlr->method == NULL || cntlr->method->incrAddrWriteBytes == NULL) { - HDF_LOGE("SdioWriteBytes: method or incrAddrWriteBytes is null!"); - return HDF_ERR_NOT_SUPPORT; - } - PLAT_LOGV("SdioWriteBytes: Success!"); - return cntlr->method->incrAddrWriteBytes(cntlr, data, addr, size, timeOut); -} - -int32_t SdioReadBytesFromFixedAddr(DevHandle handle, uint8_t *data, - uint32_t addr, uint32_t size, uint32_t timeOut) -{ - struct SdioCntlr *cntlr = NULL; - - if (handle == NULL) { - HDF_LOGE("SdioReadBytesFromFixedAddr: handle or object is null!"); - return HDF_ERR_INVALID_OBJECT; - } - if (data == NULL) { - HDF_LOGE("SdioReadBytesFromFixedAddr: data is null!"); - return HDF_ERR_INVALID_PARAM; - } - - cntlr = (struct SdioCntlr *)handle; - if (cntlr->method == NULL || cntlr->method->fixedAddrReadBytes == NULL) { - HDF_LOGE("SdioReadBytesFromFixedAddr: method or incrAddrWriteBytes is null!"); - return HDF_ERR_NOT_SUPPORT; - } - PLAT_LOGV("SdioReadBytesFromFixedAddr: Success!"); - return cntlr->method->fixedAddrReadBytes(cntlr, data, addr, size, timeOut); -} - -int32_t SdioWriteBytesToFixedAddr(DevHandle handle, uint8_t *data, - uint32_t addr, uint32_t size, uint32_t timeOut) -{ - struct SdioCntlr *cntlr = NULL; - - if (handle == NULL) { - HDF_LOGE("SdioWriteBytesToFixedAddr: handle or object is null!"); - return HDF_ERR_INVALID_OBJECT; - } - if (data == NULL) { - HDF_LOGE("SdioWriteBytesToFixedAddr: data is null!"); - return HDF_ERR_INVALID_PARAM; - } - - cntlr = (struct SdioCntlr *)handle; - if (cntlr->method == NULL || cntlr->method->fixedAddrWriteBytes == NULL) { - HDF_LOGE("SdioWriteBytesToFixedAddr: method or fixedAddrWriteBytes is null!"); - return HDF_ERR_NOT_SUPPORT; - } - PLAT_LOGV("SdioWriteBytesToFixedAddr: Success!"); - return cntlr->method->fixedAddrWriteBytes(cntlr, data, addr, size, timeOut); -} - -int32_t SdioReadBytesFromFunc0(DevHandle handle, uint8_t *data, - uint32_t addr, uint32_t size, uint32_t timeOut) -{ - struct SdioCntlr *cntlr = NULL; - - if (handle == NULL) { - HDF_LOGE("SdioReadBytesFromFunc0: handle or object is null!"); - return HDF_ERR_INVALID_OBJECT; - } - if (data == NULL) { - HDF_LOGE("SdioReadBytesFromFunc0: data is null!"); - return HDF_ERR_INVALID_PARAM; - } - - cntlr = (struct SdioCntlr *)handle; - if (cntlr->method == NULL || cntlr->method->func0ReadBytes == NULL) { - HDF_LOGE("SdioReadBytesFromFunc0: method or func0ReadBytes is null!"); - return HDF_ERR_NOT_SUPPORT; - } - PLAT_LOGV("SdioReadBytesFromFunc0: Success!"); - return cntlr->method->func0ReadBytes(cntlr, data, addr, size, timeOut); -} - -int32_t SdioWriteBytesToFunc0(DevHandle handle, uint8_t *data, - uint32_t addr, uint32_t size, uint32_t timeOut) -{ - struct SdioCntlr *cntlr = NULL; - - if (handle == NULL) { - HDF_LOGE("SdioWriteBytesToFunc0: handle or object is null!"); - return HDF_ERR_INVALID_OBJECT; - } - if (data == NULL) { - HDF_LOGE("SdioWriteBytesToFunc0: data is null!"); - return HDF_ERR_INVALID_PARAM; - } - - cntlr = (struct SdioCntlr *)handle; - if (cntlr->method == NULL || cntlr->method->func0WriteBytes == NULL) { - HDF_LOGE("SdioWriteBytesToFunc0: method or func0WriteBytes is null!"); - return HDF_ERR_NOT_SUPPORT; - } - PLAT_LOGV("SdioWriteBytesToFunc0: Success!"); - return cntlr->method->func0WriteBytes(cntlr, data, addr, size, timeOut); -} - -int32_t SdioSetBlockSize(DevHandle handle, uint32_t blockSize) -{ - struct SdioCntlr *cntlr = NULL; - - if (handle == NULL) { - HDF_LOGE("SdioSetBlockSize: handle or object is null!"); - return HDF_ERR_INVALID_OBJECT; - } - - cntlr = (struct SdioCntlr *)handle; - if (cntlr->method == NULL || cntlr->method->setBlockSize == NULL) { - HDF_LOGE("SdioSetBlockSize: method or setBlockSize is null!"); - return HDF_ERR_NOT_SUPPORT; - } - PLAT_LOGV("SdioSetBlockSize: Success!"); - return cntlr->method->setBlockSize(cntlr, blockSize); -} - -int32_t SdioGetCommonInfo(DevHandle handle, SdioCommonInfo *info, SdioCommonInfoType infoType) -{ - struct SdioCntlr *cntlr = NULL; - - if (handle == NULL) { - HDF_LOGE("SdioGetCommonInfo: handle or object is null!"); - return HDF_ERR_INVALID_OBJECT; - } - if (info == NULL) { - HDF_LOGE("SdioGetCommonInfo: info is NULL!"); - return HDF_ERR_INVALID_PARAM; - } - - cntlr = (struct SdioCntlr *)handle; - if (cntlr->method == NULL || cntlr->method->getCommonInfo == NULL) { - HDF_LOGE("SdioGetCommonInfo: method or getCommonInfo is null!"); - return HDF_ERR_NOT_SUPPORT; - } - PLAT_LOGV("SdioGetCommonInfo: Success! infoType is %d.", infoType); - return cntlr->method->getCommonInfo(cntlr, info, infoType); -} - -int32_t SdioSetCommonInfo(DevHandle handle, SdioCommonInfo *info, SdioCommonInfoType infoType) -{ - struct SdioCntlr *cntlr = NULL; - - if (handle == NULL) { - HDF_LOGE("SdioSetCommonInfo: handle or object is null!"); - return HDF_ERR_INVALID_OBJECT; - } - if (info == NULL) { - HDF_LOGE("SdioSetCommonInfo: info is NULL!"); - return HDF_ERR_INVALID_PARAM; - } - - cntlr = (struct SdioCntlr *)handle; - if (cntlr->method == NULL || cntlr->method->setCommonInfo == NULL) { - HDF_LOGE("SdioSetCommonInfo: method or setCommonInfo is null!"); - return HDF_ERR_NOT_SUPPORT; - } - PLAT_LOGV("SdioSetCommonInfo: Success! infoType is %d.", infoType); - return cntlr->method->setCommonInfo(cntlr, info, infoType); -} - -int32_t SdioFlushData(DevHandle handle) -{ - struct SdioCntlr *cntlr = NULL; - - if (handle == NULL) { - HDF_LOGE("SdioFlushData: handle or object is null!"); - return HDF_ERR_INVALID_OBJECT; - } - - cntlr = (struct SdioCntlr *)handle; - if (cntlr->method == NULL || cntlr->method->flushData == NULL) { - HDF_LOGE("SdioFlushData: method or flushData is null!"); - return HDF_ERR_NOT_SUPPORT; - } - PLAT_LOGV("SdioFlushData: Success!"); - return cntlr->method->flushData(cntlr); -} - -void SdioClaimHost(DevHandle handle) -{ - struct SdioCntlr *cntlr = NULL; - - if (handle == NULL) { - HDF_LOGE("SdioClaimHost: handle or object is null!"); - return; - } - - cntlr = (struct SdioCntlr *)handle; - if (cntlr->method == NULL || cntlr->method->claimHost == NULL) { - HDF_LOGE("SdioClaimHost: method or claimHost is null!"); - return; - } - PLAT_LOGV("SdioClaimHost: Success!"); - cntlr->method->claimHost(cntlr); -} - -void SdioReleaseHost(DevHandle handle) -{ - struct SdioCntlr *cntlr = NULL; - - if (handle == NULL) { - HDF_LOGE("SdioReleaseHost: handle or object is null!"); - return; - } - - cntlr = (struct SdioCntlr *)handle; - if (cntlr->method == NULL || cntlr->method->releaseHost == NULL) { - HDF_LOGE("SdioReleaseHost: method or releaseHost is null!"); - return; - } - PLAT_LOGV("SdioReleaseHost: Success!"); - cntlr->method->releaseHost(cntlr); -} - -int32_t SdioEnableFunc(DevHandle handle) -{ - struct SdioCntlr *cntlr = NULL; - - if (handle == NULL) { - HDF_LOGE("SdioEnableFunc: handle or object is null!"); - return HDF_ERR_INVALID_OBJECT; - } - - cntlr = (struct SdioCntlr *)handle; - if (cntlr->method == NULL || cntlr->method->enableFunc == NULL) { - HDF_LOGE("SdioEnableFunc: method or enableFunc is null!"); - return HDF_ERR_NOT_SUPPORT; - } - PLAT_LOGV("SdioEnableFunc: Success!"); - return cntlr->method->enableFunc(cntlr); -} - -int32_t SdioDisableFunc(DevHandle handle) -{ - struct SdioCntlr *cntlr = NULL; - - if (handle == NULL) { - HDF_LOGE("SdioDisableFunc: handle or object is null!"); - return HDF_ERR_INVALID_OBJECT; - } - - cntlr = (struct SdioCntlr *)handle; - if (cntlr->method == NULL || cntlr->method->disableFunc == NULL) { - HDF_LOGE("SdioDisableFunc: method or disableFunc is null!"); - return HDF_ERR_NOT_SUPPORT; - } - PLAT_LOGV("SdioDisableFunc: Success!"); - return cntlr->method->disableFunc(cntlr); -} - -int32_t SdioClaimIrq(DevHandle handle, SdioIrqHandler *irqHandler) -{ - struct SdioCntlr *cntlr = NULL; - - if (handle == NULL) { - HDF_LOGE("SdioClaimIrq: handle or object is null!"); - return HDF_ERR_INVALID_OBJECT; - } - if (irqHandler == NULL) { - HDF_LOGE("SdioClaimIrq: irqHandler is null!"); - return HDF_ERR_INVALID_PARAM; - } - - cntlr = (struct SdioCntlr *)handle; - if (cntlr->method == NULL || cntlr->method->claimIrq == NULL) { - HDF_LOGE("SdioClaimIrq: method or claimIrq is null!"); - return HDF_ERR_NOT_SUPPORT; - } - PLAT_LOGV("SdioClaimIrq: Success!"); - return cntlr->method->claimIrq(cntlr, irqHandler); -} - -int32_t SdioReleaseIrq(DevHandle handle) -{ - struct SdioCntlr *cntlr = NULL; - - if (handle == NULL) { - HDF_LOGE("SdioReleaseIrq: handle or object is null!"); - return HDF_ERR_INVALID_OBJECT; - } - - cntlr = (struct SdioCntlr *)handle; - if (cntlr->method == NULL || cntlr->method->releaseIrq == NULL) { - HDF_LOGE("SdioReleaseIrq: method or releaseIrq is null!"); - return HDF_ERR_NOT_SUPPORT; - } - PLAT_LOGV("SdioReleaseIrq: Success!"); - return cntlr->method->releaseIrq(cntlr); -} diff --git a/test/unittest/platform/common/sdio_test.c b/test/unittest/platform/common/sdio_test.c index f661c3fc2a652e99a111a0b2bef72bc0ffe2004e..a0e474bc1f16b8c667ea0cada3415757528b7150 100644 --- a/test/unittest/platform/common/sdio_test.c +++ b/test/unittest/platform/common/sdio_test.c @@ -37,7 +37,7 @@ static DevHandle SdioTestGetHandle(struct SdioTester *tester) HDF_LOGE("%s: tester is null", __func__); return NULL; } - return SdioOpen(tester->busNum); + return SdioOpen((int16_t)(tester->busNum), &(tester->config)); } static void SdioTestReleaseHandle(DevHandle handle) @@ -55,13 +55,13 @@ static int32_t TestSdioIncrAddrReadAndWriteOtherBytes(struct SdioTester *tester) uint8_t data[TEST_DATA_LEN] = {0}; const uint32_t addr = TEST_SDIO_BASE_ADDR * TEST_FUNC_NUM + TEST_ADDR_OFFSET + TEST_ADDR_ADD; - ret = SdioReadBytes(tester->handle, &data[0], addr, 1, 0); + ret = SdioReadBytes(tester->handle, &data[0], addr, 1); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: SdioReadBytes fail! ret=%d.", __func__, ret); return HDF_FAILURE; } - HDF_LOGE("%s: read, data[0]:%u\n", __func__, data[0]); - ret = SdioWriteBytes(tester->handle, &data[0], addr, 1, 0); + HDF_LOGE("%s: read, data[0]:%d\n", __func__, data[0]); + ret = SdioWriteBytes(tester->handle, &data[0], addr, 1); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: SdioWriteBytes fail! ret=%d.", __func__, ret); return HDF_FAILURE; @@ -78,14 +78,14 @@ static int32_t TestSdioIncrAddrReadAndWriteOneByte(struct SdioTester *tester) addr = TEST_SDIO_BASE_ADDR * TEST_FUNC_NUM + TEST_ADDR_OFFSET; /* read 1 bits */ - ret = SdioReadBytes(tester->handle, &val, addr, 1, 0); + ret = SdioReadBytes(tester->handle, &val, addr, 1); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: SdioReadBytes fail! ret=%d.", __func__, ret); return HDF_FAILURE; } HDF_LOGE("%s: read, val:%d\n", __func__, val); /* write 1 bits */ - ret = SdioWriteBytes(tester->handle, &val, addr, 1, 0); + ret = SdioWriteBytes(tester->handle, &val, addr, 1); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: SdioWriteBytes fail! ret=%d.", __func__, ret); return HDF_FAILURE; @@ -93,7 +93,7 @@ static int32_t TestSdioIncrAddrReadAndWriteOneByte(struct SdioTester *tester) HDF_LOGE("%s: write, val:%d\n", __func__, val); /* read 1 bits */ addr++; - ret = SdioReadBytes(tester->handle, &val, addr, 1, 0); + ret = SdioReadBytes(tester->handle, &val, addr, 1); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: SdioReadBytes fail! ret=%d.", __func__, ret); return HDF_FAILURE; @@ -101,7 +101,7 @@ static int32_t TestSdioIncrAddrReadAndWriteOneByte(struct SdioTester *tester) HDF_LOGE("%s: read, val:%u.", __func__, val); /* read 1 bits */ addr++; - ret = SdioReadBytes(tester->handle, &val, addr, 1, 0); + ret = SdioReadBytes(tester->handle, &val, addr, 1); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: SdioReadBytes fail! ret=%d.", __func__, ret); return HDF_FAILURE; @@ -139,14 +139,14 @@ static int32_t TestSdioFixedAddrReadAndWriteOtherBytes(struct SdioTester *tester const uint32_t addr = TEST_SDIO_BASE_ADDR * TEST_FUNC_NUM + TEST_FIXED_OFFSET + TEST_ADDR_ADD; /* read bits */ - ret = SdioReadBytes(tester->handle, &data[0], addr, 1, 0); + ret = SdioReadBytes(tester->handle, &data[0], addr, 1); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: SdioReadBytesFromFixedAddr fail! ret=%d.", __func__, ret); return HDF_FAILURE; } HDF_LOGE("%s: read, data[0]:%u, data[1]:%u\n", __func__, data[0], data[1]); /* write bits */ - ret = SdioWriteBytes(tester->handle, &data[0], addr, 1, 0); + ret = SdioWriteBytes(tester->handle, &data[0], addr, 1); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: SdioWriteBytesToFixedAddr fail! ret=%d.", __func__, ret); return HDF_FAILURE; @@ -163,14 +163,14 @@ static int32_t TestSdioFixedAddrReadAndWriteOneByte(struct SdioTester *tester) addr = TEST_SDIO_BASE_ADDR * TEST_FUNC_NUM + TEST_FIXED_OFFSET; /* read 1 bits */ - ret = SdioReadBytes(tester->handle, &val, addr, 1, 0); + ret = SdioReadBytes(tester->handle, &val, addr, 1); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: SdioReadBytesFromFixedAddr fail! ret=%d.", __func__, ret); return HDF_FAILURE; } HDF_LOGE("%s: read, val:%d\n", __func__, val); /* write 1 bits */ - ret = SdioWriteBytes(tester->handle, &val, addr, 1, 0); + ret = SdioWriteBytes(tester->handle, &val, addr, 1); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: SdioWriteBytesToFixedAddr fail! ret=%d.", __func__, ret); return HDF_FAILURE; @@ -178,7 +178,7 @@ static int32_t TestSdioFixedAddrReadAndWriteOneByte(struct SdioTester *tester) HDF_LOGE("%s: write, val:%d.", __func__, val); /* read 1 bits */ addr++; - ret = SdioReadBytes(tester->handle, &val, addr, 1, 0); + ret = SdioReadBytes(tester->handle, &val, addr, 1); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: SdioReadBytesFromFixedAddr fail! ret=%d.", __func__, ret); return HDF_FAILURE; @@ -186,7 +186,7 @@ static int32_t TestSdioFixedAddrReadAndWriteOneByte(struct SdioTester *tester) HDF_LOGE("%s: read, val:%d.", __func__, val); /* read 1 bits */ addr++; - ret = SdioWriteBytes(tester->handle, &val, addr, 1, 0); + ret = SdioWriteBytes(tester->handle, &val, addr, 1); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: SdioReadBytesFromFixedAddr fail! ret=%d.", __func__, ret); return HDF_FAILURE; @@ -225,7 +225,7 @@ static int32_t TestSdioFunc0ReadAndWriteBytes(struct SdioTester *tester) SdioClaimHost(tester->handle); /* read sdio rev */ - ret = SdioReadBytesFromFunc0(tester->handle, &val, TEST_FUNC0_ADDR, 1, 0); + ret = SdioReadBytesFromFunc0(tester->handle, &val, TEST_FUNC0_ADDR, 1); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: SdioReadBytesFromFunc0 fail! ret=%d.", __func__, ret); SdioReleaseHost(tester->handle); @@ -234,7 +234,7 @@ static int32_t TestSdioFunc0ReadAndWriteBytes(struct SdioTester *tester) HDF_LOGE("%s: Func0 Read, val :%d.", __func__, val); /* write sdio rev */ - ret = SdioWriteBytesToFunc0(tester->handle, &val, TEST_FUNC0_ADDR, 1, 0); + ret = SdioWriteBytesToFunc0(tester->handle, &val, TEST_FUNC0_ADDR, 1); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: SdioWriteBytesToFunc0 fail! ret=%d.", __func__, ret); SdioReleaseHost(tester->handle); @@ -242,7 +242,7 @@ static int32_t TestSdioFunc0ReadAndWriteBytes(struct SdioTester *tester) } /* read sdio rev again */ - ret = SdioReadBytesFromFunc0(tester->handle, &val, TEST_FUNC0_ADDR, 1, 0); + ret = SdioReadBytesFromFunc0(tester->handle, &val, TEST_FUNC0_ADDR, 1); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: SdioReadBytesFromFunc0 fail! ret=%d.", __func__, ret); SdioReleaseHost(tester->handle); @@ -399,24 +399,24 @@ static int32_t SdioTestFillConfig(struct SdioTester *tester, const struct Device return ret; } - ret = drsOps->GetUint32(node, "funcNum", &(tester->funcNum), 0); + ret = drsOps->GetUint32(node, "funcNum", &(tester->config.funcNr), 0); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: fill funcNum fail!", __func__); return ret; } - ret = drsOps->GetUint32(node, "vendorId", &(tester->vendorId), 0); + ret = drsOps->GetUint16(node, "vendorId", &(tester->config.vendorId), 0); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: fill vendorId fail!", __func__); return ret; } - ret = drsOps->GetUint32(node, "deviceId", &(tester->deviceId), 0); + ret = drsOps->GetUint16(node, "deviceId", &(tester->config.deviceId), 0); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: fill deviceId fail!", __func__); return ret; } - HDF_LOGE("%s: busNum:%u, funcNum:%u, vendorId:0x%x.", __func__, - tester->busNum, tester->funcNum, tester->vendorId); + HDF_LOGE("%s: busNum:%u, funcNum:%u, vendorId:0x%x, deviceId:0x%x.", __func__, + tester->busNum, tester->config.funcNr, tester->config.vendorId, tester->config.deviceId); return HDF_SUCCESS; } diff --git a/test/unittest/platform/common/sdio_test.h b/test/unittest/platform/common/sdio_test.h index 2e69ada9d92e994b23f6b1bd42bdf13e8984f723..946cb4ccb7d5967a15956ea3a1c7c6f0afb5d61e 100644 --- a/test/unittest/platform/common/sdio_test.h +++ b/test/unittest/platform/common/sdio_test.h @@ -11,6 +11,7 @@ #include "hdf_device_desc.h" #include "hdf_platform.h" +#include "sdio_if.h" enum SdioTestCmd { SDIO_DISABLE_FUNC_01 = 0, @@ -26,10 +27,8 @@ struct SdioTester { struct IDeviceIoService service; struct HdfDeviceObject *device; int32_t (*TestEntry)(struct SdioTester *tester, int32_t cmd); + struct SdioFunctionConfig config; uint32_t busNum; - uint32_t funcNum; - uint32_t vendorId; - uint32_t deviceId; DevHandle handle; };