Deleted Added
full compact
linux_compat.c (280540) linux_compat.c (282513)
1/*-
2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
5 * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 18 unchanged lines hidden (view full) ---

27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/malloc.h>
33#include <sys/kernel.h>
34#include <sys/sysctl.h>
1/*-
2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
5 * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 18 unchanged lines hidden (view full) ---

27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/malloc.h>
33#include <sys/kernel.h>
34#include <sys/sysctl.h>
35#include <sys/proc.h>
36#include <sys/sleepqueue.h>
35#include <sys/lock.h>
36#include <sys/mutex.h>
37#include <sys/bus.h>
38#include <sys/fcntl.h>
39#include <sys/file.h>
40#include <sys/filio.h>
41#include <sys/rwlock.h>
42

--- 8 unchanged lines hidden (view full) ---

51#include <linux/slab.h>
52#include <linux/module.h>
53#include <linux/cdev.h>
54#include <linux/file.h>
55#include <linux/sysfs.h>
56#include <linux/mm.h>
57#include <linux/io.h>
58#include <linux/vmalloc.h>
37#include <sys/lock.h>
38#include <sys/mutex.h>
39#include <sys/bus.h>
40#include <sys/fcntl.h>
41#include <sys/file.h>
42#include <sys/filio.h>
43#include <sys/rwlock.h>
44

--- 8 unchanged lines hidden (view full) ---

53#include <linux/slab.h>
54#include <linux/module.h>
55#include <linux/cdev.h>
56#include <linux/file.h>
57#include <linux/sysfs.h>
58#include <linux/mm.h>
59#include <linux/io.h>
60#include <linux/vmalloc.h>
61#include <linux/timer.h>
62#include <linux/netdevice.h>
59
60#include <vm/vm_pager.h>
61
62MALLOC_DEFINE(M_KMALLOC, "linux", "Linux kmalloc compat");
63
64#include <linux/rbtree.h>
65/* Undo Linux compat changes. */
66#undef RB_ROOT
67#undef file
68#undef cdev
69#define RB_ROOT(head) (head)->rbh_root
63
64#include <vm/vm_pager.h>
65
66MALLOC_DEFINE(M_KMALLOC, "linux", "Linux kmalloc compat");
67
68#include <linux/rbtree.h>
69/* Undo Linux compat changes. */
70#undef RB_ROOT
71#undef file
72#undef cdev
73#define RB_ROOT(head) (head)->rbh_root
70#undef LIST_HEAD
71/* From sys/queue.h */
72#define LIST_HEAD(name, type) \
73struct name { \
74 struct type *lh_first; /* first element */ \
75}
76
77struct kobject class_root;
78struct device linux_rootdev;
79struct class miscclass;
80struct list_head pci_drivers;
81struct list_head pci_devices;
74
75struct kobject class_root;
76struct device linux_rootdev;
77struct class miscclass;
78struct list_head pci_drivers;
79struct list_head pci_devices;
80struct net init_net;
82spinlock_t pci_lock;
83
81spinlock_t pci_lock;
82
83unsigned long linux_timer_hz_mask;
84
84int
85panic_cmp(struct rb_node *one, struct rb_node *two)
86{
87 panic("no cmp");
88}
89
90RB_GENERATE(linux_root, rb_node, __entry, panic_cmp);
91

--- 500 unchanged lines hidden (view full) ---

592 * caller's idea of the map size to properly unmap.
593 */
594struct vmmap {
595 LIST_ENTRY(vmmap) vm_next;
596 void *vm_addr;
597 unsigned long vm_size;
598};
599
85int
86panic_cmp(struct rb_node *one, struct rb_node *two)
87{
88 panic("no cmp");
89}
90
91RB_GENERATE(linux_root, rb_node, __entry, panic_cmp);
92

--- 500 unchanged lines hidden (view full) ---

593 * caller's idea of the map size to properly unmap.
594 */
595struct vmmap {
596 LIST_ENTRY(vmmap) vm_next;
597 void *vm_addr;
598 unsigned long vm_size;
599};
600
600LIST_HEAD(vmmaphd, vmmap);
601struct vmmaphd {
602 struct vmmap *lh_first;
603};
601#define VMMAP_HASH_SIZE 64
602#define VMMAP_HASH_MASK (VMMAP_HASH_SIZE - 1)
603#define VM_HASH(addr) ((uintptr_t)(addr) >> PAGE_SHIFT) & VMMAP_HASH_MASK
604static struct vmmaphd vmmaphead[VMMAP_HASH_SIZE];
605static struct mtx vmmaplock;
606
607static void
608vmmap_add(void *addr, unsigned long size)

--- 74 unchanged lines hidden (view full) ---

683 vmmap = vmmap_remove(addr);
684 if (vmmap == NULL)
685 return;
686 pmap_qremove((vm_offset_t)addr, vmmap->vm_size / PAGE_SIZE);
687 kva_free((vm_offset_t)addr, vmmap->vm_size);
688 kfree(vmmap);
689}
690
604#define VMMAP_HASH_SIZE 64
605#define VMMAP_HASH_MASK (VMMAP_HASH_SIZE - 1)
606#define VM_HASH(addr) ((uintptr_t)(addr) >> PAGE_SHIFT) & VMMAP_HASH_MASK
607static struct vmmaphd vmmaphead[VMMAP_HASH_SIZE];
608static struct mtx vmmaplock;
609
610static void
611vmmap_add(void *addr, unsigned long size)

--- 74 unchanged lines hidden (view full) ---

