This source file includes following definitions.
- psb_gem_free_object
- psb_gem_get_aperture
- psb_gem_create
- psb_gem_dumb_create
- psb_gem_fault
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #include <linux/pagemap.h>
15
16 #include <drm/drm.h>
17 #include <drm/drm_vma_manager.h>
18
19 #include "psb_drv.h"
20
21 void psb_gem_free_object(struct drm_gem_object *obj)
22 {
23 struct gtt_range *gtt = container_of(obj, struct gtt_range, gem);
24
25
26 drm_gem_free_mmap_offset(obj);
27 drm_gem_object_release(obj);
28
29
30 psb_gtt_free_range(obj->dev, gtt);
31 }
32
33 int psb_gem_get_aperture(struct drm_device *dev, void *data,
34 struct drm_file *file)
35 {
36 return -EINVAL;
37 }
38
39
40
41
42
43
44
45
46
47
48
49
50 int psb_gem_create(struct drm_file *file, struct drm_device *dev, u64 size,
51 u32 *handlep, int stolen, u32 align)
52 {
53 struct gtt_range *r;
54 int ret;
55 u32 handle;
56
57 size = roundup(size, PAGE_SIZE);
58
59
60
61 r = psb_gtt_alloc_range(dev, size, "gem", 0, PAGE_SIZE);
62 if (r == NULL) {
63 dev_err(dev->dev, "no memory for %lld byte GEM object\n", size);
64 return -ENOSPC;
65 }
66
67 if (drm_gem_object_init(dev, &r->gem, size) != 0) {
68 psb_gtt_free_range(dev, r);
69
70 dev_err(dev->dev, "GEM init failed for %lld\n", size);
71 return -ENOMEM;
72 }
73
74 mapping_set_gfp_mask(r->gem.filp->f_mapping, GFP_KERNEL | __GFP_DMA32);
75
76 ret = drm_gem_handle_create(file, &r->gem, &handle);
77 if (ret) {
78 dev_err(dev->dev, "GEM handle failed for %p, %lld\n",
79 &r->gem, size);
80 drm_gem_object_release(&r->gem);
81 psb_gtt_free_range(dev, r);
82 return ret;
83 }
84
85 drm_gem_object_put_unlocked(&r->gem);
86 *handlep = handle;
87 return 0;
88 }
89
90
91
92
93
94
95
96
97
98
99
100 int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
101 struct drm_mode_create_dumb *args)
102 {
103 args->pitch = ALIGN(args->width * ((args->bpp + 7) / 8), 64);
104 args->size = args->pitch * args->height;
105 return psb_gem_create(file, dev, args->size, &args->handle, 0,
106 PAGE_SIZE);
107 }
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126 vm_fault_t psb_gem_fault(struct vm_fault *vmf)
127 {
128 struct vm_area_struct *vma = vmf->vma;
129 struct drm_gem_object *obj;
130 struct gtt_range *r;
131 int err;
132 vm_fault_t ret;
133 unsigned long pfn;
134 pgoff_t page_offset;
135 struct drm_device *dev;
136 struct drm_psb_private *dev_priv;
137
138 obj = vma->vm_private_data;
139 dev = obj->dev;
140 dev_priv = dev->dev_private;
141
142 r = container_of(obj, struct gtt_range, gem);
143
144
145
146 mutex_lock(&dev_priv->mmap_mutex);
147
148
149
150 if (r->mmapping == 0) {
151 err = psb_gtt_pin(r);
152 if (err < 0) {
153 dev_err(dev->dev, "gma500: pin failed: %d\n", err);
154 ret = vmf_error(err);
155 goto fail;
156 }
157 r->mmapping = 1;
158 }
159
160
161
162 page_offset = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
163
164
165 if (r->stolen)
166 pfn = (dev_priv->stolen_base + r->offset) >> PAGE_SHIFT;
167 else
168 pfn = page_to_pfn(r->pages[page_offset]);
169 ret = vmf_insert_pfn(vma, vmf->address, pfn);
170 fail:
171 mutex_unlock(&dev_priv->mmap_mutex);
172
173 return ret;
174 }