diff options
| author | Gordon Ross <gordon.w.ross@gmail.com> | 2016-10-31 22:07:00 -0400 |
|---|---|---|
| committer | Gordon Ross <gordon.w.ross@gmail.com> | 2016-12-02 08:16:53 -0500 |
| commit | a727ef706f18aacc81c5d9981e121205e149f8bc (patch) | |
| tree | cc1d00503a7a152e4cc7d4e9acec7fe08996a36c /usr | |
| parent | 01d41e6dacd6f26957b16899a553d152ff46ec0c (diff) | |
| download | illumos-joyent-a727ef706f18aacc81c5d9981e121205e149f8bc.tar.gz | |
7622 Separate DRM+AGP devlinks stuff into its own module
Reviewed by: Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
Reviewed by: Toomas Soome <tsoome@me.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
Diffstat (limited to 'usr')
| -rw-r--r-- | usr/src/cmd/devfsadm/i386/Makefile | 1 | ||||
| -rw-r--r-- | usr/src/cmd/devfsadm/i386/drm_link_i386.c | 318 | ||||
| -rw-r--r-- | usr/src/cmd/devfsadm/i386/misc_link_i386.c | 248 | ||||
| -rw-r--r-- | usr/src/pkg/manifests/driver-graphics-drm.mf | 4 |
4 files changed, 323 insertions, 248 deletions
diff --git a/usr/src/cmd/devfsadm/i386/Makefile b/usr/src/cmd/devfsadm/i386/Makefile index 1f14c93dad..179db79979 100644 --- a/usr/src/cmd/devfsadm/i386/Makefile +++ b/usr/src/cmd/devfsadm/i386/Makefile @@ -23,6 +23,7 @@ # LINK_OBJS_i386 = \ + drm_link_i386.o \ misc_link_i386.o \ xen_link.o diff --git a/usr/src/cmd/devfsadm/i386/drm_link_i386.c b/usr/src/cmd/devfsadm/i386/drm_link_i386.c new file mode 100644 index 0000000000..ab29ab7899 --- /dev/null +++ b/usr/src/cmd/devfsadm/i386/drm_link_i386.c @@ -0,0 +1,318 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2010 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * Copyright 2012 Joyent, Inc. All rights reserved. + */ + +#include <regex.h> +#include <devfsadm.h> +#include <stdio.h> +#include <strings.h> +#include <stdlib.h> +#include <limits.h> +#include <ctype.h> + +/* + * Note: separate from misc_link_i386.c because this will later + * move to the gfx-drm gate. + */ + +static int agp_process(di_minor_t minor, di_node_t node); +static int drm_node(di_minor_t minor, di_node_t node); + +static devfsadm_create_t drm_cbt[] = { + { "drm", "ddi_display:drm", NULL, + TYPE_EXACT, ILEVEL_0, drm_node + }, + { "agp", "ddi_agp:pseudo", NULL, + TYPE_EXACT, ILEVEL_0, agp_process + }, + { "agp", "ddi_agp:target", NULL, + TYPE_EXACT, ILEVEL_0, agp_process + }, + { "agp", "ddi_agp:cpugart", NULL, + TYPE_EXACT, ILEVEL_0, agp_process + }, + { "agp", "ddi_agp:master", NULL, + TYPE_EXACT, ILEVEL_0, agp_process + }, +}; + +DEVFSADM_CREATE_INIT_V0(drm_cbt); + +/* + * For debugging, run devfsadm like this: + * devfsadm -V drm_mid -V devfsadm:enum -c drm + */ +static char *debug_mid = "drm_mid"; + +typedef enum { + DRIVER_AGPPSEUDO = 0, + DRIVER_AGPTARGET, + DRIVER_CPUGART, + DRIVER_AGPMASTER_DRM_I915, + DRIVER_AGPMASTER_DRM_RADEON, + DRIVER_AGPMASTER_VGATEXT, + DRIVER_UNKNOWN +} driver_defs_t; + +typedef struct { + char *driver_name; + int index; +} driver_name_table_entry_t; + +static driver_name_table_entry_t driver_name_table[] = { + { "agpgart", DRIVER_AGPPSEUDO }, + { "agptarget", DRIVER_AGPTARGET }, + { "amd64_gart", DRIVER_CPUGART }, + /* AGP master device managed by drm driver */ + { "i915", DRIVER_AGPMASTER_DRM_I915 }, + { "radeon", DRIVER_AGPMASTER_DRM_RADEON }, + { "vgatext", DRIVER_AGPMASTER_VGATEXT }, + { NULL, DRIVER_UNKNOWN } +}; + +static devfsadm_enumerate_t agptarget_rules[1] = + { "^agp$/^agptarget([0-9]+)$", 1, MATCH_ALL }; +static devfsadm_enumerate_t cpugart_rules[1] = + { "^agp$/^cpugart([0-9]+)$", 1, MATCH_ALL }; +static devfsadm_enumerate_t agpmaster_rules[1] = + { "^agp$/^agpmaster([0-9]+)$", 1, MATCH_ALL }; +static devfsadm_enumerate_t drm_rules[1] = + { "^dri$/^card([0-9]+)$", 1, MATCH_ALL }; + + +/* + * HOT auto cleanup of drm+agp links not desired. + */ +static devfsadm_remove_t drm_remove_cbt[] = { + { "agp", "^agpgart$", RM_POST, + ILEVEL_0, devfsadm_rm_all + }, + { "agp", "^agp/agpmaster[0-9]+$", RM_POST, + ILEVEL_0, devfsadm_rm_all + }, + { "agp", "^agp/agptarget[0-9]+$", RM_POST, + ILEVEL_0, devfsadm_rm_all + }, + { "agp", "^agp/cpugart[0-9]+$", RM_POST, + ILEVEL_0, devfsadm_rm_all + }, + { "drm", "^dri/card[0-9]+$", RM_POST, + ILEVEL_0, devfsadm_rm_all + }, +}; + +DEVFSADM_REMOVE_INIT_V0(drm_remove_cbt); + +static int +agp_process(di_minor_t minor, di_node_t node) +{ + char *minor_nm, *drv_nm; + char *devfspath; + char *I_path, *p_path, *buf; + char *name = (char *)NULL; + int i, index; + devfsadm_enumerate_t rules[1]; + + minor_nm = di_minor_name(minor); + drv_nm = di_driver_name(node); + + if ((minor_nm == NULL) || (drv_nm == NULL)) { + return (DEVFSADM_CONTINUE); + } + + devfsadm_print(debug_mid, "agp_process: minor=%s node=%s\n", + minor_nm, di_node_name(node)); + + devfspath = di_devfs_path(node); + if (devfspath == NULL) { + devfsadm_print(debug_mid, "agp_process: devfspath is NULL\n"); + return (DEVFSADM_CONTINUE); + } + + I_path = (char *)malloc(PATH_MAX); + + if (I_path == NULL) { + di_devfs_path_free(devfspath); + devfsadm_print(debug_mid, "agp_process: malloc failed\n"); + return (DEVFSADM_CONTINUE); + } + + p_path = (char *)malloc(PATH_MAX); + + if (p_path == NULL) { + devfsadm_print(debug_mid, "agp_process: malloc failed\n"); + di_devfs_path_free(devfspath); + free(I_path); + return (DEVFSADM_CONTINUE); + } + + (void) strlcpy(p_path, devfspath, PATH_MAX); + (void) strlcat(p_path, ":", PATH_MAX); + (void) strlcat(p_path, minor_nm, PATH_MAX); + di_devfs_path_free(devfspath); + + devfsadm_print(debug_mid, "agp_process: path %s\n", p_path); + + for (i = 0; ; i++) { + if ((driver_name_table[i].driver_name == NULL) || + (strcmp(drv_nm, driver_name_table[i].driver_name) == 0)) { + index = driver_name_table[i].index; + break; + } + } + switch (index) { + case DRIVER_AGPPSEUDO: + devfsadm_print(debug_mid, + "agp_process: psdeudo driver name\n"); + name = "agpgart"; + (void) snprintf(I_path, PATH_MAX, "%s", name); + devfsadm_print(debug_mid, + "mklink %s -> %s\n", I_path, p_path); + + (void) devfsadm_mklink(I_path, node, minor, 0); + + free(I_path); + free(p_path); + return (DEVFSADM_CONTINUE); + case DRIVER_AGPTARGET: + devfsadm_print(debug_mid, + "agp_process: target driver name\n"); + rules[0] = agptarget_rules[0]; + name = "agptarget"; + break; + case DRIVER_CPUGART: + devfsadm_print(debug_mid, + "agp_process: cpugart driver name\n"); + rules[0] = cpugart_rules[0]; + name = "cpugart"; + break; + case DRIVER_AGPMASTER_DRM_I915: + case DRIVER_AGPMASTER_DRM_RADEON: + case DRIVER_AGPMASTER_VGATEXT: + devfsadm_print(debug_mid, + "agp_process: agpmaster driver name\n"); + rules[0] = agpmaster_rules[0]; + name = "agpmaster"; + break; + case DRIVER_UNKNOWN: + devfsadm_print(debug_mid, + "agp_process: unknown driver name=%s\n", drv_nm); + free(I_path); + free(p_path); + return (DEVFSADM_CONTINUE); + } + + if (devfsadm_enumerate_int(p_path, 0, &buf, rules, 1)) { + devfsadm_print(debug_mid, "agp_process: exit/coninue\n"); + free(I_path); + free(p_path); + return (DEVFSADM_CONTINUE); + } + + + (void) snprintf(I_path, PATH_MAX, "agp/%s%s", name, buf); + + devfsadm_print(debug_mid, "agp_process: p_path=%s buf=%s\n", + p_path, buf); + + free(buf); + + devfsadm_print(debug_mid, "mklink %s -> %s\n", I_path, p_path); + + (void) devfsadm_mklink(I_path, node, minor, 0); + + free(p_path); + free(I_path); + + return (DEVFSADM_CONTINUE); +} + +static int +drm_node(di_minor_t minor, di_node_t node) +{ + char *minor_nm, *drv_nm; + char *devfspath; + char *I_path, *p_path, *buf; + char *name = "card"; + + minor_nm = di_minor_name(minor); + drv_nm = di_driver_name(node); + if ((minor_nm == NULL) || (drv_nm == NULL)) { + return (DEVFSADM_CONTINUE); + } + + devfsadm_print(debug_mid, "drm_node: minor=%s node=%s type=%s\n", + minor_nm, di_node_name(node), di_minor_nodetype(minor)); + + devfspath = di_devfs_path(node); + if (devfspath == NULL) { + devfsadm_print(debug_mid, "drm_node: devfspath is NULL\n"); + return (DEVFSADM_CONTINUE); + } + + I_path = (char *)malloc(PATH_MAX); + + if (I_path == NULL) { + di_devfs_path_free(devfspath); + devfsadm_print(debug_mid, "drm_node: malloc failed\n"); + return (DEVFSADM_CONTINUE); + } + + p_path = (char *)malloc(PATH_MAX); + + if (p_path == NULL) { + devfsadm_print(debug_mid, "drm_node: malloc failed\n"); + di_devfs_path_free(devfspath); + free(I_path); + return (DEVFSADM_CONTINUE); + } + + (void) strlcpy(p_path, devfspath, PATH_MAX); + (void) strlcat(p_path, ":", PATH_MAX); + (void) strlcat(p_path, minor_nm, PATH_MAX); + di_devfs_path_free(devfspath); + + devfsadm_print(debug_mid, "drm_node: p_path %s\n", p_path); + + if (devfsadm_enumerate_int(p_path, 0, &buf, drm_rules, 1)) { + free(p_path); + devfsadm_print(debug_mid, "drm_node: exit/coninue\n"); + return (DEVFSADM_CONTINUE); + } + (void) snprintf(I_path, PATH_MAX, "dri/%s%s", name, buf); + + devfsadm_print(debug_mid, "drm_node: p_path=%s buf=%s\n", + p_path, buf); + + free(buf); + + devfsadm_print(debug_mid, "mklink %s -> %s\n", I_path, p_path); + (void) devfsadm_mklink(I_path, node, minor, 0); + + free(p_path); + free(I_path); + + return (0); +} diff --git a/usr/src/cmd/devfsadm/i386/misc_link_i386.c b/usr/src/cmd/devfsadm/i386/misc_link_i386.c index 5d2e18ad8a..84a24b1092 100644 --- a/usr/src/cmd/devfsadm/i386/misc_link_i386.c +++ b/usr/src/cmd/devfsadm/i386/misc_link_i386.c @@ -44,8 +44,6 @@ static int vt00(di_minor_t minor, di_node_t node); static int kdmouse(di_minor_t minor, di_node_t node); static int ipmi(di_minor_t minor, di_node_t node); static int smbios(di_minor_t minor, di_node_t node); -static int agp_process(di_minor_t minor, di_node_t node); -static int drm_node(di_minor_t minor, di_node_t node); static int mc_node(di_minor_t minor, di_node_t node); static int xsvc(di_minor_t minor, di_node_t node); static int srn(di_minor_t minor, di_node_t node); @@ -57,9 +55,6 @@ static devfsadm_create_t misc_cbt[] = { { "vt00", "ddi_display", NULL, TYPE_EXACT, ILEVEL_0, vt00 }, - { "drm", "ddi_display:drm", NULL, - TYPE_EXACT, ILEVEL_0, drm_node - }, { "mouse", "ddi_mouse", "mouse8042", TYPE_EXACT | DRV_EXACT, ILEVEL_0, kdmouse }, @@ -82,18 +77,6 @@ static devfsadm_create_t misc_cbt[] = { { "serial", "ddi_serial:dialout,mb", NULL, TYPE_EXACT, ILEVEL_1, serial_dialout }, - { "agp", "ddi_agp:pseudo", NULL, - TYPE_EXACT, ILEVEL_0, agp_process - }, - { "agp", "ddi_agp:target", NULL, - TYPE_EXACT, ILEVEL_0, agp_process - }, - { "agp", "ddi_agp:cpugart", NULL, - TYPE_EXACT, ILEVEL_0, agp_process - }, - { "agp", "ddi_agp:master", NULL, - TYPE_EXACT, ILEVEL_0, agp_process - }, { "pseudo", "ddi_pseudo", NULL, TYPE_EXACT, ILEVEL_0, xsvc }, @@ -113,41 +96,6 @@ static devfsadm_create_t misc_cbt[] = { DEVFSADM_CREATE_INIT_V0(misc_cbt); -static char *debug_mid = "misc_mid"; - -typedef enum { - DRIVER_AGPPSEUDO = 0, - DRIVER_AGPTARGET, - DRIVER_CPUGART, - DRIVER_AGPMASTER_DRM_I915, - DRIVER_AGPMASTER_DRM_RADEON, - DRIVER_AGPMASTER_VGATEXT, - DRIVER_UNKNOWN -} driver_defs_t; - -typedef struct { - char *driver_name; - int index; -} driver_name_table_entry_t; - -static driver_name_table_entry_t driver_name_table[] = { - { "agpgart", DRIVER_AGPPSEUDO }, - { "agptarget", DRIVER_AGPTARGET }, - { "amd64_gart", DRIVER_CPUGART }, - /* AGP master device managed by drm driver */ - { "i915", DRIVER_AGPMASTER_DRM_I915 }, - { "radeon", DRIVER_AGPMASTER_DRM_RADEON }, - { "vgatext", DRIVER_AGPMASTER_VGATEXT }, - { NULL, DRIVER_UNKNOWN } -}; - -static devfsadm_enumerate_t agptarget_rules[1] = - { "^agp$/^agptarget([0-9]+)$", 1, MATCH_ALL }; -static devfsadm_enumerate_t cpugart_rules[1] = - { "^agp$/^cpugart([0-9]+)$", 1, MATCH_ALL }; -static devfsadm_enumerate_t agpmaster_rules[1] = - { "^agp$/^agpmaster([0-9]+)$", 1, MATCH_ALL }; - static devfsadm_remove_t misc_remove_cbt[] = { { "vt", "vt[0-9][0-9]", RM_PRE|RM_ALWAYS, ILEVEL_0, devfsadm_rm_all @@ -368,202 +316,6 @@ smbios(di_minor_t minor, di_node_t node) return (DEVFSADM_CONTINUE); } -static int -agp_process(di_minor_t minor, di_node_t node) -{ - char *minor_nm, *drv_nm; - char *devfspath; - char *I_path, *p_path, *buf; - char *name = (char *)NULL; - int i, index; - devfsadm_enumerate_t rules[1]; - - minor_nm = di_minor_name(minor); - drv_nm = di_driver_name(node); - - if ((minor_nm == NULL) || (drv_nm == NULL)) { - return (DEVFSADM_CONTINUE); - } - - devfsadm_print(debug_mid, "agp_process: minor=%s node=%s\n", - minor_nm, di_node_name(node)); - - devfspath = di_devfs_path(node); - if (devfspath == NULL) { - devfsadm_print(debug_mid, "agp_process: devfspath is NULL\n"); - return (DEVFSADM_CONTINUE); - } - - I_path = (char *)malloc(PATH_MAX); - - if (I_path == NULL) { - di_devfs_path_free(devfspath); - devfsadm_print(debug_mid, "agp_process: malloc failed\n"); - return (DEVFSADM_CONTINUE); - } - - p_path = (char *)malloc(PATH_MAX); - - if (p_path == NULL) { - devfsadm_print(debug_mid, "agp_process: malloc failed\n"); - di_devfs_path_free(devfspath); - free(I_path); - return (DEVFSADM_CONTINUE); - } - - (void) strlcpy(p_path, devfspath, PATH_MAX); - (void) strlcat(p_path, ":", PATH_MAX); - (void) strlcat(p_path, minor_nm, PATH_MAX); - di_devfs_path_free(devfspath); - - devfsadm_print(debug_mid, "agp_process: path %s\n", p_path); - - for (i = 0; ; i++) { - if ((driver_name_table[i].driver_name == NULL) || - (strcmp(drv_nm, driver_name_table[i].driver_name) == 0)) { - index = driver_name_table[i].index; - break; - } - } - switch (index) { - case DRIVER_AGPPSEUDO: - devfsadm_print(debug_mid, - "agp_process: psdeudo driver name\n"); - name = "agpgart"; - (void) snprintf(I_path, PATH_MAX, "%s", name); - devfsadm_print(debug_mid, - "mklink %s -> %s\n", I_path, p_path); - - (void) devfsadm_mklink(I_path, node, minor, 0); - - free(I_path); - free(p_path); - return (DEVFSADM_CONTINUE); - case DRIVER_AGPTARGET: - devfsadm_print(debug_mid, - "agp_process: target driver name\n"); - rules[0] = agptarget_rules[0]; - name = "agptarget"; - break; - case DRIVER_CPUGART: - devfsadm_print(debug_mid, - "agp_process: cpugart driver name\n"); - rules[0] = cpugart_rules[0]; - name = "cpugart"; - break; - case DRIVER_AGPMASTER_DRM_I915: - case DRIVER_AGPMASTER_DRM_RADEON: - case DRIVER_AGPMASTER_VGATEXT: - devfsadm_print(debug_mid, - "agp_process: agpmaster driver name\n"); - rules[0] = agpmaster_rules[0]; - name = "agpmaster"; - break; - case DRIVER_UNKNOWN: - devfsadm_print(debug_mid, - "agp_process: unknown driver name=%s\n", drv_nm); - free(I_path); - free(p_path); - return (DEVFSADM_CONTINUE); - } - - if (devfsadm_enumerate_int(p_path, 0, &buf, rules, 1)) { - devfsadm_print(debug_mid, "agp_process: exit/coninue\n"); - free(I_path); - free(p_path); - return (DEVFSADM_CONTINUE); - } - - - (void) snprintf(I_path, PATH_MAX, "agp/%s%s", name, buf); - - devfsadm_print(debug_mid, "agp_process: p_path=%s buf=%s\n", - p_path, buf); - - free(buf); - - devfsadm_print(debug_mid, "mklink %s -> %s\n", I_path, p_path); - - (void) devfsadm_mklink(I_path, node, minor, 0); - - free(p_path); - free(I_path); - - return (DEVFSADM_CONTINUE); -} - -static int -drm_node(di_minor_t minor, di_node_t node) -{ - char *minor_nm, *drv_nm; - char *devfspath; - char *I_path, *p_path, *buf; - char *name = "card"; - - devfsadm_enumerate_t drm_rules[1] = {"^dri$/^card([0-9]+)$", 1, - MATCH_ALL }; - - - minor_nm = di_minor_name(minor); - drv_nm = di_driver_name(node); - if ((minor_nm == NULL) || (drv_nm == NULL)) { - return (DEVFSADM_CONTINUE); - } - - devfsadm_print(debug_mid, "drm_node: minor=%s node=%s type=%s\n", - minor_nm, di_node_name(node), di_minor_nodetype(minor)); - - devfspath = di_devfs_path(node); - if (devfspath == NULL) { - devfsadm_print(debug_mid, "drm_node: devfspath is NULL\n"); - return (DEVFSADM_CONTINUE); - } - - I_path = (char *)malloc(PATH_MAX); - - if (I_path == NULL) { - di_devfs_path_free(devfspath); - devfsadm_print(debug_mid, "drm_node: malloc failed\n"); - return (DEVFSADM_CONTINUE); - } - - p_path = (char *)malloc(PATH_MAX); - - if (p_path == NULL) { - devfsadm_print(debug_mid, "drm_node: malloc failed\n"); - di_devfs_path_free(devfspath); - free(I_path); - return (DEVFSADM_CONTINUE); - } - - (void) strlcpy(p_path, devfspath, PATH_MAX); - (void) strlcat(p_path, ":", PATH_MAX); - (void) strlcat(p_path, minor_nm, PATH_MAX); - di_devfs_path_free(devfspath); - - devfsadm_print(debug_mid, "drm_node: p_path %s\n", p_path); - - if (devfsadm_enumerate_int(p_path, 0, &buf, drm_rules, 1)) { - free(p_path); - devfsadm_print(debug_mid, "drm_node: exit/coninue\n"); - return (DEVFSADM_CONTINUE); - } - (void) snprintf(I_path, PATH_MAX, "dri/%s%s", name, buf); - - devfsadm_print(debug_mid, "drm_node: p_path=%s buf=%s\n", - p_path, buf); - - free(buf); - - devfsadm_print(debug_mid, "mklink %s -> %s\n", I_path, p_path); - (void) devfsadm_mklink(I_path, node, minor, 0); - - free(p_path); - free(I_path); - - return (0); -} - /* * /dev/mc/mc<chipid> -> /devices/.../pci1022,1102@<chipid+24>,2:mc-amd */ diff --git a/usr/src/pkg/manifests/driver-graphics-drm.mf b/usr/src/pkg/manifests/driver-graphics-drm.mf index a1c3a94e78..80ffff7208 100644 --- a/usr/src/pkg/manifests/driver-graphics-drm.mf +++ b/usr/src/pkg/manifests/driver-graphics-drm.mf @@ -41,6 +41,9 @@ dir path=kernel/drv group=sys dir path=kernel/drv/$(ARCH64) group=sys dir path=kernel/misc group=sys dir path=kernel/misc/$(ARCH64) group=sys +dir path=usr/lib +dir path=usr/lib/devfsadm group=sys +dir path=usr/lib/devfsadm/linkmod group=sys dir path=usr/share/man dir path=usr/share/man/man7d driver name=i915 perms="* 0644 root sys" \ @@ -74,6 +77,7 @@ file path=kernel/drv/i915 group=sys file path=kernel/drv/radeon group=sys file path=kernel/misc/$(ARCH64)/drm group=sys mode=0755 file path=kernel/misc/drm group=sys mode=0755 +file path=usr/lib/devfsadm/linkmod/SUNW_drm_link_i386.so group=sys file path=usr/share/man/man7d/i915.7d file path=usr/share/man/man7d/radeon.7d legacy pkg=SUNWdrmr desc="Direct Rendering Manager kernel drivers and modules" \ |
