2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
5 * Copyright (c) 2013-2015 Mellanox Technologies, Ltd.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice unmodified, this list of conditions, and the following
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/malloc.h>
36 #include <sys/kernel.h>
37 #include <sys/sysctl.h>
39 #include <sys/sglist.h>
40 #include <sys/sleepqueue.h>
42 #include <sys/mutex.h>
44 #include <sys/fcntl.h>
46 #include <sys/filio.h>
47 #include <sys/rwlock.h>
52 #include <machine/stdarg.h>
53 #include <machine/pmap.h>
55 #include <linux/kobject.h>
56 #include <linux/device.h>
57 #include <linux/slab.h>
58 #include <linux/module.h>
59 #include <linux/cdev.h>
60 #include <linux/file.h>
61 #include <linux/sysfs.h>
64 #include <linux/vmalloc.h>
65 #include <linux/netdevice.h>
66 #include <linux/timer.h>
67 #include <linux/workqueue.h>
69 #include <vm/vm_pager.h>
71 MALLOC_DEFINE(M_KMALLOC, "linux", "Linux kmalloc compat");
73 #include <linux/rbtree.h>
74 /* Undo Linux compat changes. */
78 #define RB_ROOT(head) (head)->rbh_root
80 struct kobject linux_class_root;
81 struct device linux_root_device;
82 struct class linux_class_misc;
83 struct list_head pci_drivers;
84 struct list_head pci_devices;
88 unsigned long linux_timer_hz_mask;
91 panic_cmp(struct rb_node *one, struct rb_node *two)
96 RB_GENERATE(linux_root, rb_node, __entry, panic_cmp);
99 kobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list args)
109 if (old && fmt == NULL)
112 /* compute length of string */
113 va_copy(tmp_va, args);
114 len = vsnprintf(&dummy, 0, fmt, tmp_va);
117 /* account for zero termination */
120 /* check for error */
124 /* allocate memory for string */
125 name = kzalloc(len, GFP_KERNEL);
128 vsnprintf(name, len, fmt, args);
131 /* free old string */
134 /* filter new string */
135 for (; *name != '\0'; name++)
142 kobject_set_name(struct kobject *kobj, const char *fmt, ...)
148 error = kobject_set_name_vargs(kobj, fmt, args);
155 kobject_add_complete(struct kobject *kobj, struct kobject *parent)
157 const struct kobj_type *t;
160 kobj->parent = parent;
161 error = sysfs_create_dir(kobj);
162 if (error == 0 && kobj->ktype && kobj->ktype->default_attrs) {
163 struct attribute **attr;
166 for (attr = t->default_attrs; *attr != NULL; attr++) {
167 error = sysfs_create_file(kobj, *attr);
172 sysfs_remove_dir(kobj);
179 kobject_add(struct kobject *kobj, struct kobject *parent, const char *fmt, ...)
185 error = kobject_set_name_vargs(kobj, fmt, args);
190 return kobject_add_complete(kobj, parent);
194 linux_kobject_release(struct kref *kref)
196 struct kobject *kobj;
199 kobj = container_of(kref, struct kobject, kref);
200 sysfs_remove_dir(kobj);
202 if (kobj->ktype && kobj->ktype->release)
203 kobj->ktype->release(kobj);
208 linux_kobject_kfree(struct kobject *kobj)
214 linux_kobject_kfree_name(struct kobject *kobj)
221 const struct kobj_type linux_kfree_type = {
222 .release = linux_kobject_kfree
226 linux_device_release(struct device *dev)
228 pr_debug("linux_device_release: %s\n", dev_name(dev));
233 linux_class_show(struct kobject *kobj, struct attribute *attr, char *buf)
235 struct class_attribute *dattr;
238 dattr = container_of(attr, struct class_attribute, attr);
241 error = dattr->show(container_of(kobj, struct class, kobj),
247 linux_class_store(struct kobject *kobj, struct attribute *attr, const char *buf,
250 struct class_attribute *dattr;
253 dattr = container_of(attr, struct class_attribute, attr);
256 error = dattr->store(container_of(kobj, struct class, kobj),
262 linux_class_release(struct kobject *kobj)
266 class = container_of(kobj, struct class, kobj);
267 if (class->class_release)
268 class->class_release(class);
271 static const struct sysfs_ops linux_class_sysfs = {
272 .show = linux_class_show,
273 .store = linux_class_store,
276 const struct kobj_type linux_class_ktype = {
277 .release = linux_class_release,
278 .sysfs_ops = &linux_class_sysfs
282 linux_dev_release(struct kobject *kobj)
286 dev = container_of(kobj, struct device, kobj);
287 /* This is the precedence defined by linux. */
290 else if (dev->class && dev->class->dev_release)
291 dev->class->dev_release(dev);
295 linux_dev_show(struct kobject *kobj, struct attribute *attr, char *buf)
297 struct device_attribute *dattr;
300 dattr = container_of(attr, struct device_attribute, attr);
303 error = dattr->show(container_of(kobj, struct device, kobj),
309 linux_dev_store(struct kobject *kobj, struct attribute *attr, const char *buf,
312 struct device_attribute *dattr;
315 dattr = container_of(attr, struct device_attribute, attr);
318 error = dattr->store(container_of(kobj, struct device, kobj),
323 static const struct sysfs_ops linux_dev_sysfs = {
324 .show = linux_dev_show,
325 .store = linux_dev_store,
328 const struct kobj_type linux_dev_ktype = {
329 .release = linux_dev_release,
330 .sysfs_ops = &linux_dev_sysfs
334 device_create(struct class *class, struct device *parent, dev_t devt,
335 void *drvdata, const char *fmt, ...)
340 dev = kzalloc(sizeof(*dev), M_WAITOK);
341 dev->parent = parent;
344 dev->driver_data = drvdata;
345 dev->release = linux_device_release;
347 kobject_set_name_vargs(&dev->kobj, fmt, args);
349 device_register(dev);
355 kobject_init_and_add(struct kobject *kobj, const struct kobj_type *ktype,
356 struct kobject *parent, const char *fmt, ...)
361 kobject_init(kobj, ktype);
363 kobj->parent = parent;
367 error = kobject_set_name_vargs(kobj, fmt, args);
371 return kobject_add_complete(kobj, parent);
375 linux_file_dtor(void *cdp)
377 struct linux_file *filp;
380 filp->f_op->release(filp->f_vnode, filp);
381 vdrop(filp->f_vnode);
386 linux_dev_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
388 struct linux_cdev *ldev;
389 struct linux_file *filp;
393 file = curthread->td_fpop;
397 filp = kzalloc(sizeof(*filp), GFP_KERNEL);
398 filp->f_dentry = &filp->f_dentry_store;
399 filp->f_op = ldev->ops;
400 filp->f_flags = file->f_flag;
401 vhold(file->f_vnode);
402 filp->f_vnode = file->f_vnode;
403 if (filp->f_op->open) {
404 error = -filp->f_op->open(file->f_vnode, filp);
410 error = devfs_set_cdevpriv(filp, linux_file_dtor);
412 filp->f_op->release(file->f_vnode, filp);
421 linux_dev_close(struct cdev *dev, int fflag, int devtype, struct thread *td)
423 struct linux_cdev *ldev;
424 struct linux_file *filp;
428 file = curthread->td_fpop;
432 if ((error = devfs_get_cdevpriv((void **)&filp)) != 0)
434 filp->f_flags = file->f_flag;
435 devfs_clear_cdevpriv();
442 linux_dev_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
445 struct linux_cdev *ldev;
446 struct linux_file *filp;
450 file = curthread->td_fpop;
454 if ((error = devfs_get_cdevpriv((void **)&filp)) != 0)
456 filp->f_flags = file->f_flag;
458 * Linux does not have a generic ioctl copyin/copyout layer. All
459 * linux ioctls must be converted to void ioctls which pass a
460 * pointer to the address of the data. We want the actual user
461 * address so we dereference here.
463 data = *(void **)data;
464 if (filp->f_op->unlocked_ioctl)
465 error = -filp->f_op->unlocked_ioctl(filp, cmd, (u_long)data);
473 linux_dev_read(struct cdev *dev, struct uio *uio, int ioflag)
475 struct linux_cdev *ldev;
476 struct linux_file *filp;
481 file = curthread->td_fpop;
485 if ((error = devfs_get_cdevpriv((void **)&filp)) != 0)
487 filp->f_flags = file->f_flag;
488 if (uio->uio_iovcnt != 1)
489 panic("linux_dev_read: uio %p iovcnt %d",
490 uio, uio->uio_iovcnt);
491 if (filp->f_op->read) {
492 bytes = filp->f_op->read(filp, uio->uio_iov->iov_base,
493 uio->uio_iov->iov_len, &uio->uio_offset);
495 uio->uio_iov->iov_base =
496 ((uint8_t *)uio->uio_iov->iov_base) + bytes;
497 uio->uio_iov->iov_len -= bytes;
498 uio->uio_resid -= bytes;
508 linux_dev_write(struct cdev *dev, struct uio *uio, int ioflag)
510 struct linux_cdev *ldev;
511 struct linux_file *filp;
516 file = curthread->td_fpop;
520 if ((error = devfs_get_cdevpriv((void **)&filp)) != 0)
522 filp->f_flags = file->f_flag;
523 if (uio->uio_iovcnt != 1)
524 panic("linux_dev_write: uio %p iovcnt %d",
525 uio, uio->uio_iovcnt);
526 if (filp->f_op->write) {
527 bytes = filp->f_op->write(filp, uio->uio_iov->iov_base,
528 uio->uio_iov->iov_len, &uio->uio_offset);
530 uio->uio_iov->iov_base =
531 ((uint8_t *)uio->uio_iov->iov_base) + bytes;
532 uio->uio_iov->iov_len -= bytes;
533 uio->uio_resid -= bytes;
543 linux_dev_poll(struct cdev *dev, int events, struct thread *td)
545 struct linux_cdev *ldev;
546 struct linux_file *filp;
551 file = curthread->td_fpop;
555 if ((error = devfs_get_cdevpriv((void **)&filp)) != 0)
557 filp->f_flags = file->f_flag;
558 if (filp->f_op->poll)
559 revents = filp->f_op->poll(filp, NULL) & events;
567 linux_dev_mmap_single(struct cdev *dev, vm_ooffset_t *offset,
568 vm_size_t size, struct vm_object **object, int nprot)
570 struct linux_cdev *ldev;
571 struct linux_file *filp;
573 struct vm_area_struct vma;
576 file = curthread->td_fpop;
580 if ((error = devfs_get_cdevpriv((void **)&filp)) != 0)
582 filp->f_flags = file->f_flag;
585 vma.vm_pgoff = *offset / PAGE_SIZE;
587 vma.vm_page_prot = 0;
588 if (filp->f_op->mmap) {
589 error = -filp->f_op->mmap(filp, &vma);
593 sg = sglist_alloc(1, M_WAITOK);
594 sglist_append_phys(sg,
595 (vm_paddr_t)vma.vm_pfn << PAGE_SHIFT, vma.vm_len);
596 *object = vm_pager_allocate(OBJT_SG, sg, vma.vm_len,
597 nprot, 0, curthread->td_ucred);
598 if (*object == NULL) {
603 if (vma.vm_page_prot != VM_MEMATTR_DEFAULT) {
604 VM_OBJECT_WLOCK(*object);
605 vm_object_set_memattr(*object,
607 VM_OBJECT_WUNLOCK(*object);
616 struct cdevsw linuxcdevsw = {
617 .d_version = D_VERSION,
618 .d_flags = D_TRACKCLOSE,
619 .d_open = linux_dev_open,
620 .d_close = linux_dev_close,
621 .d_read = linux_dev_read,
622 .d_write = linux_dev_write,
623 .d_ioctl = linux_dev_ioctl,
624 .d_mmap_single = linux_dev_mmap_single,
625 .d_poll = linux_dev_poll,
629 linux_file_read(struct file *file, struct uio *uio, struct ucred *active_cred,
630 int flags, struct thread *td)
632 struct linux_file *filp;
637 filp = (struct linux_file *)file->f_data;
638 filp->f_flags = file->f_flag;
639 if (uio->uio_iovcnt != 1)
640 panic("linux_file_read: uio %p iovcnt %d",
641 uio, uio->uio_iovcnt);
642 if (filp->f_op->read) {
643 bytes = filp->f_op->read(filp, uio->uio_iov->iov_base,
644 uio->uio_iov->iov_len, &uio->uio_offset);
646 uio->uio_iov->iov_base =
647 ((uint8_t *)uio->uio_iov->iov_base) + bytes;
648 uio->uio_iov->iov_len -= bytes;
649 uio->uio_resid -= bytes;
659 linux_file_poll(struct file *file, int events, struct ucred *active_cred,
662 struct linux_file *filp;
665 filp = (struct linux_file *)file->f_data;
666 filp->f_flags = file->f_flag;
667 if (filp->f_op->poll)
668 revents = filp->f_op->poll(filp, NULL) & events;
676 linux_file_close(struct file *file, struct thread *td)
678 struct linux_file *filp;
681 filp = (struct linux_file *)file->f_data;
682 filp->f_flags = file->f_flag;
683 error = -filp->f_op->release(NULL, filp);
684 funsetown(&filp->f_sigio);
691 linux_file_ioctl(struct file *fp, u_long cmd, void *data, struct ucred *cred,
694 struct linux_file *filp;
697 filp = (struct linux_file *)fp->f_data;
698 filp->f_flags = fp->f_flag;
705 if (filp->f_op->fasync == NULL)
707 error = filp->f_op->fasync(0, filp, fp->f_flag & FASYNC);
710 error = fsetown(*(int *)data, &filp->f_sigio);
712 error = filp->f_op->fasync(0, filp,
713 fp->f_flag & FASYNC);
716 *(int *)data = fgetown(&filp->f_sigio);
726 linux_file_stat(struct file *fp, struct stat *sb, struct ucred *active_cred,
734 linux_file_fill_kinfo(struct file *fp, struct kinfo_file *kif,
735 struct filedesc *fdp)
741 struct fileops linuxfileops = {
742 .fo_read = linux_file_read,
743 .fo_write = invfo_rdwr,
744 .fo_truncate = invfo_truncate,
745 .fo_kqfilter = invfo_kqfilter,
746 .fo_stat = linux_file_stat,
747 .fo_fill_kinfo = linux_file_fill_kinfo,
748 .fo_poll = linux_file_poll,
749 .fo_close = linux_file_close,
750 .fo_ioctl = linux_file_ioctl,
751 .fo_chmod = invfo_chmod,
752 .fo_chown = invfo_chown,
753 .fo_sendfile = invfo_sendfile,
757 * Hash of vmmap addresses. This is infrequently accessed and does not
758 * need to be particularly large. This is done because we must store the
759 * caller's idea of the map size to properly unmap.
762 LIST_ENTRY(vmmap) vm_next;
764 unsigned long vm_size;
768 struct vmmap *lh_first;
770 #define VMMAP_HASH_SIZE 64
771 #define VMMAP_HASH_MASK (VMMAP_HASH_SIZE - 1)
772 #define VM_HASH(addr) ((uintptr_t)(addr) >> PAGE_SHIFT) & VMMAP_HASH_MASK
773 static struct vmmaphd vmmaphead[VMMAP_HASH_SIZE];
774 static struct mtx vmmaplock;
777 vmmap_add(void *addr, unsigned long size)
781 vmmap = kmalloc(sizeof(*vmmap), GFP_KERNEL);
782 mtx_lock(&vmmaplock);
783 vmmap->vm_size = size;
784 vmmap->vm_addr = addr;
785 LIST_INSERT_HEAD(&vmmaphead[VM_HASH(addr)], vmmap, vm_next);
786 mtx_unlock(&vmmaplock);
789 static struct vmmap *
790 vmmap_remove(void *addr)
794 mtx_lock(&vmmaplock);
795 LIST_FOREACH(vmmap, &vmmaphead[VM_HASH(addr)], vm_next)
796 if (vmmap->vm_addr == addr)
799 LIST_REMOVE(vmmap, vm_next);
800 mtx_unlock(&vmmaplock);
805 #if defined(__i386__) || defined(__amd64__)
807 _ioremap_attr(vm_paddr_t phys_addr, unsigned long size, int attr)
811 addr = pmap_mapdev_attr(phys_addr, size, attr);
814 vmmap_add(addr, size);
825 vmmap = vmmap_remove(addr);
828 #if defined(__i386__) || defined(__amd64__)
829 pmap_unmapdev((vm_offset_t)addr, vmmap->vm_size);
836 vmap(struct page **pages, unsigned int count, unsigned long flags, int prot)
841 size = count * PAGE_SIZE;
842 off = kva_alloc(size);
845 vmmap_add((void *)off, size);
846 pmap_qenter(off, pages, count);
848 return ((void *)off);
856 vmmap = vmmap_remove(addr);
859 pmap_qremove((vm_offset_t)addr, vmmap->vm_size / PAGE_SIZE);
860 kva_free((vm_offset_t)addr, vmmap->vm_size);
865 kvasprintf(gfp_t gfp, const char *fmt, va_list ap)
872 len = vsnprintf(NULL, 0, fmt, aq);
875 p = kmalloc(len + 1, gfp);
877 vsnprintf(p, len + 1, fmt, ap);
883 kasprintf(gfp_t gfp, const char *fmt, ...)
889 p = kvasprintf(gfp, fmt, ap);
896 linux_timer_jiffies_until(unsigned long expires)
898 int delta = expires - jiffies;
899 /* guard against already expired values */
906 linux_timer_callback_wrapper(void *context)
908 struct timer_list *timer;
911 timer->function(timer->data);
915 mod_timer(struct timer_list *timer, unsigned long expires)
918 timer->expires = expires;
919 callout_reset(&timer->timer_callout,
920 linux_timer_jiffies_until(expires),
921 &linux_timer_callback_wrapper, timer);
925 add_timer(struct timer_list *timer)
928 callout_reset(&timer->timer_callout,
929 linux_timer_jiffies_until(timer->expires),
930 &linux_timer_callback_wrapper, timer);
934 linux_timer_init(void *arg)
938 * Compute an internal HZ value which can divide 2**32 to
939 * avoid timer rounding problems when the tick value wraps
942 linux_timer_hz_mask = 1;
943 while (linux_timer_hz_mask < (unsigned long)hz)
944 linux_timer_hz_mask *= 2;
945 linux_timer_hz_mask--;
947 SYSINIT(linux_timer, SI_SUB_DRIVERS, SI_ORDER_FIRST, linux_timer_init, NULL);
950 linux_complete_common(struct completion *c, int all)
957 wakeup_swapper = sleepq_broadcast(c, SLEEPQ_SLEEP, 0, 0);
959 wakeup_swapper = sleepq_signal(c, SLEEPQ_SLEEP, 0, 0);
966 * Indefinite wait for done != 0 with or without signals.
969 linux_wait_for_common(struct completion *c, int flags)
973 flags = SLEEPQ_INTERRUPTIBLE | SLEEPQ_SLEEP;
975 flags = SLEEPQ_SLEEP;
980 sleepq_add(c, NULL, "completion", flags, 0);
981 if (flags & SLEEPQ_INTERRUPTIBLE) {
982 if (sleepq_wait_sig(c, 0) != 0)
983 return (-ERESTARTSYS);
994 * Time limited wait for done != 0 with or without signals.
997 linux_wait_for_timeout_common(struct completion *c, long timeout, int flags)
999 long end = jiffies + timeout;
1002 flags = SLEEPQ_INTERRUPTIBLE | SLEEPQ_SLEEP;
1004 flags = SLEEPQ_SLEEP;
1011 sleepq_add(c, NULL, "completion", flags, 0);
1012 sleepq_set_timeout(c, linux_timer_jiffies_until(end));
1013 if (flags & SLEEPQ_INTERRUPTIBLE)
1014 ret = sleepq_timedwait_sig(c, 0);
1016 ret = sleepq_timedwait(c, 0);
1018 /* check for timeout or signal */
1019 if (ret == EWOULDBLOCK)
1022 return (-ERESTARTSYS);
1028 /* return how many jiffies are left */
1029 return (linux_timer_jiffies_until(end));
1033 linux_try_wait_for_completion(struct completion *c)
1048 linux_completion_done(struct completion *c)
1061 linux_delayed_work_fn(void *arg)
1063 struct delayed_work *work;
1066 taskqueue_enqueue(work->work.taskqueue, &work->work.work_task);
1070 linux_work_fn(void *context, int pending)
1072 struct work_struct *work;
1079 linux_flush_fn(void *context, int pending)
1083 struct workqueue_struct *
1084 linux_create_workqueue_common(const char *name, int cpus)
1086 struct workqueue_struct *wq;
1088 wq = kmalloc(sizeof(*wq), M_WAITOK);
1089 wq->taskqueue = taskqueue_create(name, M_WAITOK,
1090 taskqueue_thread_enqueue, &wq->taskqueue);
1091 atomic_set(&wq->draining, 0);
1092 taskqueue_start_threads(&wq->taskqueue, cpus, PWAIT, "%s", name);
1098 destroy_workqueue(struct workqueue_struct *wq)
1100 taskqueue_free(wq->taskqueue);
1105 linux_cdev_release(struct kobject *kobj)
1107 struct linux_cdev *cdev;
1108 struct kobject *parent;
1110 cdev = container_of(kobj, struct linux_cdev, kobj);
1111 parent = kobj->parent;
1113 destroy_dev(cdev->cdev);
1115 kobject_put(parent);
1119 linux_cdev_static_release(struct kobject *kobj)
1121 struct linux_cdev *cdev;
1122 struct kobject *parent;
1124 cdev = container_of(kobj, struct linux_cdev, kobj);
1125 parent = kobj->parent;
1127 destroy_dev(cdev->cdev);
1128 kobject_put(parent);
1131 const struct kobj_type linux_cdev_ktype = {
1132 .release = linux_cdev_release,
1135 const struct kobj_type linux_cdev_static_ktype = {
1136 .release = linux_cdev_static_release,
1140 linux_compat_init(void *arg)
1142 struct sysctl_oid *rootoid;
1145 rootoid = SYSCTL_ADD_ROOT_NODE(NULL,
1146 OID_AUTO, "sys", CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, "sys");
1147 kobject_init(&linux_class_root, &linux_class_ktype);
1148 kobject_set_name(&linux_class_root, "class");
1149 linux_class_root.oidp = SYSCTL_ADD_NODE(NULL, SYSCTL_CHILDREN(rootoid),
1150 OID_AUTO, "class", CTLFLAG_RD|CTLFLAG_MPSAFE, NULL, "class");
1151 kobject_init(&linux_root_device.kobj, &linux_dev_ktype);
1152 kobject_set_name(&linux_root_device.kobj, "device");
1153 linux_root_device.kobj.oidp = SYSCTL_ADD_NODE(NULL,
1154 SYSCTL_CHILDREN(rootoid), OID_AUTO, "device", CTLFLAG_RD, NULL,
1156 linux_root_device.bsddev = root_bus;
1157 linux_class_misc.name = "misc";
1158 class_register(&linux_class_misc);
1159 INIT_LIST_HEAD(&pci_drivers);
1160 INIT_LIST_HEAD(&pci_devices);
1161 spin_lock_init(&pci_lock);
1162 mtx_init(&vmmaplock, "IO Map lock", NULL, MTX_DEF);
1163 for (i = 0; i < VMMAP_HASH_SIZE; i++)
1164 LIST_INIT(&vmmaphead[i]);
1166 SYSINIT(linux_compat, SI_SUB_DRIVERS, SI_ORDER_SECOND, linux_compat_init, NULL);
1169 linux_compat_uninit(void *arg)
1171 linux_kobject_kfree_name(&linux_class_root);
1172 linux_kobject_kfree_name(&linux_root_device.kobj);
1173 linux_kobject_kfree_name(&linux_class_misc.kobj);
1175 SYSUNINIT(linux_compat, SI_SUB_DRIVERS, SI_ORDER_SECOND, linux_compat_uninit, NULL);
1178 * NOTE: Linux frequently uses "unsigned long" for pointer to integer
1179 * conversion and vice versa, where in FreeBSD "uintptr_t" would be
1180 * used. Assert these types have the same size, else some parts of the
1181 * LinuxKPI may not work like expected:
1183 CTASSERT(sizeof(unsigned long) == sizeof(uintptr_t));