1 /*
2 * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 /*
25 * Copyright (c) 2012 Intel Corporation. All rights reserved.
26 */
27
28 #include <sys/types.h>
29 #include <sys/errno.h>
30 #include <sys/conf.h>
31 #include <sys/kmem.h>
32 #include <sys/visual_io.h>
33 #include <sys/fbio.h>
34 #include <sys/ddi.h>
35 #include <sys/sunddi.h>
36 #include <sys/stat.h>
37 #include <sys/file.h>
38 #include <sys/open.h>
39 #include <sys/modctl.h>
40 #include <sys/pci.h>
41 #include <sys/kd.h>
42 #include <sys/ddi_impldefs.h>
43 #include <sys/sunldi.h>
44 #include <sys/mkdev.h>
45 #include "drmP.h"
46 #include <sys/agpgart.h>
47 #include <sys/agp/agpdefs.h>
48 #include <sys/agp/agpmaster_io.h>
49
50 /**
51 * drm_sysfs_device_add - adds a class device to sysfs for a character driver
52 * @dev: DRM device to be added
53 * @head: DRM head in question
54 *
55 * Add a DRM device to the DRM's device model class. We use @dev's PCI device
56 * as the parent for the Linux device, and make sure it has a file containing
57 * the driver we're using (for userspace compatibility).
58 */
drm_sysfs_device_add(struct drm_minor * minor)59 int drm_sysfs_device_add(struct drm_minor *minor)
60 {
61 struct drm_device *dev = minor->dev;
62 gfxp_vgatext_softc_ptr_t gfxp;
63 int ret;
64
65 switch (minor->type) {
66 case DRM_MINOR_AGPMASTER:
67 ret = agpmaster_attach(dev->devinfo,
68 (agp_master_softc_t **)&minor->private,
69 dev->pdev->pci_cfg_acc_handle, minor->index);
70 if (ret != DDI_SUCCESS) {
71 DRM_ERROR("agpmaster_attach failed");
72 return (ret);
73 }
74 return (0);
75
76 case DRM_MINOR_VGATEXT:
77 /* Generic graphics initialization */
78 gfxp = gfxp_vgatext_softc_alloc();
79 ret = gfxp_vgatext_attach(dev->devinfo, DDI_ATTACH, gfxp);
80 if (ret != DDI_SUCCESS) {
81 DRM_ERROR("gfxp_vgatext_attach failed");
82 return (EFAULT);
83 }
84 minor->private = gfxp;
85
86 ret = ddi_create_minor_node(dev->devinfo,
87 minor->name, S_IFCHR, minor->index, DDI_NT_DISPLAY, 0);
88 if (ret != DDI_SUCCESS) {
89 DRM_ERROR("ddi_create_minor_node failed");
90 return (EFAULT);
91 }
92 return (0);
93
94 case DRM_MINOR_LEGACY:
95 case DRM_MINOR_CONTROL:
96 case DRM_MINOR_RENDER:
97 ret = ddi_create_minor_node(dev->devinfo,
98 minor->name, S_IFCHR, minor->index, DDI_NT_DISPLAY_DRM, 0);
99 if (ret != DDI_SUCCESS) {
100 DRM_ERROR("ddi_create_minor_node failed");
101 return (EFAULT);
102 }
103 return (0);
104 }
105
106 return (ENOTSUP);
107 }
108
109 /**
110 * drm_sysfs_device_remove - remove DRM device
111 * @dev: DRM device to remove
112 *
113 * This call unregisters and cleans up a class device that was created with a
114 * call to drm_sysfs_device_add()
115 */
drm_sysfs_device_remove(struct drm_minor * minor)116 void drm_sysfs_device_remove(struct drm_minor *minor)
117 {
118 switch (minor->type) {
119 case DRM_MINOR_AGPMASTER:
120 if (minor->private) {
121 agpmaster_detach(
122 (agp_master_softc_t **)&minor->private);
123 minor->private = NULL;
124 }
125 break;
126
127 case DRM_MINOR_VGATEXT:
128 if (minor->private) {
129 (void) gfxp_vgatext_detach(minor->dev->devinfo,
130 DDI_DETACH, minor->private);
131 gfxp_vgatext_softc_free(minor->private);
132 minor->private = NULL;
133 }
134 /* FALLTHROUGH */
135 /* LINTED */
136 case DRM_MINOR_LEGACY:
137 case DRM_MINOR_CONTROL:
138 case DRM_MINOR_RENDER:
139 ddi_remove_minor_node(minor->dev->devinfo, minor->name);
140 }
141 }
142