blob: fd29f03645b8e465b42add64384b339c13229dc2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Jan Engelhardt96de0e22007-10-19 23:21:04 +02002 * Copyright 2003 José Fonseca.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Copyright 2003 Leif Delgass.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Dave Airlie195b3a22006-04-05 18:12:18 +100027#include <linux/dma-mapping.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040028#include <linux/export.h>
David Howells760285e2012-10-02 18:01:07 +010029#include <drm/drmP.h>
Daniel Vetterba8286f2014-09-11 07:43:25 +020030#include "drm_legacy.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Linus Torvalds1da177e2005-04-16 15:20:36 -070032/**
Thierry Redingc6a1af8a2014-05-19 13:39:07 +020033 * drm_pci_alloc - Allocate a PCI consistent memory block, for DMA.
34 * @dev: DRM device
35 * @size: size of block to allocate
36 * @align: alignment of block
37 *
38 * Return: A handle to the allocated memory block on success or NULL on
39 * failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 */
Zhenyu Wange6be8d92010-01-05 11:25:05 +080041drm_dma_handle_t *drm_pci_alloc(struct drm_device * dev, size_t size, size_t align)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042{
Dave Airlie9c8da5e2005-07-10 15:38:56 +100043 drm_dma_handle_t *dmah;
Dave Airlieddf19b92006-03-19 18:56:12 +110044 unsigned long addr;
45 size_t sz;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47 /* pci_alloc_consistent only guarantees alignment to the smallest
48 * PAGE_SIZE order which is greater than or equal to the requested size.
49 * Return NULL here for now to make sure nobody tries for larger alignment
50 */
51 if (align > size)
52 return NULL;
53
Dave Airlie9c8da5e2005-07-10 15:38:56 +100054 dmah = kmalloc(sizeof(drm_dma_handle_t), GFP_KERNEL);
55 if (!dmah)
56 return NULL;
Dave Airlieb5e89ed2005-09-25 14:28:13 +100057
Dave Airlie9c8da5e2005-07-10 15:38:56 +100058 dmah->size = size;
Dave Airlieddf19b92006-03-19 18:56:12 +110059 dmah->vaddr = dma_alloc_coherent(&dev->pdev->dev, size, &dmah->busaddr, GFP_KERNEL | __GFP_COMP);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Dave Airlie9c8da5e2005-07-10 15:38:56 +100061 if (dmah->vaddr == NULL) {
62 kfree(dmah);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 return NULL;
Dave Airlie9c8da5e2005-07-10 15:38:56 +100064 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Dave Airlie9c8da5e2005-07-10 15:38:56 +100066 memset(dmah->vaddr, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Dave Airlieddf19b92006-03-19 18:56:12 +110068 /* XXX - Is virt_to_page() legal for consistent mem? */
69 /* Reserve */
70 for (addr = (unsigned long)dmah->vaddr, sz = size;
71 sz > 0; addr += PAGE_SIZE, sz -= PAGE_SIZE) {
Ben Hutchingse1e78532013-10-27 21:52:39 +000072 SetPageReserved(virt_to_page((void *)addr));
Dave Airlieddf19b92006-03-19 18:56:12 +110073 }
74
Dave Airlie9c8da5e2005-07-10 15:38:56 +100075 return dmah;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076}
Dave Airlieb5e89ed2005-09-25 14:28:13 +100077
Linus Torvalds1da177e2005-04-16 15:20:36 -070078EXPORT_SYMBOL(drm_pci_alloc);
79
Thierry Redingc6a1af8a2014-05-19 13:39:07 +020080/*
81 * Free a PCI consistent memory block without freeing its descriptor.
Dave Airlie9c8da5e2005-07-10 15:38:56 +100082 *
83 * This function is for internal use in the Linux-specific DRM core code.
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 */
Daniel Vetter1c96e842014-09-10 12:43:51 +020085void __drm_legacy_pci_free(struct drm_device * dev, drm_dma_handle_t * dmah)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
Dave Airlieddf19b92006-03-19 18:56:12 +110087 unsigned long addr;
88 size_t sz;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Eric Anholt9a298b22009-03-24 12:23:04 -070090 if (dmah->vaddr) {
Dave Airlieddf19b92006-03-19 18:56:12 +110091 /* XXX - Is virt_to_page() legal for consistent mem? */
92 /* Unreserve */
93 for (addr = (unsigned long)dmah->vaddr, sz = dmah->size;
94 sz > 0; addr += PAGE_SIZE, sz -= PAGE_SIZE) {
Ben Hutchingse1e78532013-10-27 21:52:39 +000095 ClearPageReserved(virt_to_page((void *)addr));
Dave Airlieddf19b92006-03-19 18:56:12 +110096 }
97 dma_free_coherent(&dev->pdev->dev, dmah->size, dmah->vaddr,
98 dmah->busaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
Dave Airlie9c8da5e2005-07-10 15:38:56 +1000101
102/**
Thierry Redingc6a1af8a2014-05-19 13:39:07 +0200103 * drm_pci_free - Free a PCI consistent memory block
104 * @dev: DRM device
105 * @dmah: handle to memory block
Dave Airlie9c8da5e2005-07-10 15:38:56 +1000106 */
Dave Airlie84b1fd12007-07-11 15:53:27 +1000107void drm_pci_free(struct drm_device * dev, drm_dma_handle_t * dmah)
Dave Airlie9c8da5e2005-07-10 15:38:56 +1000108{
Daniel Vetter1c96e842014-09-10 12:43:51 +0200109 __drm_legacy_pci_free(dev, dmah);
Dave Airlie9c8da5e2005-07-10 15:38:56 +1000110 kfree(dmah);
111}
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113EXPORT_SYMBOL(drm_pci_free);
114
Jordan Crousedcdb1672010-05-27 13:40:25 -0600115#ifdef CONFIG_PCI
Dave Airlie8410ea32010-12-15 03:16:38 +1000116
117static int drm_get_pci_domain(struct drm_device *dev)
118{
119#ifndef __alpha__
120 /* For historical reasons, drm_get_pci_domain() is busticated
121 * on most archs and has to remain so for userspace interface
122 * < 1.4, except on alpha which was right from the beginning
123 */
124 if (dev->if_version < 0x10004)
125 return 0;
126#endif /* __alpha__ */
127
128 return pci_domain_nr(dev->pdev->bus);
129}
130
David Herrmann915b4d12014-08-29 12:12:43 +0200131int drm_pci_set_busid(struct drm_device *dev, struct drm_master *master)
Dave Airlie8410ea32010-12-15 03:16:38 +1000132{
David Herrmannd0a39162014-08-29 12:12:41 +0200133 master->unique = kasprintf(GFP_KERNEL, "pci:%04x:%02x:%02x.%d",
134 drm_get_pci_domain(dev),
135 dev->pdev->bus->number,
136 PCI_SLOT(dev->pdev->devfn),
137 PCI_FUNC(dev->pdev->devfn));
138 if (!master->unique)
Dave Airlie8410ea32010-12-15 03:16:38 +1000139 return -ENOMEM;
140
David Herrmannd0a39162014-08-29 12:12:41 +0200141 master->unique_len = strlen(master->unique);
Dave Airlie8410ea32010-12-15 03:16:38 +1000142 return 0;
Dave Airlie8410ea32010-12-15 03:16:38 +1000143}
David Herrmann915b4d12014-08-29 12:12:43 +0200144EXPORT_SYMBOL(drm_pci_set_busid);
Dave Airlie8410ea32010-12-15 03:16:38 +1000145
Daniel Vetter53bf2a22013-11-03 21:47:18 +0100146int drm_pci_set_unique(struct drm_device *dev,
147 struct drm_master *master,
148 struct drm_unique *u)
Dave Airlie8410ea32010-12-15 03:16:38 +1000149{
150 int domain, bus, slot, func, ret;
Dave Airlie8410ea32010-12-15 03:16:38 +1000151
152 master->unique_len = u->unique_len;
David Herrmann1e444be2014-08-29 12:12:42 +0200153 master->unique = kmalloc(master->unique_len + 1, GFP_KERNEL);
Dave Airlie8410ea32010-12-15 03:16:38 +1000154 if (!master->unique) {
155 ret = -ENOMEM;
156 goto err;
157 }
158
159 if (copy_from_user(master->unique, u->unique, master->unique_len)) {
160 ret = -EFAULT;
161 goto err;
162 }
163
164 master->unique[master->unique_len] = '\0';
165
Dave Airlie8410ea32010-12-15 03:16:38 +1000166 /* Return error if the busid submitted doesn't match the device's actual
167 * busid.
168 */
169 ret = sscanf(master->unique, "PCI:%d:%d:%d", &bus, &slot, &func);
170 if (ret != 3) {
171 ret = -EINVAL;
172 goto err;
173 }
174
175 domain = bus >> 8;
176 bus &= 0xff;
177
178 if ((domain != drm_get_pci_domain(dev)) ||
179 (bus != dev->pdev->bus->number) ||
180 (slot != PCI_SLOT(dev->pdev->devfn)) ||
181 (func != PCI_FUNC(dev->pdev->devfn))) {
182 ret = -EINVAL;
183 goto err;
184 }
185 return 0;
186err:
187 return ret;
188}
189
Wolfram Sang45e97ab2011-06-15 11:26:47 +0200190static int drm_pci_irq_by_busid(struct drm_device *dev, struct drm_irq_busid *p)
Dave Airlie8410ea32010-12-15 03:16:38 +1000191{
192 if ((p->busnum >> 8) != drm_get_pci_domain(dev) ||
193 (p->busnum & 0xff) != dev->pdev->bus->number ||
194 p->devnum != PCI_SLOT(dev->pdev->devfn) || p->funcnum != PCI_FUNC(dev->pdev->devfn))
195 return -EINVAL;
196
197 p->irq = dev->pdev->irq;
198
199 DRM_DEBUG("%d:%d:%d => IRQ %d\n", p->busnum, p->devnum, p->funcnum,
200 p->irq);
201 return 0;
202}
203
Daniel Vettereaaf8f02013-08-28 15:19:23 +0200204/**
Thierry Redingc6a1af8a2014-05-19 13:39:07 +0200205 * drm_irq_by_busid - Get interrupt from bus ID
206 * @dev: DRM device
207 * @data: IOCTL parameter pointing to a drm_irq_busid structure
208 * @file_priv: DRM file private.
Daniel Vettereaaf8f02013-08-28 15:19:23 +0200209 *
210 * Finds the PCI device with the specified bus id and gets its IRQ number.
211 * This IOCTL is deprecated, and will now return EINVAL for any busid not equal
212 * to that of the device that this DRM instance attached to.
Thierry Redingc6a1af8a2014-05-19 13:39:07 +0200213 *
214 * Return: 0 on success or a negative error code on failure.
Daniel Vettereaaf8f02013-08-28 15:19:23 +0200215 */
216int drm_irq_by_busid(struct drm_device *dev, void *data,
217 struct drm_file *file_priv)
218{
219 struct drm_irq_busid *p = data;
220
221 if (drm_core_check_feature(dev, DRIVER_MODESET))
222 return -EINVAL;
223
224 /* UMS was only ever support on PCI devices. */
225 if (WARN_ON(!dev->pdev))
226 return -EINVAL;
227
228 if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
229 return -EINVAL;
230
231 return drm_pci_irq_by_busid(dev, p);
232}
233
Daniel Vetter8da79cc2013-12-11 11:34:34 +0100234static void drm_pci_agp_init(struct drm_device *dev)
Dave Airlie8410ea32010-12-15 03:16:38 +1000235{
Daniel Vetterd9906752013-12-11 11:34:35 +0100236 if (drm_core_check_feature(dev, DRIVER_USE_AGP)) {
Dave Airlie8410ea32010-12-15 03:16:38 +1000237 if (drm_pci_device_is_agp(dev))
238 dev->agp = drm_agp_init(dev);
Daniel Vetter28185642013-08-08 15:41:27 +0200239 if (dev->agp) {
240 dev->agp->agp_mtrr = arch_phys_wc_add(
241 dev->agp->agp_info.aper_base,
242 dev->agp->agp_info.aper_size *
243 1024 * 1024);
Dave Airlie8410ea32010-12-15 03:16:38 +1000244 }
245 }
Dave Airlie8410ea32010-12-15 03:16:38 +1000246}
247
Daniel Vetter4efafeb2013-12-11 11:34:38 +0100248void drm_pci_agp_destroy(struct drm_device *dev)
David Herrmann28ec7112013-07-27 16:37:00 +0200249{
Daniel Vetterd9906752013-12-11 11:34:35 +0100250 if (dev->agp) {
Daniel Vetter28185642013-08-08 15:41:27 +0200251 arch_phys_wc_del(dev->agp->agp_mtrr);
David Herrmann28ec7112013-07-27 16:37:00 +0200252 drm_agp_clear(dev);
Daniel Vetterd6e4b28b2013-12-11 11:34:37 +0100253 kfree(dev->agp);
David Herrmann28ec7112013-07-27 16:37:00 +0200254 dev->agp = NULL;
255 }
256}
257
Jordan Crousedcdb1672010-05-27 13:40:25 -0600258/**
Thierry Redingc6a1af8a2014-05-19 13:39:07 +0200259 * drm_get_pci_dev - Register a PCI device with the DRM subsystem
260 * @pdev: PCI device
261 * @ent: entry from the PCI ID table that matches @pdev
262 * @driver: DRM device driver
Jordan Crousedcdb1672010-05-27 13:40:25 -0600263 *
264 * Attempt to gets inter module "drm" information. If we are first
265 * then register the character device and inter module information.
266 * Try and register, if we fail to register, backout previous work.
Thierry Redingc6a1af8a2014-05-19 13:39:07 +0200267 *
268 * Return: 0 on success or a negative error code on failure.
Jordan Crousedcdb1672010-05-27 13:40:25 -0600269 */
270int drm_get_pci_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
271 struct drm_driver *driver)
272{
273 struct drm_device *dev;
274 int ret;
275
276 DRM_DEBUG("\n");
277
David Herrmann1bb72532013-10-02 11:23:34 +0200278 dev = drm_dev_alloc(driver, &pdev->dev);
Jordan Crousedcdb1672010-05-27 13:40:25 -0600279 if (!dev)
280 return -ENOMEM;
281
282 ret = pci_enable_device(pdev);
283 if (ret)
David Herrmannc22f0ac2013-10-02 11:23:35 +0200284 goto err_free;
Jordan Crousedcdb1672010-05-27 13:40:25 -0600285
Jordan Crousedcdb1672010-05-27 13:40:25 -0600286 dev->pdev = pdev;
Jordan Crousedcdb1672010-05-27 13:40:25 -0600287#ifdef __alpha__
288 dev->hose = pdev->sysdata;
289#endif
290
David Herrmannc22f0ac2013-10-02 11:23:35 +0200291 if (drm_core_check_feature(dev, DRIVER_MODESET))
Jordan Crousedcdb1672010-05-27 13:40:25 -0600292 pci_set_drvdata(pdev, dev);
Jordan Crousedcdb1672010-05-27 13:40:25 -0600293
Daniel Vetter2c695fa2013-12-11 11:34:36 +0100294 drm_pci_agp_init(dev);
Daniel Vetter2c695fa2013-12-11 11:34:36 +0100295
David Herrmannc22f0ac2013-10-02 11:23:35 +0200296 ret = drm_dev_register(dev, ent->driver_data);
297 if (ret)
Daniel Vetter2c695fa2013-12-11 11:34:36 +0100298 goto err_agp;
Jordan Crousedcdb1672010-05-27 13:40:25 -0600299
300 DRM_INFO("Initialized %s %d.%d.%d %s for %s on minor %d\n",
301 driver->name, driver->major, driver->minor, driver->patchlevel,
302 driver->date, pci_name(pdev), dev->primary->index);
303
Daniel Vetterb3f23332013-12-11 11:34:31 +0100304 /* No locking needed since shadow-attach is single-threaded since it may
305 * only be called from the per-driver module init hook. */
306 if (!drm_core_check_feature(dev, DRIVER_MODESET))
307 list_add_tail(&dev->legacy_dev_list, &driver->legacy_dev_list);
308
Jordan Crousedcdb1672010-05-27 13:40:25 -0600309 return 0;
310
Daniel Vetter2c695fa2013-12-11 11:34:36 +0100311err_agp:
Daniel Vetter2c695fa2013-12-11 11:34:36 +0100312 drm_pci_agp_destroy(dev);
Jordan Crousedcdb1672010-05-27 13:40:25 -0600313 pci_disable_device(pdev);
David Herrmannc22f0ac2013-10-02 11:23:35 +0200314err_free:
David Herrmann099d1c22014-01-29 10:21:36 +0100315 drm_dev_unref(dev);
Jordan Crousedcdb1672010-05-27 13:40:25 -0600316 return ret;
317}
318EXPORT_SYMBOL(drm_get_pci_dev);
319
320/**
Thierry Redingc6a1af8a2014-05-19 13:39:07 +0200321 * drm_pci_init - Register matching PCI devices with the DRM subsystem
322 * @driver: DRM device driver
323 * @pdriver: PCI device driver
Jordan Crousedcdb1672010-05-27 13:40:25 -0600324 *
Thierry Redingc6a1af8a2014-05-19 13:39:07 +0200325 * Initializes a drm_device structures, registering the stubs and initializing
326 * the AGP device.
Jordan Crousedcdb1672010-05-27 13:40:25 -0600327 *
Thierry Redingc6a1af8a2014-05-19 13:39:07 +0200328 * Return: 0 on success or a negative error code on failure.
Jordan Crousedcdb1672010-05-27 13:40:25 -0600329 */
Dave Airlie8410ea32010-12-15 03:16:38 +1000330int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver)
Jordan Crousedcdb1672010-05-27 13:40:25 -0600331{
332 struct pci_dev *pdev = NULL;
333 const struct pci_device_id *pid;
334 int i;
335
Dave Airlie8410ea32010-12-15 03:16:38 +1000336 DRM_DEBUG("\n");
337
Jordan Crousedcdb1672010-05-27 13:40:25 -0600338 if (driver->driver_features & DRIVER_MODESET)
Dave Airlie8410ea32010-12-15 03:16:38 +1000339 return pci_register_driver(pdriver);
Jordan Crousedcdb1672010-05-27 13:40:25 -0600340
341 /* If not using KMS, fall back to stealth mode manual scanning. */
Daniel Vetterb3f23332013-12-11 11:34:31 +0100342 INIT_LIST_HEAD(&driver->legacy_dev_list);
Dave Airlie8410ea32010-12-15 03:16:38 +1000343 for (i = 0; pdriver->id_table[i].vendor != 0; i++) {
344 pid = &pdriver->id_table[i];
Jordan Crousedcdb1672010-05-27 13:40:25 -0600345
346 /* Loop around setting up a DRM device for each PCI device
347 * matching our ID and device class. If we had the internal
348 * function that pci_get_subsys and pci_get_class used, we'd
349 * be able to just pass pid in instead of doing a two-stage
350 * thing.
351 */
352 pdev = NULL;
353 while ((pdev =
354 pci_get_subsys(pid->vendor, pid->device, pid->subvendor,
355 pid->subdevice, pdev)) != NULL) {
356 if ((pdev->class & pid->class_mask) != pid->class)
357 continue;
358
359 /* stealth mode requires a manual probe */
360 pci_dev_get(pdev);
361 drm_get_pci_dev(pdev, pid, driver);
362 }
363 }
364 return 0;
365}
366
Dave Airlief4297782012-06-27 08:35:53 +0100367int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *mask)
368{
369 struct pci_dev *root;
Bjorn Helgaasdd66cc22013-01-04 19:10:42 +0000370 u32 lnkcap, lnkcap2;
Dave Airlief4297782012-06-27 08:35:53 +0100371
372 *mask = 0;
373 if (!dev->pdev)
374 return -EINVAL;
375
Dave Airlief4297782012-06-27 08:35:53 +0100376 root = dev->pdev->bus->self;
377
Dave Airlief4297782012-06-27 08:35:53 +0100378 /* we've been informed via and serverworks don't make the cut */
379 if (root->vendor == PCI_VENDOR_ID_VIA ||
380 root->vendor == PCI_VENDOR_ID_SERVERWORKS)
381 return -EINVAL;
382
Bjorn Helgaasdd66cc22013-01-04 19:10:42 +0000383 pcie_capability_read_dword(root, PCI_EXP_LNKCAP, &lnkcap);
384 pcie_capability_read_dword(root, PCI_EXP_LNKCAP2, &lnkcap2);
Dave Airlief4297782012-06-27 08:35:53 +0100385
Bjorn Helgaasdd66cc22013-01-04 19:10:42 +0000386 if (lnkcap2) { /* PCIe r3.0-compliant */
Dave Airlief4297782012-06-27 08:35:53 +0100387 if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_2_5GB)
388 *mask |= DRM_PCIE_SPEED_25;
389 if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_5_0GB)
390 *mask |= DRM_PCIE_SPEED_50;
391 if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_8_0GB)
392 *mask |= DRM_PCIE_SPEED_80;
Bjorn Helgaasdd66cc22013-01-04 19:10:42 +0000393 } else { /* pre-r3.0 */
Bjorn Helgaas9fe04232013-01-04 19:10:32 +0000394 if (lnkcap & PCI_EXP_LNKCAP_SLS_2_5GB)
Dave Airlief4297782012-06-27 08:35:53 +0100395 *mask |= DRM_PCIE_SPEED_25;
Bjorn Helgaas9fe04232013-01-04 19:10:32 +0000396 if (lnkcap & PCI_EXP_LNKCAP_SLS_5_0GB)
Bjorn Helgaasf8acf6f2013-01-04 19:10:37 +0000397 *mask |= (DRM_PCIE_SPEED_25 | DRM_PCIE_SPEED_50);
Dave Airlief4297782012-06-27 08:35:53 +0100398 }
399
400 DRM_INFO("probing gen 2 caps for device %x:%x = %x/%x\n", root->vendor, root->device, lnkcap, lnkcap2);
401 return 0;
402}
403EXPORT_SYMBOL(drm_pcie_get_speed_cap_mask);
Bjorn Helgaas93711d82013-02-08 15:27:01 -0700404
405#else
406
407int drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver)
408{
409 return -1;
410}
411
Daniel Vetter4efafeb2013-12-11 11:34:38 +0100412void drm_pci_agp_destroy(struct drm_device *dev) {}
Daniel Vettereaaf8f02013-08-28 15:19:23 +0200413
414int drm_irq_by_busid(struct drm_device *dev, void *data,
415 struct drm_file *file_priv)
416{
417 return -EINVAL;
418}
Daniel Vetter53bf2a22013-11-03 21:47:18 +0100419
420int drm_pci_set_unique(struct drm_device *dev,
421 struct drm_master *master,
422 struct drm_unique *u)
423{
424 return -EINVAL;
425}
Bjorn Helgaas93711d82013-02-08 15:27:01 -0700426#endif
427
428EXPORT_SYMBOL(drm_pci_init);
429
Thierry Redingc6a1af8a2014-05-19 13:39:07 +0200430/**
431 * drm_pci_exit - Unregister matching PCI devices from the DRM subsystem
432 * @driver: DRM device driver
433 * @pdriver: PCI device driver
434 *
435 * Unregisters one or more devices matched by a PCI driver from the DRM
436 * subsystem.
437 */
Bjorn Helgaas93711d82013-02-08 15:27:01 -0700438void drm_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver)
439{
440 struct drm_device *dev, *tmp;
441 DRM_DEBUG("\n");
442
443 if (driver->driver_features & DRIVER_MODESET) {
444 pci_unregister_driver(pdriver);
445 } else {
Daniel Vetterb3f23332013-12-11 11:34:31 +0100446 list_for_each_entry_safe(dev, tmp, &driver->legacy_dev_list,
447 legacy_dev_list) {
Daniel Vetterb3f23332013-12-11 11:34:31 +0100448 list_del(&dev->legacy_dev_list);
Daniel Vetterc94adc42014-01-30 17:58:38 +0100449 drm_put_dev(dev);
Daniel Vetterb3f23332013-12-11 11:34:31 +0100450 }
Bjorn Helgaas93711d82013-02-08 15:27:01 -0700451 }
452 DRM_INFO("Module unloaded\n");
453}
454EXPORT_SYMBOL(drm_pci_exit);