Skip to content

Commit dcdb167

Browse files
Jordan Crouseairlied
authored andcommitted
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>
1 parent 01d73a6 commit dcdb167

17 files changed

Lines changed: 402 additions & 172 deletions

File tree

‎drivers/gpu/drm/Kconfig‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77
menuconfig DRM
88
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
1010
select I2C
1111
select I2C_ALGOBIT
1212
select SLOW_WORK
@@ -17,7 +17,7 @@ menuconfig DRM
1717
These modules provide support for synchronization, security, and
1818
DMA transfers. Please see <http://dri.sourceforge.net/> for more
1919
details. You should also select and configure AGP
20-
(/dev/agpgart) support.
20+
(/dev/agpgart) support if it is available for your platform.
2121

2222
config DRM_KMS_HELPER
2323
tristate

‎drivers/gpu/drm/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ drm-y := drm_auth.o drm_buffer.o drm_bufs.o drm_cache.o \
99
drm_drv.o drm_fops.o drm_gem.o drm_ioctl.o drm_irq.o \
1010
drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \
1111
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 \
1313
drm_crtc.o drm_modes.o drm_edid.o \
1414
drm_info.o drm_debugfs.o drm_encoder_slave.o
1515

‎drivers/gpu/drm/drm_drv.c‎

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -243,47 +243,20 @@ int drm_lastclose(struct drm_device * dev)
243243
*
244244
* Initializes an array of drm_device structures, and attempts to
245245
* initialize all available devices, using consecutive minors, registering the
246-
* stubs and initializing the AGP device.
246+
* stubs and initializing the device.
247247
*
248248
* Expands the \c DRIVER_PREINIT and \c DRIVER_POST_INIT macros before and
249249
* after the initialization for driver customization.
250250
*/
251251
int drm_init(struct drm_driver *driver)
252252
{
253-
struct pci_dev *pdev = NULL;
254-
const struct pci_device_id *pid;
255-
int i;
256-
257253
DRM_DEBUG("\n");
258-
259254
INIT_LIST_HEAD(&driver->device_list);
260255

261-
if (driver->driver_features & DRIVER_MODESET)
262-
return pci_register_driver(&driver->pci_driver);
263-
264-
/* If not using KMS, fall back to stealth mode manual scanning. */
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;
256+
if (driver->driver_features & DRIVER_USE_PLATFORM_DEVICE)
257+
return drm_platform_init(driver);
258+
else
259+
return drm_pci_init(driver);
287260
}
288261

289262
EXPORT_SYMBOL(drm_init);

‎drivers/gpu/drm/drm_edid.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ drm_do_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
282282
return block;
283283

284284
carp:
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",
286286
drm_get_connector_name(connector), j);
287287

288288
out:
@@ -1626,7 +1626,7 @@ int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
16261626
return 0;
16271627
}
16281628
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",
16301630
drm_get_connector_name(connector));
16311631
return 0;
16321632
}

‎drivers/gpu/drm/drm_info.c‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,24 @@ int drm_name_info(struct seq_file *m, void *data)
5151
if (!master)
5252
return 0;
5353

