Lines Matching +full:pci +full:- +full:to +full:- +full:cpu
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (c) 2010-2015 Steven Toth <[email protected]>
12 /* The PCI address space for buffer handling looks like this:
14 * +-u32 wide-------------+
16 * +-u64 wide------------------------------------+
18 * +----------------------+
19 * | CurrentBufferPtr + Pointer to current PCI buffer >-+
20 * +----------------------+ |
22 * +----------------------+ |
24 * +----------------------+ |
25 * | PCI buffer size + = pitch * number of lines (312) |
26 * +----------------------+ |
28 * +----------------------+ v
30 * +----------------------+ |
32 * +----------------------+ |
34 * +----------------------+ |
36 * +---------------------------------------------+ |
37 * +0| set of ptrs to PCI pagetables + |
38 * +---------------------------------------------+ |
39 * +1| set of ptrs to PCI pagetables + <--------+
40 * +---------------------------------------------+
41 * +2| set of ptrs to PCI pagetables +
42 * +---------------------------------------------+
43 * +3| set of ptrs to PCI pagetables + >--+
44 * +---------------------------------------------+ |
45 * ... More buffer pointers | +----------------+
46 * +->| pt[0] TS data |
47 * | +----------------+
49 * | +----------------+
50 * +->| pt[1] TS data |
51 * | +----------------+
57 struct saa7164_dev *dev = buf->port->dev; in saa7164_buffer_display()
61 __func__, buf, buf->idx); in saa7164_buffer_display()
63 buf->cpu, (long long)buf->dma, buf->pci_size); in saa7164_buffer_display()
65 buf->pt_cpu, (long long)buf->pt_dma, buf->pt_size); in saa7164_buffer_display()
67 /* Format the Page Table Entries to point into the data buffer */ in saa7164_buffer_display()
70 dprintk(DBGLVL_BUF, " pt[%02d] = 0x%p -> 0x%llx\n", in saa7164_buffer_display()
71 i, buf->pt_cpu, (u64)*(buf->pt_cpu)); in saa7164_buffer_display()
75 /* Allocate a new buffer structure and associated PCI space in bytes.
81 struct tmHWStreamParameters *params = &port->hw_streamingparams; in saa7164_buffer_alloc()
83 struct saa7164_dev *dev = port->dev; in saa7164_buffer_alloc()
95 buf->idx = -1; in saa7164_buffer_alloc()
96 buf->port = port; in saa7164_buffer_alloc()
97 buf->flags = SAA7164_BUFFER_FREE; in saa7164_buffer_alloc()
98 buf->pos = 0; in saa7164_buffer_alloc()
99 buf->actual_size = params->pitch * params->numberoflines; in saa7164_buffer_alloc()
100 buf->crc = 0; in saa7164_buffer_alloc()
102 buf->pci_size = SAA7164_PT_ENTRIES * 0x1000; in saa7164_buffer_alloc()
103 buf->pt_size = (SAA7164_PT_ENTRIES * sizeof(u64)) + 0x1000; in saa7164_buffer_alloc()
106 buf->cpu = dma_alloc_coherent(&port->dev->pci->dev, buf->pci_size, in saa7164_buffer_alloc()
107 &buf->dma, GFP_KERNEL); in saa7164_buffer_alloc()
108 if (!buf->cpu) in saa7164_buffer_alloc()
111 buf->pt_cpu = dma_alloc_coherent(&port->dev->pci->dev, buf->pt_size, in saa7164_buffer_alloc()
112 &buf->pt_dma, GFP_KERNEL); in saa7164_buffer_alloc()
113 if (!buf->pt_cpu) in saa7164_buffer_alloc()
116 /* init the buffers to a known pattern, easier during debugging */ in saa7164_buffer_alloc()
117 memset(buf->cpu, 0xff, buf->pci_size); in saa7164_buffer_alloc()
118 buf->crc = crc32(0, buf->cpu, buf->actual_size); in saa7164_buffer_alloc()
119 memset(buf->pt_cpu, 0xff, buf->pt_size); in saa7164_buffer_alloc()
122 __func__, buf, params->numpagetables); in saa7164_buffer_alloc()
124 buf->cpu, (long)buf->dma, buf->pci_size); in saa7164_buffer_alloc()
126 buf->pt_cpu, (long)buf->pt_dma, buf->pt_size); in saa7164_buffer_alloc()
128 /* Format the Page Table Entries to point into the data buffer */ in saa7164_buffer_alloc()
129 for (i = 0 ; i < params->numpagetables; i++) { in saa7164_buffer_alloc()
131 *(buf->pt_cpu + i) = buf->dma + (i * 0x1000); /* TODO */ in saa7164_buffer_alloc()
132 dprintk(DBGLVL_BUF, " pt[%02d] = 0x%p -> 0x%llx\n", in saa7164_buffer_alloc()
133 i, buf->pt_cpu, (u64)*(buf->pt_cpu)); in saa7164_buffer_alloc()
140 dma_free_coherent(&port->dev->pci->dev, buf->pci_size, buf->cpu, in saa7164_buffer_alloc()
141 buf->dma); in saa7164_buffer_alloc()
154 if (!buf || !buf->port) in saa7164_buffer_dealloc()
156 dev = buf->port->dev; in saa7164_buffer_dealloc()
161 if (buf->flags != SAA7164_BUFFER_FREE) in saa7164_buffer_dealloc()
162 log_warn(" freeing a non-free buffer\n"); in saa7164_buffer_dealloc()
164 dma_free_coherent(&dev->pci->dev, buf->pci_size, buf->cpu, buf->dma); in saa7164_buffer_dealloc()
165 dma_free_coherent(&dev->pci->dev, buf->pt_size, buf->pt_cpu, in saa7164_buffer_dealloc()
166 buf->pt_dma); in saa7164_buffer_dealloc()
175 struct saa7164_dev *dev = port->dev; in saa7164_buffer_zero_offsets()
177 if ((i < 0) || (i >= port->hwcfg.buffercount)) in saa7164_buffer_zero_offsets()
178 return -EINVAL; in saa7164_buffer_zero_offsets()
182 saa7164_writel(port->bufoffset + (sizeof(u32) * i), 0); in saa7164_buffer_zero_offsets()
190 struct saa7164_port *port = buf->port; in saa7164_buffer_activate()
191 struct saa7164_dev *dev = port->dev; in saa7164_buffer_activate()
193 if ((i < 0) || (i >= port->hwcfg.buffercount)) in saa7164_buffer_activate()
194 return -EINVAL; in saa7164_buffer_activate()
198 buf->idx = i; /* Note of which buffer list index position we occupy */ in saa7164_buffer_activate()
199 buf->flags = SAA7164_BUFFER_BUSY; in saa7164_buffer_activate()
200 buf->pos = 0; in saa7164_buffer_activate()
203 saa7164_writel(port->bufoffset + (sizeof(u32) * i), 0); in saa7164_buffer_activate()
204 saa7164_writel(port->bufptr32h + ((sizeof(u32) * 2) * i), buf->pt_dma); in saa7164_buffer_activate()
205 saa7164_writel(port->bufptr32l + ((sizeof(u32) * 2) * i), 0); in saa7164_buffer_activate()
208 buf->idx, in saa7164_buffer_activate()
209 (u64)port->bufoffset + (i * sizeof(u32)), in saa7164_buffer_activate()
210 saa7164_readl(port->bufoffset + (sizeof(u32) * i)), in saa7164_buffer_activate()
211 (u64)port->bufptr32h + ((sizeof(u32) * 2) * i), in saa7164_buffer_activate()
212 (u64)port->bufptr32l + ((sizeof(u32) * 2) * i), in saa7164_buffer_activate()
213 saa7164_readl(port->bufptr32h + ((sizeof(u32) * i) * 2)), in saa7164_buffer_activate()
214 saa7164_readl(port->bufptr32l + ((sizeof(u32) * i) * 2)), in saa7164_buffer_activate()
215 buf->idx); in saa7164_buffer_activate()
222 struct tmHWStreamParameters *params = &port->hw_streamingparams; in saa7164_buffer_cfg_port()
223 struct saa7164_dev *dev = port->dev; in saa7164_buffer_cfg_port()
228 dprintk(DBGLVL_BUF, "%s(port=%d)\n", __func__, port->nr); in saa7164_buffer_cfg_port()
230 saa7164_writel(port->bufcounter, 0); in saa7164_buffer_cfg_port()
231 saa7164_writel(port->pitch, params->pitch); in saa7164_buffer_cfg_port()
232 saa7164_writel(port->bufsize, params->pitch * params->numberoflines); in saa7164_buffer_cfg_port()
235 dprintk(DBGLVL_BUF, " lmmio 0x%p\n", dev->lmmio); in saa7164_buffer_cfg_port()
236 dprintk(DBGLVL_BUF, " bufcounter 0x%x = 0x%x\n", port->bufcounter, in saa7164_buffer_cfg_port()
237 saa7164_readl(port->bufcounter)); in saa7164_buffer_cfg_port()
239 dprintk(DBGLVL_BUF, " pitch 0x%x = %d\n", port->pitch, in saa7164_buffer_cfg_port()
240 saa7164_readl(port->pitch)); in saa7164_buffer_cfg_port()
242 dprintk(DBGLVL_BUF, " bufsize 0x%x = %d\n", port->bufsize, in saa7164_buffer_cfg_port()
243 saa7164_readl(port->bufsize)); in saa7164_buffer_cfg_port()
245 dprintk(DBGLVL_BUF, " buffercount = %d\n", port->hwcfg.buffercount); in saa7164_buffer_cfg_port()
246 dprintk(DBGLVL_BUF, " bufoffset = 0x%x\n", port->bufoffset); in saa7164_buffer_cfg_port()
247 dprintk(DBGLVL_BUF, " bufptr32h = 0x%x\n", port->bufptr32h); in saa7164_buffer_cfg_port()
248 dprintk(DBGLVL_BUF, " bufptr32l = 0x%x\n", port->bufptr32l); in saa7164_buffer_cfg_port()
250 /* Poke the buffers and offsets into PCI space */ in saa7164_buffer_cfg_port()
251 mutex_lock(&port->dmaqueue_lock); in saa7164_buffer_cfg_port()
252 list_for_each_safe(c, n, &port->dmaqueue.list) { in saa7164_buffer_cfg_port()
255 BUG_ON(buf->flags != SAA7164_BUFFER_FREE); in saa7164_buffer_cfg_port()
261 BUG_ON(i > port->hwcfg.buffercount); in saa7164_buffer_cfg_port()
265 mutex_unlock(&port->dmaqueue_lock); in saa7164_buffer_cfg_port()
279 buf->data = kzalloc(len, GFP_KERNEL); in saa7164_buffer_alloc_user()
281 if (!buf->data) { in saa7164_buffer_alloc_user()
286 buf->actual_size = len; in saa7164_buffer_alloc_user()
287 buf->pos = 0; in saa7164_buffer_alloc_user()
288 buf->crc = 0; in saa7164_buffer_alloc_user()
301 kfree(buf->data); in saa7164_buffer_dealloc_user()
302 buf->data = NULL; in saa7164_buffer_dealloc_user()