Skip to content

Commit d1583c9

Browse files
committed
Merge branch 'drm-next' of git://people.freedesktop.org/~dvdhrm/linux into drm-next
This is the 3rd respin of the drm-anon patches. They allow module unloading, use the pin_fs_* helpers recommended by Al and are rebased on top of drm-next. Note that there are minor conflicts with the "drm-minor" branch. * 'drm-next' of git://people.freedesktop.org/~dvdhrm/linux: drm: init TTM dev_mapping in ttm_bo_device_init() drm: use anon-inode instead of relying on cdevs drm: add pseudo filesystem for shared inodes
2 parents bcc298b + 07b48c3 commit d1583c9

20 files changed

Lines changed: 140 additions & 66 deletions

File tree

‎drivers/gpu/drm/ast/ast_ttm.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,9 @@ int ast_mm_init(struct ast_private *ast)
259259

260260
ret = ttm_bo_device_init(&ast->ttm.bdev,
261261
ast->ttm.bo_global_ref.ref.object,
262-
&ast_bo_driver, DRM_FILE_PAGE_OFFSET,
262+
&ast_bo_driver,
263+
dev->anon_inode->i_mapping,
264+
DRM_FILE_PAGE_OFFSET,
263265
true);
264266
if (ret) {
265267
DRM_ERROR("Error initialising bo driver; %d\n", ret);
@@ -324,7 +326,6 @@ int ast_bo_create(struct drm_device *dev, int size, int align,
324326
}
325327

326328
astbo->bo.bdev = &ast->ttm.bdev;
327-
astbo->bo.bdev->dev_mapping = dev->dev_mapping;
328329

329330
ast_ttm_placement(astbo, TTM_PL_FLAG_VRAM | TTM_PL_FLAG_SYSTEM);
330331

‎drivers/gpu/drm/bochs/bochs_mm.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ int bochs_mm_init(struct bochs_device *bochs)
225225

226226
ret = ttm_bo_device_init(&bochs->ttm.bdev,
227227
bochs->ttm.bo_global_ref.ref.object,
228-
&bochs_bo_driver, DRM_FILE_PAGE_OFFSET,
228+
&bochs_bo_driver,
229+
bochs->dev->anon_inode->i_mapping,
230+
DRM_FILE_PAGE_OFFSET,
229231
true);
230232
if (ret) {
231233
DRM_ERROR("Error initialising bo driver; %d\n", ret);
@@ -359,7 +361,7 @@ static int bochs_bo_create(struct drm_device *dev, int size, int align,
359361
}
360362

361363
bochsbo->bo.bdev = &bochs->ttm.bdev;
362-
bochsbo->bo.bdev->dev_mapping = dev->dev_mapping;
364+
bochsbo->bo.bdev->dev_mapping = dev->anon_inode->i_mapping;
363365

364366
bochs_ttm_placement(bochsbo, TTM_PL_FLAG_VRAM | TTM_PL_FLAG_SYSTEM);
365367

‎drivers/gpu/drm/cirrus/cirrus_ttm.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,9 @@ int cirrus_mm_init(struct cirrus_device *cirrus)
259259

260260
ret = ttm_bo_device_init(&cirrus->ttm.bdev,
261261
cirrus->ttm.bo_global_ref.ref.object,
262-
&cirrus_bo_driver, DRM_FILE_PAGE_OFFSET,
262+
&cirrus_bo_driver,
263+
dev->anon_inode->i_mapping,
264+
DRM_FILE_PAGE_OFFSET,
263265
true);
264266
if (ret) {
265267
DRM_ERROR("Error initialising bo driver; %d\n", ret);
@@ -329,7 +331,6 @@ int cirrus_bo_create(struct drm_device *dev, int size, int align,
329331
}
330332

331333
cirrusbo->bo.bdev = &cirrus->ttm.bdev;
332-
cirrusbo->bo.bdev->dev_mapping = dev->dev_mapping;
333334

334335
cirrus_ttm_placement(cirrusbo, TTM_PL_FLAG_VRAM | TTM_PL_FLAG_SYSTEM);
335336

‎drivers/gpu/drm/drm_fops.c‎

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ int drm_open(struct inode *inode, struct file *filp)
8383
struct drm_minor *minor;
8484
int retcode;
8585
int need_setup = 0;
86-
struct address_space *old_mapping;
87-
struct address_space *old_imapping;
8886

8987
minor = drm_minor_acquire(iminor(inode));
9088
if (IS_ERR(minor))
@@ -93,16 +91,9 @@ int drm_open(struct inode *inode, struct file *filp)
9391
dev = minor->dev;
9492
if (!dev->open_count++)
9593
need_setup = 1;
96-
mutex_lock(&dev->struct_mutex);
97-
old_imapping = inode->i_mapping;
98-
old_mapping = dev->dev_mapping;
99-
if (old_mapping == NULL)
100-
dev->dev_mapping = &inode->i_data;
101-
/* ihold ensures nobody can remove inode with our i_data */
102-
ihold(container_of(dev->dev_mapping, struct inode, i_data));
103-
inode->i_mapping = dev->dev_mapping;
104-
filp->f_mapping = dev->dev_mapping;
105-
mutex_unlock(&dev->struct_mutex);
94+
95+
/* share address_space across all char-devs of a single device */
96+
filp->f_mapping = dev->anon_inode->i_mapping;
10697

10798
retcode = drm_open_helper(inode, filp, minor);
10899
if (retcode)
@@ -115,12 +106,6 @@ int drm_open(struct inode *inode, struct file *filp)
115106
return 0;
116107

117108
err_undo:
118-
mutex_lock(&dev->struct_mutex);
119-
filp->f_mapping = old_imapping;
120-
inode->i_mapping = old_imapping;
121-
iput(container_of(dev->dev_mapping, struct inode, i_data));
122-
dev->dev_mapping = old_mapping;
123-
mutex_unlock(&dev->struct_mutex);
124109
dev->open_count--;
125110
drm_minor_release(minor);
126111
return retcode;
@@ -421,7 +406,6 @@ int drm_lastclose(struct drm_device * dev)
421406

422407
drm_legacy_dma_takedown(dev);
423408

424-
dev->dev_mapping = NULL;
425409
mutex_unlock(&dev->struct_mutex);
426410

427411
drm_legacy_dev_reinit(dev);
@@ -537,9 +521,6 @@ int drm_release(struct inode *inode, struct file *filp)
537521
}
538522
}
539523

540-
BUG_ON(dev->dev_mapping == NULL);
541-
iput(container_of(dev->dev_mapping, struct inode, i_data));
542-
543524
/* drop the reference held my the file priv */
544525
if (file_priv->master)
545526
drm_master_put(&file_priv->master);

‎drivers/gpu/drm/drm_stub.c‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
* DEALINGS IN THE SOFTWARE.
3232
*/
3333

34+
#include <linux/fs.h>
3435
#include <linux/module.h>
3536
#include <linux/moduleparam.h>
37+
#include <linux/mount.h>
3638
#include <linux/slab.h>
3739
#include <drm/drmP.h>
3840
#include <drm/drm_core.h>
@@ -459,6 +461,78 @@ void drm_unplug_dev(struct drm_device *dev)
459461
}
460462
EXPORT_SYMBOL(drm_unplug_dev);
461463

