From 42cc85ddbca32307544953af4c8bceebb150029e Mon Sep 17 00:00:00 2001 From: "minjie.yu" Date: Mon, 1 Jul 2024 14:32:33 +0800 Subject: [PATCH] feat: hdf core compatible with linux-6.6 Signed-off-by: minjie.yu --- adapter/khdf/linux/model/usb/host/Makefile | 1 + .../model/usb/host/src/usb_net_adapter.c | 14 ++++++++ adapter/khdf/linux/osal/src/osal_cdev.c | 5 +++ adapter/khdf/linux/osal/src/osal_time.c | 2 +- .../khdf/linux/platform/fwk/platform_trace.c | 17 +++++++++ adapter/khdf/linux/platform/spi/spi_adapter.c | 12 +++++++ .../khdf/linux/platform/uart/uart_adapter.c | 36 +++++++++++++++++++ .../vibrator/driver/src/vibrator_haptic.c | 4 +-- 8 files changed, 88 insertions(+), 3 deletions(-) diff --git a/adapter/khdf/linux/model/usb/host/Makefile b/adapter/khdf/linux/model/usb/host/Makefile index 73bad22c9..752d295db 100644 --- a/adapter/khdf/linux/model/usb/host/Makefile +++ b/adapter/khdf/linux/model/usb/host/Makefile @@ -16,6 +16,7 @@ obj-$(CONFIG_DRIVERS_HDF_USB_PNP_NOTIFY) += \ obj-$(CONFIG_DRIVERS_HDF_USB_NET_ADAPTER) += \ $(USB_PNP_NOTIFY_ROOT_DIR)/src/usb_net_adapter.o +ccflags-y += -Wno-incompatible-pointer-types-discards-qualifiers ccflags-y += -lm -lc -lgcc \ -I$(srctree)/drivers/hdf/khdf/model/usb/host/include \ -I$(srctree)/drivers/hdf/framework/include/utils \ diff --git a/adapter/khdf/linux/model/usb/host/src/usb_net_adapter.c b/adapter/khdf/linux/model/usb/host/src/usb_net_adapter.c index c8280c890..b8957f550 100755 --- a/adapter/khdf/linux/model/usb/host/src/usb_net_adapter.c +++ b/adapter/khdf/linux/model/usb/host/src/usb_net_adapter.c @@ -26,7 +26,11 @@ #endif #include +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) #include +#else +#include +#endif #include "osal_mem.h" #include "securec.h" @@ -116,8 +120,13 @@ static void RxComplete(WorkStruct *work) stats64->tx_packets, stats64->tx_bytes); flags = u64_stats_update_begin_irqsave(&stats64->syncp); +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) stats64->rx_packets++; stats64->rx_bytes += usbNet->rxLen; +#else + u64_stats_inc(&stats64->rx_packets); + u64_stats_add(&stats64->rx_bytes, usbNet->rxLen); +#endif u64_stats_update_end_irqrestore(&stats64->syncp, flags); HARCH_NET_INFO_PRINT("rx_complete stats64->rx_packets = %lu,usbNet stats64->rx_bytes = %lu", @@ -544,8 +553,13 @@ static void TxComplete(WorkStruct *work) stats64->tx_packets, stats64->tx_bytes); flags = u64_stats_update_begin_irqsave(&stats64->syncp); +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) stats64->tx_packets++; stats64->tx_bytes += usbNet->txLen; +#else + u64_stats_inc(&stats64->tx_packets); + u64_stats_add(&stats64->tx_bytes, usbNet->txLen); +#endif u64_stats_update_end_irqrestore(&stats64->syncp, flags); HARCH_NET_INFO_PRINT ("tx_complete stats64->rx_packets = %lu,usbNet stats64->rx_bytes = %lu", diff --git a/adapter/khdf/linux/osal/src/osal_cdev.c b/adapter/khdf/linux/osal/src/osal_cdev.c index c1a05b8f3..6ca1f8188 100644 --- a/adapter/khdf/linux/osal/src/osal_cdev.c +++ b/adapter/khdf/linux/osal/src/osal_cdev.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "osal_cdev.h" #include "hdf_log.h" #include "osal_file.h" @@ -58,7 +59,11 @@ static const char* StringRfindChar(const char* str, char chr) return NULL; } +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) static char* hdfDevnode(struct device* dev, umode_t* mode) +#else +static char* hdfDevnode(const struct device* dev, unsigned short* mode) +#endif { (void)mode; return kasprintf(GFP_KERNEL, "hdf/%s", dev_name(dev)); diff --git a/adapter/khdf/linux/osal/src/osal_time.c b/adapter/khdf/linux/osal/src/osal_time.c index 20d121ecd..42e5cbbe3 100644 --- a/adapter/khdf/linux/osal/src/osal_time.c +++ b/adapter/khdf/linux/osal/src/osal_time.c @@ -98,7 +98,7 @@ void OsalMDelay(uint32_t ms) } EXPORT_SYMBOL(OsalMDelay); -uint64_t OsalGetSysTimeMs() +uint64_t OsalGetSysTimeMs(void) { OsalTimespec time; diff --git a/adapter/khdf/linux/platform/fwk/platform_trace.c b/adapter/khdf/linux/platform/fwk/platform_trace.c index 5436a7ee8..047d97017 100644 --- a/adapter/khdf/linux/platform/fwk/platform_trace.c +++ b/adapter/khdf/linux/platform/fwk/platform_trace.c @@ -17,7 +17,12 @@ #include "osal_file.h" #include "osal_mem.h" #include "securec.h" +#include +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) #include "stdarg.h" +#else +#include +#endif #include #include @@ -112,7 +117,9 @@ static ssize_t TraceFileWrite(OsalFile *file, const char *string, uint32_t lengt { ssize_t ret; loff_t pos; +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) mm_segment_t org_fs; +#endif struct file *fp = NULL; if (file == NULL || IS_ERR_OR_NULL(file->realFile) || string == NULL) { @@ -121,11 +128,15 @@ static ssize_t TraceFileWrite(OsalFile *file, const char *string, uint32_t lengt } fp = (struct file *)file->realFile; pos = fp->f_pos; +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) org_fs = get_fs(); set_fs(KERNEL_DS); +#endif ret = vfs_write(fp, string, length, &pos); +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) set_fs(org_fs); +#endif if (ret < 0) { HDF_LOGE("TraceFileWrite: write file length %d fail, ret: %d!", length, ret); return HDF_FAILURE; @@ -137,7 +148,9 @@ static ssize_t TraceFileWrite(OsalFile *file, const char *string, uint32_t lengt static ssize_t TraceFileRead(OsalFile *file, char *buf, uint32_t length) { ssize_t ret; +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) mm_segment_t org_fs; +#endif loff_t pos; struct file *fp = NULL; @@ -146,12 +159,16 @@ static ssize_t TraceFileRead(OsalFile *file, char *buf, uint32_t length) return HDF_ERR_INVALID_PARAM; } fp = (struct file *)file->realFile; +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) org_fs = get_fs(); set_fs(KERNEL_DS); +#endif pos = fp->f_pos; ret = vfs_read(fp, buf, length, &pos); +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) set_fs(org_fs); +#endif if (ret < 0) { HDF_LOGE("TraceFileRead: read file length %d fail, ret: %d!", length, ret); return HDF_FAILURE; diff --git a/adapter/khdf/linux/platform/spi/spi_adapter.c b/adapter/khdf/linux/platform/spi/spi_adapter.c index ba598a5d3..dd1bc43ea 100644 --- a/adapter/khdf/linux/platform/spi/spi_adapter.c +++ b/adapter/khdf/linux/platform/spi/spi_adapter.c @@ -173,7 +173,12 @@ static int32_t SpiAdapterTransferOneMsg(struct SpiCntlr *cntlr, struct SpiMsg *m transfer->len = msg->len; transfer->speed_hz = msg->speed; transfer->cs_change = msg->keepCs; // yes! cs_change will keep the last cs active ... +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) transfer->delay_usecs = msg->delayUs; +#else + transfer->delay.value = msg->delayUs; + transfer->delay.unit = SPI_DELAY_UNIT_USECS; +#endif spi_message_add_tail(transfer, &xfer); ret = spi_sync(dev->priv, &xfer); @@ -235,8 +240,15 @@ static int32_t SpiAdapterTransferDifferent(struct SpiCntlr *cntlr, struct SpiMsg transfer[i].speed_hz = msg[i].speed; if (msg[i].keepCs != 0) transfer[i].cs_change = msg[i].keepCs; +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) if (msg[i].delayUs != 0) transfer[i].delay_usecs = msg[i].delayUs; +#else + if (msg[i].delayUs != 0) { + transfer[i].delay.value = msg[i].delayUs; + transfer[i].delay.unit = SPI_DELAY_UNIT_USECS; + } +#endif spi_message_add_tail(&transfer[i], &xfer); } diff --git a/adapter/khdf/linux/platform/uart/uart_adapter.c b/adapter/khdf/linux/platform/uart/uart_adapter.c index e8bac7820..89af4e0aa 100644 --- a/adapter/khdf/linux/platform/uart/uart_adapter.c +++ b/adapter/khdf/linux/platform/uart/uart_adapter.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "device_resource_if.h" #include "hdf_base.h" #include "hdf_log.h" @@ -40,7 +41,9 @@ static int32_t UartAdapterInit(struct UartHost *host) { char name[UART_PATHNAME_LEN] = {0}; struct file *fp = NULL; +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) mm_segment_t oldfs; +#endif if (host == NULL) { HDF_LOGE("UartAdapterInit: host is null!"); @@ -49,15 +52,21 @@ static int32_t UartAdapterInit(struct UartHost *host) if (sprintf_s(name, UART_PATHNAME_LEN - 1, "/dev/%s%d", g_driverName, host->num) < 0) { return HDF_FAILURE; } +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) oldfs = get_fs(); set_fs(KERNEL_DS); +#endif fp = filp_open(name, O_RDWR | O_NOCTTY | O_NDELAY, 0600); /* 0600 : file mode */ if (IS_ERR(fp)) { HDF_LOGE("UartAdapterInit: filp_open %s fail!", name); +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) set_fs(oldfs); +#endif return HDF_FAILURE; } +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) set_fs(oldfs); +#endif host->priv = fp; return HDF_SUCCESS; } @@ -65,19 +74,26 @@ static int32_t UartAdapterInit(struct UartHost *host) static int32_t UartAdapterDeInit(struct UartHost *host) { struct file *fp = NULL; +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) mm_segment_t oldfs; +#endif if (host == NULL) { HDF_LOGE("UartAdapterDeInit: host is null!"); return HDF_ERR_INVALID_OBJECT; } + fp = (struct file *)host->priv; +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) oldfs = get_fs(); set_fs(KERNEL_DS); +#endif if (!IS_ERR(fp) && fp) { filp_close(fp, NULL); } +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) set_fs(oldfs); +#endif host->priv = NULL; return HDF_SUCCESS; } @@ -88,7 +104,9 @@ static int32_t UartAdapterRead(struct UartHost *host, uint8_t *data, uint32_t si int ret; struct file *fp = NULL; char *p = (char *)data; +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) mm_segment_t oldfs; +#endif uint32_t tmp = 0; if (host == NULL || host->priv == NULL || data == NULL || size == 0) { @@ -97,8 +115,10 @@ static int32_t UartAdapterRead(struct UartHost *host, uint8_t *data, uint32_t si } fp = (struct file *)host->priv; +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) oldfs = get_fs(); set_fs(KERNEL_DS); +#endif while (size >= tmp) { ret = vfs_read(fp, p + tmp, 1, &pos); if (ret < 0) { @@ -107,7 +127,9 @@ static int32_t UartAdapterRead(struct UartHost *host, uint8_t *data, uint32_t si } tmp++; } +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) set_fs(oldfs); +#endif return tmp; } @@ -117,7 +139,9 @@ static int32_t UartAdapterWrite(struct UartHost *host, uint8_t *data, uint32_t s int ret; struct file *fp = NULL; char *p = (char *)data; +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) mm_segment_t oldfs; +#endif if (host == NULL || host->priv == NULL || data == NULL || size == 0) { HDF_LOGE("UartAdapterWrite: invalid parameters!"); @@ -125,33 +149,45 @@ static int32_t UartAdapterWrite(struct UartHost *host, uint8_t *data, uint32_t s } fp = (struct file *)host->priv; +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) oldfs = get_fs(); set_fs(KERNEL_DS); +#endif ret = vfs_write(fp, p, size, &pos); if (ret < 0) { HDF_LOGE("UartAdapterWrite: vfs_write fail, ret: %d!", ret); +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) set_fs(oldfs); +#endif return HDF_FAILURE; } +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) set_fs(oldfs); +#endif return HDF_SUCCESS; } static int UartAdapterIoctlInner(struct file *fp, unsigned cmd, unsigned long arg) { int ret = HDF_FAILURE; +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) mm_segment_t oldfs; +#endif if (fp == NULL) { HDF_LOGE("UartAdapterIoctlInner: fp is null!"); return HDF_FAILURE; } +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) oldfs = get_fs(); set_fs(KERNEL_DS); +#endif if (fp->f_op->unlocked_ioctl != NULL) { ret = fp->f_op->unlocked_ioctl(fp, cmd, arg); } +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0) set_fs(oldfs); +#endif return ret; } diff --git a/framework/model/misc/vibrator/driver/src/vibrator_haptic.c b/framework/model/misc/vibrator/driver/src/vibrator_haptic.c index 6a486a6ad..9caff32ee 100644 --- a/framework/model/misc/vibrator/driver/src/vibrator_haptic.c +++ b/framework/model/misc/vibrator/driver/src/vibrator_haptic.c @@ -324,7 +324,7 @@ int32_t StartHaptic(struct VibratorEffectCfg *effectCfg) return HDF_SUCCESS; } -int32_t StopHaptic() +int32_t StopHaptic(void) { int32_t ret; struct VibratorHapticData *hapticData = GetHapticData(); @@ -398,7 +398,7 @@ static void FreeHapticConfig(void) (void)OsalMutexUnlock(&hapticData->mutex); } -int32_t DestroyVibratorHaptic() +int32_t DestroyVibratorHaptic(void) { struct VibratorHapticData *hapticData = GetHapticData(); CHECK_VIBRATOR_NULL_PTR_RETURN_VALUE(hapticData, HDF_FAILURE); -- Gitee