diff options
Diffstat (limited to 'drivers/media/video/saa7164/saa7164-buffer.c')
-rw-r--r-- | drivers/media/video/saa7164/saa7164-buffer.c | 194 |
1 files changed, 180 insertions, 14 deletions
diff --git a/drivers/media/video/saa7164/saa7164-buffer.c b/drivers/media/video/saa7164/saa7164-buffer.c index ddd25d32723d..7230912acc7d 100644 --- a/drivers/media/video/saa7164/saa7164-buffer.c +++ b/drivers/media/video/saa7164/saa7164-buffer.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * Driver for the NXP SAA7164 PCIe bridge | 2 | * Driver for the NXP SAA7164 PCIe bridge |
3 | * | 3 | * |
4 | * Copyright (c) 2009 Steven Toth <stoth@kernellabs.com> | 4 | * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by | 7 | * it under the terms of the GNU General Public License as published by |
@@ -66,12 +66,33 @@ | |||
66 | | etc | 66 | | etc |
67 | */ | 67 | */ |
68 | 68 | ||
69 | void saa7164_buffer_display(struct saa7164_buffer *buf) | ||
70 | { | ||
71 | struct saa7164_dev *dev = buf->port->dev; | ||
72 | int i; | ||
73 | |||
74 | dprintk(DBGLVL_BUF, "%s() buffer @ 0x%p nr=%d\n", | ||
75 | __func__, buf, buf->idx); | ||
76 | dprintk(DBGLVL_BUF, " pci_cpu @ 0x%p dma @ 0x%08llx len = 0x%x\n", | ||
77 | buf->cpu, (long long)buf->dma, buf->pci_size); | ||
78 | dprintk(DBGLVL_BUF, " pt_cpu @ 0x%p pt_dma @ 0x%08llx len = 0x%x\n", | ||
79 | buf->pt_cpu, (long long)buf->pt_dma, buf->pt_size); | ||
80 | |||
81 | /* Format the Page Table Entries to point into the data buffer */ | ||
82 | for (i = 0 ; i < SAA7164_PT_ENTRIES; i++) { | ||
83 | |||
84 | dprintk(DBGLVL_BUF, " pt[%02d] = 0x%p -> 0x%llx\n", | ||
85 | i, buf->pt_cpu, (u64)*(buf->pt_cpu)); | ||
86 | |||
87 | } | ||
88 | } | ||
69 | /* Allocate a new buffer structure and associated PCI space in bytes. | 89 | /* Allocate a new buffer structure and associated PCI space in bytes. |
70 | * len must be a multiple of sizeof(u64) | 90 | * len must be a multiple of sizeof(u64) |
71 | */ | 91 | */ |
72 | struct saa7164_buffer *saa7164_buffer_alloc(struct saa7164_tsport *port, | 92 | struct saa7164_buffer *saa7164_buffer_alloc(struct saa7164_port *port, |
73 | u32 len) | 93 | u32 len) |
74 | { | 94 | { |
95 | struct tmHWStreamParameters *params = &port->hw_streamingparams; | ||
75 | struct saa7164_buffer *buf = 0; | 96 | struct saa7164_buffer *buf = 0; |
76 | struct saa7164_dev *dev = port->dev; | 97 | struct saa7164_dev *dev = port->dev; |
77 | int i; | 98 | int i; |
@@ -87,8 +108,12 @@ struct saa7164_buffer *saa7164_buffer_alloc(struct saa7164_tsport *port, | |||
87 | goto ret; | 108 | goto ret; |
88 | } | 109 | } |
89 | 110 | ||
111 | buf->idx = -1; | ||
90 | buf->port = port; | 112 | buf->port = port; |
91 | buf->flags = SAA7164_BUFFER_FREE; | 113 | buf->flags = SAA7164_BUFFER_FREE; |
114 | buf->pos = 0; | ||
115 | buf->actual_size = params->pitch * params->numberoflines; | ||
116 | buf->crc = 0; | ||
92 | /* TODO: arg len is being ignored */ | 117 | /* TODO: arg len is being ignored */ |
93 | buf->pci_size = SAA7164_PT_ENTRIES * 0x1000; | 118 | buf->pci_size = SAA7164_PT_ENTRIES * 0x1000; |
94 | buf->pt_size = (SAA7164_PT_ENTRIES * sizeof(u64)) + 0x1000; | 119 | buf->pt_size = (SAA7164_PT_ENTRIES * sizeof(u64)) + 0x1000; |
@@ -105,19 +130,23 @@ struct saa7164_buffer *saa7164_buffer_alloc(struct saa7164_tsport *port, | |||
105 | goto fail2; | 130 | goto fail2; |
106 | 131 | ||
107 | /* init the buffers to a known pattern, easier during debugging */ | 132 | /* init the buffers to a known pattern, easier during debugging */ |
108 | memset(buf->cpu, 0xff, buf->pci_size); | 133 | memset_io(buf->cpu, 0xff, buf->pci_size); |
109 | memset(buf->pt_cpu, 0xff, buf->pt_size); | 134 | buf->crc = crc32(0, buf->cpu, buf->actual_size); |
135 | memset_io(buf->pt_cpu, 0xff, buf->pt_size); | ||
110 | 136 | ||
111 | dprintk(DBGLVL_BUF, "%s() allocated buffer @ 0x%p\n", __func__, buf); | 137 | dprintk(DBGLVL_BUF, "%s() allocated buffer @ 0x%p (%d pageptrs)\n", |
138 | __func__, buf, params->numpagetables); | ||
112 | dprintk(DBGLVL_BUF, " pci_cpu @ 0x%p dma @ 0x%08lx len = 0x%x\n", | 139 | dprintk(DBGLVL_BUF, " pci_cpu @ 0x%p dma @ 0x%08lx len = 0x%x\n", |
113 | buf->cpu, (long)buf->dma, buf->pci_size); | 140 | buf->cpu, (long)buf->dma, buf->pci_size); |
114 | dprintk(DBGLVL_BUF, " pt_cpu @ 0x%p pt_dma @ 0x%08lx len = 0x%x\n", | 141 | dprintk(DBGLVL_BUF, " pt_cpu @ 0x%p pt_dma @ 0x%08lx len = 0x%x\n", |
115 | buf->pt_cpu, (long)buf->pt_dma, buf->pt_size); | 142 | buf->pt_cpu, (long)buf->pt_dma, buf->pt_size); |
116 | 143 | ||
117 | /* Format the Page Table Entries to point into the data buffer */ | 144 | /* Format the Page Table Entries to point into the data buffer */ |
118 | for (i = 0 ; i < SAA7164_PT_ENTRIES; i++) { | 145 | for (i = 0 ; i < params->numpagetables; i++) { |
119 | 146 | ||
120 | *(buf->pt_cpu + i) = buf->dma + (i * 0x1000); /* TODO */ | 147 | *(buf->pt_cpu + i) = buf->dma + (i * 0x1000); /* TODO */ |
148 | dprintk(DBGLVL_BUF, " pt[%02d] = 0x%p -> 0x%llx\n", | ||
149 | i, buf->pt_cpu, (u64)*(buf->pt_cpu)); | ||
121 | 150 | ||
122 | } | 151 | } |
123 | 152 | ||
@@ -133,26 +162,163 @@ ret: | |||
133 | return buf; | 162 | return buf; |
134 | } | 163 | } |
135 | 164 | ||
136 | int saa7164_buffer_dealloc(struct saa7164_tsport *port, | 165 | int saa7164_buffer_dealloc(struct saa7164_buffer *buf) |
137 | struct saa7164_buffer *buf) | ||
138 | { | 166 | { |
139 | struct saa7164_dev *dev; | 167 | struct saa7164_dev *dev; |
140 | 168 | ||
141 | if (!buf || !port) | 169 | if (!buf || !buf->port) |
142 | return SAA_ERR_BAD_PARAMETER; | 170 | return SAA_ERR_BAD_PARAMETER; |
143 | dev = port->dev; | 171 | dev = buf->port->dev; |
144 | 172 | ||
145 | dprintk(DBGLVL_BUF, "%s() deallocating buffer @ 0x%p\n", __func__, buf); | 173 | dprintk(DBGLVL_BUF, "%s() deallocating buffer @ 0x%p\n", |
174 | __func__, buf); | ||
146 | 175 | ||
147 | if (buf->flags != SAA7164_BUFFER_FREE) | 176 | if (buf->flags != SAA7164_BUFFER_FREE) |
148 | log_warn(" freeing a non-free buffer\n"); | 177 | log_warn(" freeing a non-free buffer\n"); |
149 | 178 | ||
150 | pci_free_consistent(port->dev->pci, buf->pci_size, buf->cpu, buf->dma); | 179 | pci_free_consistent(dev->pci, buf->pci_size, buf->cpu, buf->dma); |
151 | pci_free_consistent(port->dev->pci, buf->pt_size, buf->pt_cpu, | 180 | pci_free_consistent(dev->pci, buf->pt_size, buf->pt_cpu, buf->pt_dma); |
152 | buf->pt_dma); | ||
153 | 181 | ||
154 | kfree(buf); | 182 | kfree(buf); |
155 | 183 | ||
156 | return SAA_OK; | 184 | return SAA_OK; |
157 | } | 185 | } |
158 | 186 | ||
187 | int saa7164_buffer_zero_offsets(struct saa7164_port *port, int i) | ||
188 | { | ||
189 | struct saa7164_dev *dev = port->dev; | ||
190 | |||
191 | if ((i < 0) || (i >= port->hwcfg.buffercount)) | ||
192 | return -EINVAL; | ||
193 | |||
194 | dprintk(DBGLVL_BUF, "%s(idx = %d)\n", __func__, i); | ||
195 | |||
196 | saa7164_writel(port->bufoffset + (sizeof(u32) * i), 0); | ||
197 | |||
198 | return 0; | ||
199 | } | ||
200 | |||
201 | /* Write a buffer into the hardware */ | ||
202 | int saa7164_buffer_activate(struct saa7164_buffer *buf, int i) | ||
203 | { | ||
204 | struct saa7164_port *port = buf->port; | ||
205 | struct saa7164_dev *dev = port->dev; | ||
206 | |||
207 | if ((i < 0) || (i >= port->hwcfg.buffercount)) | ||
208 | return -EINVAL; | ||
209 | |||
210 | dprintk(DBGLVL_BUF, "%s(idx = %d)\n", __func__, i); | ||
211 | |||
212 | buf->idx = i; /* Note of which buffer list index position we occupy */ | ||
213 | buf->flags = SAA7164_BUFFER_BUSY; | ||
214 | buf->pos = 0; | ||
215 | |||
216 | /* TODO: Review this in light of 32v64 assignments */ | ||
217 | saa7164_writel(port->bufoffset + (sizeof(u32) * i), 0); | ||
218 | saa7164_writel(port->bufptr32h + ((sizeof(u32) * 2) * i), buf->pt_dma); | ||
219 | saa7164_writel(port->bufptr32l + ((sizeof(u32) * 2) * i), 0); | ||
220 | |||
221 | dprintk(DBGLVL_BUF, " buf[%d] offset 0x%llx (0x%x) " | ||
222 | "buf 0x%llx/%llx (0x%x/%x) nr=%d\n", | ||
223 | buf->idx, | ||
224 | (u64)port->bufoffset + (i * sizeof(u32)), | ||
225 | saa7164_readl(port->bufoffset + (sizeof(u32) * i)), | ||
226 | (u64)port->bufptr32h + ((sizeof(u32) * 2) * i), | ||
227 | (u64)port->bufptr32l + ((sizeof(u32) * 2) * i), | ||
228 | saa7164_readl(port->bufptr32h + ((sizeof(u32) * i) * 2)), | ||
229 | saa7164_readl(port->bufptr32l + ((sizeof(u32) * i) * 2)), | ||
230 | buf->idx); | ||
231 | |||
232 | return 0; | ||
233 | } | ||
234 | |||
235 | int saa7164_buffer_cfg_port(struct saa7164_port *port) | ||
236 | { | ||
237 | struct tmHWStreamParameters *params = &port->hw_streamingparams; | ||
238 | struct saa7164_dev *dev = port->dev; | ||
239 | struct saa7164_buffer *buf; | ||
240 | struct list_head *c, *n; | ||
241 | int i = 0; | ||
242 | |||
243 | dprintk(DBGLVL_BUF, "%s(port=%d)\n", __func__, port->nr); | ||
244 | |||
245 | saa7164_writel(port->bufcounter, 0); | ||
246 | saa7164_writel(port->pitch, params->pitch); | ||
247 | saa7164_writel(port->bufsize, params->pitch * params->numberoflines); | ||
248 | |||
249 | dprintk(DBGLVL_BUF, " configured:\n"); | ||
250 | dprintk(DBGLVL_BUF, " lmmio 0x%p\n", dev->lmmio); | ||
251 | dprintk(DBGLVL_BUF, " bufcounter 0x%x = 0x%x\n", port->bufcounter, | ||
252 | saa7164_readl(port->bufcounter)); | ||
253 | |||
254 | dprintk(DBGLVL_BUF, " pitch 0x%x = %d\n", port->pitch, | ||
255 | saa7164_readl(port->pitch)); | ||
256 | |||
257 | dprintk(DBGLVL_BUF, " bufsize 0x%x = %d\n", port->bufsize, | ||
258 | saa7164_readl(port->bufsize)); | ||
259 | |||
260 | dprintk(DBGLVL_BUF, " buffercount = %d\n", port->hwcfg.buffercount); | ||
261 | dprintk(DBGLVL_BUF, " bufoffset = 0x%x\n", port->bufoffset); | ||
262 | dprintk(DBGLVL_BUF, " bufptr32h = 0x%x\n", port->bufptr32h); | ||
263 | dprintk(DBGLVL_BUF, " bufptr32l = 0x%x\n", port->bufptr32l); | ||
264 | |||
265 | /* Poke the buffers and offsets into PCI space */ | ||
266 | mutex_lock(&port->dmaqueue_lock); | ||
267 | list_for_each_safe(c, n, &port->dmaqueue.list) { | ||
268 | buf = list_entry(c, struct saa7164_buffer, list); | ||
269 | |||
270 | if (buf->flags != SAA7164_BUFFER_FREE) | ||
271 | BUG(); | ||
272 | |||
273 | /* Place the buffer in the h/w queue */ | ||
274 | saa7164_buffer_activate(buf, i); | ||
275 | |||
276 | /* Don't exceed the device maximum # bufs */ | ||
277 | if (i++ > port->hwcfg.buffercount) | ||
278 | BUG(); | ||
279 | |||
280 | } | ||
281 | mutex_unlock(&port->dmaqueue_lock); | ||
282 | |||
283 | return 0; | ||
284 | } | ||
285 | |||
286 | struct saa7164_user_buffer *saa7164_buffer_alloc_user(struct saa7164_dev *dev, u32 len) | ||
287 | { | ||
288 | struct saa7164_user_buffer *buf; | ||
289 | |||
290 | buf = kzalloc(sizeof(struct saa7164_user_buffer), GFP_KERNEL); | ||
291 | if (buf == 0) | ||
292 | return 0; | ||
293 | |||
294 | buf->data = kzalloc(len, GFP_KERNEL); | ||
295 | |||
296 | if (buf->data == 0) { | ||
297 | kfree(buf); | ||
298 | return 0; | ||
299 | } | ||
300 | |||
301 | buf->actual_size = len; | ||
302 | buf->pos = 0; | ||
303 | buf->crc = 0; | ||
304 | |||
305 | dprintk(DBGLVL_BUF, "%s() allocated user buffer @ 0x%p\n", | ||
306 | __func__, buf); | ||
307 | |||
308 | return buf; | ||
309 | } | ||
310 | |||
311 | void saa7164_buffer_dealloc_user(struct saa7164_user_buffer *buf) | ||
312 | { | ||
313 | if (!buf) | ||
314 | return; | ||
315 | |||
316 | if (buf->data) { | ||
317 | kfree(buf->data); | ||
318 | buf->data = 0; | ||
319 | } | ||
320 | |||
321 | if (buf) | ||
322 | kfree(buf); | ||
323 | } | ||
324 | |||