diff --git a/XVSEC/linux-kernel/drv/Makefile b/XVSEC/linux-kernel/drv/Makefile index 6e1a1b7f..570f2228 100644 --- a/XVSEC/linux-kernel/drv/Makefile +++ b/XVSEC/linux-kernel/drv/Makefile @@ -23,13 +23,13 @@ all: make -C /lib/modules/$(XVSEC_KVER)/build M=$(XVSEC_HOME) modules @mv *.ko $(module_path)/ @cp xvsec_drv.h $(module_path)/ + @cp xvsec_drv_int.h $(module_path)/ @cp ./xvsec_mcap/xvsec_mcap.h $(module_path)/ @mv *.o $(module_path)/obj/ @mv .*cmd $(module_path)/obj/ @mv *.symvers $(module_path)/obj/ @mv *.mod* $(module_path)/obj/ @mv *.order* $(module_path)/obj/ - @mv .tmp* $(module_path)/obj/ @mv ./xvsec_mcap/*.o $(module_path)/obj/xvsec_mcap/ @mv ./xvsec_mcap/us/*.o $(module_path)/obj/xvsec_mcap/us/ @mv ./xvsec_mcap/versal/*.o $(module_path)/obj/xvsec_mcap/versal/ diff --git a/XVSEC/linux-kernel/drv/xvsec_cdev.c b/XVSEC/linux-kernel/drv/xvsec_cdev.c index 5ff1aad2..a4d728a3 100644 --- a/XVSEC/linux-kernel/drv/xvsec_cdev.c +++ b/XVSEC/linux-kernel/drv/xvsec_cdev.c @@ -32,8 +32,6 @@ #include #include #include -#include -#include #include "xvsec_drv.h" #include "xvsec_drv_int.h" diff --git a/XVSEC/linux-kernel/drv/xvsec_drv.c b/XVSEC/linux-kernel/drv/xvsec_drv.c index 64d4b84c..0146ca2e 100644 --- a/XVSEC/linux-kernel/drv/xvsec_drv.c +++ b/XVSEC/linux-kernel/drv/xvsec_drv.c @@ -32,9 +32,6 @@ #include #include #include -#include -#include - #include "version.h" #include "xvsec_drv.h" @@ -361,7 +358,7 @@ static const struct file_operations xvsec_gen_fops = { }; -static int xvsec_initialize(struct pci_dev *pdev, struct context *dev_ctx) +int xvsec_initialize(struct pci_dev *pdev, struct context *dev_ctx) { int ret = 0; int status; @@ -405,7 +402,7 @@ static int xvsec_initialize(struct pci_dev *pdev, struct context *dev_ctx) } EXPORT_SYMBOL_GPL(xvsec_initialize); -static int xvsec_deinitialize(struct context *dev_ctx) +int xvsec_deinitialize(struct context *dev_ctx) { int ret = 0; uint16_t index; @@ -456,7 +453,11 @@ static int __init xvsec_drv_init(void) if (dev_count == 0) return 0; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0) + g_xvsec_class = class_create(XVSEC_NODE_NAME); +#else g_xvsec_class = class_create(THIS_MODULE, XVSEC_NODE_NAME); +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0) */ if (IS_ERR(g_xvsec_class)) { pr_err("failed to create class"); ret = -(PTR_ERR(g_xvsec_class)); diff --git a/XVSEC/linux-kernel/drv/xvsec_drv_int.h b/XVSEC/linux-kernel/drv/xvsec_drv_int.h index 2d17240d..ef3cbab7 100644 --- a/XVSEC/linux-kernel/drv/xvsec_drv_int.h +++ b/XVSEC/linux-kernel/drv/xvsec_drv_int.h @@ -114,4 +114,7 @@ extern struct class *g_xvsec_class; int xvsec_mcap_module_init(struct vsec_context *dev_ctx); void xvsec_mcap_module_exit(struct vsec_context *dev_ctx); +extern int xvsec_initialize(struct pci_dev *, struct context *); +extern int xvsec_deinitialize(struct context *); + #endif /* __XVSEC_DRV_INT_H__ */ diff --git a/XVSEC/linux-kernel/drv/xvsec_mcap/us/xvsec_mcap_us.c b/XVSEC/linux-kernel/drv/xvsec_mcap/us/xvsec_mcap_us.c index 81cb53de..6e560671 100644 --- a/XVSEC/linux-kernel/drv/xvsec_mcap/us/xvsec_mcap_us.c +++ b/XVSEC/linux-kernel/drv/xvsec_mcap/us/xvsec_mcap_us.c @@ -32,8 +32,6 @@ #include #include #include -#include -#include #include "xvsec_util.h" #include "xvsec_drv.h" diff --git a/XVSEC/linux-kernel/drv/xvsec_mcap/versal/xvsec_mcap_versal.c b/XVSEC/linux-kernel/drv/xvsec_mcap/versal/xvsec_mcap_versal.c index 5827f82b..ee44c2a6 100644 --- a/XVSEC/linux-kernel/drv/xvsec_mcap/versal/xvsec_mcap_versal.c +++ b/XVSEC/linux-kernel/drv/xvsec_mcap/versal/xvsec_mcap_versal.c @@ -33,8 +33,6 @@ #include #include #include -#include -#include #include "xvsec_drv.h" #include "xvsec_drv_int.h" diff --git a/XVSEC/linux-kernel/drv/xvsec_mcap/xvsec_mcap.c b/XVSEC/linux-kernel/drv/xvsec_mcap/xvsec_mcap.c index 0d898e86..b88dc44b 100644 --- a/XVSEC/linux-kernel/drv/xvsec_mcap/xvsec_mcap.c +++ b/XVSEC/linux-kernel/drv/xvsec_mcap/xvsec_mcap.c @@ -32,8 +32,6 @@ #include #include #include -#include -#include #include "xvsec_drv.h" #include "xvsec_drv_int.h" diff --git a/XVSEC/linux-kernel/drv/xvsec_util.c b/XVSEC/linux-kernel/drv/xvsec_util.c index ff16de80..88071663 100644 --- a/XVSEC/linux-kernel/drv/xvsec_util.c +++ b/XVSEC/linux-kernel/drv/xvsec_util.c @@ -32,8 +32,8 @@ #include #include #include -#include -#include +#include +#include #include "xvsec_util.h" @@ -63,13 +63,21 @@ int xvsec_util_find_file_type(char *fname, const char *suffix) struct file *xvsec_util_fopen(const char *path, int flags, int rights) { struct file *filep; - mm_segment_t oldfs; int err = 0; +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0) + mm_segment_t oldfs; + oldfs = get_fs(); set_fs(KERNEL_DS); +#endif + filep = filp_open(path, (flags | O_LARGEFILE), rights); + +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0) set_fs(oldfs); +#endif + if (IS_ERR(filep) != 0) { err = PTR_ERR(filep); pr_err("%s : filp_open failed, err : 0x%X\n", __func__, err); @@ -87,17 +95,24 @@ int xvsec_util_fread(struct file *filep, uint64_t offset, uint8_t *data, uint32_t size) { int ret = 0; + +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0) mm_segment_t oldfs; oldfs = get_fs(); set_fs(KERNEL_DS); +#endif + #if KERNEL_VERSION(4, 14, 0) > LINUX_VERSION_CODE ret = vfs_read(filep, (char __user *)data, size, (loff_t *)&offset); #else ret = kernel_read(filep, (void *)data, size, (loff_t *)&offset); #endif filep->f_pos = offset; + +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0) set_fs(oldfs); +#endif if (ret < 0) { #if KERNEL_VERSION(4, 14, 0) > LINUX_VERSION_CODE @@ -117,10 +132,14 @@ int xvsec_util_fwrite(struct file *filep, uint64_t offset, uint8_t *data, uint32_t size) { int ret = 0; + +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0) mm_segment_t oldfs; oldfs = get_fs(); set_fs(KERNEL_DS); +#endif + #if KERNEL_VERSION(4, 14, 0) > LINUX_VERSION_CODE ret = vfs_write(filep, (char __user *)data, size, (loff_t *)&offset); #else @@ -128,7 +147,10 @@ int xvsec_util_fwrite(struct file *filep, uint64_t offset, (loff_t *)&offset); #endif filep->f_pos = offset; + +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0) set_fs(oldfs); +#endif if (ret < 0) { #if KERNEL_VERSION(4, 14, 0) > LINUX_VERSION_CODE @@ -151,15 +173,19 @@ int xvsec_util_fsync(struct file *filep) int xvsec_util_get_file_size(const char *fname, loff_t *size) { int ret = 0; - mm_segment_t oldfs; struct kstat stat; +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0) + mm_segment_t oldfs; + oldfs = get_fs(); set_fs(KERNEL_DS); memset(&stat, 0, sizeof(struct kstat)); + ret = vfs_stat((char __user *)fname, &stat); set_fs(oldfs); + if (ret < 0) { pr_err("%s : vfs_stat failed with error : %d\n", __func__, ret); return -(EIO); @@ -167,6 +193,29 @@ int xvsec_util_get_file_size(const char *fname, loff_t *size) *size = stat.size; +#else + + struct path path; + + memset(&stat, 0, sizeof(struct kstat)); + + ret = kern_path(fname, LOOKUP_FOLLOW, &path); + if (ret){ + pr_err("%s : kern_path failed with error : %d\n", __func__, ret); + return -(EIO); + } + + ret = vfs_getattr(&path, &stat, STATX_TYPE, AT_STATX_SYNC_AS_STAT); + path_put(&path); + if (ret){ + pr_err("%s : vfs_getattr failed with error : %d\n", __func__, ret); + return -(EIO); + } + + *size = stat.size; + +#endif + return ret; }