From 823973407906c4f3e9d7bf700d7829dc54daadc2 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Sat, 17 Jun 2017 22:52:23 +0000 Subject: Remove prototypes for unimplemented LinuxKPI functions. MFC after: 1 week --- sys/compat/linuxkpi/common/include/linux/mm.h | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'sys/compat/linuxkpi/common/include') diff --git a/sys/compat/linuxkpi/common/include/linux/mm.h b/sys/compat/linuxkpi/common/include/linux/mm.h index 6f67a0ba4b41..c2ccb4cb96ad 100644 --- a/sys/compat/linuxkpi/common/include/linux/mm.h +++ b/sys/compat/linuxkpi/common/include/linux/mm.h @@ -257,16 +257,6 @@ vm_get_page_prot(unsigned long vm_flags) return (vm_flags & VM_PROT_ALL); } -extern int vm_insert_mixed(struct vm_area_struct *, unsigned long addr, pfn_t pfn); - -extern int -vm_insert_pfn(struct vm_area_struct *, unsigned long addr, - unsigned long pfn); - -extern int -vm_insert_pfn_prot(struct vm_area_struct *, unsigned long addr, - unsigned long pfn, pgprot_t pgprot); - static inline vm_page_t vmalloc_to_page(const void *addr) { -- cgit v1.2.3 From 4eb18346d1cd36edd593cd9b49f6095549910ef2 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Sun, 18 Jun 2017 16:43:57 +0000 Subject: Avoid including list.h in LinuxKPI headers. list.h includes a number of FreeBSD headers as a workaround for the LIST_HEAD name collision. To reduce pollution, avoid including list.h in commonly used headers when it is not explicitly needed. Reviewed by: hselasky MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D11249 --- sys/compat/linuxkpi/common/include/linux/completion.h | 1 - sys/compat/linuxkpi/common/include/linux/kernel.h | 1 - sys/compat/linuxkpi/common/include/linux/kobject.h | 1 + sys/compat/linuxkpi/common/include/linux/mm_types.h | 1 - sys/compat/linuxkpi/common/include/linux/sched.h | 1 - 5 files changed, 1 insertion(+), 4 deletions(-) (limited to 'sys/compat/linuxkpi/common/include') diff --git a/sys/compat/linuxkpi/common/include/linux/completion.h b/sys/compat/linuxkpi/common/include/linux/completion.h index 73c1a99dfc44..92ccc61f38da 100644 --- a/sys/compat/linuxkpi/common/include/linux/completion.h +++ b/sys/compat/linuxkpi/common/include/linux/completion.h @@ -32,7 +32,6 @@ #define _LINUX_COMPLETION_H_ #include -#include struct completion { unsigned int done; diff --git a/sys/compat/linuxkpi/common/include/linux/kernel.h b/sys/compat/linuxkpi/common/include/linux/kernel.h index 3631ba5f2428..b8d2bd3b66a5 100644 --- a/sys/compat/linuxkpi/common/include/linux/kernel.h +++ b/sys/compat/linuxkpi/common/include/linux/kernel.h @@ -49,7 +49,6 @@ #include #include #include -#include #include #include diff --git a/sys/compat/linuxkpi/common/include/linux/kobject.h b/sys/compat/linuxkpi/common/include/linux/kobject.h index a000c4eebc10..261f35539469 100644 --- a/sys/compat/linuxkpi/common/include/linux/kobject.h +++ b/sys/compat/linuxkpi/common/include/linux/kobject.h @@ -35,6 +35,7 @@ #include #include +#include #include struct kobject; diff --git a/sys/compat/linuxkpi/common/include/linux/mm_types.h b/sys/compat/linuxkpi/common/include/linux/mm_types.h index 6b13dfd9b62c..44aad34c9ba2 100644 --- a/sys/compat/linuxkpi/common/include/linux/mm_types.h +++ b/sys/compat/linuxkpi/common/include/linux/mm_types.h @@ -30,7 +30,6 @@ #define _LINUX_MM_TYPES_H_ #include -#include #include #include diff --git a/sys/compat/linuxkpi/common/include/linux/sched.h b/sys/compat/linuxkpi/common/include/linux/sched.h index 01d44a0ce1e7..da30db96d6b1 100644 --- a/sys/compat/linuxkpi/common/include/linux/sched.h +++ b/sys/compat/linuxkpi/common/include/linux/sched.h @@ -37,7 +37,6 @@ #include #include -#include #include #include #include -- cgit v1.2.3 From 8504aa98527b7f2078980ec5b650a06063bf079a Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Sun, 18 Jun 2017 19:22:05 +0000 Subject: Add kthread parking support to the LinuxKPI. Submitted by: kmacy (original version) Reviewed by: hselasky MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D11264 --- sys/compat/linuxkpi/common/include/linux/kthread.h | 31 +++++++++++++++------- sys/compat/linuxkpi/common/include/linux/sched.h | 1 + 2 files changed, 22 insertions(+), 10 deletions(-) (limited to 'sys/compat/linuxkpi/common/include') diff --git a/sys/compat/linuxkpi/common/include/linux/kthread.h b/sys/compat/linuxkpi/common/include/linux/kthread.h index 8c7e3c899829..3afd21dc9356 100644 --- a/sys/compat/linuxkpi/common/include/linux/kthread.h +++ b/sys/compat/linuxkpi/common/include/linux/kthread.h @@ -48,15 +48,26 @@ __task; \ }) -#define in_atomic() ({ \ - linux_in_atomic(); \ -}) +int linux_kthread_stop(struct task_struct *); +bool linux_kthread_should_stop_task(struct task_struct *); +bool linux_kthread_should_stop(void); +int linux_kthread_park(struct task_struct *); +void linux_kthread_parkme(void); +bool linux_kthread_should_park(void); +void linux_kthread_unpark(struct task_struct *); +void linux_kthread_fn(void *); +struct task_struct *linux_kthread_setup_and_run(struct thread *, + linux_task_fn_t *, void *arg); +int linux_in_atomic(void); + +#define kthread_stop(task) linux_kthread_stop(task) +#define kthread_should_stop() linux_kthread_should_stop() +#define kthread_should_stop_task(task) linux_kthread_should_stop_task(task) +#define kthread_park(task) linux_kthread_park(task) +#define kthread_parkme() linux_kthread_parkme() +#define kthread_should_park() linux_kthread_should_park() +#define kthread_unpark(task) linux_kthread_unpark(task) -extern int kthread_stop(struct task_struct *); -extern bool kthread_should_stop_task(struct task_struct *); -extern bool kthread_should_stop(void); -extern void linux_kthread_fn(void *); -extern struct task_struct *linux_kthread_setup_and_run(struct thread *, linux_task_fn_t *, void *arg); -extern int linux_in_atomic(void); +#define in_atomic() linux_in_atomic() -#endif /* _LINUX_KTHREAD_H_ */ +#endif /* _LINUX_KTHREAD_H_ */ diff --git a/sys/compat/linuxkpi/common/include/linux/sched.h b/sys/compat/linuxkpi/common/include/linux/sched.h index da30db96d6b1..589c0f1e50db 100644 --- a/sys/compat/linuxkpi/common/include/linux/sched.h +++ b/sys/compat/linuxkpi/common/include/linux/sched.h @@ -54,6 +54,7 @@ #define TASK_UNINTERRUPTIBLE 0x0002 #define TASK_NORMAL (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE) #define TASK_WAKING 0x0100 +#define TASK_PARKED 0x0200 struct task_struct { struct thread *task_thread; -- cgit v1.2.3 From 33baed94529437329816a7c982dc66c8fee9bdef Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Wed, 21 Jun 2017 18:08:36 +0000 Subject: Add a lockdep macro to the LinuxKPI. Also fix some nearby style issues. MFC after: 1 week --- sys/compat/linuxkpi/common/include/linux/lockdep.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'sys/compat/linuxkpi/common/include') diff --git a/sys/compat/linuxkpi/common/include/linux/lockdep.h b/sys/compat/linuxkpi/common/include/linux/lockdep.h index 27386935bbe6..065399fa44ad 100644 --- a/sys/compat/linuxkpi/common/include/linux/lockdep.h +++ b/sys/compat/linuxkpi/common/include/linux/lockdep.h @@ -28,14 +28,18 @@ * * $FreeBSD$ */ -#ifndef _LINUX_LOCKDEP_H_ + +#ifndef _LINUX_LOCKDEP_H_ #define _LINUX_LOCKDEP_H_ struct lock_class_key { }; -#define lockdep_set_class(lock, key) +#define lockdep_set_class(lock, key) + +#define lockdep_set_class_and_name(lock, key, name) -#define lockdep_set_class_and_name(lock, key, name) +#define lockdep_assert_held_once(m) \ + sx_assert(&(m)->sx, SA_XLOCKED | SA_NOTRECURSED) -#endif /* _LINUX_LOCKDEP_H_ */ +#endif /* _LINUX_LOCKDEP_H_ */ -- cgit v1.2.3 From 9b6197df697fcc27c82c2f3c184eb9e04456202b Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Wed, 21 Jun 2017 18:15:47 +0000 Subject: Include kmod.h from the LinuxKPI's module.h. MFC after: 1 week --- sys/compat/linuxkpi/common/include/linux/module.h | 1 + 1 file changed, 1 insertion(+) (limited to 'sys/compat/linuxkpi/common/include') diff --git a/sys/compat/linuxkpi/common/include/linux/module.h b/sys/compat/linuxkpi/common/include/linux/module.h index 59c30a7ab77c..13e5e0012d82 100644 --- a/sys/compat/linuxkpi/common/include/linux/module.h +++ b/sys/compat/linuxkpi/common/include/linux/module.h @@ -37,6 +37,7 @@ #include #include +#include #include #include #include -- cgit v1.2.3 From c73cdca2c407612e3d6cae81e5aa8ae5c1786e1c Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Wed, 21 Jun 2017 18:20:17 +0000 Subject: Update io-mapping.h in the LinuxKPI. Add io_mapping_init_wc() and add a third (unused) parameter to io_mapping_map_wc(). Reviewed by: hselasky MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D11286 --- .../linuxkpi/common/include/linux/io-mapping.h | 53 ++++++++++++++++++---- 1 file changed, 43 insertions(+), 10 deletions(-) (limited to 'sys/compat/linuxkpi/common/include') diff --git a/sys/compat/linuxkpi/common/include/linux/io-mapping.h b/sys/compat/linuxkpi/common/include/linux/io-mapping.h index 8650dba65e6b..7c92c50d637a 100644 --- a/sys/compat/linuxkpi/common/include/linux/io-mapping.h +++ b/sys/compat/linuxkpi/common/include/linux/io-mapping.h @@ -28,52 +28,85 @@ * * $FreeBSD$ */ -#ifndef _LINUX_IO_MAPPING_H_ + +#ifndef _LINUX_IO_MAPPING_H_ #define _LINUX_IO_MAPPING_H_ +#include +#include + #include #include +#include -struct io_mapping; +struct io_mapping { + unsigned long base; + unsigned long size; + void *mem; + vm_memattr_t attr; +}; + +static inline struct io_mapping * +io_mapping_init_wc(struct io_mapping *mapping, resource_size_t base, + unsigned long size) +{ + + mapping->base = base; + mapping->size = size; + mapping->mem = ioremap_wc(base, size); + mapping->attr = VM_MEMATTR_WRITE_COMBINING; + return (mapping); +} static inline struct io_mapping * io_mapping_create_wc(resource_size_t base, unsigned long size) { + struct io_mapping *mapping; - return ioremap_wc(base, size); + mapping = kmalloc(sizeof(*mapping), GFP_KERNEL); + if (mapping == NULL) + return (NULL); + return (io_mapping_init_wc(mapping, base, size)); +} + +static inline void +io_mapping_fini(struct io_mapping *mapping) +{ + + iounmap(mapping->mem); } static inline void io_mapping_free(struct io_mapping *mapping) { - iounmap(mapping); + io_mapping_fini(mapping->mem); + kfree(mapping); } static inline void * io_mapping_map_atomic_wc(struct io_mapping *mapping, unsigned long offset) { - return (((char *)mapping) + offset); + return ((char *)mapping->mem + offset); } static inline void io_mapping_unmap_atomic(void *vaddr) { - } static inline void * -io_mapping_map_wc(struct io_mapping *mapping, unsigned long offset) +io_mapping_map_wc(struct io_mapping *mapping, unsigned long offset, + unsigned long size) { - return (((char *) mapping) + offset); + return ((char *)mapping->mem + offset); } static inline void io_mapping_unmap(void *vaddr) { - } -#endif /* _LINUX_IO_MAPPING_H_ */ +#endif /* _LINUX_IO_MAPPING_H_ */ -- cgit v1.2.3 From 4eb1bcfc62f17470a0c63cec35d41322d63796be Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Sun, 25 Jun 2017 19:20:12 +0000 Subject: Add noop_lseek() to the LinuxKPI. MFC after: 1 week --- sys/compat/linuxkpi/common/include/linux/fs.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'sys/compat/linuxkpi/common/include') diff --git a/sys/compat/linuxkpi/common/include/linux/fs.h b/sys/compat/linuxkpi/common/include/linux/fs.h index cc475ba2807e..ef5d1cc265e1 100644 --- a/sys/compat/linuxkpi/common/include/linux/fs.h +++ b/sys/compat/linuxkpi/common/include/linux/fs.h @@ -261,7 +261,15 @@ iput(struct inode *inode) static inline loff_t no_llseek(struct file *file, loff_t offset, int whence) { - return -ESPIPE; + + return (-ESPIPE); +} + +static inline loff_t +noop_llseek(struct linux_file *file, loff_t offset, int whence) +{ + + return (file->_file->f_offset); } #endif /* _LINUX_FS_H_ */ -- cgit v1.2.3 From 0bfde0a7c7b60fc256b8340b46387e1b5bdfe78c Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Sun, 25 Jun 2017 19:21:59 +0000 Subject: Add the thaw_early method to struct dev_pm_ops in the LinuxKPI. MFC after: 1 week --- sys/compat/linuxkpi/common/include/linux/device.h | 1 + 1 file changed, 1 insertion(+) (limited to 'sys/compat/linuxkpi/common/include') diff --git a/sys/compat/linuxkpi/common/include/linux/device.h b/sys/compat/linuxkpi/common/include/linux/device.h index af69fa05e2e6..f868c32d5656 100644 --- a/sys/compat/linuxkpi/common/include/linux/device.h +++ b/sys/compat/linuxkpi/common/include/linux/device.h @@ -69,6 +69,7 @@ struct dev_pm_ops { int (*freeze)(struct device *dev); int (*freeze_late)(struct device *dev); int (*thaw)(struct device *dev); + int (*thaw_early)(struct device *dev); int (*poweroff)(struct device *dev); int (*poweroff_late)(struct device *dev); int (*restore)(struct device *dev); -- cgit v1.2.3 From 934277c59cfdd148f9a809df2b0438a69e055e49 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Sun, 25 Jun 2017 19:23:14 +0000 Subject: Add a couple of macros to lockdep.h in the LinuxKPI. MFC after: 1 week --- sys/compat/linuxkpi/common/include/linux/lockdep.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'sys/compat/linuxkpi/common/include') diff --git a/sys/compat/linuxkpi/common/include/linux/lockdep.h b/sys/compat/linuxkpi/common/include/linux/lockdep.h index 065399fa44ad..ef562e300cd9 100644 --- a/sys/compat/linuxkpi/common/include/linux/lockdep.h +++ b/sys/compat/linuxkpi/common/include/linux/lockdep.h @@ -39,7 +39,12 @@ struct lock_class_key { #define lockdep_set_class_and_name(lock, key, name) +#define lockdep_assert_held(m) \ + sx_assert(&(m)->sx, SA_XLOCKED) + #define lockdep_assert_held_once(m) \ sx_assert(&(m)->sx, SA_XLOCKED | SA_NOTRECURSED) +#define lockdep_is_held(m) (sx_xholder(&(m)->sx) == curthread) + #endif /* _LINUX_LOCKDEP_H_ */ -- cgit v1.2.3 From 1fde37964d192ea28882130c2a3bb6d682ceabd7 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Sun, 25 Jun 2017 19:28:01 +0000 Subject: Add ns_to_ktime() to the LinuxKPI. MFC after: 1 week --- sys/compat/linuxkpi/common/include/linux/ktime.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'sys/compat/linuxkpi/common/include') diff --git a/sys/compat/linuxkpi/common/include/linux/ktime.h b/sys/compat/linuxkpi/common/include/linux/ktime.h index 7c6c40fe1a8e..e2fd977a7cc5 100644 --- a/sys/compat/linuxkpi/common/include/linux/ktime.h +++ b/sys/compat/linuxkpi/common/include/linux/ktime.h @@ -51,6 +51,15 @@ ktime_to_ns(ktime_t kt) return kt.tv64; } +static inline ktime_t +ns_to_ktime(uint64_t nsec) +{ + ktime_t kt; + + kt.tv64 = nsec; + return (kt); +} + static inline int64_t ktime_divns(const ktime_t kt, int64_t div) { -- cgit v1.2.3 From ee7c3198cd71ded5805696b3ba04758950734781 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Sun, 25 Jun 2017 19:30:20 +0000 Subject: Add u64_to_user_ptr() to the LinuxKPI. MFC after: 1 week --- sys/compat/linuxkpi/common/include/linux/kernel.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sys/compat/linuxkpi/common/include') diff --git a/sys/compat/linuxkpi/common/include/linux/kernel.h b/sys/compat/linuxkpi/common/include/linux/kernel.h index b8d2bd3b66a5..c2641320871c 100644 --- a/sys/compat/linuxkpi/common/include/linux/kernel.h +++ b/sys/compat/linuxkpi/common/include/linux/kernel.h @@ -260,6 +260,8 @@ scnprintf(char *buf, size_t size, const char *fmt, ...) #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#define u64_to_user_ptr(val) ((void *)(uintptr_t)(val)) + static inline unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base) { -- cgit v1.2.3 From 9ea3e14182f3c0fa0a22d3d53886bfd0fff9d098 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Mon, 26 Jun 2017 16:28:46 +0000 Subject: Implement parts of the hrtimer API in the LinuxKPI. Reviewed by: hselasky MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D11359 --- sys/compat/linuxkpi/common/include/linux/hrtimer.h | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 sys/compat/linuxkpi/common/include/linux/hrtimer.h (limited to 'sys/compat/linuxkpi/common/include') diff --git a/sys/compat/linuxkpi/common/include/linux/hrtimer.h b/sys/compat/linuxkpi/common/include/linux/hrtimer.h new file mode 100644 index 000000000000..658a5407771e --- /dev/null +++ b/sys/compat/linuxkpi/common/include/linux/hrtimer.h @@ -0,0 +1,79 @@ +/*- + * Copyright (c) 2017 Mark Johnston + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _LINUX_HRTIMER_H_ +#define _LINUX_HRTIMER_H_ + +#include +#include + +#include +#include + +enum hrtimer_mode { + HRTIMER_MODE_REL, +}; + +enum hrtimer_restart { + HRTIMER_RESTART, + HRTIMER_NORESTART, +}; + +struct hrtimer { + enum hrtimer_restart (*function)(struct hrtimer *); + struct mtx mtx; + struct callout callout; + uint32_t flags; +}; + +#define hrtimer_active(hrtimer) linux_hrtimer_active(hrtimer) +#define hrtimer_cancel(hrtimer) linux_hrtimer_cancel(hrtimer) +#define hrtimer_init(hrtimer, clock, mode) do { \ + CTASSERT((clock) == CLOCK_MONOTONIC); \ + CTASSERT((mode) == HRTIMER_MODE_REL); \ + linux_hrtimer_init(hrtimer); \ +} while (0) +#define hrtimer_set_expires(hrtimer, time) \ + linux_hrtimer_set_expires(hrtimer, time) +#define hrtimer_start(hrtimer, time, mode) do { \ + CTASSERT((mode) == HRTIMER_MODE_REL); \ + linux_hrtimer_start(hrtimer, time); \ +} while (0) +#define hrtimer_start_range_ns(hrtimer, time, prec, mode) do { \ + CTASSERT((mode) == HRTIMER_MODE_REL); \ + linux_hrtimer_start_range_ns(hrtimer, time, prec); \ +} while (0) + +bool linux_hrtimer_active(struct hrtimer *); +int linux_hrtimer_cancel(struct hrtimer *); +void linux_hrtimer_init(struct hrtimer *); +void linux_hrtimer_set_expires(struct hrtimer *, ktime_t); +void linux_hrtimer_start(struct hrtimer *, ktime_t); +void linux_hrtimer_start_range_ns(struct hrtimer *, ktime_t, int64_t); + +#endif /* _LINUX_HRTIMER_H_ */ -- cgit v1.2.3