686 vmmap = vmmap_remove(addr);
687 if (vmmap == NULL)
688 return;
689 pmap_qremove((vm_offset_t)addr, vmmap->vm_size / PAGE_SIZE);
690 kva_free((vm_offset_t)addr, vmmap->vm_size);
691 kfree(vmmap);
692}
693
694
695char *
696kasprintf(gfp_t gfp, const char *fmt, ...)
697{
698 va_list ap;
699 char *p;
700
701 va_start(ap, fmt);
702 p = kvasprintf(gfp, fmt, ap);
703 va_end(ap);
704
705 return p;
706}
707
708static int
709linux_timer_jiffies_until(unsigned long expires)
710{
711 int delta = expires - jiffies;
712 /* guard against already expired values */
713 if (delta < 1)
714 delta = 1;
715 return (delta);
716}
717
691static void
718static void
719linux_timer_callback_wrapper(void *context)
720{
721 struct timer_list *timer;
722
723 timer = context;
724 timer->function(timer->data);
725}
726
727void
728mod_timer(struct timer_list *timer, unsigned long expires)
729{
730
731 timer->expires = expires;
732 callout_reset(&timer->timer_callout,
733 linux_timer_jiffies_until(expires),
734 &linux_timer_callback_wrapper, timer);
735}
736
737void
738add_timer(struct timer_list *timer)
739{
740
741 callout_reset(&timer->timer_callout,
742 linux_timer_jiffies_until(timer->expires),
743 &linux_timer_callback_wrapper, timer);
744}
745
746static void
747linux_timer_init(void *arg)
748{
749
750 /*
751 * Compute an internal HZ value which can divide 2**32 to
752 * avoid timer rounding problems when the tick value wraps
753 * around 2**32:
754 */
755 linux_timer_hz_mask = 1;
756 while (linux_timer_hz_mask < (unsigned long)hz)
757 linux_timer_hz_mask *= 2;
758 linux_timer_hz_mask--;
759}
760SYSINIT(linux_timer, SI_SUB_DRIVERS, SI_ORDER_FIRST, linux_timer_init, NULL);
761
762void
763linux_complete_common(struct completion *c, int all)
764{
765 int wakeup_swapper;
766
767 sleepq_lock(c);
768 c->done++;
769 if (all)
770 wakeup_swapper = sleepq_broadcast(c, SLEEPQ_SLEEP, 0, 0);
771 else
772 wakeup_swapper = sleepq_signal(c, SLEEPQ_SLEEP, 0, 0);
773 sleepq_release(c);
774 if (wakeup_swapper)
775 kick_proc0();
776}
777
778/*
779 * Indefinite wait for done != 0 with or without signals.
780 */
781long
782linux_wait_for_common(struct completion *c, int flags)
783{
784
785 if (flags != 0)
786 flags = SLEEPQ_INTERRUPTIBLE | SLEEPQ_SLEEP;
787 else
788 flags = SLEEPQ_SLEEP;
789 for (;;) {
790 sleepq_lock(c);
791 if (c->done)
792 break;
793 sleepq_add(c, NULL, "completion", flags, 0);
794 if (flags & SLEEPQ_INTERRUPTIBLE) {
795 if (sleepq_wait_sig(c, 0) != 0)
796 return (-ERESTARTSYS);
797 } else
798 sleepq_wait(c, 0);
799 }
800 c->done--;
801 sleepq_release(c);
802
803 return (0);
804}
805
806/*
807 * Time limited wait for done != 0 with or without signals.
808 */
809long
810linux_wait_for_timeout_common(struct completion *c, long timeout, int flags)
811{
812 long end = jiffies + timeout;
813
814 if (flags != 0)
815 flags = SLEEPQ_INTERRUPTIBLE | SLEEPQ_SLEEP;
816 else
817 flags = SLEEPQ_SLEEP;
818 for (;;) {
819 int ret;
820
821 sleepq_lock(c);
822 if (c->done)
823 break;
824 sleepq_add(c, NULL, "completion", flags, 0);
825 sleepq_set_timeout(c, linux_timer_jiffies_until(end));
826 if (flags & SLEEPQ_INTERRUPTIBLE)
827 ret = sleepq_timedwait_sig(c, 0);
828 else
829 ret = sleepq_timedwait(c, 0);
830 if (ret != 0) {
831 /* check for timeout or signal */
832 if (ret == EWOULDBLOCK)
833 return (0);
834 else
835 return (-ERESTARTSYS);
836 }
837 }
838 c->done--;
839 sleepq_release(c);
840
841 /* return how many jiffies are left */
842 return (linux_timer_jiffies_until(end));
843}
844
845int
846linux_try_wait_for_completion(struct completion *c)
847{
848 int isdone;
849
850 isdone = 1;
851 sleepq_lock(c);
852 if (c->done)
853 c->done--;
854 else
855 isdone = 0;
856 sleepq_release(c);
857 return (isdone);
858}
859
860int
861linux_completion_done(struct completion *c)
862{
863 int isdone;
864
865 isdone = 1;
866 sleepq_lock(c);
867 if (c->done == 0)
868 isdone = 0;
869 sleepq_release(c);
870 return (isdone);
871}
872
873static void
692linux_compat_init(void *arg)
693{
694 struct sysctl_oid *rootoid;
695 int i;
696
697 rootoid = SYSCTL_ADD_NODE(NULL, SYSCTL_STATIC_CHILDREN(),
698 OID_AUTO, "sys", CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, "sys");
699 kobject_init(&class_root, &class_ktype);

--- 29 unchanged lines hidden ---
874linux_compat_init(void *arg)
875{
876 struct sysctl_oid *rootoid;
877 int i;
878
879 rootoid = SYSCTL_ADD_NODE(NULL, SYSCTL_STATIC_CHILDREN(),
880 OID_AUTO, "sys", CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, "sys");
881 kobject_init(&class_root, &class_ktype);

--- 29 unchanged lines hidden ---