This source file includes following definitions.
- drm_legacy_dma_setup
- drm_legacy_dma_takedown
- drm_legacy_free_buffer
- drm_legacy_reclaim_buffers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 #include <linux/export.h>
37
38 #include <drm/drm_drv.h>
39 #include <drm/drm_pci.h>
40 #include <drm/drm_print.h>
41
42 #include "drm_legacy.h"
43
44
45
46
47
48
49
50
51
52 int drm_legacy_dma_setup(struct drm_device *dev)
53 {
54 int i;
55
56 if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA) ||
57 !drm_core_check_feature(dev, DRIVER_LEGACY))
58 return 0;
59
60 dev->buf_use = 0;
61 atomic_set(&dev->buf_alloc, 0);
62
63 dev->dma = kzalloc(sizeof(*dev->dma), GFP_KERNEL);
64 if (!dev->dma)
65 return -ENOMEM;
66
67 for (i = 0; i <= DRM_MAX_ORDER; i++)
68 memset(&dev->dma->bufs[i], 0, sizeof(dev->dma->bufs[0]));
69
70 return 0;
71 }
72
73
74
75
76
77
78
79
80
81 void drm_legacy_dma_takedown(struct drm_device *dev)
82 {
83 struct drm_device_dma *dma = dev->dma;
84 int i, j;
85
86 if (!drm_core_check_feature(dev, DRIVER_HAVE_DMA) ||
87 !drm_core_check_feature(dev, DRIVER_LEGACY))
88 return;
89
90 if (!dma)
91 return;
92
93
94 for (i = 0; i <= DRM_MAX_ORDER; i++) {
95 if (dma->bufs[i].seg_count) {
96 DRM_DEBUG("order %d: buf_count = %d,"
97 " seg_count = %d\n",
98 i,
99 dma->bufs[i].buf_count,
100 dma->bufs[i].seg_count);
101 for (j = 0; j < dma->bufs[i].seg_count; j++) {
102 if (dma->bufs[i].seglist[j]) {
103 drm_pci_free(dev, dma->bufs[i].seglist[j]);
104 }
105 }
106 kfree(dma->bufs[i].seglist);
107 }
108 if (dma->bufs[i].buf_count) {
109 for (j = 0; j < dma->bufs[i].buf_count; j++) {
110 kfree(dma->bufs[i].buflist[j].dev_private);
111 }
112 kfree(dma->bufs[i].buflist);
113 }
114 }
115
116 kfree(dma->buflist);
117 kfree(dma->pagelist);
118 kfree(dev->dma);
119 dev->dma = NULL;
120 }
121
122
123
124
125
126
127
128
129
130 void drm_legacy_free_buffer(struct drm_device *dev, struct drm_buf * buf)
131 {
132 if (!buf)
133 return;
134
135 buf->waiting = 0;
136 buf->pending = 0;
137 buf->file_priv = NULL;
138 buf->used = 0;
139 }
140
141
142
143
144
145
146
147
148 void drm_legacy_reclaim_buffers(struct drm_device *dev,
149 struct drm_file *file_priv)
150 {
151 struct drm_device_dma *dma = dev->dma;
152 int i;
153
154 if (!dma)
155 return;
156 for (i = 0; i < dma->buf_count; i++) {
157 if (dma->buflist[i]->file_priv == file_priv) {
158 switch (dma->buflist[i]->list) {
159 case DRM_LIST_NONE:
160 drm_legacy_free_buffer(dev, dma->buflist[i]);
161 break;
162 case DRM_LIST_WAIT:
163 dma->buflist[i]->list = DRM_LIST_RECLAIM;
164 break;
165 default:
166
167 break;
168 }
169 }
170 }
171 }