svn commit: r311803 - in stable/11/sys/compat/linuxkpi/common: include/linux src

Hans Petter Selasky hselasky at FreeBSD.org
Mon Jan 9 17:25:25 UTC 2017


Author: hselasky
Date: Mon Jan  9 17:25:23 2017
New Revision: 311803
URL: https://svnweb.freebsd.org/changeset/base/311803

Log:
  MFC r310559 and r310583:
  Implement register and unregister chrdev in the LinuxKPI.
  
  Obtained from:	kmacy @
  Sponsored by:	Mellanox Technologies

Modified:
  stable/11/sys/compat/linuxkpi/common/include/linux/cdev.h
  stable/11/sys/compat/linuxkpi/common/include/linux/fs.h
  stable/11/sys/compat/linuxkpi/common/src/linux_compat.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/compat/linuxkpi/common/include/linux/cdev.h
==============================================================================
--- stable/11/sys/compat/linuxkpi/common/include/linux/cdev.h	Mon Jan  9 17:20:04 2017	(r311802)
+++ stable/11/sys/compat/linuxkpi/common/include/linux/cdev.h	Mon Jan  9 17:25:23 2017	(r311803)
@@ -95,7 +95,7 @@ cdev_add(struct linux_cdev *cdev, dev_t 
 	args.mda_gid = 0;
 	args.mda_mode = 0700;
 	args.mda_si_drv1 = cdev;
-	args.mda_unit = MINOR(dev);
+	args.mda_unit = dev;
 
 	error = make_dev_s(&args, &cdev->cdev, "%s",
 	    kobject_name(&cdev->kobj));
@@ -121,7 +121,7 @@ cdev_add_ext(struct linux_cdev *cdev, de
 	args.mda_gid = gid;
 	args.mda_mode = mode;
 	args.mda_si_drv1 = cdev;
-	args.mda_unit = MINOR(dev);
+	args.mda_unit = dev;
 
 	error = make_dev_s(&args, &cdev->cdev, "%s/%d",
 	    kobject_name(&cdev->kobj), MINOR(dev));
@@ -142,6 +142,8 @@ cdev_del(struct linux_cdev *cdev)
 	kobject_put(&cdev->kobj);
 }
 
+struct linux_cdev *linux_find_cdev(const char *name, unsigned major, unsigned minor);
+
 #define	cdev	linux_cdev
 
 #endif	/* _LINUX_CDEV_H_ */

Modified: stable/11/sys/compat/linuxkpi/common/include/linux/fs.h
==============================================================================
--- stable/11/sys/compat/linuxkpi/common/include/linux/fs.h	Mon Jan  9 17:20:04 2017	(r311802)
+++ stable/11/sys/compat/linuxkpi/common/include/linux/fs.h	Mon Jan  9 17:25:23 2017	(r311803)
@@ -2,7 +2,7 @@
  * Copyright (c) 2010 Isilon Systems, Inc.
  * Copyright (c) 2010 iX Systems, Inc.
  * Copyright (c) 2010 Panasas, Inc.
- * Copyright (c) 2013 Mellanox Technologies, Ltd.
+ * Copyright (c) 2013-2016 Mellanox Technologies, Ltd.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -151,6 +151,39 @@ struct file_operations {
 #define	FMODE_WRITE	FWRITE
 #define	FMODE_EXEC	FEXEC
 
+int __register_chrdev(unsigned int major, unsigned int baseminor,
+    unsigned int count, const char *name,
+    const struct file_operations *fops);
+int __register_chrdev_p(unsigned int major, unsigned int baseminor,
+    unsigned int count, const char *name,
+    const struct file_operations *fops, uid_t uid,
+    gid_t gid, int mode);
+void __unregister_chrdev(unsigned int major, unsigned int baseminor,
+    unsigned int count, const char *name);
+
+static inline void
+unregister_chrdev(unsigned int major, const char *name)
+{
+
+	__unregister_chrdev(major, 0, 256, name);
+}
+
+static inline int
+register_chrdev(unsigned int major, const char *name,
+    const struct file_operations *fops)
+{
+
+	return (__register_chrdev(major, 0, 256, name, fops));
+}
+
+static inline int
+register_chrdev_p(unsigned int major, const char *name,
+    const struct file_operations *fops, uid_t uid, gid_t gid, int mode)
+{
+
+	return (__register_chrdev_p(major, 0, 256, name, fops, uid, gid, mode));
+}
+
 static inline int
 register_chrdev_region(dev_t dev, unsigned range, const char *name)
 {
@@ -184,7 +217,7 @@ static inline dev_t
 iminor(struct inode *inode)
 {
 
-	return dev2unit(inode->v_rdev);
+	return (minor(dev2unit(inode->v_rdev)));
 }
 
 static inline struct inode *

Modified: stable/11/sys/compat/linuxkpi/common/src/linux_compat.c
==============================================================================
--- stable/11/sys/compat/linuxkpi/common/src/linux_compat.c	Mon Jan  9 17:20:04 2017	(r311802)
+++ stable/11/sys/compat/linuxkpi/common/src/linux_compat.c	Mon Jan  9 17:25:23 2017	(r311803)
@@ -1418,6 +1418,82 @@ linux_irq_handler(void *ent)
 	irqe->handler(irqe->irq, irqe->arg);
 }
 
+struct linux_cdev *
+linux_find_cdev(const char *name, unsigned major, unsigned minor)
+{
+	int unit = MKDEV(major, minor);
+	struct cdev *cdev;
+
+	dev_lock();
+	LIST_FOREACH(cdev, &linuxcdevsw.d_devs, si_list) {
+		struct linux_cdev *ldev = cdev->si_drv1;
+		if (dev2unit(cdev) == unit &&
+		    strcmp(kobject_name(&ldev->kobj), name) == 0) {
+			break;
+		}
+	}
+	dev_unlock();
+
+	return (cdev != NULL ? cdev->si_drv1 : NULL);
+}
+
+int
+__register_chrdev(unsigned int major, unsigned int baseminor,
+    unsigned int count, const char *name,
+    const struct file_operations *fops)
+{
+	struct linux_cdev *cdev;
+	int ret = 0;
+	int i;
+
+	for (i = baseminor; i < baseminor + count; i++) {
+		cdev = cdev_alloc();
+		cdev_init(cdev, fops);
+		kobject_set_name(&cdev->kobj, name);
+
+		ret = cdev_add(cdev, makedev(major, i), 1);
+		if (ret != 0)
+			break;
+	}
+	return (ret);
+}
+
+int
+__register_chrdev_p(unsigned int major, unsigned int baseminor,
+    unsigned int count, const char *name,
+    const struct file_operations *fops, uid_t uid,
+    gid_t gid, int mode)
+{
+	struct linux_cdev *cdev;
+	int ret = 0;
+	int i;
+
+	for (i = baseminor; i < baseminor + count; i++) {
+		cdev = cdev_alloc();
+		cdev_init(cdev, fops);
+		kobject_set_name(&cdev->kobj, name);
+
+		ret = cdev_add_ext(cdev, makedev(major, i), uid, gid, mode);
+		if (ret != 0)
+			break;
+	}
+	return (ret);
+}
+
+void
+__unregister_chrdev(unsigned int major, unsigned int baseminor,
+    unsigned int count, const char *name)
+{
+	struct linux_cdev *cdevp;
+	int i;
+
+	for (i = baseminor; i < baseminor + count; i++) {
+		cdevp = linux_find_cdev(name, major, i);
+		if (cdevp != NULL)
+			cdev_del(cdevp);
+	}
+}
+
 #if defined(__i386__) || defined(__amd64__)
 bool linux_cpu_has_clflush;
 #endif


More information about the svn-src-all mailing list