Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/external/bsd/drm2 Add __link_set based code to automatic...
details: https://anonhg.NetBSD.org/src/rev/3e3ebeda72a4
branches: trunk
changeset: 333638:3e3ebeda72a4
user: christos <christos%NetBSD.org@localhost>
date: Wed Nov 12 02:24:40 2014 +0000
description:
Add __link_set based code to automatically convert the linux module parameters
into sysctls.
diffstat:
sys/external/bsd/drm2/drm/drm_sysctl.c | 159 ++++++++++++++++++++++
sys/external/bsd/drm2/drm/files.drmkms | 3 +-
sys/external/bsd/drm2/i915drm/i915_module.c | 17 ++-
sys/external/bsd/drm2/include/drm/drm_sysctl.h | 31 ++++
sys/external/bsd/drm2/include/linux/module.h | 14 +-
sys/external/bsd/drm2/include/linux/moduleparam.h | 23 ++-
6 files changed, 240 insertions(+), 7 deletions(-)
diffs (truncated from 337 to 300 lines):
diff -r 4c01b70d7a1d -r 3e3ebeda72a4 sys/external/bsd/drm2/drm/drm_sysctl.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/external/bsd/drm2/drm/drm_sysctl.c Wed Nov 12 02:24:40 2014 +0000
@@ -0,0 +1,159 @@
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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, 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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.
+ */
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: drm_sysctl.c,v 1.1 2014/11/12 02:24:40 christos Exp $");
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/systm.h>
+#include <sys/sysctl.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+/* We need to specify the type programmatically */
+#undef sysctl_createv
+
+#include <drm/drm_sysctl.h>
+
+static const char *
+drm_sysctl_get_description(const struct linux_module_param_info *p, const void **v)
+{
+ const void * const *b = v[0], * const *e = v[1];
+
+ for (; b < e; b++) {
+ const struct linux_module_param_desc *d = *b;
+ if (strcmp(p->name, d->name) == 0)
+ return d->description;
+ }
+ return NULL;
+}
+
+#ifdef notyet
+static uint64_t
+drm_sysctl_get_value(const struct linux_module_param_info *p)
+{
+ switch (p->type) {
+ case MTYPE_bool:
+ return *(bool *)p->ptr;
+ case MTYPE_int:
+ return *(int *)p->ptr;
+ default:
+ aprint_error("unhandled module param type %d for %s\n",
+ p->type, p->name);
+ return 0;
+ }
+}
+
+static size_t
+drm_sysctl_get_size(const struct linux_module_param_info *p)
+{
+ switch (p->type) {
+ case MTYPE_bool:
+ return sizeof(bool);
+ case MTYPE_int:
+ return sizeof(int);
+ default:
+ aprint_error("unhandled module param type %d for %s\n",
+ p->type, p->name);
+ return sizeof(void *);
+ }
+}
+#endif
+
+static int
+drm_sysctl_get_type(const struct linux_module_param_info *p)
+{
+ switch (p->type) {
+ case MTYPE_bool:
+ return CTLTYPE_BOOL;
+ case MTYPE_int:
+ return CTLTYPE_INT;
+ default:
+ aprint_error("unhandled module param type %d for %s\n",
+ p->type, p->name);
+ return CTLTYPE_NODE;
+ }
+}
+
+
+static int
+drm_sysctl_node(const char *name, const struct sysctlnode **node,
+ struct sysctllog **log)
+{
+ return sysctl_createv(log, 0, node, node,
+ CTLFLAG_PERMANENT, CTLTYPE_NODE, name, NULL,
+ NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
+}
+
+
+void
+drm_sysctl_init(const void **v, struct sysctllog **log)
+{
+ const void * const *b = v[0], * const *e = v[1];
+ const struct sysctlnode *rnode = NULL, *cnode;
+ const char *name = "drm2";
+
+ int error;
+ if ((error = sysctl_createv(log, 0, NULL, &rnode,
+ CTLFLAG_PERMANENT, CTLTYPE_NODE, name,
+ SYSCTL_DESCR("DRM driver parameters"),
+ NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL)) != 0) {
+ aprint_error("sysctl_createv returned %d, "
+ "for %s ignoring\n", error, name);
+ return;
+ }
+
+ for (; b < e; b++) {
+ const struct linux_module_param_info *p = *b;
+ char copy[256], *n, *nn;
+ strlcpy(copy, p->name, sizeof(copy));
+ cnode = rnode;
+ for (n = copy; (nn = strchr(n, '.')) != NULL; n = nn) {
+ *nn++ = '\0';
+ if ((error = drm_sysctl_node(n, &cnode, log)) != 0) {
+ aprint_error("sysctl_createv returned %d, "
+ "for %s ignoring\n", error, n);
+ continue;
+ }
+ }
+
+ if ((error = sysctl_createv(log, 0, &cnode,
+ &cnode, p->mode == 0600 ? CTLFLAG_READWRITE : 0,
+ drm_sysctl_get_type(p), n,
+ SYSCTL_DESCR(drm_sysctl_get_description(p, v + 2)),
+ NULL, 0, p->ptr, 0, CTL_CREATE, CTL_EOL)) != 0)
+ aprint_error("sysctl_createv returned %d, "
+ "for %s ignoring\n", error, n);
+ }
+}
+
+void
+drm_sysctl_fini(struct sysctllog **log)
+{
+ sysctl_teardown(log);
+}
diff -r 4c01b70d7a1d -r 3e3ebeda72a4 sys/external/bsd/drm2/drm/files.drmkms
--- a/sys/external/bsd/drm2/drm/files.drmkms Wed Nov 12 02:19:28 2014 +0000
+++ b/sys/external/bsd/drm2/drm/files.drmkms Wed Nov 12 02:24:40 2014 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.drmkms,v 1.8 2014/09/14 19:06:00 riastradh Exp $
+# $NetBSD: files.drmkms,v 1.9 2014/11/12 02:24:40 christos Exp $
include "external/bsd/drm2/linux/files.drmkms_linux"
@@ -65,5 +65,6 @@
file external/bsd/drm2/drm/drm_gem_vm.c drmkms
file external/bsd/drm2/drm/drm_module.c drmkms
+file external/bsd/drm2/drm/drm_sysctl.c drmkms
include "external/bsd/drm2/ttm/files.ttm"
diff -r 4c01b70d7a1d -r 3e3ebeda72a4 sys/external/bsd/drm2/i915drm/i915_module.c
--- a/sys/external/bsd/drm2/i915drm/i915_module.c Wed Nov 12 02:19:28 2014 +0000
+++ b/sys/external/bsd/drm2/i915drm/i915_module.c Wed Nov 12 02:24:40 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: i915_module.c,v 1.3 2014/07/16 20:56:25 riastradh Exp $ */
+/* $NetBSD: i915_module.c,v 1.4 2014/11/12 02:24:40 christos Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i915_module.c,v 1.3 2014/07/16 20:56:25 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_module.c,v 1.4 2014/11/12 02:24:40 christos Exp $");
#include <sys/types.h>
#include <sys/module.h>
@@ -40,6 +40,7 @@
#include <sys/systm.h>
#include <drm/drmP.h>
+#include <drm/drm_sysctl.h>
#include "i915_drv.h"
@@ -54,6 +55,10 @@
extern const struct pci_device_id *const i915_device_ids;
extern const size_t i915_n_device_ids;
+static struct sysctllog *i915_sysctllog;
+__link_set_decl(linux_module_param_info, struct linux_module_param_info);
+__link_set_decl(linux_module_param_desc, struct linux_module_param_desc);
+
static int
i915drmkms_init(void)
{
@@ -74,6 +79,13 @@
error);
return error;
}
+ const void *v[] = {
+ __link_set_start(linux_module_param_info),
+ __link_set_end(linux_module_param_info),
+ __link_set_start(linux_module_param_desc),
+ __link_set_end(linux_module_param_desc),
+ };
+ drm_sysctl_init(v, &i915_sysctllog);
return 0;
}
@@ -96,6 +108,7 @@
{
drm_pci_exit(i915_drm_driver, NULL);
+ drm_sysctl_fini(&i915_sysctllog);
}
static int
diff -r 4c01b70d7a1d -r 3e3ebeda72a4 sys/external/bsd/drm2/include/drm/drm_sysctl.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/external/bsd/drm2/include/drm/drm_sysctl.h Wed Nov 12 02:24:40 2014 +0000
@@ -0,0 +1,31 @@
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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, 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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.
+ */
+struct sysctllog;
+extern void drm_sysctl_init(const void **, struct sysctllog **);
+extern void drm_sysctl_fini(struct sysctllog **);
diff -r 4c01b70d7a1d -r 3e3ebeda72a4 sys/external/bsd/drm2/include/linux/module.h
--- a/sys/external/bsd/drm2/include/linux/module.h Wed Nov 12 02:19:28 2014 +0000
+++ b/sys/external/bsd/drm2/include/linux/module.h Wed Nov 12 02:24:40 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: module.h,v 1.4 2014/08/06 13:49:33 riastradh Exp $ */
+/* $NetBSD: module.h,v 1.5 2014/11/12 02:24:40 christos Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -43,7 +43,17 @@
#define MODULE_DEVICE_TABLE(DESCRIPTION, IDLIST)
#define MODULE_FIRMWARE(FIRMWARE)
#define MODULE_LICENSE(LICENSE)
-#define MODULE_PARM_DESC(PARAMETER, DESCRIPTION)
+struct linux_module_param_desc {
+ const char *name;
+ const char *description;
+};
+#define MODULE_PARM_DESC(PARAMETER, DESCRIPTION) \
+static __attribute__((__used__)) \
+const struct linux_module_param_desc PARAMETER ## _desc = { \
+ .name = # PARAMETER, \
+ .description = DESCRIPTION, \
+}; \
+__link_set_add_rodata(linux_module_param_desc, PARAMETER ## _desc)
#define THIS_MODULE 0
Home |
Main Index |
Thread Index |
Old Index