464+
/*
465+
* DRM internal mount
466+
* We want to be able to allocate our own "struct address_space" to control
467+
* memory-mappings in VRAM (or stolen RAM, ...). However, core MM does not allow
468+
* stand-alone address_space objects, so we need an underlying inode. As there
469+
* is no way to allocate an independent inode easily, we need a fake internal
470+
* VFS mount-point.
471+
*
472+
* The drm_fs_inode_new() function allocates a new inode, drm_fs_inode_free()
473+
* frees it again. You are allowed to use iget() and iput() to get references to
474+
* the inode. But each drm_fs_inode_new() call must be paired with exactly one
475+
* drm_fs_inode_free() call (which does not have to be the last iput()).
476+
* We use drm_fs_inode_*() to manage our internal VFS mount-point and share it
477+
* between multiple inode-users. You could, technically, call
478+
* iget() + drm_fs_inode_free() directly after alloc and sometime later do an
479+
* iput(), but this way you'd end up with a new vfsmount for each inode.
480+
*/
481+
482+
static int drm_fs_cnt;
483+
static struct vfsmount *drm_fs_mnt;
484+
485+
static const struct dentry_operations drm_fs_dops = {
486+
.d_dname = simple_dname,
487+
};
488+
489+
static const struct super_operations drm_fs_sops = {
490+
.statfs = simple_statfs,
491+
};
492+
493+
static struct dentry *drm_fs_mount(struct file_system_type *fs_type, int flags,
494+
const char *dev_name, void *data)
495+
{
496+
return mount_pseudo(fs_type,
497+
"drm:",
498+
&drm_fs_sops,
499+
&drm_fs_dops,
500+
0x010203ff);
501+
}
502+
503+
static struct file_system_type drm_fs_type = {
504+
.name = "drm",
505+
.owner = THIS_MODULE,
506+
.mount = drm_fs_mount,
507+
.kill_sb = kill_anon_super,
508+
};
509+
510+
static struct inode *drm_fs_inode_new(void)
511+
{
512+
struct inode *inode;
513+
int r;
514+
515+
r = simple_pin_fs(&drm_fs_type, &drm_fs_mnt, &drm_fs_cnt);
516+
if (r < 0) {
517+
DRM_ERROR("Cannot mount pseudo fs: %d\n", r);
518+
return ERR_PTR(r);
519+
}
520+
521+
inode = alloc_anon_inode(drm_fs_mnt->mnt_sb);
522+
if (IS_ERR(inode))
523+
simple_release_fs(&drm_fs_mnt, &drm_fs_cnt);
524+
525+
return inode;
526+
}
527+
528+
static void drm_fs_inode_free(struct inode *inode)
529+
{
530+
if (inode) {
531+
iput(inode);
532+
simple_release_fs(&drm_fs_mnt, &drm_fs_cnt);
533+
}
534+
}
535+
462536
/**
463537
* drm_dev_alloc - Allocate new drm device
464538
* @driver: DRM driver to allocate device for
@@ -499,6 +573,13 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver,
499573
mutex_init(&dev->struct_mutex);
500574
mutex_init(&dev->ctxlist_mutex);
501575

576+
dev->anon_inode = drm_fs_inode_new();
577+
if (IS_ERR(dev->anon_inode)) {
578+
ret = PTR_ERR(dev->anon_inode);
579+
DRM_ERROR("Cannot allocate anonymous inode: %d\n", ret);
580+
goto err_free;
581+
}
582+
502583
if (drm_core_check_feature(dev, DRIVER_MODESET)) {
503584
ret = drm_minor_alloc(dev, DRM_MINOR_CONTROL);
504585
if (ret)
@@ -542,6 +623,8 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver,
542623
drm_minor_free(dev, DRM_MINOR_LEGACY);
543624
drm_minor_free(dev, DRM_MINOR_RENDER);
544625
drm_minor_free(dev, DRM_MINOR_CONTROL);
626+
drm_fs_inode_free(dev->anon_inode);
627+
err_free:
545628
kfree(dev);
546629
return NULL;
547630
}
@@ -556,6 +639,7 @@ static void drm_dev_release(struct kref *ref)
556639

557640
drm_ctxbitmap_cleanup(dev);
558641
drm_ht_remove(&dev->map_hash);
642+
drm_fs_inode_free(dev->anon_inode);
559643

560644
drm_minor_free(dev, DRM_MINOR_LEGACY);
561645
drm_minor_free(dev, DRM_MINOR_RENDER);

‎drivers/gpu/drm/i915/i915_gem.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,8 @@ i915_gem_release_mmap(struct drm_i915_gem_object *obj)
15321532
if (!obj->fault_mappable)
15331533
return;
15341534

1535-
drm_vma_node_unmap(&obj->base.vma_node, obj->base.dev->dev_mapping);
1535+
drm_vma_node_unmap(&obj->base.vma_node,
1536+
obj->base.dev->anon_inode->i_mapping);
15361537
obj->fault_mappable = false;
15371538
}
15381539

‎drivers/gpu/drm/mgag200/mgag200_ttm.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,9 @@ int mgag200_mm_init(struct mga_device *mdev)
259259

260260
ret = ttm_bo_device_init(&mdev->ttm.bdev,
261261
mdev->ttm.bo_global_ref.ref.object,
262-
&mgag200_bo_driver, DRM_FILE_PAGE_OFFSET,
262+
&mgag200_bo_driver,
263+
dev->anon_inode->i_mapping,
264+
DRM_FILE_PAGE_OFFSET,
263265
true);
264266
if (ret) {
265267
DRM_ERROR("Error initialising bo driver; %d\n", ret);
@@ -324,7 +326,6 @@ int mgag200_bo_create(struct drm_device *dev, int size, int align,
324326
}
325327

326328
mgabo->bo.bdev = &mdev->ttm.bdev;
327-
mgabo->bo.bdev->dev_mapping = dev->dev_mapping;
328329

329330
mgag200_ttm_placement(mgabo, TTM_PL_FLAG_VRAM | TTM_PL_FLAG_SYSTEM);
330331

‎drivers/gpu/drm/nouveau/nouveau_gem.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,6 @@ nouveau_gem_ioctl_new(struct drm_device *dev, void *data,
228228
struct nouveau_bo *nvbo = NULL;
229229
int ret = 0;
230230

231-
drm->ttm.bdev.dev_mapping = drm->dev->dev_mapping;
232-
233231
if (!pfb->memtype_valid(pfb, req->info.tile_flags)) {
234232
NV_ERROR(cli, "bad page flags: 0x%08x\n", req->info.tile_flags);
235233
return -EINVAL;

‎drivers/gpu/drm/nouveau/nouveau_ttm.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,9 @@ nouveau_ttm_init(struct nouveau_drm *drm)
376376

377377
ret = ttm_bo_device_init(&drm->ttm.bdev,
378378
drm->ttm.bo_global_ref.ref.object,
379-
&nouveau_bo_driver, DRM_FILE_PAGE_OFFSET,
379+
&nouveau_bo_driver,
380+
dev->anon_inode->i_mapping,
381+
DRM_FILE_PAGE_OFFSET,
380382
bits <= 32 ? true : false);
381383
if (ret) {
382384
NV_ERROR(drm, "error initialising bo driver, %d\n", ret);

‎drivers/gpu/drm/omapdrm/omap_gem.c‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -153,24 +153,24 @@ static struct {
153153
static void evict_entry(struct drm_gem_object *obj,
154154
enum tiler_fmt fmt, struct usergart_entry *entry)
155155
{
156-
if (obj->dev->dev_mapping) {
157-
struct omap_gem_object *omap_obj = to_omap_bo(obj);
158-
int n = usergart[fmt].height;
159-
size_t size = PAGE_SIZE * n;
160-
loff_t off = mmap_offset(obj) +
161-
(entry->obj_pgoff << PAGE_SHIFT);
162-
const int m = 1 + ((omap_obj->width << fmt) / PAGE_SIZE);
163-
if (m > 1) {
164-
int i;
165-
/* if stride > than PAGE_SIZE then sparse mapping: */
166-
for (i = n; i > 0; i--) {
167-
unmap_mapping_range(obj->dev->dev_mapping,
168-
off, PAGE_SIZE, 1);
169-
off += PAGE_SIZE * m;
170-
}
171-
} else {
172-
unmap_mapping_range(obj->dev->dev_mapping, off, size, 1);
156+
struct omap_gem_object *omap_obj = to_omap_bo(obj);
157+
int n = usergart[fmt].height;
158+
size_t size = PAGE_SIZE * n;
159+
loff_t off = mmap_offset(obj) +
160+
(entry->obj_pgoff << PAGE_SHIFT);
161+
const int m = 1 + ((omap_obj->width << fmt) / PAGE_SIZE);
162+
163+
if (m > 1) {
164+
int i;
165+
/* if stride > than PAGE_SIZE then sparse mapping: */
166+
for (i = n; i > 0; i--) {
167+
unmap_mapping_range(obj->dev->anon_inode->i_mapping,
168+
off, PAGE_SIZE, 1);
169+
off += PAGE_SIZE * m;
173170
}
171+
} else {
172+
unmap_mapping_range(obj->dev->anon_inode->i_mapping,
173+
off, size, 1);
174174
}
175175

176176
entry->obj = NULL;

0 commit comments

Comments
 (0)