Module Name: src Committed By: christos Date: Wed Nov 12 02:24:40 UTC 2014
Modified Files: src/sys/external/bsd/drm2/drm: files.drmkms src/sys/external/bsd/drm2/i915drm: i915_module.c src/sys/external/bsd/drm2/include/linux: module.h moduleparam.h Added Files: src/sys/external/bsd/drm2/drm: drm_sysctl.c src/sys/external/bsd/drm2/include/drm: drm_sysctl.h Log Message: Add __link_set based code to automatically convert the linux module parameters into sysctls. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/sys/external/bsd/drm2/drm/drm_sysctl.c cvs rdiff -u -r1.8 -r1.9 src/sys/external/bsd/drm2/drm/files.drmkms cvs rdiff -u -r1.3 -r1.4 src/sys/external/bsd/drm2/i915drm/i915_module.c cvs rdiff -u -r0 -r1.1 src/sys/external/bsd/drm2/include/drm/drm_sysctl.h cvs rdiff -u -r1.4 -r1.5 src/sys/external/bsd/drm2/include/linux/module.h cvs rdiff -u -r1.2 -r1.3 \ src/sys/external/bsd/drm2/include/linux/moduleparam.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/external/bsd/drm2/drm/files.drmkms diff -u src/sys/external/bsd/drm2/drm/files.drmkms:1.8 src/sys/external/bsd/drm2/drm/files.drmkms:1.9 --- src/sys/external/bsd/drm2/drm/files.drmkms:1.8 Sun Sep 14 15:06:00 2014 +++ src/sys/external/bsd/drm2/drm/files.drmkms Tue Nov 11 21:24:40 2014 @@ -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_vma_manag 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" Index: src/sys/external/bsd/drm2/i915drm/i915_module.c diff -u src/sys/external/bsd/drm2/i915drm/i915_module.c:1.3 src/sys/external/bsd/drm2/i915drm/i915_module.c:1.4 --- src/sys/external/bsd/drm2/i915drm/i915_module.c:1.3 Wed Jul 16 16:56:25 2014 +++ src/sys/external/bsd/drm2/i915drm/i915_module.c Tue Nov 11 21:24:40 2014 @@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: i915_module. #include <sys/systm.h> #include <drm/drmP.h> +#include <drm/drm_sysctl.h> #include "i915_drv.h" @@ -54,6 +55,10 @@ extern struct drm_driver *const i915_drm 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 @@ i915drmkms_init(void) 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 @@ i915drmkms_fini(void) { drm_pci_exit(i915_drm_driver, NULL); + drm_sysctl_fini(&i915_sysctllog); } static int Index: src/sys/external/bsd/drm2/include/linux/module.h diff -u src/sys/external/bsd/drm2/include/linux/module.h:1.4 src/sys/external/bsd/drm2/include/linux/module.h:1.5 --- src/sys/external/bsd/drm2/include/linux/module.h:1.4 Wed Aug 6 09:49:33 2014 +++ src/sys/external/bsd/drm2/include/linux/module.h Tue Nov 11 21:24:40 2014 @@ -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 Index: src/sys/external/bsd/drm2/include/linux/moduleparam.h diff -u src/sys/external/bsd/drm2/include/linux/moduleparam.h:1.2 src/sys/external/bsd/drm2/include/linux/moduleparam.h:1.3 --- src/sys/external/bsd/drm2/include/linux/moduleparam.h:1.2 Tue Mar 18 14:20:43 2014 +++ src/sys/external/bsd/drm2/include/linux/moduleparam.h Tue Nov 11 21:24:40 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: moduleparam.h,v 1.2 2014/03/18 18:20:43 riastradh Exp $ */ +/* $NetBSD: moduleparam.h,v 1.3 2014/11/12 02:24:40 christos Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. @@ -32,6 +32,25 @@ #ifndef _LINUX_MODULEPARAM_H_ #define _LINUX_MODULEPARAM_H_ -#define module_param_named(NAME, VAR, TYPE, MODE) +#include <sys/types.h> + +struct linux_module_param_info { + const char *name; + void *ptr; + int type; + mode_t mode; +}; + +#define MTYPE_int 0 +#define MTYPE_bool 1 + +#define module_param_named(NAME, VAR, TYPE, MODE) \ +static __attribute__((__used__)) struct linux_module_param_info info_ ## NAME = { \ + .name = # VAR, \ + .ptr = & VAR, \ + .type = MTYPE_ ## TYPE, \ + .mode = MODE, \ +}; \ +__link_set_add_data(linux_module_param_info, info_ ## NAME) #endif /* _LINUX_MODULEPARAM_H_ */ Added files: Index: src/sys/external/bsd/drm2/drm/drm_sysctl.c diff -u /dev/null src/sys/external/bsd/drm2/drm/drm_sysctl.c:1.1 --- /dev/null Tue Nov 11 21:24:40 2014 +++ src/sys/external/bsd/drm2/drm/drm_sysctl.c Tue Nov 11 21:24:40 2014 @@ -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); +} Index: src/sys/external/bsd/drm2/include/drm/drm_sysctl.h diff -u /dev/null src/sys/external/bsd/drm2/include/drm/drm_sysctl.h:1.1 --- /dev/null Tue Nov 11 21:24:40 2014 +++ src/sys/external/bsd/drm2/include/drm/drm_sysctl.h Tue Nov 11 21:24:40 2014 @@ -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 **);