1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include "tw68.h"
21
22
23
24
25
26
27
28
29
30
31
32
33static __le32 *tw68_risc_field(__le32 *rp, struct scatterlist *sglist,
34 unsigned int offset, u32 sync_line,
35 unsigned int bpl, unsigned int padding,
36 unsigned int lines, bool jump)
37{
38 struct scatterlist *sg;
39 unsigned int line, todo, done;
40
41 if (jump) {
42 *(rp++) = cpu_to_le32(RISC_JUMP);
43 *(rp++) = 0;
44 }
45
46
47 if (sync_line == 1)
48 *(rp++) = cpu_to_le32(RISC_SYNCO);
49 else
50 *(rp++) = cpu_to_le32(RISC_SYNCE);
51 *(rp++) = 0;
52
53
54 sg = sglist;
55 for (line = 0; line < lines; line++) {
56
57 while (offset && offset >= sg_dma_len(sg)) {
58 offset -= sg_dma_len(sg);
59 sg = sg_next(sg);
60 }
61 if (bpl <= sg_dma_len(sg) - offset) {
62
63 *(rp++) = cpu_to_le32(RISC_LINESTART |
64 bpl);
65 *(rp++) = cpu_to_le32(sg_dma_address(sg) + offset);
66 offset += bpl;
67 } else {
68
69
70
71
72
73
74 todo = bpl;
75
76 done = (sg_dma_len(sg) - offset);
77 *(rp++) = cpu_to_le32(RISC_LINESTART |
78 (7 << 24) |
79 done);
80 *(rp++) = cpu_to_le32(sg_dma_address(sg) + offset);
81 todo -= done;
82 sg = sg_next(sg);
83
84 while (todo > sg_dma_len(sg)) {
85 *(rp++) = cpu_to_le32(RISC_INLINE |
86 (done << 12) |
87 sg_dma_len(sg));
88 *(rp++) = cpu_to_le32(sg_dma_address(sg));
89 todo -= sg_dma_len(sg);
90 sg = sg_next(sg);
91 done += sg_dma_len(sg);
92 }
93 if (todo) {
94
95 *(rp++) = cpu_to_le32(RISC_INLINE |
96 (done << 12) |
97 todo);
98 *(rp++) = cpu_to_le32(sg_dma_address(sg));
99 }
100 offset = todo;
101 }
102 offset += padding;
103 }
104
105 return rp;
106}
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128int tw68_risc_buffer(struct pci_dev *pci,
129 struct tw68_buf *buf,
130 struct scatterlist *sglist,
131 unsigned int top_offset,
132 unsigned int bottom_offset,
133 unsigned int bpl,
134 unsigned int padding,
135 unsigned int lines)
136{
137 u32 instructions, fields;
138 __le32 *rp;
139
140 fields = 0;
141 if (UNSET != top_offset)
142 fields++;
143 if (UNSET != bottom_offset)
144 fields++;
145
146
147
148
149
150
151 instructions = fields * (1 + (((bpl + padding) * lines) /
152 PAGE_SIZE) + lines) + 4;
153 buf->size = instructions * 8;
154 buf->cpu = dma_alloc_coherent(&pci->dev, buf->size, &buf->dma,
155 GFP_KERNEL);
156 if (buf->cpu == NULL)
157 return -ENOMEM;
158
159
160 rp = buf->cpu;
161 if (UNSET != top_offset)
162 rp = tw68_risc_field(rp, sglist, top_offset, 1,
163 bpl, padding, lines, true);
164 if (UNSET != bottom_offset)
165 rp = tw68_risc_field(rp, sglist, bottom_offset, 2,
166 bpl, padding, lines, top_offset == UNSET);
167
168
169 buf->jmp = rp;
170 buf->cpu[1] = cpu_to_le32(buf->dma + 8);
171
172 BUG_ON((buf->jmp - buf->cpu + 2) * sizeof(buf->cpu[0]) > buf->size);
173 return 0;
174}
175
176#if 0
177
178
179
180static void tw68_risc_decode(u32 risc, u32 addr)
181{
182#define RISC_OP(reg) (((reg) >> 28) & 7)
183 static struct instr_details {
184 char *name;
185 u8 has_data_type;
186 u8 has_byte_info;
187 u8 has_addr;
188 } instr[8] = {
189 [RISC_OP(RISC_SYNCO)] = {"syncOdd", 0, 0, 0},
190 [RISC_OP(RISC_SYNCE)] = {"syncEven", 0, 0, 0},
191 [RISC_OP(RISC_JUMP)] = {"jump", 0, 0, 1},
192 [RISC_OP(RISC_LINESTART)] = {"lineStart", 1, 1, 1},
193 [RISC_OP(RISC_INLINE)] = {"inline", 1, 1, 1},
194 };
195 u32 p;
196
197 p = RISC_OP(risc);
198 if (!(risc & 0x80000000) || !instr[p].name) {
199 pr_debug("0x%08x [ INVALID ]\n", risc);
200 return;
201 }
202 pr_debug("0x%08x %-9s IRQ=%d",
203 risc, instr[p].name, (risc >> 27) & 1);
204 if (instr[p].has_data_type)
205 pr_debug(" Type=%d", (risc >> 24) & 7);
206 if (instr[p].has_byte_info)
207 pr_debug(" Start=0x%03x Count=%03u",
208 (risc >> 12) & 0xfff, risc & 0xfff);
209 if (instr[p].has_addr)
210 pr_debug(" StartAddr=0x%08x", addr);
211 pr_debug("\n");
212}
213
214void tw68_risc_program_dump(struct tw68_core *core, struct tw68_buf *buf)
215{
216 const __le32 *addr;
217
218 pr_debug("%s: risc_program_dump: risc=%p, buf->cpu=0x%p, buf->jmp=0x%p\n",
219 core->name, buf, buf->cpu, buf->jmp);
220 for (addr = buf->cpu; addr <= buf->jmp; addr += 2)
221 tw68_risc_decode(*addr, *(addr+1));
222}
223#endif
224