aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu
diff options
context:
space:
mode:
authorJordan Crouse <jcrouse@codeaurora.org>2010-05-27 15:40:25 -0400
committerDave Airlie <airlied@redhat.com>2010-05-31 20:07:39 -0400
commitdcdb167402cbdca1d021bdfa5f63995ee0a79317 (patch)
tree3cd0ab1189d972b59daaaf863f518d7b94d2de7a /drivers/gpu
parent01d73a6967f12fe6c4bbde1834a9fe662264a2eb (diff)
drm: Add support for platform devices to register as DRM devices
Allow platform devices without PCI resources to be DRM devices. [airlied: fixup warnings with dev pointers] Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org> Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'drivers/gpu')
-rw-r--r--drivers/gpu/drm/Kconfig4
-rw-r--r--drivers/gpu/drm/Makefile2
-rw-r--r--drivers/gpu/drm/drm_drv.c37
-rw-r--r--drivers/gpu/drm/drm_edid.c4
-rw-r--r--drivers/gpu/drm/drm_info.c23
-rw-r--r--drivers/gpu/drm/drm_ioctl.c71
-rw-r--r--drivers/gpu/drm/drm_irq.c15
-rw-r--r--drivers/gpu/drm/drm_pci.c143
-rw-r--r--drivers/gpu/drm/drm_platform.c122
-rw-r--r--drivers/gpu/drm/drm_stub.c89
-rw-r--r--drivers/gpu/drm/drm_sysfs.c3
-rw-r--r--drivers/gpu/drm/i915/i915_dma.c1
-rw-r--r--drivers/gpu/drm/i915/i915_drv.c2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_drv.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_drv.c2
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.c2
16 files changed, 358 insertions, 164 deletions
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 88910e5a2c77..520ab23d8a3f 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -6,7 +6,7 @@
6# 6#
7menuconfig DRM 7menuconfig DRM
8 tristate "Direct Rendering Manager (XFree86 4.1.0 and higher DRI support)" 8 tristate "Direct Rendering Manager (XFree86 4.1.0 and higher DRI support)"
9 depends on (AGP || AGP=n) && PCI && !EMULATED_CMPXCHG && MMU 9 depends on (AGP || AGP=n) && !EMULATED_CMPXCHG && MMU
10 select I2C 10 select I2C
11 select I2C_ALGOBIT 11 select I2C_ALGOBIT
12 select SLOW_WORK 12 select SLOW_WORK
@@ -17,7 +17,7 @@ menuconfig DRM
17 These modules provide support for synchronization, security, and 17 These modules provide support for synchronization, security, and
18 DMA transfers. Please see <http://dri.sourceforge.net/> for more 18 DMA transfers. Please see <http://dri.sourceforge.net/> for more
19 details. You should also select and configure AGP 19 details. You should also select and configure AGP
20 (/dev/agpgart) support. 20 (/dev/agpgart) support if it is available for your platform.
21 21
22config DRM_KMS_HELPER 22config DRM_KMS_HELPER
23 tristate 23 tristate
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index abe3f446ca48..b4b2b480d0ce 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -9,7 +9,7 @@ drm-y := drm_auth.o drm_buffer.o drm_bufs.o drm_cache.o \
9 drm_drv.o drm_fops.o drm_gem.o drm_ioctl.o drm_irq.o \ 9 drm_drv.o drm_fops.o drm_gem.o drm_ioctl.o drm_irq.o \
10 drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \ 10 drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \
11 drm_agpsupport.o drm_scatter.o ati_pcigart.o drm_pci.o \ 11 drm_agpsupport.o drm_scatter.o ati_pcigart.o drm_pci.o \
12 drm_sysfs.o drm_hashtab.o drm_sman.o drm_mm.o \ 12 drm_platform.o drm_sysfs.o drm_hashtab.o drm_sman.o drm_mm.o \
13 drm_crtc.o drm_modes.o drm_edid.o \ 13 drm_crtc.o drm_modes.o drm_edid.o \
14 drm_info.o drm_debugfs.o drm_encoder_slave.o 14 drm_info.o drm_debugfs.o drm_encoder_slave.o
15 15
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 4a66201edaec..510bc87d98f6 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -243,47 +243,20 @@ int drm_lastclose(struct drm_device * dev)
243 * 243 *
244 * Initializes an array of drm_device structures, and attempts to 244 * Initializes an array of drm_device structures, and attempts to
245 * initialize all available devices, using consecutive minors, registering the 245 * initialize all available devices, using consecutive minors, registering the
246 * stubs and initializing the AGP device. 246 * stubs and initializing the device.
247 * 247 *
248 * Expands the \c DRIVER_PREINIT and \c DRIVER_POST_INIT macros before and 248 * Expands the \c DRIVER_PREINIT and \c DRIVER_POST_INIT macros before and
249 * after the initialization for driver customization. 249 * after the initialization for driver customization.
250 */ 250 */
251int drm_init(struct drm_driver *driver) 251int drm_init(struct drm_driver *driver)
252{ 252{
253 struct pci_dev *pdev = NULL;
254 const struct pci_device_id *pid;
255 int i;
256
257 DRM_DEBUG("\n"); 253 DRM_DEBUG("\n");
258
259 INIT_LIST_HEAD(&driver->device_list); 254 INIT_LIST_HEAD(&driver->device_list);
260 255
261 if (driver->driver_features & DRIVER_MODESET) 256 if (driver->driver_features & DRIVER_USE_PLATFORM_DEVICE)
262 return pci_register_driver(&driver->pci_driver); 257 return drm_platform_init(driver);
263 258 else
264 /* If not using KMS, fall back to stealth mode manual scanning. */ 259 return drm_pci_init(driver);
265 for (i = 0; driver->pci_driver.id_table[i].vendor != 0; i++) {
266 pid = &driver->pci_driver.id_table[i];
267
268 /* Loop around setting up a DRM device for each PCI device
269 * matching our ID and device class. If we had the internal
270 * function that pci_get_subsys and pci_get_class used, we'd
271 * be able to just pass pid in instead of doing a two-stage
272 * thing.
273 */
274 pdev = NULL;
275 while ((pdev =
276 pci_get_subsys(pid->vendor, pid->device, pid->subvendor,
277 pid->subdevice, pdev)) != NULL) {
278 if ((pdev->class & pid->class_mask) != pid->class)
279 continue;
280
281 /* stealth mode requires a manual probe */
282 pci_dev_get(pdev);
283 drm_get_dev(pdev, pid, driver);
284 }
285 }
286 return 0;
287} 260}
288 261
289EXPORT_SYMBOL(drm_init); 262EXPORT_SYMBOL(drm_init);
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index c1981861bbbd..83d8072066cb 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -282,7 +282,7 @@ drm_do_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
282 return block; 282 return block;
283 283
284carp: 284carp:
285 dev_warn(&connector->dev->pdev->dev, "%s: EDID block %d invalid.\n", 285 dev_warn(connector->dev->dev, "%s: EDID block %d invalid.\n",
286 drm_get_connector_name(connector), j); 286 drm_get_connector_name(connector), j);
287 287
288out: 288out:
@@ -1626,7 +1626,7 @@ int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
1626 return 0; 1626 return 0;
1627 } 1627 }
1628 if (!drm_edid_is_valid(edid)) { 1628 if (!drm_edid_is_valid(edid)) {
1629 dev_warn(&connector->dev->pdev->dev, "%s: EDID invalid.\n", 1629 dev_warn(connector->dev->dev, "%s: EDID invalid.\n",
1630 drm_get_connector_name(connector)); 1630 drm_get_connector_name(connector));
1631 return 0; 1631 return 0;
1632 } 1632 }
diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
index f0f6c6b93f3a..2ef2c7827243 100644
--- a/drivers/gpu/drm/drm_info.c
+++ b/drivers/gpu/drm/drm_info.c
@@ -51,13 +51,24 @@ int drm_name_info(struct seq_file *m, void *data)
51 if (!master) 51 if (!master)
52 return 0; 52 return 0;
53 53
54 if (master->unique) { 54 if (drm_core_check_feature(dev, DRIVER_USE_PLATFORM_DEVICE)) {
55 seq_printf(m, "%s %s %s\n", 55 if (master->unique) {
56 dev->driver->pci_driver.name, 56 seq_printf(m, "%s %s %s\n",
57 pci_name(dev->pdev), master->unique); 57 dev->driver->platform_device->name,
58 dev_name(dev->dev), master->unique);
59 } else {
60 seq_printf(m, "%s\n",
61 dev->driver->platform_device->name);
62 }
58 } else { 63 } else {
59 seq_printf(m, "%s %s\n", dev->driver->pci_driver.name, 64 if (master->unique) {
60 pci_name(dev->pdev)); 65 seq_printf(m, "%s %s %s\n",
66 dev->driver->pci_driver.name,
67 dev_name(dev->dev), master->unique);
68 } else {
69 seq_printf(m, "%s %s\n", dev->driver->pci_driver.name,
70 dev_name(dev->dev));
71 }
61 } 72 }
62 73
63 return 0; 74 return 0;
diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
index 9b9ff46c2378..76d3d18056dd 100644
--- a/drivers/gpu/drm/drm_ioctl.c
+++ b/drivers/gpu/drm/drm_ioctl.c
@@ -132,32 +132,57 @@ static int drm_set_busid(struct drm_device *dev, struct drm_file *file_priv)
132 struct drm_master *master = file_priv->master; 132 struct drm_master *master = file_priv->master;
133 int len; 133 int len;
134 134
135 if (master->unique != NULL) 135 if (drm_core_check_feature(dev, DRIVER_USE_PLATFORM_DEVICE)) {
136 return -EBUSY; 136 master->unique_len = 10 + strlen(dev->platformdev->name);
137 137 master->unique = kmalloc(master->unique_len + 1, GFP_KERNEL);
138 master->unique_len = 40; 138
139 master->unique_size = master->unique_len; 139 if (master->unique == NULL)
140 master->unique = kmalloc(master->unique_size, GFP_KERNEL); 140 return -ENOMEM;
141 if (master->unique == NULL) 141
142 return -ENOMEM; 142 len = snprintf(master->unique, master->unique_len,
143 "platform:%s", dev->platformdev->name);
144
145 if (len > master->unique_len)
146 DRM_ERROR("Unique buffer overflowed\n");
147
148 dev->devname =
149 kmalloc(strlen(dev->platformdev->name) +
150 master->unique_len + 2, GFP_KERNEL);
151
152 if (dev->devname == NULL)
153 return -ENOMEM;
154
155 sprintf(dev->devname, "%s@%s", dev->platformdev->name,
156 master->unique);
157
158 } else {
159 master->unique_len = 40;
160 master->unique_size = master->unique_len;
161 master->unique = kmalloc(master->unique_size, GFP_KERNEL);
162 if (master->unique == NULL)
163 return -ENOMEM;
164
165 len = snprintf(master->unique, master->unique_len,
166 "pci:%04x:%02x:%02x.%d",
167 drm_get_pci_domain(dev),
168 dev->pdev->bus->number,
169 PCI_SLOT(dev->pdev->devfn),
170 PCI_FUNC(dev->pdev->devfn));
171 if (len >= master->unique_len)
172 DRM_ERROR("buffer overflow");
173 else
174 master->unique_len = len;
143 175
144 len = snprintf(master->unique, master->unique_len, "pci:%04x:%02x:%02x.%d", 176 dev->devname =
145 drm_get_pci_domain(dev), 177 kmalloc(strlen(dev->driver->pci_driver.name) +
146 dev->pdev->bus->number, 178 master->unique_len + 2, GFP_KERNEL);
147 PCI_SLOT(dev->pdev->devfn),
148 PCI_FUNC(dev->pdev->devfn));
149 if (len >= master->unique_len)
150 DRM_ERROR("buffer overflow");
151 else
152 master->unique_len = len;
153 179
154 dev->devname = kmalloc(strlen(dev->driver->pci_driver.name) + 180 if (dev->devname == NULL)
155 master->unique_len + 2, GFP_KERNEL); 181 return -ENOMEM;
156 if (dev->devname == NULL)
157 return -ENOMEM;
158 182
159 sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name, 183 sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name,
160 master->unique); 184 master->unique);
185 }
161 186
162 return 0; 187 return 0;
163} 188}
diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index a263b7070fc6..6353b625e099 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -57,6 +57,9 @@ int drm_irq_by_busid(struct drm_device *dev, void *data,
57{ 57{
58 struct drm_irq_busid *p = data; 58 struct drm_irq_busid *p = data;
59 59
60 if (drm_core_check_feature(dev, DRIVER_USE_PLATFORM_DEVICE))
61 return -EINVAL;
62
60 if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ)) 63 if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
61 return -EINVAL; 64 return -EINVAL;
62 65
@@ -211,7 +214,7 @@ int drm_irq_install(struct drm_device *dev)
211 if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ)) 214 if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
212 return -EINVAL; 215 return -EINVAL;
213 216
214 if (dev->pdev->irq == 0) 217 if (drm_dev_to_irq(dev) == 0)
215 return -EINVAL; 218 return -EINVAL;
216 219
217 mutex_lock(&dev->struct_mutex); 220 mutex_lock(&dev->struct_mutex);
@@ -229,7 +232,7 @@ int drm_irq_install(struct drm_device *dev)
229 dev->irq_enabled = 1; 232 dev->irq_enabled = 1;
230 mutex_unlock(&dev->struct_mutex); 233 mutex_unlock(&dev->struct_mutex);
231 234
232 DRM_DEBUG("irq=%d\n", dev->pdev->irq); 235 DRM_DEBUG("irq=%d\n", drm_dev_to_irq(dev));
233 236
234 /* Before installing handler */ 237 /* Before installing handler */
235 dev->driver->irq_preinstall(dev); 238 dev->driver->irq_preinstall(dev);
@@ -302,14 +305,14 @@ int drm_irq_uninstall(struct drm_device * dev)
302 if (!irq_enabled) 305 if (!irq_enabled)
303 return -EINVAL; 306 return -EINVAL;
304 307
305 DRM_DEBUG("irq=%d\n", dev->pdev->irq); 308 DRM_DEBUG("irq=%d\n", drm_dev_to_irq(dev));
306 309
307 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 310 if (!drm_core_check_feature(dev, DRIVER_MODESET))
308 vga_client_register(dev->pdev, NULL, NULL, NULL); 311 vga_client_register(dev->pdev, NULL, NULL, NULL);
309 312
310 dev->driver->irq_uninstall(dev); 313 dev->driver->irq_uninstall(dev);
311 314
312 free_irq(dev->pdev->irq, dev); 315 free_irq(drm_dev_to_irq(dev), dev);
313 316
314 return 0; 317 return 0;
315} 318}
@@ -341,7 +344,7 @@ int drm_control(struct drm_device *dev, void *data,
341 if (drm_core_check_feature(dev, DRIVER_MODESET)) 344 if (drm_core_check_feature(dev, DRIVER_MODESET))
342 return 0; 345 return 0;
343 if (dev->if_version < DRM_IF_VERSION(1, 2) && 346 if (dev->if_version < DRM_IF_VERSION(1, 2) &&
344 ctl->irq != dev->pdev->irq) 347 ctl->irq != drm_dev_to_irq(dev))
345 return -EINVAL; 348 return -EINVAL;
346 return drm_irq_install(dev); 349 return drm_irq_install(dev);
347 case DRM_UNINST_HANDLER: 350 case DRM_UNINST_HANDLER:
@@ -651,7 +654,7 @@ int drm_wait_vblank(struct drm_device *dev, void *data,
651 int ret = 0; 654 int ret = 0;
652 unsigned int flags, seq, crtc; 655 unsigned int flags, seq, crtc;
653 656
654 if ((!dev->pdev->irq) || (!dev->irq_enabled)) 657 if ((!drm_dev_to_irq(dev)) || (!dev->irq_enabled))
655 return -EINVAL; 658 return -EINVAL;
656 659
657 if (vblwait->request.type & _DRM_VBLANK_SIGNAL) 660 if (vblwait->request.type & _DRM_VBLANK_SIGNAL)
diff --git a/drivers/gpu/drm/drm_pci.c b/drivers/gpu/drm/drm_pci.c
index 2ea9ad4a8d69..e20f78b542a7 100644
--- a/drivers/gpu/drm/drm_pci.c
+++ b/drivers/gpu/drm/drm_pci.c
@@ -124,4 +124,147 @@ void drm_pci_free(struct drm_device * dev, drm_dma_handle_t * dmah)
124 124
125EXPORT_SYMBOL(drm_pci_free); 125EXPORT_SYMBOL(drm_pci_free);
126 126
127#ifdef CONFIG_PCI
128/**
129 * Register.
130 *
131 * \param pdev - PCI device structure
132 * \param ent entry from the PCI ID table with device type flags
133 * \return zero on success or a negative number on failure.
134 *
135 * Attempt to gets inter module "drm" information. If we are first
136 * then register the character device and inter module information.
137 * Try and register, if we fail to register, backout previous work.
138 */
139int drm_get_pci_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
140 struct drm_driver *driver)
141{
142 struct drm_device *dev;
143 int ret;
144
145 DRM_DEBUG("\n");
146
147 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
148 if (!dev)
149 return -ENOMEM;
150
151 ret = pci_enable_device(pdev);
152 if (ret)
153 goto err_g1;
154
155 pci_set_master(pdev);
156
157 dev->pdev = pdev;
158 dev->dev = &pdev->dev;
159
160 dev->pci_device = pdev->device;
161 dev->pci_vendor = pdev->vendor;
162
163#ifdef __alpha__
164 dev->hose = pdev->sysdata;
165#endif
166
167 if ((ret = drm_fill_in_dev(dev, ent, driver))) {
168 printk(KERN_ERR "DRM: Fill_in_dev failed.\n");
169 goto err_g2;
170 }
171
172 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
173 pci_set_drvdata(pdev, dev);
174 ret = drm_get_minor(dev, &dev->control, DRM_MINOR_CONTROL);
175 if (ret)
176 goto err_g2;
177 }
178
179 if ((ret = drm_get_minor(dev, &dev->primary, DRM_MINOR_LEGACY)))
180 goto err_g3;
181
182 if (dev->driver->load) {
183 ret = dev->driver->load(dev, ent->driver_data);
184 if (ret)
185 goto err_g4;
186 }
187
188 /* setup the grouping for the legacy output */
189 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
190 ret = drm_mode_group_init_legacy_group(dev,
191 &dev->primary->mode_group);
192 if (ret)
193 goto err_g4;
194 }
195
196 list_add_tail(&dev->driver_item, &driver->device_list);
197
198 DRM_INFO("Initialized %s %d.%d.%d %s for %s on minor %d\n",
199 driver->name, driver->major, driver->minor, driver->patchlevel,
200 driver->date, pci_name(pdev), dev->primary->index);
201
202 return 0;
203
204err_g4:
205 drm_put_minor(&dev->primary);
206err_g3:
207 if (drm_core_check_feature(dev, DRIVER_MODESET))
208 drm_put_minor(&dev->control);
209err_g2:
210 pci_disable_device(pdev);
211err_g1:
212 kfree(dev);
213 return ret;
214}
215EXPORT_SYMBOL(drm_get_pci_dev);
216
217/**
218 * PCI device initialization. Called via drm_init at module load time,
219 *
220 * \return zero on success or a negative number on failure.
221 *
222 * Initializes a drm_device structures,registering the
223 * stubs and initializing the AGP device.
224 *
225 * Expands the \c DRIVER_PREINIT and \c DRIVER_POST_INIT macros before and
226 * after the initialization for driver customization.
227 */
228int drm_pci_init(struct drm_driver *driver)
229{
230 struct pci_dev *pdev = NULL;
231 const struct pci_device_id *pid;
232 int i;
233
234 if (driver->driver_features & DRIVER_MODESET)
235 return pci_register_driver(&driver->pci_driver);
236
237 /* If not using KMS, fall back to stealth mode manual scanning. */
238 for (i = 0; driver->pci_driver.id_table[i].vendor != 0; i++) {
239 pid = &driver->pci_driver.id_table[i];
240
241 /* Loop around setting up a DRM device for each PCI device
242 * matching our ID and device class. If we had the internal
243 * function that pci_get_subsys and pci_get_class used, we'd
244 * be able to just pass pid in instead of doing a two-stage
245 * thing.
246 */
247 pdev = NULL;
248 while ((pdev =
249 pci_get_subsys(pid->vendor, pid->device, pid->subvendor,
250 pid->subdevice, pdev)) != NULL) {
251 if ((pdev->class & pid->class_mask) != pid->class)
252 continue;
253
254 /* stealth mode requires a manual probe */
255 pci_dev_get(pdev);
256 drm_get_pci_dev(pdev, pid, driver);
257 }
258 }
259 return 0;
260}
261
262#else
263
264int drm_pci_init(struct drm_driver *driver)
265{
266 return -1;
267}
268
269#endif
127/*@}*/ 270/*@}*/
diff --git a/drivers/gpu/drm/drm_platform.c b/drivers/gpu/drm/drm_platform.c
new file mode 100644
index 000000000000..460e9a3afa8d
--- /dev/null
+++ b/drivers/gpu/drm/drm_platform.c
@@ -0,0 +1,122 @@
1/*
2 * Derived from drm_pci.c
3 *
4 * Copyright 2003 José Fonseca.
5 * Copyright 2003 Leif Delgass.
6 * Copyright (c) 2009, Code Aurora Forum.
7 * All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
18 * Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
24 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 */
27
28#include "drmP.h"
29
30/**
31 * Register.
32 *
33 * \param platdev - Platform device struture
34 * \return zero on success or a negative number on failure.
35 *
36 * Attempt to gets inter module "drm" information. If we are first
37 * then register the character device and inter module information.
38 * Try and register, if we fail to register, backout previous work.
39 */
40
41int drm_get_platform_dev(struct platform_device *platdev,
42 struct drm_driver *driver)
43{
44 struct drm_device *dev;
45 int ret;
46
47 DRM_DEBUG("\n");
48
49 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
50 if (!dev)
51 return -ENOMEM;
52
53 dev->platformdev = platdev;
54 dev->dev = &platdev->dev;
55
56 ret = drm_fill_in_dev(dev, NULL, driver);
57
58 if (ret) {
59 printk(KERN_ERR "DRM: Fill_in_dev failed.\n");
60 goto err_g1;
61 }
62
63 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
64 dev_set_drvdata(&platdev->dev, dev);
65 ret = drm_get_minor(dev, &dev->control, DRM_MINOR_CONTROL);
66 if (ret)
67 goto err_g1;
68 }
69
70 ret = drm_get_minor(dev, &dev->primary, DRM_MINOR_LEGACY);
71 if (ret)
72 goto err_g2;
73
74 if (dev->driver->load) {
75 ret = dev->driver->load(dev, 0);
76 if (ret)
77 goto err_g3;
78 }
79
80 /* setup the grouping for the legacy output */
81 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
82 ret = drm_mode_group_init_legacy_group(dev,
83 &dev->primary->mode_group);
84 if (ret)
85 goto err_g3;
86 }
87
88 list_add_tail(&dev->driver_item, &driver->device_list);
89
90 DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
91 driver->name, driver->major, driver->minor, driver->patchlevel,
92 driver->date, dev->primary->index);
93
94 return 0;
95
96err_g3:
97 drm_put_minor(&dev->primary);
98err_g2:
99 if (drm_core_check_feature(dev, DRIVER_MODESET))
100 drm_put_minor(&dev->control);
101err_g1:
102 kfree(dev);
103 return ret;
104}
105EXPORT_SYMBOL(drm_get_platform_dev);
106
107/**
108 * Platform device initialization. Called via drm_init at module load time,
109 *
110 * \return zero on success or a negative number on failure.
111 *
112 * Initializes a drm_device structures,registering the
113 * stubs
114 *
115 * Expands the \c DRIVER_PREINIT and \c DRIVER_POST_INIT macros before and
116 * after the initialization for driver customization.
117 */
118
119int drm_platform_init(struct drm_driver *driver)
120{
121 return drm_get_platform_dev(driver->platform_device, driver);
122}
diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
index a0c365f2e521..63575e2fa882 100644
--- a/drivers/gpu/drm/drm_stub.c
+++ b/drivers/gpu/drm/drm_stub.c
@@ -224,7 +224,7 @@ int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
224 return 0; 224 return 0;
225} 225}
226 226
227static int drm_fill_in_dev(struct drm_device * dev, struct pci_dev *pdev, 227int drm_fill_in_dev(struct drm_device *dev,
228 const struct pci_device_id *ent, 228 const struct pci_device_id *ent,
229 struct drm_driver *driver) 229 struct drm_driver *driver)
230{ 230{
@@ -245,14 +245,6 @@ static int drm_fill_in_dev(struct drm_device * dev, struct pci_dev *pdev,
245 245
246 idr_init(&dev->drw_idr); 246 idr_init(&dev->drw_idr);
247 247
248 dev->pdev = pdev;
249 dev->pci_device = pdev->device;
250 dev->pci_vendor = pdev->vendor;
251
252#ifdef __alpha__
253 dev->hose = pdev->sysdata;
254#endif
255
256 if (drm_ht_create(&dev->map_hash, 12)) { 248 if (drm_ht_create(&dev->map_hash, 12)) {
257 return -ENOMEM; 249 return -ENOMEM;
258 } 250 }
@@ -321,7 +313,7 @@ static int drm_fill_in_dev(struct drm_device * dev, struct pci_dev *pdev,
321 * create the proc init entry via proc_init(). This routines assigns 313 * create the proc init entry via proc_init(). This routines assigns
322 * minor numbers to secondary heads of multi-headed cards 314 * minor numbers to secondary heads of multi-headed cards
323 */ 315 */
324static int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type) 316int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type)
325{ 317{
326 struct drm_minor *new_minor; 318 struct drm_minor *new_minor;
327 int ret; 319 int ret;
@@ -388,83 +380,6 @@ err_idr:
388} 380}
389 381
390/** 382/**
391 * Register.
392 *
393 * \param pdev - PCI device structure
394 * \param ent entry from the PCI ID table with device type flags
395 * \return zero on success or a negative number on failure.
396 *
397 * Attempt to gets inter module "drm" information. If we are first
398 * then register the character device and inter module information.
399 * Try and register, if we fail to register, backout previous work.
400 */
401int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
402 struct drm_driver *driver)
403{
404 struct drm_device *dev;
405 int ret;
406
407 DRM_DEBUG("\n");
408
409 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
410 if (!dev)
411 return -ENOMEM;
412
413 ret = pci_enable_device(pdev);
414 if (ret)
415 goto err_g1;
416
417 pci_set_master(pdev);
418 if ((ret = drm_fill_in_dev(dev, pdev, ent, driver))) {
419 printk(KERN_ERR "DRM: Fill_in_dev failed.\n");
420 goto err_g2;
421 }
422
423 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
424 pci_set_drvdata(pdev, dev);
425 ret = drm_get_minor(dev, &dev->control, DRM_MINOR_CONTROL);
426 if (ret)
427 goto err_g2;
428 }
429
430 if ((ret = drm_get_minor(dev, &dev->primary, DRM_MINOR_LEGACY)))
431 goto err_g3;
432
433 if (dev->driver->load) {
434 ret = dev->driver->load(dev, ent->driver_data);
435 if (ret)
436 goto err_g4;
437 }
438
439 /* setup the grouping for the legacy output */
440 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
441 ret = drm_mode_group_init_legacy_group(dev, &dev->primary->mode_group);
442 if (ret)
443 goto err_g4;
444 }
445
446 list_add_tail(&dev->driver_item, &driver->device_list);
447
448 DRM_INFO("Initialized %s %d.%d.%d %s for %s on minor %d\n",
449 driver->name, driver->major, driver->minor, driver->patchlevel,
450 driver->date, pci_name(pdev), dev->primary->index);
451
452 return 0;
453
454err_g4:
455 drm_put_minor(&dev->primary);
456err_g3:
457 if (drm_core_check_feature(dev, DRIVER_MODESET))
458 drm_put_minor(&dev->control);
459err_g2:
460 pci_disable_device(pdev);
461err_g1:
462 kfree(dev);
463 return ret;
464}
465EXPORT_SYMBOL(drm_get_dev);
466
467/**
468 * Put a secondary minor number. 383 * Put a secondary minor number.
469 * 384 *
470 * \param sec_minor - structure to be released 385 * \param sec_minor - structure to be released
diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
index 3a3a451d0bf8..14d9d829ef27 100644
--- a/drivers/gpu/drm/drm_sysfs.c
+++ b/drivers/gpu/drm/drm_sysfs.c
@@ -488,7 +488,8 @@ int drm_sysfs_device_add(struct drm_minor *minor)
488 int err; 488 int err;
489 char *minor_str; 489 char *minor_str;
490 490
491 minor->kdev.parent = &minor->dev->pdev->dev; 491 minor->kdev.parent = minor->dev->dev;
492
492 minor->kdev.class = drm_class; 493 minor->kdev.class = drm_class;
493 minor->kdev.release = drm_sysfs_device_release; 494 minor->kdev.release = drm_sysfs_device_release;
494 minor->kdev.devt = minor->device; 495 minor->kdev.devt = minor->device;
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index 9fe2d08d9e9d..9bed5617e0ea 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -34,6 +34,7 @@
34#include "i915_drm.h" 34#include "i915_drm.h"
35#include "i915_drv.h" 35#include "i915_drv.h"
36#include "i915_trace.h" 36#include "i915_trace.h"
37#include <linux/pci.h>
37#include <linux/vgaarb.h> 38#include <linux/vgaarb.h>
38#include <linux/acpi.h> 39#include <linux/acpi.h>
39#include <linux/pnp.h> 40#include <linux/pnp.h>
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 5c51e45ab68d..b7aecf5ea1fc 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -435,7 +435,7 @@ int i965_reset(struct drm_device *dev, u8 flags)
435static int __devinit 435static int __devinit
436i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 436i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
437{ 437{
438 return drm_get_dev(pdev, ent, &driver); 438 return drm_get_pci_dev(pdev, ent, &driver);
439} 439}
440 440
441static void 441static void
diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.c b/drivers/gpu/drm/nouveau/nouveau_drv.c
index c6079e36669d..f60a2b2ae445 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drv.c
+++ b/drivers/gpu/drm/nouveau/nouveau_drv.c
@@ -132,7 +132,7 @@ static struct drm_driver driver;
132static int __devinit 132static int __devinit
133nouveau_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 133nouveau_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
134{ 134{
135 return drm_get_dev(pdev, ent, &driver); 135 return drm_get_pci_dev(pdev, ent, &driver);
136} 136}
137 137
138static void 138static void
diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c
index 4afba1eca2a7..683e281b4092 100644
--- a/drivers/gpu/drm/radeon/radeon_drv.c
+++ b/drivers/gpu/drm/radeon/radeon_drv.c
@@ -236,7 +236,7 @@ static struct drm_driver kms_driver;
236static int __devinit 236static int __devinit
237radeon_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 237radeon_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
238{ 238{
239 return drm_get_dev(pdev, ent, &kms_driver); 239 return drm_get_pci_dev(pdev, ent, &kms_driver);
240} 240}
241 241
242static void 242static void
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 0c9c0811f42d..f7f248dbff58 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -758,7 +758,7 @@ static struct drm_driver driver = {
758 758
759static int vmw_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 759static int vmw_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
760{ 760{
761 return drm_get_dev(pdev, ent, &driver); 761 return drm_get_pci_dev(pdev, ent, &driver);
762} 762}
763 763
764static int __init vmwgfx_init(void) 764static int __init vmwgfx_init(void)