Skip to content
Snippets Groups Projects
Commit 1d4ad17a authored by Jonathan Hanks's avatar Jonathan Hanks
Browse files

Updates to gpstime/mbuf code to build on 5.10.x kernels.

 * Use the proper version of ioremap for each kernel version.
 * Use a 64bit time call in newer kernels.
 * Only use unlocked ioctls as the interface in the mbuf/gpstime code.
parent 94ea529c
No related branches found
No related tags found
1 merge request!283Updates to gpstime/mbuf code to build on 5.10.x kernels.
......@@ -27,7 +27,7 @@ SYMVERSDIR := /var/cache/$(MODULENAME)
ifeq ($(KERNELRELEASE),)
#all: $(MODULENAME)_test
all:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
$(MAKE) -C $(KDIR) M=$(PWD) modules
else
obj-m := $(MODULENAME).o
endif
......
......@@ -13,6 +13,7 @@
#include <linux/kernel.h>
#include <linux/kobject.h>
#include <linux/sysfs.h>
#include <linux/time.h>
#include <linux/device.h>
#include <linux/types.h>
......@@ -32,6 +33,10 @@
#include "../../include/drv/cdsHardware.h"
#include "../../include/proc.h"
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0)
#error "This kernel version is no longer supported"
#endif
CDS_HARDWARE cdsPciModules;
#define IN_LIGO_GPS_KERNEL_DRIVER 1
......@@ -42,6 +47,8 @@ CDS_HARDWARE cdsPciModules;
#define CDS_LOCAL_GPS_BUFFER_SIZE 30
/* /proc/gps entry */
struct proc_dir_entry *proc_gps_entry;
/* /proc/gps_offset entry */
......@@ -63,21 +70,13 @@ static int card_type; /* 0 - symmetricom; 1 - spectracom */
/* methods of the character device */
static int symmetricom_open(struct inode *inode, struct file *filp);
static int symmetricom_release(struct inode *inode, struct file *filp);
#ifdef HAVE_UNLOCKED_IOCTL
static long symmetricom_ioctl(struct file *inode, unsigned int cmd, unsigned long arg);
#else
static int symmetricom_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg);
#endif
/* the file operations, i.e. all character device methods */
static struct file_operations symmetricom_fops = {
.open = symmetricom_open,
.release = symmetricom_release,
#ifdef HAVE_UNLOCKED_IOCTL
.unlocked_ioctl = symmetricom_ioctl,
#else
.ioctl = symmetricom_ioctl,
#endif
.owner = THIS_MODULE,
};
......@@ -94,6 +93,22 @@ static int symmetricom_release(struct inode *inode, struct file *filp)
return 0;
}
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 18, 0)
#define LIGO_TIMESPEC struct timespec
static inline void ligo_get_current_kernel_time(LIGO_TIMESPEC *t)
{
*t = current_kernel_time();
}
#else
#define LIGO_TIMESPEC struct timespec64
static inline void ligo_get_current_kernel_time(LIGO_TIMESPEC* t)
{
ktime_get_coarse_real_ts64(t);
}
#endif
// Read current GPS time from the card
int get_cur_time(unsigned long *req) {
long offset = 0;
......@@ -114,11 +129,9 @@ int get_cur_time(unsigned long *req) {
sync = lptc_get_gps_time(&cdsPciModules, &timeSec, &timeUsec);
req[0] = timeSec; req[1] = timeUsec; req[2] = 0;
} else {
// Get current kernel time (in GPS)
struct timespec t;
extern struct timespec current_kernel_time(void);
t = current_kernel_time();
//t.tv_sec += - 315964819 + 37;
// Get current kernel time (in GPS)
LIGO_TIMESPEC t;
ligo_get_current_kernel_time(&t);
req[0] = t.tv_sec; req[1] = t.tv_nsec/1000; req[2] = t.tv_nsec%1000;
sync = 1;
}
......@@ -126,11 +139,7 @@ int get_cur_time(unsigned long *req) {
return sync;
}
#ifdef HAVE_UNLOCKED_IOCTL
static long symmetricom_ioctl(struct file *inode, unsigned int cmd, unsigned long arg)
#else
static int symmetricom_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
#endif
{
unsigned long req[3];
unsigned long res = 0;
......@@ -169,14 +178,22 @@ static int gps_open(struct inode *inode, struct file *file)
return single_open(file, gps_seq_show, NULL);
}
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
static struct file_operations gps_file_ops = {
.owner = THIS_MODULE,
.open = gps_open,
.read = seq_read,
.llseek = seq_lseek,
// .release = seq_release
.release = single_release
.owner = THIS_MODULE,
.open = gps_open,
.read = seq_read,
.llseek = seq_lseek,
.proc_release = single_release
};
#else
static struct proc_ops gps_file_ops = {
.proc_open = gps_open,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_release = single_release
};
#endif
/* The output buffer provided to all sysfs calls here is PAGE_SIZED (ie typically 4k bytes) */
......
......@@ -27,7 +27,7 @@ SYMVERSDIR := /var/cache/$(MODULENAME)
ifeq ($(KERNELRELEASE),)
#all: $(MODULENAME)_test
all:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
$(MAKE) -C $(KDIR) M=$(PWD) modules
else
obj-m := $(MODULENAME).o
endif
......
......@@ -30,6 +30,10 @@
#include "kvmem.c"
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0)
#error "This kernel version is no longer supported"
#endif
/* Set if the allocated memory filled in with one-bits */
static short int one_fill = 0;
......@@ -51,22 +55,14 @@ atomic_t mbuf_verbosity = ATOMIC_INIT(0);
static int mbuf_open(struct inode *inode, struct file *filp);
static int mbuf_release(struct inode *inode, struct file *filp);
static int mbuf_mmap(struct file *filp, struct vm_area_struct *vma);
#if HAVE_UNLOCKED_IOCTL
static long mbuf_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
#else
static int mbuf_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg);
#endif
/* the file operations, i.e. all character device methods */
static struct file_operations mbuf_fops = {
.open = mbuf_open,
.release = mbuf_release,
.mmap = mbuf_mmap,
#if HAVE_UNLOCKED_IOCTL
.unlocked_ioctl = mbuf_ioctl,
#else
.ioctl = mbuf_ioctl,
#endif
.unlocked_ioctl = mbuf_ioctl,
.owner = THIS_MODULE,
};
......@@ -309,11 +305,8 @@ static int mbuf_mmap(struct file *file, struct vm_area_struct *vma)
}
#if HAVE_UNLOCKED_IOCTL
static long mbuf_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
#else
static int mbuf_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
#endif
{
int res;
int mod = 0;
......
/*
* The ioremap call changes names.
*
* In 5.10 we use ioremap, in older versions we use ioremap_nocache
*/
#ifndef ADVLIGORTS_LIGO_IOREMAP_H
#define ADVLIGORTS_LIGO_IOREMAP_H
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
#define LIGO_IOREMAP ioremap_nocache
#else
#define LIGO_IOREMAP ioremap
#endif
#endif /* ADVLIGORTS_LIGO_IOREMAP_H */
......@@ -8,6 +8,7 @@
///< TSync-PCIe Manual</a>
#include "spectracomGPS.h"
#include "ligo_ioremap.h"
// *****************************************************************************
/// \brief Initialize TSYNC GPS card (model BC635PCI-U)
......@@ -40,7 +41,7 @@ spectracomGpsInitCheckSync( CDS_HARDWARE* pHardware,
pci_io_addr &= 0xfffffff0;
printk( "TSYNC PIC BASE 0 address = %x\n", pci_io_addr );
addr1 = (unsigned char*)ioremap_nocache( (unsigned long)pci_io_addr, 0x30 );
addr1 = (unsigned char*)LIGO_IOREMAP( (unsigned long)pci_io_addr, 0x30 );
printk( "Remapped 0x%p\n", addr1 );
pHardware->gps = (unsigned int*)addr1;
pHardware->gpsType = TSYNC_RCVR;
......
#include "symmetricomGps.h"
#include "ligo_ioremap.h"
// *****************************************************************************
/// Initialize Symmetricom GPS card (model BC635PCI-U)
......@@ -21,7 +22,7 @@ symmetricomGpsInit( CDS_HARDWARE* pHardware, struct pci_dev* gpsdev )
pci_io_addr &= 0xfffffff0;
printk( "PIC BASE 2 address = %x\n", pci_io_addr );
addr1 = (unsigned char*)ioremap_nocache( (unsigned long)pci_io_addr, 0x40 );
addr1 = (unsigned char*)LIGO_IOREMAP( (unsigned long)pci_io_addr, 0x40 );
printk( "Remapped 0x%p\n", addr1 );
pHardware->gps = (unsigned int*)addr1;
pHardware->gpsType = SYMCOM_RCVR;
......@@ -31,7 +32,7 @@ symmetricomGpsInit( CDS_HARDWARE* pHardware, struct pci_dev* gpsdev )
pci_read_config_dword( gpsdev, PCI_BASE_ADDRESS_3, &pci_io_addr );
pci_io_addr &= 0xfffffff0;
addr3 =
(unsigned char*)ioremap_nocache( (unsigned long)pci_io_addr, 0x200 );
(unsigned char*)LIGO_IOREMAP( (unsigned long)pci_io_addr, 0x200 );
printk( "PIC BASE 3 address = 0x%x\n", pci_io_addr );
printk( "PIC BASE 3 address = 0x%p\n", addr3 );
dramRead = (unsigned int*)( addr3 + 0x82 );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment