]>
Commit | Line | Data |
---|---|---|
6ee73861 BS |
1 | /* |
2 | * Copyright (C) 2008 Maarten Maathuis. | |
3 | * All Rights Reserved. | |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining | |
6 | * a copy of this software and associated documentation files (the | |
7 | * "Software"), to deal in the Software without restriction, including | |
8 | * without limitation the rights to use, copy, modify, merge, publish, | |
9 | * distribute, sublicense, and/or sell copies of the Software, and to | |
10 | * permit persons to whom the Software is furnished to do so, subject to | |
11 | * the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice (including the | |
14 | * next paragraph) shall be included in all copies or substantial | |
15 | * portions of the Software. | |
16 | * | |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
20 | * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE | |
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
24 | * | |
25 | */ | |
26 | ||
27 | #include "drmP.h" | |
28 | #include "drm_crtc_helper.h" | |
29 | #include "nouveau_drv.h" | |
30 | #include "nouveau_fb.h" | |
31 | #include "nouveau_fbcon.h" | |
042206c0 | 32 | #include "nouveau_hw.h" |
6ee73861 BS |
33 | |
34 | static void | |
35 | nouveau_user_framebuffer_destroy(struct drm_framebuffer *drm_fb) | |
36 | { | |
37 | struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb); | |
6ee73861 | 38 | |
bc9025bd LB |
39 | if (fb->nvbo) |
40 | drm_gem_object_unreference_unlocked(fb->nvbo->gem); | |
6ee73861 BS |
41 | |
42 | drm_framebuffer_cleanup(drm_fb); | |
43 | kfree(fb); | |
44 | } | |
45 | ||
46 | static int | |
47 | nouveau_user_framebuffer_create_handle(struct drm_framebuffer *drm_fb, | |
48 | struct drm_file *file_priv, | |
49 | unsigned int *handle) | |
50 | { | |
51 | struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb); | |
52 | ||
53 | return drm_gem_handle_create(file_priv, fb->nvbo->gem, handle); | |
54 | } | |
55 | ||
56 | static const struct drm_framebuffer_funcs nouveau_framebuffer_funcs = { | |
57 | .destroy = nouveau_user_framebuffer_destroy, | |
58 | .create_handle = nouveau_user_framebuffer_create_handle, | |
59 | }; | |
60 | ||
38651674 DA |
61 | int |
62 | nouveau_framebuffer_init(struct drm_device *dev, struct nouveau_framebuffer *nouveau_fb, | |
63 | struct drm_mode_fb_cmd *mode_cmd, struct nouveau_bo *nvbo) | |
6ee73861 | 64 | { |
6ee73861 BS |
65 | int ret; |
66 | ||
38651674 | 67 | ret = drm_framebuffer_init(dev, &nouveau_fb->base, &nouveau_framebuffer_funcs); |
6ee73861 | 68 | if (ret) { |
38651674 | 69 | return ret; |
6ee73861 BS |
70 | } |
71 | ||
38651674 DA |
72 | drm_helper_mode_fill_fb_struct(&nouveau_fb->base, mode_cmd); |
73 | nouveau_fb->nvbo = nvbo; | |
74 | return 0; | |
6ee73861 BS |
75 | } |
76 | ||
77 | static struct drm_framebuffer * | |
78 | nouveau_user_framebuffer_create(struct drm_device *dev, | |
79 | struct drm_file *file_priv, | |
80 | struct drm_mode_fb_cmd *mode_cmd) | |
81 | { | |
38651674 | 82 | struct nouveau_framebuffer *nouveau_fb; |
6ee73861 | 83 | struct drm_gem_object *gem; |
38651674 | 84 | int ret; |
6ee73861 BS |
85 | |
86 | gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle); | |
87 | if (!gem) | |
cce13ff7 | 88 | return ERR_PTR(-ENOENT); |
6ee73861 | 89 | |
38651674 DA |
90 | nouveau_fb = kzalloc(sizeof(struct nouveau_framebuffer), GFP_KERNEL); |
91 | if (!nouveau_fb) | |
cce13ff7 | 92 | return ERR_PTR(-ENOMEM); |
38651674 DA |
93 | |
94 | ret = nouveau_framebuffer_init(dev, nouveau_fb, mode_cmd, nouveau_gem_object(gem)); | |
95 | if (ret) { | |
6ee73861 | 96 | drm_gem_object_unreference(gem); |
cce13ff7 | 97 | return ERR_PTR(ret); |
6ee73861 BS |
98 | } |
99 | ||
38651674 | 100 | return &nouveau_fb->base; |
6ee73861 BS |
101 | } |
102 | ||
103 | const struct drm_mode_config_funcs nouveau_mode_config_funcs = { | |
104 | .fb_create = nouveau_user_framebuffer_create, | |
eb1f8e4f | 105 | .output_poll_changed = nouveau_fbcon_output_poll_changed, |
6ee73861 BS |
106 | }; |
107 | ||
042206c0 FJ |
108 | int |
109 | nouveau_vblank_enable(struct drm_device *dev, int crtc) | |
110 | { | |
111 | struct drm_nouveau_private *dev_priv = dev->dev_private; | |
112 | ||
113 | if (dev_priv->card_type >= NV_50) | |
114 | nv_mask(dev, NV50_PDISPLAY_INTR_EN_1, 0, | |
115 | NV50_PDISPLAY_INTR_EN_1_VBLANK_CRTC_(crtc)); | |
116 | else | |
117 | NVWriteCRTC(dev, crtc, NV_PCRTC_INTR_EN_0, | |
118 | NV_PCRTC_INTR_0_VBLANK); | |
119 | ||
120 | return 0; | |
121 | } | |
122 | ||
123 | void | |
124 | nouveau_vblank_disable(struct drm_device *dev, int crtc) | |
125 | { | |
126 | struct drm_nouveau_private *dev_priv = dev->dev_private; | |
127 | ||
128 | if (dev_priv->card_type >= NV_50) | |
129 | nv_mask(dev, NV50_PDISPLAY_INTR_EN_1, | |
130 | NV50_PDISPLAY_INTR_EN_1_VBLANK_CRTC_(crtc), 0); | |
131 | else | |
132 | NVWriteCRTC(dev, crtc, NV_PCRTC_INTR_EN_0, 0); | |
133 | } |