2 * Copyright (C) 2012 Avionic Design GmbH
3 * Copyright (C) 2012-2013 NVIDIA CORPORATION. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
10 #include <linux/host1x.h>
11 #include <linux/iommu.h>
13 #include <drm/drm_atomic.h>
14 #include <drm/drm_atomic_helper.h>
19 #define DRIVER_NAME "tegra"
20 #define DRIVER_DESC "NVIDIA Tegra graphics"
21 #define DRIVER_DATE "20120330"
22 #define DRIVER_MAJOR 0
23 #define DRIVER_MINOR 0
24 #define DRIVER_PATCHLEVEL 0
26 struct tegra_drm_file
{
27 struct list_head contexts
;
30 static void tegra_atomic_schedule(struct tegra_drm
*tegra
,
31 struct drm_atomic_state
*state
)
33 tegra
->commit
.state
= state
;
34 schedule_work(&tegra
->commit
.work
);
37 static void tegra_atomic_complete(struct tegra_drm
*tegra
,
38 struct drm_atomic_state
*state
)
40 struct drm_device
*drm
= tegra
->drm
;
43 * Everything below can be run asynchronously without the need to grab
44 * any modeset locks at all under one condition: It must be guaranteed
45 * that the asynchronous work has either been cancelled (if the driver
46 * supports it, which at least requires that the framebuffers get
47 * cleaned up with drm_atomic_helper_cleanup_planes()) or completed
48 * before the new state gets committed on the software side with
49 * drm_atomic_helper_swap_state().
51 * This scheme allows new atomic state updates to be prepared and
52 * checked in parallel to the asynchronous completion of the previous
53 * update. Which is important since compositors need to figure out the
54 * composition of the next frame right after having submitted the
58 drm_atomic_helper_commit_modeset_disables(drm
, state
);
59 drm_atomic_helper_commit_modeset_enables(drm
, state
);
60 drm_atomic_helper_commit_planes(drm
, state
,
61 DRM_PLANE_COMMIT_ACTIVE_ONLY
);
63 drm_atomic_helper_wait_for_vblanks(drm
, state
);
65 drm_atomic_helper_cleanup_planes(drm
, state
);
66 drm_atomic_state_put(state
);
69 static void tegra_atomic_work(struct work_struct
*work
)
71 struct tegra_drm
*tegra
= container_of(work
, struct tegra_drm
,
74 tegra_atomic_complete(tegra
, tegra
->commit
.state
);
77 static int tegra_atomic_commit(struct drm_device
*drm
,
78 struct drm_atomic_state
*state
, bool nonblock
)
80 struct tegra_drm
*tegra
= drm
->dev_private
;
83 err
= drm_atomic_helper_prepare_planes(drm
, state
);
87 /* serialize outstanding nonblocking commits */
88 mutex_lock(&tegra
->commit
.lock
);
89 flush_work(&tegra
->commit
.work
);
92 * This is the point of no return - everything below never fails except
93 * when the hw goes bonghits. Which means we can commit the new state on
94 * the software side now.
97 drm_atomic_helper_swap_state(state
, true);
99 drm_atomic_state_get(state
);
101 tegra_atomic_schedule(tegra
, state
);
103 tegra_atomic_complete(tegra
, state
);
105 mutex_unlock(&tegra
->commit
.lock
);
109 static const struct drm_mode_config_funcs tegra_drm_mode_funcs
= {
110 .fb_create
= tegra_fb_create
,
111 #ifdef CONFIG_DRM_FBDEV_EMULATION
112 .output_poll_changed
= tegra_fb_output_poll_changed
,
114 .atomic_check
= drm_atomic_helper_check
,
115 .atomic_commit
= tegra_atomic_commit
,
118 static int tegra_drm_load(struct drm_device
*drm
, unsigned long flags
)
120 struct host1x_device
*device
= to_host1x_device(drm
->dev
);
121 struct tegra_drm
*tegra
;
124 tegra
= kzalloc(sizeof(*tegra
), GFP_KERNEL
);
128 if (iommu_present(&platform_bus_type
)) {
129 struct iommu_domain_geometry
*geometry
;
132 tegra
->domain
= iommu_domain_alloc(&platform_bus_type
);
133 if (!tegra
->domain
) {
138 geometry
= &tegra
->domain
->geometry
;
139 start
= geometry
->aperture_start
;
140 end
= geometry
->aperture_end
;
142 DRM_DEBUG_DRIVER("IOMMU aperture initialized (%#llx-%#llx)\n",
144 drm_mm_init(&tegra
->mm
, start
, end
- start
+ 1);
147 mutex_init(&tegra
->clients_lock
);
148 INIT_LIST_HEAD(&tegra
->clients
);
150 mutex_init(&tegra
->commit
.lock
);
151 INIT_WORK(&tegra
->commit
.work
, tegra_atomic_work
);
153 drm
->dev_private
= tegra
;
156 drm_mode_config_init(drm
);
158 drm
->mode_config
.min_width
= 0;
159 drm
->mode_config
.min_height
= 0;
161 drm
->mode_config
.max_width
= 4096;
162 drm
->mode_config
.max_height
= 4096;
164 drm
->mode_config
.funcs
= &tegra_drm_mode_funcs
;
166 err
= tegra_drm_fb_prepare(drm
);
170 drm_kms_helper_poll_init(drm
);
172 err
= host1x_device_init(device
);
177 * We don't use the drm_irq_install() helpers provided by the DRM
178 * core, so we need to set this manually in order to allow the
179 * DRM_IOCTL_WAIT_VBLANK to operate correctly.
181 drm
->irq_enabled
= true;
183 /* syncpoints are used for full 32-bit hardware VBLANK counters */
184 drm
->max_vblank_count
= 0xffffffff;
186 err
= drm_vblank_init(drm
, drm
->mode_config
.num_crtc
);
190 drm_mode_config_reset(drm
);
192 err
= tegra_drm_fb_init(drm
);
199 drm_vblank_cleanup(drm
);
201 host1x_device_exit(device
);
203 drm_kms_helper_poll_fini(drm
);
204 tegra_drm_fb_free(drm
);
206 drm_mode_config_cleanup(drm
);
209 iommu_domain_free(tegra
->domain
);
210 drm_mm_takedown(&tegra
->mm
);
217 static void tegra_drm_unload(struct drm_device
*drm
)
219 struct host1x_device
*device
= to_host1x_device(drm
->dev
);
220 struct tegra_drm
*tegra
= drm
->dev_private
;
223 drm_kms_helper_poll_fini(drm
);
224 tegra_drm_fb_exit(drm
);
225 drm_mode_config_cleanup(drm
);
226 drm_vblank_cleanup(drm
);
228 err
= host1x_device_exit(device
);
233 iommu_domain_free(tegra
->domain
);
234 drm_mm_takedown(&tegra
->mm
);
240 static int tegra_drm_open(struct drm_device
*drm
, struct drm_file
*filp
)
242 struct tegra_drm_file
*fpriv
;
244 fpriv
= kzalloc(sizeof(*fpriv
), GFP_KERNEL
);
248 INIT_LIST_HEAD(&fpriv
->contexts
);
249 filp
->driver_priv
= fpriv
;
254 static void tegra_drm_context_free(struct tegra_drm_context
*context
)
256 context
->client
->ops
->close_channel(context
);
260 static void tegra_drm_lastclose(struct drm_device
*drm
)
262 #ifdef CONFIG_DRM_FBDEV_EMULATION
263 struct tegra_drm
*tegra
= drm
->dev_private
;
265 tegra_fbdev_restore_mode(tegra
->fbdev
);
269 static struct host1x_bo
*
270 host1x_bo_lookup(struct drm_file
*file
, u32 handle
)
272 struct drm_gem_object
*gem
;
275 gem
= drm_gem_object_lookup(file
, handle
);
279 drm_gem_object_unreference_unlocked(gem
);
281 bo
= to_tegra_bo(gem
);
285 static int host1x_reloc_copy_from_user(struct host1x_reloc
*dest
,
286 struct drm_tegra_reloc __user
*src
,
287 struct drm_device
*drm
,
288 struct drm_file
*file
)
293 err
= get_user(cmdbuf
, &src
->cmdbuf
.handle
);
297 err
= get_user(dest
->cmdbuf
.offset
, &src
->cmdbuf
.offset
);
301 err
= get_user(target
, &src
->target
.handle
);
305 err
= get_user(dest
->target
.offset
, &src
->target
.offset
);
309 err
= get_user(dest
->shift
, &src
->shift
);
313 dest
->cmdbuf
.bo
= host1x_bo_lookup(file
, cmdbuf
);
314 if (!dest
->cmdbuf
.bo
)
317 dest
->target
.bo
= host1x_bo_lookup(file
, target
);
318 if (!dest
->target
.bo
)
324 int tegra_drm_submit(struct tegra_drm_context
*context
,
325 struct drm_tegra_submit
*args
, struct drm_device
*drm
,
326 struct drm_file
*file
)
328 unsigned int num_cmdbufs
= args
->num_cmdbufs
;
329 unsigned int num_relocs
= args
->num_relocs
;
330 unsigned int num_waitchks
= args
->num_waitchks
;
331 struct drm_tegra_cmdbuf __user
*cmdbufs
=
332 (void __user
*)(uintptr_t)args
->cmdbufs
;
333 struct drm_tegra_reloc __user
*relocs
=
334 (void __user
*)(uintptr_t)args
->relocs
;
335 struct drm_tegra_waitchk __user
*waitchks
=
336 (void __user
*)(uintptr_t)args
->waitchks
;
337 struct drm_tegra_syncpt syncpt
;
338 struct host1x_job
*job
;
341 /* We don't yet support other than one syncpt_incr struct per submit */
342 if (args
->num_syncpts
!= 1)
345 job
= host1x_job_alloc(context
->channel
, args
->num_cmdbufs
,
346 args
->num_relocs
, args
->num_waitchks
);
350 job
->num_relocs
= args
->num_relocs
;
351 job
->num_waitchk
= args
->num_waitchks
;
352 job
->client
= (u32
)args
->context
;
353 job
->class = context
->client
->base
.class;
354 job
->serialize
= true;
356 while (num_cmdbufs
) {
357 struct drm_tegra_cmdbuf cmdbuf
;
358 struct host1x_bo
*bo
;
360 if (copy_from_user(&cmdbuf
, cmdbufs
, sizeof(cmdbuf
))) {
365 bo
= host1x_bo_lookup(file
, cmdbuf
.handle
);
371 host1x_job_add_gather(job
, bo
, cmdbuf
.words
, cmdbuf
.offset
);
376 /* copy and resolve relocations from submit */
377 while (num_relocs
--) {
378 err
= host1x_reloc_copy_from_user(&job
->relocarray
[num_relocs
],
379 &relocs
[num_relocs
], drm
,
385 if (copy_from_user(job
->waitchk
, waitchks
,
386 sizeof(*waitchks
) * num_waitchks
)) {
391 if (copy_from_user(&syncpt
, (void __user
*)(uintptr_t)args
->syncpts
,
397 job
->is_addr_reg
= context
->client
->ops
->is_addr_reg
;
398 job
->syncpt_incrs
= syncpt
.incrs
;
399 job
->syncpt_id
= syncpt
.id
;
400 job
->timeout
= 10000;
402 if (args
->timeout
&& args
->timeout
< 10000)
403 job
->timeout
= args
->timeout
;
405 err
= host1x_job_pin(job
, context
->client
->base
.dev
);
409 err
= host1x_job_submit(job
);
413 args
->fence
= job
->syncpt_end
;
419 host1x_job_unpin(job
);
426 #ifdef CONFIG_DRM_TEGRA_STAGING
427 static struct tegra_drm_context
*tegra_drm_get_context(__u64 context
)
429 return (struct tegra_drm_context
*)(uintptr_t)context
;
432 static bool tegra_drm_file_owns_context(struct tegra_drm_file
*file
,
433 struct tegra_drm_context
*context
)
435 struct tegra_drm_context
*ctx
;
437 list_for_each_entry(ctx
, &file
->contexts
, list
)
444 static int tegra_gem_create(struct drm_device
*drm
, void *data
,
445 struct drm_file
*file
)
447 struct drm_tegra_gem_create
*args
= data
;
450 bo
= tegra_bo_create_with_handle(file
, drm
, args
->size
, args
->flags
,
458 static int tegra_gem_mmap(struct drm_device
*drm
, void *data
,
459 struct drm_file
*file
)
461 struct drm_tegra_gem_mmap
*args
= data
;
462 struct drm_gem_object
*gem
;
465 gem
= drm_gem_object_lookup(file
, args
->handle
);
469 bo
= to_tegra_bo(gem
);
471 args
->offset
= drm_vma_node_offset_addr(&bo
->gem
.vma_node
);
473 drm_gem_object_unreference_unlocked(gem
);
478 static int tegra_syncpt_read(struct drm_device
*drm
, void *data
,
479 struct drm_file
*file
)
481 struct host1x
*host
= dev_get_drvdata(drm
->dev
->parent
);
482 struct drm_tegra_syncpt_read
*args
= data
;
483 struct host1x_syncpt
*sp
;
485 sp
= host1x_syncpt_get(host
, args
->id
);
489 args
->value
= host1x_syncpt_read_min(sp
);
493 static int tegra_syncpt_incr(struct drm_device
*drm
, void *data
,
494 struct drm_file
*file
)
496 struct host1x
*host1x
= dev_get_drvdata(drm
->dev
->parent
);
497 struct drm_tegra_syncpt_incr
*args
= data
;
498 struct host1x_syncpt
*sp
;
500 sp
= host1x_syncpt_get(host1x
, args
->id
);
504 return host1x_syncpt_incr(sp
);
507 static int tegra_syncpt_wait(struct drm_device
*drm
, void *data
,
508 struct drm_file
*file
)
510 struct host1x
*host1x
= dev_get_drvdata(drm
->dev
->parent
);
511 struct drm_tegra_syncpt_wait
*args
= data
;
512 struct host1x_syncpt
*sp
;
514 sp
= host1x_syncpt_get(host1x
, args
->id
);
518 return host1x_syncpt_wait(sp
, args
->thresh
, args
->timeout
,
522 static int tegra_open_channel(struct drm_device
*drm
, void *data
,
523 struct drm_file
*file
)
525 struct tegra_drm_file
*fpriv
= file
->driver_priv
;
526 struct tegra_drm
*tegra
= drm
->dev_private
;
527 struct drm_tegra_open_channel
*args
= data
;
528 struct tegra_drm_context
*context
;
529 struct tegra_drm_client
*client
;
532 context
= kzalloc(sizeof(*context
), GFP_KERNEL
);
536 list_for_each_entry(client
, &tegra
->clients
, list
)
537 if (client
->base
.class == args
->client
) {
538 err
= client
->ops
->open_channel(client
, context
);
542 list_add(&context
->list
, &fpriv
->contexts
);
543 args
->context
= (uintptr_t)context
;
544 context
->client
= client
;
552 static int tegra_close_channel(struct drm_device
*drm
, void *data
,
553 struct drm_file
*file
)
555 struct tegra_drm_file
*fpriv
= file
->driver_priv
;
556 struct drm_tegra_close_channel
*args
= data
;
557 struct tegra_drm_context
*context
;
559 context
= tegra_drm_get_context(args
->context
);
561 if (!tegra_drm_file_owns_context(fpriv
, context
))
564 list_del(&context
->list
);
565 tegra_drm_context_free(context
);
570 static int tegra_get_syncpt(struct drm_device
*drm
, void *data
,
571 struct drm_file
*file
)
573 struct tegra_drm_file
*fpriv
= file
->driver_priv
;
574 struct drm_tegra_get_syncpt
*args
= data
;
575 struct tegra_drm_context
*context
;
576 struct host1x_syncpt
*syncpt
;
578 context
= tegra_drm_get_context(args
->context
);
580 if (!tegra_drm_file_owns_context(fpriv
, context
))
583 if (args
->index
>= context
->client
->base
.num_syncpts
)
586 syncpt
= context
->client
->base
.syncpts
[args
->index
];
587 args
->id
= host1x_syncpt_id(syncpt
);
592 static int tegra_submit(struct drm_device
*drm
, void *data
,
593 struct drm_file
*file
)
595 struct tegra_drm_file
*fpriv
= file
->driver_priv
;
596 struct drm_tegra_submit
*args
= data
;
597 struct tegra_drm_context
*context
;
599 context
= tegra_drm_get_context(args
->context
);
601 if (!tegra_drm_file_owns_context(fpriv
, context
))
604 return context
->client
->ops
->submit(context
, args
, drm
, file
);
607 static int tegra_get_syncpt_base(struct drm_device
*drm
, void *data
,
608 struct drm_file
*file
)
610 struct tegra_drm_file
*fpriv
= file
->driver_priv
;
611 struct drm_tegra_get_syncpt_base
*args
= data
;
612 struct tegra_drm_context
*context
;
613 struct host1x_syncpt_base
*base
;
614 struct host1x_syncpt
*syncpt
;
616 context
= tegra_drm_get_context(args
->context
);
618 if (!tegra_drm_file_owns_context(fpriv
, context
))
621 if (args
->syncpt
>= context
->client
->base
.num_syncpts
)
624 syncpt
= context
->client
->base
.syncpts
[args
->syncpt
];
626 base
= host1x_syncpt_get_base(syncpt
);
630 args
->id
= host1x_syncpt_base_id(base
);
635 static int tegra_gem_set_tiling(struct drm_device
*drm
, void *data
,
636 struct drm_file
*file
)
638 struct drm_tegra_gem_set_tiling
*args
= data
;
639 enum tegra_bo_tiling_mode mode
;
640 struct drm_gem_object
*gem
;
641 unsigned long value
= 0;
644 switch (args
->mode
) {
645 case DRM_TEGRA_GEM_TILING_MODE_PITCH
:
646 mode
= TEGRA_BO_TILING_MODE_PITCH
;
648 if (args
->value
!= 0)
653 case DRM_TEGRA_GEM_TILING_MODE_TILED
:
654 mode
= TEGRA_BO_TILING_MODE_TILED
;
656 if (args
->value
!= 0)
661 case DRM_TEGRA_GEM_TILING_MODE_BLOCK
:
662 mode
= TEGRA_BO_TILING_MODE_BLOCK
;
674 gem
= drm_gem_object_lookup(file
, args
->handle
);
678 bo
= to_tegra_bo(gem
);
680 bo
->tiling
.mode
= mode
;
681 bo
->tiling
.value
= value
;
683 drm_gem_object_unreference_unlocked(gem
);
688 static int tegra_gem_get_tiling(struct drm_device
*drm
, void *data
,
689 struct drm_file
*file
)
691 struct drm_tegra_gem_get_tiling
*args
= data
;
692 struct drm_gem_object
*gem
;
696 gem
= drm_gem_object_lookup(file
, args
->handle
);
700 bo
= to_tegra_bo(gem
);
702 switch (bo
->tiling
.mode
) {
703 case TEGRA_BO_TILING_MODE_PITCH
:
704 args
->mode
= DRM_TEGRA_GEM_TILING_MODE_PITCH
;
708 case TEGRA_BO_TILING_MODE_TILED
:
709 args
->mode
= DRM_TEGRA_GEM_TILING_MODE_TILED
;
713 case TEGRA_BO_TILING_MODE_BLOCK
:
714 args
->mode
= DRM_TEGRA_GEM_TILING_MODE_BLOCK
;
715 args
->value
= bo
->tiling
.value
;
723 drm_gem_object_unreference_unlocked(gem
);
728 static int tegra_gem_set_flags(struct drm_device
*drm
, void *data
,
729 struct drm_file
*file
)
731 struct drm_tegra_gem_set_flags
*args
= data
;
732 struct drm_gem_object
*gem
;
735 if (args
->flags
& ~DRM_TEGRA_GEM_FLAGS
)
738 gem
= drm_gem_object_lookup(file
, args
->handle
);
742 bo
= to_tegra_bo(gem
);
745 if (args
->flags
& DRM_TEGRA_GEM_BOTTOM_UP
)
746 bo
->flags
|= TEGRA_BO_BOTTOM_UP
;
748 drm_gem_object_unreference_unlocked(gem
);
753 static int tegra_gem_get_flags(struct drm_device
*drm
, void *data
,
754 struct drm_file
*file
)
756 struct drm_tegra_gem_get_flags
*args
= data
;
757 struct drm_gem_object
*gem
;
760 gem
= drm_gem_object_lookup(file
, args
->handle
);
764 bo
= to_tegra_bo(gem
);
767 if (bo
->flags
& TEGRA_BO_BOTTOM_UP
)
768 args
->flags
|= DRM_TEGRA_GEM_BOTTOM_UP
;
770 drm_gem_object_unreference_unlocked(gem
);
776 static const struct drm_ioctl_desc tegra_drm_ioctls
[] = {
777 #ifdef CONFIG_DRM_TEGRA_STAGING
778 DRM_IOCTL_DEF_DRV(TEGRA_GEM_CREATE
, tegra_gem_create
, 0),
779 DRM_IOCTL_DEF_DRV(TEGRA_GEM_MMAP
, tegra_gem_mmap
, 0),
780 DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_READ
, tegra_syncpt_read
, 0),
781 DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_INCR
, tegra_syncpt_incr
, 0),
782 DRM_IOCTL_DEF_DRV(TEGRA_SYNCPT_WAIT
, tegra_syncpt_wait
, 0),
783 DRM_IOCTL_DEF_DRV(TEGRA_OPEN_CHANNEL
, tegra_open_channel
, 0),
784 DRM_IOCTL_DEF_DRV(TEGRA_CLOSE_CHANNEL
, tegra_close_channel
, 0),
785 DRM_IOCTL_DEF_DRV(TEGRA_GET_SYNCPT
, tegra_get_syncpt
, 0),
786 DRM_IOCTL_DEF_DRV(TEGRA_SUBMIT
, tegra_submit
, 0),
787 DRM_IOCTL_DEF_DRV(TEGRA_GET_SYNCPT_BASE
, tegra_get_syncpt_base
, 0),
788 DRM_IOCTL_DEF_DRV(TEGRA_GEM_SET_TILING
, tegra_gem_set_tiling
, 0),
789 DRM_IOCTL_DEF_DRV(TEGRA_GEM_GET_TILING
, tegra_gem_get_tiling
, 0),
790 DRM_IOCTL_DEF_DRV(TEGRA_GEM_SET_FLAGS
, tegra_gem_set_flags
, 0),
791 DRM_IOCTL_DEF_DRV(TEGRA_GEM_GET_FLAGS
, tegra_gem_get_flags
, 0),
795 static const struct file_operations tegra_drm_fops
= {
796 .owner
= THIS_MODULE
,
798 .release
= drm_release
,
799 .unlocked_ioctl
= drm_ioctl
,
800 .mmap
= tegra_drm_mmap
,
803 .compat_ioctl
= drm_compat_ioctl
,
804 .llseek
= noop_llseek
,
807 static u32
tegra_drm_get_vblank_counter(struct drm_device
*drm
,
810 struct drm_crtc
*crtc
= drm_crtc_from_index(drm
, pipe
);
811 struct tegra_dc
*dc
= to_tegra_dc(crtc
);
816 return tegra_dc_get_vblank_counter(dc
);
819 static int tegra_drm_enable_vblank(struct drm_device
*drm
, unsigned int pipe
)
821 struct drm_crtc
*crtc
= drm_crtc_from_index(drm
, pipe
);
822 struct tegra_dc
*dc
= to_tegra_dc(crtc
);
827 tegra_dc_enable_vblank(dc
);
832 static void tegra_drm_disable_vblank(struct drm_device
*drm
, unsigned int pipe
)
834 struct drm_crtc
*crtc
= drm_crtc_from_index(drm
, pipe
);
835 struct tegra_dc
*dc
= to_tegra_dc(crtc
);
838 tegra_dc_disable_vblank(dc
);
841 static void tegra_drm_preclose(struct drm_device
*drm
, struct drm_file
*file
)
843 struct tegra_drm_file
*fpriv
= file
->driver_priv
;
844 struct tegra_drm_context
*context
, *tmp
;
846 list_for_each_entry_safe(context
, tmp
, &fpriv
->contexts
, list
)
847 tegra_drm_context_free(context
);
852 #ifdef CONFIG_DEBUG_FS
853 static int tegra_debugfs_framebuffers(struct seq_file
*s
, void *data
)
855 struct drm_info_node
*node
= (struct drm_info_node
*)s
->private;
856 struct drm_device
*drm
= node
->minor
->dev
;
857 struct drm_framebuffer
*fb
;
859 mutex_lock(&drm
->mode_config
.fb_lock
);
861 list_for_each_entry(fb
, &drm
->mode_config
.fb_list
, head
) {
862 seq_printf(s
, "%3d: user size: %d x %d, depth %d, %d bpp, refcount %d\n",
863 fb
->base
.id
, fb
->width
, fb
->height
,
865 fb
->format
->cpp
[0] * 8,
866 drm_framebuffer_read_refcount(fb
));
869 mutex_unlock(&drm
->mode_config
.fb_lock
);
874 static int tegra_debugfs_iova(struct seq_file
*s
, void *data
)
876 struct drm_info_node
*node
= (struct drm_info_node
*)s
->private;
877 struct drm_device
*drm
= node
->minor
->dev
;
878 struct tegra_drm
*tegra
= drm
->dev_private
;
879 struct drm_printer p
= drm_seq_file_printer(s
);
881 drm_mm_print(&tegra
->mm
, &p
);
886 static struct drm_info_list tegra_debugfs_list
[] = {
887 { "framebuffers", tegra_debugfs_framebuffers
, 0 },
888 { "iova", tegra_debugfs_iova
, 0 },
891 static int tegra_debugfs_init(struct drm_minor
*minor
)
893 return drm_debugfs_create_files(tegra_debugfs_list
,
894 ARRAY_SIZE(tegra_debugfs_list
),
895 minor
->debugfs_root
, minor
);
898 static void tegra_debugfs_cleanup(struct drm_minor
*minor
)
900 drm_debugfs_remove_files(tegra_debugfs_list
,
901 ARRAY_SIZE(tegra_debugfs_list
), minor
);
905 static struct drm_driver tegra_drm_driver
= {
906 .driver_features
= DRIVER_MODESET
| DRIVER_GEM
| DRIVER_PRIME
|
908 .load
= tegra_drm_load
,
909 .unload
= tegra_drm_unload
,
910 .open
= tegra_drm_open
,
911 .preclose
= tegra_drm_preclose
,
912 .lastclose
= tegra_drm_lastclose
,
914 .get_vblank_counter
= tegra_drm_get_vblank_counter
,
915 .enable_vblank
= tegra_drm_enable_vblank
,
916 .disable_vblank
= tegra_drm_disable_vblank
,
918 #if defined(CONFIG_DEBUG_FS)
919 .debugfs_init
= tegra_debugfs_init
,
920 .debugfs_cleanup
= tegra_debugfs_cleanup
,
923 .gem_free_object_unlocked
= tegra_bo_free_object
,
924 .gem_vm_ops
= &tegra_bo_vm_ops
,
926 .prime_handle_to_fd
= drm_gem_prime_handle_to_fd
,
927 .prime_fd_to_handle
= drm_gem_prime_fd_to_handle
,
928 .gem_prime_export
= tegra_gem_prime_export
,
929 .gem_prime_import
= tegra_gem_prime_import
,
931 .dumb_create
= tegra_bo_dumb_create
,
932 .dumb_map_offset
= tegra_bo_dumb_map_offset
,
933 .dumb_destroy
= drm_gem_dumb_destroy
,
935 .ioctls
= tegra_drm_ioctls
,
936 .num_ioctls
= ARRAY_SIZE(tegra_drm_ioctls
),
937 .fops
= &tegra_drm_fops
,
942 .major
= DRIVER_MAJOR
,
943 .minor
= DRIVER_MINOR
,
944 .patchlevel
= DRIVER_PATCHLEVEL
,
947 int tegra_drm_register_client(struct tegra_drm
*tegra
,
948 struct tegra_drm_client
*client
)
950 mutex_lock(&tegra
->clients_lock
);
951 list_add_tail(&client
->list
, &tegra
->clients
);
952 mutex_unlock(&tegra
->clients_lock
);
957 int tegra_drm_unregister_client(struct tegra_drm
*tegra
,
958 struct tegra_drm_client
*client
)
960 mutex_lock(&tegra
->clients_lock
);
961 list_del_init(&client
->list
);
962 mutex_unlock(&tegra
->clients_lock
);
967 static int host1x_drm_probe(struct host1x_device
*dev
)
969 struct drm_driver
*driver
= &tegra_drm_driver
;
970 struct drm_device
*drm
;
973 drm
= drm_dev_alloc(driver
, &dev
->dev
);
977 dev_set_drvdata(&dev
->dev
, drm
);
979 err
= drm_dev_register(drm
, 0);
990 static int host1x_drm_remove(struct host1x_device
*dev
)
992 struct drm_device
*drm
= dev_get_drvdata(&dev
->dev
);
994 drm_dev_unregister(drm
);
1000 #ifdef CONFIG_PM_SLEEP
1001 static int host1x_drm_suspend(struct device
*dev
)
1003 struct drm_device
*drm
= dev_get_drvdata(dev
);
1004 struct tegra_drm
*tegra
= drm
->dev_private
;
1006 drm_kms_helper_poll_disable(drm
);
1007 tegra_drm_fb_suspend(drm
);
1009 tegra
->state
= drm_atomic_helper_suspend(drm
);
1010 if (IS_ERR(tegra
->state
)) {
1011 tegra_drm_fb_resume(drm
);
1012 drm_kms_helper_poll_enable(drm
);
1013 return PTR_ERR(tegra
->state
);
1019 static int host1x_drm_resume(struct device
*dev
)
1021 struct drm_device
*drm
= dev_get_drvdata(dev
);
1022 struct tegra_drm
*tegra
= drm
->dev_private
;
1024 drm_atomic_helper_resume(drm
, tegra
->state
);
1025 tegra_drm_fb_resume(drm
);
1026 drm_kms_helper_poll_enable(drm
);
1032 static SIMPLE_DEV_PM_OPS(host1x_drm_pm_ops
, host1x_drm_suspend
,
1035 static const struct of_device_id host1x_drm_subdevs
[] = {
1036 { .compatible
= "nvidia,tegra20-dc", },
1037 { .compatible
= "nvidia,tegra20-hdmi", },
1038 { .compatible
= "nvidia,tegra20-gr2d", },
1039 { .compatible
= "nvidia,tegra20-gr3d", },
1040 { .compatible
= "nvidia,tegra30-dc", },
1041 { .compatible
= "nvidia,tegra30-hdmi", },
1042 { .compatible
= "nvidia,tegra30-gr2d", },
1043 { .compatible
= "nvidia,tegra30-gr3d", },
1044 { .compatible
= "nvidia,tegra114-dsi", },
1045 { .compatible
= "nvidia,tegra114-hdmi", },
1046 { .compatible
= "nvidia,tegra114-gr3d", },
1047 { .compatible
= "nvidia,tegra124-dc", },
1048 { .compatible
= "nvidia,tegra124-sor", },
1049 { .compatible
= "nvidia,tegra124-hdmi", },
1050 { .compatible
= "nvidia,tegra124-dsi", },
1051 { .compatible
= "nvidia,tegra132-dsi", },
1052 { .compatible
= "nvidia,tegra210-dc", },
1053 { .compatible
= "nvidia,tegra210-dsi", },
1054 { .compatible
= "nvidia,tegra210-sor", },
1055 { .compatible
= "nvidia,tegra210-sor1", },
1059 static struct host1x_driver host1x_drm_driver
= {
1062 .pm
= &host1x_drm_pm_ops
,
1064 .probe
= host1x_drm_probe
,
1065 .remove
= host1x_drm_remove
,
1066 .subdevs
= host1x_drm_subdevs
,
1069 static struct platform_driver
* const drivers
[] = {
1073 &tegra_dpaux_driver
,
1079 static int __init
host1x_drm_init(void)
1083 err
= host1x_driver_register(&host1x_drm_driver
);
1087 err
= platform_register_drivers(drivers
, ARRAY_SIZE(drivers
));
1089 goto unregister_host1x
;
1094 host1x_driver_unregister(&host1x_drm_driver
);
1097 module_init(host1x_drm_init
);
1099 static void __exit
host1x_drm_exit(void)
1101 platform_unregister_drivers(drivers
, ARRAY_SIZE(drivers
));
1102 host1x_driver_unregister(&host1x_drm_driver
);
1104 module_exit(host1x_drm_exit
);
1106 MODULE_AUTHOR("Thierry Reding <thierry.reding@avionic-design.de>");
1107 MODULE_DESCRIPTION("NVIDIA Tegra DRM driver");
1108 MODULE_LICENSE("GPL v2");