54-
if (master->unique) {
55-
seq_printf(m, "%s %s %s\n",
56-
dev->driver->pci_driver.name,
57-
pci_name(dev->pdev), master->unique);
54+
if (drm_core_check_feature(dev, DRIVER_USE_PLATFORM_DEVICE)) {
55+
if (master->unique) {
56+
seq_printf(m, "%s %s %s\n",
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+
}
5863
} else {
59-
seq_printf(m, "%s %s\n", dev->driver->pci_driver.name,
60-
pci_name(dev->pdev));
64+
if (master->unique) {
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+
}
6172
}
6273

6374
return 0;

‎drivers/gpu/drm/drm_ioctl.c‎

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -132,32 +132,57 @@ static int drm_set_busid(struct drm_device *dev, struct drm_file *file_priv)
132132
struct drm_master *master = file_priv->master;
133133
int len;
134134

135-
if (master->unique != NULL)
136-
return -EBUSY;
137-
138-
master->unique_len = 40;
139-
master->unique_size = master->unique_len;
140-
master->unique = kmalloc(master->unique_size, GFP_KERNEL);
141-
if (master->unique == NULL)
142-
return -ENOMEM;
135+
if (drm_core_check_feature(dev, DRIVER_USE_PLATFORM_DEVICE)) {
136+
master->unique_len = 10 + strlen(dev->platformdev->name);
137+
master->unique = kmalloc(master->unique_len + 1, GFP_KERNEL);
138+
139+
if (master->unique == NULL)
140+
return -ENOMEM;
141+
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;
143175

144-
len = snprintf(master->unique, master->unique_len, "pci:%04x:%02x:%02x.%d",
145-
drm_get_pci_domain(dev),
146-
dev->pdev->bus->number,
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;
176+
dev->devname =
177+
kmalloc(strlen(dev->driver->pci_driver.name) +
178+
master->unique_len + 2, GFP_KERNEL);
153179

154-
dev->devname = kmalloc(strlen(dev->driver->pci_driver.name) +
155-
master->unique_len + 2, GFP_KERNEL);
156-
if (dev->devname == NULL)
157-
return -ENOMEM;
180+
if (dev->devname == NULL)
181+
return -ENOMEM;
158182

159-
sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name,
160-
master->unique);
183+
sprintf(dev->devname, "%s@%s", dev->driver->pci_driver.name,
184+
master->unique);
185+
}
161186

162187
return 0;
163188
}

‎drivers/gpu/drm/drm_irq.c‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ int drm_irq_by_busid(struct drm_device *dev, void *data,
5757
{
5858
struct drm_irq_busid *p = data;
5959

60+
if (drm_core_check_feature(dev, DRIVER_USE_PLATFORM_DEVICE))
61+
return -EINVAL;
62+
6063
if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
6164
return -EINVAL;
6265

@@ -211,7 +214,7 @@ int drm_irq_install(struct drm_device *dev)
211214
if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
212215
return -EINVAL;
213216

214-
if (dev->pdev->irq == 0)
217+
if (drm_dev_to_irq(dev) == 0)
215218
return -EINVAL;
216219

217220
mutex_lock(&dev->struct_mutex);
@@ -229,7 +232,7 @@ int drm_irq_install(struct drm_device *dev)
229232
dev->irq_enabled = 1;
230233
mutex_unlock(&dev->struct_mutex);
231234

232-
DRM_DEBUG("irq=%d\n", dev->pdev->irq);
235+
DRM_DEBUG("irq=%d\n", drm_dev_to_irq(dev));
233236

234237
/* Before installing handler */
235238
dev->driver->irq_preinstall(dev);
@@ -302,14 +305,14 @@ int drm_irq_uninstall(struct drm_device * dev)
302305
if (!irq_enabled)
303306
return -EINVAL;
304307

305-
DRM_DEBUG("irq=%d\n", dev->pdev->irq);
308+
DRM_DEBUG("irq=%d\n", drm_dev_to_irq(dev));
306309

307310
if (!drm_core_check_feature(dev, DRIVER_MODESET))
308311
vga_client_register(dev->pdev, NULL, NULL, NULL);
309312

310313
dev->driver->irq_uninstall(dev);
311314

312-
free_irq(dev->pdev->irq, dev);
315+
free_irq(drm_dev_to_irq(dev), dev);
313316

314317
return 0;
315318
}
@@ -341,7 +344,7 @@ int drm_control(struct drm_device *dev, void *data,
341344
if (drm_core_check_feature(dev, DRIVER_MODESET))
342345
return 0;
343346
if (dev->if_version < DRM_IF_VERSION(1, 2) &&
344-
ctl->irq != dev->pdev->irq)
347+
ctl->irq != drm_dev_to_irq(dev))
345348
return -EINVAL;
346349
return drm_irq_install(dev);
347350
case DRM_UNINST_HANDLER:
@@ -651,7 +654,7 @@ int drm_wait_vblank(struct drm_device *dev, void *data,
651654
int ret = 0;
652655
unsigned int flags, seq, crtc;
653656

654-
if ((!dev->pdev->irq) || (!dev->irq_enabled))
657+
if ((!drm_dev_to_irq(dev)) || (!dev->irq_enabled))
655658
return -EINVAL;
656659

657660
if (vblwait->request.type & _DRM_VBLANK_SIGNAL)

0 commit comments

Comments
 (0)